@skathio/somi 3.1.1 → 4.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/settings.json +13 -0
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/.copilot-extension/extension.json +1 -1
- package/.copilot-extension/marketplace.json +2 -2
- package/README.md +34 -24
- package/VERSION +1 -1
- package/agents/{architecture-reviewer.md → somi-architecture-reviewer.md} +10 -11
- package/agents/{atlas.md → somi-atlas.md} +3 -5
- package/agents/{coder.md → somi-coder.md} +26 -23
- package/agents/{designer.md → somi-designer.md} +9 -11
- package/agents/{discovery-analyst.md → somi-discovery-analyst.md} +7 -9
- package/agents/{impact.md → somi-impact.md} +6 -8
- package/agents/{incident.md → somi-incident.md} +2 -4
- package/agents/{plan-reviewer.md → somi-plan-reviewer.md} +9 -11
- package/agents/{planner.md → somi-planner.md} +16 -24
- package/agents/{pr.md → somi-pr.md} +2 -4
- package/agents/{refactor-designer.md → somi-refactor-designer.md} +14 -15
- package/agents/{refactorer.md → somi-refactorer.md} +11 -12
- package/agents/{reviewer.md → somi-reviewer.md} +8 -7
- package/agents/{sdlc-reviewer.md → somi-sdlc-reviewer.md} +8 -10
- package/agents/{security-reviewer.md → somi-security-reviewer.md} +8 -8
- package/agents/{test-strategist.md → somi-test-strategist.md} +4 -6
- package/agents/somi.md +25 -12
- package/commands/adopt.md +9 -10
- package/commands/architecture-review.md +4 -5
- package/commands/atlas.md +3 -3
- package/commands/code-loop.md +38 -14
- package/commands/code-parallel.md +4 -4
- package/commands/code.md +24 -15
- package/commands/debug.md +8 -9
- package/commands/design.md +14 -15
- package/commands/discover.md +11 -12
- package/commands/impact.md +2 -2
- package/commands/incident.md +3 -4
- package/commands/plan-loop.md +16 -12
- package/commands/plan.md +15 -16
- package/commands/pr.md +2 -2
- package/commands/refactor-design.md +10 -11
- package/commands/refactor.md +7 -8
- package/commands/release-readiness.md +6 -7
- package/commands/review-panel.md +24 -23
- package/commands/review.md +14 -14
- package/commands/security-review.md +8 -7
- package/commands/ship-loop.md +107 -28
- package/commands/ship.md +6 -6
- package/commands/somi-config.md +138 -0
- package/commands/test-strategy.md +3 -4
- package/commands/upgrade.md +4 -5
- package/examples/code-review-example.md +1 -1
- package/examples/discovery-example.md +1 -1
- package/examples/feature-plan-example.md +2 -2
- package/hooks/hooks.json +14 -1
- package/hooks/lib/common.mjs +71 -9
- package/hooks/post-tool/audit-log.mjs +3 -2
- package/hooks/pre-tool/block-secret-writes.mjs +12 -11
- package/hooks/pre-tool/guard-cost-lowering.mjs +192 -0
- package/hooks/pre-tool/guard-protected-paths.mjs +13 -3
- package/hooks/session-start/detect-repo-instructions.mjs +27 -2
- package/hooks/session-start/ensure-default-config.mjs +113 -0
- package/package.json +1 -1
- package/rules/00-priorities.md +1 -1
- package/rules/30-security-owasp.md +1 -1
- package/rules/50-collaboration.md +9 -6
- package/rules/CLAUDE.md +11 -10
- package/scripts/lib/agent-info.mjs +85 -0
- package/scripts/lib/agent-registry.mjs +92 -0
- package/scripts/lib/config-files.mjs +145 -0
- package/scripts/lib/cost-ceiling.mjs +190 -179
- package/scripts/lib/cost-config-edit.mjs +102 -0
- package/scripts/lib/cost-config.mjs +64 -0
- package/scripts/lib/cost-defaults.mjs +51 -0
- package/scripts/lib/cost-lowering.mjs +89 -0
- package/scripts/lib/cost-model.mjs +37 -22
- package/scripts/lib/dispatch-resolver.mjs +59 -50
- package/scripts/lib/loop-diff.mjs +96 -0
- package/scripts/lib/loop-dispatch.mjs +19 -0
- package/scripts/lib/loop-review.mjs +52 -0
- package/scripts/lib/run-budget.mjs +28 -0
- package/scripts/lib/size-tier.mjs +184 -0
- package/scripts/lib/tier-record.mjs +82 -0
- package/scripts/size-budget-overrides.json +7 -15
- package/scripts/somi-check.mjs +4 -3
- package/scripts/somi-config.mjs +421 -0
- package/scripts/somi-dispatch.mjs +1 -1
- package/scripts/somi-loop.mjs +75 -99
- package/scripts/somi-mcp.mjs +135 -14
- package/scripts/somi-tier.mjs +393 -0
- package/scripts/validate.sh +57 -215
- package/skills/api-design/SKILL.md +1 -1
- package/skills/clean-code/SKILL.md +1 -1
- package/skills/market-research/SKILL.md +2 -2
- package/skills/owasp-defense/SKILL.md +2 -2
- package/skills/plan-review/SKILL.md +5 -1
- package/skills/reasoning-craft/SKILL.md +1 -1
- package/skills/requirements-engineering/SKILL.md +3 -3
- package/skills/solid-principles/SKILL.md +1 -1
- package/skills/somi-dispatch/SKILL.md +104 -109
- package/skills/somi-routing/SKILL.md +88 -1
- package/skills/testing-playbook/SKILL.md +2 -2
- package/skills/threat-modeling/SKILL.md +3 -3
- package/templates/BRIEF.md.tmpl +2 -2
- package/templates/DESIGN.md.tmpl +1 -1
- package/templates/DOD.md.tmpl +2 -2
- package/templates/PHASE.md.tmpl +2 -2
- package/templates/RCA.md.tmpl +1 -1
- package/templates/REVIEW.md.tmpl +3 -2
- package/templates/SDD.md.tmpl +1 -1
- package/templates/SPEC.md.tmpl +1 -1
- package/templates/TDD.md.tmpl +1 -1
- package/tests/hooks/cases/block-secret-writes.json +130 -17
- package/tests/hooks/cases/detect-repo-instructions.json +22 -1
- package/tests/hooks/cases/guard-protected-paths.json +175 -25
- package/tests/scripts/agent-model-frontmatter.sh +38 -0
- package/tests/scripts/agent-names.sh +77 -0
- package/tests/scripts/check-frontmatter.sh +1 -1
- package/tests/scripts/checkpoint-gate.sh +44 -3
- package/tests/scripts/convergence-runner.sh +10 -6
- package/tests/scripts/cost-ceiling.sh +127 -215
- package/tests/scripts/cost-defaults.sh +128 -0
- package/tests/scripts/cost-hardcap.sh +338 -0
- package/tests/scripts/cost-lowering.sh +261 -0
- package/tests/scripts/cost-model.sh +18 -14
- package/tests/scripts/dispatch-guard.sh +7 -7
- package/tests/scripts/dispatch-line-gate.sh +61 -0
- package/tests/scripts/dispatch-reference-gate.sh +13 -13
- package/tests/scripts/ensure-default-config.sh +162 -0
- package/tests/scripts/eval-runner.sh +9 -9
- package/tests/scripts/evals-packaging.sh +127 -20
- package/tests/scripts/fixtures/size-tier-cases.json +87 -0
- package/tests/scripts/global-config.sh +167 -0
- package/tests/scripts/goldens/loop-state-done.json +1 -1
- package/tests/scripts/goldens/somi-loop.json +3 -3
- package/tests/scripts/lib/agent-registry-tests.mjs +95 -0
- package/tests/scripts/lib/brief-only-guard.mjs +27 -0
- package/tests/scripts/lib/checkpoint-gate.mjs +40 -3
- package/tests/scripts/lib/dispatch-reference-gate.mjs +5 -5
- package/tests/scripts/lib/retirement-gate.mjs +7 -2
- package/tests/scripts/lib/ship-loop-sizing-guard.mjs +52 -0
- package/tests/scripts/lib/site-roadmap-gate.mjs +64 -0
- package/tests/scripts/lib/size-tier-drift.mjs +74 -0
- package/tests/scripts/lib/somi-mcp-config-tests.mjs +92 -0
- package/tests/scripts/lib/somi-mcp-tests.mjs +66 -28
- package/tests/scripts/lib/somi-mcp-tier-tests.mjs +64 -0
- package/tests/scripts/retirement-gate.sh +19 -0
- package/tests/scripts/review-panel-seats.sh +2 -2
- package/tests/scripts/run.sh +95 -0
- package/tests/scripts/site-roadmap-gate.sh +76 -0
- package/tests/scripts/size-tier.sh +562 -0
- package/tests/scripts/somi-agent-dispatch-contract.sh +20 -11
- package/tests/scripts/somi-config.sh +286 -0
- package/tests/scripts/somi-dispatch.sh +150 -98
- package/tests/scripts/somi-mcp.sh +2 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// size-tier-drift.mjs <skill.md> <size-tier.mjs> — the routing skill's "Size tiers" section and
|
|
2
|
+
// the size-tier module must agree. Prints "ok ..." (exit 0) or one problem per line (exit 1):
|
|
3
|
+
// 1. the signal ids in the section's checklist equal SIGNAL_IDS, in order (T1-T5 stands for T1..T5);
|
|
4
|
+
// 2. every exported threshold constant appears in the section next to its name with its value;
|
|
5
|
+
// 3. the section holds no copy of the trivial threshold's five signal sentences (it points at them).
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
7
|
+
import { pathToFileURL } from 'node:url';
|
|
8
|
+
|
|
9
|
+
const [skillPath, modPath] = process.argv.slice(2);
|
|
10
|
+
const mod = await import(pathToFileURL(modPath).href);
|
|
11
|
+
const skill = readFileSync(skillPath, 'utf8');
|
|
12
|
+
const problems = [];
|
|
13
|
+
|
|
14
|
+
const sectionOf = (text, heading) => {
|
|
15
|
+
const lines = text.split('\n');
|
|
16
|
+
const start = lines.findIndex((l) => l === heading);
|
|
17
|
+
if (start < 0) return null;
|
|
18
|
+
const end = lines.findIndex((l, i) => i > start && /^## /.test(l));
|
|
19
|
+
return lines.slice(start + 1, end < 0 ? undefined : end).join('\n');
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const section = sectionOf(skill, '## Size tiers');
|
|
23
|
+
const threshold = sectionOf(skill, '## The trivial threshold');
|
|
24
|
+
if (section === null || threshold === null) {
|
|
25
|
+
console.log('the skill needs both a "## Size tiers" and a "## The trivial threshold" section');
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 1. ids: first code span of each row of the checklist table (the one whose header cell is "Id").
|
|
30
|
+
const checklist = section.split('\n').slice(section.split('\n').findIndex((l) => /^\| Id \|/.test(l)) + 2);
|
|
31
|
+
const ids = [];
|
|
32
|
+
for (const line of checklist) {
|
|
33
|
+
const m = /^\| `([^`]+)` \|/.exec(line);
|
|
34
|
+
if (!m) break;
|
|
35
|
+
ids.push(...(m[1] === 'T1-T5' ? ['T1', 'T2', 'T3', 'T4', 'T5'] : [m[1]]));
|
|
36
|
+
}
|
|
37
|
+
if (ids.join() !== mod.SIGNAL_IDS.join()) {
|
|
38
|
+
problems.push(`signal ids differ: skill [${ids.join(', ')}] vs module [${mod.SIGNAL_IDS.join(', ')}]`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 2. thresholds: the exported numeric constants, each in a table row `NAME` | value |.
|
|
42
|
+
const constants = Object.entries(mod).filter(([name, v]) => /^[A-Z_]+$/.test(name) && Number.isInteger(v));
|
|
43
|
+
for (const [name, value] of constants) {
|
|
44
|
+
const m = new RegExp(`\\| \`${name}\` \\| (\\d+) \\|`).exec(section);
|
|
45
|
+
if (!m) problems.push(`threshold ${name} is not in the Size tiers table`);
|
|
46
|
+
else if (Number(m[1]) !== value) problems.push(`threshold ${name} is ${m[1]} in the skill but ${value} in the module`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 3. no copied signal text: neither a signal's label nor any five consecutive words of its sentence.
|
|
50
|
+
const words = (t) => t.toLowerCase().replace(/[`*_]/g, '').split(/[^a-z0-9-]+/).filter(Boolean);
|
|
51
|
+
const sectionWords = ` ${words(section).join(' ')} `;
|
|
52
|
+
const numbered = threshold.split('\n').filter((l) => /^\d+\. \*\*/.test(l));
|
|
53
|
+
for (const line of numbered) {
|
|
54
|
+
const label = /\*\*([^*]+)\*\*/.exec(line)[1];
|
|
55
|
+
if (sectionWords.includes(` ${words(label).join(' ')} `)) problems.push(`the section repeats the signal label "${label}"`);
|
|
56
|
+
}
|
|
57
|
+
// A sentence can wrap onto an indented continuation line, so windows run over the item's own text.
|
|
58
|
+
const itemTexts = threshold.split(/\n(?=\d+\. )/).filter((t) => /^\d+\. /.test(t)).map((t) => t.split(/\n\n/)[0]);
|
|
59
|
+
for (const text of itemTexts) {
|
|
60
|
+
const w = words(text.replace(/^\d+\. \*\*[^*]+\*\*/, ''));
|
|
61
|
+
for (let i = 0; i + 5 <= w.length; i++) {
|
|
62
|
+
if (sectionWords.includes(` ${w.slice(i, i + 5).join(' ')} `)) {
|
|
63
|
+
problems.push(`the section copies trivial-threshold text: "${w.slice(i, i + 5).join(' ')}"`);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (numbered.length !== 5) problems.push(`the trivial threshold lists ${numbered.length} numbered signals, expected 5`);
|
|
69
|
+
|
|
70
|
+
if (problems.length) {
|
|
71
|
+
console.log(problems.join('\n'));
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
console.log(`ok ${ids.length} ids, ${constants.length} thresholds, no copied threshold text`);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Drives scripts/somi-mcp.mjs over real stdio JSON-RPC for the somi_config tool: parity with the config
|
|
3
|
+
// CLI for every action, the host-root requirement for writes, argument rejection, and a broken config.
|
|
4
|
+
// Invoked from tests/scripts/somi-config.sh. CLAUDE_PROJECT_DIR is always set explicitly, so a run inside
|
|
5
|
+
// a Claude Code shell cannot change what a case means.
|
|
6
|
+
|
|
7
|
+
import { execFileSync } from 'node:child_process';
|
|
8
|
+
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, realpathSync, symlinkSync } from 'node:fs';
|
|
9
|
+
import { tmpdir } from 'node:os';
|
|
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
|
+
const CFG_CLI = path.join(ROOT, 'scripts', 'somi-config.mjs');
|
|
17
|
+
let pass = 0; let fail = 0;
|
|
18
|
+
const check = (name, got, want) => {
|
|
19
|
+
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)})`); }
|
|
20
|
+
};
|
|
21
|
+
const tmpRoot = mkdtempSync(path.join(tmpdir(), 'somi-mcp-config-'));
|
|
22
|
+
const fresh = () => { const d = path.join(tmpRoot, `p${Math.random().toString(36).slice(2)}`); mkdirSync(d, { recursive: true }); return d; };
|
|
23
|
+
const projWith = (body) => { const d = fresh(); mkdirSync(path.join(d, '.somi')); writeFileSync(path.join(d, '.somi', 'config.json'), body); return d; };
|
|
24
|
+
async function withClient(root, fn, extraEnv = {}) {
|
|
25
|
+
const client = new McpClient(SERVER, { env: { CLAUDE_PROJECT_DIR: root, ...extraEnv } });
|
|
26
|
+
try { await client.initialize(); return await fn(client); } finally { client.close(); }
|
|
27
|
+
}
|
|
28
|
+
const call = (client, args) => client.request('tools/call', { name: 'somi_config', arguments: args });
|
|
29
|
+
const text = (r) => r?.content?.[0]?.text ?? '';
|
|
30
|
+
const exits = (r, code) => [r.isError, text(r).endsWith(`(exit ${code})`)];
|
|
31
|
+
|
|
32
|
+
console.log('== somi_config over MCP ==');
|
|
33
|
+
|
|
34
|
+
const viaMcp = fresh(); const viaCli = fresh();
|
|
35
|
+
await withClient(viaMcp, async (client) => {
|
|
36
|
+
const steps = [['init'], ['show'], ['get', 'cost.ceiling'], ['set', 'cost.ceiling', 'low'], ['set', 'cost.agents.somi-designer', 'medium'], ['get', 'cost.agents.somi-designer'], ['unset', 'cost.agents.somi-designer'], ['show'], ['set', 'cost.bogus', 'low'], ['set', 'cost.ceiling', 'turbo']];
|
|
37
|
+
for (const [action, ...kv] of steps) {
|
|
38
|
+
let want; let code = 0;
|
|
39
|
+
try { want = execFileSync(process.execPath, [CFG_CLI, action, ...kv, '--project-dir', viaCli], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, SOMI_COST_CEILING: '' } }).trimEnd(); } catch (e) { code = e.status; }
|
|
40
|
+
const r = await call(client, { action, key: kv[0], value: kv[1], project_dir: viaMcp });
|
|
41
|
+
check(`${[action, ...kv].join(' ')}: ${code === 0 ? 'same JSON as the CLI' : `error with exit ${code}`}`, code === 0 ? [r.isError, text(r)] : exits(r, code), code === 0 ? [undefined, want] : [true, true]);
|
|
42
|
+
}
|
|
43
|
+
check('both projects hold the same bytes after the same steps', readFileSync(path.join(viaMcp, '.somi', 'config.json'), 'utf8'), readFileSync(path.join(viaCli, '.somi', 'config.json'), 'utf8'));
|
|
44
|
+
for (const args of [{ action: 'drop' }, { action: 'get', key: '--project-dir' }, { action: 'set', key: 'cost.ceiling', value: 5 }, { action: 'get', key: 'cost.ceiling\u0000x' }, { action: 'set', key: 'cost.ceiling', value: 'low\nx' }]) {
|
|
45
|
+
check(`rejects ${JSON.stringify(args)} with 64`, exits(await call(client, { ...args, project_dir: viaMcp }), 64), [true, true]);
|
|
46
|
+
}
|
|
47
|
+
}, { CLAUDE_PLUGIN_ROOT: ROOT });
|
|
48
|
+
const bad = projWith('{ not json');
|
|
49
|
+
await withClient(bad, async (client) => {
|
|
50
|
+
const r = await call(client, { action: 'set', key: 'cost.ceiling', value: 'low', project_dir: bad });
|
|
51
|
+
check('an unparsable config: exit 67, file untouched', [...exits(r, 67), readFileSync(path.join(bad, '.somi', 'config.json'), 'utf8')], [true, true, '{ not json']);
|
|
52
|
+
});
|
|
53
|
+
// No host root: reads work from project_dir, writes are refused and nothing is created.
|
|
54
|
+
const lone = fresh();
|
|
55
|
+
await withClient('', async (client) => {
|
|
56
|
+
for (const args of [{ action: 'set', key: 'cost.ceiling', value: 'low' }, { action: 'unset', key: 'cost.agents.somi-coder' }, { action: 'init' }]) {
|
|
57
|
+
const r = await call(client, { ...args, project_dir: lone });
|
|
58
|
+
check(`without a host root ${args.action} is refused (67)`, [...exits(r, 67), /no host project root/.test(text(r)), existsSync(path.join(lone, '.somi'))], [true, true, true, false]);
|
|
59
|
+
}
|
|
60
|
+
const r = await call(client, { action: 'show', project_dir: lone });
|
|
61
|
+
check('without a host root show still works from project_dir', [r.isError, JSON.parse(text(r)).exists], [undefined, false]);
|
|
62
|
+
const hp = fresh(); mkdirSync(path.join(hp, '.somi')); writeFileSync(path.join(hp, '.somi', 'config.json'), '{"cost":{"ceiling":"high"}}\n');
|
|
63
|
+
const h = await call(client, { action: 'show', project_dir: hp, host: 'copilot' });
|
|
64
|
+
check('show with host copilot passes --host through: the unmapped warning appears', [h.isError, JSON.parse(text(h)).warnings.some((w) => w.startsWith('copilot has no model mapping'))], [undefined, true]);
|
|
65
|
+
const hs = await call(client, { action: 'set', key: 'cost.ceiling', value: 'high', project_dir: lone, host: 'copilot' });
|
|
66
|
+
check('host on a non-show action is refused (64) before anything runs', exits(hs, 64), [true, true]);
|
|
67
|
+
});
|
|
68
|
+
// With a host root the CLI receives the real path of the root.
|
|
69
|
+
const hostReal = fresh(); const alias = path.join(fresh(), 'alias'); symlinkSync(hostReal, alias);
|
|
70
|
+
await withClient(alias, async (client) => {
|
|
71
|
+
const r = await call(client, { action: 'init', project_dir: alias });
|
|
72
|
+
check('a host root reached through a symlink is passed to the CLI by real path and works', [r.isError, existsSync(path.join(realpathSync(hostReal), '.somi', 'config.json'))], [undefined, true]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Lowering needs the user. With no CLAUDE_PLUGIN_ROOT (a heuristic for "no hook can ask") the tool refuses
|
|
76
|
+
// a lowering; with it set the hook asks instead, so the tool does not refuse.
|
|
77
|
+
for (const [label, env, lowersOk] of [['without CLAUDE_PLUGIN_ROOT', { CLAUDE_PLUGIN_ROOT: '' }, false], ['with CLAUDE_PLUGIN_ROOT set', { CLAUDE_PLUGIN_ROOT: ROOT, COPILOT_PLUGIN_ROOT: '' }, true], ['under Copilot CLI (COPILOT_PLUGIN_ROOT set too: its tool name escapes the hook matcher)', { CLAUDE_PLUGIN_ROOT: ROOT, COPILOT_PLUGIN_ROOT: ROOT }, false]]) {
|
|
78
|
+
const p = fresh();
|
|
79
|
+
await withClient(p, async (client) => {
|
|
80
|
+
await call(client, { action: 'init', project_dir: p });
|
|
81
|
+
const lower = await call(client, { action: 'set', key: 'cost.agents.somi-coder', value: 'low', project_dir: p });
|
|
82
|
+
const onDisk = JSON.parse(readFileSync(path.join(p, '.somi', 'config.json'), 'utf8')).cost.agents;
|
|
83
|
+
const raise = await call(client, { action: 'set', key: 'cost.agents.somi-coder', value: 'high', project_dir: p });
|
|
84
|
+
const unsetPin = await call(client, { action: 'unset', key: 'cost.agents.somi-designer', project_dir: p });
|
|
85
|
+
check(`${label}: a lowering set ${lowersOk ? 'goes through (the hook asks)' : 'is refused with 64 and the fixed message'}`, lowersOk ? [lower.isError, onDisk['somi-coder']] : [...exits(lower, 64), /this change lowers a tier and needs the user/.test(text(lower))], lowersOk ? [undefined, 'low'] : [true, true, true]);
|
|
86
|
+
check(`${label}: a raise is not refused`, raise.isError, undefined);
|
|
87
|
+
check(`${label}: an unset of a pin at the ceiling or above ${lowersOk ? 'goes through' : 'is judged by the same rule'}`, lowersOk ? unsetPin.isError : [unsetPin.isError, /lowers a tier/.test(text(unsetPin))], lowersOk ? undefined : [true, true]);
|
|
88
|
+
}, env);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
console.log(`somi_config MCP tests: ${pass} ok, ${fail} failed`);
|
|
92
|
+
process.exit(fail === 0 ? 0 : 1);
|
|
@@ -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
|
|
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,20 +96,33 @@ 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
|
+
|
|
92
112
|
// --- #32: enforced/reason are exposed, and a config mapping makes copilot enforced ----------
|
|
93
113
|
await withClient({}, async (client) => {
|
|
94
114
|
await client.initialize();
|
|
95
|
-
const bare = JSON.parse(toolText(await toolCall(client, 'somi_resolve', { agent: 'designer', host: 'copilot', project_dir: fresh() })));
|
|
115
|
+
const bare = JSON.parse(toolText(await toolCall(client, 'somi_resolve', { agent: 'somi-designer', host: 'copilot', ceiling: 'high', project_dir: fresh() })));
|
|
96
116
|
check('copilot, no mapping: model null, enforced false, reason names host',
|
|
97
117
|
[bare.model, bare.enforced, /no model mapping for host copilot.*low, medium and high/.test(bare.reason ?? '')], [null, false, true]);
|
|
98
118
|
const mapped = fresh();
|
|
99
119
|
mkdirSync(path.join(mapped, '.somi'), { recursive: true });
|
|
100
120
|
writeFileSync(path.join(mapped, '.somi', 'config.json'),
|
|
101
121
|
JSON.stringify({ cost: { mapping: { copilot: { low: 'gpt-5-mini', medium: 'gpt-5', high: 'gpt-5-pro' } } } }));
|
|
102
|
-
const m = JSON.parse(toolText(await toolCall(client, 'somi_resolve', { agent: 'designer', host: 'copilot', project_dir: mapped })));
|
|
122
|
+
const m = JSON.parse(toolText(await toolCall(client, 'somi_resolve', { agent: 'somi-designer', host: 'copilot', ceiling: 'high', project_dir: mapped })));
|
|
103
123
|
check('copilot with config mapping: model set, enforced true, no reason',
|
|
104
124
|
[m.model, m.enforced, 'reason' in m], ['gpt-5-pro', true, false]);
|
|
105
|
-
const cc = JSON.parse(toolText(await toolCall(client, 'somi_resolve', { agent: 'designer', host: 'claude-code', project_dir: fresh() })));
|
|
125
|
+
const cc = JSON.parse(toolText(await toolCall(client, 'somi_resolve', { agent: 'somi-designer', host: 'claude-code', project_dir: fresh() })));
|
|
106
126
|
check('claude-code default: model set, enforced true', [typeof cc.model, cc.enforced], ['string', true]);
|
|
107
127
|
});
|
|
108
128
|
|
|
@@ -126,11 +146,29 @@ async function run() {
|
|
|
126
146
|
const brokenProj = fresh();
|
|
127
147
|
mkdirSync(path.join(brokenProj, '.somi'), { recursive: true });
|
|
128
148
|
writeFileSync(path.join(brokenProj, '.somi', 'config.json'), '{"cost": {"ceiling": "low"}\n'); // missing brace
|
|
129
|
-
r = await toolCall(client, 'somi_resolve', { agent: 'coder', project_dir: brokenProj });
|
|
149
|
+
r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', project_dir: brokenProj });
|
|
130
150
|
check('67 (project environment failure: unparsable config.json) is isError', r.isError, true);
|
|
131
151
|
check('67 appears in the error text', /\(exit 67\)/.test(toolText(r)), true);
|
|
132
152
|
});
|
|
133
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
|
+
|
|
134
172
|
// --- path traversal rejected before any read ----------------------------------------------
|
|
135
173
|
await withClient({}, async (client) => {
|
|
136
174
|
await client.initialize();
|
|
@@ -176,8 +214,8 @@ async function run() {
|
|
|
176
214
|
// --- somi_agent: the agent's instructions without frontmatter, same allowlist ------------
|
|
177
215
|
await withClient({}, async (client) => {
|
|
178
216
|
await client.initialize();
|
|
179
|
-
const r = await toolCall(client, 'somi_agent', { name: 'reviewer' });
|
|
180
|
-
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);
|
|
181
219
|
check('the returned text starts at the body: no frontmatter, no model: line', /^---|^model:/m.test(toolText(r)), false);
|
|
182
220
|
check('the returned text is really the reviewer body', toolText(r).length > 1000 && /reviewer/i.test(toolText(r)), true);
|
|
183
221
|
|
|
@@ -223,7 +261,7 @@ async function run() {
|
|
|
223
261
|
await withClient({}, async (client) => {
|
|
224
262
|
await client.initialize();
|
|
225
263
|
const proj = fresh();
|
|
226
|
-
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 });
|
|
227
265
|
check('no host root: project_dir alone decides', r.isError, undefined);
|
|
228
266
|
check('ceiling state landed under the project_dir argument', existsSync(path.join(proj, '.somi', 'somi-state')), true);
|
|
229
267
|
});
|
|
@@ -233,7 +271,7 @@ async function run() {
|
|
|
233
271
|
const envProj = fresh();
|
|
234
272
|
await withClient({ CLAUDE_PROJECT_DIR: envProj }, async (client) => {
|
|
235
273
|
await client.initialize();
|
|
236
|
-
const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
|
|
274
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low' });
|
|
237
275
|
check('CLAUDE_PROJECT_DIR is used when no project_dir is given', r.isError, undefined);
|
|
238
276
|
check('ceiling state landed under CLAUDE_PROJECT_DIR', existsSync(path.join(envProj, '.somi', 'somi-state')), true);
|
|
239
277
|
});
|
|
@@ -247,7 +285,7 @@ async function run() {
|
|
|
247
285
|
const outsideProj = fresh();
|
|
248
286
|
await withClient({ CLAUDE_PROJECT_DIR: hostProj }, async (client) => {
|
|
249
287
|
await client.initialize();
|
|
250
|
-
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 });
|
|
251
289
|
check('M3: project_dir outside the host root is refused', r.isError, true);
|
|
252
290
|
check('M3: the refusal is a usage error (64)', /\(exit 64\)/.test(toolText(r)), true);
|
|
253
291
|
check('M3: no .somi/ written under the host root', existsSync(path.join(hostProj, '.somi')), false);
|
|
@@ -263,12 +301,12 @@ async function run() {
|
|
|
263
301
|
mkdirSync(insideProj, { recursive: true });
|
|
264
302
|
await withClient({ CLAUDE_PROJECT_DIR: hostProj }, async (client) => {
|
|
265
303
|
await client.initialize();
|
|
266
|
-
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 });
|
|
267
305
|
check('M3: project_dir inside the host root is allowed', r.isError, undefined);
|
|
268
306
|
check('M3: ceiling state landed under project_dir itself, not the host root', existsSync(path.join(insideProj, '.somi', 'somi-state')), true);
|
|
269
307
|
check('M3: the host root itself got no .somi/ written', existsSync(path.join(hostProj, '.somi')), false);
|
|
270
308
|
|
|
271
|
-
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 });
|
|
272
310
|
check('M3: project_dir equal to the host root is allowed', r2.isError, undefined);
|
|
273
311
|
});
|
|
274
312
|
}
|
|
@@ -278,7 +316,7 @@ async function run() {
|
|
|
278
316
|
await client.initialize({ roots: {} });
|
|
279
317
|
const rootsProj = fresh();
|
|
280
318
|
client.rootsHandler = () => [rootsProj];
|
|
281
|
-
const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
|
|
319
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low' });
|
|
282
320
|
check('M1: a single MCP root is used when the client declares the capability', r.isError, undefined);
|
|
283
321
|
check('M1: the server actually asked for roots/list', client.messages.some((m) => m.method === 'roots/list'), true);
|
|
284
322
|
check('M1: ceiling state landed under the root the client returned', existsSync(path.join(rootsProj, '.somi', 'somi-state')), true);
|
|
@@ -289,7 +327,7 @@ async function run() {
|
|
|
289
327
|
await withClient({}, async (client) => {
|
|
290
328
|
await client.initialize({ roots: {} });
|
|
291
329
|
client.rootsHandler = () => [{ uri: 'not-a-file-uri' }];
|
|
292
|
-
const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
|
|
330
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low' });
|
|
293
331
|
check('M1: a non-file root URI is rejected outright (never resolved as a relative path)', r.isError, true);
|
|
294
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);
|
|
295
333
|
});
|
|
@@ -306,7 +344,7 @@ async function run() {
|
|
|
306
344
|
await withClient({}, async (client) => {
|
|
307
345
|
await client.initialize({ roots: {} });
|
|
308
346
|
client.rootsHandler = () => [{ uri: `file://${encodeURI(spaced)}` }];
|
|
309
|
-
const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
|
|
347
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low' });
|
|
310
348
|
check('M1: a percent-encoded root URI resolves (isError undefined)', r.isError, undefined);
|
|
311
349
|
check('M1: it decodes to the REAL space directory, not the literal-percent one', existsSync(path.join(spaced, '.somi', 'somi-state')), true);
|
|
312
350
|
check('M1: the literal "a%20b" directory is untouched', existsSync(path.join(literalPercent, '.somi')), false);
|
|
@@ -320,12 +358,12 @@ async function run() {
|
|
|
320
358
|
const rootA = fresh();
|
|
321
359
|
const rootB = fresh();
|
|
322
360
|
client.rootsHandler = () => [rootA, rootB];
|
|
323
|
-
const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
|
|
361
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low' });
|
|
324
362
|
check('M1: more than one root with no project_dir is ambiguous and refused', r.isError, true);
|
|
325
363
|
check('M1/M3: ambiguous roots refusal is the project-environment family (67)', /\(exit 67\)/.test(toolText(r)), true);
|
|
326
364
|
check('M1: neither offered root got a .somi/ written', existsSync(path.join(rootA, '.somi')) || existsSync(path.join(rootB, '.somi')), false);
|
|
327
365
|
|
|
328
|
-
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 });
|
|
329
367
|
check('M1+M3: project_dir selecting one of several ambiguous roots is allowed', r2.isError, undefined);
|
|
330
368
|
check('M1+M3: state landed under the SELECTED root', existsSync(path.join(rootB, '.somi', 'somi-state')), true);
|
|
331
369
|
check('M1+M3: the other offered root got nothing written', existsSync(path.join(rootA, '.somi')), false);
|
|
@@ -337,7 +375,7 @@ async function run() {
|
|
|
337
375
|
await client.initialize({ roots: {} });
|
|
338
376
|
const missing = path.join(tmpRoot, `missing-${Math.random().toString(36).slice(2)}`);
|
|
339
377
|
client.rootsHandler = () => [missing];
|
|
340
|
-
const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
|
|
378
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder' });
|
|
341
379
|
check('M1: a nonexistent MCP root is rejected', r.isError, true);
|
|
342
380
|
check('M1: it is never silently created', existsSync(missing), false);
|
|
343
381
|
});
|
|
@@ -346,14 +384,14 @@ async function run() {
|
|
|
346
384
|
// malformed project_dir (relative, nonexistent) is a usage error (64) regardless.
|
|
347
385
|
await withClient({}, async (client) => {
|
|
348
386
|
await client.initialize(); // no `roots` capability declared
|
|
349
|
-
const r = await toolCall(client, 'somi_resolve', { agent: 'coder' });
|
|
387
|
+
const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder' });
|
|
350
388
|
check('no root establishable is isError', r.isError, true);
|
|
351
389
|
check('the error names the reason and how to fix it', /project_dir/.test(toolText(r)), true);
|
|
352
390
|
check('the exit-67 family is used for "cannot establish a root"', /\(exit 67\)/.test(toolText(r)), true);
|
|
353
391
|
|
|
354
|
-
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' });
|
|
355
393
|
check('a non-absolute project_dir is rejected (64)', /\(exit 64\)/.test(toolText(r2)), true);
|
|
356
|
-
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' });
|
|
357
395
|
check('a nonexistent project_dir is rejected (64)', /\(exit 64\)/.test(toolText(r2)), true);
|
|
358
396
|
});
|
|
359
397
|
|
|
@@ -361,12 +399,12 @@ async function run() {
|
|
|
361
399
|
await withClient({}, async (client) => {
|
|
362
400
|
await client.initialize();
|
|
363
401
|
const proj = fresh();
|
|
364
|
-
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 });
|
|
365
403
|
check('m1: an array-valued host is rejected (64), not silently defaulted', /\(exit 64\)/.test(toolText(r)), true);
|
|
366
404
|
check('m1: a rejected host leaves the project root untouched', existsSync(path.join(proj, '.somi')), false);
|
|
367
405
|
|
|
368
406
|
const proj2 = fresh();
|
|
369
|
-
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 });
|
|
370
408
|
check('m1: an empty-string ceiling is rejected (64), not silently defaulted', /\(exit 64\)/.test(toolText(r)), true);
|
|
371
409
|
check('m1: a rejected ceiling leaves the project root untouched', existsSync(path.join(proj2, '.somi')), false);
|
|
372
410
|
});
|
|
@@ -388,8 +426,8 @@ async function run() {
|
|
|
388
426
|
{
|
|
389
427
|
const badInputs = [
|
|
390
428
|
{ name: 'invalid agent name', args: { agent: 'Not-Valid' } },
|
|
391
|
-
{ name: 'unrecognized ceiling', args: { agent: 'coder', ceiling: 'ultra' } },
|
|
392
|
-
{ name: 'somi is exempt from cost
|
|
429
|
+
{ name: 'unrecognized ceiling', args: { agent: 'somi-coder', ceiling: 'ultra' } },
|
|
430
|
+
{ name: 'somi is exempt from cost resolution', args: { agent: 'somi' } },
|
|
393
431
|
{ name: 'unknown agent', args: { agent: 'totally-not-a-real-agent' } },
|
|
394
432
|
];
|
|
395
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"
|