xonecas.io
64875
Mc

mini-coder / commit 01f4abb

feat: interactive model and session pickers with yoctoselect

- /model (no args) opens interactive filtered selector
- /session (no args) opens interactive filtered selector
- Gate stdin during select() to prevent shared reader conflicts
- Await handleSessionCommand (was missing await on async fn)
- Export setStdinGated for use by command handlers
- Unexport renderSessionTable (now only used internally)

xonecas2026-03-21 01f4abbb8a38aebd1e2f23d5721b9be7645fcf9f parent a6f3206

7 files changed

TODO.md+1−3
@@ -1,5 +1,3 @@
11 # mini-coder TODO
22
3-- [ ] Integrate yoctoselect into `/model` command (interactive model picker)
4-- [ ] Integrate yoctoselect into `/session` command (interactive session picker)
5-- [ ] Publish yoctoselect to npm
3+Nothing pending.
package.json+1−0
@@ -31,6 +31,7 @@
3131 "diff": "^8.0.3",
3232 "yoctocolors": "^2.1.2",
3333 "yoctomarkdown": "^0.0.7",
34+ "yoctoselect": "0.0.2",
3435 "zod": "^4.3.6"
3536 },
3637 "devDependencies": {
src/cli/commands-model.ts+25−42
@@ -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
src/cli/commands-session.ts+37−7
@@ -1,9 +1,14 @@
11 import * as c from "yoctocolors";
2-import { renderSessionTable } from "../session/manager.ts";
3-import { PREFIX, writeln } from "./output.ts";
2+import { select } from "yoctoselect";
3+import { listSessions } from "../session/db/index.ts";
4+import { setStdinGated } from "./input.ts";
5+import { PREFIX, tildePath, writeln } from "./output.ts";
46 import type { CommandContext } from "./types.ts";
57
6-export function handleSessionCommand(ctx: CommandContext, args: string): void {
8+export async function handleSessionCommand(
9+ ctx: CommandContext,
10+ args: string,
11+): Promise<void> {
712 const id = args.trim();
813 if (id) {
914 ctx.startSpinner("switching session");
@@ -19,10 +24,35 @@ export function handleSessionCommand(ctx: CommandContext, args: string): void {
1924 return;
2025 }
2126
22- const shown = renderSessionTable(
23- `${c.dim("Use")} /session <id> ${c.dim("to switch to a session.")}`,
24- );
25- if (!shown) {
27+ const sessions = listSessions(50);
28+ if (sessions.length === 0) {
2629 writeln(`${PREFIX.info} ${c.dim("no sessions found")}`);
30+ return;
31+ }
32+
33+ const items = sessions.map((s) => {
34+ const title = s.title || "(untitled)";
35+ const model = s.model.split("/").pop() ?? s.model;
36+ const cwd = tildePath(s.cwd);
37+ const date = new Date(s.updated_at).toLocaleDateString();
38+ return {
39+ label: `${c.dim(s.id)} ${title} ${c.cyan(model)} ${c.dim(cwd)} ${c.dim(date)}`,
40+ value: s.id,
41+ filterText: `${s.id} ${s.title} ${s.model} ${s.cwd}`,
42+ };
43+ });
44+
45+ setStdinGated(true);
46+ const picked = await select({ items, placeholder: "search sessions..." });
47+ setStdinGated(false);
48+ if (!picked) return;
49+
50+ const ok = ctx.switchSession(picked);
51+ if (ok) {
52+ writeln(
53+ `${PREFIX.success} switched to session ${c.cyan(picked)} (${c.cyan(ctx.currentModel)})`,
54+ );
55+ } else {
56+ writeln(`${PREFIX.error} session ${c.cyan(picked)} not found`);
2757 }
2858 }
src/cli/commands.ts+1−1
@@ -83,7 +83,7 @@ export async function handleCommand(
8383
8484 case "session":
8585 case "sessions":
86- handleSessionCommand(ctx, args);
86+ await handleSessionCommand(ctx, args);
8787 return { type: "handled" };
8888
8989 case "new":
src/cli/input.ts+1−1
@@ -84,7 +84,7 @@ let _stdinGated = false;
8484 * Gate stdin: while gated, the shared ReadableStream drops incoming data
8585 * so that watchForCancel's own listener is the sole consumer.
8686 */
87-function setStdinGated(gated: boolean): void {
87+export function setStdinGated(gated: boolean): void {
8888 _stdinGated = gated;
8989 }
9090
src/session/manager.ts+1−1
@@ -48,7 +48,7 @@ export function autoTitleSession(sessionId: string, userText: string): void {
4848
4949 // ─── List sessions (for --list flag) ─────────────────────────────────────────
5050
51-export function renderSessionTable(footer: string): boolean {
51+function renderSessionTable(footer: string): boolean {
5252 const sessions = listSessions(20);
5353 if (sessions.length === 0) return false;