@event4u/agent-config 9.25.0 → 9.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +58 -143
  3. package/README.md +1 -1
  4. package/dist/agent-src/commands/analyze/conformance.md +21 -2
  5. package/dist/agent-src/commands/review/changes.md +6 -5
  6. package/dist/agent-src/commands/roadmap/next.md +256 -0
  7. package/dist/agent-src/commands/roadmap.md +12 -4
  8. package/dist/agent-src/contexts/execution/subagent-routing.md +4 -1
  9. package/dist/agent-src/rules/active-remediation.md +2 -0
  10. package/dist/agent-src/rules/analysis-skill-routing.md +2 -0
  11. package/dist/agent-src/rules/architecture.md +2 -0
  12. package/dist/agent-src/rules/artifact-drafting-protocol.md +2 -0
  13. package/dist/agent-src/rules/artifact-engagement-recording.md +2 -0
  14. package/dist/agent-src/rules/augment-edit-discipline.md +2 -0
  15. package/dist/agent-src/rules/autonomous-execution.md +2 -0
  16. package/dist/agent-src/rules/brand-consistency.md +2 -0
  17. package/dist/agent-src/rules/brand-source-of-truth.md +2 -0
  18. package/dist/agent-src/rules/broken-access-control.md +2 -0
  19. package/dist/agent-src/rules/cli-output-handling.md +2 -0
  20. package/dist/agent-src/rules/code-comment-discipline.md +2 -0
  21. package/dist/agent-src/rules/code-provenance.md +2 -0
  22. package/dist/agent-src/rules/command-suggestion-policy.md +2 -0
  23. package/dist/agent-src/rules/commit-conventions.md +2 -0
  24. package/dist/agent-src/rules/communication-through-line.md +2 -0
  25. package/dist/agent-src/rules/content-quoting-floor.md +2 -0
  26. package/dist/agent-src/rules/context-hygiene.md +10 -0
  27. package/dist/agent-src/rules/copilot-routing.md +2 -0
  28. package/dist/agent-src/rules/cross-source-consistency.md +2 -0
  29. package/dist/agent-src/rules/decision-revisit-gate.md +2 -0
  30. package/dist/agent-src/rules/delegation-policy.md +5 -2
  31. package/dist/agent-src/rules/design-fidelity.md +19 -1
  32. package/dist/agent-src/rules/design-review-after-ui-write.md +120 -0
  33. package/dist/agent-src/rules/devcontainer-routing.md +2 -0
  34. package/dist/agent-src/rules/doc-screenshot-hygiene.md +2 -0
  35. package/dist/agent-src/rules/docker-commands.md +2 -0
  36. package/dist/agent-src/rules/domain-adoption-policy.md +2 -0
  37. package/dist/agent-src/rules/domain-safety-disclaimer.md +2 -0
  38. package/dist/agent-src/rules/domain-safety-pii.md +2 -0
  39. package/dist/agent-src/rules/domain-safety-retention.md +2 -0
  40. package/dist/agent-src/rules/downstream-changes.md +2 -0
  41. package/dist/agent-src/rules/engineering-safety-floor.md +2 -0
  42. package/dist/agent-src/rules/evaluator-independence.md +19 -3
  43. package/dist/agent-src/rules/external-code-graph-interop.md +2 -0
  44. package/dist/agent-src/rules/external-reference-deep-dive.md +2 -0
  45. package/dist/agent-src/rules/fast-path-marker-visibility.md +2 -0
  46. package/dist/agent-src/rules/finance-safety-floor.md +2 -0
  47. package/dist/agent-src/rules/framework-neutrality-in-generic-skills.md +2 -0
  48. package/dist/agent-src/rules/git-history-discipline.md +3 -1
  49. package/dist/agent-src/rules/guidelines.md +2 -0
  50. package/dist/agent-src/rules/history-discipline.md +2 -0
  51. package/dist/agent-src/rules/icon-consistency.md +2 -0
  52. package/dist/agent-src/rules/image-likeness-and-rights.md +2 -0
  53. package/dist/agent-src/rules/improve-before-implement.md +2 -0
  54. package/dist/agent-src/rules/invite-challenge.md +2 -0
  55. package/dist/agent-src/rules/laravel-routing.md +2 -0
  56. package/dist/agent-src/rules/laravel-translations.md +2 -0
  57. package/dist/agent-src/rules/legal-safety-floor.md +2 -0
  58. package/dist/agent-src/rules/lethal-trifecta-guard.md +2 -0
  59. package/dist/agent-src/rules/linked-projects-onboarding-gate.md +2 -0
  60. package/dist/agent-src/rules/low-impact-corpus-privacy-floor.md +2 -0
  61. package/dist/agent-src/rules/markdown-safe-codeblocks.md +2 -0
  62. package/dist/agent-src/rules/media-governance-routing.md +2 -0
  63. package/dist/agent-src/rules/media-sync-ground-truth.md +2 -0
  64. package/dist/agent-src/rules/minimal-safe-diff.md +2 -0
  65. package/dist/agent-src/rules/missing-tool-handling.md +2 -0
  66. package/dist/agent-src/rules/model-recommendation.md +2 -0
  67. package/dist/agent-src/rules/no-attribution-footers.md +2 -0
  68. package/dist/agent-src/rules/no-decorative-emojis-in-git-surfaces.md +2 -0
  69. package/dist/agent-src/rules/no-pr-progress-comments.md +2 -0
  70. package/dist/agent-src/rules/no-roadmap-references.md +2 -0
  71. package/dist/agent-src/rules/notes-first-reasoning.md +2 -0
  72. package/dist/agent-src/rules/onboarding-gate.md +2 -0
  73. package/dist/agent-src/rules/output-discipline.md +2 -0
  74. package/dist/agent-src/rules/package-ci-checks.md +2 -0
  75. package/dist/agent-src/rules/persona-governance.md +2 -0
  76. package/dist/agent-src/rules/php-coding.md +2 -0
  77. package/dist/agent-src/rules/prefer-enums-over-literals.md +2 -0
  78. package/dist/agent-src/rules/preservation-guard.md +2 -0
  79. package/dist/agent-src/rules/provider-lifecycle-discipline.md +2 -0
  80. package/dist/agent-src/rules/question-not-instruction.md +2 -0
  81. package/dist/agent-src/rules/reviewer-awareness.md +2 -0
  82. package/dist/agent-src/rules/roadmap-ci-steps-policy.md +2 -0
  83. package/dist/agent-src/rules/roadmap-progress-sync.md +2 -0
  84. package/dist/agent-src/rules/role-mode-adherence.md +2 -0
  85. package/dist/agent-src/rules/rule-type-governance.md +2 -0
  86. package/dist/agent-src/rules/runtime-safety.md +2 -0
  87. package/dist/agent-src/rules/scale-discipline.md +2 -0
  88. package/dist/agent-src/rules/secret-vcs-guard.md +2 -0
  89. package/dist/agent-src/rules/security-sensitive-stop.md +2 -0
  90. package/dist/agent-src/rules/senior-engineering-discipline.md +2 -0
  91. package/dist/agent-src/rules/session-canary.md +63 -19
  92. package/dist/agent-src/rules/settings-ask-protocol.md +180 -0
  93. package/dist/agent-src/rules/size-enforcement.md +2 -0
  94. package/dist/agent-src/rules/skill-improvement-trigger.md +2 -0
  95. package/dist/agent-src/rules/skill-quality.md +2 -0
  96. package/dist/agent-src/rules/slash-command-routing-policy.md +2 -0
  97. package/dist/agent-src/rules/source-confidentiality.md +2 -0
  98. package/dist/agent-src/rules/source-discovery-gate.md +2 -0
  99. package/dist/agent-src/rules/source-of-truth.md +2 -0
  100. package/dist/agent-src/rules/spreadsheet-source-quality.md +2 -0
  101. package/dist/agent-src/rules/strategy-safety-floor.md +2 -0
  102. package/dist/agent-src/rules/symfony-routing.md +2 -0
  103. package/dist/agent-src/rules/think-before-action.md +2 -0
  104. package/dist/agent-src/rules/token-budget-discipline.md +8 -3
  105. package/dist/agent-src/rules/token-efficiency.md +2 -0
  106. package/dist/agent-src/rules/token-optimizer-maintenance.md +2 -0
  107. package/dist/agent-src/rules/tool-safety.md +2 -0
  108. package/dist/agent-src/rules/ui-audit-gate.md +7 -0
  109. package/dist/agent-src/rules/untrusted-input-defense.md +2 -0
  110. package/dist/agent-src/rules/upstream-proposal.md +2 -0
  111. package/dist/agent-src/rules/user-interaction.md +5 -2
  112. package/dist/agent-src/rules/user-interrupt-priority.md +2 -0
  113. package/dist/agent-src/skills/recursive-verification/SKILL.md +13 -0
  114. package/dist/agent-src/templates/agents/agent-project-settings.example.yml +1 -1
  115. package/dist/cli/registry.js +2 -0
  116. package/dist/cli/registry.js.map +1 -1
  117. package/dist/cli-delegate/{chunk-SJQMJI7M.js → chunk-3KJIMFTB.js} +1 -1
  118. package/dist/cli-delegate/{chunk-BSLUHV2F.js → chunk-BCPIOAGV.js} +148 -133
  119. package/dist/cli-delegate/cmd_conformance.js +1 -1
  120. package/dist/cli-delegate/cmd_doctor.js +1 -1
  121. package/dist/cli-delegate/cmd_export.js +1 -1
  122. package/dist/cli-delegate/cmd_prune.js +1 -1
  123. package/dist/cli-delegate/cmd_route_audit.js +4 -1
  124. package/dist/cli-delegate/cmd_route_explain.js +4 -1
  125. package/dist/cli-delegate/cmd_settings_migrate.js +1 -1
  126. package/dist/cli-delegate/cmd_sync.js +1 -1
  127. package/dist/cli-delegate/cmd_uninstall.js +1 -1
  128. package/dist/cli-delegate/cmd_validate.js +1 -1
  129. package/dist/discovery/deprecation-report.md +1 -1
  130. package/dist/discovery/discovery-manifest.json +191 -120
  131. package/dist/discovery/discovery-manifest.json.sha256 +1 -1
  132. package/dist/discovery/discovery-manifest.summary.md +4 -4
  133. package/dist/discovery/orphan-report.md +1 -1
  134. package/dist/discovery/packs.json +11 -8
  135. package/dist/discovery/trust-report.md +3 -3
  136. package/dist/discovery/workspaces.json +9 -6
  137. package/dist/hooks/dispatch.js +1148 -349
  138. package/dist/install/install.mjs +1 -1
  139. package/dist/mcp/registry-manifest.json +3 -3
  140. package/dist/mcp/server.json +2 -2
  141. package/dist/mcp/server.mjs +571 -417
  142. package/dist/router.json +1 -1
  143. package/dist/scripts/condense.js +33 -2
  144. package/dist/scripts/condense.js.map +1 -1
  145. package/dist/server/io/yamlIO.js +85 -0
  146. package/dist/server/io/yamlIO.js.map +1 -1
  147. package/dist/server/nicknameResolver.js +116 -0
  148. package/dist/server/nicknameResolver.js.map +1 -0
  149. package/dist/server/routes/ping.js +29 -11
  150. package/dist/server/routes/ping.js.map +1 -1
  151. package/dist/server/routes/settings.js +1 -12
  152. package/dist/server/routes/settings.js.map +1 -1
  153. package/dist/server/routes/wizard.js +52 -2
  154. package/dist/server/routes/wizard.js.map +1 -1
  155. package/dist/shared/interactiveContext.js +73 -0
  156. package/dist/shared/interactiveContext.js.map +1 -0
  157. package/dist/shared/nicknamePrefill.js +59 -0
  158. package/dist/shared/nicknamePrefill.js.map +1 -0
  159. package/dist/shared/settingsAsks.js +128 -0
  160. package/dist/shared/settingsAsks.js.map +1 -0
  161. package/dist/shared/settingsCarveOut.js +118 -0
  162. package/dist/shared/settingsCarveOut.js.map +1 -0
  163. package/dist/shared/settingsConsent.js +93 -0
  164. package/dist/shared/settingsConsent.js.map +1 -0
  165. package/dist/shared/settingsSurface.js +7 -1
  166. package/dist/shared/settingsSurface.js.map +1 -1
  167. package/dist/ui/assets/index-DmR0mbk4.js.map +1 -1
  168. package/package.json +1 -1
  169. package/src/config/agents-paths.yml +15 -0
  170. package/src/config/evaluator-budgets.json +4 -4
  171. package/src/config/gate-coverage.yml +29 -1
  172. package/src/config/gate-violation-baselines.json +13 -7
  173. package/src/scripts/_cli/cmd_doctor.ts +6 -21
  174. package/src/scripts/_cli/cmd_route_audit.ts +4 -1
  175. package/src/scripts/_cli/cmd_route_explain.ts +9 -1
  176. package/src/scripts/_dispatch.bash +18 -0
  177. package/src/scripts/_lib/git_common_dir.ts +128 -0
  178. package/src/scripts/_lib/obligation_frequency.ts +391 -0
  179. package/src/scripts/_lib/session_register.ts +361 -0
  180. package/src/scripts/ai-video/stitch.sh +27 -9
  181. package/src/scripts/before_complete_hook.ts +23 -4
  182. package/src/scripts/bench_ab_v2_run.ts +272 -16
  183. package/src/scripts/bench_ab_v2_stats.ts +156 -3
  184. package/src/scripts/check_completion_review.ts +80 -3
  185. package/src/scripts/check_corpus_staleness.ts +692 -0
  186. package/src/scripts/check_enforcement_coverage.ts +192 -7
  187. package/src/scripts/check_gate_coverage.ts +67 -0
  188. package/src/scripts/check_hook_bundle_freshness.ts +183 -0
  189. package/src/scripts/check_rule_projection_integrity.ts +364 -0
  190. package/src/scripts/condense.ts +36 -2
  191. package/src/scripts/conformance_scan.ts +82 -17
  192. package/src/scripts/dispatch_r2_reviewer.ts +31 -2
  193. package/src/scripts/generate_settings_reference.ts +232 -0
  194. package/src/scripts/git_authorization_hook.ts +75 -10
  195. package/src/scripts/hook_manifest.yaml +87 -27
  196. package/src/scripts/hooks/block_no_verify.ts +59 -2
  197. package/src/scripts/hooks/block_unauthorized_git.ts +199 -16
  198. package/src/scripts/hooks/concern_registry.ts +2 -0
  199. package/src/scripts/hooks/design_slop_hook.ts +13 -1
  200. package/src/scripts/hooks/dispatch_hook.ts +97 -2
  201. package/src/scripts/hooks/evidence_independence.ts +40 -6
  202. package/src/scripts/language_mirror_hook.ts +256 -17
  203. package/src/scripts/lint_abstraction_thresholds.ts +41 -8
  204. package/src/scripts/lint_agents_layout.ts +2 -0
  205. package/src/scripts/lint_hook_manifest.ts +29 -0
  206. package/src/scripts/memory_learn_hook.ts +109 -6
  207. package/src/scripts/orchestration_backfill.ts +354 -0
  208. package/src/scripts/pr_url_reminder_hook.ts +17 -2
  209. package/src/scripts/release.ts +180 -37
  210. package/src/scripts/schemas/review-findings.schema.json +99 -0
  211. package/src/scripts/schemas/rule.schema.json +5 -0
  212. package/src/scripts/session_canary_hook.ts +35 -3
  213. package/src/scripts/session_register_hook.ts +288 -0
  214. package/src/scripts/sessions_cli.ts +140 -0
  215. package/src/scripts/validate_frontmatter.ts +68 -0
  216. package/src/server/io/yamlIO.ts +87 -0
  217. package/src/shared/interactiveContext.ts +98 -0
  218. package/src/shared/nicknamePrefill.ts +96 -0
  219. package/src/shared/settingsAsks.ts +176 -0
  220. package/src/shared/settingsCarveOut.ts +143 -0
  221. package/src/shared/settingsConsent.ts +136 -0
  222. package/src/shared/settingsSurface.ts +7 -1
@@ -0,0 +1,391 @@
1
+ /**
2
+ * Obligation frequency, carrier frequency, and the coverage lattice between them.
3
+ *
4
+ * `enforced_by` answers *does something carry this rule*. It does not answer
5
+ * *does it carry it often enough*, and the difference is not academic:
6
+ * `session-canary` declares `hook:session-canary`, the hook exists, is wired and
7
+ * fires — so the coverage instrument counts the rule as enforced — while the hook
8
+ * sits in the `session_start` slot and the rule's obligation is per task. The
9
+ * rule's own 30-session audit measured the opening canary dropped on ~13 of 15
10
+ * task starts. Enforced on paper, broken in fact.
11
+ *
12
+ * This module supplies the missing half: a declared obligation period per rule
13
+ * (frontmatter `obligation_frequency`), a carrier period resolved per slot AND
14
+ * per platform, and a `covers()` relation that is honest about the two ways the
15
+ * intuitive linear ordering produces FALSE GREENS.
16
+ *
17
+ * ## The value set is a forest, not a chain
18
+ *
19
+ * Four roots. A carrier in one root never covers an obligation in another:
20
+ *
21
+ * lifecycle per-turn ⊃ per-task ⊃ per-session
22
+ * tool-call per-edit ⊃ per-file-write
23
+ * repository per-commit
24
+ * external-event per-event
25
+ *
26
+ * Two corrections that a magnitude-ordered chain would get wrong:
27
+ *
28
+ * - `per-edit` and `per-turn` are INCOMPARABLE. `pre_tool_use`/`post_tool_use`
29
+ * fire per tool call, so a plain conversational reply fires them zero times.
30
+ * A per-turn obligation carried only by a per-edit hook is uncovered on
31
+ * exactly those turns — and a chain would paint that green.
32
+ * - `per-event` is a SEPARATE ROOT, not the bottom of the lifecycle chain. An
33
+ * external event fires on its own clock: a CI gate firing three times inside
34
+ * one session is not covered by a `session_start` check, yet a chain with
35
+ * `per-event` at the bottom would accept the session-scoped carrier as
36
+ * dominating it and report green.
37
+ *
38
+ * ## Point carriers vs sweep carriers — the third correction
39
+ *
40
+ * The forest rule above is stated for carriers that fire AT an event and see
41
+ * only that event: a hook. A CI validator is not that shape. It fires once per
42
+ * commit and inspects the whole tree, so it catches every edit inside the commit
43
+ * regardless of how many there were. Treating it as a `per-commit` point carrier
44
+ * would make every `validator:`-carried rule with a per-edit obligation a
45
+ * finding — roughly a fifth of the declared corpus at once, all from one
46
+ * modelling error, which is precisely the unusable-first-run failure this audit
47
+ * must avoid.
48
+ *
49
+ * So carriers have a MODE. A `sweep` carrier covers any obligation whose
50
+ * violations land in a durable artefact (`per-edit`, `per-file-write`,
51
+ * `per-commit`). It covers none of the transient ones (`per-turn`, `per-task`,
52
+ * `per-session`, `per-event`), because a reply's language, a greeting, or a
53
+ * fetched-content decision leaves nothing in the tree for a sweep to read.
54
+ */
55
+
56
+ // ------------------------------------------------------------------ vocabulary
57
+
58
+ export type Frequency =
59
+ | 'per-edit'
60
+ | 'per-turn'
61
+ | 'per-task'
62
+ | 'per-session'
63
+ | 'per-event'
64
+ | 'per-commit'
65
+ | 'per-file-write'
66
+ | 'none';
67
+
68
+ export const FREQUENCIES: readonly Frequency[] = [
69
+ 'per-edit',
70
+ 'per-turn',
71
+ 'per-task',
72
+ 'per-session',
73
+ 'per-event',
74
+ 'per-commit',
75
+ 'per-file-write',
76
+ 'none',
77
+ ] as const;
78
+
79
+ export function is_frequency(v: unknown): v is Frequency {
80
+ return typeof v === 'string' && (FREQUENCIES as readonly string[]).includes(v);
81
+ }
82
+
83
+ export type Root = 'lifecycle' | 'tool-call' | 'repository' | 'external-event' | 'none';
84
+
85
+ const ROOT_OF: Record<Frequency, Root> = {
86
+ 'per-turn': 'lifecycle',
87
+ 'per-task': 'lifecycle',
88
+ 'per-session': 'lifecycle',
89
+ 'per-edit': 'tool-call',
90
+ 'per-file-write': 'tool-call',
91
+ 'per-commit': 'repository',
92
+ 'per-event': 'external-event',
93
+ none: 'none',
94
+ };
95
+
96
+ /**
97
+ * Cross-root coverage that IS real, enumerated rather than inferred.
98
+ *
99
+ * `per-commit` keeps its own root because it is not a lifecycle event — a
100
+ * `--fixup` during a rebase has no preceding user turn, so no lifecycle carrier
101
+ * covers it. But in an agent runtime every commit the agent makes is issued
102
+ * through a tool call, so a point carrier in the tool-call root DOES observe it:
103
+ * `block-no-verify` sits in `pre_tool_use` and inspects the very `git commit`
104
+ * command. Refusing that edge on a tidy root rule would report the commit guard
105
+ * as failing to carry the commit rule, which is the opposite of true.
106
+ *
107
+ * The relation is one-directional. A per-commit carrier does not cover a
108
+ * per-edit obligation: one commit can hold twenty edits, and a point carrier at
109
+ * the commit sees the command, not each edit that preceded it.
110
+ */
111
+ const CROSS_ROOT_COVERAGE: ReadonlyArray<readonly [Frequency, Frequency]> = [
112
+ ['per-edit', 'per-commit'],
113
+ ];
114
+
115
+ export function root_of(f: Frequency): Root {
116
+ return ROOT_OF[f];
117
+ }
118
+
119
+ /**
120
+ * Within-root inclusion depth: a SMALLER number fires more often, so it is a
121
+ * superset of every larger number in the same root. Cross-root comparison is
122
+ * rejected before this table is consulted.
123
+ */
124
+ const DEPTH: Record<Frequency, number> = {
125
+ 'per-turn': 0,
126
+ 'per-task': 1,
127
+ 'per-session': 2,
128
+ 'per-edit': 0,
129
+ 'per-file-write': 1,
130
+ 'per-commit': 0,
131
+ 'per-event': 0,
132
+ none: 0,
133
+ };
134
+
135
+ // -------------------------------------------------------------------- carriers
136
+
137
+ /**
138
+ * How a carrier observes the world.
139
+ *
140
+ * `point` — fires at an event and sees that event (a hook).
141
+ * `sweep` — fires once and inspects the whole artefact tree (a CI validator, a
142
+ * test suite). Its reach is bounded by what lands in the tree, not by
143
+ * how often it runs.
144
+ */
145
+ export type CarrierMode = 'point' | 'sweep';
146
+
147
+ /** Obligations whose violations leave a durable trace a sweep can read. */
148
+ const SWEEPABLE: ReadonlySet<Frequency> = new Set<Frequency>([
149
+ 'per-edit',
150
+ 'per-file-write',
151
+ 'per-commit',
152
+ ]);
153
+
154
+ /**
155
+ * Does `carrier` cover `obligation`?
156
+ *
157
+ * An obligation of `none` is covered vacuously — there is nothing recurring to
158
+ * carry, which is what `none` means. Everything else is decided by mode first,
159
+ * then root, then within-root depth.
160
+ */
161
+ export function covers(
162
+ carrier: { frequency: Frequency; mode: CarrierMode },
163
+ obligation: Frequency,
164
+ ): boolean {
165
+ if (obligation === 'none') return true;
166
+ if (carrier.mode === 'sweep') return SWEEPABLE.has(obligation);
167
+ if (carrier.frequency === 'none') return false;
168
+ if (CROSS_ROOT_COVERAGE.some(([c, o]) => c === carrier.frequency && o === obligation)) {
169
+ return true;
170
+ }
171
+ if (ROOT_OF[carrier.frequency] !== ROOT_OF[obligation]) return false;
172
+ return DEPTH[carrier.frequency] <= DEPTH[obligation];
173
+ }
174
+
175
+ /** True when ANY of a carrier's firing periods covers the obligation. */
176
+ export function covers_any(frequencies: readonly Frequency[], obligation: Frequency): boolean {
177
+ return frequencies.some((f) => covers({ frequency: f, mode: 'point' }, obligation));
178
+ }
179
+
180
+ // ------------------------------------------------------------- the decay guard
181
+
182
+ /**
183
+ * Prose signals that suggest a period, keyed to the value they suggest.
184
+ *
185
+ * A declared value can be right the day it is written and wrong two edits later,
186
+ * and nothing in the join notices — the field would then be a stale claim
187
+ * wearing a schema. This heuristic reads the rule's own prose and reports when
188
+ * it demands a TIGHTER period than the frontmatter declares.
189
+ *
190
+ * Deliberately one-directional. Prose looser than the declaration is not a
191
+ * finding: a rule may state a per-session cache and still carry a per-turn
192
+ * obligation elsewhere in its body, and flagging that would fire on most of the
193
+ * corpus. Prose demanding MORE often than declared is the direction where the
194
+ * join silently over-credits a carrier.
195
+ */
196
+ const PROSE_SIGNALS: ReadonlyArray<readonly [Frequency, RegExp]> = [
197
+ ['per-turn', /\b(every|each) (reply|turn|answer|response)\b/i],
198
+ ['per-turn', /\bper (reply|turn)\b/i],
199
+ ['per-task', /\b(every|each) (new )?task\b/i],
200
+ ['per-edit', /\bafter every (code )?edit\b/i],
201
+ ['per-edit', /\b(every|each) edit\b/i],
202
+ ['per-commit', /\b(in the )?same commit\b/i],
203
+ ['per-commit', /\b(every|each) commit\b/i],
204
+ ];
205
+
206
+ /**
207
+ * Frequencies the prose demands but the declared value does not cover.
208
+ *
209
+ * Empty is the passing answer. A non-empty result is a WARNING — the heuristic
210
+ * is a keyword match over prose and will be noisy, so it never fails a build;
211
+ * an audited mismatch is silenced with an explicit `# frequency-override:`
212
+ * comment, which makes a suppression a decision someone signed rather than
213
+ * silence.
214
+ */
215
+ export function frequency_prose_conflicts(body: string, declared: Frequency): Frequency[] {
216
+ const out: Frequency[] = [];
217
+ for (const [freq, re] of PROSE_SIGNALS) {
218
+ if (!re.test(body)) continue;
219
+ if (covers({ frequency: declared, mode: 'point' }, freq)) continue;
220
+ if (!out.includes(freq)) out.push(freq);
221
+ }
222
+ return out;
223
+ }
224
+
225
+ /** True when the file carries an audited `# frequency-override: <reason>` note. */
226
+ export function has_frequency_override(text: string): boolean {
227
+ return /^#\s*frequency-override:\s*\S/m.test(text);
228
+ }
229
+
230
+ // --------------------------------------------------------- slot × platform map
231
+
232
+ export type Slot =
233
+ | 'session_start'
234
+ | 'session_end'
235
+ | 'stop'
236
+ | 'user_prompt_submit'
237
+ | 'pre_tool_use'
238
+ | 'post_tool_use';
239
+
240
+ /**
241
+ * Default firing period per slot, before per-platform native-event corrections.
242
+ *
243
+ * `stop` is per-turn, NOT session end. On Claude Code the native `Stop` event
244
+ * fires after every assistant reply — `hook_manifest.yaml` says so itself,
245
+ * describing the `stop` write as a "deterministic … overwrite of hot-context.md",
246
+ * i.e. a working-memory refresh per reply. True session end is the separate
247
+ * `session_end` slot.
248
+ */
249
+ const SLOT_FREQUENCY_DEFAULT: Record<Slot, Frequency> = {
250
+ session_start: 'per-session',
251
+ session_end: 'per-session',
252
+ stop: 'per-turn',
253
+ user_prompt_submit: 'per-turn',
254
+ pre_tool_use: 'per-edit',
255
+ post_tool_use: 'per-edit',
256
+ };
257
+
258
+ /**
259
+ * Per-platform overrides where the native event a slot is mapped from means
260
+ * something other than the default.
261
+ *
262
+ * Cline maps `stop` from `TaskCancel` — the session is interrupted with partial
263
+ * state (`hook_manifest.yaml`: "TaskCancel maps to stop because the session is
264
+ * interrupted with partial state"). That is an interruption on its own clock,
265
+ * not a per-reply beat, so it belongs to the external-event root and covers no
266
+ * lifecycle obligation. Collapsing it into per-turn is the semantic type error
267
+ * a one-dimensional slot→frequency table cannot express.
268
+ */
269
+ const SLOT_FREQUENCY_OVERRIDE: Record<string, Partial<Record<Slot, Frequency>>> = {
270
+ cline: { stop: 'per-event' },
271
+ };
272
+
273
+ export function slot_frequency(platform: string, slot: Slot): Frequency {
274
+ return SLOT_FREQUENCY_OVERRIDE[platform]?.[slot] ?? SLOT_FREQUENCY_DEFAULT[slot];
275
+ }
276
+
277
+ /**
278
+ * Platforms with no hook surface at all.
279
+ *
280
+ * Copilot declares `fallback_only: true` in the manifest — concerns route
281
+ * through rule-only fallback and the dispatcher no-ops. Every hook-declared
282
+ * carrier fires zero times there, for every rule equally. Including it in the
283
+ * join would turn one structural fact into a finding on every hook-carried rule
284
+ * at once, which reports a platform property as if it were a per-rule defect.
285
+ * It is excluded by declaration, and the exclusion is named in the report rather
286
+ * than hidden.
287
+ */
288
+ export function is_hook_capable(platform_block: Record<string, unknown>): boolean {
289
+ return platform_block['fallback_only'] !== true;
290
+ }
291
+
292
+ // ------------------------------------------------- hook manifest platform read
293
+
294
+ export interface PlatformBinding {
295
+ /** Platform id → slot → concern ids bound in that slot. */
296
+ slots: Map<string, Map<Slot, string[]>>;
297
+ /** Platform ids that carry no hook surface at all. */
298
+ fallback_only: Set<string>;
299
+ }
300
+
301
+ const SLOT_NAMES: ReadonlySet<string> = new Set<string>([
302
+ 'session_start',
303
+ 'session_end',
304
+ 'stop',
305
+ 'user_prompt_submit',
306
+ 'pre_tool_use',
307
+ 'post_tool_use',
308
+ ]);
309
+
310
+ /**
311
+ * Read the `platforms:` block of `hook_manifest.yaml`.
312
+ *
313
+ * A narrow reader, matching the one `check_enforcement_coverage.parse_hook_manifest`
314
+ * already uses for `concerns:` — the block is a fixed two-level shape
315
+ * (`platform: slot: [concern, …]`) and the only facts needed are slot membership
316
+ * and the `fallback_only` sentinel. Deliberately NOT a second YAML dependency.
317
+ */
318
+ export function parse_hook_platforms(text: string): PlatformBinding {
319
+ const slots = new Map<string, Map<Slot, string[]>>();
320
+ const fallback_only = new Set<string>();
321
+ let in_platforms = false;
322
+ let current: string | null = null;
323
+
324
+ for (const raw of text.split('\n')) {
325
+ const line = raw.replace(/\s+$/, '');
326
+ if (/^platforms:\s*$/.test(line)) {
327
+ in_platforms = true;
328
+ continue;
329
+ }
330
+ if (!in_platforms) continue;
331
+ if (/^\S/.test(line)) break; // left the platforms block
332
+ if (line.trim() === '' || /^\s*#/.test(line)) continue;
333
+
334
+ const platform = /^ {2}([a-z0-9_-]+):\s*$/.exec(line)?.[1];
335
+ if (platform !== undefined) {
336
+ current = platform;
337
+ slots.set(current, new Map());
338
+ continue;
339
+ }
340
+ if (current === null) continue;
341
+
342
+ if (/^\s+fallback_only:\s*true\s*$/.test(line)) {
343
+ fallback_only.add(current);
344
+ continue;
345
+ }
346
+ const m = /^\s+([a-z_]+):\s*\[(.*)\]\s*$/.exec(line);
347
+ if (m === null) continue;
348
+ const slot = m[1] as string;
349
+ if (!SLOT_NAMES.has(slot)) continue;
350
+ const concerns = (m[2] as string)
351
+ .split(',')
352
+ .map((s) => s.trim())
353
+ .filter((s) => s.length > 0);
354
+ slots.get(current)?.set(slot as Slot, concerns);
355
+ }
356
+ return { slots, fallback_only };
357
+ }
358
+
359
+ /**
360
+ * Resolve, per platform, EVERY period at which `concern` fires — a set, never a
361
+ * scalar.
362
+ *
363
+ * A concern bound in more than one slot fires at the UNION of their periods, and
364
+ * those periods can sit in different roots: `minimal-safe-diff` is bound in
365
+ * `session_start` (per-session), `user_prompt_submit` (per-turn) AND
366
+ * `post_tool_use` (per-edit). Collapsing that to one "strongest" value has no
367
+ * correct answer, because per-turn and per-edit are incomparable by
368
+ * construction — and picking either drops a root the carrier really does cover.
369
+ * Doing so reported `minimal-safe-diff` as failing to carry its own per-edit
370
+ * obligation while a post_tool_use binding was sitting right there.
371
+ *
372
+ * An empty array means the concern is bound in no slot on that platform, which
373
+ * is a distinct answer from any frequency and must not be collapsed into one.
374
+ */
375
+ export function carrier_frequency_by_platform(
376
+ concern: string,
377
+ binding: PlatformBinding,
378
+ ): Record<string, Frequency[]> {
379
+ const out: Record<string, Frequency[]> = {};
380
+ for (const [platform, slot_map] of binding.slots) {
381
+ if (binding.fallback_only.has(platform)) continue; // named in the report, not joined
382
+ const found: Frequency[] = [];
383
+ for (const [slot, concerns] of slot_map) {
384
+ if (!concerns.includes(concern)) continue;
385
+ const f = slot_frequency(platform, slot);
386
+ if (!found.includes(f)) found.push(f);
387
+ }
388
+ out[platform] = found;
389
+ }
390
+ return out;
391
+ }