harness-everything 0.53.0 → 0.54.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/AGENTS.md +3 -1
  4. package/CHANGELOG.md +26 -0
  5. package/bin/cli.js +1 -0
  6. package/ci/action-gate.test.js +1 -1
  7. package/ci/invariant-routing.test.js +22 -3
  8. package/ci/mechanism-2al-codex-hooks-compat.test.js +56 -2
  9. package/ci/mechanism-2at-fable-execution-phases.test.js +38 -0
  10. package/ci/mechanism-349-ci-change-scope.test.js +78 -57
  11. package/ci/mechanism-397-cycle-import.test.js +18 -3
  12. package/ci/mechanism-check-packet-write-set.test.js +232 -0
  13. package/ci/mechanism-codex-hook-results.test.js +145 -0
  14. package/ci/mechanism-codex-prompt-pass-through.test.js +8 -4
  15. package/ci/mechanism-error-handling-map.test.js +219 -0
  16. package/ci/mechanism-report-writer.test.js +335 -0
  17. package/ci/openai-plugin-runtime.test.js +2 -1
  18. package/ci/prompt-contract-regressions.test.js +6 -2
  19. package/ci/router-workflow-plan.test.js +50 -7
  20. package/docs/architecture.md +4 -3
  21. package/docs/error-handling/README.md +250 -0
  22. package/docs/error-handling/actions/c1-action-map.md +89 -0
  23. package/docs/error-handling/actions/c2-action-map.md +22 -0
  24. package/docs/error-handling/actions/c3-action-map.md +26 -0
  25. package/docs/error-handling/actions/c5-action-map.md +31 -0
  26. package/docs/error-handling/actions/c6-action-map.md +37 -0
  27. package/docs/error-handling/actions/c7-action-map.md +18 -0
  28. package/docs/error-handling/actions/e0002-action-map.md +101 -0
  29. package/docs/error-handling/activity.puml +84 -0
  30. package/docs/error-handling/details/c1-authority-conformance.md +93 -0
  31. package/docs/error-handling/details/c2-test-root-containment.md +35 -0
  32. package/docs/error-handling/details/c3-mode-ownership.md +50 -0
  33. package/docs/error-handling/details/c5-host-replay-contract.md +40 -0
  34. package/docs/error-handling/details/c6-packet-briefing.md +65 -0
  35. package/docs/error-handling/details/c7-write-set-check.md +54 -0
  36. package/docs/error-handling/details/e0002-capture-evidence.md +93 -0
  37. package/docs/error-handling/details/e0002-report-writer.md +116 -0
  38. package/docs/error-handling/nodes.yaml +44 -0
  39. package/docs/error-handling/registry.md +59 -0
  40. package/docs/error-handling/templates/packet-briefing.md +45 -0
  41. package/docs/platform-capabilities.md +20 -1
  42. package/fable-mode/SKILL.md +5 -5
  43. package/fable-mode/execution-guardrails/SKILL.md +1 -1
  44. package/fable-mode/fable-haiku/SKILL.md +1 -1
  45. package/fable-mode/fable-opus/SKILL.md +1 -1
  46. package/fable-mode/fable-sonnet/SKILL.md +1 -1
  47. package/fable-mode/references/execution-phases.md +26 -4
  48. package/hooks/scripts/action-gate.js +5 -0
  49. package/hooks/scripts/codex-action-gate-post.js +3 -12
  50. package/hooks/scripts/codex-user-prompt.js +2 -3
  51. package/hooks/scripts/contract-test.js +17 -7
  52. package/hooks/scripts/lib/codex-tool-outcome.js +28 -0
  53. package/hooks/scripts/rule-of-3-tracker.js +11 -4
  54. package/hooks/scripts/state-persist.js +15 -9
  55. package/hooks/scripts/subagent-scope-guard.js +32 -25
  56. package/hooks/scripts/subagent-start.js +1 -1
  57. package/hooks/scripts/subagent-stop.js +14 -3
  58. package/opencode-plugin/plugin.json +1 -1
  59. package/package.json +2 -1
  60. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  61. package/plugins/harness-everything/hooks/hooks.json +6 -6
  62. package/plugins/harness-everything/hooks/scripts/action-gate.js +5 -0
  63. package/plugins/harness-everything/hooks/scripts/codex-action-gate-post.js +3 -12
  64. package/plugins/harness-everything/hooks/scripts/codex-user-prompt.js +2 -3
  65. package/plugins/harness-everything/hooks/scripts/contract-test.js +17 -7
  66. package/plugins/harness-everything/hooks/scripts/lib/codex-tool-outcome.js +28 -0
  67. package/plugins/harness-everything/hooks/scripts/rule-of-3-tracker.js +11 -4
  68. package/plugins/harness-everything/hooks/scripts/state-persist.js +15 -9
  69. package/plugins/harness-everything/hooks/scripts/subagent-scope-guard.js +32 -25
  70. package/plugins/harness-everything/hooks/scripts/subagent-start.js +1 -1
  71. package/plugins/harness-everything/hooks/scripts/subagent-stop.js +14 -3
  72. package/plugins/harness-everything/plugin.json +1 -1
  73. package/plugins/harness-everything/skills/fable-mode/SKILL.md +5 -5
  74. package/plugins/harness-everything/skills/fable-mode/execution-guardrails/SKILL.md +1 -1
  75. package/plugins/harness-everything/skills/fable-mode/fable-haiku/SKILL.md +1 -1
  76. package/plugins/harness-everything/skills/fable-mode/fable-opus/SKILL.md +1 -1
  77. package/plugins/harness-everything/skills/fable-mode/fable-sonnet/SKILL.md +1 -1
  78. package/plugins/harness-everything/skills/fable-mode/references/execution-phases.md +26 -4
  79. package/sbom.cdx.json +7 -7
  80. package/scripts/check-packet-write-set.js +155 -0
  81. package/scripts/codex-hooks-compat.js +46 -5
  82. package/scripts/error-handling-map.js +288 -0
  83. package/scripts/report-writer.js +261 -0
@@ -0,0 +1,116 @@
1
+ # E-0002 Treat — Level 3 report-writer contract and test cases
2
+
3
+ > **Proposed design / Level 3 supporting contract, NOT an implemented CLI.** Companion to the [E-0002 Level 2 Action Map](../actions/e0002-action-map.md) and [Level 1](../README.md) in [#437](https://github.com/dyphn1/Harness-everything/issues/437) and the Error Handling subtree [#402](https://github.com/dyphn1/Harness-everything/issues/402). This specifies **what the agent should do next time** and **which mechanical operation should prevent a repeat**. The proposed commands below do not exist yet; this document does not change production hooks, report rules or ledger state.
4
+
5
+ ## Problem to prevent
6
+
7
+ **E-0002** (`report-protocol`) recurs when a report lacks its required **raw, column-zero, terminal** `STATUS: DONE` or `STATUS: BLOCKED: <reason>` line, or when a harness-label appears after it. Some failures happen in `codex exec -o` outputs where the report is also the final turn text. Previous instructions and reminders were not enough: the next agent can make the same mistake again.
8
+
9
+ **Treatment direction (proposal):** stop using free-form report editing for the terminal protocol. The **agent supplies report content and an evidence-grounded status**, while one **scoped CLI/script writes and verifies the final report file**. Preserve free-form content authoring; restrict only the structured output operation. Do not add a global document governor, second Error Ledger, automatic report generation for unrelated tasks, or a count-driven lock.
10
+
11
+ **Action ownership:** A Capture records facts; B Triage and C Identify establish the case; D Decide chooses treatment. **E Treat defines/applies the mechanical report-writing method**; F Deliver gives the agent a concise instruction and the available CLI; G Accept checks its result. This is an **E-0002-specific Action detail**, not a second Level 1 flow or a claim that all classes have the same treatment.
12
+
13
+ ## Level 3 · Script-mediated operation (supporting the Level 2 block)
14
+
15
+ ```mermaid
16
+ flowchart TD
17
+ INPUT["D · Decide: valid selected disposition"] --> NEED{"Report-writing operation required?"}
18
+ NEED -->|No| OTHER["Perform only the selected applicable operation<br/>no automatic report requirement"]
19
+ NEED -->|Yes| AUTHOR["Agent supplies true task outcome and report body<br/>DONE / BLOCKED with reason"]
20
+ AUTHOR --> SOURCE{"Source of content?"}
21
+ SOURCE -->|"Ordinary body file"| STAGE["Provide body file to script"]
22
+ SOURCE -->|"codex exec -o"| RAW["Host -o writes raw output to staging input<br/>never finalized as the report directly"]
23
+ RAW --> EXTRACT["Script applies specified host-aware<br/>extraction/validation of raw output"]
24
+ EXTRACT --> STAGE
25
+ STAGE --> WRITE["Script writes terminal STATUS atomically<br/>then reads and checks finished artifact"]
26
+ WRITE --> RC{"Exit code 0?"}
27
+ RC -->|No| ERR["Return code + unmet condition;<br/>agent corrects inside Treat or records unresolved"]
28
+ ERR -->|"correctable"| AUTHOR
29
+ ERR -->|"not satisfied"| F
30
+ RC -->|Yes| F["F · Deliver actual result / usable guidance"]
31
+ OTHER --> F
32
+ F --> G["G · Accept against applicable contract<br/>and separate task evidence"]
33
+ ```
34
+
35
+ The E-0002 report script is **proposed, not deployed**. The Agent determines outcome; a mechanical script owns report assembly, validation and useful errors. The response block may choose a fitting operation without creating a new Level 1 branch. A failed script result does **not** bypass F/G or count as a successful report; unresolved evidence is delivered and the occurrence remains open.
36
+
37
+ ## Agent-facing procedure — proposed operational contract
38
+
39
+ For a step **explicitly required to produce a report**:
40
+
41
+ 1. **Perform the work and collect evidence.** The agent must decide the true task/packet status based on observed results. `DONE` is not inferred by the CLI from a successful invocation; `BLOCKED` requires an actual reason. A completed RED experiment is not automatically product GREEN.
42
+ 2. **Prepare only the free-form body** in a staging file. Do not add a terminal STATUS line or a harness-label to that body. If the host's `-o` captures the turn's final text, treat it as **script input / raw staging output**, not the finished report.
43
+ 3. **Call the report writer** with the body path, final output path, and explicit status; the writer adds exactly one terminal STATUS line and writes the complete report atomically.
44
+ 4. **Check the written file**, not merely the CLI stdout, and retain the result as evidence. Do not append to the finalized report; to revise, change the body and call the writer again.
45
+ 5. **Return the report reference and verified result** to the caller. A separate final turn keeps its own applicable host label contract. For any shared raw `-o` output, the **script** must apply an explicit host-aware extraction contract before writing the final report; return nonzero with raw evidence if it cannot do so. Do not silently strip arbitrary metadata or declare a contract exception deployed.
46
+
47
+ ### Proposed command interface — design examples, NOT currently executable
48
+
49
+ ```bash
50
+ # Positive result: content is provided by the agent; STATUS is written by the tool
51
+ harness report write --body-file work/report-body.md --output reports/review.md --status DONE
52
+ harness report check --file reports/review.md
53
+
54
+ # Blocked result: same writer; explicit failure reason is required
55
+ harness report write --body-file work/report-body.md --output reports/review.md --status BLOCKED --reason "required verification unavailable"
56
+ harness report check --file reports/review.md
57
+ ```
58
+
59
+ These are **candidate CLI verbs**, not a mandate to create a global `harness` binary. A small repository-local Node.js script with equivalent `write` / `check` operations is sufficient for the first vertical slice. The agent-facing instruction should reference the **actual installed command and version**, not copy these placeholders as if working already.
60
+
61
+ ### Minimal writer and checker contract
62
+
63
+ | Responsibility | Expected behavior |
64
+ | --- | --- |
65
+ | `write` input | Existing body file, designated report output path, explicit `DONE` / `BLOCKED`, mandatory non-empty reason for `BLOCKED` |
66
+ | `write` output | Preserve body content, add a single newline-separated terminal control line at **column zero**, write atomically, fail without corrupting the previous target |
67
+ | Structural validation | On the finished output, check exactly one terminal protocol line, nothing after it (including hidden label), and read-back matches what was written |
68
+ | Containing structured fields | Reject conflicting column-zero terminal STATUS lines and harness-label metadata in the submitted body; make the conflict explicit rather than silently discarding unknown content |
69
+ | Artifact roles | `codex exec -o` writes raw output as **script input**; the script converts and verifies the designated final report according to a host-aware contract. If ambiguous, return nonzero; no hidden manual rewrite |
70
+ | Failure outcome | Nonzero exit + actionable diagnostics; Agent may revise within Treat or deliver outstanding evidence via F/G; no automatic `DONE`, preserve prior target and raw source |
71
+ | Scope | Operate on explicitly designated report output only; do not rewrite unrelated files, judge semantic success, touch the Ledger, or automatically change permissions |
72
+ | Revision | Re-run `write` using the edited body + true status; never mutate the terminal report with ordinary append commands |
73
+
74
+ **Design constraint:** `-o` must be handled as script-mediated output. Parsing host metadata is a deterministic responsibility of the proposed script under a defined contract. If the script cannot distinguish required protocol from host-owned label safely, **return nonzero** with the original raw output and let the Agent handle that result; do not imply an unimplemented exception has shipped.
75
+
76
+ ## Interaction with other Actions and existing facilities
77
+
78
+ ```mermaid
79
+ flowchart LR
80
+ A["A–C · ASSESS<br/>observed/identified error"] --> D["D · Decide<br/>selected, validated disposition"]
81
+ D --> E["E · Treat<br/>agent uses script and return codes"]
82
+ E --> F["F · Deliver<br/>selected operation + result or failure"]
83
+ F --> G["G · Accept<br/>mechanical check + substantive evidence"]
84
+ F -. "reusable capability, not a flow edge" .-> HOOK["Later relevant Hook / Skill disclosure"]
85
+ ```
86
+
87
+ The future Hook/Skill reference is **not** a G feedback/recurrence edge, nor does F make future tasks part of this same Error Occurrence. A new recurrence starts as a **new Capture**; a correction after nonzero exit remains within the current local Action block when permitted.
88
+
89
+ - **#359:** existing E-0002 Ledger remains class/history authority; do not create a second database.
90
+ - **#394 / ROUTE-001:** Hook provides the **available command only when relevant**; it does not enforce task success or select the disposition. A retired lesson reminder does not remove still-needed operational instructions.
91
+ - **#437:** scoped CLI/script is a proposed deterministic validator, **not** a mandatory global document controller. Validation failures are returned for Agent handling, not converted to hidden branching rules.
92
+ - **Decide/Accept:** when a machine-checkable condition or approval is not met, the script returns nonzero with the unmet requirement. The Agent can revise appropriately or preserve unresolved status. Owner authorization cannot be fabricated by a script, and a zero script exit code never proves substantive task correctness.
93
+
94
+ ## Proposed acceptance before implementation
95
+
96
+ | Test case | Expected observable result |
97
+ | --- | --- |
98
+ | Valid body + DONE | Final file ends in exactly `STATUS: DONE`; CLI `check` passes |
99
+ | Valid body + BLOCKED + reason | Final file ends in `STATUS: BLOCKED: <reason>`; check passes |
100
+ | BLOCKED without reason | Write rejected; existing report left untouched |
101
+ | Body contains conflicting terminal STATUS or harness-label | Write rejected with useful explanation, no silent normalization |
102
+ | Agent revises body after earlier report | A new `write` replaces the report atomically; one terminal STATUS remains |
103
+ | `codex exec -o` emits trailing harness-label | Raw `-o` is routed **through the script** to produce/check the final report; script returns nonzero on unsafe/ambiguous transformation |
104
+ | Tool unavailable, bad path or read-back fails | Return nonzero with reason; Agent handles correction or delivers UNVERIFIED/unresolved result via F/G; raw evidence retained |
105
+ | Report not required | No invocation, no forced report |
106
+ | Writer produces compliant format but underlying result is wrong | Structural PASS only; review/behavior acceptance stays separate |
107
+
108
+ **What to measure:** E-0002 recurrence in later **real report-writing tasks**, whether the agent actually invoked the designated writer, structural violations after invocation, and elapsed/tool/review cost relative to hand-writing. Do not declare E-0002 rooted out merely because a diagram or a one-off check exists.
109
+
110
+ ## Owner discussion items
111
+
112
+ 1. Should the first implementation be a small Node.js `report write/check` script under the existing repository, rather than a new global CLI? **Recommended: yes.**
113
+ 2. For `codex exec -o`, route raw output to a **script**, and let the script generate/check the final report. No manual coordinator rewrite or output-contract exception is assumed.
114
+ 3. Define the **script's host-aware input/output and extraction contract** for shared `-o` artifacts; ambiguous input returns nonzero, not guessed normalization.
115
+
116
+ This design leaves A Capture focused on facts and E Treat on the executable operation: the next agent receives a repeatable action, **validated return codes**, and a way to handle a failed condition, not merely an explanation of the last mistake.
@@ -0,0 +1,44 @@
1
+ # Canonical Action identity source for the Error Handling map (#437 concept, #402 implementation).
2
+ # A-G are drawing-local aliases, NOT identity or ordered numbering.
3
+ # IDs use creation category/date/UUIDv4 and never change. Names can change independently.
4
+ # status: proposed | accepted | retired.
5
+ # links: Action-to-Action control flow of View 1 in README.md, where the path between the two
6
+ # Actions passes only through non-Action nodes (decisions, outcomes). Checked against the diagram.
7
+ schema: concept-v0
8
+ scope: error-handling
9
+ actions:
10
+ A:
11
+ identifier: ERR-20261112-a82f647f-c0b1-4c6c-b90b-fb2221fe66bd
12
+ name: Capture
13
+ status: proposed
14
+ B:
15
+ identifier: ERR-20261112-da72e7fa-a37c-48ab-81b9-a678673a7324
16
+ name: Triage
17
+ status: proposed
18
+ C:
19
+ identifier: ERR-20261112-ffbb1b17-edb3-4adb-92ff-df76ad8f101c
20
+ name: Identify
21
+ status: proposed
22
+ D:
23
+ identifier: ERR-20261112-cd6a0fd5-d354-4bcb-8d34-71fcc985e5e4
24
+ name: Decide disposition
25
+ status: proposed
26
+ E:
27
+ identifier: ERR-20261112-5349acf0-f23f-43dc-9a7b-c0ae49dbcfc9
28
+ name: Treat
29
+ status: proposed
30
+ F:
31
+ identifier: ERR-20261112-a1617b0f-e5a7-4d3d-8926-40cda9953b6a
32
+ name: Deliver relevant context
33
+ status: proposed
34
+ G:
35
+ identifier: ERR-20261112-5f7496e6-5e1a-4628-b818-5292dd011580
36
+ name: Accept and retire
37
+ status: proposed
38
+ links:
39
+ - { from: A, to: B }
40
+ - { from: B, to: C }
41
+ - { from: C, to: D }
42
+ - { from: D, to: E }
43
+ - { from: E, to: F }
44
+ - { from: F, to: G }
@@ -0,0 +1,59 @@
1
+ # Error Handling — lightweight layer registry (discussion prototype)
2
+
3
+ > **P2-2 decision for #437:** use a small registry that maps existing nodes, documents, and layer references **table to table**. This is a document lookup, not a workflow engine or a second graph. No runtime loader, CLI, enforcement, schema migration, or generated document pipeline is introduced here.
4
+ >
5
+ > **P2-1 intentionally unchanged:** whether agents confuse View and Level is **not an established defect**. The owner will validate it experimentally. Do not preemptively relabel or rewrite the previously tested Level 1 diagrams to address an unproven issue.
6
+
7
+ ## Identity source — reuse the existing Action table
8
+
9
+ The [Action identity registry](./nodes.yaml) is the only proposed source for the seven existing Action identities. Their UUIDs and names are **not copied into this file**, so edits to Action identity do not require changing two registries. A–G are drawing-local aliases, never global identifiers.
10
+
11
+ ## Table A — document registry (where to look)
12
+
13
+ | Local reference | Layer / role | Document | Purpose |
14
+ | --- | --- | --- | --- |
15
+ | `EH-overview` | Level 1 · process / three Views | [README.md](./README.md) | The canonical error-occurrence lifecycle, branches, guards and Action relationships |
16
+ | `EH-activity-source` | Level 1 · diagram representation | [activity.puml](./activity.puml) | UML activity representation of the **same** Level 1 route; not an independent controller |
17
+ | `E0002-actions` | Level 2 · context-specific behavior blocks | [actions/e0002-action-map.md](./actions/e0002-action-map.md) | E-0002 lens over ASSESS / RESPOND; what the Agent should do |
18
+ | `E0002-capture` | Level 3 · evidence reference | [details/e0002-capture-evidence.md](./details/e0002-capture-evidence.md) | Source and artifact preservation details, read only if relevant |
19
+ | `E0002-writer` | Level 3 · Script/CLI reference | [details/e0002-report-writer.md](./details/e0002-report-writer.md) | `-o` handling, input/output, return codes and mechanical checks; shipped as `scripts/report-writer.js` (`npm run report`, #462) |
20
+ | `E0002-ledger` | Existing external source · error history | [E-0002 ledger](../../.agents/harness-everything/errors/E-0002-report-missing-terminal-status.md) | Existing class/signature and history, **not** a new Level 3 state store |
21
+ | `C1-actions` | Level 2 · C1 split decision | [actions/c1-action-map.md](./actions/c1-action-map.md) | One authority per named decision; consumer inventory |
22
+ | `C1-detail` | Level 3 · C1 conformance design | [details/c1-authority-conformance.md](./details/c1-authority-conformance.md) | Conformance-test design; mechanism stays a follow-up until a target is pinned |
23
+ | `C2-actions` | Level 2 · C2 test oracle | [actions/c2-action-map.md](./actions/c2-action-map.md) | Test-root containment on Unix and Windows |
24
+ | `C2-detail` | Level 3 · C2 path predicate | [details/c2-test-root-containment.md](./details/c2-test-root-containment.md) | Predicate and matrix in `ci/mechanism-397-cycle-import.test.js` |
25
+ | `C3-actions` | Level 2 · C3 machine state | [actions/c3-action-map.md](./actions/c3-action-map.md) | Routing tests own their System One mode |
26
+ | `C3-detail` | Level 3 · C3 mode ownership | [details/c3-mode-ownership.md](./details/c3-mode-ownership.md) | Env builder in the routing fixtures (#449) |
27
+ | `C5-actions` | Level 2 · C5 host protocol | [actions/c5-action-map.md](./actions/c5-action-map.md) | Pin one host protocol at its real boundary |
28
+ | `C5-detail` | Level 3 · C5 replay contract | [details/c5-host-replay-contract.md](./details/c5-host-replay-contract.md) | Replay contract and the missing retained payload |
29
+ | `C6-actions` | Level 2 · C6 briefing | [actions/c6-action-map.md](./actions/c6-action-map.md) | A packet carries its own authoritative values |
30
+ | `C6-detail` | Level 3 · C6 briefing walkthrough | [details/c6-packet-briefing.md](./details/c6-packet-briefing.md) | Walkthroughs and the report-writer dependency |
31
+ | `C6-template` | Template · packet briefing | [templates/packet-briefing.md](./templates/packet-briefing.md) | Copy per packet; every field filled or `N/A: <reason>` |
32
+ | `C7-actions` | Level 2 · C7 write-set | [actions/c7-action-map.md](./actions/c7-action-map.md) | Did the slice stay inside its write-set |
33
+ | `C7-detail` | Level 3 · C7 checker | [details/c7-write-set-check.md](./details/c7-write-set-check.md) | `scripts/check-packet-write-set.js`, run by the coordinator before accepting a slice |
34
+
35
+ `Local reference` values are **table-local lookup keys only**, not new stable Action IDs, graph node identities, persistent state, or workflow instructions.
36
+
37
+ ## Table B — relationship registry (when to follow a reference)
38
+
39
+ | From | To | Relation / relevance | Expected reading behavior |
40
+ | --- | --- | --- | --- |
41
+ | `EH-overview` | `EH-activity-source` | Same Level 1 representation | Open when UML source/notation is needed; not a new Level |
42
+ | `EH-overview` | `E0002-actions` | Context-specific expansion: **E-0002** | Open when handling this Error Class/context, rather than loading all Action Maps |
43
+ | `E0002-actions` | `E0002-capture` | Detail supporting Capture / evidence | Read when raw evidence/provenance is required |
44
+ | `E0002-actions` | `E0002-writer` | Detail supporting Treat / Report CLI | Read when producing or validating a report through the proposed script |
45
+ | `E0002-actions` | `E0002-ledger` | Existing class evidence / history | Read for Identify/history relevance; do not copy or reclassify the ledger |
46
+
47
+ **Maintenance contract (lightweight):** when a document moves, update its **Table A path**; Table B continues to refer to the same local key. When a new Level 2 behavior block or Level 3 reference is added, add only the relevant row and reference. Removing an obsolete procedure removes its registry relationship without rewriting Level 1. **Do not re-encode Mermaid/PlantUML execution arrows as registry edges**: the source diagrams own flow semantics, while the tables own *navigation/lookup*.
48
+
49
+ ## P2-3 — no mandatory input/output contract for every Action
50
+
51
+ **Action / behavior block:** expresses the relevant behavior and keeps the Agent free to select appropriate means; no universal form of `input`, `output`, `precondition`, `postcondition` or handoff schema is imposed. Required lifecycle gates already belong to Level 1.
52
+
53
+ **Concrete technical boundary (Script, CLI, API, structured output):** document machine-checkable inputs/outputs, return code, errors, and any necessary validation in **the relevant Level 3 contract**. For E-0002, [Report Writer](./details/e0002-report-writer.md) already serves this purpose. A script can reject invalid data; it cannot fabricate approvals or declare the whole task done.
54
+
55
+ ## State of validation
56
+
57
+ - The owner will run **View vs Level comprehension tests**; P2-1 is **not** a presumed flaw or a reason to modify diagram text now.
58
+ - This registry is a **minimal design mapping** only. It has not been proven to improve Agent comprehension, navigation cost or runtime recurrence.
59
+ - Effectiveness and cost evaluation of Error Handling still requires complete Error Handling + Script + Hook/Skill integration, followed by real execution evidence.
@@ -0,0 +1,45 @@
1
+ # C6 packet briefing template (rev 1)
2
+
3
+ Copy this file per packet. **Every field is either filled with this packet's own authoritative value or `N/A: <reason>`.** Shared defaults (class-common.md, shared gates files) supply background only; they are never authoritative for this packet.
4
+
5
+ ## Runner / model / effort
6
+ runner: <e.g. one-shot `codex exec` (model, effort), `-s workspace-write`>
7
+ model: <model>
8
+ effort: <reasoning effort>
9
+
10
+ ## Worktree and input SHA
11
+ worktree: <cwd / path of this packet's own worktree>
12
+ input SHA: <pinned input SHA of this packet>
13
+ `N/A:` only if the packet performs no worktree-bound execution; state the reason.
14
+
15
+ ## Scope anchor (verbatim with source)
16
+ - Owner <id> (date): "<verbatim quote>" — source: <issue / PR / comment / owner decision>
17
+ - <additional source>: "<verbatim quote>" — source: <…>
18
+
19
+ ## Write-set
20
+ - <path> — <new / modify / read-only>
21
+ - …
22
+ Nothing else. Do not edit files outside the write-set.
23
+
24
+ ## Gate (dependsOn)
25
+ <verbatim gate clause or command this packet binds>
26
+ Depends on: <previous packets / steps, or none>
27
+
28
+ ## Verification commands
29
+ <commands to run, each with its expected exit code>
30
+
31
+ ## Error ledger
32
+ Read `.agents/harness-everything/errors/README.md` and every `E-*.md` before starting. Name the applied E-ids in the report.
33
+
34
+ ## Report path and report-writer invocation
35
+ Report-bearing packets require the #462 report writer. Pin a runnable `write` and `check` invocation and the packet-owned paths at dispatch. Use `npm run report` where installed, or name the available direct script and its base.
36
+ Body in `.402-work/<ID>-body.md`, then:
37
+ `npm run report -- write --body-file .402-work/<ID>-body.md --output .402-work/<ID>-report.md --status DONE` (or `--status BLOCKED --reason "<why>"`), then:
38
+ `npm run report -- check --file .402-work/<ID>-report.md`.
39
+ Sections: files changed; RED/walkthrough evidence; GREEN; gates with exit codes; E-ids; open questions / follow-ups (out-of-slice → listed, not fixed).
40
+
41
+ ## Terminal STATUS rule
42
+ The report's last line is exactly one column-zero `STATUS: DONE` or `STATUS: BLOCKED: <reason>`; nothing after it.
43
+
44
+ ## Real dispatch cite
45
+ `N/A: real dispatch cite added by the coordinator on the next dispatch.` — retained by the coordinator when this packet is dispatched for real.
@@ -21,6 +21,23 @@ Codex and OpenCode are `Partial` in `liveHostVerification`. The Codex artifact v
21
21
 
22
22
  Exact title/body-only `update_pull_request` calls are Codex-only host-deferred mutations after an argument allowlist check; explicit required Gate hints and all additional fields retain the existing Gate. Native task scope, permissions and GitHub authorization remain authoritative. Canonical/package mechanism tests cover hashes, audit provenance, outcomes and negative controls; this does not establish candidate live-host coverage. See [Codex policy](codex-action-gate.md#codex-pr-titlebody-updates-host-deferred).
23
23
 
24
+ ### Codex post-tool and subagent-stop hooks
25
+
26
+ Codex emits `PostToolUse` for both successful and failed shell commands. Harness
27
+ requires a structured zero exit status to credit shell verification or clear a
28
+ tracked shell failure. Text-only or missing status leaves verification and
29
+ recovery state intact and is audited as `unknown` for observed gated actions.
30
+ Edits are still tracked when the outcome is unknown because side effects may
31
+ already have occurred.
32
+
33
+ Codex `SubagentStop` uses the documented JSON `systemMessage` field for a UI-only
34
+ warning when the scope audit detects a new violation. Each audit advances the
35
+ Git status baseline and replaces `subagent-scope-last.json`. A later silent stop
36
+ can therefore coexist with unresolved changes. The coordinator owns
37
+ [scope reconciliation before accepting the result](../fable-mode/references/execution-phases.md#verification-and-handoff),
38
+ even when the hook is silent. The source and package fixtures cover these
39
+ behaviors. Windows host delivery remains to be verified.
40
+
24
41
  ### Routing contract vs. host evidence
25
42
 
26
43
  The workflow plan controller rejects present non-array required/optional binding declarations before recording a requirement plan. This input-validation contract is covered by deterministic mechanism tests and does not change live-host evidence status.
@@ -142,7 +159,9 @@ Updates retain at most two fingerprinted runtimes: the current runtime and the i
142
159
 
143
160
  Installs of a plugin source tracked by a linked Git worktree refuse before writing. For an ordinary checkout, only modified or untracked files inside the plugin source subtree cause refusal. The runtime is built from the subtree's Git-tracked files, so `.gitignore`-excluded files (for example `.DS_Store` or `__pycache__`) are neither copied nor fingerprinted and do not block installation. The operator can explicitly pass `--allow-unreleased-source`. Packaged copies whose plugin manifest is not tracked by an enclosing repository remain supported, including copies inside an unrelated dirty repository. The mechanism and self-regression runners give child processes temporary HOME/USERPROFILE and CODEX_HOME directories. Tests must pass temporary Codex homes or mock the hook installer; mocking host commands alone does not isolate filesystem writes.
144
161
 
145
- Ownership is deliberately strict: update/uninstall removes only exact entries recorded in the Harness compatibility manifest. If an installed Harness entry was edited after installation, the operation fails closed rather than overwriting or deleting that user-modified entry. Unrelated pre-existing and later-added user hooks are preserved.
162
+ By default, update and uninstall remove only exact entries recorded in the Harness compatibility manifest. If an installed Harness entry was edited after installation, restore it before retrying. These operations preserve other user hooks.
163
+
164
+ For #457, `harness codex-hooks status` lists candidate `legacyTierRouterHooks` in the Codex user hooks file, even before compatibility hooks are installed. After reviewing the list, run `harness codex-hooks install --remove-legacy-tier-router` to remove direct Node invocations of the npx-cached Harness `tier-router.js` from `UserPromptSubmit` and install or refresh the JSON adapter in the same operation. Other handlers in the same hook group are preserved. Ordinary installs and automatic plugin sync preserve these unmanaged entries. Review the resulting hook sources and trust in Codex with `/hooks`.
146
165
 
147
166
  The compatibility path registers hook commands in Codex user configuration and covers the missing plugin-mount route where user hooks dispatch. It does not repair a Codex carrier that fails to dispatch `PreToolUse` at all; those host-level execution-path limitations remain a live compatibility boundary.
148
167
 
@@ -4,7 +4,7 @@ description: "Stage large tasks through plans, named fable agents, failable chec
4
4
  license: Apache-2.0
5
5
  metadata:
6
6
  author: Miya Daniel
7
- version: 0.31.3
7
+ version: 0.54.1
8
8
  ---
9
9
 
10
10
  # Fable Mode
@@ -34,10 +34,10 @@ For explanation/profile-only lookup, read only `<this-skill-dir>/references/prof
34
34
  ## Workflow
35
35
 
36
36
  1. Discover the runtime and lock the authorized file scope before edits.
37
- 2. Per stage, set artifact, check, and required/optional bindings; dependency-ready stages disclose them, passing once resolved. Gaps never lock tools or Stop; advisory replans never halt. Rule-of-3 covers same-signature failures.
38
- 3. Resolve the requested behavior profile with `model-selector.js`; `opus`, `sonnet`/`sonnect`, and `haiku` are compatibility aliases, not model bindings.
39
- 4. Delegate by profile: orchestrator coordinates, reasoning takes bounded judgment, mechanical takes low-ambiguity work; workers never spawn workers.
37
+ 2. Plan via `<this-skill-dir>/references/execution-phases.md`.
38
+ 3. Use `model-selector.js`.
39
+ 4. Delegate by profile: orchestrator coordinates, reasoning takes bounded judgment, mechanical takes low-ambiguity work; workers never spawn workers. Before Codex dispatch, load/apply `<this-skill-dir>/references/execution-phases.md#verification-and-handoff`.
40
40
  5. The host runtime-model floor is advisory; record it, never block on model choice alone.
41
- 6. Run stage checks, cold-review high-stakes artifacts, and audit profile/runtime/fallback fields.
41
+ 6. On every Codex handoff or silent stop, load/apply `<this-skill-dir>/references/execution-phases.md#verification-and-handoff` before accepting results or releasing dependent stages. Run stage checks, cold-review high-stakes artifacts, and audit profile/runtime/fallback fields.
42
42
 
43
43
  Deep dive: <this-skill-dir>/references/model-matrix.md
@@ -4,7 +4,7 @@ description: "Reference guardrails for verified warnings and safe replacements;
4
4
  license: Apache-2.0
5
5
  metadata:
6
6
  author: Miya Daniel
7
- version: 0.31.3
7
+ version: 0.54.1
8
8
  ---
9
9
 
10
10
  # Execution Guardrails
@@ -4,7 +4,7 @@ description: "Reference mechanical behavior profile (legacy alias haiku) for bul
4
4
  license: Apache-2.0
5
5
  metadata:
6
6
  author: Miya Daniel
7
- version: 0.31.3
7
+ version: 0.54.1
8
8
  ---
9
9
 
10
10
  # Fable Mode — Haiku
@@ -4,7 +4,7 @@ description: "Reference orchestrator behavior profile (legacy alias opus) for st
4
4
  license: Apache-2.0
5
5
  metadata:
6
6
  author: Miya Daniel
7
- version: 0.31.3
7
+ version: 0.54.1
8
8
  ---
9
9
 
10
10
  # Fable Mode — Opus
@@ -4,7 +4,7 @@ description: "Reference reasoning behavior profile (legacy alias sonnet/sonnect)
4
4
  license: Apache-2.0
5
5
  metadata:
6
6
  author: Miya Daniel
7
- version: 0.31.3
7
+ version: 0.54.1
8
8
  ---
9
9
 
10
10
  # Fable Mode — Sonnet
@@ -17,13 +17,18 @@ flowchart TD
17
17
  Read relevant files and sources before producing an artifact. Record the
18
18
  authorized write scope. Give each stage an objective, dependencies, write set,
19
19
  expected output, exact check command, and pass condition. Required and optional
20
- bindings belong on the stage that needs them. Replan counts are advisory; after
21
- three same-signature failures, use Rule-of-3 `zoom-out`.
20
+ bindings belong on the stage that needs them. Replans are advisory and do not
21
+ halt tools or Stop; after three same-signature failures, use Rule-of-3
22
+ `zoom-out`.
22
23
 
23
24
  ## Profiles and delegation
24
25
 
25
- Resolve a requested behavior profile with Fable's profile selector and record
26
- it separately from the runtime choice. `fable-orchestrator`,
26
+ See the [model matrix](model-matrix.md) for profile details.
27
+
28
+ Resolve a requested behavior profile with Fable's `model-selector.js` and
29
+ record it separately from the runtime choice. `opus`, `sonnet`/`sonnect`, and
30
+ `haiku` are compatibility aliases for behavior profiles, not model bindings.
31
+ `fable-orchestrator`,
27
32
  `fable-worker-sonnet`, and `fable-worker-haiku` name coordination,
28
33
  reasoning/synthesis, and mechanical-work roles. These are behavior-profile
29
34
  aliases; they do not switch the runtime model. Preserve an explicit user or
@@ -104,3 +109,20 @@ Run each named check and review scope-guard evidence before delivery. When the
104
109
  selected plan requires independent verification, the verifier is read-only and
105
110
  uses a distinct worker identity after all other stages pass. Record a blocker
106
111
  or an evidence-backed result; do not discard unresolved requirements.
112
+
113
+ For Codex subagents, the coordinator MUST reconcile scope before accepting a
114
+ result or using it in a dependent stage, even if the stage check passed.
115
+
116
+ 1. Before dispatch, capture the worker worktree's starting state, including
117
+ existing local changes. At handoff, compare the committed, staged, unstaged,
118
+ and untracked changes since dispatch with the stage's declared `writeSet`.
119
+ 2. For unexpected or ambiguously attributed changes, establish ownership and
120
+ record the disposition. Exclude the changes from the result, revert only
121
+ attributable worker changes when authorized, or obtain explicit approval for
122
+ a scope change and follow the replanning rules. Record a blocker if the
123
+ coordinator cannot reconcile a path.
124
+
125
+ Run this check after every handoff, including silent stops. The Codex warning
126
+ and `subagent-scope-last.json` describe the latest hook observation. A clean
127
+ observation can replace an earlier warning while the corresponding change is
128
+ still present.
@@ -547,6 +547,11 @@ function finalizeExecution(payload, outcome, options = {}) {
547
547
  record.disposition = 'integrity-violation';
548
548
  record.integrityViolation = 'executed-payload-hash-differs-from-approved-payload';
549
549
  } else {
550
+ // A replay without status cannot replace an already observed outcome.
551
+ const known = record.executionOutcome === 'success' || record.executionOutcome === 'failure';
552
+ if (record.disposition === 'executed' && known && outcome === 'unknown') {
553
+ return { kind: 'audit', exitCode: 0, record };
554
+ }
550
555
  record.disposition = 'executed';
551
556
  record.executionOutcome = outcome;
552
557
  }
@@ -3,19 +3,10 @@
3
3
 
4
4
  const { finalizeExecution } = require('./action-gate');
5
5
 
6
- function inferOutcome(payload) {
7
- const response = (payload && (payload.tool_response || payload.toolResponse)) || {};
8
- const rawExitCode = response.exitCode ?? response.exit_code ?? payload?.exitCode ?? payload?.exit_code;
9
- if (typeof rawExitCode === 'number') return rawExitCode === 0 ? 'success' : 'failure';
10
- if (response.success === false || response.ok === false) return 'failure';
6
+ const { readCodexToolOutcome } = require('./lib/codex-tool-outcome');
11
7
 
12
- const stderr = response.stderr ?? payload?.stderr ?? '';
13
- if (typeof stderr === 'string' && stderr.trim()) {
14
- if (/\b(error|fail|failed|failure|exception|fatal|panic|traceback|denied|refused|cannot|unable)\b/i.test(stderr)) {
15
- return 'failure';
16
- }
17
- }
18
- return 'success';
8
+ function inferOutcome(payload) {
9
+ return readCodexToolOutcome(payload).outcome;
19
10
  }
20
11
 
21
12
  function processPayload(payload) {
@@ -1,9 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
  // Codex UserPromptSubmit adapter (docs/system-one-observations.md#hosts).
4
- // Codex adds prompt-time context to the model only from JSON
5
- // hookSpecificOutput.additionalContext; the router's plain stdout never
6
- // reaches the model. This runs the kernel router and wraps its output.
4
+ // Wrap router output in JSON hookSpecificOutput.additionalContext. Codex
5
+ // treats stdout beginning with "[" (including routing banners) as JSON-like.
7
6
 
8
7
  const fs = require('fs');
9
8
  const path = require('path');
@@ -24,8 +24,14 @@ const {
24
24
  } = require('./lib/fable-contracts');
25
25
  const { loadWorkflow, matchingRun } = require('./lib/workflow-runtime');
26
26
  const { createLearningOpportunity } = require('./lib/learning-opportunity');
27
+ const { readCodexToolOutcome } = require('./lib/codex-tool-outcome');
28
+ const codex = process.argv.includes('--codex');
27
29
 
28
30
  function resultState(payload) {
31
+ if (codex) {
32
+ const { outcome, exitCode, stdout, stderr } = readCodexToolOutcome(payload);
33
+ return { outcome, exitCode, evidence: (stderr.trim() || stdout).slice(-1000).trim() };
34
+ }
29
35
  const toolResponse = payload.tool_response || payload.tool_result || {};
30
36
  const stdout = toolResponse.stdout ?? payload.stdout ?? '';
31
37
  const stderr = toolResponse.stderr ?? payload.stderr ?? '';
@@ -36,7 +42,7 @@ function resultState(payload) {
36
42
  (exitCode !== undefined && exitCode !== 0) ||
37
43
  (exitCode === undefined && stderrSignal);
38
44
  const evidence = ((stderrSignal ? stderr : stdout) || '').slice(-1000).trim();
39
- return { failed, exitCode, evidence };
45
+ return { outcome: failed ? 'failure' : 'success', exitCode, evidence };
40
46
  }
41
47
 
42
48
  function unresolvedBindings(contract) {
@@ -46,8 +52,9 @@ function unresolvedBindings(contract) {
46
52
  : !['loaded', 'not-needed'].includes(binding.status));
47
53
  }
48
54
 
49
- function updateRunContract(entry, payload, command, sessionId) {
50
- const { failed, exitCode, evidence } = resultState(payload);
55
+ function updateRunContract(entry, payload, command, sessionId, result) {
56
+ const { outcome, exitCode, evidence } = result;
57
+ const failed = outcome === 'failure';
51
58
  const unresolved = unresolvedBindings(entry.contract);
52
59
  const status = failed ? 'fail' : unresolved.length ? 'binding-unresolved' : 'pass';
53
60
  const observedAt = new Date().toISOString();
@@ -93,7 +100,7 @@ function activeFableStages(runRoot) {
93
100
  return [];
94
101
  }
95
102
 
96
- function resolveLegacyContract(stateRoot, command, payload) {
103
+ function resolveLegacyContract(stateRoot, command, result) {
97
104
  const contractsDir = path.join(stateRoot, 'contracts');
98
105
  let files = [];
99
106
  try { files = fs.readdirSync(contractsDir).filter(file => file.endsWith('.json')); } catch (_) { return null; }
@@ -106,7 +113,8 @@ function resolveLegacyContract(stateRoot, command, payload) {
106
113
  matches.push({ manifest, filePath });
107
114
  }
108
115
  if (matches.length !== 1) return matches.length > 1 ? { ambiguous: true } : null;
109
- const { failed, evidence } = resultState(payload);
116
+ const { outcome, evidence } = result;
117
+ const failed = outcome === 'failure';
110
118
  const match = matches[0];
111
119
  match.manifest.status = failed ? 'fail' : 'pass';
112
120
  match.manifest.evidence = evidence;
@@ -124,6 +132,8 @@ process.stdin.on('end', () => {
124
132
 
125
133
  const command = ((payload.tool_input && payload.tool_input.command) || '').trim();
126
134
  if (!command) process.exit(0);
135
+ const result = resultState(payload);
136
+ if (result.outcome === 'unknown') process.exit(0);
127
137
 
128
138
  const root = getWorkspaceRoot(payload);
129
139
  const stateRoot = getStateRoot(root, payload);
@@ -161,7 +171,7 @@ process.stdin.on('end', () => {
161
171
  }
162
172
  const previousStatus = entry.contract.status;
163
173
  const previousVerifiedAt = entry.contract.verifiedAt || entry.contract.updatedAt || null;
164
- const contract = updateRunContract(entry, payload, command, sessionId);
174
+ const contract = updateRunContract(entry, payload, command, sessionId, result);
165
175
  if (previousStatus === 'fail' && contract.status === 'pass') {
166
176
  try {
167
177
  createLearningOpportunity(payload, {
@@ -199,7 +209,7 @@ process.stdin.on('end', () => {
199
209
 
200
210
  // Temporary compatibility with pre-Phase-3 manifests. New orchestration
201
211
  // must use run-scoped contracts; legacy manifests have no plan/run link.
202
- const legacy = resolveLegacyContract(stateRoot, command, payload);
212
+ const legacy = resolveLegacyContract(stateRoot, command, result);
203
213
  if (legacy && legacy.ambiguous) {
204
214
  console.error(`[Contract Test] Ambiguous legacy stage contracts matched: ${command}`);
205
215
  process.exit(0);
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ // Codex PostToolUse runs for both zero and nonzero exits. A string response
4
+ // can contain arbitrary command output and is never evidence of an exit code.
5
+ function readCodexToolOutcome(payload) {
6
+ const raw = payload?.tool_response ?? payload?.toolResponse;
7
+ const response = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
8
+ const codes = [response.exitCode, response.exit_code, payload?.exitCode, payload?.exit_code]
9
+ .filter(Number.isInteger);
10
+ const exitCode = codes.find(code => code !== 0) ?? codes[0];
11
+ const stdout = typeof raw === 'string' ? raw : response.stdout ?? payload?.stdout;
12
+ const stderr = response.stderr ?? payload?.stderr;
13
+ const shell = ['Bash', 'PowerShell', 'exec_command'].includes(payload?.tool_name);
14
+ const failed = exitCode !== undefined && exitCode !== 0 ||
15
+ response.isError === true || response.is_error === true ||
16
+ response.success === false || response.ok === false;
17
+ const succeeded = exitCode === 0 || (!shell &&
18
+ (response.isError === false || response.is_error === false ||
19
+ response.success === true || response.ok === true));
20
+ return {
21
+ outcome: failed ? 'failure' : succeeded ? 'success' : 'unknown',
22
+ exitCode,
23
+ stdout: typeof stdout === 'string' ? stdout : '',
24
+ stderr: typeof stderr === 'string' ? stderr : '',
25
+ };
26
+ }
27
+
28
+ module.exports = { readCodexToolOutcome };
@@ -4,6 +4,8 @@ const path = require('path');
4
4
  const crypto = require('crypto');
5
5
  const { getWorkspaceRoot, getSessionDir } = require('./lib/harness-state');
6
6
  const { createLearningOpportunity } = require('./lib/learning-opportunity');
7
+ const { readCodexToolOutcome } = require('./lib/codex-tool-outcome');
8
+ const codex = process.argv.includes('--codex');
7
9
 
8
10
  // PostToolUse/PostToolUseFailure hooks in Claude Code receive their payload via stdin
9
11
  let inputData = '';
@@ -15,12 +17,14 @@ process.stdin.on('data', chunk => {
15
17
  process.stdin.on('end', () => {
16
18
  try {
17
19
  const payload = JSON.parse(inputData);
20
+ const codexResult = codex ? readCodexToolOutcome(payload) : null;
21
+ if (codexResult?.outcome === 'unknown') return;
18
22
  const hookEventName = payload.hook_event_name || payload.hookEventName || '';
19
23
  const isFailureEvent = hookEventName === 'PostToolUseFailure';
20
24
  const isSuccessEvent = hookEventName === 'PostToolUse';
21
25
  const toolResponse = payload.tool_response || {};
22
- const stdout = toolResponse.stdout ?? payload.stdout ?? '';
23
- const stderr = toolResponse.stderr ?? payload.stderr ?? '';
26
+ const stdout = codexResult?.stdout ?? toolResponse.stdout ?? payload.stdout ?? '';
27
+ const stderr = codexResult?.stderr ?? toolResponse.stderr ?? payload.stderr ?? '';
24
28
  const failureText = typeof payload.error === 'string' ? payload.error : '';
25
29
  const rawExitCode = toolResponse.exitCode ?? toolResponse.exit_code ?? payload.exitCode ?? payload.exit_code;
26
30
  const exitCode = typeof rawExitCode === 'number' ? rawExitCode : undefined;
@@ -33,11 +37,14 @@ process.stdin.on('end', () => {
33
37
  const explicitFailure = exitCode !== undefined && exitCode !== 0;
34
38
  const stderrSignal = typeof stderr === 'string' && stderr.trim().length > 0;
35
39
  const looksLikeError = /\b(error|fail|failed|failure|exception|fatal|panic|traceback|denied|refused|cannot|unable)\b/i.test(stderr);
36
- const isFailure = isFailureEvent || explicitFailure ||
40
+ const isFailure = codex ? codexResult.outcome === 'failure' : isFailureEvent || explicitFailure ||
37
41
  (!isSuccessEvent && exitCode === undefined && stderrSignal && looksLikeError);
38
- const errorText = isFailureEvent
42
+ const reportedError = isFailureEvent
39
43
  ? (failureText || (stderrSignal ? stderr : stdout) || '')
40
44
  : ((stderrSignal ? stderr : stdout) || failureText || '');
45
+ const errorText = reportedError || (codexResult?.outcome === 'failure'
46
+ ? (codexResult.exitCode === undefined ? 'Tool reported failure' : `Tool exited with code ${codexResult.exitCode}`)
47
+ : '');
41
48
 
42
49
  const root = getWorkspaceRoot(payload);
43
50
  const stateFile = path.join(getSessionDir(root, payload.session_id || payload.sessionId), 'rule-of-3-state.json');