MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / runProcess

Function runProcess

services/cloud-agent-next/wrapper/src/utils.ts:104–293  ·  view source on GitHub ↗
(
  command: string,
  args: string[],
  opts?: ProcessOptions
)

Source from the content-addressed store, hash-verified

102 result.stdoutTruncated === true || result.stderrTruncated === true
103 ? TRUNCATION_MARKER
104 : undefined,
105 ]
106 .filter(value => value !== undefined)
107 .join(', ');
108}
109
110function terminationMessage(reason: TerminationReason): string {
111 switch (reason) {
112 case 'timeout':
113 return EXEC_TIMEOUT_MESSAGE;
114 case 'inactivity_timeout':
115 return EXEC_INACTIVITY_TIMEOUT_MESSAGE;
116 case 'hard_timeout':
117 return EXEC_HARD_TIMEOUT_MESSAGE;
118 case 'abort':
119 return EXEC_ABORTED_MESSAGE;
120 }
121}
122
123export function runProcess(
124 command: string,
125 args: string[],
126 opts?: ProcessOptions
127): Promise<ExecResult> {
128 const startedAt = Date.now();
129 if (opts?.signal?.aborted) {
130 return Promise.resolve({
131 stdout: '',
132 stderr: EXEC_ABORTED_MESSAGE,
133 exitCode: EXEC_TIMEOUT_EXIT_CODE,
134 elapsedMs: 0,
135 terminationReason: 'abort',
136 ...(opts.rawOutput ? { stdoutBytes: Buffer.alloc(0), stderrBytes: Buffer.alloc(0) } : {}),
137 });
138 }
139
140 return new Promise((resolve, reject) => {
141 const options = {
142 cwd: opts?.cwd,
143 ...(opts?.inheritEnv === false
144 ? { env: opts.env ?? {} }
145 : opts?.env
146 ? { env: { ...process.env, ...opts.env } }
147 : {}),
148 };
149 const owned = currentOwnedProcessScope();
150 const proc =
151 owned?.spawn(command, args, options) ??
152 spawn(command, args, {
153 ...options,
154 detached: true,
155 stdio: [opts?.stdinFd ?? 'ignore', 'pipe', 'pipe'],
156 });
157 const stdoutStream = proc.stdout;
158 const stderrStream = proc.stderr;
159 if (stdoutStream === null || stderrStream === null) {
160 proc.kill();
161 reject(new Error('Child process did not create output streams'));

Callers 4

utils.test.tsFile · 0.85
removePathFunction · 0.85
gitFunction · 0.85
restoreSessionFunction · 0.85

Calls 10

terminateFunction · 0.85
resetInactivityTimerFunction · 0.85
captureOutputFunction · 0.85
waitForTerminatedGroupFunction · 0.85
removeAbortHandlerFunction · 0.85
clearTimersFunction · 0.70
resolveFunction · 0.50
rejectFunction · 0.50
onMethod · 0.45
addEventListenerMethod · 0.45

Tested by

no test coverage detected