(inputString: string, precedingInputBlocks: ContentBlockParam[], attachmentMessages: AttachmentMessage[], context: ProcessUserInputContext, setToolJSX: SetToolJSXFn)
| 15 | import { escapeXml } from '../xml.js'; |
| 16 | import type { ProcessUserInputContext } from './processUserInput.js'; |
| 17 | export 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'); |
no test coverage detected