MCPcopy Create free account
hub / github.com/apache/maka / buildPowerShellCommand

Function buildPowerShellCommand

packages/runtime/src/shell-detect.ts:114–138  ·  view source on GitHub ↗
(
  command: string,
  env: NodeJS.ProcessEnv,
)

Source from the content-addressed store, hash-verified

112const POWERSHELL_COMMAND_ENV = '__MAKA_RUNTIME_POWERSHELL_COMMAND';
113
114function buildPowerShellCommand(
115 command: string,
116 env: NodeJS.ProcessEnv,
117): { script: string; env: NodeJS.ProcessEnv } {
118 // Keep the user command as its own parsed script. Prefixing statements
119 // directly would invalidate command text that begins with script-level
120 // syntax such as `using namespace`. Carry it outside argv so wrapping does
121 // not shrink Windows' command-line budget, then remove the private slot
122 // before user code or any descendant process can inspect the environment.
123 const invokeCommand =
124 `$__makaCommandText = [Environment]::GetEnvironmentVariable('${POWERSHELL_COMMAND_ENV}')\n` +
125 `[Environment]::SetEnvironmentVariable('${POWERSHELL_COMMAND_ENV}', $null)\n` +
126 '$__makaCommand = [ScriptBlock]::Create($__makaCommandText)\n' +
127 '. $__makaCommand';
128 const inheritedEnv = Object.fromEntries(
129 Object.entries(env).filter(([key]) => key.toUpperCase() !== POWERSHELL_COMMAND_ENV),
130 );
131 return {
132 script: `${POWERSHELL_UTF8_BOOTSTRAP}\n${invokeCommand}`,
133 env: {
134 ...inheritedEnv,
135 [POWERSHELL_COMMAND_ENV]: `${command}\n${POWERSHELL_EXIT_CODE_TAIL}`,
136 },
137 };
138}
139
140export function buildShellSpawnPlan(
141 shell: ShellPlan,

Callers 2

buildShellSpawnPlanFunction · 0.85
buildPtyShellSpawnPlanFunction · 0.85

Calls 1

entriesMethod · 0.65

Tested by

no test coverage detected