@skathio/somi 4.0.1 → 4.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.
Files changed (151) hide show
  1. package/.claude/settings.json +1 -1
  2. package/.claude-plugin/marketplace.json +1 -1
  3. package/.claude-plugin/plugin.json +1 -1
  4. package/.copilot-extension/extension.json +1 -1
  5. package/.copilot-extension/marketplace.json +1 -1
  6. package/README.md +5 -4
  7. package/VERSION +1 -1
  8. package/agents/somi-coder.md +4 -228
  9. package/agents/somi-designer.md +4 -160
  10. package/agents/somi-discovery-analyst.md +4 -276
  11. package/agents/somi-flow.md +47 -0
  12. package/agents/somi-general.md +36 -0
  13. package/agents/somi-planner.md +4 -341
  14. package/agents/somi-reviewer.md +4 -199
  15. package/agents/somi.md +81 -253
  16. package/commands/adopt.md +6 -84
  17. package/commands/architecture-review.md +11 -86
  18. package/commands/atlas.md +10 -25
  19. package/commands/code-loop.md +10 -221
  20. package/commands/code-parallel.md +10 -151
  21. package/commands/code.md +9 -157
  22. package/commands/debug.md +9 -131
  23. package/commands/design.md +9 -160
  24. package/commands/discover.md +9 -194
  25. package/commands/impact.md +9 -25
  26. package/commands/incident.md +9 -39
  27. package/commands/plan-loop.md +9 -181
  28. package/commands/plan.md +9 -244
  29. package/commands/pr.md +10 -25
  30. package/commands/refactor-design.md +11 -89
  31. package/commands/refactor.md +11 -50
  32. package/commands/release-readiness.md +11 -70
  33. package/commands/review-panel.md +10 -141
  34. package/commands/review.md +11 -181
  35. package/commands/security-review.md +11 -75
  36. package/commands/ship-loop.md +9 -260
  37. package/commands/ship.md +9 -115
  38. package/commands/somi-config.md +11 -130
  39. package/commands/test-strategy.md +11 -75
  40. package/commands/upgrade.md +9 -72
  41. package/hooks/hooks.json +1 -1
  42. package/hooks/lib/common.mjs +8 -5
  43. package/hooks/pre-tool/block-dangerous-bash.mjs +1 -1
  44. package/hooks/pre-tool/block-secret-writes.mjs +5 -7
  45. package/hooks/pre-tool/guard-protected-paths.mjs +54 -34
  46. package/package.json +1 -1
  47. package/scripts/lib/cost-defaults.mjs +2 -0
  48. package/scripts/lib/escalation-facts.mjs +146 -0
  49. package/scripts/lib/escalation.mjs +129 -0
  50. package/scripts/lib/findings-ledger.mjs +241 -0
  51. package/scripts/lib/install-text.mjs +97 -0
  52. package/scripts/lib/loop-caps.mjs +140 -0
  53. package/scripts/lib/loop-diff.mjs +12 -70
  54. package/scripts/lib/loop-engine.mjs +226 -0
  55. package/scripts/lib/loop-escalate.mjs +49 -0
  56. package/scripts/lib/loop-exit.mjs +47 -0
  57. package/scripts/lib/loop-notes-compact.mjs +72 -0
  58. package/scripts/lib/loop-notes.mjs +278 -0
  59. package/scripts/lib/loop-review.mjs +355 -12
  60. package/scripts/lib/loop-state.mjs +44 -0
  61. package/scripts/lib/loop-step-close.mjs +75 -0
  62. package/scripts/lib/loop-step-kit.mjs +179 -0
  63. package/scripts/lib/loop-step-review.mjs +140 -0
  64. package/scripts/lib/loop-step-tool.mjs +89 -0
  65. package/scripts/lib/loop-step.mjs +301 -0
  66. package/scripts/lib/mcp-project-root.mjs +18 -7
  67. package/scripts/lib/path-facts.mjs +187 -0
  68. package/scripts/lib/path-safety.mjs +171 -0
  69. package/scripts/lib/run-card.mjs +73 -0
  70. package/scripts/size-budget-overrides.json +5 -13
  71. package/scripts/somi-card.mjs +39 -0
  72. package/scripts/somi-findings.mjs +56 -271
  73. package/scripts/somi-loop.mjs +77 -447
  74. package/scripts/somi-mcp.mjs +26 -95
  75. package/scripts/validate.sh +75 -57
  76. package/skills/flow-adopt/SKILL.md +92 -0
  77. package/skills/flow-architecture-review/SKILL.md +94 -0
  78. package/skills/flow-atlas/SKILL.md +34 -0
  79. package/skills/flow-code/SKILL.md +167 -0
  80. package/skills/flow-code-loop/SKILL.md +263 -0
  81. package/skills/flow-code-parallel/SKILL.md +160 -0
  82. package/skills/flow-debug/SKILL.md +141 -0
  83. package/skills/flow-design/SKILL.md +170 -0
  84. package/skills/flow-discover/SKILL.md +204 -0
  85. package/skills/flow-impact/SKILL.md +35 -0
  86. package/skills/flow-incident/SKILL.md +49 -0
  87. package/skills/flow-plan/SKILL.md +254 -0
  88. package/skills/flow-plan-loop/SKILL.md +254 -0
  89. package/skills/flow-pr/SKILL.md +34 -0
  90. package/skills/flow-refactor/SKILL.md +58 -0
  91. package/skills/flow-refactor-design/SKILL.md +97 -0
  92. package/skills/flow-release-readiness/SKILL.md +82 -0
  93. package/skills/flow-review/SKILL.md +193 -0
  94. package/skills/flow-review-panel/SKILL.md +154 -0
  95. package/skills/flow-security-review/SKILL.md +83 -0
  96. package/skills/flow-ship/SKILL.md +125 -0
  97. package/skills/flow-ship-loop/SKILL.md +274 -0
  98. package/skills/flow-somi-config/SKILL.md +142 -0
  99. package/skills/flow-status/SKILL.md +43 -0
  100. package/skills/flow-test-strategy/SKILL.md +83 -0
  101. package/skills/flow-upgrade/SKILL.md +82 -0
  102. package/skills/role-coder/SKILL.md +247 -0
  103. package/skills/role-designer/SKILL.md +172 -0
  104. package/skills/role-discovery-analyst/SKILL.md +288 -0
  105. package/skills/role-planner/SKILL.md +353 -0
  106. package/skills/role-reviewer/SKILL.md +218 -0
  107. package/skills/somi-checkpoint/SKILL.md +95 -0
  108. package/skills/somi-dispatch/SKILL.md +14 -14
  109. package/skills/somi-routing/SKILL.md +6 -2
  110. package/tests/hooks/cases/block-secret-writes.json +6 -1
  111. package/tests/hooks/cases/guard-protected-paths.json +44 -2
  112. package/tests/hooks/run.sh +21 -0
  113. package/tests/scripts/checkpoint-gate.sh +2 -2
  114. package/tests/scripts/cost-defaults.sh +2 -0
  115. package/tests/scripts/dispatch-line-gate.sh +4 -4
  116. package/tests/scripts/dispatch-reference-gate.sh +14 -14
  117. package/tests/scripts/escalation.sh +409 -0
  118. package/tests/scripts/eval-runner.sh +8 -7
  119. package/tests/scripts/fact-sheet.sh +296 -0
  120. package/tests/scripts/goldens/somi-loop.json +2 -2
  121. package/tests/scripts/lib/dispatch-reference-gate.mjs +14 -5
  122. package/tests/scripts/lib/escalation-facts-tests.mjs +140 -0
  123. package/tests/scripts/lib/escalation-tests.mjs +154 -0
  124. package/tests/scripts/lib/findings-ledger-tests.mjs +118 -0
  125. package/tests/scripts/lib/loop-engine-tests.mjs +287 -0
  126. package/tests/scripts/lib/loop-escalate-tests.mjs +356 -0
  127. package/tests/scripts/lib/loop-flow-gate.mjs +173 -0
  128. package/tests/scripts/lib/loop-notes-tests.mjs +371 -0
  129. package/tests/scripts/lib/loop-step-cli-tests.mjs +141 -0
  130. package/tests/scripts/lib/loop-step-close-tests.mjs +351 -0
  131. package/tests/scripts/lib/loop-step-lenient-tests.mjs +114 -0
  132. package/tests/scripts/lib/loop-step-state-tests.mjs +127 -0
  133. package/tests/scripts/lib/loop-step-tests.mjs +499 -0
  134. package/tests/scripts/lib/loop-step-unwritten-tests.mjs +55 -0
  135. package/tests/scripts/lib/path-facts-tests.mjs +198 -0
  136. package/tests/scripts/lib/path-safety-tests.mjs +201 -0
  137. package/tests/scripts/lib/run-suites.mjs +139 -0
  138. package/tests/scripts/lib/sizing-score-tests.mjs +210 -0
  139. package/tests/scripts/lib/sizing-set-tests.mjs +131 -0
  140. package/tests/scripts/lib/somi-mcp-loop-tests.mjs +226 -0
  141. package/tests/scripts/lib/somi-mcp-tests.mjs +21 -1
  142. package/tests/scripts/loop-engine.sh +22 -0
  143. package/tests/scripts/loop-flow-gate.sh +11 -0
  144. package/tests/scripts/review-panel-seats.sh +4 -4
  145. package/tests/scripts/run-card.sh +57 -0
  146. package/tests/scripts/run-suites.sh +74 -0
  147. package/tests/scripts/run.sh +11 -0
  148. package/tests/scripts/size-tier.sh +3 -3
  149. package/tests/scripts/somi-agent-dispatch-contract.sh +23 -3
  150. package/tests/scripts/somi-mcp.sh +1 -0
  151. package/tests/scripts/suite-plan.json +20 -0
@@ -1,42 +1,29 @@
1
1
  // somi-findings.mjs — the findings ledger: identity and lifecycle for review findings.
2
2
  //
3
- // Zero-dependency: stdlib only (node:fs, node:path). No jq, no bash. Behavior-preserving
4
- // — exit codes and stdout JSON shapes are frozen and reproduced exactly; see the bash
5
- // original's header comment for the full rationale (finding identity/lifecycle, the
6
- // consecutive-vs-cross-run recurrence distinction, why line numbers are excluded from
7
- // the locus).
8
- //
9
- // Ledger: .somi/reviews/<slug>/findings.json under the project root — committed with
10
- // the other review artifacts (it is the machine view; the markdown review file stays
11
- // the human view).
12
- //
13
- // Subcommands:
14
- // record --slug S [--review FILE] [--run ID] [--pass N]
15
- // stdin: JSON array [{file, symbol, title, severity, confidence}, …]
16
- // Upserts each finding: new locus → new F-<n>; known OPEN locus → appends a
17
- // sighting. Prints one JSON line per finding with {id, state, recurring_consecutive,
18
- // recurring_cross_run}. Exit 5 if ANY finding was recurring_consecutive (checked
19
- // after processing ALL findings) — the caller decides what to do with it.
20
- // resolve --slug S --id F-3 --status fixed|accepted|wontfix [--by REVIEW]
21
- // reopen --slug S --id F-3 [--by REVIEW]
22
- // open --slug S → JSON array of open findings
23
- // get --slug S --id F-3 → one finding
24
- //
25
- // Locus matching: same file + same symbol (case-insensitive) + same normalized title
26
- // (lowercased, non-alphanumerics collapsed, first 8 words). Line numbers are
27
- // deliberately NOT part of the locus — lines drift between passes.
3
+ // Zero-dependency: stdlib only. A thin CLI: it parses arguments, reads the project root, and reads and parses
4
+ // stdin (the trust boundary of the shell path); every handler lives in lib/findings-ledger.mjs and returns
5
+ // {lines, code, message}, which is printed here. Exit codes and stdout JSON shapes are frozen; see the bash
6
+ // original's header comment for the rationale (finding identity/lifecycle, consecutive-vs-cross-run
7
+ // recurrence, why line numbers are excluded from the locus).
28
8
  //
9
+ // Ledger: .somi/reviews/<slug>/findings.json under the project root, committed with the other review artifacts.
10
+ // Subcommands (all take --slug S):
11
+ // record [--review FILE] [--run ID] [--pass N] stdin: JSON array [{file, symbol, title, severity, confidence}, …]
12
+ // Upserts each finding (new locus → new F-<n>; known OPEN locus → appends a sighting); one JSON line per
13
+ // finding. Exit 5 if ANY finding recurred in consecutive passes, judged after all are processed.
14
+ // resolve --id F-3 --status fixed|accepted|wontfix [--by REVIEW]
15
+ // reopen --id F-3 [--by REVIEW]
16
+ // open → JSON array of open findings get --id F-3 → one finding
29
17
  // Exit codes: 0 ok · 5 consecutive recurrence detected (record only) · 64 error.
30
18
  // Tested by tests/scripts/run.sh (wired into scripts/validate.sh / CI).
31
19
 
32
20
  import fs from 'node:fs';
33
- import path from 'node:path';
21
+ import { PROG, getFinding, openFindings, recordFindings, reopenFinding, resolveFinding } from './lib/findings-ledger.mjs';
34
22
 
35
- const PROG = 'somi-findings';
23
+ const FLAGS = { '--slug': 'slug', '--review': 'review', '--run': 'run', '--pass': 'pass', '--id': 'id', '--status': 'status', '--by': 'by' };
36
24
 
37
- // Thrown to unwind to the top-level handler, which sets process.exitCode and lets Node
38
- // exit naturally — avoids process.exit()'s risk of truncating buffered stdout/stderr
39
- // writes on a pipe. Same idiom as somi-loop.mjs.
25
+ // Thrown to unwind to the top-level handler, which sets process.exitCode and lets Node exit naturally —
26
+ // avoids process.exit()'s risk of truncating buffered stdout/stderr writes on a pipe.
40
27
  class ExitSignal extends Error {
41
28
  constructor(code) {
42
29
  super(`exit ${code}`);
@@ -55,253 +42,51 @@ function projectRoot() {
55
42
  return b;
56
43
  }
57
44
 
58
- function nowDateUtc() {
59
- // `date -u +%Y-%m-%d` — bare date, no time component (findings' seen[].date).
60
- return new Date().toISOString().slice(0, 10);
61
- }
62
-
63
- // Mirrors jq's `//` alternative operator at the JSON-value level: substitutes the
64
- // fallback only when the left side is `null`/missing or `false` — NOT for other
65
- // falsy values like `""` or `0`, which jq treats as present. Used wherever the bash
66
- // script keeps a raw JSON value (locus/severity/confidence on a newly created finding).
67
- function orElse(v, fallback) {
68
- return v === null || v === undefined || v === false ? fallback : v;
69
- }
70
-
71
- // Mirrors `jq -r '<expr> // empty'` captured into a bash variable: same null/false
72
- // substitution as orElse, then stringified (bash captures everything as text) — used
73
- // wherever the bash script tests `[[ -n "$var" ]]` or concatenates into the locus key.
74
- function rawStr(v) {
75
- const x = orElse(v, '');
76
- return x === '' ? '' : String(x);
77
- }
78
-
79
- // normalize_title() — bash pipeline: `tr '[:upper:]' '[:lower:]'` (byte-wise, ASCII-only —
80
- // it only maps the 26 ASCII uppercase bytes; any multi-byte UTF-8 sequence passes through
81
- // untouched) -> `tr -cs 'a-z0-9' ' '` (every maximal run of non-alphanumerics — including a
82
- // leading or trailing run — collapses to ONE space; this is what then eats those untouched
83
- // UTF-8 bytes) -> awk takes fields 1-8 (awk's default field-splitting ignores leading/
84
- // trailing whitespace and splits on whitespace runs). By the time the tr step is done,
85
- // the only characters left in the string are lowercase alphanumerics and single-space
86
- // separators (with at most one leading and one trailing space) — so the awk step's only
87
- // remaining job is to drop that leading/trailing space and truncate to 8 fields, which
88
- // is exactly what trim + split + slice does below — PROVIDED the lowercasing step is also
89
- // byte-wise ASCII-only. JS's `String.prototype.toLowerCase()` is Unicode-aware (e.g. U+0130
90
- // İ -> "i" + combining dot above), which can *introduce* a fresh ASCII letter that bash's
91
- // byte-wise `tr` would never produce (bash leaves İ's UTF-8 bytes alone; the following
92
- // `tr -cs 'a-z0-9' ' '` step then discards all of them as non-alphanumeric). So the
93
- // lowercasing below only maps `A`-`Z`, mirroring `tr '[:upper:]' '[:lower:]'` exactly.
94
- // Verified against six normalize_title edge-case goldens (empty,
95
- // single-word, >8-word, leading/trailing whitespace, multi-space, punctuation) plus
96
- // adversarial Unicode probes (café, İstanbul).
97
- function normalizeTitle(title) {
98
- const lowered = title.replace(/[A-Z]/g, (c) => c.toLowerCase());
99
- const squeezed = lowered.replace(/[^a-z0-9]+/g, ' ').trim();
100
- if (squeezed === '') return '';
101
- return squeezed.split(/\s+/).slice(0, 8).join(' ');
102
- }
103
-
104
- function ensureLedger(ledgerDir, ledgerPath) {
105
- fs.mkdirSync(ledgerDir, { recursive: true });
106
- if (!fs.existsSync(ledgerPath)) {
107
- // Byte-for-byte the bash seed: `printf '{"next_id": 1, "findings": []}\n' > "$LEDGER"` —
108
- // a literal, NOT jq output (note the space after each colon but no other jq-pretty
109
- // formatting). Immediately superseded by the jq-pretty form on the first record/resolve/
110
- // reopen that touches this ledger; only matters at rest if `open`/`get` is called first.
111
- fs.writeFileSync(ledgerPath, '{"next_id": 1, "findings": []}\n');
45
+ function readFindingsFromStdin() {
46
+ let text;
47
+ try {
48
+ text = fs.readFileSync(0, 'utf8');
49
+ } catch {
50
+ // Any OS-level read failure — e.g. Windows raises EAGAIN for a synchronous read of a TTY console handle
51
+ // (no piped input attached) rather than blocking — degrades to the same clean die() as every bad input.
52
+ die('failed to read stdin — findings must be piped in as a JSON array');
112
53
  }
113
- }
114
-
115
- function loadLedger(ledgerPath) {
116
- return JSON.parse(fs.readFileSync(ledgerPath, 'utf8'));
117
- }
118
-
119
- function saveLedger(ledgerPath, ledger) {
120
- // Mirror bash's `tmp="$(mktemp)"; jq ... "$LEDGER" > "$tmp" && mv "$tmp" "$LEDGER"`:
121
- // pretty 2-space + trailing newline (jq's default pretty-print, verified byte-identical
122
- // against JSON.stringify(ledger, null, 2) + '\n'), written to a temp file in
123
- // the SAME directory as the target and renamed into place so the write is atomic and the
124
- // rename never crosses a filesystem boundary.
125
- const tmpPath = `${ledgerPath}.tmp`;
126
- fs.writeFileSync(tmpPath, JSON.stringify(ledger, null, 2) + '\n');
127
- fs.renameSync(tmpPath, ledgerPath);
54
+ let input;
55
+ try {
56
+ input = JSON.parse(text);
57
+ } catch {
58
+ die('stdin must be a JSON array of findings');
59
+ }
60
+ if (!Array.isArray(input)) die('stdin must be a JSON array of findings');
61
+ return input;
128
62
  }
129
63
 
130
64
  function main() {
131
- const argv = process.argv.slice(2);
132
- const CMD = argv[0] || '';
133
- let rest = argv.slice(1);
134
-
135
- let SLUG = '';
136
- let REVIEW = '';
137
- let RUN = '';
138
- let PASS = 0;
139
- let ID = '';
140
- let STATUS = '';
141
- let BY = '';
142
-
143
- while (rest.length > 0) {
144
- const a = rest[0];
145
- switch (a) {
146
- case '--slug': SLUG = rest[1]; rest = rest.slice(2); break;
147
- case '--review': REVIEW = rest[1]; rest = rest.slice(2); break;
148
- case '--run': RUN = rest[1]; rest = rest.slice(2); break;
149
- case '--pass': PASS = Number(rest[1]); rest = rest.slice(2); break;
150
- case '--id': ID = rest[1]; rest = rest.slice(2); break;
151
- case '--status': STATUS = rest[1]; rest = rest.slice(2); break;
152
- case '--by': BY = rest[1]; rest = rest.slice(2); break;
153
- default: die(`unknown argument: ${a}`);
154
- }
65
+ const [cmd = '', ...argv] = process.argv.slice(2);
66
+ const a = { slug: '', review: '', run: '', pass: 0, id: '', status: '', by: '' };
67
+ for (let rest = argv; rest.length > 0; rest = rest.slice(2)) {
68
+ if (!Object.hasOwn(FLAGS, rest[0])) die(`unknown argument: ${rest[0]}`);
69
+ const key = FLAGS[rest[0]];
70
+ a[key] = key === 'pass' ? Number(rest[1]) : rest[1];
155
71
  }
156
72
 
157
- if (!CMD) die('usage: somi-findings.mjs <record|resolve|reopen|open|get> --slug <slug> …');
158
- if (!SLUG) die('--slug is required');
159
-
160
- const root = projectRoot();
161
- const LEDGER_DIR = path.join(root, '.somi', 'reviews', SLUG);
162
- const LEDGER = path.join(LEDGER_DIR, 'findings.json');
163
-
164
- switch (CMD) {
165
- case 'record': {
166
- ensureLedger(LEDGER_DIR, LEDGER);
167
-
168
- let stdinText;
169
- try {
170
- stdinText = fs.readFileSync(0, 'utf8');
171
- } catch {
172
- // Any OS-level read failure — e.g. Windows raises EAGAIN for a synchronous read of
173
- // a TTY console handle (no piped input attached) rather than blocking, the POSIX
174
- // behavior — should degrade to the same clean die() exit every other bad-input path
175
- // here uses, not an uncaught exception.
176
- die('failed to read stdin — findings must be piped in as a JSON array');
177
- }
178
- let input;
179
- try {
180
- input = JSON.parse(stdinText);
181
- } catch {
182
- die('stdin must be a JSON array of findings');
183
- }
184
- if (!Array.isArray(input)) die('stdin must be a JSON array of findings');
185
-
186
- const ledger = loadLedger(LEDGER);
187
- const now = nowDateUtc();
188
- let breaker = false;
189
-
190
- for (let i = 0; i < input.length; i++) {
191
- const f = input[i] ?? {};
192
- const file = rawStr(f.file);
193
- // ASCII-only lowercase — same reasoning as normalizeTitle above: bash uses byte-wise
194
- // `tr '[:upper:]' '[:lower:]'` here too, so Unicode-aware toLowerCase would diverge.
195
- const symbol = rawStr(f.symbol).replace(/[A-Z]/g, (c) => c.toLowerCase());
196
- const title = rawStr(f.title);
197
- if (!file || !title) die(`finding ${i} needs at least {file, title}`);
198
- const key = `${file}|${symbol}|${normalizeTitle(title)}`;
199
-
200
- // Known open locus: recurrence classification BEFORE the sighting is appended.
201
- const existing = ledger.findings.find((x) => x.key === key && x.status === 'open');
202
-
203
- if (existing) {
204
- const recurringConsecutive = existing.seen.some((s) => s.run === RUN && s.pass === PASS - 1);
205
- const recurringCross = existing.seen.some((s) => s.run !== RUN);
206
- existing.seen.push({ review: REVIEW, run: RUN, pass: PASS, date: now });
207
- saveLedger(LEDGER, ledger);
208
- if (recurringConsecutive) breaker = true;
209
- console.log(JSON.stringify({
210
- id: existing.id,
211
- state: 'known',
212
- recurring_consecutive: recurringConsecutive,
213
- recurring_cross_run: recurringCross,
214
- }));
215
- } else {
216
- const newId = `F-${ledger.next_id}`;
217
- ledger.next_id += 1;
218
- ledger.findings.push({
219
- id: newId,
220
- key,
221
- locus: { file: f.file, symbol: orElse(f.symbol, '') },
222
- title: f.title,
223
- severity: orElse(f.severity, 'Minor'),
224
- confidence: orElse(f.confidence, 'Medium'),
225
- status: 'open',
226
- introduced_by: REVIEW,
227
- resolved_by: null,
228
- seen: [{ review: REVIEW, run: RUN, pass: PASS, date: now }],
229
- });
230
- saveLedger(LEDGER, ledger);
231
- console.log(JSON.stringify({
232
- id: newId,
233
- state: 'new',
234
- recurring_consecutive: false,
235
- recurring_cross_run: false,
236
- }));
237
- }
238
- }
239
-
240
- if (breaker) process.exitCode = 5;
241
- break;
242
- }
243
-
244
- case 'resolve': {
245
- ensureLedger(LEDGER_DIR, LEDGER);
246
- if (!ID || !STATUS) die('resolve requires --id and --status');
247
- if (!['fixed', 'accepted', 'wontfix'].includes(STATUS)) {
248
- die('--status must be fixed|accepted|wontfix');
249
- }
250
- const ledger = loadLedger(LEDGER);
251
- const found = ledger.findings.find((x) => x.id === ID);
252
- if (found) {
253
- found.status = STATUS;
254
- found.resolved_by = BY;
255
- saveLedger(LEDGER, ledger);
256
- console.log(JSON.stringify({ id: found.id, status: found.status, resolved_by: found.resolved_by }));
257
- }
258
- break;
259
- }
260
-
261
- case 'reopen': {
262
- ensureLedger(LEDGER_DIR, LEDGER);
263
- if (!ID) die('reopen requires --id');
264
- const ledger = loadLedger(LEDGER);
265
- const found = ledger.findings.find((x) => x.id === ID);
266
- if (found) {
267
- found.status = 'open';
268
- found.resolved_by = null;
269
- found.reopened_by = BY;
270
- saveLedger(LEDGER, ledger);
271
- console.log(JSON.stringify({ id: found.id, status: found.status }));
272
- }
273
- break;
274
- }
275
-
276
- case 'open': {
277
- ensureLedger(LEDGER_DIR, LEDGER);
278
- const ledger = loadLedger(LEDGER);
279
- const openFindings = ledger.findings
280
- .filter((x) => x.status === 'open')
281
- .map((x) => ({
282
- id: x.id,
283
- locus: x.locus,
284
- title: x.title,
285
- severity: x.severity,
286
- confidence: x.confidence,
287
- introduced_by: x.introduced_by,
288
- }));
289
- console.log(JSON.stringify(openFindings, null, 2));
290
- break;
291
- }
292
-
293
- case 'get': {
294
- ensureLedger(LEDGER_DIR, LEDGER);
295
- if (!ID) die('get requires --id');
296
- const ledger = loadLedger(LEDGER);
297
- const found = ledger.findings.find((x) => x.id === ID);
298
- if (found) console.log(JSON.stringify(found, null, 2));
299
- break;
300
- }
301
-
302
- default:
303
- die(`unknown subcommand: ${CMD}`);
304
- }
73
+ if (!cmd) die('usage: somi-findings.mjs <record|resolve|reopen|open|get> --slug <slug> …');
74
+ if (!a.slug) die('--slug is required');
75
+
76
+ const call = { root: projectRoot(), ...a };
77
+ const handlers = {
78
+ record: () => recordFindings({ ...call, input: readFindingsFromStdin() }),
79
+ resolve: () => resolveFinding(call),
80
+ reopen: () => reopenFinding(call),
81
+ open: () => openFindings(call),
82
+ get: () => getFinding(call),
83
+ };
84
+ if (!Object.hasOwn(handlers, cmd)) die(`unknown subcommand: ${cmd}`);
85
+
86
+ const result = handlers[cmd]();
87
+ for (const line of result.lines) console.log(line);
88
+ if (result.message) process.stderr.write(`${result.message}\n`);
89
+ process.exitCode = result.code;
305
90
  }
306
91
 
307
92
  try {