From b0f865c00c50b25c60265c397d0c0aa348c60e57 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Thu, 19 Nov 2026 20:44:06 +0800 Subject: [PATCH] Codex now holds /review to its checklist before a session can end (GST-3173) (#4522) On Codex, gstack's /review can no longer end a session with a required step skipped: the end-of-session check reads Codex's own session log and sends the agent back to finish, as it already does on Claude Code. Why: Codex users got routing and the destructive-command check in #4512, but not the /review checklist, so a review could stop after the diff read with no second-model pass. To use it: run `./setup` again and trust the new hook in Codex (`/hooks`); turn it off with `GSTACK_SKILL_CONTRACTS=off`. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=testing Review-Finding: p1/specialist-batched#2 reader=testing --- bin/gstack-settings-hook | 3 +- bin/gstack-skill-contract | 21 +- changelog.d/codex-review-contract-hook.md | 1 + docs/skill-routing-and-contracts.md | 24 +- .../claude/hooks/skill-contract-stop-hook.ts | 18 +- .../hooks/codex-skill-contract-stop-hook | 11 + .../hooks/codex-skill-contract-stop-hook.ts | 9 + lib/codex-rollout.ts | 174 ++++++++++ lib/skill-contract.ts | 70 ++++- scripts/resolvers/contract-done-means.ts | 2 +- setup | 8 +- test/codex-hooks-real-codex.test.ts | 3 +- test/codex-hooks-setup.test.ts | 21 +- .../skill-contract/block-message-codex.txt | 1 + test/fixtures/skill-contract/codex/README.md | 23 ++ .../app-server-injected-early-exit.jsonl | 22 ++ .../codex/exec-mention-not-loaded.jsonl | 25 ++ .../codex/exec-read-blocked.jsonl | 28 ++ .../codex/exec-read-failed-spawn.jsonl | 38 +++ .../skill-contract/codex/exec-read-met.jsonl | 43 +++ .../skill-contract/codex/exec-subagent.jsonl | 16 + .../skill-contract/codex/stop-payloads.json | 44 +++ test/helpers/free-fixtures-data.ts | 2 +- test/skill-contract-codex.test.ts | 297 ++++++++++++++++++ 24 files changed, 856 insertions(+), 48 deletions(-) create mode 100644 changelog.d/codex-review-contract-hook.md create mode 100755 hosts/codex/hooks/codex-skill-contract-stop-hook create mode 100755 hosts/codex/hooks/codex-skill-contract-stop-hook.ts create mode 100644 lib/codex-rollout.ts create mode 100644 test/fixtures/skill-contract/block-message-codex.txt create mode 100644 test/fixtures/skill-contract/codex/README.md create mode 100644 test/fixtures/skill-contract/codex/app-server-injected-early-exit.jsonl create mode 100644 test/fixtures/skill-contract/codex/exec-mention-not-loaded.jsonl create mode 100644 test/fixtures/skill-contract/codex/exec-read-blocked.jsonl create mode 100644 test/fixtures/skill-contract/codex/exec-read-failed-spawn.jsonl create mode 100644 test/fixtures/skill-contract/codex/exec-read-met.jsonl create mode 100644 test/fixtures/skill-contract/codex/exec-subagent.jsonl create mode 100644 test/fixtures/skill-contract/codex/stop-payloads.json create mode 100644 test/skill-contract-codex.test.ts diff --git a/bin/gstack-settings-hook b/bin/gstack-settings-hook index 73225f140..161fd9dee 100755 --- a/bin/gstack-settings-hook +++ b/bin/gstack-settings-hook @@ -164,7 +164,8 @@ var KNOWN_HOOKS = { "autoplan-stop-gate-stop": { source: "gstack-autoplan-gate", event: "Stop", matcher: "", relpath: "hosts/claude/hooks/autoplan-stop-gate-stop" }, "autoplan-stop-gate-publish": { source: "gstack-autoplan-gate", event: "PreToolUse", matcher: "Bash", relpath: "hosts/claude/hooks/autoplan-stop-gate-publish" }, "codex-skill-route-hook": { source: "gstack-skill-route", event: "UserPromptSubmit", matcher: "", relpath: "hosts/codex/hooks/codex-skill-route-hook", host: "codex" }, - "codex-destructive-guard-hook": { source: "gstack-destructive-guard", event: "PreToolUse", matcher: "Bash", relpath: "hosts/codex/hooks/codex-destructive-guard-hook", host: "codex" } + "codex-destructive-guard-hook": { source: "gstack-destructive-guard", event: "PreToolUse", matcher: "Bash", relpath: "hosts/codex/hooks/codex-destructive-guard-hook", host: "codex" }, + "codex-skill-contract-stop-hook": { source: "gstack-skill-contract", event: "Stop", matcher: "", relpath: "hosts/codex/hooks/codex-skill-contract-stop-hook", host: "codex" } }; // GSTACK_HOOKS_FORMAT=codex: the file is Codex hooks.json, and only rows with // host codex identify gstack items in it; every other row belongs to diff --git a/bin/gstack-skill-contract b/bin/gstack-skill-contract index 000c5ea45..415155134 100755 --- a/bin/gstack-skill-contract +++ b/bin/gstack-skill-contract @@ -1,7 +1,8 @@ #!/usr/bin/env -S bun --no-env-file --config=/dev/null /** * gstack-skill-contract — check a skill's contract against a Claude Code - * transcript, list recorded misses, and acknowledge a waiver (GST-1088). + * transcript or a Codex rollout, list recorded misses, and acknowledge a + * waiver (GST-1088, GST-3173). * * Usage: * gstack-skill-contract check --transcript --skill [--skill-file ] [--json] @@ -19,7 +20,7 @@ */ import { EXIT, StateError, UnknownShape, blockMessage, checkContract, isMiss, lookupContract, parseTranscript, readAllRecords, - readTranscriptFile, reportRows, skippedLine, type CheckResult, + readTranscriptFile, reportRows, skippedLine, transcriptContract, type CheckResult, type Transcript, } from '../lib/skill-contract'; import { fileURLToPath } from 'node:url'; import { installedSkillsDir } from '../lib/skill-route'; @@ -67,13 +68,18 @@ function check(args: string[]): never { const skill = flag(args, '--skill'); const json = args.includes('--json'); if (!transcriptPath || !skill) die(EXIT.USAGE, `SKILL_CONTRACT_USAGE: check needs --transcript and --skill\n${USAGE}`); - const found = lookupContract(skill, installedSkillsDir(), flag(args, '--skill-file')); + const skillFile = flag(args, '--skill-file'); + let transcript: Transcript | null = null; + let readError: unknown = null; + try { transcript = parseTranscript(readTranscriptFile(transcriptPath)); } catch (e) { readError = e; } + const found = skillFile || !transcript ? lookupContract(skill, installedSkillsDir(), skillFile) : transcriptContract(transcript, skill); if (!('contract' in found)) die(EXIT.NO_CONTRACT, `SKILL_CONTRACT_NO_CONTRACT ${skill}: ${found.error}`); for (const why of found.contract.skipped ?? []) process.stderr.write(`${skippedLine(found.file, why)} `); let result: CheckResult; try { - result = checkContract(parseTranscript(readTranscriptFile(transcriptPath)), skill, found.contract); + if (readError) throw readError; + result = checkContract(transcript as Transcript, skill, found.contract); } catch (e) { if (e instanceof StateError) die(EXIT.STATE_ERROR, `SKILL_CONTRACT_STATE_ERROR ${e.file}: ${e.why}`); if (e instanceof UnknownShape) die(EXIT.UNKNOWN_SHAPE, `SKILL_CONTRACT_UNKNOWN_SHAPE ${transcriptPath}: ${e.message}`); @@ -90,10 +96,11 @@ function report(args: string[]): never { const session = flag(args, '--session'); const { records, errors } = readAllRecords(); const rows = reportRows(records.filter(r => !session || r.session_id === session), (rec, run) => { - const found = lookupContract(run.skill, installedSkillsDir()); - if (!('contract' in found)) return null; try { - const again = checkContract(parseTranscript(readTranscriptFile(rec.transcript_path)), run.skill, found.contract, { loadLine: run.load_line }); + const t = parseTranscript(readTranscriptFile(rec.transcript_path)); + const found = transcriptContract(t, run.skill); + if (!('contract' in found)) return null; + const again = checkContract(t, run.skill, found.contract, { loadLine: run.load_line }); return again.load ? again : null; } catch { return null; diff --git a/changelog.d/codex-review-contract-hook.md b/changelog.d/codex-review-contract-hook.md new file mode 100644 index 000000000..c7ec24f10 --- /dev/null +++ b/changelog.d/codex-review-contract-hook.md @@ -0,0 +1 @@ +- **On Codex, /review is now held once when it tries to finish without its adversarial pass or its report, as it already is on Claude Code.** `./setup --host codex` adds the skill-contract Stop hook to `~/.codex/hooks.json` next to the routing hint and the destructive-command check, and Codex runs it once you trust it at its startup prompt or in `/hooks`. The hook reads Codex's rollout file (it tells a Codex rollout from a Claude Code transcript by what the file holds), counts a skill as loaded when Codex injects or the model reads a `gstack-*` SKILL.md, and counts a `spawn_agent` call that started an agent as a dispatch. /review's specialist-reviewer item is skipped on Codex, which doesn't run those reviewers yet. `gstack-skill-contract check` takes a Codex rollout too. The same `skill_contracts` switch turns it off on both hosts. Details: docs/skill-routing-and-contracts.md#codex. diff --git a/docs/skill-routing-and-contracts.md b/docs/skill-routing-and-contracts.md index 0ece37ec2..a483c3345 100644 --- a/docs/skill-routing-and-contracts.md +++ b/docs/skill-routing-and-contracts.md @@ -1,6 +1,6 @@ # Skill routing and skill contracts -Three Claude Code hooks that help a model actually run gstack's skills (GST-1088, GST-3110); two of them also run on Codex ([Codex](#codex)). All three are on by default. On Opus 5.5, unattended, a hook line naming a skill got it loaded in 58 of 60 bug-fix sessions, where the same skill relying on its description loaded in 0 of 60 (gstack-evals#369, and B1 before it on the same 60 tasks). With the contract hook, all 66 /review sessions ran its specialist reviewers, 42 of them after the hook's one block; in an earlier run without it, 0 of 66 did (gstack-evals board posts GEVA-271 and GEVA-105). Each has one default, `SWITCH_DEFAULT` in `lib/skill-route.ts`; `gstack-config defaults` prints it. With all three off nothing changes. The opt-in gates that hold one skill rule mid-run (the /plan-ceo-review and /autoplan gates) are in [skill-gates.md](skill-gates.md). +Three Claude Code hooks that help a model actually run gstack's skills (GST-1088, GST-3110); all three also run on Codex ([Codex](#codex)). All three are on by default. On Opus 5.5, unattended, a hook line naming a skill got it loaded in 58 of 60 bug-fix sessions, where the same skill relying on its description loaded in 0 of 60 (gstack-evals#369, and B1 before it on the same 60 tasks). With the contract hook, all 66 /review sessions ran its specialist reviewers, 42 of them after the hook's one block; in an earlier run without it, 0 of 66 did (gstack-evals board posts GEVA-271 and GEVA-105). Each has one default, `SWITCH_DEFAULT` in `lib/skill-route.ts`; `gstack-config defaults` prints it. With all three off nothing changes. The opt-in gates that hold one skill rule mid-run (the /plan-ceo-review and /autoplan gates) are in [skill-gates.md](skill-gates.md). - **Skill routing** (`skill_routing`, a UserPromptSubmit hook). When a prompt matches an installed skill's `triggers:`, the hook adds one line of context naming that skill, for example "this request fits /verify. Run /verify with the Skill tool before you start". - **Skill contracts** (`skill_contracts`, a Stop hook). A skill can declare the outputs that must exist before it is done. When the model tries to stop without them, the hook blocks once and names what is missing. @@ -32,8 +32,8 @@ The off switch is for people. The text the Stop hook shows the model never menti | Host | Routing hook | Contract Stop hook | Destructive-command check | Notes | |---|---|---|---|---| | Claude Code | yes | yes | yes | Registered in `~/.claude/settings.json` by `./setup` | -| Codex | yes | not yet | yes, with a deny where Claude Code asks | Registered in `${CODEX_HOME:-~/.codex}/hooks.json` by `./setup --host codex` (Codex 0.170 or newer). Codex runs them only after you trust them: see [Codex](#codex) | -| OpenCode, Cursor and other hosts | no | no | no | gstack registers no hooks on these hosts. `gstack-skill-contract check` still works on a Claude Code transcript | +| Codex | yes | yes, without /review's specialists item | yes, with a deny where Claude Code asks | Registered in `${CODEX_HOME:-~/.codex}/hooks.json` by `./setup --host codex` (Codex 0.170 or newer). Codex runs them only after you trust them: see [Codex](#codex) | +| OpenCode, Cursor and other hosts | no | no | no | gstack registers no hooks on these hosts. `gstack-skill-contract check` still works on a Claude Code transcript or a Codex rollout | ## Routing @@ -83,9 +83,9 @@ The hook reads `destructive_guard` every time it runs, so `gstack-config set des ## Codex -`./setup --host codex` (or `./setup --host auto` when `codex` is on your PATH) registers the routing hook and the destructive-command check in `${CODEX_HOME:-~/.codex}/hooks.json`, each in its own matcher group: routing on `UserPromptSubmit` with a 5-second timeout, the check on `PreToolUse` for `Bash` with a 10-second timeout. The contract Stop hook is not on Codex yet. The same three switches, in the same order, turn them on and off on both hosts; Codex adds its own two, a hook's toggle in `/hooks` and `[features] hooks = false` in `config.toml` for every hook at once. +`./setup --host codex` (or `./setup --host auto` when `codex` is on your PATH) registers the routing hook, the contract Stop hook and the destructive-command check in `${CODEX_HOME:-~/.codex}/hooks.json`, each in its own matcher group: routing on `UserPromptSubmit` with a 5-second timeout, the contract hook on `Stop` with a 10-second timeout (as on Claude Code), the check on `PreToolUse` for `Bash` with a 10-second timeout. The same three switches, in the same order, turn them on and off on both hosts; Codex adds its own two, a hook's toggle in `/hooks` and `[features] hooks = false` in `config.toml` for every hook at once. -**You trust them once.** Codex runs a hook only after you trust it, and skips an untrusted one without saying so. Setup never writes that trust. It prints one line, "gstack added 2 Codex hook(s); trust them at Codex's startup prompt or in /hooks", and the next time you start Codex it shows "Hooks need review": pick "Trust all and continue", or review them one by one in `/hooks`. `gstack-doctor` has a `codex hooks` row saying whether `config.toml` holds a trust entry for each of gstack's hooks. It only checks that an entry exists; it never computes Codex's hash. Codex asks again when a hook's command or timeout changes, so the commands point at the stable runtime root (`${CODEX_HOME:-~/.codex}/skills/gstack/hosts/codex/hooks/`), and an upgrade that only changes the scripts behind them asks nothing. Codex also keys trust by a group's position in the file, so setup adds gstack's groups after yours and never reorders them. Evals and CI that run `codex exec` pass `--dangerously-bypass-hook-trust`. +**You trust them once.** Codex runs a hook only after you trust it, and skips an untrusted one without saying so. Setup never writes that trust. It prints one line, "gstack added 3 Codex hook(s); trust them at Codex's startup prompt or in /hooks", and the next time you start Codex it shows "Hooks need review": pick "Trust all and continue", or review them one by one in `/hooks`. `gstack-doctor` has a `codex hooks` row saying whether `config.toml` holds a trust entry for each of gstack's hooks. It only checks that an entry exists; it never computes Codex's hash. Codex asks again when a hook's command or timeout changes, so the commands point at the stable runtime root (`${CODEX_HOME:-~/.codex}/skills/gstack/hosts/codex/hooks/`), and an upgrade that only changes the scripts behind them asks nothing. Codex also keys trust by a group's position in the file, so setup adds gstack's groups after yours and never reorders them. Evals and CI that run `codex exec` pass `--dangerously-bypass-hook-trust`. **Your own hooks stay as they are.** Codex 0.170 skips the whole `hooks.json` when it holds a key it does not know, your hooks included. So gstack adds no marker keys (it recognizes its groups by their command path), checks the new file against Codex's schema before moving it into place, and keeps the lock, the `hooks.json.bak.` backup and `gstack-settings-hook rollback` that `settings.json` has (`GSTACK_HOOKS_FORMAT=codex gstack-settings-hook rollback`). Setup leaves the file alone, prints why and carries on when the file does not parse or already fails Codex's schema, when `config.toml` does not parse, or when `config.toml` already declares one of gstack's hooks under `[hooks]` (Codex would run it twice). It also skips the hooks, saying why, when `codex` is missing or older than 0.170. `./setup --host codex --no-team` (plain `./setup --no-team` installs for Claude Code only, so it leaves the Codex hooks alone; `--host auto` with `codex` on your PATH also reaches them) and `gstack-uninstall` remove gstack's groups and nothing else. If one of your own hooks comes after gstack's group in the same event, removing gstack's group would shift yours to a new position and Codex would stop trusting it (`codex exec` skips an untrusted hook without asking). So gstack leaves the file unchanged and says so; delete gstack's group by hand and re-trust your hooks in `/hooks`. @@ -93,6 +93,14 @@ The hook reads `destructive_guard` every time it runs, so `gstack-config set des **The destructive-command check on Codex** runs the same `check-careful.sh`, but Codex has no "ask": its hook parser rejects `permissionDecision: "ask"` and lets the command run. So in an interactive Codex session, every command the check would ask about is blocked instead, and the reason tells the model to stop and ask you. If you want it, run it yourself by typing `!` and the command in Codex (Codex runs `!` commands without hooks), or turn the check off. In `codex exec`, and any session `gstack-session-kind` reports as headless or unattended, it is a warning and the command runs, as on Claude Code. The two deny shapes stay a deny everywhere. Codex already refuses some `rm -rf` commands by itself, before any hook runs. +**Contracts on Codex** use the same Stop hook, with the same one block per skill run, records and fail-open rules; Codex sends it the same `stop_hook_active` and `last_assistant_message` keys and takes the same block answer. The transcript is Codex's rollout file (`~/.codex/sessions///
/rollout-*.jsonl`), and the checker tells it from a Claude Code transcript by what the file holds (a rollout starts with a `session_meta` record), never by its path. On Codex: + +- A **load** is Codex injecting a `gstack-*` skill into the conversation as a `` message (the app server's skill input does this), or the model reading one with a shell command such as `cat ~/.codex/skills/gstack-review/SKILL.md`. `codex exec '$gstack-review ...'` passes the `$` mention as plain text, so in `exec` the skill loads only when the model reads it. +- A **dispatch** is a `spawn_agent` call that started an agent. One that failed (its result has no `agent_id`) doesn't count. +- **The contract** comes from gstack's own copy of the skill (`/review/SKILL.md`), because Codex's installed `SKILL.md` keeps only its name and description. +- **/review's `specialists-dispatched` item is skipped**, because Codex doesn't run /review's specialist reviewers yet. The adversarial pass and the report are checked as on Claude Code, and the block text names `spawn_agent` and `wait_agent` where Claude Code's names an Agent dispatch. +- **A subagent's own rollout is never checked**: its first record names the parent thread. + **Reasoning effort.** gstack's workflows do best at high reasoning effort. Setup leaves your `config.toml` alone and prints a reminder; start Codex with `codex -c model_reasoning_effort=high` when you run them. ## Contracts @@ -149,7 +157,7 @@ It blocks at most once per skill run. If the model stops again with the contract ### Records -Each Claude Code session has one record, `$GSTACK_STATE_ROOT/skill-contracts/.json`, written atomically (mode 0600) before any block. Each skill run in it has an outcome: `met`, `met_waived`, `blocked`, `met_after_block`, `miss` or `deferred` (stopped while its agents were still running, not yet checked; `report` re-checks it against its transcript). The hook's decisions also go to `$GSTACK_STATE_ROOT/hooks/skill-contract.log`. +Each session has one record, `$GSTACK_STATE_ROOT/skill-contracts/.json`, written atomically (mode 0600) before any block. Each skill run in it has an outcome: `met`, `met_waived`, `blocked`, `met_after_block`, `miss` or `deferred` (stopped while its agents were still running, not yet checked; `report` re-checks it against its transcript). The hook's decisions also go to `$GSTACK_STATE_ROOT/hooks/skill-contract.log`. ## Commands @@ -157,7 +165,7 @@ Each Claude Code session has one record, `$GSTACK_STATE_ROOT/skill-contracts/ --skill [--skill-file ] [--json] -A pure function of a Claude Code transcript (the JSONL a hook payload's `transcript_path` names, under `~/.claude/projects/`). The contract comes from the installed skill's frontmatter, or from `--skill-file`. It prints each item as met, missing or waived. The model never records anything itself, so evals can run the same check on their own transcripts. +A pure function of a Claude Code transcript or a Codex rollout (the JSONL a hook payload's `transcript_path` names, under `~/.claude/projects/` or `~/.codex/sessions/`). The contract comes from the installed skill's frontmatter (on Codex, gstack's own copy of the skill), or from `--skill-file`. It prints each item as met, missing or waived. The model never records anything itself, so evals can run the same check on their own transcripts. ### report @@ -203,7 +211,7 @@ The stop goes through and nothing is recorded. Fix the named path: make `$GSTACK ### 4: unknown transcript shape (SKILL_CONTRACT_UNKNOWN_SHAPE) -The file is not a Claude Code transcript this checker understands (no user or assistant records, or message content that is neither text nor a block list), for example after a Claude Code format change. The Stop hook fails open with a state error line and adds one to `$GSTACK_STATE_ROOT/hooks/skill-contract.canary.json`. A rising canary count means the parser needs an update. +The file is not a transcript this checker understands: a Claude Code transcript with no user or assistant records, or message content that is neither text nor a block list, or a Codex rollout with no message records or a record shaped in a way the reader doesn't know. That usually means Claude Code or Codex changed its format. The Stop hook fails open with a state error line and adds one to `$GSTACK_STATE_ROOT/hooks/skill-contract.canary.json`. A rising canary count means the parser needs an update. ### 5: no contract (SKILL_CONTRACT_NO_CONTRACT) diff --git a/hosts/claude/hooks/skill-contract-stop-hook.ts b/hosts/claude/hooks/skill-contract-stop-hook.ts index 80aba4574..1dcd58103 100755 --- a/hosts/claude/hooks/skill-contract-stop-hook.ts +++ b/hosts/claude/hooks/skill-contract-stop-hook.ts @@ -7,7 +7,12 @@ * * stdin -> switch on? -> transcript_path -> parse (+ last_assistant_message), * re-read until it holds that final message (lib/skill-gates.ts - * readSettledTranscript; Stop can beat the CLI's flush) + * readSettledTranscript; Stop can beat the CLI's flush). A Codex rollout + * is read by lib/codex-rollout.ts, picked by content; Codex sends the + * same payload keys and takes the same block output. A Codex subagent's + * own rollout is never checked (allow). Codex starts hooks without + * CODEX_THREAD_ID, so on Codex the payload's session_id stands in for it + * when gstack-session-kind runs, as in the Codex destructive-command hook * -> the most recently loaded skill that declares a contract (none: allow) * -> final turn? (a STATUS line, a headless or unattended session, or no * pending user question; otherwise allow) @@ -31,10 +36,10 @@ * Docs: docs/skill-routing-and-contracts.md. */ import { binPath, sessionKind } from './spawn-bin'; -import { appendHookTrace, installedSkillsDir, readSkillSwitch, readStdinBounded } from '../../../lib/skill-route'; +import { appendHookTrace, hookHost, readSkillSwitch, readStdinBounded } from '../../../lib/skill-route'; import { - AGENT_STALL_MS, StateError, UnknownShape, blockMessage, bumpCanary, checkContract, isFinalTurn, lookupContract, nextOutcome, skippedLine, - readRecord, recordPath, runKey, sameSkill, skillLoads, stateErrorLine, writeRecord, + AGENT_STALL_MS, StateError, UnknownShape, blockMessage, bumpCanary, checkContract, isFinalTurn, nextOutcome, skippedLine, + readRecord, recordPath, runKey, sameSkill, skillLoads, stateErrorLine, transcriptContract, writeRecord, type Contract, type Transcript, } from '../../../lib/skill-contract'; import { readSettledTranscript } from '../../../lib/skill-gates'; @@ -61,12 +66,11 @@ function unknownShape(file: string, why: string): void { /** The most recently loaded skill that declares a contract. An invalid contract is a state error. */ function target(t: Transcript): { skill: string; contract: Contract } | null { - const dir = installedSkillsDir(); const tried: string[] = []; for (const load of skillLoads(t).reverse()) { if (tried.some(s => sameSkill(s, load.skill))) continue; tried.push(load.skill); - const found = lookupContract(load.skill, dir); + const found = transcriptContract(t, load.skill); if ('contract' in found) { for (const why of found.contract.skipped ?? []) process.stderr.write(`${skippedLine(found.file, why)} `); @@ -94,6 +98,7 @@ async function main(): Promise { sessionId = typeof payload.session_id === 'string' ? payload.session_id : ''; const transcriptPath = typeof payload.transcript_path === 'string' ? payload.transcript_path : ''; if (!transcriptPath || !sessionId) return unknownShape('', 'payload has no transcript_path or session_id'); + if (hookHost() === 'codex' && !process.env.CODEX_THREAD_ID) process.env.CODEX_THREAD_ID = sessionId; let transcript: Transcript; try { transcript = readSettledTranscript(transcriptPath, payload.last_assistant_message).t; @@ -101,6 +106,7 @@ async function main(): Promise { if (e instanceof UnknownShape) return unknownShape(transcriptPath, e.message); throw e; } + if (transcript.subagent) return trace({ event: 'codex-subagent' }); const t = target(transcript); if (!t) return trace({ event: 'no-contract-skill' }); const result = checkContract(transcript, t.skill, t.contract); diff --git a/hosts/codex/hooks/codex-skill-contract-stop-hook b/hosts/codex/hooks/codex-skill-contract-stop-hook new file mode 100755 index 000000000..983bdef8e --- /dev/null +++ b/hosts/codex/hooks/codex-skill-contract-stop-hook @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# Bash shim for Codex: Codex runs hook commands through a login shell, so this +# wrapper makes the TypeScript hook executable via bun. ${CODEX_HOME}/hooks.json +# references it through the Codex runtime root (${CODEX_HOME}/skills/gstack, +# whose hosts/codex/hooks links here), so pwd -P finds the checkout. +# +# FAIL-OPEN: every failure path — bun missing, script crash — still exits 0. +GSTACK_BUN_CONFIG=/dev/null; case "${OSTYPE:-}" in msys*|cygwin*) if command -v cygpath >/dev/null 2>&1; then GSTACK_BUN_CONFIG=NUL; fi ;; esac +HERE="$(cd "$(dirname "$0")" && pwd -P)" || exit 0 +GSTACK_HOOK_HOST=codex bun --no-env-file --config="${GSTACK_BUN_CONFIG:-/dev/null}" "$HERE/codex-skill-contract-stop-hook.ts" || true +exit 0 diff --git a/hosts/codex/hooks/codex-skill-contract-stop-hook.ts b/hosts/codex/hooks/codex-skill-contract-stop-hook.ts new file mode 100755 index 000000000..1a4228c66 --- /dev/null +++ b/hosts/codex/hooks/codex-skill-contract-stop-hook.ts @@ -0,0 +1,9 @@ +#!/usr/bin/env -S bun --no-env-file --config=/dev/null +/** + * codex-skill-contract-stop-hook — the skill-contract Stop hook on Codex (GST-3173). It is Claude Code's hook + * (hosts/claude/hooks/skill-contract-stop-hook.ts) unchanged: Codex sends the same stop_hook_active and + * last_assistant_message keys and takes the same block answer, and lib/skill-contract.ts reads Codex's rollout file, + * which it tells from a Claude Code transcript by content. Same switch (skill_contracts), deadline, records and log. + * Docs: docs/skill-routing-and-contracts.md#codex. + */ +import '../../claude/hooks/skill-contract-stop-hook.ts'; diff --git a/lib/codex-rollout.ts b/lib/codex-rollout.ts new file mode 100644 index 000000000..2169647f0 --- /dev/null +++ b/lib/codex-rollout.ts @@ -0,0 +1,174 @@ +/** + * codex-rollout: Codex CLI's rollout JSONL (the file a Codex hook payload's + * transcript_path names, under $CODEX_HOME/sessions/) read as the transcript + * events lib/skill-contract.ts checks (GST-3173). parseTranscript picks this + * reader by the file's content: a rollout's first record is session_meta. + * + * What each Codex record becomes: + * - user message: a prompt, or meta when Codex wrote it (environment + * context, AGENTS.md, a hook's reason, a subagent notification, an + * injected ). An injected gstack-* SKILL.md is also a skill load. + * - assistant message: text. + * - exec_command / shell call: a Bash tool_use whose command is the shell + * line; a command in it that reads a gstack-* SKILL.md under a skills/ + * directory (cat, sed, head and the like) is also a skill load, unless + * the output says that read failed. Reading the same skill again with no + * user prompt or other skill load in between (a long SKILL.md read in + * chunks) continues the run, so it is not a new load. + * - spawn_agent call that started an agent: an Agent dispatch whose prompt + * is its message. One whose output names no agent_id (it failed, or it + * has no output) stays a plain spawn_agent call, so it is not a dispatch. + * - any other call: a tool_use under its own name. Call outputs are + * tool_results; a shell output that exited non-zero is an error. + * Records of other types (event_msg, turn_context, reasoning and the rest) + * are skipped. Throws UnknownShape when a record this reader uses has a shape + * it does not know, including call arguments that are not a JSON object. + */ +import { UnknownShape, type Transcript, type TranscriptEvent } from './skill-contract'; + +const isObject = (v: unknown): v is Record => typeof v === 'object' && v !== null && !Array.isArray(v); + +const META_PREFIX = /^\s*(?:<(?:environment_context|user_instructions|INSTRUCTIONS|skill|hook_prompt|subagent_notification|turn_aborted|user_shell_command|codex_internal_context|context_window_guidance|image_resize_notice|side_conversation)\b|# AGENTS\.md instructions)/; +const SKILL_INJECTION = /^\s*\s*[^<]*<\/name>\s*([^<]+)<\/path>/; +const GSTACK_SKILL_FILE = /(?:^|[\\/])skills[\\/](gstack-[A-Za-z0-9][A-Za-z0-9_-]*)[\\/]SKILL\.md$/; +const SHELL_SKILL_READ = /(?:^|[\\/\s'"=])skills[\\/](gstack-[A-Za-z0-9][A-Za-z0-9_-]*)[\\/]SKILL\.md(?=$|[\s'"`;|&)<>])/g; +const READ_PROGRAM = /(?:^|[\s;|&(`'"])(?:cat|sed|head|tail|nl|less|more|bat|awk|Get-Content)(?=\s)/; +const READ_FAILURE = /No such file|cannot open|can't read|cannot access|Permission denied|Is a directory/i; +const SHELL_SEPARATOR = /&&|\|\||[;|\n]/; +const SHELL_TOOLS = new Set(['exec_command', 'shell', 'shell_command', 'local_shell']); +const EXIT_CODE = /(?:^|\n)Process exited with code (\d+)/; + +/** Whether text is a Codex rollout: its first JSON object line is a session_meta record. */ +export function isCodexRollout(text: string): boolean { + for (const raw of text.split('\n')) { + if (!raw.trim()) continue; + let rec: unknown; + try { rec = JSON.parse(raw); } catch { continue; } + return isObject(rec) && rec.type === 'session_meta' && isObject(rec.payload); + } + return false; +} + +function contentText(content: unknown): string { + if (typeof content === 'string') return content; + if (!Array.isArray(content)) return ''; + return content.filter(c => isObject(c) && typeof c.text === 'string').map(c => c.text).join('\n'); +} + +function args(raw: unknown, line: number): Record { + if (isObject(raw)) return raw; + let parsed: unknown; + try { parsed = typeof raw === 'string' ? JSON.parse(raw) : undefined; } catch { /* reported below */ } + if (!isObject(parsed)) throw new UnknownShape(`line ${line}: call arguments are not a JSON object`); + return parsed; +} + +function shellLine(input: Record): string | null { + for (const v of [input.cmd, input.command]) { + if (typeof v === 'string') return v; + if (Array.isArray(v) && v.every(p => typeof p === 'string')) return v.join(' '); + } + return null; +} + +/** The gstack-* skills a shell line's read commands read, in order of appearance. */ +function shellSkillReads(line: string): string[] { + return line.split(SHELL_SEPARATOR).filter(cmd => READ_PROGRAM.test(cmd)).flatMap(cmd => [...cmd.matchAll(SHELL_SKILL_READ)].map(m => m[1])); +} + +const readFailed = (output: string | undefined, skill: string) => + (output ?? '').split('\n').some(l => READ_FAILURE.test(l) && new RegExp(`skills[\\\\/]${skill}[\\\\/]SKILL\\.md`).test(l)); + +const exitedNonZero = (output: string | undefined) => { + const code = output === undefined ? null : EXIT_CODE.exec(output); + return !!code && code[1] !== '0'; +}; + +const startedAgent = (output: string | undefined) => { + if (output === undefined) return false; + try { + const parsed: unknown = JSON.parse(output); + return isObject(parsed) && typeof parsed.agent_id === 'string' && parsed.agent_id !== ''; + } catch { + return false; + } +}; + +const fromHarness = (payload: Record) => { + const items = payload.internal_chat_message_metadata_passthrough?.content_item_metadata; + return Array.isArray(items) && items.some(m => isObject(m) && isObject(m.provenance) && m.provenance.type === 'harness'); +}; + +/** The main-thread events of a Codex rollout; see the file header. */ +export function parseCodexRollout(text: string): Transcript { + const records: { line: number; type: string; payload: Record }[] = []; + for (const [idx, raw] of text.split('\n').entries()) { + if (!raw.trim()) continue; + let rec: unknown; + try { rec = JSON.parse(raw); } catch { continue; } + if (!isObject(rec) || typeof rec.type !== 'string') continue; + if ((rec.type === 'session_meta' || rec.type === 'response_item') && !isObject(rec.payload)) { + throw new UnknownShape(`line ${idx + 1}: ${rec.type} record without a payload object`); + } + if (isObject(rec.payload)) records.push({ line: idx + 1, type: rec.type, payload: rec.payload }); + } + const outputs = new Map(); + for (const r of records) { + const p = r.payload; + if (r.type === 'response_item' && (p.type === 'function_call_output' || p.type === 'custom_tool_call_output') && typeof p.call_id === 'string') { + outputs.set(p.call_id, contentText(isObject(p.output) ? p.output.content : p.output)); + } + } + const events: TranscriptEvent[] = []; + let sessionId: string | null = null; + let subagent = false; + let messages = 0; + let lastLoad: string | null = null; + for (const { line, type, payload: p } of records) { + if (type === 'session_meta') { + if (sessionId === null && typeof p.id === 'string') sessionId = p.id; + if (isObject(p.source) && 'subagent' in p.source) subagent = true; + continue; + } + if (type !== 'response_item') continue; + if (p.type === 'message') { + if (!Array.isArray(p.content)) throw new UnknownShape(`line ${line}: message content is not a list`); + messages++; + const body = contentText(p.content); + if (p.role === 'assistant') { + if (body) events.push({ kind: 'text', line, text: body }); + } else if (p.role === 'user' && body) { + const injected = SKILL_INJECTION.exec(body); + const skill = injected ? GSTACK_SKILL_FILE.exec(injected[1].trim())?.[1] : undefined; + if (skill) events.push({ kind: 'load', line, skill, via: 'injected' }); + const kind = META_PREFIX.test(body) || fromHarness(p) ? 'meta' : 'prompt'; + if (kind === 'prompt') lastLoad = null; + if (skill) lastLoad = skill; + events.push({ kind, line, text: body }); + } + } else if ((p.type === 'function_call' || p.type === 'custom_tool_call') && typeof p.name === 'string') { + const id = String(p.call_id ?? ''); + const input = args(p.type === 'custom_tool_call' ? { input: p.input } : p.arguments, line); + const command = SHELL_TOOLS.has(p.name) ? shellLine(input) : null; + if (command !== null) { + events.push({ kind: 'tool_use', line, id, name: 'Bash', input: { command } }); + for (const skill of shellSkillReads(command)) { + if (skill === lastLoad || readFailed(outputs.get(id), skill)) continue; + events.push({ kind: 'load', line, skill, via: 'read' }); + lastLoad = skill; + } + } else if (p.name === 'spawn_agent' && startedAgent(outputs.get(id))) { + const prompt = [input.message, ...(Array.isArray(input.items) ? input.items.map((i: unknown) => (isObject(i) ? i.text : undefined)) : [])] + .filter(v => typeof v === 'string').join('\n'); + events.push({ kind: 'tool_use', line, id, name: 'Agent', input: { prompt, ...(typeof input.agent_type === 'string' ? { subagent_type: input.agent_type } : {}) } }); + } else { + events.push({ kind: 'tool_use', line, id, name: p.name, input }); + } + } else if ((p.type === 'function_call_output' || p.type === 'custom_tool_call_output') && typeof p.call_id === 'string') { + const out = outputs.get(p.call_id) ?? ''; + events.push({ kind: 'tool_result', line, id: p.call_id, text: out, isError: exitedNonZero(out) }); + } + } + if (messages === 0) throw new UnknownShape('Codex rollout has no response_item message records'); + return { events, sessionId, format: 'codex', ...(subagent ? { subagent: true } : {}) }; +} diff --git a/lib/skill-contract.ts b/lib/skill-contract.ts index a6996e2db..188865a24 100644 --- a/lib/skill-contract.ts +++ b/lib/skill-contract.ts @@ -6,8 +6,10 @@ * * contract: { version: 1, items: [ { id, kind, ... } ] } * - * checkContract() is a pure function of a Claude Code transcript (the JSONL a - * hook payload's transcript_path names): the model never self-records. Waivers + * checkContract() is a pure function of a Claude Code transcript or a Codex + * rollout (the JSONL a hook payload's transcript_path names; parseTranscript + * tells them apart by content, lib/codex-rollout.ts reads the rollout): the + * model never self-records. Waivers * are read the same way, from the `gstack-skill-contract waive` Bash calls in * that transcript, and count as misses for follow. The Stop hook * (hosts/claude/hooks/skill-contract-stop-hook.ts) and `gstack-skill-contract` @@ -17,8 +19,9 @@ */ import * as fs from 'fs'; import * as path from 'path'; +import { isCodexRollout, parseCodexRollout } from './codex-rollout'; import { atomicWriteSync } from './fs-atomic'; -import { readFrontmatter, scanInstalledSkills } from './skill-route'; +import { installedSkillsDir, readFrontmatter, scanInstalledSkills } from './skill-route'; import { resolveStateRoot } from './state-root'; export const TRANSCRIPT_MAX_BYTES = 32 * 1024 * 1024; @@ -170,8 +173,11 @@ export function itemSummary(item: ContractItem): string { export type TranscriptEvent = | { kind: 'prompt' | 'meta' | 'text'; line: number; text: string } | { kind: 'tool_use'; line: number; id: string; name: string; input: Record } - | { kind: 'tool_result'; line: number; id: string; text: string; isError: boolean }; -export interface Transcript { events: TranscriptEvent[]; sessionId: string | null } + | { kind: 'tool_result'; line: number; id: string; text: string; isError: boolean } + /** Codex only: the model read, or Codex injected, a gstack-* SKILL.md (lib/codex-rollout.ts). */ + | { kind: 'load'; line: number; skill: string; via: 'read' | 'injected' }; +/** format and subagent are set only on a Codex rollout; a Claude Code transcript leaves both out. */ +export interface Transcript { events: TranscriptEvent[]; sessionId: string | null; format?: 'codex'; subagent?: boolean } const META_PREFIX = /^\s*<(?:local-command-stdout|local-command-stderr|system-reminder|task-notification|user-prompt-submit-hook|bash-input|bash-stdout|bash-stderr)\b/; @@ -184,9 +190,11 @@ function blockText(content: unknown): string { /** * Main-thread events of a Claude Code transcript JSONL. Sidechain (subagent) records are skipped unless * includeSidechain is set (a subagent's own agent-.jsonl holds only sidechain records); unparseable lines (a - * partial last line) are skipped. Throws UnknownShape when the file is not a transcript this parser knows. + * partial last line) are skipped. A Codex rollout (first record session_meta) goes to parseCodexRollout instead. + * Throws UnknownShape when the file is not a transcript this parser knows. */ export function parseTranscript(text: string, opts: { includeSidechain?: boolean } = {}): Transcript { + if (isCodexRollout(text)) return parseCodexRollout(text); const events: TranscriptEvent[] = []; let sessionId: string | null = null; let lines = 0; @@ -258,13 +266,18 @@ export function sameSkill(a: string, b: string): boolean { return x === y || x === `gstack-${y}` || `gstack-${x}` === y; } -export interface SkillLoad { skill: string; at: number; line: number; via: 'skill-tool' | 'slash-command' | 'read' } +export interface SkillLoad { skill: string; at: number; line: number; via: 'skill-tool' | 'slash-command' | 'read' | 'injected' } -/** Every skill load in order: a Skill tool call, a typed /command, or a Read of a SKILL.md under a skills/ directory (an installed skill, not a checkout's source). */ +/** + * Every skill load in order: a Skill tool call, a typed /command, or a Read of a SKILL.md under a skills/ directory (an + * installed skill, not a checkout's source). On Codex, the load events lib/codex-rollout.ts found. + */ export function skillLoads(t: Transcript): SkillLoad[] { const loads: SkillLoad[] = []; t.events.forEach((e, at) => { - if (e.kind === 'tool_use' && e.name === 'Skill') { + if (e.kind === 'load') { + loads.push({ skill: canonicalSkill(e.skill), at, line: e.line, via: e.via }); + } else if (e.kind === 'tool_use' && e.name === 'Skill') { const name = e.input.skill ?? e.input.command; if (typeof name === 'string' && name.trim()) loads.push({ skill: canonicalSkill(name.split(/\s/)[0]), at, line: e.line, via: 'skill-tool' }); } else if (e.kind === 'tool_use' && e.name === 'Read' && typeof e.input.file_path === 'string') { @@ -309,7 +322,14 @@ function parseNames(raw: string): string[] { interface ItemCheck { met: boolean; detail: string; fix: string } -function checkItem(item: ContractItem, run: TranscriptEvent[]): ItemCheck { +/** + * Item kinds a Codex run never checks: Codex suppresses the resolver that renders their step (REVIEW_ARMY for + * /review's specialists), so its SKILL.md never asks for them. test/skill-contract-codex.test.ts pins this list to + * hosts/codex.ts and the Done means resolver. + */ +export const CODEX_SKIPPED_KINDS: readonly ItemKind[] = ['selected_specialists_dispatched']; + +function checkItem(item: ContractItem, run: TranscriptEvent[], codex: boolean): ItemCheck { const texts = run.filter(e => e.kind === 'text').map(e => (e as { text: string }).text); const agents = run.filter((e): e is ToolUse => isToolUse(e) && AGENT_TOOLS.test(e.name)); switch (item.kind) { @@ -349,6 +369,11 @@ function checkItem(item: ContractItem, run: TranscriptEvent[]): ItemCheck { } case 'agent_dispatch': { const re = new RegExp(item.match as string, 'i'); + if (codex) { + return agents.some(a => re.test(agentText(a))) + ? { met: true, detail: `a spawn_agent call matches /${item.match}/`, fix: '' } + : { met: false, detail: `no spawn_agent call matches /${item.match}/`, fix: item.fix ?? `start the subagent pass matching /${item.match}/ with spawn_agent, then wait_agent for its result` }; + } return agents.some(a => re.test(agentText(a))) ? { met: true, detail: `an Agent dispatch matches /${item.match}/`, fix: '' } : { met: false, detail: `no Agent dispatch matches /${item.match}/`, fix: item.fix ?? `dispatch the Agent pass matching /${item.match}/` }; @@ -392,7 +417,7 @@ export interface CheckResult { /** * The contract against one run of the skill: from its load (the last one, or the one at loadLine) to its next load. - * Pure: same transcript, same result. + * On a Codex rollout, items of a CODEX_SKIPPED_KINDS kind are left out. Pure: same transcript, same result. */ export function checkContract(t: Transcript, skill: string, contract: Contract, opts: { loadLine?: number } = {}): CheckResult { const events = t.events; @@ -407,9 +432,11 @@ export function checkContract(t: Transcript, skill: string, contract: Contract, const exitMarker = new RegExp(`^[ \\t>*_-]*${markerPattern(DEFAULT_MATCHERS.earlyExit).source}`, 'im'); const endedEarly = !!finalText && run.includes(finalText as TranscriptEvent) && exitMarker.test(finalText.text); const earlyExit = !load ? null : statusLine === 'BLOCKED' ? 'STATUS: BLOCKED' : endedEarly ? DEFAULT_MATCHERS.earlyExit : null; - const items: ItemResult[] = load ? contract.items.map(item => { + const codex = t.format === 'codex'; + const checked = codex ? contract.items.filter(item => !CODEX_SKIPPED_KINDS.includes(item.kind)) : contract.items; + const items: ItemResult[] = load ? checked.map(item => { if (earlyExit) return { id: item.id, kind: item.kind, status: 'met', detail: `the skill ended the run early (${earlyExit})`, fix: '' }; - const r = checkItem(item, run); + const r = checkItem(item, run, codex); if (r.met) return { id: item.id, kind: item.kind, status: 'met', detail: r.detail, fix: '' }; const reason = waived.get(item.id); return reason ? { id: item.id, kind: item.kind, status: 'waived', detail: r.detail, fix: r.fix, reason } : { id: item.id, kind: item.kind, status: 'missing', detail: r.detail, fix: r.fix }; @@ -483,6 +510,23 @@ export function lookupContract(skill: string, skillsDir: string, skillFile?: str return 'error' in parsed ? { skill, file, error: `${file}: ${parsed.error}`, reason: 'invalid' } : { skill, file, contract: parsed.contract }; } +/** gstack's own checkout (this file is lib/skill-contract.ts). */ +const GSTACK_ROOT = path.resolve(import.meta.dir, '..'); + +/** + * The contract of a skill the transcript loaded. Claude Code: the installed skill (installedSkillsDir). Codex: its + * installed SKILL.md keeps only name and description, so the contract comes from gstack's own copy of the skill, + * //SKILL.md (GSTACK_INSTALLED_SKILLS_DIR replaces ). + */ +export function transcriptContract(t: Transcript, skill: string, env: NodeJS.ProcessEnv = process.env): ContractLookup { + if (t.format !== 'codex') return lookupContract(skill, installedSkillsDir(env)); + const dir = env.GSTACK_INSTALLED_SKILLS_DIR || GSTACK_ROOT; + const name = canonicalSkill(skill); + const names = /^[a-z0-9][a-z0-9_-]*$/.test(name) ? [name.replace(/^gstack-/, ''), name] : []; + const file = names.map(n => path.join(dir, n, 'SKILL.md')).find(f => fs.existsSync(f)); + return file ? lookupContract(skill, dir, file) : { skill, file: null, error: `no gstack skill named ${skill} under ${dir}`, reason: 'not-found' }; +} + export type Outcome = 'met' | 'met_waived' | 'blocked' | 'met_after_block' | 'miss' | 'deferred'; /** deferred_agents: the Agent dispatches still running at the last stop the hook let through unchecked; deferred_at: when that set was first seen. */ export interface RunRecord { skill: string; load_line: number; outcome: Outcome; missing: string[]; waived: string[]; blocked_at?: string; deferred_agents?: string[]; deferred_at?: string; updated_at: string } diff --git a/scripts/resolvers/contract-done-means.ts b/scripts/resolvers/contract-done-means.ts index 4e406367c..b3ab4947d 100644 --- a/scripts/resolvers/contract-done-means.ts +++ b/scripts/resolvers/contract-done-means.ts @@ -31,7 +31,7 @@ const KIND_FIELDS: Record = { }; // The resolver and section that render the step each kind checks today. A host that suppresses the resolver, or a loadout that excludes the section, never shows that step, so its items are left out of the list there. -const BACKED_BY: Partial> = { +export const BACKED_BY: Partial> = { selected_specialists_dispatched: { resolver: 'REVIEW_ARMY', section: 'review-army' }, agent_dispatch: { resolver: 'ADVERSARIAL_STEP', section: 'adversarial' }, }; diff --git a/setup b/setup index a0f3105de..223853055 100755 --- a/setup +++ b/setup @@ -5046,9 +5046,9 @@ _skill_hook_gate() { done } # ─── Codex hooks (GST-3172) ────────────────────────────────────────────────── -# The same switches register two Codex hooks in ${CODEX_HOME:-~/.codex}/hooks.json -# (docs/skill-routing-and-contracts.md#codex): skill_routing (UserPromptSubmit) -# and destructive_guard (PreToolUse on Bash), each in its own matcher group with +# The same switches register three Codex hooks in ${CODEX_HOME:-~/.codex}/hooks.json +# (docs/skill-routing-and-contracts.md#codex): skill_routing (UserPromptSubmit), +# skill_contracts (Stop, GST-3173) and destructive_guard (PreToolUse on Bash), each in its own matcher group with # an explicit timeout (Codex's default is 600 s). gstack-settings-hook writes the # file in its Codex format: no tag keys (Codex skips a hooks.json with a key it # does not know, the user's hooks included), the user's groups left as they are, @@ -5074,6 +5074,7 @@ if [ "$INSTALL_CODEX" -eq 1 ] && [ "$CODEX_REPO_LOCAL" -eq 0 ] && [ -x "$CODEX_S fi CODEX_ROUTE_HOOK="$(_hook_command_path hosts/codex/hooks/codex-skill-route-hook "$CODEX_GSTACK" || true)" CODEX_GUARD_HOOK="$(_hook_command_path hosts/codex/hooks/codex-destructive-guard-hook "$CODEX_GSTACK" || true)" +CODEX_CONTRACT_HOOK="$(_hook_command_path hosts/codex/hooks/codex-skill-contract-stop-hook "$CODEX_GSTACK" || true)" # _codex_hook_gate KEY DECISION SOURCE_OF_DECISION — called from _skill_hook_gate # with the decision it resolved, so both hosts follow one switch (D1). _codex_hook_gate() { @@ -5081,6 +5082,7 @@ _codex_hook_gate() { case "$key" in skill_routing) event=UserPromptSubmit; cmd="$CODEX_ROUTE_HOOK"; source=gstack-skill-route; timeout=5; matcher="" ;; destructive_guard) event=PreToolUse; cmd="$CODEX_GUARD_HOOK"; source=gstack-destructive-guard; timeout=10; matcher=Bash ;; + skill_contracts) event=Stop; cmd="$CODEX_CONTRACT_HOOK"; source=gstack-skill-contract; timeout=10; matcher="" ;; *) return 0 ;; esac if [ "$decision" = "off" ] || [ "$NO_TEAM_MODE" -eq 1 ]; then diff --git a/test/codex-hooks-real-codex.test.ts b/test/codex-hooks-real-codex.test.ts index 627d24761..3ff452a32 100644 --- a/test/codex-hooks-real-codex.test.ts +++ b/test/codex-hooks-real-codex.test.ts @@ -27,7 +27,7 @@ const home = () => path.join(dir, 'codex'); const marker = () => path.join(dir, 'user-session-start'); const routeLog = () => path.join(dir, 'state', 'hooks', 'skill-route.log'); -/** The user's own SessionStart hook, then gstack's two groups through gstack-settings-hook's Codex format. */ +/** The user's own SessionStart hook, then gstack's three groups through gstack-settings-hook's Codex format. */ function install(): void { fs.mkdirSync(home(), { recursive: true }); fs.writeFileSync(path.join(home(), 'hooks.json'), JSON.stringify({ @@ -42,6 +42,7 @@ function install(): void { const shims = path.join(ROOT, 'hosts', 'codex', 'hooks'); hook(['ensure-event', '--event', 'UserPromptSubmit', '--command', path.join(shims, 'codex-skill-route-hook'), '--source', 'gstack-skill-route', '--timeout', '5']); hook(['ensure-event', '--event', 'PreToolUse', '--command', path.join(shims, 'codex-destructive-guard-hook'), '--source', 'gstack-destructive-guard', '--matcher', 'Bash', '--timeout', '10']); + hook(['ensure-event', '--event', 'Stop', '--command', path.join(shims, 'codex-skill-contract-stop-hook'), '--source', 'gstack-skill-contract', '--timeout', '10']); const skills = path.join(dir, 'skills', 'gstack-review'); fs.mkdirSync(skills, { recursive: true }); fs.writeFileSync(path.join(skills, 'SKILL.md'), '---\nname: review\ndescription: Review a diff before it lands.\n---\n'); diff --git a/test/codex-hooks-setup.test.ts b/test/codex-hooks-setup.test.ts index b6d2259d7..417f0f714 100644 --- a/test/codex-hooks-setup.test.ts +++ b/test/codex-hooks-setup.test.ts @@ -40,9 +40,10 @@ describe('setup: Codex hook registration', () => { test('both Codex hooks resolve through _hook_command_path against the Codex runtime root, which links hosts/codex/hooks', () => { expect(setupSrc).toContain('CODEX_ROUTE_HOOK="$(_hook_command_path hosts/codex/hooks/codex-skill-route-hook "$CODEX_GSTACK" || true)"'); expect(setupSrc).toContain('CODEX_GUARD_HOOK="$(_hook_command_path hosts/codex/hooks/codex-destructive-guard-hook "$CODEX_GSTACK" || true)"'); + expect(setupSrc).toContain('CODEX_CONTRACT_HOOK="$(_hook_command_path hosts/codex/hooks/codex-skill-contract-stop-hook "$CODEX_GSTACK" || true)"'); expect(fnBody('create_codex_runtime_root')).toContain('_link_or_copy "$gstack_dir/hosts/codex/hooks" "$codex_gstack/hosts/codex/hooks"'); expect(fnBody('_skill_hook_gate')).toContain('if [ -n "${CODEX_HOOKS_FILE:-}" ]; then _codex_hook_gate "$key" "$decision" "$src"; fi'); - for (const f of ['codex-skill-route-hook', 'codex-destructive-guard-hook']) { + for (const f of ['codex-skill-route-hook', 'codex-destructive-guard-hook', 'codex-skill-contract-stop-hook']) { expect(fs.statSync(path.join(ROOT, 'hosts', 'codex', 'hooks', f)).mode & 0o111).toBeTruthy(); } }); @@ -61,6 +62,7 @@ describe('setup: Codex hook registration', () => { 'CODEX_SETTINGS_HOOK="' + ROOT + '/bin/gstack-settings-hook"; CODEX_GSTACK="' + runtimeRoot + '"', 'CODEX_ROUTE_HOOK="' + runtimeRoot + '/hosts/codex/hooks/codex-skill-route-hook"', 'CODEX_GUARD_HOOK="' + runtimeRoot + '/hosts/codex/hooks/codex-destructive-guard-hook"', + 'CODEX_CONTRACT_HOOK="' + runtimeRoot + '/hosts/codex/hooks/codex-skill-contract-stop-hook"', fnBody('_codex_hook_gate'), fnBody('_skill_hook_gate'), '_skill_hook_gate ' + key + ' "$1" GSTACK_X Event "" source 5 "what"', @@ -80,8 +82,9 @@ describe('setup: Codex hook registration', () => { expect(hooks().UserPromptSubmit).toEqual([{ hooks: [{ type: 'command', command: expect.stringMatching(/hosts\/codex\/hooks\/codex-skill-route-hook$/), timeout: 5 }] }]); expect(hooks().PreToolUse).toEqual([{ matcher: 'Bash', hooks: [{ type: 'command', command: expect.stringMatching(/hosts\/codex\/hooks\/codex-destructive-guard-hook$/), timeout: 10 }] }]); expect(gate('skill_routing', '')).toEqual({ code: 0, out: '' }); - expect(gate('skill_contracts', 'on').out).not.toContain('Codex'); - expect(Object.keys(hooks()).sort()).toEqual(['PreToolUse', 'UserPromptSubmit']); + expect(gate('skill_contracts', 'on').out).toContain('registered Codex Stop hook in ' + hooksFile() + ' (on via flag; turn off: gstack-config set skill_contracts off, or ./setup --no-skill-contracts)'); + expect(hooks().Stop).toEqual([{ hooks: [{ type: 'command', command: expect.stringMatching(/hosts\/codex\/hooks\/codex-skill-contract-stop-hook$/), timeout: 10 }] }]); + expect(Object.keys(hooks()).sort()).toEqual(['PreToolUse', 'Stop', 'UserPromptSubmit']); }); test("off, a saved off and --no-team remove only gstack's Codex group", () => { @@ -92,6 +95,9 @@ describe('setup: Codex hook registration', () => { expect(hooks().PreToolUse).toHaveLength(1); gate('skill_routing', ''); expect(hooks().UserPromptSubmit).toBeUndefined(); + gate('skill_contracts', 'on'); + gate('skill_contracts', 'off'); + expect(hooks().Stop).toBeUndefined(); gate('destructive_guard', '', {}, 1); expect(hooks()).toEqual({}); }); @@ -121,7 +127,8 @@ describe('gstack-uninstall and gstack-doctor with Codex hooks', () => { const user = { matcher: 'Bash', hooks: [{ type: 'command', command: '/usr/local/bin/my-guard', timeout: 3 }] }; const ours = { matcher: 'Bash', hooks: [{ type: 'command', command: codex + '/skills/gstack/hosts/codex/hooks/codex-destructive-guard-hook', timeout: 10 }] }; const route = { hooks: [{ type: 'command', command: codex + '/skills/gstack/hosts/codex/hooks/codex-skill-route-hook', timeout: 5 }] }; - fs.writeFileSync(path.join(codex, 'hooks.json'), JSON.stringify({ hooks: { PreToolUse: [user, ours], UserPromptSubmit: [route] } }, null, 2)); + const contract = { hooks: [{ type: 'command', command: codex + '/skills/gstack/hosts/codex/hooks/codex-skill-contract-stop-hook', timeout: 10 }] }; + fs.writeFileSync(path.join(codex, 'hooks.json'), JSON.stringify({ hooks: { PreToolUse: [user, ours], UserPromptSubmit: [route], Stop: [contract] } }, null, 2)); return { user }; } @@ -165,10 +172,10 @@ describe('gstack-uninstall and gstack-doctor with Codex hooks', () => { 'BIN="' + ROOT + '/bin"; SRC="' + ROOT + '"', fn, 'check_codex_hooks', ].join('\n'); const codexHome = path.join(dir, 'home', '.codex'); - expect(run(script, { CODEX_HOME: codexHome }).out).toBe('warn|codex hooks|destructive-guard no trust entry, skill-route no trust entry (Codex skips a hook until it is trusted)|open Codex and trust them at its startup prompt or in /hooks\n'); + expect(run(script, { CODEX_HOME: codexHome }).out).toBe('warn|codex hooks|destructive-guard no trust entry, skill-route no trust entry, skill-contract no trust entry (Codex skips a hook until it is trusted)|open Codex and trust them at its startup prompt or in /hooks\n'); const file = fs.realpathSync(path.join(codexHome, 'hooks.json')); - fs.writeFileSync(path.join(codexHome, 'config.toml'), '[hooks.state."' + file + ':pre_tool_use:1:0"]\ntrusted_hash = "sha256:a"\n[hooks.state."' + file + ':user_prompt_submit:0:0"]\ntrusted_hash = "sha256:b"\n'); - expect(run(script, { CODEX_HOME: codexHome }).out).toBe('ok|codex hooks|destructive-guard trusted, skill-route trusted (trust entry found; hash not checked)|\n'); + fs.writeFileSync(path.join(codexHome, 'config.toml'), '[hooks.state."' + file + ':pre_tool_use:1:0"]\ntrusted_hash = "sha256:a"\n[hooks.state."' + file + ':user_prompt_submit:0:0"]\ntrusted_hash = "sha256:b"\n[hooks.state."' + file + ':stop:0:0"]\ntrusted_hash = "sha256:c"\n'); + expect(run(script, { CODEX_HOME: codexHome }).out).toBe('ok|codex hooks|destructive-guard trusted, skill-route trusted, skill-contract trusted (trust entry found; hash not checked)|\n'); fs.writeFileSync(path.join(codexHome, 'hooks.json'), JSON.stringify({ hooks: {} })); expect(run(script, { CODEX_HOME: codexHome }).out).toBe(''); }); diff --git a/test/fixtures/skill-contract/block-message-codex.txt b/test/fixtures/skill-contract/block-message-codex.txt new file mode 100644 index 000000000..39b8082f6 --- /dev/null +++ b/test/fixtures/skill-contract/block-message-codex.txt @@ -0,0 +1 @@ +SKILL_CONTRACT_UNMET gstack-review (contract v1): missing adversarial, report. Fix: adversarial: start the subagent pass matching /Think like an attacker and a chaos engineer/ with spawn_agent, then wait_agent for its result; report: fill Gate edits in the Pre-Landing Review with real values. If an item truly does not apply, run '{bin}' waive --reason "" (this session only; counted as a miss for follow). This blocks once. diff --git a/test/fixtures/skill-contract/codex/README.md b/test/fixtures/skill-contract/codex/README.md new file mode 100644 index 000000000..6290aba25 --- /dev/null +++ b/test/fixtures/skill-contract/codex/README.md @@ -0,0 +1,23 @@ +# Codex rollouts for the /review contract (GST-3173) + +Real Codex CLI 0.170.0 rollout files, the JSONL a Codex hook payload's +`transcript_path` names. `test/skill-contract-codex.test.ts` reads them. + +Captured on 2026-11-19 with `gpt-5.4-mini` at low effort, a fresh +`CODEX_HOME` holding gstack's Codex skills, and a two-commit Python repo +(`main` plus a `feature` branch that adds `avg()`). Strings over 1,200 +characters are trimmed (the start and end are kept), home and checkout paths +are renamed under `/home/dev`, and token and timing records are dropped. +Nothing else was edited. + +| File | How it ran | What it shows | +|---|---|---| +| `exec-read-met.jsonl` | `codex exec`, told to read the gstack-review SKILL.md with a shell command, with gstack's contract Stop hook on (`--dangerously-bypass-hook-trust`) | a load by `cat`, an adversarial `spawn_agent` and a full report: met | +| `exec-read-blocked.jsonl` | the same, told not to start subagents | the hook blocked once (the `` message), then the model ran the pass and fixed the report: met after the block | +| `exec-read-failed-spawn.jsonl` | `codex exec`, no gstack hook | a `spawn_agent` that failed (no `agent_id`) before one that started; a report without Gate edits | +| `app-server-injected-early-exit.jsonl` | `codex app-server`, the skill sent as a `skill` input | Codex injects the SKILL.md as a `` user message; the run ends "Nothing to review" | +| `exec-mention-not-loaded.jsonl` | `codex exec '$gstack-review ...'`, with a probe Stop hook that blocked once | `codex exec` passes a typed `$gstack-review` as plain text, so nothing loads | +| `exec-subagent.jsonl` | the subagent rollout from the failed-spawn run | `session_meta.source` names the parent thread | + +`stop-payloads.json` holds the three Stop payloads Codex sent gstack's hook in +the first two runs, and what the hook printed. diff --git a/test/fixtures/skill-contract/codex/app-server-injected-early-exit.jsonl b/test/fixtures/skill-contract/codex/app-server-injected-early-exit.jsonl new file mode 100644 index 000000000..dd87b4486 --- /dev/null +++ b/test/fixtures/skill-contract/codex/app-server-injected-early-exit.jsonl @@ -0,0 +1,22 @@ +{"timestamp": "2026-11-19T06:27:05.803Z", "ordinal": 0, "type": "session_meta", "payload": {"account_scoped": true, "session_id": "01a1f27c-c544-7e80-a6b8-b52c03e00b73", "id": "01a1f27c-c544-7e80-a6b8-b52c03e00b73", "timestamp": "2026-11-19T06:27:05.701Z", "cwd": "/home/dev/repo", "runtime_workspace_roots": ["/home/dev/repo"], "originator": "probe", "cli_version": "0.170.0", "source": "vscode", "model_provider": "openai", "history_mode": "paginated", "context_window": {"window_id": "01a1f27c-c548-78a0-ba87-bae67238bc50"}}} +{"timestamp": "2026-11-19T06:27:05.804Z", "ordinal": 1, "type": "event_msg", "payload": {"type": "task_started", "turn_attribution": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "turn_trigger": null, "parent_turn_id": null, "initiating_agent_path": null, "root_turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d"}, "turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "root_turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "started_at": 1795069625, "model_context_window": 258400, "collaboration_mode_kind": "default"}} +{"timestamp": "2026-11-19T06:27:06.387Z", "ordinal": 2, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f27c-c812-7052-b47b-f145d3297cb3", "role": "developer", "content": [{"type": "input_text", "text": "\n## Skills\nA skill is a set of local instructions to follow that is stored in a `SKILL.md` file. Below is the list of skills that can be used. Each entry includes a name, description, and a short path that can be expanded into an absolute path using the skill roots table.\n### Skill roots\n- `r0` = `/home/dev/.codex/skills`\n- `r1` = `/home/dev/.codex/skills/.system`\n### Available skills\n- imagegen: Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output should be a bitmap asset rather than repo-native code or vector. Do not use when the task is better handled by editing existing SVG/vector/code-native assets, extend\n[... 2266 characters trimmed from this fixture ...]\nhen you review a diff before it lands: local changes, a branch or a PR. Use for: review my changes, look over my diff, review this pr. (gstack) (file: r0/gstack/review/SKILL.md)\n"}, {"type": "input_text", "text": "\nFilesystem sandboxing defines which files can be read or written. `sandbox_mode` is `danger-full-access`: No filesystem sandboxing - all commands are permitted. Network access is enabled.\nApproval policy is currently never. Do not provide the `sandbox_permissions` for any reason, commands will be rejected.\n"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "create_time": 1795069626.3867576, "content_item_kinds": ["host_skills.instructions", "permissions.instructions"], "content_item_metadata": [{"provenance": {"type": "skills"}}, {"provenance": {"type": "harness", "hook": false}}]}}, "metadata": {"history_sequence": 1, "sampled_through_sequence": 0, "client_authored": false, "mcp_attribution": {"status": "none"}}} +{"timestamp": "2026-11-19T06:27:06.387Z", "ordinal": 3, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f27c-c812-7052-b47b-f15d8900025f", "role": "user", "content": [{"type": "input_text", "text": "\n /home/dev/repo\n bash\n 2026-11-19\n Etc/UTC\n /home/dev/repo\n"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "create_time": 1795069626.386771, "content_item_kinds": ["environments.environment_context"], "content_item_metadata": [{"provenance": {"type": "harness", "hook": false}}]}}, "metadata": {"history_sequence": 2, "sampled_through_sequence": 0, "client_authored": false}} +{"timestamp": "2026-11-19T06:27:06.389Z", "ordinal": 5, "type": "turn_context", "payload": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "root_turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "disabled_plugin_ids": [], "cwd": "/home/dev/repo", "approval_policy": "never", "approvals_reviewer": "user", "permission_profile": {"type": "disabled"}, "model": "gpt-5.4-mini", "collaboration_mode": {"mode": "default", "settings": {"model": "gpt-5.4-mini", "reasoning_effort": "low", "developer_instructions": null}}, "multi_agent_version": "v1", "realtime_active": false, "effort": "low", "summary": "none", "sandbox_policy": {"type": "danger-full-access"}}} +{"timestamp": "2026-11-19T06:27:06.389Z", "ordinal": 6, "type": "event_msg", "payload": {"type": "thread_settings_applied", "thread_id": "01a1f27c-c544-7e80-a6b8-b52c03e00b73", "thread_settings": {"model": "gpt-5.4-mini", "model_provider_id": "openai", "approval_policy": "never", "approvals_reviewer": "user", "requested_approvals_reviewer": "user", "permission_profile": {"type": "disabled"}, "cwd": "/home/dev/repo", "runtime_workspace_roots": ["/home/dev/repo"], "reasoning_effort": "low", "collaboration_mode": {"mode": "default", "settings": {"model": "gpt-5.4-mini", "reasoning_effort": "low", "developer_instructions": null}}, "disabled_plugin_ids": []}}} +{"timestamp": "2026-11-19T06:27:06.394Z", "ordinal": 7, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f27c-c81a-78f2-942c-1504e6cf6452", "role": "user", "content": [{"type": "input_text", "text": "$gstack-review review this branch against main"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "create_time": 1795069626.3945735, "content_item_kinds": ["user.text"], "content_item_metadata": [{"provenance": {"type": "user"}}]}}, "metadata": {"history_sequence": 3, "sampled_through_sequence": 0, "retained_source": {"id": {"message_id": "msg_01a1f27c-c81a-78f2-942c-1504e6cf6452", "turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "role": "user"}, "revision": "retained_01a1f27c-c81a-78f2-942c-152173febdc8", "complete": true}, "client_authored": false, "user_input_order": 0, "mcp_attribution": {"status": "none"}}} +{"timestamp": "2026-11-19T06:27:06.398Z", "ordinal": 9, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f27c-c81e-7ac2-9d01-6a9f73831771", "role": "user", "content": [{"type": "input_text", "text": "\nreview\n/home/dev/.local/share/gstack/.agents/skills/gstack-review/SKILL.md\n---\nname: review\ndescription: |\n Use when you review a diff before it lands: local changes, a branch or a PR.\n Finds bugs that pass CI and break production. Fits \"review this PR\", \"look\n over my diff\", \"review my changes\", \"code review\", \"check my diff\" or\n \"pre-landing review\".\n Proactively suggest before a merge. (gstack)\n---\n\n\n\n## Done means\n\nFinish only when each of these exists (contract v1):\n\n- `adversarial-pass`: an Agent dispatch for the adversarial pass, its prompt including \"Think like an attacker and a chaos engineer\".\n- `review-report`: a `Pre-Landing Review` with Gate edits filled in (`none: ` where the skill's own stop rule leaves one empty).\n\n`$GSTAC\n[... 103083 characters trimmed from this fixture ...]\nimilarity alone is not a defect. Keep actual defects independently actionable.\n- **Use the reply templates from greptile-triage.md.** Every reply includes evidence. Never post vague replies.\n\n"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "create_time": 1795069626.3985891, "content_item_kinds": ["skills.selected_skill_instructions"], "content_item_metadata": [{"provenance": {"type": "skills"}}]}}, "metadata": {"history_sequence": 4, "sampled_through_sequence": 0, "client_authored": false}} +{"timestamp": "2026-11-19T06:27:08.489Z", "ordinal": 11, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0af0d603bc00034d016afe96bb38a887d28604d54ba5e8ce89", "summary": [{"type": "summary_text", "text": "**Preparing for review**\n\nI need to focus on performing a review, and it looks like I’ll need to use commentary tools. I think I should start with a preamble to set the stage for what's coming next. Maybe I won’t need to access the web for this one, which could simplify things a bit. Now, I’m considering running the skill start command to get everything going. Let’s get to it!"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d"}}, "metadata": {"history_sequence": 5, "sampled_through_sequence": 4, "client_authored": false}} +{"timestamp": "2026-11-19T06:27:08.505Z", "ordinal": 13, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_0af0d603bc00034d016afe96bc6e1887d2a20091676e776e14", "role": "assistant", "content": [{"type": "output_text", "text": "I’ll inspect the branch base and review setup first.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "create_time": 1795069626.739495, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 6, "sampled_through_sequence": 4, "retained_source": {"id": {"message_id": "msg_0af0d603bc00034d016afe96bc6e1887d2a20091676e776e14", "turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "role": "assistant"}, "revision": "retained_01a1f27c-d059-7401-88f2-539aac0cc992", "complete": true}, "client_authored": false, "user_input_order": 1}} +{"timestamp": "2026-11-19T06:27:08.768Z", "ordinal": 14, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0af0d603bc00034d016afe96bc72a887d29077462e80885512", "name": "exec_command", "arguments": "{\"cmd\":\"[ -d \\\"${GSTACK_ROOT:-/-}/lib\\\" ]&&[ -d \\\"$GSTACK_ROOT/bin\\\" ]||GSTACK_ROOT=$(git rev-parse --show-toplevel 2>/dev/null)/.agents/skills/gstack\\n[ -d \\\"$GSTACK_ROOT/bin\\\" ]||GSTACK_ROOT=${CODEX_HOME:-~/.codex}/skills/gstack\\n[ -d \\\"$GSTACK_ROOT/bin\\\" ]||echo \\\"gstack: no install found (tried $GSTACK_ROOT). Fix: ./setup --host codex from your gstack checkout; ./setup --status shows it.\\\" >&2\\n\\\"$GSTACK_ROOT/bin/gstack-skill-start\\\" --skill \\\"review\\\" --model \\\"gpt-6-astra\\\"\",\"workdir\":\"/home/dev/repo\",\"max_output_tokens\":12000,\"yield_time_ms\":10000}", "call_id": "call_jMK7bjA1Y85dNxyT7dV02JPt", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "create_time": 1795069626.739495}}, "metadata": {"history_sequence": 7, "sampled_through_sequence": 4, "client_authored": false, "user_input_order": 2}} +{"timestamp": "2026-11-19T06:27:09.605Z", "ordinal": 16, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f27c-d4a4-7092-b2f3-ddf86068153d", "call_id": "call_jMK7bjA1Y85dNxyT7dV02JPt", "output": "Chunk ID: abf3b8\nWall time: 0.6537 seconds\nProcess exited with code 0\nOriginal token count: 478\nOutput:\nSKILL_START_PROTO: 1\nBRANCH: feature\nPROACTIVE: core\nPROACTIVE_PROMPTED: no\nSKILL_PREFIX: false\nREPO_MODE: unknown\nSESSION_KIND: interactive\nCAPY: off\nSTATE_ROOT: /home/dev/.gstack durable=yes\nSESSIONS: 2\nACTIVATED: yes\nFIRST_LOOP_SHOWN: yes\nFIRST_TASK: \nLAKE_INTRO: yes\nTELEMETRY: off\nTEL_PROMPTED: no\nSESSION_ID: 13655-1795069629-4a2b8d99\nTEL_START: 1795069629\nEXPLAIN_LEVEL: default\nQUESTION_TUNING: false\nUPDATE_CHECK: true\nLEARNINGS: 0\nHAS_ROUTING: no\nROUTING_DECLINED: false\nVENDORED_GSTACK: no\nMODEL_OVERLAY: gpt-6-astra\nGSTACK_PLAN_MODE: inactive\nARTIFACTS_SYNC: off\nGSTACK_INSTRUCTION_BEGIN: telemetry-prompt 13655-1795069629-4a2b8d99\nAsk telemetry once via AskUserQuestion:\n\n> Help gstack get better. Yes sends, per skill run: skill name, outcome, duration, gstack version, OS, a redact\n[... 847 characters trimmed from this fixture ...]\ntack-config set telemetry anonymous`. If B→B: `/home/dev/.codex/skills/gstack/bin/gstack-config set telemetry off`.\nAlways run: `touch \"/home/dev/.gstack/.telemetry-prompted\"`.\nGSTACK_INSTRUCTION_END\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "create_time": 1795069629.6049514}}, "metadata": {"history_sequence": 8, "sampled_through_sequence": 4, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:27:11.070Z", "ordinal": 20, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0af0d603bc00034d016afe96be4e6c87d2a74d93b4a48bb44a", "summary": [], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d"}}, "metadata": {"history_sequence": 9, "sampled_through_sequence": 8, "client_authored": false}} +{"timestamp": "2026-11-19T06:27:11.093Z", "ordinal": 22, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_0af0d603bc00034d016afe96bf026887d28075a991235134f4", "role": "assistant", "content": [{"type": "output_text", "text": "I have the review session info; now I’m detecting the base branch and diff scope.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "create_time": 1795069629.829433, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 10, "sampled_through_sequence": 8, "retained_source": {"id": {"message_id": "msg_0af0d603bc00034d016afe96bf026887d28075a991235134f4", "turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "role": "assistant"}, "revision": "retained_01a1f27c-da75-7f23-be9c-cc9c9b7ed6d7", "complete": true}, "client_authored": false, "user_input_order": 3}} +{"timestamp": "2026-11-19T06:27:11.404Z", "ordinal": 23, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0af0d603bc00034d016afe96bf091c87d2a368106f77e71f3d", "name": "exec_command", "arguments": "{\"cmd\":\"git remote get-url origin 2>/dev/null && git branch --show-current && git fetch origin feature --quiet && echo BASE_REFRESH: fresh || echo BASE_REFRESH: stale $(git rev-parse --short origin/feature) && DIFF_BASE=$(git merge-base origin/feature HEAD) && git diff \\\"$DIFF_BASE\\\" --stat\",\"workdir\":\"/home/dev/repo\",\"max_output_tokens\":12000,\"yield_time_ms\":10000}", "call_id": "call_kXKr6f3CIRF844VIiNJmnw3J", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "create_time": 1795069629.829433}}, "metadata": {"history_sequence": 11, "sampled_through_sequence": 8, "client_authored": false, "user_input_order": 4}} +{"timestamp": "2026-11-19T06:27:11.526Z", "ordinal": 26, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f27c-dc26-7f11-83c4-bacd46ca8c25", "call_id": "call_kXKr6f3CIRF844VIiNJmnw3J", "output": "Chunk ID: e9509f\nWall time: 0.0000 seconds\nProcess exited with code 0\nOriginal token count: 17\nOutput:\n/home/dev/repo\nfeature\nBASE_REFRESH: fresh\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "create_time": 1795069631.5265179}}, "metadata": {"history_sequence": 12, "sampled_through_sequence": 8, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:27:13.694Z", "ordinal": 29, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0af0d603bc00034d016afe96c0305c87d28247d4e22622f256", "summary": [{"type": "summary_text", "text": "**Investigating git stats**\n\nI need to understand why the diff stats are missing; it could be due to no changes. Maybe the command chain didn’t execute properly in the shell? If the output is empty, it might be that the merge-base or diff is empty. I need to check if the branch name is the same as the base. It’s important to determine the base branch correctly to see if I should run git diff and check for differences."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d"}}, "metadata": {"history_sequence": 13, "sampled_through_sequence": 12, "client_authored": false}} +{"timestamp": "2026-11-19T06:27:13.834Z", "ordinal": 30, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0af0d603bc00034d016afe96c1a24887d2957f1db002f8470c", "name": "exec_command", "arguments": "{\"cmd\":\"DIFF_BASE=$(git merge-base origin/feature HEAD) && echo BASE=$DIFF_BASE && git diff \\\"$DIFF_BASE\\\" --stat && git status --short\",\"workdir\":\"/home/dev/repo\",\"max_output_tokens\":12000,\"yield_time_ms\":10000}", "call_id": "call_9IRz9Yjve9l2hvUJD4hF7zcT", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "create_time": 1795069631.723826}}, "metadata": {"history_sequence": 14, "sampled_through_sequence": 12, "client_authored": false, "user_input_order": 5}} +{"timestamp": "2026-11-19T06:27:13.921Z", "ordinal": 33, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f27c-e581-79f1-8d0f-45dfdb498771", "call_id": "call_9IRz9Yjve9l2hvUJD4hF7zcT", "output": "Chunk ID: 6cceca\nWall time: 0.0000 seconds\nProcess exited with code 0\nOriginal token count: 12\nOutput:\nBASE=0cf8bb7f0bde58b3965dbeb4a854a29370118f03\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "create_time": 1795069633.921158}}, "metadata": {"history_sequence": 15, "sampled_through_sequence": 12, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:27:17.363Z", "ordinal": 36, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0af0d603bc00034d016afe96c29f9087d2a748d7549c88d0ff", "summary": [{"type": "summary_text", "text": "**Clarifying branch assessment**\n\nI want to make sure I understand correctly: if I'm on the base branch, I should output the exact line and stop. It seems like I'm likely on the feature branch since we fetched from the origin. I wonder if I should run telemetry since I was instructed at session start, but I might have skipped that due to no review. \n\nI think the user wants me to confirm that the branch matches the base, even if there's no difference. Let’s keep it concise!"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d"}}, "metadata": {"history_sequence": 16, "sampled_through_sequence": 15, "client_authored": false}} +{"timestamp": "2026-11-19T06:27:17.437Z", "ordinal": 38, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_0af0d603bc00034d016afe96c54d4487d282bfc37ae9d93926", "role": "assistant", "content": [{"type": "output_text", "text": "Nothing to review — you're on the base branch or have no changes against it.", "annotations": [], "logprobs": []}], "phase": "final_answer", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "create_time": 1795069634.166725, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 17, "sampled_through_sequence": 15, "retained_source": {"id": {"message_id": "msg_0af0d603bc00034d016afe96c54d4487d282bfc37ae9d93926", "turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "role": "assistant"}, "revision": "retained_01a1f27c-f33d-7d62-848e-01a52516c138", "complete": true}, "client_authored": false, "user_input_order": 6}} +{"timestamp": "2026-11-19T06:27:17.450Z", "ordinal": 41, "type": "event_msg", "payload": {"type": "task_complete", "root_turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "turn_id": "01a1f27c-c593-77e2-b81a-01208a8e747d", "last_agent_message": "Nothing to review — you're on the base branch or have no changes against it.", "started_at": 1795069625, "completed_at": 1795069637, "duration_ms": 11701, "time_to_first_token_ms": 1876}} diff --git a/test/fixtures/skill-contract/codex/exec-mention-not-loaded.jsonl b/test/fixtures/skill-contract/codex/exec-mention-not-loaded.jsonl new file mode 100644 index 000000000..d11c0506e --- /dev/null +++ b/test/fixtures/skill-contract/codex/exec-mention-not-loaded.jsonl @@ -0,0 +1,25 @@ +{"timestamp": "2026-11-19T06:23:16.233Z", "ordinal": 0, "type": "session_meta", "payload": {"account_scoped": true, "session_id": "01a1f279-41bb-7370-a548-2681e5061f3e", "id": "01a1f279-41bb-7370-a548-2681e5061f3e", "timestamp": "2026-11-19T06:23:16.146Z", "cwd": "/home/dev/repo", "runtime_workspace_roots": ["/home/dev/repo"], "originator": "codex_exec", "cli_version": "0.170.0", "source": "exec", "thread_source": "user", "model_provider": "openai", "history_mode": "paginated", "context_window": {"window_id": "01a1f279-449c-7022-9057-2bce3f2a56f3"}}} +{"timestamp": "2026-11-19T06:23:16.233Z", "ordinal": 1, "type": "event_msg", "payload": {"type": "task_started", "turn_attribution": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "turn_trigger": "exec", "parent_turn_id": null, "initiating_agent_path": null, "root_turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634"}, "turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "root_turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "started_at": 1795069396, "model_context_window": 258400, "collaboration_mode_kind": "default"}} +{"timestamp": "2026-11-19T06:23:16.941Z", "ordinal": 2, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f279-47cd-7272-9ffd-9307d54f4616", "role": "developer", "content": [{"type": "input_text", "text": "\n## Skills\nA skill is a set of local instructions to follow that is stored in a `SKILL.md` file. Below is the list of skills that can be used. Each entry includes a name, description, and a short path that can be expanded into an absolute path using the skill roots table.\n### Skill roots\n- `r0` = `/home/dev/.codex/skills`\n- `r1` = `/home/dev/.codex/skills/.system`\n### Available skills\n- imagegen: Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output should be a bitmap asset rather than repo-native code or vector. Do not use when the task is better handled by editing existing SVG/vector/code-native assets, extend\n[... 2266 characters trimmed from this fixture ...]\nhen you review a diff before it lands: local changes, a branch or a PR. Use for: review my changes, look over my diff, review this pr. (gstack) (file: r0/gstack/review/SKILL.md)\n"}, {"type": "input_text", "text": "\nFilesystem sandboxing defines which files can be read or written. `sandbox_mode` is `danger-full-access`: No filesystem sandboxing - all commands are permitted. Network access is enabled.\nApproval policy is currently never. Do not provide the `sandbox_permissions` for any reason, commands will be rejected.\n"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "create_time": 1795069396.9417439, "content_item_kinds": ["host_skills.instructions", "permissions.instructions"], "content_item_metadata": [{"provenance": {"type": "skills"}}, {"provenance": {"type": "harness", "hook": false}}]}}, "metadata": {"history_sequence": 1, "sampled_through_sequence": 0, "client_authored": false, "mcp_attribution": {"status": "none"}}} +{"timestamp": "2026-11-19T06:23:16.942Z", "ordinal": 3, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f279-47cd-7272-9ffd-93114b39e956", "role": "user", "content": [{"type": "input_text", "text": "\n /home/dev/repo\n bash\n 2026-11-19\n Etc/UTC\n /home/dev/repo\n"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "create_time": 1795069396.941759, "content_item_kinds": ["environments.environment_context"], "content_item_metadata": [{"provenance": {"type": "harness", "hook": false}}]}}, "metadata": {"history_sequence": 2, "sampled_through_sequence": 0, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:16.944Z", "ordinal": 5, "type": "turn_context", "payload": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "root_turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "disabled_plugin_ids": [], "cwd": "/home/dev/repo", "approval_policy": "never", "approvals_reviewer": "user", "permission_profile": {"type": "disabled"}, "model": "gpt-5.4-mini", "collaboration_mode": {"mode": "default", "settings": {"model": "gpt-5.4-mini", "reasoning_effort": "low", "developer_instructions": null}}, "multi_agent_version": "v1", "realtime_active": false, "effort": "low", "summary": "none", "sandbox_policy": {"type": "danger-full-access"}}} +{"timestamp": "2026-11-19T06:23:16.944Z", "ordinal": 6, "type": "event_msg", "payload": {"type": "thread_settings_applied", "thread_id": "01a1f279-41bb-7370-a548-2681e5061f3e", "thread_settings": {"model": "gpt-5.4-mini", "model_provider_id": "openai", "approval_policy": "never", "approvals_reviewer": "user", "requested_approvals_reviewer": "user", "permission_profile": {"type": "disabled"}, "cwd": "/home/dev/repo", "runtime_workspace_roots": ["/home/dev/repo"], "reasoning_effort": "low", "collaboration_mode": {"mode": "default", "settings": {"model": "gpt-5.4-mini", "reasoning_effort": "low", "developer_instructions": null}}, "disabled_plugin_ids": []}}} +{"timestamp": "2026-11-19T06:23:16.952Z", "ordinal": 7, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f279-47d8-7c61-901c-0310608a0a66", "role": "user", "content": [{"type": "input_text", "text": "$gstack-review review this branch against main"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "create_time": 1795069396.9524858, "content_item_kinds": ["user.text"], "content_item_metadata": [{"provenance": {"type": "user"}}]}}, "metadata": {"history_sequence": 3, "sampled_through_sequence": 0, "retained_source": {"id": {"message_id": "msg_01a1f279-47d8-7c61-901c-0310608a0a66", "turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "role": "user"}, "revision": "retained_01a1f279-47d8-7c61-901c-0337365aab8c", "complete": true}, "client_authored": false, "user_input_order": 0, "mcp_attribution": {"status": "none"}}} +{"timestamp": "2026-11-19T06:23:19.046Z", "ordinal": 10, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_06dcf647df3f6c9c016afe95d6086487d2ac50764c50c1c73a", "summary": [{"type": "summary_text", "text": "**Considering review skills**\n\nI need to evaluate whether we should use review skills, especially by inspecting the repository and checking the differences. There's a thought about using a multi-agent approach, but maybe it’s not necessary. It's important to follow the skill instructions closely, so I think I should find out more about the agents involved. I'll also need to examine the root instructions to ensure everything is set up correctly."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634"}}, "metadata": {"history_sequence": 4, "sampled_through_sequence": 3, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:19.068Z", "ordinal": 12, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_06dcf647df3f6c9c016afe95d7009c87d2832cf23b741fb552", "role": "assistant", "content": [{"type": "output_text", "text": "I’ll inspect the branch diff against `main` and then review for production issues.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "create_time": 1795069397.612615, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 5, "sampled_through_sequence": 3, "retained_source": {"id": {"message_id": "msg_06dcf647df3f6c9c016afe95d7009c87d2832cf23b741fb552", "turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "role": "assistant"}, "revision": "retained_01a1f279-501c-7872-94d4-696a68f5ef8c", "complete": true}, "client_authored": false, "user_input_order": 1}} +{"timestamp": "2026-11-19T06:23:19.324Z", "ordinal": 13, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_06dcf647df3f6c9c016afe95d7074887d2abecc72deb67e7e0", "name": "exec_command", "arguments": "{\"cmd\":\"pwd && git status --short && git branch --show-current && git rev-parse --abbrev-ref main 2>/dev/null || true && rg --files -g 'AGENTS.md' -g '!**/node_modules/**'\",\"workdir\":\"/home/dev/repo\",\"yield_time_ms\":10000,\"max_output_tokens\":4000}", "call_id": "call_nNDle0Inp2CA6UHgdKpcm5JN", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "create_time": 1795069397.612615}}, "metadata": {"history_sequence": 6, "sampled_through_sequence": 3, "client_authored": false, "user_input_order": 2}} +{"timestamp": "2026-11-19T06:23:19.438Z", "ordinal": 16, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f279-518e-7c62-a05b-2115bc920653", "call_id": "call_nNDle0Inp2CA6UHgdKpcm5JN", "output": "Chunk ID: 5b6368\nWall time: 0.0000 seconds\nProcess exited with code 1\nOriginal token count: 13\nOutput:\n/home/dev/repo\nfeature\nmain\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "create_time": 1795069399.4382975}}, "metadata": {"history_sequence": 7, "sampled_through_sequence": 3, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:23:20.441Z", "ordinal": 19, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_06dcf647df3f6c9c016afe95d80a4887d2aacbc947c08aabe7", "summary": [], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634"}}, "metadata": {"history_sequence": 8, "sampled_through_sequence": 7, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:20.475Z", "ordinal": 21, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_06dcf647df3f6c9c016afe95d8667087d2b68e877235e9d85a", "role": "assistant", "content": [{"type": "output_text", "text": "I’ve got the branch context. Next I’m pulling the `main` diff and checking the touched files.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "create_time": 1795069399.641221, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 9, "sampled_through_sequence": 7, "retained_source": {"id": {"message_id": "msg_06dcf647df3f6c9c016afe95d8667087d2b68e877235e9d85a", "turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "role": "assistant"}, "revision": "retained_01a1f279-559b-7ee1-a04d-5cb55463aa96", "complete": true}, "client_authored": false, "user_input_order": 3}} +{"timestamp": "2026-11-19T06:23:20.920Z", "ordinal": 22, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_06dcf647df3f6c9c016afe95d86f8887d28a5e76751cd7f2f6", "name": "exec_command", "arguments": "{\"cmd\":\"git diff --stat main...HEAD && echo '---' && git diff --name-only main...HEAD && echo '---PATCH---' && git diff --unified=80 main...HEAD\",\"workdir\":\"/home/dev/repo\",\"yield_time_ms\":10000,\"max_output_tokens\":12000}", "call_id": "call_bQaZwRcxpQz7NZutPYxmcNVW", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "create_time": 1795069399.641221}}, "metadata": {"history_sequence": 10, "sampled_through_sequence": 7, "client_authored": false, "user_input_order": 4}} +{"timestamp": "2026-11-19T06:23:21.006Z", "ordinal": 25, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f279-57ae-7e43-86d4-e229a317bf70", "call_id": "call_bQaZwRcxpQz7NZutPYxmcNVW", "output": "Chunk ID: cf416e\nWall time: 0.0000 seconds\nProcess exited with code 0\nOriginal token count: 65\nOutput:\n calc.py | 3 +++\n 1 file changed, 3 insertions(+)\n---\ncalc.py\n---PATCH---\ndiff --git a/calc.py b/calc.py\nindex d10b0e8..b8481fd 100644\n--- a/calc.py\n+++ b/calc.py\n@@ -1,2 +1,5 @@\n def div(a, b):\n return a / b\n+\n+def avg(xs):\n+ return sum(xs) / len(xs)\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "create_time": 1795069401.0062025}}, "metadata": {"history_sequence": 11, "sampled_through_sequence": 7, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:23:23.204Z", "ordinal": 28, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_06dcf647df3f6c9c016afe95d97ec887d2918514d272bbbadc", "summary": [{"type": "summary_text", "text": "**Identifying potential bugs**\n\nI need to review the context, as there might be a bug here. I'm thinking of checking tests, but should I compare average results on an empty list? Could that lead to a ZeroDivisionError? That might be expected, but I need to figure out if it's the root cause. Maybe I'll need to create a list to compare its usage better. I’ll search through the file to get more clarity."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634"}}, "metadata": {"history_sequence": 12, "sampled_through_sequence": 11, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:23.230Z", "ordinal": 30, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_06dcf647df3f6c9c016afe95db29cc87d282a5a2efade52ed1", "role": "assistant", "content": [{"type": "output_text", "text": "The patch is tiny, so I’m checking surrounding usage to judge behavior and edge cases.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "create_time": 1795069401.217902, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 13, "sampled_through_sequence": 11, "retained_source": {"id": {"message_id": "msg_06dcf647df3f6c9c016afe95db29cc87d282a5a2efade52ed1", "turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "role": "assistant"}, "revision": "retained_01a1f279-605e-7093-b5a5-16a438f35b8f", "complete": true}, "client_authored": false, "user_input_order": 5}} +{"timestamp": "2026-11-19T06:23:23.370Z", "ordinal": 31, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_06dcf647df3f6c9c016afe95db310c87d2a8e3f5dd3ecf7bd7", "name": "exec_command", "arguments": "{\"cmd\":\"sed -n '1,120p' calc.py && echo '---' && rg -n \\\"\\\\bavg\\\\(|\\\\bdiv\\\\(\\\" -S .\",\"workdir\":\"/home/dev/repo\",\"yield_time_ms\":10000,\"max_output_tokens\":4000}", "call_id": "call_qtshk3NudErPfhalvSuIxjDQ", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "create_time": 1795069401.217902}}, "metadata": {"history_sequence": 14, "sampled_through_sequence": 11, "client_authored": false, "user_input_order": 6}} +{"timestamp": "2026-11-19T06:23:23.438Z", "ordinal": 34, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f279-612e-7af3-9e3f-2a96197a1f47", "call_id": "call_qtshk3NudErPfhalvSuIxjDQ", "output": "Chunk ID: 750261\nWall time: 0.0000 seconds\nProcess exited with code 0\nOriginal token count: 33\nOutput:\ndef div(a, b):\n return a / b\n\ndef avg(xs):\n return sum(xs) / len(xs)\n---\n./calc.py:1:def div(a, b):\n./calc.py:4:def avg(xs):\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "create_time": 1795069403.4385297}}, "metadata": {"history_sequence": 15, "sampled_through_sequence": 11, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:23:25.671Z", "ordinal": 37, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_06dcf647df3f6c9c016afe95dc17e087d28f07ee37c906edd7", "summary": [{"type": "summary_text", "text": "**Reviewing potential issues**\n\nI feel like I need to mention that there could be an empty sequence and no guard against that, but maybe it’s just a finding for the review. I'm also pondering whether there's really a bug or a possible issue with integer division—averaging returns a float, which seems okay. I should mention that there's no validation for empty inputs and non-numeric values. Since this review aims to find defects, I think focusing on a specific line with severity would be best."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634"}}, "metadata": {"history_sequence": 16, "sampled_through_sequence": 15, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:25.798Z", "ordinal": 39, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_06dcf647df3f6c9c016afe95dda13c87d2a7ef4dd053d0b4cd", "role": "assistant", "content": [{"type": "output_text", "text": "Found one issue:\n\n- **High** — `calc.py:4` will raise `ZeroDivisionError` on `avg([])`. If empty input is possible, this new helper is unsafe; it needs an explicit empty-sequence check or a documented precondition.", "annotations": [], "logprobs": []}], "phase": "final_answer", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "create_time": 1795069403.669213, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 17, "sampled_through_sequence": 15, "retained_source": {"id": {"message_id": "msg_06dcf647df3f6c9c016afe95dda13c87d2a7ef4dd053d0b4cd", "turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "role": "assistant"}, "revision": "retained_01a1f279-6a66-70a0-9a76-99ff3ecddf8f", "complete": true}, "client_authored": false, "user_input_order": 7}} +{"timestamp": "2026-11-19T06:23:25.849Z", "ordinal": 42, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f279-6a98-7183-886e-320242b8a186", "role": "user", "content": [{"type": "input_text", "text": "Before you stop, print one line: PROBE-STOP-ACK"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "create_time": 1795069405.8489175, "content_item_kinds": ["unknown"], "content_item_metadata": [{"provenance": {"type": "harness", "hook": true}}]}}, "metadata": {"history_sequence": 18, "sampled_through_sequence": 15, "retained_source": {"id": {"message_id": "msg_01a1f279-6a98-7183-886e-320242b8a186", "turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "role": "user"}, "revision": "retained_01a1f279-6a99-7023-a883-961bab94a1bf", "complete": false}, "client_authored": false, "user_input_order": 8}} +{"timestamp": "2026-11-19T06:23:26.812Z", "ordinal": 45, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_06dcf647df3f6c9c016afe95de9ca887d2b31ba4b07c5f8134", "summary": [], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634"}}, "metadata": {"history_sequence": 19, "sampled_through_sequence": 18, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:26.879Z", "ordinal": 47, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_06dcf647df3f6c9c016afe95dec55087d2925d9d2c138e514a", "role": "assistant", "content": [{"type": "output_text", "text": "PROBE-STOP-ACK", "annotations": [], "logprobs": []}], "phase": "final_answer", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "create_time": 1795069406.243214, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 20, "sampled_through_sequence": 18, "retained_source": {"id": {"message_id": "msg_06dcf647df3f6c9c016afe95dec55087d2925d9d2c138e514a", "turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "role": "assistant"}, "revision": "retained_01a1f279-6e9f-7452-b694-3e22aa311852", "complete": true}, "client_authored": false, "user_input_order": 9}} +{"timestamp": "2026-11-19T06:23:26.911Z", "ordinal": 50, "type": "event_msg", "payload": {"type": "task_complete", "root_turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "turn_id": "01a1f279-44d5-7e63-9485-da2704d9f634", "last_agent_message": "PROBE-STOP-ACK", "started_at": 1795069396, "completed_at": 1795069406, "duration_ms": 10728, "time_to_first_token_ms": 2210}} diff --git a/test/fixtures/skill-contract/codex/exec-read-blocked.jsonl b/test/fixtures/skill-contract/codex/exec-read-blocked.jsonl new file mode 100644 index 000000000..0c971461e --- /dev/null +++ b/test/fixtures/skill-contract/codex/exec-read-blocked.jsonl @@ -0,0 +1,28 @@ +{"timestamp": "2026-11-19T06:33:34.591Z", "ordinal": 0, "type": "session_meta", "payload": {"account_scoped": true, "session_id": "01a1f282-b418-7040-bb98-0b3dffdc76fe", "id": "01a1f282-b418-7040-bb98-0b3dffdc76fe", "timestamp": "2026-11-19T06:33:34.518Z", "cwd": "/home/dev/repo", "runtime_workspace_roots": ["/home/dev/repo"], "originator": "codex_exec", "cli_version": "0.170.0", "source": "exec", "thread_source": "user", "model_provider": "openai", "history_mode": "paginated", "context_window": {"window_id": "01a1f282-b41b-75f0-95aa-f5482a64828e"}}} +{"timestamp": "2026-11-19T06:33:34.591Z", "ordinal": 1, "type": "event_msg", "payload": {"type": "task_started", "turn_attribution": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "turn_trigger": "exec", "parent_turn_id": null, "initiating_agent_path": null, "root_turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843"}, "turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "root_turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "started_at": 1795070014, "model_context_window": 258400, "collaboration_mode_kind": "default"}} +{"timestamp": "2026-11-19T06:33:35.208Z", "ordinal": 2, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f282-b6e8-7f61-ae7e-aab976aab930", "role": "developer", "content": [{"type": "input_text", "text": "\n## Skills\nA skill is a set of local instructions to follow that is stored in a `SKILL.md` file. Below is the list of skills that can be used. Each entry includes a name, description, and a short path that can be expanded into an absolute path using the skill roots table.\n### Skill roots\n- `r0` = `/home/dev/.codex/skills`\n- `r1` = `/home/dev/.codex/skills/.system`\n### Available skills\n- imagegen: Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output should be a bitmap asset rather than repo-native code or vector. Do not use when the task is better handled by editing existing SVG/vector/code-native assets, extend\n[... 2266 characters trimmed from this fixture ...]\nhen you review a diff before it lands: local changes, a branch or a PR. Use for: review my changes, look over my diff, review this pr. (gstack) (file: r0/gstack/review/SKILL.md)\n"}, {"type": "input_text", "text": "\nFilesystem sandboxing defines which files can be read or written. `sandbox_mode` is `danger-full-access`: No filesystem sandboxing - all commands are permitted. Network access is enabled.\nApproval policy is currently never. Do not provide the `sandbox_permissions` for any reason, commands will be rejected.\n"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070015.2083397, "content_item_kinds": ["host_skills.instructions", "permissions.instructions"], "content_item_metadata": [{"provenance": {"type": "skills"}}, {"provenance": {"type": "harness", "hook": false}}]}}, "metadata": {"history_sequence": 1, "sampled_through_sequence": 0, "client_authored": false, "mcp_attribution": {"status": "none"}}} +{"timestamp": "2026-11-19T06:33:35.208Z", "ordinal": 3, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f282-b6e8-7f61-ae7e-aacdc3db8e5f", "role": "user", "content": [{"type": "input_text", "text": "\n /home/dev/repo\n bash\n 2026-11-19\n Etc/UTC\n /home/dev/repo\n"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070015.2083564, "content_item_kinds": ["environments.environment_context"], "content_item_metadata": [{"provenance": {"type": "harness", "hook": false}}]}}, "metadata": {"history_sequence": 2, "sampled_through_sequence": 0, "client_authored": false}} +{"timestamp": "2026-11-19T06:33:35.211Z", "ordinal": 5, "type": "turn_context", "payload": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "root_turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "disabled_plugin_ids": [], "cwd": "/home/dev/repo", "approval_policy": "never", "approvals_reviewer": "user", "permission_profile": {"type": "disabled"}, "model": "gpt-5.4-mini", "collaboration_mode": {"mode": "default", "settings": {"model": "gpt-5.4-mini", "reasoning_effort": "low", "developer_instructions": null}}, "multi_agent_version": "v1", "realtime_active": false, "effort": "low", "summary": "none", "sandbox_policy": {"type": "danger-full-access"}}} +{"timestamp": "2026-11-19T06:33:35.211Z", "ordinal": 6, "type": "event_msg", "payload": {"type": "thread_settings_applied", "thread_id": "01a1f282-b418-7040-bb98-0b3dffdc76fe", "thread_settings": {"model": "gpt-5.4-mini", "model_provider_id": "openai", "approval_policy": "never", "approvals_reviewer": "user", "requested_approvals_reviewer": "user", "permission_profile": {"type": "disabled"}, "cwd": "/home/dev/repo", "runtime_workspace_roots": ["/home/dev/repo"], "reasoning_effort": "low", "collaboration_mode": {"mode": "default", "settings": {"model": "gpt-5.4-mini", "reasoning_effort": "low", "developer_instructions": null}}, "disabled_plugin_ids": []}}} +{"timestamp": "2026-11-19T06:33:35.216Z", "ordinal": 7, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f282-b6f0-7ba3-82d4-a80982a531e7", "role": "user", "content": [{"type": "input_text", "text": "Read the file $CODEX_HOME/skills/gstack-review/SKILL.md with a shell command and use it to review this branch against main. Keep it quick: review the diff yourself and do not start any subagents."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070015.2163348, "content_item_kinds": ["user.text"], "content_item_metadata": [{"provenance": {"type": "user"}}]}}, "metadata": {"history_sequence": 3, "sampled_through_sequence": 0, "retained_source": {"id": {"message_id": "msg_01a1f282-b6f0-7ba3-82d4-a80982a531e7", "turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "role": "user"}, "revision": "retained_01a1f282-b6f0-7ba3-82d4-a8238d36e779", "complete": true}, "client_authored": false, "user_input_order": 0, "mcp_attribution": {"status": "none"}}} +{"timestamp": "2026-11-19T06:33:37.455Z", "ordinal": 10, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_05be56c0d8d55b57016afe983ff4bc87d2b705fda30f7ed947", "summary": [], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843"}}, "metadata": {"history_sequence": 4, "sampled_through_sequence": 3, "client_authored": false}} +{"timestamp": "2026-11-19T06:33:37.474Z", "ordinal": 12, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_05be56c0d8d55b57016afe984164d487d2b97205588d4e26df", "role": "assistant", "content": [{"type": "output_text", "text": "I’ll read the review skill, then inspect the branch diff.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070015.494189, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 5, "sampled_through_sequence": 3, "retained_source": {"id": {"message_id": "msg_05be56c0d8d55b57016afe984164d487d2b97205588d4e26df", "turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "role": "assistant"}, "revision": "retained_01a1f282-bfc1-78e3-9ed5-9a20c38c30e6", "complete": true}, "client_authored": false, "user_input_order": 1}} +{"timestamp": "2026-11-19T06:33:37.670Z", "ordinal": 13, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_05be56c0d8d55b57016afe984169fc87d2bc37802ec930dcf6", "name": "exec_command", "arguments": "{\"cmd\":\"cat /home/dev/.codex/skills/gstack-review/SKILL.md && printf '\\\\n---GIT---\\\\n' && git status --short && printf '\\\\n---BRANCH---\\\\n' && git branch --show-current && printf '\\\\n---DIFFSTAT---\\\\n' && git diff --stat main...HEAD && printf '\\\\n---DIFF---\\\\n' && git diff --find-renames --find-copies main...HEAD\",\"workdir\":\"/home/dev/repo\",\"max_output_tokens\":20000}", "call_id": "call_mPoy3BME3RFpb5rSVlh6tjbp", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070015.494189}}, "metadata": {"history_sequence": 6, "sampled_through_sequence": 3, "client_authored": false, "user_input_order": 2}} +{"timestamp": "2026-11-19T06:33:37.797Z", "ordinal": 16, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f282-c105-7dd2-be2c-64c6a52c3c49", "call_id": "call_mPoy3BME3RFpb5rSVlh6tjbp", "output": "Chunk ID: 338eb9\nWall time: 0.0000 seconds\nProcess exited with code 0\nOriginal token count: 26240\nOutput:\nWarning: truncated output (original token count: 26240)\nTotal output lines: 1479\n\n---\nname: review\ndescription: |\n Use when you review a diff before it lands: local changes, a branch or a PR.\n Finds bugs that pass CI and break production. Fits \"review this PR\", \"look\n over my diff\", \"review my changes\", \"code review\", \"check my diff\" or\n \"pre-landing review\".\n Proactively suggest before a merge. (gstack)\n---\n\n\n\n## Done means\n\nFinish only when each of these exists (contract v1):\n\n- `adversarial-pass`: an Agent dispatch for the adversarial pass, its prompt including \"Think like an attacker and a chaos engineer\".\n- `review-report`: a `Pre-Landing Review` with Gate edits fille\n[... 9089 characters trimmed from this fixture ...]\n+)\n\n---DIFF---\ndiff --git a/calc.py b/calc.py\nindex d10b0e8..b8481fd 100644\n--- a/calc.py\n+++ b/calc.py\n@@ -1,2 +1,5 @@\n def div(a, b):\n return a / b\n+\n+def avg(xs):\n+ return sum(xs) / len(xs)\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070017.7978868}}, "metadata": {"history_sequence": 7, "sampled_through_sequence": 3, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:33:39.669Z", "ordinal": 19, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_05be56c0d8d55b57016afe984272b887d2b59356d0fd8a5546", "summary": [], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843"}}, "metadata": {"history_sequence": 8, "sampled_through_sequence": 7, "client_authored": false}} +{"timestamp": "2026-11-19T06:33:40.123Z", "ordinal": 21, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_05be56c0d8d55b57016afe98439b3887d2a1be76397cf5c115", "role": "assistant", "content": [{"type": "output_text", "text": "Pre-Landing Review: 1 issue (1 critical, 0 informational)\n\n- [critical] `calc.py:4` — `avg([])` raises `ZeroDivisionError` because `len(xs)` is `0`; this makes the new helper fail on empty input instead of handling or explicitly rejecting it.\n - Fix: add an empty-sequence check and raise a clearer `ValueError` (or define the expected empty-case behavior).", "annotations": [], "logprobs": []}], "phase": "final_answer", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070018.007913, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 9, "sampled_through_sequence": 7, "retained_source": {"id": {"message_id": "msg_05be56c0d8d55b57016afe98439b3887d2a1be76397cf5c115", "turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "role": "assistant"}, "revision": "retained_01a1f282-ca1b-7890-a2eb-c2d5a8ed84cd", "complete": true}, "client_authored": false, "user_input_order": 3}} +{"timestamp": "2026-11-19T06:33:40.225Z", "ordinal": 24, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f282-ca81-7af3-904b-3bd8c5e4298e", "role": "user", "content": [{"type": "input_text", "text": "SKILL_CONTRACT_UNMET gstack-review (contract v1): missing adversarial-pass, review-report. Fix: adversarial-pass: start the subagent pass matching /Think like an attacker and a chaos engineer/ with spawn_agent, then wait_agent for its result; review-report: fill Gate edits in the Pre-Landing Review with real values. If an item truly does not apply, run '/home/dev/.local/share/gstack/bin/gstack-skill-contract' waive <item> --reason \"<why>\" (this session only; counted as a miss for follow). This blocks once."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070020.2257044, "content_item_kinds": ["unknown"], "content_item_metadata": [{"provenance": {"type": "harness", "hook": true}}]}}, "metadata": {"history_sequence": 10, "sampled_through_sequence": 7, "retained_source": {"id": {"message_id": "msg_01a1f282-ca81-7af3-904b-3bd8c5e4298e", "turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "role": "user"}, "revision": "retained_01a1f282-ca81-7af3-904b-3beed94226b8", "complete": false}, "client_authored": false, "user_input_order": 4}} +{"timestamp": "2026-11-19T06:33:43.103Z", "ordinal": 27, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_05be56c0d8d55b57016afe9844ecbc87d295b30e92cc2942b3", "summary": [{"type": "summary_text", "text": "**Analyzing edits and values**\n\nI noticed that for the simple diff, there are no detected gate edits. However, I should include the actual values for clarity, maybe setting it to reflect “none detected” with “0 listed, 0 read.” I’m considering if an adversarial review pass is necessary. For that, I could spawn an agent with the exact phrase to check everything thoroughly. It feels like a detailed approach will help me better understand what’s going on."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843"}}, "metadata": {"history_sequence": 11, "sampled_through_sequence": 10, "client_authored": false}} +{"timestamp": "2026-11-19T06:33:43.128Z", "ordinal": 29, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_05be56c0d8d55b57016afe98470a2087d29c65055851da5f62", "role": "assistant", "content": [{"type": "output_text", "text": "I’m doing the required adversarial pass now, then I’ll close out the review cleanly.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070020.492948, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 12, "sampled_through_sequence": 10, "retained_source": {"id": {"message_id": "msg_05be56c0d8d55b57016afe98470a2087d29c65055851da5f62", "turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "role": "assistant"}, "revision": "retained_01a1f282-d5d8-71b3-ab77-37dd042158cc", "complete": true}, "client_authored": false, "user_input_order": 5}} +{"timestamp": "2026-11-19T06:33:43.251Z", "ordinal": 30, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_05be56c0d8d55b57016afe984711dc87d29e4678efc4d9f439", "name": "spawn_agent", "namespace": "multi_agent_v1", "arguments": "{\"message\":\"Think like an attacker and a chaos engineer. Review the current branch diff against main for bugs, edge cases, and failure modes. Return only concrete issues, if any, with file/line evidence and a one-line fix suggestion. Do not modify files.\",\"reasoning_effort\":\"medium\"}", "call_id": "call_BW3J7sttgF9osDgKd43529MP", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070020.492948}}, "metadata": {"history_sequence": 13, "sampled_through_sequence": 10, "client_authored": false, "user_input_order": 6}} +{"timestamp": "2026-11-19T06:33:43.269Z", "ordinal": 32, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f282-d665-78e0-a3ec-8ec28acb21e6", "call_id": "call_BW3J7sttgF9osDgKd43529MP", "output": "Reasoning effort `medium` is not supported for model `gpt-5.4-mini`. Supported reasoning efforts: ", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070023.269143}}, "metadata": {"history_sequence": 14, "sampled_through_sequence": 10, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:33:44.176Z", "ordinal": 35, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_05be56c0d8d55b57016afe9847eacc87d295064a66eb487c45", "summary": [], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843"}}, "metadata": {"history_sequence": 15, "sampled_through_sequence": 14, "client_authored": false}} +{"timestamp": "2026-11-19T06:33:44.343Z", "ordinal": 36, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_05be56c0d8d55b57016afe98481d6887d29d4589b996a92788", "name": "spawn_agent", "namespace": "multi_agent_v1", "arguments": "{\"message\":\"Think like an attacker and a chaos engineer. Review the current branch diff against main for bugs, edge cases, and failure modes. Return only concrete issues, if any, with file/line evidence and a one-line fix suggestion. Do not modify files.\"}", "call_id": "call_UHtai6UQc2bYqKU4Q5sCD0YV", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070023.479579}}, "metadata": {"history_sequence": 16, "sampled_through_sequence": 14, "client_authored": false, "user_input_order": 7}} +{"timestamp": "2026-11-19T06:33:44.387Z", "ordinal": 39, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f282-dac3-7543-bbf9-519033e3dac5", "call_id": "call_UHtai6UQc2bYqKU4Q5sCD0YV", "output": "{\"agent_id\":\"01a1f282-da9a-7132-9373-c658b8dc44ca\",\"nickname\":\"Halley\"}", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070024.3874521}}, "metadata": {"history_sequence": 17, "sampled_through_sequence": 14, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:33:45.239Z", "ordinal": 43, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_05be56c0d8d55b57016afe9849064087d29f9045402a5ab17c", "role": "assistant", "content": [{"type": "output_text", "text": "The adversarial pass is running; I’ll wait for its findings.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070024.594778, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 18, "sampled_through_sequence": 17, "retained_source": {"id": {"message_id": "msg_05be56c0d8d55b57016afe9849064087d29f9045402a5ab17c", "turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "role": "assistant"}, "revision": "retained_01a1f282-de17-7820-9db2-9172f43a9e53", "complete": true}, "client_authored": false, "user_input_order": 8}} +{"timestamp": "2026-11-19T06:33:45.404Z", "ordinal": 44, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_05be56c0d8d55b57016afe98492d4087d283f9e5b54d37e418", "name": "wait_agent", "namespace": "multi_agent_v1", "arguments": "{\"targets\":[\"01a1f282-da9a-7132-9373-c658b8dc44ca\"],\"timeout_ms\":30000}", "call_id": "call_FawyhsaUojROZz29jjhoXv5K", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070024.594778}}, "metadata": {"history_sequence": 19, "sampled_through_sequence": 17, "client_authored": false, "user_input_order": 9}} +{"timestamp": "2026-11-19T06:33:53.469Z", "ordinal": 47, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f282-fe3d-7310-95fd-db37f08792b7", "call_id": "call_FawyhsaUojROZz29jjhoXv5K", "output": "{\"status\":{\"01a1f282-da9a-7132-9373-c658b8dc44ca\":{\"completed\":\"- `calc.py:4-5` — `avg([])` raises `ZeroDivisionError` because `len(xs)` can be zero; fix by rejecting empty input up front or defining a safe empty-list behavior.\"}},\"timed_out\":false}", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070033.4694934}}, "metadata": {"history_sequence": 20, "sampled_through_sequence": 17, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:33:53.471Z", "ordinal": 49, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f282-fe3f-7573-bcbb-b5f408eae631", "role": "user", "content": [{"type": "input_text", "text": "\n{\"agent_path\":\"01a1f282-da9a-7132-9373-c658b8dc44ca\",\"status\":{\"completed\":\"- `calc.py:4-5` — `avg([])` raises `ZeroDivisionError` because `len(xs)` can be zero; fix by rejecting empty input up front or defining a safe empty-list behavior.\"}}\n"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070033.4717574, "content_item_kinds": ["multi_agent.subagent_notification"], "content_item_metadata": [{"provenance": {"type": "tool", "namespace": "multi_agent_v1"}}]}}, "metadata": {"history_sequence": 21, "sampled_through_sequence": 17, "client_authored": false}} +{"timestamp": "2026-11-19T06:33:56.029Z", "ordinal": 51, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_05be56c0d8d55b57016afe9852305487d29ea5ec77ee3c96cd", "summary": [{"type": "summary_text", "text": "**Reviewing report edits**\n\nI think I need to review the report with the Gate edits. It seems like the final answer should be concise, especially since there's already been an issue. I might want to mention the adversarial pass, same as before. I need to note the Gate edits as well. It looks like I don’t need a tool; I can just respond. I’ll include the final report details for the Pre-Landing Review and mention the counts and Gate edits line. Let’s make it brief!"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843"}}, "metadata": {"history_sequence": 22, "sampled_through_sequence": 21, "client_authored": false}} +{"timestamp": "2026-11-19T06:33:56.183Z", "ordinal": 53, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_05be56c0d8d55b57016afe9853f81487d2bd3ef77f0680d977", "role": "assistant", "content": [{"type": "output_text", "text": "Pre-Landing Review: 1 issue (1 critical, 0 informational)\n\n- [critical] `calc.py:4-5` — `avg([])` raises `ZeroDivisionError` because `len(xs)` can be `0`; this makes the new helper fail on empty input.\n - Fix: reject empty input up front with a clear `ValueError`, or define and implement the intended empty-sequence behavior.\n\nGate edits: none detected (0 listed, 0 read; patterns: simple arithmetic helper; unlisted idioms: none)", "annotations": [], "logprobs": []}], "phase": "final_answer", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "create_time": 1795070033.739051, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 23, "sampled_through_sequence": 21, "retained_source": {"id": {"message_id": "msg_05be56c0d8d55b57016afe9853f81487d2bd3ef77f0680d977", "turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "role": "assistant"}, "revision": "retained_01a1f283-08d7-73e2-b67f-9b6564281bc3", "complete": true}, "client_authored": false, "user_input_order": 10}} +{"timestamp": "2026-11-19T06:33:56.284Z", "ordinal": 56, "type": "event_msg", "payload": {"type": "task_complete", "root_turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", "last_agent_message": "Pre-Landing Review: 1 issue (1 critical, 0 informational)\n\n- [critical] `calc.py:4-5` — `avg([])` raises `ZeroDivisionError` because `len(xs)` can be `0`; this makes the new helper fail on empty input.\n - Fix: reject empty input up front with a clear `ValueError`, or define and implement the intended empty-sequence behavior.\n\nGate edits: none detected (0 listed, 0 read; patterns: simple arithmetic helper; unlisted idioms: none)", "started_at": 1795070014, "completed_at": 1795070036, "duration_ms": 21730, "time_to_first_token_ms": 2902}} diff --git a/test/fixtures/skill-contract/codex/exec-read-failed-spawn.jsonl b/test/fixtures/skill-contract/codex/exec-read-failed-spawn.jsonl new file mode 100644 index 000000000..2f2a03745 --- /dev/null +++ b/test/fixtures/skill-contract/codex/exec-read-failed-spawn.jsonl @@ -0,0 +1,38 @@ +{"timestamp": "2026-11-19T06:23:16.559Z", "ordinal": 0, "type": "session_meta", "payload": {"account_scoped": true, "session_id": "01a1f279-4233-7603-8835-0297f9c2cfb7", "id": "01a1f279-4233-7603-8835-0297f9c2cfb7", "timestamp": "2026-11-19T06:23:16.471Z", "cwd": "/home/dev/repo", "runtime_workspace_roots": ["/home/dev/repo"], "originator": "codex_exec", "cli_version": "0.170.0", "source": "exec", "thread_source": "user", "model_provider": "openai", "history_mode": "paginated", "context_window": {"window_id": "01a1f279-45dd-77e0-8f4d-4f1a2eb7ae52"}}} +{"timestamp": "2026-11-19T06:23:16.559Z", "ordinal": 1, "type": "event_msg", "payload": {"type": "task_started", "turn_attribution": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "turn_trigger": "exec", "parent_turn_id": null, "initiating_agent_path": null, "root_turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b"}, "turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "root_turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "started_at": 1795069396, "model_context_window": 258400, "collaboration_mode_kind": "default"}} +{"timestamp": "2026-11-19T06:23:17.153Z", "ordinal": 2, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f279-48a0-7141-86f2-559b15248d4a", "role": "developer", "content": [{"type": "input_text", "text": "\n## Skills\nA skill is a set of local instructions to follow that is stored in a `SKILL.md` file. Below is the list of skills that can be used. Each entry includes a name, description, and a short path that can be expanded into an absolute path using the skill roots table.\n### Skill roots\n- `r0` = `/home/dev/.codex/skills`\n- `r1` = `/home/dev/.codex/skills/.system`\n### Available skills\n- imagegen: Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output should be a bitmap asset rather than repo-native code or vector. Do not use when the task is better handled by editing existing SVG/vector/code-native assets, extend\n[... 2266 characters trimmed from this fixture ...]\nhen you review a diff before it lands: local changes, a branch or a PR. Use for: review my changes, look over my diff, review this pr. (gstack) (file: r0/gstack/review/SKILL.md)\n"}, {"type": "input_text", "text": "\nFilesystem sandboxing defines which files can be read or written. `sandbox_mode` is `danger-full-access`: No filesystem sandboxing - all commands are permitted. Network access is enabled.\nApproval policy is currently never. Do not provide the `sandbox_permissions` for any reason, commands will be rejected.\n"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069397.1526296, "content_item_kinds": ["host_skills.instructions", "permissions.instructions"], "content_item_metadata": [{"provenance": {"type": "skills"}}, {"provenance": {"type": "harness", "hook": false}}]}}, "metadata": {"history_sequence": 1, "sampled_through_sequence": 0, "client_authored": false, "mcp_attribution": {"status": "none"}}} +{"timestamp": "2026-11-19T06:23:17.153Z", "ordinal": 3, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f279-48a0-7141-86f2-55abf3c50055", "role": "user", "content": [{"type": "input_text", "text": "\n /home/dev/repo\n bash\n 2026-11-19\n Etc/UTC\n /home/dev/repo\n"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069397.1526444, "content_item_kinds": ["environments.environment_context"], "content_item_metadata": [{"provenance": {"type": "harness", "hook": false}}]}}, "metadata": {"history_sequence": 2, "sampled_through_sequence": 0, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:17.157Z", "ordinal": 5, "type": "turn_context", "payload": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "root_turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "disabled_plugin_ids": [], "cwd": "/home/dev/repo", "approval_policy": "never", "approvals_reviewer": "user", "permission_profile": {"type": "disabled"}, "model": "gpt-5.4-mini", "collaboration_mode": {"mode": "default", "settings": {"model": "gpt-5.4-mini", "reasoning_effort": "low", "developer_instructions": null}}, "multi_agent_version": "v1", "realtime_active": false, "effort": "low", "summary": "none", "sandbox_policy": {"type": "danger-full-access"}}} +{"timestamp": "2026-11-19T06:23:17.157Z", "ordinal": 6, "type": "event_msg", "payload": {"type": "thread_settings_applied", "thread_id": "01a1f279-4233-7603-8835-0297f9c2cfb7", "thread_settings": {"model": "gpt-5.4-mini", "model_provider_id": "openai", "approval_policy": "never", "approvals_reviewer": "user", "requested_approvals_reviewer": "user", "permission_profile": {"type": "disabled"}, "cwd": "/home/dev/repo", "runtime_workspace_roots": ["/home/dev/repo"], "reasoning_effort": "low", "collaboration_mode": {"mode": "default", "settings": {"model": "gpt-5.4-mini", "reasoning_effort": "low", "developer_instructions": null}}, "disabled_plugin_ids": []}}} +{"timestamp": "2026-11-19T06:23:17.168Z", "ordinal": 7, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f279-48b0-7320-8a7a-0c86beb508b1", "role": "user", "content": [{"type": "input_text", "text": "Read the file $CODEX_HOME/skills/gstack-review/SKILL.md with a shell command and follow it to review this branch against main."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069397.168744, "content_item_kinds": ["user.text"], "content_item_metadata": [{"provenance": {"type": "user"}}]}}, "metadata": {"history_sequence": 3, "sampled_through_sequence": 0, "retained_source": {"id": {"message_id": "msg_01a1f279-48b0-7320-8a7a-0c86beb508b1", "turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "role": "user"}, "revision": "retained_01a1f279-48b0-7320-8a7a-0ca31325f33e", "complete": true}, "client_authored": false, "user_input_order": 0, "mcp_attribution": {"status": "none"}}} +{"timestamp": "2026-11-19T06:23:19.692Z", "ordinal": 10, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0d355085f8c3780f016afe95d6867487d2ae2a84b213abddc3", "summary": [{"type": "summary_text", "text": "**Inspecting skill file**\n\nI need to inspect the skill file and review the differences. I think this will involve using a shell command for that. It’s probably a simple task, but I want to make sure I catch everything relevant. Maybe I’ll double-check syntax details to avoid errors. I’m just trying to stay organized while I work through this, ensuring I carefully assess everything I need to see in that file!"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b"}}, "metadata": {"history_sequence": 4, "sampled_through_sequence": 3, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:19.720Z", "ordinal": 12, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_0d355085f8c3780f016afe95d7a56087d2aee6bf1ba860ee82", "role": "assistant", "content": [{"type": "output_text", "text": "I’ll read the review skill first, then inspect the branch diff against `main`.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069398.200102, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 5, "sampled_through_sequence": 3, "retained_source": {"id": {"message_id": "msg_0d355085f8c3780f016afe95d7a56087d2aee6bf1ba860ee82", "turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "role": "assistant"}, "revision": "retained_01a1f279-52a7-7703-8a77-29b469ada99a", "complete": true}, "client_authored": false, "user_input_order": 1}} +{"timestamp": "2026-11-19T06:23:19.915Z", "ordinal": 13, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0d355085f8c3780f016afe95d7acf087d296dbada7a2c90d04", "name": "exec_command", "arguments": "{\"cmd\":\"cat /home/dev/.codex/skills/gstack-review/SKILL.md && printf '\\\\n---GIT---\\\\n' && git status --short && printf '\\\\n---BRANCH---\\\\n' && git branch --show-current && printf '\\\\n---BASE---\\\\n' && git rev-parse --verify main && printf '\\\\n---DIFFSTAT---\\\\n' && git diff --stat main...HEAD\",\"workdir\":\"/home/dev/repo\",\"yield_time_ms\":10000,\"max_output_tokens\":12000}", "call_id": "call_LWT3WLiRKptHC0QBchhlH2si", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069398.200102}}, "metadata": {"history_sequence": 6, "sampled_through_sequence": 3, "client_authored": false, "user_input_order": 2}} +{"timestamp": "2026-11-19T06:23:20.030Z", "ordinal": 16, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f279-53dd-7460-a956-2f0ab13b4e39", "call_id": "call_LWT3WLiRKptHC0QBchhlH2si", "output": "Chunk ID: 9ab1d5\nWall time: 0.0000 seconds\nProcess exited with code 0\nOriginal token count: 26204\nOutput:\nWarning: truncated output (original token count: 26204)\nTotal output lines: 1470\n\n---\nname: review\ndescription: |\n Use when you review a diff before it lands: local changes, a branch or a PR.\n Finds bugs that pass CI and break production. Fits \"review this PR\", \"look\n over my diff\", \"review my changes\", \"code review\", \"check my diff\" or\n \"pre-landing review\".\n Proactively suggest before a merge. (gstack)\n---\n\n\n\n## Done means\n\nFinish only when each of these exists (contract v1):\n\n- `adversarial-pass`: an Agent dispatch for the adversarial pass, its prompt including \"Think like an attacker and a chaos engineer\".\n- `review-report`: a `Pre-Landing Review` with Gate edits fille\n[... 9089 characters trimmed from this fixture ...]\nly includes evidence. Never post vague replies.\n\n---GIT---\n\n---BRANCH---\nfeature\n\n---BASE---\n6b81502aacb60bf97e265ac70633e9be1177b1fe\n\n---DIFFSTAT---\n calc.py | 3 +++\n 1 file changed, 3 insertions(+)\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069400.0299506}}, "metadata": {"history_sequence": 7, "sampled_through_sequence": 3, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:23:22.002Z", "ordinal": 19, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0d355085f8c3780f016afe95d892c487d2b5307b7cf5defebd", "summary": [{"type": "summary_text", "text": "**Reviewing instructions and output**\n\nI need to review the full differences. Maybe I won’t need the web, but I might consider using the gstack contract. As a coding agent, I can review the code directly. Inspecting the file could also be necessary. I wonder if I need to run the skill start command. According to the instructions, I have to follow them carefully. Since the output was truncated, maybe it’s a good idea to get the skill start output to inspect more concisely."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b"}}, "metadata": {"history_sequence": 8, "sampled_through_sequence": 7, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:22.030Z", "ordinal": 21, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_0d355085f8c3780f016afe95d9f4a887d28883ceb6c8e9ca8c", "role": "assistant", "content": [{"type": "output_text", "text": "I’ve got the branch shape; now I’m reading the actual code diff.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069400.242458, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 9, "sampled_through_sequence": 7, "retained_source": {"id": {"message_id": "msg_0d355085f8c3780f016afe95d9f4a887d28883ceb6c8e9ca8c", "turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "role": "assistant"}, "revision": "retained_01a1f279-5bae-70f1-b55c-118aedaaba1e", "complete": true}, "client_authored": false, "user_input_order": 3}} +{"timestamp": "2026-11-19T06:23:22.278Z", "ordinal": 22, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0d355085f8c3780f016afe95d9fc9087d2b5ff17ab26864bfd", "name": "exec_command", "arguments": "{\"cmd\":\"git diff --unified=80 main...HEAD -- calc.py\",\"workdir\":\"/home/dev/repo\",\"yield_time_ms\":10000,\"max_output_tokens\":12000}", "call_id": "call_sXy6QqFW6ESmFK8ELkh0cQdM", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069400.242458}}, "metadata": {"history_sequence": 10, "sampled_through_sequence": 7, "client_authored": false, "user_input_order": 4}} +{"timestamp": "2026-11-19T06:23:22.339Z", "ordinal": 25, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f279-5ce3-75b3-bc85-edbb3b9cbdb0", "call_id": "call_sXy6QqFW6ESmFK8ELkh0cQdM", "output": "Chunk ID: c74e92\nWall time: 0.0000 seconds\nProcess exited with code 0\nOriginal token count: 47\nOutput:\ndiff --git a/calc.py b/calc.py\nindex d10b0e8..b8481fd 100644\n--- a/calc.py\n+++ b/calc.py\n@@ -1,2 +1,5 @@\n def div(a, b):\n return a / b\n+\n+def avg(xs):\n+ return sum(xs) / len(xs)\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069402.3393562}}, "metadata": {"history_sequence": 11, "sampled_through_sequence": 7, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:23:23.911Z", "ordinal": 28, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0d355085f8c3780f016afe95dadc7487d285923d376cf81217", "summary": [{"type": "summary_text", "text": "**Assessing a potential bug**\n\nI need to determine if there's a bug in the code. To do this, I should inspect the repository context and possibly the tests related to the module. It feels like I’ll need to do a bit of a calculation to really understand where the issue might lie. I want to be thorough to ensure I catch any problems. Let's dive in and figure this out!"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b"}}, "metadata": {"history_sequence": 12, "sampled_through_sequence": 11, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:24.082Z", "ordinal": 29, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0d355085f8c3780f016afe95dbddb487d29f3afc0894374a22", "name": "exec_command", "arguments": "{\"cmd\":\"sed -n '1,200p' calc.py && printf '\\\\n---USES---\\\\n' && rg -n \\\"\\\\bavg\\\\(|\\\\bdiv\\\\(\\\" -S .\",\"workdir\":\"/home/dev/repo\",\"yield_time_ms\":10000,\"max_output_tokens\":12000}", "call_id": "call_mBXyuElcAfczDjMDHg0ws42y", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069402.564599}}, "metadata": {"history_sequence": 13, "sampled_through_sequence": 11, "client_authored": false, "user_input_order": 5}} +{"timestamp": "2026-11-19T06:23:24.141Z", "ordinal": 32, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f279-63ed-7e93-a356-21257347fbf1", "call_id": "call_mBXyuElcAfczDjMDHg0ws42y", "output": "Chunk ID: 912674\nWall time: 0.0000 seconds\nProcess exited with code 0\nOriginal token count: 35\nOutput:\ndef div(a, b):\n return a / b\n\ndef avg(xs):\n return sum(xs) / len(xs)\n\n---USES---\n./calc.py:1:def div(a, b):\n./calc.py:4:def avg(xs):\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069404.1418686}}, "metadata": {"history_sequence": 14, "sampled_through_sequence": 11, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:23:26.322Z", "ordinal": 35, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0d355085f8c3780f016afe95dcb23887d2a4daedaa7c177e6c", "summary": [{"type": "summary_text", "text": "**Reviewing potential issues**\n\nI think I need to review the full diff against the main version because it's only an addition, so I'm looking for any issues. The ZeroDivisionError in avg([]) might be acceptable, but I need to check the style and expectations. I also need to determine if there's a bug based on the likely product. Could it accept any iterable? The len(xs) requires a sized container, but maybe the average is actually meant for an iterator. I should inspect the README and tests for clarification."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b"}}, "metadata": {"history_sequence": 15, "sampled_through_sequence": 14, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:26.519Z", "ordinal": 36, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0d355085f8c3780f016afe95de46dc87d29c86815971f4b218", "name": "exec_command", "arguments": "{\"cmd\":\"rg -n \\\"calc|average|division\\\" -S README* .\",\"workdir\":\"/home/dev/repo\",\"yield_time_ms\":10000,\"max_output_tokens\":12000}", "call_id": "call_sJ0K7nBznJ9DN49If7mKaeFR", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069404.382392}}, "metadata": {"history_sequence": 16, "sampled_through_sequence": 14, "client_authored": false, "user_input_order": 6}} +{"timestamp": "2026-11-19T06:23:26.579Z", "ordinal": 39, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f279-6d73-7803-b874-3f4ca706bd28", "call_id": "call_sJ0K7nBznJ9DN49If7mKaeFR", "output": "Chunk ID: b0a41e\nWall time: 0.0000 seconds\nProcess exited with code 2\nOriginal token count: 13\nOutput:\nrg: README*: No such file or directory (os error 2)\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069406.5797641}}, "metadata": {"history_sequence": 17, "sampled_through_sequence": 14, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:23:27.315Z", "ordinal": 42, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0d355085f8c3780f016afe95df266c87d28c333c3abb3a4a91", "summary": [], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b"}}, "metadata": {"history_sequence": 18, "sampled_through_sequence": 17, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:27.418Z", "ordinal": 44, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_0d355085f8c3780f016afe95df451c87d298f1200259eccb58", "role": "assistant", "content": [{"type": "output_text", "text": "I only found one new helper, so I’m checking for surrounding expectations before I decide whether it’s a bug.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069406.806512, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 19, "sampled_through_sequence": 17, "retained_source": {"id": {"message_id": "msg_0d355085f8c3780f016afe95df451c87d298f1200259eccb58", "turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "role": "assistant"}, "revision": "retained_01a1f279-70ba-73f3-8031-85db557123d2", "complete": true}, "client_authored": false, "user_input_order": 7}} +{"timestamp": "2026-11-19T06:23:27.713Z", "ordinal": 45, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0d355085f8c3780f016afe95df5fbc87d2ac46cef095a8aea9", "name": "exec_command", "arguments": "{\"cmd\":\"find . -maxdepth 2 -type f | sort\",\"workdir\":\"/home/dev/repo\",\"yield_time_ms\":10000,\"max_output_tokens\":12000}", "call_id": "call_szQOHJmEgG5X5mLxgjWSfs4k", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069406.806512}}, "metadata": {"history_sequence": 20, "sampled_through_sequence": 17, "client_authored": false, "user_input_order": 8}} +{"timestamp": "2026-11-19T06:23:27.764Z", "ordinal": 48, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f279-7214-7400-a155-aafd62820d1c", "call_id": "call_szQOHJmEgG5X5mLxgjWSfs4k", "output": "Chunk ID: 1142d5\nWall time: 0.0000 seconds\nProcess exited with code 0\nOriginal token count: 27\nOutput:\n./.git/COMMIT_EDITMSG\n./.git/FETCH_HEAD\n./.git/HEAD\n./.git/config\n./.git/description\n./.git/index\n./calc.py\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069407.7644882}}, "metadata": {"history_sequence": 21, "sampled_through_sequence": 17, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:23:31.078Z", "ordinal": 51, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0d355085f8c3780f016afe95e055ec87d2b0407d2939e4c785", "summary": [{"type": "summary_text", "text": "**Reviewing utility function issues**\n\nI’m focused on reviewing the `calc.py` script, specifically the average function, which may not handle empty lists properly. I wonder if that's a defect or just something expected. Should it raise an error? It’s possible it should validate inputs to avoid a ZeroDivisionError, which seems cryptic. \n\nThere could also be a TypeError if a generator is passed instead of a sequence. Since the function is named `avg`, it should accommodate any iterable. \n\nI’ll consider if an adversarial pass is necessary, following the user's request for a review."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b"}}, "metadata": {"history_sequence": 22, "sampled_through_sequence": 21, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:31.257Z", "ordinal": 52, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0d355085f8c3780f016afe95e3082487d297d9824f12807ccc", "name": "spawn_agent", "namespace": "multi_agent_v1", "arguments": "{\"message\":\"Think like an attacker and a chaos engineer. Review the branch diff against main in /home/dev/repo, focusing on calc.py. Look for correctness, edge cases, and any production-impacting bugs. Return only concrete findings with file/line references and a one-line rationale each; if none, say none.\",\"reasoning_effort\":\"medium\"}", "call_id": "call_bga4EaMdCmbwZJsvkZ4SbcX9", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069407.994359}}, "metadata": {"history_sequence": 23, "sampled_through_sequence": 21, "client_authored": false, "user_input_order": 9}} +{"timestamp": "2026-11-19T06:23:31.275Z", "ordinal": 54, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f279-7fcb-73f3-b309-567b13651c68", "call_id": "call_bga4EaMdCmbwZJsvkZ4SbcX9", "output": "Reasoning effort `medium` is not supported for model `gpt-5.4-mini`. Supported reasoning efforts: ", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069411.275834}}, "metadata": {"history_sequence": 24, "sampled_through_sequence": 21, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:23:32.080Z", "ordinal": 57, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0d355085f8c3780f016afe95e3d8e487d2bf907617950a9481", "summary": [], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b"}}, "metadata": {"history_sequence": 25, "sampled_through_sequence": 24, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:32.317Z", "ordinal": 58, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0d355085f8c3780f016afe95e408cc87d2b9b98d5c46551016", "name": "spawn_agent", "namespace": "multi_agent_v1", "arguments": "{\"message\":\"Think like an attacker and a chaos engineer. Review the branch diff against main in /home/dev/repo, focusing on calc.py. Look for correctness, edge cases, and any production-impacting bugs. Return only concrete findings with file/line references and a one-line rationale each; if none, say none.\"}", "call_id": "call_XXovIjGsJeZXJzrPO8bikoUO", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069411.510641}}, "metadata": {"history_sequence": 26, "sampled_through_sequence": 24, "client_authored": false, "user_input_order": 10}} +{"timestamp": "2026-11-19T06:23:32.372Z", "ordinal": 61, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f279-8414-71f0-84d0-bfc3bb0e3c5d", "call_id": "call_XXovIjGsJeZXJzrPO8bikoUO", "output": "{\"agent_id\":\"01a1f279-83e0-7b63-89c1-316b620bcaf1\",\"nickname\":\"Hooke\"}", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069412.3721929}}, "metadata": {"history_sequence": 27, "sampled_through_sequence": 24, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:23:34.025Z", "ordinal": 65, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0d355085f8c3780f016afe95e4e81c87d289695be3bc11b9fa", "summary": [], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b"}}, "metadata": {"history_sequence": 28, "sampled_through_sequence": 27, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:34.134Z", "ordinal": 66, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0d355085f8c3780f016afe95e5fae087d2ad1f2cb3773dd824", "name": "wait_agent", "namespace": "multi_agent_v1", "arguments": "{\"targets\":[\"01a1f279-83e0-7b63-89c1-316b620bcaf1\"],\"timeout_ms\":10000}", "call_id": "call_jfGYf0N2c2CGP3q9bVdLWzW2", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069412.602096}}, "metadata": {"history_sequence": 29, "sampled_through_sequence": 27, "client_authored": false, "user_input_order": 11}} +{"timestamp": "2026-11-19T06:23:38.864Z", "ordinal": 69, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f279-9d70-7093-b75d-cd216c413721", "call_id": "call_jfGYf0N2c2CGP3q9bVdLWzW2", "output": "{\"status\":{\"01a1f279-83e0-7b63-89c1-316b620bcaf1\":{\"completed\":\"- `calc.py:4` — `avg(xs)` crashes on empty input because `len(xs)` becomes `0`, so `sum(xs) / len(xs)` raises `ZeroDivisionError`.\\n- `calc.py:4` — `avg(xs)` only works for sized containers; passing a generator or other iterable without `__len__` raises `TypeError` at `len(xs)`.\"}},\"timed_out\":false}", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069418.8649094}}, "metadata": {"history_sequence": 30, "sampled_through_sequence": 27, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:23:38.867Z", "ordinal": 71, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f279-9d73-7730-91b1-81e318170171", "role": "user", "content": [{"type": "input_text", "text": "\n{\"agent_path\":\"01a1f279-83e0-7b63-89c1-316b620bcaf1\",\"status\":{\"completed\":\"- `calc.py:4` — `avg(xs)` crashes on empty input because `len(xs)` becomes `0`, so `sum(xs) / len(xs)` raises `ZeroDivisionError`.\\n- `calc.py:4` — `avg(xs)` only works for sized containers; passing a generator or other iterable without `__len__` raises `TypeError` at `len(xs)`.\"}}\n"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069418.8671021, "content_item_kinds": ["multi_agent.subagent_notification"], "content_item_metadata": [{"provenance": {"type": "tool", "namespace": "multi_agent_v1"}}]}}, "metadata": {"history_sequence": 31, "sampled_through_sequence": 27, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:41.898Z", "ordinal": 73, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0d355085f8c3780f016afe95ec33a087d28f8d26011946b1f9", "summary": [{"type": "summary_text", "text": "**Reviewing report requirements**\n\nI need to create a final review report that's concise and highlights any issues. I might want to include gate edits, but only if I'm using all the steps. It seems skill demands mentioning gate edits, but I could also say that none were detected if applicable. Since we don't have GATE_SUMMARY, I should provide a review while noting that no tests were run. Staying concise is key!"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b"}}, "metadata": {"history_sequence": 32, "sampled_through_sequence": 31, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:42.091Z", "ordinal": 75, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_0d355085f8c3780f016afe95edda0c87d2a26f524bbf3db7b4", "role": "assistant", "content": [{"type": "output_text", "text": "Pre-Landing Review: 2 issues (2 critical, 0 informational)\n\n- `calc.py:4` — `avg(xs)` crashes on empty input because `len(xs)` is `0`, so `sum(xs) / len(xs)` raises `ZeroDivisionError`; guard empties or define the expected behavior explicitly.\n- `calc.py:4` — `avg(xs)` rejects valid iterables like generators because it requires `len(xs)`; if callers can pass any iterable, this will fail with `TypeError`.\n\nI didn’t run tests; the branch only adds this helper, so the review is based on the diff and surrounding file context.", "annotations": [], "logprobs": []}], "phase": "final_answer", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "create_time": 1795069419.88212, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 33, "sampled_through_sequence": 31, "retained_source": {"id": {"message_id": "msg_0d355085f8c3780f016afe95edda0c87d2a26f524bbf3db7b4", "turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "role": "assistant"}, "revision": "retained_01a1f279-aa0b-77a0-8a49-3bd90545243c", "complete": true}, "client_authored": false, "user_input_order": 12}} +{"timestamp": "2026-11-19T06:23:42.128Z", "ordinal": 78, "type": "event_msg", "payload": {"type": "task_complete", "root_turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "last_agent_message": "Pre-Landing Review: 2 issues (2 critical, 0 informational)\n\n- `calc.py:4` — `avg(xs)` crashes on empty input because `len(xs)` is `0`, so `sum(xs) / len(xs)` raises `ZeroDivisionError`; guard empties or define the expected behavior explicitly.\n- `calc.py:4` — `avg(xs)` rejects valid iterables like generators because it requires `len(xs)`; if callers can pass any iterable, this will fail with `TypeError`.\n\nI didn’t run tests; the branch only adds this helper, so the review is based on the diff and surrounding file context.", "started_at": 1795069396, "completed_at": 1795069422, "duration_ms": 25612, "time_to_first_token_ms": 2296}} diff --git a/test/fixtures/skill-contract/codex/exec-read-met.jsonl b/test/fixtures/skill-contract/codex/exec-read-met.jsonl new file mode 100644 index 000000000..72c24edc5 --- /dev/null +++ b/test/fixtures/skill-contract/codex/exec-read-met.jsonl @@ -0,0 +1,43 @@ +{"timestamp": "2026-11-19T06:32:43.369Z", "ordinal": 0, "type": "session_meta", "payload": {"account_scoped": true, "session_id": "01a1f281-eb07-7940-a3fd-e8cf129453b7", "id": "01a1f281-eb07-7940-a3fd-e8cf129453b7", "timestamp": "2026-11-19T06:32:43.288Z", "cwd": "/home/dev/repo", "runtime_workspace_roots": ["/home/dev/repo"], "originator": "codex_exec", "cli_version": "0.170.0", "source": "exec", "thread_source": "user", "model_provider": "openai", "history_mode": "paginated", "context_window": {"window_id": "01a1f281-ebf7-79f1-8e87-04fb4cfea4af"}}} +{"timestamp": "2026-11-19T06:32:43.369Z", "ordinal": 1, "type": "event_msg", "payload": {"type": "task_started", "turn_attribution": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "turn_trigger": "exec", "parent_turn_id": null, "initiating_agent_path": null, "root_turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57"}, "turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "root_turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "started_at": 1795069963, "model_context_window": 258400, "collaboration_mode_kind": "default"}} +{"timestamp": "2026-11-19T06:32:43.864Z", "ordinal": 2, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f281-ee57-7d00-a575-a32f753e77b8", "role": "developer", "content": [{"type": "input_text", "text": "\n## Skills\nA skill is a set of local instructions to follow that is stored in a `SKILL.md` file. Below is the list of skills that can be used. Each entry includes a name, description, and a short path that can be expanded into an absolute path using the skill roots table.\n### Skill roots\n- `r0` = `/home/dev/.codex/skills`\n- `r1` = `/home/dev/.codex/skills/.system`\n### Available skills\n- imagegen: Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output should be a bitmap asset rather than repo-native code or vector. Do not use when the task is better handled by editing existing SVG/vector/code-native assets, extend\n[... 2266 characters trimmed from this fixture ...]\nhen you review a diff before it lands: local changes, a branch or a PR. Use for: review my changes, look over my diff, review this pr. (gstack) (file: r0/gstack/review/SKILL.md)\n"}, {"type": "input_text", "text": "\nFilesystem sandboxing defines which files can be read or written. `sandbox_mode` is `danger-full-access`: No filesystem sandboxing - all commands are permitted. Network access is enabled.\nApproval policy is currently never. Do not provide the `sandbox_permissions` for any reason, commands will be rejected.\n"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069963.863591, "content_item_kinds": ["host_skills.instructions", "permissions.instructions"], "content_item_metadata": [{"provenance": {"type": "skills"}}, {"provenance": {"type": "harness", "hook": false}}]}}, "metadata": {"history_sequence": 1, "sampled_through_sequence": 0, "client_authored": false, "mcp_attribution": {"status": "none"}}} +{"timestamp": "2026-11-19T06:32:43.864Z", "ordinal": 3, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f281-ee57-7d00-a575-a33ed7da5f21", "role": "user", "content": [{"type": "input_text", "text": "\n /home/dev/repo\n bash\n 2026-11-19\n Etc/UTC\n /home/dev/repo\n"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069963.8636086, "content_item_kinds": ["environments.environment_context"], "content_item_metadata": [{"provenance": {"type": "harness", "hook": false}}]}}, "metadata": {"history_sequence": 2, "sampled_through_sequence": 0, "client_authored": false}} +{"timestamp": "2026-11-19T06:32:43.867Z", "ordinal": 5, "type": "turn_context", "payload": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "root_turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "disabled_plugin_ids": [], "cwd": "/home/dev/repo", "approval_policy": "never", "approvals_reviewer": "user", "permission_profile": {"type": "disabled"}, "model": "gpt-5.4-mini", "collaboration_mode": {"mode": "default", "settings": {"model": "gpt-5.4-mini", "reasoning_effort": "low", "developer_instructions": null}}, "multi_agent_version": "v1", "realtime_active": false, "effort": "low", "summary": "none", "sandbox_policy": {"type": "danger-full-access"}}} +{"timestamp": "2026-11-19T06:32:43.867Z", "ordinal": 6, "type": "event_msg", "payload": {"type": "thread_settings_applied", "thread_id": "01a1f281-eb07-7940-a3fd-e8cf129453b7", "thread_settings": {"model": "gpt-5.4-mini", "model_provider_id": "openai", "approval_policy": "never", "approvals_reviewer": "user", "requested_approvals_reviewer": "user", "permission_profile": {"type": "disabled"}, "cwd": "/home/dev/repo", "runtime_workspace_roots": ["/home/dev/repo"], "reasoning_effort": "low", "collaboration_mode": {"mode": "default", "settings": {"model": "gpt-5.4-mini", "reasoning_effort": "low", "developer_instructions": null}}, "disabled_plugin_ids": []}}} +{"timestamp": "2026-11-19T06:32:43.872Z", "ordinal": 7, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f281-ee60-7d50-b2c5-1b2cc14fb6a4", "role": "user", "content": [{"type": "input_text", "text": "Read the file $CODEX_HOME/skills/gstack-review/SKILL.md with a shell command and follow it to review this branch against main."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069963.8725467, "content_item_kinds": ["user.text"], "content_item_metadata": [{"provenance": {"type": "user"}}]}}, "metadata": {"history_sequence": 3, "sampled_through_sequence": 0, "retained_source": {"id": {"message_id": "msg_01a1f281-ee60-7d50-b2c5-1b2cc14fb6a4", "turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "role": "user"}, "revision": "retained_01a1f281-ee60-7d50-b2c5-1b432349ea8d", "complete": true}, "client_authored": false, "user_input_order": 0, "mcp_attribution": {"status": "none"}}} +{"timestamp": "2026-11-19T06:32:45.080Z", "ordinal": 10, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0a19968f2186c97b016afe980ced3c87d28c49b6150b8b00f8", "summary": [], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57"}}, "metadata": {"history_sequence": 4, "sampled_through_sequence": 3, "client_authored": false}} +{"timestamp": "2026-11-19T06:32:45.137Z", "ordinal": 12, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_0a19968f2186c97b016afe980d09f887d2a7c3d404e1f0df89", "role": "assistant", "content": [{"type": "output_text", "text": "I’ll read the review skill first, then inspect the diff against `main`.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069964.483186, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 5, "sampled_through_sequence": 3, "retained_source": {"id": {"message_id": "msg_0a19968f2186c97b016afe980d09f887d2a7c3d404e1f0df89", "turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "role": "assistant"}, "revision": "retained_01a1f281-f351-7ea3-baa5-736889362a0d", "complete": true}, "client_authored": false, "user_input_order": 1}} +{"timestamp": "2026-11-19T06:32:45.734Z", "ordinal": 13, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0a19968f2186c97b016afe980d18e087d28e873667f1da1cef", "name": "exec_command", "arguments": "{\"cmd\":\"cat /home/dev/.codex/skills/gstack-review/SKILL.md && printf '\\\\n---GIT---\\\\n' && git status --short && printf '\\\\n---BRANCH---\\\\n' && git branch --show-current && printf '\\\\n---BASE---\\\\n' && git rev-parse --abbrev-ref main 2>/dev/null || true\",\"workdir\":\"/home/dev/repo\",\"yield_time_ms\":10000,\"max_output_tokens\":12000}", "call_id": "call_ygn3PtZlvLsPo8nkm1ze1D7R", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069964.483186}}, "metadata": {"history_sequence": 6, "sampled_through_sequence": 3, "client_authored": false, "user_input_order": 2}} +{"timestamp": "2026-11-19T06:32:45.878Z", "ordinal": 16, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f281-f636-7f63-9b99-d27edf5d686c", "call_id": "call_ygn3PtZlvLsPo8nkm1ze1D7R", "output": "Chunk ID: de74e8\nWall time: 0.0000 seconds\nProcess exited with code 0\nOriginal token count: 26179\nOutput:\nWarning: truncated output (original token count: 26179)\nTotal output lines: 1466\n\n---\nname: review\ndescription: |\n Use when you review a diff before it lands: local changes, a branch or a PR.\n Finds bugs that pass CI and break production. Fits \"review this PR\", \"look\n over my diff\", \"review my changes\", \"code review\", \"check my diff\" or\n \"pre-landing review\".\n Proactively suggest before a merge. (gstack)\n---\n\n\n\n## Done means\n\nFinish only when each of these exists (contract v1):\n\n- `adversarial-pass`: an Agent dispatch for the adversarial pass, its prompt including \"Think like an attacker and a chaos engineer\".\n- `review-report`: a `Pre-Landing Review` with Gate edits fille\n[... 9089 characters trimmed from this fixture ...]\nual defects independently actionable.\n- **Use the reply templates from greptile-triage.md.** Every reply includes evidence. Never post vague replies.\n\n---GIT---\n\n---BRANCH---\nfeature\n\n---BASE---\nmain\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069965.87859}}, "metadata": {"history_sequence": 7, "sampled_through_sequence": 3, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:32:47.866Z", "ordinal": 19, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0a19968f2186c97b016afe980e7a0887d2b37b0750b32cd887", "summary": [{"type": "summary_text", "text": "**Figuring out process execution**\n\nI need to consider running gstack separately since the output seems truncated, but maybe it’s still enough. I might just need to use the shell only. I need to review the differences and consider whether I should follow the skill: adversarial pass dispatch. Is it better to review this branch against the main branch? I think using skills and possibly spawning a multi_agent might help comply with the contract that mentions adversarial-pass dispatch. I need to inspect the differences carefully."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57"}}, "metadata": {"history_sequence": 8, "sampled_through_sequence": 7, "client_authored": false}} +{"timestamp": "2026-11-19T06:32:47.884Z", "ordinal": 21, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_0a19968f2186c97b016afe980fd33c87d2b5f94d7625be477b", "role": "assistant", "content": [{"type": "output_text", "text": "I’ve got the review skill loaded; now I’m pulling the full branch diff.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069966.063813, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 9, "sampled_through_sequence": 7, "retained_source": {"id": {"message_id": "msg_0a19968f2186c97b016afe980fd33c87d2b5f94d7625be477b", "turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "role": "assistant"}, "revision": "retained_01a1f281-fe0c-7620-98f7-be8dcc1b67c1", "complete": true}, "client_authored": false, "user_input_order": 3}} +{"timestamp": "2026-11-19T06:32:48.023Z", "ordinal": 22, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0a19968f2186c97b016afe980fd86c87d286a1b7a142e661c7", "name": "exec_command", "arguments": "{\"cmd\":\"git diff --stat main...HEAD && printf '\\\\n---FILES---\\\\n' && git diff --name-only main...HEAD && printf '\\\\n---DIFF---\\\\n' && git diff --find-renames --find-copies main...HEAD\",\"workdir\":\"/home/dev/repo\",\"yield_time_ms\":10000,\"max_output_tokens\":20000}", "call_id": "call_f9enypSD9svR35ZUOwsUAQQC", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069966.063813}}, "metadata": {"history_sequence": 10, "sampled_through_sequence": 7, "client_authored": false, "user_input_order": 4}} +{"timestamp": "2026-11-19T06:32:48.085Z", "ordinal": 25, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f281-fed5-7181-b112-9fddb599aaac", "call_id": "call_f9enypSD9svR35ZUOwsUAQQC", "output": "Chunk ID: 300329\nWall time: 0.0000 seconds\nProcess exited with code 128\nOriginal token count: 48\nOutput:\nfatal: ambiguous argument 'main...HEAD': unknown revision or path not in the working tree.\nUse '--' to separate paths from revisions, like this:\n'git [...] -- [...]'\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069968.0856133}}, "metadata": {"history_sequence": 11, "sampled_through_sequence": 7, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:32:48.931Z", "ordinal": 28, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0a19968f2186c97b016afe9810b2fc87d2bac2351c46c52b3b", "summary": [], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57"}}, "metadata": {"history_sequence": 12, "sampled_through_sequence": 11, "client_authored": false}} +{"timestamp": "2026-11-19T06:32:48.954Z", "ordinal": 30, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_0a19968f2186c97b016afe9810e41087d28318dc0f6f7e419d", "role": "assistant", "content": [{"type": "output_text", "text": "`main` isn’t present locally, so I’m locating the base ref next.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069968.275449, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 13, "sampled_through_sequence": 11, "retained_source": {"id": {"message_id": "msg_0a19968f2186c97b016afe9810e41087d28318dc0f6f7e419d", "turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "role": "assistant"}, "revision": "retained_01a1f282-023a-7db0-9366-b9a80e00fe20", "complete": true}, "client_authored": false, "user_input_order": 5}} +{"timestamp": "2026-11-19T06:32:49.262Z", "ordinal": 31, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0a19968f2186c97b016afe9810ea3c87d2ba8b55b24fb21e0d", "name": "exec_command", "arguments": "{\"cmd\":\"git branch -a --verbose --no-abbrev && printf '\\\\n---REFS---\\\\n' && git show-ref --heads --tags | sed -n '1,40p'\",\"workdir\":\"/home/dev/repo\",\"yield_time_ms\":10000,\"max_output_tokens\":12000}", "call_id": "call_A8Vpg0rylRabhfCwgSpGPnGJ", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069968.275449}}, "metadata": {"history_sequence": 14, "sampled_through_sequence": 11, "client_authored": false, "user_input_order": 6}} +{"timestamp": "2026-11-19T06:32:49.379Z", "ordinal": 34, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f282-03e3-7152-86f2-f4f490c1216d", "call_id": "call_A8Vpg0rylRabhfCwgSpGPnGJ", "output": "Chunk ID: 2b4051\nWall time: 0.0000 seconds\nProcess exited with code 0\nOriginal token count: 83\nOutput:\n* feature 0cf8bb7f0bde58b3965dbeb4a854a29370118f03 add avg\n remotes/origin/HEAD -> origin/main\n remotes/origin/feature 0cf8bb7f0bde58b3965dbeb4a854a29370118f03 add avg\n remotes/origin/main 6b81502aacb60bf97e265ac70633e9be1177b1fe base\n\n---REFS---\n0cf8bb7f0bde58b3965dbeb4a854a29370118f03 refs/heads/feature\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069969.3794713}}, "metadata": {"history_sequence": 15, "sampled_through_sequence": 11, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:32:51.671Z", "ordinal": 37, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0a19968f2186c97b016afe981224a487d297699fdf8e9698bd", "summary": [{"type": "summary_text", "text": "**Evaluating commands and processes**\n\nI need to do a diff against origin/main. Maybe I should use the gstack skill start, though I'm not sure if it's necessary. I could consider using a shell command from the preamble instead. Running the skill might be required right now. Additionally, I need to prepare for the adversarial pass dispatch, perhaps using multi_agent spawn. So, let’s inspect that diff carefully to ensure everything is in order!"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57"}}, "metadata": {"history_sequence": 16, "sampled_through_sequence": 15, "client_authored": false}} +{"timestamp": "2026-11-19T06:32:51.831Z", "ordinal": 38, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0a19968f2186c97b016afe9813a15087d2bbf226ba823d443e", "name": "exec_command", "arguments": "{\"cmd\":\"git diff --stat origin/main...HEAD && printf '\\\\n---FILES---\\\\n' && git diff --name-only origin/main...HEAD && printf '\\\\n---DIFF---\\\\n' && git diff --find-renames --find-copies origin/main...HEAD\",\"workdir\":\"/home/dev/repo.typo\",\"yield_time_ms\":10000,\"max_output_tokens\":20000}", "call_id": "call_IQN5HGjfB746BfH3x3DooTn7", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069969.561137}}, "metadata": {"history_sequence": 17, "sampled_through_sequence": 15, "client_authored": false, "user_input_order": 7}} +{"timestamp": "2026-11-19T06:32:51.843Z", "ordinal": 41, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f282-0d83-7613-a0b4-643cf13092be", "call_id": "call_IQN5HGjfB746BfH3x3DooTn7", "output": "exec_command failed: CreateProcess { message: \"Rejected(\\\"Failed to create unified exec process: No such file or directory (os error 2)\\\")\" }", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069971.8432176}}, "metadata": {"history_sequence": 18, "sampled_through_sequence": 15, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:32:52.525Z", "ordinal": 44, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0a19968f2186c97b016afe9814539487d2859714f3d2ad0a35", "summary": [], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57"}}, "metadata": {"history_sequence": 19, "sampled_through_sequence": 18, "client_authored": false}} +{"timestamp": "2026-11-19T06:32:52.568Z", "ordinal": 46, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_0a19968f2186c97b016afe98147be087d29b491cc731285e86", "role": "assistant", "content": [{"type": "output_text", "text": "I hit a path typo; retrying the diff against `origin/main`.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069972.01511, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 20, "sampled_through_sequence": 18, "retained_source": {"id": {"message_id": "msg_0a19968f2186c97b016afe98147be087d29b491cc731285e86", "turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "role": "assistant"}, "revision": "retained_01a1f282-1058-74d2-a6e6-16b7594c0feb", "complete": true}, "client_authored": false, "user_input_order": 8}} +{"timestamp": "2026-11-19T06:32:52.914Z", "ordinal": 47, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0a19968f2186c97b016afe9814872887d28c1b0bde09ba17cd", "name": "exec_command", "arguments": "{\"cmd\":\"git diff --stat origin/main...HEAD && printf '\\\\n---FILES---\\\\n' && git diff --name-only origin/main...HEAD && printf '\\\\n---DIFF---\\\\n' && git diff --find-renames --find-copies origin/main...HEAD\",\"workdir\":\"/home/dev/repo\",\"yield_time_ms\":10000,\"max_output_tokens\":20000}", "call_id": "call_YmJ6hgLVcz0tDWS10odgexwD", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069972.01511}}, "metadata": {"history_sequence": 21, "sampled_through_sequence": 18, "client_authored": false, "user_input_order": 9}} +{"timestamp": "2026-11-19T06:32:53.024Z", "ordinal": 50, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f282-1220-78e2-a042-0e431b320e98", "call_id": "call_YmJ6hgLVcz0tDWS10odgexwD", "output": "Chunk ID: b94440\nWall time: 0.0000 seconds\nProcess exited with code 0\nOriginal token count: 67\nOutput:\n calc.py | 3 +++\n 1 file changed, 3 insertions(+)\n\n---FILES---\ncalc.py\n\n---DIFF---\ndiff --git a/calc.py b/calc.py\nindex d10b0e8..b8481fd 100644\n--- a/calc.py\n+++ b/calc.py\n@@ -1,2 +1,5 @@\n def div(a, b):\n return a / b\n+\n+def avg(xs):\n+ return sum(xs) / len(xs)\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069973.0244985}}, "metadata": {"history_sequence": 22, "sampled_through_sequence": 18, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:32:54.896Z", "ordinal": 53, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0a19968f2186c97b016afe981576ac87d2b3b5a1ee365b7686", "summary": [{"type": "summary_text", "text": "**Reviewing potential issues**\n\nI need to review the possible issue regarding an empty list causing a division by zero. It might be intentional, but I should inspect the context, possibly looking at tests. I could also check the git log for more insights. Maybe I need to consider an adversarial pass by spawning an agent with an attacker prompt. I'll dive into that while checking the relevant file at the same time."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57"}}, "metadata": {"history_sequence": 23, "sampled_through_sequence": 22, "client_authored": false}} +{"timestamp": "2026-11-19T06:32:54.912Z", "ordinal": 55, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_0a19968f2186c97b016afe9816db0487d28bd30e4a46410406", "role": "assistant", "content": [{"type": "output_text", "text": "I’ve got a tiny patch; I’m running a quick adversarial sanity check now.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069973.196594, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 24, "sampled_through_sequence": 22, "retained_source": {"id": {"message_id": "msg_0a19968f2186c97b016afe9816db0487d28bd30e4a46410406", "turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "role": "assistant"}, "revision": "retained_01a1f282-1980-7642-8918-61264eb2a506", "complete": true}, "client_authored": false, "user_input_order": 10}} +{"timestamp": "2026-11-19T06:32:55.020Z", "ordinal": 56, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0a19968f2186c97b016afe9816dfac87d29619a8ca7bbf4213", "name": "spawn_agent", "namespace": "multi_agent_v1", "arguments": "{\"message\":\"Think like an attacker and a chaos engineer. Review the branch diff against origin/main for calc.py. Look only for correctness/safety bugs that would pass casual review. Return concise findings with file/line references and why they matter. If no issues, say none.\",\"reasoning_effort\":\"medium\"}", "call_id": "call_cIivUrchuutcCvN8p5CNQAnx", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069973.196594}}, "metadata": {"history_sequence": 25, "sampled_through_sequence": 22, "client_authored": false, "user_input_order": 11}} +{"timestamp": "2026-11-19T06:32:55.033Z", "ordinal": 58, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f282-19f9-7d41-9d60-0e9efb66c80b", "call_id": "call_cIivUrchuutcCvN8p5CNQAnx", "output": "Reasoning effort `medium` is not supported for model `gpt-5.4-mini`. Supported reasoning efforts: ", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069975.0332816}}, "metadata": {"history_sequence": 26, "sampled_through_sequence": 22, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:32:56.021Z", "ordinal": 61, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0a19968f2186c97b016afe9817a99087d2a1affafd112f96c1", "summary": [], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57"}}, "metadata": {"history_sequence": 27, "sampled_through_sequence": 26, "client_authored": false}} +{"timestamp": "2026-11-19T06:32:56.182Z", "ordinal": 62, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0a19968f2186c97b016afe9817fa8087d28d8eb1a835d64663", "name": "spawn_agent", "namespace": "multi_agent_v1", "arguments": "{\"message\":\"Think like an attacker and a chaos engineer. Review the branch diff against origin/main for calc.py. Look only for correctness/safety bugs that would pass casual review. Return concise findings with file/line references and why they matter. If no issues, say none.\"}", "call_id": "call_mzgRpvOy37n0U8WRhzPTiOeb", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069975.199053}}, "metadata": {"history_sequence": 28, "sampled_through_sequence": 26, "client_authored": false, "user_input_order": 12}} +{"timestamp": "2026-11-19T06:32:56.243Z", "ordinal": 65, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f282-1eb3-7242-b4b9-57aa6e6afa7a", "call_id": "call_mzgRpvOy37n0U8WRhzPTiOeb", "output": "{\"agent_id\":\"01a1f282-1e7a-7983-b9d1-c1a4d902856e\",\"nickname\":\"Parfit\"}", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069976.2430558}}, "metadata": {"history_sequence": 29, "sampled_through_sequence": 26, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:32:57.889Z", "ordinal": 69, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0a19968f2186c97b016afe9818bb3487d2aed1f70caed0e0d4", "summary": [{"type": "summary_text", "text": "**Evaluating next steps**\n\nI'm considering whether I need to wait or if I can proceed without delay. It might be useful to continue working locally, but I'm wondering if there's an issue that complicates things. I think I should take some time to understand the repository better, specifically focusing on the calc.py file. I’ll want to carefully inspect the lines in that file to see what’s going on. Let's dig into it!"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57"}}, "metadata": {"history_sequence": 30, "sampled_through_sequence": 29, "client_authored": false}} +{"timestamp": "2026-11-19T06:32:58.017Z", "ordinal": 70, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0a19968f2186c97b016afe9819d96c87d2b7c57940516f7c88", "name": "exec_command", "arguments": "{\"cmd\":\"nl -ba calc.py\",\"workdir\":\"/home/dev/repo\",\"yield_time_ms\":10000,\"max_output_tokens\":4000}", "call_id": "call_ZhCTmeTa2RyMoLQo9lMkxCLt", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069976.426568}}, "metadata": {"history_sequence": 31, "sampled_through_sequence": 29, "client_authored": false, "user_input_order": 13}} +{"timestamp": "2026-11-19T06:32:58.082Z", "ordinal": 73, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f282-25e1-7353-aa45-72ffb6aedda3", "call_id": "call_ZhCTmeTa2RyMoLQo9lMkxCLt", "output": "Chunk ID: e93b81\nWall time: 0.0000 seconds\nProcess exited with code 0\nOriginal token count: 28\nOutput:\n 1\tdef div(a, b):\n 2\t return a / b\n 3\t\n 4\tdef avg(xs):\n 5\t return sum(xs) / len(xs)\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069978.0819583}}, "metadata": {"history_sequence": 32, "sampled_through_sequence": 29, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:32:59.966Z", "ordinal": 76, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0a19968f2186c97b016afe981a970087d2a293e51ee16fd730", "summary": [{"type": "summary_text", "text": "**Considering potential issues**\n\nI think I need to review the code to see if the only issue is an empty \"xs.\" That feels like it could be a bug, which is a bit concerning. Also, there might be a PEP8 concern regarding any blank lines between functions, but that doesn't seem like a major defect. I'll have to wait for the agent's input on this to clarify everything. Patience can be tough in situations like this!"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57"}}, "metadata": {"history_sequence": 33, "sampled_through_sequence": 32, "client_authored": false}} +{"timestamp": "2026-11-19T06:33:00.028Z", "ordinal": 77, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0a19968f2186c97b016afe981becc887d29a0377f2243fe7a6", "name": "wait_agent", "namespace": "multi_agent_v1", "arguments": "{\"targets\":[\"01a1f282-1e7a-7983-b9d1-c1a4d902856e\"],\"timeout_ms\":10000}", "call_id": "call_zRVlqHZED3We2gxr60hElg7I", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069978.263194}}, "metadata": {"history_sequence": 34, "sampled_through_sequence": 32, "client_authored": false, "user_input_order": 14}} +{"timestamp": "2026-11-19T06:33:03.124Z", "ordinal": 80, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f282-3994-7552-8862-abe01e68a4f5", "call_id": "call_zRVlqHZED3We2gxr60hElg7I", "output": "{\"status\":{\"01a1f282-1e7a-7983-b9d1-c1a4d902856e\":{\"completed\":\"- `calc.py:4-5` — `avg(xs)` assumes `xs` is a non-empty, sized container. It raises `ZeroDivisionError` on `[]` and `TypeError` on iterators/generators with no `len()`, which makes the new API brittle for common inputs and can surface as an unexpected runtime crash.\"}},\"timed_out\":false}", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069983.124205}}, "metadata": {"history_sequence": 35, "sampled_through_sequence": 32, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:33:03.126Z", "ordinal": 82, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f282-3996-7bd3-b7e2-304559a6a6db", "role": "user", "content": [{"type": "input_text", "text": "\n{\"agent_path\":\"01a1f282-1e7a-7983-b9d1-c1a4d902856e\",\"status\":{\"completed\":\"- `calc.py:4-5` — `avg(xs)` assumes `xs` is a non-empty, sized container. It raises `ZeroDivisionError` on `[]` and `TypeError` on iterators/generators with no `len()`, which makes the new API brittle for common inputs and can surface as an unexpected runtime crash.\"}}\n"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069983.1260421, "content_item_kinds": ["multi_agent.subagent_notification"], "content_item_metadata": [{"provenance": {"type": "tool", "namespace": "multi_agent_v1"}}]}}, "metadata": {"history_sequence": 36, "sampled_through_sequence": 32, "client_authored": false}} +{"timestamp": "2026-11-19T06:33:04.585Z", "ordinal": 84, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0a19968f2186c97b016afe981fe3e487d2822221107ebcb274", "summary": [], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57"}}, "metadata": {"history_sequence": 37, "sampled_through_sequence": 36, "client_authored": false}} +{"timestamp": "2026-11-19T06:33:04.758Z", "ordinal": 86, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_0a19968f2186c97b016afe98208b1c87d28dcab9e639a8933b", "role": "assistant", "content": [{"type": "output_text", "text": "Pre-Landing Review: 1 issue (1 critical, 0 informational)\n\n- Critical — `calc.py:4-5`: `avg(xs)` crashes on empty input (`ZeroDivisionError`) and rejects iterators/generators because it requires `len(xs)`. That makes the new API brittle for common callers and turns a simple helper into a runtime failure path.\n\nGate edits: none detected.", "annotations": [], "logprobs": []}], "phase": "final_answer", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "create_time": 1795069983.584035, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 38, "sampled_through_sequence": 36, "retained_source": {"id": {"message_id": "msg_0a19968f2186c97b016afe98208b1c87d28dcab9e639a8933b", "turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "role": "assistant"}, "revision": "retained_01a1f282-3ff6-7c50-99c7-59b13d12f910", "complete": true}, "client_authored": false, "user_input_order": 15}} +{"timestamp": "2026-11-19T06:33:04.872Z", "ordinal": 89, "type": "event_msg", "payload": {"type": "task_complete", "root_turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", "last_agent_message": "Pre-Landing Review: 1 issue (1 critical, 0 informational)\n\n- Critical — `calc.py:4-5`: `avg(xs)` crashes on empty input (`ZeroDivisionError`) and rejects iterators/generators because it requires `len(xs)`. That makes the new API brittle for common callers and turns a simple helper into a runtime failure path.\n\nGate edits: none detected.", "started_at": 1795069963, "completed_at": 1795069984, "duration_ms": 21534, "time_to_first_token_ms": 1744}} diff --git a/test/fixtures/skill-contract/codex/exec-subagent.jsonl b/test/fixtures/skill-contract/codex/exec-subagent.jsonl new file mode 100644 index 000000000..bb1aff670 --- /dev/null +++ b/test/fixtures/skill-contract/codex/exec-subagent.jsonl @@ -0,0 +1,16 @@ +{"timestamp": "2026-11-19T06:23:32.393Z", "ordinal": 0, "type": "session_meta", "payload": {"account_scoped": true, "session_id": "01a1f279-4233-7603-8835-0297f9c2cfb7", "id": "01a1f279-83e0-7b63-89c1-316b620bcaf1", "parent_thread_id": "01a1f279-4233-7603-8835-0297f9c2cfb7", "timestamp": "2026-11-19T06:23:32.343Z", "cwd": "/home/dev/repo", "runtime_workspace_roots": ["/home/dev/repo"], "originator": "codex_exec", "cli_version": "0.170.0", "source": {"subagent": {"thread_spawn": {"parent_thread_id": "01a1f279-4233-7603-8835-0297f9c2cfb7", "depth": 1, "agent_path": null, "agent_nickname": "Hooke", "agent_role": null}}}, "thread_source": "subagent", "agent_nickname": "Hooke", "model_provider": "openai", "history_mode": "paginated", "multi_agent_version": "v1", "context_window": {"window_id": "01a1f279-83e1-76c3-852f-81bf321fa338"}}} +{"timestamp": "2026-11-19T06:23:32.393Z", "ordinal": 1, "type": "event_msg", "payload": {"type": "task_started", "turn_attribution": {"turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d", "turn_trigger": "exec", "parent_turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "initiating_agent_path": null, "root_turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b"}, "turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d", "root_turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "started_at": 1795069412, "model_context_window": 258400, "collaboration_mode_kind": "default"}} +{"timestamp": "2026-11-19T06:23:33.641Z", "ordinal": 2, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f279-8908-7db2-97e7-46960ce45168", "role": "developer", "content": [{"type": "input_text", "text": "\n## Skills\nA skill is a set of local instructions to follow that is stored in a `SKILL.md` file. Below is the list of skills that can be used. Each entry includes a name, description, and a short path that can be expanded into an absolute path using the skill roots table.\n### Skill roots\n- `r0` = `/home/dev/.codex/skills`\n- `r1` = `/home/dev/.codex/skills/.system`\n### Available skills\n- imagegen: Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output should be a bitmap asset rather than repo-native code or vector. Do not use when the task is better handled by editing existing SVG/vector/code-native assets, extend\n[... 2266 characters trimmed from this fixture ...]\nhen you review a diff before it lands: local changes, a branch or a PR. Use for: review my changes, look over my diff, review this pr. (gstack) (file: r0/gstack/review/SKILL.md)\n"}, {"type": "input_text", "text": "\nFilesystem sandboxing defines which files can be read or written. `sandbox_mode` is `danger-full-access`: No filesystem sandboxing - all commands are permitted. Network access is enabled.\nApproval policy is currently never. Do not provide the `sandbox_permissions` for any reason, commands will be rejected.\n"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d", "create_time": 1795069413.640856, "content_item_kinds": ["host_skills.instructions", "permissions.instructions"], "content_item_metadata": [{"provenance": {"type": "skills"}}, {"provenance": {"type": "harness", "hook": false}}]}}, "metadata": {"history_sequence": 1, "sampled_through_sequence": 0, "client_authored": false, "mcp_attribution": {"status": "none"}}} +{"timestamp": "2026-11-19T06:23:33.641Z", "ordinal": 3, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f279-8908-7db2-97e7-46a2f4830aa4", "role": "user", "content": [{"type": "input_text", "text": "\n /home/dev/repo\n bash\n 2026-11-19\n Etc/UTC\n /home/dev/repo\n"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d", "create_time": 1795069413.6408656, "content_item_kinds": ["environments.environment_context"], "content_item_metadata": [{"provenance": {"type": "harness", "hook": false}}]}}, "metadata": {"history_sequence": 2, "sampled_through_sequence": 0, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:33.643Z", "ordinal": 5, "type": "turn_context", "payload": {"turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d", "root_turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "disabled_plugin_ids": [], "cwd": "/home/dev/repo", "approval_policy": "never", "approvals_reviewer": "user", "permission_profile": {"type": "disabled"}, "model": "gpt-5.4-mini", "collaboration_mode": {"mode": "default", "settings": {"model": "gpt-5.4-mini", "reasoning_effort": "low", "developer_instructions": null}}, "multi_agent_version": "v1", "realtime_active": false, "effort": "low", "summary": "none", "sandbox_policy": {"type": "danger-full-access"}}} +{"timestamp": "2026-11-19T06:23:33.643Z", "ordinal": 6, "type": "event_msg", "payload": {"type": "thread_settings_applied", "thread_id": "01a1f279-83e0-7b63-89c1-316b620bcaf1", "thread_settings": {"model": "gpt-5.4-mini", "model_provider_id": "openai", "approval_policy": "never", "approvals_reviewer": "user", "requested_approvals_reviewer": "user", "permission_profile": {"type": "disabled"}, "cwd": "/home/dev/repo", "runtime_workspace_roots": ["/home/dev/repo"], "reasoning_effort": "low", "reasoning_summary": "auto", "collaboration_mode": {"mode": "default", "settings": {"model": "gpt-5.4-mini", "reasoning_effort": "low", "developer_instructions": null}}, "disabled_plugin_ids": []}}} +{"timestamp": "2026-11-19T06:23:33.649Z", "ordinal": 7, "type": "response_item", "payload": {"type": "message", "id": "msg_01a1f279-8910-7c40-840e-96ea8971bc7a", "role": "user", "content": [{"type": "input_text", "text": "Think like an attacker and a chaos engineer. Review the branch diff against main in /home/dev/repo, focusing on calc.py. Look for correctness, edge cases, and any production-impacting bugs. Return only concrete findings with file/line references and a one-line rationale each; if none, say none."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d", "create_time": 1795069413.648925, "content_item_kinds": ["user.text"], "content_item_metadata": [{"provenance": {"type": "user"}}]}}, "metadata": {"history_sequence": 3, "sampled_through_sequence": 0, "retained_source": {"id": {"message_id": "msg_01a1f279-8910-7c40-840e-96ea8971bc7a", "turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d", "role": "user"}, "revision": "retained_01a1f279-8910-7c40-840e-9700f81738a9", "complete": true}, "client_authored": false, "user_input_order": 0, "mcp_attribution": {"status": "none"}}} +{"timestamp": "2026-11-19T06:23:35.475Z", "ordinal": 10, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0b7a98a02e702e8c016afe95e6586087d2a5d7c67b33abbaca", "summary": [{"type": "summary_text", "text": "**Reviewing diff locally**\n\nI need to review a diff, and my plan is to use the local shell for that. It's practical to do it that way, so I'll open it up and see what changes have been made. I want to check for any significant adjustments that should be noted. I’ll take my time to ensure I'm understanding everything clearly! Let's get to it and see what we're working with!"}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d"}}, "metadata": {"history_sequence": 4, "sampled_through_sequence": 3, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:35.491Z", "ordinal": 12, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_0b7a98a02e702e8c016afe95e76a1487d2a3ab32fdbfaae81f", "role": "assistant", "content": [{"type": "output_text", "text": "I’ll inspect the branch diff and zero in on `calc.py`.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d", "create_time": 1795069413.9962, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 5, "sampled_through_sequence": 3, "retained_source": {"id": {"message_id": "msg_0b7a98a02e702e8c016afe95e76a1487d2a3ab32fdbfaae81f", "turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d", "role": "assistant"}, "revision": "retained_01a1f279-9043-7433-906e-a8467dfb7e02", "complete": true}, "client_authored": false, "user_input_order": 1}} +{"timestamp": "2026-11-19T06:23:35.571Z", "ordinal": 13, "type": "response_item", "payload": {"type": "function_call", "status": "completed", "id": "fc_0b7a98a02e702e8c016afe95e76e7c87d2a758c7a8fac7f49b", "name": "exec_command", "arguments": "{\"cmd\":\"git diff --stat main...HEAD && echo '---' && git diff main...HEAD -- calc.py\",\"workdir\":\"/home/dev/repo\",\"max_output_tokens\":12000}", "call_id": "call_BBtBtEHQW3UOfl1R5apZvwFk", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d", "create_time": 1795069413.9962}}, "metadata": {"history_sequence": 6, "sampled_through_sequence": 3, "client_authored": false, "user_input_order": 2}} +{"timestamp": "2026-11-19T06:23:35.671Z", "ordinal": 16, "type": "response_item", "payload": {"type": "function_call_output", "id": "fco_01a1f279-90f7-7652-86a4-681ab176fb48", "call_id": "call_BBtBtEHQW3UOfl1R5apZvwFk", "output": "Chunk ID: ec7e78\nWall time: 0.0000 seconds\nProcess exited with code 0\nOriginal token count: 60\nOutput:\n calc.py | 3 +++\n 1 file changed, 3 insertions(+)\n---\ndiff --git a/calc.py b/calc.py\nindex d10b0e8..b8481fd 100644\n--- a/calc.py\n+++ b/calc.py\n@@ -1,2 +1,5 @@\n def div(a, b):\n return a / b\n+\n+def avg(xs):\n+ return sum(xs) / len(xs)\n", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d", "create_time": 1795069415.6718917}}, "metadata": {"history_sequence": 7, "sampled_through_sequence": 3, "client_authored": false, "fallback_token_limit_override": 3000}} +{"timestamp": "2026-11-19T06:23:37.794Z", "ordinal": 19, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0b7a98a02e702e8c016afe95e82d9487d2a935ca0613f57f25", "summary": [{"type": "summary_text", "text": "**Assessing calculation issues**\n\nI need to assess the correctness of my code in calc.py, which only added the average function. I should definitely reference the specific lines since there’s likely a division by zero error when dealing with empty iterables. I also wonder if using len() on a generator could fail. This could impact production. I suspect that calculating the average on an empty list raises a ZeroDivisionError. If that's intended, it may be a bug. I'll need to inspect the file line numbers."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d"}}, "metadata": {"history_sequence": 8, "sampled_through_sequence": 7, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:37.811Z", "ordinal": 21, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_0b7a98a02e702e8c016afe95e9bb4c87d2a2ce683336fa4d63", "role": "assistant", "content": [{"type": "output_text", "text": "I found the change; now checking for edge cases in the new helper.", "annotations": [], "logprobs": []}], "phase": "commentary", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d", "create_time": 1795069415.862048, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 9, "sampled_through_sequence": 7, "retained_source": {"id": {"message_id": "msg_0b7a98a02e702e8c016afe95e9bb4c87d2a2ce683336fa4d63", "turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d", "role": "assistant"}, "revision": "retained_01a1f279-9953-79f3-8b82-edd88b50f76e", "complete": true}, "client_authored": false, "user_input_order": 3}} +{"timestamp": "2026-11-19T06:23:38.734Z", "ordinal": 23, "type": "response_item", "payload": {"type": "reasoning", "id": "rs_0b7a98a02e702e8c016afe95e9c04487d29cff60c7fdf47e3b", "summary": [{"type": "summary_text", "text": "**Evaluating the need for context**\n\nI’m thinking that maybe I don’t need more context; perhaps I just need to run some tests. But I should focus on reviewing the branch differences closely as that might provide me with sufficient information on its own. My findings should be concrete — I'll make sure to note down what I discover! I really want to get to the bottom of this efficiently."}], "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d"}}, "metadata": {"history_sequence": 10, "sampled_through_sequence": 7, "client_authored": false}} +{"timestamp": "2026-11-19T06:23:38.851Z", "ordinal": 25, "type": "response_item", "payload": {"type": "message", "status": "completed", "id": "msg_0b7a98a02e702e8c016afe95eaac5c87d28d81028605f8d43e", "role": "assistant", "content": [{"type": "output_text", "text": "- `calc.py:4` — `avg(xs)` crashes on empty input because `len(xs)` becomes `0`, so `sum(xs) / len(xs)` raises `ZeroDivisionError`.\n- `calc.py:4` — `avg(xs)` only works for sized containers; passing a generator or other iterable without `__len__` raises `TypeError` at `len(xs)`.", "annotations": [], "logprobs": []}], "phase": "final_answer", "internal_chat_message_metadata_passthrough": {"turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d", "create_time": 1795069415.862048, "content_item_kinds": ["unknown"]}}, "metadata": {"history_sequence": 11, "sampled_through_sequence": 7, "retained_source": {"id": {"message_id": "msg_0b7a98a02e702e8c016afe95eaac5c87d28d81028605f8d43e", "turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d", "role": "assistant"}, "revision": "retained_01a1f279-9d63-7bf2-b32c-54f6372015a5", "complete": true}, "client_authored": false, "user_input_order": 4}} +{"timestamp": "2026-11-19T06:23:38.861Z", "ordinal": 28, "type": "event_msg", "payload": {"type": "task_complete", "root_turn_id": "01a1f279-4621-7b00-8b3e-5e1af08c987b", "turn_id": "01a1f279-83f9-7fc2-8fbb-49fffef8ab6d", "last_agent_message": "- `calc.py:4` — `avg(xs)` crashes on empty input because `len(xs)` becomes `0`, so `sum(xs) / len(xs)` raises `ZeroDivisionError`.\n- `calc.py:4` — `avg(xs)` only works for sized containers; passing a generator or other iterable without `__len__` raises `TypeError` at `len(xs)`.", "started_at": 1795069412, "completed_at": 1795069418, "duration_ms": 6514, "time_to_first_token_ms": 2334}} diff --git a/test/fixtures/skill-contract/codex/stop-payloads.json b/test/fixtures/skill-contract/codex/stop-payloads.json new file mode 100644 index 000000000..eaf75fd44 --- /dev/null +++ b/test/fixtures/skill-contract/codex/stop-payloads.json @@ -0,0 +1,44 @@ +[ + { + "payload": { + "session_id": "01a1f281-eb07-7940-a3fd-e8cf129453b7", + "turn_id": "01a1f281-ec48-79c1-8d84-982d2138ba57", + "transcript_path": "/home/dev/.codex/sessions/2026/11/19/rollout-2026-11-19T06-32-43-01a1f281-eb07-7940-a3fd-e8cf129453b7.jsonl", + "cwd": "/home/dev/repo", + "hook_event_name": "Stop", + "model": "gpt-5.4-mini", + "permission_mode": "bypassPermissions", + "stop_hook_active": false, + "last_assistant_message": "Pre-Landing Review: 1 issue (1 critical, 0 informational)\n\n- Critical — `calc.py:4-5`: `avg(xs)` crashes on empty input (`ZeroDivisionError`) and rejects iterators/generators because it requires `len(xs)`. That makes the new API brittle for common callers and turns a simple helper into a runtime failure path.\n\nGate edits: none detected." + }, + "hook_stdout": "" + }, + { + "payload": { + "session_id": "01a1f282-b418-7040-bb98-0b3dffdc76fe", + "turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", + "transcript_path": "/home/dev/.codex/sessions/2026/11/19/rollout-2026-11-19T06-33-34-01a1f282-b418-7040-bb98-0b3dffdc76fe.jsonl", + "cwd": "/home/dev/repo", + "hook_event_name": "Stop", + "model": "gpt-5.4-mini", + "permission_mode": "bypassPermissions", + "stop_hook_active": false, + "last_assistant_message": "Pre-Landing Review: 1 issue (1 critical, 0 informational)\n\n- [critical] `calc.py:4` — `avg([])` raises `ZeroDivisionError` because `len(xs)` is `0`; this makes the new helper fail on empty input instead of handling or explicitly rejecting it.\n - Fix: add an empty-sequence check and raise a clearer `ValueError` (or define the expected empty-case behavior)." + }, + "hook_stdout": "{\"decision\":\"block\",\"reason\":\"SKILL_CONTRACT_UNMET gstack-review (contract v1): missing adversarial-pass, review-report. Fix: adversarial-pass: start the subagent pass matching /Think like an attacker and a chaos engineer/ with spawn_agent, then wait_agent for its result; review-report: fill Gate edits in the Pre-Landing Review with real values. If an item truly does not apply, run '/home/dev/.local/share/gstack/bin/gstack-skill-contract' waive --reason \\\"\\\" (this session only; counted as a miss for follow). This blocks once.\"}" + }, + { + "payload": { + "session_id": "01a1f282-b418-7040-bb98-0b3dffdc76fe", + "turn_id": "01a1f282-b458-79d2-b82f-07a4a0f25843", + "transcript_path": "/home/dev/.codex/sessions/2026/11/19/rollout-2026-11-19T06-33-34-01a1f282-b418-7040-bb98-0b3dffdc76fe.jsonl", + "cwd": "/home/dev/repo", + "hook_event_name": "Stop", + "model": "gpt-5.4-mini", + "permission_mode": "bypassPermissions", + "stop_hook_active": true, + "last_assistant_message": "Pre-Landing Review: 1 issue (1 critical, 0 informational)\n\n- [critical] `calc.py:4-5` — `avg([])` raises `ZeroDivisionError` because `len(xs)` can be `0`; this makes the new helper fail on empty input.\n - Fix: reject empty input up front with a clear `ValueError`, or define and implement the intended empty-sequence behavior.\n\nGate edits: none detected (0 listed, 0 read; patterns: simple arithmetic helper; unlisted idioms: none)" + }, + "hook_stdout": "" + } +] \ No newline at end of file diff --git a/test/helpers/free-fixtures-data.ts b/test/helpers/free-fixtures-data.ts index 7ae75364f..d7a662186 100644 --- a/test/helpers/free-fixtures-data.ts +++ b/test/helpers/free-fixtures-data.ts @@ -251,7 +251,7 @@ export const FREE_FIXTURES: Readonly> = { 'test/fixtures/ship-queue/gbrain-stamp-pair.json': ['test/helpers/ship-queue-fixture.ts', 'test/tree-receipt-gbrain-pair.test.ts'], 'test/fixtures/ship-triage/**': ['test/ship-triage-labels.test.ts'], 'test/fixtures/skill-bin-drift-allowlist.json': ['test/skill-bin-drift.test.ts'], - 'test/fixtures/skill-contract/**': ['test/skill-contract-stop-hook.test.ts', 'test/skill-contract.test.ts'], + 'test/fixtures/skill-contract/**': ['test/skill-contract-codex.test.ts', 'test/skill-contract-stop-hook.test.ts', 'test/skill-contract.test.ts'], 'test/fixtures/skill-evals/**': ['test/skill-eval-checks.test.ts', 'test/skill-eval-tasks.test.ts'], 'test/fixtures/skill-md-size-allowlist.json': ['test/skill-md-size-guard.test.ts'], 'test/fixtures/skill-route-bug-reports.json': ['test/skill-route.test.ts'], diff --git a/test/skill-contract-codex.test.ts b/test/skill-contract-codex.test.ts new file mode 100644 index 000000000..6cf58c0b2 --- /dev/null +++ b/test/skill-contract-codex.test.ts @@ -0,0 +1,297 @@ +/** + * The /review contract on Codex (GST-3173): lib/codex-rollout.ts reads Codex + * 0.170 rollouts, checkContract skips the specialists item there, and the Stop + * hook holds a Codex /review once. The fixtures are real Codex rollouts + * (test/fixtures/skill-contract/codex/README.md says how they were captured). + * Claude Code's behaviour is pinned by test/skill-contract.test.ts and + * test/skill-contract-stop-hook.test.ts; the checks here that touch Claude + * transcripts only prove the Codex branch leaves them alone. + */ +import { afterEach, beforeEach, describe, expect, test } from 'bun:test'; +import { spawnSync } from 'node:child_process'; +import * as fs from 'node:fs'; +import * as path from 'node:path'; +import codex from '../hosts/codex'; +import { BACKED_BY } from '../scripts/resolvers/contract-done-means'; +import { + CODEX_SKIPPED_KINDS, ITEM_KINDS, UnknownShape, checkContract, parseTranscript, skillLoads, transcriptContract, + type Contract, type Transcript, +} from '../lib/skill-contract'; +import { CONTRACT_HOOK, J1_TRANSCRIPT, ROOT, hookEnv, runHook, skillsDir, tmpDir } from './helpers/skill-contract-fixture'; + +const DIR = path.join(ROOT, 'test', 'fixtures', 'skill-contract', 'codex'); +const read = (name: string) => fs.readFileSync(path.join(DIR, name), 'utf8'); +const rollout = (name: string) => parseTranscript(read(name)); +const lines = (name: string) => read(name).trimEnd().split('\n'); +const STOPS = JSON.parse(read('stop-payloads.json')) as { payload: Record; hook_stdout: string }[]; +/** exec-read-blocked.jsonl as it stood at the first Stop: everything before the hook's message. */ +const AT_FIRST_STOP = lines('exec-read-blocked.jsonl').slice(0, lines('exec-read-blocked.jsonl').findIndex(l => l.includes(' { + const found = transcriptContract(t, 'gstack-review', {}); + if (!('contract' in found)) throw new Error(found.error); + return found.contract; +}; +const status = (t: Transcript, contract: Contract) => Object.fromEntries(checkContract(t, 'gstack-review', contract).items.map(i => [i.id, i.status])); + +describe('format: chosen by content', () => { + test('every fixture parses as a Codex rollout with its session_meta id', () => { + for (const name of fs.readdirSync(DIR).filter(n => n.endsWith('.jsonl'))) { + const t = rollout(name); + expect(t.format).toBe('codex'); + expect(t.sessionId).toBe(JSON.parse(lines(name)[0]).payload.id); + } + }); + + test('a Claude Code transcript parses exactly as before: no format or subagent key', () => { + const t = parseTranscript(`${J1_TRANSCRIPT.join('\n')}\n`); + expect(Object.keys(t).sort()).toEqual(['events', 'sessionId']); + expect(t.events.some(e => e.kind === 'load')).toBe(false); + }); + + test('the path does not decide: a rollout under ~/.claude/projects is still Codex, a transcript under ~/.codex/sessions still Claude', () => { + const work = tmpDir('gstack-codex-format-'); + try { + const claudeDir = path.join(work, '.claude', 'projects', 'p'); + const codexDir = path.join(work, '.codex', 'sessions', '2026', '11', '19'); + fs.mkdirSync(claudeDir, { recursive: true }); + fs.mkdirSync(codexDir, { recursive: true }); + fs.writeFileSync(path.join(claudeDir, 'x.jsonl'), read('exec-read-met.jsonl')); + fs.writeFileSync(path.join(codexDir, 'rollout-x.jsonl'), `${J1_TRANSCRIPT.join('\n')}\n`); + expect(parseTranscript(fs.readFileSync(path.join(claudeDir, 'x.jsonl'), 'utf8')).format).toBe('codex'); + expect(parseTranscript(fs.readFileSync(path.join(codexDir, 'rollout-x.jsonl'), 'utf8')).format).toBeUndefined(); + } finally { + fs.rmSync(work, { recursive: true, force: true }); + } + }); + + test('a rollout this reader does not know throws UnknownShape', () => { + const meta = lines('exec-read-met.jsonl')[0]; + expect(() => parseTranscript(`${meta}\n`)).toThrow(UnknownShape); + expect(() => parseTranscript(`${meta}\n${JSON.stringify({ type: 'response_item', payload: 'text' })}\n`)).toThrow(UnknownShape); + expect(() => parseTranscript(`${meta}\n${JSON.stringify({ type: 'response_item', payload: { type: 'message', role: 'user', content: 'hi' } })}\n`)).toThrow(UnknownShape); + }); +}); + +describe('loads: Codex reading or injecting a gstack-* SKILL.md', () => { + test('a shell read (cat) of the installed SKILL.md is a load', () => { + expect(skillLoads(rollout('exec-read-met.jsonl')).map(l => [l.skill, l.via])).toEqual([['gstack-review', 'read']]); + }); + + test('a injection (the TUI and app-server skill input) is a load', () => { + expect(skillLoads(rollout('app-server-injected-early-exit.jsonl')).map(l => [l.skill, l.via])).toEqual([['gstack-review', 'injected']]); + }); + + test('a $gstack-review typed into codex exec is plain text: no load', () => { + expect(skillLoads(rollout('exec-mention-not-loaded.jsonl'))).toEqual([]); + }); + + test('only a read program on a skills/gstack-*/SKILL.md path loads', () => { + const meta = lines('exec-read-met.jsonl')[0]; + const call = (cmd: string) => JSON.stringify({ type: 'response_item', payload: { type: 'function_call', name: 'exec_command', arguments: JSON.stringify({ cmd }), call_id: 'c1' } }); + const user = JSON.stringify({ type: 'response_item', payload: { type: 'message', role: 'user', content: [{ type: 'input_text', text: 'review this' }] } }); + const result = (output: string) => JSON.stringify({ type: 'response_item', payload: { type: 'function_call_output', call_id: 'c1', output } }); + const loads = (cmd: string, output?: string) => skillLoads(parseTranscript([meta, user, call(cmd), ...(output === undefined ? [] : [result(output)])].join('\n'))).map(l => l.skill); + expect(loads("sed -n '1,200p' \"$CODEX_HOME/skills/gstack-review/SKILL.md\"")).toEqual(['gstack-review']); + expect(loads('cat ~/.codex/skills/gstack-review/SKILL.md', 'Process exited with code 0\nOutput:\n---')).toEqual(['gstack-review']); + expect(loads('cat ~/.codex/skills/gstack-review/SKILL.md', 'Process exited with code 1\nOutput:\ncat: /home/u/.codex/skills/gstack-review/SKILL.md: No such file or directory')).toEqual([]); + expect(loads('cat ~/.codex/skills/gstack-review/SKILL.md && git diff missing-ref', "Process exited with code 128\nOutput:\n---\nname: gstack-review\nfatal: bad revision 'missing-ref'")).toEqual(['gstack-review']); + expect(loads('cd ~/.codex && cat skills/gstack-review/SKILL.md')).toEqual(['gstack-review']); + expect(loads('cat README.md && ls ~/.codex/skills/gstack-review/SKILL.md')).toEqual([]); + expect(loads('ls ~/.codex/skills/gstack-review/SKILL.md')).toEqual([]); + expect(loads('cat ~/src/gstack/review/SKILL.md')).toEqual([]); + expect(loads('cat ~/.codex/skills/review/SKILL.md')).toEqual([]); + }); +}); + +describe('chunked reads: reading the same SKILL.md again continues the run', () => { + const met = lines('exec-read-met.jsonl'); + const spawnAt = met.findIndex(l => l.includes('"function_call"') && l.includes('spawn_agent') && met.some(o => o.includes('function_call_output') && o.includes(JSON.parse(l).payload.call_id) && o.includes('agent_id'))); + const record = (payload: Record) => JSON.stringify({ type: 'response_item', payload }); + const reread = [ + record({ type: 'function_call', name: 'exec_command', arguments: JSON.stringify({ cmd: "sed -n '400,800p' ~/.codex/skills/gstack-review/SKILL.md" }), call_id: 'reread' }), + record({ type: 'function_call_output', call_id: 'reread', output: 'Process exited with code 0\nOutput:\n## Step 5' }), + ]; + const withAfterSpawn = (extra: string[]) => parseTranscript([...met.slice(0, spawnAt + 2), ...extra, ...met.slice(spawnAt + 2)].join('\n')); + + test('a second chunk read after the adversarial spawn is not a new load, so the run stays met', () => { + const t = withAfterSpawn(reread); + expect(skillLoads(t)).toHaveLength(1); + expect(checkContract(t, 'gstack-review', realReview(t)).items.every(i => i.status !== 'missing')).toBe(true); + }); + + test('a user prompt between the reads makes the second read a new load', () => { + const prompt = record({ type: 'message', role: 'user', content: [{ type: 'input_text', text: 'review it again' }] }); + expect(skillLoads(withAfterSpawn([prompt, ...reread]))).toHaveLength(2); + }); +}); + +describe('dispatch: a spawn_agent call that started an agent', () => { + test('a spawn_agent that failed is not a dispatch; the one that started is', () => { + const t = rollout('exec-read-failed-spawn.jsonl'); + const spawns = t.events.filter(e => e.kind === 'tool_use' && (e.name === 'Agent' || e.name === 'spawn_agent')) as { name: string; input: Record }[]; + expect(spawns.map(s => s.name)).toEqual(['spawn_agent', 'Agent']); + expect(String(spawns[1].input.prompt)).toContain('Think like an attacker and a chaos engineer'); + }); + + test('negative control: without the spawn that started, the adversarial pass is missing', () => { + const all = lines('exec-read-failed-spawn.jsonl'); + const callId = all.map(l => JSON.parse(l).payload).find(p => p?.type === 'function_call_output' && String(p.output).includes('agent_id')).call_id; + const t = parseTranscript(all.filter(l => !l.includes(callId)).join('\n')); + expect(status(t, realReview(t))['adversarial-pass']).toBe('missing'); + }); + + test('a spawn_agent with no output is not a dispatch', () => { + const all = lines('exec-read-failed-spawn.jsonl'); + const callId = all.map(l => JSON.parse(l).payload).find(p => p?.type === 'function_call_output' && String(p.output).includes('agent_id')).call_id; + const t = parseTranscript(all.filter(l => !(l.includes(callId) && l.includes('function_call_output'))).join('\n')); + expect(t.events.some(e => e.kind === 'tool_use' && e.name === 'Agent')).toBe(false); + expect(status(t, realReview(t))['adversarial-pass']).toBe('missing'); + }); + + test('call arguments that are not a JSON object throw UnknownShape, so the hook fails open', () => { + const meta = lines('exec-read-met.jsonl')[0]; + const user = JSON.stringify({ type: 'response_item', payload: { type: 'message', role: 'user', content: [{ type: 'input_text', text: 'review this' }] } }); + const spawn = JSON.stringify({ type: 'response_item', payload: { type: 'function_call', name: 'spawn_agent', arguments: '{"message": ', call_id: 's1' } }); + expect(() => parseTranscript([meta, user, spawn].join('\n'))).toThrow(UnknownShape); + }); +}); + +describe('turns: Codex harness messages are meta', () => { + test("the hook's reason, a subagent notification and the environment are meta; the user's request is the only prompt", () => { + const t = rollout('exec-read-blocked.jsonl'); + const prompts = t.events.filter(e => e.kind === 'prompt') as { text: string }[]; + expect(prompts.map(p => p.text)).toEqual([expect.stringContaining('do not start any subagents')]); + const metas = (t.events.filter(e => e.kind === 'meta') as { text: string }[]).map(m => m.text.split(/[>\s]/)[0]); + expect(metas).toEqual(expect.arrayContaining([' { + expect(rollout('exec-subagent.jsonl').subagent).toBe(true); + expect(rollout('exec-read-met.jsonl').subagent).toBeUndefined(); + }); +}); + +describe('checkContract on Codex with the real /review contract', () => { + test('the contract comes from gstack\'s own review/SKILL.md, all three items', () => { + const t = rollout('exec-read-met.jsonl'); + expect(transcriptContract(t, 'gstack-review', {})).toMatchObject({ file: path.join(ROOT, 'review', 'SKILL.md') }); + expect(realReview(t).items.map(i => i.kind)).toEqual(['selected_specialists_dispatched', 'agent_dispatch', 'report_labels']); + }); + + test('specialists-dispatched is skipped on Codex and only there', () => { + const t = rollout('exec-read-met.jsonl'); + expect(status(t, realReview(t))).toEqual({ 'adversarial-pass': 'met', 'review-report': 'met' }); + const asClaude: Transcript = { events: t.events, sessionId: t.sessionId }; + expect(status(asClaude, realReview(t))['specialists-dispatched']).toBe('missing'); + }); + + test('each real run gets the verdict the run earned', () => { + const at = (text: string) => parseTranscript(text); + const blocked = at(AT_FIRST_STOP.join('\n')); + expect(status(blocked, realReview(blocked))).toEqual({ 'adversarial-pass': 'missing', 'review-report': 'missing' }); + const fixed = rollout('exec-read-blocked.jsonl'); + expect(checkContract(fixed, 'gstack-review', realReview(fixed)).met).toBe(true); + const failedSpawn = rollout('exec-read-failed-spawn.jsonl'); + expect(status(failedSpawn, realReview(failedSpawn))).toEqual({ 'adversarial-pass': 'met', 'review-report': 'missing' }); + const early = rollout('app-server-injected-early-exit.jsonl'); + expect(checkContract(early, 'gstack-review', realReview(early)).met).toBe(true); + }); + + test('the Codex wording stays in its branch: the same events as a Claude transcript get the Claude text', () => { + const t = parseTranscript(AT_FIRST_STOP.join('\n')); + const item = (tr: Transcript) => checkContract(tr, 'gstack-review', realReview(t)).items.find(i => i.id === 'adversarial-pass'); + expect(item(t)).toMatchObject({ + detail: 'no spawn_agent call matches /Think like an attacker and a chaos engineer/', + fix: 'start the subagent pass matching /Think like an attacker and a chaos engineer/ with spawn_agent, then wait_agent for its result', + }); + expect(item({ events: t.events, sessionId: t.sessionId })).toMatchObject({ + detail: 'no Agent dispatch matches /Think like an attacker and a chaos engineer/', + fix: 'dispatch the Agent pass matching /Think like an attacker and a chaos engineer/', + }); + }); + + test('CODEX_SKIPPED_KINDS is exactly the kinds whose resolver Codex suppresses', () => { + const suppressed = new Set(codex.suppressedResolvers ?? []); + const expected = ITEM_KINDS.filter(k => { const b = BACKED_BY[k]; return !!b && suppressed.has(b.resolver); }); + expect([...CODEX_SKIPPED_KINDS]).toEqual(expected); + }); +}); + +describe('the Stop hook on Codex', () => { + let state = '', work = '', skills = ''; + beforeEach(() => { + state = tmpDir('gstack-codex-state-'); + work = tmpDir('gstack-codex-work-'); + skills = skillsDir(['review']); + }); + afterEach(() => { + for (const d of [state, work, skills]) fs.rmSync(d, { recursive: true, force: true }); + }); + + /** One of Codex's real Stop payloads, pointed at a copy of the rollout. */ + const stop = (n: number, rolloutLines: string[], env: Record = {}, extra: Record = {}) => { + const file = path.join(work, 'rollout.jsonl'); + fs.writeFileSync(file, `${rolloutLines.join('\n')}\n`); + const payload = { ...STOPS[n].payload, transcript_path: file, ...extra }; + return runHook(CONTRACT_HOOK, JSON.stringify(payload), hookEnv(state, skills, { GSTACK_SKILL_CONTRACTS: 'on', CLAUDE_CODE_ENTRYPOINT: '', ...env })); + }; + const record = () => JSON.parse(fs.readFileSync(path.join(state, 'skill-contracts', `${STOPS[1].payload.session_id}.json`), 'utf8')); + + test('blocks once with the Codex reason, then records met_after_block', () => { + const first = stop(1, AT_FIRST_STOP); + expect(first.code).toBe(0); + expect(first.stderr).toBe(''); + const out = JSON.parse(first.stdout); + expect(Object.keys(out).sort()).toEqual(['decision', 'reason']); + expect(out.decision).toBe('block'); + expect(out.reason).toBe(read('../block-message-codex.txt').trimEnd().replace('{bin}', BIN)); + expect(Object.values(record().runs)).toEqual([expect.objectContaining({ skill: 'gstack-review', outcome: 'blocked', missing: ['adversarial', 'report'] })]); + const second = stop(2, lines('exec-read-blocked.jsonl')); + expect(second.stdout).toBe(''); + expect(second.stderr).toBe(''); + expect(Object.values(record().runs)).toEqual([expect.objectContaining({ outcome: 'met_after_block', missing: [] })]); + }); + + test('stop_hook_active on the first stop it sees: never blocks', () => { + const r = stop(2, AT_FIRST_STOP, {}, { last_assistant_message: STOPS[1].payload.last_assistant_message }); + expect(r.stdout).toBe(''); + }); + + test('the real met run: allowed and recorded met', () => { + const r = stop(0, lines('exec-read-met.jsonl')); + expect(r.stdout).toBe(''); + const rec = JSON.parse(fs.readFileSync(path.join(state, 'skill-contracts', `${STOPS[0].payload.session_id}.json`), 'utf8')); + expect(Object.values(rec.runs)).toEqual([expect.objectContaining({ outcome: 'met' })]); + }); + + test('an unknown rollout shape fails open and bumps the same canary as on Claude Code', () => { + const meta = lines('exec-read-met.jsonl')[0]; + const r = stop(1, [meta, JSON.stringify({ type: 'response_item', payload: { type: 'message', role: 'user', content: 'x' } })]); + expect(r.code).toBe(0); + expect(r.stdout).toBe(''); + expect(r.stderr).toMatch(/^gstack-skill-contract: SKILL_CONTRACT_STATE_ERROR .+: unknown transcript shape: line 2: message content is not a list \(canary 1\); stop allowed/); + expect(JSON.parse(fs.readFileSync(path.join(state, 'hooks', 'skill-contract.canary.json'), 'utf8')).count).toBe(1); + }); + + test('a Codex subagent rollout is never checked', () => { + const r = stop(1, lines('exec-subagent.jsonl'), {}, { last_assistant_message: undefined }); + expect(r.stdout).toBe(''); + expect(fs.readFileSync(path.join(state, 'hooks', 'skill-contract.log'), 'utf8')).toContain('event=codex-subagent'); + }); + + test('skill_contracts off turns it off on Codex too', () => { + expect(stop(1, AT_FIRST_STOP, { GSTACK_SKILL_CONTRACTS: 'off' }).stdout).toBe(''); + expect(fs.existsSync(path.join(state, 'skill-contracts'))).toBe(false); + }); + + test('gstack-skill-contract check reads a Codex rollout against gstack\'s own contract', () => { + const check = (name: string) => spawnSync(BIN, ['check', '--transcript', path.join(DIR, name), '--skill', 'gstack-review'], { env: hookEnv(state, skills, { GSTACK_INSTALLED_SKILLS_DIR: '', HOME: work }), encoding: 'utf8', timeout: 20_000 }); + const met = check('exec-read-met.jsonl'); + expect(met.status).toBe(0); + expect(met.stdout).toStartWith('SKILL_CONTRACT_MET gstack-review'); + const unmet = check('exec-read-failed-spawn.jsonl'); + expect(unmet.status).toBe(1); + expect(unmet.stdout).toContain('missing review-report'); + }); +});