@tangle-network/sdk-cli-runner 0.3.16 → 0.3.18

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.
package/dist/index.d.mts CHANGED
@@ -343,7 +343,8 @@ interface HeldSpareLetFinish {
343
343
  /**
344
344
  * How long before the discard the lock it found was last written. One
345
345
  * written before the spare started is not the spare's: it was cloned into
346
- * this HOME with a snapshot, or an earlier process left it.
346
+ * this HOME with a snapshot, or an earlier process left it. Undefined for
347
+ * a spare not shown frozen, and for a lock that could not be read.
347
348
  */
348
349
  readonly lockAgeMs: number | undefined;
349
350
  readonly spareAgeMs: number;
@@ -433,6 +434,8 @@ type RawCaptureAttempt = {
433
434
  declare function withRawCaptureAttempt<T>(attempt: RawCaptureAttempt, run: () => Promise<T>): Promise<T>;
434
435
  /** The sidecar owns this directory; the CLI's writable HOME cannot contain its evidence. */
435
436
  declare function resolveRawCapturePath(runtimeHome: string): string;
437
+ /** Prepare root-owned executor state without opening or enabling an evidence spool. */
438
+ declare function ensureRawCaptureDirectory(runtimeHome: string): string;
436
439
  /**
437
440
  * Opt one runtime HOME in to full capture, inside the shared byte budget, when
438
441
  * the platform default is off. The Sidecar calls this for a session created with retention
@@ -647,5 +650,5 @@ declare function mergeSpawnEnv(base: NodeJS.ProcessEnv, overrides: Record<string
647
650
  */
648
651
  declare function createStreamParser<T>(config: StreamParserConfig<T>): StreamParser<T>;
649
652
  //#endregion
650
- export { BridgeClosedError, type CliExecOptions, type CliExecResult, type CliExitResult, type CliLaunch, type CliLaunchSpec, type CliLauncher, type CliProcess, type CliSpawnConfig, type CliStdinValue, HELD_SPARE_IDLE_MS, type HeldSpare, type HeldSpareLetFinish, type HeldSpareRegistry, InvalidAttachmentError, JsonRpcError, RAW_CAPTURE_ROOT, RAW_CAPTURE_TOTAL_CAP_BYTES, type RawCaptureProcess, type RpcBridge, type RpcBridgeConfig, type RpcCloseReason, type RpcNotificationHandler, type RpcRequestHandler, type RpcRequestOptions, RpcRequestTimeoutError, type StreamParserConfig, allowRetainedRawCapture, argAfter, configurePrivilegeDrop, createDeferredParser, createHeldSpareRegistry, createStreamParser, execCli, launchCliProcess, launchDifferences, mergeSpawnEnv, openRawCapture, privilegeDropCommand, privilegeDropIdentity, readProcessIdentity, removeRawCapture, resolveRawCapturePath, restoreTurnPriority, shellQuote, spawnCliProcess, spawnRpcBridge, summarizeRawCapture, trimRawCapture, trustedToolPath, withRawCaptureAttempt, yieldUntilAdopted };
653
+ export { BridgeClosedError, type CliExecOptions, type CliExecResult, type CliExitResult, type CliLaunch, type CliLaunchSpec, type CliLauncher, type CliProcess, type CliSpawnConfig, type CliStdinValue, HELD_SPARE_IDLE_MS, type HeldSpare, type HeldSpareLetFinish, type HeldSpareRegistry, InvalidAttachmentError, JsonRpcError, RAW_CAPTURE_ROOT, RAW_CAPTURE_TOTAL_CAP_BYTES, type RawCaptureProcess, type RpcBridge, type RpcBridgeConfig, type RpcCloseReason, type RpcNotificationHandler, type RpcRequestHandler, type RpcRequestOptions, RpcRequestTimeoutError, type StreamParserConfig, allowRetainedRawCapture, argAfter, configurePrivilegeDrop, createDeferredParser, createHeldSpareRegistry, createStreamParser, ensureRawCaptureDirectory, execCli, launchCliProcess, launchDifferences, mergeSpawnEnv, openRawCapture, privilegeDropCommand, privilegeDropIdentity, readProcessIdentity, removeRawCapture, resolveRawCapturePath, restoreTurnPriority, shellQuote, spawnCliProcess, spawnRpcBridge, summarizeRawCapture, trimRawCapture, trustedToolPath, withRawCaptureAttempt, yieldUntilAdopted };
651
654
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -252,7 +252,7 @@ function resolveRawCapturePath(runtimeHome) {
252
252
  if (!isAbsolute(runtimeHome)) throw new Error("runtimeHome must be absolute for raw capture");
253
253
  return join(RAW_ROOT, createHash("sha256").update(resolve(runtimeHome)).digest("hex"), "process-io.frames");
254
254
  }
255
- function assertProtectedCaptureDirectory(directory) {
255
+ function assertProtectedCaptureDirectory(directory, create = false) {
256
256
  if (process.getuid?.() !== 0) throw new Error("sidecar raw capture requires root ownership");
257
257
  for (const part of [
258
258
  "/root",
@@ -260,10 +260,20 @@ function assertProtectedCaptureDirectory(directory) {
260
260
  RAW_ROOT,
261
261
  directory
262
262
  ]) {
263
+ if (create && part !== "/root") mkdirSync(part, {
264
+ recursive: true,
265
+ mode: 448
266
+ });
263
267
  const entry = lstatSync(part);
264
268
  if (!entry.isDirectory() || entry.isSymbolicLink() || entry.uid !== 0 || (entry.mode & 63) !== 0 || realpathSync(part) !== part) throw new Error(`raw capture parent is not protected: ${part}`);
265
269
  }
266
270
  }
271
+ /** Prepare root-owned executor state without opening or enabling an evidence spool. */
272
+ function ensureRawCaptureDirectory(runtimeHome) {
273
+ const directory = dirname(resolveRawCapturePath(runtimeHome));
274
+ assertProtectedCaptureDirectory(directory, true);
275
+ return directory;
276
+ }
267
277
  /**
268
278
  * Opt one runtime HOME in to full capture, inside the shared byte budget, when
269
279
  * the platform default is off. The Sidecar calls this for a session created with retention
@@ -488,7 +498,8 @@ function openRawCapture(file, options) {
488
498
  };
489
499
  if (mode === "none") return disabled;
490
500
  try {
491
- mkdirSync(directory, {
501
+ if (protectedPath) assertProtectedCaptureDirectory(directory, true);
502
+ else mkdirSync(directory, {
492
503
  recursive: true,
493
504
  mode: 448
494
505
  });
@@ -496,7 +507,6 @@ function openRawCapture(file, options) {
496
507
  if (protectedPath && captureCapacityError(error)) return disabled;
497
508
  throw error;
498
509
  }
499
- if (protectedPath) assertProtectedCaptureDirectory(directory);
500
510
  const parent = lstatSync(directory);
501
511
  if (!parent.isDirectory() || parent.isSymbolicLink() || (parent.mode & 63) !== 0) throw new Error("raw capture directory must be a private real directory");
502
512
  const path = resolve(file);
@@ -1628,8 +1638,11 @@ function createDeferredParser() {
1628
1638
  /** How long a spare no turn adopted keeps its process. */
1629
1639
  const HELD_SPARE_IDLE_MS = 12e4;
1630
1640
  /**
1631
- * How long a stopped spare has to exit after SIGTERM before it is killed.
1632
- * Its HOME stays taken, and a turn that waits for it waits, until it exits.
1641
+ * How long a stopped spare has to exit after SIGTERM before the registry
1642
+ * kills it. Its HOME stays taken, and a turn that waits for it waits, until
1643
+ * it exits. A spare launched with its controller's signal is killed sooner:
1644
+ * aborting the controller starts the runner's own escalation, 1 s
1645
+ * (child-killer.ts), and this timer is the backstop for one that was not.
1633
1646
  */
1634
1647
  const HELD_SPARE_STOP_GRACE_MS = 2e3;
1635
1648
  /** How long a discard waits to see a killed spare exit before it fails. */
@@ -1677,21 +1690,24 @@ function createHeldSpareRegistry(options = {}) {
1677
1690
  return true;
1678
1691
  };
1679
1692
  /**
1680
- * The age of a lock a frozen spare holds, if it holds one. A lock that goes
1681
- * while the spare cannot run is another process's (a tenant's own turn in
1682
- * that HOME, writing); one that stays is taken to be the spare's.
1693
+ * The lock a frozen spare holds, if it holds one: its age, or "unreadable"
1694
+ * for one that cannot be read (taken to be held). A lock that goes while
1695
+ * the spare cannot run is another process's (a tenant's own turn in that
1696
+ * HOME, writing); one that stays is taken to be the spare's.
1683
1697
  */
1684
- const heldLockAgeMs = async (spare) => {
1698
+ const heldLock = async (spare) => {
1685
1699
  const paths = options.locks?.(spare) ?? [];
1686
- const ageMs = () => {
1687
- for (const path of paths) {
1700
+ const look = () => {
1701
+ for (const path of paths) try {
1688
1702
  const lock = statSync(path, { throwIfNoEntry: false });
1689
1703
  if (lock) return Date.now() - lock.mtimeMs;
1704
+ } catch {
1705
+ return "unreadable";
1690
1706
  }
1691
1707
  };
1692
1708
  const until = performance.now() + HELD_SPARE_LOCK_SETTLE_MS;
1693
- for (let age = ageMs(); age !== void 0; age = ageMs()) {
1694
- if (performance.now() >= until) return age;
1709
+ for (let lock = look(); lock !== void 0; lock = look()) {
1710
+ if (performance.now() >= until) return lock;
1695
1711
  await setTimeout$1(HELD_SPARE_LOCK_POLL_MS);
1696
1712
  }
1697
1713
  };
@@ -1709,9 +1725,9 @@ function createHeldSpareRegistry(options = {}) {
1709
1725
  const discardOne = async (spare) => {
1710
1726
  const running = retire(spare);
1711
1727
  const frozen = options.locks === void 0 || await freeze(spare);
1712
- const lockAgeMs = frozen ? await heldLockAgeMs(spare) : void 0;
1728
+ const lock = frozen ? await heldLock(spare) : void 0;
1713
1729
  if (running) spare.controller.abort();
1714
- if (frozen && lockAgeMs === void 0) {
1730
+ if (frozen && lock === void 0) {
1715
1731
  spare.process.kill("SIGKILL");
1716
1732
  return { boundMs: HELD_SPARE_EXIT_BOUND_MS };
1717
1733
  }
@@ -1722,7 +1738,7 @@ function createHeldSpareRegistry(options = {}) {
1722
1738
  letFinish: {
1723
1739
  home: spare.home,
1724
1740
  frozen,
1725
- lockAgeMs,
1741
+ lockAgeMs: typeof lock === "number" ? lock : void 0,
1726
1742
  spareAgeMs: performance.now() - spare.startedAt
1727
1743
  }
1728
1744
  };
@@ -2591,6 +2607,6 @@ function shellQuote(value) {
2591
2607
  return `'${value.replace(/'/g, `'"'"'`)}'`;
2592
2608
  }
2593
2609
  //#endregion
2594
- export { BridgeClosedError, HELD_SPARE_IDLE_MS, InvalidAttachmentError, JsonRpcError, RAW_CAPTURE_ROOT, RAW_CAPTURE_TOTAL_CAP_BYTES, RpcRequestTimeoutError, allowRetainedRawCapture, argAfter, configurePrivilegeDrop, createDeferredParser, createHeldSpareRegistry, createStreamParser, execCli, launchCliProcess, launchDifferences, mergeSpawnEnv, openRawCapture, privilegeDropCommand, privilegeDropIdentity, readProcessIdentity, removeRawCapture, resolveRawCapturePath, restoreTurnPriority, shellQuote, spawnCliProcess, spawnRpcBridge, summarizeRawCapture, trimRawCapture, trustedToolPath, withRawCaptureAttempt, yieldUntilAdopted };
2610
+ export { BridgeClosedError, HELD_SPARE_IDLE_MS, InvalidAttachmentError, JsonRpcError, RAW_CAPTURE_ROOT, RAW_CAPTURE_TOTAL_CAP_BYTES, RpcRequestTimeoutError, allowRetainedRawCapture, argAfter, configurePrivilegeDrop, createDeferredParser, createHeldSpareRegistry, createStreamParser, ensureRawCaptureDirectory, execCli, launchCliProcess, launchDifferences, mergeSpawnEnv, openRawCapture, privilegeDropCommand, privilegeDropIdentity, readProcessIdentity, removeRawCapture, resolveRawCapturePath, restoreTurnPriority, shellQuote, spawnCliProcess, spawnRpcBridge, summarizeRawCapture, trimRawCapture, trustedToolPath, withRawCaptureAttempt, yieldUntilAdopted };
2595
2611
 
2596
2612
  //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/sdk-cli-runner",
3
- "version": "0.3.16",
3
+ "version": "0.3.18",
4
4
  "description": "Generic CLI process spawning with stdin/stdout streaming and JSONL parsing",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
@@ -26,8 +26,8 @@
26
26
  "registry": "https://registry.npmjs.org"
27
27
  },
28
28
  "tangleRelease": {
29
- "sourceSha": "ab69b47e583110faa55b91d66c6ccc24c69cc105",
30
- "mergedAt": "2026-11-22T22:13:55-08:00"
29
+ "sourceSha": "57453ab6787f82ae4359215373fc5dd0070d8aa9",
30
+ "mergedAt": "2026-11-24T01:40:28-08:00"
31
31
  },
32
32
  "scripts": {
33
33
  "build": "tsdown",