MCPcopy Create free account
hub / github.com/WJX20/claude-code / processBashCommand

Function processBashCommand

src/utils/processUserInput/processBashCommand.tsx:17–139  ·  view source on GitHub ↗
(inputString: string, precedingInputBlocks: ContentBlockParam[], attachmentMessages: AttachmentMessage[], context: ProcessUserInputContext, setToolJSX: SetToolJSXFn)

Source from the content-addressed store, hash-verified

15import { escapeXml } from '../xml.js';
16import type { ProcessUserInputContext } from './processUserInput.js';
17export async function processBashCommand(inputString: string, precedingInputBlocks: ContentBlockParam[], attachmentMessages: AttachmentMessage[], context: ProcessUserInputContext, setToolJSX: SetToolJSXFn): Promise<{
18 messages: (UserMessage | AttachmentMessage | SystemMessage)[];
19 shouldQuery: boolean;
20}> {
21 // Shell routing (docs/design/ps-shell-selection.md §5.2): consult
22 // defaultShell, fall back to bash. isPowerShellToolEnabled() applies the
23 // same platform + env-var gate as tools.ts so input-box routing matches
24 // tool-list visibility. Computed up front so telemetry records the
25 // actual shell, not the raw setting.
26 const usePowerShell = isPowerShellToolEnabled() && resolveDefaultShell() === 'powershell';
27 logEvent('tengu_input_bash', {
28 powershell: usePowerShell
29 });
30 const userMessage = createUserMessage({
31 content: prepareUserContent({
32 inputString: `<bash-input>${inputString}</bash-input>`,
33 precedingInputBlocks
34 })
35 });
36
37 // ctrl+b to background indicator
38 let jsx: React.ReactNode;
39
40 // Just show initial UI
41 setToolJSX({
42 jsx: <BashModeProgress input={inputString} progress={null} verbose={context.options.verbose} />,
43 shouldHidePromptInput: false
44 });
45 try {
46 const bashModeContext: ProcessUserInputContext = {
47 ...context,
48 // TODO: Clean up this hack
49 setToolJSX: _ => {
50 jsx = _?.jsx;
51 }
52 };
53
54 // Progress UI — shared across both shell backends (both emit ShellProgress)
55 const onProgress = (progress: {
56 data: ShellProgress;
57 }) => {
58 setToolJSX({
59 jsx: <>
60 <BashModeProgress input={inputString!} progress={progress.data} verbose={context.options.verbose} />
61 {jsx}
62 </>,
63 shouldHidePromptInput: false,
64 showSpinner: false
65 });
66 };
67
68 // User-initiated `!` commands run outside sandbox. Both shell tools honor
69 // dangerouslyDisableSandbox (checked against areUnsandboxedCommandsAllowed()
70 // in shouldUseSandbox.ts). PS sandbox is Linux/macOS/WSL2 only — on Windows
71 // native, shouldUseSandbox() returns false regardless (unsupported platform).
72 // Lazy-require PowerShellTool so its ~300KB chunk only loads when the
73 // user has actually selected the powershell default shell.
74 type PSMod = typeof import('src/tools/PowerShellTool/PowerShellTool.js');

Callers 1

processUserInputBaseFunction · 0.85

Calls 10

isPowerShellToolEnabledFunction · 0.85
resolveDefaultShellFunction · 0.85
logEventFunction · 0.85
createUserMessageFunction · 0.85
prepareUserContentFunction · 0.85
processToolResultBlockFunction · 0.85
escapeXmlFunction · 0.85
errorMessageFunction · 0.50

Tested by

no test coverage detected