xonecas.io
64875
Mc

mini-coder / commit f6f685f

refactor(cli): extract model and config command handlers

xonecas2026-03-14 f6f685f49c1d308432f2b61073cc18a35fc0db95 parent d484091

4 files changed

src/cli/commands-config.test.ts+74−0
@@ -0,0 +1,74 @@
1+import { describe, expect, test } from "bun:test";
2+import {
3+ handleCacheCommand,
4+ handleContextCommand,
5+ handleReasoningCommand,
6+} from "./commands-config.ts";
7+import type { CommandContext } from "./types.ts";
8+
9+function createContext(overrides?: Partial<CommandContext>): CommandContext {
10+ return {
11+ currentModel: "zen/claude-sonnet-4-6",
12+ setModel: () => {},
13+ thinkingEffort: null,
14+ setThinkingEffort: () => {},
15+ showReasoning: true,
16+ setShowReasoning: () => {},
17+ pruningMode: "balanced",
18+ setPruningMode: () => {},
19+ toolResultPayloadCapBytes: 0,
20+ setToolResultPayloadCapBytes: () => {},
21+ promptCachingEnabled: true,
22+ setPromptCachingEnabled: () => {},
23+ openaiPromptCacheRetention: "in_memory",
24+ setOpenAIPromptCacheRetention: () => {},
25+ googleCachedContent: null,
26+ setGoogleCachedContent: () => {},
27+ undoLastTurn: async () => false,
28+ startNewSession: () => {},
29+ connectMcpServer: async () => {},
30+ runSubagent: async () => ({ result: "", inputTokens: 0, outputTokens: 0 }),
31+ activeAgent: null,
32+ setActiveAgent: () => {},
33+ startSpinner: () => {},
34+ stopSpinner: () => {},
35+ cwd: process.cwd(),
36+ ...overrides,
37+ };
38+}
39+
40+describe("commands-config", () => {
41+ test("/context cap accepts kilobytes", () => {
42+ let captured = 0;
43+ const ctx = createContext({
44+ setToolResultPayloadCapBytes: (bytes) => {
45+ captured = bytes;
46+ },
47+ });
48+ handleContextCommand(ctx, "cap 12kb");
49+ expect(captured).toBe(12 * 1024);
50+ });
51+
52+ test("/cache gemini off clears cached content", () => {
53+ let cachedContent: string | null = "cachedContents/foo";
54+ const ctx = createContext({
55+ setGoogleCachedContent: (value) => {
56+ cachedContent = value;
57+ },
58+ });
59+ handleCacheCommand(ctx, "gemini off");
60+ expect(cachedContent).toBeNull();
61+ });
62+
63+ test("/reasoning toggles when no arg is provided", () => {
64+ let reasoningVisible = true;
65+ const ctx = createContext({
66+ showReasoning: reasoningVisible,
67+ setShowReasoning: (value) => {
68+ reasoningVisible = value;
69+ },
70+ });
71+ handleReasoningCommand(ctx, "");
72+ expect(reasoningVisible).toBe(false);
73+ });
74+});
src/cli/commands-config.ts+149−0
@@ -0,0 +1,149 @@
1+import * as c from "yoctocolors";
2+import { PREFIX, writeln } from "./output.ts";
3+import type { CommandContext } from "./types.ts";
4+
5+export function handleReasoningCommand(
6+ ctx: CommandContext,
7+ args: string,
8+): void {
9+ const mode = args.trim().toLowerCase();
10+ if (!mode) {
11+ const nextVisibility = !ctx.showReasoning;
12+ ctx.setShowReasoning(nextVisibility);
13+ writeln(
14+ `${PREFIX.success} reasoning display ${nextVisibility ? c.green("on") : c.dim("off")}`,
15+ );
16+ return;
17+ }
18+
19+ if (mode === "on") {
20+ ctx.setShowReasoning(true);
21+ writeln(`${PREFIX.success} reasoning display ${c.green("on")}`);
22+ return;
23+ }
24+
25+ if (mode === "off") {
26+ ctx.setShowReasoning(false);
27+ writeln(`${PREFIX.success} reasoning display ${c.dim("off")}`);
28+ return;
29+ }
30+
31+ writeln(`${PREFIX.error} usage: /reasoning <on|off>`);
32+}
33+
34+export function handleContextCommand(ctx: CommandContext, args: string): void {
35+ const [subcommand, value] = args.trim().split(/\s+/, 2);
36+ if (!subcommand) {
37+ const capText =
38+ ctx.toolResultPayloadCapBytes <= 0
39+ ? "off"
40+ : `${Math.round(ctx.toolResultPayloadCapBytes / 1024)}KB (${ctx.toolResultPayloadCapBytes} bytes)`;
41+ writeln(
42+ `${PREFIX.info} pruning=${c.cyan(ctx.pruningMode)} tool-result-cap=${c.cyan(capText)}`,
43+ );
44+ writeln(c.dim(" usage: /context prune <off|balanced|aggressive>"));
45+ writeln(c.dim(" /context cap <off|bytes|kb>"));
46+ return;
47+ }
48+
49+ if (subcommand === "prune") {
50+ if (value === "off" || value === "balanced" || value === "aggressive") {
51+ ctx.setPruningMode(value);
52+ writeln(`${PREFIX.success} context pruning → ${c.cyan(value)}`);
53+ return;
54+ }
55+ writeln(`${PREFIX.error} usage: /context prune <off|balanced|aggressive>`);
56+ return;
57+ }
58+
59+ if (subcommand !== "cap") {
60+ writeln(`${PREFIX.error} usage: /context <prune|cap> ...`);
61+ return;
62+ }
63+
64+ if (!value) {
65+ writeln(`${PREFIX.error} usage: /context cap <off|bytes|kb>`);
66+ return;
67+ }
68+
69+ if (value === "off") {
70+ ctx.setToolResultPayloadCapBytes(0);
71+ writeln(`${PREFIX.success} tool-result payload cap disabled`);
72+ return;
73+ }
74+
75+ const capMatch = value.match(/^(\d+)(kb)?$/i);
76+ if (!capMatch) {
77+ writeln(`${PREFIX.error} invalid cap: ${c.cyan(value)}`);
78+ return;
79+ }
80+
81+ const base = Number.parseInt(capMatch[1] ?? "", 10);
82+ const capBytes =
83+ (capMatch[2] ?? "").toLowerCase() === "kb" ? base * 1024 : base;
84+ if (!Number.isFinite(capBytes) || capBytes < 0) {
85+ writeln(`${PREFIX.error} invalid cap: ${c.cyan(value)}`);
86+ return;
87+ }
88+
89+ ctx.setToolResultPayloadCapBytes(capBytes);
90+ writeln(
91+ `${PREFIX.success} tool-result payload cap → ${c.cyan(`${capBytes} bytes`)}`,
92+ );
93+}
94+
95+export function handleCacheCommand(ctx: CommandContext, args: string): void {
96+ const [subcommand, value] = args.trim().split(/\s+/, 2);
97+
98+ if (!subcommand) {
99+ const geminiCache = ctx.googleCachedContent
100+ ? c.cyan(ctx.googleCachedContent)
101+ : "off";
102+ writeln(
103+ `${PREFIX.info} prompt-caching=${ctx.promptCachingEnabled ? c.green("on") : c.dim("off")} openai-retention=${c.cyan(ctx.openaiPromptCacheRetention)} gemini-cache=${geminiCache}`,
104+ );
105+ writeln(c.dim(" usage: /cache <on|off>"));
106+ writeln(c.dim(" /cache openai <in_memory|24h>"));
107+ writeln(c.dim(" /cache gemini <off|cachedContents/...>"));
108+ return;
109+ }
110+
111+ if (subcommand === "on" || subcommand === "off") {
112+ ctx.setPromptCachingEnabled(subcommand === "on");
113+ writeln(
114+ `${PREFIX.success} prompt caching → ${subcommand === "on" ? c.green("on") : c.dim("off")}`,
115+ );
116+ return;
117+ }
118+
119+ if (subcommand === "openai") {
120+ if (value === "in_memory" || value === "24h") {
121+ ctx.setOpenAIPromptCacheRetention(value);
122+ writeln(
123+ `${PREFIX.success} openai prompt cache retention → ${c.cyan(value)}`,
124+ );
125+ return;
126+ }
127+ writeln(`${PREFIX.error} usage: /cache openai <in_memory|24h>`);
128+ return;
129+ }
130+
131+ if (subcommand !== "gemini") {
132+ writeln(`${PREFIX.error} usage: /cache <on|off|openai|gemini> ...`);
133+ return;
134+ }
135+
136+ if (!value) {
137+ writeln(`${PREFIX.error} usage: /cache gemini <off|cachedContents/...>`);
138+ return;
139+ }
140+
141+ if (value === "off") {
142+ ctx.setGoogleCachedContent(null);
143+ writeln(`${PREFIX.success} gemini cached content → ${c.dim("off")}`);
144+ return;
145+ }
146+
147+ ctx.setGoogleCachedContent(value);
148+ writeln(`${PREFIX.success} gemini cached content → ${c.cyan(value)}`);
149+}
src/cli/commands-model.ts+194−0
@@ -0,0 +1,194 @@
1+import * as c from "yoctocolors";
2+import type { ThinkingEffort } from "../llm-api/providers.ts";
3+import { fetchAvailableModels } from "../llm-api/providers.ts";
4+import { PREFIX, writeln } from "./output.ts";
5+import type { CommandContext } from "./types.ts";
6+
7+const THINKING_EFFORTS: ThinkingEffort[] = ["low", "medium", "high", "xhigh"];
8+
9+function parseThinkingEffort(value: string): ThinkingEffort | null {
10+ return THINKING_EFFORTS.includes(value as ThinkingEffort)
11+ ? (value as ThinkingEffort)
12+ : null;
13+}
14+
15+function findModelIdByAlias(
16+ requestedModel: string,
17+ availableModelIds: string[],
18+): string | null {
19+ for (const id of availableModelIds) {
20+ if (id === requestedModel) return id;
21+ const alias = id.split("/").slice(1).join("/");
22+ if (alias === requestedModel) return id;
23+ }
24+ return null;
25+}
26+
27+function renderModelUpdatedMessage(
28+ ctx: CommandContext,
29+ modelId: string,
30+ effortArg?: string,
31+): void {
32+ if (effortArg) {
33+ if (effortArg === "off") {
34+ ctx.setThinkingEffort(null);
35+ writeln(
36+ `${PREFIX.success} model → ${c.cyan(modelId)} ${c.dim("(thinking disabled)")}`,
37+ );
38+ return;
39+ }
40+
41+ const effort = parseThinkingEffort(effortArg);
42+ if (effort) {
43+ ctx.setThinkingEffort(effort);
44+ writeln(
45+ `${PREFIX.success} model → ${c.cyan(modelId)} ${c.dim(`(✦ ${effort})`)}`,
46+ );
47+ return;
48+ }
49+
50+ writeln(`${PREFIX.success} model → ${c.cyan(modelId)}`);
51+ writeln(
52+ `${PREFIX.error} unknown effort level ${c.cyan(effortArg)} (use low, medium, high, xhigh, off)`,
53+ );
54+ return;
55+ }
56+
57+ const effortTag = ctx.thinkingEffort
58+ ? c.dim(` (✦ ${ctx.thinkingEffort})`)
59+ : "";
60+ writeln(`${PREFIX.success} model → ${c.cyan(modelId)}${effortTag}`);
61+}
62+
63+async function handleModelSet(
64+ ctx: CommandContext,
65+ args: string,
66+): Promise<void> {
67+ const parts = args.trim().split(/\s+/).filter(Boolean);
68+ const idArg = parts[0] ?? "";
69+ const effortArg = parts[1];
70+ if (!idArg) return;
71+
72+ let modelId = idArg;
73+ if (!idArg.includes("/")) {
74+ const snapshot = await fetchAvailableModels();
75+ const match = findModelIdByAlias(
76+ idArg,
77+ snapshot.models.map((model) => model.id),
78+ );
79+ if (!match) {
80+ writeln(
81+ `${PREFIX.error} unknown model ${c.cyan(idArg)} ${c.dim("— run /models for the full list")}`,
82+ );
83+ return;
84+ }
85+ modelId = match;
86+ }
87+
88+ ctx.setModel(modelId);
89+ renderModelUpdatedMessage(ctx, modelId, effortArg);
90+}
91+
92+function handleModelEffort(ctx: CommandContext, effortArg: string): void {
93+ if (effortArg === "off") {
94+ ctx.setThinkingEffort(null);
95+ writeln(`${PREFIX.success} thinking effort disabled`);
96+ return;
97+ }
98+
99+ const effort = parseThinkingEffort(effortArg);
100+ if (!effort) {
101+ writeln(`${PREFIX.error} usage: /model effort <low|medium|high|xhigh|off>`);
102+ return;
103+ }
104+
105+ ctx.setThinkingEffort(effort);
106+ writeln(`${PREFIX.success} thinking effort → ${c.cyan(effort)}`);
107+}
108+
109+async function renderModelList(ctx: CommandContext): Promise<void> {
110+ ctx.startSpinner("fetching models");
111+ const snapshot = await fetchAvailableModels();
112+ ctx.stopSpinner();
113+
114+ if (snapshot.models.length === 0) {
115+ writeln(
116+ `${PREFIX.error} No models found. Check your API keys or Ollama connection.`,
117+ );
118+ writeln(
119+ c.dim(
120+ " Set OPENCODE_API_KEY for Zen, or start Ollama for local models.",
121+ ),
122+ );
123+ return;
124+ }
125+
126+ if (snapshot.stale) {
127+ const lastSync = snapshot.lastSyncAt
128+ ? new Date(snapshot.lastSyncAt).toLocaleString()
129+ : "never";
130+ const refreshTag = snapshot.refreshing ? " (refreshing in background)" : "";
131+ writeln(
132+ c.dim(` model metadata is stale (last sync: ${lastSync})${refreshTag}`),
133+ );
134+ }
135+
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+ );
176+}
177+
178+export async function handleModelCommand(
179+ ctx: CommandContext,
180+ args: string,
181+): Promise<void> {
182+ const parts = args.trim().split(/\s+/).filter(Boolean);
183+ if (parts.length === 0) {
184+ await renderModelList(ctx);
185+ return;
186+ }
187+
188+ if (parts[0] === "effort") {
189+ handleModelEffort(ctx, parts[1] ?? "");
190+ return;
191+ }
192+
193+ await handleModelSet(ctx, args);
194+}
src/cli/commands.ts+10−274
@@ -1,13 +1,17 @@
11 import * as c from "yoctocolors";
22 import { isAbortError } from "../agent/agent-helpers.ts";
3-import type { ThinkingEffort } from "../llm-api/providers.ts";
4-import { fetchAvailableModels } from "../llm-api/providers.ts";
53 import {
64 deleteMcpServer,
75 listMcpServers,
86 upsertMcpServer,
97 } from "../session/db/index.ts";
108 import { loadAgents } from "./agents.ts";
9+import {
10+ handleCacheCommand,
11+ handleContextCommand,
12+ handleReasoningCommand,
13+} from "./commands-config.ts";
14+import { handleModelCommand } from "./commands-model.ts";
1115 import {
1216 type CustomCommand,
1317 expandTemplate,
@@ -31,274 +35,6 @@ type CommandResult =
3135
3236 // ─── Command handlers ─────────────────────────────────────────────────────────
3337
34-async function handleModel(ctx: CommandContext, args: string): Promise<void> {
35- const parts = args.trim().split(/\s+/).filter(Boolean);
36-
37- if (parts.length > 0) {
38- if (parts[0] === "effort") {
39- const effortArg = parts[1] ?? "";
40- if (effortArg === "off") {
41- ctx.setThinkingEffort(null);
42- writeln(`${PREFIX.success} thinking effort disabled`);
43- } else if (["low", "medium", "high", "xhigh"].includes(effortArg)) {
44- ctx.setThinkingEffort(effortArg as ThinkingEffort);
45- writeln(`${PREFIX.success} thinking effort → ${c.cyan(effortArg)}`);
46- } else {
47- writeln(
48- `${PREFIX.error} usage: /model effort <low|medium|high|xhigh|off>`,
49- );
50- }
51- return;
52- }
53-
54- // Otherwise, it's a model switch
55- const idArg = parts[0] ?? "";
56- let modelId = idArg;
57- if (!idArg.includes("/")) {
58- const snapshot = await fetchAvailableModels();
59- const match = snapshot.models.find(
60- (m) => m.id.split("/").slice(1).join("/") === idArg || m.id === idArg,
61- );
62- if (match) {
63- modelId = match.id;
64- } else {
65- writeln(
66- `${PREFIX.error} unknown model ${c.cyan(idArg)} ${c.dim("— run /models for the full list")}`,
67- );
68- return;
69- }
70- }
71- ctx.setModel(modelId);
72-
73- const effortArg = parts[1];
74- if (effortArg) {
75- if (effortArg === "off") {
76- ctx.setThinkingEffort(null);
77- writeln(
78- `${PREFIX.success} model → ${c.cyan(modelId)} ${c.dim("(thinking disabled)")}`,
79- );
80- } else if (["low", "medium", "high", "xhigh"].includes(effortArg)) {
81- ctx.setThinkingEffort(effortArg as ThinkingEffort);
82- writeln(
83- `${PREFIX.success} model → ${c.cyan(modelId)} ${c.dim(`(✦ ${effortArg})`)}`,
84- );
85- } else {
86- writeln(`${PREFIX.success} model → ${c.cyan(modelId)}`);
87- writeln(
88- `${PREFIX.error} unknown effort level ${c.cyan(effortArg)} (use low, medium, high, xhigh, off)`,
89- );
90- }
91- } else {
92- const e = ctx.thinkingEffort ? c.dim(` (✦ ${ctx.thinkingEffort})`) : "";
93- writeln(`${PREFIX.success} model → ${c.cyan(modelId)}${e}`);
94- }
95- return;
96- }
97-
98- ctx.startSpinner("fetching models");
99-
100- const snapshot = await fetchAvailableModels();
101- const models = snapshot.models;
102-
103- ctx.stopSpinner();
104-
105- if (models.length === 0) {
106- writeln(
107- `${PREFIX.error} No models found. Check your API keys or Ollama connection.`,
108- );
109- writeln(
110- c.dim(
111- " Set OPENCODE_API_KEY for Zen, or start Ollama for local models.",
112- ),
113- );
114- return;
115- }
116-
117- if (snapshot.stale) {
118- const lastSync = snapshot.lastSyncAt
119- ? new Date(snapshot.lastSyncAt).toLocaleString()
120- : "never";
121- const refreshTag = snapshot.refreshing ? " (refreshing in background)" : "";
122- writeln(
123- c.dim(` model metadata is stale (last sync: ${lastSync})${refreshTag}`),
124- );
125- }
126-
127- // Group by provider
128- const byProvider = new Map<string, typeof models>();
129- for (const m of models) {
130- const existing = byProvider.get(m.provider);
131- if (existing) {
132- existing.push(m);
133- } else {
134- byProvider.set(m.provider, [m]);
135- }
136- }
137-
138- writeln();
139- for (const [provider, list] of byProvider) {
140- writeln(c.bold(` ${provider}`));
141- for (const m of list) {
142- const isCurrent = ctx.currentModel === m.id;
143- const freeTag = m.free ? c.green(" free") : "";
144- const ctxTag = m.context
145- ? c.dim(` ${Math.round(m.context / 1000)}k`)
146- : "";
147- const effortTag =
148- isCurrent && ctx.thinkingEffort
149- ? c.dim(` ✦ ${ctx.thinkingEffort}`)
150- : "";
151- const cur = isCurrent ? c.cyan(" ◀") : "";
152- writeln(
153- ` ${c.dim("·")} ${m.displayName}${freeTag}${ctxTag}${cur}${effortTag}`,
154- );
155- writeln(` ${c.dim(m.id)}`);
156- }
157- }
158-
159- writeln();
160- writeln(
161- c.dim(" /model <id> to switch · e.g. /model zen/claude-sonnet-4-6"),
162- );
163- writeln(
164- c.dim(
165- " /model effort <low|medium|high|xhigh|off> to set thinking effort",
166- ),
167- );
168-}
169-
170-function handleReasoning(ctx: CommandContext, args: string): void {
171- const mode = args.trim().toLowerCase();
172- if (!mode) {
173- ctx.setShowReasoning(!ctx.showReasoning);
174- writeln(
175- `${PREFIX.success} reasoning display ${ctx.showReasoning ? c.green("on") : c.dim("off")}`,
176- );
177- return;
178- }
179- if (mode === "on") {
180- ctx.setShowReasoning(true);
181- writeln(`${PREFIX.success} reasoning display ${c.green("on")}`);
182- return;
183- }
184- if (mode === "off") {
185- ctx.setShowReasoning(false);
186- writeln(`${PREFIX.success} reasoning display ${c.dim("off")}`);
187- return;
188- }
189- writeln(`${PREFIX.error} usage: /reasoning <on|off>`);
190-}
191-
192-function handleContext(ctx: CommandContext, args: string): void {
193- const [sub, value] = args.trim().split(/\s+/, 2);
194- if (!sub) {
195- const capText =
196- ctx.toolResultPayloadCapBytes <= 0
197- ? "off"
198- : `${Math.round(ctx.toolResultPayloadCapBytes / 1024)}KB (${ctx.toolResultPayloadCapBytes} bytes)`;
199- writeln(
200- `${PREFIX.info} pruning=${c.cyan(ctx.pruningMode)} tool-result-cap=${c.cyan(capText)}`,
201- );
202- writeln(c.dim(" usage: /context prune <off|balanced|aggressive>"));
203- writeln(c.dim(" /context cap <off|bytes|kb>"));
204- return;
205- }
206-
207- if (sub === "prune") {
208- if (value === "off" || value === "balanced" || value === "aggressive") {
209- ctx.setPruningMode(value);
210- writeln(`${PREFIX.success} context pruning → ${c.cyan(value)}`);
211- return;
212- }
213- writeln(`${PREFIX.error} usage: /context prune <off|balanced|aggressive>`);
214- return;
215- }
216-
217- if (sub === "cap") {
218- if (!value) {
219- writeln(`${PREFIX.error} usage: /context cap <off|bytes|kb>`);
220- return;
221- }
222- if (value === "off") {
223- ctx.setToolResultPayloadCapBytes(0);
224- writeln(`${PREFIX.success} tool-result payload cap disabled`);
225- return;
226- }
227- const capMatch = value.match(/^(\d+)(kb)?$/i);
228- if (!capMatch) {
229- writeln(`${PREFIX.error} invalid cap: ${c.cyan(value)}`);
230- return;
231- }
232- const base = Number.parseInt(capMatch[1] ?? "", 10);
233- const capBytes =
234- (capMatch[2] ?? "").toLowerCase() === "kb" ? base * 1024 : base;
235- if (!Number.isFinite(capBytes) || capBytes < 0) {
236- writeln(`${PREFIX.error} invalid cap: ${c.cyan(value)}`);
237- return;
238- }
239- ctx.setToolResultPayloadCapBytes(capBytes);
240- writeln(
241- `${PREFIX.success} tool-result payload cap → ${c.cyan(`${capBytes} bytes`)}`,
242- );
243- return;
244- }
245-
246- writeln(`${PREFIX.error} usage: /context <prune|cap> ...`);
247-}
248-function handleCache(ctx: CommandContext, args: string): void {
249- const [sub, value] = args.trim().split(/\s+/, 2);
250-
251- if (!sub) {
252- const gCache = ctx.googleCachedContent
253- ? c.cyan(ctx.googleCachedContent)
254- : "off";
255- writeln(
256- `${PREFIX.info} prompt-caching=${ctx.promptCachingEnabled ? c.green("on") : c.dim("off")} openai-retention=${c.cyan(ctx.openaiPromptCacheRetention)} gemini-cache=${gCache}`,
257- );
258- writeln(c.dim(" usage: /cache <on|off>"));
259- writeln(c.dim(" /cache openai <in_memory|24h>"));
260- writeln(c.dim(" /cache gemini <off|cachedContents/...>"));
261- return;
262- }
263-
264- if (sub === "on" || sub === "off") {
265- ctx.setPromptCachingEnabled(sub === "on");
266- writeln(
267- `${PREFIX.success} prompt caching → ${sub === "on" ? c.green("on") : c.dim("off")}`,
268- );
269- return;
270- }
271-
272- if (sub === "openai") {
273- if (value === "in_memory" || value === "24h") {
274- ctx.setOpenAIPromptCacheRetention(value);
275- writeln(
276- `${PREFIX.success} openai prompt cache retention → ${c.cyan(value)}`,
277- );
278- return;
279- }
280- writeln(`${PREFIX.error} usage: /cache openai <in_memory|24h>`);
281- return;
282- }
283-
284- if (sub === "gemini") {
285- if (!value) {
286- writeln(`${PREFIX.error} usage: /cache gemini <off|cachedContents/...>`);
287- return;
288- }
289- if (value === "off") {
290- ctx.setGoogleCachedContent(null);
291- writeln(`${PREFIX.success} gemini cached content → ${c.dim("off")}`);
292- return;
293- }
294- ctx.setGoogleCachedContent(value);
295- writeln(`${PREFIX.success} gemini cached content → ${c.cyan(value)}`);
296- return;
297- }
298-
299- writeln(`${PREFIX.error} usage: /cache <on|off|openai|gemini> ...`);
300-}
301-
30238 async function handleUndo(ctx: CommandContext): Promise<void> {
30339 ctx.startSpinner("restoring snapshot");
30440 try {
@@ -660,7 +396,7 @@ export async function handleCommand(
660396 switch (command.toLowerCase()) {
661397 case "model":
662398 case "models":
663- await handleModel(ctx, args);
399+ await handleModelCommand(ctx, args);
664400 return { type: "handled" };
665401
666402 case "undo":
@@ -668,14 +404,14 @@ export async function handleCommand(
668404 return { type: "handled" };
669405
670406 case "reasoning":
671- handleReasoning(ctx, args);
407+ handleReasoningCommand(ctx, args);
672408 return { type: "handled" };
673409
674410 case "context":
675- handleContext(ctx, args);
411+ handleContextCommand(ctx, args);
676412 return { type: "handled" };
677413 case "cache":
678- handleCache(ctx, args);
414+ handleCacheCommand(ctx, args);
679415 return { type: "handled" };
680416
681417 case "agent":