@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.
Files changed (128) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +8 -2
  3. package/.copilot-extension/extension.json +9 -8
  4. package/.copilot-extension/marketplace.json +2 -2
  5. package/README.md +45 -33
  6. package/VERSION +1 -1
  7. package/agents/architecture-reviewer.md +16 -0
  8. package/agents/atlas.md +102 -0
  9. package/agents/coder.md +66 -22
  10. package/agents/designer.md +20 -16
  11. package/agents/discovery-analyst.md +6 -5
  12. package/agents/impact.md +97 -0
  13. package/agents/incident.md +96 -0
  14. package/agents/plan-reviewer.md +70 -0
  15. package/agents/planner.md +77 -20
  16. package/agents/pr.md +101 -0
  17. package/agents/refactor-designer.md +82 -0
  18. package/agents/refactorer.md +30 -24
  19. package/agents/reviewer.md +28 -25
  20. package/agents/sdlc-reviewer.md +69 -0
  21. package/agents/security-reviewer.md +17 -0
  22. package/agents/somi.md +204 -153
  23. package/agents/test-strategist.md +16 -1
  24. package/commands/adopt.md +21 -7
  25. package/commands/architecture-review.md +8 -5
  26. package/commands/atlas.md +24 -72
  27. package/commands/code-loop.md +46 -15
  28. package/commands/code-parallel.md +6 -4
  29. package/commands/code.md +29 -21
  30. package/commands/debug.md +17 -11
  31. package/commands/design.md +48 -31
  32. package/commands/discover.md +26 -16
  33. package/commands/impact.md +16 -54
  34. package/commands/incident.md +22 -55
  35. package/commands/plan-loop.md +43 -17
  36. package/commands/plan.md +64 -26
  37. package/commands/pr.md +19 -66
  38. package/commands/refactor-design.md +98 -0
  39. package/commands/refactor.md +22 -23
  40. package/commands/release-readiness.md +16 -7
  41. package/commands/review-panel.md +31 -10
  42. package/commands/review.md +21 -14
  43. package/commands/security-review.md +12 -3
  44. package/commands/ship-loop.md +71 -54
  45. package/commands/ship.md +17 -13
  46. package/commands/test-strategy.md +6 -4
  47. package/commands/upgrade.md +10 -8
  48. package/examples/discovery-example.md +2 -2
  49. package/examples/sample-consumer/CLAUDE.md +41 -7
  50. package/examples/sample-consumer/README.md +36 -22
  51. package/hooks/lib/common.mjs +66 -20
  52. package/hooks/post-tool/audit-log.mjs +7 -11
  53. package/hooks/post-tool/lint-changed-files.mjs +8 -11
  54. package/hooks/pre-tool/block-dangerous-bash.mjs +32 -44
  55. package/hooks/pre-tool/block-secret-writes.mjs +6 -9
  56. package/hooks/pre-tool/gate-dep-install.mjs +18 -27
  57. package/hooks/pre-tool/guard-protected-paths.mjs +9 -11
  58. package/hooks/session-start/detect-repo-instructions.mjs +21 -23
  59. package/hooks/user-prompt-submit/inject-workflow-context.mjs +190 -42
  60. package/mcp.json +10 -0
  61. package/package.json +5 -2
  62. package/rules/CLAUDE.md +22 -19
  63. package/scripts/check-links.mjs +218 -0
  64. package/scripts/check-session-artefacts.mjs +149 -0
  65. package/scripts/check-size-budget.mjs +137 -0
  66. package/scripts/generate-digest.mjs +176 -0
  67. package/scripts/lib/cost-ceiling.mjs +317 -0
  68. package/scripts/lib/cost-model.mjs +95 -0
  69. package/scripts/lib/dispatch-resolver.mjs +225 -0
  70. package/scripts/lib/mcp-project-root.mjs +183 -0
  71. package/scripts/size-budget-overrides.json +74 -0
  72. package/scripts/somi-check.mjs +6 -13
  73. package/scripts/somi-dispatch.mjs +141 -0
  74. package/scripts/somi-findings.mjs +4 -5
  75. package/scripts/somi-loop.mjs +181 -13
  76. package/scripts/somi-mcp.mjs +357 -0
  77. package/scripts/validate.sh +691 -30
  78. package/skills/clean-code/SKILL.md +1 -1
  79. package/skills/plan-review/SKILL.md +79 -0
  80. package/skills/rules/SKILL.md +47 -0
  81. package/skills/sdlc-process/SKILL.md +74 -0
  82. package/skills/somi-dispatch/SKILL.md +220 -0
  83. package/skills/somi-routing/SKILL.md +31 -6
  84. package/skills/{test-strategy → testing-playbook}/SKILL.md +1 -1
  85. package/templates/ATLAS.md.tmpl +4 -4
  86. package/templates/BRIEF.md.tmpl +23 -22
  87. package/templates/DECISIONS.md.tmpl +1 -0
  88. package/templates/DESIGN.md.tmpl +5 -5
  89. package/templates/DIARY.md.tmpl +10 -5
  90. package/templates/DOD.md.tmpl +24 -0
  91. package/templates/PROGRESS.md.tmpl +3 -16
  92. package/templates/SOMI-README.md.tmpl +3 -3
  93. package/tests/hooks/cases/inject-workflow-context.json +120 -7
  94. package/tests/hooks/run.sh +20 -11
  95. package/tests/scripts/check-links.sh +105 -0
  96. package/tests/scripts/check-session-artefacts.sh +60 -0
  97. package/tests/scripts/check-size-budget.sh +71 -0
  98. package/tests/scripts/checkpoint-gate.sh +90 -0
  99. package/tests/scripts/convergence-runner.sh +1510 -0
  100. package/tests/scripts/cost-ceiling.sh +343 -0
  101. package/tests/scripts/cost-model.sh +192 -0
  102. package/tests/scripts/dispatch-guard.sh +108 -0
  103. package/tests/scripts/dispatch-reference-gate.sh +173 -0
  104. package/tests/scripts/eval-runner.sh +3691 -0
  105. package/tests/scripts/evals-packaging.sh +117 -0
  106. package/tests/scripts/fixtures/legacy-shard-no-schema.json +50 -0
  107. package/tests/scripts/generate-digest.sh +180 -0
  108. package/tests/scripts/goldens/loop-state-breach.json +1 -0
  109. package/tests/scripts/goldens/loop-state-done.json +1 -0
  110. package/tests/scripts/goldens/somi-loop.json +1 -1
  111. package/tests/scripts/lib/adr-shape.mjs +41 -0
  112. package/tests/scripts/lib/checkpoint-gate.mjs +54 -0
  113. package/tests/scripts/lib/digest-marker-coupling.mjs +52 -0
  114. package/tests/scripts/lib/dispatch-reference-gate.mjs +112 -0
  115. package/tests/scripts/lib/multipass-dependence.mjs +192 -0
  116. package/tests/scripts/lib/multipass-source-identity.mjs +243 -0
  117. package/tests/scripts/lib/reference-pair.mjs +61 -0
  118. package/tests/scripts/lib/retirement-gate.mjs +167 -0
  119. package/tests/scripts/lib/shell-embedded-js.mjs +47 -0
  120. package/tests/scripts/lib/somi-mcp-client.mjs +102 -0
  121. package/tests/scripts/lib/somi-mcp-tests.mjs +401 -0
  122. package/tests/scripts/lib/somi-mcp-tool-schema.mjs +38 -0
  123. package/tests/scripts/retirement-gate.sh +287 -0
  124. package/tests/scripts/review-panel-seats.sh +32 -0
  125. package/tests/scripts/run.sh +184 -2
  126. package/tests/scripts/somi-agent-dispatch-contract.sh +195 -0
  127. package/tests/scripts/somi-dispatch.sh +366 -0
  128. package/tests/scripts/somi-mcp.sh +12 -0
@@ -0,0 +1,167 @@
1
+ #!/usr/bin/env node
2
+ // Retires the two-valued MAX/ECO model-tier vocabulary. Until this gate existed,
3
+ // scripts/validate.sh only ever asserted frontmatter VALUES (the thirteen frontmatter model
4
+ // assertions this replaces), never prose -- so a half-converted ruleset (frontmatter switched to
5
+ // `cost:`, prose still saying "the ECO tier") passed silently. This is the check that closes
6
+ // that gap: it fails the build on the retired vocabulary anywhere in the swept roots, in either
7
+ // form -- the retired pattern is "MAX tier" / "ECO tier" / "MAX->ECO", and this matches
8
+ // word-boundary rather than those three spellings only, because "zero hits" has to mean zero,
9
+ // not "zero of the forms we thought to enumerate".
10
+ //
11
+ // EXEMPT, and named here because the exit criteria requires every exemption to be explicit and
12
+ // justified, not just silently excluded:
13
+ // - scripts/lib/cost-model.mjs -- the mapping file itself; model names legitimately live here,
14
+ // it is the one place a repricing or a new model gets edited.
15
+ // - tests/scripts/cost-model.sh, tests/scripts/cost-ceiling.sh, tests/scripts/somi-dispatch.sh --
16
+ // unit guards for the resolver above and its CLI; their assertions are literally "does
17
+ // resolveModel(...) return the string 'haiku'" (or the CLI's JSON carry it), so the model
18
+ // names are test data proving the mapping, not tier vocabulary.
19
+ // - tests/evals/lib/boundary.mjs, tests/evals/lib/score.mjs -- historical comments about which
20
+ // specific Claude model variant graded a past eval run (an unrelated grading concern, not
21
+ // SoMi's own agent/command tier system).
22
+ // - tests/scripts/eval-runner.sh -- asserts a removed CLI flag's example value and a
23
+ // frontmatter validator's own recognized-model list; neither is the retired tier vocabulary,
24
+ // and one case (`MAX-PASSES-EXCEEDED`) is a loop-status string whose true positive is the
25
+ // word "PASSES", not "MAX" as a tier name.
26
+ // - CHANGELOG.md -- historical release record; docs/VERSIONING.md's migration-notes
27
+ // requirement for a MAJOR release means the retired words must stay quotable here.
28
+ // - tests/evals/results/ (whole directory) -- recorded eval-run transcripts (candidate model
29
+ // output from past runs); a transcript is data about what a model once said, not this
30
+ // repo's own vocabulary in force.
31
+ // - This file, and its own unit test (tests/scripts/retirement-gate.sh) -- the trap
32
+ // validate.sh:296-300 already documents for the tools-doctrine sweep applies here too: a
33
+ // detector's own pattern literals and the prose explaining them, and a test fixture built to
34
+ // contain the retired words on purpose, must all name those words to do their job. A gate
35
+ // that swept itself and its own test would fire on its own fix forever. Exempted by name,
36
+ // not by weakening the pattern.
37
+ //
38
+ // A frontmatter `model: opus` / `model: sonnet` / `model: haiku` line is exempt for the same
39
+ // reason cost-model.mjs is: Claude Code reads that field directly to select a subagent's model
40
+ // (no command passes a model to Task, so this is the only mechanism today), so it is a
41
+ // structural necessity, not vocabulary describing a tier -- by design, `cost:` carries the
42
+ // retired MAX/ECO meaning and `model:` stays the host's selection mechanism. The exemption is
43
+ // POSITIONAL: it applies only inside a file's own frontmatter, or a fenced code block teaching
44
+ // that same frontmatter shape, never to a bare `model: opus` line anywhere else in a file's body.
45
+
46
+ import { readFileSync, readdirSync, statSync } from 'node:fs';
47
+ import { join, relative, sep } from 'node:path';
48
+
49
+ const EXEMPT_FILES = new Set([
50
+ 'scripts/lib/cost-model.mjs',
51
+ 'tests/scripts/cost-model.sh',
52
+ 'tests/scripts/cost-ceiling.sh',
53
+ 'tests/scripts/somi-dispatch.sh',
54
+ 'tests/scripts/eval-runner.sh',
55
+ 'tests/evals/lib/boundary.mjs',
56
+ 'tests/evals/lib/score.mjs',
57
+ 'CHANGELOG.md',
58
+ 'tests/scripts/lib/retirement-gate.mjs',
59
+ 'tests/scripts/retirement-gate.sh',
60
+ ]);
61
+
62
+ const SKIP_DIR_NAMES = new Set(['.git', 'node_modules', '.somi', 'coverage']);
63
+ const SKIP_PATH_PREFIXES = ['tests/evals/results/'];
64
+
65
+ const TIER_PATTERN = /\bMAX\b|\bECO\b/;
66
+ // Case-insensitive: prose naturally capitalizes at a sentence start ("Opus front-loads the
67
+ // reasoning"), and "zero hits" has to mean zero of every spelling, not just the lowercase ones.
68
+ // TIER_PATTERN stays case-sensitive on purpose -- `max`/`eco` lowercase are ordinary English
69
+ // words (`max-wait-attempts`, "the maximum," "eco-friendly"), and case-folding it would fire on
70
+ // all of them.
71
+ const MODEL_PATTERN = /\b(opus|sonnet|haiku)\b/i;
72
+ const FRONTMATTER_MODEL_LINE = /^model:\s*(opus|sonnet|haiku)\s*$/;
73
+
74
+ function walk(root, out) {
75
+ let st;
76
+ try {
77
+ st = statSync(root);
78
+ } catch {
79
+ return; // a swept root that doesn't exist in this tree (e.g. a fixture missing tests/evals/)
80
+ }
81
+ if (st.isFile()) {
82
+ out.push(root);
83
+ return;
84
+ }
85
+ if (!st.isDirectory()) return;
86
+ for (const entry of readdirSync(root, { withFileTypes: true })) {
87
+ if (SKIP_DIR_NAMES.has(entry.name)) continue;
88
+ const p = join(root, entry.name);
89
+ if (entry.isDirectory()) walk(p, out);
90
+ else out.push(p);
91
+ }
92
+ }
93
+
94
+ const roots = process.argv.slice(2);
95
+ if (roots.length === 0) {
96
+ console.error('usage: retirement-gate.mjs <root...>');
97
+ process.exit(2);
98
+ }
99
+
100
+ // Relative paths (for the EXEMPT_FILES lookup and the printed locations) are resolved against
101
+ // the current working directory -- the repo root when validate.sh runs this, or a scratch
102
+ // fixture directory when the test script below points it there.
103
+ const base = process.cwd();
104
+
105
+ const files = [];
106
+ for (const r of roots) walk(r, files);
107
+
108
+ const problems = [];
109
+ for (const file of files) {
110
+ const rel = relative(base, file).split(sep).join('/');
111
+ if (EXEMPT_FILES.has(rel)) continue;
112
+ if (SKIP_PATH_PREFIXES.some((p) => rel.startsWith(p))) continue;
113
+ let text;
114
+ try {
115
+ text = readFileSync(file, 'utf8');
116
+ } catch {
117
+ continue; // not readable as a file (broken symlink, etc.) -- nothing to scan
118
+ }
119
+ // Binary-ish files (images, etc.) would false-positive on byte noise; skip anything with a
120
+ // NUL byte, which no text file in this sweep legitimately contains.
121
+ if (text.includes('\u0000')) continue;
122
+ const lines = text.split('\n');
123
+ // The bare `model:` exemption is POSITIONAL, not lexical: it applies only inside the file's own
124
+ // YAML frontmatter (the first line is exactly `---`, through the next line that is exactly
125
+ // `---`) or inside a fenced code block teaching that same frontmatter shape (docs/EXTENDING.md's
126
+ // and docs/COMMANDS.md's "Adding an agent/command" recipes). A `model: opus` sitting at column 0
127
+ // anywhere else -- a bullet, a table cell, an unrelated example -- is not exempt.
128
+ let frontmatterEnd = -1;
129
+ if (lines[0] === '---') {
130
+ const closeIdx = lines.indexOf('---', 1);
131
+ if (closeIdx !== -1) frontmatterEnd = closeIdx;
132
+ }
133
+ // CommonMark's own fencing rule, not a boolean toggle: a boolean flips on ANY run of backticks,
134
+ // so an odd-length run inside a fence (e.g. a four-backtick-fenced block whose content itself
135
+ // contains a three-backtick line) leaves it stuck open for the rest of the file. Track the
136
+ // opening marker's length instead and close only on a marker at least as long.
137
+ let fenceLen = 0;
138
+ lines.forEach((line, i) => {
139
+ const inFrontmatter = frontmatterEnd !== -1 && i <= frontmatterEnd;
140
+ const fenceMatch = line.match(/^\s*(`{3,})/);
141
+ if (fenceMatch) {
142
+ if (!fenceLen) fenceLen = fenceMatch[1].length;
143
+ else if (fenceMatch[1].length >= fenceLen) fenceLen = 0;
144
+ }
145
+ const inFence = fenceLen > 0;
146
+ if ((inFrontmatter || inFence) && FRONTMATTER_MODEL_LINE.test(line)) return; // structural, not vocabulary
147
+ if (TIER_PATTERN.test(line) || MODEL_PATTERN.test(line)) {
148
+ problems.push(`${rel}:${i + 1}: ${line.trim()}`);
149
+ }
150
+ });
151
+ }
152
+
153
+ // Exits 0 for every SCAN outcome (clean or stale) and signals purely through stdout content
154
+ // (`ok*` vs. anything else) — the same idiom digest-marker-coupling.mjs uses just above this
155
+ // block's caller in validate.sh. A non-zero exit on a scan result would die silently: validate.sh's
156
+ // caller assigns this process's stdout via command substitution under `set -euo pipefail`, and a
157
+ // plain assignment's exit status is the substitution's, so `errexit` would kill the script at the
158
+ // assignment before the `case` that prints the hit list ever runs. One idiom, one place that
159
+ // decides pass/fail (the `case` in validate.sh), rather than two disagreeing signals (exit code
160
+ // and stdout shape). `process.exit(2)` below is reserved for a usage error (missing argv), whose
161
+ // message goes to stderr via console.error and therefore survives the caller's `set -e` — a
162
+ // different case from a scan result, not a second exception to this rule.
163
+ if (problems.length) {
164
+ process.stdout.write(`STALE VOCABULARY (${problems.length} hit(s)):\n${problems.join('\n')}`);
165
+ } else {
166
+ process.stdout.write(`ok (0 stale-vocabulary hits across ${files.length} file(s))`);
167
+ }
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+ // Guards the `node -e "..."` blocks in the shell test scripts against their own quoting hazards.
3
+ //
4
+ // Inside a double-quoted shell string a BACKTICK is command substitution and a DOUBLE QUOTE ends
5
+ // the program. Both have bitten: a comment reading `-- the same "measured the wrong thing" shape`
6
+ // terminated the string, node received mangled source and exited with no output on either stream,
7
+ // and the assertion reported `got ''`. A backticked code span in the file's own comment idiom --
8
+ // which is how every other comment here is written -- executes the span as a command; one such
9
+ // span in this repo is `bash tests/scripts/evals-fixtures.sh --update-manifest`, which would
10
+ // recursively invoke the guard's own manifest path.
11
+ //
12
+ // The durable fix is to keep programs OUT of shell strings (see lib/adr-shape.mjs and
13
+ // lib/reference-pair.mjs). This catches the ones still inline, so the class cannot reopen quietly.
14
+ //
15
+ // SCOPE, deliberately narrow. Inside a block, the first unescaped `"` IS the terminator -- that is
16
+ // what the shell does, and a syntactic scan cannot tell an intended terminator from an accidental
17
+ // one. What it CAN tell:
18
+ // - a backtick anywhere inside a block: always command substitution, never intended
19
+ // - a `"` inside a JS COMMENT line: always accidental, since a comment cannot be the terminator
20
+ // Both are real instances that shipped. A broader rule flagged 50 lines of correct code, and a
21
+ // guard that reports 50 findings reports none.
22
+
23
+ import { readFileSync } from 'node:fs';
24
+
25
+ const problems = [];
26
+ for (const file of process.argv.slice(2)) {
27
+ const lines = readFileSync(file, 'utf8').split('\n');
28
+ let inBlock = false;
29
+ lines.forEach((line, n) => {
30
+ if (!inBlock) {
31
+ const at = line.search(/node (--input-type=module )?-e "/);
32
+ if (at === -1) return;
33
+ const after = line.slice(line.indexOf('-e "', at) + 4);
34
+ if (!/(^|[^\\])"/.test(after)) inBlock = true; // opened and left open
35
+ return;
36
+ }
37
+ const trimmed = line.trim();
38
+ if (line.includes('`')) {
39
+ problems.push(`${file}:${n + 1}: backtick inside a node -e block -- the shell executes it: ${trimmed.slice(0, 64)}`);
40
+ }
41
+ if (trimmed.startsWith('//') && /"/.test(line)) {
42
+ problems.push(`${file}:${n + 1}: double quote in a comment inside a node -e block -- it ends the program: ${trimmed.slice(0, 64)}`);
43
+ }
44
+ if (/(^|[^\\])"/.test(line)) inBlock = false; // the terminator, wherever it falls
45
+ });
46
+ }
47
+ process.stdout.write(problems.length ? problems.join('\n') : 'ok');
@@ -0,0 +1,102 @@
1
+ // somi-mcp-client.mjs — a minimal MCP CLIENT used only to test scripts/somi-mcp.mjs over real
2
+ // stdio: spawns the server, speaks newline-delimited JSON-RPC 2.0 in both directions (request /
3
+ // response correlation, plus answering a SERVER-initiated request such as `roots/list`, the same
4
+ // as a real MCP client would), and records every line for scenarios to inspect directly.
5
+
6
+ import { spawn } from 'node:child_process';
7
+ import { createInterface } from 'node:readline';
8
+
9
+ export class McpClient {
10
+ constructor(serverPath, { env } = {}) {
11
+ this.child = spawn(process.execPath, [serverPath], {
12
+ env: { ...process.env, ...env },
13
+ stdio: ['pipe', 'pipe', 'pipe'],
14
+ });
15
+ this.nextId = 1;
16
+ this.pending = new Map(); // id -> {resolve, reject}
17
+ this.messages = []; // every parsed line the server sent, in arrival order
18
+ this.rawLines = []; // every raw line, parsed or not (parse-error scenarios read this)
19
+ this.stderr = '';
20
+ this.rootsHandler = null; // async () => string[] -- set by a scenario to answer roots/list
21
+ this.child.stderr.on('data', (d) => { this.stderr += d.toString(); });
22
+ this.rl = createInterface({ input: this.child.stdout, terminal: false });
23
+ this.rl.on('line', (line) => this._onLine(line));
24
+ }
25
+
26
+ _onLine(rawLine) {
27
+ if (!rawLine.trim()) return;
28
+ this.rawLines.push(rawLine);
29
+ let msg;
30
+ try {
31
+ msg = JSON.parse(rawLine);
32
+ } catch {
33
+ return;
34
+ }
35
+ this.messages.push(msg);
36
+ if (msg.method === undefined && (msg.result !== undefined || msg.error !== undefined)) {
37
+ const p = this.pending.get(msg.id);
38
+ if (p) {
39
+ this.pending.delete(msg.id);
40
+ if (msg.error) p.reject(new Error(msg.error.message));
41
+ else p.resolve(msg.result);
42
+ }
43
+ return;
44
+ }
45
+ if (msg.method === 'roots/list') {
46
+ Promise.resolve(this.rootsHandler ? this.rootsHandler() : [])
47
+ .then((roots) => {
48
+ // A scenario's rootsHandler returns either a bare path (wrapped as a file:// URI here,
49
+ // the common case) or a ready-made root object (e.g. {uri: 'not-a-file-uri'} or a
50
+ // pre-encoded file:// URI) when it needs to control the URI itself -- non-file schemes,
51
+ // percent-encoding, or more than one root.
52
+ this._write({
53
+ jsonrpc: '2.0',
54
+ id: msg.id,
55
+ result: { roots: roots.map((r) => (typeof r === 'string' ? { uri: `file://${r}` } : r)) },
56
+ });
57
+ });
58
+ }
59
+ }
60
+
61
+ _write(obj) {
62
+ this.child.stdin.write(`${JSON.stringify(obj)}\n`);
63
+ }
64
+
65
+ writeRaw(text) {
66
+ this.child.stdin.write(text.endsWith('\n') ? text : `${text}\n`);
67
+ }
68
+
69
+ request(method, params) {
70
+ const id = this.nextId++;
71
+ return new Promise((resolve, reject) => {
72
+ this.pending.set(id, { resolve, reject });
73
+ this._write({ jsonrpc: '2.0', id, method, params });
74
+ });
75
+ }
76
+
77
+ notify(method, params) {
78
+ this._write({ jsonrpc: '2.0', method, params });
79
+ }
80
+
81
+ async waitFor(predicate, timeoutMs = 3000) {
82
+ const start = Date.now();
83
+ for (;;) {
84
+ const hit = this.messages.find(predicate);
85
+ if (hit) return hit;
86
+ if (Date.now() - start > timeoutMs) throw new Error('timeout waiting for a matching message');
87
+ await new Promise((r) => setTimeout(r, 20));
88
+ }
89
+ }
90
+
91
+ async initialize(capabilities = {}) {
92
+ const result = await this.request('initialize', { protocolVersion: '2024-11-05', capabilities });
93
+ this.notify('notifications/initialized');
94
+ return result;
95
+ }
96
+
97
+ close() {
98
+ try { this.child.stdin.end(); } catch { /* already closed */ }
99
+ this.rl.close();
100
+ this.child.kill();
101
+ }
102
+ }