@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
@@ -0,0 +1,208 @@
1
+ #!/usr/bin/env node
2
+ // somi: the command line behind SoMi's tools. Every state write happens inside these commands.
3
+ //
4
+ // somi route <request> [--hint ROUTE] [--sensitive] what a request should run as, at which tier
5
+ // somi review [--always] [--security] [--base REF] which reviewers a change needs
6
+ // somi review --record [--input FILE] [--tree T] records what reviewers returned, from stdin by default
7
+ // somi check [--full]
8
+ // somi pr [--base REF] [--unreviewed] writes the pull request text; a change that needed a review and has none is refused
9
+ // somi plan | --done N | --close saves the plan text from stdin, marks a milestone done, or ends the plan
10
+ // somi slot <step> <plugin:component> [--mode read|write] [--project] | somi slot --list | --remove | --confirm
11
+ // somi ledger --kind decision|constraint|pointer --text T
12
+ // somi status | migrate
13
+ // somi setup [--host claude|copilot] makes SoMi the session agent, on the model set for its tier
14
+ // somi doctor [--host claude|copilot] [--profile]
15
+ // somi init --host copilot registers the staged workflow with Copilot CLI
16
+ //
17
+ // Exit codes: 0 done, 1 a check, the doctor or the pull request gate failed, 64 the request was refused.
18
+
19
+ import fs from 'node:fs';
20
+ import path from 'node:path';
21
+ import { parseArgs } from 'node:util';
22
+ import { fileURLToPath } from 'node:url';
23
+ import { advise } from './lib/advisor.mjs';
24
+ import { runCheck } from './lib/check.mjs';
25
+ import { ConfigFileError, loadConfig } from './lib/config-files.mjs';
26
+ import { duplicateHookWarnings, runDoctor } from './lib/doctor.mjs';
27
+ import { commitBase, listFiles, repoRoot, resolveRef, snapshotTree, stateIsTracked, workBase } from './lib/git-tree.mjs';
28
+ import { writeCopilotExtension } from './lib/init.mjs';
29
+ import { addToLedger, readLedger } from './lib/ledger.mjs';
30
+ import { migrate } from './lib/migrate.mjs';
31
+ import { lastCheck, migratedFindings, pullRequest } from './lib/pr.mjs';
32
+ import { closePlan, markMilestoneDone, planStatus, savePlan } from './lib/plan.mjs';
33
+ import { ReviewInputError } from './lib/policy.mjs';
34
+ import { CHANGE_SCOPES, SCOPES, limitsFor, resolveLimits } from './lib/quality/limits.mjs';
35
+ import { repoQuality } from './lib/quality/repo.mjs';
36
+ import { qualityGate } from './lib/quality/gate.mjs';
37
+ import { readReviews, recordReviews, reviewPlan } from './lib/reviews.mjs';
38
+ import { setupAgent } from './lib/setup.mjs';
39
+ import { ShardError, confirmProjectShards, listShards, slot, unslot } from './lib/shards.mjs';
40
+ import { StateError, statePaths, writeStateFile } from './lib/state.mjs';
41
+ import { detectHost } from './lib/tiers.mjs';
42
+ import { renderStatus } from './lib/views.mjs';
43
+
44
+ const PLUGIN_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
45
+
46
+ export function makeContext(cwd = process.cwd(), env = process.env) {
47
+ const root = repoRoot(cwd);
48
+ if (!env.SOMI_STATE_DIR && stateIsTracked(root)) throw new StateError('.somi/state is committed to this repository, so SoMi will not trust it. Stop tracking it with `git rm -r --cached .somi/state`.');
49
+ let layers = [];
50
+ let config = {};
51
+ try {
52
+ const loaded = loadConfig(root, env);
53
+ layers = [loaded.global.config, loaded.project.config];
54
+ config = loaded.config;
55
+ } catch (e) {
56
+ if (!(e instanceof ConfigFileError)) throw e;
57
+ process.stderr.write('somi: ignoring an unreadable config file; built-in signals still apply\n');
58
+ }
59
+ return { root, env, config, configLayers: layers, host: detectHost(env), now: () => env.SOMI_CLOCK || new Date().toISOString().replace(/\.\d{3}Z$/, 'Z') };
60
+ }
61
+
62
+ const print = (value) => process.stdout.write(`${JSON.stringify(value)}\n`);
63
+
64
+ function checkAndRecord(ctx, { full = false, scope } = {}) {
65
+ const result = runCheck({ root: ctx.root, env: ctx.env, full, ...(scope ? { scope } : {}) });
66
+ writeStateFile(ctx.root, statePaths(ctx.root, ctx.env).check, `${JSON.stringify({ at: ctx.now(), tree: result.tree, ok: result.ok, full })}\n`, ctx.env);
67
+ return result;
68
+ }
69
+
70
+
71
+ function review(ctx, args) {
72
+ const { values } = parseArgs({ args, options: { record: { type: 'boolean' }, input: { type: 'string' }, tree: { type: 'string' }, base: { type: 'string' }, always: { type: 'boolean' }, security: { type: 'boolean' } } });
73
+ if (!values.record) return print(reviewPlan(ctx, values));
74
+ let reviews;
75
+ try { reviews = JSON.parse(fs.readFileSync(values.input ?? 0, 'utf8')); } catch { throw new ReviewInputError('the reviews are not valid JSON'); }
76
+ return print(recordReviews(ctx, { reviews, base: values.base, tree: values.tree, always: values.always, security: values.security }));
77
+ }
78
+
79
+ function pr(ctx, args) {
80
+ const { values } = parseArgs({ args, options: { base: { type: 'string' }, unreviewed: { type: 'boolean' } } });
81
+ const result = pullRequest(ctx, { base: values.base, unreviewed: values.unreviewed });
82
+ if (!result.ok) {
83
+ process.stderr.write(`somi: ${result.why.replace('pass unreviewed', 'pass --unreviewed')}\n`);
84
+ return 1;
85
+ }
86
+ process.stdout.write(result.text);
87
+ return 0;
88
+ }
89
+
90
+ // The quality gate. --scope pr, the default, scores the work since this branch left the shared history, uncommitted files included, as
91
+ // the review check sees it. --scope commit scores what a commit adds to the last one. --scope repo reports on the whole codebase as it
92
+ // stands, worst first, for a cleanup or a refactor. --benchmark scores with the default limits and
93
+ // counts an agent's own exemptions as violations.
94
+ async function quality(ctx, args) {
95
+ const { values } = parseArgs({ args, options: { from: { type: 'string' }, scope: { type: 'string' }, benchmark: { type: 'boolean' } } });
96
+ const scope = values.scope ?? 'pr';
97
+ if (!SCOPES.includes(scope)) throw new StateError(`quality takes --scope ${SCOPES.join(', ')}`);
98
+ const to = snapshotTree(ctx.root);
99
+ const { limits, ignored } = values.benchmark ? { limits: limitsFor(scope), ignored: [] } : resolveLimits({ global: ctx.configLayers[0], project: ctx.configLayers[1], scope });
100
+ if (scope === 'repo') {
101
+ const report = await repoQuality(ctx.root, { rev: to, limits, now: ctx.now() });
102
+ print({ ...report, scope, tree: to, ...(ignored.length ? { ignored_config: ignored } : {}) });
103
+ return report.ok ? 0 : 1;
104
+ }
105
+ const from = values.from ? resolveRef(ctx.root, values.from) : scope === 'commit' ? commitBase(ctx.root) : workBase(ctx.root);
106
+ const result = await qualityGate(ctx.root, { from, to, limits, now: ctx.now(), mode: values.benchmark ? 'benchmark' : 'project', repoFiles: listFiles(ctx.root, to) });
107
+ print({ ...result, scope, from, to, ...(ignored.length ? { ignored_config: ignored } : {}) });
108
+ return result.ok ? 0 : 1;
109
+ }
110
+
111
+ function plan(ctx, args) {
112
+ const { values } = parseArgs({ args, options: { done: { type: 'string' }, close: { type: 'boolean' } } });
113
+ if (values.close) return print(closePlan(ctx.root, ctx.env));
114
+ if (values.done !== undefined) return print(markMilestoneDone(ctx.root, Number(values.done)));
115
+ return print({ saved: savePlan(ctx.root, fs.readFileSync(0, 'utf8')), ...planStatus(ctx.root) });
116
+ }
117
+
118
+ // The probes do not need a repository, and a broken config is reported by the commands that need it.
119
+ function doctor(args) {
120
+ const { values } = parseArgs({ args, options: { host: { type: 'string' }, profile: { type: 'boolean' } } });
121
+ const host = values.host === 'claude' || values.host === 'copilot' ? values.host : detectHost();
122
+ if (values.profile) {
123
+ process.stdout.write(fs.readFileSync(path.join(PLUGIN_ROOT, 'profiles', `${host}.json`), 'utf8'));
124
+ return 0;
125
+ }
126
+ let root = process.cwd();
127
+ try { root = repoRoot(root); } catch { /* not in a repository */ }
128
+ let config = {};
129
+ try { config = loadConfig(root).config ?? {}; } catch { /* reported elsewhere */ }
130
+ const report = runDoctor({ root, host, config });
131
+ print(report);
132
+ return report.ok ? 0 : 1;
133
+ }
134
+
135
+ function slotCommand(ctx, args) {
136
+ const { values, positionals } = parseArgs({ args, allowPositionals: true, options: { mode: { type: 'string' }, project: { type: 'boolean' }, list: { type: 'boolean' }, remove: { type: 'boolean' }, confirm: { type: 'boolean' } } });
137
+ const [step, ref] = positionals;
138
+ if (values.list) print(listShards({ root: ctx.root, env: ctx.env }).map(({ step: s, ref: r, kind, mode, scope, state }) => ({ step: s, ref: r, kind, mode, scope, state })));
139
+ else if (values.confirm) print(confirmProjectShards({ root: ctx.root, env: ctx.env }));
140
+ else if (values.remove) print(unslot({ root: ctx.root, step, ref, project: values.project, env: ctx.env }));
141
+ else print(slot({ root: ctx.root, step, ref, mode: values.mode, project: values.project, env: ctx.env, now: ctx.now() }));
142
+ return 0;
143
+ }
144
+
145
+ function initCommand(ctx, args) {
146
+ const { values } = parseArgs({ args, options: { host: { type: 'string' } } });
147
+ if (values.host !== 'copilot') throw new StateError('init takes --host copilot; the Claude Code plugin needs no setup');
148
+ const extension = writeCopilotExtension(ctx.root, PLUGIN_ROOT);
149
+ const [duplicate] = duplicateHookWarnings(ctx.root);
150
+ print({ extension, workflows: 'Copilot runs workflows in experimental mode: start it with --experimental, or turn it on with /experimental.', ...(duplicate ? { warning: duplicate } : {}) });
151
+ return extension.written ? 0 : 1;
152
+ }
153
+
154
+ const printed = (value, ok = true) => { print(value); return ok ? 0 : 1; };
155
+
156
+ // Each command takes the project context and its own arguments, and returns the exit code.
157
+ const COMMANDS = {
158
+ route: (ctx, args) => {
159
+ const { values, positionals } = parseArgs({ args, allowPositionals: true, options: { hint: { type: 'string' }, sensitive: { type: 'boolean' } } });
160
+ return printed(advise(ctx, { request: positionals.join(' '), hint: values.hint, sensitive: values.sensitive }));
161
+ },
162
+ review: (ctx, args) => { review(ctx, args); return 0; },
163
+ quality,
164
+ check: (ctx, args) => {
165
+ const { values } = parseArgs({ args, options: { full: { type: 'boolean' }, scope: { type: 'string' } } });
166
+ if (values.scope !== undefined && !CHANGE_SCOPES.includes(values.scope)) throw new StateError(`check takes --scope ${CHANGE_SCOPES.join(' or ')}`);
167
+ const result = checkAndRecord(ctx, { full: values.full, scope: values.scope });
168
+ return printed(result, result.ok);
169
+ },
170
+ status: (ctx) => {
171
+ process.stdout.write(renderStatus({ plan: planStatus(ctx.root), ledger: readLedger(ctx.root, ctx.env), reviews: readReviews(ctx.root, ctx.env), check: lastCheck(ctx.root, ctx.env), migrated: migratedFindings(ctx.root, ctx.env) }));
172
+ return 0;
173
+ },
174
+ pr,
175
+ plan: (ctx, args) => { plan(ctx, args); return 0; },
176
+ setup: (ctx, args) => {
177
+ const { values } = parseArgs({ args, options: { host: { type: 'string' } } });
178
+ const result = setupAgent({ host: values.host === 'claude' || values.host === 'copilot' ? values.host : ctx.host, config: ctx.config, pluginRoot: PLUGIN_ROOT, env: ctx.env });
179
+ return printed(result, result.written);
180
+ },
181
+ slot: slotCommand,
182
+ ledger: (ctx, args) => {
183
+ const { values } = parseArgs({ args, options: { kind: { type: 'string' }, text: { type: 'string' } } });
184
+ return printed(addToLedger(ctx.root, { kind: values.kind, text: values.text }, ctx.env));
185
+ },
186
+ migrate: (ctx) => printed(migrate({ root: ctx.root, env: ctx.env, now: ctx.now })),
187
+ init: initCommand,
188
+ };
189
+
190
+ function main(argv) {
191
+ const [command, ...args] = argv;
192
+ if (command === 'doctor') return doctor(args);
193
+ const run = Object.hasOwn(COMMANDS, command ?? '') ? COMMANDS[command] : null;
194
+ if (!run) throw new StateError('somi takes route, review, check, quality, status, pr, plan, setup, slot, ledger, migrate, doctor or init');
195
+ return run(makeContext(), args);
196
+ }
197
+
198
+ function fail(e) {
199
+ const refused = e instanceof ReviewInputError || e instanceof StateError || e instanceof ShardError || e?.code?.startsWith?.('ERR_PARSE_ARGS');
200
+ process.stderr.write(`somi: ${refused ? e.message : e.stack ?? e}\n`);
201
+ process.exitCode = refused ? 64 : 70;
202
+ }
203
+
204
+ // Every command answers at once except the quality gate, which waits on its parser.
205
+ try {
206
+ const code = main(process.argv.slice(2));
207
+ if (code instanceof Promise) code.then((c) => { process.exitCode = c; }, fail); else process.exitCode = code;
208
+ } catch (e) { fail(e); }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Max Brunsfeld
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,16 @@
1
+ {
2
+ "registrations": [
3
+ {
4
+ "component": {
5
+ "type": "git",
6
+ "git": {
7
+ "name": "tree-sitter",
8
+ "repositoryUrl": "https://github.com/tree-sitter/tree-sitter",
9
+ "commitHash": "fc15f621334a262039ffaded5937e2844f88da61"
10
+ }
11
+ },
12
+ "license": "MIT",
13
+ "version": "0.25.1"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,59 @@
1
+ {
2
+ "note": "Vendored unchanged from the npm tarballs named here, fetched with npm pack, which checks the tarball integrity. The loader refuses any file whose sha256 does not match.",
3
+ "files": {
4
+ "web-tree-sitter.js": {
5
+ "package": "web-tree-sitter",
6
+ "version": "0.27.1",
7
+ "tarball_integrity": "sha512-qtx0VyUyNRHtL3ze7+v0hCKB/sLcAmY7ZAVp/ZK/bCj0yED8ptvNrr7Vd7DwDyKDWN9baqcUx4uaD2r2ql+6IA==",
8
+ "repository": "https://github.com/tree-sitter/tree-sitter",
9
+ "license": "MIT",
10
+ "bytes": 156132,
11
+ "sha256": "7c49e3c1d87e24e0bb4c2def909d17154dfde281f5f8280225450090bb4b8110"
12
+ },
13
+ "web-tree-sitter.wasm": {
14
+ "package": "web-tree-sitter",
15
+ "version": "0.27.1",
16
+ "tarball_integrity": "sha512-qtx0VyUyNRHtL3ze7+v0hCKB/sLcAmY7ZAVp/ZK/bCj0yED8ptvNrr7Vd7DwDyKDWN9baqcUx4uaD2r2ql+6IA==",
17
+ "repository": "https://github.com/tree-sitter/tree-sitter",
18
+ "license": "MIT",
19
+ "bytes": 210415,
20
+ "sha256": "beca80e44cccbf2299ed4d1e3fa6462a9a6fe818aeebf847547a392227ce4acc"
21
+ },
22
+ "tree-sitter-javascript.wasm": {
23
+ "package": "@vscode/tree-sitter-wasm",
24
+ "version": "0.3.1",
25
+ "tarball_integrity": "sha512-RJFoomET6FajjG511fmQxeBQfU6M24a0aFZPqpid+ttIxanWf1VGytBG0UmsGjt07qmIPJS8U31D+aecuCucsQ==",
26
+ "repository": "https://github.com/microsoft/vscode-tree-sitter-wasm",
27
+ "license": "MIT",
28
+ "bytes": 411770,
29
+ "sha256": "5fb488d0cabb4775a594bab85682de5ad6ce83c0d6ac997a9f82dd084d571240"
30
+ },
31
+ "tree-sitter-typescript.wasm": {
32
+ "package": "@vscode/tree-sitter-wasm",
33
+ "version": "0.3.1",
34
+ "tarball_integrity": "sha512-RJFoomET6FajjG511fmQxeBQfU6M24a0aFZPqpid+ttIxanWf1VGytBG0UmsGjt07qmIPJS8U31D+aecuCucsQ==",
35
+ "repository": "https://github.com/microsoft/vscode-tree-sitter-wasm",
36
+ "license": "MIT",
37
+ "bytes": 1413849,
38
+ "sha256": "778025db5a8be0e70f8ccc3671e486dfeddd048c25d9e8a70c26de2e1bf6f97d"
39
+ },
40
+ "tree-sitter-tsx.wasm": {
41
+ "package": "@vscode/tree-sitter-wasm",
42
+ "version": "0.3.1",
43
+ "tarball_integrity": "sha512-RJFoomET6FajjG511fmQxeBQfU6M24a0aFZPqpid+ttIxanWf1VGytBG0UmsGjt07qmIPJS8U31D+aecuCucsQ==",
44
+ "repository": "https://github.com/microsoft/vscode-tree-sitter-wasm",
45
+ "license": "MIT",
46
+ "bytes": 1445638,
47
+ "sha256": "79e5da75ea62855a0cd67177685f0164eac87d5f630b3cbe1e0a099751ad30f8"
48
+ },
49
+ "tree-sitter-css.wasm": {
50
+ "package": "@vscode/tree-sitter-wasm",
51
+ "version": "0.3.1",
52
+ "tarball_integrity": "sha512-RJFoomET6FajjG511fmQxeBQfU6M24a0aFZPqpid+ttIxanWf1VGytBG0UmsGjt07qmIPJS8U31D+aecuCucsQ==",
53
+ "repository": "https://github.com/microsoft/vscode-tree-sitter-wasm",
54
+ "license": "MIT",
55
+ "bytes": 128668,
56
+ "sha256": "8a23977fe271357cce6f254ef88c9bebf3854602d8046605aef6a45c02135c59"
57
+ }
58
+ }
59
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }