harness-everything 0.53.0 → 0.54.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.
Files changed (83) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/AGENTS.md +3 -1
  4. package/CHANGELOG.md +26 -0
  5. package/bin/cli.js +1 -0
  6. package/ci/action-gate.test.js +1 -1
  7. package/ci/invariant-routing.test.js +22 -3
  8. package/ci/mechanism-2al-codex-hooks-compat.test.js +56 -2
  9. package/ci/mechanism-2at-fable-execution-phases.test.js +38 -0
  10. package/ci/mechanism-349-ci-change-scope.test.js +78 -57
  11. package/ci/mechanism-397-cycle-import.test.js +18 -3
  12. package/ci/mechanism-check-packet-write-set.test.js +232 -0
  13. package/ci/mechanism-codex-hook-results.test.js +145 -0
  14. package/ci/mechanism-codex-prompt-pass-through.test.js +8 -4
  15. package/ci/mechanism-error-handling-map.test.js +219 -0
  16. package/ci/mechanism-report-writer.test.js +335 -0
  17. package/ci/openai-plugin-runtime.test.js +2 -1
  18. package/ci/prompt-contract-regressions.test.js +6 -2
  19. package/ci/router-workflow-plan.test.js +50 -7
  20. package/docs/architecture.md +4 -3
  21. package/docs/error-handling/README.md +250 -0
  22. package/docs/error-handling/actions/c1-action-map.md +89 -0
  23. package/docs/error-handling/actions/c2-action-map.md +22 -0
  24. package/docs/error-handling/actions/c3-action-map.md +26 -0
  25. package/docs/error-handling/actions/c5-action-map.md +31 -0
  26. package/docs/error-handling/actions/c6-action-map.md +37 -0
  27. package/docs/error-handling/actions/c7-action-map.md +18 -0
  28. package/docs/error-handling/actions/e0002-action-map.md +101 -0
  29. package/docs/error-handling/activity.puml +84 -0
  30. package/docs/error-handling/details/c1-authority-conformance.md +93 -0
  31. package/docs/error-handling/details/c2-test-root-containment.md +35 -0
  32. package/docs/error-handling/details/c3-mode-ownership.md +50 -0
  33. package/docs/error-handling/details/c5-host-replay-contract.md +40 -0
  34. package/docs/error-handling/details/c6-packet-briefing.md +65 -0
  35. package/docs/error-handling/details/c7-write-set-check.md +54 -0
  36. package/docs/error-handling/details/e0002-capture-evidence.md +93 -0
  37. package/docs/error-handling/details/e0002-report-writer.md +116 -0
  38. package/docs/error-handling/nodes.yaml +44 -0
  39. package/docs/error-handling/registry.md +59 -0
  40. package/docs/error-handling/templates/packet-briefing.md +45 -0
  41. package/docs/platform-capabilities.md +20 -1
  42. package/fable-mode/SKILL.md +5 -5
  43. package/fable-mode/execution-guardrails/SKILL.md +1 -1
  44. package/fable-mode/fable-haiku/SKILL.md +1 -1
  45. package/fable-mode/fable-opus/SKILL.md +1 -1
  46. package/fable-mode/fable-sonnet/SKILL.md +1 -1
  47. package/fable-mode/references/execution-phases.md +26 -4
  48. package/hooks/scripts/action-gate.js +5 -0
  49. package/hooks/scripts/codex-action-gate-post.js +3 -12
  50. package/hooks/scripts/codex-user-prompt.js +2 -3
  51. package/hooks/scripts/contract-test.js +17 -7
  52. package/hooks/scripts/lib/codex-tool-outcome.js +28 -0
  53. package/hooks/scripts/rule-of-3-tracker.js +11 -4
  54. package/hooks/scripts/state-persist.js +15 -9
  55. package/hooks/scripts/subagent-scope-guard.js +32 -25
  56. package/hooks/scripts/subagent-start.js +1 -1
  57. package/hooks/scripts/subagent-stop.js +14 -3
  58. package/opencode-plugin/plugin.json +1 -1
  59. package/package.json +2 -1
  60. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  61. package/plugins/harness-everything/hooks/hooks.json +6 -6
  62. package/plugins/harness-everything/hooks/scripts/action-gate.js +5 -0
  63. package/plugins/harness-everything/hooks/scripts/codex-action-gate-post.js +3 -12
  64. package/plugins/harness-everything/hooks/scripts/codex-user-prompt.js +2 -3
  65. package/plugins/harness-everything/hooks/scripts/contract-test.js +17 -7
  66. package/plugins/harness-everything/hooks/scripts/lib/codex-tool-outcome.js +28 -0
  67. package/plugins/harness-everything/hooks/scripts/rule-of-3-tracker.js +11 -4
  68. package/plugins/harness-everything/hooks/scripts/state-persist.js +15 -9
  69. package/plugins/harness-everything/hooks/scripts/subagent-scope-guard.js +32 -25
  70. package/plugins/harness-everything/hooks/scripts/subagent-start.js +1 -1
  71. package/plugins/harness-everything/hooks/scripts/subagent-stop.js +14 -3
  72. package/plugins/harness-everything/plugin.json +1 -1
  73. package/plugins/harness-everything/skills/fable-mode/SKILL.md +5 -5
  74. package/plugins/harness-everything/skills/fable-mode/execution-guardrails/SKILL.md +1 -1
  75. package/plugins/harness-everything/skills/fable-mode/fable-haiku/SKILL.md +1 -1
  76. package/plugins/harness-everything/skills/fable-mode/fable-opus/SKILL.md +1 -1
  77. package/plugins/harness-everything/skills/fable-mode/fable-sonnet/SKILL.md +1 -1
  78. package/plugins/harness-everything/skills/fable-mode/references/execution-phases.md +26 -4
  79. package/sbom.cdx.json +7 -7
  80. package/scripts/check-packet-write-set.js +155 -0
  81. package/scripts/codex-hooks-compat.js +46 -5
  82. package/scripts/error-handling-map.js +288 -0
  83. package/scripts/report-writer.js +261 -0
@@ -0,0 +1,335 @@
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
+ const { test } = require('node:test');
9
+
10
+ const ROOT = path.resolve(__dirname, '..');
11
+ const CLI = path.join(ROOT, 'scripts', 'report-writer.js');
12
+
13
+ function tempDir(t) {
14
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-report-writer-'));
15
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
16
+ return dir;
17
+ }
18
+
19
+ function run(args, { preload, env = process.env } = {}) {
20
+ return spawnSync(process.execPath, [...(preload ? ['-r', preload] : []), CLI, ...args], {
21
+ cwd: ROOT,
22
+ env,
23
+ encoding: 'utf8',
24
+ });
25
+ }
26
+
27
+ function assertOk(result) {
28
+ assert.equal(result.status, 0, result.stderr || result.stdout);
29
+ }
30
+
31
+ function assertRejected(result, message) {
32
+ assert.notEqual(result.status, 0, result.stdout);
33
+ assert.match(result.stderr, /report-writer:/);
34
+ if (message) assert.match(result.stderr, message);
35
+ }
36
+
37
+ function writeArgs(output, status, mode, ...extra) {
38
+ return ['write', '--output', output, '--status', status, ...mode, ...extra];
39
+ }
40
+
41
+ function readbackHook(dir) {
42
+ const hook = path.join(dir, 'fail-readback.cjs');
43
+ fs.writeFileSync(hook, `
44
+ const fs = require('node:fs');
45
+ const path = require('node:path');
46
+ const readFileSync = fs.readFileSync;
47
+ fs.readFileSync = function (file, ...args) {
48
+ const actual = path.resolve(String(file));
49
+ const target = path.resolve(process.env.REPORT_WRITER_FAIL_PATH);
50
+ const mode = process.env.REPORT_WRITER_FAIL_MODE;
51
+ const staged = path.dirname(actual) === path.dirname(target)
52
+ && path.basename(actual).startsWith('.' + path.basename(target) + '.')
53
+ && path.basename(actual).endsWith('.tmp');
54
+ if ((mode === 'staged' && staged) || (mode === 'published' && actual === target)) {
55
+ const error = new Error('controlled read-back failure');
56
+ error.code = 'EIO';
57
+ throw error;
58
+ }
59
+ return readFileSync.call(this, file, ...args);
60
+ };
61
+ `);
62
+ return hook;
63
+ }
64
+
65
+ test('writes DONE from --context and the checker accepts the exact artifact', t => {
66
+ const dir = tempDir(t);
67
+ const output = path.join(dir, 'report.md');
68
+ const result = run(writeArgs(output, 'DONE', ['--context', 'Summary\nEvidence']))
69
+ assertOk(result);
70
+ assert.equal(fs.readFileSync(output, 'utf8'), 'Summary\nEvidence\nSTATUS: DONE\n');
71
+ assertOk(run(['check', '--file', output]));
72
+ });
73
+
74
+ test('preserves body-file CRLF bytes and accepts numeric zero status', t => {
75
+ const dir = tempDir(t);
76
+ const body = path.join(dir, 'body.md');
77
+ const output = path.join(dir, 'report.md');
78
+ fs.writeFileSync(body, 'First\r\nSecond\r\n');
79
+ assertOk(run(writeArgs(output, '0', ['--body-file', body])));
80
+ assert.equal(fs.readFileSync(output, 'utf8'), 'First\r\nSecond\r\nSTATUS: DONE\r\n');
81
+ });
82
+
83
+ test('writes BLOCKED with a nonempty single-line reason', t => {
84
+ const dir = tempDir(t);
85
+ const output = path.join(dir, 'report.md');
86
+ assertOk(run(writeArgs(output, 'BLOCKED', ['--context', 'Work stopped'], '--reason', 'verification unavailable')));
87
+ assert.equal(fs.readFileSync(output, 'utf8'), 'Work stopped\nSTATUS: BLOCKED: verification unavailable\n');
88
+ assertOk(run(['check', '--file', output]));
89
+ });
90
+
91
+ test('maps a nonzero status and repeated --error values to one reason line', t => {
92
+ const dir = tempDir(t);
93
+ const output = path.join(dir, 'report.md');
94
+ assertOk(run(writeArgs(output, '2', ['--context', 'Work stopped'], '--error', 'build failed', '--error', 'required gate unavailable')));
95
+ assert.equal(fs.readFileSync(output, 'utf8'), 'Work stopped\nSTATUS: BLOCKED: build failed; required gate unavailable\n');
96
+ });
97
+
98
+ test('revises an existing artifact as one complete report', t => {
99
+ const dir = tempDir(t);
100
+ const output = path.join(dir, 'report.md');
101
+ fs.writeFileSync(output, 'Old body\nSTATUS: DONE\n');
102
+ assertOk(run(writeArgs(output, 'BLOCKED', ['--context', 'New body'], '--reason', 'gate failed')));
103
+ assert.equal(fs.readFileSync(output, 'utf8'), 'New body\nSTATUS: BLOCKED: gate failed\n');
104
+ assertOk(run(['check', '--file', output]));
105
+ });
106
+
107
+ test('imports a raw Codex report without altering its source', t => {
108
+ const dir = tempDir(t);
109
+ const raw = path.join(dir, 'raw.txt');
110
+ const output = path.join(dir, 'report.md');
111
+ const rawBytes = Buffer.from('Summary\r\nEvidence\r\nSTATUS: DONE\r\n');
112
+ fs.writeFileSync(raw, rawBytes);
113
+ const result = run(writeArgs(output, '0', ['--from-codex-output', raw]));
114
+ assertOk(result);
115
+ assert.doesNotMatch(result.stderr, /stripped.*host label/i);
116
+ assert.deepEqual(fs.readFileSync(raw), rawBytes);
117
+ assert.equal(fs.readFileSync(output, 'utf8'), rawBytes.toString('utf8'));
118
+ assertOk(run(['check', '--file', output]));
119
+ });
120
+
121
+ test('strips only one valid terminal host label and reports the extraction', t => {
122
+ const dir = tempDir(t);
123
+ const raw = path.join(dir, 'raw.txt');
124
+ const output = path.join(dir, 'report.md');
125
+ const rawBytes = Buffer.from('Summary\nSTATUS: DONE\n<!-- harness-label {"v":1,"validity":"actionable"} -->\n');
126
+ fs.writeFileSync(raw, rawBytes);
127
+ const result = run(writeArgs(output, 'DONE', ['--from-codex-output', raw]));
128
+ assertOk(result);
129
+ assert.match(result.stderr, /stripped.*host label/i);
130
+ assert.deepEqual(fs.readFileSync(raw), rawBytes);
131
+ assert.equal(fs.readFileSync(output, 'utf8'), 'Summary\nSTATUS: DONE\n');
132
+ assertOk(run(['check', '--file', output]));
133
+ });
134
+
135
+ test('assembles a DONE report from raw body text without STATUS', t => {
136
+ const dir = tempDir(t);
137
+ const raw = path.join(dir, 'raw.txt');
138
+ const output = path.join(dir, 'report.md');
139
+ const rawBytes = Buffer.from('Summary\r\nEvidence\r\n');
140
+ fs.writeFileSync(raw, rawBytes);
141
+
142
+ const result = run(writeArgs(output, 'DONE', ['--from-codex-output', raw]));
143
+
144
+ assertOk(result);
145
+ assert.doesNotMatch(result.stderr, /stripped.*host label/i);
146
+ assert.deepEqual(fs.readFileSync(raw), rawBytes);
147
+ assert.deepEqual(fs.readFileSync(output), Buffer.from('Summary\r\nEvidence\r\nSTATUS: DONE\r\n'));
148
+ assertOk(run(['check', '--file', output]));
149
+ });
150
+
151
+ test('assembles BLOCKED from a raw body, blank line, and one EOF host label', t => {
152
+ const dir = tempDir(t);
153
+ const raw = path.join(dir, 'raw.txt');
154
+ const output = path.join(dir, 'report.md');
155
+ const rawBytes = Buffer.from('Summary\n\nEvidence\n\n<!-- harness-label {"v":1,"validity":"actionable","tier":"tier2","intents":["test"],"workflow":"iterative-single","skills":[]} -->');
156
+ const body = rawBytes.subarray(0, rawBytes.lastIndexOf(Buffer.from('<!-- harness-label')));
157
+ fs.writeFileSync(raw, rawBytes);
158
+
159
+ const result = run(writeArgs(output, 'BLOCKED', ['--from-codex-output', raw], '--reason', 'verification unavailable'));
160
+
161
+ assertOk(result);
162
+ assert.match(result.stderr, /stripped.*host label/i);
163
+ assert.deepEqual(fs.readFileSync(raw), rawBytes);
164
+ assert.deepEqual(fs.readFileSync(output), Buffer.concat([body, Buffer.from('STATUS: BLOCKED: verification unavailable\n')]));
165
+ assertOk(run(['check', '--file', output]));
166
+ });
167
+
168
+ test('rejects embedded STATUS in body without changing an existing target', t => {
169
+ const dir = tempDir(t);
170
+ const output = path.join(dir, 'report.md');
171
+ const before = Buffer.from('Keep this report\nSTATUS: DONE\n');
172
+ fs.writeFileSync(output, before);
173
+ const result = run(writeArgs(output, 'DONE', ['--context', 'Summary\nSTATUS: DONE']));
174
+ assertRejected(result, /STATUS/);
175
+ assert.deepEqual(fs.readFileSync(output), before);
176
+ assert.deepEqual(fs.readdirSync(dir), ['report.md']);
177
+ });
178
+
179
+ test('rejects label markers and malformed or duplicate body controls without creating an artifact', t => {
180
+ const dir = tempDir(t);
181
+ const output = path.join(dir, 'report.md');
182
+ for (const body of [
183
+ 'Summary <!-- harness-label {"v":1} -->',
184
+ 'STATUS: broken',
185
+ 'STATUS: DONE\nSTATUS: DONE',
186
+ ]) {
187
+ assertRejected(run(writeArgs(output, 'DONE', ['--context', body])));
188
+ assert.equal(fs.existsSync(output), false);
189
+ }
190
+ assert.deepEqual(fs.readdirSync(dir), []);
191
+ });
192
+
193
+ test('rejects missing, blank, multiline, or unused outcome reasons without changing the target', t => {
194
+ const dir = tempDir(t);
195
+ const output = path.join(dir, 'report.md');
196
+ const before = Buffer.from('Existing\nSTATUS: DONE\n');
197
+ fs.writeFileSync(output, before);
198
+ const cases = [
199
+ ['BLOCKED', ['--context', 'body']],
200
+ ['1', ['--context', 'body'], '--reason', ' '],
201
+ ['BLOCKED', ['--context', 'body'], '--reason', 'line one\nline two'],
202
+ ['DONE', ['--context', 'body'], '--reason', 'not used'],
203
+ ['DONE\nSTATUS: BLOCKED: injected', ['--context', 'body']],
204
+ ];
205
+ for (const [status, mode, ...extra] of cases) {
206
+ assertRejected(run(writeArgs(output, status, mode, ...extra)));
207
+ assert.deepEqual(fs.readFileSync(output), before);
208
+ }
209
+ });
210
+
211
+ test('rejects mismatched, malformed, duplicate, or trailing Codex controls and preserves both files', t => {
212
+ const dir = tempDir(t);
213
+ const raw = path.join(dir, 'raw.txt');
214
+ const output = path.join(dir, 'report.md');
215
+ const before = Buffer.from('Keep this report\nSTATUS: DONE\n');
216
+ fs.writeFileSync(output, before);
217
+ const invalidRaw = [
218
+ ['Summary\nSTATUS: BLOCKED: wrong reason\n', 'DONE'],
219
+ ['Summary\nSTATUS: BLOCKED: wrong reason\n', 'BLOCKED', '--reason', 'expected reason'],
220
+ ['Summary\nSTATUS: FINISHED\n', 'DONE'],
221
+ ['Summary\nSTATUS: malformed\nSTATUS: DONE\n', 'DONE'],
222
+ ['Summary\nSTATUS: DONE\nSTATUS: DONE\n', 'DONE'],
223
+ ['Summary\nSTATUS: DONE\n\n', 'DONE'],
224
+ ['Summary\nSTATUS: DONE\ntext after status\n', 'DONE'],
225
+ ['Summary\nSTATUS: DONE\n\n<!-- harness-label {"v":1} -->', 'DONE'],
226
+ ['Summary\nSTATUS: DONE\ntext\n<!-- harness-label {"v":1} -->', 'DONE'],
227
+ ['Summary\nSTATUS: DONE\n<!-- harness-label {bad json} -->\n', 'DONE'],
228
+ ['Summary\nSTATUS: DONE\n<!-- harness-label [] -->\n', 'DONE'],
229
+ ['Summary\nSTATUS: DONE\n<!-- harness-label {"v":1} -->\n<!-- harness-label {"v":1} -->\n', 'DONE'],
230
+ ['Summary\nSTATUS: DONE\n<!-- harness-label {"v":1} -->\ntrailing text', 'DONE'],
231
+ ['Summary <!-- harness-label {"v":1} -->\nSTATUS: DONE\n', 'DONE'],
232
+ ];
233
+ for (const [contents, status, ...extra] of invalidRaw) {
234
+ const rawBytes = Buffer.from(contents);
235
+ fs.writeFileSync(raw, rawBytes);
236
+ assertRejected(run(writeArgs(output, status, ['--from-codex-output', raw], ...extra)));
237
+ assert.deepEqual(fs.readFileSync(raw), rawBytes);
238
+ assert.deepEqual(fs.readFileSync(output), before);
239
+ }
240
+
241
+ fs.rmSync(output);
242
+ fs.writeFileSync(raw, 'Summary\nSTATUS: BLOCKED: wrong reason\n');
243
+ assertRejected(run(writeArgs(output, 'BLOCKED', ['--from-codex-output', raw], '--reason', 'expected reason')));
244
+ assert.equal(fs.existsSync(output), false);
245
+ });
246
+
247
+ test('rejects raw-input/output aliases', t => {
248
+ const dir = tempDir(t);
249
+ const raw = path.join(dir, 'raw.txt');
250
+ const before = Buffer.from('Summary\nSTATUS: DONE\n');
251
+ fs.writeFileSync(raw, before);
252
+ assertRejected(run(writeArgs(raw, 'DONE', ['--from-codex-output', raw])), /alias/i);
253
+ assert.deepEqual(fs.readFileSync(raw), before);
254
+ });
255
+
256
+ test('rejects a body-file/output alias before replacing the source', t => {
257
+ const dir = tempDir(t);
258
+ const body = path.join(dir, 'body.md');
259
+ const before = Buffer.from('Summary');
260
+ fs.writeFileSync(body, before);
261
+ assertRejected(run(writeArgs(body, 'DONE', ['--body-file', body])), /alias/i);
262
+ assert.deepEqual(fs.readFileSync(body), before);
263
+ });
264
+
265
+ test('requires exactly one body mode and rejects conflicting reason flags', t => {
266
+ const dir = tempDir(t);
267
+ const output = path.join(dir, 'report.md');
268
+ assertRejected(run(['write', '--output', output, '--status', 'DONE']));
269
+ assertRejected(run(['write', '--output', output, '--status', 'DONE', '--context', 'body', '--body-file', 'body.md']));
270
+ assertRejected(run(writeArgs(output, 'BLOCKED', ['--context', 'body'], '--reason', 'one', '--error', 'two')));
271
+ assert.equal(fs.existsSync(output), false);
272
+ });
273
+
274
+ test('check accepts one terminal status with LF or CRLF and rejects other control layouts', t => {
275
+ const dir = tempDir(t);
276
+ const file = path.join(dir, 'report.md');
277
+ for (const valid of ['Summary\nSTATUS: DONE', 'Summary\nSTATUS: DONE\n', 'Summary\r\nSTATUS: BLOCKED: reason\r\n']) {
278
+ fs.writeFileSync(file, valid);
279
+ assertOk(run(['check', '--file', file]));
280
+ }
281
+ for (const invalid of [
282
+ 'Summary',
283
+ 'Summary\nSTATUS: DONE\n\n',
284
+ 'Summary\nSTATUS: DONE\ntrailing',
285
+ 'Summary\nSTATUS: DONE\nSTATUS: DONE',
286
+ 'Summary\nSTATUS: BLOCKED: ',
287
+ 'Summary\nSTATUS: FINISHED',
288
+ 'Summary\nSTATUS: DONE\n<!-- harness-label {"v":1} -->',
289
+ '<!-- harness-label {"v":1} -->\nSummary\nSTATUS: DONE',
290
+ ]) {
291
+ fs.writeFileSync(file, invalid);
292
+ assertRejected(run(['check', '--file', file]));
293
+ }
294
+ });
295
+
296
+ test('returns actionable errors for missing input and a bad output path', t => {
297
+ const dir = tempDir(t);
298
+ const missingBody = path.join(dir, 'missing.md');
299
+ const badOutput = path.join(dir, 'missing-parent', 'report.md');
300
+ assertRejected(run(writeArgs(path.join(dir, 'report.md'), 'DONE', ['--body-file', missingBody])), /read|open|ENOENT/i);
301
+ assertRejected(run(writeArgs(badOutput, 'DONE', ['--context', 'Summary'])), /write|publish|ENOENT|directory/i);
302
+ assert.equal(fs.existsSync(path.dirname(badOutput)), false);
303
+ assert.deepEqual(fs.readdirSync(dir), []);
304
+ });
305
+
306
+ test('a staged read-back failure leaves an existing report byte-identical and removes staging data', t => {
307
+ const dir = tempDir(t);
308
+ const output = path.join(dir, 'report.md');
309
+ const before = Buffer.from('Existing\nSTATUS: DONE\n');
310
+ fs.writeFileSync(output, before);
311
+ const hook = readbackHook(dir);
312
+ const result = run(writeArgs(output, 'DONE', ['--context', 'New body']), {
313
+ preload: hook,
314
+ env: { ...process.env, REPORT_WRITER_FAIL_PATH: output, REPORT_WRITER_FAIL_MODE: 'staged' },
315
+ });
316
+ assertRejected(result, /controlled read-back failure/);
317
+ assert.deepEqual(fs.readFileSync(output), before);
318
+ assert.deepEqual(fs.readdirSync(dir).sort(), ['fail-readback.cjs', 'report.md']);
319
+ });
320
+
321
+ test('a published read-back failure is nonzero and keeps raw evidence intact', t => {
322
+ const dir = tempDir(t);
323
+ const raw = path.join(dir, 'raw.txt');
324
+ const output = path.join(dir, 'report.md');
325
+ const rawBytes = Buffer.from('Summary\nSTATUS: DONE\n');
326
+ fs.writeFileSync(raw, rawBytes);
327
+ const hook = readbackHook(dir);
328
+ const result = run(writeArgs(output, 'DONE', ['--from-codex-output', raw]), {
329
+ preload: hook,
330
+ env: { ...process.env, REPORT_WRITER_FAIL_PATH: output, REPORT_WRITER_FAIL_MODE: 'published' },
331
+ });
332
+ assertRejected(result, /published.*verify|read-back/i);
333
+ assert.deepEqual(fs.readFileSync(raw), rawBytes);
334
+ assert.equal(fs.readFileSync(output, 'utf8'), 'Summary\nSTATUS: DONE\n');
335
+ });
@@ -170,6 +170,7 @@ const subagentStop = runHook('hooks/scripts/subagent-stop.js', {
170
170
  agent_type: 'worker'
171
171
  }, stateHome);
172
172
  assert.strictEqual(subagentStop.status, 0, subagentStop.stderr);
173
- assert.match(subagentStop.stderr, /Subagent Scope Reminder/);
173
+ assert.strictEqual(subagentStop.stderr, '');
174
+ assert.match(JSON.parse(subagentStop.stdout).systemMessage, /Subagent Scope Reminder.*[\s\S]*unplanned-change\.txt/);
174
175
 
175
176
  console.log('OpenAI plugin runtime compatibility verified.');
@@ -18,8 +18,12 @@ for (const [canonical, packaged] of [
18
18
  ]) {
19
19
  const body = read(canonical);
20
20
  assert.strictEqual(read(packaged), body, canonical + ' packaged contract matches');
21
- assert.ok(/advisory replan/i.test(body), canonical + ' must describe replans as advisory');
22
- assert.ok(/Rule-of-3/i.test(body), canonical + ' must preserve same-signature failure reflection');
21
+ // #476: fable-mode moved the planning rules into the execution-phases reference its Workflow points to.
22
+ const phases = canonical === 'fable-mode/SKILL.md' && body.includes('references/execution-phases.md')
23
+ ? read('fable-mode/references/execution-phases.md') : '';
24
+ const contract = body + '\n' + phases;
25
+ assert.ok(/advisory replan|replans are advisory/i.test(contract), canonical + ' must describe replans as advisory');
26
+ assert.ok(/Rule-of-3/i.test(contract), canonical + ' must preserve same-signature failure reflection');
23
27
  assert.ok(!/at most two (?:full )?replans/i.test(body), canonical + ' must not imply a two-replan hard cap');
24
28
  }
25
29
  for (const rel of [
@@ -3,7 +3,19 @@ const assert = require('assert');
3
3
  const fs = require('fs');
4
4
  const os = require('os');
5
5
  const path = require('path');
6
- const { spawnSync } = require('child_process');
6
+ const { spawnSync: spawnNodeSync } = require('child_process');
7
+
8
+ function spawnSync(command, args, options = {}) {
9
+ const { systemOneMode = 'off', ...spawnOptions } = options;
10
+ return spawnNodeSync(command, args, {
11
+ ...spawnOptions,
12
+ env: {
13
+ ...process.env,
14
+ ...(spawnOptions.env || {}),
15
+ HARNESS_SYSTEM_ONE_MODE: systemOneMode,
16
+ },
17
+ });
18
+ }
7
19
 
8
20
  const ROOT = path.resolve(__dirname, '..');
9
21
  const tierRouter = path.join(ROOT, 'harness-everything', 'scripts', 'tier-router.js');
@@ -27,6 +39,17 @@ function check(condition, message) {
27
39
  }
28
40
  }
29
41
 
42
+ function withInheritedSystemOneLive(run) {
43
+ const priorMode = process.env.HARNESS_SYSTEM_ONE_MODE;
44
+ try {
45
+ process.env.HARNESS_SYSTEM_ONE_MODE = 'live';
46
+ return run();
47
+ } finally {
48
+ if (priorMode === undefined) delete process.env.HARNESS_SYSTEM_ONE_MODE;
49
+ else process.env.HARNESS_SYSTEM_ONE_MODE = priorMode;
50
+ }
51
+ }
52
+
30
53
  function reviewBindingIds(run) {
31
54
  const text = `${run.result.stdout || ''}\n${run.result.stderr || ''}`;
32
55
  const line = text.match(/Candidate step binding ids: ([^\r\n]+)/);
@@ -46,6 +69,7 @@ function runTier(prompt, options = {}) {
46
69
  ...(options.env || {}),
47
70
  HARNESS_ROUTER_CONTRACT_PATH: contractPath,
48
71
  },
72
+ systemOneMode: options.systemOneMode,
49
73
  });
50
74
 
51
75
  let contract = null;
@@ -56,6 +80,22 @@ function runTier(prompt, options = {}) {
56
80
  return { result, contract };
57
81
  }
58
82
 
83
+ const priorSystemOneMode = process.env.HARNESS_SYSTEM_ONE_MODE;
84
+ let inheritedLive;
85
+ try {
86
+ process.env.HARNESS_SYSTEM_ONE_MODE = 'live';
87
+ inheritedLive = runTier('Create a new feature');
88
+ } finally {
89
+ if (priorSystemOneMode === undefined) delete process.env.HARNESS_SYSTEM_ONE_MODE;
90
+ else process.env.HARNESS_SYSTEM_ONE_MODE = priorSystemOneMode;
91
+ }
92
+ check(inheritedLive.result.status === 0 && !inheritedLive.result.stdout.includes('SYSTEM ONE REFERENCE CONFIDENCE'),
93
+ 'routing fixtures ignore inherited live mode unless explicitly selected');
94
+
95
+ const explicitLive = runTier('Create a new feature', { systemOneMode: 'live' });
96
+ check(explicitLive.result.status === 0 && explicitLive.result.stdout.includes('SYSTEM ONE REFERENCE CONFIDENCE'),
97
+ 'routing fixtures retain an explicit live-mode control');
98
+
59
99
  function validContract(run, label) {
60
100
  check(run.result.status === 0, `${label}: tier router exits successfully`);
61
101
  check(Boolean(run.contract), `${label}: structured contract exists`);
@@ -426,10 +466,11 @@ if (validContract(degraded, 'degraded routing')) {
426
466
  check(degraded.contract.workflowPlan.reasonCodes.includes('routing-degraded-strategy-deferred'), 'degraded strategy deferral is explicit');
427
467
  }
428
468
 
429
- const kernelUnknown = spawnSync(process.execPath, [kernelRouter, 'frobnicate the quux'], {
469
+ const kernelUnknown = withInheritedSystemOneLive(() => spawnSync(process.execPath, [kernelRouter, 'frobnicate the quux'], {
430
470
  cwd: ROOT,
431
471
  encoding: 'utf8',
432
- });
472
+ }));
473
+ check(!kernelUnknown.stdout.includes('SYSTEM ONE REFERENCE CONFIDENCE'), 'kernel unknown route ignores inherited live mode');
433
474
  check(kernelUnknown.status === 0, 'kernel consumes selected/deferred structured contract successfully');
434
475
  check(kernelUnknown.stdout.includes('ROUTER WORKFLOW PLAN (JSON)'), 'kernel emits the Phase 2 workflow-plan checkpoint');
435
476
  check(kernelUnknown.stdout.includes('"strategySelection":"deferred"'), 'kernel exposes deferred unclassified selection');
@@ -454,10 +495,11 @@ check(kernelNotificationPersistFailure.stdout.includes('Host notification: no ac
454
495
  check(kernelNotificationPersistFailure.stderr.includes('routing state was not persisted'), 'host notification persistence failure remains visible as a reminder');
455
496
  fs.rmSync(notificationStateHome, { recursive: true, force: true });
456
497
 
457
- const kernelIterative = spawnSync(process.execPath, [kernelRouter, 'Fix this checkout bug and add a regression test.'], {
498
+ const kernelIterative = withInheritedSystemOneLive(() => spawnSync(process.execPath, [kernelRouter, 'Fix this checkout bug and add a regression test.'], {
458
499
  cwd: ROOT,
459
500
  encoding: 'utf8',
460
- });
501
+ }));
502
+ check(!kernelIterative.stdout.includes('SYSTEM ONE REFERENCE CONFIDENCE'), 'kernel iterative route ignores inherited live mode');
461
503
  check(kernelIterative.stdout.includes('"strategy":"iterative-single"'), 'kernel consumes strategy from structured plan');
462
504
  check(kernelIterative.stdout.includes('loop-awareness:'), 'kernel prints dynamic semantic plan obligations');
463
505
  check(kernelIterative.stdout.includes('visible-status-updates:'), 'kernel prints the user-visible status invariant');
@@ -468,11 +510,11 @@ check(!kernelIterative.stdout.includes('evaluate-suggestions-before-skip'), 'leg
468
510
 
469
511
  const retainedStateHome = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-router-retained-step-'));
470
512
  const retainedSession = 'issue297-retained-step';
471
- const retainedEnv = {
513
+ const retainedEnv = withInheritedSystemOneLive(() => ({
472
514
  ...process.env,
473
515
  HARNESS_STATE_HOME: retainedStateHome,
474
516
  HARNESS_WORKSPACE_ROOT: ROOT,
475
- };
517
+ }));
476
518
  const retainedInput = prompt => JSON.stringify({ session_id: retainedSession, cwd: ROOT, hook_event_name: 'UserPromptSubmit', prompt });
477
519
  const initialRetainedRoute = spawnSync(process.execPath, [kernelRouter], {
478
520
  cwd: ROOT,
@@ -481,6 +523,7 @@ const initialRetainedRoute = spawnSync(process.execPath, [kernelRouter], {
481
523
  env: retainedEnv,
482
524
  });
483
525
  check(initialRetainedRoute.status === 0, 'retained workflow fixture routes successfully');
526
+ check(!initialRetainedRoute.stdout.includes('SYSTEM ONE REFERENCE CONFIDENCE'), 'retained kernel route ignores inherited live mode');
484
527
  check(initialRetainedRoute.stdout.includes('PLANNING STEP: decompose → compose'), 'new selected workflow exposes its planning step');
485
528
 
486
529
  const sessionPathResult = spawnSync(process.execPath, ['-e', "const s=require('./hooks/scripts/lib/harness-state');process.stdout.write(s.getSessionDir(process.env.HARNESS_WORKSPACE_ROOT, process.env.TEST_SESSION_ID, {session_id:process.env.TEST_SESSION_ID,cwd:process.env.HARNESS_WORKSPACE_ROOT}))"], {
@@ -36,9 +36,10 @@ flowchart TD
36
36
  P --> A{Strategy selected?}
37
37
  A -- No / deferred --> D[Preserve invariants<br/>choose smallest justified workflow]
38
38
  A -- Yes --> C[ACTIVE workflow contract]
39
- C --> D[Decompose ordered requirements]
40
- D --> B[Bind skills/references per step]
41
- B --> X[Execute active step/stage]
39
+ C --> Reqs[Decompose ordered requirements]
40
+ D --> Reqs
41
+ Reqs --> Bind[Bind skills/references per step]
42
+ Bind --> X[Execute active step/stage]
42
43
  X --> V{Required stage/check resolved?}
43
44
  V -- Yes --> Done[Evidence-backed completion]
44
45
  V -- No --> R[Diagnose / bounded re-plan]