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

Function exec

src/utils/Shell.ts:182–443  ·  view source on GitHub ↗
(
  command: string,
  abortSignal: AbortSignal,
  shellType: ShellType,
  options?: ExecOptions,
)

Source from the content-addressed store, hash-verified

180 * Creates a new shell process for each command execution
181 */
182export async function exec(
183 command: string,
184 abortSignal: AbortSignal,
185 shellType: ShellType,
186 options?: ExecOptions,
187): Promise<ShellCommand> {
188 const {
189 timeout,
190 onProgress,
191 preventCwdChanges,
192 shouldUseSandbox,
193 shouldAutoBackground,
194 onStdout,
195 } = options ?? {}
196 const commandTimeout = timeout || DEFAULT_TIMEOUT
197
198 const provider = await resolveProvider[shellType]()
199
200 const id = Math.floor(Math.random() * 0x10000)
201 .toString(16)
202 .padStart(4, '0')
203
204 // Sandbox temp directory - use per-user directory name to prevent multi-user permission conflicts
205 const sandboxTmpDir = posixJoin(
206 process.env.CLAUDE_CODE_TMPDIR || '/tmp',
207 getNcodeTempDirName(),
208 )
209
210 const { commandString: builtCommand, cwdFilePath } =
211 await provider.buildExecCommand(command, {
212 id,
213 sandboxTmpDir: shouldUseSandbox ? sandboxTmpDir : undefined,
214 useSandbox: shouldUseSandbox ?? false,
215 })
216
217 let commandString = builtCommand
218
219 let cwd = pwd()
220
221 // Recover if the current working directory no longer exists on disk.
222 // This can happen when a command deletes its own CWD (e.g., temp dir cleanup).
223 try {
224 await realpath(cwd)
225 } catch {
226 const fallback = getOriginalCwd()
227 logForDebugging(
228 `Shell CWD "${cwd}" no longer exists, recovering to "${fallback}"`,
229 )
230 try {
231 await realpath(fallback)
232 setCwdState(fallback)
233 cwd = fallback
234 } catch {
235 return createFailedCommand(
236 `Working directory "${cwd}" no longer exists. Please restart NCode from an existing directory.`,
237 )
238 }
239 }

Callers 4

runPowerShellCommandFunction · 0.85
runShellCommandFunction · 0.85
refreshAwsAuthFunction · 0.85
refreshGcpAuthFunction · 0.85

Calls 15

clearMethod · 0.95
readFileSyncFunction · 0.90
unlinkSyncFunction · 0.90
getNcodeTempDirNameFunction · 0.85
pwdFunction · 0.85
getOriginalCwdFunction · 0.85
setCwdStateFunction · 0.85
createFailedCommandFunction · 0.85
createAbortedCommandFunction · 0.85
getFsImplementationFunction · 0.85
generateTaskIdFunction · 0.85
mkdirFunction · 0.85

Tested by

no test coverage detected