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.
- package/CHANGELOG.md +6 -0
- package/node_modules/pi-better-background-tasks/package.json +2 -2
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-arm64.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-x64.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-arm64.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-x64.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/win32-x64.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/src/runtime/client.mjs +53 -6
- package/node_modules/pi-better-background-tasks/runtime-client/src/runtime/startup-worker.mjs +10 -0
- package/node_modules/pi-better-background-tasks/src/observed-waits.ts +3 -3
- package/node_modules/pi-better-background-tasks/src/work-observation.ts +11 -8
- package/node_modules/pi-better-subagents/README.md +4 -1
- package/node_modules/pi-better-subagents/index.ts +3 -5
- package/node_modules/pi-better-subagents/package.json +2 -2
- package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-arm64.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-x64.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-arm64.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-x64.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/artifacts/win32-x64.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/src/runtime/client.mjs +53 -6
- package/node_modules/pi-better-subagents/runtime-client/src/runtime/startup-worker.mjs +10 -0
- package/node_modules/pi-better-subagents/shared-catalog.ts +2 -2
- package/node_modules/pi-better-subagents/work-observation.ts +52 -26
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-better-background-tasks",
|
|
3
|
-
"version": "0.21.
|
|
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.
|
|
73
|
+
"pi-better-server": "0.11.11",
|
|
74
74
|
"proper-lockfile": "^4.1.2"
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"build":{"contentId":"
|
|
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":"
|
|
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":"
|
|
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":"
|
|
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":"
|
|
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 =
|
|
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)).
|
|
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 {
|
|
2297
|
-
await
|
|
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 {
|
|
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
|
-
|
|
97
|
-
const root =
|
|
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 {
|
|
101
|
-
await
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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 (
|
|
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.
|
|
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.
|
|
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":"
|
|
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":"
|
|
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":"
|
|
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":"
|
|
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":"
|
|
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 =
|
|
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 {
|
|
91
|
-
await
|
|
90
|
+
const { ensureRuntimeInBackground } = await import(path);
|
|
91
|
+
await ensureRuntimeInBackground({ agentDir, serverDir, timeoutMs, signal });
|
|
92
92
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
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 =
|
|
152
|
+
try { registration = await readRegistration(); }
|
|
148
153
|
catch (error) {
|
|
149
154
|
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
150
|
-
|
|
151
|
-
|
|
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 (
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
})
|
|
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.
|
|
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.
|
|
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.
|
|
81
|
+
"pi-better-server": "0.11.11",
|
|
82
82
|
"pi-better-ssh": "0.1.7",
|
|
83
|
-
"pi-better-subagents": "0.41.
|
|
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",
|