Skip to content

Commit 6f1950e

Browse files
steipetePeter Steinberger
andauthored
fix(tui): expose supported verbose and reasoning levels (#113782)
Co-authored-by: Peter Steinberger <[email protected]>
1 parent a1d666f commit 6f1950e

5 files changed

Lines changed: 110 additions & 11 deletions

File tree

‎src/tui/commands.test.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Verifies TUI command definitions and parser metadata.
22
import { beforeAll, describe, expect, it } from "vitest";
3-
import { getSlashCommands, helpText, parseCommand } from "./commands.js";
3+
import {
4+
getSlashCommands,
5+
helpText,
6+
parseCommand,
7+
shouldSubmitExactArgumentCompletion,
8+
} from "./commands.js";
49

510
describe("parseCommand", () => {
611
it("normalizes aliases and keeps command args", () => {
@@ -51,6 +56,21 @@ describe("getSlashCommands", () => {
5156
]);
5257
});
5358

59+
it.each([
60+
{ commandName: "verbose", level: "full", description: "Set verbose on/off/full" },
61+
{ commandName: "reasoning", level: "stream", description: "Set reasoning on/off/stream" },
62+
])(
63+
"exposes and submits the canonical /$commandName $level completion",
64+
({ commandName, level, description }) => {
65+
const commands = getSlashCommands();
66+
const command = commands.find((candidate) => candidate.name === commandName);
67+
68+
expect(command?.description).toBe(description);
69+
expect(command?.getArgumentCompletions?.(level)).toEqual([{ value: level, label: level }]);
70+
expect(shouldSubmitExactArgumentCompletion(`/${commandName} ${level}`, commands)).toBe(true);
71+
},
72+
);
73+
5474
it("keeps session status on the shared command path and exposes gateway status separately", () => {
5575
const commands = getSlashCommands();
5676
const status = commands.find((command) => command.name === "status");
@@ -158,6 +178,13 @@ describe("getSlashCommands", () => {
158178
});
159179

160180
describe("helpText", () => {
181+
it.each(["/verbose <on|off|full>", "/reasoning <on|off|stream>"])(
182+
"includes the full canonical directive levels for %s",
183+
(usage) => {
184+
expect(helpText()).toContain(usage);
185+
},
186+
);
187+
161188
it("includes slash command help for aliases", () => {
162189
const output = helpText();
163190
expect(output).toContain("/elevated <on|off|ask|full>");

‎src/tui/commands.ts‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ import {
77
listChatCommandsForConfig,
88
resolveTextCommand,
99
} from "../auto-reply/commands-registry.js";
10-
import { formatThinkingLevels, listThinkingLevelLabels } from "../auto-reply/thinking.js";
10+
import {
11+
formatThinkingLevels,
12+
listThinkingLevelLabels,
13+
type ReasoningLevel,
14+
type VerboseLevel,
15+
} from "../auto-reply/thinking.js";
1116
import type { OpenClawConfig } from "../config/types.js";
1217

13-
const VERBOSE_LEVELS = ["on", "off"];
18+
const VERBOSE_LEVELS = ["on", "off", "full"] satisfies VerboseLevel[];
1419
const TRACE_LEVELS = ["on", "off"];
1520
const FAST_LEVELS = ["status", "auto", "on", "off"];
16-
const REASONING_LEVELS = ["on", "off"];
21+
const REASONING_LEVELS = ["on", "off", "stream"] satisfies ReasoningLevel[];
1722
const ELEVATED_LEVELS = ["on", "off", "ask", "full"];
1823
const ACTIVATION_LEVELS = ["mention", "always"];
1924
const USAGE_FOOTER_LEVELS = ["off", "tokens", "full", "reset", "inherit", "clear", "default"];
@@ -55,6 +60,12 @@ function createLevelCompletion(
5560
}));
5661
}
5762

63+
/** Keep TUI help and no-argument usage aligned with actual directive completions. */
64+
export function formatTuiLevelCommandUsage(command: "verbose" | "reasoning"): string {
65+
const levels = command === "verbose" ? VERBOSE_LEVELS : REASONING_LEVELS;
66+
return `/${command} <${levels.join("|")}>`;
67+
}
68+
5869
function normalizeSlashCommandName(value: string): string {
5970
return value.replace(/^\//, "").trim();
6071
}
@@ -139,7 +150,7 @@ export function getSlashCommands(options: SlashCommandOptions = {}): SlashComman
139150
},
140151
{
141152
name: "verbose",
142-
description: "Set verbose on/off",
153+
description: `Set verbose ${VERBOSE_LEVELS.join("/")}`,
143154
getArgumentCompletions: verboseCompletions,
144155
},
145156
{
@@ -149,7 +160,7 @@ export function getSlashCommands(options: SlashCommandOptions = {}): SlashComman
149160
},
150161
{
151162
name: "reasoning",
152-
description: "Set reasoning on/off",
163+
description: `Set reasoning ${REASONING_LEVELS.join("/")}`,
153164
getArgumentCompletions: reasoningCompletions,
154165
},
155166
{
@@ -249,9 +260,9 @@ export function helpText(options: SlashCommandOptions = {}): string {
249260
"/model <provider/model> (or /models)",
250261
`/think <${thinkLevels}>`,
251262
"/fast <status|auto|on|off>",
252-
"/verbose <on|off>",
263+
formatTuiLevelCommandUsage("verbose"),
253264
"/trace <on|off>",
254-
"/reasoning <on|off>",
265+
formatTuiLevelCommandUsage("reasoning"),
255266
"/usage <off|tokens|full|reset|inherit|clear|default>",
256267
"/elevated <on|off|ask|full>",
257268
"/elev <on|off|ask|full>",

‎src/tui/tui-command-handlers.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,18 @@ describe("tui command handlers", () => {
11611161
expect(openclaw.addSystem).toHaveBeenCalledWith(expect.stringContaining("ultra"));
11621162
});
11631163

1164+
it.each([
1165+
{ command: "verbose", usage: "usage: /verbose <on|off|full>" },
1166+
{ command: "reasoning", usage: "usage: /reasoning <on|off|stream>" },
1167+
])("shows the complete canonical no-argument /$command usage", async ({ command, usage }) => {
1168+
const { handleCommand, addSystem, patchSession } = createHarness();
1169+
1170+
await handleCommand(`/${command}`);
1171+
1172+
expect(addSystem).toHaveBeenCalledWith(usage);
1173+
expect(patchSession).not.toHaveBeenCalled();
1174+
});
1175+
11641176
it("hides tools locally for /verbose off without reloading history", async () => {
11651177
const patchResult = { entry: { verboseLevel: "off" } };
11661178
const patchSession = vi.fn().mockResolvedValue(patchResult);
@@ -1201,6 +1213,31 @@ describe("tui command handlers", () => {
12011213
expect(clearTools).not.toHaveBeenCalled();
12021214
});
12031215

1216+
it("reloads history for /verbose full so prior full tool output becomes visible", async () => {
1217+
const patchResult = { entry: { verboseLevel: "full" } };
1218+
const patchSession = vi.fn().mockResolvedValue(patchResult);
1219+
const applySessionInfoFromPatch = vi.fn();
1220+
const loadHistory = vi.fn().mockResolvedValue(undefined);
1221+
const refreshSessionInfo = vi.fn().mockResolvedValue(undefined);
1222+
const { handleCommand, clearTools } = createHarness({
1223+
patchSession,
1224+
applySessionInfoFromPatch,
1225+
loadHistory,
1226+
refreshSessionInfo,
1227+
});
1228+
1229+
await handleCommand("/verbose full");
1230+
1231+
expect(patchSession).toHaveBeenCalledWith({
1232+
key: "agent:main:main",
1233+
verboseLevel: "full",
1234+
});
1235+
expect(applySessionInfoFromPatch).toHaveBeenCalledWith(patchResult);
1236+
expect(loadHistory).toHaveBeenCalledTimes(1);
1237+
expect(refreshSessionInfo).not.toHaveBeenCalled();
1238+
expect(clearTools).not.toHaveBeenCalled();
1239+
});
1240+
12041241
it("refreshes session info for /trace without reloading history", async () => {
12051242
const loadHistory = vi.fn().mockResolvedValue(undefined);
12061243
const refreshSessionInfo = vi.fn().mockResolvedValue(undefined);

‎src/tui/tui-command-handlers.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ import {
1919
import { isChatStopCommandText } from "../gateway/chat-abort.js";
2020
import { formatRelativeTimestamp } from "../infra/format-time/format-relative.ts";
2121
import { normalizeAgentId } from "../routing/session-key.js";
22-
import { helpText, isSharedTextCommand, parseCommand } from "./commands.js";
22+
import {
23+
formatTuiLevelCommandUsage,
24+
helpText,
25+
isSharedTextCommand,
26+
parseCommand,
27+
} from "./commands.js";
2328
import type { ChatLog } from "./components/chat-log.js";
2429
import {
2530
createFilterableSelectList,
@@ -570,7 +575,7 @@ export function createCommandHandlers(context: CommandHandlerContext) {
570575
break;
571576
case "verbose":
572577
if (!args) {
573-
chatLog.addSystem("usage: /verbose <on|off>");
578+
chatLog.addSystem(`usage: ${formatTuiLevelCommandUsage("verbose")}`);
574579
break;
575580
}
576581
try {
@@ -630,7 +635,7 @@ export function createCommandHandlers(context: CommandHandlerContext) {
630635
break;
631636
case "reasoning":
632637
if (!args) {
633-
chatLog.addSystem("usage: /reasoning <on|off>");
638+
chatLog.addSystem(`usage: ${formatTuiLevelCommandUsage("reasoning")}`);
634639
break;
635640
}
636641
try {

‎src/tui/tui-pty-harness.e2e.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,8 @@ describe.sequential("TUI PTY harness", () => {
857857
await fixture.run.write("/help\r", { delay: false });
858858
await fixture.run.waitForOutput("Slash commands:");
859859
await fixture.run.waitForOutput("/help");
860+
await fixture.run.waitForOutput("/verbose <on|off|full>");
861+
await fixture.run.waitForOutput("/reasoning <on|off|stream>");
860862
await fixture.run.waitForOutput("/exit");
861863
},
862864
TEST_TIMEOUT_MS,
@@ -897,6 +899,23 @@ describe.sequential("TUI PTY harness", () => {
897899
TEST_TIMEOUT_MS,
898900
);
899901

902+
it.each([
903+
{ command: "verbose", level: "full", field: "verboseLevel" },
904+
{ command: "reasoning", level: "stream", field: "reasoningLevel" },
905+
])(
906+
"submits the canonical /$command $level terminal completion with one Enter",
907+
async ({ command, level, field }) => {
908+
await fixture.run.write(`/${command} ${level}`, { delay: false });
909+
await fixture.run.waitForOutput(`→ ${level}`);
910+
await fixture.run.write("\r", { delay: false });
911+
912+
await fixture.waitForLogEntry(
913+
(entry) => entry.method === "patchSession" && objectFieldEquals(entry, field, level),
914+
);
915+
},
916+
TEST_TIMEOUT_MS,
917+
);
918+
900919
it(
901920
"creates a backend session from /new and adopts its canonical key",
902921
async () => {

0 commit comments

Comments
 (0)