@tagma/sdk 0.7.3 → 0.7.4

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 (92) hide show
  1. package/README.md +26 -5
  2. package/dist/adapters/stdin-approval.d.ts +1 -5
  3. package/dist/adapters/stdin-approval.d.ts.map +1 -1
  4. package/dist/adapters/stdin-approval.js +1 -89
  5. package/dist/adapters/stdin-approval.js.map +1 -1
  6. package/dist/adapters/websocket-approval.d.ts +1 -27
  7. package/dist/adapters/websocket-approval.d.ts.map +1 -1
  8. package/dist/adapters/websocket-approval.js +1 -146
  9. package/dist/adapters/websocket-approval.js.map +1 -1
  10. package/dist/approval.d.ts +2 -12
  11. package/dist/approval.d.ts.map +1 -1
  12. package/dist/approval.js +1 -90
  13. package/dist/approval.js.map +1 -1
  14. package/dist/bootstrap.d.ts +1 -1
  15. package/dist/bootstrap.d.ts.map +1 -1
  16. package/dist/core/task-executor.d.ts.map +1 -1
  17. package/dist/core/task-executor.js +13 -4
  18. package/dist/core/task-executor.js.map +1 -1
  19. package/dist/engine.d.ts +5 -56
  20. package/dist/engine.d.ts.map +1 -1
  21. package/dist/engine.js +7 -297
  22. package/dist/engine.js.map +1 -1
  23. package/dist/index.d.ts +4 -6
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +2 -4
  26. package/dist/index.js.map +1 -1
  27. package/dist/logger.d.ts +2 -60
  28. package/dist/logger.d.ts.map +1 -1
  29. package/dist/logger.js +1 -153
  30. package/dist/logger.js.map +1 -1
  31. package/dist/plugins.d.ts +2 -2
  32. package/dist/plugins.d.ts.map +1 -1
  33. package/dist/plugins.js +1 -1
  34. package/dist/plugins.js.map +1 -1
  35. package/dist/registry.d.ts +2 -66
  36. package/dist/registry.d.ts.map +1 -1
  37. package/dist/registry.js +1 -292
  38. package/dist/registry.js.map +1 -1
  39. package/dist/runner.d.ts +1 -35
  40. package/dist/runner.d.ts.map +1 -1
  41. package/dist/runner.js +1 -610
  42. package/dist/runner.js.map +1 -1
  43. package/dist/runtime/adapters/stdin-approval.d.ts +2 -0
  44. package/dist/runtime/adapters/stdin-approval.d.ts.map +1 -0
  45. package/dist/runtime/adapters/stdin-approval.js +2 -0
  46. package/dist/runtime/adapters/stdin-approval.js.map +1 -0
  47. package/dist/runtime/adapters/websocket-approval.d.ts +2 -0
  48. package/dist/runtime/adapters/websocket-approval.d.ts.map +1 -0
  49. package/dist/runtime/adapters/websocket-approval.js +2 -0
  50. package/dist/runtime/adapters/websocket-approval.js.map +1 -0
  51. package/dist/runtime/bun-process-runner.d.ts +2 -0
  52. package/dist/runtime/bun-process-runner.d.ts.map +1 -0
  53. package/dist/runtime/bun-process-runner.js +2 -0
  54. package/dist/runtime/bun-process-runner.js.map +1 -0
  55. package/dist/runtime.d.ts +2 -8
  56. package/dist/runtime.d.ts.map +1 -1
  57. package/dist/runtime.js +1 -7
  58. package/dist/runtime.js.map +1 -1
  59. package/dist/tagma.d.ts +3 -4
  60. package/dist/tagma.d.ts.map +1 -1
  61. package/dist/tagma.js +2 -3
  62. package/dist/tagma.js.map +1 -1
  63. package/dist/triggers/file.d.ts.map +1 -1
  64. package/dist/triggers/file.js +74 -107
  65. package/dist/triggers/file.js.map +1 -1
  66. package/package.json +15 -4
  67. package/src/adapters/stdin-approval.ts +1 -106
  68. package/src/adapters/websocket-approval.ts +1 -224
  69. package/src/approval.ts +5 -127
  70. package/src/bootstrap.ts +1 -1
  71. package/src/core/run-context.test.ts +35 -0
  72. package/src/core/task-executor.ts +13 -4
  73. package/src/engine-ports-mixed.test.ts +70 -44
  74. package/src/engine-ports.test.ts +77 -33
  75. package/src/engine.ts +18 -444
  76. package/src/index.ts +4 -6
  77. package/src/logger.ts +2 -182
  78. package/src/package-split.test.ts +15 -0
  79. package/src/pipeline-runner.test.ts +65 -12
  80. package/src/plugin-registry.test.ts +69 -3
  81. package/src/plugins.ts +2 -2
  82. package/src/registry.ts +7 -353
  83. package/src/runner.ts +1 -666
  84. package/src/runtime/adapters/stdin-approval.ts +1 -0
  85. package/src/runtime/adapters/websocket-approval.ts +1 -0
  86. package/src/runtime/bun-process-runner.ts +1 -0
  87. package/src/runtime-adapters.test.ts +10 -0
  88. package/src/runtime.ts +12 -20
  89. package/src/tagma.test.ts +162 -0
  90. package/src/tagma.ts +9 -4
  91. package/src/triggers/file.test.ts +79 -0
  92. package/src/triggers/file.ts +85 -118
package/dist/runner.js CHANGED
@@ -1,611 +1,2 @@
1
- import { existsSync, readFileSync, statSync } from 'node:fs';
2
- import { mkdir, open } from 'node:fs/promises';
3
- import { dirname, isAbsolute, join, resolve as pathResolve } from 'node:path';
4
- import { shellArgs } from './utils';
5
- // Delay before escalating SIGTERM to SIGKILL when killing a timed-out process.
6
- const SIGKILL_DELAY_MS = 3_000;
7
- /**
8
- * Default cap for the in-memory tail retained for each stream. Picked so that
9
- * a task producing runaway output (AI agent bug, adversarial input) cannot
10
- * balloon the sidecar's RSS, while still being large enough that typical AI
11
- * responses (which top out around low-MB of text) are returned whole. Callers
12
- * that need different limits supply `RunOptions.maxStdoutTailBytes` /
13
- * `.maxStderrTailBytes`.
14
- */
15
- const DEFAULT_STDOUT_TAIL_BYTES = 8 * 1024 * 1024; // 8 MB
16
- const DEFAULT_STDERR_TAIL_BYTES = 4 * 1024 * 1024; // 4 MB
17
- /**
18
- * On Windows, proc.kill('SIGTERM') / proc.kill('SIGKILL') only terminate the
19
- * direct child process. When the child is a .cmd/.bat wrapper (e.g. claude.cmd),
20
- * cmd.exe spawns the real process as a grandchild — proc.kill misses it entirely.
21
- * `taskkill /F /T /PID` kills the entire process tree rooted at the given PID.
22
- */
23
- function killProcessTree(pid) {
24
- if (process.platform !== 'win32')
25
- return;
26
- try {
27
- const result = Bun.spawnSync(['taskkill', '/F', '/T', '/PID', String(pid)], {
28
- stdout: 'pipe',
29
- stderr: 'pipe',
30
- });
31
- if (result.exitCode !== 0) {
32
- const stderr = new TextDecoder().decode(result.stderr);
33
- // Exit code 128 = process not found (already exited) — not worth warning about
34
- if (result.exitCode !== 128) {
35
- console.error(`[killProcessTree] taskkill exited ${result.exitCode} for PID ${pid}: ${stderr.trim()}`);
36
- }
37
- }
38
- }
39
- catch {
40
- /* best-effort — process may have already exited */
41
- }
42
- }
43
- /**
44
- * Read a stream to completion, persisting every chunk to `filePath` (when
45
- * provided) while keeping only the last `maxTailBytes` bytes in memory.
46
- *
47
- * Why the split: large child outputs (multi-MB AI responses, verbose debug
48
- * dumps) used to accumulate entirely in memory via `new Response(s).text()`,
49
- * which let a runaway task balloon the sidecar's RSS. Streaming to disk +
50
- * bounded tail gives callers: (a) unbounded data fidelity on disk, (b) fixed
51
- * memory footprint, (c) the tail — which is almost always what callers
52
- * actually consume (final AI answer, error summary, last N lines).
53
- *
54
- * Backpressure: we `await fh.write(chunk)` per chunk, so if disk is slow we
55
- * naturally slow the reader — but we do NOT stop reading the pipe, so the
56
- * child never blocks on a full stdout pipe. Disk errors don't abort the
57
- * stream; we close the handle, null it, and keep consuming into the tail
58
- * buffer only (with a breadcrumb in the returned text).
59
- *
60
- * Tail eviction: drops whole chunks from the front until total retained is
61
- * at or below the cap. If a single chunk alone exceeds the cap (rare — would
62
- * require a >cap-bytes chunkless burst from the child), we slice its tail.
63
- * UTF-8 boundaries at the slice point may emit replacement characters when
64
- * decoded — acceptable (the trailing/leading codepoint is a cosmetic loss).
65
- */
66
- async function collectStream(stream, filePath, maxTailBytes) {
67
- if (!stream)
68
- return { text: '', totalBytes: 0, path: null };
69
- let fh = null;
70
- let diskWriteFailed = false;
71
- if (filePath) {
72
- try {
73
- await mkdir(dirname(filePath), { recursive: true });
74
- fh = await open(filePath, 'w');
75
- }
76
- catch (err) {
77
- console.error(`[runner] failed to open ${filePath} for output streaming: ${err instanceof Error ? err.message : String(err)}`);
78
- diskWriteFailed = true;
79
- }
80
- }
81
- const chunks = [];
82
- let tailBytes = 0;
83
- let totalBytes = 0;
84
- let streamError = null;
85
- try {
86
- // Use for await...of to avoid Bun bug where getReader() returns an
87
- // incomplete reader missing releaseLock() under concurrent spawn.
88
- // https://github.com/oven-sh/bun/issues/28952
89
- //
90
- // Bun 1.3.x also has sporadic failures iterating a spawned process's
91
- // stream under concurrent Bun.spawn — the iterator throws mid-drain even
92
- // when the child exited 0. We record the error as a breadcrumb instead
93
- // of propagating, so the caller still sees the real exitCode from
94
- // proc.exited and a task that the OS considered successful doesn't get
95
- // marked failed over a runtime stream glitch.
96
- for await (const value of stream) {
97
- totalBytes += value.length;
98
- // Disk: persist every byte. Failure here degrades to tail-only mode
99
- // without interrupting the stream (child must not block on pipe fill).
100
- if (fh) {
101
- try {
102
- await fh.write(value);
103
- }
104
- catch (err) {
105
- console.error(`[runner] disk write failed for ${filePath}: ${err instanceof Error ? err.message : String(err)}`);
106
- try {
107
- await fh.close();
108
- }
109
- catch {
110
- /* ignore */
111
- }
112
- fh = null;
113
- diskWriteFailed = true;
114
- }
115
- }
116
- // Tail: append then evict whole chunks from the head while the total
117
- // retained exceeds the cap. Keep at least one chunk so short outputs
118
- // aren't lost entirely. Post-condition: tailBytes <= maxTailBytes OR
119
- // only one chunk remains (handled by the next block).
120
- chunks.push(value);
121
- tailBytes += value.length;
122
- while (chunks.length > 1 && tailBytes > maxTailBytes) {
123
- tailBytes -= chunks.shift().length;
124
- }
125
- // Pathological: a single chunk larger than the cap. Slice its tail.
126
- if (chunks.length === 1 && chunks[0].length > maxTailBytes) {
127
- const only = chunks[0];
128
- chunks[0] = only.slice(only.length - maxTailBytes);
129
- tailBytes = chunks[0].length;
130
- }
131
- }
132
- }
133
- catch (err) {
134
- streamError = err instanceof Error ? err : new Error(String(err));
135
- console.error(`[runner] stream read failed: ${streamError.message} — returning partial output`);
136
- }
137
- finally {
138
- if (fh) {
139
- try {
140
- await fh.close();
141
- }
142
- catch {
143
- /* ignore */
144
- }
145
- }
146
- }
147
- // Decode retained chunks. `stream: true` lets the decoder buffer partial
148
- // code points across chunks, handling all boundaries except the very first
149
- // chunk (which may itself start mid-codepoint after eviction) — that
150
- // boundary gets a U+FFFD replacement, which is preferable to throwing.
151
- const decoder = new TextDecoder();
152
- let text = '';
153
- for (const c of chunks)
154
- text += decoder.decode(c, { stream: true });
155
- text += decoder.decode();
156
- if (totalBytes > tailBytes) {
157
- const dropped = totalBytes - tailBytes;
158
- const pathHint = filePath
159
- ? diskWriteFailed
160
- ? `${filePath} (partial — disk write failed mid-stream)`
161
- : filePath
162
- : 'not persisted (no path configured)';
163
- text = `[…${dropped} bytes truncated from head — full output at: ${pathHint}]\n${text}`;
164
- }
165
- if (streamError) {
166
- text = text + `\n[runner] stream read aborted: ${streamError.message}`;
167
- }
168
- return {
169
- text,
170
- totalBytes,
171
- // Return the path even on partial-write failure so operators can still
172
- // inspect the head bytes we managed to persist.
173
- path: filePath ?? null,
174
- };
175
- }
176
- /**
177
- * On Windows, Bun.spawn does NOT auto-append PATHEXT extensions like
178
- * CreateProcess does. A bare command like `claude` fails with ENOENT if the
179
- * actual file on disk is `claude.cmd` / `claude.bat` / `claude.ps1`. We
180
- * manually resolve the command against PATH + PATHEXT here so Drivers can
181
- * keep using short names (`claude`, `npx`, etc.) cross-platform.
182
- *
183
- * We also auto-unwrap npm-generated .cmd shims into direct `node <js>`
184
- * invocations. Spawning the .cmd routes argv through cmd.exe, which silently
185
- * truncates any argv element at the first newline — a multi-line prompt
186
- * reaches the child as just its first line. By targeting the underlying JS
187
- * entry point directly we bypass cmd.exe entirely and newlines survive.
188
- *
189
- * Results are cached by (cmd, envPath) key so repeated spawns of the same
190
- * command don't block the event loop with synchronous PATH/shim scans.
191
- *
192
- * Returns the original name if resolution fails; Bun will raise the same
193
- * ENOENT it would have otherwise.
194
- */
195
- const RESOLVED_EXE_CACHE_MAX = 128;
196
- // A cache entry is the replacement argv head for the command:
197
- // - [path] — a single resolved executable (e.g. `foo.exe`)
198
- // - [node, jsEntry] — an npm-shim unwrapped into `node <js>`
199
- // - null — resolution failed, leave the original name
200
- const resolvedExeCache = new Map();
201
- /** Evict the oldest entry when the cache is at capacity. */
202
- function evictIfFull() {
203
- if (resolvedExeCache.size >= RESOLVED_EXE_CACHE_MAX) {
204
- // Map iteration order is insertion order — delete the first (oldest) key.
205
- const oldest = resolvedExeCache.keys().next().value;
206
- if (oldest !== undefined)
207
- resolvedExeCache.delete(oldest);
208
- }
209
- }
210
- /**
211
- * Parse an npm-generated .cmd shim and return the underlying JS entry path.
212
- *
213
- * npm's shim has the shape:
214
- * "%_prog%" "%dp0%\node_modules\<pkg>\bin\<script>" %*
215
- *
216
- * We extract the second double-quoted path, substitute `%dp0%` with the
217
- * wrapper's own directory, and return the absolute JS path. Returns null for
218
- * anything that doesn't match the npm-shim pattern (user-written .cmd
219
- * scripts, non-node tools, etc.), which keeps the caller on the .cmd path.
220
- */
221
- function parseNpmCmdShim(wrapperPath) {
222
- let contents;
223
- try {
224
- contents = readFileSync(wrapperPath, 'utf8');
225
- }
226
- catch {
227
- return null;
228
- }
229
- const execLine = contents
230
- .split(/\r?\n/)
231
- .find((l) => l.includes('%*') && l.includes('%dp0%'));
232
- if (!execLine)
233
- return null;
234
- const quoted = execLine.match(/"([^"]+)"/g);
235
- if (!quoted || quoted.length < 2)
236
- return null;
237
- const rawTarget = quoted[1].slice(1, -1); // strip surrounding quotes
238
- const wrapperDir = dirname(wrapperPath);
239
- // %dp0% expands to wrapper dir with a trailing backslash; strip either form.
240
- const expanded = rawTarget.replace(/%dp0%\\?/i, '').replace(/\//g, '\\');
241
- const abs = isAbsolute(expanded) ? expanded : pathResolve(wrapperDir, expanded);
242
- return existsSync(abs) ? abs : null;
243
- }
244
- /**
245
- * Given a resolved .cmd/.bat path, return the argv prefix that should be
246
- * spawned instead. For npm shims this is `[node, js-entry]`; for everything
247
- * else it's `[wrapperPath]` (unchanged, caller keeps using the wrapper).
248
- */
249
- function unwrapCmdShim(wrapperPath) {
250
- if (!/\.(cmd|bat)$/i.test(wrapperPath))
251
- return [wrapperPath];
252
- const jsEntry = parseNpmCmdShim(wrapperPath);
253
- if (!jsEntry)
254
- return [wrapperPath];
255
- // Prefer node colocated with the wrapper (npm global bin often ships one).
256
- const colocated = join(dirname(wrapperPath), 'node.exe');
257
- const nodeExe = existsSync(colocated) ? colocated : 'node';
258
- return [nodeExe, jsEntry];
259
- }
260
- function resolveWindowsExe(args, envPath) {
261
- if (process.platform !== 'win32' || args.length === 0)
262
- return args;
263
- const cmd = args[0];
264
- // Already a full path or has an extension → trust caller. We still attempt
265
- // shim unwrapping when the caller handed us a bare .cmd/.bat so drivers
266
- // that resolve the shim themselves still benefit from the cmd.exe bypass.
267
- if (isAbsolute(cmd) || /\.[a-z0-9]+$/i.test(cmd)) {
268
- if (/\.(cmd|bat)$/i.test(cmd) && existsSync(cmd)) {
269
- const unwrapped = unwrapCmdShim(cmd);
270
- if (unwrapped.length === 2)
271
- return [...unwrapped, ...args.slice(1)];
272
- }
273
- return args;
274
- }
275
- const cacheKey = `${cmd}\x00${envPath}`;
276
- if (resolvedExeCache.has(cacheKey)) {
277
- // ?? null coerces undefined→null so the subsequent guard narrows cleanly.
278
- const cached = resolvedExeCache.get(cacheKey) ?? null;
279
- return cached !== null ? [...cached, ...args.slice(1)] : args;
280
- }
281
- const exts = (process.env.PATHEXT ?? '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC')
282
- .split(';')
283
- .filter(Boolean);
284
- const dirs = envPath.split(';').filter(Boolean);
285
- for (const dir of dirs) {
286
- for (const ext of exts) {
287
- const candidate = join(dir, cmd + ext);
288
- try {
289
- if (existsSync(candidate) && statSync(candidate).isFile()) {
290
- const head = unwrapCmdShim(candidate);
291
- evictIfFull();
292
- resolvedExeCache.set(cacheKey, head);
293
- return [...head, ...args.slice(1)];
294
- }
295
- }
296
- catch {
297
- /* stat race — skip */
298
- }
299
- }
300
- }
301
- evictIfFull();
302
- resolvedExeCache.set(cacheKey, null);
303
- return args;
304
- }
305
- /**
306
- * H2: Build a "failed before spawn" result. Tagged as 'spawn_error' so the
307
- * engine can show a useful classification ("driver tried to launch X but
308
- * the binary wasn't found") rather than the misleading "timeout".
309
- *
310
- * Pre-spawn failures never opened the output files, so stdoutPath /
311
- * stderrPath are null regardless of what the caller passed in opts — there
312
- * is nothing on disk to point at.
313
- */
314
- function failResult(stderr, durationMs) {
315
- return {
316
- exitCode: -1,
317
- stdout: '',
318
- stderr,
319
- stdoutPath: null,
320
- stderrPath: null,
321
- stdoutBytes: 0,
322
- stderrBytes: stderr.length,
323
- durationMs,
324
- sessionId: null,
325
- normalizedOutput: null,
326
- failureKind: 'spawn_error',
327
- };
328
- }
329
- /**
330
- * R2: Validate a SpawnSpec returned by a third-party driver. Returns null on
331
- * success or a human-readable error message describing the first violation.
332
- *
333
- * Catching this here is critical: an undetected bad spec ends up calling
334
- * Bun.spawn with garbage and the resulting TypeError leaks into engine
335
- * processTask's catch block as "Cannot read properties of undefined". By
336
- * validating here we surface a clear "Driver X returned invalid args" message
337
- * instead, and short-circuit before holding any process resources.
338
- */
339
- export function validateSpawnSpec(spec, driverName) {
340
- if (!spec || typeof spec !== 'object') {
341
- return `Driver "${driverName}".buildCommand returned ${spec === null ? 'null' : typeof spec}, expected SpawnSpec object`;
342
- }
343
- const s = spec;
344
- if (!Array.isArray(s.args)) {
345
- return `Driver "${driverName}".buildCommand returned spec.args of type ${typeof s.args}, expected string[]`;
346
- }
347
- if (s.args.length === 0) {
348
- return `Driver "${driverName}".buildCommand returned an empty spec.args array`;
349
- }
350
- for (let i = 0; i < s.args.length; i++) {
351
- if (typeof s.args[i] !== 'string') {
352
- return `Driver "${driverName}".buildCommand returned spec.args[${i}] of type ${typeof s.args[i]}, expected string`;
353
- }
354
- }
355
- if (typeof s.args[0] !== 'string' || s.args[0].length === 0) {
356
- return `Driver "${driverName}".buildCommand returned an empty executable name in spec.args[0]`;
357
- }
358
- if (s.cwd !== undefined && typeof s.cwd !== 'string') {
359
- return `Driver "${driverName}".buildCommand returned spec.cwd of type ${typeof s.cwd}, expected string or undefined`;
360
- }
361
- if (s.stdin !== undefined && typeof s.stdin !== 'string') {
362
- return `Driver "${driverName}".buildCommand returned spec.stdin of type ${typeof s.stdin}, expected string or undefined`;
363
- }
364
- if (s.env !== undefined) {
365
- if (!s.env || typeof s.env !== 'object' || Array.isArray(s.env)) {
366
- return `Driver "${driverName}".buildCommand returned spec.env that is not a plain object`;
367
- }
368
- for (const [k, v] of Object.entries(s.env)) {
369
- if (typeof v !== 'string') {
370
- return `Driver "${driverName}".buildCommand returned spec.env.${k} of type ${typeof v}, expected string`;
371
- }
372
- }
373
- }
374
- return null;
375
- }
376
- export async function runSpawn(spec, driver, opts = {}) {
377
- const { timeoutMs, signal } = opts;
378
- const start = performance.now();
379
- const elapsed = () => Math.round(performance.now() - start);
380
- if (signal?.aborted) {
381
- return failResult('Pipeline aborted before spawn', 0);
382
- }
383
- // R2: validate the spec before touching it. A third-party driver that
384
- // returns a malformed SpawnSpec used to crash deep inside Bun.spawn with
385
- // an opaque TypeError; now we report a clear "Driver X returned …" message.
386
- const validationError = validateSpawnSpec(spec, driver?.name ?? '<unknown>');
387
- if (validationError !== null) {
388
- return failResult(validationError, elapsed());
389
- }
390
- const mergedEnv = { ...process.env, ...(spec.env ?? {}) };
391
- const resolvedArgs = resolveWindowsExe(spec.args, mergedEnv.PATH ?? process.env.PATH ?? '');
392
- // ── 1. Spawn (catch ENOENT / bad-cwd up front) ────────────────────────
393
- let proc;
394
- try {
395
- proc = Bun.spawn(resolvedArgs, {
396
- cwd: spec.cwd,
397
- env: mergedEnv,
398
- stdout: 'pipe',
399
- stderr: 'pipe',
400
- stdin: spec.stdin ? 'pipe' : undefined,
401
- });
402
- }
403
- catch (err) {
404
- return failResult(String(err), elapsed());
405
- }
406
- // ── 2. Write stdin ─────────────────────────────────────────────────────
407
- // Child may exit before reading (e.g. quick-fail commands that don't
408
- // touch stdin) → swallow EPIPE rather than surfacing it as an
409
- // engine-level error.
410
- if (spec.stdin && proc.stdin && typeof proc.stdin !== 'number') {
411
- try {
412
- await proc.stdin.write(spec.stdin);
413
- await proc.stdin.end();
414
- }
415
- catch {
416
- /* ignore EPIPE / closed-pipe errors */
417
- }
418
- }
419
- // ── 3. Timeout & abort handling ────────────────────────────────────────
420
- let killedByUs = false;
421
- let timedOut = false;
422
- let timer = null;
423
- let forceTimer = null;
424
- const killGracefully = () => {
425
- if (killedByUs)
426
- return;
427
- killedByUs = true;
428
- if (process.platform === 'win32') {
429
- // On Windows, kill the entire process tree via taskkill. This handles
430
- // .cmd wrappers and nested child processes that proc.kill() misses.
431
- killProcessTree(proc.pid);
432
- }
433
- else {
434
- proc.kill('SIGTERM');
435
- // If the child ignores SIGTERM, escalate to SIGKILL after 3 s.
436
- forceTimer = setTimeout(() => {
437
- try {
438
- proc.kill('SIGKILL');
439
- }
440
- catch {
441
- /* already exited */
442
- }
443
- }, SIGKILL_DELAY_MS);
444
- }
445
- };
446
- if (timeoutMs && timeoutMs > 0) {
447
- timer = setTimeout(() => {
448
- timedOut = true;
449
- killGracefully();
450
- }, timeoutMs);
451
- }
452
- const onAbort = () => killGracefully();
453
- if (signal) {
454
- if (signal.aborted) {
455
- killGracefully();
456
- }
457
- else {
458
- signal.addEventListener('abort', onAbort, { once: true });
459
- }
460
- }
461
- // ── 4. Collect output & wait ──────────────────────────────────────────
462
- // Both streams are drained concurrently with `proc.exited` to avoid the
463
- // classic pipe-buffer deadlock (child blocks on a full stdout pipe, parent
464
- // is blocked waiting on exit which the child can't reach). Each stream is
465
- // persisted to disk via `collectStream` as it arrives so we never hold the
466
- // full output in memory — only the bounded tail.
467
- const stdoutStream = typeof proc.stdout === 'object' ? proc.stdout : undefined;
468
- const stderrStream = typeof proc.stderr === 'object' ? proc.stderr : undefined;
469
- const stdoutCap = opts.maxStdoutTailBytes ?? DEFAULT_STDOUT_TAIL_BYTES;
470
- const stderrCap = opts.maxStderrTailBytes ?? DEFAULT_STDERR_TAIL_BYTES;
471
- const [exitCode, stdoutResult, stderrResult] = await Promise.all([
472
- proc.exited,
473
- collectStream(stdoutStream, opts.stdoutPath, stdoutCap),
474
- collectStream(stderrStream, opts.stderrPath, stderrCap),
475
- ]);
476
- const stdout = stdoutResult.text;
477
- const stderr = stderrResult.text;
478
- const stdoutPath = stdoutResult.path;
479
- const stderrPath = stderrResult.path;
480
- const stdoutBytes = stdoutResult.totalBytes;
481
- const stderrBytes = stderrResult.totalBytes;
482
- // ── 5. Cleanup timers & listeners ──────────────────────────────────────
483
- if (timer)
484
- clearTimeout(timer);
485
- if (forceTimer)
486
- clearTimeout(forceTimer);
487
- if (signal)
488
- signal.removeEventListener('abort', onAbort);
489
- const durationMs = elapsed();
490
- // We initiated the kill (timeout or abort) — always treat as non-success
491
- // regardless of exit code. A process that catches SIGTERM and exits 0 still
492
- // hit the timeout; letting it pass as success would unblock downstream tasks
493
- // incorrectly. The `timedOut` flag guards against the narrow race where the
494
- // process exits naturally at the exact moment the timeout fires — even if
495
- // killedByUs wasn't set in time, the timeout intention still applies.
496
- if (killedByUs || timedOut) {
497
- return {
498
- exitCode: -1,
499
- stdout,
500
- stderr,
501
- stdoutPath,
502
- stderrPath,
503
- stdoutBytes,
504
- stderrBytes,
505
- durationMs,
506
- sessionId: null,
507
- normalizedOutput: null,
508
- // H2: explicit kind so engine.ts no longer has to guess "is exitCode -1
509
- // a timeout or a spawn-failure?" Both used to share the same code.
510
- failureKind: 'timeout',
511
- };
512
- }
513
- // ── 6. Let driver extract metadata ─────────────────────────────────────
514
- // R1: parseResult is third-party code — wrap it in try/catch so a buggy
515
- // extractor doesn't discard a perfectly good spawn result. R5: even on
516
- // success, type-guard sessionId/normalizedOutput so a mistyped return
517
- // value doesn't poison sessionMap/normalizedMap downstream.
518
- let sessionId = null;
519
- let normalizedOutput = null;
520
- // M12: drivers can flip a task's terminal status to failed even when the
521
- // process exited 0 (e.g. opencode returning `{type:"error"}` JSON). When
522
- // the flag is set, we synthesize a non-zero exit code and append a reason
523
- // line to stderr so engine.ts marks the task as failed with a useful
524
- // explanation instead of letting the error JSON pass through as success.
525
- let forcedFailureMessage = null;
526
- if (driver?.parseResult) {
527
- try {
528
- const meta = driver.parseResult(stdout, stderr);
529
- if (meta && typeof meta === 'object') {
530
- if (typeof meta.sessionId === 'string' && /^[\w.-]{1,256}$/.test(meta.sessionId)) {
531
- sessionId = meta.sessionId;
532
- }
533
- if (typeof meta.normalizedOutput === 'string') {
534
- normalizedOutput = meta.normalizedOutput;
535
- }
536
- if (meta.forceFailure === true) {
537
- forcedFailureMessage =
538
- typeof meta.forceFailureReason === 'string'
539
- ? meta.forceFailureReason
540
- : 'Driver flagged task as failed (forceFailure)';
541
- }
542
- }
543
- }
544
- catch (err) {
545
- // The spawn itself succeeded; only metadata extraction failed.
546
- // Fall through with sessionId/normalizedOutput = null and append a
547
- // breadcrumb to stderr so the user can see WHY continue_from broke.
548
- const msg = err instanceof Error ? err.message : String(err);
549
- const note = `\n[runner] driver "${driver.name}".parseResult threw: ${msg}`;
550
- return {
551
- exitCode,
552
- stdout,
553
- stderr: stderr + note,
554
- stdoutPath,
555
- stderrPath,
556
- stdoutBytes,
557
- stderrBytes,
558
- durationMs,
559
- sessionId: null,
560
- normalizedOutput: null,
561
- // H2: parseResult threw — the spawn itself succeeded, so the failure
562
- // is "the process exited but the driver couldn't parse it". Surface
563
- // that as exit_nonzero (when the actual exit was non-zero) or null
564
- // (when the underlying exit was 0 — UI will still mark it failed via
565
- // engine.ts because the result is incomplete).
566
- failureKind: exitCode === 0 ? null : 'exit_nonzero',
567
- };
568
- }
569
- }
570
- // M12: when the driver forced a failure, treat as exit_nonzero with the
571
- // reason appended to stderr so users see WHY the task failed without
572
- // having to dig through driver-specific JSON.
573
- if (forcedFailureMessage !== null) {
574
- return {
575
- exitCode: exitCode === 0 ? 1 : exitCode,
576
- stdout,
577
- stderr: stderr + (stderr.endsWith('\n') ? '' : '\n') + `[driver] ${forcedFailureMessage}`,
578
- stdoutPath,
579
- stderrPath,
580
- stdoutBytes,
581
- stderrBytes,
582
- durationMs,
583
- sessionId,
584
- normalizedOutput,
585
- failureKind: 'exit_nonzero',
586
- };
587
- }
588
- return {
589
- exitCode,
590
- stdout,
591
- stderr,
592
- stdoutPath,
593
- stderrPath,
594
- stdoutBytes,
595
- stderrBytes,
596
- durationMs,
597
- sessionId,
598
- normalizedOutput,
599
- // H2: success vs nonzero exit. Engine uses this to short-circuit the
600
- // timeout branch even if a third-party driver returns -1 by mistake.
601
- failureKind: exitCode === 0 ? null : 'exit_nonzero',
602
- };
603
- }
604
- export async function runCommand(command, cwd, opts = {}) {
605
- const spec = {
606
- args: shellArgs(command),
607
- cwd,
608
- };
609
- return runSpawn(spec, null, opts);
610
- }
1
+ export { runCommand, runSpawn } from '@tagma/runtime-bun';
611
2
  //# sourceMappingURL=runner.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,IAAI,EAAmB,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AAE9E,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,+EAA+E;AAC/E,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAE/B;;;;;;;GAOG;AACH,MAAM,yBAAyB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,OAAO;AAC1D,MAAM,yBAAyB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,OAAO;AAE1D;;;;;GAKG;AACH,SAAS,eAAe,CAAC,GAAW;IAClC,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,OAAO;IACzC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,IA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EAAE,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ;YACvC,MAAM;YACN,MAAM,EAAE,MAAM,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,YAAY,oBAAoB,EAAE;YACzF,UAAU;YACV,UAAU;YACV,WAAW;YACX,WAAW;YACX,UAAU;YACV,SAAS;YACT,gBAAgB;YAChB,WAAW,EAAE,cAAc;SAC5B,CAAC;IACJ,CAAC;IACD,OAAO;QACL,QAAQ;QACR,MAAM;QACN,MAAM;QACN,UAAU;QACV,UAAU;QACV,WAAW;QACX,WAAW;QACX,UAAU;QACV,SAAS;QACT,gBAAgB;QAChB,qEAAqE;QACrE,qEAAqE;QACrE,WAAW,EAAE,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc;KACpD,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,OAAe,EACf,GAAW,EACX,OAAmB,EAAE;IAErB,MAAM,IAAI,GAAc;QACtB,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC;QACxB,GAAG;KACJ,CAAC;IACF,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC"}
1
+ {"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from '@tagma/runtime-bun/adapters/stdin-approval';
2
+ //# sourceMappingURL=stdin-approval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stdin-approval.d.ts","sourceRoot":"","sources":["../../../src/runtime/adapters/stdin-approval.ts"],"names":[],"mappings":"AAAA,cAAc,4CAA4C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from '@tagma/runtime-bun/adapters/stdin-approval';
2
+ //# sourceMappingURL=stdin-approval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stdin-approval.js","sourceRoot":"","sources":["../../../src/runtime/adapters/stdin-approval.ts"],"names":[],"mappings":"AAAA,cAAc,4CAA4C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from '@tagma/runtime-bun/adapters/websocket-approval';
2
+ //# sourceMappingURL=websocket-approval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-approval.d.ts","sourceRoot":"","sources":["../../../src/runtime/adapters/websocket-approval.ts"],"names":[],"mappings":"AAAA,cAAc,gDAAgD,CAAC"}