perchai-cli 2.4.92 → 2.4.93

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 (3) hide show
  1. package/bin/perch +34 -1
  2. package/dist/perch.mjs +831 -808
  3. package/package.json +1 -1
package/bin/perch CHANGED
@@ -1,6 +1,39 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import("../dist/perch.mjs").catch((error) => {
3
+ // Raise V8's old-space ceiling before the app starts. A long agent turn retains
4
+ // the whole turn's state in-heap (messages, tool I/O, the render tree); Node's
5
+ // default old-space limit (~2GB on many machines) aborts the process fatally the
6
+ // moment it is crossed, losing the session mid-work. We re-exec once with more
7
+ // headroom unless the user pinned their own limit via NODE_OPTIONS. Dynamic
8
+ // imports + an async IIFE keep this working whether Node loads the file as ESM or
9
+ // CJS. If the re-exec cannot run for any reason, we fall through and start
10
+ // in-process rather than fail to launch.
11
+ (async () => {
12
+ const raised =
13
+ process.env.PERCH_CLI_HEAP_REEXEC === "1" ||
14
+ /--max[-_]old[-_]space[-_]size/.test(process.env.NODE_OPTIONS ?? "");
15
+ if (!raised) {
16
+ const desiredMb = Number(process.env.PERCH_CLI_MAX_OLD_SPACE_MB || 4096);
17
+ if (Number.isFinite(desiredMb) && desiredMb > 0) {
18
+ try {
19
+ const { spawnSync } = await import("node:child_process");
20
+ const result = spawnSync(
21
+ process.execPath,
22
+ [`--max-old-space-size=${desiredMb}`, ...process.argv.slice(1)],
23
+ { stdio: "inherit", env: { ...process.env, PERCH_CLI_HEAP_REEXEC: "1" } },
24
+ );
25
+ if (!result.error) {
26
+ process.exit(result.status == null ? 1 : result.status);
27
+ }
28
+ // spawn failed: fall through and run in this process without the bump.
29
+ console.error(result.error);
30
+ } catch (error) {
31
+ console.error(error);
32
+ }
33
+ }
34
+ }
35
+ await import("../dist/perch.mjs");
36
+ })().catch((error) => {
4
37
  console.error(error);
5
38
  process.exitCode = 1;
6
39
  });