@skathio/somi 4.0.0 → 4.1.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 (163) hide show
  1. package/.claude/settings.json +1 -1
  2. package/.claude-plugin/marketplace.json +1 -1
  3. package/.claude-plugin/plugin.json +1 -1
  4. package/.copilot-extension/extension.json +1 -1
  5. package/.copilot-extension/marketplace.json +1 -1
  6. package/README.md +11 -5
  7. package/VERSION +1 -1
  8. package/agents/somi-coder.md +4 -228
  9. package/agents/somi-designer.md +4 -160
  10. package/agents/somi-discovery-analyst.md +4 -276
  11. package/agents/somi-flow.md +47 -0
  12. package/agents/somi-general.md +36 -0
  13. package/agents/somi-planner.md +4 -341
  14. package/agents/somi-reviewer.md +4 -199
  15. package/agents/somi.md +81 -253
  16. package/commands/adopt.md +6 -84
  17. package/commands/architecture-review.md +11 -86
  18. package/commands/atlas.md +10 -25
  19. package/commands/code-loop.md +10 -221
  20. package/commands/code-parallel.md +10 -151
  21. package/commands/code.md +9 -157
  22. package/commands/debug.md +9 -131
  23. package/commands/design.md +9 -160
  24. package/commands/discover.md +9 -194
  25. package/commands/impact.md +9 -25
  26. package/commands/incident.md +9 -39
  27. package/commands/plan-loop.md +9 -181
  28. package/commands/plan.md +9 -244
  29. package/commands/pr.md +10 -25
  30. package/commands/refactor-design.md +11 -89
  31. package/commands/refactor.md +11 -50
  32. package/commands/release-readiness.md +11 -70
  33. package/commands/review-panel.md +10 -141
  34. package/commands/review.md +11 -181
  35. package/commands/security-review.md +11 -75
  36. package/commands/ship-loop.md +9 -260
  37. package/commands/ship.md +9 -115
  38. package/commands/somi-config.md +12 -124
  39. package/commands/test-strategy.md +11 -75
  40. package/commands/upgrade.md +9 -72
  41. package/hooks/hooks.json +1 -1
  42. package/hooks/lib/common.mjs +15 -13
  43. package/hooks/pre-tool/block-dangerous-bash.mjs +1 -1
  44. package/hooks/pre-tool/block-secret-writes.mjs +5 -7
  45. package/hooks/pre-tool/guard-cost-lowering.mjs +26 -11
  46. package/hooks/pre-tool/guard-protected-paths.mjs +54 -34
  47. package/hooks/session-start/ensure-default-config.mjs +34 -42
  48. package/package.json +1 -1
  49. package/scripts/lib/config-files.mjs +145 -0
  50. package/scripts/lib/cost-ceiling.mjs +29 -22
  51. package/scripts/lib/cost-defaults.mjs +2 -0
  52. package/scripts/lib/escalation-facts.mjs +146 -0
  53. package/scripts/lib/escalation.mjs +129 -0
  54. package/scripts/lib/findings-ledger.mjs +241 -0
  55. package/scripts/lib/install-text.mjs +97 -0
  56. package/scripts/lib/loop-caps.mjs +140 -0
  57. package/scripts/lib/loop-diff.mjs +12 -70
  58. package/scripts/lib/loop-engine.mjs +226 -0
  59. package/scripts/lib/loop-escalate.mjs +49 -0
  60. package/scripts/lib/loop-exit.mjs +47 -0
  61. package/scripts/lib/loop-notes-compact.mjs +72 -0
  62. package/scripts/lib/loop-notes.mjs +278 -0
  63. package/scripts/lib/loop-review.mjs +355 -12
  64. package/scripts/lib/loop-state.mjs +44 -0
  65. package/scripts/lib/loop-step-close.mjs +75 -0
  66. package/scripts/lib/loop-step-kit.mjs +179 -0
  67. package/scripts/lib/loop-step-review.mjs +140 -0
  68. package/scripts/lib/loop-step-tool.mjs +89 -0
  69. package/scripts/lib/loop-step.mjs +301 -0
  70. package/scripts/lib/mcp-project-root.mjs +18 -7
  71. package/scripts/lib/path-facts.mjs +187 -0
  72. package/scripts/lib/path-safety.mjs +171 -0
  73. package/scripts/lib/run-card.mjs +73 -0
  74. package/scripts/size-budget-overrides.json +5 -13
  75. package/scripts/somi-card.mjs +39 -0
  76. package/scripts/somi-check.mjs +4 -3
  77. package/scripts/somi-config.mjs +113 -50
  78. package/scripts/somi-findings.mjs +56 -271
  79. package/scripts/somi-loop.mjs +77 -446
  80. package/scripts/somi-mcp.mjs +27 -96
  81. package/scripts/validate.sh +92 -54
  82. package/skills/flow-adopt/SKILL.md +92 -0
  83. package/skills/flow-architecture-review/SKILL.md +94 -0
  84. package/skills/flow-atlas/SKILL.md +34 -0
  85. package/skills/flow-code/SKILL.md +167 -0
  86. package/skills/flow-code-loop/SKILL.md +263 -0
  87. package/skills/flow-code-parallel/SKILL.md +160 -0
  88. package/skills/flow-debug/SKILL.md +141 -0
  89. package/skills/flow-design/SKILL.md +170 -0
  90. package/skills/flow-discover/SKILL.md +204 -0
  91. package/skills/flow-impact/SKILL.md +35 -0
  92. package/skills/flow-incident/SKILL.md +49 -0
  93. package/skills/flow-plan/SKILL.md +254 -0
  94. package/skills/flow-plan-loop/SKILL.md +254 -0
  95. package/skills/flow-pr/SKILL.md +34 -0
  96. package/skills/flow-refactor/SKILL.md +58 -0
  97. package/skills/flow-refactor-design/SKILL.md +97 -0
  98. package/skills/flow-release-readiness/SKILL.md +82 -0
  99. package/skills/flow-review/SKILL.md +193 -0
  100. package/skills/flow-review-panel/SKILL.md +154 -0
  101. package/skills/flow-security-review/SKILL.md +83 -0
  102. package/skills/flow-ship/SKILL.md +125 -0
  103. package/skills/flow-ship-loop/SKILL.md +274 -0
  104. package/skills/flow-somi-config/SKILL.md +142 -0
  105. package/skills/flow-status/SKILL.md +43 -0
  106. package/skills/flow-test-strategy/SKILL.md +83 -0
  107. package/skills/flow-upgrade/SKILL.md +82 -0
  108. package/skills/role-coder/SKILL.md +247 -0
  109. package/skills/role-designer/SKILL.md +172 -0
  110. package/skills/role-discovery-analyst/SKILL.md +288 -0
  111. package/skills/role-planner/SKILL.md +353 -0
  112. package/skills/role-reviewer/SKILL.md +218 -0
  113. package/skills/somi-checkpoint/SKILL.md +95 -0
  114. package/skills/somi-dispatch/SKILL.md +14 -14
  115. package/skills/somi-routing/SKILL.md +6 -2
  116. package/tests/hooks/cases/block-secret-writes.json +6 -1
  117. package/tests/hooks/cases/guard-protected-paths.json +44 -2
  118. package/tests/hooks/run.sh +21 -0
  119. package/tests/scripts/checkpoint-gate.sh +2 -2
  120. package/tests/scripts/cost-defaults.sh +2 -0
  121. package/tests/scripts/cost-hardcap.sh +26 -17
  122. package/tests/scripts/dispatch-line-gate.sh +4 -4
  123. package/tests/scripts/dispatch-reference-gate.sh +14 -14
  124. package/tests/scripts/ensure-default-config.sh +4 -4
  125. package/tests/scripts/escalation.sh +409 -0
  126. package/tests/scripts/eval-runner.sh +8 -7
  127. package/tests/scripts/fact-sheet.sh +296 -0
  128. package/tests/scripts/global-config.sh +167 -0
  129. package/tests/scripts/goldens/somi-loop.json +2 -2
  130. package/tests/scripts/lib/dispatch-reference-gate.mjs +14 -5
  131. package/tests/scripts/lib/escalation-facts-tests.mjs +140 -0
  132. package/tests/scripts/lib/escalation-tests.mjs +154 -0
  133. package/tests/scripts/lib/findings-ledger-tests.mjs +118 -0
  134. package/tests/scripts/lib/loop-engine-tests.mjs +287 -0
  135. package/tests/scripts/lib/loop-escalate-tests.mjs +356 -0
  136. package/tests/scripts/lib/loop-flow-gate.mjs +173 -0
  137. package/tests/scripts/lib/loop-notes-tests.mjs +371 -0
  138. package/tests/scripts/lib/loop-step-cli-tests.mjs +141 -0
  139. package/tests/scripts/lib/loop-step-close-tests.mjs +351 -0
  140. package/tests/scripts/lib/loop-step-lenient-tests.mjs +114 -0
  141. package/tests/scripts/lib/loop-step-state-tests.mjs +127 -0
  142. package/tests/scripts/lib/loop-step-tests.mjs +499 -0
  143. package/tests/scripts/lib/loop-step-unwritten-tests.mjs +55 -0
  144. package/tests/scripts/lib/path-facts-tests.mjs +198 -0
  145. package/tests/scripts/lib/path-safety-tests.mjs +201 -0
  146. package/tests/scripts/lib/run-suites.mjs +139 -0
  147. package/tests/scripts/lib/site-roadmap-gate.mjs +64 -0
  148. package/tests/scripts/lib/sizing-score-tests.mjs +210 -0
  149. package/tests/scripts/lib/sizing-set-tests.mjs +131 -0
  150. package/tests/scripts/lib/somi-mcp-loop-tests.mjs +226 -0
  151. package/tests/scripts/lib/somi-mcp-tests.mjs +21 -1
  152. package/tests/scripts/loop-engine.sh +22 -0
  153. package/tests/scripts/loop-flow-gate.sh +11 -0
  154. package/tests/scripts/review-panel-seats.sh +4 -4
  155. package/tests/scripts/run-card.sh +57 -0
  156. package/tests/scripts/run-suites.sh +74 -0
  157. package/tests/scripts/run.sh +11 -0
  158. package/tests/scripts/site-roadmap-gate.sh +76 -0
  159. package/tests/scripts/size-tier.sh +3 -3
  160. package/tests/scripts/somi-agent-dispatch-contract.sh +23 -3
  161. package/tests/scripts/somi-config.sh +9 -4
  162. package/tests/scripts/somi-mcp.sh +1 -0
  163. package/tests/scripts/suite-plan.json +20 -0
@@ -13,6 +13,10 @@
13
13
  // install directory can't be followed from a consuming project, so its text is served over the
14
14
  // same stdio channel instead.
15
15
  //
16
+ // The tool logic lives in scripts/lib/, one module per tool family: loop-step-tool.mjs (`somi_loop`),
17
+ // install-text.mjs (`somi_command`, `somi_skill`, `somi_agent`) and agent-info.mjs (`somi_agent_info`).
18
+ // This file keeps the JSON-RPC framing, the roots/list round trip and the tool table.
19
+ //
16
20
  // Hand-rolled, on purpose (zero dependencies — no MCP SDK): newline-delimited JSON-RPC 2.0 over
17
21
  // stdio, one JSON object per line either direction, matching the MCP stdio transport's own framing
18
22
  // rule. Nothing but JSON-RPC ever reaches stdout; every diagnostic goes to stderr, so a stray
@@ -28,15 +32,11 @@ import { spawnSync } from 'node:child_process';
28
32
  import fs from 'node:fs';
29
33
  import path from 'node:path';
30
34
  import { fileURLToPath } from 'node:url';
31
- import {
32
- resolveDispatch,
33
- validateDispatchArgs,
34
- AGENT_NAME_RE,
35
- EXIT_USAGE,
36
- EXIT_UNKNOWN_AGENT,
37
- } from './lib/dispatch-resolver.mjs';
35
+ import { resolveDispatch, validateDispatchArgs } from './lib/dispatch-resolver.mjs';
38
36
  import { resolveProjectRoot } from './lib/mcp-project-root.mjs';
39
37
  import { AGENT_INFO_TOOL, agentInfo } from './lib/agent-info.mjs';
38
+ import { INSTALL_TEXT_TOOLS, installText } from './lib/install-text.mjs';
39
+ import { LOOP_TOOL, callLoopStep } from './lib/loop-step-tool.mjs';
40
40
  import { SIGNAL_IDS } from './lib/size-tier.mjs';
41
41
 
42
42
  const PROG = 'somi-dispatch'; // shared identity with the CLI: this is the SAME resolver speaking.
@@ -149,55 +149,11 @@ const TOOLS = [
149
149
  },
150
150
  },
151
151
  AGENT_INFO_TOOL,
152
- {
153
- name: 'somi_command',
154
- description:
155
- "Read a SoMi command's own procedure text (commands/<name>.md) from the install root, so " +
156
- 'a front door running in a consuming project can follow it live without knowing where SoMi ' +
157
- 'is installed.',
158
- inputSchema: {
159
- type: 'object',
160
- properties: {
161
- name: { type: 'string', description: 'command name, e.g. "plan" (matches ^[a-z][a-z0-9-]*$)' },
162
- },
163
- required: ['name'],
164
- },
165
- },
166
- {
167
- name: 'somi_skill',
168
- description:
169
- "Read a SoMi skill's own text (skills/<name>/SKILL.md) from the install root — the same " +
170
- 'problem `somi_command` solves for commands/, applied to skills/: a reference to a skill from ' +
171
- "a consuming project can't rely on a relative link into SoMi's own install directory, since " +
172
- "that directory generally isn't the consuming project's own tree. Read the dispatch " +
173
- 'procedure this way (`somi_skill({name: "somi-dispatch"})`) whenever the skill can\'t be ' +
174
- 'loaded by name on the current host (e.g. no Skill tool, or a non-Claude-Code host).',
175
- inputSchema: {
176
- type: 'object',
177
- properties: {
178
- name: { type: 'string', description: 'skill name, e.g. "somi-dispatch" (matches ^[a-z][a-z0-9-]*$)' },
179
- },
180
- required: ['name'],
181
- },
182
- },
183
- {
184
- name: 'somi_agent',
185
- description:
186
- "Read a SoMi agent's instructions (agents/<name>.md, frontmatter removed) from the install " +
187
- 'root, to inspect or quote them. Not a way to run the agent: start it as the agent_type ' +
188
- 'somi_resolve returns, never as another agent given this text.',
189
- inputSchema: {
190
- type: 'object',
191
- properties: {
192
- name: { type: 'string', description: 'agent name, e.g. "somi-reviewer" (matches ^[a-z][a-z0-9-]*$)' },
193
- },
194
- required: ['name'],
195
- },
196
- },
152
+ ...INSTALL_TEXT_TOOLS,
197
153
  {
198
154
  name: 'somi_config',
199
155
  description:
200
- 'Show or change the cost settings in the project\'s .somi/config.json by running ' +
156
+ 'Show the cost settings (the user\'s global config with the project\'s .somi/config.json merged over it) or change the project file, by running ' +
201
157
  '`node scripts/somi-config.mjs`, and return its one JSON line unchanged. Actions: show ' +
202
158
  '(every agent\'s effective tier and warnings), get, set, unset, init (create the default file ' +
203
159
  'when absent). cost.ceiling and cost.agents.<name> take low|medium|high; ' +
@@ -247,6 +203,7 @@ const TOOLS = [
247
203
  required: ['signals'],
248
204
  },
249
205
  },
206
+ LOOP_TOOL,
250
207
  ];
251
208
 
252
209
  // --- tool implementations --------------------------------------------------------------------
@@ -299,40 +256,16 @@ async function callSomiAgentInfo(args) {
299
256
  return outcome.ok ? textResult(JSON.stringify(outcome.result)) : textResult(`somi-agent-info: ${outcome.message} (exit ${outcome.code})`, true);
300
257
  }
301
258
 
302
- // One reader for every install-root text tool. The name is checked against AGENT_NAME_RE BEFORE
303
- // any path is built, so a traversal payload (`../x`, `a/b`) is a 64 and never reaches path.join.
304
- // JSON.stringify, not a template interpolation, for the invalid name: an object-shaped `name`
305
- // (e.g. `{toString: null}`) throws inside `${name}` and would surface as an unrelated -32603.
306
- function readInstallText(prog, kind, name, relPath) {
307
- if (typeof name !== 'string' || !AGENT_NAME_RE.test(name)) {
308
- return { error: textResult(`${prog}: invalid name ${JSON.stringify(name)} (expected ${AGENT_NAME_RE}) (exit ${EXIT_USAGE})`, true) };
309
- }
310
- const filePath = path.join(installRoot(), ...relPath(name));
311
- try {
312
- return { content: fs.readFileSync(filePath, 'utf8') };
313
- } catch (e) {
314
- if (e.code === 'ENOENT') {
315
- return { error: textResult(`${prog}: unknown ${kind} "${name}" (no ${filePath}) (exit ${EXIT_UNKNOWN_AGENT})`, true) };
316
- }
317
- throw e;
318
- }
319
- }
320
-
321
- function callSomiCommand(args) {
322
- const r = readInstallText('somi-command', 'command', args?.name, (n) => ['commands', `${n}.md`]);
323
- return r.error ?? textResult(r.content);
259
+ // Install-root text tools; the logic lives in lib/install-text.mjs, this only supplies the install root.
260
+ function callInstallText(kind, args) {
261
+ const outcome = installText(kind, args, { installRoot: installRoot() });
262
+ return outcome.ok ? textResult(outcome.text) : textResult(`somi-${kind}: ${outcome.message} (exit ${outcome.code})`, true);
324
263
  }
325
264
 
326
- function callSomiSkill(args) {
327
- const r = readInstallText('somi-skill', 'skill', args?.name, (n) => ['skills', n, 'SKILL.md']);
328
- return r.error ?? textResult(r.content);
329
- }
330
-
331
- // The agent's instructions without its frontmatter, for reading. Dispatch never uses this: an agent
332
- // starts as its registered agent_type (see skills/somi-dispatch §5), so the text is never a payload.
333
- function callSomiAgent(args) {
334
- const r = readInstallText('somi-agent', 'agent', args?.name, (n) => ['agents', `${n}.md`]);
335
- return r.error ?? textResult(r.content.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n/, '').trimStart());
265
+ // Loop steps; the logic lives in lib/loop-step-tool.mjs, this only supplies the root lookup, the env and the install root.
266
+ async function callSomiLoop(args) {
267
+ const out = await callLoopStep(args, { resolveRoot: (projectDirArg) => resolveProjectRoot({ projectDirArg, listRoots: () => listClientRoots() }), env: process.env, installRoot: installRoot() });
268
+ return textResult(out.text, out.isError);
336
269
  }
337
270
 
338
271
  // Runs the sizing CLI itself, so the result and the exit codes are the CLI's, byte for byte.
@@ -359,16 +292,13 @@ async function callSomiConfig(args) {
359
292
  if (!text(args.key) || !text(args.value) || [args.key, args.value].some((v) => v !== undefined && (v === '' || v.startsWith('-') || /[\u0000-\u001f\u007f]/.test(v)))) {
360
293
  return textResult('somi-config: key and value must be non-empty strings without control characters that do not start with a dash (exit 64)', true);
361
294
  }
295
+ const rootOutcome = await resolveProjectRoot({ projectDirArg: args.project_dir, listRoots: () => listClientRoots() });
362
296
  // Writes need a root the HOST supplied: a model-supplied project_dir alone could point a write anywhere.
363
- // The probe (no project_dir) succeeds, or fails as ambiguous, only when the host offered a root.
364
- if (args.action !== 'show' && args.action !== 'get') {
365
- const probe = await resolveProjectRoot({ projectDirArg: undefined, listRoots: () => listClientRoots() });
366
- if (!probe.ok && !probe.message.startsWith('ambiguous')) {
367
- return textResult('somi-config: no host project root; run the CLI yourself (node scripts/somi-config.mjs) to change the config (exit 67)', true);
368
- }
297
+ const writes = args.action !== 'show' && args.action !== 'get';
298
+ if (!rootOutcome.ok && (rootOutcome.hosted !== false || !writes)) return textResult(`somi-config: ${rootOutcome.message} (exit ${rootOutcome.code})`, true);
299
+ if (writes && rootOutcome.hosted !== true) {
300
+ return textResult('somi-config: no host project root; run the CLI yourself (node scripts/somi-config.mjs) to change the config (exit 67)', true);
369
301
  }
370
- const rootOutcome = await resolveProjectRoot({ projectDirArg: args.project_dir, listRoots: () => listClientRoots() });
371
- if (!rootOutcome.ok) return textResult(`somi-config: ${rootOutcome.message} (exit ${rootOutcome.code})`, true);
372
302
  const argv = [path.join(installRoot(), 'scripts', 'somi-config.mjs'), args.action];
373
303
  if (args.key !== undefined) argv.push(args.key);
374
304
  if (args.value !== undefined) argv.push(args.value);
@@ -394,11 +324,12 @@ async function callTool(name, args) {
394
324
  switch (name) {
395
325
  case 'somi_resolve': return await callSomiResolve(args || {});
396
326
  case 'somi_agent_info': return await callSomiAgentInfo(args || {});
397
- case 'somi_command': return callSomiCommand(args || {});
398
- case 'somi_skill': return callSomiSkill(args || {});
399
- case 'somi_agent': return callSomiAgent(args || {});
327
+ case 'somi_command': return callInstallText('command', args || {});
328
+ case 'somi_skill': return callInstallText('skill', args || {});
329
+ case 'somi_agent': return callInstallText('agent', args || {});
400
330
  case 'somi_tier': return callSomiTier(args || {});
401
331
  case 'somi_config': return await callSomiConfig(args || {});
332
+ case 'somi_loop': return await callSomiLoop(args || {});
402
333
  default: return null;
403
334
  }
404
335
  }
@@ -7,6 +7,17 @@
7
7
  # stub so the hashira-ops CI coverage-report action has a file to parse (no unit test suite).
8
8
  set -euo pipefail
9
9
 
10
+ # Hermetic: no suite may read the developer's own global SoMi config (scripts/lib/config-files.mjs).
11
+ # An empty value means "no global config"; suites that test the global file set their own.
12
+ export SOMI_GLOBAL_CONFIG=""
13
+
14
+ # Test scripts are queued with suite() as the checks below reach them, then run together by
15
+ # tests/scripts/lib/run-suites.mjs (SOMI_TEST_JOBS at a time, default half the cores; 1 runs them serially) under
16
+ # tests/scripts/suite-plan.json: its alone scripts run by themselves, and SOMI_SUITE_SHARD (all, light, heavy-1..3)
17
+ # picks the part of the queue to run, so CI can spread the slow scripts over several runners. Default: all.
18
+ SUITES=()
19
+ suite() { SUITES+=("$1"); }
20
+
10
21
  # JSON validity via Node's own parser (no jq). Fails loudly on the first invalid file.
11
22
  json_valid() { node -e 'JSON.parse(require("fs").readFileSync(process.argv[1],"utf8"))' "$1"; }
12
23
 
@@ -38,57 +49,64 @@ for f in tests/hooks/cases/*.json; do
38
49
  echo " node JSON.parse: $f"
39
50
  json_valid "$f"
40
51
  done
41
- bash tests/hooks/run.sh
52
+ suite tests/hooks/run.sh
42
53
 
43
- echo "==> Loop-state & findings-ledger tests..."
44
- bash tests/scripts/run.sh
54
+ echo "==> Loop-state & findings-ledger tests... (queued)"
55
+ suite tests/scripts/run.sh
56
+ suite tests/scripts/loop-engine.sh
57
+ suite tests/scripts/run-card.sh
45
58
 
46
- echo "==> Link-checker tests..."
47
- bash tests/scripts/check-links.sh
59
+ echo "==> Link-checker tests... (queued)"
60
+ suite tests/scripts/check-links.sh
48
61
 
49
- echo "==> Session-artefact gate tests..."
62
+ echo "==> Session-artefact gate tests... (queued)"
50
63
  # Guards scripts/check-session-artefacts.mjs: fails on a tagged comment, passes a clean one, and
51
64
  # honours its explicit exclusions.
52
- bash tests/scripts/check-session-artefacts.sh
65
+ suite tests/scripts/check-session-artefacts.sh
53
66
 
54
- echo "==> Frontmatter gate tests..."
67
+ echo "==> Frontmatter gate tests... (queued)"
55
68
  # Guards scripts/check-frontmatter.mjs: the plain-scalar forms YAML rejects fail, quoted ones pass.
56
- bash tests/scripts/check-frontmatter.sh
69
+ suite tests/scripts/check-frontmatter.sh
57
70
 
58
- echo "==> File-size budget gate tests..."
71
+ echo "==> File-size budget gate tests... (queued)"
59
72
  # Guards scripts/check-size-budget.mjs: an un-ledgered oversized file fails, a ledgered file may
60
73
  # shrink but not grow, a stale entry warns, a malformed ledger fails loudly.
61
- bash tests/scripts/check-size-budget.sh
74
+ suite tests/scripts/check-size-budget.sh
62
75
 
63
- echo "==> Digest-generator tests..."
76
+ echo "==> Digest-generator tests... (queued)"
64
77
  # Guards scripts/generate-digest.mjs: per-target prefix transform, drift detection in EITHER
65
78
  # copy alone, clean errors on malformed input, and splice anchoring. Wiring `--check` itself
66
79
  # into this script is the separate "Validating digest parity" step below — this is the
67
80
  # unit guard for the generator, not the drift gate.
68
- bash tests/scripts/generate-digest.sh
81
+ suite tests/scripts/generate-digest.sh
82
+
83
+ echo "==> Cost model resolver tests... (queued)"
84
+ suite tests/scripts/cost-model.sh
69
85
 
70
- echo "==> Cost model resolver tests..."
71
- bash tests/scripts/cost-model.sh
86
+ echo "==> Cost ceiling tests... (queued)"
87
+ suite tests/scripts/cost-ceiling.sh
72
88
 
73
- echo "==> Cost ceiling tests..."
74
- bash tests/scripts/cost-ceiling.sh
89
+ echo "==> Global config, merge and reads through links... (queued)"
90
+ suite tests/scripts/global-config.sh
75
91
 
76
- echo "==> Dispatch resolver tests..."
77
- bash tests/scripts/somi-dispatch.sh
78
- bash tests/scripts/size-tier.sh
92
+ echo "==> Dispatch resolver tests... (queued)"
93
+ suite tests/scripts/somi-dispatch.sh
94
+ suite tests/scripts/size-tier.sh
95
+ suite tests/scripts/fact-sheet.sh
96
+ suite tests/scripts/escalation.sh
79
97
 
80
- echo "==> Front-door agent <-> dispatch resolver contract tests..."
98
+ echo "==> Front-door agent <-> dispatch resolver contract tests... (queued)"
81
99
  # agents/somi.md is a prompt and can't be exercised without a model, but what its Step 4 tells the
82
100
  # model to RUN can be checked deterministically: the resolve --agent/--host invocation shape it
83
101
  # instructs, and the exit codes it maps, must both be real and current against the actual CLI.
84
- bash tests/scripts/somi-agent-dispatch-contract.sh
102
+ suite tests/scripts/somi-agent-dispatch-contract.sh
85
103
 
86
- echo "==> Bundled MCP server tests (somi_resolve / somi_command)..."
104
+ echo "==> Bundled MCP server tests (somi_resolve / somi_command)... (queued)"
87
105
  # scripts/somi-mcp.mjs is the MCP-native equivalent of the CLI above, launched from
88
106
  # ${CLAUDE_PLUGIN_ROOT}/${PLUGIN_ROOT} so a prompt never needs an install path. Both wrap the
89
107
  # identical scripts/lib/dispatch-resolver.mjs, so this drives the real JSON-RPC stdio protocol
90
108
  # rather than re-testing the resolver's arithmetic a third time.
91
- bash tests/scripts/somi-mcp.sh
109
+ suite tests/scripts/somi-mcp.sh
92
110
 
93
111
  echo "==> Validating the dispatch guard (no caller ignoring per-agent overrides)..."
94
112
  # scripts/lib/cost-ceiling.mjs's modelForDispatch() is the ONLY sanctioned way to turn a dispatch
@@ -117,7 +135,7 @@ fi
117
135
  if [ "$dispatch_guard_failed" -ne 0 ]; then
118
136
  exit 1
119
137
  fi
120
- bash tests/scripts/dispatch-guard.sh
138
+ suite tests/scripts/dispatch-guard.sh
121
139
 
122
140
  echo "==> Diary compaction rule present in the template..."
123
141
  # The rule must stay triggered and concrete: a numeric trigger, a verbatim move to diary-archive.md,
@@ -129,39 +147,39 @@ for pat in 'more than 40' 'diary-archive\.md' 'verbatim' 'Never move a `decision
129
147
  done
130
148
  echo " ok: $DIARY_TMPL"
131
149
 
132
- echo "==> Eval fixture guards..."
150
+ echo "==> Eval fixture guards... (queued)"
133
151
  # Guards tests/evals/fixtures/. Two defects are guarded here: a plan tree shipped
134
152
  # under `.somi/` that .gitignore silently dropped from the package, and pass criteria
135
153
  # written into fixture source as comments the candidate reads — which would have flatlined two
136
154
  # load-bearing rubric dimensions at pass in BOTH arms of the trim comparison, reporting no
137
155
  # regression on exactly what the corpus exists to protect.
138
- if [ -d tests/evals ]; then bash tests/scripts/evals-fixtures.sh; else echo " (skipped: tests/evals not packaged)"; fi
156
+ if [ -d tests/evals ]; then suite tests/scripts/evals-fixtures.sh; else echo " (skipped: tests/evals not packaged)"; fi
139
157
 
140
- echo "==> Eval runner unit tests..."
158
+ echo "==> Eval runner unit tests... (queued)"
141
159
  # Guards tests/evals/run.mjs: the N-of-M grading bands, the trim-comparison rule, the result
142
160
  # schema, and --source worktree cleanup. Hermetic -- every case is --dry-run or a direct call.
143
161
  # This runs the runner's UNIT tests; it never invokes the runner against a model. The structural
144
162
  # assertion that npm test cannot execute the runner lives inside eval-runner.sh itself.
145
- if [ -d tests/evals ]; then bash tests/scripts/eval-runner.sh; else echo " (skipped: tests/evals not packaged)"; fi
163
+ if [ -d tests/evals ]; then suite tests/scripts/eval-runner.sh; else echo " (skipped: tests/evals not packaged)"; fi
146
164
 
147
- echo "==> Convergence gate CLI unit tests..."
165
+ echo "==> Convergence gate CLI unit tests... (queued)"
148
166
  # Guards tests/evals/convergence.mjs's CLI section: argument parsing, --dry-run's shape/zero-model-call
149
167
  # contract, --merge/--certify's shard-fold report, and the sha boundary check. Mirrors
150
168
  # eval-runner.sh's own pattern -- unit-tests the gate logic, never a live run. The module's
151
169
  # non-CLI logic is already covered by eval-runner.sh; this file is scoped to the CLI section
152
170
  # alone, so the two stay disjoint rather than duplicating each other.
153
- if [ -d tests/evals ]; then bash tests/scripts/convergence-runner.sh; else echo " (skipped: tests/evals not packaged)"; fi
171
+ if [ -d tests/evals ]; then suite tests/scripts/convergence-runner.sh; else echo " (skipped: tests/evals not packaged)"; fi
154
172
 
155
- echo "==> Eval packaging & hermeticity..."
173
+ echo "==> Eval packaging & hermeticity... (queued)"
156
174
  # The hermeticity invariant lives here, and this step owns it alone: `npm test` never
157
175
  # invokes a model, reaches the network, or reads a credential -- and the eval corpus never ships
158
176
  # to consumers. Asserted at the INVOCATION level, because validate.sh must NAME tests/evals to
159
177
  # syntax-check it, so a "no mention" rule would be self-contradicting.
160
- bash tests/scripts/evals-packaging.sh
178
+ suite tests/scripts/evals-packaging.sh
161
179
 
162
- echo "==> Eval gate rule tests..."
180
+ echo "==> Eval gate rule tests... (queued)"
163
181
  # One glob (D-P3): later iterations add tests/scripts/eval-gate-*.sh files, never a validate.sh block.
164
- if [ -d tests/evals ]; then for t in tests/scripts/eval-gate-*.sh; do bash "$t"; done; else echo " (skipped: tests/evals not packaged)"; fi
182
+ if [ -d tests/evals ]; then for t in tests/scripts/eval-gate-*.sh; do suite "$t"; done; else echo " (skipped: tests/evals not packaged)"; fi
165
183
 
166
184
  echo "==> Digest-marker / hook-fixture coupling..."
167
185
  # A `rules/` trim that removes or rewords a digest bullet must update
@@ -224,10 +242,10 @@ done
224
242
  if [ "$cost_failed" -ne 0 ]; then
225
243
  exit 1
226
244
  fi
227
- bash tests/scripts/cost-defaults.sh
245
+ suite tests/scripts/cost-defaults.sh
228
246
 
229
- echo "==> Agent names: stem == frontmatter name, somi- prefix, no stale ids..."
230
- bash tests/scripts/agent-names.sh
247
+ echo "==> Agent names: stem == frontmatter name, somi- prefix, no stale ids... (queued)"
248
+ suite tests/scripts/agent-names.sh
231
249
 
232
250
  echo "==> Validating command <-> somi-dispatch skill reference..."
233
251
  # Every command that Tasks an agent directly resolves it through the same dispatch procedure the
@@ -238,13 +256,16 @@ echo "==> Validating command <-> somi-dispatch skill reference..."
238
256
  # tests/scripts/dispatch-reference-gate.sh proves this gate RED (a `cp -a` copy with one command's
239
257
  # reference removed) and GREEN, the same two-sided proof retirement-gate.sh and dispatch-guard.sh
240
258
  # already give their own gates.
241
- if ! node tests/scripts/lib/dispatch-reference-gate.mjs commands agents; then
259
+ if ! node tests/scripts/lib/dispatch-reference-gate.mjs skills agents; then
242
260
  exit 1
243
261
  fi
244
- bash tests/scripts/dispatch-reference-gate.sh
262
+ suite tests/scripts/dispatch-reference-gate.sh
245
263
 
246
- echo "==> Dispatch line: one canonical phrase, native agent_type dispatch, requested-low disclosure..."
247
- bash tests/scripts/dispatch-line-gate.sh
264
+ echo "==> Dispatch line: one canonical phrase, native agent_type dispatch, requested-low disclosure... (queued)"
265
+ suite tests/scripts/dispatch-line-gate.sh
266
+
267
+ echo "==> Code-loop flow shape: four tool calls a clean pass, no CLI step on the MCP path... (queued)"
268
+ suite tests/scripts/loop-flow-gate.sh
248
269
 
249
270
  echo "==> Validating the stale-vocabulary retirement gate..."
250
271
  # scripts/validate.sh only ever asserted frontmatter VALUES above, never prose -- so a
@@ -267,7 +288,7 @@ case "$retirement_gate" in
267
288
  exit 1
268
289
  ;;
269
290
  esac
270
- bash tests/scripts/retirement-gate.sh
291
+ suite tests/scripts/retirement-gate.sh
271
292
 
272
293
  echo "==> Validating /ship-loop's non-overridable checkpoint..."
273
294
  # /ship-loop's single mandatory human checkpoint moved from a cost-tier boundary (which
@@ -276,10 +297,10 @@ echo "==> Validating /ship-loop's non-overridable checkpoint..."
276
297
  # the two anchors the checkpoint fires at -- the brief handoff, and (on a cold start with no design
277
298
  # action) after /plan-loop. tests/scripts/checkpoint-gate.sh proves this gate both ways, against
278
299
  # the real file and against a `cp`'d copy with the wording deliberately weakened.
279
- if ! node tests/scripts/lib/checkpoint-gate.mjs commands/ship-loop.md; then
300
+ if ! node tests/scripts/lib/checkpoint-gate.mjs skills/flow-ship-loop/SKILL.md; then
280
301
  exit 1
281
302
  fi
282
- bash tests/scripts/checkpoint-gate.sh
303
+ suite tests/scripts/checkpoint-gate.sh
283
304
 
284
305
  echo "==> Validating new cost-tier artifacts..."
285
306
  for f in \
@@ -303,7 +324,7 @@ for f in \
303
324
  done
304
325
  # The execution brief is the load-bearing design→execution handoff — it must be referenced by
305
326
  # the agents/commands that produce and consume it, not orphaned.
306
- if ! grep -rIlq 'BRIEF\.md\.tmpl' agents commands; then
327
+ if ! grep -rIlq 'BRIEF\.md\.tmpl' agents commands skills; then
307
328
  echo "templates/BRIEF.md.tmpl is not referenced by any agent or command" >&2
308
329
  exit 1
309
330
  fi
@@ -434,7 +455,7 @@ echo "==> Validating review-agent write-discipline contracts..."
434
455
  # agent added without one falsifies all five at once and silently holes that rationale. The
435
456
  # two-part sweep below finds false statements; only this finds a MISSING one.
436
457
  contract_failed=0
437
- # DERIVED, not hardcoded: the seated lenses are read out of commands/review-panel.md's own table —
458
+ # DERIVED, not hardcoded: the seated lenses are read out of skills/flow-review-panel/SKILL.md's own table —
438
459
  # the document whose concurrency rationale depends on the claim. A hardcoded list cannot detect the
439
460
  # threat this check exists for (a FIFTH review agent seated without a contract); it would only
440
461
  # catch removal from the four already known.
@@ -445,14 +466,14 @@ contract_failed=0
445
466
  # future table in this file leading with a backticked non-agent cell now produces a LOUD, named
446
467
  # MISSING AGENT error rather than a silent miss. Loud-and-wrong is diagnosable; silent-and-missing
447
468
  # is the defect class this check exists to remove.
448
- seated="$(grep -oE '^\| *`[a-z][a-z0-9-]*`' commands/review-panel.md | tr -d '|` ' | sort -u)"
469
+ seated="$(grep -oE '^\| *`[a-z][a-z0-9-]*`' skills/flow-review-panel/SKILL.md | tr -d '|` ' | sort -u)"
449
470
  if [ -z "$seated" ]; then
450
- echo "WRITE CONTRACT CHECK: found no seated lenses in commands/review-panel.md — table shape changed?" >&2
471
+ echo "WRITE CONTRACT CHECK: found no seated lenses in skills/flow-review-panel/SKILL.md — table shape changed?" >&2
451
472
  contract_failed=1
452
473
  fi
453
474
  for a in $seated; do
454
475
  if [ ! -f "agents/$a.md" ]; then
455
- echo "MISSING AGENT: commands/review-panel.md seats '$a' but agents/$a.md does not exist" >&2
476
+ echo "MISSING AGENT: skills/flow-review-panel/SKILL.md seats '$a' but agents/$a.md does not exist" >&2
456
477
  contract_failed=1
457
478
  elif ! grep -q '^## Write discipline' "agents/$a.md"; then
458
479
  echo "MISSING WRITE CONTRACT: agents/$a.md has no '## Write discipline' section" >&2
@@ -462,7 +483,7 @@ done
462
483
  if [ "$contract_failed" -ne 0 ]; then
463
484
  exit 1
464
485
  fi
465
- # pr is never seated in commands/review-panel.md (it is not a review lens), so the derived sweep
486
+ # pr is never seated in skills/flow-review-panel/SKILL.md (it is not a review lens), so the derived sweep
466
487
  # above cannot cover it -- but its own contract is load-bearing (agents/somi-pr.md's Write discipline
467
488
  # section is the only thing gating an ungated `gh pr create`), so assert it directly.
468
489
  if ! grep -q '^## Write discipline' agents/somi-pr.md; then
@@ -577,6 +598,19 @@ if ! node scripts/check-links.mjs; then
577
598
  exit 1
578
599
  fi
579
600
 
601
+ echo "==> Validating the overview page's roadmap covers every release..."
602
+ # site/src/content/roadmap.json must account for every CHANGELOG release, so a release cannot be
603
+ # dispatched (publish.yml's version job runs this script) with the page still describing the one
604
+ # before. site/ is not in the npm package, hence the skip.
605
+ if [ -d site ]; then
606
+ if ! node tests/scripts/lib/site-roadmap-gate.mjs; then
607
+ exit 1
608
+ fi
609
+ else
610
+ echo " (skipped: site/ not packaged)"
611
+ fi
612
+ suite tests/scripts/site-roadmap-gate.sh
613
+
580
614
  echo "==> Validating no session-artefact references in shipped code and prose..."
581
615
  # Comments in hooks/ and scripts/, and every line of agents/, commands/, skills/, must not point at
582
616
  # the gitignored .somi/ planning folder (finding ids, decision tags, iteration/phase numbers) --
@@ -601,13 +635,17 @@ if ! grep -q '^## The trivial threshold' skills/somi-routing/SKILL.md; then
601
635
  echo "FAIL: skills/somi-routing/SKILL.md lacks the 'The trivial threshold' section" >&2
602
636
  exit 1
603
637
  fi
604
- if ! grep -q 'somi-routing/SKILL.md#the-trivial-threshold' commands/code.md; then
605
- echo "FAIL: commands/code.md does not reference the trivial threshold" >&2
638
+ if ! grep -q 'somi-routing/SKILL.md#the-trivial-threshold' skills/flow-code/SKILL.md; then
639
+ echo "FAIL: skills/flow-code/SKILL.md does not reference the trivial threshold" >&2
606
640
  exit 1
607
641
  fi
608
642
 
609
643
  # Coder: Decision Ladder step sits between "Map the change" and "Implement"; no-plan path cites the threshold.
610
- { awk '/^[0-9]+\. \*\*Map the change/{m=NR} /^[0-9]+\. \*\*Climb the Decision Ladder/{l=NR} /^[0-9]+\. \*\*Implement the smallest/{i=NR} END{exit !(m && l>m && i>l)}' agents/somi-coder.md && grep -q 'somi-routing/SKILL.md#the-trivial-threshold' agents/somi-coder.md; } || { echo "FAIL: agents/somi-coder.md needs the Decision Ladder between Map and Implement, and the trivial-threshold reference" >&2; exit 1; }
644
+ { awk '/^[0-9]+\. \*\*Map the change/{m=NR} /^[0-9]+\. \*\*Climb the Decision Ladder/{l=NR} /^[0-9]+\. \*\*Implement the smallest/{i=NR} END{exit !(m && l>m && i>l)}' skills/role-coder/SKILL.md && grep -q 'somi-routing/SKILL.md#the-trivial-threshold' skills/role-coder/SKILL.md; } || { echo "FAIL: skills/role-coder/SKILL.md needs the Decision Ladder between Map and Implement, and the trivial-threshold reference" >&2; exit 1; }
645
+ echo "==> Test suites (${#SUITES[@]} queued, shard ${SOMI_SUITE_SHARD:-all})..."
646
+ suite tests/scripts/run-suites.sh
647
+ node tests/scripts/lib/run-suites.mjs --plan tests/scripts/suite-plan.json -- "${SUITES[@]}" || exit 1
648
+
611
649
  echo "==> Creating coverage stub..."
612
650
  mkdir -p coverage
613
651
  printf 'TN:\nend_of_record\n' > coverage/lcov.info
@@ -0,0 +1,92 @@
1
+ ---
2
+ name: flow-adopt
3
+ description: The /adopt procedure, loaded by the /adopt command and by the somi-flow runner.
4
+ user-invocable: false
5
+ ---
6
+
7
+ # /adopt — Onboard SoMi into an existing codebase
8
+
9
+ You are running SoMi's **one-time brownfield onboarding**. The goal: after this command, SoMi
10
+ already *knows this repo* — its map, its conventions, its weak spots — and the team has a
11
+ concrete first exercise, instead of "read thirteen docs and type `/plan`".
12
+
13
+ This is a composite of existing pieces, run in order, with the user confirming at each seam.
14
+
15
+ > **No `cost:` of its own, and no `model:` either — it runs on whatever model this session is
16
+ > already using.** Stage 1 Tasks
17
+ > the `somi-atlas` agent ([`agents/somi-atlas.md`](../../agents/somi-atlas.md)), which defaults to `high` on its
18
+ > own account and resolves against the session ceiling independently of this command. Stages 2 and
19
+ > 4 read and write directly, inline, at whatever tier is already running this command. Stage 3 may
20
+ > also Task [`somi-test-strategist`](../../agents/somi-test-strategist.md) for the gap report's test-thin-ice
21
+ > depth — it resolves on its own account exactly as Stage 1's `somi-atlas` does, not at this command's
22
+ > tier.
23
+
24
+ ## Stage 1 — Build the Repo Atlas (default `high`, the expensive step)
25
+
26
+ Before this `Task`, call `somi_resolve` for `somi-atlas` (with `project_dir`), pass its `model`, start it as its `agent_type`, and put the cost line in the briefing (`dispatched at cost: <tier>` only when `enforced` is true, else `requested cost: <tier> (not enforced: no mapped model)`); full rules: the `somi-dispatch` skill (`somi_skill`,
27
+ or `somi:somi-dispatch` on Claude Code). Task the `somi-atlas` agent
28
+ ([`agents/somi-atlas.md`](../../agents/somi-atlas.md)) to build or refresh
29
+ `.somi/atlas.md` (module map, dependency rules, conventions digest, hotspots, test topology,
30
+ SHA-stamped). It runs its own staleness check and skips the rebuild — saying so — when a fresh
31
+ atlas already exists.
32
+
33
+ Present the atlas §1 framing + module count and pause briefly: "does this map match your mental
34
+ model?" — a wrong map should be corrected *now*, by the people who know, not discovered by the
35
+ first `/design`.
36
+
37
+ ## Stage 2 — Confirm conventions into `99-overrides.md`
38
+
39
+ From the atlas §4 digest (and the instruction files it lists), draft the project's
40
+ `.somi/rules/99-overrides.md` scaffold **pre-filled with the detected conventions** — each as a
41
+ `## Convention:` block, plus a `## Override:` block for anything that contradicts a SoMi default
42
+ (name the rule file it overrides and a removal condition). `.somi/` is the neutral location
43
+ regardless of which host (Claude Code, GitHub Copilot) is consuming SoMi — never write this under
44
+ `.claude/` or `.github/`, and never at the project root.
45
+
46
+ **Present the draft to the user for confirmation before writing** — detected ≠ intended; the
47
+ team may be tolerating practices they don't want codified. Apply their edits, then write the
48
+ file (or, if one exists, propose additions only — never clobber). Where instruction files and
49
+ observed practice disagreed (the atlas records this), ask which one wins and record the answer.
50
+
51
+ ## Stage 3 — Gap report
52
+
53
+ From the atlas plus targeted checks, produce a short **gap report** (in-chat, plus
54
+ `.somi/reviews/_ad-hoc/<YYYY-MM-DD>-adoption-gaps.md`):
55
+
56
+ - **Test thin ice** — the atlas §6 areas where a regression wouldn't be caught; the 2–3 places
57
+ characterization tests would pay off first (this is [`somi-test-strategist`](../../agents/somi-test-strategist.md)
58
+ territory — before Tasking it, call `somi_resolve` for `somi-test-strategist`; full rules: the
59
+ `somi-dispatch` skill — if the picture needs depth).
60
+ - **Hotspots** — atlas §5, ranked; for each, whether it blocks likely upcoming work.
61
+ - **Candidate first refactors** — untangles that would make the next changes easy
62
+ ([`/refactor`](../flow-refactor/SKILL.md) for a contained smell, [`/refactor-design`](../flow-refactor-design/SKILL.md)
63
+ candidates for anything spanning modules), each with the smell named precisely.
64
+ - **Guardrail fit** — anything in the repo the hooks would fight (e.g. a workflow that
65
+ hand-edits a lockfile) → recommend the matching `.somi/config.json` policy
66
+ (`dep_install.allow`, `lockfiles.allow_edit`) instead of per-session env vars.
67
+
68
+ ## Stage 4 — Suggest the calibration work item
69
+
70
+ Recommend one **small, real** feature or fix from the team's actual backlog shape (ask if none
71
+ is obvious) to run as `/ship` — the calibration exercise from
72
+ [GOVERNANCE.md](../../docs/GOVERNANCE.md): it exercises plan → code-loop → review end-to-end, and
73
+ disagreements it surfaces belong in `.somi/rules/99-overrides.md` while they're fresh. For a bug, recommend
74
+ `/debug` instead.
75
+
76
+ ## Summarise back
77
+
78
+ - Atlas: built/refreshed, module count, top hotspots.
79
+ - Conventions: confirmed count, overrides recorded, disagreements resolved.
80
+ - Gap report: the top 3 items, with the report's path.
81
+ - The suggested calibration item + exact next command.
82
+ - One-line orientation: "on GitHub Copilot, `@somi` any time for status and routing."
83
+
84
+ ## Guardrails
85
+
86
+ - **Stage 2 writes nothing without confirmation.** Codifying conventions is a team decision;
87
+ you draft, they decide (this is the batch verification protocol applied to onboarding).
88
+ - **Never clobber** an existing `.somi/rules/99-overrides.md`, `CLAUDE.md`, or atlas — propose additions.
89
+ - **The gap report is descriptive.** No unsolicited refactoring, no "fixing" anything during
90
+ adoption. The output is knowledge + a recommended first exercise, not diffs.
91
+ - **Once per repo, roughly.** Re-running is safe (atlas refresh + report regeneration) but the
92
+ overrides confirmation shouldn't be re-litigated on every run — propose only deltas.