@skathio/somi 4.1.1 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (372) hide show
  1. package/.claude-plugin/icon.png +0 -0
  2. package/.claude-plugin/marketplace.json +8 -3
  3. package/.claude-plugin/plugin.json +9 -10
  4. package/.copilot-extension/extension.json +32 -40
  5. package/.copilot-extension/marketplace.json +8 -3
  6. package/README.md +88 -227
  7. package/VERSION +1 -1
  8. package/agents/somi-reviewer.md +21 -40
  9. package/agents/somi-security-reviewer.md +16 -90
  10. package/agents/somi-worker-high.md +11 -0
  11. package/agents/somi-worker-low.md +11 -0
  12. package/agents/somi-worker-medium.md +11 -0
  13. package/agents/somi.md +8 -75
  14. package/commands/somi-config.md +5 -14
  15. package/commands/somi-deliver.md +11 -0
  16. package/commands/somi-quality.md +10 -0
  17. package/commands/somi-review.md +10 -0
  18. package/commands/somi-status.md +11 -0
  19. package/commands/somi.md +10 -0
  20. package/hooks/hooks.json +29 -23
  21. package/hooks/lib/common.mjs +45 -34
  22. package/hooks/pre-tool/apply-tier.mjs +31 -0
  23. package/hooks/pre-tool/block-dangerous-bash.mjs +15 -0
  24. package/hooks/pre-tool/gate-dep-install.mjs +2 -2
  25. package/hooks/pre-tool/guard-protected-paths.mjs +9 -16
  26. package/hooks/pre-tool/guard-tier-config.mjs +17 -0
  27. package/hooks/pre-tool/reviewers-read-only.mjs +11 -0
  28. package/hooks/session-start/inject-digest.mjs +51 -0
  29. package/hooks/stop/review-due.mjs +44 -0
  30. package/hooks/user-prompt/capture-prompt.mjs +17 -0
  31. package/library/lenses/architecture.md +1 -0
  32. package/library/lenses/test-strategy.md +1 -0
  33. package/library/roles/accessibility.md +1 -0
  34. package/library/roles/answer.md +1 -0
  35. package/library/roles/atlas.md +1 -0
  36. package/library/roles/build.md +1 -0
  37. package/library/roles/debug.md +6 -0
  38. package/library/roles/design.md +1 -0
  39. package/library/roles/discover.md +1 -0
  40. package/library/roles/incident.md +1 -0
  41. package/library/roles/migrate.md +1 -0
  42. package/library/roles/perf.md +1 -0
  43. package/library/roles/plan.md +1 -0
  44. package/library/roles/refactor.md +1 -0
  45. package/library/roles/review.md +1 -0
  46. package/library/roles/security-review.md +1 -0
  47. package/library/roles/upgrade.md +1 -0
  48. package/library/skills/accessibility.md +16 -0
  49. package/library/skills/ci-infra-gotchas.md +12 -0
  50. package/library/skills/perf-method.md +10 -0
  51. package/library/skills/secure-coding.md +18 -0
  52. package/library/skills/testing-checklist.md +16 -0
  53. package/library/skills/threat-modeling.md +10 -0
  54. package/package.json +12 -17
  55. package/profiles/claude.json +21 -0
  56. package/profiles/copilot.json +5 -0
  57. package/rules/digest.md +40 -0
  58. package/scripts/check-links.mjs +65 -76
  59. package/scripts/lib/advisor.mjs +207 -0
  60. package/scripts/lib/check.mjs +167 -0
  61. package/scripts/lib/copilot-workflow.mjs +41 -0
  62. package/scripts/lib/doctor.mjs +91 -0
  63. package/scripts/lib/gates.mjs +69 -0
  64. package/scripts/lib/git-tree.mjs +201 -0
  65. package/scripts/lib/init.mjs +23 -0
  66. package/scripts/lib/ledger.mjs +38 -0
  67. package/scripts/lib/mcp-project-root.mjs +63 -67
  68. package/scripts/lib/migrate.mjs +73 -0
  69. package/scripts/lib/path-facts.mjs +2 -2
  70. package/scripts/lib/path-safety.mjs +6 -134
  71. package/scripts/lib/plan.mjs +69 -0
  72. package/scripts/lib/policy.mjs +103 -0
  73. package/scripts/lib/pr.mjs +28 -0
  74. package/scripts/lib/prompt.mjs +72 -0
  75. package/scripts/lib/quality/clones.mjs +76 -0
  76. package/scripts/lib/quality/css.mjs +43 -0
  77. package/scripts/lib/quality/gate.mjs +230 -0
  78. package/scripts/lib/quality/limits.mjs +97 -0
  79. package/scripts/lib/quality/metrics.mjs +159 -0
  80. package/scripts/lib/quality/parse.mjs +73 -0
  81. package/scripts/lib/quality/repo.mjs +69 -0
  82. package/scripts/lib/quality/run.mjs +58 -0
  83. package/scripts/lib/reviews.mjs +132 -0
  84. package/scripts/lib/routes.mjs +108 -0
  85. package/scripts/lib/setup.mjs +34 -0
  86. package/scripts/lib/shards.mjs +166 -0
  87. package/scripts/lib/signals.mjs +110 -0
  88. package/scripts/lib/state.mjs +42 -0
  89. package/scripts/lib/tiers.mjs +42 -0
  90. package/scripts/lib/update-notice.mjs +48 -0
  91. package/scripts/lib/views.mjs +62 -0
  92. package/scripts/lib/workflows.mjs +56 -0
  93. package/scripts/somi-mcp.mjs +182 -323
  94. package/scripts/somi.mjs +208 -0
  95. package/scripts/vendor/tree-sitter/LICENSE.vscode-tree-sitter-wasm +21 -0
  96. package/scripts/vendor/tree-sitter/LICENSE.web-tree-sitter +21 -0
  97. package/scripts/vendor/tree-sitter/cgmanifest.vscode-tree-sitter-wasm.json +16 -0
  98. package/scripts/vendor/tree-sitter/manifest.json +59 -0
  99. package/scripts/vendor/tree-sitter/package.json +3 -0
  100. package/scripts/vendor/tree-sitter/tree-sitter-css.wasm +0 -0
  101. package/scripts/vendor/tree-sitter/tree-sitter-javascript.wasm +0 -0
  102. package/scripts/vendor/tree-sitter/tree-sitter-tsx.wasm +0 -0
  103. package/scripts/vendor/tree-sitter/tree-sitter-typescript.wasm +0 -0
  104. package/scripts/vendor/tree-sitter/web-tree-sitter.js +4081 -0
  105. package/scripts/vendor/tree-sitter/web-tree-sitter.wasm +0 -0
  106. package/skills/somi-expertise/SKILL.md +6 -0
  107. package/workflows/deliver-stages.js +81 -0
  108. package/.claude/settings.json +0 -131
  109. package/agents/somi-architecture-reviewer.md +0 -101
  110. package/agents/somi-atlas.md +0 -100
  111. package/agents/somi-coder.md +0 -60
  112. package/agents/somi-designer.md +0 -36
  113. package/agents/somi-discovery-analyst.md +0 -57
  114. package/agents/somi-flow.md +0 -47
  115. package/agents/somi-general.md +0 -36
  116. package/agents/somi-impact.md +0 -95
  117. package/agents/somi-incident.md +0 -94
  118. package/agents/somi-plan-reviewer.md +0 -68
  119. package/agents/somi-planner.md +0 -57
  120. package/agents/somi-pr.md +0 -99
  121. package/agents/somi-refactor-designer.md +0 -81
  122. package/agents/somi-refactorer.md +0 -99
  123. package/agents/somi-sdlc-reviewer.md +0 -67
  124. package/agents/somi-test-strategist.md +0 -87
  125. package/commands/adopt.md +0 -14
  126. package/commands/architecture-review.md +0 -19
  127. package/commands/atlas.md +0 -19
  128. package/commands/code-loop.md +0 -19
  129. package/commands/code-parallel.md +0 -19
  130. package/commands/code.md +0 -19
  131. package/commands/debug.md +0 -19
  132. package/commands/design.md +0 -19
  133. package/commands/discover.md +0 -19
  134. package/commands/impact.md +0 -19
  135. package/commands/incident.md +0 -19
  136. package/commands/plan-loop.md +0 -19
  137. package/commands/plan.md +0 -19
  138. package/commands/pr.md +0 -19
  139. package/commands/refactor-design.md +0 -19
  140. package/commands/refactor.md +0 -19
  141. package/commands/release-readiness.md +0 -19
  142. package/commands/review-panel.md +0 -19
  143. package/commands/review.md +0 -19
  144. package/commands/security-review.md +0 -19
  145. package/commands/ship-loop.md +0 -19
  146. package/commands/ship.md +0 -19
  147. package/commands/test-strategy.md +0 -19
  148. package/commands/upgrade.md +0 -19
  149. package/examples/README.md +0 -19
  150. package/examples/code-review-example.md +0 -88
  151. package/examples/discovery-example.md +0 -200
  152. package/examples/feature-plan-example.md +0 -377
  153. package/examples/full-pipeline-example.md +0 -188
  154. package/examples/sample-consumer/.claude/settings.json +0 -29
  155. package/examples/sample-consumer/CLAUDE.md +0 -78
  156. package/examples/sample-consumer/README.md +0 -102
  157. package/hooks/post-tool/lint-changed-files.mjs +0 -209
  158. package/hooks/pre-tool/guard-cost-lowering.mjs +0 -192
  159. package/hooks/session-start/detect-repo-instructions.mjs +0 -287
  160. package/hooks/session-start/ensure-default-config.mjs +0 -113
  161. package/hooks/user-prompt-submit/inject-workflow-context.mjs +0 -580
  162. package/rules/00-priorities.md +0 -48
  163. package/rules/10-solid.md +0 -87
  164. package/rules/20-clean-code.md +0 -62
  165. package/rules/30-security-owasp.md +0 -83
  166. package/rules/40-engineering-practices.md +0 -65
  167. package/rules/50-collaboration.md +0 -114
  168. package/rules/99-overrides.md +0 -52
  169. package/rules/CLAUDE.md +0 -200
  170. package/scripts/check-session-artefacts.mjs +0 -149
  171. package/scripts/check-size-budget.mjs +0 -137
  172. package/scripts/generate-digest.mjs +0 -176
  173. package/scripts/lib/agent-info.mjs +0 -85
  174. package/scripts/lib/agent-registry.mjs +0 -92
  175. package/scripts/lib/cost-ceiling.mjs +0 -328
  176. package/scripts/lib/cost-config-edit.mjs +0 -102
  177. package/scripts/lib/cost-config.mjs +0 -64
  178. package/scripts/lib/cost-defaults.mjs +0 -53
  179. package/scripts/lib/cost-lowering.mjs +0 -89
  180. package/scripts/lib/cost-model.mjs +0 -110
  181. package/scripts/lib/dispatch-resolver.mjs +0 -243
  182. package/scripts/lib/escalation-facts.mjs +0 -146
  183. package/scripts/lib/escalation.mjs +0 -129
  184. package/scripts/lib/findings-ledger.mjs +0 -241
  185. package/scripts/lib/install-text.mjs +0 -97
  186. package/scripts/lib/loop-caps.mjs +0 -140
  187. package/scripts/lib/loop-diff.mjs +0 -38
  188. package/scripts/lib/loop-dispatch.mjs +0 -19
  189. package/scripts/lib/loop-engine.mjs +0 -227
  190. package/scripts/lib/loop-escalate.mjs +0 -49
  191. package/scripts/lib/loop-exit.mjs +0 -47
  192. package/scripts/lib/loop-notes-compact.mjs +0 -72
  193. package/scripts/lib/loop-notes.mjs +0 -282
  194. package/scripts/lib/loop-review.mjs +0 -395
  195. package/scripts/lib/loop-state.mjs +0 -44
  196. package/scripts/lib/loop-step-close.mjs +0 -75
  197. package/scripts/lib/loop-step-kit.mjs +0 -179
  198. package/scripts/lib/loop-step-review.mjs +0 -140
  199. package/scripts/lib/loop-step-tool.mjs +0 -89
  200. package/scripts/lib/loop-step.mjs +0 -303
  201. package/scripts/lib/run-budget.mjs +0 -28
  202. package/scripts/lib/run-card.mjs +0 -73
  203. package/scripts/lib/size-tier.mjs +0 -184
  204. package/scripts/lib/tier-record.mjs +0 -82
  205. package/scripts/size-budget-overrides.json +0 -58
  206. package/scripts/somi-card.mjs +0 -39
  207. package/scripts/somi-check.mjs +0 -237
  208. package/scripts/somi-config.mjs +0 -421
  209. package/scripts/somi-dispatch.mjs +0 -141
  210. package/scripts/somi-findings.mjs +0 -100
  211. package/scripts/somi-loop.mjs +0 -139
  212. package/scripts/somi-tier.mjs +0 -393
  213. package/scripts/validate.sh +0 -653
  214. package/skills/api-design/SKILL.md +0 -147
  215. package/skills/clean-code/SKILL.md +0 -142
  216. package/skills/flow-adopt/SKILL.md +0 -92
  217. package/skills/flow-architecture-review/SKILL.md +0 -94
  218. package/skills/flow-atlas/SKILL.md +0 -34
  219. package/skills/flow-code/SKILL.md +0 -167
  220. package/skills/flow-code-loop/SKILL.md +0 -263
  221. package/skills/flow-code-parallel/SKILL.md +0 -160
  222. package/skills/flow-debug/SKILL.md +0 -141
  223. package/skills/flow-design/SKILL.md +0 -170
  224. package/skills/flow-discover/SKILL.md +0 -204
  225. package/skills/flow-impact/SKILL.md +0 -35
  226. package/skills/flow-incident/SKILL.md +0 -49
  227. package/skills/flow-plan/SKILL.md +0 -254
  228. package/skills/flow-plan-loop/SKILL.md +0 -254
  229. package/skills/flow-pr/SKILL.md +0 -34
  230. package/skills/flow-refactor/SKILL.md +0 -58
  231. package/skills/flow-refactor-design/SKILL.md +0 -97
  232. package/skills/flow-release-readiness/SKILL.md +0 -82
  233. package/skills/flow-review/SKILL.md +0 -193
  234. package/skills/flow-review-panel/SKILL.md +0 -154
  235. package/skills/flow-security-review/SKILL.md +0 -83
  236. package/skills/flow-ship/SKILL.md +0 -125
  237. package/skills/flow-ship-loop/SKILL.md +0 -274
  238. package/skills/flow-somi-config/SKILL.md +0 -142
  239. package/skills/flow-status/SKILL.md +0 -43
  240. package/skills/flow-test-strategy/SKILL.md +0 -83
  241. package/skills/flow-upgrade/SKILL.md +0 -82
  242. package/skills/market-research/SKILL.md +0 -125
  243. package/skills/observability/SKILL.md +0 -133
  244. package/skills/owasp-defense/SKILL.md +0 -141
  245. package/skills/plan-review/SKILL.md +0 -83
  246. package/skills/reasoning-craft/SKILL.md +0 -213
  247. package/skills/requirements-engineering/SKILL.md +0 -137
  248. package/skills/role-coder/SKILL.md +0 -247
  249. package/skills/role-designer/SKILL.md +0 -172
  250. package/skills/role-discovery-analyst/SKILL.md +0 -288
  251. package/skills/role-planner/SKILL.md +0 -353
  252. package/skills/role-reviewer/SKILL.md +0 -218
  253. package/skills/rules/SKILL.md +0 -47
  254. package/skills/sdlc-process/SKILL.md +0 -74
  255. package/skills/solid-principles/SKILL.md +0 -143
  256. package/skills/somi-checkpoint/SKILL.md +0 -95
  257. package/skills/somi-dispatch/SKILL.md +0 -259
  258. package/skills/somi-routing/SKILL.md +0 -158
  259. package/skills/testing-playbook/SKILL.md +0 -133
  260. package/skills/threat-modeling/SKILL.md +0 -117
  261. package/templates/ADR.md.tmpl +0 -73
  262. package/templates/ATLAS.md.tmpl +0 -75
  263. package/templates/BRD.md.tmpl +0 -68
  264. package/templates/BRIEF.md.tmpl +0 -119
  265. package/templates/CONTEXT.md.tmpl +0 -74
  266. package/templates/DECISIONS.md.tmpl +0 -105
  267. package/templates/DESIGN.md.tmpl +0 -83
  268. package/templates/DIARY.md.tmpl +0 -70
  269. package/templates/DOD.md.tmpl +0 -90
  270. package/templates/FRD.md.tmpl +0 -64
  271. package/templates/PHASE.md.tmpl +0 -80
  272. package/templates/PROGRESS.md.tmpl +0 -63
  273. package/templates/RCA.md.tmpl +0 -53
  274. package/templates/RD-README.md.tmpl +0 -70
  275. package/templates/RESEARCH.md.tmpl +0 -96
  276. package/templates/REVIEW.md.tmpl +0 -82
  277. package/templates/SDD.md.tmpl +0 -82
  278. package/templates/SOMI-README.md.tmpl +0 -83
  279. package/templates/SPEC.md.tmpl +0 -123
  280. package/templates/SRS.md.tmpl +0 -85
  281. package/templates/TDD.md.tmpl +0 -77
  282. package/tests/hooks/cases/audit-log.json +0 -21
  283. package/tests/hooks/cases/block-dangerous-bash.json +0 -166
  284. package/tests/hooks/cases/block-secret-writes.json +0 -140
  285. package/tests/hooks/cases/detect-repo-instructions.json +0 -105
  286. package/tests/hooks/cases/gate-dep-install.json +0 -42
  287. package/tests/hooks/cases/guard-protected-paths.json +0 -222
  288. package/tests/hooks/cases/inject-workflow-context.json +0 -239
  289. package/tests/hooks/cases/lint-changed-files.json +0 -120
  290. package/tests/hooks/run.sh +0 -392
  291. package/tests/scripts/agent-model-frontmatter.sh +0 -38
  292. package/tests/scripts/agent-names.sh +0 -77
  293. package/tests/scripts/check-frontmatter.sh +0 -37
  294. package/tests/scripts/check-links.sh +0 -105
  295. package/tests/scripts/check-session-artefacts.sh +0 -60
  296. package/tests/scripts/check-size-budget.sh +0 -71
  297. package/tests/scripts/checkpoint-gate.sh +0 -131
  298. package/tests/scripts/convergence-runner.sh +0 -1514
  299. package/tests/scripts/cost-ceiling.sh +0 -255
  300. package/tests/scripts/cost-defaults.sh +0 -130
  301. package/tests/scripts/cost-hardcap.sh +0 -338
  302. package/tests/scripts/cost-lowering.sh +0 -261
  303. package/tests/scripts/cost-model.sh +0 -196
  304. package/tests/scripts/dispatch-guard.sh +0 -108
  305. package/tests/scripts/dispatch-line-gate.sh +0 -61
  306. package/tests/scripts/dispatch-reference-gate.sh +0 -173
  307. package/tests/scripts/ensure-default-config.sh +0 -162
  308. package/tests/scripts/escalation.sh +0 -409
  309. package/tests/scripts/eval-runner.sh +0 -3692
  310. package/tests/scripts/evals-packaging.sh +0 -224
  311. package/tests/scripts/fact-sheet.sh +0 -296
  312. package/tests/scripts/fixtures/legacy-shard-no-schema.json +0 -50
  313. package/tests/scripts/fixtures/mock-stdin-read-throw.cjs +0 -18
  314. package/tests/scripts/fixtures/size-tier-cases.json +0 -87
  315. package/tests/scripts/generate-digest.sh +0 -180
  316. package/tests/scripts/global-config.sh +0 -167
  317. package/tests/scripts/goldens/loop-state-breach.json +0 -1
  318. package/tests/scripts/goldens/loop-state-done.json +0 -1
  319. package/tests/scripts/goldens/somi-findings.json +0 -336
  320. package/tests/scripts/goldens/somi-loop.json +0 -168
  321. package/tests/scripts/lib/adr-shape.mjs +0 -41
  322. package/tests/scripts/lib/agent-registry-tests.mjs +0 -95
  323. package/tests/scripts/lib/brief-only-guard.mjs +0 -27
  324. package/tests/scripts/lib/checkpoint-gate.mjs +0 -91
  325. package/tests/scripts/lib/digest-marker-coupling.mjs +0 -52
  326. package/tests/scripts/lib/dispatch-reference-gate.mjs +0 -121
  327. package/tests/scripts/lib/escalation-facts-tests.mjs +0 -140
  328. package/tests/scripts/lib/escalation-tests.mjs +0 -154
  329. package/tests/scripts/lib/findings-ledger-tests.mjs +0 -118
  330. package/tests/scripts/lib/loop-engine-tests.mjs +0 -287
  331. package/tests/scripts/lib/loop-escalate-tests.mjs +0 -356
  332. package/tests/scripts/lib/loop-flow-gate.mjs +0 -173
  333. package/tests/scripts/lib/loop-notes-tests.mjs +0 -384
  334. package/tests/scripts/lib/loop-step-cli-tests.mjs +0 -156
  335. package/tests/scripts/lib/loop-step-close-tests.mjs +0 -351
  336. package/tests/scripts/lib/loop-step-lenient-tests.mjs +0 -114
  337. package/tests/scripts/lib/loop-step-state-tests.mjs +0 -127
  338. package/tests/scripts/lib/loop-step-tests.mjs +0 -499
  339. package/tests/scripts/lib/loop-step-unwritten-tests.mjs +0 -55
  340. package/tests/scripts/lib/multipass-dependence.mjs +0 -192
  341. package/tests/scripts/lib/multipass-source-identity.mjs +0 -243
  342. package/tests/scripts/lib/path-facts-tests.mjs +0 -198
  343. package/tests/scripts/lib/path-safety-tests.mjs +0 -201
  344. package/tests/scripts/lib/reference-pair.mjs +0 -61
  345. package/tests/scripts/lib/retirement-gate.mjs +0 -172
  346. package/tests/scripts/lib/run-suites.mjs +0 -139
  347. package/tests/scripts/lib/shell-embedded-js.mjs +0 -47
  348. package/tests/scripts/lib/ship-loop-sizing-guard.mjs +0 -52
  349. package/tests/scripts/lib/site-roadmap-gate.mjs +0 -64
  350. package/tests/scripts/lib/size-tier-drift.mjs +0 -74
  351. package/tests/scripts/lib/sizing-score-tests.mjs +0 -210
  352. package/tests/scripts/lib/sizing-set-tests.mjs +0 -131
  353. package/tests/scripts/lib/somi-mcp-client.mjs +0 -102
  354. package/tests/scripts/lib/somi-mcp-config-tests.mjs +0 -92
  355. package/tests/scripts/lib/somi-mcp-loop-tests.mjs +0 -226
  356. package/tests/scripts/lib/somi-mcp-tests.mjs +0 -491
  357. package/tests/scripts/lib/somi-mcp-tier-tests.mjs +0 -64
  358. package/tests/scripts/lib/somi-mcp-tool-schema.mjs +0 -38
  359. package/tests/scripts/loop-engine.sh +0 -22
  360. package/tests/scripts/loop-flow-gate.sh +0 -11
  361. package/tests/scripts/retirement-gate.sh +0 -306
  362. package/tests/scripts/review-panel-seats.sh +0 -32
  363. package/tests/scripts/run-card.sh +0 -57
  364. package/tests/scripts/run-suites.sh +0 -74
  365. package/tests/scripts/run.sh +0 -689
  366. package/tests/scripts/site-roadmap-gate.sh +0 -76
  367. package/tests/scripts/size-tier.sh +0 -562
  368. package/tests/scripts/somi-agent-dispatch-contract.sh +0 -224
  369. package/tests/scripts/somi-config.sh +0 -286
  370. package/tests/scripts/somi-dispatch.sh +0 -465
  371. package/tests/scripts/somi-mcp.sh +0 -15
  372. package/tests/scripts/suite-plan.json +0 -20
package/rules/CLAUDE.md DELETED
@@ -1,200 +0,0 @@
1
- # Engineering OS — Global Rules
2
-
3
- You are operating inside a project that has adopted **somi (SOMI)**. The rules in this file
4
- apply to **every workflow** (discovery, planning, coding, reviewing) and to **every agent**. They compose all numbered
5
- rule files in `rules/` into one canonical instruction set.
6
-
7
- > **If anything in this file conflicts with a downstream project's own `CLAUDE.md` or
8
- > `.somi/rules/99-overrides.md`, the project wins.** SOMI provides defaults, not mandates that
9
- > override the human in the loop.
10
-
11
- ---
12
-
13
- ## Conflict resolution (read this first)
14
-
15
- When two rules pull in different directions, resolve in this fixed order:
16
-
17
- 1. **Security** — never sacrifice security to satisfy any other concern.
18
- 2. **Correctness** — wrong code shipped fast is still wrong.
19
- 3. **Maintainability** — the code you write today is read by humans for years.
20
- 4. **Convenience** — only when the first three are satisfied.
21
-
22
- If you are forced to compromise on (3) or (4) to honor (1) or (2), say so explicitly in your output
23
- ("Tradeoff: chose X over Y because …") and surface it to the human. **Never make silent tradeoffs.**
24
-
25
- ---
26
-
27
- ## Always-on digest
28
-
29
- This digest is **always in force** — it is the compressed form of the numbered rule files, enough to
30
- act correctly on the common path without loading all of them. Each line points at the file that holds
31
- the full treatment; read that file when you **enter its domain** (see "How to load the rules" below).
32
-
33
- <!-- digest:start -->
34
- - **Priorities:** security > correctness > maintainability > convenience. Compromise on the lower
35
- only to honor the higher, and say so. ([`00`](./00-priorities.md))
36
- - **Honesty:** identify uncertainty; verify before claiming (read the file, grep the symbol, run the
37
- command); never invent facts to sound confident. ([`00`](./00-priorities.md))
38
- - **Discipline:** read before writing; smallest sufficient change (fix ≠ refactor); no silent
39
- compromises — name every shortcut in plain text. ([`00`](./00-priorities.md), [`20`](./20-clean-code.md))
40
- - **SOLID, in practice:** one reason to change per unit; depend on abstractions at boundaries; keep
41
- interfaces small and caller-shaped; no god objects or `Manager`/`Helper` catch-alls. ([`10`](./10-solid.md))
42
- - **Clean code:** names state intent and don't lie; small functions, one level of abstraction;
43
- comment the *why*, not the *what*; delete dead code rather than commenting it out. ([`20`](./20-clean-code.md))
44
- - **Security floor:** validate untrusted input at the trust boundary; parameterize every sink (SQL,
45
- shell, template, path, HTTP); authorize at the sink; never log secrets; constant-time compare
46
- secrets; fail closed. ([`30`](./30-security-owasp.md))
47
- - **Testing:** risk-driven coverage, not coverage-worship; don't mock what you don't own; tests must
48
- assert behavior and be deterministic. ([`40`](./40-engineering-practices.md))
49
- - **Observability:** structured logs with correlation, low-cardinality metrics, a signal on every
50
- critical path — "what does on-call see at 3am?" ([`40`](./40-engineering-practices.md))
51
- - **Dependencies:** a new dependency is a decision — justify it, check its provenance, don't add one
52
- the hooks would gate. ([`40`](./40-engineering-practices.md))
53
- - **Collaboration:** challenge the premise, not just the architecture; match the answer to the
54
- question; recommend with concrete options, the user decides direction; surface tradeoffs and
55
- blockers in the first line; end with one or two lines: what you skipped or did not check, and any
56
- risk the user must know. ([`50`](./50-collaboration.md))
57
- - **Reasoning craft:** before writing, parse trajectory (what will the reader do with this in 10
58
- minutes; answer the predictable next question now) → shape (choose the deliverable's form before
59
- the words; put the answer first) → verify (mark inference as inference; never trade "I confirmed"
60
- for "should work"). While writing, run four cuts: drift (answering the asked question, not an
61
- easier neighbor), hedge (two qualifiers → commit, or name the deciding variable), horoscope
62
- (delete any sentence true of every project), deletion (cut anything whose removal wouldn't change
63
- what the reader does). At most one metaphor, only if it lets the reader predict something new —
64
- otherwise name the single axis the decision turns on. As stakes rise, get blunter, not more
65
- hedged. ([`50`](./50-collaboration.md))
66
- <!-- digest:end -->
67
-
68
- ## What composes this ruleset
69
-
70
- | File | Purpose |
71
- |----------------------------------------------|---------------------------------------------------------------|
72
- | [`00-priorities.md`](./00-priorities.md) | Core priorities, uncertainty handling, escalation |
73
- | [`10-solid.md`](./10-solid.md) | SOLID principles — operationalized, not abstract |
74
- | [`20-clean-code.md`](./20-clean-code.md) | Naming, functions, comments, structure |
75
- | [`30-security-owasp.md`](./30-security-owasp.md) | OWASP Top 10 defenses + secure-by-default patterns |
76
- | [`40-engineering-practices.md`](./40-engineering-practices.md) | Testing, observability, dependencies, delivery |
77
- | [`50-collaboration.md`](./50-collaboration.md) | Working with humans + handoffs between agents |
78
- | [`99-overrides.md`](./99-overrides.md) | Project escape hatch — starter template shown here; the live copy for a project lives at **`.somi/rules/99-overrides.md`** (never `.claude/` or `.github/`, so it stays neutral across hosts and survives plugin updates). SOMI never modifies it. |
79
-
80
- ### How to load the rules (context discipline)
81
-
82
- The **digest above is always on**. Load the full numbered file when its domain is engaged — the same
83
- on-demand model the skills use — so a long agent run doesn't re-read ~600 lines of rules it isn't
84
- exercising:
85
-
86
- - **`00-priorities.md` and `50-collaboration.md`** — read in full at the start of any workflow; they
87
- govern *how* you work regardless of domain.
88
- - **`10` / `20` / `30` / `40`** — read when you enter their domain: writing or restructuring code
89
- (`10`, `20`), touching a trust boundary or sink (`30`), or shaping tests / observability /
90
- dependencies (`40`). The digest line is enough until then.
91
- - **`.somi/rules/99-overrides.md`** — always check; the project's overrides win over everything here.
92
-
93
- When in doubt, read the file — the digest is a fast path, not a license to skip a rule whose domain
94
- you're clearly in. Skipping a rule whose domain you've entered is a violation of this ruleset.
95
-
96
- ---
97
-
98
- ## Universal behavior
99
-
100
- These apply to every workflow:
101
-
102
- - **Identify uncertainty.** When you do not know something — whether code exists, whether a library behaves
103
- a certain way, whether a constraint applies — say so. Do not invent facts to sound confident.
104
- - **Verify before claiming.** A memory, an old comment, or a familiar pattern is not evidence. Read the file,
105
- grep the symbol, or run the command.
106
- - **Read before writing.** Never edit a file you have not read in this session.
107
- - **Smallest sufficient change.** Bug fix ≠ refactor. Feature ≠ cleanup. Keep diffs scoped.
108
- - **No silent compromises.** If you skip a test, disable a check, or take a shortcut, name it in plain text
109
- in your final message. Hidden shortcuts compound into outages.
110
- - **Respect the plan.** If a work item exists under `.somi/plans/<slug>/`, the coding workflow follows
111
- its `spec.md` and `phases/`. Scope changes go through the plan-change protocol (update
112
- spec/decisions/phases in place, append a diary entry), not silently into the diff.
113
- - **Flag scope creep.** If a request is bigger than it looks, stop and surface the shape before writing code.
114
-
115
- ---
116
-
117
- ## Repo-local instructions and agents (respect as context)
118
-
119
- A repository may ship its own instructions (`CLAUDE.md` root + nested, `AGENTS.md`,
120
- `.github/copilot-instructions.md`, `.cursorrules`) and its own subagents (`.claude/agents/`). SOMI
121
- treats these as **context to respect**, not competition:
122
-
123
- - **Repo-local instructions WIN** over SOMI defaults where they conflict (the project's own
124
- `CLAUDE.md` already wins per the top of this file). Follow the repo's conventions for naming, error
125
- handling, testing, dependencies, and structure.
126
- - **Read them once, carry them forward.** `cost: high` actions (`/discover`, `/design`,
127
- `/refactor-design`, and `/plan` on a cold start) distil the relevant conventions into the work item's
128
- `brief.md` / `context.md` so `cost: medium` (`/plan`, `/code`) inherits them **without
129
- re-reading** — this is part of the design→execution economy. The SessionStart hook surfaces which
130
- files exist.
131
- - **Do NOT auto-invoke the repo's own agents.** Foreign subagents are unknown-quality and
132
- untrusted-by-default; surface that they exist and let the user opt into them. Never call them
133
- silently.
134
-
135
- ---
136
-
137
- ## Workflow gates (enforced by hooks)
138
-
139
- SOMI ships deterministic hooks that enforce a small set of non-negotiables independent of agent judgment:
140
-
141
- - **Dangerous shell commands** (`rm -rf /`, `git push --force` to protected branches, `curl | sh`, …) are blocked.
142
- - **Writes to secret-bearing paths** (`.env`, `*.pem`, `id_rsa`, …) are blocked.
143
- - **Writes to protected paths** (`.git/`, `.claude/`, `node_modules/`, `dist/`, lockfiles when not requested)
144
- are blocked.
145
- - **Audit log** (`.somi/audit.log`) records denied actions for post-hoc review.
146
-
147
- These hooks are guardrails, not policy debates. If a hook blocks you, **do not try to work around it** —
148
- explain what you were trying to do and ask the human.
149
-
150
- See [docs/HOOKS.md](../docs/HOOKS.md) for the full list and how to extend it.
151
-
152
- ---
153
-
154
- ## When to invoke subagents
155
-
156
- SOMI provides specialized agents in `agents/`. Use them when the work matches their description:
157
-
158
- - **`somi-discovery-analyst`** — a new product / greenfield idea needing requirements engineering, competitive research, and high-level design *before* planning (writes `.somi/rd/<slug>/`). Optional and upstream; skip for incremental work with settled requirements. **`cost: high`.**
159
- - **`somi-designer`** — a feature / user story on an existing codebase that is design-heavy (crosses modules, touches auth/crypto/PII, needs a migration or new contract, or the architecture is open). Compiles the design + the `brief.md` execution runs against. Use *before* `/plan` when the architecture isn't settled. **`cost: high`.**
160
- - **`somi-planner`** — before writing non-trivial code, or whenever the user asks "how should we approach X". **`cost: medium`** — consumes the `brief.md` a `cost: high` action left.
161
- - **`somi-coder`** — to execute against an approved plan or do a constrained implementation task.
162
- - **`somi-reviewer`** — before declaring work done; before merging; whenever you want a skeptical second opinion.
163
- - **`somi-security-reviewer`** — auth, crypto, input handling, third-party data, file uploads, anything touching secrets.
164
- - **`somi-architecture-reviewer`** — new modules, new services, contract changes, dependency direction changes.
165
- - **`somi-test-strategist`** — flaky tests, missing coverage, deciding integration vs. unit, mocking decisions.
166
- - **`somi-refactorer`** — when the right move is "untangle this first" rather than "patch around it".
167
-
168
- Full catalogue and escalation rules: [docs/AGENTS.md](../docs/AGENTS.md).
169
-
170
- ---
171
-
172
- ## When to invoke skills
173
-
174
- Skills under `skills/` are on-demand expert packs. Pull one in when the work clearly enters its domain:
175
-
176
- - Researching a software idea (competitors, complaints, failure modes) → **`market-research`**
177
- - Writing/critiquing requirements or design docs (BRD/SRS/FRD/SDD/TDD) → **`requirements-engineering`**
178
- - Touching authentication, sessions, input validation, deserialization → **`owasp-defense`**
179
- - Designing a module, naming a class, deciding what a function should know → **`solid-principles`**, **`clean-code`**
180
- - Deciding what to test, how to test, whether to mock → **`testing-playbook`**
181
- - Adding/changing an HTTP/gRPC endpoint → **`api-design`**
182
- - Adding logging, metrics, tracing → **`observability`**
183
- - Adding a new external integration or attack surface → **`threat-modeling`**
184
- - Wanting the full detector catalog, before/after examples, a worked trace, or the portable voice
185
- spec behind the "Reasoning craft" digest bullet → **`reasoning-craft`**
186
-
187
- Don't invoke skills speculatively — they cost context. Invoke them when the domain is clearly engaged.
188
-
189
- ---
190
-
191
- ## How to fail gracefully
192
-
193
- When you get stuck, the right move is not to ship a half-thing:
194
-
195
- 1. **State what you tried** and what evidence you have.
196
- 2. **State the smallest unblocking question** for the human.
197
- 3. **Propose two options** (with tradeoffs) if you can. Do not propose more than three.
198
- 4. **Stop and wait.** Do not paper over the gap by inventing a defensible-looking diff.
199
-
200
- A clear "I'm blocked because X" is more valuable than 200 lines of speculative code.
@@ -1,149 +0,0 @@
1
- #!/usr/bin/env node
2
- // scripts/check-session-artefacts.mjs — fail the build when shipped code or prose points at the
3
- // maintainers' gitignored `.somi/` planning folder.
4
- //
5
- // A comment that says "see the plan's third decision" or "the review finding numbered 28" is a
6
- // dangling pointer for everyone who clones the repo: the plan and the ledger are not shipped, so
7
- // the reader cannot resolve it. State the reasoning in words instead, or delete the comment.
8
- //
9
- // WHAT COUNTS
10
- // A reference that only resolves inside `.somi/`: a finding id with two or more digits, a decision
11
- // tag, an iteration or phase number from a plan, a `decisions.md#` anchor, a planning-slug name.
12
- // Single-digit finding ids (the CLI usage examples) are domain text and pass.
13
- //
14
- // "phase" and "work item" are deliberately NOT banned as words — they are SoMi product vocabulary
15
- // (a pipeline stage; a planning unit users create). Only a numbered phase/iteration, or the phrase
16
- // "this work item" in a code comment (which can only mean the maintainers' own planning item),
17
- // counts.
18
- //
19
- // WHERE
20
- // - code (`.mjs`, `.sh`) under hooks/ and scripts/: comment text only, so a string literal that
21
- // legitimately mentions a decision tag is not flagged.
22
- // - code under tests/scripts/ too (comments only, as above).
23
- // - markdown under agents/, commands/, skills/, docs/, rules/, templates/: every line, with a narrower pattern, because
24
- // those files teach the plan format and use `D1:` / `phase 1, iteration 1` as sample content.
25
- //
26
- // EXCLUSIONS are explicit and few (EXCLUDED below). To gate another tree, add one SCOPES row.
27
-
28
- import fs from 'node:fs';
29
- import path from 'node:path';
30
-
31
- const FINDING = String.raw`\bF-?\d{2,}\b`;
32
- const DECISION_ANCHOR = String.raw`decisions\.md#`;
33
- const PLAN_SLUG = String.raw`node-runtime-port|somi-3-0-rework`;
34
-
35
- const CODE_PATTERN = new RegExp(
36
- [
37
- FINDING,
38
- String.raw`\bD\d+[a-z]?\b`,
39
- DECISION_ANCHOR,
40
- String.raw`\b[Ii]teration \d`,
41
- String.raw`\b[Pp]hase[ -]\d`,
42
- String.raw`\bphases/\d`,
43
- String.raw`\b\d\.\d+[a-z]?(?:'s)? pass \d`,
44
- String.raw`\b\d\.\d{1,2}[a-z]?'s\b`,
45
- String.raw`\b\d\.\d{1,2}[a-z]?[/+-]\d\.\d{1,2}\b`,
46
- String.raw`\(\d\.\d{1,2}[a-z]?[,)]`,
47
- String.raw`\b(?:this|that) iteration\b`,
48
- String.raw`\breviewer-blessed\b`,
49
- // A pointer ("see the diary") sends the reader into the planning folder; the diary and phase
50
- // files are also product artifacts SoMi's own code describes, so bare mentions are allowed.
51
- String.raw`\bsee (?:the )?(?:diary|phase file)\b`,
52
- String.raw`\b(?:spec|context|brief)\.md §`,
53
- String.raw`\bthis work[ -]item\b`,
54
- PLAN_SLUG,
55
- ].join('|'),
56
- );
57
-
58
- const MARKDOWN_PATTERN = new RegExp(
59
- [
60
- FINDING,
61
- String.raw`\(D\d+[a-z]?\)`,
62
- String.raw`\bD\d+[a-z]?'s\b`,
63
- DECISION_ANCHOR,
64
- PLAN_SLUG,
65
- ].join('|'),
66
- );
67
-
68
- // One row per gated tree. Adding another tree is a one-line change here. Only `.md` is read for
69
- // markdown trees, so `templates/*.tmpl` (which carry sample decision ids for users to copy) is not.
70
- const SCOPES = [
71
- { dir: 'hooks', kind: 'code' },
72
- { dir: 'scripts', kind: 'code' },
73
- { dir: 'agents', kind: 'markdown' },
74
- { dir: 'commands', kind: 'markdown' },
75
- { dir: 'skills', kind: 'markdown' },
76
- { dir: 'tests/scripts', kind: 'code' },
77
- { dir: 'docs', kind: 'markdown' },
78
- { dir: 'rules', kind: 'markdown' },
79
- { dir: 'templates', kind: 'markdown' },
80
- ];
81
-
82
- // Repo-relative paths (file or directory prefix). The checker holds its own pattern definitions.
83
- const EXCLUDED = [
84
- 'scripts/check-session-artefacts.mjs',
85
- 'tests/evals/results',
86
- 'CHANGELOG.md',
87
- ];
88
-
89
- const CODE_EXT = new Set(['.mjs', '.sh']);
90
-
91
- function isExcluded(rel) {
92
- return EXCLUDED.some((e) => rel === e || rel.startsWith(`${e}/`));
93
- }
94
-
95
- function* walk(root, rel) {
96
- const abs = path.join(root, rel);
97
- if (!fs.existsSync(abs)) return;
98
- for (const entry of fs.readdirSync(abs, { withFileTypes: true })) {
99
- if (entry.name === 'node_modules') continue;
100
- const child = path.posix.join(rel, entry.name);
101
- if (isExcluded(child)) continue;
102
- if (entry.isDirectory()) yield* walk(root, child);
103
- else if (entry.isFile()) yield child;
104
- }
105
- }
106
-
107
- function commentText(line, ext) {
108
- const trimmed = line.trim();
109
- if (ext === '.sh') {
110
- if (trimmed.startsWith('#!')) return null;
111
- if (trimmed.startsWith('#')) return trimmed;
112
- const at = line.search(/\s#\s/);
113
- return at === -1 ? null : line.slice(at);
114
- }
115
- if (/^(\/\/|\/\*|\*)/.test(trimmed)) return trimmed;
116
- const at = line.search(/\s\/\/\s/);
117
- return at === -1 ? null : line.slice(at);
118
- }
119
-
120
- export function findArtefacts(root) {
121
- const hits = [];
122
- for (const { dir, kind } of SCOPES) {
123
- for (const rel of walk(root, dir)) {
124
- const ext = path.extname(rel);
125
- if (kind === 'code' && !CODE_EXT.has(ext)) continue;
126
- if (kind === 'markdown' && ext !== '.md') continue;
127
- const lines = fs.readFileSync(path.join(root, rel), 'utf8').split('\n');
128
- lines.forEach((line, i) => {
129
- const text = kind === 'code' ? commentText(line, ext) : line;
130
- const pattern = kind === 'code' ? CODE_PATTERN : MARKDOWN_PATTERN;
131
- if (text !== null && pattern.test(text)) hits.push(`${rel}:${i + 1}: ${line.trim()}`);
132
- });
133
- }
134
- }
135
- return hits;
136
- }
137
-
138
- if (import.meta.url === `file://${process.argv[1]}`) {
139
- const rootIdx = process.argv.indexOf('--root');
140
- const root = rootIdx === -1 ? process.cwd() : path.resolve(process.argv[rootIdx + 1]);
141
- const hits = findArtefacts(root);
142
- if (hits.length > 0) {
143
- console.error('SESSION-ARTEFACT REFERENCES (point into the gitignored .somi/ folder):');
144
- for (const h of hits) console.error(` ${h}`);
145
- console.error(`${hits.length} line(s). Say the reason in plain words, or delete the comment.`);
146
- process.exit(1);
147
- }
148
- console.log(' ok: no session-artefact references in gated paths');
149
- }
@@ -1,137 +0,0 @@
1
- #!/usr/bin/env node
2
- // scripts/check-size-budget.mjs -- fail the build when a tracked file outgrows its line budget.
3
- //
4
- // BUDGETS (lines; one table, BUDGETS below)
5
- // prompt files agents/*.md, commands/*.md, skills/**/*.md 300 (loaded into a model's context
6
- // on every run, so size is cost)
7
- // .mjs any tracked file except tests/evals/results/ 500
8
- // .sh any tracked file 800
9
- // Docs are not gated.
10
- //
11
- // Only tracked files count (`git ls-files`), so untracked scratch never trips the gate.
12
- //
13
- // THE LEDGER: scripts/size-budget-overrides.json
14
- // A file already over budget is recorded there, one entry each, shaped
15
- // `{file, budget, current_size, source, at, reason}` (the same audit idiom as the loop's
16
- // `cap_overrides`). The ledger is tracked so an exemption is reviewable in a diff.
17
- // - An un-ledgered file over budget FAILS.
18
- // - A ledgered file larger than its recorded `current_size` FAILS: the entry exempts the file
19
- // as it is, not as it may become. Shrinking is always fine. Growth means updating the entry
20
- // with a reason a reviewer can challenge.
21
- // - A ledgered file now within budget WARNS (does not fail): delete its entry.
22
- // - A malformed ledger fails loudly (exit 2) rather than being read leniently.
23
- //
24
- // GOVERNANCE
25
- // - Who may add an entry: anyone introducing or materially touching an over-budget file, with a
26
- // concrete `reason` and a `source` (the commit that introduced or last touched it, from
27
- // `git log -1 --format=%h -- <file>`). Never a blanket exemption without attribution.
28
- // - Entries are revisited at every /release-readiness pass.
29
- // - The goal is an empty ledger: shrink or split a file, then remove its entry.
30
- //
31
- // Usage: node scripts/check-size-budget.mjs [--root <dir>]
32
-
33
- import fs from 'node:fs';
34
- import path from 'node:path';
35
- import { execFileSync } from 'node:child_process';
36
-
37
- const LEDGER = 'scripts/size-budget-overrides.json';
38
- const NOT_GATED = ['tests/evals/results/'];
39
-
40
- // First matching row wins. `test` receives the repo-relative posix path.
41
- const BUDGETS = [
42
- { kind: 'prompt', limit: 300, test: (f) => /^(agents|commands)\/[^/]+\.md$/.test(f) || /^skills\/.+\.md$/.test(f) },
43
- { kind: 'mjs', limit: 500, test: (f) => f.endsWith('.mjs') },
44
- { kind: 'sh', limit: 800, test: (f) => f.endsWith('.sh') },
45
- ];
46
-
47
- const ENTRY_FIELDS = { file: 'string', budget: 'number', current_size: 'number', source: 'string', at: 'string', reason: 'string' };
48
-
49
- function fatal(msg) {
50
- console.error(`size-budget: ${msg}`);
51
- process.exit(2);
52
- }
53
-
54
- function budgetFor(file) {
55
- if (NOT_GATED.some((p) => file.startsWith(p))) return null;
56
- return BUDGETS.find((b) => b.test(file)) || null;
57
- }
58
-
59
- function lineCount(abs) {
60
- const text = fs.readFileSync(abs, 'utf8');
61
- if (text === '') return 0;
62
- return text.split('\n').length - (text.endsWith('\n') ? 1 : 0);
63
- }
64
-
65
- function trackedFiles(root) {
66
- try {
67
- const out = execFileSync('git', ['-C', root, 'ls-files', '-z'], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
68
- return out.split('\0').filter(Boolean);
69
- } catch (e) {
70
- return fatal(`cannot enumerate tracked files under ${root}: ${e.message}`);
71
- }
72
- }
73
-
74
- export function loadLedger(root) {
75
- const abs = path.join(root, LEDGER);
76
- if (!fs.existsSync(abs)) return new Map();
77
- let data;
78
- try {
79
- data = JSON.parse(fs.readFileSync(abs, 'utf8'));
80
- } catch (e) {
81
- return fatal(`${LEDGER} is not valid JSON: ${e.message}`);
82
- }
83
- if (!Array.isArray(data)) return fatal(`${LEDGER} must be a JSON array of entries`);
84
- const byFile = new Map();
85
- data.forEach((entry, i) => {
86
- if (entry === null || typeof entry !== 'object' || Array.isArray(entry)) fatal(`${LEDGER}[${i}] is not an object`);
87
- for (const [field, type] of Object.entries(ENTRY_FIELDS)) {
88
- const v = entry[field];
89
- const ok = typeof v === type && (type !== 'string' || v.trim() !== '') && (type !== 'number' || (Number.isInteger(v) && v > 0));
90
- if (!ok) fatal(`${LEDGER}[${i}] needs a ${type === 'number' ? 'positive integer' : 'non-empty string'} "${field}"`);
91
- }
92
- if (byFile.has(entry.file)) fatal(`${LEDGER} lists ${entry.file} twice`);
93
- byFile.set(entry.file, entry);
94
- });
95
- return byFile;
96
- }
97
-
98
- export function checkBudgets(root) {
99
- const ledger = loadLedger(root);
100
- const failures = [];
101
- const warnings = [];
102
- const tracked = new Set(trackedFiles(root));
103
-
104
- for (const file of [...tracked].sort()) {
105
- const budget = budgetFor(file);
106
- if (!budget) continue;
107
- const abs = path.join(root, file);
108
- if (!fs.existsSync(abs)) continue;
109
- const size = lineCount(abs);
110
- const entry = ledger.get(file);
111
- if (size <= budget.limit) {
112
- if (entry) warnings.push(`${file} is ${size} lines, within its ${budget.limit} budget: remove its ledger entry`);
113
- } else if (!entry) {
114
- failures.push(`${file}: ${size} lines exceeds the ${budget.limit}-line ${budget.kind} budget and is not in ${LEDGER}`);
115
- } else if (size > entry.current_size) {
116
- failures.push(`${file}: ${size} lines grew past its ledgered ${entry.current_size}; shrink it, or update the entry with a reason`);
117
- }
118
- }
119
- for (const file of ledger.keys()) {
120
- if (!tracked.has(file)) warnings.push(`${file} is in the ledger but is not a tracked file: remove its entry`);
121
- }
122
- return { failures, warnings, ledgered: ledger.size };
123
- }
124
-
125
- if (import.meta.url === `file://${process.argv[1]}`) {
126
- const rootIdx = process.argv.indexOf('--root');
127
- const root = rootIdx === -1 ? process.cwd() : path.resolve(process.argv[rootIdx + 1]);
128
- const { failures, warnings, ledgered } = checkBudgets(root);
129
- for (const w of warnings) console.warn(` warn: ${w}`);
130
- if (failures.length > 0) {
131
- console.error('FILE-SIZE BUDGET EXCEEDED:');
132
- for (const f of failures) console.error(` ${f}`);
133
- console.error(`${failures.length} file(s). Shrink the file; see the header of scripts/check-size-budget.mjs for the ledger rules.`);
134
- process.exit(1);
135
- }
136
- console.log(` ok: every tracked file is within its size budget (${ledgered} ledgered)`);
137
- }
@@ -1,176 +0,0 @@
1
- #!/usr/bin/env node
2
- // scripts/generate-digest.mjs — regenerate the always-on digest copies from their canonical source.
3
- //
4
- // WHY THIS EXISTS
5
- // The always-on digest lives in three places: rules/CLAUDE.md (canonical), AGENTS.md, and
6
- // .github/copilot-instructions.md. They were hand-synced, and they drifted — the Copilot copy was
7
- // missing the `Reasoning craft` bullet entirely, which `npm test` could not see. Hand-syncing three
8
- // copies is what caused the drift, so this script makes the canonical the only editable one.
9
- //
10
- // WHAT IT DOES
11
- // Reads the bullets between `<!-- digest:start -->` / `<!-- digest:end -->` in the canonical
12
- // file and writes them into each target's own "## Always-on digest" section, adjusting the relative
13
- // link prefix per target's directory depth (see TARGETS below). `--check` exits non-zero on any diff
14
- // instead of writing, for CI (wired into scripts/validate.sh).
15
- //
16
- // THE PREFIX ADJUSTMENT IS NOT THE WHOLE FIX
17
- // A link-prefix substitution ALONE cannot reproduce the copies from a canonical with no links:
18
- // there would be no prefix to substitute. The canonical is therefore written with full markdown
19
- // links FIRST; only then does a per-file prefix adjustment become sufficient. Both halves are required — this script is the second half.
20
- //
21
- // MARKER PLACEMENT is pinned deliberately: the markers wrap ONLY the digest bullets, not the
22
- // heading and not the framing paragraph. Two consumers depend on that. This generator inserts
23
- // bullets under each target's own existing heading (neither target has a framing paragraph today,
24
- // and adding one silently would be a content change nobody asked for). The UserPromptSubmit hook
25
- // injects the same bullets into a consuming project's context, where a
26
- // repeated heading is pure token cost. One marker pair serves both.
27
- //
28
- // CONSUMER-CONTEXT CAVEAT (the seam this script deliberately does NOT own): the hook strips these
29
- // markdown links back to bare `(NN)` codes before injecting, because no repo-relative path resolves
30
- // in a consuming project — SoMi's rules/ lives in the plugin install directory. That stripping is
31
- // the hook's job, at the point of extraction. Loosening the canonical's citation style to suit
32
- // a consumer this file is never injected into would fix the symptom in the wrong place.
33
-
34
- import fs from 'node:fs';
35
- import path from 'node:path';
36
- import { fileURLToPath } from 'node:url';
37
-
38
- const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
39
- const CANONICAL = 'rules/CLAUDE.md';
40
- const START = '<!-- digest:start -->';
41
- const END = '<!-- digest:end -->';
42
- const HEADING = '## Always-on digest';
43
-
44
- // Each target's link prefix. The canonical sits at rules/CLAUDE.md and cites `./NN-*.md` —
45
- // FILE-relative, and the only form that resolves from inside rules/. (`./rules/NN-*.md` would
46
- // resolve to rules/rules/ — a dead link. That mistake shipped once here, and it passed review
47
- // because the hook's citation stripper happened to require the `rules/` segment, so a broken
48
- // canonical was the only thing that round-tripped. Both are fixed; this comment is the guard.)
49
- // AGENTS.md is at the repo root, so it needs `./rules/`; .github/copilot-instructions.md is one
50
- // level down, so it needs `../rules/`. Getting this wrong produces links that render but 404 — the
51
- // exact silent failure the digest copies exist to prevent, so it is data here rather than a guess.
52
- const TARGETS = [
53
- { file: 'AGENTS.md', prefix: './rules/' },
54
- { file: '.github/copilot-instructions.md', prefix: '../rules/' },
55
- ];
56
-
57
- function read(rel) {
58
- return fs.readFileSync(path.join(REPO_ROOT, rel), 'utf8');
59
- }
60
-
61
- // The canonical bullets, verbatim, between the markers. Throws rather than silently emitting an
62
- // empty digest — a generator that quietly writes nothing is worse than one that fails loudly.
63
- function canonicalBullets() {
64
- const src = read(CANONICAL);
65
- const i = src.indexOf(START);
66
- const j = src.indexOf(END);
67
- if (i === -1 || j === -1 || j < i) {
68
- throw new Error(`${CANONICAL}: missing or malformed ${START} / ${END} markers`);
69
- }
70
- const body = src.slice(i + START.length, j).trim();
71
- if (body === '') throw new Error(`${CANONICAL}: digest block is empty`);
72
- return body;
73
- }
74
-
75
- // Retarget the canonical's bare `./NN-*.md` to the prefix this target needs. Only the link TARGET
76
- // is rewritten, never the label — so ``[`00`](./00-priorities.md)`` keeps its `00` label intact.
77
- function retarget(bullets, prefix) {
78
- // ANCHORED on the citation shape (`./NN-name.md`), not on any `](./`. An unanchored pattern
79
- // rewrites every relative link in a bullet: a prose link like `[guide](./docs/ADOPTION.md)`
80
- // became `./rules/docs/ADOPTION.md` — dead — while `--check` reported both copies in sync.
81
- // The hook deliberately keeps prose links in bullets intact, so an
82
- // unanchored rewrite here put the two halves of the seam in disagreement about what is legal.
83
- return bullets.replace(/\]\(\.\/(\d{2}-[A-Za-z0-9-]+\.md)\)/g, `](${prefix}$1)`);
84
- }
85
-
86
- // Replace everything between the target's `## Always-on digest` heading and the next `## ` heading
87
- // (or EOF) with the generated bullets.
88
- //
89
- // Anchoring is LINE-ANCHORED and FENCE-AWARE, and a second heading match is an error rather than a
90
- // silent pick. A substring search got all three wrong, and each failure corrupted the file while
91
- // `--check` still reported "in sync" — a generator built to eliminate silent drift must not be able
92
- // to manufacture it:
93
- // - prose merely MENTIONING "## Always-on digest" above the real heading hijacked the anchor,
94
- // truncating that sentence mid-word and deleting the real section;
95
- // - a `## ` line inside a fenced code block terminated the splice early, swallowing the opening
96
- // fence and leaving it unbalanced;
97
- // - two headings would silently take the first.
98
- function splice(targetSrc, bullets) {
99
- const lines = targetSrc.split('\n');
100
- const headingRe = /^## Always-on digest[ \t]*$/;
101
- const nextHeadingRe = /^## /;
102
-
103
- // Fenced regions are invisible to both anchors. Tracked by toggling on ``` / ~~~ at line start.
104
- const fenced = new Set();
105
- let inFence = false;
106
- lines.forEach((line, i) => {
107
- if (/^\s*(```|~~~)/.test(line)) inFence = !inFence;
108
- if (inFence) fenced.add(i);
109
- });
110
-
111
- const heads = lines.map((l, i) => (headingRe.test(l) && !fenced.has(i) ? i : -1)).filter((i) => i >= 0);
112
- if (heads.length === 0) throw new Error(`missing "${HEADING}" heading`);
113
- if (heads.length > 1) {
114
- throw new Error(`"${HEADING}" appears ${heads.length} times (lines ${heads.map((i) => i + 1).join(', ')}) — ambiguous`);
115
- }
116
-
117
- const h = heads[0];
118
- let end = lines.length;
119
- for (let i = h + 1; i < lines.length; i++) {
120
- if (nextHeadingRe.test(lines[i]) && !fenced.has(i)) { end = i; break; }
121
- }
122
- const tail = end === lines.length ? '' : `\n${lines.slice(end).join('\n')}`;
123
- return `${lines.slice(0, h + 1).join('\n')}\n\n${bullets}\n${tail}`;
124
- }
125
-
126
- function main() {
127
- const check = process.argv.includes('--check');
128
-
129
- // A malformed canonical is a config error, not a crash. Without this the script exits on an
130
- // unhandled exception with a stack trace — technically non-zero, so CI would still fail, but the
131
- // operator sees a Node traceback instead of the one line that tells them what to fix. Found by
132
- // mutating the end marker and reading what the script actually printed.
133
- let bullets;
134
- try {
135
- bullets = canonicalBullets();
136
- } catch (err) {
137
- console.error(`generate-digest: ${err.message}`);
138
- process.exitCode = 1;
139
- return;
140
- }
141
-
142
- let drifted = 0;
143
-
144
- for (const { file, prefix } of TARGETS) {
145
- const current = read(file);
146
- let next;
147
- try {
148
- next = splice(current, retarget(bullets, prefix));
149
- } catch (err) {
150
- console.error(`generate-digest: ${file}: ${err.message}`);
151
- process.exitCode = 1;
152
- return;
153
- }
154
- if (next === current) continue;
155
- drifted++;
156
- if (check) {
157
- console.error(`generate-digest: DRIFT in ${file} — regenerate with \`node scripts/generate-digest.mjs\``);
158
- } else {
159
- fs.writeFileSync(path.join(REPO_ROOT, file), next);
160
- console.log(`generate-digest: updated ${file}`);
161
- }
162
- }
163
-
164
- if (check) {
165
- if (drifted > 0) {
166
- console.error(`generate-digest: ${drifted} file(s) out of sync with ${CANONICAL}`);
167
- process.exitCode = 1;
168
- } else {
169
- console.log(`generate-digest: all ${TARGETS.length} copies match ${CANONICAL}`);
170
- }
171
- } else if (drifted === 0) {
172
- console.log('generate-digest: already in sync, nothing to write');
173
- }
174
- }
175
-
176
- main();