harness-everything 0.58.0 → 1.0.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/AGENTS.md +8 -2
- package/CHANGELOG.md +24 -0
- package/README.md +4 -4
- package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/README.md +40 -0
- package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/edit-state-final.json +11 -0
- package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/events-2026-11-24.jsonl +103 -0
- package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/host-version.txt +3 -0
- package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/live-event-trace-probe.js +11 -0
- package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/plugin-load-lines.txt +2 -0
- package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/reminder-excerpt.txt +1 -0
- package/ci/doc-capability-consistency.test.js +4 -2
- package/ci/lib/opencode-v2-driver.js +169 -0
- package/ci/mechanism-2n-opencode-plugin.test.js +387 -223
- package/ci/mechanism-2p-opencode-v2-entrypoint.test.js +24 -15
- package/ci/mechanism-2u-issue-42-regressions.test.js +41 -2
- package/ci/mechanism-2w-platform-compatibility.test.js +16 -3
- package/ci/mechanism-30-opencode-plugin-loadability.test.js +78 -45
- package/ci/mechanism-338-opencode-async.test.js +367 -194
- package/ci/mechanism-341-opencode-lane.test.js +143 -183
- package/ci/mechanism-39-opencode-verify-outcomes.test.js +118 -86
- package/ci/mechanism-394-ledger-match.test.js +105 -3
- package/ci/mechanism-394-opencode-ledger-lesson.test.js +46 -97
- package/ci/mechanism-397-opencode-observations.test.js +58 -47
- package/ci/mechanism-453-opencode-v2-driver.test.js +51 -0
- package/ci/mechanism-453-opencode-v2-only-events.test.js +241 -0
- package/ci/mechanism-516-agy-post-tool-exit.test.js +472 -0
- package/ci/mechanism-516-agy-stop-revision.test.js +215 -0
- package/ci/telemetry.test.js +31 -24
- package/docs/architecture.md +4 -2
- package/docs/platform-capabilities.md +60 -26
- package/docs/platform-compatibility.json +8 -6
- package/docs/system-one-observations.md +1 -1
- package/docs/telemetry.md +1 -1
- package/docs/troubleshooting.md +2 -2
- package/hooks/scripts/agy-post-tool.js +79 -16
- package/hooks/scripts/agy-stop.js +63 -10
- package/hooks/scripts/lib/ledger-match.js +132 -20
- package/hooks/scripts/state-persist.js +7 -1
- package/opencode-plugin/README.md +60 -66
- package/opencode-plugin/index.mjs +11 -13
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/scripts/agy-post-tool.js +79 -16
- package/plugins/harness-everything/hooks/scripts/agy-stop.js +63 -10
- package/plugins/harness-everything/hooks/scripts/lib/ledger-match.js +132 -20
- package/plugins/harness-everything/hooks/scripts/state-persist.js +7 -1
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/rules/AGENTS.md +8 -2
- package/sbom.cdx.json +12 -12
|
@@ -1,104 +1,136 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const crypto = require('crypto');
|
|
4
|
-
const { pathToFileURL } = require('url');
|
|
5
4
|
const helper = require('./test-helper');
|
|
5
|
+
const { createV2Driver } = require('./lib/opencode-v2-driver');
|
|
6
6
|
|
|
7
7
|
console.log('\n[39] opencode verification outcomes and reminders with the real plugin...');
|
|
8
8
|
|
|
9
9
|
(async () => {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}, null, 2));
|
|
22
|
-
const setFixture = (source) => fs.writeFileSync(fixtureFile, `${source}\n`);
|
|
10
|
+
const d = await createV2Driver({
|
|
11
|
+
scripts: { test: 'node fixture.js' },
|
|
12
|
+
});
|
|
13
|
+
try {
|
|
14
|
+
const realWorkspace = fs.realpathSync.native(path.resolve(d.workspace));
|
|
15
|
+
const slug = path.basename(realWorkspace).toLowerCase().replace(/[^a-z0-9._-]+/g, '-').replace(/^-+|-+$/g, '') || 'workspace';
|
|
16
|
+
const hashInput = process.platform === 'win32' ? realWorkspace.toLowerCase() : realWorkspace;
|
|
17
|
+
const hash = crypto.createHash('sha1').update(hashInput).digest('hex').slice(0, 12);
|
|
18
|
+
const sessionsRoot = path.join(d.stateHome, 'workspaces', `${slug}-${hash}`, 'state', 'sessions');
|
|
19
|
+
const fixtureFile = path.join(d.workspace, 'fixture.js');
|
|
20
|
+
const setFixture = (source) => fs.writeFileSync(fixtureFile, `${source}\n`);
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
22
|
+
let callCounter = 0;
|
|
23
|
+
const sessionID = 'repeated-failures';
|
|
24
|
+
const edit = async (id = sessionID) => {
|
|
25
|
+
const callId = `call-${++callCounter}`;
|
|
26
|
+
const event = {
|
|
27
|
+
tool: 'edit',
|
|
28
|
+
sessionID: id,
|
|
29
|
+
agent: 'build',
|
|
30
|
+
messageID: `msg-${callCounter}`,
|
|
31
|
+
id: callId,
|
|
32
|
+
input: { filePath: path.join(d.workspace, 'code.js') },
|
|
33
|
+
};
|
|
34
|
+
await d.toolHook('execute.before')(event);
|
|
35
|
+
await d.toolHook('execute.after')({ ...event, status: 'completed', result: {} });
|
|
36
|
+
};
|
|
37
|
+
const turnEnd = (id = sessionID) => d.emit('session.execution.succeeded', id);
|
|
38
|
+
const stateFile = (id, name) => path.join(sessionsRoot, id, name);
|
|
39
|
+
const lastPrompt = () => d.prompts[d.prompts.length - 1].text;
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
setFixture("console.error('AssertionError [ERR_ASSERTION]: stable fixture failure');process.exit(1);");
|
|
42
|
+
for (let attempt = 0; attempt < 4; attempt += 1) {
|
|
43
|
+
let allowed = true;
|
|
44
|
+
try {
|
|
45
|
+
await edit();
|
|
46
|
+
} catch {
|
|
47
|
+
allowed = false;
|
|
48
|
+
}
|
|
49
|
+
if (!allowed) break;
|
|
50
|
+
const expectedPrompts = d.prompts.length + 1;
|
|
51
|
+
turnEnd();
|
|
52
|
+
await d.waitFor(() => d.prompts.length >= expectedPrompts, {
|
|
53
|
+
label: `failure reminder #${attempt + 1}`,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const failedPrompts = d.prompts.map((call) => call.text);
|
|
57
|
+
helper.check(
|
|
58
|
+
'39. four identical test failures each produce a reminder and do not block the next edit',
|
|
59
|
+
failedPrompts.length === 4 && failedPrompts.every((text) => /verification failed/i.test(text)
|
|
60
|
+
&& !/reflection token|## Goal|forced reflection|retries before/i.test(text)),
|
|
61
|
+
JSON.stringify(failedPrompts),
|
|
62
|
+
);
|
|
63
|
+
helper.check(
|
|
64
|
+
'39. repeated test failures create no recurrence state',
|
|
65
|
+
!fs.existsSync(stateFile(sessionID, 'circuit-breaker.json')),
|
|
66
|
+
stateFile(sessionID, 'circuit-breaker.json'),
|
|
67
|
+
);
|
|
68
|
+
let readAllowed = true;
|
|
44
69
|
try {
|
|
45
|
-
await
|
|
70
|
+
await d.toolHook('execute.before')({
|
|
71
|
+
tool: 'read',
|
|
72
|
+
sessionID,
|
|
73
|
+
agent: 'build',
|
|
74
|
+
messageID: `msg-${++callCounter}`,
|
|
75
|
+
id: 'read-after-failures',
|
|
76
|
+
input: {},
|
|
77
|
+
});
|
|
46
78
|
} catch {
|
|
47
|
-
|
|
79
|
+
readAllowed = false;
|
|
48
80
|
}
|
|
49
|
-
|
|
50
|
-
await idle();
|
|
51
|
-
}
|
|
52
|
-
const failedPrompts = promptCalls.map((call) => call.body.parts[0].text);
|
|
53
|
-
helper.check(
|
|
54
|
-
'39. four identical test failures each produce a reminder and do not block the next edit',
|
|
55
|
-
failedPrompts.length === 4 && failedPrompts.every((text) => /verification failed/i.test(text)
|
|
56
|
-
&& !/reflection token|## Goal|forced reflection|retries before/i.test(text)),
|
|
57
|
-
JSON.stringify(failedPrompts),
|
|
58
|
-
);
|
|
59
|
-
helper.check(
|
|
60
|
-
'39. repeated test failures create no recurrence state',
|
|
61
|
-
!fs.existsSync(stateFile(sessionID, 'circuit-breaker.json')),
|
|
62
|
-
stateFile(sessionID, 'circuit-breaker.json'),
|
|
63
|
-
);
|
|
64
|
-
let readAllowed = true;
|
|
65
|
-
try {
|
|
66
|
-
await hooks['tool.execute.before']({ tool: 'read', sessionID, callID: 'read-after-failures' }, { args: {} });
|
|
67
|
-
} catch {
|
|
68
|
-
readAllowed = false;
|
|
69
|
-
}
|
|
70
|
-
helper.check('39. a permitted read remains available after repeated failures', readAllowed);
|
|
81
|
+
helper.check('39. a permitted read remains available after repeated failures', readAllowed);
|
|
71
82
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
const timeoutSession = 'timeout';
|
|
84
|
+
setFixture('setTimeout(() => {}, 3000);');
|
|
85
|
+
process.env.HARNESS_VERIFY_TIMEOUT_MS = '100';
|
|
86
|
+
const promptsBeforeTimeout = d.prompts.length;
|
|
87
|
+
try {
|
|
88
|
+
await edit(timeoutSession);
|
|
89
|
+
turnEnd(timeoutSession);
|
|
90
|
+
await d.waitFor(() => d.prompts.length > promptsBeforeTimeout, {
|
|
91
|
+
label: 'timeout verification reminder',
|
|
92
|
+
});
|
|
93
|
+
} finally {
|
|
94
|
+
delete process.env.HARNESS_VERIFY_TIMEOUT_MS;
|
|
95
|
+
}
|
|
96
|
+
helper.check(
|
|
97
|
+
'39. a timeout is reported as incomplete verification without reflection or a counter',
|
|
98
|
+
/did not complete/.test(lastPrompt()) && /timed out/.test(lastPrompt())
|
|
99
|
+
&& !/reflection token|## Goal|does NOT count|retries before/i.test(lastPrompt())
|
|
100
|
+
&& !fs.existsSync(stateFile(timeoutSession, 'circuit-breaker.json')),
|
|
101
|
+
lastPrompt(),
|
|
102
|
+
);
|
|
85
103
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
const recoverSession = 'recover';
|
|
105
|
+
setFixture("console.error('AssertionError [ERR_ASSERTION]: recoverable failure');process.exit(1);");
|
|
106
|
+
const promptsBeforeRecoverFail = d.prompts.length;
|
|
107
|
+
await edit(recoverSession);
|
|
108
|
+
turnEnd(recoverSession);
|
|
109
|
+
await d.waitFor(() => d.prompts.length > promptsBeforeRecoverFail, {
|
|
110
|
+
label: 'recoverable failure reminder',
|
|
111
|
+
});
|
|
112
|
+
const promptsBeforeSuccess = d.prompts.length;
|
|
113
|
+
setFixture('process.exit(0);');
|
|
114
|
+
await edit(recoverSession);
|
|
115
|
+
turnEnd(recoverSession);
|
|
116
|
+
await d.waitFor(() => {
|
|
117
|
+
const file = stateFile(recoverSession, 'edit-state.json');
|
|
118
|
+
if (!fs.existsSync(file)) return false;
|
|
119
|
+
const state = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
120
|
+
return state.verificationPending === false && state.editsSinceVerification === 0;
|
|
121
|
+
}, { label: 'passing verification clears pending state' });
|
|
122
|
+
await d.settled({ quietMs: 200 });
|
|
123
|
+
const recoveredState = JSON.parse(fs.readFileSync(stateFile(recoverSession, 'edit-state.json'), 'utf8'));
|
|
124
|
+
helper.check(
|
|
125
|
+
'39. a passing verification clears pending state without an extra reminder',
|
|
126
|
+
recoveredState.verificationPending === false && recoveredState.editsSinceVerification === 0
|
|
127
|
+
&& d.prompts.length === promptsBeforeSuccess
|
|
128
|
+
&& !fs.existsSync(stateFile(recoverSession, 'circuit-breaker.json')),
|
|
129
|
+
JSON.stringify(recoveredState),
|
|
130
|
+
);
|
|
131
|
+
} finally {
|
|
132
|
+
await d.teardown();
|
|
133
|
+
}
|
|
102
134
|
|
|
103
135
|
helper.finish();
|
|
104
136
|
})().catch((err) => {
|
|
@@ -170,8 +170,6 @@ test('source and packaged matchers bound simple command sequences and reject uns
|
|
|
170
170
|
];
|
|
171
171
|
const unsupported = [
|
|
172
172
|
"echo 'git commit; echo done'",
|
|
173
|
-
'git commit | cat',
|
|
174
|
-
'cat | git commit',
|
|
175
173
|
'(git commit)',
|
|
176
174
|
'git commit <<EOF\nmessage\nEOF',
|
|
177
175
|
'git commit;',
|
|
@@ -186,6 +184,77 @@ test('source and packaged matchers bound simple command sequences and reject uns
|
|
|
186
184
|
}
|
|
187
185
|
});
|
|
188
186
|
|
|
187
|
+
test('source and packaged matchers recognize pipeline members and literal redirects', () => {
|
|
188
|
+
const expected = { tool: 'shell', executable: 'git', subcommand: 'commit' };
|
|
189
|
+
const supported = [
|
|
190
|
+
'git commit -m "A"',
|
|
191
|
+
'cd /x && git commit -m "A"',
|
|
192
|
+
'git commit --dry-run -m "A"',
|
|
193
|
+
'git commit -m "A" 2>&1',
|
|
194
|
+
'git commit -m "A" 2>&1 | tail -3',
|
|
195
|
+
'git commit -m "A" | cat',
|
|
196
|
+
'echo before | git commit -m "A"',
|
|
197
|
+
'git 2>&1 commit -m "A"',
|
|
198
|
+
'2>errors.log git commit -m "A"',
|
|
199
|
+
'git commit 2>&1 -m "A"',
|
|
200
|
+
'git commit -m "A" >out.log',
|
|
201
|
+
'git commit -m "A" >out#log',
|
|
202
|
+
'git commit -m "A" >> "out file.log"',
|
|
203
|
+
'git commit -m "A" < input.txt',
|
|
204
|
+
'git commit -m "A" &>combined.log',
|
|
205
|
+
'git commit -m "A" 2> errors.log',
|
|
206
|
+
'git commit -m "A | B"',
|
|
207
|
+
'git commit -m A \\| cat',
|
|
208
|
+
'git commit -m "A" # | cat is comment text'
|
|
209
|
+
];
|
|
210
|
+
const unsupported = [
|
|
211
|
+
"echo 'git commit | cat'",
|
|
212
|
+
'echo before > git commit',
|
|
213
|
+
'echo before # git commit | cat',
|
|
214
|
+
'env git commit',
|
|
215
|
+
'git commit |',
|
|
216
|
+
'| git commit',
|
|
217
|
+
'git commit | | cat',
|
|
218
|
+
'git commit |& cat',
|
|
219
|
+
'git commit &',
|
|
220
|
+
'git commit &>>out.log',
|
|
221
|
+
'git commit 2>&-',
|
|
222
|
+
'git commit 2>&1-',
|
|
223
|
+
'git commit 2>&1suffix',
|
|
224
|
+
'2 >errors.log git commit',
|
|
225
|
+
"'2'>errors.log git commit",
|
|
226
|
+
'name2>errors.log git commit',
|
|
227
|
+
'git commit >',
|
|
228
|
+
'git commit > # missing redirect target',
|
|
229
|
+
'git commit >#missing-target',
|
|
230
|
+
'git commit >""',
|
|
231
|
+
'git commit >"$OUT"',
|
|
232
|
+
'git commit >*.log',
|
|
233
|
+
'git commit <<EOF\nmessage\nEOF',
|
|
234
|
+
'git commit <<< message',
|
|
235
|
+
'git commit > >(tee out.log)',
|
|
236
|
+
'cat <(git commit)',
|
|
237
|
+
'(git commit)',
|
|
238
|
+
'echo "$(git commit)"',
|
|
239
|
+
'echo "`git commit`"'
|
|
240
|
+
];
|
|
241
|
+
for (const implementation of [matcher, packagedMatcher]) {
|
|
242
|
+
for (const command of supported) {
|
|
243
|
+
assert.deepEqual(implementation.normalizeGitCommitCommand(command), expected, command);
|
|
244
|
+
const result = implementation.matchLedgerLessons(input({
|
|
245
|
+
event: { phase: 'action', tool: 'shell', command, outcome: { failed: 'unknown' } }
|
|
246
|
+
}));
|
|
247
|
+
assert.deepEqual(result?.ids, ['E-0003'], command);
|
|
248
|
+
}
|
|
249
|
+
for (const command of unsupported) {
|
|
250
|
+
assert.equal(implementation.normalizeGitCommitCommand(command), null, command);
|
|
251
|
+
assert.equal(implementation.matchLedgerLessons(input({
|
|
252
|
+
event: { phase: 'action', tool: 'shell', command, outcome: { failed: 'unknown' } }
|
|
253
|
+
})), null, command);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
|
|
189
258
|
test('source and packaged matchers accept an empty Git config value', () => {
|
|
190
259
|
const expected = { tool: 'shell', executable: 'git', subcommand: 'commit' };
|
|
191
260
|
for (const implementation of [matcher, packagedMatcher]) {
|
|
@@ -225,7 +294,6 @@ test('simple command segments select commit lessons without matching quoted text
|
|
|
225
294
|
}
|
|
226
295
|
for (const command of [
|
|
227
296
|
"echo 'git commit; echo done'",
|
|
228
|
-
'git commit | cat',
|
|
229
297
|
'(git commit)',
|
|
230
298
|
'git commit <<EOF\nmessage\nEOF',
|
|
231
299
|
'env git commit'
|
|
@@ -272,6 +340,40 @@ test('failure lessons require a known outcome and an exact diagnostic', () => {
|
|
|
272
340
|
}
|
|
273
341
|
});
|
|
274
342
|
|
|
343
|
+
test('a pipeline keeps the per-session action and failure reminder policy', () => {
|
|
344
|
+
const state = stateDir('pipeline-once');
|
|
345
|
+
const base = input({ stateDir: state, sessionIdentity: 'session:pipeline-once' });
|
|
346
|
+
const action = matcher.matchLedgerLessons(base);
|
|
347
|
+
assert.deepEqual(action?.ids, ['E-0003']);
|
|
348
|
+
assert.equal(matcher.matchLedgerLessons(base), null, 'a duplicate action stays silent');
|
|
349
|
+
|
|
350
|
+
const failureInput = {
|
|
351
|
+
...base,
|
|
352
|
+
event: {
|
|
353
|
+
phase: 'failure',
|
|
354
|
+
tool: 'shell',
|
|
355
|
+
command: 'git commit -m "Bad Subject" 2>&1 | tail -3',
|
|
356
|
+
outcome: { failed: false, output: COMMITLINT_OUTPUT }
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
const failure = matcher.matchLedgerLessons(failureInput);
|
|
360
|
+
assert.deepEqual(failure?.ids, ['E-0003'], 'an exact diagnostic can recover a pipeline masked by zero status');
|
|
361
|
+
assert.equal(matcher.matchLedgerLessons(failureInput), null, 'a duplicate failure stays silent');
|
|
362
|
+
|
|
363
|
+
const unknown = matcher.matchLedgerLessons({
|
|
364
|
+
...failureInput,
|
|
365
|
+
sessionIdentity: 'session:pipeline-unknown',
|
|
366
|
+
event: { ...failureInput.event, outcome: { failed: 'unknown', output: COMMITLINT_OUTPUT } }
|
|
367
|
+
});
|
|
368
|
+
assert.equal(unknown, null, 'an unknown pipeline outcome stays silent');
|
|
369
|
+
const redirectedZero = matcher.matchLedgerLessons({
|
|
370
|
+
...failureInput,
|
|
371
|
+
sessionIdentity: 'session:redirected-zero',
|
|
372
|
+
event: { ...failureInput.event, command: 'git commit -m "Bad Subject" 2>&1', outcome: { failed: false, output: COMMITLINT_OUTPUT } }
|
|
373
|
+
});
|
|
374
|
+
assert.equal(redirectedZero, null, 'a redirect alone remains one command and cannot recover a zero status');
|
|
375
|
+
});
|
|
376
|
+
|
|
275
377
|
test('the real generator and runtime accept quoted identity and match scalars', () => {
|
|
276
378
|
const root = workspace('generated quoted record');
|
|
277
379
|
const ledger = path.join(root, '.agents', 'harness-everything', 'errors');
|
|
@@ -5,8 +5,8 @@ const fs = require('node:fs');
|
|
|
5
5
|
const os = require('node:os');
|
|
6
6
|
const path = require('node:path');
|
|
7
7
|
const { spawnSync } = require('node:child_process');
|
|
8
|
-
const { pathToFileURL } = require('node:url');
|
|
9
8
|
const { test } = require('node:test');
|
|
9
|
+
const { createV2Driver } = require('./lib/opencode-v2-driver');
|
|
10
10
|
|
|
11
11
|
const ROOT = path.resolve(__dirname, '..');
|
|
12
12
|
const PLUGIN = path.join(ROOT, 'opencode-plugin', 'index.mjs');
|
|
@@ -15,7 +15,7 @@ const ERRORS_SYNC = path.join(ROOT, 'scripts', 'errors-sync.js');
|
|
|
15
15
|
const COMMITLINT = fs.readFileSync(path.join(__dirname, 'fixtures/394-ledger-match/commitlint-subject-case.txt'), 'utf8');
|
|
16
16
|
const OLD_ENV = Object.fromEntries(['HOME', 'USERPROFILE', 'HARNESS_STATE_HOME', 'HARNESS_TELEMETRY', 'HARNESS_SYSTEM_ONE_MODE']
|
|
17
17
|
.map(key => [key, process.env[key]]));
|
|
18
|
-
const TMP = fs.mkdtempSync(path.join(os.tmpdir(), 'mechanism-394-opencode-ledger-'));
|
|
18
|
+
const TMP = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'mechanism-394-opencode-ledger-')));
|
|
19
19
|
|
|
20
20
|
function isOutside(root, target) {
|
|
21
21
|
const relative = path.relative(root, target);
|
|
@@ -49,63 +49,11 @@ function packagePlugin() {
|
|
|
49
49
|
return path.join(pluginDir, 'harness-enforcement.mjs');
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
function
|
|
53
|
-
const toolHooks = new Map();
|
|
54
|
-
const sessionHooks = new Map();
|
|
55
|
-
const eventQueue = [];
|
|
56
|
-
let eventWaiter;
|
|
57
|
-
let currentEvent;
|
|
58
|
-
const ctx = {
|
|
59
|
-
location: { directory: ROOT },
|
|
60
|
-
tool: { hook: async (name, callback) => { toolHooks.set(name, callback); return { dispose: async () => {} }; } },
|
|
61
|
-
session: {
|
|
62
|
-
get: async ({ sessionID }) => ({ id: sessionID, location: { directory: sessionWorkspaces[sessionID] } }),
|
|
63
|
-
hook: async (name, callback) => { sessionHooks.set(name, callback); return { dispose: async () => {} }; },
|
|
64
|
-
prompt: async () => ({}),
|
|
65
|
-
context: async () => [],
|
|
66
|
-
},
|
|
67
|
-
event: {
|
|
68
|
-
subscribe: ({ signal }) => ({
|
|
69
|
-
[Symbol.asyncIterator]() {
|
|
70
|
-
return {
|
|
71
|
-
next: () => {
|
|
72
|
-
currentEvent?.resolve();
|
|
73
|
-
currentEvent = null;
|
|
74
|
-
if (eventQueue.length) {
|
|
75
|
-
currentEvent = eventQueue.shift();
|
|
76
|
-
return Promise.resolve({ value: currentEvent.event, done: false });
|
|
77
|
-
}
|
|
78
|
-
if (signal.aborted) return Promise.resolve({ done: true });
|
|
79
|
-
return new Promise(resolve => {
|
|
80
|
-
eventWaiter = resolve;
|
|
81
|
-
signal.addEventListener('abort', () => resolve({ done: true }), { once: true });
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
},
|
|
86
|
-
}),
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
return import(pathToFileURL(pluginFile).href).then(async mod => ({
|
|
90
|
-
toolHooks,
|
|
91
|
-
sessionHooks,
|
|
92
|
-
pushEvent: event => new Promise(resolve => {
|
|
93
|
-
const item = { event, resolve };
|
|
94
|
-
if (eventWaiter) {
|
|
95
|
-
currentEvent = item;
|
|
96
|
-
eventWaiter({ value: event, done: false });
|
|
97
|
-
eventWaiter = null;
|
|
98
|
-
} else eventQueue.push(item);
|
|
99
|
-
}),
|
|
100
|
-
dispose: await mod.default.setup(ctx),
|
|
101
|
-
}));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async function toolCall(harness, sessionID, id, status = 'completed', output = 'ok', exit = 0,
|
|
52
|
+
async function toolCall(driver, sessionID, id, status = 'completed', output = 'ok', exit = 0,
|
|
105
53
|
command = 'git commit -m "docs(errors): Bad Case"') {
|
|
106
54
|
const before = { tool: 'bash', sessionID, agent: 'build', messageID: `message-${id}`, id, input: { command } };
|
|
107
55
|
const beforeSnapshot = structuredClone(before);
|
|
108
|
-
assert.equal(await
|
|
56
|
+
assert.equal(await driver.toolHook('execute.before')(before), undefined);
|
|
109
57
|
assert.deepEqual(before, beforeSnapshot, 'execute.before does not change the tool request');
|
|
110
58
|
|
|
111
59
|
const after = {
|
|
@@ -116,13 +64,13 @@ async function toolCall(harness, sessionID, id, status = 'completed', output = '
|
|
|
116
64
|
: { result: { output, metadata: exit === null ? {} : { exit } } }),
|
|
117
65
|
};
|
|
118
66
|
const afterSnapshot = structuredClone(after);
|
|
119
|
-
assert.equal(await
|
|
67
|
+
assert.equal(await driver.toolHook('execute.after')(after), undefined);
|
|
120
68
|
assert.deepEqual(after, afterSnapshot, 'execute.after does not change the host tool result');
|
|
121
69
|
}
|
|
122
70
|
|
|
123
|
-
async function context(
|
|
71
|
+
async function context(driver, sessionID, base = 'base system') {
|
|
124
72
|
const event = { sessionID, kind: 'primary', system: [{ type: 'text', text: base }] };
|
|
125
|
-
await
|
|
73
|
+
await driver.sessionHook('context')(event);
|
|
126
74
|
return event.system.map(part => part.text || '').join('\n');
|
|
127
75
|
}
|
|
128
76
|
|
|
@@ -136,19 +84,15 @@ test.after(() => {
|
|
|
136
84
|
|
|
137
85
|
test('OpenCode V2 carries real ledger matches through the source and packaged context hooks', async () => {
|
|
138
86
|
assert.ok(isOutside(ROOT, TMP), 'fixture state must stay outside the repository');
|
|
139
|
-
const home = path.join(TMP, 'home');
|
|
140
87
|
const workspace = path.join(TMP, 'workspace');
|
|
141
88
|
const otherWorkspace = path.join(TMP, 'other-workspace');
|
|
142
89
|
const emptyWorkspace = path.join(TMP, 'empty-workspace');
|
|
143
|
-
|
|
90
|
+
const sharedStateHome = path.join(TMP, 'harness-state');
|
|
144
91
|
fs.mkdirSync(workspace, { recursive: true });
|
|
145
92
|
fs.mkdirSync(otherWorkspace, { recursive: true });
|
|
146
93
|
fs.mkdirSync(emptyWorkspace, { recursive: true });
|
|
147
94
|
addLedger(workspace);
|
|
148
95
|
addLedger(otherWorkspace);
|
|
149
|
-
process.env.HOME = home;
|
|
150
|
-
process.env.USERPROFILE = home;
|
|
151
|
-
process.env.HARNESS_STATE_HOME = path.join(TMP, 'harness-state');
|
|
152
96
|
process.env.HARNESS_TELEMETRY = 'off';
|
|
153
97
|
delete process.env.HARNESS_SYSTEM_ONE_MODE;
|
|
154
98
|
|
|
@@ -164,16 +108,18 @@ test('OpenCode V2 carries real ledger matches through the source and packaged co
|
|
|
164
108
|
disposal: workspace,
|
|
165
109
|
sessionCleanup: workspace,
|
|
166
110
|
};
|
|
167
|
-
const
|
|
111
|
+
const sessionLookup = async ({ sessionID }) => ({ id: sessionID, location: { directory: sessionWorkspaces[sessionID] } });
|
|
112
|
+
const driver = await createV2Driver({ workspace, sessionLookup });
|
|
113
|
+
process.env.HARNESS_STATE_HOME = sharedStateHome;
|
|
168
114
|
const command = 'git -C x commit -m "docs(errors): Bad Case"';
|
|
169
115
|
try {
|
|
170
|
-
assert.ok(
|
|
171
|
-
assert.ok(
|
|
172
|
-
assert.equal(
|
|
116
|
+
assert.ok(driver.toolHooks.has('execute.before') && driver.toolHooks.has('execute.after'));
|
|
117
|
+
assert.ok(driver.sessionHooks.has('context'));
|
|
118
|
+
assert.equal(driver.toolHooks.size, 2, 'the carrier registers no permission hook or additional tool gate');
|
|
173
119
|
|
|
174
120
|
const before = { tool: 'bash', sessionID: 'same', agent: 'build', messageID: 'message-same', id: 'same-action', input: { command } };
|
|
175
121
|
const beforeSnapshot = structuredClone(before);
|
|
176
|
-
assert.equal(await
|
|
122
|
+
assert.equal(await driver.toolHook('execute.before')(before), undefined);
|
|
177
123
|
assert.deepEqual(before, beforeSnapshot);
|
|
178
124
|
|
|
179
125
|
const failure = {
|
|
@@ -182,35 +128,35 @@ test('OpenCode V2 carries real ledger matches through the source and packaged co
|
|
|
182
128
|
error: { name: 'ToolError', message: COMMITLINT },
|
|
183
129
|
};
|
|
184
130
|
const failureSnapshot = structuredClone(failure);
|
|
185
|
-
assert.equal(await
|
|
131
|
+
assert.equal(await driver.toolHook('execute.after')(failure), undefined);
|
|
186
132
|
assert.deepEqual(failure, failureSnapshot, 'the failed shell result remains untouched');
|
|
187
133
|
|
|
188
134
|
const wrongSessionSystem = [{ type: 'text', text: 'base system' }];
|
|
189
|
-
await
|
|
135
|
+
await driver.sessionHook('context')({ sessionID: 'other', kind: 'primary', system: wrongSessionSystem });
|
|
190
136
|
assert.deepEqual(wrongSessionSystem, [{ type: 'text', text: 'base system' }], 'a pending lesson stays bound to its session');
|
|
191
137
|
|
|
192
|
-
const delivered = await context(
|
|
138
|
+
const delivered = await context(driver, 'same');
|
|
193
139
|
assert.equal((delivered.match(/Cue:\n/g) || []).length, 2,
|
|
194
140
|
'action selection runs in execute.before and failure selection in execute.after; both arrive at the next model request');
|
|
195
141
|
assert.match(delivered, /subject-case/);
|
|
196
|
-
assert.equal(await context(
|
|
142
|
+
assert.equal(await context(driver, 'same'), 'base system', 'a delivered phase is not replayed on another context build');
|
|
197
143
|
|
|
198
|
-
await toolCall(
|
|
199
|
-
assert.equal((await context(
|
|
144
|
+
await toolCall(driver, 'other', 'other-action', 'completed', COMMITLINT, 0);
|
|
145
|
+
assert.equal((await context(driver, 'other')).match(/Cue:\n/g)?.length, 1,
|
|
200
146
|
'a direct command with diagnostic-looking output and zero exit remains action-only');
|
|
201
147
|
|
|
202
|
-
await toolCall(
|
|
148
|
+
await toolCall(driver, 'masked', 'masked-action', 'completed', COMMITLINT, 0,
|
|
203
149
|
'git commit -m "Bad Subject"; echo "$?"');
|
|
204
|
-
assert.equal((await context(
|
|
150
|
+
assert.equal((await context(driver, 'masked')).match(/Cue:\n/g)?.length, 2,
|
|
205
151
|
'a precise commitlint diagnostic recovers a commit failure masked by a compound shell exit');
|
|
206
152
|
|
|
207
|
-
await toolCall(
|
|
153
|
+
await toolCall(driver, 'unknownExit', 'unknown-exit-action', 'completed', COMMITLINT, null,
|
|
208
154
|
'git commit -m "Bad Subject"; echo "$?"');
|
|
209
|
-
assert.equal((await context(
|
|
155
|
+
assert.equal((await context(driver, 'unknownExit')).match(/Cue:\n/g)?.length, 1,
|
|
210
156
|
'a completed compound command without metadata.exit remains action-only');
|
|
211
157
|
|
|
212
|
-
await toolCall(
|
|
213
|
-
assert.equal((await context(
|
|
158
|
+
await toolCall(driver, 'separateWorkspace', 'workspace-action', 'completed', COMMITLINT, 1);
|
|
159
|
+
assert.equal((await context(driver, 'separateWorkspace')).match(/Cue:\n/g)?.length, 2,
|
|
214
160
|
'a completed tool result with nonzero metadata.exit and captured diagnostics selects failure too');
|
|
215
161
|
|
|
216
162
|
// Live OpenCode 2.1.4 shape (E-0006/E-0008): tool "shell", input carries workdir,
|
|
@@ -220,13 +166,13 @@ test('OpenCode V2 carries real ledger matches through the source and packaged co
|
|
|
220
166
|
|
|
221
167
|
const shellActionEvent = { ...shellBase, sessionID: 'shellAction', id: 'shell-action' };
|
|
222
168
|
const shellActionSnapshot = structuredClone(shellActionEvent);
|
|
223
|
-
assert.equal(await
|
|
169
|
+
assert.equal(await driver.toolHook('execute.before')(shellActionEvent), undefined);
|
|
224
170
|
assert.deepEqual(shellActionEvent, shellActionSnapshot, 'execute.before does not change a live shell tool request');
|
|
225
|
-
assert.equal((await context(
|
|
171
|
+
assert.equal((await context(driver, 'shellAction')).match(/Cue:\n/g)?.length, 1,
|
|
226
172
|
'a live shell action event delivers the action lesson');
|
|
227
173
|
|
|
228
174
|
const shellFailureBefore = { ...shellBase, sessionID: 'shellFailure', id: 'shell-failure-before' };
|
|
229
|
-
assert.equal(await
|
|
175
|
+
assert.equal(await driver.toolHook('execute.before')(shellFailureBefore), undefined);
|
|
230
176
|
const shellFailureAfter = {
|
|
231
177
|
...shellFailureBefore,
|
|
232
178
|
id: 'shell-failure-after',
|
|
@@ -238,41 +184,44 @@ test('OpenCode V2 carries real ledger matches through the source and packaged co
|
|
|
238
184
|
},
|
|
239
185
|
};
|
|
240
186
|
const shellFailureSnapshot = structuredClone(shellFailureAfter);
|
|
241
|
-
assert.equal(await
|
|
187
|
+
assert.equal(await driver.toolHook('execute.after')(shellFailureAfter), undefined);
|
|
242
188
|
assert.deepEqual(shellFailureAfter, shellFailureSnapshot, 'execute.after does not change a live shell tool result');
|
|
243
|
-
const shellDelivered = await context(
|
|
189
|
+
const shellDelivered = await context(driver, 'shellFailure');
|
|
244
190
|
assert.equal((shellDelivered.match(/Cue:\n/g) || []).length, 2,
|
|
245
191
|
'live shell action and failure events deliver both lessons');
|
|
246
192
|
assert.match(shellDelivered, /subject-case/, 'the failure lesson carries the commitlint diagnostic');
|
|
247
193
|
|
|
248
|
-
await toolCall(
|
|
249
|
-
assert.equal(await context(
|
|
194
|
+
await toolCall(driver, 'noLedger', 'no-ledger-action');
|
|
195
|
+
assert.equal(await context(driver, 'noLedger'), 'base system', 'an unrelated workspace without a ledger is silent');
|
|
250
196
|
|
|
251
|
-
await toolCall(
|
|
197
|
+
await toolCall(driver, 'sessionCleanup', 'session-cleanup-action');
|
|
252
198
|
const state = require(path.join(ROOT, 'hooks/scripts/lib/harness-state.js'));
|
|
253
199
|
const sessionState = state.getSessionDir(workspace, 'sessionCleanup', { workspace_root: workspace, session_id: 'sessionCleanup', host_id: 'opencode' });
|
|
254
200
|
const claims = fs.readdirSync(sessionState).filter(file => file.endsWith('.claim'));
|
|
255
201
|
assert.equal(claims.length, 1);
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
202
|
+
driver.emit('session.deleted', 'sessionCleanup');
|
|
203
|
+
await driver.waitFor(
|
|
204
|
+
() => claims.every(file => !fs.existsSync(path.join(sessionState, file))),
|
|
205
|
+
{ label: 'session invalidation releases undelivered matcher reservation' },
|
|
206
|
+
);
|
|
259
207
|
|
|
260
|
-
await
|
|
208
|
+
await driver.toolHook('execute.before')({
|
|
261
209
|
tool: 'bash', sessionID: 'disposal', agent: 'build', messageID: 'message-disposal', id: 'pending-action', input: { command },
|
|
262
210
|
});
|
|
263
211
|
} finally {
|
|
264
|
-
await
|
|
212
|
+
await driver.teardown();
|
|
265
213
|
}
|
|
266
214
|
|
|
267
|
-
const packaged = await
|
|
215
|
+
const packaged = await createV2Driver({ plugin: packagePlugin(), workspace, sessionLookup });
|
|
216
|
+
process.env.HARNESS_STATE_HOME = sharedStateHome;
|
|
268
217
|
try {
|
|
269
|
-
await packaged.
|
|
218
|
+
await packaged.toolHook('execute.before')({
|
|
270
219
|
tool: 'bash', sessionID: 'disposal', agent: 'build', messageID: 'message-disposal-2', id: 'pending-action-2', input: { command },
|
|
271
220
|
});
|
|
272
221
|
const packagedDelivery = await context(packaged, 'disposal');
|
|
273
222
|
assert.match(packagedDelivery, /subject-case/,
|
|
274
223
|
'disposing the prior carrier releases an undelivered claim, and the packaged loader resolves the shared matcher');
|
|
275
224
|
} finally {
|
|
276
|
-
await packaged.
|
|
225
|
+
await packaged.teardown();
|
|
277
226
|
}
|
|
278
227
|
});
|