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,9 +1,16 @@
|
|
|
1
1
|
import { mkdir, readFile, open, rename, unlink } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { PartitionedAppendLog } from "./partition-log.js";
|
|
4
|
+
import { HubTransactionLog, } from "./hub-transaction-log.js";
|
|
4
5
|
import { createHash, randomUUID, timingSafeEqual } from "node:crypto";
|
|
5
6
|
import { projectConversationState, reconcileConversationState, } from "./task-state.js";
|
|
6
|
-
export const taskPending = (task) => !isTerminal(task.status) ||
|
|
7
|
+
export const taskPending = (task) => !isTerminal(task.status) ||
|
|
8
|
+
!!(task.cancelRequested && !task.stopConfirmed) ||
|
|
9
|
+
(task.recoveryUntil !== undefined && task.recoveryUntil > Date.now());
|
|
10
|
+
export const taskHasImmutableEvidence = (task) => !!task.contract ||
|
|
11
|
+
!!task.artifact ||
|
|
12
|
+
task.artifactProduced === true ||
|
|
13
|
+
(task.executionMode === "code" && task.executionCompleted === true);
|
|
7
14
|
export const isTerminal = (status) => ["completed", "failed", "interrupted"].includes(status);
|
|
8
15
|
export const hashSecret = (secret) => createHash("sha256").update(secret).digest("hex");
|
|
9
16
|
export function secretMatches(secret, hash) {
|
|
@@ -19,7 +26,6 @@ export function publicTask(task) {
|
|
|
19
26
|
const { leaseToken: _token, ...visible } = task;
|
|
20
27
|
return visible;
|
|
21
28
|
}
|
|
22
|
-
/** Rows kept per room when replaying append logs; mirrors the group retention the Hub enforces. */
|
|
23
29
|
export const HUB_LOG_RETENTION = 500;
|
|
24
30
|
function createHubLogs(dataDir) {
|
|
25
31
|
const root = join(dataDir, "hub-log");
|
|
@@ -35,8 +41,7 @@ function createHubLogs(dataDir) {
|
|
|
35
41
|
partition: (task) => task.roomId,
|
|
36
42
|
id: (task) => task.id,
|
|
37
43
|
retention: HUB_LOG_RETENTION,
|
|
38
|
-
|
|
39
|
-
protect: (task) => taskPending(task),
|
|
44
|
+
protect: (task) => taskPending(task) || taskHasImmutableEvidence(task),
|
|
40
45
|
}),
|
|
41
46
|
conversationMessages: new PartitionedAppendLog({
|
|
42
47
|
dir: join(root, "conversation-messages"),
|
|
@@ -48,12 +53,17 @@ function createHubLogs(dataDir) {
|
|
|
48
53
|
function emptyHubState() {
|
|
49
54
|
return {
|
|
50
55
|
version: 2,
|
|
56
|
+
checkpointSeq: 0,
|
|
51
57
|
conversations: [],
|
|
52
58
|
conversationMessages: [],
|
|
53
59
|
deliveries: [],
|
|
54
60
|
reviews: [],
|
|
55
61
|
deliveryReceipts: [],
|
|
56
62
|
integrations: [],
|
|
63
|
+
workItems: [],
|
|
64
|
+
workItemEvents: [],
|
|
65
|
+
routerJobs: [],
|
|
66
|
+
workItemOutbox: [],
|
|
57
67
|
accounts: [],
|
|
58
68
|
devices: [],
|
|
59
69
|
bots: [],
|
|
@@ -64,14 +74,12 @@ function emptyHubState() {
|
|
|
64
74
|
receipts: [],
|
|
65
75
|
};
|
|
66
76
|
}
|
|
67
|
-
/** Tasks/messages are partitioned by room; conversations may reference a room row that no longer exists. */
|
|
68
77
|
function roomPartitionsOf(state) {
|
|
69
78
|
return new Set([
|
|
70
79
|
...state.rooms.map((room) => room.id),
|
|
71
80
|
...state.conversations.map((conversation) => conversation.roomId),
|
|
72
81
|
]);
|
|
73
82
|
}
|
|
74
|
-
/** Merge log rows with rows still inlined by an older Hub; inline rows win (they are the older baseline). */
|
|
75
83
|
function mergeRows(stored, inline) {
|
|
76
84
|
if (!inline.length)
|
|
77
85
|
return [...stored];
|
|
@@ -85,11 +93,98 @@ function mergeRows(stored, inline) {
|
|
|
85
93
|
merged.set(row.id, row);
|
|
86
94
|
return [...merged.values()];
|
|
87
95
|
}
|
|
96
|
+
function computeCollectionDiff(oldRows, newRows) {
|
|
97
|
+
const oldMap = new Map();
|
|
98
|
+
for (const row of oldRows) {
|
|
99
|
+
oldMap.set(row.id, JSON.stringify(row));
|
|
100
|
+
}
|
|
101
|
+
const upsert = [];
|
|
102
|
+
const newIds = new Set();
|
|
103
|
+
for (const row of newRows) {
|
|
104
|
+
newIds.add(row.id);
|
|
105
|
+
const serialized = JSON.stringify(row);
|
|
106
|
+
if (oldMap.get(row.id) !== serialized) {
|
|
107
|
+
upsert.push(row);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const deleteIds = [];
|
|
111
|
+
for (const row of oldRows) {
|
|
112
|
+
if (!newIds.has(row.id)) {
|
|
113
|
+
deleteIds.push(row.id);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return { upsert, deleteIds };
|
|
117
|
+
}
|
|
118
|
+
function applyCollectionDiff(target, diff) {
|
|
119
|
+
const deleteSet = new Set(diff.deleteIds);
|
|
120
|
+
let i = 0;
|
|
121
|
+
while (i < target.length) {
|
|
122
|
+
if (deleteSet.has(target[i].id)) {
|
|
123
|
+
target.splice(i, 1);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
i++;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const indexMap = new Map();
|
|
130
|
+
for (let j = 0; j < target.length; j++) {
|
|
131
|
+
indexMap.set(target[j].id, j);
|
|
132
|
+
}
|
|
133
|
+
for (const item of diff.upsert) {
|
|
134
|
+
const existingIndex = indexMap.get(item.id);
|
|
135
|
+
if (existingIndex !== undefined) {
|
|
136
|
+
target[existingIndex] = item;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
target.push(item);
|
|
140
|
+
indexMap.set(item.id, target.length - 1);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function extractIndexState(state) {
|
|
145
|
+
const { messages: _m, tasks: _t, conversationMessages: _cm, ...index } = state;
|
|
146
|
+
return index;
|
|
147
|
+
}
|
|
148
|
+
async function persistIndexTo(indexPath, state, checkpointSeq) {
|
|
149
|
+
const temporary = `${indexPath}.${randomUUID()}.tmp`;
|
|
150
|
+
const index = {
|
|
151
|
+
...state,
|
|
152
|
+
messages: [],
|
|
153
|
+
tasks: [],
|
|
154
|
+
conversationMessages: [],
|
|
155
|
+
checkpointSeq,
|
|
156
|
+
};
|
|
157
|
+
delete index.checkpointSeqRaw;
|
|
158
|
+
try {
|
|
159
|
+
const file = await open(temporary, "wx", 0o600);
|
|
160
|
+
try {
|
|
161
|
+
await file.writeFile(JSON.stringify(index));
|
|
162
|
+
await file.sync();
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
await file.close();
|
|
166
|
+
}
|
|
167
|
+
await rename(temporary, indexPath);
|
|
168
|
+
}
|
|
169
|
+
finally {
|
|
170
|
+
await unlink(temporary).catch((error) => {
|
|
171
|
+
if (error.code !== "ENOENT")
|
|
172
|
+
throw error;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
88
176
|
async function loadHubFiles(dataDir, options = {}) {
|
|
89
|
-
|
|
177
|
+
if (!options.readOnly) {
|
|
178
|
+
await mkdir(dataDir, { recursive: true, mode: 0o700 });
|
|
179
|
+
}
|
|
90
180
|
let state;
|
|
181
|
+
let checkpointSeq = 0;
|
|
91
182
|
try {
|
|
92
|
-
|
|
183
|
+
const rawText = await readFile(join(dataDir, "device-hub.json"), "utf8");
|
|
184
|
+
const rawJson = JSON.parse(rawText);
|
|
185
|
+
checkpointSeq = typeof rawJson.checkpointSeq === "number" ? rawJson.checkpointSeq : 0;
|
|
186
|
+
state = rawJson;
|
|
187
|
+
delete state.checkpointSeq;
|
|
93
188
|
if (state.version !== 2 ||
|
|
94
189
|
![
|
|
95
190
|
state.accounts,
|
|
@@ -108,6 +203,7 @@ async function loadHubFiles(dataDir, options = {}) {
|
|
|
108
203
|
if (error.code !== "ENOENT")
|
|
109
204
|
throw error;
|
|
110
205
|
state = emptyHubState();
|
|
206
|
+
delete state.checkpointSeq;
|
|
111
207
|
}
|
|
112
208
|
state.conversations ??= [];
|
|
113
209
|
state.conversationMessages ??= [];
|
|
@@ -115,6 +211,10 @@ async function loadHubFiles(dataDir, options = {}) {
|
|
|
115
211
|
state.reviews ??= [];
|
|
116
212
|
state.deliveryReceipts ??= [];
|
|
117
213
|
state.integrations ??= [];
|
|
214
|
+
state.workItems ??= [];
|
|
215
|
+
state.workItemEvents ??= [];
|
|
216
|
+
state.routerJobs ??= [];
|
|
217
|
+
state.workItemOutbox ??= [];
|
|
118
218
|
if (![
|
|
119
219
|
state.conversations,
|
|
120
220
|
state.conversationMessages,
|
|
@@ -122,12 +222,24 @@ async function loadHubFiles(dataDir, options = {}) {
|
|
|
122
222
|
state.reviews,
|
|
123
223
|
state.deliveryReceipts,
|
|
124
224
|
state.integrations,
|
|
225
|
+
state.workItems,
|
|
226
|
+
state.workItemEvents,
|
|
227
|
+
state.routerJobs,
|
|
228
|
+
state.workItemOutbox,
|
|
125
229
|
].every(Array.isArray))
|
|
126
230
|
throw new Error("Invalid conversation store");
|
|
231
|
+
const wal = new HubTransactionLog({ walPath: join(dataDir, "hub-wal.jsonl") });
|
|
232
|
+
const { records } = await wal.readTransactions({ readOnly: options.readOnly });
|
|
233
|
+
const unprojectedRecords = records.filter((record) => record.seq > checkpointSeq);
|
|
127
234
|
const logs = createHubLogs(dataDir);
|
|
128
235
|
const roomPartitions = roomPartitionsOf(state);
|
|
129
236
|
const conversations = new Set(state.conversations.map((conversation) => conversation.id));
|
|
130
|
-
|
|
237
|
+
for (const record of unprojectedRecords) {
|
|
238
|
+
for (const partition of roomPartitionsOf(record.index))
|
|
239
|
+
roomPartitions.add(partition);
|
|
240
|
+
for (const conversation of record.index.conversations)
|
|
241
|
+
conversations.add(conversation.id);
|
|
242
|
+
}
|
|
131
243
|
const storedMessages = await logs.messages.load(roomPartitions, options);
|
|
132
244
|
const storedTasks = await logs.tasks.load(roomPartitions, options);
|
|
133
245
|
const storedConversationMessages = await logs.conversationMessages.load(conversations, options);
|
|
@@ -135,19 +247,34 @@ async function loadHubFiles(dataDir, options = {}) {
|
|
|
135
247
|
state.messages = mergeRows(storedMessages, state.messages);
|
|
136
248
|
state.tasks = mergeRows(storedTasks, state.tasks);
|
|
137
249
|
state.conversationMessages = mergeRows(storedConversationMessages, state.conversationMessages);
|
|
138
|
-
|
|
250
|
+
if (unprojectedRecords.length > 0) {
|
|
251
|
+
for (const record of unprojectedRecords) {
|
|
252
|
+
const { checkpointSeq: _recSeq, ...indexProps } = record.index;
|
|
253
|
+
Object.assign(state, indexProps);
|
|
254
|
+
applyCollectionDiff(state.messages, record.diff.messages);
|
|
255
|
+
applyCollectionDiff(state.tasks, record.diff.tasks);
|
|
256
|
+
applyCollectionDiff(state.conversationMessages, record.diff.conversationMessages);
|
|
257
|
+
checkpointSeq = record.seq;
|
|
258
|
+
}
|
|
259
|
+
if (!options.readOnly) {
|
|
260
|
+
const recoveryRooms = roomPartitionsOf(state);
|
|
261
|
+
const recoveryConversations = new Set(state.conversations.map((conversation) => conversation.id));
|
|
262
|
+
await logs.messages.commit(state.messages, recoveryRooms);
|
|
263
|
+
await logs.tasks.commit(state.tasks, recoveryRooms);
|
|
264
|
+
await logs.conversationMessages.commit(state.conversationMessages, recoveryConversations);
|
|
265
|
+
await persistIndexTo(join(dataDir, "device-hub.json"), state, checkpointSeq);
|
|
266
|
+
await wal.checkpoint(checkpointSeq);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
139
269
|
for (const conversation of state.conversations) {
|
|
140
270
|
conversation.taskState = projectConversationState(state, conversation);
|
|
141
271
|
conversation.events ??= [];
|
|
142
272
|
}
|
|
143
|
-
return { state, logs, legacy };
|
|
273
|
+
return { state, logs, wal, checkpointSeq, legacy };
|
|
144
274
|
}
|
|
145
|
-
/** Read the durable state without open() side effects (no interrupt marking); used by tests and tooling. */
|
|
146
275
|
export async function readPersistedHub(dataDir) {
|
|
147
|
-
|
|
148
|
-
return (await loadHubFiles(dataDir, { sweep: false })).state;
|
|
276
|
+
return (await loadHubFiles(dataDir, { sweep: false, readOnly: true })).state;
|
|
149
277
|
}
|
|
150
|
-
/** A single process owns a data directory. Transactions publish only after the index replacement. */
|
|
151
278
|
export class DeviceHubStore {
|
|
152
279
|
state;
|
|
153
280
|
listeners = new Set();
|
|
@@ -160,34 +287,58 @@ export class DeviceHubStore {
|
|
|
160
287
|
tail = Promise.resolve();
|
|
161
288
|
path;
|
|
162
289
|
logs;
|
|
290
|
+
wal;
|
|
163
291
|
logDir;
|
|
164
|
-
|
|
292
|
+
lastSeq;
|
|
293
|
+
checkpointSeq;
|
|
294
|
+
projectionFailed = false;
|
|
295
|
+
lastProjectionError;
|
|
296
|
+
constructor(dataDir, state, logs, wal, checkpointSeq) {
|
|
165
297
|
this.path = join(dataDir, "device-hub.json");
|
|
166
298
|
this.logDir = join(dataDir, "hub-log");
|
|
167
299
|
this.state = state;
|
|
168
300
|
this.logs = logs;
|
|
301
|
+
this.wal = wal;
|
|
302
|
+
this.checkpointSeq = checkpointSeq;
|
|
303
|
+
this.lastSeq = checkpointSeq;
|
|
169
304
|
}
|
|
170
|
-
static async open(dataDir) {
|
|
171
|
-
const { state, logs, legacy } = await loadHubFiles(dataDir);
|
|
172
|
-
const store = new DeviceHubStore(dataDir, state, logs);
|
|
173
|
-
// Move collections that older Hubs kept inline into their append logs. Logs are written first so
|
|
174
|
-
// an interrupted migration can be retried from the still-inline index without losing rows.
|
|
305
|
+
static async open(dataDir, options = {}) {
|
|
306
|
+
const { state, logs, wal, checkpointSeq, legacy } = await loadHubFiles(dataDir);
|
|
307
|
+
const store = new DeviceHubStore(dataDir, state, logs, wal, checkpointSeq);
|
|
175
308
|
if (legacy)
|
|
176
309
|
await store.migrateInlineCollections();
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
310
|
+
const now = Date.now();
|
|
311
|
+
const recoveryGraceMs = 60_000;
|
|
312
|
+
const tasksToInterrupt = state.tasks.filter((task) => {
|
|
313
|
+
if (isTerminal(task.status))
|
|
314
|
+
return false;
|
|
315
|
+
if (options.retainUnleasedQueued) {
|
|
316
|
+
if (task.status === "running")
|
|
317
|
+
return true;
|
|
318
|
+
if (task.status === "queued" && (task.leaseToken || task.leaseGeneration !== undefined))
|
|
319
|
+
return true;
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
return true;
|
|
323
|
+
});
|
|
324
|
+
if (tasksToInterrupt.length > 0) {
|
|
180
325
|
await store.transact((draft) => {
|
|
181
|
-
for (const task of draft.tasks)
|
|
182
|
-
if (
|
|
326
|
+
for (const task of draft.tasks) {
|
|
327
|
+
if (isTerminal(task.status))
|
|
328
|
+
continue;
|
|
329
|
+
const shouldInterrupt = options.retainUnleasedQueued
|
|
330
|
+
? task.status === "running" ||
|
|
331
|
+
(task.status === "queued" && (task.leaseToken || task.leaseGeneration !== undefined))
|
|
332
|
+
: true;
|
|
333
|
+
if (shouldInterrupt) {
|
|
183
334
|
task.status = "interrupted";
|
|
184
335
|
task.report = "Hub restarted before execution was confirmed; submit a new turn to retry.";
|
|
185
336
|
task.updatedAt = now;
|
|
186
|
-
if (task.leaseToken) {
|
|
187
|
-
// Retain recovery grace window for active leases to claim on reconnect!
|
|
337
|
+
if (task.leaseToken || task.leaseGeneration !== undefined) {
|
|
188
338
|
task.recoveryUntil = now + recoveryGraceMs;
|
|
189
339
|
}
|
|
190
340
|
}
|
|
341
|
+
}
|
|
191
342
|
});
|
|
192
343
|
}
|
|
193
344
|
return store;
|
|
@@ -211,39 +362,65 @@ export class DeviceHubStore {
|
|
|
211
362
|
}
|
|
212
363
|
async transact(update) {
|
|
213
364
|
const operation = this.tail.then(async () => {
|
|
365
|
+
if (this.wal.isPoisoned()) {
|
|
366
|
+
throw new Error("Store is poisoned due to previous WAL rollback failure; operations halted");
|
|
367
|
+
}
|
|
214
368
|
const draft = structuredClone(this.state);
|
|
215
369
|
const result = update(draft);
|
|
216
370
|
if (result && (typeof result === "object" || typeof result === "function") && "then" in result) {
|
|
217
|
-
// Transactions only reserve/commit state. External work runs between transactions.
|
|
218
|
-
// Drain a rejected accidental async callback without publishing its detached draft.
|
|
219
371
|
void Promise.resolve(result).catch(() => { });
|
|
220
372
|
throw new Error("Hub transactions require a synchronous update");
|
|
221
373
|
}
|
|
222
374
|
if (typeof reconcileConversationState === "function") {
|
|
223
375
|
reconcileConversationState(this.state, draft);
|
|
224
376
|
}
|
|
225
|
-
|
|
226
|
-
this.
|
|
377
|
+
const detachedResult = structuredClone(result);
|
|
378
|
+
const nextSeq = this.lastSeq + 1;
|
|
379
|
+
const diff = {
|
|
380
|
+
messages: computeCollectionDiff(this.state.messages, draft.messages),
|
|
381
|
+
tasks: computeCollectionDiff(this.state.tasks, draft.tasks),
|
|
382
|
+
conversationMessages: computeCollectionDiff(this.state.conversationMessages, draft.conversationMessages),
|
|
383
|
+
};
|
|
384
|
+
await this.persist(draft, nextSeq, diff);
|
|
227
385
|
for (const listener of this.listeners) {
|
|
228
386
|
try {
|
|
229
387
|
listener();
|
|
230
388
|
}
|
|
231
|
-
catch {
|
|
232
|
-
/* notification cannot roll back a committed transaction */
|
|
233
|
-
}
|
|
389
|
+
catch { }
|
|
234
390
|
}
|
|
235
|
-
return
|
|
391
|
+
return detachedResult;
|
|
236
392
|
});
|
|
237
393
|
this.tail = operation.catch(() => { });
|
|
238
394
|
return operation;
|
|
239
395
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
396
|
+
async persist(state, checkpointSeq = this.lastSeq, diff) {
|
|
397
|
+
state = structuredClone(state);
|
|
398
|
+
if (diff)
|
|
399
|
+
diff = structuredClone(diff);
|
|
400
|
+
if (this.projectionFailed) {
|
|
401
|
+
this.logs.messages.invalidateCache();
|
|
402
|
+
this.logs.tasks.invalidateCache();
|
|
403
|
+
this.logs.conversationMessages.invalidateCache();
|
|
404
|
+
}
|
|
405
|
+
if (diff) {
|
|
406
|
+
await this.wal.append(checkpointSeq, extractIndexState(state), diff);
|
|
407
|
+
this.state = state;
|
|
408
|
+
this.lastSeq = checkpointSeq;
|
|
409
|
+
}
|
|
410
|
+
try {
|
|
411
|
+
await this.commitLogs(state);
|
|
412
|
+
await this.persistIndex(state, checkpointSeq);
|
|
413
|
+
await this.wal.checkpoint(checkpointSeq);
|
|
414
|
+
this.checkpointSeq = checkpointSeq;
|
|
415
|
+
this.projectionFailed = false;
|
|
416
|
+
this.lastProjectionError = undefined;
|
|
417
|
+
}
|
|
418
|
+
catch (projectionError) {
|
|
419
|
+
this.projectionFailed = true;
|
|
420
|
+
this.lastProjectionError = projectionError;
|
|
421
|
+
if (!diff)
|
|
422
|
+
throw projectionError;
|
|
423
|
+
}
|
|
247
424
|
}
|
|
248
425
|
async commitLogs(state) {
|
|
249
426
|
const rooms = roomPartitionsOf(state);
|
|
@@ -252,31 +429,12 @@ export class DeviceHubStore {
|
|
|
252
429
|
await this.logs.tasks.commit(state.tasks, rooms);
|
|
253
430
|
await this.logs.conversationMessages.commit(state.conversationMessages, conversations);
|
|
254
431
|
}
|
|
255
|
-
/** One-time upgrade from Hubs that inlined messages/tasks/transcripts in the index file. */
|
|
256
432
|
async migrateInlineCollections() {
|
|
257
433
|
await this.commitLogs(this.state);
|
|
258
|
-
await this.persistIndex(this.state);
|
|
434
|
+
await this.persistIndex(this.state, this.checkpointSeq);
|
|
259
435
|
}
|
|
260
|
-
async persistIndex(state) {
|
|
261
|
-
|
|
262
|
-
const index = { ...state, messages: [], tasks: [], conversationMessages: [] };
|
|
263
|
-
try {
|
|
264
|
-
const file = await open(temporary, "wx", 0o600);
|
|
265
|
-
try {
|
|
266
|
-
await file.writeFile(JSON.stringify(index));
|
|
267
|
-
await file.sync();
|
|
268
|
-
}
|
|
269
|
-
finally {
|
|
270
|
-
await file.close();
|
|
271
|
-
}
|
|
272
|
-
await rename(temporary, this.path);
|
|
273
|
-
}
|
|
274
|
-
finally {
|
|
275
|
-
await unlink(temporary).catch((error) => {
|
|
276
|
-
if (error.code !== "ENOENT")
|
|
277
|
-
throw error;
|
|
278
|
-
});
|
|
279
|
-
}
|
|
436
|
+
async persistIndex(state, checkpointSeq = this.checkpointSeq) {
|
|
437
|
+
await persistIndexTo(this.path, state, checkpointSeq);
|
|
280
438
|
}
|
|
281
439
|
async close() {
|
|
282
440
|
await this.tail;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** Select optional reference data only. Current task text, handoff and runtime state never pass through here. */
|
|
2
1
|
export function selectTaskContext(source, budget = 12 * 1024) {
|
|
3
2
|
if (!Number.isSafeInteger(budget) || budget < 0)
|
|
4
3
|
throw new RangeError("Task context budget must be a nonnegative safe integer");
|
|
@@ -43,7 +42,6 @@ export function selectTaskContext(source, budget = 12 * 1024) {
|
|
|
43
42
|
lookup: "Optional reference snapshot. Use device_collab task_state for full canonical state, omitted constraints/decisions and current revision before acting.",
|
|
44
43
|
};
|
|
45
44
|
const measure = () => {
|
|
46
|
-
// bytes counts itself, so settle its decimal width before comparing the budget.
|
|
47
45
|
let bytes;
|
|
48
46
|
do {
|
|
49
47
|
bytes = selection.bytes;
|
|
@@ -65,7 +63,6 @@ export function selectTaskContext(source, budget = 12 * 1024) {
|
|
|
65
63
|
measure();
|
|
66
64
|
return false;
|
|
67
65
|
};
|
|
68
|
-
// Newest human decisions first; each question/answer pair is indivisible.
|
|
69
66
|
for (const d of [...source.decisions].reverse()) {
|
|
70
67
|
const decision = {
|
|
71
68
|
attentionId: d.attentionId,
|
|
@@ -3,8 +3,8 @@ import { join } from "node:path";
|
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
4
|
import { sanitizeTextForJournal, sanitizeToolParameters } from "./task-progress.js";
|
|
5
5
|
export const MAX_JOURNAL_SEGMENT_ENTRIES = 50;
|
|
6
|
-
export const MAX_JOURNAL_SEGMENT_BYTES = 64 * 1024;
|
|
7
|
-
export const MAX_JOURNAL_RETAINED_SEGMENTS = 20;
|
|
6
|
+
export const MAX_JOURNAL_SEGMENT_BYTES = 64 * 1024;
|
|
7
|
+
export const MAX_JOURNAL_RETAINED_SEGMENTS = 20;
|
|
8
8
|
function sha256Hex(data) {
|
|
9
9
|
return createHash("sha256").update(data).digest("hex");
|
|
10
10
|
}
|
|
@@ -29,9 +29,7 @@ export function decodeJournalCursor(cursorStr) {
|
|
|
29
29
|
return { taskId: obj.taskId, attemptId: obj.attemptId, sequence: obj.sequence };
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
catch {
|
|
33
|
-
// invalid cursor
|
|
34
|
-
}
|
|
32
|
+
catch { }
|
|
35
33
|
return null;
|
|
36
34
|
}
|
|
37
35
|
async function writeAtomicAsync(filePath, content) {
|
|
@@ -49,9 +47,7 @@ async function writeAtomicAsync(filePath, content) {
|
|
|
49
47
|
export function createTaskJournalManager(baseDir) {
|
|
50
48
|
const rootDir = join(baseDir, "task-journals");
|
|
51
49
|
let closed = false;
|
|
52
|
-
// In-memory active task state cache to avoid repeated disk reads on progress loops
|
|
53
50
|
const activeTasks = new Map();
|
|
54
|
-
// Asynchronous serialization tail Promise per task
|
|
55
51
|
const taskLocks = new Map();
|
|
56
52
|
function taskDir(taskId) {
|
|
57
53
|
return join(rootDir, safeTaskDirName(taskId));
|
|
@@ -101,7 +97,6 @@ export function createTaskJournalManager(baseDir) {
|
|
|
101
97
|
await mkdir(dir, { recursive: true });
|
|
102
98
|
await writeAtomicAsync(join(dir, "meta.json"), JSON.stringify(meta, null, 2));
|
|
103
99
|
}
|
|
104
|
-
// Stat current active segment to track bytes and lines without full read
|
|
105
100
|
const segPath = join(dir, segmentFileName(meta.activeSegmentIndex));
|
|
106
101
|
let bytes = 0;
|
|
107
102
|
let lines = 0;
|
|
@@ -111,9 +106,7 @@ export function createTaskJournalManager(baseDir) {
|
|
|
111
106
|
const content = await readFile(segPath, "utf8");
|
|
112
107
|
lines = content.split("\n").filter((l) => l.trim().length > 0).length;
|
|
113
108
|
}
|
|
114
|
-
catch {
|
|
115
|
-
// Segment does not exist yet
|
|
116
|
-
}
|
|
109
|
+
catch { }
|
|
117
110
|
const state = {
|
|
118
111
|
meta,
|
|
119
112
|
currentSegBytes: bytes,
|
|
@@ -175,7 +168,6 @@ export function createTaskJournalManager(baseDir) {
|
|
|
175
168
|
const now = Date.now();
|
|
176
169
|
const timestamp = entryInput.timestamp || now;
|
|
177
170
|
const id = `${taskId}-${seq}`;
|
|
178
|
-
// Sanitize output, summary, reason, parameters
|
|
179
171
|
let sanitizedOutput;
|
|
180
172
|
if (typeof entryInput.output === "string") {
|
|
181
173
|
sanitizedOutput = sanitizeTextForJournal(entryInput.output).slice(0, 2048);
|
|
@@ -217,7 +209,6 @@ export function createTaskJournalManager(baseDir) {
|
|
|
217
209
|
};
|
|
218
210
|
const line = JSON.stringify(entry) + "\n";
|
|
219
211
|
const lineBytes = Buffer.byteLength(line, "utf8");
|
|
220
|
-
// Rotate segment if needed
|
|
221
212
|
if (taskState.currentSegLines >= MAX_JOURNAL_SEGMENT_ENTRIES ||
|
|
222
213
|
taskState.currentSegBytes + lineBytes >= MAX_JOURNAL_SEGMENT_BYTES) {
|
|
223
214
|
meta.activeSegmentIndex++;
|
|
@@ -226,13 +217,11 @@ export function createTaskJournalManager(baseDir) {
|
|
|
226
217
|
taskState.currentSegLines = 0;
|
|
227
218
|
}
|
|
228
219
|
const segPath = join(dir, segmentFileName(meta.activeSegmentIndex));
|
|
229
|
-
// Direct non-blocking append to file, no full segment rewrite
|
|
230
220
|
await appendFile(segPath, line, "utf8");
|
|
231
221
|
taskState.currentSegBytes += lineBytes;
|
|
232
222
|
taskState.currentSegLines++;
|
|
233
223
|
meta.totalEvents++;
|
|
234
224
|
meta.updatedAt = now;
|
|
235
|
-
// Segment bound pruning
|
|
236
225
|
if (meta.segmentCount > MAX_JOURNAL_RETAINED_SEGMENTS) {
|
|
237
226
|
const files = (await readdir(dir)).filter((f) => f.startsWith("segment-") && f.endsWith(".jsonl")).sort();
|
|
238
227
|
if (files.length > MAX_JOURNAL_RETAINED_SEGMENTS) {
|
|
@@ -243,9 +232,7 @@ export function createTaskJournalManager(baseDir) {
|
|
|
243
232
|
meta.droppedCount += oldLines.length;
|
|
244
233
|
await unlink(join(dir, f));
|
|
245
234
|
}
|
|
246
|
-
catch {
|
|
247
|
-
// ignore
|
|
248
|
-
}
|
|
235
|
+
catch { }
|
|
249
236
|
}
|
|
250
237
|
meta.truncated = true;
|
|
251
238
|
const remaining = (await readdir(dir))
|
|
@@ -259,13 +246,10 @@ export function createTaskJournalManager(baseDir) {
|
|
|
259
246
|
meta.minRetainedSequence = parsed.sequence;
|
|
260
247
|
}
|
|
261
248
|
}
|
|
262
|
-
catch {
|
|
263
|
-
// ignore
|
|
264
|
-
}
|
|
249
|
+
catch { }
|
|
265
250
|
}
|
|
266
251
|
}
|
|
267
252
|
}
|
|
268
|
-
// Asynchronous metadata atomic write
|
|
269
253
|
await writeAtomicAsync(join(dir, "meta.json"), JSON.stringify(meta, null, 2));
|
|
270
254
|
return entry;
|
|
271
255
|
});
|
|
@@ -323,7 +307,6 @@ export function createTaskJournalManager(baseDir) {
|
|
|
323
307
|
};
|
|
324
308
|
}
|
|
325
309
|
}
|
|
326
|
-
// Read retained segment entries asynchronously
|
|
327
310
|
const files = (await readdir(dir)).filter((f) => f.startsWith("segment-") && f.endsWith(".jsonl")).sort();
|
|
328
311
|
const allEntries = [];
|
|
329
312
|
let corrupted = false;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { parseReportMetadata } from "./report-metadata.js";
|
|
3
|
+
import { deviceTaskFailure } from "./task-error.js";
|
|
4
|
+
import { boundTaskReport } from "./task-report.js";
|
|
5
|
+
import { validateDeviceArtifact } from "./work-contract.js";
|
|
6
|
+
export const TASK_OUTCOME_ERROR_BYTES = 4 * 1024;
|
|
7
|
+
export function deepFreeze(obj) {
|
|
8
|
+
if (obj === null || typeof obj !== "object" || Object.isFrozen(obj))
|
|
9
|
+
return obj;
|
|
10
|
+
Object.freeze(obj);
|
|
11
|
+
for (const key of Object.keys(obj)) {
|
|
12
|
+
deepFreeze(obj[key]);
|
|
13
|
+
}
|
|
14
|
+
return obj;
|
|
15
|
+
}
|
|
16
|
+
export function computeOutcomeFingerprint(taskId, attemptId, status, report, error, reportMetadata, artifactDigest, executionCompleted, artifactProduced) {
|
|
17
|
+
const hasProofOrArtifact = artifactDigest !== undefined || executionCompleted !== undefined || artifactProduced !== undefined;
|
|
18
|
+
const payload = [
|
|
19
|
+
taskId,
|
|
20
|
+
attemptId,
|
|
21
|
+
status,
|
|
22
|
+
report ?? "",
|
|
23
|
+
error ?? "",
|
|
24
|
+
reportMetadata === undefined ? null : parseReportMetadata(reportMetadata),
|
|
25
|
+
...(hasProofOrArtifact ? [artifactDigest ?? null, executionCompleted ?? null, artifactProduced ?? null] : []),
|
|
26
|
+
];
|
|
27
|
+
return createHash("sha256").update(JSON.stringify(payload)).digest("hex").slice(0, 16);
|
|
28
|
+
}
|
|
29
|
+
export function computeLegacyOutcomeFingerprint(taskId, attemptId, status, report, error, reportMetadata) {
|
|
30
|
+
return createHash("sha256")
|
|
31
|
+
.update(`${taskId}:${attemptId}:${status}:${report ?? ""}:${error ?? ""}${reportMetadata ? JSON.stringify(reportMetadata) : ""}`)
|
|
32
|
+
.digest("hex")
|
|
33
|
+
.slice(0, 16);
|
|
34
|
+
}
|
|
35
|
+
export function normalizeTaskOutcome(taskId, attemptId, outcome) {
|
|
36
|
+
const safeReport = outcome.report ? boundTaskReport(outcome.report) : undefined;
|
|
37
|
+
const safeError = outcome.error
|
|
38
|
+
? boundTaskReport(deviceTaskFailure(outcome.error), TASK_OUTCOME_ERROR_BYTES)
|
|
39
|
+
: undefined;
|
|
40
|
+
const reportMetadata = outcome.reportMetadata === undefined ? undefined : parseReportMetadata(outcome.reportMetadata);
|
|
41
|
+
let validArtifact;
|
|
42
|
+
if (outcome.artifact !== undefined) {
|
|
43
|
+
const res = validateDeviceArtifact(outcome.artifact);
|
|
44
|
+
if (!res.valid) {
|
|
45
|
+
throw new Error(`Invalid device artifact: ${res.reason}`);
|
|
46
|
+
}
|
|
47
|
+
validArtifact = deepFreeze(structuredClone(res.artifact));
|
|
48
|
+
}
|
|
49
|
+
if (outcome.executionCompleted !== undefined && typeof outcome.executionCompleted !== "boolean") {
|
|
50
|
+
throw new Error("Execution proof 'executionCompleted' must be a boolean when present");
|
|
51
|
+
}
|
|
52
|
+
if (outcome.artifactProduced !== undefined && typeof outcome.artifactProduced !== "boolean") {
|
|
53
|
+
throw new Error("Artifact proof 'artifactProduced' must be a boolean when present");
|
|
54
|
+
}
|
|
55
|
+
const executionCompleted = outcome.executionCompleted;
|
|
56
|
+
const artifactProduced = outcome.artifactProduced;
|
|
57
|
+
const fingerprint = computeOutcomeFingerprint(taskId, attemptId, outcome.status, safeReport, safeError, reportMetadata, validArtifact?.digest, executionCompleted, artifactProduced);
|
|
58
|
+
return {
|
|
59
|
+
status: outcome.status,
|
|
60
|
+
report: safeReport,
|
|
61
|
+
error: safeError,
|
|
62
|
+
reportMetadata,
|
|
63
|
+
artifact: validArtifact,
|
|
64
|
+
executionCompleted,
|
|
65
|
+
artifactProduced,
|
|
66
|
+
fingerprint,
|
|
67
|
+
};
|
|
68
|
+
}
|