Files
OpenResearch/ui/src/bashCommand.ts
T
Myles AndersonandClaude Fable 5.1 56ed86d466 feat: ! bash mode in the chat composer (#283)
A draft that opens with `!` is a shell command, as in Claude Code: the
composer turns amber with a Bash chip, Enter (or the Run button) runs it
in the session's worktree through POST /api/chat/sessions/{id}/shell,
and the exchange lands on the transcript as a user-side card. Commands
run since the last real message are folded into the next turn's prompt
as untrusted context. Output is capped, the process group is killed on
timeout, and a backgrounded child cannot hold the request open.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-03 17:03:27 -07:00

13 lines
511 B
TypeScript

/** A draft opening with `!` is a shell command, not a message (Claude Code's bash mode). */
export const BASH_PREFIX = "!";
export function bashCommand(draft: string): string | null {
if (!draft.startsWith(BASH_PREFIX)) return null;
return draft.slice(BASH_PREFIX.length).trim();
}
/** The draft with the shell prefix dropped, for leaving the mode in place. */
export function withoutBashPrefix(draft: string): string {
return draft.startsWith(BASH_PREFIX) ? draft.slice(BASH_PREFIX.length) : draft;
}