Skip to main content

Module codex_ask

Module codex_ask 

Source
Expand description

Client-side codex exec ask path (ab-0429c6e1).

codex is a one-shot codex exec --json subprocess (NOT a PTY agent): it emits a JSONL stream to stdout, the Rust client drains and parses it, and returns the reply text. The fno daemon cannot handle this path because handle_ask renders a PTY screen; byte-parity with Python’s providers/codex.py requires a direct subprocess approach.

Byte-parity is the contract. The observable behavior (stdout reply, exit code, events.jsonl fields) must match Python’s implementation.

§Architecture

  • Wave B1 (this file, pure core): argv builders, inject_from_name, JSONL line parser, error enum + exit-code map. No I/O.
  • Wave B2 (this file, subprocess driver): run_codex subprocess with own-pgrp, watchdog SIGTERM->SIGKILL, grace reap, output.jsonl tee; codex_create / codex_resume; dispatch_codex_ask orchestrator; maybe_run_codex_ask client entry point.

§Locked Decisions (from Python codex.py)

  • bounded default (create): global --ask-for-approval never before exec plus the exec flag --sandbox workspace-write after it. (-a is a top-level codex flag in >= 0.133.0, not an exec flag.)
  • full yolo (explicit): --dangerously-bypass-approvals-and-sandbox.
  • LD7: inject_from_name is plain [from: X]\n\n<prompt>, no escaping.
  • LD8: output.jsonl is append-only, line-buffered tee (create & resume).
  • LD11: stdin=DEVNULL.
  • LD12: stderr merged into stdout (stderr=STDOUT).
  • LD14 warn-on-drift: NoSessionId carries observed event type names.

Structs§

AskOutcome
Outcome of dispatch_codex_ask.
CodexResult
Result of a successful codex create or resume invocation.

Enums§

CodexAskError
Errors from the codex ask path. Each variant maps to a specific Python- compatible exit code.
JsonlEvent
Parsed variant of one codex JSONL line.

Functions§

approval_flag
Argv tokens for the create-path approval policy (bounded-posture amendment).
build_argv_create
Build the create argv: codex exec --json -C <cwd> --skip-git-repo-check <sandbox> <full_prompt>. full_prompt should already have been built via inject_from_name. The subprocess cwd is NOT set via Popen(cwd=…) on the create path (the -C flag handles it); Python codex.create passes popen_cwd=None.
build_argv_resume
Build the resume argv: codex exec resume <session_id> --json --skip-git-repo-check <sandbox_resume> <full_prompt>. full_prompt should already have been built via inject_from_name. Resume does NOT use -C; the subprocess cwd is pinned via Command::current_dir.
codex_create
Spawn codex exec --json -C <cwd> ... and parse the JSONL stream. agent_self is the name of this agent (injected into spawn env for nested fno agents ask attribution).
codex_resume
Spawn codex exec resume <session_id> --json ... from cwd. Resume does NOT accept --cd; cwd is pinned via Command::current_dir.
dispatch_codex_ask
Orchestrate one codex ask: validate, lock, decide create-vs-resume, stamp the registry, emit events, and return stdout/stderr/exit_code.
dispatch_codex_once
Orchestrate one codex spawn --once: validate, lock, collision-check, create + exchange, teardown registry row, return reply on stdout and teardown receipt on stderr. Reuses dispatch_create machinery.
inject_from_name
Prepend [from: <from_name>]\n\n to prompt (Locked Decision 7). Plain concatenation; no escaping of any kind.
maybe_run_codex_ask
Route a codex ask to the client-side codex exec path, bypassing the daemon (mirrors maybe_run_claude_ask in client.rs).
parse_jsonl_line
Parse one raw line from the codex JSONL stream.
sandbox_flag
Argv tokens for the create-path sandbox posture (bounded-posture amendment).
sandbox_flag_resume
Argv tokens for the sandbox mode on the resume path. codex exec resume only accepts the bypass flag; --sandbox is not honored on resume (verified against codex 0.130.0 –help).