({
input,
abortController,
setAppState,
setToolJSX,
preventCwdChanges,
isMainThread,
toolUseId,
agentId
}: {
input: PowerShellToolInput;
abortController: AbortController;
setAppState: (f: (prev: AppState) => AppState) => void;
setToolJSX?: SetToolJSXFn;
preventCwdChanges?: boolean;
isMainThread?: boolean;
toolUseId?: string;
agentId?: AgentId;
})
| 661 | } |
| 662 | } satisfies ToolDef<InputSchema, Out>); |
| 663 | async function* runPowerShellCommand({ |
| 664 | input, |
| 665 | abortController, |
| 666 | setAppState, |
| 667 | setToolJSX, |
| 668 | preventCwdChanges, |
| 669 | isMainThread, |
| 670 | toolUseId, |
| 671 | agentId |
| 672 | }: { |
| 673 | input: PowerShellToolInput; |
| 674 | abortController: AbortController; |
| 675 | setAppState: (f: (prev: AppState) => AppState) => void; |
| 676 | setToolJSX?: SetToolJSXFn; |
| 677 | preventCwdChanges?: boolean; |
| 678 | isMainThread?: boolean; |
| 679 | toolUseId?: string; |
| 680 | agentId?: AgentId; |
| 681 | }): AsyncGenerator<{ |
| 682 | type: 'progress'; |
| 683 | output: string; |
| 684 | fullOutput: string; |
| 685 | elapsedTimeSeconds: number; |
| 686 | totalLines: number; |
| 687 | totalBytes: number; |
| 688 | taskId?: string; |
| 689 | timeoutMs?: number; |
| 690 | }, ExecResult, void> { |
| 691 | const { |
| 692 | command, |
| 693 | description, |
| 694 | timeout, |
| 695 | run_in_background, |
| 696 | dangerouslyDisableSandbox |
| 697 | } = input; |
| 698 | const timeoutMs = Math.min(timeout || getDefaultTimeoutMs(), getMaxTimeoutMs()); |
| 699 | let fullOutput = ''; |
| 700 | let lastProgressOutput = ''; |
| 701 | let lastTotalLines = 0; |
| 702 | let lastTotalBytes = 0; |
| 703 | let backgroundShellId: string | undefined = undefined; |
| 704 | let interruptBackgroundingStarted = false; |
| 705 | let assistantAutoBackgrounded = false; |
| 706 | |
| 707 | // Progress signal: resolved when backgroundShellId is set in the async |
| 708 | // .then() path, waking the generator's Promise.race immediately instead of |
| 709 | // waiting for the next setTimeout tick (matches BashTool pattern). |
| 710 | let resolveProgress: (() => void) | null = null; |
| 711 | function createProgressSignal(): Promise<null> { |
| 712 | return new Promise<null>(resolve => { |
| 713 | resolveProgress = () => resolve(null); |
| 714 | }); |
| 715 | } |
| 716 | const shouldAutoBackground = !isBackgroundTasksDisabled && isAutobackgroundingAllowed(command); |
| 717 | const powershellPath = await getCachedPowerShellPath(); |
| 718 | if (!powershellPath) { |
| 719 | // Pre-flight failure: pwsh not installed. Return code 0 so call() surfaces |
| 720 | // this as a graceful stderr message rather than throwing ShellError — the |
no test coverage detected