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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { mkdirSync, readFileSync, realpathSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
|
-
import {
|
|
5
|
+
import { connectWorkClient } from "./shared-work-client.mjs";
|
|
6
6
|
export const TERMINAL_NAVIGATOR_RETENTION_MS = 30_000;
|
|
7
7
|
let client;
|
|
8
8
|
let snapshot;
|
|
@@ -15,10 +15,18 @@ let retry;
|
|
|
15
15
|
let backoff = 100;
|
|
16
16
|
let failure = "Shared runtime observation is connecting.";
|
|
17
17
|
let generation = 0;
|
|
18
|
+
let connectionAbort = new AbortController();
|
|
18
19
|
const details = new Map();
|
|
19
20
|
const pendingDetails = new Set();
|
|
20
21
|
let refresh = () => { };
|
|
22
|
+
const observationListeners = new Set();
|
|
23
|
+
export function onWorkObservation(notify) {
|
|
24
|
+
observationListeners.add(notify);
|
|
25
|
+
return () => { observationListeners.delete(notify); };
|
|
26
|
+
}
|
|
21
27
|
export function workObservation() { return snapshot; }
|
|
28
|
+
export function hasWorkObservationContext() { return context !== undefined; }
|
|
29
|
+
export function workObservationStarted() { return Boolean(connecting || client || retry || snapshot); }
|
|
22
30
|
export function workObservationFailure() { return snapshot?.reason ?? failure; }
|
|
23
31
|
function degraded(error) {
|
|
24
32
|
failure = String(error);
|
|
@@ -38,7 +46,7 @@ function reconnectLater(current) {
|
|
|
38
46
|
retry.unref?.();
|
|
39
47
|
backoff = Math.min(2000, backoff * 2);
|
|
40
48
|
}
|
|
41
|
-
// Every page is bounded;
|
|
49
|
+
// Every page is bounded; a conversation anchor fences collection across filtered queries.
|
|
42
50
|
async function collect(candidate, current) {
|
|
43
51
|
dirty = true;
|
|
44
52
|
if (collecting && collectingClient === candidate)
|
|
@@ -51,25 +59,32 @@ async function collect(candidate, current) {
|
|
|
51
59
|
let completed = false;
|
|
52
60
|
for (let attempt = 0; attempt < 2 && !completed; attempt++) {
|
|
53
61
|
try {
|
|
62
|
+
const anchorScope = { ...context.origin, limit: 1 };
|
|
63
|
+
const anchor = await candidate.get(anchorScope);
|
|
54
64
|
const first = await candidate.get(scope);
|
|
55
65
|
if (current !== generation || candidate !== client)
|
|
56
66
|
return;
|
|
57
67
|
if (first.status === "rebuilding") {
|
|
58
68
|
snapshot = { ...first, rows: snapshot?.rows ?? [] };
|
|
59
69
|
refresh();
|
|
60
|
-
|
|
70
|
+
// A newer publication may already be owed while this page
|
|
71
|
+
// was in flight. Drain that demand, but never poll for it.
|
|
72
|
+
break;
|
|
61
73
|
}
|
|
62
74
|
const rows = [...first.rows];
|
|
63
75
|
let cursor = first.nextCursor;
|
|
64
76
|
while (cursor) {
|
|
65
77
|
const page = await candidate.get({ ...scope, cursor });
|
|
66
|
-
if (page.
|
|
78
|
+
if (page.scopeRevision !== first.scopeRevision || page.instanceId !== first.instanceId)
|
|
67
79
|
throw new Error("resync_required: active pages changed");
|
|
68
80
|
rows.push(...page.rows);
|
|
69
81
|
cursor = page.nextCursor;
|
|
70
82
|
}
|
|
71
|
-
|
|
72
|
-
|
|
83
|
+
// Cover the disconnect interval, not merely the last 30 s of
|
|
84
|
+
// worker time. The navigator starts its own visibility clock.
|
|
85
|
+
const endedAfter = Math.min(Date.now() - TERMINAL_NAVIGATOR_RETENTION_MS, snapshot?.observedAtLocal ?? Date.now());
|
|
86
|
+
const history = await candidate.get({ ...context.origin, active: false, endedAfter, limit: 200 });
|
|
87
|
+
if (history.instanceId !== first.instanceId)
|
|
73
88
|
throw new Error("resync_required: history changed");
|
|
74
89
|
if (current !== generation || candidate !== client)
|
|
75
90
|
return;
|
|
@@ -77,15 +92,32 @@ async function collect(candidate, current) {
|
|
|
77
92
|
let owedCursor;
|
|
78
93
|
do {
|
|
79
94
|
const page = await candidate.get({ ...context.origin, pendingRecipient: true, limit: 200, ...(owedCursor ? { cursor: owedCursor } : {}) });
|
|
80
|
-
if (page.
|
|
95
|
+
if (page.instanceId !== first.instanceId)
|
|
81
96
|
throw new Error("resync_required: recipient page changed");
|
|
82
97
|
owed.push(...page.rows);
|
|
83
98
|
owedCursor = page.nextCursor;
|
|
84
99
|
} while (owedCursor);
|
|
85
100
|
if (current !== generation || candidate !== client)
|
|
86
101
|
return;
|
|
87
|
-
const
|
|
88
|
-
|
|
102
|
+
const historyRows = [...history.rows];
|
|
103
|
+
let historyCursor = history.nextCursor;
|
|
104
|
+
while (historyCursor) {
|
|
105
|
+
const page = await candidate.get({ ...context.origin, active: false, endedAfter, limit: 200, cursor: historyCursor });
|
|
106
|
+
if (page.scopeRevision !== history.scopeRevision || page.instanceId !== first.instanceId)
|
|
107
|
+
throw new Error("resync_required: history pages changed");
|
|
108
|
+
historyRows.push(...page.rows);
|
|
109
|
+
historyCursor = page.nextCursor;
|
|
110
|
+
}
|
|
111
|
+
if (current !== generation || candidate !== client)
|
|
112
|
+
return;
|
|
113
|
+
const confirmed = await candidate.get(anchorScope);
|
|
114
|
+
if (current !== generation || candidate !== client)
|
|
115
|
+
return;
|
|
116
|
+
if (confirmed.instanceId !== anchor.instanceId || confirmed.scopeRevision !== anchor.scopeRevision)
|
|
117
|
+
throw new Error("resync_required: conversation changed during collection");
|
|
118
|
+
const allRows = [...new Map([...rows, ...historyRows, ...owed].map(row => [row.meta.id, row])).values()];
|
|
119
|
+
snapshot = { ...first, seq: anchor.seq, observedRevisionVector: anchor.observedRevisionVector, rows: allRows, nextCursor: undefined,
|
|
120
|
+
observedAtLocal: Date.now(),
|
|
89
121
|
totalMatching: first.totalMatching + history.totalMatching, activity: { active: rows.length } };
|
|
90
122
|
completed = true;
|
|
91
123
|
refresh();
|
|
@@ -111,6 +143,7 @@ async function collect(candidate, current) {
|
|
|
111
143
|
}
|
|
112
144
|
async function connectObservation(current) {
|
|
113
145
|
const saved = context;
|
|
146
|
+
const signal = connectionAbort.signal;
|
|
114
147
|
mkdirSync(saved.agentDir, { recursive: true, mode: 0o700 });
|
|
115
148
|
saved.agentDir = realpathSync(saved.agentDir);
|
|
116
149
|
let registration;
|
|
@@ -122,7 +155,7 @@ async function connectObservation(current) {
|
|
|
122
155
|
throw error;
|
|
123
156
|
const path = "./runtime-client/src/runtime/client.mjs";
|
|
124
157
|
const { ensureRuntime } = await import(path);
|
|
125
|
-
await ensureRuntime({ agentDir: saved.agentDir });
|
|
158
|
+
await ensureRuntime({ agentDir: saved.agentDir, signal });
|
|
126
159
|
registration = JSON.parse(readFileSync(join(saved.agentDir, "server-registration-v1.json"), "utf8"));
|
|
127
160
|
}
|
|
128
161
|
if (current !== generation)
|
|
@@ -130,7 +163,18 @@ async function connectObservation(current) {
|
|
|
130
163
|
if (registration.version !== 1 || registration.agentDir !== saved.agentDir)
|
|
131
164
|
throw new Error("Invalid canonical runtime registration");
|
|
132
165
|
client?.close();
|
|
133
|
-
const candidate =
|
|
166
|
+
const candidate = await connectWorkClient(join(registration.serverDir, "pi-server.sock"), saved.agentDir, [], {
|
|
167
|
+
signal,
|
|
168
|
+
recover: async ({ timeoutMs, signal }) => {
|
|
169
|
+
const path = "./runtime-client/src/runtime/client.mjs";
|
|
170
|
+
const { ensureRuntime } = await import(path);
|
|
171
|
+
await ensureRuntime({ agentDir: saved.agentDir, serverDir: registration.serverDir, timeoutMs, signal });
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
if (current !== generation) {
|
|
175
|
+
candidate.close();
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
134
178
|
client = candidate;
|
|
135
179
|
candidate.onChange(() => {
|
|
136
180
|
if (current !== generation || candidate !== client)
|
|
@@ -145,7 +189,7 @@ async function connectObservation(current) {
|
|
|
145
189
|
void collect(candidate, current).catch(error => { if (current === generation)
|
|
146
190
|
degraded(error); });
|
|
147
191
|
});
|
|
148
|
-
await candidate.subscribe({ ...saved.origin,
|
|
192
|
+
await candidate.subscribe({ ...saved.origin, limit: 200 });
|
|
149
193
|
if (candidate.snapshot?.status === "rebuilding")
|
|
150
194
|
await new Promise((resolve, reject) => {
|
|
151
195
|
const timer = setTimeout(() => { stop(); reject(new Error("Runtime scope is still rebuilding; retry the observation.")); }, 5000);
|
|
@@ -167,11 +211,19 @@ async function connectObservation(current) {
|
|
|
167
211
|
retry = undefined;
|
|
168
212
|
}
|
|
169
213
|
}
|
|
170
|
-
export
|
|
214
|
+
export function configureWorkObservation(agentDir, origin, changed) {
|
|
171
215
|
stopWorkObservation();
|
|
172
|
-
const current = generation;
|
|
173
216
|
context = { agentDir, origin };
|
|
174
|
-
refresh =
|
|
217
|
+
refresh = () => {
|
|
218
|
+
changed();
|
|
219
|
+
for (const notify of observationListeners)
|
|
220
|
+
notify();
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
export async function activateWorkObservation() {
|
|
224
|
+
if (!context)
|
|
225
|
+
return;
|
|
226
|
+
const current = generation;
|
|
175
227
|
try {
|
|
176
228
|
await ensureObservation();
|
|
177
229
|
}
|
|
@@ -182,6 +234,10 @@ export async function startWorkObservation(agentDir, origin, changed) {
|
|
|
182
234
|
}
|
|
183
235
|
}
|
|
184
236
|
}
|
|
237
|
+
export async function startWorkObservation(agentDir, origin, changed) {
|
|
238
|
+
configureWorkObservation(agentDir, origin, changed);
|
|
239
|
+
await activateWorkObservation();
|
|
240
|
+
}
|
|
185
241
|
async function ensureObservation() {
|
|
186
242
|
if (connecting)
|
|
187
243
|
return connecting;
|
|
@@ -194,13 +250,16 @@ async function ensureObservation() {
|
|
|
194
250
|
return connecting;
|
|
195
251
|
}
|
|
196
252
|
async function query(scope) {
|
|
253
|
+
const current = generation;
|
|
197
254
|
for (let attempt = 0;; attempt++) {
|
|
198
255
|
try {
|
|
199
256
|
await ensureObservation();
|
|
257
|
+
if (current !== generation)
|
|
258
|
+
throw new Error("runtime-unavailable: observation closed");
|
|
200
259
|
return await client.get(scope);
|
|
201
260
|
}
|
|
202
261
|
catch (error) {
|
|
203
|
-
if ((client && !client.closed) || attempt === 1)
|
|
262
|
+
if (current !== generation || (client && !client.closed) || attempt === 1)
|
|
204
263
|
throw error;
|
|
205
264
|
}
|
|
206
265
|
}
|
|
@@ -216,6 +275,8 @@ export async function observedList(scope) { return query(scope); }
|
|
|
216
275
|
export function stopWorkObservation() {
|
|
217
276
|
generation++;
|
|
218
277
|
context = undefined;
|
|
278
|
+
connectionAbort.abort();
|
|
279
|
+
connectionAbort = new AbortController();
|
|
219
280
|
if (retry)
|
|
220
281
|
clearTimeout(retry);
|
|
221
282
|
retry = undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdirSync, readFileSync, realpathSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
-
import { WorkClient } from "./shared-work-client.mjs";
|
|
4
|
+
import { WorkClient, connectWorkClient } from "./shared-work-client.mjs";
|
|
5
5
|
export const TERMINAL_NAVIGATOR_RETENTION_MS = 30_000;
|
|
6
6
|
|
|
7
7
|
let client: WorkClient | undefined;
|
|
@@ -15,11 +15,19 @@ let retry: ReturnType<typeof setTimeout> | undefined;
|
|
|
15
15
|
let backoff = 100;
|
|
16
16
|
let failure = "Shared runtime observation is connecting.";
|
|
17
17
|
let generation = 0;
|
|
18
|
+
let connectionAbort = new AbortController();
|
|
18
19
|
const details = new Map<string, any>();
|
|
19
20
|
const pendingDetails = new Set<string>();
|
|
20
21
|
let refresh = () => {};
|
|
22
|
+
const observationListeners = new Set<() => void>();
|
|
23
|
+
export function onWorkObservation(notify: () => void) {
|
|
24
|
+
observationListeners.add(notify);
|
|
25
|
+
return () => { observationListeners.delete(notify); };
|
|
26
|
+
}
|
|
21
27
|
|
|
22
28
|
export function workObservation() { return snapshot; }
|
|
29
|
+
export function hasWorkObservationContext() { return context !== undefined; }
|
|
30
|
+
export function workObservationStarted() { return Boolean(connecting || client || retry || snapshot); }
|
|
23
31
|
export function workObservationFailure() { return snapshot?.reason ?? failure; }
|
|
24
32
|
|
|
25
33
|
function degraded(error: unknown) {
|
|
@@ -38,7 +46,7 @@ function reconnectLater(current: number) {
|
|
|
38
46
|
backoff = Math.min(2000, backoff * 2);
|
|
39
47
|
}
|
|
40
48
|
|
|
41
|
-
// Every page is bounded;
|
|
49
|
+
// Every page is bounded; a conversation anchor fences collection across filtered queries.
|
|
42
50
|
async function collect(candidate: WorkClient, current: number) {
|
|
43
51
|
dirty = true;
|
|
44
52
|
if (collecting && collectingClient === candidate) return collecting;
|
|
@@ -50,31 +58,51 @@ async function collect(candidate: WorkClient, current: number) {
|
|
|
50
58
|
let completed = false;
|
|
51
59
|
for (let attempt = 0; attempt < 2 && !completed; attempt++) {
|
|
52
60
|
try {
|
|
61
|
+
const anchorScope = { ...context!.origin, limit: 1 };
|
|
62
|
+
const anchor = await candidate.get(anchorScope);
|
|
53
63
|
const first = await candidate.get(scope);
|
|
54
64
|
if (current !== generation || candidate !== client) return;
|
|
55
65
|
if (first.status === "rebuilding") {
|
|
56
|
-
snapshot = { ...first, rows: snapshot?.rows ?? [] }; refresh();
|
|
66
|
+
snapshot = { ...first, rows: snapshot?.rows ?? [] }; refresh();
|
|
67
|
+
// A newer publication may already be owed while this page
|
|
68
|
+
// was in flight. Drain that demand, but never poll for it.
|
|
69
|
+
break;
|
|
57
70
|
}
|
|
58
71
|
const rows = [...first.rows];
|
|
59
72
|
let cursor = first.nextCursor;
|
|
60
73
|
while (cursor) {
|
|
61
74
|
const page = await candidate.get({ ...scope, cursor });
|
|
62
|
-
if (page.
|
|
75
|
+
if (page.scopeRevision !== first.scopeRevision || page.instanceId !== first.instanceId) throw new Error("resync_required: active pages changed");
|
|
63
76
|
rows.push(...page.rows); cursor = page.nextCursor;
|
|
64
77
|
}
|
|
65
|
-
|
|
66
|
-
|
|
78
|
+
// Cover the disconnect interval, not merely the last 30 s of
|
|
79
|
+
// worker time. The navigator starts its own visibility clock.
|
|
80
|
+
const endedAfter = Math.min(Date.now() - TERMINAL_NAVIGATOR_RETENTION_MS, snapshot?.observedAtLocal ?? Date.now());
|
|
81
|
+
const history = await candidate.get({ ...context!.origin, active: false, endedAfter, limit: 200 });
|
|
82
|
+
if (history.instanceId !== first.instanceId) throw new Error("resync_required: history changed");
|
|
67
83
|
if (current !== generation || candidate !== client) return;
|
|
68
84
|
const owed = [];
|
|
69
85
|
let owedCursor: string | undefined;
|
|
70
86
|
do {
|
|
71
87
|
const page = await candidate.get({ ...context!.origin, pendingRecipient: true, limit: 200, ...(owedCursor ? { cursor: owedCursor } : {}) });
|
|
72
|
-
if (page.
|
|
88
|
+
if (page.instanceId !== first.instanceId) throw new Error("resync_required: recipient page changed");
|
|
73
89
|
owed.push(...page.rows); owedCursor = page.nextCursor;
|
|
74
90
|
} while (owedCursor);
|
|
75
91
|
if (current !== generation || candidate !== client) return;
|
|
76
|
-
const
|
|
77
|
-
|
|
92
|
+
const historyRows = [...history.rows];
|
|
93
|
+
let historyCursor = history.nextCursor;
|
|
94
|
+
while (historyCursor) {
|
|
95
|
+
const page = await candidate.get({ ...context!.origin, active: false, endedAfter, limit: 200, cursor: historyCursor });
|
|
96
|
+
if (page.scopeRevision !== history.scopeRevision || page.instanceId !== first.instanceId) throw new Error("resync_required: history pages changed");
|
|
97
|
+
historyRows.push(...page.rows); historyCursor = page.nextCursor;
|
|
98
|
+
}
|
|
99
|
+
if (current !== generation || candidate !== client) return;
|
|
100
|
+
const confirmed = await candidate.get(anchorScope);
|
|
101
|
+
if (current !== generation || candidate !== client) return;
|
|
102
|
+
if (confirmed.instanceId !== anchor.instanceId || confirmed.scopeRevision !== anchor.scopeRevision) throw new Error("resync_required: conversation changed during collection");
|
|
103
|
+
const allRows = [...new Map([...rows, ...historyRows, ...owed].map(row => [row.meta.id, row])).values()];
|
|
104
|
+
snapshot = { ...first, seq: anchor.seq, observedRevisionVector: anchor.observedRevisionVector, rows: allRows, nextCursor: undefined,
|
|
105
|
+
observedAtLocal: Date.now(),
|
|
78
106
|
totalMatching: first.totalMatching + history.totalMatching, activity: { active: rows.length } };
|
|
79
107
|
completed = true; refresh();
|
|
80
108
|
} catch (error) {
|
|
@@ -96,6 +124,7 @@ async function collect(candidate: WorkClient, current: number) {
|
|
|
96
124
|
|
|
97
125
|
async function connectObservation(current: number) {
|
|
98
126
|
const saved = context!;
|
|
127
|
+
const signal = connectionAbort.signal;
|
|
99
128
|
mkdirSync(saved.agentDir, { recursive: true, mode: 0o700 });
|
|
100
129
|
saved.agentDir = realpathSync(saved.agentDir);
|
|
101
130
|
let registration;
|
|
@@ -104,13 +133,21 @@ async function connectObservation(current: number) {
|
|
|
104
133
|
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
105
134
|
const path = "./runtime-client/src/runtime/client.mjs";
|
|
106
135
|
const { ensureRuntime } = await import(path);
|
|
107
|
-
await ensureRuntime({ agentDir: saved.agentDir });
|
|
136
|
+
await ensureRuntime({ agentDir: saved.agentDir, signal });
|
|
108
137
|
registration = JSON.parse(readFileSync(join(saved.agentDir, "server-registration-v1.json"), "utf8"));
|
|
109
138
|
}
|
|
110
139
|
if (current !== generation) return;
|
|
111
140
|
if (registration.version !== 1 || registration.agentDir !== saved.agentDir) throw new Error("Invalid canonical runtime registration");
|
|
112
141
|
client?.close();
|
|
113
|
-
const candidate =
|
|
142
|
+
const candidate = await connectWorkClient(join(registration.serverDir, "pi-server.sock"), saved.agentDir, [], {
|
|
143
|
+
signal,
|
|
144
|
+
recover: async ({ timeoutMs, signal }) => {
|
|
145
|
+
const path = "./runtime-client/src/runtime/client.mjs";
|
|
146
|
+
const { ensureRuntime } = await import(path);
|
|
147
|
+
await ensureRuntime({ agentDir: saved.agentDir, serverDir: registration.serverDir, timeoutMs, signal });
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
if (current !== generation) { candidate.close(); return; }
|
|
114
151
|
client = candidate;
|
|
115
152
|
candidate.onChange(() => {
|
|
116
153
|
if (current !== generation || candidate !== client) return;
|
|
@@ -120,7 +157,7 @@ async function connectObservation(current: number) {
|
|
|
120
157
|
reconnectLater(current);
|
|
121
158
|
} else void collect(candidate, current).catch(error => { if (current === generation) degraded(error); });
|
|
122
159
|
});
|
|
123
|
-
await candidate.subscribe({ ...saved.origin,
|
|
160
|
+
await candidate.subscribe({ ...saved.origin, limit: 200 });
|
|
124
161
|
if (candidate.snapshot?.status === "rebuilding") await new Promise<void>((resolve, reject) => {
|
|
125
162
|
const timer = setTimeout(() => { stop(); reject(new Error("Runtime scope is still rebuilding; retry the observation.")); }, 5000);
|
|
126
163
|
const stop = candidate.onChange(value => {
|
|
@@ -132,14 +169,26 @@ async function connectObservation(current: number) {
|
|
|
132
169
|
if (current === generation) { backoff = 100; if (retry) clearTimeout(retry); retry = undefined; }
|
|
133
170
|
}
|
|
134
171
|
|
|
135
|
-
export
|
|
172
|
+
export function configureWorkObservation(agentDir: string, origin: { cwd: string; sessionId?: string }, changed: () => void) {
|
|
136
173
|
stopWorkObservation();
|
|
174
|
+
context = { agentDir, origin }; refresh = () => {
|
|
175
|
+
changed();
|
|
176
|
+
for (const notify of observationListeners) notify();
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export async function activateWorkObservation() {
|
|
181
|
+
if (!context) return;
|
|
137
182
|
const current = generation;
|
|
138
|
-
context = { agentDir, origin }; refresh = changed;
|
|
139
183
|
try { await ensureObservation(); }
|
|
140
184
|
catch (error) { if (current === generation) { degraded(error); reconnectLater(current); } }
|
|
141
185
|
}
|
|
142
186
|
|
|
187
|
+
export async function startWorkObservation(agentDir: string, origin: { cwd: string; sessionId?: string }, changed: () => void) {
|
|
188
|
+
configureWorkObservation(agentDir, origin, changed);
|
|
189
|
+
await activateWorkObservation();
|
|
190
|
+
}
|
|
191
|
+
|
|
143
192
|
async function ensureObservation() {
|
|
144
193
|
if (connecting) return connecting;
|
|
145
194
|
if (client && !client.closed) return;
|
|
@@ -150,9 +199,14 @@ async function ensureObservation() {
|
|
|
150
199
|
}
|
|
151
200
|
|
|
152
201
|
async function query(scope: object) {
|
|
202
|
+
const current = generation;
|
|
153
203
|
for (let attempt = 0; ; attempt++) {
|
|
154
|
-
try {
|
|
155
|
-
|
|
204
|
+
try {
|
|
205
|
+
await ensureObservation();
|
|
206
|
+
if (current !== generation) throw new Error("runtime-unavailable: observation closed");
|
|
207
|
+
return await client!.get(scope);
|
|
208
|
+
}
|
|
209
|
+
catch (error) { if (current !== generation || (client && !client.closed) || attempt === 1) throw error; }
|
|
156
210
|
}
|
|
157
211
|
}
|
|
158
212
|
|
|
@@ -167,6 +221,7 @@ export async function observedList(scope: object) { return query(scope); }
|
|
|
167
221
|
|
|
168
222
|
export function stopWorkObservation() {
|
|
169
223
|
generation++; context = undefined;
|
|
224
|
+
connectionAbort.abort(); connectionAbort = new AbortController();
|
|
170
225
|
if (retry) clearTimeout(retry); retry = undefined;
|
|
171
226
|
client?.close(); client = undefined; snapshot = undefined;
|
|
172
227
|
connecting = undefined; collecting = undefined; collectingClient = undefined; dirty = false;
|
|
@@ -169,6 +169,7 @@ export async function createOperationBridgeHost(options = {}) {
|
|
|
169
169
|
? { checkpointEvidenceValidator: registration.checkpointEvidenceValidator }
|
|
170
170
|
: {}),
|
|
171
171
|
handlers: Object.freeze({ ...registration.handlers }),
|
|
172
|
+
onToolRejected: registration.onToolRejected,
|
|
172
173
|
descriptor,
|
|
173
174
|
});
|
|
174
175
|
runs.set(registration.runId, {
|
|
@@ -469,13 +470,17 @@ export async function createOperationBridgeHost(options = {}) {
|
|
|
469
470
|
return;
|
|
470
471
|
}
|
|
471
472
|
const params = (envelope.params ?? {});
|
|
473
|
+
const reject = (error) => {
|
|
474
|
+
run.registration.onToolRejected?.(error, makeContext(run, envelope, new AbortController().signal));
|
|
475
|
+
sendError(socket, envelope.id, error);
|
|
476
|
+
};
|
|
472
477
|
if (findSecretField(params)) {
|
|
473
|
-
|
|
478
|
+
reject({ code: "authority-field", message: "request contains a credential-shaped field" });
|
|
474
479
|
return;
|
|
475
480
|
}
|
|
476
481
|
const bridgeEnvironmentField = findBridgeEnvironmentKey(params);
|
|
477
482
|
if (bridgeEnvironmentField) {
|
|
478
|
-
|
|
483
|
+
reject({
|
|
479
484
|
code: "bridge-env-leak",
|
|
480
485
|
message: `${bridgeEnvironmentField} is a parent bridge credential and cannot be passed to a launched task`,
|
|
481
486
|
});
|
|
@@ -484,7 +489,7 @@ export async function createOperationBridgeHost(options = {}) {
|
|
|
484
489
|
}
|
|
485
490
|
const authorityField = findAuthorityField(params);
|
|
486
491
|
if (authorityField) {
|
|
487
|
-
|
|
492
|
+
reject({
|
|
488
493
|
code: "authority-field",
|
|
489
494
|
message: `caller field ${authorityField} would override parent authority`,
|
|
490
495
|
});
|
|
@@ -493,7 +498,7 @@ export async function createOperationBridgeHost(options = {}) {
|
|
|
493
498
|
}
|
|
494
499
|
const schema = validateJsonSchema(descriptor.parameters, params);
|
|
495
500
|
if (!schema.ok) {
|
|
496
|
-
|
|
501
|
+
reject({
|
|
497
502
|
code: "schema-invalid",
|
|
498
503
|
message: `${schema.path}: ${schema.message}`,
|
|
499
504
|
});
|
|
@@ -139,6 +139,8 @@ export interface OperationRunRegistration {
|
|
|
139
139
|
* against the parent's own records before the checkpoint handler runs.
|
|
140
140
|
*/
|
|
141
141
|
checkpointEvidenceValidator?: OperationCheckpointEvidenceCheck;
|
|
142
|
+
/** Synchronous parent diagnostic hook after authentication, before handler dispatch. */
|
|
143
|
+
onToolRejected?: (error: OperationBridgeErrorBody, context: OperationRequestContext) => void;
|
|
142
144
|
handlers: OperationRunHandlers;
|
|
143
145
|
/** Test-only or pre-provisioned token. Production should omit this and use the generated value. */
|
|
144
146
|
token?: string;
|
|
@@ -209,6 +211,7 @@ interface FrozenRegistration {
|
|
|
209
211
|
tools: readonly OperationToolDescriptor[];
|
|
210
212
|
ownership: OperationOwnershipCheck;
|
|
211
213
|
checkpointEvidenceValidator?: OperationCheckpointEvidenceCheck;
|
|
214
|
+
onToolRejected?: OperationRunRegistration["onToolRejected"];
|
|
212
215
|
handlers: OperationRunHandlers;
|
|
213
216
|
descriptor: OperationBridgeDescriptor;
|
|
214
217
|
}
|
|
@@ -401,6 +404,7 @@ export async function createOperationBridgeHost(
|
|
|
401
404
|
? { checkpointEvidenceValidator: registration.checkpointEvidenceValidator }
|
|
402
405
|
: {}),
|
|
403
406
|
handlers: Object.freeze({ ...registration.handlers }),
|
|
407
|
+
onToolRejected: registration.onToolRejected,
|
|
404
408
|
descriptor,
|
|
405
409
|
});
|
|
406
410
|
runs.set(registration.runId, {
|
|
@@ -698,13 +702,17 @@ export async function createOperationBridgeHost(
|
|
|
698
702
|
return;
|
|
699
703
|
}
|
|
700
704
|
const params = (envelope.params ?? {}) as JsonRecord;
|
|
705
|
+
const reject = (error: OperationBridgeErrorBody): void => {
|
|
706
|
+
run.registration.onToolRejected?.(error, makeContext(run, envelope, new AbortController().signal));
|
|
707
|
+
sendError(socket, envelope.id, error);
|
|
708
|
+
};
|
|
701
709
|
if (findSecretField(params)) {
|
|
702
|
-
|
|
710
|
+
reject({ code: "authority-field", message: "request contains a credential-shaped field" });
|
|
703
711
|
return;
|
|
704
712
|
}
|
|
705
713
|
const bridgeEnvironmentField = findBridgeEnvironmentKey(params);
|
|
706
714
|
if (bridgeEnvironmentField) {
|
|
707
|
-
|
|
715
|
+
reject({
|
|
708
716
|
code: "bridge-env-leak",
|
|
709
717
|
message: `${bridgeEnvironmentField} is a parent bridge credential and cannot be passed to a launched task`,
|
|
710
718
|
});
|
|
@@ -713,7 +721,7 @@ export async function createOperationBridgeHost(
|
|
|
713
721
|
}
|
|
714
722
|
const authorityField = findAuthorityField(params);
|
|
715
723
|
if (authorityField) {
|
|
716
|
-
|
|
724
|
+
reject({
|
|
717
725
|
code: "authority-field",
|
|
718
726
|
message: `caller field ${authorityField} would override parent authority`,
|
|
719
727
|
});
|
|
@@ -722,7 +730,7 @@ export async function createOperationBridgeHost(
|
|
|
722
730
|
}
|
|
723
731
|
const schema = validateJsonSchema(descriptor.parameters, params);
|
|
724
732
|
if (!schema.ok) {
|
|
725
|
-
|
|
733
|
+
reject({
|
|
726
734
|
code: "schema-invalid",
|
|
727
735
|
message: `${schema.path}: ${schema.message}`,
|
|
728
736
|
});
|