@skathio/somi 4.0.0 → 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 (163) 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 +11 -5
  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 +12 -124
  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 +15 -13
  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-cost-lowering.mjs +26 -11
  46. package/hooks/pre-tool/guard-protected-paths.mjs +54 -34
  47. package/hooks/session-start/ensure-default-config.mjs +34 -42
  48. package/package.json +1 -1
  49. package/scripts/lib/config-files.mjs +145 -0
  50. package/scripts/lib/cost-ceiling.mjs +29 -22
  51. package/scripts/lib/cost-defaults.mjs +2 -0
  52. package/scripts/lib/escalation-facts.mjs +146 -0
  53. package/scripts/lib/escalation.mjs +129 -0
  54. package/scripts/lib/findings-ledger.mjs +241 -0
  55. package/scripts/lib/install-text.mjs +97 -0
  56. package/scripts/lib/loop-caps.mjs +140 -0
  57. package/scripts/lib/loop-diff.mjs +12 -70
  58. package/scripts/lib/loop-engine.mjs +226 -0
  59. package/scripts/lib/loop-escalate.mjs +49 -0
  60. package/scripts/lib/loop-exit.mjs +47 -0
  61. package/scripts/lib/loop-notes-compact.mjs +72 -0
  62. package/scripts/lib/loop-notes.mjs +278 -0
  63. package/scripts/lib/loop-review.mjs +355 -12
  64. package/scripts/lib/loop-state.mjs +44 -0
  65. package/scripts/lib/loop-step-close.mjs +75 -0
  66. package/scripts/lib/loop-step-kit.mjs +179 -0
  67. package/scripts/lib/loop-step-review.mjs +140 -0
  68. package/scripts/lib/loop-step-tool.mjs +89 -0
  69. package/scripts/lib/loop-step.mjs +301 -0
  70. package/scripts/lib/mcp-project-root.mjs +18 -7
  71. package/scripts/lib/path-facts.mjs +187 -0
  72. package/scripts/lib/path-safety.mjs +171 -0
  73. package/scripts/lib/run-card.mjs +73 -0
  74. package/scripts/size-budget-overrides.json +5 -13
  75. package/scripts/somi-card.mjs +39 -0
  76. package/scripts/somi-check.mjs +4 -3
  77. package/scripts/somi-config.mjs +113 -50
  78. package/scripts/somi-findings.mjs +56 -271
  79. package/scripts/somi-loop.mjs +77 -446
  80. package/scripts/somi-mcp.mjs +27 -96
  81. package/scripts/validate.sh +92 -54
  82. package/skills/flow-adopt/SKILL.md +92 -0
  83. package/skills/flow-architecture-review/SKILL.md +94 -0
  84. package/skills/flow-atlas/SKILL.md +34 -0
  85. package/skills/flow-code/SKILL.md +167 -0
  86. package/skills/flow-code-loop/SKILL.md +263 -0
  87. package/skills/flow-code-parallel/SKILL.md +160 -0
  88. package/skills/flow-debug/SKILL.md +141 -0
  89. package/skills/flow-design/SKILL.md +170 -0
  90. package/skills/flow-discover/SKILL.md +204 -0
  91. package/skills/flow-impact/SKILL.md +35 -0
  92. package/skills/flow-incident/SKILL.md +49 -0
  93. package/skills/flow-plan/SKILL.md +254 -0
  94. package/skills/flow-plan-loop/SKILL.md +254 -0
  95. package/skills/flow-pr/SKILL.md +34 -0
  96. package/skills/flow-refactor/SKILL.md +58 -0
  97. package/skills/flow-refactor-design/SKILL.md +97 -0
  98. package/skills/flow-release-readiness/SKILL.md +82 -0
  99. package/skills/flow-review/SKILL.md +193 -0
  100. package/skills/flow-review-panel/SKILL.md +154 -0
  101. package/skills/flow-security-review/SKILL.md +83 -0
  102. package/skills/flow-ship/SKILL.md +125 -0
  103. package/skills/flow-ship-loop/SKILL.md +274 -0
  104. package/skills/flow-somi-config/SKILL.md +142 -0
  105. package/skills/flow-status/SKILL.md +43 -0
  106. package/skills/flow-test-strategy/SKILL.md +83 -0
  107. package/skills/flow-upgrade/SKILL.md +82 -0
  108. package/skills/role-coder/SKILL.md +247 -0
  109. package/skills/role-designer/SKILL.md +172 -0
  110. package/skills/role-discovery-analyst/SKILL.md +288 -0
  111. package/skills/role-planner/SKILL.md +353 -0
  112. package/skills/role-reviewer/SKILL.md +218 -0
  113. package/skills/somi-checkpoint/SKILL.md +95 -0
  114. package/skills/somi-dispatch/SKILL.md +14 -14
  115. package/skills/somi-routing/SKILL.md +6 -2
  116. package/tests/hooks/cases/block-secret-writes.json +6 -1
  117. package/tests/hooks/cases/guard-protected-paths.json +44 -2
  118. package/tests/hooks/run.sh +21 -0
  119. package/tests/scripts/checkpoint-gate.sh +2 -2
  120. package/tests/scripts/cost-defaults.sh +2 -0
  121. package/tests/scripts/cost-hardcap.sh +26 -17
  122. package/tests/scripts/dispatch-line-gate.sh +4 -4
  123. package/tests/scripts/dispatch-reference-gate.sh +14 -14
  124. package/tests/scripts/ensure-default-config.sh +4 -4
  125. package/tests/scripts/escalation.sh +409 -0
  126. package/tests/scripts/eval-runner.sh +8 -7
  127. package/tests/scripts/fact-sheet.sh +296 -0
  128. package/tests/scripts/global-config.sh +167 -0
  129. package/tests/scripts/goldens/somi-loop.json +2 -2
  130. package/tests/scripts/lib/dispatch-reference-gate.mjs +14 -5
  131. package/tests/scripts/lib/escalation-facts-tests.mjs +140 -0
  132. package/tests/scripts/lib/escalation-tests.mjs +154 -0
  133. package/tests/scripts/lib/findings-ledger-tests.mjs +118 -0
  134. package/tests/scripts/lib/loop-engine-tests.mjs +287 -0
  135. package/tests/scripts/lib/loop-escalate-tests.mjs +356 -0
  136. package/tests/scripts/lib/loop-flow-gate.mjs +173 -0
  137. package/tests/scripts/lib/loop-notes-tests.mjs +371 -0
  138. package/tests/scripts/lib/loop-step-cli-tests.mjs +141 -0
  139. package/tests/scripts/lib/loop-step-close-tests.mjs +351 -0
  140. package/tests/scripts/lib/loop-step-lenient-tests.mjs +114 -0
  141. package/tests/scripts/lib/loop-step-state-tests.mjs +127 -0
  142. package/tests/scripts/lib/loop-step-tests.mjs +499 -0
  143. package/tests/scripts/lib/loop-step-unwritten-tests.mjs +55 -0
  144. package/tests/scripts/lib/path-facts-tests.mjs +198 -0
  145. package/tests/scripts/lib/path-safety-tests.mjs +201 -0
  146. package/tests/scripts/lib/run-suites.mjs +139 -0
  147. package/tests/scripts/lib/site-roadmap-gate.mjs +64 -0
  148. package/tests/scripts/lib/sizing-score-tests.mjs +210 -0
  149. package/tests/scripts/lib/sizing-set-tests.mjs +131 -0
  150. package/tests/scripts/lib/somi-mcp-loop-tests.mjs +226 -0
  151. package/tests/scripts/lib/somi-mcp-tests.mjs +21 -1
  152. package/tests/scripts/loop-engine.sh +22 -0
  153. package/tests/scripts/loop-flow-gate.sh +11 -0
  154. package/tests/scripts/review-panel-seats.sh +4 -4
  155. package/tests/scripts/run-card.sh +57 -0
  156. package/tests/scripts/run-suites.sh +74 -0
  157. package/tests/scripts/run.sh +11 -0
  158. package/tests/scripts/site-roadmap-gate.sh +76 -0
  159. package/tests/scripts/size-tier.sh +3 -3
  160. package/tests/scripts/somi-agent-dispatch-contract.sh +23 -3
  161. package/tests/scripts/somi-config.sh +9 -4
  162. package/tests/scripts/somi-mcp.sh +1 -0
  163. package/tests/scripts/suite-plan.json +20 -0
@@ -27,7 +27,7 @@ verdict() {
27
27
 
28
28
  mutant() { # $1 = name, $2 = sed expression deleting one check; builds $TMP/$1 from the real lib
29
29
  mkdir -p "$TMP/$1"
30
- cp "$LIB_SRC/cost-ceiling.mjs" "$LIB_SRC/cost-model.mjs" "$LIB_SRC/cost-config.mjs" "$TMP/$1/"
30
+ cp "$LIB_SRC/cost-ceiling.mjs" "$LIB_SRC/cost-model.mjs" "$LIB_SRC/cost-config.mjs" "$LIB_SRC/config-files.mjs" "$TMP/$1/"
31
31
  sed -i "$2" "$TMP/$1/cost-config.mjs"
32
32
  cmp -s "$LIB_SRC/cost-config.mjs" "$TMP/$1/cost-config.mjs" && { bad "mutant $1 did not change the file"; return 1; }
33
33
  return 0
@@ -88,7 +88,7 @@ eq() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1 (want '$3', got '$2')"; fi
88
88
 
89
89
  # Red proofs: each mutant breaks exactly one rule in a COPY of the lib; the real case must then fail.
90
90
  mutant_sel() { # $1 = name, $2 = replacement for the selection expression
91
- mkdir -p "$TMP/$1"; cp "$LIB_SRC/cost-ceiling.mjs" "$LIB_SRC/cost-model.mjs" "$LIB_SRC/cost-config.mjs" "$TMP/$1/"
91
+ mkdir -p "$TMP/$1"; cp "$LIB_SRC/cost-ceiling.mjs" "$LIB_SRC/cost-model.mjs" "$LIB_SRC/cost-config.mjs" "$LIB_SRC/config-files.mjs" "$TMP/$1/"
92
92
  sed -i "s/const selected = override === undefined ? ceiling : override;/const selected = $2;/" "$TMP/$1/cost-ceiling.mjs"
93
93
  cmp -s "$LIB_SRC/cost-ceiling.mjs" "$TMP/$1/cost-ceiling.mjs" && bad "mutant $1 did not change the file"
94
94
  }
@@ -174,15 +174,15 @@ P="$(proj)"; big 60000 > "$P/.somi/config.json"; rc=0
174
174
  cli "$P" --agent somi-coder >/dev/null 2>&1 || rc=$?
175
175
  eq "a config.json under the cap (60000 bytes) is still read" "$rc" "0"
176
176
  # Red proof: raise the cap in a copy and the oversize file is accepted.
177
- mkdir -p "$TMP/nocap"; cp "$LIB_SRC"/cost-*.mjs "$TMP/nocap/"
178
- sed -i 's/64 \* 1024/64 * 1024 * 1024/' "$TMP/nocap/cost-ceiling.mjs"
177
+ mkdir -p "$TMP/nocap"; cp "$LIB_SRC"/cost-*.mjs "$LIB_SRC/config-files.mjs" "$TMP/nocap/"
178
+ sed -i 's/64 \* 1024/64 * 1024 * 1024/' "$TMP/nocap/config-files.mjs"
179
179
  P="$(proj)"; big 70000 > "$P/.somi/config.json"
180
180
  eq "red proof (size cap): without the cap the 70000-byte file is read" \
181
181
  "$(node --input-type=module -e "
182
182
  const C = await import('$TMP/nocap/cost-ceiling.mjs');
183
183
  try { C.readCostConfig('$P'); console.log('ok'); } catch (e) { console.log('reject'); }")" "ok"
184
184
 
185
- # ---- the read is fd-based: boundary sizes, symlinks refused, non-regular files refused ----------
185
+ # ---- the read is fd-based: boundary sizes, links followed, non-regular files refused ------------
186
186
  exact() { local pre='{"cost":{"ceiling":"low"},"pad":"' suf='"}'; printf '%s' "$pre"; head -c "$(( $1 - ${#pre} - ${#suf} ))" /dev/zero | tr '\0' 'x'; printf '%s' "$suf"; }
187
187
  P="$(proj)"; exact 65536 > "$P/.somi/config.json"; rc=0
188
188
  cli "$P" --agent somi-coder >/dev/null 2>&1 || rc=$?
@@ -191,13 +191,21 @@ P="$(proj)"; exact 65537 > "$P/.somi/config.json"; rc=0
191
191
  cli "$P" --agent somi-coder >/dev/null 2>&1 || rc=$?
192
192
  eq "a config.json of 65537 bytes is rejected with 67" "$rc" "67"
193
193
 
194
+ # Config reads follow links (a junction or symlinked .somi, a linked config file); what a link could
195
+ # abuse -- a device or FIFO that never ends, an endless read -- is refused on the open descriptor.
194
196
  P="$(proj)"; ln -s /dev/zero "$P/.somi/config.json"; rc=0
195
197
  timeout 10 env CLAUDE_PROJECT_DIR="$P" env -u SOMI_COST_CEILING node "$CLI" resolve --agent somi-coder >"$TMP/sym.out" 2>"$TMP/sym.err" || rc=$?
196
198
  eq "a config.json symlink to /dev/zero is rejected quickly with 67 (no timeout)" "$rc" "67"
197
- eq "... and the message says it refuses a symlink" "$(grep -c 'symlink' "$TMP/sym.err")" "1"
199
+ eq "... and the message says it is not a regular file" "$(grep -c 'not a regular file' "$TMP/sym.err")" "1"
200
+ P="$(proj)"; rm -f "$P/.somi/config.json"; mkfifo "$P/.somi/config.json"; rc=0
201
+ timeout 10 env CLAUDE_PROJECT_DIR="$P" env -u SOMI_COST_CEILING node "$CLI" resolve --agent somi-coder >/dev/null 2>"$TMP/fifo.err" || rc=$?
202
+ eq "a config.json that is a FIFO is rejected quickly with 67 (the open does not block)" "$rc" "67"
198
203
  P="$(proj '{"cost":{"ceiling":"low"}}')"; mv "$P/.somi/config.json" "$P/real.json"; ln -s ../real.json "$P/.somi/config.json"; rc=0
199
- cli "$P" --agent somi-coder >/dev/null 2>&1 || rc=$?
200
- eq "a symlink to an ordinary valid config is refused too" "$rc" "67"
204
+ out="$(cli "$P" --agent somi-coder 2>/dev/null)" || rc=$?
205
+ eq "a symlink to an ordinary valid config is read" "$rc|$(printf '%s' "$out" | grep -o '"tier":"[a-z]*"')" '0|"tier":"low"'
206
+ P="$(mktemp -d -p "$TMP")"; SHARED="$(mktemp -d -p "$TMP")"; printf '{"cost":{"ceiling":"low"}}' > "$SHARED/config.json"; ln -s "$SHARED" "$P/.somi"; rc=0
207
+ out="$(cli "$P" --agent somi-coder 2>/dev/null)" || rc=$?
208
+ eq "a .somi that is a link to another directory (a junction on Windows) is read through" "$rc|$(printf '%s' "$out" | grep -o '"tier":"[a-z]*"')" '0|"tier":"low"'
201
209
  P="$(proj)"; mkdir "$P/.somi/config.json"; rc=0
202
210
  cli "$P" --agent somi-coder >"$TMP/dir.out" 2>"$TMP/dir.err" || rc=$?
203
211
  eq "a config.json that is a directory is rejected with 67" "$rc" "67"
@@ -207,14 +215,15 @@ verdict_file() { # $1 = lib dir, $2 = project root -> ok | reject: msg
207
215
  const C = await import('$1/cost-ceiling.mjs');
208
216
  try { C.readCostConfig('$2'); console.log('ok'); } catch (e) { console.log('reject: ' + e.message); }"
209
217
  }
210
- mkdir -p "$TMP/nofollow" "$TMP/nofile"
211
- cp "$LIB_SRC"/cost-*.mjs "$TMP/nofollow/"; cp "$LIB_SRC"/cost-*.mjs "$TMP/nofile/"
212
- sed -i 's/(fs.constants.O_NOFOLLOW ?? 0)/0/' "$TMP/nofollow/cost-ceiling.mjs"
213
- sed -i 's/!fs.fstatSync(fd).isFile()/false/' "$TMP/nofile/cost-ceiling.mjs"
214
- cmp -s "$LIB_SRC/cost-ceiling.mjs" "$TMP/nofollow/cost-ceiling.mjs" && bad "mutant nofollow did not change the file"
215
- cmp -s "$LIB_SRC/cost-ceiling.mjs" "$TMP/nofile/cost-ceiling.mjs" && bad "mutant nofile did not change the file"
216
- P="$(proj '{"cost":{"ceiling":"low"}}')"; mv "$P/.somi/config.json" "$P/real.json"; ln -s ../real.json "$P/.somi/config.json"
217
- eq "red proof (O_NOFOLLOW): without it the symlinked config is followed and accepted" "$(verdict_file "$TMP/nofollow" "$P")" "ok"
218
+ mkdir -p "$TMP/nofile" "$TMP/blocking"
219
+ cp "$LIB_SRC"/cost-*.mjs "$LIB_SRC/config-files.mjs" "$TMP/nofile/"; cp "$LIB_SRC"/cost-*.mjs "$LIB_SRC/config-files.mjs" "$TMP/blocking/"
220
+ sed -i 's/!fs.fstatSync(fd).isFile()/false/' "$TMP/nofile/config-files.mjs"
221
+ sed -i 's/fs.constants.O_RDONLY | (fs.constants.O_NONBLOCK ?? 0)/fs.constants.O_RDONLY/' "$TMP/blocking/config-files.mjs"
222
+ cmp -s "$LIB_SRC/config-files.mjs" "$TMP/nofile/config-files.mjs" && bad "mutant nofile did not change the file"
223
+ cmp -s "$LIB_SRC/config-files.mjs" "$TMP/blocking/config-files.mjs" && bad "mutant blocking did not change the file"
224
+ P="$(proj)"; rm -f "$P/.somi/config.json"; mkfifo "$P/.somi/config.json"; rc=0
225
+ timeout 5 node --input-type=module -e "const C = await import('$TMP/blocking/cost-ceiling.mjs'); try { C.readCostConfig('$P'); } catch {}" >/dev/null 2>&1 || rc=$?
226
+ eq "red proof (O_NONBLOCK): without it a FIFO config hangs the read (timeout)" "$rc" "124"
218
227
  P="$(proj)"; mkdir "$P/.somi/config.json"
219
228
  case "$(verdict_file "$LIB_SRC" "$P")" in *"not a regular file"*) ok "a directory config is rejected by the regular-file check" ;; *) bad "a directory config is rejected by the regular-file check" ;; esac
220
229
  case "$(verdict_file "$TMP/nofile" "$P")" in *"not a regular file"*) bad "red proof (isFile): the regular-file message persists without the check" ;; *) ok "red proof (isFile): without the check the regular-file rejection is gone" ;; esac
@@ -239,7 +248,7 @@ pj() { # $1 = config body or '', $2 = state body or ''
239
248
  echo "$r"
240
249
  }
241
250
  mut_prec() { # $1 = name, $2 = sed expression
242
- mkdir -p "$TMP/$1"; cp "$LIB_SRC"/cost-*.mjs "$TMP/$1/"; sed -i "$2" "$TMP/$1/cost-ceiling.mjs"
251
+ mkdir -p "$TMP/$1"; cp "$LIB_SRC"/cost-*.mjs "$LIB_SRC/config-files.mjs" "$TMP/$1/"; sed -i "$2" "$TMP/$1/cost-ceiling.mjs"
243
252
  cmp -s "$LIB_SRC/cost-ceiling.mjs" "$TMP/$1/cost-ceiling.mjs" && bad "mutant $1 did not change the file"
244
253
  }
245
254
  mut_prec config-ignored 's/^ if (isConfigured) {$/ if (false) {/'
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bash
2
2
  # Gate for the one dispatch line (#38) and native dispatch: the canonical "pass its `model`, start it as
3
3
  # its `agent_type`, and put the cost line ..." phrase lives once, between markers in
4
- # skills/somi-dispatch/SKILL.md, and every copy in commands/*.md and agents/somi.md must match it
4
+ # skills/somi-dispatch/SKILL.md, and every copy in skills/flow-*/SKILL.md and the dispatcher and runner agents must match it
5
5
  # (whitespace and blockquote markers aside); every command that names the cost line names it through
6
6
  # that phrase; the three agents that trim at `low` carry the same requested-tier disclosure; and no
7
7
  # dispatch text calls somi_agent to stand in for an agent. Proven red on mutated copies.
@@ -26,7 +26,7 @@ const m = /<!-- dispatch-line:start -->\n([\s\S]*?)\n<!-- dispatch-line:end -->/
26
26
  if (!m) { console.log('skills/somi-dispatch/SKILL.md: no dispatch-line markers'); process.exit(0); }
27
27
  const canon = norm(m[1]).trim();
28
28
  const COST = 'requested cost: <tier> (not enforced: no mapped model)';
29
- const files = [...fs.readdirSync(path.join(root, 'commands')).filter((f) => f.endsWith('.md')).map((f) => `commands/${f}`), 'agents/somi.md'];
29
+ const files = [...fs.readdirSync(path.join(root, 'skills')).filter((d) => d.startsWith('flow-')).map((d) => `skills/${d}/SKILL.md`), 'agents/somi.md', 'agents/somi-flow.md'];
30
30
  for (const f of files) {
31
31
  const t = norm(read(f));
32
32
  const costLines = t.split(COST).length - 1;
@@ -52,9 +52,9 @@ red() { # $1 = label, $2 = mutation run inside a copy
52
52
  (cd "$TMP/r" && eval "$2")
53
53
  if [ -n "$(gate "$TMP/r")" ]; then ok "red proof: $1"; else bad "red proof: $1 (not caught)"; fi
54
54
  }
55
- red "a command whose copy drifted (agent_type dropped)" "sed -i 's/, start it as its \`agent_type\`,/,/' commands/plan.md"
55
+ red "a command whose copy drifted (agent_type dropped)" "sed -i 's/, start it as its \`agent_type\`,/,/' skills/flow-plan/SKILL.md"
56
56
  red "the canonical phrase edited in the skill only" "sed -i 's/start it as its \`agent_type\`, and put/start it as its \`agent_type\` and put/' skills/somi-dispatch/SKILL.md"
57
- red "a command that hands agent text to somi_agent" "printf 'call somi_agent({name: \"somi-coder\"}) and start a general-purpose agent\n' >> commands/code.md"
57
+ red "a command that hands agent text to somi_agent" "printf 'call somi_agent({name: \"somi-coder\"}) and start a general-purpose agent\n' >> skills/flow-code/SKILL.md"
58
58
  red "a missing requested-low disclosure" "sed -i 's/requested, not enforced: the host chose the model/requested/' agents/somi-planner.md"
59
59
 
60
60
  echo "dispatch-line-gate tests: $pass ok, $fail failed"
@@ -100,13 +100,13 @@ else
100
100
  bad "synthetic call-site cases: $unit_bad mismatch(es) -- see MISMATCH lines above"
101
101
  fi
102
102
 
103
- # --- fixture-level: a `cp -a` copy of the real commands/ + agents/ -------------------------------
104
- cp -a "$ROOT/commands" "$TMP/commands"
103
+ # --- fixture-level: a `cp -a` copy of the real skills/ + agents/ -------------------------------
104
+ cp -a "$ROOT/skills" "$TMP/skills"
105
105
  cp -a "$ROOT/agents" "$TMP/agents"
106
106
 
107
107
  # --- GREEN: the unmodified copy passes -----------------------------------------------------------
108
- if out_green="$(node "$GATE" "$TMP/commands" "$TMP/agents" 2>&1)"; then
109
- ok "gate exits 0 against an unmodified cp -a copy of the real commands/ + agents/"
108
+ if out_green="$(node "$GATE" "$TMP/skills" "$TMP/agents" 2>&1)"; then
109
+ ok "gate exits 0 against an unmodified cp -a copy of the real skills/ + agents/"
110
110
  else
111
111
  bad "gate exited non-zero against an unmodified copy (got: $out_green)"
112
112
  fi
@@ -129,27 +129,27 @@ else
129
129
  bad "expected at least 21 commands derived as starting an agent, got $checked_count -- the call-site pattern derivation may have regressed"
130
130
  fi
131
131
 
132
- # --- RED: removing commands/code.md's dispatch reference must fail ------------------------------
132
+ # --- RED: removing skills/flow-code/SKILL.md's dispatch reference must fail ------------------------------
133
133
  # Strips BOTH satisfying tokens, not just one -- the gate now accepts either "skills/somi-dispatch"
134
134
  # or "somi_resolve" (DISPATCH_REFERENCE_RE), so a fixture that only strips lines mentioning
135
135
  # "somi-dispatch" would leave a bare "somi_resolve" mention behind and this RED case would no
136
136
  # longer actually go red.
137
- sed -i -E '/somi-dispatch|somi_resolve/d' "$TMP/commands/code.md"
138
- out_red="$(node "$GATE" "$TMP/commands" "$TMP/agents" 2>&1)"; rc_red=$?
137
+ sed -i -E '/somi-dispatch|somi_resolve/d' "$TMP/skills/flow-code/SKILL.md"
138
+ out_red="$(node "$GATE" "$TMP/skills" "$TMP/agents" 2>&1)"; rc_red=$?
139
139
  if [ "$rc_red" -eq 1 ]; then
140
- ok "gate exits 1 once commands/code.md's dispatch reference is removed"
140
+ ok "gate exits 1 once skills/flow-code/SKILL.md's dispatch reference is removed"
141
141
  else
142
- bad "gate did not exit 1 after removing commands/code.md's reference (rc=$rc_red, out=$out_red)"
142
+ bad "gate did not exit 1 after removing skills/flow-code/SKILL.md's reference (rc=$rc_red, out=$out_red)"
143
143
  fi
144
144
  case "$out_red" in
145
- *"MISSING DISPATCH REFERENCE: code.md"*) ok "gate names code.md as missing the dispatch reference" ;;
145
+ *"MISSING DISPATCH REFERENCE: flow-code/SKILL.md"*) ok "gate names code.md as missing the dispatch reference" ;;
146
146
  *) bad "gate's output does not name code.md as missing the reference (got: $out_red)" ;;
147
147
  esac
148
148
 
149
149
  # --- RED fixture does not spuriously flag OTHER commands (only code.md was touched) --------------
150
150
  case "$out_red" in
151
151
  *"MISSING DISPATCH REFERENCE"*"MISSING DISPATCH REFERENCE"*)
152
- bad "more than one command flagged missing -- only commands/code.md was modified (got: $out_red)" ;;
152
+ bad "more than one command flagged missing -- only skills/flow-code/SKILL.md was modified (got: $out_red)" ;;
153
153
  *)
154
154
  ok "exactly one command (code.md) is flagged, not a spurious wider failure" ;;
155
155
  esac
@@ -159,12 +159,12 @@ router_out="$(node --input-type=module -e '
159
159
  import { agentStartedBy, agentNamesFrom } from "'"$GATE"'";
160
160
  const names = agentNamesFrom("'"$TMP"'/agents");
161
161
  import fs from "node:fs";
162
- const text = fs.readFileSync("'"$TMP"'/commands/ship.md", "utf8");
162
+ const text = fs.readFileSync("'"$TMP"'/skills/flow-ship/SKILL.md", "utf8");
163
163
  console.log(agentStartedBy(text, names) === null ? "EXCLUDED" : "FALSE POSITIVE");
164
164
  ' 2>&1)"
165
165
  case "$router_out" in
166
- EXCLUDED) ok "commands/ship.md (a router -- Tasks other commands, never an agent) is correctly excluded" ;;
167
- *) bad "commands/ship.md was NOT excluded (got: $router_out) -- a router must never be misdiagnosed as starting an agent" ;;
166
+ EXCLUDED) ok "skills/flow-ship/SKILL.md (a router -- Tasks other commands, never an agent) is correctly excluded" ;;
167
+ *) bad "skills/flow-ship/SKILL.md was NOT excluded (got: $router_out) -- a router must never be misdiagnosed as starting an agent" ;;
168
168
  esac
169
169
 
170
170
  bash "$ROOT/tests/scripts/review-panel-seats.sh" || fail=$((fail+1))
@@ -129,14 +129,14 @@ check "an unexpanded \${...} root falls back to the working directory (no litera
129
129
  # --- red proofs: each safety check removed from a copy must be caught -----------------------------
130
130
  mutant() { # $1 = name, $2 = sed expression -> $TMP/$1/hooks/session-start/ensure-default-config.mjs (a copy inside a plugin-shaped tree)
131
131
  local d="$TMP/$1"; mkdir -p "$d/hooks/session-start" "$d/hooks/lib" "$d/scripts/lib"
132
- cp "$ROOT_REPO/hooks/lib/common.mjs" "$d/hooks/lib/"; cp "$ROOT_REPO"/scripts/lib/cost-*.mjs "$d/scripts/lib/"
132
+ cp "$ROOT_REPO/hooks/lib/common.mjs" "$d/hooks/lib/"; cp "$ROOT_REPO"/scripts/lib/cost-*.mjs "$ROOT_REPO/scripts/lib/config-files.mjs" "$d/scripts/lib/"
133
133
  sed "$2" "$HOOK_SRC" > "$d/hooks/session-start/ensure-default-config.mjs"
134
134
  cmp -s "$HOOK_SRC" "$d/hooks/session-start/ensure-default-config.mjs" && bad "mutant $1 did not change the hook"
135
135
  }
136
136
  mutant no-excl "s/ | fs.constants.O_EXCL//"
137
137
  mutant no-nofollow "s/ | (fs.constants.O_NOFOLLOW ?? 0)//"
138
138
  mutant no-somi-check "s/if (dir \&\& !dir.isDirectory()) return;//"
139
- mutant overwrite "s/if (existing) {/if (false) {/; s/ | fs.constants.O_EXCL/ | fs.constants.O_TRUNC/"
139
+ mutant overwrite "s/if (existing || hasGlobal) {/if (false) {/; s/ | fs.constants.O_EXCL/ | fs.constants.O_TRUNC/"
140
140
  M="$TMP/no-somi-check/hooks/session-start/ensure-default-config.mjs"
141
141
  P="$(proj)"; OUTSIDE="$(mktemp -d -p "$TMP")"; ln -s "$OUTSIDE" "$P/.somi"; runhook "$M" "$P" > /dev/null
142
142
  check "red proof: without the .somi check a symlinked .somi is written through" "$([ -e "$OUTSIDE/config.json" ] && echo written || echo clean)" "written"
@@ -146,10 +146,10 @@ check "red proof: without the exists-check and O_EXCL an existing file is overwr
146
146
  M="$TMP/no-excl/hooks/session-start/ensure-default-config.mjs"
147
147
  P="$(proj)"; mkdir "$P/.somi"; printf 'OLD-CONTENT-LONGER-THAN-NOTHING' > "$P/.somi/config.json"
148
148
  # the exists-check still stops it, so remove that too: only O_EXCL is the last line of defence against a race
149
- sed -i 's/if (existing) {/if (false) {/' "$M"; runhook "$M" "$P" > /dev/null
149
+ sed -i 's/if (existing || hasGlobal) {/if (false) {/' "$M"; runhook "$M" "$P" > /dev/null
150
150
  check "red proof: without O_EXCL (and the early check) an existing file is rewritten" "$(cmp -s "$P/.somi/config.json" "$EXPECT" && echo overwritten || echo kept)" "overwritten"
151
151
  M="$TMP/no-nofollow/hooks/session-start/ensure-default-config.mjs"
152
- sed -i 's/if (existing) {/if (false) {/; s/ | fs.constants.O_EXCL//' "$M"
152
+ sed -i 's/if (existing || hasGlobal) {/if (false) {/; s/ | fs.constants.O_EXCL//' "$M"
153
153
  P="$(proj)"; mkdir "$P/.somi"; echo KEEP2 > "$TMP/victim2.txt"; ln -s "$TMP/victim2.txt" "$P/.somi/config.json"; runhook "$M" "$P" > /dev/null
154
154
  check "red proof: without O_NOFOLLOW (and O_EXCL, early check) a symlink at config.json is written through" "$([ "$(cat "$TMP/victim2.txt")" = KEEP2 ] && echo kept || echo written)" "written"
155
155