xonecas.io
64875
Mc

mini-coder / commit f18e758

feat: add /logout, /new, /fork, /undo, /reasoning, /verbose commands

Simple commands:
- /new: create session, clear messages/stats, guard running state
- /fork: forkSession, reload, info message, guard running state
- /undo: interrupt if running, undoLastTurn, reload messages/stats
- /reasoning: toggle showReasoning
- /verbose: toggle verbose
- /logout: Select of logged-in OAuth providers, clear creds + provider

Info messages refactored: separate infoMessages array (display-only),
not in state.messages, never sent to LLM. Cleared on session switch.

Update AGENTS.md: new lessons learned (Escape dispatch, apiKey
passthrough, display-only state), testing coverage notes.

10 of 11 spec commands implemented. /help and Tab autocomplete remain.

xonecas2026-04-05 f18e75831865fcec64accab64acf3328920b34ad parent 950f172

3 files changed

AGENTS.md+5−1
@@ -46,6 +46,9 @@
4646 - **Respect the phased plan.** Each TODO.md phase has explicit scope. Do not implement features from later phases — even if they feel "easy" or "related." Scope creep wastes review time, introduces bugs from untested code paths, and erodes trust. If something isn't listed in the current phase, it doesn't exist yet.
4747 - **Understand callback return semantics.** In cel-tui's `onKeyPress`, returning `false` means "prevent the default action" — returning it unconditionally blocks all typing. Only return `false` for keys you explicitly intercept. Let all other keys fall through with no return.
4848 - **Use the dependency's types, not weaker ones.** If a dependency defines a specific type (e.g., cel-tui's `Color`), use it in your own interfaces. Don't weaken to `string` and then cast with `as any` everywhere — that defeats type safety and creates lint noise.
49+- **Read the framework's key dispatch code.** cel-tui intercepts Escape at the framework level (unfocuses before `onKeyPress` fires). Use `onBlur` for dismiss-on-Escape instead of `onKeyPress`. Don't assume events reach component handlers without checking the framework's dispatch order.
50+- **Pass all required options through the call chain.** pi-ai's `streamSimple` needs `apiKey` in options for OAuth providers (env vars aren't set). When adding a new field to a dependency's options, trace the full call path from UI → agent loop → provider to ensure it arrives.
51+- **Display-only state must not leak into model context.** Info messages (login progress, fork confirmation) belong in a separate display array, not `state.messages`. Anything in `state.messages` gets sent to the LLM as conversation history.
4952
5053 ## Testing strategy
5154
@@ -68,6 +71,7 @@ We test our logic at the boundaries. Never test dependencies (pi-ai, cel-tui, bu
6871 - Turn numbering: user message gets MAX+1, subsequent messages share the turn.
6972 - Undo: deletes correct turn, leaves others intact.
7073 - Fork: copies all messages, new session id, preserves turn order.
74+- Truncation: keeps most recent N sessions per CWD, cascades to messages.
7175 - Cumulative stats computation from message history.
7276
7377 **System prompt construction** (`prompt.ts`):
@@ -98,5 +102,5 @@ We test our logic at the boundaries. Never test dependencies (pi-ai, cel-tui, bu
98102
99103 **Theme** (`theme.ts`):
100104
101-- Default theme has all required keys (9 terminal palette colors).
105+- Default theme has all required keys (10 themed colors including `overlayBg`).
102106 - `mergeThemes` applies partial overrides left-to-right without mutating the base.
TODO.md+13−7
@@ -111,12 +111,13 @@
111111 - [x] Session truncation — keep max 20 per CWD, runs on init
112112 - [x] Fix: pass `apiKey` from `state.providers` through `RunAgentOpts` to `streamSimple` (OAuth providers failed without this)
113113 - [x] Fix: pass `effort` (reasoning level) to `streamSimple` (was silently ignored)
114-- [ ] `/logout` — OAuth logout (clear saved credentials)
115-- [ ] `/new` — new session, reset counters
116-- [ ] `/fork` — fork current session
117-- [ ] `/undo` — remove last turn
118-- [ ] `/reasoning` — toggle thinking display
119-- [ ] `/verbose` — toggle full output (disable truncation)
114+- [x] `/logout` — OAuth logout (Select of logged-in providers, clear creds, nullify model if needed)
115+- [x] `/new` — new session, reset messages/stats
116+- [x] `/fork` — fork current session, info message
117+- [x] `/undo` — interrupt if running, then remove last turn
118+- [x] `/reasoning` — toggle `showReasoning`
119+- [x] `/verbose` — toggle `verbose`
120+- [x] Info messages separated from `state.messages` — display-only `infoMessages` array, not sent to LLM, cleared on session switch
120121 - [ ] `/help` — list commands, AGENTS.md files, skills, plugins
121122 - [ ] `/` + Tab — command autocomplete in input
122123
@@ -129,10 +130,15 @@
129130 - `/session` lists sessions via `listSessions(db, cwd)`, labels show relative timestamp (`formatSessionDate`) + model + `(current)` marker. Resume swaps `state.session`, reloads messages and stats.
130131 - `truncateSessions(db, cwd, keep)` in `session.ts` — deletes oldest beyond limit per CWD. `listSessions` SQL uses `rowid DESC` tiebreaker for deterministic ordering.
131132 - `/login` shows OAuth providers from `getOAuthProviders()` with login status. `performLogin()` calls `provider.login()` with `onAuth` (opens browser via `xdg-open`/`open`), `onProgress` (status in log). `onPrompt` rejects (no manual code input). On success: persists creds, registers API key in `state.providers`, auto-selects model if none.
133+- `/logout` filters `getOAuthProviders()` to those with saved creds. On select: deletes creds, removes from `state.providers`, clears model if it belonged to the provider.
134+- `/new` creates session via `createSession`, clears messages/stats/infoMessages. Guards against running state.
135+- `/fork` calls `forkSession`, reloads messages/stats, shows info message. Guards against running state.
136+- `/undo` aborts agent if running, then `undoLastTurn`, reloads messages/stats.
137+- `/reasoning` and `/verbose` toggle their respective `AppState` booleans and re-render.
132138 - `apiKey` added to `RunAgentOpts` and passed to `streamSimple` — required for OAuth providers (env vars not set). `effort` also passed as `reasoning` option.
133139 - `handleInput()` routes through `parseInput()` → `handleCommand()` for commands, `submitMessage()` for text. Skill and image cases are stubs for Phase 4d.
134140 - `Theme` gained `overlayBg: Color` (default `"color08"`).
135-- `appendInfoMessage()` helper for system status messages in the log (login progress, etc.).
141+- `appendInfoMessage()` helper for display-only status messages. Uses separate `infoMessages` array (not `state.messages`) so info text is never sent to the LLM. Cleared on `/new`, `/session` resume, `/fork`.
136142 - 162 tests across 9 files (session: 24, tools: 36, git: 10, skills: 14, prompt: 21, agent: 12, plugins: 10, input: 30, theme: 5).
137143
138144 ### Spec review findings (Phase 4c checkpoint)
src/ui.ts+141−2
@@ -47,8 +47,11 @@ import { parseInput } from "./input.ts";
4747 import {
4848 appendMessage,
4949 computeStats,
50+ createSession,
51+ forkSession,
5052 listSessions,
5153 loadMessages,
54+ undoLastTurn,
5255 } from "./session.ts";
5356 import { truncateOutput } from "./tools.ts";
5457
@@ -116,6 +119,9 @@ interface PendingToolCall {
116119 /** Tool calls collected during the current streaming turn. */
117120 let pendingToolCalls: PendingToolCall[] = [];
118121
122+/** Display-only info messages (not persisted, not sent to LLM). */
123+let infoMessages: Message[] = [];
124+
119125 // ---------------------------------------------------------------------------
120126 // Overlay state
121127 // ---------------------------------------------------------------------------
@@ -547,6 +553,18 @@ function buildConversationLog(state: AppState): Node[] {
547553 nodes.push(...renderStreamingResponse(state));
548554 }
549555
556+ // Append display-only info messages
557+ for (const msg of infoMessages) {
558+ nodes.push(
559+ VStack({ padding: { x: 1 } }, [
560+ Text(typeof msg.content === "string" ? msg.content : "", {
561+ fgColor: "color08",
562+ italic: true,
563+ }),
564+ ]),
565+ );
566+ }
567+
550568 // Empty state
551569 if (nodes.length === 0) {
552570 nodes.push(Spacer());
@@ -717,6 +735,7 @@ function handleSessionCommand(state: AppState): void {
717735 state.session = picked;
718736 state.messages = loadMessages(state.db, picked.id);
719737 state.stats = computeStats(state.messages);
738+ infoMessages = [];
720739 stickToBottom = true;
721740 }
722741 }
@@ -757,17 +776,73 @@ function openInBrowser(url: string): void {
757776 * Used for login progress/status messages that aren't part of the
758777 * agent conversation. Rendered as dimmed italic text.
759778 */
760-function appendInfoMessage(text: string, state: AppState): void {
779+function appendInfoMessage(text: string, _state: AppState): void {
761780 const msg: Message = {
762781 role: "user",
763782 content: `[${text}]`,
764783 timestamp: Date.now(),
765784 };
766- state.messages.push(msg);
785+ infoMessages.push(msg);
786+ stickToBottom = true;
787+ cel.render();
788+}
789+
790+/** Handle the /new command: start a new session. */
791+function handleNewCommand(state: AppState): void {
792+ if (state.running) return;
793+ const modelLabel = state.model
794+ ? `${state.model.provider}/${state.model.id}`
795+ : undefined;
796+ state.session = createSession(state.db, {
797+ cwd: state.cwd,
798+ model: modelLabel,
799+ effort: state.effort,
800+ });
801+ state.messages = [];
802+ state.stats = { totalInput: 0, totalOutput: 0, totalCost: 0 };
803+ infoMessages = [];
767804 stickToBottom = true;
768805 cel.render();
769806 }
770807
808+/** Handle the /fork command: fork the current session. */
809+function handleForkCommand(state: AppState): void {
810+ if (state.running) return;
811+ const forked = forkSession(state.db, state.session.id);
812+ state.session = forked;
813+ state.messages = loadMessages(state.db, forked.id);
814+ state.stats = computeStats(state.messages);
815+ infoMessages = [];
816+ appendInfoMessage(`Forked session.`, state);
817+}
818+
819+/** Handle the /undo command: remove the last turn. */
820+function handleUndoCommand(state: AppState): void {
821+ // Interrupt first if the agent is running
822+ if (state.running && state.abortController) {
823+ state.abortController.abort();
824+ }
825+ const removed = undoLastTurn(state.db, state.session.id);
826+ if (removed) {
827+ state.messages = loadMessages(state.db, state.session.id);
828+ state.stats = computeStats(state.messages);
829+ stickToBottom = true;
830+ cel.render();
831+ }
832+}
833+
834+/** Handle the /reasoning command: toggle thinking display. */
835+function handleReasoningCommand(state: AppState): void {
836+ state.showReasoning = !state.showReasoning;
837+ cel.render();
838+}
839+
840+/** Handle the /verbose command: toggle full output display. */
841+function handleVerboseCommand(state: AppState): void {
842+ state.verbose = !state.verbose;
843+ cel.render();
844+}
845+
771846 /** Handle the /login command: OAuth provider login. */
772847 function handleLoginCommand(state: AppState): void {
773848 const oauthProviders = getOAuthProviders();
@@ -853,6 +928,52 @@ async function performLogin(
853928 appendInfoMessage(`Logged in to ${provider.name}.`, state);
854929 }
855930
931+/** Handle the /logout command: clear OAuth credentials for a provider. */
932+function handleLogoutCommand(state: AppState): void {
933+ const loggedInProviders = getOAuthProviders().filter(
934+ (p) => state.oauthCredentials[p.id] != null,
935+ );
936+ if (loggedInProviders.length === 0) {
937+ return;
938+ }
939+
940+ const items = loggedInProviders.map((p) => ({
941+ label: p.name,
942+ value: p.id,
943+ filterText: p.name,
944+ }));
945+
946+ const select = Select({
947+ items,
948+ maxVisible: OVERLAY_MAX_VISIBLE,
949+ placeholder: "type to filter providers...",
950+ focused: true,
951+ highlightColor: "color06",
952+ onSelect: (providerId) => {
953+ delete state.oauthCredentials[providerId];
954+ saveOAuthCredentials(state.oauthCredentials);
955+ state.providers.delete(providerId);
956+
957+ // Clear model if it belonged to the logged-out provider
958+ if (state.model && state.model.provider === providerId) {
959+ state.model = null;
960+ }
961+
962+ const provider = loggedInProviders.find((p) => p.id === providerId);
963+ dismissOverlay();
964+ appendInfoMessage(
965+ `Logged out of ${provider?.name ?? providerId}.`,
966+ state,
967+ );
968+ },
969+ onBlur: dismissOverlay,
970+ });
971+
972+ inputFocused = false;
973+ activeOverlay = { select, title: "Logout from a provider" };
974+ cel.render();
975+}
976+
856977 /** Dispatch a parsed command. Returns true if handled. */
857978 function handleCommand(command: string, state: AppState): boolean {
858979 switch (command) {
@@ -868,6 +989,24 @@ function handleCommand(command: string, state: AppState): boolean {
868989 case "login":
869990 handleLoginCommand(state);
870991 return true;
992+ case "logout":
993+ handleLogoutCommand(state);
994+ return true;
995+ case "new":
996+ handleNewCommand(state);
997+ return true;
998+ case "fork":
999+ handleForkCommand(state);
1000+ return true;
1001+ case "undo":
1002+ handleUndoCommand(state);
1003+ return true;
1004+ case "reasoning":
1005+ handleReasoningCommand(state);
1006+ return true;
1007+ case "verbose":
1008+ handleVerboseCommand(state);
1009+ return true;
8711010 default:
8721011 return false;
8731012 }