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
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const { spawnSync } = require('child_process');
|
|
8
|
+
|
|
9
|
+
const HOOK_REL = path.join('hooks', 'scripts', 'agy-post-tool.js');
|
|
10
|
+
const PACKAGED_POST_TOOL_REL = path.join('plugins', 'harness-everything', 'hooks', 'scripts', 'agy-post-tool.js');
|
|
11
|
+
const PACKAGED_STOP_REL = path.join('plugins', 'harness-everything', 'hooks', 'scripts', 'agy-stop.js');
|
|
12
|
+
const { getSessionDir } = require(path.join('..', 'hooks', 'scripts', 'lib', 'harness-state'));
|
|
13
|
+
const { mapAgyPayloadToStatePersist } = require(path.join('..', 'hooks', 'scripts', 'agy-post-tool'));
|
|
14
|
+
|
|
15
|
+
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-516-agy-post-tool-'));
|
|
16
|
+
const tempStateHome = path.join(tempRoot, 'state-home');
|
|
17
|
+
fs.mkdirSync(tempStateHome, { recursive: true });
|
|
18
|
+
|
|
19
|
+
const originalStateHome = process.env.HARNESS_STATE_HOME;
|
|
20
|
+
process.env.HARNESS_STATE_HOME = tempStateHome;
|
|
21
|
+
|
|
22
|
+
function runHookRel(scriptRel, payload, expectedShape = {}) {
|
|
23
|
+
const childEnv = { ...process.env, HARNESS_STATE_HOME: tempStateHome };
|
|
24
|
+
delete childEnv.HARNESS_REQUIRE_VERIFICATION;
|
|
25
|
+
const run = spawnSync(process.execPath, [scriptRel], {
|
|
26
|
+
input: JSON.stringify(payload),
|
|
27
|
+
encoding: 'utf8',
|
|
28
|
+
env: childEnv,
|
|
29
|
+
timeout: 20000
|
|
30
|
+
});
|
|
31
|
+
assert.strictEqual(run.status, 0, `${scriptRel} exited non-zero: ${run.stderr}`);
|
|
32
|
+
let parsed;
|
|
33
|
+
try {
|
|
34
|
+
parsed = JSON.parse(run.stdout.trim());
|
|
35
|
+
} catch (_) {
|
|
36
|
+
assert.fail(`${scriptRel} stdout is not valid JSON: "${run.stdout}"`);
|
|
37
|
+
}
|
|
38
|
+
if (expectedShape.emptyObject) {
|
|
39
|
+
assert.deepStrictEqual(parsed, {}, `${scriptRel} must always emit {}`);
|
|
40
|
+
}
|
|
41
|
+
return parsed;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function runPostTool(payload) {
|
|
45
|
+
return runHookRel(HOOK_REL, payload, { emptyObject: true });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function runPackagedPostTool(payload) {
|
|
49
|
+
return runHookRel(PACKAGED_POST_TOOL_REL, payload, { emptyObject: true });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function runPackagedStop(payload) {
|
|
53
|
+
const parsed = runHookRel(PACKAGED_STOP_REL, payload);
|
|
54
|
+
assert.ok(parsed && (parsed.decision === 'allow' || parsed.decision === 'continue'), `unexpected Stop output: ${JSON.stringify(parsed)}`);
|
|
55
|
+
return parsed;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function readHandoff(ws, convId) {
|
|
59
|
+
const handoffFile = path.join(getSessionDir(ws, convId), 'handoff-state.json');
|
|
60
|
+
assert.ok(fs.existsSync(handoffFile), `handoff-state.json must exist for ${convId}`);
|
|
61
|
+
return JSON.parse(fs.readFileSync(handoffFile, 'utf8'));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function makeWs(name) {
|
|
65
|
+
const ws = path.join(tempRoot, name);
|
|
66
|
+
fs.mkdirSync(ws, { recursive: true });
|
|
67
|
+
return ws;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
// 1. Existing numeric exitCode 0 / nonzero & conflicting numeric codes
|
|
72
|
+
{
|
|
73
|
+
const ws = makeWs('ws-numeric');
|
|
74
|
+
const conv = 'conv-516-numeric';
|
|
75
|
+
|
|
76
|
+
runPostTool({
|
|
77
|
+
conversationId: conv,
|
|
78
|
+
workspacePaths: [ws],
|
|
79
|
+
toolCall: { name: 'write_file', args: { Path: path.join(ws, 'a.js'), Content: '1' } }
|
|
80
|
+
});
|
|
81
|
+
const afterEdit = readHandoff(ws, conv);
|
|
82
|
+
assert.ok(afterEdit.lastEditAt > 0, 'write_file must set lastEditAt');
|
|
83
|
+
|
|
84
|
+
// Numeric nonzero in toolResponse.exit_code -> failed
|
|
85
|
+
runPostTool({
|
|
86
|
+
conversationId: conv,
|
|
87
|
+
workspacePaths: [ws],
|
|
88
|
+
toolCall: { name: 'run_command', args: { CommandLine: 'npm test', Cwd: ws } },
|
|
89
|
+
toolResponse: { exit_code: 2 }
|
|
90
|
+
});
|
|
91
|
+
const afterFail = readHandoff(ws, conv);
|
|
92
|
+
assert.strictEqual(afterFail.status, 'failed');
|
|
93
|
+
assert.strictEqual(afterFail.exitCode, 2);
|
|
94
|
+
assert.ok(!afterFail.lastVerifyAt, 'nonzero exit_code must not grant lastVerifyAt');
|
|
95
|
+
|
|
96
|
+
// Conflicting numeric codes (0 + 1) -> nonzero wins, stays failed
|
|
97
|
+
runPostTool({
|
|
98
|
+
conversationId: conv,
|
|
99
|
+
workspacePaths: [ws],
|
|
100
|
+
toolCall: { name: 'run_command', args: { CommandLine: 'npm test', Cwd: ws } },
|
|
101
|
+
exitCode: 0,
|
|
102
|
+
toolResponse: { exit_code: 1 }
|
|
103
|
+
});
|
|
104
|
+
const afterConflictNum = readHandoff(ws, conv);
|
|
105
|
+
assert.strictEqual(afterConflictNum.status, 'failed');
|
|
106
|
+
assert.strictEqual(afterConflictNum.exitCode, 1);
|
|
107
|
+
assert.ok(!afterConflictNum.lastVerifyAt, 'conflicting numeric 0 and 1 must not grant lastVerifyAt');
|
|
108
|
+
|
|
109
|
+
// Unrecognized command + numeric exitCode: 0 -> no verification credit
|
|
110
|
+
runPostTool({
|
|
111
|
+
conversationId: conv,
|
|
112
|
+
workspacePaths: [ws],
|
|
113
|
+
toolCall: { name: 'run_command', args: { CommandLine: 'node -e "console.log(1)"', Cwd: ws } },
|
|
114
|
+
exitCode: 0
|
|
115
|
+
});
|
|
116
|
+
const afterUnrecognized = readHandoff(ws, conv);
|
|
117
|
+
assert.ok(!afterUnrecognized.lastVerifyAt, 'unrecognized command with exitCode: 0 must not grant lastVerifyAt');
|
|
118
|
+
|
|
119
|
+
// Recognized check + numeric exitCode: 0 -> advances lastVerifyAt & clears failed
|
|
120
|
+
runPostTool({
|
|
121
|
+
conversationId: conv,
|
|
122
|
+
workspacePaths: [ws],
|
|
123
|
+
toolCall: { name: 'run_command', args: { CommandLine: 'npm test', Cwd: ws } },
|
|
124
|
+
exitCode: 0
|
|
125
|
+
});
|
|
126
|
+
const afterPass = readHandoff(ws, conv);
|
|
127
|
+
assert.strictEqual(afterPass.status, 'idle');
|
|
128
|
+
assert.strictEqual(afterPass.lastVerifyExitCode, 0);
|
|
129
|
+
assert.ok(afterPass.lastVerifyAt >= afterEdit.lastEditAt, 'recognized check with exitCode: 0 must advance lastVerifyAt');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 2. Structured status / error flags & string toolResponse normalization
|
|
133
|
+
{
|
|
134
|
+
const ws = makeWs('ws-structured');
|
|
135
|
+
|
|
136
|
+
const failurePayloads = [
|
|
137
|
+
{ label: 'toolResponse.isError', extra: { toolResponse: { isError: true } } },
|
|
138
|
+
{ label: 'toolResponse.is_error', extra: { toolResponse: { is_error: true, exitCode: 0 } } },
|
|
139
|
+
{ label: 'toolResponse.success=false', extra: { toolResponse: { success: false } } },
|
|
140
|
+
{ label: 'toolResponse.ok=false', extra: { toolResponse: { ok: false, exitCode: 0 } } },
|
|
141
|
+
{ label: 'toolResponse.status=failed', extra: { toolResponse: { status: 'failed', exitCode: 0 } } },
|
|
142
|
+
{ label: 'payload.status=error', extra: { status: 'error' } },
|
|
143
|
+
{ label: 'payload.interrupted=true', extra: { interrupted: true } }
|
|
144
|
+
];
|
|
145
|
+
|
|
146
|
+
for (const item of failurePayloads) {
|
|
147
|
+
const conv = `conv-516-${item.label}`;
|
|
148
|
+
runPostTool({
|
|
149
|
+
conversationId: conv,
|
|
150
|
+
workspacePaths: [ws],
|
|
151
|
+
toolCall: { name: 'run_command', args: { CommandLine: 'npm test', Cwd: ws } },
|
|
152
|
+
...item.extra
|
|
153
|
+
});
|
|
154
|
+
const state = readHandoff(ws, conv);
|
|
155
|
+
assert.strictEqual(state.status, 'failed', `${item.label} must record status: failed`);
|
|
156
|
+
assert.ok(!state.lastVerifyAt, `${item.label} must not grant lastVerifyAt`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Positive control: isError: false WITH numeric exitCode: 0 advances lastVerifyAt
|
|
160
|
+
const convPos = 'conv-516-isError-false-pos';
|
|
161
|
+
runPostTool({
|
|
162
|
+
conversationId: convPos,
|
|
163
|
+
workspacePaths: [ws],
|
|
164
|
+
toolCall: { name: 'run_command', args: { CommandLine: 'npm test', Cwd: ws } },
|
|
165
|
+
toolResponse: { isError: false, exitCode: 0 }
|
|
166
|
+
});
|
|
167
|
+
const posState = readHandoff(ws, convPos);
|
|
168
|
+
assert.strictEqual(posState.status, 'idle');
|
|
169
|
+
assert.strictEqual(posState.lastVerifyExitCode, 0);
|
|
170
|
+
assert.ok(posState.lastVerifyAt > 0, 'isError: false with exitCode: 0 must grant lastVerifyAt');
|
|
171
|
+
|
|
172
|
+
// Negative control: success/completed flags WITHOUT numeric exitCode: 0 must NOT credit shell verification
|
|
173
|
+
for (const [idx, extra] of [
|
|
174
|
+
{ toolResponse: { isError: false } },
|
|
175
|
+
{ toolResponse: { success: true } },
|
|
176
|
+
{ toolResponse: { ok: true } },
|
|
177
|
+
{ toolResponse: { status: 'completed' } }
|
|
178
|
+
].entries()) {
|
|
179
|
+
const convNeg = `conv-516-no-exitcode-${idx}`;
|
|
180
|
+
runPostTool({
|
|
181
|
+
conversationId: convNeg,
|
|
182
|
+
workspacePaths: [ws],
|
|
183
|
+
toolCall: { name: 'run_command', args: { CommandLine: 'npm test', Cwd: ws } },
|
|
184
|
+
...extra
|
|
185
|
+
});
|
|
186
|
+
const negState = readHandoff(ws, convNeg);
|
|
187
|
+
assert.strictEqual(negState.status, 'idle');
|
|
188
|
+
assert.ok(!negState.lastVerifyAt, 'structured success without exitCode: 0 must not credit shell verification');
|
|
189
|
+
assert.ok(!negState.lastEditAt, 'recognized shell verification without exitCode must not bump lastEditAt');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// String toolResponse/result preserves stdout without trusting text as exit code
|
|
193
|
+
const mappedStr = mapAgyPayloadToStatePersist({
|
|
194
|
+
conversationId: 'conv-516-str',
|
|
195
|
+
workspacePaths: [ws],
|
|
196
|
+
toolCall: { name: 'run_command', args: { CommandLine: 'npm test', Cwd: ws } },
|
|
197
|
+
toolResponse: 'Command exited with code 0.'
|
|
198
|
+
});
|
|
199
|
+
assert.ok(mappedStr, 'string toolResponse must map to a state-persist payload');
|
|
200
|
+
assert.strictEqual(mappedStr.tool_response.stdout, 'Command exited with code 0.', 'string toolResponse must be preserved as stdout');
|
|
201
|
+
assert.strictEqual(mappedStr.exitCode, undefined, 'string toolResponse must not be trusted as exitCode');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// 3. Unidentified text markers in stdout / output / string toolResponse stay unknown; explicit host error + marker 0 stays failed
|
|
205
|
+
{
|
|
206
|
+
const ws = makeWs('ws-text-markers');
|
|
207
|
+
const conv = 'conv-516-text';
|
|
208
|
+
|
|
209
|
+
// Seed an edit and a pending failure to verify nothing is cleared or credited by text-only markers
|
|
210
|
+
runPostTool({
|
|
211
|
+
conversationId: conv,
|
|
212
|
+
workspacePaths: [ws],
|
|
213
|
+
toolCall: { name: 'write_file', args: { Path: path.join(ws, 'app.js'), Content: '1' } }
|
|
214
|
+
});
|
|
215
|
+
runPostTool({
|
|
216
|
+
conversationId: conv,
|
|
217
|
+
workspacePaths: [ws],
|
|
218
|
+
toolCall: { name: 'run_command', args: { CommandLine: 'npm test', Cwd: ws } },
|
|
219
|
+
error: 'prior failure'
|
|
220
|
+
});
|
|
221
|
+
const baseline = readHandoff(ws, conv);
|
|
222
|
+
assert.strictEqual(baseline.status, 'failed');
|
|
223
|
+
|
|
224
|
+
const unknownMarkerPayloads = [
|
|
225
|
+
{ toolResponse: { stdout: 'Command exited with code 0.' } },
|
|
226
|
+
{ output: 'Command exited with code 0.' },
|
|
227
|
+
{ toolResponse: 'Command exited with code 0.' },
|
|
228
|
+
{ result: 'Command exited with code 0.' },
|
|
229
|
+
{ toolResponse: { stdout: 'Command exited with code 0.\nCommand exited with code 1.' } },
|
|
230
|
+
{ output: 'Command exited with code 0.\nCommand exited with code 1.' }
|
|
231
|
+
];
|
|
232
|
+
|
|
233
|
+
for (const extra of unknownMarkerPayloads) {
|
|
234
|
+
runPostTool({
|
|
235
|
+
conversationId: conv,
|
|
236
|
+
workspacePaths: [ws],
|
|
237
|
+
toolCall: { name: 'run_command', args: { CommandLine: 'npm test', Cwd: ws } },
|
|
238
|
+
...extra
|
|
239
|
+
});
|
|
240
|
+
const after = readHandoff(ws, conv);
|
|
241
|
+
assert.strictEqual(after.status, 'failed', 'unknown/stdout text markers must preserve existing failed state');
|
|
242
|
+
assert.strictEqual(after.lastEditAt, baseline.lastEditAt, 'recognized check with unknown text marker must not bump lastEditAt');
|
|
243
|
+
assert.ok(!after.lastVerifyAt, 'unknown/stdout text markers must not grant lastVerifyAt');
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Explicit host error + marker 0 (or exitCode 0) stays failed
|
|
247
|
+
for (const [idx, extra] of [
|
|
248
|
+
{ error: 'explicit host error', exitCode: 0 },
|
|
249
|
+
{ error: 'Command exited with code 0.' },
|
|
250
|
+
{ error: 'explicit host error', output: 'Command exited with code 0.' }
|
|
251
|
+
].entries()) {
|
|
252
|
+
const convErr = `conv-516-explicit-err-${idx}`;
|
|
253
|
+
runPostTool({
|
|
254
|
+
conversationId: convErr,
|
|
255
|
+
workspacePaths: [ws],
|
|
256
|
+
toolCall: { name: 'run_command', args: { CommandLine: 'npm test', Cwd: ws } },
|
|
257
|
+
...extra
|
|
258
|
+
});
|
|
259
|
+
const errState = readHandoff(ws, convErr);
|
|
260
|
+
assert.strictEqual(errState.status, 'failed', `explicit host error case ${idx} must fail`);
|
|
261
|
+
assert.ok(!errState.lastVerifyAt, `explicit host error case ${idx} must not grant lastVerifyAt`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// 4. P516-B2 repair rows: error normalization precedence, no generic pending/background bypass, text-only lookalikes, and packaged PostToolUse -> handoff -> Stop positive control
|
|
266
|
+
{
|
|
267
|
+
const ws = makeWs('ws-b2-repair');
|
|
268
|
+
|
|
269
|
+
// Row 1: blank top-level error + nonblank nested error + exitCode 0 -> failed, verification stale, packaged Stop continue
|
|
270
|
+
for (const [idx, variant] of [
|
|
271
|
+
{ error: ' ', toolResponse: { error: 'explicit host error' }, exitCode: 0 },
|
|
272
|
+
{ error: '\t\n ', tool_response: { error: 'nested tool_response error', exitCode: 0 } },
|
|
273
|
+
{ error: ' ', result: { error: { message: 'nested result error' } }, exitCode: 0 }
|
|
274
|
+
].entries()) {
|
|
275
|
+
const conv = `conv-516-b2-nested-err-${idx}`;
|
|
276
|
+
runPackagedPostTool({
|
|
277
|
+
conversationId: conv,
|
|
278
|
+
workspacePaths: [ws],
|
|
279
|
+
toolCall: { name: 'write_file', args: { Path: path.join(ws, `edit-${idx}.js`), Content: '1' } }
|
|
280
|
+
});
|
|
281
|
+
const afterEdit = readHandoff(ws, conv);
|
|
282
|
+
assert.ok(afterEdit.lastEditAt > 0, `row 1.${idx}: write_file must set lastEditAt`);
|
|
283
|
+
|
|
284
|
+
const mapped = mapAgyPayloadToStatePersist({
|
|
285
|
+
conversationId: conv,
|
|
286
|
+
workspacePaths: [ws],
|
|
287
|
+
toolCall: { name: 'run_command', args: { CommandLine: 'npm test', Cwd: ws } },
|
|
288
|
+
...variant
|
|
289
|
+
});
|
|
290
|
+
assert.strictEqual(mapped.hook_event_name, 'PostToolUseFailure', `row 1.${idx}: blank top-level error must fall back to nested error`);
|
|
291
|
+
assert.strictEqual(mapped.exitCode, undefined, `row 1.${idx}: exitCode 0 must be withheld on explicit nested error`);
|
|
292
|
+
|
|
293
|
+
runPackagedPostTool({
|
|
294
|
+
conversationId: conv,
|
|
295
|
+
workspacePaths: [ws],
|
|
296
|
+
toolCall: { name: 'run_command', args: { CommandLine: 'npm test', Cwd: ws } },
|
|
297
|
+
...variant
|
|
298
|
+
});
|
|
299
|
+
const state = readHandoff(ws, conv);
|
|
300
|
+
assert.strictEqual(state.status, 'failed', `row 1.${idx}: blank top-level error + nonblank nested error + exitCode 0 must stay failed`);
|
|
301
|
+
assert.ok(!state.lastVerifyAt, `row 1.${idx}: must leave lastVerifyAt unset (verification stale)`);
|
|
302
|
+
|
|
303
|
+
const stopRes = runPackagedStop({
|
|
304
|
+
conversationId: conv,
|
|
305
|
+
workspacePaths: [ws],
|
|
306
|
+
continuationActive: false,
|
|
307
|
+
terminationReason: 'NO_TOOL_CALL'
|
|
308
|
+
});
|
|
309
|
+
assert.strictEqual(stopRes.decision, 'continue', `row 1.${idx}: packaged Stop must return continue`);
|
|
310
|
+
assert.ok(stopRes.reason.includes('pending tool failure'), `row 1.${idx}: Stop reason must cite pending tool failure`);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Row 2: status: "queued" (and background: true) + recognized check + numeric zero -> normal credit (no bypass)
|
|
314
|
+
for (const [idx, extra] of [
|
|
315
|
+
{ status: 'queued', exitCode: 0 },
|
|
316
|
+
{ background: true, exitCode: 0 },
|
|
317
|
+
{ toolResponse: { status: 'queued', exit_code: 0 } },
|
|
318
|
+
{ toolResponse: { background: true, exitCode: 0 } },
|
|
319
|
+
{ isBackground: true, exitCode: 0 }
|
|
320
|
+
].entries()) {
|
|
321
|
+
const conv = `conv-516-b2-queued-verify-${idx}`;
|
|
322
|
+
runPackagedPostTool({
|
|
323
|
+
conversationId: conv,
|
|
324
|
+
workspacePaths: [ws],
|
|
325
|
+
toolCall: { name: 'write_file', args: { Path: path.join(ws, `q-${idx}.js`), Content: '1' } }
|
|
326
|
+
});
|
|
327
|
+
const afterEdit = readHandoff(ws, conv);
|
|
328
|
+
assert.ok(afterEdit.lastEditAt > 0);
|
|
329
|
+
|
|
330
|
+
const checkPayload = {
|
|
331
|
+
conversationId: conv,
|
|
332
|
+
workspacePaths: [ws],
|
|
333
|
+
toolCall: { name: 'run_command', args: { CommandLine: 'npm test', Cwd: ws } },
|
|
334
|
+
...extra
|
|
335
|
+
};
|
|
336
|
+
const mapped = mapAgyPayloadToStatePersist(checkPayload);
|
|
337
|
+
assert.ok(mapped !== null, `row 2.${idx}: generic queued/background metadata must not bypass state-persist`);
|
|
338
|
+
|
|
339
|
+
runPackagedPostTool(checkPayload);
|
|
340
|
+
const afterVerify = readHandoff(ws, conv);
|
|
341
|
+
assert.strictEqual(afterVerify.status, 'idle', `row 2.${idx}: recognized check with exitCode 0 must stay idle`);
|
|
342
|
+
assert.strictEqual(afterVerify.lastVerifyExitCode, 0, `row 2.${idx}: must record lastVerifyExitCode 0`);
|
|
343
|
+
assert.ok(afterVerify.lastVerifyAt >= afterEdit.lastEditAt, `row 2.${idx}: must advance lastVerifyAt normally`);
|
|
344
|
+
|
|
345
|
+
const stopRes = runPackagedStop({
|
|
346
|
+
conversationId: conv,
|
|
347
|
+
workspacePaths: [ws],
|
|
348
|
+
continuationActive: false,
|
|
349
|
+
terminationReason: 'NO_TOOL_CALL'
|
|
350
|
+
});
|
|
351
|
+
assert.deepStrictEqual(stopRes, { decision: 'allow' }, `row 2.${idx}: packaged Stop must allow after credited zero`);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Row 3: status: "queued" (and background: true) on an in-workspace write_file -> edit persisted (no bypass)
|
|
355
|
+
for (const [idx, extra] of [
|
|
356
|
+
{ status: 'queued' },
|
|
357
|
+
{ background: true },
|
|
358
|
+
{ toolResponse: { status: 'queued' } }
|
|
359
|
+
].entries()) {
|
|
360
|
+
const conv = `conv-516-b2-queued-write-${idx}`;
|
|
361
|
+
const writePayload = {
|
|
362
|
+
conversationId: conv,
|
|
363
|
+
workspacePaths: [ws],
|
|
364
|
+
toolCall: { name: 'write_file', args: { Path: path.join(ws, `write-${idx}.js`), Content: 'export const x = 1;' } },
|
|
365
|
+
...extra
|
|
366
|
+
};
|
|
367
|
+
const mapped = mapAgyPayloadToStatePersist(writePayload);
|
|
368
|
+
assert.ok(mapped !== null, `row 3.${idx}: write_file with generic metadata must not bypass state-persist`);
|
|
369
|
+
|
|
370
|
+
runPackagedPostTool(writePayload);
|
|
371
|
+
const afterWrite = readHandoff(ws, conv);
|
|
372
|
+
assert.ok(afterWrite.lastEditAt > 0, `row 3.${idx}: in-workspace write_file with ${JSON.stringify(extra)} must persist lastEditAt`);
|
|
373
|
+
|
|
374
|
+
const stopRes = runPackagedStop({
|
|
375
|
+
conversationId: conv,
|
|
376
|
+
workspacePaths: [ws],
|
|
377
|
+
continuationActive: false,
|
|
378
|
+
terminationReason: 'model_stop'
|
|
379
|
+
});
|
|
380
|
+
assert.strictEqual(stopRes.decision, 'continue', `row 3.${idx}: unverified persisted edit must make packaged Stop continue`);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// Row 4: text-only "Command exited with code 0." / "Tool is running as a background task" in stdout -> no credit, no bypass
|
|
384
|
+
for (const [idx, caseDef] of [
|
|
385
|
+
{ cmd: 'npm test', extra: { toolResponse: { stdout: 'Command exited with code 0.' } } },
|
|
386
|
+
{ cmd: 'npm test', extra: { output: 'Command exited with code 0.' } },
|
|
387
|
+
{ cmd: 'npm test', extra: { toolResponse: { stdout: 'Tool is running as a background task' } } },
|
|
388
|
+
{ cmd: 'npm test', extra: { output: 'Tool is running as a background task' } },
|
|
389
|
+
{ cmd: 'node dev-server.js', extra: { toolResponse: { stdout: 'Tool is running as a background task' } } },
|
|
390
|
+
{ cmd: 'node dev-server.js', extra: { output: 'Tool is running as a background task' } }
|
|
391
|
+
].entries()) {
|
|
392
|
+
const conv = `conv-516-b2-text-only-${idx}`;
|
|
393
|
+
runPackagedPostTool({
|
|
394
|
+
conversationId: conv,
|
|
395
|
+
workspacePaths: [ws],
|
|
396
|
+
toolCall: { name: 'write_file', args: { Path: path.join(ws, `t-${idx}.js`), Content: '1' } }
|
|
397
|
+
});
|
|
398
|
+
const before = readHandoff(ws, conv);
|
|
399
|
+
|
|
400
|
+
const textPayload = {
|
|
401
|
+
conversationId: conv,
|
|
402
|
+
workspacePaths: [ws],
|
|
403
|
+
toolCall: { name: 'run_command', args: { CommandLine: caseDef.cmd, Cwd: ws } },
|
|
404
|
+
...caseDef.extra
|
|
405
|
+
};
|
|
406
|
+
const mapped = mapAgyPayloadToStatePersist(textPayload);
|
|
407
|
+
assert.ok(mapped !== null, `row 4.${idx}: text-only lookalike must not bypass state-persist`);
|
|
408
|
+
assert.strictEqual(mapped.exitCode, undefined, `row 4.${idx}: text-only lookalike must not synthesize exitCode`);
|
|
409
|
+
|
|
410
|
+
runPackagedPostTool(textPayload);
|
|
411
|
+
const after = readHandoff(ws, conv);
|
|
412
|
+
assert.ok(!after.lastVerifyAt, `row 4.${idx}: text-only lookalike must not grant verification credit`);
|
|
413
|
+
if (caseDef.cmd === 'npm test') {
|
|
414
|
+
assert.strictEqual(after.lastEditAt, before.lastEditAt, `row 4.${idx}: recognized check with unknown text must preserve lastEditAt`);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const stopRes = runPackagedStop({
|
|
418
|
+
conversationId: conv,
|
|
419
|
+
workspacePaths: [ws],
|
|
420
|
+
continuationActive: false,
|
|
421
|
+
terminationReason: 'NO_TOOL_CALL'
|
|
422
|
+
});
|
|
423
|
+
assert.strictEqual(stopRes.decision, 'continue', `row 4.${idx}: packaged Stop must continue when no verification credit was earned`);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// Row 5: positive control - clean numeric zero on a recognized check -> credit + packaged Stop allow
|
|
427
|
+
{
|
|
428
|
+
const conv = 'conv-516-b2-positive-control';
|
|
429
|
+
runPackagedPostTool({
|
|
430
|
+
conversationId: conv,
|
|
431
|
+
workspacePaths: [ws],
|
|
432
|
+
toolCall: { name: 'write_file', args: { Path: path.join(ws, 'pos.js'), Content: '1' } }
|
|
433
|
+
});
|
|
434
|
+
const afterEdit = readHandoff(ws, conv);
|
|
435
|
+
assert.strictEqual(
|
|
436
|
+
runPackagedStop({
|
|
437
|
+
conversationId: conv,
|
|
438
|
+
workspacePaths: [ws],
|
|
439
|
+
continuationActive: false,
|
|
440
|
+
terminationReason: 'NO_TOOL_CALL'
|
|
441
|
+
}).decision,
|
|
442
|
+
'continue',
|
|
443
|
+
'row 5: packaged Stop must continue before verification'
|
|
444
|
+
);
|
|
445
|
+
|
|
446
|
+
runPackagedPostTool({
|
|
447
|
+
conversationId: conv,
|
|
448
|
+
workspacePaths: [ws],
|
|
449
|
+
toolCall: { name: 'run_command', args: { CommandLine: 'npm test', Cwd: ws } },
|
|
450
|
+
exitCode: 0
|
|
451
|
+
});
|
|
452
|
+
const afterVerify = readHandoff(ws, conv);
|
|
453
|
+
assert.strictEqual(afterVerify.status, 'idle');
|
|
454
|
+
assert.strictEqual(afterVerify.lastVerifyExitCode, 0);
|
|
455
|
+
assert.ok(afterVerify.lastVerifyAt >= afterEdit.lastEditAt, 'row 5: clean numeric zero must advance lastVerifyAt');
|
|
456
|
+
|
|
457
|
+
const stopAllow = runPackagedStop({
|
|
458
|
+
conversationId: conv,
|
|
459
|
+
workspacePaths: [ws],
|
|
460
|
+
continuationActive: false,
|
|
461
|
+
terminationReason: 'NO_TOOL_CALL'
|
|
462
|
+
});
|
|
463
|
+
assert.deepStrictEqual(stopAllow, { decision: 'allow' }, 'row 5: packaged Stop must allow after clean numeric zero');
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
console.log('AGY PostToolUse completion normalization (P516-B) verified.');
|
|
468
|
+
} finally {
|
|
469
|
+
if (originalStateHome === undefined) delete process.env.HARNESS_STATE_HOME;
|
|
470
|
+
else process.env.HARNESS_STATE_HOME = originalStateHome;
|
|
471
|
+
fs.rmSync(tempRoot, { recursive: true, force: true });
|
|
472
|
+
}
|