xonecas.io
64875
Mc

mini-coder / commit c7a3dc1

feat: /thinking command and full selection banner

Add /thinking, listing the current model's supported levels (pi-ai
getSupportedThinkingLevels) for a numbered pick; the choice applies live
and persists. Extend the thinkingEffort schema to accept "off" (the only
level for non-reasoning models), and generalize saveSelection into
saveConfig(patch) so all three commands share one atomic writer.

Startup, /provider, /model, and /thinking now all print the same
'mini-coder · provider/model · thinking' banner after a change.

xonecas2026-09-26 c7a3dc1f1b5209195de09243e0e183a951e7cfc4 parent 884bdc7

3 files changed

src/config.ts+10−4
@@ -7,6 +7,7 @@ import {
77 Type,
88 type Api,
99 type Model,
10+ type ModelThinkingLevel,
1011 type MutableModels,
1112 type Static,
1213 } from "@earendil-works/pi-ai";
@@ -54,6 +55,7 @@ const ConfigSchema = Type.Object(
5455 model: Type.String(),
5556 thinkingEffort: Type.Union(
5657 [
58+ Type.Literal("off"),
5759 Type.Literal("minimal"),
5860 Type.Literal("low"),
5961 Type.Literal("medium"),
@@ -105,16 +107,20 @@ export function loadConfig(): Config {
105107 }
106108
107109 /**
108- * Persist the chosen pair to the global config, leaving every other key
109- * untouched. Written atomically: a temp file, then a rename over the target.
110+ * Persist a patch to the global config, leaving every other key untouched.
111+ * Written atomically: a temp file, then a rename over the target.
110112 */
111-export function saveSelection(provider: string, model: string): void {
113+export function saveConfig(patch: {
114+ provider?: string;
115+ model?: string;
116+ thinkingEffort?: ModelThinkingLevel;
117+}): void {
112118 const path = configPath();
113119 const existing = readJson(path);
114120 if (typeof existing !== "object" || existing === null || Array.isArray(existing)) {
115121 throw new Error(`config ${path}: not an object`);
116122 }
117- const next = { ...existing, provider, model };
123+ const next = { ...existing, ...patch };
118124 mkdirSync(dirname(path), { recursive: true });
119125 const temp = join(dirname(path), `.${process.pid}.${Date.now()}.tmp`);
120126 writeFileSync(temp, `${JSON.stringify(next, null, 2)}\n`);
src/tui/commands.ts+31−5
@@ -1,5 +1,14 @@
1-import type { Api, AuthEvent, AuthPrompt, AuthType, Model, Models } from "@earendil-works/pi-ai";
2-import { saveSelection } from "../config.ts";
1+import {
2+ getSupportedThinkingLevels,
3+ type Api,
4+ type AuthEvent,
5+ type AuthPrompt,
6+ type AuthType,
7+ type Model,
8+ type ModelThinkingLevel,
9+ type Models,
10+} from "@earendil-works/pi-ai";
11+import { saveConfig } from "../config.ts";
312 import { dim, red } from "./styles.ts";
413 import { commonPrefix } from "./complete.ts";
514
@@ -10,6 +19,8 @@ export interface CommandContext {
1019 model: Model<Api>;
1120 /** Switches the running session to `model`. */
1221 select(model: Model<Api>): void;
22+ /** Sets the running session's thinking level. */
23+ setThinking(level: ModelThinkingLevel): void;
1324 /** Aborts when the running command is cancelled (Ctrl+C). */
1425 signal: AbortSignal;
1526 /** Appends already-styled lines to scrollback. */
@@ -125,11 +136,26 @@ const provider: Command = {
125136 });
126137 const chosen = models.find((m) => m.id === modelId);
127138 if (chosen === undefined) throw new Error(`unknown model: ${modelId}`);
128- saveSelection(providerId, modelId);
139+ saveConfig({ provider: providerId, model: modelId });
129140 ctx.select(chosen);
130141 },
131142 };
132143
144+const thinking: Command = {
145+ name: "thinking",
146+ description: "set the thinking level",
147+ async run(ctx): Promise<void> {
148+ const levels = getSupportedThinkingLevels(ctx.model);
149+ const level = (await ctx.prompt({
150+ type: "select",
151+ message: "Select a thinking level",
152+ options: levels.map((l) => ({ id: l, label: l })),
153+ })) as ModelThinkingLevel;
154+ saveConfig({ thinkingEffort: level });
155+ ctx.setThinking(level);
156+ },
157+};
158+
133159 const model: Command = {
134160 name: "model",
135161 description: "choose a model for the current provider",
@@ -145,12 +171,12 @@ const model: Command = {
145171 });
146172 const chosen = models.find((m) => m.id === modelId);
147173 if (chosen === undefined) throw new Error(`unknown model: ${modelId}`);
148- saveSelection(providerId, modelId);
174+ saveConfig({ provider: providerId, model: modelId });
149175 ctx.select(chosen);
150176 },
151177 };
152178
153-const COMMANDS: Command[] = [help, login, provider, model];
179+const COMMANDS: Command[] = [help, login, provider, model, thinking];
154180
155181 /** `/name` for a known `name`, else null; unknown slash text stays a message. */
156182 export function findCommand(text: string): { command: Command; args: string } | null {
src/tui/tui.ts+18−6
@@ -8,6 +8,7 @@ import {
88 type JsonObject,
99 type Message,
1010 type Model,
11+ type ModelThinkingLevel,
1112 type UserMessage,
1213 } from "@earendil-works/pi-ai";
1314 import { assistantText, runAgentTurn, type AgentEvent, type AgentOptions, type Phase } from "../agent.ts";
@@ -241,9 +242,7 @@ class Tui {
241242 this.term.start();
242243 process.on("SIGINT", this.onSignal);
243244 process.on("SIGTERM", this.onSignal);
244- this.separator = true;
245- this.push(`mini-coder · ${this.opts.model.provider}/${this.opts.model.id} · ${this.opts.thinkingEffort}`);
246- this.separator = true;
245+ this.pushBanner();
247246 this.render();
248247 }
249248
@@ -330,6 +329,7 @@ class Tui {
330329 models: this.opts.models,
331330 model: this.opts.model,
332331 select: (model) => this.select(model),
332+ setThinking: (level) => this.setThinking(level),
333333 signal: abort.signal,
334334 write: (lines) => {
335335 this.separator = true;
@@ -355,6 +355,13 @@ class Tui {
355355 })();
356356 }
357357
358+ /** The startup and selection banner: provider, model, and thinking effort. */
359+ private pushBanner(): void {
360+ this.separator = true;
361+ this.push(`mini-coder · ${this.opts.model.provider}/${this.opts.model.id} · ${this.opts.thinkingEffort}`);
362+ this.separator = true;
363+ }
364+
358365 /**
359366 * Switches the running session to `model`: derived state follows — the
360367 * thinking effort is re-clamped, and `read`'s image behaviour is rebuilt for
@@ -365,9 +372,14 @@ class Tui {
365372 this.opts.model = model;
366373 this.opts.thinkingEffort = clampThinkingLevel(model, this.opts.thinkingEffort);
367374 this.opts.tools = toolSchemas(this.opts.toolNames, acceptsImages(model));
368- this.separator = true;
369- this.push(`${model.provider}/${model.id}`);
370- this.separator = true;
375+ this.pushBanner();
376+ this.render();
377+ }
378+
379+ /** Sets the running session's thinking level, clamped to the current model. */
380+ private setThinking(level: ModelThinkingLevel): void {
381+ this.opts.thinkingEffort = clampThinkingLevel(this.opts.model, level);
382+ this.pushBanner();
371383 this.render();
372384 }