From 2914ff451a2031e9237131fed2d2b528801c670d Mon Sep 17 00:00:00 2001 From: garrytan Date: Mon, 2 Nov 2026 14:55:27 +0000 Subject: [PATCH 1/5] fix(capy): installer picks the loadout from the owner's agent_model preference when no model is named (GST-982) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --- bin/gstack-capy-install | 14 ++++-- changelog.d/gsta161-gst-982-capy-model.md | 7 +++ docs/capy-install.md | 4 +- docs/loadouts.md | 5 ++- test/gstack-capy-install.test.ts | 53 +++++++++++++++++++++++ 5 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 changelog.d/gsta161-gst-982-capy-model.md 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']); From f2cebc7437788cdb4c7e77bdbb3e2e8ac8d148c9 Mon Sep 17 00:00:00 2001 From: garrytan Date: Mon, 2 Nov 2026 15:07:28 +0000 Subject: [PATCH 2/5] fix(capy): label config-sourced agent_model, note the assumption, skip it inside eval runs (GST-982 review) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --- bin/gstack-capy-install | 14 ++++++++++---- changelog.d/gsta161-gst-982-capy-model.md | 4 ++-- docs/capy-install.md | 3 ++- docs/loadouts.md | 2 +- test/gstack-capy-install.test.ts | 15 +++++++++++++++ 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/bin/gstack-capy-install b/bin/gstack-capy-install index a9f7bf26e..6122d76e4 100755 --- a/bin/gstack-capy-install +++ b/bin/gstack-capy-install @@ -724,9 +724,13 @@ 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 +if [ "$RC" -eq 0 ] && [ -z "$MODEL" ] && [ -n "${GSTACK_PREFERENCES_FILE:-}" ] && [ -z "${GSTACK_EVAL_DIR:-}${EVALS_RUN_ID:-}" ] && [ "$PROFILE" -eq 0 ] && [ -n "$LAUNCH_FILE" ]; then + _ag_first=$(cd "$ROOT" && bin/gstack-models resolve --role agent 2>/dev/null | head -1) + case "$_ag_first" in + *", this machine") MODEL_SOURCE=config ;; + *", the preferences file") MODEL_SOURCE=preferences ;; + esac + [ "$MODEL_SOURCE" = GSTACK_MODEL ] || MODEL=$(printf '%s' "$_ag_first" | sed -n 's|^agent: [a-z0-9-]*/\([A-Za-z0-9._-]*\) .*|\1|p') 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)") @@ -736,9 +740,11 @@ if [ "$RC" -eq 0 ] && [ -n "$MODEL" ] && [ "$PROFILE" -eq 0 ] && [ -n "$LAUNCH_F _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/') + case "$MODEL_SOURCE" in preferences|config) _lo_line=$(printf '%s' "$_lo_line" | sed "s/ source=model-flag/ source=$MODEL_SOURCE/") ;; esac _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): ') + case "$MODEL_SOURCE" in preferences|config) _lo_notes="${_lo_notes:+$_lo_notes +}LOADOUT_ASSUMED: model=$MODEL is the owner's agent_model ($MODEL_SOURCE), not read from the session; a session on another model sets GSTACK_MODEL=" ;; esac _lo_name=$(printf '%s' "$_lo_line" | sed -n 's/^LOADOUT: \([a-z0-9-]*\) .*/\1/p') _lo_digest=$(printf '%s' "$_lo_line" | sed -n 's/.* digest=\([0-9a-f]\{12\}\) .*/\1/p') if [ -n "$_lo_name" ] && [ "$_lo_name" != full ]; then diff --git a/changelog.d/gsta161-gst-982-capy-model.md b/changelog.d/gsta161-gst-982-capy-model.md index 478e298bc..7bbe0e299 100644 --- a/changelog.d/gsta161-gst-982-capy-model.md +++ b/changelog.d/gsta161-gst-982-capy-model.md @@ -1,7 +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. +- **`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` (`source=config` when this machine's `config.yaml` sets it), followed by a `LOADOUT_ASSUMED:` note that the model came from the preference and not the session. Eval runs (`GSTACK_EVAL_DIR` or `EVALS_RUN_ID` set) skip the preference. `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. +- `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 `config.yaml` preference reads `source=config`, eval runs skip 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 5f50afee9..1aa27b2dc 100644 --- a/docs/capy-install.md +++ b/docs/capy-install.md @@ -473,7 +473,8 @@ make writable, or set GSTACK_STATE_ROOT to a writable directory 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 `, `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: …` +`agent_model` in the session's `GSTACK_PREFERENCES_FILE` outside an eval run (GST-982, with a +`LOADOUT_ASSUMED:` note), 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 91042a7c6..adc02078b 100644 --- a/docs/loadouts.md +++ b/docs/loadouts.md @@ -55,7 +55,7 @@ A model id is lowercased, its `provider/` prefix and a trailing `[…]` are drop ### Capy -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: +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, or `source=config` when this machine's `config.yaml` sets `agent_model`). The preference names the model Garry starts sessions on, not the model reading the skill, so the installer says so in a `LOADOUT_ASSUMED:` line, and it skips the preference inside an eval run (`GSTACK_EVAL_DIR` or `EVALS_RUN_ID` set), where the model under test may differ. A session on another model names its own 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 6f90daac8..52db9a11a 100644 --- a/test/gstack-capy-install.test.ts +++ b/test/gstack-capy-install.test.ts @@ -605,6 +605,7 @@ describe('gstack-capy-install: launch PATH, Bun reuse, CI pins, setup skip, verd ]); script(path.join(f.root, 'bin/gstack-models'), [ 'echo "models $* prefs=${GSTACK_PREFERENCES_FILE:-}" >> "$CAPY_LOG"', + '[ -z "${FAKE_CONFIG_MODEL:-}" ] || { echo "agent: anthropic/$FAKE_CONFIG_MODEL (opus) - from agent_model in $HOME/.gstack/config.yaml, this machine"; exit 0; }', '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)" ;;', @@ -618,6 +619,20 @@ describe('gstack-capy-install: launch PATH, Bun reuse, CI pins, setup skip, verd 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')); + expect(opus.stdout).toContain("LOADOUT_ASSUMED: model=claude-opus-5-5 is the owner's agent_model (preferences), not read from the session; a session on another model sets GSTACK_MODEL=\n"); + + const config = run(f, ['--for', 'ship'], { GSTACK_PREFERENCES_FILE: prefs, FAKE_CONFIG_MODEL: 'claude-opus-5-5' }); + expect(config.status, config.stdout + config.stderr).toBe(0); + expect(config.stdout).toContain('LOADOUT: lite model=claude-opus-5-5 source=config digest=0123456789ab'); + expect(config.stdout).toContain("is the owner's agent_model (config)"); + + const modulesBefore = f.calls().filter(l => l.startsWith('modules ')).length; + for (const evalEnv of [{ GSTACK_EVAL_DIR: path.join(f.home, 'evals') }, { EVALS_RUN_ID: 'r1' }]) { + const ev = run(f, ['--for', 'ship'], { GSTACK_PREFERENCES_FILE: prefs, ...evalEnv }); + expect(ev.status, ev.stdout + ev.stderr).toBe(0); + expect(ev.stdout).not.toMatch(/^(LOADOUT|LOADOUT_ASSUMED|SKILL_ROOT):/m); + } + expect(f.calls().filter(l => l.startsWith('modules ')).length).toBe(modulesBefore); 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); From f0ca2743422f2053a058e103b5e1878da5c9f1b9 Mon Sep 17 00:00:00 2001 From: garrytan Date: Mon, 2 Nov 2026 15:09:50 +0000 Subject: [PATCH 3/5] docs(loadouts): the Capy preference is an assumption; non-Opus sessions set GSTACK_MODEL (GST-982 review) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --- docs/loadouts.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/loadouts.md b/docs/loadouts.md index adc02078b..1b44d99ae 100644 --- a/docs/loadouts.md +++ b/docs/loadouts.md @@ -44,14 +44,14 @@ bin/gstack-modules install --full-root "$HOME/.claude/skills" --model claude-opu ### How gstack picks a loadout -gstack never guesses the model. It uses, in order: +gstack does not detect the running 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. 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. +3. On Capy only, with neither and outside an eval run: the owner's `agent_model` (this machine's `config.yaml`, else the Drive skill's `preferences.yaml`), as `gstack-models resolve --role agent` resolves it (`opus` is the newest Opus). This is an assumption, not a detection, and the installer prints `LOADOUT_ASSUMED:` beside it. `host` or no preference 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. +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 on Claude Code a Sonnet subagent of an Opus session gets `full` unless its own install names Opus. On Capy every session shares the owner's preference, so a session on another model sets `GSTACK_MODEL=` to get its own loadout. ### Capy From 6c2a9d0b810f9f9cfdae61e56b0bb45fa2039135 Mon Sep 17 00:00:00 2001 From: garrytan Date: Mon, 2 Nov 2026 15:12:29 +0000 Subject: [PATCH 4/5] fix(capy): an unresolvable agent_model prints LOADOUT_FALLBACK (GST-982 review) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --- bin/gstack-capy-install | 4 +++- changelog.d/gsta161-gst-982-capy-model.md | 4 ++-- test/gstack-capy-install.test.ts | 8 ++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bin/gstack-capy-install b/bin/gstack-capy-install index 6122d76e4..4ad259627 100755 --- a/bin/gstack-capy-install +++ b/bin/gstack-capy-install @@ -725,11 +725,13 @@ fi record_verdict "$TRAILER" "$([ "$RC" -eq 0 ] && echo 1 || echo 0)" LOADOUT_LINES="" if [ "$RC" -eq 0 ] && [ -z "$MODEL" ] && [ -n "${GSTACK_PREFERENCES_FILE:-}" ] && [ -z "${GSTACK_EVAL_DIR:-}${EVALS_RUN_ID:-}" ] && [ "$PROFILE" -eq 0 ] && [ -n "$LAUNCH_FILE" ]; then - _ag_first=$(cd "$ROOT" && bin/gstack-models resolve --role agent 2>/dev/null | head -1) + _ag_out=$(cd "$ROOT" && bin/gstack-models resolve --role agent 2>&1) && _ag_rc=0 || _ag_rc=$? + _ag_first=$(printf '%s\n' "$_ag_out" | head -1) case "$_ag_first" in *", this machine") MODEL_SOURCE=config ;; *", the preferences file") MODEL_SOURCE=preferences ;; esac + [ "$_ag_rc" -eq 0 ] || LOADOUT_LINES="LOADOUT_FALLBACK: agent_model unreadable: $(printf '%s' "$_ag_first" | tr -d '\000-\037' | cut -c1-200); serving full (docs/troubleshooting.md#loadout-fallback)" [ "$MODEL_SOURCE" = GSTACK_MODEL ] || MODEL=$(printf '%s' "$_ag_first" | sed -n 's|^agent: [a-z0-9-]*/\([A-Za-z0-9._-]*\) .*|\1|p') fi if [ "$RC" -eq 0 ] && [ -n "$MODEL" ] && [ "$PROFILE" -eq 0 ] && [ -n "$LAUNCH_FILE" ]; then diff --git a/changelog.d/gsta161-gst-982-capy-model.md b/changelog.d/gsta161-gst-982-capy-model.md index 7bbe0e299..109ccbddb 100644 --- a/changelog.d/gsta161-gst-982-capy-model.md +++ b/changelog.d/gsta161-gst-982-capy-model.md @@ -1,7 +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` (`source=config` when this machine's `config.yaml` sets it), followed by a `LOADOUT_ASSUMED:` note that the model came from the preference and not the session. Eval runs (`GSTACK_EVAL_DIR` or `EVALS_RUN_ID` set) skip the preference. `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. +- **`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` (`source=config` when this machine's `config.yaml` sets it), followed by a `LOADOUT_ASSUMED:` note that the model came from the preference and not the session. Eval runs (`GSTACK_EVAL_DIR` or `EVALS_RUN_ID` set) skip the preference, and a preference `gstack-models` cannot resolve prints `LOADOUT_FALLBACK` instead of serving full silently. `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 `config.yaml` preference reads `source=config`, eval runs skip 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. +- `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 `config.yaml` preference reads `source=config`, eval runs skip the preference, an unresolvable preference prints `LOADOUT_FALLBACK`, 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/test/gstack-capy-install.test.ts b/test/gstack-capy-install.test.ts index 52db9a11a..3a651fbbe 100644 --- a/test/gstack-capy-install.test.ts +++ b/test/gstack-capy-install.test.ts @@ -605,6 +605,7 @@ describe('gstack-capy-install: launch PATH, Bun reuse, CI pins, setup skip, verd ]); script(path.join(f.root, 'bin/gstack-models'), [ 'echo "models $* prefs=${GSTACK_PREFERENCES_FILE:-}" >> "$CAPY_LOG"', + '[ -z "${FAKE_BAD_MODEL:-}" ] || { echo "agent: agent_model $FAKE_BAD_MODEL is not a model"; exit 1; }', '[ -z "${FAKE_CONFIG_MODEL:-}" ] || { echo "agent: anthropic/$FAKE_CONFIG_MODEL (opus) - from agent_model in $HOME/.gstack/config.yaml, this machine"; exit 0; }', '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" ;;', @@ -634,6 +635,13 @@ describe('gstack-capy-install: launch PATH, Bun reuse, CI pins, setup skip, verd } expect(f.calls().filter(l => l.startsWith('modules ')).length).toBe(modulesBefore); + const bad = run(f, ['--for', 'ship'], { GSTACK_PREFERENCES_FILE: prefs, FAKE_BAD_MODEL: 'gpt-6.1-sol' }); + expect(bad.status, bad.stdout + bad.stderr).toBe(0); + expect(bad.stdout).toContain('LOADOUT_FALLBACK: agent_model unreadable: agent: agent_model gpt-6.1-sol is not a model; serving full (docs/troubleshooting.md#loadout-fallback)\n'); + expect(bad.stdout).not.toMatch(/^(LOADOUT|SKILL_ROOT):/m); + expect(launchOf(bad.stdout)).toBe(verdicts(f)[0].replace(/\.json$/, '.env')); + expect(f.calls().filter(l => l.startsWith('modules ')).length).toBe(modulesBefore); + 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`); From 7382ecbc36038edbb6902ebef14c4bbc4b9db362 Mon Sep 17 00:00:00 2001 From: garrytan Date: Mon, 2 Nov 2026 15:20:10 +0000 Subject: [PATCH 5/5] test(capy): type the eval env rows for the test typecheck ratchet (GST-982) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --- changelog.d/gsta161-gst-982-capy-model.md | 4 ++-- test/gstack-capy-install.test.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/changelog.d/gsta161-gst-982-capy-model.md b/changelog.d/gsta161-gst-982-capy-model.md index 109ccbddb..708685c0a 100644 --- a/changelog.d/gsta161-gst-982-capy-model.md +++ b/changelog.d/gsta161-gst-982-capy-model.md @@ -1,7 +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` (`source=config` when this machine's `config.yaml` sets it), followed by a `LOADOUT_ASSUMED:` note that the model came from the preference and not the session. Eval runs (`GSTACK_EVAL_DIR` or `EVALS_RUN_ID` set) skip the preference, and a preference `gstack-models` cannot resolve prints `LOADOUT_FALLBACK` instead of serving full silently. `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. +- **`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` (`source=config` when this machine's `config.yaml` sets it), followed by a `LOADOUT_ASSUMED:` note that the model came from the preference and not the session. Eval runs (`GSTACK_EVAL_DIR` or `EVALS_RUN_ID` set) skip the preference, and a preference `gstack-models` rejects prints `LOADOUT_FALLBACK` instead of serving full silently. `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 `config.yaml` preference reads `source=config`, eval runs skip the preference, an unresolvable preference prints `LOADOUT_FALLBACK`, a `host` preference prints no loadout lines, and the real `gstack-models resolve --role agent` keeps the `agent: /` first line the installer reads. +- `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 `config.yaml` preference reads `source=config`, eval runs skip the preference, a rejected preference prints `LOADOUT_FALLBACK`, 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/test/gstack-capy-install.test.ts b/test/gstack-capy-install.test.ts index 3a651fbbe..405458549 100644 --- a/test/gstack-capy-install.test.ts +++ b/test/gstack-capy-install.test.ts @@ -628,7 +628,7 @@ describe('gstack-capy-install: launch PATH, Bun reuse, CI pins, setup skip, verd expect(config.stdout).toContain("is the owner's agent_model (config)"); const modulesBefore = f.calls().filter(l => l.startsWith('modules ')).length; - for (const evalEnv of [{ GSTACK_EVAL_DIR: path.join(f.home, 'evals') }, { EVALS_RUN_ID: 'r1' }]) { + for (const evalEnv of [{ GSTACK_EVAL_DIR: path.join(f.home, 'evals') }, { EVALS_RUN_ID: 'r1' }] as Record[]) { const ev = run(f, ['--for', 'ship'], { GSTACK_PREFERENCES_FILE: prefs, ...evalEnv }); expect(ev.status, ev.stdout + ev.stderr).toBe(0); expect(ev.stdout).not.toMatch(/^(LOADOUT|LOADOUT_ASSUMED|SKILL_ROOT):/m);