From 6b379bc42363caac08884b71e53cdd6213e26557 Mon Sep 17 00:00:00 2001 From: AaronWander Date: Thu, 29 Jan 2026 09:31:10 +0800 Subject: [PATCH] TUI: fix /reasoning by supporting stream + normalization --- src/tui/commands.test.ts | 9 +++++++ src/tui/commands.ts | 4 +-- src/tui/tui-command-handlers.test.ts | 39 ++++++++++++++++++++++++++++ src/tui/tui-command-handlers.ts | 12 ++++++--- 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/tui/commands.test.ts b/src/tui/commands.test.ts index 43be20733..590406139 100644 --- a/src/tui/commands.test.ts +++ b/src/tui/commands.test.ts @@ -19,4 +19,13 @@ describe("tui slash commands", () => { expect(commands.some((command) => command.name === "context")).toBe(true); expect(commands.some((command) => command.name === "commands")).toBe(true); }); + + it("offers reasoning stream mode", () => { + const commands = getSlashCommands({}); + const reasoning = commands.find((command) => command.name === "reasoning"); + expect(reasoning).toBeTruthy(); + expect(reasoning?.getArgumentCompletions?.("")).toEqual( + expect.arrayContaining([{ value: "stream", label: "stream" }]), + ); + }); }); diff --git a/src/tui/commands.ts b/src/tui/commands.ts index dfc419632..9de7c5beb 100644 --- a/src/tui/commands.ts +++ b/src/tui/commands.ts @@ -4,7 +4,7 @@ import { formatThinkingLevels, listThinkingLevelLabels } from "../auto-reply/thi import type { MoltbotConfig } from "../config/types.js"; const VERBOSE_LEVELS = ["on", "off"]; -const REASONING_LEVELS = ["on", "off"]; +const REASONING_LEVELS = ["on", "off", "stream"]; const ELEVATED_LEVELS = ["on", "off", "ask", "full"]; const ACTIVATION_LEVELS = ["mention", "always"]; const USAGE_FOOTER_LEVELS = ["off", "tokens", "full"]; @@ -68,7 +68,7 @@ export function getSlashCommands(options: SlashCommandOptions = {}): SlashComman }, { name: "reasoning", - description: "Set reasoning on/off", + description: "Set reasoning visibility", getArgumentCompletions: (prefix) => REASONING_LEVELS.filter((v) => v.startsWith(prefix.toLowerCase())).map((value) => ({ value, diff --git a/src/tui/tui-command-handlers.test.ts b/src/tui/tui-command-handlers.test.ts index fc2ac4fa6..f624b42c0 100644 --- a/src/tui/tui-command-handlers.test.ts +++ b/src/tui/tui-command-handlers.test.ts @@ -44,4 +44,43 @@ describe("tui command handlers", () => { ); expect(requestRender).toHaveBeenCalled(); }); + + it("normalizes /reasoning streaming to stream", async () => { + const patchSession = vi.fn().mockResolvedValue(undefined); + const addUser = vi.fn(); + const addSystem = vi.fn(); + const requestRender = vi.fn(); + const refreshSessionInfo = vi.fn().mockResolvedValue(undefined); + + const { handleCommand } = createCommandHandlers({ + client: { patchSession } as never, + chatLog: { addUser, addSystem } as never, + tui: { requestRender } as never, + opts: {}, + state: { + currentSessionKey: "agent:main:main", + activeChatRunId: null, + sessionInfo: {}, + } as never, + deliverDefault: false, + openOverlay: vi.fn(), + closeOverlay: vi.fn(), + refreshSessionInfo, + loadHistory: vi.fn(), + setSession: vi.fn(), + refreshAgents: vi.fn(), + abortActive: vi.fn(), + setActivityStatus: vi.fn(), + formatSessionKey: vi.fn(), + }); + + await handleCommand("/reasoning streaming"); + + expect(patchSession).toHaveBeenCalledWith({ + key: "agent:main:main", + reasoningLevel: "stream", + }); + expect(addSystem).toHaveBeenCalledWith("reasoning set to stream"); + expect(refreshSessionInfo).toHaveBeenCalled(); + }); }); diff --git a/src/tui/tui-command-handlers.ts b/src/tui/tui-command-handlers.ts index a14172809..70b78107a 100644 --- a/src/tui/tui-command-handlers.ts +++ b/src/tui/tui-command-handlers.ts @@ -1,6 +1,7 @@ import type { Component, TUI } from "@mariozechner/pi-tui"; import { formatThinkingLevels, + normalizeReasoningLevel, normalizeUsageDisplay, resolveResponseUsageMode, } from "../auto-reply/thinking.js"; @@ -333,15 +334,20 @@ export function createCommandHandlers(context: CommandHandlerContext) { break; case "reasoning": if (!args) { - chatLog.addSystem("usage: /reasoning "); + chatLog.addSystem("usage: /reasoning "); break; } try { + const normalized = normalizeReasoningLevel(args); + if (!normalized) { + chatLog.addSystem("usage: /reasoning "); + break; + } await client.patchSession({ key: state.currentSessionKey, - reasoningLevel: args, + reasoningLevel: normalized, }); - chatLog.addSystem(`reasoning set to ${args}`); + chatLog.addSystem(`reasoning set to ${normalized}`); await refreshSessionInfo(); } catch (err) { chatLog.addSystem(`reasoning failed: ${String(err)}`);