harness-everything 0.56.1 → 0.57.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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +22 -0
- package/benchmarks/results/live-host/claude-2026-11-21-ledger-lesson/README.md +33 -0
- package/benchmarks/results/live-host/claude-2026-11-21-ledger-lesson/trace.jsonl +13 -0
- package/ci/fixtures/394-claude-ledger-lesson/post-tool-use-failure.json +13 -0
- package/ci/fixtures/394-claude-ledger-lesson/pre-tool-use.json +10 -0
- package/ci/fixtures/394-codex-ledger-lesson/post-tool-use-failure.json +17 -0
- package/ci/fixtures/394-codex-ledger-lesson/post-tool-use-success.json +17 -0
- package/ci/fixtures/394-codex-ledger-lesson/post-tool-use-unknown.json +15 -0
- package/ci/fixtures/394-codex-ledger-lesson/pre-tool-use.json +12 -0
- package/ci/fixtures/394-ledger-match/commitlint-empty-subject.txt +5 -0
- package/ci/fixtures/394-ledger-match/commitlint-subject-case.txt +5 -0
- package/ci/fixtures/394-ledger-match/provisional-candidates.json +20 -0
- package/ci/fixtures/394-ledger-match/quoted-match-record.md +25 -0
- package/ci/mechanism-394-claude-ledger-lesson.test.js +176 -0
- package/ci/mechanism-394-codex-ledger-lesson.test.js +203 -0
- package/ci/mechanism-394-ledger-match.test.js +521 -0
- package/ci/mechanism-394-opencode-ledger-lesson.test.js +232 -0
- package/ci/mechanism-errors-sync-root.test.js +86 -4
- package/docs/adr/ROUTE-001-error-lesson-delivery.md +52 -49
- package/docs/governed-index.md +1 -1
- package/docs/platform-capabilities.md +4 -0
- package/hooks/hooks.json +22 -0
- package/hooks/scripts/codex-ledger-lesson.js +82 -0
- package/hooks/scripts/ledger-lesson.js +94 -0
- package/hooks/scripts/lib/ledger-match.js +452 -0
- package/opencode-plugin/index.mjs +113 -4
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/hooks.json +24 -0
- package/plugins/harness-everything/hooks/scripts/codex-ledger-lesson.js +82 -0
- package/plugins/harness-everything/hooks/scripts/ledger-lesson.js +94 -0
- package/plugins/harness-everything/hooks/scripts/lib/ledger-match.js +452 -0
- package/plugins/harness-everything/plugin.json +1 -1
- package/sbom.cdx.json +7 -7
- package/scripts/errors-sync.js +63 -2
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"name": "harness-everything",
|
|
11
11
|
"source": "./",
|
|
12
12
|
"description": "Harness OS: an orchestrated agent operating system — tier routing, circuit breaker guardrails, verification gates, WAL session memory, and self-evolving workspace rules.",
|
|
13
|
-
"version": "0.
|
|
13
|
+
"version": "0.57.1",
|
|
14
14
|
"author": {
|
|
15
15
|
"name": "Miya Daniel"
|
|
16
16
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "harness-everything",
|
|
3
3
|
"description": "Harness OS: an orchestrated agent operating system — tier routing, circuit breaker guardrails, verification gates, WAL session memory, and self-evolving workspace rules.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.57.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Miya Daniel"
|
|
7
7
|
},
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.57.1](https://github.com/dyphn1/Harness-everything/compare/v0.57.0...v0.57.1) (2026-11-22)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
* **ledger:** accept empty git config values ([6788ab7](https://github.com/dyphn1/Harness-everything/commit/6788ab7be7e31ee1dde84e8cddd8c96826cf4113))
|
|
10
|
+
|
|
11
|
+
## [0.57.0](https://github.com/dyphn1/Harness-everything/compare/v0.56.1...v0.57.0) (2026-11-21)
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* **errors:** validate and index ledger match rules ([69ec4b3](https://github.com/dyphn1/Harness-everything/commit/69ec4b3ceae209bcab14e50f75ce4cf08d1ebdfe)), closes [#394](https://github.com/dyphn1/Harness-everything/issues/394) [#394](https://github.com/dyphn1/Harness-everything/issues/394)
|
|
16
|
+
* **hooks:** add the shared ledger lesson matcher ([8c87fd5](https://github.com/dyphn1/Harness-everything/commit/8c87fd56da3be9a86043168b1b031f9d0339502a)), closes [#394](https://github.com/dyphn1/Harness-everything/issues/394) [#394](https://github.com/dyphn1/Harness-everything/issues/394)
|
|
17
|
+
* **hooks:** carry matched ledger lessons into claude code bash context ([c844215](https://github.com/dyphn1/Harness-everything/commit/c844215506831bbad133a1dfbaa4b9c04b4c52a5)), closes [#394](https://github.com/dyphn1/Harness-everything/issues/394) [#394](https://github.com/dyphn1/Harness-everything/issues/394)
|
|
18
|
+
* **hooks:** carry matched ledger lessons into codex bash context ([463b1a2](https://github.com/dyphn1/Harness-everything/commit/463b1a2cf654433260824525779c0460d9d600ef)), closes [#394](https://github.com/dyphn1/Harness-everything/issues/394) [#394](https://github.com/dyphn1/Harness-everything/issues/394)
|
|
19
|
+
* **hooks:** carry matched ledger lessons into opencode v2 model context ([9f9118b](https://github.com/dyphn1/Harness-everything/commit/9f9118b681dbb283183f75d9d80c0c0eaa9dacff)), closes [#394](https://github.com/dyphn1/Harness-everything/issues/394) [#394](https://github.com/dyphn1/Harness-everything/issues/394)
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* **hooks:** select ledger rules from the generated index and accept git global options ([da04617](https://github.com/dyphn1/Harness-everything/commit/da046171759c505c0ea2dbfcd4b0a57d8bbe62d9)), closes [#501](https://github.com/dyphn1/Harness-everything/issues/501) [#394](https://github.com/dyphn1/Harness-everything/issues/394)
|
|
24
|
+
|
|
5
25
|
## [0.56.1](https://github.com/dyphn1/Harness-everything/compare/v0.56.0...v0.56.1) (2026-11-21)
|
|
6
26
|
|
|
7
27
|
### Bug Fixes
|
|
@@ -157,6 +177,8 @@ All notable changes to this project are documented in this file.
|
|
|
157
177
|
|
|
158
178
|
## [Unreleased]
|
|
159
179
|
|
|
180
|
+
- Error-ledger lesson injection (#394): ledger records gain optional `match` rules; a shared matcher carries matched Cue/Lesson text into Claude Code, Codex and OpenCode V2 context at a `git commit` action and its commitlint failure (mechanism evidence; OpenCode V1 delivery unchecked). ROUTE-001 is superseded.
|
|
181
|
+
|
|
160
182
|
- Retired the Rule-of-3 failure-count breaker on Claude Code, Codex and OpenCode (#394). Hooks no longer count same-signature failures, block tools, demand a reflection report or offer `harness:reset`; legacy breaker state is ignored. Zoom-out is agent-initiated: an agent may reassess on a first meaningful failure and may keep iterating while attempts produce new evidence. Error-ledger lesson injection remains planned under #394.
|
|
161
183
|
|
|
162
184
|
### Features
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Claude Code ledger-lesson delivery (#394)
|
|
2
|
+
|
|
3
|
+
**Observed:** Claude Code 2.1.330 on macOS, 2026-11-21, model `claude-haiku-5-5`, plugin loaded with `--plugin-dir` from integration commit `a8533ed6` (branch `feat/394-inject`). One fresh disposable clone of that commit with `npm ci` (real ledger index with the E-0003 `match` rules, real commitlint and husky). The prompt asked only to run three commands and report exit codes; it did not mention the ledger or the lesson.
|
|
4
|
+
|
|
5
|
+
[`trace.jsonl`](trace.jsonl) is a sanitized extract of the session transcript (home and scratch paths replaced): tool calls, tool results, hook context attachments, and for each model request whether the ledger context was in it.
|
|
6
|
+
|
|
7
|
+
```mermaid
|
|
8
|
+
sequenceDiagram
|
|
9
|
+
participant M as Model
|
|
10
|
+
participant H as Claude Code + hooks
|
|
11
|
+
M->>H: Bash git status --short
|
|
12
|
+
H-->>M: result (no ledger context)
|
|
13
|
+
M->>H: Bash git commit --allow-empty -m "docs: Probe Subject"
|
|
14
|
+
H->>H: PreToolUse ledger-lesson → E-0003 context
|
|
15
|
+
H->>H: commitlint subject-case rejects, exit 1
|
|
16
|
+
H->>H: PostToolUseFailure ledger-lesson → E-0003 context
|
|
17
|
+
H-->>M: next request carries both contexts (b69abfb52183)
|
|
18
|
+
M->>H: Bash git log --oneline -1 (HEAD unchanged)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
| Row | Observed |
|
|
22
|
+
|---|---|
|
|
23
|
+
| Control (`git status`, `git log`) | No ledger context. |
|
|
24
|
+
| Action (`git commit`) | `PreToolUse:Bash` additional context = E-0003 Cue + Lesson + one neutral invitation (667 chars). |
|
|
25
|
+
| Failure (commitlint `subject-case`, exit 1) | `PostToolUseFailure:Bash` additional context, same lesson (phase-keyed dedupe allows both). |
|
|
26
|
+
| Model input | The model request after the commit (`b69abfb52183`) contains both contexts; no earlier request does. |
|
|
27
|
+
| Tool result / permission | Commit refused by the existing husky hook; HEAD unchanged (`a8533ed6` before and after); no permission decision emitted by the carrier. |
|
|
28
|
+
|
|
29
|
+
## What this does not establish
|
|
30
|
+
|
|
31
|
+
- **Timing:** the action context reached the model only in the request after the commit ran, so on Claude Code the pre-tool lesson cannot stop the first attempt; it informs the next step.
|
|
32
|
+
- **Behaviour:** the model reported the rejection and did not retry; consideration and use of the lesson are not observed, and one run says nothing about recurrence. A behaviour claim needs paired baseline/treatment runs.
|
|
33
|
+
- **Other hosts:** Codex and OpenCode delivery were not captured in this session (see the #394 PR).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{"kind": "api-request", "hash": "0352c2653be9", "containsPreToolUseLedgerContext": false, "containsPostToolUseFailureLedgerContext": false}
|
|
2
|
+
{"kind": "api-request", "hash": "dfe06d43762b", "containsPreToolUseLedgerContext": false, "containsPostToolUseFailureLedgerContext": false}
|
|
3
|
+
{"kind": "tool_use", "id": "toolu_01U5BFE1gy4BCtmjaehAyJbb", "command": "git status --short"}
|
|
4
|
+
{"kind": "tool_result", "tool_use_id": "toolu_01U5BFE1gy4BCtmjaehAyJbb", "is_error": false, "firstLine": "(Bash completed with no output)"}
|
|
5
|
+
{"kind": "api-request", "hash": "b877a0750ef0", "containsPreToolUseLedgerContext": false, "containsPostToolUseFailureLedgerContext": false}
|
|
6
|
+
{"kind": "tool_use", "id": "toolu_01X1qmPJ6EFPMLACYZb1vt9H", "command": "git commit --allow-empty -m \"docs: Probe Subject\" -m \"Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>\""}
|
|
7
|
+
{"kind": "hook_additional_context", "hookEvent": "PreToolUse", "toolUseID": "toolu_01X1qmPJ6EFPMLACYZb1vt9H", "text": "Cue:\nA commit is rejected locally by commitlint for the shape of its subject line — uppercase text or a header past the length limit — in the middle of a routine push or release.\nLesson:\nCheck the subject line against both rules before committing: lower case (`subject-case`) and at most 100 characters (`header-max-length`). The existing `.husky/commit-msg` hook already runs commitlint on the message, so the failure surfaces at `git commit`, not in CI. The retrospective's prevention candidate — a pre-push helper that checks mergeability and commit-message lint — does not exist yet.\n\nConsider a fresh look, and zoom out if warranted."}
|
|
8
|
+
{"kind": "tool_result", "tool_use_id": "toolu_01X1qmPJ6EFPMLACYZb1vt9H", "is_error": true, "firstLine": "Exit code 1"}
|
|
9
|
+
{"kind": "hook_additional_context", "hookEvent": "PostToolUseFailure", "toolUseID": "toolu_01X1qmPJ6EFPMLACYZb1vt9H", "text": "Cue:\nA commit is rejected locally by commitlint for the shape of its subject line — uppercase text or a header past the length limit — in the middle of a routine push or release.\nLesson:\nCheck the subject line against both rules before committing: lower case (`subject-case`) and at most 100 characters (`header-max-length`). The existing `.husky/commit-msg` hook already runs commitlint on the message, so the failure surfaces at `git commit`, not in CI. The retrospective's prevention candidate — a pre-push helper that checks mergeability and commit-message lint — does not exist yet.\n\nConsider a fresh look, and zoom out if warranted."}
|
|
10
|
+
{"kind": "api-request", "hash": "b69abfb52183", "containsPreToolUseLedgerContext": true, "containsPostToolUseFailureLedgerContext": true}
|
|
11
|
+
{"kind": "tool_use", "id": "toolu_01V36NLjZiH1oi7Qfbrh9vmo", "command": "git log --oneline -1"}
|
|
12
|
+
{"kind": "tool_result", "tool_use_id": "toolu_01V36NLjZiH1oi7Qfbrh9vmo", "is_error": false, "firstLine": "a8533ed6 docs(platform): record the ledger lesson carriers as mechanism evidence"}
|
|
13
|
+
{"kind": "api-request", "hash": "328bc72af58c", "containsPreToolUseLedgerContext": false, "containsPostToolUseFailureLedgerContext": false}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"session_id": "r2c1-sess-a",
|
|
3
|
+
"transcript_path": "/tmp/r2c1/transcript-a.jsonl",
|
|
4
|
+
"cwd": "/tmp/r2c1-ws",
|
|
5
|
+
"permission_mode": "default",
|
|
6
|
+
"hook_event_name": "PostToolUseFailure",
|
|
7
|
+
"tool_name": "Bash",
|
|
8
|
+
"tool_input": { "command": "npm test", "description": "Run test suite" },
|
|
9
|
+
"tool_use_id": "toolu_r2c1_b",
|
|
10
|
+
"error": "Exit code 2\nnpm ERR! r2c1 simulated failure",
|
|
11
|
+
"is_interrupt": false,
|
|
12
|
+
"duration_ms": 4187
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hook_event_name": "PreToolUse",
|
|
3
|
+
"tool_name": "Bash",
|
|
4
|
+
"tool_use_id": "toolu_hc_action",
|
|
5
|
+
"session_id": "hc-session",
|
|
6
|
+
"prompt_id": "hc-prompt",
|
|
7
|
+
"tool_input_command": "git commit -m \"docs: record task progress\"",
|
|
8
|
+
"cwd": ".",
|
|
9
|
+
"transcript_path": "/tmp/hc-session.jsonl"
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"session_id": "fixture-session",
|
|
3
|
+
"cwd": "/tmp/ledger-workspace",
|
|
4
|
+
"hook_event_name": "PostToolUse",
|
|
5
|
+
"turn_id": "fixture-turn",
|
|
6
|
+
"tool_name": "Bash",
|
|
7
|
+
"tool_use_id": "fixture-tool-use",
|
|
8
|
+
"permission_mode": "default",
|
|
9
|
+
"tool_input": {
|
|
10
|
+
"command": "git commit -m \"Docs: rejected subject\""
|
|
11
|
+
},
|
|
12
|
+
"tool_response": {
|
|
13
|
+
"exit_code": 1,
|
|
14
|
+
"stdout": "",
|
|
15
|
+
"stderr": ""
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"session_id": "fixture-session",
|
|
3
|
+
"cwd": "/tmp/ledger-workspace",
|
|
4
|
+
"hook_event_name": "PostToolUse",
|
|
5
|
+
"turn_id": "fixture-turn",
|
|
6
|
+
"tool_name": "Bash",
|
|
7
|
+
"tool_use_id": "fixture-tool-use",
|
|
8
|
+
"permission_mode": "default",
|
|
9
|
+
"tool_input": {
|
|
10
|
+
"command": "git commit -m \"docs: accepted subject\""
|
|
11
|
+
},
|
|
12
|
+
"tool_response": {
|
|
13
|
+
"exit_code": 0,
|
|
14
|
+
"stdout": "[main 0123456] docs: accepted subject",
|
|
15
|
+
"stderr": ""
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"session_id": "fixture-session",
|
|
3
|
+
"cwd": "/tmp/ledger-workspace",
|
|
4
|
+
"hook_event_name": "PostToolUse",
|
|
5
|
+
"turn_id": "fixture-turn",
|
|
6
|
+
"tool_name": "Bash",
|
|
7
|
+
"tool_use_id": "fixture-tool-use",
|
|
8
|
+
"permission_mode": "default",
|
|
9
|
+
"tool_input": {
|
|
10
|
+
"command": "git commit -m \"Docs: unknown result\""
|
|
11
|
+
},
|
|
12
|
+
"tool_response": {
|
|
13
|
+
"stderr": ""
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"session_id": "fixture-session",
|
|
3
|
+
"cwd": "/tmp/ledger-workspace",
|
|
4
|
+
"hook_event_name": "PreToolUse",
|
|
5
|
+
"turn_id": "fixture-turn",
|
|
6
|
+
"tool_name": "Bash",
|
|
7
|
+
"tool_use_id": "fixture-tool-use",
|
|
8
|
+
"permission_mode": "default",
|
|
9
|
+
"tool_input": {
|
|
10
|
+
"command": "git commit -m \"Docs: rejected subject\""
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"identity": "local-commit-a",
|
|
4
|
+
"signature": "local-commit-a",
|
|
5
|
+
"match": {
|
|
6
|
+
"actions": [{ "tool": "shell", "executable": "git", "subcommand": "commit" }]
|
|
7
|
+
},
|
|
8
|
+
"cue": "A local note about a commit.",
|
|
9
|
+
"lesson": "Check the proposed message before retrying."
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"identity": "local-commit-b",
|
|
13
|
+
"signature": "local-commit-b",
|
|
14
|
+
"match": {
|
|
15
|
+
"actions": [{ "tool": "shell", "executable": "git", "subcommand": "commit" }]
|
|
16
|
+
},
|
|
17
|
+
"cue": "A second local note about a commit.",
|
|
18
|
+
"lesson": "Keep the corrected message within the project's rules."
|
|
19
|
+
}
|
|
20
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: "E-0999"
|
|
3
|
+
signature: "quoted-match-record"
|
|
4
|
+
class: "test"
|
|
5
|
+
scope: "in"
|
|
6
|
+
status: "lesson"
|
|
7
|
+
match:
|
|
8
|
+
actions:
|
|
9
|
+
- tool: "shell"
|
|
10
|
+
executable: "git"
|
|
11
|
+
subcommand: "commit"
|
|
12
|
+
failures:
|
|
13
|
+
- tool: "shell"
|
|
14
|
+
executable: "git"
|
|
15
|
+
subcommand: "commit"
|
|
16
|
+
diagnostics:
|
|
17
|
+
- "subject-case"
|
|
18
|
+
---
|
|
19
|
+
## Cue
|
|
20
|
+
|
|
21
|
+
A generated quoted rule is still an ordinary Git commit.
|
|
22
|
+
|
|
23
|
+
## Lesson
|
|
24
|
+
|
|
25
|
+
Review the commit message before retrying.
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const assert = require('node:assert/strict');
|
|
5
|
+
const { spawnSync } = require('node:child_process');
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
const os = require('node:os');
|
|
8
|
+
const path = require('node:path');
|
|
9
|
+
const test = require('node:test');
|
|
10
|
+
|
|
11
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
12
|
+
const HOOKS = JSON.parse(fs.readFileSync(path.join(ROOT, 'hooks/hooks.json'), 'utf8')).hooks;
|
|
13
|
+
const ADAPTER = path.join(ROOT, 'hooks/scripts/ledger-lesson.js');
|
|
14
|
+
const ERRORS_SYNC = path.join(ROOT, 'scripts/errors-sync.js');
|
|
15
|
+
const FIXTURES = path.join(__dirname, 'fixtures/394-claude-ledger-lesson');
|
|
16
|
+
const LEDGER = path.join(ROOT, '.agents/harness-everything/errors');
|
|
17
|
+
const E3_FILE = fs.readdirSync(LEDGER).find(file => /^E-0003-[a-z0-9-]+\.md$/.test(file));
|
|
18
|
+
const COMMITLINT_OUTPUT = fs.readFileSync(
|
|
19
|
+
path.join(__dirname, 'fixtures/394-ledger-match/commitlint-subject-case.txt'), 'utf8');
|
|
20
|
+
const TMP = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), '394 claude ledger lesson ')));
|
|
21
|
+
const STATE_HOME = path.join(TMP, 'state-home');
|
|
22
|
+
let serial = 0;
|
|
23
|
+
|
|
24
|
+
test.after(() => fs.rmSync(TMP, { recursive: true, force: true }));
|
|
25
|
+
|
|
26
|
+
function register(event, id) {
|
|
27
|
+
const entries = HOOKS[event].filter(entry => entry.id === id);
|
|
28
|
+
assert.equal(entries.length, 1, `${event} registers exactly one ${id} hook`);
|
|
29
|
+
assert.equal(entries[0].matcher, 'Bash', `${id} matches Bash only`);
|
|
30
|
+
assert.deepEqual(entries[0].hooks, [{
|
|
31
|
+
type: 'command',
|
|
32
|
+
command: 'node "${CLAUDE_PLUGIN_ROOT}/hooks/scripts/ledger-lesson.js"'
|
|
33
|
+
}]);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function newWorkspace(name) {
|
|
37
|
+
const root = path.join(TMP, `${name}-${++serial}`);
|
|
38
|
+
const ledger = path.join(root, '.agents/harness-everything/errors');
|
|
39
|
+
fs.mkdirSync(ledger, { recursive: true });
|
|
40
|
+
fs.copyFileSync(path.join(LEDGER, E3_FILE), path.join(ledger, E3_FILE));
|
|
41
|
+
const generated = spawnSync(process.execPath, [ERRORS_SYNC, '--root', root], { cwd: ROOT, encoding: 'utf8' });
|
|
42
|
+
assert.equal(generated.status, 0, generated.stderr);
|
|
43
|
+
return root;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function payload(name, overrides = {}) {
|
|
47
|
+
return {
|
|
48
|
+
...JSON.parse(fs.readFileSync(path.join(FIXTURES, name), 'utf8')),
|
|
49
|
+
...overrides
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function run(input) {
|
|
54
|
+
let payloadValue = typeof input === 'string' ? null : input;
|
|
55
|
+
if (!payloadValue && typeof input === 'string') {
|
|
56
|
+
try { payloadValue = JSON.parse(input); } catch (_) { /* malformed input uses the action hook */ }
|
|
57
|
+
}
|
|
58
|
+
const event = payloadValue?.hook_event_name === 'PostToolUseFailure'
|
|
59
|
+
? 'PostToolUseFailure' : 'PreToolUse';
|
|
60
|
+
const id = event === 'PreToolUse'
|
|
61
|
+
? 'harness:pre:ledger-lesson' : 'harness:post-failure:ledger-lesson';
|
|
62
|
+
const registration = HOOKS[event].find(entry => entry.id === id);
|
|
63
|
+
assert.ok(registration, `${event} registration exists before invocation`);
|
|
64
|
+
const env = { ...process.env, CLAUDE_PLUGIN_ROOT: ROOT, HARNESS_STATE_HOME: STATE_HOME };
|
|
65
|
+
delete env.HARNESS_SYSTEM_ONE_MODE;
|
|
66
|
+
delete env.CLAUDE_PROJECT_DIR;
|
|
67
|
+
delete env.CODEX_PROJECT_DIR;
|
|
68
|
+
delete env.HARNESS_WORKSPACE_ROOT;
|
|
69
|
+
delete env.FABLE_WORKSPACE_ROOT;
|
|
70
|
+
const command = registration.hooks[0].command.replace(/\$\{CLAUDE_PLUGIN_ROOT\}/g, env.CLAUDE_PLUGIN_ROOT);
|
|
71
|
+
const target = command.match(/^node\s+"([^"]+)"$/);
|
|
72
|
+
assert.ok(target, `${event} resolves to a direct Node hook command: ${registration.hooks[0].command}`);
|
|
73
|
+
assert.equal(path.resolve(target[1]), path.resolve(ADAPTER), `${event} resolves its registered adapter path`);
|
|
74
|
+
return spawnSync('node', [target[1]], {
|
|
75
|
+
cwd: ROOT,
|
|
76
|
+
env,
|
|
77
|
+
input: typeof input === 'string' ? input : JSON.stringify(input),
|
|
78
|
+
encoding: 'utf8'
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function assertContext(result, eventName) {
|
|
83
|
+
assert.equal(result.status, 0, result.stderr || 'adapter exits successfully');
|
|
84
|
+
assert.equal(result.stderr, '', 'adapter stays silent on stderr');
|
|
85
|
+
const output = JSON.parse(result.stdout);
|
|
86
|
+
assert.deepEqual(Object.keys(output), ['hookSpecificOutput']);
|
|
87
|
+
assert.deepEqual(Object.keys(output.hookSpecificOutput), ['hookEventName', 'additionalContext']);
|
|
88
|
+
assert.equal(output.hookSpecificOutput.hookEventName, eventName);
|
|
89
|
+
assert.match(output.hookSpecificOutput.additionalContext, /Check the subject line against both rules/);
|
|
90
|
+
assert.equal(output.hookSpecificOutput.permissionDecision, undefined,
|
|
91
|
+
'the carrier does not change Claude permission handling');
|
|
92
|
+
return output.hookSpecificOutput.additionalContext;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function assertSilent(result) {
|
|
96
|
+
assert.equal(result.status, 0, result.stderr || 'fail-open adapter exits successfully');
|
|
97
|
+
assert.equal(result.stdout, '', 'no-match and malformed events emit no context');
|
|
98
|
+
assert.equal(result.stderr, '', 'fail-open handling stays silent');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
test('registers the Claude Bash action and failure context carrier', () => {
|
|
102
|
+
register('PreToolUse', 'harness:pre:ledger-lesson');
|
|
103
|
+
register('PostToolUseFailure', 'harness:post-failure:ledger-lesson');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('emits action then failure context once per phase and session without changing tool flow', () => {
|
|
107
|
+
assert.ok(fs.existsSync(ADAPTER), 'Claude ledger lesson adapter exists');
|
|
108
|
+
const root = newWorkspace('with-ledger');
|
|
109
|
+
const sessionId = `hc-session-${process.pid}`;
|
|
110
|
+
const action = payload('pre-tool-use.json', { cwd: root, session_id: sessionId });
|
|
111
|
+
const failure = payload('post-tool-use-failure.json', {
|
|
112
|
+
cwd: root,
|
|
113
|
+
session_id: sessionId,
|
|
114
|
+
tool_input: { command: 'git commit -m "Bad Subject"' },
|
|
115
|
+
error: COMMITLINT_OUTPUT
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const actionContext = assertContext(run(JSON.stringify(action)), 'PreToolUse');
|
|
119
|
+
const failureContext = assertContext(run(JSON.stringify(failure)), 'PostToolUseFailure');
|
|
120
|
+
assert.equal(actionContext, failureContext, 'both phases carry the same canonical Cue and Lesson');
|
|
121
|
+
assert.ok(!failureContext.includes(COMMITLINT_OUTPUT),
|
|
122
|
+
'failure diagnostics are matching input, not copied into context');
|
|
123
|
+
|
|
124
|
+
const prefixedSession = sessionId + '-prefixed';
|
|
125
|
+
const prefixedAction = {
|
|
126
|
+
...action,
|
|
127
|
+
session_id: prefixedSession,
|
|
128
|
+
tool_input_command: 'git -C x commit -m "Bad Subject"'
|
|
129
|
+
};
|
|
130
|
+
const prefixedFailure = {
|
|
131
|
+
...failure,
|
|
132
|
+
session_id: prefixedSession,
|
|
133
|
+
tool_input: { command: 'git -C x commit -m "Bad Subject"' }
|
|
134
|
+
};
|
|
135
|
+
assertContext(run(JSON.stringify(prefixedAction)), 'PreToolUse');
|
|
136
|
+
assertContext(run(JSON.stringify(prefixedFailure)), 'PostToolUseFailure');
|
|
137
|
+
|
|
138
|
+
assertSilent(run(JSON.stringify(action)));
|
|
139
|
+
assertSilent(run(JSON.stringify(failure)));
|
|
140
|
+
assertContext(run(JSON.stringify({ ...action, session_id: `${sessionId}-other` })), 'PreToolUse');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('keeps dedupe state separate when a session changes workspace identity', () => {
|
|
144
|
+
const firstRoot = newWorkspace('first-workspace');
|
|
145
|
+
const secondRoot = newWorkspace('second-workspace');
|
|
146
|
+
const sessionId = `hc-workspace-${process.pid}`;
|
|
147
|
+
const action = payload('pre-tool-use.json', { cwd: firstRoot, session_id: sessionId });
|
|
148
|
+
|
|
149
|
+
assertContext(run(JSON.stringify(action)), 'PreToolUse');
|
|
150
|
+
const secondWorkspaceAction = {
|
|
151
|
+
...action,
|
|
152
|
+
cwd: secondRoot,
|
|
153
|
+
workspace_identity_reset: true
|
|
154
|
+
};
|
|
155
|
+
assertContext(run(JSON.stringify(secondWorkspaceAction)), 'PreToolUse');
|
|
156
|
+
assertSilent(run(JSON.stringify(secondWorkspaceAction)));
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('unrelated events, missing ledgers and malformed input remain silent and exit zero', t => {
|
|
160
|
+
if (!fs.existsSync(ADAPTER)) return t.skip('adapter is absent at the pinned RED state');
|
|
161
|
+
const root = newWorkspace('with-ledger-controls');
|
|
162
|
+
const base = payload('pre-tool-use.json', { cwd: root, session_id: `hc-control-${process.pid}` });
|
|
163
|
+
assertSilent(run(JSON.stringify({ ...base, tool_input_command: 'git status' })));
|
|
164
|
+
assertSilent(run(JSON.stringify({ ...base, hook_event_name: 'PostToolUse' })));
|
|
165
|
+
assertSilent(run(JSON.stringify({ ...base, tool_name: 'Write' })));
|
|
166
|
+
assertSilent(run(JSON.stringify({ ...base, session_id: undefined })));
|
|
167
|
+
assertSilent(run(JSON.stringify({ ...base, cwd: undefined, session_id: `hc-missing-cwd-${process.pid}` })));
|
|
168
|
+
assertSilent(run(JSON.stringify({ ...base, cwd: '.', session_id: `hc-relative-cwd-${process.pid}` })));
|
|
169
|
+
|
|
170
|
+
const noLedger = path.join(TMP, `without-ledger-${++serial}`);
|
|
171
|
+
fs.mkdirSync(noLedger, { recursive: true });
|
|
172
|
+
assertSilent(run(JSON.stringify({ ...base, cwd: noLedger, session_id: `hc-no-ledger-${process.pid}` })));
|
|
173
|
+
assertSilent(run(JSON.stringify({ ...base, tool_input_command: undefined })));
|
|
174
|
+
assertSilent(run('{"hook_event_name":'));
|
|
175
|
+
assertSilent(run(JSON.stringify({ ...base, padding: 'x'.repeat(65_536) })));
|
|
176
|
+
});
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const assert = require('node:assert/strict');
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const os = require('node:os');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
const { spawnSync } = require('node:child_process');
|
|
9
|
+
const test = require('node:test');
|
|
10
|
+
const compat = require('../scripts/codex-hooks-compat');
|
|
11
|
+
|
|
12
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
13
|
+
const PLUGIN_ROOT = path.join(ROOT, 'plugins', 'harness-everything');
|
|
14
|
+
const ERRORS_SYNC = path.join(ROOT, 'scripts', 'errors-sync.js');
|
|
15
|
+
const LEDGER_DIR = path.join(ROOT, '.agents', 'harness-everything', 'errors');
|
|
16
|
+
const TEMP = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), '394 codex ledger ')));
|
|
17
|
+
const STATE_HOME = path.join(TEMP, 'state');
|
|
18
|
+
const E3_FILE = fs.readdirSync(LEDGER_DIR).find(file => /^E-0003-[a-z0-9-]+\.md$/.test(file));
|
|
19
|
+
const COMMITLINT_OUTPUT = fs.readFileSync(
|
|
20
|
+
path.join(ROOT, 'ci', 'fixtures', '394-ledger-match', 'commitlint-subject-case.txt'), 'utf8');
|
|
21
|
+
const FIXTURES = path.join(__dirname, 'fixtures', '394-codex-ledger-lesson');
|
|
22
|
+
const previousStateHome = process.env.HARNESS_STATE_HOME;
|
|
23
|
+
process.env.HARNESS_STATE_HOME = STATE_HOME;
|
|
24
|
+
|
|
25
|
+
test.after(() => {
|
|
26
|
+
if (previousStateHome === undefined) delete process.env.HARNESS_STATE_HOME;
|
|
27
|
+
else process.env.HARNESS_STATE_HOME = previousStateHome;
|
|
28
|
+
fs.rmSync(TEMP, { recursive: true, force: true });
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
function payload(name, workspaceRoot, sessionId) {
|
|
32
|
+
const value = JSON.parse(fs.readFileSync(path.join(FIXTURES, name), 'utf8'));
|
|
33
|
+
value.cwd = workspaceRoot;
|
|
34
|
+
value.session_id = sessionId;
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function workspace(name, { ledger = true } = {}) {
|
|
39
|
+
const root = path.join(TEMP, name);
|
|
40
|
+
fs.mkdirSync(path.join(root, '.git'), { recursive: true });
|
|
41
|
+
if (ledger) {
|
|
42
|
+
const recordDir = path.join(root, '.agents', 'harness-everything', 'errors');
|
|
43
|
+
fs.mkdirSync(recordDir, { recursive: true });
|
|
44
|
+
fs.copyFileSync(path.join(LEDGER_DIR, E3_FILE), path.join(recordDir, E3_FILE));
|
|
45
|
+
const generated = spawnSync(process.execPath, [ERRORS_SYNC, '--root', root], { cwd: ROOT, encoding: 'utf8' });
|
|
46
|
+
assert.equal(generated.status, 0, generated.stderr);
|
|
47
|
+
}
|
|
48
|
+
return fs.realpathSync.native(root);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function stagePlugin() {
|
|
52
|
+
const staged = path.join(TEMP, 'native-plugin');
|
|
53
|
+
fs.cpSync(PLUGIN_ROOT, staged, { recursive: true });
|
|
54
|
+
for (const [source, target] of [
|
|
55
|
+
['hooks/scripts/codex-ledger-lesson.js', 'hooks/scripts/codex-ledger-lesson.js'],
|
|
56
|
+
['hooks/scripts/lib/ledger-match.js', 'hooks/scripts/lib/ledger-match.js'],
|
|
57
|
+
['hooks/scripts/lib/codex-tool-outcome.js', 'hooks/scripts/lib/codex-tool-outcome.js'],
|
|
58
|
+
['hooks/scripts/lib/harness-state.js', 'hooks/scripts/lib/harness-state.js'],
|
|
59
|
+
['scripts/lib/workspace.js', 'scripts/lib/workspace.js'],
|
|
60
|
+
]) {
|
|
61
|
+
const destination = path.join(staged, target);
|
|
62
|
+
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
63
|
+
fs.copyFileSync(path.join(ROOT, source), destination);
|
|
64
|
+
}
|
|
65
|
+
return staged;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function registeredHook(pluginRoot, event) {
|
|
69
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(pluginRoot, 'hooks', 'hooks.json'), 'utf8'));
|
|
70
|
+
const group = manifest.hooks[event].find(entry => entry.matcher === 'Bash' &&
|
|
71
|
+
entry.hooks.some(hook => hook.command.includes('codex-ledger-lesson.js')));
|
|
72
|
+
assert.ok(group, `packaged ${event} Bash hook registers codex-ledger-lesson.js`);
|
|
73
|
+
assert.equal(group.hooks.length, 1, `${event} lesson carrier is an isolated hook`);
|
|
74
|
+
const hook = group.hooks[0];
|
|
75
|
+
assert.equal(hook.command, 'node "${PLUGIN_ROOT}/hooks/scripts/codex-ledger-lesson.js"');
|
|
76
|
+
assert.equal(hook.commandWindows, 'node "${PLUGIN_ROOT}\\hooks\\scripts\\codex-ledger-lesson.js"');
|
|
77
|
+
return hook;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function runScript(script, pluginRoot, input) {
|
|
81
|
+
const result = spawnSync(process.execPath, [script], {
|
|
82
|
+
cwd: input.cwd,
|
|
83
|
+
input: JSON.stringify(input),
|
|
84
|
+
encoding: 'utf8',
|
|
85
|
+
timeout: 10000,
|
|
86
|
+
env: { ...process.env, PLUGIN_ROOT: pluginRoot, HARNESS_STATE_HOME: STATE_HOME },
|
|
87
|
+
});
|
|
88
|
+
assert.ifError(result.error);
|
|
89
|
+
assert.equal(result.status, 0, result.stderr);
|
|
90
|
+
assert.equal(result.stderr, '', 'no-match and matched delivery are silent on stderr');
|
|
91
|
+
return result.stdout;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function runNative(pluginRoot, event, input) {
|
|
95
|
+
registeredHook(pluginRoot, event);
|
|
96
|
+
return runScript(path.join(pluginRoot, 'hooks', 'scripts', 'codex-ledger-lesson.js'), pluginRoot, input);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function runCompatibility(config, event, input) {
|
|
100
|
+
const group = config.hooks[event].find(entry => entry.matcher === 'Bash' &&
|
|
101
|
+
entry.hooks.some(hook => hook.command.includes('codex-ledger-lesson.js')));
|
|
102
|
+
assert.ok(group, `codex-hooks compatibility install registers ${event} Bash lesson hook`);
|
|
103
|
+
assert.equal(group.hooks.length, 1, `${event} compatibility lesson carrier is isolated`);
|
|
104
|
+
const hook = group.hooks[0];
|
|
105
|
+
const command = /^node "(.+)"$/.exec(hook.command);
|
|
106
|
+
assert.ok(command, hook.command);
|
|
107
|
+
assert.equal(hook.commandWindows, hook.command.replaceAll('/', '\\'));
|
|
108
|
+
return runScript(command[1], path.dirname(path.dirname(path.dirname(command[1]))), input);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function context(stdout, event) {
|
|
112
|
+
assert.ok(stdout, `${event} should carry a matching ledger lesson`);
|
|
113
|
+
const result = JSON.parse(stdout);
|
|
114
|
+
assert.deepEqual(Object.keys(result), ['hookSpecificOutput']);
|
|
115
|
+
assert.deepEqual(Object.keys(result.hookSpecificOutput), ['hookEventName', 'additionalContext']);
|
|
116
|
+
assert.equal(result.hookSpecificOutput.hookEventName, event);
|
|
117
|
+
assert.match(result.hookSpecificOutput.additionalContext, /A commit is rejected locally by commitlint/);
|
|
118
|
+
assert.match(result.hookSpecificOutput.additionalContext, /Consider a fresh look/);
|
|
119
|
+
assert.doesNotMatch(JSON.stringify(result), /permissionDecision|updatedInput|"decision"|"continue"/,
|
|
120
|
+
'lesson context does not alter tool permission or result flow');
|
|
121
|
+
return result.hookSpecificOutput.additionalContext;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function carrierRoundTrip(run, name) {
|
|
125
|
+
const root = workspace(`${name}-workspace`);
|
|
126
|
+
const firstAction = payload('pre-tool-use.json', root, `${name}-session-a`);
|
|
127
|
+
const originalPayload = JSON.stringify(firstAction);
|
|
128
|
+
const actionContext = context(run('PreToolUse', firstAction), 'PreToolUse');
|
|
129
|
+
assert.ok(actionContext.includes('Lesson:'), 'action context carries the canonical E-0003 lesson');
|
|
130
|
+
assert.equal(fs.readFileSync(path.join(FIXTURES, 'pre-tool-use.json'), 'utf8').includes(root), false,
|
|
131
|
+
'test workspace state is isolated from the checked-in payload template');
|
|
132
|
+
assert.equal(run('PreToolUse', firstAction), '', 'repeated action context is deduplicated');
|
|
133
|
+
assert.equal(JSON.stringify(firstAction), originalPayload, 'the input action and permission fields remain unchanged');
|
|
134
|
+
|
|
135
|
+
const failure = payload('post-tool-use-failure.json', root, `${name}-session-a`);
|
|
136
|
+
failure.tool_input.command = firstAction.tool_input.command;
|
|
137
|
+
failure.tool_response.stderr = COMMITLINT_OUTPUT;
|
|
138
|
+
context(run('PostToolUse', failure), 'PostToolUse');
|
|
139
|
+
assert.equal(run('PostToolUse', failure), '', 'repeated failure context is deduplicated');
|
|
140
|
+
|
|
141
|
+
const prefixedAction = payload('pre-tool-use.json', root, `${name}-session-prefixed`);
|
|
142
|
+
prefixedAction.tool_input.command = 'git -C x commit -m "Docs: rejected subject"';
|
|
143
|
+
context(run('PreToolUse', prefixedAction), 'PreToolUse');
|
|
144
|
+
const prefixedFailure = payload('post-tool-use-failure.json', root, `${name}-session-prefixed`);
|
|
145
|
+
prefixedFailure.tool_input.command = prefixedAction.tool_input.command;
|
|
146
|
+
prefixedFailure.tool_response.stderr = COMMITLINT_OUTPUT;
|
|
147
|
+
context(run('PostToolUse', prefixedFailure), 'PostToolUse');
|
|
148
|
+
|
|
149
|
+
const anotherSession = payload('pre-tool-use.json', root, `${name}-session-b`);
|
|
150
|
+
context(run('PreToolUse', anotherSession), 'PreToolUse');
|
|
151
|
+
|
|
152
|
+
const anotherWorkspace = workspace(`${name}-other-workspace`);
|
|
153
|
+
const otherWorkspaceAction = payload('pre-tool-use.json', anotherWorkspace, `${name}-other-session`);
|
|
154
|
+
context(run('PreToolUse', otherWorkspaceAction), 'PreToolUse');
|
|
155
|
+
|
|
156
|
+
const noLedger = workspace(`${name}-no-ledger`, { ledger: false });
|
|
157
|
+
const unrelatedWorkspace = payload('pre-tool-use.json', noLedger, `${name}-no-ledger-session`);
|
|
158
|
+
assert.equal(run('PreToolUse', unrelatedWorkspace), '', 'missing workspace ledger produces no context');
|
|
159
|
+
const missingSession = payload('pre-tool-use.json', root, `${name}-missing-session`);
|
|
160
|
+
delete missingSession.session_id;
|
|
161
|
+
assert.equal(run('PreToolUse', missingSession), '', 'missing session identity never falls back to shared state');
|
|
162
|
+
const missingWorkspace = payload('pre-tool-use.json', root, `${name}-missing-workspace`);
|
|
163
|
+
delete missingWorkspace.cwd;
|
|
164
|
+
assert.equal(run('PreToolUse', missingWorkspace), '', 'missing workspace never falls back to the adapter checkout');
|
|
165
|
+
|
|
166
|
+
const oversized = payload('pre-tool-use.json', root, `${name}-oversized-session`);
|
|
167
|
+
oversized.unused_large_field = 'x'.repeat(129 * 1024);
|
|
168
|
+
assert.equal(run('PreToolUse', oversized), '', 'oversized hook payload is bounded and fails open');
|
|
169
|
+
|
|
170
|
+
const success = payload('post-tool-use-success.json', root, `${name}-success-session`);
|
|
171
|
+
success.tool_response.stderr = COMMITLINT_OUTPUT;
|
|
172
|
+
assert.equal(run('PostToolUse', success), '', 'successful exit stays silent even with diagnostic-looking output');
|
|
173
|
+
|
|
174
|
+
const unknown = payload('post-tool-use-unknown.json', root, `${name}-unknown-session`);
|
|
175
|
+
unknown.tool_response.stderr = COMMITLINT_OUTPUT;
|
|
176
|
+
assert.equal(run('PostToolUse', unknown), '', 'unknown exit stays silent despite commitlint-looking output');
|
|
177
|
+
|
|
178
|
+
const unrelatedFailure = payload('post-tool-use-failure.json', root, `${name}-unrelated-session`);
|
|
179
|
+
unrelatedFailure.tool_response.stderr = 'fatal: not a git repository';
|
|
180
|
+
assert.equal(run('PostToolUse', unrelatedFailure), '', 'unrelated failed command output stays silent');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
test('Codex packaged and user-hook carriers deliver E-0003 without changing tool flow', () => {
|
|
184
|
+
registeredHook(PLUGIN_ROOT, 'PreToolUse');
|
|
185
|
+
const stagedPlugin = stagePlugin();
|
|
186
|
+
const preToolUse = registeredHook(stagedPlugin, 'PreToolUse');
|
|
187
|
+
const postToolUse = registeredHook(stagedPlugin, 'PostToolUse');
|
|
188
|
+
assert.ok(preToolUse && postToolUse);
|
|
189
|
+
carrierRoundTrip((event, input) => runNative(stagedPlugin, event, input), 'native');
|
|
190
|
+
|
|
191
|
+
const codexHome = path.join(TEMP, 'codex-home');
|
|
192
|
+
fs.mkdirSync(codexHome, { recursive: true });
|
|
193
|
+
const configFile = path.join(codexHome, 'config.toml');
|
|
194
|
+
fs.writeFileSync(configFile, 'model = "fixture"\n', 'utf8');
|
|
195
|
+
const configBefore = fs.readFileSync(configFile, 'utf8');
|
|
196
|
+
const installed = compat.install({ allowUnreleasedSource: true, codexHome, sourcePluginRoot: stagedPlugin });
|
|
197
|
+
assert.equal(installed.status, 'installed');
|
|
198
|
+
assert.equal(installed.trustChanged, false, 'compatibility install does not change Codex hook trust');
|
|
199
|
+
const hooksFile = path.join(codexHome, 'hooks.json');
|
|
200
|
+
const config = JSON.parse(fs.readFileSync(hooksFile, 'utf8'));
|
|
201
|
+
assert.equal(fs.readFileSync(configFile, 'utf8'), configBefore, 'config.toml stays byte-identical');
|
|
202
|
+
carrierRoundTrip((event, input) => runCompatibility(config, event, input), 'compat');
|
|
203
|
+
});
|