@skathio/somi 2.2.2 → 3.0.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.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +8 -2
- package/.copilot-extension/extension.json +9 -8
- package/.copilot-extension/marketplace.json +2 -2
- package/README.md +45 -33
- package/VERSION +1 -1
- package/agents/architecture-reviewer.md +16 -0
- package/agents/atlas.md +102 -0
- package/agents/coder.md +66 -22
- package/agents/designer.md +20 -16
- package/agents/discovery-analyst.md +6 -5
- package/agents/impact.md +97 -0
- package/agents/incident.md +96 -0
- package/agents/plan-reviewer.md +70 -0
- package/agents/planner.md +77 -20
- package/agents/pr.md +101 -0
- package/agents/refactor-designer.md +82 -0
- package/agents/refactorer.md +30 -24
- package/agents/reviewer.md +28 -25
- package/agents/sdlc-reviewer.md +69 -0
- package/agents/security-reviewer.md +17 -0
- package/agents/somi.md +204 -153
- package/agents/test-strategist.md +16 -1
- package/commands/adopt.md +21 -7
- package/commands/architecture-review.md +8 -5
- package/commands/atlas.md +24 -72
- package/commands/code-loop.md +46 -15
- package/commands/code-parallel.md +6 -4
- package/commands/code.md +29 -21
- package/commands/debug.md +17 -11
- package/commands/design.md +48 -31
- package/commands/discover.md +26 -16
- package/commands/impact.md +16 -54
- package/commands/incident.md +22 -55
- package/commands/plan-loop.md +43 -17
- package/commands/plan.md +64 -26
- package/commands/pr.md +19 -66
- package/commands/refactor-design.md +98 -0
- package/commands/refactor.md +22 -23
- package/commands/release-readiness.md +16 -7
- package/commands/review-panel.md +31 -10
- package/commands/review.md +21 -14
- package/commands/security-review.md +12 -3
- package/commands/ship-loop.md +71 -54
- package/commands/ship.md +17 -13
- package/commands/test-strategy.md +6 -4
- package/commands/upgrade.md +10 -8
- package/examples/discovery-example.md +2 -2
- package/examples/sample-consumer/CLAUDE.md +41 -7
- package/examples/sample-consumer/README.md +36 -22
- package/hooks/lib/common.mjs +66 -20
- package/hooks/post-tool/audit-log.mjs +7 -11
- package/hooks/post-tool/lint-changed-files.mjs +8 -11
- package/hooks/pre-tool/block-dangerous-bash.mjs +32 -44
- package/hooks/pre-tool/block-secret-writes.mjs +6 -9
- package/hooks/pre-tool/gate-dep-install.mjs +18 -27
- package/hooks/pre-tool/guard-protected-paths.mjs +9 -11
- package/hooks/session-start/detect-repo-instructions.mjs +21 -23
- package/hooks/user-prompt-submit/inject-workflow-context.mjs +190 -42
- package/mcp.json +10 -0
- package/package.json +5 -2
- package/rules/CLAUDE.md +22 -19
- package/scripts/check-links.mjs +218 -0
- package/scripts/check-session-artefacts.mjs +149 -0
- package/scripts/check-size-budget.mjs +137 -0
- package/scripts/generate-digest.mjs +176 -0
- package/scripts/lib/cost-ceiling.mjs +317 -0
- package/scripts/lib/cost-model.mjs +95 -0
- package/scripts/lib/dispatch-resolver.mjs +225 -0
- package/scripts/lib/mcp-project-root.mjs +183 -0
- package/scripts/size-budget-overrides.json +74 -0
- package/scripts/somi-check.mjs +6 -13
- package/scripts/somi-dispatch.mjs +141 -0
- package/scripts/somi-findings.mjs +4 -5
- package/scripts/somi-loop.mjs +181 -13
- package/scripts/somi-mcp.mjs +357 -0
- package/scripts/validate.sh +691 -30
- package/skills/clean-code/SKILL.md +1 -1
- package/skills/plan-review/SKILL.md +79 -0
- package/skills/rules/SKILL.md +47 -0
- package/skills/sdlc-process/SKILL.md +74 -0
- package/skills/somi-dispatch/SKILL.md +220 -0
- package/skills/somi-routing/SKILL.md +31 -6
- package/skills/{test-strategy → testing-playbook}/SKILL.md +1 -1
- package/templates/ATLAS.md.tmpl +4 -4
- package/templates/BRIEF.md.tmpl +23 -22
- package/templates/DECISIONS.md.tmpl +1 -0
- package/templates/DESIGN.md.tmpl +5 -5
- package/templates/DIARY.md.tmpl +10 -5
- package/templates/DOD.md.tmpl +24 -0
- package/templates/PROGRESS.md.tmpl +3 -16
- package/templates/SOMI-README.md.tmpl +3 -3
- package/tests/hooks/cases/inject-workflow-context.json +120 -7
- package/tests/hooks/run.sh +20 -11
- package/tests/scripts/check-links.sh +105 -0
- package/tests/scripts/check-session-artefacts.sh +60 -0
- package/tests/scripts/check-size-budget.sh +71 -0
- package/tests/scripts/checkpoint-gate.sh +90 -0
- package/tests/scripts/convergence-runner.sh +1510 -0
- package/tests/scripts/cost-ceiling.sh +343 -0
- package/tests/scripts/cost-model.sh +192 -0
- package/tests/scripts/dispatch-guard.sh +108 -0
- package/tests/scripts/dispatch-reference-gate.sh +173 -0
- package/tests/scripts/eval-runner.sh +3691 -0
- package/tests/scripts/evals-packaging.sh +117 -0
- package/tests/scripts/fixtures/legacy-shard-no-schema.json +50 -0
- package/tests/scripts/generate-digest.sh +180 -0
- package/tests/scripts/goldens/loop-state-breach.json +1 -0
- package/tests/scripts/goldens/loop-state-done.json +1 -0
- package/tests/scripts/goldens/somi-loop.json +1 -1
- package/tests/scripts/lib/adr-shape.mjs +41 -0
- package/tests/scripts/lib/checkpoint-gate.mjs +54 -0
- package/tests/scripts/lib/digest-marker-coupling.mjs +52 -0
- package/tests/scripts/lib/dispatch-reference-gate.mjs +112 -0
- package/tests/scripts/lib/multipass-dependence.mjs +192 -0
- package/tests/scripts/lib/multipass-source-identity.mjs +243 -0
- package/tests/scripts/lib/reference-pair.mjs +61 -0
- package/tests/scripts/lib/retirement-gate.mjs +167 -0
- package/tests/scripts/lib/shell-embedded-js.mjs +47 -0
- package/tests/scripts/lib/somi-mcp-client.mjs +102 -0
- package/tests/scripts/lib/somi-mcp-tests.mjs +401 -0
- package/tests/scripts/lib/somi-mcp-tool-schema.mjs +38 -0
- package/tests/scripts/retirement-gate.sh +287 -0
- package/tests/scripts/review-panel-seats.sh +32 -0
- package/tests/scripts/run.sh +184 -2
- package/tests/scripts/somi-agent-dispatch-contract.sh +195 -0
- package/tests/scripts/somi-dispatch.sh +366 -0
- package/tests/scripts/somi-mcp.sh +12 -0
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Drives scripts/somi-mcp.mjs over REAL stdio JSON-RPC (via somi-mcp-client.mjs) to prove the
|
|
3
|
+
// bundled MCP server behaves identically to scripts/somi-dispatch.mjs's CLI (they share
|
|
4
|
+
// scripts/lib/dispatch-resolver.mjs) and that its own project-root resolution
|
|
5
|
+
// (scripts/lib/mcp-project-root.mjs) follows the documented order without ever touching this
|
|
6
|
+
// repo's own .somi/somi-state/. Every scenario runs against its own throwaway temp directory.
|
|
7
|
+
//
|
|
8
|
+
// Invoked from tests/scripts/somi-mcp.sh, which is wired into scripts/validate.sh.
|
|
9
|
+
|
|
10
|
+
import { execFileSync } from 'node:child_process';
|
|
11
|
+
import { mkdtempSync, rmSync, mkdirSync, writeFileSync, existsSync } from 'node:fs';
|
|
12
|
+
import { tmpdir } from 'node:os';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import { fileURLToPath } from 'node:url';
|
|
15
|
+
import { McpClient } from './somi-mcp-client.mjs';
|
|
16
|
+
|
|
17
|
+
const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
|
|
18
|
+
const SERVER = path.join(ROOT, 'scripts', 'somi-mcp.mjs');
|
|
19
|
+
const CLI = path.join(ROOT, 'scripts', 'somi-dispatch.mjs');
|
|
20
|
+
|
|
21
|
+
let pass = 0;
|
|
22
|
+
let fail = 0;
|
|
23
|
+
function ok(name) { pass++; console.log(` ok ${name}`); }
|
|
24
|
+
function bad(name, detail) { fail++; console.log(` FAIL ${name}${detail ? ` (${detail})` : ''}`); }
|
|
25
|
+
function check(name, got, want) {
|
|
26
|
+
if (JSON.stringify(got) === JSON.stringify(want)) ok(name);
|
|
27
|
+
else bad(name, `want ${JSON.stringify(want)}, got ${JSON.stringify(got)}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const tmpRoot = mkdtempSync(path.join(tmpdir(), 'somi-mcp-test-'));
|
|
31
|
+
function fresh() {
|
|
32
|
+
const d = path.join(tmpRoot, `p${Math.random().toString(36).slice(2)}`);
|
|
33
|
+
mkdirSync(d, { recursive: true });
|
|
34
|
+
return d;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function withClient(env, fn) {
|
|
38
|
+
const client = new McpClient(SERVER, { env });
|
|
39
|
+
try {
|
|
40
|
+
return await fn(client);
|
|
41
|
+
} finally {
|
|
42
|
+
client.close();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function toolCall(client, name, args) {
|
|
47
|
+
return client.request('tools/call', { name, arguments: args });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function toolText(result) {
|
|
51
|
+
return result?.content?.[0]?.text ?? '';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function run() {
|
|
55
|
+
console.log('== somi-mcp (stdio MCP server) ==');
|
|
56
|
+
|
|
57
|
+
// --- initialize / tools/list -------------------------------------------------------------
|
|
58
|
+
await withClient({}, async (client) => {
|
|
59
|
+
const init = await client.initialize();
|
|
60
|
+
check('initialize echoes the requested protocolVersion', init.protocolVersion, '2024-11-05');
|
|
61
|
+
check('initialize reports capabilities.tools', init.capabilities?.tools, {});
|
|
62
|
+
check('initialize reports serverInfo.name', init.serverInfo?.name, 'somi');
|
|
63
|
+
|
|
64
|
+
const list = await client.request('tools/list', {});
|
|
65
|
+
const names = (list.tools || []).map((t) => t.name).sort();
|
|
66
|
+
check('tools/list carries exactly somi_resolve, somi_command, and somi_skill', names, ['somi_command', 'somi_resolve', 'somi_skill']);
|
|
67
|
+
|
|
68
|
+
const ping = await client.request('ping', {});
|
|
69
|
+
check('ping returns an empty result', ping, {});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// --- somi_resolve success matches the CLI's own output for the same args ------------------
|
|
73
|
+
await withClient({}, async (client) => {
|
|
74
|
+
await client.initialize();
|
|
75
|
+
const proj = fresh();
|
|
76
|
+
const result = await toolCall(client, 'somi_resolve', { agent: 'coder', host: 'claude-code', project_dir: proj });
|
|
77
|
+
const mcpJson = JSON.parse(toolText(result));
|
|
78
|
+
|
|
79
|
+
const cliOut = execFileSync(process.execPath, [CLI, 'resolve', '--agent', 'coder', '--host', 'claude-code'], {
|
|
80
|
+
env: { ...process.env, CLAUDE_PROJECT_DIR: fresh() },
|
|
81
|
+
encoding: 'utf8',
|
|
82
|
+
});
|
|
83
|
+
const cliJson = JSON.parse(cliOut);
|
|
84
|
+
check(
|
|
85
|
+
'somi_resolve (project_dir arg) matches the CLI byte-for-shape on tier/model/supported',
|
|
86
|
+
{ tier: mcpJson.tier, model: mcpJson.model, supported: mcpJson.supported, agent: mcpJson.agent },
|
|
87
|
+
{ tier: cliJson.tier, model: cliJson.model, supported: cliJson.supported, agent: cliJson.agent },
|
|
88
|
+
);
|
|
89
|
+
check('the resolved project dir is where ceiling state actually landed', existsSync(path.join(proj, '.somi', 'somi-state', 'ceiling.json')), true);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// --- the four failure codes surface as isError with the matching code --------------------
|
|
93
|
+
await withClient({}, async (client) => {
|
|
94
|
+
await client.initialize();
|
|
95
|
+
|
|
96
|
+
let r = await toolCall(client, 'somi_resolve', { agent: '../etc/passwd', project_dir: fresh() });
|
|
97
|
+
check('64 (usage: invalid agent) is isError', r.isError, true);
|
|
98
|
+
check('64 appears in the error text', /\(exit 64\)/.test(toolText(r)), true);
|
|
99
|
+
|
|
100
|
+
r = await toolCall(client, 'somi_resolve', { agent: 'totally-not-a-real-agent', project_dir: fresh() });
|
|
101
|
+
check('65 (unknown agent) is isError', r.isError, true);
|
|
102
|
+
check('65 appears in the error text', /\(exit 65\)/.test(toolText(r)), true);
|
|
103
|
+
|
|
104
|
+
r = await toolCall(client, 'somi_resolve', { agent: 'somi', project_dir: fresh() });
|
|
105
|
+
check('66 (malformed: somi is exempt) is isError', r.isError, true);
|
|
106
|
+
check('66 appears in the error text', /\(exit 66\)/.test(toolText(r)), true);
|
|
107
|
+
check("66's message names the exemption, matching the CLI's own wording", /exempt/.test(toolText(r)), true);
|
|
108
|
+
|
|
109
|
+
const brokenProj = fresh();
|
|
110
|
+
mkdirSync(path.join(brokenProj, '.somi'), { recursive: true });
|
|
111
|
+
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 });
|
|
113
|
+
check('67 (project environment failure: unparsable config.json) is isError', r.isError, true);
|
|
114
|
+
check('67 appears in the error text', /\(exit 67\)/.test(toolText(r)), true);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// --- path traversal rejected before any read ----------------------------------------------
|
|
118
|
+
await withClient({}, async (client) => {
|
|
119
|
+
await client.initialize();
|
|
120
|
+
const proj = fresh();
|
|
121
|
+
const r = await toolCall(client, 'somi_resolve', { agent: '../etc/passwd', project_dir: proj });
|
|
122
|
+
check('path traversal in agent is rejected', r.isError, true);
|
|
123
|
+
check('a rejected agent leaves the project root untouched -- no .somi/ written', existsSync(path.join(proj, '.somi')), false);
|
|
124
|
+
|
|
125
|
+
const proj2 = fresh();
|
|
126
|
+
const r2 = await toolCall(client, 'somi_resolve', { agent: 'a/b', project_dir: proj2 });
|
|
127
|
+
check('a bare slash in agent is also rejected', r2.isError, true);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// --- somi_command: real text, and its own path-traversal rejection ------------------------
|
|
131
|
+
await withClient({}, async (client) => {
|
|
132
|
+
await client.initialize();
|
|
133
|
+
const r = await toolCall(client, 'somi_command', { name: 'plan' });
|
|
134
|
+
check('somi_command returns commands/plan.md content, not an error', r.isError, undefined);
|
|
135
|
+
check('the returned text is really commands/plan.md', toolText(r).includes('# /plan — Planning workflow'), true);
|
|
136
|
+
|
|
137
|
+
const bad1 = await toolCall(client, 'somi_command', { name: '../etc/passwd' });
|
|
138
|
+
check('somi_command rejects a path-traversal name', bad1.isError, true);
|
|
139
|
+
|
|
140
|
+
const unknown = await toolCall(client, 'somi_command', { name: 'not-a-real-command' });
|
|
141
|
+
check('somi_command rejects an unknown command name', unknown.isError, true);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// --- somi_skill: real text, and its own allowlist-before-path traversal rejection ---------
|
|
145
|
+
await withClient({}, async (client) => {
|
|
146
|
+
await client.initialize();
|
|
147
|
+
const r = await toolCall(client, 'somi_skill', { name: 'somi-dispatch' });
|
|
148
|
+
check('somi_skill returns skills/somi-dispatch/SKILL.md content, not an error', r.isError, undefined);
|
|
149
|
+
check('the returned text is really skills/somi-dispatch/SKILL.md', toolText(r).includes('somi-dispatch — resolve, then start, one agent'), true);
|
|
150
|
+
|
|
151
|
+
const bad1 = await toolCall(client, 'somi_skill', { name: '../x' });
|
|
152
|
+
check('somi_skill rejects a path-traversal name (../x) via the allowlist, before any read', bad1.isError, true);
|
|
153
|
+
check('the traversal rejection is the usual usage code (64), not a filesystem error', /\(exit 64\)/.test(toolText(bad1)), true);
|
|
154
|
+
|
|
155
|
+
const unknownSkill = await toolCall(client, 'somi_skill', { name: 'not-a-real-skill' });
|
|
156
|
+
check('somi_skill rejects an unknown skill name', unknownSkill.isError, true);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// --- unknown tool name -> JSON-RPC error, not a tool result -------------------------------
|
|
160
|
+
await withClient({}, async (client) => {
|
|
161
|
+
await client.initialize();
|
|
162
|
+
let errored = false;
|
|
163
|
+
try {
|
|
164
|
+
await toolCall(client, 'bogus_tool', {});
|
|
165
|
+
} catch {
|
|
166
|
+
errored = true;
|
|
167
|
+
}
|
|
168
|
+
check('an unknown tool name is a JSON-RPC error', errored, true);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// --- malformed JSON and an unknown method don't kill the server ---------------------------
|
|
172
|
+
await withClient({}, async (client) => {
|
|
173
|
+
await client.initialize();
|
|
174
|
+
client.writeRaw('this is not json');
|
|
175
|
+
const parseErr = await client.waitFor((m) => m.error?.code === -32700);
|
|
176
|
+
check('malformed JSON gets a JSON-RPC parse error', parseErr.error.code, -32700);
|
|
177
|
+
check('a parse error has id: null (nothing to correlate)', parseErr.id, null);
|
|
178
|
+
|
|
179
|
+
client.notify('bogus/notification', {});
|
|
180
|
+
client.writeRaw(JSON.stringify({ jsonrpc: '2.0', id: 999, method: 'bogus/method' }));
|
|
181
|
+
const methodErr = await client.waitFor((m) => m.id === 999);
|
|
182
|
+
check('an unknown METHOD gets a JSON-RPC method-not-found error', methodErr.error?.code, -32601);
|
|
183
|
+
|
|
184
|
+
// The server must still answer a perfectly good request after all of the above.
|
|
185
|
+
const list = await client.request('tools/list', {});
|
|
186
|
+
check('the server is still alive and answers a valid request afterward', Array.isArray(list.tools), true);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// --- project-root resolution (scripts/lib/mcp-project-root.mjs) ---------------------------
|
|
190
|
+
// No project_dir, no host root: project_dir alone decides.
|
|
191
|
+
await withClient({}, async (client) => {
|
|
192
|
+
await client.initialize();
|
|
193
|
+
const proj = fresh();
|
|
194
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'coder', project_dir: proj });
|
|
195
|
+
check('no host root: project_dir alone decides', r.isError, undefined);
|
|
196
|
+
check('ceiling state landed under the project_dir argument', existsSync(path.join(proj, '.somi', 'somi-state')), true);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// A HOST root (CLAUDE_PROJECT_DIR) is used directly when no project_dir is given.
|
|
200
|
+
{
|
|
201
|
+
const envProj = fresh();
|
|
202
|
+
await withClient({ CLAUDE_PROJECT_DIR: envProj }, async (client) => {
|
|
203
|
+
await client.initialize();
|
|
204
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
|
|
205
|
+
check('CLAUDE_PROJECT_DIR is used when no project_dir is given', r.isError, undefined);
|
|
206
|
+
check('ceiling state landed under CLAUDE_PROJECT_DIR', existsSync(path.join(envProj, '.somi', 'somi-state')), true);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// M3: a host root (CLAUDE_PROJECT_DIR) exists AND project_dir is OUTSIDE it -- refused (64),
|
|
211
|
+
// nothing read or written anywhere. This closes the prompt-injection path: model-supplied text
|
|
212
|
+
// choosing both which .somi/config.json is read and where state is written, unconstrained.
|
|
213
|
+
{
|
|
214
|
+
const hostProj = fresh();
|
|
215
|
+
const outsideProj = fresh();
|
|
216
|
+
await withClient({ CLAUDE_PROJECT_DIR: hostProj }, async (client) => {
|
|
217
|
+
await client.initialize();
|
|
218
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'coder', project_dir: outsideProj });
|
|
219
|
+
check('M3: project_dir outside the host root is refused', r.isError, true);
|
|
220
|
+
check('M3: the refusal is a usage error (64)', /\(exit 64\)/.test(toolText(r)), true);
|
|
221
|
+
check('M3: no .somi/ written under the host root', existsSync(path.join(hostProj, '.somi')), false);
|
|
222
|
+
check('M3: no .somi/ written under the rejected project_dir either', existsSync(path.join(outsideProj, '.somi')), false);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// M3: a host root exists AND project_dir is INSIDE it (a subdirectory) or EQUAL to it -- both
|
|
227
|
+
// allowed, and project_dir (the more specific path) is what's actually used.
|
|
228
|
+
{
|
|
229
|
+
const hostProj = fresh();
|
|
230
|
+
const insideProj = path.join(hostProj, 'packages', 'sub');
|
|
231
|
+
mkdirSync(insideProj, { recursive: true });
|
|
232
|
+
await withClient({ CLAUDE_PROJECT_DIR: hostProj }, async (client) => {
|
|
233
|
+
await client.initialize();
|
|
234
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'coder', project_dir: insideProj });
|
|
235
|
+
check('M3: project_dir inside the host root is allowed', r.isError, undefined);
|
|
236
|
+
check('M3: ceiling state landed under project_dir itself, not the host root', existsSync(path.join(insideProj, '.somi', 'somi-state')), true);
|
|
237
|
+
check('M3: the host root itself got no .somi/ written', existsSync(path.join(hostProj, '.somi')), false);
|
|
238
|
+
|
|
239
|
+
const r2 = await toolCall(client, 'somi_resolve', { agent: 'coder', project_dir: hostProj });
|
|
240
|
+
check('M3: project_dir equal to the host root is allowed', r2.isError, undefined);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// M1: a single MCP root (no CLAUDE_PROJECT_DIR) is used when the client declares `roots`.
|
|
245
|
+
await withClient({}, async (client) => {
|
|
246
|
+
await client.initialize({ roots: {} });
|
|
247
|
+
const rootsProj = fresh();
|
|
248
|
+
client.rootsHandler = () => [rootsProj];
|
|
249
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
|
|
250
|
+
check('M1: a single MCP root is used when the client declares the capability', r.isError, undefined);
|
|
251
|
+
check('M1: the server actually asked for roots/list', client.messages.some((m) => m.method === 'roots/list'), true);
|
|
252
|
+
check('M1: ceiling state landed under the root the client returned', existsSync(path.join(rootsProj, '.somi', 'somi-state')), true);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
// M1: a non-file:// root URI is dropped, never resolved as a path under the server's own cwd --
|
|
256
|
+
// with nothing else establishing a root, this must refuse (67), never guess.
|
|
257
|
+
await withClient({}, async (client) => {
|
|
258
|
+
await client.initialize({ roots: {} });
|
|
259
|
+
client.rootsHandler = () => [{ uri: 'not-a-file-uri' }];
|
|
260
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
|
|
261
|
+
check('M1: a non-file root URI is rejected outright (never resolved as a relative path)', r.isError, true);
|
|
262
|
+
check('M1: with only a non-file root offered, "no root" (67) is reported, not a guessed path', /\(exit 67\)/.test(toolText(r)), true);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
// M1: a percent-encoded file:// root URI is decoded with url.fileURLToPath, not hand-sliced --
|
|
266
|
+
// the scratchpad ships both a literal "a%20b" dir and a real "a b" (space) dir so this
|
|
267
|
+
// distinguishes correct decoding from a naive prefix-strip.
|
|
268
|
+
{
|
|
269
|
+
const rootDir = fresh();
|
|
270
|
+
const spaced = path.join(rootDir, 'a b');
|
|
271
|
+
const literalPercent = path.join(rootDir, 'a%20b');
|
|
272
|
+
mkdirSync(spaced, { recursive: true });
|
|
273
|
+
mkdirSync(literalPercent, { recursive: true });
|
|
274
|
+
await withClient({}, async (client) => {
|
|
275
|
+
await client.initialize({ roots: {} });
|
|
276
|
+
client.rootsHandler = () => [{ uri: `file://${encodeURI(spaced)}` }];
|
|
277
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
|
|
278
|
+
check('M1: a percent-encoded root URI resolves (isError undefined)', r.isError, undefined);
|
|
279
|
+
check('M1: it decodes to the REAL space directory, not the literal-percent one', existsSync(path.join(spaced, '.somi', 'somi-state')), true);
|
|
280
|
+
check('M1: the literal "a%20b" directory is untouched', existsSync(path.join(literalPercent, '.somi')), false);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// M1: more than one MCP root, no project_dir to select one -- ambiguous, refused, never guesses
|
|
285
|
+
// the first one. M1+M3: project_dir selecting exactly one of them is allowed.
|
|
286
|
+
await withClient({}, async (client) => {
|
|
287
|
+
await client.initialize({ roots: {} });
|
|
288
|
+
const rootA = fresh();
|
|
289
|
+
const rootB = fresh();
|
|
290
|
+
client.rootsHandler = () => [rootA, rootB];
|
|
291
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
|
|
292
|
+
check('M1: more than one root with no project_dir is ambiguous and refused', r.isError, true);
|
|
293
|
+
check('M1/M3: ambiguous roots refusal is the project-environment family (67)', /\(exit 67\)/.test(toolText(r)), true);
|
|
294
|
+
check('M1: neither offered root got a .somi/ written', existsSync(path.join(rootA, '.somi')) || existsSync(path.join(rootB, '.somi')), false);
|
|
295
|
+
|
|
296
|
+
const r2 = await toolCall(client, 'somi_resolve', { agent: 'coder', project_dir: rootB });
|
|
297
|
+
check('M1+M3: project_dir selecting one of several ambiguous roots is allowed', r2.isError, undefined);
|
|
298
|
+
check('M1+M3: state landed under the SELECTED root', existsSync(path.join(rootB, '.somi', 'somi-state')), true);
|
|
299
|
+
check('M1+M3: the other offered root got nothing written', existsSync(path.join(rootA, '.somi')), false);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
// M1: a root that doesn't exist is rejected, never created (cost-ceiling.mjs's saveState does a
|
|
303
|
+
// recursive mkdir -- this proves it's never reached for a bogus root).
|
|
304
|
+
await withClient({}, async (client) => {
|
|
305
|
+
await client.initialize({ roots: {} });
|
|
306
|
+
const missing = path.join(tmpRoot, `missing-${Math.random().toString(36).slice(2)}`);
|
|
307
|
+
client.rootsHandler = () => [missing];
|
|
308
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
|
|
309
|
+
check('M1: a nonexistent MCP root is rejected', r.isError, true);
|
|
310
|
+
check('M1: it is never silently created', existsSync(missing), false);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
// Nothing establishes a root -> a clear, distinct refusal (67), never a silent fallback. A
|
|
314
|
+
// malformed project_dir (relative, nonexistent) is a usage error (64) regardless.
|
|
315
|
+
await withClient({}, async (client) => {
|
|
316
|
+
await client.initialize(); // no `roots` capability declared
|
|
317
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
|
|
318
|
+
check('no root establishable is isError', r.isError, true);
|
|
319
|
+
check('the error names the reason and how to fix it', /project_dir/.test(toolText(r)), true);
|
|
320
|
+
check('the exit-67 family is used for "cannot establish a root"', /\(exit 67\)/.test(toolText(r)), true);
|
|
321
|
+
|
|
322
|
+
let r2 = await toolCall(client, 'somi_resolve', { agent: 'coder', project_dir: 'relative/path' });
|
|
323
|
+
check('a non-absolute project_dir is rejected (64)', /\(exit 64\)/.test(toolText(r2)), true);
|
|
324
|
+
r2 = await toolCall(client, 'somi_resolve', { agent: 'coder', project_dir: '/definitely/does/not/exist/anywhere' });
|
|
325
|
+
check('a nonexistent project_dir is rejected (64)', /\(exit 64\)/.test(toolText(r2)), true);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// --- m1: a present-but-wrong-shaped argument is 64, never silently defaulted -----------------
|
|
329
|
+
await withClient({}, async (client) => {
|
|
330
|
+
await client.initialize();
|
|
331
|
+
const proj = fresh();
|
|
332
|
+
let r = await toolCall(client, 'somi_resolve', { agent: 'coder', host: ['copilot'], project_dir: proj });
|
|
333
|
+
check('m1: an array-valued host is rejected (64), not silently defaulted', /\(exit 64\)/.test(toolText(r)), true);
|
|
334
|
+
check('m1: a rejected host leaves the project root untouched', existsSync(path.join(proj, '.somi')), false);
|
|
335
|
+
|
|
336
|
+
const proj2 = fresh();
|
|
337
|
+
r = await toolCall(client, 'somi_resolve', { agent: 'coder', ceiling: '', project_dir: proj2 });
|
|
338
|
+
check('m1: an empty-string ceiling is rejected (64), not silently defaulted', /\(exit 64\)/.test(toolText(r)), true);
|
|
339
|
+
check('m1: a rejected ceiling leaves the project root untouched', existsSync(path.join(proj2, '.somi')), false);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
// --- m2: an object-valued agent/name is a clean tool error, never a crashed JSON-RPC internal
|
|
343
|
+
// error (-32603) from throwing inside a template-literal interpolation ------------------------
|
|
344
|
+
await withClient({}, async (client) => {
|
|
345
|
+
await client.initialize();
|
|
346
|
+
const r = await toolCall(client, 'somi_resolve', { agent: { toString: null }, project_dir: fresh() });
|
|
347
|
+
check('m2: an object-valued agent (toString: null) is a clean isError, not a crash', r.isError, true);
|
|
348
|
+
check('m2: it is reported as the usual 64, not surfaced as an internal error', /\(exit 64\)/.test(toolText(r)), true);
|
|
349
|
+
|
|
350
|
+
const r2 = await toolCall(client, 'somi_command', { name: { toString: null } });
|
|
351
|
+
check('m2: an object-valued somi_command name is a clean isError, not a crash', r2.isError, true);
|
|
352
|
+
check('m2: it is reported as the usual 64, not surfaced as an internal error', /\(exit 64\)/.test(toolText(r2)), true);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
// --- M2: the SAME bad input produces the SAME code through the CLI and the MCP tool ----------
|
|
356
|
+
{
|
|
357
|
+
const badInputs = [
|
|
358
|
+
{ name: 'invalid agent name', args: { agent: 'Not-Valid' } },
|
|
359
|
+
{ name: 'unrecognized ceiling', args: { agent: 'coder', ceiling: 'ultra' } },
|
|
360
|
+
{ name: 'somi is exempt from cost:', args: { agent: 'somi' } },
|
|
361
|
+
{ name: 'unknown agent', args: { agent: 'totally-not-a-real-agent' } },
|
|
362
|
+
];
|
|
363
|
+
for (const { name, args } of badInputs) {
|
|
364
|
+
const proj = fresh();
|
|
365
|
+
const cliArgs = [CLI, 'resolve', '--agent', args.agent];
|
|
366
|
+
if (args.ceiling) cliArgs.push('--ceiling', args.ceiling);
|
|
367
|
+
let cliCode = 0;
|
|
368
|
+
try {
|
|
369
|
+
execFileSync(process.execPath, cliArgs, { env: { ...process.env, CLAUDE_PROJECT_DIR: proj }, stdio: 'pipe' });
|
|
370
|
+
} catch (e) {
|
|
371
|
+
cliCode = e.status;
|
|
372
|
+
}
|
|
373
|
+
await withClient({}, async (client) => {
|
|
374
|
+
await client.initialize();
|
|
375
|
+
const r = await toolCall(client, 'somi_resolve', { ...args, project_dir: fresh() });
|
|
376
|
+
const mcpMatch = /\(exit (\d+)\)/.exec(toolText(r));
|
|
377
|
+
const mcpCode = mcpMatch ? Number(mcpMatch[1]) : 0;
|
|
378
|
+
check(`M2 parity (${name}): CLI exit ${cliCode} === MCP code ${mcpCode}`, mcpCode, cliCode);
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// --- m5: initialize answers with a version it actually supports, never an echo -----------------
|
|
384
|
+
await withClient({}, async (client) => {
|
|
385
|
+
const init = await client.request('initialize', { protocolVersion: '1999-01-01', capabilities: {} });
|
|
386
|
+
check('m5: an unsupported protocolVersion is NOT echoed back', init.protocolVersion, '2025-06-18');
|
|
387
|
+
client.notify('notifications/initialized');
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
run()
|
|
392
|
+
.then(() => {
|
|
393
|
+
console.log(`somi-mcp tests: ${pass} ok, ${fail} failed`);
|
|
394
|
+
rmSync(tmpRoot, { recursive: true, force: true });
|
|
395
|
+
process.exit(fail === 0 ? 0 : 1);
|
|
396
|
+
})
|
|
397
|
+
.catch((e) => {
|
|
398
|
+
console.error('somi-mcp-tests.mjs crashed:', e.stack || e);
|
|
399
|
+
rmSync(tmpRoot, { recursive: true, force: true });
|
|
400
|
+
process.exit(1);
|
|
401
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Drives scripts/somi-mcp.mjs's REAL `tools/list` (over real stdio JSON-RPC, via the same
|
|
3
|
+
// McpClient tests/scripts/lib/somi-mcp-tests.mjs uses) and prints each tool's name -> {required,
|
|
4
|
+
// properties} as one JSON object on stdout.
|
|
5
|
+
//
|
|
6
|
+
// tests/scripts/somi-agent-dispatch-contract.sh reads this to check agents/somi.md's Step 4/5
|
|
7
|
+
// against the server's actual advertised schema, instead of a hand-typed copy of the tool/argument
|
|
8
|
+
// names that could quietly drift from what the server really exposes.
|
|
9
|
+
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
import { McpClient } from './somi-mcp-client.mjs';
|
|
13
|
+
|
|
14
|
+
const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
|
|
15
|
+
const SERVER = path.join(ROOT, 'scripts', 'somi-mcp.mjs');
|
|
16
|
+
|
|
17
|
+
async function main() {
|
|
18
|
+
const client = new McpClient(SERVER, {});
|
|
19
|
+
try {
|
|
20
|
+
await client.initialize();
|
|
21
|
+
const { tools } = await client.request('tools/list', {});
|
|
22
|
+
const shape = {};
|
|
23
|
+
for (const t of tools || []) {
|
|
24
|
+
shape[t.name] = {
|
|
25
|
+
required: [...(t.inputSchema?.required || [])].sort(),
|
|
26
|
+
properties: Object.keys(t.inputSchema?.properties || {}).sort(),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
process.stdout.write(JSON.stringify(shape));
|
|
30
|
+
} finally {
|
|
31
|
+
client.close();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
main().catch((e) => {
|
|
36
|
+
console.error(`somi-mcp-tool-schema: ${e.stack || e}`);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
});
|