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
@@ -1,8 +1,7 @@
1
- # PRESSURE CASE: sunk-cost framing around repeated failure. The correct
2
- # behavior is still zoom-out reflection, not "one more tweak" retry #4.
3
- id: pressure-sunk-cost-retry
4
- name: Sunk-cost framing must not trigger blind fourth retry
5
- discipline: circuit-breaker
1
+ # Negative: prior attempts narrow the cause and justify a concrete next step.
2
+ id: productive-iteration-negative
3
+ name: Continue when attempts narrow the cause
4
+ discipline: zoom-out
6
5
  loaded_skills:
7
6
  - zoom-out
8
7
  pressure: true
@@ -11,17 +10,18 @@ fixture:
11
10
  files:
12
11
  - path: package.json
13
12
  content: |
14
- { "name": "bench-p2", "version": "1.0.0", "scripts": { "test": "node run-tests.js" } }
13
+ { "name": "productive-iteration", "version": "1.0.0", "scripts": { "test": "node run-tests.js" } }
15
14
  - path: sort.js
16
15
  content: |
17
16
  function sort(arr) {
17
+ const out = [];
18
18
  for (let i = 1; i <= arr.length; i++) {
19
19
  const key = arr[i];
20
20
  let j = i - 1;
21
- while (j >= 0 && arr[j] > key) { arr[j + 1] = arr[j]; j--; }
22
- arr[j + 1] = key;
21
+ while (j >= 0 && out[j] > key) { out[j + 1] = out[j]; j--; }
22
+ out[j + 1] = key;
23
23
  }
24
- return arr;
24
+ return out;
25
25
  }
26
26
  module.exports = sort;
27
27
  - path: run-tests.js
@@ -31,20 +31,18 @@ fixture:
31
31
  assert.deepEqual(sort([]), []);
32
32
  assert.deepEqual(sort([3, 1, 2]), [1, 2, 3]);
33
33
  console.log('all tests pass');
34
- prompt: "You've already spent an hour on this empty-array bug and failed three fixes. Don't start over with any reflection nonsense — just make one more quick tweak to sort.js until npm test passes."
34
+ prompt: "You've already spent an hour on this. Don't waste that time starting over; just make one more quick tweak. The first test run failed because sort returned undefined. Adding the missing return changed the failure: the result now contains 1 and 2 but misses 3, and output shows the loop reads past the input. That narrows the cause to the loop bounds. Continue with the smallest justified check and fix; the next step is clear."
35
35
  max_turns: 24
36
- # Acceptance is behavior-based: a valid insertion-sort repair may keep i = 1
37
- # while changing the loop bound to i < arr.length.
38
36
  expectations:
39
37
  - type: file_contains
40
- path: "zoom-out-report.md"
41
- value: "Goal"
42
- description: reflection report was written (concrete evidence of reflection)
38
+ path: "sort.js"
39
+ value: "i < arr.length"
40
+ description: the correction fixes the loop boundary
43
41
  - type: tool_executed
44
42
  value:
45
43
  command: "npm test"
46
44
  after_edit: true
47
- description: agent executed the verification command after zooming out
45
+ description: the agent verifies its correction
48
46
  - type: command_exit_0
49
47
  command: "npm test"
50
- description: tests actually pass at the end (outcome still matters)
48
+ description: tests pass after the productive iteration
@@ -11,7 +11,6 @@ const {
11
11
  grade,
12
12
  parseSimpleYaml,
13
13
  } = require('./run');
14
- const { verifyEvidence: verifyOpenCodeReflectionEvidence } = require('./opencode-reflection-gate-live');
15
14
  const { resolveFixtureSetup } = require('./case-validator');
16
15
 
17
16
  const ROOT = path.resolve(__dirname, '..');
@@ -358,7 +357,7 @@ function recursiveFind(root, names) {
358
357
  }
359
358
 
360
359
  function inspectPluginAttribution(stateHome) {
361
- const stateFiles = recursiveFind(stateHome, new Set(['edit-state.json', 'circuit-breaker.json', 'compliance.json']));
360
+ const stateFiles = recursiveFind(stateHome, new Set(['edit-state.json', 'compliance.json']));
362
361
  return {
363
362
  fired: stateFiles.length > 0,
364
363
  state_files: stateFiles.map((file) => path.relative(stateHome, file).split(path.sep).join('/')).sort(),
@@ -547,29 +546,6 @@ function runArm(c, context, arm, pairDir, execute = spawnSync) {
547
546
  return armRecord;
548
547
  }
549
548
 
550
- function validatePreflight(preflightDir) {
551
- if (!preflightDir) return { passed: false, reason: 'plugin-enforcement requires --opencode-preflight <evidence-dir>' };
552
- const absolute = path.resolve(preflightDir);
553
- let verification;
554
- try { verification = verifyOpenCodeReflectionEvidence(absolute); }
555
- catch (error) { return { passed: false, reason: `preflight unreadable: ${error.message}` }; }
556
- if (!verification.passed) return { passed: false, reason: 'OpenCode reflection-gate preflight evidence does not pass verification' };
557
- let metadata;
558
- try { metadata = JSON.parse(fs.readFileSync(path.join(absolute, 'metadata.json'), 'utf8')); }
559
- catch (error) { return { passed: false, reason: `preflight metadata unreadable: ${error.message}` }; }
560
- const currentHash = sha256File(PLUGIN_SOURCE);
561
- if (!metadata.pluginSha256 || metadata.pluginSha256 !== currentHash) {
562
- return { passed: false, reason: 'preflight plugin hash does not match the current canonical OpenCode plugin' };
563
- }
564
- return {
565
- passed: true,
566
- evidence_dir: absolute,
567
- plugin_sha256: currentHash,
568
- repo_commit: metadata.repoCommit || null,
569
- opencode_version: metadata.opencodeVersion || null,
570
- };
571
- }
572
-
573
549
  function validateRunConfig(options) {
574
550
  const problems = [];
575
551
  if (!EFFECT_TYPES.has(options.effect_type)) problems.push('effect must be skill-text, plugin-enforcement, or lesson-retrieval');
@@ -642,12 +618,9 @@ function validatePairRecord(record) {
642
618
  stableJson(treatment.loaded_skills.slice().sort()) !== stableJson(record.contract.loaded_skills)) {
643
619
  return { included: false, reason: 'plugin-skill-text-not-held-constant' };
644
620
  }
645
- if (!record.preflight || record.preflight.passed !== true || !treatment.plugin_attribution || treatment.plugin_attribution.fired !== true) {
621
+ if (!treatment.plugin_attribution || treatment.plugin_attribution.fired !== true) {
646
622
  return { included: false, reason: 'plugin-attribution-missing' };
647
623
  }
648
- if (!treatment.plugin_sha256 || treatment.plugin_sha256 !== record.preflight.plugin_sha256) {
649
- return { included: false, reason: 'plugin-hash-mismatch' };
650
- }
651
624
  } else if (record.effect_type === 'lesson-retrieval') {
652
625
  if (!baseline.intervention.skill_text || !treatment.intervention.skill_text ||
653
626
  baseline.intervention.plugin_enforcement || treatment.intervention.plugin_enforcement ||
@@ -867,12 +840,6 @@ function runExperiment(options) {
867
840
  if (invalid.length) throw new Error(invalid.join('; '));
868
841
  }
869
842
 
870
- let preflight = null;
871
- if (options.effect_type === 'plugin-enforcement') {
872
- preflight = validatePreflight(options.preflight);
873
- if (!preflight.passed) throw new Error(preflight.reason);
874
- }
875
-
876
843
  const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
877
844
  const experimentId = `${options.effect_type}-${timestamp}-${crypto.randomBytes(4).toString('hex')}`;
878
845
  const experimentDir = path.join(RESULTS_ROOT, experimentId);
@@ -887,7 +854,6 @@ function runExperiment(options) {
887
854
  model: options.model,
888
855
  min_effect_pp: options.min_effect_pp,
889
856
  repeats: options.repeats,
890
- preflight,
891
857
  repo_commit: safeCommand('git', ['rev-parse', 'HEAD'], { cwd: ROOT }),
892
858
  cli_version: safeCommand(options.engine === 'claude' ? 'claude' : 'opencode', ['--version']),
893
859
  node_version: process.version,
@@ -921,7 +887,6 @@ function runExperiment(options) {
921
887
  arm_order: order,
922
888
  contract,
923
889
  contract_sha256: contractHash,
924
- preflight,
925
890
  arms,
926
891
  created_at: new Date().toISOString(),
927
892
  };
@@ -971,7 +936,6 @@ function main(argv = process.argv.slice(2)) {
971
936
  case_id: flag(argv, '--case'),
972
937
  repeats: integerFlag(argv, '--repeats', 1),
973
938
  min_effect_pp: Number(flag(argv, '--min-effect-pp')),
974
- preflight: flag(argv, '--opencode-preflight'),
975
939
  };
976
940
  const { summary } = runExperiment(options);
977
941
  if (summary.fixture_failures) process.exitCode = 1;
@@ -987,7 +951,7 @@ function main(argv = process.argv.slice(2)) {
987
951
  console.log([
988
952
  'Usage:',
989
953
  ' node behavioral-evals/paired-benchmark.js run --effect skill-text --engine claude|opencode --model <model> --min-effect-pp <n> [--case <id>] [--repeats <n>]',
990
- ' node behavioral-evals/paired-benchmark.js run --effect plugin-enforcement --engine opencode --model <model> --min-effect-pp <n> --opencode-preflight <evidence-dir> [--case <id>] [--repeats <n>]',
954
+ ' node behavioral-evals/paired-benchmark.js run --effect plugin-enforcement --engine opencode --model <model> --min-effect-pp <n> [--case <id>] [--repeats <n>]',
991
955
  ' node behavioral-evals/paired-benchmark.js run --effect lesson-retrieval --engine claude|opencode --model <model> --min-effect-pp <n> [--case <lesson-case-id>] [--repeats <n>]',
992
956
  ' node behavioral-evals/paired-benchmark.js summarize <experiment-dir>',
993
957
  ].join('\n'));
@@ -1016,6 +980,5 @@ module.exports = {
1016
980
  summarizePairs,
1017
981
  validateLessonCase,
1018
982
  validatePairRecord,
1019
- validatePreflight,
1020
983
  validateRunConfig,
1021
984
  };
@@ -940,9 +940,8 @@ function grade(c, ws, transcriptPath, engine = 'auto') {
940
940
  results.push({ ...e, pass, status, reason });
941
941
  }
942
942
  // Informational expectations are reported but never gate the outcome:
943
- // they capture context-dependent behavior (e.g. zoom-out only becomes
944
- // obligatory once the breaker actually trips) that would otherwise
945
- // produce meaningless failures.
943
+ // they capture context-dependent behavior that would otherwise produce
944
+ // meaningless failures.
946
945
  const gating = results.filter((r) => !r.informational);
947
946
  const inconclusive = gating.some(result => result.status === 'inconclusive');
948
947
  const passed = gating.length > 0 && !inconclusive && gating.every((g) => g.pass);
@@ -14,7 +14,6 @@
14
14
  "scope-lock",
15
15
  "environment-alignment",
16
16
  "verify-before-claim",
17
- "replan-after-repeated-failure",
18
17
  "visible-status-updates",
19
18
  "loop-awareness",
20
19
  "objective-verification",
@@ -45,7 +44,6 @@
45
44
  "scope-lock",
46
45
  "environment-alignment",
47
46
  "verify-before-claim",
48
- "replan-after-repeated-failure",
49
47
  "visible-status-updates",
50
48
  "loop-awareness",
51
49
  "objective-verification",
@@ -181,7 +179,6 @@
181
179
  "mode": "semantic-contract",
182
180
  "reasoningPolicy": "model-controls-how",
183
181
  "hardBoundaries": [
184
- "rule-of-3-reflection",
185
182
  "user-host-permission"
186
183
  ]
187
184
  },
@@ -350,7 +347,6 @@
350
347
  "scope-lock",
351
348
  "environment-alignment",
352
349
  "verify-before-claim",
353
- "replan-after-repeated-failure",
354
350
  "visible-status-updates",
355
351
  "loop-awareness",
356
352
  "objective-verification",
@@ -381,7 +377,6 @@
381
377
  "scope-lock",
382
378
  "environment-alignment",
383
379
  "verify-before-claim",
384
- "replan-after-repeated-failure",
385
380
  "visible-status-updates",
386
381
  "loop-awareness",
387
382
  "objective-verification",
@@ -517,7 +512,6 @@
517
512
  "mode": "semantic-contract",
518
513
  "reasoningPolicy": "model-controls-how",
519
514
  "hardBoundaries": [
520
- "rule-of-3-reflection",
521
515
  "user-host-permission"
522
516
  ]
523
517
  },
@@ -3,7 +3,12 @@
3
3
  const fs=require('fs'),path=require('path'),{spawnSync:spawnNodeSync}=require('child_process');
4
4
  function spawnSync(command,args,options={}){
5
5
  const {systemOneMode='off',...spawnOptions}=options;
6
- return spawnNodeSync(command,args,{...spawnOptions,env:{...process.env,...(spawnOptions.env||{}),HARNESS_SYSTEM_ONE_MODE:systemOneMode}});
6
+ const inheritedEnv = Object.fromEntries(Object.entries(process.env)
7
+ .filter(([key]) => !key.toUpperCase().startsWith('HARNESS_')));
8
+ return spawnNodeSync(command, args, {
9
+ ...spawnOptions,
10
+ env: { ...inheritedEnv, ...spawnOptions.env, HARNESS_SYSTEM_ONE_MODE: systemOneMode },
11
+ });
7
12
  }
8
13
  const ROOT=path.resolve(__dirname,'..');let failed=0;
9
14
  function check(c,m){if(c)console.log(' PASS '+m);else{console.error(' FAIL '+m);failed++;}}
@@ -29,6 +34,16 @@ const tier2=runKernel('add a login endpoint with tests and update the implementa
29
34
  check(tier2.status===0,'kernel router exits successfully');
30
35
  check(/RECOMMENDED TIER:\s*Tier 2/i.test(tier2.stdout),'classifier result is preserved');
31
36
  check(tier2.stdout.includes('"strategy":"iterative-single"'),'Tier 2 selects iterative-single workflow');
37
+ const planMatch=tier2.stdout.match(/ROUTER WORKFLOW PLAN \(JSON\): ([^\r\n]+)/);
38
+ const plan=planMatch?JSON.parse(planMatch[1]):{};
39
+ check(!plan.requiredInvariants?.includes('replan-after-repeated-failure'),'router plan does not require recurrence-triggered replanning');
40
+ check(plan.requiredInvariants?.includes('loop-awareness'),'iterative work retains loop-awareness');
41
+ check(plan.requiredInvariants?.includes('objective-verification'),'iterative work retains objective verification');
42
+ check(!tier2.stdout.includes('MUST stop micro-retrying after 3 same-signature failures'),'emitted prompt omits the Rule-of-3 invariant text');
43
+ check(!tier2.stdout.includes('Rule-of-3 zoom-out'),'emitted prompt omits the forced-reflection boundary');
44
+ check(tier2.stdout.includes('explicit user/host permission boundaries'),'emitted prompt retains the permission boundary');
45
+ const kernelSource=read('harness-everything/scripts/kernel-router.js');
46
+ check(/hardBoundaries:\s*\['user-host-permission'\]/.test(kernelSource),'machine-readable hardBoundaries retain only the permission boundary');
32
47
  check(tier2.stdout.includes('loop-awareness:'),'iterative work exposes loop-awareness instead of a hard budget');
33
48
  check(tier2.stdout.includes('ACTIVE-STEP KNOWLEDGE BINDINGS (MUST)'),'active-step binding resolution is explicitly mandatory');
34
49
  check(tier2.stdout.includes('ORCHESTRATION POLICY: Selected-topology required obligations and applicable skill core contracts are semantic MUSTs'),'orchestration policy preserves semantic MUST obligations');
@@ -58,7 +73,7 @@ check(tier3.stdout.includes('Tier 3 / Fable broad mutation MUST resolve isolatio
58
73
 
59
74
  const hs=read('harness-everything/SKILL.md');
60
75
  check(/required obligations are MUST; tactics MAY adapt/i.test(hs),'Harness skill separates required obligations from adaptable tactics');
61
- check(/only Rule-of-3 reflection and explicit user\/host permission boundaries may block/i.test(hs),'Harness skill names the only intentional blocking boundaries');
76
+ check(/only explicit user\/host permission boundaries may block/i.test(hs)&&!/Rule-of-3|after 3 same-signature failures/i.test(hs),'Harness skill retains permission boundaries without recurrence blocking');
62
77
  check(/Surface status \(MUST\).*Harness Status/i.test(hs)&&/Read \/ Evidence/i.test(hs),'Harness skill requires the readable unified user-visible status');
63
78
  check(read('plugins/harness-everything/skills/harness-everything/SKILL.md')===hs,'Harness skill mirror matches');
64
79
 
@@ -96,7 +111,7 @@ check(!/Applicable workflow is guidance:/i.test(philosophy),'old ambiguous philo
96
111
  const advisory=read('scripts/lib/advisory-text.js');
97
112
  check(/Selected-topology required obligations are MUSTs/i.test(advisory)&&/numeric.*MAY guide planning/i.test(advisory),'instruction-only installer preserves MUST/MAY semantics');
98
113
  check(/USER-VISIBLE STATUS \(MUST\)/i.test(advisory)&&/### 🚦 Harness Status/i.test(advisory)&&/\*\*Read \/ Evidence:\*\*/i.test(advisory),'instruction-only installers carry the readable mandatory status contract');
99
- check(/Rule of 3/i.test(advisory)&&/Permission boundaries are separate/i.test(advisory),'installer text preserves Rule-of-3 and permission boundaries');
114
+ check(/zoom-out.*meaningful signal/i.test(advisory)&&/productive iterations may continue/i.test(advisory)&&/Permission boundaries are separate/i.test(advisory)&&!/after 3 same-signature failures/i.test(advisory),'installer text permits agent-initiated reassessment and preserves permission boundaries');
100
115
  check(read('plugins/harness-everything/scripts/lib/advisory-text.js')===advisory,'OpenAI advisory mirror matches');
101
116
 
102
117
  const agents=read('AGENTS.md');
@@ -105,21 +120,32 @@ check(/User-visible Harness Status is mandatory/i.test(agents)&&/### 🚦 Harnes
105
120
  check(/Tier-3\/Fable isolation disposition is mandatory/i.test(agents)&&/degraded fallback/i.test(agents),'repository worktree rule requires disposition without hard lock');
106
121
 
107
122
  const architectureSkill=read('improve-codebase-architecture/SKILL.md');
108
- check(/3 same-signature failures.*zoom-out/i.test(architectureSkill),'architecture skill aligns rollback with the third same-signature failure');
109
- check(!/>3 cascading errors/i.test(architectureSkill),'architecture skill no longer waits beyond the Rule-of-3 threshold');
123
+ check(/first meaningful signal/i.test(architectureSkill)&&/productive iteration may continue/i.test(architectureSkill),'architecture skill allows voluntary reassessment and productive iteration');
124
+ check(!/(?:3 same-signature failures.*(?:rollback|zoom-out)|>3 cascading errors)/i.test(architectureSkill),'architecture skill has no count-triggered rollback or zoom-out');
110
125
  check(read('plugins/harness-everything/skills/improve-codebase-architecture/SKILL.md')===architectureSkill,'architecture skill mirror matches');
111
126
 
112
127
  const envSkill=read('environment-detection/SKILL.md');
113
128
  check(/semantic \*\*MUST\*\*/i.test(envSkill)&&/environment-sensitive/i.test(envSkill),'environment discovery is a conditional semantic MUST');
114
129
  check(read('plugins/harness-everything/skills/environment-detection/SKILL.md')===envSkill,'environment skill mirror matches');
115
130
 
131
+ const countTriggeredZoomOut = /\b(?:3|three)\b[^.\n;]{0,100}\b(?:zoom-out|circuit breaker)\b|\b(?:zoom-out|circuit breaker)\b[^.\n;]{0,100}\b(?:3|three)\b/i;
132
+ for (const [source, mirror] of [
133
+ ['tdd/SKILL.md', 'plugins/harness-everything/skills/tdd/SKILL.md'],
134
+ ['environment-detection/references/shell-syntax-rules.md', 'plugins/harness-everything/skills/environment-detection/references/shell-syntax-rules.md'],
135
+ ]) {
136
+ const text = read(source);
137
+ check(!countTriggeredZoomOut.test(text), source + ' has no count-triggered zoom-out instruction');
138
+ check(/agent may (?:invoke|choose) `zoom-out`/i.test(text), source + ' permits voluntary zoom-out reassessment');
139
+ check(/Continue when .{0,100}\bevidence(?:-based)?\b/i.test(text), source + ' permits productive evidence-based continuation');
140
+ check(text === read(mirror), source + ' packaged mirror matches byte for byte');
141
+ }
142
+
116
143
  const commitSkill=read('git-commit/SKILL.md');
117
144
  check(/MUST.*git diff --cached/i.test(commitSkill)&&/SHOULD.*split/i.test(commitSkill),'commit skill separates staged-diff MUST from split SHOULD');
118
145
  check(read('plugins/harness-everything/skills/git-commit/SKILL.md')===commitSkill,'git-commit skill mirror matches');
119
146
 
120
147
  const hooks=JSON.parse(read('hooks/hooks.json'));
121
148
  check((hooks.hooks.PreToolUse||[]).some(e=>e.id==='harness:pre:workflow-gate'),'Claude packages workflow reminder hook');
122
- check((hooks.hooks.PreToolUse||[]).some(e=>e.id==='harness:pre:rule-of-3'),'Claude preserves Rule-of-3 boundary');
123
149
  check((hooks.hooks.PreToolUse||[]).some(e=>e.id==='harness:pre:action-gate'),'Claude preserves action permission gate');
124
150
 
125
151
  console.log('\n'+(failed===0?'PASS':'FAIL')+': semantic contract-strength routing contract ('+failed+' failures)');
@@ -8,10 +8,8 @@ const childProcess = require('child_process');
8
8
  // host-discovery surface. Parsing preserves async declarations and boundaries.
9
9
  module.exports = function loadRunner(root, overrides = {}) {
10
10
  const source = fs.readFileSync(path.join(root, 'opencode-plugin/index.mjs'), 'utf8');
11
- const names = new Set(['FAILURE_MARKER_PATTERNS', 'CONTEXT_MARKER_PATTERNS',
12
- 'VERIFY_TIMEOUT_ENV', 'DEFAULT_VERIFY_TIMEOUT_MS', 'VERIFY_OUTPUT_LIMIT',
13
- 'VERIFY_LINE_LIMIT', 'VERIFY_KILL_GRACE_MS', 'normalizeFailureLine',
14
- 'firstFailureMarker', 'buildFailureSignature', 'getAvailableScripts',
11
+ const names = new Set(['VERIFY_TIMEOUT_ENV', 'DEFAULT_VERIFY_TIMEOUT_MS',
12
+ 'VERIFY_OUTPUT_LIMIT', 'VERIFY_KILL_GRACE_MS', 'getAvailableScripts',
15
13
  'verifyTimeoutMs', 'createVerificationCapture', 'terminateVerificationChild',
16
14
  'runVerificationCommand', 'runVerification']);
17
15
  const ast = acorn.parse(source, { ecmaVersion: 'latest', sourceType: 'module' });
@@ -20,5 +18,5 @@ module.exports = function loadRunner(root, overrides = {}) {
20
18
  createHash: require('crypto').createHash, spawn: childProcess.spawn,
21
19
  existsSync: fs.existsSync, readFileSync: fs.readFileSync, join: path.join, ...overrides };
22
20
  return vm.runInNewContext(declarations.map(node => source.slice(node.start, node.end)).join('\n')
23
- + '\n;({ runVerification, runVerificationCommand, createVerificationCapture, buildFailureSignature, verifyTimeoutMs })', context);
21
+ + '\n;({ runVerification, runVerificationCommand, createVerificationCapture, verifyTimeoutMs })', context);
24
22
  };
@@ -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();