@skathio/somi 3.1.0 → 4.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 (148) hide show
  1. package/.claude/settings.json +13 -0
  2. package/.claude-plugin/marketplace.json +2 -2
  3. package/.claude-plugin/plugin.json +1 -1
  4. package/.copilot-extension/extension.json +1 -1
  5. package/.copilot-extension/marketplace.json +2 -2
  6. package/README.md +28 -23
  7. package/VERSION +1 -1
  8. package/agents/{architecture-reviewer.md → somi-architecture-reviewer.md} +10 -11
  9. package/agents/{atlas.md → somi-atlas.md} +3 -5
  10. package/agents/{coder.md → somi-coder.md} +29 -26
  11. package/agents/{designer.md → somi-designer.md} +9 -11
  12. package/agents/{discovery-analyst.md → somi-discovery-analyst.md} +7 -9
  13. package/agents/{impact.md → somi-impact.md} +6 -8
  14. package/agents/{incident.md → somi-incident.md} +2 -4
  15. package/agents/{plan-reviewer.md → somi-plan-reviewer.md} +9 -11
  16. package/agents/{planner.md → somi-planner.md} +19 -27
  17. package/agents/{pr.md → somi-pr.md} +2 -4
  18. package/agents/{refactor-designer.md → somi-refactor-designer.md} +14 -15
  19. package/agents/{refactorer.md → somi-refactorer.md} +14 -15
  20. package/agents/{reviewer.md → somi-reviewer.md} +8 -7
  21. package/agents/{sdlc-reviewer.md → somi-sdlc-reviewer.md} +8 -10
  22. package/agents/{security-reviewer.md → somi-security-reviewer.md} +8 -8
  23. package/agents/{test-strategist.md → somi-test-strategist.md} +4 -6
  24. package/agents/somi.md +27 -14
  25. package/commands/adopt.md +9 -10
  26. package/commands/architecture-review.md +4 -5
  27. package/commands/atlas.md +3 -4
  28. package/commands/code-loop.md +38 -14
  29. package/commands/code-parallel.md +4 -4
  30. package/commands/code.md +24 -15
  31. package/commands/debug.md +8 -9
  32. package/commands/design.md +14 -15
  33. package/commands/discover.md +11 -12
  34. package/commands/impact.md +2 -3
  35. package/commands/incident.md +3 -4
  36. package/commands/plan-loop.md +16 -12
  37. package/commands/plan.md +15 -16
  38. package/commands/pr.md +2 -3
  39. package/commands/refactor-design.md +10 -11
  40. package/commands/refactor.md +7 -8
  41. package/commands/release-readiness.md +6 -7
  42. package/commands/review-panel.md +24 -23
  43. package/commands/review.md +14 -14
  44. package/commands/security-review.md +8 -7
  45. package/commands/ship-loop.md +107 -28
  46. package/commands/ship.md +6 -6
  47. package/commands/somi-config.md +131 -0
  48. package/commands/test-strategy.md +3 -4
  49. package/commands/upgrade.md +4 -5
  50. package/examples/code-review-example.md +1 -1
  51. package/examples/discovery-example.md +1 -1
  52. package/examples/feature-plan-example.md +2 -2
  53. package/hooks/hooks.json +14 -1
  54. package/hooks/lib/common.mjs +64 -1
  55. package/hooks/post-tool/audit-log.mjs +3 -2
  56. package/hooks/pre-tool/block-secret-writes.mjs +12 -11
  57. package/hooks/pre-tool/guard-cost-lowering.mjs +177 -0
  58. package/hooks/pre-tool/guard-protected-paths.mjs +13 -3
  59. package/hooks/session-start/detect-repo-instructions.mjs +27 -2
  60. package/hooks/session-start/ensure-default-config.mjs +121 -0
  61. package/package.json +1 -1
  62. package/rules/00-priorities.md +1 -1
  63. package/rules/30-security-owasp.md +1 -1
  64. package/rules/50-collaboration.md +9 -6
  65. package/rules/CLAUDE.md +11 -10
  66. package/scripts/lib/agent-info.mjs +85 -0
  67. package/scripts/lib/agent-registry.mjs +92 -0
  68. package/scripts/lib/cost-ceiling.mjs +175 -171
  69. package/scripts/lib/cost-config-edit.mjs +102 -0
  70. package/scripts/lib/cost-config.mjs +64 -0
  71. package/scripts/lib/cost-defaults.mjs +51 -0
  72. package/scripts/lib/cost-lowering.mjs +89 -0
  73. package/scripts/lib/cost-model.mjs +37 -22
  74. package/scripts/lib/dispatch-resolver.mjs +68 -50
  75. package/scripts/lib/loop-diff.mjs +96 -0
  76. package/scripts/lib/loop-dispatch.mjs +19 -0
  77. package/scripts/lib/loop-review.mjs +52 -0
  78. package/scripts/lib/run-budget.mjs +28 -0
  79. package/scripts/lib/size-tier.mjs +184 -0
  80. package/scripts/lib/tier-record.mjs +82 -0
  81. package/scripts/size-budget-overrides.json +7 -15
  82. package/scripts/somi-config.mjs +358 -0
  83. package/scripts/somi-dispatch.mjs +1 -1
  84. package/scripts/somi-loop.mjs +71 -96
  85. package/scripts/somi-mcp.mjs +135 -14
  86. package/scripts/somi-tier.mjs +393 -0
  87. package/scripts/validate.sh +37 -215
  88. package/skills/api-design/SKILL.md +1 -1
  89. package/skills/clean-code/SKILL.md +1 -1
  90. package/skills/market-research/SKILL.md +2 -2
  91. package/skills/owasp-defense/SKILL.md +2 -2
  92. package/skills/plan-review/SKILL.md +5 -1
  93. package/skills/reasoning-craft/SKILL.md +1 -1
  94. package/skills/requirements-engineering/SKILL.md +3 -3
  95. package/skills/solid-principles/SKILL.md +1 -1
  96. package/skills/somi-dispatch/SKILL.md +116 -87
  97. package/skills/somi-routing/SKILL.md +88 -1
  98. package/skills/testing-playbook/SKILL.md +2 -2
  99. package/skills/threat-modeling/SKILL.md +3 -3
  100. package/templates/BRIEF.md.tmpl +2 -2
  101. package/templates/DESIGN.md.tmpl +1 -1
  102. package/templates/DOD.md.tmpl +2 -2
  103. package/templates/PHASE.md.tmpl +2 -2
  104. package/templates/RCA.md.tmpl +1 -1
  105. package/templates/REVIEW.md.tmpl +3 -2
  106. package/templates/SDD.md.tmpl +1 -1
  107. package/templates/SPEC.md.tmpl +1 -1
  108. package/templates/TDD.md.tmpl +1 -1
  109. package/tests/hooks/cases/block-secret-writes.json +130 -17
  110. package/tests/hooks/cases/detect-repo-instructions.json +22 -1
  111. package/tests/hooks/cases/guard-protected-paths.json +175 -25
  112. package/tests/scripts/agent-model-frontmatter.sh +38 -0
  113. package/tests/scripts/agent-names.sh +77 -0
  114. package/tests/scripts/check-frontmatter.sh +1 -1
  115. package/tests/scripts/checkpoint-gate.sh +44 -3
  116. package/tests/scripts/convergence-runner.sh +10 -6
  117. package/tests/scripts/cost-ceiling.sh +127 -215
  118. package/tests/scripts/cost-defaults.sh +128 -0
  119. package/tests/scripts/cost-hardcap.sh +329 -0
  120. package/tests/scripts/cost-lowering.sh +261 -0
  121. package/tests/scripts/cost-model.sh +18 -14
  122. package/tests/scripts/dispatch-guard.sh +7 -7
  123. package/tests/scripts/dispatch-line-gate.sh +61 -0
  124. package/tests/scripts/dispatch-reference-gate.sh +13 -13
  125. package/tests/scripts/ensure-default-config.sh +162 -0
  126. package/tests/scripts/eval-runner.sh +9 -9
  127. package/tests/scripts/evals-packaging.sh +127 -20
  128. package/tests/scripts/fixtures/size-tier-cases.json +87 -0
  129. package/tests/scripts/goldens/loop-state-done.json +1 -1
  130. package/tests/scripts/goldens/somi-loop.json +3 -3
  131. package/tests/scripts/lib/agent-registry-tests.mjs +95 -0
  132. package/tests/scripts/lib/brief-only-guard.mjs +27 -0
  133. package/tests/scripts/lib/checkpoint-gate.mjs +40 -3
  134. package/tests/scripts/lib/dispatch-reference-gate.mjs +5 -5
  135. package/tests/scripts/lib/retirement-gate.mjs +7 -2
  136. package/tests/scripts/lib/ship-loop-sizing-guard.mjs +52 -0
  137. package/tests/scripts/lib/size-tier-drift.mjs +74 -0
  138. package/tests/scripts/lib/somi-mcp-config-tests.mjs +92 -0
  139. package/tests/scripts/lib/somi-mcp-tests.mjs +80 -25
  140. package/tests/scripts/lib/somi-mcp-tier-tests.mjs +64 -0
  141. package/tests/scripts/retirement-gate.sh +19 -0
  142. package/tests/scripts/review-panel-seats.sh +2 -2
  143. package/tests/scripts/run.sh +95 -0
  144. package/tests/scripts/size-tier.sh +562 -0
  145. package/tests/scripts/somi-agent-dispatch-contract.sh +20 -11
  146. package/tests/scripts/somi-config.sh +281 -0
  147. package/tests/scripts/somi-dispatch.sh +194 -95
  148. package/tests/scripts/somi-mcp.sh +2 -0
@@ -8,7 +8,7 @@
8
8
  // Invoked from tests/scripts/somi-mcp.sh, which is wired into scripts/validate.sh.
9
9
 
10
10
  import { execFileSync } from 'node:child_process';
11
- import { mkdtempSync, rmSync, mkdirSync, writeFileSync, existsSync } from 'node:fs';
11
+ import { mkdtempSync, rmSync, mkdirSync, writeFileSync, existsSync, readFileSync } from 'node:fs';
12
12
  import { tmpdir } from 'node:os';
13
13
  import path from 'node:path';
14
14
  import { fileURLToPath } from 'node:url';
@@ -34,6 +34,13 @@ function fresh() {
34
34
  return d;
35
35
  }
36
36
 
37
+ function projWith(body) {
38
+ const d = fresh();
39
+ mkdirSync(path.join(d, '.somi'), { recursive: true });
40
+ writeFileSync(path.join(d, '.somi', 'config.json'), body);
41
+ return d;
42
+ }
43
+
37
44
  async function withClient(env, fn) {
38
45
  const client = new McpClient(SERVER, { env });
39
46
  try {
@@ -63,7 +70,7 @@ async function run() {
63
70
 
64
71
  const list = await client.request('tools/list', {});
65
72
  const names = (list.tools || []).map((t) => t.name).sort();
66
- check('tools/list carries exactly somi_resolve, somi_command, somi_skill and somi_agent', names, ['somi_agent', 'somi_command', 'somi_resolve', 'somi_skill']);
73
+ check('tools/list carries exactly somi_resolve, somi_agent_info, somi_command, somi_skill, somi_agent, somi_tier and somi_config', names, ['somi_agent', 'somi_agent_info', 'somi_command', 'somi_config', 'somi_resolve', 'somi_skill', 'somi_tier']);
67
74
 
68
75
  const ping = await client.request('ping', {});
69
76
  check('ping returns an empty result', ping, {});
@@ -73,10 +80,10 @@ async function run() {
73
80
  await withClient({}, async (client) => {
74
81
  await client.initialize();
75
82
  const proj = fresh();
76
- const result = await toolCall(client, 'somi_resolve', { agent: 'coder', host: 'claude-code', project_dir: proj });
83
+ const result = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', host: 'claude-code', ceiling: 'low', project_dir: proj });
77
84
  const mcpJson = JSON.parse(toolText(result));
78
85
 
79
- const cliOut = execFileSync(process.execPath, [CLI, 'resolve', '--agent', 'coder', '--host', 'claude-code'], {
86
+ const cliOut = execFileSync(process.execPath, [CLI, 'resolve', '--agent', 'somi-coder', '--host', 'claude-code', '--ceiling', 'low'], {
80
87
  env: { ...process.env, CLAUDE_PROJECT_DIR: fresh() },
81
88
  encoding: 'utf8',
82
89
  });
@@ -89,6 +96,36 @@ async function run() {
89
96
  check('the resolved project dir is where ceiling state actually landed', existsSync(path.join(proj, '.somi', 'somi-state', 'ceiling.json')), true);
90
97
  });
91
98
 
99
+ // --- CLI vs MCP parity with NO ceiling argument: config decides, and a bare resolve writes no state
100
+ await withClient({}, async (client) => {
101
+ await client.initialize();
102
+ const mk = () => projWith('{"cost":{"ceiling":"low"}}');
103
+ const proj = mk();
104
+ const mcpJson = JSON.parse(toolText(await toolCall(client, 'somi_resolve', { agent: 'somi-coder', project_dir: proj })));
105
+ const cliJson = JSON.parse(execFileSync(process.execPath, [CLI, 'resolve', '--agent', 'somi-coder'], {
106
+ env: { ...process.env, CLAUDE_PROJECT_DIR: mk(), SOMI_COST_CEILING: '' },
107
+ }).toString());
108
+ check('no ceiling argument: MCP and CLI both resolve ceiling low from the config', [mcpJson.ceiling, mcpJson.ceiling_source, cliJson.ceiling, cliJson.ceiling_source], ['low', 'config', 'low', 'config']);
109
+ check('a bare MCP resolve writes no .somi/somi-state', existsSync(path.join(proj, '.somi', 'somi-state')), false);
110
+ });
111
+
112
+ // --- #32: enforced/reason are exposed, and a config mapping makes copilot enforced ----------
113
+ await withClient({}, async (client) => {
114
+ await client.initialize();
115
+ const bare = JSON.parse(toolText(await toolCall(client, 'somi_resolve', { agent: 'somi-designer', host: 'copilot', ceiling: 'high', project_dir: fresh() })));
116
+ check('copilot, no mapping: model null, enforced false, reason names host',
117
+ [bare.model, bare.enforced, /no model mapping for host copilot.*low, medium and high/.test(bare.reason ?? '')], [null, false, true]);
118
+ const mapped = fresh();
119
+ mkdirSync(path.join(mapped, '.somi'), { recursive: true });
120
+ writeFileSync(path.join(mapped, '.somi', 'config.json'),
121
+ JSON.stringify({ cost: { mapping: { copilot: { low: 'gpt-5-mini', medium: 'gpt-5', high: 'gpt-5-pro' } } } }));
122
+ const m = JSON.parse(toolText(await toolCall(client, 'somi_resolve', { agent: 'somi-designer', host: 'copilot', ceiling: 'high', project_dir: mapped })));
123
+ check('copilot with config mapping: model set, enforced true, no reason',
124
+ [m.model, m.enforced, 'reason' in m], ['gpt-5-pro', true, false]);
125
+ const cc = JSON.parse(toolText(await toolCall(client, 'somi_resolve', { agent: 'somi-designer', host: 'claude-code', project_dir: fresh() })));
126
+ check('claude-code default: model set, enforced true', [typeof cc.model, cc.enforced], ['string', true]);
127
+ });
128
+
92
129
  // --- the four failure codes surface as isError with the matching code --------------------
93
130
  await withClient({}, async (client) => {
94
131
  await client.initialize();
@@ -109,11 +146,29 @@ async function run() {
109
146
  const brokenProj = fresh();
110
147
  mkdirSync(path.join(brokenProj, '.somi'), { recursive: true });
111
148
  writeFileSync(path.join(brokenProj, '.somi', 'config.json'), '{"cost": {"ceiling": "low"}\n'); // missing brace
112
- r = await toolCall(client, 'somi_resolve', { agent: 'coder', project_dir: brokenProj });
149
+ r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', project_dir: brokenProj });
113
150
  check('67 (project environment failure: unparsable config.json) is isError', r.isError, true);
114
151
  check('67 appears in the error text', /\(exit 67\)/.test(toolText(r)), true);
115
152
  });
116
153
 
154
+ // --- hard cap / overrides / size cap surface through somi_resolve unchanged -----------------
155
+ await withClient({}, async (client) => {
156
+ await client.initialize();
157
+ const withConfig = projWith;
158
+ let r = await toolCall(client, 'somi_resolve', { agent: 'somi-designer', project_dir: withConfig('{"cost":{"ceiling":"low"}}') });
159
+ let j = JSON.parse(toolText(r));
160
+ check('hard cap: high-only designer under ceiling low is clamped, degraded, tier_source ceiling', [j.tier, j.degraded, j.declared, j.tier_source], ['low', true, ['high'], 'ceiling']);
161
+ r = await toolCall(client, 'somi_resolve', { agent: 'somi-designer', project_dir: withConfig('{"cost":{"ceiling":"low","agents":{"somi-designer":"high"}}}') });
162
+ j = JSON.parse(toolText(r));
163
+ check('a cost.agents override wins over the ceiling', [j.tier, j.degraded, j.tier_source], ['high', false, 'override']);
164
+
165
+ r = await toolCall(client, 'somi_resolve', { agent: 'somi-designer', project_dir: withConfig('{"cost":{"agents":{"somi-designer":"turbo"}}}') });
166
+ check('a bad override value is isError with exit 67', [r.isError, /\(exit 67\)/.test(toolText(r))], [true, true]);
167
+
168
+ r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', project_dir: withConfig(`{"pad":"${'x'.repeat(70000)}"}`) });
169
+ check('an oversize config.json is isError with exit 67', [r.isError, /\(exit 67\)/.test(toolText(r))], [true, true]);
170
+ });
171
+
117
172
  // --- path traversal rejected before any read ----------------------------------------------
118
173
  await withClient({}, async (client) => {
119
174
  await client.initialize();
@@ -159,8 +214,8 @@ async function run() {
159
214
  // --- somi_agent: the agent's instructions without frontmatter, same allowlist ------------
160
215
  await withClient({}, async (client) => {
161
216
  await client.initialize();
162
- const r = await toolCall(client, 'somi_agent', { name: 'reviewer' });
163
- check('somi_agent returns agents/reviewer.md content, not an error', r.isError, undefined);
217
+ const r = await toolCall(client, 'somi_agent', { name: 'somi-reviewer' });
218
+ check('somi_agent returns agents/somi-reviewer.md content, not an error', r.isError, undefined);
164
219
  check('the returned text starts at the body: no frontmatter, no model: line', /^---|^model:/m.test(toolText(r)), false);
165
220
  check('the returned text is really the reviewer body', toolText(r).length > 1000 && /reviewer/i.test(toolText(r)), true);
166
221
 
@@ -206,7 +261,7 @@ async function run() {
206
261
  await withClient({}, async (client) => {
207
262
  await client.initialize();
208
263
  const proj = fresh();
209
- const r = await toolCall(client, 'somi_resolve', { agent: 'coder', project_dir: proj });
264
+ const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low', project_dir: proj });
210
265
  check('no host root: project_dir alone decides', r.isError, undefined);
211
266
  check('ceiling state landed under the project_dir argument', existsSync(path.join(proj, '.somi', 'somi-state')), true);
212
267
  });
@@ -216,7 +271,7 @@ async function run() {
216
271
  const envProj = fresh();
217
272
  await withClient({ CLAUDE_PROJECT_DIR: envProj }, async (client) => {
218
273
  await client.initialize();
219
- const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
274
+ const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low' });
220
275
  check('CLAUDE_PROJECT_DIR is used when no project_dir is given', r.isError, undefined);
221
276
  check('ceiling state landed under CLAUDE_PROJECT_DIR', existsSync(path.join(envProj, '.somi', 'somi-state')), true);
222
277
  });
@@ -230,7 +285,7 @@ async function run() {
230
285
  const outsideProj = fresh();
231
286
  await withClient({ CLAUDE_PROJECT_DIR: hostProj }, async (client) => {
232
287
  await client.initialize();
233
- const r = await toolCall(client, 'somi_resolve', { agent: 'coder', project_dir: outsideProj });
288
+ const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', project_dir: outsideProj });
234
289
  check('M3: project_dir outside the host root is refused', r.isError, true);
235
290
  check('M3: the refusal is a usage error (64)', /\(exit 64\)/.test(toolText(r)), true);
236
291
  check('M3: no .somi/ written under the host root', existsSync(path.join(hostProj, '.somi')), false);
@@ -246,12 +301,12 @@ async function run() {
246
301
  mkdirSync(insideProj, { recursive: true });
247
302
  await withClient({ CLAUDE_PROJECT_DIR: hostProj }, async (client) => {
248
303
  await client.initialize();
249
- const r = await toolCall(client, 'somi_resolve', { agent: 'coder', project_dir: insideProj });
304
+ const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low', project_dir: insideProj });
250
305
  check('M3: project_dir inside the host root is allowed', r.isError, undefined);
251
306
  check('M3: ceiling state landed under project_dir itself, not the host root', existsSync(path.join(insideProj, '.somi', 'somi-state')), true);
252
307
  check('M3: the host root itself got no .somi/ written', existsSync(path.join(hostProj, '.somi')), false);
253
308
 
254
- const r2 = await toolCall(client, 'somi_resolve', { agent: 'coder', project_dir: hostProj });
309
+ const r2 = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', project_dir: hostProj });
255
310
  check('M3: project_dir equal to the host root is allowed', r2.isError, undefined);
256
311
  });
257
312
  }
@@ -261,7 +316,7 @@ async function run() {
261
316
  await client.initialize({ roots: {} });
262
317
  const rootsProj = fresh();
263
318
  client.rootsHandler = () => [rootsProj];
264
- const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
319
+ const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low' });
265
320
  check('M1: a single MCP root is used when the client declares the capability', r.isError, undefined);
266
321
  check('M1: the server actually asked for roots/list', client.messages.some((m) => m.method === 'roots/list'), true);
267
322
  check('M1: ceiling state landed under the root the client returned', existsSync(path.join(rootsProj, '.somi', 'somi-state')), true);
@@ -272,7 +327,7 @@ async function run() {
272
327
  await withClient({}, async (client) => {
273
328
  await client.initialize({ roots: {} });
274
329
  client.rootsHandler = () => [{ uri: 'not-a-file-uri' }];
275
- const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
330
+ const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low' });
276
331
  check('M1: a non-file root URI is rejected outright (never resolved as a relative path)', r.isError, true);
277
332
  check('M1: with only a non-file root offered, "no root" (67) is reported, not a guessed path', /\(exit 67\)/.test(toolText(r)), true);
278
333
  });
@@ -289,7 +344,7 @@ async function run() {
289
344
  await withClient({}, async (client) => {
290
345
  await client.initialize({ roots: {} });
291
346
  client.rootsHandler = () => [{ uri: `file://${encodeURI(spaced)}` }];
292
- const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
347
+ const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low' });
293
348
  check('M1: a percent-encoded root URI resolves (isError undefined)', r.isError, undefined);
294
349
  check('M1: it decodes to the REAL space directory, not the literal-percent one', existsSync(path.join(spaced, '.somi', 'somi-state')), true);
295
350
  check('M1: the literal "a%20b" directory is untouched', existsSync(path.join(literalPercent, '.somi')), false);
@@ -303,12 +358,12 @@ async function run() {
303
358
  const rootA = fresh();
304
359
  const rootB = fresh();
305
360
  client.rootsHandler = () => [rootA, rootB];
306
- const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
361
+ const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low' });
307
362
  check('M1: more than one root with no project_dir is ambiguous and refused', r.isError, true);
308
363
  check('M1/M3: ambiguous roots refusal is the project-environment family (67)', /\(exit 67\)/.test(toolText(r)), true);
309
364
  check('M1: neither offered root got a .somi/ written', existsSync(path.join(rootA, '.somi')) || existsSync(path.join(rootB, '.somi')), false);
310
365
 
311
- const r2 = await toolCall(client, 'somi_resolve', { agent: 'coder', project_dir: rootB });
366
+ const r2 = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low', project_dir: rootB });
312
367
  check('M1+M3: project_dir selecting one of several ambiguous roots is allowed', r2.isError, undefined);
313
368
  check('M1+M3: state landed under the SELECTED root', existsSync(path.join(rootB, '.somi', 'somi-state')), true);
314
369
  check('M1+M3: the other offered root got nothing written', existsSync(path.join(rootA, '.somi')), false);
@@ -320,7 +375,7 @@ async function run() {
320
375
  await client.initialize({ roots: {} });
321
376
  const missing = path.join(tmpRoot, `missing-${Math.random().toString(36).slice(2)}`);
322
377
  client.rootsHandler = () => [missing];
323
- const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
378
+ const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder' });
324
379
  check('M1: a nonexistent MCP root is rejected', r.isError, true);
325
380
  check('M1: it is never silently created', existsSync(missing), false);
326
381
  });
@@ -329,14 +384,14 @@ async function run() {
329
384
  // malformed project_dir (relative, nonexistent) is a usage error (64) regardless.
330
385
  await withClient({}, async (client) => {
331
386
  await client.initialize(); // no `roots` capability declared
332
- const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
387
+ const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder' });
333
388
  check('no root establishable is isError', r.isError, true);
334
389
  check('the error names the reason and how to fix it', /project_dir/.test(toolText(r)), true);
335
390
  check('the exit-67 family is used for "cannot establish a root"', /\(exit 67\)/.test(toolText(r)), true);
336
391
 
337
- let r2 = await toolCall(client, 'somi_resolve', { agent: 'coder', project_dir: 'relative/path' });
392
+ let r2 = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', project_dir: 'relative/path' });
338
393
  check('a non-absolute project_dir is rejected (64)', /\(exit 64\)/.test(toolText(r2)), true);
339
- r2 = await toolCall(client, 'somi_resolve', { agent: 'coder', project_dir: '/definitely/does/not/exist/anywhere' });
394
+ r2 = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', project_dir: '/definitely/does/not/exist/anywhere' });
340
395
  check('a nonexistent project_dir is rejected (64)', /\(exit 64\)/.test(toolText(r2)), true);
341
396
  });
342
397
 
@@ -344,12 +399,12 @@ async function run() {
344
399
  await withClient({}, async (client) => {
345
400
  await client.initialize();
346
401
  const proj = fresh();
347
- let r = await toolCall(client, 'somi_resolve', { agent: 'coder', host: ['copilot'], project_dir: proj });
402
+ let r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', host: ['copilot'], project_dir: proj });
348
403
  check('m1: an array-valued host is rejected (64), not silently defaulted', /\(exit 64\)/.test(toolText(r)), true);
349
404
  check('m1: a rejected host leaves the project root untouched', existsSync(path.join(proj, '.somi')), false);
350
405
 
351
406
  const proj2 = fresh();
352
- r = await toolCall(client, 'somi_resolve', { agent: 'coder', ceiling: '', project_dir: proj2 });
407
+ r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: '', project_dir: proj2 });
353
408
  check('m1: an empty-string ceiling is rejected (64), not silently defaulted', /\(exit 64\)/.test(toolText(r)), true);
354
409
  check('m1: a rejected ceiling leaves the project root untouched', existsSync(path.join(proj2, '.somi')), false);
355
410
  });
@@ -371,8 +426,8 @@ async function run() {
371
426
  {
372
427
  const badInputs = [
373
428
  { name: 'invalid agent name', args: { agent: 'Not-Valid' } },
374
- { name: 'unrecognized ceiling', args: { agent: 'coder', ceiling: 'ultra' } },
375
- { name: 'somi is exempt from cost:', args: { agent: 'somi' } },
429
+ { name: 'unrecognized ceiling', args: { agent: 'somi-coder', ceiling: 'ultra' } },
430
+ { name: 'somi is exempt from cost resolution', args: { agent: 'somi' } },
376
431
  { name: 'unknown agent', args: { agent: 'totally-not-a-real-agent' } },
377
432
  ];
378
433
  for (const { name, args } of badInputs) {
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env node
2
+ // Drives scripts/somi-mcp.mjs over real stdio JSON-RPC for the somi_tier tool: the sizing CLI's own output and
3
+ // exit codes for every case, the advertised schema, and the hint for invented signal names. Invoked from
4
+ // tests/scripts/somi-mcp.sh next to the main MCP tests.
5
+
6
+ import { execFileSync } from 'node:child_process';
7
+ import { existsSync } from 'node:fs';
8
+ import path from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
10
+ import { McpClient } from './somi-mcp-client.mjs';
11
+ import { SIGNAL_IDS } from '../../../scripts/lib/size-tier.mjs';
12
+
13
+ const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
14
+ const SERVER = path.join(ROOT, 'scripts', 'somi-mcp.mjs');
15
+ let pass = 0; let fail = 0;
16
+ const check = (name, got, want) => {
17
+ if (JSON.stringify(got) === JSON.stringify(want)) { pass++; console.log(` ok ${name}`); } else { fail++; console.log(` FAIL ${name} (want ${JSON.stringify(want)}, got ${JSON.stringify(got)})`); }
18
+ };
19
+ async function withClient(env, fn) {
20
+ const client = new McpClient(SERVER, { env });
21
+ try { await client.initialize(); return await fn(client); } finally { client.close(); }
22
+ }
23
+ const toolCall = (client, name, args) => client.request('tools/call', { name, arguments: args });
24
+ const toolText = (r) => r?.content?.[0]?.text ?? '';
25
+
26
+ async function run() {
27
+ console.log('== somi_tier (MCP) ==');
28
+ // --- somi_tier: the sizing CLI's own output and exit codes, for every case --------------------
29
+ await withClient({}, async (client) => {
30
+ await client.initialize();
31
+ const TIER_CLI = path.join(ROOT, 'scripts', 'somi-tier.mjs');
32
+ const base = { T1: true, T2: true, T3: true, T4: true, T5: true, sensitive_core: false, hard_surface: false, design_open: false, open_questions: 0, acceptance_testable: true, modules_touched: 1, est_files: 1, est_diff_lines: 40, existing_work_item: false, brief_exists: false };
33
+ const sig = (over = {}) => Object.fromEntries(Object.entries({ ...base, ...over }).map(([k, v]) => [k, { value: v, evidence: 'e' }]));
34
+ const cases = [
35
+ ['trivial', sig(), undefined], ['small', sig({ T2: false, est_diff_lines: 80 }), undefined],
36
+ ['floor', sig({ T3: false, sensitive_core: true, hard_surface: true }), undefined], ['security lens, no floor', sig({ T3: false }), undefined], ['unknown signal', { ...sig(), T3: { value: null, evidence: 'x' } }, undefined],
37
+ ['raise', sig(), 'full'], ['lower below the floor', sig({ T3: false, sensitive_core: true }), 'small'],
38
+ ];
39
+ for (const [label, signals, override] of cases) {
40
+ const argv = [TIER_CLI, 'resolve', '--signals', '-', ...(override ? ['--override', override] : [])];
41
+ let want; let code = 0;
42
+ try { want = execFileSync(process.execPath, argv, { input: JSON.stringify(signals), encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trimEnd(); } catch (e) { code = e.status; want = null; }
43
+ const r = await toolCall(client, 'somi_tier', { signals, ...(override ? { override } : {}) });
44
+ if (code === 0) check(`somi_tier ${label}: same JSON as the CLI`, [r.isError, toolText(r)], [undefined, want]);
45
+ else check(`somi_tier ${label}: error carries the CLI exit code`, [r.isError, toolText(r).endsWith(`(exit ${code})`)], [true, true]);
46
+ }
47
+ // The advertised schema lists the rubric's own ids (imported, not copied), each with value and evidence.
48
+ const tierTool = ((await client.request('tools/list', {})).tools || []).find((t) => t.name === 'somi_tier');
49
+ const sp = tierTool?.inputSchema?.properties?.signals;
50
+ check('somi_tier schema: signals lists exactly the rubric signal ids, all required', [Object.keys(sp?.properties ?? {}), sp?.required], [[...SIGNAL_IDS], [...SIGNAL_IDS]]);
51
+ check('somi_tier schema: every signal is an object that requires value and evidence', Object.values(sp?.properties ?? {}).every((v) => v.type === 'object' && JSON.stringify(v.required) === '["value","evidence"]'), true);
52
+ check('somi_tier description says the ids are exact and points at the routing skill without stating a threshold', [/ids in `signals` are exact/.test(tierTool?.description ?? ''), /somi-routing/.test(sp?.description ?? ''), /\b(40|50)\b/.test(JSON.stringify(sp))], [true, true, false]);
53
+ const invented = await toolCall(client, 'somi_tier', { signals: { business_logic_complexity: { value: true, evidence: 'SECRET-VALUE' }, 'x\u202ey': 1 } });
54
+ const iv = JSON.parse(toolText(invented));
55
+ check('somi_tier: invented names come back as unrecognized next to the expected ids; the decision is the closed one (full) and no value is echoed', [iv.tier, iv.unrecognized, iv.expected, toolText(invented).includes('SECRET-VALUE'), toolText(invented).includes('\u202e')], ['full', ['business_logic_complexity', 'x\u202ey'], [...SIGNAL_IDS], false, false]);
56
+ check('somi_tier: a correct call carries neither unrecognized nor expected', ['unrecognized' in JSON.parse(toolText(await toolCall(client, 'somi_tier', { signals: sig() }))), 'expected' in JSON.parse(toolText(await toolCall(client, 'somi_tier', { signals: sig() })))], [false, false]);
57
+ const noObj = await toolCall(client, 'somi_tier', { signals: [1] });
58
+ check('somi_tier rejects non-object signals with 64 and writes nothing', [noObj.isError, /\(exit 64\)/.test(toolText(noObj)), existsSync(path.join(ROOT, '.somi', 'somi-state', 'tier', 'x.json'))], [true, true, false]);
59
+ });
60
+
61
+ console.log(`somi_tier tests: ${pass} ok, ${fail} failed`);
62
+ if (fail) process.exitCode = 1;
63
+ }
64
+ run().catch((e) => { console.error(e); process.exit(1); });
@@ -271,6 +271,25 @@ case "$out10" in
271
271
  bad "an odd-count nested fence run left the tracker stuck open -- 'model: opus' below it was silently exempted (got: $out10)" ;;
272
272
  esac
273
273
 
274
+ # --- RED/GREEN: prose claiming an agent declares a frontmatter `cost:` tier or range ------------
275
+ COSTCLAIM="$TMP/costclaim"; mkdir -p "$COSTCLAIM/docs"
276
+ printf '%s\n' 'The coder declares `cost: medium` in its frontmatter.' > "$COSTCLAIM/docs/a.md"
277
+ printf '%s\n' 'The reviewer is graded as cost: medium, high.' > "$COSTCLAIM/docs/b.md"
278
+ printf '%s\n' '- **Cost**: `medium, high` - one job over two depths.' > "$COSTCLAIM/docs/c.md"
279
+ printf '%s\n' '| `somi-planner` | `low, medium` | when |' > "$COSTCLAIM/docs/d.md"
280
+ out11="$(cd "$COSTCLAIM" && node "$GATE" docs 2>&1)"
281
+ case "$out11" in
282
+ "STALE VOCABULARY (4 hit(s))"*) ok "a bare backticked range in a Cost bullet or table cell, a 'declares \`cost: <tier>\`' claim and a 'cost: medium, high' range both fail the gate" ;;
283
+ *) bad "the retired frontmatter-cost claims did not fail the gate (got: $out11)" ;;
284
+ esac
285
+ COSTOK="$TMP/costok"; mkdir -p "$COSTOK/docs"
286
+ printf '%s\n' 'The coder defaults to `medium`; a command declares no `cost:` of its own, and (`cost: high`) names a tier; the ceiling is `low`, `medium` and `high`.' > "$COSTOK/docs/a.md"
287
+ out12="$(cd "$COSTOK" && node "$GATE" docs 2>&1)"
288
+ case "$out12" in
289
+ ok*) ok "default-tier wording, 'declares no \`cost:\`' and a bare tier label do not fail the gate" ;;
290
+ *) bad "default-tier wording failed the gate (got: $out12)" ;;
291
+ esac
292
+
274
293
  # --- Pin EXEMPT_FILES.size so growing the exemption list is a deliberate, visible edit -----------
275
294
  exempt_count="$(awk '
276
295
  /^const EXEMPT_FILES = new Set\(\[$/ { f=1; next }
@@ -12,7 +12,7 @@ derive() { grep -oE '^\| *`[a-z][a-z0-9-]*`' "$1/commands/review-panel.md" | tr
12
12
 
13
13
  echo "== review-panel seated-lens derivation =="
14
14
  seated="$(derive "$ROOT")"
15
- for a in reviewer security-reviewer architecture-reviewer test-strategist plan-reviewer sdlc-reviewer; do
15
+ for a in somi-reviewer somi-security-reviewer somi-architecture-reviewer somi-test-strategist somi-plan-reviewer somi-sdlc-reviewer; do
16
16
  if grep -qx "$a" <<<"$seated"; then ok "derived membership includes $a"; else bad "derived membership is missing $a"; fi
17
17
  grep -q '^## Write discipline' "$ROOT/agents/$a.md" && ok "agents/$a.md has Write discipline" || bad "agents/$a.md lacks Write discipline"
18
18
  done
@@ -23,7 +23,7 @@ done
23
23
 
24
24
  TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
25
25
  cp -a "$ROOT/commands" "$ROOT/agents" "$TMP/"
26
- sed -i '/^## Write discipline/d' "$TMP/agents/plan-reviewer.md"
26
+ sed -i '/^## Write discipline/d' "$TMP/agents/somi-plan-reviewer.md"
27
27
  red=0
28
28
  for a in $(derive "$TMP"); do grep -q '^## Write discipline' "$TMP/agents/$a.md" || red=$((red+1)); done
29
29
  [ "$red" -eq 1 ] && ok "RED: removing plan-reviewer's Write discipline is caught via the derived table" || bad "RED fixture caught $red agents, expected 1"
@@ -68,6 +68,101 @@ check "init: CLI flag beats env and config" \
68
68
  expect_exit "init: refuses to clobber a running loop without --force" 64 \
69
69
  node "$LOOP" init --slug demo --loop code --iteration 1.1 --files "src/a.txt"
70
70
 
71
+ # --- somi-loop: a brief-only work item (plan dir without phases/) needs the approved tier record ---
72
+ mkdir -p .somi/plans/bo
73
+ printf 'brief one\n' > .somi/plans/bo/brief.md
74
+ TIER="$ROOT/scripts/somi-tier.mjs"
75
+ node -e 'const s={};for(const k of ["T1","T2","T3","T4","T5"])s[k]={value:k!=="T2",evidence:"e"};Object.assign(s,{sensitive_core:{value:false,evidence:"e"},hard_surface:{value:false,evidence:"e"},design_open:{value:false,evidence:"e"},open_questions:{value:0,evidence:"e"},acceptance_testable:{value:true,evidence:"e"},modules_touched:{value:1,evidence:"e"},est_files:{value:2,evidence:"e"},est_diff_lines:{value:80,evidence:"e"},existing_work_item:{value:false,evidence:"e"},brief_exists:{value:false,evidence:"e"}});console.log(JSON.stringify(s))' > "$TMP/small-signals.json"
76
+ expect_exit "brief-only: refused with no tier record" 64 \
77
+ node "$LOOP" init --force --slug bo --loop code --iteration 1.1 --files ".somi/plans/bo/brief.md"
78
+ node "$TIER" resolve --signals "$TMP/small-signals.json" --record bo --project-dir "$REPO" >/dev/null
79
+ check "brief-only: tier record is small" "$(jq -e '.tier == "small"' .somi/somi-state/tier/bo.json >/dev/null; echo $?)"
80
+ expect_exit "brief-only: refused when sized but not approved" 64 \
81
+ node "$LOOP" init --force --slug bo --loop code --iteration 1.1 --files ".somi/plans/bo/brief.md"
82
+ node "$TIER" approve --slug bo --project-dir "$REPO" >/dev/null
83
+ expect_exit "brief-only: accepted once approved" 0 \
84
+ node "$LOOP" init --force --slug bo --loop code --iteration 1.1 --files ".somi/plans/bo/brief.md"
85
+ printf 'brief two\n' > .somi/plans/bo/brief.md
86
+ expect_exit "brief-only: refused once the brief changed after approval" 64 \
87
+ node "$LOOP" init --force --slug bo --loop code --iteration 1.1 --files ".somi/plans/bo/brief.md"
88
+ mkdir -p .somi/plans/bo/phases
89
+ expect_exit "a plan with phases/ is unaffected" 0 \
90
+ node "$LOOP" init --force --slug bo --loop code --iteration 1.1 --files "src/a.txt"
91
+ out="$(node "$LOOP" init --force --slug bo --loop code --iteration 1.1 --files "src/a.txt")"
92
+ check "review lens: a record proven free of untrusted input and the core asks for no lens" \
93
+ "$(jq -e '.review_min == null' <<<"$out" >/dev/null && jq -e '.security_lens == false' .somi/somi-state/tier/bo.json >/dev/null; echo $?)"
94
+ jq '.T3.value = false' "$TMP/small-signals.json" > "$TMP/lens-signals.json"
95
+ node "$TIER" resolve --signals "$TMP/lens-signals.json" --record lens --project-dir "$REPO" >/dev/null
96
+ check "review lens: untrusted input alone stays small and records the security lens" \
97
+ "$(jq -e '.tier == "small" and .security_lens == true' .somi/somi-state/tier/lens.json >/dev/null; echo $?)"
98
+ mkdir -p .somi/plans/lens/phases
99
+ out="$(node "$LOOP" init --force --slug lens --loop code --iteration 1.1 --files "src/a.txt")"
100
+ check "review lens: init carries review_min security from the tier record" "$(jq -e '.review_min == "security"' <<<"$out" >/dev/null; echo $?)"
101
+ out="$(node "$LOOP" pass --slug lens --iteration 1.1)"
102
+ check "review lens: every pass repeats review_min" "$(jq -e '.pass == 1 and .review_min == "security"' <<<"$out" >/dev/null; echo $?)"
103
+ out="$(node "$LOOP" init --force --slug lens --loop plan --iteration 1.1)"
104
+ check "review lens: a plan loop carries no review_min" "$(jq -e '.review_min == null' <<<"$out" >/dev/null; echo $?)"
105
+ rm -rf .somi/plans/bo .somi/plans/lens .somi/somi-state/tier
106
+
107
+ # --- somi-loop: review scope (delta re-review from pass 2; full on the first and the last pass) ---
108
+ node "$LOOP" init --force --slug scope --loop code --iteration 1.1 --max-passes 3 --files "src/" >/dev/null
109
+ node "$LOOP" pass --slug scope --iteration 1.1 >/dev/null
110
+ out="$(node "$LOOP" review-scope --slug scope --iteration 1.1)"
111
+ check "review scope: pass 1 is reviewed in full" "$(jq -e '.scope == "full" and .why == "first-pass"' <<<"$out" >/dev/null; echo $?)"
112
+ idx_before="$(git ls-files -s | sha256sum)"; staged_before="$(git diff --cached --name-only | sha256sum)"
113
+ node "$LOOP" record-pass --slug scope --iteration 1.1 --verdict request-changes --blockers 0 --majors 1 >/dev/null
114
+ check "review scope: record-pass stores the reviewed tree" "$(node "$LOOP" stats --slug scope --iteration 1.1 | jq -e '.history[0].tree | test("^[0-9a-f]{40}$")' >/dev/null; echo $?)"
115
+ check "review scope: snapshotting leaves the caller's index untouched" "$([[ "$(git ls-files -s | sha256sum)" == "$idx_before" && "$(git diff --cached --name-only | sha256sum)" == "$staged_before" ]]; echo $?)"
116
+ printf 'fixed\n' >> src/a.txt; printf 'new\n' > src/new-untracked.txt
117
+ node "$LOOP" pass --slug scope --iteration 1.1 >/dev/null
118
+ out="$(node "$LOOP" review-scope --slug scope --iteration 1.1)"
119
+ check "review scope: pass 2 sees only the delta since the reviewed tree, untracked files included" \
120
+ "$(jq -e '.scope == "delta" and .since_pass == 1 and (.files | sort) == ["src/a.txt","src/new-untracked.txt"]' <<<"$out" >/dev/null; echo $?)"
121
+ check "review scope: the delta's trees reproduce the change" "$(git diff "$(jq -r .from <<<"$out")" "$(jq -r .to <<<"$out")" -- src/a.txt | grep -qx '+fixed'; echo $?)"
122
+ out="$(SOMI_CODE_LOOP_REVIEW_SCOPE=full node "$LOOP" review-scope --slug scope --iteration 1.1)"
123
+ check "review scope: SOMI_CODE_LOOP_REVIEW_SCOPE=full restores full re-review" "$(jq -e '.scope == "full" and .why == "setting"' <<<"$out" >/dev/null; echo $?)"
124
+ printf '{"code_loop": {"review_scope": "full"}}\n' > .somi/config.json
125
+ out="$(node "$LOOP" review-scope --slug scope --iteration 1.1)"
126
+ check "review scope: code_loop.review_scope full in config restores full re-review" "$(jq -e '.scope == "full"' <<<"$out" >/dev/null; echo $?)"
127
+ printf '{"code_loop": {"max_passes": 2, "diff_cap_lines": 10}}\n' > .somi/config.json
128
+ expect_exit "review scope: an unknown setting is refused" 64 env SOMI_CODE_LOOP_REVIEW_SCOPE=partial node "$LOOP" review-scope --slug scope --iteration 1.1
129
+ node "$LOOP" record-pass --slug scope --iteration 1.1 --verdict request-changes --blockers 0 --majors 1 >/dev/null
130
+ node "$LOOP" pass --slug scope --iteration 1.1 >/dev/null
131
+ out="$(node "$LOOP" review-scope --slug scope --iteration 1.1)"
132
+ check "review scope: the last allowed pass is reviewed in full" "$(jq -e '.scope == "full" and .why == "last-pass"' <<<"$out" >/dev/null; echo $?)"
133
+ git checkout -q -- src/a.txt; rm -f src/new-untracked.txt
134
+
135
+ # --- somi-loop: a /ship-loop run's wall-time budget, enforced at every pass on the slug ---
136
+ out="$(node "$LOOP" run-start --slug clock)"
137
+ check "run-start: without a budget the start is recorded and max_minutes is null" "$(jq -e '.max_minutes == null and (.started | test("T"))' <<<"$out" >/dev/null; echo $?)"
138
+ node "$LOOP" init --force --slug clock --loop plan >/dev/null
139
+ expect_exit "pass: no budget, no time stop" 0 node "$LOOP" pass --slug clock
140
+ out="$(node "$LOOP" run-start --slug clock --max-minutes 30)"
141
+ check "run-start: a resumed run keeps its clock and budget" "$(jq -e '.resumed == true and .max_minutes == null' <<<"$out" >/dev/null; echo $?)"
142
+ out="$(SOMI_SHIP_LOOP_MAX_MINUTES=30 node "$LOOP" run-start --force --slug clock)"
143
+ check "run-start: the env budget is recorded" "$(jq -e '.max_minutes == 30' <<<"$out" >/dev/null; echo $?)"
144
+ expect_exit "pass: inside the budget" 0 node "$LOOP" pass --slug clock
145
+ jq '.started = "2000-01-01T00:00:00.000Z"' .somi/somi-state/run/clock.json > "$TMP/clock.json" && cp "$TMP/clock.json" .somi/somi-state/run/clock.json
146
+ expect_exit "pass: an exhausted time budget stops every loop on the slug (exit 4)" 4 node "$LOOP" pass --slug clock
147
+ check "pass: the refused pass is not counted" "$(node "$LOOP" stats --slug clock | jq -e '.pass == 2' >/dev/null; echo $?)"
148
+ jq '.started = "not a date"' .somi/somi-state/run/clock.json > "$TMP/clock.json" && cp "$TMP/clock.json" .somi/somi-state/run/clock.json
149
+ expect_exit "pass: an unreadable start fails closed" 4 node "$LOOP" pass --slug clock
150
+ expect_exit "run-start: a zero budget is refused" 64 node "$LOOP" run-start --force --slug clock --max-minutes 0
151
+ expect_exit "run-start: a malformed budget is refused" 64 node "$LOOP" run-start --force --slug clock --max-minutes soon
152
+ rm -rf .somi/somi-state/run
153
+
154
+ # --- somi-loop: the dispatch record is the resolver's answer, never the caller's claim ---
155
+ out="$(node "$LOOP" record-dispatch --slug scope --iteration 1.1 --agent somi-coder)"
156
+ check "record-dispatch: claude-code entry carries tier, model and enforced from the resolver" \
157
+ "$(jq -e '.agent == "somi-coder" and .host == "claude-code" and .pass == 3 and (.tier | type) == "string" and .enforced == true and (.model | type) == "string"' <<<"$out" >/dev/null; echo $?)"
158
+ out="$(node "$LOOP" record-dispatch --slug scope --iteration 1.1 --agent somi-reviewer --host copilot)"
159
+ check "record-dispatch: an unmapped host is recorded as not enforced, with the reason" \
160
+ "$(jq -e '.host == "copilot" and .model == null and .enforced == false and (.reason | test("no model mapping"))' <<<"$out" >/dev/null; echo $?)"
161
+ expect_exit "record-dispatch: an unknown agent is refused with the resolver's code" 65 node "$LOOP" record-dispatch --slug scope --iteration 1.1 --agent reviewer
162
+ expect_exit "record-dispatch: --agent is required" 64 node "$LOOP" record-dispatch --slug scope --iteration 1.1
163
+ out="$(node "$LOOP" finish --slug scope --iteration 1.1 --status done)"
164
+ check "finish: the summary lists every recorded dispatch" "$(jq -e '(.dispatches | length) == 2 and .dispatches[1].enforced == false' <<<"$out" >/dev/null; echo $?)"
165
+
71
166
  # --- somi-loop: pass counting ---------------------------------------------------
72
167
  node "$LOOP" pass --slug demo --iteration 1.1 >/dev/null
73
168
  expect_exit "pass: exceeding max_passes exits 2" 2 \