harness-everything 0.55.2 → 0.55.4

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 (177) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/AGENTS.md +1 -1
  4. package/BENCHMARK_SOP.md +2 -2
  5. package/CHANGELOG.md +22 -0
  6. package/README.md +15 -16
  7. package/SECURITY.md +1 -1
  8. package/VERIFICATION.md +4 -8
  9. package/behavioral-evals/PAIRED-BENCHMARK.md +12 -27
  10. package/behavioral-evals/README.md +21 -65
  11. package/behavioral-evals/cases/breaker-zoom-out-after-3.yaml +26 -33
  12. package/behavioral-evals/cases/pressure-sunk-cost-retry.yaml +15 -17
  13. package/behavioral-evals/paired-benchmark.js +3 -40
  14. package/behavioral-evals/run.js +2 -3
  15. package/ci/fixtures/doc-obligations/reconciliation-s2b/wiring/legacy-off-golden.json +0 -6
  16. package/ci/invariant-routing.test.js +32 -6
  17. package/ci/lib/opencode-verification-loader.js +3 -5
  18. package/ci/mechanism-2a-rule-of-3.test.js +111 -97
  19. package/ci/mechanism-2n-opencode-plugin.test.js +68 -206
  20. package/ci/mechanism-2p-opencode-v2-entrypoint.test.js +47 -28
  21. package/ci/mechanism-2w-platform-compatibility.test.js +1 -0
  22. package/ci/mechanism-32-paired-benchmark.test.js +1 -2
  23. package/ci/mechanism-33-issues-205-207.test.js +1 -1
  24. package/ci/mechanism-338-opencode-async.test.js +18 -49
  25. package/ci/mechanism-36-verify-timeout.test.js +3 -189
  26. package/ci/mechanism-39-opencode-verify-outcomes.test.js +56 -323
  27. package/ci/mechanism-397-opencode-observations.test.js +64 -9
  28. package/ci/mechanism-check-packet-write-set.test.js +163 -8
  29. package/ci/mechanism-codex-hook-results.test.js +9 -5
  30. package/ci/mechanism-prb-outline-review.test.js +1 -13
  31. package/ci/mechanism-system-one-router.test.js +1 -1
  32. package/ci/openai-plugin-package.test.js +30 -7
  33. package/ci/openai-plugin-runtime.test.js +64 -32
  34. package/ci/prompt-contract-regressions.test.js +1 -5
  35. package/ci/router-workflow-plan.test.js +8 -8
  36. package/ci/self-evolve-loop.test.js +51 -51
  37. package/ci/workflow-execution-contract.test.js +3 -6
  38. package/code-review/SKILL.md +1 -1
  39. package/code-review/templates/finding.template.md +17 -1
  40. package/docker-verify.sh +1 -117
  41. package/docs/architecture.md +9 -7
  42. package/docs/document-lifecycle.md +1 -1
  43. package/docs/enforcement-locks.md +12 -10
  44. package/docs/mechanism-first-skill-mesh.md +2 -2
  45. package/docs/openai-plugin.md +3 -3
  46. package/docs/philosophy.md +1 -1
  47. package/docs/platform-capabilities.md +4 -3
  48. package/docs/platform-compatibility.json +2 -2
  49. package/docs/reflection.md +1 -1
  50. package/docs/routing.md +2 -2
  51. package/docs/system-one-suggestion-gates.md +4 -4
  52. package/docs/troubleshooting.md +9 -35
  53. package/docs/workflow-runtime.md +19 -18
  54. package/docs/workflows/environment-detection.md +11 -9
  55. package/docs/workflows/fable-discipline.md +6 -5
  56. package/docs/workflows/fable-mode.md +6 -5
  57. package/docs/workflows/harness-everything.md +5 -5
  58. package/docs/workflows/improve-codebase-architecture.md +10 -8
  59. package/docs/workflows/install-cognitive-os.md +5 -5
  60. package/docs/workflows/tdd.md +9 -9
  61. package/docs/workflows/zoom-out.md +20 -30
  62. package/environment-detection/SKILL.md +2 -2
  63. package/environment-detection/references/shell-syntax-rules.md +1 -1
  64. package/eval-harness/SKILL.md +1 -1
  65. package/eval-harness/references/scoring-rubric.md +3 -3
  66. package/evals/zoom-out/eval.yaml +2 -2
  67. package/evals/zoom-out/tasks/negative-productive-iteration.yaml +15 -0
  68. package/evals/zoom-out/tasks/negative-trivial-edit.yaml +6 -6
  69. package/evals/zoom-out/tasks/positive-first-failure.yaml +15 -0
  70. package/evals/zoom-out/tasks/positive-repair-loop.yaml +1 -1
  71. package/fable-discipline/SKILL.md +3 -3
  72. package/fable-discipline/references/discipline-rules.md +1 -1
  73. package/fable-mode/SKILL.md +1 -1
  74. package/fable-mode/execution-guardrails/SKILL.md +2 -4
  75. package/fable-mode/execution-guardrails/references/guardrail-rules.md +3 -3
  76. package/fable-mode/fable-haiku/SKILL.md +1 -1
  77. package/fable-mode/fable-opus/SKILL.md +2 -2
  78. package/fable-mode/fable-sonnet/SKILL.md +1 -1
  79. package/fable-mode/references/execution-phases.md +2 -2
  80. package/harness-everything/SKILL.md +3 -3
  81. package/harness-everything/references/router-workflow-plan.md +2 -2
  82. package/harness-everything/references/skill-registry.md +2 -2
  83. package/harness-everything/references/triage-and-tiers.md +5 -5
  84. package/harness-everything/scripts/bootstrap.js +1 -26
  85. package/harness-everything/scripts/kernel-router-core.js +2 -3
  86. package/harness-everything/scripts/kernel-router.js +1 -1
  87. package/harness-everything/scripts/router-contract-core.js +1 -1
  88. package/harness-everything/scripts/routing-keywords.json +0 -2
  89. package/hooks/hooks.json +0 -33
  90. package/hooks/scripts/lib/harness-state.js +5 -6
  91. package/hooks/scripts/lib/learning-opportunity.js +3 -13
  92. package/hooks/scripts/openai-session-start.js +2 -4
  93. package/improve-codebase-architecture/SKILL.md +3 -3
  94. package/improve-codebase-architecture/guides/refactoring-workflow.md +5 -4
  95. package/install-cognitive-os/SKILL.md +3 -3
  96. package/opencode-plugin/README.md +18 -43
  97. package/opencode-plugin/index.mjs +52 -380
  98. package/opencode-plugin/plugin.json +1 -1
  99. package/package.json +1 -4
  100. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  101. package/plugins/harness-everything/hooks/hooks.json +0 -14
  102. package/plugins/harness-everything/hooks/scripts/lib/harness-state.js +5 -6
  103. package/plugins/harness-everything/hooks/scripts/lib/learning-opportunity.js +3 -13
  104. package/plugins/harness-everything/hooks/scripts/lib/workspace.js +2 -2
  105. package/plugins/harness-everything/hooks/scripts/openai-session-start.js +2 -4
  106. package/plugins/harness-everything/hooks/session-start.js +2 -4
  107. package/plugins/harness-everything/plugin.json +1 -1
  108. package/plugins/harness-everything/scripts/lib/advisory-text.js +2 -2
  109. package/plugins/harness-everything/scripts/lib/workspace.js +2 -2
  110. package/plugins/harness-everything/skills/code-review/SKILL.md +1 -1
  111. package/plugins/harness-everything/skills/code-review/templates/finding.template.md +17 -1
  112. package/plugins/harness-everything/skills/environment-detection/SKILL.md +2 -2
  113. package/plugins/harness-everything/skills/environment-detection/references/shell-syntax-rules.md +1 -1
  114. package/plugins/harness-everything/skills/eval-harness/SKILL.md +1 -1
  115. package/plugins/harness-everything/skills/eval-harness/references/scoring-rubric.md +3 -3
  116. package/plugins/harness-everything/skills/fable-discipline/SKILL.md +3 -3
  117. package/plugins/harness-everything/skills/fable-discipline/references/discipline-rules.md +1 -1
  118. package/plugins/harness-everything/skills/fable-mode/SKILL.md +1 -1
  119. package/plugins/harness-everything/skills/fable-mode/execution-guardrails/SKILL.md +2 -4
  120. package/plugins/harness-everything/skills/fable-mode/execution-guardrails/references/guardrail-rules.md +3 -3
  121. package/plugins/harness-everything/skills/fable-mode/fable-haiku/SKILL.md +1 -1
  122. package/plugins/harness-everything/skills/fable-mode/fable-opus/SKILL.md +2 -2
  123. package/plugins/harness-everything/skills/fable-mode/fable-sonnet/SKILL.md +1 -1
  124. package/plugins/harness-everything/skills/fable-mode/references/execution-phases.md +2 -2
  125. package/plugins/harness-everything/skills/harness-everything/SKILL.md +3 -3
  126. package/plugins/harness-everything/skills/harness-everything/references/router-workflow-plan.md +2 -2
  127. package/plugins/harness-everything/skills/harness-everything/references/skill-registry.md +2 -2
  128. package/plugins/harness-everything/skills/harness-everything/references/triage-and-tiers.md +5 -5
  129. package/plugins/harness-everything/skills/harness-everything/scripts/bootstrap.js +1 -26
  130. package/plugins/harness-everything/skills/harness-everything/scripts/kernel-router-core.js +2 -3
  131. package/plugins/harness-everything/skills/harness-everything/scripts/kernel-router.js +1 -1
  132. package/plugins/harness-everything/skills/harness-everything/scripts/router-contract-core.js +1 -1
  133. package/plugins/harness-everything/skills/harness-everything/scripts/routing-keywords.json +0 -2
  134. package/plugins/harness-everything/skills/improve-codebase-architecture/SKILL.md +3 -3
  135. package/plugins/harness-everything/skills/improve-codebase-architecture/guides/refactoring-workflow.md +5 -4
  136. package/plugins/harness-everything/skills/install-cognitive-os/SKILL.md +3 -3
  137. package/plugins/harness-everything/skills/self-evolve/SKILL.md +1 -1
  138. package/plugins/harness-everything/skills/self-evolve/references/memory-resolution.md +3 -3
  139. package/plugins/harness-everything/skills/self-evolve/schemas/lesson-candidate.schema.json +4 -1
  140. package/plugins/harness-everything/skills/self-evolve/scripts/lesson-candidate.js +1 -0
  141. package/plugins/harness-everything/skills/skill-creator/SKILL.md +1 -1
  142. package/plugins/harness-everything/skills/skill-creator/references/quality-checklist.md +1 -1
  143. package/plugins/harness-everything/skills/skill-creator/references/quality-principles.md +4 -4
  144. package/plugins/harness-everything/skills/tdd/SKILL.md +2 -2
  145. package/plugins/harness-everything/skills/tdd/references/core-discipline.md +3 -5
  146. package/plugins/harness-everything/skills/todo-driven-workflow/SKILL.md +2 -2
  147. package/plugins/harness-everything/skills/zoom-out/SKILL.md +14 -26
  148. package/plugins/harness-everything/skills/zoom-out/references/circuit-breaker.md +18 -62
  149. package/references/platform-advisory-template.md +3 -9
  150. package/sbom.cdx.json +7 -7
  151. package/scripts/check-packet-write-set.js +76 -1
  152. package/scripts/lib/advisory-text.js +2 -2
  153. package/scripts/lib/workspace.js +2 -2
  154. package/self-evolve/SKILL.md +1 -1
  155. package/self-evolve/references/memory-resolution.md +3 -3
  156. package/self-evolve/schemas/lesson-candidate.schema.json +4 -1
  157. package/self-evolve/scripts/lesson-candidate.js +1 -0
  158. package/skill-creator/SKILL.md +1 -1
  159. package/skill-creator/references/quality-checklist.md +1 -1
  160. package/skill-creator/references/quality-principles.md +4 -4
  161. package/submission/openai/test-cases.json +5 -5
  162. package/tdd/SKILL.md +2 -2
  163. package/tdd/references/core-discipline.md +3 -5
  164. package/todo-driven-workflow/SKILL.md +2 -2
  165. package/zoom-out/SKILL.md +14 -26
  166. package/zoom-out/references/circuit-breaker.md +18 -62
  167. package/behavioral-evals/opencode-hardlock-live.js +0 -17
  168. package/behavioral-evals/opencode-reflection-gate-live.js +0 -342
  169. package/ci/mechanism-31-opencode-hardlock-evidence.test.js +0 -82
  170. package/evals/zoom-out/tasks/negative-first-edge-case-review.yaml +0 -16
  171. package/evals/zoom-out/tasks/positive-repeated-failure.yaml +0 -15
  172. package/hooks/scripts/reset-circuit-breaker.js +0 -30
  173. package/hooks/scripts/rule-of-3-tracker.js +0 -165
  174. package/hooks/scripts/rule-of-3.js +0 -171
  175. package/plugins/harness-everything/hooks/scripts/reset-circuit-breaker.js +0 -30
  176. package/plugins/harness-everything/hooks/scripts/rule-of-3-tracker.js +0 -165
  177. package/plugins/harness-everything/hooks/scripts/rule-of-3.js +0 -171
@@ -4,367 +4,100 @@ const crypto = require('crypto');
4
4
  const { pathToFileURL } = require('url');
5
5
  const helper = require('./test-helper');
6
6
 
7
- console.log('\n[39] opencode verification outcomes: Rule-of-3 downstream behavior with the real plugin...');
7
+ console.log('\n[39] opencode verification outcomes and reminders with the real plugin...');
8
8
 
9
9
  (async () => {
10
10
  const workspace = helper.tempDir('.mechanism-test-verify-outcomes-workspace');
11
11
  fs.mkdirSync(workspace, { recursive: true });
12
12
  const stateHome = process.env.HARNESS_STATE_HOME;
13
-
14
- // Mirrors the plugin's getWorkspaceKey(directory) (same derivation as the
15
- // 2n test) so this harness can read the state files the real hooks write.
16
13
  const realWorkspace = fs.realpathSync(path.resolve(workspace));
17
14
  const slug = path.basename(realWorkspace).toLowerCase().replace(/[^a-z0-9._-]+/g, '-').replace(/^-+|-+$/g, '') || 'workspace';
18
15
  const hashInput = process.platform === 'win32' ? realWorkspace.toLowerCase() : realWorkspace;
19
16
  const hash = crypto.createHash('sha1').update(hashInput).digest('hex').slice(0, 12);
20
17
  const sessionsRoot = path.join(stateHome, 'workspaces', `${slug}-${hash}`, 'state', 'sessions');
21
-
22
18
  const fixtureFile = path.join(workspace, 'fixture.js');
23
- fs.writeFileSync(
24
- path.join(workspace, 'package.json'),
25
- JSON.stringify({ name: 'fixture', version: '0.0.0', scripts: { test: 'node fixture.js' } }, null, 2),
26
- );
27
- const setFixture = (lines) => fs.writeFileSync(fixtureFile, `${lines.join('\n')}\n`);
28
- const markerFailure = (name) => [
29
- "console.log('> harness-everything@0.34.0 test');",
30
- "console.log('> node self-evolve/scripts/self-regression.js');",
31
- `console.log('\u2716 ${name} (1.2ms)');`,
32
- `console.log('AssertionError [ERR_ASSERTION]: ${name} boom');`,
33
- 'process.exit(1);',
34
- ];
19
+ fs.writeFileSync(path.join(workspace, 'package.json'), JSON.stringify({
20
+ name: 'fixture', version: '0.0.0', scripts: { test: 'node fixture.js' }
21
+ }, null, 2));
22
+ const setFixture = (source) => fs.writeFileSync(fixtureFile, `${source}\n`);
35
23
 
36
24
  const promptCalls = [];
37
25
  const client = { session: { prompt: async (opts) => { promptCalls.push(opts); return {}; } } };
38
26
  const { HarnessEnforcement } = await import(pathToFileURL(path.join(helper.root, 'opencode-plugin', 'index.mjs')).href);
39
27
  const hooks = await HarnessEnforcement({ client, directory: workspace });
40
-
41
- const stateFile = (sessionID, name) => path.join(sessionsRoot, sessionID, name);
42
- const readBreaker = (sessionID) => JSON.parse(fs.readFileSync(stateFile(sessionID, 'circuit-breaker.json'), 'utf8'));
43
- const readEditState = (sessionID) => JSON.parse(fs.readFileSync(stateFile(sessionID, 'edit-state.json'), 'utf8'));
44
28
  let callCounter = 0;
45
- const edit = async (sessionID) => hooks['tool.execute.after'](
46
- { tool: 'edit', sessionID, callID: `edit-${(callCounter += 1)}` },
47
- { title: '', output: '', metadata: {}, args: { filePath: path.join(workspace, 'code.js') } },
48
- );
49
- const idle = async (sessionID) => hooks.event({ event: { type: 'session.idle', properties: { sessionID } } });
29
+ const sessionID = 'repeated-failures';
30
+ const edit = async (id = sessionID) => {
31
+ await hooks['tool.execute.before']({ tool: 'edit', sessionID: id, callID: `before-${++callCounter}` }, { args: {} });
32
+ await hooks['tool.execute.after'](
33
+ { tool: 'edit', sessionID: id, callID: `after-${callCounter}` },
34
+ { title: '', output: '', metadata: {}, args: { filePath: path.join(workspace, 'code.js') } },
35
+ );
36
+ };
37
+ const idle = async (id = sessionID) => hooks.event({ event: { type: 'session.idle', properties: { sessionID: id } } });
38
+ const stateFile = (id, name) => path.join(sessionsRoot, id, name);
50
39
  const lastPrompt = () => promptCalls[promptCalls.length - 1].body.parts[0].text;
51
40
 
52
- // --- three timeouts must not band together into a reflection ----------
53
- const timeoutSession = 'timeouts';
54
- setFixture(['setTimeout(() => {}, 3000);']);
55
- process.env.HARNESS_VERIFY_TIMEOUT_MS = '150';
56
- for (let i = 0; i < 3; i += 1) {
57
- await edit(timeoutSession);
58
- await idle(timeoutSession);
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
+ await idle();
59
51
  }
60
- delete process.env.HARNESS_VERIFY_TIMEOUT_MS;
61
- const timeoutPrompts = promptCalls.slice(0, 3).map((call) => call.body.parts[0].text);
52
+ const failedPrompts = promptCalls.map((call) => call.body.parts[0].text);
62
53
  helper.check(
63
- '39. three timeouts never write a same-check failure entry',
64
- !fs.existsSync(stateFile(timeoutSession, 'circuit-breaker.json')),
65
- 'a circuit-breaker file was written for pure timeouts',
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),
66
58
  );
67
59
  helper.check(
68
- '39. timeout follow-ups say the run did not complete and is not counted',
69
- timeoutPrompts.length === 3 &&
70
- timeoutPrompts.every((text) => /did not complete/.test(text) && /does NOT count toward the repeated-failure reflection/.test(text)) &&
71
- !timeoutPrompts.some((text) => /reflection token|## Goal/.test(text)),
72
- timeoutPrompts[0],
60
+ '39. repeated test failures create no recurrence state',
61
+ !fs.existsSync(stateFile(sessionID, 'circuit-breaker.json')),
62
+ stateFile(sessionID, 'circuit-breaker.json'),
73
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);
74
71
 
75
- setFixture(markerFailure('real test A'));
72
+ const timeoutSession = 'timeout';
73
+ setFixture('setTimeout(() => {}, 3000);');
74
+ process.env.HARNESS_VERIFY_TIMEOUT_MS = '100';
76
75
  await edit(timeoutSession);
77
76
  await idle(timeoutSession);
78
- let breaker = readBreaker(timeoutSession);
79
- let entries = Object.values(breaker.failures);
80
- helper.check(
81
- '39. a real failing check after three timeouts counts once, with no reflection',
82
- entries.length === 1 && entries[0].count === 1 && breaker.reflectionPending === false,
83
- JSON.stringify(breaker),
84
- );
85
- helper.check(
86
- '39. the post-timeout failure prompt offers retries instead of reflection',
87
- /2 retries before a forced reflection/.test(lastPrompt()),
88
- lastPrompt(),
89
- );
90
-
91
- // --- distinct failures sharing a banner stay distinct -----------------
92
- const distinctSession = 'distinct';
93
- for (const name of ['alpha', 'beta', 'gamma']) {
94
- setFixture(markerFailure(name));
95
- await edit(distinctSession);
96
- await idle(distinctSession);
97
- }
98
- breaker = readBreaker(distinctSession);
99
- entries = Object.values(breaker.failures);
100
- helper.check(
101
- '39. distinct failures behind a common banner stay three separate signatures',
102
- Object.keys(breaker.failures).length === 3 && entries.every((entry) => entry.count === 1) && breaker.reflectionPending === false,
103
- JSON.stringify(breaker),
104
- );
105
-
106
- // --- identical stdout, different stderr assertions stay distinct ------
107
- // P1 regression: the old classifier kept only stdout, so three assertion
108
- // failures printed to stderr behind the same npm banner collapsed into one
109
- // signature and forced a reflection for healthy retries.
110
- const stderrSession = 'stderr-distinct';
111
- const stderrFailure = (name) => [
112
- `console.error('AssertionError [ERR_ASSERTION]: ${name} boom');`,
113
- 'process.exit(1);',
114
- ];
115
- for (const name of ['alpha', 'beta', 'gamma']) {
116
- setFixture(stderrFailure(name));
117
- await edit(stderrSession);
118
- await idle(stderrSession);
119
- }
120
- breaker = readBreaker(stderrSession);
121
- entries = Object.values(breaker.failures);
122
- helper.check(
123
- '39. identical stdout with different stderr assertions stays three separate signatures',
124
- Object.keys(breaker.failures).length === 3 && entries.every((entry) => entry.count === 1) && breaker.reflectionPending === false,
125
- JSON.stringify(breaker),
126
- );
127
-
128
- // --- >2 KiB shared prefix, different markerless tails stay distinct ---
129
- // P1 regression: the old 2 KiB leading-prefix truncation hashed the same
130
- // prefix for all three runs, so different markerless failures collided.
131
- const prefixSession = 'prefix-distinct';
132
- const markerlessFailure = (token) => [
133
- "console.log('progress '.repeat(400));",
134
- `console.log('HARNESS-UNIQUE-${token}');`,
135
- 'process.exit(1);',
136
- ];
137
- for (const token of ['ALPHA', 'BETA', 'GAMMA']) {
138
- setFixture(markerlessFailure(token));
139
- await edit(prefixSession);
140
- await idle(prefixSession);
141
- }
142
- breaker = readBreaker(prefixSession);
143
- entries = Object.values(breaker.failures);
144
- helper.check(
145
- '39. a shared >2 KiB markerless prefix with different tails stays three separate signatures',
146
- Object.keys(breaker.failures).length === 3 &&
147
- entries.every((entry) => entry.count === 1) &&
148
- Object.keys(breaker.failures).every((signature) => /unrecognized-output/.test(signature)) &&
149
- breaker.reflectionPending === false,
150
- JSON.stringify(breaker),
151
- );
152
-
153
- // --- Jest suite output: FAIL <file> is context, not identity -----------
154
- // P1 regression: the old classifier returned the first matching line, so
155
- // `FAIL src/parser.test.js` made three different test failures in the same
156
- // file one signature and forced a reflection.
157
- const jestSession = 'jest-distinct';
158
- const jestFailure = (name) => [
159
- "console.log('FAIL src/parser.test.js');",
160
- `console.log(' ● parser › accepts ${name}');`,
161
- `console.log(' AssertionError: ${name}');`,
162
- 'process.exit(1);',
163
- ];
164
- for (const name of ['alpha', 'beta', 'gamma']) {
165
- setFixture(jestFailure(name));
166
- await edit(jestSession);
167
- await idle(jestSession);
168
- }
169
- breaker = readBreaker(jestSession);
170
- entries = Object.values(breaker.failures);
171
- helper.check(
172
- '39. different Jest failures from one file stay three separate signatures',
173
- Object.keys(breaker.failures).length === 3 && entries.every((entry) => entry.count === 1) && breaker.reflectionPending === false,
174
- JSON.stringify(breaker),
175
- );
176
-
177
- const jestIdenticalSession = 'jest-identical';
178
- setFixture(jestFailure('stable'));
179
- for (let i = 0; i < 3; i += 1) {
180
- await edit(jestIdenticalSession);
181
- await idle(jestIdenticalSession);
182
- }
183
- breaker = readBreaker(jestIdenticalSession);
184
- entries = Object.values(breaker.failures);
185
- helper.check(
186
- '39. three identical Jest failures still force the Rule-of-3 reflection',
187
- Object.keys(breaker.failures).length === 1 && entries[0].count === 3 && breaker.reflectionPending === true,
188
- JSON.stringify(breaker),
189
- );
190
- helper.check(
191
- '39. the Jest-identical reflection prompt names the token',
192
- /reflection token: [A-Za-z0-9]+/.test(lastPrompt()),
193
- lastPrompt(),
194
- );
195
-
196
-
197
- // --- indented Mocha tests: true identity survives volatile diagnostics ---
198
- // P2 regression: the old unindented regex missed " 1) test", then the
199
- // markerless digest changed on every stack-line number even for the same
200
- // failing check, preventing Rule-of-3 from reaching reflection.
201
- const mochaFailure = (name, frameLine) => [
202
- `console.log(' 1) should parse ${name}');`,
203
- "console.error(' AssertionError: expected true to equal false');",
204
- `console.log(' at Context.<anonymous> (fixture.test.js:${frameLine}:7)');`,
205
- 'process.exit(1);',
206
- ];
207
-
208
- const mochaDistinctSession = 'mocha-distinct';
209
- for (const name of ['alpha', 'beta', 'gamma']) {
210
- setFixture(mochaFailure(name, 19));
211
- await edit(mochaDistinctSession);
212
- await idle(mochaDistinctSession);
213
- }
214
- breaker = readBreaker(mochaDistinctSession);
215
- entries = Object.values(breaker.failures);
216
- helper.check(
217
- '39. different indented Mocha checks never count as one repeated failure',
218
- Object.keys(breaker.failures).length === 3 &&
219
- entries.every((entry) => entry.count === 1) &&
220
- breaker.reflectionPending === false,
221
- JSON.stringify(breaker),
222
- );
223
-
224
- const mochaIdenticalSession = 'mocha-identical';
225
- for (const frameLine of [19, 27, 35]) {
226
- setFixture(mochaFailure('stable', frameLine));
227
- await edit(mochaIdenticalSession);
228
- await idle(mochaIdenticalSession);
229
- }
230
- breaker = readBreaker(mochaIdenticalSession);
231
- entries = Object.values(breaker.failures);
232
- helper.check(
233
- '39. same indented Mocha check with changing stack output still triggers Rule-of-3',
234
- Object.keys(breaker.failures).length === 1 &&
235
- entries[0].count === 3 &&
236
- breaker.reflectionPending === true,
237
- JSON.stringify(breaker),
238
- );
239
- helper.check(
240
- '39. Mocha Rule-of-3 reflection includes a token',
241
- /reflection token: [A-Za-z0-9]+/.test(lastPrompt()),
242
- lastPrompt(),
243
- );
244
-
245
- // --- Console payload noise: logged Error lines are not failure identity ---
246
- // Regression guard for the indented-error pattern: a Jest Console payload
247
- // (logged output, volatile run to run) must not become the marker, or the
248
- // same failing check stops accumulating toward the Rule of 3.
249
- const consoleNoisyFailure = [
250
- "console.log('PASS src/loggy.test.js');",
251
- "console.log(' ● Console');",
252
- "console.log('');",
253
- "console.log(' console.error');",
254
- "console.log(' Error: connection refused at ' + Date.now());",
255
- "console.log('');",
256
- "console.log('FAIL src/parser.test.js');",
257
- "console.log(' ● parser › accepts stable');",
258
- 'process.exit(1);',
259
- ];
260
- const consoleNoiseSession = 'console-noise';
261
- for (let i = 0; i < 3; i += 1) {
262
- setFixture(consoleNoisyFailure);
263
- await edit(consoleNoiseSession);
264
- await idle(consoleNoiseSession);
265
- }
266
- breaker = readBreaker(consoleNoiseSession);
267
- entries = Object.values(breaker.failures);
268
- helper.check(
269
- '39. volatile Console payload noise never breaks the failing check identity',
270
- Object.keys(breaker.failures).length === 1 && entries[0].count === 3 && breaker.reflectionPending === true,
271
- JSON.stringify(breaker),
272
- );
273
-
274
- // --- nested Jest Console bullets are payload, not test-level markers ---
275
- // The previous fix only excluded indented Error lines. A logged "●" used
276
- // to terminate the Console section regardless of indentation, causing
277
- // either false reflection (shared console text) or missed Rule-of-3
278
- // (volatile console text) for actual Jest failures.
279
- const consoleBulletFailure = (name, noise) => [
280
- "console.log('PASS src/loggy.test.js');",
281
- "console.log(' ● Console');",
282
- "console.log('');",
283
- "console.log(' console.log');",
284
- `console.log(' ● ${noise}');`,
285
- "console.log(' ● Console');",
286
- "console.log('');",
287
- "console.log('FAIL src/parser.test.js');",
288
- `console.log(' ● parser › accepts ${name}');`,
289
- 'process.exit(1);',
290
- ];
291
-
292
- const consoleBulletDistinctSession = 'console-bullet-distinct';
293
- for (const name of ['alpha', 'beta', 'gamma']) {
294
- setFixture(consoleBulletFailure(name, 'preparing runtime'));
295
- await edit(consoleBulletDistinctSession);
296
- await idle(consoleBulletDistinctSession);
297
- }
298
- breaker = readBreaker(consoleBulletDistinctSession);
299
- entries = Object.values(breaker.failures);
300
- helper.check(
301
- '39. shared nested Console bullet with different Jest failures never causes false Rule-of-3',
302
- Object.keys(breaker.failures).length === 3 &&
303
- entries.every((entry) => entry.count === 1) &&
304
- breaker.reflectionPending === false,
305
- JSON.stringify(breaker),
306
- );
307
-
308
- const consoleBulletIdenticalSession = 'console-bullet-identical';
309
- for (const noise of ['preparing runtime', 'loading plugins', 'initialization complete']) {
310
- setFixture(consoleBulletFailure('stable', noise));
311
- await edit(consoleBulletIdenticalSession);
312
- await idle(consoleBulletIdenticalSession);
313
- }
314
- breaker = readBreaker(consoleBulletIdenticalSession);
315
- entries = Object.values(breaker.failures);
316
- helper.check(
317
- '39. differing nested Console bullets do not stop the same Jest failure from reaching Rule-of-3',
318
- Object.keys(breaker.failures).length === 1 &&
319
- entries[0].count === 3 &&
320
- breaker.reflectionPending === true,
321
- JSON.stringify(breaker),
322
- );
323
- helper.check(
324
- '39. nested Console bullet Rule-of-3 produces a reflection token',
325
- /reflection token: [A-Za-z0-9]+/.test(lastPrompt()),
326
- lastPrompt(),
327
- );
328
-
329
- // --- genuinely identical failures keep the Rule of 3 ------------------
330
- const identicalSession = 'identical';
331
- setFixture(markerFailure('stable check'));
332
- for (let i = 0; i < 3; i += 1) {
333
- await edit(identicalSession);
334
- await idle(identicalSession);
335
- }
336
- breaker = readBreaker(identicalSession);
337
- entries = Object.values(breaker.failures);
338
- helper.check(
339
- '39. three genuinely identical failures still force the Rule-of-3 reflection',
340
- Object.keys(breaker.failures).length === 1 && entries[0].count === 3 && breaker.reflectionPending === true,
341
- JSON.stringify(breaker),
342
- );
77
+ delete process.env.HARNESS_VERIFY_TIMEOUT_MS;
343
78
  helper.check(
344
- '39. the forced reflection names the token and required report sections',
345
- /reflection token: [A-Za-z0-9]+/.test(lastPrompt()) && /## Goal/.test(lastPrompt()) && /## Decision/.test(lastPrompt()),
79
+ '39. a timeout is reported as incomplete verification without reflection or a counter',
80
+ /did not complete/.test(lastPrompt()) && /timed out/.test(lastPrompt())
81
+ && !/reflection token|## Goal|does NOT count|retries before/i.test(lastPrompt())
82
+ && !fs.existsSync(stateFile(timeoutSession, 'circuit-breaker.json')),
346
83
  lastPrompt(),
347
84
  );
348
85
 
349
- // --- success after failure clears pending state -----------------------
350
86
  const recoverSession = 'recover';
351
- setFixture(markerFailure('recover check'));
87
+ setFixture("console.error('AssertionError [ERR_ASSERTION]: recoverable failure');process.exit(1);");
352
88
  await edit(recoverSession);
353
89
  await idle(recoverSession);
354
90
  const promptsBeforeSuccess = promptCalls.length;
355
- setFixture(['process.exit(0);']);
91
+ setFixture('process.exit(0);');
356
92
  await edit(recoverSession);
357
93
  await idle(recoverSession);
358
- const recoveredState = readEditState(recoverSession);
359
- breaker = readBreaker(recoverSession);
360
- entries = Object.values(breaker.failures);
94
+ const recoveredState = JSON.parse(fs.readFileSync(stateFile(recoverSession, 'edit-state.json'), 'utf8'));
361
95
  helper.check(
362
- '39. a passing run after a failure clears pending verification without erasing failure history',
363
- recoveredState.verificationPending === false &&
364
- recoveredState.editsSinceVerification === 0 &&
365
- promptCalls.length === promptsBeforeSuccess &&
366
- entries[0].count === 1,
367
- JSON.stringify({ recoveredState, breaker }),
96
+ '39. a passing verification clears pending state without an extra reminder',
97
+ recoveredState.verificationPending === false && recoveredState.editsSinceVerification === 0
98
+ && promptCalls.length === promptsBeforeSuccess
99
+ && !fs.existsSync(stateFile(recoverSession, 'circuit-breaker.json')),
100
+ JSON.stringify(recoveredState),
368
101
  );
369
102
 
370
103
  helper.finish();
@@ -148,8 +148,8 @@ function fixture(observationMode = 'on') {
148
148
  };
149
149
  }
150
150
 
151
- async function install(f) {
152
- const mod = await import(pathToFileURL(PLUGIN).href);
151
+ async function install(f, plugin = PLUGIN) {
152
+ const mod = await import(pathToFileURL(plugin).href);
153
153
  return mod.default.setup(f.ctx);
154
154
  }
155
155
 
@@ -286,6 +286,8 @@ test('inject: the documented OpenCode hooks deliver the kernel router output and
286
286
  test('runtime: a non-Node host binary still runs the router on Node and injects its output', { concurrency: false }, async () => {
287
287
  const f = fixture();
288
288
  let dispose;
289
+ const warnings = [];
290
+ const originalWarn = console.warn;
289
291
  const originalExecPath = process.execPath;
290
292
  const hadBun = Object.hasOwn(process.versions, 'bun');
291
293
  const originalBun = process.versions.bun;
@@ -299,16 +301,20 @@ test('runtime: a non-Node host binary still runs the router on Node and injects
299
301
  fs.writeFileSync(stubRuntime, process.platform === 'win32' ? '@exit /b 1\r\n' : '#!/bin/sh\nexit 1\n', { mode: 0o755 });
300
302
  Object.defineProperty(process, 'execPath', { value: stubRuntime, configurable: true, writable: true });
301
303
  Object.defineProperty(process.versions, 'bun', { value: '1.2.0', configurable: true });
304
+ console.warn = message => warnings.push(String(message));
302
305
 
303
306
  dispose = await install(f);
307
+ assert.deepEqual(warnings, [], 'setup without traffic produces no warnings');
304
308
  const prompt = { sessionID: 'runtime-session', messageID: 'runtime-turn', prompt: { text: 'add a small behavior change' } };
305
309
  await f.sessionHooks.get('prompt')(prompt);
306
310
  const context = { sessionID: 'runtime-session', kind: 'primary', system: [], messages: [] };
307
311
  await f.sessionHooks.get('context')(context);
308
312
  const injected = context.system.map(part => part.text || '').join('\n');
309
313
  assert.match(injected, /=> ROUTER WORKFLOW PLAN/, 'the router ran on Node despite a non-Node host binary');
314
+ assert.deepEqual(warnings, []);
310
315
  } finally {
311
316
  if (dispose) await dispose();
317
+ console.warn = originalWarn;
312
318
  Object.defineProperty(process, 'execPath', { value: originalExecPath, configurable: true, writable: true });
313
319
  if (hadBun) Object.defineProperty(process.versions, 'bun', { value: originalBun, configurable: true });
314
320
  else delete process.versions.bun;
@@ -316,6 +322,56 @@ test('runtime: a non-Node host binary still runs the router on Node and injects
316
322
  }
317
323
  });
318
324
 
325
+ for (const reason of ['spawn-failed', 'runtime-failed', 'runtime-missing']) {
326
+ test(`runtime: ${reason} warns without prompt content and admits the prompt`, async () => {
327
+ const f = fixture('off');
328
+ const originalExecPath = process.execPath;
329
+ const originalWarn = console.warn;
330
+ const warnings = [];
331
+ let dispose;
332
+ try {
333
+ let plugin = PLUGIN;
334
+ if (reason === 'spawn-failed') {
335
+ // Exercise the same ENOENT as a missing Node on PATH, including on
336
+ // Windows where executable lookup can also use the host directory.
337
+ Object.defineProperty(process, 'execPath', {
338
+ value: path.join(f.dir, 'missing-node'), configurable: true, writable: true,
339
+ });
340
+ } else {
341
+ plugin = path.join(f.dir, 'opencode-plugin', 'index.mjs');
342
+ fs.mkdirSync(path.dirname(plugin));
343
+ fs.copyFileSync(PLUGIN, plugin);
344
+ if (reason === 'runtime-failed') {
345
+ const router = path.join(f.dir, 'harness-everything/scripts/kernel-router.js');
346
+ const observationsFile = path.join(f.dir, 'hooks/scripts/lib/observations.js');
347
+ fs.mkdirSync(path.dirname(router), { recursive: true });
348
+ fs.mkdirSync(path.dirname(observationsFile), { recursive: true });
349
+ fs.writeFileSync(router, "console.log('PRIVATE-ROUTER-OUTPUT'); require('./missing-router-runtime');\n");
350
+ fs.writeFileSync(observationsFile, 'module.exports = { enabled: () => false };\n');
351
+ }
352
+ }
353
+ console.warn = message => warnings.push(String(message));
354
+ dispose = await install(f, plugin);
355
+ assert.deepEqual(warnings, []);
356
+ for (const count of [1, 2]) {
357
+ const sessionID = 'private-router-failure-session';
358
+ const prompt = { sessionID, messageID: `private-turn-${count}`, prompt: { text: 'private prompt text' } };
359
+ await assert.doesNotReject(() => f.sessionHooks.get('prompt')(prompt));
360
+ const context = { sessionID, kind: 'primary', system: [], messages: [] };
361
+ await f.sessionHooks.get('context')(context);
362
+ assert.deepEqual(context.system, [], 'failed output is never injected');
363
+ assert.equal(warnings.length, count);
364
+ assert.equal(warnings.at(-1), `[Harness] OpenCode router-unavailable (${reason}; count=${count})`);
365
+ }
366
+ } finally {
367
+ if (dispose) await dispose();
368
+ console.warn = originalWarn;
369
+ Object.defineProperty(process, 'execPath', { value: originalExecPath, configurable: true, writable: true });
370
+ f.restore();
371
+ }
372
+ });
373
+ }
374
+
319
375
  test('record: OpenCode prompt, tool and idle events append one host-tagged record to the shared store', { concurrency: false }, async () => {
320
376
  const f = fixture();
321
377
  let dispose;
@@ -1056,9 +1112,9 @@ test('V2 consumers α3: both completion orders and a post-completion counterpart
1056
1112
  }
1057
1113
  });
1058
1114
 
1059
- test('V2 consumers α3: duplicate completion notifications do not advance Rule-of-3', { concurrency: false }, async () => {
1115
+ test('V2 consumers α3: duplicate completion notifications do not duplicate verification', { concurrency: false }, async () => {
1060
1116
  const f = fixture('off');
1061
- const sessionID = 'v2-rule-of-three';
1117
+ const sessionID = 'v2-duplicate-completion';
1062
1118
  const checkLog = path.join(f.dir, 'check-runs.txt');
1063
1119
  writeVerificationPackage(f, `const fs=require('node:fs');fs.appendFileSync(${JSON.stringify(checkLog)},'x\\n');console.error('AssertionError [ERR_ASSERTION]: stable fixture failure');process.exit(1)`);
1064
1120
  let dispose;
@@ -1083,12 +1139,11 @@ test('V2 consumers α3: duplicate completion notifications do not advance Rule-o
1083
1139
  assert.equal(await waitUntil(() => fs.existsSync(editStateArtifact(f.workspace, sessionID))
1084
1140
  && readJson(editStateArtifact(f.workspace, sessionID)).followUpPending === true), true,
1085
1141
  `revision ${i + 1} recorded one completed failing check`);
1086
- const breaker = readJson(path.join(stateDir(f.workspace, sessionID), 'circuit-breaker.json'));
1087
- const count = Object.values(breaker.failures)[0]?.count;
1088
- assert.equal(count, i + 1, `duplicate completion for revision ${i + 1} does not add a failure`);
1089
- assert.equal(breaker.reflectionPending, i === 2, 'reflection is forced only on the third separate failed revision');
1090
1142
  assert.equal(fs.readFileSync(checkLog, 'utf8').trim().split(/\r?\n/).length, i + 1, 'one check ran per edit revision');
1091
- assert.equal(readJson(path.join(stateDir(f.workspace, sessionID), 'compliance.json')).circuitBreakerTrips, i === 2 ? 1 : 0);
1143
+ assert.equal(fs.existsSync(path.join(stateDir(f.workspace, sessionID), 'circuit-breaker.json')), false,
1144
+ 'verification failure does not create recurrence state');
1145
+ assert.equal(readJson(path.join(stateDir(f.workspace, sessionID), 'compliance.json')).totalEdits, i + 1,
1146
+ 'each new edit is recorded once');
1092
1147
  }
1093
1148
  } finally {
1094
1149
  if (dispose) await dispose();