MCPcopy Index your code
hub / github.com/Noumena-Network/code / runPowerShellCommand

Function runPowerShellCommand

src/tools/PowerShellTool/PowerShellTool.tsx:665–1002  ·  view source on GitHub ↗
({
  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;
})

Source from the content-addressed store, hash-verified

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

Callers 1

callFunction · 0.85

Calls 15

getCachedPowerShellPathFunction · 0.85
execFunction · 0.85
getPlatformFunction · 0.85
shouldUseSandboxFunction · 0.85
getKairosActiveFunction · 0.85
registerForegroundFunction · 0.85
unregisterForegroundFunction · 0.85
startPollingMethod · 0.80
maxMethod · 0.80
stopPollingMethod · 0.80
getDefaultTimeoutMsFunction · 0.70
getMaxTimeoutMsFunction · 0.70

Tested by

no test coverage detected