A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
[RSI] Usage errors for no-argument slash commands given arguments (#2244)
Seth Karten292ae3028e1b
diff --git a/packages/coding-agent/.changes/eng-6103-no-arg-slash-usage-errors.md b/packages/coding-agent/.changes/eng-6103-no-arg-slash-usage-errors.mdnew file mode 100644index 0000000000..f41983de0e--- /dev/null+++ b/packages/coding-agent/.changes/eng-6103-no-arg-slash-usage-errors.md@@ -0,0 +1 @@+- No-argument slash commands now show a `Usage: /<command>` error when given arguments instead of silently sending the text to the model; the input is preserved for editing.diff --git a/packages/coding-agent/src/modes/interactive/interactive-mode.ts b/packages/coding-agent/src/modes/interactive/interactive-mode.tsindex 96797f0f59..efe3c0237e 100644--- a/packages/coding-agent/src/modes/interactive/interactive-mode.ts+++ b/packages/coding-agent/src/modes/interactive/interactive-mode.ts@@ -4631,12 +4631,22 @@ export class InteractiveMode {await this.handleSideQuestion(commandArgs);return;}- if (commandName === "settings" && !commandArgs) {+ if (commandName === "settings") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /settings");+ return;+ }await this.showSettingsSelector();this.editor.setText("");return;}- if (commandName === "scoped-models" && !commandArgs) {+ if (commandName === "scoped-models") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /scoped-models");+ return;+ }this.editor.setText("");await this.showModelsSelector();return;@@ -4671,12 +4681,22 @@ export class InteractiveMode {this.editor.setText("");return;}- if (commandName === "share" && !commandArgs) {+ if (commandName === "share") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /share");+ return;+ }await this.handleShareCommand();this.editor.setText("");return;}- if (commandName === "copy" && !commandArgs) {+ if (commandName === "copy") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /copy");+ return;+ }await this.handleCopyCommand();this.editor.setText("");return;@@ -4691,13 +4711,23 @@ export class InteractiveMode {await this.handleRlmMaxDepthCommand(commandArgs);return;}- if (commandName === "session" && !commandArgs) {+ if (commandName === "session") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /session");+ return;+ }this.echoLocalCommand(text);await this.handleSessionCommand();this.editor.setText("");return;}- if (commandName === "system-prompt" && !commandArgs) {+ if (commandName === "system-prompt") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /system-prompt");+ return;+ }this.echoLocalCommand(text);await this.handleSystemPromptCommand();this.editor.setText("");@@ -4708,13 +4738,23 @@ export class InteractiveMode {this.editor.setText("");return;}- if (commandName === "context" && !commandArgs) {+ if (commandName === "context") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /context");+ return;+ }this.echoLocalCommand(text);await this.handleContextCommand();this.editor.setText("");return;}- if (commandName === "logs" && !commandArgs) {+ if (commandName === "logs") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /logs");+ return;+ }this.echoLocalCommand(text);this.handleLogsCommand();this.editor.setText("");@@ -4726,44 +4766,84 @@ export class InteractiveMode {return;}if (commandName === "heartbeats") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /heartbeats");+ return;+ }this.editor.setText("");await this.showHeartbeatManager();return;}- if (commandName === "changelog" && !commandArgs) {+ if (commandName === "changelog") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /changelog");+ return;+ }this.echoLocalCommand(text);this.handleChangelogCommand();this.editor.setText("");return;}- if (commandName === "hotkeys" && !commandArgs) {+ if (commandName === "hotkeys") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /hotkeys");+ return;+ }this.echoLocalCommand(text);this.handleHotkeysCommand();this.editor.setText("");return;}- if (commandName === "fork" && !commandArgs) {+ if (commandName === "fork") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /fork");+ return;+ }this.editor.setText("");await this.showUserMessageSelector();return;}- if (commandName === "clone" && !commandArgs) {+ if (commandName === "clone") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /clone");+ return;+ }this.editor.setText("");await this.handleCloneCommand();return;}- if (commandName === "tree" && !commandArgs) {+ if (commandName === "tree") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /tree");+ return;+ }this.editor.setText("");restorePromptStashAfterSubmit = false;await this.showTreeSelector();return;}- if (commandName === "login" && !commandArgs) {+ if (commandName === "login") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /login");+ return;+ }this.editor.setText("");await this.showConfigurationMenu("providers");return;}- if (commandName === "logout" && !commandArgs) {+ if (commandName === "logout") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /logout");+ return;+ }this.editor.setText("");await this.showLogoutSelector();return;@@ -4801,7 +4881,12 @@ export class InteractiveMode {await this.handleResumeCommand(commandArgs);return;}- if (commandName === "reload" && !commandArgs) {+ if (commandName === "reload") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /reload");+ return;+ }this.editor.setText("");await this.handleReloadCommand();return;@@ -4830,7 +4915,12 @@ export class InteractiveMode {this.setFullscreenMode(enable);return;}- if (commandName === "debug" && !commandArgs) {+ if (commandName === "debug") {+ if (commandArgs) {+ this.editor.setText(text);+ this.showError("Usage: /debug");+ return;+ }await this.handleDebugCommand();this.editor.setText("");return;diff --git a/packages/coding-agent/test/interactive-mode-command-usage.test.ts b/packages/coding-agent/test/interactive-mode-command-usage.test.tsnew file mode 100644index 0000000000..36611605e7--- /dev/null+++ b/packages/coding-agent/test/interactive-mode-command-usage.test.ts@@ -0,0 +1,85 @@+import { beforeAll, describe, expect, it, vi } from "vitest";+import { InteractiveMode } from "../src/modes/interactive/interactive-mode.js";+import { initTheme } from "../src/modes/interactive/theme/theme.js";++type SubmitContext = {+ defaultEditor: { onSubmit?: (text: string) => Promise<void> };+ editor: { getText: () => string; setText: (text: string) => void };+ [key: string]: unknown;+};++type Prototype = {+ setupEditorSubmitHandler(this: SubmitContext): void;+};++const prototype = InteractiveMode.prototype as unknown as Prototype;++function makeSubmitContext() {+ const prompt = vi.fn(async () => undefined);+ let editorText = "";+ const context: SubmitContext = {+ defaultEditor: {},+ editor: {+ getText: () => editorText,+ setText: (text: string) => {+ editorText = text;+ },+ },+ agentConnection: { prompt },+ showError: vi.fn(),+ showStatus: vi.fn(),+ echoLocalCommand: vi.fn(),+ handleSessionCommand: vi.fn(async () => undefined),+ showTreeSelector: vi.fn(async () => undefined),+ showSettingsSelector: vi.fn(async () => undefined),+ showHeartbeatManager: vi.fn(async () => undefined),+ submittedInputBehavior: "steer",+ inputSubmissionGeneration: 0,+ inputSubmissionsPending: 0,+ pendingPromptStashReleases: [],+ promptStashState: {},+ pendingSubmittedPromptStash: undefined,+ snapshotPromptStash: vi.fn(() => ({ text: "" })),+ promptStash: undefined,+ promptStashSessionId: "session-1",+ sessionId: "session-1",+ clearShortcutGuide: vi.fn(),+ };+ return context;+}++describe("InteractiveMode no-argument command usage errors", () => {+ beforeAll(() => initTheme("dark"));++ it("rejects arguments to /tree with a usage error instead of prompting", async () => {+ const context = makeSubmitContext();+ const prompt = (context.agentConnection as { prompt: ReturnType<typeof vi.fn> }).prompt;+ prototype.setupEditorSubmitHandler.call(context);+ // The real editor clears its buffer before onSubmit runs; the usage+ // error must put the draft back for editing (as /clear does).+ // The real editor clears its buffer BEFORE invoking onSubmit.+ context.editor.setText("");+ await context.defaultEditor.onSubmit?.("/tree fix the bug");+ expect(context.showError).toHaveBeenCalledWith("Usage: /tree");+ expect(prompt).not.toHaveBeenCalled();+ expect(context.showTreeSelector).not.toHaveBeenCalled();+ expect(context.editor.getText()).toBe("/tree fix the bug");+ });++ it("still opens the tree selector without arguments", async () => {+ const context = makeSubmitContext();+ prototype.setupEditorSubmitHandler.call(context);+ await context.defaultEditor.onSubmit?.("/tree");+ expect(context.showTreeSelector).toHaveBeenCalledTimes(1);+ expect(context.showError).not.toHaveBeenCalled();+ });++ it.each(["settings", "session", "heartbeats"])("rejects arguments to /%s", async (command) => {+ const context = makeSubmitContext();+ const prompt = (context.agentConnection as { prompt: ReturnType<typeof vi.fn> }).prompt;+ prototype.setupEditorSubmitHandler.call(context);+ await context.defaultEditor.onSubmit?.(`/${command} stray argument`);+ expect(context.showError).toHaveBeenCalledWith(`Usage: /${command}`);+ expect(prompt).not.toHaveBeenCalled();+ });+});