@skathio/somi 5.1.1 → 5.3.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 (58) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.copilot-extension/extension.json +5 -1
  4. package/.copilot-extension/marketplace.json +1 -1
  5. package/README.md +20 -8
  6. package/VERSION +1 -1
  7. package/agents/somi-reviewer.md +3 -1
  8. package/agents/somi-security-reviewer.md +3 -1
  9. package/commands/somi-brief.md +11 -0
  10. package/commands/somi-deliver.md +3 -1
  11. package/commands/somi.md +2 -2
  12. package/hooks/pre-tool/apply-tier.mjs +12 -6
  13. package/library/roles/brief.md +33 -0
  14. package/package.json +1 -2
  15. package/rules/digest.md +6 -0
  16. package/scripts/lib/advisor.mjs +47 -14
  17. package/scripts/lib/brief-own.mjs +13 -0
  18. package/scripts/lib/brief-parse.mjs +94 -0
  19. package/scripts/lib/brief-route.mjs +49 -0
  20. package/scripts/lib/brief.mjs +69 -0
  21. package/scripts/lib/chat-commands.mjs +65 -0
  22. package/scripts/lib/check.mjs +3 -2
  23. package/scripts/lib/git-tree.mjs +37 -8
  24. package/scripts/lib/ledger.mjs +9 -0
  25. package/scripts/lib/policy.mjs +20 -1
  26. package/scripts/lib/pr.mjs +2 -2
  27. package/scripts/lib/prompt.mjs +17 -4
  28. package/scripts/lib/quality/clones.mjs +113 -26
  29. package/scripts/lib/quality/coupling.mjs +115 -0
  30. package/scripts/lib/quality/exports.mjs +33 -0
  31. package/scripts/lib/quality/findings.mjs +18 -0
  32. package/scripts/lib/quality/functions.mjs +71 -0
  33. package/scripts/lib/quality/gate.mjs +134 -144
  34. package/scripts/lib/quality/imports.mjs +88 -0
  35. package/scripts/lib/quality/js-source.mjs +55 -0
  36. package/scripts/lib/quality/limits.mjs +102 -23
  37. package/scripts/lib/quality/metrics.mjs +65 -16
  38. package/scripts/lib/quality/parse.mjs +16 -11
  39. package/scripts/lib/quality/path-aliases.mjs +36 -0
  40. package/scripts/lib/quality/python-exports.mjs +31 -0
  41. package/scripts/lib/quality/python-findings.mjs +82 -0
  42. package/scripts/lib/quality/python-imports.mjs +64 -0
  43. package/scripts/lib/quality/python.mjs +50 -0
  44. package/scripts/lib/quality/repo.mjs +31 -12
  45. package/scripts/lib/quality/run.mjs +2 -2
  46. package/scripts/lib/quality/slop.mjs +168 -0
  47. package/scripts/lib/quality/suppressions.mjs +38 -0
  48. package/scripts/lib/quality/totals.mjs +39 -0
  49. package/scripts/lib/reviews.mjs +20 -9
  50. package/scripts/lib/routes.mjs +2 -1
  51. package/scripts/lib/views.mjs +8 -3
  52. package/scripts/lib/workflows.mjs +24 -1
  53. package/scripts/somi-mcp.mjs +26 -3
  54. package/scripts/somi.mjs +21 -7
  55. package/scripts/vendor/tree-sitter/LICENSE.tree-sitter-python +21 -0
  56. package/scripts/vendor/tree-sitter/manifest.json +11 -1
  57. package/scripts/vendor/tree-sitter/tree-sitter-python.wasm +0 -0
  58. package/workflows/deliver-stages.js +420 -48
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // somi-mcp.mjs: a zero-dependency stdio MCP server with six tools. They give advice and keep a small record, and none of them holds up the
2
+ // somi-mcp.mjs: a zero-dependency stdio MCP server with seven tools. They give advice and keep a small record, and none of them holds up the
3
3
  // conversation: a question, a follow-up or a change of mind never needs to go through here.
4
4
  //
5
5
  // MCP servers run outside the OS sandbox on Claude Code, so this path never executes project commands. It only reads git and SoMi's own files,
@@ -14,6 +14,7 @@ import { fileURLToPath } from 'node:url';
14
14
  import { ConfigFileError, loadConfig } from './lib/config-files.mjs';
15
15
  import { advise, shardAdvice } from './lib/advisor.mjs';
16
16
  import { repoRoot, stateIsTracked } from './lib/git-tree.mjs';
17
+ import { briefStatus, closeBrief, readBrief, saveBrief } from './lib/brief.mjs';
17
18
  import { addToLedger } from './lib/ledger.mjs';
18
19
  import { resolveProjectRoot } from './lib/mcp-project-root.mjs';
19
20
  import { ReviewInputError } from './lib/policy.mjs';
@@ -114,6 +115,15 @@ const TOOLS = [
114
115
  properties: { text: { type: 'string' }, done: { type: 'integer', minimum: 1 }, close: { type: 'boolean' }, project_dir: PROJECT_DIR },
115
116
  },
116
117
  },
118
+ {
119
+ name: 'somi_brief',
120
+ description: 'The brief /somi-brief prepares. text saves it once the user approves, and refuses one that is not ready; close ends it; nothing shows it.',
121
+ inputSchema: {
122
+ type: 'object',
123
+ additionalProperties: false,
124
+ properties: { text: { type: 'string' }, close: { type: 'boolean' }, project_dir: PROJECT_DIR },
125
+ },
126
+ },
117
127
  {
118
128
  name: 'somi_quality',
119
129
  description: 'Checks code against the quality limits: the branch by default, one commit, or the whole codebase for a cleanup. Use when the user asks about code quality.',
@@ -174,6 +184,13 @@ function planTool(ctx, a) {
174
184
  return textResult(planStatus(ctx.root) ?? { plan: null, advice: 'No plan is open.' });
175
185
  }
176
186
 
187
+ function briefTool(ctx, a) {
188
+ if (a.close === true) return textResult(closeBrief(ctx.root, ctx.env));
189
+ if (typeof a.text === 'string') return textResult(saveBrief(ctx.root, a.text, ctx.env));
190
+ const open = readBrief(ctx.root);
191
+ return textResult(open ? { ...briefStatus(open), text: open.text } : { brief: null, advice: 'No brief is open.' });
192
+ }
193
+
177
194
  function prTool(ctx, a) {
178
195
  const result = pullRequest(ctx, { base: a.base, unreviewed: a.unreviewed === true });
179
196
  return textResult(result.ok ? { ...result, ...shardAdvice(ctx, 'pr.open') } : result, !result.ok);
@@ -181,6 +198,8 @@ function prTool(ctx, a) {
181
198
 
182
199
  const QUALITY_ADVICE = 'Tell the user what failed, worst first, in a few lines. Fix it only if they ask, or if it is code you changed in this conversation: refactor until it passes with the tests still green, and never add a somi-gate-allow exemption to get past it. To change a limit, the user sets it under quality in their own config, which somi_route with hint config explains.';
183
200
 
201
+ const QUALITY_PASS = 'Everything is within the limits. Say so in one line. Warnings are advice: mention any in code you changed in this conversation, and fix one only if the user asks. Skipped and uncovered files were not scored.';
202
+
184
203
  function qualityTool(ctx, a) {
185
204
  const scope = a.scope ?? 'pr';
186
205
  if (!SCOPES.includes(scope)) return textResult(`scope is one of ${SCOPES.join(', ')}.`, true);
@@ -189,7 +208,9 @@ function qualityTool(ctx, a) {
189
208
  if (r.error) return textResult(r.error, true);
190
209
  const worst = CHANGE_SCOPES.includes(scope) ? {} : { most_complex: r.summary.most_complex.slice(0, 5), most_findings: r.summary.most_findings.slice(0, 5) };
191
210
  const ignored = r.ignored_config ? { ignored_config: r.ignored_config } : {};
192
- return textResult({ ok: r.ok, scope, failures: describeAll(r.violations, scope), scored: r.scored, unanalyzed: r.unanalyzed.length, ...worst, ...ignored, advice: r.ok ? 'Everything is within the limits. Say so in one line.' : QUALITY_ADVICE });
211
+ const advice = r.warnings?.length ? { warnings: describeAll(r.warnings, scope) } : {};
212
+ const notScored = { ...(r.skipped?.length ? { skipped: r.skipped.length } : {}), ...(r.uncovered?.length ? { uncovered: r.uncovered.length } : {}) };
213
+ return textResult({ ok: r.ok, scope, failures: describeAll(r.violations, scope), ...advice, scored: r.scored, unanalyzed: r.unanalyzed.length, ...notScored, ...worst, ...ignored, advice: r.ok ? QUALITY_PASS : QUALITY_ADVICE });
193
214
  }
194
215
 
195
216
  function reviewAdvice(plan) {
@@ -204,7 +225,8 @@ function reviewTool(ctx, a) {
204
225
  if (typeof a.reviews === 'string') { try { a.reviews = JSON.parse(a.reviews); } catch { return textResult('reviews is not valid JSON. Send an array with every reviewer\'s JSON object.', true); } }
205
226
  if (a.reviews) return textResult({ ...recordReviews(ctx, { ...options, reviews: a.reviews, tree: a.tree }), ...shardAdvice(ctx, 'review.done') });
206
227
  const plan = reviewPlan(ctx, options);
207
- const security = plan.signals.some((s) => SECURITY_SIGNALS.includes(s)) ? { security: 'Security signals fired on this diff, so the security reviewer runs on the high tier, and any fix stays in this conversation, not on a cheaper worker.' } : {};
228
+ const tier = plan.reviewers.find((r) => r.agent === 'somi:somi-security-reviewer')?.tier ?? 'high';
229
+ const security = plan.signals.some((s) => SECURITY_SIGNALS.includes(s)) ? { security: `Security signals fired on this diff, so the security reviewer runs on the ${tier} tier, on the model its seat names, and any fix stays in this conversation, not on a cheaper worker.` } : {};
208
230
  return textResult({ ...plan, ...security, advice: reviewAdvice(plan) });
209
231
  }
210
232
 
@@ -212,6 +234,7 @@ const TOOL_HANDLERS = {
212
234
  somi_route: (ctx, a) => textResult(advise(ctx, { request: typeof a.request === 'string' ? a.request : undefined, hint: a.hint, ticket: a.ticket, sensitive: a.sensitive, staged: a.staged })),
213
235
  somi_note: (ctx, a) => textResult(addToLedger(ctx.root, { kind: a.kind, text: a.text }, ctx.env)),
214
236
  somi_plan: planTool,
237
+ somi_brief: briefTool,
215
238
  somi_pr: prTool,
216
239
  somi_quality: qualityTool,
217
240
  somi_review: reviewTool,
package/scripts/somi.mjs CHANGED
@@ -7,6 +7,7 @@
7
7
  // somi check [--full]
8
8
  // somi pr [--base REF] [--unreviewed] writes the pull request text; a change that needed a review and has none is refused
9
9
  // somi plan | --done N | --close saves the plan text from stdin, marks a milestone done, or ends the plan
10
+ // somi brief | --show | --close saves the brief from stdin, shows it, or ends it
10
11
  // somi slot <step> <plugin:component> [--mode read|write] [--project] | somi slot --list | --remove | --confirm
11
12
  // somi ledger --kind decision|constraint|pointer --text T
12
13
  // somi status | migrate
@@ -30,12 +31,13 @@ import { duplicateHookWarnings, runDoctor } from './lib/doctor.mjs';
30
31
  import { commitBase, listFiles, repoRoot, resolveRef, snapshotTree, stateIsTracked, workBase } from './lib/git-tree.mjs';
31
32
  import { copilotHomeExists, installCopilotExtension, projectExtensionWarnings } from './lib/init.mjs';
32
33
  import { LAUNCH_HOSTS, launchPlan, spawnPlan } from './lib/launch.mjs';
34
+ import { briefStatus, closeBrief, readBrief, saveBrief } from './lib/brief.mjs';
33
35
  import { addToLedger, readLedger } from './lib/ledger.mjs';
34
36
  import { migrate } from './lib/migrate.mjs';
35
37
  import { lastCheck, migratedFindings, pullRequest } from './lib/pr.mjs';
36
38
  import { closePlan, markMilestoneDone, planStatus, savePlan } from './lib/plan.mjs';
37
39
  import { ReviewInputError } from './lib/policy.mjs';
38
- import { CHANGE_SCOPES, SCOPES, limitsFor, resolveLimits } from './lib/quality/limits.mjs';
40
+ import { CHANGE_SCOPES, SCOPES, limitsFor, resolveForbidden, resolveLimits } from './lib/quality/limits.mjs';
39
41
  import { repoQuality } from './lib/quality/repo.mjs';
40
42
  import { qualityGate } from './lib/quality/gate.mjs';
41
43
  import { readReviews, recordReviews, reviewPlan } from './lib/reviews.mjs';
@@ -100,15 +102,17 @@ async function quality(ctx, args) {
100
102
  const scope = values.scope ?? 'pr';
101
103
  if (!SCOPES.includes(scope)) throw new StateError(`quality takes --scope ${SCOPES.join(', ')}`);
102
104
  const to = snapshotTree(ctx.root);
103
- const { limits, ignored } = values.benchmark ? { limits: limitsFor(scope), ignored: [] } : resolveLimits({ global: ctx.configLayers[0], project: ctx.configLayers[1], scope });
105
+ const { limits, level, ignored } = values.benchmark ? { limits: limitsFor(scope), level: 'strict', ignored: [] } : resolveLimits({ global: ctx.configLayers[0], project: ctx.configLayers[1], scope });
104
106
  if (scope === 'repo') {
105
107
  const report = await repoQuality(ctx.root, { rev: to, limits, now: ctx.now() });
106
- print({ ...report, scope, tree: to, ...(ignored.length ? { ignored_config: ignored } : {}) });
108
+ print({ ...report, scope, level, tree: to, ...(ignored.length ? { ignored_config: ignored } : {}) });
107
109
  return report.ok ? 0 : 1;
108
110
  }
109
111
  const from = values.from ? resolveRef(ctx.root, values.from) : scope === 'commit' ? commitBase(ctx.root) : workBase(ctx.root);
110
- const result = await qualityGate(ctx.root, { from, to, limits, now: ctx.now(), mode: values.benchmark ? 'benchmark' : 'project', repoFiles: listFiles(ctx.root, to) });
111
- print({ ...result, scope, from, to, ...(ignored.length ? { ignored_config: ignored } : {}) });
112
+ const rules = values.benchmark ? { forbid: [], ignored: [] } : resolveForbidden({ global: ctx.configLayers[0], project: ctx.configLayers[1] });
113
+ const result = await qualityGate(ctx.root, { from, to, limits, forbid: rules.forbid, now: ctx.now(), mode: values.benchmark ? 'benchmark' : 'project', repoFiles: listFiles(ctx.root, to) });
114
+ const notApplied = [...ignored, ...rules.ignored];
115
+ print({ ...result, scope, level, from, to, ...(notApplied.length ? { ignored_config: notApplied } : {}) });
112
116
  return result.ok ? 0 : 1;
113
117
  }
114
118
 
@@ -119,6 +123,15 @@ function plan(ctx, args) {
119
123
  return print({ saved: savePlan(ctx.root, fs.readFileSync(0, 'utf8')), ...planStatus(ctx.root) });
120
124
  }
121
125
 
126
+ const briefOf = (root) => { const open = readBrief(root); return open ? briefStatus(open) : null; };
127
+
128
+ function brief(ctx, args) {
129
+ const { values } = parseArgs({ args, options: { show: { type: 'boolean' }, close: { type: 'boolean' } } });
130
+ if (values.close) return print(closeBrief(ctx.root, ctx.env));
131
+ if (values.show) { const open = readBrief(ctx.root); return print(open ? { ...briefStatus(open), text: open.text } : { brief: null }); }
132
+ return print(saveBrief(ctx.root, fs.readFileSync(0, 'utf8'), ctx.env));
133
+ }
134
+
122
135
  // The probes do not need a repository, and a broken config is reported by the commands that need it.
123
136
  function doctor(args) {
124
137
  const { values } = parseArgs({ args, options: { host: { type: 'string' }, profile: { type: 'boolean' } } });
@@ -205,11 +218,12 @@ const COMMANDS = {
205
218
  return printed(result, result.ok);
206
219
  },
207
220
  status: (ctx) => {
208
- process.stdout.write(renderStatus({ plan: planStatus(ctx.root), ledger: readLedger(ctx.root, ctx.env), reviews: readReviews(ctx.root, ctx.env), check: lastCheck(ctx.root, ctx.env), migrated: migratedFindings(ctx.root, ctx.env) }));
221
+ process.stdout.write(renderStatus({ plan: planStatus(ctx.root), brief: briefOf(ctx.root), ledger: readLedger(ctx.root, ctx.env), reviews: readReviews(ctx.root, ctx.env), check: lastCheck(ctx.root, ctx.env), migrated: migratedFindings(ctx.root, ctx.env) }));
209
222
  return 0;
210
223
  },
211
224
  pr,
212
225
  plan: (ctx, args) => { plan(ctx, args); return 0; },
226
+ brief: (ctx, args) => { brief(ctx, args); return 0; },
213
227
  setup: (ctx, args) => {
214
228
  const { values } = parseArgs({ args, options: { host: { type: 'string' } } });
215
229
  const result = setupAgent({ host: values.host === 'claude' || values.host === 'copilot' ? values.host : ctx.host, config: ctx.config, pluginRoot: PLUGIN_ROOT, env: ctx.env });
@@ -229,7 +243,7 @@ function main(argv) {
229
243
  if (command === 'doctor') return doctor(args);
230
244
  if (command === 'launch') return launch(args);
231
245
  const run = Object.hasOwn(COMMANDS, command ?? '') ? COMMANDS[command] : null;
232
- if (!run) throw new StateError('somi takes route, review, check, quality, status, pr, plan, setup, slot, ledger, migrate, doctor, init or launch');
246
+ if (!run) throw new StateError('somi takes route, review, check, quality, status, pr, plan, brief, setup, slot, ledger, migrate, doctor, init or launch');
233
247
  return run(makeContext(), args);
234
248
  }
235
249
 
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Max Brunsfeld
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,5 +1,5 @@
1
1
  {
2
- "note": "Vendored unchanged from the npm tarballs named here, fetched with npm pack, which checks the tarball integrity. The loader refuses any file whose sha256 does not match.",
2
+ "note": "Vendored unchanged from the npm tarballs named here, fetched with npm pack, which checks the tarball integrity. The loader refuses any file whose sha256 does not match. The Python grammar is the tree-sitter project's own release; it was built for language ABI 15, which the web-tree-sitter runtime here loads.",
3
3
  "files": {
4
4
  "web-tree-sitter.js": {
5
5
  "package": "web-tree-sitter",
@@ -63,6 +63,16 @@
63
63
  "license": "MIT",
64
64
  "bytes": 5103332,
65
65
  "sha256": "d12d85996c25957b4c1b71e26db2d7cc8a294997b60642e9c2a3b031b2c66dd3"
66
+ },
67
+ "tree-sitter-python.wasm": {
68
+ "package": "tree-sitter-python",
69
+ "version": "0.25.0",
70
+ "tarball_integrity": "sha512-eCmJx6zQa35GxaCtQD+wXHOhYqBxEL+bp71W/s3fcDMu06MrtzkVXR437dRrCrbrDbyLuUDJpAgycs7ncngLXw==",
71
+ "repository": "https://github.com/tree-sitter/tree-sitter-python",
72
+ "license": "MIT",
73
+ "abi": 15,
74
+ "bytes": 457883,
75
+ "sha256": "16108b50df4ee9a30168794252ab55e7c93bfc5765d7fa0aa3e335752c515f47"
66
76
  }
67
77
  }
68
78
  }