xonecas.io
64875
Mc

mini-coder / commit c77df13

feat: add /model and /effort commands with overlay Select

- Wire parseInput() into the Enter handler to route commands vs text
- Add overlay layer system using cel-tui's multi-layer viewport
- /model: interactive model selector from authenticated providers
- /effort: interactive effort level selector (low/med/high/xhigh)
- Overlay renders centered with horizontal padding, fixed height
- Escape dismisses via onBlur (cel-tui intercepts Escape at framework level)
- Add getAvailableModels() helper in index.ts
- Add overlayBg theme color
- Note user preference persistence as future idea in TODO.md

xonecas2026-04-05 c77df1357b2dc5561d229bde632f46df01454958 parent 9a21a6e

4 files changed

TODO.md+1−0
@@ -124,6 +124,7 @@
124124
125125 ## Future ideas
126126
127+- [ ] User preferences persistence (model, effort) — not in spec, currently resets to defaults on launch
127128 - [ ] Divider theme plugin — customizable divider animations. Candidates designed during Phase 4 UI exploration:
128129 - **Scanning pulse** (current default): bright segment sweeps across the dimmed divider
129130 - **Breathing**: divider alternates between two dim levels, subtle pulse
src/index.ts+17−0
@@ -403,6 +403,23 @@ export function buildToolList(state: AppState): {
403403 return buildTools(state.model, state.plugins);
404404 }
405405
406+/**
407+ * Get all models from authenticated providers.
408+ *
409+ * Returns a flat list of models from providers the user has credentials
410+ * for, suitable for the `/model` selector.
411+ */
412+export function getAvailableModels(state: AppState): Model<string>[] {
413+ const result: Model<string>[] = [];
414+ for (const provider of state.providers.keys()) {
415+ const models = getModels(provider as KnownProvider);
416+ for (const model of models) {
417+ result.push(model);
418+ }
419+ }
420+ return result;
421+}
422+
406423 /** Clean up resources on shutdown. */
407424 export async function shutdown(state: AppState): Promise<void> {
408425 await destroyPlugins(state.plugins, (entry, err) => {
src/theme.ts+3−0
@@ -41,6 +41,8 @@ export interface Theme {
4141 statusText: Color;
4242 /** Error text. */
4343 error: Color;
44+ /** Overlay modal background. */
45+ overlayBg: Color;
4446 }
4547
4648 // ---------------------------------------------------------------------------
@@ -63,6 +65,7 @@ export const DEFAULT_THEME: Theme = {
6365 dividerPulse: "color07",
6466 statusText: "color07",
6567 error: "color01",
68+ overlayBg: "color08",
6669 };
6770
6871 // ---------------------------------------------------------------------------
src/ui.ts+190−6
@@ -9,7 +9,8 @@
99 */
1010
1111 import { homedir } from "node:os";
12-import { Divider, Markdown, Spacer } from "@cel-tui/components";
12+import type { SelectInstance } from "@cel-tui/components";
13+import { Divider, Markdown, Select, Spacer } from "@cel-tui/components";
1314 import {
1415 cel,
1516 HStack,
@@ -24,6 +25,7 @@ import type {
2425 Message,
2526 TextContent,
2627 ThinkingContent,
28+ ThinkingLevel,
2729 ToolCall,
2830 } from "@mariozechner/pi-ai";
2931 import { structuredPatch } from "diff";
@@ -31,7 +33,13 @@ import type { AgentEvent } from "./agent.ts";
3133 import { runAgentLoop } from "./agent.ts";
3234 import { getGitState } from "./git.ts";
3335 import type { AppState } from "./index.ts";
34-import { buildPrompt, buildToolList, shutdown } from "./index.ts";
36+import {
37+ buildPrompt,
38+ buildToolList,
39+ getAvailableModels,
40+ shutdown,
41+} from "./index.ts";
42+import { parseInput } from "./input.ts";
3543 import { appendMessage, computeStats } from "./session.ts";
3644 import { truncateOutput } from "./tools.ts";
3745
@@ -99,6 +107,24 @@ interface PendingToolCall {
99107 /** Tool calls collected during the current streaming turn. */
100108 let pendingToolCalls: PendingToolCall[] = [];
101109
110+// ---------------------------------------------------------------------------
111+// Overlay state
112+// ---------------------------------------------------------------------------
113+
114+/** Max visible items in the overlay Select. */
115+const OVERLAY_MAX_VISIBLE = 15;
116+
117+/** Horizontal padding around the overlay modal. */
118+const OVERLAY_PADDING_X = 4;
119+
120+/** Active overlay for interactive commands (/model, /effort, etc.). */
121+let activeOverlay: {
122+ /** The Select component instance. */
123+ select: SelectInstance;
124+ /** Title displayed above the Select. */
125+ title: string;
126+} | null = null;
127+
102128 // ---------------------------------------------------------------------------
103129 // Divider animation
104130 // ---------------------------------------------------------------------------
@@ -531,10 +557,164 @@ function buildConversationLog(state: AppState): Node[] {
531557 return nodes;
532558 }
533559
560+// ---------------------------------------------------------------------------
561+// Overlay rendering
562+// ---------------------------------------------------------------------------
563+
564+/** Dismiss the active overlay and return focus to the input. */
565+function dismissOverlay(): void {
566+ activeOverlay = null;
567+ inputFocused = true;
568+ cel.render();
569+}
570+
571+/** Render the overlay layer (transparent background, centered modal). */
572+function renderOverlay(state: AppState): Node {
573+ // Fixed height: 1 (title) + 1 (search) + maxVisible items + 1 (overflow)
574+ const modalHeight = OVERLAY_MAX_VISIBLE + 3;
575+
576+ return VStack(
577+ {
578+ height: "100%",
579+ justifyContent: "center",
580+ padding: { x: OVERLAY_PADDING_X },
581+ },
582+ [
583+ VStack(
584+ {
585+ height: modalHeight,
586+ bgColor: state.theme.overlayBg,
587+ padding: { x: 1 },
588+ },
589+ [
590+ Text(activeOverlay!.title, { bold: true, fgColor: "color06" }),
591+ activeOverlay!.select(),
592+ ],
593+ ),
594+ ],
595+ );
596+}
597+
598+// ---------------------------------------------------------------------------
599+// Command handlers
600+// ---------------------------------------------------------------------------
601+
602+/** Handle the /model command: show interactive model selector. */
603+function handleModelCommand(state: AppState): void {
604+ const models = getAvailableModels(state);
605+ if (models.length === 0) {
606+ // No providers — nothing to show
607+ return;
608+ }
609+
610+ const currentValue = state.model
611+ ? `${state.model.provider}/${state.model.id}`
612+ : null;
613+
614+ const items = models.map((m) => {
615+ const value = `${m.provider}/${m.id}`;
616+ const current = value === currentValue ? " (current)" : "";
617+ return {
618+ label: `${m.provider}/${m.id}${current}`,
619+ value,
620+ filterText: `${m.provider} ${m.id}`,
621+ };
622+ });
623+
624+ const select = Select({
625+ items,
626+ maxVisible: OVERLAY_MAX_VISIBLE,
627+ placeholder: "type to filter models...",
628+ focused: true,
629+ highlightColor: "color06",
630+ onSelect: (value) => {
631+ const picked = models.find((m) => `${m.provider}/${m.id}` === value);
632+ if (picked) {
633+ state.model = picked;
634+ }
635+ dismissOverlay();
636+ },
637+ onBlur: dismissOverlay,
638+ });
639+
640+ inputFocused = false;
641+ activeOverlay = { select, title: "Select a model" };
642+ cel.render();
643+}
644+
645+/** Effort levels available for selection. */
646+const EFFORT_LEVELS: { label: string; value: ThinkingLevel }[] = [
647+ { label: "low", value: "low" },
648+ { label: "medium", value: "medium" },
649+ { label: "high", value: "high" },
650+ { label: "xhigh", value: "xhigh" },
651+];
652+
653+/** Handle the /effort command: show effort level selector. */
654+function handleEffortCommand(state: AppState): void {
655+ const items = EFFORT_LEVELS.map((e) => ({
656+ label: e.value === state.effort ? `${e.label} (current)` : e.label,
657+ value: e.value,
658+ filterText: e.label,
659+ }));
660+
661+ const select = Select({
662+ items,
663+ maxVisible: OVERLAY_MAX_VISIBLE,
664+ placeholder: "type to filter...",
665+ focused: true,
666+ highlightColor: "color06",
667+ onSelect: (value) => {
668+ state.effort = value as ThinkingLevel;
669+ dismissOverlay();
670+ },
671+ onBlur: dismissOverlay,
672+ });
673+
674+ inputFocused = false;
675+ activeOverlay = { select, title: "Select effort level" };
676+ cel.render();
677+}
678+
679+/** Dispatch a parsed command. Returns true if handled. */
680+function handleCommand(command: string, state: AppState): boolean {
681+ switch (command) {
682+ case "model":
683+ handleModelCommand(state);
684+ return true;
685+ case "effort":
686+ handleEffortCommand(state);
687+ return true;
688+ default:
689+ return false;
690+ }
691+}
692+
534693 // ---------------------------------------------------------------------------
535694 // Agent loop wiring
536695 // ---------------------------------------------------------------------------
537696
697+/** Route raw user input through parseInput and dispatch accordingly. */
698+function handleInput(raw: string, state: AppState): void {
699+ const parsed = parseInput(raw);
700+
701+ switch (parsed.type) {
702+ case "command":
703+ if (!handleCommand(parsed.command, state)) {
704+ // Unimplemented command — ignore for now
705+ }
706+ break;
707+ case "text":
708+ if (parsed.text) {
709+ submitMessage(parsed.text, state).catch((err) => {
710+ console.error("Submit error:", err);
711+ });
712+ }
713+ break;
714+ // skill and image handling will be added in Phase 4d
715+ }
716+}
717+
538718 /** Send a plain text message and run the agent loop. */
539719 async function submitMessage(text: string, state: AppState): Promise<void> {
540720 if (!text.trim() || !state.model || state.running) return;
@@ -688,7 +868,7 @@ export function startUI(state: AppState): void {
688868 cel.viewport(() => {
689869 const cols = terminal.columns;
690870
691- return VStack(
871+ const base = VStack(
692872 {
693873 height: "100%",
694874 onKeyPress: (key) => {
@@ -749,11 +929,10 @@ export function startUI(state: AppState): void {
749929 },
750930 onKeyPress: (key) => {
751931 if (key === "enter") {
752- submitMessage(inputValue, state).catch((err) => {
753- console.error("Submit error:", err);
754- });
932+ const raw = inputValue;
755933 inputValue = "";
756934 cel.render();
935+ handleInput(raw, state);
757936 return false;
758937 }
759938 },
@@ -785,5 +964,10 @@ export function startUI(state: AppState): void {
785964 ),
786965 ],
787966 );
967+
968+ if (activeOverlay) {
969+ return [base, renderOverlay(state)];
970+ }
971+ return base;
788972 });
789973 }