diff --git a/bin/gstack-capy-install b/bin/gstack-capy-install index bf5ad1928..a9f7bf26e 100755 --- a/bin/gstack-capy-install +++ b/bin/gstack-capy-install @@ -42,7 +42,8 @@ # mode-0600 file beside the verdict; callers and their children `. ` it, # never re-type it) and the doctor's trailer (`gstack: ok ...` or `gstack: fail ...`; # grep that, never pipe through tail). -# --model , else GSTACK_MODEL (GSTA-161, docs/loadouts.md), names the model this session runs: +# --model , else GSTACK_MODEL (GSTA-161, docs/loadouts.md), else the agent_model of the session's +# GSTACK_PREFERENCES_FILE as gstack-models resolve --role agent reads it (GST-982), names the model this session runs: # bin/gstack-modules install picks its loadout, publishes a non-full one beside # the full Claude install and prints LOADOUT and SKILL_ROOT lines before the # launch lines; a non-full loadout gets its own launch file, keyed by loadout @@ -723,14 +724,19 @@ fi [ "$RC" -eq 0 ] || { [ "$PROFILE" -eq 1 ] && rm -rf "${VERDICT%.json}.profile" 2>/dev/null; verdict_kept || rm -f "$LAUNCH_FILE" 2>/dev/null; LAUNCH_FILE=""; } record_verdict "$TRAILER" "$([ "$RC" -eq 0 ] && echo 1 || echo 0)" LOADOUT_LINES="" +if [ "$RC" -eq 0 ] && [ -z "$MODEL" ] && [ -n "${GSTACK_PREFERENCES_FILE:-}" ] && [ "$PROFILE" -eq 0 ] && [ -n "$LAUNCH_FILE" ]; then + MODEL=$(cd "$ROOT" && bin/gstack-models resolve --role agent 2>/dev/null | sed -n '1s|^agent: [a-z0-9-]*/\([A-Za-z0-9._-]*\) .*|\1|p') + MODEL_SOURCE=preferences +fi if [ "$RC" -eq 0 ] && [ -n "$MODEL" ] && [ "$PROFILE" -eq 0 ] && [ -n "$LAUNCH_FILE" ]; then _lo_full=$(. "$SELF/bin/gstack-claude-root.sh" && dirname "$(gstack_canonical_claude_root)") - if [ "$MODEL_SOURCE" = model-flag ]; then - _lo_out=$(cd "$ROOT" && bin/gstack-modules install --model "$MODEL" --full-root "$_lo_full" 2>&1) - else + if [ "$MODEL_SOURCE" = GSTACK_MODEL ]; then _lo_out=$(cd "$ROOT" && GSTACK_MODEL=$MODEL bin/gstack-modules install --full-root "$_lo_full" 2>&1) + else + _lo_out=$(cd "$ROOT" && bin/gstack-modules install --model "$MODEL" --full-root "$_lo_full" 2>&1) fi _lo_line=$(printf '%s\n' "$_lo_out" | grep -m1 '^LOADOUT: ') + [ "$MODEL_SOURCE" = preferences ] && _lo_line=$(printf '%s' "$_lo_line" | sed 's/ source=model-flag/ source=preferences/') _lo_root=$(printf '%s\n' "$_lo_out" | sed -n 's/^SKILL_ROOT: //p' | head -1) _lo_notes=$(printf '%s\n' "$_lo_out" | grep -E '^(LOADOUT_INVALID_MODEL|LOADOUT_FALLBACK): ') _lo_name=$(printf '%s' "$_lo_line" | sed -n 's/^LOADOUT: \([a-z0-9-]*\) .*/\1/p') diff --git a/changelog.d/gsta161-gst-982-capy-model.md b/changelog.d/gsta161-gst-982-capy-model.md new file mode 100644 index 000000000..478e298bc --- /dev/null +++ b/changelog.d/gsta161-gst-982-capy-model.md @@ -0,0 +1,7 @@ +**Capy sessions get their model's loadout again without a sentence in the skill (GST-982).** The browse wave (#3858) removed the Capy skill's instruction to run the installer with `GSTACK_MODEL`, to keep `capy/skill/gstack/SKILL.md` under its context budget. After that, every Capy session installed the full skills, including Opus 5.5 sessions that should get `lite`. Now the installer finds the model by itself. + +### Fixed +- **`gstack-capy-install` reads the owner's model preference.** When it gets no `--model` and no `GSTACK_MODEL`, it uses the `agent_model` in the session's `GSTACK_PREFERENCES_FILE` (the Drive skill's `preferences.yaml`, which `gstack-capy-session` already exports), resolved by `gstack-models resolve --role agent`. So `opus` means `claude-opus-5-5` today. The line reads `LOADOUT: … source=preferences`. `GSTACK_MODEL` and `--model` still win, and a `host` preference or no file still serves full. The frozen bootstrapper `capy/skill/gstack/scripts/install.sh` and the skill text are unchanged. + +### Tests +- `test/gstack-capy-install.test.ts`: an `opus` preference picks lite with `source=preferences` and its own launch file, `GSTACK_MODEL` overrides the preference, a `host` preference prints no loadout lines, and the real `gstack-models resolve --role agent` keeps the `agent: /` first line the installer reads. diff --git a/docs/capy-install.md b/docs/capy-install.md index cbfd145df..5f50afee9 100644 --- a/docs/capy-install.md +++ b/docs/capy-install.md @@ -472,8 +472,8 @@ make writable, or set GSTACK_STATE_ROOT to a writable directory (LAUNCH_FILE_UNWRITABLE)`, and a failing run prints no `GSTACK_LAUNCH_FILE` line and removes the file an earlier passing run left beside the verdict it rewrites (a profile check that keeps a fuller ok verdict leaves that verdict's file). -With `--model `, or `GSTACK_MODEL=` in its environment (what the Capy -skill passes), an ok run other than `--for review-voice` also prints `LOADOUT: …` +With `--model `, `GSTACK_MODEL=` in its environment, or else an +`agent_model` in the session's `GSTACK_PREFERENCES_FILE` (GST-982), an ok run other than `--for review-voice` also prints `LOADOUT: …` and `SKILL_ROOT: ` just before `GSTACK_LAUNCH`. For a loadout other than `full`, `GSTACK_LAUNCH_FILE` then names `.loadout--.env`, a copy of the verdict's launch file that adds `GSTACK_LOADOUT_SKILL_ROOT`; the diff --git a/docs/loadouts.md b/docs/loadouts.md index b3ba8299e..91042a7c6 100644 --- a/docs/loadouts.md +++ b/docs/loadouts.md @@ -48,13 +48,14 @@ gstack never guesses the model. It uses, in order: 1. An explicit loadout: `./setup --loadout ` on Claude Code, or `bin/gstack-modules install --loadout `. It is served as asked and bound to no model. 2. An explicit model id: `--model ` on the Capy installer (`scripts/install.sh --model `, which passes it to `bin/gstack-capy-install`), else `GSTACK_MODEL`, which the installer also reads. -3. Nothing: `full`. +3. On Capy only, with neither: the `agent_model` in the Drive skill's `preferences.yaml`, as `gstack-models resolve --role agent` resolves it (`opus` is the newest Opus). `host` or no file means no model. +4. Nothing: `full`. A model id is lowercased, its `provider/` prefix and a trailing `[…]` are dropped, and it must then be a plain id (`^[a-z0-9][a-z0-9._-]{0,79}$`). An unmapped id serves `full`; an id that is not plain also serves `full` and prints `LOADOUT_INVALID_MODEL`. Nothing reads Claude Code settings or an inherited loadout variable, so a Sonnet subagent of an Opus session gets `full` unless its own install names Opus. ### Capy -The Capy skill passes the thread's model id in the environment: `GSTACK_MODEL= bash scripts/install.sh --check --for `. The variable, unlike `--model`, is safe on a checkout whose installer predates loadouts: that installer ignores it instead of refusing an unknown argument. The installer prints two lines before the launch lines: +A plain `bash scripts/install.sh --check --for ` picks the loadout from the owner's `agent_model` preference, so the skill needs no model sentence (`source=preferences` on the line below). A session can still name its own model with `GSTACK_MODEL=`, which wins over the preference and, unlike `--model`, is safe on a checkout whose installer predates loadouts: that installer ignores it instead of refusing an unknown argument. The installer prints two lines before the launch lines: ``` LOADOUT: lite model=claude-opus-5-5 source=GSTACK_MODEL digest=3f2a9c01d4e7 reused=yes diff --git a/test/gstack-capy-install.test.ts b/test/gstack-capy-install.test.ts index b36e76f64..6f90daac8 100644 --- a/test/gstack-capy-install.test.ts +++ b/test/gstack-capy-install.test.ts @@ -593,6 +593,59 @@ describe('gstack-capy-install: launch PATH, Bun reuse, CI pins, setup skip, verd expect(fs.existsSync(lite)).toBe(true); }); + test('with no --model and no GSTACK_MODEL, the agent_model in the session preferences file picks the loadout (GST-982); GSTACK_MODEL still wins and a host preference serves full', () => { + const f = fixture(); + script(path.join(f.root, 'bin/gstack-modules'), [ + 'echo "modules $*" >> "$CAPY_LOG"', + 'model="${GSTACK_MODEL:-}" full=""; while [ $# -gt 0 ]; do case "$1" in --model) model="$2"; shift ;; --full-root) full="$2"; shift ;; esac; shift; done', + 'case "$model" in', + ' claude-opus-5-5) mkdir -p "$HOME/lite-0123456789ab"; echo "LOADOUT: lite model=claude-opus-5-5 source=model-flag digest=0123456789ab reused=no"; echo "SKILL_ROOT: $HOME/lite-0123456789ab" ;;', + ' *) echo "LOADOUT: full model=none source=GSTACK_MODEL reason=unmapped"; echo "SKILL_ROOT: $full" ;;', + 'esac', + ]); + script(path.join(f.root, 'bin/gstack-models'), [ + 'echo "models $* prefs=${GSTACK_PREFERENCES_FILE:-}" >> "$CAPY_LOG"', + 'case "$(sed -n "s/^agent_model: *//p" "${GSTACK_PREFERENCES_FILE:-/dev/null}" 2>/dev/null)" in', + ' opus) echo "agent: anthropic/claude-opus-5-5 (opus) - from agent_model in $GSTACK_PREFERENCES_FILE, the preferences file" ;;', + ' *) echo "agent: host - keep the running agent\'s own model and omit the model field (no preference set)" ;;', + 'esac', + ]); + const prefs = path.join(f.home, 'drive-skill/preferences.yaml'); + write(prefs, 'agent_model: opus\n'); + const launchOf = (out: string) => out.match(/^GSTACK_LAUNCH_FILE: (.+)$/m)![1]; + const opus = run(f, ['--for', 'ship'], { GSTACK_PREFERENCES_FILE: prefs }); + expect(opus.status, opus.stdout + opus.stderr).toBe(0); + expect(f.calls().filter(l => l.startsWith('modules '))).toEqual([`modules install --model claude-opus-5-5 --full-root ${f.home}/.claude/skills`]); + expect(opus.stdout).toContain(`LOADOUT: lite model=claude-opus-5-5 source=preferences digest=0123456789ab reused=no\nSKILL_ROOT: ${f.home}/lite-0123456789ab\n`); + expect(launchOf(opus.stdout)).toBe(verdicts(f)[0].replace(/\.json$/, '.loadout-lite-0123456789ab.env')); + + const env = run(f, ['--for', 'ship'], { GSTACK_PREFERENCES_FILE: prefs, GSTACK_MODEL: 'claude-sonnet-5-5' }); + expect(env.status, env.stdout + env.stderr).toBe(0); + expect(f.calls().filter(l => l.startsWith('modules ')).at(-1)).toBe(`modules install --full-root ${f.home}/.claude/skills`); + expect(env.stdout).toContain('LOADOUT: full model=none source=GSTACK_MODEL reason=unmapped\n'); + + write(prefs, 'agent_model: host\n'); + const host = run(f, ['--for', 'ship'], { GSTACK_PREFERENCES_FILE: prefs }); + expect(host.status, host.stdout + host.stderr).toBe(0); + expect(host.stdout).not.toMatch(/^(LOADOUT|SKILL_ROOT):/m); + expect(launchOf(host.stdout)).toBe(verdicts(f)[0].replace(/\.json$/, '.env')); + }); + + test('the first line of gstack-models resolve --role agent keeps the provider/model shape the installer reads (GST-982)', () => { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gst982-')); + try { + for (const [pref, want] of [['opus', /^agent: anthropic\/claude-opus-[0-9a-z.-]+ \(opus\) /], ['host', /^agent: host /]] as const) { + const file = path.join(dir, `${pref}.yaml`); + fs.writeFileSync(file, `agent_model: ${pref}\n`); + const out = spawnSync(path.join(REPO, 'bin/gstack-models'), ['resolve', '--role', 'agent'], { encoding: 'utf8', timeout: 30_000, env: { ...process.env, GSTACK_PREFERENCES_FILE: file, GSTACK_STATE_ROOT: dir, GSTACK_HOME: dir } }); + expect(out.status, out.stderr).toBe(0); + expect(out.stdout.split('\n')[0]).toMatch(want); + } + } finally { + fs.rmSync(dir, { recursive: true, force: true }); + } + }); + test('the verdict file records checkout, HEAD, workflow, trailer and the Bun resolution, keyed by checkout and project; --check certifies without setup or downloads', () => { const f = fixture(); const r = run(f, ['--for', 'autoplan']);