@skathio/somi 5.0.3 → 5.1.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.
@@ -13,7 +13,7 @@
13
13
  "url": "https://github.com/skathio/somi.git"
14
14
  },
15
15
  "description": "A workflow plugin for coding agents: say what you want or pass a ticket, and it picks the right workflow and keeps the cost down, while your agent stays in charge.",
16
- "version": "5.0.3",
16
+ "version": "5.1.0",
17
17
  "tags": [
18
18
  "workflow",
19
19
  "agents",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "somi",
3
- "version": "5.0.3",
3
+ "version": "5.1.0",
4
4
  "displayName": "SoMi",
5
5
  "description": "A workflow plugin for coding agents: say what you want or pass a ticket, and it picks the right workflow and keeps the cost down, while your agent stays in charge.",
6
6
  "keywords": [
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "somi",
3
3
  "displayName": "SoMi",
4
- "version": "5.0.3",
4
+ "version": "5.1.0",
5
5
  "description": "A workflow plugin for coding agents: say what you want or pass a ticket, and it picks the right workflow and keeps the cost down, while your agent stays in charge.",
6
6
  "keywords": [
7
7
  "workflow",
@@ -11,7 +11,7 @@
11
11
  "name": "somi",
12
12
  "source": "github:skathio/somi",
13
13
  "description": "A workflow plugin for coding agents: say what you want or pass a ticket, and it picks the right workflow and keeps the cost down, while your agent stays in charge.",
14
- "version": "5.0.3",
14
+ "version": "5.1.0",
15
15
  "tags": [
16
16
  "workflow",
17
17
  "agents",
package/VERSION CHANGED
@@ -1 +1 @@
1
- 5.0.3
1
+ 5.1.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skathio/somi",
3
- "version": "5.0.3",
3
+ "version": "5.1.0",
4
4
  "scripts": {
5
5
  "test": "node --test --test-reporter=spec tests/*.test.mjs",
6
6
  "test:coverage": "node -e \"require('fs').mkdirSync('coverage',{recursive:true})\" && node --test --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info tests/*.test.mjs",
@@ -118,7 +118,7 @@ const LARGE = (request) => String(request ?? '').length > LONG_REQUEST;
118
118
  // Everything here is done from the chat: the agent runs SoMi's own commands by their full path, because no somi command is on the PATH.
119
119
  const QUALITY_CONFIG = `Relay this briefly. To change a quality limit, write it under quality in the file named by global_config, or under quality.commit or quality.pr for one scope, never in the project's .somi/config.json, where only a tighter value counts. Before you write a value looser than the current limit, ask the user and wait for a yes. quality_timeout_seconds is how long the gate may run before it counts as failed: to change it, write quality.timeout_seconds there, a whole number from ${QUALITY_TIMEOUT.min} to ${QUALITY_TIMEOUT.max}.`;
120
120
  const SETUP = (host) => `To check SoMi's setup, run \`${somiCommand('doctor')}\` and relay what it finds. After tiers.main changes, run \`${somiCommand('setup')}\`. To connect another plugin to a step, run \`${somiCommand('slot <step> <plugin:component>')}\` with the step and component the user names, and \`${somiCommand('slot --list')}\` to show what is connected. To start sessions with SoMi's agent on its tier's model, \`${somiCommand('launch claude')}\` or \`${somiCommand('launch copilot')}\` does it, with anything after it passed to the host: give the user that command for an alias of their own.${host === 'claude' ? '' : ' SoMi registers the staged workflow, /somi-deliver, with Copilot for every project at session start, so there is nothing to run for it: a session that started before that gets it after /clear, and Copilot runs it only in experimental mode.'}`;
121
- const STAGED_ADVICE = (host) => `The user typed /somi-deliver to run this work in stages. Start the workflow below by its name with its args unchanged${host === 'claude' ? ', using the Workflow tool: it is a saved workflow, so no script and no authoring guide are needed' : ', as Copilot runs workflows in experimental mode. If Copilot says no workflow is registered by that name, this session started before SoMi registered it: tell the user that /clear or a new session loads it, and that /experimental must be on'}. Tell the user it is running and end your turn. When it returns, do not read or check the work again, because the workflow ran the checks: record its reviews with somi_review, passing tree as review_tree, and tell the user its summary and status in a few lines. If you cannot start it, say why, and call somi_route again with the same request and without staged for the steps.`;
121
+ const STAGED_ADVICE = (host) => `The user typed /somi-deliver to run this work in stages. Start the workflow below by its name with its args unchanged${host === 'claude' ? ', using the Workflow tool: it is a saved workflow, so no script and no authoring guide are needed' : ', as Copilot runs workflows in experimental mode. If Copilot says no workflow is registered by that name, this session started before SoMi registered it: reload extensions with the extensions reload tool, which registers it without losing the conversation, then start the workflow again; failing that, tell the user that /clear or a new session loads it. /experimental must be on'}. Tell the user it is running and end your turn. When it returns, do not read or check the work again, because the workflow ran the checks: record its reviews with somi_review, passing tree as review_tree, and tell the user its summary and status in a few lines. If you cannot start it, say why, and call somi_route again with the same request and without staged for the steps.`;
122
122
  const SUGGEST_STAGED = 'This looks like large work. Tell the user once that typing /somi-deliver with it runs it in stages, each on its tier, and that only they can start that. Then follow steps.';
123
123
 
124
124
  // With no rule to go on and the whole table to choose from, a request is new work. Asking the model to pick costs a turn and lets it
@@ -13,6 +13,8 @@ const PROJECT_MARK = '// Written by somi init:';
13
13
 
14
14
  const isLink = (p) => { try { return fs.lstatSync(p).isSymbolicLink(); } catch { return false; } };
15
15
 
16
+ export const copilotHomeExists = (env = process.env, home = os.homedir()) => fs.existsSync(env.COPILOT_HOME || path.join(home, '.copilot'));
17
+
16
18
  export const copilotExtensionFile = (env = process.env, home = os.homedir()) => path.join(env.COPILOT_HOME || path.join(home, '.copilot'), 'extensions', 'somi', 'extension.mjs');
17
19
 
18
20
  // A few lines that load SoMi's own module from the plugin. When the plugin is gone, it joins with nothing rather than failing to load.
@@ -43,10 +43,17 @@ export function exemption(ctx, lines, unit, rule) {
43
43
  return { reason: m[2], expires: m[3] };
44
44
  }
45
45
 
46
+ // A function is paired with its old version by name and signature first, so a new overload added above an old one is new, not the
47
+ // old one got different. What is left is paired by name alone, so a function whose parameters changed is still the same function.
46
48
  function pairUnits(before, after) {
47
- const pool = new Map();
48
- for (const u of before) { const k = `${u.kind}:${u.name}`; pool.set(k, [...(pool.get(k) ?? []), u]); }
49
- return after.map((u) => ({ after: u, before: pool.get(`${u.kind}:${u.name}`)?.shift() ?? null }));
49
+ const taken = new Set();
50
+ const match = (u, key) => {
51
+ const old = before.find((b) => !taken.has(b) && key(b) === key(u));
52
+ if (old) taken.add(old);
53
+ return old ?? null;
54
+ };
55
+ const exact = after.map((u) => match(u, (x) => `${x.kind}:${x.name}:${x.signature}`));
56
+ return after.map((u, i) => ({ after: u, before: exact[i] ?? match(u, (x) => `${x.kind}:${x.name}`) }));
50
57
  }
51
58
 
52
59
  const inAdded = (added, line) => added.some(([a, b]) => line >= a && line <= b);
@@ -1,17 +1,21 @@
1
- // quality/metrics.mjs: per-function structure of JavaScript and TypeScript, from a tree-sitter tree. SoMi-CC v1 follows SonarSource's
1
+ // quality/metrics.mjs: per-function structure of JavaScript, TypeScript and C#, from a tree-sitter tree. SoMi-CC v1 follows SonarSource's
2
2
  // cognitive complexity: +1 for each break in linear flow, plus the nesting level for one that is nested, +1 per sequence of like
3
3
  // boolean operators, +1 for recursion, and nothing for shorthand such as ?? or ?. . It deviates in one way, written down so nobody
4
4
  // reads it as Sonar parity: a function nested in another is scored as its own unit, starting at the control-flow nesting around the
5
5
  // point where it is defined. Sonar folds it into the outer function, which would score a test file's describe block as one function.
6
6
 
7
- const FUNCTIONS = new Set(['function_declaration', 'function_expression', 'function', 'arrow_function', 'method_definition', 'generator_function_declaration', 'generator_function']);
8
- const LOOPS = new Set(['for_statement', 'for_in_statement', 'for_of_statement', 'while_statement', 'do_statement']);
7
+ // The C# grammar's node types sit beside the JavaScript ones. An else-if there is an if_statement held directly as the alternative.
8
+ const FUNCTIONS = new Set(['function_declaration', 'function_expression', 'function', 'arrow_function', 'method_definition', 'generator_function_declaration', 'generator_function',
9
+ 'method_declaration', 'constructor_declaration', 'destructor_declaration', 'operator_declaration', 'conversion_operator_declaration', 'local_function_statement', 'lambda_expression', 'anonymous_method_expression']);
10
+ const LOOPS = new Set(['for_statement', 'for_in_statement', 'for_of_statement', 'while_statement', 'do_statement', 'foreach_statement']);
11
+ const TERNARY = new Set(['ternary_expression', 'conditional_expression', 'switch_expression']);
9
12
  const DEPTH = new Set(['if_statement', 'switch_statement', 'try_statement', ...LOOPS]);
10
13
  const BOOLEAN = new Set(['&&', '||']);
11
14
  const JSX = new Set(['jsx_element', 'jsx_self_closing_element', 'jsx_fragment']);
12
15
 
13
16
  const field = (node, name) => node.childForFieldName(name);
14
17
  const same = (a, b) => Boolean(a && b) && a.startIndex === b.startIndex && a.endIndex === b.endIndex && a.type === b.type;
18
+ const isElseIf = (node) => node.type === 'if_statement' && (node.parent?.type === 'else_clause' || same(node, field(node.parent, 'alternative')));
15
19
  const operator = (node) => field(node, 'operator')?.type ?? node.children.find((c) => !c.isNamed && BOOLEAN.has(c.type))?.type;
16
20
 
17
21
  function nameOf(node) {
@@ -28,6 +32,7 @@ function nameOf(node) {
28
32
  function paramCount(node) {
29
33
  if (field(node, 'parameter')) return 1;
30
34
  const params = field(node, 'parameters');
35
+ if (params?.type === 'implicit_parameter') return 1;
31
36
  return params ? params.namedChildren.filter((c) => c.type !== 'comment').length : 0;
32
37
  }
33
38
 
@@ -52,12 +57,13 @@ function hasJsx(node) {
52
57
  // What each structure that breaks linear flow adds, and which of its parts sit one nesting level deeper. An else-if adds one and keeps
53
58
  // the nesting of the if it continues; an else adds one.
54
59
  function ifStatement(node, nesting, ctx) {
55
- const elseIf = node.parent?.type === 'else_clause';
60
+ const elseIf = isElseIf(node);
56
61
  ctx.score += elseIf ? 1 : 1 + nesting;
57
62
  const base = elseIf ? nesting - 1 : nesting;
58
63
  ctx.walk(field(node, 'condition'), base);
59
64
  ctx.walk(field(node, 'consequence'), base + 1);
60
- const inner = field(node, 'alternative')?.namedChildren.find((c) => c.type !== 'comment');
65
+ const alternative = field(node, 'alternative');
66
+ const inner = alternative?.type === 'else_clause' ? alternative.namedChildren.find((c) => c.type !== 'comment') : alternative;
61
67
  if (inner && inner.type !== 'if_statement') ctx.score += 1;
62
68
  ctx.walk(inner, base + 1);
63
69
  }
@@ -71,6 +77,11 @@ const nestsIn = (fields) => (node, nesting, ctx) => {
71
77
  const STRUCTURES = {
72
78
  if_statement: ifStatement,
73
79
  ternary_expression: nestsIn(['consequence', 'alternative']),
80
+ conditional_expression: nestsIn(['consequence', 'alternative']),
81
+ switch_expression: (node, nesting, ctx) => {
82
+ ctx.score += 1 + nesting;
83
+ for (const c of node.namedChildren) ctx.walk(c, c.type === 'switch_expression_arm' ? nesting + 1 : nesting);
84
+ },
74
85
  switch_statement: nestsIn(['body']),
75
86
  catch_clause: nestsIn(['body']),
76
87
  ...Object.fromEntries([...LOOPS].map((type) => [type, nestsIn(['body'])])),
@@ -86,7 +97,7 @@ const recursion = (node, ctx) => {
86
97
  const callee = field(node, 'function');
87
98
  return ctx.name && callee?.type === 'identifier' && callee.text === ctx.name ? 1 : 0;
88
99
  };
89
- const FLAT = { break_statement: labelled, continue_statement: labelled, binary_expression: sequence, call_expression: recursion };
100
+ const FLAT = { break_statement: labelled, continue_statement: labelled, goto_statement: () => 1, binary_expression: sequence, call_expression: recursion, invocation_expression: recursion };
90
101
 
91
102
  // Cognitive complexity of one unit. Nested functions are left out here and scored as their own units by unitsOf.
92
103
  function cognitive(unit, name, startNesting) {
@@ -107,7 +118,7 @@ function maxDepth(unit) {
107
118
  let max = 0;
108
119
  const walk = (node, depth) => {
109
120
  if (node !== unit && FUNCTIONS.has(node.type)) return;
110
- const counts = DEPTH.has(node.type) && !(node.type === 'if_statement' && node.parent?.type === 'else_clause');
121
+ const counts = DEPTH.has(node.type) && !isElseIf(node);
111
122
  const d = counts ? depth + 1 : depth;
112
123
  if (d > max) max = d;
113
124
  for (const c of node.namedChildren) walk(c, d);
@@ -120,7 +131,7 @@ function maxDepth(unit) {
120
131
  function nestingAt(node) {
121
132
  let n = 0;
122
133
  for (let p = node.parent, child = node; p && !FUNCTIONS.has(p.type); child = p, p = p.parent) {
123
- if (LOOPS.has(p.type) || p.type === 'switch_statement' || p.type === 'catch_clause' || p.type === 'ternary_expression') n += 1;
134
+ if (LOOPS.has(p.type) || p.type === 'switch_statement' || p.type === 'catch_clause' || TERNARY.has(p.type)) n += 1;
124
135
  if (p.type === 'if_statement' && !same(child, field(p, 'condition'))) n += 1;
125
136
  }
126
137
  return n;
@@ -143,6 +154,8 @@ export function unitsOf(tree, { file = '', isTest = false } = {}) {
143
154
  cognitive: cognitive(node, name, start),
144
155
  depth: maxDepth(node),
145
156
  params: paramCount(node),
157
+ // C# overloads, and a constructor beside its destructor, share a name: the gate tells them apart by this.
158
+ signature: `${node.type}(${(field(node, 'parameters') ?? field(node, 'parameter'))?.text.replace(/\s+/g, ' ') ?? ''})`,
146
159
  });
147
160
  for (const c of node.namedChildren) visit(c, start);
148
161
  return;
@@ -10,7 +10,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
10
10
  const DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'vendor', 'tree-sitter');
11
11
  export const MAX_FILE_BYTES = 512 * 1024;
12
12
  export const PARSE_TIMEOUT_MS = 5000;
13
- const LANGUAGES = { '.js': 'javascript', '.mjs': 'javascript', '.cjs': 'javascript', '.jsx': 'javascript', '.ts': 'typescript', '.mts': 'typescript', '.cts': 'typescript', '.tsx': 'tsx', '.css': 'css' };
13
+ const LANGUAGES = { '.js': 'javascript', '.mjs': 'javascript', '.cjs': 'javascript', '.jsx': 'javascript', '.ts': 'typescript', '.mts': 'typescript', '.cts': 'typescript', '.tsx': 'tsx', '.css': 'css', '.cs': 'c-sharp' };
14
14
 
15
15
  /** The grammar a file is parsed with, or null when the gate does not cover its language yet. */
16
16
  export const languageOf = (file) => LANGUAGES[path.extname(file).toLowerCase()] ?? null;
package/scripts/somi.mjs CHANGED
@@ -12,7 +12,7 @@
12
12
  // somi status | migrate
13
13
  // somi setup [--host claude|copilot] makes SoMi the session agent, on the model set for its tier
14
14
  // somi doctor [--host claude|copilot] [--profile]
15
- // somi init --host copilot registers the staged workflow with Copilot CLI, once for every project
15
+ // somi init [--host copilot] registers the staged workflow with Copilot CLI, once for every project
16
16
  // somi launch claude|copilot [args...] starts the host with SoMi's agent, on the model set for its tier
17
17
  //
18
18
  // Exit codes: 0 done, 1 a check, the doctor or the pull request gate failed, 64 the request was refused.
@@ -28,7 +28,7 @@ import { runCheck } from './lib/check.mjs';
28
28
  import { ConfigFileError, globalConfigPath, loadConfig, readConfigFile } from './lib/config-files.mjs';
29
29
  import { duplicateHookWarnings, runDoctor } from './lib/doctor.mjs';
30
30
  import { commitBase, listFiles, repoRoot, resolveRef, snapshotTree, stateIsTracked, workBase } from './lib/git-tree.mjs';
31
- import { installCopilotExtension, projectExtensionWarnings } from './lib/init.mjs';
31
+ import { copilotHomeExists, installCopilotExtension, projectExtensionWarnings } from './lib/init.mjs';
32
32
  import { LAUNCH_HOSTS, launchPlan, spawnPlan } from './lib/launch.mjs';
33
33
  import { addToLedger, readLedger } from './lib/ledger.mjs';
34
34
  import { migrate } from './lib/migrate.mjs';
@@ -146,13 +146,19 @@ function slotCommand(ctx, args) {
146
146
  return 0;
147
147
  }
148
148
 
149
- // The session-start hook does this on its own, so init is for a session that started before the plugin was installed.
149
+ // The session-start hook does this on its own, so init is for a session that started before the plugin was installed. Without --host it
150
+ // finds Copilot CLI by its environment or its folder, and on Claude Code it has nothing to do.
151
+ const RELOAD = 'A file that is current is not yet a loaded extension. In the open session, reload extensions (the extensions reload tool) to register the workflow without losing the conversation, or start a new session or /clear. Copilot runs workflows in experimental mode: start with --experimental, or turn it on with /experimental.';
150
152
  function initCommand(ctx, args) {
151
153
  const { values } = parseArgs({ args, options: { host: { type: 'string' } } });
152
- if (values.host !== 'copilot') throw new StateError('init takes --host copilot; the Claude Code plugin needs no setup');
154
+ if (values.host !== undefined && values.host !== 'copilot' && values.host !== 'claude') throw new StateError('init takes --host copilot or --host claude');
155
+ // An explicit SOMI_HOST wins; the folder is only a guess for when nothing says which host this is.
156
+ const named = ctx.env.SOMI_HOST === 'claude' || ctx.env.SOMI_HOST === 'copilot';
157
+ const host = values.host ?? (detectHost(ctx.env) === 'copilot' || (!named && copilotHomeExists(ctx.env)) ? 'copilot' : 'claude');
158
+ if (host === 'claude') { print({ host, extension: null, workflows: 'The Claude Code plugin needs no setup.' }); return 0; }
153
159
  const extension = installCopilotExtension({ pluginRoot: PLUGIN_ROOT, env: ctx.env });
154
160
  const warnings = [...duplicateHookWarnings(ctx.root), ...projectExtensionWarnings(ctx.root)];
155
- print({ extension, workflows: 'Copilot loads it at the next session start or after /clear, and runs workflows in experimental mode: start with --experimental, or turn it on with /experimental.', ...(warnings.length ? { warnings } : {}) });
161
+ print({ host, extension, workflows: RELOAD, ...(warnings.length ? { warnings } : {}) });
156
162
  return extension.written || extension.current ? 0 : 1;
157
163
  }
158
164
 
@@ -54,6 +54,15 @@
54
54
  "license": "MIT",
55
55
  "bytes": 128668,
56
56
  "sha256": "8a23977fe271357cce6f254ef88c9bebf3854602d8046605aef6a45c02135c59"
57
+ },
58
+ "tree-sitter-c-sharp.wasm": {
59
+ "package": "@vscode/tree-sitter-wasm",
60
+ "version": "0.3.1",
61
+ "tarball_integrity": "sha512-RJFoomET6FajjG511fmQxeBQfU6M24a0aFZPqpid+ttIxanWf1VGytBG0UmsGjt07qmIPJS8U31D+aecuCucsQ==",
62
+ "repository": "https://github.com/microsoft/vscode-tree-sitter-wasm",
63
+ "license": "MIT",
64
+ "bytes": 5103332,
65
+ "sha256": "d12d85996c25957b4c1b71e26db2d7cc8a294997b60642e9c2a3b031b2c66dd3"
57
66
  }
58
67
  }
59
68
  }