@skathio/somi 4.1.1 → 5.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 (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 +83 -228
  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 +28 -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 +40 -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 +165 -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 +73 -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 +38 -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 +181 -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
@@ -1,102 +0,0 @@
1
- # sample-consumer — minimal project consuming somi
2
-
3
- This directory shows what a project **consuming** SoMi looks like. Install it with:
4
-
5
- ```text
6
- /plugin marketplace add https://github.com/skathio/somi
7
- /plugin install somi@somi
8
- ```
9
-
10
- It's a layout reference, not a runnable project — there's no application code here. Note that SoMi
11
- creates **only** `.somi/`; `CLAUDE.md` and `.claude/settings.json` are yours.
12
-
13
- > **A marketplace install does not put the plugin in your project.** Claude Code copies plugin
14
- > files into a **user-level cache** (`~/.claude/plugins/cache`), so your project directory does not
15
- > contain SoMi's code at all. The `.claude/plugins/somi/` node below shows the **vendored** layout —
16
- > a copy you place in the repo yourself — and is drawn here only to name the pieces.
17
-
18
- ## Layout reference (vendored install shown)
19
-
20
- ```
21
- <your project>/
22
- ├── CLAUDE.md # YOURS — SoMi never creates or writes this
23
- ├── .somi/ # workflow artifacts + project-local SoMi state
24
- │ ├── README.md
25
- │ ├── rules/
26
- │ │ └── 99-overrides.md # your project escape hatch (created by /adopt or by hand)
27
- │ ├── rd/ # discovery initiatives (created when /discover runs)
28
- │ │ └── <slug>/ # research-report, brd, srs, frd, sdd, tdd, decisions, diary
29
- │ ├── plans/
30
- │ │ └── <slug>/ # one per /plan invocation
31
- │ │ ├── context.md
32
- │ │ ├── spec.md
33
- │ │ ├── decisions.md
34
- │ │ ├── progress.md
35
- │ │ ├── diary.md
36
- │ │ └── phases/
37
- │ ├── reviews/
38
- │ │ └── <slug>/ # reviews keyed by work-item slug
39
- │ ├── somi-state/ # runtime state (loop resume, context-injection signature); gitignored
40
- │ └── audit.log # append-only tool-call log; gitignored
41
- └── .claude/
42
- ├── settings.json # yours; SoMi writes none of it. Claude Code merges the
43
- │ # plugin's hooks/hooks.json at runtime (a project-scope
44
- │ # install may add its own enabledPlugins entry)
45
- └── plugins/
46
- └── somi/
47
- ├── .claude-plugin/plugin.json
48
- ├── agents/ # discovery-analyst, planner, coder, reviewer + support
49
- ├── commands/ # /discover, /plan, /code, /review, /ship + support
50
- ├── skills/ # market-research, requirements-engineering, OWASP, SOLID, ...
51
- ├── rules/ # global ruleset (00-50 + the 99-overrides.md starter template)
52
- ├── templates/ # context, spec, decisions, phase, progress, diary, review, ADR, DoD; R&D: RD-README, RESEARCH, BRD, SRS, FRD, SDD, TDD
53
- └── hooks/ # guardrail scripts; wired via hooks/hooks.json
54
- ```
55
-
56
- ## Things to notice
57
-
58
- - **`CLAUDE.md` is yours and is never generated.** Claude Code loads it as project-level
59
- instructions. SoMi's own ruleset does **not** arrive through it — the `UserPromptSubmit` hook
60
- injects a priority floor every turn plus the digest on signature-change turns, and the numbered
61
- rule files are on-demand via the `rules` skill. See
62
- [`docs/RULES.md`](../../docs/RULES.md#how-the-ruleset-reaches-your-session).
63
- - **Hooks live inside the plugin install directory** and are referenced via `${CLAUDE_PLUGIN_ROOT}`
64
- in `hooks/hooks.json` (or `${SOMI_VENDOR_ROOT}` for a vendored copy), so they work regardless of
65
- where the plugin root resolves. (`${SOMI_ROOT}` was removed before 2.0.0 — if you see that
66
- name in a vendored `settings.json`, it is stale.)
67
- - **`settings.json` stays yours — SoMi never writes it.** Claude Code merges the plugin's
68
- `hooks/hooks.json` at runtime, so hooks fire without any file surgery; see
69
- [`docs/INSTALL.md`](../../docs/INSTALL.md), which states you do not need to edit
70
- `.claude/settings.json`. (A *vendored* copy is the exception — there you merge the hooks block by
71
- hand, as this directory's own `.claude/settings.json` explains in its `_comment`.)
72
- - **All SoMi-written runtime state lives under `.somi/`, never `.claude/`.** `audit.log`,
73
- `somi-state/` (loop resume, context-injection signature), and `rules/99-overrides.md` are all
74
- project-local and host-neutral — the same regardless of whether the consumer is Claude Code or
75
- GitHub Copilot. Only the plugin's own *installed code*
76
- (agents/commands/skills/rules/hooks) lives under the plugin's install root — the user-level cache
77
- for a marketplace install, `.claude/plugins/somi/` for a vendored copy.
78
-
79
- ## What stays yours after install
80
-
81
- - `CLAUDE.md` — SoMi never writes it at all, so there is nothing to overwrite. Add
82
- project-specific instructions in `.somi/rules/99-overrides.md`, which SoMi never touches and which
83
- survives `/plugin update somi` (that path is consumer-relative: it exists in your project, not in
84
- this example directory), or directly in your `CLAUDE.md`.
85
- - Your `settings.json` in full — SoMi writes none of it.
86
- - Everything under `.somi/` — workflow artifacts and SoMi's own project-local state. Work items
87
- persist indefinitely; only you delete from there.
88
-
89
- ## Updating
90
-
91
- ```text
92
- /plugin update somi
93
- ```
94
-
95
- ## Uninstalling
96
-
97
- ```text
98
- /plugin uninstall somi
99
- ```
100
-
101
- Removes the plugin. Leaves your `CLAUDE.md` and everything under `.somi/` (including `audit.log`
102
- and `rules/99-overrides.md`) alone.
@@ -1,209 +0,0 @@
1
- #!/usr/bin/env node
2
- // hooks/post-tool/lint-changed-files.mjs — PostToolUse hook (matcher: Write|Edit) —
3
- // best-effort lint of just-changed files.
4
- //
5
- // Imports the shared read/context/projectRoot helpers from ../lib/common.mjs rather than
6
- // reimplementing them.
7
- //
8
- // Runs the project's configured linter on the touched file, if one is available,
9
- // keyed off file extension + presence of a config file. Result is informational —
10
- // this hook NEVER blocks (PostToolUse: the file is already written by the time it
11
- // runs). Every failure mode — missing linter, missing config, linter crash, linter
12
- // non-zero exit, output truncated by maxBuffer — degrades to "no context emitted",
13
- // never a deny, never a non-zero hook exit. Preserve that contract exactly; a
14
- // future edit must not let any of these become a thrown, uncaught error.
15
- //
16
- // --- PROJECT_ROOT resolution: guarded projectRoot(), not bash's raw pattern ------
17
- // bash: `PROJECT_ROOT="${CLAUDE_PROJECT_DIR:-$PWD}"` — no `${...}`-unexpanded-
18
- // literal guard on THIS specific line (unlike most other ported hooks' PROJECT_ROOT
19
- // lines). Using common.mjs's projectRoot() here anyway (which DOES
20
- // carry the guard) is a deliberate, safe-direction improvement, not a silent
21
- // behavior change: if a host ever fails to expand `${CLAUDE_PROJECT_DIR}` before
22
- // setting it, bash's un-guarded line would set PROJECT_ROOT to that literal
23
- // garbage string, and the .ts/.go/.rs branches' `cd "$PROJECT_ROOT" &&` would then
24
- // FAIL (nonexistent directory) — which, under this script's `set -euo pipefail`,
25
- // aborts the ENTIRE hook script non-gracefully (a crash, not the intended
26
- // best-effort no-op). The guarded projectRoot() falls back to `process.cwd()` in
27
- // that same scenario instead, so this port degrades to "no lint delegate ran" for
28
- // the broken-host case rather than crashing — strictly safer, and consistent with
29
- // the centralization intent (every hook imports the one guarded helper rather
30
- // than re-duplicating bash's un-guarded line).
31
- //
32
- // --- run_if_present() -> runIfPresent(), combined with the `command -v` gate ----
33
- // bash checks presence first (`command -v "$cmd"`), then, only if found, execs it
34
- // with `2>&1 || true` (swallow a non-zero exit AND merge stdout+stderr). Node's
35
- // spawnSync already reports "executable not found on PATH" as
36
- // `result.error.code === 'ENOENT'` (Node does the PATH search itself, including
37
- // PATHEXT on Windows) — a single spawnSync call reproduces BOTH steps (presence
38
- // check + conditional exec) without a separate hand-rolled PATH-search helper, and
39
- // without the check-then-exec TOCTOU race the bash original technically has
40
- // (immaterial for a best-effort hook either way, but a strictly safer property of
41
- // this shape, not a behavior change). `result.error` covers every reason the
42
- // subprocess output couldn't be captured (not found, EACCES, exceeded maxBuffer,
43
- // ...) — all of them collapse to "no lint output," matching bash's blanket `|| true`
44
- // swallow.
45
- //
46
- // stdout/stderr are captured as SEPARATE buffers by spawnSync and concatenated
47
- // (`stdout + stderr`) rather than truly interleaved the way a shell's `2>&1`
48
- // fd-level merge would produce — Node has no direct equivalent without opening a
49
- // real on-disk fd shared by both streams, which would be needless complexity for
50
- // output that is purely informational and never programmatically parsed
51
- // downstream. This is an intentional, named divergence: the acceptance criteria
52
- // for this port pin SHAPE (does the wrapped "Lint output for the file just
53
- // changed:" envelope appear, non-empty, when a real delegate run produces
54
- // anything), not exact interleaved text — verified per fixture case that every
55
- // scenario this port is actually tested against produces output on only ONE of
56
- // the two streams, so concatenation order is moot for what's tested.
57
- //
58
- // --- maxBuffer -------------------------------------------------------------------
59
- // LINT_MAX_BUFFER below is set explicitly on every output-capturing spawnSync call.
60
- // This is the first hook port that shells out to capture an ARBITRARY THIRD-PARTY
61
- // TOOL's own output (prior ports only capture `git`'s output for decision logic,
62
- // not a linter's free-form diagnostic text) — Node's child_process default
63
- // maxBuffer is 1 MB, and a verbose linter run (e.g. `cargo clippy` across a whole
64
- // crate, or `eslint` with a large ruleset) could plausibly exceed that. 10 MB is a
65
- // generous ceiling: enough to never truncate a realistic single-file lint run,
66
- // small enough to bound worst-case memory use from a hook that's supposed to be a
67
- // cheap, best-effort side note. If a real run exceeds it, spawnSync sets
68
- // `result.error`, which `runIfPresent`'s swallow-everything contract already
69
- // treats as "nothing to report" — an over-the-cap linter run degrades to silence,
70
- // not a crash. This is the explicit-maxBuffer convention; any hook that captures
71
- // subprocess output should follow it.
72
- //
73
- // --- command-substitution trailing-newline stripping -----------------------------
74
- // bash builds LINT_OUTPUT via `"$(...)"` command substitution, which
75
- // UNCONDITIONALLY strips ALL trailing newlines from the captured text (a bash
76
- // `$(...)` primitive, not specific to this hook). Node's spawnSync does not do
77
- // this — reproduced explicitly via stripTrailingNewlines() below, applied to every
78
- // branch's captured output, not just the `cargo clippy | head -50` branch that
79
- // visibly pipes through another command.
80
- //
81
- // --- extension dispatch + config gating -------------------------------------------
82
- // Ported 1:1 from the bash `case "$PATH_INPUT" in ... esac` arms, same order,
83
- // same per-linter config-file gate, same cd-vs-no-cd behavior per branch (verified
84
- // line-by-line against the bash original: ts/go/rust branches `cd "$PROJECT_ROOT"`
85
- // before running their delegate; py/sh branches do not).
86
- //
87
- // --- cargo clippy path unreachable in the authoring/CI sandbox -------------------
88
- // No rust toolchain exists in either environment (confirmed absent both places) —
89
- // headLines()'s "head -50" translation is a faithful, readable-output-preserving
90
- // port (not byte-exact POSIX `head` semantics, which don't matter here since bash's
91
- // own `$(...)` strips trailing newlines from the piped result anyway), but is
92
- // UNVERIFIED against a real `cargo clippy` invocation. Flagged, not silently
93
- // assumed correct.
94
- import fs from 'node:fs';
95
- import path from 'node:path';
96
- import { spawnSync } from 'node:child_process';
97
- import { readPayload, field, contextOutput, projectRoot, runHook } from '../lib/common.mjs';
98
-
99
- const LINT_MAX_BUFFER = 10 * 1024 * 1024; // 10 MB — see header comment.
100
- const MAX_LINT_FILE_BYTES = 500000; // bash: SIZE_BYTES > 500000 skip (likely generated).
101
-
102
- function isFile(p) {
103
- try {
104
- return fs.statSync(p).isFile();
105
- } catch {
106
- return false;
107
- }
108
- }
109
-
110
- function stripTrailingNewlines(text) {
111
- return text.replace(/\n+$/, '');
112
- }
113
-
114
- // See the header comment's "run_if_present() -> runIfPresent()" section.
115
- function runIfPresent(cmd, args, cwd) {
116
- const result = spawnSync(cmd, args, { cwd, encoding: 'utf8', maxBuffer: LINT_MAX_BUFFER });
117
- if (result.error) return '';
118
- return stripTrailingNewlines((result.stdout || '') + (result.stderr || ''));
119
- }
120
-
121
- // head -N equivalent for the clippy branch. Bash's own `$(...)` strips trailing
122
- // newlines from the piped-through result regardless, so byte-exact `head`
123
- // semantics around a missing/present final newline don't matter here — see the
124
- // header comment.
125
- function headLines(text, n) {
126
- const lines = text.split('\n');
127
- if (lines.length <= n) return text;
128
- return lines.slice(0, n).join('\n');
129
- }
130
-
131
- // bash: nullglob loop over "$PROJECT_ROOT"/.eslintrc* filtered to `-f` (regular
132
- // files only), OR eslint.config.js, OR eslint.config.mjs.
133
- function hasEslintConfig(root) {
134
- let entries;
135
- try {
136
- entries = fs.readdirSync(root);
137
- } catch {
138
- entries = [];
139
- }
140
- const hasRcVariant = entries.some(
141
- (name) => name.startsWith('.eslintrc') && isFile(path.join(root, name)),
142
- );
143
- if (hasRcVariant) return true;
144
- return isFile(path.join(root, 'eslint.config.js')) || isFile(path.join(root, 'eslint.config.mjs'));
145
- }
146
-
147
- // bash: "./$(dirname "${PATH_INPUT#$PROJECT_ROOT/}")/..." — strip the
148
- // PROJECT_ROOT/ prefix (a no-op if PATH_INPUT doesn't actually start with it,
149
- // matching bash's `#`-prefix-removal no-op-on-no-match behavior), take the
150
- // directory component, wrap as a `go vet` package pattern. Uses platform-default
151
- // path.dirname (posix on Linux/macOS) — same Windows-backslash caveat the
152
- // other path-handling hooks already flag and defer (not fixed here either).
153
- function goVetPackageArg(pathInput, root) {
154
- const prefix = root.endsWith(path.sep) ? root : root + path.sep;
155
- const rel = pathInput.startsWith(prefix) ? pathInput.slice(prefix.length) : pathInput;
156
- return `./${path.dirname(rel)}/...`;
157
- }
158
-
159
- function main() {
160
- const payload = readPayload();
161
- const pathInput = field(payload, '.tool_input.file_path');
162
- if (!pathInput) return;
163
- if (!isFile(pathInput)) return;
164
-
165
- // Skip oversized files (likely generated). bash: `wc -c < "$PATH_INPUT" 2>/dev/null
166
- // || echo 0` — a stat race after the isFile() check above falls back to 0 (treated
167
- // as "not oversized," matching bash's fallback exactly).
168
- let sizeBytes = 0;
169
- try {
170
- sizeBytes = fs.statSync(pathInput).size;
171
- } catch {
172
- sizeBytes = 0;
173
- }
174
- if (sizeBytes > MAX_LINT_FILE_BYTES) return;
175
-
176
- const root = projectRoot();
177
- let lintOutput = '';
178
-
179
- if (pathInput.endsWith('.py')) {
180
- if (isFile(path.join(root, 'pyproject.toml')) || isFile(path.join(root, '.ruff.toml'))) {
181
- lintOutput = runIfPresent('ruff', ['check', '--quiet', pathInput], undefined);
182
- }
183
- } else if (['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'].some((ext) => pathInput.endsWith(ext))) {
184
- if (hasEslintConfig(root)) {
185
- lintOutput = runIfPresent('npx', ['--no-install', 'eslint', '--no-color', pathInput], root);
186
- }
187
- } else if (pathInput.endsWith('.go')) {
188
- if (isFile(path.join(root, 'go.mod'))) {
189
- lintOutput = runIfPresent('go', ['vet', goVetPackageArg(pathInput, root)], root);
190
- }
191
- } else if (pathInput.endsWith('.rs')) {
192
- if (isFile(path.join(root, 'Cargo.toml'))) {
193
- lintOutput = headLines(
194
- runIfPresent('cargo', ['clippy', '--quiet', '--message-format=short'], root),
195
- 50,
196
- );
197
- }
198
- } else if (pathInput.endsWith('.sh')) {
199
- lintOutput = runIfPresent('shellcheck', [pathInput], undefined);
200
- }
201
-
202
- if (lintOutput) {
203
- // PostToolUse additionalContext must live under hookSpecificOutput per the
204
- // Claude Code hook schema (same note the bash original carried).
205
- contextOutput('PostToolUse', `Lint output for the file just changed:\n${lintOutput}`);
206
- }
207
- }
208
-
209
- runHook(main);
@@ -1,192 +0,0 @@
1
- #!/usr/bin/env node
2
- // hooks/pre-tool/guard-cost-lowering.mjs — PreToolUse hook (matcher: Write|Edit|MultiEdit|mcp__.*somi_config)
3
- // — ask the USER before a change that lowers a cost tier.
4
- //
5
- // A model steered by injected text could lower security-reviewer or the ceiling through the somi_config
6
- // MCP tool or by editing .somi/config.json, and the warning would only reach that model. This hook
7
- // computes what the change would do and, if it lowers any agent's effective tier (see
8
- // scripts/lib/cost-lowering.mjs for the exact rules), answers permissionDecision "ask" with a plain-text
9
- // reason built from fixed strings. Raises and no-ops are silent, and so is every unrelated tool call.
10
- //
11
- // - somi_config (set|unset): `after` = the current config with tool_input applied by the shared edit
12
- // lib (scripts/lib/cost-config-edit.mjs), so the hook and the tool cannot disagree on meaning.
13
- // - Write / Edit / MultiEdit of <project>/.somi/config.json (the path is resolved against the project
14
- // root, so `.somi/../.somi/config.json` and a symlinked .somi resolve to the same file): `after` = the
15
- // written content, or the current text with the edits applied exactly as the Edit tool would.
16
- // Both sides are judged as the resolver sees them: the global config with the project file merged
17
- // over it (scripts/lib/config-files.mjs), so a project file that drops below a global pin is a lowering.
18
- // - Any file-tool write to the global config asks, whatever it changes: that file applies to every
19
- // project and session, and the somi_config tool never writes it (only the user, through the CLI).
20
- //
21
- // Fail closed to the user: for a config-file path, any inability to evaluate (unreadable or unparsable
22
- // content, an edit that does not apply, an exception) asks. Nothing from any file is ever echoed.
23
- // Accepted limits: a model with an approved Bash tool can still edit the file by other means; the
24
- // somi_config tool's own refusal (--refuse-lowering) covers hosts where this hook does not run.
25
-
26
- import fs from 'node:fs';
27
- import path from 'node:path';
28
- import { pathToFileURL } from 'node:url';
29
- import { readPayload, field, askPretool, HookExit, projectRoot, writeTargets } from '../lib/common.mjs';
30
- import { globalConfigPath, mergeConfig, parseConfigText, readConfigFile, readConfigText } from '../../scripts/lib/config-files.mjs';
31
-
32
- const LIB = path.join(import.meta.dirname, '..', '..', 'scripts', 'lib');
33
- const UNEVALUABLE = 'SoMi: this change to .somi/config.json could not be evaluated, so it needs your confirmation.';
34
- const OUTSIDE = 'SoMi: this call names a project directory outside the project root, so it needs your confirmation.';
35
- const STATE_WRITE = 'SoMi: this writes the persisted cost ceiling (.somi/somi-state/ceiling.json), which can lower the ceiling, so it needs your confirmation.';
36
- const UNREADABLE_WRITE = 'SoMi: this writes the SoMi cost config or ceiling in a form the guard cannot evaluate, so it needs your confirmation.';
37
- const GLOBAL_WRITE = 'SoMi: this changes your global SoMi config, which every project and session uses, so it needs your confirmation.';
38
- const RESOLVE_LOWER = 'SoMi: this somi_resolve call sets a session ceiling lower than the current one, so it needs your confirmation.';
39
- const SECURITY_ONLY = 'SoMi: after this change security-reviewer would run below high (it is not pinned to high). Confirm only if you intend that.';
40
- const reasonFor = (reasons, REASONS) => (reasons.length === 1 && reasons[0] === REASONS.security
41
- ? SECURITY_ONLY
42
- : `SoMi: this change lowers a cost setting (${reasons.join('; ')}). Confirm only if you intend it.`);
43
-
44
- const realOrNull = (p) => { try { return fs.realpathSync(p); } catch { return null; } };
45
- const statOrNull = (p) => { try { return fs.statSync(p); } catch { return null; } };
46
- const same = (a, b) => a !== null && b !== null && a.dev === b.dev && a.ino === b.ino;
47
-
48
- // Is `target` (as given by the tool) the project's .somi/config.json? Decided by identity, not spelling:
49
- // - it is the same file (dev/ino, following links), or
50
- // - its nearest existing ancestor is the same directory as <root>/.somi and the rest is config.json
51
- // (any case), or that ancestor is the root itself and the rest is .somi/config.json (any case), so an
52
- // absent file, an absent .somi, a symlinked .somi, an aliased root and a case-insensitive filesystem
53
- // are all caught, or
54
- // - lexically it is <root>/.somi/config.json in any letter case (fail closed when nothing resolves).
55
- // `segs` is the file's path below the root: ['.somi', 'config.json'] or ['.somi', 'somi-state', 'ceiling.json'].
56
- function isProjectPath(root, target, segs) {
57
- const lexical = path.resolve(root, target);
58
- if (same(statOrNull(lexical), statOrNull(path.join(root, ...segs)))) return true;
59
- let anc = lexical; const rest = [];
60
- while (statOrNull(anc) === null && path.dirname(anc) !== anc) { rest.unshift(path.basename(anc)); anc = path.dirname(anc); }
61
- const low = rest.map((x) => x.toLowerCase());
62
- const ancStat = statOrNull(anc);
63
- const n = low.length;
64
- if (n >= 1 && n <= segs.length && low.join('/') === segs.slice(segs.length - n).join('/') && same(ancStat, statOrNull(path.join(root, ...segs.slice(0, segs.length - n))))) return true;
65
- const rel = path.relative(root, lexical).split(path.sep).map((x) => x.toLowerCase());
66
- return rel.join('/') === segs.join('/');
67
- }
68
- const isConfigPath = (root, target) => isProjectPath(root, target, ['.somi', 'config.json']);
69
- const isStatePath = (root, target) => isProjectPath(root, target, ['.somi', 'somi-state', 'ceiling.json']);
70
- // The global config, by the same identity rules, its directory standing in for the root.
71
- const isGlobalPath = (root, target, globalFile) => globalFile !== null
72
- && isProjectPath(path.dirname(globalFile), path.resolve(root, target), [path.basename(globalFile)]);
73
- const isObj = (x) => x !== null && typeof x === 'object' && !Array.isArray(x);
74
- // The global config as the resolver reads it ({} when there is none); unreadable throws, and the caller asks.
75
- const globalConfig = () => { const g = globalConfigPath(); return (g && readConfigFile(g)) ?? {}; };
76
-
77
- // The project directory a somi_config / somi_resolve call acts on: project_dir when it resolves to the root
78
- // or inside it, the root when none is given; anything else is something the hook cannot evaluate: ask.
79
- function narrowedDir(payload, input, root) {
80
- if (input.project_dir === undefined) return root;
81
- const dir = typeof input.project_dir === 'string' && path.isAbsolute(input.project_dir) ? realOrNull(input.project_dir) : null;
82
- const host = realOrNull(root);
83
- if (!dir || !host || !(dir === host || dir.startsWith(host + path.sep))) askPretool(payload, OUTSIDE);
84
- return dir;
85
- }
86
-
87
- // The Edit tool's rule: old_string must occur (once, unless replace_all). Returns the new text or null.
88
- function applyOneEdit(text, e) {
89
- if (typeof e?.old_string !== 'string' || typeof e?.new_string !== 'string' || e.old_string === '') return null;
90
- const n = text.split(e.old_string).length - 1;
91
- if (n === 0 || (n > 1 && e.replace_all !== true)) return null;
92
- return e.replace_all === true ? text.split(e.old_string).join(e.new_string) : text.replace(e.old_string, () => e.new_string);
93
- }
94
-
95
- // The project config's text, links followed (as the resolver reads it), or null when absent.
96
- const readCurrent = (file) => readConfigText(file);
97
-
98
- // somi_resolve({ceiling}) persists a CLI-style ceiling; one below the ceiling in force needs the user.
99
- async function resolveCheck(payload, input, root) {
100
- if (input.ceiling === undefined) return;
101
- const dir = narrowedDir(payload, input, root);
102
- try {
103
- const [{ loadState, DEFAULT_CEILING }, { VALID_COSTS }] = await Promise.all(
104
- ['cost-ceiling', 'cost-model'].map((m) => import(pathToFileURL(path.join(LIB, `${m}.mjs`)).href)),
105
- );
106
- if (!VALID_COSTS.includes(input.ceiling)) return; // the tool rejects it itself
107
- const file = path.join(dir, '.somi', 'config.json');
108
- const text = readCurrent(file);
109
- const cfg = mergeConfig(globalConfig(), text === null ? {} : parseConfigText(text, file));
110
- const state = loadState(dir);
111
- const effective = VALID_COSTS.includes(cfg?.cost?.ceiling) ? cfg.cost.ceiling
112
- : (state && ['cli', 'env'].includes(state.ceiling_origin) ? state.ceiling : DEFAULT_CEILING);
113
- if (VALID_COSTS.indexOf(input.ceiling) < VALID_COSTS.indexOf(effective)) askPretool(payload, RESOLVE_LOWER);
114
- } catch (e) {
115
- if (e instanceof HookExit) throw e;
116
- askPretool(payload, RESOLVE_LOWER);
117
- }
118
- }
119
-
120
- async function main() {
121
- const payload = readPayload();
122
- const tool = field(payload, 'tool_name');
123
- const input = payload?.tool_input && typeof payload.tool_input === 'object' ? payload.tool_input : {};
124
- const isMcp = /^mcp__.*somi_config$/.test(tool) || tool === 'somi_config';
125
- const isResolve = /^mcp__.*somi_resolve$/.test(tool) || tool === 'somi_resolve';
126
- const isFileTool = tool === 'Write' || tool === 'Edit' || tool === 'MultiEdit';
127
- if (!isMcp && !isFileTool && !isResolve) return;
128
-
129
- const root = projectRoot();
130
- if (isResolve) return resolveCheck(payload, input, root);
131
- const globalFile = globalConfigPath();
132
- // Copilot CLI's file tools (Write with `path`, Edit with a raw patch) carry no file_path and no
133
- // before/after the evaluation below can read: a write that reaches the config or the persisted
134
- // ceiling in that shape asks. One whose target cannot be read at all is the path guards' to refuse.
135
- if (isFileTool && !(typeof input.file_path === 'string' && input.file_path !== '')) {
136
- const { paths } = writeTargets(payload);
137
- if (paths.some((p) => isConfigPath(root, p) || isStatePath(root, p) || isGlobalPath(root, p, globalFile))) askPretool(payload, UNREADABLE_WRITE);
138
- return;
139
- }
140
- if (isFileTool && isGlobalPath(root, input.file_path, globalFile)) askPretool(payload, GLOBAL_WRITE);
141
- // Any write to the persisted ceiling file asks: it is the other way to lower the ceiling.
142
- if (isFileTool && typeof input.file_path === 'string' && input.file_path !== '' && isStatePath(root, input.file_path)) askPretool(payload, STATE_WRITE);
143
- let projDir = root; // the directory whose config is evaluated (and whose persisted ceiling applies)
144
- if (isMcp) {
145
- if (input.action !== 'set' && input.action !== 'unset') return;
146
- // The tool writes into project_dir when it narrows the host root; evaluate THAT config. A project_dir
147
- // that does not resolve to the root or a directory inside it is something the hook cannot evaluate: ask.
148
- projDir = narrowedDir(payload, input, root);
149
- } else {
150
- const target = input.file_path;
151
- if (typeof target !== 'string' || target === '' || !isConfigPath(root, target)) return;
152
- }
153
- const file = path.join(projDir, '.somi', 'config.json');
154
-
155
- // From here the call is about the project config: any failure asks.
156
- try {
157
- const [{ applyEdit, EditError }, { lowers, REASONS }] = await Promise.all(
158
- ['cost-config-edit', 'cost-lowering'].map((m) => import(pathToFileURL(path.join(LIB, `${m}.mjs`)).href)),
159
- );
160
- const base = globalConfig();
161
- const currentText = readCurrent(file);
162
- let before = {};
163
- if (currentText !== null) { try { before = JSON.parse(currentText); } catch { before = {}; } }
164
- let after;
165
- if (isMcp) {
166
- try { after = applyEdit(currentText === null ? null : JSON.parse(currentText), { action: input.action, key: input.key, value: input.value }).next; } catch (e) {
167
- if (e instanceof EditError) return; // the tool rejects this call itself; nothing would change
168
- throw e;
169
- }
170
- } else if (tool === 'Write') {
171
- if (typeof input.content !== 'string') throw new Error('no content');
172
- after = JSON.parse(input.content);
173
- } else {
174
- let text = currentText ?? '';
175
- const edits = tool === 'MultiEdit' ? input.edits : [input];
176
- if (!Array.isArray(edits)) throw new Error('no edits');
177
- for (const e of edits) {
178
- text = applyOneEdit(text, e);
179
- if (text === null) throw new Error('edit does not apply');
180
- }
181
- after = JSON.parse(text);
182
- }
183
- const verdict = lowers(mergeConfig(base, isObj(before) ? before : {}), isObj(after) ? mergeConfig(base, after) : after, projDir);
184
- if (verdict.lowers) askPretool(payload, reasonFor(verdict.reasons, REASONS));
185
- } catch (e) {
186
- if (e instanceof HookExit) throw e;
187
- askPretool(payload, UNEVALUABLE);
188
- }
189
- }
190
-
191
- // Exit 0 on every path: a HookExit is the question already asked, anything else is silence.
192
- main().then(() => {}, () => {}).finally(() => { process.exitCode = 0; });