pi-better-server 0.5.0 → 0.6.0
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/package.json +4 -1
- package/scripts/copy-pi-test-providers.mjs +10 -0
- package/scripts/event-publication/README.md +26 -0
- package/scripts/event-publication/commit.mjs +21 -0
- package/scripts/event-publication/measure.mjs +37 -5
- package/scripts/event-publication/writer.mjs +3 -8
- package/scripts/measure-full-runtime/probe.mjs +4 -2
- package/scripts/measure-full-runtime/recovery-trace-loader.mjs +51 -0
- package/scripts/measure-full-runtime/recovery-trace.mjs +16 -0
- package/scripts/measure-shared-reads.mjs +2 -1
- package/scripts/private-runtime/package-lock.json +18 -0
- package/scripts/private-runtime/package.json +4 -1
- package/scripts/source-provenance.mjs +2 -2
- package/scripts/test-on-pi.sh +2 -9
- package/src/handshake.ts +1 -1
- package/src/hosted-session.ts +32 -4
- package/src/maintenance.ts +35 -7
- package/src/registry.ts +28 -4
- package/src/runtime/attempt-invalidation.ts +54 -0
- package/src/runtime/background-history.ts +151 -45
- package/src/runtime/background-policy.ts +9 -4
- package/src/runtime/background-tools.ts +131 -23
- package/src/runtime/background.ts +351 -68
- package/src/runtime/cancellation.ts +28 -7
- package/src/runtime/catalog-sources.ts +199 -0
- package/src/runtime/catalog.ts +53 -21
- package/src/runtime/client.ts +22 -2
- package/src/runtime/domain/assignment-inbox.mjs +119 -0
- package/src/runtime/domain/assignment-observation.d.mts +1 -1
- package/src/runtime/domain/assignment-observation.mjs +43 -35
- package/src/runtime/domain/background/process-identity.mjs +20 -2
- package/src/runtime/domain/background/process.mjs +3 -3
- package/src/runtime/domain/background/registry.mjs +61 -3
- package/src/runtime/domain/background/types.mjs +1 -0
- package/src/runtime/domain/background-service/adapter-contract.domain.mjs +1 -1
- package/src/runtime/domain/background-service/adapter-contract.ts +1 -1
- package/src/runtime/domain/background-service/goal-provider.domain.mjs +35 -16
- package/src/runtime/domain/background-service/goal-provider.ts +31 -16
- package/src/runtime/domain/background-service/index.domain.mjs +6 -9
- package/src/runtime/domain/background-service/index.ts +6 -9
- package/src/runtime/domain/background-service/managed-authority.domain.mjs +6 -3
- package/src/runtime/domain/background-service/managed-authority.ts +5 -3
- package/src/runtime/domain/background-service/managed-client.domain.mjs +21 -7
- package/src/runtime/domain/background-service/managed-client.ts +20 -7
- package/src/runtime/domain/background-service/managed-frontend.domain.mjs +75 -17
- package/src/runtime/domain/background-service/managed-frontend.ts +62 -17
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +16 -5
- package/src/runtime/domain/background-service/navigator-provider.ts +15 -5
- package/src/runtime/domain/background-service/observed-wait-client.domain.mjs +6 -0
- package/src/runtime/domain/background-service/observed-wait-client.ts +10 -0
- package/src/runtime/domain/background-service/observed-waits.domain.mjs +170 -27
- package/src/runtime/domain/background-service/observed-waits.ts +154 -30
- package/src/runtime/domain/background-service/process-identity.domain.mjs +20 -2
- package/src/runtime/domain/background-service/process-identity.ts +18 -2
- package/src/runtime/domain/background-service/process.domain.mjs +3 -3
- package/src/runtime/domain/background-service/process.ts +3 -3
- package/src/runtime/domain/background-service/registry.domain.mjs +61 -3
- package/src/runtime/domain/background-service/registry.ts +53 -5
- package/src/runtime/domain/background-service/runtime.domain.mjs +32 -16
- package/src/runtime/domain/background-service/runtime.ts +19 -9
- package/src/runtime/domain/background-service/sandbox.domain.mjs +14 -15
- package/src/runtime/domain/background-service/sandbox.ts +14 -11
- package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +8 -1
- package/src/runtime/domain/background-service/shared-callback-batcher.ts +11 -2
- package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +24 -2
- package/src/runtime/domain/background-service/shared-navigator-panels.ts +26 -4
- package/src/runtime/domain/background-service/shared-navigator.domain.mjs +218 -13
- package/src/runtime/domain/background-service/shared-navigator.ts +197 -14
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-observation.mjs +53 -41
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +14 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +5 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +44 -4
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +50 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +42 -21
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +40 -24
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +21 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +34 -8
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +24 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +1 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +5 -1
- package/src/runtime/domain/background-service/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/background-service/shared-work-client.mjs +174 -7
- package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +20 -2
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +3 -3
- package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +1 -1
- package/src/runtime/domain/background-service/task-diagnostics.ts +1 -1
- package/src/runtime/domain/background-service/tools.domain.mjs +31 -24
- package/src/runtime/domain/background-service/tools.ts +41 -38
- package/src/runtime/domain/background-service/types.domain.mjs +1 -0
- package/src/runtime/domain/background-service/types.ts +3 -1
- package/src/runtime/domain/background-service/work-observation.domain.mjs +46 -20
- package/src/runtime/domain/background-service/work-observation.ts +46 -19
- package/src/runtime/domain/catalog/catalog-store.d.mts +9 -1
- package/src/runtime/domain/catalog/catalog-store.mjs +20 -22
- package/src/runtime/domain/coordinator/src/assignment-changes.mjs +75 -0
- package/src/runtime/domain/coordinator/src/assignment-outcomes.mjs +2 -0
- package/src/runtime/domain/coordinator/src/background-requests.mjs +11 -2
- package/src/runtime/domain/coordinator/src/discovery.mjs +4 -2
- package/src/runtime/domain/coordinator/src/operations.mjs +44 -4
- package/src/runtime/domain/coordinator/src/result-supervision.mjs +12 -0
- package/src/runtime/domain/coordinator/src/rows.mjs +2 -0
- package/src/runtime/domain/coordinator/src/schema.mjs +42 -21
- package/src/runtime/domain/coordinator/src/store.mjs +21 -3
- package/src/runtime/domain/coordinator/src/subagent-launch.mjs +23 -1
- package/src/runtime/domain/coordinator/src/types.mjs +1 -1
- package/src/runtime/domain/health-observation.d.mts +3 -1
- package/src/runtime/domain/health-observation.mjs +189 -190
- package/src/runtime/domain/log-cursor.d.mts +2 -0
- package/src/runtime/domain/log-cursor.mjs +85 -16
- package/src/runtime/domain/parse.d.mts +4 -1
- package/src/runtime/domain/parse.mjs +50 -5
- package/src/runtime/domain/sandbox-policy/README.md +61 -63
- package/src/runtime/domain/sandbox-policy/commands.domain.mjs +11 -8
- package/src/runtime/domain/sandbox-policy/commands.ts +12 -7
- package/src/runtime/domain/sandbox-policy/index.domain.mjs +53 -9
- package/src/runtime/domain/sandbox-policy/index.ts +52 -9
- package/src/runtime/domain/sandbox-policy/package.json +1 -1
- package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +5 -2
- package/src/runtime/domain/sandbox-policy/permission-settings.ts +9 -2
- package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +56 -137
- package/src/runtime/domain/sandbox-policy/permissions-page.ts +52 -130
- package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +1 -6
- package/src/runtime/domain/sandbox-policy/permissions.ts +1 -6
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +14 -1
- package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +12 -1
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.domain.mjs +3 -2
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +8 -2
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +4 -3
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +5 -3
- package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +8 -5
- package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +8 -5
- package/src/runtime/domain/subagents/README.md +1 -1
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +12 -6
- package/src/runtime/domain/subagents/assignment-outcomes.ts +11 -5
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +87 -24
- package/src/runtime/domain/subagents/assignment-report.ts +83 -19
- package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +21 -3
- package/src/runtime/domain/subagents/catalog-host-admission.ts +19 -3
- package/src/runtime/domain/subagents/catalog-preferences.ts +1 -1
- package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +35 -1
- package/src/runtime/domain/subagents/catalog-resolver.ts +35 -1
- package/src/runtime/domain/subagents/catalog-store.domain.mjs +20 -22
- package/src/runtime/domain/subagents/catalog-store.ts +27 -20
- package/src/runtime/domain/subagents/child-apply-patch.domain.mjs +13 -0
- package/src/runtime/domain/subagents/child-apply-patch.ts +13 -0
- package/src/runtime/domain/subagents/child-dependencies.mjs +27 -15
- package/src/runtime/domain/subagents/child-operations.domain.mjs +80 -2
- package/src/runtime/domain/subagents/child-operations.ts +80 -1
- package/src/runtime/domain/subagents/child-preflight.mjs +9 -2
- package/src/runtime/domain/subagents/child-process-list.domain.mjs +7 -0
- package/src/runtime/domain/subagents/child-process-list.ts +8 -0
- package/src/runtime/domain/subagents/config.domain.mjs +49 -2
- package/src/runtime/domain/subagents/config.ts +46 -2
- package/src/runtime/domain/subagents/continuation-authority.domain.mjs +5 -1
- package/src/runtime/domain/subagents/continuation-authority.ts +3 -1
- package/src/runtime/domain/subagents/continuation-runtime.domain.mjs +89 -0
- package/src/runtime/domain/subagents/continuation-runtime.ts +88 -0
- package/src/runtime/domain/subagents/extensions.mjs +11 -13
- package/src/runtime/domain/subagents/finalization.domain.mjs +12 -0
- package/src/runtime/domain/subagents/finalization.ts +15 -0
- package/src/runtime/domain/subagents/goal-provider.domain.mjs +44 -2
- package/src/runtime/domain/subagents/goal-provider.ts +44 -2
- package/src/runtime/domain/subagents/health-observation.domain.mjs +189 -190
- package/src/runtime/domain/subagents/health-observation.ts +43 -48
- package/src/runtime/domain/subagents/index.domain.mjs +296 -123
- package/src/runtime/domain/subagents/index.ts +257 -98
- package/src/runtime/domain/subagents/launch-context.domain.mjs +24 -0
- package/src/runtime/domain/subagents/launch-context.ts +23 -0
- package/src/runtime/domain/subagents/launch-digest.mjs +6 -0
- package/src/runtime/domain/subagents/log-cursor.domain.mjs +85 -16
- package/src/runtime/domain/subagents/log-cursor.ts +91 -15
- package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +2 -2
- package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +6 -3
- package/src/runtime/domain/subagents/managed-launch-client.ts +6 -3
- package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +222 -14
- package/src/runtime/domain/subagents/managed-launch-host.ts +168 -15
- package/src/runtime/domain/subagents/managed-launch-journal.mjs +1 -5
- package/src/runtime/domain/subagents/managed-launch-port.ts +4 -0
- package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +27 -2
- package/src/runtime/domain/subagents/operation-bridge-types.ts +27 -2
- package/src/runtime/domain/subagents/owned-exit.domain.mjs +12 -0
- package/src/runtime/domain/subagents/owned-exit.ts +12 -0
- package/src/runtime/domain/subagents/package.json +1 -1
- package/src/runtime/domain/subagents/parse.domain.mjs +50 -5
- package/src/runtime/domain/subagents/parse.ts +48 -6
- package/src/runtime/domain/subagents/permission-policy.domain.mjs +32 -8
- package/src/runtime/domain/subagents/permission-policy.ts +41 -8
- package/src/runtime/domain/subagents/process-identity.mjs +33 -0
- package/src/runtime/domain/subagents/registry.domain.mjs +47 -33
- package/src/runtime/domain/subagents/registry.ts +54 -33
- package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +8 -1
- package/src/runtime/domain/subagents/shared-callback-batcher.ts +11 -2
- package/src/runtime/domain/subagents/shared-catalog.domain.mjs +6 -23
- package/src/runtime/domain/subagents/shared-catalog.ts +6 -14
- package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +24 -2
- package/src/runtime/domain/subagents/shared-navigator-panels.ts +26 -4
- package/src/runtime/domain/subagents/shared-navigator.domain.mjs +218 -13
- package/src/runtime/domain/subagents/shared-navigator.ts +197 -14
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +53 -41
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +14 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +5 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +44 -4
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +50 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +42 -21
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +40 -24
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +21 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +34 -8
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +24 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +1 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +5 -1
- package/src/runtime/domain/subagents/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +14 -1
- package/src/runtime/domain/subagents/shared-task-exec.ts +12 -1
- package/src/runtime/domain/subagents/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/subagents/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/subagents/shared-task-process-list.domain.mjs +3 -2
- package/src/runtime/domain/subagents/shared-task-process-list.ts +8 -2
- package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +4 -3
- package/src/runtime/domain/subagents/shared-task-sandbox.ts +5 -3
- package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +8 -5
- package/src/runtime/domain/subagents/shared-task-tools.ts +8 -5
- package/src/runtime/domain/subagents/shared-work-client.mjs +174 -7
- package/src/runtime/domain/subagents/subagent-tools.domain.mjs +22 -38
- package/src/runtime/domain/subagents/subagent-tools.ts +28 -34
- package/src/runtime/domain/subagents/task-policy.domain.mjs +1 -1
- package/src/runtime/domain/subagents/task-policy.ts +3 -1
- package/src/runtime/domain/subagents/timing.domain.mjs +10 -1
- package/src/runtime/domain/subagents/timing.ts +10 -1
- package/src/runtime/domain/subagents/work-observation.domain.mjs +77 -16
- package/src/runtime/domain/subagents/work-observation.ts +71 -16
- package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +9 -4
- package/src/runtime/domain/subagents/worker-operations-host.ts +12 -4
- package/src/runtime/domain/subagents/worker-waits.domain.mjs +89 -35
- package/src/runtime/domain/subagents/worker-waits.ts +93 -34
- package/src/runtime/health-config.ts +27 -11
- package/src/runtime/log-checkpoints.ts +117 -0
- package/src/runtime/mutation-store.ts +5 -4
- package/src/runtime/queries.ts +25 -2
- package/src/runtime/query-executor.ts +149 -28
- package/src/runtime/query-worker.mjs +106 -21
- package/src/runtime/read-model.ts +846 -120
- package/src/runtime/read-watchdog-probe.ts +4 -0
- package/src/runtime/result-supervision.ts +188 -16
- package/src/runtime/source-watch.ts +175 -0
- package/src/runtime/subagent-launch.ts +11 -4
- package/src/runtime/work-budget.ts +130 -0
- package/src/runtime/work-client.d.mts +8 -0
- package/src/runtime/work-client.mjs +150 -7
- package/src/server.ts +104 -23
- package/src/session-activity.ts +26 -4
- package/src/version.ts +1 -1
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/shared-work-client.mjs. Do not edit directly.
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
2
3
|
import { connect } from "node:net";
|
|
3
4
|
import { performance } from "node:perf_hooks";
|
|
5
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
6
|
+
/** A persisted session can own work even when its selected branch is empty. */
|
|
7
|
+
export function shouldRestoreWorkObservation(event, session) {
|
|
8
|
+
if (event?.piBetterObserveWork)
|
|
9
|
+
return true;
|
|
10
|
+
const reason = event?.reason;
|
|
11
|
+
if (reason === "new")
|
|
12
|
+
return false;
|
|
13
|
+
if (reason !== "startup" || typeof session?.getSessionFile !== "function")
|
|
14
|
+
return true;
|
|
15
|
+
const file = session.getSessionFile();
|
|
16
|
+
return file ? existsSync(file) : Boolean(session.getLeafId?.());
|
|
17
|
+
}
|
|
4
18
|
/** SDK-free observation stream. Cached snapshots are the only synchronous read API. */
|
|
5
19
|
export class WorkClient {
|
|
6
20
|
socket;
|
|
@@ -12,6 +26,11 @@ export class WorkClient {
|
|
|
12
26
|
scope;
|
|
13
27
|
buffer = "";
|
|
14
28
|
closed = false;
|
|
29
|
+
recoveryTimer;
|
|
30
|
+
recoveryActive = false;
|
|
31
|
+
recoveryAgain = false;
|
|
32
|
+
recoveryDelay = 100;
|
|
33
|
+
scopeGeneration = 0;
|
|
15
34
|
constructor(socketPath, agentDir, requiredCapabilities = []) {
|
|
16
35
|
this.socket = typeof socketPath === "string" ? connect(socketPath) : socketPath;
|
|
17
36
|
this.socket.setEncoding("utf8");
|
|
@@ -32,10 +51,10 @@ export class WorkClient {
|
|
|
32
51
|
}
|
|
33
52
|
if (message.event.type === "resync_required") {
|
|
34
53
|
this.degrade(message.event.reason);
|
|
35
|
-
|
|
54
|
+
this.scheduleRecovery();
|
|
36
55
|
}
|
|
37
56
|
else if (message.event.type === "runtime_snapshot")
|
|
38
|
-
this.accept(message.event.snapshot);
|
|
57
|
+
this.accept(message.event.snapshot, message.event.previousSeq);
|
|
39
58
|
}
|
|
40
59
|
else {
|
|
41
60
|
const request = this.pending.get(message.id);
|
|
@@ -54,7 +73,9 @@ export class WorkClient {
|
|
|
54
73
|
}
|
|
55
74
|
}
|
|
56
75
|
});
|
|
57
|
-
this.socket.on("error", error => this.fail(error)
|
|
76
|
+
this.socket.on("error", error => this.fail(["ECONNRESET", "EPIPE"].includes(error.code)
|
|
77
|
+
? Object.assign(new Error(`runtime-unavailable: disconnected (${error.code}); resync required`, { cause: error }), { code: error.code })
|
|
78
|
+
: error));
|
|
58
79
|
this.socket.on("close", () => this.fail(new Error("runtime-unavailable: disconnected; resync required")));
|
|
59
80
|
this.ready = this.request("hello", { protocolVersion: 1, runtimeRoot: agentDir, requiredCapabilities: ["runtime-state-v1", "runtime-subscriptions-v1", ...requiredCapabilities] })
|
|
60
81
|
.then(async (hello) => { if (typeof socketPath === "string" && hello.capabilities?.includes("runtime-client-retention-v1"))
|
|
@@ -80,31 +101,78 @@ export class WorkClient {
|
|
|
80
101
|
this.snapshot = { ...this.snapshot, status: "degraded", reason, rows: this.snapshot?.rows ?? [] };
|
|
81
102
|
this.notify();
|
|
82
103
|
}
|
|
83
|
-
accept(snapshot) {
|
|
104
|
+
accept(snapshot, previousSeq) {
|
|
84
105
|
if (this.snapshot?.instanceId === snapshot.instanceId && snapshot.seq < this.snapshot.seq)
|
|
85
106
|
return;
|
|
86
107
|
if (this.snapshot?.instanceId && this.snapshot.instanceId !== snapshot.instanceId) {
|
|
87
108
|
this.degrade("instance-changed: resync required");
|
|
88
109
|
snapshot = { ...snapshot, resyncRequired: true, resyncReason: "instance-changed" };
|
|
89
110
|
}
|
|
90
|
-
else if (this.snapshot?.seq !== undefined &&
|
|
111
|
+
else if (this.snapshot?.seq !== undefined && Number.isSafeInteger(previousSeq) && previousSeq > this.snapshot.seq) {
|
|
91
112
|
this.degrade("sequence-gap: replacing with a full authoritative snapshot");
|
|
92
113
|
snapshot = { ...snapshot, resyncRequired: true, resyncReason: "sequence-gap" };
|
|
93
114
|
}
|
|
94
|
-
//
|
|
115
|
+
// Global seq may skip unrelated changes; only a missing subscription
|
|
116
|
+
// predecessor indicates loss. The received snapshot is still complete.
|
|
95
117
|
this.snapshot = Object.freeze(snapshot);
|
|
96
118
|
this.notify();
|
|
97
119
|
}
|
|
120
|
+
scheduleRecovery(delay = 0) {
|
|
121
|
+
if (this.closed)
|
|
122
|
+
return;
|
|
123
|
+
if (this.recoveryActive) {
|
|
124
|
+
this.recoveryAgain = true;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (this.recoveryTimer)
|
|
128
|
+
return;
|
|
129
|
+
this.recoveryTimer = setTimeout(() => {
|
|
130
|
+
this.recoveryTimer = undefined;
|
|
131
|
+
void this.recover();
|
|
132
|
+
}, delay);
|
|
133
|
+
this.recoveryTimer.unref?.();
|
|
134
|
+
}
|
|
135
|
+
async recover() {
|
|
136
|
+
const generation = this.scopeGeneration;
|
|
137
|
+
this.recoveryActive = true;
|
|
138
|
+
let retry = false;
|
|
139
|
+
try {
|
|
140
|
+
await this.resync();
|
|
141
|
+
this.recoveryDelay = 100;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
if (!this.closed && generation === this.scopeGeneration) {
|
|
145
|
+
this.degrade(String(error));
|
|
146
|
+
retry = /runtime-(?:timeout|overloaded|unhealthy)/.test(String(error));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
finally {
|
|
150
|
+
this.recoveryActive = false;
|
|
151
|
+
const again = this.recoveryAgain;
|
|
152
|
+
this.recoveryAgain = false;
|
|
153
|
+
if (!this.closed && (again || retry && generation === this.scopeGeneration)) {
|
|
154
|
+
this.scheduleRecovery(again ? 0 : this.recoveryDelay);
|
|
155
|
+
this.recoveryDelay = Math.min(1000, this.recoveryDelay * 2);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
98
159
|
async subscribe(scope) {
|
|
99
160
|
await this.ready;
|
|
161
|
+
this.scopeGeneration++;
|
|
162
|
+
clearTimeout(this.recoveryTimer);
|
|
163
|
+
this.recoveryTimer = undefined;
|
|
164
|
+
this.recoveryAgain = false;
|
|
165
|
+
this.recoveryDelay = 100;
|
|
100
166
|
this.scope = scope;
|
|
101
167
|
const snapshot = await this.request("runtime_subscribe", { scope });
|
|
102
168
|
this.accept(snapshot);
|
|
103
169
|
return snapshot;
|
|
104
170
|
}
|
|
105
171
|
async resync() {
|
|
172
|
+
const generation = this.scopeGeneration;
|
|
106
173
|
const snapshot = await this.request("runtime_subscribe", { scope: this.scope, sinceSeq: this.snapshot?.seq, instanceId: this.snapshot?.instanceId });
|
|
107
|
-
this.
|
|
174
|
+
if (!this.closed && generation === this.scopeGeneration)
|
|
175
|
+
this.accept(snapshot);
|
|
108
176
|
return snapshot;
|
|
109
177
|
}
|
|
110
178
|
async get(scope) {
|
|
@@ -122,6 +190,9 @@ export class WorkClient {
|
|
|
122
190
|
if (this.closed)
|
|
123
191
|
return;
|
|
124
192
|
this.closed = true;
|
|
193
|
+
this.scopeGeneration++;
|
|
194
|
+
clearTimeout(this.recoveryTimer);
|
|
195
|
+
this.recoveryTimer = undefined;
|
|
125
196
|
for (const request of this.pending.values()) {
|
|
126
197
|
clearTimeout(request.timer);
|
|
127
198
|
request.reject(error);
|
|
@@ -134,3 +205,99 @@ export class WorkClient {
|
|
|
134
205
|
}
|
|
135
206
|
close() { this.fail(new Error("runtime-unavailable: client closed")); this.listeners.clear(); this.catalogListeners.clear(); }
|
|
136
207
|
}
|
|
208
|
+
// Shared across the standalone extension copies, but never across agent roots.
|
|
209
|
+
const recoveryKey = Symbol.for("pi-better-runtime.connection-recovery.v2");
|
|
210
|
+
const recoveries = globalThis[recoveryKey] ??= new Map();
|
|
211
|
+
const connectionDemands = globalThis[Symbol.for("pi-better-runtime.connection-demand.v2")] ??= new Map();
|
|
212
|
+
/** Establish a transport only. Never replay an application request after dispatch. */
|
|
213
|
+
export async function connectWorkClient(socketPath, agentDir, capabilities = [], options = {}) {
|
|
214
|
+
const timeoutMs = options.timeoutMs ?? 60000;
|
|
215
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0)
|
|
216
|
+
throw new Error("Invalid connection timeout");
|
|
217
|
+
const deadline = performance.now() + timeoutMs;
|
|
218
|
+
const started = performance.now();
|
|
219
|
+
let backoff = 100, recovered = false, lastError, recoveryError, ownedRecovery;
|
|
220
|
+
const remaining = () => Math.max(1, deadline - performance.now());
|
|
221
|
+
const key = JSON.stringify([agentDir, socketPath]);
|
|
222
|
+
connectionDemands.set(key, (connectionDemands.get(key) ?? 0) + 1);
|
|
223
|
+
try {
|
|
224
|
+
while (performance.now() < deadline) {
|
|
225
|
+
options.signal?.throwIfAborted();
|
|
226
|
+
const client = new WorkClient(socketPath, agentDir, capabilities);
|
|
227
|
+
const abort = () => client.close();
|
|
228
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
229
|
+
const timer = setTimeout(() => client.close(), remaining());
|
|
230
|
+
try {
|
|
231
|
+
await client.ready;
|
|
232
|
+
options.signal?.throwIfAborted();
|
|
233
|
+
return client;
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
client.close();
|
|
237
|
+
options.signal?.throwIfAborted();
|
|
238
|
+
lastError = error;
|
|
239
|
+
if (recoveryError)
|
|
240
|
+
throw recoveryError;
|
|
241
|
+
if (!["ENOENT", "ECONNREFUSED", "ECONNRESET", "EPIPE"].includes(error?.code)
|
|
242
|
+
&& !/runtime-unavailable: (?:disconnected|server closed)/.test(String(error)))
|
|
243
|
+
throw error;
|
|
244
|
+
}
|
|
245
|
+
finally {
|
|
246
|
+
clearTimeout(timer);
|
|
247
|
+
options.signal?.removeEventListener("abort", abort);
|
|
248
|
+
}
|
|
249
|
+
// Most replacement gaps need only a reconnect. Startup remains owner-safe.
|
|
250
|
+
if (!recovered && options.recover && performance.now() - started >= 250 && performance.now() < deadline) {
|
|
251
|
+
recovered = true;
|
|
252
|
+
let recovery = recoveries.get(key);
|
|
253
|
+
if (!recovery) {
|
|
254
|
+
const controller = new AbortController();
|
|
255
|
+
const budget = Math.ceil(remaining());
|
|
256
|
+
const timer = setTimeout(() => {
|
|
257
|
+
controller.abort(new Error("runtime-unavailable: reconnect deadline exceeded during recovery"));
|
|
258
|
+
}, budget);
|
|
259
|
+
const promise = waitForRecovery(Promise.resolve().then(() => options.recover({ timeoutMs: budget, signal: controller.signal })), controller.signal)
|
|
260
|
+
.finally(() => clearTimeout(timer));
|
|
261
|
+
recovery = { promise, controller, key };
|
|
262
|
+
recoveries.set(key, recovery);
|
|
263
|
+
void recovery.promise.finally(() => { if (recoveries.get(key) === recovery)
|
|
264
|
+
recoveries.delete(key); }).catch(() => { });
|
|
265
|
+
}
|
|
266
|
+
// A caller can cancel its wait without cancelling another caller's recovery.
|
|
267
|
+
// Keep trying the transport while the owner-safe installer waits.
|
|
268
|
+
// A replacement can accept compatible clients before the pinned
|
|
269
|
+
// installer finishes; waiting for it would stall all subscribers.
|
|
270
|
+
ownedRecovery = recovery;
|
|
271
|
+
void recovery.promise.catch(error => { recoveryError = error; });
|
|
272
|
+
}
|
|
273
|
+
if (performance.now() >= deadline)
|
|
274
|
+
break;
|
|
275
|
+
await delay(Math.min(backoff, remaining()), undefined, { signal: options.signal });
|
|
276
|
+
backoff = Math.min(1000, backoff * 2);
|
|
277
|
+
}
|
|
278
|
+
throw new Error("runtime-unavailable: reconnect deadline exceeded; task state is unknown, retry after recovery", { cause: lastError });
|
|
279
|
+
}
|
|
280
|
+
finally {
|
|
281
|
+
const remainingDemand = connectionDemands.get(key) - 1;
|
|
282
|
+
if (remainingDemand)
|
|
283
|
+
connectionDemands.set(key, remainingDemand);
|
|
284
|
+
else {
|
|
285
|
+
connectionDemands.delete(key);
|
|
286
|
+
const recovery = recoveries.get(key) ?? ownedRecovery;
|
|
287
|
+
if (recovery) {
|
|
288
|
+
recoveries.delete(key);
|
|
289
|
+
recovery.controller.abort();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function waitForRecovery(recovery, signal) {
|
|
295
|
+
return new Promise((resolve, reject) => {
|
|
296
|
+
const finish = (callback, value) => { signal.removeEventListener("abort", abort); callback(value); };
|
|
297
|
+
const abort = () => finish(reject, signal.reason);
|
|
298
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
299
|
+
recovery.then(value => finish(resolve, value), error => finish(reject, error));
|
|
300
|
+
if (signal.aborted)
|
|
301
|
+
abort();
|
|
302
|
+
});
|
|
303
|
+
}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/subagent-tools.ts. Do not edit directly.
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* Guarded: apply_patch, a harness adapter on the guarded file operations.
|
|
6
|
-
* Trusted: a tool ticked in /sandbox, admitted by name AND owning package, whose
|
|
7
|
-
* package is loaded into the child. `toolExtensions` in config.json still picks
|
|
8
|
-
* the package to load (an override), but the loaded package must be the ticked one.
|
|
9
|
-
*/
|
|
2
|
+
/** Bind selected tools to their confined adapter or canonical provider before startup (ADR 0027). */
|
|
3
|
+
import { supportedChildEntrypoint } from "./config.domain.mjs";
|
|
10
4
|
import { canonicalizePath } from "./shared-sandbox-core.domain.mjs";
|
|
11
|
-
import { isNetworkTool, packageLabel,
|
|
5
|
+
import { isNetworkTool, packageLabel, discoverTrustedTools, RESERVED_TOOL_NAMES } from "./shared-task-tools.domain.mjs";
|
|
12
6
|
export const APPLY_PATCH = "apply_patch";
|
|
13
7
|
function specList(value) {
|
|
14
8
|
if (typeof value === "string")
|
|
@@ -17,6 +11,7 @@ function specList(value) {
|
|
|
17
11
|
}
|
|
18
12
|
export function planTaskTools(options) {
|
|
19
13
|
const plan = { applyPatch: false, trusted: [], refused: [] };
|
|
14
|
+
const registered = discoverTrustedTools(options.registered);
|
|
20
15
|
for (const name of options.requested) {
|
|
21
16
|
if (name === "process_list" && options.processAccess !== "read") {
|
|
22
17
|
plan.refused.push({ name, reason: "Process access is Off; enable Read in /sandbox" });
|
|
@@ -25,15 +20,11 @@ export function planTaskTools(options) {
|
|
|
25
20
|
if (options.builtins.includes(name))
|
|
26
21
|
continue;
|
|
27
22
|
if (name === APPLY_PATCH) {
|
|
28
|
-
|
|
29
|
-
plan.applyPatch = true;
|
|
30
|
-
else
|
|
31
|
-
plan.refused.push({ name, reason: "apply_patch is off in /sandbox (Subagents · Tools)" });
|
|
23
|
+
plan.applyPatch = true;
|
|
32
24
|
continue;
|
|
33
25
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
plan.refused.push({ name, reason: "not a guarded tool and not ticked as trusted in /sandbox (Subagents · Tools)" });
|
|
26
|
+
if (RESERVED_TOOL_NAMES.includes(name)) {
|
|
27
|
+
plan.refused.push({ name, reason: "no supported task adapter" });
|
|
37
28
|
continue;
|
|
38
29
|
}
|
|
39
30
|
const network = isNetworkTool(name);
|
|
@@ -41,39 +32,32 @@ export function planTaskTools(options) {
|
|
|
41
32
|
plan.refused.push({ name, reason: "needs Network access, which is Off for subagents" });
|
|
42
33
|
continue;
|
|
43
34
|
}
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
const
|
|
35
|
+
// The selected mapping identifies the implementation. Old saved entries can
|
|
36
|
+
// still identify its package when the worker has no configured mapping.
|
|
37
|
+
const mapped = specList(options.toolExtensions?.[name]);
|
|
38
|
+
const packages = mapped.length ? mapped : options.settings.trusted.filter(tool => tool.name === name).map(tool => tool.package);
|
|
47
39
|
let chosen;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const loadPath = options.resolvePath(entry.package);
|
|
54
|
-
if (loadPath) {
|
|
55
|
-
chosen = { package: entry.package, loadPath };
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
problem = `its package ${packageLabel(entry.package)} is not installed`;
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
const owner = options.registered.map(toolPackage).find((tool) => tool?.name === name && tool.package === entry.package);
|
|
62
|
-
const loadPath = owner?.root ?? (entry.package.startsWith("npm:") ? options.resolvePath(entry.package) : undefined);
|
|
63
|
-
if (loadPath) {
|
|
64
|
-
chosen = { package: entry.package, loadPath };
|
|
40
|
+
for (const pkg of packages) {
|
|
41
|
+
const owner = registered.find(tool => tool.name === name && tool.package === pkg);
|
|
42
|
+
const path = mapped.length ? options.resolvePath(pkg) : owner?.root ?? (pkg.startsWith("npm:") ? options.resolvePath(pkg) : undefined);
|
|
43
|
+
if (path) {
|
|
44
|
+
chosen = { package: pkg, loadPath: path };
|
|
65
45
|
break;
|
|
66
46
|
}
|
|
67
|
-
problem = `its package ${packageLabel(entry.package)} can't be found (not installed or not loaded in this Pi)`;
|
|
68
47
|
}
|
|
69
48
|
if (!chosen) {
|
|
70
|
-
|
|
49
|
+
const reason = packages.length ? `provider ${packages.map(packageLabel).join(", ")} is unavailable` : "no provider selected for this worker";
|
|
50
|
+
plan.refused.push({ name, reason });
|
|
71
51
|
continue;
|
|
72
52
|
}
|
|
73
53
|
// A directory is admitted as a package root; a file admits only itself.
|
|
74
54
|
let root;
|
|
75
55
|
try {
|
|
76
56
|
root = canonicalizePath(chosen.loadPath);
|
|
57
|
+
if (!supportedChildEntrypoint(name, chosen.package, root)) {
|
|
58
|
+
plan.refused.push({ name, reason: "provider requires a supported task adapter" });
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
77
61
|
}
|
|
78
62
|
catch {
|
|
79
63
|
plan.refused.push({ name, reason: `its package path ${chosen.loadPath} can't be resolved` });
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Guarded: apply_patch, a harness adapter on the guarded file operations.
|
|
5
|
-
* Trusted: a tool ticked in /sandbox, admitted by name AND owning package, whose
|
|
6
|
-
* package is loaded into the child. `toolExtensions` in config.json still picks
|
|
7
|
-
* the package to load (an override), but the loaded package must be the ticked one.
|
|
8
|
-
*/
|
|
1
|
+
/** Bind selected tools to their confined adapter or canonical provider before startup (ADR 0027). */
|
|
2
|
+
import { supportedChildEntrypoint } from "./config.ts";
|
|
9
3
|
import { canonicalizePath } from "./shared-sandbox-core.ts";
|
|
10
|
-
import { isNetworkTool, packageLabel,
|
|
4
|
+
import { isNetworkTool, packageLabel, discoverTrustedTools, RESERVED_TOOL_NAMES, type SubagentToolSettings, type ToolSource } from "./shared-task-tools.ts";
|
|
11
5
|
import type { TaskExtensionTool } from "./task-policy.ts";
|
|
12
6
|
|
|
13
7
|
export const APPLY_PATCH = "apply_patch";
|
|
@@ -32,12 +26,13 @@ export function planTaskTools(options: {
|
|
|
32
26
|
network: boolean;
|
|
33
27
|
processAccess?: "off" | "read";
|
|
34
28
|
builtins: readonly string[];
|
|
35
|
-
/** Tools registered in the parent Pi (`pi.getAllTools()`), used to
|
|
29
|
+
/** Tools registered in the parent Pi (`pi.getAllTools()`), used to resolve a legacy provider identity. */
|
|
36
30
|
registered: readonly ToolSource[];
|
|
37
31
|
toolExtensions?: Record<string, string | string[]> | null;
|
|
38
32
|
resolvePath: (spec: string) => string | undefined;
|
|
39
33
|
}): TaskToolPlan {
|
|
40
34
|
const plan: TaskToolPlan = { applyPatch: false, trusted: [], refused: [] };
|
|
35
|
+
const registered = discoverTrustedTools(options.registered);
|
|
41
36
|
for (const name of options.requested) {
|
|
42
37
|
if (name === "process_list" && options.processAccess !== "read") {
|
|
43
38
|
plan.refused.push({ name, reason: "Process access is Off; enable Read in /sandbox" });
|
|
@@ -45,13 +40,11 @@ export function planTaskTools(options: {
|
|
|
45
40
|
}
|
|
46
41
|
if (options.builtins.includes(name)) continue;
|
|
47
42
|
if (name === APPLY_PATCH) {
|
|
48
|
-
|
|
49
|
-
else plan.refused.push({ name, reason: "apply_patch is off in /sandbox (Subagents · Tools)" });
|
|
43
|
+
plan.applyPatch = true;
|
|
50
44
|
continue;
|
|
51
45
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
plan.refused.push({ name, reason: "not a guarded tool and not ticked as trusted in /sandbox (Subagents · Tools)" });
|
|
46
|
+
if (RESERVED_TOOL_NAMES.includes(name)) {
|
|
47
|
+
plan.refused.push({ name, reason: "no supported task adapter" });
|
|
55
48
|
continue;
|
|
56
49
|
}
|
|
57
50
|
const network = isNetworkTool(name);
|
|
@@ -59,32 +52,33 @@ export function planTaskTools(options: {
|
|
|
59
52
|
plan.refused.push({ name, reason: "needs Network access, which is Off for subagents" });
|
|
60
53
|
continue;
|
|
61
54
|
}
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
const
|
|
55
|
+
// The selected mapping identifies the implementation. Old saved entries can
|
|
56
|
+
// still identify its package when the worker has no configured mapping.
|
|
57
|
+
const mapped = specList(options.toolExtensions?.[name]);
|
|
58
|
+
const packages = mapped.length ? mapped : options.settings.trusted.filter(tool => tool.name === name).map(tool => tool.package);
|
|
65
59
|
let chosen: { package: string; loadPath: string } | undefined;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const loadPath = options.resolvePath(entry.package);
|
|
71
|
-
if (loadPath) { chosen = { package: entry.package, loadPath }; break; }
|
|
72
|
-
problem = `its package ${packageLabel(entry.package)} is not installed`;
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
const owner = options.registered.map(toolPackage).find((tool) => tool?.name === name && tool.package === entry.package);
|
|
76
|
-
const loadPath = owner?.root ?? (entry.package.startsWith("npm:") ? options.resolvePath(entry.package) : undefined);
|
|
77
|
-
if (loadPath) { chosen = { package: entry.package, loadPath }; break; }
|
|
78
|
-
problem = `its package ${packageLabel(entry.package)} can't be found (not installed or not loaded in this Pi)`;
|
|
60
|
+
for (const pkg of packages) {
|
|
61
|
+
const owner = registered.find(tool => tool.name === name && tool.package === pkg);
|
|
62
|
+
const path = mapped.length ? options.resolvePath(pkg) : owner?.root ?? (pkg.startsWith("npm:") ? options.resolvePath(pkg) : undefined);
|
|
63
|
+
if (path) { chosen = { package: pkg, loadPath: path }; break; }
|
|
79
64
|
}
|
|
80
65
|
if (!chosen) {
|
|
81
|
-
|
|
66
|
+
const reason = packages.length ? `provider ${packages.map(packageLabel).join(", ")} is unavailable` : "no provider selected for this worker";
|
|
67
|
+
plan.refused.push({ name, reason });
|
|
82
68
|
continue;
|
|
83
69
|
}
|
|
84
70
|
// A directory is admitted as a package root; a file admits only itself.
|
|
85
71
|
let root: string;
|
|
86
|
-
try {
|
|
87
|
-
|
|
72
|
+
try {
|
|
73
|
+
root = canonicalizePath(chosen.loadPath);
|
|
74
|
+
if (!supportedChildEntrypoint(name, chosen.package, root)) {
|
|
75
|
+
plan.refused.push({ name, reason: "provider requires a supported task adapter" });
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
} catch {
|
|
79
|
+
plan.refused.push({ name, reason: `its package path ${chosen.loadPath} can't be resolved` });
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
88
82
|
plan.trusted.push({ name, package: chosen.package, root, network, loadPath: chosen.loadPath });
|
|
89
83
|
}
|
|
90
84
|
return plan;
|
|
@@ -184,7 +184,7 @@ export function prepareTaskRuntime(options) {
|
|
|
184
184
|
tools: options.tools,
|
|
185
185
|
applyPatch: options.applyPatch === true,
|
|
186
186
|
operationBridge: options.tools.some(name => OPERATION_BRIDGE_TOOL_NAMES.includes(name)) &&
|
|
187
|
-
(options.extensionPaths ?? []).some(path => canonicalizePath(path) === canonicalizePath(fileURLToPath(new URL("./child-operations.ts", import.meta.url)))),
|
|
187
|
+
(options.extensionPaths ?? []).some(path => canonicalizePath(path) === canonicalizePath(options.operationBridgePath ?? fileURLToPath(new URL("./child-operations.ts", import.meta.url)))),
|
|
188
188
|
extensionTools: (options.extensionTools ?? []).map((tool) => ({ ...tool, root: canonicalizePath(tool.root) })),
|
|
189
189
|
});
|
|
190
190
|
compileWritePolicy({ writableRoot: root, home, permissions: policy.permissions, denyWrite: policy.denyWrite, runtimeCompatibility: true });
|
|
@@ -175,6 +175,8 @@ export function prepareTaskRuntime(options: {
|
|
|
175
175
|
root: string; controlDir: string; tools: readonly string[]; piBin?: string;
|
|
176
176
|
permissions?: SandboxPermissions & Partial<CommandSettings>; extensionPaths?: readonly string[]; runtimeRoots?: readonly string[];
|
|
177
177
|
capturedDenyWrite?: readonly string[];
|
|
178
|
+
/** Trusted launcher-selected bridge from the pinned worker release. */
|
|
179
|
+
operationBridgePath?: string;
|
|
178
180
|
applyPatch?: boolean; extensionTools?: readonly TaskExtensionTool[];
|
|
179
181
|
}): { file: string; fileArgs: string[]; policy: TaskPolicy; policyPath: string } {
|
|
180
182
|
if (typeof PiCodingAgent.getAgentDir !== "function" || typeof PiCodingAgent.getPackageDir !== "function") {
|
|
@@ -216,7 +218,7 @@ export function prepareTaskRuntime(options: {
|
|
|
216
218
|
tools: options.tools,
|
|
217
219
|
applyPatch: options.applyPatch === true,
|
|
218
220
|
operationBridge: options.tools.some(name => (OPERATION_BRIDGE_TOOL_NAMES as readonly string[]).includes(name)) &&
|
|
219
|
-
(options.extensionPaths ?? []).some(path => canonicalizePath(path) === canonicalizePath(fileURLToPath(new URL("./child-operations.ts", import.meta.url)))),
|
|
221
|
+
(options.extensionPaths ?? []).some(path => canonicalizePath(path) === canonicalizePath(options.operationBridgePath ?? fileURLToPath(new URL("./child-operations.ts", import.meta.url)))),
|
|
220
222
|
extensionTools: (options.extensionTools ?? []).map((tool) => ({ ...tool, root: canonicalizePath(tool.root) })),
|
|
221
223
|
});
|
|
222
224
|
compileWritePolicy({ writableRoot: root, home, permissions: policy.permissions, denyWrite: policy.denyWrite, runtimeCompatibility: true });
|
|
@@ -235,7 +235,7 @@ function isProgressResult(name, command, afterFailure, novel) {
|
|
|
235
235
|
/** Cheap pre-filter: only these rows can change progress state. */
|
|
236
236
|
export function isProgressRelevantLine(line) {
|
|
237
237
|
const head = line.slice(0, 160);
|
|
238
|
-
return head.includes('"tool_execution_start"') || head.includes('"message_end"');
|
|
238
|
+
return head.includes('"tool_execution_start"') || head.includes('"tool_execution_end"') || head.includes('"message_end"');
|
|
239
239
|
}
|
|
240
240
|
/** Fold one parsed child event into the progress state. */
|
|
241
241
|
export function foldProgress(state, event) {
|
|
@@ -276,6 +276,15 @@ export function foldProgress(state, event) {
|
|
|
276
276
|
});
|
|
277
277
|
return;
|
|
278
278
|
}
|
|
279
|
+
if (type === "tool_execution_end" && typeof event.parentToolCallId === "string") {
|
|
280
|
+
// Nested calls do not get a transcript toolResult. The outer call still
|
|
281
|
+
// owns progress accounting through its timestamped result message.
|
|
282
|
+
const id = event.toolCallId;
|
|
283
|
+
if (typeof id === "string" && state.open.delete(id) && state.open.size === 0) {
|
|
284
|
+
state.inFlightSince = undefined;
|
|
285
|
+
}
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
279
288
|
if (type !== "message_end")
|
|
280
289
|
return;
|
|
281
290
|
const message = event.message;
|
|
@@ -350,7 +350,7 @@ function isProgressResult(name: string, command: string | undefined, afterFailur
|
|
|
350
350
|
/** Cheap pre-filter: only these rows can change progress state. */
|
|
351
351
|
export function isProgressRelevantLine(line: string): boolean {
|
|
352
352
|
const head = line.slice(0, 160);
|
|
353
|
-
return head.includes('"tool_execution_start"') || head.includes('"message_end"');
|
|
353
|
+
return head.includes('"tool_execution_start"') || head.includes('"tool_execution_end"') || head.includes('"message_end"');
|
|
354
354
|
}
|
|
355
355
|
|
|
356
356
|
/** Fold one parsed child event into the progress state. */
|
|
@@ -390,6 +390,15 @@ export function foldProgress(state: ProgressState, event: Record<string, unknown
|
|
|
390
390
|
});
|
|
391
391
|
return;
|
|
392
392
|
}
|
|
393
|
+
if (type === "tool_execution_end" && typeof event.parentToolCallId === "string") {
|
|
394
|
+
// Nested calls do not get a transcript toolResult. The outer call still
|
|
395
|
+
// owns progress accounting through its timestamped result message.
|
|
396
|
+
const id = event.toolCallId;
|
|
397
|
+
if (typeof id === "string" && state.open.delete(id) && state.open.size === 0) {
|
|
398
|
+
state.inFlightSince = undefined;
|
|
399
|
+
}
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
393
402
|
if (type !== "message_end") return;
|
|
394
403
|
const message = event.message as Record<string, unknown> | undefined;
|
|
395
404
|
const at = typeof message?.timestamp === "number" && Number.isFinite(message.timestamp) ? message.timestamp : undefined;
|