From 5acd4fb89f3bf7118243e611cb78a1bd40af6f00 Mon Sep 17 00:00:00 2001 From: "Robert E. Lee" Date: Thu, 30 Jul 2026 14:16:13 -0700 Subject: [PATCH 1/2] fix(execution): harden supervised host workers (#88) Rebase the contributor follow-ups onto current main and preserve the original security, correctness, and test-gap repairs. Use one shell-free invocation descriptor across Claude, Codex, and OpenCode. Native Windows executables run directly; package-manager shims require a sibling PowerShell script and pass hostile arguments literally through PowerShell -File. Bound OpenCode startup, SSE, teardown, and subprocess termination; validate routing inputs and adapter construction; forward supported turn caps; document the repository trust boundary. Verification: pnpm run check; pnpm run test:surface; pnpm audit --audit-level=moderate; pnpm run lint:links:internal. --- .../0018-generalized-host-worker-execution.md | 23 ++ src/commands/run.mjs | 40 ++- src/lib/exec.mjs | 86 ++++-- src/lib/execution/adapters.mjs | 19 ++ src/lib/execution/claude.mjs | 3 + src/lib/execution/codex.mjs | 4 +- src/lib/execution/opencode.mjs | 120 +++++++-- src/lib/execution/subprocess.mjs | 52 +++- tests/kit/exec.test.mjs | 67 ++++- tests/kit/execution-runner.test.mjs | 58 ++++ tests/kit/opencode-execution.test.mjs | 253 +++++++++++++++++- tests/kit/routing.test.mjs | 8 + tests/kit/run-command.test.mjs | 26 ++ tests/kit/subprocess-execution.test.mjs | 110 ++++++++ 14 files changed, 813 insertions(+), 56 deletions(-) diff --git a/docs/adr/0018-generalized-host-worker-execution.md b/docs/adr/0018-generalized-host-worker-execution.md index 874e775..cca793f 100644 --- a/docs/adr/0018-generalized-host-worker-execution.md +++ b/docs/adr/0018-generalized-host-worker-execution.md @@ -2,6 +2,8 @@ - **Status:** Accepted - **Date:** 2026-07-29 +- **Updated:** 2026-07-30 +- **Update note:** Hardened trusted-policy validation, adapter invariants, plan guards, and bounded worker teardown. - **Deciders:** agentic-kit maintainers ## Context @@ -68,6 +70,27 @@ permission-response contract required for a routable worker. [OpenCode CLI docum conformance evidence. Its routes are accepted by `ak run`, but are never auto-seeded, AQE-projected, primary-host eligible, or accepted by deprecated `ak dual`. +### The trust boundary (stated, not weakened) + +`ak run` executes workers with the **user's own CLI trust posture in the target +repository**. That means the repository itself is *inside* the trust boundary: + +- An owned OpenCode server reads the project `opencode.json` from the target cwd. A + repository that ships `{"permission":{"bash":"allow"}}` (or hostile `mcp` entries) + pre-approves those permissions — **no `permission.updated` event ever fires, so the + adapter's abort boundary does not trip by design**. The abort covers permission + *requests*; it is not a sandbox. +- Claude/Codex workers likewise inherit the repo's `.claude/settings.json` hooks and + permissions under the user's own workspace trust for that path. +- Repository content (`AGENTS.md`, README, source) flows into worker prompts — an + indirect prompt-injection channel for any agent runner, ak included. + +**Contract: run `ak` (and any agent runner) only in repositories you would trust with +your full user privileges.** ak will not silently weaken, bypass, or "secure" a hostile +repo for you; what it guarantees instead is the honest version: loopback-only owned +servers, ephemeral per-run credentials, no `--auto`, no permission approval on your +behalf, and terminal evidence that records what actually ran. + ## Consequences - `ak run` executes the host-neutral plan and result schema while preserving the legacy diff --git a/src/commands/run.mjs b/src/commands/run.mjs index 1209326..e9684c8 100644 --- a/src/commands/run.mjs +++ b/src/commands/run.mjs @@ -19,6 +19,10 @@ export const help = `ak run — execute a host-neutral activity pipeline Materializes the managed per-activity routing policy and runs each worker through its host adapter. OpenCode is accepted only after its routing capability is enabled. +Trust boundary: workers run with YOUR CLI trust posture in the target repo — +its opencode.json / .claude settings / AGENTS.md apply. Run this only in +repositories you would trust with your full user privileges (ADR-0018). + Usage: ak run