mirror of
https://github.com/alphaXiv/OpenResearch.git
synced 2026-11-12 10:05:24 +08:00
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>
13 lines
511 B
TypeScript
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;
|
|
}
|