Skip to content

Commit 62cba0a

Browse files
authored
Merge pull request #7 from engram-node/m3
m3: bash on Android + pre-M3 hardening
2 parents d12de03 + 1c80476 commit 62cba0a

145 files changed

Lines changed: 7805 additions & 1319 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.githooks/pre-commit‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
# Secret scan on staged changes; keep secrets out of history.
3+
# Enable once per clone: git config core.hooksPath .githooks
4+
# Requires gitleaks >= 8.19 on PATH (https://github.com/gitleaks/gitleaks).
5+
# CI enforces the same config (.gitleaks.toml) on every push/PR; this hook is
6+
# a local convenience and skips with a warning when gitleaks is missing.
7+
if ! command -v gitleaks >/dev/null 2>&1; then
8+
echo "pre-commit: gitleaks not on PATH - secret scan SKIPPED (CI will enforce)" >&2
9+
exit 0
10+
fi
11+
if ! gitleaks git --pre-commit --redact --config .gitleaks.toml; then
12+
echo "pre-commit: gitleaks found a secret - commit blocked" >&2
13+
exit 1
14+
fi

‎.github/workflows/ci.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,14 @@ jobs:
114114
fi
115115
done
116116
exit $fail
117+
118+
secrets:
119+
runs-on: ubuntu-24.04
120+
steps:
121+
- uses: actions/checkout@v4
122+
- name: gitleaks (pinned, checksum-verified)
123+
run: |
124+
curl -sSfL -o /tmp/gitleaks.tar.gz https://github.com/gitleaks/gitleaks/releases/download/v8.30.1/gitleaks_8.30.1_linux_x64.tar.gz
125+
echo "551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb /tmp/gitleaks.tar.gz" | sha256sum -c -
126+
tar -xzf /tmp/gitleaks.tar.gz -C /tmp gitleaks
127+
/tmp/gitleaks dir . --redact --config .gitleaks.toml --exit-code 1

‎.gitleaks.toml‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
title = "palmcode secrets policy"
2+
3+
[extend]
4+
# default rule set plus the custom rules below
5+
useDefault = true
6+
7+
[[rules]]
8+
id = "palmcode-byok-key-shape"
9+
description = "BYOK provider keys (sk-... including dash-containing forms the default OpenAI rule misses)"
10+
regex = '''(?i)\bsk-[a-z0-9_-]{20,}\b'''
11+
keywords = ["sk-"]
12+
13+
[[allowlists]]
14+
description = "known-fake test placeholders (redaction unit tests)"
15+
regexes = [
16+
'''sk-never-log-me-''',
17+
'''sk-test-mock-key''',
18+
]
19+
20+
[[allowlists]]
21+
description = "untracked build outputs and vendored checksum manifests (never committed / upstream sha256 maps)"
22+
paths = [
23+
'''android[/\\]app[/\\]build[/\\]''',
24+
'''core[/\\]target[/\\]''',
25+
'''[/\\]gitleaks-bin[/\\]''',
26+
'''\.cargo-checksum\.json$''',
27+
]
28+
29+
[[allowlists]]
30+
description = "vendored upstream test-data / API-constant files (crypto test keys, p12 fixtures, netlink constants). gitleaks path matches skip files ENTIRELY, so these are file-level exclusions; every other core/vendor/ file is fully scanned. A vendor bump that adds new test data may need an entry here."
31+
paths = [
32+
'''core/vendor/linux-raw-sys/.*/netlink\.rs$''',
33+
'''core/vendor/libsqlite3-sys/(sqlite3|sqlcipher)/''',
34+
'''core/vendor/openssl/(src/(cipher_ctx|dsa|ec|pkey|pkey_ctx|rsa|symm)\.rs|test/)''',
35+
'''core/vendor/ring/src/(aead/poly1305_test\.txt|rsa/keypair\.rs)''',
36+
'''core/vendor/(schannel/src/crypt_prov\.rs|security-framework/src/os/macos/encrypt_transform\.rs)''',
37+
'''core/vendor/tokio-native-tls/(tests|examples)/identity\.p12''',
38+
'''core/vendor/windows-sys[^/]*/src/Windows/Win32/(NetworkManagement/WiFi|Security/Cryptography/Certificates)/mod\.rs$''',
39+
]

‎AGENTS.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Agent-facing project notes. Humans: read `README.md`.
1919
emulator or device; keep `docs/VERIFY.md` accurate.
2020
- **Record non-obvious decisions in `docs/decisions/`** including rejected
2121
alternatives.
22+
- **No secrets, provider hostnames, or model aliases in the tree.** Endpoint,
23+
key and model come from `PALMCODE_LLM_*` env vars only (ADR 0013); gitleaks
24+
runs in CI and locally via `git config core.hooksPath .githooks`. Never put
25+
key material in summaries, docs, ADRs or logs.
2226

2327
## Build & test
2428

‎README.md‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# palmcode
1+
# palmcode
22

33
On-device, BYOK coding-agent harness for Android. The agent runs entirely on the
44
phone; the only network traffic is the user's own LLM requests to an
@@ -33,6 +33,21 @@ Gradle drives `cargo ndk`, binding generation, and (from M3) the userland
3333
build. The Rust build vendors its dependencies (`core/vendor/`), so it works
3434
offline after a clean checkout.
3535

36+
## Secrets policy
37+
38+
This repo must stay F-Droid-publishable: no API keys, no provider hostnames
39+
or model aliases anywhere in the tree or docs (see
40+
`docs/decisions/0013-secrets-and-provider-neutrality.md`). Endpoint, key and
41+
model come from env only: `PALMCODE_LLM_BASE_URL`, `PALMCODE_LLM_API_KEY`,
42+
`PALMCODE_LLM_MODEL` (`PALMCODE_LLM_FAST_MODEL` for the fast role).
43+
44+
CI runs gitleaks on every push/PR and fails on findings. For local
45+
pre-commit scanning (gitleaks >= 8.19 on PATH):
46+
47+
```
48+
git config core.hooksPath .githooks
49+
```
50+
3651
## Layout
3752

3853
```

‎android/app/build.gradle.kts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ val gnuSelfContained: File? = File(System.getProperty("user.home"), ".rustup/too
9696
val msysBinutils = File("C:\\msys64\\mingw64\\bin")
9797

9898
fun cargoEnvironment(ndkDir: File): Map<String, String> = buildMap {
99+
// One NDK, everywhere: AGP's ndkVersion, CI's sdkmanager install and
100+
// cargo-ndk's env all agree on ndkVersionPin. Set BOTH legacy names so a
101+
// stray inherited ANDROID_NDK_ROOT pointing at another NDK cannot split
102+
// the toolchain (observed: 27.3 vs 30.0 warning mid-build).
99103
put("ANDROID_NDK_HOME", ndkDir.absolutePath)
104+
put("ANDROID_NDK_ROOT", ndkDir.absolutePath)
100105
// Reproducibility: assert()/__FILE__ in vendored C (tree-sitter grammars)
101106
// would bake absolute build paths into the .so; NDEBUG compiles asserts
102107
// out, the prefix-map normalizes anything left. cc-rs splits the env var
@@ -207,6 +212,33 @@ val execProbeTasks = abiTriples.map { (abi, triple) ->
207212
}
208213
}
209214

215+
// ---------------------------------------------------------------------------
216+
// Userland (busybox/rg/git) from checksum-verified source — userland/build.sh.
217+
// Lands in build/userland/jniLibs/<abi>/lib{name}.so next to libexecprobe.so.
218+
// ---------------------------------------------------------------------------
219+
220+
val userlandBuild = tasks.register<Exec>("userlandBuild") {
221+
group = "build"
222+
description = "Cross-build busybox/ripgrep/git from source (needs bash+make; MSYS2 on Windows, system tools on Linux CI)"
223+
val outDir = layout.buildDirectory.dir("userland")
224+
inputs.files(rootProject.file("userland/build.sh"), rootProject.file("userland/versions.env"))
225+
outputs.dir(outDir)
226+
outputs.cacheIf { true }
227+
environment("NDK_HOME", ndkDir.absolutePath)
228+
environment("OUT_DIR", outDir.get().asFile.absolutePath)
229+
// MSYS2 bash on Windows (proven path for the kbuild/autoconf host steps);
230+
// MUST be a login shell: non-login MSYS2 lacks /tmp, /usr/bin on PATH and
231+
// working `ln -s` (all three observed failing under direct gradle spawn).
232+
executable = if (isWindows) "C:\\msys64\\usr\\bin\\bash.exe" else "bash"
233+
if (isWindows) {
234+
val scriptPosix = rootProject.file("userland/build.sh").absolutePath
235+
.replace('\\', '/').replace(Regex("^([A-Za-z]):"), "/$1").lowercase()
236+
args("-lc", "\"$scriptPosix\"")
237+
} else {
238+
args(rootProject.file("userland/build.sh").absolutePath)
239+
}
240+
}
241+
210242
// License texts (Apache-2.0 obligation stack, GPL source offer) ship as
211243
// assets; the app shows them from the home screen.
212244
val copyLicenseAssets = tasks.register<Copy>("copyLicenseAssets") {
@@ -219,6 +251,7 @@ tasks.named("preBuild") {
219251
dependsOn(cargoNdkRelease)
220252
dependsOn(uniffiBindgen)
221253
dependsOn(execProbeTasks)
254+
dependsOn(userlandBuild)
222255
dependsOn(copyLicenseAssets)
223256
}
224257

‎android/app/src/main/java/dev/palmcode/app/CoreManager.kt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class ToolCard(val id: String, val name: String, val path: String?) {
5757
var ok by mutableStateOf(false)
5858
var durationMs by mutableStateOf(0L)
5959
var preview by mutableStateOf("")
60+
/** Live merged stdout+stderr of a bash run (capped tail; full text in the spill file). */
61+
var liveOutput by mutableStateOf("")
6062
}
6163

6264
/** A pending approval sheet (engine blocks the call until resolved). */
@@ -164,6 +166,12 @@ object AppState {
164166
c.preview = e.preview
165167
}
166168
}
169+
is CoreEvent.ToolOutput -> find(e.sessionId, e.messageId)?.let { m ->
170+
m.tools.firstOrNull { it.id == e.callId }?.let { c ->
171+
// cap the card tail; the full stream is in the spill file
172+
c.liveOutput = (c.liveOutput + e.chunk).takeLast(8192)
173+
}
174+
}
167175
is CoreEvent.ApprovalRequested -> {
168176
if (approvals.none { it.requestId == e.requestId }) {
169177
approvals.add(

‎android/app/src/main/java/dev/palmcode/app/ui/WorkspaceScreen.kt‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import androidx.compose.runtime.getValue
2626
import androidx.compose.runtime.mutableStateListOf
2727
import androidx.compose.runtime.mutableStateOf
2828
import androidx.compose.runtime.remember
29+
import androidx.compose.runtime.rememberCoroutineScope
2930
import androidx.compose.runtime.setValue
3031
import androidx.compose.ui.Alignment
3132
import androidx.compose.ui.Modifier
@@ -40,9 +41,11 @@ import dev.palmcode.core.workspaceImportDir
4041
import dev.palmcode.core.workspaceMetrics
4142
import dev.palmcode.core.workspaceRegister
4243
import dev.palmcode.core.workspaceRemove
44+
import dev.palmcode.core.workspaceSetTrusted
4345
import dev.palmcode.core.workspacesList
4446
import java.io.File
4547
import kotlinx.coroutines.Dispatchers
48+
import kotlinx.coroutines.launch
4649
import kotlinx.coroutines.withContext
4750

4851
private fun humanSize(bytes: ULong): String {
@@ -66,6 +69,7 @@ fun WorkspaceScreen() {
6669
var importUri by remember { mutableStateOf<Uri?>(null) }
6770
var exportUri by remember { mutableStateOf<Uri?>(null) }
6871
var refreshTick by remember { mutableStateOf(0) }
72+
val scope = rememberCoroutineScope()
6973

7074
suspend fun refreshSilently() {
7175
val list = withContext(Dispatchers.IO) { workspacesList() }
@@ -148,6 +152,12 @@ fun WorkspaceScreen() {
148152
workspaceRemove(w.id, true)
149153
refreshTick++
150154
},
155+
onToggleTrust = {
156+
scope.launch(Dispatchers.IO) {
157+
runCatching { workspaceSetTrusted(w.id, !w.trusted) }
158+
withContext(Dispatchers.Main) { refreshTick++ }
159+
}
160+
},
151161
)
152162
}
153163
}
@@ -194,6 +204,7 @@ private fun WorkspaceRow(
194204
onOpen: () -> Unit,
195205
onForget: () -> Unit,
196206
onDelete: () -> Unit,
207+
onToggleTrust: () -> Unit,
197208
) {
198209
var metrics by remember(w.id) { mutableStateOf<String?>(null) }
199210
LaunchedEffect(w.id) {
@@ -224,6 +235,16 @@ private fun WorkspaceRow(
224235
TextButton(onClick = onForget) { Text("Forget") }
225236
TextButton(onClick = onDelete) { Text("Delete copy") }
226237
}
238+
Row {
239+
// M3 trust: untrusted ignores the repo's .palmcode/config.json;
240+
// trusted honors its ask/deny rules (allows are always stripped)
241+
val label = if (w.trusted) "trusted ✓ — project ask/deny rules on"
242+
else "untrusted — project config ignored"
243+
TextButton(onClick = onToggleTrust) {
244+
Text(label, color = if (w.trusted) MaterialTheme.colorScheme.primary
245+
else MaterialTheme.colorScheme.outline)
246+
}
247+
}
227248
}
228249
}
229250
}

‎core/Cargo.lock‎

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎core/agent/Cargo.toml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license.workspace = true
77
publish = false
88

99
[dependencies]
10+
palmcode-exec = { path = "../exec" }
1011
palmcode-llm = { path = "../llm" }
1112
palmcode-perms = { path = "../perms" }
1213
palmcode-store = { path = "../store" }
@@ -20,3 +21,6 @@ tracing = "0.1"
2021

2122
[dev-dependencies]
2223
tempfile = "3"
24+
25+
[target.'cfg(unix)'.dependencies]
26+
libc = "0.2"

0 commit comments

Comments
 (0)