@carrieros/cli-staging 0.0.0-stage → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +6 -2
  2. package/dist/commands/attach.js +45 -0
  3. package/dist/commands/auth.js +60 -0
  4. package/dist/commands/btw.js +78 -0
  5. package/dist/commands/changes.js +167 -0
  6. package/dist/commands/chat.js +182 -0
  7. package/dist/commands/context.js +200 -0
  8. package/dist/commands/doctor.js +119 -0
  9. package/dist/commands/files.js +94 -0
  10. package/dist/commands/help.js +37 -0
  11. package/dist/commands/history.js +112 -0
  12. package/dist/commands/login.js +62 -0
  13. package/dist/commands/logout.js +26 -0
  14. package/dist/commands/memory.js +162 -0
  15. package/dist/commands/mode-model.js +64 -0
  16. package/dist/commands/models.js +28 -0
  17. package/dist/commands/modes.js +30 -0
  18. package/dist/commands/permissions.js +78 -0
  19. package/dist/commands/project.js +106 -0
  20. package/dist/commands/repo.js +146 -0
  21. package/dist/commands/repos.js +61 -0
  22. package/dist/commands/review.js +92 -0
  23. package/dist/commands/scope.js +155 -0
  24. package/dist/commands/search.js +92 -0
  25. package/dist/commands/sessions.js +282 -0
  26. package/dist/commands/settings.js +160 -0
  27. package/dist/commands/update.js +285 -0
  28. package/dist/commands/upload.js +223 -0
  29. package/dist/commands/usage.js +229 -0
  30. package/dist/commands/version.js +26 -0
  31. package/dist/commands/whoami.js +44 -0
  32. package/dist/ide/editor-context.js +275 -0
  33. package/dist/ide/ide-session.js +364 -0
  34. package/dist/ide/tool-host.js +109 -0
  35. package/dist/main.js +132 -0
  36. package/dist/services/api.js +441 -0
  37. package/dist/services/auth-origin.js +20 -0
  38. package/dist/services/auto-update.js +221 -0
  39. package/dist/services/chat-stream.js +168 -0
  40. package/dist/services/checkpoints.js +278 -0
  41. package/dist/services/client-tools.js +356 -0
  42. package/dist/services/code-intel.js +243 -0
  43. package/dist/services/code-symbols.js +94 -0
  44. package/dist/services/coding-workflow.js +554 -0
  45. package/dist/services/command-coordinator.js +273 -0
  46. package/dist/services/command-policy.js +434 -0
  47. package/dist/services/config.js +384 -0
  48. package/dist/services/container-runner.js +254 -0
  49. package/dist/services/container-supervisor.js +38 -0
  50. package/dist/services/context.js +416 -0
  51. package/dist/services/device-auth.js +288 -0
  52. package/dist/services/diff.js +196 -0
  53. package/dist/services/env-policy.js +108 -0
  54. package/dist/services/execution-platform.js +30 -0
  55. package/dist/services/file-detect.js +104 -0
  56. package/dist/services/file-resolver.js +199 -0
  57. package/dist/services/file-upload.js +126 -0
  58. package/dist/services/folder-key.js +22 -0
  59. package/dist/services/git-tools.js +429 -0
  60. package/dist/services/glob-match.js +164 -0
  61. package/dist/services/helper-bin.js +85 -0
  62. package/dist/services/ignore-rules.js +189 -0
  63. package/dist/services/instruction-resolver.js +54 -0
  64. package/dist/services/job-helper.js +328 -0
  65. package/dist/services/local-files.js +639 -0
  66. package/dist/services/local-tools.js +937 -0
  67. package/dist/services/login-flow.js +156 -0
  68. package/dist/services/meta.js +42 -0
  69. package/dist/services/mutation-coordinator.js +327 -0
  70. package/dist/services/mutation-groups.js +309 -0
  71. package/dist/services/mutation-recovery.js +159 -0
  72. package/dist/services/mutations.js +679 -0
  73. package/dist/services/open-url.js +68 -0
  74. package/dist/services/output.js +62 -0
  75. package/dist/services/packaged-update.js +403 -0
  76. package/dist/services/packaged.js +39 -0
  77. package/dist/services/permission-mode.js +78 -0
  78. package/dist/services/process-runner.js +412 -0
  79. package/dist/services/project-context.js +298 -0
  80. package/dist/services/redaction.js +201 -0
  81. package/dist/services/result-reconciliation.js +49 -0
  82. package/dist/services/secure-store.js +217 -0
  83. package/dist/services/session-resolver.js +115 -0
  84. package/dist/services/sia.js +51 -0
  85. package/dist/services/spinner.js +40 -0
  86. package/dist/services/supported-runtime.js +59 -0
  87. package/dist/services/task-context.js +212 -0
  88. package/dist/services/task-snapshot.js +38 -0
  89. package/dist/services/tool-result-outbox.js +195 -0
  90. package/dist/services/update.js +730 -0
  91. package/dist/services/workspace-registry.js +310 -0
  92. package/dist/services/workspace.js +580 -0
  93. package/dist/shell/shell-chat.js +1622 -0
  94. package/dist/shell/shell-commands.js +411 -0
  95. package/dist/shell/shell-prompt.js +110 -0
  96. package/dist/shell/shell-renderer.js +51 -0
  97. package/dist/shell/shell-router.js +37 -0
  98. package/dist/shell/shell.js +414 -0
  99. package/dist/shell/task-context-view.js +40 -0
  100. package/dist/staging.js +5 -0
  101. package/dist/types/index.js +6 -0
  102. package/dist/ui/agent-cards.js +111 -0
  103. package/dist/ui/agent-presentation.js +131 -0
  104. package/dist/ui/approval.js +111 -0
  105. package/dist/ui/banner.js +56 -0
  106. package/dist/ui/btw-overlay.js +230 -0
  107. package/dist/ui/change-review.js +334 -0
  108. package/dist/ui/chat-renderer.js +463 -0
  109. package/dist/ui/code-block.js +52 -0
  110. package/dist/ui/color-picker.js +100 -0
  111. package/dist/ui/colors.js +55 -0
  112. package/dist/ui/command-details.js +11 -0
  113. package/dist/ui/command-filter.js +92 -0
  114. package/dist/ui/command-item.js +6 -0
  115. package/dist/ui/command-palette.js +383 -0
  116. package/dist/ui/command-registry.js +128 -0
  117. package/dist/ui/command-renderer.js +55 -0
  118. package/dist/ui/command-review.js +187 -0
  119. package/dist/ui/composer-layout.js +74 -0
  120. package/dist/ui/conversation.js +450 -0
  121. package/dist/ui/interrupt.js +35 -0
  122. package/dist/ui/live.js +141 -0
  123. package/dist/ui/logo.js +58 -0
  124. package/dist/ui/markdown.js +205 -0
  125. package/dist/ui/message.js +21 -0
  126. package/dist/ui/screen-prompt.js +181 -0
  127. package/dist/ui/screen.js +297 -0
  128. package/dist/ui/select.js +284 -0
  129. package/dist/ui/sia-qa.js +213 -0
  130. package/dist/ui/spinner.js +23 -0
  131. package/dist/ui/sticky-stream.js +64 -0
  132. package/dist/ui/task-context-card.js +99 -0
  133. package/dist/ui/text-prompt.js +74 -0
  134. package/dist/ui/theme.js +80 -0
  135. package/dist/ui/trust.js +88 -0
  136. package/dist/ui/ui.js +101 -0
  137. package/package.json +33 -4
@@ -0,0 +1,412 @@
1
+ import { spawn } from "node:child_process";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { StringDecoder } from "node:string_decoder";
5
+ import { buildChildEnv } from "./env-policy.js";
6
+ import { JOB_HELPER_FAILURE_EXIT, JobHelperError, ensureJobHelper } from "./job-helper.js";
7
+ import { isInside } from "./local-files.js";
8
+ import { executionAdapter, executionPlatform } from "./execution-platform.js";
9
+ import { runContainer } from "./container-runner.js";
10
+ /**
11
+ * Runs ONE local program, contained, bounded and redacted.
12
+ * Windows uses the Job Object implementation below. macOS/Linux dispatch to
13
+ * the isolated container adapter; neither has an unrestricted host fallback.
14
+ *
15
+ * This is the only way a command proposed by a model may ever reach the
16
+ * machine, and it is deliberately unaware of models, approval or policy — the
17
+ * caller decides WHETHER to run something; this decides HOW, and refuses
18
+ * anything it cannot run safely:
19
+ *
20
+ * - no shell, ever: a command is `program` + `args[]`, started by absolute path
21
+ * through the Job Object helper. `.cmd`/`.bat`/scripts, shells and
22
+ * interpreters-as-shells are refused by name, and shell operators are refused
23
+ * even though, without a shell, they would only be text.
24
+ * - npm/pnpm/yarn run as `node <their JS entry>`, never through `npm.cmd`.
25
+ * - the working directory must resolve, by realpath, inside the project root.
26
+ * - the environment comes from an allowlist (env-policy.ts).
27
+ * - every descendant lives in a kill-on-close Job Object: timeout, abort and
28
+ * the CLI exiting all end the whole tree.
29
+ * - output is redacted line by line before anyone sees it, and only a bounded
30
+ * head and tail are kept.
31
+ */
32
+ export class RunnerError extends Error {
33
+ code;
34
+ constructor(code, message) {
35
+ super(message);
36
+ this.code = code;
37
+ this.name = "RunnerError";
38
+ }
39
+ }
40
+ /** Hard ceiling on any single command; the server holds a call for 15 minutes. */
41
+ export const MAX_TIMEOUT_MS = 14 * 60 * 1000;
42
+ export const DEFAULT_HEAD_BYTES = 16 * 1024;
43
+ export const DEFAULT_TAIL_BYTES = 44 * 1024;
44
+ /** Refused as programs regardless of policy: each is a way back to a shell. */
45
+ const DENIED_PROGRAMS = new Set([
46
+ "cmd",
47
+ "command",
48
+ "powershell",
49
+ "powershell_ise",
50
+ "pwsh",
51
+ "bash",
52
+ "sh",
53
+ "zsh",
54
+ "wsl",
55
+ "wslhost",
56
+ "wscript",
57
+ "cscript",
58
+ "mshta",
59
+ "rundll32",
60
+ "regsvr32",
61
+ "start",
62
+ "conhost",
63
+ "runas",
64
+ "npx",
65
+ "explorer"
66
+ ]);
67
+ /** Characters that only mean something to a shell. */
68
+ const SHELL_OPERATOR = /[&|;<>`\r\n\0]|\$\(/;
69
+ // ── Validation ───────────────────────────────────────────────────────────────
70
+ export function validateArgs(args) {
71
+ if (!Array.isArray(args) || args.some((a) => typeof a !== "string")) {
72
+ throw new RunnerError("INVALID_ARGUMENTS", "args must be an array of strings.");
73
+ }
74
+ if (args.length > 64)
75
+ throw new RunnerError("INVALID_ARGUMENTS", "Too many arguments.");
76
+ for (const a of args) {
77
+ if (a.length > 4096)
78
+ throw new RunnerError("INVALID_ARGUMENTS", "An argument is too long.");
79
+ if (SHELL_OPERATOR.test(a)) {
80
+ throw new RunnerError("SHELL_OPERATOR", `Shell syntax is not accepted in arguments: ${JSON.stringify(a.slice(0, 80))}`);
81
+ }
82
+ }
83
+ return args;
84
+ }
85
+ /** Realpath-contained working directory, or a RunnerError. */
86
+ export function resolveCwd(cwd, root) {
87
+ if (typeof cwd !== "string" || !cwd.trim())
88
+ throw new RunnerError("INVALID_CWD", "A working directory is required.");
89
+ const raw = cwd.trim();
90
+ if (raw.includes("\0") || raw.startsWith("\\\\") || (/^[A-Za-z]:/.test(raw) && !path.isAbsolute(raw)) || raw.split(/[\\/]+/).includes("..")) {
91
+ throw new RunnerError("OUTSIDE_WORKSPACE", "The working directory must stay inside the project.");
92
+ }
93
+ const realRoot = fs.realpathSync.native(root);
94
+ const abs = path.isAbsolute(raw) ? path.resolve(raw) : path.resolve(realRoot, raw);
95
+ if (!isInside(realRoot, abs) && !isInside(root, abs)) {
96
+ throw new RunnerError("OUTSIDE_WORKSPACE", "The working directory must be inside the project.");
97
+ }
98
+ let real;
99
+ try {
100
+ real = fs.realpathSync.native(abs);
101
+ }
102
+ catch {
103
+ throw new RunnerError("INVALID_CWD", "The working directory does not exist.");
104
+ }
105
+ if (!isInside(realRoot, real)) {
106
+ throw new RunnerError("OUTSIDE_WORKSPACE", "The working directory links outside the project.");
107
+ }
108
+ if (!fs.statSync(real).isDirectory())
109
+ throw new RunnerError("INVALID_CWD", "The working directory is not a folder.");
110
+ return real;
111
+ }
112
+ function findOnPath(exeName, pathValue) {
113
+ for (const dir of pathValue.split(path.delimiter)) {
114
+ if (!dir || !path.isAbsolute(dir))
115
+ continue;
116
+ const candidate = path.join(dir, exeName);
117
+ try {
118
+ if (fs.statSync(candidate).isFile())
119
+ return candidate;
120
+ }
121
+ catch {
122
+ /* not here */
123
+ }
124
+ }
125
+ return null;
126
+ }
127
+ /** A package manager's JavaScript entry point, found next to its .cmd shim. */
128
+ function jsEntry(shim, pathValue, rel) {
129
+ const candidates = [path.join(path.dirname(process.execPath), "node_modules", ...rel)];
130
+ const dir = findOnPath(shim, pathValue);
131
+ if (dir)
132
+ candidates.push(path.join(path.dirname(dir), "node_modules", ...rel));
133
+ for (const c of candidates) {
134
+ try {
135
+ if (fs.statSync(c).isFile())
136
+ return c;
137
+ }
138
+ catch {
139
+ /* next */
140
+ }
141
+ }
142
+ return null;
143
+ }
144
+ /**
145
+ * The absolute argv prefix for a program name. Names only — a path, an
146
+ * extension other than .exe, or a shell/interpreter name is refused.
147
+ */
148
+ export function resolveProgram(program, pathValue) {
149
+ if (typeof program !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(program)) {
150
+ throw new RunnerError("INVALID_PROGRAM", "The program must be a bare name such as npm, node or git.");
151
+ }
152
+ const lower = program.toLowerCase();
153
+ const ext = path.extname(lower);
154
+ if (ext && ext !== ".exe") {
155
+ throw new RunnerError("PROGRAM_DENIED", `${program} cannot be run directly — only programs, not scripts or shell files.`);
156
+ }
157
+ const name = ext ? lower.slice(0, -ext.length) : lower;
158
+ if (DENIED_PROGRAMS.has(name))
159
+ throw new RunnerError("PROGRAM_DENIED", `${program} is not allowed.`);
160
+ switch (name) {
161
+ case "node":
162
+ return [process.execPath];
163
+ case "npm": {
164
+ const entry = jsEntry("npm.cmd", pathValue, ["npm", "bin", "npm-cli.js"]);
165
+ if (!entry)
166
+ throw new RunnerError("PROGRAM_NOT_FOUND", "npm was not found next to Node.");
167
+ return [process.execPath, entry];
168
+ }
169
+ case "pnpm": {
170
+ const entry = jsEntry("pnpm.cmd", pathValue, ["pnpm", "bin", "pnpm.cjs"]);
171
+ if (!entry)
172
+ throw new RunnerError("PROGRAM_NOT_FOUND", "pnpm was not found.");
173
+ return [process.execPath, entry];
174
+ }
175
+ case "yarn": {
176
+ const entry = jsEntry("yarn.cmd", pathValue, ["yarn", "bin", "yarn.js"]);
177
+ if (!entry)
178
+ throw new RunnerError("PROGRAM_NOT_FOUND", "yarn was not found.");
179
+ return [process.execPath, entry];
180
+ }
181
+ default: {
182
+ const exe = findOnPath(`${name}.exe`, pathValue);
183
+ if (!exe)
184
+ throw new RunnerError("PROGRAM_NOT_FOUND", `${program} was not found on PATH.`);
185
+ return [exe];
186
+ }
187
+ }
188
+ }
189
+ // ── Output ───────────────────────────────────────────────────────────────────
190
+ /**
191
+ * The nearest index at or after (`up`) / at or before (`down`) `i` that starts
192
+ * a UTF-8 character. `up` always returns at least 1 when i ≥ 1, so a trim
193
+ * always makes progress.
194
+ */
195
+ export function utf8Boundary(buf, i, dir) {
196
+ let at = Math.max(0, Math.min(i, buf.length));
197
+ const continuation = (n) => n < buf.length && (buf[n] & 0xc0) === 0x80;
198
+ if (dir === "up") {
199
+ while (continuation(at))
200
+ at += 1;
201
+ return at;
202
+ }
203
+ while (at > 0 && continuation(at))
204
+ at -= 1;
205
+ return at;
206
+ }
207
+ /** Keeps the first `headBytes` and the last `tailBytes` of what it is given. */
208
+ export class HeadTailBuffer {
209
+ headLimit;
210
+ tailLimit;
211
+ head = "";
212
+ headBytes = 0;
213
+ tail = [];
214
+ tailBytes = 0;
215
+ dropped = 0;
216
+ constructor(headLimit, tailLimit) {
217
+ this.headLimit = headLimit;
218
+ this.tailLimit = tailLimit;
219
+ }
220
+ append(text) {
221
+ if (!text)
222
+ return;
223
+ let rest = Buffer.from(text, "utf8");
224
+ if (this.headBytes < this.headLimit) {
225
+ if (rest.length <= this.headLimit - this.headBytes) {
226
+ this.head += text;
227
+ this.headBytes += rest.length;
228
+ return;
229
+ }
230
+ const at = utf8Boundary(rest, this.headLimit - this.headBytes, "down");
231
+ this.head += rest.subarray(0, at).toString("utf8");
232
+ this.headBytes += at;
233
+ rest = rest.subarray(at);
234
+ }
235
+ this.tail.push(rest.toString("utf8"));
236
+ this.tailBytes += rest.length;
237
+ // Every pass removes at least one byte, so this always terminates — a cut
238
+ // that lands inside a multi-byte character is moved to the next character
239
+ // boundary rather than re-encoded (re-encoding a partial `✓` can produce a
240
+ // replacement character just as long as what was cut, and loop forever).
241
+ while (this.tailBytes > this.tailLimit && this.tail.length) {
242
+ const first = Buffer.from(this.tail[0], "utf8");
243
+ const excess = this.tailBytes - this.tailLimit;
244
+ if (first.length <= excess) {
245
+ this.tail.shift();
246
+ this.tailBytes -= first.length;
247
+ this.dropped += first.length;
248
+ }
249
+ else {
250
+ const at = utf8Boundary(first, excess, "up");
251
+ this.tail[0] = first.subarray(at).toString("utf8");
252
+ this.tailBytes -= at;
253
+ this.dropped += at;
254
+ }
255
+ }
256
+ }
257
+ get truncated() {
258
+ return this.dropped > 0;
259
+ }
260
+ text() {
261
+ const tail = this.tail.join("");
262
+ return this.dropped > 0 ? `${this.head}\n… [${this.dropped} bytes of output omitted] …\n${tail}` : this.head + tail;
263
+ }
264
+ }
265
+ // ── Running ──────────────────────────────────────────────────────────────────
266
+ const active = new Set();
267
+ let exitHookInstalled = false;
268
+ /**
269
+ * Belt and braces for a clean CLI exit: the Job Object already guarantees the
270
+ * tree dies with the CLI, but ending it synchronously here means nothing is
271
+ * still running for even a moment after the prompt returns to the user.
272
+ */
273
+ function installExitHook() {
274
+ if (exitHookInstalled)
275
+ return;
276
+ exitHookInstalled = true;
277
+ process.once("exit", () => {
278
+ for (const child of active) {
279
+ try {
280
+ child.kill();
281
+ }
282
+ catch {
283
+ /* already gone */
284
+ }
285
+ }
286
+ });
287
+ }
288
+ export async function runProcess(req) {
289
+ if (executionAdapter(executionPlatform()) === "isolated-container")
290
+ return runContainer(req);
291
+ const args = validateArgs(req.args);
292
+ if (!Number.isFinite(req.timeoutMs) || req.timeoutMs < 1 || req.timeoutMs > MAX_TIMEOUT_MS) {
293
+ throw new RunnerError("INVALID_TIMEOUT", `timeout must be between 1 ms and ${MAX_TIMEOUT_MS} ms.`);
294
+ }
295
+ const cwd = resolveCwd(req.cwd, req.root);
296
+ const { env, dropped } = buildChildEnv(req.sourceEnv ?? process.env, req.root);
297
+ const pathValue = Object.entries(env).find(([k]) => k.toUpperCase() === "PATH")?.[1] ?? "";
298
+ const prefix = resolveProgram(req.program, pathValue);
299
+ const helper = ensureJobHelper(); // throws JobHelperError — never run uncontained
300
+ if (req.signal?.aborted)
301
+ throw new RunnerError("CANCELLED", "Cancelled before it started.");
302
+ const resolved = [...prefix, ...args];
303
+ const buffer = new HeadTailBuffer(req.headBytes ?? DEFAULT_HEAD_BYTES, req.tailBytes ?? DEFAULT_TAIL_BYTES);
304
+ const counts = { stdout: 0, stderr: 0 };
305
+ let helperStderr = "";
306
+ const started = Date.now();
307
+ const child = spawn(helper, resolved, {
308
+ cwd,
309
+ env,
310
+ stdio: ["ignore", "pipe", "pipe"],
311
+ windowsHide: true,
312
+ shell: false
313
+ });
314
+ active.add(child);
315
+ installExitHook();
316
+ let timedOut = false;
317
+ let cancelled = false;
318
+ let treeKilled = false;
319
+ const killTree = () => {
320
+ if (treeKilled)
321
+ return;
322
+ treeKilled = true;
323
+ // Terminating the helper closes the only handle to its Job Object, and
324
+ // KILL_ON_JOB_CLOSE ends every process in it.
325
+ try {
326
+ child.kill();
327
+ }
328
+ catch {
329
+ /* already exited */
330
+ }
331
+ };
332
+ const wire = (stream, readable) => {
333
+ if (!readable)
334
+ return null;
335
+ const decoder = new StringDecoder("utf8");
336
+ const redact = req.redactor.stream((text) => {
337
+ buffer.append(text);
338
+ req.onOutput?.(stream, text);
339
+ });
340
+ readable.on("data", (chunk) => {
341
+ counts[stream] += chunk.length;
342
+ if (stream === "stderr" && helperStderr.length < 512)
343
+ helperStderr += chunk.toString("utf8");
344
+ redact.write(decoder.write(chunk));
345
+ });
346
+ return () => {
347
+ redact.write(decoder.end());
348
+ redact.end();
349
+ };
350
+ };
351
+ const endStdout = wire("stdout", child.stdout);
352
+ const endStderr = wire("stderr", child.stderr);
353
+ const timer = setTimeout(() => {
354
+ timedOut = true;
355
+ killTree();
356
+ }, req.timeoutMs);
357
+ const onAbort = () => {
358
+ cancelled = true;
359
+ killTree();
360
+ };
361
+ req.signal?.addEventListener("abort", onAbort, { once: true });
362
+ let spawnError = null;
363
+ child.once("spawn", () => req.onStart?.({ pid: child.pid, resolved }));
364
+ const outcome = await new Promise((resolve) => {
365
+ child.once("error", (err) => {
366
+ spawnError = err;
367
+ resolve({ code: null, signal: null });
368
+ });
369
+ child.once("close", (code, signal) => resolve({ code, signal }));
370
+ // `close` waits for every holder of the output pipes. Once the helper has
371
+ // exited its job is gone, so anything still holding them is not ours to
372
+ // wait for: stop reading after a short grace period instead of hanging.
373
+ child.once("exit", (code, signal) => {
374
+ setTimeout(() => {
375
+ child.stdout?.destroy();
376
+ child.stderr?.destroy();
377
+ resolve({ code, signal });
378
+ }, 3000).unref();
379
+ });
380
+ });
381
+ clearTimeout(timer);
382
+ req.signal?.removeEventListener("abort", onAbort);
383
+ active.delete(child);
384
+ endStdout?.();
385
+ endStderr?.();
386
+ if (spawnError) {
387
+ throw new RunnerError("START_FAILED", `The command could not be started: ${spawnError.message}`);
388
+ }
389
+ if (!treeKilled && outcome.code === JOB_HELPER_FAILURE_EXIT && helperStderr.startsWith("cos-job-runner:")) {
390
+ throw new RunnerError("START_FAILED", helperStderr.split(/\r?\n/)[0].replace(/^cos-job-runner:\s*/, ""));
391
+ }
392
+ const ended = Date.now();
393
+ return {
394
+ exit_code: treeKilled ? null : outcome.code,
395
+ signal: treeKilled ? "SIGKILL" : outcome.signal,
396
+ timed_out: timedOut,
397
+ cancelled: cancelled && !timedOut,
398
+ tree_killed: treeKilled,
399
+ started_at: new Date(started).toISOString(),
400
+ ended_at: new Date(ended).toISOString(),
401
+ duration_ms: ended - started,
402
+ stdout_bytes: counts.stdout,
403
+ stderr_bytes: counts.stderr,
404
+ truncated: buffer.truncated,
405
+ output: buffer.text(),
406
+ redaction_count: req.redactor.count,
407
+ dropped_environment_names: dropped,
408
+ resolved_argv: resolved,
409
+ cwd
410
+ };
411
+ }
412
+ export { JobHelperError };