@morty-build/cli 0.4.13 → 0.4.14

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 (35) hide show
  1. package/dist/{chunk-LZZG3QZL.js → chunk-LX4JLVDZ.js} +124 -50
  2. package/dist/{chunk-LZZG3QZL.js.map → chunk-LX4JLVDZ.js.map} +4 -4
  3. package/dist/{chunk-SPF6MCPU.js → chunk-VQQB6Z6M.js} +2 -2
  4. package/dist/{chunk-SPF6MCPU.js.map → chunk-VQQB6Z6M.js.map} +1 -1
  5. package/dist/{cli-4X34ILGE.js → cli-G2QTUF4J.js} +3 -3
  6. package/dist/cli.js +2 -2
  7. package/dist/engine/acp/harness/codex/app-server-client.d.ts +1 -1
  8. package/dist/engine/acp/harness/codex/app-server-client.d.ts.map +1 -1
  9. package/dist/engine/acp/harness/codex/app-server-client.js +2 -3
  10. package/dist/engine/acp/harness/codex/app-server-client.js.map +1 -1
  11. package/dist/engine/util/process/executable.d.ts +5 -3
  12. package/dist/engine/util/process/executable.d.ts.map +1 -1
  13. package/dist/engine/util/process/executable.js +22 -30
  14. package/dist/engine/util/process/executable.js.map +1 -1
  15. package/dist/engine/util/process/platform/contracts.d.ts +16 -1
  16. package/dist/engine/util/process/platform/contracts.d.ts.map +1 -1
  17. package/dist/engine/util/process/platform/index.d.ts.map +1 -1
  18. package/dist/engine/util/process/platform/index.js +2 -2
  19. package/dist/engine/util/process/platform/index.js.map +1 -1
  20. package/dist/engine/util/process/platform/linux.d.ts.map +1 -1
  21. package/dist/engine/util/process/platform/linux.js +2 -2
  22. package/dist/engine/util/process/platform/linux.js.map +1 -1
  23. package/dist/engine/util/process/platform/macos.d.ts.map +1 -1
  24. package/dist/engine/util/process/platform/macos.js +2 -2
  25. package/dist/engine/util/process/platform/macos.js.map +1 -1
  26. package/dist/engine/util/process/platform/posix.d.ts +2 -2
  27. package/dist/engine/util/process/platform/posix.d.ts.map +1 -1
  28. package/dist/engine/util/process/platform/posix.js +34 -1
  29. package/dist/engine/util/process/platform/posix.js.map +1 -1
  30. package/dist/engine/util/process/platform/windows.d.ts.map +1 -1
  31. package/dist/engine/util/process/platform/windows.js +70 -5
  32. package/dist/engine/util/process/platform/windows.js.map +1 -1
  33. package/dist/engine.js +2 -2
  34. package/package.json +1 -1
  35. /package/dist/{cli-4X34ILGE.js.map → cli-G2QTUF4J.js.map} +0 -0
@@ -3,7 +3,7 @@ import {
3
3
  __export,
4
4
  __using,
5
5
  package_default
6
- } from "./chunk-SPF6MCPU.js";
6
+ } from "./chunk-VQQB6Z6M.js";
7
7
 
8
8
  // src/engine/runtime/relay/runtime-revocation.ts
9
9
  var runtimeRevocationCloseCode = 1008;
@@ -71284,6 +71284,33 @@ function readProcessTableWithPs(executable) {
71284
71284
  );
71285
71285
  });
71286
71286
  }
71287
+ function selectPosixProcessTree(entries, rootProcessId) {
71288
+ const processIds = /* @__PURE__ */ new Set([rootProcessId]);
71289
+ for (const entry of entries) {
71290
+ if (entry.processGroupId === rootProcessId) {
71291
+ processIds.add(entry.processId);
71292
+ }
71293
+ }
71294
+ let previousSize = 0;
71295
+ while (previousSize !== processIds.size) {
71296
+ previousSize = processIds.size;
71297
+ for (const entry of entries) {
71298
+ if (processIds.has(entry.parentProcessId)) {
71299
+ processIds.add(entry.processId);
71300
+ }
71301
+ }
71302
+ }
71303
+ return entries.filter((entry) => processIds.has(entry.processId)).map((entry) => ({
71304
+ processGroupId: entry.processGroupId,
71305
+ processId: entry.processId
71306
+ }));
71307
+ }
71308
+ function posixProcessTreeCapture(readSynchronously, read) {
71309
+ return async (root) => {
71310
+ const entries = readSynchronously();
71311
+ return selectPosixProcessTree(entries.length > 0 ? entries : await read(), root.processId);
71312
+ };
71313
+ }
71287
71314
  function processExists(processId) {
71288
71315
  try {
71289
71316
  process.kill(processId, 0);
@@ -71445,7 +71472,7 @@ function processExists2(processId) {
71445
71472
  var linuxProcessPlatform = {
71446
71473
  ...posixOperations2,
71447
71474
  readProcessTable: readLinuxProcessTableWithFallback,
71448
- readProcessTableSynchronously: readLinuxProcessTableSynchronously,
71475
+ captureProcessTree: posixProcessTreeCapture(readLinuxProcessTableSynchronously, readLinuxProcessTableWithFallback),
71449
71476
  processExists: processExists2
71450
71477
  };
71451
71478
 
@@ -71453,7 +71480,10 @@ var linuxProcessPlatform = {
71453
71480
  var macosProcessPlatform = {
71454
71481
  ...posixOperations2,
71455
71482
  readProcessTable: () => readProcessTableWithPs("/bin/ps"),
71456
- readProcessTableSynchronously: () => [],
71483
+ captureProcessTree: posixProcessTreeCapture(
71484
+ () => [],
71485
+ () => readProcessTableWithPs("/bin/ps")
71486
+ ),
71457
71487
  processExists
71458
71488
  };
71459
71489
 
@@ -71532,7 +71562,24 @@ function executableLaunch(command2, args) {
71532
71562
  }
71533
71563
  return { command: command2, arguments: args };
71534
71564
  }
71535
- function readProcessTable() {
71565
+ function parseWindowsProcesses(output2) {
71566
+ const processes = [];
71567
+ for (const line of output2.split("\n")) {
71568
+ const groups = /^\s*(?<pid>\d+)\s+(?<ppid>\d+)\s+(?<created>\d+)\s*$/.exec(line)?.groups;
71569
+ if (groups === void 0) {
71570
+ continue;
71571
+ }
71572
+ const processId = Number(groups["pid"]);
71573
+ const parentProcessId = Number(groups["ppid"]);
71574
+ const createdAt = Number(groups["created"]);
71575
+ if (!Number.isSafeInteger(processId) || processId <= 0 || !Number.isSafeInteger(parentProcessId) || parentProcessId < 0 || !Number.isSafeInteger(createdAt)) {
71576
+ continue;
71577
+ }
71578
+ processes.push({ processId, parentProcessId, createdAt });
71579
+ }
71580
+ return processes;
71581
+ }
71582
+ function readWindowsProcesses() {
71536
71583
  const systemRoot = environmentValue2(process.env, "SystemRoot");
71537
71584
  if (systemRoot === void 0) {
71538
71585
  return Promise.resolve([]);
@@ -71545,7 +71592,8 @@ function readProcessTable() {
71545
71592
  "-NoProfile",
71546
71593
  "-NonInteractive",
71547
71594
  "-Command",
71548
- "Get-CimInstance Win32_Process | ForEach-Object { '{0} {1} {0}' -f $_.ProcessId, $_.ParentProcessId }"
71595
+ // Processes without a creation time, such as the System process, are never part of a spawned tree.
71596
+ "Get-CimInstance Win32_Process | Where-Object { $_.CreationDate } | ForEach-Object { '{0} {1} {2}' -f $_.ProcessId, $_.ParentProcessId, ([DateTimeOffset]$_.CreationDate.ToUniversalTime()).ToUnixTimeMilliseconds() }"
71549
71597
  ],
71550
71598
  {
71551
71599
  encoding: "utf8",
@@ -71554,10 +71602,44 @@ function readProcessTable() {
71554
71602
  signal: AbortSignal.timeout(1e4),
71555
71603
  maxBuffer: 1024 * 1024
71556
71604
  },
71557
- (error62, stdout) => resolveTable(error62 === null ? parseProcessTable(stdout) : [])
71605
+ (error62, stdout) => resolveTable(error62 === null ? parseWindowsProcesses(stdout) : [])
71558
71606
  );
71559
71607
  });
71560
71608
  }
71609
+ async function readProcessTable() {
71610
+ return (await readWindowsProcesses()).map(({ processId, parentProcessId }) => ({
71611
+ processId,
71612
+ parentProcessId,
71613
+ processGroupId: processId
71614
+ }));
71615
+ }
71616
+ function selectWindowsProcessTree(processes, root) {
71617
+ const running = new Map(processes.map((entry) => [entry.processId, entry]));
71618
+ const members2 = /* @__PURE__ */ new Set();
71619
+ if (root.state === "running" && running.has(root.processId)) {
71620
+ members2.add(root.processId);
71621
+ }
71622
+ const belongsToTree = (entry) => {
71623
+ const parent = running.get(entry.parentProcessId);
71624
+ if (parent !== void 0 && parent.createdAt <= entry.createdAt) {
71625
+ return members2.has(parent.processId);
71626
+ }
71627
+ return root.state === "exited" && entry.parentProcessId === root.processId && root.spawnedAt <= entry.createdAt && entry.createdAt <= root.exitedAt;
71628
+ };
71629
+ let previousSize = -1;
71630
+ while (previousSize !== members2.size) {
71631
+ previousSize = members2.size;
71632
+ for (const entry of processes) {
71633
+ if (!members2.has(entry.processId) && belongsToTree(entry)) {
71634
+ members2.add(entry.processId);
71635
+ }
71636
+ }
71637
+ }
71638
+ return [...members2].map((processId) => ({ processGroupId: processId, processId }));
71639
+ }
71640
+ async function captureProcessTree(root) {
71641
+ return selectWindowsProcessTree(await readWindowsProcesses(), root);
71642
+ }
71561
71643
  function signalCapturedProcesses2(processes, _rootProcessId, signal) {
71562
71644
  for (const identity2 of [...processes].reverse()) {
71563
71645
  try {
@@ -71582,7 +71664,7 @@ var windowsProcessPlatform = {
71582
71664
  signalCapturedProcesses: signalCapturedProcesses2,
71583
71665
  terminateProcess: terminateProcess2,
71584
71666
  readProcessTable,
71585
- readProcessTableSynchronously: () => [],
71667
+ captureProcessTree,
71586
71668
  processExists
71587
71669
  };
71588
71670
 
@@ -71590,7 +71672,10 @@ var windowsProcessPlatform = {
71590
71672
  var fallbackPlatform2 = {
71591
71673
  ...posixOperations2,
71592
71674
  readProcessTable: () => readProcessTableWithPs("/usr/bin/ps"),
71593
- readProcessTableSynchronously: () => [],
71675
+ captureProcessTree: posixProcessTreeCapture(
71676
+ () => [],
71677
+ () => readProcessTableWithPs("/usr/bin/ps")
71678
+ ),
71594
71679
  processExists
71595
71680
  };
71596
71681
  var platforms2 = /* @__PURE__ */ new Map([
@@ -71696,29 +71781,25 @@ function appendBounded(chunks, chunk, currentBytes, limitBytes) {
71696
71781
  chunks.push(chunk);
71697
71782
  return nextBytes;
71698
71783
  }
71699
- function readProcessTable2() {
71700
- return hostPlatform.readProcessTable();
71701
- }
71702
- function selectProcessTree(entries, rootProcessId) {
71703
- const processIds = /* @__PURE__ */ new Set([rootProcessId]);
71704
- for (const entry of entries) {
71705
- if (entry.processGroupId === rootProcessId) {
71706
- processIds.add(entry.processId);
71707
- }
71784
+ var lifetimes = /* @__PURE__ */ new WeakMap();
71785
+ function spawnProcess(command2, args, options) {
71786
+ const spawnedAt = Date.now();
71787
+ const child = spawn3(command2, [...args], options);
71788
+ const processId = child.pid;
71789
+ if (processId !== void 0) {
71790
+ lifetimes.set(child, { state: "running", processId, spawnedAt });
71791
+ child.once("exit", () => {
71792
+ lifetimes.set(child, { state: "exited", processId, spawnedAt, exitedAt: Date.now() });
71793
+ });
71708
71794
  }
71709
- let previousSize = 0;
71710
- while (previousSize !== processIds.size) {
71711
- previousSize = processIds.size;
71712
- for (const entry of entries) {
71713
- if (processIds.has(entry.parentProcessId)) {
71714
- processIds.add(entry.processId);
71715
- }
71716
- }
71795
+ return child;
71796
+ }
71797
+ function spawnedProcess(child) {
71798
+ const lifetime = lifetimes.get(child);
71799
+ if (lifetime === void 0) {
71800
+ throw new Error("Only a child started by spawnProcess has an identifiable process tree");
71717
71801
  }
71718
- return entries.filter((entry) => processIds.has(entry.processId)).map((entry) => ({
71719
- processGroupId: entry.processGroupId,
71720
- processId: entry.processId
71721
- }));
71802
+ return lifetime;
71722
71803
  }
71723
71804
  function mergeProcessTrees(captured, current) {
71724
71805
  const processes = /* @__PURE__ */ new Map();
@@ -71730,15 +71811,11 @@ function mergeProcessTrees(captured, current) {
71730
71811
  }
71731
71812
  return [...processes.values()];
71732
71813
  }
71733
- async function captureProcessTree(child) {
71814
+ async function captureProcessTree2(child) {
71734
71815
  if (child.pid === void 0) {
71735
71816
  return [];
71736
71817
  }
71737
- const entries = hostPlatform.readProcessTableSynchronously();
71738
- if (entries.length > 0) {
71739
- return selectProcessTree(entries, child.pid);
71740
- }
71741
- return selectProcessTree(await readProcessTable2(), child.pid);
71818
+ return await hostPlatform.captureProcessTree(spawnedProcess(child));
71742
71819
  }
71743
71820
  async function waitForCapturedProcessesExit(processes, rootProcessId) {
71744
71821
  const processIds = processes.map((identity2) => identity2.processId).filter((processId) => processId !== rootProcessId);
@@ -71746,7 +71823,7 @@ async function waitForCapturedProcessesExit(processes, rootProcessId) {
71746
71823
  if (processIds.every((processId) => !hostPlatform.processExists(processId))) {
71747
71824
  return true;
71748
71825
  }
71749
- await readProcessTable2();
71826
+ await hostPlatform.readProcessTable();
71750
71827
  }
71751
71828
  return processIds.every((processId) => !hostPlatform.processExists(processId));
71752
71829
  }
@@ -71756,7 +71833,7 @@ async function stopProcessTree(child, capturedProcesses = []) {
71756
71833
  return;
71757
71834
  }
71758
71835
  const childExited = child.exitCode !== null || child.signalCode !== null;
71759
- const processes = mergeProcessTrees(capturedProcesses, await captureProcessTree(child));
71836
+ const processes = mergeProcessTrees(capturedProcesses, await captureProcessTree2(child));
71760
71837
  if (childExited && processes.length === 0) {
71761
71838
  return;
71762
71839
  }
@@ -71806,7 +71883,7 @@ async function runBoundedProcess(options) {
71806
71883
  options.signal.throwIfAborted();
71807
71884
  const outputLimitBytes = options.outputLimitBytes ?? DEFAULT_OUTPUT_LIMIT_BYTES;
71808
71885
  const launch = executableLaunch2(options.command, options.arguments);
71809
- const child = spawn3(launch.command, [...launch.arguments], {
71886
+ const child = spawnProcess(launch.command, launch.arguments, {
71810
71887
  cwd: options.cwd,
71811
71888
  ...hostPlatform.spawnOptions,
71812
71889
  env: { ...options.environment },
@@ -71996,9 +72073,6 @@ var ClaudeCodeAgentSpecification = class extends InProcessAcpAgentSpecification
71996
72073
  };
71997
72074
  };
71998
72075
 
71999
- // src/engine/acp/harness/codex/app-server-client.ts
72000
- import { spawn as spawn4 } from "node:child_process";
72001
-
72002
72076
  // src/engine/acp/harness/codex/app-server-protocol.ts
72003
72077
  import { isAbsolute as isAbsolute8 } from "node:path";
72004
72078
  var boundedText = (maximum) => external_exports.string().max(maximum);
@@ -72331,7 +72405,7 @@ var CodexAppServerClient = class {
72331
72405
  constructor(options) {
72332
72406
  this.#handlers = options.handlers;
72333
72407
  const launch = executableLaunch2(options.command, ["app-server"]);
72334
- this.#child = spawn4(launch.command, [...launch.arguments], {
72408
+ this.#child = spawnProcess(launch.command, launch.arguments, {
72335
72409
  cwd: options.cwd,
72336
72410
  ...platformSpawnOptions,
72337
72411
  env: { ...process.env, ...options.environment },
@@ -72730,12 +72804,12 @@ function presentToolItem(item) {
72730
72804
  };
72731
72805
  }
72732
72806
  if (item.type === "collabAgentToolCall") {
72733
- const spawn6 = item.tool === "spawnAgent";
72807
+ const spawn5 = item.tool === "spawnAgent";
72734
72808
  return {
72735
72809
  content: [],
72736
72810
  kind: "other",
72737
72811
  locations: [],
72738
- rawInput: spawn6 ? {
72812
+ rawInput: spawn5 ? {
72739
72813
  model: item.model,
72740
72814
  prompt: item.prompt,
72741
72815
  reasoningEffort: item.reasoningEffort,
@@ -72743,10 +72817,10 @@ function presentToolItem(item) {
72743
72817
  } : { receiverThreadIds: item.receiverThreadIds, senderThreadId: item.senderThreadId },
72744
72818
  rawOutput: {
72745
72819
  agentsStates: item.agentsStates,
72746
- ...spawn6 ? { receiverThreadIds: item.receiverThreadIds } : {}
72820
+ ...spawn5 ? { receiverThreadIds: item.receiverThreadIds } : {}
72747
72821
  },
72748
72822
  status: collaborationStatus(item.status),
72749
- title: spawn6 ? "Dispatch subagent" : "Wait for subagent"
72823
+ title: spawn5 ? "Dispatch subagent" : "Wait for subagent"
72750
72824
  };
72751
72825
  }
72752
72826
  if (item.type === "subAgentActivity" && item.kind === "started") {
@@ -74929,7 +75003,7 @@ var CodexAcpAgent = class {
74929
75003
  this.#appServer.detach();
74930
75004
  const child = this.#appServer.child();
74931
75005
  try {
74932
- const captured = await captureProcessTree(child);
75006
+ const captured = await captureProcessTree2(child);
74933
75007
  await stopProcessTree(child, captured);
74934
75008
  } finally {
74935
75009
  this.#connection?.close();
@@ -75070,7 +75144,7 @@ import { existsSync as existsSync8, readdirSync as readdirSync6, readFileSync as
75070
75144
  import { basename as basename5, dirname as dirname9, isAbsolute as isAbsolute12, join as join21 } from "node:path";
75071
75145
 
75072
75146
  // src/engine/acp/harness/pi/upstream/dist/pi-rpc/process.js
75073
- import { spawn as spawn5 } from "node:child_process";
75147
+ import { spawn as spawn4 } from "node:child_process";
75074
75148
  import * as readline from "node:readline";
75075
75149
 
75076
75150
  // src/engine/acp/harness/pi/upstream/dist/pi-rpc/command.js
@@ -75187,7 +75261,7 @@ var PiRpcProcess = class _PiRpcProcess {
75187
75261
  args.push("--fork", params.origin.sessionPath);
75188
75262
  break;
75189
75263
  }
75190
- const child = spawn5(cmd, args, {
75264
+ const child = spawn4(cmd, args, {
75191
75265
  cwd: params.cwd,
75192
75266
  stdio: "pipe",
75193
75267
  env: params.environment,
@@ -97907,4 +97981,4 @@ export {
97907
97981
  * MIT Licensed
97908
97982
  *)
97909
97983
  */
97910
- //# sourceMappingURL=chunk-LZZG3QZL.js.map
97984
+ //# sourceMappingURL=chunk-LX4JLVDZ.js.map