@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.
- package/.claude/settings.json +1 -1
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.copilot-extension/extension.json +1 -1
- package/.copilot-extension/marketplace.json +1 -1
- package/README.md +5 -4
- package/VERSION +1 -1
- package/agents/somi-coder.md +4 -228
- package/agents/somi-designer.md +4 -160
- package/agents/somi-discovery-analyst.md +4 -276
- package/agents/somi-flow.md +47 -0
- package/agents/somi-general.md +36 -0
- package/agents/somi-planner.md +4 -341
- package/agents/somi-reviewer.md +4 -199
- package/agents/somi.md +81 -253
- package/commands/adopt.md +6 -84
- package/commands/architecture-review.md +11 -86
- package/commands/atlas.md +10 -25
- package/commands/code-loop.md +10 -221
- package/commands/code-parallel.md +10 -151
- package/commands/code.md +9 -157
- package/commands/debug.md +9 -131
- package/commands/design.md +9 -160
- package/commands/discover.md +9 -194
- package/commands/impact.md +9 -25
- package/commands/incident.md +9 -39
- package/commands/plan-loop.md +9 -181
- package/commands/plan.md +9 -244
- package/commands/pr.md +10 -25
- package/commands/refactor-design.md +11 -89
- package/commands/refactor.md +11 -50
- package/commands/release-readiness.md +11 -70
- package/commands/review-panel.md +10 -141
- package/commands/review.md +11 -181
- package/commands/security-review.md +11 -75
- package/commands/ship-loop.md +9 -260
- package/commands/ship.md +9 -115
- package/commands/somi-config.md +11 -130
- package/commands/test-strategy.md +11 -75
- package/commands/upgrade.md +9 -72
- package/hooks/hooks.json +1 -1
- package/hooks/lib/common.mjs +8 -5
- package/hooks/pre-tool/block-dangerous-bash.mjs +1 -1
- package/hooks/pre-tool/block-secret-writes.mjs +5 -7
- package/hooks/pre-tool/guard-protected-paths.mjs +54 -34
- package/package.json +1 -1
- package/scripts/lib/cost-defaults.mjs +2 -0
- package/scripts/lib/escalation-facts.mjs +146 -0
- package/scripts/lib/escalation.mjs +129 -0
- package/scripts/lib/findings-ledger.mjs +241 -0
- package/scripts/lib/install-text.mjs +97 -0
- package/scripts/lib/loop-caps.mjs +140 -0
- package/scripts/lib/loop-diff.mjs +12 -70
- package/scripts/lib/loop-engine.mjs +226 -0
- package/scripts/lib/loop-escalate.mjs +49 -0
- package/scripts/lib/loop-exit.mjs +47 -0
- package/scripts/lib/loop-notes-compact.mjs +72 -0
- package/scripts/lib/loop-notes.mjs +278 -0
- package/scripts/lib/loop-review.mjs +355 -12
- package/scripts/lib/loop-state.mjs +44 -0
- package/scripts/lib/loop-step-close.mjs +75 -0
- package/scripts/lib/loop-step-kit.mjs +179 -0
- package/scripts/lib/loop-step-review.mjs +140 -0
- package/scripts/lib/loop-step-tool.mjs +89 -0
- package/scripts/lib/loop-step.mjs +301 -0
- package/scripts/lib/mcp-project-root.mjs +18 -7
- package/scripts/lib/path-facts.mjs +187 -0
- package/scripts/lib/path-safety.mjs +171 -0
- package/scripts/lib/run-card.mjs +73 -0
- package/scripts/size-budget-overrides.json +5 -13
- package/scripts/somi-card.mjs +39 -0
- package/scripts/somi-findings.mjs +56 -271
- package/scripts/somi-loop.mjs +77 -447
- package/scripts/somi-mcp.mjs +26 -95
- package/scripts/validate.sh +75 -57
- package/skills/flow-adopt/SKILL.md +92 -0
- package/skills/flow-architecture-review/SKILL.md +94 -0
- package/skills/flow-atlas/SKILL.md +34 -0
- package/skills/flow-code/SKILL.md +167 -0
- package/skills/flow-code-loop/SKILL.md +263 -0
- package/skills/flow-code-parallel/SKILL.md +160 -0
- package/skills/flow-debug/SKILL.md +141 -0
- package/skills/flow-design/SKILL.md +170 -0
- package/skills/flow-discover/SKILL.md +204 -0
- package/skills/flow-impact/SKILL.md +35 -0
- package/skills/flow-incident/SKILL.md +49 -0
- package/skills/flow-plan/SKILL.md +254 -0
- package/skills/flow-plan-loop/SKILL.md +254 -0
- package/skills/flow-pr/SKILL.md +34 -0
- package/skills/flow-refactor/SKILL.md +58 -0
- package/skills/flow-refactor-design/SKILL.md +97 -0
- package/skills/flow-release-readiness/SKILL.md +82 -0
- package/skills/flow-review/SKILL.md +193 -0
- package/skills/flow-review-panel/SKILL.md +154 -0
- package/skills/flow-security-review/SKILL.md +83 -0
- package/skills/flow-ship/SKILL.md +125 -0
- package/skills/flow-ship-loop/SKILL.md +274 -0
- package/skills/flow-somi-config/SKILL.md +142 -0
- package/skills/flow-status/SKILL.md +43 -0
- package/skills/flow-test-strategy/SKILL.md +83 -0
- package/skills/flow-upgrade/SKILL.md +82 -0
- package/skills/role-coder/SKILL.md +247 -0
- package/skills/role-designer/SKILL.md +172 -0
- package/skills/role-discovery-analyst/SKILL.md +288 -0
- package/skills/role-planner/SKILL.md +353 -0
- package/skills/role-reviewer/SKILL.md +218 -0
- package/skills/somi-checkpoint/SKILL.md +95 -0
- package/skills/somi-dispatch/SKILL.md +14 -14
- package/skills/somi-routing/SKILL.md +6 -2
- package/tests/hooks/cases/block-secret-writes.json +6 -1
- package/tests/hooks/cases/guard-protected-paths.json +44 -2
- package/tests/hooks/run.sh +21 -0
- package/tests/scripts/checkpoint-gate.sh +2 -2
- package/tests/scripts/cost-defaults.sh +2 -0
- package/tests/scripts/dispatch-line-gate.sh +4 -4
- package/tests/scripts/dispatch-reference-gate.sh +14 -14
- package/tests/scripts/escalation.sh +409 -0
- package/tests/scripts/eval-runner.sh +8 -7
- package/tests/scripts/fact-sheet.sh +296 -0
- package/tests/scripts/goldens/somi-loop.json +2 -2
- package/tests/scripts/lib/dispatch-reference-gate.mjs +14 -5
- package/tests/scripts/lib/escalation-facts-tests.mjs +140 -0
- package/tests/scripts/lib/escalation-tests.mjs +154 -0
- package/tests/scripts/lib/findings-ledger-tests.mjs +118 -0
- package/tests/scripts/lib/loop-engine-tests.mjs +287 -0
- package/tests/scripts/lib/loop-escalate-tests.mjs +356 -0
- package/tests/scripts/lib/loop-flow-gate.mjs +173 -0
- package/tests/scripts/lib/loop-notes-tests.mjs +371 -0
- package/tests/scripts/lib/loop-step-cli-tests.mjs +141 -0
- package/tests/scripts/lib/loop-step-close-tests.mjs +351 -0
- package/tests/scripts/lib/loop-step-lenient-tests.mjs +114 -0
- package/tests/scripts/lib/loop-step-state-tests.mjs +127 -0
- package/tests/scripts/lib/loop-step-tests.mjs +499 -0
- package/tests/scripts/lib/loop-step-unwritten-tests.mjs +55 -0
- package/tests/scripts/lib/path-facts-tests.mjs +198 -0
- package/tests/scripts/lib/path-safety-tests.mjs +201 -0
- package/tests/scripts/lib/run-suites.mjs +139 -0
- package/tests/scripts/lib/sizing-score-tests.mjs +210 -0
- package/tests/scripts/lib/sizing-set-tests.mjs +131 -0
- package/tests/scripts/lib/somi-mcp-loop-tests.mjs +226 -0
- package/tests/scripts/lib/somi-mcp-tests.mjs +21 -1
- package/tests/scripts/loop-engine.sh +22 -0
- package/tests/scripts/loop-flow-gate.sh +11 -0
- package/tests/scripts/review-panel-seats.sh +4 -4
- package/tests/scripts/run-card.sh +57 -0
- package/tests/scripts/run-suites.sh +74 -0
- package/tests/scripts/run.sh +11 -0
- package/tests/scripts/size-tier.sh +3 -3
- package/tests/scripts/somi-agent-dispatch-contract.sh +23 -3
- package/tests/scripts/somi-mcp.sh +1 -0
- 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
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
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
|
|
21
|
+
import { PROG, getFinding, openFindings, recordFindings, reopenFinding, resolveFinding } from './lib/findings-ledger.mjs';
|
|
34
22
|
|
|
35
|
-
const
|
|
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
|
-
//
|
|
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
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
|
133
|
-
let rest = argv.slice(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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 (!
|
|
158
|
-
if (!
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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 {
|