peaks-loop 4.1.4 → 4.1.6

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 (294) hide show
  1. package/.claude-plugin/marketplace.json +7 -2
  2. package/CHANGELOG.md +148 -0
  3. package/README-en.md +47 -183
  4. package/README.md +24 -188
  5. package/dist/cli/cli-helpers.d.ts +20 -0
  6. package/dist/cli/cli-helpers.js +34 -0
  7. package/dist/cli/commands/_register.js +2 -0
  8. package/dist/cli/commands/best-practice-scan-command.d.ts +11 -6
  9. package/dist/cli/commands/best-practice-scan-command.js +35 -20
  10. package/dist/cli/commands/best-practice-scan-helpers.d.ts +47 -0
  11. package/dist/cli/commands/best-practice-scan-helpers.js +88 -5
  12. package/dist/cli/commands/best-practice-scan-lookup-results.d.ts +13 -0
  13. package/dist/cli/commands/best-practice-scan-lookup-results.js +237 -0
  14. package/dist/cli/commands/code-commands.d.ts +6 -4
  15. package/dist/cli/commands/code-commands.js +6 -4
  16. package/dist/cli/commands/code-gate-command.d.ts +5 -5
  17. package/dist/cli/commands/code-gate-command.js +49 -9
  18. package/dist/cli/commands/code-mode-gate-plan-command.d.ts +1 -1
  19. package/dist/cli/commands/code-mode-gate-plan-command.js +2 -2
  20. package/dist/cli/commands/core/memory-extract-command.js +10 -5
  21. package/dist/cli/commands/dispatch-cli-invocation-check.d.ts +108 -0
  22. package/dist/cli/commands/dispatch-cli-invocation-check.js +87 -0
  23. package/dist/cli/commands/dispatch-cli-invocation-scan.d.ts +66 -0
  24. package/dist/cli/commands/dispatch-cli-invocation-scan.js +162 -0
  25. package/dist/cli/commands/dispatch-command-spec.js +1 -1
  26. package/dist/cli/commands/dispatch-commands.js +12 -5
  27. package/dist/cli/commands/dispatch-isolation-lease.d.ts +1 -1
  28. package/dist/cli/commands/dispatch-isolation-lease.js +6 -53
  29. package/dist/cli/commands/dispatch-preflight.js +46 -0
  30. package/dist/cli/commands/dispatch-prompt-blocks.d.ts +1 -1
  31. package/dist/cli/commands/dispatch-prompt-composition.d.ts +7 -1
  32. package/dist/cli/commands/dispatch-prompt-composition.js +29 -7
  33. package/dist/cli/commands/dispatch-record-write.d.ts +1 -1
  34. package/dist/cli/commands/dispatch-tool-call.d.ts +1 -1
  35. package/dist/cli/commands/doc-commands.js +1 -1
  36. package/dist/cli/commands/feedback-commands-helpers.js +1 -1
  37. package/dist/cli/commands/final-review-prepare-command.js +22 -1
  38. package/dist/cli/commands/gate-commands-enforce.js +3 -3
  39. package/dist/cli/commands/hook-handle.js +41 -20
  40. package/dist/cli/commands/lint-commands.js +3 -1
  41. package/dist/cli/commands/loop-eval-capture-index.js +2 -4
  42. package/dist/cli/commands/openspec-command-shared.js +2 -2
  43. package/dist/cli/commands/perf-audit-commands.js +15 -5
  44. package/dist/cli/commands/project-commands.js +9 -6
  45. package/dist/cli/commands/race-commands.d.ts +15 -0
  46. package/dist/cli/commands/race-commands.js +65 -0
  47. package/dist/cli/commands/race-pilot-gate-record-command.d.ts +3 -0
  48. package/dist/cli/commands/race-pilot-gate-record-command.js +81 -0
  49. package/dist/cli/commands/request-command-options.d.ts +8 -0
  50. package/dist/cli/commands/request-commands.js +2 -0
  51. package/dist/cli/commands/request-init-command.js +67 -12
  52. package/dist/cli/commands/{vm-status-command.d.ts → request-retag-command.d.ts} +1 -1
  53. package/dist/cli/commands/request-retag-command.js +50 -0
  54. package/dist/cli/commands/request-show-command.d.ts +8 -0
  55. package/dist/cli/commands/request-show-command.js +14 -1
  56. package/dist/cli/commands/request-transition-command.js +12 -4
  57. package/dist/cli/commands/request-transition-failures.d.ts +14 -0
  58. package/dist/cli/commands/request-transition-failures.js +76 -7
  59. package/dist/cli/commands/request-transition-preflight.js +1 -1
  60. package/dist/cli/commands/scan-scope-commands.js +2 -2
  61. package/dist/cli/commands/security-audit-commands.js +26 -6
  62. package/dist/cli/commands/slice-decompose-artifacts.js +2 -1
  63. package/dist/cli/commands/verdict-aggregate-command.js +2 -1
  64. package/dist/cli/commands/workflow-gate-commands.js +4 -4
  65. package/dist/cli/commands/worktree-lease-gc-command.js +1 -1
  66. package/dist/cli/program.js +0 -2
  67. package/dist/services/artifacts/artifact-contract-block.d.ts +53 -0
  68. package/dist/services/artifacts/artifact-contract-block.js +231 -0
  69. package/dist/services/artifacts/artifact-prerequisites.d.ts +27 -19
  70. package/dist/services/artifacts/artifact-prerequisites.js +65 -135
  71. package/dist/services/artifacts/artifact-templates.d.ts +1 -1
  72. package/dist/services/artifacts/artifact-templates.js +17 -10
  73. package/dist/services/artifacts/prerequisite-checks.d.ts +87 -0
  74. package/dist/services/artifacts/prerequisite-checks.js +198 -0
  75. package/dist/services/artifacts/prerequisite-transition-event.d.ts +20 -0
  76. package/dist/services/artifacts/prerequisite-transition-event.js +27 -0
  77. package/dist/services/artifacts/rd-transition-gates.d.ts +33 -0
  78. package/dist/services/artifacts/rd-transition-gates.js +71 -0
  79. package/dist/services/artifacts/request-artifact-metadata.d.ts +31 -0
  80. package/dist/services/artifacts/request-artifact-metadata.js +44 -0
  81. package/dist/services/artifacts/request-artifact-service.d.ts +5 -0
  82. package/dist/services/artifacts/request-artifact-service.js +43 -69
  83. package/dist/services/artifacts/request-artifact-state-helpers.d.ts +21 -1
  84. package/dist/services/artifacts/request-artifact-state-helpers.js +34 -8
  85. package/dist/services/artifacts/request-retag-service.d.ts +68 -0
  86. package/dist/services/artifacts/request-retag-service.js +125 -0
  87. package/dist/services/artifacts/request-state-order.d.ts +38 -0
  88. package/dist/services/artifacts/request-state-order.js +99 -0
  89. package/dist/services/artifacts/request-type-demand.d.ts +44 -0
  90. package/dist/services/artifacts/request-type-demand.js +71 -0
  91. package/dist/services/audit/audit-goal-service.d.ts +7 -0
  92. package/dist/services/audit/enforcers/active-skill-resolver.d.ts +18 -0
  93. package/dist/services/audit/enforcers/active-skill-resolver.js +48 -1
  94. package/dist/services/audit/enforcers/code-ban.d.ts +11 -2
  95. package/dist/services/audit/enforcers/code-ban.js +21 -1
  96. package/dist/services/audit/red-line-catalog-p2-a-bee-runtime.d.ts +17 -0
  97. package/dist/services/audit/red-line-catalog-p2-a-bee-runtime.js +24 -7
  98. package/dist/services/audit-independent/handoff-missing-refusal.d.ts +26 -0
  99. package/dist/services/audit-independent/handoff-missing-refusal.js +109 -0
  100. package/dist/services/audit-independent/handoff-readers.d.ts +37 -0
  101. package/dist/services/audit-independent/handoff-readers.js +81 -0
  102. package/dist/services/audit-independent/index.d.ts +6 -1
  103. package/dist/services/audit-independent/index.js +6 -1
  104. package/dist/services/audit-independent/judged-declaration-build.d.ts +48 -0
  105. package/dist/services/audit-independent/judged-declaration-build.js +73 -0
  106. package/dist/services/audit-independent/judged-declaration-check.d.ts +80 -0
  107. package/dist/services/audit-independent/judged-declaration-check.js +216 -0
  108. package/dist/services/audit-independent/judged-declaration.d.ts +94 -0
  109. package/dist/services/audit-independent/judged-declaration.js +218 -0
  110. package/dist/services/audit-independent/perf-audit-service.js +12 -14
  111. package/dist/services/audit-independent/security-audit-artifact.d.ts +28 -0
  112. package/dist/services/audit-independent/security-audit-artifact.js +90 -0
  113. package/dist/services/audit-independent/security-audit-service.d.ts +6 -53
  114. package/dist/services/audit-independent/security-audit-service.js +34 -178
  115. package/dist/services/capability-guard-runner/contracts/J05.js +60 -14
  116. package/dist/services/codegraph/codegraph-index-integrity.js +2 -0
  117. package/dist/services/context/build-dispatch-system-prompt.d.ts +8 -12
  118. package/dist/services/context/build-dispatch-system-prompt.js +18 -18
  119. package/dist/services/context/collector.js +5 -1
  120. package/dist/services/context/post-compact-reinjection.js +1 -1
  121. package/dist/services/dispatch/active-dispatch-index.d.ts +36 -0
  122. package/dist/services/dispatch/active-dispatch-index.js +118 -0
  123. package/dist/services/dispatch/batch-counter.js +1 -2
  124. package/dist/services/dispatch/dispatch-record-writer.d.ts +29 -16
  125. package/dist/services/dispatch/dispatch-record-writer.js +58 -100
  126. package/dist/services/dispatch/dispatch-sub-agent.js +1 -1
  127. package/dist/services/dispatch/karpathy-block.d.ts +55 -0
  128. package/dist/services/dispatch/karpathy-block.js +101 -0
  129. package/dist/services/dispatch/ledger-reaper.d.ts +80 -0
  130. package/dist/services/dispatch/ledger-reaper.js +131 -0
  131. package/dist/services/dispatch/test-tool-detection.d.ts +17 -1
  132. package/dist/services/dispatch/test-tool-detection.js +12 -1
  133. package/dist/services/evidence/evidence-generator.js +23 -12
  134. package/dist/services/feedback/feedback-promotion-service.d.ts +8 -11
  135. package/dist/services/feedback/feedback-promotion-service.js +30 -35
  136. package/dist/services/feedback/promotion-artifact-json-evidence.d.ts +18 -0
  137. package/dist/services/feedback/promotion-artifact-missing.d.ts +22 -0
  138. package/dist/services/feedback/promotion-artifact-missing.js +63 -0
  139. package/dist/services/final-review/final-review-contract.d.ts +95 -4
  140. package/dist/services/final-review/final-review-contract.js +64 -0
  141. package/dist/services/final-review/final-review-delivery.d.ts +13 -0
  142. package/dist/services/final-review/final-review-delivery.js +26 -12
  143. package/dist/services/final-review/final-review-evidence-collect.js +8 -53
  144. package/dist/services/final-review/final-review-evidence-records.d.ts +21 -0
  145. package/dist/services/final-review/final-review-evidence-records.js +67 -0
  146. package/dist/services/final-review/final-review-evidence-sources.d.ts +22 -0
  147. package/dist/services/final-review/final-review-evidence-sources.js +28 -4
  148. package/dist/services/final-review/final-review-prompt.js +19 -6
  149. package/dist/services/final-review/final-review-runner.js +5 -0
  150. package/dist/services/final-review/final-review-service.d.ts +2 -2
  151. package/dist/services/final-review/index.d.ts +1 -1
  152. package/dist/services/final-review/pre-post-diff.d.ts +2 -75
  153. package/dist/services/final-review/pre-post-diff.js +60 -59
  154. package/dist/services/hooks/pre-tool-code-gate.d.ts +7 -1
  155. package/dist/services/hooks/pre-tool-code-gate.js +21 -2
  156. package/dist/services/hooks/worktree-authorization-gate.js +6 -31
  157. package/dist/services/hooks/worktree-refusal-messages.d.ts +74 -0
  158. package/dist/services/hooks/worktree-refusal-messages.js +102 -0
  159. package/dist/services/lint/eslint-runner-support.d.ts +1 -1
  160. package/dist/services/lint/eslint-runner-support.js +2 -1
  161. package/dist/services/lint/eslint-runner-types.d.ts +8 -0
  162. package/dist/services/lint/eslint-runner.js +17 -4
  163. package/dist/services/llm/anthropic-runner.js +24 -7
  164. package/dist/services/loop/loop-observability.d.ts +39 -0
  165. package/dist/services/loop/loop-observability.js +55 -0
  166. package/dist/services/loop/monotonic-guard.js +6 -9
  167. package/dist/services/loop/monotonic-runner.js +8 -7
  168. package/dist/services/loop/run-driver.js +18 -22
  169. package/dist/services/memory/project-memory-service/index/kind-dispatch.js +14 -1
  170. package/dist/services/memory/project-memory-service/index/project-memory-plan-exec.js +13 -2
  171. package/dist/services/memory/project-memory-service/index.d.ts +2 -2
  172. package/dist/services/memory/project-memory-service/index.js +1 -1
  173. package/dist/services/memory/project-memory-service/parsers/frontmatter-parse.d.ts +36 -0
  174. package/dist/services/memory/project-memory-service/parsers/frontmatter-parse.js +48 -2
  175. package/dist/services/memory/project-memory-service/parsers/markdown-pure.d.ts +23 -1
  176. package/dist/services/memory/project-memory-service/parsers/markdown-pure.js +37 -0
  177. package/dist/services/memory/project-memory-service/types.d.ts +32 -0
  178. package/dist/services/observability/observability-service.d.ts +7 -0
  179. package/dist/services/observability/observability-service.js +2 -1
  180. package/dist/services/openspec/coverage-evidence-reader.d.ts +9 -9
  181. package/dist/services/openspec/coverage-evidence-reader.js +8 -8
  182. package/dist/services/openspec/openspec-archive-service.d.ts +1 -1
  183. package/dist/services/openspec/openspec-archive-service.js +6 -6
  184. package/dist/services/prd/gate-evidence-derivation.d.ts +4 -3
  185. package/dist/services/prd/gate-evidence-derivation.js +4 -3
  186. package/dist/services/qa/bdd-test-style-verifier.js +22 -8
  187. package/dist/services/race/gate2-evaluator.d.ts +58 -0
  188. package/dist/services/race/gate2-evaluator.js +111 -0
  189. package/dist/services/race/gate2-policy.d.ts +17 -0
  190. package/dist/services/race/gate2-policy.js +31 -0
  191. package/dist/services/race/lane-phase.d.ts +19 -0
  192. package/dist/services/race/lane-phase.js +113 -0
  193. package/dist/services/race/pilot-gate-store.d.ts +67 -0
  194. package/dist/services/race/pilot-gate-store.js +227 -0
  195. package/dist/services/scan/file-size-baseline.d.ts +33 -0
  196. package/dist/services/scan/file-size-baseline.js +173 -0
  197. package/dist/services/scan/file-size-scan.d.ts +35 -3
  198. package/dist/services/scan/file-size-scan.js +63 -42
  199. package/dist/services/scan/type-corroboration.d.ts +32 -0
  200. package/dist/services/scan/type-corroboration.js +51 -0
  201. package/dist/services/scan/type-sanity-service.d.ts +14 -0
  202. package/dist/services/scan/type-sanity-service.js +23 -22
  203. package/dist/services/security/safe-settings-path.d.ts +5 -0
  204. package/dist/services/security/safe-settings-path.js +64 -8
  205. package/dist/services/skill/resume-detector.js +11 -11
  206. package/dist/services/skills/hooks-codegate-superpowers.d.ts +5 -6
  207. package/dist/services/skills/hooks-codegate-superpowers.js +7 -8
  208. package/dist/services/skills/hooks-settings-service.d.ts +1 -1
  209. package/dist/services/skills/hooks-settings-service.js +1 -1
  210. package/dist/services/skills/presence-lease-order.d.ts +13 -0
  211. package/dist/services/skills/presence-lease-order.js +24 -0
  212. package/dist/services/skills/skill-conformance-service.js +1 -0
  213. package/dist/services/skills/skill-statusline-service.js +4 -7
  214. package/dist/services/slice/slice-check-service.js +8 -8
  215. package/dist/services/workflow/pipeline-verify-gate-support.d.ts +24 -8
  216. package/dist/services/workflow/pipeline-verify-gate-support.js +34 -39
  217. package/dist/services/workflow/pipeline-verify-qa-phase.d.ts +102 -0
  218. package/dist/services/workflow/pipeline-verify-qa-phase.js +176 -0
  219. package/dist/services/workflow/pipeline-verify-service.js +27 -28
  220. package/dist/services/workflow/request-type-resolution.d.ts +99 -0
  221. package/dist/services/workflow/request-type-resolution.js +130 -0
  222. package/dist/services/workflow/workflow-skip-service.d.ts +1 -20
  223. package/dist/services/workflow/workflow-skip-service.js +22 -25
  224. package/dist/services/workflow/workflow-state-store.d.ts +9 -0
  225. package/dist/services/workflow/workflow-state-store.js +26 -1
  226. package/dist/services/workspace/claude-settings-retirements.d.ts +54 -0
  227. package/dist/services/workspace/claude-settings-retirements.js +112 -0
  228. package/dist/services/workspace/claude-settings-template-merge.d.ts +35 -15
  229. package/dist/services/workspace/claude-settings-template-merge.js +33 -53
  230. package/dist/services/workspace/claude-settings-template.d.ts +62 -12
  231. package/dist/services/workspace/claude-settings-template.js +58 -58
  232. package/dist/services/workspace/migrate-1-4-1-service.js +3 -0
  233. package/dist/services/workspace/reconcile-service.js +0 -1
  234. package/dist/shared/incrementing-number.d.ts +33 -2
  235. package/dist/shared/incrementing-number.js +72 -3
  236. package/package.json +5 -7
  237. package/skills/bee/peaks-perf-audit/SKILL.md +1 -1
  238. package/skills/bee/peaks-prd/SKILL.md +4 -3
  239. package/skills/bee/peaks-qa/SKILL.md +1 -1
  240. package/skills/bee/peaks-qa/references/qa-sub-agent-dispatch.md +2 -2
  241. package/skills/bee/peaks-qa/references/qa-transition-gates.md +1 -1
  242. package/skills/bee/peaks-rd/SKILL.md +2 -2
  243. package/skills/bee/peaks-rd/references/rd-fanout-contracts.md +1 -1
  244. package/skills/bee/peaks-rd/references/rd-sub-agent-dispatch.md +8 -4
  245. package/skills/bee/peaks-rd/references/rd-transition-gates.md +3 -3
  246. package/skills/bee/peaks-rd/references/v2-12-fanout-collapse.md +2 -2
  247. package/skills/bee/peaks-rd/references/writing-handoff-frontmatter.md +1 -1
  248. package/skills/bee/peaks-reviewer/SKILL.md +1 -1
  249. package/skills/bee/peaks-sc/SKILL.md +1 -1
  250. package/skills/bee/peaks-security-audit/SKILL.md +10 -2
  251. package/skills/bee/peaks-txt/SKILL.md +4 -3
  252. package/skills/bee/peaks-ui/SKILL.md +3 -3
  253. package/skills/peaks-audit/SKILL.md +29 -1
  254. package/skills/peaks-code/SKILL.md +37 -17
  255. package/skills/peaks-code/references/fast-lane-norm.md +42 -0
  256. package/skills/peaks-code/references/fast-mode.md +3 -2
  257. package/skills/peaks-code/references/local-artifact-workspace.md +3 -3
  258. package/skills/peaks-code/references/micro-cycle.md +3 -3
  259. package/skills/peaks-code/references/resume-detection.md +1 -1
  260. package/skills/peaks-code/references/runbook.md +12 -6
  261. package/skills/peaks-code/references/step-11-memory-sediment.md +4 -0
  262. package/skills/peaks-code/references/sub-agent-dispatch.md +1 -1
  263. package/skills/peaks-code/references/swarm-dispatch-contract.md +40 -16
  264. package/skills/peaks-code/references/workflow-gates-and-types.md +6 -6
  265. package/skills/peaks-code/references/worktree-governance.md +4 -4
  266. package/skills/peaks-content/SKILL.md +1 -1
  267. package/skills/peaks-doctor/SKILL.md +1 -1
  268. package/skills/peaks-final-review/SKILL.md +31 -11
  269. package/skills/peaks-ide/SKILL.md +1 -1
  270. package/skills/peaks-issue-fix-orchestrator/SKILL.md +1 -1
  271. package/skills/peaks-race-code/SKILL.md +185 -0
  272. package/skills/peaks-resume/SKILL.md +1 -1
  273. package/skills/peaks-slice-decompose/SKILL.md +1 -1
  274. package/skills/peaks-solo/SKILL.md +1 -1
  275. package/skills/peaks-sop/SKILL.md +1 -1
  276. package/skills/peaks-status/SKILL.md +1 -1
  277. package/skills/peaks-test/SKILL.md +7 -4
  278. package/dist/cli/commands/vm-command-shared.d.ts +0 -23
  279. package/dist/cli/commands/vm-command-shared.js +0 -23
  280. package/dist/cli/commands/vm-commands.d.ts +0 -3
  281. package/dist/cli/commands/vm-commands.js +0 -45
  282. package/dist/cli/commands/vm-hypervisor-probe.d.ts +0 -27
  283. package/dist/cli/commands/vm-hypervisor-probe.js +0 -78
  284. package/dist/cli/commands/vm-hypervisor-runtime.d.ts +0 -15
  285. package/dist/cli/commands/vm-hypervisor-runtime.js +0 -64
  286. package/dist/cli/commands/vm-release-command.d.ts +0 -5
  287. package/dist/cli/commands/vm-release-command.js +0 -101
  288. package/dist/cli/commands/vm-spawn-command.d.ts +0 -5
  289. package/dist/cli/commands/vm-spawn-command.js +0 -177
  290. package/dist/cli/commands/vm-status-command.js +0 -50
  291. package/dist/services/audit/enforcers/lint-peaks-skill-runtime.d.ts +0 -23
  292. package/dist/services/audit/enforcers/lint-peaks-skill-runtime.js +0 -64
  293. package/dist/services/vm/vm-lease.d.ts +0 -40
  294. package/dist/services/vm/vm-lease.js +0 -160
@@ -30,11 +30,13 @@
30
30
  * - Output: `.peaks/_runtime/<sid>/audit/security-<rid>.md`
31
31
  * - Schema: `.peaks/project-scan/audit-output-schema.md` (schemaVersion: 1)
32
32
  */
33
- import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
34
- import { join, resolve, isAbsolute } from 'node:path';
35
- import { createHash } from 'node:crypto';
36
- import { REQUEST_ID_PATTERN } from '../artifacts/request-artifact-service.js';
33
+ import { existsSync } from 'node:fs';
34
+ import { join } from 'node:path';
37
35
  import { resolveHandoffPath } from '../prd/handoff-service.js';
36
+ import { handoffMissingRefusal } from './handoff-missing-refusal.js';
37
+ import { renderSecurityAuditArtifact, writeSecurityAuditArtifact } from './security-audit-artifact.js';
38
+ import { declarationMissingDetect, renderJudgedDeclaration } from './judged-declaration.js';
39
+ import { buildJudgedDeclarationFor } from './judged-declaration-build.js';
38
40
  /**
39
41
  * Validate a raw value as a SecurityAuditEnvelope. Mirrors the
40
42
  * `isEccEnvelope` strict-shape pattern.
@@ -75,70 +77,6 @@ export function isSecurityAuditEnvelope(value) {
75
77
  }
76
78
  return true;
77
79
  }
78
- /**
79
- * Read the peaks-prd handoff frontmatter + body, verify sha256 matches
80
- * the body. Returns null on missing file or sha256 mismatch; otherwise
81
- * returns the parsed frontmatter + body string.
82
- *
83
- * Defensive: we read frontmatter via a 1-line regex match, not via
84
- * a YAML parser. The handoff service (`src/services/prd/handoff-service.ts`)
85
- * is the canonical writer; we only consume its output here.
86
- */
87
- export function readAndVerifyHandoff(handoffPath, projectRoot) {
88
- if (!handoffPath || !isAbsolute(handoffPath)) {
89
- const absolutePath = resolve(projectRoot, handoffPath);
90
- if (!existsSync(absolutePath))
91
- return null;
92
- return readAndVerifyHandoff(absolutePath, projectRoot);
93
- }
94
- if (!existsSync(handoffPath))
95
- return null;
96
- let raw;
97
- try {
98
- raw = readFileSync(handoffPath, 'utf8');
99
- }
100
- catch {
101
- // TODO(g2): legacy silent catch — grace: 1 minor release (v2.14.0)
102
- return null;
103
- }
104
- // Frontmatter pattern: `---` line, then key: value pairs, then `---` line.
105
- const match = raw.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
106
- if (match === null)
107
- return null;
108
- const frontmatterRaw = match[1];
109
- const body = match[2];
110
- const sha256Match = frontmatterRaw.match(/^sha256:\s*([a-f0-9]{64})\s*$/m);
111
- const schemaVersionMatch = frontmatterRaw.match(/^schemaVersion:\s*(\d+)\s*$/m);
112
- if (sha256Match === null || schemaVersionMatch === null)
113
- return null;
114
- const sha256Expected = sha256Match[1];
115
- const schemaVersion = parseInt(schemaVersionMatch[1], 10);
116
- const sha256Actual = createHash('sha256').update(body, 'utf8').digest('hex');
117
- if (sha256Expected !== sha256Actual)
118
- return null;
119
- return {
120
- frontmatter: { sha256: sha256Expected, schemaVersion },
121
- body
122
- };
123
- }
124
- /**
125
- * Read the project-level security-template.md. Returns the body
126
- * string (with frontmatter stripped) or null if the file is absent.
127
- * Does NOT validate the template content; the parent LLM validates
128
- * by reading.
129
- */
130
- export function readSecurityTemplate(projectRoot) {
131
- const templatePath = join(projectRoot, '.peaks', 'project-scan', 'security-template.md');
132
- if (!existsSync(templatePath))
133
- return null;
134
- try {
135
- return readFileSync(templatePath, 'utf8');
136
- }
137
- catch {
138
- // TODO(g2): legacy silent catch — grace: 1 minor release (v2.14.0)
139
- return null;
140
- }
141
- }
142
80
  /**
143
81
  * 5-state detector. The parent skill inspects the state and either
144
82
  * proceeds (when `ready`) or records a degradation note and falls
@@ -159,22 +97,20 @@ export function detectSecurityAudit(input) {
159
97
  const templatePath = join(input.projectRoot, '.peaks', 'project-scan', 'security-template.md');
160
98
  const templatePresent = existsSync(templatePath);
161
99
  if (!handoffPresent) {
100
+ const refusal = handoffMissingRefusal({
101
+ role: 'security',
102
+ projectRoot: input.projectRoot,
103
+ sessionId: input.sessionId,
104
+ ...(input.requestId !== undefined ? { requestId: input.requestId } : {}),
105
+ // Measured, not assumed: `detect` supplies no envelope at all.
106
+ envelopeValidated: input.envelope !== undefined && isSecurityAuditEnvelope(input.envelope)
107
+ });
162
108
  return {
163
109
  state: 'handoff-missing',
164
110
  handoffPresent: false,
165
111
  templatePresent,
166
- warnings: [
167
- `peaks-prd handoff not found under ${join(input.projectRoot, '.peaks', '_runtime', input.sessionId, 'prd')}`,
168
- ...(input.requestId === undefined
169
- ? [
170
- "No --rid was supplied, so only the pre-rid-scoping `prd/handoff.md` could be probed. Pass --rid to resolve this slice's `prd/handoff-<rid>.md`."
171
- ]
172
- : [])
173
- ],
174
- nextActions: [
175
- 'Run peaks-prd handoff init to produce a sha256-locked handoff before running peaks security-audit.',
176
- 'Until the handoff exists, peaks-security-audit cannot start (gate fail).'
177
- ]
112
+ warnings: refusal.warnings,
113
+ nextActions: refusal.nextActions
178
114
  };
179
115
  }
180
116
  if (!templatePresent) {
@@ -225,90 +161,6 @@ export function detectSecurityAudit(input) {
225
161
  nextActions
226
162
  };
227
163
  }
228
- /**
229
- * Render a SecurityAuditEnvelope to the canonical audit artifact body
230
- * (markdown). Mirrors `adaptEccEnvelopeToRdCodeReview` in ecc-bridge.ts:
231
- * produce a markdown body with all required sections, ready to write
232
- * to `.peaks/_runtime/<sid>/audit/security-<rid>.md`.
233
- */
234
- export function renderSecurityAuditArtifact(env, opts) {
235
- const counts = {};
236
- for (const v of env.violations) {
237
- counts[v.severity] = (counts[v.severity] ?? 0) + 1;
238
- }
239
- const criticalCount = counts['CRITICAL'] ?? 0;
240
- const findingsBullets = env.violations.length === 0
241
- ? '- (none)'
242
- : env.violations
243
- .map((v) => `- [${v.severity}] ${v.dimension} @ ${v.file}:${v.line} — ${v.hint}`)
244
- .join('\n');
245
- const requiredFixes = buildRequiredFixes(env);
246
- const body = [
247
- '## Summary',
248
- '',
249
- env.summary,
250
- '',
251
- '## Threat model coverage',
252
- '',
253
- `audited at: ${opts.generatedAt}`,
254
- `verdict: ${env.verdict}`,
255
- `handoffHash: ${opts.handoffHash}`,
256
- '',
257
- '## Findings',
258
- '',
259
- findingsBullets,
260
- '',
261
- requiredFixes,
262
- '## Verdict',
263
- '',
264
- `verdict: ${env.verdict}`,
265
- `CRITICAL: ${criticalCount}`,
266
- ''
267
- ]
268
- .filter((s) => s.length > 0)
269
- .join('\n');
270
- return {
271
- body,
272
- violationsCount: env.violations.length,
273
- verdict: env.verdict
274
- };
275
- }
276
- function buildRequiredFixes(env) {
277
- const requiredFixes = env.violations.length === 0
278
- ? ''
279
- : [
280
- '## Required fixes',
281
- '',
282
- ...env.violations.map((v) => `- [${v.severity}] ${v.file}:${v.line} — ${v.hint}`),
283
- ''
284
- ].join('\n');
285
- return requiredFixes;
286
- }
287
- /**
288
- * Write the rendered audit artifact to
289
- * `.peaks/_runtime/<sid>/audit/security-<rid>.md`.
290
- *
291
- * Atomic write (tmp + rename) to avoid partial writes on crash.
292
- * Returns the absolute path on success.
293
- */
294
- export function writeSecurityAuditArtifact(projectRoot, sessionId, rid, body) {
295
- // The rid is a filename below, and the write is tmp+rename, so an
296
- // unvalidated rid can OVERWRITE an arbitrary `.md` rather than merely create
297
- // one. Guarded here (not only at the CLI boundary) so no caller can skip it.
298
- if (!REQUEST_ID_PATTERN.test(rid)) {
299
- throw new Error(`Invalid request id: ${rid} (expected letters, digits, dots, underscores, or dashes)`);
300
- }
301
- const targetDir = join(projectRoot, '.peaks', '_runtime', sessionId, 'audit');
302
- mkdirSync(targetDir, { recursive: true });
303
- const targetPath = join(targetDir, `security-${rid}.md`);
304
- // tmp + rename for atomicity
305
- const tmpPath = `${targetPath}.tmp`;
306
- writeFileSync(tmpPath, body, 'utf8');
307
- // Sync rename: on Windows, fs.renameSync overwrites if target exists (Node 22+)
308
- const { renameSync } = require('node:fs');
309
- renameSync(tmpPath, targetPath);
310
- return targetPath;
311
- }
312
164
  /**
313
165
  * Convenience: run `detectSecurityAudit` + `renderSecurityAuditArtifact`
314
166
  * + `writeSecurityAuditArtifact` in one call.
@@ -324,24 +176,28 @@ export function runSecurityAudit(input) {
324
176
  ...(input.dispatchError !== undefined ? { dispatchError: input.dispatchError } : {}),
325
177
  ...(input.envelope !== undefined ? { envelope: input.envelope } : {})
326
178
  });
327
- if (detect.state !== 'ready' || input.envelope === undefined) {
328
- return { detect, artifactPath: null, violationsCount: 0, verdict: null };
179
+ // The stamp is built inside the producer, before anything is written, so a
180
+ // caller that reaches the service alone still cannot leave an unstamped
181
+ // artifact behind. Folding its failure into the probe's own verdict keeps the
182
+ // refusal on this function's single early-return rather than a second one.
183
+ const built = buildJudgedDeclarationFor(input);
184
+ // A probe that is already refusing keeps its own diagnosis: the declaration
185
+ // is what this run would write, not what stopped it earlier.
186
+ const probe = built.ok || detect.state !== 'ready' ? detect : declarationMissingDetect(detect, built);
187
+ if (probe.state !== 'ready' || input.envelope === undefined || !built.ok) {
188
+ return { detect: probe, artifactPath: null, violationsCount: 0, verdict: null };
329
189
  }
330
- // detect.state === 'ready' implies input.envelope passed isSecurityAuditEnvelope.
190
+ // probe.state === 'ready' implies input.envelope passed isSecurityAuditEnvelope.
331
191
  const env = input.envelope;
332
- const handoffPath = resolveHandoffPath({
333
- projectRoot: input.projectRoot,
334
- sessionId: input.sessionId,
335
- requestId: input.rid
336
- });
337
- const verified = handoffPath === null ? null : readAndVerifyHandoff(handoffPath, input.projectRoot);
338
- const handoffHash = verified?.frontmatter.sha256 ?? 'unknown';
339
- const rendered = renderSecurityAuditArtifact(env, {
192
+ const renderOpts = {
340
193
  rid: input.rid,
341
- handoffHash,
194
+ handoffHash: built.handoffHash,
342
195
  generatedAt: input.generatedAt
343
- });
344
- const artifactPath = writeSecurityAuditArtifact(input.projectRoot, input.sessionId, input.rid, rendered.body);
196
+ };
197
+ const rendered = renderSecurityAuditArtifact(env, renderOpts);
198
+ const declared = built.declaration;
199
+ const body = `${rendered.body}\n${renderJudgedDeclaration(declared)}`;
200
+ const artifactPath = writeSecurityAuditArtifact(input.projectRoot, input.sessionId, input.rid, body);
345
201
  return {
346
202
  detect,
347
203
  artifactPath,
@@ -12,27 +12,49 @@ const FOUR_DIMENSIONS = [
12
12
  ];
13
13
  const FIFTH_DIMENSION = 'capability-consistency';
14
14
  /**
15
- * One oversized, omitted source that backs `dimension`. `omitted` + over-cap +
16
- * zero delivered bytes is the structural case: nothing can ever deliver it.
15
+ * An oversized source that backs `dimension`, in whichever of the two states
16
+ * the allocator can leave it.
17
+ *
18
+ * F3 (review 2026-10-13) — this used to build the omitted shape behind an
19
+ * `as unknown as CollectedEvidence` cast that omitted `excerpt`, so a `found`
20
+ * over-cap source built here would have been reported as "no deliverable
21
+ * source" while a cap-sized head of it had been inlined. The cast is gone and
22
+ * `excerpt` is declared, so the state the report distinguishes cannot be
23
+ * expressed wrongly from this helper.
17
24
  */
18
- function undeliverableSource(dimension, totalBytes) {
25
+ function overCapSource(dimension, totalBytes, inlined) {
19
26
  return {
20
27
  source: {
21
28
  key: `k-${dimension}`,
22
29
  label: dimension,
23
30
  segments: [`${dimension}.md`],
31
+ // The fixture deliberately fabricates dimension names (the fifth one is
32
+ // not a `DimensionKind`), so this ONE field is asserted, not inferred —
33
+ // the rest of the record is fully typed.
24
34
  supports: [dimension],
25
35
  delivery: { kind: 'whole' }
26
36
  },
27
37
  relativePath: `${dimension}.md`,
28
38
  absolutePath: `/nonexistent/${dimension}.md`,
29
- status: 'omitted',
39
+ status: inlined ? 'found' : 'omitted',
30
40
  totalBytes,
31
- includedBytes: 0,
32
- content: '',
33
- reason: 'over-cap'
41
+ includedBytes: inlined ? MAX_EVIDENCE_BYTES_PER_FILE : 0,
42
+ excerpt: inlined,
43
+ content: inlined ? 'x'.repeat(MAX_EVIDENCE_BYTES_PER_FILE) : '',
44
+ reason: inlined ? '' : 'over-cap'
34
45
  };
35
46
  }
47
+ /**
48
+ * One oversized, omitted source that backs `dimension`. `omitted` + over-cap +
49
+ * zero delivered bytes is the structural case: nothing can ever deliver it.
50
+ */
51
+ function undeliverableSource(dimension, totalBytes) {
52
+ return overCapSource(dimension, totalBytes, false);
53
+ }
54
+ /** `dimension=excerpt|silent` per entry — what the report says ARRIVED. */
55
+ function excerptState(report) {
56
+ return report.map((r) => `${r.dimension}=${r.excerptDelivered ? 'excerpt' : 'silent'}`).join(',');
57
+ }
36
58
  function reviewJson(dimensions) {
37
59
  return JSON.stringify({
38
60
  rid: 'J05-fixture',
@@ -112,22 +134,46 @@ function probeOutputBudget() {
112
134
  }
113
135
  return { floor, ceiling, badOverrideThrows };
114
136
  }
137
+ /**
138
+ * The over-cap evidence states, as probes.
139
+ *
140
+ * F3 (review 2026-10-13) is the pair that matters: the SAME oversized source,
141
+ * once inlined and once not, has to be reported as two DIFFERENT things. Both
142
+ * are driven here so the report cannot answer "nothing arrived" about a source
143
+ * whose cap-sized head is in the reviewer's prompt.
144
+ *
145
+ * Extracted from `runJ05Contract` so that function stays inside the
146
+ * function-length rule.
147
+ */
148
+ function overCapEvidenceProbes() {
149
+ const reported = undeliverableDimensions(FOUR_DIMENSIONS.map((d) => undeliverableSource(d, MAX_EVIDENCE_BYTES_PER_FILE + 1000)));
150
+ const dimensions = reported.map((r) => r.dimension);
151
+ const fifthOnly = undeliverableDimensions([
152
+ undeliverableSource(FIFTH_DIMENSION, MAX_EVIDENCE_BYTES_PER_FILE + 1000)
153
+ ]);
154
+ const excerptOnly = undeliverableDimensions([
155
+ overCapSource(FOUR_DIMENSIONS[0], MAX_EVIDENCE_BYTES_PER_FILE + 1000, true)
156
+ ]);
157
+ return [
158
+ probe(dimensions.length === FOUR_DIMENSIONS.length &&
159
+ FOUR_DIMENSIONS.every((d) => dimensions.includes(d)), `the canonical dimension set is exactly the four baseline dimensions (reported: ${dimensions.join(',') || 'none'})`),
160
+ probe(fifthOnly.length === 0, `the fifth dimension is not part of the required set (reported: ${fifthOnly.length})`),
161
+ probe(excerptOnly.length === 1 &&
162
+ excerptOnly[0]?.excerptDelivered === true &&
163
+ excerptOnly[0]?.sources[0]?.excerptBytes === MAX_EVIDENCE_BYTES_PER_FILE, `an over-cap source that WAS inlined is reported as an excerpt, not as nothing arrived (reported: ${excerptState(excerptOnly)})`),
164
+ probe(reported.length === FOUR_DIMENSIONS.length && reported.every((r) => !r.excerptDelivered), `an over-cap source that was NOT inlined is reported as nothing arrived (reported: ${excerptState(reported)})`)
165
+ ];
166
+ }
115
167
  export async function runJ05Contract(ctx) {
116
168
  const row = requireBaselineRow(ctx);
117
169
  const missing = missingSourceFiles(ctx, row);
118
170
  const prepared = await probePrepareFinalReview();
119
- const oversized = FOUR_DIMENSIONS.map((d) => undeliverableSource(d, MAX_EVIDENCE_BYTES_PER_FILE + 1000));
120
- const reported = undeliverableDimensions(oversized).map((r) => r.dimension);
121
- const fifthOnly = undeliverableDimensions([
122
- undeliverableSource(FIFTH_DIMENSION, MAX_EVIDENCE_BYTES_PER_FILE + 1000)
123
- ]);
124
171
  const { floor, ceiling, badOverrideThrows } = probeOutputBudget();
125
172
  const result = combineProbes([
126
173
  probe(missing.length === 0, `baseline sourceFiles present (${row.sourceFiles.length})`),
127
174
  probe(prepared.rejected, `a three-dimension review is refused (${prepared.detail})`),
128
175
  probe(prepared.accepted, `a four-dimension review is accepted (${prepared.detail})`),
129
- probe(reported.length === 4 && FOUR_DIMENSIONS.every((d) => reported.includes(d)), `the canonical dimension set is exactly the four baseline dimensions (reported: ${reported.join(',') || 'none'})`),
130
- probe(fifthOnly.length === 0, `the fifth dimension is not part of the required set (reported: ${fifthOnly.length})`),
176
+ ...overCapEvidenceProbes(),
131
177
  probe(MAX_EVIDENCE_BYTES_PER_FILE === 10240, `per-file evidence cap divides the total by four (${String(MAX_EVIDENCE_BYTES_PER_FILE)})`),
132
178
  probe(floor === 15288 && ceiling === 32000, `output budget is clamped on both ends (${String(floor)} / ${String(ceiling)})`),
133
179
  probe(badOverrideThrows, 'a non-integer budget override throws instead of falling back silently')
@@ -249,6 +249,8 @@ let cachedUpstreamGrammars = null;
249
249
  */
250
250
  function loadUpstreamGrammars() {
251
251
  if (cachedUpstreamGrammars === null) {
252
+ // Deliberate, and not a missed ESM conversion: `grammarsPath` is computed
253
+ // at runtime, which no static `import` can express — see the ESM guard.
252
254
  const require = createRequire(import.meta.url);
253
255
  const { moduleDir } = resolveCodegraphUpstreamLayout();
254
256
  const grammarsPath = join(moduleDir, 'extraction', 'grammars.js');
@@ -95,10 +95,10 @@ export interface DispatchPromptInput {
95
95
  * reuse the task body verbatim).
96
96
  * trivially testable.
97
97
  *
98
- * fallback path is `peaks worktree auth grant --rid <id> --reason <text>
99
- * --ttl <5m>` (already shipped). Update the prose once `spawn` lands.
98
+ * fallback path is the command the auth-grant CLI declares:
99
+ * `peaks worktree auth grant --operation <op> --reason <text>`.
100
100
  */
101
- export declare const L1_WORKTREE_GOVERNANCE_BLOCK = "## Superpowers chain refusal (L1 worktree governance \u2014 locked 2026-07-29)\n\nYou MUST NOT follow the superpowers chain for worktree decisions:\n\n- superpowers:brainstorming \u2192 superpowers:writing-plans \u2192\n superpowers:subagent-driven-development \u2192 superpowers:using-git-worktrees\n\nThat chain ends with `git worktree add` (superpowers:using-git-worktrees SKILL.md line 96), which bypasses peaks-loop's L2 hook gate and L3 IDE `permissions.deny`. L3 denial is NOT sufficient \u2014 by then the chain has already taught raw `git worktree add`.\n\nFor worktree operations, use ONLY:\n\n- `peaks worktree spawn --rid <rid> --ttl <duration> --purpose <text>` (after rid-L2-extended ships)\n- until then: `peaks worktree auth grant --rid <id> --reason <text> --ttl <5m>`\n\nSuperpowers skills remain REFERENCE material for brainstorming / planning techniques, but MUST NOT be used as a workflow. peaks-rd's own PRD/RD artifacts (`.peaks/_runtime/<sessionId>/rd/requests/<rid>.md`) are authoritative.\n\nIf the upstream superpowers chain suggests raw `git worktree add`:\n\n1. STOP\n2. Re-author the plan as a peaks-rd artifact\n3. Continue with `peaks worktree spawn` (or the auth-grant fallback)\n";
101
+ export declare const L1_WORKTREE_GOVERNANCE_BLOCK = "## Superpowers chain refusal (L1 worktree governance \u2014 locked 2026-07-29)\n\nYou MUST NOT follow the superpowers chain for worktree decisions:\n\n- superpowers:brainstorming \u2192 superpowers:writing-plans \u2192\n superpowers:subagent-driven-development \u2192 superpowers:using-git-worktrees\n\nThat chain ends with `git worktree add` (superpowers:using-git-worktrees SKILL.md line 96), which bypasses peaks-loop's L2 hook gate and L3 IDE `permissions.deny`. L3 denial is NOT sufficient \u2014 by then the chain has already taught raw `git worktree add`.\n\nFor worktree operations, use ONLY:\n\n- `peaks worktree spawn --rid <rid> --role <role> --purpose <text>` (after rid-L2-extended ships)\n- until then: `peaks worktree auth grant --operation <op> --reason <text>` (`<op>`, e.g. `git-worktree` | `agent-isolation-worktree`)\n\nSuperpowers skills remain REFERENCE material for brainstorming / planning techniques, but MUST NOT be used as a workflow. peaks-rd's own PRD/RD artifacts (`.peaks/_runtime/<sessionId>/rd/requests/<rid>.md`) are authoritative.\n\nIf the upstream superpowers chain suggests raw `git worktree add`:\n\n1. STOP\n2. Re-author the plan as a peaks-rd artifact\n3. Continue with the `spawn` command above (or the auth-grant fallback)\n";
102
102
  /**
103
103
  * system prompt gains three lifecycle rules. The sub-agent must:
104
104
  *
@@ -208,15 +208,11 @@ export declare const CODEGRAPH_UNAVAILABLE_BLOCK: string;
208
208
  /** Binding phrases every dispatch prompt must contain, for every role. */
209
209
  export declare const BINDING_RULE_TOKENS: readonly string[];
210
210
  /**
211
- * The runner-direct-path tokens: the refusal example, the two direct paths
212
- * the block names (`peaks test --json` to introspect; PB-5, the repo-defined
213
- * `test` / `test:*` scripts that are NOT gated), and the two pieces of
214
- * quality guidance that must survive any compression — never assume a
215
- * runner without asking the user as a last resort, and prefer
216
- * `peaks test <file>` because it resolves the local binary Windows-aware.
217
- *
218
- * so this set is asserted IDENTICALLY for every role. The runner EXAMPLES
219
- * were removed as part of the unification — they were never rules.
211
+ * The runner-direct-path tokens: the scope requirement; the whole-tree tier by ALL THREE of its
212
+ * members (both guard directories and the root selector); the PRINCIPLE they are the mechanism
213
+ * for; the two direct paths the block names (`peaks test --json` to introspect, PB-5 = the
214
+ * repo-defined `test` / `test:*` scripts that are NOT gated); and the quality guidance that must
215
+ * survive compression — never assume a runner without asking; prefer `peaks test <file>`.
220
216
  */
221
217
  export declare const TEST_RUNNER_RULE_TOKENS: readonly string[];
222
218
  /**
@@ -16,8 +16,8 @@ import { resolveCodegraphBlock } from './codegraph-unavailable-block.js';
16
16
  * reuse the task body verbatim).
17
17
  * trivially testable.
18
18
  *
19
- * fallback path is `peaks worktree auth grant --rid <id> --reason <text>
20
- * --ttl <5m>` (already shipped). Update the prose once `spawn` lands.
19
+ * fallback path is the command the auth-grant CLI declares:
20
+ * `peaks worktree auth grant --operation <op> --reason <text>`.
21
21
  */
22
22
  export const L1_WORKTREE_GOVERNANCE_BLOCK = `## Superpowers chain refusal (L1 worktree governance — locked 2026-07-29)
23
23
 
@@ -30,8 +30,8 @@ That chain ends with \`git worktree add\` (superpowers:using-git-worktrees SKILL
30
30
 
31
31
  For worktree operations, use ONLY:
32
32
 
33
- - \`peaks worktree spawn --rid <rid> --ttl <duration> --purpose <text>\` (after rid-L2-extended ships)
34
- - until then: \`peaks worktree auth grant --rid <id> --reason <text> --ttl <5m>\`
33
+ - \`peaks worktree spawn --rid <rid> --role <role> --purpose <text>\` (after rid-L2-extended ships)
34
+ - until then: \`peaks worktree auth grant --operation <op> --reason <text>\` (\`<op>\`, e.g. \`git-worktree\` | \`agent-isolation-worktree\`)
35
35
 
36
36
  Superpowers skills remain REFERENCE material for brainstorming / planning techniques, but MUST NOT be used as a workflow. peaks-rd's own PRD/RD artifacts (\`.peaks/_runtime/<sessionId>/rd/requests/<rid>.md\`) are authoritative.
37
37
 
@@ -39,7 +39,7 @@ If the upstream superpowers chain suggests raw \`git worktree add\`:
39
39
 
40
40
  1. STOP
41
41
  2. Re-author the plan as a peaks-rd artifact
42
- 3. Continue with \`peaks worktree spawn\` (or the auth-grant fallback)
42
+ 3. Continue with the \`spawn\` command above (or the auth-grant fallback)
43
43
  `;
44
44
  /**
45
45
  * system prompt gains three lifecycle rules. The sub-agent must:
@@ -300,8 +300,8 @@ export const BINDING_RULE_TOKENS = [
300
300
  'MUST NOT follow the superpowers chain',
301
301
  'superpowers:using-git-worktrees',
302
302
  '`git worktree add`',
303
- '`peaks worktree spawn --rid <rid> --ttl <duration> --purpose <text>`',
304
- '`peaks worktree auth grant --rid <id> --reason <text> --ttl <5m>`',
303
+ '`peaks worktree spawn --rid <rid> --role <role> --purpose <text>`',
304
+ '`peaks worktree auth grant --operation <op> --reason <text>`',
305
305
  'MUST NOT be used as a workflow',
306
306
  'STOP',
307
307
  'Re-author the plan as a peaks-rd artifact',
@@ -334,25 +334,25 @@ export const BINDING_RULE_TOKENS = [
334
334
  'do NOT invoke `npx <runner>`',
335
335
  '## Test Scope (mandatory)',
336
336
  'PEAKS_FULL_TEST=1',
337
- 'refused'
337
+ 'not permitted'
338
338
  ];
339
339
  /**
340
- * The runner-direct-path tokens: the refusal example, the two direct paths
341
- * the block names (`peaks test --json` to introspect; PB-5, the repo-defined
342
- * `test` / `test:*` scripts that are NOT gated), and the two pieces of
343
- * quality guidance that must survive any compression — never assume a
344
- * runner without asking the user as a last resort, and prefer
345
- * `peaks test <file>` because it resolves the local binary Windows-aware.
346
- *
347
- * so this set is asserted IDENTICALLY for every role. The runner EXAMPLES
348
- * were removed as part of the unification — they were never rules.
340
+ * The runner-direct-path tokens: the scope requirement; the whole-tree tier by ALL THREE of its
341
+ * members (both guard directories and the root selector); the PRINCIPLE they are the mechanism
342
+ * for; the two direct paths the block names (`peaks test --json` to introspect, PB-5 = the
343
+ * repo-defined `test` / `test:*` scripts that are NOT gated); and the quality guidance that must
344
+ * survive compression — never assume a runner without asking; prefer `peaks test <file>`.
349
345
  */
350
346
  export const TEST_RUNNER_RULE_TOKENS = [
351
347
  '`./node_modules/.bin/vitest run`',
352
348
  'PB-5',
353
349
  '`peaks test --json`',
354
350
  'ask the user before assuming a runner',
355
- '(Windows-aware)'
351
+ '(Windows-aware)',
352
+ 'subject is the tree, not one file, is in scope for every slice',
353
+ '`tests/unit/standards`',
354
+ '`tests/unit/lint`',
355
+ '`tests/unit/*.test.ts`'
356
356
  ];
357
357
  /**
358
358
  * Return the subset of `tokens` that `text` does NOT contain. Pure; used by
@@ -45,7 +45,11 @@ async function scanFiles(root, exclude) {
45
45
  const s = await stat(full);
46
46
  out.push({
47
47
  path: rel,
48
- kind: classifyKind(relative(root, full)),
48
+ // `rel`, not a second `relative()` call: the raw value is
49
+ // `\`-separated on win32 and `classifyKind` tests for `/__tests__/`,
50
+ // so the nested-test branch could never match on the platform it was
51
+ // written on. The normalised value is the one computed above.
52
+ kind: classifyKind(rel),
49
53
  lines: 0, // computed lazily; full line count is expensive
50
54
  hash: '' // computed lazily via content-hash-cache-pattern
51
55
  });
@@ -108,7 +108,7 @@ export const POST_COMPACT_REINJECTION_BYTE_BUDGET = 3072;
108
108
  */
109
109
  export const AGENT_RUNTIME_RULES = Object.freeze([
110
110
  'CLI: run `node --import tsx src/cli/index.ts <cmd>`, never `pnpm exec tsx` — on Windows the latter truncates any argument at its first newline.',
111
- 'Test scope: one file or pattern per run; the full suite requires PEAKS_FULL_TEST=1.',
111
+ 'Test scope: one file or pattern per run; the full suite requires PEAKS_FULL_TEST=1; a slice also runs the whole-tree tier tests/unit/standards + tests/unit/lint + the root of tests/unit/ (tests/unit/*.test.ts).',
112
112
  "Exit codes: never read a test result through a pipe (`| tail` reports tail's status); read ${PIPESTATUS[0]}.",
113
113
  'Never write `.claude/settings.local.json` from a slice — reproduce against a temp project copy via `--project <tmpdir>`.',
114
114
  'Git: commit / push policy is per-dispatch and is NOT inherited from this card — re-read the dispatch record before any state-mutating git command.',
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Active-dispatches index. Per-session JSON file at
3
+ * `.peaks/_sub_agents/<sid>/active-dispatches.json`. Map<recordPath,
4
+ * ActiveDispatchEntry>. Updated on dispatch + completion.
5
+ */
6
+ export interface ActiveDispatchEntry {
7
+ readonly recordPath: string;
8
+ readonly requestId: string;
9
+ readonly role: string;
10
+ readonly batchId: string;
11
+ readonly createdAt: string;
12
+ readonly status: 'queued' | 'running' | 'finalizing' | 'done' | 'failed' | 'cancelled' | 'stale' | 'no-execution' | 'never-started' | 'unreadable';
13
+ }
14
+ export declare function activeDispatchIndexPath(projectRoot: string, sessionId: string): string;
15
+ export declare function registerActiveDispatch(input: {
16
+ projectRoot: string;
17
+ sessionId: string;
18
+ recordPath: string;
19
+ requestId: string;
20
+ role: string;
21
+ batchId: string;
22
+ now: () => Date;
23
+ }): void;
24
+ export declare function unregisterActiveDispatch(input: {
25
+ projectRoot: string;
26
+ sessionId: string;
27
+ recordPath: string;
28
+ status: ActiveDispatchEntry['status'];
29
+ }): void;
30
+ /**
31
+ * for a session. Returns the current map<recordPath, entry>. Used
32
+ * by the LLM-side runner to discover in-flight records on restart.
33
+ * Returns an empty map when the index file is missing or corrupt
34
+ * (the on-disk records directory is the next fallback).
35
+ */
36
+ export declare function readActiveDispatchIndex(projectRoot: string, sessionId: string): Record<string, ActiveDispatchEntry>;