@skathio/somi 4.0.1 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) 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 +5 -4
  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 +11 -130
  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 +8 -5
  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-protected-paths.mjs +54 -34
  46. package/package.json +1 -1
  47. package/scripts/lib/cost-defaults.mjs +2 -0
  48. package/scripts/lib/escalation-facts.mjs +146 -0
  49. package/scripts/lib/escalation.mjs +129 -0
  50. package/scripts/lib/findings-ledger.mjs +241 -0
  51. package/scripts/lib/install-text.mjs +97 -0
  52. package/scripts/lib/loop-caps.mjs +140 -0
  53. package/scripts/lib/loop-diff.mjs +12 -70
  54. package/scripts/lib/loop-engine.mjs +227 -0
  55. package/scripts/lib/loop-escalate.mjs +49 -0
  56. package/scripts/lib/loop-exit.mjs +47 -0
  57. package/scripts/lib/loop-notes-compact.mjs +72 -0
  58. package/scripts/lib/loop-notes.mjs +282 -0
  59. package/scripts/lib/loop-review.mjs +355 -12
  60. package/scripts/lib/loop-state.mjs +44 -0
  61. package/scripts/lib/loop-step-close.mjs +75 -0
  62. package/scripts/lib/loop-step-kit.mjs +179 -0
  63. package/scripts/lib/loop-step-review.mjs +140 -0
  64. package/scripts/lib/loop-step-tool.mjs +89 -0
  65. package/scripts/lib/loop-step.mjs +303 -0
  66. package/scripts/lib/mcp-project-root.mjs +18 -7
  67. package/scripts/lib/path-facts.mjs +187 -0
  68. package/scripts/lib/path-safety.mjs +171 -0
  69. package/scripts/lib/run-card.mjs +73 -0
  70. package/scripts/size-budget-overrides.json +5 -13
  71. package/scripts/somi-card.mjs +39 -0
  72. package/scripts/somi-findings.mjs +56 -271
  73. package/scripts/somi-loop.mjs +84 -443
  74. package/scripts/somi-mcp.mjs +26 -95
  75. package/scripts/validate.sh +75 -57
  76. package/skills/flow-adopt/SKILL.md +92 -0
  77. package/skills/flow-architecture-review/SKILL.md +94 -0
  78. package/skills/flow-atlas/SKILL.md +34 -0
  79. package/skills/flow-code/SKILL.md +167 -0
  80. package/skills/flow-code-loop/SKILL.md +263 -0
  81. package/skills/flow-code-parallel/SKILL.md +160 -0
  82. package/skills/flow-debug/SKILL.md +141 -0
  83. package/skills/flow-design/SKILL.md +170 -0
  84. package/skills/flow-discover/SKILL.md +204 -0
  85. package/skills/flow-impact/SKILL.md +35 -0
  86. package/skills/flow-incident/SKILL.md +49 -0
  87. package/skills/flow-plan/SKILL.md +254 -0
  88. package/skills/flow-plan-loop/SKILL.md +254 -0
  89. package/skills/flow-pr/SKILL.md +34 -0
  90. package/skills/flow-refactor/SKILL.md +58 -0
  91. package/skills/flow-refactor-design/SKILL.md +97 -0
  92. package/skills/flow-release-readiness/SKILL.md +82 -0
  93. package/skills/flow-review/SKILL.md +193 -0
  94. package/skills/flow-review-panel/SKILL.md +154 -0
  95. package/skills/flow-security-review/SKILL.md +83 -0
  96. package/skills/flow-ship/SKILL.md +125 -0
  97. package/skills/flow-ship-loop/SKILL.md +274 -0
  98. package/skills/flow-somi-config/SKILL.md +142 -0
  99. package/skills/flow-status/SKILL.md +43 -0
  100. package/skills/flow-test-strategy/SKILL.md +83 -0
  101. package/skills/flow-upgrade/SKILL.md +82 -0
  102. package/skills/role-coder/SKILL.md +247 -0
  103. package/skills/role-designer/SKILL.md +172 -0
  104. package/skills/role-discovery-analyst/SKILL.md +288 -0
  105. package/skills/role-planner/SKILL.md +353 -0
  106. package/skills/role-reviewer/SKILL.md +218 -0
  107. package/skills/somi-checkpoint/SKILL.md +95 -0
  108. package/skills/somi-dispatch/SKILL.md +14 -14
  109. package/skills/somi-routing/SKILL.md +6 -2
  110. package/tests/hooks/cases/block-secret-writes.json +6 -1
  111. package/tests/hooks/cases/guard-protected-paths.json +44 -2
  112. package/tests/hooks/run.sh +21 -0
  113. package/tests/scripts/checkpoint-gate.sh +2 -2
  114. package/tests/scripts/cost-defaults.sh +2 -0
  115. package/tests/scripts/dispatch-line-gate.sh +4 -4
  116. package/tests/scripts/dispatch-reference-gate.sh +14 -14
  117. package/tests/scripts/escalation.sh +409 -0
  118. package/tests/scripts/eval-runner.sh +8 -7
  119. package/tests/scripts/fact-sheet.sh +296 -0
  120. package/tests/scripts/goldens/somi-loop.json +2 -2
  121. package/tests/scripts/lib/dispatch-reference-gate.mjs +14 -5
  122. package/tests/scripts/lib/escalation-facts-tests.mjs +140 -0
  123. package/tests/scripts/lib/escalation-tests.mjs +154 -0
  124. package/tests/scripts/lib/findings-ledger-tests.mjs +118 -0
  125. package/tests/scripts/lib/loop-engine-tests.mjs +287 -0
  126. package/tests/scripts/lib/loop-escalate-tests.mjs +356 -0
  127. package/tests/scripts/lib/loop-flow-gate.mjs +173 -0
  128. package/tests/scripts/lib/loop-notes-tests.mjs +384 -0
  129. package/tests/scripts/lib/loop-step-cli-tests.mjs +156 -0
  130. package/tests/scripts/lib/loop-step-close-tests.mjs +351 -0
  131. package/tests/scripts/lib/loop-step-lenient-tests.mjs +114 -0
  132. package/tests/scripts/lib/loop-step-state-tests.mjs +127 -0
  133. package/tests/scripts/lib/loop-step-tests.mjs +499 -0
  134. package/tests/scripts/lib/loop-step-unwritten-tests.mjs +55 -0
  135. package/tests/scripts/lib/path-facts-tests.mjs +198 -0
  136. package/tests/scripts/lib/path-safety-tests.mjs +201 -0
  137. package/tests/scripts/lib/run-suites.mjs +139 -0
  138. package/tests/scripts/lib/sizing-score-tests.mjs +210 -0
  139. package/tests/scripts/lib/sizing-set-tests.mjs +131 -0
  140. package/tests/scripts/lib/somi-mcp-loop-tests.mjs +226 -0
  141. package/tests/scripts/lib/somi-mcp-tests.mjs +21 -1
  142. package/tests/scripts/loop-engine.sh +22 -0
  143. package/tests/scripts/loop-flow-gate.sh +11 -0
  144. package/tests/scripts/review-panel-seats.sh +4 -4
  145. package/tests/scripts/run-card.sh +57 -0
  146. package/tests/scripts/run-suites.sh +74 -0
  147. package/tests/scripts/run.sh +11 -0
  148. package/tests/scripts/size-tier.sh +3 -3
  149. package/tests/scripts/somi-agent-dispatch-contract.sh +23 -3
  150. package/tests/scripts/somi-mcp.sh +1 -0
  151. 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,51 +149,7 @@ 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:
@@ -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
  }
@@ -11,6 +11,13 @@ set -euo pipefail
11
11
  # An empty value means "no global config"; suites that test the global file set their own.
12
12
  export SOMI_GLOBAL_CONFIG=""
13
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
+
14
21
  # JSON validity via Node's own parser (no jq). Fails loudly on the first invalid file.
15
22
  json_valid() { node -e 'JSON.parse(require("fs").readFileSync(process.argv[1],"utf8"))' "$1"; }
16
23
 
@@ -42,60 +49,64 @@ for f in tests/hooks/cases/*.json; do
42
49
  echo " node JSON.parse: $f"
43
50
  json_valid "$f"
44
51
  done
45
- bash tests/hooks/run.sh
52
+ suite tests/hooks/run.sh
46
53
 
47
- echo "==> Loop-state & findings-ledger tests..."
48
- 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
49
58
 
50
- echo "==> Link-checker tests..."
51
- bash tests/scripts/check-links.sh
59
+ echo "==> Link-checker tests... (queued)"
60
+ suite tests/scripts/check-links.sh
52
61
 
53
- echo "==> Session-artefact gate tests..."
62
+ echo "==> Session-artefact gate tests... (queued)"
54
63
  # Guards scripts/check-session-artefacts.mjs: fails on a tagged comment, passes a clean one, and
55
64
  # honours its explicit exclusions.
56
- bash tests/scripts/check-session-artefacts.sh
65
+ suite tests/scripts/check-session-artefacts.sh
57
66
 
58
- echo "==> Frontmatter gate tests..."
67
+ echo "==> Frontmatter gate tests... (queued)"
59
68
  # Guards scripts/check-frontmatter.mjs: the plain-scalar forms YAML rejects fail, quoted ones pass.
60
- bash tests/scripts/check-frontmatter.sh
69
+ suite tests/scripts/check-frontmatter.sh
61
70
 
62
- echo "==> File-size budget gate tests..."
71
+ echo "==> File-size budget gate tests... (queued)"
63
72
  # Guards scripts/check-size-budget.mjs: an un-ledgered oversized file fails, a ledgered file may
64
73
  # shrink but not grow, a stale entry warns, a malformed ledger fails loudly.
65
- bash tests/scripts/check-size-budget.sh
74
+ suite tests/scripts/check-size-budget.sh
66
75
 
67
- echo "==> Digest-generator tests..."
76
+ echo "==> Digest-generator tests... (queued)"
68
77
  # Guards scripts/generate-digest.mjs: per-target prefix transform, drift detection in EITHER
69
78
  # copy alone, clean errors on malformed input, and splice anchoring. Wiring `--check` itself
70
79
  # into this script is the separate "Validating digest parity" step below — this is the
71
80
  # unit guard for the generator, not the drift gate.
72
- bash tests/scripts/generate-digest.sh
81
+ suite tests/scripts/generate-digest.sh
73
82
 
74
- echo "==> Cost model resolver tests..."
75
- bash tests/scripts/cost-model.sh
83
+ echo "==> Cost model resolver tests... (queued)"
84
+ suite tests/scripts/cost-model.sh
76
85
 
77
- echo "==> Cost ceiling tests..."
78
- bash tests/scripts/cost-ceiling.sh
86
+ echo "==> Cost ceiling tests... (queued)"
87
+ suite tests/scripts/cost-ceiling.sh
79
88
 
80
- echo "==> Global config, merge and reads through links..."
81
- bash tests/scripts/global-config.sh
89
+ echo "==> Global config, merge and reads through links... (queued)"
90
+ suite tests/scripts/global-config.sh
82
91
 
83
- echo "==> Dispatch resolver tests..."
84
- bash tests/scripts/somi-dispatch.sh
85
- 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
86
97
 
87
- echo "==> Front-door agent <-> dispatch resolver contract tests..."
98
+ echo "==> Front-door agent <-> dispatch resolver contract tests... (queued)"
88
99
  # agents/somi.md is a prompt and can't be exercised without a model, but what its Step 4 tells the
89
100
  # model to RUN can be checked deterministically: the resolve --agent/--host invocation shape it
90
101
  # instructs, and the exit codes it maps, must both be real and current against the actual CLI.
91
- bash tests/scripts/somi-agent-dispatch-contract.sh
102
+ suite tests/scripts/somi-agent-dispatch-contract.sh
92
103
 
93
- echo "==> Bundled MCP server tests (somi_resolve / somi_command)..."
104
+ echo "==> Bundled MCP server tests (somi_resolve / somi_command)... (queued)"
94
105
  # scripts/somi-mcp.mjs is the MCP-native equivalent of the CLI above, launched from
95
106
  # ${CLAUDE_PLUGIN_ROOT}/${PLUGIN_ROOT} so a prompt never needs an install path. Both wrap the
96
107
  # identical scripts/lib/dispatch-resolver.mjs, so this drives the real JSON-RPC stdio protocol
97
108
  # rather than re-testing the resolver's arithmetic a third time.
98
- bash tests/scripts/somi-mcp.sh
109
+ suite tests/scripts/somi-mcp.sh
99
110
 
100
111
  echo "==> Validating the dispatch guard (no caller ignoring per-agent overrides)..."
101
112
  # scripts/lib/cost-ceiling.mjs's modelForDispatch() is the ONLY sanctioned way to turn a dispatch
@@ -124,7 +135,7 @@ fi
124
135
  if [ "$dispatch_guard_failed" -ne 0 ]; then
125
136
  exit 1
126
137
  fi
127
- bash tests/scripts/dispatch-guard.sh
138
+ suite tests/scripts/dispatch-guard.sh
128
139
 
129
140
  echo "==> Diary compaction rule present in the template..."
130
141
  # The rule must stay triggered and concrete: a numeric trigger, a verbatim move to diary-archive.md,
@@ -136,39 +147,39 @@ for pat in 'more than 40' 'diary-archive\.md' 'verbatim' 'Never move a `decision
136
147
  done
137
148
  echo " ok: $DIARY_TMPL"
138
149
 
139
- echo "==> Eval fixture guards..."
150
+ echo "==> Eval fixture guards... (queued)"
140
151
  # Guards tests/evals/fixtures/. Two defects are guarded here: a plan tree shipped
141
152
  # under `.somi/` that .gitignore silently dropped from the package, and pass criteria
142
153
  # written into fixture source as comments the candidate reads — which would have flatlined two
143
154
  # load-bearing rubric dimensions at pass in BOTH arms of the trim comparison, reporting no
144
155
  # regression on exactly what the corpus exists to protect.
145
- 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
146
157
 
147
- echo "==> Eval runner unit tests..."
158
+ echo "==> Eval runner unit tests... (queued)"
148
159
  # Guards tests/evals/run.mjs: the N-of-M grading bands, the trim-comparison rule, the result
149
160
  # schema, and --source worktree cleanup. Hermetic -- every case is --dry-run or a direct call.
150
161
  # This runs the runner's UNIT tests; it never invokes the runner against a model. The structural
151
162
  # assertion that npm test cannot execute the runner lives inside eval-runner.sh itself.
152
- 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
153
164
 
154
- echo "==> Convergence gate CLI unit tests..."
165
+ echo "==> Convergence gate CLI unit tests... (queued)"
155
166
  # Guards tests/evals/convergence.mjs's CLI section: argument parsing, --dry-run's shape/zero-model-call
156
167
  # contract, --merge/--certify's shard-fold report, and the sha boundary check. Mirrors
157
168
  # eval-runner.sh's own pattern -- unit-tests the gate logic, never a live run. The module's
158
169
  # non-CLI logic is already covered by eval-runner.sh; this file is scoped to the CLI section
159
170
  # alone, so the two stay disjoint rather than duplicating each other.
160
- 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
161
172
 
162
- echo "==> Eval packaging & hermeticity..."
173
+ echo "==> Eval packaging & hermeticity... (queued)"
163
174
  # The hermeticity invariant lives here, and this step owns it alone: `npm test` never
164
175
  # invokes a model, reaches the network, or reads a credential -- and the eval corpus never ships
165
176
  # to consumers. Asserted at the INVOCATION level, because validate.sh must NAME tests/evals to
166
177
  # syntax-check it, so a "no mention" rule would be self-contradicting.
167
- bash tests/scripts/evals-packaging.sh
178
+ suite tests/scripts/evals-packaging.sh
168
179
 
169
- echo "==> Eval gate rule tests..."
180
+ echo "==> Eval gate rule tests... (queued)"
170
181
  # One glob (D-P3): later iterations add tests/scripts/eval-gate-*.sh files, never a validate.sh block.
171
- 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
172
183
 
173
184
  echo "==> Digest-marker / hook-fixture coupling..."
174
185
  # A `rules/` trim that removes or rewords a digest bullet must update
@@ -231,10 +242,10 @@ done
231
242
  if [ "$cost_failed" -ne 0 ]; then
232
243
  exit 1
233
244
  fi
234
- bash tests/scripts/cost-defaults.sh
245
+ suite tests/scripts/cost-defaults.sh
235
246
 
236
- echo "==> Agent names: stem == frontmatter name, somi- prefix, no stale ids..."
237
- 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
238
249
 
239
250
  echo "==> Validating command <-> somi-dispatch skill reference..."
240
251
  # Every command that Tasks an agent directly resolves it through the same dispatch procedure the
@@ -245,13 +256,16 @@ echo "==> Validating command <-> somi-dispatch skill reference..."
245
256
  # tests/scripts/dispatch-reference-gate.sh proves this gate RED (a `cp -a` copy with one command's
246
257
  # reference removed) and GREEN, the same two-sided proof retirement-gate.sh and dispatch-guard.sh
247
258
  # already give their own gates.
248
- 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
249
260
  exit 1
250
261
  fi
251
- bash tests/scripts/dispatch-reference-gate.sh
262
+ suite tests/scripts/dispatch-reference-gate.sh
263
+
264
+ echo "==> Dispatch line: one canonical phrase, native agent_type dispatch, requested-low disclosure... (queued)"
265
+ suite tests/scripts/dispatch-line-gate.sh
252
266
 
253
- echo "==> Dispatch line: one canonical phrase, native agent_type dispatch, requested-low disclosure..."
254
- bash tests/scripts/dispatch-line-gate.sh
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
255
269
 
256
270
  echo "==> Validating the stale-vocabulary retirement gate..."
257
271
  # scripts/validate.sh only ever asserted frontmatter VALUES above, never prose -- so a
@@ -274,7 +288,7 @@ case "$retirement_gate" in
274
288
  exit 1
275
289
  ;;
276
290
  esac
277
- bash tests/scripts/retirement-gate.sh
291
+ suite tests/scripts/retirement-gate.sh
278
292
 
279
293
  echo "==> Validating /ship-loop's non-overridable checkpoint..."
280
294
  # /ship-loop's single mandatory human checkpoint moved from a cost-tier boundary (which
@@ -283,10 +297,10 @@ echo "==> Validating /ship-loop's non-overridable checkpoint..."
283
297
  # the two anchors the checkpoint fires at -- the brief handoff, and (on a cold start with no design
284
298
  # action) after /plan-loop. tests/scripts/checkpoint-gate.sh proves this gate both ways, against
285
299
  # the real file and against a `cp`'d copy with the wording deliberately weakened.
286
- 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
287
301
  exit 1
288
302
  fi
289
- bash tests/scripts/checkpoint-gate.sh
303
+ suite tests/scripts/checkpoint-gate.sh
290
304
 
291
305
  echo "==> Validating new cost-tier artifacts..."
292
306
  for f in \
@@ -310,7 +324,7 @@ for f in \
310
324
  done
311
325
  # The execution brief is the load-bearing design→execution handoff — it must be referenced by
312
326
  # the agents/commands that produce and consume it, not orphaned.
313
- if ! grep -rIlq 'BRIEF\.md\.tmpl' agents commands; then
327
+ if ! grep -rIlq 'BRIEF\.md\.tmpl' agents commands skills; then
314
328
  echo "templates/BRIEF.md.tmpl is not referenced by any agent or command" >&2
315
329
  exit 1
316
330
  fi
@@ -441,7 +455,7 @@ echo "==> Validating review-agent write-discipline contracts..."
441
455
  # agent added without one falsifies all five at once and silently holes that rationale. The
442
456
  # two-part sweep below finds false statements; only this finds a MISSING one.
443
457
  contract_failed=0
444
- # 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 —
445
459
  # the document whose concurrency rationale depends on the claim. A hardcoded list cannot detect the
446
460
  # threat this check exists for (a FIFTH review agent seated without a contract); it would only
447
461
  # catch removal from the four already known.
@@ -452,14 +466,14 @@ contract_failed=0
452
466
  # future table in this file leading with a backticked non-agent cell now produces a LOUD, named
453
467
  # MISSING AGENT error rather than a silent miss. Loud-and-wrong is diagnosable; silent-and-missing
454
468
  # is the defect class this check exists to remove.
455
- 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)"
456
470
  if [ -z "$seated" ]; then
457
- 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
458
472
  contract_failed=1
459
473
  fi
460
474
  for a in $seated; do
461
475
  if [ ! -f "agents/$a.md" ]; then
462
- 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
463
477
  contract_failed=1
464
478
  elif ! grep -q '^## Write discipline' "agents/$a.md"; then
465
479
  echo "MISSING WRITE CONTRACT: agents/$a.md has no '## Write discipline' section" >&2
@@ -469,7 +483,7 @@ done
469
483
  if [ "$contract_failed" -ne 0 ]; then
470
484
  exit 1
471
485
  fi
472
- # 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
473
487
  # above cannot cover it -- but its own contract is load-bearing (agents/somi-pr.md's Write discipline
474
488
  # section is the only thing gating an ungated `gh pr create`), so assert it directly.
475
489
  if ! grep -q '^## Write discipline' agents/somi-pr.md; then
@@ -595,7 +609,7 @@ if [ -d site ]; then
595
609
  else
596
610
  echo " (skipped: site/ not packaged)"
597
611
  fi
598
- bash tests/scripts/site-roadmap-gate.sh
612
+ suite tests/scripts/site-roadmap-gate.sh
599
613
 
600
614
  echo "==> Validating no session-artefact references in shipped code and prose..."
601
615
  # Comments in hooks/ and scripts/, and every line of agents/, commands/, skills/, must not point at
@@ -621,13 +635,17 @@ if ! grep -q '^## The trivial threshold' skills/somi-routing/SKILL.md; then
621
635
  echo "FAIL: skills/somi-routing/SKILL.md lacks the 'The trivial threshold' section" >&2
622
636
  exit 1
623
637
  fi
624
- if ! grep -q 'somi-routing/SKILL.md#the-trivial-threshold' commands/code.md; then
625
- 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
626
640
  exit 1
627
641
  fi
628
642
 
629
643
  # Coder: Decision Ladder step sits between "Map the change" and "Implement"; no-plan path cites the threshold.
630
- { 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
+
631
649
  echo "==> Creating coverage stub..."
632
650
  mkdir -p coverage
633
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.