From 0b1f02219b01f7f79b76e2ea345dc6a4dad9547e Mon Sep 17 00:00:00 2001 From: jonathancostin <66714927+jonathancostin@users.noreply.github.com> Date: Wed, 11 Mar 2026 07:57:55 -0500 Subject: [PATCH] fix: restore scoped models from settings on new session startup (#22) --- src/cli.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/cli.ts b/src/cli.ts index 5bd2946f1..9c253fe28 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -73,5 +73,48 @@ if (extensionsResult.errors.length > 0) { } } +// Restore scoped models from settings on startup. +// The upstream InteractiveMode reads enabledModels from settings when /scoped-models is opened, +// but doesn't apply them to the session at startup — so Ctrl+P cycles all models instead of +// just the saved selection until the user re-runs /scoped-models. +const enabledModelPatterns = settingsManager.getEnabledModels() +if (enabledModelPatterns && enabledModelPatterns.length > 0) { + const availableModels = modelRegistry.getAvailable() + const scopedModels: Array<{ model: (typeof availableModels)[number] }> = [] + const seen = new Set() + + for (const pattern of enabledModelPatterns) { + // Patterns are "provider/modelId" exact strings saved by /scoped-models + const slashIdx = pattern.indexOf('/') + if (slashIdx !== -1) { + const provider = pattern.substring(0, slashIdx) + const modelId = pattern.substring(slashIdx + 1) + const model = availableModels.find((m) => m.provider === provider && m.id === modelId) + if (model) { + const key = `${model.provider}/${model.id}` + if (!seen.has(key)) { + seen.add(key) + scopedModels.push({ model }) + } + } + } else { + // Fallback: match by model id alone + const model = availableModels.find((m) => m.id === pattern) + if (model) { + const key = `${model.provider}/${model.id}` + if (!seen.has(key)) { + seen.add(key) + scopedModels.push({ model }) + } + } + } + } + + // Only apply if we resolved some models and it's a genuine subset + if (scopedModels.length > 0 && scopedModels.length < availableModels.length) { + session.setScopedModels(scopedModels) + } +} + const interactiveMode = new InteractiveMode(session) await interactiveMode.run()