@@ -1,6 +1,8 @@
11 import * as c from "yoctocolors";
2+import { select } from "yoctoselect";
23 import type { ThinkingEffort } from "../llm-api/providers.ts";
34 import { fetchAvailableModels } from "../llm-api/providers.ts";
5+import { setStdinGated } from "./input.ts";
46 import { PREFIX, writeln } from "./output.ts";
57 import type { CommandContext } from "./types.ts";
68
@@ -106,7 +108,7 @@ function handleModelEffort(ctx: CommandContext, effortArg: string): void {
106108 writeln(`${PREFIX.success} thinking effort → ${c.cyan(effort)}`);
107109 }
108110
109-async function renderModelList(ctx: CommandContext): Promise<void> {
111+async function handleModelSelect(ctx: CommandContext): Promise<void> {
110112 ctx.startSpinner("fetching models");
111113 const snapshot = await fetchAvailableModels();
112114 ctx.stopSpinner();
@@ -133,46 +135,27 @@ async function renderModelList(ctx: CommandContext): Promise<void> {
133135 );
134136 }
135137
136- const modelsByProvider = new Map<string, typeof snapshot.models>();
137- for (const model of snapshot.models) {
138- const providerModels = modelsByProvider.get(model.provider);
139- if (providerModels) {
140- providerModels.push(model);
141- } else {
142- modelsByProvider.set(model.provider, [model]);
143- }
144- }
145-
146- writeln();
147- for (const [provider, providerModels] of modelsByProvider) {
148- writeln(c.bold(` ${provider}`));
149- for (const model of providerModels) {
150- const isCurrent = ctx.currentModel === model.id;
151- const freeTag = model.free ? c.green(" free") : "";
152- const contextTag = model.context
153- ? c.dim(` ${Math.round(model.context / 1000)}k`)
154- : "";
155- const effortTag =
156- isCurrent && ctx.thinkingEffort
157- ? c.dim(` ✦ ${ctx.thinkingEffort}`)
158- : "";
159- const currentTag = isCurrent ? c.cyan(" ◀") : "";
160- writeln(
161- ` ${c.dim("·")} ${model.displayName}${freeTag}${contextTag}${currentTag}${effortTag}`,
162- );
163- writeln(` ${c.dim(model.id)}`);
164- }
165- }
166-
167- writeln();
168- writeln(
169- c.dim(" /model <id> to switch · e.g. /model zen/claude-sonnet-4-6"),
170- );
171- writeln(
172- c.dim(
173- " /model effort <low|medium|high|xhigh|off> to set thinking effort",
174- ),
175- );
138+ const items = snapshot.models.map((model) => {
139+ const isCurrent = ctx.currentModel === model.id;
140+ const freeTag = model.free ? c.green(" free") : "";
141+ const contextTag = model.context
142+ ? c.dim(` ${Math.round(model.context / 1000)}k`)
143+ : "";
144+ const currentTag = isCurrent ? c.cyan(" ◀") : "";
145+ return {
146+ label: `${model.displayName}${freeTag}${contextTag}${currentTag}`,
147+ value: model.id,
148+ filterText: `${model.id} ${model.displayName} ${model.provider}`,
149+ };
150+ });
151+
152+ setStdinGated(true);
153+ const picked = await select({ items, placeholder: "search models..." });
154+ setStdinGated(false);
155+ if (!picked) return;
156+
157+ ctx.setModel(picked);
158+ renderModelUpdatedMessage(ctx, picked);
176159 }
177160
178161 export async function handleModelCommand(
@@ -181,7 +164,7 @@ export async function handleModelCommand(
181164 ): Promise<void> {
182165 const parts = args.trim().split(/\s+/).filter(Boolean);
183166 if (parts.length === 0) {
184- await renderModelList(ctx);
167+ await handleModelSelect(ctx);
185168 return;
186169 }
187170