pi-better-server 0.4.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 +8 -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 +87 -0
- package/scripts/event-publication/writer.mjs +6 -0
- package/scripts/measure-full-runtime/frontend.ts +24 -0
- package/scripts/measure-full-runtime/hosted-extension.ts +28 -0
- package/scripts/measure-full-runtime/probe.mjs +29 -0
- 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 +146 -0
- package/scripts/measure-shared-reads/probe.mjs +26 -2
- package/scripts/measure-shared-reads.mjs +44 -9
- package/scripts/private-runtime/package-lock.json +66 -4
- package/scripts/private-runtime/package.json +10 -2
- package/scripts/source-provenance.mjs +31 -0
- package/scripts/test-on-pi.sh +3 -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 +27 -0
- package/src/runtime/background-tools.ts +389 -0
- package/src/runtime/background.ts +410 -48
- 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 +71 -33
- 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 +89 -4
- package/src/runtime/domain/background/types.mjs +1 -0
- package/src/runtime/domain/background-service/adapter-contract.domain.mjs +83 -0
- package/src/runtime/domain/background-service/adapter-contract.ts +70 -0
- package/src/runtime/domain/background-service/batch.domain.mjs +91 -0
- package/src/runtime/domain/background-service/batch.ts +111 -0
- package/src/runtime/domain/background-service/conditions.domain.mjs +94 -0
- package/src/runtime/domain/background-service/conditions.ts +99 -0
- package/src/runtime/domain/background-service/delivery-observer.domain.mjs +37 -0
- package/src/runtime/domain/background-service/delivery-observer.ts +42 -0
- package/src/runtime/domain/background-service/failures.domain.mjs +209 -0
- package/src/runtime/domain/background-service/failures.ts +212 -0
- package/src/runtime/domain/background-service/goal-provider.domain.mjs +193 -0
- package/src/runtime/domain/background-service/goal-provider.ts +209 -0
- package/src/runtime/domain/background-service/index.domain.mjs +54 -0
- package/src/runtime/domain/background-service/index.ts +55 -0
- package/src/runtime/domain/background-service/logs.domain.mjs +129 -0
- package/src/runtime/domain/background-service/logs.ts +134 -0
- package/src/runtime/domain/background-service/maintenance.domain.mjs +95 -0
- package/src/runtime/domain/background-service/maintenance.ts +98 -0
- package/src/runtime/domain/background-service/managed-authority.domain.mjs +32 -0
- package/src/runtime/domain/background-service/managed-authority.ts +30 -0
- package/src/runtime/domain/background-service/managed-client.domain.mjs +79 -0
- package/src/runtime/domain/background-service/managed-client.ts +73 -0
- package/src/runtime/domain/background-service/managed-frontend.domain.mjs +225 -0
- package/src/runtime/domain/background-service/managed-frontend.ts +176 -0
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +492 -0
- package/src/runtime/domain/background-service/navigator-provider.ts +485 -0
- 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 +4080 -0
- package/src/runtime/domain/background-service/observed-waits.ts +4513 -0
- package/src/runtime/domain/background-service/output.domain.mjs +867 -0
- package/src/runtime/domain/background-service/output.ts +952 -0
- package/src/runtime/domain/background-service/process-identity.domain.mjs +129 -0
- package/src/runtime/domain/background-service/process-identity.ts +134 -0
- package/src/runtime/domain/background-service/process.domain.mjs +512 -0
- package/src/runtime/domain/background-service/process.ts +532 -0
- package/src/runtime/domain/background-service/prompt.domain.mjs +58 -0
- package/src/runtime/domain/background-service/prompt.ts +72 -0
- package/src/runtime/domain/background-service/registry.domain.mjs +460 -0
- package/src/runtime/domain/background-service/registry.ts +450 -0
- package/src/runtime/domain/background-service/remote-task-preset.domain.mjs +67 -0
- package/src/runtime/domain/background-service/remote-task-preset.ts +127 -0
- package/src/runtime/domain/background-service/runtime.domain.mjs +1511 -0
- package/src/runtime/domain/background-service/runtime.ts +1636 -0
- package/src/runtime/domain/background-service/sandbox.domain.mjs +735 -0
- package/src/runtime/domain/background-service/sandbox.ts +913 -0
- package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +777 -0
- package/src/runtime/domain/background-service/shared-callback-batcher.ts +956 -0
- package/src/runtime/domain/background-service/shared-execution-policy.domain.mjs +50 -0
- package/src/runtime/domain/background-service/shared-execution-policy.ts +61 -0
- package/src/runtime/domain/background-service/shared-failure-observations.domain.mjs +1078 -0
- package/src/runtime/domain/background-service/shared-failure-observations.ts +1166 -0
- package/src/runtime/domain/background-service/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/background-service/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/background-service/shared-log-utils.domain.mjs +1223 -0
- package/src/runtime/domain/background-service/shared-log-utils.ts +1492 -0
- package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +289 -0
- package/src/runtime/domain/background-service/shared-navigator-panels.ts +272 -0
- package/src/runtime/domain/background-service/shared-navigator.domain.mjs +1930 -0
- package/src/runtime/domain/background-service/shared-navigator.ts +1962 -0
- 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 +189 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/index.domain.mjs +51 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/index.ts +122 -0
- 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 +163 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +174 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-parent-callbacks.domain.mjs +66 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +87 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +90 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +97 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +139 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/errors.domain.mjs +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/errors.ts +79 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +342 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +513 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.domain.mjs +283 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +458 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/recovery.domain.mjs +52 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/recovery.ts +55 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +114 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +140 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +280 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +442 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +420 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +441 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/sqlite.domain.mjs +194 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/sqlite.ts +239 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +275 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +585 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +120 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +142 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-cancellation.domain.mjs +188 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-cancellation.ts +224 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +25 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +707 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/upgrade.domain.mjs +22 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/upgrade.ts +22 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/validate.domain.mjs +234 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/validate.ts +241 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.domain.mjs +851 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.ts +1424 -0
- package/src/runtime/domain/background-service/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/background-service/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/background-service/shared-render-scheduler.domain.mjs +41 -0
- package/src/runtime/domain/background-service/shared-render-scheduler.ts +47 -0
- package/src/runtime/domain/background-service/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/background-service/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/background-service/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/background-service/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/background-service/shared-ssh-core/index.domain.mjs +698 -0
- package/src/runtime/domain/background-service/shared-ssh-core/index.ts +979 -0
- package/src/runtime/domain/background-service/shared-stall-detector.domain.mjs +37 -0
- package/src/runtime/domain/background-service/shared-stall-detector.ts +69 -0
- package/src/runtime/domain/background-service/shared-work-client.mjs +303 -0
- package/src/runtime/domain/background-service/stall-attention.domain.mjs +29 -0
- package/src/runtime/domain/background-service/stall-attention.ts +31 -0
- package/src/runtime/domain/background-service/stall.domain.mjs +57 -0
- package/src/runtime/domain/background-service/stall.ts +57 -0
- package/src/runtime/domain/background-service/supervisor/README.md +111 -0
- package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +90 -0
- package/src/runtime/domain/background-service/supervisor/generated/conditions.mjs +96 -0
- package/src/runtime/domain/background-service/supervisor/generated/identity.mjs +95 -0
- package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +131 -0
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +514 -0
- package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +872 -0
- package/src/runtime/domain/background-service/supervisor/generated/store.mjs +609 -0
- package/src/runtime/domain/background-service/supervisor/generated/types.mjs +50 -0
- package/src/runtime/domain/background-service/supervisor/identity.domain.mjs +93 -0
- package/src/runtime/domain/background-service/supervisor/identity.ts +99 -0
- package/src/runtime/domain/background-service/supervisor/index.domain.mjs +22 -0
- package/src/runtime/domain/background-service/supervisor/index.ts +37 -0
- package/src/runtime/domain/background-service/supervisor/invocation.domain.mjs +30 -0
- package/src/runtime/domain/background-service/supervisor/invocation.ts +44 -0
- package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +870 -0
- package/src/runtime/domain/background-service/supervisor/runner.ts +982 -0
- package/src/runtime/domain/background-service/supervisor/store.domain.mjs +605 -0
- package/src/runtime/domain/background-service/supervisor/store.ts +651 -0
- package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +721 -0
- package/src/runtime/domain/background-service/supervisor/supervisor.ts +804 -0
- package/src/runtime/domain/background-service/supervisor/types.domain.mjs +48 -0
- package/src/runtime/domain/background-service/supervisor/types.ts +394 -0
- package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +60 -0
- package/src/runtime/domain/background-service/task-diagnostics.ts +71 -0
- package/src/runtime/domain/background-service/tools.domain.mjs +1050 -0
- package/src/runtime/domain/background-service/tools.ts +1142 -0
- package/src/runtime/domain/background-service/types.domain.mjs +5 -0
- package/src/runtime/domain/background-service/types.ts +236 -0
- package/src/runtime/domain/background-service/work-observation.domain.mjs +176 -0
- package/src/runtime/domain/background-service/work-observation.ts +144 -0
- 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-parent-callbacks.mjs +65 -0
- package/src/runtime/domain/coordinator/src/background-requests.mjs +86 -0
- 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 +73 -21
- package/src/runtime/domain/coordinator/src/store.mjs +32 -3
- package/src/runtime/domain/coordinator/src/subagent-launch.mjs +119 -0
- package/src/runtime/domain/coordinator/src/types.mjs +1 -1
- package/src/runtime/domain/coordinator/src/upgrade.mjs +22 -0
- 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 +633 -0
- package/src/runtime/domain/sandbox-policy/background-admission.domain.mjs +83 -0
- package/src/runtime/domain/sandbox-policy/background-admission.ts +75 -0
- package/src/runtime/domain/sandbox-policy/commands.domain.mjs +245 -0
- package/src/runtime/domain/sandbox-policy/commands.ts +336 -0
- package/src/runtime/domain/sandbox-policy/deny-rules.domain.mjs +440 -0
- package/src/runtime/domain/sandbox-policy/deny-rules.ts +620 -0
- package/src/runtime/domain/sandbox-policy/diagnostics-command.domain.mjs +30 -0
- package/src/runtime/domain/sandbox-policy/diagnostics-command.ts +27 -0
- package/src/runtime/domain/sandbox-policy/events.domain.mjs +49 -0
- package/src/runtime/domain/sandbox-policy/events.ts +85 -0
- package/src/runtime/domain/sandbox-policy/files.domain.mjs +153 -0
- package/src/runtime/domain/sandbox-policy/files.ts +224 -0
- package/src/runtime/domain/sandbox-policy/index.domain.mjs +289 -0
- package/src/runtime/domain/sandbox-policy/index.ts +386 -0
- package/src/runtime/domain/sandbox-policy/package.json +66 -0
- package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +36 -0
- package/src/runtime/domain/sandbox-policy/permission-settings.ts +46 -0
- package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +309 -0
- package/src/runtime/domain/sandbox-policy/permissions-page.ts +295 -0
- package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +98 -0
- package/src/runtime/domain/sandbox-policy/permissions.ts +125 -0
- package/src/runtime/domain/sandbox-policy/policy.domain.mjs +80 -0
- package/src/runtime/domain/sandbox-policy/policy.ts +102 -0
- package/src/runtime/domain/sandbox-policy/preferences.domain.mjs +55 -0
- package/src/runtime/domain/sandbox-policy/preferences.ts +82 -0
- package/src/runtime/domain/sandbox-policy/rules-page.domain.mjs +138 -0
- package/src/runtime/domain/sandbox-policy/rules-page.ts +176 -0
- package/src/runtime/domain/sandbox-policy/session-permissions.domain.mjs +22 -0
- package/src/runtime/domain/sandbox-policy/session-permissions.ts +24 -0
- package/src/runtime/domain/sandbox-policy/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/sandbox-policy/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/sandbox-policy/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/sandbox-policy/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/sandbox-policy/shared-task-application.domain.mjs +185 -0
- package/src/runtime/domain/sandbox-policy/shared-task-application.ts +185 -0
- package/src/runtime/domain/sandbox-policy/shared-task-apply-patch.domain.mjs +416 -0
- package/src/runtime/domain/sandbox-policy/shared-task-apply-patch.ts +409 -0
- package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +325 -0
- package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +335 -0
- package/src/runtime/domain/sandbox-policy/shared-task-files.domain.mjs +346 -0
- package/src/runtime/domain/sandbox-policy/shared-task-files.ts +342 -0
- 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 +220 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +209 -0
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +227 -0
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +224 -0
- package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +92 -0
- package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +123 -0
- package/src/runtime/domain/sandbox-policy/shell.domain.mjs +93 -0
- package/src/runtime/domain/sandbox-policy/shell.ts +129 -0
- package/src/runtime/domain/sandbox-policy/state.domain.mjs +307 -0
- package/src/runtime/domain/sandbox-policy/state.ts +408 -0
- package/src/runtime/domain/sandbox-policy/status.domain.mjs +64 -0
- package/src/runtime/domain/sandbox-policy/status.ts +76 -0
- package/src/runtime/domain/sandbox-policy/subagent-admission.domain.mjs +69 -0
- package/src/runtime/domain/sandbox-policy/subagent-admission.ts +60 -0
- package/src/runtime/domain/subagents/CONTEXT.md +202 -0
- package/src/runtime/domain/subagents/PRODUCT.md +49 -0
- package/src/runtime/domain/subagents/README.md +201 -0
- package/src/runtime/domain/subagents/agent-catalog.mjs +64 -0
- package/src/runtime/domain/subagents/agent-commands.domain.mjs +822 -0
- package/src/runtime/domain/subagents/agent-commands.ts +905 -0
- package/src/runtime/domain/subagents/agent-inspection.domain.mjs +398 -0
- package/src/runtime/domain/subagents/agent-inspection.ts +574 -0
- package/src/runtime/domain/subagents/agent-operations.domain.mjs +40 -0
- package/src/runtime/domain/subagents/agent-operations.ts +61 -0
- package/src/runtime/domain/subagents/agent-session-settings.domain.mjs +112 -0
- package/src/runtime/domain/subagents/agent-session-settings.ts +118 -0
- package/src/runtime/domain/subagents/agents-catalog-tool.domain.mjs +84 -0
- package/src/runtime/domain/subagents/agents-catalog-tool.ts +118 -0
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +276 -0
- package/src/runtime/domain/subagents/assignment-outcomes.ts +212 -0
- package/src/runtime/domain/subagents/assignment-projection.mjs +261 -0
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +174 -0
- package/src/runtime/domain/subagents/assignment-report.ts +156 -0
- package/src/runtime/domain/subagents/batch.mjs +275 -0
- package/src/runtime/domain/subagents/callback-fields.domain.mjs +72 -0
- package/src/runtime/domain/subagents/callback-fields.ts +95 -0
- package/src/runtime/domain/subagents/capacity.mjs +108 -0
- package/src/runtime/domain/subagents/catalog-editor.domain.mjs +98 -0
- package/src/runtime/domain/subagents/catalog-editor.ts +125 -0
- package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +104 -0
- package/src/runtime/domain/subagents/catalog-host-admission.ts +85 -0
- package/src/runtime/domain/subagents/catalog-identity.domain.mjs +222 -0
- package/src/runtime/domain/subagents/catalog-identity.ts +258 -0
- package/src/runtime/domain/subagents/catalog-overlay.domain.mjs +9 -0
- package/src/runtime/domain/subagents/catalog-overlay.ts +10 -0
- package/src/runtime/domain/subagents/catalog-preferences.domain.mjs +164 -0
- package/src/runtime/domain/subagents/catalog-preferences.ts +139 -0
- package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +366 -0
- package/src/runtime/domain/subagents/catalog-resolver.ts +540 -0
- package/src/runtime/domain/subagents/catalog-runtime.domain.mjs +570 -0
- package/src/runtime/domain/subagents/catalog-runtime.ts +680 -0
- package/src/runtime/domain/subagents/catalog-schema.domain.mjs +1331 -0
- package/src/runtime/domain/subagents/catalog-schema.ts +1563 -0
- package/src/runtime/domain/subagents/catalog-skill-edits.domain.mjs +95 -0
- package/src/runtime/domain/subagents/catalog-skill-edits.ts +116 -0
- package/src/runtime/domain/subagents/catalog-store.domain.mjs +808 -0
- package/src/runtime/domain/subagents/catalog-store.ts +1006 -0
- package/src/runtime/domain/subagents/catalog-ui.domain.mjs +651 -0
- package/src/runtime/domain/subagents/catalog-ui.ts +611 -0
- 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-codemode.domain.mjs +16 -0
- package/src/runtime/domain/subagents/child-codemode.ts +17 -0
- package/src/runtime/domain/subagents/child-dependencies.mjs +193 -0
- package/src/runtime/domain/subagents/child-incidents.domain.mjs +170 -0
- package/src/runtime/domain/subagents/child-incidents.ts +169 -0
- package/src/runtime/domain/subagents/child-operations.domain.mjs +986 -0
- package/src/runtime/domain/subagents/child-operations.ts +1191 -0
- package/src/runtime/domain/subagents/child-ownership.domain.mjs +205 -0
- package/src/runtime/domain/subagents/child-ownership.ts +160 -0
- package/src/runtime/domain/subagents/child-preflight.mjs +38 -0
- 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/child-runtime.mjs +67 -0
- package/src/runtime/domain/subagents/child-steer.domain.mjs +109 -0
- package/src/runtime/domain/subagents/child-steer.ts +102 -0
- package/src/runtime/domain/subagents/cleanup.domain.mjs +818 -0
- package/src/runtime/domain/subagents/cleanup.ts +1017 -0
- package/src/runtime/domain/subagents/codex-import.domain.mjs +575 -0
- package/src/runtime/domain/subagents/codex-import.ts +717 -0
- package/src/runtime/domain/subagents/completion.domain.mjs +6 -0
- package/src/runtime/domain/subagents/completion.mjs +152 -0
- package/src/runtime/domain/subagents/completion.ts +11 -0
- package/src/runtime/domain/subagents/config.domain.mjs +248 -0
- package/src/runtime/domain/subagents/config.json +15 -0
- package/src/runtime/domain/subagents/config.ts +328 -0
- package/src/runtime/domain/subagents/continuation-authority.domain.mjs +38 -0
- package/src/runtime/domain/subagents/continuation-authority.ts +31 -0
- 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 +942 -0
- package/src/runtime/domain/subagents/continuation.ts +1051 -0
- package/src/runtime/domain/subagents/delegation.domain.mjs +19 -0
- package/src/runtime/domain/subagents/delegation.ts +24 -0
- package/src/runtime/domain/subagents/effective-settings.domain.mjs +130 -0
- package/src/runtime/domain/subagents/effective-settings.ts +184 -0
- package/src/runtime/domain/subagents/extensions.domain.mjs +6 -0
- package/src/runtime/domain/subagents/extensions.mjs +164 -0
- package/src/runtime/domain/subagents/extensions.ts +19 -0
- package/src/runtime/domain/subagents/failures.domain.mjs +362 -0
- package/src/runtime/domain/subagents/failures.ts +319 -0
- package/src/runtime/domain/subagents/finalization.domain.mjs +168 -0
- package/src/runtime/domain/subagents/finalization.ts +218 -0
- package/src/runtime/domain/subagents/git-remotes.domain.mjs +351 -0
- package/src/runtime/domain/subagents/git-remotes.ts +413 -0
- package/src/runtime/domain/subagents/git-workspace.domain.mjs +337 -0
- package/src/runtime/domain/subagents/git-workspace.ts +430 -0
- package/src/runtime/domain/subagents/goal-provider.domain.mjs +125 -0
- package/src/runtime/domain/subagents/goal-provider.ts +132 -0
- package/src/runtime/domain/subagents/health-observation.domain.mjs +617 -0
- package/src/runtime/domain/subagents/health-observation.ts +818 -0
- package/src/runtime/domain/subagents/health-surface.mjs +284 -0
- package/src/runtime/domain/subagents/health.domain.mjs +261 -0
- package/src/runtime/domain/subagents/health.ts +343 -0
- package/src/runtime/domain/subagents/historical-attention.domain.mjs +37 -0
- package/src/runtime/domain/subagents/historical-attention.ts +35 -0
- package/src/runtime/domain/subagents/incident-model.domain.mjs +322 -0
- package/src/runtime/domain/subagents/incident-model.ts +358 -0
- package/src/runtime/domain/subagents/index.domain.mjs +4731 -0
- package/src/runtime/domain/subagents/index.ts +4781 -0
- package/src/runtime/domain/subagents/launch-abort.domain.mjs +13 -0
- package/src/runtime/domain/subagents/launch-abort.ts +21 -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/lifecycle.domain.mjs +265 -0
- package/src/runtime/domain/subagents/lifecycle.ts +360 -0
- package/src/runtime/domain/subagents/list.domain.mjs +2 -0
- package/src/runtime/domain/subagents/list.mjs +152 -0
- package/src/runtime/domain/subagents/list.ts +19 -0
- package/src/runtime/domain/subagents/log-cursor.domain.mjs +217 -0
- package/src/runtime/domain/subagents/log-cursor.ts +268 -0
- package/src/runtime/domain/subagents/managed-background-capability.domain.mjs +10 -0
- package/src/runtime/domain/subagents/managed-background-capability.ts +9 -0
- package/src/runtime/domain/subagents/managed-failure-worker.mjs +36 -0
- package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +48 -0
- package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +75 -0
- package/src/runtime/domain/subagents/managed-launch-client.ts +59 -0
- package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +627 -0
- package/src/runtime/domain/subagents/managed-launch-host.ts +504 -0
- package/src/runtime/domain/subagents/managed-launch-journal.mjs +17 -0
- package/src/runtime/domain/subagents/managed-launch-ownership.domain.mjs +29 -0
- package/src/runtime/domain/subagents/managed-launch-ownership.ts +22 -0
- package/src/runtime/domain/subagents/managed-launch-port.domain.mjs +2 -0
- package/src/runtime/domain/subagents/managed-launch-port.ts +25 -0
- package/src/runtime/domain/subagents/managed-launch-recovery.domain.mjs +29 -0
- package/src/runtime/domain/subagents/managed-launch-recovery.ts +45 -0
- package/src/runtime/domain/subagents/managed-worker-bridge.domain.mjs +63 -0
- package/src/runtime/domain/subagents/managed-worker-bridge.ts +48 -0
- package/src/runtime/domain/subagents/managed-worker.mjs +13 -0
- package/src/runtime/domain/subagents/model-resolution-core.domain.mjs +822 -0
- package/src/runtime/domain/subagents/model-resolution-core.ts +1074 -0
- package/src/runtime/domain/subagents/model-resolution.domain.mjs +22 -0
- package/src/runtime/domain/subagents/model-resolution.ts +32 -0
- package/src/runtime/domain/subagents/navigator.domain.mjs +6 -0
- package/src/runtime/domain/subagents/navigator.mjs +1233 -0
- package/src/runtime/domain/subagents/navigator.ts +39 -0
- package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +1012 -0
- package/src/runtime/domain/subagents/operation-bridge-types.ts +1156 -0
- package/src/runtime/domain/subagents/outage-observations.domain.mjs +84 -0
- package/src/runtime/domain/subagents/outage-observations.ts +73 -0
- package/src/runtime/domain/subagents/output-payload.domain.mjs +767 -0
- package/src/runtime/domain/subagents/output-payload.ts +987 -0
- 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 +86 -0
- package/src/runtime/domain/subagents/park-checkpoint.domain.mjs +55 -0
- package/src/runtime/domain/subagents/park-checkpoint.ts +61 -0
- package/src/runtime/domain/subagents/parse.domain.mjs +1218 -0
- package/src/runtime/domain/subagents/parse.ts +1451 -0
- package/src/runtime/domain/subagents/permission-policy.domain.mjs +232 -0
- package/src/runtime/domain/subagents/permission-policy.ts +291 -0
- package/src/runtime/domain/subagents/process-identity.mjs +33 -0
- package/src/runtime/domain/subagents/registry.domain.mjs +1584 -0
- package/src/runtime/domain/subagents/registry.ts +1904 -0
- package/src/runtime/domain/subagents/role-assignment.domain.mjs +104 -0
- package/src/runtime/domain/subagents/role-assignment.ts +141 -0
- package/src/runtime/domain/subagents/roles/role.architect.md +13 -0
- package/src/runtime/domain/subagents/roles/role.developer.md +16 -0
- package/src/runtime/domain/subagents/roles/role.explorer.md +13 -0
- package/src/runtime/domain/subagents/roles/role.product-manager.md +13 -0
- package/src/runtime/domain/subagents/roles/role.researcher.md +13 -0
- package/src/runtime/domain/subagents/roles/role.reviewer.md +13 -0
- package/src/runtime/domain/subagents/roles/role.writer.md +12 -0
- package/src/runtime/domain/subagents/sandbox.domain.mjs +64 -0
- package/src/runtime/domain/subagents/sandbox.ts +92 -0
- package/src/runtime/domain/subagents/session-selection.domain.mjs +32 -0
- package/src/runtime/domain/subagents/session-selection.ts +35 -0
- package/src/runtime/domain/subagents/session-store.domain.mjs +489 -0
- package/src/runtime/domain/subagents/session-store.ts +468 -0
- package/src/runtime/domain/subagents/settings-page.domain.mjs +313 -0
- package/src/runtime/domain/subagents/settings-page.ts +363 -0
- package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +777 -0
- package/src/runtime/domain/subagents/shared-callback-batcher.ts +956 -0
- package/src/runtime/domain/subagents/shared-catalog.domain.mjs +70 -0
- package/src/runtime/domain/subagents/shared-catalog.ts +61 -0
- package/src/runtime/domain/subagents/shared-execution-policy.domain.mjs +50 -0
- package/src/runtime/domain/subagents/shared-execution-policy.ts +61 -0
- package/src/runtime/domain/subagents/shared-failure-observations.domain.mjs +1078 -0
- package/src/runtime/domain/subagents/shared-failure-observations.ts +1166 -0
- package/src/runtime/domain/subagents/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/subagents/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/subagents/shared-log-utils.domain.mjs +1223 -0
- package/src/runtime/domain/subagents/shared-log-utils.ts +1492 -0
- package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +289 -0
- package/src/runtime/domain/subagents/shared-navigator-panels.ts +272 -0
- package/src/runtime/domain/subagents/shared-navigator.domain.mjs +1930 -0
- package/src/runtime/domain/subagents/shared-navigator.ts +1962 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +189 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/index.domain.mjs +51 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/index.ts +122 -0
- 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 +163 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +174 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-parent-callbacks.domain.mjs +66 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +87 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +90 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +97 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +139 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/errors.domain.mjs +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/errors.ts +79 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +342 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +513 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.domain.mjs +283 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +458 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/recovery.domain.mjs +52 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/recovery.ts +55 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +114 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +140 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +280 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +442 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +420 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +441 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/sqlite.domain.mjs +194 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/sqlite.ts +239 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +275 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +585 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +120 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +142 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.domain.mjs +188 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.ts +224 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +25 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +707 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/upgrade.domain.mjs +22 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/upgrade.ts +22 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/validate.domain.mjs +234 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/validate.ts +241 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.domain.mjs +851 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.ts +1424 -0
- package/src/runtime/domain/subagents/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/subagents/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/subagents/shared-render-scheduler.domain.mjs +41 -0
- package/src/runtime/domain/subagents/shared-render-scheduler.ts +47 -0
- package/src/runtime/domain/subagents/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/subagents/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/subagents/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/subagents/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/subagents/shared-stall-detector.domain.mjs +37 -0
- package/src/runtime/domain/subagents/shared-stall-detector.ts +69 -0
- package/src/runtime/domain/subagents/shared-task-application.domain.mjs +185 -0
- package/src/runtime/domain/subagents/shared-task-application.ts +185 -0
- package/src/runtime/domain/subagents/shared-task-apply-patch.domain.mjs +416 -0
- package/src/runtime/domain/subagents/shared-task-apply-patch.ts +409 -0
- package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +325 -0
- package/src/runtime/domain/subagents/shared-task-exec.ts +335 -0
- package/src/runtime/domain/subagents/shared-task-files.domain.mjs +346 -0
- package/src/runtime/domain/subagents/shared-task-files.ts +342 -0
- 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 +220 -0
- package/src/runtime/domain/subagents/shared-task-process-list.ts +209 -0
- package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +227 -0
- package/src/runtime/domain/subagents/shared-task-sandbox.ts +224 -0
- package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +92 -0
- package/src/runtime/domain/subagents/shared-task-tools.ts +123 -0
- package/src/runtime/domain/subagents/shared-work-client.mjs +303 -0
- package/src/runtime/domain/subagents/shared-worktree-context.domain.mjs +142 -0
- package/src/runtime/domain/subagents/shared-worktree-context.ts +158 -0
- package/src/runtime/domain/subagents/skill-picker.domain.mjs +316 -0
- package/src/runtime/domain/subagents/skill-picker.ts +353 -0
- package/src/runtime/domain/subagents/skills.domain.mjs +138 -0
- package/src/runtime/domain/subagents/skills.ts +183 -0
- package/src/runtime/domain/subagents/spawn.domain.mjs +72 -0
- package/src/runtime/domain/subagents/spawn.ts +80 -0
- package/src/runtime/domain/subagents/stop.domain.mjs +184 -0
- package/src/runtime/domain/subagents/stop.ts +217 -0
- package/src/runtime/domain/subagents/subagent-tools.domain.mjs +101 -0
- package/src/runtime/domain/subagents/subagent-tools.ts +137 -0
- package/src/runtime/domain/subagents/task-guard.domain.mjs +163 -0
- package/src/runtime/domain/subagents/task-guard.ts +144 -0
- package/src/runtime/domain/subagents/task-policy.domain.mjs +201 -0
- package/src/runtime/domain/subagents/task-policy.ts +236 -0
- package/src/runtime/domain/subagents/task-runtime.mjs +53 -0
- package/src/runtime/domain/subagents/task-tool-owner.domain.mjs +18 -0
- package/src/runtime/domain/subagents/task-tool-owner.ts +21 -0
- package/src/runtime/domain/subagents/thinking.domain.mjs +22 -0
- package/src/runtime/domain/subagents/thinking.ts +28 -0
- package/src/runtime/domain/subagents/tier-policy.domain.mjs +75 -0
- package/src/runtime/domain/subagents/tier-policy.ts +126 -0
- package/src/runtime/domain/subagents/timing-notifications.domain.mjs +51 -0
- package/src/runtime/domain/subagents/timing-notifications.ts +37 -0
- package/src/runtime/domain/subagents/timing.domain.mjs +487 -0
- package/src/runtime/domain/subagents/timing.ts +634 -0
- package/src/runtime/domain/subagents/tools.domain.mjs +558 -0
- package/src/runtime/domain/subagents/tools.ts +629 -0
- package/src/runtime/domain/subagents/widget.domain.mjs +6 -0
- package/src/runtime/domain/subagents/widget.mjs +246 -0
- package/src/runtime/domain/subagents/widget.ts +30 -0
- package/src/runtime/domain/subagents/work-observation.domain.mjs +316 -0
- package/src/runtime/domain/subagents/work-observation.ts +248 -0
- package/src/runtime/domain/subagents/worker-catalog.domain.mjs +120 -0
- package/src/runtime/domain/subagents/worker-catalog.ts +162 -0
- package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +1009 -0
- package/src/runtime/domain/subagents/worker-operations-host.ts +1238 -0
- package/src/runtime/domain/subagents/worker-waits.domain.mjs +2336 -0
- package/src/runtime/domain/subagents/worker-waits.ts +2878 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.mjs +52 -0
- package/src/runtime/domain/subagents/workspace-scope.ts +50 -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 +27 -3
- package/src/runtime/query-executor.ts +178 -34
- package/src/runtime/query-worker.mjs +119 -22
- package/src/runtime/read-model.ts +939 -113
- 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 +73 -0
- 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 +185 -22
- package/src/session-activity.ts +26 -4
- package/src/version.ts +1 -1
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
// Generated from packages/task-sandbox/files.ts. Do not edit directly.
|
|
2
|
+
/** Kernel-confined operations for Pi's built-in file tools. */
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { constants, realpathSync } from "node:fs";
|
|
6
|
+
import { access, lstat, mkdir, open, readFile, stat, unlink, writeFile } from "node:fs/promises";
|
|
7
|
+
import { basename, dirname, join } from "node:path";
|
|
8
|
+
import type { ReadOperations, WriteOperations, EditOperations } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
import type { SandboxDiagnostics, DiagnosticResource } from "./shared-sandbox-diagnostics.ts";
|
|
10
|
+
import {
|
|
11
|
+
canonicalizePath, compileWritePolicy, evaluateDeleteAccess, evaluateReadAccess, evaluateWriteAccess, maybeBuildSandboxCommand,
|
|
12
|
+
type CompiledSandboxWritePolicy, type SandboxSeams, type SandboxWritePolicy, type WriteAccessDecision,
|
|
13
|
+
} from "./shared-sandbox-core.ts";
|
|
14
|
+
|
|
15
|
+
export interface TaskFileController {
|
|
16
|
+
requireLaunchPlan(): { confined: false } | { confined: true; policy: SandboxWritePolicy; profilePath: string };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// The SDK truncates display output after reading. This separate operation cap
|
|
20
|
+
// bounds worker memory and pipe traffic, and rejects rather than truncates files.
|
|
21
|
+
const MAX_FILE_BYTES = 8 * 1024 * 1024;
|
|
22
|
+
const MAX_REQUEST_BYTES = 12 * 1024 * 1024;
|
|
23
|
+
const MAX_RESPONSE_BYTES = 12 * 1024 * 1024;
|
|
24
|
+
|
|
25
|
+
// Fixed program: tool-supplied path/content are JSON on stdin, never argv/code.
|
|
26
|
+
const FILE_WORKER = String.raw`
|
|
27
|
+
const fs = require('node:fs/promises');
|
|
28
|
+
const { constants } = require('node:fs');
|
|
29
|
+
const MAX = 8 * 1024 * 1024;
|
|
30
|
+
let input = Buffer.alloc(0);
|
|
31
|
+
process.stdin.on('data', chunk => {
|
|
32
|
+
if (input.length + chunk.length > 12 * 1024 * 1024) {
|
|
33
|
+
process.stdout.write(JSON.stringify({error:'File operation request exceeds 12 MiB',code:'EFBIG'}));
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
input = Buffer.concat([input, chunk]);
|
|
37
|
+
});
|
|
38
|
+
process.stdin.on('end', async () => {
|
|
39
|
+
try {
|
|
40
|
+
const { operation, path, content } = JSON.parse(input.toString('utf8'));
|
|
41
|
+
if (typeof path !== 'string') throw new Error('Invalid file path');
|
|
42
|
+
let data;
|
|
43
|
+
switch (operation) {
|
|
44
|
+
case 'read':
|
|
45
|
+
case 'mime': {
|
|
46
|
+
const handle = await fs.open(path, 'r');
|
|
47
|
+
try {
|
|
48
|
+
if (operation === 'mime') {
|
|
49
|
+
const sample = Buffer.alloc(4100);
|
|
50
|
+
const { bytesRead } = await handle.read(sample, 0, sample.length, 0);
|
|
51
|
+
data = sample.subarray(0, bytesRead).toString('base64');
|
|
52
|
+
} else {
|
|
53
|
+
const chunks = [];
|
|
54
|
+
let size = 0;
|
|
55
|
+
for (;;) {
|
|
56
|
+
const chunk = Buffer.alloc(Math.min(65536, MAX + 1 - size));
|
|
57
|
+
const { bytesRead } = await handle.read(chunk, 0, chunk.length, null);
|
|
58
|
+
if (!bytesRead) break;
|
|
59
|
+
size += bytesRead;
|
|
60
|
+
if (size > MAX) throw Object.assign(new Error('File exceeds 8 MiB operation limit'), {code:'EFBIG'});
|
|
61
|
+
chunks.push(chunk.subarray(0, bytesRead));
|
|
62
|
+
}
|
|
63
|
+
data = Buffer.concat(chunks, size).toString('base64');
|
|
64
|
+
}
|
|
65
|
+
} finally { await handle.close(); }
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case 'access-read': await fs.access(path, constants.R_OK); break;
|
|
69
|
+
case 'access-edit': await fs.access(path, constants.R_OK | constants.W_OK); break;
|
|
70
|
+
case 'existing-directory':
|
|
71
|
+
if (!(await fs.stat(path)).isDirectory()) throw new Error('Not an existing directory');
|
|
72
|
+
break;
|
|
73
|
+
case 'mkdir': await fs.mkdir(path, {recursive:true}); break;
|
|
74
|
+
case 'write':
|
|
75
|
+
if (typeof content !== 'string' || Buffer.byteLength(content, 'utf8') > MAX)
|
|
76
|
+
throw Object.assign(new Error('File exceeds 8 MiB operation limit'), {code:'EFBIG'});
|
|
77
|
+
await fs.writeFile(path, content, 'utf8'); break;
|
|
78
|
+
case 'unlink':
|
|
79
|
+
if ((await fs.lstat(path)).isDirectory()) throw Object.assign(new Error('Refusing to remove a directory'), {code:'EISDIR'});
|
|
80
|
+
await fs.unlink(path); break;
|
|
81
|
+
default: throw new Error('Unknown file operation');
|
|
82
|
+
}
|
|
83
|
+
process.stdout.write(JSON.stringify({ok:true, data}));
|
|
84
|
+
} catch (error) {
|
|
85
|
+
process.stdout.write(JSON.stringify({error: String(error.message || error), code: error.code}));
|
|
86
|
+
process.exitCode = 1;
|
|
87
|
+
}
|
|
88
|
+
});`;
|
|
89
|
+
|
|
90
|
+
type Operation = "read" | "mime" | "access-read" | "access-edit" | "mkdir" | "existing-directory" | "write" | "unlink";
|
|
91
|
+
|
|
92
|
+
/** Guarded removal of one file (never a directory). Follows the same launch policy as writes. */
|
|
93
|
+
export interface TaskRemoveOperations {
|
|
94
|
+
remove(path: string): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Policy pre-checks with no I/O, so a multi-file tool can validate a whole
|
|
99
|
+
* request before changing anything. Each throws the same refusal the operation
|
|
100
|
+
* itself would; unconfined plans allow everything.
|
|
101
|
+
*/
|
|
102
|
+
export interface TaskAccessChecks {
|
|
103
|
+
write(path: string): void;
|
|
104
|
+
remove(path: string): void;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function refusal(verb: string, decision: WriteAccessDecision): Error {
|
|
108
|
+
const detail = !decision.allowed && decision.deniedBy ? ` (protected by ${decision.deniedBy})` : "";
|
|
109
|
+
return new Error(`Task sandbox refused to ${verb} ${decision.path}: ${decision.allowed ? "" : decision.reason}${detail}.`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Removing an entry is judged on both its resolved target and its own directory
|
|
114
|
+
* entry, so a link can neither remove a protected file nor hide a protected entry.
|
|
115
|
+
* The entry is evaluated without following its final component: the parent is
|
|
116
|
+
* canonicalized, the leaf is taken literally. Otherwise a link planted in
|
|
117
|
+
* `~/.ssh` or a sibling repository would be judged by its (deletable) target.
|
|
118
|
+
*/
|
|
119
|
+
export function removeDecision(path: string, policy: CompiledSandboxWritePolicy): WriteAccessDecision {
|
|
120
|
+
const target = evaluateDeleteAccess(path, policy);
|
|
121
|
+
if (!target.allowed) return target;
|
|
122
|
+
const entry = join(canonicalizePath(dirname(path)), basename(path));
|
|
123
|
+
if (entry === target.path) return target;
|
|
124
|
+
const literalLeaf: SandboxSeams = {
|
|
125
|
+
canonicalize: (candidate) => {
|
|
126
|
+
if (candidate === entry) throw new Error("the leaf entry is judged literally");
|
|
127
|
+
return realpathSync.native(candidate);
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
return evaluateDeleteAccess(entry, policy, literalLeaf);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function mimeType(data: Buffer): string | null {
|
|
134
|
+
const ascii = (at: number, text: string) => data.toString("ascii", at, at + text.length) === text;
|
|
135
|
+
if (data.length >= 4 && data[0] === 0xff && data[1] === 0xd8 && data[2] === 0xff) {
|
|
136
|
+
return data[3] === 0xf7 ? null : "image/jpeg";
|
|
137
|
+
}
|
|
138
|
+
if (data.length >= 16 && data.subarray(0, 8).equals(Buffer.from("89504e470d0a1a0a", "hex")) &&
|
|
139
|
+
data.readUInt32BE(8) === 13 && ascii(12, "IHDR")) {
|
|
140
|
+
for (let offset = 8; offset + 8 <= data.length;) {
|
|
141
|
+
if (ascii(offset + 4, "acTL")) return null;
|
|
142
|
+
if (ascii(offset + 4, "IDAT")) break;
|
|
143
|
+
const next = offset + 12 + data.readUInt32BE(offset);
|
|
144
|
+
if (next <= offset || next > data.length) break;
|
|
145
|
+
offset = next;
|
|
146
|
+
}
|
|
147
|
+
return "image/png";
|
|
148
|
+
}
|
|
149
|
+
if (ascii(0, "GIF87a") || ascii(0, "GIF89a")) return "image/gif";
|
|
150
|
+
if (ascii(0, "RIFF") && ascii(8, "WEBP")) return "image/webp";
|
|
151
|
+
if (ascii(0, "BM") && data.length >= 30) {
|
|
152
|
+
const size = data.readUInt32LE(2);
|
|
153
|
+
const offset = data.readUInt32LE(10);
|
|
154
|
+
const dib = data.readUInt32LE(14);
|
|
155
|
+
const planes = dib === 12 ? data.readUInt16LE(22) : data.readUInt16LE(26);
|
|
156
|
+
const bits = dib === 12 ? data.readUInt16LE(24) : data.readUInt16LE(28);
|
|
157
|
+
if ((size === 0 || size >= 26) && offset >= 14 + dib && (size === 0 || offset < size) &&
|
|
158
|
+
(dib === 12 || (dib >= 40 && dib <= 124)) && planes === 1 && [1, 4, 8, 16, 24, 32].includes(bits)) {
|
|
159
|
+
return "image/bmp";
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function createTaskFileOperations(controller: TaskFileController, diagnostics?: Pick<SandboxDiagnostics, "observe">, toolOverride?: string): {
|
|
166
|
+
read: ReadOperations; write: WriteOperations; edit: EditOperations; remove: TaskRemoveOperations; check: TaskAccessChecks;
|
|
167
|
+
} {
|
|
168
|
+
function resource(path: string, policy: CompiledSandboxWritePolicy): DiagnosticResource {
|
|
169
|
+
path = canonicalizePath(path);
|
|
170
|
+
const inside = (root: string) => path === root || path.startsWith(root.endsWith("/") ? root : `${root}/`);
|
|
171
|
+
if (policy.credentialPaths?.some(inside)) return "credential-files";
|
|
172
|
+
return inside(policy.writableRoot) ? "project-files" : "outside-project-files";
|
|
173
|
+
}
|
|
174
|
+
const observe = (tool: string, operation: Operation | "remove", path: string, policy: CompiledSandboxWritePolicy,
|
|
175
|
+
basis: "policy-refusal" | "os-permission-error", outcome: "denied" | "succeeded") =>
|
|
176
|
+
{ try { diagnostics?.observe({ tool, operation: { operation, path }, resource: resource(path, policy), basis, outcome }); }
|
|
177
|
+
catch { /* Diagnostics must never change the operation's outcome. */ } };
|
|
178
|
+
|
|
179
|
+
async function run(operation: Operation, path: string, content?: string, tool = "read"): Promise<Buffer | void> {
|
|
180
|
+
tool = toolOverride ?? tool;
|
|
181
|
+
const result = await perform(operation, path, content, tool);
|
|
182
|
+
try { diagnostics?.observe({ tool, operation: { operation, path }, resource: "unknown",
|
|
183
|
+
basis: "os-permission-error", outcome: "succeeded" }); } catch { /* Observation is nonfatal. */ }
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async function perform(operation: Operation, path: string, content?: string, tool = "read"): Promise<Buffer | void> {
|
|
188
|
+
const plan = controller.requireLaunchPlan();
|
|
189
|
+
if (!plan.confined) {
|
|
190
|
+
switch (operation) {
|
|
191
|
+
case "read": return readFile(path);
|
|
192
|
+
case "mime": {
|
|
193
|
+
const handle = await open(path, "r");
|
|
194
|
+
try {
|
|
195
|
+
const sample = Buffer.alloc(4100);
|
|
196
|
+
const { bytesRead } = await handle.read(sample, 0, sample.length, 0);
|
|
197
|
+
return sample.subarray(0, bytesRead);
|
|
198
|
+
} finally { await handle.close(); }
|
|
199
|
+
}
|
|
200
|
+
case "access-read": return access(path, constants.R_OK);
|
|
201
|
+
case "access-edit": return access(path, constants.R_OK | constants.W_OK);
|
|
202
|
+
case "existing-directory":
|
|
203
|
+
if (!(await stat(path)).isDirectory()) throw new Error("Not an existing directory");
|
|
204
|
+
return;
|
|
205
|
+
case "mkdir": await mkdir(path, { recursive: true }); return;
|
|
206
|
+
case "write": return writeFile(path, content!, "utf8");
|
|
207
|
+
case "unlink":
|
|
208
|
+
if ((await lstat(path)).isDirectory()) throw Object.assign(new Error("Refusing to remove a directory"), { code: "EISDIR" });
|
|
209
|
+
return unlink(path);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const policy = compileWritePolicy(plan.policy);
|
|
214
|
+
if (operation === "unlink") {
|
|
215
|
+
const decision = removeDecision(path, policy);
|
|
216
|
+
if (!decision.allowed) {
|
|
217
|
+
observe(tool, operation, path, policy, "policy-refusal", "denied");
|
|
218
|
+
throw refusal("remove", decision);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const writing = operation === "write" || operation === "mkdir" || operation === "access-edit" || operation === "unlink";
|
|
222
|
+
const decision = writing ? evaluateWriteAccess(path, policy) : evaluateReadAccess(path, policy);
|
|
223
|
+
if (!decision.allowed && operation !== "existing-directory") {
|
|
224
|
+
if (operation === "mkdir" && decision.reason === "permission-denied") {
|
|
225
|
+
// SDK write prepares the parent even when it already exists.
|
|
226
|
+
// Confirm that no-op inside confinement; never grant mkdir.
|
|
227
|
+
try { await run("existing-directory", path, undefined, tool); return; } catch { /* Preserve the original refusal. */ }
|
|
228
|
+
}
|
|
229
|
+
const detail = "deniedBy" in decision ? ` (protected by ${decision.deniedBy})` : "";
|
|
230
|
+
observe(tool, operation, path, policy, "policy-refusal", "denied");
|
|
231
|
+
throw new Error(`Task sandbox refused to ${writing ? "write" : "read"} ${decision.path}: ${decision.reason}${detail}.`);
|
|
232
|
+
}
|
|
233
|
+
if (operation === "access-edit") {
|
|
234
|
+
const readable = evaluateReadAccess(path, policy);
|
|
235
|
+
if (!readable.allowed) {
|
|
236
|
+
observe(tool, operation, path, policy, "policy-refusal", "denied");
|
|
237
|
+
throw new Error(`Task sandbox refused to read ${readable.path}: ${readable.reason}.`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (content !== undefined && Buffer.byteLength(content, "utf8") > MAX_FILE_BYTES) {
|
|
241
|
+
throw new Error("File exceeds 8 MiB operation limit");
|
|
242
|
+
}
|
|
243
|
+
const payload = Buffer.from(JSON.stringify({ operation, path, content }), "utf8");
|
|
244
|
+
if (payload.length > MAX_REQUEST_BYTES) throw new Error("File operation request exceeds 12 MiB");
|
|
245
|
+
|
|
246
|
+
// Internal helper privilege only: never alter file/credential rules.
|
|
247
|
+
const helperPolicy: SandboxWritePolicy = {
|
|
248
|
+
...plan.policy,
|
|
249
|
+
permissions: {
|
|
250
|
+
projectFiles: "read-write", outsideProject: "read", storedCredentials: "read",
|
|
251
|
+
...plan.policy.permissions,
|
|
252
|
+
commands: true, network: false,
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
const profilePath = `${plan.profilePath}.${randomUUID()}.files.sb`;
|
|
256
|
+
let command;
|
|
257
|
+
try {
|
|
258
|
+
command = maybeBuildSandboxCommand({
|
|
259
|
+
execPath: canonicalizePath(process.execPath), execArgs: ["-e", FILE_WORKER], internalHelperExecutable: true,
|
|
260
|
+
profilePath, policy: helperPolicy,
|
|
261
|
+
}, { sandboxEnabled: true, explicitSandbox: true });
|
|
262
|
+
} catch (error) {
|
|
263
|
+
void unlink(profilePath).catch(() => {});
|
|
264
|
+
throw error;
|
|
265
|
+
}
|
|
266
|
+
if (!command) throw new Error("Task file sandbox backend unavailable");
|
|
267
|
+
|
|
268
|
+
return new Promise<Buffer | void>((resolve, reject) => {
|
|
269
|
+
const child = spawn(command.file, command.fileArgs, {
|
|
270
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
271
|
+
env: { PATH: process.env.PATH ?? "", HOME: plan.policy.home },
|
|
272
|
+
});
|
|
273
|
+
const chunks: Buffer[] = [];
|
|
274
|
+
let size = 0;
|
|
275
|
+
let stderr = "";
|
|
276
|
+
let finished = false;
|
|
277
|
+
const timer = setTimeout(() => child.kill(), 30_000);
|
|
278
|
+
child.stdout.on("data", (chunk: Buffer) => {
|
|
279
|
+
size += chunk.length;
|
|
280
|
+
if (size > MAX_RESPONSE_BYTES) child.kill();
|
|
281
|
+
else chunks.push(chunk);
|
|
282
|
+
});
|
|
283
|
+
child.stderr.on("data", (chunk: Buffer) => { stderr = (stderr + chunk.toString()).slice(-2048); });
|
|
284
|
+
child.stdin.on("error", () => {}); // An early sandbox failure may close stdin.
|
|
285
|
+
child.on("error", (error) => {
|
|
286
|
+
if (["EACCES", "EPERM"].includes((error as NodeJS.ErrnoException).code ?? "")) {
|
|
287
|
+
observe(tool, operation, path, policy, "os-permission-error", "denied");
|
|
288
|
+
}
|
|
289
|
+
if (!finished) { finished = true; clearTimeout(timer); void unlink(profilePath).catch(() => {}); reject(error); }
|
|
290
|
+
});
|
|
291
|
+
child.on("close", (code) => {
|
|
292
|
+
void unlink(profilePath).catch(() => {});
|
|
293
|
+
if (finished) return;
|
|
294
|
+
finished = true;
|
|
295
|
+
clearTimeout(timer);
|
|
296
|
+
if (size > MAX_RESPONSE_BYTES) return reject(new Error("File operation response exceeds 12 MiB"));
|
|
297
|
+
let result: { ok?: boolean; data?: string; error?: string; code?: string };
|
|
298
|
+
try { result = JSON.parse(Buffer.concat(chunks).toString("utf8")); }
|
|
299
|
+
catch { return reject(new Error(`Task file sandbox failed (${code}): ${stderr || "no worker response"}`)); }
|
|
300
|
+
if (!result.ok) {
|
|
301
|
+
const error = new Error(result.error ?? `Task file sandbox failed (${code})`) as NodeJS.ErrnoException;
|
|
302
|
+
error.code = result.code;
|
|
303
|
+
if (["EACCES", "EPERM"].includes(result.code ?? "")) observe(tool, operation, path, policy, "os-permission-error", "denied");
|
|
304
|
+
return reject(error);
|
|
305
|
+
}
|
|
306
|
+
if (code !== 0) return reject(new Error(`Task file sandbox exited ${code}: ${stderr}`));
|
|
307
|
+
resolve(result.data === undefined ? undefined : Buffer.from(result.data, "base64"));
|
|
308
|
+
});
|
|
309
|
+
child.stdin.end(payload);
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const check = (verb: "write" | "remove") => (path: string) => {
|
|
314
|
+
const plan = controller.requireLaunchPlan();
|
|
315
|
+
if (!plan.confined) return;
|
|
316
|
+
const policy = compileWritePolicy(plan.policy);
|
|
317
|
+
const decision = verb === "write" ? evaluateWriteAccess(path, policy) : removeDecision(path, policy);
|
|
318
|
+
if (!decision.allowed) {
|
|
319
|
+
observe("apply_patch", verb === "remove" ? "unlink" : "write", path, policy, "policy-refusal", "denied");
|
|
320
|
+
throw refusal(verb, decision);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
return {
|
|
325
|
+
remove: { remove: (path) => run("unlink", path, undefined, "apply_patch") as Promise<void> },
|
|
326
|
+
check: { write: check("write"), remove: check("remove") },
|
|
327
|
+
read: {
|
|
328
|
+
readFile: (path) => run("read", path) as Promise<Buffer>,
|
|
329
|
+
access: (path) => run("access-read", path) as Promise<void>,
|
|
330
|
+
detectImageMimeType: async (path) => mimeType(await run("mime", path) as Buffer),
|
|
331
|
+
},
|
|
332
|
+
write: {
|
|
333
|
+
mkdir: (path) => run("mkdir", path, undefined, "write") as Promise<void>,
|
|
334
|
+
writeFile: (path, content) => run("write", path, content, "write") as Promise<void>,
|
|
335
|
+
},
|
|
336
|
+
edit: {
|
|
337
|
+
readFile: (path) => run("read", path, undefined, "edit") as Promise<Buffer>,
|
|
338
|
+
access: (path) => run("access-edit", path, undefined, "edit") as Promise<void>,
|
|
339
|
+
writeFile: (path, content) => run("write", path, content, "edit") as Promise<void>,
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-sandbox/shared-task-process-identity.ts. Do not edit directly.
|
|
2
|
+
// Generated from packages/task-sandbox/process-identity.ts. Do not edit directly.
|
|
3
|
+
/** Darwin-only, fixed ps identity compatibility for confined task descendants. */
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { chmod, lstat, mkdtemp, readFile, realpath, rm, writeFile } from "node:fs/promises";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { compileWritePolicy } from "./shared-sandbox-core.domain.mjs";
|
|
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
|
+
const helpers = new Map();
|
|
51
|
+
const digest = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
52
|
+
// The trusted host compiles fixed source, with fixed argv and a minimal env.
|
|
53
|
+
// The resulting helper, not the compiler, runs as the task under Seatbelt.
|
|
54
|
+
async function compile(source, output) {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
const child = spawn("/usr/bin/clang", ["-Wall", "-Wextra", "-Werror", "-O2", source, "-o", output], {
|
|
57
|
+
detached: true, shell: false, stdio: ["ignore", "pipe", "pipe"],
|
|
58
|
+
env: { PATH: "/usr/bin:/bin", HOME: "/var/empty", LC_ALL: "C" },
|
|
59
|
+
});
|
|
60
|
+
let failure;
|
|
61
|
+
let size = 0;
|
|
62
|
+
const stop = (error) => {
|
|
63
|
+
if (failure)
|
|
64
|
+
return;
|
|
65
|
+
failure = error;
|
|
66
|
+
if (child.pid)
|
|
67
|
+
try {
|
|
68
|
+
process.kill(-child.pid, "SIGKILL");
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
child.kill("SIGKILL");
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const timer = setTimeout(() => stop(new Error("Process identity compiler timed out")), 15000);
|
|
75
|
+
for (const pipe of [child.stdout, child.stderr])
|
|
76
|
+
pipe.on("data", (chunk) => {
|
|
77
|
+
size += chunk.length;
|
|
78
|
+
if (size > 65536)
|
|
79
|
+
stop(new Error("Process identity compiler output exceeded limit"));
|
|
80
|
+
});
|
|
81
|
+
child.on("error", error => { failure ??= error; });
|
|
82
|
+
child.on("close", code => {
|
|
83
|
+
clearTimeout(timer);
|
|
84
|
+
if (failure || code !== 0)
|
|
85
|
+
reject(failure ?? new Error("Process identity compiler failed"));
|
|
86
|
+
else
|
|
87
|
+
resolve();
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
async function build(parent) {
|
|
92
|
+
const directory = await mkdtemp(join(parent, "process-identity-"));
|
|
93
|
+
const source = join(directory, "identity.c"), binary = join(directory, "ps");
|
|
94
|
+
try {
|
|
95
|
+
await writeFile(source, SOURCE, { mode: 0o600, flag: "wx" });
|
|
96
|
+
try {
|
|
97
|
+
await compile(source, binary);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// Preserve all other commands when the optional compiler is absent.
|
|
101
|
+
// Identity requests still fail explicitly, never via a broader ps.
|
|
102
|
+
await rm(binary, { force: true });
|
|
103
|
+
await writeFile(binary, UNAVAILABLE, { mode: 0o700, flag: "wx" });
|
|
104
|
+
}
|
|
105
|
+
await chmod(binary, 0o700);
|
|
106
|
+
return { directory, digest: digest(await readFile(binary)) };
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
await rm(directory, { recursive: true, force: true });
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
await rm(source, { force: true });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export async function processIdentityDirectory(plan) {
|
|
117
|
+
if (process.platform !== "darwin" || plan.policy.permissions?.processAccess !== "read")
|
|
118
|
+
return undefined;
|
|
119
|
+
const parent = await realpath(dirname(plan.profilePath));
|
|
120
|
+
// The controller's control directory must be protected even with broad writes.
|
|
121
|
+
const policy = compileWritePolicy(plan.policy);
|
|
122
|
+
if (!policy.denyWrite.some(root => parent === root || parent.startsWith(`${root}/`))) {
|
|
123
|
+
throw new Error("Sandbox process identity requires a task-write-protected control directory.");
|
|
124
|
+
}
|
|
125
|
+
let pending = helpers.get(parent);
|
|
126
|
+
if (!pending) {
|
|
127
|
+
pending = build(parent);
|
|
128
|
+
helpers.set(parent, pending);
|
|
129
|
+
void pending.catch(() => { if (helpers.get(parent) === pending)
|
|
130
|
+
helpers.delete(parent); });
|
|
131
|
+
}
|
|
132
|
+
const helper = await pending;
|
|
133
|
+
const binary = join(helper.directory, "ps");
|
|
134
|
+
const info = await lstat(binary);
|
|
135
|
+
if (!info.isFile() || info.uid !== process.getuid() || (info.mode & 0o7777) !== 0o700 ||
|
|
136
|
+
await realpath(helper.directory) !== helper.directory || digest(await readFile(binary)) !== helper.digest) {
|
|
137
|
+
throw new Error("Sandbox process identity helper changed; restart the session.");
|
|
138
|
+
}
|
|
139
|
+
return helper.directory;
|
|
140
|
+
}
|
|
@@ -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
|
+
}
|