@event4u/agent-config 6.0.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1758) hide show
  1. package/.claude-plugin/marketplace.json +39 -7
  2. package/AGENTS.md +8 -7
  3. package/CHANGELOG.md +557 -422
  4. package/CONTRIBUTING.md +1 -1
  5. package/README.md +18 -16
  6. package/dist/agent-src/commands/agent-handoff.md +5 -4
  7. package/dist/agent-src/commands/agent-status.md +3 -2
  8. package/dist/agent-src/commands/agents/audit.md +4 -3
  9. package/dist/agent-src/commands/agents/init.md +4 -1
  10. package/dist/agent-src/commands/agents/optimize.md +5 -4
  11. package/dist/agent-src/commands/agents/user/accept.md +1 -0
  12. package/dist/agent-src/commands/agents/user/init.md +1 -0
  13. package/dist/agent-src/commands/agents/user/review.md +1 -0
  14. package/dist/agent-src/commands/agents/user/show.md +1 -0
  15. package/dist/agent-src/commands/agents/user/update.md +1 -0
  16. package/dist/agent-src/commands/agents/user.md +1 -0
  17. package/dist/agent-src/commands/agents.md +1 -0
  18. package/dist/agent-src/commands/analytics/prune.md +3 -2
  19. package/dist/agent-src/commands/analytics/show.md +3 -2
  20. package/dist/agent-src/commands/analytics.md +3 -2
  21. package/dist/agent-src/commands/analyze/decision.md +108 -0
  22. package/dist/agent-src/commands/analyze/incident.md +120 -0
  23. package/dist/agent-src/commands/analyze/near-miss.md +113 -0
  24. package/dist/agent-src/commands/analyze/postmortem.md +130 -0
  25. package/dist/agent-src/commands/analyze/premortem.md +104 -0
  26. package/dist/agent-src/commands/analyze-reference-repo.md +1 -0
  27. package/dist/agent-src/commands/analyze.md +124 -0
  28. package/dist/agent-src/commands/brand/identity.md +27 -0
  29. package/dist/agent-src/commands/brand/review.md +27 -0
  30. package/dist/agent-src/commands/brand/strategy.md +27 -0
  31. package/dist/agent-src/commands/brand/tokens.md +28 -0
  32. package/dist/agent-src/commands/brand/voice.md +27 -0
  33. package/dist/agent-src/commands/brand.md +58 -0
  34. package/dist/agent-src/commands/bug-fix.md +1 -0
  35. package/dist/agent-src/commands/bug-investigate.md +1 -0
  36. package/dist/agent-src/commands/challenge-me/vision.md +3 -2
  37. package/dist/agent-src/commands/challenge-me/with-docs.md +3 -2
  38. package/dist/agent-src/commands/challenge-me.md +3 -2
  39. package/dist/agent-src/commands/chat-history/import.md +9 -9
  40. package/dist/agent-src/commands/chat-history.md +32 -30
  41. package/dist/agent-src/commands/check-current-md.md +4 -3
  42. package/dist/agent-src/commands/commit/in-chunks.md +1 -0
  43. package/dist/agent-src/commands/commit.md +1 -0
  44. package/dist/agent-src/commands/condense.md +3 -2
  45. package/dist/agent-src/commands/context/create.md +1 -0
  46. package/dist/agent-src/commands/context/refactor.md +1 -0
  47. package/dist/agent-src/commands/context.md +1 -0
  48. package/dist/agent-src/commands/cost-report.md +5 -4
  49. package/dist/agent-src/commands/council/analysis.md +3 -2
  50. package/dist/agent-src/commands/council/debate.md +7 -6
  51. package/dist/agent-src/commands/council/default.md +48 -20
  52. package/dist/agent-src/commands/council/design.md +3 -2
  53. package/dist/agent-src/commands/council/optimize.md +3 -2
  54. package/dist/agent-src/commands/council/pr.md +3 -2
  55. package/dist/agent-src/commands/council.md +4 -3
  56. package/dist/agent-src/commands/e2e-heal.md +1 -0
  57. package/dist/agent-src/commands/e2e-plan.md +1 -0
  58. package/dist/agent-src/commands/estimate-ticket.md +1 -0
  59. package/dist/agent-src/commands/feature/dev.md +1 -0
  60. package/dist/agent-src/commands/feature/explore.md +1 -0
  61. package/dist/agent-src/commands/feature/plan.md +6 -6
  62. package/dist/agent-src/commands/feature/refactor.md +1 -0
  63. package/dist/agent-src/commands/feature/roadmap.md +1 -0
  64. package/dist/agent-src/commands/feature.md +1 -0
  65. package/dist/agent-src/commands/fix/ci.md +1 -0
  66. package/dist/agent-src/commands/fix/portability.md +4 -3
  67. package/dist/agent-src/commands/fix/pr-comments.md +147 -15
  68. package/dist/agent-src/commands/fix/refs.md +4 -3
  69. package/dist/agent-src/commands/fix/seeder.md +1 -0
  70. package/dist/agent-src/commands/fix.md +8 -8
  71. package/dist/agent-src/commands/ghostwriter/delete.md +1 -0
  72. package/dist/agent-src/commands/ghostwriter/fetch.md +1 -0
  73. package/dist/agent-src/commands/ghostwriter/list.md +1 -0
  74. package/dist/agent-src/commands/ghostwriter/show.md +1 -0
  75. package/dist/agent-src/commands/ghostwriter/write.md +1 -0
  76. package/dist/agent-src/commands/ghostwriter.md +1 -0
  77. package/dist/agent-src/commands/grill-me.md +3 -2
  78. package/dist/agent-src/commands/image/analyse.md +1 -0
  79. package/dist/agent-src/commands/image/create.md +1 -0
  80. package/dist/agent-src/commands/image/verify.md +1 -0
  81. package/dist/agent-src/commands/image.md +1 -0
  82. package/dist/agent-src/commands/implement-ticket.md +37 -6
  83. package/dist/agent-src/commands/jira-ticket.md +1 -0
  84. package/dist/agent-src/commands/judge/on-diff.md +1 -0
  85. package/dist/agent-src/commands/judge/solo.md +1 -0
  86. package/dist/agent-src/commands/judge/steps.md +1 -0
  87. package/dist/agent-src/commands/judge.md +1 -0
  88. package/dist/agent-src/commands/knowledge/cross-repo.md +2 -1
  89. package/dist/agent-src/commands/knowledge/forget.md +1 -0
  90. package/dist/agent-src/commands/knowledge/ingest.md +1 -0
  91. package/dist/agent-src/commands/knowledge/list.md +1 -0
  92. package/dist/agent-src/commands/knowledge.md +1 -0
  93. package/dist/agent-src/commands/memory/add.md +9 -7
  94. package/dist/agent-src/commands/memory/learn-low-impact.md +3 -2
  95. package/dist/agent-src/commands/memory/load.md +7 -7
  96. package/dist/agent-src/commands/memory/mine-session.md +39 -12
  97. package/dist/agent-src/commands/memory/promote.md +3 -2
  98. package/dist/agent-src/commands/memory/propose.md +7 -6
  99. package/dist/agent-src/commands/memory.md +3 -2
  100. package/dist/agent-src/commands/mission/upgrade.md +182 -0
  101. package/dist/agent-src/commands/mode.md +1 -0
  102. package/dist/agent-src/commands/module/create.md +1 -0
  103. package/dist/agent-src/commands/module/explore.md +1 -0
  104. package/dist/agent-src/commands/module.md +1 -0
  105. package/dist/agent-src/commands/optimize/agents-dir.md +1 -0
  106. package/dist/agent-src/commands/optimize/augmentignore.md +1 -0
  107. package/dist/agent-src/commands/optimize/rtk.md +1 -0
  108. package/dist/agent-src/commands/optimize/skills.md +3 -2
  109. package/dist/agent-src/commands/optimize-prompt.md +1 -0
  110. package/dist/agent-src/commands/optimize.md +1 -0
  111. package/dist/agent-src/commands/orchestrate.md +2 -1
  112. package/dist/agent-src/commands/override/create.md +1 -0
  113. package/dist/agent-src/commands/override/manage.md +1 -0
  114. package/dist/agent-src/commands/override.md +1 -0
  115. package/dist/agent-src/commands/package-reset.md +1 -0
  116. package/dist/agent-src/commands/package-test.md +1 -0
  117. package/dist/agent-src/commands/post-as/ghostwriter.md +1 -0
  118. package/dist/agent-src/commands/post-as/me.md +1 -0
  119. package/dist/agent-src/commands/post-as.md +1 -0
  120. package/dist/agent-src/commands/pr/create/description-only.md +1 -0
  121. package/dist/agent-src/commands/pr/create.md +31 -4
  122. package/dist/agent-src/commands/prediction-pool.md +1 -0
  123. package/dist/agent-src/commands/prepare-for-review.md +1 -0
  124. package/dist/agent-src/commands/profile/activate.md +1 -0
  125. package/dist/agent-src/commands/profile/deactivate.md +1 -0
  126. package/dist/agent-src/commands/profile/show.md +1 -0
  127. package/dist/agent-src/commands/profile.md +1 -0
  128. package/dist/agent-src/commands/project-analyze.md +1 -0
  129. package/dist/agent-src/commands/project-health.md +1 -0
  130. package/dist/agent-src/commands/quality-fix.md +1 -0
  131. package/dist/agent-src/commands/refine-ticket.md +1 -0
  132. package/dist/agent-src/commands/research/deep.md +1 -0
  133. package/dist/agent-src/commands/research/report.md +1 -0
  134. package/dist/agent-src/commands/research.md +1 -0
  135. package/dist/agent-src/commands/review-changes.md +9 -0
  136. package/dist/agent-src/commands/review-routing.md +1 -0
  137. package/dist/agent-src/commands/roadmap/ai-council.md +1 -0
  138. package/dist/agent-src/commands/roadmap/create.md +1 -0
  139. package/dist/agent-src/commands/roadmap/materialize.md +73 -0
  140. package/dist/agent-src/commands/roadmap/process-full.md +1 -0
  141. package/dist/agent-src/commands/roadmap/process-phase.md +1 -0
  142. package/dist/agent-src/commands/roadmap/process-step.md +1 -0
  143. package/dist/agent-src/commands/roadmap.md +1 -0
  144. package/dist/agent-src/commands/rule-compliance-audit.md +1 -0
  145. package/dist/agent-src/commands/security-audit-config.md +84 -0
  146. package/dist/agent-src/commands/set-cost-profile.md +1 -0
  147. package/dist/agent-src/commands/skill/preview.md +2 -1
  148. package/dist/agent-src/commands/skill.md +1 -0
  149. package/dist/agent-src/commands/skills/discover.md +2 -1
  150. package/dist/agent-src/commands/skills.md +1 -0
  151. package/dist/agent-src/commands/sync-agent-settings.md +1 -0
  152. package/dist/agent-src/commands/sync-gitignore/fix.md +1 -0
  153. package/dist/agent-src/commands/sync-gitignore.md +1 -0
  154. package/dist/agent-src/commands/tests/create.md +1 -0
  155. package/dist/agent-src/commands/tests/execute.md +1 -0
  156. package/dist/agent-src/commands/tests.md +1 -0
  157. package/dist/agent-src/commands/threat-model.md +5 -4
  158. package/dist/agent-src/commands/update-form-request-messages.md +1 -0
  159. package/dist/agent-src/commands/upstream-contribute.md +4 -3
  160. package/dist/agent-src/commands/video/from-script.md +3 -2
  161. package/dist/agent-src/commands/video/from-song.md +4 -3
  162. package/dist/agent-src/commands/video/scene.md +2 -1
  163. package/dist/agent-src/commands/video/stitch.md +1 -0
  164. package/dist/agent-src/commands/video/storyboard.md +2 -1
  165. package/dist/agent-src/commands/video.md +4 -3
  166. package/dist/agent-src/commands/work.md +1 -0
  167. package/dist/agent-src/contexts/augment-infrastructure.md +1 -1
  168. package/dist/agent-src/contexts/communication/rules-auto/skill-quality-mechanics.md +1 -1
  169. package/dist/agent-src/contexts/communication/rules-auto/slash-command-routing-policy-mechanics.md +2 -2
  170. package/dist/agent-src/contexts/communication/rules-auto/source-of-truth-mechanics.md +3 -3
  171. package/dist/agent-src/contexts/communication/rules-auto/think-before-action-mechanics.md +6 -6
  172. package/dist/agent-src/contexts/communication/rules-auto/user-interaction-mechanics.md +1 -1
  173. package/dist/agent-src/contexts/contracts/consumer-agents-md-guide.md +2 -2
  174. package/dist/agent-src/contexts/execution/evidence-discipline.md +153 -0
  175. package/dist/agent-src/contexts/execution/project-intelligence.md +264 -0
  176. package/dist/agent-src/contexts/execution/rdp-gate.md +75 -0
  177. package/dist/agent-src/contexts/execution/roadmap-process-loop.md +2 -1
  178. package/dist/agent-src/contexts/subagent-configuration.md +1 -0
  179. package/dist/agent-src/personas/advisors/contrarian.md +1 -1
  180. package/dist/agent-src/personas/advisors/executor.md +1 -1
  181. package/dist/agent-src/personas/advisors/expansionist.md +1 -1
  182. package/dist/agent-src/personas/advisors/first-principles.md +1 -1
  183. package/dist/agent-src/personas/advisors/outsider.md +1 -1
  184. package/dist/agent-src/personas/ai-video-technical-director.md +1 -1
  185. package/dist/agent-src/personas/brand-strategist.md +74 -0
  186. package/dist/agent-src/personas/design-director.md +74 -0
  187. package/dist/agent-src/rules/autonomous-execution.md +12 -0
  188. package/dist/agent-src/rules/brand-consistency.md +77 -0
  189. package/dist/agent-src/rules/brand-source-of-truth.md +57 -0
  190. package/dist/agent-src/rules/direct-answers.md +2 -0
  191. package/dist/agent-src/rules/domain-safety-disclaimer.md +2 -0
  192. package/dist/agent-src/rules/external-reference-deep-dive.md +1 -1
  193. package/dist/agent-src/rules/git-history-discipline.md +48 -1
  194. package/dist/agent-src/rules/icon-consistency.md +53 -0
  195. package/dist/agent-src/rules/image-likeness-and-rights.md +67 -0
  196. package/dist/agent-src/rules/improve-before-implement.md +12 -0
  197. package/dist/agent-src/rules/lethal-trifecta-guard.md +80 -0
  198. package/dist/agent-src/rules/no-pr-progress-comments.md +3 -4
  199. package/dist/agent-src/rules/notes-first-reasoning.md +71 -0
  200. package/dist/agent-src/rules/persona-governance.md +2 -2
  201. package/dist/agent-src/rules/provider-lifecycle-discipline.md +3 -1
  202. package/dist/agent-src/rules/roadmap-progress-sync.md +58 -31
  203. package/dist/agent-src/rules/security-sensitive-stop.md +22 -3
  204. package/dist/agent-src/rules/size-enforcement.md +1 -1
  205. package/dist/agent-src/rules/source-confidentiality.md +97 -0
  206. package/dist/agent-src/rules/source-discovery-gate.md +98 -0
  207. package/dist/agent-src/rules/think-before-action.md +10 -1
  208. package/dist/agent-src/rules/ui-audit-gate.md +2 -0
  209. package/dist/agent-src/rules/untrusted-input-defense.md +76 -0
  210. package/dist/agent-src/rules/user-interaction.md +1 -1
  211. package/dist/agent-src/scripts/archive_completed_roadmaps.ts +392 -0
  212. package/dist/agent-src/scripts/update_roadmap_progress.ts +824 -0
  213. package/dist/agent-src/skills/adr-create/SKILL.md +5 -5
  214. package/dist/agent-src/skills/adversarial-review/SKILL.md +14 -0
  215. package/dist/agent-src/skills/agent-security-review/SKILL.md +113 -0
  216. package/dist/agent-src/skills/agent-security-review/evals/triggers.json +52 -0
  217. package/dist/agent-src/skills/agents-md-thin-root/SKILL.md +1 -1
  218. package/dist/agent-src/skills/ai-council/SKILL.md +4 -4
  219. package/dist/agent-src/skills/analysis-autonomous-mode/SKILL.md +9 -13
  220. package/dist/agent-src/skills/async-python-patterns/SKILL.md +1 -1
  221. package/dist/agent-src/skills/blade-ui/SKILL.md +12 -5
  222. package/dist/agent-src/skills/blameless-post-mortem/SKILL.md +199 -0
  223. package/dist/agent-src/skills/blast-radius-analyzer/SKILL.md +12 -11
  224. package/dist/agent-src/skills/brand/ATTRIBUTION.md +38 -0
  225. package/dist/agent-src/skills/brand/SKILL.md +115 -0
  226. package/dist/agent-src/skills/brand/data/archetypes.csv +13 -0
  227. package/dist/agent-src/skills/brand/data/color-psychology.csv +14 -0
  228. package/dist/agent-src/skills/brand/data/logo-style-fit.csv +13 -0
  229. package/dist/agent-src/skills/brand/data/manifest.json +226 -0
  230. package/dist/agent-src/skills/brand/data/messaging-frameworks.csv +13 -0
  231. package/dist/agent-src/skills/brand/data/naming-patterns.csv +13 -0
  232. package/dist/agent-src/skills/brand/data/typography-principles.csv +13 -0
  233. package/dist/agent-src/skills/brand/data/voice-tone.csv +13 -0
  234. package/dist/agent-src/skills/brand/evals/triggers.json +17 -0
  235. package/dist/agent-src/skills/brand-asset-generation/SKILL.md +89 -0
  236. package/dist/agent-src/skills/brand-asset-generation/evals/triggers.json +17 -0
  237. package/dist/agent-src/skills/brand-audit/SKILL.md +67 -0
  238. package/dist/agent-src/skills/brand-audit/evals/triggers.json +17 -0
  239. package/dist/agent-src/skills/brand-identity/SKILL.md +101 -0
  240. package/dist/agent-src/skills/brand-identity/evals/triggers.json +17 -0
  241. package/dist/agent-src/skills/brand-strategy/SKILL.md +83 -0
  242. package/dist/agent-src/skills/brand-strategy/evals/triggers.json +17 -0
  243. package/dist/agent-src/skills/brand-to-tokens/SKILL.md +102 -0
  244. package/dist/agent-src/skills/brand-to-tokens/evals/triggers.json +17 -0
  245. package/dist/agent-src/skills/brand-to-tokens/templates/marp-brand-deck.md.example +46 -0
  246. package/dist/agent-src/skills/brand-to-tokens/templates/reveal-brand-deck.yaml +32 -0
  247. package/dist/agent-src/skills/canvas-design/evals/triggers.json +1 -0
  248. package/dist/agent-src/skills/check-refs/SKILL.md +5 -5
  249. package/dist/agent-src/skills/code-review/SKILL.md +6 -15
  250. package/dist/agent-src/skills/command-routing/SKILL.md +1 -1
  251. package/dist/agent-src/skills/command-writing/SKILL.md +2 -2
  252. package/dist/agent-src/skills/complexity-first-planning/SKILL.md +96 -0
  253. package/dist/agent-src/skills/complexity-first-planning/evals/triggers.json +17 -0
  254. package/dist/agent-src/skills/context-authoring/SKILL.md +2 -2
  255. package/dist/agent-src/skills/context-document/SKILL.md +35 -2
  256. package/dist/agent-src/skills/copilot-config/SKILL.md +3 -4
  257. package/dist/agent-src/skills/corpus-grounding/evals/triggers.json +1 -0
  258. package/dist/agent-src/skills/corpus-grounding/scripts/bm25_search.ts +482 -0
  259. package/dist/agent-src/skills/corpus-grounding/scripts/decision_engine.ts +803 -0
  260. package/dist/agent-src/skills/corpus-grounding/scripts/ground.ts +541 -0
  261. package/dist/agent-src/skills/corpus-grounding/scripts/schema_validator.ts +309 -0
  262. package/dist/agent-src/skills/database/SKILL.md +26 -4
  263. package/dist/agent-src/skills/decision-record/SKILL.md +1 -1
  264. package/dist/agent-src/skills/decision-record/evals/triggers.json +17 -0
  265. package/dist/agent-src/skills/decision-review/SKILL.md +179 -0
  266. package/dist/agent-src/skills/defense-in-depth/SKILL.md +1 -1
  267. package/dist/agent-src/skills/description-assist/SKILL.md +1 -1
  268. package/dist/agent-src/skills/design-intelligence/SKILL.md +1 -1
  269. package/dist/agent-src/skills/design-intelligence/data/manifest.json +23 -6
  270. package/dist/agent-src/skills/design-intelligence/evals/triggers.json +1 -0
  271. package/dist/agent-src/skills/design-tokens/evals/triggers.json +1 -0
  272. package/dist/agent-src/skills/design-tokens/scripts/tokens.ts +888 -0
  273. package/dist/agent-src/skills/developer-like-execution/SKILL.md +5 -4
  274. package/dist/agent-src/skills/doc-coauthoring/evals/triggers.json +1 -0
  275. package/dist/agent-src/skills/eloquent/evals/triggers.json +1 -0
  276. package/dist/agent-src/skills/emit-tickets/SKILL.md +198 -0
  277. package/dist/agent-src/skills/error-handling-patterns/SKILL.md +1 -1
  278. package/dist/agent-src/skills/estimate-ticket/evals/triggers.json +1 -0
  279. package/dist/agent-src/skills/feature-planning/SKILL.md +2 -2
  280. package/dist/agent-src/skills/git-workflow/SKILL.md +33 -0
  281. package/dist/agent-src/skills/guideline-writing/SKILL.md +2 -2
  282. package/dist/agent-src/skills/iconography/SKILL.md +88 -0
  283. package/dist/agent-src/skills/iconography/evals/triggers.json +17 -0
  284. package/dist/agent-src/skills/image-analyser/evals/triggers.json +1 -0
  285. package/dist/agent-src/skills/image-creator/evals/triggers.json +1 -0
  286. package/dist/agent-src/skills/image-editing/SKILL.md +100 -0
  287. package/dist/agent-src/skills/image-editing/evals/triggers.json +17 -0
  288. package/dist/agent-src/skills/image-generation/SKILL.md +95 -0
  289. package/dist/agent-src/skills/image-generation/evals/triggers.json +17 -0
  290. package/dist/agent-src/skills/image-provider-routing/SKILL.md +96 -0
  291. package/dist/agent-src/skills/image-provider-routing/evals/triggers.json +17 -0
  292. package/dist/agent-src/skills/launch-readiness/SKILL.md +21 -0
  293. package/dist/agent-src/skills/learning-to-rule-or-skill/SKILL.md +12 -8
  294. package/dist/agent-src/skills/lint-skills/SKILL.md +5 -5
  295. package/dist/agent-src/skills/logo-generation/SKILL.md +98 -0
  296. package/dist/agent-src/skills/logo-generation/evals/triggers.json +17 -0
  297. package/dist/agent-src/skills/markitdown/SKILL.md +1 -1
  298. package/dist/agent-src/skills/mcp-builder/SKILL.md +1 -1
  299. package/dist/agent-src/skills/md-language-check/SKILL.md +1 -1
  300. package/dist/agent-src/skills/memory-consolidation/SKILL.md +63 -17
  301. package/dist/agent-src/skills/motion-choreographer/SKILL.md +1 -1
  302. package/dist/agent-src/skills/php-coder/evals/triggers.json +1 -0
  303. package/dist/agent-src/skills/prediction-pool-optimizer/evals/triggers.json +1 -0
  304. package/dist/agent-src/skills/premortem/SKILL.md +137 -0
  305. package/dist/agent-src/skills/prompt-engineering-image/SKILL.md +115 -0
  306. package/dist/agent-src/skills/prompt-engineering-image/evals/triggers.json +17 -0
  307. package/dist/agent-src/skills/prompt-engineering-patterns/SKILL.md +1 -1
  308. package/dist/agent-src/skills/prompt-validator/evals/triggers.json +1 -0
  309. package/dist/agent-src/skills/react-shadcn-ui/SKILL.md +12 -5
  310. package/dist/agent-src/skills/react-shadcn-ui/scripts/shadcn_add.ts +388 -0
  311. package/dist/agent-src/skills/readme-writing-package/SKILL.md +1 -1
  312. package/dist/agent-src/skills/reasoning-orchestrator/SKILL.md +119 -0
  313. package/dist/agent-src/skills/reasoning-orchestrator/evals/triggers.json +17 -0
  314. package/dist/agent-src/skills/receiving-code-review/SKILL.md +6 -6
  315. package/dist/agent-src/skills/refine-prompt/SKILL.md +1 -1
  316. package/dist/agent-src/skills/refine-ticket/SKILL.md +1 -1
  317. package/dist/agent-src/skills/refine-ticket/evals/triggers.json +1 -0
  318. package/dist/agent-src/skills/repomix-packer/SKILL.md +1 -1
  319. package/dist/agent-src/skills/roadmap-management/SKILL.md +16 -3
  320. package/dist/agent-src/skills/roadmap-writing/SKILL.md +76 -0
  321. package/dist/agent-src/skills/root-cause-frameworks/SKILL.md +146 -0
  322. package/dist/agent-src/skills/rule-refactor/SKILL.md +9 -9
  323. package/dist/agent-src/skills/rule-writing/SKILL.md +7 -7
  324. package/dist/agent-src/skills/script-writing/SKILL.md +2 -2
  325. package/dist/agent-src/skills/secrets-management/SKILL.md +1 -1
  326. package/dist/agent-src/skills/security-audit/SKILL.md +5 -0
  327. package/dist/agent-src/skills/skill-improvement-pipeline/SKILL.md +19 -3
  328. package/dist/agent-src/skills/skill-management/SKILL.md +3 -3
  329. package/dist/agent-src/skills/skill-reviewer/SKILL.md +1 -1
  330. package/dist/agent-src/skills/skill-writing/SKILL.md +5 -5
  331. package/dist/agent-src/skills/skill-writing/evals/triggers.json +1 -0
  332. package/dist/agent-src/skills/source-discovery/SKILL.md +182 -0
  333. package/dist/agent-src/skills/standards-from-config/SKILL.md +93 -0
  334. package/dist/agent-src/skills/subagent-orchestration/SKILL.md +10 -3
  335. package/dist/agent-src/skills/systematic-debugging/SKILL.md +7 -0
  336. package/dist/agent-src/skills/tailwind-engineer/scripts/tailwind_config_gen.ts +561 -0
  337. package/dist/agent-src/skills/testing-anti-patterns/SKILL.md +1 -1
  338. package/dist/agent-src/skills/testing-anti-patterns/process-anti-patterns.md +1 -1
  339. package/dist/agent-src/skills/threat-modeling/SKILL.md +1 -0
  340. package/dist/agent-src/skills/token-optimizer/SKILL.md +1 -1
  341. package/dist/agent-src/skills/typography-system/SKILL.md +138 -0
  342. package/dist/agent-src/skills/typography-system/evals/triggers.json +17 -0
  343. package/dist/agent-src/skills/upstream-contribute/SKILL.md +3 -3
  344. package/dist/agent-src/skills/verify-repair-loop/SKILL.md +209 -0
  345. package/dist/agent-src/skills/verify-repair-loop/evals/output-schema.yml +20 -0
  346. package/dist/agent-src/skills/verify-repair-loop/evals/triggers.json +17 -0
  347. package/dist/agent-src/templates/agent-settings.md +7 -0
  348. package/dist/agent-src/templates/agents/.gitattributes.fragment +0 -1
  349. package/dist/agent-src/templates/agents/agent-project-settings.example.yml +4 -4
  350. package/dist/agent-src/templates/contexts/knowledge-card.md +69 -0
  351. package/dist/agent-src/templates/contexts/lesson-card.md +73 -0
  352. package/dist/agent-src/templates/roadmaps.md +29 -1
  353. package/dist/agent-src/templates/scripts/README.md +6 -6
  354. package/dist/agent-src/templates/scripts/check_memory.ts +640 -0
  355. package/dist/agent-src/templates/scripts/check_memory_proposal.ts +351 -0
  356. package/dist/agent-src/templates/scripts/implement_ticket/__main__.ts +27 -0
  357. package/dist/agent-src/templates/scripts/memory_hash.ts +333 -0
  358. package/dist/agent-src/templates/scripts/memory_lookup.ts +1067 -0
  359. package/dist/agent-src/templates/scripts/memory_report.ts +846 -0
  360. package/dist/agent-src/templates/scripts/memory_signal.ts +422 -0
  361. package/dist/agent-src/templates/scripts/memory_status.ts +191 -0
  362. package/dist/agent-src/templates/scripts/pr_review_routing.ts +523 -0
  363. package/dist/agent-src/templates/scripts/pr_risk_review.ts +0 -0
  364. package/dist/agent-src/templates/scripts/telemetry/aggregator.ts +0 -0
  365. package/dist/agent-src/templates/scripts/telemetry/boundary.ts +164 -0
  366. package/dist/agent-src/templates/scripts/telemetry/engagement.ts +479 -0
  367. package/dist/agent-src/templates/scripts/telemetry/report_renderer.ts +394 -0
  368. package/dist/agent-src/templates/scripts/telemetry/settings.ts +210 -0
  369. package/dist/agent-src/templates/scripts/telemetry_record.ts +255 -0
  370. package/dist/agent-src/templates/scripts/telemetry_report.ts +189 -0
  371. package/dist/agent-src/templates/scripts/telemetry_status.ts +312 -0
  372. package/dist/agent-src/templates/scripts/tier_usage_report.ts +597 -0
  373. package/dist/agent-src/templates/scripts/work_engine/__main__.ts +14 -0
  374. package/dist/agent-src/templates/scripts/work_engine/_lib/agent_settings.ts +1118 -0
  375. package/dist/agent-src/templates/scripts/work_engine/_lib/user_global_paths.ts +329 -0
  376. package/dist/agent-src/templates/scripts/work_engine/cli.ts +206 -0
  377. package/dist/agent-src/templates/scripts/work_engine/cli_args.ts +249 -0
  378. package/dist/agent-src/templates/scripts/work_engine/delivery_state.ts +225 -0
  379. package/dist/agent-src/templates/scripts/work_engine/directives/backend/analyze.ts +125 -0
  380. package/dist/agent-src/templates/scripts/work_engine/directives/backend/implement.ts +189 -0
  381. package/dist/agent-src/templates/scripts/work_engine/directives/backend/index.ts +94 -0
  382. package/dist/agent-src/templates/scripts/work_engine/directives/backend/memory.ts +193 -0
  383. package/dist/agent-src/templates/scripts/work_engine/directives/backend/plan.ts +267 -0
  384. package/dist/agent-src/templates/scripts/work_engine/directives/backend/refine.ts +518 -0
  385. package/dist/agent-src/templates/scripts/work_engine/directives/backend/report.ts +379 -0
  386. package/dist/agent-src/templates/scripts/work_engine/directives/backend/test.ts +268 -0
  387. package/dist/agent-src/templates/scripts/work_engine/directives/backend/verify.ts +258 -0
  388. package/dist/agent-src/templates/scripts/work_engine/directives/index.ts +32 -0
  389. package/dist/agent-src/templates/scripts/work_engine/directives/mixed/contract.ts +243 -0
  390. package/dist/agent-src/templates/scripts/work_engine/directives/mixed/index.ts +108 -0
  391. package/dist/agent-src/templates/scripts/work_engine/directives/mixed/stitch.ts +259 -0
  392. package/dist/agent-src/templates/scripts/work_engine/directives/mixed/ui.ts +216 -0
  393. package/dist/agent-src/templates/scripts/work_engine/directives/ui/_passthrough.ts +40 -0
  394. package/dist/agent-src/templates/scripts/work_engine/directives/ui/app_spec.ts +241 -0
  395. package/dist/agent-src/templates/scripts/work_engine/directives/ui/apply.ts +216 -0
  396. package/dist/agent-src/templates/scripts/work_engine/directives/ui/audit.ts +506 -0
  397. package/dist/agent-src/templates/scripts/work_engine/directives/ui/design.ts +325 -0
  398. package/dist/agent-src/templates/scripts/work_engine/directives/ui/index.ts +102 -0
  399. package/dist/agent-src/templates/scripts/work_engine/directives/ui/polish.ts +462 -0
  400. package/dist/agent-src/templates/scripts/work_engine/directives/ui/review.ts +474 -0
  401. package/dist/agent-src/templates/scripts/work_engine/directives/ui/scaffold.ts +352 -0
  402. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/_skipped.ts +33 -0
  403. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/apply.ts +213 -0
  404. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/index.ts +111 -0
  405. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/refine.ts +126 -0
  406. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/report.ts +112 -0
  407. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/test.ts +164 -0
  408. package/dist/agent-src/templates/scripts/work_engine/dispatcher.ts +515 -0
  409. package/dist/agent-src/templates/scripts/work_engine/emitters.ts +119 -0
  410. package/dist/agent-src/templates/scripts/work_engine/errors.ts +24 -0
  411. package/dist/agent-src/templates/scripts/work_engine/hook_bootstrap.ts +104 -0
  412. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/_chat_history_base.ts +176 -0
  413. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_append.ts +41 -0
  414. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_halt_append.ts +89 -0
  415. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/decision_gate.ts +193 -0
  416. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/decision_trace.ts +304 -0
  417. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/directive_set_guard.ts +110 -0
  418. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/halt_surface_audit.ts +118 -0
  419. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/index.ts +17 -0
  420. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/memory_visibility.ts +161 -0
  421. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/state_shape_validation.ts +45 -0
  422. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/trace.ts +134 -0
  423. package/dist/agent-src/templates/scripts/work_engine/hooks/context.ts +94 -0
  424. package/dist/agent-src/templates/scripts/work_engine/hooks/events.ts +58 -0
  425. package/dist/agent-src/templates/scripts/work_engine/hooks/exceptions.ts +85 -0
  426. package/dist/agent-src/templates/scripts/work_engine/hooks/index.ts +27 -0
  427. package/dist/agent-src/templates/scripts/work_engine/hooks/registry.ts +66 -0
  428. package/dist/agent-src/templates/scripts/work_engine/hooks/runner.ts +90 -0
  429. package/dist/agent-src/templates/scripts/work_engine/hooks/settings.ts +260 -0
  430. package/dist/agent-src/templates/scripts/work_engine/input_builders.ts +260 -0
  431. package/dist/agent-src/templates/scripts/work_engine/intent/classify.ts +466 -0
  432. package/dist/agent-src/templates/scripts/work_engine/migration/v0_to_v1.ts +531 -0
  433. package/dist/agent-src/templates/scripts/work_engine/orchestration.ts +366 -0
  434. package/dist/agent-src/templates/scripts/work_engine/persona_policy.ts +97 -0
  435. package/dist/agent-src/templates/scripts/work_engine/resolvers/diff.ts +135 -0
  436. package/dist/agent-src/templates/scripts/work_engine/resolvers/file.ts +175 -0
  437. package/dist/agent-src/templates/scripts/work_engine/resolvers/prompt.ts +115 -0
  438. package/dist/agent-src/templates/scripts/work_engine/scoring/confidence.ts +415 -0
  439. package/dist/agent-src/templates/scripts/work_engine/scoring/decision_engine.ts +466 -0
  440. package/dist/agent-src/templates/scripts/work_engine/scoring/decision_trace.ts +298 -0
  441. package/dist/agent-src/templates/scripts/work_engine/scoring/memory_visibility.ts +444 -0
  442. package/dist/agent-src/templates/scripts/work_engine/stack/detect.ts +252 -0
  443. package/dist/agent-src/templates/scripts/work_engine/stack/runner.ts +745 -0
  444. package/dist/agent-src/templates/scripts/work_engine/state.ts +1151 -0
  445. package/dist/agent-src/templates/scripts/work_engine/state_io.ts +413 -0
  446. package/dist/agent-src/templates/tickets.md +120 -0
  447. package/dist/cli/agent-config.js +31 -300
  448. package/dist/cli/agent-config.js.map +1 -1
  449. package/dist/cli/commands/commands.js +11 -6
  450. package/dist/cli/commands/commands.js.map +1 -1
  451. package/dist/cli/commands/doctorShell.js +4 -22
  452. package/dist/cli/commands/doctorShell.js.map +1 -1
  453. package/dist/cli/commands/packs.js +1 -1
  454. package/dist/cli/commands/packs.js.map +1 -1
  455. package/dist/cli/commands/recordTriggerEval.js +179 -0
  456. package/dist/cli/commands/recordTriggerEval.js.map +1 -0
  457. package/dist/cli/commands/recordTriggerEval.test.js +113 -0
  458. package/dist/cli/commands/recordTriggerEval.test.js.map +1 -0
  459. package/dist/cli/commands/workspaces.js +1 -1
  460. package/dist/cli/commands/workspaces.js.map +1 -1
  461. package/dist/cli/discovery/loadManifest.js.map +1 -1
  462. package/dist/cli/main.js +330 -0
  463. package/dist/cli/main.js.map +1 -0
  464. package/dist/cli/python/knowledge_ingest.js +1048 -0
  465. package/dist/cli/python/knowledge_ingest.js.map +1 -0
  466. package/dist/cli/python/workspace_analytics.js +1085 -0
  467. package/dist/cli/python/workspace_analytics.js.map +1 -0
  468. package/dist/cli/python/workspace_crypto.js +544 -0
  469. package/dist/cli/python/workspace_crypto.js.map +1 -0
  470. package/dist/cli/python/workspace_documents.js +1216 -0
  471. package/dist/cli/python/workspace_documents.js.map +1 -0
  472. package/dist/cli/python/workspace_drive.js +574 -0
  473. package/dist/cli/python/workspace_drive.js.map +1 -0
  474. package/dist/cli/python/workspace_drive_health.js +628 -0
  475. package/dist/cli/python/workspace_drive_health.js.map +1 -0
  476. package/dist/cli/python/workspace_explain.js +765 -0
  477. package/dist/cli/python/workspace_explain.js.map +1 -0
  478. package/dist/cli/python/workspace_hosts.js +349 -0
  479. package/dist/cli/python/workspace_hosts.js.map +1 -0
  480. package/dist/cli/python/workspace_inbox.js +692 -0
  481. package/dist/cli/python/workspace_inbox.js.map +1 -0
  482. package/dist/cli/python/workspace_render.js +816 -0
  483. package/dist/cli/python/workspace_render.js.map +1 -0
  484. package/dist/cli/python/workspace_roles.js +487 -0
  485. package/dist/cli/python/workspace_roles.js.map +1 -0
  486. package/dist/cli/python/workspace_secrets.js +180 -0
  487. package/dist/cli/python/workspace_secrets.js.map +1 -0
  488. package/dist/cli/python/workspace_sessions.js +1079 -0
  489. package/dist/cli/python/workspace_sessions.js.map +1 -0
  490. package/dist/cli/python/workspace_skills.js +417 -0
  491. package/dist/cli/python/workspace_skills.js.map +1 -0
  492. package/dist/cli/registry.js +2 -0
  493. package/dist/cli/registry.js.map +1 -1
  494. package/dist/discovery/deprecation-report.md +1 -1
  495. package/dist/discovery/discovery-manifest.json +1802 -448
  496. package/dist/discovery/discovery-manifest.json.sha256 +1 -1
  497. package/dist/discovery/discovery-manifest.summary.md +12 -6
  498. package/dist/discovery/orphan-report.md +1 -1
  499. package/dist/discovery/packs.json +303 -43
  500. package/dist/discovery/trust-report.md +4 -4
  501. package/dist/discovery/workspaces.json +127 -41
  502. package/dist/install/install.mjs +13934 -0
  503. package/dist/mcp/registry-manifest.json +4 -4
  504. package/dist/router.json +1 -1
  505. package/dist/server/routes/wizard.js +54 -24
  506. package/dist/server/routes/wizard.js.map +1 -1
  507. package/dist/server/routes/workspace.js +44 -25
  508. package/dist/server/routes/workspace.js.map +1 -1
  509. package/dist/server/schemas/settings.js +33 -0
  510. package/dist/server/schemas/settings.js.map +1 -1
  511. package/docs/MIGRATION.md +1 -1
  512. package/docs/SKILL_CENSUS.md +344 -0
  513. package/docs/adrs/cost/0001-hard-stop-hook.md +5 -5
  514. package/docs/adrs/memory/0001-consumer-side-snapshot.md +15 -7
  515. package/docs/adrs/memory/README.md +6 -5
  516. package/docs/adrs/router/0001-three-tier-routing.md +2 -2
  517. package/docs/adrs/schema/0001-json-schema-frontmatter.md +2 -2
  518. package/docs/adrs/smoke/0001-per-tier-smoke-scripts.md +5 -5
  519. package/docs/adrs/telegraph/0001-default-off-until-bench.md +3 -3
  520. package/docs/architecture/augment-projection.md +1 -1
  521. package/docs/architecture/multi-tool-projection.md +3 -3
  522. package/docs/architecture.md +42 -11
  523. package/docs/archive/CHANGELOG-pre-2.2.0.md +30 -30
  524. package/docs/archive/CHANGELOG-pre-2.25.0.md +1 -1
  525. package/docs/archive/CHANGELOG-pre-4.5.0.md +1 -1
  526. package/docs/archive/CHANGELOG-pre-6.0.0.md +473 -0
  527. package/docs/benchmark.md +51 -53
  528. package/docs/benchmarks.md +2 -2
  529. package/docs/capability-matrix.md +32 -0
  530. package/docs/case-studies/frontend-design-positioning.md +86 -0
  531. package/docs/catalog.md +63 -15
  532. package/docs/command-flows.md +90 -92
  533. package/docs/command-naming-audit.md +60 -0
  534. package/docs/contracts/STABILITY.md +32 -0
  535. package/docs/contracts/adr-layout.md +2 -3
  536. package/docs/contracts/adr-level-6-productization.md +1 -1
  537. package/docs/contracts/agents-md-tech-stack.md +1 -1
  538. package/docs/contracts/ai-council-config.md +64 -29
  539. package/docs/contracts/analysis-memory-loop.md +149 -0
  540. package/docs/contracts/benchmark-ab-contract.md +3 -3
  541. package/docs/contracts/branch-protection-policy.md +27 -0
  542. package/docs/contracts/brand-token-consumption.md +69 -0
  543. package/docs/contracts/command-clusters.md +3 -2
  544. package/docs/contracts/command-surface-tiers.md +13 -0
  545. package/docs/contracts/cost-enforcement.md +1 -1
  546. package/docs/contracts/cost-summary-schema.md +1 -1
  547. package/docs/contracts/daily-workspace.md +1 -0
  548. package/docs/contracts/discovery-manifest.schema.json +25 -4
  549. package/docs/contracts/explain-modes.md +1 -1
  550. package/docs/contracts/implement-ticket-flow.md +15 -16
  551. package/docs/contracts/install-layout.md +249 -0
  552. package/docs/contracts/kernel-membership.md +1 -1
  553. package/docs/contracts/linear-ai-rules-inclusion.md +2 -2
  554. package/docs/contracts/linter-structural-model.md +1 -1
  555. package/docs/contracts/mcp-discovery-phase-notice.md +1 -1
  556. package/docs/contracts/mcp-tool-inventory.md +10 -10
  557. package/docs/contracts/measurement-baseline.md +1 -1
  558. package/docs/contracts/memory-visibility-v1.md +1 -5
  559. package/docs/contracts/multi-tool-projection-fidelity.md +1 -1
  560. package/docs/contracts/namespace.md +3 -3
  561. package/docs/contracts/no-runtime-boundary.md +56 -0
  562. package/docs/contracts/package-self-orientation.md +24 -0
  563. package/docs/contracts/persona-schema.md +1 -1
  564. package/docs/contracts/provider-lifecycle.md +3 -3
  565. package/docs/contracts/reasoning-discipline-protocol.md +83 -0
  566. package/docs/contracts/rule-classification.md +3 -3
  567. package/docs/contracts/rule-interactions.md +1 -1
  568. package/docs/contracts/skill-domains.md +1 -1
  569. package/docs/contracts/smoke-contracts.md +2 -2
  570. package/docs/contracts/surface-tiers.md +81 -0
  571. package/docs/contracts/ticket-bundle-format.md +228 -0
  572. package/docs/contracts/universal-skills.md +0 -1
  573. package/docs/contracts/workspace-boundary.md +84 -0
  574. package/docs/cookbook.md +152 -0
  575. package/docs/customization.md +15 -4
  576. package/docs/decisions/ADR-009-event4u-namespace.md +1 -1
  577. package/docs/decisions/ADR-013-discovery-frontmatter-contract.md +17 -1
  578. package/docs/decisions/ADR-026-explain-mode-translation.md +1 -1
  579. package/docs/decisions/ADR-056-unvalidated-video-adapters-disposition.md +1 -1
  580. package/docs/decisions/ADR-059-render-resume-filesystem-as-state.md +1 -1
  581. package/docs/decisions/ADR-060-comfyui-sandbox-model.md +1 -1
  582. package/docs/decisions/ADR-061-corpus-grounding-layer.md +48 -1
  583. package/docs/decisions/ADR-088-no-external-runtime-federation.md +26 -27
  584. package/docs/decisions/ADR-090-visibility-command-frontmatter-field.md +95 -0
  585. package/docs/decisions/ADR-091-split-meta-capability-packs.md +113 -0
  586. package/docs/decisions/ADR-092-defer-command-tier-alias-removal.md +93 -0
  587. package/docs/decisions/ADR-093-ai-council-config-user-global.md +111 -0
  588. package/docs/decisions/ADR-094-agent-memory-layer-removal.md +94 -0
  589. package/docs/decisions/ADR-095-workspace-boundary-contract.md +108 -0
  590. package/docs/decisions/ADR-096-analysis-workbench.md +110 -0
  591. package/docs/decisions/ADR-097-mission-recipe-privilege-boundary.md +121 -0
  592. package/docs/decisions/ADR-098-evidence-first-structure-discovery.md +154 -0
  593. package/docs/decisions/ADR-099-file-first-pattern-library.md +87 -0
  594. package/docs/decisions/ADR-100-global-knowledge-card-sharing.md +133 -0
  595. package/docs/decisions/ADR-101-ticket-bundle-emission.md +109 -0
  596. package/docs/decisions/ADR-102-ticket-handoff-paste-and-mcp.md +72 -0
  597. package/docs/decisions/ADR-103-global-knowledge-default-off-until-measured.md +92 -0
  598. package/docs/decisions/ADR-200-python-to-typescript-migration.md +193 -0
  599. package/docs/decisions/INDEX.md +15 -0
  600. package/docs/development.md +5 -7
  601. package/docs/distribution/mcp-submission-checklist.md +3 -3
  602. package/docs/featured-commands.md +1 -1
  603. package/docs/featured-skills.md +1 -1
  604. package/docs/getting-started-by-role.md +2 -0
  605. package/docs/getting-started.md +4 -4
  606. package/docs/guidelines/agent-infra/5w2h-analysis.md +1 -1
  607. package/docs/guidelines/agent-infra/comparison-matrix.md +1 -1
  608. package/docs/guidelines/agent-infra/corpus-grounding-authoring.md +1 -1
  609. package/docs/guidelines/agent-infra/critical-thinking.md +1 -1
  610. package/docs/guidelines/agent-infra/engineering-memory-data-format.md +1 -5
  611. package/docs/guidelines/agent-infra/failure-signatures.md +35 -0
  612. package/docs/guidelines/agent-infra/first-principles.md +1 -1
  613. package/docs/guidelines/agent-infra/frontier-reasoning-operating-profile.md +169 -0
  614. package/docs/guidelines/agent-infra/inversion-thinking.md +1 -1
  615. package/docs/guidelines/agent-infra/ios-simulator-guide.md +9 -14
  616. package/docs/guidelines/agent-infra/mcp-request-signing.md +19 -22
  617. package/docs/guidelines/agent-infra/memory-access.md +25 -31
  618. package/docs/guidelines/agent-infra/mental-models.md +1 -1
  619. package/docs/guidelines/agent-infra/model-recommendation.md +29 -0
  620. package/docs/guidelines/agent-infra/scqa-framework.md +3 -3
  621. package/docs/guidelines/agent-infra/security-lint-containment.md +81 -0
  622. package/docs/guidelines/agent-infra/six-hats.md +1 -1
  623. package/docs/guidelines/agent-infra/size-and-scope.md +17 -0
  624. package/docs/guidelines/agent-infra/skill-quality-checklist.md +2 -2
  625. package/docs/guidelines/agent-infra/systems-thinking.md +1 -1
  626. package/docs/guidelines/agent-infra/untrusted-input-spotlighting.md +72 -0
  627. package/docs/guides/frontend-design-corpus-refresh.md +83 -0
  628. package/docs/guides/skill-preview.md +1 -1
  629. package/docs/hook-payload-capture.md +4 -4
  630. package/docs/installation.md +1 -1
  631. package/docs/mcp.md +3 -3
  632. package/docs/migration/consumer-template-consumption-model.md +145 -0
  633. package/docs/migration/divergences/README.md +55 -0
  634. package/docs/migration/divergences/_template.md +50 -0
  635. package/docs/migration/divergences/bench-stats-float-precision.md +72 -0
  636. package/docs/migration/divergences/mcp-telemetry-node-sqlite.md +61 -0
  637. package/docs/migration/divergences/pack-mcp-content-gzip-body.md +53 -0
  638. package/docs/migration/divergences/src-scripts-build_cloud_bundle.md +63 -0
  639. package/docs/migration/divergences/src-scripts-check_memory.md +91 -0
  640. package/docs/migration/divergences/src-scripts-inventory_abstraction_budget.md +65 -0
  641. package/docs/migration/divergences/src-scripts-lint_marketplace.md +57 -0
  642. package/docs/migration/divergences/src-scripts-lint_mcp_registry_manifest.md +70 -0
  643. package/docs/migration/divergences/src-scripts-spotcheck_thin_root.md +60 -0
  644. package/docs/migration/divergences/src-scripts-validate_agent_settings.md +58 -0
  645. package/docs/migration/node-floor.md +86 -0
  646. package/docs/migration/yaml-roundtrip-spike.md +163 -0
  647. package/docs/parity/bench-external.json +58 -0
  648. package/docs/parity/external-runtime.md +46 -0
  649. package/docs/personas.md +6 -1
  650. package/docs/quality.md +3 -3
  651. package/docs/role-experiences.md +19 -0
  652. package/docs/safety.md +3 -3
  653. package/docs/setup/per-ide/windsurf.md +1 -1
  654. package/docs/skills-catalog.md +26 -2
  655. package/docs/threat-model.md +28 -0
  656. package/llms.txt +25 -1
  657. package/package.json +10 -15
  658. package/src/config/agent-settings.template.yml +128 -3
  659. package/src/config/discovery/packs.yml +60 -0
  660. package/src/config/discovery/unassigned-artefacts.yml +6 -0
  661. package/src/config/discovery/workspaces.yml +5 -3
  662. package/src/config/gitignore-block.txt +13 -0
  663. package/src/scripts/_cli/cmd_doctor.ts +2306 -0
  664. package/src/scripts/_cli/cmd_explain.ts +748 -0
  665. package/src/scripts/_cli/cmd_export.ts +375 -0
  666. package/src/scripts/_cli/cmd_migrate.ts +951 -0
  667. package/src/scripts/_cli/cmd_prune.ts +610 -0
  668. package/src/scripts/_cli/cmd_refresh.ts +530 -0
  669. package/src/scripts/_cli/cmd_settings_check.ts +407 -0
  670. package/src/scripts/_cli/cmd_settings_migrate.ts +344 -0
  671. package/src/scripts/_cli/cmd_sync.ts +381 -0
  672. package/src/scripts/_cli/cmd_uninstall.ts +833 -0
  673. package/src/scripts/_cli/cmd_update.ts +585 -0
  674. package/src/scripts/_cli/cmd_upgrade.ts +390 -0
  675. package/src/scripts/_cli/cmd_validate.ts +394 -0
  676. package/src/scripts/_cli/cmd_versions.ts +492 -0
  677. package/src/scripts/_cli/explain_last/assumptions.ts +114 -0
  678. package/src/scripts/_cli/explain_last/council.ts +197 -0
  679. package/src/scripts/_cli/explain_last/halt.ts +73 -0
  680. package/src/scripts/_cli/explain_last/index.ts +155 -0
  681. package/src/scripts/_cli/explain_last/inputs.ts +211 -0
  682. package/src/scripts/_cli/explain_last/memory.ts +231 -0
  683. package/src/scripts/_cli/explain_last/provider.ts +82 -0
  684. package/src/scripts/_cli/explain_last/render.ts +54 -0
  685. package/src/scripts/_cli/explain_last/route.ts +70 -0
  686. package/src/scripts/_cli/explain_last/scrubber.ts +138 -0
  687. package/src/scripts/_cli/explain_last/sections/assumptions.ts +51 -0
  688. package/src/scripts/_cli/explain_last/sections/council.ts +56 -0
  689. package/src/scripts/_cli/explain_last/sections/halt.ts +60 -0
  690. package/src/scripts/_cli/explain_last/sections/header.ts +50 -0
  691. package/src/scripts/_cli/explain_last/sections/index.ts +21 -0
  692. package/src/scripts/_cli/explain_last/sections/inputs.ts +63 -0
  693. package/src/scripts/_cli/explain_last/sections/memory.ts +124 -0
  694. package/src/scripts/_cli/explain_last/sections/pack.ts +42 -0
  695. package/src/scripts/_cli/explain_last/sections/provider.ts +51 -0
  696. package/src/scripts/_cli/explain_last/sections/route.ts +48 -0
  697. package/src/scripts/_cli/explain_last/state_loader.ts +119 -0
  698. package/src/scripts/_dispatch.bash +179 -163
  699. package/src/scripts/_lib/agent_settings.ts +1123 -0
  700. package/src/scripts/_lib/agent_src.ts +654 -0
  701. package/src/scripts/_lib/agents_overlay.ts +183 -0
  702. package/src/scripts/_lib/bench_ab_cache.ts +399 -0
  703. package/src/scripts/_lib/bench_ab_scoring.ts +352 -0
  704. package/src/scripts/_lib/bench_ab_scoring_v2.ts +751 -0
  705. package/src/scripts/_lib/bench_cost.ts +396 -0
  706. package/src/scripts/_lib/bench_quality.ts +237 -0
  707. package/src/scripts/_lib/bench_report.ts +255 -0
  708. package/src/scripts/_lib/bench_telegraph.ts +516 -0
  709. package/src/scripts/_lib/bench_telegraph_report.ts +272 -0
  710. package/src/scripts/_lib/changelog_eras.ts +398 -0
  711. package/src/scripts/_lib/claude_desktop_bundler.ts +324 -0
  712. package/src/scripts/_lib/cli_wrapper.ts +89 -0
  713. package/src/scripts/_lib/fs_atomic.ts +172 -0
  714. package/src/scripts/_lib/global_deploy_inventory.ts +639 -0
  715. package/src/scripts/_lib/install_layout.ts +87 -0
  716. package/src/scripts/_lib/install_regenerator.ts +157 -0
  717. package/src/scripts/_lib/installed_lock.ts +451 -0
  718. package/src/scripts/_lib/installed_tools.ts +518 -0
  719. package/src/scripts/_lib/json_pointers.ts +388 -0
  720. package/src/scripts/_lib/knowledge_global.ts +770 -0
  721. package/src/scripts/_lib/knowledge_global_promote.ts +453 -0
  722. package/src/scripts/_lib/knowledge_global_redaction.ts +448 -0
  723. package/src/scripts/_lib/link_crypto.ts +325 -0
  724. package/src/scripts/_lib/linked_projects.ts +613 -0
  725. package/src/scripts/_lib/model_tier.ts +65 -0
  726. package/src/scripts/_lib/module_detection.ts +275 -0
  727. package/src/scripts/_lib/node_sqlite.d.ts +32 -0
  728. package/src/scripts/_lib/pin_resolver.ts +264 -0
  729. package/src/scripts/_lib/py_random.ts +212 -0
  730. package/src/scripts/_lib/script_output.ts +147 -0
  731. package/src/scripts/_lib/security_lint.ts +623 -0
  732. package/src/scripts/_lib/surface_tiers.ts +127 -0
  733. package/src/scripts/_lib/token_count.ts +126 -0
  734. package/src/scripts/_lib/update_check.ts +297 -0
  735. package/src/scripts/_lib/user_global_paths.ts +329 -0
  736. package/src/scripts/_lib/value_ladder.ts +882 -0
  737. package/src/scripts/_lib/value_report.ts +617 -0
  738. package/src/scripts/_lib/zip_min.ts +175 -0
  739. package/src/scripts/adoption_report.ts +357 -0
  740. package/src/scripts/adoption_snapshot.ts +392 -0
  741. package/src/scripts/adoption_status.ts +424 -0
  742. package/src/scripts/adr/regenerate_index.ts +257 -0
  743. package/src/scripts/ai-image/adapters/flux.sh +45 -0
  744. package/src/scripts/ai-image/adapters/gemini-image.sh +45 -0
  745. package/src/scripts/ai-image/adapters/ideogram.sh +45 -0
  746. package/src/scripts/ai-image/adapters/recraft.sh +47 -0
  747. package/src/scripts/ai-video/adapters/comfyui.sh +3 -3
  748. package/src/scripts/ai-video/adapters/fal.sh +3 -3
  749. package/src/scripts/ai-video/adapters/gemini-veo.sh +3 -3
  750. package/src/scripts/ai-video/adapters/higgsfield.sh +3 -3
  751. package/src/scripts/ai-video/adapters/kling.sh +3 -3
  752. package/src/scripts/ai-video/adapters/musetalk.sh +2 -2
  753. package/src/scripts/ai-video/adapters/openai-images.sh +3 -3
  754. package/src/scripts/ai-video/adapters/replicate.sh +3 -3
  755. package/src/scripts/ai-video/adapters/sora.sh +3 -3
  756. package/src/scripts/ai-video/adapters/syncso.sh +3 -3
  757. package/src/scripts/ai-video/audio-adapters/allin1.sh +2 -2
  758. package/src/scripts/ai-video/audio-adapters/whisperx.sh +2 -2
  759. package/src/scripts/ai-video/lib/audio-adapter-contract.md +1 -1
  760. package/src/scripts/ai-video/lib/embed-provenance.sh +2 -2
  761. package/src/scripts/ai-video/lib/ingest-song.sh +2 -2
  762. package/src/scripts/ai-video/lib/parse-blueprint.sh +1 -1
  763. package/src/scripts/ai-video/lib/resume-scan.sh +2 -2
  764. package/src/scripts/ai-video/smoke-trace.sh +16 -7
  765. package/src/scripts/ai-video/stitch.sh +2 -2
  766. package/src/scripts/ai_council/_default_prices.ts +73 -0
  767. package/src/scripts/ai_council/advisors.ts +244 -0
  768. package/src/scripts/ai_council/airgap.ts +249 -0
  769. package/src/scripts/ai_council/budget_guard.ts +492 -0
  770. package/src/scripts/ai_council/bundler.ts +376 -0
  771. package/src/scripts/ai_council/cli_hints.ts +120 -0
  772. package/src/scripts/ai_council/clients.ts +2214 -0
  773. package/src/scripts/ai_council/compile_corpus.ts +681 -0
  774. package/src/scripts/ai_council/confidence_gate.ts +230 -0
  775. package/src/scripts/ai_council/config.ts +1729 -0
  776. package/src/scripts/ai_council/consensus.ts +551 -0
  777. package/src/scripts/ai_council/events_log.ts +327 -0
  778. package/src/scripts/ai_council/learn_low_impact_preview.ts +317 -0
  779. package/src/scripts/ai_council/low_impact.ts +1069 -0
  780. package/src/scripts/ai_council/low_impact_corpus.ts +662 -0
  781. package/src/scripts/ai_council/low_impact_intake.ts +222 -0
  782. package/src/scripts/ai_council/modes.ts +169 -0
  783. package/src/scripts/ai_council/necessity.ts +933 -0
  784. package/src/scripts/ai_council/orchestrator.ts +1689 -0
  785. package/src/scripts/ai_council/pricing.ts +267 -0
  786. package/src/scripts/ai_council/probation_gate.ts +282 -0
  787. package/src/scripts/ai_council/project_context.ts +308 -0
  788. package/src/scripts/ai_council/prompts.ts +600 -0
  789. package/src/scripts/ai_council/redact_low_impact_entry.ts +291 -0
  790. package/src/scripts/ai_council/replay.ts +314 -0
  791. package/src/scripts/ai_council/session.ts +558 -0
  792. package/src/scripts/ai_council/shadow_dispatch.ts +509 -0
  793. package/src/scripts/ai_council/solo_dispatch.ts +281 -0
  794. package/src/scripts/analysis_freshness.ts +343 -0
  795. package/src/scripts/annotate_discovery.ts +288 -0
  796. package/src/scripts/apply_modules_config.ts +537 -0
  797. package/src/scripts/audit_adr_coverage.ts +357 -0
  798. package/src/scripts/audit_auto_rules.ts +415 -0
  799. package/src/scripts/audit_cloud_compatibility.ts +608 -0
  800. package/src/scripts/audit_command_surface.ts +1227 -0
  801. package/src/scripts/audit_initial_context.ts +694 -0
  802. package/src/scripts/audit_likelihood.ts +434 -0
  803. package/src/scripts/audit_mcp_tools.ts +252 -0
  804. package/src/scripts/audit_overlap.ts +421 -0
  805. package/src/scripts/audit_skill_descriptions.ts +402 -0
  806. package/src/scripts/audit_skill_overlap.ts +576 -0
  807. package/src/scripts/audit_user_type_axis.ts +264 -0
  808. package/src/scripts/backfill_model_tier.ts +349 -0
  809. package/src/scripts/bench_ab_cache_dispatch.ts +126 -0
  810. package/src/scripts/bench_ab_clone.ts +610 -0
  811. package/src/scripts/bench_ab_diff.ts +609 -0
  812. package/src/scripts/bench_ab_integrity.ts +261 -0
  813. package/src/scripts/bench_ab_run.ts +417 -0
  814. package/src/scripts/bench_ab_task_runner.ts +1382 -0
  815. package/src/scripts/bench_ab_tracka_run.ts +436 -0
  816. package/src/scripts/bench_ab_v2_run.ts +585 -0
  817. package/src/scripts/bench_ab_v2_stats.ts +1018 -0
  818. package/src/scripts/bench_baseline_ready.ts +326 -0
  819. package/src/scripts/bench_condense_memory.ts +479 -0
  820. package/src/scripts/bench_drift_check.ts +503 -0
  821. package/src/scripts/bench_per_tool.ts +591 -0
  822. package/src/scripts/bench_rtk_savings.ts +710 -0
  823. package/src/scripts/bench_run.ts +509 -0
  824. package/src/scripts/bench_runner.ts +519 -0
  825. package/src/scripts/build_cloud_bundle.ts +692 -0
  826. package/src/scripts/build_discovery_manifest.ts +1371 -0
  827. package/src/scripts/build_linear_digest.ts +368 -0
  828. package/src/scripts/build_mcp_registry_manifest.ts +351 -0
  829. package/src/scripts/build_rule_trigger_matrix.ts +469 -0
  830. package/src/scripts/capture_showcase_session.ts +735 -0
  831. package/src/scripts/chat_history.ts +2301 -0
  832. package/src/scripts/check_always_budget.ts +694 -0
  833. package/src/scripts/check_artefact_checksums.ts +281 -0
  834. package/src/scripts/check_augment_description_cap.ts +133 -0
  835. package/src/scripts/check_augmentignore.ts +108 -0
  836. package/src/scripts/check_beta_review_markers.ts +234 -0
  837. package/src/scripts/check_bite_sized_granularity.ts +116 -0
  838. package/src/scripts/check_cluster_patterns.ts +285 -0
  839. package/src/scripts/check_command_count_messaging.ts +224 -0
  840. package/src/scripts/check_condensation.ts +900 -0
  841. package/src/scripts/check_condensed_paths.ts +414 -0
  842. package/src/scripts/check_context_paths.ts +388 -0
  843. package/src/scripts/check_council_config_location.ts +260 -0
  844. package/src/scripts/check_council_layout.ts +180 -0
  845. package/src/scripts/check_council_references.ts +345 -0
  846. package/src/scripts/check_discovery_determinism.ts +124 -0
  847. package/src/scripts/check_gate_paths.ts +230 -0
  848. package/src/scripts/check_iron_law_prominence.ts +298 -0
  849. package/src/scripts/check_kernel_rule_bundle.ts +242 -0
  850. package/src/scripts/check_knowledge_cards.ts +759 -0
  851. package/src/scripts/check_md_language.ts +291 -0
  852. package/src/scripts/check_memory.ts +845 -0
  853. package/src/scripts/check_memory_proposal.ts +351 -0
  854. package/src/scripts/check_module_management_neutral.ts +238 -0
  855. package/src/scripts/check_no_conflict_markers.ts +298 -0
  856. package/src/scripts/check_no_conflict_markers_allowlist.json +4 -0
  857. package/src/scripts/check_no_external_sources.ts +351 -0
  858. package/src/scripts/check_no_local_settings_committed.ts +69 -0
  859. package/src/scripts/check_no_new_legacy_path.ts +188 -0
  860. package/src/scripts/check_no_roadmap_refs.ts +304 -0
  861. package/src/scripts/check_one_off_location.ts +165 -0
  862. package/src/scripts/check_overlay_cascade_subdirs.ts +188 -0
  863. package/src/scripts/check_portability.ts +860 -0
  864. package/src/scripts/check_proposal.ts +0 -0
  865. package/src/scripts/check_public_catalog_links.ts +204 -0
  866. package/src/scripts/check_public_links.ts +357 -0
  867. package/src/scripts/check_references.ts +963 -0
  868. package/src/scripts/check_release_includes_discovery.ts +94 -0
  869. package/src/scripts/check_release_pr_shape.ts +222 -0
  870. package/src/scripts/check_release_published.ts +235 -0
  871. package/src/scripts/check_release_trunk_sync.ts +203 -0
  872. package/src/scripts/check_reply_consistency.ts +359 -0
  873. package/src/scripts/check_roadmap_trackable.ts +268 -0
  874. package/src/scripts/check_role_doc_links.ts +187 -0
  875. package/src/scripts/check_safety_floor_untouched.ts +160 -0
  876. package/src/scripts/check_skill_requires.ts +205 -0
  877. package/src/scripts/check_structural_breaking.ts +170 -0
  878. package/src/scripts/check_surface_tiers.ts +567 -0
  879. package/src/scripts/check_template_pin_drift.ts +222 -0
  880. package/src/scripts/check_test_coverage_diff.ts +235 -0
  881. package/src/scripts/check_token_optimizer_freshness.ts +183 -0
  882. package/src/scripts/check_trigger_evals.ts +375 -0
  883. package/src/scripts/check_update_banner.ts +143 -0
  884. package/src/scripts/ci_status.ts +0 -0
  885. package/src/scripts/ci_summary.ts +235 -0
  886. package/src/scripts/ci_time_ratio.ts +526 -0
  887. package/src/scripts/command_suggester/cooldown.ts +176 -0
  888. package/src/scripts/command_suggester/index.ts +41 -0
  889. package/src/scripts/command_suggester/loader.ts +205 -0
  890. package/src/scripts/command_suggester/match.ts +294 -0
  891. package/src/scripts/command_suggester/rank.ts +201 -0
  892. package/src/scripts/command_suggester/render.ts +122 -0
  893. package/src/scripts/command_suggester/sanitize.ts +114 -0
  894. package/src/scripts/command_suggester/settings.ts +186 -0
  895. package/src/scripts/command_suggester/types.ts +0 -0
  896. package/src/scripts/compile_router.ts +297 -0
  897. package/src/scripts/condense.sh +7 -1
  898. package/src/scripts/condense.ts +2035 -0
  899. package/src/scripts/condense_memory.ts +334 -0
  900. package/src/scripts/config/index.ts +15 -0
  901. package/src/scripts/config/packs.ts +310 -0
  902. package/src/scripts/config/presets.ts +369 -0
  903. package/src/scripts/config/profile_explain.ts +114 -0
  904. package/src/scripts/config/profiles.ts +277 -0
  905. package/src/scripts/config/session_profiles.ts +1064 -0
  906. package/src/scripts/context_hygiene_hook.ts +272 -0
  907. package/src/scripts/cost_by_conversation.ts +444 -0
  908. package/src/scripts/cost_summary.ts +407 -0
  909. package/src/scripts/council_cli.ts +2827 -0
  910. package/src/scripts/council_prune.ts +153 -0
  911. package/src/scripts/cross_repo_retrieve.ts +694 -0
  912. package/src/scripts/discovery_stats.ts +218 -0
  913. package/src/scripts/evidence_report.ts +580 -0
  914. package/src/scripts/external_sources_denylist.json +92 -0
  915. package/src/scripts/extract_audit_patterns.ts +394 -0
  916. package/src/scripts/first_run_gate_hook.ts +246 -0
  917. package/src/scripts/gen_discovery_baseline.ts +297 -0
  918. package/src/scripts/generate_capabilities_index.ts +496 -0
  919. package/src/scripts/generate_capability_matrix.ts +430 -0
  920. package/src/scripts/generate_catalog.ts +178 -0
  921. package/src/scripts/generate_command_flows.ts +316 -0
  922. package/src/scripts/generate_cookbook.ts +302 -0
  923. package/src/scripts/generate_index.ts +500 -0
  924. package/src/scripts/generate_ownership_matrix.ts +646 -0
  925. package/src/scripts/generate_pack_manifests.ts +1025 -0
  926. package/src/scripts/generate_role_experiences_catalog.ts +265 -0
  927. package/src/scripts/hermetic-install.sh +22 -11
  928. package/src/scripts/hook_manifest.yaml +37 -15
  929. package/src/scripts/hooks/augment-chat-history.sh +3 -10
  930. package/src/scripts/hooks/augment-context-hygiene.sh +3 -10
  931. package/src/scripts/hooks/augment-dispatcher.sh +3 -10
  932. package/src/scripts/hooks/augment-onboarding-gate.sh +3 -10
  933. package/src/scripts/hooks/augment-roadmap-progress.sh +3 -10
  934. package/src/scripts/hooks/block_no_verify.ts +413 -0
  935. package/src/scripts/hooks/cline-dispatcher.sh +3 -10
  936. package/src/scripts/hooks/cowork-dispatcher.sh +3 -14
  937. package/src/scripts/hooks/cursor-dispatcher.sh +3 -10
  938. package/src/scripts/hooks/dispatch_hook.ts +851 -0
  939. package/src/scripts/hooks/dispatch_issues.ts +226 -0
  940. package/src/scripts/hooks/envelope.ts +140 -0
  941. package/src/scripts/hooks/gemini-dispatcher.sh +3 -8
  942. package/src/scripts/hooks/replay_hook.ts +364 -0
  943. package/src/scripts/hooks/state_io.ts +293 -0
  944. package/src/scripts/hooks/windsurf-dispatcher.sh +3 -9
  945. package/src/scripts/hooks_doctor.ts +418 -0
  946. package/src/scripts/hooks_status.ts +292 -0
  947. package/src/scripts/injection_scan_hook.ts +285 -0
  948. package/src/scripts/install +36 -22
  949. package/src/scripts/install-hooks.sh +29 -12
  950. package/src/scripts/install.sh +38 -14
  951. package/src/scripts/install.ts +4515 -0
  952. package/src/scripts/inventory_abstraction_budget.ts +1104 -0
  953. package/src/scripts/inventory_frontmatter.ts +320 -0
  954. package/src/scripts/inventory_meta_layers.ts +516 -0
  955. package/src/scripts/iron_law_sha.ts +233 -0
  956. package/src/scripts/knowledge_global_cli.ts +1105 -0
  957. package/src/scripts/linked_projects_list.ts +310 -0
  958. package/src/scripts/lint_agent_security.ts +224 -0
  959. package/src/scripts/lint_agent_skill_names.ts +241 -0
  960. package/src/scripts/lint_agents_layout.ts +205 -0
  961. package/src/scripts/lint_agents_md.ts +294 -0
  962. package/src/scripts/lint_archived_skills.ts +309 -0
  963. package/src/scripts/lint_artefact_frontmatter.ts +359 -0
  964. package/src/scripts/lint_bench_ab.ts +319 -0
  965. package/src/scripts/lint_bench_corpus.ts +421 -0
  966. package/src/scripts/lint_command_flow_coverage.ts +231 -0
  967. package/src/scripts/lint_command_routing.ts +377 -0
  968. package/src/scripts/lint_command_tiers.ts +345 -0
  969. package/src/scripts/lint_command_verbs.ts +379 -0
  970. package/src/scripts/lint_commit_subjects.ts +243 -0
  971. package/src/scripts/lint_context_spine_usage.ts +198 -0
  972. package/src/scripts/lint_discovery_manifest.ts +540 -0
  973. package/src/scripts/lint_discovery_vocabulary.ts +393 -0
  974. package/src/scripts/lint_empty_roadmaps.ts +147 -0
  975. package/src/scripts/lint_eval_freshness.ts +335 -0
  976. package/src/scripts/lint_examples.ts +183 -0
  977. package/src/scripts/lint_explain_trace.ts +381 -0
  978. package/src/scripts/lint_featured_skills.ts +0 -0
  979. package/src/scripts/lint_flows.ts +701 -0
  980. package/src/scripts/lint_framework_leakage.ts +497 -0
  981. package/src/scripts/lint_framework_leakage_allowlist.json +8 -1
  982. package/src/scripts/lint_frontmatter_boilerplate.ts +356 -0
  983. package/src/scripts/lint_ghostwriter_source.ts +389 -0
  984. package/src/scripts/lint_global_paths.ts +420 -0
  985. package/src/scripts/lint_handoffs.ts +362 -0
  986. package/src/scripts/lint_hidden_unicode.ts +350 -0
  987. package/src/scripts/lint_hook_concern_budget.ts +319 -0
  988. package/src/scripts/lint_hook_manifest.ts +354 -0
  989. package/src/scripts/lint_instruction_smuggling.ts +173 -0
  990. package/src/scripts/lint_load_context.ts +371 -0
  991. package/src/scripts/lint_marketplace.ts +286 -0
  992. package/src/scripts/lint_marketplace_install_completeness.ts +309 -0
  993. package/src/scripts/lint_mcp_config_security.ts +225 -0
  994. package/src/scripts/lint_mcp_registry_manifest.ts +350 -0
  995. package/src/scripts/lint_media_policy_linkage.ts +224 -0
  996. package/src/scripts/lint_missions.ts +774 -0
  997. package/src/scripts/lint_model_tier_coverage.ts +151 -0
  998. package/src/scripts/lint_namespace.ts +295 -0
  999. package/src/scripts/lint_namespace_collisions.ts +203 -0
  1000. package/src/scripts/lint_new_skill_gate.ts +462 -0
  1001. package/src/scripts/lint_no_new_atomic_commands.ts +342 -0
  1002. package/src/scripts/lint_one_off_age.ts +348 -0
  1003. package/src/scripts/lint_orchestration_dsl.ts +377 -0
  1004. package/src/scripts/lint_orchestrator_auto_detect.ts +177 -0
  1005. package/src/scripts/lint_pack_boundaries.ts +366 -0
  1006. package/src/scripts/lint_pack_dependencies.ts +541 -0
  1007. package/src/scripts/lint_pack_first_win.ts +202 -0
  1008. package/src/scripts/lint_persona_governance.ts +292 -0
  1009. package/src/scripts/lint_positioning.ts +257 -0
  1010. package/src/scripts/lint_profile_overlay_set_only.ts +324 -0
  1011. package/src/scripts/lint_readme_jargon.ts +189 -0
  1012. package/src/scripts/lint_readme_size.ts +73 -0
  1013. package/src/scripts/lint_regression.ts +497 -0
  1014. package/src/scripts/lint_roadmap_ci_steps.ts +252 -0
  1015. package/src/scripts/lint_roadmap_complexity.ts +295 -0
  1016. package/src/scripts/lint_roadmap_later_disposition.ts +357 -0
  1017. package/src/scripts/lint_role_experiences.ts +410 -0
  1018. package/src/scripts/lint_rule_interactions.ts +281 -0
  1019. package/src/scripts/lint_rule_tiers.ts +169 -0
  1020. package/src/scripts/lint_showcase_sessions.ts +254 -0
  1021. package/src/scripts/lint_skill_frontmatter_safety.ts +279 -0
  1022. package/src/scripts/lint_skill_originality.ts +586 -0
  1023. package/src/scripts/lint_skill_originality_allowlist.json +20 -0
  1024. package/src/scripts/lint_skill_tools.ts +320 -0
  1025. package/src/scripts/lint_ticket_buildable.ts +1027 -0
  1026. package/src/scripts/lint_topics_yaml.ts +203 -0
  1027. package/src/scripts/lint_trust_coherence.ts +377 -0
  1028. package/src/scripts/lint_value_dashboard.ts +314 -0
  1029. package/src/scripts/lint_workflow_security.ts +637 -0
  1030. package/src/scripts/lint_workflow_security_allowlist.json +20 -0
  1031. package/src/scripts/lint_workspace_boundary.ts +248 -0
  1032. package/src/scripts/mcp_parity_smoke.ts +638 -0
  1033. package/src/scripts/mcp_render.ts +346 -0
  1034. package/src/scripts/mcp_server/__main__.ts +28 -0
  1035. package/src/scripts/mcp_server/catalog.ts +154 -0
  1036. package/src/scripts/mcp_server/consumer_tool_catalog.json +2 -3
  1037. package/src/scripts/mcp_server/index.ts +24 -0
  1038. package/src/scripts/mcp_server/metadata.ts +83 -0
  1039. package/src/scripts/mcp_server/prompts.ts +711 -0
  1040. package/src/scripts/mcp_server/resources.ts +343 -0
  1041. package/src/scripts/mcp_server/server.ts +439 -0
  1042. package/src/scripts/mcp_server/telemetry.ts +154 -0
  1043. package/src/scripts/mcp_server/tools.ts +1031 -0
  1044. package/src/scripts/mcp_setup.sh +25 -52
  1045. package/src/scripts/mcp_telemetry_health.ts +362 -0
  1046. package/src/scripts/mcp_telemetry_query.ts +371 -0
  1047. package/src/scripts/mcp_telemetry_store.ts +422 -0
  1048. package/src/scripts/measure_augment_budget.ts +453 -0
  1049. package/src/scripts/measure_density.ts +618 -0
  1050. package/src/scripts/measure_frugality_savings.ts +353 -0
  1051. package/src/scripts/measure_markitdown_lift.ts +299 -0
  1052. package/src/scripts/measure_patterns.ts +682 -0
  1053. package/src/scripts/measure_projection_bytes.ts +425 -0
  1054. package/src/scripts/measure_rule_budget.ts +627 -0
  1055. package/src/scripts/measure_skill_reduction.ts +442 -0
  1056. package/src/scripts/media/lib/adapter-common.sh +247 -0
  1057. package/src/scripts/media/lib/adapter-contract.md +329 -0
  1058. package/src/scripts/media/lib/fixtures/comfyui/result.json +1 -0
  1059. package/src/scripts/media/lib/fixtures/fal/result.json +1 -0
  1060. package/src/scripts/media/lib/fixtures/flux/asset-0001.png +0 -0
  1061. package/src/scripts/media/lib/fixtures/flux/result.json +1 -0
  1062. package/src/scripts/media/lib/fixtures/gemini-image/asset-0001.png +0 -0
  1063. package/src/scripts/media/lib/fixtures/gemini-image/result.json +1 -0
  1064. package/src/scripts/media/lib/fixtures/gemini-veo/result.json +1 -0
  1065. package/src/scripts/media/lib/fixtures/higgsfield/result.json +1 -0
  1066. package/src/scripts/media/lib/fixtures/ideogram/asset-0001.png +0 -0
  1067. package/src/scripts/media/lib/fixtures/ideogram/result.json +1 -0
  1068. package/src/scripts/media/lib/fixtures/kling/result.json +1 -0
  1069. package/src/scripts/media/lib/fixtures/musetalk/result.json +1 -0
  1070. package/src/scripts/media/lib/fixtures/openai-images/result.json +1 -0
  1071. package/src/scripts/media/lib/fixtures/recraft/asset-0001.svg +1 -0
  1072. package/src/scripts/media/lib/fixtures/recraft/result.json +1 -0
  1073. package/src/scripts/media/lib/fixtures/replicate/result.json +1 -0
  1074. package/src/scripts/media/lib/fixtures/sora/result.json +1 -0
  1075. package/src/scripts/media/lib/fixtures/syncso/result.json +1 -0
  1076. package/src/scripts/media/lib/load-config.sh +180 -0
  1077. package/src/scripts/media/lib/redact.sh +85 -0
  1078. package/src/scripts/memory_hash.ts +331 -0
  1079. package/src/scripts/memory_lookup.ts +1278 -0
  1080. package/src/scripts/memory_report.ts +845 -0
  1081. package/src/scripts/memory_signal.ts +417 -0
  1082. package/src/scripts/memory_status.ts +189 -0
  1083. package/src/scripts/migrate_command_suggestions.ts +341 -0
  1084. package/src/scripts/migrate_frontmatter_defaults.ts +539 -0
  1085. package/src/scripts/migration_status.ts +301 -0
  1086. package/src/scripts/mine_session.ts +645 -0
  1087. package/src/scripts/minimal_safe_diff_hook.ts +355 -0
  1088. package/src/scripts/move_artefact.ts +869 -0
  1089. package/src/scripts/new_skill.ts +404 -0
  1090. package/src/scripts/onboarding_gate_hook.ts +224 -0
  1091. package/src/scripts/pack_dependency_allowlist.json +2 -2
  1092. package/src/scripts/pack_mcp_content.ts +552 -0
  1093. package/src/scripts/parity/README.md +140 -0
  1094. package/src/scripts/parity/compare.ts +189 -0
  1095. package/src/scripts/parity/coverage_diff.ts +199 -0
  1096. package/src/scripts/parity/phase-manifest.json +93 -0
  1097. package/src/scripts/parity/phase_gate.ts +270 -0
  1098. package/src/scripts/parity/replay.ts +320 -0
  1099. package/src/scripts/pattern_share.ts +363 -0
  1100. package/src/scripts/plan_physical_move.ts +605 -0
  1101. package/src/scripts/prediction-pool/poisson_sim.ts +537 -0
  1102. package/src/scripts/prediction-pool/pool_winsim.ts +677 -0
  1103. package/src/scripts/prediction-pool/score_ev.ts +546 -0
  1104. package/src/scripts/print_required_checks.ts +249 -0
  1105. package/src/scripts/probe_projection_fidelity.ts +468 -0
  1106. package/src/scripts/probe_skill_registration.ts +787 -0
  1107. package/src/scripts/profile_staleness_hook.ts +169 -0
  1108. package/src/scripts/profile_use.ts +227 -0
  1109. package/src/scripts/project_thin_rules.ts +387 -0
  1110. package/src/scripts/propose_modules_config.ts +311 -0
  1111. package/src/scripts/prototype_lint_contradictions.ts +414 -0
  1112. package/src/scripts/prove_pack_extractable.ts +388 -0
  1113. package/src/scripts/readme_linter.ts +913 -0
  1114. package/src/scripts/redact_hook_capture.ts +325 -0
  1115. package/src/scripts/refine_ticket_detect.ts +703 -0
  1116. package/src/scripts/release.ts +1697 -0
  1117. package/src/scripts/render_benchmark_md.ts +664 -0
  1118. package/src/scripts/render_value_md.ts +506 -0
  1119. package/src/scripts/repro/repro_marketplace_install_gap.sh +1 -1
  1120. package/src/scripts/roadmap_progress_hook.ts +410 -0
  1121. package/src/scripts/router_telemetry.ts +972 -0
  1122. package/src/scripts/run.ts +98 -0
  1123. package/src/scripts/run_skill_evals.ts +477 -0
  1124. package/src/scripts/runtime_dispatcher.ts +586 -0
  1125. package/src/scripts/runtime_handler.ts +231 -0
  1126. package/src/scripts/runtime_registry.ts +394 -0
  1127. package/src/scripts/schemas/command.schema.json +7 -1
  1128. package/src/scripts/schemas/mission-catalog.schema.json +112 -0
  1129. package/src/scripts/schemas/mission.schema.json +87 -0
  1130. package/src/scripts/schemas/pack.schema.json +6 -0
  1131. package/src/scripts/schemas/rule.schema.json +1 -0
  1132. package/src/scripts/schemas/skill.schema.json +1 -0
  1133. package/src/scripts/schemas/ticket-manifest.schema.json +35 -0
  1134. package/src/scripts/schemas/ticket.schema.json +60 -0
  1135. package/src/scripts/score_skill_selection.ts +570 -0
  1136. package/src/scripts/security_audit_config.ts +423 -0
  1137. package/src/scripts/skill_collision_clusters.ts +448 -0
  1138. package/src/scripts/skill_discovery.ts +690 -0
  1139. package/src/scripts/skill_linter.ts +4276 -0
  1140. package/src/scripts/skill_overlap.ts +414 -0
  1141. package/src/scripts/skill_preview.ts +548 -0
  1142. package/src/scripts/skill_tools/audit_persona_coverage.ts +427 -0
  1143. package/src/scripts/skill_tools/audit_user_type_coverage.ts +507 -0
  1144. package/src/scripts/skill_tools/index.ts +28 -0
  1145. package/src/scripts/skill_tools/run_block_d_eval.ts +373 -0
  1146. package/src/scripts/skill_tools/score_skill_relevance.ts +475 -0
  1147. package/src/scripts/skill_tools/suggest_skill_for_task.ts +288 -0
  1148. package/src/scripts/skill_trigger_eval.ts +1046 -0
  1149. package/src/scripts/skill_usage_collect.ts +465 -0
  1150. package/src/scripts/skill_usage_report.ts +364 -0
  1151. package/src/scripts/smoke/kernel.sh +4 -5
  1152. package/src/scripts/smoke/router.sh +76 -76
  1153. package/src/scripts/smoke/schema.sh +2 -2
  1154. package/src/scripts/smoke/skills.sh +73 -52
  1155. package/src/scripts/smoke_path_resolution.ts +194 -0
  1156. package/src/scripts/smoke_quickstart.ts +224 -0
  1157. package/src/scripts/snapshot_agent_outputs.ts +375 -0
  1158. package/src/scripts/spotcheck_thin_root.ts +247 -0
  1159. package/src/scripts/surface-tiers.yml +68 -0
  1160. package/src/scripts/sync_agent_settings.ts +763 -0
  1161. package/src/scripts/sync_github_metadata.ts +550 -0
  1162. package/src/scripts/sync_gitignore.ts +630 -0
  1163. package/src/scripts/sync_yaml_rt.ts +910 -0
  1164. package/src/scripts/telegraph_stats.ts +447 -0
  1165. package/src/scripts/tool_registry.ts +330 -0
  1166. package/src/scripts/tools/adapter_errors.ts +93 -0
  1167. package/src/scripts/tools/base_adapter.ts +147 -0
  1168. package/src/scripts/tools/github_adapter.ts +229 -0
  1169. package/src/scripts/tools/jira_adapter.ts +196 -0
  1170. package/src/scripts/trigger_coverage.ts +251 -0
  1171. package/src/scripts/update_counts.ts +284 -0
  1172. package/src/scripts/update_prices.ts +219 -0
  1173. package/src/scripts/validate_agent_settings.ts +265 -0
  1174. package/src/scripts/validate_decision_engine.ts +366 -0
  1175. package/src/scripts/validate_discovery_manifest.ts +160 -0
  1176. package/src/scripts/validate_frontmatter.ts +1030 -0
  1177. package/src/scripts/validate_pack_yaml.ts +0 -0
  1178. package/src/scripts/validate_safe_paths.ts +164 -0
  1179. package/src/scripts/validate_telegraph_carveouts.ts +485 -0
  1180. package/src/scripts/verify_before_complete_hook.ts +306 -0
  1181. package/src/scripts/verify_physical_move.ts +411 -0
  1182. package/src/scripts/wrapper_freshness_hook.ts +179 -0
  1183. package/dist/agent-src/commands/chat-history/learn.md +0 -184
  1184. package/dist/agent-src/commands/chat-history/show.md +0 -113
  1185. package/dist/agent-src/commands/fix/pr-bot-comments.md +0 -157
  1186. package/dist/agent-src/commands/fix/pr-developer-comments.md +0 -163
  1187. package/dist/agent-src/scripts/update_roadmap_progress.py +0 -537
  1188. package/dist/agent-src/skills/corpus-grounding/scripts/bm25_search.py +0 -212
  1189. package/dist/agent-src/skills/corpus-grounding/scripts/decision_engine.py +0 -438
  1190. package/dist/agent-src/skills/corpus-grounding/scripts/ground.py +0 -166
  1191. package/dist/agent-src/skills/corpus-grounding/scripts/schema_validator.py +0 -160
  1192. package/dist/agent-src/skills/design-tokens/scripts/tokens.py +0 -296
  1193. package/dist/agent-src/skills/react-shadcn-ui/scripts/shadcn_add.py +0 -299
  1194. package/dist/agent-src/skills/tailwind-engineer/scripts/tailwind_config_gen.py +0 -463
  1195. package/dist/agent-src/templates/agents/memory/architecture-decisions.example.yml +0 -95
  1196. package/dist/agent-src/templates/scripts/check_memory.py +0 -283
  1197. package/dist/agent-src/templates/scripts/check_memory_proposal.py +0 -180
  1198. package/dist/agent-src/templates/scripts/implement_ticket/__init__.py +0 -94
  1199. package/dist/agent-src/templates/scripts/implement_ticket/__main__.py +0 -15
  1200. package/dist/agent-src/templates/scripts/memory_hash.py +0 -75
  1201. package/dist/agent-src/templates/scripts/memory_lookup.py +0 -577
  1202. package/dist/agent-src/templates/scripts/memory_report.py +0 -184
  1203. package/dist/agent-src/templates/scripts/memory_signal.py +0 -167
  1204. package/dist/agent-src/templates/scripts/memory_status.py +0 -257
  1205. package/dist/agent-src/templates/scripts/pr_review_routing.py +0 -340
  1206. package/dist/agent-src/templates/scripts/pr_risk_review.py +0 -211
  1207. package/dist/agent-src/templates/scripts/telemetry/__init__.py +0 -42
  1208. package/dist/agent-src/templates/scripts/telemetry/aggregator.py +0 -169
  1209. package/dist/agent-src/templates/scripts/telemetry/boundary.py +0 -171
  1210. package/dist/agent-src/templates/scripts/telemetry/engagement.py +0 -297
  1211. package/dist/agent-src/templates/scripts/telemetry/report_renderer.py +0 -197
  1212. package/dist/agent-src/templates/scripts/telemetry/settings.py +0 -177
  1213. package/dist/agent-src/templates/scripts/telemetry_record.py +0 -179
  1214. package/dist/agent-src/templates/scripts/telemetry_report.py +0 -161
  1215. package/dist/agent-src/templates/scripts/telemetry_status.py +0 -142
  1216. package/dist/agent-src/templates/scripts/tier_usage_report.py +0 -183
  1217. package/dist/agent-src/templates/scripts/work_engine/__init__.py +0 -58
  1218. package/dist/agent-src/templates/scripts/work_engine/__main__.py +0 -9
  1219. package/dist/agent-src/templates/scripts/work_engine/_lib/__init__.py +0 -7
  1220. package/dist/agent-src/templates/scripts/work_engine/_lib/agent_settings.py +0 -840
  1221. package/dist/agent-src/templates/scripts/work_engine/_lib/user_global_paths.py +0 -249
  1222. package/dist/agent-src/templates/scripts/work_engine/cli.py +0 -195
  1223. package/dist/agent-src/templates/scripts/work_engine/cli_args.py +0 -116
  1224. package/dist/agent-src/templates/scripts/work_engine/delivery_state.py +0 -137
  1225. package/dist/agent-src/templates/scripts/work_engine/directives/__init__.py +0 -33
  1226. package/dist/agent-src/templates/scripts/work_engine/directives/backend/__init__.py +0 -98
  1227. package/dist/agent-src/templates/scripts/work_engine/directives/backend/analyze.py +0 -98
  1228. package/dist/agent-src/templates/scripts/work_engine/directives/backend/implement.py +0 -145
  1229. package/dist/agent-src/templates/scripts/work_engine/directives/backend/memory.py +0 -136
  1230. package/dist/agent-src/templates/scripts/work_engine/directives/backend/plan.py +0 -175
  1231. package/dist/agent-src/templates/scripts/work_engine/directives/backend/refine.py +0 -396
  1232. package/dist/agent-src/templates/scripts/work_engine/directives/backend/report.py +0 -227
  1233. package/dist/agent-src/templates/scripts/work_engine/directives/backend/test.py +0 -180
  1234. package/dist/agent-src/templates/scripts/work_engine/directives/backend/verify.py +0 -170
  1235. package/dist/agent-src/templates/scripts/work_engine/directives/mixed/__init__.py +0 -116
  1236. package/dist/agent-src/templates/scripts/work_engine/directives/mixed/contract.py +0 -254
  1237. package/dist/agent-src/templates/scripts/work_engine/directives/mixed/stitch.py +0 -229
  1238. package/dist/agent-src/templates/scripts/work_engine/directives/mixed/ui.py +0 -231
  1239. package/dist/agent-src/templates/scripts/work_engine/directives/ui/__init__.py +0 -113
  1240. package/dist/agent-src/templates/scripts/work_engine/directives/ui/_passthrough.py +0 -44
  1241. package/dist/agent-src/templates/scripts/work_engine/directives/ui/apply.py +0 -241
  1242. package/dist/agent-src/templates/scripts/work_engine/directives/ui/audit.py +0 -414
  1243. package/dist/agent-src/templates/scripts/work_engine/directives/ui/design.py +0 -335
  1244. package/dist/agent-src/templates/scripts/work_engine/directives/ui/polish.py +0 -513
  1245. package/dist/agent-src/templates/scripts/work_engine/directives/ui/review.py +0 -471
  1246. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/__init__.py +0 -119
  1247. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/_skipped.py +0 -37
  1248. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/apply.py +0 -165
  1249. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/refine.py +0 -66
  1250. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/report.py +0 -62
  1251. package/dist/agent-src/templates/scripts/work_engine/directives/ui_trivial/test.py +0 -115
  1252. package/dist/agent-src/templates/scripts/work_engine/dispatcher.py +0 -331
  1253. package/dist/agent-src/templates/scripts/work_engine/emitters.py +0 -68
  1254. package/dist/agent-src/templates/scripts/work_engine/errors.py +0 -19
  1255. package/dist/agent-src/templates/scripts/work_engine/hook_bootstrap.py +0 -91
  1256. package/dist/agent-src/templates/scripts/work_engine/hooks/__init__.py +0 -54
  1257. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/__init__.py +0 -35
  1258. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/_chat_history_base.py +0 -59
  1259. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_append.py +0 -43
  1260. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_halt_append.py +0 -41
  1261. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/decision_gate.py +0 -162
  1262. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/decision_trace.py +0 -163
  1263. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/directive_set_guard.py +0 -53
  1264. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/halt_surface_audit.py +0 -50
  1265. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/memory_visibility.py +0 -141
  1266. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/state_shape_validation.py +0 -52
  1267. package/dist/agent-src/templates/scripts/work_engine/hooks/builtin/trace.py +0 -84
  1268. package/dist/agent-src/templates/scripts/work_engine/hooks/context.py +0 -66
  1269. package/dist/agent-src/templates/scripts/work_engine/hooks/events.py +0 -44
  1270. package/dist/agent-src/templates/scripts/work_engine/hooks/exceptions.py +0 -79
  1271. package/dist/agent-src/templates/scripts/work_engine/hooks/registry.py +0 -60
  1272. package/dist/agent-src/templates/scripts/work_engine/hooks/runner.py +0 -73
  1273. package/dist/agent-src/templates/scripts/work_engine/hooks/settings.py +0 -196
  1274. package/dist/agent-src/templates/scripts/work_engine/input_builders.py +0 -163
  1275. package/dist/agent-src/templates/scripts/work_engine/intent/__init__.py +0 -47
  1276. package/dist/agent-src/templates/scripts/work_engine/intent/classify.py +0 -280
  1277. package/dist/agent-src/templates/scripts/work_engine/migration/__init__.py +0 -8
  1278. package/dist/agent-src/templates/scripts/work_engine/migration/v0_to_v1.py +0 -231
  1279. package/dist/agent-src/templates/scripts/work_engine/orchestration.py +0 -193
  1280. package/dist/agent-src/templates/scripts/work_engine/persona_policy.py +0 -85
  1281. package/dist/agent-src/templates/scripts/work_engine/resolvers/__init__.py +0 -22
  1282. package/dist/agent-src/templates/scripts/work_engine/resolvers/diff.py +0 -106
  1283. package/dist/agent-src/templates/scripts/work_engine/resolvers/file.py +0 -113
  1284. package/dist/agent-src/templates/scripts/work_engine/resolvers/prompt.py +0 -90
  1285. package/dist/agent-src/templates/scripts/work_engine/scoring/__init__.py +0 -14
  1286. package/dist/agent-src/templates/scripts/work_engine/scoring/confidence.py +0 -300
  1287. package/dist/agent-src/templates/scripts/work_engine/scoring/decision_engine.py +0 -351
  1288. package/dist/agent-src/templates/scripts/work_engine/scoring/decision_trace.py +0 -141
  1289. package/dist/agent-src/templates/scripts/work_engine/scoring/memory_visibility.py +0 -284
  1290. package/dist/agent-src/templates/scripts/work_engine/stack/__init__.py +0 -31
  1291. package/dist/agent-src/templates/scripts/work_engine/stack/detect.py +0 -187
  1292. package/dist/agent-src/templates/scripts/work_engine/stack/runner.py +0 -481
  1293. package/dist/agent-src/templates/scripts/work_engine/state.py +0 -694
  1294. package/dist/agent-src/templates/scripts/work_engine/state_io.py +0 -202
  1295. package/dist/cli/python/resolvePython.js +0 -38
  1296. package/dist/cli/python/resolvePython.js.map +0 -1
  1297. package/docs/case-studies/frontend-design-vs-ui-ux-pro-max.md +0 -86
  1298. package/docs/contracts/agent-memory-contract.md +0 -159
  1299. package/docs/parity/bench-ruflo.json +0 -58
  1300. package/docs/parity/ruflo.md +0 -46
  1301. package/src/scripts/__pycache__/validate_frontmatter.cpython-312.pyc +0 -0
  1302. package/src/scripts/_archive/_backfill_skill_domains.py +0 -140
  1303. package/src/scripts/_archive/_bootstrap_tier_frontmatter.py +0 -151
  1304. package/src/scripts/_archive/_p43_bodies.py +0 -235
  1305. package/src/scripts/_archive/_p43_condense.py +0 -118
  1306. package/src/scripts/_archive/_p4_migrate.py +0 -199
  1307. package/src/scripts/_archive/_phase2_shim_helper.py +0 -109
  1308. package/src/scripts/_archive/_pilot_council_question.py +0 -57
  1309. package/src/scripts/_cli/__init__.py +0 -0
  1310. package/src/scripts/_cli/cmd_doctor.py +0 -1583
  1311. package/src/scripts/_cli/cmd_explain.py +0 -355
  1312. package/src/scripts/_cli/cmd_export.py +0 -157
  1313. package/src/scripts/_cli/cmd_migrate.py +0 -524
  1314. package/src/scripts/_cli/cmd_prune.py +0 -322
  1315. package/src/scripts/_cli/cmd_refresh.py +0 -179
  1316. package/src/scripts/_cli/cmd_settings_check.py +0 -171
  1317. package/src/scripts/_cli/cmd_settings_migrate.py +0 -147
  1318. package/src/scripts/_cli/cmd_sync.py +0 -166
  1319. package/src/scripts/_cli/cmd_uninstall.py +0 -476
  1320. package/src/scripts/_cli/cmd_update.py +0 -279
  1321. package/src/scripts/_cli/cmd_upgrade.py +0 -172
  1322. package/src/scripts/_cli/cmd_validate.py +0 -177
  1323. package/src/scripts/_cli/cmd_versions.py +0 -160
  1324. package/src/scripts/_cli/explain_last/__init__.py +0 -122
  1325. package/src/scripts/_cli/explain_last/assumptions.py +0 -59
  1326. package/src/scripts/_cli/explain_last/council.py +0 -105
  1327. package/src/scripts/_cli/explain_last/halt.py +0 -44
  1328. package/src/scripts/_cli/explain_last/inputs.py +0 -128
  1329. package/src/scripts/_cli/explain_last/memory.py +0 -94
  1330. package/src/scripts/_cli/explain_last/provider.py +0 -52
  1331. package/src/scripts/_cli/explain_last/render.py +0 -52
  1332. package/src/scripts/_cli/explain_last/route.py +0 -59
  1333. package/src/scripts/_cli/explain_last/scrubber.py +0 -105
  1334. package/src/scripts/_cli/explain_last/sections/__init__.py +0 -35
  1335. package/src/scripts/_cli/explain_last/sections/assumptions.py +0 -21
  1336. package/src/scripts/_cli/explain_last/sections/council.py +0 -27
  1337. package/src/scripts/_cli/explain_last/sections/halt.py +0 -31
  1338. package/src/scripts/_cli/explain_last/sections/header.py +0 -24
  1339. package/src/scripts/_cli/explain_last/sections/inputs.py +0 -27
  1340. package/src/scripts/_cli/explain_last/sections/memory.py +0 -21
  1341. package/src/scripts/_cli/explain_last/sections/pack.py +0 -16
  1342. package/src/scripts/_cli/explain_last/sections/provider.py +0 -26
  1343. package/src/scripts/_cli/explain_last/sections/route.py +0 -22
  1344. package/src/scripts/_cli/explain_last/state_loader.py +0 -76
  1345. package/src/scripts/_emit_domain_table.py +0 -35
  1346. package/src/scripts/_lib/__init__.py +0 -5
  1347. package/src/scripts/_lib/__pycache__/__init__.cpython-312.pyc +0 -0
  1348. package/src/scripts/_lib/__pycache__/agent_src.cpython-312.pyc +0 -0
  1349. package/src/scripts/_lib/agent_settings.py +0 -840
  1350. package/src/scripts/_lib/agent_src.py +0 -491
  1351. package/src/scripts/_lib/agents_overlay.py +0 -120
  1352. package/src/scripts/_lib/bench_ab_cache.py +0 -162
  1353. package/src/scripts/_lib/bench_ab_scoring.py +0 -209
  1354. package/src/scripts/_lib/bench_cost.py +0 -138
  1355. package/src/scripts/_lib/bench_quality.py +0 -118
  1356. package/src/scripts/_lib/bench_report.py +0 -149
  1357. package/src/scripts/_lib/bench_telegraph.py +0 -273
  1358. package/src/scripts/_lib/bench_telegraph_report.py +0 -151
  1359. package/src/scripts/_lib/changelog_eras.py +0 -330
  1360. package/src/scripts/_lib/claude_desktop_bundler.py +0 -238
  1361. package/src/scripts/_lib/cli_wrapper.py +0 -64
  1362. package/src/scripts/_lib/fs_atomic.py +0 -116
  1363. package/src/scripts/_lib/global_deploy_inventory.py +0 -282
  1364. package/src/scripts/_lib/install_regenerator.py +0 -134
  1365. package/src/scripts/_lib/installed_lock.py +0 -256
  1366. package/src/scripts/_lib/installed_tools.py +0 -381
  1367. package/src/scripts/_lib/json_pointers.py +0 -260
  1368. package/src/scripts/_lib/linked_projects.py +0 -238
  1369. package/src/scripts/_lib/model_tier.py +0 -52
  1370. package/src/scripts/_lib/module_detection.py +0 -223
  1371. package/src/scripts/_lib/pin_resolver.py +0 -152
  1372. package/src/scripts/_lib/script_output.py +0 -144
  1373. package/src/scripts/_lib/token_count.py +0 -95
  1374. package/src/scripts/_lib/update_check.py +0 -207
  1375. package/src/scripts/_lib/user_global_paths.py +0 -249
  1376. package/src/scripts/_lib/value_ladder.py +0 -696
  1377. package/src/scripts/_lib/value_report.py +0 -455
  1378. package/src/scripts/_phase4_bucket.py +0 -210
  1379. package/src/scripts/_pilot_measure.py +0 -53
  1380. package/src/scripts/_tmp_scan_framework_leakage.py +0 -119
  1381. package/src/scripts/adoption_report.py +0 -195
  1382. package/src/scripts/adoption_snapshot.py +0 -219
  1383. package/src/scripts/adoption_status.py +0 -166
  1384. package/src/scripts/adr/regenerate_index.py +0 -79
  1385. package/src/scripts/ai-video/lib/adapter-common.sh +0 -231
  1386. package/src/scripts/ai-video/lib/adapter-contract.md +0 -329
  1387. package/src/scripts/ai-video/lib/fixtures/comfyui/result.json +0 -1
  1388. package/src/scripts/ai-video/lib/fixtures/fal/result.json +0 -1
  1389. package/src/scripts/ai-video/lib/fixtures/gemini-veo/result.json +0 -1
  1390. package/src/scripts/ai-video/lib/fixtures/higgsfield/result.json +0 -1
  1391. package/src/scripts/ai-video/lib/fixtures/kling/result.json +0 -1
  1392. package/src/scripts/ai-video/lib/fixtures/musetalk/result.json +0 -1
  1393. package/src/scripts/ai-video/lib/fixtures/openai-images/result.json +0 -1
  1394. package/src/scripts/ai-video/lib/fixtures/replicate/result.json +0 -1
  1395. package/src/scripts/ai-video/lib/fixtures/sora/result.json +0 -1
  1396. package/src/scripts/ai-video/lib/fixtures/syncso/result.json +0 -1
  1397. package/src/scripts/ai-video/lib/load-config.sh +0 -180
  1398. package/src/scripts/ai-video/lib/redact.sh +0 -85
  1399. package/src/scripts/ai_council/__init__.py +0 -40
  1400. package/src/scripts/ai_council/_default_prices.py +0 -50
  1401. package/src/scripts/ai_council/advisors.py +0 -148
  1402. package/src/scripts/ai_council/airgap.py +0 -165
  1403. package/src/scripts/ai_council/budget_guard.py +0 -202
  1404. package/src/scripts/ai_council/bundler.py +0 -263
  1405. package/src/scripts/ai_council/cli_hints.py +0 -123
  1406. package/src/scripts/ai_council/clients.py +0 -1385
  1407. package/src/scripts/ai_council/compile_corpus.py +0 -179
  1408. package/src/scripts/ai_council/confidence_gate.py +0 -156
  1409. package/src/scripts/ai_council/config.py +0 -1364
  1410. package/src/scripts/ai_council/consensus.py +0 -329
  1411. package/src/scripts/ai_council/events_log.py +0 -141
  1412. package/src/scripts/ai_council/learn_low_impact_preview.py +0 -252
  1413. package/src/scripts/ai_council/low_impact.py +0 -714
  1414. package/src/scripts/ai_council/low_impact_corpus.py +0 -466
  1415. package/src/scripts/ai_council/low_impact_intake.py +0 -163
  1416. package/src/scripts/ai_council/modes.py +0 -131
  1417. package/src/scripts/ai_council/necessity.py +0 -782
  1418. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_2a4_acceptance.py +0 -208
  1419. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_add_quiet.py +0 -149
  1420. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_budget_v2_audit.py +0 -206
  1421. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_context_layer_v1_estimate.py +0 -67
  1422. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_context_layer_v1_review.py +0 -292
  1423. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_followups_review.py +0 -259
  1424. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_inject_quiet_flag.py +0 -33
  1425. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_measure_v2.sh +0 -36
  1426. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_measure_verbosity.sh +0 -26
  1427. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_nondestructive_inline_audit.py +0 -209
  1428. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_per_task.sh +0 -41
  1429. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_phase4_dispatch_latency.py +0 -108
  1430. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_phase6_trigger_jaccard.py +0 -92
  1431. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_phase_2a_budget_rebalance.py +0 -257
  1432. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_phase_2a_post_revert.py +0 -197
  1433. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_rebalancing_audit.py +0 -149
  1434. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_roundtrip.py +0 -111
  1435. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_rule_hardening_v1.py +0 -251
  1436. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_silent_taskfiles.py +0 -98
  1437. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_structural_open_questions.py +0 -232
  1438. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_structural_optimization.py +0 -144
  1439. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_structural_v3_gaps.py +0 -252
  1440. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_structural_v3_review.py +0 -240
  1441. package/src/scripts/ai_council/one_off_archive/2026-05/_one_off_tier_retrofit.py +0 -180
  1442. package/src/scripts/ai_council/orchestrator.py +0 -1206
  1443. package/src/scripts/ai_council/pricing.py +0 -215
  1444. package/src/scripts/ai_council/probation_gate.py +0 -152
  1445. package/src/scripts/ai_council/project_context.py +0 -159
  1446. package/src/scripts/ai_council/prompts.py +0 -567
  1447. package/src/scripts/ai_council/redact_low_impact_entry.py +0 -155
  1448. package/src/scripts/ai_council/replay.py +0 -155
  1449. package/src/scripts/ai_council/session.py +0 -366
  1450. package/src/scripts/ai_council/shadow_dispatch.py +0 -235
  1451. package/src/scripts/ai_council/solo_dispatch.py +0 -226
  1452. package/src/scripts/annotate_discovery.py +0 -149
  1453. package/src/scripts/apply_modules_config.py +0 -290
  1454. package/src/scripts/audit_adr_coverage.py +0 -175
  1455. package/src/scripts/audit_auto_rules.py +0 -175
  1456. package/src/scripts/audit_cloud_compatibility.py +0 -362
  1457. package/src/scripts/audit_command_surface.py +0 -669
  1458. package/src/scripts/audit_initial_context.py +0 -237
  1459. package/src/scripts/audit_likelihood.py +0 -148
  1460. package/src/scripts/audit_mcp_tools.py +0 -146
  1461. package/src/scripts/audit_overlap.py +0 -145
  1462. package/src/scripts/audit_skill_descriptions.py +0 -180
  1463. package/src/scripts/audit_skill_overlap.py +0 -207
  1464. package/src/scripts/audit_user_type_axis.py +0 -140
  1465. package/src/scripts/backfill_model_tier.py +0 -184
  1466. package/src/scripts/bench_ab_cache_dispatch.py +0 -68
  1467. package/src/scripts/bench_ab_clone.py +0 -170
  1468. package/src/scripts/bench_ab_diff.py +0 -220
  1469. package/src/scripts/bench_ab_integrity.py +0 -143
  1470. package/src/scripts/bench_ab_run.py +0 -235
  1471. package/src/scripts/bench_ab_task_runner.py +0 -369
  1472. package/src/scripts/bench_ab_tracka_run.py +0 -202
  1473. package/src/scripts/bench_baseline_ready.py +0 -108
  1474. package/src/scripts/bench_condense_memory.py +0 -168
  1475. package/src/scripts/bench_drift_check.py +0 -151
  1476. package/src/scripts/bench_per_tool.py +0 -216
  1477. package/src/scripts/bench_rtk_savings.py +0 -320
  1478. package/src/scripts/bench_run.py +0 -272
  1479. package/src/scripts/bench_runner.py +0 -158
  1480. package/src/scripts/build_cloud_bundle.py +0 -458
  1481. package/src/scripts/build_discovery_manifest.py +0 -747
  1482. package/src/scripts/build_linear_digest.py +0 -260
  1483. package/src/scripts/build_mcp_registry_manifest.py +0 -181
  1484. package/src/scripts/build_rule_trigger_matrix.py +0 -350
  1485. package/src/scripts/capture_showcase_session.py +0 -361
  1486. package/src/scripts/chat_history.py +0 -1799
  1487. package/src/scripts/check_always_budget.py +0 -532
  1488. package/src/scripts/check_artefact_checksums.py +0 -111
  1489. package/src/scripts/check_augment_description_cap.py +0 -79
  1490. package/src/scripts/check_augmentignore.py +0 -72
  1491. package/src/scripts/check_beta_review_markers.py +0 -127
  1492. package/src/scripts/check_bite_sized_granularity.py +0 -99
  1493. package/src/scripts/check_cluster_patterns.py +0 -206
  1494. package/src/scripts/check_command_count_messaging.py +0 -152
  1495. package/src/scripts/check_condensation.py +0 -375
  1496. package/src/scripts/check_condensed_paths.py +0 -231
  1497. package/src/scripts/check_context_paths.py +0 -202
  1498. package/src/scripts/check_council_layout.py +0 -125
  1499. package/src/scripts/check_council_references.py +0 -228
  1500. package/src/scripts/check_discovery_determinism.py +0 -70
  1501. package/src/scripts/check_gate_paths.py +0 -128
  1502. package/src/scripts/check_iron_law_prominence.py +0 -145
  1503. package/src/scripts/check_kernel_rule_bundle.py +0 -151
  1504. package/src/scripts/check_md_language.py +0 -161
  1505. package/src/scripts/check_memory.py +0 -443
  1506. package/src/scripts/check_memory_proposal.py +0 -182
  1507. package/src/scripts/check_module_management_neutral.py +0 -147
  1508. package/src/scripts/check_no_local_settings_committed.py +0 -51
  1509. package/src/scripts/check_no_new_legacy_path.py +0 -100
  1510. package/src/scripts/check_no_roadmap_refs.py +0 -155
  1511. package/src/scripts/check_one_off_location.py +0 -81
  1512. package/src/scripts/check_overlay_cascade_subdirs.py +0 -129
  1513. package/src/scripts/check_portability.py +0 -574
  1514. package/src/scripts/check_proposal.py +0 -269
  1515. package/src/scripts/check_public_catalog_links.py +0 -125
  1516. package/src/scripts/check_public_links.py +0 -185
  1517. package/src/scripts/check_references.py +0 -557
  1518. package/src/scripts/check_release_includes_discovery.py +0 -61
  1519. package/src/scripts/check_release_pr_shape.py +0 -123
  1520. package/src/scripts/check_release_published.py +0 -145
  1521. package/src/scripts/check_release_trunk_sync.py +0 -152
  1522. package/src/scripts/check_reply_consistency.py +0 -169
  1523. package/src/scripts/check_roadmap_trackable.py +0 -114
  1524. package/src/scripts/check_role_doc_links.py +0 -110
  1525. package/src/scripts/check_safety_floor_untouched.py +0 -125
  1526. package/src/scripts/check_skill_requires.py +0 -147
  1527. package/src/scripts/check_template_pin_drift.py +0 -129
  1528. package/src/scripts/check_test_coverage_diff.py +0 -180
  1529. package/src/scripts/check_token_optimizer_freshness.py +0 -146
  1530. package/src/scripts/check_update_banner.py +0 -86
  1531. package/src/scripts/ci_status.py +0 -301
  1532. package/src/scripts/ci_summary.py +0 -131
  1533. package/src/scripts/ci_time_ratio.py +0 -168
  1534. package/src/scripts/command_suggester/__init__.py +0 -51
  1535. package/src/scripts/command_suggester/cooldown.py +0 -132
  1536. package/src/scripts/command_suggester/loader.py +0 -73
  1537. package/src/scripts/command_suggester/match.py +0 -180
  1538. package/src/scripts/command_suggester/rank.py +0 -120
  1539. package/src/scripts/command_suggester/render.py +0 -86
  1540. package/src/scripts/command_suggester/sanitize.py +0 -113
  1541. package/src/scripts/command_suggester/settings.py +0 -127
  1542. package/src/scripts/command_suggester/types.py +0 -78
  1543. package/src/scripts/compile_router.py +0 -232
  1544. package/src/scripts/condense.py +0 -1919
  1545. package/src/scripts/condense_memory.py +0 -178
  1546. package/src/scripts/config/__init__.py +0 -9
  1547. package/src/scripts/config/packs.py +0 -157
  1548. package/src/scripts/config/presets.py +0 -224
  1549. package/src/scripts/config/profile_explain.py +0 -89
  1550. package/src/scripts/config/profiles.py +0 -191
  1551. package/src/scripts/config/session_profiles.py +0 -542
  1552. package/src/scripts/context_hygiene_hook.py +0 -181
  1553. package/src/scripts/cost_by_conversation.py +0 -78
  1554. package/src/scripts/cost_summary.py +0 -97
  1555. package/src/scripts/council_cli.py +0 -2557
  1556. package/src/scripts/council_prune.py +0 -81
  1557. package/src/scripts/cross_repo_retrieve.py +0 -172
  1558. package/src/scripts/discovery_stats.py +0 -70
  1559. package/src/scripts/extract_audit_patterns.py +0 -202
  1560. package/src/scripts/first_run_gate_hook.py +0 -179
  1561. package/src/scripts/gen_discovery_baseline.py +0 -127
  1562. package/src/scripts/generate_catalog.py +0 -116
  1563. package/src/scripts/generate_command_flows.py +0 -191
  1564. package/src/scripts/generate_index.py +0 -303
  1565. package/src/scripts/generate_ownership_matrix.py +0 -378
  1566. package/src/scripts/generate_pack_manifests.py +0 -340
  1567. package/src/scripts/hooks/__init__.py +0 -1
  1568. package/src/scripts/hooks/dispatch_hook.py +0 -461
  1569. package/src/scripts/hooks/dispatch_issues.py +0 -136
  1570. package/src/scripts/hooks/envelope.py +0 -98
  1571. package/src/scripts/hooks/replay_hook.py +0 -144
  1572. package/src/scripts/hooks/state_io.py +0 -145
  1573. package/src/scripts/hooks_doctor.py +0 -223
  1574. package/src/scripts/hooks_status.py +0 -157
  1575. package/src/scripts/install.py +0 -5183
  1576. package/src/scripts/inventory_abstraction_budget.py +0 -622
  1577. package/src/scripts/inventory_frontmatter.py +0 -164
  1578. package/src/scripts/inventory_meta_layers.py +0 -288
  1579. package/src/scripts/iron_law_sha.py +0 -107
  1580. package/src/scripts/linked_projects_list.py +0 -91
  1581. package/src/scripts/lint_agent_skill_names.py +0 -150
  1582. package/src/scripts/lint_agents_layout.py +0 -197
  1583. package/src/scripts/lint_agents_md.py +0 -210
  1584. package/src/scripts/lint_archived_skills.py +0 -159
  1585. package/src/scripts/lint_artefact_frontmatter.py +0 -188
  1586. package/src/scripts/lint_bench_ab.py +0 -172
  1587. package/src/scripts/lint_bench_corpus.py +0 -255
  1588. package/src/scripts/lint_command_flow_coverage.py +0 -132
  1589. package/src/scripts/lint_command_routing.py +0 -160
  1590. package/src/scripts/lint_command_tiers.py +0 -175
  1591. package/src/scripts/lint_command_verbs.py +0 -206
  1592. package/src/scripts/lint_commit_subjects.py +0 -139
  1593. package/src/scripts/lint_context_spine_usage.py +0 -137
  1594. package/src/scripts/lint_discovery_manifest.py +0 -176
  1595. package/src/scripts/lint_discovery_vocabulary.py +0 -220
  1596. package/src/scripts/lint_examples.py +0 -102
  1597. package/src/scripts/lint_explain_trace.py +0 -80
  1598. package/src/scripts/lint_featured_skills.py +0 -144
  1599. package/src/scripts/lint_flows.py +0 -215
  1600. package/src/scripts/lint_framework_leakage.py +0 -375
  1601. package/src/scripts/lint_frontmatter_boilerplate.py +0 -77
  1602. package/src/scripts/lint_ghostwriter_source.py +0 -242
  1603. package/src/scripts/lint_global_paths.py +0 -148
  1604. package/src/scripts/lint_handoffs.py +0 -217
  1605. package/src/scripts/lint_hook_concern_budget.py +0 -207
  1606. package/src/scripts/lint_hook_manifest.py +0 -217
  1607. package/src/scripts/lint_load_context.py +0 -196
  1608. package/src/scripts/lint_marketplace.py +0 -180
  1609. package/src/scripts/lint_marketplace_install_completeness.py +0 -198
  1610. package/src/scripts/lint_mcp_registry_manifest.py +0 -69
  1611. package/src/scripts/lint_media_policy_linkage.py +0 -140
  1612. package/src/scripts/lint_model_tier_coverage.py +0 -73
  1613. package/src/scripts/lint_namespace.py +0 -135
  1614. package/src/scripts/lint_namespace_collisions.py +0 -103
  1615. package/src/scripts/lint_new_skill_gate.py +0 -144
  1616. package/src/scripts/lint_no_new_atomic_commands.py +0 -180
  1617. package/src/scripts/lint_one_off_age.py +0 -184
  1618. package/src/scripts/lint_orchestration_dsl.py +0 -217
  1619. package/src/scripts/lint_orchestrator_auto_detect.py +0 -111
  1620. package/src/scripts/lint_pack_boundaries.py +0 -147
  1621. package/src/scripts/lint_pack_dependencies.py +0 -137
  1622. package/src/scripts/lint_pack_first_win.py +0 -121
  1623. package/src/scripts/lint_persona_governance.py +0 -164
  1624. package/src/scripts/lint_positioning.py +0 -143
  1625. package/src/scripts/lint_profile_overlay_set_only.py +0 -179
  1626. package/src/scripts/lint_readme_jargon.py +0 -131
  1627. package/src/scripts/lint_readme_size.py +0 -33
  1628. package/src/scripts/lint_regression.py +0 -251
  1629. package/src/scripts/lint_roadmap_ci_steps.py +0 -186
  1630. package/src/scripts/lint_roadmap_complexity.py +0 -220
  1631. package/src/scripts/lint_role_experiences.py +0 -255
  1632. package/src/scripts/lint_rule_interactions.py +0 -170
  1633. package/src/scripts/lint_rule_tiers.py +0 -90
  1634. package/src/scripts/lint_showcase_sessions.py +0 -148
  1635. package/src/scripts/lint_skill_tools.py +0 -168
  1636. package/src/scripts/lint_topics_yaml.py +0 -89
  1637. package/src/scripts/lint_trust_coherence.py +0 -212
  1638. package/src/scripts/lint_value_dashboard.py +0 -218
  1639. package/src/scripts/mcp_parity_smoke.py +0 -316
  1640. package/src/scripts/mcp_render.py +0 -173
  1641. package/src/scripts/mcp_server/__init__.py +0 -19
  1642. package/src/scripts/mcp_server/__main__.py +0 -12
  1643. package/src/scripts/mcp_server/catalog.py +0 -125
  1644. package/src/scripts/mcp_server/metadata.py +0 -75
  1645. package/src/scripts/mcp_server/prompts.py +0 -442
  1646. package/src/scripts/mcp_server/requirements.txt +0 -4
  1647. package/src/scripts/mcp_server/resources.py +0 -201
  1648. package/src/scripts/mcp_server/server.py +0 -270
  1649. package/src/scripts/mcp_server/telemetry.py +0 -128
  1650. package/src/scripts/mcp_server/tools.py +0 -950
  1651. package/src/scripts/mcp_telemetry_health.py +0 -214
  1652. package/src/scripts/mcp_telemetry_query.py +0 -203
  1653. package/src/scripts/mcp_telemetry_store.py +0 -211
  1654. package/src/scripts/measure_augment_budget.py +0 -214
  1655. package/src/scripts/measure_density.py +0 -232
  1656. package/src/scripts/measure_frugality_savings.py +0 -164
  1657. package/src/scripts/measure_markitdown_lift.py +0 -127
  1658. package/src/scripts/measure_patterns.py +0 -376
  1659. package/src/scripts/measure_projection_bytes.py +0 -159
  1660. package/src/scripts/measure_rule_budget.py +0 -347
  1661. package/src/scripts/measure_skill_reduction.py +0 -102
  1662. package/src/scripts/memory_hash.py +0 -75
  1663. package/src/scripts/memory_lookup.py +0 -705
  1664. package/src/scripts/memory_report.py +0 -336
  1665. package/src/scripts/memory_signal.py +0 -212
  1666. package/src/scripts/memory_status.py +0 -257
  1667. package/src/scripts/migrate_command_suggestions.py +0 -151
  1668. package/src/scripts/migrate_frontmatter_defaults.py +0 -245
  1669. package/src/scripts/mine_session.py +0 -279
  1670. package/src/scripts/minimal_safe_diff_hook.py +0 -245
  1671. package/src/scripts/move_artefact.py +0 -143
  1672. package/src/scripts/new_skill.py +0 -148
  1673. package/src/scripts/onboarding_gate_hook.py +0 -142
  1674. package/src/scripts/pack_mcp_content.py +0 -293
  1675. package/src/scripts/plan_physical_move.py +0 -353
  1676. package/src/scripts/prediction-pool/poisson_sim.py +0 -167
  1677. package/src/scripts/prediction-pool/pool_winsim.py +0 -236
  1678. package/src/scripts/prediction-pool/score_ev.py +0 -188
  1679. package/src/scripts/print_required_checks.py +0 -196
  1680. package/src/scripts/probe_projection_fidelity.py +0 -202
  1681. package/src/scripts/probe_skill_registration.py +0 -413
  1682. package/src/scripts/profile_staleness_hook.py +0 -69
  1683. package/src/scripts/profile_use.py +0 -164
  1684. package/src/scripts/project_thin_rules.py +0 -168
  1685. package/src/scripts/propose_modules_config.py +0 -145
  1686. package/src/scripts/prototype_lint_contradictions.py +0 -150
  1687. package/src/scripts/prove_pack_extractable.py +0 -187
  1688. package/src/scripts/readme_linter.py +0 -589
  1689. package/src/scripts/redact_hook_capture.py +0 -148
  1690. package/src/scripts/refine_ticket_detect.py +0 -646
  1691. package/src/scripts/release.py +0 -1091
  1692. package/src/scripts/render_benchmark_md.py +0 -312
  1693. package/src/scripts/render_value_md.py +0 -347
  1694. package/src/scripts/requirements-evals.txt +0 -8
  1695. package/src/scripts/roadmap_progress_hook.py +0 -274
  1696. package/src/scripts/router_telemetry.py +0 -470
  1697. package/src/scripts/run_skill_evals.py +0 -185
  1698. package/src/scripts/runtime_dispatcher.py +0 -276
  1699. package/src/scripts/runtime_handler.py +0 -148
  1700. package/src/scripts/runtime_registry.py +0 -166
  1701. package/src/scripts/score_skill_selection.py +0 -198
  1702. package/src/scripts/setup_eval_venv.sh +0 -58
  1703. package/src/scripts/skill_collision_clusters.py +0 -162
  1704. package/src/scripts/skill_discovery.py +0 -254
  1705. package/src/scripts/skill_linter.py +0 -3694
  1706. package/src/scripts/skill_overlap.py +0 -204
  1707. package/src/scripts/skill_preview.py +0 -179
  1708. package/src/scripts/skill_tools/__init__.py +0 -22
  1709. package/src/scripts/skill_tools/audit_persona_coverage.py +0 -147
  1710. package/src/scripts/skill_tools/audit_user_type_coverage.py +0 -148
  1711. package/src/scripts/skill_tools/run_block_d_eval.py +0 -129
  1712. package/src/scripts/skill_tools/score_skill_relevance.py +0 -169
  1713. package/src/scripts/skill_tools/suggest_skill_for_task.py +0 -113
  1714. package/src/scripts/skill_trigger_eval.py +0 -682
  1715. package/src/scripts/skill_usage_collect.py +0 -191
  1716. package/src/scripts/skill_usage_report.py +0 -162
  1717. package/src/scripts/smoke_path_resolution.py +0 -93
  1718. package/src/scripts/smoke_quickstart.py +0 -144
  1719. package/src/scripts/snapshot_agent_outputs.py +0 -144
  1720. package/src/scripts/spotcheck_thin_root.py +0 -134
  1721. package/src/scripts/sync_agent_settings.py +0 -180
  1722. package/src/scripts/sync_github_metadata.py +0 -147
  1723. package/src/scripts/sync_gitignore.py +0 -291
  1724. package/src/scripts/sync_yaml_rt.py +0 -734
  1725. package/src/scripts/telegraph_stats.py +0 -119
  1726. package/src/scripts/tool_registry.py +0 -146
  1727. package/src/scripts/tools/__init__.py +0 -1
  1728. package/src/scripts/tools/adapter_errors.py +0 -63
  1729. package/src/scripts/tools/base_adapter.py +0 -91
  1730. package/src/scripts/tools/github_adapter.py +0 -128
  1731. package/src/scripts/tools/jira_adapter.py +0 -115
  1732. package/src/scripts/trigger_coverage.py +0 -129
  1733. package/src/scripts/update_counts.py +0 -199
  1734. package/src/scripts/update_prices.py +0 -125
  1735. package/src/scripts/validate_agent_settings.py +0 -124
  1736. package/src/scripts/validate_decision_engine.py +0 -136
  1737. package/src/scripts/validate_discovery_manifest.py +0 -94
  1738. package/src/scripts/validate_frontmatter.py +0 -647
  1739. package/src/scripts/validate_pack_yaml.py +0 -179
  1740. package/src/scripts/validate_safe_paths.py +0 -118
  1741. package/src/scripts/validate_telegraph_carveouts.py +0 -129
  1742. package/src/scripts/verify_before_complete_hook.py +0 -216
  1743. package/src/scripts/verify_physical_move.py +0 -185
  1744. package/src/scripts/wrapper_freshness_hook.py +0 -86
  1745. /package/dist/agent-src/skills/design-intelligence/data/{typography.csv → font-pairings-reference.csv} +0 -0
  1746. /package/src/scripts/{ai-video → media}/lib/fixtures/allin1/analysis.json +0 -0
  1747. /package/src/scripts/{ai-video → media}/lib/fixtures/comfyui/scene-0001.mp4 +0 -0
  1748. /package/src/scripts/{ai-video → media}/lib/fixtures/fal/scene-0001.mp4 +0 -0
  1749. /package/src/scripts/{ai-video → media}/lib/fixtures/gemini-veo/scene-0001.mp4 +0 -0
  1750. /package/src/scripts/{ai-video → media}/lib/fixtures/higgsfield/scene-0001.mp4 +0 -0
  1751. /package/src/scripts/{ai-video → media}/lib/fixtures/kling/scene-0001.mp4 +0 -0
  1752. /package/src/scripts/{ai-video → media}/lib/fixtures/musetalk/lipsync-0001.mp4 +0 -0
  1753. /package/src/scripts/{ai-video → media}/lib/fixtures/openai-images/scene-0001.png +0 -0
  1754. /package/src/scripts/{ai-video → media}/lib/fixtures/replicate/scene-0001.mp4 +0 -0
  1755. /package/src/scripts/{ai-video → media}/lib/fixtures/sora/scene-0001.mp4 +0 -0
  1756. /package/src/scripts/{ai-video → media}/lib/fixtures/syncso/lipsync-0001.mp4 +0 -0
  1757. /package/src/scripts/{ai-video → media}/lib/fixtures/whisperx/transcript.json +0 -0
  1758. /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
+ }