GeezerVison is showing github.com — [codex] add m1 headless exec surface by Vasanthdev2004 · Pull Request #17 · Twigpine/zero
Conversation
Summary
Adds the M1 headless exec slice for Zero:
- adds a focused
docs/M1_HEADLESS_EXEC_PRD.md
- implements
zero exec [prompt...] with --file, --model, --cwd, --output-format text|json, and --skip-permissions-unsafe
- keeps text stdout clean and emits tool/status output on stderr
- emits JSONL events for JSON output mode
- adds explicit exec exit-code handling
- keeps unsafe tool execution on the
ToolRegistry.run path instead of bypassing validation
Tests
bun run typecheck
bun test ./tests --timeout 15000
bun run build
Notes
Provider adapters for Anthropic/Gemini, full stream-json protocol, sessions, resume/fork, and persistent permissions remain later M1/M2 slices by design.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed by Hermes Agent. I checked the headless exec CLI surface, prompt/file/cwd handling, JSONL/text output paths, permission-mode gating, and tests. Local validation passed with npx bun: bun test, bun run typecheck, and bun run build. LGTM.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Jun 3, 2026
Blockers
None found.
Non-Blocking
- This overlaps with feat: add Zero Anthropic provider #15 in
src/cli/index.ts; if Anthropic lands first, this branch will need a small rebase/conflict resolution. Keep Anthropic implemented and Google pending in the provider-error path.
- The M1 PRD is marked Draft, which is fine for this slice, but if this becomes official public docs later we should either mark it accepted or fold it into the main PRD/work split.
Looks Good
zero exec has a clear M1 surface: prompt args, --file, --model, --cwd, text/json output, and explicit unsafe permission mode.
- Normal mode keeps prompt-gated tools hidden; unsafe mode advertises non-deny tools and still routes execution through
ToolRegistry.run() with permission granted, so validation is not bypassed.
- Text output keeps assistant text on stdout and tool/status rows on stderr; JSON mode emits structured JSONL events.
- Validation passed locally in an isolated worktree: typecheck, 102/102 tests, build, exec help, and diff-check. Combined feat: add M2 update check #16 + [codex] add m1 headless exec surface #17 merge also passed 117/117 tests and build.
Verdict: Approve from code review, but comment-only because this PR is authored by Vasanthdev2004.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review: PR #17 — [codex] add m1 headless exec surface
Author: @Vasanthdev2004 → main
Scope: 6 files, +527/-63. Adds zero exec with --file, --model, --cwd, --output-format, --skip-permissions-unsafe. Refactors runHeadless to delegate to runExec. Fixes gnanam1990's PR #11 blocker by threading permissionGranted through toolRegistry.run. Exit code system (0-5). PRD doc included.
PRD alignment: Per the v2 PRD, Vasanth owns M1 agent loop and headless runtime. Scope matches feat/m1-exec exactly. No cross-milestone creep. Owner is correct.
Verdict: Request changes — two real issues that impact users today.
Requires changes
1. formatProviderError hardcodes anthropic as "not implemented" → misleading error
src/cli/index.ts:232-239:
function formatProviderError(err: any, runtime: ZeroResolvedProviderRuntime | undefined) {
const message = err?.message ?? String(err);
if (runtime?.provider === 'anthropic' || runtime?.provider === 'google') {
return `${message}\nZero ${runtime.provider} adapter is not implemented yet. ...`;
}
return message;
}
This is a regression from PR #15's design. The resolver now exports ZeroPendingProviderError — only truly pending providers (like google) throw it. Anthropic is implemented (PR #15 approved). A user with a valid Anthropic config who hits a real error (bad API key, network failure, auth) will see:
Provider authentication error (check your API key)
Zero anthropic adapter is not implemented yet. Use an OpenAI-compatible gateway...
The second line is false and sends the user debugging in the wrong direction. Additionally, the resolver's createZeroProvider already throws ZeroPendingProviderError for pending providers, so the error object is the typed signal — you don't need to re-derive it from runtime.provider.
Fix: Check err instanceof ZeroPendingProviderError instead of hardcoding provider names. Import from ../zero-provider-runtime (already exported — PR #15 added the barrel file). For backwards compat with untyped errors, the fallback can remain as return message.
2. No --max-turns flag for CI use cases
RunExecOptions has maxTurns?: number, runAgent has DEFAULT_MAX_TURNS, but the CLI never exposes it. The PR body lists CI as a primary use case ("Automation, or CI"). Without caller-settable max turns:
- A
zero exec run in CI could hang for hundreds of tool calls if the model gets stuck in a loop.
- The only way to bound cost is an external timeout (CI runner kill), which gives no exit code distinction from a crash.
- Every other non-trivial headless agent CLI (Claude Code, Codex CLI, aider) exposes
--max-turns.
Fix: Add --max-turns <number> to the exec command in src/index.ts:24. Default remains the internal DEFAULT_MAX_TURNS, so existing users are unaffected. M1 scope includes CI readiness per the PRD's user story #2.
3. No CLI integration test for --skip-permissions-unsafe
tests/agent-loop.test.ts validates runAgent's permission filtering. tests/headless-exec.test.ts tests help, usage errors, and provider failures. There is no test that --skip-permissions-unsafe actually propagates to permissionMode: 'unsafe' in runExec. This is a wiring gap — if someone refactors runExec and drops the flag, no test catches it.
Fix: In tests/headless-exec.test.ts, add one test that runs zero exec --help and asserts --skip-permissions-unsafe is documented, or add a unit test to runExec with skipPermissionsUnsafe: true and verify via a mock that permissionMode is 'unsafe'.
Suggestions (non-blocking)
- No
--cwd or --file integration test — resolveExecPrompt and changeWorkingDirectory are unit-tested, but the CLI wiring isn't.
changeWorkingDirectory uses stat then chdir — stat succeeds but chdir could fail (permission denied on the directory's parent). Corner case, caught by the outer crash catch.
exec argument [prompt...] joined by space — zero exec read src/ && write test would pass read, src/, &&, write, test as separate arg strings, joined to "read src/ && write test". That's correct Commander behavior for rest args.
- PR title says
[codex] prefix — seems like a leftover from a template. Unlikely to matter but worth correcting before merge.
Cross-owner notes
- PR #15 conflict:
src/cli/index.ts in this PR replaces the error-handling section that PR #15 already refactored to use ZeroPendingProviderError. The formatProviderError function reintroduces the exact hardcoded-provider-name pattern that PR #15 removed. These need alignment before both can land.
src/index.ts — this PR adds exec subcommand. PR #16 adds update subcommand. Both touch the same file in additive ways. No conflict if merged sequentially.
src/agent/loop.ts permission fix — this is the exact change needed to address gnanam1990's review #4412206154 on PR #11. The permissionGranted option is now threaded through toolRegistry.run. Good.
What I like
- Clean separation of concerns:
runExec handles CLI concerns (cwd, format, exit codes), runAgent handles agent loop concerns (tools, turns, permissions).
- Exit code table (
ZERO_EXEC_EXIT_CODES) is typed, documented in the PRD, and tested for usage and provider cases.
permissionMode: 'auto' | 'unsafe' is the right abstraction for the headless permission model. Unsafe mode still goes through toolRegistry.run (not a bypass).
- Text mode output is clean: agent text on stdout, tool rows on stderr. JSONL output is structured and automation-friendly.
- The PRD document is well-scoped and matches the implementation.
- Error path for provider failures returns exit code 3 without crashing or hanging — correct for CI.
Validation noted from PR body
bun run typecheck, bun test ./tests --timeout 15000, bun run build — all pass per author. zero exec --help documents the M1 flags. Usage errors don't initialize providers (tested). Provider failures return exit code 3 (tested).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-review: PR #17 v2 — [codex] add m1 headless exec surface
Author: @Vasanthdev2004 → main
Head: 10d75a0e (was c0fc0dd)
Delta: Only formatProviderError was changed.
Review items disposition
| Issue |
Status |
formatProviderError hardcodes anthropic/google as "not implemented" (misleading errors after PR #15) |
FIXED — now uses err instanceof ZeroPendingProviderError. The runtime parameter is dropped; the typed error carries everything needed. Message: "Use an implemented provider, or set provider: "openai-compatible" with a custom gateway." |
No --max-turns CLI flag for CI use cases |
NOT ADDRESSED — runExec and runAgent both accept maxTurns, but the exec command in src/index.ts has no option for it. runAgent's DEFAULT_MAX_TURNS prevents unbounded loops, so this is a CI convenience gap, not a correctness issue. |
No CLI test for --skip-permissions-unsafe wiring |
NOT ADDRESSED — no new test validates that the flag propagates to permissionMode: 'unsafe'. |
Verdict
Approve. The only real correctness issue from v1 (misleading error messages about pending providers) is properly fixed. The two remaining items are non-blocking follow-ups for a subsequent iteration.
Follow-ups noted:
--max-turns <n> option on the exec command for CI callers who want tighter bounds than DEFAULT_MAX_TURNS.
- CLI integration test that exercises
--skip-permissions-unsafe and asserts the permissionMode path.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
anandh8x
anandh8x approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|