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,5 +1,7 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/index.ts. Do not edit directly.
|
|
2
|
+
import { shouldRestoreWorkObservation } from "./shared-work-client.mjs";
|
|
2
3
|
import { appendTimingWake, removeTimingReceipt, receiptTimingWake, timingWakeReceipt } from "./timing-notifications.domain.mjs";
|
|
4
|
+
import { captureLaunchContext } from "./launch-context.domain.mjs";
|
|
3
5
|
/**
|
|
4
6
|
* pi-better-subagents — Claude Code-style async subagents for pi.
|
|
5
7
|
*
|
|
@@ -16,7 +18,7 @@ import { createAssignmentProjector } from "./assignment-projection.mjs";
|
|
|
16
18
|
import { historicalWaits, attentionRevision, attentionDismissed, dismissAttention } from "./historical-attention.domain.mjs";
|
|
17
19
|
import { registerAssignmentAttempt, commitAssignmentTerminal, readOutcome, receiptOutcome, outcomeTranscriptReceipt, inspectOutcome, createOutcomeHost, closeOutcomeHost, claimOutcome } from "./assignment-outcomes.domain.mjs";
|
|
18
20
|
import { currentSandboxPermissions } from "./permission-policy.domain.mjs";
|
|
19
|
-
import { createToolDescriptor } from "./operation-bridge-types.domain.mjs";
|
|
21
|
+
import { assertWaitToolDependencies, createToolDescriptor } from "./operation-bridge-types.domain.mjs";
|
|
20
22
|
import { requestResumeAdmission } from "./worker-waits.domain.mjs";
|
|
21
23
|
import { execSync } from "node:child_process";
|
|
22
24
|
import { writeFileSync, mkdirSync, renameSync, statSync } from "node:fs";
|
|
@@ -24,41 +26,39 @@ import * as PiCodingAgent from "@earendil-works/pi-coding-agent";
|
|
|
24
26
|
import * as PiTui from "@earendil-works/pi-tui";
|
|
25
27
|
import { CustomEditor } from "@earendil-works/pi-coding-agent";
|
|
26
28
|
import { initializeNavigatorPanels } from "./shared-navigator-panels.domain.mjs";
|
|
27
|
-
import { workObservation, workObservationFailure,
|
|
29
|
+
import { workObservation, workObservationStarted, workObservationFailure, configureWorkObservation, activateWorkObservation, stopWorkObservation, observedAssignment, observedList, requestWorkDetail, TERMINAL_NAVIGATOR_RETENTION_MS } from "./work-observation.domain.mjs";
|
|
28
30
|
import { withAssignmentObservations } from "./assignment-projection.mjs";
|
|
29
31
|
import { formatNavigatorHealthFacts } from "./health-surface.mjs";
|
|
30
32
|
import { matchesKey, Key, truncateToWidth } from "@earendil-works/pi-tui";
|
|
31
33
|
import { Type } from "typebox";
|
|
32
|
-
import { disposeBackgroundWorkNavigator, ensureBackgroundWorkNavigator, isNavigatorUiAvailable, refreshBackgroundWorkNavigator, registerBackgroundWorkProvider, renderRegisteredWorkDetail, } from "./shared-navigator.domain.mjs";
|
|
34
|
+
import { disposeBackgroundWorkNavigator, ensureBackgroundWorkNavigator, isNavigatorUiAvailable, refreshBackgroundWorkNavigator, registerBackgroundWorkProvider, observeNavigatorLaunch, renderRegisteredWorkDetail, } from "./shared-navigator.domain.mjs";
|
|
33
35
|
import { spawnDetached } from "./spawn.domain.mjs";
|
|
34
|
-
import { abortUncommittedLaunch } from "./launch-abort.domain.mjs";
|
|
35
36
|
import { parseRun, parseRunForLifecycle, resetParseRunCursor } from "./parse.domain.mjs";
|
|
36
|
-
import { finalizeRun as finalizeRunCore } from "./finalization.domain.mjs";
|
|
37
|
+
import { finalizeRun as finalizeRunCore, reconcileInterruptedRun } from "./finalization.domain.mjs";
|
|
38
|
+
import { completeOwnedExit } from "./owned-exit.domain.mjs";
|
|
37
39
|
import { selectSessionByName } from "./session-selection.domain.mjs";
|
|
38
40
|
import { isWithinWorkspace } from "./workspace-scope.domain.mjs";
|
|
39
|
-
import {
|
|
41
|
+
import { BUILTIN_TOOLS } from "./extensions.domain.mjs";
|
|
42
|
+
import { ORDINARY_TOOL_PROVIDERS, activeChildProviders, ordinaryChildConfig, addEditablePatch, loadConfig, writeDelegationMode, writeSubagentSettings, isConcurrencyCap, normalizeConcurrencyCap, normalizeTools, resolveExtensionPath, configPath, selfDir, SAFE_DEFAULT_TOOLS, SAFE_CLEAN_TOOLS } from "./config.domain.mjs";
|
|
40
43
|
import { createSubagentSettingsPage } from "./settings-page.domain.mjs";
|
|
41
44
|
import { deliverSubagentPrompt, effectiveSubagentSettings, subagentSettingsTool } from "./effective-settings.domain.mjs";
|
|
42
45
|
import { STEER_FILE_ENV, readSteerReceipt } from "./child-steer.domain.mjs";
|
|
43
46
|
import { continuationTimingParams, decideTiming, describeTiming, DEFAULT_TIMING_MINUTES, emptyProgress, foldProgress, formatTimingLimits, isTimingMinutes, isProgressRelevantLine, resolveRunTiming, steerText, stuckAlertText, TIMING_ENV, timingParameterSchemas, toolWaitAlertText, validatedTimingMinutes, } from "./timing.domain.mjs";
|
|
44
47
|
import { readAppendedLines } from "./log-cursor.domain.mjs";
|
|
45
48
|
import { DELEGATION_MODES, DELEGATION_MODE_REQUEST, isDelegationMode, normalizeDelegationMode } from "./delegation.domain.mjs";
|
|
46
|
-
import { resolveChildClosure, resolveChildLaunch, configSnapshot } from "./child-dependencies.mjs";
|
|
47
|
-
import { PREFLIGHT_ENV } from "./child-preflight.mjs";
|
|
48
49
|
import { resolveExtensions, extensionArgs } from "./extensions.domain.mjs";
|
|
49
|
-
import { prepareTaskRuntime, applyDirectApplicationLoadout, RUN_APPLICATION, SDK_BUILTIN_TOOLS } from "./task-policy.domain.mjs";
|
|
50
|
+
import { prepareTaskRuntime, applyDirectApplicationLoadout, DEFAULT_TASK_PERMISSIONS, RUN_APPLICATION, SDK_BUILTIN_TOOLS } from "./task-policy.domain.mjs";
|
|
50
51
|
import { canonicalizePath, takeRecoverySnapshot } from "./shared-sandbox-core.domain.mjs";
|
|
51
52
|
import { TASK_BUILTINS } from "./shared-task-sandbox.domain.mjs";
|
|
52
|
-
import {
|
|
53
|
-
import { announceExecutionAdapter, observeSandboxPermissions, resolveCommandSettings, resolveSubagentPermissions, } from "./permission-policy.domain.mjs";
|
|
54
|
-
import { resolveSubagentWorkspace } from "./git-workspace.domain.mjs";
|
|
53
|
+
import { describeTaskTools, planTaskTools, selectEffectiveTaskTools } from "./subagent-tools.domain.mjs";
|
|
54
|
+
import { announceExecutionAdapter, describeSubagentProcessPolicy, effectiveWorkerProcessAccess, observeSandboxPermissions, resolveCommandSettings, resolveSubagentPermissions, } from "./permission-policy.domain.mjs";
|
|
55
55
|
import { dirname, isAbsolute, join } from "node:path";
|
|
56
56
|
import { baseDir, taskWorkspaceDir, sessionsDir, runDir, recordTaskRuntimeProvenance, recordLaunchAttempt, clearLaunchAttempt, logPathFor, promptPathFor, nextRunId, writeMeta, readMeta, listMetas, listActiveMetasForParent, listMetasForOrigin, listMetasForParent, onMetaChanged, effectiveStatus, ownedByThisParent as ownedByFrontend, navigatorVisibleRuns, dismissRun, } from "./registry.domain.mjs";
|
|
57
57
|
import { captureProcessIdentity, extractChildEventFactsFromLog, loadHealthThresholdsFromConfig, isAbandonedByParent, needsMonitoring, observeRunHealth, realProcessProbe, reconcileRun, resetChildEventLogCursor, } from "./health.domain.mjs";
|
|
58
58
|
import { assignBatchJobNames, batchLaunchOutputSchema, batchLaunchResult, mergeJobOptions, nextBatchId, planBatchLaunches, validateBatchPlan, } from "./batch.mjs";
|
|
59
59
|
import { formatCapacityRejectMessage, getSharedCapacityGate, } from "./capacity.mjs";
|
|
60
60
|
import { buildHealthCallbackDelivery } from "./completion.domain.mjs";
|
|
61
|
-
import { cancelCallbackBatch, getCallbackBatcher, setCallbackBatchContext } from "./shared-callback-batcher.domain.mjs";
|
|
61
|
+
import { cancelCallbackBatch, getCallbackBatcher, packCallbackBatch, setCallbackBatchContext } from "./shared-callback-batcher.domain.mjs";
|
|
62
62
|
let managementPort;
|
|
63
63
|
const ownedByThisParent = (meta) => managementPort ? managementPort.owns(meta) : ownedByFrontend(meta);
|
|
64
64
|
const supervisedMetas = () => managementPort ? managementPort.supervised() : listMetasForParent(process.pid);
|
|
@@ -70,6 +70,7 @@ import { stopRun } from "./stop.domain.mjs";
|
|
|
70
70
|
import { WIDGET_CLEAR, fmtElapsed, fmtSpend, fmtTokens, shortModel, isSpendCacheFresh, resolveHealthLogExtraction, withinRefreshFloor, } from "./widget.domain.mjs";
|
|
71
71
|
import { executeNavigatorClose, pendingNavigatorPark, buildNavigatorDetail, } from "./navigator.domain.mjs";
|
|
72
72
|
import { enforceRegistrySizeCapOnce, runDailyCleanupOnce } from "./cleanup.domain.mjs";
|
|
73
|
+
import { managedRuntimeRoot, selectContinuationRuntime } from "./continuation-runtime.domain.mjs";
|
|
73
74
|
import { ContinuationError, acquireConversationLease, assertContinuationExtensions, buildLaunchRecipe, planContinuation, } from "./continuation.domain.mjs";
|
|
74
75
|
import { createHash } from "node:crypto";
|
|
75
76
|
import { assertThinkingLevel, parseModelThinking } from "./thinking.domain.mjs";
|
|
@@ -166,7 +167,7 @@ function callbackOriginFromContext(ctx) {
|
|
|
166
167
|
catch {
|
|
167
168
|
sessionId = undefined;
|
|
168
169
|
}
|
|
169
|
-
return { cwd: ctx.cwd, sessionId };
|
|
170
|
+
return { cwd: ctx.cwd, sessionId, branchId: ctx.sessionManager?.getLeafId?.() ?? null };
|
|
170
171
|
}
|
|
171
172
|
/** Origin with a readable session id, or undefined when identity is unavailable. */
|
|
172
173
|
function verifiedOriginFromContext(ctx) {
|
|
@@ -483,10 +484,57 @@ async function tryEnqueueAssignmentOutcome(pi, meta) {
|
|
|
483
484
|
return;
|
|
484
485
|
}
|
|
485
486
|
const deliveryHost = outcomeHost;
|
|
486
|
-
|
|
487
|
+
// The Goal scheduler can take up to 20 seconds. Keep the short probe only
|
|
488
|
+
// for a standalone parent, with no bound Goal or acknowledged check.
|
|
489
|
+
const workflowBudgetMs = 25_000;
|
|
490
|
+
const gate = await requestResumeAdmission(pi, active, {
|
|
491
|
+
timeoutMs: active.goalId || outcome.recipient.goalId ? workflowBudgetMs : 50,
|
|
492
|
+
pendingTimeoutMs: workflowBudgetMs,
|
|
493
|
+
});
|
|
487
494
|
outcomeAdmission.set(outcome.eventId, () => gate.allowed ? gate.isCurrent?.() !== false : !active.goalId && !outcome.recipient.goalId && gate.revision === -1);
|
|
488
495
|
if (!gate.allowed && (active.goalId || outcome.recipient.goalId || gate.revision !== -1)) {
|
|
489
|
-
|
|
496
|
+
// Admission controls model execution, not delivery of an already
|
|
497
|
+
// committed result. Paused Goals still owe their human a notification.
|
|
498
|
+
if (sessionTornDown || outcomeHost !== deliveryHost || uiCtx !== ctx || callbackSuppressionReason(meta)
|
|
499
|
+
|| (outcome.recipient.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === outcome.recipient.branchId))) {
|
|
500
|
+
deferOutcome(meta, "Recorded parent delivery scope changed; automatic reconciliation will retry.");
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
// Native Pi queues messages during a turn even with triggerTurn:false.
|
|
504
|
+
// Wait for idle so replay cannot enqueue the same unreceipted message.
|
|
505
|
+
if (!ctx.isIdle()) {
|
|
506
|
+
deferOutcome(meta, "Waiting for an idle parent to append the outcome without starting a turn.");
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
if (!claimOutcome(meta, deliveryHost)) {
|
|
510
|
+
deferOutcome(meta, "Outcome dispatch is owned by another host; automatic reconciliation will retry.");
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
const details = { completionEventIds: [outcome.eventId] };
|
|
514
|
+
const packed = packCallbackBatch([{
|
|
515
|
+
source: "subagent", id: outcome.eventId, inspectId: meta.id, receiptId: outcome.eventId,
|
|
516
|
+
label: meta.name ?? meta.id, status: outcome.outcome, outcome: outcome.reason,
|
|
517
|
+
detailTool: "subagent_result", callback: true,
|
|
518
|
+
}]);
|
|
519
|
+
try {
|
|
520
|
+
await pi.sendMessage({ customType: "background-completion-batch", display: true,
|
|
521
|
+
content: `${packed.text}\nAutomatic continuation: ${gate.reason}`, details }, { triggerTurn: false });
|
|
522
|
+
}
|
|
523
|
+
catch (error) {
|
|
524
|
+
// A failed persistence must not look like a durable transcript receipt.
|
|
525
|
+
details.completionEventIds.length = 0;
|
|
526
|
+
throw error;
|
|
527
|
+
}
|
|
528
|
+
const entry = outcomeTranscriptReceipt(ctx.sessionManager.getBranch(), outcome.eventId);
|
|
529
|
+
if (!entry)
|
|
530
|
+
throw new Error("Awaiting durable recipient transcript receipt.");
|
|
531
|
+
receiptOutcome(meta, entry);
|
|
532
|
+
markCompletionCallbackSent(meta.id, Date.now());
|
|
533
|
+
deferOutcome(meta);
|
|
534
|
+
try {
|
|
535
|
+
ctx.ui?.notify(`${meta.name ?? meta.id}: ${outcome.outcome}. Automatic continuation: ${gate.reason}. Inspect subagent_result.`, outcome.outcome === "failed" ? "warning" : "info");
|
|
536
|
+
}
|
|
537
|
+
catch { /* transcript remains visible */ }
|
|
490
538
|
return;
|
|
491
539
|
}
|
|
492
540
|
// Admission may yield across a session switch or Goal/workflow change.
|
|
@@ -639,19 +687,13 @@ function deliverFailureAttention(pi, meta, now) {
|
|
|
639
687
|
function markHealthCallbackSuppressed(meta, status, reason, now) {
|
|
640
688
|
if (isConversationIdentityReason(reason))
|
|
641
689
|
return;
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
if (meta.lostCallbackSuppressedAt !== undefined)
|
|
650
|
-
return;
|
|
651
|
-
meta.lostCallbackSuppressedAt = now;
|
|
652
|
-
meta.lostCallbackSuppressedReason = reason;
|
|
653
|
-
}
|
|
654
|
-
writeMeta(meta);
|
|
690
|
+
writeMeta(meta, { patch: current => {
|
|
691
|
+
if (isHealthCallbackHandled(current, status))
|
|
692
|
+
return;
|
|
693
|
+
return status === "orphaned"
|
|
694
|
+
? { orphanedCallbackSuppressedAt: now, orphanedCallbackSuppressedReason: reason }
|
|
695
|
+
: { lostCallbackSuppressedAt: now, lostCallbackSuppressedReason: reason };
|
|
696
|
+
} });
|
|
655
697
|
}
|
|
656
698
|
function isHealthCallbackHandled(meta, status) {
|
|
657
699
|
return status === "orphaned"
|
|
@@ -793,6 +835,7 @@ function stopTicker() {
|
|
|
793
835
|
/** How often supervision is reconciled. Independent of TUI render scheduling. */
|
|
794
836
|
const HEALTH_TICK_MS = 15_000;
|
|
795
837
|
let healthTicker;
|
|
838
|
+
let managedHealthClose;
|
|
796
839
|
/** ExtensionAPI retained so health transitions can deliver coordinator follow-ups (#65). */
|
|
797
840
|
let healthPi;
|
|
798
841
|
/**
|
|
@@ -837,11 +880,11 @@ function deliverHealthCallback(pi, meta, status, now) {
|
|
|
837
880
|
return;
|
|
838
881
|
}
|
|
839
882
|
// The marker acknowledges quiet delivery, never a model turn.
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
883
|
+
writeMeta(meta, { patch: current => {
|
|
884
|
+
if (current.status !== status || isHealthCallbackHandled(current, status) || callbackSuppressionReason(current))
|
|
885
|
+
return;
|
|
886
|
+
return status === "orphaned" ? { orphanedCallbackSentAt: now } : { lostCallbackSentAt: now };
|
|
887
|
+
} });
|
|
845
888
|
return;
|
|
846
889
|
}
|
|
847
890
|
void getCallbackBatcher(pi).deliverUrgent({
|
|
@@ -867,11 +910,11 @@ function deliverHealthCallback(pi, meta, status, now) {
|
|
|
867
910
|
if (attention.incidents.some((incident) => pendingFailureAttention(collectRunFailures(meta.id, meta.cwd), at, { terminal: true })?.incidents.includes(incident)))
|
|
868
911
|
return;
|
|
869
912
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
913
|
+
writeMeta(current, { patch: current => {
|
|
914
|
+
if (isHealthCallbackHandled(current, status))
|
|
915
|
+
return;
|
|
916
|
+
return status === "orphaned" ? { orphanedCallbackSentAt: at } : { lostCallbackSentAt: at };
|
|
917
|
+
} });
|
|
875
918
|
},
|
|
876
919
|
onSuppressed: (reason, at) => {
|
|
877
920
|
const current = readMeta(meta.id);
|
|
@@ -1214,7 +1257,7 @@ function enforceTiming(pi, meta, now) {
|
|
|
1214
1257
|
return false;
|
|
1215
1258
|
}
|
|
1216
1259
|
/** One reconciliation + durable health-callback recovery pass. */
|
|
1217
|
-
function reconcileHealth() {
|
|
1260
|
+
function reconcileHealth(ids) {
|
|
1218
1261
|
if (!managementPort)
|
|
1219
1262
|
return;
|
|
1220
1263
|
try {
|
|
@@ -1226,7 +1269,8 @@ function reconcileHealth() {
|
|
|
1226
1269
|
}
|
|
1227
1270
|
const ctx = uiCtx;
|
|
1228
1271
|
const pi = healthPi;
|
|
1229
|
-
|
|
1272
|
+
const selected = ids ? ids.map(id => readMeta(id)).filter((meta) => Boolean(meta)) : supervisedMetas();
|
|
1273
|
+
for (const summary of selected) {
|
|
1230
1274
|
if (!ownedByThisParent(summary))
|
|
1231
1275
|
continue;
|
|
1232
1276
|
// running/orphaned: process reconcile. lost: durable callback recovery only.
|
|
@@ -1248,10 +1292,24 @@ function reconcileHealth() {
|
|
|
1248
1292
|
// Interrupted work whose child already exited is finalized from its own
|
|
1249
1293
|
// coherent log before any other verdict (and before timing can mislabel
|
|
1250
1294
|
// an already-finished run as stopped) (#625).
|
|
1295
|
+
let interruptedReconciliation;
|
|
1251
1296
|
if (meta.status === "running" || meta.status === "orphaned") {
|
|
1252
1297
|
try {
|
|
1253
|
-
if (
|
|
1254
|
-
|
|
1298
|
+
if (pi && !directlySupervisedRunIds.has(meta.id) && meta.supervisionInterruptedAt !== undefined) {
|
|
1299
|
+
const observed = reconcileInterruptedRun(meta, realProcessProbe, now, {
|
|
1300
|
+
renderWidget,
|
|
1301
|
+
notify: (message, level) => { try {
|
|
1302
|
+
ctx?.ui.notify(message, level);
|
|
1303
|
+
}
|
|
1304
|
+
catch { /* unavailable UI */ } },
|
|
1305
|
+
sendMessage: () => enqueueCompletionCallback(pi, meta.id),
|
|
1306
|
+
});
|
|
1307
|
+
if (observed.finalization?.applied) {
|
|
1308
|
+
syncHealthTicker();
|
|
1309
|
+
continue;
|
|
1310
|
+
}
|
|
1311
|
+
interruptedReconciliation = observed.reconciliation;
|
|
1312
|
+
}
|
|
1255
1313
|
}
|
|
1256
1314
|
catch { /* best-effort; the ordinary reconciliation below still runs */ }
|
|
1257
1315
|
}
|
|
@@ -1261,7 +1319,7 @@ function reconcileHealth() {
|
|
|
1261
1319
|
}
|
|
1262
1320
|
catch { /* timing is best-effort per tick; supervision below still runs */ }
|
|
1263
1321
|
if (meta.status === "running" || meta.status === "orphaned") {
|
|
1264
|
-
const result = reconcileRun(meta, realProcessProbe, now);
|
|
1322
|
+
const result = interruptedReconciliation ?? reconcileRun(meta, realProcessProbe, now);
|
|
1265
1323
|
if (result.changed) {
|
|
1266
1324
|
Object.assign(meta, result.patch, { status: result.status });
|
|
1267
1325
|
writeMeta(meta);
|
|
@@ -1307,7 +1365,7 @@ function reconcileHealth() {
|
|
|
1307
1365
|
// is the human's own interrupted work, not another session's live run, and
|
|
1308
1366
|
// `finalizeInterruptedRunFromLog` still requires all process evidence to be
|
|
1309
1367
|
// absent, so a live writer is never touched.
|
|
1310
|
-
for (const summary of listMetas({ includeArchived: false })) {
|
|
1368
|
+
for (const summary of ids ? selected : listMetas({ includeArchived: false })) {
|
|
1311
1369
|
if (summary.status !== "running" && summary.status !== "orphaned")
|
|
1312
1370
|
continue;
|
|
1313
1371
|
if (ownedByThisParent(summary) || !ownsInterruptedSupervision(summary))
|
|
@@ -1321,7 +1379,7 @@ function reconcileHealth() {
|
|
|
1321
1379
|
catch { /* the next tick retries */ }
|
|
1322
1380
|
}
|
|
1323
1381
|
// Completed runs can still have failed completion handoffs to retry.
|
|
1324
|
-
for (const summary of
|
|
1382
|
+
for (const summary of selected) {
|
|
1325
1383
|
if (!pi || !ownedByThisParent(summary) || summary.status === "running" || summary.status === "orphaned" || summary.status === "lost")
|
|
1326
1384
|
continue;
|
|
1327
1385
|
const meta = readMeta(summary.id);
|
|
@@ -1423,6 +1481,10 @@ function syncHealthTicker() {
|
|
|
1423
1481
|
stopHealthTicker();
|
|
1424
1482
|
return;
|
|
1425
1483
|
}
|
|
1484
|
+
if (managementPort.observeHealth) {
|
|
1485
|
+
ensureHealthTicker();
|
|
1486
|
+
return;
|
|
1487
|
+
}
|
|
1426
1488
|
if (needsMonitoring(supervisedMetas()) || needsInterruptedSupervision())
|
|
1427
1489
|
ensureHealthTicker();
|
|
1428
1490
|
else
|
|
@@ -1432,6 +1494,10 @@ function syncHealthTicker() {
|
|
|
1432
1494
|
function ensureHealthTicker() {
|
|
1433
1495
|
if (!managementPort)
|
|
1434
1496
|
return;
|
|
1497
|
+
if (managementPort.observeHealth) {
|
|
1498
|
+
managedHealthClose ??= managementPort.observeHealth(ids => reconcileHealth(ids));
|
|
1499
|
+
return;
|
|
1500
|
+
}
|
|
1435
1501
|
// Not gated on `sessionTornDown`: a spawn always means the current session is
|
|
1436
1502
|
// doing new work. Only `syncHealthTicker` — the path a late child finalizer
|
|
1437
1503
|
// takes — stays closed in a replaced instance.
|
|
@@ -1441,6 +1507,8 @@ function ensureHealthTicker() {
|
|
|
1441
1507
|
healthTicker.unref?.(); // never keep the process alive on our account
|
|
1442
1508
|
}
|
|
1443
1509
|
function stopHealthTicker() {
|
|
1510
|
+
managedHealthClose?.();
|
|
1511
|
+
managedHealthClose = undefined;
|
|
1444
1512
|
if (healthTicker) {
|
|
1445
1513
|
clearInterval(healthTicker);
|
|
1446
1514
|
healthTicker = undefined;
|
|
@@ -1448,7 +1516,7 @@ function stopHealthTicker() {
|
|
|
1448
1516
|
}
|
|
1449
1517
|
/** Test/diagnostic seam: whether the periodic reconciliation loop is active. */
|
|
1450
1518
|
export function isHealthTickerActive() {
|
|
1451
|
-
return healthTicker !== undefined;
|
|
1519
|
+
return healthTicker !== undefined || managedHealthClose !== undefined;
|
|
1452
1520
|
}
|
|
1453
1521
|
/**
|
|
1454
1522
|
* Spawn-time identity probe. Production uses the OS-backed probe; extension-
|
|
@@ -1509,7 +1577,7 @@ const pendingNavigatorDismissals = new Set();
|
|
|
1509
1577
|
function navigatorRunningCount() {
|
|
1510
1578
|
const snapshot = workObservation();
|
|
1511
1579
|
return (snapshot?.rows.filter((row) => !pendingNavigatorDismissals.has(row.meta.id) && !row.meta.dismissedAt && ["running", "waiting"].includes(row.assignment.state)).length ?? 0) +
|
|
1512
|
-
(
|
|
1580
|
+
(workObservationStarted() && snapshot?.status !== "ready" ? 1 : 0);
|
|
1513
1581
|
}
|
|
1514
1582
|
/**
|
|
1515
1583
|
* The visible run set. The durable origin index limits reads to this session;
|
|
@@ -1616,22 +1684,20 @@ function subagentWorkRows(now) {
|
|
|
1616
1684
|
if (!undismissed.has(id))
|
|
1617
1685
|
pendingNavigatorDismissals.delete(id);
|
|
1618
1686
|
}
|
|
1619
|
-
const rows = sourceRows.filter((row) => !pendingNavigatorDismissals.has(row.meta.id) && !row.meta.dismissedAt
|
|
1620
|
-
(["running", "waiting"].includes(row.assignment.state) || typeof (row.meta.endedAt ?? row.meta.lostAt) !== "number" ||
|
|
1621
|
-
now - (row.meta.endedAt ?? row.meta.lostAt) < TERMINAL_NAVIGATOR_RETENTION_MS)).map((row) => {
|
|
1687
|
+
const rows = sourceRows.filter((row) => !pendingNavigatorDismissals.has(row.meta.id) && !row.meta.dismissedAt).map((row) => {
|
|
1622
1688
|
const meta = row.meta;
|
|
1623
1689
|
const health = row.health ? observeRunHealth({ ...row.health, status: row.assignment.processStatus === "exited" ? meta.status : row.assignment.processStatus, now, startedAt: meta.startedAt }) : undefined;
|
|
1624
1690
|
const terminal = !["running", "waiting"].includes(row.assignment.state);
|
|
1625
|
-
return { providerId: "subagents", id: meta.id, name: meta.name || meta.id,
|
|
1691
|
+
return { providerId: "subagents", id: meta.id, agentId: meta.sessionId ?? meta.id, name: meta.name || meta.id,
|
|
1626
1692
|
model: shortModel(meta.model), effort: meta.effort, status: row.assignment.state,
|
|
1627
1693
|
tool: row.display?.tool, tokens: row.display?.spend,
|
|
1628
1694
|
statusTone: statusTone(row.assignment.state), kind: "subagent", elapsed: fmtElapsed((meta.endedAt ?? now) - meta.startedAt),
|
|
1629
1695
|
primary: [shortModel(meta.model), meta.effort, row.display?.tool, row.display?.spend].filter(Boolean).join(" ") || "subagent run", facts: formatNavigatorHealthFacts(health), sortStartedAt: meta.startedAt,
|
|
1630
1696
|
expiresAt: terminal && typeof meta.endedAt === "number" ? meta.endedAt + TERMINAL_NAVIGATOR_RETENTION_MS : undefined };
|
|
1631
1697
|
});
|
|
1632
|
-
if (
|
|
1633
|
-
rows.unshift({ providerId: "subagents", id: "runtime-observation", name: "
|
|
1634
|
-
status: snapshot?.status ?? "degraded", statusTone: "warning", kind: "observation", elapsed: "", primary:
|
|
1698
|
+
if (workObservationStarted() && snapshot?.status !== "ready")
|
|
1699
|
+
rows.unshift({ providerId: "subagents", id: "runtime-observation", name: "Status sync",
|
|
1700
|
+
status: snapshot?.status ?? "degraded", statusTone: "warning", kind: "observation", readOnly: true, elapsed: "", primary: "Task status unconfirmed · enter for details", sortStartedAt: now });
|
|
1635
1701
|
return rows;
|
|
1636
1702
|
}
|
|
1637
1703
|
const DELEGATION_BLURB = {
|
|
@@ -1714,6 +1780,14 @@ function mainAgentWorkDetail(now) {
|
|
|
1714
1780
|
function subagentWorkDetail(id, now, options) {
|
|
1715
1781
|
if (id === "main")
|
|
1716
1782
|
return mainAgentWorkDetail(now);
|
|
1783
|
+
if (id === "runtime-observation")
|
|
1784
|
+
return {
|
|
1785
|
+
providerId: "subagents", id, title: "Subagent status sync", status: workObservation()?.status ?? "rebuilding", statusTone: "warning",
|
|
1786
|
+
subtitle: "Shared status service · task status unconfirmed",
|
|
1787
|
+
metadata: [{ label: "scope", value: "Subagent status reads; not an individual task" }],
|
|
1788
|
+
evidence: { label: "Full diagnostic", text: workObservationFailure() },
|
|
1789
|
+
footerActions: [],
|
|
1790
|
+
};
|
|
1717
1791
|
const row = requestWorkDetail(id);
|
|
1718
1792
|
if (!row?.detail)
|
|
1719
1793
|
return { providerId: "subagents", id, title: id, status: row?.observationError ? "degraded" : "rebuilding", statusTone: "warning", metadata: [], evidence: { label: "observation", text: row?.observationError ?? workObservationFailure() } };
|
|
@@ -1814,8 +1888,10 @@ function ensureSubagentProvider() {
|
|
|
1814
1888
|
id: "subagents",
|
|
1815
1889
|
label: "Subagents",
|
|
1816
1890
|
priority: 10,
|
|
1891
|
+
onOpen: () => { void activateWorkObservation(); },
|
|
1817
1892
|
visibleCount: () => navigatorRunningCount(),
|
|
1818
|
-
|
|
1893
|
+
// The last worker becoming terminal must not hide its retained result.
|
|
1894
|
+
showSection: (rows) => rows.length > 0,
|
|
1819
1895
|
parentRow: (now) => mainAgentWorkRow(now),
|
|
1820
1896
|
listRows: (now) => subagentWorkRows(now),
|
|
1821
1897
|
detail: (id, now, options) => subagentWorkDetail(id, now, options),
|
|
@@ -1833,6 +1909,8 @@ function ensureSubagentProvider() {
|
|
|
1833
1909
|
},
|
|
1834
1910
|
armCloseLabel: (row) => pendingNavigatorPark(workObservation()?.rows.find((observed) => observed.meta.id === row.id)?.meta) ? "x again to cancel resume" : row.status === "running" || row.status === "orphaned" ? "x again to stop" : "x again to dismiss",
|
|
1835
1911
|
close: (id) => {
|
|
1912
|
+
if (id === "runtime-observation")
|
|
1913
|
+
return { action: "not-closable", providerId: "subagents", id };
|
|
1836
1914
|
const outcome = navigatorCloseRun(id);
|
|
1837
1915
|
return { ...outcome, providerId: "subagents" };
|
|
1838
1916
|
},
|
|
@@ -2088,7 +2166,8 @@ function revalidateContinuationUnderLease(plan, origin) {
|
|
|
2088
2166
|
id: plan.prior.id,
|
|
2089
2167
|
prior: current,
|
|
2090
2168
|
origin,
|
|
2091
|
-
|
|
2169
|
+
// Archived attempts are completed and cannot be competing writers.
|
|
2170
|
+
others: listMetas({ includeArchived: false }),
|
|
2092
2171
|
});
|
|
2093
2172
|
if (fresh.conversation.sessionId !== plan.conversation.sessionId || fresh.conversation.path !== plan.conversation.path) {
|
|
2094
2173
|
throw new ContinuationError(`Cannot continue ${plan.prior.id}: the saved conversation it would reopen changed while this launch was being prepared ` +
|
|
@@ -2649,13 +2728,16 @@ export default function (pi, managed) {
|
|
|
2649
2728
|
const registerSpawnTool = (definition) => {
|
|
2650
2729
|
registeredSpawnSchemas.set(definition.name, definition.parameters);
|
|
2651
2730
|
pi.registerTool(managed ? { ...definition, async execute(key, params, signal, onUpdate, ctx) {
|
|
2731
|
+
ctx = captureLaunchContext(ctx);
|
|
2652
2732
|
restoreDelegationMode(ctx);
|
|
2653
2733
|
await workerOperations.start();
|
|
2654
2734
|
return definition.execute(key, params, signal, onUpdate, ctx);
|
|
2655
2735
|
} } : { ...definition, async execute(key, params, _signal, _onUpdate, ctx) {
|
|
2736
|
+
ctx = captureLaunchContext(ctx);
|
|
2656
2737
|
catalogHostFrom(ctx);
|
|
2657
2738
|
const { submitManagedLaunch } = await import("./managed-launch-client.domain.mjs");
|
|
2658
|
-
|
|
2739
|
+
void activateWorkObservation();
|
|
2740
|
+
return await observeNavigatorLaunch(ctx, "subagents", key, "Subagent launch", () => submitManagedLaunch(pi, ctx, key, definition.name, params));
|
|
2659
2741
|
} });
|
|
2660
2742
|
};
|
|
2661
2743
|
announceExecutionAdapter(pi, {
|
|
@@ -2751,6 +2833,9 @@ export default function (pi, managed) {
|
|
|
2751
2833
|
* this call, and a manual continuation passes neither.
|
|
2752
2834
|
*/
|
|
2753
2835
|
internal) {
|
|
2836
|
+
const { resolveChildClosure, resolveChildLaunch, configSnapshot } = await import("./child-dependencies.mjs");
|
|
2837
|
+
const { resolveSubagentWorkspace } = await import("./git-workspace.domain.mjs");
|
|
2838
|
+
const { PREFLIGHT_ENV } = await import("./child-preflight.mjs");
|
|
2754
2839
|
assertThinkingLevel(p.thinking);
|
|
2755
2840
|
// Skill exposure is a caller choice, not a launch: validate its shape
|
|
2756
2841
|
// before any attempt directory or capacity effect exists. A continuation
|
|
@@ -2770,11 +2855,12 @@ export default function (pi, managed) {
|
|
|
2770
2855
|
// frozen confinement intent. Historical metadata can never widen authority,
|
|
2771
2856
|
// and a profile that would change confinement refuses instead of silently
|
|
2772
2857
|
// moving a live conversation into a different sandbox.
|
|
2773
|
-
const permissionPlan = resolveSubagentPermissions(pi, resume
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2858
|
+
const permissionPlan = resolveSubagentPermissions(pi, p.sandbox, resume && { runId: resume.prior.id, sandbox: resume.recipe.sandbox });
|
|
2859
|
+
const processPolicy = describeSubagentProcessPolicy(permissionPlan, process.platform);
|
|
2860
|
+
const processAccess = effectiveWorkerProcessAccess(permissionPlan);
|
|
2861
|
+
const taskPermissions = permissionPlan.inactiveProfile
|
|
2862
|
+
? { ...DEFAULT_TASK_PERMISSIONS, processAccess }
|
|
2863
|
+
: permissionPlan.permissions;
|
|
2778
2864
|
const cfg = loadConfig();
|
|
2779
2865
|
// Harness-owned timing (soft deadline, ceiling, tool-wait and stuck windows); validated before any side effect.
|
|
2780
2866
|
resolveRunTiming({ params: launchTimingParams(p), settings: timingSettingsFor(cfg), env: process.env, startedAt: 0 });
|
|
@@ -2918,8 +3004,7 @@ export default function (pi, managed) {
|
|
|
2918
3004
|
allow = [...allow.split(","), ...SUBAGENT_TOOLS.filter((t) => !have.has(t))]
|
|
2919
3005
|
.filter(Boolean).join(",");
|
|
2920
3006
|
}
|
|
2921
|
-
//
|
|
2922
|
-
// the guarded apply_patch adapter, and trusted tools admitted by name and package.
|
|
3007
|
+
// Exclusions apply to the worker selection before provider admission (ADR 0027).
|
|
2923
3008
|
const requestedExcludes = new Set(requestedExcludeTools.split(",").map((t) => t.trim()).filter(Boolean));
|
|
2924
3009
|
// Supervised worker operations. This only decides which names the
|
|
2925
3010
|
// child's loadout carries: clean children, explicit tool lists,
|
|
@@ -2961,20 +3046,19 @@ export default function (pi, managed) {
|
|
|
2961
3046
|
bridgePlan.capabilities = { ...bridgePlan.capabilities, reportAssignment: true };
|
|
2962
3047
|
productionBridgeSchemas.schemas.set("report_assignment_result", createToolDescriptor("report_assignment_result"));
|
|
2963
3048
|
}
|
|
3049
|
+
assertWaitToolDependencies(bridgePlan.capabilities, bridgePlan.tools);
|
|
2964
3050
|
const bridgeEnabled = bridgePlan.tools.length > 0;
|
|
2965
3051
|
if (bridgeEnabled) {
|
|
2966
3052
|
allow = [...new Set([...allow.split(",").filter(Boolean), ...bridgePlan.tools])].join(",");
|
|
2967
3053
|
}
|
|
2968
|
-
if (
|
|
3054
|
+
if (!clean) {
|
|
2969
3055
|
const names = allow.split(",").filter(Boolean);
|
|
2970
|
-
//
|
|
2971
|
-
if (
|
|
2972
|
-
names
|
|
2973
|
-
if (requestedTools === undefined)
|
|
2974
|
-
names.push(...permissionPlan.tools.trusted.map((entry) => entry.name));
|
|
3056
|
+
// Derive the editable loadout before applying the resource policy.
|
|
3057
|
+
if (!resume)
|
|
3058
|
+
addEditablePatch(names, requestedExcludes);
|
|
2975
3059
|
allow = [...new Set(names)].join(",");
|
|
2976
3060
|
}
|
|
2977
|
-
if (sandboxEnabled && requestedTools === undefined &&
|
|
3061
|
+
if (sandboxEnabled && requestedTools === undefined && processAccess === "read") {
|
|
2978
3062
|
allow = [...new Set([...allow.split(","), "process_list"])].join(",");
|
|
2979
3063
|
}
|
|
2980
3064
|
// Shell Off confines the child to directly launched applications: a requested bash
|
|
@@ -2994,12 +3078,20 @@ export default function (pi, managed) {
|
|
|
2994
3078
|
// Candidates for the task-tool plan: exclusions and bridge-supplied
|
|
2995
3079
|
// names never reach extension admission.
|
|
2996
3080
|
const plannedTools = allow.split(",").filter((name) => name && !requestedExcludes.has(name) && !bridgeToolNames.has(name));
|
|
3081
|
+
const continuationRuntime = selectContinuationRuntime({ currentDir: selfDir(), recipe: resume?.recipe });
|
|
3082
|
+
const workerPath = (path) => continuationRuntime?.mapPath(path) ?? path;
|
|
3083
|
+
const workerArgs = (args) => continuationRuntime?.mapArgs(args) ?? args;
|
|
3084
|
+
const workerResolvePath = (spec) => {
|
|
3085
|
+
const path = resolveExtensionPath(spec);
|
|
3086
|
+
return path ? workerPath(path) : path;
|
|
3087
|
+
};
|
|
3088
|
+
const normalProviders = ordinaryChildConfig(cfg, managed?.activeProviders?.() ?? activeChildProviders(pi));
|
|
2997
3089
|
const taskTools = sandboxEnabled ? planTaskTools({
|
|
2998
3090
|
requested: plannedTools,
|
|
2999
3091
|
settings: permissionPlan.tools, network: permissionPlan.permissions?.network ?? true,
|
|
3000
|
-
processAccess
|
|
3092
|
+
processAccess,
|
|
3001
3093
|
builtins: [...TASK_BUILTINS, "codemode"], registered: pi.getAllTools?.() ?? [],
|
|
3002
|
-
toolExtensions:
|
|
3094
|
+
toolExtensions: normalProviders.toolExtensions, resolvePath: workerResolvePath,
|
|
3003
3095
|
}) : undefined;
|
|
3004
3096
|
// One effective selection feeds the task policy, child preflight, worker
|
|
3005
3097
|
// bridge and frozen recipe, so a refused tool cannot leak into any of them
|
|
@@ -3019,9 +3111,9 @@ export default function (pi, managed) {
|
|
|
3019
3111
|
.map((tool) => `${tool.name} (${withheldBridgeReasons.get(tool.name) ?? tool.reason})`).join(", ");
|
|
3020
3112
|
throw resume
|
|
3021
3113
|
? new ContinuationError(`Cannot continue ${resume.prior.id}: its frozen launch requires tool(s) this parent can no longer provide: ${detail}. ` +
|
|
3022
|
-
`Launch a new run instead of continuing this conversation
|
|
3114
|
+
`Launch a new run instead of continuing this conversation. ${processPolicy}`)
|
|
3023
3115
|
: new Error(`Requested tool(s) are not available in the task sandbox: ${detail}. ` +
|
|
3024
|
-
`
|
|
3116
|
+
`Check the child tool provider and the Subagents resource permissions; nothing was launched.`);
|
|
3025
3117
|
}
|
|
3026
3118
|
if (toolSelection) {
|
|
3027
3119
|
if (plannedTools.length > 0 && toolSelection.tools.length === 0) {
|
|
@@ -3029,53 +3121,66 @@ export default function (pi, managed) {
|
|
|
3029
3121
|
}
|
|
3030
3122
|
allow = toolSelection.tools.join(",");
|
|
3031
3123
|
}
|
|
3124
|
+
// Older recipes were frozen before isolated workers gained Harness providers
|
|
3125
|
+
// and inherited workers began loading mappings explicitly.
|
|
3126
|
+
const legacyToolLoading = resume !== undefined && !resume.recipe.toolLoadingVersion;
|
|
3127
|
+
let extensionConfig = cfg;
|
|
3128
|
+
if (!sandboxEnabled && !legacyToolLoading)
|
|
3129
|
+
extensionConfig = normalProviders;
|
|
3130
|
+
if (legacyToolLoading && cfg.inheritExtensions)
|
|
3131
|
+
extensionConfig = { ...cfg, toolExtensions: {} };
|
|
3032
3132
|
const dependencyOptions = {
|
|
3033
3133
|
model, virtual: (() => {
|
|
3034
3134
|
const slash = model?.indexOf("/") ?? -1;
|
|
3035
3135
|
return slash > 0 && ctx.modelRegistry?.find?.(model.slice(0, slash), model.slice(slash + 1))?.api === "pi-virtual";
|
|
3036
|
-
})(), config:
|
|
3037
|
-
configPaths: [configPath(), join(selfDir(), "config.json")],
|
|
3136
|
+
})(), config: extensionConfig, resolvePath: workerResolvePath,
|
|
3137
|
+
configPaths: [configPath(), workerPath(join(selfDir(), "config.json"))],
|
|
3038
3138
|
};
|
|
3039
3139
|
// Bridge tools are supplied by the worker bridge extension, not by a
|
|
3040
3140
|
// configured toolExtensions mapping: keep them out of extension
|
|
3041
3141
|
// resolution so `unmapped` stays an accurate operator warning and the
|
|
3042
3142
|
// frozen launch recipe never depends on bridge availability.
|
|
3043
|
-
const extensionAllowlist = () => (
|
|
3044
|
-
|
|
3045
|
-
: allow);
|
|
3143
|
+
const extensionAllowlist = () => allow.split(",")
|
|
3144
|
+
.filter(name => !requestedExcludes.has(name) && !bridgeToolNames.has(name)).join(",");
|
|
3046
3145
|
const { resolution, fullResolution } = await resolveChildLaunch({ ...dependencyOptions, resolution: resolveExtensions({
|
|
3047
3146
|
// Only SDK builtins reach `--tools` and extension resolution: process_list and run_application
|
|
3048
3147
|
// are task builtins that the mandatory guard installs and activates itself.
|
|
3049
3148
|
tools: sandboxEnabled ? allow.split(",").filter((name) => SDK_BUILTIN_TOOLS.includes(name)).join(",") : extensionAllowlist(),
|
|
3050
|
-
model, clean, allowNested: sandboxEnabled ? false : allowNested, config:
|
|
3149
|
+
model, clean, allowNested: sandboxEnabled ? false : allowNested, config: extensionConfig,
|
|
3051
3150
|
}) }, taskTools?.trusted.map(tool => tool.loadPath) ?? []);
|
|
3052
|
-
|
|
3151
|
+
if (!sandboxEnabled && resolution.mode === "isolated" &&
|
|
3152
|
+
fullResolution.specs.every((spec) => Object.values(ORDINARY_TOOL_PROVIDERS).includes(spec))) {
|
|
3153
|
+
const missingTools = resolution.unmapped.filter((name) => requiredToolNames.has(name));
|
|
3154
|
+
if (missingTools.length)
|
|
3155
|
+
throw new Error(`No provider for required child tools: ${missingTools.join(", ")}. Configure toolExtensions or change the requested tools.`);
|
|
3156
|
+
}
|
|
3157
|
+
const { args: resolvedExtArgs, missing } = extensionArgs(resolution, (spec) => resolution.paths[spec] ?? workerResolvePath(spec));
|
|
3053
3158
|
const trustedExtArgs = fullResolution.specs.map(spec => fullResolution.paths[spec])
|
|
3054
3159
|
.filter(path => !resolvedExtArgs.includes(path)).flatMap(path => ["--extension", path]);
|
|
3055
3160
|
// Harness child controls ride along in every mode, including clean and unsandboxed runs.
|
|
3056
3161
|
// They deliver deadline steers and keep external monitoring with the coordinator.
|
|
3057
3162
|
const codemodeArgs = !sandboxEnabled && allow.split(",").includes("codemode") && !requestedExcludes.has("codemode")
|
|
3058
3163
|
? ["--extension", join(selfDir(), "child-codemode.ts")] : [];
|
|
3059
|
-
const extArgs = [...resolvedExtArgs, ...trustedExtArgs, ...codemodeArgs,
|
|
3164
|
+
const extArgs = workerArgs([...resolvedExtArgs, ...trustedExtArgs, ...codemodeArgs,
|
|
3060
3165
|
"--extension", childSteerExtensionPath(), "--extension", join(selfDir(), "child-ownership.ts")]
|
|
3061
|
-
.map((value, index, all) => sandboxEnabled && all[index - 1] === "--extension" ? canonicalizePath(value) : value);
|
|
3062
|
-
const baseExtensionArgs = [...resolvedExtArgs, ...codemodeArgs,
|
|
3166
|
+
.map((value, index, all) => sandboxEnabled && all[index - 1] === "--extension" ? canonicalizePath(value) : value));
|
|
3167
|
+
const baseExtensionArgs = workerArgs([...resolvedExtArgs, ...codemodeArgs,
|
|
3063
3168
|
"--extension", childSteerExtensionPath(), "--extension", join(selfDir(), "child-ownership.ts")]
|
|
3064
|
-
.map((value, index, all) => sandboxEnabled && all[index - 1] === "--extension" ? canonicalizePath(value) : value);
|
|
3169
|
+
.map((value, index, all) => sandboxEnabled && all[index - 1] === "--extension" ? canonicalizePath(value) : value));
|
|
3065
3170
|
if (resume?.recipe.extensionArgs) {
|
|
3066
3171
|
// A model escalation may change provider auth, but an unchanged tool
|
|
3067
3172
|
// must not silently switch implementations with current configuration.
|
|
3068
3173
|
const reference = model === resume.recipe.model ? resolution : await resolveChildClosure({
|
|
3069
3174
|
...dependencyOptions, model: resume.recipe.model, virtual: false, resolution: resolveExtensions({
|
|
3070
3175
|
tools: sandboxEnabled ? allow.split(",").filter((name) => SDK_BUILTIN_TOOLS.includes(name)).join(",") : extensionAllowlist(),
|
|
3071
|
-
model: resume.recipe.model, clean, allowNested: sandboxEnabled ? false : allowNested, config:
|
|
3176
|
+
model: resume.recipe.model, clean, allowNested: sandboxEnabled ? false : allowNested, config: extensionConfig,
|
|
3072
3177
|
})
|
|
3073
3178
|
});
|
|
3074
|
-
const referenceArgs = [...extensionArgs(reference, (spec) => reference.paths[spec] ??
|
|
3179
|
+
const referenceArgs = [...extensionArgs(reference, (spec) => reference.paths[spec] ?? workerResolvePath(spec)).args, ...codemodeArgs,
|
|
3075
3180
|
...(!resume.recipe.baseExtensionArgs ? trustedExtArgs : []),
|
|
3076
3181
|
"--extension", childSteerExtensionPath(), "--extension", join(selfDir(), "child-ownership.ts")]
|
|
3077
3182
|
.map((value, index, all) => sandboxEnabled && all[index - 1] === "--extension" ? canonicalizePath(value) : value);
|
|
3078
|
-
assertContinuationExtensions(resume.prior.id, resume.recipe, referenceArgs, taskTools?.trusted ?? []);
|
|
3183
|
+
assertContinuationExtensions(resume.prior.id, resume.recipe, workerArgs(referenceArgs), (taskTools?.trusted ?? []).map(tool => ({ ...tool, loadPath: workerPath(tool.loadPath) })));
|
|
3079
3184
|
}
|
|
3080
3185
|
if (sandboxEnabled && resolution.mode === "inherit") {
|
|
3081
3186
|
throw new Error("Task confinement requires explicit extensions; inheritExtensions is unsupported while sandboxing is enabled.");
|
|
@@ -3104,7 +3209,7 @@ export default function (pi, managed) {
|
|
|
3104
3209
|
// supervision capability, not a tool implementation, so it must not
|
|
3105
3210
|
// invalidate a conversation's saved recipe when it appears later.
|
|
3106
3211
|
const commandExtArgs = bridgeEnabled
|
|
3107
|
-
? [...extArgs, "--extension", childBridgeExtensionPath(selfDir())]
|
|
3212
|
+
? [...extArgs, "--extension", workerPath(childBridgeExtensionPath(selfDir()))]
|
|
3108
3213
|
: extArgs;
|
|
3109
3214
|
const args = [
|
|
3110
3215
|
"-p", "--mode", "json",
|
|
@@ -3119,20 +3224,24 @@ export default function (pi, managed) {
|
|
|
3119
3224
|
p.prompt,
|
|
3120
3225
|
];
|
|
3121
3226
|
const selectedTools = allow.split(",").filter((name) => name && !excludes.has(name));
|
|
3227
|
+
const inheritedTrusted = resume ? new Set(resume.recipe.optionalTrustedTools ?? []) : undefined;
|
|
3228
|
+
const optionalTrustedTools = taskTools?.trusted.filter(({ name }) => selectedTools.includes(name)
|
|
3229
|
+
&& (inheritedTrusted ? inheritedTrusted.has(name) : requestedTools === undefined)).map(({ name }) => name) ?? [];
|
|
3122
3230
|
const dropped = toolSelection?.dropped ?? [];
|
|
3123
3231
|
const taskRuntime = sandboxEnabled && requestedSandboxDir ? prepareTaskRuntime({
|
|
3124
3232
|
root: requestedSandboxDir, controlDir: join(runDir(id), "control"),
|
|
3125
3233
|
tools: selectedTools,
|
|
3126
|
-
permissions:
|
|
3234
|
+
permissions: taskPermissions && { ...taskPermissions, ...commandSettings },
|
|
3127
3235
|
applyPatch: taskTools?.applyPatch === true,
|
|
3128
|
-
extensionTools: taskTools?.trusted.map(({ loadPath: _loadPath, ...tool }) => tool) ?? [],
|
|
3236
|
+
extensionTools: taskTools?.trusted.map(({ loadPath: _loadPath, ...tool }) => ({ ...tool, root: workerPath(tool.root) })) ?? [],
|
|
3129
3237
|
// The sandboxed child's policy enables the guarded operation bridge
|
|
3130
3238
|
// only when the fixed bridge adapter path is among its extension
|
|
3131
3239
|
// paths; the task guard then admits those tools by exact source.
|
|
3132
3240
|
extensionPaths: [
|
|
3133
3241
|
...extArgs.flatMap((arg, index) => arg === "--extension" && extArgs[index + 1] ? [extArgs[index + 1]] : []),
|
|
3134
|
-
...(bridgeEnabled ? [childBridgeExtensionPath(selfDir())] : []),
|
|
3242
|
+
...(bridgeEnabled ? [workerPath(childBridgeExtensionPath(selfDir()))] : []),
|
|
3135
3243
|
],
|
|
3244
|
+
operationBridgePath: workerPath(childBridgeExtensionPath(selfDir())),
|
|
3136
3245
|
runtimeRoots: [baseDir()],
|
|
3137
3246
|
capturedDenyWrite: internal?.resumeWait
|
|
3138
3247
|
? resume?.prior.operations?.policy.sandbox?.denyWrite
|
|
@@ -3159,9 +3268,10 @@ export default function (pi, managed) {
|
|
|
3159
3268
|
catch { /* ignore */ }
|
|
3160
3269
|
});
|
|
3161
3270
|
}
|
|
3162
|
-
const
|
|
3271
|
+
const currentCommand = taskRuntime ? { file: taskRuntime.file, fileArgs: [...taskRuntime.fileArgs, ...args] }
|
|
3163
3272
|
: managed ? managed.workerCommand(args)
|
|
3164
3273
|
: { file: process.execPath, fileArgs: [join(selfDir(), "child-runtime.mjs"), resolvePiBinary(), ...args] };
|
|
3274
|
+
const cmd = continuationRuntime?.command(currentCommand) ?? currentCommand;
|
|
3165
3275
|
const sandboxDir = taskRuntime ? requestedSandboxDir : undefined;
|
|
3166
3276
|
// Reservations prevent competing admissions, but do not grandfather
|
|
3167
3277
|
// unstarted work after a cap reduction. No await separates this live
|
|
@@ -3186,6 +3296,7 @@ export default function (pi, managed) {
|
|
|
3186
3296
|
revalidateContinuationUnderLease(resume, callbackOrigin);
|
|
3187
3297
|
const preflightPath = join(runDir(id), "child-preflight.json");
|
|
3188
3298
|
writeFileSync(preflightPath, JSON.stringify({ ...fullResolution, model, tools: selectedTools,
|
|
3299
|
+
optionalTrustedTools,
|
|
3189
3300
|
configSnapshot: configSnapshot([dirname(configPath()), join(cwd, ".pi")]),
|
|
3190
3301
|
}));
|
|
3191
3302
|
// Register the worker's bridge run before the child can start, so the
|
|
@@ -3270,12 +3381,15 @@ export default function (pi, managed) {
|
|
|
3270
3381
|
}
|
|
3271
3382
|
// Freeze the ordinary recipe before the durable external-launch intent.
|
|
3272
3383
|
const recipe = buildLaunchRecipe({
|
|
3384
|
+
...(!legacyToolLoading ? { toolLoadingVersion: 1 } : {}),
|
|
3273
3385
|
attemptId: id, sessionId, sessionDir: childSessionDir, cwd, model, effort: thinking,
|
|
3274
3386
|
tools: callerLaunchTools(allow), excludeTools: requestedExcludes.size ? [...requestedExcludes].join(",") : undefined,
|
|
3387
|
+
...(optionalTrustedTools.length ? { optionalTrustedTools } : {}),
|
|
3275
3388
|
skills: skills.mode === "inherit" ? undefined : [...skills.paths], clean, allowNested, approve,
|
|
3276
3389
|
sandbox: sandboxEnabled, sandboxDir: requestedSandboxDir, gitCloneWorkspace, callback: callbackEnabled, name: launchName,
|
|
3277
3390
|
agent: resume ? resume.recipe.agent : p.agent, role: resume ? resume.recipe.role : p.role,
|
|
3278
3391
|
alias: resume ? resume.recipe.alias : p.alias, catalog: launchCatalog, extensionArgs: extArgs, baseExtensionArgs,
|
|
3392
|
+
runtimeRoot: continuationRuntime?.root ?? managedRuntimeRoot(selfDir()),
|
|
3279
3393
|
trustedExtensions: resume?.recipe.trustedExtensions ?? taskTools?.trusted.map(({ name, package: owner, loadPath }) => ({ name, package: owner, loadPath })),
|
|
3280
3394
|
});
|
|
3281
3395
|
const startedAt = Date.now();
|
|
@@ -3360,33 +3474,30 @@ export default function (pi, managed) {
|
|
|
3360
3474
|
// Register exit supervision before any fallible post-spawn publication.
|
|
3361
3475
|
// A failed metadata write must not strand a running child without a close
|
|
3362
3476
|
// handler; the lease stays held until that child has actually exited.
|
|
3363
|
-
|
|
3364
|
-
try {
|
|
3365
|
-
finalizeRun(pi, ctx, id, code);
|
|
3366
|
-
}
|
|
3367
|
-
finally {
|
|
3368
|
-
lease?.release();
|
|
3369
|
-
}
|
|
3477
|
+
const exitCompletion = completeOwnedExit(spawned.exit, code => finalizeRun(pi, ctx, id, code), () => { lease?.release(); }, async () => {
|
|
3370
3478
|
if (workerBridge)
|
|
3371
3479
|
workerOperations.release(id, "attempt-exited");
|
|
3372
3480
|
// Reconcile this attempt's earlier published writer before its
|
|
3373
3481
|
// next park can admit another continuation of the conversation.
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3482
|
+
if (internal?.resumeWait && resume)
|
|
3483
|
+
await settleResumedAttemptExit({
|
|
3484
|
+
attemptId: id,
|
|
3485
|
+
priorPark: { runId: resume.prior.id, ...internal.resumeWait },
|
|
3486
|
+
service: workerOperations.service,
|
|
3487
|
+
status: readMeta(id)?.status ?? "exited",
|
|
3488
|
+
// The exit handler releases the conversation writer lease just
|
|
3489
|
+
// above, before this call.
|
|
3490
|
+
writerLeaseReleased: true,
|
|
3491
|
+
notify: (message) => {
|
|
3492
|
+
try {
|
|
3493
|
+
uiCtx?.ui?.notify?.(message, "warning");
|
|
3494
|
+
}
|
|
3495
|
+
catch { /* ignore UI failures */ }
|
|
3496
|
+
},
|
|
3497
|
+
});
|
|
3388
3498
|
await settleParkedExit(id);
|
|
3389
3499
|
});
|
|
3500
|
+
managed?.observeExit?.(id, exitCompletion);
|
|
3390
3501
|
writeMeta(meta);
|
|
3391
3502
|
committed = true;
|
|
3392
3503
|
// `meta.json` is now the record of this run; the claim has served its
|
|
@@ -3415,7 +3526,9 @@ export default function (pi, managed) {
|
|
|
3415
3526
|
const modelNote = catalogDefaultNote(resume ? undefined : p.catalog, model, thinking);
|
|
3416
3527
|
// The resolved skill exposure rides with the runtime summary, which every
|
|
3417
3528
|
// launch and continuation message already prints.
|
|
3418
|
-
|
|
3529
|
+
const inventoryNote = taskRuntime?.policy.permissions?.processAccess === "read" &&
|
|
3530
|
+
!taskRuntime.policy.tools.includes("process_list") ? " process_list is not in this launch's tool loadout." : "";
|
|
3531
|
+
return { id, meta, spawned, runtime: `${runtime}${processPolicy}${inventoryNote}\n${describeSkillExposure(skills)}\n${meta.timing ? `${formatTimingLimits(meta.timing, startedAt)}\n` : ""}`, warn, sandboxDir, modelNote };
|
|
3419
3532
|
}
|
|
3420
3533
|
catch (error) {
|
|
3421
3534
|
// A launch that never committed metadata is not a run: drop
|
|
@@ -3427,6 +3540,7 @@ export default function (pi, managed) {
|
|
|
3427
3540
|
// must not keep running unsupervised; its log goes with the
|
|
3428
3541
|
// attempt, because a record without metadata can never be read.
|
|
3429
3542
|
if (!committed) {
|
|
3543
|
+
const { abortUncommittedLaunch } = await import("./launch-abort.domain.mjs");
|
|
3430
3544
|
await abortUncommittedLaunch(id, {
|
|
3431
3545
|
child: spawned, lease,
|
|
3432
3546
|
artifacts: { sessionDir: childSessionDir, workspaceDir: ownedCloneWorkspace, scratch: launchScratch },
|
|
@@ -3502,7 +3616,7 @@ export default function (pi, managed) {
|
|
|
3502
3616
|
id: prior.id,
|
|
3503
3617
|
prior,
|
|
3504
3618
|
origin: { cwd: input.park.record.ownerWorkspace ?? prior.callbackOrigin?.cwd ?? prior.cwd, sessionId: input.park.record.ownerSessionId ?? prior.callbackOrigin?.sessionId },
|
|
3505
|
-
others: listMetas(),
|
|
3619
|
+
others: listMetas({ includeArchived: false }),
|
|
3506
3620
|
});
|
|
3507
3621
|
}
|
|
3508
3622
|
catch (error) {
|
|
@@ -3547,7 +3661,7 @@ export default function (pi, managed) {
|
|
|
3547
3661
|
claim: input.claim,
|
|
3548
3662
|
owner,
|
|
3549
3663
|
admissionRevision: input.admissionRevision,
|
|
3550
|
-
permissionsUnchanged: () => samePermissionPlan(permissionPlan, resolveSubagentPermissions(pi, target.recipe.sandbox)),
|
|
3664
|
+
permissionsUnchanged: () => samePermissionPlan(permissionPlan, resolveSubagentPermissions(pi, undefined, { runId: target.prior.id, sandbox: target.recipe.sandbox })),
|
|
3551
3665
|
capacityAvailable: () => resumeCapacity().recheck(),
|
|
3552
3666
|
}),
|
|
3553
3667
|
onSpawned: () => { spawned = true; },
|
|
@@ -3581,7 +3695,10 @@ export default function (pi, managed) {
|
|
|
3581
3695
|
};
|
|
3582
3696
|
return JSON.stringify(sort(value));
|
|
3583
3697
|
};
|
|
3584
|
-
|
|
3698
|
+
// Describe provenance to the caller, but fence on authority, not its display label.
|
|
3699
|
+
const { activationSource: _leftSource, ...leftAuthority } = left;
|
|
3700
|
+
const { activationSource: _rightSource, ...rightAuthority } = right;
|
|
3701
|
+
return canonical(leftAuthority) === canonical(rightAuthority);
|
|
3585
3702
|
}
|
|
3586
3703
|
/** Preserve the original assignment deadline across parking; never extend it. */
|
|
3587
3704
|
function continuationTiming(prior) {
|
|
@@ -4222,6 +4339,30 @@ export default function (pi, managed) {
|
|
|
4222
4339
|
pi.events?.emit("harness-settings:register", contribution);
|
|
4223
4340
|
pi.events?.emit("harness-settings:register", agentsContribution);
|
|
4224
4341
|
};
|
|
4342
|
+
const unsubscribeToolLoading = pi.events?.on?.("pi-better-subagents:default-tool-loading", (request) => {
|
|
4343
|
+
const query = request;
|
|
4344
|
+
if (typeof query?.reply !== "function")
|
|
4345
|
+
return;
|
|
4346
|
+
const config = ordinaryChildConfig(loadConfig(), activeChildProviders(pi));
|
|
4347
|
+
const names = normalizeTools(config.defaultTools ?? SAFE_DEFAULT_TOOLS).split(",").filter(Boolean);
|
|
4348
|
+
addEditablePatch(names, new Set());
|
|
4349
|
+
const rows = [...new Set(names)].map(name => {
|
|
4350
|
+
if (name === "codemode") {
|
|
4351
|
+
const supported = "createCodemodeExtension" in PiCodingAgent && typeof PiCodingAgent.createCodemodeExtension === "function";
|
|
4352
|
+
return { name, provider: supported ? "Harness" : "SDK unavailable" };
|
|
4353
|
+
}
|
|
4354
|
+
if (BUILTIN_TOOLS.includes(name))
|
|
4355
|
+
return { name, provider: "Pi" };
|
|
4356
|
+
const spec = config.toolExtensions?.[name];
|
|
4357
|
+
const sources = typeof spec === "string" ? [spec] : spec ?? [];
|
|
4358
|
+
const providers = sources.map(source => {
|
|
4359
|
+
const label = source === ORDINARY_TOOL_PROVIDERS[name] ? "Harness" : source;
|
|
4360
|
+
return resolveExtensionPath(source) ? label : `${label} (missing)`;
|
|
4361
|
+
});
|
|
4362
|
+
return { name, provider: providers.join(", ") || (config.inheritExtensions ? "Session extensions" : "No provider mapped") };
|
|
4363
|
+
});
|
|
4364
|
+
query.reply(rows);
|
|
4365
|
+
});
|
|
4225
4366
|
const unsubscribeSettingsRequest = pi.events?.on?.("harness-settings:request", registerSettings);
|
|
4226
4367
|
const unsubscribeOutcomeWorkflow = pi.events?.on?.("pi-better-workflow:changed", () => recoverAssignmentOutcomes(pi));
|
|
4227
4368
|
registerSettings();
|
|
@@ -4387,7 +4528,15 @@ export default function (pi, managed) {
|
|
|
4387
4528
|
// Capture a UI-bearing context and, if runs from a prior session are still
|
|
4388
4529
|
// alive, resume the ticking widget. Deferred out of the factory per pi's
|
|
4389
4530
|
// "no background resources at load" rule.
|
|
4390
|
-
|
|
4531
|
+
let restoreObservation;
|
|
4532
|
+
let offFirstAssignment;
|
|
4533
|
+
const cancelDeferredObservation = () => {
|
|
4534
|
+
if (restoreObservation)
|
|
4535
|
+
clearImmediate(restoreObservation);
|
|
4536
|
+
offFirstAssignment?.();
|
|
4537
|
+
offFirstAssignment = undefined;
|
|
4538
|
+
};
|
|
4539
|
+
pi.on("session_start", async (event, ctx) => {
|
|
4391
4540
|
// A session begins in this process again (reload, restart, or a session
|
|
4392
4541
|
// switch), so the previous session's teardown no longer applies: the
|
|
4393
4542
|
// replacing session owns this instance's supervision loops (#625).
|
|
@@ -4412,11 +4561,31 @@ export default function (pi, managed) {
|
|
|
4412
4561
|
activeCallbackOrigin = callbackOriginFromContext(ctx);
|
|
4413
4562
|
pendingRecipientRecovery.clear();
|
|
4414
4563
|
observedRecipientRows.clear();
|
|
4415
|
-
|
|
4416
|
-
|
|
4564
|
+
cancelDeferredObservation();
|
|
4565
|
+
if (!managed && activeCallbackOrigin) {
|
|
4566
|
+
configureWorkObservation(PiCodingAgent.getAgentDir(), activeCallbackOrigin, () => {
|
|
4417
4567
|
refreshBackgroundWorkNavigator(ctx);
|
|
4418
4568
|
observeRecipientNotifications(pi);
|
|
4419
4569
|
});
|
|
4570
|
+
if (!event?.reason) {
|
|
4571
|
+
// Older hosts use completion of their untyped start callback as the readiness signal.
|
|
4572
|
+
await activateWorkObservation();
|
|
4573
|
+
}
|
|
4574
|
+
else if (shouldRestoreWorkObservation(event, ctx.sessionManager)) {
|
|
4575
|
+
restoreObservation = setImmediate(() => { void activateWorkObservation(); });
|
|
4576
|
+
}
|
|
4577
|
+
else {
|
|
4578
|
+
// Another extension can assign work to this recipient before it calls a tool.
|
|
4579
|
+
const origin = activeCallbackOrigin;
|
|
4580
|
+
offFirstAssignment = onMetaChanged(meta => {
|
|
4581
|
+
if (!meta || !belongsToOrigin(meta, origin))
|
|
4582
|
+
return;
|
|
4583
|
+
offFirstAssignment?.();
|
|
4584
|
+
offFirstAssignment = undefined;
|
|
4585
|
+
void activateWorkObservation();
|
|
4586
|
+
});
|
|
4587
|
+
}
|
|
4588
|
+
}
|
|
4420
4589
|
if (!managed) {
|
|
4421
4590
|
recoverCompletionCallbacks(pi);
|
|
4422
4591
|
observeRecipientNotifications(pi);
|
|
@@ -4471,6 +4640,7 @@ export default function (pi, managed) {
|
|
|
4471
4640
|
await startWorkerOperations();
|
|
4472
4641
|
});
|
|
4473
4642
|
pi.on("session_before_switch", () => {
|
|
4643
|
+
cancelDeferredObservation();
|
|
4474
4644
|
closeCatalogHost();
|
|
4475
4645
|
agentSessionSettings.clear();
|
|
4476
4646
|
catalogModelRegistry = undefined;
|
|
@@ -4485,6 +4655,7 @@ export default function (pi, managed) {
|
|
|
4485
4655
|
// Tear down the timer and clear the widget when the session ends.
|
|
4486
4656
|
pi.on("session_shutdown", async (event, ctx) => {
|
|
4487
4657
|
closeCatalogHost();
|
|
4658
|
+
cancelDeferredObservation();
|
|
4488
4659
|
stopWorkObservation();
|
|
4489
4660
|
pendingNavigatorDismissals.clear();
|
|
4490
4661
|
if (outcomeTicker)
|
|
@@ -4494,6 +4665,8 @@ export default function (pi, managed) {
|
|
|
4494
4665
|
closeOutcomeHost(outcomeHost);
|
|
4495
4666
|
if (typeof unsubscribeOutcomeWorkflow === "function")
|
|
4496
4667
|
unsubscribeOutcomeWorkflow();
|
|
4668
|
+
if (typeof unsubscribeToolLoading === "function")
|
|
4669
|
+
unsubscribeToolLoading();
|
|
4497
4670
|
if (typeof unsubscribeSettingsRequest === "function")
|
|
4498
4671
|
unsubscribeSettingsRequest();
|
|
4499
4672
|
// #625: subagent children are detached process groups that outlive this
|