pi-goosedump 0.12.68 → 0.12.69

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 (2) hide show
  1. package/dist/index.ts +59 -11
  2. package/package.json +2 -2
package/dist/index.ts CHANGED
@@ -7,7 +7,7 @@ import { randomUUID as randomUUID2 } from "node:crypto";
7
7
  // src/cli.ts
8
8
  import { Type as Type2 } from "typebox";
9
9
  import { Value as Value2 } from "typebox/value";
10
- import { execFile } from "node:child_process";
10
+ import { spawn } from "node:child_process";
11
11
  import { accessSync, constants as fsConstants, existsSync, readFileSync as readFileSync2, statSync } from "node:fs";
12
12
  import { createRequire } from "node:module";
13
13
  import { dirname, isAbsolute, join } from "node:path";
@@ -513,18 +513,66 @@ function resolveNativeGoosedumpBinary(environment = process.env) {
513
513
  }
514
514
  }
515
515
  function runGoosedumpAsync(args, signal, executablePath = resolveNativeGoosedumpBinary()) {
516
+ if (signal?.aborted)
517
+ return Promise.reject(signal.reason);
516
518
  return new Promise((resolve, reject) => {
517
- execFile(executablePath, args, {
518
- encoding: "utf-8",
519
- maxBuffer: 16 * 1024 * 1024,
520
- signal,
521
- ...process.platform === "linux" ? { env: { ...process.env, APPIMAGE_EXTRACT_AND_RUN: "1" } } : {}
522
- }, (err, stdout, stderr) => {
523
- if (err) {
524
- const message = stderr.trim() || err.message;
525
- reject(new Error(message));
519
+ const processGroup = process.platform !== "win32";
520
+ const output = { stdout: "", stderr: "" };
521
+ const bytes = { stdout: 0, stderr: 0 };
522
+ let child;
523
+ let failure;
524
+ const abort = () => {
525
+ if (child?.pid === undefined)
526
+ return;
527
+ try {
528
+ if (processGroup)
529
+ process.kill(-child.pid, "SIGTERM");
530
+ else
531
+ child.kill("SIGTERM");
532
+ } catch (error) {
533
+ if (error.code !== "ESRCH") {
534
+ failure = new Error("failed to stop goosedump process", { cause: error });
535
+ }
536
+ }
537
+ };
538
+ const capture = (stream, chunk) => {
539
+ if (failure)
540
+ return;
541
+ bytes[stream] += Buffer.byteLength(chunk);
542
+ if (bytes[stream] > 16 * 1024 * 1024) {
543
+ failure = new Error(`goosedump ${stream} exceeded the 16 MiB buffer limit`);
544
+ abort();
545
+ } else {
546
+ output[stream] += chunk;
547
+ }
548
+ };
549
+ signal?.addEventListener("abort", abort, { once: true });
550
+ try {
551
+ child = spawn(executablePath, args, {
552
+ detached: processGroup,
553
+ signal,
554
+ stdio: ["ignore", "pipe", "pipe"],
555
+ ...process.platform === "linux" ? { env: { ...process.env, APPIMAGE_EXTRACT_AND_RUN: "1" } } : {}
556
+ });
557
+ } catch (error) {
558
+ signal?.removeEventListener("abort", abort);
559
+ reject(error);
560
+ return;
561
+ }
562
+ child.stdout?.setEncoding("utf8");
563
+ child.stderr?.setEncoding("utf8");
564
+ child.stdout?.on("data", (chunk) => capture("stdout", chunk));
565
+ child.stderr?.on("data", (chunk) => capture("stderr", chunk));
566
+ child.on("error", (error) => {
567
+ failure ??= error;
568
+ });
569
+ child.once("close", (code, exitSignal) => {
570
+ signal?.removeEventListener("abort", abort);
571
+ if (failure || code !== 0) {
572
+ const message = output.stderr.trim() || failure?.message || `goosedump exited with ${exitSignal ?? `code ${code}`}`;
573
+ reject(new Error(message, { cause: failure }));
526
574
  } else {
527
- resolve({ stdout, stderr });
575
+ resolve(output);
528
576
  }
529
577
  });
530
578
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-goosedump",
3
- "version": "0.12.68",
3
+ "version": "0.12.69",
4
4
  "description": "Pi extension for goosedump session search, durable memory, session management, and compaction",
5
5
  "keywords": [
6
6
  "compaction",
@@ -37,7 +37,7 @@
37
37
  "ci:test": "npm test"
38
38
  },
39
39
  "dependencies": {
40
- "@jarkkojs/goosedump-api": "^0.12.68"
40
+ "@jarkkojs/goosedump-api": "^0.12.69"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@earendil-works/pi-coding-agent": "^0.84.2",