feat(miner-hands): CLI-subprocess CodingAgentDriver - #4531
Conversation
Implements the CodingAgentDriver seam (JSONbored#4262) by running the coding agent (claude/codex) as a subprocess in the attempt's scoped working directory. The spawn primitive is INJECTED — a generalized version of src/selfhost/ai.ts's SpawnFn, redeclared here so gittensory-engine stays standalone (no import from src/) — so the driver is fully testable without a real child process. Reuses (not duplicates) the two safety primitives already centralized in subprocess-env.ts (JSONbored#4284): the child gets a STRICT allowlisted env via buildAllowlistedEnv (never the full host env — a coding-agent subprocess is prompt-injectable), and any subprocess output surfaced in a transcript or folded into an error is run through redactSecrets first, plus a caller-supplied knownSecrets list. A non-zero/absent exit code or a timeout yields ok:false with a redacted error; exit 0 yields ok:true. Detecting which files changed is a sibling concern (a git diff over the worktree, JSONbored#4269), so changedFiles is []. - packages/gittensory-engine/src/miner/cli-subprocess-driver.ts: createCliSubprocessCodingAgentDriver + the injectable CliSubprocessSpawnFn type and CliSubprocessDriverOptions (command, spawn, timeout, env allowlist inputs, knownSecrets, and an overridable argv builder). - packages/gittensory-engine/src/index.ts: barrel re-export. - test/unit/cli-subprocess-driver.test.ts: success, non-zero exit (redacted), no-stderr fallback, timeout, env-allowlisting, and secret-redaction + custom argv — all via an injected fake spawn (100% branch coverage). Closes JSONbored#4266
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4531 +/- ##
=======================================
Coverage 94.04% 94.04%
=======================================
Files 422 423 +1
Lines 37574 37592 +18
Branches 13724 13732 +8
=======================================
+ Hits 35335 35353 +18
Misses 1583 1583
Partials 656 656
🚀 New features to boost your workflow:
|
|
Tip 🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩 ✅ Gittensory review result - approve/merge recommendedReview updated: 2026-07-09 23:15:16 UTC
✅ Suggested Action - Approve/Merge
Review summary Nits — 5 non-blocking
Linked issue satisfactionPartially addressed Review context
Contributor next steps
Signal definitions
🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.
|
Closes #4266
What
Implements the
CodingAgentDriverseam (#4262) by running the coding agent (claude/codex) as a subprocess in the attempt's scoped working directory. The spawn primitive is injected — a generalized version ofsrc/selfhost/ai.ts'sSpawnFn, redeclared here sogittensory-enginestays standalone (no import fromsrc/) — so the driver is fully testable without a real child process.Reuses the shared safety primitives (not duplicated)
Both come from
subprocess-env.ts(#4284), the engine-hosted source of truth:buildAllowlistedEnv+SUBPROCESS_CLI_ENV_ALLOWLIST— the child gets only home/proxy/TLS/locale/XDG keys plus caller-supplied extras, never the full host env (a coding-agent subprocess is prompt-injectable, so runtime credentials must not leak into it).redactSecrets— any subprocess output kept as a transcript or folded into an error is redacted first (well-known token shapes + a caller-suppliedknownSecretslist).Behavior
0→ok: true.ok: falsewith a redacted<command>_exit_<code>: <detail>error (falls back toexit <code>when the subprocess wrote no stderr).ok: falsewith a distinct<command>_timeout_<ms>mserror.changedFilesis[].API (
packages/gittensory-engine/src/miner/cli-subprocess-driver.ts)createCliSubprocessCodingAgentDriver(options)→CodingAgentDriver, withCliSubprocessSpawnFn(the injectable spawn type) andCliSubprocessDriverOptions(command,spawn,timeoutMs,parentEnv/env,knownSecrets, and an overridablebuildArgs).Testing
6/6 tests pass (success, non-zero-exit redaction, no-stderr fallback incl. a null code, timeout, env-allowlisting, secret-redaction + custom argv) via an injected fake spawn; typecheck clean. New engine file at 100% line + branch coverage (18/18, 18/18, 3/3).