harness-everything 0.55.3 → 0.56.0

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 (179) 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 +26 -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/468-dispatch/runner.js +144 -0
  16. package/ci/fixtures/doc-obligations/reconciliation-s2b/wiring/legacy-off-golden.json +0 -6
  17. package/ci/invariant-routing.test.js +26 -5
  18. package/ci/lib/opencode-verification-loader.js +3 -5
  19. package/ci/mechanism-2a-rule-of-3.test.js +111 -97
  20. package/ci/mechanism-2n-opencode-plugin.test.js +68 -206
  21. package/ci/mechanism-2p-opencode-v2-entrypoint.test.js +47 -28
  22. package/ci/mechanism-2w-platform-compatibility.test.js +1 -0
  23. package/ci/mechanism-32-paired-benchmark.test.js +1 -2
  24. package/ci/mechanism-33-issues-205-207.test.js +1 -1
  25. package/ci/mechanism-338-opencode-async.test.js +18 -49
  26. package/ci/mechanism-36-verify-timeout.test.js +3 -189
  27. package/ci/mechanism-39-opencode-verify-outcomes.test.js +56 -323
  28. package/ci/mechanism-397-opencode-observations.test.js +6 -7
  29. package/ci/mechanism-468-dispatch-cli.test.js +546 -0
  30. package/ci/mechanism-codex-hook-results.test.js +9 -5
  31. package/ci/mechanism-error-handling-map.test.js +14 -12
  32. package/ci/mechanism-prb-outline-review.test.js +1 -13
  33. package/ci/mechanism-system-one-router.test.js +1 -1
  34. package/ci/openai-plugin-package.test.js +30 -7
  35. package/ci/openai-plugin-runtime.test.js +64 -32
  36. package/ci/prompt-contract-regressions.test.js +1 -5
  37. package/ci/self-evolve-loop.test.js +51 -51
  38. package/ci/workflow-execution-contract.test.js +3 -6
  39. package/docker-verify.sh +1 -117
  40. package/docs/architecture.md +9 -7
  41. package/docs/document-lifecycle.md +1 -1
  42. package/docs/enforcement-locks.md +12 -10
  43. package/docs/error-handling/README.md +3 -3
  44. package/docs/error-handling/actions/c8-action-map.md +41 -0
  45. package/docs/error-handling/details/c8-dispatch-cli.md +75 -0
  46. package/docs/error-handling/nodes.yaml +5 -0
  47. package/docs/error-handling/registry.md +4 -1
  48. package/docs/mechanism-first-skill-mesh.md +2 -2
  49. package/docs/openai-plugin.md +3 -3
  50. package/docs/philosophy.md +1 -1
  51. package/docs/platform-capabilities.md +2 -2
  52. package/docs/platform-compatibility.json +2 -2
  53. package/docs/reflection.md +1 -1
  54. package/docs/routing.md +2 -2
  55. package/docs/system-one-suggestion-gates.md +4 -4
  56. package/docs/troubleshooting.md +9 -35
  57. package/docs/workflow-runtime.md +19 -18
  58. package/docs/workflows/environment-detection.md +11 -9
  59. package/docs/workflows/fable-discipline.md +6 -5
  60. package/docs/workflows/fable-mode.md +6 -5
  61. package/docs/workflows/harness-everything.md +5 -5
  62. package/docs/workflows/improve-codebase-architecture.md +10 -8
  63. package/docs/workflows/install-cognitive-os.md +5 -5
  64. package/docs/workflows/tdd.md +9 -9
  65. package/docs/workflows/zoom-out.md +20 -30
  66. package/environment-detection/SKILL.md +2 -2
  67. package/environment-detection/references/shell-syntax-rules.md +1 -1
  68. package/eval-harness/SKILL.md +1 -1
  69. package/eval-harness/references/scoring-rubric.md +3 -3
  70. package/evals/zoom-out/eval.yaml +2 -2
  71. package/evals/zoom-out/tasks/negative-productive-iteration.yaml +15 -0
  72. package/evals/zoom-out/tasks/negative-trivial-edit.yaml +6 -6
  73. package/evals/zoom-out/tasks/positive-first-failure.yaml +15 -0
  74. package/evals/zoom-out/tasks/positive-repair-loop.yaml +1 -1
  75. package/fable-discipline/SKILL.md +3 -3
  76. package/fable-discipline/references/discipline-rules.md +1 -1
  77. package/fable-mode/SKILL.md +1 -1
  78. package/fable-mode/execution-guardrails/SKILL.md +2 -4
  79. package/fable-mode/execution-guardrails/references/guardrail-rules.md +3 -3
  80. package/fable-mode/fable-haiku/SKILL.md +1 -1
  81. package/fable-mode/fable-opus/SKILL.md +2 -2
  82. package/fable-mode/fable-sonnet/SKILL.md +1 -1
  83. package/fable-mode/references/execution-phases.md +2 -2
  84. package/harness-everything/SKILL.md +3 -3
  85. package/harness-everything/references/router-workflow-plan.md +2 -2
  86. package/harness-everything/references/skill-registry.md +2 -2
  87. package/harness-everything/references/triage-and-tiers.md +5 -5
  88. package/harness-everything/scripts/bootstrap.js +1 -26
  89. package/harness-everything/scripts/kernel-router-core.js +2 -3
  90. package/harness-everything/scripts/kernel-router.js +1 -1
  91. package/harness-everything/scripts/router-contract-core.js +1 -1
  92. package/harness-everything/scripts/routing-keywords.json +0 -2
  93. package/hooks/hooks.json +0 -33
  94. package/hooks/scripts/lib/harness-state.js +5 -6
  95. package/hooks/scripts/lib/learning-opportunity.js +3 -13
  96. package/hooks/scripts/openai-session-start.js +2 -4
  97. package/improve-codebase-architecture/SKILL.md +3 -3
  98. package/improve-codebase-architecture/guides/refactoring-workflow.md +5 -4
  99. package/install-cognitive-os/SKILL.md +3 -3
  100. package/opencode-plugin/README.md +12 -43
  101. package/opencode-plugin/index.mjs +21 -368
  102. package/opencode-plugin/plugin.json +1 -1
  103. package/package.json +2 -4
  104. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  105. package/plugins/harness-everything/hooks/hooks.json +0 -14
  106. package/plugins/harness-everything/hooks/scripts/lib/harness-state.js +5 -6
  107. package/plugins/harness-everything/hooks/scripts/lib/learning-opportunity.js +3 -13
  108. package/plugins/harness-everything/hooks/scripts/lib/workspace.js +2 -2
  109. package/plugins/harness-everything/hooks/scripts/openai-session-start.js +2 -4
  110. package/plugins/harness-everything/hooks/session-start.js +2 -4
  111. package/plugins/harness-everything/plugin.json +1 -1
  112. package/plugins/harness-everything/scripts/lib/advisory-text.js +2 -2
  113. package/plugins/harness-everything/scripts/lib/workspace.js +2 -2
  114. package/plugins/harness-everything/skills/environment-detection/SKILL.md +2 -2
  115. package/plugins/harness-everything/skills/environment-detection/references/shell-syntax-rules.md +1 -1
  116. package/plugins/harness-everything/skills/eval-harness/SKILL.md +1 -1
  117. package/plugins/harness-everything/skills/eval-harness/references/scoring-rubric.md +3 -3
  118. package/plugins/harness-everything/skills/fable-discipline/SKILL.md +3 -3
  119. package/plugins/harness-everything/skills/fable-discipline/references/discipline-rules.md +1 -1
  120. package/plugins/harness-everything/skills/fable-mode/SKILL.md +1 -1
  121. package/plugins/harness-everything/skills/fable-mode/execution-guardrails/SKILL.md +2 -4
  122. package/plugins/harness-everything/skills/fable-mode/execution-guardrails/references/guardrail-rules.md +3 -3
  123. package/plugins/harness-everything/skills/fable-mode/fable-haiku/SKILL.md +1 -1
  124. package/plugins/harness-everything/skills/fable-mode/fable-opus/SKILL.md +2 -2
  125. package/plugins/harness-everything/skills/fable-mode/fable-sonnet/SKILL.md +1 -1
  126. package/plugins/harness-everything/skills/fable-mode/references/execution-phases.md +2 -2
  127. package/plugins/harness-everything/skills/harness-everything/SKILL.md +3 -3
  128. package/plugins/harness-everything/skills/harness-everything/references/router-workflow-plan.md +2 -2
  129. package/plugins/harness-everything/skills/harness-everything/references/skill-registry.md +2 -2
  130. package/plugins/harness-everything/skills/harness-everything/references/triage-and-tiers.md +5 -5
  131. package/plugins/harness-everything/skills/harness-everything/scripts/bootstrap.js +1 -26
  132. package/plugins/harness-everything/skills/harness-everything/scripts/kernel-router-core.js +2 -3
  133. package/plugins/harness-everything/skills/harness-everything/scripts/kernel-router.js +1 -1
  134. package/plugins/harness-everything/skills/harness-everything/scripts/router-contract-core.js +1 -1
  135. package/plugins/harness-everything/skills/harness-everything/scripts/routing-keywords.json +0 -2
  136. package/plugins/harness-everything/skills/improve-codebase-architecture/SKILL.md +3 -3
  137. package/plugins/harness-everything/skills/improve-codebase-architecture/guides/refactoring-workflow.md +5 -4
  138. package/plugins/harness-everything/skills/install-cognitive-os/SKILL.md +3 -3
  139. package/plugins/harness-everything/skills/self-evolve/SKILL.md +1 -1
  140. package/plugins/harness-everything/skills/self-evolve/references/memory-resolution.md +3 -3
  141. package/plugins/harness-everything/skills/self-evolve/schemas/lesson-candidate.schema.json +4 -1
  142. package/plugins/harness-everything/skills/self-evolve/scripts/lesson-candidate.js +1 -0
  143. package/plugins/harness-everything/skills/skill-creator/SKILL.md +1 -1
  144. package/plugins/harness-everything/skills/skill-creator/references/quality-checklist.md +1 -1
  145. package/plugins/harness-everything/skills/skill-creator/references/quality-principles.md +4 -4
  146. package/plugins/harness-everything/skills/tdd/SKILL.md +2 -2
  147. package/plugins/harness-everything/skills/tdd/references/core-discipline.md +3 -5
  148. package/plugins/harness-everything/skills/todo-driven-workflow/SKILL.md +2 -2
  149. package/plugins/harness-everything/skills/zoom-out/SKILL.md +14 -26
  150. package/plugins/harness-everything/skills/zoom-out/references/circuit-breaker.md +18 -62
  151. package/references/platform-advisory-template.md +3 -9
  152. package/sbom.cdx.json +7 -7
  153. package/scripts/dispatch.js +340 -0
  154. package/scripts/lib/advisory-text.js +2 -2
  155. package/scripts/lib/workspace.js +2 -2
  156. package/self-evolve/SKILL.md +1 -1
  157. package/self-evolve/references/memory-resolution.md +3 -3
  158. package/self-evolve/schemas/lesson-candidate.schema.json +4 -1
  159. package/self-evolve/scripts/lesson-candidate.js +1 -0
  160. package/skill-creator/SKILL.md +1 -1
  161. package/skill-creator/references/quality-checklist.md +1 -1
  162. package/skill-creator/references/quality-principles.md +4 -4
  163. package/submission/openai/test-cases.json +5 -5
  164. package/tdd/SKILL.md +2 -2
  165. package/tdd/references/core-discipline.md +3 -5
  166. package/todo-driven-workflow/SKILL.md +2 -2
  167. package/zoom-out/SKILL.md +14 -26
  168. package/zoom-out/references/circuit-breaker.md +18 -62
  169. package/behavioral-evals/opencode-hardlock-live.js +0 -17
  170. package/behavioral-evals/opencode-reflection-gate-live.js +0 -342
  171. package/ci/mechanism-31-opencode-hardlock-evidence.test.js +0 -82
  172. package/evals/zoom-out/tasks/negative-first-edge-case-review.yaml +0 -16
  173. package/evals/zoom-out/tasks/positive-repeated-failure.yaml +0 -15
  174. package/hooks/scripts/reset-circuit-breaker.js +0 -30
  175. package/hooks/scripts/rule-of-3-tracker.js +0 -165
  176. package/hooks/scripts/rule-of-3.js +0 -171
  177. package/plugins/harness-everything/hooks/scripts/reset-circuit-breaker.js +0 -30
  178. package/plugins/harness-everything/hooks/scripts/rule-of-3-tracker.js +0 -165
  179. package/plugins/harness-everything/hooks/scripts/rule-of-3.js +0 -171
@@ -1,116 +1,130 @@
1
- const fs = require('fs');
2
- const path = require('path');
1
+ 'use strict';
2
+
3
+ const assert = require('node:assert/strict');
4
+ const fs = require('node:fs');
5
+ const path = require('node:path');
6
+ const { spawnSync } = require('node:child_process');
3
7
  const helper = require('./test-helper');
4
8
 
5
- console.log('\n[2a] Rule of 3 circuit breaker...');
9
+ const manifest = JSON.parse(fs.readFileSync(path.join(helper.root, 'hooks/hooks.json'), 'utf8'));
10
+ const retiredIds = new Set([
11
+ 'harness:pre:rule-of-3',
12
+ 'harness:post:rule-of-3-tracker',
13
+ 'harness:post-failure:rule-of-3-tracker',
14
+ ]);
15
+ const entries = Object.entries(manifest.hooks).flatMap(([event, groups]) =>
16
+ groups.map(group => ({ event, ...group })));
17
+ const retiredFiles = [
18
+ 'hooks/scripts/rule-of-3.js',
19
+ 'hooks/scripts/rule-of-3-tracker.js',
20
+ 'hooks/scripts/reset-circuit-breaker.js',
21
+ ];
22
+ const registeredRetired = entries.filter(entry => retiredIds.has(entry.id) ||
23
+ (entry.hooks || []).some(hook => /(?:rule-of-3(?:-tracker)?|reset-circuit-breaker)\.js/.test(hook.command)));
6
24
 
7
- const hooksConfig = JSON.parse(fs.readFileSync(path.join(helper.root, 'hooks', 'hooks.json'), 'utf8'));
8
- const preRuleHook = (hooksConfig.hooks.PreToolUse || []).find(entry => entry.id === 'harness:pre:rule-of-3');
9
- const successTrackerHook = (hooksConfig.hooks.PostToolUse || []).find(entry => entry.id === 'harness:post:rule-of-3-tracker');
10
- const failureTrackerHook = (hooksConfig.hooks.PostToolUseFailure || []).find(entry => entry.id === 'harness:post-failure:rule-of-3-tracker');
11
- const matcherHas = (entry, tool) => Boolean(entry && String(entry.matcher || '').split('|').includes(tool));
12
- helper.check(
13
- '2a-wiring. PostToolUseFailure invokes the Rule-of-3 tracker',
14
- matcherHas(failureTrackerHook, 'Bash') && matcherHas(failureTrackerHook, 'PowerShell') &&
15
- matcherHas(failureTrackerHook, 'apply_patch') &&
16
- failureTrackerHook.hooks?.some(hook => hook.command.includes('rule-of-3-tracker.js')),
17
- JSON.stringify(failureTrackerHook)
18
- );
19
25
  helper.check(
20
- '2a-wiring. apply_patch is covered before and after execution',
21
- matcherHas(preRuleHook, 'apply_patch') && matcherHas(successTrackerHook, 'apply_patch') && matcherHas(failureTrackerHook, 'apply_patch'),
22
- JSON.stringify({ preRuleHook, successTrackerHook, failureTrackerHook })
26
+ '2a-retirement.wiring. Claude registers no retired blocker, tracker, or reset entry',
27
+ registeredRetired.length === 0,
28
+ JSON.stringify(registeredRetired)
23
29
  );
30
+ for (const relative of retiredFiles) {
31
+ helper.check(`2a-retirement.file. ${relative} is retired`, !fs.existsSync(path.join(helper.root, relative)));
32
+ }
33
+
34
+ function runRegisteredRuleHook(event, payload) {
35
+ const entry = entries.find(candidate => candidate.event === event && retiredIds.has(candidate.id));
36
+ if (!entry) return [];
37
+ return (entry.hooks || []).map(hook => {
38
+ const relative = hook.command.match(/\$\{CLAUDE_PLUGIN_ROOT\}\/([^" ]+)/)?.[1];
39
+ if (!relative) return { status: 1, stderr: `unrecognized hook command: ${hook.command}` };
40
+ return spawnSync(process.execPath, [path.join(helper.root, relative)], {
41
+ cwd: helper.root,
42
+ input: JSON.stringify({ cwd: helper.root, session_id: helper.SESSION_ID, ...payload }),
43
+ encoding: 'utf8',
44
+ env: process.env,
45
+ });
46
+ });
47
+ }
48
+
49
+ function permittedToolCall() {
50
+ return spawnSync(process.execPath, ['-e', 'process.stdout.write("permitted")'], {
51
+ cwd: helper.root,
52
+ encoding: 'utf8',
53
+ });
54
+ }
55
+
56
+ const stateFile = path.join(helper.sessionDir, 'rule-of-3-state.json');
57
+ const reportFile = path.join(helper.sessionDir, 'zoom-out-report.md');
58
+ const oldState = { count: 3, lastHash: 'legacy-trip', zoomOutResolved: false, lastFailureAt: 123, zoomOutCycles: 0 };
59
+ const note = 'agent-authored recovery note\n';
24
60
 
25
- const failure = {
26
- hook_event_name: 'PostToolUseFailure',
27
- tool_name: 'Bash',
28
- tool_input: { command: 'node -e "process.exit(1)"' },
29
- error: 'Exit code 1\ncommand failed',
30
- session_id: helper.SESSION_ID,
31
- };
32
- for (let i = 0; i < 3; i++) helper.runHook('rule-of-3-tracker.js', failure);
33
- let state = helper.readState('rule-of-3-state.json');
61
+ helper.writeState('rule-of-3-state.json', oldState);
62
+ fs.writeFileSync(reportFile, note, 'utf8');
63
+ helper.writeState('subagent-scope-state.json', { old: true });
64
+ const bootstrap = spawnSync(process.execPath, [path.join(helper.root, 'harness-everything/scripts/bootstrap.js')], {
65
+ cwd: helper.root,
66
+ input: JSON.stringify({ hook_event_name: 'SessionStart', cwd: helper.root, session_id: helper.SESSION_ID }),
67
+ encoding: 'utf8',
68
+ env: process.env,
69
+ });
70
+ helper.check('2a-retirement.bootstrap. startup completes', bootstrap.status === 0, bootstrap.stderr);
34
71
  helper.check(
35
- '2a-three. exactly three matching failures arm zoom-out',
36
- state.count === 3 && state.lastHash && state.zoomOutResolved === false && state.threshold === undefined,
37
- JSON.stringify(state)
72
+ '2a-retirement.bootstrap. legacy breaker state and optional agent note remain intact',
73
+ fs.existsSync(stateFile) && fs.readFileSync(stateFile, 'utf8') === JSON.stringify(oldState, null, 2) &&
74
+ fs.existsSync(reportFile) && fs.readFileSync(reportFile, 'utf8') === note
38
75
  );
39
-
40
- const trip = helper.runHook('rule-of-3.js', { hook_event_name: 'PreToolUse', tool_name: 'Bash', session_id: helper.SESSION_ID });
41
76
  helper.check(
42
- '2a-trip. third matching failure blocks mutation for reflection',
43
- trip.code === 2 && trip.stderr.includes('RULE OF 3 CIRCUIT BREAKER TRIGGERED'),
44
- trip.stderr
77
+ '2a-retirement.bootstrap. unrelated subagent scope baseline still resets',
78
+ !fs.existsSync(path.join(helper.sessionDir, 'subagent-scope-state.json'))
45
79
  );
46
-
47
- helper.writeState('rule-of-3-state.json', { count: 3, lastHash: 'mech-test', zoomOutResolved: false, lastFailureAt: 0, zoomOutCycles: 0 });
48
- fs.writeFileSync(path.join(helper.sessionDir, 'zoom-out-report.md'),
49
- '## Goal\nx\n## Failed Attempts\nx\n## Verified Facts\nx\n## Diagnosis\nx\n## Decision\nRESUME: new approach\n', 'utf8');
50
- const release = helper.runHook('rule-of-3.js', { session_id: helper.SESSION_ID });
51
- state = helper.readState('rule-of-3-state.json');
80
+ helper.writeState('subagent-scope-state.json', { old: true });
81
+ const startup = helper.runHook('openai-session-start.js', {
82
+ hook_event_name: 'SessionStart', cwd: helper.root, session_id: helper.SESSION_ID,
83
+ });
84
+ helper.check('2a-retirement.startup. Codex startup completes', startup.code === 0, startup.stderr);
52
85
  helper.check(
53
- '2a-release. valid reflection releases breaker and resets count',
54
- release.code === 0 && state.count === 0 && state.zoomOutResolved === true && state.zoomOutCycles === 1,
55
- JSON.stringify(state)
86
+ '2a-retirement.startup. legacy breaker state and optional agent note remain intact',
87
+ fs.existsSync(stateFile) && fs.readFileSync(stateFile, 'utf8') === JSON.stringify(oldState, null, 2) &&
88
+ fs.existsSync(reportFile) && fs.readFileSync(reportFile, 'utf8') === note
56
89
  );
57
-
58
- helper.writeState('rule-of-3-state.json', { count: 3, lastHash: 'mech-test', zoomOutResolved: false, lastFailureAt: Date.now() + 60000, zoomOutCycles: 1 });
59
- const retrip = helper.runHook('rule-of-3.js', { session_id: helper.SESSION_ID });
60
90
  helper.check(
61
- '2a-repeat. later three-failure cycle requests another zoom-out, not permanent hard lock',
62
- retrip.code === 2 && retrip.stderr.includes('RULE OF 3 CIRCUIT BREAKER TRIGGERED') && !/hard lock|repeat trip/i.test(retrip.stderr),
63
- retrip.stderr
91
+ '2a-retirement.startup. unrelated subagent scope baseline still resets',
92
+ !fs.existsSync(path.join(helper.sessionDir, 'subagent-scope-state.json'))
64
93
  );
65
94
 
66
- helper.writeState('rule-of-3-state.json', { count: 0, lastHash: null, zoomOutResolved: false, zoomOutCycles: 0, lastFailureAt: 0 });
67
- for (let i = 0; i < 2; i++) helper.runHook('rule-of-3-tracker.js', {
68
- hook_event_name: 'PostToolUseFailure', tool_name: 'Bash',
69
- tool_input: { command: 'cat protected.txt' }, error: 'EACCES: permission denied, open protected.txt',
70
- session_id: helper.SESSION_ID,
71
- });
72
- state = helper.readState('rule-of-3-state.json');
73
- helper.check('2a-category. permission failures still use the same threshold of three', state.count === 2 && state.category === 'permission' && state.threshold === undefined, JSON.stringify(state));
74
- const beforeThird = helper.runHook('rule-of-3.js', { session_id: helper.SESSION_ID });
75
- helper.check('2a-category-two. two permission failures do not trip early', beforeThird.code === 0, beforeThird.stderr);
76
- helper.runHook('rule-of-3-tracker.js', {
77
- hook_event_name: 'PostToolUseFailure', tool_name: 'Bash',
78
- tool_input: { command: 'cat protected.txt' }, error: 'EACCES: permission denied, open protected.txt',
79
- session_id: helper.SESSION_ID,
80
- });
81
- const third = helper.runHook('rule-of-3.js', { session_id: helper.SESSION_ID });
82
- helper.check('2a-category-three. third permission failure trips normally', third.code === 2, third.stderr);
95
+ for (const legacyState of [false, true]) {
96
+ if (fs.existsSync(stateFile)) fs.unlinkSync(stateFile);
97
+ if (legacyState) helper.writeState('rule-of-3-state.json', oldState);
83
98
 
84
- helper.writeState('rule-of-3-state.json', { count: 0, lastHash: null, lastOperationHash: null, zoomOutResolved: false, zoomOutCycles: 0, lastFailureAt: 0 });
85
- const repeatedFailure = {
86
- hook_event_name: 'PostToolUseFailure',
87
- tool_name: 'Bash',
88
- tool_input: { command: 'node flaky.js' },
89
- error: 'Error: flaky failure',
90
- session_id: helper.SESSION_ID,
91
- };
92
- helper.runHook('rule-of-3-tracker.js', repeatedFailure);
93
- helper.runHook('rule-of-3-tracker.js', repeatedFailure);
94
- helper.runHook('rule-of-3-tracker.js', {
95
- hook_event_name: 'PostToolUse',
96
- tool_name: 'Bash',
97
- tool_input: { command: 'git status --short' },
98
- tool_response: { exitCode: 0, stdout: '' },
99
- session_id: helper.SESSION_ID,
100
- });
101
- state = helper.readState('rule-of-3-state.json');
102
- helper.check('2a-interleaved. unrelated success preserves the matching failure count', state.count === 2 && state.lastHash, JSON.stringify(state));
103
- helper.runHook('rule-of-3-tracker.js', repeatedFailure);
104
- state = helper.readState('rule-of-3-state.json');
105
- helper.check('2a-interleaved-three. third matching failure still arms zoom-out after unrelated success', state.count === 3 && state.zoomOutResolved === false, JSON.stringify(state));
106
- helper.runHook('rule-of-3-tracker.js', {
107
- hook_event_name: 'PostToolUse',
108
- tool_name: 'Bash',
109
- tool_input: { command: 'node flaky.js' },
110
- tool_response: { exitCode: 0, stdout: 'recovered' },
111
- session_id: helper.SESSION_ID,
99
+ const pre = runRegisteredRuleHook('PreToolUse', {
100
+ hook_event_name: 'PreToolUse', tool_name: 'Bash', tool_input: { command: 'node -e process.exit(0)' },
101
+ });
102
+ const call = pre.every(result => result.status === 0) ? permittedToolCall() : null;
103
+ const post = call && call.status === 0 ? runRegisteredRuleHook('PostToolUse', {
104
+ hook_event_name: 'PostToolUse', tool_name: 'Bash', tool_input: { command: 'node -e process.exit(0)' },
105
+ tool_response: { exitCode: 0, stdout: 'permitted' },
106
+ }) : [];
107
+
108
+ helper.check(
109
+ `2a-retirement.tool.${legacyState ? 'legacy' : 'fresh'}. otherwise-permitted tool call runs`,
110
+ pre.every(result => result.status === 0) && call?.status === 0 && post.every(result => result.status === 0),
111
+ JSON.stringify({ pre: pre.map(result => result.status), call: call?.status, post: post.map(result => result.status) })
112
+ );
113
+ helper.check(
114
+ `2a-retirement.tool.${legacyState ? 'legacy' : 'fresh'}. no breaker state is created`,
115
+ legacyState ? fs.readFileSync(stateFile, 'utf8') === JSON.stringify(oldState, null, 2) : !fs.existsSync(stateFile)
116
+ );
117
+ }
118
+
119
+ if (fs.existsSync(stateFile)) fs.unlinkSync(stateFile);
120
+ const failure = runRegisteredRuleHook('PostToolUseFailure', {
121
+ hook_event_name: 'PostToolUseFailure', tool_name: 'Bash',
122
+ tool_input: { command: 'node -e process.exit(1)' }, error: 'fixture failure',
112
123
  });
113
- state = helper.readState('rule-of-3-state.json');
114
- helper.check('2a-resolved. same-operation success clears the resolved signature', state.count === 0 && state.lastHash === null && state.lastOperationHash === null, JSON.stringify(state));
124
+ helper.check(
125
+ '2a-retirement.failure. failed tool result creates no breaker state',
126
+ failure.every(result => result.status === 0) && !fs.existsSync(stateFile),
127
+ JSON.stringify(failure.map(result => ({ status: result.status, stderr: result.stderr })))
128
+ );
115
129
 
116
130
  helper.finish();
@@ -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(