pi-better-server 0.5.0 → 0.7.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 +7 -3
- 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/frontend.ts +10 -2
- 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-full-runtime.mjs +2 -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 +181 -27
- package/src/runtime/background.ts +365 -70
- 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 +52 -14
- package/src/runtime/domain/background/registry.mjs +61 -3
- package/src/runtime/domain/background/supervisor/store.mjs +3 -3
- package/src/runtime/domain/background/supervisor/supervisor.mjs +9 -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 +25 -9
- package/src/runtime/domain/background-service/index.ts +25 -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 +159 -19
- package/src/runtime/domain/background-service/managed-frontend.ts +135 -19
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +21 -5
- package/src/runtime/domain/background-service/navigator-provider.ts +19 -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 +372 -57
- package/src/runtime/domain/background-service/observed-waits.ts +321 -53
- 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 +52 -14
- package/src/runtime/domain/background-service/process.ts +48 -14
- 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/review-settings.domain.mjs +16 -0
- package/src/runtime/domain/background-service/review-settings.ts +18 -0
- package/src/runtime/domain/background-service/runtime.domain.mjs +40 -86
- package/src/runtime/domain/background-service/runtime.ts +27 -82
- 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 +273 -41
- package/src/runtime/domain/background-service/shared-navigator.ts +244 -40
- 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/outbox.domain.mjs +7 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +9 -0
- 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 +26 -4
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +40 -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/stall.domain.mjs +5 -3
- package/src/runtime/domain/background-service/stall.ts +7 -4
- package/src/runtime/domain/background-service/supervised-progress.domain.mjs +42 -0
- package/src/runtime/domain/background-service/supervised-progress.ts +43 -0
- package/src/runtime/domain/background-service/supervisor/README.md +1 -4
- package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +1 -0
- package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +20 -2
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +52 -14
- package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +47 -4
- package/src/runtime/domain/background-service/supervisor/generated/store.mjs +3 -3
- package/src/runtime/domain/background-service/supervisor/generated/watch-fingerprint.mjs +69 -0
- package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +47 -4
- package/src/runtime/domain/background-service/supervisor/runner.ts +38 -3
- package/src/runtime/domain/background-service/supervisor/store.domain.mjs +3 -3
- package/src/runtime/domain/background-service/supervisor/store.ts +3 -3
- package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +9 -3
- package/src/runtime/domain/background-service/supervisor/supervisor.ts +6 -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 +53 -40
- package/src/runtime/domain/background-service/tools.ts +67 -54
- package/src/runtime/domain/background-service/types.domain.mjs +1 -0
- package/src/runtime/domain/background-service/types.ts +7 -3
- package/src/runtime/domain/background-service/watch-fingerprint.domain.mjs +67 -0
- package/src/runtime/domain/background-service/watch-fingerprint.ts +70 -0
- 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/outbox.mjs +7 -0
- 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 +26 -4
- 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/log-paths.mjs +8 -1
- package/src/runtime/domain/parse.d.mts +4 -1
- package/src/runtime/domain/parse.mjs +58 -9
- package/src/runtime/domain/sandbox-policy/README.md +63 -65
- 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/session-store.mjs +7 -0
- package/src/runtime/domain/subagents/README.md +13 -11
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +10 -7
- package/src/runtime/domain/subagents/assignment-outcomes.ts +9 -6
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +109 -24
- package/src/runtime/domain/subagents/assignment-report.ts +103 -19
- package/src/runtime/domain/subagents/batch.mjs +13 -5
- 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/cleanup.domain.mjs +11 -2
- package/src/runtime/domain/subagents/cleanup.ts +10 -2
- package/src/runtime/domain/subagents/config.domain.mjs +54 -2
- package/src/runtime/domain/subagents/config.ts +53 -3
- 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/continuation.domain.mjs +4 -2
- package/src/runtime/domain/subagents/continuation.ts +4 -2
- package/src/runtime/domain/subagents/extensions.mjs +11 -13
- package/src/runtime/domain/subagents/failures.domain.mjs +11 -2
- package/src/runtime/domain/subagents/failures.ts +10 -2
- package/src/runtime/domain/subagents/finalization.domain.mjs +16 -1
- package/src/runtime/domain/subagents/finalization.ts +21 -1
- 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 +457 -182
- package/src/runtime/domain/subagents/index.ts +417 -155
- package/src/runtime/domain/subagents/isolated-workspace.domain.mjs +515 -0
- package/src/runtime/domain/subagents/isolated-workspace.ts +557 -0
- 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/list.mjs +2 -2
- 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 +27 -7
- package/src/runtime/domain/subagents/managed-launch-client.ts +28 -8
- 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/output-payload.domain.mjs +24 -9
- package/src/runtime/domain/subagents/output-payload.ts +26 -12
- 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 +4 -2
- package/src/runtime/domain/subagents/parse.domain.mjs +58 -9
- package/src/runtime/domain/subagents/parse.ts +57 -10
- 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 +71 -51
- package/src/runtime/domain/subagents/registry.ts +77 -38
- package/src/runtime/domain/subagents/retained-result.domain.mjs +56 -0
- package/src/runtime/domain/subagents/retained-result.ts +65 -0
- package/src/runtime/domain/subagents/session-selection.domain.mjs +3 -1
- package/src/runtime/domain/subagents/session-selection.ts +2 -1
- package/src/runtime/domain/subagents/session-store.domain.mjs +7 -0
- package/src/runtime/domain/subagents/session-store.ts +9 -0
- package/src/runtime/domain/subagents/settings-page.domain.mjs +151 -107
- package/src/runtime/domain/subagents/settings-page.ts +147 -108
- 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 +28 -29
- package/src/runtime/domain/subagents/shared-catalog.ts +29 -21
- 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 +273 -41
- package/src/runtime/domain/subagents/shared-navigator.ts +244 -40
- 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/outbox.domain.mjs +7 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +9 -0
- 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 +26 -4
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +40 -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-guard.domain.mjs +14 -1
- package/src/runtime/domain/subagents/task-guard.ts +13 -1
- package/src/runtime/domain/subagents/task-policy.domain.mjs +3 -2
- package/src/runtime/domain/subagents/task-policy.ts +8 -2
- package/src/runtime/domain/subagents/timing.domain.mjs +10 -1
- package/src/runtime/domain/subagents/timing.ts +10 -1
- package/src/runtime/domain/subagents/tools.domain.mjs +4 -8
- package/src/runtime/domain/subagents/tools.ts +4 -7
- package/src/runtime/domain/subagents/work-observation.domain.mjs +102 -17
- package/src/runtime/domain/subagents/work-observation.ts +91 -17
- 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/domain/subagents/workspace-files.domain.mjs +103 -0
- package/src/runtime/domain/subagents/workspace-files.ts +114 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.d.mts +38 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.mjs +5 -0
- package/src/runtime/domain/subagents/workspace-scope.ts +6 -0
- package/src/runtime/domain/subagents/worktree-feedback.domain.mjs +55 -0
- package/src/runtime/domain/subagents/worktree-feedback.ts +77 -0
- 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 +849 -121
- package/src/runtime/read-watchdog-probe.ts +4 -0
- package/src/runtime/result-supervision.ts +188 -16
- package/src/runtime/root.ts +5 -2
- 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
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Generated from packages/task-sandbox/process-identity.ts. Do not edit directly.
|
|
2
|
+
/** Darwin-only, fixed ps identity compatibility for confined task descendants. */
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { chmod, lstat, mkdtemp, readFile, realpath, rm, writeFile } from "node:fs/promises";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
import { compileWritePolicy, type SandboxWritePolicy } from "./shared-sandbox-core.ts";
|
|
8
|
+
|
|
9
|
+
// This is trusted implementation source, never interpolated with task input.
|
|
10
|
+
const SOURCE = String.raw`
|
|
11
|
+
#include <libproc.h>
|
|
12
|
+
#include <sys/proc_info.h>
|
|
13
|
+
#include <unistd.h>
|
|
14
|
+
#include <errno.h>
|
|
15
|
+
#include <limits.h>
|
|
16
|
+
#include <stdio.h>
|
|
17
|
+
#include <stdlib.h>
|
|
18
|
+
#include <string.h>
|
|
19
|
+
#include <time.h>
|
|
20
|
+
static int refuse(const char *reason) {
|
|
21
|
+
fprintf(stderr, "Sandbox process identity: %s (errno=%d). Supported: ps -p PID -o lstart= -o comm=\n", reason, errno);
|
|
22
|
+
return 1;
|
|
23
|
+
}
|
|
24
|
+
int main(int argc, char **argv) {
|
|
25
|
+
if (argc != 7 || strcmp(argv[1], "-p") || strcmp(argv[3], "-o") ||
|
|
26
|
+
strcmp(argv[4], "lstart=") || strcmp(argv[5], "-o") || strcmp(argv[6], "comm=")) return refuse("unsupported arguments");
|
|
27
|
+
for (const char *p = argv[2]; *p; p++) if (*p < '0' || *p > '9') return refuse("invalid PID");
|
|
28
|
+
char *end; errno = 0;
|
|
29
|
+
long pid = strtol(argv[2], &end, 10);
|
|
30
|
+
if (errno || end == argv[2] || *end || pid <= 0 || pid > INT_MAX) return refuse("invalid PID");
|
|
31
|
+
struct proc_bsdinfo a = {0}, b = {0};
|
|
32
|
+
if (proc_pidinfo((int)pid, PROC_PIDTBSDINFO, 0, &a, sizeof a) != sizeof a) return refuse("identity unavailable");
|
|
33
|
+
if (a.pbi_uid != getuid() || a.pbi_ruid != getuid()) return refuse("different user");
|
|
34
|
+
if (a.pbi_pid != (unsigned int)pid || !a.pbi_start_tvsec || a.pbi_start_tvusec >= 1000000) return refuse("invalid identity");
|
|
35
|
+
char path[PROC_PIDPATHINFO_MAXSIZE] = {0}, confirmed[PROC_PIDPATHINFO_MAXSIZE] = {0};
|
|
36
|
+
if (proc_pidpath((int)pid, path, sizeof path) <= 0 || path[0] != '/') return refuse("path unavailable");
|
|
37
|
+
for (const unsigned char *p = (unsigned char *)path; *p; p++) if (*p < 32 || *p == 127) return refuse("invalid path");
|
|
38
|
+
if (proc_pidinfo((int)pid, PROC_PIDTBSDINFO, 0, &b, sizeof b) != sizeof b) return refuse("identity unavailable");
|
|
39
|
+
if (a.pbi_pid != b.pbi_pid || a.pbi_uid != b.pbi_uid || a.pbi_ruid != b.pbi_ruid || a.pbi_ppid != b.pbi_ppid ||
|
|
40
|
+
a.pbi_start_tvsec != b.pbi_start_tvsec || a.pbi_start_tvusec != b.pbi_start_tvusec) return refuse("identity changed");
|
|
41
|
+
if (proc_pidpath((int)pid, confirmed, sizeof confirmed) <= 0 || strcmp(path, confirmed)) return refuse("executable changed");
|
|
42
|
+
time_t seconds = (time_t)a.pbi_start_tvsec;
|
|
43
|
+
struct tm started; char timestamp[64];
|
|
44
|
+
if (!localtime_r(&seconds, &started) || !strftime(timestamp, sizeof timestamp, "%a %b %e %H:%M:%S %Y", &started)) return refuse("invalid start time");
|
|
45
|
+
printf("%-28s %s\n", timestamp, path);
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
const UNAVAILABLE = '#!/bin/sh\nprintf "%s\\n" "Sandbox process identity unavailable: trusted helper build failed; check Xcode Command Line Tools and restart the session. No unconfined ps fallback was used." >&2\nexit 126\n';
|
|
50
|
+
|
|
51
|
+
type Helper = { directory: string; digest: string };
|
|
52
|
+
const helpers = new Map<string, Promise<Helper>>();
|
|
53
|
+
const digest = (bytes: Buffer | string) => createHash("sha256").update(bytes).digest("hex");
|
|
54
|
+
|
|
55
|
+
// The trusted host compiles fixed source, with fixed argv and a minimal env.
|
|
56
|
+
// The resulting helper, not the compiler, runs as the task under Seatbelt.
|
|
57
|
+
async function compile(source: string, output: string): Promise<void> {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
const child = spawn("/usr/bin/clang", ["-Wall", "-Wextra", "-Werror", "-O2", source, "-o", output], {
|
|
60
|
+
detached: true, shell: false, stdio: ["ignore", "pipe", "pipe"],
|
|
61
|
+
env: { PATH: "/usr/bin:/bin", HOME: "/var/empty", LC_ALL: "C" },
|
|
62
|
+
});
|
|
63
|
+
let failure: Error | undefined;
|
|
64
|
+
let size = 0;
|
|
65
|
+
const stop = (error: Error) => {
|
|
66
|
+
if (failure) return;
|
|
67
|
+
failure = error;
|
|
68
|
+
if (child.pid) try { process.kill(-child.pid, "SIGKILL"); } catch { child.kill("SIGKILL"); }
|
|
69
|
+
};
|
|
70
|
+
const timer = setTimeout(() => stop(new Error("Process identity compiler timed out")), 15000);
|
|
71
|
+
for (const pipe of [child.stdout, child.stderr]) pipe.on("data", (chunk: Buffer) => {
|
|
72
|
+
size += chunk.length;
|
|
73
|
+
if (size > 65536) stop(new Error("Process identity compiler output exceeded limit"));
|
|
74
|
+
});
|
|
75
|
+
child.on("error", error => { failure ??= error; });
|
|
76
|
+
child.on("close", code => {
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
if (failure || code !== 0) reject(failure ?? new Error("Process identity compiler failed"));
|
|
79
|
+
else resolve();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function build(parent: string): Promise<Helper> {
|
|
85
|
+
const directory = await mkdtemp(join(parent, "process-identity-"));
|
|
86
|
+
const source = join(directory, "identity.c"), binary = join(directory, "ps");
|
|
87
|
+
try {
|
|
88
|
+
await writeFile(source, SOURCE, { mode: 0o600, flag: "wx" });
|
|
89
|
+
try { await compile(source, binary); }
|
|
90
|
+
catch {
|
|
91
|
+
// Preserve all other commands when the optional compiler is absent.
|
|
92
|
+
// Identity requests still fail explicitly, never via a broader ps.
|
|
93
|
+
await rm(binary, { force: true });
|
|
94
|
+
await writeFile(binary, UNAVAILABLE, { mode: 0o700, flag: "wx" });
|
|
95
|
+
}
|
|
96
|
+
await chmod(binary, 0o700);
|
|
97
|
+
return { directory, digest: digest(await readFile(binary)) };
|
|
98
|
+
} catch (error) {
|
|
99
|
+
await rm(directory, { recursive: true, force: true });
|
|
100
|
+
throw error;
|
|
101
|
+
} finally { await rm(source, { force: true }); }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function processIdentityDirectory(plan: { policy: SandboxWritePolicy; profilePath: string }): Promise<string | undefined> {
|
|
105
|
+
if (process.platform !== "darwin" || plan.policy.permissions?.processAccess !== "read") return undefined;
|
|
106
|
+
const parent = await realpath(dirname(plan.profilePath));
|
|
107
|
+
// The controller's control directory must be protected even with broad writes.
|
|
108
|
+
const policy = compileWritePolicy(plan.policy);
|
|
109
|
+
if (!policy.denyWrite.some(root => parent === root || parent.startsWith(`${root}/`))) {
|
|
110
|
+
throw new Error("Sandbox process identity requires a task-write-protected control directory.");
|
|
111
|
+
}
|
|
112
|
+
let pending = helpers.get(parent);
|
|
113
|
+
if (!pending) {
|
|
114
|
+
pending = build(parent);
|
|
115
|
+
helpers.set(parent, pending);
|
|
116
|
+
void pending.catch(() => { if (helpers.get(parent) === pending) helpers.delete(parent); });
|
|
117
|
+
}
|
|
118
|
+
const helper = await pending;
|
|
119
|
+
const binary = join(helper.directory, "ps");
|
|
120
|
+
const info = await lstat(binary);
|
|
121
|
+
if (!info.isFile() || info.uid !== process.getuid!() || (info.mode & 0o7777) !== 0o700 ||
|
|
122
|
+
await realpath(helper.directory) !== helper.directory || digest(await readFile(binary)) !== helper.digest) {
|
|
123
|
+
throw new Error("Sandbox process identity helper changed; restart the session.");
|
|
124
|
+
}
|
|
125
|
+
return helper.directory;
|
|
126
|
+
}
|
|
@@ -8,6 +8,7 @@ import { unlink } from "node:fs/promises";
|
|
|
8
8
|
import { homedir } from "node:os";
|
|
9
9
|
import { maybeBuildSandboxCommand } from "./shared-sandbox-core.domain.mjs";
|
|
10
10
|
export const PROCESS_LIST_TOOL = "process_list";
|
|
11
|
+
export const PROCESS_ACCESS_OFF = "Sandbox: Process access is Off. Enable Read in /sandbox.";
|
|
11
12
|
const EXECUTABLE = "/usr/bin/pgrep";
|
|
12
13
|
const MAX_STDOUT = 1024 * 1024;
|
|
13
14
|
const MAX_STDERR = 2048;
|
|
@@ -147,11 +148,11 @@ function run(file, argv, cwd, home, signal) {
|
|
|
147
148
|
});
|
|
148
149
|
});
|
|
149
150
|
}
|
|
150
|
-
export function createProcessListToolDefinition(cwd, controller, access) {
|
|
151
|
+
export function createProcessListToolDefinition(cwd, controller, access, accessDenied = () => PROCESS_ACCESS_OFF) {
|
|
151
152
|
let identity;
|
|
152
153
|
const checkAccess = () => {
|
|
153
154
|
if (access() !== "read")
|
|
154
|
-
throw new Error(
|
|
155
|
+
throw new Error(accessDenied());
|
|
155
156
|
};
|
|
156
157
|
const checkExecutable = () => {
|
|
157
158
|
const current = executableIdentity();
|
|
@@ -9,6 +9,7 @@ import { maybeBuildSandboxCommand, type SandboxWritePolicy } from "./shared-sand
|
|
|
9
9
|
import type { TaskFileController } from "./shared-task-files.ts";
|
|
10
10
|
|
|
11
11
|
export const PROCESS_LIST_TOOL = "process_list";
|
|
12
|
+
export const PROCESS_ACCESS_OFF = "Sandbox: Process access is Off. Enable Read in /sandbox.";
|
|
12
13
|
|
|
13
14
|
const EXECUTABLE = "/usr/bin/pgrep";
|
|
14
15
|
const MAX_STDOUT = 1024 * 1024;
|
|
@@ -139,10 +140,15 @@ function run(file: string, argv: string[], cwd: string, home: string, signal?: A
|
|
|
139
140
|
});
|
|
140
141
|
}
|
|
141
142
|
|
|
142
|
-
export function createProcessListToolDefinition(
|
|
143
|
+
export function createProcessListToolDefinition(
|
|
144
|
+
cwd: string,
|
|
145
|
+
controller: TaskFileController,
|
|
146
|
+
access: () => "off" | "read",
|
|
147
|
+
accessDenied: () => string = () => PROCESS_ACCESS_OFF,
|
|
148
|
+
) {
|
|
143
149
|
let identity: string | undefined;
|
|
144
150
|
const checkAccess = () => {
|
|
145
|
-
if (access() !== "read") throw new Error(
|
|
151
|
+
if (access() !== "read") throw new Error(accessDenied());
|
|
146
152
|
};
|
|
147
153
|
const checkExecutable = () => {
|
|
148
154
|
const current = executableIdentity();
|
|
@@ -9,7 +9,7 @@ import { basename, dirname, isAbsolute, join, parse, resolve, sep } from "node:p
|
|
|
9
9
|
import { canonicalizePath, compileWritePolicy, isRemovableUnderWrite } from "./shared-sandbox-core.domain.mjs";
|
|
10
10
|
import { createTaskFileOperations } from "./shared-task-files.domain.mjs";
|
|
11
11
|
import { APPLY_PATCH_TOOL, createApplyPatchToolDefinition } from "./shared-task-apply-patch.domain.mjs";
|
|
12
|
-
import { createProcessListToolDefinition, PROCESS_LIST_TOOL } from "./shared-task-process-list.domain.mjs";
|
|
12
|
+
import { createProcessListToolDefinition, PROCESS_ACCESS_OFF, PROCESS_LIST_TOOL } from "./shared-task-process-list.domain.mjs";
|
|
13
13
|
import { createRunApplicationToolDefinition, RUN_APPLICATION_TOOL } from "./shared-task-application.domain.mjs";
|
|
14
14
|
import { createTaskExecutor, directShellInterpreter, SHELL_SCRIPTS_OFF, shellInterpreterOff } from "./shared-task-exec.domain.mjs";
|
|
15
15
|
export const TASK_BUILTINS = Object.freeze(["read", "write", "edit", "bash", PROCESS_LIST_TOOL, RUN_APPLICATION_TOOL]);
|
|
@@ -141,7 +141,7 @@ export function installTaskTools(pi, options) {
|
|
|
141
141
|
pi.registerTool(own(createEditToolDefinition(cwd, { operations: files.edit })));
|
|
142
142
|
pi.registerTool(own(options.bashDefinition ? options.bashDefinition(cwd, bash) : createBashToolDefinition(cwd, { operations: bash })));
|
|
143
143
|
pi.registerTool(own(createRunApplicationToolDefinition(cwd, commandExec)));
|
|
144
|
-
pi.registerTool(own(createProcessListToolDefinition(cwd, controller, options.processAccess ?? (() => "off"))));
|
|
144
|
+
pi.registerTool(own(createProcessListToolDefinition(cwd, controller, options.processAccess ?? (() => "off"), processAccessDenied)));
|
|
145
145
|
if (options.applyPatch) {
|
|
146
146
|
const patchFiles = createTaskFileOperations(controller, options.diagnostics, "apply_patch");
|
|
147
147
|
pi.registerTool(own(createApplyPatchToolDefinition(cwd, {
|
|
@@ -150,6 +150,7 @@ export function installTaskTools(pi, options) {
|
|
|
150
150
|
}, PiCodingAgent.withFileMutationQueue)));
|
|
151
151
|
}
|
|
152
152
|
};
|
|
153
|
+
const processAccessDenied = options.processAccessDenied ?? (() => PROCESS_ACCESS_OFF);
|
|
153
154
|
register(options.cwd);
|
|
154
155
|
pi.on("user_bash", () => ({ operations: bash }));
|
|
155
156
|
pi.on("tool_call", (event, ctx) => {
|
|
@@ -192,7 +193,7 @@ export function installTaskTools(pi, options) {
|
|
|
192
193
|
}
|
|
193
194
|
}
|
|
194
195
|
if (event.toolName === PROCESS_LIST_TOOL && options.processAccess?.() !== "read") {
|
|
195
|
-
return blocked(
|
|
196
|
+
return blocked(processAccessDenied(), "process-inspection");
|
|
196
197
|
}
|
|
197
198
|
return;
|
|
198
199
|
}
|
|
@@ -10,7 +10,7 @@ import { basename, dirname, isAbsolute, join, parse, resolve, sep } from "node:p
|
|
|
10
10
|
import { canonicalizePath, compileWritePolicy, isRemovableUnderWrite, type SandboxPermissions } from "./shared-sandbox-core.ts";
|
|
11
11
|
import { createTaskFileOperations, type TaskFileController } from "./shared-task-files.ts";
|
|
12
12
|
import { APPLY_PATCH_TOOL, createApplyPatchToolDefinition } from "./shared-task-apply-patch.ts";
|
|
13
|
-
import { createProcessListToolDefinition, PROCESS_LIST_TOOL } from "./shared-task-process-list.ts";
|
|
13
|
+
import { createProcessListToolDefinition, PROCESS_ACCESS_OFF, PROCESS_LIST_TOOL } from "./shared-task-process-list.ts";
|
|
14
14
|
import { createRunApplicationToolDefinition, RUN_APPLICATION_TOOL } from "./shared-task-application.ts";
|
|
15
15
|
import { createTaskExecutor, directShellInterpreter, SHELL_SCRIPTS_OFF, shellInterpreterOff } from "./shared-task-exec.ts";
|
|
16
16
|
import type { SandboxDiagnostics, DiagnosticResource } from "./shared-sandbox-diagnostics.ts";
|
|
@@ -124,6 +124,7 @@ export function installTaskTools(pi: ExtensionAPI, options: {
|
|
|
124
124
|
applyPatch?: boolean;
|
|
125
125
|
/** Human-controlled access to the fixed read-only inventory adapter. */
|
|
126
126
|
processAccess?: () => "off" | "read";
|
|
127
|
+
processAccessDenied?: () => string;
|
|
127
128
|
/** Build the admitted bash definition from the confined operations (default: the SDK bash tool). */
|
|
128
129
|
bashDefinition?: (cwd: string, operations: BashOperations) => ReturnType<typeof createBashToolDefinition>;
|
|
129
130
|
diagnostics?: Pick<SandboxDiagnostics, "observe">;
|
|
@@ -150,7 +151,7 @@ export function installTaskTools(pi: ExtensionAPI, options: {
|
|
|
150
151
|
pi.registerTool(own(createEditToolDefinition(cwd, { operations: files.edit })));
|
|
151
152
|
pi.registerTool(own(options.bashDefinition ? options.bashDefinition(cwd, bash) : createBashToolDefinition(cwd, { operations: bash })));
|
|
152
153
|
pi.registerTool(own(createRunApplicationToolDefinition(cwd, commandExec)) as any);
|
|
153
|
-
pi.registerTool(own(createProcessListToolDefinition(cwd, controller, options.processAccess ?? (() => "off"))) as any);
|
|
154
|
+
pi.registerTool(own(createProcessListToolDefinition(cwd, controller, options.processAccess ?? (() => "off"), processAccessDenied)) as any);
|
|
154
155
|
if (options.applyPatch) {
|
|
155
156
|
const patchFiles = createTaskFileOperations(controller, options.diagnostics, "apply_patch");
|
|
156
157
|
pi.registerTool(own(createApplyPatchToolDefinition(cwd, {
|
|
@@ -159,6 +160,7 @@ export function installTaskTools(pi: ExtensionAPI, options: {
|
|
|
159
160
|
}, PiCodingAgent.withFileMutationQueue)) as any);
|
|
160
161
|
}
|
|
161
162
|
};
|
|
163
|
+
const processAccessDenied = options.processAccessDenied ?? (() => PROCESS_ACCESS_OFF);
|
|
162
164
|
register(options.cwd);
|
|
163
165
|
pi.on("user_bash", () => ({ operations: bash }));
|
|
164
166
|
pi.on("tool_call", (event, ctx) => {
|
|
@@ -195,7 +197,7 @@ export function installTaskTools(pi: ExtensionAPI, options: {
|
|
|
195
197
|
}
|
|
196
198
|
}
|
|
197
199
|
if (event.toolName === PROCESS_LIST_TOOL && options.processAccess?.() !== "read") {
|
|
198
|
-
return blocked(
|
|
200
|
+
return blocked(processAccessDenied(), "process-inspection");
|
|
199
201
|
}
|
|
200
202
|
return;
|
|
201
203
|
}
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* - Guarded tools are harness adapters that go through the task's guarded file
|
|
7
7
|
* operations, so the file rules govern them. Today: apply_patch.
|
|
8
8
|
* - Trusted tools are extension tools admitted by name AND owning package.
|
|
9
|
-
* They run in the child Pi process, outside the file rules
|
|
10
|
-
* one in /sandbox. Network tools are refused while Network is Off.
|
|
9
|
+
* They run in the child Pi process, outside the file rules. The launch record pins their source. Network tools are refused while Network is Off.
|
|
11
10
|
*/
|
|
12
11
|
import { existsSync } from "node:fs";
|
|
13
12
|
import { dirname, join } from "node:path";
|
|
@@ -64,6 +63,12 @@ export function toolPackage(tool) {
|
|
|
64
63
|
const pkg = info.source && info.source !== "builtin" ? info.source : base;
|
|
65
64
|
return { name: tool.name, package: pkg, root: base };
|
|
66
65
|
}
|
|
66
|
+
export function supportsChildProvider(name, pkg, root) {
|
|
67
|
+
if (RESERVED_TOOL_NAMES.includes(name))
|
|
68
|
+
return false;
|
|
69
|
+
const harnessOwners = [pkg, root].map(id => id.replace(/\/+$/, "")).filter(id => HARNESS_PACKAGES.test(id));
|
|
70
|
+
return !harnessOwners.length || (SSH_TOOL_NAMES.includes(name) && harnessOwners.every(id => SSH_PACKAGE.test(id)));
|
|
71
|
+
}
|
|
67
72
|
/** Candidate trusted tools, excluding core builtins, guarded names and non-SSH harness tools. */
|
|
68
73
|
export function discoverTrustedTools(tools) {
|
|
69
74
|
const found = [];
|
|
@@ -73,9 +78,7 @@ export function discoverTrustedTools(tools) {
|
|
|
73
78
|
const owner = toolPackage(tool);
|
|
74
79
|
if (!owner)
|
|
75
80
|
continue;
|
|
76
|
-
|
|
77
|
-
.filter((id) => HARNESS_PACKAGES.test(id));
|
|
78
|
-
if (harnessOwners.length && !(SSH_TOOL_NAMES.includes(tool.name) && harnessOwners.every((id) => SSH_PACKAGE.test(id))))
|
|
81
|
+
if (!supportsChildProvider(tool.name, owner.package, owner.root))
|
|
79
82
|
continue;
|
|
80
83
|
if (!found.some((t) => t.name === owner.name && t.package === owner.package)) {
|
|
81
84
|
found.push(tool.sourceInfo?.source === "builtin" ? { ...owner, source: "builtin" } : owner);
|
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
* - Guarded tools are harness adapters that go through the task's guarded file
|
|
6
6
|
* operations, so the file rules govern them. Today: apply_patch.
|
|
7
7
|
* - Trusted tools are extension tools admitted by name AND owning package.
|
|
8
|
-
* They run in the child Pi process, outside the file rules
|
|
9
|
-
* one in /sandbox. Network tools are refused while Network is Off.
|
|
8
|
+
* They run in the child Pi process, outside the file rules. The launch record pins their source. Network tools are refused while Network is Off.
|
|
10
9
|
*/
|
|
11
10
|
import { existsSync } from "node:fs";
|
|
12
11
|
import { dirname, join } from "node:path";
|
|
@@ -97,6 +96,12 @@ export function toolPackage(tool: ToolSource): DiscoveredTool | undefined {
|
|
|
97
96
|
return { name: tool.name, package: pkg, root: base };
|
|
98
97
|
}
|
|
99
98
|
|
|
99
|
+
export function supportsChildProvider(name: string, pkg: string, root: string): boolean {
|
|
100
|
+
if (RESERVED_TOOL_NAMES.includes(name)) return false;
|
|
101
|
+
const harnessOwners = [pkg, root].map(id => id.replace(/\/+$/, "")).filter(id => HARNESS_PACKAGES.test(id));
|
|
102
|
+
return !harnessOwners.length || (SSH_TOOL_NAMES.includes(name) && harnessOwners.every(id => SSH_PACKAGE.test(id)));
|
|
103
|
+
}
|
|
104
|
+
|
|
100
105
|
/** Candidate trusted tools, excluding core builtins, guarded names and non-SSH harness tools. */
|
|
101
106
|
export function discoverTrustedTools(tools: readonly ToolSource[]): DiscoveredTool[] {
|
|
102
107
|
const found: DiscoveredTool[] = [];
|
|
@@ -104,9 +109,7 @@ export function discoverTrustedTools(tools: readonly ToolSource[]): DiscoveredTo
|
|
|
104
109
|
if (RESERVED_TOOL_NAMES.includes(tool.name)) continue;
|
|
105
110
|
const owner = toolPackage(tool);
|
|
106
111
|
if (!owner) continue;
|
|
107
|
-
|
|
108
|
-
.filter((id) => HARNESS_PACKAGES.test(id));
|
|
109
|
-
if (harnessOwners.length && !(SSH_TOOL_NAMES.includes(tool.name) && harnessOwners.every((id) => SSH_PACKAGE.test(id)))) continue;
|
|
112
|
+
if (!supportsChildProvider(tool.name, owner.package, owner.root)) continue;
|
|
110
113
|
if (!found.some((t) => t.name === owner.name && t.package === owner.package)) {
|
|
111
114
|
found.push(tool.sourceInfo?.source === "builtin" ? { ...owner, source: "builtin" } : owner);
|
|
112
115
|
}
|
|
@@ -72,6 +72,13 @@ export function durableSubagentRoot(env = process.env, home = homedir()) {
|
|
|
72
72
|
const agentDir = env.PI_CODING_AGENT_DIR?.trim();
|
|
73
73
|
return join(agentDir || join(home, ".pi", "agent"), "subagents");
|
|
74
74
|
}
|
|
75
|
+
export function resultDir(id) {
|
|
76
|
+
return /^sa_[a-z0-9]+_[a-z0-9]+$/i.test(id) ? join(durableSubagentRoot(), "results", id) : undefined;
|
|
77
|
+
}
|
|
78
|
+
export function retainedLogPath(id) {
|
|
79
|
+
const dir = resultDir(id);
|
|
80
|
+
return dir && join(dir, "output.log");
|
|
81
|
+
}
|
|
75
82
|
/** Durable `--session-dir` for new child launches. */
|
|
76
83
|
export function durableSessionsDir() {
|
|
77
84
|
return join(durableSubagentRoot(), "sessions");
|
|
@@ -31,7 +31,8 @@ The API is `runtime-client/src/runtime/client.mjs`, exporting `ensureRuntime`.
|
|
|
31
31
|
- Explicit tool allowlists for child sessions, and `skills` for prompt exposure: omit it to keep user-catalog discovery, pass `[]` for no skills, or pass absolute `SKILL.md` paths for exactly those. See [skill exposure](docs/usage.md#skill-exposure).
|
|
32
32
|
- Durable logs, result retrieval, and [failure observations](docs/failure-observations.md) independent of lifecycle status. A live child handles its own tool errors; the parent is woken only for actionable incidents, and children can classify handled failures with `failure_disposition`.
|
|
33
33
|
- Live background-work navigator for active runs.
|
|
34
|
-
-
|
|
34
|
+
- Git writers start in separate Clones by default. **Git workspace** in `/subagents settings` also offers Worktree. Results carry the working directory or a recoverable copy, including incomplete work. [Workspace recovery](docs/usage.md#git-workspaces)
|
|
35
|
+
- Harness-owned run timing: every run gets independent factual alerts for a tool call left open (5 min) and for no progress (10 min), plus a 60-minute hard timeout. Choose a duration or **No limit** under **Run timeout** in `/subagents settings`. Soft deadlines remain opt-in. Configure per spawn with `deadline_minutes`, `grace_minutes`, `max_minutes`, `tool_wait_minutes`, `stuck_minutes`, globally in `config.json` / `PI_SUBAGENT_*_MINUTES`, or in `/subagents settings`. See [usage notes](docs/usage.md#run-timing-deadline-ceiling-tool-wait-stuck).
|
|
35
36
|
|
|
36
37
|
Every single or batch launch automatically joins one shared supervision watcher in the
|
|
37
38
|
foreground Pi process. The last active run's exit or stop tears it down; a later
|
|
@@ -41,6 +42,8 @@ alerts retain supervision until their handoff is handled, so lost work is not si
|
|
|
41
42
|
|
|
42
43
|
## Worker Ownership
|
|
43
44
|
|
|
45
|
+
Every subagent follows the same contract for preserving work and delivering results to its parent. It applies to read-only investigations as well as tasks that create or change files. [Subagent lifecycle, preservation and delivery](https://github.com/1aboveio/pi-better-harness/blob/main/packages/pi-better-subagents/docs/adr/0007-subagent-lifecycle.md)
|
|
46
|
+
|
|
44
47
|
Every child launch, including clean, batch and unsandboxed launches, loads a Pi
|
|
45
48
|
hook that keeps external CI/PR monitoring with its coordinator. Workers finish
|
|
46
49
|
their assigned implementation or diagnosis, run focused checks, push only when
|
|
@@ -87,25 +90,24 @@ pi -e npm:pi-better-subagents
|
|
|
87
90
|
|
|
88
91
|
Sandboxing starts Off for fresh settings, including standalone subagents without published settings. Explicit saved profiles and session choices remain unchanged. Set `sandbox:true` for a confined launch; `sandbox:false` cannot bypass a human-enabled Subagents profile.
|
|
89
92
|
|
|
90
|
-
Linux confinement requires a usable `bubblewrap` backend and Pi SDK 0.82.1 or newer. `/sandbox` controls the independent Subagents profile, which each launch freezes. Pi handles its own startup, authentication, and provider connection; task tools obey the selected file, command, and network permissions. Outside project defaults to Write: tasks write across home and temp but can remove files outside the workspace only in temp, hidden home directories, and worktree folders (Linux keeps ordinary home folders read-only instead). Confined children admit `read`, `write`, `edit`, and policy-permitted `bash` or guarded `run_application`, the guarded `apply_patch` (Codex patches that follow the file rules), and the
|
|
93
|
+
Linux confinement requires a usable `bubblewrap` backend and Pi SDK 0.82.1 or newer. `/sandbox` controls the independent Subagents profile, which each launch freezes. Pi handles its own startup, authentication, and provider connection; task tools obey the selected file, command, and network permissions. Outside project defaults to Write: tasks write across home and temp but can remove files outside the workspace only in temp, hidden home directories, and worktree folders (Linux keeps ordinary home folders read-only instead). Confined children admit `read`, `write`, `edit`, and policy-permitted `bash` or guarded `run_application`, the guarded `apply_patch` (Codex patches that follow the file rules), and the selected extension tools with verified providers (defaults include `web_fetch` and `web_search`), which run outside the file rules. Other requested tools are reported as unavailable, with the reason. For direct applications without shell scripts, set Subagents → Sandbox On, Run applications On, Shell scripts Off, and Command time limit to 10 min in `/sandbox`, then press Ctrl+S. This is an explicit choice, not the default. New launches capture the policy; running children keep theirs. See [usage notes](https://github.com/1aboveio/pi-better-harness/blob/main/packages/pi-better-subagents/docs/usage.md#write-sandbox) for the runtime boundary and supported configurations.
|
|
91
94
|
|
|
92
95
|
## Delegation Modes
|
|
93
96
|
|
|
94
97
|
The user config sets `delegationMode` to `manual`, `adaptive` (default), or
|
|
95
98
|
`coordinator`. `/subagents settings` (or `/subagents`) opens a settings page
|
|
96
|
-
for delegation mode, the concurrent-subagent cap (default 6),
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
for delegation mode, the concurrent-subagent cap (default 6), and Git workspace
|
|
100
|
+
(Clone or Worktree). Run timeout supports a duration or **No limit**. The
|
|
101
|
+
tool-wait alert (default 5 minutes) and no-progress alert (default 10 minutes)
|
|
102
|
+
have separate intervals. Enter `0` to turn an alert off. Skill exposure cycles between Discover automatically and No skill
|
|
100
103
|
catalog. The Selected skills row opens the same searchable checkbox picker used
|
|
101
104
|
by `/agents`: it lists loaded skills by name and description, Space toggles one,
|
|
102
105
|
Enter applies, and typing filters without dropping checked items. Saved paths
|
|
103
106
|
missing from discovery stay visible as unavailable and survive apply. Zero
|
|
104
107
|
checked applies No skill catalog, not discovery. Manual Add skill path remains
|
|
105
|
-
available. The
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
exposure as defaults, and Reset to defaults clears session overrides, including
|
|
108
|
+
available. The Skill exposure row shows where the current skill setting comes from. The session choice controls the next launch before Ctrl+S, and
|
|
109
|
+
edits persist across reloads. Ctrl+S saves delegation, workspace, timing, and skill
|
|
110
|
+
settings as defaults, and Reset to defaults clears session overrides, including
|
|
109
111
|
the skill list. Agents opens the same catalog as `/agents`; a definition that inherits
|
|
110
112
|
skill exposure shows whether the live value comes from this session, saved
|
|
111
113
|
config, or discovery, and an invalid draft is marked invalid rather than shown
|
|
@@ -194,7 +196,7 @@ The projection exposes an opaque semantic `revision`, readable `reason`, attempt
|
|
|
194
196
|
identity, process status, termination evidence and retained evidence references.
|
|
195
197
|
Compare revisions for equality; unchanged observations keep the same revision.
|
|
196
198
|
Unavailable or unsupported coordinator reads report Waiting with an unverified
|
|
197
|
-
reason. See the [projection contract](
|
|
199
|
+
reason. See the [projection contract](https://github.com/1aboveio/pi-better-harness/blob/main/docs/adr/0022-assignment-progress-projection.md).
|
|
198
200
|
|
|
199
201
|
- Repository: https://github.com/1aboveio/pi-better-harness
|
|
200
202
|
- Detailed notes: https://github.com/1aboveio/pi-better-harness/blob/main/packages/pi-better-subagents/docs/usage.md
|
|
@@ -4,10 +4,10 @@ import { randomUUID } from "node:crypto";
|
|
|
4
4
|
import { isDeepStrictEqual } from "node:util";
|
|
5
5
|
import { join, relative, isAbsolute, dirname, resolve } from "node:path";
|
|
6
6
|
import { openSync, closeSync, fstatSync, readSync, realpathSync, constants } from "node:fs";
|
|
7
|
-
import { openStore, ownerDiff
|
|
7
|
+
import { openStore, ownerDiff } from "./shared-operation-coordinator/index.domain.mjs";
|
|
8
8
|
import { processStartToken, readMeta } from "./registry.domain.mjs";
|
|
9
9
|
import { credentialFilePaths } from "./shared-sandbox-core.domain.mjs";
|
|
10
|
-
import { readAssignmentReport } from "./assignment-report.domain.mjs";
|
|
10
|
+
import { assignmentReportOutcomeReason, readAssignmentReport } from "./assignment-report.domain.mjs";
|
|
11
11
|
export const ASSIGNMENT_OUTCOMES_VERSION = 1;
|
|
12
12
|
const closedHosts = globalThis.__assignmentOutcomeClosedHosts ??= new Set();
|
|
13
13
|
export function createOutcomeHost() {
|
|
@@ -129,9 +129,10 @@ export function commitAssignmentTerminal(meta, recoveryFailure = false) {
|
|
|
129
129
|
try {
|
|
130
130
|
return store.recordAssignmentOutcome({ ...binding, revision: 1,
|
|
131
131
|
outcome: complete ? "succeeded" : meta.status === "killed" ? "cancelled" : "failed",
|
|
132
|
-
reason: meta.failureReason || invalidReport || (meta.status === "completed" && report ? report
|
|
133
|
-
: meta.status === "completed"
|
|
134
|
-
:
|
|
132
|
+
reason: (meta.failureReason || invalidReport || (meta.status === "completed" && report ? assignmentReportOutcomeReason(report) : complete ? "Assigned work and required interpretation are complete."
|
|
133
|
+
: meta.status === "completed" && meta.assignmentReportRejection ? `Assignment report rejected: ${meta.assignmentReportRejection.reason}`
|
|
134
|
+
: meta.status === "completed" ? "Assignment completion is unverified: the attempt exited without an evidence-backed completion decision. Inspect retained output and continue unfinished work or report a concrete blocker."
|
|
135
|
+
: `Assignment ended ${meta.status}; retained attempt evidence is available.`)).slice(0, 8192),
|
|
135
136
|
processUncertain: meta.status === "lost" || typeof meta.exitCode !== "number"
|
|
136
137
|
|| waits.some((w) => w.dependencies.some((d) => d.terminalRevision === 0)
|
|
137
138
|
|| store.listResumeClaims({ waitId: w.waitId, generation: w.generation, state: "published" }).length > 0),
|
|
@@ -143,10 +144,12 @@ export function commitAssignmentTerminal(meta, recoveryFailure = false) {
|
|
|
143
144
|
catch (error) {
|
|
144
145
|
// A competing finalizer may commit after our initial read. The store
|
|
145
146
|
// still refuses rewrites; return only the same captured binding's winner.
|
|
146
|
-
|
|
147
|
+
// Borrowed runtime stores use a different coordinator module's StoreError constructor.
|
|
148
|
+
if (error instanceof Error && error.name === "StoreError" && "code" in error
|
|
149
|
+
&& error.code === "validation" && error.message === "A terminal assignment cannot be rewritten or reopened.") {
|
|
147
150
|
const winner = store.getAssignmentOutcome(binding.assignmentId);
|
|
148
151
|
const current = readMeta(meta.id);
|
|
149
|
-
if (winner && winner.assignmentId === binding.assignmentId && ownerDiff(winner.owner, binding.owner) === "none"
|
|
152
|
+
if (winner && winner.assignmentId === binding.assignmentId && winner.revision === 1 && ownerDiff(winner.owner, binding.owner) === "none"
|
|
150
153
|
&& ownerDiff(winner.recipient, binding.recipient) === "none"
|
|
151
154
|
&& current?.assignment?.assignmentId === binding.assignmentId
|
|
152
155
|
&& ownerDiff(current.assignment.owner, binding.owner) === "none" && ownerDiff(current.assignment.recipient, binding.recipient) === "none"
|
|
@@ -3,12 +3,12 @@ import { randomUUID } from "node:crypto";
|
|
|
3
3
|
import { isDeepStrictEqual } from "node:util";
|
|
4
4
|
import { join, relative, isAbsolute, dirname, resolve } from "node:path";
|
|
5
5
|
import { openSync, closeSync, fstatSync, readSync, realpathSync, constants } from "node:fs";
|
|
6
|
-
import { openStore, ownerDiff,
|
|
6
|
+
import { openStore, ownerDiff, type OwnerIdentity, type AssignmentOutcomeRecord } from "./shared-operation-coordinator/index.ts";
|
|
7
7
|
import type { RunMeta } from "./registry.ts";
|
|
8
8
|
import { processStartToken, readMeta } from "./registry.ts";
|
|
9
9
|
import type { PermissionSnapshot } from "./permission-policy.ts";
|
|
10
10
|
import { credentialFilePaths } from "./shared-sandbox-core.ts";
|
|
11
|
-
import { readAssignmentReport } from "./assignment-report.ts";
|
|
11
|
+
import { assignmentReportOutcomeReason, readAssignmentReport } from "./assignment-report.ts";
|
|
12
12
|
|
|
13
13
|
export const ASSIGNMENT_OUTCOMES_VERSION = 1;
|
|
14
14
|
const closedHosts = (globalThis as typeof globalThis & { __assignmentOutcomeClosedHosts?: Set<string> }).__assignmentOutcomeClosedHosts ??= new Set<string>();
|
|
@@ -93,9 +93,10 @@ export function commitAssignmentTerminal(meta: RunMeta, recoveryFailure = false)
|
|
|
93
93
|
: !invalidReport && waits.some((w) => w.acknowledgement?.disposition === "assignment-complete"));
|
|
94
94
|
try { return store.recordAssignmentOutcome({ ...binding, revision: 1,
|
|
95
95
|
outcome: complete ? "succeeded" : meta.status === "killed" ? "cancelled" : "failed",
|
|
96
|
-
reason: meta.failureReason || invalidReport || (meta.status === "completed" && report ? report
|
|
96
|
+
reason: (meta.failureReason || invalidReport || (meta.status === "completed" && report ? assignmentReportOutcomeReason(report) : complete ? "Assigned work and required interpretation are complete."
|
|
97
|
+
: meta.status === "completed" && meta.assignmentReportRejection ? `Assignment report rejected: ${meta.assignmentReportRejection.reason}`
|
|
97
98
|
: meta.status === "completed" ? "Assignment completion is unverified: the attempt exited without an evidence-backed completion decision. Inspect retained output and continue unfinished work or report a concrete blocker."
|
|
98
|
-
: `Assignment ended ${meta.status}; retained attempt evidence is available.`),
|
|
99
|
+
: `Assignment ended ${meta.status}; retained attempt evidence is available.`)).slice(0, 8192),
|
|
99
100
|
processUncertain: meta.status === "lost" || typeof meta.exitCode !== "number"
|
|
100
101
|
|| waits.some((w) => w.dependencies.some((d) => d.terminalRevision === 0)
|
|
101
102
|
|| store.listResumeClaims({ waitId: w.waitId, generation: w.generation, state: "published" }).length > 0),
|
|
@@ -106,10 +107,12 @@ export function commitAssignmentTerminal(meta: RunMeta, recoveryFailure = false)
|
|
|
106
107
|
}); } catch (error) {
|
|
107
108
|
// A competing finalizer may commit after our initial read. The store
|
|
108
109
|
// still refuses rewrites; return only the same captured binding's winner.
|
|
109
|
-
|
|
110
|
+
// Borrowed runtime stores use a different coordinator module's StoreError constructor.
|
|
111
|
+
if (error instanceof Error && error.name === "StoreError" && "code" in error
|
|
112
|
+
&& error.code === "validation" && error.message === "A terminal assignment cannot be rewritten or reopened.") {
|
|
110
113
|
const winner = store.getAssignmentOutcome(binding.assignmentId);
|
|
111
114
|
const current = readMeta(meta.id);
|
|
112
|
-
if (winner && winner.assignmentId === binding.assignmentId && ownerDiff(winner.owner, binding.owner) === "none"
|
|
115
|
+
if (winner && winner.assignmentId === binding.assignmentId && winner.revision === 1 && ownerDiff(winner.owner, binding.owner) === "none"
|
|
113
116
|
&& ownerDiff(winner.recipient, binding.recipient) === "none"
|
|
114
117
|
&& current?.assignment?.assignmentId === binding.assignmentId
|
|
115
118
|
&& ownerDiff(current.assignment.owner, binding.owner) === "none" && ownerDiff(current.assignment.recipient, binding.recipient) === "none"
|