harness-everything 0.56.0 → 0.57.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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +23 -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/fixtures/468-dispatch/runner.js +30 -4
- 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 +507 -0
- package/ci/mechanism-394-opencode-ledger-lesson.test.js +232 -0
- package/ci/mechanism-468-dispatch-cli.test.js +143 -5
- package/ci/mechanism-errors-sync-root.test.js +86 -4
- package/ci/mechanism-report-writer.test.js +13 -1
- package/docs/adr/ROUTE-001-error-lesson-delivery.md +52 -49
- package/docs/error-handling/details/c8-dispatch-cli.md +8 -4
- 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/dispatch.js +31 -7
- package/scripts/errors-sync.js +63 -2
- package/scripts/report-writer.js +4 -2
|
@@ -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
|
+
});
|