pi-web-ui 0.117.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 +48 -2
- 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 +147 -43
- 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 +56 -444
- 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 +160 -374
- package/dist/server/agent-service.js +875 -2978
- 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 +26 -30
- 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 +6 -213
- 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 +3 -76
- 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 +0 -82
- 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 +0 -8
- 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 +1 -3
- package/dist/server/device-center/collab-tool.js +0 -10
- package/dist/server/device-center/connector.js +21 -11
- package/dist/server/device-center/delivery-authority.js +0 -3
- package/dist/server/device-center/delivery-subject.js +0 -1
- 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 +1 -27
- 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 +0 -1
- 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 +0 -27
- 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 +0 -12
- package/dist/server/device-center/hub-deliveries.js +0 -1
- package/dist/server/device-center/hub-integration.js +0 -8
- 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 +25 -7
- package/dist/server/device-center/hub-setup.js +0 -6
- package/dist/server/device-center/hub-transaction-log.js +0 -22
- 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 +210 -86
- 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 +0 -2
- package/dist/server/device-center/local-hub.js +0 -2
- package/dist/server/device-center/local-publication.js +1 -8
- package/dist/server/device-center/local-verification-job.js +0 -2
- package/dist/server/device-center/local-verification.js +0 -1
- package/dist/server/device-center/local.js +267 -39
- package/dist/server/device-center/main.js +14 -1
- 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 +0 -31
- package/dist/server/device-center/path-portal.js +42 -12
- package/dist/server/device-center/publication-journal.js +0 -7
- package/dist/server/device-center/publish-intent.js +0 -5
- package/dist/server/device-center/relay.js +85 -30
- package/dist/server/device-center/report-upload.js +0 -1
- package/dist/server/device-center/runtime.js +1 -18
- package/dist/server/device-center/store.js +13 -33
- 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 +0 -13
- 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 +5 -88
- 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 +0 -18
- package/dist/server/device-center/task-state.js +0 -12
- package/dist/server/device-center/task-workspace.js +0 -50
- 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 +0 -1
- package/dist/server/device-center/work-contract.js +1 -73
- 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 +190 -32
- package/dist/server/dispatch-plugin-handlers.js +2 -19
- package/dist/server/dsh/dsh-agent-service.js +69 -599
- 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 +177 -680
- 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 +3 -43
- package/dist/server/patch-remote-catalog.js +1 -32
- 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 +9 -62
- package/dist/server/preset-plugin-dependencies.js +0 -2
- package/dist/server/preset-share.js +3 -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 +34 -1
- package/dist/server/quick-ask.js +123 -27
- 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 +0 -26
- 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 +3 -54
- 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 +17 -25
- package/dist/server/session-open.js +2 -26
- package/dist/server/session-parser.js +1 -55
- package/dist/server/session-scan.js +1 -17
- package/dist/server/session-search.js +0 -56
- package/dist/server/settings-service.js +11 -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 +0 -42
- 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 +1 -19
- 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 +12 -172
- 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 +26 -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 +1 -56
- 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 +37 -1
- package/docs/device-center.md +28 -2
- 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 +7 -3
- package/plugin-sdk/README.md +6 -0
- package/plugin-sdk/client-utils.mjs +0 -7
- package/plugin-sdk/client.d.ts +0 -1
- package/plugin-sdk/client.mjs +1 -31
- package/plugin-sdk/import-check.mjs +4 -51
- package/plugin-sdk/index.d.ts +120 -119
- package/plugin-sdk/index.mjs +0 -6
- package/plugin-sdk/ssh-host-trust.mjs +0 -12
- package/plugin-sdk/testing.d.ts +0 -1
- package/plugin-sdk/testing.mjs +31 -86
- 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 +1 -9
- package/themes/flow-ink.css +1 -10
- package/themes/flow-light.css +1 -10
- package/themes/flow-obsidian.css +1 -10
- package/themes/flow-zurich.css +1 -10
- 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-BjNRIUIc.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-CQtstPGv.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-ChTW8o1m.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-BX5rUuoI.js → PiSetupModal-DZKY5Wiw.js} +1 -1
- package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +1 -0
- package/web/dist/assets/{SCMPanel-DPAyY2sW.js → SCMPanel-CuEgzAlO.js} +2 -2
- 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-Dzi-eEyE.js → remote-ssh-client-Cdf-cTUe.js} +1 -1
- package/web/dist/assets/theme-DGL7hLUs.js +1 -0
- package/web/dist/index.html +11 -10
- package/web/dist/sw.js +15 -61
- package/web/public/sw.js +14 -60
- package/web/dist/assets/BgTasksModal-C0zuU8FE.js +0 -1
- package/web/dist/assets/CanvasStudio-BWvdmJ0M.js +0 -1579
- package/web/dist/assets/CanvasStudio-VQFjmTGq.js +0 -1579
- package/web/dist/assets/DeviceCenter-DI9_0aBB.js +0 -3
- package/web/dist/assets/DeviceCenter-DsNtXqzY.js +0 -3
- package/web/dist/assets/DeviceExecutionSettings-BLP1Su5G.js +0 -1
- package/web/dist/assets/DeviceGroups-2Pvk0Cds.js +0 -1
- package/web/dist/assets/DeviceGroups-CP7CcyPD.js +0 -1
- package/web/dist/assets/FilePreview-BMB2tNyT.js +0 -2
- package/web/dist/assets/FilePreview-RGFQUbJo.js +0 -2
- package/web/dist/assets/GlobalSearchModal-BM5wxiqU.js +0 -1
- package/web/dist/assets/GlobalSearchModal-DGv_WINq.js +0 -1
- package/web/dist/assets/GroupConversation-B7SnuXj1.js +0 -61
- package/web/dist/assets/GroupConversation-Dda69q-2.js +0 -61
- package/web/dist/assets/ModelConfigModal-C-0Z4hUZ.js +0 -2
- package/web/dist/assets/ModelConfigModal-yqeadyab.js +0 -2
- package/web/dist/assets/ProviderOAuthControls-DY4SCfXg.js +0 -1
- package/web/dist/assets/SCMPanel-C4KbQvvK.js +0 -2
- package/web/dist/assets/SettingsModal-DxZp6D_g.js +0 -32
- package/web/dist/assets/SettingsModal-WhQzaOPt.js +0 -32
- package/web/dist/assets/TerminalPanel-D4By_RVc.js +0 -3
- package/web/dist/assets/TerminalPanel-lZw8-i3j.js +0 -3
- package/web/dist/assets/TuiOverlayModal-C3pAVuC8.js +0 -1
- package/web/dist/assets/TuiOverlayModal-D7_rEXcJ.js +0 -1
- package/web/dist/assets/app-globals-KqOVtmp1.js +0 -123
- package/web/dist/assets/canvas-client-BY6ojmle.js +0 -1
- package/web/dist/assets/desktop-CV6KKp9R.js +0 -1
- package/web/dist/assets/index-BawF7ZP5.js +0 -397
- package/web/dist/assets/index-BoGCoq5X.js +0 -397
- package/web/dist/assets/index-CVW9FoY2.css +0 -1
- package/web/dist/assets/plugin-host-Dn8Dd6SC.js +0 -1
- package/web/dist/assets/theme-D_bihpdN.js +0 -1
package/dist/server/serialize.js
CHANGED
|
@@ -4,27 +4,9 @@ import { stripMarkers } from "./markers/index.js";
|
|
|
4
4
|
export const TEXT_CAP = 200_000;
|
|
5
5
|
export const TOOL_OUTPUT_CAP = 100_000;
|
|
6
6
|
export const ARGS_CAP = 200_000;
|
|
7
|
-
/**
|
|
8
|
-
* toolResult 里单张图片进快照的上限(dataUrl 字符数 ≈ 1.5MB 二进制)。
|
|
9
|
-
* 视口/元素截图随便过;超大整页截图回落成占位文本(模型侧不受影响 —— 图它
|
|
10
|
-
* 已经看过,只是浏览器这边的缩略图不带)。超限截断 base64 会得到一张坏图,
|
|
11
|
-
* 所以是整张丢、不是截一半。
|
|
12
|
-
*/
|
|
13
7
|
const TOOL_RESULT_IMAGE_CAP = 2_000_000;
|
|
14
|
-
/** 单条 toolResult 最多带几张图进快照(防图片刷屏把快照撑爆)。 */
|
|
15
8
|
const TOOL_RESULT_IMAGE_MAX = 8;
|
|
16
|
-
/**
|
|
17
|
-
* toolResult.details 的体积上限。details 是给 UI 用的结构化元数据(如
|
|
18
|
-
* present_files 的卡片数据、ask_user_question 的答案),快照每 60ms 推一次,
|
|
19
|
-
* 不能无节制。超过上限时**整个丢掉**(而不是截断 —— 截断后的 JSON 不可解析,
|
|
20
|
-
* 前端还得写容错);工具作者应自己封顶(见 present-files-tool.ts 的摘录预算)。
|
|
21
|
-
*/
|
|
22
9
|
const TOOL_DETAILS_CAP = 64_000;
|
|
23
|
-
/**
|
|
24
|
-
* 对带有嵌套调用列表(如 codemode 的 details.calls)的 details 做安全预算裁剪。
|
|
25
|
-
* 当 JSON 体积超过 TOOL_DETAILS_CAP(64KB)时,不直接丢弃整包,而是保留首尾
|
|
26
|
-
* 关键调用并精简单项 args/error 长度,保证 UI 仍能渲染出调用树。
|
|
27
|
-
*/
|
|
28
10
|
export function pruneCallsDetails(details, cap) {
|
|
29
11
|
const rawCalls = details.calls;
|
|
30
12
|
if (!Array.isArray(rawCalls))
|
|
@@ -88,13 +70,6 @@ export function truncate(s, cap) {
|
|
|
88
70
|
return { text: str, truncated: false };
|
|
89
71
|
return { text: `${str.slice(0, cap)}\n\n… [truncated]`, truncated: true };
|
|
90
72
|
}
|
|
91
|
-
/**
|
|
92
|
-
* SDK/工具的图片块 → 前端可直接 <img> 的 UiImageBlock。
|
|
93
|
-
* Canonical ImageContent shape is { type, data, mimeType }; tolerate the
|
|
94
|
-
* legacy { source } wrapper too.
|
|
95
|
-
* cap: dataUrl 超过该字符数回 undefined(调用方按占位文本处理);默认不限
|
|
96
|
-
* (用户粘贴图走 image-paste 的缩放管线,尺寸本来就有界)。
|
|
97
|
-
*/
|
|
98
73
|
function imageBlockToUi(b, cap = Number.POSITIVE_INFINITY) {
|
|
99
74
|
const img = b;
|
|
100
75
|
const src = img.source;
|
|
@@ -152,9 +127,6 @@ function serializeAssistantContent(content, streaming = false) {
|
|
|
152
127
|
return { type: "text", text, truncated };
|
|
153
128
|
}
|
|
154
129
|
if (b.type === "thinking") {
|
|
155
|
-
// thinking 也走 TEXT_CAP:思维链没有长度保证(长任务能刷出远超正文的
|
|
156
|
-
// 体量),不截断会把快照推送撑爆。UiThinkingBlock 没有 truncated 字段
|
|
157
|
-
// (protocol 不动),截断语义靠 truncate 自带的 "… [truncated]" 尾标。
|
|
158
130
|
const { text } = truncate(b.thinking, TEXT_CAP);
|
|
159
131
|
return { type: "thinking", thinking: text };
|
|
160
132
|
}
|
|
@@ -174,17 +146,6 @@ function serializeAssistantContent(content, streaming = false) {
|
|
|
174
146
|
return { type: "unknown", ...b };
|
|
175
147
|
});
|
|
176
148
|
}
|
|
177
|
-
/**
|
|
178
|
-
* Hide transient LLM failures while an auto-retry is pending.
|
|
179
|
-
*
|
|
180
|
-
* The SDK finalizes the failed assistant message (message_end, then agent_end
|
|
181
|
-
* with willRetry) BEFORE it slices the message out of state and backs off, so
|
|
182
|
-
* a snapshot taken in between would paint a red error that vanishes one frame
|
|
183
|
-
* later. While `retryActive` the trailing stopReason=error assistant messages
|
|
184
|
-
* are intermediate state: dropped here (retry success → the user never sees
|
|
185
|
-
* them; exhaustion → auto_retry_end clears the flag and the message renders
|
|
186
|
-
* red permanently). Non-trailing content is never touched.
|
|
187
|
-
*/
|
|
188
149
|
export function stripTransientRetryErrors(messages, retryActive) {
|
|
189
150
|
if (!retryActive)
|
|
190
151
|
return messages;
|
|
@@ -198,12 +159,6 @@ export function stripTransientRetryErrors(messages, retryActive) {
|
|
|
198
159
|
}
|
|
199
160
|
return end === messages.length ? messages : messages.slice(0, end);
|
|
200
161
|
}
|
|
201
|
-
/**
|
|
202
|
-
* Single source for rendered message ids. Both serializeMessage (下发) and
|
|
203
|
-
* resolveMessageEntry (解析) must derive ids through this function — recomputing
|
|
204
|
-
* the format anywhere else is how the two sides drifted apart and fork/rollback
|
|
205
|
-
* on assistant bubbles stopped resolving (issue #381).
|
|
206
|
-
*/
|
|
207
162
|
export function uiMessageId(m, seq) {
|
|
208
163
|
switch (m.role) {
|
|
209
164
|
case "user":
|
|
@@ -224,13 +179,6 @@ export function uiMessageId(m, seq) {
|
|
|
224
179
|
return `x-${seq}`;
|
|
225
180
|
}
|
|
226
181
|
}
|
|
227
|
-
/**
|
|
228
|
-
* Find the session entry a rendered message id points at, by re-deriving each
|
|
229
|
-
* entry's rendered id through uiMessageId() — the same function serializeMessage
|
|
230
|
-
* used to hand ids to the browser. `seqOf` supplies the per-message seq; the
|
|
231
|
-
* caller injects its counter there (agent-service passes uiMessageKey().n, which
|
|
232
|
-
* is exactly the counter serialization drew from — issue #381).
|
|
233
|
-
*/
|
|
234
182
|
export function findEntryByUiId(entries, messageId, seqOf) {
|
|
235
183
|
const userSeqByTs = new Map();
|
|
236
184
|
for (const entry of entries) {
|
|
@@ -240,8 +188,6 @@ export function findEntryByUiId(entries, messageId, seqOf) {
|
|
|
240
188
|
const m = entry.message;
|
|
241
189
|
let seq;
|
|
242
190
|
if (m.role === "user") {
|
|
243
|
-
// User ids count messages sharing a timestamp — mirrors the
|
|
244
|
-
// special-case in serializeCachedFor() (see its comment).
|
|
245
191
|
const ts = m.timestamp ?? 0;
|
|
246
192
|
seq = (userSeqByTs.get(ts) ?? 0) + 1;
|
|
247
193
|
userSeqByTs.set(ts, seq);
|
|
@@ -253,9 +199,6 @@ export function findEntryByUiId(entries, messageId, seqOf) {
|
|
|
253
199
|
return entry;
|
|
254
200
|
}
|
|
255
201
|
else if (entry.type === "custom_message" && entry.display !== false) {
|
|
256
|
-
// Custom messages carry content/timestamp on the entry itself (no
|
|
257
|
-
// message object); rebuild the shape uiMessageId()/seqOf() key on —
|
|
258
|
-
// the same conversion createCustomMessage() uses on reload.
|
|
259
202
|
const m = {
|
|
260
203
|
role: "custom",
|
|
261
204
|
content: entry.content,
|
|
@@ -292,13 +235,6 @@ function serializeAssistantMessage(m, id, streaming = false) {
|
|
|
292
235
|
};
|
|
293
236
|
}
|
|
294
237
|
export function serializeMessage(m, seq) {
|
|
295
|
-
// SDK 的 system 消息是 prompt sections 的内部差量
|
|
296
|
-
// (content 空串 + sections 结构化内存)、compaction 的
|
|
297
|
-
// systemMessage 等——从来不面向用户。不过滤的话
|
|
298
|
-
// 会掉进 default 分支被序列化成 content: []
|
|
299
|
-
// 的空气泡、前端顶着 system 标题白显示一条
|
|
300
|
-
// (对话结束后底部冒出的空 SYSTEM 气泡就是它)。
|
|
301
|
-
// LLM 上下文不受影响——这里只决定浏览器看到什么。
|
|
302
238
|
if (m.role === "system") {
|
|
303
239
|
return null;
|
|
304
240
|
}
|
|
@@ -333,9 +269,6 @@ export function serializeMessage(m, seq) {
|
|
|
333
269
|
case "assistant":
|
|
334
270
|
return serializeAssistantMessage(m, id);
|
|
335
271
|
case "toolResult": {
|
|
336
|
-
// 工具结果里的图片(web_shot 截图、read 读到的图……)要下发浏览器:
|
|
337
|
-
// 卡片里直接显示缩略图、点开放大(见 ToolCallBlock)。以前这里统一丢成
|
|
338
|
-
// "[image result]",用户只能看到占位文本。超限/超数的图仍回落占位文本。
|
|
339
272
|
const textParts = [];
|
|
340
273
|
let textLength = 0;
|
|
341
274
|
let hasTextPart = false;
|
|
@@ -356,7 +289,6 @@ export function serializeMessage(m, seq) {
|
|
|
356
289
|
}
|
|
357
290
|
};
|
|
358
291
|
const appendText = (part) => {
|
|
359
|
-
// Empty parts still contribute join separators, even at the cap.
|
|
360
292
|
if (hasTextPart)
|
|
361
293
|
appendChunk("\n");
|
|
362
294
|
hasTextPart = true;
|
|
@@ -389,9 +321,6 @@ export function serializeMessage(m, seq) {
|
|
|
389
321
|
isError: m.isError,
|
|
390
322
|
timestamp: m.timestamp,
|
|
391
323
|
};
|
|
392
|
-
// 结构化元数据(tool result details)也要下发:present_files 的预览卡片
|
|
393
|
-
// 就靠它拿 kind/size/excerpt(前端不能靠再打一次 HTTP 才知类型),
|
|
394
|
-
// ask_user_question 同理。体积封顶,超限整丢(见 TOOL_DETAILS_CAP)。
|
|
395
324
|
if (m.details !== undefined) {
|
|
396
325
|
try {
|
|
397
326
|
const json = JSON.stringify(m.details);
|
|
@@ -404,9 +333,7 @@ export function serializeMessage(m, seq) {
|
|
|
404
333
|
msg.details = pruned;
|
|
405
334
|
}
|
|
406
335
|
}
|
|
407
|
-
catch {
|
|
408
|
-
// 循环引用等序列化不了的值:details 是附加信息,丢掉不影响消息本体。
|
|
409
|
-
}
|
|
336
|
+
catch { }
|
|
410
337
|
}
|
|
411
338
|
return msg;
|
|
412
339
|
}
|
|
@@ -429,8 +356,6 @@ export function serializeMessage(m, seq) {
|
|
|
429
356
|
};
|
|
430
357
|
}
|
|
431
358
|
case "custom": {
|
|
432
|
-
// Third-party extension messages with display:false are UI-hidden
|
|
433
|
-
// (they still go into LLM context — the SDK handles that).
|
|
434
359
|
if (m.display === false) {
|
|
435
360
|
return null;
|
|
436
361
|
}
|
|
@@ -442,18 +367,13 @@ export function serializeMessage(m, seq) {
|
|
|
442
367
|
customType: m.customType,
|
|
443
368
|
timestamp: m.timestamp,
|
|
444
369
|
};
|
|
445
|
-
// custom details 与 toolResult 的 details 同一闸门(TOOL_DETAILS_CAP):
|
|
446
|
-
// details 随每 60ms 一发的快照推送,扩展塞进来的大对象不能无节制;
|
|
447
|
-
// 超限/序列化失败整丢(截断后的 JSON 不可解析,前端还得写容错)。
|
|
448
370
|
const rawDetails = m.details;
|
|
449
371
|
if (rawDetails !== undefined) {
|
|
450
372
|
try {
|
|
451
373
|
if (JSON.stringify(rawDetails).length <= TOOL_DETAILS_CAP)
|
|
452
374
|
msg.details = rawDetails;
|
|
453
375
|
}
|
|
454
|
-
catch {
|
|
455
|
-
// 循环引用等序列化不了的值:details 是附加信息,丢掉不影响消息本体。
|
|
456
|
-
}
|
|
376
|
+
catch { }
|
|
457
377
|
}
|
|
458
378
|
return msg;
|
|
459
379
|
}
|
|
@@ -485,18 +405,8 @@ export function serializeMessage(m, seq) {
|
|
|
485
405
|
};
|
|
486
406
|
}
|
|
487
407
|
}
|
|
488
|
-
/**
|
|
489
|
-
* Serialize the in-progress assistant message (agent.state.streamingMessage).
|
|
490
|
-
*
|
|
491
|
-
* Unlike persisted messages, the id must be STABLE across snapshots: the SDK
|
|
492
|
-
* replaces the partial object on every stream event, so a seq-based id would
|
|
493
|
-
* remount the React component (and collapse open thinking/tool blocks) every
|
|
494
|
-
* 60ms. The timestamp is fixed at message creation, so `stream-<ts>` stays
|
|
495
|
-
* constant for the whole stream.
|
|
496
|
-
*/
|
|
497
408
|
export function serializeStreamingMessage(m) {
|
|
498
409
|
const id = `stream-${m.timestamp ?? 0}`;
|
|
499
|
-
// Streamed assistant blocks must be converted only once per snapshot.
|
|
500
410
|
if (m.role === "assistant")
|
|
501
411
|
return serializeAssistantMessage(m, id, true);
|
|
502
412
|
const msg = serializeMessage(m, 0);
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 本地配置页的持久化后端。
|
|
3
|
-
*
|
|
4
|
-
* `GET /setup` 与 `/api/setup/*` 只允许回环地址访问(见 isLoopbackAddress),
|
|
5
|
-
* 因此忘记 token 也能进——这正是它的存在意义。配置落在
|
|
6
|
-
* `<dataDir>/server-config.json`,优先级:命令行旗标 > 环境变量 > 本文件 > 默认值。
|
|
7
|
-
* 改 host/port/allowlist 需要重启服务生效;token 支持热旋转(index.ts 里 AUTH_TOKEN 是 let)。
|
|
8
|
-
*/
|
|
9
1
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
10
2
|
import { join } from "node:path";
|
|
11
3
|
const FILE_NAME = "server-config.json";
|
|
@@ -42,7 +34,6 @@ export function saveServerFileConfig(dataDir, cfg) {
|
|
|
42
34
|
mkdirSync(dataDir, { recursive: true });
|
|
43
35
|
writeFileSync(configFilePath(dataDir), `${JSON.stringify(cfg, null, "\t")}\n`, "utf8");
|
|
44
36
|
}
|
|
45
|
-
/** 回环判定:IPv4 127/8、IPv6 ::1(含 IPv4 映射)都算本地。 */
|
|
46
37
|
export function isLoopbackAddress(remoteAddress) {
|
|
47
38
|
if (!remoteAddress)
|
|
48
39
|
return false;
|
|
@@ -51,12 +42,10 @@ export function isLoopbackAddress(remoteAddress) {
|
|
|
51
42
|
return true;
|
|
52
43
|
if (ip === "127.0.0.1" || ip.startsWith("127."))
|
|
53
44
|
return true;
|
|
54
|
-
// ::ffff:127.x.x.x 映射形
|
|
55
45
|
if (ip.startsWith("::ffff:127."))
|
|
56
46
|
return true;
|
|
57
47
|
return false;
|
|
58
48
|
}
|
|
59
|
-
/** token 强度小建议(不硬拦,只提示):空=不清/不设,短于 8 字符警告。 */
|
|
60
49
|
export function tokenWarning(token) {
|
|
61
50
|
if (!token)
|
|
62
51
|
return "";
|
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session branch evaluation, leaf calibration, and transcript topological reordering.
|
|
3
|
-
*
|
|
4
|
-
* Background (issue #567):
|
|
5
|
-
* When multiple devices access the same session, or when extensions append metadata
|
|
6
|
-
* (e.g. type: "custom" such as plannotator entries) pointing to an older ancestor node,
|
|
7
|
-
* the appended entries appear at the physical tail of the JSONL file.
|
|
8
|
-
*
|
|
9
|
-
* In the SDK's SessionManager._buildIndex():
|
|
10
|
-
* for (const entry of this.fileEntries) {
|
|
11
|
-
* if (entry.type === "session") continue;
|
|
12
|
-
* this.byId.set(entry.id, entry);
|
|
13
|
-
* this.leafId = entry.id; // file tail becomes the active leaf!
|
|
14
|
-
* }
|
|
15
|
-
*
|
|
16
|
-
* If metadata was appended to an older branch (e.g. node 292 while the main branch
|
|
17
|
-
* continued to 557), reopening the session or restarting the backend will restore
|
|
18
|
-
* the older branch (292), making later task history (293..557) invisible even though
|
|
19
|
-
* it is still safely stored in the JSONL file.
|
|
20
|
-
*
|
|
21
|
-
* This module provides:
|
|
22
|
-
* 1. selectBestSessionLeaf: Evaluates branch candidates by message count, freshness,
|
|
23
|
-
* and depth, detecting metadata-only hijacking or stale branch reversion.
|
|
24
|
-
* 2. calibrateSessionLeaf: In-memory leaf calibration for any SessionManager instance.
|
|
25
|
-
* 3. reorderEntriesForMainBranch: Topological reordering of session entries to ensure
|
|
26
|
-
* the active main branch leaf resides at the physical tail of the transcript file
|
|
27
|
-
* without losing or modifying any custom/metadata entries.
|
|
28
|
-
*/
|
|
29
1
|
function parseEntryTimestamp(ts) {
|
|
30
2
|
if (typeof ts === "string") {
|
|
31
3
|
const parsed = Date.parse(ts);
|
|
@@ -37,9 +9,6 @@ function parseEntryTimestamp(ts) {
|
|
|
37
9
|
}
|
|
38
10
|
return 0;
|
|
39
11
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Identify all branch leaves and compute branch metrics (from root to leaf).
|
|
42
|
-
*/
|
|
43
12
|
export function findBranchCandidates(entries) {
|
|
44
13
|
const validEntries = [];
|
|
45
14
|
const byId = new Map();
|
|
@@ -68,9 +37,6 @@ export function findBranchCandidates(entries) {
|
|
|
68
37
|
if (leaves.length === 0)
|
|
69
38
|
return [];
|
|
70
39
|
const candidates = [];
|
|
71
|
-
// Shared ancestors are visited for every leaf. Cache by object (not ID, which
|
|
72
|
-
// may be duplicated), and only for this call so later entry edits stay visible.
|
|
73
|
-
// Path traversal and pathIds output still cost the sum of all branch depths.
|
|
74
40
|
const timestamps = new WeakMap();
|
|
75
41
|
const timestampOf = (entry) => {
|
|
76
42
|
const cached = timestamps.get(entry);
|
|
@@ -91,7 +57,7 @@ export function findBranchCandidates(entries) {
|
|
|
91
57
|
path.push(node);
|
|
92
58
|
cur = typeof node.parentId === "string" ? node.parentId : null;
|
|
93
59
|
}
|
|
94
|
-
path.reverse();
|
|
60
|
+
path.reverse();
|
|
95
61
|
let messageCount = 0;
|
|
96
62
|
let lastMessageTimestamp = 0;
|
|
97
63
|
for (const node of path) {
|
|
@@ -116,9 +82,6 @@ export function findBranchCandidates(entries) {
|
|
|
116
82
|
}
|
|
117
83
|
return candidates;
|
|
118
84
|
}
|
|
119
|
-
/**
|
|
120
|
-
* Find the lowest common ancestor (LCA) entry ID of two branches.
|
|
121
|
-
*/
|
|
122
85
|
function findLowestCommonAncestor(branchA, branchB) {
|
|
123
86
|
const setA = new Set(branchA.pathIds);
|
|
124
87
|
let lca = null;
|
|
@@ -132,20 +95,10 @@ function findLowestCommonAncestor(branchA, branchB) {
|
|
|
132
95
|
}
|
|
133
96
|
return lca;
|
|
134
97
|
}
|
|
135
|
-
/**
|
|
136
|
-
* Select the best branch leaf from all branch candidates.
|
|
137
|
-
*
|
|
138
|
-
* If multiple leaves exist, compares the currently selected leaf against the candidate
|
|
139
|
-
* pool. If the current leaf is on an abandoned metadata-only branch (e.g. extension
|
|
140
|
-
* wrote to an older node after a completed task) or significantly lags behind the main
|
|
141
|
-
* conversation in message count, selects the main branch leaf.
|
|
142
|
-
*/
|
|
143
98
|
export function selectBestSessionLeaf(entries, currentLeafId) {
|
|
144
99
|
let candidates = findBranchCandidates(entries);
|
|
145
100
|
if (candidates.length === 0)
|
|
146
101
|
return null;
|
|
147
|
-
// An edit/reask explicitly discards the later history in this same file.
|
|
148
|
-
// Honor the latest durable selection, even when abandoned history is longer.
|
|
149
102
|
const reask = [...entries]
|
|
150
103
|
.reverse()
|
|
151
104
|
.find((entry) => entry.type === "custom" && entry.customType === "pi-web-ui:reask");
|
|
@@ -162,11 +115,6 @@ export function selectBestSessionLeaf(entries, currentLeafId) {
|
|
|
162
115
|
changed: currentLeafId !== undefined && currentLeafId !== null && currentLeafId !== single.leafId,
|
|
163
116
|
};
|
|
164
117
|
}
|
|
165
|
-
// Sort candidates by preference:
|
|
166
|
-
// 1. Message count (descending)
|
|
167
|
-
// 2. Last message timestamp (descending)
|
|
168
|
-
// 3. Total entry depth (descending)
|
|
169
|
-
// 4. Leaf timestamp (descending)
|
|
170
118
|
const sorted = [...candidates].sort((a, b) => {
|
|
171
119
|
if (b.messageCount !== a.messageCount)
|
|
172
120
|
return b.messageCount - a.messageCount;
|
|
@@ -201,7 +149,6 @@ export function selectBestSessionLeaf(entries, currentLeafId) {
|
|
|
201
149
|
changed: false,
|
|
202
150
|
};
|
|
203
151
|
}
|
|
204
|
-
// Check if current leaf is a hijacked/stale branch:
|
|
205
152
|
const lca = findLowestCommonAncestor(currentCandidate, bestCandidate);
|
|
206
153
|
const lcaIndexCurrent = lca ? currentCandidate.pathIds.indexOf(lca) : -1;
|
|
207
154
|
const currentEntriesAfterLca = lcaIndexCurrent >= 0 ? currentCandidate.pathIds.slice(lcaIndexCurrent + 1) : [];
|
|
@@ -224,9 +171,6 @@ export function selectBestSessionLeaf(entries, currentLeafId) {
|
|
|
224
171
|
if (node?.type === "message")
|
|
225
172
|
bestMessagesAfterLca += 1;
|
|
226
173
|
}
|
|
227
|
-
// Pattern A: Metadata-only branch hijacking (issue #567)
|
|
228
|
-
// Current branch has 0 messages after LCA (only custom / extension metadata),
|
|
229
|
-
// while best branch has real messages after LCA.
|
|
230
174
|
if (currentMessagesAfterLca === 0 && bestMessagesAfterLca > 0) {
|
|
231
175
|
return {
|
|
232
176
|
bestLeafId: bestCandidate.leafId,
|
|
@@ -235,7 +179,6 @@ export function selectBestSessionLeaf(entries, currentLeafId) {
|
|
|
235
179
|
reason: `Current branch has no messages after divergence (LCA=${lca}), while main branch has ${bestMessagesAfterLca} messages`,
|
|
236
180
|
};
|
|
237
181
|
}
|
|
238
|
-
// Pattern B: Substantial message gap (stale branch restored after task completed elsewhere)
|
|
239
182
|
if (bestCandidate.messageCount > currentCandidate.messageCount) {
|
|
240
183
|
return {
|
|
241
184
|
bestLeafId: bestCandidate.leafId,
|
|
@@ -244,16 +187,12 @@ export function selectBestSessionLeaf(entries, currentLeafId) {
|
|
|
244
187
|
reason: `Main branch has ${bestCandidate.messageCount} messages vs current branch's ${currentCandidate.messageCount}`,
|
|
245
188
|
};
|
|
246
189
|
}
|
|
247
|
-
// Otherwise, current branch has equal or valid intentional message history
|
|
248
190
|
return {
|
|
249
191
|
bestLeafId: currentCandidate.leafId,
|
|
250
192
|
currentLeafId,
|
|
251
193
|
changed: false,
|
|
252
194
|
};
|
|
253
195
|
}
|
|
254
|
-
/**
|
|
255
|
-
* Calibrate the active leaf of a SessionManager in memory.
|
|
256
|
-
*/
|
|
257
196
|
export function calibrateSessionLeaf(sessionManager) {
|
|
258
197
|
try {
|
|
259
198
|
const entries = sessionManager.getEntries();
|
|
@@ -274,13 +213,6 @@ export function calibrateSessionLeaf(sessionManager) {
|
|
|
274
213
|
return { changed: false, calibratedLeafId: sessionManager.getLeafId() ?? undefined, reason: String(err) };
|
|
275
214
|
}
|
|
276
215
|
}
|
|
277
|
-
/**
|
|
278
|
-
* Reorder entries topologically so that the main branch's leaf is at the tail of the transcript.
|
|
279
|
-
*
|
|
280
|
-
* Preserves all entries and valid parent-child relationships (every node still appears after
|
|
281
|
-
* its parent). Side-branch metadata attached to older nodes is placed before the main branch's
|
|
282
|
-
* continuing path so SDK SessionManager's sequential scan lands on the main branch leaf.
|
|
283
|
-
*/
|
|
284
216
|
export function reorderEntriesForMainBranch(entries) {
|
|
285
217
|
if (entries.length <= 1)
|
|
286
218
|
return { entries, changed: false };
|
|
@@ -298,10 +230,6 @@ export function reorderEntriesForMainBranch(entries) {
|
|
|
298
230
|
if (!bestCandidate)
|
|
299
231
|
return { entries, changed: false };
|
|
300
232
|
const bestPathSet = new Set(bestCandidate.pathIds);
|
|
301
|
-
// Separate entries into:
|
|
302
|
-
// 1. Header (type === "session")
|
|
303
|
-
// 2. Entries on the best path
|
|
304
|
-
// 3. Entries on side branches
|
|
305
233
|
const headerEntries = [];
|
|
306
234
|
const sideEntries = [];
|
|
307
235
|
const mainEntries = [];
|
|
@@ -316,21 +244,12 @@ export function reorderEntriesForMainBranch(entries) {
|
|
|
316
244
|
sideEntries.push(e);
|
|
317
245
|
}
|
|
318
246
|
}
|
|
319
|
-
// If no side entries exist or main entries are empty, nothing to reorder
|
|
320
247
|
if (sideEntries.length === 0 || mainEntries.length === 0) {
|
|
321
248
|
return { entries, changed: false };
|
|
322
249
|
}
|
|
323
|
-
// We want to interleave side entries after their respective parent in main entries,
|
|
324
|
-
// BUT ensure that the continuation of the main branch ends with bestCandidate.leafId.
|
|
325
|
-
// A robust topological sort:
|
|
326
|
-
// Each side entry must come after its parent.
|
|
327
|
-
// Since side branches branched off an ancestor in mainEntries, we can place side entries
|
|
328
|
-
// as early as possible (immediately after their parent) so that the deep main branch entries
|
|
329
|
-
// remain at the end of the file.
|
|
330
250
|
const result = [...headerEntries];
|
|
331
251
|
const placedIds = new Set();
|
|
332
252
|
const placedRefs = new Set(headerEntries);
|
|
333
|
-
// Helper to place a side entry and its side descendants
|
|
334
253
|
const sideChildrenOf = new Map();
|
|
335
254
|
for (const s of sideEntries) {
|
|
336
255
|
const pid = typeof s.parentId === "string" ? s.parentId : "";
|
|
@@ -377,12 +296,9 @@ export function reorderEntriesForMainBranch(entries) {
|
|
|
377
296
|
placeSideDescendants(m.id);
|
|
378
297
|
}
|
|
379
298
|
}
|
|
380
|
-
// Any dangling side entries (including valid JSON entries without an `id` field, #601)
|
|
381
|
-
// are placed before the final main entry so that ZERO transcript lines are ever dropped.
|
|
382
299
|
for (const s of sideEntries) {
|
|
383
300
|
if (!placedRefs.has(s)) {
|
|
384
301
|
markPlaced(s);
|
|
385
|
-
// Insert before the last entry (which is the best leaf)
|
|
386
302
|
if (result.length > headerEntries.length + 1) {
|
|
387
303
|
result.splice(result.length - 1, 0, s);
|
|
388
304
|
}
|
|
@@ -391,7 +307,6 @@ export function reorderEntriesForMainBranch(entries) {
|
|
|
391
307
|
}
|
|
392
308
|
}
|
|
393
309
|
}
|
|
394
|
-
// Verify that no entries were lost (#601) and the new last non-header entry with id is bestLeafId
|
|
395
310
|
if (result.length !== entries.length) {
|
|
396
311
|
return { entries, changed: false };
|
|
397
312
|
}
|
|
@@ -399,7 +314,6 @@ export function reorderEntriesForMainBranch(entries) {
|
|
|
399
314
|
const newTail = newNonHeader[newNonHeader.length - 1];
|
|
400
315
|
const successfullyReordered = newTail?.id === bestLeafId;
|
|
401
316
|
if (!successfullyReordered) {
|
|
402
|
-
// Fallback: don't alter if topological sort couldn't guarantee tail
|
|
403
317
|
return { entries, changed: false };
|
|
404
318
|
}
|
|
405
319
|
return {
|
|
@@ -1,36 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 会话列表元信息扫描(左栏历史列表用):字节级、可增量。
|
|
3
|
-
*
|
|
4
|
-
* 与 parseSessionInfoFast(列表模式)提取相同字段、同一套规则:
|
|
5
|
-
* - session 头:id / cwd / timestamp / parentSession;session_info:最后一个非空 name;
|
|
6
|
-
* - message:计数、最大 message.timestamp、第一条用户消息文本;
|
|
7
|
-
* - 已拿到 id 与首条用户消息后,超过 512 字节、且不含 "session_info" 的长行不做 JSON.parse,
|
|
8
|
-
* 只看行首判断是否 message 并取第一个数值型 "timestamp"。
|
|
9
|
-
*
|
|
10
|
-
* 相对原实现的改进:
|
|
11
|
-
* 1. 按字节读取、按换行字节切行(UTF-8 中 0x0A 不会出现在多字节序列里),长行走快路径时
|
|
12
|
-
* 完全不解码成字符串、也不经过逐字符的 base64 过滤器;
|
|
13
|
-
* 2. 增量:记录最后一个完整行之后的字节偏移与两处指纹(文件头 + 偏移前一小段)。会话文件是
|
|
14
|
-
* 追加写入的,再次扫描时若两处指纹未变,只解析新增的字节;文件被改写(链修复、截断等)
|
|
15
|
-
* 指纹不符则整份重扫。末尾未写完的半行计入本次结果但不推进偏移,下次随完整行重读。
|
|
16
|
-
*/
|
|
17
1
|
import { promises as fsPromises } from "node:fs";
|
|
18
2
|
import { setImmediate } from "node:timers/promises";
|
|
3
|
+
import { NATIVE_CLI_ENTRY, parseNativeCliMetadata } from "./native-cli.js";
|
|
19
4
|
const CHUNK_BYTES = 64 * 1024;
|
|
20
5
|
const FAST_PATH_MIN_BYTES = 512;
|
|
21
6
|
const HEAD_SIG_BYTES = 128;
|
|
22
7
|
const TAIL_SIG_BYTES = 64;
|
|
23
|
-
/** 需要完整解析的超长行先剔除内嵌 base64("data":"…"),避免把图片载荷解析成对象。 */
|
|
24
8
|
const STRIP_DATA_MIN_CHARS = 64 * 1024;
|
|
25
9
|
const DATA_VALUE_RE = /"data"\s*:\s*"(?:[^"\\]|\\.)*"/g;
|
|
26
10
|
const COLON = 0x3a;
|
|
27
11
|
const TIMESTAMP_KEY = Buffer.from('"timestamp"');
|
|
28
12
|
const SESSION_INFO_KEY = Buffer.from('"session_info"');
|
|
13
|
+
const NATIVE_CLI_KEY = Buffer.from(NATIVE_CLI_ENTRY);
|
|
29
14
|
const MESSAGE_TYPE_RE = /"type"\s*:\s*"message"/;
|
|
30
15
|
function isWs(b) {
|
|
31
16
|
return b === 0x20 || b === 0x09 || b === 0x0d || b === 0x0a;
|
|
32
17
|
}
|
|
33
|
-
/** 等价于 /"timestamp"\s*:\s*(\d{10,16})/.exec(line) 的第一个匹配,直接在字节上找。 */
|
|
34
18
|
function firstNumericTimestamp(line) {
|
|
35
19
|
let from = 0;
|
|
36
20
|
for (;;) {
|
|
@@ -74,7 +58,11 @@ function isBlank(line) {
|
|
|
74
58
|
function applyLine(line, st) {
|
|
75
59
|
if (line.length === 0 || isBlank(line))
|
|
76
60
|
return;
|
|
77
|
-
if (st.id &&
|
|
61
|
+
if (st.id &&
|
|
62
|
+
st.firstMessage &&
|
|
63
|
+
line.length > FAST_PATH_MIN_BYTES &&
|
|
64
|
+
line.indexOf(SESSION_INFO_KEY) < 0 &&
|
|
65
|
+
line.indexOf(NATIVE_CLI_KEY) < 0) {
|
|
78
66
|
const head = line.toString("utf8", 0, 140);
|
|
79
67
|
if (MESSAGE_TYPE_RE.test(head)) {
|
|
80
68
|
st.messageCount++;
|
|
@@ -108,6 +96,14 @@ function applyLine(line, st) {
|
|
|
108
96
|
if (typeof rec.name === "string" && rec.name.trim())
|
|
109
97
|
st.name = rec.name.trim();
|
|
110
98
|
}
|
|
99
|
+
else if (rec.type === "custom" && rec.customType === NATIVE_CLI_ENTRY) {
|
|
100
|
+
try {
|
|
101
|
+
st.nativeCli = parseNativeCliMetadata(rec.data);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
delete st.nativeCli;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
111
107
|
else if (rec.type === "message") {
|
|
112
108
|
st.messageCount++;
|
|
113
109
|
const msg = rec.message;
|
|
@@ -141,18 +137,15 @@ function toInfo(filePath, fileMtime, f) {
|
|
|
141
137
|
id: f.id,
|
|
142
138
|
cwd: f.cwd,
|
|
143
139
|
name: f.name,
|
|
140
|
+
...(f.nativeCli ? { nativeCli: f.nativeCli } : {}),
|
|
144
141
|
parentSessionPath: f.parentSessionPath,
|
|
145
142
|
created: new Date(f.headerTime || fileMtime),
|
|
146
143
|
modified: new Date(modified),
|
|
147
144
|
messageCount: f.messageCount,
|
|
148
|
-
firstMessage: f.firstMessage || "(no messages)",
|
|
145
|
+
firstMessage: f.firstMessage || (f.nativeCli ? "" : "(no messages)"),
|
|
149
146
|
allMessagesText: "",
|
|
150
147
|
};
|
|
151
148
|
}
|
|
152
|
-
/**
|
|
153
|
-
* 扫描会话文件的列表元信息。`prev` 为上次扫描的状态:文件只是被追加时,从上次偏移继续;
|
|
154
|
-
* 否则整份重扫。返回 null 仅在文件不可读时。
|
|
155
|
-
*/
|
|
156
149
|
export async function scanSessionListInfo(filePath, fileMtime, prev) {
|
|
157
150
|
let fh;
|
|
158
151
|
try {
|
|
@@ -206,7 +199,6 @@ export async function scanSessionListInfo(filePath, fileMtime, prev) {
|
|
|
206
199
|
headSig,
|
|
207
200
|
tailSig: await readSig(fh, committed - tailLen, tailLen),
|
|
208
201
|
};
|
|
209
|
-
// 末尾未写完的半行:计入本次结果,但不进入可续扫状态(下次随完整行重读)
|
|
210
202
|
let resultFields = fields;
|
|
211
203
|
if (pending.length > 0) {
|
|
212
204
|
resultFields = { ...fields };
|
|
@@ -1,28 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 打开历史会话的 SessionManager:异步读盘 + 分时片解析(C2)。
|
|
3
|
-
*
|
|
4
|
-
* SDK 的 `SessionManager.open` 用同步 readSync 读完整个转录并逐行 JSON.parse,大转录(数十 MB)
|
|
5
|
-
* 会把事件循环卡住数百毫秒——期间所有客户端的 WebSocket(流式输出、心跳、其他人的操作)一起停摆。
|
|
6
|
-
* 这里改为 fs.promises 异步读取,逐行解析时每 ~8ms 让出一次事件循环,再把解析好的条目交给 SDK
|
|
7
|
-
* (与 `SessionManager.open` 在超大头部时走的 preloadedFileEntries 是同一条构造路径)。
|
|
8
|
-
*
|
|
9
|
-
* 总 CPU 不变,变化的是「不再独占主线程」。
|
|
10
|
-
*
|
|
11
|
-
* SDK 的构造函数在类型上是 private:这里按其运行时签名
|
|
12
|
-
* `(cwd, sessionDir, sessionFile, persist, newSessionOptions, preloadedFileEntries)` 调用,
|
|
13
|
-
* 并在构造后核验结果(会话文件、会话 id、条目数);任何一步不符或抛错都回退到
|
|
14
|
-
* `SessionManager.open`,因此 SDK 将来改了签名也只会退回原行为,不会打开错的会话。
|
|
15
|
-
* `PI_WEB_ASYNC_SESSION_OPEN=0` 可强制使用原路径。
|
|
16
|
-
*
|
|
17
|
-
* 与 SDK `loadEntriesFromFile` 的语义对齐:空行 / 坏行跳过;首条必须是带字符串 id 的 session
|
|
18
|
-
* 头(否则交给 SDK 原路径处理报错 / 空文件语义);文件末尾缺换行时补一个 "\n"。
|
|
19
|
-
*/
|
|
20
1
|
import { promises as fsPromises } from "node:fs";
|
|
21
2
|
import { dirname, resolve } from "node:path";
|
|
22
3
|
import { setImmediate } from "node:timers/promises";
|
|
23
4
|
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
24
5
|
const SLICE_MS = 8;
|
|
25
|
-
/** 逐行解析 JSONL,每 sliceMs 让出一次事件循环。规则同 SDK parseSessionEntryLine。 */
|
|
26
6
|
export async function parseJsonlSliced(raw, sliceMs = SLICE_MS) {
|
|
27
7
|
const entries = [];
|
|
28
8
|
let start = 0;
|
|
@@ -33,11 +13,9 @@ export async function parseJsonlSliced(raw, sliceMs = SLICE_MS) {
|
|
|
33
13
|
try {
|
|
34
14
|
const v = JSON.parse(line);
|
|
35
15
|
if (v)
|
|
36
|
-
entries.push(v);
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
// Skip malformed lines(与 SDK 一致)
|
|
16
|
+
entries.push(v);
|
|
40
17
|
}
|
|
18
|
+
catch { }
|
|
41
19
|
};
|
|
42
20
|
for (;;) {
|
|
43
21
|
const nl = raw.indexOf("\n", start);
|
|
@@ -68,11 +46,9 @@ export async function openSessionManagerAsync(path) {
|
|
|
68
46
|
const { entries, tail } = await parseJsonlSliced(raw);
|
|
69
47
|
const header = entries[0];
|
|
70
48
|
if (!header || header.type !== "session" || typeof header.id !== "string") {
|
|
71
|
-
// 空文件 / 非 pi 会话:交给 SDK 原路径(初始化空文件或抛出明确错误)
|
|
72
49
|
return SessionManager.open(resolvedPath);
|
|
73
50
|
}
|
|
74
51
|
try {
|
|
75
|
-
// SDK loadEntriesFromFile:头部合法且文件末尾缺换行时先补一个(在构造前,构造可能因版本迁移重写文件)
|
|
76
52
|
if (tail)
|
|
77
53
|
await fsPromises.appendFile(resolvedPath, "\n");
|
|
78
54
|
const cwd = typeof header.cwd === "string" ? header.cwd : process.cwd();
|