pi-web-ui 0.116.0 → 0.118.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/CHANGELOG.md +83 -3
- package/README.md +69 -138
- package/README.zh-CN.md +70 -179
- package/README.zh-TW.md +3 -1
- package/bin/device-hub-cli.mjs +163 -36
- package/bin/frp-manager.mjs +4 -80
- package/bin/hub-upgrade.mjs +561 -0
- package/bin/pi-device-hub.mjs +0 -1
- package/bin/pi-web-ui.mjs +184 -504
- package/deploy/nginx-subpath.conf +0 -33
- package/deploy/pi-web-ui.service +0 -20
- package/dist/server/agent-formatters.js +4 -38
- package/dist/server/agent-service-daemon.js +203 -371
- package/dist/server/agent-service.js +1281 -3030
- package/dist/server/approval-audit.js +2 -23
- package/dist/server/approval-default-rules.js +0 -6
- package/dist/server/approval-rules.js +7 -105
- package/dist/server/ask-user-question-tool.js +1 -12
- package/dist/server/atomic-file.js +33 -5
- package/dist/server/attachment-store.js +0 -36
- package/dist/server/attachments.js +3 -112
- package/dist/server/auth-cookie.js +0 -21
- package/dist/server/bash-tool.js +1 -32
- package/dist/server/bg-servers.js +0 -96
- package/dist/server/browser-page-tool.js +11 -62
- package/dist/server/builtin-modules.js +7 -0
- package/dist/server/canvas/canvas-agent-tool.js +58 -47
- package/dist/server/canvas/canvas-cards.js +0 -14
- package/dist/server/canvas/canvas-dispatch.js +7 -4
- package/dist/server/canvas/canvas-orchestrator.js +167 -181
- package/dist/server/canvas/canvas-runtime-messages.js +30 -0
- package/dist/server/canvas/canvas-scheduled-task.js +0 -3
- package/dist/server/canvas/canvas-scheduler.js +5 -7
- package/dist/server/canvas/canvas-store.js +24 -35
- package/dist/server/canvas/canvas-validation.js +17 -14
- package/dist/server/canvas/canvas-workspace.js +42 -114
- package/dist/server/canvas/pstack-skills-data.js +0 -5
- package/dist/server/claim-files-tool.js +1 -15
- package/dist/server/claim-store.js +5 -49
- package/dist/server/client-id-utils.js +0 -16
- package/dist/server/client-state.js +36 -214
- package/dist/server/communicate-tool.js +0 -3
- package/dist/server/compact-context-tool.js +0 -30
- package/dist/server/compacted-history.js +0 -35
- package/dist/server/compaction-instructions.js +0 -13
- package/dist/server/compaction-markers.js +38 -92
- package/dist/server/compaction-state.js +0 -21
- package/dist/server/composer-drafts.js +0 -34
- package/dist/server/context-budget-runner.js +0 -11
- package/dist/server/context-budget.js +1 -70
- package/dist/server/context-evidence.js +0 -14
- package/dist/server/context-usage.js +0 -12
- package/dist/server/control-socket.js +4 -48
- package/dist/server/conversation-communication.js +0 -10
- package/dist/server/conversation-identity.js +0 -1
- package/dist/server/conversation-read-tool.js +0 -58
- package/dist/server/conversation-tool-names.js +0 -1
- package/dist/server/conversation-tool.js +0 -1
- package/dist/server/conversation-touches.js +4 -75
- package/dist/server/dangling-tools.js +142 -68
- package/dist/server/delegate-mode.js +0 -36
- package/dist/server/delegate-task.js +2 -28
- package/dist/server/device-center/approval-summary.js +0 -1
- package/dist/server/device-center/bot-catalog.js +0 -3
- package/dist/server/device-center/bot-execution.js +48 -9
- package/dist/server/device-center/bot-presets.js +0 -1
- package/dist/server/device-center/bots.js +0 -1
- package/dist/server/device-center/collab-service.js +27 -11
- package/dist/server/device-center/collab-tool.js +393 -27
- package/dist/server/device-center/connector.js +128 -48
- package/dist/server/device-center/delivery-authority.js +95 -0
- package/dist/server/device-center/delivery-subject.js +29 -0
- package/dist/server/device-center/desktop-linux.js +3 -15
- package/dist/server/device-center/desktop-native.js +1 -10
- package/dist/server/device-center/desktop-page.js +2 -3
- package/dist/server/device-center/desktop-setup.js +1 -3
- package/dist/server/device-center/desktop.js +1 -7
- package/dist/server/device-center/device-integration.js +452 -208
- package/dist/server/device-center/device-lan-access.js +403 -0
- package/dist/server/device-center/device-lan.js +484 -0
- package/dist/server/device-center/device-portals.js +0 -3
- package/dist/server/device-center/execution-failure.js +0 -2
- package/dist/server/device-center/execution-guides.js +15 -6
- package/dist/server/device-center/execution-instructions.js +0 -1
- package/dist/server/device-center/execution-settings.js +0 -1
- package/dist/server/device-center/execution-system-prompt.js +0 -3
- package/dist/server/device-center/execution-workspace.js +1 -4
- package/dist/server/device-center/executor.js +46 -31
- package/dist/server/device-center/file-sync-paths.js +0 -5
- package/dist/server/device-center/file-sync.js +0 -10
- package/dist/server/device-center/group-context-delta.js +0 -8
- package/dist/server/device-center/group-context-message.js +0 -14
- package/dist/server/device-center/group-context.js +0 -19
- package/dist/server/device-center/group-events.js +0 -2
- package/dist/server/device-center/group-plan-guard.js +1 -35
- package/dist/server/device-center/group-router-runtime.js +182 -0
- package/dist/server/device-center/group-router-worker.js +178 -0
- package/dist/server/device-center/group-router.js +359 -0
- package/dist/server/device-center/hub-auth.js +24 -2
- package/dist/server/device-center/hub-conversations.js +13 -15
- package/dist/server/device-center/hub-deliveries.js +119 -15
- package/dist/server/device-center/hub-integration.js +647 -334
- package/dist/server/device-center/hub-locks.js +1 -5
- package/dist/server/device-center/hub-mobile.js +147 -0
- package/dist/server/device-center/hub-orchestration.js +400 -0
- package/dist/server/device-center/hub-page.js +28 -9
- package/dist/server/device-center/hub-setup.js +23 -7
- package/dist/server/device-center/hub-transaction-log.js +175 -0
- package/dist/server/device-center/hub-upgrade.js +162 -0
- package/dist/server/device-center/hub-webhooks.js +1 -3
- package/dist/server/device-center/hub.js +946 -404
- package/dist/server/device-center/human-interaction.js +1 -4
- package/dist/server/device-center/integration-errors.js +0 -2
- package/dist/server/device-center/integration-verification.js +111 -0
- package/dist/server/device-center/local-hub.js +6 -4
- package/dist/server/device-center/local-publication.js +416 -0
- package/dist/server/device-center/local-verification-job.js +95 -0
- package/dist/server/device-center/local-verification.js +273 -0
- package/dist/server/device-center/local.js +341 -18
- package/dist/server/device-center/main.js +18 -2
- package/dist/server/device-center/mobile-notification-forwarder.js +292 -0
- package/dist/server/device-center/native-desktop/macos.js +0 -1
- package/dist/server/device-center/native-desktop/windows.js +0 -1
- package/dist/server/device-center/partition-log.js +52 -46
- package/dist/server/device-center/path-portal.js +42 -12
- package/dist/server/device-center/publication-journal.js +305 -0
- package/dist/server/device-center/publish-intent.js +374 -0
- package/dist/server/device-center/relay.js +217 -52
- package/dist/server/device-center/report-upload.js +0 -1
- package/dist/server/device-center/runtime.js +419 -52
- package/dist/server/device-center/store.js +223 -65
- package/dist/server/device-center/task-context-budget.js +0 -3
- package/dist/server/device-center/task-error.js +0 -1
- package/dist/server/device-center/task-journal.js +6 -23
- package/dist/server/device-center/task-outcome.js +68 -0
- package/dist/server/device-center/task-plan.js +0 -1
- package/dist/server/device-center/task-progress.js +0 -16
- package/dist/server/device-center/task-recovery.js +569 -227
- package/dist/server/device-center/task-report-outbox.js +0 -4
- package/dist/server/device-center/task-report.js +2 -10
- package/dist/server/device-center/task-scheduler.js +1 -35
- package/dist/server/device-center/task-settlement.js +335 -0
- package/dist/server/device-center/task-state.js +0 -12
- package/dist/server/device-center/task-workspace.js +393 -0
- package/dist/server/device-center/transfer-stream.js +5 -45
- package/dist/server/device-center/transfers.js +2 -10
- package/dist/server/device-center/verification-limits.js +9 -0
- package/dist/server/device-center/work-contract.js +923 -0
- package/dist/server/device-center/work-items.js +317 -0
- package/dist/server/device-center/workspaces.js +0 -1
- package/dist/server/dispatch-domain-handlers.js +202 -29
- package/dist/server/dispatch-plugin-handlers.js +2 -19
- package/dist/server/dsh/dsh-agent-service.js +78 -601
- package/dist/server/dsh/dsh-client.js +7 -111
- package/dist/server/dsh/dsh-market-service.js +4 -25
- package/dist/server/dsh/dsh-serialize.js +0 -49
- package/dist/server/dsh/dsh-sessions.js +0 -37
- package/dist/server/dsh/dsh-usage.js +0 -37
- package/dist/server/dsh/preset-clones.js +1 -65
- package/dist/server/dsh/runtime/custom-prompt.mjs +0 -14
- package/dist/server/dsh/runtime/goal-rpc.mjs +7 -176
- package/dist/server/dsh/runtime/launcher.mjs +2 -53
- package/dist/server/dsh/runtime/override.patch.yml +0 -29
- package/dist/server/dsh/runtime/runtime-root.mjs +0 -54
- package/dist/server/durable/durable-agent-service.js +5 -23
- package/dist/server/durable/durable-driver.js +12 -73
- package/dist/server/durable/durable-event-projector.js +1 -50
- package/dist/server/durable/durable-loader.js +0 -12
- package/dist/server/durable/durable-models.js +11 -80
- package/dist/server/durable/durable-storage.js +1 -17
- package/dist/server/durable/durable-tools.js +2 -20
- package/dist/server/durable/index.js +0 -3
- package/dist/server/edit-soft-tool.js +2 -81
- package/dist/server/engine-capabilities.js +0 -13
- package/dist/server/engine-catalog.js +74 -0
- package/dist/server/engine-cli.js +89 -0
- package/dist/server/engine-probe.js +35 -217
- package/dist/server/ensure-bash.js +2 -28
- package/dist/server/eval-tool.js +1 -50
- package/dist/server/evidence-tool-hooks.js +0 -2
- package/dist/server/file-archives.js +0 -10
- package/dist/server/file-save.js +1 -12
- package/dist/server/file-transfer-routes.js +0 -11
- package/dist/server/files-service.js +18 -271
- package/dist/server/global-loader.js +9 -89
- package/dist/server/goal-evidence.js +1 -35
- package/dist/server/goal-review-gate.js +0 -58
- package/dist/server/goal-service.js +19 -422
- package/dist/server/hashline-engine.js +8 -112
- package/dist/server/host-guard.js +0 -24
- package/dist/server/host-metrics.js +0 -6
- package/dist/server/http-proxy.js +1 -7
- package/dist/server/i18n.js +5 -72
- package/dist/server/icon-svg.js +0 -15
- package/dist/server/index.js +199 -677
- package/dist/server/json-utils.js +0 -12
- package/dist/server/launch-origin.js +0 -44
- package/dist/server/left-panel-running.js +0 -9
- package/dist/server/load-timing.js +1 -4
- package/dist/server/load-tools-tool.js +0 -20
- package/dist/server/locales.js +1 -46
- package/dist/server/lsp-tool.js +13 -126
- package/dist/server/managed.js +0 -48
- package/dist/server/marker-service.js +1 -22
- package/dist/server/markers/builtins/action.js +0 -19
- package/dist/server/markers/builtins/notify.js +1 -9
- package/dist/server/markers/builtins/rename.js +0 -13
- package/dist/server/markers/index.js +0 -3
- package/dist/server/markers/marker.js +0 -13
- package/dist/server/markers/registry.js +0 -3
- package/dist/server/markers/store.js +1 -12
- package/dist/server/market-service.js +7 -43
- package/dist/server/mcp-agent-tool.js +0 -10
- package/dist/server/mcp-bridge.js +6 -138
- package/dist/server/mcp-hot-reload.js +0 -25
- package/dist/server/mcp-manager.js +2 -44
- package/dist/server/mcp-oauth-login.js +0 -2
- package/dist/server/mcp-oauth-ui.js +1 -4
- package/dist/server/mcp-oauth.js +5 -79
- package/dist/server/mcp-project-runtime.js +0 -4
- package/dist/server/message-deletion.js +0 -2
- package/dist/server/message-entry-resolver.js +0 -8
- package/dist/server/message-window.js +0 -71
- package/dist/server/mobile-notification-events.js +16 -0
- package/dist/server/mobile-origin.js +79 -0
- package/dist/server/mobile-push.js +523 -0
- package/dist/server/model-admin.js +19 -358
- package/dist/server/model-enrich.js +0 -19
- package/dist/server/model-resolver.js +2 -61
- package/dist/server/native-cli-discovery.js +115 -0
- package/dist/server/native-cli-model.js +71 -0
- package/dist/server/native-cli-references.js +214 -0
- package/dist/server/native-cli-remote-cleanup.js +58 -0
- package/dist/server/native-cli-remote-files.js +282 -0
- package/dist/server/native-cli-routes.js +68 -0
- package/dist/server/native-cli-runtime.js +1 -0
- package/dist/server/native-cli-session-hooks.js +170 -0
- package/dist/server/native-cli-session.js +585 -0
- package/dist/server/native-cli-state.js +82 -0
- package/dist/server/native-cli.js +210 -0
- package/dist/server/net-guard.js +9 -71
- package/dist/server/office-parse.js +0 -50
- package/dist/server/orphan-manager.js +0 -18
- package/dist/server/patch-bash-process.js +0 -4
- package/dist/server/patch-executable-lookup.js +0 -77
- package/dist/server/patch-node-pty.js +6 -45
- package/dist/server/patch-remote-catalog.js +4 -34
- package/dist/server/patch-tool.js +0 -15
- package/dist/server/payload-limits.js +0 -5
- package/dist/server/pending-question.js +0 -5
- package/dist/server/permission-preset.js +4 -33
- package/dist/server/persona-chain.js +0 -26
- package/dist/server/pkg-info.js +1 -17
- package/dist/server/plan-manager.js +2 -49
- package/dist/server/plan-mode.js +0 -97
- package/dist/server/plan-update-tool.js +1 -15
- package/dist/server/plugin-api-catalog.js +6 -4
- package/dist/server/plugin-assets.js +1 -35
- package/dist/server/plugin-bundled.js +68 -0
- package/dist/server/plugin-catalog-sync.js +0 -37
- package/dist/server/plugin-catalog.js +13 -67
- package/dist/server/plugin-chat-attachments.js +0 -1
- package/dist/server/plugin-conversation-view.js +0 -20
- package/dist/server/plugin-dom.js +1 -23
- package/dist/server/plugin-facilities.js +4 -115
- package/dist/server/plugin-grants.js +2 -90
- package/dist/server/plugin-install-spec.js +0 -43
- package/dist/server/plugin-installer.js +34 -75
- package/dist/server/plugin-llm.js +4 -38
- package/dist/server/plugin-manifest-validate.js +0 -31
- package/dist/server/plugin-permissions.js +1 -24
- package/dist/server/plugin-project.js +7 -129
- package/dist/server/plugin-removal.js +1 -8
- package/dist/server/plugin-schedule.js +1 -38
- package/dist/server/plugin-secrets.js +3 -16
- package/dist/server/plugin-tool-guard.js +1 -28
- package/dist/server/plugin-ui-slots.js +0 -4
- package/dist/server/plugin-updater.js +15 -90
- package/dist/server/plugins.js +71 -619
- package/dist/server/present-files-tool.js +0 -57
- package/dist/server/preset-fields.js +24 -61
- package/dist/server/preset-plugin-dependencies.js +0 -2
- package/dist/server/preset-share.js +4 -172
- package/dist/server/process-utils.js +4 -80
- package/dist/server/prompt-assembler.js +2 -30
- package/dist/server/prompt-base-store.js +0 -47
- package/dist/server/prompt-composer.js +21 -98
- package/dist/server/prompt-templates.js +0 -2
- package/dist/server/protocol-version.js +1 -11
- package/dist/server/protocol.js +0 -5
- package/dist/server/queue-modes.js +0 -3
- package/dist/server/queue-utils.js +0 -40
- package/dist/server/quick-ask-context.js +384 -0
- package/dist/server/quick-ask-settings.js +61 -0
- package/dist/server/quick-ask.js +260 -0
- package/dist/server/read-tool.js +0 -65
- package/dist/server/reasoning-registry.js +1 -29
- package/dist/server/remote-cli-persistence.js +373 -0
- package/dist/server/remote-native-cli.js +78 -0
- package/dist/server/remote-ssh-service.js +481 -190
- package/dist/server/request-context.js +0 -9
- package/dist/server/resolve-global-sdk.js +55 -31
- package/dist/server/sandbox-data.js +0 -1
- package/dist/server/sandbox-engines.js +0 -1
- package/dist/server/sandbox-runtime-gate.js +0 -3
- package/dist/server/sandbox-service.js +0 -41
- package/dist/server/sandbox-tool.js +0 -20
- package/dist/server/schedule-agent-tool.js +2 -31
- package/dist/server/scheduler-tasks.js +32 -56
- package/dist/server/scm-commitmsg.js +0 -53
- package/dist/server/scm.js +3 -48
- package/dist/server/sdk-builtin-extensions.js +2 -29
- package/dist/server/sdk-origin.js +0 -45
- package/dist/server/serialize.js +2 -92
- package/dist/server/server-config.js +0 -11
- package/dist/server/session-branch.js +1 -87
- package/dist/server/session-list-scan.js +215 -0
- package/dist/server/session-open.js +69 -0
- package/dist/server/session-parser.js +4 -54
- package/dist/server/session-scan.js +81 -45
- package/dist/server/session-search.js +0 -56
- package/dist/server/settings-service.js +19 -126
- package/dist/server/setup-config.js +0 -2
- package/dist/server/setup-page.js +0 -9
- package/dist/server/skill-content-filler.js +0 -17
- package/dist/server/skill-discovery.js +5 -92
- package/dist/server/skill-maintenance.js +1 -28
- package/dist/server/skill-tool.js +0 -30
- package/dist/server/slash-commands.js +5 -50
- package/dist/server/soft-cap.js +3 -40
- package/dist/server/startup-banner.js +0 -8
- package/dist/server/subagent-handoff.js +0 -11
- package/dist/server/subagent-helpers.js +2 -17
- package/dist/server/subagent-notify.js +0 -19
- package/dist/server/subagent-security-gate.js +0 -50
- package/dist/server/subagent-task.js +0 -9
- package/dist/server/subagent-templates-hant.js +0 -10
- package/dist/server/subagent-templates.js +3 -103
- package/dist/server/subagents.js +1 -87
- package/dist/server/system-screenshot-windows.js +259 -0
- package/dist/server/system-screenshot.js +77 -0
- package/dist/server/tabs.js +3 -48
- package/dist/server/terminals.js +559 -586
- package/dist/server/text-quote.js +0 -12
- package/dist/server/text-sniff.js +2 -52
- package/dist/server/themes.js +2 -41
- package/dist/server/tool-approval.js +0 -47
- package/dist/server/tool-guards.js +0 -90
- package/dist/server/tool-host-factories.js +1 -16
- package/dist/server/tool-info.js +0 -13
- package/dist/server/tool-manager.js +1 -229
- package/dist/server/tool-overrides.js +1 -46
- package/dist/server/tool-prompt-overrides.js +1 -30
- package/dist/server/tool-prompts.js +0 -14
- package/dist/server/tool-signature.js +0 -25
- package/dist/server/transcript-prepare.js +55 -0
- package/dist/server/tts-routes.js +58 -0
- package/dist/server/tts-service.js +106 -0
- package/dist/server/tts-system.js +160 -0
- package/dist/server/turn-timing.js +0 -1
- package/dist/server/unauthorized-page.js +0 -8
- package/dist/server/universal/driver-base.js +2 -31
- package/dist/server/universal/drivers/claude-code.js +98 -194
- package/dist/server/universal/drivers/codex.js +12 -35
- package/dist/server/universal/drivers/mock-driver.js +1 -11
- package/dist/server/universal/index.js +0 -3
- package/dist/server/universal/session-store.js +4 -21
- package/dist/server/universal/universal-attachments.js +2 -36
- package/dist/server/universal/universal-service.js +5 -24
- package/dist/server/universal/universal-session.js +30 -148
- package/dist/server/universal/universal-types.js +0 -3
- package/dist/server/update-check.js +6 -182
- package/dist/server/uploads.js +4 -43
- package/dist/server/virtual-tui.js +2 -27
- package/dist/server/vision-bridge.js +0 -27
- package/dist/server/wait-subscription-scan.js +13 -115
- package/dist/server/webui-context.js +2 -87
- package/dist/server/workspace-handle.js +373 -0
- package/dist/server/workspace-snapshot.js +7 -113
- package/dist/server/worktree-service.js +2 -53
- package/dist/server/worktree-tool.js +0 -11
- package/dist/server/ws-client-id.js +0 -18
- package/dist/server/ws-pending-queue.js +0 -7
- package/dist/server/ws-unknown-types.js +0 -17
- package/docs/README.md +24 -17
- package/docs/architecture-plugins.md +55 -6
- package/docs/device-center.md +57 -23
- package/docs/device-desktop.md +3 -3
- package/docs/group-orchestration.md +142 -0
- package/docs/hub-upgrade-release-testing.md +46 -0
- package/extensions/webui.ts +3 -74
- package/package.json +9 -6
- package/plugin-sdk/README.md +22 -8
- package/plugin-sdk/client-utils.mjs +0 -7
- package/plugin-sdk/client.d.ts +26 -0
- package/plugin-sdk/client.mjs +52 -0
- package/plugin-sdk/import-check.mjs +4 -51
- package/plugin-sdk/index.d.ts +128 -117
- package/plugin-sdk/index.mjs +2 -687
- package/plugin-sdk/package.json +15 -4
- package/plugin-sdk/ssh-host-trust.mjs +0 -12
- package/plugin-sdk/testing.d.ts +9 -0
- package/plugin-sdk/testing.mjs +511 -0
- package/plugins/catalog.json +52 -4
- package/plugins/superagent/README.md +110 -0
- package/plugins/superagent/client/entry.mjs +21 -0
- package/plugins/superagent/index.mjs +8 -0
- package/plugins/superagent/main.mjs +218 -0
- package/plugins/superagent/manifest.json +15 -0
- package/plugins/superagent/server.mjs +572 -0
- package/plugins/superagent/style.css +167 -0
- package/themes/aetheris.css +1 -31
- package/themes/ayu-light.css +0 -1
- package/themes/bases/flow-base.css +2 -83
- package/themes/bases/obsidian-base.css +2 -37
- package/themes/bases/statusbar-flat-base.css +0 -1
- package/themes/bases/zhujian-base.css +0 -63
- package/themes/bases/zhupi-base.css +0 -64
- package/themes/catppuccin-latte.css +0 -1
- package/themes/catppuccin.css +0 -1
- package/themes/claude-code-dark.css +0 -1
- package/themes/codex.css +0 -1
- package/themes/dark-teal.css +22 -54
- package/themes/everforest-light.css +0 -1
- package/themes/flow-cristallo.css +160 -0
- package/themes/flow-ink.css +160 -0
- package/themes/flow-light.css +1 -10
- package/themes/flow-obsidian.css +160 -0
- package/themes/flow-zurich.css +160 -0
- package/themes/flow.css +1 -9
- package/themes/geist.css +0 -1
- package/themes/gruvbox-light.css +0 -1
- package/themes/kanagawa-lotus.css +0 -1
- package/themes/md-preview.css +1 -2
- package/themes/mist.css +0 -1
- package/themes/nord.css +0 -1
- package/themes/one-dark.css +0 -1
- package/themes/paper.css +0 -1
- package/themes/rose-pine-dawn.css +0 -1
- package/themes/sakura.css +0 -1
- package/themes/solarized-light.css +0 -1
- package/themes/tokyo-night.css +0 -1
- package/themes/translucent.css +4 -35
- package/themes/transparent.css +4 -41
- package/themes/vs-code-dark.css +0 -1
- package/themes/wallpaper-flow.css +3 -17
- package/themes/wallpaper-obsidian.css +1 -4
- package/themes/white.css +0 -1
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/{BgTasksModal-BDoOpj-F.js → BgTasksModal-D-x7kA63.js} +1 -1
- package/web/dist/assets/CanvasStudio-CAWcs9tm.js +1579 -0
- package/web/dist/assets/DeviceCenter-Dc0whRcu.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +1 -0
- package/web/dist/assets/DeviceGroups-C_fZMNeK.js +1 -0
- package/web/dist/assets/{Dropdown-C4LIhshN.js → Dropdown-CTgVLUbp.js} +1 -1
- package/web/dist/assets/FilePreview-C6W0PvaK.js +2 -0
- package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +1 -0
- package/web/dist/assets/GroupConversation-C81YjF2C.js +61 -0
- package/web/dist/assets/GroupWorkItems-BIvZtr10.js +1 -0
- package/web/dist/assets/{HintTip-c6d0TJoh.js → HintTip-Da6qc566.js} +1 -1
- package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +2 -0
- package/web/dist/assets/NativeCliPanel-CU1rZmyu.js +5 -0
- package/web/dist/assets/{PiSetupModal-BmMrrgB9.js → PiSetupModal-DZKY5Wiw.js} +1 -1
- package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +1 -0
- package/web/dist/assets/SCMPanel-CuEgzAlO.js +2 -0
- package/web/dist/assets/SettingsModal-Cdu5h29p.js +33 -0
- package/web/dist/assets/TermXterm-Bt5WKAxP.js +3 -0
- package/web/dist/assets/TerminalPanel-BCIBV8se.js +1 -0
- package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +1 -0
- package/web/dist/assets/app-globals-CZjFtI4F.js +129 -0
- package/web/dist/assets/canvas-client-WkhM55mR.js +1 -0
- package/web/dist/assets/composer-bridge-CImnjDHq.js +1 -0
- package/web/dist/assets/desktop-B8NZ3KW-.js +1 -0
- package/web/dist/assets/index-CQc3VrWa.css +1 -0
- package/web/dist/assets/index-D_AGu4Zv.js +404 -0
- package/web/dist/assets/plugin-host-uqZGpvCs.js +1 -0
- package/web/dist/assets/{remote-ssh-client-CfYSMEZg.js → remote-ssh-client-Cdf-cTUe.js} +1 -1
- package/web/dist/assets/theme-DGL7hLUs.js +1 -0
- package/web/dist/index.html +12 -11
- package/web/dist/sw.js +15 -61
- package/web/public/sw.js +14 -60
- package/dist/gh-comment-781.md +0 -5
- package/dist/server/device-center/local-page.js +0 -17
- package/dist/server/device-center/smoke-preview.js +0 -3
- package/dist/server/durable/durable-capabilities.js +0 -11
- package/dist/server/markers/builtins/services.js +0 -123
- package/dist/server/markers/builtins/todo.js +0 -189
- package/dist/server/markers-list-tool.js +0 -34
- package/dist/server/orchestrator.js +0 -109
- package/dist/server/patch-turn-end-boundary.js +0 -77
- package/dist/server/system-prompt-soul.js +0 -41
- package/dist/server/univer-service.js +0 -448
- package/dist/server/universal/drivers/dsh-driver.js +0 -379
- package/dist/test-artifact.md +0 -9
- package/dist/test-preview-modal.md +0 -11
- package/dist/test-report.html +0 -20
- package/web/dist/assets/BgTasksModal-C0i3O1FT.js +0 -1
- package/web/dist/assets/CanvasStudio-B8thymBN.js +0 -1579
- package/web/dist/assets/CanvasStudio-zSxyIx1R.js +0 -1579
- package/web/dist/assets/DeviceCenter-DfAHKcid.js +0 -3
- package/web/dist/assets/DeviceCenter-ydvOTlzE.js +0 -3
- package/web/dist/assets/DeviceExecutionSettings-q5Ik8oXg.js +0 -1
- package/web/dist/assets/DeviceGroups-CI14_SRb.js +0 -1
- package/web/dist/assets/DeviceGroups-DvsB5IEU.js +0 -1
- package/web/dist/assets/FilePreview-BgGongmv.js +0 -2
- package/web/dist/assets/FilePreview-D4NrhF-U.js +0 -2
- package/web/dist/assets/GlobalSearchModal-BWgU8yPd.js +0 -1
- package/web/dist/assets/GlobalSearchModal-F7fNimKk.js +0 -1
- package/web/dist/assets/GroupConversation-Dh71Pdb-.js +0 -17
- package/web/dist/assets/GroupConversation-ZK3nRmNm.js +0 -17
- package/web/dist/assets/ModelConfigModal-YVEgyy34.js +0 -2
- package/web/dist/assets/ModelConfigModal-vWtg3srp.js +0 -2
- package/web/dist/assets/ProviderOAuthControls-BGSBIKD7.js +0 -1
- package/web/dist/assets/SCMPanel-B8_EDxNr.js +0 -2
- package/web/dist/assets/SCMPanel-BU58qk3T.js +0 -2
- package/web/dist/assets/SettingsModal-CMUybq3J.js +0 -32
- package/web/dist/assets/SettingsModal-OBmGTh-5.js +0 -32
- package/web/dist/assets/TerminalPanel-0CYvD72B.js +0 -3
- package/web/dist/assets/TerminalPanel-DDavKvFr.js +0 -3
- package/web/dist/assets/TuiOverlayModal-BsA-QTvN.js +0 -1
- package/web/dist/assets/TuiOverlayModal-DzoVQBuG.js +0 -1
- package/web/dist/assets/app-globals-CZxzGvIo.js +0 -123
- package/web/dist/assets/canvas-client-CUnXlQYX.js +0 -1
- package/web/dist/assets/desktop-aAKpvKJV.js +0 -1
- package/web/dist/assets/index-C6DwztqE.css +0 -1
- package/web/dist/assets/index-CuN802Sj.js +0 -93
- package/web/dist/assets/index-EH5Fw9fa.js +0 -93
- package/web/dist/assets/plugin-host-BRWib9DF.js +0 -1
- package/web/dist/assets/theme-D2l_mLNo.js +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
/** Pure deterministic chunk extractor for long reports/journals; never silences or drops boundaries. */
|
|
3
2
|
export function queryTaskReportChunk(taskId, reportText, offset = 0, limit = 8192, options) {
|
|
4
3
|
if (!Number.isSafeInteger(offset) || offset < 0) {
|
|
5
4
|
throw new RangeError("Offset must be a nonnegative safe integer");
|
|
@@ -10,17 +9,14 @@ export function queryTaskReportChunk(taskId, reportText, offset = 0, limit = 819
|
|
|
10
9
|
const buf = Buffer.from(reportText, "utf8");
|
|
11
10
|
const totalBytes = buf.length;
|
|
12
11
|
let actualOffset = Math.min(offset, totalBytes);
|
|
13
|
-
// If actualOffset falls on a UTF-8 continuation byte, align backward to the code point start.
|
|
14
12
|
while (actualOffset > 0 && (buf[actualOffset] & 0xc0) === 0x80) {
|
|
15
13
|
actualOffset--;
|
|
16
14
|
}
|
|
17
15
|
const safeLimit = Math.max(1, Math.min(limit, 65536));
|
|
18
16
|
let end = Math.min(actualOffset + safeLimit, totalBytes);
|
|
19
|
-
// If end falls on a continuation byte, shrink backward to prevent exceeding safeLimit.
|
|
20
17
|
while (end > actualOffset && (buf[end] & 0xc0) === 0x80) {
|
|
21
18
|
end--;
|
|
22
19
|
}
|
|
23
|
-
// Fallback for single multi-byte code point exceeding safeLimit: advance to include it.
|
|
24
20
|
if (end === actualOffset && actualOffset < totalBytes) {
|
|
25
21
|
end++;
|
|
26
22
|
while (end < totalBytes && (buf[end] & 0xc0) === 0x80) {
|
|
@@ -55,7 +51,6 @@ export function queryTaskReportChunk(taskId, reportText, offset = 0, limit = 819
|
|
|
55
51
|
sha256,
|
|
56
52
|
};
|
|
57
53
|
}
|
|
58
|
-
/** Deterministic aggregation of task state without calling any external LLM summary. */
|
|
59
54
|
export function buildDeterministicTaskSummary(taskState, options) {
|
|
60
55
|
const constraints = [];
|
|
61
56
|
const maxBytes = options?.maxConstraintBytes ?? 2000;
|
|
@@ -149,14 +144,11 @@ const REFERENCE_LIMIT = 20;
|
|
|
149
144
|
const TEXT_LIMIT = 2048;
|
|
150
145
|
const bounded = (text) => text.slice(0, TEXT_LIMIT);
|
|
151
146
|
const terminal = (task) => ["completed", "failed", "interrupted"].includes(task.status);
|
|
152
|
-
/** A snapshot of canonical records, never a second task lifecycle. No historical events are inferred. */
|
|
153
147
|
export function projectConversationState(state, conversation) {
|
|
154
148
|
const prior = conversation.taskState;
|
|
155
149
|
const tasks = state.tasks.filter((task) => task.conversationId === conversation.id);
|
|
156
150
|
const current = tasks.find((task) => task.id === conversation.latestTaskId);
|
|
157
151
|
const messages = state.conversationMessages.filter((message) => message.conversationId === conversation.id);
|
|
158
|
-
// rootTaskId tracks the dispatch budget chain and can change on a new human turn.
|
|
159
|
-
// Delegated conversations may also point at a root in a different conversation.
|
|
160
152
|
const initial = [
|
|
161
153
|
...tasks.map((task) => ({ text: task.text, createdAt: task.createdAt })),
|
|
162
154
|
...messages.map((message) => ({ text: message.text, createdAt: message.createdAt })),
|
|
@@ -219,7 +211,6 @@ export function projectConversationState(state, conversation) {
|
|
|
219
211
|
...(prior?.reported ? { reported: prior.reported } : {}),
|
|
220
212
|
};
|
|
221
213
|
}
|
|
222
|
-
/** Run after every canonical mutation and before persistence, including restart recovery. */
|
|
223
214
|
export function reconcileConversationState(previous, next) {
|
|
224
215
|
const oldConversations = new Map(previous.conversations.map((conversation) => [conversation.id, conversation]));
|
|
225
216
|
const oldMessages = new Set(previous.conversationMessages.map((message) => message.id));
|
|
@@ -228,7 +219,6 @@ export function reconcileConversationState(previous, next) {
|
|
|
228
219
|
const oldReviews = new Set(previous.reviews.map((review) => review.id));
|
|
229
220
|
for (const conversation of next.conversations) {
|
|
230
221
|
const before = oldConversations.get(conversation.id);
|
|
231
|
-
// Only reported fields may be explicitly changed; the rest is always derived here.
|
|
232
222
|
const reported = conversation.taskState?.reported;
|
|
233
223
|
conversation.taskState = before?.taskState;
|
|
234
224
|
const projected = projectConversationState(next, conversation);
|
|
@@ -255,7 +245,6 @@ export function reconcileConversationState(previous, next) {
|
|
|
255
245
|
};
|
|
256
246
|
const newMessages = next.conversationMessages.filter((message) => message.conversationId === conversation.id && !oldMessages.has(message.id));
|
|
257
247
|
for (const message of newMessages) {
|
|
258
|
-
// Own execution reports are represented by the canonical task status transition.
|
|
259
248
|
const task = next.tasks.find((task) => task.id === message.taskId);
|
|
260
249
|
if (message.kind === "result" && (task?.kind !== "result" || message.sourceBotId === task.botId))
|
|
261
250
|
continue;
|
|
@@ -292,7 +281,6 @@ export function reconcileConversationState(previous, next) {
|
|
|
292
281
|
if (before?.attention && before.attention.id !== conversation.attention?.id) {
|
|
293
282
|
const attention = before.attention;
|
|
294
283
|
const humans = newMessages.filter((message) => !message.sourceBotId && message.kind === "message" && message.createdAt >= attention.createdAt);
|
|
295
|
-
// Ambiguous removal (close/cancel/replacement) must never invent a human decision.
|
|
296
284
|
const answer = !conversation.closed && !conversation.attention && humans.length === 1 ? humans[0] : undefined;
|
|
297
285
|
append("attention_resolved", attention.id, answer?.createdAt ?? conversation.updatedAt, answer?.taskId ?? attention.taskId);
|
|
298
286
|
if (answer && attention.kind === "decision")
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { applyBinaryPatch, canonicalPath, checkSignal, computeCanonicalRepositoryId, createDetachedWorktree, git, inside, removeDetachedWorktree, safeId, snapshotTree, verifyPatchProducesTree, verifyRepoRoot, verifyWorktreeIdentity, } from "../workspace-handle.js";
|
|
5
|
+
import { computeArtifactDigest, deepFreeze, validateContextManifest, validateDeviceArtifact, validateInputArtifacts, validateWorkContract, } from "./work-contract.js";
|
|
6
|
+
import { validateDeviceProject } from "./workspaces.js";
|
|
7
|
+
export const MAX_TASK_ARTIFACT_PATCH_BYTES = 128 * 1024;
|
|
8
|
+
const workspaceRegistry = new Map();
|
|
9
|
+
const preparingBindings = new Set();
|
|
10
|
+
const trustedCapabilities = new WeakMap();
|
|
11
|
+
function bindingKey(binding) {
|
|
12
|
+
return createHash("sha256")
|
|
13
|
+
.update(JSON.stringify([binding.deviceId, binding.botId, binding.botRevision, binding.taskId, binding.attemptId]))
|
|
14
|
+
.digest("hex");
|
|
15
|
+
}
|
|
16
|
+
export function isTrustedTaskWorkspaceCapability(value) {
|
|
17
|
+
if (!value || typeof value !== "object")
|
|
18
|
+
return false;
|
|
19
|
+
const trusted = trustedCapabilities.get(value);
|
|
20
|
+
return !!trusted && workspaceRegistry.has(trusted.handleId);
|
|
21
|
+
}
|
|
22
|
+
export async function resolveTrustedTaskWorkspace(capability, binding) {
|
|
23
|
+
if (!capability || typeof capability !== "object")
|
|
24
|
+
throw new Error("Untrusted task workspace capability");
|
|
25
|
+
const trusted = trustedCapabilities.get(capability);
|
|
26
|
+
if (!trusted)
|
|
27
|
+
throw new Error("Untrusted task workspace capability");
|
|
28
|
+
return resolveTaskWorkspace(trusted.handleId, binding);
|
|
29
|
+
}
|
|
30
|
+
function getRegisteredRecord(handle, binding) {
|
|
31
|
+
const handleId = typeof handle === "string" ? handle.trim() : handle?.handleId?.trim();
|
|
32
|
+
if (!handleId) {
|
|
33
|
+
throw new Error("Invalid task workspace handle: missing handleId");
|
|
34
|
+
}
|
|
35
|
+
const record = workspaceRegistry.get(handleId);
|
|
36
|
+
if (!record) {
|
|
37
|
+
throw new Error(`Unregistered or expired task workspace handle: ${handleId}`);
|
|
38
|
+
}
|
|
39
|
+
if (binding.deviceId !== record.deviceId ||
|
|
40
|
+
binding.botId !== record.botId ||
|
|
41
|
+
binding.botRevision !== record.botRevision ||
|
|
42
|
+
binding.taskId !== record.taskId ||
|
|
43
|
+
binding.attemptId !== record.attemptId) {
|
|
44
|
+
throw new Error(`Task workspace binding mismatch for handle ${handleId}: caller binding does not match registered capability`);
|
|
45
|
+
}
|
|
46
|
+
return record;
|
|
47
|
+
}
|
|
48
|
+
export async function prepareTaskWorkspace(options) {
|
|
49
|
+
checkSignal(options.signal);
|
|
50
|
+
options = { ...options };
|
|
51
|
+
const key = bindingKey(options);
|
|
52
|
+
if (preparingBindings.has(key) || [...workspaceRegistry.values()].some((record) => record.bindingKey === key)) {
|
|
53
|
+
throw new Error("Task workspace binding is already preparing or registered");
|
|
54
|
+
}
|
|
55
|
+
preparingBindings.add(key);
|
|
56
|
+
try {
|
|
57
|
+
return await prepareRegisteredWorkspace(options, key);
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
preparingBindings.delete(key);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function prepareRegisteredWorkspace(options, key) {
|
|
64
|
+
const deviceId = safeId(options.deviceId, "deviceId");
|
|
65
|
+
const botId = safeId(options.botId, "botId");
|
|
66
|
+
const taskId = safeId(options.taskId, "taskId");
|
|
67
|
+
const attemptId = safeId(options.attemptId, "attemptId");
|
|
68
|
+
if (!Number.isSafeInteger(options.botRevision) || options.botRevision < 1) {
|
|
69
|
+
throw new Error(`Invalid botRevision: ${options.botRevision}`);
|
|
70
|
+
}
|
|
71
|
+
const contractCheck = validateWorkContract(deepFreeze(structuredClone(options.contract)));
|
|
72
|
+
if (!contractCheck.valid) {
|
|
73
|
+
throw new Error(`Invalid task contract: ${contractCheck.reason}`);
|
|
74
|
+
}
|
|
75
|
+
const contract = contractCheck.contract;
|
|
76
|
+
const manifestCheck = validateContextManifest(deepFreeze(structuredClone(options.contextManifest)), contract);
|
|
77
|
+
if (!manifestCheck.valid) {
|
|
78
|
+
throw new Error(`Invalid context manifest: ${manifestCheck.reason}`);
|
|
79
|
+
}
|
|
80
|
+
const contextManifest = manifestCheck.manifest;
|
|
81
|
+
const validatedProjectRoot = await validateDeviceProject(options.repoRoot, options.dataDir);
|
|
82
|
+
const { repoRoot } = await verifyRepoRoot(validatedProjectRoot, options.signal);
|
|
83
|
+
if (validatedProjectRoot !== repoRoot) {
|
|
84
|
+
throw new Error("Task code workspace requires Bot.cwd at the Git repository root; subdirectory code workspaces are not supported");
|
|
85
|
+
}
|
|
86
|
+
const baselineStatus = (await git(repoRoot, ["status", "--porcelain", "--untracked-files=all"], options.signal)).trim();
|
|
87
|
+
if (baselineStatus.length > 0) {
|
|
88
|
+
throw new Error("Device task workspace requires a clean baseline repository; commit or stash changes first");
|
|
89
|
+
}
|
|
90
|
+
const canonicalRepoId = await computeCanonicalRepositoryId(repoRoot, options.signal);
|
|
91
|
+
let baseCommit;
|
|
92
|
+
if (contract.baseline) {
|
|
93
|
+
const candidateCommit = contract.baseline.commit.trim().toLowerCase();
|
|
94
|
+
try {
|
|
95
|
+
baseCommit = (await git(repoRoot, ["rev-parse", "--verify", `${candidateCommit}^{commit}`], options.signal)).trim();
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
checkSignal(options.signal);
|
|
99
|
+
throw new Error(`Baseline commit ${candidateCommit} does not exist in repository ${repoRoot}`, {
|
|
100
|
+
cause: error,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const expectedRepoId = contract.baseline.repositoryId.trim();
|
|
104
|
+
if (expectedRepoId !== canonicalRepoId) {
|
|
105
|
+
throw new Error(`Repository identity mismatch: baseline specifies '${expectedRepoId}', local repository is '${canonicalRepoId}'`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
baseCommit = (await git(repoRoot, ["rev-parse", "HEAD"], options.signal)).trim();
|
|
110
|
+
}
|
|
111
|
+
const handleId = randomUUID();
|
|
112
|
+
const refNamespace = `${key}/${handleId}`;
|
|
113
|
+
const resolvedDataDir = resolve(options.dataDir);
|
|
114
|
+
const worktreeDir = join(resolvedDataDir, "task-workspaces", handleId);
|
|
115
|
+
if (!inside(resolvedDataDir, worktreeDir)) {
|
|
116
|
+
throw new Error("Task workspace directory escapes dataDir");
|
|
117
|
+
}
|
|
118
|
+
if (inside(repoRoot, worktreeDir)) {
|
|
119
|
+
throw new Error("Task workspace dataDir must be outside the baseline repository");
|
|
120
|
+
}
|
|
121
|
+
if (existsSync(worktreeDir)) {
|
|
122
|
+
throw new Error(`Task workspace directory already exists: ${worktreeDir}; refusing overwrite`);
|
|
123
|
+
}
|
|
124
|
+
let creationAttempted = false;
|
|
125
|
+
let workspaceCommit;
|
|
126
|
+
const workspaceRef = `refs/pi-tasks/workspaces/${refNamespace}`;
|
|
127
|
+
const artifactRef = `refs/pi-tasks/artifacts/${refNamespace}`;
|
|
128
|
+
try {
|
|
129
|
+
creationAttempted = true;
|
|
130
|
+
await createDetachedWorktree(repoRoot, worktreeDir, baseCommit, options.signal);
|
|
131
|
+
const identity = await verifyWorktreeIdentity(worktreeDir, repoRoot, options.signal);
|
|
132
|
+
const canonicalWorktreePath = identity.toplevel;
|
|
133
|
+
const canonicalGitDir = identity.gitDir;
|
|
134
|
+
let inputTree = (await git(repoRoot, ["rev-parse", `${baseCommit}^{tree}`], options.signal)).trim();
|
|
135
|
+
if (contract.inputArtifacts && contract.inputArtifacts.length > 0) {
|
|
136
|
+
const synthCheck = validateInputArtifacts(contract.inputArtifacts, contract.baseline, contract.executionMode);
|
|
137
|
+
if (!synthCheck.valid) {
|
|
138
|
+
throw new Error(`Invalid contract inputArtifacts: ${synthCheck.reason}`);
|
|
139
|
+
}
|
|
140
|
+
const touched = new Set();
|
|
141
|
+
for (const artifact of contract.inputArtifacts) {
|
|
142
|
+
if (!artifact.baseline || !artifact.outputTree) {
|
|
143
|
+
throw new Error(`Input artifact ${artifact.id} requires baseline and outputTree proof`);
|
|
144
|
+
}
|
|
145
|
+
if (artifact.baseline.repositoryId !== canonicalRepoId ||
|
|
146
|
+
artifact.baseline.commit.toLowerCase() !== baseCommit) {
|
|
147
|
+
throw new Error(`Input artifact ${artifact.id} baseline mismatch`);
|
|
148
|
+
}
|
|
149
|
+
if (artifact.patchBase64 === undefined) {
|
|
150
|
+
throw new Error(`Input artifact ${artifact.id} has no patchBase64`);
|
|
151
|
+
}
|
|
152
|
+
const patchBytes = Buffer.from(artifact.patchBase64, "base64");
|
|
153
|
+
if (patchBytes.length > MAX_TASK_ARTIFACT_PATCH_BYTES) {
|
|
154
|
+
throw new Error(`Input artifact ${artifact.id} patch exceeds size limit of 128 KiB`);
|
|
155
|
+
}
|
|
156
|
+
const computedPatchSha256 = createHash("sha256").update(patchBytes).digest("hex");
|
|
157
|
+
if (computedPatchSha256.toLowerCase() !== artifact.patchSha256?.toLowerCase()) {
|
|
158
|
+
throw new Error(`Input artifact ${artifact.id} patchSha256 checksum mismatch`);
|
|
159
|
+
}
|
|
160
|
+
await verifyPatchProducesTree(repoRoot, baseCommit, patchBytes, artifact.outputTree, resolvedDataDir, options.signal);
|
|
161
|
+
const paths = (await git(repoRoot, [
|
|
162
|
+
"diff",
|
|
163
|
+
"--no-ext-diff",
|
|
164
|
+
"--no-textconv",
|
|
165
|
+
"--no-renames",
|
|
166
|
+
"--name-only",
|
|
167
|
+
"-z",
|
|
168
|
+
baseCommit,
|
|
169
|
+
artifact.outputTree,
|
|
170
|
+
"--",
|
|
171
|
+
], options.signal))
|
|
172
|
+
.split("\0")
|
|
173
|
+
.filter(Boolean);
|
|
174
|
+
for (const path of paths) {
|
|
175
|
+
if ([...touched].some((other) => path === other || path.startsWith(`${other}/`) || other.startsWith(`${path}/`))) {
|
|
176
|
+
throw new Error(`Input artifact conflict: overlapping or ancestor input at ${path}; cumulative layers are not deduplicated`);
|
|
177
|
+
}
|
|
178
|
+
touched.add(path);
|
|
179
|
+
}
|
|
180
|
+
await applyBinaryPatch(worktreeDir, patchBytes, options.signal);
|
|
181
|
+
}
|
|
182
|
+
inputTree = await snapshotTree(worktreeDir, options.dataDir, options.signal, join("task-workspaces", "input-indexes"));
|
|
183
|
+
}
|
|
184
|
+
workspaceCommit = (await git(repoRoot, ["commit-tree", inputTree, "-p", baseCommit, "-m", "pi-task-workspace"], options.signal)).trim();
|
|
185
|
+
checkSignal(options.signal);
|
|
186
|
+
await git(repoRoot, ["update-ref", workspaceRef, workspaceCommit, "0".repeat(baseCommit.length)]);
|
|
187
|
+
const record = {
|
|
188
|
+
handleId,
|
|
189
|
+
deviceId,
|
|
190
|
+
botId,
|
|
191
|
+
botRevision: options.botRevision,
|
|
192
|
+
taskId,
|
|
193
|
+
attemptId,
|
|
194
|
+
repoRoot,
|
|
195
|
+
worktreePath: worktreeDir,
|
|
196
|
+
canonicalWorktreePath,
|
|
197
|
+
canonicalGitDir,
|
|
198
|
+
canonicalCommonDir: identity.commonDir,
|
|
199
|
+
bindingKey: key,
|
|
200
|
+
workspaceRef,
|
|
201
|
+
workspaceCommit,
|
|
202
|
+
artifactRef,
|
|
203
|
+
repositoryId: canonicalRepoId,
|
|
204
|
+
baseCommit,
|
|
205
|
+
contract,
|
|
206
|
+
contextManifest,
|
|
207
|
+
dataDir: resolvedDataDir,
|
|
208
|
+
inputTree,
|
|
209
|
+
createdAt: Date.now(),
|
|
210
|
+
};
|
|
211
|
+
workspaceRegistry.set(handleId, record);
|
|
212
|
+
return Object.freeze({ handleId, deviceId, botId, taskId, attemptId });
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
const failures = [];
|
|
216
|
+
if (creationAttempted && existsSync(worktreeDir)) {
|
|
217
|
+
try {
|
|
218
|
+
const identity = await verifyWorktreeIdentity(worktreeDir, repoRoot);
|
|
219
|
+
if (identity.toplevel !== worktreeDir || identity.headCommit !== baseCommit)
|
|
220
|
+
throw new Error("Failed workspace ownership cannot be verified; retained for inspection");
|
|
221
|
+
await removeDetachedWorktree(repoRoot, worktreeDir, { force: true });
|
|
222
|
+
}
|
|
223
|
+
catch (cleanupError) {
|
|
224
|
+
failures.push(cleanupError);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (workspaceCommit) {
|
|
228
|
+
try {
|
|
229
|
+
await git(repoRoot, ["update-ref", "-d", workspaceRef, workspaceCommit]);
|
|
230
|
+
}
|
|
231
|
+
catch (cleanupError) {
|
|
232
|
+
failures.push(cleanupError);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (failures.length)
|
|
236
|
+
throw new AggregateError([error, ...failures], "Workspace preparation failed; cleanup incomplete, retained for inspection", { cause: error });
|
|
237
|
+
throw error;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
export async function resolveTaskWorkspace(handle, binding) {
|
|
241
|
+
const record = getRegisteredRecord(handle, binding);
|
|
242
|
+
if (record.closing)
|
|
243
|
+
throw new Error("Task workspace cleanup is in progress");
|
|
244
|
+
const canonicalCurrent = await canonicalPath(record.worktreePath);
|
|
245
|
+
if (canonicalCurrent !== record.canonicalWorktreePath) {
|
|
246
|
+
throw new Error(`Task workspace path redirect detected: expected ${record.canonicalWorktreePath}, resolved to ${canonicalCurrent}`);
|
|
247
|
+
}
|
|
248
|
+
await verifyWorktreeIdentity(record.worktreePath, record.repoRoot, undefined, record.canonicalGitDir, record.canonicalCommonDir);
|
|
249
|
+
return {
|
|
250
|
+
cwd: record.worktreePath,
|
|
251
|
+
repoRoot: record.repoRoot,
|
|
252
|
+
worktreePath: record.worktreePath,
|
|
253
|
+
baseCommit: record.baseCommit,
|
|
254
|
+
contractDigest: record.contract.digest,
|
|
255
|
+
manifestDigest: record.contextManifest.digest,
|
|
256
|
+
inputTree: record.inputTree,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
export function getTaskWorkspaceCapability(handle, binding) {
|
|
260
|
+
const record = getRegisteredRecord(handle, binding);
|
|
261
|
+
const registeredBinding = Object.freeze({
|
|
262
|
+
deviceId: record.deviceId,
|
|
263
|
+
botId: record.botId,
|
|
264
|
+
botRevision: record.botRevision,
|
|
265
|
+
taskId: record.taskId,
|
|
266
|
+
attemptId: record.attemptId,
|
|
267
|
+
});
|
|
268
|
+
const capability = Object.freeze({
|
|
269
|
+
handleId: record.handleId,
|
|
270
|
+
binding: registeredBinding,
|
|
271
|
+
resolve: () => resolveTaskWorkspace(record.handleId, registeredBinding),
|
|
272
|
+
getCwd: async () => (await resolveTaskWorkspace(record.handleId, registeredBinding)).cwd,
|
|
273
|
+
getRepoRoot: async () => (await resolveTaskWorkspace(record.handleId, registeredBinding)).repoRoot,
|
|
274
|
+
captureArtifact: (signal) => captureTaskArtifact(record.handleId, registeredBinding, signal),
|
|
275
|
+
cleanup: (options) => cleanupTaskWorkspace(record.handleId, registeredBinding, options),
|
|
276
|
+
});
|
|
277
|
+
trustedCapabilities.set(capability, { handleId: record.handleId, binding: registeredBinding });
|
|
278
|
+
return capability;
|
|
279
|
+
}
|
|
280
|
+
export async function captureTaskArtifact(handle, binding, signal) {
|
|
281
|
+
checkSignal(signal);
|
|
282
|
+
const record = getRegisteredRecord(handle, binding);
|
|
283
|
+
if (record.closing)
|
|
284
|
+
throw new Error("Task workspace cleanup is in progress");
|
|
285
|
+
if (record.artifactCaptured)
|
|
286
|
+
return record.artifactCaptured;
|
|
287
|
+
if (!record.captureFlight) {
|
|
288
|
+
record.captureFlight = captureRegisteredArtifact(record, signal).finally(() => {
|
|
289
|
+
record.captureFlight = undefined;
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
const artifact = await record.captureFlight;
|
|
293
|
+
checkSignal(signal);
|
|
294
|
+
return artifact;
|
|
295
|
+
}
|
|
296
|
+
async function captureRegisteredArtifact(record, signal) {
|
|
297
|
+
const canonicalCurrent = await canonicalPath(record.worktreePath);
|
|
298
|
+
if (canonicalCurrent !== record.canonicalWorktreePath) {
|
|
299
|
+
throw new Error(`Task workspace path redirect detected during capture: expected ${record.canonicalWorktreePath}, resolved to ${canonicalCurrent}`);
|
|
300
|
+
}
|
|
301
|
+
await verifyWorktreeIdentity(record.worktreePath, record.repoRoot, signal, record.canonicalGitDir, record.canonicalCommonDir);
|
|
302
|
+
const outputTree = await snapshotTree(record.worktreePath, record.dataDir, signal, join("task-workspaces", "output-indexes"));
|
|
303
|
+
await verifyWorktreeIdentity(record.worktreePath, record.repoRoot, signal, record.canonicalGitDir, record.canonicalCommonDir);
|
|
304
|
+
const baseTree = (await git(record.repoRoot, ["rev-parse", `${record.baseCommit}^{tree}`], signal)).trim();
|
|
305
|
+
const patchStr = await git(record.worktreePath, ["diff", "--binary", "--full-index", "--no-ext-diff", "--no-textconv", baseTree, outputTree, "--"], signal);
|
|
306
|
+
const patchBytes = Buffer.from(patchStr, "utf8");
|
|
307
|
+
if (patchBytes.length > MAX_TASK_ARTIFACT_PATCH_BYTES) {
|
|
308
|
+
throw new Error(`Artifact patch size (${patchBytes.length} bytes) exceeds maximum limit of ${MAX_TASK_ARTIFACT_PATCH_BYTES} bytes (128 KiB)`);
|
|
309
|
+
}
|
|
310
|
+
const patchSha256 = createHash("sha256").update(patchBytes).digest("hex");
|
|
311
|
+
const patchBase64 = patchBytes.toString("base64");
|
|
312
|
+
const retentionCommit = (await git(record.repoRoot, [
|
|
313
|
+
"commit-tree",
|
|
314
|
+
outputTree,
|
|
315
|
+
"-p",
|
|
316
|
+
record.workspaceCommit,
|
|
317
|
+
"-m",
|
|
318
|
+
`pi-task-artifact: task=${record.taskId} attempt=${record.attemptId}`,
|
|
319
|
+
], signal)).trim();
|
|
320
|
+
const artifact = {
|
|
321
|
+
id: `artifact-${randomUUID()}`,
|
|
322
|
+
digest: "",
|
|
323
|
+
producer: {
|
|
324
|
+
deviceId: record.deviceId,
|
|
325
|
+
botId: record.botId,
|
|
326
|
+
taskId: record.taskId,
|
|
327
|
+
attemptId: record.attemptId,
|
|
328
|
+
contractDigest: record.contract.digest,
|
|
329
|
+
manifestDigest: record.contextManifest.digest,
|
|
330
|
+
},
|
|
331
|
+
baseline: { repositoryId: record.repositoryId, commit: record.baseCommit },
|
|
332
|
+
inputTree: record.inputTree,
|
|
333
|
+
outputTree,
|
|
334
|
+
patchBase64,
|
|
335
|
+
patchSha256,
|
|
336
|
+
createdAt: Date.now(),
|
|
337
|
+
};
|
|
338
|
+
artifact.digest = computeArtifactDigest(artifact);
|
|
339
|
+
const validated = validateDeviceArtifact(artifact);
|
|
340
|
+
if (!validated.valid) {
|
|
341
|
+
throw new Error(`Constructed invalid artifact: ${validated.reason}`);
|
|
342
|
+
}
|
|
343
|
+
const immutable = deepFreeze(structuredClone(validated.artifact));
|
|
344
|
+
checkSignal(signal);
|
|
345
|
+
await git(record.repoRoot, ["update-ref", record.artifactRef, retentionCommit, "0".repeat(record.baseCommit.length)]);
|
|
346
|
+
record.artifactCaptured = immutable;
|
|
347
|
+
return immutable;
|
|
348
|
+
}
|
|
349
|
+
export async function cleanupTaskWorkspace(handle, binding, options = {}) {
|
|
350
|
+
checkSignal(options.signal);
|
|
351
|
+
const record = getRegisteredRecord(handle, binding);
|
|
352
|
+
if (!record.cleanupFlight) {
|
|
353
|
+
record.closing = true;
|
|
354
|
+
record.cleanupFlight = cleanupRegisteredWorkspace(record, options).finally(() => {
|
|
355
|
+
record.closing = false;
|
|
356
|
+
record.cleanupFlight = undefined;
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
return record.cleanupFlight;
|
|
360
|
+
}
|
|
361
|
+
async function cleanupRegisteredWorkspace(record, options) {
|
|
362
|
+
await record.captureFlight;
|
|
363
|
+
checkSignal(options.signal);
|
|
364
|
+
const canonicalCurrent = await canonicalPath(record.worktreePath);
|
|
365
|
+
if (canonicalCurrent !== record.canonicalWorktreePath) {
|
|
366
|
+
throw new Error(`Task workspace path redirect detected during cleanup: expected ${record.canonicalWorktreePath}, resolved to ${canonicalCurrent}`);
|
|
367
|
+
}
|
|
368
|
+
await verifyWorktreeIdentity(record.worktreePath, record.repoRoot, options.signal, record.canonicalGitDir, record.canonicalCommonDir);
|
|
369
|
+
if (!options.force) {
|
|
370
|
+
const head = (await git(record.worktreePath, ["rev-parse", "HEAD"], options.signal)).trim();
|
|
371
|
+
if (head !== record.baseCommit) {
|
|
372
|
+
throw new Error("Task workspace has additional commits; retained for inspection");
|
|
373
|
+
}
|
|
374
|
+
const status = (await git(record.worktreePath, ["status", "--porcelain", "--untracked-files=all"], options.signal)).trim();
|
|
375
|
+
if (status.length > 0) {
|
|
376
|
+
throw new Error("Task workspace has uncommitted changes; retained for inspection");
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
checkSignal(options.signal);
|
|
380
|
+
await removeDetachedWorktree(record.repoRoot, record.worktreePath, { force: options.force });
|
|
381
|
+
try {
|
|
382
|
+
await git(record.repoRoot, ["update-ref", "-d", record.workspaceRef, record.workspaceCommit]);
|
|
383
|
+
}
|
|
384
|
+
finally {
|
|
385
|
+
workspaceRegistry.delete(record.handleId);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
export function getRegisteredWorkspaceCount() {
|
|
389
|
+
return workspaceRegistry.size;
|
|
390
|
+
}
|
|
391
|
+
export function clearTaskWorkspaceRegistry() {
|
|
392
|
+
workspaceRegistry.clear();
|
|
393
|
+
}
|