pi-better-harness 0.66.0 → 0.66.1

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 (24) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/node_modules/pi-better-background-tasks/package.json +2 -2
  3. package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-arm64.json +1 -1
  4. package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-x64.json +1 -1
  5. package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-arm64.json +1 -1
  6. package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-x64.json +1 -1
  7. package/node_modules/pi-better-background-tasks/runtime-client/artifacts/win32-x64.json +1 -1
  8. package/node_modules/pi-better-background-tasks/runtime-client/src/runtime/client.mjs +53 -6
  9. package/node_modules/pi-better-background-tasks/runtime-client/src/runtime/startup-worker.mjs +10 -0
  10. package/node_modules/pi-better-background-tasks/src/observed-waits.ts +3 -3
  11. package/node_modules/pi-better-background-tasks/src/work-observation.ts +11 -8
  12. package/node_modules/pi-better-subagents/README.md +4 -1
  13. package/node_modules/pi-better-subagents/index.ts +3 -5
  14. package/node_modules/pi-better-subagents/package.json +2 -2
  15. package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-arm64.json +1 -1
  16. package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-x64.json +1 -1
  17. package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-arm64.json +1 -1
  18. package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-x64.json +1 -1
  19. package/node_modules/pi-better-subagents/runtime-client/artifacts/win32-x64.json +1 -1
  20. package/node_modules/pi-better-subagents/runtime-client/src/runtime/client.mjs +53 -6
  21. package/node_modules/pi-better-subagents/runtime-client/src/runtime/startup-worker.mjs +10 -0
  22. package/node_modules/pi-better-subagents/shared-catalog.ts +2 -2
  23. package/node_modules/pi-better-subagents/work-observation.ts +52 -26
  24. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.66.1] - 2026-12-04
4
+
5
+ ### Changed
6
+
7
+ - Pi starts the local task server in the background. You can enter a prompt while the server starts, and the first task reuses the connection.
8
+
3
9
  ## [0.66.0] - 2026-12-04
4
10
 
5
11
  ### Changed
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-background-tasks",
3
- "version": "0.21.19",
3
+ "version": "0.21.20",
4
4
  "description": "Pi extension for durable background shell tasks, watchers, logs, and status inspection.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -70,7 +70,7 @@
70
70
  "vitest": "^3.0.0"
71
71
  },
72
72
  "dependencies": {
73
- "pi-better-server": "0.11.10",
73
+ "pi-better-server": "0.11.11",
74
74
  "proper-lockfile": "^4.1.2"
75
75
  }
76
76
  }
@@ -1 +1 @@
1
- {"build":{"contentId":"06b98bf4e6f1e7d77c53fe8ded1995829309d0c843065993a03575f692ad0640","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"darwin-arm64","protocolVersion":1,"serverVersion":"0.11.10","sourceDigest":"75441154c84cf249c9abc0b836a6f95f424de3e9bbfb617c5938e025d76d78a7"},"sha256":"49bf8c261c1e4c0ca676641e5d1a59e15ee91a8236df4313feb6e83d5d54f5ab"}
1
+ {"build":{"contentId":"7ea53a9ab306acdb807d91d40e390a626649719ab6c3dc68abac89a5bdf0a50b","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"darwin-arm64","protocolVersion":1,"serverVersion":"0.11.11","sourceDigest":"9201868088ad78f5d2c2ded80d7929df5bcbc5e6ce3455c042d80dede4cf384c"},"sha256":"8851a7e15b3082c98017b5d4d6ee11d68e28bab15028100dab71f462c25e939d"}
@@ -1 +1 @@
1
- {"build":{"contentId":"91fac528426cbd0cc8958763e11436b1c23a1080a64ce943f1e0a468b7c99eef","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"darwin-x64","protocolVersion":1,"serverVersion":"0.11.10","sourceDigest":"75441154c84cf249c9abc0b836a6f95f424de3e9bbfb617c5938e025d76d78a7"},"sha256":"f399c112766a7da82899f3e1ec69e074e9b2562c304da5199562c21b8564171a"}
1
+ {"build":{"contentId":"6b8c0f8e8dc0e8857f9b506f9b02e4656a55b906ba8e865d674cfd61ea52ccd4","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"darwin-x64","protocolVersion":1,"serverVersion":"0.11.11","sourceDigest":"9201868088ad78f5d2c2ded80d7929df5bcbc5e6ce3455c042d80dede4cf384c"},"sha256":"db7abb20bd5a0958676bff1bb8237cbfb01bcaa4fc73030656f72ea5b8046307"}
@@ -1 +1 @@
1
- {"build":{"contentId":"d41ad3e6a413ded11bd420200d93e20673e5259a8b7a502a86a529bea996dc03","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"linux-arm64","protocolVersion":1,"serverVersion":"0.11.10","sourceDigest":"75441154c84cf249c9abc0b836a6f95f424de3e9bbfb617c5938e025d76d78a7"},"sha256":"96a4831055f9e95e7b298e10615567cbc19fdf7bf74b4a81784a7611e3c60553"}
1
+ {"build":{"contentId":"41f305a8be6279c9d7772f298faaaa5d13ee5917fc5d594580f4d0020f4319f7","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"linux-arm64","protocolVersion":1,"serverVersion":"0.11.11","sourceDigest":"9201868088ad78f5d2c2ded80d7929df5bcbc5e6ce3455c042d80dede4cf384c"},"sha256":"430e3a1bce7f7f870c17e8da26562e0f77bb4c921ba58c4255418357005c0a29"}
@@ -1 +1 @@
1
- {"build":{"contentId":"d531e6509c6baecc9e109a8f31ed03631eccf62ebc1c812432d316a3b7012c24","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"linux-x64","protocolVersion":1,"serverVersion":"0.11.10","sourceDigest":"75441154c84cf249c9abc0b836a6f95f424de3e9bbfb617c5938e025d76d78a7"},"sha256":"3cff5bafbedc4f1238596216f8c12ddf0f0740ff21262c7409dbc2cf97f03837"}
1
+ {"build":{"contentId":"59d0b5a9267847833cbe977d923b6ba71e01b60b10ab064a924a722a322d4498","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"linux-x64","protocolVersion":1,"serverVersion":"0.11.11","sourceDigest":"9201868088ad78f5d2c2ded80d7929df5bcbc5e6ce3455c042d80dede4cf384c"},"sha256":"d7a9a566e17d45a3122b903d471874dc2131f7ae28eb9b78e182bec3366d7a60"}
@@ -1 +1 @@
1
- {"build":{"contentId":"57cbe0230cf34b955e6b9575fa3ed54b9b2eb5ef58132c1d3f84864d239bfc93","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"win32-x64","protocolVersion":1,"serverVersion":"0.11.10","sourceDigest":"75441154c84cf249c9abc0b836a6f95f424de3e9bbfb617c5938e025d76d78a7"},"sha256":"4e76e369fded7c2c0726bee174d532c9ef540a4d4f8b8d792a988fdf4f74160e"}
1
+ {"build":{"contentId":"25560d031d54c564df55a5d21c7b5831bc26f0a821306e66608875a80691d031","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"win32-x64","protocolVersion":1,"serverVersion":"0.11.11","sourceDigest":"9201868088ad78f5d2c2ded80d7929df5bcbc5e6ce3455c042d80dede4cf384c"},"sha256":"6d6d0dfd2556e5723e03a6b419edb512cdaa254bbb073935ce265a9d6932e1ff"}
@@ -1,5 +1,8 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { closeSync, openSync, readFileSync } from "node:fs";
3
+ import { readFile } from "node:fs/promises";
4
+ import { once } from "node:events";
5
+ import { Worker } from "node:worker_threads";
3
6
  import { createRequire } from "node:module";
4
7
  import { connectRuntimeSocket as connect } from "./windows-native.mjs";
5
8
  import { join } from "node:path";
@@ -13,6 +16,55 @@ import { socketPathFor } from "./socket.mjs";
13
16
  export { WorkClient } from "./work-client.mjs";
14
17
  // End-to-end release support. Building an artifact for a new target does not enable it here.
15
18
  const releasedManagedPlatforms = ["darwin-arm64", "darwin-x64", "linux-arm64", "linux-x64", "win32-x64"];
19
+ function supportedPlatform() {
20
+ const platform = `${process.platform}-${process.arch}`;
21
+ if (!releasedManagedPlatforms.includes(platform)) {
22
+ const tracking = process.platform === "win32" ? " Track native Windows support at https://github.com/1aboveio/pi-better-harness/issues/917" : "";
23
+ throw new Error(`runtime-unavailable: this release does not support managed Subagents and Background Tasks on ${platform}. `
24
+ + `Use a supported host (${releasedManagedPlatforms.join(", ")}).${tracking}`);
25
+ }
26
+ return platform;
27
+ }
28
+ const startupKey = Symbol.for("pi-better-runtime.foreground-starts.v1");
29
+ const starts = globalThis[startupKey] ??= new Map();
30
+ /** Both standalone packages can join the same cold start without staging an archive on Pi's event loop. */
31
+ export async function ensureRuntimeInBackground({ agentDir, serverDir = process.env.PI_SERVER_DIR, timeoutMs, signal }) {
32
+ signal?.throwIfAborted();
33
+ const platform = supportedPlatform();
34
+ if (timeoutMs !== undefined && (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 120000))
35
+ throw new Error("Runtime timeout must be from 1 to 120000 ms");
36
+ const deadline = timeoutMs === undefined ? signal : AbortSignal.any([AbortSignal.timeout(timeoutMs), ...(signal ? [signal] : [])]);
37
+ const pin = await readFile(new URL(`../../artifacts/${platform}.json`, import.meta.url), { encoding: "utf8", signal: deadline });
38
+ deadline?.throwIfAborted();
39
+ const offline = process.env.PI_OFFLINE === "1";
40
+ const key = JSON.stringify([agentDir, pin, offline]);
41
+ let start = starts.get(key);
42
+ if (!start) {
43
+ const worker = new Worker(new URL("./startup-worker.mjs", import.meta.url), {
44
+ execArgv: [], workerData: { client: import.meta.url, options: { agentDir, serverDir, offline, timeoutMs: 120000 } },
45
+ });
46
+ worker.setMaxListeners(0);
47
+ // All waiters can abort before the worker reports a staging error.
48
+ worker.on("error", () => { });
49
+ start = { worker, waiters: 0 };
50
+ starts.set(key, start);
51
+ }
52
+ start.waiters++;
53
+ try {
54
+ const [code] = await once(start.worker, "exit", { signal: deadline });
55
+ if (code !== 0)
56
+ throw new Error(`runtime-unavailable: startup worker exited with code ${code}`);
57
+ }
58
+ finally {
59
+ if (--start.waiters === 0) {
60
+ starts.delete(key);
61
+ if (deadline?.aborted) {
62
+ start.worker.postMessage("abort");
63
+ start.worker.unref();
64
+ }
65
+ }
66
+ }
67
+ }
16
68
  /** One bounded LF-JSON exchange; importing this module never loads the Pi SDK. */
17
69
  export async function runtimeStatus(socketPath, agentDir, artifact, timeoutMs = 2000) {
18
70
  return new Promise((resolve, reject) => {
@@ -64,12 +116,7 @@ export async function ensureRuntime(options) {
64
116
  const timeoutMs = options.timeoutMs ?? 15000;
65
117
  if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 120000)
66
118
  throw new Error("Runtime timeout must be from 1 to 120000 ms");
67
- const platform = `${process.platform}-${process.arch}`;
68
- if (!releasedManagedPlatforms.includes(platform)) {
69
- const tracking = process.platform === "win32" ? " Track native Windows support at https://github.com/1aboveio/pi-better-harness/issues/917" : "";
70
- throw new Error(`runtime-unavailable: this release does not support managed Subagents and Background Tasks on ${platform}. `
71
- + `Use a supported host (${releasedManagedPlatforms.join(", ")}).${tracking}`);
72
- }
119
+ const platform = supportedPlatform();
73
120
  const directory = fileURLToPath(new URL("../../artifacts/", import.meta.url));
74
121
  let artifact;
75
122
  try {
@@ -0,0 +1,10 @@
1
+ import { parentPort, workerData } from "node:worker_threads";
2
+
3
+ const controller = new AbortController();
4
+ parentPort.once("message", () => controller.abort());
5
+ try {
6
+ const { ensureRuntime } = await import(workerData.client);
7
+ await ensureRuntime({ ...workerData.options, signal: controller.signal });
8
+ } finally {
9
+ parentPort.close();
10
+ }
@@ -1720,7 +1720,7 @@ export class ObservedWaitHost {
1720
1720
  const registrationPath = join(root, "server-registration-v1.json");
1721
1721
  if (!existsSync(registrationPath)) {
1722
1722
  const installer = "../runtime-client/src/runtime/client.mjs";
1723
- await (await import(installer)).ensureRuntime({ agentDir: root });
1723
+ await (await import(installer)).ensureRuntimeInBackground({ agentDir: root });
1724
1724
  }
1725
1725
  const registration = JSON.parse(readFileSync(registrationPath, "utf8"));
1726
1726
  if (registration.agentDir !== root || registration.version !== 1) throw new Error("not_accepted: invalid canonical runtime registration");
@@ -2293,8 +2293,8 @@ export class ObservedWaitHost {
2293
2293
  if (!["ENOENT", "ECONNREFUSED"].includes((error as NodeJS.ErrnoException).code ?? "")) throw error;
2294
2294
  // The packaged canonical client owns artifact verification, owner checks and startup.
2295
2295
  // @ts-expect-error Generated by sync-runtime-client during package preparation.
2296
- const { ensureRuntime } = await import("../runtime-client/src/runtime/client.mjs");
2297
- await ensureRuntime({ agentDir: root, serverDir: process.env.PI_SERVER_DIR });
2296
+ const { ensureRuntimeInBackground } = await import("../runtime-client/src/runtime/client.mjs");
2297
+ await ensureRuntimeInBackground({ agentDir: root, serverDir: process.env.PI_SERVER_DIR });
2298
2298
  client = await connect();
2299
2299
  }
2300
2300
  return client;
@@ -1,6 +1,6 @@
1
1
  import { socketPathFor } from "./shared-work-client.mjs";
2
2
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
3
- import { mkdirSync, readFileSync, realpathSync } from "node:fs";
3
+ import { mkdir, readFile, realpath } from "node:fs/promises";
4
4
  import { join } from "node:path";
5
5
  import { homedir } from "node:os";
6
6
  import { setTimeout as delay } from "node:timers/promises";
@@ -93,19 +93,19 @@ function observationClient(pi: ExtensionAPI, scope: { background: boolean; cwd:
93
93
  catch (error) { hosted.close(); throw error; }
94
94
  }
95
95
  const requestedRoot = process.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent");
96
- mkdirSync(requestedRoot, { recursive: true, mode: 0o700 });
97
- const root = realpathSync(requestedRoot);
96
+ await mkdir(requestedRoot, { recursive: true, mode: 0o700 });
97
+ const root = await realpath(requestedRoot);
98
98
  const ensure = async (timeoutMs?: number, signal?: AbortSignal) => {
99
99
  const installer = new URL("../runtime-client/src/runtime/client.mjs", import.meta.url).href;
100
- const { ensureRuntime } = await import(installer);
101
- await ensureRuntime({ agentDir: root, serverDir: process.env.PI_SERVER_DIR, timeoutMs, signal });
100
+ const { ensureRuntimeInBackground } = await import(installer);
101
+ await ensureRuntimeInBackground({ agentDir: root, serverDir: process.env.PI_SERVER_DIR, timeoutMs, signal });
102
102
  };
103
103
  let registration;
104
- try { registration = JSON.parse(readFileSync(join(root, "server-registration-v1.json"), "utf8")); }
104
+ try { registration = JSON.parse(await readFile(join(root, "server-registration-v1.json"), { encoding: "utf8", signal: controller.signal })); }
105
105
  catch (error) {
106
106
  if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
107
107
  await ensure(undefined, controller.signal);
108
- registration = JSON.parse(readFileSync(join(root, "server-registration-v1.json"), "utf8"));
108
+ registration = JSON.parse(await readFile(join(root, "server-registration-v1.json"), { encoding: "utf8", signal: controller.signal }));
109
109
  }
110
110
  if (registration.version !== 1 || registration.agentDir !== root) throw new Error("Invalid canonical runtime registration");
111
111
  const module = new URL("./shared-work-client.mjs", import.meta.url).href;
@@ -129,7 +129,10 @@ function observationClient(pi: ExtensionAPI, scope: { background: boolean; cwd:
129
129
  return client;
130
130
  };
131
131
  return connect();
132
- })();
132
+ })().catch(error => {
133
+ checkOpen();
134
+ throw error;
135
+ });
133
136
  clients.set(pi, pending);
134
137
  pending.catch(() => { if (clients.get(pi) === pending) clients.delete(pi); });
135
138
  }
@@ -12,7 +12,10 @@ Run `pi-subagents-runtime-status` to ensure the manifest-pinned local server and
12
12
  print its canonical agent root, build, Node version, instance and capabilities as JSON.
13
13
  This command does not create a hosted Pi session or require Harness.
14
14
  The package pins its `pi-better-server` dependency and verifies the shared runtime archive against its own manifest.
15
- The first use installs a verified private Node 24 and locked server dependencies.
15
+ When Pi starts a foreground session, Subagents connects to the server in the background.
16
+ On a cold start, a worker verifies the archive and installs the private Node 24 runtime and locked server dependencies.
17
+ Pi can accept input during startup. A task requested before the server is ready waits for that same startup.
18
+ A fresh session subscribes to task updates when a tool, assignment or Navigator needs them.
16
19
  Set `PI_OFFLINE=1` to require the cached runtime without downloads.
17
20
  `PI_CODING_AGENT_DIR` selects the agent root; `PI_SERVER_DIR` selects the initial
18
21
  transport directory. Later calls for the same canonical root reuse the registered
@@ -29,7 +29,7 @@ import * as PiCodingAgent from "@earendil-works/pi-coding-agent";
29
29
  import * as PiTui from "@earendil-works/pi-tui";
30
30
  import { CustomEditor } from "@earendil-works/pi-coding-agent";
31
31
  import { initializeNavigatorPanels } from "./shared-navigator-panels.ts";
32
- import { workObservation, workObservationStarted, workObservationFailure, configureWorkObservation, activateWorkObservation, stopWorkObservation, observedAssignment, observedList, requestWorkDetail, TERMINAL_NAVIGATOR_RETENTION_MS } from "./work-observation.ts";
32
+ import { workObservation, workObservationStarted, workObservationFailure, configureWorkObservation, warmWorkRuntime, activateWorkObservation, stopWorkObservation, observedAssignment, observedList, requestWorkDetail, TERMINAL_NAVIGATOR_RETENTION_MS } from "./work-observation.ts";
33
33
  import { withAssignmentObservations } from "./assignment-projection.mjs";
34
34
  import { formatNavigatorHealthFacts } from "./health-surface.mjs";
35
35
  import { matchesKey, Key, truncateToWidth, type AutocompleteItem } from "@earendil-works/pi-tui";
@@ -4816,12 +4816,10 @@ function installSubagents(pi: ExtensionAPI, managed?: import("./managed-launch-p
4816
4816
  refreshBackgroundWorkNavigator(ctx);
4817
4817
  observeRecipientNotifications(pi);
4818
4818
  });
4819
- if (!event?.reason) {
4820
- // Older hosts use completion of their untyped start callback as the readiness signal.
4821
- await activateWorkObservation();
4822
- } else if (shouldRestoreWorkObservation(event, ctx.sessionManager)) {
4819
+ if (shouldRestoreWorkObservation(event, ctx.sessionManager)) {
4823
4820
  restoreObservation = setImmediate(() => { void activateWorkObservation(); });
4824
4821
  } else {
4822
+ restoreObservation = setImmediate(warmWorkRuntime);
4825
4823
  // Another extension can assign work to this recipient before it calls a tool.
4826
4824
  const origin = activeCallbackOrigin;
4827
4825
  offFirstAssignment = onMetaChanged(meta => {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-subagents",
3
- "version": "0.41.12",
3
+ "version": "0.41.13",
4
4
  "description": "Pi extension for detached, sandboxed subagent runs that keep the foreground session free.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -81,7 +81,7 @@
81
81
  "@earendil-works/pi-tui": "*"
82
82
  },
83
83
  "dependencies": {
84
- "pi-better-server": "0.11.10",
84
+ "pi-better-server": "0.11.11",
85
85
  "proper-lockfile": "^4.1.2",
86
86
  "shell-quote": "1.12.0",
87
87
  "smol-toml": "1.9.0",
@@ -1 +1 @@
1
- {"build":{"contentId":"06b98bf4e6f1e7d77c53fe8ded1995829309d0c843065993a03575f692ad0640","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"darwin-arm64","protocolVersion":1,"serverVersion":"0.11.10","sourceDigest":"75441154c84cf249c9abc0b836a6f95f424de3e9bbfb617c5938e025d76d78a7"},"sha256":"49bf8c261c1e4c0ca676641e5d1a59e15ee91a8236df4313feb6e83d5d54f5ab"}
1
+ {"build":{"contentId":"7ea53a9ab306acdb807d91d40e390a626649719ab6c3dc68abac89a5bdf0a50b","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"darwin-arm64","protocolVersion":1,"serverVersion":"0.11.11","sourceDigest":"9201868088ad78f5d2c2ded80d7929df5bcbc5e6ce3455c042d80dede4cf384c"},"sha256":"8851a7e15b3082c98017b5d4d6ee11d68e28bab15028100dab71f462c25e939d"}
@@ -1 +1 @@
1
- {"build":{"contentId":"91fac528426cbd0cc8958763e11436b1c23a1080a64ce943f1e0a468b7c99eef","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"darwin-x64","protocolVersion":1,"serverVersion":"0.11.10","sourceDigest":"75441154c84cf249c9abc0b836a6f95f424de3e9bbfb617c5938e025d76d78a7"},"sha256":"f399c112766a7da82899f3e1ec69e074e9b2562c304da5199562c21b8564171a"}
1
+ {"build":{"contentId":"6b8c0f8e8dc0e8857f9b506f9b02e4656a55b906ba8e865d674cfd61ea52ccd4","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"darwin-x64","protocolVersion":1,"serverVersion":"0.11.11","sourceDigest":"9201868088ad78f5d2c2ded80d7929df5bcbc5e6ce3455c042d80dede4cf384c"},"sha256":"db7abb20bd5a0958676bff1bb8237cbfb01bcaa4fc73030656f72ea5b8046307"}
@@ -1 +1 @@
1
- {"build":{"contentId":"d41ad3e6a413ded11bd420200d93e20673e5259a8b7a502a86a529bea996dc03","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"linux-arm64","protocolVersion":1,"serverVersion":"0.11.10","sourceDigest":"75441154c84cf249c9abc0b836a6f95f424de3e9bbfb617c5938e025d76d78a7"},"sha256":"96a4831055f9e95e7b298e10615567cbc19fdf7bf74b4a81784a7611e3c60553"}
1
+ {"build":{"contentId":"41f305a8be6279c9d7772f298faaaa5d13ee5917fc5d594580f4d0020f4319f7","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"linux-arm64","protocolVersion":1,"serverVersion":"0.11.11","sourceDigest":"9201868088ad78f5d2c2ded80d7929df5bcbc5e6ce3455c042d80dede4cf384c"},"sha256":"430e3a1bce7f7f870c17e8da26562e0f77bb4c921ba58c4255418357005c0a29"}
@@ -1 +1 @@
1
- {"build":{"contentId":"d531e6509c6baecc9e109a8f31ed03631eccf62ebc1c812432d316a3b7012c24","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"linux-x64","protocolVersion":1,"serverVersion":"0.11.10","sourceDigest":"75441154c84cf249c9abc0b836a6f95f424de3e9bbfb617c5938e025d76d78a7"},"sha256":"3cff5bafbedc4f1238596216f8c12ddf0f0740ff21262c7409dbc2cf97f03837"}
1
+ {"build":{"contentId":"59d0b5a9267847833cbe977d923b6ba71e01b60b10ab064a924a722a322d4498","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"linux-x64","protocolVersion":1,"serverVersion":"0.11.11","sourceDigest":"9201868088ad78f5d2c2ded80d7929df5bcbc5e6ce3455c042d80dede4cf384c"},"sha256":"d7a9a566e17d45a3122b903d471874dc2131f7ae28eb9b78e182bec3366d7a60"}
@@ -1 +1 @@
1
- {"build":{"contentId":"57cbe0230cf34b955e6b9575fa3ed54b9b2eb5ef58132c1d3f84864d239bfc93","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"win32-x64","protocolVersion":1,"serverVersion":"0.11.10","sourceDigest":"75441154c84cf249c9abc0b836a6f95f424de3e9bbfb617c5938e025d76d78a7"},"sha256":"4e76e369fded7c2c0726bee174d532c9ef540a4d4f8b8d792a988fdf4f74160e"}
1
+ {"build":{"contentId":"25560d031d54c564df55a5d21c7b5831bc26f0a821306e66608875a80691d031","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"win32-x64","protocolVersion":1,"serverVersion":"0.11.11","sourceDigest":"9201868088ad78f5d2c2ded80d7929df5bcbc5e6ce3455c042d80dede4cf384c"},"sha256":"6d6d0dfd2556e5723e03a6b419edb512cdaa254bbb073935ce265a9d6932e1ff"}
@@ -1,5 +1,8 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { closeSync, openSync, readFileSync } from "node:fs";
3
+ import { readFile } from "node:fs/promises";
4
+ import { once } from "node:events";
5
+ import { Worker } from "node:worker_threads";
3
6
  import { createRequire } from "node:module";
4
7
  import { connectRuntimeSocket as connect } from "./windows-native.mjs";
5
8
  import { join } from "node:path";
@@ -13,6 +16,55 @@ import { socketPathFor } from "./socket.mjs";
13
16
  export { WorkClient } from "./work-client.mjs";
14
17
  // End-to-end release support. Building an artifact for a new target does not enable it here.
15
18
  const releasedManagedPlatforms = ["darwin-arm64", "darwin-x64", "linux-arm64", "linux-x64", "win32-x64"];
19
+ function supportedPlatform() {
20
+ const platform = `${process.platform}-${process.arch}`;
21
+ if (!releasedManagedPlatforms.includes(platform)) {
22
+ const tracking = process.platform === "win32" ? " Track native Windows support at https://github.com/1aboveio/pi-better-harness/issues/917" : "";
23
+ throw new Error(`runtime-unavailable: this release does not support managed Subagents and Background Tasks on ${platform}. `
24
+ + `Use a supported host (${releasedManagedPlatforms.join(", ")}).${tracking}`);
25
+ }
26
+ return platform;
27
+ }
28
+ const startupKey = Symbol.for("pi-better-runtime.foreground-starts.v1");
29
+ const starts = globalThis[startupKey] ??= new Map();
30
+ /** Both standalone packages can join the same cold start without staging an archive on Pi's event loop. */
31
+ export async function ensureRuntimeInBackground({ agentDir, serverDir = process.env.PI_SERVER_DIR, timeoutMs, signal }) {
32
+ signal?.throwIfAborted();
33
+ const platform = supportedPlatform();
34
+ if (timeoutMs !== undefined && (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 120000))
35
+ throw new Error("Runtime timeout must be from 1 to 120000 ms");
36
+ const deadline = timeoutMs === undefined ? signal : AbortSignal.any([AbortSignal.timeout(timeoutMs), ...(signal ? [signal] : [])]);
37
+ const pin = await readFile(new URL(`../../artifacts/${platform}.json`, import.meta.url), { encoding: "utf8", signal: deadline });
38
+ deadline?.throwIfAborted();
39
+ const offline = process.env.PI_OFFLINE === "1";
40
+ const key = JSON.stringify([agentDir, pin, offline]);
41
+ let start = starts.get(key);
42
+ if (!start) {
43
+ const worker = new Worker(new URL("./startup-worker.mjs", import.meta.url), {
44
+ execArgv: [], workerData: { client: import.meta.url, options: { agentDir, serverDir, offline, timeoutMs: 120000 } },
45
+ });
46
+ worker.setMaxListeners(0);
47
+ // All waiters can abort before the worker reports a staging error.
48
+ worker.on("error", () => { });
49
+ start = { worker, waiters: 0 };
50
+ starts.set(key, start);
51
+ }
52
+ start.waiters++;
53
+ try {
54
+ const [code] = await once(start.worker, "exit", { signal: deadline });
55
+ if (code !== 0)
56
+ throw new Error(`runtime-unavailable: startup worker exited with code ${code}`);
57
+ }
58
+ finally {
59
+ if (--start.waiters === 0) {
60
+ starts.delete(key);
61
+ if (deadline?.aborted) {
62
+ start.worker.postMessage("abort");
63
+ start.worker.unref();
64
+ }
65
+ }
66
+ }
67
+ }
16
68
  /** One bounded LF-JSON exchange; importing this module never loads the Pi SDK. */
17
69
  export async function runtimeStatus(socketPath, agentDir, artifact, timeoutMs = 2000) {
18
70
  return new Promise((resolve, reject) => {
@@ -64,12 +116,7 @@ export async function ensureRuntime(options) {
64
116
  const timeoutMs = options.timeoutMs ?? 15000;
65
117
  if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 120000)
66
118
  throw new Error("Runtime timeout must be from 1 to 120000 ms");
67
- const platform = `${process.platform}-${process.arch}`;
68
- if (!releasedManagedPlatforms.includes(platform)) {
69
- const tracking = process.platform === "win32" ? " Track native Windows support at https://github.com/1aboveio/pi-better-harness/issues/917" : "";
70
- throw new Error(`runtime-unavailable: this release does not support managed Subagents and Background Tasks on ${platform}. `
71
- + `Use a supported host (${releasedManagedPlatforms.join(", ")}).${tracking}`);
72
- }
119
+ const platform = supportedPlatform();
73
120
  const directory = fileURLToPath(new URL("../../artifacts/", import.meta.url));
74
121
  let artifact;
75
122
  try {
@@ -0,0 +1,10 @@
1
+ import { parentPort, workerData } from "node:worker_threads";
2
+
3
+ const controller = new AbortController();
4
+ parentPort.once("message", () => controller.abort());
5
+ try {
6
+ const { ensureRuntime } = await import(workerData.client);
7
+ await ensureRuntime({ ...workerData.options, signal: controller.signal });
8
+ } finally {
9
+ parentPort.close();
10
+ }
@@ -87,6 +87,6 @@ export function waitForCatalogSetup<T>(pending: Promise<T>, signal?: AbortSignal
87
87
 
88
88
  async function ensureCatalogRuntime(agentDir: string, serverDir?: string, timeoutMs?: number, signal?: AbortSignal): Promise<void> {
89
89
  const path = "./runtime-client/src/runtime/client.mjs";
90
- const { ensureRuntime } = await import(path);
91
- await ensureRuntime({ agentDir, serverDir, timeoutMs, signal });
90
+ const { ensureRuntimeInBackground } = await import(path);
91
+ await ensureRuntimeInBackground({ agentDir, serverDir, timeoutMs, signal });
92
92
  }
@@ -1,4 +1,4 @@
1
- import { mkdirSync, readFileSync, realpathSync } from "node:fs";
1
+ import { mkdir, readFile, realpath } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { homedir } from "node:os";
4
4
  import { socketPathFor, WorkClient, connectWorkClient } from "./shared-work-client.mjs";
@@ -7,6 +7,7 @@ export const TERMINAL_NAVIGATOR_RETENTION_MS = 30_000;
7
7
  let client: WorkClient | undefined;
8
8
  let snapshot: any;
9
9
  let context: { agentDir: string; origin: { cwd: string; sessionId?: string } } | undefined;
10
+ let transport: Promise<WorkClient> | undefined;
10
11
  let connecting: Promise<void> | undefined;
11
12
  let collecting: Promise<void> | undefined;
12
13
  let collectingClient: WorkClient | undefined;
@@ -138,31 +139,49 @@ async function collect(candidate: WorkClient, current: number) {
138
139
  return collecting;
139
140
  }
140
141
 
141
- async function connectObservation(current: number) {
142
- const saved = context!;
143
- const signal = connectionAbort.signal;
144
- mkdirSync(saved.agentDir, { recursive: true, mode: 0o700 });
145
- saved.agentDir = realpathSync(saved.agentDir);
142
+ async function openTransport(agentDir: string, signal: AbortSignal) {
143
+ await mkdir(agentDir, { recursive: true, mode: 0o700 });
144
+ const root = await realpath(agentDir);
145
+ const readRegistration = async () => JSON.parse(await readFile(join(root, "server-registration-v1.json"), { encoding: "utf8", signal }));
146
+ const ensure = async (serverDir?: string, timeoutMs?: number, startupSignal = signal) => {
147
+ const path = "./runtime-client/src/runtime/client.mjs";
148
+ const { ensureRuntimeInBackground } = await import(path);
149
+ await ensureRuntimeInBackground({ agentDir: root, serverDir, timeoutMs, signal: startupSignal });
150
+ };
146
151
  let registration;
147
- try { registration = JSON.parse(readFileSync(join(saved.agentDir, "server-registration-v1.json"), "utf8")); }
152
+ try { registration = await readRegistration(); }
148
153
  catch (error) {
149
154
  if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
150
- const path = "./runtime-client/src/runtime/client.mjs";
151
- const { ensureRuntime } = await import(path);
152
- await ensureRuntime({ agentDir: saved.agentDir, signal });
153
- registration = JSON.parse(readFileSync(join(saved.agentDir, "server-registration-v1.json"), "utf8"));
155
+ await ensure();
156
+ registration = await readRegistration();
154
157
  }
155
- if (current !== generation) return;
156
- if (registration.version !== 1 || registration.agentDir !== saved.agentDir) throw new Error("Invalid canonical runtime registration");
157
- client?.close();
158
- const candidate = await connectWorkClient(socketPathFor(registration.serverDir), saved.agentDir, [], {
159
- signal,
160
- recover: async ({ timeoutMs, signal }) => {
161
- const path = "./runtime-client/src/runtime/client.mjs";
162
- const { ensureRuntime } = await import(path);
163
- await ensureRuntime({ agentDir: saved.agentDir, serverDir: registration.serverDir, timeoutMs, signal });
164
- },
158
+ if (registration.version !== 1 || registration.agentDir !== root) throw new Error("Invalid canonical runtime registration");
159
+ return connectWorkClient(socketPathFor(registration.serverDir), root, [], {
160
+ signal, recover: ({ timeoutMs, signal }) => ensure(registration.serverDir, timeoutMs, signal),
165
161
  });
162
+ }
163
+
164
+ function getTransport() {
165
+ if (transport) return transport;
166
+ const pending = openTransport(context!.agentDir, connectionAbort.signal);
167
+ transport = pending;
168
+ const forget = () => { if (transport === pending) transport = undefined; };
169
+ void pending.then(candidate => {
170
+ if (transport !== pending) { candidate.close(); return; }
171
+ candidate.onChange(() => { if (candidate.closed) forget(); });
172
+ if (candidate.closed) forget();
173
+ }, forget);
174
+ return pending;
175
+ }
176
+
177
+ // Fresh sessions warm only the socket. Task tools and Navigator activate the subscription.
178
+ export function warmWorkRuntime() {
179
+ if (context) void getTransport().catch(() => {});
180
+ }
181
+
182
+ async function connectObservation(current: number) {
183
+ const saved = context!;
184
+ const candidate = await getTransport();
166
185
  if (current !== generation) { candidate.close(); return; }
167
186
  client = candidate;
168
187
  candidate.onChange(() => {
@@ -248,6 +267,9 @@ export function stopWorkObservation() {
248
267
  collectionFailures = 0;
249
268
  connectionAbort.abort(); connectionAbort = new AbortController();
250
269
  if (retry) clearTimeout(retry); retry = undefined;
270
+ const pending = transport;
271
+ transport = undefined;
272
+ void pending?.then(candidate => candidate.close(), () => {});
251
273
  client?.close(); client = undefined; snapshot = undefined;
252
274
  connecting = undefined; collecting = undefined; collectingClient = undefined; dirty = false;
253
275
  details.clear(); pendingDetails.clear(); backoff = 100;
@@ -255,19 +277,23 @@ export function stopWorkObservation() {
255
277
 
256
278
  export function requestWorkDetail(id: string) {
257
279
  const cached = details.get(id);
258
- if ((cached?.seq === snapshot?.seq && cached?.instanceId === snapshot?.instanceId) || pendingDetails.has(id) || !client) return cached?.row;
280
+ const seq = snapshot?.seq;
281
+ const instanceId = snapshot?.instanceId;
282
+ if ((cached && cached.seq === seq && cached.instanceId === instanceId) || pendingDetails.has(id) || !client) return cached?.row;
259
283
  pendingDetails.add(id);
260
284
  const current = generation;
261
285
  void query({ id, detail: true, limit: 1 }).then(value => {
262
286
  if (current !== generation) return;
263
- details.set(id, { seq: value.seq, instanceId: value.instanceId, row: value.rows[0] });
287
+ details.set(id, { seq, instanceId, row: value.rows[0] });
264
288
  if (details.size > 16) details.delete(details.keys().next().value!);
265
- refresh();
266
289
  }).catch(error => {
267
290
  if (current !== generation) return;
268
291
  failure = String(error);
269
- details.set(id, { seq: snapshot?.seq, instanceId: snapshot?.instanceId, row: { ...cached?.row, observationError: failure } });
292
+ details.set(id, { seq, instanceId, row: { ...cached?.row, observationError: failure } });
293
+ }).finally(() => {
294
+ if (current !== generation) return;
295
+ pendingDetails.delete(id);
270
296
  refresh();
271
- }).finally(() => { if (current === generation) pendingDetails.delete(id); });
297
+ });
272
298
  return cached?.row;
273
299
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-harness",
3
- "version": "0.66.0",
3
+ "version": "0.66.1",
4
4
  "description": "Pi extension bundle for a write sandbox, subagents, background tasks, SSH, Goals, and Todo lists.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -75,12 +75,12 @@
75
75
  "@xterm/xterm": "6.0.0",
76
76
  "marked": "18.0.5",
77
77
  "openai": "6.26.0",
78
- "pi-better-background-tasks": "0.21.19",
78
+ "pi-better-background-tasks": "0.21.20",
79
79
  "pi-better-goal": "0.18.6",
80
80
  "pi-better-sandbox": "0.15.5",
81
- "pi-better-server": "0.11.10",
81
+ "pi-better-server": "0.11.11",
82
82
  "pi-better-ssh": "0.1.7",
83
- "pi-better-subagents": "0.41.12",
83
+ "pi-better-subagents": "0.41.13",
84
84
  "proper-lockfile": "^4.1.2",
85
85
  "shell-quote": "1.12.0",
86
86
  "smol-toml": "1.9.0",