harness-everything 0.54.0 → 0.55.0

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 (72) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +2 -1
  3. package/CHANGELOG.md +25 -0
  4. package/README.md +1 -0
  5. package/ci/action-gate.test.js +1 -1
  6. package/ci/mechanism-2at-fable-execution-phases.test.js +38 -0
  7. package/ci/mechanism-codex-hook-results.test.js +145 -0
  8. package/ci/mechanism-error-ledger-oracle.test.js +222 -0
  9. package/ci/mechanism-error-ledger-promote.test.js +520 -0
  10. package/ci/mechanism-error-ledger-scan.test.js +640 -0
  11. package/ci/mechanism-errors-sync-root.test.js +215 -0
  12. package/ci/openai-plugin-package.test.js +1 -1
  13. package/ci/openai-plugin-runtime.test.js +2 -1
  14. package/ci/prompt-contract-regressions.test.js +6 -2
  15. package/docs/platform-capabilities.md +17 -0
  16. package/docs/workflows/error-ledger-bootstrap.md +23 -0
  17. package/error-ledger-bootstrap/SKILL.md +33 -0
  18. package/error-ledger-bootstrap/references/workflow.md +79 -0
  19. package/error-ledger-bootstrap/scripts/promote.js +613 -0
  20. package/error-ledger-bootstrap/scripts/scan.js +654 -0
  21. package/evals/error-ledger-bootstrap/eval.yaml +26 -0
  22. package/evals/error-ledger-bootstrap/tasks/negative-error-handling-map.yaml +16 -0
  23. package/evals/error-ledger-bootstrap/tasks/negative-trigger.yaml +16 -0
  24. package/evals/error-ledger-bootstrap/tasks/positive-trigger.yaml +15 -0
  25. package/fable-mode/SKILL.md +5 -5
  26. package/fable-mode/execution-guardrails/SKILL.md +1 -1
  27. package/fable-mode/fable-haiku/SKILL.md +1 -1
  28. package/fable-mode/fable-opus/SKILL.md +1 -1
  29. package/fable-mode/fable-sonnet/SKILL.md +1 -1
  30. package/fable-mode/references/execution-phases.md +26 -4
  31. package/harness-everything/SKILL.md +1 -1
  32. package/harness-everything/references/skill-registry.md +1 -0
  33. package/harness-everything/scripts/routing-keywords.json +11 -0
  34. package/hooks/scripts/action-gate.js +5 -0
  35. package/hooks/scripts/codex-action-gate-post.js +3 -12
  36. package/hooks/scripts/contract-test.js +17 -7
  37. package/hooks/scripts/lib/codex-tool-outcome.js +28 -0
  38. package/hooks/scripts/rule-of-3-tracker.js +11 -4
  39. package/hooks/scripts/state-persist.js +15 -9
  40. package/hooks/scripts/subagent-scope-guard.js +32 -25
  41. package/hooks/scripts/subagent-start.js +1 -1
  42. package/hooks/scripts/subagent-stop.js +14 -3
  43. package/opencode-plugin/plugin.json +1 -1
  44. package/package.json +1 -1
  45. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  46. package/plugins/harness-everything/hooks/hooks.json +6 -6
  47. package/plugins/harness-everything/hooks/scripts/action-gate.js +5 -0
  48. package/plugins/harness-everything/hooks/scripts/codex-action-gate-post.js +3 -12
  49. package/plugins/harness-everything/hooks/scripts/contract-test.js +17 -7
  50. package/plugins/harness-everything/hooks/scripts/lib/codex-tool-outcome.js +28 -0
  51. package/plugins/harness-everything/hooks/scripts/rule-of-3-tracker.js +11 -4
  52. package/plugins/harness-everything/hooks/scripts/state-persist.js +15 -9
  53. package/plugins/harness-everything/hooks/scripts/subagent-scope-guard.js +32 -25
  54. package/plugins/harness-everything/hooks/scripts/subagent-start.js +1 -1
  55. package/plugins/harness-everything/hooks/scripts/subagent-stop.js +14 -3
  56. package/plugins/harness-everything/plugin.json +1 -1
  57. package/plugins/harness-everything/skills/error-ledger-bootstrap/SKILL.md +33 -0
  58. package/plugins/harness-everything/skills/error-ledger-bootstrap/references/workflow.md +79 -0
  59. package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/promote.js +613 -0
  60. package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/scan.js +654 -0
  61. package/plugins/harness-everything/skills/fable-mode/SKILL.md +5 -5
  62. package/plugins/harness-everything/skills/fable-mode/execution-guardrails/SKILL.md +1 -1
  63. package/plugins/harness-everything/skills/fable-mode/fable-haiku/SKILL.md +1 -1
  64. package/plugins/harness-everything/skills/fable-mode/fable-opus/SKILL.md +1 -1
  65. package/plugins/harness-everything/skills/fable-mode/fable-sonnet/SKILL.md +1 -1
  66. package/plugins/harness-everything/skills/fable-mode/references/execution-phases.md +26 -4
  67. package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
  68. package/plugins/harness-everything/skills/harness-everything/references/skill-registry.md +1 -0
  69. package/plugins/harness-everything/skills/harness-everything/scripts/routing-keywords.json +11 -0
  70. package/sbom.cdx.json +7 -7
  71. package/scripts/error-ledger-oracle.js +257 -0
  72. package/scripts/errors-sync.js +175 -12
@@ -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.54.0",
13
+ "version": "0.55.0",
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.54.0",
4
+ "version": "0.55.0",
5
5
  "author": {
6
6
  "name": "Miya Daniel"
7
7
  },
@@ -24,6 +24,7 @@
24
24
  "skills": [
25
25
  "./multi-agent-workspace",
26
26
  "./code-review",
27
+ "./error-ledger-bootstrap",
27
28
  "./environment-detection",
28
29
  "./eval-harness",
29
30
  "./fable-discipline",
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  All notable changes to this project are documented in this file.
4
4
 
5
+ ## [0.55.0](https://github.com/dyphn1/Harness-everything/compare/v0.54.1...v0.55.0) (2026-11-20)
6
+
7
+ ### Features
8
+
9
+ * **errors:** add a local scanner for ledger bootstrap candidates ([b34be38](https://github.com/dyphn1/Harness-everything/commit/b34be38145348176c63f0faf26fd071115e1485f)), closes [#479](https://github.com/dyphn1/Harness-everything/issues/479)
10
+ * **errors:** add the error-ledger-bootstrap skill with routing eval ([71e64c3](https://github.com/dyphn1/Harness-everything/commit/71e64c3ba691b2c5f3c8647976c46a27a9916445)), closes [#479](https://github.com/dyphn1/Harness-everything/issues/479)
11
+ * **errors:** promote an owner-approved candidate into a target ledger ([7c8b672](https://github.com/dyphn1/Harness-everything/commit/7c8b6723f0120559805fddf9e54ea8eb8e2e8a86)), closes [#479](https://github.com/dyphn1/Harness-everything/issues/479)
12
+ * **errors:** scan repeated doc fixes and offline tracker exports ([5e36882](https://github.com/dyphn1/Harness-everything/commit/5e368829464abe8f5f66129045fe685f31ae5950)), closes [#479](https://github.com/dyphn1/Harness-everything/issues/479)
13
+ * **errors:** sync the ledger index of a target repository with --root ([0973bec](https://github.com/dyphn1/Harness-everything/commit/0973bec75a0f45b4cd4de0c9ef158c75f0186ed5)), closes [#479](https://github.com/dyphn1/Harness-everything/issues/479)
14
+
15
+ ### Bug Fixes
16
+
17
+ * **errors:** close the pr 483 owner review findings ([7e35a65](https://github.com/dyphn1/Harness-everything/commit/7e35a6574bd450ebe67e866a555ad8bfd15c355d))
18
+ * **errors:** confine ledger index writes to the target ledger ([410231c](https://github.com/dyphn1/Harness-everything/commit/410231c88addb1ce8ce6666784aa05c926709d8e)), closes [#479](https://github.com/dyphn1/Harness-everything/issues/479)
19
+ * **errors:** keep private memory labels opaque in bootstrap reports ([c61f080](https://github.com/dyphn1/Harness-everything/commit/c61f08060193bb4030c21f310e197e5012b7800c)), closes [#479](https://github.com/dyphn1/Harness-everything/issues/479)
20
+ * **errors:** label the oracle unmatched share as a path-overlap proxy ([79cb92c](https://github.com/dyphn1/Harness-everything/commit/79cb92c81fae064a60c11c8bb2dc3b2868800be9)), closes [#479](https://github.com/dyphn1/Harness-everything/issues/479)
21
+
22
+ ## [0.54.1](https://github.com/dyphn1/Harness-everything/compare/v0.54.0...v0.54.1) (2026-11-20)
23
+
24
+ ### Bug Fixes
25
+
26
+ * **codex:** handle hook outcomes and subagent warnings ([420b36f](https://github.com/dyphn1/Harness-everything/commit/420b36f4f21e32d1ce416abbcda0c239a4ee0a8b))
27
+ * **fable:** move planning rules into execution phases and relax the prompt contract pin ([149bc78](https://github.com/dyphn1/Harness-everything/commit/149bc785ee9575c839f15a50ecb73606be0d3b0e)), closes [#476](https://github.com/dyphn1/Harness-everything/issues/476)
28
+ * **fable:** restore quoted skill description within the token budget ([7935939](https://github.com/dyphn1/Harness-everything/commit/7935939f4455ba4c885f8cfaa4b3bbb4de3a5ee5))
29
+
5
30
  ## [0.54.0](https://github.com/dyphn1/Harness-everything/compare/v0.53.0...v0.54.0) (2026-11-19)
6
31
 
7
32
  ### Features
package/README.md CHANGED
@@ -239,6 +239,7 @@ This repo uses a flat layout (waza/agentskills.io convention). The table below m
239
239
  | `references` | **Documentation** | Shared checklists (security, performance, definition-of-done) |
240
240
  | `multi-agent-workspace` | **Skill (Tier 3)** | Scaffold a verified multi-agent workspace and select bounded specialists from an external catalog without vendoring the full roster |
241
241
  | `code-review` | **Skill (Tier 2)** | Independent, evidence-tiered PR/diff code review (read-only by default) |
242
+ | `error-ledger-bootstrap` | **Skill (Tier 2)** | Inventory local lessons and promote owner-approved error-ledger entries |
242
243
  | `environment-detection` | **Foundation** | Preflight: detect OS, shell, package manager |
243
244
  | `eval-harness` | **Skill (Tier 2)** | Evaluate agent outputs against rubrics |
244
245
  | `fable-discipline` | **Skill (Tier 3)** | Fable execution guardrails when Fable is selected |
@@ -348,7 +348,7 @@ try {
348
348
  check(pluginPost && pluginPost.hooks.some(hook => /codex-action-gate-post\.js/.test(hook.command)), 'Codex plugin infers action-gate outcome from supported PostToolUse');
349
349
  check(codexPost.inferOutcome({ tool_response: { exitCode: 0 } }) === 'success', 'Codex PostToolUse maps zero exit code to success');
350
350
  check(codexPost.inferOutcome({ tool_response: { exit_code: 2, stderr: 'failed' } }) === 'failure', 'Codex PostToolUse maps non-zero exit code to failure');
351
- check(codexPost.inferOutcome({ tool_response: { stderr: 'fatal: denied' } }) === 'failure', 'Codex PostToolUse conservatively recognizes failure stderr without exit code');
351
+ check(codexPost.inferOutcome({ tool_response: { stderr: 'fatal: denied' } }) === 'unknown', 'Codex PostToolUse treats stderr without a structured status as unknown');
352
352
  check(pluginHooks.hooks.Stop.some(group => group.hooks.some(hook => /action-gate\.js/.test(hook.command))), 'OpenAI plugin closes pending approvals at Stop');
353
353
 
354
354
  check(fs.readFileSync(rulesPath, 'utf8') === fs.readFileSync(pluginRules, 'utf8'), 'canonical and plugin action-gate rule tables are byte-identical');
@@ -5,6 +5,8 @@ const fs = require('fs');
5
5
  const path = require('path');
6
6
 
7
7
  const ROOT = path.resolve(__dirname, '..');
8
+ const skill = fs.readFileSync(path.join(ROOT, 'fable-mode/SKILL.md'), 'utf8');
9
+ const packagedSkill = fs.readFileSync(path.join(ROOT, 'plugins/harness-everything/skills/fable-mode/SKILL.md'), 'utf8');
8
10
  const guide = fs.readFileSync(path.join(ROOT, 'fable-mode/references/execution-phases.md'), 'utf8');
9
11
  const packagedGuide = fs.readFileSync(path.join(ROOT, 'plugins/harness-everything/skills/fable-mode/references/execution-phases.md'), 'utf8');
10
12
  const contract = fs.readFileSync(path.join(ROOT, 'fable-mode/CONTRACT-FORMAT.md'), 'utf8');
@@ -43,4 +45,40 @@ assert.match(guide, /explicit user or\s+host runtime choice/i);
43
45
  assert.doesNotMatch(guide, /Resolve requested model|Opus macro work|do not silently change models/i);
44
46
  assert.match(guide.slice(legacyStart), /`\.claude\/harness-everything\/state\/contracts\//);
45
47
 
48
+ const workflow = skill.split('## Workflow\n')[1];
49
+ assert.strictEqual(packagedSkill, skill, 'OpenAI package includes the canonical Fable workflow');
50
+ const routing = [
51
+ '## USE FOR:',
52
+ '- Large multi-file, multi-source, or multi-session work',
53
+ '- Fable profile explanations or explicit Fable execution requests',
54
+ '- Work needing named delegation and cold verification',
55
+ '',
56
+ '## DO NOT USE FOR:',
57
+ '- One obvious single-pass edit',
58
+ '- Ordinary Tier 2 implementation or bugfix work',
59
+ '',
60
+ '## Select Operation First',
61
+ ].join('\n');
62
+ assert.ok(skill.includes(routing), 'the existing Fable routing text is preserved');
63
+ assert.match(workflow, /^1\. Discover the runtime and lock the authorized file scope before edits\.$/m);
64
+ assert.ok(skill.includes('Execution only: stage checklist and audit records.'));
65
+ assert.match(skill, /Execution: `<this-skill-dir>\/scripts\/model-selector\.js`, stage contracts, and `<skills-repo-root>\/harness-everything\/scripts\/verify-gate\.js`\./);
66
+ assert.ok(skill.includes('For explanation/profile-only lookup, read only `<this-skill-dir>/references/profile-lookup.md` and answer. No stage state, delegation, or selector source reads. Quoted aliases do not start Fable. Mixed execution retains its topology; execution follows the workflow below.'));
67
+ assert.match(workflow, /^4\. Delegate by profile: orchestrator coordinates, reasoning takes bounded judgment, mechanical takes low-ambiguity work; workers never spawn workers\./m);
68
+ assert.match(workflow, /^5\. The host runtime-model floor is advisory; record it, never block on model choice alone\.$/m);
69
+ assert.match(workflow, /^6\. .*Run stage checks, cold-review high-stakes artifacts, and audit profile\/runtime\/fallback fields\.$/m);
70
+ const handoffReference = '`<this-skill-dir>/references/execution-phases.md#verification-and-handoff`'; // portability-lint: allow markdown text to match, never a path
71
+ assert.ok(workflow.includes(`4. Delegate by profile: orchestrator coordinates, reasoning takes bounded judgment, mechanical takes low-ambiguity work; workers never spawn workers. Before Codex dispatch, load/apply ${handoffReference}.`),
72
+ 'step 4 requires loading and applying the verification-and-handoff reference before Codex subagent dispatch');
73
+ assert.ok(workflow.includes(`6. On every Codex handoff or silent stop, load/apply ${handoffReference} before accepting results or releasing dependent stages. Run stage checks, cold-review high-stakes artifacts, and audit profile/runtime/fallback fields.`),
74
+ 'step 6 requires loading and applying the verification-and-handoff reference at every handoff before accepting results or releasing dependent stages');
75
+ assert.match(workflow, /^2\. Plan via `<this-skill-dir>\/references\/execution-phases\.md`\.$/m);
76
+ assert.match(workflow, /^3\. Use `model-selector\.js`\.$/m);
77
+ assert.match(guide, /^## Verification and handoff$/m, 'the explicit handoff target heading exists');
78
+ const handoff = guide.split(/\r?\n## Verification and handoff\r?\n/)[1];
79
+ assert.ok(handoff, 'the dispatch reference contains Verification and handoff');
80
+ assert.match(handoff, /coordinator MUST reconcile scope before accepting a\nresult or using it in a dependent stage/);
81
+ assert.match(handoff, /Before dispatch, capture the worker worktree's starting state/);
82
+ assert.match(handoff, /Run this check after every handoff, including silent stops\./);
83
+
46
84
  console.log('PASS Fable execution phases match the active workflow contract and preserve a scoped legacy fallback');
@@ -0,0 +1,145 @@
1
+ 'use strict';
2
+
3
+ const assert = require('node:assert/strict');
4
+ const fs = require('node:fs');
5
+ const os = require('node:os');
6
+ const path = require('node:path');
7
+ const { spawnSync } = require('node:child_process');
8
+
9
+ const root = path.resolve(__dirname, '..');
10
+ const pluginRoot = path.join(root, 'plugins', 'harness-everything');
11
+ const manifest = require('../plugins/harness-everything/hooks/hooks.json');
12
+ const { getSessionDir, getStateRoot } = require('../hooks/scripts/lib/harness-state');
13
+
14
+ function registeredHook(event, script) {
15
+ const handler = manifest.hooks[event].flatMap(group => group.hooks)
16
+ .find(hook => hook.command.includes('/' + script + '"'));
17
+ assert.ok(handler, script + ' is registered');
18
+ const match = /^node "\$\{PLUGIN_ROOT\}\/([^"]+)"( --codex)?$/.exec(handler.command);
19
+ assert.ok(match, handler.command);
20
+ assert.equal(handler.commandWindows,
21
+ 'node "${PLUGIN_ROOT}\\' + match[1].replaceAll('/', '\\') + '"' + (match[2] || ''));
22
+ return match[2] ? [match[1], '--codex'] : [match[1]];
23
+ }
24
+
25
+ function spawn(executable, args, cwd, input) {
26
+ const result = spawnSync(executable, args, { cwd, input, encoding: 'utf8', timeout: 10000 });
27
+ assert.ifError(result.error);
28
+ assert.equal(result.status, 0, result.stderr);
29
+ return result;
30
+ }
31
+
32
+ const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-codex-hook-results-'));
33
+ process.env.HARNESS_STATE_HOME = path.join(temp, 'state');
34
+ delete process.env.HARNESS_DOC_RECONCILIATION_PILOT;
35
+
36
+ try {
37
+ for (const layout of [root, pluginRoot]) {
38
+ const label = layout === root ? 'source' : 'package';
39
+ const cwd = path.join(temp, 'workspace ' + label);
40
+ const session_id = 'codex-result-' + label;
41
+ fs.mkdirSync(cwd);
42
+ spawn('git', ['init', '-q'], cwd);
43
+
44
+ function hook(event, script, fields = {}) {
45
+ const [relative, ...args] = registeredHook(event, script);
46
+ return spawn(process.execPath, [path.join(layout, relative), ...args], cwd,
47
+ JSON.stringify({ hook_event_name: event, cwd, session_id, ...fields }));
48
+ }
49
+
50
+ const session = getSessionDir(cwd, session_id);
51
+ const checkCommand = 'npm test';
52
+ const shell = { tool_name: 'Bash', tool_input: { command: checkCommand } };
53
+
54
+ const runRoot = path.join(getStateRoot(cwd), 'fable-runs', 'result-run');
55
+ const contract = path.join(runRoot, 'contracts', 'check.json');
56
+ const evidence = path.join(runRoot, 'evidence', 'check.json');
57
+ fs.mkdirSync(path.dirname(contract), { recursive: true });
58
+ fs.writeFileSync(contract, JSON.stringify({
59
+ schemaVersion: 2, planId: 'result-plan', runId: 'result-run', stageId: 'check',
60
+ sessionId: session_id, status: 'pending', checkCommand,
61
+ }));
62
+ function read(file) { return JSON.parse(fs.readFileSync(file, 'utf8')); }
63
+ function post(response) {
64
+ for (const script of ['state-persist.js', 'rule-of-3-tracker.js', 'contract-test.js']) {
65
+ hook('PostToolUse', script, { ...shell, tool_response: response });
66
+ }
67
+ }
68
+
69
+ const handoff = path.join(session, 'handoff-state.json');
70
+ const tracker = path.join(session, 'rule-of-3-state.json');
71
+ post({ exit_code: 1, stderr: 'test failed' });
72
+ assert.equal(read(handoff).status, 'failed');
73
+ assert.equal(read(tracker).count, 1);
74
+ assert.equal(read(contract).status, 'fail');
75
+ function evidenceSnapshot() {
76
+ // Test commands can themselves write files, so the edit timestamp is
77
+ // independent of whether the host confirmed success.
78
+ const { lastEditAt, ...verification } = read(handoff);
79
+ return [verification, ...[tracker, contract, evidence].map(read)];
80
+ }
81
+ const snapshots = evidenceSnapshot();
82
+
83
+ for (const ambiguous of [
84
+ undefined, null, [], { stdout: { exitCode: 0 } }, { exitCode: '0' },
85
+ { success: true }, 'Process exited with code 0\nOutput:\nanything',
86
+ ]) {
87
+ post(ambiguous);
88
+ assert.deepEqual(evidenceSnapshot(), snapshots);
89
+ }
90
+
91
+ post({ exitCode: 0, stderr: 'benign test warning' });
92
+ assert.equal(read(handoff).status, 'idle');
93
+ assert.ok(read(handoff).lastVerifyAt > 0);
94
+ assert.equal(read(tracker).count, 0);
95
+ assert.equal(read(contract).status, 'pass');
96
+
97
+ const priorEdit = read(handoff).lastEditAt;
98
+ const edits = hook('PostToolUse', 'state-persist.js', {
99
+ tool_name: 'Bash', tool_input: { command: 'echo changed > generated.txt' },
100
+ tool_response: 'opaque',
101
+ });
102
+ assert.equal(edits.stdout, '');
103
+ assert.ok(read(handoff).lastEditAt > priorEdit);
104
+
105
+ const { inferOutcome } = require(path.join(layout, 'hooks/scripts/codex-action-gate-post.js'));
106
+ assert.equal(inferOutcome({ ...shell, tool_response: 'done' }), 'unknown');
107
+ assert.equal(inferOutcome({ ...shell, tool_response: { stderr: 'error' } }), 'unknown');
108
+ assert.equal(inferOutcome({ ...shell, tool_response: { exitCode: 0, isError: true } }), 'failure');
109
+ assert.equal(inferOutcome({ tool_name: 'mcp__repo__update', tool_response: { isError: false } }), 'success');
110
+
111
+ const tool_use_id = 'gated-mcp-result';
112
+ const gated = {
113
+ host: 'codex', tool_use_id, tool_name: 'mcp__codex_apps__github__update_pull_request',
114
+ tool_input: { repository_full_name: 'example/repo', pr_number: 7, body: 'test fixture' },
115
+ };
116
+ hook('PreToolUse', 'codex-action-gate-pre.js', gated);
117
+ const audit = path.join(session, 'action-gate', tool_use_id + '.json');
118
+ hook('PostToolUse', 'codex-action-gate-post.js', { ...gated, tool_response: 'opaque' });
119
+ assert.equal(read(audit).executionOutcome, 'unknown');
120
+ hook('PostToolUse', 'codex-action-gate-post.js', { ...gated, tool_response: { exitCode: 1 } });
121
+ assert.equal(read(audit).executionOutcome, 'failure');
122
+ hook('PostToolUse', 'codex-action-gate-post.js', { ...gated, tool_response: 'opaque' });
123
+ assert.equal(read(audit).executionOutcome, 'failure');
124
+
125
+ const worker = { agent_id: 'worker-1', agent_type: 'default' };
126
+ hook('SubagentStart', 'subagent-start.js', worker);
127
+ const clean = hook('SubagentStop', 'subagent-stop.js', worker);
128
+ assert.equal(clean.stdout, '');
129
+ assert.equal(clean.stderr, '');
130
+ fs.writeFileSync(path.join(cwd, 'unexpected.txt'), 'change\n');
131
+ const changed = hook('SubagentStop', 'subagent-stop.js', worker);
132
+ const warning = JSON.parse(changed.stdout);
133
+ assert.deepEqual(Object.keys(warning), ['systemMessage']);
134
+ assert.match(warning.systemMessage, /unexpected\.txt/);
135
+ assert.equal(changed.stderr, '');
136
+ const scopeAudit = path.join(session, 'subagent-scope-last.json');
137
+ assert.equal(read(scopeAudit).outOfScope.length, 1);
138
+ assert.equal(hook('SubagentStop', 'subagent-stop.js', worker).stdout, '');
139
+ assert.deepEqual(read(scopeAudit).outOfScope, []);
140
+ assert.equal(fs.readFileSync(path.join(cwd, 'unexpected.txt'), 'utf8'), 'change\n');
141
+ console.log('PASS Codex ' + label + ' outcome and advisory SubagentStop contracts');
142
+ }
143
+ } finally {
144
+ fs.rmSync(temp, { recursive: true, force: true });
145
+ }
@@ -0,0 +1,222 @@
1
+ 'use strict';
2
+
3
+ const assert = require('node:assert/strict');
4
+ const childProcess = require('node:child_process');
5
+ const crypto = require('node:crypto');
6
+ const fs = require('node:fs');
7
+ const os = require('node:os');
8
+ const path = require('node:path');
9
+
10
+ const ROOT = path.resolve(__dirname, '..');
11
+ const SCRIPT = path.join(ROOT, 'scripts', 'error-ledger-oracle.js');
12
+ const TMP = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'harness-error-ledger-oracle-')));
13
+ process.on('exit', () => fs.rmSync(TMP, { recursive: true, force: true }));
14
+
15
+ function write(file, value) {
16
+ fs.mkdirSync(path.dirname(file), { recursive: true });
17
+ fs.writeFileSync(file, value);
18
+ }
19
+
20
+ function makeFixture(name, records, candidates) {
21
+ const root = path.join(TMP, name);
22
+ const ledger = path.join(root, 'errors');
23
+ const report = path.join(root, 'scan-report.json');
24
+ fs.mkdirSync(ledger, { recursive: true });
25
+ for (const record of records) {
26
+ const sites = record.sites.map(site => ` - ${JSON.stringify(site)}`).join('\n');
27
+ write(path.join(ledger, `${record.id}-fixture.md`), [
28
+ '---', `id: ${record.id}`, 'sites:', sites, '---',
29
+ '', record.lesson || `PRIVATE_RECORD_BODY_${record.id}`, ''
30
+ ].join('\n'));
31
+ }
32
+ write(report, `${JSON.stringify({
33
+ schemaVersion: 1,
34
+ candidates: candidates.map(candidate => ({
35
+ kind: 'error-candidate',
36
+ id: candidate.id,
37
+ title: candidate.title || `PRIVATE_CANDIDATE_TITLE_${candidate.id}`,
38
+ sites: candidate.sites,
39
+ sources: [{ type: 'memory', title: 'PRIVATE_MEMORY_SOURCE_TITLE' }]
40
+ }))
41
+ }, null, 2)}\n`);
42
+ return { root, ledger, report };
43
+ }
44
+
45
+ function snapshot(dir) {
46
+ const entries = [];
47
+ function visit(current, relative = '') {
48
+ for (const entry of fs.readdirSync(current, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
49
+ const child = path.join(current, entry.name);
50
+ const childRelative = path.join(relative, entry.name);
51
+ if (entry.isDirectory()) visit(child, childRelative);
52
+ else entries.push([childRelative, crypto.createHash('sha256').update(fs.readFileSync(child)).digest('hex')]);
53
+ }
54
+ }
55
+ visit(dir);
56
+ return entries;
57
+ }
58
+
59
+ function run(fixture, options = []) {
60
+ const env = { ...process.env, HOME: TMP, USERPROFILE: TMP };
61
+ delete env.HARNESS_SYSTEM_ONE_MODE;
62
+ const result = childProcess.spawnSync(process.execPath, [
63
+ SCRIPT, '--report', fixture.report, '--ledger', fixture.ledger, ...options
64
+ ], { cwd: ROOT, encoding: 'utf8', env });
65
+ assert.ifError(result.error);
66
+ return result;
67
+ }
68
+
69
+ function jsonResult(result, expectedStatus = 0) {
70
+ assert.strictEqual(result.status, expectedStatus,
71
+ `oracle exit ${result.status}; expected ${expectedStatus}; stderr: ${result.stderr}`);
72
+ if (expectedStatus === 0) assert.strictEqual(result.stderr, '', 'successful oracle runs do not write stderr');
73
+ return expectedStatus === 0 ? JSON.parse(result.stdout) : null;
74
+ }
75
+
76
+ const fixture = makeFixture('main', [
77
+ { id: 'E-0001', sites: ['parser/parser.js (PR #448 branch; not on main at bd986013)'] },
78
+ { id: 'E-0002', sites: ['dir-only'] },
79
+ { id: 'E-0003', sites: ['boundary/a/bc.js'] },
80
+ { id: 'E-0004', sites: ['/private/absolute.js (PR #448)', 'C:\\private\\absolute.js', '../outside.js', 'https://example.invalid/a/path'] },
81
+ { id: 'E-0005', sites: ['shared/file.js'] },
82
+ { id: 'E-0006', sites: ['shared/file.js'] },
83
+ { id: 'E-0007', sites: ['other/never.js'] },
84
+ { id: 'E-0008', sites: ['parent/child.js'] }
85
+ ], [
86
+ { id: 'candidate-exact', sites: ['./parser\\parser.js'] },
87
+ { id: 'candidate-child', sites: ['dir-only/sub/module.js'] },
88
+ { id: 'candidate-boundary', sites: ['boundary/a/b'] },
89
+ { id: 'candidate-shared', sites: ['shared/file.js'] },
90
+ { id: 'candidate-parent', sites: ['parent'] }
91
+ ]);
92
+
93
+ const ledgerBefore = snapshot(fixture.ledger);
94
+ const reportBefore = fs.readFileSync(fixture.report);
95
+ const result = run(fixture, ['--json']);
96
+ const payload = jsonResult(result);
97
+
98
+ assert.deepStrictEqual(Object.keys(payload).sort(),
99
+ ['counts', 'rates', 'metricNote', 'nonComparable', 'linked', 'unlinked', 'sharedPathHits'].sort());
100
+ assert.deepStrictEqual(payload.counts, {
101
+ records: 8,
102
+ comparableRecords: 7,
103
+ linkedRecords: 5,
104
+ candidates: 5,
105
+ unmatchedCandidates: 1
106
+ });
107
+ assert.deepStrictEqual(payload.rates, { recallAll: 5 / 8, recallComparable: 5 / 7, unmatchedShare: 1 / 5 });
108
+ assert.match(payload.metricNote, /path overlap is a proxy and may link distinct lessons/i);
109
+ assert.match(payload.metricNote, /recall \(all\) = linked records \/ all records/i);
110
+ assert.match(payload.metricNote, /recall \(comparable\) = linked records \/ comparable records/i);
111
+ assert.deepStrictEqual(payload.nonComparable, ['E-0004']);
112
+ assert.deepStrictEqual(payload.linked, [
113
+ { id: 'E-0001', candidateIds: ['candidate-exact'] },
114
+ { id: 'E-0002', candidateIds: ['candidate-child'] },
115
+ { id: 'E-0005', candidateIds: ['candidate-shared'] },
116
+ { id: 'E-0006', candidateIds: ['candidate-shared'] },
117
+ { id: 'E-0008', candidateIds: ['candidate-parent'] }
118
+ ]);
119
+ assert.deepStrictEqual(payload.unlinked, ['E-0003', 'E-0004', 'E-0007'],
120
+ 'a/bc.js does not match the directory a/b at a segment boundary');
121
+ assert.deepStrictEqual(payload.sharedPathHits, [{
122
+ site: 'shared/file.js',
123
+ recordIds: ['E-0005', 'E-0006'],
124
+ candidateIds: ['candidate-shared']
125
+ }]);
126
+ assert.ok(!result.stdout.includes('PRIVATE_RECORD_BODY_') && !result.stdout.includes('PRIVATE_CANDIDATE_TITLE_') &&
127
+ !result.stdout.includes('PRIVATE_MEMORY_SOURCE_TITLE'), 'output contains ids and counts, not record bodies or memory titles');
128
+ assert.deepStrictEqual(snapshot(fixture.ledger), ledgerBefore, 'the fixture ledger is byte-identical after a run');
129
+ assert.deepStrictEqual(fs.readFileSync(fixture.report), reportBefore, 'the scan report is byte-identical after a run');
130
+
131
+ const markdown = run(fixture);
132
+ assert.strictEqual(markdown.status, 0, `Markdown output failed: ${markdown.stderr}`);
133
+ assert.match(markdown.stdout, /^Path overlap is a proxy/i);
134
+ assert.match(markdown.stdout, /\n\n\| Metric \| Value \|/);
135
+ assert.ok(markdown.stdout.includes('recall (all)') &&
136
+ markdown.stdout.includes('unmatched candidate share (path overlap)'));
137
+ assert.match(markdown.stdout, /path overlap is a proxy and may link distinct lessons/i);
138
+ assert.match(markdown.stdout, /recall \(all\) = linked records \/ all records/i);
139
+ assert.match(markdown.stdout, /recall \(comparable\) = linked records \/ comparable records/i);
140
+
141
+ const saved = path.join(fixture.root, 'oracle.json');
142
+ const savedResult = run(fixture, ['--json', '--out', saved]);
143
+ jsonResult(savedResult);
144
+ assert.deepStrictEqual(JSON.parse(fs.readFileSync(saved, 'utf8')), payload, '--out saves the JSON output');
145
+
146
+ const blocked = run(fixture, ['--json', '--out', path.join(fixture.ledger, 'forbidden.json')]);
147
+ assert.strictEqual(blocked.status, 2, 'an output path inside the ledger is rejected');
148
+ assert.match(blocked.stderr, /inside the ledger directory/);
149
+ assert.deepStrictEqual(snapshot(fixture.ledger), ledgerBefore, 'a rejected output path leaves every ledger byte unchanged');
150
+ const reportOverwrite = run(fixture, ['--json', '--out', fixture.report]);
151
+ assert.strictEqual(reportOverwrite.status, 2, 'the scan report cannot be used as an output path');
152
+ assert.deepStrictEqual(fs.readFileSync(fixture.report), reportBefore, 'a rejected output path leaves the scan report unchanged');
153
+ const reportHardlink = path.join(fixture.root, 'report-hardlink.json');
154
+ try {
155
+ fs.linkSync(fixture.report, reportHardlink);
156
+ const hardlinkOverwrite = run(fixture, ['--json', '--out', reportHardlink]);
157
+ assert.strictEqual(hardlinkOverwrite.status, 2, 'a hard link to the scan report cannot be used as output');
158
+ assert.deepStrictEqual(fs.readFileSync(fixture.report), reportBefore, 'a rejected hard link leaves the scan report unchanged');
159
+ } catch (error) {
160
+ if (!['EPERM', 'EACCES', 'ENOTSUP', 'ENOSYS', 'EINVAL'].includes(error.code)) throw error;
161
+ }
162
+ const ledgerAlias = path.join(fixture.root, 'errors-alias');
163
+ try {
164
+ fs.symlinkSync(fixture.ledger, ledgerAlias, 'dir');
165
+ const aliasOutput = run(fixture, ['--json', '--out', path.join(ledgerAlias, 'forbidden.json')]);
166
+ assert.strictEqual(aliasOutput.status, 2, 'a symlinked path into the ledger is rejected');
167
+ assert.deepStrictEqual(snapshot(fixture.ledger), ledgerBefore, 'a symlinked output cannot write into the ledger');
168
+ } catch (error) {
169
+ if (!['EPERM', 'EACCES', 'ENOTSUP', 'ENOSYS', 'EINVAL'].includes(error.code)) throw error;
170
+ }
171
+ const danglingAlias = path.join(fixture.root, 'dangling-output');
172
+ try {
173
+ fs.symlinkSync(path.join(fixture.ledger, 'new-record.md'), danglingAlias);
174
+ const danglingOutput = run(fixture, ['--json', '--out', danglingAlias]);
175
+ assert.strictEqual(danglingOutput.status, 2, 'a dangling symlink into the ledger is rejected');
176
+ assert.deepStrictEqual(snapshot(fixture.ledger), ledgerBefore, 'a dangling symlink cannot create a ledger file');
177
+ } catch (error) {
178
+ if (!['EPERM', 'EACCES', 'ENOTSUP', 'ENOSYS', 'EINVAL'].includes(error.code)) throw error;
179
+ }
180
+
181
+ const zero = makeFixture('zero-candidates', [
182
+ { id: 'E-0009', sites: ['src/never-linked.js'] }
183
+ ], []);
184
+ const zeroPayload = jsonResult(run(zero, ['--json']));
185
+ assert.strictEqual(zeroPayload.rates.unmatchedShare, null, 'unmatched share is null when there are no candidates');
186
+ assert.strictEqual(zeroPayload.counts.unmatchedCandidates, 0);
187
+ const zeroMarkdown = run(zero);
188
+ assert.strictEqual(zeroMarkdown.status, 0, `zero-candidate Markdown output failed: ${zeroMarkdown.stderr}`);
189
+ assert.match(zeroMarkdown.stdout, /\| unmatched candidate share \(path overlap\) \| n\/a \|/);
190
+
191
+ const differentLessons = makeFixture('same-path-different-lessons', [
192
+ { id: 'E-0012', sites: ['shared/ambiguous.js'], lesson: 'Database deadlock handling' }
193
+ ], [
194
+ { id: 'candidate-different-lesson', sites: ['shared/ambiguous.js'], title: 'CSS formatting only' }
195
+ ]);
196
+ const differentLessonPayload = jsonResult(run(differentLessons, ['--json']));
197
+ assert.deepStrictEqual(differentLessonPayload.linked, [
198
+ { id: 'E-0012', candidateIds: ['candidate-different-lesson'] }
199
+ ], 'same-file candidates link even when their lesson text differs');
200
+ assert.strictEqual(differentLessonPayload.rates.unmatchedShare, 0,
201
+ 'path overlap alone cannot identify a semantically unrelated candidate');
202
+ assert.match(differentLessonPayload.metricNote, /may link distinct lessons/i);
203
+
204
+ const windows = makeFixture('windows', [
205
+ { id: 'E-0010', sites: ['Src\\Parser.JS'] },
206
+ { id: 'E-0011', sites: ['C:\\repo\\src'] }
207
+ ], [
208
+ { id: 'candidate-win-case', sites: ['src/parser.js'] },
209
+ { id: 'candidate-other-drive', sites: ['D:/repo/src/file.js'] }
210
+ ]);
211
+ const windowsPayload = jsonResult(run(windows, ['--json', '--platform', 'win32']));
212
+ assert.deepStrictEqual(windowsPayload.linked, [
213
+ { id: 'E-0010', candidateIds: ['candidate-win-case'] }
214
+ ], 'win32 matching ignores case and never treats C: and D: paths as contained');
215
+ assert.deepStrictEqual(windowsPayload.nonComparable, ['E-0011']);
216
+
217
+ try {
218
+ fs.rmSync(TMP, { recursive: true, force: true });
219
+ } catch (error) {
220
+ process.stderr.write(`temporary fixture cleanup failed: ${error.message}\n`);
221
+ process.exitCode = 1;
222
+ }