diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index f8fcc3bd..3f7402b3 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixed +- Scoped models (`--models` or `enabledModels`) now remember the last selected model across sessions instead of always starting with the first model in the scope ([#736](https://github.com/badlogic/pi-mono/pull/736) by [@ogulcancelik](https://github.com/ogulcancelik)) - Show `bun install` instead of `npm install` in update notification when running under Bun ([#714](https://github.com/badlogic/pi-mono/pull/714) by [@dannote](https://github.com/dannote)) - `/skill` prompts now include the skill path ([#711](https://github.com/badlogic/pi-mono/pull/711) by [@jblwilliams](https://github.com/jblwilliams)) - Use configurable `expandTools` keybinding instead of hardcoded Ctrl+O ([#717](https://github.com/badlogic/pi-mono/pull/717) by [@dannote](https://github.com/dannote)) diff --git a/packages/coding-agent/src/main.ts b/packages/coding-agent/src/main.ts index 1a37d49b..996b0922 100644 --- a/packages/coding-agent/src/main.ts +++ b/packages/coding-agent/src/main.ts @@ -5,7 +5,7 @@ * createAgentSession() options. The SDK does the heavy lifting. */ -import { type ImageContent, supportsXhigh } from "@mariozechner/pi-ai"; +import { type ImageContent, modelsAreEqual, supportsXhigh } from "@mariozechner/pi-ai"; import chalk from "chalk"; import { existsSync } from "fs"; import { join } from "path"; @@ -164,16 +164,30 @@ function buildSessionOptions( } options.model = model; } else if (scopedModels.length > 0 && !parsed.continue && !parsed.resume) { - options.model = scopedModels[0].model; + // Check if saved default is in scoped models - use it if so, otherwise first scoped model + const savedProvider = settingsManager.getDefaultProvider(); + const savedModelId = settingsManager.getDefaultModel(); + const savedModel = savedProvider && savedModelId ? modelRegistry.find(savedProvider, savedModelId) : undefined; + const savedInScope = savedModel ? scopedModels.find((sm) => modelsAreEqual(sm.model, savedModel)) : undefined; + + if (savedInScope) { + options.model = savedInScope.model; + // Use thinking level from scoped model config if explicitly set + if (!parsed.thinking && savedInScope.thinkingLevel) { + options.thinkingLevel = savedInScope.thinkingLevel; + } + } else { + options.model = scopedModels[0].model; + // Use thinking level from first scoped model if explicitly set + if (!parsed.thinking && scopedModels[0].thinkingLevel) { + options.thinkingLevel = scopedModels[0].thinkingLevel; + } + } } - // Thinking level - // Only use scoped model's thinking level if it was explicitly specified (e.g., "model:high") - // Otherwise, let the SDK use defaultThinkingLevel from settings + // Thinking level from CLI (takes precedence over scoped model thinking levels set above) if (parsed.thinking) { options.thinkingLevel = parsed.thinking; - } else if (scopedModels.length > 0 && scopedModels[0].thinkingLevel && !parsed.continue && !parsed.resume) { - options.thinkingLevel = scopedModels[0].thinkingLevel; } // Scoped models for Ctrl+P cycling - fill in default thinking level for models without explicit level