@skathio/somi 2.2.1 → 3.0.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-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +8 -2
- package/.copilot-extension/extension.json +9 -8
- package/.copilot-extension/marketplace.json +2 -2
- package/README.md +45 -33
- package/VERSION +1 -1
- package/agents/architecture-reviewer.md +16 -0
- package/agents/atlas.md +102 -0
- package/agents/coder.md +66 -22
- package/agents/designer.md +20 -16
- package/agents/discovery-analyst.md +6 -5
- package/agents/impact.md +97 -0
- package/agents/incident.md +96 -0
- package/agents/plan-reviewer.md +70 -0
- package/agents/planner.md +77 -20
- package/agents/pr.md +101 -0
- package/agents/refactor-designer.md +82 -0
- package/agents/refactorer.md +30 -24
- package/agents/reviewer.md +28 -25
- package/agents/sdlc-reviewer.md +69 -0
- package/agents/security-reviewer.md +17 -0
- package/agents/somi.md +207 -209
- package/agents/test-strategist.md +16 -1
- package/commands/adopt.md +21 -7
- package/commands/architecture-review.md +8 -5
- package/commands/atlas.md +24 -72
- package/commands/code-loop.md +46 -15
- package/commands/code-parallel.md +6 -4
- package/commands/code.md +29 -21
- package/commands/debug.md +17 -11
- package/commands/design.md +48 -31
- package/commands/discover.md +26 -16
- package/commands/impact.md +16 -54
- package/commands/incident.md +22 -55
- package/commands/plan-loop.md +43 -17
- package/commands/plan.md +64 -26
- package/commands/pr.md +19 -66
- package/commands/refactor-design.md +98 -0
- package/commands/refactor.md +22 -23
- package/commands/release-readiness.md +16 -7
- package/commands/review-panel.md +31 -10
- package/commands/review.md +21 -14
- package/commands/security-review.md +12 -3
- package/commands/ship-loop.md +71 -54
- package/commands/ship.md +17 -13
- package/commands/test-strategy.md +6 -4
- package/commands/upgrade.md +10 -8
- package/examples/discovery-example.md +2 -2
- package/examples/sample-consumer/CLAUDE.md +41 -7
- package/examples/sample-consumer/README.md +36 -22
- package/hooks/lib/common.mjs +66 -20
- package/hooks/post-tool/audit-log.mjs +7 -11
- package/hooks/post-tool/lint-changed-files.mjs +8 -11
- package/hooks/pre-tool/block-dangerous-bash.mjs +32 -44
- package/hooks/pre-tool/block-secret-writes.mjs +6 -9
- package/hooks/pre-tool/gate-dep-install.mjs +18 -27
- package/hooks/pre-tool/guard-protected-paths.mjs +9 -11
- package/hooks/session-start/detect-repo-instructions.mjs +21 -23
- package/hooks/user-prompt-submit/inject-workflow-context.mjs +190 -42
- package/mcp.json +10 -0
- package/package.json +5 -2
- package/rules/CLAUDE.md +22 -19
- package/scripts/check-links.mjs +218 -0
- package/scripts/check-session-artefacts.mjs +149 -0
- package/scripts/check-size-budget.mjs +137 -0
- package/scripts/generate-digest.mjs +176 -0
- package/scripts/lib/cost-ceiling.mjs +317 -0
- package/scripts/lib/cost-model.mjs +95 -0
- package/scripts/lib/dispatch-resolver.mjs +224 -0
- package/scripts/lib/mcp-project-root.mjs +183 -0
- package/scripts/size-budget-overrides.json +74 -0
- package/scripts/somi-check.mjs +6 -13
- package/scripts/somi-dispatch.mjs +141 -0
- package/scripts/somi-findings.mjs +4 -5
- package/scripts/somi-loop.mjs +181 -13
- package/scripts/somi-mcp.mjs +357 -0
- package/scripts/validate.sh +690 -29
- package/skills/clean-code/SKILL.md +1 -1
- package/skills/plan-review/SKILL.md +79 -0
- package/skills/rules/SKILL.md +47 -0
- package/skills/sdlc-process/SKILL.md +74 -0
- package/skills/somi-dispatch/SKILL.md +220 -0
- package/skills/somi-routing/SKILL.md +33 -8
- package/skills/{test-strategy → testing-playbook}/SKILL.md +1 -1
- package/templates/ATLAS.md.tmpl +4 -4
- package/templates/BRIEF.md.tmpl +23 -22
- package/templates/DECISIONS.md.tmpl +1 -0
- package/templates/DESIGN.md.tmpl +5 -5
- package/templates/DIARY.md.tmpl +10 -5
- package/templates/DOD.md.tmpl +24 -0
- package/templates/PROGRESS.md.tmpl +3 -16
- package/templates/SOMI-README.md.tmpl +3 -3
- package/tests/hooks/cases/inject-workflow-context.json +120 -7
- package/tests/hooks/run.sh +20 -11
- package/tests/scripts/check-links.sh +105 -0
- package/tests/scripts/check-session-artefacts.sh +60 -0
- package/tests/scripts/check-size-budget.sh +71 -0
- package/tests/scripts/checkpoint-gate.sh +90 -0
- package/tests/scripts/convergence-runner.sh +1510 -0
- package/tests/scripts/cost-ceiling.sh +343 -0
- package/tests/scripts/cost-model.sh +192 -0
- package/tests/scripts/dispatch-guard.sh +108 -0
- package/tests/scripts/dispatch-reference-gate.sh +173 -0
- package/tests/scripts/eval-runner.sh +3691 -0
- package/tests/scripts/evals-packaging.sh +117 -0
- package/tests/scripts/fixtures/legacy-shard-no-schema.json +50 -0
- package/tests/scripts/generate-digest.sh +180 -0
- package/tests/scripts/goldens/loop-state-breach.json +1 -0
- package/tests/scripts/goldens/loop-state-done.json +1 -0
- package/tests/scripts/goldens/somi-loop.json +1 -1
- package/tests/scripts/lib/adr-shape.mjs +41 -0
- package/tests/scripts/lib/checkpoint-gate.mjs +54 -0
- package/tests/scripts/lib/digest-marker-coupling.mjs +52 -0
- package/tests/scripts/lib/dispatch-reference-gate.mjs +112 -0
- package/tests/scripts/lib/multipass-dependence.mjs +192 -0
- package/tests/scripts/lib/multipass-source-identity.mjs +243 -0
- package/tests/scripts/lib/reference-pair.mjs +61 -0
- package/tests/scripts/lib/retirement-gate.mjs +167 -0
- package/tests/scripts/lib/shell-embedded-js.mjs +47 -0
- package/tests/scripts/lib/somi-mcp-client.mjs +102 -0
- package/tests/scripts/lib/somi-mcp-tests.mjs +401 -0
- package/tests/scripts/lib/somi-mcp-tool-schema.mjs +38 -0
- package/tests/scripts/retirement-gate.sh +287 -0
- package/tests/scripts/review-panel-seats.sh +32 -0
- package/tests/scripts/run.sh +184 -2
- package/tests/scripts/somi-agent-dispatch-contract.sh +195 -0
- package/tests/scripts/somi-dispatch.sh +354 -0
- package/tests/scripts/somi-mcp.sh +12 -0
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
// hooks/user-prompt-submit/inject-workflow-context.mjs — UserPromptSubmit hook — inject SOMI
|
|
3
3
|
// context on relevant turns.
|
|
4
4
|
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// signature-hash gate). Imports the shared read/context/projectRoot helpers from
|
|
8
|
-
// ../lib/common.mjs (2.1, reviewer-blessed) rather than reimplementing them.
|
|
5
|
+
// The heaviest hook in the set: several pattern lists and a signature-hash gate. Imports the
|
|
6
|
+
// shared read/context/projectRoot helpers from ../lib/common.mjs rather than reimplementing them.
|
|
9
7
|
//
|
|
10
|
-
// Two responsibilities (unchanged from bash):
|
|
8
|
+
// Two responsibilities (unchanged from the original bash hook):
|
|
11
9
|
// 1. Remind the agent of the priority stack and active work-item state.
|
|
12
10
|
// 2. Surface end-of-turn loose ends (TODO(claude) markers, scratch files) on the NEXT user
|
|
13
11
|
// turn — this replaces the old Stop hook, which used an additionalContext channel that Stop
|
|
@@ -19,6 +17,31 @@
|
|
|
19
17
|
// independent of the reminder gate (see main() — this independence is pinned by the fixture case
|
|
20
18
|
// "nudge-fires-independent-of-suppressed-reminder").
|
|
21
19
|
//
|
|
20
|
+
// === THE TIER 1 / TIER 2 DIGEST SPLIT =========================================================
|
|
21
|
+
//
|
|
22
|
+
// This hook carries rules/CLAUDE.md's always-on digest into a consuming Claude Code project —
|
|
23
|
+
// the only delivery path that reaches one (plugin.json has no `rules` key). An always-on floor and the state-change gate below want opposite behavior from the same
|
|
24
|
+
// mechanism, so emission is split into two independent tiers rather than picking one:
|
|
25
|
+
//
|
|
26
|
+
// Tier 1 — REMINDER_BODY, unconditional, every UserPromptSubmit turn, independent of the
|
|
27
|
+
// signature gate below (the same independence pattern the loose-end nudges already use).
|
|
28
|
+
//
|
|
29
|
+
// Tier 2 — the full eleven-bullet digest, extracted at RUNTIME from rules/CLAUDE.md's
|
|
30
|
+
// `<!-- digest:start/end -->` markers (never hand-copied into this hook as a fourth drift-prone
|
|
31
|
+
// copy), plus planHint/rdHint. Both hints STAY on Tier 2 rather than moving to
|
|
32
|
+
// Tier 1: they are themselves state-change signals (which plan/rd is active), so gating them
|
|
33
|
+
// here preserves their gated behavior rather than making them newly always-on. Tier 2 rides the signature gate exactly as the old single-tier reminder did.
|
|
34
|
+
//
|
|
35
|
+
// Tier 2's bullets are read via pluginRoot() (hooks/lib/common.mjs), not assumed to live at this
|
|
36
|
+
// repo's own path, because this hook also runs inside a CONSUMING project, where SoMi's rules/
|
|
37
|
+
// lives inside the plugin's install directory, not at ./rules/... relative to the consumer's
|
|
38
|
+
// project root. For the same reason, each bullet's trailing citation is rewritten to a bare
|
|
39
|
+
// `` `NN` `` numeric code before injection (stripDigestCitations() below) rather than left as
|
|
40
|
+
// whatever link form rules/CLAUDE.md's canonical file uses — an unmodified normalized link would
|
|
41
|
+
// assert six paths that ENOENT in the consumer's context, on every gated turn. Fails safe:
|
|
42
|
+
// an unresolved pluginRoot(), or a rules/CLAUDE.md missing/malformed digest markers, silently
|
|
43
|
+
// omits Tier 2 rather than throwing — Tier 1 still fires regardless (see buildTier2Digest()).
|
|
44
|
+
//
|
|
22
45
|
// === THE SIGNATURE-HASH GATE: what bash actually feeds sha256sum ================================
|
|
23
46
|
//
|
|
24
47
|
// bash's compute_signature() runs THREE independent `find ... -printf '%T@ %p\n' | sort |
|
|
@@ -64,20 +87,19 @@
|
|
|
64
87
|
// doesn't exist at all on Windows) nor required for correctness. What IS required, and IS
|
|
65
88
|
// preserved exactly, is the gate's BEHAVIORAL contract: stable across repeated invocations when
|
|
66
89
|
// nothing changed, and different whenever the matched file set or any matched file's mtime
|
|
67
|
-
// changes — both verified by direct probe
|
|
90
|
+
// changes — both verified by direct probe. One bounded, expected consequence:
|
|
68
91
|
// the FIRST Node-hook invocation on a host whose `.somi/somi-state/last-context-signature`
|
|
69
92
|
// was last written by the bash hook will see a "changed" signature (different hash algorithms
|
|
70
93
|
// for the same state) and re-emit the reminder ONE extra time at cutover — benign, not a bug.
|
|
71
94
|
//
|
|
72
|
-
// === THE STATUS-DETECTION DECISION (explicit
|
|
95
|
+
// === THE STATUS-DETECTION DECISION (explicit and named) =============================
|
|
73
96
|
//
|
|
74
|
-
//
|
|
97
|
+
// A fixture pinned a real gap in the original bash hook: its in-progress detection recognizes a bare status line
|
|
75
98
|
// matching `^[[:space:]]*<?in-progress>?[[:space:]]*$` (optional ANGLE brackets, not backticks)
|
|
76
99
|
// or a line matching `status:[[:space:]]*`?in-progress`?` (requires a literal "status:" prefix).
|
|
77
100
|
// Neither pattern matches this project's OWN `progress.md` convention: a bare, BACKTICK-wrapped
|
|
78
101
|
// status line with no "Status:" prefix — confirmed not just by the fixture's synthetic example
|
|
79
|
-
// but by
|
|
80
|
-
// and by `templates/PROGRESS.md.tmpl` line 16 (`<One of: ... | in-progress | ...>` under a bare
|
|
102
|
+
// but by `templates/PROGRESS.md.tmpl` (`<One of: ... | in-progress | ...>` under a bare
|
|
81
103
|
// `## Status` heading, zero "Status:" prefix) — the CANONICAL template every `/plan`-generated
|
|
82
104
|
// work item's `progress.md` follows. So the narrow bash regexes miss the mainline case, not an
|
|
83
105
|
// edge case: every SoMi work item created via the documented template is invisible to this
|
|
@@ -91,69 +113,66 @@
|
|
|
91
113
|
// rule the original never had. The full-line anchor (`^...$`, tested per PHYSICAL LINE, matching
|
|
92
114
|
// grep's line-oriented semantics, not a whole-file substring search) is preserved exactly.
|
|
93
115
|
//
|
|
94
|
-
// Reasoning, weighed explicitly against reproducing the narrow detection for parity
|
|
95
|
-
// 2.7's prune-list decision structure):
|
|
116
|
+
// Reasoning, weighed explicitly against reproducing the narrow detection for parity:
|
|
96
117
|
//
|
|
97
118
|
// 1. Self-inconsistency, not a deliberate choice being preserved. SoMi's OWN planning tooling
|
|
98
119
|
// generates `progress.md` files in the exact format its OWN hook fails to recognize. This
|
|
99
120
|
// is not a hypothetical third-party format difference — it is SoMi authoring content for
|
|
100
121
|
// itself that its own runtime cannot read.
|
|
101
122
|
// 2. Bounded, precisely-scoped false-positive risk — verified empirically, not assumed. Unlike
|
|
102
|
-
//
|
|
103
|
-
// in the safe direction), THIS widening is in the OPPOSITE risk direction: it can make the
|
|
123
|
+
// the prune-list fix in detect-repo-instructions.mjs (which could only ever go quiet, never
|
|
124
|
+
// surface something new — fail-quiet in the safe direction), THIS widening is in the OPPOSITE risk direction: it can make the
|
|
104
125
|
// hook say MORE than it used to, and a badly-shaped widening could false-positive on
|
|
105
|
-
// narrative text. Checked directly: `grep -nE '^\s*[<`]?in-progress[>`]?\s*$'` against
|
|
106
|
-
//
|
|
126
|
+
// narrative text. Checked directly: `grep -nE '^\s*[<`]?in-progress[>`]?\s*$'` against a
|
|
127
|
+
// real ~1100-line `progress.md` — which repeatedly contains the SUBSTRING
|
|
107
128
|
// "in-progress" inside narrative sentences (e.g. "Iteration left `in-progress` (pass 1);
|
|
108
129
|
// review decides `done`." appears a dozen+ times in the Recent-activity/diary prose) —
|
|
109
130
|
// matches EXACTLY ONE line: the real `## Status` field's own bare `` `in-progress` `` line.
|
|
110
131
|
// Every narrative occurrence is disqualified by the full-line anchor (surrounding text on
|
|
111
132
|
// the same physical line breaks the `^...$` match). This is the concrete evidence that a
|
|
112
133
|
// substring-anywhere widening would be dangerous (it would false-positive on nearly every
|
|
113
|
-
// real `progress.md` once it accumulates
|
|
134
|
+
// real `progress.md` once it accumulates history) while the full-line-anchored
|
|
114
135
|
// widening actually chosen is not.
|
|
115
136
|
// 3. Confined blast radius: only `PLAN_STATUS_BARE_RE` changes. The R&D status scan
|
|
116
137
|
// (`researching|drafting|awaiting-verification|ready-for-planning`) already matches this
|
|
117
138
|
// repo's actual R&D README convention (`> Status: `researching``, already carrying the
|
|
118
|
-
// "Status:" prefix the regex requires) —
|
|
139
|
+
// "Status:" prefix the regex requires) — no gap there, so it is
|
|
119
140
|
// reproduced unchanged. `PLAN_STATUS_PREFIXED_RE` (the "status:"-prefixed in-progress form)
|
|
120
141
|
// is also reproduced unchanged — it already matches its own fixture cases correctly.
|
|
121
142
|
//
|
|
122
|
-
// Consumer-observable consequence
|
|
123
|
-
//
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
//
|
|
127
|
-
// (a new D-entry, D6-style) and 4.4's CHANGELOG scope, alongside D6's SessionStart prune change.
|
|
143
|
+
// Consumer-observable consequence: a work item using the bare-backtick `progress.md` convention
|
|
144
|
+
// now surfaces its "Active work item:" hint on turns where it previously stayed silent. This is a
|
|
145
|
+
// real behavior change, not a bug fix to an internal-only mechanism (unlike the SessionStart
|
|
146
|
+
// prune fix, which only affected an already-informational context surface), so it belongs in
|
|
147
|
+
// the CHANGELOG.
|
|
128
148
|
//
|
|
129
149
|
// Fixture implication: `tests/hooks/cases/inject-workflow-context.json`'s
|
|
130
150
|
// `plan-hint-bare-backtick-status-not-detected` case (which pinned the bash gap as current
|
|
131
151
|
// behavior) is renamed to `plan-hint-bare-backtick-status-now-detected` and its expectation
|
|
132
152
|
// FLIPPED (`expect_context_excludes: "Active work item:"` → `expect_context: "Active work item:
|
|
133
|
-
// \`.somi/plans/demo-slug/\`."`) — the one deliberate
|
|
134
|
-
// makes. Every other case passes with only the `"script"` field retargeted.
|
|
153
|
+
// \`.somi/plans/demo-slug/\`."`) — the one deliberate case edit this change required.
|
|
135
154
|
//
|
|
136
155
|
// === Loose-end nudges: execFileSync argument arrays, explicit maxBuffer ==========================
|
|
137
156
|
// `git diff`/`git status` are invoked via `execFileSync` with argument ARRAYS (never a shell
|
|
138
157
|
// string), avoiding any shell-injection surface entirely (paths interpolated into a shell command
|
|
139
158
|
// string is exactly the class of bug `execFileSync(cmd, [args])` structurally forecloses). Both
|
|
140
|
-
// calls set `maxBuffer` explicitly (10 MB — the convention
|
|
141
|
-
// output-capturing subprocess call in
|
|
159
|
+
// calls set `maxBuffer` explicitly (10 MB — the convention for every
|
|
160
|
+
// output-capturing subprocess call in the hooks), rather than relying on Node's low
|
|
142
161
|
// 1 MB default. A failed/absent `git` (ENOENT) or a non-zero exit from either command degrades to
|
|
143
162
|
// "no nudge from that check" — mirrors bash's `2>/dev/null` + `set -o pipefail`-tolerant `if
|
|
144
163
|
// pipeline; then` idiom, where either failure mode collapses to the same "condition false" outcome
|
|
145
164
|
// (a pipeline's non-zero exit inside an `if` condition does not abort under `set -e`).
|
|
146
165
|
//
|
|
147
|
-
// === Windows caveat (same class already flagged in
|
|
166
|
+
// === Windows caveat (same class already flagged in the other path-handling hooks) ==========
|
|
148
167
|
// Paths embedded in the signature hash and extracted slugs use `path.join`/`path.basename`
|
|
149
168
|
// (platform-default separator). Purely internal (signature) or free-text-message (slugs) use —
|
|
150
|
-
// not fixed here, consistent with
|
|
169
|
+
// not fixed here, consistent with the other hooks' documented-not-fixed Windows path-separator gaps.
|
|
151
170
|
|
|
152
171
|
import fs from 'node:fs';
|
|
153
172
|
import path from 'node:path';
|
|
154
173
|
import crypto from 'node:crypto';
|
|
155
174
|
import { execFileSync } from 'node:child_process';
|
|
156
|
-
import { readPayload, projectRoot, contextOutput, runHook } from '../lib/common.mjs';
|
|
175
|
+
import { readPayload, projectRoot, pluginRoot, contextOutput, runHook } from '../lib/common.mjs';
|
|
157
176
|
|
|
158
177
|
// bash: `grep -qiE '^[[:space:]]*<?in-progress>?[[:space:]]*$'` — WIDENED per THE
|
|
159
178
|
// STATUS-DETECTION DECISION above: backtick added as a second optional wrap character alongside
|
|
@@ -164,8 +183,8 @@ const PLAN_STATUS_BARE_RE = /^\s*[<`]?in-progress[>`]?\s*$/i;
|
|
|
164
183
|
const PLAN_STATUS_PREFIXED_RE = /status:\s*`?in-progress`?/i;
|
|
165
184
|
|
|
166
185
|
// bash: `grep -qiE 'status:[[:space:]]*`?(researching|drafting|awaiting-verification)`?'` /
|
|
167
|
-
// `grep -qiE 'status:[[:space:]]*`?ready-for-planning`?'` — reproduced unchanged;
|
|
168
|
-
//
|
|
186
|
+
// `grep -qiE 'status:[[:space:]]*`?ready-for-planning`?'` — reproduced unchanged; the real R&D
|
|
187
|
+
// README.md convention already carries the required "Status:" prefix.
|
|
169
188
|
const RD_STATUS_ACTIVE_RE = /status:\s*`?(researching|drafting|awaiting-verification)`?/i;
|
|
170
189
|
const RD_STATUS_READY_RE = /status:\s*`?ready-for-planning`?/i;
|
|
171
190
|
|
|
@@ -174,18 +193,133 @@ const TODO_MARKER_RE = /^\+.*(TODO\(claude\)|TODO\(agent\)|FIXME\(claude\))/;
|
|
|
174
193
|
// bash: `grep -E '^\?\? .*(\.bak|\.orig|scratch_)'` against `git status --porcelain` output.
|
|
175
194
|
const SCRATCH_FILE_RE = /^\?\? .*(\.bak|\.orig|scratch_)/;
|
|
176
195
|
|
|
177
|
-
//
|
|
178
|
-
//
|
|
179
|
-
//
|
|
196
|
+
// The convention for every output-capturing subprocess call (Node's spawnSync/execFileSync default
|
|
197
|
+
// maxBuffer is 1 MB — too small for a real `git diff`/`git status --porcelain` on a large
|
|
198
|
+
// working tree).
|
|
180
199
|
const GIT_MAX_BUFFER = 10 * 1024 * 1024;
|
|
181
200
|
|
|
182
201
|
const REMINDER_BODY =
|
|
183
202
|
'somi is active. Reminders:\n' +
|
|
184
|
-
|
|
203
|
+
// No `rules/...` path here, deliberately. This text is injected into a CONSUMING
|
|
204
|
+
// project's context, where SoMi's `rules/` lives inside the plugin install dir, not at
|
|
205
|
+
// `./rules/`. Naming the path asserted a file that ENOENTs there — the same defect the Tier 2
|
|
206
|
+
// digest avoids — and this block is emitted on EVERY turn, so the false assertion would be
|
|
207
|
+
// loud. Stating the priority order directly needs no path at all. Keeping
|
|
208
|
+
// Tier 1 free of `rules/` is also what lets the Tier 2 assertion be a flat "no `rules/`".
|
|
209
|
+
'- Follow SoMi\'s priority order: security > correctness > maintainability > performance > convenience.\n' +
|
|
185
210
|
'- Plan before coding non-trivial work. Code from the plan, not around it.\n' +
|
|
186
211
|
'- Surface tradeoffs and shortcuts in plain text; never silently compromise.\n' +
|
|
187
212
|
'- Hooks may deny dangerous bash, secret writes, protected paths, and unsanctioned dep installs — do not work around them.';
|
|
188
213
|
|
|
214
|
+
// Markers pinned in rules/CLAUDE.md's own "Always-on digest" section so extraction never depends
|
|
215
|
+
// on heading text staying stable — scripts/generate-digest.mjs consumes the same two markers for
|
|
216
|
+
// its own targets.
|
|
217
|
+
const DIGEST_MARKER_RE = /<!-- digest:start -->\r?\n([\s\S]*?)\r?\n<!-- digest:end -->/;
|
|
218
|
+
|
|
219
|
+
// Flattens a markdown link to its target, e.g. `[label](target)` -> `target` — the first half of
|
|
220
|
+
// rewriting each bullet's trailing citation to a bare numeric code (see stripDigestCitations()
|
|
221
|
+
// below). `.replace()` with a global regex resets its own lastIndex at the start of every call
|
|
222
|
+
// (per spec), so reusing this module-level pattern across lines carries none of the
|
|
223
|
+
// stateful-/g-regex hazard common.mjs's toRegExp()/matchesAny() guard against.
|
|
224
|
+
const DIGEST_LINK_RE = /\[([^\]]*)\]\(([^)]*)\)/g;
|
|
225
|
+
|
|
226
|
+
// Rewrites each physical line's trailing `(...)` citation to bare backtick-wrapped numeric
|
|
227
|
+
// code(s): `(`00`)` stays `(`00`)`; `([rules/00-priorities.md](./rules/00-priorities.md))`
|
|
228
|
+
// becomes `(`00`)`; `(`00`, `20`)` stays `(`00`, `20`)`. This is the required OUTPUT, not "strip
|
|
229
|
+
// back to the parenthetical it wrapped" — the latter, applied to a markdown-link source, still
|
|
230
|
+
// leaves a path assertion behind (`(rules/00-priorities.md)` still ENOENTs in a consuming
|
|
231
|
+
// project). Handles the already-bare canonical form and the
|
|
232
|
+
// full-markdown-link form identically — a markdown link is flattened to its target text before
|
|
233
|
+
// the numeric code is extracted, so this function doesn't need to know which form rules/CLAUDE.md
|
|
234
|
+
// is currently in.
|
|
235
|
+
function stripDigestCitations(block) {
|
|
236
|
+
return block
|
|
237
|
+
.split('\n')
|
|
238
|
+
.map((line) => {
|
|
239
|
+
// Match the trailing parenthetical on the ORIGINAL line — never on a pre-flattened copy
|
|
240
|
+
// Flattening the whole line first and returning that copy from the reject paths meant
|
|
241
|
+
// any line the recognizer DECLINED still had its markdown links destroyed: a bullet reading
|
|
242
|
+
// `read [the security file](./rules/30-security-owasp.md) before touching a sink` was injected
|
|
243
|
+
// as `read ./rules/30-security-owasp.md before touching a sink` — the very output this function exists
|
|
244
|
+
// to prevent, reached through the opposite door, and via the `!citationMatch` branch, which has nothing to do with
|
|
245
|
+
// citations at all. The mutation is now confined to the citation: links are flattened ONLY
|
|
246
|
+
// inside the captured body, and every reject path returns `line` byte-identical.
|
|
247
|
+
//
|
|
248
|
+
// One level of nesting is tolerated so a full markdown-link citation —
|
|
249
|
+
// `([rules/00-priorities.md](./rules/00-priorities.md))`, the form the digest generator
|
|
250
|
+
// normalizes to — is captured whole rather than truncated at its inner `)`.
|
|
251
|
+
const citationMatch = line.match(/\((?:[^()]|\([^()]*\))*\)\s*$/);
|
|
252
|
+
if (!citationMatch) return line; // no trailing parenthetical on this physical line — a
|
|
253
|
+
// bullet's citation sits on its own word-wrapped continuation line, not every line has one.
|
|
254
|
+
// Returns `line`, NOT a flattened copy: a line with no citation is none of this function's
|
|
255
|
+
// business, whatever else it contains.
|
|
256
|
+
const inner = citationMatch[0].slice(1, -1); // drop the outer parens
|
|
257
|
+
const flattenedBody = inner.replace(DIGEST_LINK_RE, (_m, label, target) => target || label);
|
|
258
|
+
// ANCHORED recognizer. An earlier form scanned the parenthetical unanchored
|
|
259
|
+
// for any two-digit run, so ANY line-final parenthetical containing two consecutive digits
|
|
260
|
+
// became a rule citation: a bullet ending `(ISO 27001)` was rewritten to (`27`, `00`) —
|
|
261
|
+
// fabricating a citation to two rule files and delivering it to the model as fact. Rewrapping or trimming this block is precisely when a non-citation
|
|
262
|
+
// parenthetical lands at end-of-line.
|
|
263
|
+
//
|
|
264
|
+
// The whole body must now BE a citation list — comma-separated `NN` / `` `NN` `` /
|
|
265
|
+
// `rules/NN-*.md` / `./rules/NN-*.md` — or the line is left untouched. Partial matches no
|
|
266
|
+
// longer leak: `ISO 27001` fails because `27001` is not a two-digit item.
|
|
267
|
+
const body = flattenedBody.trim();
|
|
268
|
+
// The `rules/` segment is OPTIONAL (widened after review). The canonical
|
|
269
|
+
// digest lives at rules/CLAUDE.md, so a link that RESOLVES from there is `./NN-*.md` with no
|
|
270
|
+
// `rules/` segment — the form the composition table in that same file already uses. Requiring
|
|
271
|
+
// `rules/` accepted only `./rules/NN-*.md`, which resolves to `rules/rules/...` and is a dead
|
|
272
|
+
// link; the round-trip appeared to pass precisely BECAUSE the canonical was broken. Both forms
|
|
273
|
+
// are accepted now so correcting the canonical cannot silently reintroduce path assertions.
|
|
274
|
+
const ITEM_RE = /^(?:`?(\d{2})`?|\.?\/?(?:rules\/)?(\d{2})-[A-Za-z0-9-]+\.md)$/;
|
|
275
|
+
const items = body === '' ? [] : body.split(',').map((s) => s.trim());
|
|
276
|
+
const codes = [];
|
|
277
|
+
let allItemsAreCitations = items.length > 0;
|
|
278
|
+
for (const item of items) {
|
|
279
|
+
const m = ITEM_RE.exec(item);
|
|
280
|
+
if (!m) {
|
|
281
|
+
allItemsAreCitations = false;
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
const code = m[1] ?? m[2];
|
|
285
|
+
if (!codes.includes(code)) codes.push(code);
|
|
286
|
+
}
|
|
287
|
+
// Not a citation list — return `line` UNCHANGED. A rejected line keeps its original
|
|
288
|
+
// markdown links intact. If such a link points into `rules/`, a digest-wide
|
|
289
|
+
// `excludes: "rules/"` assertion goes red and forces the digest's author to use the accepted
|
|
290
|
+
// grammar rather than having the link silently mangled into a bare path. Loud beats silent.
|
|
291
|
+
if (!allItemsAreCitations || codes.length === 0) return line;
|
|
292
|
+
const rewritten = `(${codes.map((c) => `\`${c}\``).join(', ')})`;
|
|
293
|
+
return line.slice(0, citationMatch.index) + rewritten;
|
|
294
|
+
})
|
|
295
|
+
.join('\n');
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Tier 2's content, read fresh from rules/CLAUDE.md at runtime rather than hand-copied into this
|
|
299
|
+
// hook as a fourth drift-prone copy. Fails safe at every step — an unresolved
|
|
300
|
+
// pluginRoot(), an unreadable file, or missing/malformed digest markers all return '' (Tier 2
|
|
301
|
+
// silently omitted) rather than throwing; Tier 1 (REMINDER_BODY) fires regardless, in main().
|
|
302
|
+
function buildTier2Digest() {
|
|
303
|
+
const base = pluginRoot();
|
|
304
|
+
if (!base) return '';
|
|
305
|
+
let content;
|
|
306
|
+
try {
|
|
307
|
+
content = fs.readFileSync(path.join(base, 'rules', 'CLAUDE.md'), 'utf8');
|
|
308
|
+
} catch {
|
|
309
|
+
return '';
|
|
310
|
+
}
|
|
311
|
+
const match = DIGEST_MARKER_RE.exec(content);
|
|
312
|
+
if (!match) return '';
|
|
313
|
+
return stripDigestCitations(match[1]);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// The single, durable pointer that replaces the per-bullet paths stripDigestCitations() removes.
|
|
317
|
+
// Appended by main() AFTER planHint/rdHint so it is genuinely trailing: building it into
|
|
318
|
+
// buildTier2Digest() put it before the hints, leaving a hint rendered as a dangling bullet hanging
|
|
319
|
+
// off a prose sentence — readable as an elaboration of "load the rules skill" rather than as the
|
|
320
|
+
// work-item notice it is.
|
|
321
|
+
const RULES_SKILL_POINTER = 'For full detail on any of these, load the `rules` skill.';
|
|
322
|
+
|
|
189
323
|
function isDirectory(p) {
|
|
190
324
|
try {
|
|
191
325
|
return fs.statSync(p).isDirectory();
|
|
@@ -412,10 +546,23 @@ function main() {
|
|
|
412
546
|
const rdHint = computeRdHint(root);
|
|
413
547
|
const nudges = computeNudges(root);
|
|
414
548
|
|
|
415
|
-
|
|
549
|
+
// Tier 1: unconditional, every turn, independent of emitReminder.
|
|
550
|
+
const parts = [REMINDER_BODY];
|
|
551
|
+
|
|
552
|
+
// Tier 2: gated exactly as the old single-tier reminder was. planHint/rdHint ride Tier 2 (see
|
|
553
|
+
// the header note above) — concatenated the same way REMINDER_BODY+hints were joined before
|
|
554
|
+
// this split, then any leading newline left over from an empty/omitted digest is trimmed so a
|
|
555
|
+
// fail-safe-omitted Tier 2 with a present hint doesn't emit a stray blank line.
|
|
416
556
|
if (emitReminder) {
|
|
417
|
-
|
|
557
|
+
const tier2Digest = buildTier2Digest();
|
|
558
|
+
let tier2Block = `${tier2Digest}${planHint}${rdHint}`.replace(/^\n+/, '');
|
|
559
|
+
// The pointer goes last, after the hints — and only when a digest was actually
|
|
560
|
+
// extracted, so the fail-safe path (missing/marker-less rules/CLAUDE.md) doesn't advertise a
|
|
561
|
+
// skill for content it just failed to deliver.
|
|
562
|
+
if (tier2Digest !== '') tier2Block += `\n\n${RULES_SKILL_POINTER}`;
|
|
563
|
+
if (tier2Block !== '') parts.push(tier2Block);
|
|
418
564
|
}
|
|
565
|
+
|
|
419
566
|
if (nudges.length > 0) {
|
|
420
567
|
let nudgeBlock = 'somi loose-end check:';
|
|
421
568
|
for (const n of nudges) {
|
|
@@ -424,9 +571,10 @@ function main() {
|
|
|
424
571
|
parts.push(nudgeBlock);
|
|
425
572
|
}
|
|
426
573
|
|
|
427
|
-
if (parts.length > 0)
|
|
428
|
-
|
|
429
|
-
|
|
574
|
+
// Tier 1 is unconditional, so `parts` is never empty — the old `if (parts.length > 0)` guard
|
|
575
|
+
// became dead code with the tier split and is dropped rather than left as a false suggestion that
|
|
576
|
+
// a silent turn is still reachable.
|
|
577
|
+
contextOutput('UserPromptSubmit', parts.join('\n\n'));
|
|
430
578
|
}
|
|
431
579
|
|
|
432
580
|
runHook(main);
|
package/mcp.json
ADDED
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skathio/somi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"scripts": {
|
|
5
|
-
"test": "bash scripts/validate.sh"
|
|
5
|
+
"test": "bash scripts/validate.sh",
|
|
6
|
+
"eval:behavioral": "node tests/evals/run.mjs",
|
|
7
|
+
"eval:convergence": "node tests/evals/convergence.mjs"
|
|
6
8
|
},
|
|
7
9
|
"bin": {
|
|
8
10
|
"somi-check": "scripts/somi-check.mjs"
|
|
@@ -50,6 +52,7 @@
|
|
|
50
52
|
".claude-plugin/",
|
|
51
53
|
".copilot-extension/",
|
|
52
54
|
".claude/",
|
|
55
|
+
"mcp.json",
|
|
53
56
|
"VERSION",
|
|
54
57
|
"LICENSE"
|
|
55
58
|
]
|
package/rules/CLAUDE.md
CHANGED
|
@@ -30,28 +30,29 @@ This digest is **always in force** — it is the compressed form of the numbered
|
|
|
30
30
|
act correctly on the common path without loading all of them. Each line points at the file that holds
|
|
31
31
|
the full treatment; read that file when you **enter its domain** (see "How to load the rules" below).
|
|
32
32
|
|
|
33
|
+
<!-- digest:start -->
|
|
33
34
|
- **Priorities:** security > correctness > maintainability > convenience. Compromise on the lower
|
|
34
|
-
only to honor the higher, and say so. (`00`)
|
|
35
|
+
only to honor the higher, and say so. ([`00`](./00-priorities.md))
|
|
35
36
|
- **Honesty:** identify uncertainty; verify before claiming (read the file, grep the symbol, run the
|
|
36
|
-
command); never invent facts to sound confident. (`00`)
|
|
37
|
+
command); never invent facts to sound confident. ([`00`](./00-priorities.md))
|
|
37
38
|
- **Discipline:** read before writing; smallest sufficient change (fix ≠ refactor); no silent
|
|
38
|
-
compromises — name every shortcut in plain text. (`00
|
|
39
|
+
compromises — name every shortcut in plain text. ([`00`](./00-priorities.md), [`20`](./20-clean-code.md))
|
|
39
40
|
- **SOLID, in practice:** one reason to change per unit; depend on abstractions at boundaries; keep
|
|
40
|
-
interfaces small and caller-shaped; no god objects or `Manager`/`Helper` catch-alls. (`10`)
|
|
41
|
+
interfaces small and caller-shaped; no god objects or `Manager`/`Helper` catch-alls. ([`10`](./10-solid.md))
|
|
41
42
|
- **Clean code:** names state intent and don't lie; small functions, one level of abstraction;
|
|
42
|
-
comment the *why*, not the *what*; delete dead code rather than commenting it out. (`20`)
|
|
43
|
+
comment the *why*, not the *what*; delete dead code rather than commenting it out. ([`20`](./20-clean-code.md))
|
|
43
44
|
- **Security floor:** validate untrusted input at the trust boundary; parameterize every sink (SQL,
|
|
44
45
|
shell, template, path, HTTP); authorize at the sink; never log secrets; constant-time compare
|
|
45
|
-
secrets; fail closed. (`30`)
|
|
46
|
+
secrets; fail closed. ([`30`](./30-security-owasp.md))
|
|
46
47
|
- **Testing:** risk-driven coverage, not coverage-worship; don't mock what you don't own; tests must
|
|
47
|
-
assert behavior and be deterministic. (`40`)
|
|
48
|
+
assert behavior and be deterministic. ([`40`](./40-engineering-practices.md))
|
|
48
49
|
- **Observability:** structured logs with correlation, low-cardinality metrics, a signal on every
|
|
49
|
-
critical path — "what does on-call see at 3am?" (`40`)
|
|
50
|
+
critical path — "what does on-call see at 3am?" ([`40`](./40-engineering-practices.md))
|
|
50
51
|
- **Dependencies:** a new dependency is a decision — justify it, check its provenance, don't add one
|
|
51
|
-
the hooks would gate. (`40`)
|
|
52
|
+
the hooks would gate. ([`40`](./40-engineering-practices.md))
|
|
52
53
|
- **Collaboration:** challenge the premise, not just the architecture; match the answer to the
|
|
53
54
|
question; recommend with concrete options, the user decides direction; surface tradeoffs and
|
|
54
|
-
blockers in the first line. (`50`)
|
|
55
|
+
blockers in the first line. ([`50`](./50-collaboration.md))
|
|
55
56
|
- **Reasoning craft:** before writing, parse trajectory (what will the reader do with this in 10
|
|
56
57
|
minutes; answer the predictable next question now) → shape (choose the deliverable's form before
|
|
57
58
|
the words; put the answer first) → verify (mark inference as inference; never trade "I confirmed"
|
|
@@ -60,7 +61,8 @@ the full treatment; read that file when you **enter its domain** (see "How to lo
|
|
|
60
61
|
(delete any sentence true of every project), deletion (cut anything whose removal wouldn't change
|
|
61
62
|
what the reader does). At most one metaphor, only if it lets the reader predict something new —
|
|
62
63
|
otherwise name the single axis the decision turns on. As stakes rise, get blunter, not more
|
|
63
|
-
hedged. (`50`)
|
|
64
|
+
hedged. ([`50`](./50-collaboration.md))
|
|
65
|
+
<!-- digest:end -->
|
|
64
66
|
|
|
65
67
|
## What composes this ruleset
|
|
66
68
|
|
|
@@ -120,10 +122,11 @@ treats these as **context to respect**, not competition:
|
|
|
120
122
|
- **Repo-local instructions WIN** over SOMI defaults where they conflict (the project's own
|
|
121
123
|
`CLAUDE.md` already wins per the top of this file). Follow the repo's conventions for naming, error
|
|
122
124
|
handling, testing, dependencies, and structure.
|
|
123
|
-
- **Read them once, carry them forward.**
|
|
124
|
-
and `/plan` on a cold start) distil the relevant conventions into the work item's
|
|
125
|
-
`context.md` so
|
|
126
|
-
of the
|
|
125
|
+
- **Read them once, carry them forward.** `cost: high` actions (`/discover`, `/design`,
|
|
126
|
+
`/refactor-design`, and `/plan` on a cold start) distil the relevant conventions into the work item's
|
|
127
|
+
`brief.md` / `context.md` so `cost: medium` (`/plan`, `/code`) inherits them **without
|
|
128
|
+
re-reading** — this is part of the design→execution economy. The SessionStart hook surfaces which
|
|
129
|
+
files exist.
|
|
127
130
|
- **Do NOT auto-invoke the repo's own agents.** Foreign subagents are unknown-quality and
|
|
128
131
|
untrusted-by-default; surface that they exist and let the user opt into them. Never call them
|
|
129
132
|
silently.
|
|
@@ -151,9 +154,9 @@ See [docs/HOOKS.md](../docs/HOOKS.md) for the full list and how to extend it.
|
|
|
151
154
|
|
|
152
155
|
SOMI provides specialized agents in `agents/`. Use them when the work matches their description:
|
|
153
156
|
|
|
154
|
-
- **`discovery-analyst`** — a new product / greenfield idea needing requirements engineering, competitive research, and high-level design *before* planning (writes `.somi/rd/<slug>/`). Optional and upstream; skip for incremental work with settled requirements.
|
|
155
|
-
- **`designer`** — a feature / user story on an existing codebase that is design-heavy (crosses modules, touches auth/crypto/PII, needs a migration or new contract, or the architecture is open). Compiles the design + the `brief.md`
|
|
156
|
-
- **`planner`** — before writing non-trivial code, or whenever the user asks "how should we approach X".
|
|
157
|
+
- **`discovery-analyst`** — a new product / greenfield idea needing requirements engineering, competitive research, and high-level design *before* planning (writes `.somi/rd/<slug>/`). Optional and upstream; skip for incremental work with settled requirements. **`cost: high`.**
|
|
158
|
+
- **`designer`** — a feature / user story on an existing codebase that is design-heavy (crosses modules, touches auth/crypto/PII, needs a migration or new contract, or the architecture is open). Compiles the design + the `brief.md` execution runs against. Use *before* `/plan` when the architecture isn't settled. **`cost: high`.**
|
|
159
|
+
- **`planner`** — before writing non-trivial code, or whenever the user asks "how should we approach X". **`cost: medium`** — consumes the `brief.md` a `cost: high` action left.
|
|
157
160
|
- **`coder`** — to execute against an approved plan or do a constrained implementation task.
|
|
158
161
|
- **`reviewer`** — before declaring work done; before merging; whenever you want a skeptical second opinion.
|
|
159
162
|
- **`security-reviewer`** — auth, crypto, input handling, third-party data, file uploads, anything touching secrets.
|
|
@@ -173,7 +176,7 @@ Skills under `skills/` are on-demand expert packs. Pull one in when the work cle
|
|
|
173
176
|
- Writing/critiquing requirements or design docs (BRD/SRS/FRD/SDD/TDD) → **`requirements-engineering`**
|
|
174
177
|
- Touching authentication, sessions, input validation, deserialization → **`owasp-defense`**
|
|
175
178
|
- Designing a module, naming a class, deciding what a function should know → **`solid-principles`**, **`clean-code`**
|
|
176
|
-
- Deciding what to test, how to test, whether to mock → **`
|
|
179
|
+
- Deciding what to test, how to test, whether to mock → **`testing-playbook`**
|
|
177
180
|
- Adding/changing an HTTP/gRPC endpoint → **`api-design`**
|
|
178
181
|
- Adding logging, metrics, tracing → **`observability`**
|
|
179
182
|
- Adding a new external integration or attack surface → **`threat-modeling`**
|