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,43 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* context-budget.ts — 多级分层上下文预算裁剪(Hierarchical Context Budgeting)
|
|
3
|
-
*
|
|
4
|
-
* 借鉴 DeepSeek Harness (DSH) 的梯度裁剪策略:在触发昂贵的 LLM 全文摘要之前,
|
|
5
|
-
* 增加确定性梯度瘦身,大幅推迟全量压缩时间点,保留近期关键代码的完整细节记忆:
|
|
6
|
-
*
|
|
7
|
-
* 1. 第一级(远期工具输出裁剪):当上下文达到预警水位(例如 70%)时,自动将历史中
|
|
8
|
-
* 较早的工具巨量输出(如几千行的命令输出、超长文件读取)替换为轻量占位摘要
|
|
9
|
-
* (`[Tool output trimmed: N lines / M bytes]`),保留工具调用的元数据与首尾关键信息;
|
|
10
|
-
* 2. 第二级(已完成步骤折叠):折叠已通过的目标轮次中间调试日志;
|
|
11
|
-
* 3. 第三级(语义全量压缩):仅在前两级裁剪后依然超标时,才调用 LLM 执行深度语义压缩。
|
|
12
|
-
*
|
|
13
|
-
* 纯模块:纯函数与纯逻辑,无外部 I/O 副作用,易于单测与多端复用。
|
|
14
|
-
*/
|
|
15
1
|
import { SOFT_CAP_MIN_HEADROOM } from "./soft-cap.js";
|
|
16
|
-
/** 默认第一级触发预警水位(70%)。 */
|
|
17
2
|
export const DEFAULT_PRUNE_WATERMARK = 0.7;
|
|
18
|
-
/** 默认第二级触发预警水位(85%)。 */
|
|
19
3
|
export const DEFAULT_STAGE2_WATERMARK = 0.85;
|
|
20
|
-
/** 触发远期工具裁剪的最小行数(超过此行数视作巨量输出)。 */
|
|
21
4
|
export const DEFAULT_MIN_TRIM_LINES = 20;
|
|
22
|
-
/** 触发远期工具裁剪的最小字节数(超过此体积视作巨量输出)。 */
|
|
23
5
|
export const DEFAULT_MIN_TRIM_BYTES = 1000;
|
|
24
|
-
/** 裁剪时保留的头部行数。 */
|
|
25
6
|
export const DEFAULT_HEAD_LINES = 3;
|
|
26
|
-
/** 裁剪时保留的尾部行数。 */
|
|
27
7
|
export const DEFAULT_TAIL_LINES = 3;
|
|
28
|
-
/** 保留最近若干轮不裁剪(近期关键工作记忆保护)。1 轮通常包含 user + assistant + toolResult。 */
|
|
29
8
|
export const DEFAULT_KEEP_RECENT_TURNS = 2;
|
|
30
|
-
/**
|
|
31
|
-
* 粗略估算字符串的 token 数(chars / 4 保守估算)。
|
|
32
|
-
*/
|
|
33
9
|
export function estimateTextTokens(text) {
|
|
34
10
|
if (!text)
|
|
35
11
|
return 0;
|
|
36
12
|
return Math.ceil(text.length / 4);
|
|
37
13
|
}
|
|
38
|
-
/**
|
|
39
|
-
* 估算一条 AgentMessage 的 token 数。
|
|
40
|
-
*/
|
|
41
14
|
export function estimateMessageTokens(message) {
|
|
42
15
|
let total = 0;
|
|
43
16
|
const msg = message;
|
|
@@ -59,7 +32,7 @@ export function estimateMessageTokens(message) {
|
|
|
59
32
|
total += estimateTextTokens(JSON.stringify(b.arguments));
|
|
60
33
|
}
|
|
61
34
|
else if (b.type === "image") {
|
|
62
|
-
total += 800;
|
|
35
|
+
total += 800;
|
|
63
36
|
}
|
|
64
37
|
}
|
|
65
38
|
}
|
|
@@ -68,9 +41,6 @@ export function estimateMessageTokens(message) {
|
|
|
68
41
|
}
|
|
69
42
|
return Math.max(1, total);
|
|
70
43
|
}
|
|
71
|
-
/**
|
|
72
|
-
* 估算消息数组的总 token 数。
|
|
73
|
-
*/
|
|
74
44
|
export function estimateMessagesTotalTokens(messages) {
|
|
75
45
|
let sum = 0;
|
|
76
46
|
for (const m of messages) {
|
|
@@ -78,10 +48,6 @@ export function estimateMessagesTotalTokens(messages) {
|
|
|
78
48
|
}
|
|
79
49
|
return sum;
|
|
80
50
|
}
|
|
81
|
-
/**
|
|
82
|
-
* 查找属于“近期工作记忆”的消息起始索引。
|
|
83
|
-
* 从后往前数 keepRecentTurns 个 user 消息;在此之后的皆为近期交互,不参与第一级工具裁剪。
|
|
84
|
-
*/
|
|
85
51
|
export function findRecentCutoffIndex(messages, keepRecentTurns = DEFAULT_KEEP_RECENT_TURNS) {
|
|
86
52
|
if (messages.length === 0 || keepRecentTurns <= 0)
|
|
87
53
|
return 0;
|
|
@@ -97,12 +63,6 @@ export function findRecentCutoffIndex(messages, keepRecentTurns = DEFAULT_KEEP_R
|
|
|
97
63
|
}
|
|
98
64
|
return 0;
|
|
99
65
|
}
|
|
100
|
-
/**
|
|
101
|
-
* 第一级裁剪:远期工具输出裁剪(Distant Tool Output Trimming)
|
|
102
|
-
*
|
|
103
|
-
* 将历史中较早的工具巨量输出(几千行命令输出、超长文件读取)替换为轻量占位摘要,
|
|
104
|
-
* 保留工具调用的元数据与首尾关键信息。
|
|
105
|
-
*/
|
|
106
66
|
export function trimDistantToolOutputs(messages, options = {}) {
|
|
107
67
|
const minLines = options.minLines ?? DEFAULT_MIN_TRIM_LINES;
|
|
108
68
|
const minBytes = options.minBytes ?? DEFAULT_MIN_TRIM_BYTES;
|
|
@@ -114,12 +74,10 @@ export function trimDistantToolOutputs(messages, options = {}) {
|
|
|
114
74
|
let savedBytes = 0;
|
|
115
75
|
let savedTokens = 0;
|
|
116
76
|
const newMessages = messages.map((m, index) => {
|
|
117
|
-
// 近期消息不裁剪,保护最近的关键工作上下文
|
|
118
77
|
if (index >= cutoffIndex) {
|
|
119
78
|
return m;
|
|
120
79
|
}
|
|
121
80
|
const msg = m;
|
|
122
|
-
// 1. 处理 toolResult 消息
|
|
123
81
|
if (msg.role === "toolResult" && Array.isArray(msg.content)) {
|
|
124
82
|
let modified = false;
|
|
125
83
|
const newContent = msg.content.map((block) => {
|
|
@@ -128,7 +86,6 @@ export function trimDistantToolOutputs(messages, options = {}) {
|
|
|
128
86
|
const b = block;
|
|
129
87
|
if (b.type === "text" && typeof b.text === "string") {
|
|
130
88
|
const text = b.text;
|
|
131
|
-
// 如果已经裁剪过,避免重复处理
|
|
132
89
|
if (text.includes("[Tool output trimmed:")) {
|
|
133
90
|
return block;
|
|
134
91
|
}
|
|
@@ -160,7 +117,6 @@ export function trimDistantToolOutputs(messages, options = {}) {
|
|
|
160
117
|
return { ...msg, content: newContent };
|
|
161
118
|
}
|
|
162
119
|
}
|
|
163
|
-
// 2. 处理 bashExecution 消息
|
|
164
120
|
if (msg.role === "bashExecution" && typeof msg.output === "string") {
|
|
165
121
|
const text = msg.output;
|
|
166
122
|
if (!text.includes("[Tool output trimmed:")) {
|
|
@@ -195,34 +151,23 @@ export function trimDistantToolOutputs(messages, options = {}) {
|
|
|
195
151
|
savedTokens: Math.max(0, savedTokens),
|
|
196
152
|
};
|
|
197
153
|
}
|
|
198
|
-
/**
|
|
199
|
-
* 第二级裁剪:已完成步骤折叠(Completed Steps Folding)
|
|
200
|
-
*
|
|
201
|
-
* 折叠已通过的目标轮次中间调试日志或已确认步骤的重试调试过程。
|
|
202
|
-
* 将已解决步骤中冗余的反复排查、中间反思文本折叠为轻量占位,保留最终决策和产物。
|
|
203
|
-
*/
|
|
204
154
|
export function foldCompletedStepLogs(messages, options = {}) {
|
|
205
155
|
const keepRecentTurns = options.keepRecentTurns ?? 1;
|
|
206
156
|
const cutoffIndex = findRecentCutoffIndex(messages, keepRecentTurns);
|
|
207
157
|
let foldedCount = 0;
|
|
208
158
|
let savedBytes = 0;
|
|
209
159
|
let savedTokens = 0;
|
|
210
|
-
// 检查历史中是否存在已完成/通过的目标审查或成功修复标记
|
|
211
|
-
// 例如包含目标审查通过、已完成步骤标记等
|
|
212
160
|
const newMessages = messages.map((m, index) => {
|
|
213
161
|
if (index >= cutoffIndex) {
|
|
214
162
|
return m;
|
|
215
163
|
}
|
|
216
164
|
const msg = m;
|
|
217
|
-
// 对中间的 assistant 消息中的冗长调试日志/思考排查进行轻量折叠
|
|
218
|
-
// 若 assistant 消息包含明显的中间失败重试排查日志且不是最后结论
|
|
219
165
|
if (msg.role === "assistant" && Array.isArray(msg.content)) {
|
|
220
166
|
let modified = false;
|
|
221
167
|
const newContent = msg.content.map((block) => {
|
|
222
168
|
if (!block || typeof block !== "object")
|
|
223
169
|
return block;
|
|
224
170
|
const b = block;
|
|
225
|
-
// 如果有长 thinking 块,且在已完成历史中
|
|
226
171
|
if (b.type === "thinking" && typeof b.thinking === "string") {
|
|
227
172
|
const t = b.thinking;
|
|
228
173
|
if (t.length > 500 && !t.includes("[Completed step debug logs folded:")) {
|
|
@@ -254,21 +199,10 @@ export function foldCompletedStepLogs(messages, options = {}) {
|
|
|
254
199
|
savedTokens: Math.max(0, savedTokens),
|
|
255
200
|
};
|
|
256
201
|
}
|
|
257
|
-
/**
|
|
258
|
-
* 多级分层上下文预算裁剪总调度器(Hierarchical Pruning Orchestrator)
|
|
259
|
-
*
|
|
260
|
-
* 按照梯度策略执行:
|
|
261
|
-
* 1. 评估当前 token 占用与有效预算阈值;
|
|
262
|
-
* 2. 达到 70% 水位时,执行第一级(远期工具输出裁剪);
|
|
263
|
-
* 3. 若仍超标或达到 85% 水位,执行第二级(已完成步骤折叠);
|
|
264
|
-
* 4. 仅在前两级裁剪后依然超标时,才标记 needsCompaction = true 进入第三级。
|
|
265
|
-
*/
|
|
266
202
|
export function pruneContextHierarchically(messages, options) {
|
|
267
203
|
const contextWindow = options.contextWindow > 0 ? options.contextWindow : 128_000;
|
|
268
204
|
const reserveTokens = options.reserveTokens > 0 ? options.reserveTokens : 16_384;
|
|
269
205
|
const room = contextWindow - reserveTokens;
|
|
270
|
-
// reserve 若是按更大窗口换算的(例如 1M - 256K = 744K),room 会变成负数,
|
|
271
|
-
// 70% 水位跟着变成负数,任意长度都会裁。只在 room 不为正时改按当前窗口收口。
|
|
272
206
|
const physicalCap = room > 0 ? room : Math.max(1, contextWindow - SOFT_CAP_MIN_HEADROOM);
|
|
273
207
|
const effectiveCap = options.softCap && options.softCap > 0 ? Math.min(options.softCap, physicalCap) : physicalCap;
|
|
274
208
|
const tier1Watermark = options.tier1Watermark ?? DEFAULT_PRUNE_WATERMARK;
|
|
@@ -282,7 +216,6 @@ export function pruneContextHierarchically(messages, options) {
|
|
|
282
216
|
const tier2Result = { foldedCount: 0, savedBytes: 0, savedTokens: 0 };
|
|
283
217
|
const reachedTier1 = options.force || currentTokens >= tier1Threshold;
|
|
284
218
|
let reachedTier2 = options.force || currentTokens >= tier2Threshold;
|
|
285
|
-
// 1. 第一级:远期工具输出裁剪
|
|
286
219
|
if (reachedTier1) {
|
|
287
220
|
const r1 = trimDistantToolOutputs(currentMessages);
|
|
288
221
|
if (r1.trimmedCount > 0) {
|
|
@@ -293,7 +226,6 @@ export function pruneContextHierarchically(messages, options) {
|
|
|
293
226
|
currentTokens = estimateMessagesTotalTokens(currentMessages);
|
|
294
227
|
}
|
|
295
228
|
}
|
|
296
|
-
// 2. 第二级:已完成步骤折叠(如果仍达到第二级水位或仍超标)
|
|
297
229
|
reachedTier2 = reachedTier2 || currentTokens >= tier2Threshold;
|
|
298
230
|
if (reachedTier2 || (options.force && currentTokens >= effectiveCap)) {
|
|
299
231
|
const r2 = foldCompletedStepLogs(currentMessages);
|
|
@@ -305,7 +237,6 @@ export function pruneContextHierarchically(messages, options) {
|
|
|
305
237
|
currentTokens = estimateMessagesTotalTokens(currentMessages);
|
|
306
238
|
}
|
|
307
239
|
}
|
|
308
|
-
// 3. 第三级判定:前两级瘦身后,是否依然超过有效预算上限
|
|
309
240
|
const needsCompaction = currentTokens >= effectiveCap;
|
|
310
241
|
return {
|
|
311
242
|
messages: currentMessages,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** Immutable, session-local evidence. Persistence must succeed before replacing text. */
|
|
2
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
2
|
import { constants } from "node:fs";
|
|
4
3
|
import { link, lstat, mkdir, open, readdir, rm, unlink } from "node:fs/promises";
|
|
@@ -10,7 +9,6 @@ const ARTIFACT = /^[a-f0-9]{64}\.txt$/;
|
|
|
10
9
|
export function contextEvidenceReference(text) {
|
|
11
10
|
return `context-evidence:${createHash("sha256").update(text).digest("hex")}`;
|
|
12
11
|
}
|
|
13
|
-
/** Deterministic summary appendix: names only, never artifact bodies or machine-specific paths. */
|
|
14
12
|
export async function buildContextEvidenceIndex(sessionFile) {
|
|
15
13
|
return withEvidenceQueue([sessionFile], undefined, async () => {
|
|
16
14
|
let directory;
|
|
@@ -34,7 +32,6 @@ export async function buildContextEvidenceIndex(sessionFile) {
|
|
|
34
32
|
].join("\n");
|
|
35
33
|
});
|
|
36
34
|
}
|
|
37
|
-
/** Resolve before permission guards, so they inspect the actual filesystem path. */
|
|
38
35
|
export function withContextEvidenceRead(base, getSessionFile) {
|
|
39
36
|
return {
|
|
40
37
|
...base,
|
|
@@ -54,8 +51,6 @@ export function withContextEvidenceRead(base, getSessionFile) {
|
|
|
54
51
|
throw new Error("Invalid evidence reference or no persisted session");
|
|
55
52
|
}
|
|
56
53
|
else if (sessionFile) {
|
|
57
|
-
// SDK hooks may already have resolved the alias. Only this session's exact directory
|
|
58
|
-
// or a direct hash-named child qualifies; sibling prefixes and nested paths do not.
|
|
59
54
|
const directory = resolve(`${sessionFile}.evidence`);
|
|
60
55
|
const candidate = resolve(ctx.cwd || process.cwd(), value);
|
|
61
56
|
const child = relative(directory, candidate);
|
|
@@ -71,7 +66,6 @@ export function withContextEvidenceRead(base, getSessionFile) {
|
|
|
71
66
|
if (digest)
|
|
72
67
|
await readEvidence(path, digest, signal);
|
|
73
68
|
signal?.throwIfAborted();
|
|
74
|
-
// Keep the original reader (including its permission guard and offset/limit behavior).
|
|
75
69
|
const result = await base.execute(id, { ...input, path, ...("file_path" in input ? { file_path: path } : {}) }, signal, onUpdate, ctx);
|
|
76
70
|
signal?.throwIfAborted();
|
|
77
71
|
if (digest)
|
|
@@ -83,8 +77,6 @@ export function withContextEvidenceRead(base, getSessionFile) {
|
|
|
83
77
|
},
|
|
84
78
|
};
|
|
85
79
|
}
|
|
86
|
-
// Reserve all queues synchronously: opposite-direction copies never hold one lock while acquiring another.
|
|
87
|
-
// One service process owns a data directory. Canonical lexical paths also serialize relative/absolute aliases.
|
|
88
80
|
const pendingWrites = new Map();
|
|
89
81
|
async function withEvidenceQueue(sessions, signal, operation) {
|
|
90
82
|
signal?.throwIfAborted();
|
|
@@ -108,7 +100,6 @@ async function withEvidenceQueue(sessions, signal, operation) {
|
|
|
108
100
|
function missing(error) {
|
|
109
101
|
return error.code === "ENOENT";
|
|
110
102
|
}
|
|
111
|
-
/** O_NOFOLLOW is not supported by Windows. There, compare lstat against the opened handle too. */
|
|
112
103
|
async function openRegular(path, signal) {
|
|
113
104
|
signal?.throwIfAborted();
|
|
114
105
|
const before = await lstat(path);
|
|
@@ -146,7 +137,6 @@ async function evidenceDirectory(session, create, signal) {
|
|
|
146
137
|
throw new Error("Invalid evidence directory");
|
|
147
138
|
return directory;
|
|
148
139
|
}
|
|
149
|
-
/** Never read more than the fstat size plus one byte, even if the file grows during the read. */
|
|
150
140
|
async function readEvidence(path, digest, signal, output, expectedSize) {
|
|
151
141
|
const handle = await openRegular(path, signal);
|
|
152
142
|
try {
|
|
@@ -197,7 +187,6 @@ async function sessionExists(session, signal) {
|
|
|
197
187
|
await handle.close();
|
|
198
188
|
signal?.throwIfAborted();
|
|
199
189
|
}
|
|
200
|
-
/** Include every entry in the budget; never follow symlinks or silently ignore damaged named artifacts. */
|
|
201
190
|
async function inventory(directory, signal) {
|
|
202
191
|
const sizes = new Map();
|
|
203
192
|
let total = 0;
|
|
@@ -217,7 +206,6 @@ async function inventory(directory, signal) {
|
|
|
217
206
|
signal?.throwIfAborted();
|
|
218
207
|
return sizes;
|
|
219
208
|
}
|
|
220
|
-
/** Publish without replacing an existing digest, and remove a newly published file if cancellation wins. */
|
|
221
209
|
async function publish(temporary, target, session, signal) {
|
|
222
210
|
await sessionExists(session, signal);
|
|
223
211
|
signal?.throwIfAborted();
|
|
@@ -274,7 +262,6 @@ export async function persistContextEvidence(sessionFile, text, signal) {
|
|
|
274
262
|
}
|
|
275
263
|
});
|
|
276
264
|
}
|
|
277
|
-
/** Call after removing the transcript; queued writers then observe its absence. */
|
|
278
265
|
export async function removeContextEvidence(sessionFile, signal) {
|
|
279
266
|
await withEvidenceQueue([sessionFile], signal, async () => {
|
|
280
267
|
signal?.throwIfAborted();
|
|
@@ -282,7 +269,6 @@ export async function removeContextEvidence(sessionFile, signal) {
|
|
|
282
269
|
signal?.throwIfAborted();
|
|
283
270
|
});
|
|
284
271
|
}
|
|
285
|
-
/** Copy all artifacts sequentially with one fixed-size buffer, while reserving both session queues. */
|
|
286
272
|
export async function copyContextEvidence(source, destination, signal) {
|
|
287
273
|
await withEvidenceQueue([source, destination], signal, async () => {
|
|
288
274
|
signal?.throwIfAborted();
|
|
@@ -3,12 +3,10 @@ import { effectiveTemplate, estimatePromptTokens, overrideOf } from "./prompt-co
|
|
|
3
3
|
function emptyWeights() {
|
|
4
4
|
return { systemPrompt: 0, memoryFiles: 0, tools: 0, skills: 0, toolResults: 0, messages: 0, other: 0 };
|
|
5
5
|
}
|
|
6
|
-
/** Uses the same rendered prompt and token estimator as the settings preview. */
|
|
7
6
|
export function estimateBaseContext(snapshot, options) {
|
|
8
7
|
const weights = emptyWeights();
|
|
9
8
|
const disabled = new Set(options.promptDisabled ?? []);
|
|
10
9
|
const template = effectiveTemplate(options.promptTemplate ?? "");
|
|
11
|
-
// Count only sections actually present in the template, including repeated placeholders.
|
|
12
10
|
for (const match of template.matchAll(/\{\{\s*(context|skills|tools)\s*\}\}/g)) {
|
|
13
11
|
const name = match[1];
|
|
14
12
|
if (disabled.has(name))
|
|
@@ -19,7 +17,6 @@ export function estimateBaseContext(snapshot, options) {
|
|
|
19
17
|
}
|
|
20
18
|
const prompt = estimatePromptTokens(snapshot.full);
|
|
21
19
|
const schema = estimatePromptTokens(snapshot.toolsSchema);
|
|
22
|
-
// Rounding individual sections can exceed the full prompt by a few tokens.
|
|
23
20
|
const sections = weights.memoryFiles + weights.skills + weights.tools;
|
|
24
21
|
if (sections > prompt) {
|
|
25
22
|
for (const category of ["memoryFiles", "skills", "tools"]) {
|
|
@@ -30,17 +27,11 @@ export function estimateBaseContext(snapshot, options) {
|
|
|
30
27
|
weights.tools += schema;
|
|
31
28
|
return { tokens: prompt + schema, weights };
|
|
32
29
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Estimate proportions from live session messages, excluding compacted/branched-away entries.
|
|
35
|
-
* These are transcript weights, not an exact breakdown of a provider request: request-local
|
|
36
|
-
* deduplication, evidence externalization and extensions can change the submitted messages.
|
|
37
|
-
*/
|
|
38
30
|
export function estimateContextWeights(base, messages, streamingMessage, cache) {
|
|
39
31
|
const weights = { ...base };
|
|
40
32
|
const add = (value, settled = false) => {
|
|
41
33
|
if (!value || typeof value !== "object")
|
|
42
34
|
return;
|
|
43
|
-
// A former prefix may become the mutable tail after truncation; discard its old estimate.
|
|
44
35
|
if (!settled)
|
|
45
36
|
cache?.delete(value);
|
|
46
37
|
const cached = settled ? cache?.get(value) : undefined;
|
|
@@ -75,8 +66,6 @@ export function estimateContextWeights(base, messages, streamingMessage, cache)
|
|
|
75
66
|
for (const category of Object.keys(weights))
|
|
76
67
|
weights[category] += contribution[category];
|
|
77
68
|
};
|
|
78
|
-
// Agent-core appends message_end and clears streamingMessage before AgentSession awaits
|
|
79
|
-
// extensions, which may replace the final message in place. Cache only the earlier prefix.
|
|
80
69
|
const lastMessage = messages[messages.length - 1];
|
|
81
70
|
for (const message of messages)
|
|
82
71
|
add(message, message !== streamingMessage && message !== lastMessage);
|
|
@@ -84,7 +73,6 @@ export function estimateContextWeights(base, messages, streamingMessage, cache)
|
|
|
84
73
|
add(streamingMessage);
|
|
85
74
|
return weights;
|
|
86
75
|
}
|
|
87
|
-
/** Keep the provider's total authoritative; integer allocation does not make the estimated proportions exact. */
|
|
88
76
|
export function reconcileContextCategories(weights, usedTokens) {
|
|
89
77
|
const total = Math.max(0, Math.round(Number.isFinite(usedTokens) ? usedTokens : 0));
|
|
90
78
|
const entries = Object.keys(weights).map((category) => ({
|
|
@@ -1,29 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local control socket for the pi-web-ui server.
|
|
3
|
-
*
|
|
4
|
-
* Lets the CLI (and humans) query status and quiesce/unquiesce the server
|
|
5
|
-
* WITHOUT opening a network port or exposing an unauthenticated HTTP
|
|
6
|
-
* endpoint. Only the local OS user can reach it:
|
|
7
|
-
* - POSIX: a mode-0600 Unix domain socket at <dataDir>/pi-web-ui.sock
|
|
8
|
-
* - Windows: a named pipe \\.\pipe\pi-web-ui-<port>
|
|
9
|
-
*
|
|
10
|
-
* Protocol: one JSON object per line.
|
|
11
|
-
* → {"cmd":"status"} ← {"ok":true, ...serviceStatus}
|
|
12
|
-
* → {"cmd":"quiesce"} ← {"ok":true}
|
|
13
|
-
* → {"cmd":"unquiesce"} ← {"ok":true}
|
|
14
|
-
* → anything else ← {"ok":false,"error":"..."}
|
|
15
|
-
*
|
|
16
|
-
* Idle connections are closed after a short timeout so a stuck CLI never
|
|
17
|
-
* holds the socket.
|
|
18
|
-
*/
|
|
19
1
|
import { createServer, createConnection } from "node:net";
|
|
20
2
|
import { chmodSync, existsSync, rmSync } from "node:fs";
|
|
21
3
|
import { join } from "node:path";
|
|
22
|
-
/** 探测既有 socket 的超时:活实例对 connect 的响应是内核级的,300ms 足够。 */
|
|
23
4
|
const CONTROL_PROBE_TIMEOUT_MS = 300;
|
|
24
|
-
/** 控制路径探测:连得上(有活实例在 listen)→ null;失败 → errno
|
|
25
|
-
* (ECONNREFUSED/ENOENT = 崩溃残留,可安全删除)。超时按「可能是活实例」
|
|
26
|
-
* 保守处理,返回超时码 —— 宁可不删残留也别摘掉正在服务的 socket。 */
|
|
27
5
|
function probeControlPath(path) {
|
|
28
6
|
return new Promise((resolve) => {
|
|
29
7
|
const sock = createConnection(path);
|
|
@@ -41,24 +19,16 @@ function probeControlPath(path) {
|
|
|
41
19
|
sock.once("error", (err) => finish(err.code ?? "EUNKNOWN"));
|
|
42
20
|
});
|
|
43
21
|
}
|
|
44
|
-
/** How long a control connection may sit idle before the server closes it. */
|
|
45
22
|
const CONTROL_IDLE_TIMEOUT_MS = 5_000;
|
|
46
|
-
/** Socket path (POSIX) or pipe name (Windows). */
|
|
47
23
|
export function controlPath(dataDir, port) {
|
|
48
24
|
return process.platform === "win32" ? `\\\\.\\pipe\\pi-web-ui-${port}` : join(dataDir, "pi-web-ui.sock");
|
|
49
25
|
}
|
|
50
|
-
/** Start the control socket; returns a stop function. */
|
|
51
26
|
export function startControlServer(opts) {
|
|
52
27
|
const { service, dataDir, port, authToken } = opts;
|
|
53
28
|
const path = controlPath(dataDir, port);
|
|
54
29
|
let server;
|
|
55
|
-
// 只有本实例真正 bind 成功才允许 stop 时删 socket 文件:探测发现活实例而
|
|
56
|
-
// listen 失败时,path 上是对方的 socket,删了会让后续客户端全部失联。
|
|
57
30
|
let bound = false;
|
|
58
31
|
if (process.platform === "win32") {
|
|
59
|
-
// Windows named pipe 不落盘(最后一个句柄关闭即消失),不存在崩溃残留
|
|
60
|
-
// 文件可清理;撞上活实例时 listen 直接 EADDRINUSE,走下方统一 error
|
|
61
|
-
// 处理。无需探测。
|
|
62
32
|
server = createServer(handleConnection);
|
|
63
33
|
server.listen(path, () => {
|
|
64
34
|
bound = true;
|
|
@@ -67,33 +37,23 @@ export function startControlServer(opts) {
|
|
|
67
37
|
}
|
|
68
38
|
else {
|
|
69
39
|
server = createServer(handleConnection);
|
|
70
|
-
// POSIX socket 文件崩溃后会残留,但先探测再删:无条件 rmSync 会把正在
|
|
71
|
-
// 服务的实例(比如被新的 pi-web 抢占前仍在跑的旧实例)的 socket 文件摘
|
|
72
|
-
// 走,新旧实例互相踩。只有连不上的残留(ECONNREFUSED/ENOENT)才删;
|
|
73
|
-
// 探测超时保守当作活实例,让 listen 自己以 EADDRINUSE 失败告警。
|
|
74
40
|
void probeControlPath(path).then((probeErr) => {
|
|
75
41
|
if (probeErr && existsSync(path)) {
|
|
76
42
|
try {
|
|
77
43
|
rmSync(path);
|
|
78
44
|
}
|
|
79
|
-
catch {
|
|
80
|
-
/* best-effort */
|
|
81
|
-
}
|
|
45
|
+
catch { }
|
|
82
46
|
}
|
|
83
47
|
server.listen(path, () => {
|
|
84
48
|
bound = true;
|
|
85
49
|
try {
|
|
86
50
|
chmodSync(path, 0o600);
|
|
87
51
|
}
|
|
88
|
-
catch {
|
|
89
|
-
/* best-effort */
|
|
90
|
-
}
|
|
52
|
+
catch { }
|
|
91
53
|
console.log(` control : ${path}`);
|
|
92
54
|
});
|
|
93
55
|
});
|
|
94
56
|
}
|
|
95
|
-
// A second instance on the same data dir / port would fail to bind — don't
|
|
96
|
-
// crash the server over it, just log and run without a control socket.
|
|
97
57
|
server.on("error", (err) => {
|
|
98
58
|
if (err.code === "EADDRINUSE") {
|
|
99
59
|
console.warn(`[control] socket ${path} already in use — control socket disabled`);
|
|
@@ -148,9 +108,7 @@ export function startControlServer(opts) {
|
|
|
148
108
|
sock.write(JSON.stringify(resp) + "\n");
|
|
149
109
|
}
|
|
150
110
|
});
|
|
151
|
-
sock.on("error", () => {
|
|
152
|
-
/* client vanished */
|
|
153
|
-
});
|
|
111
|
+
sock.on("error", () => { });
|
|
154
112
|
sock.on("close", () => clearTimeout(timer));
|
|
155
113
|
}
|
|
156
114
|
return () => {
|
|
@@ -159,8 +117,6 @@ export function startControlServer(opts) {
|
|
|
159
117
|
if (process.platform !== "win32" && bound && existsSync(path))
|
|
160
118
|
rmSync(path);
|
|
161
119
|
}
|
|
162
|
-
catch {
|
|
163
|
-
/* best-effort */
|
|
164
|
-
}
|
|
120
|
+
catch { }
|
|
165
121
|
};
|
|
166
122
|
}
|
|
@@ -102,7 +102,6 @@ function checkAnswers(answers, questions) {
|
|
|
102
102
|
throw new Error("Missing answer");
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
/** Process-wide coordinator. No agent service, holder, transport or wake policy is retained. */
|
|
106
105
|
export class ConversationCommunication {
|
|
107
106
|
queues = new Map();
|
|
108
107
|
requests = new Map();
|
|
@@ -121,7 +120,6 @@ export class ConversationCommunication {
|
|
|
121
120
|
inbox(endpoint) {
|
|
122
121
|
return structuredClone([...(this.queues.get(endpoint)?.values() ?? [])]);
|
|
123
122
|
}
|
|
124
|
-
/** Any incoming or outgoing decision still waiting, including user escalation. */
|
|
125
123
|
pending(endpoint) {
|
|
126
124
|
return [...this.requests.values()].some((r) => r.sender === endpoint || r.target === endpoint);
|
|
127
125
|
}
|
|
@@ -133,7 +131,6 @@ export class ConversationCommunication {
|
|
|
133
131
|
requestSource(requestId) {
|
|
134
132
|
return this.requests.get(requestId)?.sender;
|
|
135
133
|
}
|
|
136
|
-
/** Original object for host question registration; do not replace its settlement ownership. */
|
|
137
134
|
pendingQuestion(requestId) {
|
|
138
135
|
return this.requests.get(requestId)?.question;
|
|
139
136
|
}
|
|
@@ -144,7 +141,6 @@ export class ConversationCommunication {
|
|
|
144
141
|
this.queues.delete(endpoint);
|
|
145
142
|
return removed;
|
|
146
143
|
}
|
|
147
|
-
/** Stop/reset cancels current work while preserving the stable endpoint for later turns. */
|
|
148
144
|
cancel(endpoint) {
|
|
149
145
|
this.queues.delete(endpoint);
|
|
150
146
|
for (const record of this.requests.values()) {
|
|
@@ -152,7 +148,6 @@ export class ConversationCommunication {
|
|
|
152
148
|
record.question.resolve({ cancelled: true, reason: "Communication endpoint closed" });
|
|
153
149
|
}
|
|
154
150
|
}
|
|
155
|
-
/** Final removal only. Holder migration must call neither close nor cancel. */
|
|
156
151
|
close(endpoint) {
|
|
157
152
|
this.cancel(endpoint);
|
|
158
153
|
this.closed.add(endpoint);
|
|
@@ -192,7 +187,6 @@ export class ConversationCommunication {
|
|
|
192
187
|
checkSignal(signal);
|
|
193
188
|
if (!args || Buffer.byteLength(JSON.stringify(args)) > this.limits.maxMessageBytes)
|
|
194
189
|
throw new Error("Communication payload exceeds byte limit");
|
|
195
|
-
// Copy caller-owned data before callbacks or awaits can mutate it.
|
|
196
190
|
args = structuredClone(args);
|
|
197
191
|
if (action === "read") {
|
|
198
192
|
this.authorize(host, sender, sender, action);
|
|
@@ -207,7 +201,6 @@ export class ConversationCommunication {
|
|
|
207
201
|
const result = structuredClone({ messages, remaining: (queue?.size ?? 0) - messages.length });
|
|
208
202
|
if (host.listRecipients) {
|
|
209
203
|
result.conversations = [];
|
|
210
|
-
// Reserve the optional field before fitting directory entries; messages take priority.
|
|
211
204
|
if (Buffer.byteLength(JSON.stringify(result)) > 48 * 1024)
|
|
212
205
|
delete result.conversations;
|
|
213
206
|
else
|
|
@@ -247,7 +240,6 @@ export class ConversationCommunication {
|
|
|
247
240
|
record.escalated = true;
|
|
248
241
|
record.question.audience = "user";
|
|
249
242
|
this.acknowledge(record.target, record.envelope.id);
|
|
250
|
-
// Return immediately: the original requester waits for the shared question.
|
|
251
243
|
try {
|
|
252
244
|
void Promise.resolve(host.askUser(record.sender, record.question, record.controller.signal)).catch(() => record.question.resolve({ cancelled: true, reason: "User question delivery failed" }));
|
|
253
245
|
}
|
|
@@ -347,7 +339,6 @@ export class ConversationCommunication {
|
|
|
347
339
|
}
|
|
348
340
|
}
|
|
349
341
|
if (!question.settled) {
|
|
350
|
-
// Delivery may block or fail. Neither may outlive the pending question clock.
|
|
351
342
|
void this.deliver(host, target, envelope, controller.signal, sender)
|
|
352
343
|
.then((status) => {
|
|
353
344
|
if (status === "delivered")
|
|
@@ -378,5 +369,4 @@ export class ConversationCommunication {
|
|
|
378
369
|
}
|
|
379
370
|
}
|
|
380
371
|
}
|
|
381
|
-
/** Shared across ClientSession holders. Hosts are supplied per call, never cached. */
|
|
382
372
|
export const conversationCommunication = new ConversationCommunication();
|