Skip to content

feat(miner-hands): CLI-subprocess CodingAgentDriver (reuse SpawnFn/redactSecrets/EFFORT_TIMEOUT_MS pattern) #4266

Description

@JSONbored

Implements the CodingAgentDriver interface (#4262, this batch — foundational, must land first) for the "run a local CLI as a subprocess" case: claude (Claude Code CLI) or codex, invoked NOT for a review opinion (the existing createClaudeCodeAi/createCodexAi use in src/selfhost/ai.ts) but to actually edit files in a scoped local working directory. The subprocess-spawning, secret-redaction, and per-effort-timeout machinery this needs already exists in src/selfhost/ai.ts for the review use case — this issue reuses it rather than re-inventing it.

Deliverables

  • packages/gittensory-engine/src/miner/cli-subprocess-driver.ts (path coordinated with feat(miner-hands): define the CodingAgentDriver interface seam #4262's src/miner/ home) implementing CodingAgentDriver by spawning claude/codex as a subprocess against the scoped working directory, using an injected SpawnFn-shaped function — the exact type from src/selfhost/ai.ts:627-641, generalized so this package doesn't import from src/ directly (packages/gittensory-engine is meant to stand alone).
  • Reuse (not duplicate) redactSecrets's behavior (src/selfhost/ai.ts:724-731) on any subprocess stderr/output this driver surfaces in errors or logs — a coding-agent invocation is exactly as capable of echoing a leaked token as the existing review invocation is.
  • Reuse the per-effort timeout ladder pattern (CLAUDE_EFFORT_TIMEOUT_MS/CODEX_EFFORT_TIMEOUT_MS, src/selfhost/ai.ts:185-186, and resolveCliTimeoutFrom, :188-192) rather than one fixed timeout — a coding-agent invocation legitimately runs far longer than a review call (it edits files, runs commands, iterates), so this needs its own ceiling, sized independently from the review ladder (mirror the pattern, don't import/share its constants directly).
  • Unlike createClaudeCodeAi's review invocation (--permission-mode plan --disallowedTools Bash,Edit,Write,WebFetch,WebSearch, src/selfhost/ai.ts:809), this driver's whole point is letting the CLI edit files — it must NOT reuse that disallowed-tools flag set. Document explicitly which flags differ and why, so a future reader doesn't assume this is a copy-paste of the review call.
  • Tests with an injected fake SpawnFn (no real subprocess spawned in CI), covering: success with changed files, non-zero exit, timeout, and a redacted-secret-in-stderr case — mirroring the existing createClaudeCodeAi/createCodexAi test patterns.

References

  • src/selfhost/ai.ts:627-641 (SpawnFn type)
  • src/selfhost/ai.ts:644-711 (defaultSpawn — the real child_process.spawn wiring this driver's production SpawnFn should mirror, including timeout/kill handling)
  • src/selfhost/ai.ts:724-731 (redactSecrets)
  • src/selfhost/ai.ts:185-200 (CLAUDE_EFFORT_TIMEOUT_MS/CODEX_EFFORT_TIMEOUT_MS, resolveCliTimeoutFrom, resolveClaudeCliTimeoutMs, resolveCodexCliTimeoutMs)
  • src/selfhost/ai.ts:772-838 (createClaudeCodeAi — closest existing example of spawning claude as a subprocess, albeit for review not editing)
  • src/selfhost/ai.ts:349-404 (SUBSCRIPTION_CLI_ENV_ALLOWLIST, subscriptionCliEnv — env isolation this driver should also apply; generalized further in a separate issue in this batch)
  • Depends on feat(miner-hands): define the CodingAgentDriver interface seam #4262 (this batch) — the CodingAgentDriver interface this implements

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:featureGittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.gittensor:priorityMaintainer-selected Gittensor priority — scores a 1.5x multiplier.help wantedExtra attention is needed

    Projects

    Status
    In Progress

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions