@skathio/somi 3.1.0 → 4.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/settings.json +13 -0
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/.copilot-extension/extension.json +1 -1
- package/.copilot-extension/marketplace.json +2 -2
- package/README.md +28 -23
- package/VERSION +1 -1
- package/agents/{architecture-reviewer.md → somi-architecture-reviewer.md} +10 -11
- package/agents/{atlas.md → somi-atlas.md} +3 -5
- package/agents/{coder.md → somi-coder.md} +29 -26
- package/agents/{designer.md → somi-designer.md} +9 -11
- package/agents/{discovery-analyst.md → somi-discovery-analyst.md} +7 -9
- package/agents/{impact.md → somi-impact.md} +6 -8
- package/agents/{incident.md → somi-incident.md} +2 -4
- package/agents/{plan-reviewer.md → somi-plan-reviewer.md} +9 -11
- package/agents/{planner.md → somi-planner.md} +19 -27
- package/agents/{pr.md → somi-pr.md} +2 -4
- package/agents/{refactor-designer.md → somi-refactor-designer.md} +14 -15
- package/agents/{refactorer.md → somi-refactorer.md} +14 -15
- package/agents/{reviewer.md → somi-reviewer.md} +8 -7
- package/agents/{sdlc-reviewer.md → somi-sdlc-reviewer.md} +8 -10
- package/agents/{security-reviewer.md → somi-security-reviewer.md} +8 -8
- package/agents/{test-strategist.md → somi-test-strategist.md} +4 -6
- package/agents/somi.md +27 -14
- package/commands/adopt.md +9 -10
- package/commands/architecture-review.md +4 -5
- package/commands/atlas.md +3 -4
- package/commands/code-loop.md +38 -14
- package/commands/code-parallel.md +4 -4
- package/commands/code.md +24 -15
- package/commands/debug.md +8 -9
- package/commands/design.md +14 -15
- package/commands/discover.md +11 -12
- package/commands/impact.md +2 -3
- package/commands/incident.md +3 -4
- package/commands/plan-loop.md +16 -12
- package/commands/plan.md +15 -16
- package/commands/pr.md +2 -3
- package/commands/refactor-design.md +10 -11
- package/commands/refactor.md +7 -8
- package/commands/release-readiness.md +6 -7
- package/commands/review-panel.md +24 -23
- package/commands/review.md +14 -14
- package/commands/security-review.md +8 -7
- package/commands/ship-loop.md +107 -28
- package/commands/ship.md +6 -6
- package/commands/somi-config.md +131 -0
- package/commands/test-strategy.md +3 -4
- package/commands/upgrade.md +4 -5
- package/examples/code-review-example.md +1 -1
- package/examples/discovery-example.md +1 -1
- package/examples/feature-plan-example.md +2 -2
- package/hooks/hooks.json +14 -1
- package/hooks/lib/common.mjs +64 -1
- package/hooks/post-tool/audit-log.mjs +3 -2
- package/hooks/pre-tool/block-secret-writes.mjs +12 -11
- package/hooks/pre-tool/guard-cost-lowering.mjs +177 -0
- package/hooks/pre-tool/guard-protected-paths.mjs +13 -3
- package/hooks/session-start/detect-repo-instructions.mjs +27 -2
- package/hooks/session-start/ensure-default-config.mjs +121 -0
- package/package.json +1 -1
- package/rules/00-priorities.md +1 -1
- package/rules/30-security-owasp.md +1 -1
- package/rules/50-collaboration.md +9 -6
- package/rules/CLAUDE.md +11 -10
- package/scripts/lib/agent-info.mjs +85 -0
- package/scripts/lib/agent-registry.mjs +92 -0
- package/scripts/lib/cost-ceiling.mjs +175 -171
- package/scripts/lib/cost-config-edit.mjs +102 -0
- package/scripts/lib/cost-config.mjs +64 -0
- package/scripts/lib/cost-defaults.mjs +51 -0
- package/scripts/lib/cost-lowering.mjs +89 -0
- package/scripts/lib/cost-model.mjs +37 -22
- package/scripts/lib/dispatch-resolver.mjs +68 -50
- package/scripts/lib/loop-diff.mjs +96 -0
- package/scripts/lib/loop-dispatch.mjs +19 -0
- package/scripts/lib/loop-review.mjs +52 -0
- package/scripts/lib/run-budget.mjs +28 -0
- package/scripts/lib/size-tier.mjs +184 -0
- package/scripts/lib/tier-record.mjs +82 -0
- package/scripts/size-budget-overrides.json +7 -15
- package/scripts/somi-config.mjs +358 -0
- package/scripts/somi-dispatch.mjs +1 -1
- package/scripts/somi-loop.mjs +71 -96
- package/scripts/somi-mcp.mjs +135 -14
- package/scripts/somi-tier.mjs +393 -0
- package/scripts/validate.sh +37 -215
- package/skills/api-design/SKILL.md +1 -1
- package/skills/clean-code/SKILL.md +1 -1
- package/skills/market-research/SKILL.md +2 -2
- package/skills/owasp-defense/SKILL.md +2 -2
- package/skills/plan-review/SKILL.md +5 -1
- package/skills/reasoning-craft/SKILL.md +1 -1
- package/skills/requirements-engineering/SKILL.md +3 -3
- package/skills/solid-principles/SKILL.md +1 -1
- package/skills/somi-dispatch/SKILL.md +116 -87
- package/skills/somi-routing/SKILL.md +88 -1
- package/skills/testing-playbook/SKILL.md +2 -2
- package/skills/threat-modeling/SKILL.md +3 -3
- package/templates/BRIEF.md.tmpl +2 -2
- package/templates/DESIGN.md.tmpl +1 -1
- package/templates/DOD.md.tmpl +2 -2
- package/templates/PHASE.md.tmpl +2 -2
- package/templates/RCA.md.tmpl +1 -1
- package/templates/REVIEW.md.tmpl +3 -2
- package/templates/SDD.md.tmpl +1 -1
- package/templates/SPEC.md.tmpl +1 -1
- package/templates/TDD.md.tmpl +1 -1
- package/tests/hooks/cases/block-secret-writes.json +130 -17
- package/tests/hooks/cases/detect-repo-instructions.json +22 -1
- package/tests/hooks/cases/guard-protected-paths.json +175 -25
- package/tests/scripts/agent-model-frontmatter.sh +38 -0
- package/tests/scripts/agent-names.sh +77 -0
- package/tests/scripts/check-frontmatter.sh +1 -1
- package/tests/scripts/checkpoint-gate.sh +44 -3
- package/tests/scripts/convergence-runner.sh +10 -6
- package/tests/scripts/cost-ceiling.sh +127 -215
- package/tests/scripts/cost-defaults.sh +128 -0
- package/tests/scripts/cost-hardcap.sh +329 -0
- package/tests/scripts/cost-lowering.sh +261 -0
- package/tests/scripts/cost-model.sh +18 -14
- package/tests/scripts/dispatch-guard.sh +7 -7
- package/tests/scripts/dispatch-line-gate.sh +61 -0
- package/tests/scripts/dispatch-reference-gate.sh +13 -13
- package/tests/scripts/ensure-default-config.sh +162 -0
- package/tests/scripts/eval-runner.sh +9 -9
- package/tests/scripts/evals-packaging.sh +127 -20
- package/tests/scripts/fixtures/size-tier-cases.json +87 -0
- package/tests/scripts/goldens/loop-state-done.json +1 -1
- package/tests/scripts/goldens/somi-loop.json +3 -3
- package/tests/scripts/lib/agent-registry-tests.mjs +95 -0
- package/tests/scripts/lib/brief-only-guard.mjs +27 -0
- package/tests/scripts/lib/checkpoint-gate.mjs +40 -3
- package/tests/scripts/lib/dispatch-reference-gate.mjs +5 -5
- package/tests/scripts/lib/retirement-gate.mjs +7 -2
- package/tests/scripts/lib/ship-loop-sizing-guard.mjs +52 -0
- package/tests/scripts/lib/size-tier-drift.mjs +74 -0
- package/tests/scripts/lib/somi-mcp-config-tests.mjs +92 -0
- package/tests/scripts/lib/somi-mcp-tests.mjs +80 -25
- package/tests/scripts/lib/somi-mcp-tier-tests.mjs +64 -0
- package/tests/scripts/retirement-gate.sh +19 -0
- package/tests/scripts/review-panel-seats.sh +2 -2
- package/tests/scripts/run.sh +95 -0
- package/tests/scripts/size-tier.sh +562 -0
- package/tests/scripts/somi-agent-dispatch-contract.sh +20 -11
- package/tests/scripts/somi-config.sh +281 -0
- package/tests/scripts/somi-dispatch.sh +194 -95
- package/tests/scripts/somi-mcp.sh +2 -0
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
#
|
|
4
4
|
# Exercises: re-resolution per dispatch across separate process invocations (state lives on disk,
|
|
5
5
|
# not in memory), a bare .somi/config.json edit cannot move a ceiling already recorded,
|
|
6
|
-
#
|
|
7
|
-
#
|
|
6
|
+
# hard-cap selection (no override: the ceiling tier itself, whatever was declared; the declared set
|
|
7
|
+
# only feeds `degraded`; the old never-degrade rule is reversed), and a
|
|
8
8
|
# malformed ceiling or declared set — from config, an env var, or an explicit argument — dying loudly
|
|
9
9
|
# instead of silently disabling the ceiling.
|
|
10
10
|
set -uo pipefail
|
|
@@ -30,172 +30,87 @@ echo "== cost ceiling =="
|
|
|
30
30
|
TMP="$(mktemp -d)"
|
|
31
31
|
trap 'rm -rf "$TMP"' EXIT
|
|
32
32
|
|
|
33
|
-
#
|
|
33
|
+
# State file helper: prints the persisted state as compact JSON, or "none".
|
|
34
|
+
state() { run "$1" 'const fs = await import("node:fs"); const f = C.ceilingStatePath(ROOT); process.stdout.write(fs.existsSync(f) ? fs.readFileSync(f, "utf8") : "none")'; }
|
|
35
|
+
res() { run "$1" 'const r = C.resolveCeiling(ROOT, undefined); process.stdout.write([r.ceiling, r.overridden, r.source, r.ceiling_origin].join(","))'; }
|
|
36
|
+
|
|
37
|
+
# --- nothing set: the built-in default is medium, and nothing is written ------------------------
|
|
34
38
|
A="$TMP/a"; mkdir -p "$A/.somi"
|
|
35
|
-
check "
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
check "bootstrap writes state with no ceiling_overrides key (lazy creation)" \
|
|
39
|
-
"$(run "$A" 'const fs = await import("node:fs"); const s = JSON.parse(fs.readFileSync(C.ceilingStatePath(ROOT), "utf8")); process.stdout.write(String("ceiling_overrides" in s))')" \
|
|
40
|
-
"false"
|
|
39
|
+
check "no config, no state, no env, no arg: medium, from the default" "$(res "$A")" "medium,false,default,default"
|
|
40
|
+
check "... and a resolve with nothing explicit writes no state file" "$(state "$A")" "none"
|
|
41
|
+
check "DEFAULT_CEILING is medium" "$(run "$A" 'process.stdout.write(C.DEFAULT_CEILING)')" "medium"
|
|
41
42
|
|
|
42
|
-
# ---
|
|
43
|
+
# --- config is read LIVE: an edit between two resolves moves the ceiling -------------------------
|
|
43
44
|
B="$TMP/b"; mkdir -p "$B/.somi"
|
|
44
45
|
printf '{"cost": {"ceiling": "low"}}\n' > "$B/.somi/config.json"
|
|
45
|
-
check "
|
|
46
|
-
"$(run "$B" 'process.stdout.write(C.resolveCeiling(ROOT, undefined).ceiling)')" \
|
|
47
|
-
"low"
|
|
48
|
-
|
|
49
|
-
# The loop-cap precedent's central guard, mirrored: a bare config edit AFTER state exists must
|
|
50
|
-
# not move a ceiling already in force.
|
|
46
|
+
check "config's cost.ceiling is honoured" "$(res "$B")" "low,false,config,config"
|
|
51
47
|
printf '{"cost": {"ceiling": "high"}}\n' > "$B/.somi/config.json"
|
|
52
|
-
check "a bare config edit
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
check "a bare config edit moves the ceiling on the very next resolve (config is live)" "$(res "$B")" "high,false,config,config"
|
|
49
|
+
printf '{}\n' > "$B/.somi/config.json"
|
|
50
|
+
check "removing cost.ceiling from the config falls back to the default" "$(res "$B")" "medium,false,default,default"
|
|
51
|
+
check "config-only resolves never write state" "$(state "$B")" "none"
|
|
55
52
|
|
|
56
|
-
# ---
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
check "the override
|
|
60
|
-
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
|
|
53
|
+
# --- CLI/env beat config, and are persisted with their origin ------------------------------------
|
|
54
|
+
printf '{"cost": {"ceiling": "low"}}\n' > "$B/.somi/config.json"
|
|
55
|
+
out="$(SOMI_COST_CEILING=high node --input-type=module -e "const C = await import('$LIB'); const r = C.resolveCeiling('$B', undefined); process.stdout.write(r.ceiling+','+r.overridden+','+r.source+','+r.override.field+','+r.override.from+','+r.override.to+','+r.override.source)")"
|
|
56
|
+
check "env value beats config, and the override record names what was in force" "$out" "high,true,env,ceiling,low,high,env"
|
|
57
|
+
check "the override was persisted with origin env and a one-entry ceiling_overrides" \
|
|
58
|
+
"$(run "$B" 'const fs = await import("node:fs"); const s = JSON.parse(fs.readFileSync(C.ceilingStatePath(ROOT), "utf8")); process.stdout.write([s.ceiling, s.ceiling_origin, s.ceiling_overrides.length, s.ceiling_overrides[0].source].join(","))')" \
|
|
59
|
+
"high,env,1,env"
|
|
60
|
+
|
|
61
|
+
# Config OUTRANKS a persisted cli/env ceiling (it is live; state only fills in when config is silent).
|
|
62
|
+
check "persisted env ceiling is outranked by cost.ceiling in config (config > persisted state)" \
|
|
63
|
+
"$(res "$B")" "low,false,config,config"
|
|
64
|
+
printf '{}\n' > "$B/.somi/config.json"
|
|
65
|
+
check "with config silent, the persisted env ceiling stands: source state, origin env" \
|
|
66
|
+
"$(res "$B")" "high,false,state,env"
|
|
67
|
+
printf '{"cost": {"ceiling": "low"}}\n' > "$B/.somi/config.json"
|
|
68
|
+
check "no duplicate override entry was recorded by the bare calls" \
|
|
68
69
|
"$(run "$B" 'const fs = await import("node:fs"); const s = JSON.parse(fs.readFileSync(C.ceilingStatePath(ROOT), "utf8")); process.stdout.write(String(s.ceiling_overrides.length))')" \
|
|
69
70
|
"1"
|
|
70
71
|
|
|
71
72
|
# --- an explicit argument beats an env var set in the SAME call ---------------------------------
|
|
72
|
-
out="$(SOMI_COST_CEILING=low node --input-type=module -e "const C = await import('$LIB'); const r = C.resolveCeiling('$B', 'medium'); process.stdout.write(r.ceiling+','+r.override.source+','+r.override.from)")"
|
|
73
|
-
check "explicit argument wins over env
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
check "bootstrap with no config, no env, no arg: source is 'default'" \
|
|
81
|
-
"$(run "$DEF" 'process.stdout.write(C.resolveCeiling(ROOT, undefined).source)')" \
|
|
82
|
-
"default"
|
|
83
|
-
|
|
84
|
-
CFGSRC="$TMP/source-config"; mkdir -p "$CFGSRC/.somi"
|
|
85
|
-
printf '{"cost": {"ceiling": "low"}}\n' > "$CFGSRC/.somi/config.json"
|
|
86
|
-
check "bootstrap from .somi/config.json's cost.ceiling: source is 'config'" \
|
|
87
|
-
"$(run "$CFGSRC" 'process.stdout.write(C.resolveCeiling(ROOT, undefined).source)')" \
|
|
88
|
-
"config"
|
|
89
|
-
check "a later bare call against the same state: source is 'state', not 'config' again" \
|
|
90
|
-
"$(run "$CFGSRC" 'process.stdout.write(C.resolveCeiling(ROOT, undefined).source)')" \
|
|
91
|
-
"state"
|
|
92
|
-
check "an explicit CLI argument: source is 'cli' even when it matches the value already on disk" \
|
|
93
|
-
"$(run "$CFGSRC" 'process.stdout.write(C.resolveCeiling(ROOT, "low").source)')" \
|
|
94
|
-
"cli"
|
|
95
|
-
out="$(SOMI_COST_CEILING=low node --input-type=module -e "const C = await import('$LIB'); process.stdout.write(C.resolveCeiling('$CFGSRC', undefined).source)")"
|
|
73
|
+
out="$(SOMI_COST_CEILING=low node --input-type=module -e "const C = await import('$LIB'); const r = C.resolveCeiling('$B', 'medium'); process.stdout.write(r.ceiling+','+r.override.source+','+r.override.from+','+r.ceiling_origin)")"
|
|
74
|
+
check "explicit argument wins over env, is recorded with source cli; from is the ceiling in force" "$out" "medium,cli,low,cli"
|
|
75
|
+
check "an explicit CLI value matching what config gives still reports source cli and persists origin cli" \
|
|
76
|
+
"$(run "$B" 'const r = C.resolveCeiling(ROOT, "low"); process.stdout.write([r.overridden, r.source, r.ceiling_origin].join(","))')" \
|
|
77
|
+
"false,cli,cli"
|
|
78
|
+
check "... the persisted origin is now cli" \
|
|
79
|
+
"$(run "$B" 'const fs = await import("node:fs"); process.stdout.write(JSON.parse(fs.readFileSync(C.ceilingStatePath(ROOT), "utf8")).ceiling_origin)')" "cli"
|
|
80
|
+
out="$(SOMI_COST_CEILING=low node --input-type=module -e "const C = await import('$LIB'); process.stdout.write(C.resolveCeiling('$B', undefined).source)")"
|
|
96
81
|
check "an explicit env var: source is 'env'" "$out" "env"
|
|
97
82
|
|
|
98
|
-
# ---
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
"default,default"
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
check "a
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
check "a
|
|
125
|
-
"$(run "$
|
|
126
|
-
"
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
# no-duplicate-entry behavior above) -- ceiling_origin must therefore be left exactly as it was,
|
|
130
|
-
# not overwritten to "cli" for a value that didn't actually move.
|
|
131
|
-
ORIG_NOOP="$TMP/origin-noop"; mkdir -p "$ORIG_NOOP/.somi"
|
|
132
|
-
printf '{"cost": {"ceiling": "medium"}}\n' > "$ORIG_NOOP/.somi/config.json"
|
|
133
|
-
run "$ORIG_NOOP" 'C.resolveCeiling(ROOT, undefined)' >/dev/null # bootstrap from config first
|
|
134
|
-
check "a --ceiling matching the value already on disk: ceiling_origin is untouched (still 'config')" \
|
|
135
|
-
"$(run "$ORIG_NOOP" 'const r = C.resolveCeiling(ROOT, "medium"); process.stdout.write(r.overridden + "," + r.source + "," + r.ceiling_origin)')" \
|
|
136
|
-
"false,cli,config"
|
|
137
|
-
|
|
138
|
-
# M3: a state file written BEFORE ceiling_origin existed (this repo's own committed
|
|
139
|
-
# .somi/somi-state/ceiling.json is exactly this shape: {"ceiling":"high"}, no origin key at all) has
|
|
140
|
-
# no way to have set it -- absence is legacy, not corruption, and must not hard-fail. Reported as the
|
|
141
|
-
# distinct value 'unknown' rather than a guess. Contrast with ORIG_BADVAL below: PRESENT but wrong
|
|
142
|
-
# is still rejected.
|
|
143
|
-
ORIG_LEGACY="$TMP/origin-legacy"; mkdir -p "$ORIG_LEGACY/.somi/somi-state"
|
|
144
|
-
printf '{"ceiling": "high"}' > "$ORIG_LEGACY/.somi/somi-state/ceiling.json"
|
|
145
|
-
check "a state file predating ceiling_origin does not hard-fail; reports 'unknown'" \
|
|
146
|
-
"$(run "$ORIG_LEGACY" 'const r = C.resolveCeiling(ROOT, undefined); process.stdout.write(r.ceiling + "," + r.ceiling_origin)')" \
|
|
147
|
-
"high,unknown"
|
|
148
|
-
|
|
149
|
-
# M2: `ceiling_origin: "config"` goes stale when .somi/config.json's cost.ceiling changes to a
|
|
150
|
-
# DIFFERENT value after state already exists -- a bare edit still cannot MOVE the ceiling already in
|
|
151
|
-
# force (proven above), but continuing to report "config" would keep claiming a committed policy
|
|
152
|
-
# that no longer matches what's committed. Reported as "config-stale", never persisted.
|
|
153
|
-
ORIG_STALE="$TMP/origin-stale"; mkdir -p "$ORIG_STALE/.somi"
|
|
154
|
-
printf '{"cost": {"ceiling": "low"}}\n' > "$ORIG_STALE/.somi/config.json"
|
|
155
|
-
run "$ORIG_STALE" 'C.resolveCeiling(ROOT, undefined)' >/dev/null # bootstrap from config: low, origin config
|
|
156
|
-
printf '{"cost": {"ceiling": "high"}}\n' > "$ORIG_STALE/.somi/config.json" # config now says something else
|
|
157
|
-
check "config changed after bootstrap: ceiling stays put, ceiling_origin reports 'config-stale'" \
|
|
158
|
-
"$(run "$ORIG_STALE" 'const r = C.resolveCeiling(ROOT, undefined); process.stdout.write(r.ceiling + "," + r.overridden + "," + r.ceiling_origin)')" \
|
|
159
|
-
"low,false,config-stale"
|
|
160
|
-
check "config-stale is never written back to the state file itself" \
|
|
161
|
-
"$(run "$ORIG_STALE" 'const fs = await import("node:fs"); const s = JSON.parse(fs.readFileSync(C.ceilingStatePath(ROOT), "utf8")); process.stdout.write(s.ceiling_origin)')" \
|
|
162
|
-
"config"
|
|
163
|
-
|
|
164
|
-
ORIG_REMOVED="$TMP/origin-removed"; mkdir -p "$ORIG_REMOVED/.somi"
|
|
165
|
-
printf '{"cost": {"ceiling": "medium"}}\n' > "$ORIG_REMOVED/.somi/config.json"
|
|
166
|
-
run "$ORIG_REMOVED" 'C.resolveCeiling(ROOT, undefined)' >/dev/null # bootstrap from config
|
|
167
|
-
printf '{}\n' > "$ORIG_REMOVED/.somi/config.json" # the policy is removed entirely, not just changed
|
|
168
|
-
check "config.json's cost.ceiling removed entirely after bootstrap: still reported 'config-stale'" \
|
|
169
|
-
"$(run "$ORIG_REMOVED" 'process.stdout.write(C.resolveCeiling(ROOT, undefined).ceiling_origin)')" \
|
|
170
|
-
"config-stale"
|
|
171
|
-
|
|
172
|
-
ORIG_UNCHANGED="$TMP/origin-unchanged"; mkdir -p "$ORIG_UNCHANGED/.somi"
|
|
173
|
-
printf '{"cost": {"ceiling": "low"}}\n' > "$ORIG_UNCHANGED/.somi/config.json"
|
|
174
|
-
run "$ORIG_UNCHANGED" 'C.resolveCeiling(ROOT, undefined)' >/dev/null # bootstrap
|
|
175
|
-
check "config.json unchanged after bootstrap: ceiling_origin stays plain 'config', not stale" \
|
|
176
|
-
"$(run "$ORIG_UNCHANGED" 'process.stdout.write(C.resolveCeiling(ROOT, undefined).ceiling_origin)')" \
|
|
177
|
-
"config"
|
|
178
|
-
|
|
179
|
-
# A ceiling_origin of 'cli'/'env'/'default' never gets the staleness check applied, even against a
|
|
180
|
-
# config.json that would otherwise look stale by value -- staleness is only ever about a 'config'
|
|
181
|
-
# claim specifically.
|
|
182
|
-
ORIG_NOTCONFIG="$TMP/origin-not-config"; mkdir -p "$ORIG_NOTCONFIG/.somi"
|
|
183
|
-
out="$(SOMI_COST_CEILING=low node --input-type=module -e "const C = await import('$LIB'); const r = C.resolveCeiling('$ORIG_NOTCONFIG', undefined); process.stdout.write(r.ceiling_origin)")"
|
|
184
|
-
check "bootstrap via env override: ceiling_origin is 'env', unaffected by the config-staleness check" "$out" "env"
|
|
185
|
-
|
|
186
|
-
# M3 + M2 do not interact: a legacy (no ceiling_origin) state file is never treated as possibly stale.
|
|
187
|
-
ORIG_LEGACY_CFG="$TMP/origin-legacy-cfg"; mkdir -p "$ORIG_LEGACY_CFG/.somi/somi-state"
|
|
188
|
-
mkdir -p "$ORIG_LEGACY_CFG/.somi"
|
|
189
|
-
printf '{"ceiling": "high"}' > "$ORIG_LEGACY_CFG/.somi/somi-state/ceiling.json"
|
|
190
|
-
printf '{"cost": {"ceiling": "low"}}\n' > "$ORIG_LEGACY_CFG/.somi/config.json"
|
|
191
|
-
check "a legacy state file with a differing config.json still reports 'unknown', not 'config-stale'" \
|
|
192
|
-
"$(run "$ORIG_LEGACY_CFG" 'process.stdout.write(C.resolveCeiling(ROOT, undefined).ceiling_origin)')" \
|
|
193
|
-
"unknown"
|
|
194
|
-
|
|
195
|
-
ORIG_BADVAL="$TMP/origin-badval"; mkdir -p "$ORIG_BADVAL/.somi/somi-state"
|
|
196
|
-
printf '{"ceiling": "low", "ceiling_origin": "bogus"}' > "$ORIG_BADVAL/.somi/somi-state/ceiling.json"
|
|
197
|
-
expect_exit "a present state file with an invalid (not merely absent) ceiling_origin value dies loudly" 1 \
|
|
198
|
-
"$ORIG_BADVAL" 'C.resolveCeiling(ROOT, undefined)'
|
|
83
|
+
# --- a persisted ceiling that was NOT set by cli/env yields to config and to the default ---------
|
|
84
|
+
STATES="$TMP/states"
|
|
85
|
+
for spec in 'legacy|{"ceiling":"high"}' 'default-origin|{"ceiling":"high","ceiling_origin":"default"}' 'config-origin|{"ceiling":"high","ceiling_origin":"config"}'; do
|
|
86
|
+
name="${spec%%|*}"; body="${spec#*|}"
|
|
87
|
+
d="$STATES-$name"; mkdir -p "$d/.somi/somi-state"; printf '%s' "$body" > "$d/.somi/somi-state/ceiling.json"
|
|
88
|
+
check "$name fixture was written" "$(state "$d")" "$body"
|
|
89
|
+
check "$name state (high) yields to the medium default" "$(res "$d")" "medium,false,default,default"
|
|
90
|
+
printf '{"cost": {"ceiling": "low"}}\n' > "$d/.somi/config.json"
|
|
91
|
+
check "$name state (high) yields to config low" "$(res "$d")" "low,false,config,config"
|
|
92
|
+
rm "$d/.somi/config.json"
|
|
93
|
+
done
|
|
94
|
+
# A state file written before origins were recorded: just {"ceiling":"high"}.
|
|
95
|
+
LEG="$TMP/legacy-literal"; mkdir -p "$LEG/.somi/somi-state"; printf '{"ceiling":"high"}' > "$LEG/.somi/somi-state/ceiling.json"
|
|
96
|
+
check "the legacy fixture really holds high" "$(state "$LEG")" '{"ceiling":"high"}'
|
|
97
|
+
check "a legacy state file does not outrank the default" "$(res "$LEG")" "medium,false,default,default"
|
|
98
|
+
d="$STATES-cli"; mkdir -p "$d/.somi/somi-state"; printf '{"ceiling":"low","ceiling_origin":"cli"}' > "$d/.somi/somi-state/ceiling.json"
|
|
99
|
+
check "a cli-origin state (low) does apply when config is silent" "$(res "$d")" "low,false,state,cli"
|
|
100
|
+
printf '{"cost": {"ceiling": "high"}}\n' > "$d/.somi/config.json"
|
|
101
|
+
check "... and config high outranks it" "$(res "$d")" "high,false,config,config"
|
|
102
|
+
d="$STATES-yield-write"; mkdir -p "$d/.somi/somi-state"; printf '{"ceiling":"high"}' > "$d/.somi/somi-state/ceiling.json"
|
|
103
|
+
run "$d" 'C.resolveCeiling(ROOT, undefined)' >/dev/null
|
|
104
|
+
check "a yielding legacy state file is left untouched by a bare resolve" "$(state "$d")" '{"ceiling":"high"}'
|
|
105
|
+
check "an explicit value persists over a legacy state file, with origin" \
|
|
106
|
+
"$(run "$d" 'C.resolveCeiling(ROOT, "low"); const fs = await import("node:fs"); const s = JSON.parse(fs.readFileSync(C.ceilingStatePath(ROOT), "utf8")); process.stdout.write(s.ceiling + "," + s.ceiling_origin + "," + s.ceiling_overrides[0].from)')" \
|
|
107
|
+
"low,cli,medium"
|
|
108
|
+
|
|
109
|
+
check "a present state file with an invalid (not merely absent) ceiling_origin value dies loudly" \
|
|
110
|
+
"$(run "$STATES-yield-write" 'const fs = await import("node:fs"); fs.writeFileSync(C.ceilingStatePath(ROOT), JSON.stringify({ceiling:"low",ceiling_origin:"bogus"})); try { C.resolveCeiling(ROOT, undefined); process.stdout.write("no"); } catch { process.stdout.write("threw"); }')" \
|
|
111
|
+
"threw"
|
|
112
|
+
check "config-stale is gone: no resolve ever reports it" \
|
|
113
|
+
"$(run "$B" 'process.stdout.write(String(JSON.stringify(C.resolveCeiling(ROOT, undefined)).includes("stale")))')" "false"
|
|
199
114
|
|
|
200
115
|
# --- an UNPARSABLE state file (bad JSON, not just a wrong shape) dies loudly and names the file --
|
|
201
116
|
STATE_BROKEN="$TMP/state-broken"; mkdir -p "$STATE_BROKEN/.somi/somi-state"
|
|
@@ -205,21 +120,26 @@ expect_exit "an unparsable state file dies loudly rather than a bare uncaught Sy
|
|
|
205
120
|
check "the unparsable-state error names the ceiling.json file path, not a bare JSON position" \
|
|
206
121
|
"$(run "$STATE_BROKEN" 'try { C.resolveCeiling(ROOT, undefined); } catch (e) { process.stdout.write(String(e.message.includes("ceiling.json"))); }')" \
|
|
207
122
|
"true"
|
|
123
|
+
SYMS="$TMP/state-symlink"; mkdir -p "$SYMS/.somi/somi-state"; printf '{"ceiling":"low","ceiling_origin":"cli"}' > "$SYMS/real.json"
|
|
124
|
+
ln -s ../../real.json "$SYMS/.somi/somi-state/ceiling.json"
|
|
125
|
+
expect_exit "a symlinked state file is refused rather than followed" 1 "$SYMS" 'C.resolveCeiling(ROOT, undefined)'
|
|
208
126
|
|
|
209
127
|
# --- malformed values die loudly, never silently defang the ceiling -----------------------------
|
|
128
|
+
M="$TMP/m"; mkdir -p "$M/.somi"
|
|
129
|
+
run "$M" 'C.resolveCeiling(ROOT, "low")' >/dev/null; run "$M" 'C.resolveCeiling(ROOT, "high")' >/dev/null
|
|
210
130
|
expect_exit "a malformed explicit argument is rejected (uncaught, not swallowed)" 1 \
|
|
211
|
-
"$
|
|
131
|
+
"$M" 'C.resolveCeiling(ROOT, "unlimited")'
|
|
212
132
|
expect_exit "a malformed env var is rejected" 1 \
|
|
213
|
-
"$
|
|
133
|
+
"$M" 'process.env.SOMI_COST_CEILING = "unlimited"; C.resolveCeiling(ROOT, undefined)'
|
|
214
134
|
check "a rejected malformed value leaves the on-disk ceiling and override count untouched" \
|
|
215
|
-
"$(run "$
|
|
216
|
-
"
|
|
135
|
+
"$(run "$M" 'const fs = await import("node:fs"); const s = JSON.parse(fs.readFileSync(C.ceilingStatePath(ROOT), "utf8")); process.stdout.write(s.ceiling + "," + s.ceiling_overrides.length)')" \
|
|
136
|
+
"high,2"
|
|
217
137
|
|
|
218
138
|
CFG="$TMP/c"; mkdir -p "$CFG/.somi"
|
|
219
139
|
printf '{"cost": {"ceiling": "unlimited"}}\n' > "$CFG/.somi/config.json"
|
|
220
|
-
expect_exit "a malformed config-sourced ceiling dies loudly
|
|
140
|
+
expect_exit "a malformed config-sourced ceiling dies loudly" 1 \
|
|
221
141
|
"$CFG" 'C.resolveCeiling(ROOT, undefined)'
|
|
222
|
-
check "a failed
|
|
142
|
+
check "a failed config read leaves no state file behind" \
|
|
223
143
|
"$(run "$CFG" 'const fs = await import("node:fs"); process.stdout.write(String(fs.existsSync(C.ceilingStatePath(ROOT))))')" \
|
|
224
144
|
"false"
|
|
225
145
|
|
|
@@ -257,51 +177,36 @@ check "the thrown message names the state file, not a flag or env var" \
|
|
|
257
177
|
"$(run "$CORRUPT" 'try { C.resolveCeiling(ROOT, undefined); } catch (e) { process.stdout.write(String(e.message.includes("ceiling.json"))); }')" \
|
|
258
178
|
"true"
|
|
259
179
|
|
|
260
|
-
# --- decideDispatch:
|
|
261
|
-
#
|
|
262
|
-
#
|
|
263
|
-
|
|
264
|
-
#
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
"allow,high,
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
check "
|
|
280
|
-
"$(
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
"allow,medium"
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
# member is always the one chosen, never a lower one left on the table.
|
|
291
|
-
check "three-member set [low,medium,high], ceiling low: selects low" \
|
|
292
|
-
"$(run "$B" 'const d = C.decideDispatch(["low","medium","high"], "low"); process.stdout.write(d.action + "," + d.selected)')" \
|
|
293
|
-
"allow,low"
|
|
294
|
-
check "three-member set [low,medium,high], ceiling medium: selects medium, not low" \
|
|
295
|
-
"$(run "$B" 'const d = C.decideDispatch(["low","medium","high"], "medium"); process.stdout.write(d.action + "," + d.selected)')" \
|
|
296
|
-
"allow,medium"
|
|
297
|
-
check "three-member set [low,medium,high], ceiling high: selects high, not a lower member" \
|
|
298
|
-
"$(run "$B" 'const d = C.decideDispatch(["low","medium","high"], "high"); process.stdout.write(d.action + "," + d.selected)')" \
|
|
299
|
-
"allow,high"
|
|
300
|
-
|
|
301
|
-
# No code path ever yields a tier absent from the declared set, and every outcome is "allow": sweep
|
|
302
|
-
# every set against every ceiling.
|
|
303
|
-
check "action is always allow, and selected is always a member of the declared set, across every set x ceiling" \
|
|
304
|
-
"$(run "$B" 'const sets=[["low"],["medium"],["high"],["low","medium"],["medium","high"],["low","high"],["low","medium","high"]]; const ceilings=["low","medium","high"]; let bad=0; for (const s of sets) for (const c of ceilings) { const d=C.decideDispatch(s,c); if (d.action!=="allow") bad++; if (!s.includes(d.selected)) bad++; } process.stdout.write(String(bad))')" \
|
|
180
|
+
# --- decideDispatch: the ceiling is a HARD cap. With no override the selected tier IS the ceiling,
|
|
181
|
+
# whatever the unit declared; the declared set (a capability set) is echoed in `supported` and used
|
|
182
|
+
# only to compute `degraded`. A bare string is a one-member set. The old never-degrade rule (run at
|
|
183
|
+
# the cheapest declared member when none fits) is reversed. Override / source cases: cost-hardcap.sh.
|
|
184
|
+
# Each case prints action,selected,supported,degraded,tier_source.
|
|
185
|
+
dd() { run "$B" "const d = C.decideDispatch($1); process.stdout.write([d.action, d.selected, d.supported.join('|'), d.degraded, d.tier_source].join(','))"; }
|
|
186
|
+
|
|
187
|
+
check "one-member set under a higher ceiling: runs at the ceiling, not degraded" \
|
|
188
|
+
"$(dd '"low", "high"')" "allow,high,low,false,ceiling"
|
|
189
|
+
check "single-high declaration under a medium ceiling: clamped to medium, degraded" \
|
|
190
|
+
"$(dd '"high", "medium"')" "allow,medium,high,true,ceiling"
|
|
191
|
+
check "single-high declaration under a low ceiling: clamped to low, degraded" \
|
|
192
|
+
"$(dd '["high"], "low"')" "allow,low,high,true,ceiling"
|
|
193
|
+
check "two-member set [medium,high], ceiling low: clamped to low, below every declared member" \
|
|
194
|
+
"$(dd '["medium","high"], "low"')" "allow,low,medium|high,true,ceiling"
|
|
195
|
+
check "two-member set [medium,high], ceiling medium: medium, degraded (below its highest member)" \
|
|
196
|
+
"$(dd '["medium","high"], "medium"')" "allow,medium,medium|high,true,ceiling"
|
|
197
|
+
check "two-member set [medium,high], ceiling high: high, not degraded" \
|
|
198
|
+
"$(dd '["medium","high"], "high"')" "allow,high,medium|high,false,ceiling"
|
|
199
|
+
check "three-member set, ceiling low: low, degraded" \
|
|
200
|
+
"$(dd '["low","medium","high"], "low"')" "allow,low,low|medium|high,true,ceiling"
|
|
201
|
+
check "three-member set, ceiling medium: medium, degraded" \
|
|
202
|
+
"$(dd '["low","medium","high"], "medium"')" "allow,medium,low|medium|high,true,ceiling"
|
|
203
|
+
check "three-member set, ceiling high: high, not degraded" \
|
|
204
|
+
"$(dd '["low","medium","high"], "high"')" "allow,high,low|medium|high,false,ceiling"
|
|
205
|
+
|
|
206
|
+
# Sweep: without an override, selected is exactly the ceiling for every set x ceiling; the selected
|
|
207
|
+
# tier may be outside the declared set, and degraded is exactly "selected below the top member".
|
|
208
|
+
check "no override: selected === ceiling and degraded matches rank, across every set x ceiling" \
|
|
209
|
+
"$(run "$B" 'const sets=[["low"],["medium"],["high"],["low","medium"],["medium","high"],["low","high"],["low","medium","high"]]; const R={low:0,medium:1,high:2}; let bad=0; for (const s of sets) for (const c of ["low","medium","high"]) { const d=C.decideDispatch(s,c); if (d.action!=="allow"||d.selected!==c||d.tier_source!=="ceiling") bad++; if (d.degraded !== (R[c] < R[s[s.length-1]])) bad++; } process.stdout.write(String(bad))')" \
|
|
305
210
|
"0"
|
|
306
211
|
|
|
307
212
|
check "the decision object is frozen -- a caller cannot rewrite the selection after the fact" \
|
|
@@ -310,9 +215,9 @@ check "the decision object is frozen -- a caller cannot rewrite the selection af
|
|
|
310
215
|
check "the supported array itself is frozen too, not just the decision object wrapping it" \
|
|
311
216
|
"$(run "$B" 'const d = C.decideDispatch(["low","high"], "high"); const before = d.supported.length; try { d.supported.push("medium"); } catch {} process.stdout.write(String(d.supported.length === before))')" \
|
|
312
217
|
"true"
|
|
313
|
-
check "the allow shape carries exactly action, selected, supported,
|
|
218
|
+
check "the allow shape carries exactly action, ceiling, degraded, selected, supported, tier_source" \
|
|
314
219
|
"$(run "$B" 'process.stdout.write(Object.keys(C.decideDispatch(["low","high"], "high")).sort().join("|"))')" \
|
|
315
|
-
"action|ceiling|selected|supported"
|
|
220
|
+
"action|ceiling|degraded|selected|supported|tier_source"
|
|
316
221
|
expect_exit "an unrecognized cost value throws rather than silently allowing" 1 \
|
|
317
222
|
"$B" 'C.decideDispatch("critical", "high")'
|
|
318
223
|
expect_exit "an unrecognized ceiling value throws rather than silently allowing" 1 \
|
|
@@ -324,16 +229,18 @@ expect_exit "a duplicate in the declared set throws" 1 \
|
|
|
324
229
|
expect_exit "an empty declared set throws rather than resolving to no-capability-silently" 1 \
|
|
325
230
|
"$B" 'C.decideDispatch([], "high")'
|
|
326
231
|
|
|
327
|
-
# --- modelForDispatch: the sanctioned composition
|
|
232
|
+
# --- modelForDispatch: the sanctioned composition from a decideDispatch decision ----------------
|
|
328
233
|
check "modelForDispatch resolves the model for the SELECTED tier, not just any declared member" \
|
|
329
234
|
"$(run "$B" 'process.stdout.write(C.modelForDispatch(C.decideDispatch(["low","medium"],"medium"), "claude-code"))')" \
|
|
330
235
|
"sonnet"
|
|
331
|
-
check "modelForDispatch on a one-member set resolves
|
|
236
|
+
check "modelForDispatch on a one-member set resolves the CEILING tier's model (hard cap), not the member's" \
|
|
332
237
|
"$(run "$B" 'process.stdout.write(C.modelForDispatch(C.decideDispatch("low","high"), "claude-code"))')" \
|
|
333
|
-
"
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
238
|
+
"opus"
|
|
239
|
+
check "modelForDispatch follows an override above the ceiling" \
|
|
240
|
+
"$(run "$B" 'process.stdout.write(C.modelForDispatch(C.decideDispatch("low","low","high"), "claude-code"))')" \
|
|
241
|
+
"opus"
|
|
242
|
+
# decideDispatch itself can only produce "allow" -- the guard is unreachable by construction, but it
|
|
243
|
+
# is still exercised directly against a hand-built non-allow shape, so the backstop stays proven.
|
|
337
244
|
expect_exit "modelForDispatch refuses a decision shaped as anything but allow" 1 \
|
|
338
245
|
"$B" 'C.modelForDispatch({ action: "refuse", supported: ["high"], ceiling: "low" }, "claude-code")'
|
|
339
246
|
expect_exit "modelForDispatch refuses a missing decision" 1 \
|
|
@@ -341,3 +248,8 @@ expect_exit "modelForDispatch refuses a missing decision" 1 \
|
|
|
341
248
|
|
|
342
249
|
echo "cost ceiling tests: $pass ok, $fail failed"
|
|
343
250
|
[ "$fail" -eq 0 ] || exit 1
|
|
251
|
+
bash "$(dirname "${BASH_SOURCE[0]}")/cost-hardcap.sh" || exit 1
|
|
252
|
+
bash "$(dirname "${BASH_SOURCE[0]}")/ensure-default-config.sh" || exit 1
|
|
253
|
+
bash "$(dirname "${BASH_SOURCE[0]}")/somi-config.sh" || exit 1
|
|
254
|
+
bash "$(dirname "${BASH_SOURCE[0]}")/cost-lowering.sh" || exit 1
|
|
255
|
+
bash "$(dirname "${BASH_SOURCE[0]}")/agent-model-frontmatter.sh" || exit 1
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Guard for the default tier table (scripts/lib/cost-defaults.mjs), the one source of each agent's tier:
|
|
3
|
+
# - the table lists exactly the agents/*.md files, minus the exempt front-door `somi` (existence, both
|
|
4
|
+
# directions);
|
|
5
|
+
# - no agents/*.md or commands/*.md declares `cost:` (the real check from scripts/validate.sh, extracted
|
|
6
|
+
# from a copy of it and run over fixtures, so this proves that block's own logic).
|
|
7
|
+
# Each check is also proven red: a copy of the table with one row removed or added, and fixtures that
|
|
8
|
+
# declare `cost:`, must fail the same comparison.
|
|
9
|
+
set -uo pipefail
|
|
10
|
+
|
|
11
|
+
ROOT_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
12
|
+
LIB_SRC="$ROOT_REPO/scripts/lib"
|
|
13
|
+
|
|
14
|
+
pass=0; fail=0
|
|
15
|
+
ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
|
|
16
|
+
bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
|
|
17
|
+
check() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1 (want '$3', got '$2')"; fi; }
|
|
18
|
+
|
|
19
|
+
echo "== cost defaults =="
|
|
20
|
+
|
|
21
|
+
TMP="$(mktemp -d)"
|
|
22
|
+
trap 'rm -rf "$TMP"' EXIT
|
|
23
|
+
|
|
24
|
+
# Prints the agent names (agents/*.md minus the exempt `somi`), sorted.
|
|
25
|
+
agent_files() { for f in "$1"/*.md; do n="$(basename "$f" .md)"; [ "$n" = somi ] || printf '%s\n' "$n"; done | sort; }
|
|
26
|
+
# Prints the table's agent names for the lib dir given, sorted.
|
|
27
|
+
table_names() {
|
|
28
|
+
node --input-type=module -e "
|
|
29
|
+
const D = await import('$1/cost-defaults.mjs');
|
|
30
|
+
for (const k of Object.keys(D.AGENT_DEFAULT_TIERS)) console.log(k);" | sort
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
EXPECT="$(agent_files "$ROOT_REPO/agents")"
|
|
34
|
+
[ -n "$EXPECT" ] || bad "no agent file was found"
|
|
35
|
+
check "the table lists exactly the agent files (minus the exempt somi)" "$(table_names "$LIB_SRC")" "$EXPECT"
|
|
36
|
+
|
|
37
|
+
# The tier values themselves: a literal expected list (changing a tier is a deliberate edit here).
|
|
38
|
+
EXPECT_TIERS="somi-architecture-reviewer:high
|
|
39
|
+
somi-atlas:high
|
|
40
|
+
somi-coder:medium
|
|
41
|
+
somi-designer:high
|
|
42
|
+
somi-discovery-analyst:high
|
|
43
|
+
somi-impact:medium
|
|
44
|
+
somi-incident:medium
|
|
45
|
+
somi-plan-reviewer:high
|
|
46
|
+
somi-planner:medium
|
|
47
|
+
somi-pr:medium
|
|
48
|
+
somi-refactor-designer:high
|
|
49
|
+
somi-refactorer:medium
|
|
50
|
+
somi-reviewer:high
|
|
51
|
+
somi-sdlc-reviewer:high
|
|
52
|
+
somi-security-reviewer:high
|
|
53
|
+
somi-test-strategist:high"
|
|
54
|
+
table_tiers() {
|
|
55
|
+
node --input-type=module -e "
|
|
56
|
+
const D = await import('$1/cost-defaults.mjs');
|
|
57
|
+
for (const [k, v] of Object.entries(D.AGENT_DEFAULT_TIERS)) console.log(k + ':' + v);" | sort
|
|
58
|
+
}
|
|
59
|
+
EXPECT_TIERS="$(printf '%s\n' "$EXPECT_TIERS" | sort)"
|
|
60
|
+
check "the table's name:tier list equals the literal expected list" "$(table_tiers "$LIB_SRC")" "$EXPECT_TIERS"
|
|
61
|
+
|
|
62
|
+
# Red proofs on copies of the lib.
|
|
63
|
+
mutant() { # $1 = name, $2 = sed expression
|
|
64
|
+
mkdir -p "$TMP/$1"; cp "$LIB_SRC"/cost-*.mjs "$TMP/$1/"; sed -i "$2" "$TMP/$1/cost-defaults.mjs"
|
|
65
|
+
cmp -s "$LIB_SRC/cost-defaults.mjs" "$TMP/$1/cost-defaults.mjs" && bad "mutant $1 did not change the file"
|
|
66
|
+
}
|
|
67
|
+
mutant tier-changed "s/^ 'somi-coder': 'medium',/ 'somi-coder': 'high',/"
|
|
68
|
+
mutant row-removed "/^ 'somi-atlas': 'high',/d"
|
|
69
|
+
mutant row-added "s/^ 'somi-atlas': 'high',/ 'somi-atlas': 'high',\n 'somi-ghost': 'low',/"
|
|
70
|
+
if [ "$(table_tiers "$TMP/tier-changed")" != "$EXPECT_TIERS" ]; then ok "red proof: the tier list check fails for tier-changed"; else bad "red proof: a changed tier went unnoticed"; fi
|
|
71
|
+
for m in row-removed row-added; do
|
|
72
|
+
if [ "$(table_names "$TMP/$m")" != "$EXPECT" ]; then ok "red proof: existence check fails for $m"; else bad "red proof: existence check still holds for $m"; fi
|
|
73
|
+
done
|
|
74
|
+
mkdir -p "$TMP/agents-extra"; cp "$ROOT_REPO"/agents/*.md "$TMP/agents-extra/"; printf -- '---\nname: extra\n---\n' > "$TMP/agents-extra/extra.md"
|
|
75
|
+
if [ "$(agent_files "$TMP/agents-extra")" != "$(table_names "$LIB_SRC")" ]; then ok "red proof: an agent file with no table row fails the check"; else bad "red proof: an unlisted agent file went unnoticed"; fi
|
|
76
|
+
|
|
77
|
+
# No agent or command declares `cost:` -- the real block from scripts/validate.sh, over fixtures.
|
|
78
|
+
HELPER="$(awk '/^fm_has\(\) \{/{c=1} c{print} c&&/^\}$/{exit}' "$ROOT_REPO/scripts/validate.sh")"
|
|
79
|
+
BLOCK="$(awk '/^cost_failed=0$/{c=1} c{print} c&&/^done$/{exit}' "$ROOT_REPO/scripts/validate.sh")"
|
|
80
|
+
if [ -z "$HELPER" ] || [ -z "$BLOCK" ]; then bad "could not extract the cost check from scripts/validate.sh -- its markers may have moved"; else
|
|
81
|
+
SNIPPET="$HELPER"$'\n'"$BLOCK"$'\nexit $cost_failed'
|
|
82
|
+
fx() { (cd "$1" && bash -c "$SNIPPET" 2>"$1/err"); echo $?; }
|
|
83
|
+
mkdir -p "$TMP/fx-ok/agents" "$TMP/fx-ok/commands" "$TMP/fx-agent/agents" "$TMP/fx-agent/commands" "$TMP/fx-cmd/agents" "$TMP/fx-cmd/commands" "$TMP/fx-crlf/agents" "$TMP/fx-crlf/commands"
|
|
84
|
+
printf -- '---\nname: x\ndescription: d\n---\nbody line: cost: high\n' > "$TMP/fx-ok/agents/x.md"
|
|
85
|
+
printf -- '---\ndescription: d\n---\nbody\n' > "$TMP/fx-ok/commands/c.md"
|
|
86
|
+
for d in fx-agent fx-cmd fx-crlf; do cp "$TMP/fx-ok/agents/x.md" "$TMP/$d/agents/x.md"; cp "$TMP/fx-ok/commands/c.md" "$TMP/$d/commands/c.md"; done
|
|
87
|
+
printf -- '---\nname: x\ncost: medium, high\n---\n' > "$TMP/fx-agent/agents/x.md"
|
|
88
|
+
printf -- '---\ndescription: d\ncost: high\n---\n' > "$TMP/fx-cmd/commands/c.md"
|
|
89
|
+
printf -- '---\r\nname: x\r\ncost: high\r\n---\r\n' > "$TMP/fx-crlf/agents/x.md"
|
|
90
|
+
check "an agent and a command without a frontmatter cost: pass (a body line is not frontmatter)" "$(fx "$TMP/fx-ok")" "0"
|
|
91
|
+
check "red proof: an agent declaring cost: fails" "$(fx "$TMP/fx-agent")" "1"
|
|
92
|
+
check "red proof: a command declaring cost: fails" "$(fx "$TMP/fx-cmd")" "1"
|
|
93
|
+
check "red proof: a CRLF agent declaring cost: fails" "$(fx "$TMP/fx-crlf")" "1"
|
|
94
|
+
grep -q "agents/x.md declares cost:" "$TMP/fx-agent/err" && ok "the message names the offending file" || bad "message wrong: $(cat "$TMP/fx-agent/err")"
|
|
95
|
+
n="$(awk 'FNR==1{c=0} /^---$/{c++} c==1 && /^cost:/{print FILENAME; nextfile}' "$ROOT_REPO"/agents/*.md "$ROOT_REPO"/commands/*.md | wc -l)"
|
|
96
|
+
check "no shipped agent or command declares cost:" "$n" "0"
|
|
97
|
+
fi
|
|
98
|
+
|
|
99
|
+
# The shape of the default config.
|
|
100
|
+
node --input-type=module -e "
|
|
101
|
+
const D = await import('$LIB_SRC/cost-defaults.mjs');
|
|
102
|
+
const C = await import('$LIB_SRC/cost-ceiling.mjs');
|
|
103
|
+
const V = await import('$LIB_SRC/cost-config.mjs');
|
|
104
|
+
const cfg = D.buildDefaultConfig();
|
|
105
|
+
const out = [];
|
|
106
|
+
out.push(['ceiling is the built-in default', cfg.cost.ceiling === C.DEFAULT_CEILING && D.DEFAULT_CEILING_TIER === C.DEFAULT_CEILING]);
|
|
107
|
+
out.push(['validates through the shared validator', (() => { try { V.validateCostConfig(cfg.cost); return true; } catch { return false; } })()]);
|
|
108
|
+
out.push(['agents are sorted by name', Object.keys(cfg.cost.agents).join() === Object.keys(cfg.cost.agents).sort().join()]);
|
|
109
|
+
out.push(['the table is frozen and null-prototype', Object.isFrozen(D.AGENT_DEFAULT_TIERS) && Object.getPrototypeOf(D.AGENT_DEFAULT_TIERS) === null]);
|
|
110
|
+
out.push(['serialization is stable and is JSON, 2-space indent, trailing newline', D.serializeDefaultConfig() === D.serializeDefaultConfig() && D.serializeDefaultConfig() === JSON.stringify(cfg, null, 2) + '\n' && D.serializeDefaultConfig().endsWith('}\n')]);
|
|
111
|
+
out.push(['serialization round-trips to the same object', JSON.stringify(JSON.parse(D.serializeDefaultConfig())) === JSON.stringify(cfg)]);
|
|
112
|
+
out.push(['the somi front-door agent is not listed', !('somi' in D.AGENT_DEFAULT_TIERS)]);
|
|
113
|
+
out.push(['a bad table row is rejected', (() => { try { D.buildDefaultConfig({ 'somi-coder': 'turbo' }); return false; } catch { return true; } })()]);
|
|
114
|
+
out.push(['a bad agent name is rejected', (() => { try { D.buildDefaultConfig({ 'Bad_Name': 'low' }); return false; } catch { return true; } })()]);
|
|
115
|
+
for (const [n, v] of out) console.log((v ? 'ok' : 'FAIL') + '\t' + n);" > "$TMP/shape.out" 2>&1
|
|
116
|
+
while IFS=$'\t' read -r s n; do case "$s" in ok) ok "$n" ;; FAIL) bad "$n" ;; *) bad "unexpected output: $s $n" ;; esac; done < "$TMP/shape.out"
|
|
117
|
+
|
|
118
|
+
# No model names anywhere in the file or its output: the pattern comes from the shipped mapping.
|
|
119
|
+
PATTERN="$(node --input-type=module -e "
|
|
120
|
+
const M = await import('$LIB_SRC/cost-model.mjs');
|
|
121
|
+
console.log(Object.values(M.HOST_MODELS).flatMap((h) => Object.values(h)).join('|'))")"
|
|
122
|
+
if [ -n "$PATTERN" ] && ! grep -qiE "$PATTERN" "$LIB_SRC/cost-defaults.mjs" \
|
|
123
|
+
&& ! node --input-type=module -e "const D = await import('$LIB_SRC/cost-defaults.mjs'); process.stdout.write(D.serializeDefaultConfig())" | grep -qiE "$PATTERN"; then
|
|
124
|
+
ok "no model name in the table file or in the serialized config"
|
|
125
|
+
else bad "a model name appears in the table file or the serialized config"; fi
|
|
126
|
+
|
|
127
|
+
echo "cost defaults tests: $pass ok, $fail failed"
|
|
128
|
+
[ "$fail" -eq 0 ] || exit 1
|