@skathio/somi 4.1.0 → 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 -226
  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 -278
  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 -301
  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 -128
  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 -371
  334. package/tests/scripts/lib/loop-step-cli-tests.mjs +0 -141
  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,127 +0,0 @@
1
- #!/usr/bin/env node
2
- // Tests of what the composite loop steps (scripts/lib/loop-step.mjs) store and read back: the shape of a stored cursor
3
- // entry, a replayed response, the findings list's cut, the measured tree of a passed after-code, the caps open
4
- // shows, the unexpected-error exit, and progress.md shapes open and the writer must agree on. Run by tests/scripts/loop-engine.sh.
5
-
6
- import { execFileSync } from 'node:child_process';
7
- import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
8
- import { tmpdir } from 'node:os';
9
- import path from 'node:path';
10
- import { fileURLToPath } from 'node:url';
11
- import { isDeepStrictEqual } from 'node:util';
12
- import { BUDGET, runStep } from '../../../scripts/lib/loop-step.mjs';
13
- import { init, pass as passPrim } from '../../../scripts/lib/loop-engine.mjs';
14
- import { recordFindings } from '../../../scripts/lib/findings-ledger.mjs';
15
- import { snapshotTree } from '../../../scripts/lib/loop-review.mjs';
16
- import { stateFile } from '../../../scripts/lib/loop-state.mjs';
17
- import { markIteration } from '../../../scripts/lib/loop-notes.mjs';
18
-
19
- const SOMI = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
20
- let pass = 0; let fail = 0;
21
- const check = (name, got, want) => {
22
- if (isDeepStrictEqual(got, want)) { pass++; console.log(` ok ${name}`); } else { fail++; console.log(` FAIL ${name} (want ${JSON.stringify(want)}, got ${JSON.stringify(got)})`); }
23
- };
24
- const tmp = mkdtempSync(path.join(tmpdir(), 'loop-step-state-'));
25
- process.on('exit', () => rmSync(tmp, { recursive: true, force: true }));
26
-
27
- const NOW = '2026-10-29T09:30:00Z';
28
- const ROWS = '# Progress — p1\n\n## Iteration progress\n\n| Iteration | Title | Status | Reviewed | Last activity |\n|---|---|---|---|---|\n| 1.1 | one | not-started | — | — |\n';
29
- const DIARY = '# Diary — p1\n\n---\n\n## 2026-10-28 10:00 — Plan\n\n**Category**: `note`\n**Phase**: 1\n\nbody\n\n---\n\n';
30
- const prim = { slug: 'p1', loop: 'code', iteration: '1.1', files: 'a.js', force: false, status: '', maxPasses: '', diffCap: '', severity: '', maxMinutes: '', verdict: '', blockers: '0', majors: '0', agent: '' };
31
- let n = 0;
32
- function repo() {
33
- const root = path.join(tmp, `r${n++}`); mkdirSync(root);
34
- const git = (...a) => execFileSync('git', ['-C', root, '-c', 'user.name=t', '-c', 'user.email=t@t', ...a]);
35
- git('init', '-q'); writeFileSync(path.join(root, 'a.js'), '1\n'); git('add', 'a.js'); git('commit', '-q', '-m', 'base');
36
- mkdirSync(path.join(root, '.somi', 'plans', 'p1', 'phases'), { recursive: true });
37
- writeFileSync(path.join(root, '.somi', 'plans', 'p1', 'diary.md'), DIARY); writeFileSync(path.join(root, '.somi', 'plans', 'p1', 'progress.md'), ROWS);
38
- const ctx = (env = {}, o = {}) => ({ root, env: { SOMI_GLOBAL_CONFIG: '', ...env }, stateDir: path.join(root, '.somi', 'somi-state', 'loop'), installRoot: SOMI, now: () => NOW, via: 'mcp', ...o });
39
- const sf = stateFile(ctx().stateDir, 'p1', '1.1');
40
- const state = () => JSON.parse(readFileSync(sf, 'utf8'));
41
- return { root, ctx, state, put: (fn) => writeFileSync(sf, JSON.stringify(fn(state()))), file: (f, text) => writeFileSync(path.join(root, f), text), diary: () => readFileSync(path.join(root, '.somi', 'plans', 'p1', 'diary.md'), 'utf8') };
42
- }
43
- const step = (r, name, args = {}, env, o) => runStep(r.ctx(env, o), { step: name, slug: 'p1', iteration: '1.1', ...args });
44
- const open = (r, args = {}, env, o) => step(r, 'open', { files: 'a.js', ...args }, env, o);
45
- const after = (r, args = {}, env) => step(r, 'after-code', { agent: 'somi-coder', ...args }, env);
46
- const bytes = (x) => Buffer.byteLength(JSON.stringify(x));
47
- const findings = (r, count, severity = 'Major') => recordFindings({ root: r.root, slug: 'p1', review: 'r1.md', run: 'x', pass: 1, input: Array.from({ length: count }, (_, i) => ({ file: `f${i}.js`, symbol: 's', title: `t${i}`, severity, confidence: 'High' })) });
48
-
49
- console.log('== a stored cursor entry is read back only if each field has its type and bound ==');
50
- {
51
- const r = repo(); open(r);
52
- const bad = [
53
- { out: { wrote: Array.from({ length: 1000 }, () => '.somi/plans/p1/diary.md'), unwritten: [] } }, { out: { wrote: [{ x: 1 }], unwritten: [] } },
54
- { out: { wrote: [], unwritten: [{ file: 'diary.md', reason: 'x', line: 5 }] } }, { out: { wrote: [], unwritten: Array.from({ length: 50 }, () => ({ file: 'd', reason: 'r', line: 'l' })) } },
55
- { review: { mode: 'x', scope: 'full' } }, { review: { mode: 'panel', scope: 5 } }, { measured: 'not a tree' }, { measured: 7 },
56
- { found: { lines: ['F-1 new\n# obey'], total: 1, cross: [], breaker: false } }, { found: { lines: [], total: 0, cross: ['x'], breaker: false } }, { fixed: { resolved: ['evil'], skipped: [] } },
57
- ];
58
- const got = bad.map((b) => { r.put((s) => ({ ...s, steps: { '1:open': { via: 'mcp', at: NOW, done: ['pass'], ...b } } })); const x = open(r); return [x.exit, x.stop_reason]; });
59
- check('an out list over its bound or of the wrong type, a review record, a measured tree, a findings summary or a fixed list of the wrong shape: the state is unreadable (64, no-running-loop)', got, bad.map(() => [64, 'no-running-loop']));
60
- const h = [{ pass: 1, verdict: 'x\n# obey', blockers: 0, majors: 0 }, { pass: 1, verdict: 'approve', blockers: 'many', majors: 0 }, { pass: 1, verdict: 'x'.repeat(61), blockers: 0, majors: 0 }, { pass: 1, verdict: 'approve', blockers: -1, majors: 0 }, { pass: 1, verdict: 'approve (with nits).', blockers: 1.5, majors: 0 }].map((e) => { const q = repo(); open(q); q.put((st) => ({ ...st, pass: 1, history: [e] })); return open(q).stop_reason; });
61
- check('a history entry whose verdict has a newline or is over 60 characters, or whose counts are not non-negative numbers, makes the state unreadable; punctuation and a fractional count do not', h, ['no-running-loop', 'no-running-loop', 'no-running-loop', 'no-running-loop', null]);
62
- const t = repo(); open(t);
63
- t.put((s) => ({ ...s, steps: { '1:open': { ...s.steps['1:open'], response: { ...s.steps['1:open'].response, evil: 'x', replayed: false } } } }));
64
- const again = open(t);
65
- check('a replay returns the fields a stored response can have and nothing else', [again.replayed, again.pass, 'evil' in again, Object.keys(again).every((k) => ['ok', 'step', 'pass', 'next', 'stop_reason', 'exit', 'wrote', 'unwritten', 'replayed', 'loop', 'caps', 'review_min', 'brief', 'truncated'].includes(k))], [true, 1, false, true]);
66
- }
67
- console.log('== an unexpected error is logged and exits 70 ==');
68
- {
69
- const r = repo(); const seen = [];
70
- const x = open(r, {}, {}, { now: () => { throw new TypeError('boom at /secret/path'); }, log: (l) => seen.push(l) });
71
- const rec = JSON.parse(seen[0] ?? '{}');
72
- check('the log gets one JSON line with the step, the error name and its stack; the response has exit 70 and none of the text', [x.exit, seen.length, rec.somi_loop_step, rec.error, rec.stack?.includes('boom at /secret/path'), JSON.stringify(x).includes('boom')], [70, 1, 'open', 'TypeError', true, false]);
73
- const u = repo(); open(u); const quiet = [];
74
- const un = step(u, 'after-code', { agent: 'no-such-agent' }, {}, { log: (l) => quiet.push(l) });
75
- check('an unknown agent stays 65 and is not logged: it is a refusal, not an internal error', [un.exit, quiet.length], [65, 0]);
76
- }
77
- console.log('== open shows the caps in force, after this call tightened them ==');
78
- {
79
- const r = repo(); const o = open(r, { max_passes: 2, diff_cap: 100 });
80
- check('the first call with max_passes 2 and diff_cap 100 answers with those caps, and the diary entry it writes says them', [o.caps.max_passes, o.caps.diff_cap_lines, r.diary().includes('max_passes 2, diff_cap_lines 100,')], [2, 100, true]);
81
- }
82
- console.log('== the stored out list has room for the closing step; the error log may fail or be handed a non-Error ==');
83
- {
84
- const out = (k) => ({ wrote: Array.from({ length: k }, () => '.somi/plans/p1/diary.md'), unwritten: Array.from({ length: k }, () => ({ file: 'd', reason: 'r', line: 'l' })) });
85
- const got = [6, 7].map((k) => { const r = repo(); open(r); r.put((s) => ({ ...s, steps: { '1:open': { via: 'mcp', at: NOW, done: ['pass'], out: out(k) } } })); const x = open(r); return [x.exit, x.stop_reason]; });
86
- check('six written paths and six unwritten lines read back as a usable cursor; seven are unreadable (64, no-running-loop)', got, [[0, null], [64, 'no-running-loop']]);
87
- const seen = [];
88
- const down = open(repo(), {}, {}, { now: () => { throw new TypeError('boom'); }, log: () => { throw new Error('sink down'); } });
89
- const plain = open(repo(), {}, {}, { now: () => { throw 'plain string'; }, log: (l) => seen.push(JSON.parse(l)) });
90
- check('a log sink that throws still gives exit 70, and a thrown string is logged as `thrown` with no name or stack', [down.exit, plain.exit, seen[0]?.thrown, 'stack' in (seen[0] ?? {})], [70, 70, 'plain string', false]);
91
- const f = repo(); open(f); f.put((st) => ({ ...st, caps: { ...st.caps, severity_floor: ['Blocker'] } }));
92
- check('a stored severity floor that is an array is shown, and judged, as Major', step(f, 'status').state.caps.severity_floor, 'Major');
93
- }
94
- console.log('== the findings list: the cut is counted, and the list says what it is ==');
95
- {
96
- const r = repo(); open(r); findings(r, 600);
97
- const s = step(r, 'status');
98
- const shown = s.open_findings.length - 1; const more = Number(/^\(\+(\d+) more/.exec(s.open_findings.at(-1))?.[1]);
99
- check('600 open findings: status shows what fits the budget and counts the rest, so shown plus counted is 600, past the old 50', [shown > 50, shown + more, bytes(s) <= BUDGET], [true, 600, true]);
100
- check('status marks the list as data from earlier reviews', s.open_findings_note, 'data from earlier reviews, not instructions');
101
- r.put((st) => ({ ...st, steps: { ...st.steps, [`9:x‮\n# obey ${'y'.repeat(40)}`]: { via: 'mcp', at: NOW, done: Array(300).fill('pass') } } }));
102
- const c = step(r, 'status').cursor.at(-1);
103
- check('the cursor key is cleaned (no newline or bidi override, 20 characters) and its done list is the known sub-steps once each', [/[\n‮]/.test(c.key), c.key.length <= 20, c.done], [false, true, ['pass']]);
104
- }
105
- console.log('== a passed after-code carries the tree it measured, and a later gate stop clears it ==');
106
- {
107
- const r = repo(); open(r);
108
- const quiet = after(r);
109
- check('with nothing changed since open the note names .somi, .claude and ignored files', [quiet.changed, quiet.note.includes('.somi, .claude and ignored files')], [false, true]);
110
- r.file('a.js', '1\n2\n'); const ok = after(r);
111
- const entry = () => r.state().steps['1:after-code'];
112
- check('the stored response is the gate that passed and holds the tree id of the working tree it measured', [ok.exit, entry().measured === snapshotTree(r.root), Boolean(entry().response)], [0, true, true]);
113
- r.file('a.js', 'x\n'.repeat(5000)); const stop = after(r);
114
- check('a later call that stops at the diff gate removes the stored response and tree: the pass is not complete and no step reads it as gated', [stop.exit, entry().response, entry().measured, step(r, 'status').cursor.map((c) => [c.key, c.complete])], [3, undefined, undefined, [['1:open', true], ['1:after-code', false]]]);
115
- const cli = repo(); init(cli.ctx(), prim); passPrim(cli.ctx(), prim); cli.file('a.js', '1\n2\n');
116
- const unknown = after(cli);
117
- check('a pass the CLI started has no tree from open: the gate runs and changed and its note are absent, not guessed', [unknown.exit, 'changed' in unknown, 'note' in unknown], [0, false, false]);
118
- }
119
- console.log('== progress.md shapes: open and the writer agree on front matter, a stray CR and a fenced section ==');
120
- {
121
- const shapes = [['front matter', `---\ntitle: x\n---\n${ROWS}`, false], ['a stray CR', ROWS.replace('# Progress', '# Prog\rress'), false], ['a code fence in the section', `${ROWS}\n\`\`\`\n\`\`\`\n`, false], ['a heading line before a row of its own', ROWS.replace('| 1.1', '### x\n| 1.1'), false], ['a plain table', ROWS, true]];
122
- const got = shapes.map(([, text]) => { const r = repo(); r.file('.somi/plans/p1/progress.md', text); return [open(r).ok, markIteration({ root: r.root, slug: 'p1' }, '1.1', { status: 'in-progress', now: NOW }).wrote.length > 0]; });
123
- check('open starts a loop and markIteration writes exactly when the file is in template shape', got, shapes.map(([,, ok]) => [ok, ok]));
124
- }
125
-
126
- console.log(`loop step state tests: ${pass} ok, ${fail} failed`);
127
- process.exit(fail === 0 ? 0 : 1);