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
@@ -51,8 +51,8 @@ helper.check(
51
51
  // packages/plugin/src/index.ts and packages/web/.../plugins.mdx in the
52
52
  // opencode source - see opencode-plugin/README.md). Two isolations are
53
53
  // load-bearing: HOME -> temp, because the plugin persists under
54
- // ~/.agents/harness-everything/ and an un-redirected run would corrupt a
55
- // real session's circuit-breaker state; workspace -> temp, with a
54
+ // ~/.agents/harness-everything/ and an un-redirected run would corrupt real
55
+ // session state; workspace -> temp, with a
56
56
  // package.json this test controls, so verification pass/fail is
57
57
  // deterministic.
58
58
  (async () => {
@@ -147,263 +147,125 @@ helper.check(
147
147
  );
148
148
  helper.check('2n. no follow-up prompt is sent when verification passes', promptCalls.length === 0, `${promptCalls.length} prompt(s) sent`);
149
149
 
150
- // --- verification gate: failing case drives the circuit breaker ---
150
+ // Repeated verification failures keep reminding but never block permitted edits.
151
151
  writePackageScript('node -e "process.exit(1)"');
152
-
153
- for (let i = 1; i <= 2; i++) {
152
+ const editAllowedAfterFailures = [];
153
+ for (let i = 1; i <= 4; i++) {
154
+ let allowed = true;
155
+ try {
156
+ await hooks['tool.execute.before']({ tool: 'edit', sessionID: 's1', callID: `retry-${i}` }, { args: {} });
157
+ } catch {
158
+ allowed = false;
159
+ }
160
+ editAllowedAfterFailures.push(allowed);
161
+ if (!allowed) break;
154
162
  await hooks['tool.execute.after']({ tool: 'edit', sessionID: 's1', callID: `c${i + 1}` }, { title: '', output: '', metadata: {} });
155
163
  await hooks.event({ event: { type: 'session.idle', properties: { sessionID: 's1' } } });
156
164
  }
157
- let breaker = JSON.parse(fs.readFileSync(breakerFile, 'utf8'));
158
- const sig = Object.keys(breaker.failures)[0];
159
165
  helper.check(
160
- '2n. two failures on the same signature: still allowed, not yet tripped',
161
- breaker.failures[sig].count === 2 && breaker.hardLock === undefined,
162
- JSON.stringify(breaker)
166
+ '2n. four edits proceed through repeated failures, including beyond the former threshold',
167
+ editAllowedAfterFailures.every(Boolean),
168
+ JSON.stringify(editAllowedAfterFailures)
163
169
  );
164
- helper.check('2n. each failed verification sends exactly one follow-up prompt', promptCalls.length === 2, `${promptCalls.length} prompt(s) sent`);
165
-
166
- // 3rd failure -> force reflection
167
- await hooks['tool.execute.after']({ tool: 'edit', sessionID: 's1', callID: 'c4' }, { title: '', output: '', metadata: {} });
168
- await hooks.event({ event: { type: 'session.idle', properties: { sessionID: 's1' } } });
169
- breaker = JSON.parse(fs.readFileSync(breakerFile, 'utf8'));
170
- let compliance = JSON.parse(fs.readFileSync(complianceFile, 'utf8'));
170
+ const failurePrompts = promptCalls.map((call) => call.body.parts[0].text);
171
171
  helper.check(
172
- '2n. 3rd failure on the same signature forces reflection',
173
- breaker.failures[sig].count === 3 && compliance.reflectionsForced === 1,
174
- JSON.stringify({ breaker, compliance })
172
+ '2n. each failed verification sends a reminder without a trip, token, or report demand',
173
+ failurePrompts.length === 4 && failurePrompts.every((text) => /verification failed/i.test(text)
174
+ && !/reflection token|## Goal|forced reflection|retries before/i.test(text)),
175
+ JSON.stringify(failurePrompts)
175
176
  );
176
177
  helper.check(
177
- '2n. the forced-reflection prompt says to reflect',
178
- /reflect/i.test(promptCalls[promptCalls.length - 1].body.parts[0].text),
179
- promptCalls[promptCalls.length - 1].body.parts[0].text
178
+ '2n. verification failures create no breaker file or trip counters',
179
+ !fs.existsSync(breakerFile)
180
+ && !Object.hasOwn(JSON.parse(fs.readFileSync(complianceFile, 'utf8')), 'circuitBreakerTrips')
181
+ && !Object.hasOwn(JSON.parse(fs.readFileSync(complianceFile, 'utf8')), 'reflectionsForced'),
182
+ fs.existsSync(breakerFile) ? fs.readFileSync(breakerFile, 'utf8') : JSON.stringify(JSON.parse(fs.readFileSync(complianceFile, 'utf8')))
180
183
  );
181
184
 
182
- let pendingEditBlocked = false;
183
- try {
184
- await hooks['tool.execute.before']({ tool: 'edit', sessionID: 's1', callID: 'pending-edit' }, { args: {} });
185
- } catch {
186
- pendingEditBlocked = true;
187
- }
188
- helper.check('2n. pending reflection blocks another code edit', pendingEditBlocked, 'tool.execute.before allowed an edit before the report');
189
-
190
185
  let pendingReadAllowed = true;
191
186
  try {
192
187
  await hooks['tool.execute.before']({ tool: 'read', sessionID: 's1', callID: 'pending-read' }, { args: {} });
193
188
  } catch {
194
189
  pendingReadAllowed = false;
195
190
  }
196
- helper.check('2n. pending reflection still allows read tools', pendingReadAllowed, 'tool.execute.before blocked a read during reflection');
197
-
198
- // Complete the reflection through the real hook sequence: the forced
199
- // prompt names a token and artifact, then the agent writes that artifact
200
- // through an edit-shaped tool call. No test seeding of breaker state.
201
- const reflectionPrompt = promptCalls[promptCalls.length - 1].body.parts[0].text;
202
- const reflectionTokenMatch = reflectionPrompt.match(/reflection token: ([A-Za-z0-9_-]+)/i);
203
- helper.check('2n. the forced-reflection prompt names a verifiable artifact token', !!reflectionTokenMatch, reflectionPrompt);
204
- const reflectionToken = reflectionTokenMatch && reflectionTokenMatch[1];
205
- const reflectionFile = path.join(stateDir, 'zoom-out-report.md');
206
- fs.writeFileSync(
207
- reflectionFile,
208
- `RESUME: misplaced\n## Goal\nfix the fixture\n## Failed Attempts\nthree retries\n## Verified Facts\ntest remains red\n## Diagnosis\nthe fixture intentionally fails\n## Decision\nA decision without a directive\nReflection token: ${reflectionToken}\n`,
209
- 'utf8'
210
- );
211
- await hooks['tool.execute.after'](
212
- { tool: 'write', sessionID: 's1', callID: 'reflection' },
213
- { title: '', output: '', metadata: {}, args: { filePath: reflectionFile } }
214
- );
215
- breaker = JSON.parse(fs.readFileSync(breakerFile, 'utf8'));
216
- helper.check(
217
- '2n. a directive outside the Decision section does not complete reflection',
218
- breaker.reflectionPending === true && breaker.lastReflection === null,
219
- JSON.stringify(breaker)
220
- );
221
-
222
- fs.writeFileSync(
223
- reflectionFile,
224
- `## Goal\nfix the fixture\n## Failed Attempts\nthree retries\n## Verified Facts\ntest remains red\n## Diagnosis\nthe fixture intentionally fails\n## Decision\nRESUME: change the fixture\nReflection token: ${reflectionToken}\n`,
225
- 'utf8'
226
- );
227
- await hooks['tool.execute.after'](
228
- { tool: 'apply_patch', sessionID: 's1', callID: 'reflection-patch' },
229
- {
230
- title: '',
231
- output: '',
232
- metadata: {},
233
- args: { patchText: `*** Begin Patch\n*** Update File: ${reflectionFile}\n@@\n*** End Patch` }
234
- }
235
- );
236
- breaker = JSON.parse(fs.readFileSync(breakerFile, 'utf8'));
237
- helper.check(
238
- '2n. apply_patch reflection completes the lifecycle, resets the signature count, and persists lastReflection',
239
- Number.isFinite(breaker.lastReflection) && breaker.lastReflection > 0 && breaker.reflectionPending === false && breaker.failures[sig].count === 0,
240
- JSON.stringify(breaker)
241
- );
242
-
243
- // A repeated idle event after the follow-up is already pending is a no-op.
244
- // The breaker must wait for a fresh code edit before counting another try.
245
- const promptsAfterReflection = promptCalls.length;
246
- await hooks.event({ event: { type: 'session.idle', properties: { sessionID: 's1' } } });
247
- helper.check(
248
- '2n. repeated idle does not duplicate verification or follow-up prompts',
249
- promptCalls.length === promptsAfterReflection,
250
- `${promptCalls.length} prompt(s) sent`
251
- );
252
-
253
- const patchSessionDir = path.join(stateRoot, 'sessions', 'patch-only');
254
- const patchBreakerFile = path.join(patchSessionDir, 'circuit-breaker.json');
255
- const patchReflectionFile = path.join(patchSessionDir, 'zoom-out-report.md');
256
- const patchReflectionToken = 'patch-reflection-token';
257
- fs.mkdirSync(patchSessionDir, { recursive: true });
258
- fs.writeFileSync(
259
- patchBreakerFile,
260
- JSON.stringify({
261
- failures: { fixture: { count: 3, firstSeen: Date.now() - 1000 } },
262
- hardLock: false,
263
- lastReflection: null,
264
- lastReflectionSignature: null,
265
- reflectionPending: true,
266
- reflectionRequestedAt: Date.now(),
267
- reflectionToken: patchReflectionToken,
268
- reflectionSignature: 'fixture'
269
- }, null, 2),
270
- 'utf8'
271
- );
272
- fs.writeFileSync(
273
- patchReflectionFile,
274
- `## Goal\nfix the fixture\n## Failed Attempts\nthree retries\n## Verified Facts\ntest remains red\n## Diagnosis\nthe fixture intentionally fails\n## Decision\nRESUME: change the fixture\nReflection token: ${patchReflectionToken}\n`,
275
- 'utf8'
276
- );
277
- const patchText = `*** Begin Patch\n*** Update File: ${patchReflectionFile}\n@@\n*** End Patch`;
278
- let patchBeforeAllowed = true;
191
+ helper.check('2n. non-edit tools remain available after repeated failures', pendingReadAllowed, 'tool.execute.before blocked a read');
192
+
193
+ const legacyPendingDir = path.join(stateRoot, 'sessions', 'legacy-pending');
194
+ const legacyBreakerFile = path.join(legacyPendingDir, 'circuit-breaker.json');
195
+ fs.mkdirSync(legacyPendingDir, { recursive: true });
196
+ const legacyPendingState = JSON.stringify({
197
+ failures: { old: { count: 3, firstSeen: 1, lastSeen: 2 } },
198
+ reflectionPending: true, reflectionRequestedAt: 2, reflectionToken: 'old-token', reflectionSignature: 'old'
199
+ }, null, 2);
200
+ fs.writeFileSync(legacyBreakerFile, legacyPendingState);
201
+ let legacyEditAllowed = true;
279
202
  try {
280
- await hooks['tool.execute.before'](
281
- { tool: 'apply_patch', sessionID: 'patch-only', callID: 'patch-before' },
282
- { args: { patchText } }
283
- );
284
- } catch (error) {
285
- patchBeforeAllowed = false;
203
+ await hooks['tool.execute.before']({ tool: 'edit', sessionID: 'legacy-pending', callID: 'legacy-edit' }, { args: {} });
204
+ } catch {
205
+ legacyEditAllowed = false;
286
206
  }
287
207
  helper.check(
288
- '2n. apply_patch is allowed to write a pending reflection artifact',
289
- patchBeforeAllowed,
290
- 'tool.execute.before blocked output.args.patchText'
208
+ '2n. legacy pending reflection state stays inert and does not block an edit',
209
+ legacyEditAllowed && fs.readFileSync(legacyBreakerFile, 'utf8') === legacyPendingState,
210
+ fs.readFileSync(legacyBreakerFile, 'utf8')
291
211
  );
292
- await hooks['tool.execute.after'](
293
- { tool: 'apply_patch', sessionID: 'patch-only', callID: 'patch-after' },
294
- { title: '', output: '', metadata: {}, args: { patchText } }
295
- );
296
- const patchBreaker = JSON.parse(fs.readFileSync(patchBreakerFile, 'utf8'));
297
- helper.check(
298
- '2n. apply_patch output args complete a pending reflection',
299
- patchBreaker.reflectionPending === false && Number.isFinite(patchBreaker.lastReflection),
300
- JSON.stringify(patchBreaker)
301
- );
302
-
303
- const mixedPatchSessionDir = path.join(stateRoot, 'sessions', 'mixed-patch');
304
- const mixedPatchBreakerFile = path.join(mixedPatchSessionDir, 'circuit-breaker.json');
305
- const mixedPatchReflectionFile = path.join(mixedPatchSessionDir, 'zoom-out-report.md');
306
- fs.mkdirSync(mixedPatchSessionDir, { recursive: true });
307
- fs.writeFileSync(mixedPatchBreakerFile, JSON.stringify({
308
- failures: { fixture: { count: 3, firstSeen: Date.now() - 1000 } },
309
- hardLock: false,
310
- lastReflection: null,
311
- lastReflectionSignature: null,
312
- reflectionPending: true,
313
- reflectionRequestedAt: Date.now(),
314
- reflectionToken: 'mixed-patch-token',
315
- reflectionSignature: 'fixture'
316
- }, null, 2));
317
- fs.writeFileSync(mixedPatchReflectionFile, [
318
- '## Goal', 'fix the fixture', '## Failed Attempts', 'three retries',
319
- '## Verified Facts', 'test remains red', '## Diagnosis', 'the fixture intentionally fails',
320
- '## Decision', 'RESUME: change the fixture', 'Reflection token: mixed-patch-token', ''
321
- ].join('\n'));
322
- let mixedPatchBlocked = false;
323
- try {
324
- await hooks['tool.execute.before'](
325
- { tool: 'apply_patch', sessionID: 'mixed-patch', callID: 'mixed-before' },
326
- { args: { patchText: `*** Begin Patch\n*** Update File: ${mixedPatchReflectionFile}\n@@\n*** Update File: ${path.join(workspace, 'unrelated.js')}\n@@\n*** End Patch` } }
212
+ if (legacyEditAllowed) {
213
+ await hooks['tool.execute.after'](
214
+ { tool: 'edit', sessionID: 'legacy-pending', callID: 'legacy-edit-after' },
215
+ { title: '', output: '', metadata: {}, args: { filePath: path.join(workspace, 'legacy.js') } }
327
216
  );
328
- } catch {
329
- mixedPatchBlocked = true;
330
217
  }
331
- helper.check('2n. mixed apply_patch cannot bypass a pending reflection', mixedPatchBlocked, 'unrelated files were accepted with the reflection artifact');
218
+ helper.check('2n. legacy pending state permits the full V1 edit lifecycle',
219
+ JSON.parse(fs.readFileSync(path.join(legacyPendingDir, 'edit-state.json'), 'utf8')).verificationPending === true,
220
+ path.join(legacyPendingDir, 'edit-state.json'));
332
221
 
333
- // A fresh failure after reflection starts a new three-failure cycle.
334
- await hooks['tool.execute.after']({ tool: 'edit', sessionID: 's1', callID: 'c5' }, { title: '', output: '', metadata: {} });
222
+ // A repeated idle event after a follow-up is already pending is a no-op.
223
+ const promptsAfterFailure = promptCalls.length;
335
224
  await hooks.event({ event: { type: 'session.idle', properties: { sessionID: 's1' } } });
336
- breaker = JSON.parse(fs.readFileSync(breakerFile, 'utf8'));
337
- helper.check('2n. first post-reflection failure starts again at count=1', breaker.failures[sig].count === 1 && breaker.reflectionPending === false, JSON.stringify(breaker));
338
- let postReflectionEditAllowed = true;
339
- try {
340
- await hooks['tool.execute.before']({ tool: 'edit', sessionID: 's1', callID: 'c6' }, { args: {} });
341
- } catch {
342
- postReflectionEditAllowed = false;
343
- }
344
- helper.check('2n. no permanent post-reflection hard lock remains', postReflectionEditAllowed, 'tool.execute.before unexpectedly blocked after one fresh failure');
345
-
346
- // The same workspace can host independent sessions. Session s2 starts with
347
- // a fresh breaker and cannot inherit s1 state.
348
- await hooks['tool.execute.after']({ tool: 'edit', sessionID: 's2', callID: 's2-c1', args: {} }, { title: '', output: '', metadata: {} });
349
- await hooks.event({ event: { type: 'session.idle', properties: { sessionID: 's2' } } });
350
- const secondBreaker = JSON.parse(fs.readFileSync(path.join(secondSessionDir, 'circuit-breaker.json'), 'utf8'));
351
225
  helper.check(
352
- '2n. a second session has an independent breaker stream',
353
- secondBreaker.hardLock === undefined && Object.values(secondBreaker.failures).some((entry) => entry.count === 1),
354
- JSON.stringify(secondBreaker)
226
+ '2n. repeated idle does not duplicate verification or follow-up prompts',
227
+ promptCalls.length === promptsAfterFailure,
228
+ `${promptCalls.length} prompt(s) sent`
355
229
  );
356
230
 
357
- const corruptSessionDir = path.join(stateRoot, 'sessions', 'corrupt');
358
- const corruptBreakerFile = path.join(corruptSessionDir, 'circuit-breaker.json');
359
- fs.mkdirSync(corruptSessionDir, { recursive: true });
360
- fs.writeFileSync(corruptBreakerFile, '{not-json', 'utf8');
361
- let corruptStateBlocked = false;
362
- let corruptStateMessage = '';
363
- try {
364
- await hooks['tool.execute.before']({ tool: 'edit', sessionID: 'corrupt', callID: 'corrupt-edit' }, { args: {} });
365
- } catch (error) {
366
- corruptStateBlocked = true;
367
- corruptStateMessage = String(error && error.message ? error.message : error);
368
- }
231
+ // The same workspace can host independent sessions.
232
+ await hooks['tool.execute.after']({ tool: 'edit', sessionID: 's2', callID: 's2-c1', args: {} }, { title: '', output: '', metadata: {} });
233
+ await hooks.event({ event: { type: 'session.idle', properties: { sessionID: 's2' } } });
369
234
  helper.check(
370
- '2n. corrupt breaker state fails open instead of becoming a cognitive lock',
371
- !corruptStateBlocked,
372
- corruptStateMessage || 'corrupt state was ignored as expected'
235
+ '2n. a second session keeps independent edit state',
236
+ fs.existsSync(path.join(secondSessionDir, 'edit-state.json')) && !fs.existsSync(path.join(secondSessionDir, 'circuit-breaker.json')),
237
+ secondSessionDir
373
238
  );
374
239
 
375
- // A prompt transport failure is retryable without re-running verification
376
- // or incrementing the circuit-breaker count.
240
+ // A prompt transport failure is retryable without re-running verification.
377
241
  const promptsBeforeDeliveryFailure = promptCalls.length;
378
242
  rejectNextPrompt = true;
379
243
  await hooks['tool.execute.after']({ tool: 'edit', sessionID: 'prompt-retry', callID: 'retry-c1' }, { title: '', output: '', metadata: {} });
380
244
  await hooks.event({ event: { type: 'session.idle', properties: { sessionID: 'prompt-retry' } } });
381
245
  let retryEditState = JSON.parse(fs.readFileSync(path.join(retrySessionDir, 'edit-state.json'), 'utf8'));
382
- let retryBreaker = JSON.parse(fs.readFileSync(path.join(retrySessionDir, 'circuit-breaker.json'), 'utf8'));
383
246
  helper.check(
384
247
  '2n. failed prompt delivery remains retryable',
385
248
  promptCalls.length === promptsBeforeDeliveryFailure + 1 &&
386
249
  retryEditState.followUpPending === false &&
387
250
  retryEditState.followUpDeliveryPending === true &&
388
- retryBreaker.failures[Object.keys(retryBreaker.failures)[0]].count === 1,
389
- JSON.stringify({ retryEditState, retryBreaker })
251
+ !fs.existsSync(path.join(retrySessionDir, 'circuit-breaker.json')),
252
+ JSON.stringify(retryEditState)
390
253
  );
391
254
  await hooks.event({ event: { type: 'session.idle', properties: { sessionID: 'prompt-retry' } } });
392
255
  retryEditState = JSON.parse(fs.readFileSync(path.join(retrySessionDir, 'edit-state.json'), 'utf8'));
393
- retryBreaker = JSON.parse(fs.readFileSync(path.join(retrySessionDir, 'circuit-breaker.json'), 'utf8'));
394
256
  helper.check(
395
257
  '2n. next idle retries the saved follow-up exactly once',
396
258
  promptCalls.length === promptsBeforeDeliveryFailure + 2 &&
397
259
  retryEditState.followUpPending === true &&
398
260
  retryEditState.followUpDeliveryPending === false &&
399
- retryBreaker.failures[Object.keys(retryBreaker.failures)[0]].count === 1,
400
- JSON.stringify({ retryEditState, retryBreaker })
261
+ !fs.existsSync(path.join(retrySessionDir, 'circuit-breaker.json')),
262
+ JSON.stringify(retryEditState)
401
263
  );
402
264
 
403
265
  // A fresh session event is the explicit reset contract for a reused session
404
266
  // identity, and it removes only that session's plugin state.
405
267
  await hooks.event({ event: { type: 'session.created', properties: { info: { id: 's1' } } } });
406
- helper.check('2n. session.created resets only the current session state', !fs.existsSync(breakerFile), breakerFile);
268
+ helper.check('2n. session.created resets only the current session state', !fs.existsSync(editStateFile), editStateFile);
407
269
  let resetAllowed = true;
408
270
  try {
409
271
  await hooks['tool.execute.before']({ tool: 'edit', sessionID: 's1', callID: 'after-reset' }, { args: {} });
@@ -429,7 +291,7 @@ helper.check(
429
291
  sessionEntries.map((entry) => entry.name).join(', ')
430
292
  );
431
293
  helper.check('2n. resetting an unsafe session cannot delete an outside sentinel', fs.existsSync(path.join(outsideSentinel, 'keep.txt')), outsideSentinel);
432
- helper.check('2n. resetting s1 leaves the independent s2 state', fs.existsSync(path.join(secondSessionDir, 'circuit-breaker.json')), secondSessionDir);
294
+ helper.check('2n. resetting s1 leaves the independent s2 state', fs.existsSync(path.join(secondSessionDir, 'edit-state.json')), secondSessionDir);
433
295
 
434
296
  const workspaceStateRoot = path.dirname(stateRoot);
435
297
  helper.check(
@@ -45,6 +45,7 @@ helper.check(
45
45
  const registered = [];
46
46
  const sessionHooks = [];
47
47
  let subscribeCount = 0;
48
+ let consumedEvents = 0;
48
49
  const eventQueue = [];
49
50
  const fakeCtx = {
50
51
  location: { directory: workspace },
@@ -76,6 +77,7 @@ helper.check(
76
77
  if (options.signal.aborted) return { done: true, value: undefined };
77
78
  await new Promise((resolve) => setTimeout(resolve, 5));
78
79
  }
80
+ consumedEvents++;
79
81
  return { done: false, value: eventQueue.shift() };
80
82
  },
81
83
  }),
@@ -89,7 +91,10 @@ helper.check(
89
91
  const waitFor = async (predicate) => {
90
92
  const deadline = Date.now() + 5000;
91
93
  while (!predicate()) {
92
- if (Date.now() > deadline) throw new Error('V2 async verification did not settle');
94
+ if (Date.now() > deadline) {
95
+ const editState = path.join(stateRoot, 's1', 'edit-state.json');
96
+ throw new Error(`V2 async verification did not settle: prompts=${prompts.length}; consumedEvents=${consumedEvents}; queued=${eventQueue.length}; editState=${fs.existsSync(editState) ? fs.readFileSync(editState, 'utf8') : 'missing'}`);
97
+ }
93
98
  await new Promise(resolve => setTimeout(resolve, 20));
94
99
  }
95
100
  };
@@ -128,59 +133,73 @@ helper.check(
128
133
  const before = registered.find((r) => r.name === 'execute.before').callback;
129
134
  const after = registered.find((r) => r.name === 'execute.after').callback;
130
135
 
131
- // Flow 1: a failure loop drives verification through real V2 event shapes:
136
+ // Flow 1: repeated failures use real V2 event shapes and leave edits available:
132
137
  // execute.before/after carry {tool, sessionID, id, input}; the event stream
133
138
  // carries flat {type, sessionID}.
134
139
  const sessionDir = path.join(stateRoot, 's1');
135
140
  for (let i = 1; i <= 3; i++) {
141
+ await before({ tool: 'edit', sessionID: 's1', id: `before-${i}`, input: {} });
136
142
  await after({ tool: 'edit', sessionID: 's1', id: `c${i}`, input: {} });
137
143
  push({ type: 'session.idle', sessionID: 's1' });
138
144
  await waitFor(() => prompts.length === i);
139
145
  }
140
146
 
141
147
  helper.check(
142
- '2p. three v2-shaped edit/idle cycles force reflection',
148
+ '2p. three v2-shaped edit/idle cycles send verification reminders',
143
149
  prompts.length === 3,
144
150
  `prompts: ${prompts.length}`
145
151
  );
146
152
 
147
153
  helper.check(
148
154
  '2p. the V2 ctx.session.prompt receives {sessionID, text}, not the V1 {path, body} shape',
149
- prompts.every((p) => typeof p.sessionID === 'string' && typeof p.text === 'string'),
155
+ prompts.every((p) => typeof p.sessionID === 'string' && typeof p.text === 'string'
156
+ && /verification failed/i.test(p.text) && !/reflection token|## Goal|forced reflection|retries before/i.test(p.text)),
150
157
  JSON.stringify(prompts)
151
158
  );
152
159
 
153
- const breaker = JSON.parse(fs.readFileSync(path.join(sessionDir, 'circuit-breaker.json'), 'utf8'));
154
- const signature = Object.keys(breaker.failures)[0];
155
160
  helper.check(
156
- '2p. three same-signature failures via the v2 hooks force reflectionPending',
157
- breaker.failures[signature].count === 3 && breaker.reflectionPending === true,
158
- JSON.stringify(breaker)
161
+ '2p. repeated failures create no breaker state',
162
+ !fs.existsSync(path.join(sessionDir, 'circuit-breaker.json')),
163
+ sessionDir
159
164
  );
160
165
 
161
- let blocked = false;
166
+ let nextEditAllowed = true;
162
167
  try {
163
- await before({ tool: 'edit', sessionID: 's1', id: 'blocked-edit', input: {} });
168
+ await before({ tool: 'edit', sessionID: 's1', id: 'after-threshold', input: {} });
164
169
  } catch {
165
- blocked = true;
170
+ nextEditAllowed = false;
171
+ }
172
+ if (nextEditAllowed) {
173
+ await after({ tool: 'edit', sessionID: 's1', id: 'after-threshold-ran', input: { filePath: path.join(workspace, 'after-threshold.js') } });
174
+ }
175
+ helper.check('2p. the next v2-shaped edit remains available after the former threshold', nextEditAllowed);
176
+ helper.check('2p. the permitted next edit reaches the V2 after hook',
177
+ nextEditAllowed && JSON.parse(fs.readFileSync(path.join(sessionDir, 'edit-state.json'), 'utf8')).editRevision === 4,
178
+ sessionDir);
179
+
180
+ // A pre-retirement pending token is inert at the V2 adapter seam.
181
+ const legacyDir = path.join(stateRoot, 'legacy-pending');
182
+ const legacyBreakerFile = path.join(legacyDir, 'circuit-breaker.json');
183
+ fs.mkdirSync(legacyDir, { recursive: true });
184
+ const legacyState = JSON.stringify({
185
+ failures: { old: { count: 3, firstSeen: 1, lastSeen: 2 } },
186
+ reflectionPending: true, reflectionRequestedAt: 2, reflectionToken: 'old-token', reflectionSignature: 'old'
187
+ }, null, 2);
188
+ fs.writeFileSync(legacyBreakerFile, legacyState);
189
+ let legacyEditAllowed = true;
190
+ try {
191
+ await before({ tool: 'edit', sessionID: 'legacy-pending', id: 'legacy-edit', input: {} });
192
+ } catch {
193
+ legacyEditAllowed = false;
194
+ }
195
+ if (legacyEditAllowed) {
196
+ await after({ tool: 'edit', sessionID: 'legacy-pending', id: 'legacy-edit-after', input: { filePath: path.join(workspace, 'legacy.js') } });
166
197
  }
167
- helper.check('2p. a pending reflection blocks a v2-shaped edit call', blocked, 'edit call was allowed during pending reflection');
168
-
169
- // Flow 2: the reflection artifact is accepted through the V2 after hook,
170
- // proving input-args mapping across the adapter.
171
- const token = (prompts.map((p) => (p.text.match(/reflection token: ([A-Za-z0-9_-]+)/i) || [])[1]).filter(Boolean).pop());
172
- const reflectionFile = path.join(sessionDir, 'zoom-out-report.md');
173
- fs.writeFileSync(
174
- reflectionFile,
175
- `## Goal\nfix the fixture\n## Failed Attempts\nthree retries\n## Verified Facts\ntest stays red\n## Diagnosis\nthe fixture intentionally fails\n## Decision\nRESUME: change the fixture\nReflection token: ${token}\n`
176
- );
177
- await after({ tool: 'write', sessionID: 's1', id: 'reflect-write', input: { filePath: reflectionFile } });
178
-
179
- const breakerAfter = JSON.parse(fs.readFileSync(path.join(sessionDir, 'circuit-breaker.json'), 'utf8'));
180
198
  helper.check(
181
- '2p. a v2-shaped reflection artifact completes the reflection',
182
- breakerAfter.reflectionPending === false && Number.isFinite(breakerAfter.lastReflection) && breakerAfter.failures[signature].count === 0,
183
- JSON.stringify(breakerAfter)
199
+ '2p. legacy pending token state stays inert and the V2 edit completes',
200
+ legacyEditAllowed && fs.readFileSync(legacyBreakerFile, 'utf8') === legacyState
201
+ && fs.existsSync(path.join(legacyDir, 'edit-state.json')),
202
+ legacyDir
184
203
  );
185
204
 
186
205
  // Flow 3: session reset through the flat V2 event shape.
@@ -79,6 +79,7 @@ for (const platform of matrix.platforms) {
79
79
  assert.ok(fs.statSync(path.join(artifactRoot, file)).size > 0, `Missing OpenCode evidence: ${file}`);
80
80
  }
81
81
  const session = path.join(artifactRoot, 'state', 'sessions', 'ses_f5520f1d9ffeB8KLTIUKgA5ng8');
82
+ // This is an archived post-reset snapshot, not a current behavior witness.
82
83
  const breaker = JSON.parse(fs.readFileSync(path.join(session, 'circuit-breaker.json'), 'utf8'));
83
84
  const compliance = JSON.parse(fs.readFileSync(path.join(session, 'compliance.json'), 'utf8'));
84
85
  assert.strictEqual(breaker.hardLock, false, 'Retained snapshot is post-reset, not hard-lock proof');
@@ -312,7 +312,6 @@ try {
312
312
  effect_type: 'plugin-enforcement',
313
313
  contract: pluginContract,
314
314
  contract_sha256: hash(pluginContract),
315
- preflight: { passed: true, plugin_sha256: 'plugin-hash' },
316
315
  arms: {
317
316
  baseline: {
318
317
  ...arm('fail', true),
@@ -329,7 +328,7 @@ try {
329
328
  },
330
329
  };
331
330
  helper.check(
332
- '32. plugin pair is includable only when preflight, hash, constant skill text, and per-arm attribution agree',
331
+ '32. plugin pair is includable with a matching hash, constant skill text, and per-arm attribution',
333
332
  validatePairRecord(pluginPair).included,
334
333
  JSON.stringify(validatePairRecord(pluginPair)),
335
334
  );
@@ -24,7 +24,7 @@ check(/STATE_DIR=\$\(node -e[\s\S]*getSessionDir\(null, 'default'\)/.test(docker
24
24
  '#205 docker verifier resolves one canonical session state directory');
25
25
  check(!dockerVerify.includes(legacyStatePath),
26
26
  '#205 docker verifier does not seed or read the legacy repo-relative state directory');
27
- check((dockerVerify.match(/\$STATE_DIR\//g) || []).length >= 10,
27
+ check((dockerVerify.match(/\$STATE_DIR\//g) || []).length >= 8,
28
28
  '#205 docker verifier routes all state checks through STATE_DIR');
29
29
 
30
30
  const architecture = fs.readFileSync(path.join(ROOT, 'docs/architecture.md'), 'utf8');