fix(miner): use claude/codex's real non-interactive CLI argv#5382
Merged
Conversation
Advances #5135 defaultCliSubprocessArgs built ["--max-turns", N, "--acceptance-criteria", path, instructions] -- neither --max-turns nor --acceptance-criteria is a real flag on the claude or codex CLI (verified against `claude --help` and `codex exec --help`, plus a live invocation), and the argv never included -p/--print (claude) or the exec subcommand (codex) at all. Without those, a spawned claude/codex process starts an INTERACTIVE session against a subprocess whose stdin is closed -- meaning the claude-cli/codex-cli providers had no real non-interactive argv shape in production. Splits the shared builder into defaultClaudeCliArgs (--print --output-format json --permission-mode acceptEdits) and defaultCodexCliArgs (exec --json --sandbox workspace-write), matching each CLI's own real, verified interface. --output-format json / --json also finally activate claudeErrorStatus/codexErrorFromStdout's existing JSON(L) parsing, which was already written for exactly this shape but never actually triggered since the flag was never passed. Surfaces two more real, previously-latent gaps this exposed: - claude's own documented behavior ("--output-format json sometimes exits non-zero") implies it can also exit 0 while the JSON envelope reports is_error: true -- confirmed empirically via a live invocation. claudeErrorStatus was already written to detect this exact shape but was only ever checked on the code!==0 branch; now also checked on success exit codes. - Adds real cost parsing (ported from src/selfhost/ai.ts's own COST_KEYS/extractCliUsage best-effort pattern) so claude-cli/codex-cli now report costUsd from their own real JSON(L) output too, closing the "CLI providers report no cost" gap #5356 documented. driver-factory.ts's buildCliArgsWithConfiguredModel is now command-aware: codex's own -m/--model flag is scoped to the exec subcommand (per codex exec --help) and must land after "exec", not prefixed before everything the way claude's top-level --model flag can be -- a single shared prefix-everything scheme would have silently misparsed for codex.
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
gittensory-ui | d2af581 | Commit Preview URL Branch Preview URL |
Jul 12 2026, 03:49 PM |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5382 +/- ##
==========================================
- Coverage 94.43% 94.40% -0.04%
==========================================
Files 551 551
Lines 44191 44223 +32
Branches 14641 14654 +13
==========================================
+ Hits 41732 41747 +15
- Misses 1784 1801 +17
Partials 675 675
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
While tracing #5135's cost tracking, found that
defaultCliSubprocessArgsbuilt["--max-turns", N, "--acceptance-criteria", path, instructions]— neither--max-turnsnor--acceptance-criteriais a real flag on theclaudeorcodexCLI (verified againstclaude --helpandcodex exec --help, plus a live invocation). The argv also never included-p/--print(claude) or theexecsubcommand (codex) at all. Without those, a spawnedclaude/codexprocess starts an interactive session against a subprocess whose stdin is closed — meaning theclaude-cli/codex-cliproviders had no real non-interactive argv shape in production.Fix
Splits the shared builder into
defaultClaudeCliArgs(--print --output-format json --permission-mode acceptEdits) anddefaultCodexCliArgs(exec --json --sandbox workspace-write), matching each CLI's own real, verified interface.--output-format json/--jsonalso finally activateclaudeErrorStatus/codexErrorFromStdout's existing JSON(L) parsing, which was already written for exactly this shape but never actually triggered since the flag was never passed.Two more real, previously-latent gaps this exposed
--output-format jsonsometimes exits non-zero") implies it can also exit 0 while the JSON envelope reportsis_error: true— confirmed empirically via a live invocation.claudeErrorStatuswas already written to detect this exact shape but was only ever checked on thecode !== 0branch; now also checked on success exit codes.src/selfhost/ai.ts's ownCOST_KEYS/extractCliUsagebest-effort pattern) soclaude-cli/codex-clinow reportcostUsdfrom their own real JSON(L) output too, closing the "CLI providers report no cost" gap fix(miner): wire real dollar-cost tracking into the loop's budgetSpent #5356 documented as a deliberate limitation.driver-factory.ts'sbuildCliArgsWithConfiguredModelis now command-aware: codex's own-m/--modelflag is scoped to theexecsubcommand (percodex exec --help) and must land after"exec", not prefixed before everything the way claude's top-level--modelflag can be — a single shared prefix-everything scheme would have silently misparsed for codex.Test plan
claudeandcodexdefault buildersbuildArgsoverride; an explicit override still worksok:falsewhen--output-format json's envelope carriesis_error:trueeven on exit code 0; stillok:trueon a genuine success envelope; never inspected for non-claude commandsnpx vitest run test/unit— 738 files / 14,654 tests passnpx tsc --noEmit -p . --incremental false(fresh, no cache) — cleannpm run test:driver-parity,npm run test --workspace @jsonbored/gittensory-engine(520 node:test cases) — passnpm run --prefix packages/gittensory-miner build— passgit diff --check— cleannpm run test:coveragerun (cross-checked against the exact diff hunks, not just the file totals)