harness-everything 0.3.6 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (580) hide show
  1. package/.agents/plugins/marketplace.json +20 -0
  2. package/.claude-plugin/marketplace.json +1 -1
  3. package/.claude-plugin/plugin.json +8 -7
  4. package/.github/workflows/behavioral-evals.yml +3 -3
  5. package/.github/workflows/ci.yml +49 -28
  6. package/.github/workflows/release.yml +52 -27
  7. package/.nvmrc +1 -0
  8. package/.releaserc.json +113 -0
  9. package/AGENTS.md +44 -24
  10. package/BENCHMARK_SOP.md +38 -18
  11. package/CHANGELOG.md +196 -3
  12. package/CONTRIBUTING.md +37 -9
  13. package/Dockerfile +1 -1
  14. package/PRIVACY.md +25 -0
  15. package/README.md +126 -91
  16. package/RELEASING.md +93 -0
  17. package/SUPPORT.md +27 -0
  18. package/TERMS.md +21 -0
  19. package/VERIFICATION.md +192 -284
  20. package/behavioral-evals/README.md +21 -0
  21. package/behavioral-evals/case-validator.js +194 -0
  22. package/behavioral-evals/cases/baseline-environment-detection.yaml +21 -0
  23. package/behavioral-evals/cases/baseline-eval-harness.yaml +27 -0
  24. package/behavioral-evals/cases/baseline-fable-discipline.yaml +31 -0
  25. package/behavioral-evals/cases/baseline-find-skills-exposure.yaml +49 -0
  26. package/behavioral-evals/cases/baseline-find-skills.yaml +21 -0
  27. package/behavioral-evals/cases/baseline-git-commit.yaml +2 -2
  28. package/behavioral-evals/cases/baseline-install-cognitive-os.yaml +24 -0
  29. package/behavioral-evals/cases/baseline-multi-agent-workspace.yaml +28 -0
  30. package/behavioral-evals/cases/baseline-rewrite-commits.yaml +34 -0
  31. package/behavioral-evals/cases/baseline-self-evolve.yaml +31 -0
  32. package/behavioral-evals/cases/baseline-skill-creator.yaml +20 -0
  33. package/behavioral-evals/cases/baseline-skill-style.yaml +21 -0
  34. package/behavioral-evals/cases/baseline-to-spec.yaml +34 -0
  35. package/behavioral-evals/cases/baseline-to-tickets.yaml +24 -0
  36. package/behavioral-evals/cases/baseline-todo-driven-workflow.yaml +32 -0
  37. package/behavioral-evals/cases/baseline-using-git-worktrees.yaml +15 -0
  38. package/behavioral-evals/cases/breaker-zoom-out-after-3.yaml +2 -2
  39. package/behavioral-evals/cases/pressure-complexity-skip.yaml +2 -2
  40. package/behavioral-evals/cases/pressure-scope-bypass.yaml +7 -2
  41. package/behavioral-evals/cases/pressure-sunk-cost-retry.yaml +7 -4
  42. package/behavioral-evals/cases/scope-discipline.yaml +2 -1
  43. package/behavioral-evals/cases/verify-before-done.yaml +7 -5
  44. package/behavioral-evals/evidence/2026-09-07/baseline-debugging/case.yaml +31 -0
  45. package/behavioral-evals/evidence/2026-09-07/baseline-debugging/historical-case.yaml +31 -0
  46. package/behavioral-evals/evidence/2026-09-07/baseline-debugging/provenance.json +42 -0
  47. package/behavioral-evals/evidence/2026-09-07/baseline-debugging/result.sanitized.json +20 -0
  48. package/behavioral-evals/evidence/2026-09-07/baseline-performance/case.yaml +34 -0
  49. package/behavioral-evals/evidence/2026-09-07/baseline-performance/historical-case.yaml +34 -0
  50. package/behavioral-evals/evidence/2026-09-07/baseline-performance/provenance.json +42 -0
  51. package/behavioral-evals/evidence/2026-09-07/baseline-performance/result.sanitized.json +20 -0
  52. package/behavioral-evals/evidence/2026-09-07/baseline-security-review/case.yaml +28 -0
  53. package/behavioral-evals/evidence/2026-09-07/baseline-security-review/historical-case.yaml +28 -0
  54. package/behavioral-evals/evidence/2026-09-07/baseline-security-review/provenance.json +42 -0
  55. package/behavioral-evals/evidence/2026-09-07/baseline-security-review/result.sanitized.json +20 -0
  56. package/behavioral-evals/evidence/2026-09-07/baseline-simple-bugfix/case.yaml +33 -0
  57. package/behavioral-evals/evidence/2026-09-07/baseline-simple-bugfix/historical-case.yaml +33 -0
  58. package/behavioral-evals/evidence/2026-09-07/baseline-simple-bugfix/provenance.json +42 -0
  59. package/behavioral-evals/evidence/2026-09-07/baseline-simple-bugfix/result.sanitized.json +20 -0
  60. package/behavioral-evals/evidence/2026-09-07/grill-me-adversarial/case.yaml +28 -0
  61. package/behavioral-evals/evidence/2026-09-07/grill-me-adversarial/historical-case.yaml +18 -0
  62. package/behavioral-evals/evidence/2026-09-07/grill-me-adversarial/provenance.json +30 -0
  63. package/behavioral-evals/evidence/2026-09-07/live-run-blocker.md +16 -0
  64. package/behavioral-evals/evidence/2026-09-07/manifest.json +88 -0
  65. package/behavioral-evals/evidence/2026-09-07/pressure-scope-bypass/case.yaml +33 -0
  66. package/behavioral-evals/evidence/2026-09-07/pressure-scope-bypass/historical-case.yaml +28 -0
  67. package/behavioral-evals/evidence/2026-09-07/pressure-scope-bypass/provenance.json +30 -0
  68. package/behavioral-evals/evidence/2026-09-07/pressure-skip-docs/case.yaml +50 -0
  69. package/behavioral-evals/evidence/2026-09-07/pressure-skip-docs/historical-case.yaml +50 -0
  70. package/behavioral-evals/evidence/2026-09-07/pressure-skip-docs/provenance.json +42 -0
  71. package/behavioral-evals/evidence/2026-09-07/pressure-skip-docs/result.sanitized.json +20 -0
  72. package/behavioral-evals/evidence/2026-09-07/pressure-skip-error-handling/case.yaml +35 -0
  73. package/behavioral-evals/evidence/2026-09-07/pressure-skip-error-handling/historical-case.yaml +35 -0
  74. package/behavioral-evals/evidence/2026-09-07/pressure-skip-error-handling/provenance.json +42 -0
  75. package/behavioral-evals/evidence/2026-09-07/pressure-skip-error-handling/result.sanitized.json +20 -0
  76. package/behavioral-evals/evidence/2026-09-07/pressure-skip-verification/case.yaml +43 -0
  77. package/behavioral-evals/evidence/2026-09-07/pressure-skip-verification/historical-case.yaml +43 -0
  78. package/behavioral-evals/evidence/2026-09-07/pressure-skip-verification/provenance.json +42 -0
  79. package/behavioral-evals/evidence/2026-09-07/pressure-skip-verification/result.sanitized.json +24 -0
  80. package/behavioral-evals/evidence/2026-09-07/pressure-skip-verification--2026-08-23-pressure-skip-verification/case.yaml +43 -0
  81. package/behavioral-evals/evidence/2026-09-07/pressure-skip-verification--2026-08-23-pressure-skip-verification/historical-case.yaml +43 -0
  82. package/behavioral-evals/evidence/2026-09-07/pressure-skip-verification--2026-08-23-pressure-skip-verification/provenance.json +42 -0
  83. package/behavioral-evals/evidence/2026-09-07/pressure-skip-verification--2026-08-23-pressure-skip-verification/result.sanitized.json +20 -0
  84. package/behavioral-evals/evidence/2026-09-07/pressure-skip-verification--2026-08-27-pressure-skip-verification/case.yaml +43 -0
  85. package/behavioral-evals/evidence/2026-09-07/pressure-skip-verification--2026-08-27-pressure-skip-verification/historical-case.yaml +43 -0
  86. package/behavioral-evals/evidence/2026-09-07/pressure-skip-verification--2026-08-27-pressure-skip-verification/provenance.json +42 -0
  87. package/behavioral-evals/evidence/2026-09-07/pressure-skip-verification--2026-08-27-pressure-skip-verification/result.sanitized.json +24 -0
  88. package/behavioral-evals/evidence/2026-09-07/pressure-sunk-cost-retry/case.yaml +50 -0
  89. package/behavioral-evals/evidence/2026-09-07/pressure-sunk-cost-retry/historical-case.yaml +47 -0
  90. package/behavioral-evals/evidence/2026-09-07/pressure-sunk-cost-retry/provenance.json +42 -0
  91. package/behavioral-evals/evidence/2026-09-07/pressure-sunk-cost-retry/result.sanitized.json +24 -0
  92. package/behavioral-evals/evidence/2026-09-07/pressure-sunk-cost-retry--2026-08-23-pressure-sunk-cost-retry/case.yaml +50 -0
  93. package/behavioral-evals/evidence/2026-09-07/pressure-sunk-cost-retry--2026-08-23-pressure-sunk-cost-retry/historical-case.yaml +47 -0
  94. package/behavioral-evals/evidence/2026-09-07/pressure-sunk-cost-retry--2026-08-23-pressure-sunk-cost-retry/provenance.json +42 -0
  95. package/behavioral-evals/evidence/2026-09-07/pressure-sunk-cost-retry--2026-08-23-pressure-sunk-cost-retry/result.sanitized.json +20 -0
  96. package/behavioral-evals/evidence/2026-09-07/pressure-sunk-cost-retry--2026-08-27-pressure-sunk-cost-retry/case.yaml +50 -0
  97. package/behavioral-evals/evidence/2026-09-07/pressure-sunk-cost-retry--2026-08-27-pressure-sunk-cost-retry/historical-case.yaml +47 -0
  98. package/behavioral-evals/evidence/2026-09-07/pressure-sunk-cost-retry--2026-08-27-pressure-sunk-cost-retry/provenance.json +42 -0
  99. package/behavioral-evals/evidence/2026-09-07/pressure-sunk-cost-retry--2026-08-27-pressure-sunk-cost-retry/result.sanitized.json +24 -0
  100. package/behavioral-evals/evidence/2026-09-07/tdd-test-first/case.yaml +30 -0
  101. package/behavioral-evals/evidence/2026-09-07/tdd-test-first/historical-case.yaml +23 -0
  102. package/behavioral-evals/evidence/2026-09-07/tdd-test-first/provenance.json +30 -0
  103. package/behavioral-evals/evidence/2026-09-07/triage-matrix.json +426 -0
  104. package/behavioral-evals/evidence/2026-09-07/triage-matrix.md +24 -0
  105. package/behavioral-evals/evidence/2026-09-07/verify-before-claim-cites/case.yaml +19 -0
  106. package/behavioral-evals/evidence/2026-09-07/verify-before-claim-cites/historical-case.yaml +18 -0
  107. package/behavioral-evals/evidence/2026-09-07/verify-before-claim-cites/provenance.json +30 -0
  108. package/behavioral-evals/evidence/2026-09-07/verify-before-done/case.yaml +33 -0
  109. package/behavioral-evals/evidence/2026-09-07/verify-before-done/historical-case.yaml +31 -0
  110. package/behavioral-evals/evidence/2026-09-07/verify-before-done/provenance.json +42 -0
  111. package/behavioral-evals/evidence/2026-09-07/verify-before-done/result.sanitized.json +20 -0
  112. package/behavioral-evals/evidence/2026-09-07/verify-before-done--2026-08-23-verify-before-done/case.yaml +33 -0
  113. package/behavioral-evals/evidence/2026-09-07/verify-before-done--2026-08-23-verify-before-done/historical-case.yaml +31 -0
  114. package/behavioral-evals/evidence/2026-09-07/verify-before-done--2026-08-23-verify-before-done/provenance.json +42 -0
  115. package/behavioral-evals/evidence/2026-09-07/verify-before-done--2026-08-23-verify-before-done/result.sanitized.json +20 -0
  116. package/behavioral-evals/evidence/2026-09-07/verify-before-done--2026-08-27-verify-before-done/case.yaml +33 -0
  117. package/behavioral-evals/evidence/2026-09-07/verify-before-done--2026-08-27-verify-before-done/historical-case.yaml +31 -0
  118. package/behavioral-evals/evidence/2026-09-07/verify-before-done--2026-08-27-verify-before-done/provenance.json +42 -0
  119. package/behavioral-evals/evidence/2026-09-07/verify-before-done--2026-08-27-verify-before-done/result.sanitized.json +20 -0
  120. package/behavioral-evals/evidence/2026-09-09/pressure-scope-bypass/case.yaml +33 -0
  121. package/behavioral-evals/evidence/2026-09-09/pressure-scope-bypass/historical-case.yaml +33 -0
  122. package/behavioral-evals/evidence/2026-09-09/pressure-scope-bypass/provenance.json +42 -0
  123. package/behavioral-evals/evidence/2026-09-09/pressure-scope-bypass/result.sanitized.json +480 -0
  124. package/behavioral-evals/evidence/2026-09-09/pressure-scope-bypass/transcript.sanitized.jsonl +95 -0
  125. package/behavioral-evals/evidence-tool.js +443 -0
  126. package/behavioral-evals/fixtures/claude-denied.jsonl +3 -0
  127. package/behavioral-evals/fixtures/claude-legacy.json +1 -0
  128. package/behavioral-evals/fixtures/claude-oral-only.jsonl +2 -0
  129. package/behavioral-evals/fixtures/claude-success.jsonl +5 -0
  130. package/behavioral-evals/fixtures/claude-truncated.jsonl +3 -0
  131. package/behavioral-evals/fixtures/opencode-success.jsonl +6 -0
  132. package/behavioral-evals/results/2026-08-31-baseline-add-feature.json +20 -0
  133. package/behavioral-evals/results/2026-09-03-baseline-environment-detection-pair.json +133 -0
  134. package/behavioral-evals/results/2026-09-03-baseline-eval-harness-pair.json +141 -0
  135. package/behavioral-evals/results/2026-09-03-baseline-fable-discipline-pair.json +149 -0
  136. package/behavioral-evals/results/2026-09-03-baseline-find-skills-exposure-pair.json +141 -0
  137. package/behavioral-evals/results/2026-09-03-baseline-find-skills-pair.json +141 -0
  138. package/behavioral-evals/results/2026-09-03-baseline-install-cognitive-os-pair.json +133 -0
  139. package/behavioral-evals/results/2026-09-03-baseline-multi-agent-workspace-pair.json +141 -0
  140. package/behavioral-evals/results/2026-09-03-baseline-rewrite-commits-pair.json +95 -0
  141. package/behavioral-evals/results/2026-09-03-baseline-self-evolve-pair.json +141 -0
  142. package/behavioral-evals/results/2026-09-03-baseline-skill-creator-pair.json +141 -0
  143. package/behavioral-evals/results/2026-09-03-baseline-skill-style-pair.json +133 -0
  144. package/behavioral-evals/results/2026-09-03-baseline-to-spec-pair.json +133 -0
  145. package/behavioral-evals/results/2026-09-03-baseline-to-tickets-pair.json +141 -0
  146. package/behavioral-evals/results/2026-09-03-baseline-todo-driven-workflow-pair.json +141 -0
  147. package/behavioral-evals/results/2026-09-03-baseline-using-git-worktrees-pair.json +133 -0
  148. package/behavioral-evals/results/2026-09-03-summary-both.json +41 -0
  149. package/behavioral-evals/results/2026-09-04-baseline-find-skills-pair.json +141 -0
  150. package/behavioral-evals/results/2026-09-04-baseline-self-evolve-treatment.json +80 -0
  151. package/behavioral-evals/results/2026-09-04-baseline-skill-creator-treatment.json +80 -0
  152. package/behavioral-evals/results/2026-09-04-summary-both.json +41 -0
  153. package/behavioral-evals/run-with-plugin.js +15 -31
  154. package/behavioral-evals/run.js +446 -105
  155. package/behavioral-evals/transcript-parser.js +591 -0
  156. package/bin/cli.js +24 -12
  157. package/ci/ab-test-cases/grill-me-adversarial.yaml +14 -4
  158. package/ci/ab-test-cases/tdd-test-first.yaml +13 -6
  159. package/ci/ab-test-cases/verification-loop-gates.yaml +20 -7
  160. package/ci/ab-test-cases/verify-before-claim-cites.yaml +7 -6
  161. package/ci/ab-test-harness.js +113 -38
  162. package/ci/action-gate-platform-doc.test.js +31 -0
  163. package/ci/action-gate.test.js +260 -0
  164. package/ci/cases/case2.json +2 -2
  165. package/ci/consistency-check.js +51 -5
  166. package/ci/description-collision.js +15 -6
  167. package/ci/disclosure-check.js +225 -0
  168. package/ci/doc-capability-consistency.test.js +180 -0
  169. package/ci/fixtures/phase4/parallel-disjoint.stages.json +32 -0
  170. package/ci/fixtures/phase4/parallel-read-only.stages.json +32 -0
  171. package/ci/installer-roundtrip.test.js +159 -0
  172. package/ci/invariant-routing.test.js +74 -0
  173. package/ci/issue99-runtime.test.js +218 -0
  174. package/ci/mechanism-2aa-codex-action-gate-policy.test.js +117 -0
  175. package/ci/mechanism-2ab-openai-plugin-sync-integrity.test.js +80 -0
  176. package/ci/mechanism-2j-behavioral-runner.test.js +43 -1
  177. package/ci/mechanism-2k-reference-check.test.js +57 -2
  178. package/ci/mechanism-2l-multi-agent-workspace.test.js +202 -6
  179. package/ci/mechanism-2m-self-repo-guard.test.js +65 -0
  180. package/ci/mechanism-2n-opencode-plugin.test.js +461 -0
  181. package/ci/mechanism-2o-state-home-isolation.test.js +183 -0
  182. package/ci/mechanism-2p-installer-links.test.js +183 -0
  183. package/ci/mechanism-2q-installer-global-shared-store.test.js +132 -0
  184. package/ci/mechanism-2r-uninstall-flags.test.js +148 -0
  185. package/ci/mechanism-2s-tdd-quality.test.js +203 -0
  186. package/ci/mechanism-2t-disclosure.test.js +90 -0
  187. package/ci/mechanism-2t-evidence-triage.test.js +200 -0
  188. package/ci/mechanism-2t-issue-20.test.js +75 -0
  189. package/ci/mechanism-2t-platform-skill-targets.test.js +164 -0
  190. package/ci/mechanism-2t-transcript-parser.test.js +179 -0
  191. package/ci/mechanism-2t-workspace-identity.test.js +200 -0
  192. package/ci/mechanism-2u-issue-42-regressions.test.js +239 -0
  193. package/ci/mechanism-2u-issue-44.test.js +35 -0
  194. package/ci/mechanism-2v-verifier-boundaries.test.js +138 -0
  195. package/ci/mechanism-2w-platform-compatibility.test.js +148 -0
  196. package/ci/mechanism-2x-release-automation.test.js +157 -0
  197. package/ci/mechanism-2x-release-commit-message.test.js +66 -0
  198. package/ci/mechanism-2y-release-tooling-compat.test.js +47 -0
  199. package/ci/mechanism-2z-claude-plugin-manifest.test.js +29 -0
  200. package/ci/mutation-check.js +53 -0
  201. package/ci/mutation-loader.js +57 -0
  202. package/ci/negative-controls.js +76 -46
  203. package/ci/openai-plugin-package.test.js +182 -0
  204. package/ci/openai-plugin-runtime.test.js +175 -0
  205. package/ci/openai-plugin-submission.test.js +101 -0
  206. package/ci/phase4-ensemble-memory.test.js +307 -0
  207. package/ci/reference-check.js +73 -25
  208. package/ci/release-consistency-check.js +24 -1
  209. package/ci/repository-contract.test.js +17 -0
  210. package/ci/router-phase2-safety.test.js +81 -0
  211. package/ci/router-workflow-plan.test.js +264 -0
  212. package/ci/routing-check.js +6 -5
  213. package/ci/runner.js +6 -5
  214. package/ci/skill-routing-check.js +48 -11
  215. package/ci/test-behavioral-case-validation.js +62 -0
  216. package/ci/test-helper.js +10 -0
  217. package/ci/workflow-plan-consumers-edge.test.js +72 -0
  218. package/ci/workflow-plan-consumers.test.js +276 -0
  219. package/docs/architecture.md +137 -57
  220. package/docs/audit.md +22 -20
  221. package/docs/codex-action-gate.md +90 -0
  222. package/docs/issue-20-rollup.md +47 -0
  223. package/docs/mechanism-first-skill-mesh.md +22 -20
  224. package/docs/openai-plugin.md +118 -0
  225. package/docs/philosophy.md +28 -17
  226. package/docs/platform-capabilities.md +73 -0
  227. package/docs/platform-compatibility.json +270 -0
  228. package/docs/reflection.md +37 -22
  229. package/docs/release-evidence.md +27 -0
  230. package/docs/repository-contract.md +27 -0
  231. package/docs/routing.md +157 -44
  232. package/docs/security-audit.md +38 -0
  233. package/docs/troubleshooting.md +94 -51
  234. package/docs/verifier-boundaries.md +45 -0
  235. package/docs/workflows/fable-mode.md +77 -21
  236. package/docs/workflows/find-skills.md +40 -0
  237. package/docs/workflows/grill-with-docs.md +2 -2
  238. package/docs/workflows/multi-agent-workspace.md +22 -10
  239. package/docs/workflows/self-evolve.md +33 -0
  240. package/docs/workflows/tdd.md +36 -0
  241. package/docs/workflows/todo-driven-workflow.md +33 -0
  242. package/environment-detection/SKILL.md +3 -3
  243. package/eval-harness/SKILL.md +7 -7
  244. package/eval-harness/scripts/evaluate.js +12 -10
  245. package/evals/evaluation-reports.md +14 -0
  246. package/evals/harness-everything/tasks/positive-tier1.yaml +1 -1
  247. package/evals/harness-everything/tasks/positive-tier2.yaml +1 -1
  248. package/evals/harness-everything/tasks/positive-tier3.yaml +1 -1
  249. package/evals/install-cognitive-os/tasks/positive-trigger.yaml +1 -1
  250. package/fable-discipline/SKILL.md +2 -2
  251. package/fable-mode/CONTRACT-FORMAT.md +147 -33
  252. package/fable-mode/SKILL.md +3 -3
  253. package/fable-mode/agents/fable-orchestrator.md +95 -35
  254. package/fable-mode/execution-guardrails/SKILL.md +2 -2
  255. package/fable-mode/fable-haiku/SKILL.md +3 -3
  256. package/fable-mode/fable-opus/SKILL.md +3 -3
  257. package/fable-mode/fable-sonnet/SKILL.md +3 -3
  258. package/fable-mode/scripts/ensemble-review.js +371 -0
  259. package/fable-mode/scripts/model-selector.js +134 -3
  260. package/fable-mode/scripts/workflow-plan-consumer.js +337 -0
  261. package/find-skills/SKILL.md +5 -5
  262. package/find-skills/references/discovery-flow.md +1 -1
  263. package/find-skills/scripts/use-skill.js +7 -1
  264. package/git-commit/SKILL.md +4 -11
  265. package/grill-me/SKILL.md +5 -5
  266. package/grill-with-docs/SKILL.md +7 -7
  267. package/grill-with-docs/references/session-playbook.md +6 -4
  268. package/harness-everything/SKILL.md +23 -22
  269. package/harness-everything/references/router-workflow-plan.md +128 -0
  270. package/harness-everything/references/triage-and-tiers.md +173 -96
  271. package/harness-everything/schemas/router-task-shape.schema.json +126 -0
  272. package/harness-everything/schemas/router-workflow-plan.schema.json +149 -0
  273. package/harness-everything/scripts/bootstrap.js +13 -4
  274. package/harness-everything/scripts/ensemble-policy.js +102 -0
  275. package/harness-everything/scripts/kernel-router.js +212 -0
  276. package/harness-everything/scripts/router-contract.js +612 -0
  277. package/harness-everything/scripts/self-heal.js +29 -20
  278. package/harness-everything/scripts/tier-router.js +346 -221
  279. package/hooks/hooks.json +60 -15
  280. package/hooks/scripts/action-gate-rules.json +77 -0
  281. package/hooks/scripts/action-gate.js +528 -0
  282. package/hooks/scripts/atomic-commit-check.js +5 -5
  283. package/hooks/scripts/codex-action-gate-post.js +46 -0
  284. package/hooks/scripts/codex-permission-request.js +140 -0
  285. package/hooks/scripts/context-compact.js +4 -3
  286. package/hooks/scripts/contract-test.js +118 -51
  287. package/hooks/scripts/lib/fable-contracts.js +121 -0
  288. package/hooks/scripts/lib/harness-state.js +164 -28
  289. package/hooks/scripts/lib/platforms/claude.js +45 -62
  290. package/hooks/scripts/lib/platforms/codex.js +35 -61
  291. package/hooks/scripts/lib/platforms/continue.js +7 -7
  292. package/hooks/scripts/lib/platforms/copilot.js +29 -53
  293. package/hooks/scripts/lib/platforms/hermes.js +71 -20
  294. package/hooks/scripts/openai-session-start.js +81 -0
  295. package/hooks/scripts/rule-of-3-tracker.js +9 -8
  296. package/hooks/scripts/rule-of-3.js +29 -21
  297. package/hooks/scripts/state-persist.js +5 -4
  298. package/hooks/scripts/stop-gate.js +2 -2
  299. package/hooks/scripts/subagent-scope-guard.js +144 -38
  300. package/hooks/scripts/subagent-start.js +19 -0
  301. package/hooks/scripts/subagent-stop.js +6 -0
  302. package/improve-codebase-architecture/SKILL.md +2 -4
  303. package/improve-codebase-architecture/references/README.md +16 -0
  304. package/install-cognitive-os/SKILL.md +28 -22
  305. package/multi-agent-workspace/SKILL.md +16 -15
  306. package/multi-agent-workspace/references/architecture-guide.md +13 -9
  307. package/multi-agent-workspace/references/orchestration.md +39 -22
  308. package/multi-agent-workspace/scripts/consume-workflow-plan.js +129 -0
  309. package/multi-agent-workspace/scripts/index_memory.js +79 -26
  310. package/multi-agent-workspace/scripts/path-boundary.js +59 -0
  311. package/multi-agent-workspace/scripts/project-docs-resolver.js +357 -0
  312. package/multi-agent-workspace/scripts/scaffold.js +258 -103
  313. package/multi-agent-workspace/templates/AGENTS.md +20 -0
  314. package/multi-agent-workspace/workflows/03-generation.md +8 -10
  315. package/multi-agent-workspace/workflows/04-launcher.md +5 -5
  316. package/opencode-plugin/README.md +114 -71
  317. package/opencode-plugin/hooks/verify.js +62 -12
  318. package/opencode-plugin/index.mjs +547 -0
  319. package/opencode-plugin/plugin.json +4 -12
  320. package/package.json +20 -4
  321. package/plugins/harness-everything/.codex-plugin/plugin.json +39 -0
  322. package/plugins/harness-everything/hooks/hooks.json +197 -0
  323. package/plugins/harness-everything/hooks/scripts/action-gate-rules.json +77 -0
  324. package/plugins/harness-everything/hooks/scripts/action-gate.js +528 -0
  325. package/plugins/harness-everything/hooks/scripts/atomic-commit-check.js +68 -0
  326. package/plugins/harness-everything/hooks/scripts/boundary-guard.js +55 -0
  327. package/plugins/harness-everything/hooks/scripts/codex-action-gate-post.js +46 -0
  328. package/plugins/harness-everything/hooks/scripts/codex-permission-request.js +140 -0
  329. package/plugins/harness-everything/hooks/scripts/context-compact.js +115 -0
  330. package/plugins/harness-everything/hooks/scripts/contract-test.js +146 -0
  331. package/plugins/harness-everything/hooks/scripts/depth-guard.js +65 -0
  332. package/plugins/harness-everything/hooks/scripts/lib/fable-contracts.js +121 -0
  333. package/plugins/harness-everything/hooks/scripts/lib/harness-state.js +275 -0
  334. package/plugins/harness-everything/hooks/scripts/lib/platforms/claude.js +168 -0
  335. package/plugins/harness-everything/hooks/scripts/lib/platforms/codex.js +88 -0
  336. package/plugins/harness-everything/hooks/scripts/lib/platforms/continue.js +91 -0
  337. package/plugins/harness-everything/hooks/scripts/lib/platforms/copilot.js +85 -0
  338. package/plugins/harness-everything/hooks/scripts/lib/platforms/cursor.js +89 -0
  339. package/plugins/harness-everything/hooks/scripts/lib/platforms/hermes.js +108 -0
  340. package/plugins/harness-everything/hooks/scripts/lib/platforms/index.js +17 -0
  341. package/plugins/harness-everything/hooks/scripts/lib/platforms/worktrees.js +20 -0
  342. package/plugins/harness-everything/hooks/scripts/lib/workspace.js +290 -0
  343. package/plugins/harness-everything/hooks/scripts/openai-session-start.js +81 -0
  344. package/plugins/harness-everything/hooks/scripts/reset-circuit-breaker.js +30 -0
  345. package/plugins/harness-everything/hooks/scripts/rule-of-3-tracker.js +125 -0
  346. package/plugins/harness-everything/hooks/scripts/rule-of-3.js +195 -0
  347. package/plugins/harness-everything/hooks/scripts/state-persist.js +100 -0
  348. package/plugins/harness-everything/hooks/scripts/stop-gate.js +80 -0
  349. package/plugins/harness-everything/hooks/scripts/subagent-scope-guard.js +194 -0
  350. package/plugins/harness-everything/hooks/scripts/subagent-start.js +19 -0
  351. package/plugins/harness-everything/hooks/scripts/subagent-stop.js +6 -0
  352. package/plugins/harness-everything/hooks/session-start.js +81 -0
  353. package/plugins/harness-everything/plugin.json +43 -0
  354. package/plugins/harness-everything/scripts/lib/advisory-text.js +174 -0
  355. package/plugins/harness-everything/skills/environment-detection/SKILL.md +41 -0
  356. package/plugins/harness-everything/skills/environment-detection/references/shell-syntax-rules.md +76 -0
  357. package/plugins/harness-everything/skills/environment-detection/scripts/preflight.js +103 -0
  358. package/plugins/harness-everything/skills/eval-harness/SKILL.md +42 -0
  359. package/plugins/harness-everything/skills/eval-harness/references/scoring-rubric.md +68 -0
  360. package/plugins/harness-everything/skills/eval-harness/scripts/evaluate.js +79 -0
  361. package/plugins/harness-everything/skills/fable-discipline/SKILL.md +41 -0
  362. package/plugins/harness-everything/skills/fable-discipline/references/discipline-rules.md +22 -0
  363. package/plugins/harness-everything/skills/fable-mode/CONTRACT-FORMAT.md +165 -0
  364. package/plugins/harness-everything/skills/fable-mode/SKILL.md +39 -0
  365. package/plugins/harness-everything/skills/fable-mode/agents/fable-orchestrator.md +159 -0
  366. package/plugins/harness-everything/skills/fable-mode/agents/fable-verifier.md +32 -0
  367. package/plugins/harness-everything/skills/fable-mode/agents/fable-worker-haiku.md +52 -0
  368. package/plugins/harness-everything/skills/fable-mode/agents/fable-worker-sonnet.md +53 -0
  369. package/plugins/harness-everything/skills/fable-mode/execution-guardrails/SKILL.md +43 -0
  370. package/plugins/harness-everything/skills/fable-mode/execution-guardrails/references/guardrail-rules.md +56 -0
  371. package/plugins/harness-everything/skills/fable-mode/fable-haiku/SKILL.md +36 -0
  372. package/plugins/harness-everything/skills/fable-mode/fable-haiku/references/routing-notes.md +26 -0
  373. package/plugins/harness-everything/skills/fable-mode/fable-opus/SKILL.md +36 -0
  374. package/plugins/harness-everything/skills/fable-mode/fable-sonnet/SKILL.md +36 -0
  375. package/plugins/harness-everything/skills/fable-mode/model-matrix.json +32 -0
  376. package/plugins/harness-everything/skills/fable-mode/references/execution-phases.md +37 -0
  377. package/plugins/harness-everything/skills/fable-mode/references/model-matrix.md +39 -0
  378. package/plugins/harness-everything/skills/fable-mode/scripts/ensemble-review.js +371 -0
  379. package/plugins/harness-everything/skills/fable-mode/scripts/model-selector.js +260 -0
  380. package/plugins/harness-everything/skills/fable-mode/scripts/workflow-plan-consumer.js +337 -0
  381. package/plugins/harness-everything/skills/find-skills/SKILL.md +48 -0
  382. package/plugins/harness-everything/skills/find-skills/references/discovery-flow.md +102 -0
  383. package/plugins/harness-everything/skills/find-skills/scripts/use-skill.js +112 -0
  384. package/plugins/harness-everything/skills/git-commit/SKILL.md +38 -0
  385. package/plugins/harness-everything/skills/git-commit/guides/ANGULAR_STYLE.md +61 -0
  386. package/plugins/harness-everything/skills/git-commit/guides/COMMIT_GENERATION.md +24 -0
  387. package/plugins/harness-everything/skills/git-commit/guides/LANGUAGE_DETECTION.md +16 -0
  388. package/plugins/harness-everything/skills/git-commit/guides/MAIN_REPO.md +15 -0
  389. package/plugins/harness-everything/skills/git-commit/guides/SUBMODULES.md +27 -0
  390. package/plugins/harness-everything/skills/git-commit/references/commit-flow.md +30 -0
  391. package/plugins/harness-everything/skills/grill-me/SKILL.md +43 -0
  392. package/plugins/harness-everything/skills/grill-me/references/grilling-playbook.md +38 -0
  393. package/plugins/harness-everything/skills/grill-with-docs/ADR-FORMAT.md +47 -0
  394. package/plugins/harness-everything/skills/grill-with-docs/CONTEXT-FORMAT.md +63 -0
  395. package/plugins/harness-everything/skills/grill-with-docs/SKILL.md +41 -0
  396. package/plugins/harness-everything/skills/grill-with-docs/references/session-playbook.md +99 -0
  397. package/plugins/harness-everything/skills/harness-everything/SKILL.md +43 -0
  398. package/plugins/harness-everything/skills/harness-everything/examples/README.md +9 -0
  399. package/plugins/harness-everything/skills/harness-everything/examples/todo-workflow.md +22 -0
  400. package/plugins/harness-everything/skills/harness-everything/references/router-workflow-plan.md +128 -0
  401. package/plugins/harness-everything/skills/harness-everything/references/skill-registry.md +39 -0
  402. package/plugins/harness-everything/skills/harness-everything/references/triage-and-tiers.md +193 -0
  403. package/plugins/harness-everything/skills/harness-everything/schemas/router-task-shape.schema.json +126 -0
  404. package/plugins/harness-everything/skills/harness-everything/schemas/router-workflow-plan.schema.json +149 -0
  405. package/plugins/harness-everything/skills/harness-everything/scripts/bootstrap.js +212 -0
  406. package/plugins/harness-everything/skills/harness-everything/scripts/ensemble-policy.js +102 -0
  407. package/plugins/harness-everything/skills/harness-everything/scripts/kernel-router.js +212 -0
  408. package/plugins/harness-everything/skills/harness-everything/scripts/router-contract.js +612 -0
  409. package/plugins/harness-everything/skills/harness-everything/scripts/routing-keywords.json +320 -0
  410. package/plugins/harness-everything/skills/harness-everything/scripts/self-heal.js +250 -0
  411. package/plugins/harness-everything/skills/harness-everything/scripts/tier-router.js +459 -0
  412. package/plugins/harness-everything/skills/harness-everything/scripts/verify-gate.js +100 -0
  413. package/plugins/harness-everything/skills/improve-codebase-architecture/SKILL.md +38 -0
  414. package/plugins/harness-everything/skills/improve-codebase-architecture/guides/DEEPENING.md +37 -0
  415. package/plugins/harness-everything/skills/improve-codebase-architecture/guides/HTML-REPORT.md +123 -0
  416. package/plugins/harness-everything/skills/improve-codebase-architecture/guides/INTERFACE-DESIGN.md +44 -0
  417. package/plugins/harness-everything/skills/improve-codebase-architecture/guides/LANGUAGE.md +53 -0
  418. package/plugins/harness-everything/skills/improve-codebase-architecture/guides/refactoring-workflow.md +59 -0
  419. package/plugins/harness-everything/skills/improve-codebase-architecture/references/README.md +16 -0
  420. package/plugins/harness-everything/skills/install-cognitive-os/SKILL.md +44 -0
  421. package/plugins/harness-everything/skills/install-cognitive-os/references/cognitive-loop.md +27 -0
  422. package/plugins/harness-everything/skills/multi-agent-workspace/NOTICE-agency-agents.md +27 -0
  423. package/plugins/harness-everything/skills/multi-agent-workspace/SKILL.md +38 -0
  424. package/plugins/harness-everything/skills/multi-agent-workspace/examples/csharp-monorepo.md +123 -0
  425. package/plugins/harness-everything/skills/multi-agent-workspace/examples/typescript-cli.md +126 -0
  426. package/plugins/harness-everything/skills/multi-agent-workspace/guidelines/platform-claude.md +77 -0
  427. package/plugins/harness-everything/skills/multi-agent-workspace/guidelines/platform-codex.md +146 -0
  428. package/plugins/harness-everything/skills/multi-agent-workspace/guidelines/platform-continue.md +38 -0
  429. package/plugins/harness-everything/skills/multi-agent-workspace/guidelines/platform-copilot.md +74 -0
  430. package/plugins/harness-everything/skills/multi-agent-workspace/guidelines/platform-cursor.md +40 -0
  431. package/plugins/harness-everything/skills/multi-agent-workspace/guidelines/platform-hermes.md +38 -0
  432. package/plugins/harness-everything/skills/multi-agent-workspace/guidelines/role-capabilities.md +108 -0
  433. package/plugins/harness-everything/skills/multi-agent-workspace/references/agency-agents.md +31 -0
  434. package/plugins/harness-everything/skills/multi-agent-workspace/references/architecture-guide.md +36 -0
  435. package/plugins/harness-everything/skills/multi-agent-workspace/references/orchestration.md +65 -0
  436. package/plugins/harness-everything/skills/multi-agent-workspace/scripts/agency-catalog.js +190 -0
  437. package/plugins/harness-everything/skills/multi-agent-workspace/scripts/consume-workflow-plan.js +129 -0
  438. package/plugins/harness-everything/skills/multi-agent-workspace/scripts/index_memory.js +104 -0
  439. package/plugins/harness-everything/skills/multi-agent-workspace/scripts/path-boundary.js +59 -0
  440. package/plugins/harness-everything/skills/multi-agent-workspace/scripts/project-docs-resolver.js +357 -0
  441. package/plugins/harness-everything/skills/multi-agent-workspace/scripts/scaffold.js +408 -0
  442. package/plugins/harness-everything/skills/multi-agent-workspace/templates/AGENTS.md +20 -0
  443. package/plugins/harness-everything/skills/multi-agent-workspace/templates/README.md +17 -0
  444. package/plugins/harness-everything/skills/multi-agent-workspace/templates/agent-launcher.md +68 -0
  445. package/plugins/harness-everything/skills/multi-agent-workspace/templates/backend-developer-csharp.md +56 -0
  446. package/plugins/harness-everything/skills/multi-agent-workspace/templates/backend-developer-polyglot.md +62 -0
  447. package/plugins/harness-everything/skills/multi-agent-workspace/templates/backend-developer-ts.md +57 -0
  448. package/plugins/harness-everything/skills/multi-agent-workspace/templates/memory-keeper.md +37 -0
  449. package/plugins/harness-everything/skills/multi-agent-workspace/templates/requirement-analyzer.md +66 -0
  450. package/plugins/harness-everything/skills/multi-agent-workspace/templates/specialist-agent.md +34 -0
  451. package/plugins/harness-everything/skills/multi-agent-workspace/templates/task-verifier.md +56 -0
  452. package/plugins/harness-everything/skills/multi-agent-workspace/templates/tool-maker.md +33 -0
  453. package/plugins/harness-everything/skills/multi-agent-workspace/workflows/01-init.md +22 -0
  454. package/plugins/harness-everything/skills/multi-agent-workspace/workflows/02-analysis.md +23 -0
  455. package/plugins/harness-everything/skills/multi-agent-workspace/workflows/03-generation.md +25 -0
  456. package/plugins/harness-everything/skills/multi-agent-workspace/workflows/04-launcher.md +16 -0
  457. package/plugins/harness-everything/skills/repo-docs/SKILL.md +42 -0
  458. package/plugins/harness-everything/skills/repo-docs/references/process-guide.md +60 -0
  459. package/plugins/harness-everything/skills/repo-docs/templates/agents-template.md +264 -0
  460. package/plugins/harness-everything/skills/repo-docs/templates/knowledge-agents-template.md +50 -0
  461. package/plugins/harness-everything/skills/repo-docs/templates/knowledge-readme-template.md +83 -0
  462. package/plugins/harness-everything/skills/repo-docs/templates/manual-recon.md +117 -0
  463. package/plugins/harness-everything/skills/repo-docs/templates/multi-skills-readme-template.md +72 -0
  464. package/plugins/harness-everything/skills/repo-docs/templates/product-agents-template.md +78 -0
  465. package/plugins/harness-everything/skills/repo-docs/templates/product-readme-template.md +95 -0
  466. package/plugins/harness-everything/skills/repo-docs/templates/readme-template.md +136 -0
  467. package/plugins/harness-everything/skills/repo-docs/templates/single-skill-readme-template.md +70 -0
  468. package/plugins/harness-everything/skills/repo-docs/templates/skills-agents-template.md +60 -0
  469. package/plugins/harness-everything/skills/rewrite-commits/SKILL.md +37 -0
  470. package/plugins/harness-everything/skills/rewrite-commits/references/workflow.md +18 -0
  471. package/plugins/harness-everything/skills/security-review/SKILL.md +47 -0
  472. package/plugins/harness-everything/skills/security-review/guides/OWASP-PATTERNS.md +31 -0
  473. package/plugins/harness-everything/skills/security-review/guides/STRIDE-THREAT-MODEL.md +21 -0
  474. package/plugins/harness-everything/skills/security-review/references/security-checklist.md +478 -0
  475. package/plugins/harness-everything/skills/security-review/scripts/audit-secrets.js +85 -0
  476. package/plugins/harness-everything/skills/self-evolve/SKILL.md +45 -0
  477. package/plugins/harness-everything/skills/self-evolve/references/memory-resolution.md +61 -0
  478. package/plugins/harness-everything/skills/self-evolve/scripts/persist-memory.js +272 -0
  479. package/plugins/harness-everything/skills/self-evolve/scripts/register-dynamic-skill.js +253 -0
  480. package/plugins/harness-everything/skills/self-evolve/scripts/self-regression.js +125 -0
  481. package/plugins/harness-everything/skills/skill-creator/SKILL.md +47 -0
  482. package/plugins/harness-everything/skills/skill-creator/references/authoring-workflow.md +14 -0
  483. package/plugins/harness-everything/skills/skill-creator/references/dynamic-generation-contract.md +21 -0
  484. package/plugins/harness-everything/skills/skill-creator/references/quality-checklist.md +16 -0
  485. package/plugins/harness-everything/skills/skill-creator/references/quality-principles.md +81 -0
  486. package/plugins/harness-everything/skills/skill-creator/references/testing-workflow.md +27 -0
  487. package/plugins/harness-everything/skills/skill-style/SKILL.md +42 -0
  488. package/plugins/harness-everything/skills/skill-style/references/style-guide.md +62 -0
  489. package/plugins/harness-everything/skills/tdd/SKILL.md +38 -0
  490. package/plugins/harness-everything/skills/tdd/fixtures/pass-evidence.json +100 -0
  491. package/plugins/harness-everything/skills/tdd/fixtures/quality-scenarios.json +20 -0
  492. package/plugins/harness-everything/skills/tdd/guides/deep-modules.md +33 -0
  493. package/plugins/harness-everything/skills/tdd/guides/interface-design.md +31 -0
  494. package/plugins/harness-everything/skills/tdd/guides/mocking.md +59 -0
  495. package/plugins/harness-everything/skills/tdd/guides/refactoring.md +10 -0
  496. package/plugins/harness-everything/skills/tdd/guides/tests.md +61 -0
  497. package/plugins/harness-everything/skills/tdd/references/core-discipline.md +51 -0
  498. package/plugins/harness-everything/skills/tdd/references/integration-testing.md +13 -0
  499. package/plugins/harness-everything/skills/tdd/references/quality-model.md +68 -0
  500. package/plugins/harness-everything/skills/tdd/references/unit-testing.md +15 -0
  501. package/plugins/harness-everything/skills/tdd/schemas/quality-evidence.schema.json +211 -0
  502. package/plugins/harness-everything/skills/tdd/schemas/quality-report.schema.json +110 -0
  503. package/plugins/harness-everything/skills/tdd/scripts/quality-gate.js +475 -0
  504. package/plugins/harness-everything/skills/to-spec/SKILL.md +40 -0
  505. package/plugins/harness-everything/skills/to-spec/references/process.md +77 -0
  506. package/plugins/harness-everything/skills/to-spec/scripts/check-project-docs.js +239 -0
  507. package/plugins/harness-everything/skills/to-spec/scripts/project-docs-resolver.js +111 -0
  508. package/plugins/harness-everything/skills/to-spec/templates/cli-reference.md +31 -0
  509. package/plugins/harness-everything/skills/to-spec/templates/dev-doc.md +27 -0
  510. package/plugins/harness-everything/skills/to-spec/templates/feature-spec.md +59 -0
  511. package/plugins/harness-everything/skills/to-spec/templates/schema-doc.md +31 -0
  512. package/plugins/harness-everything/skills/to-tickets/SKILL.md +42 -0
  513. package/plugins/harness-everything/skills/to-tickets/references/publishing-and-templates.md +97 -0
  514. package/plugins/harness-everything/skills/todo-driven-workflow/SKILL.md +42 -0
  515. package/plugins/harness-everything/skills/todo-driven-workflow/references/execution-guide.md +27 -0
  516. package/plugins/harness-everything/skills/using-git-worktrees/SKILL.md +49 -0
  517. package/plugins/harness-everything/skills/using-git-worktrees/references/workflow-details.md +108 -0
  518. package/plugins/harness-everything/skills/verification-loop/SKILL.md +46 -0
  519. package/plugins/harness-everything/skills/verification-loop/references/verification-phases.md +116 -0
  520. package/plugins/harness-everything/skills/verification-loop/templates/verification-report.template.md +15 -0
  521. package/plugins/harness-everything/skills/verify-before-claim/SKILL.md +43 -0
  522. package/plugins/harness-everything/skills/verify-before-claim/references/verification-guide.md +73 -0
  523. package/plugins/harness-everything/skills/zoom-out/SKILL.md +42 -0
  524. package/plugins/harness-everything/skills/zoom-out/references/circuit-breaker.md +66 -0
  525. package/plugins/harness-everything/skills/zoom-out/templates/zoom-out-report.template.md +20 -0
  526. package/repo-docs/SKILL.md +3 -7
  527. package/rewrite-commits/SKILL.md +2 -2
  528. package/scripts/build-openai-submission.js +158 -0
  529. package/scripts/installer.js +86 -11
  530. package/scripts/lib/advisory-text.js +25 -18
  531. package/scripts/lib/execution-contract.js +70 -0
  532. package/scripts/lib/manifest.js +34 -38
  533. package/scripts/lib/path-boundary.js +90 -0
  534. package/scripts/lib/skills.js +124 -70
  535. package/scripts/lib/workspace.js +269 -7
  536. package/scripts/repository-contract.js +213 -0
  537. package/scripts/sync-current-docs.js +12 -0
  538. package/scripts/sync-openai-plugin.js +91 -0
  539. package/scripts/sync-release-version.js +212 -0
  540. package/security-review/SKILL.md +4 -7
  541. package/security-review/scripts/audit-secrets.js +9 -8
  542. package/self-evolve/SKILL.md +9 -11
  543. package/self-evolve/references/memory-resolution.md +4 -1
  544. package/self-evolve/scripts/persist-memory.js +221 -88
  545. package/self-evolve/scripts/register-dynamic-skill.js +12 -10
  546. package/self-evolve/scripts/self-regression.js +23 -8
  547. package/skill-creator/SKILL.md +12 -14
  548. package/skill-creator/references/quality-checklist.md +1 -0
  549. package/skill-style/SKILL.md +4 -4
  550. package/skill-style/references/style-guide.md +29 -3
  551. package/submission/openai/README.md +67 -0
  552. package/submission/openai/listing.json +31 -0
  553. package/submission/openai/test-cases.json +61 -0
  554. package/tdd/SKILL.md +20 -26
  555. package/tdd/fixtures/pass-evidence.json +100 -0
  556. package/tdd/fixtures/quality-scenarios.json +20 -0
  557. package/tdd/references/core-discipline.md +2 -0
  558. package/tdd/references/integration-testing.md +13 -0
  559. package/tdd/references/quality-model.md +68 -0
  560. package/tdd/references/unit-testing.md +15 -0
  561. package/tdd/schemas/quality-evidence.schema.json +211 -0
  562. package/tdd/schemas/quality-report.schema.json +110 -0
  563. package/tdd/scripts/quality-gate.js +475 -0
  564. package/to-spec/SKILL.md +3 -5
  565. package/to-spec/scripts/check-project-docs.js +42 -62
  566. package/to-spec/scripts/project-docs-resolver.js +111 -0
  567. package/to-tickets/SKILL.md +4 -4
  568. package/todo-driven-workflow/SKILL.md +6 -4
  569. package/using-git-worktrees/SKILL.md +3 -3
  570. package/verification-loop/SKILL.md +4 -4
  571. package/verify-before-claim/SKILL.md +2 -2
  572. package/zoom-out/SKILL.md +4 -4
  573. package/ab-test-deep-analysis-2026-08-27.md +0 -383
  574. package/ab-test-results-2026-08-27.md +0 -152
  575. package/ab-test-statistical-analysis-31cases.md +0 -193
  576. package/opencode-plugin/hooks/circuit-breaker.js +0 -121
  577. package/opencode-plugin/hooks/compliance.js +0 -128
  578. package/opencode-plugin/hooks/post-edit.js +0 -62
  579. package/opencode-plugin/hooks/pre-complete.js +0 -65
  580. package/opencode-plugin/test-hook-firing.js +0 -198
@@ -0,0 +1,371 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const crypto = require('crypto');
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const {
8
+ derivePlanId,
9
+ getWorkspaceStateRoot,
10
+ } = require('./workflow-plan-consumer');
11
+
12
+ const ENSEMBLE_EVIDENCE_VERSION = 1;
13
+ const SUPPORTED_DIVERSITY = new Set(['model', 'prompt', 'evidence']);
14
+ const VERIFICATION_STATUSES = new Set(['pass', 'fail', 'inconclusive']);
15
+ const VERIFIER_VERDICTS = new Set(['accept', 'reject', 'inconclusive']);
16
+ const CORRECTNESS_STATES = new Set(['pass', 'fail', 'inconclusive']);
17
+
18
+ function sanitizeId(value, label) {
19
+ const text = String(value || '').trim();
20
+ if (!text) throw new Error(`${label} is required`);
21
+ if (!/^[A-Za-z0-9._-]+$/.test(text)) throw new Error(`${label} contains unsupported characters: ${text}`);
22
+ return text.slice(0, 128);
23
+ }
24
+
25
+ function boundedString(value, label, max = 512) {
26
+ const text = String(value || '').trim();
27
+ if (!text) throw new Error(`${label} is required`);
28
+ if (text.length > max) throw new Error(`${label} exceeds ${max} characters`);
29
+ return text;
30
+ }
31
+
32
+ function normalizeEvidenceRefs(values, label) {
33
+ if (!Array.isArray(values)) throw new Error(`${label} must be an array`);
34
+ return [...new Set(values.map((value, index) => boundedString(value, `${label}[${index}]`, 512)))].sort();
35
+ }
36
+
37
+ function normalizeMetricNumber(value, label, integer = true) {
38
+ if (value === undefined || value === null) return null;
39
+ const number = Number(value);
40
+ if (!Number.isFinite(number) || number < 0 || (integer && !Number.isInteger(number))) {
41
+ throw new Error(`${label} must be a non-negative ${integer ? 'integer' : 'number'} or null`);
42
+ }
43
+ return number;
44
+ }
45
+
46
+ function normalizeMetrics(raw = {}) {
47
+ const correctness = raw.correctness === undefined || raw.correctness === null
48
+ ? null
49
+ : String(raw.correctness);
50
+ if (correctness !== null && !CORRECTNESS_STATES.has(correctness)) {
51
+ throw new Error(`metrics.correctness is invalid: ${correctness}`);
52
+ }
53
+ const failureMode = raw.failureMode === undefined || raw.failureMode === null
54
+ ? null
55
+ : boundedString(raw.failureMode, 'metrics.failureMode', 256);
56
+ return {
57
+ correctness,
58
+ toolCalls: normalizeMetricNumber(raw.toolCalls, 'metrics.toolCalls'),
59
+ tokens: normalizeMetricNumber(raw.tokens, 'metrics.tokens'),
60
+ elapsedMs: normalizeMetricNumber(raw.elapsedMs, 'metrics.elapsedMs', false),
61
+ retries: normalizeMetricNumber(raw.retries, 'metrics.retries'),
62
+ failureMode,
63
+ };
64
+ }
65
+
66
+ function normalizeCandidate(raw) {
67
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) throw new Error('candidate must be an object');
68
+ const candidateId = sanitizeId(raw.candidateId, 'candidateId');
69
+ const position = boundedString(raw.position, `${candidateId}.position`, 512);
70
+ const diversity = raw.diversity;
71
+ if (!diversity || typeof diversity !== 'object' || Array.isArray(diversity)) {
72
+ throw new Error(`${candidateId}.diversity must be an object`);
73
+ }
74
+ const modelId = boundedString(diversity.modelId, `${candidateId}.diversity.modelId`, 128);
75
+ const promptVariantId = boundedString(diversity.promptVariantId, `${candidateId}.diversity.promptVariantId`, 128);
76
+ const evidenceSetId = boundedString(diversity.evidenceSetId, `${candidateId}.diversity.evidenceSetId`, 128);
77
+
78
+ const verification = raw.objectiveVerification;
79
+ if (!verification || typeof verification !== 'object' || Array.isArray(verification)) {
80
+ throw new Error(`${candidateId}.objectiveVerification must be an object`);
81
+ }
82
+ const status = String(verification.status || '');
83
+ if (!VERIFICATION_STATUSES.has(status)) {
84
+ throw new Error(`${candidateId}.objectiveVerification.status is invalid: ${status}`);
85
+ }
86
+
87
+ return {
88
+ candidateId,
89
+ position,
90
+ diversity: { modelId, promptVariantId, evidenceSetId },
91
+ objectiveVerification: {
92
+ status,
93
+ evidenceRefs: normalizeEvidenceRefs(verification.evidenceRefs || [], `${candidateId}.objectiveVerification.evidenceRefs`),
94
+ },
95
+ metrics: normalizeMetrics(raw.metrics || {}),
96
+ };
97
+ }
98
+
99
+ function diversityFingerprint(candidate) {
100
+ return [
101
+ candidate.diversity.modelId,
102
+ candidate.diversity.promptVariantId,
103
+ candidate.diversity.evidenceSetId,
104
+ ].join('|');
105
+ }
106
+
107
+ function fingerprintHash(candidate) {
108
+ return crypto.createHash('sha256').update(diversityFingerprint(candidate)).digest('hex').slice(0, 16);
109
+ }
110
+
111
+ function normalizeVerifier(raw, candidateIds) {
112
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) throw new Error('independent verifier evidence is required');
113
+ const verifierId = sanitizeId(raw.verifierId, 'verifierId');
114
+ if (candidateIds.has(verifierId)) throw new Error('verifierId must not reuse a candidateId');
115
+ if (raw.independent !== true) throw new Error('verifier must declare independent=true');
116
+ const verdict = String(raw.verdict || '');
117
+ if (!VERIFIER_VERDICTS.has(verdict)) throw new Error(`verifier verdict is invalid: ${verdict}`);
118
+ const position = raw.position === null || raw.position === undefined
119
+ ? null
120
+ : boundedString(raw.position, 'verifier.position', 512);
121
+ if (verdict === 'accept' && !position) throw new Error('accept verdict requires verifier.position');
122
+ const evidenceRefs = normalizeEvidenceRefs(raw.evidenceRefs || [], 'verifier.evidenceRefs');
123
+ if (evidenceRefs.length === 0) throw new Error('independent verifier must provide at least one evidence reference');
124
+ return { verifierId, independent: true, verdict, position, evidenceRefs };
125
+ }
126
+
127
+ function validateEnsembleConfig(plan) {
128
+ if (!plan || typeof plan !== 'object' || Array.isArray(plan)) throw new Error('workflow plan must be an object');
129
+ const config = plan.ensemble;
130
+ if (!config || typeof config !== 'object' || Array.isArray(config)) throw new Error('workflow plan does not enable ensemble review');
131
+ if (!Number.isInteger(config.maxCandidates) || config.maxCandidates < 2 || config.maxCandidates > 4) {
132
+ throw new Error('ensemble.maxCandidates must be an integer from 2 through 4');
133
+ }
134
+ if (!Array.isArray(config.diversity) || config.diversity.length === 0) {
135
+ throw new Error('ensemble.diversity must be a non-empty array');
136
+ }
137
+ for (const dimension of config.diversity) {
138
+ if (!SUPPORTED_DIVERSITY.has(dimension)) throw new Error(`unsupported ensemble diversity dimension: ${dimension}`);
139
+ }
140
+ if (config.synthesis !== 'preserve-disagreement') throw new Error('ensemble.synthesis must be preserve-disagreement');
141
+ if (config.verifier !== 'independent') throw new Error('ensemble.verifier must be independent');
142
+ return {
143
+ maxCandidates: config.maxCandidates,
144
+ diversity: [...new Set(config.diversity)],
145
+ synthesis: config.synthesis,
146
+ verifier: config.verifier,
147
+ reasonCodes: Array.isArray(config.reasonCodes) ? [...new Set(config.reasonCodes.filter(Boolean))] : [],
148
+ };
149
+ }
150
+
151
+ function pairedEvidenceAllowsImprovementClaim(raw) {
152
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return false;
153
+ return raw.paired === true &&
154
+ raw.sameEngineModelFixtureRubricConfig === true &&
155
+ Number.isInteger(raw.sampleCount) && raw.sampleCount > 0 &&
156
+ raw.effectEstimate !== undefined && raw.effectEstimate !== null &&
157
+ raw.uncertainty !== undefined && raw.uncertainty !== null;
158
+ }
159
+
160
+ function synthesizeEnsemble({ plan, candidates, verifier, pairedEvidence = null }) {
161
+ const config = validateEnsembleConfig(plan);
162
+ if (!Array.isArray(candidates)) throw new Error('candidates must be an array');
163
+ if (candidates.length < 2) throw new Error('ensemble review requires at least two candidates');
164
+ if (candidates.length > config.maxCandidates) {
165
+ throw new Error(`candidate count ${candidates.length} exceeds ensemble.maxCandidates=${config.maxCandidates}`);
166
+ }
167
+
168
+ const normalized = candidates.map(normalizeCandidate);
169
+ const candidateIds = new Set();
170
+ const fingerprints = new Set();
171
+ for (const candidate of normalized) {
172
+ if (candidateIds.has(candidate.candidateId)) throw new Error(`duplicate candidateId: ${candidate.candidateId}`);
173
+ candidateIds.add(candidate.candidateId);
174
+ const fingerprint = diversityFingerprint(candidate);
175
+ if (fingerprints.has(fingerprint)) {
176
+ throw new Error(`candidates are not independent: duplicate model/prompt/evidence fingerprint for ${candidate.candidateId}`);
177
+ }
178
+ fingerprints.add(fingerprint);
179
+ }
180
+
181
+ const normalizedVerifier = normalizeVerifier(verifier, candidateIds);
182
+ const byPosition = new Map();
183
+ for (const candidate of normalized) {
184
+ if (!byPosition.has(candidate.position)) byPosition.set(candidate.position, []);
185
+ byPosition.get(candidate.position).push(candidate);
186
+ }
187
+
188
+ const positions = [...byPosition.entries()]
189
+ .map(([position, members]) => ({
190
+ position,
191
+ count: members.length,
192
+ candidateIds: members.map(member => member.candidateId).sort(),
193
+ verificationStatuses: members.map(member => member.objectiveVerification.status).sort(),
194
+ evidenceRefs: [...new Set(members.flatMap(member => member.objectiveVerification.evidenceRefs))].sort(),
195
+ }))
196
+ .sort((left, right) => left.position.localeCompare(right.position));
197
+
198
+ const maxCount = Math.max(...positions.map(entry => entry.count));
199
+ const leaders = positions.filter(entry => entry.count === maxCount);
200
+ const strictMajority = leaders.length === 1 && maxCount > normalized.length / 2
201
+ ? leaders[0].position
202
+ : null;
203
+ const unanimous = positions.length === 1 ? positions[0].position : null;
204
+ const proposedPosition = unanimous || strictMajority;
205
+ const proposedMembers = proposedPosition ? byPosition.get(proposedPosition) : [];
206
+ const objectiveFailureBlocks = proposedMembers.some(candidate => candidate.objectiveVerification.status === 'fail');
207
+
208
+ let disposition = 'disagreement-preserved';
209
+ let selectedPosition = null;
210
+ const reasonCodes = [...config.reasonCodes];
211
+ if (objectiveFailureBlocks) {
212
+ disposition = 'blocked-objective-failure';
213
+ reasonCodes.push('objective-verification-failure');
214
+ } else if (!proposedPosition) {
215
+ reasonCodes.push('no-strict-majority');
216
+ } else if (normalizedVerifier.verdict === 'reject') {
217
+ disposition = 'verifier-rejected';
218
+ reasonCodes.push('independent-verifier-rejected');
219
+ } else if (normalizedVerifier.verdict === 'inconclusive') {
220
+ disposition = 'verifier-inconclusive';
221
+ reasonCodes.push('independent-verifier-inconclusive');
222
+ } else if (normalizedVerifier.position !== proposedPosition) {
223
+ disposition = 'verifier-position-mismatch';
224
+ reasonCodes.push('independent-verifier-position-mismatch');
225
+ } else {
226
+ disposition = 'accepted';
227
+ selectedPosition = proposedPosition;
228
+ reasonCodes.push('independent-verifier-accepted');
229
+ }
230
+
231
+ const improvementAllowed = pairedEvidenceAllowsImprovementClaim(pairedEvidence);
232
+ const minorityPositions = positions
233
+ .filter(entry => entry.position !== selectedPosition)
234
+ .map(entry => entry.position);
235
+
236
+ return {
237
+ schemaVersion: ENSEMBLE_EVIDENCE_VERSION,
238
+ ensemble: config,
239
+ candidateCount: normalized.length,
240
+ candidateSummaries: normalized.map(candidate => ({
241
+ candidateId: candidate.candidateId,
242
+ position: candidate.position,
243
+ diversityFingerprint: fingerprintHash(candidate),
244
+ objectiveVerification: candidate.objectiveVerification,
245
+ })),
246
+ positions,
247
+ disagreement: positions.length > 1,
248
+ minorityPositions,
249
+ proposedPosition,
250
+ selectedPosition,
251
+ disposition,
252
+ verifier: normalizedVerifier,
253
+ reasonCodes: [...new Set(reasonCodes)],
254
+ measurement: {
255
+ sourceIssues: ['#71', '#83'],
256
+ correctness: normalized.map(candidate => ({
257
+ candidateId: candidate.candidateId,
258
+ value: candidate.metrics.correctness,
259
+ })),
260
+ executionCost: normalized.map(candidate => ({
261
+ candidateId: candidate.candidateId,
262
+ toolCalls: candidate.metrics.toolCalls,
263
+ tokens: candidate.metrics.tokens,
264
+ elapsedMs: candidate.metrics.elapsedMs,
265
+ retries: candidate.metrics.retries,
266
+ })),
267
+ failureModes: normalized.map(candidate => ({
268
+ candidateId: candidate.candidateId,
269
+ failureMode: candidate.metrics.failureMode,
270
+ })),
271
+ telemetryOptional: true,
272
+ },
273
+ improvementClaim: {
274
+ allowed: improvementAllowed,
275
+ reasonCode: improvementAllowed ? 'paired-evidence-present' : 'paired-evidence-required',
276
+ },
277
+ };
278
+ }
279
+
280
+ function atomicWriteJson(filePath, value) {
281
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
282
+ const tempPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
283
+ fs.writeFileSync(tempPath, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
284
+ fs.renameSync(tempPath, filePath);
285
+ }
286
+
287
+ function writeCorrelatedEvidence({ routerContract, workspaceRoot, runId, synthesis }) {
288
+ const root = path.resolve(workspaceRoot || process.cwd());
289
+ const planId = derivePlanId(routerContract);
290
+ const cleanRunId = sanitizeId(runId, 'runId');
291
+ const runRoot = path.join(getWorkspaceStateRoot(root), 'fable-runs', cleanRunId);
292
+ const manifestPath = path.join(runRoot, 'run.json');
293
+ if (!fs.existsSync(manifestPath)) throw new Error(`run manifest not found: ${manifestPath}`);
294
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
295
+ if (manifest.planId !== planId) throw new Error('run manifest planId does not match router contract');
296
+ if (manifest.runId !== cleanRunId) throw new Error('run manifest runId mismatch');
297
+ const artifact = {
298
+ ...synthesis,
299
+ planId,
300
+ runId: cleanRunId,
301
+ generatedAt: new Date().toISOString(),
302
+ };
303
+ const evidencePath = path.join(runRoot, 'ensemble.json');
304
+ atomicWriteJson(evidencePath, artifact);
305
+ return { artifact, evidencePath };
306
+ }
307
+
308
+ function parseArgs(argv) {
309
+ const args = {};
310
+ for (let index = 0; index < argv.length; index++) {
311
+ const token = argv[index];
312
+ if (token === '--plan-file') args.planFile = argv[++index];
313
+ else if (token === '--candidates-file') args.candidatesFile = argv[++index];
314
+ else if (token === '--verifier-file') args.verifierFile = argv[++index];
315
+ else if (token === '--paired-evidence-file') args.pairedEvidenceFile = argv[++index];
316
+ else if (token === '--root') args.root = argv[++index];
317
+ else if (token === '--run-id') args.runId = argv[++index];
318
+ else if (token === '--help' || token === '-h') args.help = true;
319
+ else throw new Error(`unknown argument: ${token}`);
320
+ }
321
+ return args;
322
+ }
323
+
324
+ function usage() {
325
+ return 'Usage: node fable-mode/scripts/ensemble-review.js --plan-file <router-contract.json> --candidates-file <candidates.json> --verifier-file <verifier.json> --root <workspace> --run-id <runId> [--paired-evidence-file <paired.json>]';
326
+ }
327
+
328
+ if (require.main === module) {
329
+ try {
330
+ const args = parseArgs(process.argv.slice(2));
331
+ if (args.help) {
332
+ console.log(usage());
333
+ process.exit(0);
334
+ }
335
+ if (!args.planFile || !args.candidatesFile || !args.verifierFile || !args.root || !args.runId) {
336
+ throw new Error(usage());
337
+ }
338
+ const routerContract = JSON.parse(fs.readFileSync(path.resolve(args.planFile), 'utf8'));
339
+ const candidatesPayload = JSON.parse(fs.readFileSync(path.resolve(args.candidatesFile), 'utf8'));
340
+ const verifier = JSON.parse(fs.readFileSync(path.resolve(args.verifierFile), 'utf8'));
341
+ const pairedEvidence = args.pairedEvidenceFile
342
+ ? JSON.parse(fs.readFileSync(path.resolve(args.pairedEvidenceFile), 'utf8'))
343
+ : null;
344
+ const synthesis = synthesizeEnsemble({
345
+ plan: routerContract.workflowPlan,
346
+ candidates: Array.isArray(candidatesPayload) ? candidatesPayload : candidatesPayload.candidates,
347
+ verifier,
348
+ pairedEvidence,
349
+ });
350
+ const result = writeCorrelatedEvidence({
351
+ routerContract,
352
+ workspaceRoot: args.root,
353
+ runId: args.runId,
354
+ synthesis,
355
+ });
356
+ process.stdout.write(`${JSON.stringify({ ...result.artifact, evidencePath: result.evidencePath })}\n`);
357
+ } catch (err) {
358
+ console.error(`[FABLE ENSEMBLE REVIEW] ${err.message}`);
359
+ process.exit(2);
360
+ }
361
+ }
362
+
363
+ module.exports = {
364
+ ENSEMBLE_EVIDENCE_VERSION,
365
+ diversityFingerprint,
366
+ normalizeCandidate,
367
+ pairedEvidenceAllowsImprovementClaim,
368
+ synthesizeEnsemble,
369
+ validateEnsembleConfig,
370
+ writeCorrelatedEvidence,
371
+ };
@@ -0,0 +1,260 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+ const path = require('path');
6
+ const crypto = require('crypto');
7
+
8
+ const MATRIX_PATH = path.join(__dirname, '..', 'model-matrix.json');
9
+ const SESSION_REGISTRY_DIR = 'session-workspaces';
10
+ const SESSION_REGISTRY_VERSION = 1;
11
+ const UNBOUND_WORKSPACE_KEY = 'unbound-workspace';
12
+ const HOST_CONTEXT_KEYS = ['host_id', 'hostId', 'agent_id', 'agentId', 'client_id', 'clientId', 'machine_id', 'machineId', 'runtime_id', 'runtimeId'];
13
+
14
+ // This script ships standalone (copied whole into every install target,
15
+ // e.g. .claude/skills/fable-mode/scripts/), so it can't require the source
16
+ // repo's scripts/lib/workspace.js. The audit log is genuine runtime state
17
+ // though - not a project artifact - so it needs to land in the same global,
18
+ // workspace-keyed root that hooks/scripts/lib/harness-state.js resolves to,
19
+ // not scattered under cwd (issue #42). Duplicated here, algorithm-for-
20
+ // algorithm, same as opencode-plugin/index.mjs's own inlined copy.
21
+ function findWorkspaceRoot(startPath, allowNonGit = false) {
22
+ if (typeof startPath !== 'string' || !startPath.trim()) return null;
23
+ let dir = path.resolve(startPath);
24
+ while (true) {
25
+ if (fs.existsSync(path.join(dir, '.git'))) return canonicalPath(dir);
26
+ const parent = path.dirname(dir);
27
+ if (parent === dir) break;
28
+ dir = parent;
29
+ }
30
+ return allowNonGit ? canonicalPath(startPath) : null;
31
+ }
32
+
33
+ function canonicalPath(value) {
34
+ if (typeof value !== 'string' || !value.trim()) return null;
35
+ const resolved = path.resolve(value);
36
+ try { return fs.realpathSync(resolved); } catch (err) { return resolved; }
37
+ }
38
+
39
+ function getSessionId(context) {
40
+ if (!context || typeof context !== 'object') return null;
41
+ return context.session_id || context.sessionId || null;
42
+ }
43
+
44
+ function getHostId(context) {
45
+ if (!context || typeof context !== 'object') return process.env.FABLE_HOST_ID || process.env.HARNESS_HOST_ID || null;
46
+ for (const key of HOST_CONTEXT_KEYS) {
47
+ if (typeof context[key] === 'string' && context[key].trim()) return context[key].trim();
48
+ }
49
+ return process.env.FABLE_HOST_ID || process.env.HARNESS_HOST_ID || null;
50
+ }
51
+
52
+ function getSessionRegistryPath(sessionId, hostId) {
53
+ const namespace = hostId ? `${hostId}\0${sessionId}` : String(sessionId);
54
+ const hash = crypto.createHash('sha256').update(namespace).digest('hex');
55
+ const home = process.env.HARNESS_STATE_HOME || path.join(os.homedir(), '.agents', 'harness-everything');
56
+ return path.join(home, SESSION_REGISTRY_DIR, `${hash}.json`);
57
+ }
58
+
59
+ function readRegistryRecord(filePath) {
60
+ try {
61
+ const record = JSON.parse(fs.readFileSync(filePath, 'utf8'));
62
+ return record.version === SESSION_REGISTRY_VERSION && typeof record.workspaceRoot === 'string' ? record : null;
63
+ } catch (err) {
64
+ return null;
65
+ }
66
+ }
67
+
68
+ function getBoundWorkspace(sessionId, context) {
69
+ if (!sessionId) return null;
70
+ const hostId = getHostId(context);
71
+ const records = [];
72
+ const preferred = readRegistryRecord(getSessionRegistryPath(sessionId, hostId));
73
+ if (preferred && (!hostId || !preferred.hostId || preferred.hostId === hostId)) records.push(preferred);
74
+ if (hostId) {
75
+ const unscoped = readRegistryRecord(getSessionRegistryPath(sessionId, null));
76
+ if (unscoped && !unscoped.hostId) records.push(unscoped);
77
+ }
78
+ try {
79
+ const home = process.env.HARNESS_STATE_HOME || path.join(os.homedir(), '.agents', 'harness-everything');
80
+ const dir = path.join(home, SESSION_REGISTRY_DIR);
81
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
82
+ if (!entry.isFile() || !entry.name.endsWith('.json')) continue;
83
+ const record = readRegistryRecord(path.join(dir, entry.name));
84
+ if (record && record.sessionId === sessionId && (!hostId || !record.hostId || record.hostId === hostId)) records.push(record);
85
+ }
86
+ } catch (err) { /* no registry yet */ }
87
+ const unique = [...new Map(records.map(record => [`${record.hostId || ''}\0${record.workspaceRoot}`, record])).values()];
88
+ if (unique.length === 1) return unique[0].workspaceRoot;
89
+ if (unique.length > 1 && new Set(unique.map(record => canonicalPath(record.workspaceRoot))).size === 1) return unique[0].workspaceRoot;
90
+ return null;
91
+ }
92
+
93
+ function getRegistryRecord(sessionId, context) {
94
+ const root = getBoundWorkspace(sessionId, context);
95
+ return root ? { workspaceRoot: root } : null;
96
+ }
97
+
98
+ function bindWorkspace(sessionId, root, context) {
99
+ if (!sessionId) return;
100
+ if (!root) return;
101
+ const hostId = getHostId(context);
102
+ const target = getSessionRegistryPath(sessionId, hostId);
103
+ const record = { version: SESSION_REGISTRY_VERSION, sessionId, hostId: hostId || undefined, workspaceRoot: root, updatedAt: new Date().toISOString() };
104
+ let temporary;
105
+ try {
106
+ fs.mkdirSync(path.dirname(target), { recursive: true });
107
+ temporary = `${target}.${process.pid}.${Date.now()}.tmp`;
108
+ fs.writeFileSync(temporary, JSON.stringify(record, null, 2), 'utf8');
109
+ if (fs.existsSync(target)) fs.unlinkSync(temporary);
110
+ else fs.renameSync(temporary, target);
111
+ } catch (err) {
112
+ try { if (temporary && fs.existsSync(temporary)) fs.unlinkSync(temporary); } catch (cleanupErr) { /* ignore */ }
113
+ }
114
+ }
115
+
116
+ function getWorkspaceRoot(context) {
117
+ const sessionId = getSessionId(context);
118
+ const bound = getRegistryRecord(sessionId, context);
119
+ if (bound) return bound.workspaceRoot;
120
+ const explicit = context && (context.workspace_root || context.workspaceRoot || context.cwd);
121
+ const hostRoot = explicit || process.env.HARNESS_WORKSPACE_ROOT || process.env.FABLE_WORKSPACE_ROOT;
122
+ const root = findWorkspaceRoot(hostRoot || process.cwd(), Boolean(hostRoot));
123
+ if (sessionId) bindWorkspace(sessionId, root, context);
124
+ return root;
125
+ }
126
+
127
+ function getWorkspaceStateDir(root) {
128
+ const home = process.env.HARNESS_STATE_HOME || path.join(os.homedir(), '.agents', 'harness-everything');
129
+ if (!root) return path.join(home, 'workspaces', UNBOUND_WORKSPACE_KEY);
130
+ let real = path.resolve(root);
131
+ try { real = fs.realpathSync(real); } catch (err) { /* path may not exist yet */ }
132
+ const slug = path.basename(real).toLowerCase().replace(/[^a-z0-9._-]+/g, '-').replace(/^-+|-+$/g, '') || 'workspace';
133
+ const hashInput = process.platform === 'win32' ? real.toLowerCase() : real;
134
+ const hash = crypto.createHash('sha1').update(hashInput).digest('hex').slice(0, 12);
135
+ return path.join(home, 'workspaces', `${slug}-${hash}`);
136
+ }
137
+ const REQUIRED = ['stageBrief', 'passCondition', 'verificationCommand', 'verifierResult'];
138
+ const VALID_VERIFIER_RESULTS = new Set(['pending', 'pass', 'fail', 'not-run', 'blocked']);
139
+
140
+ function loadMatrix() {
141
+ return JSON.parse(fs.readFileSync(MATRIX_PATH, 'utf8'));
142
+ }
143
+
144
+ function normalizeModel(value, matrix) {
145
+ const input = String(value || '').trim().toLowerCase();
146
+ for (const [model, definition] of Object.entries(matrix.modes)) {
147
+ if (definition.aliases.includes(input)) return model;
148
+ }
149
+ return null;
150
+ }
151
+
152
+ function parseArgs(argv) {
153
+ const args = {};
154
+ for (let i = 0; i < argv.length; i += 1) {
155
+ const token = argv[i];
156
+ if (token === '--help' || token === '-h') return { help: true };
157
+ if (!token.startsWith('--')) throw new Error(`unknown argument: ${token}`);
158
+ const key = token.slice(2).replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
159
+ const value = argv[i + 1];
160
+ if (typeof value === 'undefined' || value.startsWith('--')) throw new Error(`missing value for --${key}`);
161
+ args[key] = value;
162
+ i += 1;
163
+ }
164
+ return args;
165
+ }
166
+
167
+ function resolveMode(input, matrix = loadMatrix()) {
168
+ const requestedModel = normalizeModel(input.requested, matrix);
169
+ if (!requestedModel) throw new Error('requested model must be one of haiku, sonnet, sonnect, or opus');
170
+
171
+ const availableModels = String(input.available || '')
172
+ .split(/[\s,]+/)
173
+ .map(model => normalizeModel(model, matrix))
174
+ .filter(Boolean);
175
+ const availableAgents = String(input.availableAgents || '')
176
+ .split(/[\s,]+/)
177
+ .map(agent => agent.trim())
178
+ .filter(Boolean);
179
+ const fallback = input.fallback || 'stop';
180
+ if (!Object.prototype.hasOwnProperty.call(matrix.fallbacks, fallback)) {
181
+ throw new Error('fallback must be inline or stop');
182
+ }
183
+
184
+ for (const field of REQUIRED) {
185
+ if (!String(input[field] || '').trim()) throw new Error(`${field} is required for an auditable stage`);
186
+ }
187
+ if (!VALID_VERIFIER_RESULTS.has(input.verifierResult)) {
188
+ throw new Error(`verifierResult must be one of ${[...VALID_VERIFIER_RESULTS].join(', ')}`);
189
+ }
190
+
191
+ const requestedAgent = matrix.modes[requestedModel].agent;
192
+ const modelAvailable = availableModels.includes(requestedModel);
193
+ const agentAvailable = availableAgents.includes(requestedAgent);
194
+ const selected = modelAvailable && agentAvailable;
195
+ const hostModel = String(input.hostModel || 'current-host').trim();
196
+ const fallbackDefinition = matrix.fallbacks[fallback];
197
+ const status = selected ? 'selected' : fallbackDefinition.status;
198
+ const effectiveModel = selected
199
+ ? requestedModel
200
+ : fallback === 'inline'
201
+ ? hostModel
202
+ : fallbackDefinition.effectiveModel;
203
+ const missing = [];
204
+ if (!modelAvailable) missing.push(`${requestedModel} is not in availableModels`);
205
+ if (!agentAvailable) missing.push(`${requestedAgent} is not in availableAgents`);
206
+ const fallbackReason = selected
207
+ ? 'none'
208
+ : `${fallbackDefinition.reason}: ${missing.join('; ')}`;
209
+
210
+ return {
211
+ schemaVersion: matrix.schemaVersion,
212
+ status,
213
+ requestedModel,
214
+ requestedInput: String(input.requested).trim(),
215
+ effectiveModel,
216
+ availableModels: [...new Set(availableModels)],
217
+ availableAgents: [...new Set(availableAgents)],
218
+ fallbackPolicy: fallback,
219
+ fallbackReason,
220
+ agent: selected ? requestedAgent : null,
221
+ modelRole: matrix.modes[requestedModel].role,
222
+ stageBrief: String(input.stageBrief).trim(),
223
+ passCondition: String(input.passCondition).trim(),
224
+ verificationCommand: String(input.verificationCommand).trim(),
225
+ verifierResult: input.verifierResult,
226
+ escalationRequired: status === 'blocked'
227
+ };
228
+ }
229
+
230
+ function printHelp() {
231
+ console.log('Usage: node fable-mode/scripts/model-selector.js --requested <haiku|sonnet|sonnect|opus> --available <models> --available-agents <agent names> --stage-brief <text> --pass-condition <text> --verification-command <command> --verifier-result <pending|pass|fail|not-run|blocked> [--fallback <inline|stop>] [--host-model <model>] [--audit-file <path>]');
232
+ }
233
+
234
+ function appendAuditRecord(record, auditFile, context) {
235
+ const target = auditFile || process.env.FABLE_AUDIT_FILE ||
236
+ path.join(getWorkspaceStateDir(getWorkspaceRoot(context)), 'state', 'fable-mode', 'audit.jsonl');
237
+ fs.mkdirSync(path.dirname(path.resolve(target)), { recursive: true });
238
+ fs.appendFileSync(target, `${JSON.stringify(record)}\n`, 'utf8');
239
+ }
240
+
241
+ function main(argv = process.argv.slice(2)) {
242
+ try {
243
+ const input = parseArgs(argv);
244
+ if (input.help) {
245
+ printHelp();
246
+ return 0;
247
+ }
248
+ const record = resolveMode(input);
249
+ appendAuditRecord(record, input.auditFile, input);
250
+ console.log(JSON.stringify(record, null, 2));
251
+ return record.status === 'blocked' ? 2 : 0;
252
+ } catch (error) {
253
+ console.error(`[fable-mode/model-selector] ${error.message}`);
254
+ return 2;
255
+ }
256
+ }
257
+
258
+ if (require.main === module) process.exitCode = main();
259
+
260
+ module.exports = { loadMatrix, normalizeModel, parseArgs, resolveMode, main };