Changesets · Branches · Tags · Compare
| Changeset | 7fbb7af6157cec313e6c77bee9731af6921729e1aeb0f01cb8aa37d74edc1993 |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-09-02 19:20 -07:00 |
| Committer | Dallin Romney <dallinromney@gmail.com> · 2025-09-02 19:20 -07:00 |
| Parents | add1a24afaff |
4 files changed
modified extensions/cli/spec/bash-mode.md +12 −1
| @@ -1,23 +1,27 @@ | ||
| 1 | 1 | Bash Mode (CLI TUI) |
| 2 | 2 | |
| 3 | 3 | Overview |
| 4 | + | |
| 4 | 5 | - Bash mode lets users run shell commands directly from the chat input by starting their input with an exclamation mark (!). |
| 5 | 6 | - It is intended for quick terminal command execution without leaving the TUI. |
| 6 | 7 | |
| 7 | 8 | Activation |
| 9 | + | |
| 8 | 10 | - Bash mode is activated when the current input (trimmed) starts with ! |
| 9 | - - Example: "!git status" or " !ls -la" both activate Bash mode. | |
| 11 | + - Example: "!git status" or " !ls -la" both activate Bash mode. | |
| 10 | 12 | - Visual indicator: |
| 11 | 13 | - Input border color changes to yellow. |
| 12 | 14 | - The input prompt indicator changes to a yellow "$". |
| 13 | 15 | - The input placeholder includes "! for bash mode". |
| 14 | 16 | |
| 15 | 17 | Deactivation / Exiting Bash Mode |
| 18 | + | |
| 16 | 19 | - Pressing Enter to submit the input exits bash mode immediately after submission, regardless of the command result. |
| 17 | 20 | - Pressing Esc when the input (trimmed) is exactly ! clears the input and exits bash mode. |
| 18 | 21 | - Editing the input so it no longer starts with ! also exits bash mode and restores normal input behavior. |
| 19 | 22 | |
| 20 | 23 | Interaction with other input helpers |
| 24 | + | |
| 21 | 25 | - When in bash mode (input starts with !): |
| 22 | 26 | - "@" file search suggestions are disabled. |
| 23 | 27 | - "/" slash command UI is disabled. |
| @@ -25,12 +29,14 @@ | ||
| 25 | 29 | - "@" file search suggestions are disabled. |
| 26 | 30 | |
| 27 | 31 | Submission behavior |
| 32 | + | |
| 28 | 33 | - On submit (Enter) with a bash-mode input: |
| 29 | 34 | - The leading ! is removed and the remainder is treated as the shell command to run. |
| 30 | 35 | - The TUI immediately appends an assistant message representing a Bash tool call, with status set to calling, so users can see that the command is in progress. |
| 31 | 36 | - The bash command is executed asynchronously; when it completes, the tool call status is updated to done (or error) and the output is populated. |
| 32 | 37 | |
| 33 | 38 | Execution semantics |
| 39 | + | |
| 34 | 40 | - The command is executed from the current working directory of the CLI process. |
| 35 | 41 | - The command runs in the user’s shell as a login shell: |
| 36 | 42 | - Unix/macOS: SHELL (or /bin/bash) invoked with -l -c "<command>". |
| @@ -40,6 +46,7 @@ | ||
| 40 | 46 | - Environment variables are inherited from the parent process. Aliases/functions availability depends on the user’s shell configuration and is not guaranteed. |
| 41 | 47 | |
| 42 | 48 | Output handling |
| 49 | + | |
| 43 | 50 | - Stdout is streamed into memory; Stderr is captured and appended as a trailing "Stderr: ..." section on success. |
| 44 | 51 | - If the process exits non-zero and Stderr contains content, the tool call is marked as error and the error text is shown. |
| 45 | 52 | - Output is truncated to the first 5000 lines if exceeded. |
| @@ -47,18 +54,22 @@ | ||
| 47 | 54 | "[Command timed out after 30 seconds of no output]". |
| 48 | 55 | |
| 49 | 56 | Keyboard behaviors (summary) |
| 57 | + | |
| 50 | 58 | - Enter: submit input. If in bash mode, exits bash mode after submission and shows the pending Bash tool call immediately. |
| 51 | 59 | - Shift+Enter: new line. |
| 52 | 60 | - Backslash (\) at end-of-line: inserts a new line (line continuation) as usual. |
| 53 | 61 | - Esc: if only ! (trimmed) is present, clears input and exits bash mode; otherwise cancels streaming or closes suggestions depending on context. |
| 54 | 62 | |
| 55 | 63 | Scope / Modes |
| 64 | + | |
| 56 | 65 | - Bash mode applies to interactive (TUI/standard) CLI usage. It is not part of headless (-p/--print) processing. |
| 57 | 66 | |
| 58 | 67 | Error handling |
| 68 | + | |
| 59 | 69 | - Command execution errors are captured and surfaced in the tool call as status error with human-readable error text (including Stderr when available). |
| 60 | 70 | |
| 61 | 71 | Examples |
| 72 | + | |
| 62 | 73 | - "!git status" → shows a Bash tool call immediately, then populates with the git status output. |
| 63 | 74 | - "!echo hello" → shows a Bash tool call immediately, then output "hello". |
| 64 | 75 | - "!some-unknown-cmd" → shows a Bash tool call immediately, then sets status to error with an error message. |
modified extensions/cli/src/ui/UserInput.tsx +7 −3
| @@ -618,7 +618,8 @@ | ||
| 618 | 618 | const renderInputText = () => { |
| 619 | 619 | const placeholderText = isRemoteMode |
| 620 | 620 | ? "Ask anything, / for slash commands, ! for bash mode" |
| 621 | - : placeholder || "Ask anything, @ for context, / for slash commands, ! for bash mode"; | |
| 621 | + : placeholder || | |
| 622 | + "Ask anything, @ for context, / for slash commands, ! for bash mode"; | |
| 622 | 623 | if (inputText.length === 0) { |
| 623 | 624 | return ( |
| 624 | 625 | <> |
| @@ -717,8 +718,11 @@ | ||
| 717 | 718 | paddingX={1} |
| 718 | 719 | borderColor={showBashMode ? "yellow" : isRemoteMode ? "cyan" : "gray"} |
| 719 | 720 | > |
| 720 | - <Text color={showBashMode ? "yellow" : isRemoteMode ? "cyan" : "blue"} bold> | |
| 721 | - {showBashMode ? "$" : isRemoteMode ? "◉" : "●"} | |
| 721 | + <Text | |
| 722 | + color={showBashMode ? "yellow" : isRemoteMode ? "cyan" : "blue"} | |
| 723 | + bold | |
| 724 | + > | |
| 725 | + {showBashMode ? "$" : isRemoteMode ? "◉" : "●"} | |
| 722 | 726 | </Text> |
| 723 | 727 | {renderInputText()} |
| 724 | 728 | </Box> |
modified extensions/cli/src/ui/hooks/useChat.bashMode.test.ts +4 −2
| @@ -20,7 +20,9 @@ | ||
| 20 | 20 | |
| 21 | 21 | it("should detect bash mode when message starts with !", async () => { |
| 22 | 22 | const mockRun = vi.mocked(runTerminalCommandTool.run); |
| 23 | - mockRun.mockResolvedValue("total 5\ndrwxr-xr-x 2 user user 4096 Jan 1 12:00 .\ndrwxr-xr-x 3 user user 4096 Jan 1 12:00 .."); | |
| 23 | + mockRun.mockResolvedValue( | |
| 24 | + "total 5\ndrwxr-xr-x 2 user user 4096 Jan 1 12:00 .\ndrwxr-xr-x 3 user user 4096 Jan 1 12:00 ..", | |
| 25 | + ); | |
| 24 | 26 | |
| 25 | 27 | const ctx = createMinimalTestContext(); |
| 26 | 28 | const chat = useChat({ |
| @@ -105,4 +107,4 @@ | ||
| 105 | 107 | |
| 106 | 108 | expect(mockRun).toHaveBeenCalledWith({ command: "echo hello" }); |
| 107 | 109 | }); |
| 108 | -}); | |
| No newline at the end of the file | ||
| 110 | +}); |
modified extensions/cli/src/ui/hooks/useChat.ts +7 −3
| @@ -349,7 +349,7 @@ | ||
| 349 | 349 | |
| 350 | 350 | // Extract the command after the ! |
| 351 | 351 | const bashCommand = message.trimStart().slice(1).trim(); |
| 352 | - | |
| 352 | + | |
| 353 | 353 | if (!bashCommand) { |
| 354 | 354 | return message; // No command provided, treat as regular message |
| 355 | 355 | } |
| @@ -373,8 +373,12 @@ | ||
| 373 | 373 | // Execute the bash command asynchronously - don't block UI |
| 374 | 374 | (async () => { |
| 375 | 375 | try { |
| 376 | - const { runTerminalCommandTool } = await import("../../tools/runTerminalCommand.js"); | |
| 377 | - const result = await runTerminalCommandTool.run({ command: bashCommand }); | |
| 376 | + const { runTerminalCommandTool } = await import( | |
| 377 | + "../../tools/runTerminalCommand.js" | |
| 378 | + ); | |
| 379 | + const result = await runTerminalCommandTool.run({ | |
| 380 | + command: bashCommand, | |
| 381 | + }); | |
| 378 | 382 | services.chatHistory.addToolResult(toolCallId, result, "done"); |
| 379 | 383 | } catch (error: any) { |
| 380 | 384 | const errorMessage = `Bash command failed: ${error?.message || String(error)}`; |