diff --git a/docs/concepts/interaction-pattern-catalog.md b/docs/concepts/interaction-pattern-catalog.md index 944581b480..5fd063cdc4 100644 --- a/docs/concepts/interaction-pattern-catalog.md +++ b/docs/concepts/interaction-pattern-catalog.md @@ -2202,9 +2202,7 @@ the stable schema. **Validation** - `docs/reference/protocols/protocol-action-packet-decision-v0.md` -- `docs/product/runtimes/codex-cli/codex-cli-same-open-tui-continuation-observation.md` - `examples/interaction-pattern-catalog-smoke.py` -- `examples/codex-cli-visible-attach-acceptance-smoke.py` #### IP-028 Connector Runtime Boundary diff --git a/docs/guides/getting-started.md b/docs/guides/getting-started.md index 619d582d10..666f1c4e91 100644 --- a/docs/guides/getting-started.md +++ b/docs/guides/getting-started.md @@ -294,90 +294,17 @@ If the user only wants the pasteable TUI text, omit the wrapper: loopx codex-cli-bootstrap-message --project . --goal-id --message-only ``` -To review the whole one-message loop contract without running Codex, generate a -pilot packet: - -```bash -loopx codex-cli-one-message-loop-pilot --project . --goal-id --agent-id -``` - -The pilot ties the first TUI paste message to the later -`codex-cli-local-scheduler-exec` bridge. It stays dry-run by default and is for -operators/contributors validating the path, not a prerequisite for first-time -users. - -To review the returning-user local-driver loop without touching a real Codex -session, generate the visible local-driver pilot packet: - -```bash -loopx codex-cli-visible-local-driver-pilot --project . --goal-id --agent-id -``` - -This keeps the first-message TUI start primary, then models later scheduler -ticks, visible proof, idle guard, guarded execution, blocker writeback, and -no-transcript boundaries as public-safe metadata. - -The later-turn rule is intentionally stricter than the first message: LoopX may -add a visible steering turn only after public-safe visible proof, -runtime idle evidence, a fresh guard, and explicit execution bounds. Without -that proof, the driver should write a compact blocker or keep the one-message -setup bootstrap as the product path. - -The commands below are optional automation checks after the setup path -works. To evaluate future same-session automation support without touching -transcripts or session files, run: - -```bash -loopx codex-cli-session-probe -``` - -To turn that probe into a dry-run driver decision without mutating a Codex -session, run: - -```bash -loopx codex-cli-visible-driver-plan --project . --goal-id -``` - -To see the full local automation setup plan in one packet, including quota -guard, visible-driver decision, TUI bootstrap command, the headless-disabled -boundary, and idle-guard requirement, run: - -```bash -loopx codex-cli-local-driver-plan --project . --goal-id --agent-id -``` - -This is still dry-run-only. It does not run Codex, read transcripts, read -session files, mutate a session, or spend quota. - -When the driver plan says `resume [PROMPT]` or `remote-control` might support a -visible same-session path, validate a public-safe proof fixture before treating -that path as automation: - -```bash -loopx codex-cli-visible-session-proof \ - --project . \ - --goal-id \ - --agent-id \ - --proof-fixture visible-proof.public.json -``` - -The fixture should contain only booleans and public-safe labels proving user -opt-in, quota guard, idle guard, visible turn, interruptibility, no transcript -or session-file reads, and compact writeback planning. - -The default Codex CLI setup-then-`/goal` product path does not offer a headless fallback. -For compatibility, the old handoff command only reports the disabled boundary -and points back to the message-only TUI bootstrap: - -```bash -loopx codex-cli-exec-handoff --project . --goal-id -``` +The default Codex CLI setup-then-`/goal` product path keeps execution visible in +the TUI and preserves a headless-disabled boundary for onboarding. Explicit +isolated-headless automation runs use `loopx turn plan` and `loopx turn run-once` +instead; see the [LoopX Turn quickstart](../product/runtimes/codex-cli/loopx-turn-codex-cli-quickstart.md) +and [Automation driver audit](../product/runtimes/codex-cli/codex-cli-automation-driver.md). See the [Codex CLI TUI-first loop](../product/runtimes/codex-cli/codex-cli-tui-loop.md) contract for the bootstrap, session-attached automation, and headless-disabled boundary. The [Codex CLI first-run rehearsal](../product/runtimes/codex-cli/codex-cli-first-run-rehearsal.md) keeps the shortest user-facing route in one place: no-clone install, -one-message setup bootstrap, and proof-capture fixtures for later automation. +one-message setup bootstrap, and explicit `loopx turn` boundaries. For current product scheduling, the [Codex CLI TUI continuation priority](../product/runtimes/codex-cli/codex-cli-tui-continuation-priority.md) keeps same-open-TUI continuation ahead of frontstage or showcase polish when diff --git a/docs/product/runtimes/codex-cli/README.md b/docs/product/runtimes/codex-cli/README.md index ba550cf394..26f58b60b9 100644 --- a/docs/product/runtimes/codex-cli/README.md +++ b/docs/product/runtimes/codex-cli/README.md @@ -11,44 +11,18 @@ bounded partner path rather than the default user experience. - [Packaged install](codex-cli-packaged-install.md): PyPI install, update, and start path; clone-plus-canary remains a contributor route. - [First-run rehearsal](codex-cli-first-run-rehearsal.md): connects PyPI - install, one-message TUI bootstrap, and proof-capture fixtures. + install, one-message TUI bootstrap, and explicit `loopx turn` boundaries. - [No-clone release verification](codex-cli-no-clone-release-verification.md): - proves installer, bootstrap message, bundle, and proof fixtures stay aligned. + proves installer, bootstrap message, and command surface stay aligned. - [LoopX Turn quickstart](loopx-turn-codex-cli-quickstart.md): the bounded isolated-headless path with one adapter, one validator, one command, and typed outcomes. -## Visible Session Evidence - -- [Codex CLI live TUI first-message pilot](codex-cli-live-tui-first-message-pilot.md): - records why manual paste remains primary until visible completion is proven. -- [Visible proof-capture protocol](codex-cli-visible-proof-capture-protocol.md): - opt-in procedure for turning `resume` or `remote-control` signals into - public-safe evidence. -- [Visible attach proof pilot](codex-cli-visible-attach-proof-pilot.md): the - bounded acceptance path for proving a resumed session is the intended one. -- [Proof-capture demo](codex-cli-proof-capture-demo.md): sample fixtures and - acceptance decisions without running Codex or reading session material. -- [Same-open-TUI continuation observation](codex-cli-same-open-tui-continuation-observation.md): - current evidence for visible first-turn continuation and the remaining - scheduled-attach boundary. - -The Codex CLI bounded visible pilot adapter is the public-safe packet command -covered by `examples/codex-cli-bounded-visible-pilot-adapter-smoke.py`. It -validates first-response and runtime-idle fixtures before a live TUI bootstrap -can count as successful. - -The Codex CLI visible first-response capture plan is the copy-first packet -command covered by -`examples/codex-cli-visible-first-response-capture-plan-smoke.py`. It produces -`public-first-response.json` and `public-runtime-idle.json` without argv prompt -leakage or raw transcript reads. - ## Scheduling And Automation - [Automation driver audit](codex-cli-automation-driver.md): keeps TUI - bootstrap primary, composes quota/idle/fallback checks, and treats - `codex exec` as an explicit fallback. + bootstrap primary, routes isolated headless turns through `loopx turn`, and + treats `codex exec` as an explicit fallback. - [TUI continuation priority](codex-cli-tui-continuation-priority.md): keeps same-open-TUI continuation ahead of frontstage or showcase support work when both are runnable. diff --git a/docs/product/runtimes/codex-cli/codex-cli-automation-driver.md b/docs/product/runtimes/codex-cli/codex-cli-automation-driver.md index 1ed9c2a254..7a704108bc 100644 --- a/docs/product/runtimes/codex-cli/codex-cli-automation-driver.md +++ b/docs/product/runtimes/codex-cli/codex-cli-automation-driver.md @@ -41,9 +41,10 @@ The remaining parity gaps are narrower: and scheduler hint without overlapping a live host turn; and - benchmark promotion still requires matched, countable comparative evidence. -The older `codex-cli-local-scheduler-*` commands remain diagnostics and -compatibility probes. They are not the default orchestration narrative and must -not be composed manually as a second control plane. +The older pre-Turn `codex-cli-local-scheduler-*` and pilot probe commands +have been retired in favor of `loopx turn` (`turn_driver/codex_cli.py`). +Callers should use `loopx turn plan` and `loopx turn run-once` rather than +composing manual probe chains. ## Codex App Parity Matrix @@ -200,9 +201,7 @@ or local artifact paths. ## Rollback And Non-goals The adapter must be disableable without changing LoopX goal state, normal CLI -commands, or Codex App heartbeat operation. Old probe commands may remain as -diagnostics until the consolidated driver covers their durable boundaries; they -must not be the default product narrative. +commands, or Codex App heartbeat operation. This route does not: diff --git a/docs/product/runtimes/codex-cli/codex-cli-first-run-rehearsal.md b/docs/product/runtimes/codex-cli/codex-cli-first-run-rehearsal.md index 01ebdfd6ca..64fd95e68b 100644 --- a/docs/product/runtimes/codex-cli/codex-cli-first-run-rehearsal.md +++ b/docs/product/runtimes/codex-cli/codex-cli-first-run-rehearsal.md @@ -11,7 +11,7 @@ This route connects three shipped surfaces: 1. PyPI install/update with packaged workflow skills and an archive fallback; 2. one-message Codex CLI TUI bootstrap; -3. proof-capture fixtures for later visible automation. +3. bounded isolated-headless turns via `loopx turn` when explicit non-TUI execution is requested. ## Fresh User Path @@ -56,75 +56,31 @@ Once `loopx` is on PATH, generate a stricter project-specific TUI message: loopx codex-cli-bootstrap-message --project . --goal-id --message-only ``` -For release rehearsal without running Codex or reading session material: - -```bash -loopx codex-cli-tui-bootstrap-smoke-bundle \ - --project . \ - --goal-id \ - --agent-id -``` - -That bundle checks the install-repair command, paste block, quota guard, -bounded writeback, and spend command shape. It is not a first-time user step. Use the [no-clone release verification](codex-cli-no-clone-release-verification.md) when validating that the packaged installer and fresh-project command surface match this route before promotion. ## Later Automation Gate -Same-TUI automation stays optional until the proof path passes. A scheduler may -return to Codex CLI only after all of these are true: - -- visible-session proof is public-safe and accepted; -- runtime idle evidence is fresh; -- quota/status guard still permits the selected work; -- the command boundary is explicit; -- validation writes compact evidence or a blocker before spend. - -Rehearse the proof path with public fixtures: - -```bash -loopx --format json codex-cli-visible-attach-acceptance \ - --project . \ - --goal-id public-codex-cli-goal \ - --agent-id codex-side-bypass \ - --fixture examples/fixtures/codex-cli-visible-proof/codex-visible-resume-help.public.json \ - --proof-fixture examples/fixtures/codex-cli-visible-proof/visible-resume-proof.public.json \ - --idle-fixture examples/fixtures/codex-cli-visible-proof/runtime-idle-visible-resume.public.json -``` - -This current likely path can pass as a visible later-turn spike, but it still -does not prove same-open-TUI automation. Until a same-TUI attach proof is -accepted, the product path remains one-message TUI bootstrap plus explicit -fallbacks. - -## Live TUI Pilot Note - -The first real [live TUI first-message pilot](codex-cli-live-tui-first-message-pilot.md) -confirmed that the generated message can launch Codex CLI through -`codex [PROMPT]`, but it did not prove that the LoopX loop started -successfully. The process stayed active, no bounded first-response marker was -available, and passing the message as argv would leak project-specific prompt -text through the process command line in real repos. - -So the reliable first-run route remains manual paste into the visible Codex CLI -TUI. Automated live launch needs a bounded visible completion proof first. +Same-TUI automation stays optional until a safe attach primitive is proven. +Manual paste into the visible Codex CLI TUI remains primary; automated +isolated-headless execution uses `loopx turn` (`turn_driver/codex_cli.py`) as an +explicit opt-in path. ## Boundary This first-run route must not: - require cloning the LoopX repo; -- launch Codex as part of the rehearsal bundle; +- launch Codex as part of install/bootstrap packet generation; - read raw Codex transcripts, session files, stdout, stderr, credentials, or private paths; - spend LoopX quota before validated writeback; - treat headless `codex exec` as the default user experience; -- promote same-TUI automation without visible proof and idle evidence. +- claim same-open-TUI scheduled attach without an explicit attach primitive. See also: - [Codex CLI packaged install path](codex-cli-packaged-install.md) - [Codex CLI TUI-first loop](codex-cli-tui-loop.md) -- [Codex CLI proof-capture demo](codex-cli-proof-capture-demo.md) +- [LoopX Turn quickstart](loopx-turn-codex-cli-quickstart.md) diff --git a/docs/product/runtimes/codex-cli/codex-cli-live-tui-first-message-pilot.md b/docs/product/runtimes/codex-cli/codex-cli-live-tui-first-message-pilot.md deleted file mode 100644 index 5fa8cda4d9..0000000000 --- a/docs/product/runtimes/codex-cli/codex-cli-live-tui-first-message-pilot.md +++ /dev/null @@ -1,150 +0,0 @@ -# Codex CLI Live TUI First-Message Pilot - -Status: blocker recorded; manual TUI bootstrap remains primary. -Recorded: 2026-06-21. - -This note records a real Codex CLI TUI pilot for the one-message LoopX -bootstrap path. The pilot used only a disposable public-safe repo and kept raw -TUI output, Codex transcripts, session files, credentials, and private project -paths out of the repository. - -## Question - -Can LoopX launch a real visible Codex CLI TUI with the generated start -message and prove that the loop starts, remains observable, and stays steerable -by the user? - -## Method - -The pilot used a temporary public repo with a small `README.md`, a small -`GOAL.md`, and a generated start message: - -```bash -loopx codex-cli-bootstrap-message \ - --project /tmp/loopx-live-tui-pilot. \ - --goal-id public-live-tui-pilot-goal \ - --agent-id codex-side-bypass \ - --message-only -``` - -The local Codex CLI surface was `codex-cli 0.142.0-alpha.7`. Its help exposed: - -- `codex [OPTIONS] [PROMPT]`; -- `--no-alt-screen`; -- `--cd `; -- `resume`; -- `remote-control`. - -Two bounded probes were attempted: - -1. `codex doctor` from the disposable repo. It did not produce bounded output - before manual interrupt. -2. A real TUI launch with a public-safe generated message: - - ```bash - codex --no-alt-screen --ask-for-approval never --sandbox workspace-write \ - -C /tmp/loopx-live-tui-pilot. \ - "$(cat loopx-start-message.txt)" - ``` - -The second probe launched Codex CLI, but it did not produce a compact, -machine-checkable first-response result in the bounded capture window. The -process was still active afterward and was stopped by exact temp-repo process -match. - -## Result - -Not proven yet. - -The generated message can start a real Codex CLI TUI through `codex [PROMPT]`, -but the current automation-side proof is insufficient for claiming that the -LoopX loop started successfully. - -Observed blockers: - -- no bounded first-response or completion signal; -- capture output exceeded the automation budget before a compact result was - available; -- the TUI process remained active after the capture window; -- passing the generated message as `[PROMPT]` exposes the prompt in the process - command line, which is acceptable only for this public-safe pilot and should - not become the default path for real project repos. - -Decision: - -`live_tui_first_message_blocked_by_bounded_visible_completion_missing` - -## Product Implication - -The public user path should still be: - -1. the user opens Codex CLI TUI in the project repo; -2. the user pastes one LoopX start message; -3. Codex keeps the visible TUI as the live control surface. - -LoopX should not advertise automated `codex [PROMPT]` launch as a -verified first-run path until a bounded visible pilot adapter exists. - -That adapter needs to prove all of these without raw transcript or session-file -reads: - -- inject or paste the start message without leaking project-specific prompt - text through process arguments; -- observe a compact public-safe first-response marker; -- stop or idle-check the TUI without racing the user; -- show that the user can still steer, review, interrupt, or take over; -- write compact success evidence or a precise blocker before quota spend. - -## Follow-Up - -Create a bounded visible pilot adapter before promoting live TUI automation: - -```text -[P0] Codex CLI bounded visible pilot adapter: define and test a minimal -public-safe first-response capture and stop protocol for Codex CLI TUI bootstrap -before claiming live TUI first-message success; avoid raw transcripts, session -files, credentials, private paths, and argv prompt leakage. -``` - -Until then, keep the no-clone installer, generated paste message, and -transcript-free smoke bundle as the reliable first-run route. - -## Bounded Adapter Command - -The follow-up adapter is public-safe and packet-only: it validates a compact -first-response fixture plus runtime-idle evidence, but it does not start Codex, -read transcripts, read session files, capture stdout/stderr, or mutate the TUI. - -```bash -loopx codex-cli-bounded-visible-pilot-adapter \ - --project /tmp/loopx-live-tui-pilot. \ - --goal-id public-live-tui-pilot-goal \ - --agent-id codex-side-bypass \ - --first-response-fixture public-first-response.json \ - --idle-fixture public-runtime-idle.json -``` - -The first-response fixture must prove the visible TUI showed the goal id, user -gate or none, top user todo or none, selected agent todo, and next safe action; -it must also prove the user can interrupt or take over, compact writeback is -planned before quota spend, and the bootstrap prompt was not passed as an argv -prompt. If any piece is missing, the pilot stays a precise blocker instead of a -success claim. - -## Visible Capture Plan - -Use this packet before a real user-visible rehearsal: - -```bash -loopx codex-cli-visible-first-response-capture-plan \ - --project /tmp/loopx-live-tui-pilot. \ - --goal-id public-live-tui-pilot-goal \ - --agent-id codex-side-bypass -``` - -It prints the copy-first procedure, stop conditions, and sample -`public-first-response.json` / `public-runtime-idle.json` shapes. The user still -starts in the Codex CLI TUI and pastes the generated message; the packet only -tells the operator which public-safe booleans to record before running the -bounded adapter. It never runs Codex, reads terminal output, reads session files, -or accepts an argv prompt path as success evidence. diff --git a/docs/product/runtimes/codex-cli/codex-cli-no-clone-release-verification.md b/docs/product/runtimes/codex-cli/codex-cli-no-clone-release-verification.md index 7c0f261e71..4e44487802 100644 --- a/docs/product/runtimes/codex-cli/codex-cli-no-clone-release-verification.md +++ b/docs/product/runtimes/codex-cli/codex-cli-no-clone-release-verification.md @@ -15,12 +15,9 @@ The release verifier exercises the path as a fresh user would see it: mechanism used by the public no-clone command; 3. confirm the installed `loopx` wrapper can run `doctor`; 4. confirm the installed top-level help points at `loopx commands`, and the - installed command reference exposes the first-run commands: - `codex-cli-bootstrap-message`, `codex-cli-tui-bootstrap-smoke-bundle`, and - `codex-cli-visible-attach-acceptance`; -5. generate the one-message TUI bootstrap text from the fresh project; -6. generate the transcript-free bootstrap bundle from the fresh project; -7. replay the public proof-capture fixture from the installed release snapshot. + installed command reference exposes the first-run command + `codex-cli-bootstrap-message`; +5. generate the one-message TUI bootstrap text from the fresh project. The verifier does not launch Codex, read transcripts, read session files, read credentials, mutate a Codex session, or spend LoopX quota. @@ -39,20 +36,16 @@ Ready: - the archive installer creates a stable release snapshot without requiring a local LoopX checkout; -- the installed wrapper exposes the first-run TUI bootstrap, smoke bundle, and - visible-attach acceptance commands; +- the installed wrapper exposes the first-run TUI bootstrap command; - the generated bootstrap text tells the agent to install, connect, run quota, - preserve the visible TUI, write back evidence, and avoid raw transcripts; -- the smoke bundle confirms no Codex launch and no LoopX quota spend; -- proof-capture fixtures are packaged into the release snapshot and can be - replayed by the installed wrapper. + preserve the visible TUI, write back evidence, and avoid raw transcripts. Boundary: - public install still depends on network access to GitHub archive endpoints unless the caller overrides `LOOPX_ARCHIVE_URL` with a trusted archive; -- same-TUI automation is not the default path until visible proof plus runtime - idle evidence pass. +- same-TUI automation is not the default path; bounded isolated-headless runs + use `loopx turn`. That means the archive route can remain a tested recovery option while PyPI is the default and contributor clone-plus-canary remains the development path. @@ -64,14 +57,13 @@ Before promoting a new release snapshot, run: ```bash python3 examples/release/codex-cli-no-clone-release-verification-smoke.py python3 examples/codex-cli-first-run-rehearsal-smoke.py -python3 examples/codex-cli-tui-bootstrap-smoke-bundle-smoke.py -python3 examples/codex-cli-proof-capture-demo-fixtures-smoke.py +python3 examples/codex-cli-bootstrap-message-smoke.py ``` If the first command fails, do not advertise the archive fallback as qualified until the failure is reduced to a compact blocker: missing installer -dependency, archive layout mismatch, missing installed command, broken -bootstrap generation, or missing public proof fixture. +dependency, archive layout mismatch, missing installed command, or broken +bootstrap generation. ## Boundary @@ -86,4 +78,4 @@ See also: - [Codex CLI packaged install path](codex-cli-packaged-install.md) - [Codex CLI first-run rehearsal](codex-cli-first-run-rehearsal.md) -- [Codex CLI proof-capture demo](codex-cli-proof-capture-demo.md) +- [LoopX Turn quickstart](loopx-turn-codex-cli-quickstart.md) diff --git a/docs/product/runtimes/codex-cli/codex-cli-packaged-install.md b/docs/product/runtimes/codex-cli/codex-cli-packaged-install.md index c4d95ec4b0..e92532e055 100644 --- a/docs/product/runtimes/codex-cli/codex-cli-packaged-install.md +++ b/docs/product/runtimes/codex-cli/codex-cli-packaged-install.md @@ -68,10 +68,10 @@ This keeps the product hierarchy clear: and transcript-free validation checklist; - copy-only mode: `codex-cli-bootstrap-message --message-only` prints just the pasteable TUI block, while the default output remains the review packet; -- smoke bundle: `codex-cli-tui-bootstrap-smoke-bundle` verifies the fresh-repo - installer, paste block, quota guard, and bounded writeback commands without - launching Codex or reading transcripts; -- recurring automation: separate driver work; +- release verification: [no-clone release verification](codex-cli-no-clone-release-verification.md) + verifies the fresh-repo installer, command reference, and bootstrap message + without launching Codex or reading transcripts; +- recurring automation: separate driver work (`loopx turn`); - contributor development: clone plus canary remains available. ## Update Path diff --git a/docs/product/runtimes/codex-cli/codex-cli-proof-capture-demo.md b/docs/product/runtimes/codex-cli/codex-cli-proof-capture-demo.md deleted file mode 100644 index fc4599848f..0000000000 --- a/docs/product/runtimes/codex-cli/codex-cli-proof-capture-demo.md +++ /dev/null @@ -1,72 +0,0 @@ -# Codex CLI Proof-Capture Demo - -This demo bundle lets a user or contributor rehearse the visible proof protocol -without running Codex, reading session material, or touching local LoopX -state. It is deliberately fixture-first: the commands validate public-safe -evidence shape and show the acceptance decision that a real opt-in proof would -need to produce. - -## Files - -- `examples/fixtures/codex-cli-visible-proof/codex-visible-resume-help.public.json` - models a Codex CLI surface with `resume [PROMPT]` / `remote-control`. -- `examples/fixtures/codex-cli-visible-proof/visible-resume-proof.public.json` - records the visible, interruptible proof for that surface. -- `examples/fixtures/codex-cli-visible-proof/runtime-idle-visible-resume.public.json` - records the fresh idle guard for that surface. -- `examples/fixtures/codex-cli-visible-proof/codex-same-tui-help.public.json` - models a future explicit same-TUI attach primitive. -- `examples/fixtures/codex-cli-visible-proof/same-tui-proof.public.json` - records the proof shape that can promote same-TUI automation. -- `examples/fixtures/codex-cli-visible-proof/runtime-idle-same-tui.public.json` - records the matching idle guard. - -## Rehearse The Current Likely Path - -```bash -loopx --format json codex-cli-visible-attach-acceptance \ - --project . \ - --goal-id public-codex-cli-goal \ - --agent-id codex-side-bypass \ - --fixture examples/fixtures/codex-cli-visible-proof/codex-visible-resume-help.public.json \ - --proof-fixture examples/fixtures/codex-cli-visible-proof/visible-resume-proof.public.json \ - --idle-fixture examples/fixtures/codex-cli-visible-proof/runtime-idle-visible-resume.public.json -``` - -Expected decision: - -```text -decision: visible_surface_spike_passed_not_same_tui -accepted_for_visible_later_turn: true -accepted_for_same_tui_automation: false -blocker: same_tui_visible_attach_not_proven -``` - -This is the important product distinction. A visible `resume` or -`remote-control` path can become a useful proof spike, but it still does not -prove LoopX can safely add a turn to the same open TUI. - -## Rehearse The Future Promotion Path - -```bash -loopx --format json codex-cli-visible-attach-acceptance \ - --project . \ - --goal-id public-codex-cli-goal \ - --agent-id codex-side-bypass \ - --fixture examples/fixtures/codex-cli-visible-proof/codex-same-tui-help.public.json \ - --proof-fixture examples/fixtures/codex-cli-visible-proof/same-tui-proof.public.json \ - --idle-fixture examples/fixtures/codex-cli-visible-proof/runtime-idle-same-tui.public.json -``` - -Expected decision: - -```text -decision: same_tui_visible_attach_accepted -accepted_for_visible_later_turn: true -accepted_for_same_tui_automation: true -blockers: [] -``` - -That result is still an acceptance packet, not an executor. A later driver must -rerun quota, rerun a fresh idle guard, obey the command boundary, write compact -evidence or a blocker, and spend quota only after validation. diff --git a/docs/product/runtimes/codex-cli/codex-cli-same-open-tui-continuation-observation.md b/docs/product/runtimes/codex-cli/codex-cli-same-open-tui-continuation-observation.md deleted file mode 100644 index 0ca832900b..0000000000 --- a/docs/product/runtimes/codex-cli/codex-cli-same-open-tui-continuation-observation.md +++ /dev/null @@ -1,101 +0,0 @@ -# Codex CLI Same-Open-TUI Continuation Observation - -Status: same-open-TUI bootstrap continuation observed; scheduled same-TUI -automation still blocked. -Recorded: 2026-06-21. - -This note records a public-safe observation from a live Codex CLI TUI session. -It is intentionally narrower than a new runtime packet contract. The evidence -is about the interactive one-message path staying visible in the same open TUI, -not about a scheduler injecting future prompts into a hidden or detached -session. - -## Question - -Can a user start LoopX with one Codex CLI TUI message and keep the same -visible TUI as the place to watch, steer, review, and take over through the -initial LoopX guard and steering step? - -## Observation - -Yes, for the interactive bootstrap continuation path. - -In the observed session: - -- the operator started from an already visible Codex CLI TUI and explicitly - asked LoopX to keep that TUI as the primary surface; -- the agent first showed the current goal id, concrete user gate, top user todo, - top agent todo, and next safe action before running longer work; -- the registered-agent quota guard initially returned a peer workspace - repair, and that repair was handled visibly by switching shell work to an - independent peer worktree rather than using hidden headless execution; -- the same registered-agent quota guard then returned `decision=run` and - `effective_action=normal_run` from the independent worktree; -- subsequent steering stayed in the same visible TUI session, with no switch to - headless `codex exec` as the primary path. - -The observation did not read raw Codex transcripts, session files, stdout or -stderr streams, credentials, screenshots, local private material, or hidden TUI -buffers. It did not mutate hidden Codex session state. - -## Result - -`same_open_tui_bootstrap_continuation_observed`: yes. - -This proves the manual, user-observed continuation after a one-message TUI -bootstrap can remain in the same open TUI through the first guard, workspace -repair, and steering decision. - -`scheduled_same_tui_attach_proven`: no. - -The current acceptance packet still requires a public-safe visible-session proof -fixture before promoting a later automated same-TUI steering turn. Local idle -flags alone are insufficient, and the packet correctly returns -`visible_session_proof_required` when no proof fixture is supplied. - -## Product Decision - -Keep the product path as: - -1. user opens Codex CLI TUI in the project repo; -2. user pastes one LoopX bootstrap message; -3. LoopX shows the compact control-plane snapshot and, if quota allows, - performs one bounded visible segment in that same TUI; -4. later automation remains blocked until visible-session proof and runtime-idle - evidence pass; -5. `codex exec` remains an explicit headless fallback, not the default - interactive path. - -This keeps the trusted TUI front and center while avoiding a premature claim -that LoopX can safely inject future scheduled turns into the same open -session. - -## Validation - -Public-safe validation commands for this observation: - -```bash -loopx --format json --registry "$HOME/.codex/loopx/registry.global.json" \ - quota should-run --goal-id loopx-meta --agent-id codex-side-bypass -``` - -From the independent peer worktree this returned `decision=run` and -`effective_action=normal_run`. - -```bash -loopx --format json codex-cli-visible-attach-acceptance \ - --project . \ - --goal-id loopx-meta \ - --agent-id codex-side-bypass \ - --observed-surface same_tui_visible_attach \ - --turn-state idle \ - --human-input-idle-seconds 30 \ - --min-human-input-idle-seconds 5 \ - --checked-before-prompt \ - --visible-to-user \ - --user-can-interrupt \ - --manual-takeover-available -``` - -Without a proof fixture this returned `decision=visible_session_proof_required`, -which is the intended blocker for scheduled same-TUI automation. diff --git a/docs/product/runtimes/codex-cli/codex-cli-tui-loop.md b/docs/product/runtimes/codex-cli/codex-cli-tui-loop.md index 28e136d96e..2b3a241af2 100644 --- a/docs/product/runtimes/codex-cli/codex-cli-tui-loop.md +++ b/docs/product/runtimes/codex-cli/codex-cli-tui-loop.md @@ -102,18 +102,6 @@ generate the thin heartbeat body, set Codex CLI goal mode to `/goal `, run the quota/status guard for the first snapshot, obey `interaction_contract`, preserve the visible TUI, and stop before longer work. -Transcript-free first-run smoke packet: - -```bash -loopx codex-cli-tui-bootstrap-smoke-bundle --project . --goal-id --agent-id -``` - -This packet is for product and release validation, not an extra user step. It -checks the PyPI-first install repair path, the copy-only paste block, the quota -guard command, and the bounded writeback/spend commands without launching -Codex, reading transcripts, inspecting session files, mutating a session, or -spending quota. - The first useful TUI response should be a control-plane snapshot, not a lecture about internals: @@ -124,33 +112,8 @@ about internals: - next safe action. Registry paths, runtime roots, JSON payloads, local-driver plans, -clone/canary setup, and visible-session proof fixtures are follow-up -diagnostics. They should not be required before a first-time user sees the -current goal/gate/todo state. - -Current pilot packet: - -```bash -loopx codex-cli-one-message-loop-pilot --project . --goal-id --agent-id -``` - -This command does not run Codex. It packages the first TUI paste message and -the safe scheduler/executor bridge into one reviewable packet: - -- first turn: paste one LoopX message into the visible Codex CLI TUI; -- first response: show goal id, concrete user gate or none, top user todo or - none, top agent todo, and next safe action; -- first work segment: if the guard permits work, claim or choose one runnable - agent todo and complete one bounded validated segment in that same visible - TUI turn; -- later scheduler: use `codex-cli-local-scheduler-exec` in dry-run mode by - default; -- bridge side effects: require a fresh guard plus explicit candidate prefix or - blocker-writeback opt-in. - -The pilot is a contract check for the user experience. It is not a prerequisite -for a first-time user; the first-time path remains "paste one message and watch -the TUI." +and clone/canary setup are follow-up diagnostics. They should not be required +before a first-time user sees the current goal/gate/todo state. ### 2. Session-Attached Automation @@ -168,210 +131,19 @@ A valid attachment needs: If Codex CLI cannot expose a safe session attachment primitive, LoopX should not fake it by writing hidden state. It should fall back to a transparent -mode. - -Current probe: - -```bash -loopx codex-cli-session-probe -``` - -The probe is help-only by default: it checks public Codex CLI command surfaces -such as `codex --help`, `codex exec --help`, and `codex resume --help`. It does -not read raw transcripts, credentials, local session files, or mutate a Codex -session. The key distinction is deliberate: `exec` or `resume` support can be a -useful fallback, but it is not evidence that LoopX can inject a visible -turn into the same open TUI. Same-session automation requires an explicit -visible attach/inject primitive plus an idle guard. A visible `resume [PROMPT]` -or experimental `remote-control` surface is stronger than plain headless -fallback, but it still belongs in a separate spike until LoopX proves the -turn is visible, idle-guarded, interruptible, and not racing a human-typed TUI -message. - -Current driver-plan prototype: - -```bash -loopx codex-cli-visible-driver-plan --project . --goal-id -``` - -This command turns the probe result into a dry-run driver plan. It does not run -Codex, read raw transcripts, read session files, mutate a Codex session, or -spend LoopX quota. Its job is to choose one of three next modes: - -- `session_attached_visible_turn`: a future local driver may try the detected - visible attach primitive, but only behind quota guard and idle guard. -- `visible_resume_or_remote_control_spike`: `resume [PROMPT]` or - `remote-control` exists, but it must prove that the turn is visible and - interruptible before LoopX treats it as session-attached automation. -- `tui_bootstrap_only`: ask the user to start inside Codex CLI TUI. If the - probe only exposes `codex exec`, LoopX still stays in this mode - because headless fallback is disabled for the default `/goal` product path. - -Current local-driver planner: - -```bash -loopx codex-cli-local-driver-plan --project . --goal-id --agent-id -``` - -This command is the conservative MVP for automation setup. It composes the -quota guard, visible-driver plan, TUI bootstrap command, headless-disabled -boundary, and idle-guard requirement into a single dry-run packet. It -does not run Codex, read transcripts, read session files, mutate a session, or -spend quota. - -Current local-scheduler execution wrapper: - -```bash -loopx codex-cli-local-scheduler-exec --project . --goal-id --agent-id -``` - -Without explicit execution flags, this command is still a no-execution packet. -For a later visible Codex CLI turn, it must also receive public-safe runtime -idle evidence through `--observe-local-runtime ...` or `--idle-fixture -`. A visible-session proof says the route is visible -and interruptible; the runtime-idle detector says this exact later turn is not -racing human typing or an already-running Codex turn. Missing runtime-idle -evidence produces a precise blocker instead of a candidate command. - -With runtime-idle evidence and `--guard-checked`, a local scheduler may choose -exactly one opt-in side effect: - -- `--execute-candidate --candidate-command-prefix `: run a proven - visible candidate whose command starts with an allowed prefix. -- `--execute-blocker-writeback`: run the precise LoopX blocker writeback - command when the tick says proof is missing. - -The wrapper reports only whether it ran, return code, timeout, and the selected -kind. It discards stdout/stderr, does not read transcripts, does not inspect -session files, does not mutate hidden Codex state, and does not spend Goal -Harness quota. This keeps the first executable bridge narrow enough to test -without turning the user's TUI into an opaque background daemon. - -Current visible local-driver pilot: - -```bash -loopx codex-cli-visible-local-driver-pilot --project . --goal-id --agent-id -``` - -This command still does not run Codex. It binds the first one-message TUI start -to later scheduler ticks and makes the returning-user contract explicit: - -- later turns must remain visible to the user; -- the user must be able to interrupt or take over; -- a public-safe visible proof is required before resume, remote-control, or - same-TUI prompt candidates can run; -- every later tick needs quota guard and idle guard; -- candidate execution still requires `--guard-checked` plus an allowed command - prefix; -- blocker writeback still requires `--guard-checked`; -- the pilot never reads transcripts, session files, credentials, stdout, or - stderr, and never spends quota by itself. - -Current visible-session proof harness: - -```bash -loopx codex-cli-visible-session-proof \ - --project . \ - --goal-id \ - --agent-id \ - --proof-fixture visible-proof.public.json -``` - -The proof fixture must be public-safe. It records booleans for user opt-in, -quota guard, idle guard, turn visibility, interruptibility, private-data -boundaries, and compact writeback planning. Passing this proof only means a -future local driver may try that visible surface behind the same guards; it -does not mean LoopX may read transcripts, read session files, mutate -hidden session state, or bypass user gates. - -Current runtime-idle detector: - -```bash -loopx codex-cli-runtime-idle-detector \ - --project . \ - --goal-id \ - --agent-id \ - --observe-local-runtime \ - --observed-surface visible_resume_prompt \ - --turn-state idle \ - --probe-human-input-idle \ - --checked-before-prompt \ - --visible-to-user \ - --user-can-interrupt \ - --manual-takeover-available -``` - -This detector accepts either a public-safe fixture or a narrow local -observation adapter. The local adapter may probe a coarse platform idle counter -for "no recent human input" and requires an explicit visible `--turn-state -idle`; unknown or running turn state fails closed. It is deliberately separate -from the visible-session proof: the proof says "this route can create a -visible, interruptible turn"; the idle detector says "this exact later turn is -not racing human typing or an already-running Codex turn." It must prove no -active human typing, no running turn, and no -transcript/session/stdout/stderr/credential reads before LoopX treats a -later visible prompt as executable. - -For reproducible tests or external sensors, the fixture path remains: - -```bash -loopx codex-cli-runtime-idle-detector \ - --project . \ - --goal-id \ - --agent-id \ - --idle-fixture runtime-idle.public.json -``` - -Current same-TUI acceptance packet: - -```bash -loopx codex-cli-visible-attach-acceptance \ - --project . \ - --goal-id \ - --agent-id \ - --proof-fixture visible-proof.public.json \ - --idle-fixture runtime-idle.public.json -``` - -This packet is the promotion gate before LoopX treats later Codex CLI -automation as safe same-TUI attach. It composes the help-only probe, -visible-session proof, and runtime-idle detector. `remote-control` or `resume -[PROMPT]` can pass as a visible spike candidate, but they are not accepted as -same-TUI automation unless the proof surface is `same_tui_visible_attach` and -the idle detector passes. If either proof or idle evidence is missing, the -packet returns a precise blocker and keeps the one-message setup bootstrap as the -primary path. - -The first public-safe proof pilot is recorded in -[Codex CLI Visible Attach Proof Pilot](codex-cli-visible-attach-proof-pilot.md): -current `resume` / `remote-control` evidence is promising, but still blocked -until a visible same-TUI proof and runtime-idle evidence exist. - -The repeatable capture path is defined in -[Codex CLI Visible Proof Capture Protocol](codex-cli-visible-proof-capture-protocol.md). -It treats `resume` / `remote-control` as proof targets, keeps fixtures -public-safe, and records blocker-first stop conditions before any later visible -turn is promoted. +mode. Explicit non-TUI isolated headless execution is handled by `loopx turn` +(`turn_driver/codex_cli.py`), see [LoopX Turn quickstart](loopx-turn-codex-cli-quickstart.md) +and [Automation driver audit](codex-cli-automation-driver.md). ### 3. Headless Disabled Boundary -`codex exec` remains useful for scheduled or CI-like work, but it is not the -primary product experience for interactive users. The default Codex CLI -LoopX setup-then-`/goal` path does not expose a headless fallback, even -as an opt-in, so a first-run packet cannot accidentally move work into hidden -execution. - -Compatibility boundary: - -```bash -loopx codex-cli-exec-handoff --project . --goal-id -``` - -This command no longer prints a runnable `codex exec` handoff script. It -reports the disabled boundary and points back to -`codex-cli-bootstrap-message --message-only` for use inside the visible TUI. -It does not run Codex, read transcripts, read credentials, read session files, -mutate a session, or spend quota. +`codex exec` remains useful for scheduled or CI-like work via `loopx turn`, but +it is not the primary product experience for interactive users. The default +Codex CLI LoopX setup-then-`/goal` path does not expose a headless fallback, +even as an opt-in, so a first-run packet cannot accidentally move work into +hidden execution. The older pre-Turn pilot and probe subcommands have been +retired in favor of `loopx codex-cli-bootstrap-message`, `loopx start-goal`, +and `loopx turn`. ## Session-Attached Turn Algorithm @@ -411,62 +183,18 @@ projects runnable candidates; it should not over-specify the model's local plan. 1. **Bootstrap prompt**: ship a concise Codex CLI TUI paste message in README and getting-started docs. 2. **No-clone install repair**: make the first-run agent path able to install - the CLI and reusable skills from a GitHub archive, while reserving + the CLI and reusable skills from PyPI or a GitHub archive, while reserving clone-plus-canary setup for contributors. -3. **Bootstrap command**: add a LoopX command that prints a tailored +3. **Bootstrap command**: `loopx codex-cli-bootstrap-message` prints a tailored Codex CLI bootstrap message for the current repo. -4. **One-message loop pilot**: ship - `loopx codex-cli-one-message-loop-pilot` to bind the first TUI paste - message and the later scheduler/executor bridge into one public-safe packet. -5. **Session probe**: document whether current Codex CLI exposes a stable - session id, resume handle, or safe injection primitive. The current - implementation is `loopx codex-cli-session-probe`; it separates - headless-disabled execution support, visible resume / remote-control spike - surfaces, and true same-open-TUI visible injection. -6. **Visible driver plan**: generate a dry-run plan with - `loopx codex-cli-visible-driver-plan` so the next local driver knows - whether to attempt visible attach, run a resume/remote-control proof, or - keep the one-message setup bootstrap as the product path. -7. **Local driver planner**: ship - `loopx codex-cli-local-driver-plan` as the dry-run command that - composes quota, visible-driver, TUI bootstrap, headless-disabled boundary, - and idle-guard requirements. -8. **Visible-session proof harness**: validate public-safe observations with - `loopx codex-cli-visible-session-proof` before promoting - resume/remote-control into any same-session automation path. -9. **Visible driver run packet**: add - `loopx codex-cli-visible-driver-run` as the no-execution packet that - decides whether the next turn needs visible proof, TUI bootstrap, or a - proven visible-session candidate. -10. **Local scheduler tick**: add - `loopx codex-cli-local-scheduler-tick` as the first executor-facing - one-shot packet. It emits either an external command candidate or a precise - blocker writeback command, but does not run Codex, read session files, or - write LoopX state itself. Visible candidates require both - visible-session proof and runtime-idle detector approval; headless fallback - remains disabled for the default `/goal` path. -11. **Local scheduler executor wrapper**: add - `loopx codex-cli-local-scheduler-exec` as the explicit opt-in bridge - that can run one tick result only after guard confirmation, runtime-idle - approval for visible candidates, and an allowed command prefix. -12. **Visible local driver pilot**: ship - `loopx codex-cli-visible-local-driver-pilot` to bind the one-message - TUI start, scheduler executor, visible proof, idle guard, and no-transcript - boundary into one public-safe packet. -13. **Runtime idle detector**: validate public-safe idle evidence with - `loopx codex-cli-runtime-idle-detector` before a visible later turn; - the command now supports fixture replay and a narrow local observation - adapter that can prove coarse human-input idle plus explicit visible - turn-state without reading transcripts, stdout/stderr, credentials, or - hidden session files. -14. **Visible attach acceptance**: promote only a proven `same_tui_visible_attach` - route with passing runtime-idle evidence; keep `resume [PROMPT]` and - `remote-control` as visible spike candidates until they prove same-TUI - semantics. -15. **Validation harness**: add a public-safe fixture that proves the driver - never stores raw transcript text and never spends quota before writeback. -16. **Claude Code follow-up**: port the same product contract only after the - Codex CLI path is credible. +4. **LoopX Turn driver**: `loopx turn plan` and `loopx turn run-once` + (`turn_driver/codex_cli.py`) replace the older pre-Turn pilot and probe + commands for bounded isolated-headless execution, validation, durable + writeback, and quota spend. +5. **Same-open-TUI attach**: `interactive-visible` remains gated until Codex CLI + exposes a verified safe attach primitive with idle and interruption guarantees. +6. **Claude Code follow-up**: port the same product contract across hosts via the + shared `start-goal` and `agent-onboard` surfaces. ## Success Criteria diff --git a/docs/product/runtimes/codex-cli/codex-cli-visible-attach-proof-pilot.md b/docs/product/runtimes/codex-cli/codex-cli-visible-attach-proof-pilot.md deleted file mode 100644 index 66bb29d6bb..0000000000 --- a/docs/product/runtimes/codex-cli/codex-cli-visible-attach-proof-pilot.md +++ /dev/null @@ -1,65 +0,0 @@ -# Codex CLI Visible Attach Proof Pilot - -Status: blocker recorded, TUI bootstrap remains primary. -Recorded: 2026-06-21. - -This note records the first public-safe proof pilot for LoopX steering a -later Codex CLI turn without taking the user out of the visible TUI. It uses the -`codex-cli-visible-attach-acceptance` packet added in PR #383. - -## Question - -Can LoopX safely add a later steering turn to the same open Codex CLI TUI -session today? - -## Result - -Not yet. - -The current Codex CLI help surface exposes promising `resume` / -`remote-control` style capabilities, so this remains worth exploring. But the -available help-only evidence does not prove a safe same-TUI attach primitive. -The acceptance packet returns: - -- `decision`: `visible_session_proof_required` -- `accepted_for_same_tui_automation`: `False` -- `accepted_for_visible_later_turn`: `False` -- `driver_mode`: `visible_resume_or_remote_control_spike` -- blocker: `visible_session_proof_missing` - -## Boundary - -This pilot did not: - -- run Codex CLI delivery; -- read raw transcripts; -- read session files; -- read stdout/stderr streams; -- read credentials; -- mutate a Codex session; -- spend LoopX quota by itself. - -## Interpretation - -`resume [PROMPT]` and `remote-control` are not enough on their own. They may be -usable as a visible spike, but LoopX should not call them -same-TUI automation until a public-safe proof shows: - -- the resulting turn is visible to the user; -- the user can interrupt or take over; -- a runtime idle detector passed immediately before the turn; -- the route does not require transcript/session-file reads; -- compact evidence or a blocker will be written before quota spend. - -Until that proof exists, the product-safe path stays: - -1. Start from one Codex CLI TUI bootstrap message. -2. Keep later automation in no-execution packet mode. -3. Use `codex exec` only as an explicit opt-in headless fallback. - -## Next Step - -Run a visible `resume` / `remote-control` proof only when it can be captured as -a public-safe fixture with user opt-in and runtime-idle evidence. If that proof -cannot be captured without reading private session material or racing the TUI, -keep this blocker and continue improving the one-message TUI bootstrap path. diff --git a/docs/product/runtimes/codex-cli/codex-cli-visible-proof-capture-protocol.md b/docs/product/runtimes/codex-cli/codex-cli-visible-proof-capture-protocol.md deleted file mode 100644 index 1ddd7e786f..0000000000 --- a/docs/product/runtimes/codex-cli/codex-cli-visible-proof-capture-protocol.md +++ /dev/null @@ -1,163 +0,0 @@ -# Codex CLI Visible Proof Capture Protocol - -Status: public-safe protocol for opt-in proof capture. -Primary path: one-message Codex CLI TUI bootstrap. - -This protocol turns a promising Codex CLI `resume` / `remote-control` surface -into evidence, not authority. LoopX may only promote later visible -automation after a public-safe proof shows the turn is visible, interruptible, -freshly idle-guarded, and independent of transcripts, session files, stdout, -stderr, credentials, or hidden session mutation. - -## When To Use It - -Use this protocol only when all of these are true: - -- the user has already started from a normal Codex CLI TUI flow or explicitly - opted into a proof run; -- `quota should-run` allows this LoopX turn; -- the test prompt is public-safe and does not depend on private repo state; -- the candidate surface is one of `visible_resume_prompt`, - `remote_control_visible_prompt`, or `same_tui_visible_attach`; -- the goal is to prove visibility, not to deliver production work. - -If any condition is missing, keep the one-message TUI bootstrap as the product -path and record a blocker instead of attempting a later visible turn. - -## Capture Packet - -The durable packet is two public-safe fixtures plus the acceptance result. -The public demo bundle in -[Codex CLI Proof-Capture Demo](codex-cli-proof-capture-demo.md) provides sample -fixtures for both a visible `resume` spike and a future same-TUI attach proof. - -### Visible-Session Proof Fixture - -```json -{ - "observed_surface": "visible_resume_prompt", - "user_opt_in": true, - "quota_guard": { "passed": true }, - "idle_guard": { - "no_active_human_typing": true, - "no_running_turn": true, - "checked_before_prompt": true - }, - "turn_visibility": { - "visible_to_user": true, - "prompt_public_safe": true - }, - "interruptibility": { - "user_can_interrupt": true, - "manual_takeover_available": true - }, - "boundary": { - "reads_raw_transcripts": false, - "reads_session_files": false, - "reads_credentials": false, - "mutates_hidden_session_state": false, - "spends_quota_before_writeback": false - }, - "writeback": { "compact_evidence_planned": true } -} -``` - -### Runtime-Idle Fixture - -```json -{ - "observed_surface": "visible_resume_prompt", - "idle_guard": { - "no_active_human_typing": true, - "no_running_turn": true, - "checked_before_prompt": true - }, - "turn_visibility": { "visible_to_user": true }, - "interruptibility": { - "user_can_interrupt": true, - "manual_takeover_available": true - }, - "boundary": { - "reads_raw_transcripts": false, - "reads_session_files": false, - "reads_stdout_stderr": false, - "reads_credentials": false, - "mutates_hidden_session_state": false - } -} -``` - -Fixtures may include compact public labels such as `operator_initials`, -`proof_started_at`, `proof_result`, or `blocker`, but they must not include -screenshots, raw prompts from private work, raw model output, local session ids, -absolute local paths, credentials, internal document links, or command output -bodies. - -## Procedure - -1. Pick a public-safe fixture repo or demo goal. -2. Run `quota should-run` with the registered `agent_id`; stop if the user - channel requires action. -3. Confirm explicit user opt-in for the proof. The user must know the proof is - testing visibility, not doing production work. -4. Capture or generate fresh runtime-idle evidence immediately before the - candidate prompt. Unknown turn state, recent typing, or a running turn fails - closed. -5. Attempt only a visible proof prompt with an allowed command prefix. The - prompt should say that LoopX is testing visible steering and should - be safe to interrupt. -6. Record only the compact fixture booleans and public-safe labels above. -7. Validate the fixtures: - -```bash -loopx codex-cli-visible-session-proof \ - --project . \ - --goal-id \ - --agent-id \ - --proof-fixture visible-proof.public.json - -loopx codex-cli-runtime-idle-detector \ - --project . \ - --goal-id \ - --agent-id \ - --idle-fixture runtime-idle.public.json - -loopx codex-cli-visible-attach-acceptance \ - --project . \ - --goal-id \ - --agent-id \ - --proof-fixture visible-proof.public.json \ - --idle-fixture runtime-idle.public.json -``` - -8. Write back the acceptance result. Spend quota only after the blocker or - evidence is written back and validation has passed. - -## Promotion Rules - -`visible_resume_prompt` and `remote_control_visible_prompt` can prove a useful -visible spike, but they do not prove same-open-TUI automation. They remain -experimental until a later proof captures `same_tui_visible_attach`. - -Only `same_tui_visible_attach` plus a passing runtime-idle detector may promote -the route toward a same-TUI automation driver. Even then, the next step is a -separate wiring task behind fresh quota guard, fresh idle guard, explicit -command boundary, and compact writeback. - -## Stop Conditions - -Stop and record a blocker when any of these happen: - -- no explicit proof opt-in; -- `interaction_contract.user_channel.action_required=true`; -- runtime-idle state is unknown, recently active, or already running; -- the candidate needs transcript, session-file, stdout/stderr, credential, or - hidden runtime reads; -- the route writes hidden Codex session state; -- the prompt is not visible, not interruptible, or not manually recoverable; -- the command prefix is not explicitly allowed; -- the proof would expose private repo names, task ids, internal links, local - paths, screenshots, or raw session material. - -The safe fallback is always to keep the one-message TUI bootstrap visible and -write the precise blocker into LoopX. diff --git a/examples/canary/catalog-planner-smoke.py b/examples/canary/catalog-planner-smoke.py index f27dc612cf..a3c1e19ff3 100644 --- a/examples/canary/catalog-planner-smoke.py +++ b/examples/canary/catalog-planner-smoke.py @@ -708,7 +708,7 @@ def assert_pr_release_and_refactor_profiles_select() -> None: ] assert "python3 examples/control_plane/heartbeat-prompt-smoke.py" in runtime_connector_commands assert ( - "python3 examples/codex-cli-tui-bootstrap-smoke-bundle-smoke.py" + "python3 examples/codex-cli-bootstrap-message-smoke.py" in runtime_connector_commands ) assert "python3 examples/claude-goalmode-lifecycle-smoke.py" in runtime_connector_commands diff --git a/examples/cli-command-module-size-ownership-command-modularization-smoke.py b/examples/cli-command-module-size-ownership-command-modularization-smoke.py index 8cefe282a2..34b6f02885 100644 --- a/examples/cli-command-module-size-ownership-command-modularization-smoke.py +++ b/examples/cli-command-module-size-ownership-command-modularization-smoke.py @@ -16,12 +16,6 @@ "starter.py": 180, "starter_bootstrap.py": 220, "starter_bootstrap_registration.py": 240, - "starter_runtime_idle.py": 160, - "starter_scheduler.py": 240, - "starter_session_runtime.py": 220, - "starter_visible_common.py": 120, - "starter_visible_driver.py": 220, - "starter_visible_pilot.py": 340, } STARTER_COMMAND_OWNERS = { "start-goal": "start_goal.py", @@ -29,21 +23,6 @@ "deliver-operation": "goal_channel_operation.py", "new-project-prompt": "starter_bootstrap_registration.py", "codex-cli-bootstrap-message": "starter_bootstrap_registration.py", - "codex-cli-tui-bootstrap-smoke-bundle": "starter_bootstrap_registration.py", - "codex-cli-exec-handoff": "starter_bootstrap_registration.py", - "codex-cli-one-message-loop-pilot": "starter_visible_pilot.py", - "codex-cli-visible-local-driver-pilot": "starter_visible_pilot.py", - "codex-cli-bounded-visible-pilot-adapter": "starter_visible_pilot.py", - "codex-cli-visible-first-response-capture-plan": "starter_visible_pilot.py", - "codex-cli-visible-attach-acceptance": "starter_visible_pilot.py", - "codex-cli-visible-driver-plan": "starter_visible_driver.py", - "codex-cli-local-driver-plan": "starter_visible_driver.py", - "codex-cli-visible-driver-run": "starter_visible_driver.py", - "codex-cli-session-probe": "starter_session_runtime.py", - "codex-cli-visible-session-proof": "starter_session_runtime.py", - "codex-cli-runtime-idle-detector": "starter_session_runtime.py", - "codex-cli-local-scheduler-tick": "starter_scheduler.py", - "codex-cli-local-scheduler-exec": "starter_scheduler.py", } ADD_PARSER_RE = re.compile( diff --git a/examples/cli-help-manpage-smoke.py b/examples/cli-help-manpage-smoke.py index 218781f737..cdc8d506e6 100644 --- a/examples/cli-help-manpage-smoke.py +++ b/examples/cli-help-manpage-smoke.py @@ -30,7 +30,7 @@ ) -LONG_TAIL_COMMAND = "codex-cli-visible-first-response-capture-plan" +LONG_TAIL_COMMAND = "configuration-backup" def run_cli(*args: str) -> subprocess.CompletedProcess[str]: diff --git a/examples/cli-starter-bootstrap-family-command-modularization-smoke.py b/examples/cli-starter-bootstrap-family-command-modularization-smoke.py deleted file mode 100644 index 68002f731f..0000000000 --- a/examples/cli-starter-bootstrap-family-command-modularization-smoke.py +++ /dev/null @@ -1,190 +0,0 @@ -#!/usr/bin/env python3 -from __future__ import annotations - -import json -import subprocess -import sys -from pathlib import Path - - -ROOT = Path(__file__).resolve().parents[1] -STARTER = ROOT / "loopx" / "cli_commands" / "starter.py" -BOOTSTRAP = ROOT / "loopx" / "cli_commands" / "starter_bootstrap.py" -BOOTSTRAP_REGISTRATION = ROOT / "loopx" / "cli_commands" / "starter_bootstrap_registration.py" -START_GOAL = ROOT / "loopx" / "cli_commands" / "start_goal.py" -INIT = ROOT / "loopx" / "cli_commands" / "__init__.py" - - -def run_cli(*args: str) -> subprocess.CompletedProcess[str]: - return subprocess.run( - [sys.executable, "-m", "loopx.cli", *args], - cwd=ROOT, - text=True, - capture_output=True, - check=False, - ) - - -def require(condition: bool, message: str) -> None: - if not condition: - raise AssertionError(message) - - -def require_success(result: subprocess.CompletedProcess[str]) -> str: - if result.returncode != 0: - raise AssertionError( - f"expected success, got {result.returncode}\n" - f"stdout:\n{result.stdout}\n\nstderr:\n{result.stderr}" - ) - return result.stdout - - -def require_json_success(result: subprocess.CompletedProcess[str]) -> dict[str, object]: - payload = json.loads(require_success(result)) - require(isinstance(payload, dict), "expected JSON object payload") - require(payload.get("ok") is True, f"payload was not ok: {payload}") - return payload - - -def assert_source_shape() -> None: - starter_source = STARTER.read_text(encoding="utf-8") - bootstrap_source = BOOTSTRAP.read_text(encoding="utf-8") - registration_source = BOOTSTRAP_REGISTRATION.read_text(encoding="utf-8") - start_goal_source = START_GOAL.read_text(encoding="utf-8") - init_source = INIT.read_text(encoding="utf-8") - - forbidden_starter_markers = [ - "DEFAULT_HANDOFF_ADAPTER_KIND", - "build_new_project_prompt(", - "render_new_project_prompt_markdown", - "build_codex_cli_bootstrap_message(", - "render_codex_cli_bootstrap_message_markdown", - "build_codex_cli_tui_bootstrap_smoke_bundle(", - "build_codex_cli_exec_handoff(", - "def handle_new_project_prompt_command(", - "def handle_codex_cli_bootstrap_message_command(", - "def handle_codex_cli_tui_bootstrap_smoke_bundle_command(", - "def handle_codex_cli_exec_handoff_command(", - ] - for marker in forbidden_starter_markers: - require(marker not in starter_source, f"bootstrap/message marker leaked into starter.py: {marker}") - - for marker in ( - "register_starter_bootstrap_commands(subparsers)", - "handle_starter_bootstrap_command(args, print_payload)", - ): - require(marker in starter_source, f"starter.py missing bootstrap delegation marker: {marker}") - - for marker in ( - "def handle_starter_bootstrap_command(", - "def handle_new_project_prompt_command(", - "def handle_codex_cli_bootstrap_message_command(", - "def handle_codex_cli_tui_bootstrap_smoke_bundle_command(", - "def handle_codex_cli_exec_handoff_command(", - "build_new_project_prompt(", - "build_codex_cli_exec_handoff(", - ): - require(marker in bootstrap_source, f"starter_bootstrap.py missing marker: {marker}") - - for marker in ( - "def register_starter_bootstrap_commands(", - 'subparsers.add_parser(\n "agent-onboard"', - 'subparsers.add_parser(\n "bootstrap-command-pack"', - 'subparsers.add_parser(\n "new-project-prompt"', - ): - require( - marker in registration_source, - f"starter_bootstrap_registration.py missing marker: {marker}", - ) - - for marker in ( - "def register_start_goal_command(", - 'subparsers.add_parser(\n "start-goal"', - ): - require( - marker in start_goal_source, - f"start_goal.py missing marker: {marker}", - ) - - for marker in ( - "handle_starter_bootstrap_command", - "register_starter_bootstrap_commands", - "handle_new_project_prompt_command", - "handle_codex_cli_exec_handoff_command", - ): - require(marker in init_source, f"__init__ omitted bootstrap export: {marker}") - - -def assert_cli_surfaces() -> None: - for command, needles in { - "new-project-prompt": ["--goal-doc", "--adapter-status", "--write-scope"], - "codex-cli-bootstrap-message": ["--agent-id", "--message-only"], - "codex-cli-tui-bootstrap-smoke-bundle": ["--agent-id", "--cli-bin"], - "codex-cli-exec-handoff": ["--codex-bin", "--cli-bin"], - }.items(): - help_text = require_success(run_cli(command, "--help")) - for needle in needles: - require(needle in help_text, f"{command} help omitted {needle}") - - prompt_payload = require_json_success( - run_cli( - "--format", - "json", - "new-project-prompt", - "--project", - ".", - "--goal-doc", - "README.md", - "--goal-id", - "starter-bootstrap-smoke", - ) - ) - require(prompt_payload.get("goal_id") == "starter-bootstrap-smoke", prompt_payload) - - bootstrap_text = require_success( - run_cli( - "codex-cli-bootstrap-message", - "--project", - ".", - "--goal-id", - "starter-bootstrap-smoke", - "--message-only", - ) - ) - require("loopx" in bootstrap_text, "bootstrap message lost LoopX text") - - bundle_payload = require_json_success( - run_cli( - "--format", - "json", - "codex-cli-tui-bootstrap-smoke-bundle", - "--project", - ".", - "--goal-id", - "starter-bootstrap-smoke", - ) - ) - require(bundle_payload.get("goal_id") == "starter-bootstrap-smoke", bundle_payload) - - handoff_payload = require_json_success( - run_cli( - "--format", - "json", - "codex-cli-exec-handoff", - "--project", - ".", - "--goal-id", - "starter-bootstrap-smoke", - ) - ) - require(handoff_payload.get("goal_id") == "starter-bootstrap-smoke", handoff_payload) - - -def main() -> None: - assert_source_shape() - assert_cli_surfaces() - print("cli-starter-bootstrap-family-command-modularization-smoke: ok") - - -if __name__ == "__main__": - main() diff --git a/examples/cli-starter-dispatch-command-modularization-smoke.py b/examples/cli-starter-dispatch-command-modularization-smoke.py deleted file mode 100644 index ecf68c69ae..0000000000 --- a/examples/cli-starter-dispatch-command-modularization-smoke.py +++ /dev/null @@ -1,209 +0,0 @@ -#!/usr/bin/env python3 -from __future__ import annotations - -import json -import subprocess -import sys -from pathlib import Path - - -ROOT = Path(__file__).resolve().parents[1] -CLI = ROOT / "loopx" / "cli.py" -STARTER_MODULE = ROOT / "loopx" / "cli_commands" / "starter.py" -VISIBLE_DRIVER_MODULE = ROOT / "loopx" / "cli_commands" / "starter_visible_driver.py" -SCHEDULER_MODULE = ROOT / "loopx" / "cli_commands" / "starter_scheduler.py" -SESSION_RUNTIME_MODULE = ROOT / "loopx" / "cli_commands" / "starter_session_runtime.py" -INIT = ROOT / "loopx" / "cli_commands" / "__init__.py" - - -def run_cli(*args: str) -> subprocess.CompletedProcess[str]: - return subprocess.run( - [sys.executable, "-m", "loopx.cli", *args], - cwd=ROOT, - text=True, - capture_output=True, - check=False, - ) - - -def require(condition: bool, message: str) -> None: - if not condition: - raise AssertionError(message) - - -def require_success(result: subprocess.CompletedProcess[str]) -> str: - if result.returncode != 0: - raise AssertionError( - f"expected success, got {result.returncode}\n" - f"stdout:\n{result.stdout}\n\nstderr:\n{result.stderr}" - ) - return result.stdout - - -def require_json_success(result: subprocess.CompletedProcess[str]) -> dict[str, object]: - payload = json.loads(require_success(result)) - require(isinstance(payload, dict), "expected JSON object payload") - require(payload.get("ok") is True, f"payload was not ok: {payload}") - return payload - - -def assert_source_shape() -> None: - cli_source = CLI.read_text(encoding="utf-8") - starter_source = STARTER_MODULE.read_text(encoding="utf-8") - visible_driver_source = VISIBLE_DRIVER_MODULE.read_text(encoding="utf-8") - scheduler_source = SCHEDULER_MODULE.read_text(encoding="utf-8") - session_runtime_source = SESSION_RUNTIME_MODULE.read_text(encoding="utf-8") - init_source = INIT.read_text(encoding="utf-8") - - starter_commands = [ - "new-project-prompt", - "codex-cli-bootstrap-message", - "codex-cli-tui-bootstrap-smoke-bundle", - "codex-cli-one-message-loop-pilot", - "codex-cli-visible-local-driver-pilot", - "codex-cli-bounded-visible-pilot-adapter", - "codex-cli-visible-first-response-capture-plan", - "codex-cli-visible-attach-acceptance", - "codex-cli-exec-handoff", - "codex-cli-session-probe", - "codex-cli-visible-driver-plan", - "codex-cli-local-driver-plan", - "codex-cli-visible-driver-run", - "codex-cli-local-scheduler-tick", - "codex-cli-local-scheduler-exec", - "codex-cli-visible-session-proof", - "codex-cli-runtime-idle-detector", - "demo", - ] - for command in starter_commands: - marker = f'if args.command == "{command}":' - require(marker not in cli_source, f"starter dispatch branch leaked into cli.py: {marker}") - - forbidden_handler_markers = [ - "handle_new_project_prompt_command(", - "handle_codex_cli_bootstrap_message_command(", - "handle_codex_cli_visible_driver_run_command(", - "handle_codex_cli_local_scheduler_exec_command(", - "handle_demo_command(", - ] - for marker in forbidden_handler_markers: - require(marker not in cli_source, f"starter handler marker leaked into cli.py: {marker}") - - require("register_starter_commands(sub)" in cli_source, "cli.py did not register starter commands") - require("handle_starter_command(args, print_payload)" in cli_source, "cli.py did not call starter dispatcher") - require("def handle_starter_command(" in starter_source, "starter module omitted dispatcher") - require( - "register_starter_visible_driver_commands(subparsers)" in starter_source, - "starter module omitted visible-driver registration delegation", - ) - require( - "handle_starter_visible_driver_command(args, print_payload)" in starter_source, - "starter module omitted visible-driver dispatch delegation", - ) - require( - "register_starter_session_runtime_commands(subparsers)" in starter_source, - "starter module omitted session-runtime registration delegation", - ) - require( - "handle_starter_session_runtime_command(args, print_payload)" in starter_source, - "starter module omitted session-runtime dispatch delegation", - ) - require( - "register_starter_scheduler_commands(subparsers)" in starter_source, - "starter module omitted scheduler registration delegation", - ) - require( - "handle_starter_scheduler_command(args, print_payload)" in starter_source, - "starter module omitted scheduler dispatch delegation", - ) - require( - '"codex-cli-visible-driver-run": handle_codex_cli_visible_driver_run_command' in visible_driver_source, - "visible-driver module omitted visible driver run dispatch", - ) - require( - '"codex-cli-local-scheduler-exec": handle_codex_cli_local_scheduler_exec_command' in scheduler_source, - "scheduler module omitted local scheduler exec dispatch", - ) - require( - '"codex-cli-runtime-idle-detector": handle_codex_cli_runtime_idle_detector_command' in session_runtime_source, - "session-runtime module omitted runtime idle dispatch", - ) - require('str(getattr(args, "command", "")) == "demo"' in starter_source, "starter dispatcher omitted demo") - require("handle_starter_command" in init_source, "__init__ omitted starter dispatcher export") - - -def assert_cli_surfaces() -> None: - help_expectations = { - "new-project-prompt": ["--goal-doc", "--write-scope"], - "codex-cli-bootstrap-message": ["--agent-id", "--message-only"], - "codex-cli-visible-driver-run": ["--proof-fixture", "--allow-headless-fallback"], - "codex-cli-local-scheduler-exec": ["--guard-checked", "--candidate-command-prefix", "--quota-fixture"], - "demo": ["--user-todo", "--agent-todo"], - } - for command, needles in help_expectations.items(): - help_text = require_success(run_cli(command, "--help")) - for needle in needles: - require(needle in help_text, f"{command} help omitted {needle}") - - prompt_payload = require_json_success( - run_cli( - "--format", - "json", - "new-project-prompt", - "--project", - ".", - "--goal-doc", - "README.md", - "--goal-id", - "starter-dispatch-smoke", - ) - ) - require(prompt_payload.get("goal_id") == "starter-dispatch-smoke", prompt_payload) - - bootstrap_text = require_success( - run_cli( - "codex-cli-bootstrap-message", - "--project", - ".", - "--goal-id", - "starter-dispatch-smoke", - "--message-only", - ) - ) - require("loopx" in bootstrap_text, "message-only bootstrap output lost LoopX command text") - - capture_payload = require_json_success( - run_cli( - "--format", - "json", - "codex-cli-visible-first-response-capture-plan", - "--project", - ".", - "--goal-id", - "starter-dispatch-smoke", - ) - ) - require(capture_payload.get("goal_id") == "starter-dispatch-smoke", capture_payload) - - handoff_payload = require_json_success( - run_cli( - "--format", - "json", - "codex-cli-exec-handoff", - "--project", - ".", - "--goal-id", - "starter-dispatch-smoke", - ) - ) - require(handoff_payload.get("goal_id") == "starter-dispatch-smoke", handoff_payload) - - -def main() -> None: - assert_source_shape() - assert_cli_surfaces() - print("cli-starter-dispatch-command-modularization-smoke: ok") - - -if __name__ == "__main__": - main() diff --git a/examples/cli-starter-runtime-family-command-modularization-smoke.py b/examples/cli-starter-runtime-family-command-modularization-smoke.py deleted file mode 100644 index 64c9bd9530..0000000000 --- a/examples/cli-starter-runtime-family-command-modularization-smoke.py +++ /dev/null @@ -1,221 +0,0 @@ -#!/usr/bin/env python3 -from __future__ import annotations - -import json -import subprocess -import sys -from pathlib import Path - - -ROOT = Path(__file__).resolve().parents[1] -STARTER = ROOT / "loopx" / "cli_commands" / "starter.py" -SCHEDULER = ROOT / "loopx" / "cli_commands" / "starter_scheduler.py" -SESSION_RUNTIME = ROOT / "loopx" / "cli_commands" / "starter_session_runtime.py" -RUNTIME_IDLE = ROOT / "loopx" / "cli_commands" / "starter_runtime_idle.py" -INIT = ROOT / "loopx" / "cli_commands" / "__init__.py" -VISIBLE_HELP_FIXTURE = ( - ROOT / "examples" / "fixtures" / "codex-cli-visible-proof" / "codex-visible-resume-help.public.json" -) -VISIBLE_PROOF_FIXTURE = ( - ROOT / "examples" / "fixtures" / "codex-cli-visible-proof" / "visible-resume-proof.public.json" -) -RUNTIME_IDLE_FIXTURE = ( - ROOT / "examples" / "fixtures" / "codex-cli-visible-proof" / "runtime-idle-visible-resume.public.json" -) - - -SESSION_RUNTIME_COMMANDS = { - "codex-cli-session-probe": ["--fixture", "--codex-bin"], - "codex-cli-visible-session-proof": ["--proof-fixture", "--cli-bin"], - "codex-cli-runtime-idle-detector": ["--idle-fixture", "--observe-local-runtime"], -} -SCHEDULER_COMMANDS = { - "codex-cli-local-scheduler-tick": ["--proof-fixture", "--idle-fixture", "--quota-fixture", "--allow-headless-fallback"], - "codex-cli-local-scheduler-exec": ["--guard-checked", "--candidate-command-prefix", "--quota-fixture", "--executor-timeout-seconds"], -} - - -def run_cli(*args: str) -> subprocess.CompletedProcess[str]: - return subprocess.run( - [sys.executable, "-m", "loopx.cli", *args], - cwd=ROOT, - text=True, - capture_output=True, - check=False, - ) - - -def require(condition: bool, message: str) -> None: - if not condition: - raise AssertionError(message) - - -def require_success(result: subprocess.CompletedProcess[str]) -> str: - if result.returncode != 0: - raise AssertionError( - f"expected success, got {result.returncode}\n" - f"stdout:\n{result.stdout}\n\nstderr:\n{result.stderr}" - ) - return result.stdout - - -def require_json_success(result: subprocess.CompletedProcess[str]) -> dict[str, object]: - payload = json.loads(require_success(result)) - require(isinstance(payload, dict), "expected JSON object payload") - require(payload.get("ok") is True, f"payload was not ok: {payload}") - return payload - - -def assert_source_shape() -> None: - starter_source = STARTER.read_text(encoding="utf-8") - scheduler_source = SCHEDULER.read_text(encoding="utf-8") - session_runtime_source = SESSION_RUNTIME.read_text(encoding="utf-8") - runtime_idle_source = RUNTIME_IDLE.read_text(encoding="utf-8") - init_source = INIT.read_text(encoding="utf-8") - - forbidden_starter_markers = [ - "codex-cli-session-probe", - "codex-cli-local-scheduler-tick", - "codex-cli-local-scheduler-exec", - "codex-cli-visible-session-proof", - "codex-cli-runtime-idle-detector", - "def handle_codex_cli_session_probe_command(", - "def handle_codex_cli_local_scheduler_tick_command(", - "def handle_codex_cli_local_scheduler_exec_command(", - "def handle_codex_cli_visible_session_proof_command(", - "def handle_codex_cli_runtime_idle_detector_command(", - "build_codex_cli_local_scheduler_tick(", - "build_codex_cli_local_scheduler_executor(", - "build_codex_cli_visible_session_proof(", - "build_codex_cli_runtime_idle_detector(", - ] - for marker in forbidden_starter_markers: - require(marker not in starter_source, f"runtime/scheduler marker leaked into starter.py: {marker}") - - for marker in ( - "register_starter_session_runtime_commands(subparsers)", - "handle_starter_session_runtime_command(args, print_payload)", - "register_starter_scheduler_commands(subparsers)", - "handle_starter_scheduler_command(args, print_payload)", - ): - require(marker in starter_source, f"starter.py missing delegation marker: {marker}") - - for command in SESSION_RUNTIME_COMMANDS: - require(command in session_runtime_source, f"starter_session_runtime.py missing command: {command}") - for marker in ( - "def register_starter_session_runtime_commands(", - "def handle_starter_session_runtime_command(", - "_SESSION_RUNTIME_HANDLERS", - "build_codex_cli_visible_session_proof(", - "build_codex_cli_runtime_idle_detector(", - ): - require(marker in session_runtime_source, f"starter_session_runtime.py missing marker: {marker}") - - for command in SCHEDULER_COMMANDS: - require(command in scheduler_source, f"starter_scheduler.py missing command: {command}") - for marker in ( - "def register_starter_scheduler_commands(", - "def handle_starter_scheduler_command(", - "_SCHEDULER_HANDLERS", - "build_codex_cli_local_scheduler_tick(", - "build_codex_cli_local_scheduler_executor(", - ): - require(marker in scheduler_source, f"starter_scheduler.py missing marker: {marker}") - - for marker in ( - "def _add_runtime_idle_observation_arguments(", - "def _load_codex_cli_runtime_idle_payload(", - ): - require(marker in runtime_idle_source, f"starter_runtime_idle.py missing marker: {marker}") - - for marker in ( - "handle_starter_scheduler_command", - "register_starter_scheduler_commands", - "handle_starter_session_runtime_command", - "register_starter_session_runtime_commands", - "handle_codex_cli_runtime_idle_detector_command", - "handle_codex_cli_local_scheduler_exec_command", - ): - require(marker in init_source, f"__init__ omitted runtime/scheduler export: {marker}") - - -def assert_cli_surfaces() -> None: - for command, needles in {**SESSION_RUNTIME_COMMANDS, **SCHEDULER_COMMANDS}.items(): - help_text = require_success(run_cli(command, "--help")) - for needle in needles: - require(needle in help_text, f"{command} help omitted {needle}") - - probe_payload = require_json_success( - run_cli( - "--format", - "json", - "codex-cli-session-probe", - "--fixture", - str(VISIBLE_HELP_FIXTURE), - ) - ) - require(probe_payload.get("recommended_mode") == "visible_resume_or_remote_control_spike", probe_payload) - - proof_payload = require_json_success( - run_cli( - "--format", - "json", - "codex-cli-visible-session-proof", - "--project", - ".", - "--goal-id", - "starter-runtime-family-smoke", - "--proof-fixture", - str(VISIBLE_PROOF_FIXTURE), - ) - ) - require(proof_payload.get("decision") == "visible_session_proof_passed", proof_payload) - - idle_payload = require_json_success( - run_cli( - "--format", - "json", - "codex-cli-runtime-idle-detector", - "--project", - ".", - "--goal-id", - "starter-runtime-family-smoke", - "--idle-fixture", - str(RUNTIME_IDLE_FIXTURE), - ) - ) - require(idle_payload.get("decision") == "runtime_idle_detector_passed", idle_payload) - - scheduler_payload = require_json_success( - run_cli( - "--format", - "json", - "codex-cli-local-scheduler-exec", - "--project", - ".", - "--goal-id", - "starter-runtime-family-smoke", - "--fixture", - str(VISIBLE_HELP_FIXTURE), - "--proof-fixture", - str(VISIBLE_PROOF_FIXTURE), - "--idle-fixture", - str(RUNTIME_IDLE_FIXTURE), - ) - ) - require(scheduler_payload.get("decision") == "visible_session_turn_candidate", scheduler_payload) - boundary = scheduler_payload.get("boundary") - require(isinstance(boundary, dict), scheduler_payload) - require(boundary.get("runs_external_candidate") is False, scheduler_payload) - require(boundary.get("runs_codex_candidate_possible") is False, scheduler_payload) - require(boundary.get("requires_fresh_quota_guard_confirmation") is True, scheduler_payload) - - -def main() -> None: - assert_source_shape() - assert_cli_surfaces() - print("cli-starter-runtime-family-command-modularization-smoke: ok") - - -if __name__ == "__main__": - main() diff --git a/examples/cli-starter-visible-driver-family-command-modularization-smoke.py b/examples/cli-starter-visible-driver-family-command-modularization-smoke.py deleted file mode 100644 index 250dda24a7..0000000000 --- a/examples/cli-starter-visible-driver-family-command-modularization-smoke.py +++ /dev/null @@ -1,223 +0,0 @@ -#!/usr/bin/env python3 -from __future__ import annotations - -import json -import subprocess -import sys -from pathlib import Path - - -ROOT = Path(__file__).resolve().parents[1] -STARTER = ROOT / "loopx" / "cli_commands" / "starter.py" -VISIBLE_COMMON = ROOT / "loopx" / "cli_commands" / "starter_visible_common.py" -VISIBLE_DRIVER = ROOT / "loopx" / "cli_commands" / "starter_visible_driver.py" -VISIBLE_PILOT = ROOT / "loopx" / "cli_commands" / "starter_visible_pilot.py" -RUNTIME_IDLE = ROOT / "loopx" / "cli_commands" / "starter_runtime_idle.py" -INIT = ROOT / "loopx" / "cli_commands" / "__init__.py" -VISIBLE_HELP_FIXTURE = ( - ROOT / "examples" / "fixtures" / "codex-cli-visible-proof" / "codex-visible-resume-help.public.json" -) -VISIBLE_PROOF_FIXTURE = ( - ROOT / "examples" / "fixtures" / "codex-cli-visible-proof" / "visible-resume-proof.public.json" -) - - -VISIBLE_PILOT_COMMANDS = { - "codex-cli-one-message-loop-pilot": ["--proof-fixture", "--allow-headless-fallback"], - "codex-cli-visible-local-driver-pilot": ["--idle-fixture", "--allow-headless-fallback"], - "codex-cli-bounded-visible-pilot-adapter": ["--first-response-fixture", "--idle-fixture"], - "codex-cli-visible-first-response-capture-plan": ["--first-response-path", "--idle-path"], - "codex-cli-visible-attach-acceptance": ["--proof-fixture", "--idle-fixture"], -} -VISIBLE_DRIVER_COMMANDS = { - "codex-cli-visible-driver-plan": ["--fixture", "--codex-bin"], - "codex-cli-local-driver-plan": ["--fixture", "--codex-bin"], - "codex-cli-visible-driver-run": ["--proof-fixture", "--allow-headless-fallback"], -} - - -def run_cli(*args: str) -> subprocess.CompletedProcess[str]: - return subprocess.run( - [sys.executable, "-m", "loopx.cli", *args], - cwd=ROOT, - text=True, - capture_output=True, - check=False, - ) - - -def require(condition: bool, message: str) -> None: - if not condition: - raise AssertionError(message) - - -def require_success(result: subprocess.CompletedProcess[str]) -> str: - if result.returncode != 0: - raise AssertionError( - f"expected success, got {result.returncode}\n" - f"stdout:\n{result.stdout}\n\nstderr:\n{result.stderr}" - ) - return result.stdout - - -def require_json_success(result: subprocess.CompletedProcess[str]) -> dict[str, object]: - payload = json.loads(require_success(result)) - require(isinstance(payload, dict), "expected JSON object payload") - require(payload.get("ok") is True, f"payload was not ok: {payload}") - return payload - - -def assert_source_shape() -> None: - starter_source = STARTER.read_text(encoding="utf-8") - visible_common_source = VISIBLE_COMMON.read_text(encoding="utf-8") - visible_driver_source = VISIBLE_DRIVER.read_text(encoding="utf-8") - visible_pilot_source = VISIBLE_PILOT.read_text(encoding="utf-8") - runtime_idle_source = RUNTIME_IDLE.read_text(encoding="utf-8") - init_source = INIT.read_text(encoding="utf-8") - - forbidden_starter_markers = [ - "build_codex_cli_one_message_loop_pilot(", - "build_codex_cli_visible_local_driver_pilot(", - "build_codex_cli_bounded_visible_pilot_adapter(", - "build_codex_cli_visible_first_response_capture_plan(", - "build_codex_cli_visible_attach_acceptance(", - "build_codex_cli_visible_driver_plan(", - "build_codex_cli_local_driver_plan(", - "build_codex_cli_visible_driver_run_packet(", - "def handle_codex_cli_one_message_loop_pilot_command(", - "def handle_codex_cli_visible_local_driver_pilot_command(", - "def handle_codex_cli_bounded_visible_pilot_adapter_command(", - "def handle_codex_cli_visible_first_response_capture_plan_command(", - "def handle_codex_cli_visible_attach_acceptance_command(", - "def handle_codex_cli_visible_driver_plan_command(", - "def handle_codex_cli_local_driver_plan_command(", - "def handle_codex_cli_visible_driver_run_command(", - ] - for marker in forbidden_starter_markers: - require(marker not in starter_source, f"visible-driver marker leaked into starter.py: {marker}") - - for marker in ( - "register_starter_visible_driver_commands(subparsers)", - "handle_starter_visible_driver_command(args, print_payload)", - ): - require(marker in starter_source, f"starter.py missing visible-driver delegation marker: {marker}") - - for command in VISIBLE_PILOT_COMMANDS: - require(command in visible_pilot_source, f"starter_visible_pilot.py missing command: {command}") - require(command not in visible_driver_source, f"pilot command leaked into starter_visible_driver.py: {command}") - for command in VISIBLE_DRIVER_COMMANDS: - require(command in visible_driver_source, f"starter_visible_driver.py missing command: {command}") - - for marker in ( - "def register_starter_visible_driver_commands(", - "def handle_starter_visible_driver_command(", - "def handle_codex_cli_visible_driver_run_command(", - "_VISIBLE_DRIVER_HANDLERS", - ): - require(marker in visible_driver_source, f"starter_visible_driver.py missing marker: {marker}") - for marker in ( - "register_starter_visible_pilot_commands(subparsers)", - "handle_starter_visible_pilot_command(args, print_payload)", - ): - require(marker in visible_driver_source, f"starter_visible_driver.py missing pilot delegation marker: {marker}") - for marker in ( - "def register_starter_visible_pilot_commands(", - "def handle_starter_visible_pilot_command(", - "def handle_codex_cli_one_message_loop_pilot_command(", - "def handle_codex_cli_visible_attach_acceptance_command(", - "_VISIBLE_PILOT_HANDLERS", - ): - require(marker in visible_pilot_source, f"starter_visible_pilot.py missing marker: {marker}") - - for marker in ( - "def _add_project_arguments(", - "def _add_codex_probe_arguments(", - "def _add_optional_proof_fixture(", - "def _add_headless_fallback_argument(", - ): - require(marker in visible_common_source, f"starter_visible_common.py missing marker: {marker}") - - for marker in ( - "def _add_runtime_idle_observation_arguments(", - "def _load_codex_cli_runtime_idle_payload(", - "build_codex_cli_runtime_idle_observation_payload(", - ): - require(marker in runtime_idle_source, f"starter_runtime_idle.py missing marker: {marker}") - - for marker in ( - "handle_starter_visible_driver_command", - "handle_starter_visible_pilot_command", - "register_starter_visible_driver_commands", - "register_starter_visible_pilot_commands", - "handle_codex_cli_visible_driver_run_command", - ): - require(marker in init_source, f"__init__ omitted visible-driver export: {marker}") - - require(len(visible_driver_source.splitlines()) <= 220, "starter_visible_driver.py exceeded size guard") - require(len(visible_pilot_source.splitlines()) <= 340, "starter_visible_pilot.py exceeded size guard") - - -def assert_cli_surfaces() -> None: - for command, needles in {**VISIBLE_PILOT_COMMANDS, **VISIBLE_DRIVER_COMMANDS}.items(): - help_text = require_success(run_cli(command, "--help")) - for needle in needles: - require(needle in help_text, f"{command} help omitted {needle}") - - capture_payload = require_json_success( - run_cli( - "--format", - "json", - "codex-cli-visible-first-response-capture-plan", - "--project", - ".", - "--goal-id", - "starter-visible-driver-smoke", - ) - ) - require(capture_payload.get("goal_id") == "starter-visible-driver-smoke", capture_payload) - - plan_payload = require_json_success( - run_cli( - "--format", - "json", - "codex-cli-visible-driver-plan", - "--project", - ".", - "--goal-id", - "starter-visible-driver-smoke", - "--fixture", - str(VISIBLE_HELP_FIXTURE), - ) - ) - require(plan_payload.get("driver_mode") == "visible_resume_or_remote_control_spike", plan_payload) - - run_payload = require_json_success( - run_cli( - "--format", - "json", - "codex-cli-visible-driver-run", - "--project", - ".", - "--goal-id", - "starter-visible-driver-smoke", - "--fixture", - str(VISIBLE_HELP_FIXTURE), - "--proof-fixture", - str(VISIBLE_PROOF_FIXTURE), - ) - ) - require(run_payload.get("decision") == "visible_session_turn_candidate", run_payload) - boundary = run_payload.get("boundary") - require(isinstance(boundary, dict), run_payload) - require(boundary.get("runs_codex") is False, run_payload) - require(boundary.get("mutates_codex_session") is False, run_payload) - - -def main() -> None: - assert_source_shape() - assert_cli_surfaces() - print("cli-starter-visible-driver-family-command-modularization-smoke: ok") - - -if __name__ == "__main__": - main() diff --git a/examples/codex-cli-bootstrap-message-smoke.py b/examples/codex-cli-bootstrap-message-smoke.py index 1a69c41e14..3791217ccc 100644 --- a/examples/codex-cli-bootstrap-message-smoke.py +++ b/examples/codex-cli-bootstrap-message-smoke.py @@ -193,13 +193,12 @@ def assert_docs_surface_codex_cli_quickstart() -> None: assert "Codex App gets a heartbeat automation body that starts at 3 minutes" in normalized_getting_started, getting_started assert "transcript-free validation checklist" in normalized_getting_started, getting_started assert "installs the generated LoopX goal/heartbeat loader immediately" in normalized_product_contract, product_contract - assert "optional automation checks after the setup path works" in normalized_getting_started, getting_started assert "first useful TUI response should be a control-plane snapshot" in normalized_product_contract, product_contract assert "setup-only work" in normalized_product_contract, product_contract - assert "loopx codex-cli-session-probe" in getting_started, getting_started - assert "loopx codex-cli-exec-handoff --project . --goal-id " in getting_started, getting_started + assert "loopx turn plan" in getting_started, getting_started + assert "loopx turn run-once" in getting_started, getting_started assert "headless-disabled boundary" in normalized_getting_started, getting_started - assert "This command no longer prints a runnable `codex exec` handoff script" in product_contract, product_contract + assert "default Codex CLI LoopX setup-then-`/goal` path does not expose a headless fallback" in normalized_product_contract, product_contract def main() -> int: diff --git a/examples/codex-cli-bounded-visible-pilot-adapter-smoke.py b/examples/codex-cli-bounded-visible-pilot-adapter-smoke.py deleted file mode 100644 index 8bb28ddf51..0000000000 --- a/examples/codex-cli-bounded-visible-pilot-adapter-smoke.py +++ /dev/null @@ -1,225 +0,0 @@ -#!/usr/bin/env python3 -"""Smoke-test the Codex CLI bounded visible pilot adapter packet.""" - -from __future__ import annotations - -import copy -import json -import subprocess -import sys -import tempfile -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -if str(REPO_ROOT) not in sys.path: - sys.path.insert(0, str(REPO_ROOT)) - -from loopx.codex_cli_probe import ( # noqa: E402 - build_codex_cli_bounded_visible_pilot_adapter, -) - - -PROJECT = Path("/tmp/public-codex-cli-project") -GOAL_ID = "public-codex-cli-goal" -AGENT_ID = "codex-side-bypass" -LIVE_PILOT_DOC = REPO_ROOT / "docs" / "product" / "runtimes" / "codex-cli" / "codex-cli-live-tui-first-message-pilot.md" -PRODUCT_README = ( - REPO_ROOT / "docs" / "product" / "runtimes" / "codex-cli" / "README.md" -) - - -PASSING_FIRST_RESPONSE_FIXTURE = { - "observed_surface": "codex_cli_tui_visible_window", - "prompt_delivery": { - "manual_or_visible_delivery": True, - "prompt_public_safe": True, - "argv_prompt_used": False, - }, - "first_response": { - "goal_id_visible": True, - "user_gate_or_none_visible": True, - "top_user_todo_or_none_visible": True, - "top_agent_todo_visible": True, - "next_safe_action_visible": True, - "bounded_segment_started_or_blocker_written": True, - }, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "writeback": { - "compact_evidence_planned": True, - "quota_spend_after_writeback_only": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - "spends_quota_before_writeback": False, - }, -} - - -PASSING_IDLE_FIXTURE = { - "observed_surface": "codex_cli_tui_visible_window", - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": {"visible_to_user": True}, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - }, -} - - -def build_adapter( - *, - first_response: dict[str, object] | None = None, - idle: dict[str, object] | None = None, -) -> dict[str, object]: - return build_codex_cli_bounded_visible_pilot_adapter( - project=PROJECT, - goal_id=GOAL_ID, - agent_id=AGENT_ID, - cli_bin="loopx", - first_response_payload=first_response, - idle_payload=idle, - ) - - -def assert_boundary(payload: dict[str, object]) -> None: - boundary = payload["boundary"] - assert boundary["adapter_packet_only"] is True, payload - assert boundary["runs_codex"] is False, payload - assert boundary["reads_raw_transcripts"] is False, payload - assert boundary["reads_session_files"] is False, payload - assert boundary["reads_stdout_stderr"] is False, payload - assert boundary["reads_credentials"] is False, payload - assert boundary["mutates_codex_session"] is False, payload - assert boundary["writes_loopx_state"] is False, payload - assert boundary["spends_loopx_quota"] is False, payload - assert boundary["requires_visible_delivery"] is True, payload - assert boundary["argv_prompt_rejected"] is True, payload - assert boundary["success_claim_requires_first_response_and_idle"] is True, payload - - -def run_cli(*extra_args: str) -> str: - result = subprocess.run( - [sys.executable, "-m", "loopx.cli", *extra_args], - cwd=REPO_ROOT, - check=True, - capture_output=True, - text=True, - ) - return result.stdout - - -def assert_docs() -> None: - live_pilot = LIVE_PILOT_DOC.read_text(encoding="utf-8") - product_readme = PRODUCT_README.read_text(encoding="utf-8") - assert "codex-cli-bounded-visible-pilot-adapter" in live_pilot, live_pilot - assert "public-first-response.json" in live_pilot, live_pilot - assert "argv prompt" in live_pilot, live_pilot - assert "Codex CLI bounded visible pilot adapter" in product_readme, product_readme - assert "codex-cli-bounded-visible-pilot-adapter-smoke.py" in product_readme, product_readme - - -def main() -> int: - missing = build_adapter() - assert missing["ok"] is True, missing - assert missing["schema_version"] == "codex_cli_bounded_visible_pilot_adapter_v0", missing - assert missing["decision"] == "bounded_visible_completion_evidence_required", missing - assert missing["approved_for_live_tui_success_claim"] is False, missing - assert "missing_first_response_evidence" in missing["blockers"], missing - assert "missing_runtime_idle_evidence" in missing["blockers"], missing - assert "codex-cli-bootstrap-message" in missing["commands"]["bootstrap_message"], missing - assert "codex-cli-bounded-visible-pilot-adapter" in missing["commands"]["bounded_visible_pilot_adapter"], missing - assert_boundary(missing) - - argv_leaking = copy.deepcopy(PASSING_FIRST_RESPONSE_FIXTURE) - argv_leaking["prompt_delivery"]["argv_prompt_used"] = True - rejected = build_adapter(first_response=argv_leaking, idle=PASSING_IDLE_FIXTURE) - assert rejected["decision"] == "bounded_visible_first_response_incomplete", rejected - assert rejected["approved_for_live_tui_success_claim"] is False, rejected - assert "no_argv_prompt" in rejected["blockers"], rejected - assert "argv_prompt_leakage_risk" in rejected["blockers"], rejected - assert rejected["runtime_idle_detector"]["approved"] is True, rejected - assert_boundary(rejected) - - passing = build_adapter( - first_response=PASSING_FIRST_RESPONSE_FIXTURE, - idle=PASSING_IDLE_FIXTURE, - ) - assert passing["decision"] == "bounded_visible_pilot_ready_for_success_claim", passing - assert passing["approved_for_live_tui_success_claim"] is True, passing - assert passing["first_response"]["approved"] is True, passing - assert passing["runtime_idle_detector"]["approved"] is True, passing - assert passing["blockers"] == [], passing - assert "--delivery-outcome outcome_progress" in passing["commands"]["success_writeback"], passing - assert_boundary(passing) - - with tempfile.TemporaryDirectory(prefix="loopx-codex-cli-bounded-visible-") as tmp: - tmp_path = Path(tmp) - first_response_fixture = tmp_path / "public-first-response.json" - first_response_fixture.write_text(json.dumps(PASSING_FIRST_RESPONSE_FIXTURE)) - idle_fixture = tmp_path / "public-runtime-idle.json" - idle_fixture.write_text(json.dumps(PASSING_IDLE_FIXTURE)) - - cli_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-bounded-visible-pilot-adapter", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--first-response-fixture", - str(first_response_fixture), - "--idle-fixture", - str(idle_fixture), - ) - ) - assert cli_json["decision"] == "bounded_visible_pilot_ready_for_success_claim", cli_json - assert cli_json["approved_for_live_tui_success_claim"] is True, cli_json - assert_boundary(cli_json) - - markdown = run_cli( - "codex-cli-bounded-visible-pilot-adapter", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--first-response-fixture", - str(first_response_fixture), - "--idle-fixture", - str(idle_fixture), - ) - assert "# Codex CLI Bounded Visible Pilot Adapter" in markdown, markdown - assert "approved_for_live_tui_success_claim" in markdown, markdown - assert "argv_prompt_rejected" in markdown, markdown - - assert_docs() - print("codex-cli-bounded-visible-pilot-adapter-smoke ok") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/examples/codex-cli-exec-handoff-smoke.py b/examples/codex-cli-exec-handoff-smoke.py deleted file mode 100644 index 4b717064a2..0000000000 --- a/examples/codex-cli-exec-handoff-smoke.py +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env python3 -"""Smoke-test the disabled Codex CLI exec handoff boundary.""" - -from __future__ import annotations - -import json -import subprocess -import sys -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -if str(REPO_ROOT) not in sys.path: - sys.path.insert(0, str(REPO_ROOT)) - -from loopx.project_prompt import build_codex_cli_exec_handoff # noqa: E402 - - -PROJECT = Path("/tmp/public-codex-cli-project") -GOAL_ID = "public-codex-cli-goal" -AGENT_ID = "codex-side-bypass" - - -def run_cli(*extra_args: str) -> str: - result = subprocess.run( - [sys.executable, "-m", "loopx.cli", *extra_args], - cwd=REPO_ROOT, - check=True, - capture_output=True, - text=True, - ) - return result.stdout - - -def assert_handoff_contract(payload: dict[str, object]) -> None: - assert payload["ok"] is True, payload - assert payload["schema_version"] == "codex_cli_exec_handoff_v0", payload - assert payload["mode"] == "headless_fallback_disabled_for_goal_mode_bootstrap", payload - assert payload["primary_experience"] == "codex_cli_tui_goal_bootstrap", payload - assert payload["goal_id"] == GOAL_ID, payload - assert payload["agent_id"] == AGENT_ID, payload - command = str(payload["handoff_command"]) - message_only = str(payload["message_only_command"]) - assert command == "", payload - assert "codex exec" not in command, payload - assert "codex-cli-bootstrap-message" in message_only, payload - assert "--message-only" in message_only, payload - assert "disabled" in str(payload["disabled_reason"]).lower(), payload - boundary = payload["boundary"] - assert boundary["runs_codex"] is False, payload - assert boundary["reads_raw_transcripts"] is False, payload - assert boundary["reads_credentials"] is False, payload - assert boundary["reads_session_files"] is False, payload - assert boundary["mutates_codex_session"] is False, payload - assert boundary["spends_loopx_quota"] is False, payload - assert boundary["headless_execution_disabled"] is True, payload - assert boundary["provides_executable_headless_command"] is False, payload - - -def main() -> int: - payload = build_codex_cli_exec_handoff( - project=PROJECT, - goal_id=GOAL_ID, - agent_id=AGENT_ID, - cli_bin="loopx", - codex_bin="codex", - ) - assert_handoff_contract(payload) - - cli_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-exec-handoff", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - ) - ) - assert_handoff_contract(cli_json) - - cli_markdown = run_cli( - "codex-cli-exec-handoff", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - ) - assert "# Codex CLI Exec Handoff Disabled" in cli_markdown, cli_markdown - assert "Headless `codex exec` handoff is disabled" in cli_markdown, cli_markdown - assert "codex-cli-bootstrap-message" in cli_markdown, cli_markdown - assert "cat <<'LOOPX_CODEX_PROMPT' | codex exec" not in cli_markdown, cli_markdown - - print("codex-cli-exec-handoff-smoke ok") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/examples/codex-cli-first-run-rehearsal-smoke.py b/examples/codex-cli-first-run-rehearsal-smoke.py index ac64e15fb8..f94bb87d6d 100644 --- a/examples/codex-cli-first-run-rehearsal-smoke.py +++ b/examples/codex-cli-first-run-rehearsal-smoke.py @@ -43,15 +43,12 @@ def assert_doc() -> None: "Codex CLI First-Run Rehearsal", "PyPI install/update with packaged workflow skills and an archive fallback", "one-message Codex CLI TUI bootstrap", - "proof-capture fixtures for later visible automation", + "bounded isolated-headless turns via `loopx turn`", "Start LoopX for this repo", "python3 -m pip install --upgrade loopx", "loopx workflow-skills --install", "loopx codex-cli-bootstrap-message --project . --goal-id --message-only", - "loopx codex-cli-tui-bootstrap-smoke-bundle", - "loopx --format json codex-cli-visible-attach-acceptance", - "does not prove same-open-TUI automation", - "Same-TUI automation stays optional until the proof path passes", + "Same-TUI automation stays optional until a safe attach primitive is proven", "must not:", "require cloning the LoopX repo", "read raw Codex transcripts, session files, stdout, stderr, credentials, or private paths", @@ -77,7 +74,7 @@ def assert_indexes() -> None: assert f"../product/runtimes/codex-cli/{link}" in getting_started, getting_started assert "PyPI" in product, product assert "one-message TUI bootstrap" in product, product - assert "proof-capture fixtures" in getting_started, getting_started + assert "explicit `loopx turn` boundaries" in getting_started, getting_started def assert_cli_surfaces_align() -> None: @@ -111,20 +108,6 @@ def assert_cli_surfaces_align() -> None: assert "settlement_plan.ordered_steps" in normalized, message assert "raw Codex transcripts" in normalized, message - bundle = run_cli( - "codex-cli-tui-bootstrap-smoke-bundle", - "--project", - "/tmp/public-codex-cli-project", - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - ) - normalized_bundle = normalize(bundle) - assert "Codex CLI TUI Bootstrap Smoke Bundle" in normalized_bundle, bundle - assert "runs_codex: `False`" in normalized_bundle, bundle - assert "requires_loopx_repo_clone: `False`" in normalized_bundle, bundle - def main() -> int: assert_doc() diff --git a/examples/codex-cli-live-tui-first-message-pilot-smoke.py b/examples/codex-cli-live-tui-first-message-pilot-smoke.py deleted file mode 100644 index 02a159041f..0000000000 --- a/examples/codex-cli-live-tui-first-message-pilot-smoke.py +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/env python3 -"""Validate the Codex CLI live TUI first-message pilot record.""" - -from __future__ import annotations - -import subprocess -import sys -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -DOC = REPO_ROOT / "docs" / "product" / "runtimes" / "codex-cli" / "codex-cli-live-tui-first-message-pilot.md" -FIRST_RUN = REPO_ROOT / "docs" / "product" / "runtimes" / "codex-cli" / "codex-cli-first-run-rehearsal.md" -PRODUCT_README = ( - REPO_ROOT / "docs" / "product" / "runtimes" / "codex-cli" / "README.md" -) -GOAL_ID = "public-live-tui-pilot-goal" -AGENT_ID = "codex-side-bypass" - - -def normalize(text: str) -> str: - return " ".join(text.split()) - - -def run_cli(*args: str) -> str: - result = subprocess.run( - [sys.executable, "-m", "loopx.cli", *args], - cwd=REPO_ROOT, - check=True, - text=True, - capture_output=True, - ) - return result.stdout - - -def assert_doc() -> None: - text = DOC.read_text(encoding="utf-8") - normalized = normalize(text) - - must_have = ( - "Codex CLI Live TUI First-Message Pilot", - "Status: blocker recorded; manual TUI bootstrap remains primary.", - "Recorded: 2026-06-21.", - "disposable public-safe repo", - "codex [OPTIONS] [PROMPT]", - "--no-alt-screen", - "--cd ", - "resume", - "remote-control", - "codex doctor", - "did not produce bounded output before manual interrupt", - "no bounded first-response or completion signal", - "capture output exceeded the automation budget", - "process remained active", - "process command line", - "live_tui_first_message_blocked_by_bounded_visible_completion_missing", - "manual TUI bootstrap remains primary", - "the user pastes one LoopX start message", - "without leaking project-specific prompt text through process arguments", - "raw transcript or session-file reads", - "Codex CLI bounded visible pilot adapter", - ) - for phrase in must_have: - assert phrase in normalized, phrase - - assert "LoopX should not advertise automated `codex [PROMPT]` launch" in text - assert "raw TUI output, Codex transcripts, session files" in normalized, text - assert "without raw transcript or session-file reads" in normalized, text - - -def assert_indexes() -> None: - product = PRODUCT_README.read_text(encoding="utf-8") - first_run = FIRST_RUN.read_text(encoding="utf-8") - assert "codex-cli-live-tui-first-message-pilot.md" in product, product - assert "Codex CLI live TUI first-message pilot" in product, product - assert "Live TUI Pilot Note" in first_run, first_run - assert ( - "Automated live launch needs a bounded visible completion proof first." in first_run - ), first_run - - -def assert_bootstrap_message_still_copy_first() -> None: - message = run_cli( - "codex-cli-bootstrap-message", - "--project", - "/tmp/loopx-live-tui-pilot.public", - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--message-only", - ) - normalized = normalize(message) - assert message.startswith("Install and connect LoopX for this repo"), message - assert not message.startswith("/goal "), message - assert "Codex CLI TUI" in normalized, message - assert "setup/bootstrap instruction" in normalized, message - assert "/goal " in normalized, message - assert "raw Codex transcripts" in normalized, message - assert "watch, steer, review, and take over" in normalized, message - - -def main() -> int: - assert_doc() - assert_indexes() - assert_bootstrap_message_still_copy_first() - print("codex-cli-live-tui-first-message-pilot-smoke ok") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/examples/codex-cli-local-driver-plan-smoke.py b/examples/codex-cli-local-driver-plan-smoke.py deleted file mode 100644 index 14d57c5171..0000000000 --- a/examples/codex-cli-local-driver-plan-smoke.py +++ /dev/null @@ -1,183 +0,0 @@ -#!/usr/bin/env python3 -"""Smoke-test the dry-run-first Codex CLI local driver plan.""" - -from __future__ import annotations - -import json -import subprocess -import sys -import tempfile -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -if str(REPO_ROOT) not in sys.path: - sys.path.insert(0, str(REPO_ROOT)) - -from loopx.codex_cli_probe import ( # noqa: E402 - build_codex_cli_local_driver_plan, - classify_codex_cli_session_surface, -) - - -PROJECT = Path("/tmp/public-codex-cli-project") -GOAL_ID = "public-codex-cli-goal" -AGENT_ID = "codex-side-bypass" - - -HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec Run Codex non-interactively - resume Resume a previous conversation -""", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": "Usage: codex resume [SESSION_ID]", -} - - -REMOTE_RESUME_HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec - remote-control Manage the app-server daemon with remote control enabled - resume Resume a previous interactive session - -Options: - --remote Connect the TUI to a remote app server endpoint -""", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": """ -Usage: codex resume [OPTIONS] [SESSION_ID] [PROMPT] - -Resume a previous interactive session. -""", -} - - -ATTACH_HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec - resume - attach-session Send prompt to session after checking the idle TUI -""", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": "Usage: codex resume [SESSION_ID]", -} - - -def run_cli(*extra_args: str) -> str: - result = subprocess.run( - [sys.executable, "-m", "loopx.cli", *extra_args], - cwd=REPO_ROOT, - check=True, - capture_output=True, - text=True, - ) - return result.stdout - - -def assert_common_contract(payload: dict[str, object]) -> None: - assert payload["ok"] is True, payload - assert payload["schema_version"] == "codex_cli_local_driver_plan_v0", payload - assert payload["driver_phase"] == "dry_run_plan", payload - assert payload["goal_id"] == GOAL_ID, payload - assert payload["agent_id"] == AGENT_ID, payload - commands = payload["commands"] - assert "quota should-run --goal-id public-codex-cli-goal --agent-id codex-side-bypass" in commands["quota_guard"], payload - assert "codex-cli-visible-driver-plan" in commands["visible_driver_plan"], payload - assert "codex-cli-bootstrap-message" in commands["tui_bootstrap_message"], payload - assert commands["explicit_headless_fallback"] is None, payload - assert "headless codex exec is disabled" in commands["headless_fallback_disabled"], payload - assert payload["idle_guard"]["required"] is True, payload - assert payload["idle_guard"]["implemented"] is False, payload - policy = payload["execution_policy"] - assert policy["tui_bootstrap_primary"] is True, payload - assert policy["headless_execution_disabled"] is True, payload - assert policy["same_session_attachment_requires_visible_proof"] is True, payload - boundary = payload["boundary"] - assert boundary["dry_run_plan_only"] is True, payload - assert boundary["runs_codex"] is False, payload - assert boundary["reads_raw_transcripts"] is False, payload - assert boundary["reads_credentials"] is False, payload - assert boundary["reads_session_files"] is False, payload - assert boundary["mutates_codex_session"] is False, payload - assert boundary["spends_loopx_quota"] is False, payload - - -def build_plan(command_outputs: dict[str, str]) -> dict[str, object]: - return build_codex_cli_local_driver_plan( - project=PROJECT, - goal_id=GOAL_ID, - agent_id=AGENT_ID, - cli_bin="loopx", - codex_bin="codex", - probe_payload=classify_codex_cli_session_surface(command_outputs=command_outputs), - ) - - -def main() -> int: - fallback_plan = build_plan(HELP_FIXTURE) - assert_common_contract(fallback_plan) - assert fallback_plan["driver_mode"] == "tui_bootstrap_only", fallback_plan - assert fallback_plan["decision"] == "ask_user_to_start_from_tui", fallback_plan - - remote_plan = build_plan(REMOTE_RESUME_HELP_FIXTURE) - assert_common_contract(remote_plan) - assert remote_plan["driver_mode"] == "visible_resume_or_remote_control_spike", remote_plan - assert remote_plan["decision"] == "run_visible_resume_or_remote_control_proof", remote_plan - - attach_plan = build_plan(ATTACH_HELP_FIXTURE) - assert_common_contract(attach_plan) - assert attach_plan["driver_mode"] == "session_attached_visible_turn", attach_plan - assert attach_plan["decision"] == "attempt_visible_session_attach_after_idle_guard", attach_plan - - with tempfile.TemporaryDirectory(prefix="loopx-codex-cli-local-driver-") as tmp: - fixture = Path(tmp) / "codex-remote-help.json" - fixture.write_text(json.dumps({"command_outputs": REMOTE_RESUME_HELP_FIXTURE})) - cli_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-local-driver-plan", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(fixture), - ) - ) - assert_common_contract(cli_json) - assert cli_json["driver_mode"] == "visible_resume_or_remote_control_spike", cli_json - - cli_markdown = run_cli( - "codex-cli-local-driver-plan", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(fixture), - ) - assert "# Codex CLI Local Driver Plan" in cli_markdown, cli_markdown - assert "driver_phase: `dry_run_plan`" in cli_markdown, cli_markdown - assert "headless_execution_disabled: `True`" in cli_markdown, cli_markdown - - print("codex-cli-local-driver-plan-smoke ok") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/examples/codex-cli-local-scheduler-exec-smoke.py b/examples/codex-cli-local-scheduler-exec-smoke.py deleted file mode 100644 index cbbe19e8ea..0000000000 --- a/examples/codex-cli-local-scheduler-exec-smoke.py +++ /dev/null @@ -1,359 +0,0 @@ -#!/usr/bin/env python3 -"""Smoke-test the Codex CLI local scheduler executor wrapper.""" - -from __future__ import annotations - -import json -import shlex -import subprocess -import sys -import tempfile -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -if str(REPO_ROOT) not in sys.path: - sys.path.insert(0, str(REPO_ROOT)) - -from loopx.codex_cli_probe import ( # noqa: E402 - build_codex_cli_local_scheduler_executor, - classify_codex_cli_session_surface, - execute_codex_cli_local_scheduler_tick_result, -) - - -PROJECT = Path("/tmp/public-codex-cli-project") -GOAL_ID = "public-codex-cli-goal" -AGENT_ID = "codex-side-bypass" - - -REMOTE_RESUME_HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec - remote-control Manage the app-server daemon with remote control enabled - resume Resume a previous interactive session - -Options: - --remote Connect the TUI to a remote app server endpoint -""", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": """ -Usage: codex resume [OPTIONS] [SESSION_ID] [PROMPT] - -Resume a previous interactive session. -""", -} - - -VISIBLE_PROOF_FIXTURE = { - "observed_surface": "visible_resume_prompt", - "recommended_command": f"{shlex.quote(sys.executable)} -c 'pass'", - "user_opt_in": True, - "quota_guard": {"passed": True}, - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": { - "visible_to_user": True, - "prompt_public_safe": True, - }, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - "spends_quota_before_writeback": False, - }, - "writeback": {"compact_evidence_planned": True}, -} - - -RUNTIME_IDLE_FIXTURE = { - "observed_surface": "visible_resume_prompt", - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": {"visible_to_user": True}, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - }, -} - - -def fake_runner_calls() -> tuple[list[dict[str, object]], object]: - calls: list[dict[str, object]] = [] - - def runner(command: str, *, timeout_seconds: float, capture_output: bool = False) -> dict[str, object]: - calls.append( - { - "command": command, - "timeout_seconds": timeout_seconds, - "capture_output": capture_output, - } - ) - return { - "attempted": True, - "returncode": 0, - "timed_out": False, - "output_captured": capture_output, - } - - return calls, runner - - -def build_exec( - *, - proof_payload: dict[str, object] | None = VISIBLE_PROOF_FIXTURE, - idle_payload: dict[str, object] | None = RUNTIME_IDLE_FIXTURE, - execute_candidate: bool = False, - execute_blocker_writeback: bool = False, - guard_checked: bool = False, - prefixes: list[str] | None = None, - runner=None, -) -> dict[str, object]: - return build_codex_cli_local_scheduler_executor( - project=PROJECT, - goal_id=GOAL_ID, - agent_id=AGENT_ID, - cli_bin="loopx", - codex_bin="codex", - probe_payload=classify_codex_cli_session_surface(command_outputs=REMOTE_RESUME_HELP_FIXTURE), - proof_payload=proof_payload, - idle_payload=idle_payload, - execute_candidate=execute_candidate, - execute_blocker_writeback=execute_blocker_writeback, - guard_checked=guard_checked, - candidate_command_prefixes=prefixes or [], - runner=runner, - ) - - -def assert_executor_boundary(payload: dict[str, object]) -> None: - assert payload["schema_version"] == "codex_cli_local_scheduler_executor_v0", payload - boundary = payload["boundary"] - assert boundary["executor_wrapper"] is True, payload - assert boundary["requires_explicit_execute_flag"] is True, payload - assert boundary["requires_fresh_quota_guard_confirmation"] is True, payload - assert boundary["candidate_prefix_required"] is True, payload - assert boundary["runtime_idle_detector_required_for_visible_candidate"] is True, payload - assert boundary["reads_raw_transcripts"] is False, payload - assert boundary["reads_credentials"] is False, payload - assert boundary["reads_session_files"] is False, payload - assert boundary["mutates_codex_session"] is False, payload - assert boundary["candidate_output_captured"] is False, payload - assert boundary["blocker_output_captured"] is False, payload - assert boundary["spends_loopx_quota"] is False, payload - - -def run_cli(*extra_args: str) -> str: - result = subprocess.run( - [sys.executable, "-m", "loopx.cli", *extra_args], - cwd=REPO_ROOT, - check=True, - capture_output=True, - text=True, - ) - return result.stdout - - -def main() -> int: - calls, runner = fake_runner_calls() - - no_execute = build_exec(runner=runner) - assert no_execute["ok"] is True, no_execute - assert_executor_boundary(no_execute) - assert no_execute["execution"]["executed"] is False, no_execute - assert no_execute["execution"]["reason"] == "no_execute_flag", no_execute - assert calls == [], calls - - guard_missing = build_exec( - execute_candidate=True, - prefixes=[sys.executable], - runner=runner, - ) - assert guard_missing["execution"]["reason"] == "fresh_quota_guard_confirmation_required", guard_missing - assert calls == [], calls - - idle_missing = build_exec( - idle_payload=None, - execute_candidate=True, - guard_checked=True, - prefixes=[sys.executable], - runner=runner, - ) - assert idle_missing["scheduler_action"] == "write_precise_blocker", idle_missing - assert idle_missing["scheduler_tick"]["precise_blocker"]["reason"] == "runtime_idle_evidence_missing", idle_missing - assert idle_missing["execution"]["reason"] == "scheduler_action_not_candidate", idle_missing - assert calls == [], calls - - tampered_tick = { - "schema_version": "codex_cli_local_scheduler_tick_v0", - "project": str(PROJECT), - "goal_id": GOAL_ID, - "agent_id": AGENT_ID, - "cli_bin": "loopx", - "codex_bin": "codex", - "scheduler_phase": "tick_packet_no_execution", - "scheduler_action": "external_visible_command_candidate", - "decision": "visible_session_turn_candidate", - "next_safe_step": "tampered visible candidate", - "candidate_command": f"{shlex.quote(sys.executable)} -c 'pass'", - "commands": {"scheduler_tick": "loopx codex-cli-local-scheduler-tick"}, - "visible_driver_run_packet": { - "visible_session_proof": {"supplied": True, "approved": True} - }, - "runtime_idle_detector": {"supplied": False, "approved": False}, - } - tampered_reject = execute_codex_cli_local_scheduler_tick_result( - tampered_tick, - execute_candidate=True, - guard_checked=True, - candidate_command_prefixes=[sys.executable], - runner=runner, - ) - assert tampered_reject["execution"]["reason"] == "runtime_idle_detector_required", tampered_reject - assert calls == [], calls - - prefix_missing = build_exec( - execute_candidate=True, - guard_checked=True, - runner=runner, - ) - assert prefix_missing["execution"]["reason"] == "candidate_command_prefix_required", prefix_missing - assert calls == [], calls - - prefix_mismatch = build_exec( - execute_candidate=True, - guard_checked=True, - prefixes=["definitely-not-python"], - runner=runner, - ) - assert prefix_mismatch["execution"]["reason"] == "candidate_command_prefix_mismatch", prefix_mismatch - assert calls == [], calls - - candidate = build_exec( - execute_candidate=True, - guard_checked=True, - prefixes=[sys.executable], - runner=runner, - ) - assert candidate["ok"] is True, candidate - assert candidate["execution"]["executed"] is True, candidate - assert candidate["execution"]["kind"] == "candidate_command", candidate - assert candidate["execution"]["reason"] == "candidate_command_executed", candidate - assert candidate["boundary"]["runs_external_candidate"] is True, candidate - assert calls[-1]["capture_output"] is False, calls - - blocker = build_exec( - proof_payload=None, - execute_blocker_writeback=True, - guard_checked=True, - runner=runner, - ) - assert blocker["ok"] is True, blocker - assert blocker["execution"]["kind"] == "blocker_writeback", blocker - assert "refresh-state" in calls[-1]["command"], calls - assert blocker["boundary"]["writes_loopx_state"] is True, blocker - assert blocker["boundary"]["spends_loopx_quota"] is False, blocker - assert calls[-1]["capture_output"] is False, calls - - with tempfile.TemporaryDirectory(prefix="loopx-codex-cli-scheduler-exec-") as tmp: - tmp_path = Path(tmp) - help_fixture = tmp_path / "codex-remote-help.json" - help_fixture.write_text(json.dumps({"command_outputs": REMOTE_RESUME_HELP_FIXTURE})) - proof_fixture = tmp_path / "visible-proof.json" - proof_fixture.write_text(json.dumps(VISIBLE_PROOF_FIXTURE)) - idle_fixture = tmp_path / "runtime-idle.json" - idle_fixture.write_text(json.dumps(RUNTIME_IDLE_FIXTURE)) - missing_registry = tmp_path / "missing-registry.json" - runtime_root = tmp_path / "runtime" - - cli_json = json.loads( - run_cli( - "--registry", - str(missing_registry), - "--runtime-root", - str(runtime_root), - "--format", - "json", - "codex-cli-local-scheduler-exec", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - ) - ) - assert_executor_boundary(cli_json) - assert cli_json["execution"]["reason"] == "no_execute_flag", cli_json - - cli_prefix_reject = json.loads( - run_cli( - "--format", - "json", - "codex-cli-local-scheduler-exec", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - "--proof-fixture", - str(proof_fixture), - "--idle-fixture", - str(idle_fixture), - "--execute-candidate", - "--guard-checked", - "--candidate-command-prefix", - "definitely-not-python", - ) - ) - assert cli_prefix_reject["ok"] is True, cli_prefix_reject - assert cli_prefix_reject["execution"]["executed"] is False, cli_prefix_reject - assert cli_prefix_reject["execution"]["reason"] == "candidate_command_prefix_mismatch", cli_prefix_reject - - cli_markdown = run_cli( - "codex-cli-local-scheduler-exec", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - ) - assert "# Codex CLI Local Scheduler Executor" in cli_markdown, cli_markdown - assert "reason: `no_execute_flag`" in cli_markdown, cli_markdown - assert "candidate_output_captured: `False`" in cli_markdown, cli_markdown - - print("codex-cli-local-scheduler-exec-smoke ok") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/examples/codex-cli-local-scheduler-tick-smoke.py b/examples/codex-cli-local-scheduler-tick-smoke.py deleted file mode 100644 index 0df0ccf48c..0000000000 --- a/examples/codex-cli-local-scheduler-tick-smoke.py +++ /dev/null @@ -1,353 +0,0 @@ -#!/usr/bin/env python3 -"""Smoke-test the Codex CLI local scheduler tick packet.""" - -from __future__ import annotations - -import json -import subprocess -import sys -import tempfile -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -if str(REPO_ROOT) not in sys.path: - sys.path.insert(0, str(REPO_ROOT)) - -from loopx.codex_cli_probe import ( # noqa: E402 - build_codex_cli_local_scheduler_tick, - classify_codex_cli_session_surface, -) - - -PROJECT = Path("/tmp/public-codex-cli-project") -GOAL_ID = "public-codex-cli-goal" -AGENT_ID = "codex-side-bypass" - - -FALLBACK_HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec Run Codex non-interactively - resume Resume a previous conversation -""", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": "Usage: codex resume [SESSION_ID]", -} - - -REMOTE_RESUME_HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec - remote-control Manage the app-server daemon with remote control enabled - resume Resume a previous interactive session - -Options: - --remote Connect the TUI to a remote app server endpoint -""", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": """ -Usage: codex resume [OPTIONS] [SESSION_ID] [PROMPT] - -Resume a previous interactive session. -""", -} - - -VISIBLE_PROOF_FIXTURE = { - "observed_surface": "visible_resume_prompt", - "recommended_command": "codex resume public-session-id 'LoopX visible steering turn'", - "user_opt_in": True, - "quota_guard": {"passed": True}, - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": { - "visible_to_user": True, - "prompt_public_safe": True, - }, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - "spends_quota_before_writeback": False, - }, - "writeback": {"compact_evidence_planned": True}, -} - - -RUNTIME_IDLE_FIXTURE = { - "observed_surface": "visible_resume_prompt", - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": {"visible_to_user": True}, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - }, -} - - -QUOTA_HINT_FIXTURE = { - "scheduler_hint": { - "schema_version": "scheduler_hint_v0", - "action": "backoff_until_reassigned", - "cadence_class": "agent_scope_wait", - "codex_app": { - "recommended_interval_minutes": 10, - "max_interval_minutes": 60, - "unchanged_poll_backoff_multiplier": 2, - "example_progression_minutes": [10, 20, 30, 60], - }, - "unchanged_poll": { - "limits": { - "local_scheduler": 3, - "codex_cli_tui": 3, - "claude_code_loop": 3, - }, - "after_limits": { - "local_scheduler": "stop_tick_loop", - "codex_cli_tui": "update_goal_blocked_keep_loopx_active", - "claude_code_loop": "stop_loop", - }, - "final_quota_replan_check_enabled": True, - "final_quota_replan_check_action": "rerun_quota_should_run_once", - }, - "reset_policy": { - "schema_version": "scheduler_reset_policy_v0", - "reset_token": "fixture-reset-001", - "local_scheduler_initial_interval_minutes": 10, - "codex_app_initial_rrule": "FREQ=MINUTELY;INTERVAL=10", - }, - } -} - - -def assert_boundary(payload: dict[str, object]) -> None: - assert payload["ok"] is True, payload - assert payload["schema_version"] == "codex_cli_local_scheduler_tick_v0", payload - assert payload["scheduler_phase"] == "tick_packet_no_execution", payload - boundary = payload["boundary"] - assert boundary["tick_packet_only"] is True, payload - assert boundary["runs_codex"] is False, payload - assert boundary["reads_raw_transcripts"] is False, payload - assert boundary["reads_credentials"] is False, payload - assert boundary["reads_session_files"] is False, payload - assert boundary["mutates_codex_session"] is False, payload - assert boundary["spends_loopx_quota"] is False, payload - assert boundary["writes_loopx_state"] is False, payload - assert boundary["visible_candidate_requires_runtime_idle_detector"] is True, payload - assert boundary["headless_execution_disabled"] is True, payload - - -def build_tick( - command_outputs: dict[str, str], - *, - proof_payload: dict[str, object] | None = None, - idle_payload: dict[str, object] | None = None, - quota_payload: dict[str, object] | None = None, - allow_headless_fallback: bool = False, -) -> dict[str, object]: - return build_codex_cli_local_scheduler_tick( - project=PROJECT, - goal_id=GOAL_ID, - agent_id=AGENT_ID, - cli_bin="loopx", - codex_bin="codex", - probe_payload=classify_codex_cli_session_surface(command_outputs=command_outputs), - quota_payload=quota_payload, - proof_payload=proof_payload, - idle_payload=idle_payload, - allow_headless_fallback=allow_headless_fallback, - ) - - -def run_cli(*extra_args: str) -> str: - result = subprocess.run( - [sys.executable, "-m", "loopx.cli", *extra_args], - cwd=REPO_ROOT, - check=True, - capture_output=True, - text=True, - ) - return result.stdout - - -def main() -> int: - proof_missing = build_tick(REMOTE_RESUME_HELP_FIXTURE) - assert_boundary(proof_missing) - assert proof_missing["scheduler_action"] == "write_precise_blocker", proof_missing - assert proof_missing["precise_blocker"]["reason"] == "visible_session_proof_missing", proof_missing - assert "refresh-state" in proof_missing["blocker_writeback_command"], proof_missing - assert proof_missing["candidate_command"] is None, proof_missing - - tui_only = build_tick(FALLBACK_HELP_FIXTURE) - assert_boundary(tui_only) - assert tui_only["scheduler_action"] == "surface_tui_bootstrap", tui_only - assert tui_only["candidate_command"] is None, tui_only - assert tui_only["blocker_writeback_command"] is None, tui_only - - fallback_ignored = build_tick(FALLBACK_HELP_FIXTURE, allow_headless_fallback=True) - assert_boundary(fallback_ignored) - assert fallback_ignored["scheduler_action"] == "surface_tui_bootstrap", fallback_ignored - assert fallback_ignored["candidate_command"] is None, fallback_ignored - assert fallback_ignored["blocker_writeback_command"] is None, fallback_ignored - assert any("allow_headless_fallback was ignored" in warning for warning in fallback_ignored["warnings"]), fallback_ignored - - visible_idle_missing = build_tick(REMOTE_RESUME_HELP_FIXTURE, proof_payload=VISIBLE_PROOF_FIXTURE) - assert_boundary(visible_idle_missing) - assert visible_idle_missing["scheduler_action"] == "write_precise_blocker", visible_idle_missing - assert visible_idle_missing["precise_blocker"]["reason"] == "runtime_idle_evidence_missing", visible_idle_missing - assert visible_idle_missing["runtime_idle_detector"]["approved"] is False, visible_idle_missing - assert visible_idle_missing["candidate_command"] is None, visible_idle_missing - - visible_candidate = build_tick( - REMOTE_RESUME_HELP_FIXTURE, - proof_payload=VISIBLE_PROOF_FIXTURE, - idle_payload=RUNTIME_IDLE_FIXTURE, - ) - assert_boundary(visible_candidate) - assert visible_candidate["scheduler_action"] == "external_visible_command_candidate", visible_candidate - assert "codex resume public-session-id" in visible_candidate["candidate_command"], visible_candidate - assert visible_candidate["runtime_idle_detector"]["approved"] is True, visible_candidate - - hinted_tick = build_tick(FALLBACK_HELP_FIXTURE, quota_payload=QUOTA_HINT_FIXTURE) - assert hinted_tick["scheduler_hint"]["action"] == "backoff_until_reassigned", hinted_tick - assert hinted_tick["launchd"]["recommended_interval_seconds"] == 600, hinted_tick - assert hinted_tick["launchd"]["reset_token"] == "fixture-reset-001", hinted_tick - assert hinted_tick["launchd"]["reset_interval_seconds"] == 600, hinted_tick - assert hinted_tick["launchd"]["reset_policy"]["codex_app_initial_rrule"] == "FREQ=MINUTELY;INTERVAL=10", hinted_tick - assert hinted_tick["scheduler_hint"]["codex_app"]["example_progression_minutes"] == [10, 20, 30, 60], hinted_tick - assert hinted_tick["scheduler_hint"]["unchanged_poll"]["final_quota_replan_check_enabled"] is True, hinted_tick - - with tempfile.TemporaryDirectory(prefix="loopx-codex-cli-scheduler-tick-") as tmp: - tmp_path = Path(tmp) - help_fixture = tmp_path / "codex-remote-help.json" - help_fixture.write_text(json.dumps({"command_outputs": REMOTE_RESUME_HELP_FIXTURE})) - proof_fixture = tmp_path / "visible-proof.json" - proof_fixture.write_text(json.dumps(VISIBLE_PROOF_FIXTURE)) - idle_fixture = tmp_path / "runtime-idle.json" - idle_fixture.write_text(json.dumps(RUNTIME_IDLE_FIXTURE)) - quota_fixture = tmp_path / "quota.json" - quota_fixture.write_text(json.dumps(QUOTA_HINT_FIXTURE)) - missing_registry = tmp_path / "missing-registry.json" - runtime_root = tmp_path / "runtime" - - cli_json = json.loads( - run_cli( - "--registry", - str(missing_registry), - "--runtime-root", - str(runtime_root), - "--format", - "json", - "codex-cli-local-scheduler-tick", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - "--quota-fixture", - str(quota_fixture), - ) - ) - assert_boundary(cli_json) - assert cli_json["scheduler_action"] == "write_precise_blocker", cli_json - assert cli_json["scheduler_hint"]["action"] == "backoff_until_reassigned", cli_json - assert cli_json["launchd"]["recommended_interval_seconds"] == 600, cli_json - - cli_proof_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-local-scheduler-tick", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - "--proof-fixture", - str(proof_fixture), - ) - ) - assert_boundary(cli_proof_json) - assert cli_proof_json["scheduler_action"] == "write_precise_blocker", cli_proof_json - assert cli_proof_json["precise_blocker"]["reason"] == "runtime_idle_evidence_missing", cli_proof_json - - cli_proof_idle_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-local-scheduler-tick", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - "--proof-fixture", - str(proof_fixture), - "--idle-fixture", - str(idle_fixture), - ) - ) - assert_boundary(cli_proof_idle_json) - assert cli_proof_idle_json["scheduler_action"] == "external_visible_command_candidate", cli_proof_idle_json - assert cli_proof_idle_json["runtime_idle_detector"]["approved"] is True, cli_proof_idle_json - - cli_markdown = run_cli( - "codex-cli-local-scheduler-tick", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - "--quota-fixture", - str(quota_fixture), - ) - assert "# Codex CLI Local Scheduler Tick" in cli_markdown, cli_markdown - assert "scheduler_action: `write_precise_blocker`" in cli_markdown, cli_markdown - assert "local_progression_minutes: `[10, 20, 30, 60]`" in cli_markdown, cli_markdown - assert "local_unchanged_poll_limit: `3`" in cli_markdown, cli_markdown - assert "final_quota_replan_check:" in cli_markdown, cli_markdown - assert "runs_codex: `False`" in cli_markdown, cli_markdown - - print("codex-cli-local-scheduler-tick-smoke ok") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/examples/codex-cli-one-message-loop-pilot-smoke.py b/examples/codex-cli-one-message-loop-pilot-smoke.py deleted file mode 100644 index 9be5cafa6a..0000000000 --- a/examples/codex-cli-one-message-loop-pilot-smoke.py +++ /dev/null @@ -1,277 +0,0 @@ -#!/usr/bin/env python3 -"""Smoke-test the Codex CLI one-message loop pilot packet.""" - -from __future__ import annotations - -import json -import subprocess -import sys -import tempfile -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -if str(REPO_ROOT) not in sys.path: - sys.path.insert(0, str(REPO_ROOT)) - -from loopx.codex_cli_probe import ( # noqa: E402 - build_codex_cli_one_message_loop_pilot, - classify_codex_cli_session_surface, -) - - -PROJECT = Path("/tmp/public-codex-cli-project") -GOAL_ID = "public-codex-cli-goal" -AGENT_ID = "codex-side-bypass" - - -REMOTE_RESUME_HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec - remote-control Manage the app-server daemon with remote control enabled - resume Resume a previous interactive session - -Options: - --remote Connect the TUI to a remote app server endpoint -""", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": """ -Usage: codex resume [OPTIONS] [SESSION_ID] [PROMPT] - -Resume a previous interactive session. -""", -} - - -VISIBLE_PROOF_FIXTURE = { - "observed_surface": "visible_resume_prompt", - "recommended_command": "codex resume public-session-id 'LoopX visible steering turn'", - "user_opt_in": True, - "quota_guard": {"passed": True}, - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": { - "visible_to_user": True, - "prompt_public_safe": True, - }, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - "spends_quota_before_writeback": False, - }, - "writeback": {"compact_evidence_planned": True}, -} - - -RUNTIME_IDLE_FIXTURE = { - "observed_surface": "visible_resume_prompt", - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": {"visible_to_user": True}, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - }, -} - - -def build_pilot( - proof_payload: dict[str, object] | None = None, - idle_payload: dict[str, object] | None = None, -) -> dict[str, object]: - return build_codex_cli_one_message_loop_pilot( - project=PROJECT, - goal_id=GOAL_ID, - agent_id=AGENT_ID, - cli_bin="loopx", - codex_bin="codex", - probe_payload=classify_codex_cli_session_surface(command_outputs=REMOTE_RESUME_HELP_FIXTURE), - proof_payload=proof_payload, - idle_payload=idle_payload, - ) - - -def assert_pilot_boundary(payload: dict[str, object]) -> None: - assert payload["ok"] is True, payload - assert payload["schema_version"] == "codex_cli_one_message_loop_pilot_v0", payload - boundary = payload["boundary"] - assert boundary["pilot_packet_only"] is True, payload - assert boundary["runs_codex"] is False, payload - assert boundary["runs_scheduler_result"] is False, payload - assert boundary["reads_raw_transcripts"] is False, payload - assert boundary["reads_credentials"] is False, payload - assert boundary["reads_session_files"] is False, payload - assert boundary["mutates_codex_session"] is False, payload - assert boundary["spends_loopx_quota"] is False, payload - assert boundary["requires_user_visible_start"] is True, payload - assert boundary["headless_execution_disabled"] is True, payload - - -def run_cli(*extra_args: str) -> str: - result = subprocess.run( - [sys.executable, "-m", "loopx.cli", *extra_args], - cwd=REPO_ROOT, - check=True, - capture_output=True, - text=True, - ) - return result.stdout - - -def main() -> int: - no_proof = build_pilot() - assert_pilot_boundary(no_proof) - assert no_proof["start_surface"] == "codex_cli_tui_one_message", no_proof - assert no_proof["pilot_decision"] == "first_message_then_visible_blocker_writeback", no_proof - assert no_proof["first_turn"]["autostarts_loopx_loop"] is True, no_proof - assert no_proof["first_turn"]["setup_then_loop_activation"] is True, no_proof - assert no_proof["first_turn"]["loop_activation"]["codex_cli"] == "/goal ", no_proof - assert no_proof["first_turn"]["loop_activation"]["codex_app"] == " heartbeat automation", no_proof - assert no_proof["first_turn"]["preserve_tui"] is True, no_proof - assert "workspace_guard" in no_proof["first_turn"]["stop_only_for"], no_proof - assert no_proof["first_turn"]["message"].startswith("Install and connect LoopX for this repo"), no_proof - assert not no_proof["first_turn"]["message"].startswith("/goal "), no_proof - assert "Codex CLI TUI" in no_proof["first_turn"]["message"], no_proof - assert "headless `codex exec`" in no_proof["first_turn"]["message"], no_proof - assert "runtime_idle_evidence" in no_proof["later_turn_contract"]["visible_steering_requires"], no_proof - assert no_proof["bootstrap_message"]["invocation_mode"] == "codex_cli_setup_then_goal_mode", no_proof - assert "heartbeat-prompt --thin" in no_proof["bootstrap_message"]["heartbeat_prompt_json_command"], no_proof - assert no_proof["later_turn_contract"]["default_without_proof"] == "write_blocker_or_keep_tui_bootstrap_primary", no_proof - assert no_proof["automation_bridge"]["command"] == "codex-cli-local-scheduler-exec", no_proof - assert no_proof["automation_bridge"]["default_executes"] is False, no_proof - assert no_proof["automation_bridge"]["scheduler_action"] == "write_precise_blocker", no_proof - assert no_proof["automation_bridge"]["executor_reason"] == "no_execute_flag", no_proof - assert "codex-cli-bootstrap-message" in no_proof["commands"]["bootstrap_message"], no_proof - assert "codex-cli-local-scheduler-exec" in no_proof["commands"]["scheduler_exec_dry_run"], no_proof - assert "--execute-blocker-writeback" in no_proof["commands"]["scheduler_exec_blocker_template"], no_proof - - with_proof = build_pilot(VISIBLE_PROOF_FIXTURE) - assert_pilot_boundary(with_proof) - assert with_proof["pilot_decision"] == "first_message_then_runtime_idle_required", with_proof - assert with_proof["automation_bridge"]["scheduler_action"] == "write_precise_blocker", with_proof - assert with_proof["scheduler_executor"]["execution"]["executed"] is False, with_proof - - with_proof_and_idle = build_pilot(VISIBLE_PROOF_FIXTURE, RUNTIME_IDLE_FIXTURE) - assert_pilot_boundary(with_proof_and_idle) - assert with_proof_and_idle["pilot_decision"] == "first_message_then_candidate_available", with_proof_and_idle - assert with_proof_and_idle["automation_bridge"]["scheduler_action"] == "external_visible_command_candidate", with_proof_and_idle - assert with_proof_and_idle["scheduler_executor"]["scheduler_tick"]["runtime_idle_detector"]["approved"] is True, with_proof_and_idle - - with tempfile.TemporaryDirectory(prefix="loopx-codex-cli-one-message-") as tmp: - tmp_path = Path(tmp) - help_fixture = tmp_path / "codex-remote-help.json" - help_fixture.write_text(json.dumps({"command_outputs": REMOTE_RESUME_HELP_FIXTURE})) - proof_fixture = tmp_path / "visible-proof.json" - proof_fixture.write_text(json.dumps(VISIBLE_PROOF_FIXTURE)) - idle_fixture = tmp_path / "runtime-idle.json" - idle_fixture.write_text(json.dumps(RUNTIME_IDLE_FIXTURE)) - missing_registry = tmp_path / "missing-registry.json" - runtime_root = tmp_path / "runtime" - - cli_json = json.loads( - run_cli( - "--registry", - str(missing_registry), - "--runtime-root", - str(runtime_root), - "--format", - "json", - "codex-cli-one-message-loop-pilot", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - ) - ) - assert_pilot_boundary(cli_json) - assert cli_json["pilot_decision"] == "first_message_then_visible_blocker_writeback", cli_json - - cli_proof_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-one-message-loop-pilot", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - "--proof-fixture", - str(proof_fixture), - ) - ) - assert_pilot_boundary(cli_proof_json) - assert cli_proof_json["pilot_decision"] == "first_message_then_runtime_idle_required", cli_proof_json - - cli_proof_idle_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-one-message-loop-pilot", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - "--proof-fixture", - str(proof_fixture), - "--idle-fixture", - str(idle_fixture), - ) - ) - assert_pilot_boundary(cli_proof_idle_json) - assert cli_proof_idle_json["pilot_decision"] == "first_message_then_candidate_available", cli_proof_idle_json - - cli_markdown = run_cli( - "codex-cli-one-message-loop-pilot", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - ) - assert "# Codex CLI One-Message Loop Pilot" in cli_markdown, cli_markdown - assert "requires_user_visible_start: `True`" in cli_markdown, cli_markdown - assert "candidate_execution_requires_guard_and_prefix: `True`" in cli_markdown, cli_markdown - - print("codex-cli-one-message-loop-pilot-smoke ok") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/examples/codex-cli-proof-capture-demo-fixtures-smoke.py b/examples/codex-cli-proof-capture-demo-fixtures-smoke.py deleted file mode 100644 index c71b589f51..0000000000 --- a/examples/codex-cli-proof-capture-demo-fixtures-smoke.py +++ /dev/null @@ -1,157 +0,0 @@ -#!/usr/bin/env python3 -"""Validate the public Codex CLI proof-capture demo fixtures.""" - -from __future__ import annotations - -import json -import subprocess -import sys -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -if str(REPO_ROOT) not in sys.path: - sys.path.insert(0, str(REPO_ROOT)) - -from loopx.codex_cli_probe import ( # noqa: E402 - build_codex_cli_visible_attach_acceptance, - classify_codex_cli_session_surface, -) - - -PROJECT = Path("/tmp/public-codex-cli-project") -GOAL_ID = "public-codex-cli-goal" -AGENT_ID = "codex-side-bypass" -FIXTURE_DIR = REPO_ROOT / "examples" / "fixtures" / "codex-cli-visible-proof" - - -def load_fixture(name: str) -> dict[str, object]: - path = FIXTURE_DIR / name - return json.loads(path.read_text()) - - -def command_outputs(name: str) -> dict[str, str]: - payload = load_fixture(name) - outputs = payload["command_outputs"] - assert isinstance(outputs, dict), payload - return {str(key): str(value) for key, value in outputs.items()} - - -def build_acceptance( - help_fixture: str, - proof_fixture: str, - idle_fixture: str, -) -> dict[str, object]: - return build_codex_cli_visible_attach_acceptance( - project=PROJECT, - goal_id=GOAL_ID, - agent_id=AGENT_ID, - cli_bin="loopx", - codex_bin="codex", - probe_payload=classify_codex_cli_session_surface( - command_outputs=command_outputs(help_fixture) - ), - proof_payload=load_fixture(proof_fixture), - idle_payload=load_fixture(idle_fixture), - ) - - -def run_cli_acceptance( - help_fixture: str, - proof_fixture: str, - idle_fixture: str, -) -> dict[str, object]: - result = subprocess.run( - [ - sys.executable, - "-m", - "loopx.cli", - "--format", - "json", - "codex-cli-visible-attach-acceptance", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(FIXTURE_DIR / help_fixture), - "--proof-fixture", - str(FIXTURE_DIR / proof_fixture), - "--idle-fixture", - str(FIXTURE_DIR / idle_fixture), - ], - cwd=REPO_ROOT, - check=True, - capture_output=True, - text=True, - ) - return json.loads(result.stdout) - - -def assert_public_safe_boundary(payload: dict[str, object]) -> None: - boundary = payload["boundary"] - assert boundary["acceptance_packet_only"] is True, payload - assert boundary["runs_codex"] is False, payload - assert boundary["reads_raw_transcripts"] is False, payload - assert boundary["reads_session_files"] is False, payload - assert boundary["reads_stdout_stderr"] is False, payload - assert boundary["mutates_codex_session"] is False, payload - assert boundary["spends_loopx_quota"] is False, payload - assert boundary["writes_loopx_state"] is False, payload - - -def assert_visible_resume_spike(payload: dict[str, object]) -> None: - assert payload["decision"] == "visible_surface_spike_passed_not_same_tui", payload - assert payload["accepted_for_visible_later_turn"] is True, payload - assert payload["accepted_for_same_tui_automation"] is False, payload - assert payload["observed_surface"] == "visible_resume_prompt", payload - assert "same_tui_visible_attach_not_proven" in payload["blockers"], payload - assert_public_safe_boundary(payload) - - -def assert_same_tui_accepted(payload: dict[str, object]) -> None: - assert payload["decision"] == "same_tui_visible_attach_accepted", payload - assert payload["accepted_for_visible_later_turn"] is True, payload - assert payload["accepted_for_same_tui_automation"] is True, payload - assert payload["observed_surface"] == "same_tui_visible_attach", payload - assert payload["blockers"] == [], payload - assert_public_safe_boundary(payload) - - -def main() -> int: - visible_resume = build_acceptance( - "codex-visible-resume-help.public.json", - "visible-resume-proof.public.json", - "runtime-idle-visible-resume.public.json", - ) - assert_visible_resume_spike(visible_resume) - - visible_resume_cli = run_cli_acceptance( - "codex-visible-resume-help.public.json", - "visible-resume-proof.public.json", - "runtime-idle-visible-resume.public.json", - ) - assert_visible_resume_spike(visible_resume_cli) - - same_tui = build_acceptance( - "codex-same-tui-help.public.json", - "same-tui-proof.public.json", - "runtime-idle-same-tui.public.json", - ) - assert_same_tui_accepted(same_tui) - - same_tui_cli = run_cli_acceptance( - "codex-same-tui-help.public.json", - "same-tui-proof.public.json", - "runtime-idle-same-tui.public.json", - ) - assert_same_tui_accepted(same_tui_cli) - - print("codex-cli-proof-capture-demo-fixtures-smoke ok") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/examples/codex-cli-runtime-idle-detector-smoke.py b/examples/codex-cli-runtime-idle-detector-smoke.py deleted file mode 100644 index 458ada76c9..0000000000 --- a/examples/codex-cli-runtime-idle-detector-smoke.py +++ /dev/null @@ -1,246 +0,0 @@ -#!/usr/bin/env python3 -"""Smoke-test the Codex CLI runtime idle detector packet.""" - -from __future__ import annotations - -import json -import subprocess -import sys -import tempfile -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -if str(REPO_ROOT) not in sys.path: - sys.path.insert(0, str(REPO_ROOT)) - -from loopx.codex_cli_probe import ( # noqa: E402 - build_codex_cli_runtime_idle_detector, - build_codex_cli_runtime_idle_observation_payload, -) - - -PROJECT = Path("/tmp/public-codex-cli-project") -GOAL_ID = "public-codex-cli-goal" -AGENT_ID = "codex-side-bypass" - - -PASSING_IDLE_FIXTURE = { - "observed_surface": "visible_resume_prompt", - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": {"visible_to_user": True}, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - }, -} - - -def build_idle(payload: dict[str, object] | None) -> dict[str, object]: - return build_codex_cli_runtime_idle_detector( - project=PROJECT, - goal_id=GOAL_ID, - agent_id=AGENT_ID, - cli_bin="loopx", - idle_payload=payload, - ) - - -def assert_boundary(payload: dict[str, object]) -> None: - boundary = payload["boundary"] - assert boundary["runs_codex"] is False, payload - assert boundary["reads_raw_transcripts"] is False, payload - assert boundary["reads_session_files"] is False, payload - assert boundary["reads_stdout_stderr"] is False, payload - assert boundary["reads_credentials"] is False, payload - assert boundary["mutates_codex_session"] is False, payload - assert boundary["spends_loopx_quota"] is False, payload - - -def run_cli(*extra_args: str) -> str: - result = subprocess.run( - [sys.executable, "-m", "loopx.cli", *extra_args], - cwd=REPO_ROOT, - check=True, - capture_output=True, - text=True, - ) - return result.stdout - - -def run_cli_fail_closed(*extra_args: str) -> str: - result = subprocess.run( - [sys.executable, "-m", "loopx.cli", *extra_args], - cwd=REPO_ROOT, - check=False, - capture_output=True, - text=True, - ) - assert result.returncode != 0, result.stdout - return result.stdout - - -def main() -> int: - missing = build_idle(None) - assert missing["ok"] is False, missing - assert missing["schema_version"] == "codex_cli_runtime_idle_detector_v0", missing - assert missing["decision"] == "runtime_idle_evidence_required", missing - assert missing["approved_for_visible_later_turn"] is False, missing - assert "missing_runtime_idle_evidence" in missing["failures"], missing - assert_boundary(missing) - - failing_fixture = dict(PASSING_IDLE_FIXTURE) - failing_fixture["idle_guard"] = dict(PASSING_IDLE_FIXTURE["idle_guard"]) - failing_fixture["idle_guard"]["no_running_turn"] = False - incomplete = build_idle(failing_fixture) - assert incomplete["ok"] is True, incomplete - assert incomplete["decision"] == "runtime_idle_detector_incomplete", incomplete - assert incomplete["approved_for_visible_later_turn"] is False, incomplete - assert "idle_no_running_turn" in incomplete["failures"], incomplete - assert_boundary(incomplete) - - passing = build_idle(PASSING_IDLE_FIXTURE) - assert passing["ok"] is True, passing - assert passing["decision"] == "runtime_idle_detector_passed", passing - assert passing["approved_for_visible_later_turn"] is True, passing - assert passing["observed_surface"] == "visible_resume_prompt", passing - assert not passing["failures"], passing - assert passing["source"] == "idle_fixture", passing - assert passing["boundary"]["fixture_only"] is True, passing - assert_boundary(passing) - - local_observation = build_codex_cli_runtime_idle_observation_payload( - observed_surface="visible_resume_prompt", - turn_state="idle", - human_input_idle_seconds=12.0, - min_human_input_idle_seconds=5.0, - checked_before_prompt=True, - visible_to_user=True, - user_can_interrupt=True, - manual_takeover_available=True, - probe_result={"ok": True, "source": "test_idle_counter"}, - ) - local_passing = build_idle(local_observation) - assert local_passing["ok"] is True, local_passing - assert local_passing["decision"] == "runtime_idle_detector_passed", local_passing - assert local_passing["approved_for_visible_later_turn"] is True, local_passing - assert local_passing["source"] == "local_runtime_observation", local_passing - assert local_passing["boundary"]["fixture_only"] is False, local_passing - assert local_passing["boundary"]["local_observation_adapter_supported"] is True, local_passing - runtime_observation = local_passing["runtime_observation"] - assert runtime_observation["human_input_idle_seconds"] == 12.0, local_passing - assert runtime_observation["turn_state"] == "idle", local_passing - assert_boundary(local_passing) - - local_unknown_turn = build_idle( - build_codex_cli_runtime_idle_observation_payload( - observed_surface="visible_resume_prompt", - turn_state="unknown", - human_input_idle_seconds=12.0, - min_human_input_idle_seconds=5.0, - checked_before_prompt=True, - visible_to_user=True, - user_can_interrupt=True, - manual_takeover_available=True, - ) - ) - assert local_unknown_turn["decision"] == "runtime_idle_detector_incomplete", local_unknown_turn - assert "idle_no_running_turn" in local_unknown_turn["failures"], local_unknown_turn - - local_recent_input = build_idle( - build_codex_cli_runtime_idle_observation_payload( - observed_surface="visible_resume_prompt", - turn_state="idle", - human_input_idle_seconds=1.0, - min_human_input_idle_seconds=5.0, - checked_before_prompt=True, - visible_to_user=True, - user_can_interrupt=True, - manual_takeover_available=True, - ) - ) - assert local_recent_input["decision"] == "runtime_idle_detector_incomplete", local_recent_input - assert "idle_no_human_typing" in local_recent_input["failures"], local_recent_input - - with tempfile.TemporaryDirectory(prefix="loopx-codex-cli-runtime-idle-") as tmp: - fixture = Path(tmp) / "runtime-idle.json" - fixture.write_text(json.dumps(PASSING_IDLE_FIXTURE)) - - cli_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-runtime-idle-detector", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--idle-fixture", - str(fixture), - ) - ) - assert cli_json["decision"] == "runtime_idle_detector_passed", cli_json - assert cli_json["approved_for_visible_later_turn"] is True, cli_json - assert_boundary(cli_json) - - cli_local_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-runtime-idle-detector", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--observe-local-runtime", - "--observed-surface", - "visible_resume_prompt", - "--turn-state", - "idle", - "--human-input-idle-seconds", - "12", - "--min-human-input-idle-seconds", - "5", - "--checked-before-prompt", - "--visible-to-user", - "--user-can-interrupt", - "--manual-takeover-available", - ) - ) - assert cli_local_json["decision"] == "runtime_idle_detector_passed", cli_local_json - assert cli_local_json["source"] == "local_runtime_observation", cli_local_json - assert cli_local_json["runtime_observation"]["human_input_idle_seconds"] == 12.0, cli_local_json - assert_boundary(cli_local_json) - - cli_markdown = run_cli_fail_closed( - "codex-cli-runtime-idle-detector", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - ) - assert "# Codex CLI Runtime Idle Detector" in cli_markdown, cli_markdown - assert "runtime_idle_evidence_required" in cli_markdown, cli_markdown - assert "reads_stdout_stderr: `False`" in cli_markdown, cli_markdown - - print("codex-cli-runtime-idle-detector-smoke ok") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/examples/codex-cli-session-probe-smoke.py b/examples/codex-cli-session-probe-smoke.py deleted file mode 100644 index 7f28f99030..0000000000 --- a/examples/codex-cli-session-probe-smoke.py +++ /dev/null @@ -1,216 +0,0 @@ -#!/usr/bin/env python3 -"""Smoke-test the Codex CLI session-attachment capability probe.""" - -from __future__ import annotations - -import json -import subprocess -import sys -import tempfile -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -if str(REPO_ROOT) not in sys.path: - sys.path.insert(0, str(REPO_ROOT)) - -from loopx.codex_cli_probe import ( # noqa: E402 - build_codex_cli_visible_driver_plan, - classify_codex_cli_session_surface, -) - - -HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec Run Codex non-interactively - resume Resume a previous conversation -""", - "exec": """ -Usage: codex exec [OPTIONS] [PROMPT] - -Options: - --resume Continue from a previous session -""", - "resume": """ -Usage: codex resume [SESSION_ID] - -Resume a previous conversation in a new Codex invocation. -""", -} - - -ATTACH_HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec - resume - attach-session Send prompt to session after checking the idle TUI -""", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": "Usage: codex resume [SESSION_ID]", -} - - -REMOTE_RESUME_HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec - remote-control Manage the app-server daemon with remote control enabled - resume Resume a previous interactive session - -Options: - --remote Connect the TUI to a remote app server endpoint -""", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": """ -Usage: codex resume [OPTIONS] [SESSION_ID] [PROMPT] - -Resume a previous interactive session. -""", -} - - -def run_cli(*extra_args: str) -> str: - result = subprocess.run( - [sys.executable, "-m", "loopx.cli", *extra_args], - cwd=REPO_ROOT, - check=True, - capture_output=True, - text=True, - ) - return result.stdout - - -def assert_fallback_contract(payload: dict[str, object]) -> None: - assert payload["ok"] is True, payload - assert payload["schema_version"] == "codex_cli_session_probe_v0", payload - capabilities = payload["capabilities"] - assert capabilities["exec_supported"] is True, payload - assert capabilities["resume_supported"] is True, payload - assert capabilities["session_handle_detected"] is True, payload - assert capabilities["visible_resume_supported"] is False, payload - assert capabilities["remote_control_surface_detected"] is False, payload - assert capabilities["same_tui_injection_detected"] is False, payload - assert capabilities["safe_injection_supported"] is False, payload - assert payload["recommended_mode"] == "tui_bootstrap_only", payload - assert payload["automation_action"] == "ask_user_to_start_inside_codex_cli_tui", payload - assert any("headless fallback is disabled" in warning for warning in payload["warnings"]), payload - boundary = payload["boundary"] - assert boundary["help_only_probe"] is True, payload - assert boundary["reads_raw_transcripts"] is False, payload - assert boundary["reads_credentials"] is False, payload - assert boundary["reads_session_files"] is False, payload - assert boundary["mutates_codex_session"] is False, payload - assert boundary["spends_loopx_quota"] is False, payload - - -def main() -> int: - payload = classify_codex_cli_session_surface(command_outputs=HELP_FIXTURE) - assert_fallback_contract(payload) - - remote_payload = classify_codex_cli_session_surface(command_outputs=REMOTE_RESUME_HELP_FIXTURE) - assert remote_payload["capabilities"]["visible_resume_supported"] is True, remote_payload - assert remote_payload["capabilities"]["remote_control_surface_detected"] is True, remote_payload - assert remote_payload["capabilities"]["same_tui_injection_detected"] is False, remote_payload - assert remote_payload["recommended_mode"] == "visible_resume_or_remote_control_spike", remote_payload - assert remote_payload["automation_action"] == "prototype_visible_resume_or_remote_control_with_idle_guard", remote_payload - remote_plan = build_codex_cli_visible_driver_plan( - project=Path("/tmp/public-codex-cli-project"), - goal_id="public-codex-cli-goal", - agent_id="codex-side-bypass", - cli_bin="loopx", - codex_bin="codex", - probe_payload=remote_payload, - ) - assert remote_plan["schema_version"] == "codex_cli_visible_driver_plan_v0", remote_plan - assert remote_plan["driver_mode"] == "visible_resume_or_remote_control_spike", remote_plan - assert remote_plan["boundary"]["dry_run_plan_only"] is True, remote_plan - assert remote_plan["boundary"]["reads_raw_transcripts"] is False, remote_plan - assert remote_plan["boundary"]["reads_session_files"] is False, remote_plan - assert remote_plan["boundary"]["mutates_codex_session"] is False, remote_plan - assert remote_plan["boundary"]["spends_loopx_quota"] is False, remote_plan - assert "resume [PROMPT]" in " ".join(remote_plan["driver_steps"]), remote_plan - assert remote_plan["commands"]["explicit_headless_fallback"] is None, remote_plan - assert "headless codex exec is disabled" in remote_plan["commands"]["headless_fallback_disabled"], remote_plan - - attach_payload = classify_codex_cli_session_surface(command_outputs=ATTACH_HELP_FIXTURE) - assert attach_payload["capabilities"]["safe_injection_supported"] is True, attach_payload - assert attach_payload["recommended_mode"] == "session_attached_visible_turn", attach_payload - attach_plan = build_codex_cli_visible_driver_plan( - project=Path("/tmp/public-codex-cli-project"), - goal_id="public-codex-cli-goal", - agent_id="codex-side-bypass", - cli_bin="loopx", - codex_bin="codex", - probe_payload=attach_payload, - ) - assert attach_plan["driver_mode"] == "session_attached_visible_turn", attach_plan - assert "visible attach primitive" in attach_plan["next_step"], attach_plan - - with tempfile.TemporaryDirectory(prefix="loopx-codex-cli-probe-") as tmp: - fixture = Path(tmp) / "codex-help.json" - fixture.write_text(json.dumps({"command_outputs": HELP_FIXTURE})) - cli_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-session-probe", - "--fixture", - str(fixture), - ) - ) - assert_fallback_contract(cli_json) - - cli_markdown = run_cli("codex-cli-session-probe", "--fixture", str(fixture)) - assert "# Codex CLI Session Probe" in cli_markdown, cli_markdown - assert "recommended_mode: `tui_bootstrap_only`" in cli_markdown, cli_markdown - assert "same_tui_injection_detected: `False`" in cli_markdown, cli_markdown - - remote_fixture = Path(tmp) / "codex-remote-help.json" - remote_fixture.write_text(json.dumps({"command_outputs": REMOTE_RESUME_HELP_FIXTURE})) - cli_plan_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-visible-driver-plan", - "--project", - "/tmp/public-codex-cli-project", - "--goal-id", - "public-codex-cli-goal", - "--agent-id", - "codex-side-bypass", - "--fixture", - str(remote_fixture), - ) - ) - assert cli_plan_json["driver_mode"] == "visible_resume_or_remote_control_spike", cli_plan_json - assert cli_plan_json["boundary"]["dry_run_plan_only"] is True, cli_plan_json - assert cli_plan_json["boundary"]["reads_raw_transcripts"] is False, cli_plan_json - cli_plan_markdown = run_cli( - "codex-cli-visible-driver-plan", - "--project", - "/tmp/public-codex-cli-project", - "--goal-id", - "public-codex-cli-goal", - "--agent-id", - "codex-side-bypass", - "--fixture", - str(remote_fixture), - ) - assert "# Codex CLI Visible Driver Plan" in cli_plan_markdown, cli_plan_markdown - assert "driver_mode: `visible_resume_or_remote_control_spike`" in cli_plan_markdown, cli_plan_markdown - assert "dry_run_plan_only: `True`" in cli_plan_markdown, cli_plan_markdown - - print("codex-cli-session-probe-smoke ok") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/examples/codex-cli-tui-bootstrap-smoke-bundle-smoke.py b/examples/codex-cli-tui-bootstrap-smoke-bundle-smoke.py deleted file mode 100644 index 2b59e7a1dd..0000000000 --- a/examples/codex-cli-tui-bootstrap-smoke-bundle-smoke.py +++ /dev/null @@ -1,230 +0,0 @@ -#!/usr/bin/env python3 -"""Smoke-test the transcript-free Codex CLI TUI bootstrap bundle.""" - -from __future__ import annotations - -import json -import os -import subprocess -import sys -import tarfile -import tempfile -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -GOAL_ID = "public-fresh-codex-cli-goal" -AGENT_ID = "codex-side-bypass" - - -def add_tree(tar: tarfile.TarFile, root: Path, name: str) -> None: - path = root / name - if path.is_dir(): - for child in sorted(path.rglob("*")): - if ".git" in child.parts or "__pycache__" in child.parts: - continue - tar.add( - child, - arcname=str(Path("loopx-main") / child.relative_to(root)), - recursive=False, - ) - else: - tar.add(path, arcname=str(Path("loopx-main") / name)) - - -def run(command: list[str], *, env: dict[str, str], cwd: Path) -> subprocess.CompletedProcess[str]: - return subprocess.run( - command, - check=True, - env=env, - cwd=cwd, - text=True, - capture_output=True, - ) - - -def path_without_loopx(path_text: str) -> str: - entries: list[str] = [] - for entry in path_text.split(os.pathsep): - if not entry: - continue - if (Path(entry).expanduser() / "loopx").exists(): - continue - entries.append(entry) - return os.pathsep.join(entries) - - -def main() -> None: - install_script = REPO_ROOT / "scripts" / "install-from-github.sh" - subprocess.run(["bash", "-n", str(install_script)], check=True) - - with tempfile.TemporaryDirectory(prefix="loopx-codex-cli-tui-bundle-") as td: - tmp = Path(td) - archive = tmp / "loopx.tar.gz" - home = tmp / "home" - fake_bin = tmp / "fake-bin" - fresh_repo = tmp / "public-fresh-repo" - codex_called_marker = tmp / "codex-called" - home.mkdir() - fake_bin.mkdir() - fresh_repo.mkdir() - (fresh_repo / "README.md").write_text("# Public fresh repo\n", encoding="utf-8") - - fake_codex = fake_bin / "codex" - fake_codex.write_text( - "#!/usr/bin/env bash\n" - "echo called > \"${CODEX_CALLED_MARKER:?}\"\n" - "exit 77\n", - encoding="utf-8", - ) - fake_codex.chmod(0o755) - - with tarfile.open(archive, "w:gz") as tar: - for name in ( - "loopx", - "scripts", - "skills", - "docs", - "examples", - "README.md", - "pyproject.toml", - "LICENSE", - ): - add_tree(tar, REPO_ROOT, name) - - env = os.environ.copy() - host_path_without_loopx = path_without_loopx(env.get("PATH", "")) - env.update( - { - "HOME": str(home), - "CODEX_HOME": str(home / ".codex"), - "LOOPX_BIN_DIR": str(home / ".local" / "bin"), - "LOOPX_RELEASES_DIR": str(home / ".local" / "share" / "loopx" / "releases"), - "LOOPX_SHELL_PROFILE": str(home / ".profile"), - "LOOPX_ARCHIVE_URL": f"file://{archive}", - "LOOPX_INSTALL_CANARY": "0", - "LOOPX_PYTHON": sys.executable, - "CODEX_CALLED_MARKER": str(codex_called_marker), - "PATH": f"{fake_bin}:{host_path_without_loopx}", - } - ) - run(["bash", str(install_script)], env=env, cwd=tmp) - - installed = home / ".local" / "bin" / "loopx" - assert installed.exists(), installed - run([str(installed), "doctor"], env=env, cwd=fresh_repo) - - bundle = json.loads( - run( - [ - str(installed), - "--format", - "json", - "codex-cli-tui-bootstrap-smoke-bundle", - "--project", - str(fresh_repo), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - ], - env=env, - cwd=fresh_repo, - ).stdout - ) - assert bundle["schema_version"] == "codex_cli_tui_bootstrap_smoke_bundle_v0", bundle - assert bundle["goal_id"] == GOAL_ID, bundle - assert bundle["agent_id"] == AGENT_ID, bundle - assert "--message-only" in bundle["message_only_command"], bundle - assert str(fresh_repo) in bundle["message_only_command"], bundle - repair = bundle["install_repair_command"] - assert "loopx doctor" in repair, bundle - if os.name == "nt": - assert "| bash" not in repair, bundle - assert ( - "install-windows.ps1" in repair - or "-m pip install --upgrade loopx" in repair - ), bundle - else: - assert "loopx-project.github.io/loopx/install.sh" in repair, bundle - assert "python3 -m pip install --upgrade loopx" in repair, bundle - assert "workflow-skills --install" in repair, bundle - assert "quota should-run" in bundle["quota_guard_command"], bundle - assert "--agent-id codex-side-bypass" in bundle["quota_guard_command"], bundle - assert "refresh-state --goal-id public-fresh-codex-cli-goal" in bundle["refresh_command"], bundle - assert "--delivery-batch-scale " in bundle["progress_refresh_command"], bundle - assert "--delivery-outcome " in bundle["progress_refresh_command"], bundle - assert "--delivery-outcome outcome_progress" not in bundle["progress_refresh_command"], bundle - assert "--agent-id codex-side-bypass" in bundle["progress_refresh_command"], bundle - assert "quota spend-slot" in bundle["quota_spend_command"], bundle - assert "--source heartbeat --execute --agent-id codex-side-bypass" in bundle["quota_spend_command"], bundle - assert any("message-only command" in item for item in bundle["validation_checklist"]), bundle - assert any("no raw Codex transcripts" in item for item in bundle["validation_checklist"]), bundle - - boundary = bundle["boundary"] - for key in ( - "runs_codex", - "reads_raw_transcripts", - "reads_session_files", - "reads_credentials", - "mutates_codex_session", - "spends_loopx_quota", - "requires_loopx_repo_clone", - ): - assert boundary[key] is False, (key, boundary) - - message_only = run( - [ - str(installed), - "codex-cli-bootstrap-message", - "--project", - str(fresh_repo), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--message-only", - ], - env=env, - cwd=fresh_repo, - ).stdout - assert message_only.startswith("Install and connect LoopX for this repo"), message_only - assert not message_only.startswith("/goal "), message_only - assert "# Codex CLI LoopX Bootstrap Message" not in message_only, message_only - assert "Fresh Repo Install Repair" not in message_only, message_only - assert "loopx doctor" in message_only, message_only - if os.name != "nt": - assert "loopx-project.github.io/loopx/install.sh" in message_only, message_only - assert "python3 -m pip install --upgrade loopx" in message_only, message_only - assert "/goal " in message_only, message_only - assert "quota should-run" in message_only, message_only - assert "refresh-state --goal-id public-fresh-codex-cli-goal" in message_only, message_only - assert "settlement_plan.ordered_steps" in message_only, message_only - assert "raw Codex transcripts" in message_only, message_only - - markdown = run( - [ - str(installed), - "codex-cli-tui-bootstrap-smoke-bundle", - "--project", - str(fresh_repo), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - ], - env=env, - cwd=fresh_repo, - ).stdout - assert "# Codex CLI TUI Bootstrap Smoke Bundle" in markdown, markdown - assert "Transcript-Free Boundary" in markdown, markdown - assert "runs_codex: `False`" in markdown, markdown - assert "requires_loopx_repo_clone: `False`" in markdown, markdown - - assert not codex_called_marker.exists(), codex_called_marker - - print("codex-cli-tui-bootstrap-smoke-bundle-smoke ok") - - -if __name__ == "__main__": - main() diff --git a/examples/codex-cli-visible-attach-acceptance-smoke.py b/examples/codex-cli-visible-attach-acceptance-smoke.py deleted file mode 100644 index 913877fe31..0000000000 --- a/examples/codex-cli-visible-attach-acceptance-smoke.py +++ /dev/null @@ -1,265 +0,0 @@ -#!/usr/bin/env python3 -"""Smoke-test the Codex CLI visible attach acceptance packet.""" - -from __future__ import annotations - -import json -import subprocess -import sys -import tempfile -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -if str(REPO_ROOT) not in sys.path: - sys.path.insert(0, str(REPO_ROOT)) - -from loopx.codex_cli_probe import ( # noqa: E402 - build_codex_cli_visible_attach_acceptance, - classify_codex_cli_session_surface, -) - - -PROJECT = Path("/tmp/public-codex-cli-project") -GOAL_ID = "public-codex-cli-goal" -AGENT_ID = "codex-side-bypass" - - -REMOTE_RESUME_HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec - remote-control Manage the app-server daemon with remote control enabled - resume Resume a previous interactive session - -Options: - --remote Connect the TUI to a remote app server endpoint -""", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": "Usage: codex resume [OPTIONS] [SESSION_ID] [PROMPT]", -} - - -ATTACH_HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec - resume - attach-session Send prompt to session after checking the idle TUI -""", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": "Usage: codex resume [SESSION_ID]", -} - - -FALLBACK_HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec Run Codex non-interactively - resume Resume a previous conversation -""", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": "Usage: codex resume [SESSION_ID]", -} - - -def proof_fixture(surface: str) -> dict[str, object]: - return { - "observed_surface": surface, - "user_opt_in": True, - "quota_guard": {"passed": True}, - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": { - "visible_to_user": True, - "prompt_public_safe": True, - }, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - "spends_quota_before_writeback": False, - }, - "writeback": {"compact_evidence_planned": True}, - } - - -PASSING_IDLE_FIXTURE = { - "observed_surface": "same_tui_visible_attach", - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": {"visible_to_user": True}, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - }, -} - - -def run_cli(*extra_args: str) -> str: - result = subprocess.run( - [sys.executable, "-m", "loopx.cli", *extra_args], - cwd=REPO_ROOT, - check=True, - capture_output=True, - text=True, - ) - return result.stdout - - -def build( - command_outputs: dict[str, str], - *, - proof: dict[str, object] | None = None, - idle: dict[str, object] | None = None, -) -> dict[str, object]: - return build_codex_cli_visible_attach_acceptance( - project=PROJECT, - goal_id=GOAL_ID, - agent_id=AGENT_ID, - cli_bin="loopx", - codex_bin="codex", - probe_payload=classify_codex_cli_session_surface(command_outputs=command_outputs), - proof_payload=proof, - idle_payload=idle, - ) - - -def assert_public_safe_boundary(payload: dict[str, object]) -> None: - boundary = payload["boundary"] - assert boundary["acceptance_packet_only"] is True, payload - assert boundary["runs_codex"] is False, payload - assert boundary["reads_raw_transcripts"] is False, payload - assert boundary["reads_session_files"] is False, payload - assert boundary["reads_stdout_stderr"] is False, payload - assert boundary["mutates_codex_session"] is False, payload - assert boundary["spends_loopx_quota"] is False, payload - assert boundary["writes_loopx_state"] is False, payload - - -def main() -> int: - remote_without_proof = build(REMOTE_RESUME_HELP_FIXTURE) - assert remote_without_proof["ok"] is True, remote_without_proof - assert remote_without_proof["decision"] == "visible_session_proof_required", remote_without_proof - assert remote_without_proof["accepted_for_same_tui_automation"] is False, remote_without_proof - assert "visible_session_proof_missing" in remote_without_proof["blockers"], remote_without_proof - assert_public_safe_boundary(remote_without_proof) - - remote_spike = build( - REMOTE_RESUME_HELP_FIXTURE, - proof=proof_fixture("remote_control_visible_prompt"), - idle={**PASSING_IDLE_FIXTURE, "observed_surface": "remote_control_visible_prompt"}, - ) - assert remote_spike["decision"] == "visible_surface_spike_passed_not_same_tui", remote_spike - assert remote_spike["accepted_for_visible_later_turn"] is True, remote_spike - assert remote_spike["accepted_for_same_tui_automation"] is False, remote_spike - assert "same_tui_visible_attach_not_proven" in remote_spike["blockers"], remote_spike - assert_public_safe_boundary(remote_spike) - - same_tui_accepted = build( - ATTACH_HELP_FIXTURE, - proof=proof_fixture("same_tui_visible_attach"), - idle=PASSING_IDLE_FIXTURE, - ) - assert same_tui_accepted["decision"] == "same_tui_visible_attach_accepted", same_tui_accepted - assert same_tui_accepted["accepted_for_same_tui_automation"] is True, same_tui_accepted - assert same_tui_accepted["accepted_for_visible_later_turn"] is True, same_tui_accepted - assert same_tui_accepted["blockers"] == [], same_tui_accepted - assert_public_safe_boundary(same_tui_accepted) - - missing_idle = build( - ATTACH_HELP_FIXTURE, - proof=proof_fixture("same_tui_visible_attach"), - ) - assert missing_idle["decision"] == "runtime_idle_evidence_required", missing_idle - assert missing_idle["accepted_for_same_tui_automation"] is False, missing_idle - assert "missing_runtime_idle_evidence" in missing_idle["blockers"], missing_idle - assert_public_safe_boundary(missing_idle) - - fallback = build(FALLBACK_HELP_FIXTURE) - assert fallback["decision"] == "tui_bootstrap_only", fallback - assert fallback["accepted_for_same_tui_automation"] is False, fallback - assert fallback["accepted_for_visible_later_turn"] is False, fallback - assert fallback["requirements"]["headless_execution_disabled"] is True, fallback - assert_public_safe_boundary(fallback) - - with tempfile.TemporaryDirectory(prefix="loopx-codex-cli-visible-attach-") as tmp: - tmpdir = Path(tmp) - help_fixture = tmpdir / "codex-attach-help.json" - proof_path = tmpdir / "same-tui-proof.json" - idle_path = tmpdir / "runtime-idle.json" - help_fixture.write_text(json.dumps({"command_outputs": ATTACH_HELP_FIXTURE})) - proof_path.write_text(json.dumps(proof_fixture("same_tui_visible_attach"))) - idle_path.write_text(json.dumps(PASSING_IDLE_FIXTURE)) - - cli_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-visible-attach-acceptance", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - "--proof-fixture", - str(proof_path), - "--idle-fixture", - str(idle_path), - ) - ) - assert cli_json["decision"] == "same_tui_visible_attach_accepted", cli_json - assert cli_json["accepted_for_same_tui_automation"] is True, cli_json - - cli_markdown = run_cli( - "codex-cli-visible-attach-acceptance", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - "--proof-fixture", - str(proof_path), - "--idle-fixture", - str(idle_path), - ) - assert "# Codex CLI Visible Attach Acceptance" in cli_markdown, cli_markdown - assert "accepted_for_same_tui_automation: `True`" in cli_markdown, cli_markdown - assert "same_tui_visible_attach_accepted" in cli_markdown, cli_markdown - - print("codex-cli-visible-attach-acceptance-smoke ok") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/examples/codex-cli-visible-driver-run-smoke.py b/examples/codex-cli-visible-driver-run-smoke.py deleted file mode 100644 index e5246cd71b..0000000000 --- a/examples/codex-cli-visible-driver-run-smoke.py +++ /dev/null @@ -1,233 +0,0 @@ -#!/usr/bin/env python3 -"""Smoke-test the Codex CLI visible driver run packet.""" - -from __future__ import annotations - -import json -import subprocess -import sys -import tempfile -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -if str(REPO_ROOT) not in sys.path: - sys.path.insert(0, str(REPO_ROOT)) - -from loopx.codex_cli_probe import ( # noqa: E402 - build_codex_cli_visible_driver_run_packet, - classify_codex_cli_session_surface, -) - - -PROJECT = Path("/tmp/public-codex-cli-project") -GOAL_ID = "public-codex-cli-goal" -AGENT_ID = "codex-side-bypass" - - -FALLBACK_HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec Run Codex non-interactively - resume Resume a previous conversation -""", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": "Usage: codex resume [SESSION_ID]", -} - - -REMOTE_RESUME_HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec - remote-control Manage the app-server daemon with remote control enabled - resume Resume a previous interactive session - -Options: - --remote Connect the TUI to a remote app server endpoint -""", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": """ -Usage: codex resume [OPTIONS] [SESSION_ID] [PROMPT] - -Resume a previous interactive session. -""", -} - - -VISIBLE_PROOF_FIXTURE = { - "observed_surface": "visible_resume_prompt", - "recommended_command": "codex resume public-session-id 'LoopX visible steering turn'", - "user_opt_in": True, - "quota_guard": {"passed": True}, - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": { - "visible_to_user": True, - "prompt_public_safe": True, - }, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - "spends_quota_before_writeback": False, - }, - "writeback": {"compact_evidence_planned": True}, -} - - -def run_cli(*extra_args: str) -> str: - result = subprocess.run( - [sys.executable, "-m", "loopx.cli", *extra_args], - cwd=REPO_ROOT, - check=True, - capture_output=True, - text=True, - ) - return result.stdout - - -def assert_boundary(payload: dict[str, object]) -> None: - assert payload["ok"] is True, payload - assert payload["schema_version"] == "codex_cli_visible_driver_run_packet_v0", payload - assert payload["driver_phase"] == "run_packet_no_execution", payload - boundary = payload["boundary"] - assert boundary["run_packet_only"] is True, payload - assert boundary["runs_codex"] is False, payload - assert boundary["reads_raw_transcripts"] is False, payload - assert boundary["reads_credentials"] is False, payload - assert boundary["reads_session_files"] is False, payload - assert boundary["mutates_codex_session"] is False, payload - assert boundary["spends_loopx_quota"] is False, payload - policy = payload["execution_policy"] - assert policy["tui_bootstrap_primary"] is True, payload - assert policy["same_session_attachment_requires_visible_proof"] is True, payload - assert policy["headless_execution_disabled"] is True, payload - assert policy["quota_guard_required"] is True, payload - assert policy["idle_guard_required_before_visible_prompt"] is True, payload - assert policy["spend_after_validated_writeback_only"] is True, payload - - -def build_packet( - command_outputs: dict[str, str], - *, - proof_payload: dict[str, object] | None = None, - allow_headless_fallback: bool = False, -) -> dict[str, object]: - return build_codex_cli_visible_driver_run_packet( - project=PROJECT, - goal_id=GOAL_ID, - agent_id=AGENT_ID, - cli_bin="loopx", - codex_bin="codex", - probe_payload=classify_codex_cli_session_surface(command_outputs=command_outputs), - proof_payload=proof_payload, - allow_headless_fallback=allow_headless_fallback, - ) - - -def main() -> int: - proof_required = build_packet(REMOTE_RESUME_HELP_FIXTURE) - assert_boundary(proof_required) - assert proof_required["decision"] == "visible_session_proof_required", proof_required - assert proof_required["next_driver_action"] == "capture_public_safe_visible_session_proof", proof_required - assert proof_required["visible_session_proof"]["supplied"] is False, proof_required - assert "codex-cli-visible-session-proof" in proof_required["recommended_command"], proof_required - - tui_only = build_packet(FALLBACK_HELP_FIXTURE) - assert_boundary(tui_only) - assert tui_only["decision"] == "tui_bootstrap_only", tui_only - assert tui_only["next_driver_action"] == "ask_user_to_start_inside_codex_cli_tui", tui_only - assert "codex-cli-bootstrap-message" in tui_only["recommended_command"], tui_only - - fallback_ignored = build_packet(FALLBACK_HELP_FIXTURE, allow_headless_fallback=True) - assert_boundary(fallback_ignored) - assert fallback_ignored["decision"] == "tui_bootstrap_only", fallback_ignored - assert fallback_ignored["next_driver_action"] == "ask_user_to_start_inside_codex_cli_tui", fallback_ignored - assert "codex-cli-bootstrap-message" in fallback_ignored["recommended_command"], fallback_ignored - assert any("allow_headless_fallback was ignored" in warning for warning in fallback_ignored["warnings"]), fallback_ignored - - visible_candidate = build_packet(REMOTE_RESUME_HELP_FIXTURE, proof_payload=VISIBLE_PROOF_FIXTURE) - assert_boundary(visible_candidate) - assert visible_candidate["decision"] == "visible_session_turn_candidate", visible_candidate - assert visible_candidate["visible_session_proof"]["approved"] is True, visible_candidate - assert "codex resume public-session-id" in visible_candidate["recommended_command"], visible_candidate - - with tempfile.TemporaryDirectory(prefix="loopx-codex-cli-driver-run-") as tmp: - tmp_path = Path(tmp) - help_fixture = tmp_path / "codex-remote-help.json" - help_fixture.write_text(json.dumps({"command_outputs": REMOTE_RESUME_HELP_FIXTURE})) - proof_fixture = tmp_path / "visible-proof.json" - proof_fixture.write_text(json.dumps(VISIBLE_PROOF_FIXTURE)) - - cli_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-visible-driver-run", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - ) - ) - assert_boundary(cli_json) - assert cli_json["decision"] == "visible_session_proof_required", cli_json - - cli_proof_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-visible-driver-run", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - "--proof-fixture", - str(proof_fixture), - ) - ) - assert_boundary(cli_proof_json) - assert cli_proof_json["decision"] == "visible_session_turn_candidate", cli_proof_json - - cli_markdown = run_cli( - "codex-cli-visible-driver-run", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - ) - assert "# Codex CLI Visible Driver Run Packet" in cli_markdown, cli_markdown - assert "decision: `visible_session_proof_required`" in cli_markdown, cli_markdown - assert "runs_codex: `False`" in cli_markdown, cli_markdown - - print("codex-cli-visible-driver-run-smoke ok") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/examples/codex-cli-visible-first-response-capture-plan-smoke.py b/examples/codex-cli-visible-first-response-capture-plan-smoke.py deleted file mode 100644 index 4c98346826..0000000000 --- a/examples/codex-cli-visible-first-response-capture-plan-smoke.py +++ /dev/null @@ -1,171 +0,0 @@ -#!/usr/bin/env python3 -"""Smoke-test the Codex CLI visible first-response capture plan.""" - -from __future__ import annotations - -import json -import subprocess -import sys -import tempfile -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -if str(REPO_ROOT) not in sys.path: - sys.path.insert(0, str(REPO_ROOT)) - -from loopx.codex_cli_probe import ( # noqa: E402 - build_codex_cli_bounded_visible_pilot_adapter, - build_codex_cli_visible_first_response_capture_plan, -) - - -PROJECT = Path("/tmp/public-codex-cli-project") -GOAL_ID = "public-codex-cli-goal" -AGENT_ID = "codex-side-bypass" -DOC = REPO_ROOT / "docs" / "product" / "runtimes" / "codex-cli" / "codex-cli-live-tui-first-message-pilot.md" -PRODUCT_README = ( - REPO_ROOT / "docs" / "product" / "runtimes" / "codex-cli" / "README.md" -) - - -def run_cli(*extra_args: str) -> str: - result = subprocess.run( - [sys.executable, "-m", "loopx.cli", *extra_args], - cwd=REPO_ROOT, - check=True, - capture_output=True, - text=True, - ) - return result.stdout - - -def assert_boundary(payload: dict[str, object]) -> None: - boundary = payload["boundary"] - assert boundary["capture_plan_only"] is True, payload - assert boundary["runs_codex"] is False, payload - assert boundary["reads_raw_transcripts"] is False, payload - assert boundary["reads_session_files"] is False, payload - assert boundary["reads_stdout_stderr"] is False, payload - assert boundary["reads_credentials"] is False, payload - assert boundary["mutates_codex_session"] is False, payload - assert boundary["writes_loopx_state"] is False, payload - assert boundary["spends_loopx_quota"] is False, payload - assert boundary["manual_paste_primary"] is True, payload - assert boundary["argv_prompt_rejected"] is True, payload - assert boundary["success_claim_requires_bounded_adapter"] is True, payload - - -def assert_capture_plan(payload: dict[str, object]) -> None: - assert payload["schema_version"] == "codex_cli_visible_first_response_capture_plan_v0" - assert payload["decision"] == "manual_visible_capture_plan_ready", payload - assert payload["start_surface"] == "codex_cli_tui_manual_paste", payload - assert "public-first-response.json" in payload["commands"]["bounded_visible_pilot_adapter"], payload - assert "public-runtime-idle.json" in payload["commands"]["bounded_visible_pilot_adapter"], payload - assert "codex-cli-bootstrap-message" in payload["commands"]["bootstrap_message"], payload - assert "codex-cli-runtime-idle-detector" in payload["commands"]["runtime_idle_detector"], payload - assert "argv_prompt_used" in payload["sample_first_response_fixture"]["prompt_delivery"], payload - assert payload["sample_first_response_fixture"]["prompt_delivery"]["argv_prompt_used"] is False - assert payload["sample_runtime_idle_fixture"]["idle_guard"]["no_running_turn"] is True - assert "the bootstrap message would have to be passed as argv" in payload["stop_conditions"], payload - assert_boundary(payload) - - -def assert_sample_fixtures_pass_adapter(payload: dict[str, object]) -> None: - passing = build_codex_cli_bounded_visible_pilot_adapter( - project=PROJECT, - goal_id=GOAL_ID, - agent_id=AGENT_ID, - cli_bin="loopx", - first_response_payload=payload["sample_first_response_fixture"], - idle_payload=payload["sample_runtime_idle_fixture"], - ) - assert passing["decision"] == "bounded_visible_pilot_ready_for_success_claim", passing - assert passing["approved_for_live_tui_success_claim"] is True, passing - assert passing["blockers"] == [], passing - - -def assert_cli() -> None: - cli_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-visible-first-response-capture-plan", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - ) - ) - assert_capture_plan(cli_json) - assert_sample_fixtures_pass_adapter(cli_json) - - markdown = run_cli( - "codex-cli-visible-first-response-capture-plan", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - ) - assert "# Codex CLI Visible First-Response Capture Plan" in markdown, markdown - assert "Sample First-Response Fixture" in markdown, markdown - assert "argv_prompt_rejected" in markdown, markdown - assert "reads_raw_transcripts" in markdown, markdown - - with tempfile.TemporaryDirectory(prefix="loopx-codex-cli-first-response-") as tmp: - tmp_path = Path(tmp) - first_response = tmp_path / "public-first-response.json" - idle = tmp_path / "public-runtime-idle.json" - first_response.write_text(json.dumps(cli_json["sample_first_response_fixture"])) - idle.write_text(json.dumps(cli_json["sample_runtime_idle_fixture"])) - adapter = json.loads( - run_cli( - "--format", - "json", - "codex-cli-bounded-visible-pilot-adapter", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--first-response-fixture", - str(first_response), - "--idle-fixture", - str(idle), - ) - ) - assert adapter["approved_for_live_tui_success_claim"] is True, adapter - - -def assert_docs() -> None: - doc = DOC.read_text(encoding="utf-8") - readme = PRODUCT_README.read_text(encoding="utf-8") - assert "codex-cli-visible-first-response-capture-plan" in doc, doc - assert "public-first-response.json" in doc, doc - assert "public-runtime-idle.json" in doc, doc - assert "visible first-response capture plan" in readme, readme - assert "codex-cli-visible-first-response-capture-plan-smoke.py" in readme, readme - - -def main() -> int: - direct = build_codex_cli_visible_first_response_capture_plan( - project=PROJECT, - goal_id=GOAL_ID, - agent_id=AGENT_ID, - cli_bin="loopx", - ) - assert_capture_plan(direct) - assert_sample_fixtures_pass_adapter(direct) - assert_cli() - assert_docs() - print("codex-cli-visible-first-response-capture-plan-smoke ok") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/examples/codex-cli-visible-local-driver-pilot-smoke.py b/examples/codex-cli-visible-local-driver-pilot-smoke.py deleted file mode 100644 index 3143cb5bdd..0000000000 --- a/examples/codex-cli-visible-local-driver-pilot-smoke.py +++ /dev/null @@ -1,290 +0,0 @@ -#!/usr/bin/env python3 -"""Smoke-test the Codex CLI visible local driver pilot packet.""" - -from __future__ import annotations - -import json -import subprocess -import sys -import tempfile -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -if str(REPO_ROOT) not in sys.path: - sys.path.insert(0, str(REPO_ROOT)) - -from loopx.codex_cli_probe import ( # noqa: E402 - build_codex_cli_visible_local_driver_pilot, - classify_codex_cli_session_surface, -) - - -PROJECT = Path("/tmp/public-codex-cli-project") -GOAL_ID = "public-codex-cli-goal" -AGENT_ID = "codex-side-bypass" - - -REMOTE_RESUME_HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec - remote-control Manage the app-server daemon with remote control enabled - resume Resume a previous interactive session - -Options: - --remote Connect the TUI to a remote app server endpoint -""", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": """ -Usage: codex resume [OPTIONS] [SESSION_ID] [PROMPT] - -Resume a previous interactive session. -""", -} - - -VISIBLE_PROOF_FIXTURE = { - "observed_surface": "visible_resume_prompt", - "recommended_command": "codex resume public-session-id 'LoopX visible steering turn'", - "user_opt_in": True, - "quota_guard": {"passed": True}, - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": { - "visible_to_user": True, - "prompt_public_safe": True, - }, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - "spends_quota_before_writeback": False, - }, - "writeback": {"compact_evidence_planned": True}, -} - - -RUNTIME_IDLE_FIXTURE = { - "observed_surface": "visible_resume_prompt", - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": {"visible_to_user": True}, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - }, -} - - -def build_pilot( - proof_payload: dict[str, object] | None = None, - idle_payload: dict[str, object] | None = None, -) -> dict[str, object]: - return build_codex_cli_visible_local_driver_pilot( - project=PROJECT, - goal_id=GOAL_ID, - agent_id=AGENT_ID, - cli_bin="loopx", - codex_bin="codex", - probe_payload=classify_codex_cli_session_surface(command_outputs=REMOTE_RESUME_HELP_FIXTURE), - proof_payload=proof_payload, - idle_payload=idle_payload, - ) - - -def assert_pilot_boundary(payload: dict[str, object]) -> None: - assert payload["ok"] is True, payload - assert payload["schema_version"] == "codex_cli_visible_local_driver_pilot_v0", payload - assert payload["pilot_phase"] == "visible_local_driver_loop_no_execution", payload - boundary = payload["boundary"] - assert boundary["pilot_packet_only"] is True, payload - assert boundary["runs_codex"] is False, payload - assert boundary["runs_scheduler_result"] is False, payload - assert boundary["reads_raw_transcripts"] is False, payload - assert boundary["reads_credentials"] is False, payload - assert boundary["reads_session_files"] is False, payload - assert boundary["reads_stdout_stderr"] is False, payload - assert boundary["mutates_codex_session"] is False, payload - assert boundary["writes_loopx_state"] is False, payload - assert boundary["spends_loopx_quota"] is False, payload - assert boundary["candidate_execution_requires_guard_and_prefix"] is True, payload - assert boundary["blocker_writeback_requires_guard_checked"] is True, payload - - -def run_cli(*extra_args: str) -> str: - result = subprocess.run( - [sys.executable, "-m", "loopx.cli", *extra_args], - cwd=REPO_ROOT, - check=True, - capture_output=True, - text=True, - ) - return result.stdout - - -def main() -> int: - no_proof = build_pilot() - assert_pilot_boundary(no_proof) - assert no_proof["start_surface"] == "codex_cli_tui_one_message", no_proof - assert no_proof["loop_decision"] == "visible_loop_blocker_writeback_ready", no_proof - assert no_proof["next_driver_action"] == "write_precise_blocker_after_fresh_guard", no_proof - assert no_proof["scheduler_executor"]["scheduler_action"] == "write_precise_blocker", no_proof - assert no_proof["scheduler_executor"]["executor_reason"] == "no_execute_flag", no_proof - assert no_proof["scheduler_executor"]["executed"] is False, no_proof - assert no_proof["visible_session_proof"]["approved"] is False, no_proof - assert no_proof["runtime_idle_detector"]["approved"] is False, no_proof - assert no_proof["runtime_idle_detector"]["decision"] == "runtime_idle_evidence_required", no_proof - assert no_proof["idle_guard_contract"]["required_before_visible_prompt"] is True, no_proof - assert no_proof["idle_guard_contract"]["current_pilot_implements_runtime_idle_detection"] is True, no_proof - assert no_proof["idle_guard_contract"]["fixture_backed_runtime_idle_detector"] is True, no_proof - assert no_proof["idle_guard_contract"]["runtime_sensor_implemented"] is True, no_proof - assert no_proof["idle_guard_contract"]["local_observation_adapter_supported"] is True, no_proof - assert no_proof["idle_guard_contract"]["no_private_state_observation"] is True, no_proof - assert "codex-cli-local-scheduler-exec" in no_proof["commands"]["scheduler_exec_dry_run"], no_proof - assert "codex-cli-runtime-idle-detector" in no_proof["commands"]["runtime_idle_detector"], no_proof - assert "--observe-local-runtime" in no_proof["commands"]["runtime_idle_detector"], no_proof - assert "runtime_idle_detector_fixture" in no_proof["commands"], no_proof - assert "--idle-fixture" in no_proof["commands"]["runtime_idle_detector_fixture"], no_proof - assert "--execute-blocker-writeback" in no_proof["commands"]["scheduler_exec_blocker_template"], no_proof - - with_proof = build_pilot(VISIBLE_PROOF_FIXTURE) - assert_pilot_boundary(with_proof) - assert with_proof["loop_decision"] == "runtime_idle_detector_required", with_proof - assert with_proof["next_driver_action"] == "capture_public_safe_runtime_idle_observation", with_proof - assert with_proof["scheduler_executor"]["scheduler_action"] == "write_precise_blocker", with_proof - assert with_proof["visible_session_proof"]["supplied"] is True, with_proof - assert with_proof["visible_session_proof"]["approved"] is True, with_proof - assert with_proof["runtime_idle_detector"]["supplied"] is False, with_proof - assert with_proof["runtime_idle_detector"]["approved"] is False, with_proof - - with_proof_and_idle = build_pilot(VISIBLE_PROOF_FIXTURE, RUNTIME_IDLE_FIXTURE) - assert_pilot_boundary(with_proof_and_idle) - assert with_proof_and_idle["loop_decision"] == "visible_candidate_ready_for_guarded_execution", with_proof_and_idle - assert with_proof_and_idle["next_driver_action"] == "run_scheduler_exec_candidate_after_fresh_guard_and_prefix", with_proof_and_idle - assert with_proof_and_idle["scheduler_executor"]["scheduler_action"] == "external_visible_command_candidate", with_proof_and_idle - assert with_proof_and_idle["visible_session_proof"]["approved"] is True, with_proof_and_idle - assert with_proof_and_idle["runtime_idle_detector"]["supplied"] is True, with_proof_and_idle - assert with_proof_and_idle["runtime_idle_detector"]["approved"] is True, with_proof_and_idle - assert with_proof["execution_policy"]["later_turns_visible_to_user"] is True, with_proof - assert with_proof["execution_policy"]["user_can_interrupt_or_take_over"] is True, with_proof - - with tempfile.TemporaryDirectory(prefix="loopx-codex-cli-visible-local-driver-") as tmp: - tmp_path = Path(tmp) - help_fixture = tmp_path / "codex-remote-help.json" - help_fixture.write_text(json.dumps({"command_outputs": REMOTE_RESUME_HELP_FIXTURE})) - proof_fixture = tmp_path / "visible-proof.json" - proof_fixture.write_text(json.dumps(VISIBLE_PROOF_FIXTURE)) - idle_fixture = tmp_path / "runtime-idle.json" - idle_fixture.write_text(json.dumps(RUNTIME_IDLE_FIXTURE)) - missing_registry = tmp_path / "missing-registry.json" - runtime_root = tmp_path / "runtime" - - cli_json = json.loads( - run_cli( - "--registry", - str(missing_registry), - "--runtime-root", - str(runtime_root), - "--format", - "json", - "codex-cli-visible-local-driver-pilot", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - ) - ) - assert_pilot_boundary(cli_json) - assert cli_json["loop_decision"] == "visible_loop_blocker_writeback_ready", cli_json - - cli_proof_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-visible-local-driver-pilot", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - "--proof-fixture", - str(proof_fixture), - ) - ) - assert_pilot_boundary(cli_proof_json) - assert cli_proof_json["loop_decision"] == "runtime_idle_detector_required", cli_proof_json - - cli_proof_idle_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-visible-local-driver-pilot", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - "--proof-fixture", - str(proof_fixture), - "--idle-fixture", - str(idle_fixture), - ) - ) - assert_pilot_boundary(cli_proof_idle_json) - assert cli_proof_idle_json["loop_decision"] == "visible_candidate_ready_for_guarded_execution", cli_proof_idle_json - assert cli_proof_idle_json["runtime_idle_detector"]["approved"] is True, cli_proof_idle_json - - cli_markdown = run_cli( - "codex-cli-visible-local-driver-pilot", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(help_fixture), - ) - assert "# Codex CLI Visible Local Driver Pilot" in cli_markdown, cli_markdown - assert "loop_decision: `visible_loop_blocker_writeback_ready`" in cli_markdown, cli_markdown - assert "## Runtime Idle Detector" in cli_markdown, cli_markdown - assert "reads_raw_transcripts: `False`" in cli_markdown, cli_markdown - assert "user_can_interrupt_or_take_over: `True`" in cli_markdown, cli_markdown - - print("codex-cli-visible-local-driver-pilot-smoke ok") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/examples/codex-cli-visible-session-proof-smoke.py b/examples/codex-cli-visible-session-proof-smoke.py deleted file mode 100644 index cc8097c01c..0000000000 --- a/examples/codex-cli-visible-session-proof-smoke.py +++ /dev/null @@ -1,169 +0,0 @@ -#!/usr/bin/env python3 -"""Smoke-test the Codex CLI visible session proof contract.""" - -from __future__ import annotations - -import json -import subprocess -import sys -import tempfile -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -if str(REPO_ROOT) not in sys.path: - sys.path.insert(0, str(REPO_ROOT)) - -from loopx.codex_cli_probe import build_codex_cli_visible_session_proof # noqa: E402 - - -PROJECT = Path("/tmp/public-codex-cli-project") -GOAL_ID = "public-codex-cli-goal" -AGENT_ID = "codex-side-bypass" - - -PASSING_PROOF = { - "observed_surface": "visible_resume_prompt", - "user_opt_in": True, - "quota_guard": {"passed": True}, - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": { - "visible_to_user": True, - "prompt_public_safe": True, - }, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - "spends_quota_before_writeback": False, - }, - "writeback": {"compact_evidence_planned": True}, -} - - -FAILING_PROOF = { - **PASSING_PROOF, - "observed_surface": "headless_exec", - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": False, - "checked_before_prompt": True, - }, - "boundary": { - **PASSING_PROOF["boundary"], - "reads_session_files": True, - }, -} - - -def run_cli(*extra_args: str) -> str: - result = subprocess.run( - [sys.executable, "-m", "loopx.cli", *extra_args], - cwd=REPO_ROOT, - check=True, - capture_output=True, - text=True, - ) - return result.stdout - - -def assert_common_boundary(payload: dict[str, object]) -> None: - assert payload["schema_version"] == "codex_cli_visible_session_proof_v0", payload - assert payload["project"] == str(PROJECT), payload - assert payload["goal_id"] == GOAL_ID, payload - assert payload["agent_id"] == AGENT_ID, payload - boundary = payload["boundary"] - assert boundary["fixture_only"] is True, payload - assert boundary["runs_codex"] is False, payload - assert boundary["reads_raw_transcripts"] is False, payload - assert boundary["reads_session_files"] is False, payload - assert boundary["mutates_codex_session"] is False, payload - assert boundary["spends_loopx_quota"] is False, payload - - -def build(proof: dict[str, object] | None) -> dict[str, object]: - return build_codex_cli_visible_session_proof( - project=PROJECT, - goal_id=GOAL_ID, - agent_id=AGENT_ID, - cli_bin="loopx", - proof_payload=proof, - ) - - -def main() -> int: - missing = build(None) - assert missing["ok"] is False, missing - assert_common_boundary(missing) - assert missing["decision"] == "proof_fixture_required", missing - assert missing["approved_for_same_session_automation"] is False, missing - assert "required_fixture_shape" in missing, missing - - passing = build(PASSING_PROOF) - assert passing["ok"] is True, passing - assert_common_boundary(passing) - assert passing["decision"] == "visible_session_proof_passed", passing - assert passing["approved_for_same_session_automation"] is True, passing - assert passing["failures"] == [], passing - assert all(check["passed"] for check in passing["checks"]), passing - - failing = build(FAILING_PROOF) - assert failing["ok"] is True, failing - assert_common_boundary(failing) - assert failing["decision"] == "visible_session_proof_incomplete", failing - assert failing["approved_for_same_session_automation"] is False, failing - assert "idle_no_running_turn" in failing["failures"], failing - assert "no_session_files_read" in failing["failures"], failing - assert "unsupported_observed_surface" in failing["failures"], failing - - with tempfile.TemporaryDirectory(prefix="loopx-codex-cli-visible-proof-") as tmp: - fixture = Path(tmp) / "visible-proof.json" - fixture.write_text(json.dumps(PASSING_PROOF)) - cli_json = json.loads( - run_cli( - "--format", - "json", - "codex-cli-visible-session-proof", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--proof-fixture", - str(fixture), - ) - ) - assert cli_json["approved_for_same_session_automation"] is True, cli_json - assert cli_json["observed_surface"] == "visible_resume_prompt", cli_json - - cli_markdown = run_cli( - "codex-cli-visible-session-proof", - "--project", - str(PROJECT), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--proof-fixture", - str(fixture), - ) - assert "# Codex CLI Visible Session Proof" in cli_markdown, cli_markdown - assert "approved_for_same_session_automation: `True`" in cli_markdown, cli_markdown - assert "- [x] visible_to_user" in cli_markdown, cli_markdown - - print("codex-cli-visible-session-proof-smoke ok") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/examples/fixtures/codex-cli-visible-proof/codex-same-tui-help.public.json b/examples/fixtures/codex-cli-visible-proof/codex-same-tui-help.public.json deleted file mode 100644 index da63099084..0000000000 --- a/examples/fixtures/codex-cli-visible-proof/codex-same-tui-help.public.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "command_outputs": { - "root": "Usage: codex [OPTIONS] [PROMPT]\n\nCommands:\n exec\n resume\n attach-session Send prompt to session after checking the idle TUI\n", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": "Usage: codex resume [SESSION_ID]" - } -} diff --git a/examples/fixtures/codex-cli-visible-proof/codex-visible-resume-help.public.json b/examples/fixtures/codex-cli-visible-proof/codex-visible-resume-help.public.json deleted file mode 100644 index 8784e9fd39..0000000000 --- a/examples/fixtures/codex-cli-visible-proof/codex-visible-resume-help.public.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "command_outputs": { - "root": "Usage: codex [OPTIONS] [PROMPT]\n\nCommands:\n exec\n remote-control Manage the app-server daemon with remote control enabled\n resume Resume a previous interactive session\n\nOptions:\n --remote Connect the TUI to a remote app server endpoint\n", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": "Usage: codex resume [OPTIONS] [SESSION_ID] [PROMPT]" - } -} diff --git a/examples/fixtures/codex-cli-visible-proof/runtime-idle-same-tui.public.json b/examples/fixtures/codex-cli-visible-proof/runtime-idle-same-tui.public.json deleted file mode 100644 index fdc6db1628..0000000000 --- a/examples/fixtures/codex-cli-visible-proof/runtime-idle-same-tui.public.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "observed_surface": "same_tui_visible_attach", - "idle_guard": { - "no_active_human_typing": true, - "no_running_turn": true, - "checked_before_prompt": true - }, - "turn_visibility": { - "visible_to_user": true - }, - "interruptibility": { - "user_can_interrupt": true, - "manual_takeover_available": true - }, - "boundary": { - "reads_raw_transcripts": false, - "reads_session_files": false, - "reads_stdout_stderr": false, - "reads_credentials": false, - "mutates_hidden_session_state": false - }, - "proof_result": "fresh idle guard passed for a same-TUI demo fixture" -} diff --git a/examples/fixtures/codex-cli-visible-proof/runtime-idle-visible-resume.public.json b/examples/fixtures/codex-cli-visible-proof/runtime-idle-visible-resume.public.json deleted file mode 100644 index 6bf03bc21e..0000000000 --- a/examples/fixtures/codex-cli-visible-proof/runtime-idle-visible-resume.public.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "observed_surface": "visible_resume_prompt", - "idle_guard": { - "no_active_human_typing": true, - "no_running_turn": true, - "checked_before_prompt": true - }, - "turn_visibility": { - "visible_to_user": true - }, - "interruptibility": { - "user_can_interrupt": true, - "manual_takeover_available": true - }, - "boundary": { - "reads_raw_transcripts": false, - "reads_session_files": false, - "reads_stdout_stderr": false, - "reads_credentials": false, - "mutates_hidden_session_state": false - }, - "proof_result": "fresh idle guard passed for a visible resume proof prompt" -} diff --git a/examples/fixtures/codex-cli-visible-proof/same-tui-proof.public.json b/examples/fixtures/codex-cli-visible-proof/same-tui-proof.public.json deleted file mode 100644 index bdb232917f..0000000000 --- a/examples/fixtures/codex-cli-visible-proof/same-tui-proof.public.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "observed_surface": "same_tui_visible_attach", - "user_opt_in": true, - "quota_guard": { - "passed": true - }, - "idle_guard": { - "no_active_human_typing": true, - "no_running_turn": true, - "checked_before_prompt": true - }, - "turn_visibility": { - "visible_to_user": true, - "prompt_public_safe": true - }, - "interruptibility": { - "user_can_interrupt": true, - "manual_takeover_available": true - }, - "boundary": { - "reads_raw_transcripts": false, - "reads_session_files": false, - "reads_credentials": false, - "mutates_hidden_session_state": false, - "spends_quota_before_writeback": false - }, - "writeback": { - "compact_evidence_planned": true - }, - "proof_result": "same-TUI visible attach proof passed for a public demo fixture" -} diff --git a/examples/fixtures/codex-cli-visible-proof/visible-resume-proof.public.json b/examples/fixtures/codex-cli-visible-proof/visible-resume-proof.public.json deleted file mode 100644 index 7eb97140d4..0000000000 --- a/examples/fixtures/codex-cli-visible-proof/visible-resume-proof.public.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "observed_surface": "visible_resume_prompt", - "user_opt_in": true, - "quota_guard": { - "passed": true - }, - "idle_guard": { - "no_active_human_typing": true, - "no_running_turn": true, - "checked_before_prompt": true - }, - "turn_visibility": { - "visible_to_user": true, - "prompt_public_safe": true - }, - "interruptibility": { - "user_can_interrupt": true, - "manual_takeover_available": true - }, - "boundary": { - "reads_raw_transcripts": false, - "reads_session_files": false, - "reads_credentials": false, - "mutates_hidden_session_state": false, - "spends_quota_before_writeback": false - }, - "writeback": { - "compact_evidence_planned": true - }, - "proof_result": "visible spike proof only; same-TUI attach not proven" -} diff --git a/examples/release/codex-cli-no-clone-release-verification-smoke.py b/examples/release/codex-cli-no-clone-release-verification-smoke.py index 20671572b6..80ff455646 100644 --- a/examples/release/codex-cli-no-clone-release-verification-smoke.py +++ b/examples/release/codex-cli-no-clone-release-verification-smoke.py @@ -24,8 +24,6 @@ AGENT_ID = "codex-side-bypass" FIRST_RUN_COMMANDS = ( "codex-cli-bootstrap-message", - "codex-cli-tui-bootstrap-smoke-bundle", - "codex-cli-visible-attach-acceptance", ) @@ -85,8 +83,6 @@ def assert_docs() -> None: "Codex CLI No-Clone Release Verification", "scripts/install-from-github.sh", "codex-cli-bootstrap-message", - "codex-cli-tui-bootstrap-smoke-bundle", - "codex-cli-visible-attach-acceptance", "Current archive route: **qualified as the recovery fallback, with one boundary**.", "network access to GitHub archive endpoints", "same-TUI automation is not the default path", @@ -138,8 +134,6 @@ def assert_installed_release( assert (release_dir / "docs" / "product" / "runtimes" / "codex-cli" / "codex-cli-first-run-rehearsal.md").exists() assert (release_dir / "docs" / "product" / "runtimes" / "codex-cli" / "codex-cli-no-clone-release-verification.md").exists() - fixture_dir = release_dir / "examples" / "fixtures" / "codex-cli-visible-proof" - assert fixture_dir.exists(), fixture_dir message = run( [ @@ -176,61 +170,6 @@ def assert_installed_release( assert "settlement_plan.ordered_steps" in normalized_message, message assert "raw Codex transcripts" in normalized_message, message - bundle = json.loads( - run( - [ - str(installed), - "--format", - "json", - "codex-cli-tui-bootstrap-smoke-bundle", - "--project", - str(fresh_repo), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - ], - env=runtime_env, - cwd=fresh_repo, - ).stdout - ) - assert bundle["schema_version"] == "codex_cli_tui_bootstrap_smoke_bundle_v0", bundle - assert bundle["boundary"]["runs_codex"] is False, bundle - assert bundle["boundary"]["requires_loopx_repo_clone"] is False, bundle - assert bundle["boundary"]["spends_loopx_quota"] is False, bundle - assert str(fresh_repo) in bundle["message_only_command"], bundle - - acceptance = json.loads( - run( - [ - str(installed), - "--format", - "json", - "codex-cli-visible-attach-acceptance", - "--project", - str(fresh_repo), - "--goal-id", - GOAL_ID, - "--agent-id", - AGENT_ID, - "--fixture", - str(fixture_dir / "codex-visible-resume-help.public.json"), - "--proof-fixture", - str(fixture_dir / "visible-resume-proof.public.json"), - "--idle-fixture", - str(fixture_dir / "runtime-idle-visible-resume.public.json"), - ], - env=runtime_env, - cwd=fresh_repo, - ).stdout - ) - assert acceptance["decision"] == "visible_surface_spike_passed_not_same_tui", acceptance - assert acceptance["accepted_for_visible_later_turn"] is True, acceptance - assert acceptance["accepted_for_same_tui_automation"] is False, acceptance - assert acceptance["boundary"]["runs_codex"] is False, acceptance - assert acceptance["boundary"]["reads_raw_transcripts"] is False, acceptance - assert acceptance["boundary"]["reads_session_files"] is False, acceptance - assert not codex_called_marker.exists(), codex_called_marker diff --git a/loopx/canary/module_metric_baseline.json b/loopx/canary/module_metric_baseline.json index a2e82b0bac..e6a6fe67b9 100644 --- a/loopx/canary/module_metric_baseline.json +++ b/loopx/canary/module_metric_baseline.json @@ -49,10 +49,6 @@ "dict_any_count": 0, "lines": 2058 }, - "loopx/codex_cli_probe.py": { - "any_count": 37, - "dict_any_count": 0 - }, "loopx/control_plane/agents/agent_scope.py": { "any_count": 107, "dict_any_count": 0 diff --git a/loopx/canary/planner.py b/loopx/canary/planner.py index 29af2a36eb..2f904be580 100644 --- a/loopx/canary/planner.py +++ b/loopx/canary/planner.py @@ -1000,9 +1000,9 @@ "reason": "guards Codex App heartbeat identity, scheduler hints, and no-spend cadence behavior", }, { - "command": "python3 examples/codex-cli-tui-bootstrap-smoke-bundle-smoke.py", + "command": "python3 examples/codex-cli-bootstrap-message-smoke.py", "tier": "default", - "reason": "checks Codex CLI TUI bootstrap bundle and scoped LoopX command contract", + "reason": "checks Codex CLI TUI bootstrap message and scoped LoopX command contract", }, { "command": "python3 examples/claude-goalmode-lifecycle-smoke.py", diff --git a/loopx/cli_commands/__init__.py b/loopx/cli_commands/__init__.py index 72ae204ec6..769bf2372f 100644 --- a/loopx/cli_commands/__init__.py +++ b/loopx/cli_commands/__init__.py @@ -95,42 +95,11 @@ def _load_exports() -> None: ) from .starter_bootstrap import ( handle_codex_cli_bootstrap_message_command, - handle_codex_cli_exec_handoff_command, - handle_codex_cli_tui_bootstrap_smoke_bundle_command, handle_loopx_bootstrap_command_pack_command, handle_new_project_prompt_command, handle_starter_bootstrap_command, ) from .starter_bootstrap_registration import register_starter_bootstrap_commands - from .starter_scheduler import ( - handle_codex_cli_local_scheduler_exec_command, - handle_codex_cli_local_scheduler_tick_command, - handle_starter_scheduler_command, - register_starter_scheduler_commands, - ) - from .starter_session_runtime import ( - handle_codex_cli_runtime_idle_detector_command, - handle_codex_cli_session_probe_command, - handle_codex_cli_visible_session_proof_command, - handle_starter_session_runtime_command, - register_starter_session_runtime_commands, - ) - from .starter_visible_driver import ( - handle_codex_cli_local_driver_plan_command, - handle_codex_cli_visible_driver_plan_command, - handle_codex_cli_visible_driver_run_command, - handle_starter_visible_driver_command, - register_starter_visible_driver_commands, - ) - from .starter_visible_pilot import ( - handle_codex_cli_bounded_visible_pilot_adapter_command, - handle_codex_cli_one_message_loop_pilot_command, - handle_codex_cli_visible_attach_acceptance_command, - handle_codex_cli_visible_first_response_capture_plan_command, - handle_codex_cli_visible_local_driver_pilot_command, - handle_starter_visible_pilot_command, - register_starter_visible_pilot_commands, - ) from .summary_all import handle_summary_all_command, register_summary_all_command from .status import ( handle_check_command, @@ -175,23 +144,8 @@ def _load_exports() -> None: "handle_capability_command", "handle_extension_command", "handle_check_command", - "handle_codex_cli_bounded_visible_pilot_adapter_command", "handle_codex_cli_bootstrap_message_command", - "handle_codex_cli_exec_handoff_command", "handle_loopx_bootstrap_command_pack_command", - "handle_codex_cli_visible_first_response_capture_plan_command", - "handle_codex_cli_local_driver_plan_command", - "handle_codex_cli_local_scheduler_exec_command", - "handle_codex_cli_local_scheduler_tick_command", - "handle_codex_cli_one_message_loop_pilot_command", - "handle_codex_cli_runtime_idle_detector_command", - "handle_codex_cli_session_probe_command", - "handle_codex_cli_tui_bootstrap_smoke_bundle_command", - "handle_codex_cli_visible_attach_acceptance_command", - "handle_codex_cli_visible_local_driver_pilot_command", - "handle_codex_cli_visible_driver_run_command", - "handle_codex_cli_visible_driver_plan_command", - "handle_codex_cli_visible_session_proof_command", "handle_diagnose_command", "handle_demo_command", "handle_doctor_command", @@ -223,10 +177,6 @@ def _load_exports() -> None: "handle_status_command", "handle_starter_command", "handle_starter_bootstrap_command", - "handle_starter_scheduler_command", - "handle_starter_session_runtime_command", - "handle_starter_visible_driver_command", - "handle_starter_visible_pilot_command", "handle_summary_all_command", "handle_support_control_command", "handle_authority_shadow_command", @@ -272,10 +222,6 @@ def _load_exports() -> None: "register_slash_commands_command", "register_starter_commands", "register_starter_bootstrap_commands", - "register_starter_scheduler_commands", - "register_starter_session_runtime_commands", - "register_starter_visible_driver_commands", - "register_starter_visible_pilot_commands", "register_summary_all_command", "register_status_commands", "register_support_control_commands", diff --git a/loopx/cli_commands/starter.py b/loopx/cli_commands/starter.py index 8b3d1844d0..095e16ad03 100644 --- a/loopx/cli_commands/starter.py +++ b/loopx/cli_commands/starter.py @@ -24,18 +24,6 @@ ) from .starter_bootstrap import handle_starter_bootstrap_command from .starter_bootstrap_registration import register_starter_bootstrap_commands -from .starter_scheduler import ( - handle_starter_scheduler_command, - register_starter_scheduler_commands, -) -from .starter_session_runtime import ( - handle_starter_session_runtime_command, - register_starter_session_runtime_commands, -) -from .starter_visible_driver import ( - handle_starter_visible_driver_command, - register_starter_visible_driver_commands, -) PrintPayload = Callable[ @@ -46,9 +34,6 @@ def register_starter_commands(subparsers: argparse._SubParsersAction) -> None: register_starter_bootstrap_commands(subparsers) - register_starter_visible_driver_commands(subparsers) - register_starter_session_runtime_commands(subparsers) - register_starter_scheduler_commands(subparsers) demo_parser = subparsers.add_parser( "demo", @@ -161,15 +146,6 @@ def handle_starter_command( bootstrap_result = handle_starter_bootstrap_command(args, print_payload) if bootstrap_result is not None: return bootstrap_result - visible_driver_result = handle_starter_visible_driver_command(args, print_payload) - if visible_driver_result is not None: - return visible_driver_result - session_runtime_result = handle_starter_session_runtime_command(args, print_payload) - if session_runtime_result is not None: - return session_runtime_result - scheduler_result = handle_starter_scheduler_command(args, print_payload) - if scheduler_result is not None: - return scheduler_result if str(getattr(args, "command", "")) == "demo": return handle_demo_command(args, print_payload) return None diff --git a/loopx/cli_commands/starter_bootstrap.py b/loopx/cli_commands/starter_bootstrap.py index ae25026c21..3d21efbca3 100644 --- a/loopx/cli_commands/starter_bootstrap.py +++ b/loopx/cli_commands/starter_bootstrap.py @@ -20,12 +20,8 @@ ) from ..project_prompt import ( build_codex_cli_bootstrap_message, - build_codex_cli_exec_handoff, - build_codex_cli_tui_bootstrap_smoke_bundle, build_new_project_prompt, render_codex_cli_bootstrap_message_markdown, - render_codex_cli_exec_handoff_markdown, - render_codex_cli_tui_bootstrap_smoke_bundle_markdown, render_new_project_prompt_markdown, ) from ._host_thread import current_host_thread_id @@ -134,35 +130,6 @@ def handle_codex_cli_bootstrap_message_command( return 0 -def handle_codex_cli_tui_bootstrap_smoke_bundle_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int: - payload = build_codex_cli_tui_bootstrap_smoke_bundle( - project=Path(args.project), - goal_id=args.goal_id, - agent_id=args.agent_id, - cli_bin=args.cli_bin, - ) - print_payload(payload, args.format, render_codex_cli_tui_bootstrap_smoke_bundle_markdown) - return 0 - - -def handle_codex_cli_exec_handoff_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int: - payload = build_codex_cli_exec_handoff( - project=Path(args.project), - goal_id=args.goal_id, - agent_id=args.agent_id, - cli_bin=args.cli_bin, - codex_bin=args.codex_bin, - ) - print_payload(payload, args.format, render_codex_cli_exec_handoff_markdown) - return 0 if payload.get("ok") else 1 - - def handle_starter_bootstrap_command( args: argparse.Namespace, print_payload: PrintPayload, @@ -173,8 +140,6 @@ def handle_starter_bootstrap_command( "start-goal": handle_start_goal_command, "new-project-prompt": handle_new_project_prompt_command, "codex-cli-bootstrap-message": handle_codex_cli_bootstrap_message_command, - "codex-cli-tui-bootstrap-smoke-bundle": handle_codex_cli_tui_bootstrap_smoke_bundle_command, - "codex-cli-exec-handoff": handle_codex_cli_exec_handoff_command, } handler = handlers.get(str(getattr(args, "command", ""))) if handler is None: diff --git a/loopx/cli_commands/starter_bootstrap_registration.py b/loopx/cli_commands/starter_bootstrap_registration.py index aa3f5f7c6c..e40e04bcad 100644 --- a/loopx/cli_commands/starter_bootstrap_registration.py +++ b/loopx/cli_commands/starter_bootstrap_registration.py @@ -5,7 +5,6 @@ from ..bootstrap_command_pack import ( START_GOAL_HOST_SURFACES, ) -from ..codex_cli_probe import DEFAULT_CODEX_BIN from ..project_prompt import ( DEFAULT_HANDOFF_ADAPTER_KIND, DEFAULT_HANDOFF_ADAPTER_STATUS, @@ -152,47 +151,3 @@ def register_starter_bootstrap_commands(subparsers: argparse._SubParsersAction) action="store_true", help="Print only the Codex CLI TUI paste message, without the Markdown review packet.", ) - - codex_cli_tui_bootstrap_smoke_parser = subparsers.add_parser( - "codex-cli-tui-bootstrap-smoke-bundle", - help="Generate a transcript-free first-run smoke packet for the Codex CLI TUI bootstrap path.", - ) - codex_cli_tui_bootstrap_smoke_parser.add_argument( - "--project", - default=".", - help="Project directory to model as the fresh repo.", - ) - codex_cli_tui_bootstrap_smoke_parser.add_argument( - "--goal-id", - help="Goal id. Defaults to -goal.", - ) - codex_cli_tui_bootstrap_smoke_parser.add_argument( - "--agent-id", - help="Registered LoopX agent id to include in quota/claim instructions.", - ) - codex_cli_tui_bootstrap_smoke_parser.add_argument( - "--cli-bin", - default="loopx", - help="LoopX CLI binary name embedded in generated commands.", - ) - - codex_cli_exec_parser = subparsers.add_parser( - "codex-cli-exec-handoff", - help="Show the disabled headless handoff boundary and the TUI message-only bootstrap command.", - ) - codex_cli_exec_parser.add_argument("--project", default=".", help="Project directory to start from.") - codex_cli_exec_parser.add_argument("--goal-id", help="Goal id. Defaults to -goal.") - codex_cli_exec_parser.add_argument( - "--agent-id", - help="Registered LoopX agent id to include in quota/claim instructions.", - ) - codex_cli_exec_parser.add_argument( - "--cli-bin", - default="loopx", - help="LoopX CLI binary name embedded in generated commands.", - ) - codex_cli_exec_parser.add_argument( - "--codex-bin", - default=DEFAULT_CODEX_BIN, - help="Codex CLI executable name embedded in the generated handoff command.", - ) diff --git a/loopx/cli_commands/starter_runtime_idle.py b/loopx/cli_commands/starter_runtime_idle.py deleted file mode 100644 index 7200661ca1..0000000000 --- a/loopx/cli_commands/starter_runtime_idle.py +++ /dev/null @@ -1,107 +0,0 @@ -from __future__ import annotations - -import argparse -from pathlib import Path - -from ..codex_cli_probe import ( - DEFAULT_MIN_HUMAN_INPUT_IDLE_SECONDS, - build_codex_cli_runtime_idle_observation_payload, - load_codex_cli_runtime_idle_fixture, - probe_human_input_idle_seconds, -) - - -def _add_runtime_idle_observation_arguments( - parser: argparse.ArgumentParser, - *, - include_idle_fixture: bool = True, -) -> None: - if include_idle_fixture: - parser.add_argument( - "--idle-fixture", - help="Optional public-safe runtime idle fixture. Without it, later visible turn candidates remain blocked.", - ) - parser.add_argument( - "--observe-local-runtime", - action="store_true", - help="Build the idle packet from public-safe local observation fields instead of a JSON fixture.", - ) - parser.add_argument( - "--observed-surface", - default="codex_cli_tui_visible_window", - choices=[ - "codex_cli_tui_visible_window", - "remote_control_visible_prompt", - "same_tui_visible_attach", - "visible_resume_prompt", - ], - help="Visible Codex CLI surface observed by the local runtime check.", - ) - parser.add_argument( - "--turn-state", - choices=["idle", "running", "unknown"], - default="unknown", - help="Public-safe visible turn state. Unknown or running fails closed.", - ) - parser.add_argument( - "--human-input-idle-seconds", - type=float, - help="Public-safe observed seconds since last human input. Useful for tests or external sensors.", - ) - parser.add_argument( - "--probe-human-input-idle", - action="store_true", - help="Probe the local platform for coarse human-input idle seconds when supported.", - ) - parser.add_argument( - "--min-human-input-idle-seconds", - type=float, - default=DEFAULT_MIN_HUMAN_INPUT_IDLE_SECONDS, - help="Minimum idle seconds required to consider human typing inactive.", - ) - parser.add_argument( - "--checked-before-prompt", - action="store_true", - help="Confirm this idle check ran before any later visible prompt.", - ) - parser.add_argument( - "--visible-to-user", - action="store_true", - help="Confirm the target turn remains visible to the user.", - ) - parser.add_argument( - "--user-can-interrupt", - action="store_true", - help="Confirm the user can interrupt the target turn.", - ) - parser.add_argument( - "--manual-takeover-available", - action="store_true", - help="Confirm manual takeover remains available.", - ) - - -def _load_codex_cli_runtime_idle_payload(args: argparse.Namespace) -> dict[str, object] | None: - if args.idle_fixture and args.observe_local_runtime: - raise ValueError("Use either --idle-fixture or --observe-local-runtime, not both.") - if args.idle_fixture: - return load_codex_cli_runtime_idle_fixture(Path(args.idle_fixture).expanduser()) - if not args.observe_local_runtime: - return None - probe_result = None - human_input_idle_seconds = args.human_input_idle_seconds - if args.probe_human_input_idle: - probe_result = probe_human_input_idle_seconds() - if probe_result.get("ok") is True: - human_input_idle_seconds = float(probe_result["human_input_idle_seconds"]) - return build_codex_cli_runtime_idle_observation_payload( - observed_surface=args.observed_surface, - turn_state=args.turn_state, - human_input_idle_seconds=human_input_idle_seconds, - min_human_input_idle_seconds=args.min_human_input_idle_seconds, - checked_before_prompt=bool(args.checked_before_prompt), - visible_to_user=bool(args.visible_to_user), - user_can_interrupt=bool(args.user_can_interrupt), - manual_takeover_available=bool(args.manual_takeover_available), - probe_result=probe_result, - ) diff --git a/loopx/cli_commands/starter_scheduler.py b/loopx/cli_commands/starter_scheduler.py deleted file mode 100644 index d1396b2295..0000000000 --- a/loopx/cli_commands/starter_scheduler.py +++ /dev/null @@ -1,207 +0,0 @@ -from __future__ import annotations - -import argparse -import json -from collections.abc import Callable -from pathlib import Path - -from ..codex_cli_probe import ( - DEFAULT_CODEX_BIN, - DEFAULT_EXECUTOR_TIMEOUT_SECONDS, - DEFAULT_TIMEOUT_SECONDS, - load_codex_cli_visible_session_proof_fixture, - render_codex_cli_local_scheduler_executor_markdown, - render_codex_cli_local_scheduler_tick_markdown, - run_codex_cli_session_probe, -) -from ..codex_cli_scheduler import ( - build_codex_cli_local_scheduler_executor, - build_codex_cli_local_scheduler_tick, -) -from .starter_runtime_idle import ( - _add_runtime_idle_observation_arguments, - _load_codex_cli_runtime_idle_payload, -) - - -PrintPayload = Callable[ - [dict[str, object], str, Callable[[dict[str, object]], str]], - None, -] - - -def _add_scheduler_common_arguments(parser: argparse.ArgumentParser) -> None: - parser.add_argument("--project", default=".", help="Project directory to start from.") - parser.add_argument("--goal-id", help="Goal id. Defaults to -goal.") - parser.add_argument( - "--agent-id", - help="Registered LoopX agent id to include in quota/claim instructions.", - ) - parser.add_argument( - "--cli-bin", - default="loopx", - help="LoopX CLI binary name embedded in generated commands.", - ) - parser.add_argument( - "--codex-bin", - default=DEFAULT_CODEX_BIN, - help="Codex CLI executable to probe for visible-session capabilities.", - ) - parser.add_argument( - "--timeout-seconds", - type=float, - default=DEFAULT_TIMEOUT_SECONDS, - help="Per-command timeout for help-only Codex CLI probes.", - ) - parser.add_argument( - "--fixture", - help="Public-safe JSON fixture with command_outputs, used instead of invoking Codex CLI.", - ) - parser.add_argument( - "--quota-fixture", - help="Optional public-safe quota should-run JSON fixture with scheduler_hint.", - ) - parser.add_argument( - "--proof-fixture", - help="Optional public-safe visible-session proof fixture. Without it, same-session automation remains blocked.", - ) - _add_runtime_idle_observation_arguments(parser) - parser.add_argument( - "--allow-headless-fallback", - action="store_true", - help="Deprecated and ignored; headless codex exec is disabled for this default /goal path.", - ) - - -def register_starter_scheduler_commands(subparsers: argparse._SubParsersAction) -> None: - codex_cli_local_scheduler_tick_parser = subparsers.add_parser( - "codex-cli-local-scheduler-tick", - help="Build a no-execution local scheduler tick around codex-cli-visible-driver-run.", - ) - _add_scheduler_common_arguments(codex_cli_local_scheduler_tick_parser) - - codex_cli_local_scheduler_exec_parser = subparsers.add_parser( - "codex-cli-local-scheduler-exec", - help="Explicit opt-in executor wrapper for codex-cli-local-scheduler-tick results.", - ) - _add_scheduler_common_arguments(codex_cli_local_scheduler_exec_parser) - codex_cli_local_scheduler_exec_parser.add_argument( - "--executor-timeout-seconds", - type=float, - default=DEFAULT_EXECUTOR_TIMEOUT_SECONDS, - help="Timeout for the explicitly executed scheduler result command.", - ) - codex_cli_local_scheduler_exec_parser.add_argument( - "--guard-checked", - action="store_true", - help="Confirm a fresh quota/user-gate guard was checked before executing a candidate or blocker writeback.", - ) - codex_cli_local_scheduler_exec_parser.add_argument( - "--execute-candidate", - action="store_true", - help="Execute the scheduler candidate command after guard and prefix checks.", - ) - codex_cli_local_scheduler_exec_parser.add_argument( - "--execute-blocker-writeback", - action="store_true", - help="Execute the precise LoopX blocker writeback command after a fresh guard check.", - ) - codex_cli_local_scheduler_exec_parser.add_argument( - "--candidate-command-prefix", - action="append", - default=[], - help="Allowed command prefix for --execute-candidate. Repeatable; required before candidate execution.", - ) - - -def handle_codex_cli_local_scheduler_tick_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int: - probe_payload = run_codex_cli_session_probe( - codex_bin=args.codex_bin, - timeout_seconds=args.timeout_seconds, - fixture=Path(args.fixture).expanduser() if args.fixture else None, - ) - proof_payload = ( - load_codex_cli_visible_session_proof_fixture(Path(args.proof_fixture).expanduser()) - if args.proof_fixture - else None - ) - idle_payload = _load_codex_cli_runtime_idle_payload(args) - quota_payload = ( - json.loads(Path(args.quota_fixture).expanduser().read_text(encoding="utf-8")) - if args.quota_fixture - else None - ) - payload = build_codex_cli_local_scheduler_tick( - project=Path(args.project), - goal_id=args.goal_id, - agent_id=args.agent_id, - cli_bin=args.cli_bin, - codex_bin=args.codex_bin, - probe_payload=probe_payload, - quota_payload=quota_payload, - proof_payload=proof_payload, - idle_payload=idle_payload, - allow_headless_fallback=bool(args.allow_headless_fallback), - ) - print_payload(payload, args.format, render_codex_cli_local_scheduler_tick_markdown) - return 0 if payload.get("ok") else 1 - - -def handle_codex_cli_local_scheduler_exec_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int: - probe_payload = run_codex_cli_session_probe( - codex_bin=args.codex_bin, - timeout_seconds=args.timeout_seconds, - fixture=Path(args.fixture).expanduser() if args.fixture else None, - ) - proof_payload = ( - load_codex_cli_visible_session_proof_fixture(Path(args.proof_fixture).expanduser()) - if args.proof_fixture - else None - ) - idle_payload = _load_codex_cli_runtime_idle_payload(args) - quota_payload = ( - json.loads(Path(args.quota_fixture).expanduser().read_text(encoding="utf-8")) - if args.quota_fixture - else None - ) - payload = build_codex_cli_local_scheduler_executor( - project=Path(args.project), - goal_id=args.goal_id, - agent_id=args.agent_id, - cli_bin=args.cli_bin, - codex_bin=args.codex_bin, - probe_payload=probe_payload, - quota_payload=quota_payload, - proof_payload=proof_payload, - idle_payload=idle_payload, - allow_headless_fallback=bool(args.allow_headless_fallback), - execute_candidate=bool(args.execute_candidate), - execute_blocker_writeback=bool(args.execute_blocker_writeback), - guard_checked=bool(args.guard_checked), - candidate_command_prefixes=list(args.candidate_command_prefix or []), - executor_timeout_seconds=args.executor_timeout_seconds, - ) - print_payload(payload, args.format, render_codex_cli_local_scheduler_executor_markdown) - return 0 if payload.get("ok") else 1 - - -_SCHEDULER_HANDLERS: dict[str, Callable[[argparse.Namespace, PrintPayload], int]] = { - "codex-cli-local-scheduler-tick": handle_codex_cli_local_scheduler_tick_command, - "codex-cli-local-scheduler-exec": handle_codex_cli_local_scheduler_exec_command, -} - - -def handle_starter_scheduler_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int | None: - handler = _SCHEDULER_HANDLERS.get(str(getattr(args, "command", ""))) - if handler is None: - return None - return handler(args, print_payload) diff --git a/loopx/cli_commands/starter_session_runtime.py b/loopx/cli_commands/starter_session_runtime.py deleted file mode 100644 index d3a03375a7..0000000000 --- a/loopx/cli_commands/starter_session_runtime.py +++ /dev/null @@ -1,152 +0,0 @@ -from __future__ import annotations - -import argparse -from collections.abc import Callable -from pathlib import Path - -from ..codex_cli_probe import ( - DEFAULT_CODEX_BIN, - DEFAULT_TIMEOUT_SECONDS, - build_codex_cli_runtime_idle_detector, - build_codex_cli_visible_session_proof, - load_codex_cli_visible_session_proof_fixture, - render_codex_cli_runtime_idle_detector_markdown, - render_codex_cli_session_probe_markdown, - render_codex_cli_visible_session_proof_markdown, - run_codex_cli_session_probe, -) -from .starter_runtime_idle import ( - _add_runtime_idle_observation_arguments, - _load_codex_cli_runtime_idle_payload, -) - - -PrintPayload = Callable[ - [dict[str, object], str, Callable[[dict[str, object]], str]], - None, -] - - -def register_starter_session_runtime_commands(subparsers: argparse._SubParsersAction) -> None: - codex_cli_probe_parser = subparsers.add_parser( - "codex-cli-session-probe", - help="Probe Codex CLI help surfaces for same-session LoopX automation support.", - ) - codex_cli_probe_parser.add_argument( - "--codex-bin", - default=DEFAULT_CODEX_BIN, - help="Codex CLI executable to probe with help-only commands.", - ) - codex_cli_probe_parser.add_argument( - "--timeout-seconds", - type=float, - default=DEFAULT_TIMEOUT_SECONDS, - help="Per-command timeout for help-only Codex CLI probes.", - ) - codex_cli_probe_parser.add_argument( - "--fixture", - help="Public-safe JSON fixture with command_outputs, used instead of invoking Codex CLI.", - ) - - codex_cli_visible_session_proof_parser = subparsers.add_parser( - "codex-cli-visible-session-proof", - help="Validate a public-safe proof fixture before treating Codex CLI resume or remote-control as same-session automation.", - ) - codex_cli_visible_session_proof_parser.add_argument("--project", default=".", help="Project directory to start from.") - codex_cli_visible_session_proof_parser.add_argument("--goal-id", help="Goal id. Defaults to -goal.") - codex_cli_visible_session_proof_parser.add_argument( - "--agent-id", - help="Registered LoopX agent id to include in the proof packet.", - ) - codex_cli_visible_session_proof_parser.add_argument( - "--cli-bin", - default="loopx", - help="LoopX CLI binary name embedded in proof metadata.", - ) - codex_cli_visible_session_proof_parser.add_argument( - "--proof-fixture", - help="Public-safe JSON proof fixture. When omitted, prints the required fixture shape.", - ) - - codex_cli_runtime_idle_parser = subparsers.add_parser( - "codex-cli-runtime-idle-detector", - help="Validate public-safe runtime idle evidence before a later visible Codex CLI turn.", - ) - codex_cli_runtime_idle_parser.add_argument("--project", default=".", help="Project directory to start from.") - codex_cli_runtime_idle_parser.add_argument("--goal-id", help="Goal id. Defaults to -goal.") - codex_cli_runtime_idle_parser.add_argument( - "--agent-id", - help="Registered LoopX agent id to include in the idle packet.", - ) - codex_cli_runtime_idle_parser.add_argument( - "--cli-bin", - default="loopx", - help="LoopX CLI binary name embedded in idle detector metadata.", - ) - _add_runtime_idle_observation_arguments(codex_cli_runtime_idle_parser) - - -def handle_codex_cli_session_probe_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int: - payload = run_codex_cli_session_probe( - codex_bin=args.codex_bin, - timeout_seconds=args.timeout_seconds, - fixture=Path(args.fixture).expanduser() if args.fixture else None, - ) - print_payload(payload, args.format, render_codex_cli_session_probe_markdown) - return 0 if payload.get("ok") else 1 - - -def handle_codex_cli_visible_session_proof_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int: - proof_payload = ( - load_codex_cli_visible_session_proof_fixture(Path(args.proof_fixture).expanduser()) - if args.proof_fixture - else None - ) - payload = build_codex_cli_visible_session_proof( - project=Path(args.project), - goal_id=args.goal_id, - agent_id=args.agent_id, - cli_bin=args.cli_bin, - proof_payload=proof_payload, - ) - print_payload(payload, args.format, render_codex_cli_visible_session_proof_markdown) - return 0 if payload.get("ok") else 1 - - -def handle_codex_cli_runtime_idle_detector_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int: - idle_payload = _load_codex_cli_runtime_idle_payload(args) - payload = build_codex_cli_runtime_idle_detector( - project=Path(args.project), - goal_id=args.goal_id, - agent_id=args.agent_id, - cli_bin=args.cli_bin, - idle_payload=idle_payload, - ) - print_payload(payload, args.format, render_codex_cli_runtime_idle_detector_markdown) - return 0 if payload.get("ok") else 1 - - -_SESSION_RUNTIME_HANDLERS: dict[str, Callable[[argparse.Namespace, PrintPayload], int]] = { - "codex-cli-session-probe": handle_codex_cli_session_probe_command, - "codex-cli-visible-session-proof": handle_codex_cli_visible_session_proof_command, - "codex-cli-runtime-idle-detector": handle_codex_cli_runtime_idle_detector_command, -} - - -def handle_starter_session_runtime_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int | None: - handler = _SESSION_RUNTIME_HANDLERS.get(str(getattr(args, "command", ""))) - if handler is None: - return None - return handler(args, print_payload) diff --git a/loopx/cli_commands/starter_visible_common.py b/loopx/cli_commands/starter_visible_common.py deleted file mode 100644 index a868d16344..0000000000 --- a/loopx/cli_commands/starter_visible_common.py +++ /dev/null @@ -1,54 +0,0 @@ -from __future__ import annotations - -import argparse - -from ..codex_cli_probe import DEFAULT_CODEX_BIN, DEFAULT_TIMEOUT_SECONDS - - -def _add_project_arguments( - parser: argparse.ArgumentParser, - *, - agent_help: str = "Registered LoopX agent id to include in quota/claim instructions.", -) -> None: - parser.add_argument("--project", default=".", help="Project directory to start from.") - parser.add_argument("--goal-id", help="Goal id. Defaults to -goal.") - parser.add_argument("--agent-id", help=agent_help) - parser.add_argument( - "--cli-bin", - default="loopx", - help="LoopX CLI binary name embedded in generated commands.", - ) - - -def _add_codex_probe_arguments( - parser: argparse.ArgumentParser, - *, - codex_help: str = "Codex CLI executable to probe and reference in fallback commands.", -) -> None: - parser.add_argument( - "--codex-bin", - default=DEFAULT_CODEX_BIN, - help=codex_help, - ) - parser.add_argument( - "--timeout-seconds", - type=float, - default=DEFAULT_TIMEOUT_SECONDS, - help="Per-command timeout for help-only Codex CLI probes.", - ) - parser.add_argument( - "--fixture", - help="Public-safe JSON fixture with command_outputs, used instead of invoking Codex CLI.", - ) - - -def _add_optional_proof_fixture(parser: argparse.ArgumentParser, *, help_text: str) -> None: - parser.add_argument("--proof-fixture", help=help_text) - - -def _add_headless_fallback_argument(parser: argparse.ArgumentParser) -> None: - parser.add_argument( - "--allow-headless-fallback", - action="store_true", - help="Deprecated and ignored; headless codex exec is disabled for this default /goal path.", - ) diff --git a/loopx/cli_commands/starter_visible_driver.py b/loopx/cli_commands/starter_visible_driver.py deleted file mode 100644 index a9804a043e..0000000000 --- a/loopx/cli_commands/starter_visible_driver.py +++ /dev/null @@ -1,161 +0,0 @@ -from __future__ import annotations - -import argparse -from collections.abc import Callable -from pathlib import Path - -from ..codex_cli_probe import ( - build_codex_cli_local_driver_plan, - build_codex_cli_visible_driver_plan, - build_codex_cli_visible_driver_run_packet, - load_codex_cli_visible_session_proof_fixture, - render_codex_cli_local_driver_plan_markdown, - render_codex_cli_visible_driver_plan_markdown, - render_codex_cli_visible_driver_run_packet_markdown, - run_codex_cli_session_probe, -) -from .starter_visible_common import ( - _add_codex_probe_arguments, - _add_headless_fallback_argument, - _add_optional_proof_fixture, - _add_project_arguments, -) -from .starter_visible_pilot import ( - handle_starter_visible_pilot_command, - register_starter_visible_pilot_commands, -) - - -PrintPayload = Callable[ - [dict[str, object], str, Callable[[dict[str, object]], str]], - None, -] - - -def register_starter_visible_driver_commands(subparsers: argparse._SubParsersAction) -> None: - register_starter_visible_pilot_commands(subparsers) - - codex_cli_visible_driver_parser = subparsers.add_parser( - "codex-cli-visible-driver-plan", - help="Plan a public-safe visible Codex CLI driver path from session-probe evidence.", - ) - _add_project_arguments(codex_cli_visible_driver_parser) - _add_codex_probe_arguments(codex_cli_visible_driver_parser) - - codex_cli_local_driver_parser = subparsers.add_parser( - "codex-cli-local-driver-plan", - help=( - "Compose a dry-run-first local Codex CLI driver plan from quota, " - "TUI bootstrap, visible-driver, and exec fallback commands." - ), - ) - _add_project_arguments(codex_cli_local_driver_parser) - _add_codex_probe_arguments(codex_cli_local_driver_parser) - - codex_cli_visible_driver_run_parser = subparsers.add_parser( - "codex-cli-visible-driver-run", - help="Build a no-execution visible Codex CLI driver run packet from quota-safe driver planning inputs.", - ) - _add_project_arguments(codex_cli_visible_driver_run_parser) - _add_codex_probe_arguments( - codex_cli_visible_driver_run_parser, - codex_help="Codex CLI executable to probe for visible-session capabilities.", - ) - _add_optional_proof_fixture( - codex_cli_visible_driver_run_parser, - help_text=( - "Optional public-safe visible-session proof fixture. " - "Without it, same-session automation remains blocked." - ), - ) - _add_headless_fallback_argument(codex_cli_visible_driver_run_parser) - - -def handle_codex_cli_visible_driver_plan_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int: - probe_payload = run_codex_cli_session_probe( - codex_bin=args.codex_bin, - timeout_seconds=args.timeout_seconds, - fixture=Path(args.fixture).expanduser() if args.fixture else None, - ) - payload = build_codex_cli_visible_driver_plan( - project=Path(args.project), - goal_id=args.goal_id, - agent_id=args.agent_id, - cli_bin=args.cli_bin, - codex_bin=args.codex_bin, - probe_payload=probe_payload, - ) - print_payload(payload, args.format, render_codex_cli_visible_driver_plan_markdown) - return 0 if payload.get("ok") else 1 - - -def handle_codex_cli_local_driver_plan_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int: - probe_payload = run_codex_cli_session_probe( - codex_bin=args.codex_bin, - timeout_seconds=args.timeout_seconds, - fixture=Path(args.fixture).expanduser() if args.fixture else None, - ) - payload = build_codex_cli_local_driver_plan( - project=Path(args.project), - goal_id=args.goal_id, - agent_id=args.agent_id, - cli_bin=args.cli_bin, - codex_bin=args.codex_bin, - probe_payload=probe_payload, - ) - print_payload(payload, args.format, render_codex_cli_local_driver_plan_markdown) - return 0 if payload.get("ok") else 1 - - -def handle_codex_cli_visible_driver_run_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int: - probe_payload = run_codex_cli_session_probe( - codex_bin=args.codex_bin, - timeout_seconds=args.timeout_seconds, - fixture=Path(args.fixture).expanduser() if args.fixture else None, - ) - proof_payload = ( - load_codex_cli_visible_session_proof_fixture(Path(args.proof_fixture).expanduser()) - if args.proof_fixture - else None - ) - payload = build_codex_cli_visible_driver_run_packet( - project=Path(args.project), - goal_id=args.goal_id, - agent_id=args.agent_id, - cli_bin=args.cli_bin, - codex_bin=args.codex_bin, - probe_payload=probe_payload, - proof_payload=proof_payload, - allow_headless_fallback=bool(args.allow_headless_fallback), - ) - print_payload(payload, args.format, render_codex_cli_visible_driver_run_packet_markdown) - return 0 if payload.get("ok") else 1 - - -_VISIBLE_DRIVER_HANDLERS: dict[str, Callable[[argparse.Namespace, PrintPayload], int]] = { - "codex-cli-visible-driver-plan": handle_codex_cli_visible_driver_plan_command, - "codex-cli-local-driver-plan": handle_codex_cli_local_driver_plan_command, - "codex-cli-visible-driver-run": handle_codex_cli_visible_driver_run_command, -} - - -def handle_starter_visible_driver_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int | None: - pilot_result = handle_starter_visible_pilot_command(args, print_payload) - if pilot_result is not None: - return pilot_result - handler = _VISIBLE_DRIVER_HANDLERS.get(str(getattr(args, "command", ""))) - if handler is None: - return None - return handler(args, print_payload) diff --git a/loopx/cli_commands/starter_visible_pilot.py b/loopx/cli_commands/starter_visible_pilot.py deleted file mode 100644 index 7898f1dd9b..0000000000 --- a/loopx/cli_commands/starter_visible_pilot.py +++ /dev/null @@ -1,278 +0,0 @@ -from __future__ import annotations - -import argparse -from collections.abc import Callable -from pathlib import Path - -from ..codex_cli_probe import ( - build_codex_cli_bounded_visible_pilot_adapter, - build_codex_cli_one_message_loop_pilot, - build_codex_cli_visible_attach_acceptance, - build_codex_cli_visible_first_response_capture_plan, - build_codex_cli_visible_local_driver_pilot, - load_codex_cli_first_response_fixture, - load_codex_cli_visible_session_proof_fixture, - render_codex_cli_bounded_visible_pilot_adapter_markdown, - render_codex_cli_one_message_loop_pilot_markdown, - render_codex_cli_visible_attach_acceptance_markdown, - render_codex_cli_visible_first_response_capture_plan_markdown, - render_codex_cli_visible_local_driver_pilot_markdown, - run_codex_cli_session_probe, -) -from .starter_runtime_idle import ( - _add_runtime_idle_observation_arguments, - _load_codex_cli_runtime_idle_payload, -) -from .starter_visible_common import ( - _add_codex_probe_arguments, - _add_headless_fallback_argument, - _add_optional_proof_fixture, - _add_project_arguments, -) - - -PrintPayload = Callable[ - [dict[str, object], str, Callable[[dict[str, object]], str]], - None, -] - - -def register_starter_visible_pilot_commands(subparsers: argparse._SubParsersAction) -> None: - codex_cli_one_message_loop_parser = subparsers.add_parser( - "codex-cli-one-message-loop-pilot", - help="Compose the first Codex CLI TUI paste message with the safe scheduler/executor bridge.", - ) - _add_project_arguments(codex_cli_one_message_loop_parser) - _add_codex_probe_arguments( - codex_cli_one_message_loop_parser, - codex_help="Codex CLI executable to probe and reference in bridge commands.", - ) - _add_optional_proof_fixture( - codex_cli_one_message_loop_parser, - help_text=( - "Optional public-safe visible-session proof fixture. " - "Without it, same-session automation remains blocked." - ), - ) - _add_runtime_idle_observation_arguments(codex_cli_one_message_loop_parser) - _add_headless_fallback_argument(codex_cli_one_message_loop_parser) - - codex_cli_visible_local_driver_parser = subparsers.add_parser( - "codex-cli-visible-local-driver-pilot", - help="Compose the one-message TUI start and later scheduler bridge into a visible local driver pilot packet.", - ) - _add_project_arguments(codex_cli_visible_local_driver_parser) - _add_codex_probe_arguments( - codex_cli_visible_local_driver_parser, - codex_help="Codex CLI executable to probe and reference in bridge commands.", - ) - _add_optional_proof_fixture( - codex_cli_visible_local_driver_parser, - help_text="Optional public-safe visible-session proof fixture. Without it, later visible turns remain blocked.", - ) - codex_cli_visible_local_driver_parser.add_argument( - "--idle-fixture", - help="Optional public-safe runtime idle fixture. Without it, later visible turn candidates remain blocked.", - ) - _add_runtime_idle_observation_arguments( - codex_cli_visible_local_driver_parser, - include_idle_fixture=False, - ) - _add_headless_fallback_argument(codex_cli_visible_local_driver_parser) - - codex_cli_bounded_visible_parser = subparsers.add_parser( - "codex-cli-bounded-visible-pilot-adapter", - help="Validate public-safe first-response and idle evidence before claiming Codex CLI live TUI bootstrap success.", - ) - _add_project_arguments( - codex_cli_bounded_visible_parser, - agent_help="Registered LoopX agent id to include in adapter commands.", - ) - codex_cli_bounded_visible_parser.add_argument( - "--first-response-fixture", - help="Public-safe JSON fixture proving the first visible TUI response shape.", - ) - _add_runtime_idle_observation_arguments(codex_cli_bounded_visible_parser) - - codex_cli_first_response_capture_parser = subparsers.add_parser( - "codex-cli-visible-first-response-capture-plan", - help="Plan the public-safe manual visible capture of Codex CLI first-response and idle fixtures.", - ) - _add_project_arguments( - codex_cli_first_response_capture_parser, - agent_help="Registered LoopX agent id to include in generated commands.", - ) - codex_cli_first_response_capture_parser.add_argument( - "--first-response-path", - default="public-first-response.json", - help="Public-safe first-response fixture path used in generated commands.", - ) - codex_cli_first_response_capture_parser.add_argument( - "--idle-path", - default="public-runtime-idle.json", - help="Public-safe runtime idle fixture path used in generated commands.", - ) - - codex_cli_visible_attach_acceptance_parser = subparsers.add_parser( - "codex-cli-visible-attach-acceptance", - help="Accept or block same-TUI Codex CLI visible attach from help-only probe, proof, and idle evidence.", - ) - _add_project_arguments( - codex_cli_visible_attach_acceptance_parser, - agent_help="Registered LoopX agent id to include in acceptance commands.", - ) - _add_codex_probe_arguments( - codex_cli_visible_attach_acceptance_parser, - codex_help="Codex CLI executable to probe and reference in fallback commands.", - ) - _add_optional_proof_fixture( - codex_cli_visible_attach_acceptance_parser, - help_text="Optional public-safe visible-session proof fixture. Without it, same-TUI attach is not accepted.", - ) - _add_runtime_idle_observation_arguments(codex_cli_visible_attach_acceptance_parser) - - -def handle_codex_cli_one_message_loop_pilot_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int: - probe_payload = run_codex_cli_session_probe( - codex_bin=args.codex_bin, - timeout_seconds=args.timeout_seconds, - fixture=Path(args.fixture).expanduser() if args.fixture else None, - ) - proof_payload = ( - load_codex_cli_visible_session_proof_fixture(Path(args.proof_fixture).expanduser()) - if args.proof_fixture - else None - ) - idle_payload = _load_codex_cli_runtime_idle_payload(args) - payload = build_codex_cli_one_message_loop_pilot( - project=Path(args.project), - goal_id=args.goal_id, - agent_id=args.agent_id, - cli_bin=args.cli_bin, - codex_bin=args.codex_bin, - probe_payload=probe_payload, - proof_payload=proof_payload, - idle_payload=idle_payload, - allow_headless_fallback=bool(args.allow_headless_fallback), - ) - print_payload(payload, args.format, render_codex_cli_one_message_loop_pilot_markdown) - return 0 if payload.get("ok") else 1 - - -def handle_codex_cli_visible_local_driver_pilot_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int: - probe_payload = run_codex_cli_session_probe( - codex_bin=args.codex_bin, - timeout_seconds=args.timeout_seconds, - fixture=Path(args.fixture).expanduser() if args.fixture else None, - ) - proof_payload = ( - load_codex_cli_visible_session_proof_fixture(Path(args.proof_fixture).expanduser()) - if args.proof_fixture - else None - ) - idle_payload = _load_codex_cli_runtime_idle_payload(args) - payload = build_codex_cli_visible_local_driver_pilot( - project=Path(args.project), - goal_id=args.goal_id, - agent_id=args.agent_id, - cli_bin=args.cli_bin, - codex_bin=args.codex_bin, - probe_payload=probe_payload, - proof_payload=proof_payload, - idle_payload=idle_payload, - allow_headless_fallback=bool(args.allow_headless_fallback), - ) - print_payload(payload, args.format, render_codex_cli_visible_local_driver_pilot_markdown) - return 0 if payload.get("ok") else 1 - - -def handle_codex_cli_bounded_visible_pilot_adapter_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int: - first_response_payload = ( - load_codex_cli_first_response_fixture(Path(args.first_response_fixture).expanduser()) - if args.first_response_fixture - else None - ) - idle_payload = _load_codex_cli_runtime_idle_payload(args) - payload = build_codex_cli_bounded_visible_pilot_adapter( - project=Path(args.project), - goal_id=args.goal_id, - agent_id=args.agent_id, - cli_bin=args.cli_bin, - first_response_payload=first_response_payload, - idle_payload=idle_payload, - ) - print_payload(payload, args.format, render_codex_cli_bounded_visible_pilot_adapter_markdown) - return 0 if payload.get("ok") else 1 - - -def handle_codex_cli_visible_first_response_capture_plan_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int: - payload = build_codex_cli_visible_first_response_capture_plan( - project=Path(args.project), - goal_id=args.goal_id, - agent_id=args.agent_id, - cli_bin=args.cli_bin, - first_response_path=args.first_response_path, - idle_path=args.idle_path, - ) - print_payload(payload, args.format, render_codex_cli_visible_first_response_capture_plan_markdown) - return 0 if payload.get("ok") else 1 - - -def handle_codex_cli_visible_attach_acceptance_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int: - probe_payload = run_codex_cli_session_probe( - codex_bin=args.codex_bin, - timeout_seconds=args.timeout_seconds, - fixture=Path(args.fixture).expanduser() if args.fixture else None, - ) - proof_payload = ( - load_codex_cli_visible_session_proof_fixture(Path(args.proof_fixture).expanduser()) - if args.proof_fixture - else None - ) - idle_payload = _load_codex_cli_runtime_idle_payload(args) - payload = build_codex_cli_visible_attach_acceptance( - project=Path(args.project), - goal_id=args.goal_id, - agent_id=args.agent_id, - cli_bin=args.cli_bin, - codex_bin=args.codex_bin, - probe_payload=probe_payload, - proof_payload=proof_payload, - idle_payload=idle_payload, - ) - print_payload(payload, args.format, render_codex_cli_visible_attach_acceptance_markdown) - return 0 if payload.get("ok") else 1 - - -_VISIBLE_PILOT_HANDLERS: dict[str, Callable[[argparse.Namespace, PrintPayload], int]] = { - "codex-cli-one-message-loop-pilot": handle_codex_cli_one_message_loop_pilot_command, - "codex-cli-visible-local-driver-pilot": handle_codex_cli_visible_local_driver_pilot_command, - "codex-cli-bounded-visible-pilot-adapter": handle_codex_cli_bounded_visible_pilot_adapter_command, - "codex-cli-visible-first-response-capture-plan": handle_codex_cli_visible_first_response_capture_plan_command, - "codex-cli-visible-attach-acceptance": handle_codex_cli_visible_attach_acceptance_command, -} - - -def handle_starter_visible_pilot_command( - args: argparse.Namespace, - print_payload: PrintPayload, -) -> int | None: - handler = _VISIBLE_PILOT_HANDLERS.get(str(getattr(args, "command", ""))) - if handler is None: - return None - return handler(args, print_payload) diff --git a/loopx/cli_runtime.py b/loopx/cli_runtime.py index e0920149ad..ba7e8b1b90 100644 --- a/loopx/cli_runtime.py +++ b/loopx/cli_runtime.py @@ -29,20 +29,6 @@ "agent-onboard", "connect", "codex-cli-bootstrap-message", - "codex-cli-bounded-visible-pilot-adapter", - "codex-cli-exec-handoff", - "codex-cli-visible-first-response-capture-plan", - "codex-cli-local-driver-plan", - "codex-cli-local-scheduler-exec", - "codex-cli-local-scheduler-tick", - "codex-cli-one-message-loop-pilot", - "codex-cli-runtime-idle-detector", - "codex-cli-session-probe", - "codex-cli-visible-attach-acceptance", - "codex-cli-visible-local-driver-pilot", - "codex-cli-visible-driver-run", - "codex-cli-visible-driver-plan", - "codex-cli-visible-session-proof", "commands", "demo", "doctor", diff --git a/loopx/codex_cli_probe.py b/loopx/codex_cli_probe.py deleted file mode 100644 index b2a21f9750..0000000000 --- a/loopx/codex_cli_probe.py +++ /dev/null @@ -1,1531 +0,0 @@ -from __future__ import annotations - -from pathlib import Path -from typing import Any, Callable - -from .control_plane.projects.identity import default_goal_id -from .paths import shell_selected_global_registry -from .codex_cli_probe_markdown import ( - render_codex_cli_bounded_visible_pilot_adapter_markdown as render_codex_cli_bounded_visible_pilot_adapter_markdown, - render_codex_cli_local_driver_plan_markdown as render_codex_cli_local_driver_plan_markdown, - render_codex_cli_local_scheduler_executor_markdown as render_codex_cli_local_scheduler_executor_markdown, - render_codex_cli_local_scheduler_tick_markdown as render_codex_cli_local_scheduler_tick_markdown, - render_codex_cli_one_message_loop_pilot_markdown as render_codex_cli_one_message_loop_pilot_markdown, - render_codex_cli_runtime_idle_detector_markdown as render_codex_cli_runtime_idle_detector_markdown, - render_codex_cli_session_probe_markdown as render_codex_cli_session_probe_markdown, - render_codex_cli_visible_attach_acceptance_markdown as render_codex_cli_visible_attach_acceptance_markdown, - render_codex_cli_visible_driver_plan_markdown as render_codex_cli_visible_driver_plan_markdown, - render_codex_cli_visible_driver_run_packet_markdown as render_codex_cli_visible_driver_run_packet_markdown, - render_codex_cli_visible_first_response_capture_plan_markdown as render_codex_cli_visible_first_response_capture_plan_markdown, - render_codex_cli_visible_local_driver_pilot_markdown as render_codex_cli_visible_local_driver_pilot_markdown, - render_codex_cli_visible_session_proof_markdown as render_codex_cli_visible_session_proof_markdown, -) -from .codex_cli_runtime_probe import ( - DEFAULT_CODEX_BIN as DEFAULT_CODEX_BIN, - DEFAULT_EXECUTOR_TIMEOUT_SECONDS as DEFAULT_EXECUTOR_TIMEOUT_SECONDS, - DEFAULT_MIN_HUMAN_INPUT_IDLE_SECONDS as DEFAULT_MIN_HUMAN_INPUT_IDLE_SECONDS, - DEFAULT_TIMEOUT_SECONDS as DEFAULT_TIMEOUT_SECONDS, - HELP_COMMANDS as HELP_COMMANDS, - FIRST_RESPONSE_REQUIRED_FALSE_CHECKS, - FIRST_RESPONSE_REQUIRED_TRUE_CHECKS, - RUNTIME_IDLE_REQUIRED_FALSE_CHECKS, - RUNTIME_IDLE_REQUIRED_TRUE_CHECKS, - _nested_bool, - _nested_false, - _shell_arg, - build_codex_cli_runtime_idle_detector as build_codex_cli_runtime_idle_detector, - build_codex_cli_runtime_idle_observation_payload as build_codex_cli_runtime_idle_observation_payload, - build_codex_cli_visible_session_proof as build_codex_cli_visible_session_proof, - classify_codex_cli_session_surface as classify_codex_cli_session_surface, - load_codex_cli_first_response_fixture as load_codex_cli_first_response_fixture, - load_codex_cli_probe_fixture as load_codex_cli_probe_fixture, - load_codex_cli_runtime_idle_fixture as load_codex_cli_runtime_idle_fixture, - load_codex_cli_visible_session_proof_fixture as load_codex_cli_visible_session_proof_fixture, - probe_human_input_idle_seconds as probe_human_input_idle_seconds, - run_codex_cli_session_probe as run_codex_cli_session_probe, -) -from .project_prompt import ( - CODEX_CLI_VISIBLE_SCHEDULER_CONTEXT, - build_codex_cli_bootstrap_message, - render_scheduler_execution_args, -) - - -CODEX_CLI_SCHEDULER_ARGS = render_scheduler_execution_args( - scheduler_execution_context=CODEX_CLI_VISIBLE_SCHEDULER_CONTEXT -) - - -def build_codex_cli_visible_attach_acceptance( - *, - project: Path, - goal_id: str | None, - agent_id: str | None, - cli_bin: str, - codex_bin: str, - probe_payload: dict[str, Any], - proof_payload: dict[str, Any] | None = None, - idle_payload: dict[str, Any] | None = None, -) -> dict[str, Any]: - """Decide whether evidence is strong enough for same-TUI visible attach. - - This packet is an acceptance gate, not an executor. It deliberately keeps - Codex CLI `resume` / `remote-control` surfaces in a spike lane unless a - public-safe proof shows a visible same-TUI attach and a fresh idle detector - proves the later turn is not racing the user or an existing turn. - """ - - local_plan = build_codex_cli_local_driver_plan( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - codex_bin=codex_bin, - probe_payload=probe_payload, - ) - visible_plan = ( - local_plan.get("visible_driver_plan") - if isinstance(local_plan.get("visible_driver_plan"), dict) - else {} - ) - proof = build_codex_cli_visible_session_proof( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - proof_payload=proof_payload, - ) - idle_detector = build_codex_cli_runtime_idle_detector( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - idle_payload=idle_payload, - ) - resolved_project = str(local_plan["project"]) - resolved_goal_id = str(local_plan["goal_id"]) - agent_arg = f" --agent-id {_shell_arg(agent_id)}" if agent_id else "" - common_args = ( - f"--project {_shell_arg(resolved_project)} " - f"--goal-id {_shell_arg(resolved_goal_id)}{agent_arg} " - f"--codex-bin {_shell_arg(codex_bin)}" - ) - proof_approved = proof.get("approved_for_same_session_automation") is True - idle_approved = idle_detector.get("approved_for_visible_later_turn") is True - observed_surface = str(proof.get("observed_surface") or "unknown") - driver_mode = str(local_plan.get("driver_mode") or "tui_bootstrap_only") - same_tui_proof = proof_approved and observed_surface == "same_tui_visible_attach" - accepted_same_tui = same_tui_proof and idle_approved - visible_later_turn_candidate = proof_approved and idle_approved - - blockers: list[str] = [] - if accepted_same_tui: - decision = "same_tui_visible_attach_accepted" - acceptance_action = "allow_opt_in_same_tui_visible_turn_after_fresh_quota_guard" - next_safe_step = ( - "wire the proven same-TUI visible attach primitive behind a fresh " - "quota guard, runtime idle detector, and explicit command boundary" - ) - elif proof_approved and idle_approved: - decision = "visible_surface_spike_passed_not_same_tui" - acceptance_action = "keep_visible_surface_as_spike_candidate_not_same_tui_attach" - blockers.append("same_tui_visible_attach_not_proven") - next_safe_step = ( - "keep one-message TUI bootstrap primary; treat the proven visible " - "resume/remote-control surface as an opt-in spike until same-TUI " - "attachment is demonstrated" - ) - elif proof_approved: - decision = "runtime_idle_evidence_required" - acceptance_action = "capture_runtime_idle_evidence_before_later_visible_turn" - blockers.extend(idle_detector.get("failures") or ["runtime_idle_evidence_missing"]) - next_safe_step = ( - "capture a public-safe runtime idle fixture or local observation " - "before any later visible Codex CLI prompt" - ) - elif driver_mode in {"session_attached_visible_turn", "visible_resume_or_remote_control_spike"}: - decision = "visible_session_proof_required" - acceptance_action = "capture_public_safe_visible_session_proof" - if proof_payload is None: - blockers.append("visible_session_proof_missing") - else: - blockers.extend(proof.get("failures") or ["visible_session_proof_incomplete"]) - next_safe_step = ( - "do not call this accepted automation yet; first prove visibility, " - "interruptibility, boundaries, and compact writeback planning" - ) - else: - decision = "tui_bootstrap_only" - acceptance_action = "ask_user_to_start_inside_codex_cli_tui" - blockers.append("codex_cli_attach_surface_not_exposed_by_probe") - next_safe_step = ( - "ask the user to start in Codex CLI TUI and paste the bootstrap message; " - "headless codex exec is disabled for this product path" - ) - - commands = ( - local_plan.get("commands") - if isinstance(local_plan.get("commands"), dict) - else {} - ) - return { - "ok": True, - "schema_version": "codex_cli_visible_attach_acceptance_v0", - "project": resolved_project, - "goal_id": resolved_goal_id, - "agent_id": agent_id, - "cli_bin": cli_bin, - "codex_bin": codex_bin, - "decision": decision, - "acceptance_action": acceptance_action, - "accepted_for_same_tui_automation": accepted_same_tui, - "accepted_for_visible_later_turn": visible_later_turn_candidate, - "observed_surface": observed_surface, - "driver_mode": driver_mode, - "next_safe_step": next_safe_step, - "blockers": blockers, - "requirements": { - "help_probe_required": True, - "public_safe_visible_session_proof_required": True, - "runtime_idle_detector_required": True, - "same_tui_surface_required_for_same_tui_acceptance": True, - "fresh_quota_guard_required_before_execution": True, - "headless_execution_disabled": True, - }, - "probe": { - "schema_version": probe_payload.get("schema_version"), - "source": probe_payload.get("source"), - "recommended_mode": probe_payload.get("recommended_mode"), - "capabilities": probe_payload.get("capabilities"), - "warnings": probe_payload.get("warnings") or [], - }, - "visible_driver_plan": { - "schema_version": visible_plan.get("schema_version"), - "driver_mode": visible_plan.get("driver_mode"), - "automation_action": visible_plan.get("automation_action"), - "next_step": visible_plan.get("next_step"), - }, - "visible_session_proof": { - "supplied": proof_payload is not None, - "approved": proof_approved, - "decision": proof.get("decision"), - "observed_surface": proof.get("observed_surface"), - "failures": proof.get("failures") or [], - }, - "runtime_idle_detector": { - "supplied": idle_payload is not None, - "approved": idle_approved, - "decision": idle_detector.get("decision"), - "failures": idle_detector.get("failures") or [], - "source": idle_detector.get("source"), - }, - "commands": { - "session_probe": f"{_shell_arg(cli_bin)} codex-cli-session-probe --codex-bin {_shell_arg(codex_bin)}", - "local_driver_plan": commands.get("local_driver_plan"), - "visible_driver_plan": commands.get("visible_driver_plan"), - "visible_attach_acceptance": ( - f"{_shell_arg(cli_bin)} codex-cli-visible-attach-acceptance {common_args} " - "--proof-fixture --idle-fixture " - ), - "visible_session_proof": ( - f"{_shell_arg(cli_bin)} codex-cli-visible-session-proof " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}" - f"{agent_arg} --proof-fixture " - ), - "runtime_idle_detector_fixture": ( - f"{_shell_arg(cli_bin)} codex-cli-runtime-idle-detector " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}" - f"{agent_arg} --idle-fixture " - ), - "tui_bootstrap_message": commands.get("tui_bootstrap_message"), - "explicit_headless_fallback": None, - "headless_fallback_disabled": commands.get("headless_fallback_disabled"), - }, - "boundary": { - "acceptance_packet_only": True, - "runs_codex": False, - "reads_raw_transcripts": False, - "reads_credentials": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "mutates_codex_session": False, - "spends_loopx_quota": False, - "writes_loopx_state": False, - "requires_fresh_quota_guard_before_execution": True, - "headless_execution_disabled": True, - }, - "warnings": list(probe_payload.get("warnings") or []), - } - - -def build_codex_cli_visible_driver_plan( - *, - project: Path, - goal_id: str | None, - agent_id: str | None, - cli_bin: str, - codex_bin: str, - probe_payload: dict[str, Any], -) -> dict[str, Any]: - """Build a public-safe plan for a visible Codex CLI automation driver. - - The plan is intentionally read-only. It decides whether a future local - driver should attempt a visible session attachment, run a resume/remote - control spike, or keep the one-message TUI bootstrap as the product path. - """ - - resolved_project = str(project.expanduser()) - resolved_goal_id = goal_id or default_goal_id(project) - capabilities = probe_payload.get("capabilities") if isinstance(probe_payload.get("capabilities"), dict) else {} - safe_injection_supported = bool(capabilities.get("safe_injection_supported")) - visible_resume_supported = bool(capabilities.get("visible_resume_supported")) - remote_control_supported = bool(capabilities.get("remote_control_surface_detected")) - agent_arg = f" --agent-id {_shell_arg(agent_id)}" if agent_id else "" - quota_guard_command = ( - f"{_shell_arg(cli_bin)} --format json quota should-run " - f"--goal-id {_shell_arg(resolved_goal_id)}{agent_arg}" - f"{CODEX_CLI_SCHEDULER_ARGS}" - ) - bootstrap_command = ( - f"{_shell_arg(cli_bin)} codex-cli-bootstrap-message " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}{agent_arg}" - ) - probe_command = f"{_shell_arg(cli_bin)} codex-cli-session-probe --codex-bin {_shell_arg(codex_bin)}" - - if safe_injection_supported: - driver_mode = "session_attached_visible_turn" - automation_action = "try_visible_session_attach_with_idle_guard" - next_step = "wire the detected visible attach primitive behind idle guard and quota guard" - elif visible_resume_supported or remote_control_supported: - driver_mode = "visible_resume_or_remote_control_spike" - automation_action = "prototype_visible_resume_or_remote_control_with_idle_guard" - next_step = "run an explicit proof that resume or remote-control creates a visible interruptible turn" - else: - driver_mode = "tui_bootstrap_only" - automation_action = "ask_user_to_start_inside_codex_cli_tui" - next_step = "ask the user to start in Codex CLI TUI and paste the bootstrap message; headless fallback is disabled" - - driver_steps = [ - "run the session probe and quota guard before any delivery turn", - "if user_channel.action_required=true, surface only the concrete user gate", - "if delivery is allowed, verify idle_guard before any visible prompt", - "prefer a visible same-TUI turn; otherwise keep the one-message TUI bootstrap as the product path", - "write back compact evidence and spend quota only after validation", - ] - if driver_mode == "visible_resume_or_remote_control_spike": - driver_steps.insert( - 3, - "treat resume [PROMPT] or remote-control as unproven until a visible interruptible turn is observed", - ) - if driver_mode == "session_attached_visible_turn": - driver_steps.insert(3, "use only the detected visible attach primitive; do not write hidden session state") - - return { - "ok": True, - "schema_version": "codex_cli_visible_driver_plan_v0", - "project": resolved_project, - "goal_id": resolved_goal_id, - "agent_id": agent_id, - "cli_bin": cli_bin, - "codex_bin": codex_bin, - "probe_source": probe_payload.get("source"), - "probe_recommended_mode": probe_payload.get("recommended_mode"), - "driver_mode": driver_mode, - "automation_action": automation_action, - "next_step": next_step, - "capabilities": capabilities, - "commands": { - "probe": probe_command, - "quota_guard": quota_guard_command, - "tui_bootstrap_message": bootstrap_command, - "explicit_headless_fallback": None, - "headless_fallback_disabled": "headless codex exec is disabled for the default LoopX setup-then-goal bootstrap path", - }, - "driver_steps": driver_steps, - "boundary": { - "dry_run_plan_only": True, - "runs_codex": False, - "reads_raw_transcripts": False, - "reads_credentials": False, - "reads_session_files": False, - "mutates_codex_session": False, - "spends_loopx_quota": False, - "requires_idle_guard_before_visible_prompt": True, - "requires_user_gate_stop": True, - "headless_execution_disabled": True, - }, - "warnings": list(probe_payload.get("warnings") or []), - } - - -def build_codex_cli_local_driver_plan( - *, - project: Path, - goal_id: str | None, - agent_id: str | None, - cli_bin: str, - codex_bin: str, - probe_payload: dict[str, Any], -) -> dict[str, Any]: - """Build a dry-run-first local driver plan for Codex CLI. - - This does not launch Codex or mutate any session. It composes the existing - one-message TUI bootstrap, visible-driver plan, quota guard, and the - headless-disabled boundary into one operator-facing decision packet. - """ - - visible_plan = build_codex_cli_visible_driver_plan( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - codex_bin=codex_bin, - probe_payload=probe_payload, - ) - resolved_project = visible_plan["project"] - resolved_goal_id = visible_plan["goal_id"] - agent_arg = f" --agent-id {_shell_arg(agent_id)}" if agent_id else "" - visible_driver_plan_command = ( - f"{_shell_arg(cli_bin)} codex-cli-visible-driver-plan " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}{agent_arg} " - f"--codex-bin {_shell_arg(codex_bin)}" - ) - quota_guard_command = ( - f"{_shell_arg(cli_bin)} --format json " - f"--registry {shell_selected_global_registry()} " - f"quota should-run --goal-id {_shell_arg(resolved_goal_id)}{agent_arg}" - f"{CODEX_CLI_SCHEDULER_ARGS}" - ) - bootstrap_command = ( - f"{_shell_arg(cli_bin)} codex-cli-bootstrap-message " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}{agent_arg}" - ) - driver_mode = str(visible_plan.get("driver_mode") or "tui_bootstrap_only") - - if driver_mode == "session_attached_visible_turn": - decision = "attempt_visible_session_attach_after_idle_guard" - operator_instruction = ( - "Run quota guard, verify idle guard, then attempt only the detected visible attach primitive." - ) - elif driver_mode == "visible_resume_or_remote_control_spike": - decision = "run_visible_resume_or_remote_control_proof" - operator_instruction = ( - "Treat resume or remote-control as a proof target, not production session attachment, until the turn is visible and interruptible." - ) - else: - decision = "ask_user_to_start_from_tui" - operator_instruction = ( - "Ask the user to start inside Codex CLI TUI and paste the bootstrap message; " - "headless codex exec is disabled for this product path." - ) - - return { - "ok": True, - "schema_version": "codex_cli_local_driver_plan_v0", - "project": resolved_project, - "goal_id": resolved_goal_id, - "agent_id": agent_id, - "cli_bin": cli_bin, - "codex_bin": codex_bin, - "driver_phase": "dry_run_plan", - "driver_mode": driver_mode, - "decision": decision, - "operator_instruction": operator_instruction, - "visible_driver_plan": { - "schema_version": visible_plan.get("schema_version"), - "driver_mode": visible_plan.get("driver_mode"), - "automation_action": visible_plan.get("automation_action"), - "next_step": visible_plan.get("next_step"), - }, - "commands": { - "quota_guard": quota_guard_command, - "local_driver_plan": ( - f"{_shell_arg(cli_bin)} codex-cli-local-driver-plan " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}{agent_arg} " - f"--codex-bin {_shell_arg(codex_bin)}" - ), - "visible_driver_plan": visible_driver_plan_command, - "tui_bootstrap_message": bootstrap_command, - "explicit_headless_fallback": None, - "headless_fallback_disabled": "headless codex exec is disabled for the default LoopX setup-then-goal bootstrap path", - }, - "driver_steps": [ - "run quota_guard and stop when user_channel.action_required=true", - "run visible_driver_plan to classify TUI, resume, or remote-control mode", - "verify idle_guard before any visible resume or remote-control prompt", - "prefer one-message TUI bootstrap until visible attach is proven", - "do not offer headless codex exec from the default LoopX setup-then-goal bootstrap path", - "write back compact evidence or a precise blocker before quota spend", - ], - "idle_guard": { - "required": True, - "implemented": False, - "placeholder": "future driver must prove no active human typing and no running turn before visible resume or remote-control prompt", - }, - "execution_policy": { - "tui_bootstrap_primary": True, - "headless_execution_disabled": True, - "same_session_attachment_requires_visible_proof": True, - "quota_guard_required": True, - "spend_after_validated_writeback_only": True, - }, - "boundary": { - "dry_run_plan_only": True, - "runs_codex": False, - "reads_raw_transcripts": False, - "reads_credentials": False, - "reads_session_files": False, - "mutates_codex_session": False, - "spends_loopx_quota": False, - "requires_idle_guard_before_visible_prompt": True, - "requires_user_gate_stop": True, - "headless_execution_disabled": True, - }, - "warnings": list(visible_plan.get("warnings") or []), - } - - -def build_codex_cli_visible_driver_run_packet( - *, - project: Path, - goal_id: str | None, - agent_id: str | None, - cli_bin: str, - codex_bin: str, - probe_payload: dict[str, Any], - proof_payload: dict[str, Any] | None = None, - allow_headless_fallback: bool = False, -) -> dict[str, Any]: - """Build the v0 runner packet for one visible Codex CLI driver turn. - - The packet is deliberately not an executor. It converts the dry-run local - driver plan and optional visible-session proof into the next safe command - boundary for a local scheduler or human operator. Headless fallback remains - disabled for this default LoopX setup-then-goal bootstrap path. - """ - - local_plan = build_codex_cli_local_driver_plan( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - codex_bin=codex_bin, - probe_payload=probe_payload, - ) - resolved_project = str(local_plan["project"]) - resolved_goal_id = str(local_plan["goal_id"]) - driver_mode = str(local_plan.get("driver_mode") or "tui_bootstrap_only") - commands = local_plan.get("commands") if isinstance(local_plan.get("commands"), dict) else {} - proof = build_codex_cli_visible_session_proof( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - proof_payload=proof_payload, - ) if proof_payload is not None else None - proof_approved = bool(proof and proof.get("approved_for_same_session_automation") is True) - proof_command = ( - f"{_shell_arg(cli_bin)} codex-cli-visible-session-proof " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}" - f"{' --agent-id ' + _shell_arg(agent_id) if agent_id else ''} " - "--proof-fixture " - ) - - if proof_approved: - decision = "visible_session_turn_candidate" - next_driver_action = "run_visible_session_turn_after_quota_and_idle_guard" - recommended_command = proof_payload.get("recommended_command") if isinstance(proof_payload, dict) else None - if not recommended_command: - recommended_command = "use the proven visible Codex CLI surface; do not read transcripts or hidden session files" - elif driver_mode in {"session_attached_visible_turn", "visible_resume_or_remote_control_spike"}: - decision = "visible_session_proof_required" - next_driver_action = "capture_public_safe_visible_session_proof" - recommended_command = proof_command - else: - decision = "tui_bootstrap_only" - next_driver_action = "ask_user_to_start_inside_codex_cli_tui" - recommended_command = commands.get("tui_bootstrap_message") - - driver_steps = [ - "run quota_guard and stop if user_channel.action_required=true", - "stop or relocate if workspace_guard blocks the current checkout", - "use a visible session only when proof_approved=true and an idle guard passes", - "do not use headless codex exec from the default LoopX setup-then-goal bootstrap path", - "after the Codex turn, validate evidence or blocker before refresh-state", - "spend quota exactly once after validated writeback, never for this packet alone", - ] - warnings = list(local_plan.get("warnings") or []) - if allow_headless_fallback: - warnings.append( - "allow_headless_fallback was ignored because headless fallback is disabled for the default LoopX setup-then-goal bootstrap path." - ) - - return { - "ok": True, - "schema_version": "codex_cli_visible_driver_run_packet_v0", - "project": resolved_project, - "goal_id": resolved_goal_id, - "agent_id": agent_id, - "cli_bin": cli_bin, - "codex_bin": codex_bin, - "driver_phase": "run_packet_no_execution", - "driver_mode": driver_mode, - "decision": decision, - "next_driver_action": next_driver_action, - "recommended_command": recommended_command, - "allow_headless_fallback": allow_headless_fallback, - "visible_session_proof": { - "supplied": proof is not None, - "approved": proof_approved, - "decision": proof.get("decision") if proof else None, - "failures": proof.get("failures") if proof else [], - }, - "local_driver_plan": { - "schema_version": local_plan.get("schema_version"), - "driver_mode": local_plan.get("driver_mode"), - "decision": local_plan.get("decision"), - "operator_instruction": local_plan.get("operator_instruction"), - }, - "commands": { - "quota_guard": commands.get("quota_guard"), - "tui_bootstrap_message": commands.get("tui_bootstrap_message"), - "visible_session_proof": proof_command, - "explicit_headless_fallback": None, - "headless_fallback_disabled": commands.get("headless_fallback_disabled"), - }, - "driver_steps": driver_steps, - "execution_policy": { - "tui_bootstrap_primary": True, - "same_session_attachment_requires_visible_proof": True, - "headless_execution_disabled": True, - "quota_guard_required": True, - "idle_guard_required_before_visible_prompt": True, - "spend_after_validated_writeback_only": True, - }, - "boundary": { - "run_packet_only": True, - "runs_codex": False, - "reads_raw_transcripts": False, - "reads_credentials": False, - "reads_session_files": False, - "mutates_codex_session": False, - "spends_loopx_quota": False, - "requires_user_gate_stop": True, - "headless_execution_disabled": True, - }, - "warnings": warnings, - } - - -SchedulerCommandRunner = Callable[..., dict[str, Any]] - - -def build_codex_cli_local_scheduler_tick( - *, - project: Path, - goal_id: str | None, - agent_id: str | None, - cli_bin: str, - codex_bin: str, - probe_payload: dict[str, Any], - quota_payload: dict[str, Any] | None = None, - proof_payload: dict[str, Any] | None = None, - idle_payload: dict[str, Any] | None = None, - allow_headless_fallback: bool = False, -) -> dict[str, Any]: - from .codex_cli_scheduler import build_codex_cli_local_scheduler_tick as _build - - return _build( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - codex_bin=codex_bin, - probe_payload=probe_payload, - quota_payload=quota_payload, - proof_payload=proof_payload, - idle_payload=idle_payload, - allow_headless_fallback=allow_headless_fallback, - ) - - -def execute_codex_cli_local_scheduler_tick_result( - tick_payload: dict[str, Any], - *, - execute_candidate: bool = False, - execute_blocker_writeback: bool = False, - guard_checked: bool = False, - candidate_command_prefixes: list[str] | None = None, - executor_timeout_seconds: float = DEFAULT_EXECUTOR_TIMEOUT_SECONDS, - runner: SchedulerCommandRunner | None = None, -) -> dict[str, Any]: - from .codex_cli_scheduler import execute_codex_cli_local_scheduler_tick_result as _execute - - return _execute( - tick_payload, - execute_candidate=execute_candidate, - execute_blocker_writeback=execute_blocker_writeback, - guard_checked=guard_checked, - candidate_command_prefixes=candidate_command_prefixes, - executor_timeout_seconds=executor_timeout_seconds, - runner=runner, - ) - - -def build_codex_cli_local_scheduler_executor( - *, - project: Path, - goal_id: str | None, - agent_id: str | None, - cli_bin: str, - codex_bin: str, - probe_payload: dict[str, Any], - quota_payload: dict[str, Any] | None = None, - proof_payload: dict[str, Any] | None = None, - idle_payload: dict[str, Any] | None = None, - allow_headless_fallback: bool = False, - execute_candidate: bool = False, - execute_blocker_writeback: bool = False, - guard_checked: bool = False, - candidate_command_prefixes: list[str] | None = None, - executor_timeout_seconds: float = DEFAULT_EXECUTOR_TIMEOUT_SECONDS, - runner: SchedulerCommandRunner | None = None, -) -> dict[str, Any]: - from .codex_cli_scheduler import build_codex_cli_local_scheduler_executor as _build - - return _build( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - codex_bin=codex_bin, - probe_payload=probe_payload, - quota_payload=quota_payload, - proof_payload=proof_payload, - idle_payload=idle_payload, - allow_headless_fallback=allow_headless_fallback, - execute_candidate=execute_candidate, - execute_blocker_writeback=execute_blocker_writeback, - guard_checked=guard_checked, - candidate_command_prefixes=candidate_command_prefixes, - executor_timeout_seconds=executor_timeout_seconds, - runner=runner, - ) - - -def build_codex_cli_one_message_loop_pilot( - *, - project: Path, - goal_id: str | None, - agent_id: str | None, - cli_bin: str, - codex_bin: str, - probe_payload: dict[str, Any], - proof_payload: dict[str, Any] | None = None, - idle_payload: dict[str, Any] | None = None, - allow_headless_fallback: bool = False, -) -> dict[str, Any]: - """Compose the first-message TUI path with the safe scheduler bridge.""" - - bootstrap = build_codex_cli_bootstrap_message( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - ) - resolved_project = str(bootstrap["project"]) - resolved_goal_id = str(bootstrap["goal_id"]) - agent_arg = f" --agent-id {_shell_arg(agent_id)}" if agent_id else "" - common_args = ( - f"--project {_shell_arg(resolved_project)} " - f"--goal-id {_shell_arg(resolved_goal_id)}{agent_arg} " - f"--codex-bin {_shell_arg(codex_bin)}" - ) - scheduler_executor = build_codex_cli_local_scheduler_executor( - project=project, - goal_id=resolved_goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - codex_bin=codex_bin, - probe_payload=probe_payload, - proof_payload=proof_payload, - idle_payload=idle_payload, - allow_headless_fallback=allow_headless_fallback, - execute_candidate=False, - execute_blocker_writeback=False, - ) - scheduler_action = str(scheduler_executor.get("scheduler_action") or "") - scheduler_tick = ( - scheduler_executor.get("scheduler_tick") - if isinstance(scheduler_executor.get("scheduler_tick"), dict) - else {} - ) - scheduler_blocker = ( - scheduler_tick.get("precise_blocker") - if isinstance(scheduler_tick.get("precise_blocker"), dict) - else {} - ) - scheduler_blocker_reason = str(scheduler_blocker.get("reason") or "") - if scheduler_action == "external_visible_command_candidate": - pilot_decision = "first_message_then_candidate_available" - followup_mode = "local scheduler can show the candidate, but execution still requires guard and prefix opt-in" - elif scheduler_action == "write_precise_blocker" and scheduler_blocker_reason.startswith("runtime_idle_"): - pilot_decision = "first_message_then_runtime_idle_required" - followup_mode = ( - "local scheduler must capture public-safe runtime idle observation before later visible automation" - ) - elif scheduler_action == "write_precise_blocker": - pilot_decision = "first_message_then_visible_blocker_writeback" - followup_mode = "local scheduler can write the precise blocker after explicit guard-checked opt-in" - else: - pilot_decision = "first_message_tui_bootstrap_only" - followup_mode = "keep the TUI bootstrap as the product path until a visible proof exists" - - bootstrap_command = ( - f"{_shell_arg(cli_bin)} codex-cli-bootstrap-message " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}{agent_arg}" - ) - scheduler_exec_dry_run_command = ( - f"{_shell_arg(cli_bin)} codex-cli-local-scheduler-exec {common_args}" - " --observe-local-runtime --observed-surface visible_resume_prompt " - "--turn-state idle --probe-human-input-idle --checked-before-prompt " - "--visible-to-user --user-can-interrupt --manual-takeover-available" - ) - candidate_execute_template = ( - f"{scheduler_exec_dry_run_command} --guard-checked --execute-candidate " - "--candidate-command-prefix " - ) - blocker_execute_template = ( - f"{scheduler_exec_dry_run_command} --guard-checked --execute-blocker-writeback" - ) - return { - "ok": True, - "schema_version": "codex_cli_one_message_loop_pilot_v0", - "project": resolved_project, - "goal_id": resolved_goal_id, - "agent_id": agent_id, - "cli_bin": cli_bin, - "codex_bin": codex_bin, - "pilot_decision": pilot_decision, - "followup_mode": followup_mode, - "start_surface": "codex_cli_tui_one_message", - "first_turn": { - "user_action": "paste_bootstrap_message_into_codex_cli_tui", - "autostarts_loopx_loop": True, - "setup_then_loop_activation": True, - "preserve_tui": True, - "loop_activation": { - "source_command": bootstrap.get("heartbeat_prompt_json_command"), - "codex_cli": "/goal ", - "codex_app": " heartbeat automation", - }, - "stop_only_for": [ - "concrete_user_gate", - "workspace_guard", - "missing_capability", - "missing_installation_primitive", - "unsafe_boundary", - ], - "message": bootstrap.get("message"), - "snapshot_required": [ - "current goal id", - "concrete user gate or none", - "top user todo or none", - "top agent todo", - "next safe action", - ], - }, - "later_turn_contract": { - "preserve_visible_tui": True, - "visible_steering_requires": [ - "public_safe_visible_session_proof", - "runtime_idle_evidence", - "fresh_quota_guard", - "guard_checked", - "explicit_execution_bounds", - ], - "default_without_proof": "write_blocker_or_keep_tui_bootstrap_primary", - }, - "automation_bridge": { - "command": "codex-cli-local-scheduler-exec", - "default_executes": False, - "scheduler_action": scheduler_action, - "executor_reason": (scheduler_executor.get("execution") or {}).get("reason") - if isinstance(scheduler_executor.get("execution"), dict) - else None, - "followup_mode": followup_mode, - }, - "commands": { - "bootstrap_message": bootstrap_command, - "scheduler_exec_dry_run": scheduler_exec_dry_run_command, - "scheduler_exec_candidate_template": candidate_execute_template, - "scheduler_exec_blocker_template": blocker_execute_template, - }, - "bootstrap_message": { - "schema_version": bootstrap.get("schema_version"), - "invocation_mode": bootstrap.get("invocation_mode"), - "heartbeat_prompt_json_command": bootstrap.get("heartbeat_prompt_json_command"), - "quota_guard_command": bootstrap.get("quota_guard_command"), - "progress_refresh_command": bootstrap.get("progress_refresh_command"), - "refresh_command": bootstrap.get("refresh_command"), - "quota_spend_command": bootstrap.get("quota_spend_command"), - }, - "scheduler_executor": scheduler_executor, - "boundary": { - "pilot_packet_only": True, - "runs_codex": False, - "runs_scheduler_result": False, - "reads_raw_transcripts": False, - "reads_credentials": False, - "reads_session_files": False, - "mutates_codex_session": False, - "spends_loopx_quota": False, - "requires_user_visible_start": True, - "headless_execution_disabled": True, - "candidate_execution_requires_guard_and_prefix": True, - }, - "warnings": list(scheduler_executor.get("warnings") or []), - } - - -def build_codex_cli_visible_local_driver_pilot( - *, - project: Path, - goal_id: str | None, - agent_id: str | None, - cli_bin: str, - codex_bin: str, - probe_payload: dict[str, Any], - proof_payload: dict[str, Any] | None = None, - idle_payload: dict[str, Any] | None = None, - allow_headless_fallback: bool = False, -) -> dict[str, Any]: - """Prototype the visible local driver loop without executing Codex. - - This composes the first visible TUI bootstrap, a no-execution scheduler - wrapper, and the public-safe proof boundary a returning user would need - before LoopX can steer later visible turns. - """ - - one_message = build_codex_cli_one_message_loop_pilot( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - codex_bin=codex_bin, - probe_payload=probe_payload, - proof_payload=proof_payload, - idle_payload=idle_payload, - allow_headless_fallback=allow_headless_fallback, - ) - scheduler_executor = ( - one_message.get("scheduler_executor") - if isinstance(one_message.get("scheduler_executor"), dict) - else {} - ) - scheduler_tick = ( - scheduler_executor.get("scheduler_tick") - if isinstance(scheduler_executor.get("scheduler_tick"), dict) - else {} - ) - execution = ( - scheduler_executor.get("execution") - if isinstance(scheduler_executor.get("execution"), dict) - else {} - ) - resolved_project = str(one_message["project"]) - resolved_goal_id = str(one_message["goal_id"]) - scheduler_action = str(scheduler_executor.get("scheduler_action") or "") - scheduler_blocker = ( - scheduler_tick.get("precise_blocker") - if isinstance(scheduler_tick.get("precise_blocker"), dict) - else {} - ) - scheduler_blocker_reason = str(scheduler_blocker.get("reason") or "") - proof = ( - scheduler_tick.get("visible_session_proof") - if isinstance(scheduler_tick.get("visible_session_proof"), dict) - else {} - ) - proof_approved = bool(proof.get("approved") is True) - idle_detector = build_codex_cli_runtime_idle_detector( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - idle_payload=idle_payload, - ) - idle_approved = bool(idle_detector.get("approved_for_visible_later_turn") is True) - idle_detector_command = ( - f"{_shell_arg(cli_bin)} codex-cli-runtime-idle-detector " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}" - f"{' --agent-id ' + _shell_arg(agent_id) if agent_id else ''} " - "--observe-local-runtime --observed-surface visible_resume_prompt " - "--turn-state idle --probe-human-input-idle --checked-before-prompt " - "--visible-to-user --user-can-interrupt --manual-takeover-available" - ) - idle_fixture_detector_command = ( - f"{_shell_arg(cli_bin)} codex-cli-runtime-idle-detector " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}" - f"{' --agent-id ' + _shell_arg(agent_id) if agent_id else ''} " - "--idle-fixture " - ) - - if proof_approved and scheduler_action == "external_visible_command_candidate" and idle_approved: - loop_decision = "visible_candidate_ready_for_guarded_execution" - next_driver_action = "run_scheduler_exec_candidate_after_fresh_guard_and_prefix" - elif proof_approved and ( - scheduler_action == "external_visible_command_candidate" - or scheduler_blocker_reason.startswith("runtime_idle_") - ): - loop_decision = "runtime_idle_detector_required" - next_driver_action = "capture_public_safe_runtime_idle_observation" - elif scheduler_action == "write_precise_blocker": - loop_decision = "visible_loop_blocker_writeback_ready" - next_driver_action = "write_precise_blocker_after_fresh_guard" - elif scheduler_action == "surface_tui_bootstrap": - loop_decision = "surface_tui_bootstrap_only" - next_driver_action = "keep_first_message_tui_path_visible" - else: - loop_decision = "review_scheduler_packet_before_execution" - next_driver_action = "inspect_scheduler_executor_packet" - - commands = one_message.get("commands") if isinstance(one_message.get("commands"), dict) else {} - scheduler_commands = ( - scheduler_executor.get("commands") - if isinstance(scheduler_executor.get("commands"), dict) - else {} - ) - visible_loop_steps = [ - "start from the visible Codex CLI TUI with the one-message bootstrap", - "run quota should-run with the registered agent id before each scheduler tick", - "stop on interaction_contract.user_channel.action_required=true and show the concrete user todo", - "require public-safe local idle observation or a fixture before any visible resume, remote-control, or same-TUI prompt", - "run codex-cli-local-scheduler-exec as dry-run unless guard and explicit execution flags are present", - "for a visible candidate, require guard_checked plus an allowed candidate command prefix", - "for a blocker, write compact LoopX state only after guard_checked", - "never read raw transcripts, session files, credentials, stdout, or stderr for this pilot", - ] - - return { - "ok": True, - "schema_version": "codex_cli_visible_local_driver_pilot_v0", - "project": resolved_project, - "goal_id": resolved_goal_id, - "agent_id": agent_id, - "cli_bin": cli_bin, - "codex_bin": codex_bin, - "pilot_phase": "visible_local_driver_loop_no_execution", - "start_surface": "codex_cli_tui_one_message", - "loop_decision": loop_decision, - "next_driver_action": next_driver_action, - "one_message_pilot": { - "schema_version": one_message.get("schema_version"), - "pilot_decision": one_message.get("pilot_decision"), - "start_surface": one_message.get("start_surface"), - "followup_mode": one_message.get("followup_mode"), - }, - "scheduler_executor": { - "schema_version": scheduler_executor.get("schema_version"), - "scheduler_action": scheduler_action, - "decision": scheduler_executor.get("decision"), - "executor_reason": execution.get("reason"), - "executed": execution.get("executed"), - }, - "visible_session_proof": { - "supplied": bool(proof.get("supplied")), - "approved": proof_approved, - "decision": proof.get("decision"), - "failures": proof.get("failures") or [], - }, - "runtime_idle_detector": { - "supplied": idle_payload is not None, - "approved": idle_approved, - "decision": idle_detector.get("decision"), - "failures": idle_detector.get("failures") or [], - "command": idle_detector_command, - }, - "idle_guard_contract": { - "required_before_visible_prompt": True, - "fixture_keys": [ - "idle_guard.no_active_human_typing", - "idle_guard.no_running_turn", - "idle_guard.checked_before_prompt", - "turn_visibility.visible_to_user", - "interruptibility.user_can_interrupt", - "interruptibility.manual_takeover_available", - ], - "current_pilot_implements_runtime_idle_detection": True, - "fixture_backed_runtime_idle_detector": True, - "runtime_sensor_implemented": True, - "public_safe_fixture_supported": True, - "local_observation_adapter_supported": True, - "no_private_state_observation": True, - }, - "visible_loop_steps": visible_loop_steps, - "commands": { - "bootstrap_message": commands.get("bootstrap_message"), - "scheduler_exec_dry_run": commands.get("scheduler_exec_dry_run"), - "scheduler_exec_candidate_template": commands.get("scheduler_exec_candidate_template"), - "scheduler_exec_blocker_template": commands.get("scheduler_exec_blocker_template"), - "scheduler_tick": scheduler_commands.get("scheduler_tick"), - "candidate_command": scheduler_commands.get("candidate_command"), - "blocker_writeback": scheduler_commands.get("blocker_writeback"), - "runtime_idle_detector": idle_detector_command, - "runtime_idle_detector_fixture": idle_fixture_detector_command, - }, - "execution_policy": { - "tui_bootstrap_primary": True, - "later_turns_visible_to_user": True, - "user_can_interrupt_or_take_over": True, - "same_session_attachment_requires_visible_proof": True, - "headless_execution_disabled": True, - "quota_guard_required_each_tick": True, - "spend_after_validated_writeback_only": True, - }, - "boundary": { - "pilot_packet_only": True, - "runs_codex": False, - "runs_scheduler_result": False, - "reads_raw_transcripts": False, - "reads_credentials": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "mutates_codex_session": False, - "writes_loopx_state": False, - "spends_loopx_quota": False, - "requires_fresh_guard_before_execution": True, - "candidate_execution_requires_guard_and_prefix": True, - "blocker_writeback_requires_guard_checked": True, - "headless_execution_disabled": True, - }, - "warnings": [ - *list(one_message.get("warnings") or []), - *( - ["Runtime idle detector must pass before a later visible Codex CLI turn can run."] - if proof_approved and not idle_approved - else [] - ), - ], - } - - -def build_codex_cli_visible_first_response_capture_plan( - *, - project: Path, - goal_id: str | None, - agent_id: str | None, - cli_bin: str, - first_response_path: str = "public-first-response.json", - idle_path: str = "public-runtime-idle.json", -) -> dict[str, Any]: - """Describe the safest public fixture capture path for visible TUI bootstrap. - - This is deliberately a plan packet. It does not start Codex, read terminal - buffers, inspect session files, or write fixtures. A human-visible TUI run - supplies the observations, and the bounded visible adapter validates the - resulting public-safe JSON before any success claim or quota spend. - """ - - adapter = build_codex_cli_bounded_visible_pilot_adapter( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - ) - resolved_project = str(adapter["project"]) - resolved_goal_id = str(adapter["goal_id"]) - agent_arg = f" --agent-id {_shell_arg(agent_id)}" if agent_id else "" - first_response_fixture = { - "observed_surface": "codex_cli_tui_visible_window", - "prompt_delivery": { - "manual_or_visible_delivery": True, - "prompt_public_safe": True, - "argv_prompt_used": False, - }, - "first_response": { - "goal_id_visible": True, - "user_gate_or_none_visible": True, - "top_user_todo_or_none_visible": True, - "top_agent_todo_visible": True, - "next_safe_action_visible": True, - "bounded_segment_started_or_blocker_written": True, - }, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "writeback": { - "compact_evidence_planned": True, - "quota_spend_after_writeback_only": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - "spends_quota_before_writeback": False, - }, - } - runtime_idle_fixture = { - "observed_surface": "codex_cli_tui_visible_window", - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": {"visible_to_user": True}, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - }, - } - first_response_checklist = [ - { - "key": key, - "required": True, - "description": description, - "path": ".".join(path), - } - for key, path, description in FIRST_RESPONSE_REQUIRED_TRUE_CHECKS - ] + [ - { - "key": key, - "required": False, - "description": description, - "path": ".".join(path), - } - for key, path, description in FIRST_RESPONSE_REQUIRED_FALSE_CHECKS - ] - runtime_idle_checklist = [ - { - "key": key, - "required": True, - "description": description, - "path": ".".join(path), - } - for key, path, description in RUNTIME_IDLE_REQUIRED_TRUE_CHECKS - ] + [ - { - "key": key, - "required": False, - "description": description, - "path": ".".join(path), - } - for key, path, description in RUNTIME_IDLE_REQUIRED_FALSE_CHECKS - ] - capture_steps = [ - "Run quota should-run for the goal and stop if a concrete user gate blocks this path.", - "Open Codex CLI TUI yourself in the project repo; do not pass the bootstrap message as argv.", - "Paste the generated LoopX bootstrap message into the visible TUI.", - "Observe only whether the first response exposes the required public-safe fields; do not copy raw text.", - f"Write those booleans to {first_response_path}.", - "After the first response or blocker is visible, confirm the TUI is idle and the user is not typing.", - f"Write those idle booleans to {idle_path}.", - "Run the bounded visible pilot adapter with both fixtures before claiming success or spending quota.", - ] - stop_conditions = [ - "the first response contains private paths, internal project names, credentials, or raw logs", - "the bootstrap message would have to be passed as argv", - "the user is typing or Codex is already running a visible turn", - "the response does not show goal/todo/gate/next-action status clearly enough to fill the fixture", - "any required boundary boolean would be false", - ] - commands = { - "quota_guard": ( - f"{_shell_arg(cli_bin)} --format json quota should-run " - f"--goal-id {_shell_arg(resolved_goal_id)}{agent_arg}" - f"{CODEX_CLI_SCHEDULER_ARGS}" - ), - "bootstrap_message": ( - f"{_shell_arg(cli_bin)} codex-cli-bootstrap-message " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}" - f"{agent_arg} --message-only" - ), - "runtime_idle_detector": ( - f"{_shell_arg(cli_bin)} codex-cli-runtime-idle-detector " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}" - f"{agent_arg} --idle-fixture {_shell_arg(idle_path)}" - ), - "bounded_visible_pilot_adapter": ( - f"{_shell_arg(cli_bin)} codex-cli-bounded-visible-pilot-adapter " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}" - f"{agent_arg} --first-response-fixture {_shell_arg(first_response_path)} " - f"--idle-fixture {_shell_arg(idle_path)}" - ), - "capture_plan": ( - f"{_shell_arg(cli_bin)} codex-cli-visible-first-response-capture-plan " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}" - f"{agent_arg} --first-response-path {_shell_arg(first_response_path)} " - f"--idle-path {_shell_arg(idle_path)}" - ), - } - return { - "ok": True, - "schema_version": "codex_cli_visible_first_response_capture_plan_v0", - "project": resolved_project, - "goal_id": resolved_goal_id, - "agent_id": agent_id, - "cli_bin": cli_bin, - "decision": "manual_visible_capture_plan_ready", - "start_surface": "codex_cli_tui_manual_paste", - "next_safe_step": "paste the bootstrap message into a visible Codex CLI TUI and record only public-safe fixture booleans", - "output_artifacts": { - "first_response_fixture": first_response_path, - "runtime_idle_fixture": idle_path, - }, - "capture_steps": capture_steps, - "stop_conditions": stop_conditions, - "first_response_checklist": first_response_checklist, - "runtime_idle_checklist": runtime_idle_checklist, - "sample_first_response_fixture": first_response_fixture, - "sample_runtime_idle_fixture": runtime_idle_fixture, - "commands": commands, - "adapter_decision_without_fixtures": adapter.get("decision"), - "boundary": { - "capture_plan_only": True, - "runs_codex": False, - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "reads_credentials": False, - "mutates_codex_session": False, - "writes_loopx_state": False, - "spends_loopx_quota": False, - "requires_visible_delivery": True, - "manual_paste_primary": True, - "argv_prompt_rejected": True, - "success_claim_requires_bounded_adapter": True, - }, - } - - -def build_codex_cli_bounded_visible_pilot_adapter( - *, - project: Path, - goal_id: str | None, - agent_id: str | None, - cli_bin: str, - first_response_payload: dict[str, Any] | None = None, - idle_payload: dict[str, Any] | None = None, -) -> dict[str, Any]: - """Validate the bounded evidence needed before claiming live TUI success. - - The adapter is intentionally a packet builder and fixture validator. It - does not start Codex, inspect transcripts, read session files, or capture - stdout/stderr. A separate visible/manual run must supply a public-safe - first-response fixture and a runtime-idle fixture before this packet can - approve a live-TUI first-message success claim. - """ - - bootstrap = build_codex_cli_bootstrap_message( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - ) - resolved_project = str(bootstrap["project"]) - resolved_goal_id = str(bootstrap["goal_id"]) - agent_arg = f" --agent-id {_shell_arg(agent_id)}" if agent_id else "" - required_first_response_shape = { - "observed_surface": "codex_cli_tui_visible_window | visible_paste_adapter", - "prompt_delivery": { - "manual_or_visible_delivery": True, - "prompt_public_safe": True, - "argv_prompt_used": False, - }, - "first_response": { - "goal_id_visible": True, - "user_gate_or_none_visible": True, - "top_user_todo_or_none_visible": True, - "top_agent_todo_visible": True, - "next_safe_action_visible": True, - "bounded_segment_started_or_blocker_written": True, - }, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "writeback": { - "compact_evidence_planned": True, - "quota_spend_after_writeback_only": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - "spends_quota_before_writeback": False, - }, - } - - first_response_checks: list[dict[str, Any]] = [] - first_response_failures: list[str] = [] - observed_surface = "missing" - if first_response_payload is None: - first_response_failures.append("missing_first_response_evidence") - else: - observed_surface = str(first_response_payload.get("observed_surface") or "unknown") - for key, path, description in FIRST_RESPONSE_REQUIRED_TRUE_CHECKS: - passed = _nested_bool(first_response_payload, path) - first_response_checks.append( - {"key": key, "required": True, "passed": passed, "description": description} - ) - if not passed: - first_response_failures.append(key) - for key, path, description in FIRST_RESPONSE_REQUIRED_FALSE_CHECKS: - passed = _nested_false(first_response_payload, path) - first_response_checks.append( - {"key": key, "required": False, "passed": passed, "description": description} - ) - if not passed: - first_response_failures.append(key) - supported_surface = observed_surface in { - "codex_cli_tui_visible_window", - "visible_paste_adapter", - } - first_response_checks.append( - { - "key": "supported_observed_surface", - "required": sorted(["codex_cli_tui_visible_window", "visible_paste_adapter"]), - "actual": observed_surface, - "passed": supported_surface, - "description": "first response was observed on a visible Codex CLI surface", - } - ) - if not supported_surface: - first_response_failures.append("unsupported_observed_surface") - if _nested_bool(first_response_payload, ("prompt_delivery", "argv_prompt_used")): - first_response_failures.append("argv_prompt_leakage_risk") - - idle_detector = build_codex_cli_runtime_idle_detector( - project=project, - goal_id=resolved_goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - idle_payload=idle_payload, - ) - idle_approved = idle_detector.get("approved_for_visible_later_turn") is True - first_response_approved = bool(first_response_payload is not None and not first_response_failures) - blockers: list[str] = [] - blockers.extend(first_response_failures) - if not idle_approved: - blockers.extend(idle_detector.get("failures") or ["runtime_idle_evidence_required"]) - - if first_response_approved and idle_approved: - decision = "bounded_visible_pilot_ready_for_success_claim" - approved = True - next_safe_step = ( - "write compact success evidence, refresh state with outcome_progress, " - "then spend exactly one quota slot" - ) - elif first_response_payload is None: - decision = "bounded_visible_completion_evidence_required" - approved = False - next_safe_step = ( - "capture the first visible TUI response as the public-safe fixture shape " - "below, then rerun this adapter before spending quota" - ) - elif not first_response_approved: - decision = "bounded_visible_first_response_incomplete" - approved = False - next_safe_step = ( - "treat the live TUI pilot as blocked and write the precise blocker; " - "do not claim first-message success" - ) - else: - decision = "bounded_visible_runtime_idle_required" - approved = False - next_safe_step = ( - "capture runtime idle evidence proving no active typing or running turn " - "before marking the visible pilot complete" - ) - - bounded_adapter_command = ( - f"{_shell_arg(cli_bin)} codex-cli-bounded-visible-pilot-adapter " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}" - f"{agent_arg} --first-response-fixture " - "--idle-fixture " - ) - runtime_idle_command = ( - f"{_shell_arg(cli_bin)} codex-cli-runtime-idle-detector " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}" - f"{agent_arg} --idle-fixture " - ) - blocker_summary = blockers[0] if blockers else "none" - blocker_writeback = ( - f"{_shell_arg(cli_bin)} refresh-state --goal-id {_shell_arg(resolved_goal_id)} " - "--classification codex_cli_bounded_visible_pilot_blocker " - "--delivery-batch-scale implementation --delivery-outcome outcome_gap " - f"--recommended-action {_shell_arg('Codex CLI bounded visible pilot blocked: ' + blocker_summary)}" - ) - success_writeback = ( - f"{_shell_arg(cli_bin)} refresh-state --goal-id {_shell_arg(resolved_goal_id)} " - "--classification codex_cli_bounded_visible_pilot_success " - "--delivery-batch-scale implementation --delivery-outcome outcome_progress " - "--recommended-action " - f"{_shell_arg('Promote Codex CLI one-message TUI bootstrap only after documented release-path validation.')}" - ) - - return { - "ok": True, - "schema_version": "codex_cli_bounded_visible_pilot_adapter_v0", - "project": resolved_project, - "goal_id": resolved_goal_id, - "agent_id": agent_id, - "cli_bin": cli_bin, - "decision": decision, - "approved_for_live_tui_success_claim": approved, - "observed_surface": observed_surface, - "next_safe_step": next_safe_step, - "blockers": blockers, - "first_response": { - "supplied": first_response_payload is not None, - "approved": first_response_approved, - "checks": first_response_checks, - "failures": first_response_failures, - }, - "runtime_idle_detector": { - "supplied": idle_payload is not None, - "approved": idle_approved, - "decision": idle_detector.get("decision"), - "failures": idle_detector.get("failures") or [], - "source": idle_detector.get("source"), - }, - "commands": { - "bootstrap_message": ( - f"{_shell_arg(cli_bin)} codex-cli-bootstrap-message " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}" - f"{agent_arg} --message-only" - ), - "bounded_visible_pilot_adapter": bounded_adapter_command, - "runtime_idle_detector": runtime_idle_command, - "blocker_writeback": blocker_writeback, - "success_writeback": success_writeback, - }, - "required_first_response_shape": required_first_response_shape, - "required_runtime_idle_shape": idle_detector.get("required_fixture_shape"), - "boundary": { - "adapter_packet_only": True, - "runs_codex": False, - "reads_raw_transcripts": False, - "reads_credentials": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "mutates_codex_session": False, - "writes_loopx_state": False, - "spends_loopx_quota": False, - "requires_visible_delivery": True, - "argv_prompt_rejected": True, - "success_claim_requires_first_response_and_idle": True, - }, - } diff --git a/loopx/codex_cli_probe_markdown.py b/loopx/codex_cli_probe_markdown.py deleted file mode 100644 index 07d0492bd3..0000000000 --- a/loopx/codex_cli_probe_markdown.py +++ /dev/null @@ -1,937 +0,0 @@ -from __future__ import annotations - -import json -from typing import Any - - -def render_codex_cli_session_probe_markdown(payload: dict[str, Any]) -> str: - capabilities = payload.get("capabilities") or {} - boundary = payload.get("boundary") or {} - warnings = payload.get("warnings") or [] - warning_lines = "\n".join(f"- {warning}" for warning in warnings) if warnings else "- none" - return f"""# Codex CLI Session Probe - -- source: `{payload.get("source")}` -- recommended_mode: `{payload.get("recommended_mode")}` -- automation_action: `{payload.get("automation_action")}` - -## Capabilities - -- exec_supported: `{capabilities.get("exec_supported")}` -- resume_supported: `{capabilities.get("resume_supported")}` -- session_handle_detected: `{capabilities.get("session_handle_detected")}` -- visible_resume_supported: `{capabilities.get("visible_resume_supported")}` -- remote_control_surface_detected: `{capabilities.get("remote_control_surface_detected")}` -- same_tui_injection_detected: `{capabilities.get("same_tui_injection_detected")}` -- safe_injection_supported: `{capabilities.get("safe_injection_supported")}` - -## Boundary - -- help_only_probe: `{boundary.get("help_only_probe")}` -- reads_raw_transcripts: `{boundary.get("reads_raw_transcripts")}` -- reads_credentials: `{boundary.get("reads_credentials")}` -- reads_session_files: `{boundary.get("reads_session_files")}` -- mutates_codex_session: `{boundary.get("mutates_codex_session")}` -- spends_loopx_quota: `{boundary.get("spends_loopx_quota")}` - -## Warnings - -{warning_lines} -""" - - - -def render_codex_cli_visible_driver_plan_markdown(payload: dict[str, Any]) -> str: - boundary = payload.get("boundary") if isinstance(payload.get("boundary"), dict) else {} - commands = payload.get("commands") if isinstance(payload.get("commands"), dict) else {} - steps = payload.get("driver_steps") if isinstance(payload.get("driver_steps"), list) else [] - warnings = payload.get("warnings") if isinstance(payload.get("warnings"), list) else [] - step_lines = "\n".join(f"{index}. {step}" for index, step in enumerate(steps, start=1)) - warning_lines = "\n".join(f"- {warning}" for warning in warnings) if warnings else "- none" - headless_line = commands.get("explicit_headless_fallback") or ( - f"# {commands.get('headless_fallback_disabled') or 'headless fallback disabled'}" - ) - return f"""# Codex CLI Visible Driver Plan - -- driver_mode: `{payload.get("driver_mode")}` -- automation_action: `{payload.get("automation_action")}` -- probe_recommended_mode: `{payload.get("probe_recommended_mode")}` -- next_step: {payload.get("next_step")} - -## Commands - -```bash -{commands.get("probe")} -{commands.get("quota_guard")} -{commands.get("tui_bootstrap_message")} -{headless_line} -``` - -## Driver Steps - -{step_lines} - -## Boundary - -- dry_run_plan_only: `{boundary.get("dry_run_plan_only")}` -- reads_raw_transcripts: `{boundary.get("reads_raw_transcripts")}` -- reads_session_files: `{boundary.get("reads_session_files")}` -- mutates_codex_session: `{boundary.get("mutates_codex_session")}` -- spends_loopx_quota: `{boundary.get("spends_loopx_quota")}` -- requires_idle_guard_before_visible_prompt: `{boundary.get("requires_idle_guard_before_visible_prompt")}` -- requires_user_gate_stop: `{boundary.get("requires_user_gate_stop")}` - -## Warnings - -{warning_lines} -""" - - - -def render_codex_cli_local_driver_plan_markdown(payload: dict[str, Any]) -> str: - boundary = payload.get("boundary") if isinstance(payload.get("boundary"), dict) else {} - commands = payload.get("commands") if isinstance(payload.get("commands"), dict) else {} - steps = payload.get("driver_steps") if isinstance(payload.get("driver_steps"), list) else [] - idle_guard = payload.get("idle_guard") if isinstance(payload.get("idle_guard"), dict) else {} - policy = payload.get("execution_policy") if isinstance(payload.get("execution_policy"), dict) else {} - warnings = payload.get("warnings") if isinstance(payload.get("warnings"), list) else [] - step_lines = "\n".join(f"{index}. {step}" for index, step in enumerate(steps, start=1)) - warning_lines = "\n".join(f"- {warning}" for warning in warnings) if warnings else "- none" - headless_line = commands.get("explicit_headless_fallback") or ( - f"# {commands.get('headless_fallback_disabled') or 'headless fallback disabled'}" - ) - return f"""# Codex CLI Local Driver Plan - -- driver_phase: `{payload.get("driver_phase")}` -- driver_mode: `{payload.get("driver_mode")}` -- decision: `{payload.get("decision")}` -- operator_instruction: {payload.get("operator_instruction")} - -## Commands - -```bash -{commands.get("quota_guard")} -{commands.get("visible_driver_plan")} -{commands.get("tui_bootstrap_message")} -{headless_line} -``` - -## Driver Steps - -{step_lines} - -## Idle Guard - -- required: `{idle_guard.get("required")}` -- implemented: `{idle_guard.get("implemented")}` -- placeholder: {idle_guard.get("placeholder")} - -## Execution Policy - -- tui_bootstrap_primary: `{policy.get("tui_bootstrap_primary")}` -- headless_execution_disabled: `{policy.get("headless_execution_disabled")}` -- same_session_attachment_requires_visible_proof: `{policy.get("same_session_attachment_requires_visible_proof")}` -- quota_guard_required: `{policy.get("quota_guard_required")}` -- spend_after_validated_writeback_only: `{policy.get("spend_after_validated_writeback_only")}` - -## Boundary - -- dry_run_plan_only: `{boundary.get("dry_run_plan_only")}` -- runs_codex: `{boundary.get("runs_codex")}` -- reads_raw_transcripts: `{boundary.get("reads_raw_transcripts")}` -- reads_session_files: `{boundary.get("reads_session_files")}` -- mutates_codex_session: `{boundary.get("mutates_codex_session")}` -- spends_loopx_quota: `{boundary.get("spends_loopx_quota")}` - -## Warnings - -{warning_lines} -""" - - - -def render_codex_cli_visible_driver_run_packet_markdown(payload: dict[str, Any]) -> str: - boundary = payload.get("boundary") if isinstance(payload.get("boundary"), dict) else {} - commands = payload.get("commands") if isinstance(payload.get("commands"), dict) else {} - steps = payload.get("driver_steps") if isinstance(payload.get("driver_steps"), list) else [] - proof = payload.get("visible_session_proof") if isinstance(payload.get("visible_session_proof"), dict) else {} - policy = payload.get("execution_policy") if isinstance(payload.get("execution_policy"), dict) else {} - warnings = payload.get("warnings") if isinstance(payload.get("warnings"), list) else [] - step_lines = "\n".join(f"{index}. {step}" for index, step in enumerate(steps, start=1)) - warning_lines = "\n".join(f"- {warning}" for warning in warnings) if warnings else "- none" - headless_line = commands.get("explicit_headless_fallback") or ( - f"# {commands.get('headless_fallback_disabled') or 'headless fallback disabled'}" - ) - return f"""# Codex CLI Visible Driver Run Packet - -- driver_phase: `{payload.get("driver_phase")}` -- driver_mode: `{payload.get("driver_mode")}` -- decision: `{payload.get("decision")}` -- next_driver_action: `{payload.get("next_driver_action")}` -- allow_headless_fallback: `{payload.get("allow_headless_fallback")}` - -## Recommended Command - -```bash -{payload.get("recommended_command")} -``` - -## Commands - -```bash -{commands.get("quota_guard")} -{commands.get("tui_bootstrap_message")} -{commands.get("visible_session_proof")} -{headless_line} -``` - -## Visible Session Proof - -- supplied: `{proof.get("supplied")}` -- approved: `{proof.get("approved")}` -- decision: `{proof.get("decision")}` -- failures: `{proof.get("failures")}` - -## Driver Steps - -{step_lines} - -## Execution Policy - -- tui_bootstrap_primary: `{policy.get("tui_bootstrap_primary")}` -- same_session_attachment_requires_visible_proof: `{policy.get("same_session_attachment_requires_visible_proof")}` -- headless_execution_disabled: `{policy.get("headless_execution_disabled")}` -- quota_guard_required: `{policy.get("quota_guard_required")}` -- idle_guard_required_before_visible_prompt: `{policy.get("idle_guard_required_before_visible_prompt")}` -- spend_after_validated_writeback_only: `{policy.get("spend_after_validated_writeback_only")}` - -## Boundary - -- run_packet_only: `{boundary.get("run_packet_only")}` -- runs_codex: `{boundary.get("runs_codex")}` -- reads_raw_transcripts: `{boundary.get("reads_raw_transcripts")}` -- reads_session_files: `{boundary.get("reads_session_files")}` -- mutates_codex_session: `{boundary.get("mutates_codex_session")}` -- spends_loopx_quota: `{boundary.get("spends_loopx_quota")}` -- headless_execution_disabled: `{boundary.get("headless_execution_disabled")}` - -## Warnings - -{warning_lines} -""" - - - -def render_codex_cli_local_scheduler_tick_markdown(payload: dict[str, Any]) -> str: - boundary = payload.get("boundary") if isinstance(payload.get("boundary"), dict) else {} - commands = payload.get("commands") if isinstance(payload.get("commands"), dict) else {} - launchd = payload.get("launchd") if isinstance(payload.get("launchd"), dict) else {} - scheduler_hint = ( - payload.get("scheduler_hint") - if isinstance(payload.get("scheduler_hint"), dict) - else {} - ) - local_scheduler = ( - scheduler_hint.get("local_scheduler") - if isinstance(scheduler_hint.get("local_scheduler"), dict) - else {} - ) - codex_app = ( - scheduler_hint.get("app_automation") - if isinstance(scheduler_hint.get("app_automation"), dict) - else scheduler_hint.get("codex_app") - if isinstance(scheduler_hint.get("codex_app"), dict) - else {} - ) - unchanged_poll = ( - scheduler_hint.get("unchanged_poll") - if isinstance(scheduler_hint.get("unchanged_poll"), dict) - else {} - ) - limits = unchanged_poll.get("limits") if isinstance(unchanged_poll.get("limits"), dict) else {} - after_limits = ( - unchanged_poll.get("after_limits") - if isinstance(unchanged_poll.get("after_limits"), dict) - else {} - ) - local_interval = ( - local_scheduler.get("recommended_interval_minutes") - or codex_app.get("recommended_interval_minutes") - ) - local_progression = ( - local_scheduler.get("example_progression_minutes") - or codex_app.get("example_progression_minutes") - ) - local_unchanged_limit = ( - local_scheduler.get("unchanged_poll_limit") - if "unchanged_poll_limit" in local_scheduler - else limits.get("local_scheduler") - ) - local_after_limit = ( - local_scheduler.get("after_limit") - or after_limits.get("local_scheduler") - ) - final_replan_check = ( - local_scheduler.get("final_quota_replan_check") - or { - "enabled": unchanged_poll.get("final_quota_replan_check_enabled"), - "action": unchanged_poll.get("final_quota_replan_check_action"), - } - ) - blocker = payload.get("precise_blocker") if isinstance(payload.get("precise_blocker"), dict) else None - runtime_idle = ( - payload.get("runtime_idle_detector") - if isinstance(payload.get("runtime_idle_detector"), dict) - else {} - ) - warnings = payload.get("warnings") if isinstance(payload.get("warnings"), list) else [] - warning_lines = "\n".join(f"- {warning}" for warning in warnings) if warnings else "- none" - blocker_lines = "- none" - if blocker: - blocker_lines = f"- reason: `{blocker.get('reason')}`\n- message: {blocker.get('message')}" - return f"""# Codex CLI Local Scheduler Tick - -- scheduler_phase: `{payload.get("scheduler_phase")}` -- scheduler_action: `{payload.get("scheduler_action")}` -- decision: `{payload.get("decision")}` -- next_safe_step: {payload.get("next_safe_step")} - -## Commands - -```bash -{commands.get("visible_driver_run")} -{commands.get("runtime_idle_detector")} -{commands.get("runtime_idle_detector_fixture")} -{commands.get("scheduler_tick")} -{commands.get("candidate_codex_command") or "# no Codex command candidate"} -{commands.get("blocker_writeback") or "# no blocker writeback command"} -``` - -## Precise Blocker - -{blocker_lines} - -## Runtime Idle Detector - -- supplied: `{runtime_idle.get("supplied")}` -- approved: `{runtime_idle.get("approved")}` -- decision: `{runtime_idle.get("decision")}` -- failures: `{runtime_idle.get("failures")}` - -## Launchd Shape - -- label: `{launchd.get("label")}` -- keep_alive: `{launchd.get("keep_alive")}` -- recommended_interval_seconds: `{launchd.get("recommended_interval_seconds")}` -- one_shot_command: `{launchd.get("one_shot_command")}` - -## Scheduler Hint - -- action: `{scheduler_hint.get("action")}` -- cadence_class: `{scheduler_hint.get("cadence_class")}` -- local_interval_minutes: `{local_interval}` -- local_progression_minutes: `{local_progression}` -- local_unchanged_poll_limit: `{local_unchanged_limit}` -- local_after_limit: `{local_after_limit}` -- final_quota_replan_check: `{final_replan_check}` - -## Boundary - -- tick_packet_only: `{boundary.get("tick_packet_only")}` -- runs_codex: `{boundary.get("runs_codex")}` -- reads_raw_transcripts: `{boundary.get("reads_raw_transcripts")}` -- reads_session_files: `{boundary.get("reads_session_files")}` -- mutates_codex_session: `{boundary.get("mutates_codex_session")}` -- spends_loopx_quota: `{boundary.get("spends_loopx_quota")}` -- writes_loopx_state: `{boundary.get("writes_loopx_state")}` -- visible_candidate_requires_runtime_idle_detector: `{boundary.get("visible_candidate_requires_runtime_idle_detector")}` -- headless_execution_disabled: `{boundary.get("headless_execution_disabled")}` - -## Warnings - -{warning_lines} -""" - - - -def render_codex_cli_local_scheduler_executor_markdown(payload: dict[str, Any]) -> str: - boundary = payload.get("boundary") if isinstance(payload.get("boundary"), dict) else {} - commands = payload.get("commands") if isinstance(payload.get("commands"), dict) else {} - execution = payload.get("execution") if isinstance(payload.get("execution"), dict) else {} - request = payload.get("execution_request") if isinstance(payload.get("execution_request"), dict) else {} - scheduler_tick = payload.get("scheduler_tick") if isinstance(payload.get("scheduler_tick"), dict) else {} - runtime_idle = ( - scheduler_tick.get("runtime_idle_detector") - if isinstance(scheduler_tick.get("runtime_idle_detector"), dict) - else {} - ) - warnings = payload.get("warnings") if isinstance(payload.get("warnings"), list) else [] - warning_lines = "\n".join(f"- {warning}" for warning in warnings) if warnings else "- none" - return f"""# Codex CLI Local Scheduler Executor - -- executor_phase: `{payload.get("executor_phase")}` -- scheduler_action: `{payload.get("scheduler_action")}` -- decision: `{payload.get("decision")}` -- next_safe_step: {payload.get("next_safe_step")} - -## Execution Request - -- execute_candidate: `{request.get("execute_candidate")}` -- execute_blocker_writeback: `{request.get("execute_blocker_writeback")}` -- guard_checked: `{request.get("guard_checked")}` -- candidate_command_prefixes: `{request.get("candidate_command_prefixes")}` -- executor_timeout_seconds: `{request.get("executor_timeout_seconds")}` -- runtime_idle_detector_required_for_visible_candidate: `{request.get("runtime_idle_detector_required_for_visible_candidate")}` - -## Execution Result - -- attempted: `{execution.get("attempted")}` -- executed: `{execution.get("executed")}` -- kind: `{execution.get("kind")}` -- reason: `{execution.get("reason")}` -- returncode: `{execution.get("returncode")}` -- timed_out: `{execution.get("timed_out")}` -- output_captured: `{execution.get("output_captured")}` -- candidate_prefix_matched: `{execution.get("candidate_prefix_matched")}` - -## Runtime Idle Detector - -- supplied: `{runtime_idle.get("supplied")}` -- approved: `{runtime_idle.get("approved")}` -- decision: `{runtime_idle.get("decision")}` -- failures: `{runtime_idle.get("failures")}` - -## Commands - -```bash -{commands.get("scheduler_tick")} -{commands.get("candidate_command") or "# no candidate command"} -{commands.get("blocker_writeback") or "# no blocker writeback command"} -``` - -## Boundary - -- executor_wrapper: `{boundary.get("executor_wrapper")}` -- requires_explicit_execute_flag: `{boundary.get("requires_explicit_execute_flag")}` -- requires_fresh_quota_guard_confirmation: `{boundary.get("requires_fresh_quota_guard_confirmation")}` -- candidate_prefix_required: `{boundary.get("candidate_prefix_required")}` -- runtime_idle_detector_required_for_visible_candidate: `{boundary.get("runtime_idle_detector_required_for_visible_candidate")}` -- runs_external_candidate: `{boundary.get("runs_external_candidate")}` -- reads_raw_transcripts: `{boundary.get("reads_raw_transcripts")}` -- reads_session_files: `{boundary.get("reads_session_files")}` -- mutates_codex_session: `{boundary.get("mutates_codex_session")}` -- candidate_output_captured: `{boundary.get("candidate_output_captured")}` -- blocker_output_captured: `{boundary.get("blocker_output_captured")}` -- spends_loopx_quota: `{boundary.get("spends_loopx_quota")}` -- writes_loopx_state: `{boundary.get("writes_loopx_state")}` - -## Warnings - -{warning_lines} -""" - - - -def render_codex_cli_one_message_loop_pilot_markdown(payload: dict[str, Any]) -> str: - boundary = payload.get("boundary") if isinstance(payload.get("boundary"), dict) else {} - commands = payload.get("commands") if isinstance(payload.get("commands"), dict) else {} - first_turn = payload.get("first_turn") if isinstance(payload.get("first_turn"), dict) else {} - bridge = payload.get("automation_bridge") if isinstance(payload.get("automation_bridge"), dict) else {} - snapshot_required = first_turn.get("snapshot_required") if isinstance(first_turn.get("snapshot_required"), list) else [] - snapshot_lines = "\n".join(f"- {item}" for item in snapshot_required) - warnings = payload.get("warnings") if isinstance(payload.get("warnings"), list) else [] - warning_lines = "\n".join(f"- {warning}" for warning in warnings) if warnings else "- none" - return f"""# Codex CLI One-Message Loop Pilot - -- start_surface: `{payload.get("start_surface")}` -- pilot_decision: `{payload.get("pilot_decision")}` -- followup_mode: {payload.get("followup_mode")} - -## First TUI Turn - -- user_action: `{first_turn.get("user_action")}` -- preserve_tui: `{first_turn.get("preserve_tui")}` - -The first response should show: - -{snapshot_lines} - -````text -{first_turn.get("message") or ""} -```` - -## Automation Bridge - -- command: `{bridge.get("command")}` -- default_executes: `{bridge.get("default_executes")}` -- scheduler_action: `{bridge.get("scheduler_action")}` -- executor_reason: `{bridge.get("executor_reason")}` -- followup_mode: {bridge.get("followup_mode")} - -## Commands - -```bash -{commands.get("bootstrap_message")} -{commands.get("scheduler_exec_dry_run")} -{commands.get("scheduler_exec_candidate_template")} -{commands.get("scheduler_exec_blocker_template")} -``` - -## Boundary - -- pilot_packet_only: `{boundary.get("pilot_packet_only")}` -- runs_codex: `{boundary.get("runs_codex")}` -- runs_scheduler_result: `{boundary.get("runs_scheduler_result")}` -- reads_raw_transcripts: `{boundary.get("reads_raw_transcripts")}` -- reads_session_files: `{boundary.get("reads_session_files")}` -- mutates_codex_session: `{boundary.get("mutates_codex_session")}` -- spends_loopx_quota: `{boundary.get("spends_loopx_quota")}` -- requires_user_visible_start: `{boundary.get("requires_user_visible_start")}` -- headless_execution_disabled: `{boundary.get("headless_execution_disabled")}` -- candidate_execution_requires_guard_and_prefix: `{boundary.get("candidate_execution_requires_guard_and_prefix")}` - -## Warnings - -{warning_lines} -""" - - - -def render_codex_cli_visible_local_driver_pilot_markdown(payload: dict[str, Any]) -> str: - boundary = payload.get("boundary") if isinstance(payload.get("boundary"), dict) else {} - commands = payload.get("commands") if isinstance(payload.get("commands"), dict) else {} - proof = payload.get("visible_session_proof") if isinstance(payload.get("visible_session_proof"), dict) else {} - runtime_idle = ( - payload.get("runtime_idle_detector") - if isinstance(payload.get("runtime_idle_detector"), dict) - else {} - ) - idle_guard = payload.get("idle_guard_contract") if isinstance(payload.get("idle_guard_contract"), dict) else {} - scheduler = payload.get("scheduler_executor") if isinstance(payload.get("scheduler_executor"), dict) else {} - policy = payload.get("execution_policy") if isinstance(payload.get("execution_policy"), dict) else {} - steps = payload.get("visible_loop_steps") if isinstance(payload.get("visible_loop_steps"), list) else [] - warnings = payload.get("warnings") if isinstance(payload.get("warnings"), list) else [] - step_lines = "\n".join(f"{index}. {step}" for index, step in enumerate(steps, start=1)) - fixture_keys = idle_guard.get("fixture_keys") if isinstance(idle_guard.get("fixture_keys"), list) else [] - fixture_key_lines = "\n".join(f"- {key}" for key in fixture_keys) - warning_lines = "\n".join(f"- {warning}" for warning in warnings) if warnings else "- none" - return f"""# Codex CLI Visible Local Driver Pilot - -- pilot_phase: `{payload.get("pilot_phase")}` -- start_surface: `{payload.get("start_surface")}` -- loop_decision: `{payload.get("loop_decision")}` -- next_driver_action: `{payload.get("next_driver_action")}` - -## Scheduler Executor - -- scheduler_action: `{scheduler.get("scheduler_action")}` -- decision: `{scheduler.get("decision")}` -- executor_reason: `{scheduler.get("executor_reason")}` -- executed: `{scheduler.get("executed")}` - -## Visible Session Proof - -- supplied: `{proof.get("supplied")}` -- approved: `{proof.get("approved")}` -- decision: `{proof.get("decision")}` -- failures: `{proof.get("failures")}` - -## Runtime Idle Detector - -- supplied: `{runtime_idle.get("supplied")}` -- approved: `{runtime_idle.get("approved")}` -- decision: `{runtime_idle.get("decision")}` -- failures: `{runtime_idle.get("failures")}` - -## Idle Guard Contract - -- required_before_visible_prompt: `{idle_guard.get("required_before_visible_prompt")}` -- current_pilot_implements_runtime_idle_detection: `{idle_guard.get("current_pilot_implements_runtime_idle_detection")}` -- fixture_backed_runtime_idle_detector: `{idle_guard.get("fixture_backed_runtime_idle_detector")}` -- runtime_sensor_implemented: `{idle_guard.get("runtime_sensor_implemented")}` -- public_safe_fixture_supported: `{idle_guard.get("public_safe_fixture_supported")}` -- local_observation_adapter_supported: `{idle_guard.get("local_observation_adapter_supported")}` -- no_private_state_observation: `{idle_guard.get("no_private_state_observation")}` - -{fixture_key_lines} - -## Visible Loop Steps - -{step_lines} - -## Commands - -```bash -{commands.get("bootstrap_message")} -{commands.get("scheduler_exec_dry_run")} -{commands.get("scheduler_exec_candidate_template")} -{commands.get("scheduler_exec_blocker_template")} -{commands.get("runtime_idle_detector")} -{commands.get("runtime_idle_detector_fixture")} -``` - -## Execution Policy - -- tui_bootstrap_primary: `{policy.get("tui_bootstrap_primary")}` -- later_turns_visible_to_user: `{policy.get("later_turns_visible_to_user")}` -- user_can_interrupt_or_take_over: `{policy.get("user_can_interrupt_or_take_over")}` -- same_session_attachment_requires_visible_proof: `{policy.get("same_session_attachment_requires_visible_proof")}` -- headless_execution_disabled: `{policy.get("headless_execution_disabled")}` -- quota_guard_required_each_tick: `{policy.get("quota_guard_required_each_tick")}` -- spend_after_validated_writeback_only: `{policy.get("spend_after_validated_writeback_only")}` - -## Boundary - -- pilot_packet_only: `{boundary.get("pilot_packet_only")}` -- runs_codex: `{boundary.get("runs_codex")}` -- runs_scheduler_result: `{boundary.get("runs_scheduler_result")}` -- reads_raw_transcripts: `{boundary.get("reads_raw_transcripts")}` -- reads_session_files: `{boundary.get("reads_session_files")}` -- reads_stdout_stderr: `{boundary.get("reads_stdout_stderr")}` -- mutates_codex_session: `{boundary.get("mutates_codex_session")}` -- writes_loopx_state: `{boundary.get("writes_loopx_state")}` -- spends_loopx_quota: `{boundary.get("spends_loopx_quota")}` -- candidate_execution_requires_guard_and_prefix: `{boundary.get("candidate_execution_requires_guard_and_prefix")}` -- blocker_writeback_requires_guard_checked: `{boundary.get("blocker_writeback_requires_guard_checked")}` -- headless_execution_disabled: `{boundary.get("headless_execution_disabled")}` - -## Warnings - -{warning_lines} -""" - - - -def render_codex_cli_bounded_visible_pilot_adapter_markdown(payload: dict[str, Any]) -> str: - boundary = payload.get("boundary") if isinstance(payload.get("boundary"), dict) else {} - commands = payload.get("commands") if isinstance(payload.get("commands"), dict) else {} - first_response = ( - payload.get("first_response") - if isinstance(payload.get("first_response"), dict) - else {} - ) - runtime_idle = ( - payload.get("runtime_idle_detector") - if isinstance(payload.get("runtime_idle_detector"), dict) - else {} - ) - blockers = payload.get("blockers") if isinstance(payload.get("blockers"), list) else [] - blocker_lines = "\n".join(f"- {blocker}" for blocker in blockers) if blockers else "- none" - checks = first_response.get("checks") if isinstance(first_response.get("checks"), list) else [] - check_lines = "\n".join( - f"- [{'x' if check.get('passed') else ' '}] {check.get('key')}: {check.get('description')}" - for check in checks - if isinstance(check, dict) - ) - if not check_lines: - check_lines = "- no first-response fixture supplied" - required_first_response_shape = payload.get("required_first_response_shape") - required_runtime_idle_shape = payload.get("required_runtime_idle_shape") - required_shapes = "" - if isinstance(required_first_response_shape, dict): - required_shapes += f""" -## Required First-Response Fixture - -```json -{json.dumps(required_first_response_shape, indent=2, ensure_ascii=False)} -``` -""" - if isinstance(required_runtime_idle_shape, dict): - required_shapes += f""" -## Required Runtime Idle Fixture - -```json -{json.dumps(required_runtime_idle_shape, indent=2, ensure_ascii=False)} -``` -""" - return f"""# Codex CLI Bounded Visible Pilot Adapter - -- decision: `{payload.get("decision")}` -- approved_for_live_tui_success_claim: `{payload.get("approved_for_live_tui_success_claim")}` -- observed_surface: `{payload.get("observed_surface")}` -- next_safe_step: {payload.get("next_safe_step")} - -## First Response - -- supplied: `{first_response.get("supplied")}` -- approved: `{first_response.get("approved")}` - -{check_lines} - -## Runtime Idle Detector - -- supplied: `{runtime_idle.get("supplied")}` -- approved: `{runtime_idle.get("approved")}` -- decision: `{runtime_idle.get("decision")}` -- failures: `{runtime_idle.get("failures")}` - -## Blockers - -{blocker_lines} - -## Commands - -```bash -{commands.get("bootstrap_message")} -{commands.get("bounded_visible_pilot_adapter")} -{commands.get("runtime_idle_detector")} -{commands.get("blocker_writeback")} -{commands.get("success_writeback")} -``` - -## Boundary - -- adapter_packet_only: `{boundary.get("adapter_packet_only")}` -- runs_codex: `{boundary.get("runs_codex")}` -- reads_raw_transcripts: `{boundary.get("reads_raw_transcripts")}` -- reads_session_files: `{boundary.get("reads_session_files")}` -- reads_stdout_stderr: `{boundary.get("reads_stdout_stderr")}` -- mutates_codex_session: `{boundary.get("mutates_codex_session")}` -- writes_loopx_state: `{boundary.get("writes_loopx_state")}` -- spends_loopx_quota: `{boundary.get("spends_loopx_quota")}` -- requires_visible_delivery: `{boundary.get("requires_visible_delivery")}` -- argv_prompt_rejected: `{boundary.get("argv_prompt_rejected")}` -- success_claim_requires_first_response_and_idle: `{boundary.get("success_claim_requires_first_response_and_idle")}` -{required_shapes} -""" - - - -def render_codex_cli_visible_first_response_capture_plan_markdown( - payload: dict[str, Any], -) -> str: - boundary = payload.get("boundary") if isinstance(payload.get("boundary"), dict) else {} - commands = payload.get("commands") if isinstance(payload.get("commands"), dict) else {} - artifacts = ( - payload.get("output_artifacts") - if isinstance(payload.get("output_artifacts"), dict) - else {} - ) - steps = payload.get("capture_steps") if isinstance(payload.get("capture_steps"), list) else [] - stops = payload.get("stop_conditions") if isinstance(payload.get("stop_conditions"), list) else [] - first_response_fixture = payload.get("sample_first_response_fixture") - runtime_idle_fixture = payload.get("sample_runtime_idle_fixture") - step_lines = "\n".join(f"{index}. {step}" for index, step in enumerate(steps, start=1)) - stop_lines = "\n".join(f"- {stop}" for stop in stops) if stops else "- none" - return f"""# Codex CLI Visible First-Response Capture Plan - -- decision: `{payload.get("decision")}` -- start_surface: `{payload.get("start_surface")}` -- first_response_fixture: `{artifacts.get("first_response_fixture")}` -- runtime_idle_fixture: `{artifacts.get("runtime_idle_fixture")}` -- next_safe_step: {payload.get("next_safe_step")} - -## Commands - -```bash -{commands.get("quota_guard")} -{commands.get("bootstrap_message")} -{commands.get("bounded_visible_pilot_adapter")} -{commands.get("runtime_idle_detector")} -``` - -## Capture Steps - -{step_lines} - -## Stop Conditions - -{stop_lines} - -## Sample First-Response Fixture - -```json -{json.dumps(first_response_fixture, indent=2, ensure_ascii=False)} -``` - -## Sample Runtime Idle Fixture - -```json -{json.dumps(runtime_idle_fixture, indent=2, ensure_ascii=False)} -``` - -## Boundary - -- capture_plan_only: `{boundary.get("capture_plan_only")}` -- runs_codex: `{boundary.get("runs_codex")}` -- reads_raw_transcripts: `{boundary.get("reads_raw_transcripts")}` -- reads_session_files: `{boundary.get("reads_session_files")}` -- reads_stdout_stderr: `{boundary.get("reads_stdout_stderr")}` -- mutates_codex_session: `{boundary.get("mutates_codex_session")}` -- writes_loopx_state: `{boundary.get("writes_loopx_state")}` -- spends_loopx_quota: `{boundary.get("spends_loopx_quota")}` -- manual_paste_primary: `{boundary.get("manual_paste_primary")}` -- argv_prompt_rejected: `{boundary.get("argv_prompt_rejected")}` -- success_claim_requires_bounded_adapter: `{boundary.get("success_claim_requires_bounded_adapter")}` -""" - - - -def render_codex_cli_runtime_idle_detector_markdown(payload: dict[str, Any]) -> str: - boundary = payload.get("boundary") if isinstance(payload.get("boundary"), dict) else {} - checks = payload.get("checks") if isinstance(payload.get("checks"), list) else [] - failures = payload.get("failures") if isinstance(payload.get("failures"), list) else [] - required_shape = payload.get("required_fixture_shape") - check_lines = "\n".join( - f"- [{'x' if check.get('passed') else ' '}] {check.get('key')}: {check.get('description')}" - for check in checks - if isinstance(check, dict) - ) - if not check_lines: - check_lines = "- no runtime idle evidence supplied" - failure_lines = "\n".join(f"- {failure}" for failure in failures) if failures else "- none" - required_shape_block = "" - if isinstance(required_shape, dict): - required_shape_block = f""" -## Required Evidence Shape - -```json -{json.dumps(required_shape, indent=2, ensure_ascii=False)} -``` -""" - return f"""# Codex CLI Runtime Idle Detector - -- decision: `{payload.get("decision")}` -- approved_for_visible_later_turn: `{payload.get("approved_for_visible_later_turn")}` -- source: `{payload.get("source")}` -- observed_surface: `{payload.get("observed_surface")}` -- recommended_action: {payload.get("recommended_action")} - -## Checks - -{check_lines} - -## Failures - -{failure_lines} - -## Boundary - -- fixture_only: `{boundary.get("fixture_only")}` -- public_safe_fixture_supported: `{boundary.get("public_safe_fixture_supported")}` -- local_observation_adapter_supported: `{boundary.get("local_observation_adapter_supported")}` -- runs_codex: `{boundary.get("runs_codex")}` -- reads_raw_transcripts: `{boundary.get("reads_raw_transcripts")}` -- reads_session_files: `{boundary.get("reads_session_files")}` -- reads_stdout_stderr: `{boundary.get("reads_stdout_stderr")}` -- mutates_codex_session: `{boundary.get("mutates_codex_session")}` -- spends_loopx_quota: `{boundary.get("spends_loopx_quota")}` -{required_shape_block} -""" - - - -def render_codex_cli_visible_session_proof_markdown(payload: dict[str, Any]) -> str: - boundary = payload.get("boundary") if isinstance(payload.get("boundary"), dict) else {} - checks = payload.get("checks") if isinstance(payload.get("checks"), list) else [] - failures = payload.get("failures") if isinstance(payload.get("failures"), list) else [] - required_shape = payload.get("required_fixture_shape") - check_lines = "\n".join( - f"- [{'x' if check.get('passed') else ' '}] {check.get('key')}: {check.get('description')}" - for check in checks - if isinstance(check, dict) - ) - if not check_lines: - check_lines = "- no proof fixture supplied" - failure_lines = "\n".join(f"- {failure}" for failure in failures) if failures else "- none" - required_shape_block = "" - if isinstance(required_shape, dict): - required_shape_block = f""" -## Required Fixture Shape - -```json -{json.dumps(required_shape, indent=2, ensure_ascii=False)} -``` -""" - return f"""# Codex CLI Visible Session Proof - -- decision: `{payload.get("decision")}` -- approved_for_same_session_automation: `{payload.get("approved_for_same_session_automation")}` -- observed_surface: `{payload.get("observed_surface")}` -- recommended_action: {payload.get("recommended_action")} - -## Checks - -{check_lines} - -## Failures - -{failure_lines} - -## Boundary - -- fixture_only: `{boundary.get("fixture_only")}` -- runs_codex: `{boundary.get("runs_codex")}` -- reads_raw_transcripts: `{boundary.get("reads_raw_transcripts")}` -- reads_session_files: `{boundary.get("reads_session_files")}` -- mutates_codex_session: `{boundary.get("mutates_codex_session")}` -- spends_loopx_quota: `{boundary.get("spends_loopx_quota")}` -{required_shape_block} -""" - - - -def render_codex_cli_visible_attach_acceptance_markdown(payload: dict[str, Any]) -> str: - boundary = payload.get("boundary") if isinstance(payload.get("boundary"), dict) else {} - commands = payload.get("commands") if isinstance(payload.get("commands"), dict) else {} - proof = ( - payload.get("visible_session_proof") - if isinstance(payload.get("visible_session_proof"), dict) - else {} - ) - runtime_idle = ( - payload.get("runtime_idle_detector") - if isinstance(payload.get("runtime_idle_detector"), dict) - else {} - ) - blockers = payload.get("blockers") if isinstance(payload.get("blockers"), list) else [] - blocker_lines = "\n".join(f"- {blocker}" for blocker in blockers) if blockers else "- none" - warnings = payload.get("warnings") if isinstance(payload.get("warnings"), list) else [] - warning_lines = "\n".join(f"- {warning}" for warning in warnings) if warnings else "- none" - return f"""# Codex CLI Visible Attach Acceptance - -- decision: `{payload.get("decision")}` -- accepted_for_same_tui_automation: `{payload.get("accepted_for_same_tui_automation")}` -- accepted_for_visible_later_turn: `{payload.get("accepted_for_visible_later_turn")}` -- observed_surface: `{payload.get("observed_surface")}` -- driver_mode: `{payload.get("driver_mode")}` -- next_safe_step: {payload.get("next_safe_step")} - -## Proof And Idle - -- proof_supplied: `{proof.get("supplied")}` -- proof_approved: `{proof.get("approved")}` -- proof_decision: `{proof.get("decision")}` -- idle_supplied: `{runtime_idle.get("supplied")}` -- idle_approved: `{runtime_idle.get("approved")}` -- idle_decision: `{runtime_idle.get("decision")}` - -## Blockers - -{blocker_lines} - -## Commands - -```bash -{commands.get("session_probe")} -{commands.get("visible_attach_acceptance")} -{commands.get("visible_session_proof")} -{commands.get("runtime_idle_detector_fixture")} -{commands.get("tui_bootstrap_message")} -``` - -## Boundary - -- acceptance_packet_only: `{boundary.get("acceptance_packet_only")}` -- runs_codex: `{boundary.get("runs_codex")}` -- reads_raw_transcripts: `{boundary.get("reads_raw_transcripts")}` -- reads_session_files: `{boundary.get("reads_session_files")}` -- reads_stdout_stderr: `{boundary.get("reads_stdout_stderr")}` -- mutates_codex_session: `{boundary.get("mutates_codex_session")}` -- spends_loopx_quota: `{boundary.get("spends_loopx_quota")}` -- writes_loopx_state: `{boundary.get("writes_loopx_state")}` - -## Warnings - -{warning_lines} -""" diff --git a/loopx/codex_cli_runtime_probe.py b/loopx/codex_cli_runtime_probe.py deleted file mode 100644 index e11026ba9b..0000000000 --- a/loopx/codex_cli_runtime_probe.py +++ /dev/null @@ -1,733 +0,0 @@ -from __future__ import annotations - -import json -import platform -import shlex -import subprocess -from pathlib import Path -from typing import Any, Mapping - -from .control_plane.projects.identity import default_goal_id - - -DEFAULT_CODEX_BIN = "codex" -DEFAULT_TIMEOUT_SECONDS = 2.0 -DEFAULT_EXECUTOR_TIMEOUT_SECONDS = 30.0 -DEFAULT_MIN_HUMAN_INPUT_IDLE_SECONDS = 5.0 - - -HELP_COMMANDS = { - "root": ("--help",), - "exec": ("exec", "--help"), - "resume": ("resume", "--help"), -} - - -def _normalize(text: str | None) -> str: - return " ".join((text or "").lower().replace("_", "-").split()) - - -def _has_any(text: str, needles: tuple[str, ...]) -> bool: - return any(needle in text for needle in needles) - - -def _visible_session_injection_detected(text: str) -> bool: - has_session = _has_any( - text, - ( - "session", - "conversation", - "thread", - "--session", - "--conversation", - "session-id", - "session id", - ), - ) - has_attach = _has_any( - text, - ( - "attach to existing tui", - "attach to active tui", - "attach to an idle tui", - "attach to existing session", - "attach to active session", - "inject into session", - "inject into active session", - "inject prompt into session", - "send prompt to session", - "send message to session", - "send-message", - "send message", - ), - ) - has_visible_turn = _has_any(text, ("prompt", "message", "stdin", "turn", "tui", "visible")) - return has_session and has_attach and has_visible_turn - - -def _remote_control_surface_detected(text: str) -> bool: - return _has_any(text, ("remote-control", "remote control")) and _has_any( - text, - ("--remote", "app server", "app-server"), - ) - - -def _visible_resume_supported(resume_help: str) -> bool: - return "usage: codex resume" in resume_help and "[prompt]" in resume_help - - -def classify_codex_cli_session_surface( - *, - command_outputs: Mapping[str, str], - command_errors: Mapping[str, str] | None = None, - codex_cli_available: bool = True, -) -> dict[str, Any]: - """Classify public Codex CLI help text without reading local sessions.""" - - command_errors = command_errors or {} - normalized_outputs = {name: _normalize(text) for name, text in command_outputs.items()} - all_help = " ".join(normalized_outputs.values()) - root_help = normalized_outputs.get("root", "") - exec_help = normalized_outputs.get("exec", "") - resume_help = normalized_outputs.get("resume", "") - - exec_supported = " exec" in f" {root_help} " or bool(exec_help.strip()) - resume_supported = " resume" in f" {root_help} " or bool(resume_help.strip()) - session_handle_detected = resume_supported or _has_any( - all_help, - ( - "--session", - "--conversation", - "session-id", - "session id", - "conversation id", - "resume", - ), - ) - same_tui_injection_detected = _visible_session_injection_detected(all_help) - remote_control_surface_detected = _remote_control_surface_detected(all_help) - visible_resume_supported = _visible_resume_supported(resume_help) - safe_injection_supported = same_tui_injection_detected - - if safe_injection_supported: - recommended_mode = "session_attached_visible_turn" - automation_action = "try_visible_session_attach_with_idle_guard" - elif remote_control_surface_detected or visible_resume_supported: - recommended_mode = "visible_resume_or_remote_control_spike" - automation_action = "prototype_visible_resume_or_remote_control_with_idle_guard" - elif exec_supported: - recommended_mode = "tui_bootstrap_only" - automation_action = "ask_user_to_start_inside_codex_cli_tui" - else: - recommended_mode = "tui_bootstrap_only" - automation_action = "ask_user_to_start_inside_codex_cli_tui" - - warnings: list[str] = [] - if session_handle_detected and not same_tui_injection_detected: - warnings.append( - "Resume/session help is not enough to claim same-open-TUI injection; require an explicit visible attach/inject primitive." - ) - if (remote_control_surface_detected or visible_resume_supported) and not same_tui_injection_detected: - warnings.append( - "A visible resume or remote-control surface exists; prototype it behind an idle guard before calling it session-attached automation." - ) - if exec_supported and not (safe_injection_supported or remote_control_surface_detected or visible_resume_supported): - warnings.append( - "Codex exec is available, but headless fallback is disabled for the default LoopX setup-then-goal bootstrap path." - ) - if not codex_cli_available: - warnings.append("Codex CLI was not available on PATH; classification used missing-command evidence.") - if command_errors: - warnings.append("Some probe commands returned errors; inspect command_errors before enabling automation.") - - return { - "ok": True, - "schema_version": "codex_cli_session_probe_v0", - "codex_cli_available": codex_cli_available, - "capabilities": { - "exec_supported": exec_supported, - "resume_supported": resume_supported, - "session_handle_detected": session_handle_detected, - "visible_resume_supported": visible_resume_supported, - "remote_control_surface_detected": remote_control_surface_detected, - "same_tui_injection_detected": same_tui_injection_detected, - "safe_injection_supported": safe_injection_supported, - }, - "recommended_mode": recommended_mode, - "automation_action": automation_action, - "boundary": { - "help_only_probe": True, - "reads_raw_transcripts": False, - "reads_credentials": False, - "reads_session_files": False, - "mutates_codex_session": False, - "spends_loopx_quota": False, - }, - "command_errors": dict(command_errors), - "warnings": warnings, - } - - -def load_codex_cli_probe_fixture(path: Path) -> dict[str, str]: - data = json.loads(path.read_text(encoding="utf-8")) - if "command_outputs" in data: - outputs = data["command_outputs"] - else: - outputs = data - if not isinstance(outputs, dict): - raise ValueError("Codex CLI probe fixture must be a JSON object") - return {str(key): str(value) for key, value in outputs.items()} - - -def load_codex_cli_visible_session_proof_fixture(path: Path) -> dict[str, Any]: - data = json.loads(path.read_text(encoding="utf-8")) - if not isinstance(data, dict): - raise ValueError("Codex CLI visible session proof fixture must be a JSON object") - return data - - -def load_codex_cli_runtime_idle_fixture(path: Path) -> dict[str, Any]: - data = json.loads(path.read_text(encoding="utf-8")) - if not isinstance(data, dict): - raise ValueError("Codex CLI runtime idle fixture must be a JSON object") - return data - - -def load_codex_cli_first_response_fixture(path: Path) -> dict[str, Any]: - data = json.loads(path.read_text(encoding="utf-8")) - if not isinstance(data, dict): - raise ValueError("Codex CLI first-response fixture must be a JSON object") - return data - - -def probe_human_input_idle_seconds(*, timeout_seconds: float = DEFAULT_TIMEOUT_SECONDS) -> dict[str, Any]: - """Read a coarse local human-input idle metric without touching Codex state. - - On macOS this reads IOHIDSystem's HIDIdleTime counter. The value says only - how long the machine has been idle since the last keyboard/mouse event; it - does not read typed text, terminal buffers, Codex transcripts, session - files, stdout/stderr, or credentials. - """ - - system = platform.system().lower() - if system != "darwin": - return { - "ok": False, - "source": "unsupported_platform", - "platform": system or "unknown", - "error": "human_input_idle_probe_only_implemented_for_macos", - } - try: - result = subprocess.run( - ["ioreg", "-c", "IOHIDSystem"], - check=False, - capture_output=True, - text=True, encoding="utf-8", errors="replace", - timeout=timeout_seconds, - ) - except FileNotFoundError: - return {"ok": False, "source": "macos_hid_idle_time", "error": "ioreg_not_found"} - except subprocess.TimeoutExpired: - return {"ok": False, "source": "macos_hid_idle_time", "error": "timeout"} - if result.returncode != 0: - return {"ok": False, "source": "macos_hid_idle_time", "error": f"exit_{result.returncode}"} - for line in result.stdout.splitlines(): - if "HIDIdleTime" not in line: - continue - raw_value = line.split("=", 1)[-1].strip() - try: - return { - "ok": True, - "source": "macos_hid_idle_time", - "platform": "darwin", - "human_input_idle_seconds": int(raw_value) / 1_000_000_000, - } - except ValueError: - return { - "ok": False, - "source": "macos_hid_idle_time", - "error": "unparseable_hid_idle_time", - } - return {"ok": False, "source": "macos_hid_idle_time", "error": "hid_idle_time_not_found"} - - -def run_codex_cli_session_probe( - *, - codex_bin: str = DEFAULT_CODEX_BIN, - timeout_seconds: float = DEFAULT_TIMEOUT_SECONDS, - fixture: Path | None = None, -) -> dict[str, Any]: - if fixture: - outputs = load_codex_cli_probe_fixture(fixture) - payload = classify_codex_cli_session_surface( - command_outputs=outputs, - codex_cli_available=True, - ) - payload["source"] = "fixture" - return payload - - outputs: dict[str, str] = {} - errors: dict[str, str] = {} - available = True - for name, extra_args in HELP_COMMANDS.items(): - try: - result = subprocess.run( - [codex_bin, *extra_args], - check=False, - capture_output=True, - text=True, encoding="utf-8", errors="replace", - timeout=timeout_seconds, - ) - except FileNotFoundError: - available = False - errors[name] = "codex_cli_not_found" - break - except subprocess.TimeoutExpired: - errors[name] = "timeout" - continue - text = "\n".join(part for part in (result.stdout, result.stderr) if part) - if result.returncode != 0: - errors[name] = f"exit_{result.returncode}" - outputs[name] = text - - payload = classify_codex_cli_session_surface( - command_outputs=outputs, - command_errors=errors, - codex_cli_available=available, - ) - payload["source"] = "real_help" - payload["codex_bin"] = codex_bin - payload["timeout_seconds"] = timeout_seconds - return payload - - -def _shell_arg(value: str) -> str: - return shlex.quote(value) - - -def _nested_bool(payload: Mapping[str, Any], path: tuple[str, ...]) -> bool: - current: Any = payload - for key in path: - if not isinstance(current, Mapping): - return False - current = current.get(key) - return current is True - - -def _nested_false(payload: Mapping[str, Any], path: tuple[str, ...]) -> bool: - current: Any = payload - for key in path: - if not isinstance(current, Mapping): - return False - current = current.get(key) - return current is False - - -VISIBLE_SESSION_PROOF_REQUIRED_TRUE_CHECKS: tuple[tuple[str, tuple[str, ...], str], ...] = ( - ("user_opt_in", ("user_opt_in",), "user explicitly opted into this proof"), - ("quota_guard_passed", ("quota_guard", "passed"), "quota should-run allowed this proof path"), - ("idle_no_human_typing", ("idle_guard", "no_active_human_typing"), "idle guard saw no active human typing"), - ("idle_no_running_turn", ("idle_guard", "no_running_turn"), "idle guard saw no running Codex turn"), - ("idle_checked_before_prompt", ("idle_guard", "checked_before_prompt"), "idle guard ran before the visible prompt"), - ("visible_to_user", ("turn_visibility", "visible_to_user"), "the steering turn was visible to the user"), - ("visible_prompt_public_safe", ("turn_visibility", "prompt_public_safe"), "the visible prompt was public-safe"), - ("user_can_interrupt", ("interruptibility", "user_can_interrupt"), "the user can interrupt the turn"), - ("manual_takeover_available", ("interruptibility", "manual_takeover_available"), "manual takeover remains available"), - ("compact_writeback_planned", ("writeback", "compact_evidence_planned"), "compact evidence writeback is planned before quota spend"), -) - - -VISIBLE_SESSION_PROOF_REQUIRED_FALSE_CHECKS: tuple[tuple[str, tuple[str, ...], str], ...] = ( - ("no_raw_transcript_read", ("boundary", "reads_raw_transcripts"), "raw transcripts were not read"), - ("no_session_files_read", ("boundary", "reads_session_files"), "session files were not read"), - ("no_credentials_read", ("boundary", "reads_credentials"), "credentials were not read"), - ("no_hidden_session_mutation", ("boundary", "mutates_hidden_session_state"), "hidden session state was not mutated"), - ("no_quota_spend_before_writeback", ("boundary", "spends_quota_before_writeback"), "quota was not spent before writeback"), -) - - -RUNTIME_IDLE_REQUIRED_TRUE_CHECKS: tuple[tuple[str, tuple[str, ...], str], ...] = ( - ("idle_no_human_typing", ("idle_guard", "no_active_human_typing"), "no active human typing was observed"), - ("idle_no_running_turn", ("idle_guard", "no_running_turn"), "no running Codex turn was observed"), - ("idle_checked_before_prompt", ("idle_guard", "checked_before_prompt"), "idle check ran before any visible prompt"), - ("visible_to_user", ("turn_visibility", "visible_to_user"), "the target turn remains visible to the user"), - ("user_can_interrupt", ("interruptibility", "user_can_interrupt"), "the user can interrupt the turn"), - ("manual_takeover_available", ("interruptibility", "manual_takeover_available"), "manual takeover remains available"), -) - - -RUNTIME_IDLE_REQUIRED_FALSE_CHECKS: tuple[tuple[str, tuple[str, ...], str], ...] = ( - ("no_raw_transcript_read", ("boundary", "reads_raw_transcripts"), "raw transcripts were not read"), - ("no_session_files_read", ("boundary", "reads_session_files"), "session files were not read"), - ("no_stdout_stderr_read", ("boundary", "reads_stdout_stderr"), "stdout/stderr streams were not read"), - ("no_credentials_read", ("boundary", "reads_credentials"), "credentials were not read"), - ("no_hidden_session_mutation", ("boundary", "mutates_hidden_session_state"), "hidden session state was not mutated"), -) - - -FIRST_RESPONSE_REQUIRED_TRUE_CHECKS: tuple[tuple[str, tuple[str, ...], str], ...] = ( - ("manual_or_visible_delivery", ("prompt_delivery", "manual_or_visible_delivery"), "the start message was delivered through a visible TUI path"), - ("prompt_public_safe", ("prompt_delivery", "prompt_public_safe"), "the delivered prompt was public-safe"), - ("goal_id_visible", ("first_response", "goal_id_visible"), "the first response showed the current goal id"), - ("user_gate_or_none_visible", ("first_response", "user_gate_or_none_visible"), "the first response showed the concrete user gate or that none blocks the path"), - ("top_user_todo_or_none_visible", ("first_response", "top_user_todo_or_none_visible"), "the first response showed the top user todo or that none exists"), - ("top_agent_todo_visible", ("first_response", "top_agent_todo_visible"), "the first response showed the selected agent todo"), - ("next_safe_action_visible", ("first_response", "next_safe_action_visible"), "the first response showed the next safe action"), - ("bounded_segment_started_or_blocker_written", ("first_response", "bounded_segment_started_or_blocker_written"), "the first response either started one bounded segment or wrote a precise blocker"), - ("user_can_interrupt", ("interruptibility", "user_can_interrupt"), "the user can interrupt the visible TUI path"), - ("manual_takeover_available", ("interruptibility", "manual_takeover_available"), "manual takeover remains available"), - ("compact_evidence_planned", ("writeback", "compact_evidence_planned"), "compact evidence writeback is planned before quota spend"), - ("quota_spend_after_writeback_only", ("writeback", "quota_spend_after_writeback_only"), "quota spend happens only after validated writeback"), -) - - -FIRST_RESPONSE_REQUIRED_FALSE_CHECKS: tuple[tuple[str, tuple[str, ...], str], ...] = ( - ("no_argv_prompt", ("prompt_delivery", "argv_prompt_used"), "the start prompt was not passed as a process argv prompt"), - ("no_raw_transcript_read", ("boundary", "reads_raw_transcripts"), "raw transcripts were not read"), - ("no_session_files_read", ("boundary", "reads_session_files"), "session files were not read"), - ("no_stdout_stderr_read", ("boundary", "reads_stdout_stderr"), "stdout/stderr streams were not read"), - ("no_credentials_read", ("boundary", "reads_credentials"), "credentials were not read"), - ("no_hidden_session_mutation", ("boundary", "mutates_hidden_session_state"), "hidden session state was not mutated"), - ("no_quota_spend_before_writeback", ("boundary", "spends_quota_before_writeback"), "quota was not spent before writeback"), -) - - -def build_codex_cli_runtime_idle_observation_payload( - *, - observed_surface: str, - turn_state: str, - human_input_idle_seconds: float | None, - min_human_input_idle_seconds: float, - checked_before_prompt: bool, - visible_to_user: bool, - user_can_interrupt: bool, - manual_takeover_available: bool, - probe_result: dict[str, Any] | None = None, -) -> dict[str, Any]: - """Convert public-safe local idle observations into detector input.""" - - idle_seconds_known = human_input_idle_seconds is not None - no_active_human_typing = bool( - idle_seconds_known and human_input_idle_seconds >= min_human_input_idle_seconds - ) - no_running_turn = turn_state == "idle" - return { - "observed_surface": observed_surface, - "source": "local_runtime_observation", - "runtime_observation": { - "schema_version": "codex_cli_runtime_idle_observation_v0", - "human_input_idle_seconds": human_input_idle_seconds, - "min_human_input_idle_seconds": min_human_input_idle_seconds, - "human_input_idle_source": (probe_result or {}).get("source") or "provided", - "human_input_idle_probe_ok": (probe_result or {}).get("ok"), - "turn_state": turn_state, - "turn_state_source": "public_safe_local_observation", - "cannot_prove_unknown_turn_state": turn_state == "unknown", - }, - "idle_guard": { - "no_active_human_typing": no_active_human_typing, - "no_running_turn": no_running_turn, - "checked_before_prompt": checked_before_prompt, - }, - "turn_visibility": {"visible_to_user": visible_to_user}, - "interruptibility": { - "user_can_interrupt": user_can_interrupt, - "manual_takeover_available": manual_takeover_available, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - }, - } - - -def build_codex_cli_runtime_idle_detector( - *, - project: Path, - goal_id: str | None, - agent_id: str | None, - cli_bin: str, - idle_payload: dict[str, Any] | None, -) -> dict[str, Any]: - """Validate public-safe runtime idle evidence before a visible later turn. - - This is not a Codex session inspector. It accepts either a reproducible - public-safe fixture or a narrow local observation payload. Both paths prove - the two product-critical facts for later visible turns: the user is not - typing, and Codex is not already running a turn. The detector intentionally - does not read transcripts, session files, stdout/stderr, credentials, or - hidden runtime state. - """ - - resolved_project = str(project.expanduser()) - resolved_goal_id = goal_id or default_goal_id(project) - required_fixture_shape = { - "observed_surface": "visible_resume_prompt | remote_control_visible_prompt | same_tui_visible_attach | codex_cli_tui_visible_window", - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": {"visible_to_user": True}, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - }, - } - if idle_payload is None: - return { - "ok": False, - "schema_version": "codex_cli_runtime_idle_detector_v0", - "project": resolved_project, - "goal_id": resolved_goal_id, - "agent_id": agent_id, - "cli_bin": cli_bin, - "source": "idle_evidence_required", - "decision": "runtime_idle_evidence_required", - "approved_for_visible_later_turn": False, - "recommended_action": "capture public-safe runtime idle evidence before steering a later visible Codex CLI turn", - "required_fixture_shape": required_fixture_shape, - "checks": [], - "failures": ["missing_runtime_idle_evidence"], - "boundary": { - "fixture_only": False, - "public_safe_fixture_supported": True, - "local_observation_adapter_supported": True, - "runs_codex": False, - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "reads_credentials": False, - "mutates_codex_session": False, - "spends_loopx_quota": False, - }, - } - - checks: list[dict[str, Any]] = [] - failures: list[str] = [] - for key, path, description in RUNTIME_IDLE_REQUIRED_TRUE_CHECKS: - passed = _nested_bool(idle_payload, path) - checks.append({"key": key, "required": True, "passed": passed, "description": description}) - if not passed: - failures.append(key) - for key, path, description in RUNTIME_IDLE_REQUIRED_FALSE_CHECKS: - passed = _nested_false(idle_payload, path) - checks.append({"key": key, "required": False, "passed": passed, "description": description}) - if not passed: - failures.append(key) - - observed_surface = str(idle_payload.get("observed_surface") or "unknown") - supported_surface = observed_surface in { - "visible_resume_prompt", - "remote_control_visible_prompt", - "same_tui_visible_attach", - "codex_cli_tui_visible_window", - } - checks.append( - { - "key": "supported_observed_surface", - "required": sorted( - [ - "codex_cli_tui_visible_window", - "remote_control_visible_prompt", - "same_tui_visible_attach", - "visible_resume_prompt", - ] - ), - "actual": observed_surface, - "passed": supported_surface, - "description": "idle evidence was captured from a visible Codex CLI surface", - } - ) - if not supported_surface: - failures.append("unsupported_observed_surface") - - approved = not failures - if approved: - decision = "runtime_idle_detector_passed" - recommended_action = "allow a later visible Codex CLI turn only after a fresh quota guard" - else: - decision = "runtime_idle_detector_incomplete" - recommended_action = "keep the TUI bootstrap path visible and do not steer a later turn yet" - - source = str(idle_payload.get("source") or "idle_fixture") - local_observation = source == "local_runtime_observation" - return { - "ok": True, - "schema_version": "codex_cli_runtime_idle_detector_v0", - "project": resolved_project, - "goal_id": resolved_goal_id, - "agent_id": agent_id, - "cli_bin": cli_bin, - "source": source, - "observed_surface": observed_surface, - "runtime_observation": idle_payload.get("runtime_observation"), - "decision": decision, - "approved_for_visible_later_turn": approved, - "recommended_action": recommended_action, - "checks": checks, - "failures": failures, - "boundary": { - "fixture_only": not local_observation, - "public_safe_fixture_supported": True, - "local_observation_adapter_supported": True, - "runs_codex": False, - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_stdout_stderr": False, - "reads_credentials": False, - "mutates_codex_session": False, - "spends_loopx_quota": False, - }, - } - - -def build_codex_cli_visible_session_proof( - *, - project: Path, - goal_id: str | None, - agent_id: str | None, - cli_bin: str, - proof_payload: dict[str, Any] | None, -) -> dict[str, Any]: - """Validate a public-safe proof packet for visible Codex CLI steering. - - This command intentionally does not run Codex or inspect local session - state. It validates whether a separately captured public-safe observation - is strong enough to treat resume/remote-control as a candidate for future - same-session automation. - """ - - resolved_project = str(project.expanduser()) - resolved_goal_id = goal_id or default_goal_id(project) - if proof_payload is None: - return { - "ok": False, - "schema_version": "codex_cli_visible_session_proof_v0", - "project": resolved_project, - "goal_id": resolved_goal_id, - "agent_id": agent_id, - "decision": "proof_fixture_required", - "approved_for_same_session_automation": False, - "recommended_action": "capture a public-safe proof fixture; do not run same-session automation yet", - "required_fixture_shape": { - "user_opt_in": True, - "quota_guard": {"passed": True}, - "idle_guard": { - "no_active_human_typing": True, - "no_running_turn": True, - "checked_before_prompt": True, - }, - "turn_visibility": { - "visible_to_user": True, - "prompt_public_safe": True, - }, - "interruptibility": { - "user_can_interrupt": True, - "manual_takeover_available": True, - }, - "boundary": { - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_credentials": False, - "mutates_hidden_session_state": False, - "spends_quota_before_writeback": False, - }, - "writeback": {"compact_evidence_planned": True}, - }, - "boundary": { - "fixture_only": True, - "runs_codex": False, - "reads_raw_transcripts": False, - "reads_credentials": False, - "reads_session_files": False, - "mutates_codex_session": False, - "spends_loopx_quota": False, - }, - "checks": [], - "failures": ["missing_proof_fixture"], - } - - checks: list[dict[str, Any]] = [] - failures: list[str] = [] - for key, path, description in VISIBLE_SESSION_PROOF_REQUIRED_TRUE_CHECKS: - passed = _nested_bool(proof_payload, path) - checks.append({"key": key, "required": True, "passed": passed, "description": description}) - if not passed: - failures.append(key) - for key, path, description in VISIBLE_SESSION_PROOF_REQUIRED_FALSE_CHECKS: - passed = _nested_false(proof_payload, path) - checks.append({"key": key, "required": False, "passed": passed, "description": description}) - if not passed: - failures.append(key) - - observed_surface = str(proof_payload.get("observed_surface") or "unknown") - supported_surface = observed_surface in { - "visible_resume_prompt", - "remote_control_visible_prompt", - "same_tui_visible_attach", - } - if not supported_surface: - failures.append("unsupported_observed_surface") - checks.append( - { - "key": "supported_observed_surface", - "required": sorted( - [ - "remote_control_visible_prompt", - "same_tui_visible_attach", - "visible_resume_prompt", - ] - ), - "actual": observed_surface, - "passed": supported_surface, - "description": "observed surface is a visible Codex CLI steering path", - } - ) - - approved = not failures - if approved: - decision = "visible_session_proof_passed" - recommended_action = ( - "allow a future opt-in driver spike to use this visible surface behind quota and idle guards" - ) - else: - decision = "visible_session_proof_incomplete" - recommended_action = ( - "keep TUI bootstrap primary; do not treat this as same-session automation" - ) - - return { - "ok": True, - "schema_version": "codex_cli_visible_session_proof_v0", - "project": resolved_project, - "goal_id": resolved_goal_id, - "agent_id": agent_id, - "cli_bin": cli_bin, - "source": "proof_fixture", - "observed_surface": observed_surface, - "decision": decision, - "approved_for_same_session_automation": approved, - "recommended_action": recommended_action, - "checks": checks, - "failures": failures, - "boundary": { - "fixture_only": True, - "runs_codex": False, - "reads_raw_transcripts": False, - "reads_credentials": False, - "reads_session_files": False, - "mutates_codex_session": False, - "spends_loopx_quota": False, - }, - } diff --git a/loopx/codex_cli_scheduler.py b/loopx/codex_cli_scheduler.py deleted file mode 100644 index 65b2b80213..0000000000 --- a/loopx/codex_cli_scheduler.py +++ /dev/null @@ -1,566 +0,0 @@ -from __future__ import annotations - -import shlex -import subprocess -from pathlib import Path -from typing import Any, Callable - -from .codex_cli_probe import ( - DEFAULT_EXECUTOR_TIMEOUT_SECONDS, - _shell_arg, - build_codex_cli_runtime_idle_detector, - build_codex_cli_visible_driver_run_packet, -) -from .control_plane.effect_program import effect_program_from_ordered_steps - - -def _scheduler_label(goal_id: str, agent_id: str | None) -> str: - raw = f"{goal_id}-{agent_id or 'agent'}" - safe = "".join(ch.lower() if ch.isalnum() else "-" for ch in raw) - safe = "-".join(part for part in safe.split("-") if part) - return f"com.loopx.codex-cli.{safe}" - - -def _positive_int(value: Any, default: int) -> int: - try: - parsed = int(value) - except (TypeError, ValueError): - return default - return parsed if parsed > 0 else default - - -def build_codex_cli_local_scheduler_tick( - *, - project: Path, - goal_id: str | None, - agent_id: str | None, - cli_bin: str, - codex_bin: str, - probe_payload: dict[str, Any], - quota_payload: dict[str, Any] | None = None, - proof_payload: dict[str, Any] | None = None, - idle_payload: dict[str, Any] | None = None, - allow_headless_fallback: bool = False, -) -> dict[str, Any]: - """Build a local scheduler tick packet without executing Codex. - - This is the first executor-facing spike: a local scheduler can run it as a - one-shot tick and either receive a candidate external command or a precise - blocker writeback command. The tick itself does not read Codex session - files, inspect transcripts, mutate sessions, launch Codex, or spend quota. - """ - - run_packet = build_codex_cli_visible_driver_run_packet( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - codex_bin=codex_bin, - probe_payload=probe_payload, - proof_payload=proof_payload, - allow_headless_fallback=allow_headless_fallback, - ) - idle_detector = build_codex_cli_runtime_idle_detector( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - idle_payload=idle_payload, - ) - idle_approved = bool(idle_detector.get("approved_for_visible_later_turn") is True) - resolved_project = str(run_packet["project"]) - resolved_goal_id = str(run_packet["goal_id"]) - decision = str(run_packet.get("decision") or "tui_bootstrap_only") - agent_arg = f" --agent-id {_shell_arg(agent_id)}" if agent_id else "" - common_args = ( - f"--project {_shell_arg(resolved_project)} " - f"--goal-id {_shell_arg(resolved_goal_id)}{agent_arg} " - f"--codex-bin {_shell_arg(codex_bin)}" - ) - visible_driver_run_command = ( - f"{_shell_arg(cli_bin)} codex-cli-visible-driver-run {common_args}" - ) - runtime_idle_detector_command = ( - f"{_shell_arg(cli_bin)} codex-cli-runtime-idle-detector " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}" - f"{agent_arg} --observe-local-runtime --observed-surface visible_resume_prompt " - "--turn-state idle --probe-human-input-idle --checked-before-prompt " - "--visible-to-user --user-can-interrupt --manual-takeover-available" - ) - runtime_idle_fixture_command = ( - f"{_shell_arg(cli_bin)} codex-cli-runtime-idle-detector " - f"--project {_shell_arg(resolved_project)} --goal-id {_shell_arg(resolved_goal_id)}" - f"{agent_arg} --idle-fixture " - ) - scheduler_tick_command = ( - f"{_shell_arg(cli_bin)} codex-cli-local-scheduler-tick {common_args} " - "--observe-local-runtime --observed-surface visible_resume_prompt " - "--turn-state idle --probe-human-input-idle --checked-before-prompt " - "--visible-to-user --user-can-interrupt --manual-takeover-available" - ) - scheduler_hint = ( - quota_payload.get("scheduler_hint") - if isinstance(quota_payload, dict) - and isinstance(quota_payload.get("scheduler_hint"), dict) - else {} - ) - local_scheduler_hint = ( - scheduler_hint.get("local_scheduler") - if isinstance(scheduler_hint.get("local_scheduler"), dict) - else {} - ) - codex_app_hint = ( - scheduler_hint.get("app_automation") - if isinstance(scheduler_hint.get("app_automation"), dict) - else scheduler_hint.get("codex_app") - if isinstance(scheduler_hint.get("codex_app"), dict) - else {} - ) - reset_policy = ( - scheduler_hint.get("reset_policy") - if isinstance(scheduler_hint.get("reset_policy"), dict) - else {} - ) - recommended_interval_minutes = _positive_int( - local_scheduler_hint.get("recommended_interval_minutes") - or codex_app_hint.get("recommended_interval_minutes"), - 10, - ) - reset_interval_minutes = _positive_int( - reset_policy.get("local_scheduler_initial_interval_minutes"), - recommended_interval_minutes, - ) - - candidate_command = None - precise_blocker: dict[str, str] | None = None - if decision == "visible_session_turn_candidate": - if idle_approved: - scheduler_action = "external_visible_command_candidate" - candidate_command = run_packet.get("recommended_command") - next_safe_step = ( - "external scheduler may run the visible command only after a fresh quota guard, " - "runtime idle observation, guard_checked, and an allowed command prefix" - ) - else: - scheduler_action = "write_precise_blocker" - reason = ( - "runtime_idle_evidence_missing" - if idle_payload is None - else "runtime_idle_detector_incomplete" - ) - failures = idle_detector.get("failures") if isinstance(idle_detector.get("failures"), list) else [] - precise_blocker = { - "reason": reason, - "message": ( - "Codex CLI visible automation is blocked until a public-safe runtime idle " - "observation proves no active human typing, no running visible turn, user " - f"visibility, and interruptibility. failures={failures}" - ), - } - next_safe_step = ( - "capture a public-safe runtime idle observation, keep the one-message TUI path visible, " - "and do not run Codex from the scheduler" - ) - elif decision == "visible_session_proof_required": - scheduler_action = "write_precise_blocker" - precise_blocker = { - "reason": "visible_session_proof_missing", - "message": ( - "Codex CLI automation is blocked until a public-safe visible-session proof " - "shows user opt-in, quota guard, idle guard, visibility, interruptibility, " - "boundary safety, and compact writeback planning." - ), - } - next_safe_step = "write the blocker, keep TUI bootstrap primary, and do not run Codex from the scheduler" - elif decision.startswith("headless_"): - scheduler_action = "write_precise_blocker" - precise_blocker = { - "reason": "headless_fallback_disabled", - "message": ( - "Codex CLI headless fallback is disabled for the default LoopX " - "/goal bootstrap path; keep the visible TUI bootstrap primary." - ), - } - next_safe_step = "write the blocker and keep the one-message TUI bootstrap as the user-facing path" - else: - scheduler_action = "surface_tui_bootstrap" - next_safe_step = "surface the TUI bootstrap command; do not run Codex from the scheduler" - - if precise_blocker: - recommended_action = f"{precise_blocker['reason']}: {precise_blocker['message']}" - blocker_writeback_command = ( - f"{_shell_arg(cli_bin)} refresh-state --goal-id {_shell_arg(resolved_goal_id)} " - "--classification codex_cli_local_scheduler_blocked " - "--delivery-batch-scale single_surface --delivery-outcome outcome_gap" - f"{agent_arg} --agent-lane productization_codex_cli " - f"--recommended-action {_shell_arg(recommended_action)}" - ) - else: - blocker_writeback_command = None - - commands_program = effect_program_from_ordered_steps( - [ - { - "id": "visible_driver_run", - "kind": "codex_cli_command", - "command": visible_driver_run_command, - }, - { - "id": "runtime_idle_detector", - "kind": "codex_cli_command", - "command": runtime_idle_detector_command, - }, - { - "id": "runtime_idle_detector_fixture", - "kind": "codex_cli_command", - "command": runtime_idle_fixture_command, - }, - { - "id": "scheduler_tick", - "kind": "codex_cli_command", - "command": scheduler_tick_command, - }, - { - "id": "candidate_codex_command", - "kind": "codex_cli_command", - "command": candidate_command or "", - }, - { - "id": "blocker_writeback", - "kind": "codex_cli_command", - "command": blocker_writeback_command or "", - }, - ], - execution_mode="serial", - ) - commands = { - step.step_id: step.command for step in commands_program.steps - } - - return { - "ok": True, - "schema_version": "codex_cli_local_scheduler_tick_v0", - "project": resolved_project, - "goal_id": resolved_goal_id, - "agent_id": agent_id, - "cli_bin": cli_bin, - "codex_bin": codex_bin, - "scheduler_phase": "tick_packet_no_execution", - "scheduler_action": scheduler_action, - "decision": decision, - "next_safe_step": next_safe_step, - "candidate_command": candidate_command, - "precise_blocker": precise_blocker, - "blocker_writeback_command": blocker_writeback_command, - "scheduler_hint": scheduler_hint or None, - "launchd": { - "label": _scheduler_label(resolved_goal_id, agent_id), - "one_shot_command": scheduler_tick_command, - "keep_alive": False, - "recommended_interval_seconds": recommended_interval_minutes * 60, - "reset_token": reset_policy.get("reset_token"), - "reset_interval_seconds": reset_interval_minutes * 60, - "reset_policy": reset_policy or None, - "notes": [ - "Run this tick as a one-shot or low-frequency launchd job.", - "If quota scheduler_hint is present, apply its cadence/backoff and unchanged-poll stop policy.", - "If scheduler_hint.reset_policy.reset_token changes, reset the local interval to reset_interval_seconds and clear unchanged-poll state without spending quota.", - "The tick prints a candidate command or blocker command; it does not execute Codex.", - "Use external logging that excludes raw transcripts, session files, credentials, and private paths.", - ], - }, - "commands": commands, - "visible_driver_run_packet": { - "schema_version": run_packet.get("schema_version"), - "driver_mode": run_packet.get("driver_mode"), - "decision": run_packet.get("decision"), - "next_driver_action": run_packet.get("next_driver_action"), - "allow_headless_fallback": run_packet.get("allow_headless_fallback"), - "visible_session_proof": run_packet.get("visible_session_proof"), - }, - "runtime_idle_detector": { - "supplied": idle_payload is not None, - "approved": idle_approved, - "decision": idle_detector.get("decision"), - "failures": idle_detector.get("failures") or [], - "source": idle_detector.get("source"), - }, - "boundary": { - "tick_packet_only": True, - "runs_codex": False, - "reads_raw_transcripts": False, - "reads_credentials": False, - "reads_session_files": False, - "mutates_codex_session": False, - "spends_loopx_quota": False, - "writes_loopx_state": False, - "blocker_writeback_requires_external_execution": True, - "visible_candidate_requires_runtime_idle_detector": True, - "headless_execution_disabled": True, - }, - "warnings": list(run_packet.get("warnings") or []), - } - - -def _command_matches_allowed_prefix(command: str | None, prefixes: list[str]) -> bool: - if not command or not prefixes: - return False - try: - command_parts = shlex.split(command) - except ValueError: - command_parts = [] - for raw_prefix in prefixes: - prefix = (raw_prefix or "").strip() - if not prefix: - continue - try: - prefix_parts = shlex.split(prefix) - except ValueError: - prefix_parts = [] - if prefix_parts and command_parts[: len(prefix_parts)] == prefix_parts: - return True - if command.strip() == prefix or command.strip().startswith(f"{prefix} "): - return True - return False - - -def _run_scheduler_executor_shell_command( - command: str, - *, - timeout_seconds: float, - capture_output: bool = False, -) -> dict[str, Any]: - stdout = subprocess.PIPE if capture_output else subprocess.DEVNULL - stderr = subprocess.PIPE if capture_output else subprocess.DEVNULL - try: - argv = shlex.split(command) - except ValueError as exc: - return { - "attempted": False, - "returncode": None, - "timed_out": False, - "output_captured": capture_output, - "error": f"invalid_command: {exc}", - } - if not argv: - return { - "attempted": False, - "returncode": None, - "timed_out": False, - "output_captured": capture_output, - "error": "empty_command", - } - try: - completed = subprocess.run( - argv, - check=False, - text=True, encoding="utf-8", errors="replace", - timeout=timeout_seconds, - stdout=stdout, - stderr=stderr, - ) - except subprocess.TimeoutExpired: - return { - "attempted": True, - "returncode": None, - "timed_out": True, - "output_captured": capture_output, - } - return { - "attempted": True, - "returncode": completed.returncode, - "timed_out": False, - "output_captured": capture_output, - } - - -SchedulerCommandRunner = Callable[..., dict[str, Any]] - - -def execute_codex_cli_local_scheduler_tick_result( - tick_payload: dict[str, Any], - *, - execute_candidate: bool = False, - execute_blocker_writeback: bool = False, - guard_checked: bool = False, - candidate_command_prefixes: list[str] | None = None, - executor_timeout_seconds: float = DEFAULT_EXECUTOR_TIMEOUT_SECONDS, - runner: SchedulerCommandRunner | None = None, -) -> dict[str, Any]: - """Optionally execute one scheduler tick result behind explicit opt-in gates.""" - - candidate_command_prefixes = list(candidate_command_prefixes or []) - runner = runner or _run_scheduler_executor_shell_command - scheduler_action = str(tick_payload.get("scheduler_action") or "") - candidate_command = tick_payload.get("candidate_command") - blocker_writeback_command = tick_payload.get("blocker_writeback_command") - candidate_command = candidate_command if isinstance(candidate_command, str) else None - blocker_writeback_command = ( - blocker_writeback_command if isinstance(blocker_writeback_command, str) else None - ) - commands = tick_payload.get("commands") if isinstance(tick_payload.get("commands"), dict) else {} - runtime_idle = ( - tick_payload.get("runtime_idle_detector") - if isinstance(tick_payload.get("runtime_idle_detector"), dict) - else {} - ) - runtime_idle_approved = bool(runtime_idle.get("approved") is True) - - execution: dict[str, Any] = { - "attempted": False, - "executed": False, - "kind": None, - "reason": "no_execute_flag", - "returncode": None, - "timed_out": False, - "output_captured": False, - "candidate_prefix_matched": None, - } - - if execute_candidate and execute_blocker_writeback: - execution["reason"] = "choose_one_execute_mode" - elif (execute_candidate or execute_blocker_writeback) and not guard_checked: - execution["reason"] = "fresh_quota_guard_confirmation_required" - elif execute_candidate: - if scheduler_action != "external_visible_command_candidate": - execution["reason"] = "scheduler_action_not_candidate" - elif scheduler_action == "external_visible_command_candidate" and not runtime_idle_approved: - execution["reason"] = "runtime_idle_detector_required" - elif not candidate_command: - execution["reason"] = "candidate_command_missing" - elif not candidate_command_prefixes: - execution["reason"] = "candidate_command_prefix_required" - elif not _command_matches_allowed_prefix(candidate_command, candidate_command_prefixes): - execution["reason"] = "candidate_command_prefix_mismatch" - execution["candidate_prefix_matched"] = False - else: - execution["candidate_prefix_matched"] = True - result = runner( - candidate_command, - timeout_seconds=executor_timeout_seconds, - capture_output=False, - ) - execution.update(result) - execution["executed"] = True - execution["kind"] = "candidate_command" - execution["reason"] = "candidate_command_executed" - elif execute_blocker_writeback: - if scheduler_action != "write_precise_blocker": - execution["reason"] = "scheduler_action_not_blocker_writeback" - elif not blocker_writeback_command: - execution["reason"] = "blocker_writeback_command_missing" - else: - result = runner( - blocker_writeback_command, - timeout_seconds=executor_timeout_seconds, - capture_output=False, - ) - execution.update(result) - execution["executed"] = True - execution["kind"] = "blocker_writeback" - execution["reason"] = "blocker_writeback_executed" - - executed = bool(execution.get("executed")) - command_failed = executed and ( - bool(execution.get("timed_out")) or execution.get("returncode") not in {0, None} - ) - return { - "ok": not command_failed, - "schema_version": "codex_cli_local_scheduler_executor_v0", - "project": tick_payload.get("project"), - "goal_id": tick_payload.get("goal_id"), - "agent_id": tick_payload.get("agent_id"), - "cli_bin": tick_payload.get("cli_bin"), - "codex_bin": tick_payload.get("codex_bin"), - "executor_phase": "explicit_opt_in_executor", - "scheduler_action": scheduler_action, - "decision": tick_payload.get("decision"), - "next_safe_step": tick_payload.get("next_safe_step"), - "execution_request": { - "execute_candidate": execute_candidate, - "execute_blocker_writeback": execute_blocker_writeback, - "guard_checked": guard_checked, - "candidate_command_prefixes": candidate_command_prefixes, - "executor_timeout_seconds": executor_timeout_seconds, - "runtime_idle_detector_required_for_visible_candidate": True, - }, - "execution": execution, - "commands": { - "scheduler_tick": commands.get("scheduler_tick"), - "candidate_command": candidate_command, - "blocker_writeback": blocker_writeback_command, - }, - "scheduler_tick": { - "schema_version": tick_payload.get("schema_version"), - "scheduler_phase": tick_payload.get("scheduler_phase"), - "scheduler_action": scheduler_action, - "decision": tick_payload.get("decision"), - "precise_blocker": tick_payload.get("precise_blocker"), - "visible_session_proof": ( - (tick_payload.get("visible_driver_run_packet") or {}).get("visible_session_proof") - if isinstance(tick_payload.get("visible_driver_run_packet"), dict) - else None - ), - "runtime_idle_detector": runtime_idle, - }, - "boundary": { - "executor_wrapper": True, - "requires_explicit_execute_flag": True, - "requires_fresh_quota_guard_confirmation": True, - "candidate_prefix_required": True, - "runtime_idle_detector_required_for_visible_candidate": True, - "runs_external_candidate": executed and execution.get("kind") == "candidate_command", - "runs_codex_candidate_possible": executed and execution.get("kind") == "candidate_command", - "reads_raw_transcripts": False, - "reads_credentials": False, - "reads_session_files": False, - "mutates_codex_session": False, - "candidate_output_captured": False, - "blocker_output_captured": False, - "spends_loopx_quota": False, - "writes_loopx_state": executed and execution.get("kind") == "blocker_writeback", - }, - "warnings": list(tick_payload.get("warnings") or []), - } - - -def build_codex_cli_local_scheduler_executor( - *, - project: Path, - goal_id: str | None, - agent_id: str | None, - cli_bin: str, - codex_bin: str, - probe_payload: dict[str, Any], - quota_payload: dict[str, Any] | None = None, - proof_payload: dict[str, Any] | None = None, - idle_payload: dict[str, Any] | None = None, - allow_headless_fallback: bool = False, - execute_candidate: bool = False, - execute_blocker_writeback: bool = False, - guard_checked: bool = False, - candidate_command_prefixes: list[str] | None = None, - executor_timeout_seconds: float = DEFAULT_EXECUTOR_TIMEOUT_SECONDS, - runner: SchedulerCommandRunner | None = None, -) -> dict[str, Any]: - tick_payload = build_codex_cli_local_scheduler_tick( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - codex_bin=codex_bin, - probe_payload=probe_payload, - quota_payload=quota_payload, - proof_payload=proof_payload, - idle_payload=idle_payload, - allow_headless_fallback=allow_headless_fallback, - ) - return execute_codex_cli_local_scheduler_tick_result( - tick_payload, - execute_candidate=execute_candidate, - execute_blocker_writeback=execute_blocker_writeback, - guard_checked=guard_checked, - candidate_command_prefixes=candidate_command_prefixes, - executor_timeout_seconds=executor_timeout_seconds, - runner=runner, - ) diff --git a/loopx/help_surface.py b/loopx/help_surface.py index 7b5b3fa782..c6b938ed26 100644 --- a/loopx/help_surface.py +++ b/loopx/help_surface.py @@ -218,14 +218,6 @@ def register_command_reference(subparsers: argparse._SubParsersAction[argparse.A "command": "loopx codex-cli-bootstrap-message", "purpose": "Generate the visible Codex CLI TUI setup message.", }, - { - "command": "loopx codex-cli-tui-bootstrap-smoke-bundle", - "purpose": "Generate a transcript-free Codex CLI first-run smoke bundle.", - }, - { - "command": "loopx codex-cli-visible-attach-acceptance", - "purpose": "Check public-safe visible Codex CLI attach evidence.", - }, {"command": "loopx heartbeat-prompt", "purpose": "Generate a guarded heartbeat automation body."}, { "command": "loopx supervisor-prompt", @@ -377,19 +369,6 @@ def register_command_reference(subparsers: argparse._SubParsersAction[argparse.A "capability", "chat-endpoint", "checkpoint-context", - "codex-cli-bounded-visible-pilot-adapter", - "codex-cli-exec-handoff", - "codex-cli-local-driver-plan", - "codex-cli-local-scheduler-exec", - "codex-cli-local-scheduler-tick", - "codex-cli-one-message-loop-pilot", - "codex-cli-runtime-idle-detector", - "codex-cli-session-probe", - "codex-cli-visible-driver-plan", - "codex-cli-visible-driver-run", - "codex-cli-visible-first-response-capture-plan", - "codex-cli-visible-local-driver-pilot", - "codex-cli-visible-session-proof", "configure-goal", "configuration-backup", "delegation", diff --git a/loopx/project_prompt.py b/loopx/project_prompt.py index a76933bbaf..a690cff2bd 100644 --- a/loopx/project_prompt.py +++ b/loopx/project_prompt.py @@ -663,126 +663,6 @@ def build_codex_cli_bootstrap_message( } -def build_codex_cli_tui_bootstrap_smoke_bundle( - *, - project: Path, - goal_id: str | None, - agent_id: str | None, - cli_bin: str, -) -> dict[str, Any]: - bootstrap = build_codex_cli_bootstrap_message( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - ) - resolved_project = str(bootstrap["project"]) - resolved_goal_id = str(bootstrap["goal_id"]) - agent_arg = f" --agent-id {shell_arg(agent_id)}" if agent_id else "" - message_only_command = ( - f"{shell_arg(cli_bin)} codex-cli-bootstrap-message " - f"--project {shell_arg(resolved_project)} " - f"--goal-id {shell_arg(resolved_goal_id)}{agent_arg} --message-only" - ) - review_packet_command = ( - f"{shell_arg(cli_bin)} codex-cli-bootstrap-message " - f"--project {shell_arg(resolved_project)} " - f"--goal-id {shell_arg(resolved_goal_id)}{agent_arg}" - ) - boundary = { - "runs_codex": False, - "reads_raw_transcripts": False, - "reads_session_files": False, - "reads_credentials": False, - "mutates_codex_session": False, - "spends_loopx_quota": False, - "requires_loopx_repo_clone": False, - } - validation_checklist = [ - "archive installer works from a temporary GitHub-style tarball or existing install", - "message-only command prints only the setup paste block, not the Markdown review packet", - "paste block includes no-clone install repair, project bootstrap/connect, thin heartbeat generation, loop activation, and quota guard", - "accountable progress refresh then quota spend remain later post-delivery commands inside the paste block, not setup or smoke side effects", - "no raw Codex transcripts, session files, credentials, stdout, stderr, or private paths are read", - ] - return { - "ok": True, - "schema_version": "codex_cli_tui_bootstrap_smoke_bundle_v0", - "project": resolved_project, - "goal_id": resolved_goal_id, - "agent_id": agent_id, - "cli_bin": cli_bin, - "install_repair_command": bootstrap["install_repair_command"], - "review_packet_command": review_packet_command, - "message_only_command": message_only_command, - "heartbeat_prompt_command": bootstrap["heartbeat_prompt_command"], - "heartbeat_prompt_json_command": bootstrap["heartbeat_prompt_json_command"], - "quota_guard_command": bootstrap["quota_guard_command"], - "refresh_command": bootstrap["refresh_command"], - "progress_refresh_command": bootstrap["progress_refresh_command"], - "quota_spend_command": bootstrap["quota_spend_command"], - "validation_checklist": validation_checklist, - "boundary": boundary, - } - - -def build_codex_cli_exec_handoff( - *, - project: Path, - goal_id: str | None, - agent_id: str | None, - cli_bin: str, - codex_bin: str, -) -> dict[str, Any]: - bootstrap = build_codex_cli_bootstrap_message( - project=project, - goal_id=goal_id, - agent_id=agent_id, - cli_bin=cli_bin, - ) - resolved_project = str(project.expanduser()) - resolved_goal_id = str(bootstrap["goal_id"]) - agent_arg = f" --agent-id {shell_arg(agent_id)}" if agent_id else "" - message_only_command = ( - f"{shell_arg(cli_bin)} codex-cli-bootstrap-message " - f"--project {shell_arg(resolved_project)} " - f"--goal-id {shell_arg(resolved_goal_id)}{agent_arg} --message-only" - ) - return { - "ok": True, - "schema_version": "codex_cli_exec_handoff_v0", - "mode": "headless_fallback_disabled_for_goal_mode_bootstrap", - "primary_experience": "codex_cli_tui_goal_bootstrap", - "project": resolved_project, - "goal_id": resolved_goal_id, - "agent_id": agent_id, - "cli_bin": cli_bin, - "codex_bin": codex_bin, - "disabled_reason": ( - "Default Codex CLI LoopX bootstrap must stay visible in the TUI; " - "headless codex exec handoff is disabled to avoid accidental hidden execution." - ), - "session_probe_command": f"{shell_arg(cli_bin)} codex-cli-session-probe --codex-bin {shell_arg(codex_bin)}", - "quota_guard_command": bootstrap["quota_guard_command"], - "progress_refresh_command": bootstrap["progress_refresh_command"], - "refresh_command": bootstrap["refresh_command"], - "quota_spend_command": bootstrap["quota_spend_command"], - "heartbeat_prompt_json_command": bootstrap["heartbeat_prompt_json_command"], - "message_only_command": message_only_command, - "handoff_command": "", - "boundary": { - "runs_codex": False, - "reads_raw_transcripts": False, - "reads_credentials": False, - "reads_session_files": False, - "mutates_codex_session": False, - "spends_loopx_quota": False, - "headless_execution_disabled": True, - "provides_executable_headless_command": False, - }, - } - - def render_codex_cli_bootstrap_message_text( *, project: str, @@ -1217,82 +1097,3 @@ def render_codex_cli_bootstrap_message_markdown(payload: dict[str, Any]) -> str: - cli_bin: `{payload.get("cli_bin")}` - heartbeat_prompt_drift_check: `{payload.get("heartbeat_prompt_command")}` """ - - -def render_codex_cli_tui_bootstrap_smoke_bundle_markdown(payload: dict[str, Any]) -> str: - boundary = payload.get("boundary") or {} - checklist = "\n".join(f"- {item}" for item in payload.get("validation_checklist", [])) - return f"""# Codex CLI TUI Bootstrap Smoke Bundle - -This packet is for validating the first-run Codex CLI path without launching or -mutating a real Codex session. - -## Commands - -```bash -{payload.get("message_only_command", "")} -``` - -- review_packet: `{payload.get("review_packet_command")}` -- heartbeat_prompt: `{payload.get("heartbeat_prompt_command")}` -- heartbeat_prompt_json: `{payload.get("heartbeat_prompt_json_command")}` -- quota_guard: `{payload.get("quota_guard_command")}` -- accountable_progress_refresh: `{payload.get("progress_refresh_command")}` -- quota_spend_after_validation: `{payload.get("quota_spend_command")}` -- optional_state_only_refresh_after_spend: `{payload.get("refresh_command")}` - -## Fresh Repo Install Repair - -```bash -{payload.get("install_repair_command", "")} -``` - -## Transcript-Free Boundary - -- runs_codex: `{boundary.get("runs_codex")}` -- reads_raw_transcripts: `{boundary.get("reads_raw_transcripts")}` -- reads_session_files: `{boundary.get("reads_session_files")}` -- reads_credentials: `{boundary.get("reads_credentials")}` -- mutates_codex_session: `{boundary.get("mutates_codex_session")}` -- spends_loopx_quota: `{boundary.get("spends_loopx_quota")}` -- requires_loopx_repo_clone: `{boundary.get("requires_loopx_repo_clone")}` - -## Validation Checklist - -{checklist} -""" - - -def render_codex_cli_exec_handoff_markdown(payload: dict[str, Any]) -> str: - boundary = payload.get("boundary") or {} - return f"""# Codex CLI Exec Handoff Disabled - -The default Codex CLI LoopX bootstrap is visible setup, then thin -`/goal ` activation. Headless `codex exec` handoff is disabled here -to avoid accidental hidden execution. Use the message-only command below inside -the visible Codex CLI TUI. - -````bash -{payload.get("message_only_command", "")} -```` - -## Guard Commands - -- session_probe: `{payload.get("session_probe_command")}` -- quota_guard: `{payload.get("quota_guard_command")}` -- accountable_progress_refresh: `{payload.get("progress_refresh_command")}` -- quota_spend: `{payload.get("quota_spend_command")}` -- optional_state_only_refresh_after_spend: `{payload.get("refresh_command")}` -- disabled_reason: {payload.get("disabled_reason")} - -## Boundary - -- runs_codex: `{boundary.get("runs_codex")}` -- reads_raw_transcripts: `{boundary.get("reads_raw_transcripts")}` -- reads_credentials: `{boundary.get("reads_credentials")}` -- reads_session_files: `{boundary.get("reads_session_files")}` -- mutates_codex_session: `{boundary.get("mutates_codex_session")}` -- spends_loopx_quota: `{boundary.get("spends_loopx_quota")}` -- headless_execution_disabled: `{boundary.get("headless_execution_disabled")}` -- provides_executable_headless_command: `{boundary.get("provides_executable_headless_command")}` -""" diff --git a/man/loopx.1 b/man/loopx.1 index 5a3c418659..bda8dcb29b 100644 --- a/man/loopx.1 +++ b/man/loopx.1 @@ -164,12 +164,6 @@ Remove one exact host thread binding without unregistering its agent or peer ses \fBloopx codex\-cli\-bootstrap\-message\fR Generate the visible Codex CLI TUI setup message. .TP -\fBloopx codex\-cli\-tui\-bootstrap\-smoke\-bundle\fR -Generate a transcript\-free Codex CLI first\-run smoke bundle. -.TP -\fBloopx codex\-cli\-visible\-attach\-acceptance\fR -Check public\-safe visible Codex CLI attach evidence. -.TP \fBloopx heartbeat\-prompt\fR Generate a guarded heartbeat automation body. .TP diff --git a/tests/architecture/top_level_module_budget.json b/tests/architecture/top_level_module_budget.json index 5ac0dc081a..5eb69d838b 100644 --- a/tests/architecture/top_level_module_budget.json +++ b/tests/architecture/top_level_module_budget.json @@ -1,6 +1,6 @@ { "schema": "loopx_top_level_module_budget_v0", - "baseline_commit": "a4483aaece5bc74ec3f969fd067229487022401b", - "max_top_level_modules": 127, + "baseline_commit": "0514512ee7fbdf5548c88d07763a41dbfc5df931", + "max_top_level_modules": 124, "allowlist": ["__init__.py", "entrypoint.py", "cli.py"] } diff --git a/tests/control_plane/test_codex_cli_scheduler_effect_program.py b/tests/control_plane/test_codex_cli_scheduler_effect_program.py deleted file mode 100644 index a423a652aa..0000000000 --- a/tests/control_plane/test_codex_cli_scheduler_effect_program.py +++ /dev/null @@ -1,60 +0,0 @@ -from __future__ import annotations - -from pathlib import Path - -from loopx.codex_cli_probe import classify_codex_cli_session_surface -from loopx.codex_cli_scheduler import build_codex_cli_local_scheduler_tick -from loopx.control_plane.effect_program import effect_program_from_ordered_steps - -PROJECT = Path("/tmp/public-codex-cli-project") -GOAL_ID = "public-codex-cli-goal" -AGENT_ID = "codex-side-bypass" - -FALLBACK_HELP_FIXTURE = { - "root": """ -Usage: codex [OPTIONS] [PROMPT] - -Commands: - exec Run Codex non-interactively - resume Resume a previous conversation -""", - "exec": "Usage: codex exec [OPTIONS] [PROMPT]", - "resume": "Usage: codex resume [SESSION_ID]", -} - - -def test_scheduler_commands_round_trip_through_effect_program() -> None: - payload = build_codex_cli_local_scheduler_tick( - project=PROJECT, - goal_id=GOAL_ID, - agent_id=AGENT_ID, - cli_bin="loopx", - codex_bin="codex", - probe_payload=classify_codex_cli_session_surface( - command_outputs=FALLBACK_HELP_FIXTURE - ), - ) - commands = payload["commands"] - - assert set(commands) == { - "visible_driver_run", - "runtime_idle_detector", - "runtime_idle_detector_fixture", - "scheduler_tick", - "candidate_codex_command", - "blocker_writeback", - } - program = effect_program_from_ordered_steps( - [ - {"id": step_id, "kind": "codex_cli_command", "command": command} - for step_id, command in commands.items() - if command - ], - execution_mode="serial", - ) - assert program.execution_mode == "serial" - assert {step.step_id: step.command for step in program.steps} == { - step_id: command - for step_id, command in commands.items() - if command - } diff --git a/tests/test_release_smoke_archive_helpers.py b/tests/test_release_smoke_archive_helpers.py index d438062b41..f53055f38c 100644 --- a/tests/test_release_smoke_archive_helpers.py +++ b/tests/test_release_smoke_archive_helpers.py @@ -10,7 +10,6 @@ REPOSITORY_ROOT = Path(__file__).resolve().parents[1] ARCHIVE_SMOKES = ( Path("examples/codex-cli-packaged-install-smoke.py"), - Path("examples/codex-cli-tui-bootstrap-smoke-bundle-smoke.py"), Path("examples/release/codex-cli-no-clone-release-verification-smoke.py"), )