@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
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// path-safety.mjs — inspectPath(root, raw): may a script look at this model-named path?
|
|
2
|
+
//
|
|
3
|
+
// A model, steered by request text, names paths; this module is the only door between those names and the
|
|
4
|
+
// filesystem. It returns a result by class, never file content:
|
|
5
|
+
// { kind: 'denied' } the NAME is a secret (.env*, key and certificate files, .git/): decided
|
|
6
|
+
// on the string alone, no lstat, no realpath, no open, whatever the
|
|
7
|
+
// file's state, so nothing can be learned about it
|
|
8
|
+
// { kind: 'refused', refusal, denied? } unsafe or unreadable; `refusal` is one of REFUSAL_IDS (ASCII, never
|
|
9
|
+
// the input text); `denied: true` when the name is also deny-listed,
|
|
10
|
+
// so a malformed secret name (../../.env) keeps its floor
|
|
11
|
+
// { kind: 'contained', exists, rel, ... } inside the root: a plain file (exists: true, with its size, and
|
|
12
|
+
// `answer` when a probe was given) or a new path whose parent exists
|
|
13
|
+
// `rel` is the caller's own text and may be non-ASCII; the output layer escapes it. A name over MAX_PATH_CHARS is
|
|
14
|
+
// never normalised or judged: it counts as deny-listed, so it is refused `path_length` with `denied: true`.
|
|
15
|
+
// Backslashes are separators everywhere here, so `a\..\b` is a traversal on every platform.
|
|
16
|
+
//
|
|
17
|
+
// A probe is called with the open descriptor and the size, and returns true or false; this module closes the
|
|
18
|
+
// descriptor, so it never escapes. This module returns only that boolean, so the probe must be synchronous; a
|
|
19
|
+
// probe that throws becomes the `probe` refusal, never its message. The probe must not close the descriptor: a
|
|
20
|
+
// probe that does makes this module's own close fail, which is the `probe` refusal too (a close that fails with no probe is `unreadable`).
|
|
21
|
+
//
|
|
22
|
+
// Seams: `realpath` (default fs.realpathSync.native) and `constants` (default fs.constants).
|
|
23
|
+
// shortcut: containment is checked, then the file is opened by its canonical path; a directory swapped in
|
|
24
|
+
// between the walk and the open by a process already running as the user is not defended (O_NOFOLLOW covers the
|
|
25
|
+
// last component), upgrade when the script runs for a different user than the files' owner.
|
|
26
|
+
import fs from 'node:fs';
|
|
27
|
+
import path from 'node:path';
|
|
28
|
+
|
|
29
|
+
export const MAX_PATHS = 40;
|
|
30
|
+
export const MAX_PATH_CHARS = 240;
|
|
31
|
+
export const MAX_FILE_BYTES = 1024 * 1024;
|
|
32
|
+
|
|
33
|
+
export const REFUSAL_IDS = Object.freeze([
|
|
34
|
+
'malformed', 'path_count', 'path_length', 'control', 'absolute', 'traversal', 'symlink', 'escape',
|
|
35
|
+
'no_parent', 'not_file', 'file_size', 'platform', 'unreadable', 'probe',
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
const SEPARATORS = /[\\/]+/;
|
|
39
|
+
// Cf includes ZWNJ and ZWJ: refusing them (they matter in some scripts) is deliberate, a hidden join is a spoof.
|
|
40
|
+
export const UNSAFE_CHARS = /[\p{Cc}\p{Cf}\p{Cs}\p{Zl}\p{Zp}]/u;
|
|
41
|
+
const ABSOLUTE = /^(?:[\\/]|[a-z]:)/i;
|
|
42
|
+
const PARENT_SEGMENT = /^\.{2}[. ]*$/;
|
|
43
|
+
// A bare `config` is allowed on purpose, though the secret-write hook denies it: this match is per segment, so `config`
|
|
44
|
+
// here would deny every `config/` directory. The secret-bearing configs sit under the `.git`, `.ssh`, `.aws`, `.kube`
|
|
45
|
+
// and `.docker` segments below. `credentials` also denies a `credentials/` directory, which the hook (basename only) does not.
|
|
46
|
+
const NAME_EXACT = ['.git', '.ssh', '.gnupg', '.aws', '.kube', '.docker', 'credentials'];
|
|
47
|
+
const NAME_PREFIXES = ['.env', 'id_rsa', 'id_dsa', 'id_ecdsa', 'id_ed25519', '.npmrc', '.netrc', '.git-credentials', '.pypirc', '.pgpass', 'terraform.tfstate', '_netrc', '_pgpass', '.htpasswd', '.vault-token'];
|
|
48
|
+
const NAME_SUFFIXES = ['.pem', '.key', '.p12', '.pfx', '.crt', '.cer', '.der', '.jks', '.keystore', '.ppk', '.tfvars', '.kdbx', '.tfstate', '.tfstate.backup', '.p8', '.netrc', '.pgpass', '-key.json', 'credentials.json'];
|
|
49
|
+
// Names the repository's own secret-write hook denies by pattern rather than by affix, and the common service-account
|
|
50
|
+
// and OAuth client key files it does not name: the exact `key.json` (the GCP docs' default) and a `.tfstate.<n>.backup` copy.
|
|
51
|
+
// `[^]*`, not `.*`: a line terminator in the middle of a name must not stop the match (`.` does not match one).
|
|
52
|
+
const NAME_PATTERN = /service[-_]?account[^]*\.json$|client_secret[^]*\.json$|secrets?\.(?:ya?ml|json)$|^key\.json$|\.tfstate\.[^]*\.backup$/;
|
|
53
|
+
|
|
54
|
+
const segmentsOf = (raw) => raw.split(SEPARATORS).filter((s) => s !== '' && s !== '.');
|
|
55
|
+
export const trimDots = (s) => { let e = s.length; while (e > 0 && (s[e - 1] === '.' || s[e - 1] === ' ')) e--; return s.slice(0, e); };
|
|
56
|
+
const refused = (refusal, denied = false) => (denied ? { kind: 'refused', refusal, denied: true } : { kind: 'refused', refusal });
|
|
57
|
+
|
|
58
|
+
// The fold every name test shares (case, compatibility forms): callers that read names the way the deny list does import it.
|
|
59
|
+
export const foldName = (s) => s.normalize('NFKC').toUpperCase().toLowerCase();
|
|
60
|
+
|
|
61
|
+
// Pure string test, case-folded (upper then lower, so a sharp s reads as ss): the same answer for .ENV as .env on every filesystem.
|
|
62
|
+
// The raw path is split first and each segment folded after, because seven code points fold to a separator (U+FF0F,
|
|
63
|
+
// U+FF3C, U+FE68, U+2100, U+2101, U+2105, U+2106): a segment is tested whole and as its re-split pieces (a union), so
|
|
64
|
+
// `x/.env` and `service-account/prod.json` are both denied.
|
|
65
|
+
export function denyListed(raw) {
|
|
66
|
+
if (typeof raw !== 'string') return false;
|
|
67
|
+
if (raw.length > MAX_PATH_CHARS) return true;
|
|
68
|
+
return raw.split(SEPARATORS).some((segment) => {
|
|
69
|
+
const folded = foldName(segment);
|
|
70
|
+
return [...new Set([folded, ...folded.split(SEPARATORS)])].some((piece) => {
|
|
71
|
+
const name = trimDots(piece);
|
|
72
|
+
return NAME_EXACT.includes(name) || /~\d/.test(name) || name.includes(':') || NAME_PATTERN.test(name) || NAME_PREFIXES.some((p) => name.startsWith(p)) || NAME_SUFFIXES.some((s) => name.endsWith(s));
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// The list-level cap. A list over it is refused whole and keeps the deny-listed fact for any name in it; a list over
|
|
78
|
+
// 4 x MAX_PATHS is not scanned at all and is refused as denied outright.
|
|
79
|
+
export function refuseList(paths) {
|
|
80
|
+
if (!Array.isArray(paths)) return refused('malformed');
|
|
81
|
+
if (paths.length <= MAX_PATHS) return null;
|
|
82
|
+
if (paths.length > 4 * MAX_PATHS) return refused('path_count', true); // not scanned: a list this long is hostile
|
|
83
|
+
return refused('path_count', paths.some(denyListed));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function malformed(raw) {
|
|
87
|
+
if (typeof raw !== 'string') return 'malformed';
|
|
88
|
+
if (raw.length > MAX_PATH_CHARS) return 'path_length';
|
|
89
|
+
if (UNSAFE_CHARS.test(raw)) return 'control';
|
|
90
|
+
if (ABSOLUTE.test(raw)) return 'absolute';
|
|
91
|
+
const segments = segmentsOf(raw);
|
|
92
|
+
if (segments.some((s) => PARENT_SEGMENT.test(s))) return 'traversal';
|
|
93
|
+
return segments.length === 0 ? 'malformed' : null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Walks the root downwards one component at a time; any symlink refuses. Returns the canonical path and
|
|
97
|
+
// whether it exists, or a result to hand back.
|
|
98
|
+
function locate(root, segments, realpath) {
|
|
99
|
+
const base = realpath(root);
|
|
100
|
+
let current = base;
|
|
101
|
+
for (let i = 0; i < segments.length; i++) {
|
|
102
|
+
const next = path.join(current, segments[i]);
|
|
103
|
+
let stat;
|
|
104
|
+
try {
|
|
105
|
+
stat = fs.lstatSync(next);
|
|
106
|
+
} catch (e) {
|
|
107
|
+
if (e.code !== 'ENOENT') return { result: refused('unreadable') };
|
|
108
|
+
if (i < segments.length - 1) return { result: refused('no_parent') };
|
|
109
|
+
return { base, real: path.join(realpath(current), segments[i]), exists: false };
|
|
110
|
+
}
|
|
111
|
+
if (stat.isSymbolicLink()) return { result: refused('symlink') };
|
|
112
|
+
if (i < segments.length - 1 && !stat.isDirectory()) return { result: refused('not_file') };
|
|
113
|
+
if (i === segments.length - 1 && !stat.isFile()) return { result: refused('not_file') };
|
|
114
|
+
current = next;
|
|
115
|
+
}
|
|
116
|
+
return { base, real: realpath(current), exists: true };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Opens without following a link or blocking on a FIFO; returns the descriptor and size, or a result.
|
|
120
|
+
function openPlainFile(real, constants) {
|
|
121
|
+
let fd;
|
|
122
|
+
try {
|
|
123
|
+
fd = fs.openSync(real, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK | (constants.O_NOCTTY ?? 0));
|
|
124
|
+
} catch (e) {
|
|
125
|
+
return { result: refused(e.code === 'ELOOP' ? 'symlink' : 'unreadable') };
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
const stat = fs.fstatSync(fd);
|
|
129
|
+
if (!stat.isFile()) throw Object.assign(new Error(), { refusal: 'not_file' });
|
|
130
|
+
if (stat.size > MAX_FILE_BYTES) throw Object.assign(new Error(), { refusal: 'file_size' });
|
|
131
|
+
return { fd, size: stat.size };
|
|
132
|
+
} catch (e) {
|
|
133
|
+
fs.closeSync(fd);
|
|
134
|
+
return { result: refused(e.refusal ?? 'unreadable') };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function inspectPath(root, raw, probe = null, { realpath = fs.realpathSync.native, constants = fs.constants } = {}) {
|
|
139
|
+
const denied = denyListed(raw);
|
|
140
|
+
const bad = malformed(raw);
|
|
141
|
+
if (bad) return refused(bad, denied);
|
|
142
|
+
if (denied) return { kind: 'denied' };
|
|
143
|
+
if (!(constants.O_NOFOLLOW > 0 && constants.O_NONBLOCK > 0)) return refused('platform');
|
|
144
|
+
let found;
|
|
145
|
+
try {
|
|
146
|
+
found = locate(root, segmentsOf(raw), realpath);
|
|
147
|
+
} catch {
|
|
148
|
+
return refused('unreadable');
|
|
149
|
+
}
|
|
150
|
+
if (found.result) return found.result;
|
|
151
|
+
const rel = path.relative(found.base, found.real);
|
|
152
|
+
if (rel === '' || rel === '..' || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel)) return refused('escape');
|
|
153
|
+
if (denyListed(rel)) return { kind: 'denied' };
|
|
154
|
+
const contained = { kind: 'contained', exists: found.exists, rel: rel.split(path.sep).join('/') };
|
|
155
|
+
if (!found.exists) return contained;
|
|
156
|
+
const opened = openPlainFile(found.real, constants);
|
|
157
|
+
if (opened.result) return opened.result;
|
|
158
|
+
let result = contained;
|
|
159
|
+
try {
|
|
160
|
+
contained.size = opened.size;
|
|
161
|
+
if (probe) contained.answer = probe(opened.fd, opened.size) === true;
|
|
162
|
+
} catch {
|
|
163
|
+
result = refused('probe');
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
fs.closeSync(opened.fd);
|
|
167
|
+
} catch {
|
|
168
|
+
return refused(probe ? 'probe' : 'unreadable'); // with a probe, the likely cause is the probe closing the descriptor
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// run-card.mjs -- the run card: the few verified facts every agent of one code iteration needs, built once from the
|
|
2
|
+
// loop state the orchestrator already has, so each agent it starts stops re-deriving them (where SoMi's scripts are,
|
|
3
|
+
// which plan files to read, which files the iteration may touch, how the tests run) and every briefing in the loop
|
|
4
|
+
// opens with the same bytes, which a repeated start can reuse from the prompt cache.
|
|
5
|
+
//
|
|
6
|
+
// Facts only, never reasoning: a reviewer briefed with the card learns where things are, not what the coder thought.
|
|
7
|
+
// The card is data: every value is checked or reduced to a printable path before it is written, and the text is
|
|
8
|
+
// fenced so an agent reads it as data.
|
|
9
|
+
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
|
|
13
|
+
export const SLUG_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
14
|
+
// The one iteration id pattern (loop steps, the notes writers and the card): N.M, or a split such as 2.1b.
|
|
15
|
+
export const ITERATION_RE = /^(?:0|[1-9]\d{0,2})\.(?:0|[1-9]\d{0,2})[a-z]?$/;
|
|
16
|
+
export const HOSTS = ['claude-code', 'copilot'];
|
|
17
|
+
export const MAX_FILES = 20;
|
|
18
|
+
export const MAX_BYTES = 2048;
|
|
19
|
+
|
|
20
|
+
// A path as printable text: control and bidi characters removed, length capped.
|
|
21
|
+
const printable = (s) => String(s).replace(/[\u0000-\u001f\u007f--]/g, '').slice(0, 200);
|
|
22
|
+
|
|
23
|
+
export function phaseFile(planDir, iteration) {
|
|
24
|
+
const n = iteration.split('.')[0].padStart(2, '0');
|
|
25
|
+
try {
|
|
26
|
+
const hit = fs.readdirSync(path.join(planDir, 'phases')).filter((f) => f.startsWith(`${n}-`) && f.endsWith('.md')).sort()[0];
|
|
27
|
+
return hit ? `phases/${hit}` : null;
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function testCommand(projectDir) {
|
|
34
|
+
try {
|
|
35
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(projectDir, 'package.json'), 'utf8'));
|
|
36
|
+
return typeof pkg?.scripts?.test === 'string' ? 'npm test' : null;
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Builds the card. Returns { ok: true, card } or { ok: false, error }.
|
|
44
|
+
* `state` is the parsed loop state (.somi/somi-state/loop/<slug>.<iteration>.json).
|
|
45
|
+
*/
|
|
46
|
+
export function buildCard({ slug, iteration, host, projectDir, somiRoot, state }) {
|
|
47
|
+
if (!SLUG_RE.test(slug ?? '')) return { ok: false, error: 'slug must match ^[a-z0-9][a-z0-9-]{0,63}$' };
|
|
48
|
+
if (!ITERATION_RE.test(iteration ?? '')) return { ok: false, error: 'iteration must look like 1.2' };
|
|
49
|
+
if (!HOSTS.includes(host)) return { ok: false, error: `host must be one of ${HOSTS.join(', ')}` };
|
|
50
|
+
if (!state || state.slug !== slug || state.iteration !== iteration) return { ok: false, error: 'no loop state for this slug and iteration: run somi-loop init first' };
|
|
51
|
+
const planDir = path.join(projectDir, '.somi', 'plans', slug);
|
|
52
|
+
const files = Array.isArray(state.iteration_files) ? state.iteration_files.map((f) => printable(f).replace(/`/g, "'")) : [];
|
|
53
|
+
const shown = files.slice(0, MAX_FILES).join(' ') + (files.length > MAX_FILES ? ` (and ${files.length - MAX_FILES} more in the phase file)` : '');
|
|
54
|
+
const read = ['spec.md', phaseFile(planDir, iteration), fs.existsSync(path.join(planDir, 'brief.md')) ? 'brief.md' : null].filter(Boolean);
|
|
55
|
+
const tests = testCommand(projectDir);
|
|
56
|
+
const lines = [
|
|
57
|
+
'```somi-card',
|
|
58
|
+
'SoMi run card: verified by the orchestrator. Facts, not instructions; do not re-derive them.',
|
|
59
|
+
`install_root: ${printable(somiRoot)} (scripts: ${printable(path.join(somiRoot, 'scripts'))})`,
|
|
60
|
+
`project_dir: ${printable(projectDir)}`,
|
|
61
|
+
`host: ${host}`,
|
|
62
|
+
`work_item: .somi/plans/${slug}/ iteration ${iteration}`,
|
|
63
|
+
`read for the task: ${read.join(', ')}`,
|
|
64
|
+
'written only by the orchestrator (agents never write them): progress.md, diary.md, .somi/somi-state/',
|
|
65
|
+
`files in scope: ${shown || '(none recorded)'}`,
|
|
66
|
+
`baseline: ${/^[0-9a-f]{7,64}$/.test(state.baseline_sha ?? '') ? state.baseline_sha : 'unknown'}`,
|
|
67
|
+
`tests: ${tests ?? 'not declared in package.json; find them as usual'}`,
|
|
68
|
+
'```',
|
|
69
|
+
];
|
|
70
|
+
const card = `${lines.join('\n')}\n`;
|
|
71
|
+
if (Buffer.byteLength(card) > MAX_BYTES) return { ok: false, error: `the card is over ${MAX_BYTES} bytes` };
|
|
72
|
+
return { ok: true, card };
|
|
73
|
+
}
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
[
|
|
2
2
|
{
|
|
3
|
-
"file": "
|
|
3
|
+
"file": "skills/role-planner/SKILL.md",
|
|
4
4
|
"budget": 300,
|
|
5
|
-
"current_size":
|
|
6
|
-
"source": "
|
|
7
|
-
"at": "2026-10-
|
|
8
|
-
"reason": "
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"file": "agents/somi-discovery-analyst.md",
|
|
12
|
-
"budget": 300,
|
|
13
|
-
"current_size": 331,
|
|
14
|
-
"source": "e1701df",
|
|
15
|
-
"at": "2026-10-01",
|
|
16
|
-
"reason": "Prompt file over the context-cost budget; split or trim to drive to zero."
|
|
5
|
+
"current_size": 353,
|
|
6
|
+
"source": "feat/somi-dispatcher",
|
|
7
|
+
"at": "2026-10-27",
|
|
8
|
+
"reason": "The planner procedure moved here from agents/somi-planner.md (ledgered at 402); split or trim to drive to zero."
|
|
17
9
|
},
|
|
18
10
|
{
|
|
19
11
|
"file": "hooks/user-prompt-submit/inject-workflow-context.mjs",
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// somi-card.mjs -- prints the run card for one code iteration (scripts/lib/run-card.mjs), for the orchestrator to
|
|
3
|
+
// paste, unchanged, at the top of every agent briefing in one code-review loop.
|
|
4
|
+
//
|
|
5
|
+
// Usage: node somi-card.mjs --slug <slug> --iteration <N.M> --host <claude-code|copilot>
|
|
6
|
+
// Reads .somi/somi-state/loop/<slug>.<N.M>.json under the project (CLAUDE_PROJECT_DIR, else the current directory),
|
|
7
|
+
// so run it after `somi-loop.mjs init`. Exit 0 with the card on stdout; 64 on a usage error or a missing loop state.
|
|
8
|
+
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
import { buildCard, SLUG_RE, ITERATION_RE } from './lib/run-card.mjs';
|
|
13
|
+
|
|
14
|
+
const usage = 'usage: somi-card.mjs --slug <slug> --iteration <N.M> --host <claude-code|copilot>';
|
|
15
|
+
const die = (msg) => { process.stderr.write(`somi-card: ${msg}\n${usage}\n`); process.exit(64); };
|
|
16
|
+
|
|
17
|
+
const args = {};
|
|
18
|
+
const argv = process.argv.slice(2);
|
|
19
|
+
for (let i = 0; i < argv.length; i += 2) {
|
|
20
|
+
const k = argv[i];
|
|
21
|
+
if (!['--slug', '--iteration', '--host'].includes(k) || argv[i + 1] === undefined) die(`unexpected argument ${JSON.stringify(k)}`);
|
|
22
|
+
args[k.slice(2)] = argv[i + 1];
|
|
23
|
+
}
|
|
24
|
+
if (!SLUG_RE.test(args.slug ?? '') || !ITERATION_RE.test(args.iteration ?? '')) die('--slug and --iteration are required and must be well formed');
|
|
25
|
+
|
|
26
|
+
let projectDir = process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
27
|
+
if (projectDir.includes('${')) projectDir = process.cwd();
|
|
28
|
+
projectDir = path.resolve(projectDir);
|
|
29
|
+
const somiRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
30
|
+
|
|
31
|
+
let state = null;
|
|
32
|
+
try {
|
|
33
|
+
state = JSON.parse(fs.readFileSync(path.join(projectDir, '.somi', 'somi-state', 'loop', `${args.slug}.${args.iteration}.json`), 'utf8'));
|
|
34
|
+
} catch {
|
|
35
|
+
die(`no loop state for ${args.slug} ${args.iteration}: run somi-loop init first`);
|
|
36
|
+
}
|
|
37
|
+
const r = buildCard({ slug: args.slug, iteration: args.iteration, host: args.host, projectDir, somiRoot, state });
|
|
38
|
+
if (!r.ok) die(r.error);
|
|
39
|
+
process.stdout.write(r.card);
|