@event4u/agent-config 6.1.0 → 7.0.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 (1539) hide show
  1. package/.claude-plugin/marketplace.json +35 -3
  2. package/AGENTS.md +8 -7
  3. package/CHANGELOG.md +31 -107
  4. package/CONTRIBUTING.md +1 -1
  5. package/README.md +17 -15
  6. package/dist/agent-src/commands/agent-status.md +2 -2
  7. package/dist/agent-src/commands/agents/audit.md +3 -3
  8. package/dist/agent-src/commands/agents/init.md +1 -1
  9. package/dist/agent-src/commands/agents/optimize.md +4 -4
  10. package/dist/agent-src/commands/analyze/decision.md +108 -0
  11. package/dist/agent-src/commands/analyze/incident.md +120 -0
  12. package/dist/agent-src/commands/analyze/near-miss.md +113 -0
  13. package/dist/agent-src/commands/analyze/postmortem.md +130 -0
  14. package/dist/agent-src/commands/analyze/premortem.md +104 -0
  15. package/dist/agent-src/commands/analyze.md +124 -0
  16. package/dist/agent-src/commands/brand/identity.md +27 -0
  17. package/dist/agent-src/commands/brand/review.md +27 -0
  18. package/dist/agent-src/commands/brand/strategy.md +27 -0
  19. package/dist/agent-src/commands/brand/tokens.md +28 -0
  20. package/dist/agent-src/commands/brand/voice.md +27 -0
  21. package/dist/agent-src/commands/brand.md +58 -0
  22. package/dist/agent-src/commands/check-current-md.md +3 -3
  23. package/dist/agent-src/commands/condense.md +2 -2
  24. package/dist/agent-src/commands/council/debate.md +2 -2
  25. package/dist/agent-src/commands/council/default.md +45 -18
  26. package/dist/agent-src/commands/fix/portability.md +3 -3
  27. package/dist/agent-src/commands/fix/refs.md +3 -3
  28. package/dist/agent-src/commands/implement-ticket.md +36 -6
  29. package/dist/agent-src/commands/knowledge/cross-repo.md +1 -1
  30. package/dist/agent-src/commands/memory/add.md +1 -1
  31. package/dist/agent-src/commands/mission/upgrade.md +182 -0
  32. package/dist/agent-src/commands/optimize/skills.md +2 -2
  33. package/dist/agent-src/commands/orchestrate.md +1 -1
  34. package/dist/agent-src/commands/pr/create.md +6 -4
  35. package/dist/agent-src/commands/review-changes.md +8 -0
  36. package/dist/agent-src/commands/roadmap/materialize.md +73 -0
  37. package/dist/agent-src/commands/skill/preview.md +1 -1
  38. package/dist/agent-src/commands/skills/discover.md +1 -1
  39. package/dist/agent-src/commands/threat-model.md +4 -4
  40. package/dist/agent-src/commands/upstream-contribute.md +3 -3
  41. package/dist/agent-src/commands/video/from-script.md +2 -2
  42. package/dist/agent-src/commands/video/from-song.md +3 -3
  43. package/dist/agent-src/commands/video/scene.md +1 -1
  44. package/dist/agent-src/commands/video/storyboard.md +1 -1
  45. package/dist/agent-src/commands/video.md +3 -3
  46. package/dist/agent-src/contexts/communication/rules-auto/source-of-truth-mechanics.md +3 -3
  47. package/dist/agent-src/contexts/communication/rules-auto/user-interaction-mechanics.md +1 -1
  48. package/dist/agent-src/contexts/execution/evidence-discipline.md +153 -0
  49. package/dist/agent-src/contexts/execution/project-intelligence.md +264 -0
  50. package/dist/agent-src/contexts/execution/roadmap-process-loop.md +2 -1
  51. package/dist/agent-src/personas/ai-video-technical-director.md +1 -1
  52. package/dist/agent-src/personas/brand-strategist.md +74 -0
  53. package/dist/agent-src/personas/design-director.md +74 -0
  54. package/dist/agent-src/rules/brand-consistency.md +77 -0
  55. package/dist/agent-src/rules/brand-source-of-truth.md +57 -0
  56. package/dist/agent-src/rules/direct-answers.md +2 -0
  57. package/dist/agent-src/rules/domain-safety-disclaimer.md +2 -0
  58. package/dist/agent-src/rules/git-history-discipline.md +1 -0
  59. package/dist/agent-src/rules/icon-consistency.md +53 -0
  60. package/dist/agent-src/rules/image-likeness-and-rights.md +67 -0
  61. package/dist/agent-src/rules/lethal-trifecta-guard.md +1 -1
  62. package/dist/agent-src/rules/persona-governance.md +2 -2
  63. package/dist/agent-src/rules/provider-lifecycle-discipline.md +3 -1
  64. package/dist/agent-src/rules/roadmap-progress-sync.md +10 -0
  65. package/dist/agent-src/rules/security-sensitive-stop.md +9 -3
  66. package/dist/agent-src/rules/size-enforcement.md +1 -1
  67. package/dist/agent-src/rules/source-confidentiality.md +3 -3
  68. package/dist/agent-src/rules/source-discovery-gate.md +98 -0
  69. package/dist/agent-src/rules/think-before-action.md +1 -0
  70. package/dist/agent-src/rules/ui-audit-gate.md +2 -0
  71. package/dist/agent-src/rules/untrusted-input-defense.md +1 -1
  72. package/dist/agent-src/rules/user-interaction.md +1 -1
  73. package/dist/agent-src/scripts/archive_completed_roadmaps.ts +392 -0
  74. package/dist/agent-src/scripts/update_roadmap_progress.ts +824 -0
  75. package/dist/agent-src/skills/adr-create/SKILL.md +5 -5
  76. package/dist/agent-src/skills/agent-security-review/evals/triggers.json +1 -0
  77. package/dist/agent-src/skills/agents-md-thin-root/SKILL.md +1 -1
  78. package/dist/agent-src/skills/ai-council/SKILL.md +1 -1
  79. package/dist/agent-src/skills/analysis-autonomous-mode/SKILL.md +9 -13
  80. package/dist/agent-src/skills/blade-ui/SKILL.md +12 -5
  81. package/dist/agent-src/skills/blameless-post-mortem/SKILL.md +199 -0
  82. package/dist/agent-src/skills/brand/ATTRIBUTION.md +38 -0
  83. package/dist/agent-src/skills/brand/SKILL.md +115 -0
  84. package/dist/agent-src/skills/brand/data/archetypes.csv +13 -0
  85. package/dist/agent-src/skills/brand/data/color-psychology.csv +14 -0
  86. package/dist/agent-src/skills/brand/data/logo-style-fit.csv +13 -0
  87. package/dist/agent-src/skills/brand/data/manifest.json +226 -0
  88. package/dist/agent-src/skills/brand/data/messaging-frameworks.csv +13 -0
  89. package/dist/agent-src/skills/brand/data/naming-patterns.csv +13 -0
  90. package/dist/agent-src/skills/brand/data/typography-principles.csv +13 -0
  91. package/dist/agent-src/skills/brand/data/voice-tone.csv +13 -0
  92. package/dist/agent-src/skills/brand/evals/triggers.json +17 -0
  93. package/dist/agent-src/skills/brand-asset-generation/SKILL.md +89 -0
  94. package/dist/agent-src/skills/brand-asset-generation/evals/triggers.json +17 -0
  95. package/dist/agent-src/skills/brand-audit/SKILL.md +67 -0
  96. package/dist/agent-src/skills/brand-audit/evals/triggers.json +17 -0
  97. package/dist/agent-src/skills/brand-identity/SKILL.md +101 -0
  98. package/dist/agent-src/skills/brand-identity/evals/triggers.json +17 -0
  99. package/dist/agent-src/skills/brand-strategy/SKILL.md +83 -0
  100. package/dist/agent-src/skills/brand-strategy/evals/triggers.json +17 -0
  101. package/dist/agent-src/skills/brand-to-tokens/SKILL.md +102 -0
  102. package/dist/agent-src/skills/brand-to-tokens/evals/triggers.json +17 -0
  103. package/dist/agent-src/skills/brand-to-tokens/templates/marp-brand-deck.md.example +46 -0
  104. package/dist/agent-src/skills/brand-to-tokens/templates/reveal-brand-deck.yaml +32 -0
  105. package/dist/agent-src/skills/canvas-design/evals/triggers.json +1 -0
  106. package/dist/agent-src/skills/check-refs/SKILL.md +5 -5
  107. package/dist/agent-src/skills/code-review/SKILL.md +6 -15
  108. package/dist/agent-src/skills/command-writing/SKILL.md +2 -2
  109. package/dist/agent-src/skills/complexity-first-planning/evals/triggers.json +1 -0
  110. package/dist/agent-src/skills/context-authoring/SKILL.md +2 -2
  111. package/dist/agent-src/skills/context-document/SKILL.md +35 -2
  112. package/dist/agent-src/skills/corpus-grounding/evals/triggers.json +1 -0
  113. package/dist/agent-src/skills/corpus-grounding/scripts/bm25_search.ts +482 -0
  114. package/dist/agent-src/skills/corpus-grounding/scripts/decision_engine.ts +803 -0
  115. package/dist/agent-src/skills/corpus-grounding/scripts/ground.ts +541 -0
  116. package/dist/agent-src/skills/corpus-grounding/scripts/schema_validator.ts +309 -0
  117. package/dist/agent-src/skills/database/SKILL.md +26 -4
  118. package/dist/agent-src/skills/decision-record/SKILL.md +1 -1
  119. package/dist/agent-src/skills/decision-record/evals/triggers.json +17 -0
  120. package/dist/agent-src/skills/decision-review/SKILL.md +179 -0
  121. package/dist/agent-src/skills/description-assist/SKILL.md +1 -1
  122. package/dist/agent-src/skills/design-intelligence/SKILL.md +1 -1
  123. package/dist/agent-src/skills/design-intelligence/data/manifest.json +23 -6
  124. package/dist/agent-src/skills/design-intelligence/evals/triggers.json +1 -0
  125. package/dist/agent-src/skills/design-tokens/evals/triggers.json +1 -0
  126. package/dist/agent-src/skills/design-tokens/scripts/tokens.ts +888 -0
  127. package/dist/agent-src/skills/doc-coauthoring/evals/triggers.json +1 -0
  128. package/dist/agent-src/skills/eloquent/evals/triggers.json +1 -0
  129. package/dist/agent-src/skills/emit-tickets/SKILL.md +198 -0
  130. package/dist/agent-src/skills/estimate-ticket/evals/triggers.json +1 -0
  131. package/dist/agent-src/skills/git-workflow/SKILL.md +33 -0
  132. package/dist/agent-src/skills/guideline-writing/SKILL.md +2 -2
  133. package/dist/agent-src/skills/iconography/SKILL.md +88 -0
  134. package/dist/agent-src/skills/iconography/evals/triggers.json +17 -0
  135. package/dist/agent-src/skills/image-analyser/evals/triggers.json +1 -0
  136. package/dist/agent-src/skills/image-creator/evals/triggers.json +1 -0
  137. package/dist/agent-src/skills/image-editing/SKILL.md +100 -0
  138. package/dist/agent-src/skills/image-editing/evals/triggers.json +17 -0
  139. package/dist/agent-src/skills/image-generation/SKILL.md +95 -0
  140. package/dist/agent-src/skills/image-generation/evals/triggers.json +17 -0
  141. package/dist/agent-src/skills/image-provider-routing/SKILL.md +96 -0
  142. package/dist/agent-src/skills/image-provider-routing/evals/triggers.json +17 -0
  143. package/dist/agent-src/skills/launch-readiness/SKILL.md +21 -0
  144. package/dist/agent-src/skills/learning-to-rule-or-skill/SKILL.md +12 -8
  145. package/dist/agent-src/skills/lint-skills/SKILL.md +5 -5
  146. package/dist/agent-src/skills/logo-generation/SKILL.md +98 -0
  147. package/dist/agent-src/skills/logo-generation/evals/triggers.json +17 -0
  148. package/dist/agent-src/skills/markitdown/SKILL.md +1 -1
  149. package/dist/agent-src/skills/md-language-check/SKILL.md +1 -1
  150. package/dist/agent-src/skills/motion-choreographer/SKILL.md +1 -1
  151. package/dist/agent-src/skills/php-coder/evals/triggers.json +1 -0
  152. package/dist/agent-src/skills/prediction-pool-optimizer/evals/triggers.json +1 -0
  153. package/dist/agent-src/skills/premortem/SKILL.md +137 -0
  154. package/dist/agent-src/skills/prompt-engineering-image/SKILL.md +115 -0
  155. package/dist/agent-src/skills/prompt-engineering-image/evals/triggers.json +17 -0
  156. package/dist/agent-src/skills/prompt-validator/evals/triggers.json +1 -0
  157. package/dist/agent-src/skills/react-shadcn-ui/SKILL.md +12 -5
  158. package/dist/agent-src/skills/react-shadcn-ui/scripts/shadcn_add.ts +388 -0
  159. package/dist/agent-src/skills/reasoning-orchestrator/SKILL.md +1 -1
  160. package/dist/agent-src/skills/reasoning-orchestrator/evals/triggers.json +1 -0
  161. package/dist/agent-src/skills/refine-ticket/evals/triggers.json +1 -0
  162. package/dist/agent-src/skills/roadmap-management/SKILL.md +16 -3
  163. package/dist/agent-src/skills/roadmap-writing/SKILL.md +76 -0
  164. package/dist/agent-src/skills/root-cause-frameworks/SKILL.md +146 -0
  165. package/dist/agent-src/skills/rule-refactor/SKILL.md +9 -9
  166. package/dist/agent-src/skills/rule-writing/SKILL.md +7 -7
  167. package/dist/agent-src/skills/script-writing/SKILL.md +2 -2
  168. package/dist/agent-src/skills/security-audit/SKILL.md +5 -0
  169. package/dist/agent-src/skills/skill-improvement-pipeline/SKILL.md +19 -3
  170. package/dist/agent-src/skills/skill-management/SKILL.md +3 -3
  171. package/dist/agent-src/skills/skill-reviewer/SKILL.md +1 -1
  172. package/dist/agent-src/skills/skill-writing/SKILL.md +5 -5
  173. package/dist/agent-src/skills/skill-writing/evals/triggers.json +1 -0
  174. package/dist/agent-src/skills/source-discovery/SKILL.md +182 -0
  175. package/dist/agent-src/skills/standards-from-config/SKILL.md +93 -0
  176. package/dist/agent-src/skills/systematic-debugging/SKILL.md +7 -0
  177. package/dist/agent-src/skills/tailwind-engineer/scripts/tailwind_config_gen.ts +561 -0
  178. package/dist/agent-src/skills/threat-modeling/SKILL.md +1 -0
  179. package/dist/agent-src/skills/typography-system/SKILL.md +138 -0
  180. package/dist/agent-src/skills/typography-system/evals/triggers.json +17 -0
  181. package/dist/agent-src/skills/upstream-contribute/SKILL.md +3 -3
  182. package/dist/agent-src/skills/verify-repair-loop/SKILL.md +209 -0
  183. package/dist/agent-src/skills/verify-repair-loop/evals/output-schema.yml +20 -0
  184. package/dist/agent-src/skills/verify-repair-loop/evals/triggers.json +17 -0
  185. package/dist/agent-src/templates/agent-settings.md +7 -0
  186. package/dist/agent-src/templates/contexts/knowledge-card.md +69 -0
  187. package/dist/agent-src/templates/contexts/lesson-card.md +73 -0
  188. package/dist/agent-src/templates/roadmaps.md +29 -1
  189. package/dist/agent-src/templates/scripts/README.md +6 -6
  190. package/dist/agent-src/templates/scripts/check_memory.ts +640 -0
  191. package/dist/agent-src/templates/scripts/check_memory_proposal.ts +351 -0
  192. package/dist/agent-src/templates/scripts/implement_ticket/__main__.ts +27 -0
  193. package/dist/agent-src/templates/scripts/memory_hash.ts +333 -0
  194. package/dist/agent-src/templates/scripts/memory_lookup.ts +1067 -0
  195. package/dist/agent-src/templates/scripts/memory_report.ts +846 -0
  196. package/dist/agent-src/templates/scripts/memory_signal.ts +422 -0
  197. package/dist/agent-src/templates/scripts/memory_status.ts +191 -0
  198. package/dist/agent-src/templates/scripts/pr_review_routing.ts +523 -0
  199. package/dist/agent-src/templates/scripts/pr_risk_review.ts +0 -0
  200. package/dist/agent-src/templates/scripts/telemetry/aggregator.ts +0 -0
  201. package/dist/agent-src/templates/scripts/telemetry/boundary.ts +164 -0
  202. package/dist/agent-src/templates/scripts/telemetry/engagement.ts +479 -0
  203. package/dist/agent-src/templates/scripts/telemetry/report_renderer.ts +394 -0
  204. package/dist/agent-src/templates/scripts/telemetry/settings.ts +210 -0
  205. package/dist/agent-src/templates/scripts/telemetry_record.ts +255 -0
  206. package/dist/agent-src/templates/scripts/telemetry_report.ts +189 -0
  207. package/dist/agent-src/templates/scripts/telemetry_status.ts +312 -0
  208. package/dist/agent-src/templates/scripts/tier_usage_report.ts +597 -0
  209. package/dist/agent-src/templates/scripts/work_engine/__main__.ts +14 -0
  210. package/dist/agent-src/templates/scripts/work_engine/_lib/agent_settings.ts +1118 -0
  211. package/dist/agent-src/templates/scripts/work_engine/_lib/user_global_paths.ts +329 -0
  212. package/dist/agent-src/templates/scripts/work_engine/cli.ts +206 -0
  213. package/dist/agent-src/templates/scripts/work_engine/cli_args.ts +249 -0
  214. package/dist/agent-src/templates/scripts/work_engine/delivery_state.ts +225 -0
  215. package/dist/agent-src/templates/scripts/work_engine/directives/backend/analyze.ts +125 -0
  216. package/dist/agent-src/templates/scripts/work_engine/directives/backend/implement.ts +189 -0
  217. package/dist/agent-src/templates/scripts/work_engine/directives/backend/index.ts +94 -0
  218. package/dist/agent-src/templates/scripts/work_engine/directives/backend/memory.ts +193 -0
  219. package/dist/agent-src/templates/scripts/work_engine/directives/backend/plan.ts +267 -0
  220. package/dist/agent-src/templates/scripts/work_engine/directives/backend/refine.ts +518 -0
  221. package/dist/agent-src/templates/scripts/work_engine/directives/backend/report.ts +379 -0
  222. package/dist/agent-src/templates/scripts/work_engine/directives/backend/test.ts +268 -0
  223. package/dist/agent-src/templates/scripts/work_engine/directives/backend/verify.ts +258 -0
  224. package/dist/agent-src/templates/scripts/work_engine/directives/index.ts +32 -0
  225. package/dist/agent-src/templates/scripts/work_engine/directives/mixed/contract.ts +243 -0
  226. package/dist/agent-src/templates/scripts/work_engine/directives/mixed/index.ts +108 -0
  227. package/dist/agent-src/templates/scripts/work_engine/directives/mixed/stitch.ts +259 -0
  228. package/dist/agent-src/templates/scripts/work_engine/directives/mixed/ui.ts +216 -0
  229. package/dist/agent-src/templates/scripts/work_engine/directives/ui/_passthrough.ts +40 -0
  230. package/dist/agent-src/templates/scripts/work_engine/directives/ui/app_spec.ts +241 -0
  231. package/dist/agent-src/templates/scripts/work_engine/directives/ui/apply.ts +216 -0
  232. package/dist/agent-src/templates/scripts/work_engine/directives/ui/audit.ts +506 -0
  233. package/dist/agent-src/templates/scripts/work_engine/directives/ui/design.ts +325 -0
  234. package/dist/agent-src/templates/scripts/work_engine/directives/ui/index.ts +102 -0
  235. package/dist/agent-src/templates/scripts/work_engine/directives/ui/polish.ts +462 -0
  236. package/dist/agent-src/templates/scripts/work_engine/directives/ui/review.ts +474 -0
  237. package/dist/agent-src/templates/scripts/work_engine/directives/ui/scaffold.ts +352 -0
  238. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/_skipped.ts +33 -0
  239. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/apply.ts +213 -0
  240. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/index.ts +111 -0
  241. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/refine.ts +126 -0
  242. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/report.ts +112 -0
  243. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/test.ts +164 -0
  244. package/dist/agent-src/templates/scripts/work_engine/dispatcher.ts +515 -0
  245. package/dist/agent-src/templates/scripts/work_engine/emitters.ts +119 -0
  246. package/dist/agent-src/templates/scripts/work_engine/errors.ts +24 -0
  247. package/dist/agent-src/templates/scripts/work_engine/hook_bootstrap.ts +104 -0
  248. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/_chat_history_base.ts +176 -0
  249. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_append.ts +41 -0
  250. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_halt_append.ts +89 -0
  251. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/decision_gate.ts +193 -0
  252. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/decision_trace.ts +304 -0
  253. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/directive_set_guard.ts +110 -0
  254. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/halt_surface_audit.ts +118 -0
  255. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/index.ts +17 -0
  256. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/memory_visibility.ts +161 -0
  257. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/state_shape_validation.ts +45 -0
  258. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/trace.ts +134 -0
  259. package/dist/agent-src/templates/scripts/work_engine/hooks/context.ts +94 -0
  260. package/dist/agent-src/templates/scripts/work_engine/hooks/events.ts +58 -0
  261. package/dist/agent-src/templates/scripts/work_engine/hooks/exceptions.ts +85 -0
  262. package/dist/agent-src/templates/scripts/work_engine/hooks/index.ts +27 -0
  263. package/dist/agent-src/templates/scripts/work_engine/hooks/registry.ts +66 -0
  264. package/dist/agent-src/templates/scripts/work_engine/hooks/runner.ts +90 -0
  265. package/dist/agent-src/templates/scripts/work_engine/hooks/settings.ts +260 -0
  266. package/dist/agent-src/templates/scripts/work_engine/input_builders.ts +260 -0
  267. package/dist/agent-src/templates/scripts/work_engine/intent/classify.ts +466 -0
  268. package/dist/agent-src/templates/scripts/work_engine/migration/v0_to_v1.ts +531 -0
  269. package/dist/agent-src/templates/scripts/work_engine/orchestration.ts +366 -0
  270. package/dist/agent-src/templates/scripts/work_engine/persona_policy.ts +97 -0
  271. package/dist/agent-src/templates/scripts/work_engine/resolvers/diff.ts +135 -0
  272. package/dist/agent-src/templates/scripts/work_engine/resolvers/file.ts +175 -0
  273. package/dist/agent-src/templates/scripts/work_engine/resolvers/prompt.ts +115 -0
  274. package/dist/agent-src/templates/scripts/work_engine/scoring/confidence.ts +415 -0
  275. package/dist/agent-src/templates/scripts/work_engine/scoring/decision_engine.ts +466 -0
  276. package/dist/agent-src/templates/scripts/work_engine/scoring/decision_trace.ts +298 -0
  277. package/dist/agent-src/templates/scripts/work_engine/scoring/memory_visibility.ts +444 -0
  278. package/dist/agent-src/templates/scripts/work_engine/stack/detect.ts +252 -0
  279. package/dist/agent-src/templates/scripts/work_engine/stack/runner.ts +745 -0
  280. package/dist/agent-src/templates/scripts/work_engine/state.ts +1151 -0
  281. package/dist/agent-src/templates/scripts/work_engine/state_io.ts +413 -0
  282. package/dist/agent-src/templates/tickets.md +120 -0
  283. package/dist/cli/commands/commands.js +2 -2
  284. package/dist/cli/commands/commands.js.map +1 -1
  285. package/dist/cli/commands/doctorShell.js +4 -22
  286. package/dist/cli/commands/doctorShell.js.map +1 -1
  287. package/dist/cli/commands/packs.js +1 -1
  288. package/dist/cli/commands/packs.js.map +1 -1
  289. package/dist/cli/commands/recordTriggerEval.js +179 -0
  290. package/dist/cli/commands/recordTriggerEval.js.map +1 -0
  291. package/dist/cli/commands/recordTriggerEval.test.js +113 -0
  292. package/dist/cli/commands/recordTriggerEval.test.js.map +1 -0
  293. package/dist/cli/commands/workspaces.js +1 -1
  294. package/dist/cli/commands/workspaces.js.map +1 -1
  295. package/dist/cli/main.js +22 -1
  296. package/dist/cli/main.js.map +1 -1
  297. package/dist/cli/python/knowledge_ingest.js +1048 -0
  298. package/dist/cli/python/knowledge_ingest.js.map +1 -0
  299. package/dist/cli/python/workspace_analytics.js +1085 -0
  300. package/dist/cli/python/workspace_analytics.js.map +1 -0
  301. package/dist/cli/python/workspace_crypto.js +544 -0
  302. package/dist/cli/python/workspace_crypto.js.map +1 -0
  303. package/dist/cli/python/workspace_documents.js +1216 -0
  304. package/dist/cli/python/workspace_documents.js.map +1 -0
  305. package/dist/cli/python/workspace_drive.js +574 -0
  306. package/dist/cli/python/workspace_drive.js.map +1 -0
  307. package/dist/cli/python/workspace_drive_health.js +628 -0
  308. package/dist/cli/python/workspace_drive_health.js.map +1 -0
  309. package/dist/cli/python/workspace_explain.js +765 -0
  310. package/dist/cli/python/workspace_explain.js.map +1 -0
  311. package/dist/cli/python/workspace_hosts.js +349 -0
  312. package/dist/cli/python/workspace_hosts.js.map +1 -0
  313. package/dist/cli/python/workspace_inbox.js +692 -0
  314. package/dist/cli/python/workspace_inbox.js.map +1 -0
  315. package/dist/cli/python/workspace_render.js +816 -0
  316. package/dist/cli/python/workspace_render.js.map +1 -0
  317. package/dist/cli/python/workspace_roles.js +487 -0
  318. package/dist/cli/python/workspace_roles.js.map +1 -0
  319. package/dist/cli/python/workspace_secrets.js +180 -0
  320. package/dist/cli/python/workspace_secrets.js.map +1 -0
  321. package/dist/cli/python/workspace_sessions.js +1079 -0
  322. package/dist/cli/python/workspace_sessions.js.map +1 -0
  323. package/dist/cli/python/workspace_skills.js +417 -0
  324. package/dist/cli/python/workspace_skills.js.map +1 -0
  325. package/dist/cli/registry.js +2 -0
  326. package/dist/cli/registry.js.map +1 -1
  327. package/dist/discovery/deprecation-report.md +1 -1
  328. package/dist/discovery/discovery-manifest.json +1174 -123
  329. package/dist/discovery/discovery-manifest.json.sha256 +1 -1
  330. package/dist/discovery/discovery-manifest.summary.md +9 -6
  331. package/dist/discovery/orphan-report.md +1 -1
  332. package/dist/discovery/packs.json +163 -15
  333. package/dist/discovery/trust-report.md +4 -4
  334. package/dist/discovery/workspaces.json +73 -12
  335. package/dist/install/install.mjs +13950 -0
  336. package/dist/mcp/registry-manifest.json +4 -4
  337. package/dist/router.json +1 -1
  338. package/dist/server/routes/wizard.js +50 -21
  339. package/dist/server/routes/wizard.js.map +1 -1
  340. package/dist/server/routes/workspace.js +44 -25
  341. package/dist/server/routes/workspace.js.map +1 -1
  342. package/dist/server/schemas/settings.js +15 -0
  343. package/dist/server/schemas/settings.js.map +1 -1
  344. package/docs/SKILL_CENSUS.md +344 -0
  345. package/docs/architecture/augment-projection.md +1 -1
  346. package/docs/architecture/multi-tool-projection.md +3 -3
  347. package/docs/architecture.md +37 -6
  348. package/docs/archive/CHANGELOG-7.0.0.md +419 -0
  349. package/docs/archive/CHANGELOG-pre-7.0.0.md +126 -0
  350. package/docs/benchmark.md +24 -27
  351. package/docs/capability-matrix.md +32 -0
  352. package/docs/catalog.md +50 -9
  353. package/docs/command-naming-audit.md +60 -0
  354. package/docs/contracts/STABILITY.md +32 -0
  355. package/docs/contracts/agents-md-tech-stack.md +1 -1
  356. package/docs/contracts/ai-council-config.md +22 -22
  357. package/docs/contracts/analysis-memory-loop.md +149 -0
  358. package/docs/contracts/benchmark-ab-contract.md +3 -3
  359. package/docs/contracts/branch-protection-policy.md +27 -0
  360. package/docs/contracts/brand-token-consumption.md +69 -0
  361. package/docs/contracts/command-clusters.md +2 -1
  362. package/docs/contracts/command-surface-tiers.md +13 -0
  363. package/docs/contracts/discovery-manifest.schema.json +24 -5
  364. package/docs/contracts/implement-ticket-flow.md +9 -9
  365. package/docs/contracts/install-layout.md +249 -0
  366. package/docs/contracts/kernel-membership.md +1 -1
  367. package/docs/contracts/linear-ai-rules-inclusion.md +2 -2
  368. package/docs/contracts/linter-structural-model.md +1 -1
  369. package/docs/contracts/mcp-discovery-phase-notice.md +1 -1
  370. package/docs/contracts/multi-tool-projection-fidelity.md +1 -1
  371. package/docs/contracts/namespace.md +2 -2
  372. package/docs/contracts/no-runtime-boundary.md +56 -0
  373. package/docs/contracts/package-self-orientation.md +24 -0
  374. package/docs/contracts/provider-lifecycle.md +3 -3
  375. package/docs/contracts/reasoning-discipline-protocol.md +83 -0
  376. package/docs/contracts/rule-classification.md +3 -3
  377. package/docs/contracts/skill-domains.md +1 -1
  378. package/docs/contracts/smoke-contracts.md +1 -1
  379. package/docs/contracts/surface-tiers.md +81 -0
  380. package/docs/contracts/ticket-bundle-format.md +228 -0
  381. package/docs/cookbook.md +152 -0
  382. package/docs/customization.md +12 -1
  383. package/docs/decisions/ADR-013-discovery-frontmatter-contract.md +16 -0
  384. package/docs/decisions/ADR-056-unvalidated-video-adapters-disposition.md +1 -1
  385. package/docs/decisions/ADR-059-render-resume-filesystem-as-state.md +1 -1
  386. package/docs/decisions/ADR-060-comfyui-sandbox-model.md +1 -1
  387. package/docs/decisions/ADR-061-corpus-grounding-layer.md +48 -1
  388. package/docs/decisions/ADR-096-analysis-workbench.md +110 -0
  389. package/docs/decisions/ADR-097-mission-recipe-privilege-boundary.md +121 -0
  390. package/docs/decisions/ADR-098-evidence-first-structure-discovery.md +154 -0
  391. package/docs/decisions/ADR-099-file-first-pattern-library.md +87 -0
  392. package/docs/decisions/ADR-100-global-knowledge-card-sharing.md +133 -0
  393. package/docs/decisions/ADR-101-ticket-bundle-emission.md +109 -0
  394. package/docs/decisions/ADR-102-ticket-handoff-paste-and-mcp.md +72 -0
  395. package/docs/decisions/ADR-103-global-knowledge-default-off-until-measured.md +92 -0
  396. package/docs/decisions/ADR-200-python-to-typescript-migration.md +193 -0
  397. package/docs/decisions/INDEX.md +9 -0
  398. package/docs/distribution/mcp-submission-checklist.md +3 -3
  399. package/docs/featured-commands.md +1 -1
  400. package/docs/featured-skills.md +1 -1
  401. package/docs/getting-started-by-role.md +2 -0
  402. package/docs/getting-started.md +2 -2
  403. package/docs/guidelines/agent-infra/failure-signatures.md +35 -0
  404. package/docs/guidelines/agent-infra/frontier-reasoning-operating-profile.md +5 -0
  405. package/docs/guidelines/agent-infra/size-and-scope.md +17 -0
  406. package/docs/guidelines/agent-infra/skill-quality-checklist.md +2 -2
  407. package/docs/guides/frontend-design-corpus-refresh.md +83 -0
  408. package/docs/guides/skill-preview.md +1 -1
  409. package/docs/hook-payload-capture.md +4 -4
  410. package/docs/mcp.md +1 -1
  411. package/docs/migration/consumer-template-consumption-model.md +145 -0
  412. package/docs/migration/divergences/README.md +55 -0
  413. package/docs/migration/divergences/_template.md +50 -0
  414. package/docs/migration/divergences/bench-stats-float-precision.md +72 -0
  415. package/docs/migration/divergences/mcp-telemetry-node-sqlite.md +61 -0
  416. package/docs/migration/divergences/pack-mcp-content-gzip-body.md +53 -0
  417. package/docs/migration/divergences/src-scripts-build_cloud_bundle.md +63 -0
  418. package/docs/migration/divergences/src-scripts-check_memory.md +91 -0
  419. package/docs/migration/divergences/src-scripts-inventory_abstraction_budget.md +65 -0
  420. package/docs/migration/divergences/src-scripts-lint_marketplace.md +57 -0
  421. package/docs/migration/divergences/src-scripts-lint_mcp_registry_manifest.md +70 -0
  422. package/docs/migration/divergences/src-scripts-spotcheck_thin_root.md +60 -0
  423. package/docs/migration/divergences/src-scripts-validate_agent_settings.md +58 -0
  424. package/docs/migration/node-floor.md +86 -0
  425. package/docs/migration/yaml-roundtrip-spike.md +163 -0
  426. package/docs/personas.md +6 -1
  427. package/docs/role-experiences.md +19 -0
  428. package/docs/setup/per-ide/windsurf.md +1 -1
  429. package/docs/skills-catalog.md +24 -3
  430. package/docs/threat-model.md +28 -0
  431. package/llms.txt +23 -2
  432. package/package.json +10 -15
  433. package/src/config/agent-settings.template.yml +64 -1
  434. package/src/config/discovery/packs.yml +31 -0
  435. package/src/config/discovery/unassigned-artefacts.yml +6 -0
  436. package/src/config/discovery/workspaces.yml +2 -2
  437. package/src/config/gitignore-block.txt +7 -0
  438. package/src/scripts/_cli/cmd_doctor.ts +2306 -0
  439. package/src/scripts/_cli/cmd_explain.ts +748 -0
  440. package/src/scripts/_cli/cmd_export.ts +375 -0
  441. package/src/scripts/_cli/cmd_migrate.ts +951 -0
  442. package/src/scripts/_cli/cmd_prune.ts +610 -0
  443. package/src/scripts/_cli/cmd_refresh.ts +530 -0
  444. package/src/scripts/_cli/cmd_settings_check.ts +407 -0
  445. package/src/scripts/_cli/cmd_settings_migrate.ts +344 -0
  446. package/src/scripts/_cli/cmd_sync.ts +381 -0
  447. package/src/scripts/_cli/cmd_uninstall.ts +833 -0
  448. package/src/scripts/_cli/cmd_update.ts +585 -0
  449. package/src/scripts/_cli/cmd_upgrade.ts +390 -0
  450. package/src/scripts/_cli/cmd_validate.ts +394 -0
  451. package/src/scripts/_cli/cmd_versions.ts +492 -0
  452. package/src/scripts/_cli/explain_last/assumptions.ts +114 -0
  453. package/src/scripts/_cli/explain_last/council.ts +197 -0
  454. package/src/scripts/_cli/explain_last/halt.ts +73 -0
  455. package/src/scripts/_cli/explain_last/index.ts +155 -0
  456. package/src/scripts/_cli/explain_last/inputs.ts +211 -0
  457. package/src/scripts/_cli/explain_last/memory.ts +231 -0
  458. package/src/scripts/_cli/explain_last/provider.ts +82 -0
  459. package/src/scripts/_cli/explain_last/render.ts +54 -0
  460. package/src/scripts/_cli/explain_last/route.ts +70 -0
  461. package/src/scripts/_cli/explain_last/scrubber.ts +138 -0
  462. package/src/scripts/_cli/explain_last/sections/assumptions.ts +51 -0
  463. package/src/scripts/_cli/explain_last/sections/council.ts +56 -0
  464. package/src/scripts/_cli/explain_last/sections/halt.ts +60 -0
  465. package/src/scripts/_cli/explain_last/sections/header.ts +50 -0
  466. package/src/scripts/_cli/explain_last/sections/index.ts +21 -0
  467. package/src/scripts/_cli/explain_last/sections/inputs.ts +63 -0
  468. package/src/scripts/_cli/explain_last/sections/memory.ts +124 -0
  469. package/src/scripts/_cli/explain_last/sections/pack.ts +42 -0
  470. package/src/scripts/_cli/explain_last/sections/provider.ts +51 -0
  471. package/src/scripts/_cli/explain_last/sections/route.ts +48 -0
  472. package/src/scripts/_cli/explain_last/state_loader.ts +119 -0
  473. package/src/scripts/_dispatch.bash +179 -163
  474. package/src/scripts/_lib/agent_settings.ts +1123 -0
  475. package/src/scripts/_lib/agent_src.ts +654 -0
  476. package/src/scripts/_lib/agents_overlay.ts +183 -0
  477. package/src/scripts/_lib/bench_ab_cache.ts +399 -0
  478. package/src/scripts/_lib/bench_ab_scoring.ts +352 -0
  479. package/src/scripts/_lib/bench_ab_scoring_v2.ts +751 -0
  480. package/src/scripts/_lib/bench_cost.ts +396 -0
  481. package/src/scripts/_lib/bench_quality.ts +237 -0
  482. package/src/scripts/_lib/bench_report.ts +255 -0
  483. package/src/scripts/_lib/bench_telegraph.ts +516 -0
  484. package/src/scripts/_lib/bench_telegraph_report.ts +272 -0
  485. package/src/scripts/_lib/changelog_eras.ts +456 -0
  486. package/src/scripts/_lib/claude_desktop_bundler.ts +324 -0
  487. package/src/scripts/_lib/cli_wrapper.ts +89 -0
  488. package/src/scripts/_lib/fs_atomic.ts +172 -0
  489. package/src/scripts/_lib/global_deploy_inventory.ts +639 -0
  490. package/src/scripts/_lib/install_layout.ts +87 -0
  491. package/src/scripts/_lib/install_regenerator.ts +157 -0
  492. package/src/scripts/_lib/installed_lock.ts +486 -0
  493. package/src/scripts/_lib/installed_tools.ts +518 -0
  494. package/src/scripts/_lib/json_pointers.ts +388 -0
  495. package/src/scripts/_lib/knowledge_global.ts +770 -0
  496. package/src/scripts/_lib/knowledge_global_promote.ts +453 -0
  497. package/src/scripts/_lib/knowledge_global_redaction.ts +448 -0
  498. package/src/scripts/_lib/link_crypto.ts +325 -0
  499. package/src/scripts/_lib/linked_projects.ts +613 -0
  500. package/src/scripts/_lib/model_tier.ts +65 -0
  501. package/src/scripts/_lib/module_detection.ts +275 -0
  502. package/src/scripts/_lib/node_sqlite.d.ts +32 -0
  503. package/src/scripts/_lib/pin_resolver.ts +264 -0
  504. package/src/scripts/_lib/py_random.ts +212 -0
  505. package/src/scripts/_lib/script_output.ts +147 -0
  506. package/src/scripts/_lib/security_lint.ts +623 -0
  507. package/src/scripts/_lib/surface_tiers.ts +127 -0
  508. package/src/scripts/_lib/token_count.ts +126 -0
  509. package/src/scripts/_lib/update_check.ts +297 -0
  510. package/src/scripts/_lib/user_global_paths.ts +329 -0
  511. package/src/scripts/_lib/value_ladder.ts +882 -0
  512. package/src/scripts/_lib/value_report.ts +617 -0
  513. package/src/scripts/_lib/zip_min.ts +175 -0
  514. package/src/scripts/adoption_report.ts +357 -0
  515. package/src/scripts/adoption_snapshot.ts +392 -0
  516. package/src/scripts/adoption_status.ts +424 -0
  517. package/src/scripts/adr/regenerate_index.ts +257 -0
  518. package/src/scripts/ai-image/adapters/flux.sh +45 -0
  519. package/src/scripts/ai-image/adapters/gemini-image.sh +45 -0
  520. package/src/scripts/ai-image/adapters/ideogram.sh +45 -0
  521. package/src/scripts/ai-image/adapters/recraft.sh +47 -0
  522. package/src/scripts/ai-video/adapters/comfyui.sh +3 -3
  523. package/src/scripts/ai-video/adapters/fal.sh +3 -3
  524. package/src/scripts/ai-video/adapters/gemini-veo.sh +3 -3
  525. package/src/scripts/ai-video/adapters/higgsfield.sh +3 -3
  526. package/src/scripts/ai-video/adapters/kling.sh +3 -3
  527. package/src/scripts/ai-video/adapters/musetalk.sh +2 -2
  528. package/src/scripts/ai-video/adapters/openai-images.sh +3 -3
  529. package/src/scripts/ai-video/adapters/replicate.sh +3 -3
  530. package/src/scripts/ai-video/adapters/sora.sh +3 -3
  531. package/src/scripts/ai-video/adapters/syncso.sh +3 -3
  532. package/src/scripts/ai-video/audio-adapters/allin1.sh +2 -2
  533. package/src/scripts/ai-video/audio-adapters/whisperx.sh +2 -2
  534. package/src/scripts/ai-video/lib/audio-adapter-contract.md +1 -1
  535. package/src/scripts/ai-video/lib/embed-provenance.sh +2 -2
  536. package/src/scripts/ai-video/lib/ingest-song.sh +2 -2
  537. package/src/scripts/ai-video/lib/parse-blueprint.sh +1 -1
  538. package/src/scripts/ai-video/lib/resume-scan.sh +2 -2
  539. package/src/scripts/ai-video/smoke-trace.sh +16 -7
  540. package/src/scripts/ai-video/stitch.sh +2 -2
  541. package/src/scripts/ai_council/_default_prices.ts +73 -0
  542. package/src/scripts/ai_council/advisors.ts +244 -0
  543. package/src/scripts/ai_council/airgap.ts +249 -0
  544. package/src/scripts/ai_council/budget_guard.ts +492 -0
  545. package/src/scripts/ai_council/bundler.ts +376 -0
  546. package/src/scripts/ai_council/cli_hints.ts +120 -0
  547. package/src/scripts/ai_council/clients.ts +2214 -0
  548. package/src/scripts/ai_council/compile_corpus.ts +681 -0
  549. package/src/scripts/ai_council/confidence_gate.ts +230 -0
  550. package/src/scripts/ai_council/config.ts +1729 -0
  551. package/src/scripts/ai_council/consensus.ts +551 -0
  552. package/src/scripts/ai_council/events_log.ts +327 -0
  553. package/src/scripts/ai_council/learn_low_impact_preview.ts +317 -0
  554. package/src/scripts/ai_council/low_impact.ts +1069 -0
  555. package/src/scripts/ai_council/low_impact_corpus.ts +662 -0
  556. package/src/scripts/ai_council/low_impact_intake.ts +222 -0
  557. package/src/scripts/ai_council/modes.ts +169 -0
  558. package/src/scripts/ai_council/necessity.ts +933 -0
  559. package/src/scripts/ai_council/orchestrator.ts +1689 -0
  560. package/src/scripts/ai_council/pricing.ts +267 -0
  561. package/src/scripts/ai_council/probation_gate.ts +282 -0
  562. package/src/scripts/ai_council/project_context.ts +308 -0
  563. package/src/scripts/ai_council/prompts.ts +600 -0
  564. package/src/scripts/ai_council/redact_low_impact_entry.ts +291 -0
  565. package/src/scripts/ai_council/replay.ts +314 -0
  566. package/src/scripts/ai_council/session.ts +558 -0
  567. package/src/scripts/ai_council/shadow_dispatch.ts +509 -0
  568. package/src/scripts/ai_council/solo_dispatch.ts +281 -0
  569. package/src/scripts/analysis_freshness.ts +343 -0
  570. package/src/scripts/annotate_discovery.ts +288 -0
  571. package/src/scripts/apply_modules_config.ts +537 -0
  572. package/src/scripts/audit_adr_coverage.ts +357 -0
  573. package/src/scripts/audit_auto_rules.ts +415 -0
  574. package/src/scripts/audit_cloud_compatibility.ts +608 -0
  575. package/src/scripts/audit_command_surface.ts +1227 -0
  576. package/src/scripts/audit_initial_context.ts +694 -0
  577. package/src/scripts/audit_likelihood.ts +434 -0
  578. package/src/scripts/audit_mcp_tools.ts +252 -0
  579. package/src/scripts/audit_overlap.ts +421 -0
  580. package/src/scripts/audit_skill_descriptions.ts +402 -0
  581. package/src/scripts/audit_skill_overlap.ts +576 -0
  582. package/src/scripts/audit_user_type_axis.ts +264 -0
  583. package/src/scripts/backfill_model_tier.ts +349 -0
  584. package/src/scripts/bench_ab_cache_dispatch.ts +126 -0
  585. package/src/scripts/bench_ab_clone.ts +610 -0
  586. package/src/scripts/bench_ab_diff.ts +609 -0
  587. package/src/scripts/bench_ab_integrity.ts +261 -0
  588. package/src/scripts/bench_ab_run.ts +417 -0
  589. package/src/scripts/bench_ab_task_runner.ts +1382 -0
  590. package/src/scripts/bench_ab_tracka_run.ts +436 -0
  591. package/src/scripts/bench_ab_v2_run.ts +585 -0
  592. package/src/scripts/bench_ab_v2_stats.ts +1018 -0
  593. package/src/scripts/bench_baseline_ready.ts +326 -0
  594. package/src/scripts/bench_condense_memory.ts +479 -0
  595. package/src/scripts/bench_drift_check.ts +503 -0
  596. package/src/scripts/bench_per_tool.ts +591 -0
  597. package/src/scripts/bench_rtk_savings.ts +710 -0
  598. package/src/scripts/bench_run.ts +509 -0
  599. package/src/scripts/bench_runner.ts +519 -0
  600. package/src/scripts/build_cloud_bundle.ts +692 -0
  601. package/src/scripts/build_discovery_manifest.ts +1371 -0
  602. package/src/scripts/build_linear_digest.ts +368 -0
  603. package/src/scripts/build_mcp_registry_manifest.ts +351 -0
  604. package/src/scripts/build_rule_trigger_matrix.ts +469 -0
  605. package/src/scripts/capture_showcase_session.ts +735 -0
  606. package/src/scripts/chat_history.ts +2301 -0
  607. package/src/scripts/check_always_budget.ts +694 -0
  608. package/src/scripts/check_artefact_checksums.ts +281 -0
  609. package/src/scripts/check_augment_description_cap.ts +133 -0
  610. package/src/scripts/check_augmentignore.ts +108 -0
  611. package/src/scripts/check_beta_review_markers.ts +234 -0
  612. package/src/scripts/check_bite_sized_granularity.ts +116 -0
  613. package/src/scripts/check_cluster_patterns.ts +285 -0
  614. package/src/scripts/check_command_count_messaging.ts +224 -0
  615. package/src/scripts/check_condensation.ts +900 -0
  616. package/src/scripts/check_condensed_paths.ts +414 -0
  617. package/src/scripts/check_context_paths.ts +388 -0
  618. package/src/scripts/check_council_config_location.ts +260 -0
  619. package/src/scripts/check_council_layout.ts +180 -0
  620. package/src/scripts/check_council_references.ts +345 -0
  621. package/src/scripts/check_discovery_determinism.ts +124 -0
  622. package/src/scripts/check_gate_paths.ts +230 -0
  623. package/src/scripts/check_iron_law_prominence.ts +298 -0
  624. package/src/scripts/check_kernel_rule_bundle.ts +242 -0
  625. package/src/scripts/check_knowledge_cards.ts +759 -0
  626. package/src/scripts/check_md_language.ts +291 -0
  627. package/src/scripts/check_memory.ts +845 -0
  628. package/src/scripts/check_memory_proposal.ts +351 -0
  629. package/src/scripts/check_module_management_neutral.ts +238 -0
  630. package/src/scripts/check_no_conflict_markers.ts +298 -0
  631. package/src/scripts/check_no_conflict_markers_allowlist.json +4 -0
  632. package/src/scripts/check_no_external_sources.ts +351 -0
  633. package/src/scripts/check_no_local_settings_committed.ts +69 -0
  634. package/src/scripts/check_no_new_legacy_path.ts +188 -0
  635. package/src/scripts/check_no_roadmap_refs.ts +304 -0
  636. package/src/scripts/check_one_off_location.ts +165 -0
  637. package/src/scripts/check_overlay_cascade_subdirs.ts +188 -0
  638. package/src/scripts/check_portability.ts +860 -0
  639. package/src/scripts/check_proposal.ts +0 -0
  640. package/src/scripts/check_public_catalog_links.ts +204 -0
  641. package/src/scripts/check_public_links.ts +357 -0
  642. package/src/scripts/check_references.ts +963 -0
  643. package/src/scripts/check_release_includes_discovery.ts +94 -0
  644. package/src/scripts/check_release_pr_shape.ts +222 -0
  645. package/src/scripts/check_release_published.ts +235 -0
  646. package/src/scripts/check_release_trunk_sync.ts +203 -0
  647. package/src/scripts/check_reply_consistency.ts +359 -0
  648. package/src/scripts/check_roadmap_trackable.ts +268 -0
  649. package/src/scripts/check_role_doc_links.ts +187 -0
  650. package/src/scripts/check_safety_floor_untouched.ts +160 -0
  651. package/src/scripts/check_skill_requires.ts +205 -0
  652. package/src/scripts/check_structural_breaking.ts +170 -0
  653. package/src/scripts/check_surface_tiers.ts +567 -0
  654. package/src/scripts/check_template_pin_drift.ts +222 -0
  655. package/src/scripts/check_test_coverage_diff.ts +235 -0
  656. package/src/scripts/check_token_optimizer_freshness.ts +183 -0
  657. package/src/scripts/check_trigger_evals.ts +375 -0
  658. package/src/scripts/check_update_banner.ts +143 -0
  659. package/src/scripts/ci_status.ts +0 -0
  660. package/src/scripts/ci_summary.ts +235 -0
  661. package/src/scripts/ci_time_ratio.ts +526 -0
  662. package/src/scripts/command_suggester/cooldown.ts +176 -0
  663. package/src/scripts/command_suggester/index.ts +41 -0
  664. package/src/scripts/command_suggester/loader.ts +205 -0
  665. package/src/scripts/command_suggester/match.ts +294 -0
  666. package/src/scripts/command_suggester/rank.ts +201 -0
  667. package/src/scripts/command_suggester/render.ts +122 -0
  668. package/src/scripts/command_suggester/sanitize.ts +114 -0
  669. package/src/scripts/command_suggester/settings.ts +186 -0
  670. package/src/scripts/command_suggester/types.ts +0 -0
  671. package/src/scripts/compile_router.ts +297 -0
  672. package/src/scripts/condense.sh +7 -1
  673. package/src/scripts/condense.ts +2035 -0
  674. package/src/scripts/condense_memory.ts +334 -0
  675. package/src/scripts/config/index.ts +15 -0
  676. package/src/scripts/config/packs.ts +310 -0
  677. package/src/scripts/config/presets.ts +369 -0
  678. package/src/scripts/config/profile_explain.ts +114 -0
  679. package/src/scripts/config/profiles.ts +277 -0
  680. package/src/scripts/config/session_profiles.ts +1064 -0
  681. package/src/scripts/context_hygiene_hook.ts +272 -0
  682. package/src/scripts/cost_by_conversation.ts +444 -0
  683. package/src/scripts/cost_summary.ts +407 -0
  684. package/src/scripts/council_cli.ts +2827 -0
  685. package/src/scripts/council_prune.ts +153 -0
  686. package/src/scripts/cross_repo_retrieve.ts +694 -0
  687. package/src/scripts/discovery_stats.ts +218 -0
  688. package/src/scripts/evidence_report.ts +580 -0
  689. package/src/scripts/external_sources_denylist.json +1 -0
  690. package/src/scripts/extract_audit_patterns.ts +394 -0
  691. package/src/scripts/first_run_gate_hook.ts +246 -0
  692. package/src/scripts/gen_discovery_baseline.ts +297 -0
  693. package/src/scripts/generate_capabilities_index.ts +496 -0
  694. package/src/scripts/generate_capability_matrix.ts +430 -0
  695. package/src/scripts/generate_catalog.ts +178 -0
  696. package/src/scripts/generate_command_flows.ts +316 -0
  697. package/src/scripts/generate_cookbook.ts +302 -0
  698. package/src/scripts/generate_index.ts +500 -0
  699. package/src/scripts/generate_ownership_matrix.ts +646 -0
  700. package/src/scripts/generate_pack_manifests.ts +1025 -0
  701. package/src/scripts/generate_role_experiences_catalog.ts +265 -0
  702. package/src/scripts/hermetic-install.sh +22 -11
  703. package/src/scripts/hook_manifest.yaml +24 -10
  704. package/src/scripts/hooks/augment-chat-history.sh +3 -10
  705. package/src/scripts/hooks/augment-context-hygiene.sh +3 -10
  706. package/src/scripts/hooks/augment-dispatcher.sh +3 -10
  707. package/src/scripts/hooks/augment-onboarding-gate.sh +3 -10
  708. package/src/scripts/hooks/augment-roadmap-progress.sh +3 -10
  709. package/src/scripts/hooks/block_no_verify.ts +413 -0
  710. package/src/scripts/hooks/cline-dispatcher.sh +3 -10
  711. package/src/scripts/hooks/cowork-dispatcher.sh +3 -14
  712. package/src/scripts/hooks/cursor-dispatcher.sh +3 -10
  713. package/src/scripts/hooks/dispatch_hook.ts +851 -0
  714. package/src/scripts/hooks/dispatch_issues.ts +226 -0
  715. package/src/scripts/hooks/envelope.ts +140 -0
  716. package/src/scripts/hooks/gemini-dispatcher.sh +3 -8
  717. package/src/scripts/hooks/replay_hook.ts +364 -0
  718. package/src/scripts/hooks/state_io.ts +293 -0
  719. package/src/scripts/hooks/windsurf-dispatcher.sh +3 -9
  720. package/src/scripts/hooks_doctor.ts +418 -0
  721. package/src/scripts/hooks_status.ts +292 -0
  722. package/src/scripts/injection_scan_hook.ts +285 -0
  723. package/src/scripts/install +36 -22
  724. package/src/scripts/install-hooks.sh +20 -14
  725. package/src/scripts/install.sh +38 -14
  726. package/src/scripts/install.ts +4515 -0
  727. package/src/scripts/inventory_abstraction_budget.ts +1104 -0
  728. package/src/scripts/inventory_frontmatter.ts +320 -0
  729. package/src/scripts/inventory_meta_layers.ts +516 -0
  730. package/src/scripts/iron_law_sha.ts +233 -0
  731. package/src/scripts/knowledge_global_cli.ts +1105 -0
  732. package/src/scripts/linked_projects_list.ts +310 -0
  733. package/src/scripts/lint_agent_security.ts +224 -0
  734. package/src/scripts/lint_agent_skill_names.ts +241 -0
  735. package/src/scripts/lint_agents_layout.ts +205 -0
  736. package/src/scripts/lint_agents_md.ts +294 -0
  737. package/src/scripts/lint_archived_skills.ts +309 -0
  738. package/src/scripts/lint_artefact_frontmatter.ts +359 -0
  739. package/src/scripts/lint_bench_ab.ts +319 -0
  740. package/src/scripts/lint_bench_corpus.ts +421 -0
  741. package/src/scripts/lint_command_flow_coverage.ts +231 -0
  742. package/src/scripts/lint_command_routing.ts +377 -0
  743. package/src/scripts/lint_command_tiers.ts +345 -0
  744. package/src/scripts/lint_command_verbs.ts +379 -0
  745. package/src/scripts/lint_commit_subjects.ts +243 -0
  746. package/src/scripts/lint_context_spine_usage.ts +198 -0
  747. package/src/scripts/lint_discovery_manifest.ts +540 -0
  748. package/src/scripts/lint_discovery_vocabulary.ts +393 -0
  749. package/src/scripts/lint_empty_roadmaps.ts +147 -0
  750. package/src/scripts/lint_eval_freshness.ts +335 -0
  751. package/src/scripts/lint_examples.ts +183 -0
  752. package/src/scripts/lint_explain_trace.ts +381 -0
  753. package/src/scripts/lint_featured_skills.ts +0 -0
  754. package/src/scripts/lint_flows.ts +701 -0
  755. package/src/scripts/lint_framework_leakage.ts +497 -0
  756. package/src/scripts/lint_framework_leakage_allowlist.json +8 -1
  757. package/src/scripts/lint_frontmatter_boilerplate.ts +356 -0
  758. package/src/scripts/lint_ghostwriter_source.ts +389 -0
  759. package/src/scripts/lint_global_paths.ts +420 -0
  760. package/src/scripts/lint_handoffs.ts +362 -0
  761. package/src/scripts/lint_hidden_unicode.ts +350 -0
  762. package/src/scripts/lint_hook_concern_budget.ts +319 -0
  763. package/src/scripts/lint_hook_manifest.ts +354 -0
  764. package/src/scripts/lint_instruction_smuggling.ts +173 -0
  765. package/src/scripts/lint_load_context.ts +371 -0
  766. package/src/scripts/lint_marketplace.ts +286 -0
  767. package/src/scripts/lint_marketplace_install_completeness.ts +309 -0
  768. package/src/scripts/lint_mcp_config_security.ts +225 -0
  769. package/src/scripts/lint_mcp_registry_manifest.ts +350 -0
  770. package/src/scripts/lint_media_policy_linkage.ts +224 -0
  771. package/src/scripts/lint_missions.ts +774 -0
  772. package/src/scripts/lint_model_tier_coverage.ts +151 -0
  773. package/src/scripts/lint_namespace.ts +295 -0
  774. package/src/scripts/lint_namespace_collisions.ts +203 -0
  775. package/src/scripts/lint_new_skill_gate.ts +462 -0
  776. package/src/scripts/lint_no_new_atomic_commands.ts +342 -0
  777. package/src/scripts/lint_one_off_age.ts +348 -0
  778. package/src/scripts/lint_orchestration_dsl.ts +377 -0
  779. package/src/scripts/lint_orchestrator_auto_detect.ts +177 -0
  780. package/src/scripts/lint_pack_boundaries.ts +366 -0
  781. package/src/scripts/lint_pack_dependencies.ts +541 -0
  782. package/src/scripts/lint_pack_first_win.ts +202 -0
  783. package/src/scripts/lint_persona_governance.ts +292 -0
  784. package/src/scripts/lint_positioning.ts +257 -0
  785. package/src/scripts/lint_profile_overlay_set_only.ts +324 -0
  786. package/src/scripts/lint_readme_jargon.ts +189 -0
  787. package/src/scripts/lint_readme_size.ts +73 -0
  788. package/src/scripts/lint_regression.ts +497 -0
  789. package/src/scripts/lint_roadmap_ci_steps.ts +252 -0
  790. package/src/scripts/lint_roadmap_complexity.ts +295 -0
  791. package/src/scripts/lint_roadmap_later_disposition.ts +357 -0
  792. package/src/scripts/lint_role_experiences.ts +410 -0
  793. package/src/scripts/lint_rule_interactions.ts +281 -0
  794. package/src/scripts/lint_rule_tiers.ts +169 -0
  795. package/src/scripts/lint_showcase_sessions.ts +254 -0
  796. package/src/scripts/lint_skill_frontmatter_safety.ts +279 -0
  797. package/src/scripts/lint_skill_originality.ts +586 -0
  798. package/src/scripts/lint_skill_originality_allowlist.json +20 -0
  799. package/src/scripts/lint_skill_tools.ts +320 -0
  800. package/src/scripts/lint_ticket_buildable.ts +1027 -0
  801. package/src/scripts/lint_topics_yaml.ts +203 -0
  802. package/src/scripts/lint_trust_coherence.ts +377 -0
  803. package/src/scripts/lint_value_dashboard.ts +314 -0
  804. package/src/scripts/lint_workflow_security.ts +637 -0
  805. package/src/scripts/lint_workflow_security_allowlist.json +20 -0
  806. package/src/scripts/lint_workspace_boundary.ts +248 -0
  807. package/src/scripts/mcp_parity_smoke.ts +638 -0
  808. package/src/scripts/mcp_render.ts +346 -0
  809. package/src/scripts/mcp_server/__main__.ts +28 -0
  810. package/src/scripts/mcp_server/catalog.ts +154 -0
  811. package/src/scripts/mcp_server/index.ts +24 -0
  812. package/src/scripts/mcp_server/metadata.ts +83 -0
  813. package/src/scripts/mcp_server/prompts.ts +711 -0
  814. package/src/scripts/mcp_server/resources.ts +343 -0
  815. package/src/scripts/mcp_server/server.ts +439 -0
  816. package/src/scripts/mcp_server/telemetry.ts +154 -0
  817. package/src/scripts/mcp_server/tools.ts +1031 -0
  818. package/src/scripts/mcp_setup.sh +25 -52
  819. package/src/scripts/mcp_telemetry_health.ts +362 -0
  820. package/src/scripts/mcp_telemetry_query.ts +371 -0
  821. package/src/scripts/mcp_telemetry_store.ts +422 -0
  822. package/src/scripts/measure_augment_budget.ts +453 -0
  823. package/src/scripts/measure_density.ts +618 -0
  824. package/src/scripts/measure_frugality_savings.ts +353 -0
  825. package/src/scripts/measure_markitdown_lift.ts +299 -0
  826. package/src/scripts/measure_patterns.ts +682 -0
  827. package/src/scripts/measure_projection_bytes.ts +425 -0
  828. package/src/scripts/measure_rule_budget.ts +627 -0
  829. package/src/scripts/measure_skill_reduction.ts +442 -0
  830. package/src/scripts/media/lib/adapter-common.sh +247 -0
  831. package/src/scripts/media/lib/adapter-contract.md +329 -0
  832. package/src/scripts/media/lib/fixtures/comfyui/result.json +1 -0
  833. package/src/scripts/media/lib/fixtures/fal/result.json +1 -0
  834. package/src/scripts/media/lib/fixtures/flux/asset-0001.png +0 -0
  835. package/src/scripts/media/lib/fixtures/flux/result.json +1 -0
  836. package/src/scripts/media/lib/fixtures/gemini-image/asset-0001.png +0 -0
  837. package/src/scripts/media/lib/fixtures/gemini-image/result.json +1 -0
  838. package/src/scripts/media/lib/fixtures/gemini-veo/result.json +1 -0
  839. package/src/scripts/media/lib/fixtures/higgsfield/result.json +1 -0
  840. package/src/scripts/media/lib/fixtures/ideogram/asset-0001.png +0 -0
  841. package/src/scripts/media/lib/fixtures/ideogram/result.json +1 -0
  842. package/src/scripts/media/lib/fixtures/kling/result.json +1 -0
  843. package/src/scripts/media/lib/fixtures/musetalk/result.json +1 -0
  844. package/src/scripts/media/lib/fixtures/openai-images/result.json +1 -0
  845. package/src/scripts/media/lib/fixtures/recraft/asset-0001.svg +1 -0
  846. package/src/scripts/media/lib/fixtures/recraft/result.json +1 -0
  847. package/src/scripts/media/lib/fixtures/replicate/result.json +1 -0
  848. package/src/scripts/media/lib/fixtures/sora/result.json +1 -0
  849. package/src/scripts/media/lib/fixtures/syncso/result.json +1 -0
  850. package/src/scripts/media/lib/load-config.sh +180 -0
  851. package/src/scripts/media/lib/redact.sh +85 -0
  852. package/src/scripts/memory_hash.ts +331 -0
  853. package/src/scripts/memory_lookup.ts +1278 -0
  854. package/src/scripts/memory_report.ts +845 -0
  855. package/src/scripts/memory_signal.ts +417 -0
  856. package/src/scripts/memory_status.ts +189 -0
  857. package/src/scripts/migrate_command_suggestions.ts +341 -0
  858. package/src/scripts/migrate_frontmatter_defaults.ts +539 -0
  859. package/src/scripts/migration_status.ts +301 -0
  860. package/src/scripts/mine_session.ts +645 -0
  861. package/src/scripts/minimal_safe_diff_hook.ts +355 -0
  862. package/src/scripts/move_artefact.ts +869 -0
  863. package/src/scripts/new_skill.ts +404 -0
  864. package/src/scripts/onboarding_gate_hook.ts +224 -0
  865. package/src/scripts/pack_dependency_allowlist.json +1 -1
  866. package/src/scripts/pack_mcp_content.ts +552 -0
  867. package/src/scripts/parity/README.md +140 -0
  868. package/src/scripts/parity/compare.ts +189 -0
  869. package/src/scripts/parity/coverage_diff.ts +199 -0
  870. package/src/scripts/parity/phase-manifest.json +93 -0
  871. package/src/scripts/parity/phase_gate.ts +270 -0
  872. package/src/scripts/parity/replay.ts +320 -0
  873. package/src/scripts/pattern_share.ts +363 -0
  874. package/src/scripts/plan_physical_move.ts +605 -0
  875. package/src/scripts/prediction-pool/poisson_sim.ts +537 -0
  876. package/src/scripts/prediction-pool/pool_winsim.ts +677 -0
  877. package/src/scripts/prediction-pool/score_ev.ts +546 -0
  878. package/src/scripts/print_required_checks.ts +249 -0
  879. package/src/scripts/probe_projection_fidelity.ts +468 -0
  880. package/src/scripts/probe_skill_registration.ts +787 -0
  881. package/src/scripts/profile_staleness_hook.ts +169 -0
  882. package/src/scripts/profile_use.ts +227 -0
  883. package/src/scripts/project_thin_rules.ts +387 -0
  884. package/src/scripts/propose_modules_config.ts +311 -0
  885. package/src/scripts/prototype_lint_contradictions.ts +414 -0
  886. package/src/scripts/prove_pack_extractable.ts +388 -0
  887. package/src/scripts/readme_linter.ts +913 -0
  888. package/src/scripts/redact_hook_capture.ts +325 -0
  889. package/src/scripts/refine_ticket_detect.ts +703 -0
  890. package/src/scripts/release.ts +1748 -0
  891. package/src/scripts/render_benchmark_md.ts +664 -0
  892. package/src/scripts/render_value_md.ts +506 -0
  893. package/src/scripts/repro/repro_marketplace_install_gap.sh +1 -1
  894. package/src/scripts/roadmap_progress_hook.ts +410 -0
  895. package/src/scripts/router_telemetry.ts +972 -0
  896. package/src/scripts/run.ts +98 -0
  897. package/src/scripts/run_skill_evals.ts +477 -0
  898. package/src/scripts/runtime_dispatcher.ts +586 -0
  899. package/src/scripts/runtime_handler.ts +231 -0
  900. package/src/scripts/runtime_registry.ts +394 -0
  901. package/src/scripts/schemas/command.schema.json +3 -2
  902. package/src/scripts/schemas/mission-catalog.schema.json +112 -0
  903. package/src/scripts/schemas/mission.schema.json +87 -0
  904. package/src/scripts/schemas/pack.schema.json +6 -0
  905. package/src/scripts/schemas/rule.schema.json +1 -0
  906. package/src/scripts/schemas/skill.schema.json +1 -0
  907. package/src/scripts/schemas/ticket-manifest.schema.json +35 -0
  908. package/src/scripts/schemas/ticket.schema.json +60 -0
  909. package/src/scripts/score_skill_selection.ts +570 -0
  910. package/src/scripts/security_audit_config.ts +423 -0
  911. package/src/scripts/skill_collision_clusters.ts +448 -0
  912. package/src/scripts/skill_discovery.ts +690 -0
  913. package/src/scripts/skill_linter.ts +4276 -0
  914. package/src/scripts/skill_overlap.ts +414 -0
  915. package/src/scripts/skill_preview.ts +548 -0
  916. package/src/scripts/skill_tools/audit_persona_coverage.ts +427 -0
  917. package/src/scripts/skill_tools/audit_user_type_coverage.ts +507 -0
  918. package/src/scripts/skill_tools/index.ts +28 -0
  919. package/src/scripts/skill_tools/run_block_d_eval.ts +373 -0
  920. package/src/scripts/skill_tools/score_skill_relevance.ts +475 -0
  921. package/src/scripts/skill_tools/suggest_skill_for_task.ts +288 -0
  922. package/src/scripts/skill_trigger_eval.ts +1046 -0
  923. package/src/scripts/skill_usage_collect.ts +465 -0
  924. package/src/scripts/skill_usage_report.ts +364 -0
  925. package/src/scripts/smoke/kernel.sh +4 -5
  926. package/src/scripts/smoke/router.sh +76 -76
  927. package/src/scripts/smoke/schema.sh +2 -2
  928. package/src/scripts/smoke/skills.sh +73 -52
  929. package/src/scripts/smoke_path_resolution.ts +194 -0
  930. package/src/scripts/smoke_quickstart.ts +224 -0
  931. package/src/scripts/snapshot_agent_outputs.ts +375 -0
  932. package/src/scripts/spotcheck_thin_root.ts +247 -0
  933. package/src/scripts/surface-tiers.yml +68 -0
  934. package/src/scripts/sync_agent_settings.ts +763 -0
  935. package/src/scripts/sync_github_metadata.ts +550 -0
  936. package/src/scripts/sync_gitignore.ts +630 -0
  937. package/src/scripts/sync_yaml_rt.ts +910 -0
  938. package/src/scripts/telegraph_stats.ts +447 -0
  939. package/src/scripts/tool_registry.ts +330 -0
  940. package/src/scripts/tools/adapter_errors.ts +93 -0
  941. package/src/scripts/tools/base_adapter.ts +147 -0
  942. package/src/scripts/tools/github_adapter.ts +229 -0
  943. package/src/scripts/tools/jira_adapter.ts +196 -0
  944. package/src/scripts/trigger_coverage.ts +251 -0
  945. package/src/scripts/update_counts.ts +284 -0
  946. package/src/scripts/update_prices.ts +219 -0
  947. package/src/scripts/validate_agent_settings.ts +265 -0
  948. package/src/scripts/validate_decision_engine.ts +366 -0
  949. package/src/scripts/validate_discovery_manifest.ts +160 -0
  950. package/src/scripts/validate_frontmatter.ts +1030 -0
  951. package/src/scripts/validate_pack_yaml.ts +0 -0
  952. package/src/scripts/validate_safe_paths.ts +164 -0
  953. package/src/scripts/validate_telegraph_carveouts.ts +485 -0
  954. package/src/scripts/verify_before_complete_hook.ts +306 -0
  955. package/src/scripts/verify_physical_move.ts +411 -0
  956. package/src/scripts/wrapper_freshness_hook.ts +179 -0
  957. package/dist/agent-src/scripts/archive_completed_roadmaps.py +0 -171
  958. package/dist/agent-src/scripts/update_roadmap_progress.py +0 -537
  959. package/dist/agent-src/skills/corpus-grounding/scripts/bm25_search.py +0 -212
  960. package/dist/agent-src/skills/corpus-grounding/scripts/decision_engine.py +0 -438
  961. package/dist/agent-src/skills/corpus-grounding/scripts/ground.py +0 -166
  962. package/dist/agent-src/skills/corpus-grounding/scripts/schema_validator.py +0 -160
  963. package/dist/agent-src/skills/design-tokens/scripts/tokens.py +0 -296
  964. package/dist/agent-src/skills/react-shadcn-ui/scripts/shadcn_add.py +0 -299
  965. package/dist/agent-src/skills/tailwind-engineer/scripts/tailwind_config_gen.py +0 -463
  966. package/dist/agent-src/templates/scripts/check_memory.py +0 -282
  967. package/dist/agent-src/templates/scripts/check_memory_proposal.py +0 -180
  968. package/dist/agent-src/templates/scripts/implement_ticket/__init__.py +0 -94
  969. package/dist/agent-src/templates/scripts/implement_ticket/__main__.py +0 -15
  970. package/dist/agent-src/templates/scripts/memory_hash.py +0 -75
  971. package/dist/agent-src/templates/scripts/memory_lookup.py +0 -436
  972. package/dist/agent-src/templates/scripts/memory_report.py +0 -314
  973. package/dist/agent-src/templates/scripts/memory_signal.py +0 -165
  974. package/dist/agent-src/templates/scripts/memory_status.py +0 -76
  975. package/dist/agent-src/templates/scripts/pr_review_routing.py +0 -340
  976. package/dist/agent-src/templates/scripts/pr_risk_review.py +0 -211
  977. package/dist/agent-src/templates/scripts/telemetry/__init__.py +0 -42
  978. package/dist/agent-src/templates/scripts/telemetry/aggregator.py +0 -169
  979. package/dist/agent-src/templates/scripts/telemetry/boundary.py +0 -171
  980. package/dist/agent-src/templates/scripts/telemetry/engagement.py +0 -297
  981. package/dist/agent-src/templates/scripts/telemetry/report_renderer.py +0 -197
  982. package/dist/agent-src/templates/scripts/telemetry/settings.py +0 -177
  983. package/dist/agent-src/templates/scripts/telemetry_record.py +0 -179
  984. package/dist/agent-src/templates/scripts/telemetry_report.py +0 -161
  985. package/dist/agent-src/templates/scripts/telemetry_status.py +0 -142
  986. package/dist/agent-src/templates/scripts/tier_usage_report.py +0 -183
  987. package/dist/agent-src/templates/scripts/work_engine/__init__.py +0 -58
  988. package/dist/agent-src/templates/scripts/work_engine/__main__.py +0 -9
  989. package/dist/agent-src/templates/scripts/work_engine/_lib/__init__.py +0 -7
  990. package/dist/agent-src/templates/scripts/work_engine/_lib/agent_settings.py +0 -840
  991. package/dist/agent-src/templates/scripts/work_engine/_lib/user_global_paths.py +0 -249
  992. package/dist/agent-src/templates/scripts/work_engine/cli.py +0 -195
  993. package/dist/agent-src/templates/scripts/work_engine/cli_args.py +0 -116
  994. package/dist/agent-src/templates/scripts/work_engine/delivery_state.py +0 -137
  995. package/dist/agent-src/templates/scripts/work_engine/directives/__init__.py +0 -33
  996. package/dist/agent-src/templates/scripts/work_engine/directives/backend/__init__.py +0 -98
  997. package/dist/agent-src/templates/scripts/work_engine/directives/backend/analyze.py +0 -98
  998. package/dist/agent-src/templates/scripts/work_engine/directives/backend/implement.py +0 -145
  999. package/dist/agent-src/templates/scripts/work_engine/directives/backend/memory.py +0 -136
  1000. package/dist/agent-src/templates/scripts/work_engine/directives/backend/plan.py +0 -175
  1001. package/dist/agent-src/templates/scripts/work_engine/directives/backend/refine.py +0 -396
  1002. package/dist/agent-src/templates/scripts/work_engine/directives/backend/report.py +0 -227
  1003. package/dist/agent-src/templates/scripts/work_engine/directives/backend/test.py +0 -180
  1004. package/dist/agent-src/templates/scripts/work_engine/directives/backend/verify.py +0 -170
  1005. package/dist/agent-src/templates/scripts/work_engine/directives/mixed/__init__.py +0 -116
  1006. package/dist/agent-src/templates/scripts/work_engine/directives/mixed/contract.py +0 -254
  1007. package/dist/agent-src/templates/scripts/work_engine/directives/mixed/stitch.py +0 -229
  1008. package/dist/agent-src/templates/scripts/work_engine/directives/mixed/ui.py +0 -231
  1009. package/dist/agent-src/templates/scripts/work_engine/directives/ui/__init__.py +0 -113
  1010. package/dist/agent-src/templates/scripts/work_engine/directives/ui/_passthrough.py +0 -44
  1011. package/dist/agent-src/templates/scripts/work_engine/directives/ui/apply.py +0 -241
  1012. package/dist/agent-src/templates/scripts/work_engine/directives/ui/audit.py +0 -414
  1013. package/dist/agent-src/templates/scripts/work_engine/directives/ui/design.py +0 -335
  1014. package/dist/agent-src/templates/scripts/work_engine/directives/ui/polish.py +0 -513
  1015. package/dist/agent-src/templates/scripts/work_engine/directives/ui/review.py +0 -471
  1016. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/__init__.py +0 -119
  1017. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/_skipped.py +0 -37
  1018. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/apply.py +0 -165
  1019. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/refine.py +0 -66
  1020. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/report.py +0 -62
  1021. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/test.py +0 -115
  1022. package/dist/agent-src/templates/scripts/work_engine/dispatcher.py +0 -331
  1023. package/dist/agent-src/templates/scripts/work_engine/emitters.py +0 -68
  1024. package/dist/agent-src/templates/scripts/work_engine/errors.py +0 -19
  1025. package/dist/agent-src/templates/scripts/work_engine/hook_bootstrap.py +0 -91
  1026. package/dist/agent-src/templates/scripts/work_engine/hooks/__init__.py +0 -54
  1027. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/__init__.py +0 -35
  1028. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/_chat_history_base.py +0 -59
  1029. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_append.py +0 -43
  1030. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_halt_append.py +0 -41
  1031. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/decision_gate.py +0 -162
  1032. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/decision_trace.py +0 -163
  1033. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/directive_set_guard.py +0 -53
  1034. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/halt_surface_audit.py +0 -50
  1035. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/memory_visibility.py +0 -141
  1036. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/state_shape_validation.py +0 -52
  1037. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/trace.py +0 -84
  1038. package/dist/agent-src/templates/scripts/work_engine/hooks/context.py +0 -66
  1039. package/dist/agent-src/templates/scripts/work_engine/hooks/events.py +0 -44
  1040. package/dist/agent-src/templates/scripts/work_engine/hooks/exceptions.py +0 -79
  1041. package/dist/agent-src/templates/scripts/work_engine/hooks/registry.py +0 -60
  1042. package/dist/agent-src/templates/scripts/work_engine/hooks/runner.py +0 -73
  1043. package/dist/agent-src/templates/scripts/work_engine/hooks/settings.py +0 -196
  1044. package/dist/agent-src/templates/scripts/work_engine/input_builders.py +0 -163
  1045. package/dist/agent-src/templates/scripts/work_engine/intent/__init__.py +0 -47
  1046. package/dist/agent-src/templates/scripts/work_engine/intent/classify.py +0 -280
  1047. package/dist/agent-src/templates/scripts/work_engine/migration/__init__.py +0 -8
  1048. package/dist/agent-src/templates/scripts/work_engine/migration/v0_to_v1.py +0 -231
  1049. package/dist/agent-src/templates/scripts/work_engine/orchestration.py +0 -193
  1050. package/dist/agent-src/templates/scripts/work_engine/persona_policy.py +0 -85
  1051. package/dist/agent-src/templates/scripts/work_engine/resolvers/__init__.py +0 -22
  1052. package/dist/agent-src/templates/scripts/work_engine/resolvers/diff.py +0 -106
  1053. package/dist/agent-src/templates/scripts/work_engine/resolvers/file.py +0 -113
  1054. package/dist/agent-src/templates/scripts/work_engine/resolvers/prompt.py +0 -90
  1055. package/dist/agent-src/templates/scripts/work_engine/scoring/__init__.py +0 -14
  1056. package/dist/agent-src/templates/scripts/work_engine/scoring/confidence.py +0 -300
  1057. package/dist/agent-src/templates/scripts/work_engine/scoring/decision_engine.py +0 -351
  1058. package/dist/agent-src/templates/scripts/work_engine/scoring/decision_trace.py +0 -141
  1059. package/dist/agent-src/templates/scripts/work_engine/scoring/memory_visibility.py +0 -283
  1060. package/dist/agent-src/templates/scripts/work_engine/stack/__init__.py +0 -31
  1061. package/dist/agent-src/templates/scripts/work_engine/stack/detect.py +0 -187
  1062. package/dist/agent-src/templates/scripts/work_engine/stack/runner.py +0 -481
  1063. package/dist/agent-src/templates/scripts/work_engine/state.py +0 -694
  1064. package/dist/agent-src/templates/scripts/work_engine/state_io.py +0 -202
  1065. package/dist/cli/python/resolvePython.js +0 -38
  1066. package/dist/cli/python/resolvePython.js.map +0 -1
  1067. package/src/scripts/__pycache__/validate_frontmatter.cpython-312.pyc +0 -0
  1068. package/src/scripts/_archive/_backfill_skill_domains.py +0 -140
  1069. package/src/scripts/_archive/_bootstrap_tier_frontmatter.py +0 -151
  1070. package/src/scripts/_archive/_p43_bodies.py +0 -235
  1071. package/src/scripts/_archive/_p43_condense.py +0 -118
  1072. package/src/scripts/_archive/_p4_migrate.py +0 -199
  1073. package/src/scripts/_archive/_phase2_shim_helper.py +0 -109
  1074. package/src/scripts/_archive/_pilot_council_question.py +0 -57
  1075. package/src/scripts/_cli/__init__.py +0 -0
  1076. package/src/scripts/_cli/cmd_doctor.py +0 -1669
  1077. package/src/scripts/_cli/cmd_explain.py +0 -355
  1078. package/src/scripts/_cli/cmd_export.py +0 -157
  1079. package/src/scripts/_cli/cmd_migrate.py +0 -524
  1080. package/src/scripts/_cli/cmd_prune.py +0 -322
  1081. package/src/scripts/_cli/cmd_refresh.py +0 -179
  1082. package/src/scripts/_cli/cmd_settings_check.py +0 -171
  1083. package/src/scripts/_cli/cmd_settings_migrate.py +0 -147
  1084. package/src/scripts/_cli/cmd_sync.py +0 -166
  1085. package/src/scripts/_cli/cmd_uninstall.py +0 -476
  1086. package/src/scripts/_cli/cmd_update.py +0 -279
  1087. package/src/scripts/_cli/cmd_upgrade.py +0 -172
  1088. package/src/scripts/_cli/cmd_validate.py +0 -177
  1089. package/src/scripts/_cli/cmd_versions.py +0 -160
  1090. package/src/scripts/_cli/explain_last/__init__.py +0 -122
  1091. package/src/scripts/_cli/explain_last/assumptions.py +0 -59
  1092. package/src/scripts/_cli/explain_last/council.py +0 -105
  1093. package/src/scripts/_cli/explain_last/halt.py +0 -44
  1094. package/src/scripts/_cli/explain_last/inputs.py +0 -128
  1095. package/src/scripts/_cli/explain_last/memory.py +0 -94
  1096. package/src/scripts/_cli/explain_last/provider.py +0 -52
  1097. package/src/scripts/_cli/explain_last/render.py +0 -52
  1098. package/src/scripts/_cli/explain_last/route.py +0 -59
  1099. package/src/scripts/_cli/explain_last/scrubber.py +0 -105
  1100. package/src/scripts/_cli/explain_last/sections/__init__.py +0 -35
  1101. package/src/scripts/_cli/explain_last/sections/assumptions.py +0 -21
  1102. package/src/scripts/_cli/explain_last/sections/council.py +0 -27
  1103. package/src/scripts/_cli/explain_last/sections/halt.py +0 -31
  1104. package/src/scripts/_cli/explain_last/sections/header.py +0 -24
  1105. package/src/scripts/_cli/explain_last/sections/inputs.py +0 -27
  1106. package/src/scripts/_cli/explain_last/sections/memory.py +0 -21
  1107. package/src/scripts/_cli/explain_last/sections/pack.py +0 -16
  1108. package/src/scripts/_cli/explain_last/sections/provider.py +0 -26
  1109. package/src/scripts/_cli/explain_last/sections/route.py +0 -22
  1110. package/src/scripts/_cli/explain_last/state_loader.py +0 -76
  1111. package/src/scripts/_emit_domain_table.py +0 -35
  1112. package/src/scripts/_lib/__init__.py +0 -5
  1113. package/src/scripts/_lib/__pycache__/__init__.cpython-312.pyc +0 -0
  1114. package/src/scripts/_lib/__pycache__/agent_src.cpython-312.pyc +0 -0
  1115. package/src/scripts/_lib/agent_settings.py +0 -840
  1116. package/src/scripts/_lib/agent_src.py +0 -491
  1117. package/src/scripts/_lib/agents_overlay.py +0 -120
  1118. package/src/scripts/_lib/bench_ab_cache.py +0 -162
  1119. package/src/scripts/_lib/bench_ab_scoring.py +0 -209
  1120. package/src/scripts/_lib/bench_ab_scoring_v2.py +0 -227
  1121. package/src/scripts/_lib/bench_cost.py +0 -138
  1122. package/src/scripts/_lib/bench_quality.py +0 -118
  1123. package/src/scripts/_lib/bench_report.py +0 -149
  1124. package/src/scripts/_lib/bench_telegraph.py +0 -273
  1125. package/src/scripts/_lib/bench_telegraph_report.py +0 -151
  1126. package/src/scripts/_lib/changelog_eras.py +0 -330
  1127. package/src/scripts/_lib/claude_desktop_bundler.py +0 -238
  1128. package/src/scripts/_lib/cli_wrapper.py +0 -64
  1129. package/src/scripts/_lib/fs_atomic.py +0 -116
  1130. package/src/scripts/_lib/global_deploy_inventory.py +0 -312
  1131. package/src/scripts/_lib/install_regenerator.py +0 -134
  1132. package/src/scripts/_lib/installed_lock.py +0 -256
  1133. package/src/scripts/_lib/installed_tools.py +0 -381
  1134. package/src/scripts/_lib/json_pointers.py +0 -260
  1135. package/src/scripts/_lib/link_crypto.py +0 -206
  1136. package/src/scripts/_lib/linked_projects.py +0 -238
  1137. package/src/scripts/_lib/model_tier.py +0 -52
  1138. package/src/scripts/_lib/module_detection.py +0 -223
  1139. package/src/scripts/_lib/pin_resolver.py +0 -152
  1140. package/src/scripts/_lib/script_output.py +0 -144
  1141. package/src/scripts/_lib/security_lint.py +0 -228
  1142. package/src/scripts/_lib/token_count.py +0 -95
  1143. package/src/scripts/_lib/update_check.py +0 -207
  1144. package/src/scripts/_lib/user_global_paths.py +0 -249
  1145. package/src/scripts/_lib/value_ladder.py +0 -696
  1146. package/src/scripts/_lib/value_report.py +0 -455
  1147. package/src/scripts/_phase4_bucket.py +0 -210
  1148. package/src/scripts/_pilot_measure.py +0 -53
  1149. package/src/scripts/_tmp_scan_framework_leakage.py +0 -119
  1150. package/src/scripts/adoption_report.py +0 -195
  1151. package/src/scripts/adoption_snapshot.py +0 -219
  1152. package/src/scripts/adoption_status.py +0 -166
  1153. package/src/scripts/adr/regenerate_index.py +0 -79
  1154. package/src/scripts/ai-video/lib/adapter-common.sh +0 -231
  1155. package/src/scripts/ai-video/lib/adapter-contract.md +0 -329
  1156. package/src/scripts/ai-video/lib/fixtures/comfyui/result.json +0 -1
  1157. package/src/scripts/ai-video/lib/fixtures/fal/result.json +0 -1
  1158. package/src/scripts/ai-video/lib/fixtures/gemini-veo/result.json +0 -1
  1159. package/src/scripts/ai-video/lib/fixtures/higgsfield/result.json +0 -1
  1160. package/src/scripts/ai-video/lib/fixtures/kling/result.json +0 -1
  1161. package/src/scripts/ai-video/lib/fixtures/musetalk/result.json +0 -1
  1162. package/src/scripts/ai-video/lib/fixtures/openai-images/result.json +0 -1
  1163. package/src/scripts/ai-video/lib/fixtures/replicate/result.json +0 -1
  1164. package/src/scripts/ai-video/lib/fixtures/sora/result.json +0 -1
  1165. package/src/scripts/ai-video/lib/fixtures/syncso/result.json +0 -1
  1166. package/src/scripts/ai-video/lib/load-config.sh +0 -180
  1167. package/src/scripts/ai-video/lib/redact.sh +0 -85
  1168. package/src/scripts/ai_council/__init__.py +0 -40
  1169. package/src/scripts/ai_council/_default_prices.py +0 -50
  1170. package/src/scripts/ai_council/advisors.py +0 -148
  1171. package/src/scripts/ai_council/airgap.py +0 -165
  1172. package/src/scripts/ai_council/budget_guard.py +0 -202
  1173. package/src/scripts/ai_council/bundler.py +0 -263
  1174. package/src/scripts/ai_council/cli_hints.py +0 -123
  1175. package/src/scripts/ai_council/clients.py +0 -1385
  1176. package/src/scripts/ai_council/compile_corpus.py +0 -179
  1177. package/src/scripts/ai_council/confidence_gate.py +0 -156
  1178. package/src/scripts/ai_council/config.py +0 -1419
  1179. package/src/scripts/ai_council/consensus.py +0 -329
  1180. package/src/scripts/ai_council/events_log.py +0 -141
  1181. package/src/scripts/ai_council/learn_low_impact_preview.py +0 -252
  1182. package/src/scripts/ai_council/low_impact.py +0 -714
  1183. package/src/scripts/ai_council/low_impact_corpus.py +0 -466
  1184. package/src/scripts/ai_council/low_impact_intake.py +0 -163
  1185. package/src/scripts/ai_council/modes.py +0 -131
  1186. package/src/scripts/ai_council/necessity.py +0 -782
  1187. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_2a4_acceptance.py +0 -208
  1188. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_add_quiet.py +0 -149
  1189. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_budget_v2_audit.py +0 -206
  1190. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_context_layer_v1_estimate.py +0 -67
  1191. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_context_layer_v1_review.py +0 -292
  1192. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_followups_review.py +0 -259
  1193. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_inject_quiet_flag.py +0 -33
  1194. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_measure_v2.sh +0 -36
  1195. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_measure_verbosity.sh +0 -26
  1196. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_nondestructive_inline_audit.py +0 -209
  1197. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_per_task.sh +0 -41
  1198. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_phase4_dispatch_latency.py +0 -108
  1199. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_phase6_trigger_jaccard.py +0 -92
  1200. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_phase_2a_budget_rebalance.py +0 -257
  1201. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_phase_2a_post_revert.py +0 -197
  1202. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_rebalancing_audit.py +0 -149
  1203. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_roundtrip.py +0 -111
  1204. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_rule_hardening_v1.py +0 -251
  1205. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_silent_taskfiles.py +0 -98
  1206. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_structural_open_questions.py +0 -232
  1207. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_structural_optimization.py +0 -144
  1208. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_structural_v3_gaps.py +0 -252
  1209. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_structural_v3_review.py +0 -240
  1210. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_tier_retrofit.py +0 -180
  1211. package/src/scripts/ai_council/orchestrator.py +0 -1206
  1212. package/src/scripts/ai_council/pricing.py +0 -215
  1213. package/src/scripts/ai_council/probation_gate.py +0 -152
  1214. package/src/scripts/ai_council/project_context.py +0 -159
  1215. package/src/scripts/ai_council/prompts.py +0 -567
  1216. package/src/scripts/ai_council/redact_low_impact_entry.py +0 -155
  1217. package/src/scripts/ai_council/replay.py +0 -155
  1218. package/src/scripts/ai_council/session.py +0 -366
  1219. package/src/scripts/ai_council/shadow_dispatch.py +0 -235
  1220. package/src/scripts/ai_council/solo_dispatch.py +0 -226
  1221. package/src/scripts/annotate_discovery.py +0 -149
  1222. package/src/scripts/apply_modules_config.py +0 -290
  1223. package/src/scripts/audit_adr_coverage.py +0 -173
  1224. package/src/scripts/audit_auto_rules.py +0 -175
  1225. package/src/scripts/audit_cloud_compatibility.py +0 -362
  1226. package/src/scripts/audit_command_surface.py +0 -682
  1227. package/src/scripts/audit_initial_context.py +0 -237
  1228. package/src/scripts/audit_likelihood.py +0 -148
  1229. package/src/scripts/audit_mcp_tools.py +0 -146
  1230. package/src/scripts/audit_overlap.py +0 -145
  1231. package/src/scripts/audit_skill_descriptions.py +0 -180
  1232. package/src/scripts/audit_skill_overlap.py +0 -207
  1233. package/src/scripts/audit_user_type_axis.py +0 -140
  1234. package/src/scripts/backfill_model_tier.py +0 -184
  1235. package/src/scripts/bench_ab_cache_dispatch.py +0 -68
  1236. package/src/scripts/bench_ab_clone.py +0 -220
  1237. package/src/scripts/bench_ab_diff.py +0 -220
  1238. package/src/scripts/bench_ab_integrity.py +0 -143
  1239. package/src/scripts/bench_ab_run.py +0 -235
  1240. package/src/scripts/bench_ab_task_runner.py +0 -814
  1241. package/src/scripts/bench_ab_tracka_run.py +0 -202
  1242. package/src/scripts/bench_ab_v2_run.py +0 -247
  1243. package/src/scripts/bench_ab_v2_stats.py +0 -347
  1244. package/src/scripts/bench_baseline_ready.py +0 -108
  1245. package/src/scripts/bench_condense_memory.py +0 -168
  1246. package/src/scripts/bench_drift_check.py +0 -151
  1247. package/src/scripts/bench_per_tool.py +0 -216
  1248. package/src/scripts/bench_rtk_savings.py +0 -320
  1249. package/src/scripts/bench_run.py +0 -272
  1250. package/src/scripts/bench_runner.py +0 -158
  1251. package/src/scripts/build_cloud_bundle.py +0 -458
  1252. package/src/scripts/build_discovery_manifest.py +0 -757
  1253. package/src/scripts/build_linear_digest.py +0 -260
  1254. package/src/scripts/build_mcp_registry_manifest.py +0 -181
  1255. package/src/scripts/build_rule_trigger_matrix.py +0 -350
  1256. package/src/scripts/capture_showcase_session.py +0 -361
  1257. package/src/scripts/chat_history.py +0 -1799
  1258. package/src/scripts/check_always_budget.py +0 -532
  1259. package/src/scripts/check_artefact_checksums.py +0 -111
  1260. package/src/scripts/check_augment_description_cap.py +0 -79
  1261. package/src/scripts/check_augmentignore.py +0 -72
  1262. package/src/scripts/check_beta_review_markers.py +0 -127
  1263. package/src/scripts/check_bite_sized_granularity.py +0 -98
  1264. package/src/scripts/check_cluster_patterns.py +0 -206
  1265. package/src/scripts/check_command_count_messaging.py +0 -152
  1266. package/src/scripts/check_condensation.py +0 -375
  1267. package/src/scripts/check_condensed_paths.py +0 -231
  1268. package/src/scripts/check_context_paths.py +0 -202
  1269. package/src/scripts/check_council_layout.py +0 -125
  1270. package/src/scripts/check_council_references.py +0 -228
  1271. package/src/scripts/check_discovery_determinism.py +0 -70
  1272. package/src/scripts/check_gate_paths.py +0 -128
  1273. package/src/scripts/check_iron_law_prominence.py +0 -145
  1274. package/src/scripts/check_kernel_rule_bundle.py +0 -151
  1275. package/src/scripts/check_md_language.py +0 -161
  1276. package/src/scripts/check_memory.py +0 -429
  1277. package/src/scripts/check_memory_proposal.py +0 -182
  1278. package/src/scripts/check_module_management_neutral.py +0 -147
  1279. package/src/scripts/check_no_external_sources.py +0 -101
  1280. package/src/scripts/check_no_local_settings_committed.py +0 -51
  1281. package/src/scripts/check_no_new_legacy_path.py +0 -100
  1282. package/src/scripts/check_no_roadmap_refs.py +0 -155
  1283. package/src/scripts/check_one_off_location.py +0 -81
  1284. package/src/scripts/check_overlay_cascade_subdirs.py +0 -129
  1285. package/src/scripts/check_portability.py +0 -574
  1286. package/src/scripts/check_proposal.py +0 -269
  1287. package/src/scripts/check_public_catalog_links.py +0 -125
  1288. package/src/scripts/check_public_links.py +0 -185
  1289. package/src/scripts/check_references.py +0 -559
  1290. package/src/scripts/check_release_includes_discovery.py +0 -61
  1291. package/src/scripts/check_release_pr_shape.py +0 -123
  1292. package/src/scripts/check_release_published.py +0 -145
  1293. package/src/scripts/check_release_trunk_sync.py +0 -152
  1294. package/src/scripts/check_reply_consistency.py +0 -169
  1295. package/src/scripts/check_roadmap_trackable.py +0 -114
  1296. package/src/scripts/check_role_doc_links.py +0 -110
  1297. package/src/scripts/check_safety_floor_untouched.py +0 -125
  1298. package/src/scripts/check_skill_requires.py +0 -147
  1299. package/src/scripts/check_template_pin_drift.py +0 -129
  1300. package/src/scripts/check_test_coverage_diff.py +0 -180
  1301. package/src/scripts/check_token_optimizer_freshness.py +0 -146
  1302. package/src/scripts/check_update_banner.py +0 -86
  1303. package/src/scripts/ci_status.py +0 -301
  1304. package/src/scripts/ci_summary.py +0 -131
  1305. package/src/scripts/ci_time_ratio.py +0 -168
  1306. package/src/scripts/command_suggester/__init__.py +0 -51
  1307. package/src/scripts/command_suggester/cooldown.py +0 -132
  1308. package/src/scripts/command_suggester/loader.py +0 -73
  1309. package/src/scripts/command_suggester/match.py +0 -180
  1310. package/src/scripts/command_suggester/rank.py +0 -120
  1311. package/src/scripts/command_suggester/render.py +0 -86
  1312. package/src/scripts/command_suggester/sanitize.py +0 -113
  1313. package/src/scripts/command_suggester/settings.py +0 -127
  1314. package/src/scripts/command_suggester/types.py +0 -78
  1315. package/src/scripts/compile_router.py +0 -232
  1316. package/src/scripts/condense.py +0 -1919
  1317. package/src/scripts/condense_memory.py +0 -178
  1318. package/src/scripts/config/__init__.py +0 -9
  1319. package/src/scripts/config/packs.py +0 -157
  1320. package/src/scripts/config/presets.py +0 -224
  1321. package/src/scripts/config/profile_explain.py +0 -89
  1322. package/src/scripts/config/profiles.py +0 -191
  1323. package/src/scripts/config/session_profiles.py +0 -542
  1324. package/src/scripts/context_hygiene_hook.py +0 -181
  1325. package/src/scripts/cost_by_conversation.py +0 -78
  1326. package/src/scripts/cost_summary.py +0 -97
  1327. package/src/scripts/council_cli.py +0 -2571
  1328. package/src/scripts/council_prune.py +0 -81
  1329. package/src/scripts/cross_repo_retrieve.py +0 -172
  1330. package/src/scripts/discovery_stats.py +0 -70
  1331. package/src/scripts/extract_audit_patterns.py +0 -202
  1332. package/src/scripts/first_run_gate_hook.py +0 -179
  1333. package/src/scripts/gen_discovery_baseline.py +0 -127
  1334. package/src/scripts/generate_catalog.py +0 -116
  1335. package/src/scripts/generate_command_flows.py +0 -191
  1336. package/src/scripts/generate_index.py +0 -303
  1337. package/src/scripts/generate_ownership_matrix.py +0 -378
  1338. package/src/scripts/generate_pack_manifests.py +0 -340
  1339. package/src/scripts/hooks/__init__.py +0 -1
  1340. package/src/scripts/hooks/dispatch_hook.py +0 -461
  1341. package/src/scripts/hooks/dispatch_issues.py +0 -136
  1342. package/src/scripts/hooks/envelope.py +0 -98
  1343. package/src/scripts/hooks/replay_hook.py +0 -144
  1344. package/src/scripts/hooks/state_io.py +0 -145
  1345. package/src/scripts/hooks_doctor.py +0 -223
  1346. package/src/scripts/hooks_status.py +0 -157
  1347. package/src/scripts/injection_scan_hook.py +0 -145
  1348. package/src/scripts/install.py +0 -5258
  1349. package/src/scripts/inventory_abstraction_budget.py +0 -622
  1350. package/src/scripts/inventory_frontmatter.py +0 -164
  1351. package/src/scripts/inventory_meta_layers.py +0 -288
  1352. package/src/scripts/iron_law_sha.py +0 -107
  1353. package/src/scripts/linked_projects_list.py +0 -91
  1354. package/src/scripts/lint_agent_security.py +0 -112
  1355. package/src/scripts/lint_agent_skill_names.py +0 -150
  1356. package/src/scripts/lint_agents_layout.py +0 -197
  1357. package/src/scripts/lint_agents_md.py +0 -210
  1358. package/src/scripts/lint_archived_skills.py +0 -159
  1359. package/src/scripts/lint_artefact_frontmatter.py +0 -188
  1360. package/src/scripts/lint_bench_ab.py +0 -173
  1361. package/src/scripts/lint_bench_corpus.py +0 -255
  1362. package/src/scripts/lint_command_flow_coverage.py +0 -132
  1363. package/src/scripts/lint_command_routing.py +0 -160
  1364. package/src/scripts/lint_command_tiers.py +0 -216
  1365. package/src/scripts/lint_command_verbs.py +0 -206
  1366. package/src/scripts/lint_commit_subjects.py +0 -139
  1367. package/src/scripts/lint_context_spine_usage.py +0 -137
  1368. package/src/scripts/lint_discovery_manifest.py +0 -176
  1369. package/src/scripts/lint_discovery_vocabulary.py +0 -222
  1370. package/src/scripts/lint_empty_roadmaps.py +0 -80
  1371. package/src/scripts/lint_examples.py +0 -102
  1372. package/src/scripts/lint_explain_trace.py +0 -80
  1373. package/src/scripts/lint_featured_skills.py +0 -144
  1374. package/src/scripts/lint_flows.py +0 -215
  1375. package/src/scripts/lint_framework_leakage.py +0 -375
  1376. package/src/scripts/lint_frontmatter_boilerplate.py +0 -77
  1377. package/src/scripts/lint_ghostwriter_source.py +0 -242
  1378. package/src/scripts/lint_global_paths.py +0 -148
  1379. package/src/scripts/lint_handoffs.py +0 -217
  1380. package/src/scripts/lint_hidden_unicode.py +0 -132
  1381. package/src/scripts/lint_hook_concern_budget.py +0 -207
  1382. package/src/scripts/lint_hook_manifest.py +0 -217
  1383. package/src/scripts/lint_instruction_smuggling.py +0 -107
  1384. package/src/scripts/lint_load_context.py +0 -196
  1385. package/src/scripts/lint_marketplace.py +0 -180
  1386. package/src/scripts/lint_marketplace_install_completeness.py +0 -198
  1387. package/src/scripts/lint_mcp_config_security.py +0 -124
  1388. package/src/scripts/lint_mcp_registry_manifest.py +0 -69
  1389. package/src/scripts/lint_media_policy_linkage.py +0 -140
  1390. package/src/scripts/lint_model_tier_coverage.py +0 -73
  1391. package/src/scripts/lint_namespace.py +0 -135
  1392. package/src/scripts/lint_namespace_collisions.py +0 -103
  1393. package/src/scripts/lint_new_skill_gate.py +0 -144
  1394. package/src/scripts/lint_no_new_atomic_commands.py +0 -180
  1395. package/src/scripts/lint_one_off_age.py +0 -184
  1396. package/src/scripts/lint_orchestration_dsl.py +0 -217
  1397. package/src/scripts/lint_orchestrator_auto_detect.py +0 -111
  1398. package/src/scripts/lint_pack_boundaries.py +0 -147
  1399. package/src/scripts/lint_pack_dependencies.py +0 -137
  1400. package/src/scripts/lint_pack_first_win.py +0 -121
  1401. package/src/scripts/lint_persona_governance.py +0 -164
  1402. package/src/scripts/lint_positioning.py +0 -143
  1403. package/src/scripts/lint_profile_overlay_set_only.py +0 -179
  1404. package/src/scripts/lint_readme_jargon.py +0 -131
  1405. package/src/scripts/lint_readme_size.py +0 -33
  1406. package/src/scripts/lint_regression.py +0 -251
  1407. package/src/scripts/lint_roadmap_ci_steps.py +0 -186
  1408. package/src/scripts/lint_roadmap_complexity.py +0 -220
  1409. package/src/scripts/lint_role_experiences.py +0 -255
  1410. package/src/scripts/lint_rule_interactions.py +0 -170
  1411. package/src/scripts/lint_rule_tiers.py +0 -90
  1412. package/src/scripts/lint_showcase_sessions.py +0 -148
  1413. package/src/scripts/lint_skill_frontmatter_safety.py +0 -144
  1414. package/src/scripts/lint_skill_tools.py +0 -168
  1415. package/src/scripts/lint_topics_yaml.py +0 -89
  1416. package/src/scripts/lint_trust_coherence.py +0 -212
  1417. package/src/scripts/lint_value_dashboard.py +0 -218
  1418. package/src/scripts/lint_workspace_boundary.py +0 -122
  1419. package/src/scripts/mcp_parity_smoke.py +0 -316
  1420. package/src/scripts/mcp_render.py +0 -173
  1421. package/src/scripts/mcp_server/__init__.py +0 -19
  1422. package/src/scripts/mcp_server/__main__.py +0 -12
  1423. package/src/scripts/mcp_server/catalog.py +0 -125
  1424. package/src/scripts/mcp_server/metadata.py +0 -75
  1425. package/src/scripts/mcp_server/prompts.py +0 -442
  1426. package/src/scripts/mcp_server/requirements.txt +0 -4
  1427. package/src/scripts/mcp_server/resources.py +0 -201
  1428. package/src/scripts/mcp_server/server.py +0 -270
  1429. package/src/scripts/mcp_server/telemetry.py +0 -128
  1430. package/src/scripts/mcp_server/tools.py +0 -926
  1431. package/src/scripts/mcp_telemetry_health.py +0 -214
  1432. package/src/scripts/mcp_telemetry_query.py +0 -203
  1433. package/src/scripts/mcp_telemetry_store.py +0 -211
  1434. package/src/scripts/measure_augment_budget.py +0 -214
  1435. package/src/scripts/measure_density.py +0 -232
  1436. package/src/scripts/measure_frugality_savings.py +0 -164
  1437. package/src/scripts/measure_markitdown_lift.py +0 -127
  1438. package/src/scripts/measure_patterns.py +0 -376
  1439. package/src/scripts/measure_projection_bytes.py +0 -159
  1440. package/src/scripts/measure_rule_budget.py +0 -347
  1441. package/src/scripts/measure_skill_reduction.py +0 -102
  1442. package/src/scripts/memory_hash.py +0 -75
  1443. package/src/scripts/memory_lookup.py +0 -436
  1444. package/src/scripts/memory_report.py +0 -314
  1445. package/src/scripts/memory_signal.py +0 -165
  1446. package/src/scripts/memory_status.py +0 -76
  1447. package/src/scripts/migrate_command_suggestions.py +0 -151
  1448. package/src/scripts/migrate_frontmatter_defaults.py +0 -245
  1449. package/src/scripts/mine_session.py +0 -356
  1450. package/src/scripts/minimal_safe_diff_hook.py +0 -245
  1451. package/src/scripts/move_artefact.py +0 -143
  1452. package/src/scripts/new_skill.py +0 -148
  1453. package/src/scripts/onboarding_gate_hook.py +0 -142
  1454. package/src/scripts/pack_mcp_content.py +0 -293
  1455. package/src/scripts/plan_physical_move.py +0 -353
  1456. package/src/scripts/prediction-pool/poisson_sim.py +0 -167
  1457. package/src/scripts/prediction-pool/pool_winsim.py +0 -236
  1458. package/src/scripts/prediction-pool/score_ev.py +0 -188
  1459. package/src/scripts/print_required_checks.py +0 -196
  1460. package/src/scripts/probe_projection_fidelity.py +0 -202
  1461. package/src/scripts/probe_skill_registration.py +0 -413
  1462. package/src/scripts/profile_staleness_hook.py +0 -69
  1463. package/src/scripts/profile_use.py +0 -164
  1464. package/src/scripts/project_thin_rules.py +0 -168
  1465. package/src/scripts/propose_modules_config.py +0 -145
  1466. package/src/scripts/prototype_lint_contradictions.py +0 -150
  1467. package/src/scripts/prove_pack_extractable.py +0 -187
  1468. package/src/scripts/readme_linter.py +0 -589
  1469. package/src/scripts/redact_hook_capture.py +0 -148
  1470. package/src/scripts/refine_ticket_detect.py +0 -646
  1471. package/src/scripts/release.py +0 -1091
  1472. package/src/scripts/render_benchmark_md.py +0 -401
  1473. package/src/scripts/render_value_md.py +0 -347
  1474. package/src/scripts/requirements-evals.txt +0 -8
  1475. package/src/scripts/roadmap_progress_hook.py +0 -274
  1476. package/src/scripts/router_telemetry.py +0 -470
  1477. package/src/scripts/run_skill_evals.py +0 -185
  1478. package/src/scripts/runtime_dispatcher.py +0 -276
  1479. package/src/scripts/runtime_handler.py +0 -148
  1480. package/src/scripts/runtime_registry.py +0 -166
  1481. package/src/scripts/score_skill_selection.py +0 -198
  1482. package/src/scripts/security_audit_config.py +0 -153
  1483. package/src/scripts/setup_eval_venv.sh +0 -58
  1484. package/src/scripts/skill_collision_clusters.py +0 -162
  1485. package/src/scripts/skill_discovery.py +0 -254
  1486. package/src/scripts/skill_linter.py +0 -3694
  1487. package/src/scripts/skill_overlap.py +0 -204
  1488. package/src/scripts/skill_preview.py +0 -179
  1489. package/src/scripts/skill_tools/__init__.py +0 -22
  1490. package/src/scripts/skill_tools/audit_persona_coverage.py +0 -147
  1491. package/src/scripts/skill_tools/audit_user_type_coverage.py +0 -148
  1492. package/src/scripts/skill_tools/run_block_d_eval.py +0 -129
  1493. package/src/scripts/skill_tools/score_skill_relevance.py +0 -169
  1494. package/src/scripts/skill_tools/suggest_skill_for_task.py +0 -113
  1495. package/src/scripts/skill_trigger_eval.py +0 -682
  1496. package/src/scripts/skill_usage_collect.py +0 -191
  1497. package/src/scripts/skill_usage_report.py +0 -162
  1498. package/src/scripts/smoke_path_resolution.py +0 -93
  1499. package/src/scripts/smoke_quickstart.py +0 -144
  1500. package/src/scripts/snapshot_agent_outputs.py +0 -144
  1501. package/src/scripts/spotcheck_thin_root.py +0 -134
  1502. package/src/scripts/sync_agent_settings.py +0 -180
  1503. package/src/scripts/sync_github_metadata.py +0 -147
  1504. package/src/scripts/sync_gitignore.py +0 -291
  1505. package/src/scripts/sync_yaml_rt.py +0 -734
  1506. package/src/scripts/telegraph_stats.py +0 -119
  1507. package/src/scripts/tool_registry.py +0 -146
  1508. package/src/scripts/tools/__init__.py +0 -1
  1509. package/src/scripts/tools/adapter_errors.py +0 -63
  1510. package/src/scripts/tools/base_adapter.py +0 -91
  1511. package/src/scripts/tools/github_adapter.py +0 -128
  1512. package/src/scripts/tools/jira_adapter.py +0 -115
  1513. package/src/scripts/trigger_coverage.py +0 -129
  1514. package/src/scripts/update_counts.py +0 -199
  1515. package/src/scripts/update_prices.py +0 -125
  1516. package/src/scripts/validate_agent_settings.py +0 -124
  1517. package/src/scripts/validate_decision_engine.py +0 -136
  1518. package/src/scripts/validate_discovery_manifest.py +0 -94
  1519. package/src/scripts/validate_frontmatter.py +0 -647
  1520. package/src/scripts/validate_pack_yaml.py +0 -179
  1521. package/src/scripts/validate_safe_paths.py +0 -118
  1522. package/src/scripts/validate_telegraph_carveouts.py +0 -129
  1523. package/src/scripts/verify_before_complete_hook.py +0 -216
  1524. package/src/scripts/verify_physical_move.py +0 -185
  1525. package/src/scripts/wrapper_freshness_hook.py +0 -86
  1526. /package/dist/agent-src/skills/design-intelligence/data/{typography.csv → font-pairings-reference.csv} +0 -0
  1527. /package/src/scripts/{ai-video → media}/lib/fixtures/allin1/analysis.json +0 -0
  1528. /package/src/scripts/{ai-video → media}/lib/fixtures/comfyui/scene-0001.mp4 +0 -0
  1529. /package/src/scripts/{ai-video → media}/lib/fixtures/fal/scene-0001.mp4 +0 -0
  1530. /package/src/scripts/{ai-video → media}/lib/fixtures/gemini-veo/scene-0001.mp4 +0 -0
  1531. /package/src/scripts/{ai-video → media}/lib/fixtures/higgsfield/scene-0001.mp4 +0 -0
  1532. /package/src/scripts/{ai-video → media}/lib/fixtures/kling/scene-0001.mp4 +0 -0
  1533. /package/src/scripts/{ai-video → media}/lib/fixtures/musetalk/lipsync-0001.mp4 +0 -0
  1534. /package/src/scripts/{ai-video → media}/lib/fixtures/openai-images/scene-0001.png +0 -0
  1535. /package/src/scripts/{ai-video → media}/lib/fixtures/replicate/scene-0001.mp4 +0 -0
  1536. /package/src/scripts/{ai-video → media}/lib/fixtures/sora/scene-0001.mp4 +0 -0
  1537. /package/src/scripts/{ai-video → media}/lib/fixtures/syncso/lipsync-0001.mp4 +0 -0
  1538. /package/src/scripts/{ai-video → media}/lib/fixtures/whisperx/transcript.json +0 -0
  1539. /package/src/scripts/{ai-video → media}/lib/telemetry.sh +0 -0
@@ -0,0 +1,4276 @@
1
+ #!/usr/bin/env tsx
2
+ /**
3
+ * skill_linter.ts — minimal skill/rule linter for agent-config repositories.
4
+ *
5
+ * TypeScript twin of `src/scripts/skill_linter.py` (ADR-200, Phase 4 Wave 4a).
6
+ * The public CLI contract is mirrored EXACTLY: same flags (`--all`,
7
+ * `--changed`, `--format`, `--pairs`, `--duplicates`, `--condensation-quality`,
8
+ * `--strict-warnings`, `--report`, `--repo-root`, `--quiet`, positional paths),
9
+ * same exit codes (0 pass / 1 warn-with-strict / 2 fail / 3 malice-or-internal),
10
+ * same stdout/stderr split, and byte-for-byte finding messages. No behaviour
11
+ * changes — latent Python quirks are replicated.
12
+ *
13
+ * Dependencies: imports the `validate_frontmatter` twin (local, ported because
14
+ * the Python original is a later-wave dependency) and the `_lib/agent_src`
15
+ * twin for multi-root artefact resolution.
16
+ *
17
+ * MVP checks:
18
+ * - Detect skill vs rule
19
+ * - Required skill sections
20
+ * - Basic rule validation
21
+ * - Vague validation detection
22
+ * - Output format presence
23
+ * - Gotchas / Do NOT presence
24
+ * - Single file, --all, --changed
25
+ * - Text and JSON output
26
+ *
27
+ * Exit codes:
28
+ * 0 = pass
29
+ * 1 = warnings only (with --strict-warnings)
30
+ * 2 = errors
31
+ * 3 = internal error / structural malice
32
+ */
33
+ import { spawnSync } from 'node:child_process';
34
+ import * as fs from 'node:fs';
35
+ import * as path from 'node:path';
36
+ import process from 'node:process';
37
+ import { fileURLToPath, pathToFileURL } from 'node:url';
38
+
39
+ import {
40
+ apply_schema_defaults,
41
+ load_schema,
42
+ parse_frontmatter as parse_frontmatter_for_schema,
43
+ validate as validate_against_schema,
44
+ type YamlValue,
45
+ } from './validate_frontmatter.js';
46
+ import { artefact_roots, resolve_logical } from './_lib/agent_src.js';
47
+
48
+ // __file__ equivalent for repo-root derivation (mirrors Python
49
+ // `Path(__file__).resolve().parent.parent.parent` = <repo>/src/scripts → repo).
50
+ const _HERE = path.dirname(fileURLToPath(import.meta.url));
51
+
52
+ export type Severity = 'error' | 'warning' | 'info';
53
+ export type ArtifactType =
54
+ | 'skill'
55
+ | 'rule'
56
+ | 'command'
57
+ | 'guideline'
58
+ | 'persona'
59
+ | 'user-type'
60
+ | 'unknown';
61
+ export type Status = 'pass' | 'pass_with_warnings' | 'fail';
62
+
63
+ const REQUIRED_PERSONA_SECTIONS_CORE = [
64
+ 'Focus',
65
+ 'Mindset',
66
+ 'Unique Questions',
67
+ 'Output Expectations',
68
+ 'Anti-Patterns',
69
+ ];
70
+ const REQUIRED_PERSONA_SECTIONS_SPECIALIST = [
71
+ ...REQUIRED_PERSONA_SECTIONS_CORE,
72
+ 'Critical Rules',
73
+ 'Workflows',
74
+ ];
75
+ const VALID_PERSONA_TIERS = new Set(['core', 'specialist']);
76
+ // Locked in docs/contracts/persona-schema.md § 4: core ≤ 120, specialist ≤ 100.
77
+ const PERSONA_LINE_BUDGETS: Record<string, number> = { core: 120, specialist: 100 };
78
+
79
+ const REQUIRED_USERTYPE_SECTIONS = [
80
+ 'Focus',
81
+ 'Daily Workflow',
82
+ 'Vocabulary',
83
+ 'Operational Constraints',
84
+ 'Unique Questions',
85
+ 'Ticket Red Flags',
86
+ 'Anti-Patterns',
87
+ ];
88
+ const USERTYPE_LINE_BUDGET = 120;
89
+ const VALID_PERSONA_WINGS = new Set([1, 2, 3, 4]);
90
+ // Wing-scoped persona line-budget overrides; keyed by `${tier}:${wing}`.
91
+ const PERSONA_LINE_BUDGETS_BY_WING: Record<string, number> = {
92
+ 'specialist:3': 140,
93
+ 'specialist:4': 140,
94
+ };
95
+
96
+ const REQUIRED_SKILL_SECTIONS = ['When to use', 'Gotcha', 'Procedure', 'Output format', 'Do NOT'];
97
+
98
+ const SECTION_ALIASES: Record<string, Set<string>> = {
99
+ Gotcha: new Set(['Gotcha', 'Gotchas']),
100
+ Procedure: new Set(), // prefix-matched separately
101
+ 'Do NOT': new Set(['Do NOT', 'Do not', 'Anti-patterns']),
102
+ 'Output format': new Set(['Output format', 'Output']),
103
+ };
104
+
105
+ const RECOMMENDED_SKILL_SECTIONS: string[] = [];
106
+
107
+ const RULE_BAD_SIGNS = ['## Procedure', '## Output format', '## Gotchas'];
108
+
109
+ const FRUGALITY_WRITER_SKILLS = new Set([
110
+ 'skill-writing',
111
+ 'rule-writing',
112
+ 'command-writing',
113
+ 'guideline-writing',
114
+ 'context-authoring',
115
+ 'agent-docs-writing',
116
+ 'conventional-commits-writing',
117
+ 'readme-writing',
118
+ 'readme-writing-package',
119
+ 'adr-create',
120
+ 'persona-writing',
121
+ 'roadmap-writing',
122
+ 'script-writing',
123
+ ]);
124
+ const FRUGALITY_CHARTER_RELPATH = 'contexts/communication/frugality-charter.md';
125
+ const FRUGALITY_CHARTER_INDEX_RULES: Record<string, string> = {
126
+ 'direct-answers.md': 'iron-law-3',
127
+ 'user-interaction.md': 'iron-law-1',
128
+ 'no-cheap-questions.md': 'pre-send-self-check',
129
+ 'token-efficiency.md': 'the-iron-laws',
130
+ };
131
+
132
+ const VAGUE_VALIDATION_PATTERNS = [
133
+ String.raw`\bcheck if it works\b`,
134
+ String.raw`\bverify it works\b`,
135
+ String.raw`\btest manually\b`,
136
+ String.raw`\bcheck manually\b`,
137
+ String.raw`\bmake sure it works\b`,
138
+ ];
139
+
140
+ const TRIGGER_WARNING_PATTERNS = [
141
+ String.raw`\bgeneral helper\b`,
142
+ String.raw`\blaravel skill\b`,
143
+ String.raw`\bgeneral coding\b`,
144
+ String.raw`\beverything about\b`,
145
+ ];
146
+
147
+ const ORDERED_STEP_PATTERN = /^(?:\s*|#{1,4}\s*)(\d+)\.\s+/gm;
148
+ const SECTION_PATTERN = /^##\s+(.+?)\s*$/gm;
149
+ export const FRONTMATTER_PATTERN = /^---\n([\s\S]*?)\n---\n/;
150
+ export const DESCRIPTION_PATTERN = /^description:\s*"?(.*?)"?\s*$/m;
151
+ const STATUS_PATTERN = /^status:\s*"?(active|deprecated|superseded)"?\s*$/m;
152
+ const REPLACED_BY_PATTERN = /^replaced_by:\s*"?([\w-]+)"?\s*$/m;
153
+ const TIER_PATTERN = /^tier:\s*"?([\w-]+)"?\s*$/m;
154
+ const TYPE_PATTERN = /^type:\s*"?(always|auto|manual)"?\s*$/m;
155
+ const SOURCE_PATTERN = /^source:\s*"?(package|project)"?\s*$/m;
156
+
157
+ // --- Senior-tier required-block patterns ---
158
+ const SENIOR_RELATED_SKILLS_PATTERN = /^##\s+Related Skills\s*$/m;
159
+ const SENIOR_RELATED_WHEN_PATTERN = /\*\*WHEN to use this\*\*/i;
160
+ const SENIOR_RELATED_WHEN_NOT_PATTERN = /\*\*WHEN NOT to use this\*\*/i;
161
+ const SENIOR_PROACTIVE_PATTERN = /^##\s+When the agent should load this\s*$/m;
162
+ const SENIOR_OUTPUT_PATTERN = /^##\s+Output\s*$/m;
163
+ const H1_PATTERN = /^# .+/m;
164
+ const DOUBLE_BLANK_PATTERN = /\n{3,}/;
165
+
166
+ const VALID_RULE_TYPES = new Set(['always', 'auto', 'manual']);
167
+ const VALID_RULE_SOURCES = new Set(['package', 'project']);
168
+
169
+ const ROUTER_ALLOWED_TRIGGER_KEYS = new Set([
170
+ 'keyword',
171
+ 'phrase',
172
+ 'intent',
173
+ 'file_pattern',
174
+ 'path_prefix',
175
+ 'command',
176
+ ]);
177
+ const KERNEL_RULE_IDS = new Set([
178
+ 'agent-authority',
179
+ 'ask-when-uncertain',
180
+ 'commit-policy',
181
+ 'direct-answers',
182
+ 'language-and-tone',
183
+ 'no-cheap-questions',
184
+ 'non-destructive-by-default',
185
+ 'scope-control',
186
+ 'verify-before-complete',
187
+ ]);
188
+
189
+ // --- Runtime execution metadata constants ---
190
+ export const VALID_EXECUTION_TYPES = new Set(['manual', 'assisted', 'automated']);
191
+ export const VALID_EXECUTION_HANDLERS = new Set(['none', 'shell', 'php', 'node', 'internal']);
192
+ const VALID_EXECUTION_SAFETY_MODES = new Set(['strict']);
193
+ const VALID_EXECUTION_FIELDS = new Set([
194
+ 'type',
195
+ 'handler',
196
+ 'timeout_seconds',
197
+ 'safety_mode',
198
+ 'allowed_tools',
199
+ 'command',
200
+ ]);
201
+
202
+ // --- Wing-3 GTM cognition-boundary patterns ---
203
+ const WING3_SPINE_SLOTS = new Set(['channel-stage', 'funnel-stage', 'customer-segment']);
204
+
205
+ const CONTEXT_SPINE_INLINE_PATTERN = /^context_spine:\s*\[(.*?)\]\s*$/m;
206
+
207
+ const WING3_SAAS_URL_PATTERN =
208
+ /https?:\/\/[\w.-]*\.(salesforce|hubspot|marketo|pardot|mailchimp|intercom|amplitude|mixpanel|segment|klaviyo|sendgrid|mailgun|pendo|gong|outreach|salesloft|apollo)\.(com|io)\b/i;
209
+
210
+ const WING3_VENDOR_BLACKLIST =
211
+ /\b(salesforce|hubspot|marketo|pardot|mailchimp|intercom|drift|klaviyo|sendgrid|mailgun|amplitude|mixpanel|pendo|gong|outreach\.io|salesloft|apollo\.io|zendesk|freshworks)\b/i;
212
+
213
+ const WING3_STACK_LOCKED_PATTERN =
214
+ /\b(npm install|pip install|composer require|gem install|cargo add|yarn add|pnpm add|bundle add)\s+[\w@/.-]+/i;
215
+
216
+ const WING3_CHANNEL_TACTIC_PATTERN =
217
+ /\b(email subject line|tweet length|linkedin (post|ad)|facebook ad|google ads?|tiktok (post|video)|instagram (post|reel)|sms character limit|cold email template)\b/i;
218
+
219
+ // --- Wing-4 Money/Strategy/Ops cognition-boundary patterns ---
220
+ const WING4_SPINE_SLOTS = new Set(['fiscal-period', 'org-stage', 'regulatory-regime']);
221
+
222
+ const WING4_SAAS_URL_PATTERN =
223
+ /https?:\/\/[\w.-]*\.(quickbooks|intuit|netsuite|xero|sage|carta|pulley|gusto|bamboohr|lattice|15five|justworks|docusign|ironclad|onetrust|rippling|workday|deel|namely|adp|paychex|trinet|hibob|cultureamp)\.(com|io|co)\b/i;
224
+
225
+ const WING4_VENDOR_BLACKLIST =
226
+ /\b(quickbooks|netsuite|xero|sage intacct|carta|pulley|gusto|bamboohr|lattice|15five|justworks|docusign|ironclad|onetrust|rippling|workday|deel|namely|adp|paychex|trinet|hibob|culture amp)\b/i;
227
+
228
+ const WING4_STAGE_AGNOSTIC_PATTERN =
229
+ /(?:\b\d+\s+months?\s+of\s+runway\b|\brunway\s+of\s+at\s+least\s+\d+\s+months?\b|\bminimum\s+runway\s+of\s+\d+\b|\b(?:seed|series\s+[a-d]|growth|pre-?ipo|post-?ipo)[-\s]stage\s+(?:companies|startups|teams|founders|orgs)\s+(?:must|should|always|never)\b|\bteam\s+of\s+\d+\s+(?:or\s+more|or\s+fewer)\b|\b(?:arr|mrr|burn\s+rate)\s+(?:of|over|under|above|below)\s+\$\d+)/i;
230
+
231
+ export class Issue {
232
+ severity: Severity;
233
+ code: string;
234
+ message: string;
235
+
236
+ constructor(severity: Severity, code: string, message: string) {
237
+ this.severity = severity;
238
+ this.code = code;
239
+ this.message = message;
240
+ }
241
+ }
242
+
243
+ export class LintResult {
244
+ file: string;
245
+ artifact_type: ArtifactType;
246
+ status: Status;
247
+ issues: Issue[];
248
+ suggestions: string[];
249
+
250
+ constructor(
251
+ file: string,
252
+ artifactType: ArtifactType,
253
+ status: Status,
254
+ issues: Issue[],
255
+ suggestions: string[],
256
+ ) {
257
+ this.file = file;
258
+ this.artifact_type = artifactType;
259
+ this.status = status;
260
+ this.issues = issues;
261
+ this.suggestions = suggestions;
262
+ }
263
+ }
264
+
265
+ // --- Regex / string helpers (Python parity) --------------------------------
266
+
267
+ /** Python `str.splitlines()` — splits on \n, \r, \r\n; trailing newline does
268
+ * NOT yield a final empty element. */
269
+ function splitlines(text: string): string[] {
270
+ if (text === '') {
271
+ return [];
272
+ }
273
+ const lines = text.split(/\r\n|\r|\n/);
274
+ // Python splitlines drops a single trailing empty produced by a final \n.
275
+ if (lines.length > 0 && lines[lines.length - 1] === '') {
276
+ // Only drop the trailing empty when the text ends with a line break.
277
+ if (/(\r\n|\r|\n)$/.test(text)) {
278
+ lines.pop();
279
+ }
280
+ }
281
+ return lines;
282
+ }
283
+
284
+ /** Python `len(text.splitlines())`. */
285
+ function lineCount(text: string): number {
286
+ return splitlines(text).length;
287
+ }
288
+
289
+ function isUpper(ch: string): boolean {
290
+ return ch >= 'A' && ch <= 'Z';
291
+ }
292
+ function isAlpha(ch: string): boolean {
293
+ return /[A-Za-z]/.test(ch);
294
+ }
295
+
296
+ function readText(p: string): string {
297
+ return fs.readFileSync(p, 'utf-8');
298
+ }
299
+
300
+ function isFile(p: string): boolean {
301
+ try {
302
+ return fs.statSync(p).isFile();
303
+ } catch {
304
+ return false;
305
+ }
306
+ }
307
+ function isDir(p: string): boolean {
308
+ try {
309
+ return fs.statSync(p).isDirectory();
310
+ } catch {
311
+ return false;
312
+ }
313
+ }
314
+ function exists(p: string): boolean {
315
+ return fs.existsSync(p);
316
+ }
317
+ function isSymlink(p: string): boolean {
318
+ try {
319
+ return fs.lstatSync(p).isSymbolicLink();
320
+ } catch {
321
+ return false;
322
+ }
323
+ }
324
+
325
+ /** Recursive glob equivalent of `Path.rglob(pattern)` for SKILL.md / *.md. */
326
+ function rglob(root: string, predicate: (basename: string) => boolean): string[] {
327
+ const out: string[] = [];
328
+ function walk(dir: string): void {
329
+ let entries: fs.Dirent[];
330
+ try {
331
+ entries = fs.readdirSync(dir, { withFileTypes: true });
332
+ } catch {
333
+ return;
334
+ }
335
+ for (const ent of entries) {
336
+ const full = path.join(dir, ent.name);
337
+ if (ent.isDirectory()) {
338
+ walk(full);
339
+ } else if (predicate(ent.name)) {
340
+ out.push(full);
341
+ }
342
+ }
343
+ }
344
+ walk(root);
345
+ return out;
346
+ }
347
+
348
+ /** Equivalent of `Path.glob('*.md')` (non-recursive). */
349
+ function glob(dir: string, predicate: (basename: string) => boolean): string[] {
350
+ let entries: fs.Dirent[];
351
+ try {
352
+ entries = fs.readdirSync(dir, { withFileTypes: true });
353
+ } catch {
354
+ return [];
355
+ }
356
+ return entries
357
+ .filter((e) => e.isFile() && predicate(e.name))
358
+ .map((e) => path.join(dir, e.name));
359
+ }
360
+
361
+ function basename(p: string): string {
362
+ return path.basename(p);
363
+ }
364
+ function stem(p: string): string {
365
+ const b = path.basename(p);
366
+ const dot = b.lastIndexOf('.');
367
+ return dot > 0 ? b.slice(0, dot) : b;
368
+ }
369
+ function parentName(p: string): string {
370
+ return path.basename(path.dirname(p));
371
+ }
372
+
373
+ function dedupePreserveOrder(items: Iterable<string>): string[] {
374
+ const seen = new Set<string>();
375
+ const result: string[] = [];
376
+ for (const item of items) {
377
+ if (!seen.has(item)) {
378
+ seen.add(item);
379
+ result.push(item);
380
+ }
381
+ }
382
+ return result;
383
+ }
384
+
385
+ // --- Role-contract anchor cache ---
386
+ const _ROLE_CONTRACT_CANDIDATES = ['docs/guidelines/agent-infra/role-contracts.md'];
387
+ let _ROLE_CONTRACT_SLUGS_CACHE: Set<string> | null = null;
388
+
389
+ function _loadRoleContractSlugs(): Set<string> {
390
+ if (_ROLE_CONTRACT_SLUGS_CACHE !== null) {
391
+ return _ROLE_CONTRACT_SLUGS_CACHE;
392
+ }
393
+ let slugs = new Set<string>();
394
+ for (const candidate of _ROLE_CONTRACT_CANDIDATES) {
395
+ if (!exists(candidate)) {
396
+ continue;
397
+ }
398
+ let text: string;
399
+ try {
400
+ text = readText(candidate);
401
+ } catch {
402
+ continue;
403
+ }
404
+ let inSkeletons = false;
405
+ for (const line of splitlines(text)) {
406
+ if (line.startsWith('## ')) {
407
+ inSkeletons = line.trim().toLowerCase().startsWith('## contract skeletons');
408
+ continue;
409
+ }
410
+ if (inSkeletons && line.startsWith('### ')) {
411
+ const name = line.slice(4).trim().toLowerCase();
412
+ slugs.add(name.replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, ''));
413
+ }
414
+ }
415
+ if (slugs.size > 0) {
416
+ break;
417
+ }
418
+ }
419
+ _ROLE_CONTRACT_SLUGS_CACHE = slugs;
420
+ return slugs;
421
+ }
422
+
423
+ /** Test seam — reset the role-contract anchor cache. */
424
+ export function _resetRoleContractCacheForTest(): void {
425
+ _ROLE_CONTRACT_SLUGS_CACHE = null;
426
+ }
427
+
428
+ const _ROLE_CONTRACT_REF_PATTERN = /role-contracts\.md#([a-z0-9][a-z0-9-]*)/gi;
429
+
430
+ export function lint_role_contract_refs(text: string): Issue[] {
431
+ const slugs = _loadRoleContractSlugs();
432
+ if (slugs.size === 0) {
433
+ return [];
434
+ }
435
+ const issues: Issue[] = [];
436
+ const seen = new Set<string>();
437
+ for (const match of text.matchAll(_ROLE_CONTRACT_REF_PATTERN)) {
438
+ const slug = (match[1] as string).toLowerCase();
439
+ if (seen.has(slug)) {
440
+ continue;
441
+ }
442
+ seen.add(slug);
443
+ if (!slugs.has(slug)) {
444
+ issues.push(
445
+ new Issue(
446
+ 'warning',
447
+ 'unknown_role_contract',
448
+ `References role-contracts.md#${slug} but no such mode is defined in the guideline (known: ${[...slugs].sort().join(', ')})`,
449
+ ),
450
+ );
451
+ }
452
+ }
453
+ return issues;
454
+ }
455
+
456
+ export function extract_sections(text: string): Set<string> {
457
+ const out = new Set<string>();
458
+ for (const m of text.matchAll(SECTION_PATTERN)) {
459
+ out.add((m[1] as string).trim());
460
+ }
461
+ return out;
462
+ }
463
+
464
+ function _densityScore(text: string): number {
465
+ let insideFence = false;
466
+ let structured = 0;
467
+ let nonBlank = 0;
468
+ for (const raw of splitlines(text)) {
469
+ const stripped = raw.trim();
470
+ if (!stripped) {
471
+ continue;
472
+ }
473
+ nonBlank += 1;
474
+ if (stripped.startsWith('```')) {
475
+ insideFence = !insideFence;
476
+ structured += 1;
477
+ continue;
478
+ }
479
+ if (insideFence) {
480
+ structured += 1;
481
+ continue;
482
+ }
483
+ if (stripped.startsWith('#')) {
484
+ structured += 1;
485
+ continue;
486
+ }
487
+ if (stripped.startsWith('|') && stripped.endsWith('|')) {
488
+ structured += 1;
489
+ continue;
490
+ }
491
+ if (stripped.startsWith('- ') || stripped.startsWith('* ') || stripped.startsWith('+ ')) {
492
+ structured += 1;
493
+ continue;
494
+ }
495
+ if (/^\d+\.\s/.test(stripped)) {
496
+ structured += 1;
497
+ continue;
498
+ }
499
+ }
500
+ if (nonBlank === 0) {
501
+ return 0.0;
502
+ }
503
+ // Python round() — banker's rounding to 3 decimals.
504
+ return roundHalfEven(structured / nonBlank, 3);
505
+ }
506
+
507
+ /** Python round(value, ndigits) — round-half-to-even. */
508
+ function roundHalfEven(value: number, ndigits: number): number {
509
+ const factor = 10 ** ndigits;
510
+ const scaled = value * factor;
511
+ const floor = Math.floor(scaled);
512
+ const diff = scaled - floor;
513
+ let rounded: number;
514
+ if (diff > 0.5) {
515
+ rounded = floor + 1;
516
+ } else if (diff < 0.5) {
517
+ rounded = floor;
518
+ } else {
519
+ rounded = floor % 2 === 0 ? floor : floor + 1;
520
+ }
521
+ return rounded / factor;
522
+ }
523
+
524
+ /** Python `f"{value:.2f}"` — round-half-to-even at 2 decimals, fixed width. */
525
+ function fmt2f(value: number): string {
526
+ return roundHalfEven(value, 2).toFixed(2);
527
+ }
528
+
529
+ const PROCEDURE_HEADING_PATTERN = /^##\s+Procedure(\s*[:—-].*)?\s*$/gm;
530
+ const COMMAND_FRONTMATTER_DELEGATION_KEYS = ['cluster:', 'routes_to:'];
531
+ const MD_LINK_PATTERN_G = /\[[^\]]+\]\(([^)]+\.md[^)]*)\)/g;
532
+
533
+ function _countProcedureSections(text: string): number {
534
+ return [...text.matchAll(PROCEDURE_HEADING_PATTERN)].length;
535
+ }
536
+
537
+ function _commandDelegationSignal(text: string, frontmatter: string | null): boolean {
538
+ if (frontmatter) {
539
+ for (const key of COMMAND_FRONTMATTER_DELEGATION_KEYS) {
540
+ // Python: re.search(rf"^{escape(key)}", frontmatter, MULTILINE)
541
+ const re = new RegExp(`^${escapeRegex(key)}`, 'm');
542
+ if (re.test(frontmatter)) {
543
+ return true;
544
+ }
545
+ }
546
+ }
547
+ if ([...text.matchAll(MD_LINK_PATTERN_G)].length >= 3) {
548
+ return true;
549
+ }
550
+ return false;
551
+ }
552
+
553
+ function escapeRegex(s: string): string {
554
+ return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
555
+ }
556
+
557
+ function _stripMarkdownForCheck(text: string): string {
558
+ let out = text.replace(/```[^\n]*\n[\s\S]*?```/g, '');
559
+ out = out.replace(/`[^`\n]+`/g, '');
560
+ out = out.replace(/\[[^\]]*\]\([^)]*\)/g, '');
561
+ return out;
562
+ }
563
+
564
+ function _ironLawBlocks(text: string): number {
565
+ let blocks = 0;
566
+ let inside = false;
567
+ let body: string[] = [];
568
+ for (const raw of splitlines(text)) {
569
+ if (raw.trim().startsWith('```')) {
570
+ if (inside && body.length > 0) {
571
+ const nonEmpty = body.filter((b) => b.trim() !== '');
572
+ const letters = nonEmpty.join('');
573
+ let upper = 0;
574
+ let total = 0;
575
+ for (const c of letters) {
576
+ if (isAlpha(c)) {
577
+ total += 1;
578
+ if (isUpper(c)) {
579
+ upper += 1;
580
+ }
581
+ }
582
+ }
583
+ if (total >= 30 && upper / total >= 0.6 && nonEmpty.length > 0) {
584
+ blocks += 1;
585
+ }
586
+ }
587
+ inside = !inside;
588
+ body = [];
589
+ continue;
590
+ }
591
+ if (inside) {
592
+ body.push(raw);
593
+ }
594
+ }
595
+ return blocks;
596
+ }
597
+
598
+ export function extract_description(text: string): string | null {
599
+ const fm = FRONTMATTER_PATTERN.exec(text);
600
+ if (!fm) {
601
+ return null;
602
+ }
603
+ const m = DESCRIPTION_PATTERN.exec(fm[1] as string);
604
+ return m ? (m[1] as string).trim() : null;
605
+ }
606
+
607
+ export const NAME_PATTERN = /^name:\s*"?(.*?)"?\s*$/m;
608
+ const DISABLE_MODEL_PATTERN = /^disable-model-invocation:\s*"?(true|false)"?\s*$/m;
609
+
610
+ export function detect_artifact_type(p: string, text: string): ArtifactType {
611
+ const pathStr = p.replace(/\\/g, '/').toLowerCase();
612
+ const hasSkillHeading = text.includes('## When to use') && text.includes('## Procedure');
613
+
614
+ if (pathStr.includes('/commands/') && basename(p) !== 'SKILL.md') {
615
+ return 'command';
616
+ }
617
+ if (basename(p).toLowerCase() === 'skill.md' || pathStr.includes('/skills/')) {
618
+ return 'skill';
619
+ }
620
+ if (pathStr.includes('/rules/')) {
621
+ return 'rule';
622
+ }
623
+ if (pathStr.includes('/guidelines/')) {
624
+ return 'guideline';
625
+ }
626
+ if (pathStr.includes('/personas/')) {
627
+ return 'persona';
628
+ }
629
+ if (pathStr.includes('/user-types/')) {
630
+ return 'user-type';
631
+ }
632
+ if (hasSkillHeading) {
633
+ return 'skill';
634
+ }
635
+ return 'unknown';
636
+ }
637
+
638
+ export function classify_status(issues: Issue[]): Status {
639
+ const severities = new Set(issues.map((i) => i.severity));
640
+ if (severities.has('error')) {
641
+ return 'fail';
642
+ }
643
+ if (severities.has('warning')) {
644
+ return 'pass_with_warnings';
645
+ }
646
+ return 'pass';
647
+ }
648
+
649
+ export function extract_section_block(text: string, sectionName: string): string {
650
+ const pattern = new RegExp(
651
+ `^##\\s+${escapeRegex(sectionName)}\\s*$([\\s\\S]*?)(?=^##\\s+|$(?![\\s\\S]))`,
652
+ 'm',
653
+ );
654
+ const match = pattern.exec(text);
655
+ return match ? (match[1] as string).trim() : '';
656
+ }
657
+
658
+ function parseOrderedListItems(text: string): string[] {
659
+ return splitlines(text)
660
+ .filter((line) => /^\s*\d+\.\s+/.test(line))
661
+ .map((line) => line.trim());
662
+ }
663
+
664
+ function countBullets(text: string): number {
665
+ return splitlines(text).filter((line) => /^\s*[*-]\s+/.test(line)).length;
666
+ }
667
+
668
+ function hasValidationStep(procedureBlock: string): boolean {
669
+ const lowered = procedureBlock.toLowerCase();
670
+ if (lowered.includes('validate') || lowered.includes('validation')) {
671
+ return true;
672
+ }
673
+ const goodSignals = [
674
+ 'expected',
675
+ 'status code',
676
+ 'no errors',
677
+ 'appears in',
678
+ 'exact check',
679
+ 'concrete checks',
680
+ 'verify',
681
+ 'confirm',
682
+ 'must pass',
683
+ 'must fail',
684
+ 'assert',
685
+ 'check that',
686
+ 'ensure',
687
+ 'run test',
688
+ 'run phpstan',
689
+ 'run ecs',
690
+ 'run rector',
691
+ 'lint',
692
+ 'passes',
693
+ 'exit code',
694
+ 'should return',
695
+ 'should contain',
696
+ 'must contain',
697
+ 'must return',
698
+ ];
699
+ return goodSignals.some((signal) => lowered.includes(signal));
700
+ }
701
+
702
+ const _INSPECT_VERB_PATTERN =
703
+ /\b(?:inspect|examine|audit|survey|read|look\s+at|check|review|understand|identify|analyze|analyse|detect|gather|discover)\b/i;
704
+
705
+ function hasInspectStep(procedureBlock: string): boolean {
706
+ return _INSPECT_VERB_PATTERN.test(procedureBlock);
707
+ }
708
+
709
+ function findVagueValidation(text: string): string[] {
710
+ const hits: string[] = [];
711
+ for (const pattern of VAGUE_VALIDATION_PATTERNS) {
712
+ const re = new RegExp(pattern, 'gi');
713
+ for (const m of text.matchAll(re)) {
714
+ hits.push(m[0]);
715
+ }
716
+ }
717
+ return hits;
718
+ }
719
+
720
+ function isProbablyTooBroad(text: string, description: string | null): boolean {
721
+ const haystacks: string[] = [];
722
+ if (description) {
723
+ haystacks.push(description.toLowerCase());
724
+ }
725
+ const whenBlock = extract_section_block(text, 'When to use');
726
+ if (whenBlock) {
727
+ haystacks.push(whenBlock.toLowerCase());
728
+ }
729
+ if (haystacks.length === 0) {
730
+ return false;
731
+ }
732
+ const combined = haystacks.join('\n');
733
+ const broadSignals = [
734
+ 'everything about',
735
+ 'general purpose',
736
+ 'general-purpose',
737
+ 'all markdown',
738
+ 'helper for everything',
739
+ ];
740
+ return broadSignals.some((signal) => combined.includes(signal));
741
+ }
742
+
743
+ function sectionMatches(required: string, sections: Set<string>): boolean {
744
+ if (sections.has(required)) {
745
+ return true;
746
+ }
747
+ const aliases = SECTION_ALIASES[required];
748
+ if (aliases) {
749
+ for (const a of aliases) {
750
+ if (sections.has(a)) {
751
+ return true;
752
+ }
753
+ }
754
+ }
755
+ for (const s of sections) {
756
+ if (s.startsWith(`${required}:`) || s.startsWith(`${required} `)) {
757
+ return true;
758
+ }
759
+ }
760
+ return false;
761
+ }
762
+
763
+ function findProcedureBlock(text: string): string | null {
764
+ const block = extract_section_block(text, 'Procedure');
765
+ if (block) {
766
+ return block;
767
+ }
768
+ const match = /^##\s+Procedure[:\s]/m.exec(text);
769
+ if (match) {
770
+ const start = (match.index ?? 0) + match[0].length;
771
+ const rest = text.slice(start);
772
+ const nextHeading = /^##\s+/m.exec(rest);
773
+ if (nextHeading) {
774
+ return text.slice(start, start + (nextHeading.index ?? 0)).trim();
775
+ }
776
+ return text.slice(start).trim();
777
+ }
778
+ return null;
779
+ }
780
+
781
+ export function extract_frontmatter(text: string): string | null {
782
+ const match = FRONTMATTER_PATTERN.exec(text);
783
+ return match ? (match[1] as string) : null;
784
+ }
785
+
786
+ function extractFrontmatterField(frontmatter: string, pattern: RegExp): string | null {
787
+ const match = pattern.exec(frontmatter);
788
+ return match ? (match[1] as string).trim() : null;
789
+ }
790
+
791
+ // --- YAML list parsing (rule router) ---
792
+
793
+ type YamlListItem = string | Record<string, string>;
794
+
795
+ function _parseTrustLevel(frontmatter: string): string | null {
796
+ const lines = splitlines(frontmatter);
797
+ let inBlock = false;
798
+ for (const line of lines) {
799
+ if (!inBlock) {
800
+ if (line.startsWith('trust:')) {
801
+ const rhs = line.slice('trust:'.length).trim();
802
+ if (rhs === '') {
803
+ inBlock = true;
804
+ }
805
+ }
806
+ continue;
807
+ }
808
+ if (line.startsWith(' level:')) {
809
+ return stripQuotes(line.slice(' level:'.length).trim());
810
+ }
811
+ if (line.startsWith(' ')) {
812
+ continue;
813
+ }
814
+ break;
815
+ }
816
+ return null;
817
+ }
818
+
819
+ function stripQuotes(s: string): string {
820
+ return s.replace(/^["']/, '').replace(/["']$/, '');
821
+ }
822
+
823
+ function _parseYamlList(frontmatter: string, key: string): YamlListItem[] | null {
824
+ const lines = splitlines(frontmatter);
825
+ const out: YamlListItem[] = [];
826
+ let inBlock = false;
827
+ for (const line of lines) {
828
+ if (!inBlock) {
829
+ if (line.startsWith(`${key}:`)) {
830
+ const rhs = line.slice(key.length + 1).trim();
831
+ if (rhs === '' || rhs === '[]') {
832
+ if (rhs === '[]') {
833
+ return [];
834
+ }
835
+ inBlock = true;
836
+ } else {
837
+ return null; // unexpected scalar shape
838
+ }
839
+ }
840
+ continue;
841
+ }
842
+ if (line.startsWith(' - ')) {
843
+ const item = line.slice(4).trim();
844
+ if (item.includes(':') && !(item.startsWith("'") || item.startsWith('"'))) {
845
+ const idx = item.indexOf(':');
846
+ const k = item.slice(0, idx);
847
+ const v = item.slice(idx + 1);
848
+ out.push({ [k.trim()]: stripQuotes(v.trim()) });
849
+ } else {
850
+ out.push(stripQuotes(item));
851
+ }
852
+ } else if (line.trim() === '' || line.startsWith(' ')) {
853
+ continue;
854
+ } else {
855
+ break;
856
+ }
857
+ }
858
+ return inBlock ? out : null;
859
+ }
860
+
861
+ function isMapping(item: YamlListItem): item is Record<string, string> {
862
+ return typeof item === 'object' && item !== null;
863
+ }
864
+
865
+ function lint_router_frontmatter(
866
+ ruleId: string,
867
+ frontmatter: string,
868
+ ruleType: string | null,
869
+ ): Issue[] {
870
+ const issues: Issue[] = [];
871
+ const triggers = _parseYamlList(frontmatter, 'triggers');
872
+ const routesTo = _parseYamlList(frontmatter, 'routes_to');
873
+
874
+ if (ruleType === 'manual') {
875
+ return issues;
876
+ }
877
+
878
+ const isKernel = KERNEL_RULE_IDS.has(ruleId) || ruleType === 'always';
879
+
880
+ if (isKernel) {
881
+ if (triggers !== null) {
882
+ issues.push(
883
+ new Issue(
884
+ 'error',
885
+ 'kernel_has_triggers',
886
+ 'Kernel rules MUST NOT declare triggers: (kernel is unconditional)',
887
+ ),
888
+ );
889
+ }
890
+ if (routesTo !== null) {
891
+ issues.push(
892
+ new Issue(
893
+ 'error',
894
+ 'kernel_has_routes_to',
895
+ 'Kernel rules MUST NOT declare routes_to: (kernel body stays inline)',
896
+ ),
897
+ );
898
+ }
899
+ return issues;
900
+ }
901
+
902
+ if (triggers === null) {
903
+ issues.push(
904
+ new Issue(
905
+ 'info',
906
+ 'router_triggers_missing',
907
+ 'Non-kernel rule has no triggers: — falls back to description matching until Phase 4 migration lands',
908
+ ),
909
+ );
910
+ } else {
911
+ triggers.forEach((item, idx) => {
912
+ if (!isMapping(item) || Object.keys(item).length !== 1) {
913
+ issues.push(
914
+ new Issue('error', 'trigger_shape_invalid', `triggers[${idx}] must be a single-key mapping`),
915
+ );
916
+ return;
917
+ }
918
+ const k = Object.keys(item)[0] as string;
919
+ if (!ROUTER_ALLOWED_TRIGGER_KEYS.has(k)) {
920
+ const allowed = [...ROUTER_ALLOWED_TRIGGER_KEYS].sort().join(', ');
921
+ issues.push(
922
+ new Issue(
923
+ 'error',
924
+ 'trigger_key_unknown',
925
+ `triggers[${idx}] key '${k}' not in allowed set (${allowed})`,
926
+ ),
927
+ );
928
+ }
929
+ });
930
+ }
931
+
932
+ if (routesTo === null) {
933
+ const trustLevel = _parseTrustLevel(frontmatter);
934
+ if (trustLevel !== 'core') {
935
+ issues.push(
936
+ new Issue(
937
+ 'info',
938
+ 'router_routes_to_missing',
939
+ 'Non-kernel rule has no routes_to: — body should migrate to skill / guideline in Phase 4',
940
+ ),
941
+ );
942
+ }
943
+ } else {
944
+ const repoRoot = path.resolve(_HERE, '..', '..');
945
+ routesTo.forEach((item, idx) => {
946
+ if (typeof item !== 'string' || !item.includes(':')) {
947
+ issues.push(new Issue('error', 'route_shape_invalid', `routes_to[${idx}] must be 'kind:id'`));
948
+ return;
949
+ }
950
+ const ci = item.indexOf(':');
951
+ const kind = item.slice(0, ci);
952
+ const targetId = item.slice(ci + 1);
953
+ let target: string | null = null;
954
+ if (kind === 'skill') {
955
+ target = resolve_logical(`skills/${targetId}/SKILL.md`);
956
+ } else if (kind === 'guideline') {
957
+ const gpath = path.join(repoRoot, 'docs', 'guidelines', `${targetId}.md`);
958
+ target = exists(gpath) ? gpath : null;
959
+ } else if (kind === 'command') {
960
+ target = resolve_logical(`commands/${targetId}.md`);
961
+ } else if (kind === 'contract') {
962
+ const cpath = path.join(repoRoot, 'docs', 'contracts', `${targetId}.md`);
963
+ if (exists(cpath)) {
964
+ target = cpath;
965
+ } else {
966
+ target = resolve_logical(`contexts/contracts/${targetId}.md`);
967
+ }
968
+ } else {
969
+ issues.push(
970
+ new Issue(
971
+ 'error',
972
+ 'route_kind_unknown',
973
+ `routes_to[${idx}] kind '${kind}' must be 'skill', 'guideline', 'command', or 'contract'`,
974
+ ),
975
+ );
976
+ return;
977
+ }
978
+ if (target === null || !exists(target)) {
979
+ issues.push(
980
+ new Issue(
981
+ 'error',
982
+ 'route_target_missing',
983
+ `routes_to[${idx}] target '${item}' not found under any artefact root`,
984
+ ),
985
+ );
986
+ }
987
+ });
988
+ }
989
+ return issues;
990
+ }
991
+
992
+ // --- Execution block ---
993
+
994
+ export type ExecutionBlock = Record<string, string | number | string[]>;
995
+
996
+ export function parseExecutionBlock(frontmatter: string): ExecutionBlock | null {
997
+ const lines = splitlines(frontmatter);
998
+ let execStart: number | null = null;
999
+ for (let i = 0; i < lines.length; i += 1) {
1000
+ if (/^execution:\s*$/.test(lines[i] as string)) {
1001
+ execStart = i;
1002
+ break;
1003
+ }
1004
+ }
1005
+ if (execStart === null) {
1006
+ return null;
1007
+ }
1008
+
1009
+ const result: ExecutionBlock & { _current_list?: string } = {};
1010
+ for (let i = execStart + 1; i < lines.length; i += 1) {
1011
+ const line = lines[i] as string;
1012
+ if (line.length > 0 && !/\s/.test(line[0] as string)) {
1013
+ break;
1014
+ }
1015
+ const stripped = line.trim();
1016
+ if (!stripped || stripped.startsWith('#')) {
1017
+ continue;
1018
+ }
1019
+ if (stripped.startsWith('- ')) {
1020
+ const cur = result._current_list;
1021
+ if (cur !== undefined) {
1022
+ (result[cur] as string[]).push(stripQuotes(stripped.slice(2).trim()));
1023
+ }
1024
+ continue;
1025
+ }
1026
+ const m = /^(\w+):\s*(.*?)\s*$/.exec(stripped);
1027
+ if (m) {
1028
+ const key = m[1] as string;
1029
+ const value = stripQuotes((m[2] as string).trim());
1030
+ if (value === '[]') {
1031
+ result[key] = [];
1032
+ result._current_list = key;
1033
+ } else if (/^\[.*\]$/.test(value)) {
1034
+ const inner = value.slice(1, -1).trim();
1035
+ if (inner) {
1036
+ result[key] = inner.split(',').map((it) => stripQuotes(it.trim()));
1037
+ } else {
1038
+ result[key] = [];
1039
+ }
1040
+ result._current_list = key;
1041
+ } else if (value === '') {
1042
+ result[key] = [];
1043
+ result._current_list = key;
1044
+ } else {
1045
+ if (/^-?[0-9]+$/.test(value)) {
1046
+ result[key] = Number.parseInt(value, 10);
1047
+ } else {
1048
+ result[key] = value;
1049
+ }
1050
+ delete result._current_list;
1051
+ }
1052
+ }
1053
+ }
1054
+ delete result._current_list;
1055
+ return result;
1056
+ }
1057
+
1058
+ function lint_senior_tier_blocks(text: string): Issue[] {
1059
+ const issues: Issue[] = [];
1060
+
1061
+ if (!SENIOR_RELATED_SKILLS_PATTERN.test(text)) {
1062
+ issues.push(
1063
+ new Issue(
1064
+ 'error',
1065
+ 'missing_senior_related_skills',
1066
+ 'Senior-tier skill missing `## Related Skills` block (skill-quality.md § Senior-Tier Required Structure)',
1067
+ ),
1068
+ );
1069
+ } else {
1070
+ const relatedBlock = extract_section_block(text, 'Related Skills') || '';
1071
+ if (!SENIOR_RELATED_WHEN_PATTERN.test(relatedBlock)) {
1072
+ issues.push(
1073
+ new Issue(
1074
+ 'error',
1075
+ 'missing_senior_related_when',
1076
+ 'Senior-tier `## Related Skills` block missing `**WHEN to use this**` list',
1077
+ ),
1078
+ );
1079
+ }
1080
+ if (!SENIOR_RELATED_WHEN_NOT_PATTERN.test(relatedBlock)) {
1081
+ issues.push(
1082
+ new Issue(
1083
+ 'error',
1084
+ 'missing_senior_related_when_not',
1085
+ 'Senior-tier `## Related Skills` block missing `**WHEN NOT to use this**` list',
1086
+ ),
1087
+ );
1088
+ }
1089
+ }
1090
+
1091
+ if (!SENIOR_PROACTIVE_PATTERN.test(text)) {
1092
+ issues.push(
1093
+ new Issue(
1094
+ 'error',
1095
+ 'missing_senior_proactive_triggers',
1096
+ 'Senior-tier skill missing `## When the agent should load this` block',
1097
+ ),
1098
+ );
1099
+ }
1100
+
1101
+ if (!SENIOR_OUTPUT_PATTERN.test(text)) {
1102
+ issues.push(
1103
+ new Issue(
1104
+ 'error',
1105
+ 'missing_senior_output_artifacts',
1106
+ 'Senior-tier skill missing `## Output` block declaring artifact name + shape',
1107
+ ),
1108
+ );
1109
+ }
1110
+
1111
+ return issues;
1112
+ }
1113
+
1114
+ function parseContextSpine(frontmatter: string): string[] | null {
1115
+ const match = CONTEXT_SPINE_INLINE_PATTERN.exec(frontmatter);
1116
+ if (match !== null) {
1117
+ const inner = (match[1] as string).trim();
1118
+ if (!inner) {
1119
+ return [];
1120
+ }
1121
+ return inner
1122
+ .split(',')
1123
+ .map((s) => stripQuotes(s.trim()))
1124
+ .filter((s) => s !== '');
1125
+ }
1126
+ const block = _parseYamlList(frontmatter, 'context_spine');
1127
+ if (block === null) {
1128
+ return null;
1129
+ }
1130
+ return block.map((item) => (typeof item === 'string' ? item : Object.keys(item)[0] ?? ''));
1131
+ }
1132
+
1133
+ function _stripWing3CarveOuts(text: string): string {
1134
+ let out = text.replace(/```[^\n]*\n[\s\S]*?```/g, '');
1135
+ out = out.replace(/`[^`]+`/g, '');
1136
+ // `## Do NOT` strip: Python uses MULTILINE|DOTALL → `^##` matches at every
1137
+ // line start. `\Z` = end of string (no trailing-newline subtlety needed).
1138
+ out = out.replace(/^##\s+Do NOT\s*$[\s\S]*?(?=^##\s+|$(?![\s\S]))/gm, '');
1139
+ // `**WHEN NOT to use this**` strip — LATENT PYTHON BUG REPLICATED: the
1140
+ // Python original passes only DOTALL|IGNORECASE (NO MULTILINE), so the
1141
+ // `^##\s+` alternative in its lookahead matches only at string position 0,
1142
+ // never at a mid-text line start. With no `**WHEN` after the first one, the
1143
+ // non-greedy `.*?` therefore consumes to end-of-string — stripping every
1144
+ // section after the first `**WHEN NOT to use this**` (e.g. Gotcha, Do NOT).
1145
+ // We mirror that by omitting the `m` flag so `^##` only matches at index 0.
1146
+ // Divergence-candidate: see report.
1147
+ out = out.replace(/\*\*WHEN NOT to use this\*\*[\s\S]*?(?=\*\*WHEN|^##\s+|$(?![\s\S]))/gi, '');
1148
+ return out;
1149
+ }
1150
+
1151
+ function lint_wing3_boundaries(text: string): Issue[] {
1152
+ const issues: Issue[] = [];
1153
+ const body = _stripWing3CarveOuts(text);
1154
+
1155
+ let m = WING3_SAAS_URL_PATTERN.exec(body);
1156
+ if (m) {
1157
+ issues.push(
1158
+ new Issue(
1159
+ 'warning',
1160
+ 'wing3_agent_operability',
1161
+ `Wing-3 skill cites external SaaS URL \`${m[0]}\` outside carve-outs — cognition skills must operate without SaaS auth (council Q7 boundary)`,
1162
+ ),
1163
+ );
1164
+ }
1165
+ m = WING3_VENDOR_BLACKLIST.exec(body);
1166
+ if (m) {
1167
+ issues.push(
1168
+ new Issue(
1169
+ 'warning',
1170
+ 'wing3_vendor_independence',
1171
+ `Wing-3 skill names vendor \`${m[0]}\` outside carve-outs — keep cognition vendor-agnostic (council Q7 boundary)`,
1172
+ ),
1173
+ );
1174
+ }
1175
+ m = WING3_STACK_LOCKED_PATTERN.exec(body);
1176
+ if (m) {
1177
+ issues.push(
1178
+ new Issue(
1179
+ 'warning',
1180
+ 'wing3_transferability',
1181
+ `Wing-3 skill includes stack-locked instruction \`${m[0]}\` outside carve-outs — cognition should transfer across stacks (council Q7 boundary)`,
1182
+ ),
1183
+ );
1184
+ }
1185
+ m = WING3_CHANNEL_TACTIC_PATTERN.exec(body);
1186
+ if (m) {
1187
+ issues.push(
1188
+ new Issue(
1189
+ 'warning',
1190
+ 'wing3_channel_agnosticism',
1191
+ `Wing-3 skill prescribes channel-specific tactic \`${m[0]}\` outside carve-outs — keep cognition channel-agnostic (council Q7 boundary)`,
1192
+ ),
1193
+ );
1194
+ }
1195
+ return issues;
1196
+ }
1197
+
1198
+ function lint_wing4_boundaries(text: string): Issue[] {
1199
+ const issues: Issue[] = [];
1200
+ const body = _stripWing3CarveOuts(text);
1201
+
1202
+ let m = WING4_SAAS_URL_PATTERN.exec(body);
1203
+ if (m) {
1204
+ issues.push(
1205
+ new Issue(
1206
+ 'warning',
1207
+ 'wing4_agent_operability',
1208
+ `Wing-4 skill cites external SaaS URL \`${m[0]}\` outside carve-outs — cognition skills must operate without SaaS auth (council Q7 boundary)`,
1209
+ ),
1210
+ );
1211
+ }
1212
+ m = WING4_VENDOR_BLACKLIST.exec(body);
1213
+ if (m) {
1214
+ issues.push(
1215
+ new Issue(
1216
+ 'warning',
1217
+ 'wing4_vendor_independence',
1218
+ `Wing-4 skill names vendor \`${m[0]}\` outside carve-outs — keep cognition vendor-agnostic (council Q7 boundary)`,
1219
+ ),
1220
+ );
1221
+ }
1222
+ m = WING3_STACK_LOCKED_PATTERN.exec(body);
1223
+ if (m) {
1224
+ issues.push(
1225
+ new Issue(
1226
+ 'warning',
1227
+ 'wing4_transferability',
1228
+ `Wing-4 skill includes stack-locked instruction \`${m[0]}\` outside carve-outs — cognition should transfer across stacks (council Q7 boundary)`,
1229
+ ),
1230
+ );
1231
+ }
1232
+ m = WING4_STAGE_AGNOSTIC_PATTERN.exec(body);
1233
+ if (m) {
1234
+ issues.push(
1235
+ new Issue(
1236
+ 'warning',
1237
+ 'wing4_stage_agnosticism',
1238
+ `Wing-4 skill prescribes stage-locked threshold \`${m[0]}\` outside carve-outs — cognition must transfer across seed and public (council Q7 boundary)`,
1239
+ ),
1240
+ );
1241
+ }
1242
+ return issues;
1243
+ }
1244
+
1245
+ function lint_execution_metadata(execution: ExecutionBlock): Issue[] {
1246
+ const issues: Issue[] = [];
1247
+
1248
+ const execType = execution.type;
1249
+ if (execType !== undefined) {
1250
+ if (typeof execType !== 'string' || !VALID_EXECUTION_TYPES.has(execType)) {
1251
+ issues.push(
1252
+ new Issue(
1253
+ 'error',
1254
+ 'invalid_execution_type',
1255
+ `Invalid execution.type '${String(execType)}'; must be one of: ${[...VALID_EXECUTION_TYPES].sort().join(', ')}`,
1256
+ ),
1257
+ );
1258
+ }
1259
+ } else {
1260
+ issues.push(
1261
+ new Issue('error', 'missing_execution_type', "Execution block present but missing 'type' field"),
1262
+ );
1263
+ }
1264
+
1265
+ const handler = execution.handler;
1266
+ if (handler !== undefined) {
1267
+ if (typeof handler !== 'string' || !VALID_EXECUTION_HANDLERS.has(handler)) {
1268
+ issues.push(
1269
+ new Issue(
1270
+ 'error',
1271
+ 'invalid_execution_handler',
1272
+ `Invalid execution.handler '${String(handler)}'; must be one of: ${[...VALID_EXECUTION_HANDLERS].sort().join(', ')}`,
1273
+ ),
1274
+ );
1275
+ }
1276
+ }
1277
+
1278
+ if (execType === 'automated') {
1279
+ if (handler === undefined || handler === 'none') {
1280
+ issues.push(
1281
+ new Issue(
1282
+ 'error',
1283
+ 'automated_missing_handler',
1284
+ "Automated execution requires a handler other than 'none'",
1285
+ ),
1286
+ );
1287
+ }
1288
+ const safetyMode = execution.safety_mode;
1289
+ if (safetyMode === undefined) {
1290
+ issues.push(
1291
+ new Issue(
1292
+ 'error',
1293
+ 'automated_missing_safety_mode',
1294
+ "Automated execution requires 'safety_mode: strict'",
1295
+ ),
1296
+ );
1297
+ } else if (typeof safetyMode !== 'string' || !VALID_EXECUTION_SAFETY_MODES.has(safetyMode)) {
1298
+ issues.push(
1299
+ new Issue('error', 'invalid_safety_mode', `Invalid safety_mode '${String(safetyMode)}'; must be 'strict'`),
1300
+ );
1301
+ }
1302
+ if (!('allowed_tools' in execution)) {
1303
+ issues.push(
1304
+ new Issue(
1305
+ 'warning',
1306
+ 'automated_missing_allowed_tools',
1307
+ "Automated execution should declare 'allowed_tools' (use [] for none)",
1308
+ ),
1309
+ );
1310
+ }
1311
+ }
1312
+
1313
+ const safetyMode = execution.safety_mode;
1314
+ if (safetyMode !== undefined && (typeof safetyMode !== 'string' || !VALID_EXECUTION_SAFETY_MODES.has(safetyMode))) {
1315
+ issues.push(
1316
+ new Issue('error', 'invalid_safety_mode', `Invalid safety_mode '${String(safetyMode)}'; must be 'strict'`),
1317
+ );
1318
+ }
1319
+
1320
+ const timeout = execution.timeout_seconds;
1321
+ if (timeout !== undefined) {
1322
+ if (typeof timeout !== 'number' || !Number.isInteger(timeout) || timeout <= 0) {
1323
+ issues.push(
1324
+ new Issue(
1325
+ 'warning',
1326
+ 'invalid_timeout',
1327
+ `timeout_seconds should be a positive integer, got '${String(timeout)}'`,
1328
+ ),
1329
+ );
1330
+ }
1331
+ }
1332
+
1333
+ const allowedTools = execution.allowed_tools;
1334
+ if (allowedTools !== undefined) {
1335
+ if (!Array.isArray(allowedTools)) {
1336
+ issues.push(new Issue('error', 'invalid_allowed_tools', 'allowed_tools must be a list'));
1337
+ } else if (!allowedTools.every((t) => typeof t === 'string')) {
1338
+ issues.push(
1339
+ new Issue('error', 'invalid_allowed_tools_entries', 'All entries in allowed_tools must be strings'),
1340
+ );
1341
+ }
1342
+ }
1343
+
1344
+ const command = execution.command;
1345
+ if (command !== undefined) {
1346
+ if (!Array.isArray(command) || !command.every((c) => typeof c === 'string')) {
1347
+ issues.push(
1348
+ new Issue('error', 'invalid_command', 'command must be a list of strings (argv form)'),
1349
+ );
1350
+ } else if (command.length === 0) {
1351
+ issues.push(new Issue('error', 'empty_command', 'command must not be empty'));
1352
+ }
1353
+ }
1354
+
1355
+ const unknown = Object.keys(execution).filter((k) => !VALID_EXECUTION_FIELDS.has(k));
1356
+ for (const field of unknown.sort()) {
1357
+ issues.push(
1358
+ new Issue('warning', 'unknown_execution_field', `Unknown field in execution block: '${field}'`),
1359
+ );
1360
+ }
1361
+
1362
+ return issues;
1363
+ }
1364
+
1365
+ export function lint_skill(p: string, text: string): LintResult {
1366
+ const issues: Issue[] = [];
1367
+ const suggestions: string[] = [];
1368
+
1369
+ const sections = extract_sections(text);
1370
+ const description = extract_description(text);
1371
+
1372
+ for (const section of REQUIRED_SKILL_SECTIONS) {
1373
+ if (!sectionMatches(section, sections)) {
1374
+ issues.push(new Issue('error', 'missing_section', `Missing required section: ${section}`));
1375
+ }
1376
+ }
1377
+
1378
+ for (const section of RECOMMENDED_SKILL_SECTIONS) {
1379
+ if (!sectionMatches(section, sections)) {
1380
+ issues.push(
1381
+ new Issue('warning', 'missing_recommended_section', `Missing recommended section: ${section}`),
1382
+ );
1383
+ }
1384
+ }
1385
+
1386
+ if (description) {
1387
+ if (description.length > 200) {
1388
+ issues.push(
1389
+ new Issue(
1390
+ 'error',
1391
+ 'description_too_long',
1392
+ `Description is ${description.length} chars (hard cap: 200) — see road-to-governance-cleanup F6`,
1393
+ ),
1394
+ );
1395
+ }
1396
+ for (const pattern of TRIGGER_WARNING_PATTERNS) {
1397
+ if (new RegExp(pattern, 'i').test(description)) {
1398
+ issues.push(new Issue('warning', 'weak_trigger', `Description looks too generic: ${description}`));
1399
+ break;
1400
+ }
1401
+ }
1402
+ } else {
1403
+ issues.push(new Issue('warning', 'missing_description', 'Frontmatter description is missing or unreadable'));
1404
+ }
1405
+
1406
+ // --- Bare-noun name check ---
1407
+ const skillName = basename(p) === 'SKILL.md' ? parentName(p) : stem(p);
1408
+ if (skillName && !skillName.includes('-') && skillName.length >= 3) {
1409
+ const ALLOWED_BARE_NOUNS = new Set([
1410
+ 'database',
1411
+ 'devcontainer',
1412
+ 'docker',
1413
+ 'eloquent',
1414
+ 'flux',
1415
+ 'forecasting',
1416
+ 'grafana',
1417
+ 'laravel',
1418
+ 'livewire',
1419
+ 'markitdown',
1420
+ 'mcp',
1421
+ 'openapi',
1422
+ 'performance',
1423
+ 'security',
1424
+ 'terraform',
1425
+ 'terragrunt',
1426
+ 'traefik',
1427
+ 'websocket',
1428
+ ]);
1429
+ if (!ALLOWED_BARE_NOUNS.has(skillName.toLowerCase())) {
1430
+ issues.push(
1431
+ new Issue(
1432
+ 'warning',
1433
+ 'bare_noun_name',
1434
+ `Bare-noun skill name \`${skillName}\` — consider adding a qualifier (e.g., \`${skillName}-management\`)`,
1435
+ ),
1436
+ );
1437
+ }
1438
+ }
1439
+
1440
+ // --- Status lifecycle check ---
1441
+ const frontmatter = extract_frontmatter(text);
1442
+ if (frontmatter) {
1443
+ const statusMatch = STATUS_PATTERN.exec(frontmatter);
1444
+ if (statusMatch) {
1445
+ const status = statusMatch[1] as string;
1446
+ if (status === 'deprecated') {
1447
+ const replacedBy = extractFrontmatterField(frontmatter, REPLACED_BY_PATTERN);
1448
+ let msg = 'Skill is deprecated';
1449
+ if (replacedBy) {
1450
+ msg += ` (replaced by: ${replacedBy})`;
1451
+ }
1452
+ issues.push(new Issue('warning', 'deprecated_skill', msg));
1453
+ } else if (status === 'superseded') {
1454
+ const replacedBy = extractFrontmatterField(frontmatter, REPLACED_BY_PATTERN);
1455
+ let msg = 'Skill is superseded — should be removed';
1456
+ if (replacedBy) {
1457
+ msg += ` (replaced by: ${replacedBy})`;
1458
+ }
1459
+ issues.push(new Issue('warning', 'superseded_skill', msg));
1460
+ }
1461
+ }
1462
+
1463
+ const execution = parseExecutionBlock(frontmatter);
1464
+ if (execution !== null) {
1465
+ issues.push(...lint_execution_metadata(execution));
1466
+ }
1467
+
1468
+ const tierMatch = TIER_PATTERN.exec(frontmatter);
1469
+ if (tierMatch && tierMatch[1] === 'senior') {
1470
+ issues.push(...lint_senior_tier_blocks(text));
1471
+ }
1472
+
1473
+ const spineSlots = parseContextSpine(frontmatter);
1474
+ if (spineSlots && spineSlots.some((s) => WING3_SPINE_SLOTS.has(s))) {
1475
+ issues.push(...lint_wing3_boundaries(text));
1476
+ }
1477
+ if (spineSlots && spineSlots.some((s) => WING4_SPINE_SLOTS.has(s))) {
1478
+ issues.push(...lint_wing4_boundaries(text));
1479
+ }
1480
+ }
1481
+
1482
+ const procedureBlock = findProcedureBlock(text);
1483
+ if (procedureBlock !== null) {
1484
+ if (!procedureBlock) {
1485
+ issues.push(new Issue('error', 'empty_procedure', 'Procedure section is empty'));
1486
+ } else {
1487
+ const hasOrdered = freshMatch(ORDERED_STEP_PATTERN, procedureBlock) !== null;
1488
+ const hasSubheadings = /^###\s+/m.test(procedureBlock);
1489
+ if (!hasOrdered && !hasSubheadings) {
1490
+ issues.push(new Issue('error', 'unordered_procedure', 'Procedure has no ordered steps or sub-headings'));
1491
+ }
1492
+ const meaningfulSteps = countMatches(ORDERED_STEP_PATTERN, procedureBlock);
1493
+ if (meaningfulSteps < 3) {
1494
+ issues.push(new Issue('warning', 'short_procedure', 'Procedure has fewer than 3 ordered steps'));
1495
+ }
1496
+ if (!hasValidationStep(procedureBlock) && !hasValidationStep(text)) {
1497
+ issues.push(new Issue('error', 'missing_validation', 'Skill lacks a concrete validation step'));
1498
+ }
1499
+ const vagueHits = findVagueValidation(procedureBlock);
1500
+ for (const hit of vagueHits) {
1501
+ issues.push(new Issue('error', 'vague_validation', `Vague validation detected: ${hit}`));
1502
+ }
1503
+ if (!hasInspectStep(procedureBlock)) {
1504
+ issues.push(new Issue('warning', 'missing_inspect_step', 'Procedure has no explicit inspect/check step'));
1505
+ }
1506
+ }
1507
+ }
1508
+
1509
+ if (text.includes('## Output format')) {
1510
+ const outputBlock = extract_section_block(text, 'Output format');
1511
+ if (!outputBlock || parseOrderedListItems(outputBlock).length < 2) {
1512
+ issues.push(
1513
+ new Issue('warning', 'weak_output_format', 'Output format should contain at least 2 ordered requirements'),
1514
+ );
1515
+ suggestions.push('Add 2-4 ordered output requirements');
1516
+ }
1517
+ } else {
1518
+ suggestions.push('Add an Output format section with ordered response constraints');
1519
+ }
1520
+
1521
+ const gotchaBlock = extract_section_block(text, 'Gotchas') || extract_section_block(text, 'Gotcha');
1522
+ if (gotchaBlock) {
1523
+ if (countBullets(gotchaBlock) < 1) {
1524
+ issues.push(new Issue('warning', 'weak_gotchas', 'Gotchas should contain at least one realistic failure mode'));
1525
+ }
1526
+ } else {
1527
+ suggestions.push('Add at least one realistic failure pattern to Gotchas');
1528
+ }
1529
+
1530
+ if (text.includes('## Do NOT')) {
1531
+ const doNotBlock = extract_section_block(text, 'Do NOT');
1532
+ if (countBullets(doNotBlock) < 1) {
1533
+ issues.push(new Issue('warning', 'weak_do_not', 'Do NOT should contain at least one enforceable constraint'));
1534
+ }
1535
+ } else {
1536
+ suggestions.push('Add at least one enforceable Do NOT constraint');
1537
+ }
1538
+
1539
+ if (isProbablyTooBroad(text, description)) {
1540
+ issues.push(new Issue('warning', 'broad_scope', 'Skill scope appears broad and may need splitting'));
1541
+ suggestions.push('Narrow the trigger or split unrelated workflows');
1542
+ }
1543
+
1544
+ // --- Developer judgment check for assisted skills ---
1545
+ const fm = extract_frontmatter(text);
1546
+ const execBlock = fm ? parseExecutionBlock(fm) : null;
1547
+ const execTypeVal = execBlock ? (execBlock.type ?? '') : '';
1548
+ if (execTypeVal === 'assisted' && procedureBlock) {
1549
+ const validationTerms = [
1550
+ 'validat',
1551
+ 'check',
1552
+ 'verify',
1553
+ 'confirm',
1554
+ 'challenge',
1555
+ 'existing',
1556
+ 'duplicate',
1557
+ 'contradict',
1558
+ 'fit',
1559
+ 'misfit',
1560
+ ];
1561
+ const lower = procedureBlock.toLowerCase();
1562
+ const hasValidation = validationTerms.some((term) => lower.includes(term));
1563
+ if (!hasValidation) {
1564
+ issues.push(
1565
+ new Issue(
1566
+ 'warning',
1567
+ 'missing_validation_step',
1568
+ 'Assisted skill has no validation/challenge step in procedure',
1569
+ ),
1570
+ );
1571
+ suggestions.push('Add a requirement-checking or validation step before implementation');
1572
+ }
1573
+ }
1574
+
1575
+ // --- Size check ---
1576
+ const totalLines = lineCount(text);
1577
+ const isMetaSkill = Boolean(fm) && /^meta_skill:\s*true\s*$/m.test(fm as string);
1578
+ if (totalLines > 400 && !isMetaSkill) {
1579
+ const density = _densityScore(text);
1580
+ const procedures = _countProcedureSections(text);
1581
+ if (density < 0.6 || procedures >= 2) {
1582
+ const reason = density < 0.6 ? `density ${fmt2f(density)} < 0.60` : `${procedures} ## Procedure blocks (≥ 2)`;
1583
+ issues.push(
1584
+ new Issue(
1585
+ 'warning',
1586
+ 'skill_too_large',
1587
+ `Skill has ${totalLines} lines and ${reason}; review for split (see linter-structural-model contract)`,
1588
+ ),
1589
+ );
1590
+ }
1591
+ }
1592
+
1593
+ // --- Pointer-only / guideline-dependent skill detection ---
1594
+ if (procedureBlock) {
1595
+ const procLines = splitlines(procedureBlock)
1596
+ .map((line) => line.trim())
1597
+ .filter((line) => line !== '');
1598
+
1599
+ const delegationCount = countMatches(
1600
+ /(?:see|read|check|follow|refer\s+to|consult|per|apply\s+.*from)\s+.*(?:guideline|skill|rule|doc|documentation)/gi,
1601
+ procedureBlock,
1602
+ );
1603
+
1604
+ const actionVerbsRe =
1605
+ /\b(?:run|execute|create|write|validate|verify|inspect|check|ensure|test|build|generate|compare|extract|parse|detect|fix|update|add|remove|install|configure|deploy|trace|review|map|resolve|measure|confirm)\b/gi;
1606
+ const actionVerbs = [...procedureBlock.matchAll(actionVerbsRe)].map((m) => m[0].toLowerCase());
1607
+ const actionCount = new Set(actionVerbs).size;
1608
+
1609
+ const meaningfulSteps = countMatches(ORDERED_STEP_PATTERN, procedureBlock);
1610
+
1611
+ const hasThinProcedure = meaningfulSteps < 3 && procLines.length < 8;
1612
+
1613
+ if (delegationCount >= 3 && actionCount <= 1 && hasThinProcedure) {
1614
+ issues.push(
1615
+ new Issue(
1616
+ 'error',
1617
+ 'guideline_dependent_skill',
1618
+ `Skill is effectively a pointer to guidelines/docs (${delegationCount} delegations, ${actionCount} action verbs, ${meaningfulSteps} steps) — not an executable workflow`,
1619
+ ),
1620
+ );
1621
+ suggestions.push('Add concrete steps, decision points, and validation directly into the skill');
1622
+ } else if (delegationCount >= 2 && actionCount <= 2 && hasThinProcedure) {
1623
+ issues.push(
1624
+ new Issue(
1625
+ 'warning',
1626
+ 'pointer_only_skill',
1627
+ `Skill appears too guideline-dependent (${delegationCount} delegations, ${actionCount} action verbs, ${meaningfulSteps} steps) — may lack its own executable workflow`,
1628
+ ),
1629
+ );
1630
+ suggestions.push('Expand the skill so it remains executable without opening a guideline');
1631
+ }
1632
+ }
1633
+
1634
+ issues.push(...validate_evals_json(p));
1635
+
1636
+ return new LintResult(p, 'skill', classify_status(issues), issues, dedupePreserveOrder(suggestions));
1637
+ }
1638
+
1639
+ export function validate_evals_json(skillPath: string): Issue[] {
1640
+ const evalsPath = path.join(path.dirname(skillPath), 'evals', 'evals.json');
1641
+ if (!isFile(evalsPath)) {
1642
+ return [];
1643
+ }
1644
+ const issues: Issue[] = [];
1645
+ let data: unknown;
1646
+ try {
1647
+ data = JSON.parse(readText(evalsPath));
1648
+ } catch (exc) {
1649
+ return [new Issue('warning', 'evals_json_unreadable', `evals/evals.json could not be parsed: ${pyExcStr(exc)}`)];
1650
+ }
1651
+ if (typeof data !== 'object' || data === null || Array.isArray(data)) {
1652
+ return [new Issue('warning', 'evals_json_shape', 'evals/evals.json root must be an object')];
1653
+ }
1654
+ const obj = data as Record<string, unknown>;
1655
+ if (!('skill' in obj) || typeof obj.skill !== 'string') {
1656
+ issues.push(
1657
+ new Issue('warning', 'evals_json_missing_skill', "evals/evals.json must declare top-level 'skill' (string)"),
1658
+ );
1659
+ }
1660
+ const scenarios = obj.scenarios;
1661
+ if (!Array.isArray(scenarios) || scenarios.length < 1) {
1662
+ issues.push(
1663
+ new Issue('warning', 'evals_json_no_scenarios', "evals/evals.json must declare 'scenarios' (non-empty array)"),
1664
+ );
1665
+ return issues;
1666
+ }
1667
+ const validKinds = ['contains', 'file_exists', 'rubric'];
1668
+ const validKindsSet = new Set(validKinds);
1669
+ scenarios.forEach((scenario, idx) => {
1670
+ const loc = `scenarios[${idx}]`;
1671
+ if (typeof scenario !== 'object' || scenario === null || Array.isArray(scenario)) {
1672
+ issues.push(new Issue('warning', 'evals_json_scenario_shape', `${loc} must be an object`));
1673
+ return;
1674
+ }
1675
+ const sc = scenario as Record<string, unknown>;
1676
+ for (const key of ['id', 'prompt']) {
1677
+ const v = sc[key];
1678
+ if (!(key in sc) || typeof v !== 'string' || v.trim() === '') {
1679
+ issues.push(
1680
+ new Issue('warning', 'evals_json_scenario_missing_field', `${loc} missing required string field '${key}'`),
1681
+ );
1682
+ }
1683
+ }
1684
+ const assertions = sc.assertions;
1685
+ if (!Array.isArray(assertions) || assertions.length < 1) {
1686
+ issues.push(
1687
+ new Issue('warning', 'evals_json_scenario_no_assertions', `${loc}.assertions must be a non-empty array`),
1688
+ );
1689
+ return;
1690
+ }
1691
+ assertions.forEach((assertion, aIdx) => {
1692
+ const aLoc = `${loc}.assertions[${aIdx}]`;
1693
+ if (typeof assertion !== 'object' || assertion === null || Array.isArray(assertion)) {
1694
+ issues.push(new Issue('warning', 'evals_json_assertion_shape', `${aLoc} must be an object`));
1695
+ return;
1696
+ }
1697
+ const a = assertion as Record<string, unknown>;
1698
+ const kind = a.kind;
1699
+ if (typeof kind !== 'string' || !validKindsSet.has(kind)) {
1700
+ issues.push(
1701
+ new Issue(
1702
+ 'warning',
1703
+ 'evals_json_assertion_kind',
1704
+ `${aLoc}.kind must be one of ${pyStrListRepr(validKinds)}, got ${pyReprUnknown(kind)}`,
1705
+ ),
1706
+ );
1707
+ return;
1708
+ }
1709
+ const requiredField = { contains: 'value', file_exists: 'path', rubric: 'criterion' }[kind] as string;
1710
+ if (!(requiredField in a) || typeof a[requiredField] !== 'string') {
1711
+ issues.push(
1712
+ new Issue(
1713
+ 'warning',
1714
+ 'evals_json_assertion_missing_field',
1715
+ `${aLoc} (kind=${kind}) missing required string field '${requiredField}'`,
1716
+ ),
1717
+ );
1718
+ }
1719
+ });
1720
+ });
1721
+ return issues;
1722
+ }
1723
+
1724
+ export function lint_rule(p: string, text: string): LintResult {
1725
+ const issues: Issue[] = [];
1726
+ const suggestions: string[] = [];
1727
+
1728
+ const frontmatter = extract_frontmatter(text);
1729
+ if (frontmatter === null) {
1730
+ issues.push(new Issue('error', 'missing_frontmatter', 'Rule is missing YAML frontmatter (--- block)'));
1731
+ } else {
1732
+ const ruleType = extractFrontmatterField(frontmatter, TYPE_PATTERN);
1733
+ if (ruleType === null) {
1734
+ issues.push(
1735
+ new Issue('error', 'missing_type', "Frontmatter missing 'type' field (must be 'always', 'auto', or 'manual')"),
1736
+ );
1737
+ } else if (!VALID_RULE_TYPES.has(ruleType)) {
1738
+ issues.push(
1739
+ new Issue('error', 'invalid_type', `Invalid type '${ruleType}'; must be 'always', 'auto', or 'manual'`),
1740
+ );
1741
+ }
1742
+
1743
+ const ruleSource = extractFrontmatterField(frontmatter, SOURCE_PATTERN);
1744
+ if (ruleSource !== null && !VALID_RULE_SOURCES.has(ruleSource)) {
1745
+ issues.push(
1746
+ new Issue('error', 'invalid_source', `Invalid source '${ruleSource}'; must be 'package' or 'project'`),
1747
+ );
1748
+ }
1749
+
1750
+ if (ruleType === 'auto') {
1751
+ const description = extract_description(text);
1752
+ if (!description) {
1753
+ issues.push(
1754
+ new Issue('error', 'auto_missing_description', "Auto rules require a 'description' field for matching"),
1755
+ );
1756
+ }
1757
+ }
1758
+
1759
+ const ruleDescription = extract_description(text);
1760
+ if (ruleDescription && ruleDescription.length > 200) {
1761
+ issues.push(
1762
+ new Issue(
1763
+ 'error',
1764
+ 'description_too_long',
1765
+ `Description is ${ruleDescription.length} chars (hard cap: 200) — see road-to-governance-cleanup F6`,
1766
+ ),
1767
+ );
1768
+ }
1769
+
1770
+ if (ruleType === 'always') {
1771
+ const description = extract_description(text) || '';
1772
+ const topicKeywords = [
1773
+ ...description.matchAll(
1774
+ /\b(?:PHP|Laravel|Docker|Git|E2E|Playwright|SQL|Blade|Livewire|Terraform|Jira|Sentry|translations|i18n)\b/gi,
1775
+ ),
1776
+ ].map((m) => m[0]);
1777
+ if (topicKeywords.length >= 2) {
1778
+ issues.push(
1779
+ new Issue(
1780
+ 'info',
1781
+ 'always_auto_candidate',
1782
+ `Always-rule with topic-specific description (${topicKeywords.join(', ')}) — consider auto type per rule-type-governance`,
1783
+ ),
1784
+ );
1785
+ }
1786
+ }
1787
+
1788
+ issues.push(...lint_router_frontmatter(stem(p), frontmatter, ruleType));
1789
+ }
1790
+
1791
+ if (!H1_PATTERN.test(text)) {
1792
+ issues.push(new Issue('error', 'missing_h1', 'Rule is missing an H1 heading (# Title)'));
1793
+ }
1794
+
1795
+ if (!text.endsWith('\n')) {
1796
+ issues.push(new Issue('error', 'no_trailing_newline', 'File must end with exactly one newline'));
1797
+ } else if (text.endsWith('\n\n')) {
1798
+ issues.push(new Issue('warning', 'extra_trailing_newlines', 'File ends with multiple newlines; should be exactly one'));
1799
+ }
1800
+
1801
+ if (DOUBLE_BLANK_PATTERN.test(text)) {
1802
+ issues.push(new Issue('warning', 'double_blank_lines', 'File contains double or triple blank lines'));
1803
+ }
1804
+
1805
+ const lc = splitlines(text).filter((line) => line.trim() !== '').length;
1806
+ const totalLines = lineCount(text);
1807
+ if (totalLines > 200) {
1808
+ issues.push(
1809
+ new Issue('error', 'rule_too_large', `Rule has ${totalLines} lines (hard limit: 200); must split or move to guideline`),
1810
+ );
1811
+ } else if (lc > 60) {
1812
+ const density = _densityScore(text);
1813
+ const ironBlocks = _ironLawBlocks(text);
1814
+ if (density < 0.5 && ironBlocks === 0) {
1815
+ issues.push(
1816
+ new Issue(
1817
+ 'warning',
1818
+ 'long_rule',
1819
+ `Rule has ${lc} non-empty lines, density ${fmt2f(density)} < 0.50, no Iron-Law block; rules should be concise (see linter-structural-model contract)`,
1820
+ ),
1821
+ );
1822
+ }
1823
+ }
1824
+
1825
+ for (const badSign of RULE_BAD_SIGNS) {
1826
+ if (text.includes(badSign)) {
1827
+ issues.push(new Issue('error', 'rule_looks_like_skill', `Rule contains skill-like section: ${badSign}`));
1828
+ }
1829
+ }
1830
+
1831
+ // Procedural-rule heuristic.
1832
+ const body = frontmatter ? splitN(text, '---', 2)[splitN(text, '---', 2).length - 1] ?? text : text;
1833
+ const strippedBody = _stripMarkdownForCheck(body);
1834
+ const kwCount = countMatches(/\b(procedure|workflow)\b/gi, strippedBody);
1835
+ const orderedSteps = countMatches(/^\s*\d+\.\s+/gm, body);
1836
+ if (kwCount >= 2 && orderedSteps >= 3 && _ironLawBlocks(text) === 0) {
1837
+ issues.push(new Issue('warning', 'procedural_rule', 'Rule looks procedural; consider a skill instead'));
1838
+ }
1839
+
1840
+ return new LintResult(p, 'rule', classify_status(issues), issues, dedupePreserveOrder(suggestions));
1841
+ }
1842
+
1843
+ function _lint_command_suggestion_block(text: string): Issue[] {
1844
+ const issues: Issue[] = [];
1845
+ const [data] = parse_frontmatter_for_schema(text);
1846
+ if (data === null) {
1847
+ return issues;
1848
+ }
1849
+ const suggestion = data.suggestion;
1850
+ if (suggestion === undefined) {
1851
+ issues.push(
1852
+ new Issue(
1853
+ 'error',
1854
+ 'missing_suggestion_block',
1855
+ "Command frontmatter is missing the 'suggestion' block — required by road-to-context-aware-command-suggestion Phase 2.",
1856
+ ),
1857
+ );
1858
+ return issues;
1859
+ }
1860
+ if (typeof suggestion !== 'object' || suggestion === null || Array.isArray(suggestion)) {
1861
+ issues.push(new Issue('error', 'invalid_suggestion_block', "'suggestion' must be a mapping"));
1862
+ return issues;
1863
+ }
1864
+ const sug = suggestion as Record<string, YamlValue>;
1865
+ const eligible = sug.eligible;
1866
+ if (eligible === true) {
1867
+ const td = String(sug.trigger_description ?? '').trim();
1868
+ const tc = String(sug.trigger_context ?? '').trim();
1869
+ if (!td) {
1870
+ issues.push(
1871
+ new Issue(
1872
+ 'error',
1873
+ 'missing_trigger_description',
1874
+ "suggestion.eligible=true requires a non-empty 'trigger_description'.",
1875
+ ),
1876
+ );
1877
+ } else if (td.length < 10) {
1878
+ issues.push(
1879
+ new Issue(
1880
+ 'warning',
1881
+ 'trigger_description_too_short',
1882
+ 'suggestion.trigger_description is suspiciously short (<10 chars); linter rejects empty or overly generic patterns.',
1883
+ ),
1884
+ );
1885
+ }
1886
+ if (!tc) {
1887
+ issues.push(
1888
+ new Issue(
1889
+ 'error',
1890
+ 'missing_trigger_context',
1891
+ "suggestion.eligible=true requires a non-empty 'trigger_context'.",
1892
+ ),
1893
+ );
1894
+ } else if (tc.length < 10) {
1895
+ issues.push(
1896
+ new Issue(
1897
+ 'warning',
1898
+ 'trigger_context_too_short',
1899
+ 'suggestion.trigger_context is suspiciously short (<10 chars); linter rejects empty or overly generic patterns.',
1900
+ ),
1901
+ );
1902
+ }
1903
+ } else if (eligible === false) {
1904
+ const rationale = String(sug.rationale ?? '').trim();
1905
+ if (!rationale) {
1906
+ issues.push(
1907
+ new Issue('error', 'missing_suggestion_rationale', "suggestion.eligible=false requires a non-empty 'rationale'."),
1908
+ );
1909
+ }
1910
+ } else {
1911
+ issues.push(new Issue('error', 'invalid_suggestion_eligible', 'suggestion.eligible must be true or false.'));
1912
+ }
1913
+ return issues;
1914
+ }
1915
+
1916
+ export function lint_command(p: string, text: string): LintResult {
1917
+ const issues: Issue[] = [];
1918
+ const suggestions: string[] = [];
1919
+
1920
+ const frontmatter = extract_frontmatter(text);
1921
+ if (frontmatter === null) {
1922
+ issues.push(new Issue('error', 'missing_frontmatter', 'Command is missing YAML frontmatter (--- block)'));
1923
+ } else {
1924
+ const nameMatch = NAME_PATTERN.exec(frontmatter);
1925
+ if (!nameMatch || (nameMatch[1] as string).trim() === '') {
1926
+ issues.push(new Issue('error', 'missing_name', "Frontmatter missing 'name' field"));
1927
+ }
1928
+
1929
+ const dmiMatch = DISABLE_MODEL_PATTERN.exec(frontmatter);
1930
+ if (dmiMatch && dmiMatch[1] !== 'true') {
1931
+ issues.push(
1932
+ new Issue('warning', 'disable_model_invocation_false', "disable-model-invocation should be 'true' for commands"),
1933
+ );
1934
+ }
1935
+
1936
+ const description = extract_description(text);
1937
+ if (!description) {
1938
+ issues.push(new Issue('warning', 'missing_description', 'Frontmatter description is missing'));
1939
+ } else if (description.length > 200) {
1940
+ issues.push(
1941
+ new Issue(
1942
+ 'error',
1943
+ 'description_too_long',
1944
+ `Description is ${description.length} chars (hard cap: 200) — see road-to-governance-cleanup F6`,
1945
+ ),
1946
+ );
1947
+ }
1948
+
1949
+ issues.push(..._lint_command_suggestion_block(text));
1950
+
1951
+ if (frontmatter.includes('superseded_by:')) {
1952
+ const shimWarning =
1953
+ /⚠️\s+\/[a-z][a-z0-9-]*\s+is deprecated;\s+use\s+\/[a-z][a-z0-9 -]+\s+instead/.test(text);
1954
+ if (!shimWarning) {
1955
+ issues.push(
1956
+ new Issue(
1957
+ 'error',
1958
+ 'shim_missing_warning',
1959
+ "Deprecation shim must contain a one-line warning matching '⚠️ /<old-name> is deprecated; use /<cluster> <sub> instead.' (or '/<cluster> --<flag>' for flag-clusters) (see docs/contracts/command-clusters.md § Deprecation shim contract)",
1960
+ ),
1961
+ );
1962
+ }
1963
+ }
1964
+ }
1965
+
1966
+ if (!H1_PATTERN.test(text)) {
1967
+ issues.push(new Issue('error', 'missing_h1', 'Command is missing an H1 heading (# Title)'));
1968
+ }
1969
+
1970
+ const sections = extract_sections(text);
1971
+ const hasSteps = [...sections].some((s) => s.toLowerCase().startsWith('step'));
1972
+ const hasNumbered = /^###?\s+(?:\d+\.|step\s+\d+)\s+/im.test(text);
1973
+ if (!hasSteps && !hasNumbered) {
1974
+ const delegated = _commandDelegationSignal(text, frontmatter);
1975
+ if (!delegated) {
1976
+ issues.push(new Issue('warning', 'no_steps', 'Command has no Steps section or numbered sub-headings'));
1977
+ }
1978
+ }
1979
+
1980
+ const wordCount = pySplitWhitespace(text).length;
1981
+ if (wordCount > 1000) {
1982
+ const density = _densityScore(text);
1983
+ const delegated = _commandDelegationSignal(text, frontmatter);
1984
+ if (!delegated && density < 0.65) {
1985
+ issues.push(
1986
+ new Issue(
1987
+ 'warning',
1988
+ 'large_command',
1989
+ `Command has ${wordCount} words, density ${fmt2f(density)} < 0.65, no delegation signal (frontmatter cluster:/routes_to: or ≥ 3 .md links); review for split or delegation (see linter-structural-model contract)`,
1990
+ ),
1991
+ );
1992
+ }
1993
+ }
1994
+
1995
+ if (!text.endsWith('\n')) {
1996
+ issues.push(new Issue('error', 'no_trailing_newline', 'File must end with exactly one newline'));
1997
+ } else if (text.endsWith('\n\n')) {
1998
+ issues.push(new Issue('warning', 'extra_trailing_newlines', 'File ends with multiple newlines; should be exactly one'));
1999
+ }
2000
+
2001
+ issues.push(...lint_role_contract_refs(text));
2002
+
2003
+ return new LintResult(p, 'command', classify_status(issues), issues, dedupePreserveOrder(suggestions));
2004
+ }
2005
+
2006
+ export function lint_unknown(p: string): LintResult {
2007
+ const issues = [
2008
+ new Issue('error', 'unknown_artifact', 'Could not detect whether file is a skill, rule, or command'),
2009
+ ];
2010
+ return new LintResult(p, 'unknown', 'fail', issues, [
2011
+ 'Move the file into a recognized skills/, rules/, or commands/ path',
2012
+ ]);
2013
+ }
2014
+
2015
+ export function lint_guideline(p: string, text: string): LintResult {
2016
+ const issues: Issue[] = [];
2017
+
2018
+ if (!H1_PATTERN.test(text)) {
2019
+ issues.push(new Issue('warning', 'missing_h1', 'Guideline is missing an H1 heading'));
2020
+ }
2021
+
2022
+ const wordCount = pySplitWhitespace(text).length;
2023
+ if (wordCount > 1500) {
2024
+ issues.push(new Issue('info', 'large_guideline', `Guideline has ${wordCount} words (target: 400-1500)`));
2025
+ }
2026
+
2027
+ if (!text.endsWith('\n')) {
2028
+ issues.push(new Issue('warning', 'no_trailing_newline', 'File must end with exactly one newline'));
2029
+ }
2030
+
2031
+ return new LintResult(p, 'guideline', classify_status(issues), issues, []);
2032
+ }
2033
+
2034
+ export function lint_persona(p: string, text: string): LintResult {
2035
+ const issues: Issue[] = [];
2036
+
2037
+ const frontmatter = extract_frontmatter(text);
2038
+ if (!frontmatter) {
2039
+ issues.push(new Issue('error', 'missing_frontmatter', 'Persona requires YAML frontmatter'));
2040
+ return new LintResult(p, 'persona', 'fail', issues, [
2041
+ 'See .agent-src.uncondensed/templates/persona.md for the schema',
2042
+ ]);
2043
+ }
2044
+
2045
+ const required: Record<string, RegExp> = {
2046
+ id: /^id:\s*"?([\w-]+)"?\s*$/m,
2047
+ role: /^role:\s*"?(.+?)"?\s*$/m,
2048
+ description: /^description:\s*"?(.+?)"?\s*$/m,
2049
+ tier: /^tier:\s*"?(\w+)"?\s*$/m,
2050
+ };
2051
+ const optionalDefaulted: Record<string, RegExp> = {
2052
+ version: /^version:\s*"?(.+?)"?\s*$/m,
2053
+ source: /^source:\s*"?(package|project)"?\s*$/m,
2054
+ };
2055
+ const parsed: Record<string, string | number> = {};
2056
+ for (const [field, pattern] of Object.entries(required)) {
2057
+ const value = extractFrontmatterField(frontmatter, pattern);
2058
+ if (!value) {
2059
+ issues.push(new Issue('error', `missing_${field}`, `Persona frontmatter must declare \`${field}\``));
2060
+ } else {
2061
+ parsed[field] = value;
2062
+ }
2063
+ }
2064
+ for (const [field, pattern] of Object.entries(optionalDefaulted)) {
2065
+ const value = extractFrontmatterField(frontmatter, pattern);
2066
+ if (value) {
2067
+ parsed[field] = value;
2068
+ }
2069
+ }
2070
+
2071
+ if ('id' in parsed && parsed.id !== stem(p)) {
2072
+ issues.push(
2073
+ new Issue('error', 'id_filename_mismatch', `Persona id \`${parsed.id}\` must match filename stem \`${stem(p)}\``),
2074
+ );
2075
+ }
2076
+
2077
+ if ('tier' in parsed && !VALID_PERSONA_TIERS.has(parsed.tier as string)) {
2078
+ issues.push(
2079
+ new Issue(
2080
+ 'error',
2081
+ 'invalid_tier',
2082
+ `Persona tier \`${parsed.tier}\` must be one of ${pyStrListRepr([...VALID_PERSONA_TIERS].sort())}`,
2083
+ ),
2084
+ );
2085
+ }
2086
+
2087
+ const wingMatch = /^wing:\s*"?(\d+)"?\s*$/m.exec(frontmatter);
2088
+ if (wingMatch) {
2089
+ const wingValue = Number.parseInt(wingMatch[1] as string, 10);
2090
+ if (VALID_PERSONA_WINGS.has(wingValue)) {
2091
+ parsed.wing = wingValue;
2092
+ } else {
2093
+ issues.push(
2094
+ new Issue(
2095
+ 'error',
2096
+ 'invalid_wing',
2097
+ `Persona wing \`${wingValue}\` must be one of ${pyIntListRepr([...VALID_PERSONA_WINGS].sort((a, b) => a - b))}`,
2098
+ ),
2099
+ );
2100
+ }
2101
+ }
2102
+
2103
+ if ('description' in parsed && (parsed.description as string).length > 160) {
2104
+ issues.push(
2105
+ new Issue('warning', 'long_description', `Persona description is ${(parsed.description as string).length} chars (target ≤ 160)`),
2106
+ );
2107
+ }
2108
+
2109
+ const sections = extract_sections(text);
2110
+ const tier = parsed.tier;
2111
+ const requiredSections = tier === 'specialist' ? REQUIRED_PERSONA_SECTIONS_SPECIALIST : REQUIRED_PERSONA_SECTIONS_CORE;
2112
+ for (const requiredSection of requiredSections) {
2113
+ if (!sections.has(requiredSection)) {
2114
+ issues.push(new Issue('error', 'missing_section', `Persona is missing required section \`## ${requiredSection}\``));
2115
+ }
2116
+ }
2117
+
2118
+ const uqBlock = extract_section_block(text, 'Unique Questions');
2119
+ if (uqBlock) {
2120
+ const bulletCount = countMatches(/^\s*[-*]\s+/gm, uqBlock);
2121
+ if (bulletCount < 3) {
2122
+ issues.push(new Issue('warning', 'too_few_unique_questions', `Persona has ${bulletCount} unique questions (target ≥ 3)`));
2123
+ }
2124
+ }
2125
+
2126
+ if ('tier' in parsed && (parsed.tier as string) in PERSONA_LINE_BUDGETS) {
2127
+ const tierValue = parsed.tier as string;
2128
+ const wingValue = 'wing' in parsed ? (parsed.wing as number) : null;
2129
+ const wingKey = wingValue !== null ? `${tierValue}:${wingValue}` : '';
2130
+ const budget = PERSONA_LINE_BUDGETS_BY_WING[wingKey] ?? PERSONA_LINE_BUDGETS[tierValue] ?? 0;
2131
+ const lc = lineCount(text);
2132
+ if (lc > budget) {
2133
+ const scope = wingValue === null ? `${tierValue}` : `${tierValue}, wing ${wingValue}`;
2134
+ issues.push(new Issue('warning', 'size_budget', `Persona has ${lc} lines (${scope} budget ≤ ${budget})`));
2135
+ }
2136
+ }
2137
+
2138
+ if (!H1_PATTERN.test(text)) {
2139
+ issues.push(new Issue('warning', 'missing_h1', 'Persona is missing an H1 heading'));
2140
+ }
2141
+
2142
+ if (!text.endsWith('\n')) {
2143
+ issues.push(new Issue('warning', 'no_trailing_newline', 'File must end with exactly one newline'));
2144
+ }
2145
+
2146
+ return new LintResult(p, 'persona', classify_status(issues), issues, []);
2147
+ }
2148
+
2149
+ export function lint_usertype(p: string, text: string): LintResult {
2150
+ const issues: Issue[] = [];
2151
+
2152
+ const frontmatter = extract_frontmatter(text);
2153
+ if (!frontmatter) {
2154
+ issues.push(new Issue('error', 'missing_frontmatter', 'User-type requires YAML frontmatter'));
2155
+ return new LintResult(p, 'user-type', 'fail', issues, [
2156
+ '.agent-src.uncondensed/user-types/_template/user-type.md',
2157
+ ]);
2158
+ }
2159
+
2160
+ const required: Record<string, RegExp> = {
2161
+ id: /^id:\s*"?([\w-]+)"?\s*$/m,
2162
+ kind: /^kind:\s*"?([\w-]+)"?\s*$/m,
2163
+ description: /^description:\s*"?([^"\n]+?)"?\s*$/m,
2164
+ version: /^version:\s*"?([\d.]+)"?\s*$/m,
2165
+ source: /^source:\s*"?(package|project)"?\s*$/m,
2166
+ };
2167
+ const parsed: Record<string, string> = {};
2168
+ for (const [field, pattern] of Object.entries(required)) {
2169
+ const value = extractFrontmatterField(frontmatter, pattern);
2170
+ if (!value) {
2171
+ issues.push(new Issue('error', `missing_${field}`, `User-type frontmatter must declare \`${field}\``));
2172
+ } else {
2173
+ parsed[field] = value;
2174
+ }
2175
+ }
2176
+
2177
+ if ('id' in parsed && parsed.id !== stem(p)) {
2178
+ issues.push(
2179
+ new Issue('error', 'id_filename_mismatch', `User-type id \`${parsed.id}\` must match filename stem \`${stem(p)}\``),
2180
+ );
2181
+ }
2182
+
2183
+ if ('kind' in parsed && parsed.kind !== 'user-type') {
2184
+ issues.push(new Issue('error', 'invalid_kind', `User-type kind must be \`user-type\` (got \`${parsed.kind}\`)`));
2185
+ }
2186
+
2187
+ if ('description' in parsed && (parsed.description as string).length > 160) {
2188
+ issues.push(
2189
+ new Issue('warning', 'long_description', `User-type description is ${(parsed.description as string).length} chars (target ≤ 160)`),
2190
+ );
2191
+ }
2192
+
2193
+ const sections = extract_sections(text);
2194
+ for (const requiredSection of REQUIRED_USERTYPE_SECTIONS) {
2195
+ if (!sections.has(requiredSection)) {
2196
+ issues.push(new Issue('error', 'missing_section', `User-type is missing required section \`## ${requiredSection}\``));
2197
+ }
2198
+ }
2199
+
2200
+ const uqBlock = extract_section_block(text, 'Unique Questions');
2201
+ if (uqBlock) {
2202
+ const bulletCount = countMatches(/^\s*[-*]\s+/gm, uqBlock);
2203
+ if (bulletCount < 3) {
2204
+ issues.push(new Issue('warning', 'too_few_unique_questions', `User-type has ${bulletCount} unique questions (target ≥ 3)`));
2205
+ }
2206
+ }
2207
+
2208
+ const lc = lineCount(text);
2209
+ if (lc > USERTYPE_LINE_BUDGET) {
2210
+ issues.push(new Issue('warning', 'size_budget', `User-type has ${lc} lines (budget ≤ ${USERTYPE_LINE_BUDGET})`));
2211
+ }
2212
+
2213
+ if (!H1_PATTERN.test(text)) {
2214
+ issues.push(new Issue('warning', 'missing_h1', 'User-type is missing an H1 heading'));
2215
+ }
2216
+
2217
+ if (!text.endsWith('\n')) {
2218
+ issues.push(new Issue('warning', 'no_trailing_newline', 'File must end with exactly one newline'));
2219
+ }
2220
+
2221
+ return new LintResult(p, 'user-type', classify_status(issues), issues, []);
2222
+ }
2223
+
2224
+ // --- File gathering ---
2225
+
2226
+ export function gather_all_candidate_files(root: string): string[] {
2227
+ const candidates: string[] = [];
2228
+ const seenLogical = new Set<string>();
2229
+
2230
+ const add = (file: string, sourceRoot: string): void => {
2231
+ if (isSymlink(file) || !isFile(file)) {
2232
+ return;
2233
+ }
2234
+ let logical: string;
2235
+ if (isUnder(file, sourceRoot)) {
2236
+ logical = relPosix(file, sourceRoot);
2237
+ } else {
2238
+ logical = basename(file);
2239
+ }
2240
+ if (seenLogical.has(logical)) {
2241
+ return;
2242
+ }
2243
+ seenLogical.add(logical);
2244
+ candidates.push(file);
2245
+ };
2246
+
2247
+ const sources = artefact_roots();
2248
+ if (sources.length > 0) {
2249
+ for (const srcRoot of sources) {
2250
+ const skillsDir = path.join(srcRoot, 'skills');
2251
+ if (isDir(skillsDir)) {
2252
+ for (const f of rglob(skillsDir, (b) => b === 'SKILL.md')) {
2253
+ add(f, srcRoot);
2254
+ }
2255
+ }
2256
+ for (const sub of ['rules', 'commands', 'guidelines']) {
2257
+ const base = path.join(srcRoot, sub);
2258
+ if (exists(base)) {
2259
+ for (const f of rglob(base, (b) => b.endsWith('.md'))) {
2260
+ add(f, srcRoot);
2261
+ }
2262
+ }
2263
+ }
2264
+ for (const sub of ['personas', 'user-types']) {
2265
+ const base = path.join(srcRoot, sub);
2266
+ if (exists(base)) {
2267
+ for (const f of glob(base, (b) => b.endsWith('.md'))) {
2268
+ if (basename(f).toLowerCase() === 'readme.md') {
2269
+ continue;
2270
+ }
2271
+ add(f, srcRoot);
2272
+ }
2273
+ }
2274
+ }
2275
+ const charter = path.join(srcRoot, FRUGALITY_CHARTER_RELPATH);
2276
+ if (exists(charter) && !isSymlink(charter)) {
2277
+ add(charter, srcRoot);
2278
+ }
2279
+ }
2280
+ } else {
2281
+ const augmentRoot = path.join(root, 'dist/agent-src');
2282
+ if (exists(augmentRoot)) {
2283
+ const subPatterns: Array<[string, (b: string) => boolean]> = [
2284
+ ['skills', (b) => b === 'SKILL.md'],
2285
+ ['rules', (b) => b.endsWith('.md')],
2286
+ ['commands', (b) => b.endsWith('.md')],
2287
+ ['guidelines', (b) => b.endsWith('.md')],
2288
+ ];
2289
+ for (const [sub, pred] of subPatterns) {
2290
+ const base = path.join(augmentRoot, sub);
2291
+ if (exists(base)) {
2292
+ for (const f of rglob(base, pred)) {
2293
+ add(f, augmentRoot);
2294
+ }
2295
+ }
2296
+ }
2297
+ for (const sub of ['personas', 'user-types']) {
2298
+ const base = path.join(augmentRoot, sub);
2299
+ if (exists(base)) {
2300
+ for (const f of glob(base, (b) => b.endsWith('.md'))) {
2301
+ if (basename(f).toLowerCase() === 'readme.md') {
2302
+ continue;
2303
+ }
2304
+ add(f, augmentRoot);
2305
+ }
2306
+ }
2307
+ }
2308
+ const charter = path.join(augmentRoot, FRUGALITY_CHARTER_RELPATH);
2309
+ if (exists(charter) && !isSymlink(charter)) {
2310
+ add(charter, augmentRoot);
2311
+ }
2312
+ }
2313
+ }
2314
+
2315
+ return sortedUnique(candidates);
2316
+ }
2317
+
2318
+ export function gather_candidate_files_under(srcRoot: string): string[] {
2319
+ const out: string[] = [];
2320
+ if (!isDir(srcRoot)) {
2321
+ return out;
2322
+ }
2323
+ const seen = new Set<string>();
2324
+
2325
+ const push = (file: string): void => {
2326
+ if (isSymlink(file) || !isFile(file)) {
2327
+ return;
2328
+ }
2329
+ const resolved = fs.realpathSync(file);
2330
+ if (seen.has(resolved)) {
2331
+ return;
2332
+ }
2333
+ seen.add(resolved);
2334
+ out.push(file);
2335
+ };
2336
+
2337
+ const skillsDir = path.join(srcRoot, 'skills');
2338
+ if (exists(skillsDir)) {
2339
+ for (const f of rglob(skillsDir, (b) => b === 'SKILL.md')) {
2340
+ push(f);
2341
+ }
2342
+ }
2343
+ for (const sub of ['rules', 'commands', 'guidelines']) {
2344
+ const base = path.join(srcRoot, sub);
2345
+ if (exists(base)) {
2346
+ for (const f of rglob(base, (b) => b.endsWith('.md'))) {
2347
+ push(f);
2348
+ }
2349
+ }
2350
+ }
2351
+ for (const sub of ['personas', 'user-types']) {
2352
+ const base = path.join(srcRoot, sub);
2353
+ if (exists(base)) {
2354
+ for (const f of glob(base, (b) => b.endsWith('.md'))) {
2355
+ if (basename(f).toLowerCase() === 'readme.md') {
2356
+ continue;
2357
+ }
2358
+ push(f);
2359
+ }
2360
+ }
2361
+ }
2362
+ const charter = path.join(srcRoot, FRUGALITY_CHARTER_RELPATH);
2363
+ if (exists(charter) && !isSymlink(charter)) {
2364
+ push(charter);
2365
+ }
2366
+ return sortedUnique(out);
2367
+ }
2368
+
2369
+ export function gather_changed_candidate_files(root: string): string[] {
2370
+ const diffCommands = [
2371
+ ['git', 'diff', '--name-only', 'origin/main...HEAD'],
2372
+ ['git', 'diff', '--name-only', '--cached', 'HEAD'],
2373
+ ['git', 'diff', '--name-only', 'HEAD'],
2374
+ ];
2375
+ try {
2376
+ let rawLines: string[] = [];
2377
+ for (const cmd of diffCommands) {
2378
+ const result = spawnSync(cmd[0] as string, cmd.slice(1), {
2379
+ cwd: root,
2380
+ encoding: 'utf-8',
2381
+ });
2382
+ if (result.status === 0 && (result.stdout ?? '').trim()) {
2383
+ rawLines = splitlines(result.stdout);
2384
+ break;
2385
+ }
2386
+ }
2387
+
2388
+ const files: string[] = [];
2389
+ for (let raw of rawLines) {
2390
+ raw = raw.trim();
2391
+ if (!raw) {
2392
+ continue;
2393
+ }
2394
+ const p = path.join(root, raw);
2395
+ if (!exists(p)) {
2396
+ continue;
2397
+ }
2398
+ if (isSymlink(p)) {
2399
+ continue;
2400
+ }
2401
+ const norm = raw.replace(/\\/g, '/');
2402
+ const inSource =
2403
+ norm.startsWith('.agent-src.uncondensed/') ||
2404
+ norm.startsWith('dist/agent-src/') ||
2405
+ norm.includes('/.agent-src.uncondensed/') ||
2406
+ norm.includes('/dist/agent-src/');
2407
+ if (!inSource) {
2408
+ continue;
2409
+ }
2410
+ const isMd = path.extname(p) === '.md';
2411
+ const inEvals = norm.includes('/evals/');
2412
+ if (
2413
+ !inEvals &&
2414
+ (basename(p) === 'SKILL.md' || (isMd && (norm.includes('/rules/') || norm.includes('/commands/'))))
2415
+ ) {
2416
+ files.push(p);
2417
+ }
2418
+ }
2419
+ return sortedUnique(files);
2420
+ } catch {
2421
+ return [];
2422
+ }
2423
+ }
2424
+
2425
+ // --- Interaction quality checks ---
2426
+
2427
+ const _INTERACTION_NAME_PATTERNS =
2428
+ /skill-router|handoff|analysis-skill|skill-writing|skill-reviewer|model-recommendation|developer-like-execution|universal-project-analysis|interaction|autonomous-mode|feature-planning/i;
2429
+ const _INTERACTION_CONTENT_KEYWORDS = [
2430
+ 'handoff',
2431
+ 'model switch',
2432
+ 'clarification',
2433
+ 'ask the user',
2434
+ 'framework choice',
2435
+ 'requirements are unclear',
2436
+ ];
2437
+
2438
+ function _isInteractionArtifact(p: string, text: string): boolean {
2439
+ const name = p.replace(/\\/g, '/').toLowerCase();
2440
+ if (_INTERACTION_NAME_PATTERNS.test(name)) {
2441
+ return true;
2442
+ }
2443
+ const textLower = text.toLowerCase();
2444
+ const matches = _INTERACTION_CONTENT_KEYWORDS.filter((kw) => textLower.includes(kw)).length;
2445
+ return matches >= 3;
2446
+ }
2447
+
2448
+ function lint_interaction_quality(p: string, text: string): Issue[] {
2449
+ if (!_isInteractionArtifact(p, text)) {
2450
+ return [];
2451
+ }
2452
+
2453
+ const issues: Issue[] = [];
2454
+ const textLower = text.toLowerCase();
2455
+
2456
+ const hasQuestionContext = [
2457
+ 'ask the user',
2458
+ 'ask clarification',
2459
+ 'numbered options',
2460
+ 'present options',
2461
+ 'question strategy',
2462
+ 'ask before',
2463
+ ].some((kw) => textLower.includes(kw));
2464
+
2465
+ if (hasQuestionContext) {
2466
+ const hasSimple = ['simple', 'binary', 'independent'].some((kw) => textLower.includes(kw));
2467
+ const hasComplex = ['complex', 'one at a time', 'one question'].some((kw) => textLower.includes(kw));
2468
+ if (!(hasSimple && hasComplex)) {
2469
+ issues.push(
2470
+ new Issue(
2471
+ 'warning',
2472
+ 'question_strategy_missing',
2473
+ 'Interaction guidance does not distinguish simple grouped questions from complex sequential questions',
2474
+ ),
2475
+ );
2476
+ }
2477
+ }
2478
+
2479
+ const hasHandoff = ['handoff', 'model switch', 'model-switch'].some((kw) => textLower.includes(kw));
2480
+ if (hasHandoff) {
2481
+ const hasOrdering = ['last', 'after context', 'after clarification', 'after all'].some((kw) =>
2482
+ textLower.includes(kw),
2483
+ );
2484
+ if (!hasOrdering) {
2485
+ issues.push(
2486
+ new Issue(
2487
+ 'warning',
2488
+ 'handoff_order_missing',
2489
+ 'Handoff/model-switch guidance does not specify asking handoff questions AFTER context/domain questions',
2490
+ ),
2491
+ );
2492
+ }
2493
+ }
2494
+
2495
+ const hasImpl = ['implement', 'component', 'ui component', 'ui framework'].some((kw) => textLower.includes(kw));
2496
+ const hasMulti = ['multiple frameworks', 'multiple systems', 'competing', 'which framework'].some((kw) =>
2497
+ textLower.includes(kw),
2498
+ );
2499
+ if (hasImpl && hasMulti) {
2500
+ const hasGuard = [
2501
+ 'ask which',
2502
+ 'ask before',
2503
+ 'do not implement blindly',
2504
+ 'analyze what exists',
2505
+ 'do not pick',
2506
+ 'clarif',
2507
+ ].some((kw) => textLower.includes(kw));
2508
+ if (!hasGuard) {
2509
+ issues.push(
2510
+ new Issue(
2511
+ 'warning',
2512
+ 'framework_choice_guard_missing',
2513
+ 'Discusses implementation choices but does not require clarification when multiple frameworks/patterns exist',
2514
+ ),
2515
+ );
2516
+ }
2517
+ }
2518
+
2519
+ const hasExecutionGuidance = ['procedure', 'workflow', 'step 1', '### 1.'].some((kw) => textLower.includes(kw));
2520
+ if (hasExecutionGuidance) {
2521
+ const hasClarification = [
2522
+ 'requirements are unclear',
2523
+ 'ask clarification',
2524
+ 'do not assume',
2525
+ 'clarification question',
2526
+ 'missing instructions',
2527
+ 'incomplete',
2528
+ ].some((kw) => textLower.includes(kw));
2529
+ if (!hasClarification) {
2530
+ issues.push(
2531
+ new Issue(
2532
+ 'info',
2533
+ 'clarification_guard_missing',
2534
+ 'Contains action guidance but no explicit clarification behavior for incomplete requirements',
2535
+ ),
2536
+ );
2537
+ }
2538
+ }
2539
+
2540
+ const isMeta = ['review', 'improve', 'learn', 'audit', 'optim'].some((kw) => p.toLowerCase().includes(kw));
2541
+ if (isMeta) {
2542
+ const hasLearning = [
2543
+ 'learning',
2544
+ 'feedback',
2545
+ 'frustration',
2546
+ 'capture',
2547
+ 'improve the system',
2548
+ 'rule / skill',
2549
+ 'rule/skill',
2550
+ ].some((kw) => textLower.includes(kw));
2551
+ if (!hasLearning) {
2552
+ issues.push(
2553
+ new Issue(
2554
+ 'info',
2555
+ 'feedback_learning_missing',
2556
+ 'Meta/reviewer artifact does not mention learning from negative feedback or converting failures into system improvements',
2557
+ ),
2558
+ );
2559
+ }
2560
+ }
2561
+
2562
+ return issues;
2563
+ }
2564
+
2565
+ // --- Execution quality checks ---
2566
+
2567
+ const _EXEC_FILE_SIGNALS = [
2568
+ 'execution',
2569
+ 'debug',
2570
+ 'implement',
2571
+ 'developer',
2572
+ 'action',
2573
+ 'validation',
2574
+ 'testing',
2575
+ 'coder',
2576
+ 'bug',
2577
+ 'fix',
2578
+ ];
2579
+
2580
+ const _EXEC_CONTENT_SIGNALS = [
2581
+ 'implement',
2582
+ 'debug',
2583
+ 'refactor',
2584
+ 'modify',
2585
+ 'fix',
2586
+ 'verify',
2587
+ 'validate',
2588
+ 'runtime',
2589
+ 'test',
2590
+ 'coding',
2591
+ 'before acting',
2592
+ 'before coding',
2593
+ 'before changing',
2594
+ ];
2595
+
2596
+ function _isExecutionArtifact(p: string, text: string): boolean {
2597
+ const pathLower = p.replace(/\\/g, '/').toLowerCase();
2598
+ const textLower = text.toLowerCase();
2599
+
2600
+ if (
2601
+ pathLower.includes('/commands/') ||
2602
+ pathLower.includes('/guidelines/') ||
2603
+ pathLower.includes('/personas/') ||
2604
+ pathLower.includes('/user-types/')
2605
+ ) {
2606
+ return false;
2607
+ }
2608
+
2609
+ if (_EXEC_FILE_SIGNALS.some((sig) => pathLower.includes(sig))) {
2610
+ return true;
2611
+ }
2612
+
2613
+ const matches = _EXEC_CONTENT_SIGNALS.filter((sig) => textLower.includes(sig)).length;
2614
+ return matches >= 5;
2615
+ }
2616
+
2617
+ function lint_execution_quality(p: string, text: string): Issue[] {
2618
+ if (!_isExecutionArtifact(p, text)) {
2619
+ return [];
2620
+ }
2621
+
2622
+ const issues: Issue[] = [];
2623
+ const textLower = text.toLowerCase();
2624
+ const pathLower = p.replace(/\\/g, '/').toLowerCase();
2625
+
2626
+ const isStrongMatch = _EXEC_FILE_SIGNALS.some((sig) => pathLower.includes(sig));
2627
+
2628
+ const analysisSignals = [
2629
+ 'analyze',
2630
+ 'inspect',
2631
+ 'understand',
2632
+ 'read relevant',
2633
+ 'review existing',
2634
+ 'trace flow',
2635
+ 'read affected',
2636
+ 'check current',
2637
+ 'before acting',
2638
+ 'before coding',
2639
+ 'examine',
2640
+ 'study',
2641
+ 'investigate',
2642
+ 'check existing',
2643
+ 'gather context',
2644
+ 'read project',
2645
+ 'read the changelog',
2646
+ 'identify break',
2647
+ 'assess',
2648
+ 'before upgrading',
2649
+ 'before changing',
2650
+ 'before creating',
2651
+ 'before modifying',
2652
+ 'read docs',
2653
+ 'read module',
2654
+ 'read agents',
2655
+ ];
2656
+ const verificationSignals = [
2657
+ 'verify',
2658
+ 'validate',
2659
+ 'test',
2660
+ 'real execution',
2661
+ 'run endpoint',
2662
+ 'playwright',
2663
+ 'curl',
2664
+ 'postman',
2665
+ 'debugger',
2666
+ 'run tests',
2667
+ 'hit the endpoint',
2668
+ 'confirm',
2669
+ 'assert',
2670
+ 'check result',
2671
+ 'observe',
2672
+ 'run phpstan',
2673
+ 'run rector',
2674
+ 'build and verify',
2675
+ 'must pass',
2676
+ 'response shape',
2677
+ ];
2678
+ const verificationToolSignals = [
2679
+ 'playwright',
2680
+ 'curl',
2681
+ 'postman',
2682
+ 'xdebug',
2683
+ 'browser',
2684
+ 'http::fake',
2685
+ 'phpstan',
2686
+ 'rector',
2687
+ 'phpunit',
2688
+ 'pest',
2689
+ 'devcontainer build',
2690
+ ];
2691
+ const debugRuntimeSignals = [
2692
+ 'debugger',
2693
+ 'xdebug',
2694
+ 'mcp debugger',
2695
+ 'runtime inspection',
2696
+ 'trace execution',
2697
+ 'breakpoint',
2698
+ 'step through',
2699
+ 'runtime',
2700
+ 'stack trace',
2701
+ 'dump',
2702
+ 'dd(',
2703
+ ];
2704
+ const efficientToolingSignals = [
2705
+ 'jq',
2706
+ ' rg ',
2707
+ 'grep',
2708
+ 'filter',
2709
+ 'selective',
2710
+ 'extract',
2711
+ 'targeted',
2712
+ '--json',
2713
+ '--filter',
2714
+ 'narrow',
2715
+ 'scoped',
2716
+ 'specific field',
2717
+ 'only relevant',
2718
+ ];
2719
+ const antiBruteforceSignals = [
2720
+ 'avoid retr',
2721
+ 'do not brute',
2722
+ 'do not guess',
2723
+ 'do not retry blind',
2724
+ 'analyze before retry',
2725
+ 'blind retr',
2726
+ 'trial-and-error',
2727
+ 'trial and error',
2728
+ 'max 2 retries',
2729
+ 'stop and rethink',
2730
+ 'diagnose',
2731
+ 'root cause',
2732
+ 'targeted fix',
2733
+ 'do not blindly',
2734
+ 'never guess',
2735
+ ];
2736
+ const clarificationSignals = [
2737
+ 'ask',
2738
+ 'clarif',
2739
+ 'unclear',
2740
+ 'missing information',
2741
+ 'do not assume',
2742
+ "don't assume",
2743
+ 'instead of assuming',
2744
+ 'confirm with user',
2745
+ 'verify requirement',
2746
+ 'ambiguous',
2747
+ 'if unsure',
2748
+ 'when in doubt',
2749
+ ];
2750
+
2751
+ const hasAny = (signals: string[]): boolean => signals.some((s) => textLower.includes(s));
2752
+
2753
+ const sectionHeaders = [...text.matchAll(/^#{1,4}\s+(.+)$/gm)].map((m) => m[1] as string);
2754
+ const sectionHeadersLower = sectionHeaders.map((h) => h.toLowerCase());
2755
+
2756
+ const hasAnalysisSection = sectionHeadersLower.some((h) =>
2757
+ ['understand', 'analyze', 'assess', 'context', 'review', 'current setup', 'current state', 'before'].some(
2758
+ (kw) => h.includes(kw),
2759
+ ),
2760
+ );
2761
+ const hasVerificationSection = sectionHeadersLower.some((h) =>
2762
+ ['verify', 'validat', 'test', 'acceptance', 'quality gate'].some((kw) => h.includes(kw)),
2763
+ );
2764
+ // hasAntipatternSection computed in the Python original but never used downstream.
2765
+ void sectionHeadersLower.some((h) =>
2766
+ ['do not', "don't", 'gotcha', 'anti-pattern', 'avoid'].some((kw) => h.includes(kw)),
2767
+ );
2768
+
2769
+ const changeSignals = ['implement', 'modify', 'fix', 'refactor', 'change', 'update', 'code'];
2770
+ const hasChangeLanguage = changeSignals.some((s) => textLower.includes(s));
2771
+
2772
+ const hasAnalysis = hasAny(analysisSignals) || hasAnalysisSection;
2773
+ const hasVerification = hasAny(verificationSignals) || hasVerificationSection;
2774
+
2775
+ const isSkill = p.replace(/\\/g, '/').toLowerCase().includes('/skills/');
2776
+ if (isSkill && hasChangeLanguage && !hasAnalysis) {
2777
+ issues.push(
2778
+ new Issue(
2779
+ 'error',
2780
+ 'missing_analysis_before_action',
2781
+ 'Execution-oriented skill encourages implementation without requiring prior analysis of existing system',
2782
+ ),
2783
+ );
2784
+ }
2785
+
2786
+ if (isSkill && isStrongMatch && hasChangeLanguage && !hasVerification) {
2787
+ issues.push(
2788
+ new Issue(
2789
+ 'error',
2790
+ 'missing_real_verification',
2791
+ 'Implementation/debugging skill does not require real verification after changes',
2792
+ ),
2793
+ );
2794
+ }
2795
+
2796
+ if (isStrongMatch) {
2797
+ if (hasAny(verificationSignals) && !hasAny(verificationToolSignals)) {
2798
+ issues.push(
2799
+ new Issue(
2800
+ 'warning',
2801
+ 'missing_verification_tool_mapping',
2802
+ 'Verification is generic — does not reference concrete tools (Playwright, curl, Postman, Xdebug)',
2803
+ ),
2804
+ );
2805
+ }
2806
+
2807
+ const debugContext = ['debug', 'execution flow', 'trace', 'unexpected behavior'].some((s) =>
2808
+ textLower.includes(s),
2809
+ );
2810
+ if (debugContext && !hasAny(debugRuntimeSignals)) {
2811
+ issues.push(
2812
+ new Issue(
2813
+ 'warning',
2814
+ 'missing_runtime_debug_guidance',
2815
+ 'Debugging/execution artifact does not mention runtime debug tools (Xdebug, debugger, breakpoints)',
2816
+ ),
2817
+ );
2818
+ }
2819
+
2820
+ const dataContext = ['api', 'log', 'json', 'response', 'output', 'data'].some((s) => textLower.includes(s));
2821
+ if (dataContext && !hasAny(efficientToolingSignals)) {
2822
+ issues.push(
2823
+ new Issue(
2824
+ 'warning',
2825
+ 'missing_efficient_tooling_guidance',
2826
+ 'Artifact does not encourage targeted filtering tools (jq, rg, grep) for reducing output',
2827
+ ),
2828
+ );
2829
+ }
2830
+
2831
+ if (isSkill && hasChangeLanguage && !hasAny(antiBruteforceSignals)) {
2832
+ issues.push(
2833
+ new Issue(
2834
+ 'warning',
2835
+ 'missing_anti_bruteforce_guidance',
2836
+ 'Execution guidance lacks explicit anti-retry / anti-bruteforce behavior',
2837
+ ),
2838
+ );
2839
+ }
2840
+
2841
+ if (isSkill && hasChangeLanguage && !hasAny(clarificationSignals)) {
2842
+ issues.push(
2843
+ new Issue(
2844
+ 'warning',
2845
+ 'missing_clarification_guard',
2846
+ 'Implementation guidance does not require clarification when requirements are incomplete',
2847
+ ),
2848
+ );
2849
+ }
2850
+ }
2851
+
2852
+ return issues;
2853
+ }
2854
+
2855
+ // --- Type boundary checks ---
2856
+
2857
+ function lint_type_boundaries(p: string, text: string, artifactType: string): Issue[] {
2858
+ const issues: Issue[] = [];
2859
+
2860
+ if (artifactType === 'guideline') {
2861
+ const numberedSteps = [
2862
+ ...text.matchAll(/^\d+\.\s+\*?\*?(?:Step|Run|Create|Execute|Implement)/gim),
2863
+ ];
2864
+ if (numberedSteps.length >= 5) {
2865
+ issues.push(
2866
+ new Issue(
2867
+ 'warning',
2868
+ 'guideline_contains_executable_procedure',
2869
+ `Guideline has ${numberedSteps.length} executable numbered steps — consider extracting into a skill or command`,
2870
+ ),
2871
+ );
2872
+ }
2873
+ }
2874
+
2875
+ if (artifactType === 'command') {
2876
+ const frontmatter = extract_frontmatter(text);
2877
+ let hasSkillsField = false;
2878
+ let isOrchestrator = false;
2879
+ if (frontmatter) {
2880
+ const skillsMatch = /skills:\s*\[(.+)\]/.exec(frontmatter);
2881
+ hasSkillsField = Boolean(skillsMatch && (skillsMatch[1] as string).trim());
2882
+ const typeMatch = /^type:\s*['"]?orchestrator['"]?\s*$/m.exec(frontmatter);
2883
+ isOrchestrator = Boolean(typeMatch);
2884
+ }
2885
+
2886
+ const hasSkillRef = /skill|SKILL\.md/.test(text);
2887
+
2888
+ if (!hasSkillsField && !hasSkillRef && !isOrchestrator) {
2889
+ issues.push(
2890
+ new Issue(
2891
+ 'warning',
2892
+ 'command_missing_skill_references',
2893
+ 'Command does not reference any skills — commands should orchestrate skills, not contain domain logic (use `type: orchestrator` in frontmatter to exempt routers)',
2894
+ ),
2895
+ );
2896
+ }
2897
+ }
2898
+
2899
+ if (artifactType === 'skill') {
2900
+ const validationSection =
2901
+ /(?:^#{1,4}\s+(?:Validat|Verif|Quality|Accept).+?\n)((?:.*\n)*?)(?=^#{1,4}\s|$(?![\s\S]))/im.exec(text);
2902
+ if (validationSection) {
2903
+ const validationText = (validationSection[1] as string).toLowerCase();
2904
+ const vaguePatterns = [
2905
+ 'check if it works',
2906
+ "make sure it's correct",
2907
+ 'verify it works',
2908
+ 'should work',
2909
+ 'looks correct',
2910
+ ];
2911
+ const concretePatterns = [
2912
+ 'run ',
2913
+ 'curl ',
2914
+ 'phpstan',
2915
+ 'rector',
2916
+ 'pest',
2917
+ 'playwright',
2918
+ 'assert',
2919
+ 'exit code',
2920
+ 'must pass',
2921
+ '0 fail',
2922
+ '0 error',
2923
+ ];
2924
+ const hasVague = vaguePatterns.some((vp) => validationText.includes(vp));
2925
+ const hasConcrete = concretePatterns.some((cp) => validationText.includes(cp));
2926
+ if (hasVague && !hasConcrete) {
2927
+ issues.push(
2928
+ new Issue(
2929
+ 'warning',
2930
+ 'skill_validation_too_generic',
2931
+ 'Validation section uses vague language — add concrete checks (commands, expected output, conditions)',
2932
+ ),
2933
+ );
2934
+ }
2935
+ }
2936
+ }
2937
+
2938
+ return issues;
2939
+ }
2940
+
2941
+ // --- Verification maturity checks ---
2942
+
2943
+ const _TASK_TYPE_SIGNALS: Record<string, string[]> = {
2944
+ backend: [
2945
+ 'api',
2946
+ 'endpoint',
2947
+ 'controller',
2948
+ 'route',
2949
+ 'service',
2950
+ 'repository',
2951
+ 'eloquent',
2952
+ 'migration',
2953
+ 'artisan',
2954
+ 'middleware',
2955
+ 'job',
2956
+ 'queue',
2957
+ ],
2958
+ frontend: ['blade', 'livewire', 'component', 'view', 'ui', 'frontend', 'tailwind', 'flux', 'css', 'template'],
2959
+ cli: ['artisan command', 'cli', 'console', 'schedule', 'cron'],
2960
+ database: ['migration', 'database', 'schema', 'index', 'query', 'sql', 'mariadb', 'mysql', 'seeder'],
2961
+ debugging: ['debug', 'xdebug', 'error', 'exception', 'sentry', 'trace', 'breakpoint', 'log'],
2962
+ };
2963
+
2964
+ const _VERIFICATION_TOOLS: Record<string, string[]> = {
2965
+ backend: ['curl', 'postman', 'http::fake', 'actingas', 'api/'],
2966
+ frontend: ['playwright', 'browser', 'screenshot', 'snapshot', 'livewire test'],
2967
+ cli: ['exit code', 'command output', 'artisan test', 'expectsoutput'],
2968
+ database: ['query', 'assertdatabase', 'migration', 'seedandassert', 'table'],
2969
+ debugging: ['xdebug', 'breakpoint', 'dump', 'dd(', 'stack trace', 'log'],
2970
+ };
2971
+
2972
+ function lint_verification_maturity(p: string, text: string, artifactType: string): Issue[] {
2973
+ if (artifactType !== 'skill') {
2974
+ return [];
2975
+ }
2976
+
2977
+ const pathLower = p.replace(/\\/g, '/').toLowerCase();
2978
+ if (!_EXEC_FILE_SIGNALS.some((sig) => pathLower.includes(sig))) {
2979
+ return [];
2980
+ }
2981
+
2982
+ const issues: Issue[] = [];
2983
+ const textLower = text.toLowerCase();
2984
+
2985
+ const detectedTypes: string[] = [];
2986
+ for (const [taskType, signals] of Object.entries(_TASK_TYPE_SIGNALS)) {
2987
+ const matches = signals.filter((s) => textLower.includes(s)).length;
2988
+ if (matches >= 2) {
2989
+ detectedTypes.push(taskType);
2990
+ }
2991
+ }
2992
+
2993
+ if (detectedTypes.length === 0) {
2994
+ return [];
2995
+ }
2996
+
2997
+ for (const taskType of detectedTypes) {
2998
+ const tools = _VERIFICATION_TOOLS[taskType] ?? [];
2999
+ const hasTool = tools.some((t) => textLower.includes(t));
3000
+ if (!hasTool) {
3001
+ issues.push(
3002
+ new Issue(
3003
+ 'warning',
3004
+ `missing_${taskType}_verification_example`,
3005
+ `Skill covers ${taskType} tasks but does not mention verification tools for that context (e.g. ${tools.slice(0, 3).join(', ')})`,
3006
+ ),
3007
+ );
3008
+ }
3009
+ }
3010
+
3011
+ return issues;
3012
+ }
3013
+
3014
+ // --- Frugality validator helpers + Layers 1 & 2 ---
3015
+
3016
+ function _headingToSlug(heading: string): string {
3017
+ let s = heading.trim().toLowerCase();
3018
+ s = s.replace(/[^a-z0-9 \-]/g, '');
3019
+ s = s.replace(/ /g, '-');
3020
+ return s.replace(/^-+|-+$/g, '');
3021
+ }
3022
+
3023
+ function _extractHeadingSlugs(text: string): Set<string> {
3024
+ const slugs = new Set<string>();
3025
+ for (const line of splitlines(text)) {
3026
+ if (line.startsWith('## ') || line.startsWith('### ')) {
3027
+ const heading = line.split(' ').slice(1).join(' ').trim();
3028
+ slugs.add(_headingToSlug(heading));
3029
+ }
3030
+ }
3031
+ return slugs;
3032
+ }
3033
+
3034
+ function _skillIdFromPath(p: string): string | null {
3035
+ if (basename(p).toLowerCase() !== 'skill.md') {
3036
+ return null;
3037
+ }
3038
+ return parentName(p);
3039
+ }
3040
+
3041
+ function _isFrugalityCharter(p: string): boolean {
3042
+ const norm = p.replace(/\\/g, '/');
3043
+ return norm.endsWith(`/${FRUGALITY_CHARTER_RELPATH}`);
3044
+ }
3045
+
3046
+ const _FRUGALITY_STANDARDS_PATTERN = /^##\s+Frugality Standards\s*$/m;
3047
+ const _FRUGALITY_CHARTER_LINK_PATTERN = /\]\([^)]*frugality-charter\.md[^)]*\)/;
3048
+
3049
+ function lint_frugality_writer_cite(p: string, text: string, artifactType: string): Issue[] {
3050
+ if (artifactType !== 'skill') {
3051
+ return [];
3052
+ }
3053
+ const skillId = _skillIdFromPath(p);
3054
+ if (skillId === null || !FRUGALITY_WRITER_SKILLS.has(skillId)) {
3055
+ return [];
3056
+ }
3057
+ const issues: Issue[] = [];
3058
+ const sectionMatch = _FRUGALITY_STANDARDS_PATTERN.exec(text);
3059
+ if (!sectionMatch) {
3060
+ issues.push(
3061
+ new Issue(
3062
+ 'error',
3063
+ 'frugality_section_missing',
3064
+ 'Writer skill must carry a `## Frugality Standards` section (road-to-token-frugality Phase 0.4 Layer 1)',
3065
+ ),
3066
+ );
3067
+ return issues;
3068
+ }
3069
+ const bodyStart = (sectionMatch.index ?? 0) + sectionMatch[0].length;
3070
+ const rest = text.slice(bodyStart);
3071
+ const nextH2 = /^##\s+/m.exec(rest);
3072
+ const bodyEnd = nextH2 ? bodyStart + (nextH2.index ?? 0) : text.length;
3073
+ const body = text.slice(bodyStart, bodyEnd);
3074
+ if (!_FRUGALITY_CHARTER_LINK_PATTERN.test(body)) {
3075
+ issues.push(
3076
+ new Issue(
3077
+ 'error',
3078
+ 'frugality_charter_cite_missing',
3079
+ '`## Frugality Standards` section must link to `frugality-charter.md` (road-to-token-frugality Phase 0.4 Layer 1)',
3080
+ ),
3081
+ );
3082
+ }
3083
+ return issues;
3084
+ }
3085
+
3086
+ const _MD_LINK_PATTERN = /\[[^\]]+\]\(([^)#]+)(?:#([^)]+))?\)/g;
3087
+
3088
+ function lint_frugality_charter_index(p: string, text: string): Issue[] {
3089
+ if (!_isFrugalityCharter(p)) {
3090
+ return [];
3091
+ }
3092
+ const issues: Issue[] = [];
3093
+ const rulesDir = path.join(path.dirname(path.dirname(path.dirname(p))), 'rules');
3094
+ const ruleSlugsCache = new Map<string, Set<string>>();
3095
+ const canonicalSatisfied = new Set<string>();
3096
+ for (const linkMatch of text.matchAll(_MD_LINK_PATTERN)) {
3097
+ const linkPath = linkMatch[1] as string;
3098
+ const linkAnchor = linkMatch[2] as string | undefined;
3099
+ const ruleName = basename(linkPath);
3100
+ if (!(ruleName in FRUGALITY_CHARTER_INDEX_RULES)) {
3101
+ continue;
3102
+ }
3103
+ if (linkAnchor === undefined) {
3104
+ continue;
3105
+ }
3106
+ const anchorLc = linkAnchor.toLowerCase();
3107
+ const requiredSubstr = FRUGALITY_CHARTER_INDEX_RULES[ruleName] as string;
3108
+ if (anchorLc.includes(requiredSubstr)) {
3109
+ canonicalSatisfied.add(ruleName);
3110
+ }
3111
+ if (!ruleSlugsCache.has(ruleName)) {
3112
+ const ruleFile = path.join(rulesDir, ruleName);
3113
+ if (!exists(ruleFile)) {
3114
+ issues.push(
3115
+ new Issue(
3116
+ 'error',
3117
+ 'frugality_charter_rule_missing',
3118
+ `Charter cites ${ruleName} but the rule file does not exist at ${ruleFile}`,
3119
+ ),
3120
+ );
3121
+ ruleSlugsCache.set(ruleName, new Set());
3122
+ continue;
3123
+ }
3124
+ let ruleText: string;
3125
+ try {
3126
+ ruleText = readText(ruleFile);
3127
+ } catch (e) {
3128
+ issues.push(
3129
+ new Issue('error', 'frugality_charter_rule_unreadable', `Cannot read ${ruleName}: ${pyExcStr(e)}`),
3130
+ );
3131
+ ruleSlugsCache.set(ruleName, new Set());
3132
+ continue;
3133
+ }
3134
+ ruleSlugsCache.set(ruleName, _extractHeadingSlugs(ruleText));
3135
+ }
3136
+ if (!(ruleSlugsCache.get(ruleName) as Set<string>).has(anchorLc)) {
3137
+ issues.push(
3138
+ new Issue(
3139
+ 'error',
3140
+ 'frugality_charter_anchor_unresolved',
3141
+ `Charter cites ${ruleName}#${linkAnchor} but no H2/H3 heading with that slug exists in the rule file`,
3142
+ ),
3143
+ );
3144
+ }
3145
+ }
3146
+ const missing = Object.keys(FRUGALITY_CHARTER_INDEX_RULES).filter((r) => !canonicalSatisfied.has(r));
3147
+ for (const ruleName of missing.sort()) {
3148
+ const requiredSubstr = FRUGALITY_CHARTER_INDEX_RULES[ruleName] as string;
3149
+ issues.push(
3150
+ new Issue(
3151
+ 'error',
3152
+ 'frugality_charter_canonical_missing',
3153
+ `Charter index lacks a canonical citation of ${ruleName} with anchor containing '${requiredSubstr}' (road-to-token-frugality Phase 0.4 Layer 2)`,
3154
+ ),
3155
+ );
3156
+ }
3157
+ return issues;
3158
+ }
3159
+
3160
+ // --- Governance & packaging checks ---
3161
+
3162
+ function lint_governance(p: string, _text: string, artifactType: string, repoRoot: string | null): Issue[] {
3163
+ const issues: Issue[] = [];
3164
+ if (repoRoot === null) {
3165
+ return issues;
3166
+ }
3167
+
3168
+ const pathStr = p;
3169
+ const isCondensed = pathStr.includes('/dist/agent-src/') && !pathStr.includes('/.agent-src.uncondensed/');
3170
+ const isUncondensed = pathStr.includes('/.agent-src.uncondensed/');
3171
+
3172
+ if (!isCondensed && !isUncondensed) {
3173
+ return issues;
3174
+ }
3175
+
3176
+ const norm = pathStr.replace(/\\/g, '/');
3177
+ if (isUncondensed) {
3178
+ let logical = stripSourcePrefix(norm);
3179
+ if (logical === null) {
3180
+ const marker = '/.agent-src.uncondensed/';
3181
+ const idx = norm.lastIndexOf(marker);
3182
+ logical = idx !== -1 ? norm.slice(idx + marker.length) : null;
3183
+ }
3184
+ if (logical) {
3185
+ const condensedPath = path.join(repoRoot, 'dist/agent-src', logical);
3186
+ if (!exists(condensedPath)) {
3187
+ issues.push(
3188
+ new Issue(
3189
+ 'warning',
3190
+ 'condensed_variant_missing',
3191
+ `Uncondensed file exists but condensed variant missing: ${basename(condensedPath)}`,
3192
+ ),
3193
+ );
3194
+ }
3195
+ }
3196
+ } else if (isCondensed) {
3197
+ const marker = '/dist/agent-src/';
3198
+ const idx = norm.lastIndexOf(marker);
3199
+ const logical = idx !== -1 ? norm.slice(idx + marker.length) : null;
3200
+ if (logical) {
3201
+ const uncondensedPath = resolve_logical(logical);
3202
+ if (uncondensedPath === null || !exists(uncondensedPath)) {
3203
+ issues.push(
3204
+ new Issue(
3205
+ 'warning',
3206
+ 'uncondensed_variant_missing',
3207
+ `Condensed file exists but uncondensed source missing: ${basename(logical)}`,
3208
+ ),
3209
+ );
3210
+ }
3211
+ }
3212
+ }
3213
+
3214
+ const locationMap: Record<string, string> = {
3215
+ skill: '/skills/',
3216
+ rule: '/rules/',
3217
+ command: '/commands/',
3218
+ guideline: '/guidelines/',
3219
+ };
3220
+ const expectedLoc = locationMap[artifactType];
3221
+ if (expectedLoc && !pathStr.includes(expectedLoc)) {
3222
+ issues.push(
3223
+ new Issue(
3224
+ 'warning',
3225
+ 'invalid_location_for_type',
3226
+ `Artifact detected as '${artifactType}' but not in expected location (${expectedLoc})`,
3227
+ ),
3228
+ );
3229
+ }
3230
+
3231
+ return issues;
3232
+ }
3233
+
3234
+ // --- Structural malice check ---
3235
+
3236
+ const _MALICE_CRED_EXFIL =
3237
+ /\b(?:curl|wget)\b[^\n]*(?:\$\{?[A-Z_]*(?:TOKEN|KEY|SECRET|PASSWORD|CREDENTIAL|API)[A-Z_]*\}?|~\/\.(?:aws|ssh)\/)/;
3238
+ const _MALICE_REMOTE_EXEC =
3239
+ /(?:\b(?:eval|exec)\s*\([^)]*(?:curl|wget|requests\.get|urllib)|\b(?:bash|sh|zsh)\s*<\s*\(\s*(?:curl|wget))/;
3240
+ const _MALICE_FORCE_PUSH =
3241
+ /\bgit\s+push\b[^\n]*--force(?:-with-lease)?\b[^\n]*\b(?:main|master|prod|production|release)\b/;
3242
+ const _MALICE_CHMOD_SECRETS = /\bchmod\s+0?[4567]\d{2}\s+[^\n]*\.(?:pem|key|env)\b/;
3243
+ const _MALICE_SHELL_INJECT = /\bsubprocess\.[A-Za-z_]+\s*\([^)]*shell\s*=\s*True[^)]*\$\{/;
3244
+
3245
+ const _MALICE_PATTERNS: Array<[string, RegExp]> = [
3246
+ ['cred_exfil', _MALICE_CRED_EXFIL],
3247
+ ['remote_exec', _MALICE_REMOTE_EXEC],
3248
+ ['force_push_protected', _MALICE_FORCE_PUSH],
3249
+ ['chmod_secrets', _MALICE_CHMOD_SECRETS],
3250
+ ['shell_injection', _MALICE_SHELL_INJECT],
3251
+ ];
3252
+
3253
+ export function check_structural_malice(text: string): Issue[] {
3254
+ const issues: Issue[] = [];
3255
+ const lines = splitlines(text);
3256
+ lines.forEach((raw, idx) => {
3257
+ const lineno = idx + 1;
3258
+ for (const [name, pattern] of _MALICE_PATTERNS) {
3259
+ const match = pattern.exec(raw);
3260
+ if (match) {
3261
+ issues.push(new Issue('error', `malice:${name}`, `${lineno}:${match[0].trim()}`));
3262
+ }
3263
+ }
3264
+ });
3265
+ return issues;
3266
+ }
3267
+
3268
+ // --- Output-schema check ---
3269
+
3270
+ const _OUTPUT_SCHEMA_KEY_PATTERN = /^(\w+):\s*(.*?)\s*$/;
3271
+
3272
+ export function parse_output_schema(text: string): Record<string, string | number | string[]> {
3273
+ const result: Record<string, string | number | string[]> = {};
3274
+ let currentList: string | null = null;
3275
+ for (const raw of splitlines(text)) {
3276
+ const stripped = raw.trim();
3277
+ if (!stripped || stripped.startsWith('#')) {
3278
+ continue;
3279
+ }
3280
+ if (stripped.startsWith('- ')) {
3281
+ if (currentList === null) {
3282
+ continue;
3283
+ }
3284
+ const value = stripQuotes(stripped.slice(2).trim());
3285
+ (result[currentList] as string[]).push(value);
3286
+ continue;
3287
+ }
3288
+ const match = _OUTPUT_SCHEMA_KEY_PATTERN.exec(stripped);
3289
+ if (!match) {
3290
+ continue;
3291
+ }
3292
+ const key = match[1] as string;
3293
+ const value = stripQuotes((match[2] as string).trim());
3294
+ if (value === '') {
3295
+ result[key] = [];
3296
+ currentList = key;
3297
+ } else {
3298
+ currentList = null;
3299
+ if (/^-?[0-9]+$/.test(value)) {
3300
+ result[key] = Number.parseInt(value, 10);
3301
+ } else {
3302
+ result[key] = value;
3303
+ }
3304
+ }
3305
+ }
3306
+ return result;
3307
+ }
3308
+
3309
+ function load_output_schema(skillPath: string): Record<string, string | number | string[]> | null {
3310
+ if (basename(skillPath) !== 'SKILL.md') {
3311
+ return null;
3312
+ }
3313
+ const schemaPath = path.join(path.dirname(skillPath), 'evals', 'output-schema.yml');
3314
+ if (!exists(schemaPath)) {
3315
+ return null;
3316
+ }
3317
+ try {
3318
+ return parse_output_schema(readText(schemaPath));
3319
+ } catch {
3320
+ return null;
3321
+ }
3322
+ }
3323
+
3324
+ export function lint_output_schema(p: string, text: string): Issue[] {
3325
+ const schema = load_output_schema(p);
3326
+ if (schema === null) {
3327
+ return [];
3328
+ }
3329
+ const required = schema.required_headers ?? [];
3330
+ if (!Array.isArray(required) || required.length === 0) {
3331
+ return [];
3332
+ }
3333
+ const issues: Issue[] = [];
3334
+ for (const header of required) {
3335
+ if (typeof header !== 'string' || header.trim() === '') {
3336
+ continue;
3337
+ }
3338
+ const pattern = new RegExp(`^##\\s+${escapeRegex(header.trim())}\\s*$`, 'm');
3339
+ if (!pattern.test(text)) {
3340
+ issues.push(
3341
+ new Issue(
3342
+ 'error',
3343
+ 'output_schema_drift',
3344
+ `Output template is missing required header \`## ${header}\` (declared in evals/output-schema.yml)`,
3345
+ ),
3346
+ );
3347
+ }
3348
+ }
3349
+ return issues;
3350
+ }
3351
+
3352
+ const _SCHEMA_ARTEFACT_TYPES = new Set(['skill', 'rule', 'command', 'persona', 'user-type']);
3353
+
3354
+ function lint_frontmatter_schema(p: string, text: string, artifactType: string): Issue[] {
3355
+ if (!_SCHEMA_ARTEFACT_TYPES.has(artifactType)) {
3356
+ return [];
3357
+ }
3358
+ let schema: Record<string, YamlValue>;
3359
+ try {
3360
+ schema = load_schema(artifactType);
3361
+ } catch (e) {
3362
+ if ((e as { code?: string }).code === 'ENOENT') {
3363
+ return [];
3364
+ }
3365
+ throw e;
3366
+ }
3367
+
3368
+ const [data] = parse_frontmatter_for_schema(text);
3369
+ if (data === null) {
3370
+ return [];
3371
+ }
3372
+
3373
+ apply_schema_defaults(data, schema);
3374
+
3375
+ const issues: Issue[] = [];
3376
+ for (const error of validate_against_schema(data, schema)) {
3377
+ const code = `schema_${error.rule}`;
3378
+ const message = `${error.path} – ${error.message}`;
3379
+ issues.push(new Issue('error', code, message));
3380
+ }
3381
+ return issues;
3382
+ }
3383
+
3384
+ export function lint_file(p: string, repoRoot: string | null = null): LintResult {
3385
+ if (basename(p).toLowerCase() === 'readme.md') {
3386
+ return new LintResult(p, 'unknown', 'pass', [], []);
3387
+ }
3388
+ const text = readText(p);
3389
+ const artifactType = detect_artifact_type(p, text);
3390
+ let displayPath = p;
3391
+ if (repoRoot) {
3392
+ if (isUnder(p, repoRoot) || path.resolve(p) === path.resolve(repoRoot)) {
3393
+ displayPath = relPosixNative(p, repoRoot);
3394
+ }
3395
+ }
3396
+
3397
+ let result: LintResult;
3398
+ if (artifactType === 'skill') {
3399
+ result = lint_skill(displayPath, text);
3400
+ } else if (artifactType === 'rule') {
3401
+ result = lint_rule(displayPath, text);
3402
+ } else if (artifactType === 'command') {
3403
+ result = lint_command(displayPath, text);
3404
+ } else if (artifactType === 'guideline') {
3405
+ result = lint_guideline(displayPath, text);
3406
+ } else if (artifactType === 'persona') {
3407
+ result = lint_persona(displayPath, text);
3408
+ } else if (artifactType === 'user-type') {
3409
+ result = lint_usertype(displayPath, text);
3410
+ } else {
3411
+ if (_isFrugalityCharter(p)) {
3412
+ const charterIssues = lint_frugality_charter_index(p, text);
3413
+ return new LintResult(displayPath, 'unknown', classify_status(charterIssues), charterIssues, []);
3414
+ }
3415
+ return lint_unknown(displayPath);
3416
+ }
3417
+
3418
+ const schemaIssues = lint_frontmatter_schema(displayPath, text, artifactType);
3419
+ if (schemaIssues.length > 0) {
3420
+ result.issues.push(...schemaIssues);
3421
+ result.status = classify_status(result.issues);
3422
+ }
3423
+
3424
+ const interactionIssues = lint_interaction_quality(displayPath, text);
3425
+ if (interactionIssues.length > 0) {
3426
+ result.issues.push(...interactionIssues);
3427
+ result.status = classify_status(result.issues);
3428
+ }
3429
+
3430
+ const executionIssues = lint_execution_quality(displayPath, text);
3431
+ if (executionIssues.length > 0) {
3432
+ result.issues.push(...executionIssues);
3433
+ result.status = classify_status(result.issues);
3434
+ }
3435
+
3436
+ const boundaryIssues = lint_type_boundaries(displayPath, text, artifactType);
3437
+ if (boundaryIssues.length > 0) {
3438
+ result.issues.push(...boundaryIssues);
3439
+ result.status = classify_status(result.issues);
3440
+ }
3441
+
3442
+ const maturityIssues = lint_verification_maturity(displayPath, text, artifactType);
3443
+ if (maturityIssues.length > 0) {
3444
+ result.issues.push(...maturityIssues);
3445
+ result.status = classify_status(result.issues);
3446
+ }
3447
+
3448
+ const governanceIssues = lint_governance(p, text, artifactType, repoRoot);
3449
+ if (governanceIssues.length > 0) {
3450
+ result.issues.push(...governanceIssues);
3451
+ result.status = classify_status(result.issues);
3452
+ }
3453
+
3454
+ if (artifactType === 'skill') {
3455
+ const outputSchemaIssues = lint_output_schema(p, text);
3456
+ if (outputSchemaIssues.length > 0) {
3457
+ result.issues.push(...outputSchemaIssues);
3458
+ result.status = classify_status(result.issues);
3459
+ }
3460
+ }
3461
+
3462
+ if (artifactType === 'skill' || artifactType === 'rule' || artifactType === 'command') {
3463
+ const maliceIssues = check_structural_malice(text);
3464
+ if (maliceIssues.length > 0) {
3465
+ result.issues.push(...maliceIssues);
3466
+ result.status = classify_status(result.issues);
3467
+ }
3468
+ }
3469
+
3470
+ const frugalityIssues = lint_frugality_writer_cite(displayPath, text, artifactType);
3471
+ if (frugalityIssues.length > 0) {
3472
+ result.issues.push(...frugalityIssues);
3473
+ result.status = classify_status(result.issues);
3474
+ }
3475
+
3476
+ return result;
3477
+ }
3478
+
3479
+ // --- Output formatting ---
3480
+
3481
+ export function format_text(results: LintResult[], quiet = false): string {
3482
+ const lines: string[] = [];
3483
+ let maliceTotal = 0;
3484
+ for (const result of results) {
3485
+ for (const issue of result.issues) {
3486
+ if (issue.code.startsWith('malice:')) {
3487
+ const patternName = issue.code.split(':').slice(1).join(':');
3488
+ const idx = issue.message.indexOf(':');
3489
+ const lineno = idx === -1 ? issue.message : issue.message.slice(0, idx);
3490
+ const matched = idx === -1 ? '' : issue.message.slice(idx + 1);
3491
+ lines.push(`${result.file}:${lineno}:malice:${patternName}:${matched}`);
3492
+ maliceTotal += 1;
3493
+ }
3494
+ }
3495
+ }
3496
+ if (maliceTotal) {
3497
+ lines.push('');
3498
+ }
3499
+
3500
+ for (const result of results) {
3501
+ if (quiet && result.status === 'pass' && result.issues.length === 0 && result.suggestions.length === 0) {
3502
+ continue;
3503
+ }
3504
+ const badge = { pass: '[PASS]', pass_with_warnings: '[WARN]', fail: '[FAIL]' }[result.status];
3505
+ lines.push(`${badge} ${result.file} (${result.artifact_type})`);
3506
+ if (result.issues.length > 0) {
3507
+ for (const issue of result.issues) {
3508
+ lines.push(` - ${issue.severity.toUpperCase()} ${issue.code}: ${issue.message}`);
3509
+ }
3510
+ } else {
3511
+ lines.push(' - No issues found');
3512
+ }
3513
+ if (result.suggestions.length > 0) {
3514
+ lines.push(' Suggested fixes:');
3515
+ for (const suggestion of result.suggestions) {
3516
+ lines.push(` - ${suggestion}`);
3517
+ }
3518
+ }
3519
+ lines.push('');
3520
+ }
3521
+
3522
+ const total = results.length;
3523
+ const fails = results.filter((r) => r.status === 'fail').length;
3524
+ const warns = results.filter((r) => r.status === 'pass_with_warnings').length;
3525
+ const passes = results.filter((r) => r.status === 'pass').length;
3526
+ const suffix = maliceTotal ? `, ${maliceTotal} malice` : '';
3527
+ lines.push(`Summary: ${passes} pass, ${warns} warn, ${fails} fail, ${total} total${suffix}`);
3528
+ return lines.join('\n');
3529
+ }
3530
+
3531
+ export function format_json(results: LintResult[]): string {
3532
+ const payload = {
3533
+ summary: {
3534
+ pass: results.filter((r) => r.status === 'pass').length,
3535
+ pass_with_warnings: results.filter((r) => r.status === 'pass_with_warnings').length,
3536
+ fail: results.filter((r) => r.status === 'fail').length,
3537
+ total: results.length,
3538
+ },
3539
+ results: results.map((r) => ({
3540
+ file: r.file,
3541
+ artifact_type: r.artifact_type,
3542
+ status: r.status,
3543
+ issues: r.issues.map((issue) => ({
3544
+ severity: issue.severity,
3545
+ code: issue.code,
3546
+ message: issue.message,
3547
+ })),
3548
+ suggestions: r.suggestions,
3549
+ })),
3550
+ };
3551
+ return jsonIndent2(payload);
3552
+ }
3553
+
3554
+ export function check_condensation_pairs(root: string): LintResult[] {
3555
+ const results: LintResult[] = [];
3556
+
3557
+ const pairs: Array<[string, string, boolean]> = [
3558
+ ['skills', 'SKILL.md', true],
3559
+ ['rules', '*.md', false],
3560
+ ['commands', '*.md', false],
3561
+ ];
3562
+
3563
+ for (const [subdir, pattern, isNested] of pairs) {
3564
+ const condensedDir = path.join(root, 'dist/agent-src', subdir);
3565
+ const uncondensedNames = new Set<string>();
3566
+ let anySource = false;
3567
+ for (const srcRoot of artefact_roots()) {
3568
+ const uncondensedDir = path.join(srcRoot, subdir);
3569
+ if (!exists(uncondensedDir)) {
3570
+ continue;
3571
+ }
3572
+ anySource = true;
3573
+ if (isNested) {
3574
+ for (const d of iterdir(uncondensedDir)) {
3575
+ if (isDir(d) && exists(path.join(d, pattern))) {
3576
+ uncondensedNames.add(basename(d));
3577
+ }
3578
+ }
3579
+ } else {
3580
+ for (const f of glob(uncondensedDir, (b) => b.endsWith('.md'))) {
3581
+ if (isFile(f)) {
3582
+ uncondensedNames.add(basename(f));
3583
+ }
3584
+ }
3585
+ }
3586
+ }
3587
+
3588
+ if (!anySource) {
3589
+ continue;
3590
+ }
3591
+
3592
+ let condensedNames = new Set<string>();
3593
+ if (exists(condensedDir)) {
3594
+ if (isNested) {
3595
+ for (const d of iterdir(condensedDir)) {
3596
+ if (isDir(d) && exists(path.join(d, pattern))) {
3597
+ condensedNames.add(basename(d));
3598
+ }
3599
+ }
3600
+ } else {
3601
+ for (const f of glob(condensedDir, (b) => b.endsWith('.md'))) {
3602
+ if (isFile(f)) {
3603
+ condensedNames.add(basename(f));
3604
+ }
3605
+ }
3606
+ }
3607
+ }
3608
+
3609
+ for (const name of [...uncondensedNames].filter((n) => !condensedNames.has(n)).sort()) {
3610
+ const pathStr = isNested
3611
+ ? `dist/agent-src/${subdir}/${name}/${pattern}`
3612
+ : `dist/agent-src/${subdir}/${name}`;
3613
+ results.push(
3614
+ new LintResult(
3615
+ pathStr,
3616
+ rstripS(subdir) as ArtifactType,
3617
+ 'fail',
3618
+ [new Issue('error', 'missing_condensed', 'Uncondensed exists but condensed version is missing')],
3619
+ [`Run /condense to generate dist/agent-src/${subdir}/${name}`],
3620
+ ),
3621
+ );
3622
+ }
3623
+
3624
+ for (const name of [...condensedNames].filter((n) => !uncondensedNames.has(n)).sort()) {
3625
+ const pathStr = isNested
3626
+ ? `dist/agent-src/${subdir}/${name}/${pattern}`
3627
+ : `dist/agent-src/${subdir}/${name}`;
3628
+ results.push(
3629
+ new LintResult(
3630
+ pathStr,
3631
+ rstripS(subdir) as ArtifactType,
3632
+ 'fail',
3633
+ [new Issue('error', 'orphaned_condensed', 'Condensed exists but uncondensed source is missing')],
3634
+ ['Delete orphaned file or restore uncondensed source'],
3635
+ ),
3636
+ );
3637
+ }
3638
+ }
3639
+
3640
+ return results;
3641
+ }
3642
+
3643
+ export function check_condensation_quality(root: string): LintResult[] {
3644
+ const results: LintResult[] = [];
3645
+ const condensedDir = path.join(root, 'dist/agent-src', 'skills');
3646
+ if (!exists(condensedDir)) {
3647
+ return results;
3648
+ }
3649
+
3650
+ const skillSources: string[] = [];
3651
+ for (const srcRoot of artefact_roots()) {
3652
+ const uncondensedDir = path.join(srcRoot, 'skills');
3653
+ if (exists(uncondensedDir)) {
3654
+ skillSources.push(...iterdir(uncondensedDir).sort());
3655
+ }
3656
+ }
3657
+ if (skillSources.length === 0) {
3658
+ return results;
3659
+ }
3660
+
3661
+ const preservedSections = ['When to use', 'Procedure', 'Gotcha', 'Gotchas', 'Do NOT', 'Output format', 'Output'];
3662
+
3663
+ for (const skillDir of skillSources) {
3664
+ const src = path.join(skillDir, 'SKILL.md');
3665
+ const dst = path.join(condensedDir, basename(skillDir), 'SKILL.md');
3666
+ if (!exists(src) || !exists(dst)) {
3667
+ continue;
3668
+ }
3669
+
3670
+ const srcText = readText(src);
3671
+ const dstText = readText(dst);
3672
+ const srcSections = extract_sections(srcText);
3673
+ const dstSections = extract_sections(dstText);
3674
+
3675
+ const issues: Issue[] = [];
3676
+ const suggestions: string[] = [];
3677
+
3678
+ for (const section of preservedSections) {
3679
+ if (sectionMatches(section, srcSections) && !sectionMatches(section, dstSections)) {
3680
+ issues.push(new Issue('warning', 'condensation_lost_section', `Condensed version lost '${section}' section`));
3681
+ }
3682
+ }
3683
+
3684
+ const srcProc = findProcedureBlock(srcText) || '';
3685
+ const dstProc = findProcedureBlock(dstText) || '';
3686
+ const validationPatterns = [/\bverif/i, /\bcheck\b/i, /\bconfirm\b/i, /\bvalidat/i, /\binspect/i];
3687
+ const srcHasValidation = validationPatterns.some((p) => p.test(srcProc));
3688
+ const dstHasValidation = validationPatterns.some((p) => p.test(dstProc));
3689
+ if (srcHasValidation && !dstHasValidation) {
3690
+ issues.push(
3691
+ new Issue(
3692
+ 'warning',
3693
+ 'condensation_lost_validation',
3694
+ 'Condensed procedure lost validation keywords present in uncondensed',
3695
+ ),
3696
+ );
3697
+ }
3698
+
3699
+ const srcCodeBlocks = countMatches(/```/g, srcText);
3700
+ const dstCodeBlocks = countMatches(/```/g, dstText);
3701
+ if (srcCodeBlocks > 0 && dstCodeBlocks < Math.floor(srcCodeBlocks / 2)) {
3702
+ issues.push(
3703
+ new Issue(
3704
+ 'warning',
3705
+ 'condensation_lost_example',
3706
+ `Condensed version has fewer code blocks (${Math.floor(dstCodeBlocks / 2)} vs ${Math.floor(srcCodeBlocks / 2)} in source)`,
3707
+ ),
3708
+ );
3709
+ }
3710
+
3711
+ const srcDonot = countMatches(/(?:Do NOT|NEVER|MUST NOT)\b/g, srcText);
3712
+ const dstDonot = countMatches(/(?:Do NOT|NEVER|MUST NOT)\b/g, dstText);
3713
+ if (srcDonot > 0 && dstDonot < Math.floor(srcDonot / 2)) {
3714
+ issues.push(
3715
+ new Issue(
3716
+ 'warning',
3717
+ 'condensation_lost_antipattern',
3718
+ `Condensed version lost anti-pattern constraints (${dstDonot} vs ${srcDonot} in source)`,
3719
+ ),
3720
+ );
3721
+ }
3722
+
3723
+ if (issues.length > 0) {
3724
+ const relPath = `dist/agent-src/skills/${basename(skillDir)}/SKILL.md`;
3725
+ results.push(
3726
+ new LintResult(
3727
+ relPath,
3728
+ 'skill',
3729
+ 'pass_with_warnings',
3730
+ issues,
3731
+ suggestions.length > 0 ? suggestions : ['Re-condense to preserve lost content'],
3732
+ ),
3733
+ );
3734
+ }
3735
+ }
3736
+
3737
+ return results;
3738
+ }
3739
+
3740
+ export function check_duplication(root: string): LintResult[] {
3741
+ void root;
3742
+ const results: LintResult[] = [];
3743
+ const skillDirs: string[] = [];
3744
+ const seen = new Set<string>();
3745
+ for (const srcRoot of artefact_roots()) {
3746
+ const sd = path.join(srcRoot, 'skills');
3747
+ if (!exists(sd)) {
3748
+ continue;
3749
+ }
3750
+ for (const d of iterdir(sd).sort()) {
3751
+ if (isDir(d) && !seen.has(basename(d))) {
3752
+ seen.add(basename(d));
3753
+ skillDirs.push(d);
3754
+ }
3755
+ }
3756
+ }
3757
+ if (skillDirs.length === 0) {
3758
+ return results;
3759
+ }
3760
+
3761
+ const skillData: Array<[string, string, string]> = [];
3762
+ for (const skillDir of skillDirs) {
3763
+ const skillFile = path.join(skillDir, 'SKILL.md');
3764
+ if (!exists(skillFile)) {
3765
+ continue;
3766
+ }
3767
+ const text = readText(skillFile);
3768
+ const desc = extract_description(text) || '';
3769
+ skillData.push([basename(skillDir), desc.toLowerCase(), skillFile]);
3770
+ }
3771
+
3772
+ for (let i = 0; i < skillData.length; i += 1) {
3773
+ const [nameA, descA] = skillData[i] as [string, string, string];
3774
+ for (let j = i + 1; j < skillData.length; j += 1) {
3775
+ const [nameB, descB] = skillData[j] as [string, string, string];
3776
+ if (nameA === nameB) {
3777
+ continue;
3778
+ }
3779
+ if (descA && descB) {
3780
+ const wordsA = new Set(descA.split(/\s+/).filter((w) => w !== ''));
3781
+ const wordsB = new Set(descB.split(/\s+/).filter((w) => w !== ''));
3782
+ if (wordsA.size > 3 && wordsB.size > 3) {
3783
+ let inter = 0;
3784
+ for (const w of wordsA) {
3785
+ if (wordsB.has(w)) {
3786
+ inter += 1;
3787
+ }
3788
+ }
3789
+ const overlap = inter / Math.min(wordsA.size, wordsB.size);
3790
+ if (overlap > 0.7) {
3791
+ const relA = `.agent-src.uncondensed/skills/${nameA}/SKILL.md`;
3792
+ results.push(
3793
+ new LintResult(
3794
+ relA,
3795
+ 'skill',
3796
+ 'pass_with_warnings',
3797
+ [
3798
+ new Issue(
3799
+ 'warning',
3800
+ 'similar_description',
3801
+ `Description highly similar to '${nameB}' (${pyPercent(overlap)} word overlap)`,
3802
+ ),
3803
+ ],
3804
+ [`Consider merging with '${nameB}' or differentiating descriptions`],
3805
+ ),
3806
+ );
3807
+ }
3808
+ }
3809
+ }
3810
+ }
3811
+ }
3812
+
3813
+ return results;
3814
+ }
3815
+
3816
+ export function compute_exit_code(results: LintResult[], strictWarnings: boolean): number {
3817
+ for (const r of results) {
3818
+ if (r.issues.some((issue) => issue.code.startsWith('malice:'))) {
3819
+ return 3;
3820
+ }
3821
+ }
3822
+ if (results.some((r) => r.status === 'fail')) {
3823
+ return 2;
3824
+ }
3825
+ if (results.some((r) => r.status === 'pass_with_warnings') && strictWarnings) {
3826
+ return 1;
3827
+ }
3828
+ return 0;
3829
+ }
3830
+
3831
+ export function format_report(results: LintResult[]): string {
3832
+ const lines = ['# Quality Report', ''];
3833
+
3834
+ const byType = new Map<string, LintResult[]>();
3835
+ for (const r of results) {
3836
+ const arr = byType.get(r.artifact_type) ?? [];
3837
+ arr.push(r);
3838
+ byType.set(r.artifact_type, arr);
3839
+ }
3840
+
3841
+ lines.push('| Type | Total | Pass | Warn | Fail | Score |');
3842
+ lines.push('|---|---|---|---|---|---|');
3843
+ let totalScore = 0.0;
3844
+ let totalCount = 0;
3845
+ for (const atype of [...byType.keys()].sort()) {
3846
+ const items = byType.get(atype) as LintResult[];
3847
+ const n = items.length;
3848
+ const nPass = items.filter((r) => r.status === 'pass').length;
3849
+ const nWarn = items.filter((r) => (r.status as string) === 'warn' || r.status === 'pass_with_warnings').length;
3850
+ const nFail = items.filter((r) => r.status === 'fail').length;
3851
+ const typeScore = (nPass * 10 + nWarn * 8 + nFail * 3) / Math.max(n, 1);
3852
+ totalScore += typeScore * n;
3853
+ totalCount += n;
3854
+ lines.push(`| ${atype} | ${n} | ${nPass} | ${nWarn} | ${nFail} | ${typeScore.toFixed(1)}/10 |`);
3855
+ }
3856
+ const overall = totalScore / Math.max(totalCount, 1);
3857
+ lines.push(`| **TOTAL** | **${totalCount}** | | | | **${overall.toFixed(1)}/10** |`);
3858
+
3859
+ const issueCounts = new Map<string, number>();
3860
+ for (const r of results) {
3861
+ for (const i of r.issues) {
3862
+ issueCounts.set(i.code, (issueCounts.get(i.code) ?? 0) + 1);
3863
+ }
3864
+ }
3865
+ if (issueCounts.size > 0) {
3866
+ lines.push('', '## Top Issues', '');
3867
+ lines.push('| Issue | Count | Severity |');
3868
+ lines.push('|---|---|---|');
3869
+ const sorted = [...issueCounts.entries()].sort((a, b) => b[1] - a[1]).slice(0, 15);
3870
+ for (const [code, count] of sorted) {
3871
+ let sev = '?';
3872
+ for (const r of results) {
3873
+ for (const i of r.issues) {
3874
+ if (i.code === code) {
3875
+ sev = i.severity;
3876
+ break;
3877
+ }
3878
+ }
3879
+ if (sev !== '?') {
3880
+ break;
3881
+ }
3882
+ }
3883
+ lines.push(`| \`${code}\` | ${count} | ${sev} |`);
3884
+ }
3885
+ }
3886
+
3887
+ const filesWithIssues = results.filter((r) => r.issues.length > 0).map((r) => [r.file, r.issues.length, r.status] as [string, number, string]);
3888
+ filesWithIssues.sort((a, b) => b[1] - a[1]);
3889
+ if (filesWithIssues.length > 0) {
3890
+ lines.push('', '## Files with Most Issues (Top 10)', '');
3891
+ lines.push('| File | Issues | Status |');
3892
+ lines.push('|---|---|---|');
3893
+ for (const [fpath, count, status] of filesWithIssues.slice(0, 10)) {
3894
+ const short = fpath.replace('.agent-src.uncondensed/', '');
3895
+ lines.push(`| \`${short}\` | ${count} | ${status} |`);
3896
+ }
3897
+ }
3898
+
3899
+ const skillResults = results.filter((r) => r.artifact_type === 'skill' && !r.file.includes('/pair-check/'));
3900
+ if (skillResults.length > 0) {
3901
+ lines.push('', '## Per-File Quality (Skills)', '');
3902
+ lines.push('| Skill | Structure | Validation | Scope | Dependency | Lines |');
3903
+ lines.push('|---|---|---|---|---|---|');
3904
+ for (const r of [...skillResults].sort((a, b) => (a.file < b.file ? -1 : a.file > b.file ? 1 : 0))) {
3905
+ const short = r.file
3906
+ .replace('.agent-src.uncondensed/skills/', '')
3907
+ .replace('dist/agent-src/skills/', '')
3908
+ .replace('/SKILL.md', '');
3909
+ const codes = new Set(r.issues.map((i) => i.code));
3910
+
3911
+ const struct = setIntersects(codes, ['missing_section', 'empty_procedure', 'unordered_procedure'])
3912
+ ? '❌'
3913
+ : '✅';
3914
+
3915
+ let valid: string;
3916
+ if (setIntersects(codes, ['missing_validation', 'vague_validation'])) {
3917
+ valid = '❌ weak';
3918
+ } else if (codes.has('missing_inspect_step')) {
3919
+ valid = '⚠️ partial';
3920
+ } else {
3921
+ valid = '✅ strong';
3922
+ }
3923
+
3924
+ const scope = codes.has('broad_scope') ? '⚠️ broad' : '✅ focused';
3925
+
3926
+ let dep: string;
3927
+ if (codes.has('guideline_dependent_skill')) {
3928
+ dep = '❌ high';
3929
+ } else if (codes.has('pointer_only_skill')) {
3930
+ dep = '⚠️ medium';
3931
+ } else {
3932
+ dep = '✅ low';
3933
+ }
3934
+
3935
+ let totalLines = 0;
3936
+ try {
3937
+ totalLines = countChar(readText(r.file), '\n');
3938
+ } catch {
3939
+ // OSError → leave 0
3940
+ }
3941
+
3942
+ lines.push(`| \`${short}\` | ${struct} | ${valid} | ${scope} | ${dep} | ${totalLines} |`);
3943
+ }
3944
+ }
3945
+
3946
+ return lines.join('\n');
3947
+ }
3948
+
3949
+ // --- arg parsing + main ---
3950
+
3951
+ interface Args {
3952
+ paths: string[];
3953
+ all: boolean;
3954
+ changed: boolean;
3955
+ format: 'text' | 'json';
3956
+ pairs: boolean;
3957
+ duplicates: boolean;
3958
+ condensationQuality: boolean;
3959
+ strictWarnings: boolean;
3960
+ report: boolean;
3961
+ repoRoot: string;
3962
+ quiet: boolean;
3963
+ }
3964
+
3965
+ export function parse_args(argv: string[]): Args {
3966
+ const args: Args = {
3967
+ paths: [],
3968
+ all: false,
3969
+ changed: false,
3970
+ format: 'text',
3971
+ pairs: false,
3972
+ duplicates: false,
3973
+ condensationQuality: false,
3974
+ strictWarnings: false,
3975
+ report: false,
3976
+ repoRoot: '.',
3977
+ quiet: false,
3978
+ };
3979
+ for (let i = 0; i < argv.length; i += 1) {
3980
+ const a = argv[i] as string;
3981
+ if (a === '--all') {
3982
+ args.all = true;
3983
+ } else if (a === '--changed') {
3984
+ args.changed = true;
3985
+ } else if (a === '--format') {
3986
+ const v = argv[i + 1];
3987
+ i += 1;
3988
+ if (v !== 'text' && v !== 'json') {
3989
+ throw new ArgError(`argument --format: invalid choice: '${v ?? ''}' (choose from 'text', 'json')`);
3990
+ }
3991
+ args.format = v;
3992
+ } else if (a.startsWith('--format=')) {
3993
+ const v = a.slice('--format='.length);
3994
+ if (v !== 'text' && v !== 'json') {
3995
+ throw new ArgError(`argument --format: invalid choice: '${v}' (choose from 'text', 'json')`);
3996
+ }
3997
+ args.format = v;
3998
+ } else if (a === '--pairs') {
3999
+ args.pairs = true;
4000
+ } else if (a === '--duplicates') {
4001
+ args.duplicates = true;
4002
+ } else if (a === '--condensation-quality') {
4003
+ args.condensationQuality = true;
4004
+ } else if (a === '--strict-warnings') {
4005
+ args.strictWarnings = true;
4006
+ } else if (a === '--report') {
4007
+ args.report = true;
4008
+ } else if (a === '--repo-root') {
4009
+ args.repoRoot = (argv[i + 1] as string) ?? '.';
4010
+ i += 1;
4011
+ } else if (a.startsWith('--repo-root=')) {
4012
+ args.repoRoot = a.slice('--repo-root='.length);
4013
+ } else if (a === '--quiet') {
4014
+ args.quiet = true;
4015
+ } else {
4016
+ args.paths.push(a);
4017
+ }
4018
+ }
4019
+ return args;
4020
+ }
4021
+
4022
+ class ArgError extends Error {}
4023
+
4024
+ export function main(argv: string[]): number {
4025
+ let args: Args;
4026
+ try {
4027
+ args = parse_args(argv);
4028
+ } catch (e) {
4029
+ if (e instanceof ArgError) {
4030
+ process.stderr.write(`skill_linter.ts: error: ${e.message}\n`);
4031
+ return 2;
4032
+ }
4033
+ throw e;
4034
+ }
4035
+ const root = path.resolve(args.repoRoot);
4036
+
4037
+ try {
4038
+ const paths: string[] = [];
4039
+ if (args.all || args.report) {
4040
+ paths.push(...gather_all_candidate_files(root));
4041
+ }
4042
+ if (args.changed) {
4043
+ paths.push(...gather_changed_candidate_files(root));
4044
+ }
4045
+ for (const raw of args.paths) {
4046
+ const p = path.isAbsolute(raw) ? raw : path.resolve(root, raw);
4047
+ if (!exists(p)) {
4048
+ continue;
4049
+ }
4050
+ if (isDir(p)) {
4051
+ paths.push(...gather_candidate_files_under(p));
4052
+ } else {
4053
+ paths.push(p);
4054
+ }
4055
+ }
4056
+
4057
+ const sortedPaths = sortedUnique(paths);
4058
+ if (sortedPaths.length === 0) {
4059
+ if (args.report) {
4060
+ process.stdout.write(`${format_report([])}\n`);
4061
+ } else if (args.format === 'json') {
4062
+ process.stdout.write(`${format_json([])}\n`);
4063
+ }
4064
+ process.stderr.write('No matching skill/rule files found.\n');
4065
+ return 0;
4066
+ }
4067
+
4068
+ const results = sortedPaths.map((p) => lint_file(p, root));
4069
+
4070
+ if (args.pairs || args.report) {
4071
+ results.push(...check_condensation_pairs(root));
4072
+ }
4073
+ if (args.duplicates) {
4074
+ results.push(...check_duplication(root));
4075
+ }
4076
+ if (args.condensationQuality || args.report) {
4077
+ results.push(...check_condensation_quality(root));
4078
+ }
4079
+
4080
+ if (args.report) {
4081
+ process.stdout.write(`${format_report(results)}\n`);
4082
+ } else if (args.format === 'json') {
4083
+ process.stdout.write(`${format_json(results)}\n`);
4084
+ } else {
4085
+ process.stdout.write(`${format_text(results, args.quiet)}\n`);
4086
+ }
4087
+
4088
+ return compute_exit_code(results, args.strictWarnings);
4089
+ } catch (exc) {
4090
+ process.stderr.write(`Internal error: ${pyExcStr(exc)}\n`);
4091
+ return 3;
4092
+ }
4093
+ }
4094
+
4095
+ // --- low-level Python-parity helpers --------------------------------------
4096
+
4097
+ /** Count non-overlapping regex matches (mirrors `len(re.findall(...))` for a
4098
+ * pattern with a single full match per position; the `g` flag must be set). */
4099
+ function countMatches(pattern: RegExp, text: string): number {
4100
+ const re = new RegExp(pattern.source, pattern.flags.includes('g') ? pattern.flags : `${pattern.flags}g`);
4101
+ let n = 0;
4102
+ while (re.exec(text) !== null) {
4103
+ n += 1;
4104
+ if (re.lastIndex === 0) {
4105
+ re.lastIndex += 1; // guard against zero-width infinite loop
4106
+ }
4107
+ }
4108
+ return n;
4109
+ }
4110
+
4111
+ /** Fresh `.search`-style first match (resets lastIndex). */
4112
+ function freshMatch(pattern: RegExp, text: string): RegExpExecArray | null {
4113
+ const re = new RegExp(pattern.source, pattern.flags);
4114
+ return re.exec(text);
4115
+ }
4116
+
4117
+ /** Python `str.split(sep, maxsplit)`. */
4118
+ function splitN(text: string, sep: string, maxsplit: number): string[] {
4119
+ const parts: string[] = [];
4120
+ let rest = text;
4121
+ let count = 0;
4122
+ while (count < maxsplit) {
4123
+ const idx = rest.indexOf(sep);
4124
+ if (idx === -1) {
4125
+ break;
4126
+ }
4127
+ parts.push(rest.slice(0, idx));
4128
+ rest = rest.slice(idx + sep.length);
4129
+ count += 1;
4130
+ }
4131
+ parts.push(rest);
4132
+ return parts;
4133
+ }
4134
+
4135
+ /** Python `str.split()` with no args — split on runs of whitespace, drop empties. */
4136
+ function pySplitWhitespace(text: string): string[] {
4137
+ return text.split(/\s+/).filter((s) => s !== '');
4138
+ }
4139
+
4140
+ function rstripS(s: string): string {
4141
+ return s.endsWith('s') ? s.slice(0, -1) : s;
4142
+ }
4143
+
4144
+ function setIntersects(s: Set<string>, candidates: string[]): boolean {
4145
+ return candidates.some((c) => s.has(c));
4146
+ }
4147
+
4148
+ function countChar(text: string, ch: string): number {
4149
+ let n = 0;
4150
+ for (let i = 0; i < text.length; i += 1) {
4151
+ if (text[i] === ch) {
4152
+ n += 1;
4153
+ }
4154
+ }
4155
+ return n;
4156
+ }
4157
+
4158
+ /** Python `f"{overlap:.0%}"` — percent with no decimals, round-half-even. */
4159
+ function pyPercent(value: number): string {
4160
+ return `${roundHalfEven(value * 100, 0)}%`;
4161
+ }
4162
+
4163
+ function iterdir(dir: string): string[] {
4164
+ try {
4165
+ return fs.readdirSync(dir).map((name) => path.join(dir, name));
4166
+ } catch {
4167
+ return [];
4168
+ }
4169
+ }
4170
+
4171
+ function isUnder(child: string, parent: string): boolean {
4172
+ const c = path.resolve(child);
4173
+ const par = path.resolve(parent);
4174
+ const rel = path.relative(par, c);
4175
+ return rel !== '' && !rel.startsWith('..') && !path.isAbsolute(rel);
4176
+ }
4177
+
4178
+ /** Equivalent of `child.relative_to(parent).as_posix()`. */
4179
+ function relPosix(child: string, parent: string): string {
4180
+ return path.relative(path.resolve(parent), path.resolve(child)).split(path.sep).join('/');
4181
+ }
4182
+
4183
+ /** Like relPosix but preserves the native separator (mirrors `str(Path)` use). */
4184
+ function relPosixNative(child: string, parent: string): string {
4185
+ return path.relative(path.resolve(parent), path.resolve(child));
4186
+ }
4187
+
4188
+ /**
4189
+ * Sort + dedup like Python `sorted(set(Path(...)))`. Python compares pathlib
4190
+ * objects component-wise (the case-normalized parts tuple), NOT as a flat
4191
+ * string — so `laravel` sorts before `laravel-validation` because the
4192
+ * directory component `laravel` < `laravel-validation`, even though the joined
4193
+ * string `laravel-validation/...` < `laravel/...` under plain string order
4194
+ * (`-` 0x2D < `/` 0x2F). Replicate the component-wise comparison.
4195
+ */
4196
+ function sortedUnique(items: string[]): string[] {
4197
+ return [...new Set(items)].sort(comparePathComponents);
4198
+ }
4199
+
4200
+ function comparePathComponents(a: string, b: string): number {
4201
+ const pa = a.split(/[\\/]/);
4202
+ const pb = b.split(/[\\/]/);
4203
+ const n = Math.min(pa.length, pb.length);
4204
+ for (let i = 0; i < n; i += 1) {
4205
+ const ca = pa[i] as string;
4206
+ const cb = pb[i] as string;
4207
+ if (ca < cb) {
4208
+ return -1;
4209
+ }
4210
+ if (ca > cb) {
4211
+ return 1;
4212
+ }
4213
+ }
4214
+ return pa.length - pb.length;
4215
+ }
4216
+
4217
+ function stripSourcePrefix(norm: string): string | null {
4218
+ const LEGACY = '.agent-src.uncondensed/';
4219
+ if (norm.startsWith(LEGACY)) {
4220
+ return norm.slice(LEGACY.length);
4221
+ }
4222
+ if (norm.startsWith('packages/')) {
4223
+ const suffix = '/.agent-src.uncondensed/';
4224
+ const idx = norm.indexOf(suffix);
4225
+ if (idx !== -1) {
4226
+ return norm.slice(idx + suffix.length);
4227
+ }
4228
+ }
4229
+ return null;
4230
+ }
4231
+
4232
+ /** Python `str(exc)` rendering for messages. */
4233
+ function pyExcStr(exc: unknown): string {
4234
+ if (exc instanceof Error) {
4235
+ return exc.message;
4236
+ }
4237
+ return String(exc);
4238
+ }
4239
+
4240
+ /** Python repr of an unknown scalar (used in evals_json_assertion_kind). */
4241
+ function pyReprUnknown(value: unknown): string {
4242
+ if (typeof value === 'string') {
4243
+ return `'${value}'`;
4244
+ }
4245
+ if (value === null || value === undefined) {
4246
+ return 'None';
4247
+ }
4248
+ if (typeof value === 'boolean') {
4249
+ return value ? 'True' : 'False';
4250
+ }
4251
+ return String(value);
4252
+ }
4253
+
4254
+ function pyStrListRepr(values: string[]): string {
4255
+ return `[${values.map((v) => `'${v}'`).join(', ')}]`;
4256
+ }
4257
+ function pyIntListRepr(values: number[]): string {
4258
+ return `[${values.join(', ')}]`;
4259
+ }
4260
+
4261
+ /** Python `json.dumps(payload, indent=2, ensure_ascii=False)` parity. */
4262
+ function jsonIndent2(payload: unknown): string {
4263
+ return JSON.stringify(payload, null, 2);
4264
+ }
4265
+
4266
+ // CLI entry — only when executed directly, not when imported by tests.
4267
+ const isCliEntry =
4268
+ process.argv[1] !== undefined &&
4269
+ import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href;
4270
+ if (isCliEntry) {
4271
+ // Set exitCode rather than calling process.exit() so a large stdout write
4272
+ // to a pipe is fully flushed before the process terminates — process.exit()
4273
+ // can truncate async pipe writes (observed with --all --format json over
4274
+ // spawnSync). Node exits with process.exitCode once the event loop drains.
4275
+ process.exitCode = main(process.argv.slice(2));
4276
+ }