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
|
@@ -1,35 +1,12 @@
|
|
|
1
|
-
// ---------------------------------------------------------------------------
|
|
2
|
-
// conversation-read-tool.ts — 让 AI(含子代理)读取别的对话
|
|
3
|
-
// ---------------------------------------------------------------------------
|
|
4
|
-
// 背景:用户在左栏有「运行的对话」(含子代理)与「历史对话」,也常想让 AI
|
|
5
|
-
// 「结合另一个对话的内容回答」。此前 AI 既不知道别的对话的 id,也没有干净的
|
|
6
|
-
// 读取通道(只能用 read/bash 翻转录 jsonl,既难找路径又难解析)。
|
|
7
|
-
//
|
|
8
|
-
// 本工具提供只读双通道:
|
|
9
|
-
// action=list → 运行中对话(本标签页的全部 conversation,含子代理)+
|
|
10
|
-
// 历史会话转录(scope=current 仅当前项目,all 跨全部项目);
|
|
11
|
-
// action=read → 按 id 读运行中对话的实时消息(含未落盘的),或按 path 读
|
|
12
|
-
// 历史转录(只接受会话列表里的路径,任意文件不给读)。
|
|
13
|
-
//
|
|
14
|
-
// 转录文本走 transcriptText/formatTranscript 纯函数(有单测);文件解析走
|
|
15
|
-
// parseTranscriptLines(jsonl 逐行,坏行跳过)。输出按条数 + 字符数双封顶,
|
|
16
|
-
// 长对话分多次 offset 翻页。跨标签页的实时运行读不到——以落盘历史为准,
|
|
17
|
-
// description 里会告诉模型这一点。
|
|
18
|
-
//
|
|
19
|
-
// 文案约定:工具 definition(description/promptSnippet/promptGuidelines)为纯英文;per-call
|
|
20
|
-
// 返回文本按 lang 取 pick(lang, zh, en, key, vars),缺表回落英文内联。
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
1
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
23
2
|
import { Type } from "typebox";
|
|
24
3
|
import { pick } from "./i18n.js";
|
|
25
4
|
import { extractTouches, formatTouchEntry, formatTouchesCompact, toolCallRefsOfContent, unionTouchLists, } from "./conversation-touches.js";
|
|
26
|
-
/** 由 content 块提 toolCalls 字段(additive;格式化输出不受影响,见接口注释)。 */
|
|
27
5
|
function fillToolCalls(target, content) {
|
|
28
6
|
const refs = toolCallRefsOfContent(content);
|
|
29
7
|
if (refs.length > 0)
|
|
30
8
|
target.toolCalls = refs;
|
|
31
9
|
}
|
|
32
|
-
/** AgentMessage → 转录最小结构(角色原样保留,内容不动,格式化延后)。 */
|
|
33
10
|
export function toTranscriptInput(m) {
|
|
34
11
|
const role = m.role;
|
|
35
12
|
const r = typeof role === "string" ? role : "unknown";
|
|
@@ -55,7 +32,6 @@ export function toTranscriptInput(m) {
|
|
|
55
32
|
base.timestamp = anyM.timestamp;
|
|
56
33
|
return base;
|
|
57
34
|
}
|
|
58
|
-
/** 内容块 → 纯文本:text 拼接;图片占位;具名块(toolCall 等)留名;其余占位。 */
|
|
59
35
|
function textOfContent(content) {
|
|
60
36
|
if (typeof content === "string")
|
|
61
37
|
return content;
|
|
@@ -81,7 +57,6 @@ function textOfContent(content) {
|
|
|
81
57
|
}
|
|
82
58
|
return parts.join("\n");
|
|
83
59
|
}
|
|
84
|
-
/** 附件 aside 的短名(details.name/path),非附件返回空。 */
|
|
85
60
|
function attachmentName(details) {
|
|
86
61
|
if (!details || typeof details !== "object")
|
|
87
62
|
return "";
|
|
@@ -92,7 +67,6 @@ function attachmentName(details) {
|
|
|
92
67
|
return d.path.split(/[\\/]/).pop() ?? d.path;
|
|
93
68
|
return "";
|
|
94
69
|
}
|
|
95
|
-
/** 单条转录消息 → 可读文本行(角色标签 + 内容,不截断,截断由 format 统一做)。 */
|
|
96
70
|
export function transcriptText(m) {
|
|
97
71
|
switch (m.role) {
|
|
98
72
|
case "bashExecution":
|
|
@@ -121,13 +95,11 @@ export function transcriptText(m) {
|
|
|
121
95
|
}
|
|
122
96
|
}
|
|
123
97
|
}
|
|
124
|
-
/** 角色标签(列表行里的序号前缀用)。 */
|
|
125
98
|
function roleLabel(m) {
|
|
126
99
|
if (m.role === "toolResult")
|
|
127
100
|
return `tool result${m.toolName ? ` (${m.toolName})` : ""}`;
|
|
128
101
|
return m.role;
|
|
129
102
|
}
|
|
130
|
-
/** 单条消息截断:超出部分标注剩余字符数(调用方一眼知道丢了多少)。 */
|
|
131
103
|
export function truncateCounted(s, cap) {
|
|
132
104
|
if (s.length <= cap)
|
|
133
105
|
return s;
|
|
@@ -136,7 +108,6 @@ export function truncateCounted(s, cap) {
|
|
|
136
108
|
function trunc(s, cap) {
|
|
137
109
|
return truncateCounted(s, cap);
|
|
138
110
|
}
|
|
139
|
-
/** 转录分页格式化:序号形如 [12/135 user],尾部带翻页提示位(调用方拼 header)。 */
|
|
140
111
|
export function formatTranscript(messages, opts) {
|
|
141
112
|
const total = messages.length;
|
|
142
113
|
const offset = Math.max(0, Math.floor(opts?.offset ?? 0));
|
|
@@ -160,10 +131,6 @@ export function formatTranscript(messages, opts) {
|
|
|
160
131
|
text = "";
|
|
161
132
|
return { text, total, from, to, truncated };
|
|
162
133
|
}
|
|
163
|
-
/**
|
|
164
|
-
* 转录 jsonl → 转录消息(message 条目取 message;compaction/branch_summary
|
|
165
|
-
* 取 summary;坏行跳过)。纯函数:文件读取由宿主做,单测直接喂文本。
|
|
166
|
-
*/
|
|
167
134
|
export function parseTranscriptLines(text) {
|
|
168
135
|
const out = [];
|
|
169
136
|
for (const line of text.split("\n")) {
|
|
@@ -204,11 +171,9 @@ export function parseTranscriptLines(text) {
|
|
|
204
171
|
}
|
|
205
172
|
return out;
|
|
206
173
|
}
|
|
207
|
-
/** 大小写不敏感子串(空 query 全匹配)。 */
|
|
208
174
|
function matchesHay(hay, q) {
|
|
209
175
|
return q === "" || hay.toLowerCase().includes(q);
|
|
210
176
|
}
|
|
211
|
-
/** read 选择器(纯函数):view → query → last 的顺序固定,见注释。 */
|
|
212
177
|
export function selectReadMessages(messages, opts) {
|
|
213
178
|
const list = Array.isArray(messages) ? messages : [];
|
|
214
179
|
const view = opts?.view === "full" ? "full" : "chat";
|
|
@@ -217,8 +182,6 @@ export function selectReadMessages(messages, opts) {
|
|
|
217
182
|
let selected = inView;
|
|
218
183
|
let hitIndices = [];
|
|
219
184
|
if (q) {
|
|
220
|
-
// 在 view 内按转录文本搜:hitIndices 只记命中(报数/定位用),
|
|
221
|
-
// selected 是命中 ±1 条上下文展开(去重保序)。
|
|
222
185
|
const hits = [];
|
|
223
186
|
const keep = new Set();
|
|
224
187
|
for (let i = 0; i < inView.length; i++) {
|
|
@@ -236,7 +199,6 @@ export function selectReadMessages(messages, opts) {
|
|
|
236
199
|
const n = Math.min(200, Math.max(1, Math.floor(last)));
|
|
237
200
|
if (selected.length > n) {
|
|
238
201
|
selected = selected.slice(selected.length - n);
|
|
239
|
-
// last 裁掉上下文外层时命中序号跟走(只留仍在选区内的)。
|
|
240
202
|
if (hitIndices.length > 0) {
|
|
241
203
|
const keep = new Set(selected);
|
|
242
204
|
hitIndices = hitIndices.filter((i) => keep.has(inView[i]));
|
|
@@ -245,7 +207,6 @@ export function selectReadMessages(messages, opts) {
|
|
|
245
207
|
}
|
|
246
208
|
return { selected, totalInView: inView.length, hitIndices };
|
|
247
209
|
}
|
|
248
|
-
/** 工具参数里的一句话提示(path/command,单行 ≤80 字符;拿不到就空串)。 */
|
|
249
210
|
function toolHint(args) {
|
|
250
211
|
if (!args || typeof args !== "object")
|
|
251
212
|
return "";
|
|
@@ -259,7 +220,6 @@ function toolHint(args) {
|
|
|
259
220
|
}
|
|
260
221
|
return "";
|
|
261
222
|
}
|
|
262
|
-
/** action=status 的摘要器(纯函数):只读转录,不碰 host。 */
|
|
263
223
|
export function summarizeConversation(messages) {
|
|
264
224
|
const list = Array.isArray(messages) ? messages : [];
|
|
265
225
|
let lastTool;
|
|
@@ -311,7 +271,6 @@ export function summarizeConversation(messages) {
|
|
|
311
271
|
}
|
|
312
272
|
return { lastTool, lastAssistant, waitingQuestion: lastAskIdx >= 0 && lastAskResultIdx < lastAskIdx };
|
|
313
273
|
}
|
|
314
|
-
/** read 的附加说明行:query 命中位置 + chat 视图裁剪说明(纯函数)。 */
|
|
315
274
|
export function readExtraLines(L, query, sel, rawTotal, view) {
|
|
316
275
|
const lines = [];
|
|
317
276
|
const q = query.trim();
|
|
@@ -325,8 +284,6 @@ export function readExtraLines(L, query, sel, rawTotal, view) {
|
|
|
325
284
|
}
|
|
326
285
|
return lines.length > 0 ? `\n${lines.join("\n")}` : "";
|
|
327
286
|
}
|
|
328
|
-
/** 认领行格式化(files/status 共用,纯函数;head 文案各调用方自己 pick)。
|
|
329
|
-
* style: bullets = 独立成行(files 块用);inline = 行内逗分(status 一行用)。 */
|
|
330
287
|
export function formatClaimLines(claims, maxItems = 5, style = "bullets") {
|
|
331
288
|
const list = Array.isArray(claims) ? claims : [];
|
|
332
289
|
const shown = list.slice(0, Math.max(1, Math.floor(maxItems)));
|
|
@@ -348,16 +305,11 @@ export function filterHistory(list, query) {
|
|
|
348
305
|
return list;
|
|
349
306
|
return list.filter((s) => matchesHay(s.path, q) || matchesHay(s.name ?? "", q) || matchesHay(s.firstMessage, q));
|
|
350
307
|
}
|
|
351
|
-
/** 短 id/路径展示(列表行里路径太长只留尾部)。 */
|
|
352
308
|
export function shortPath(p, keep = 48) {
|
|
353
309
|
return p.length <= keep ? p : `…${p.slice(p.length - keep)}`;
|
|
354
310
|
}
|
|
355
|
-
/** action=list 的默认条数:历史默认 15(以前无上限,几百条一次吐完);
|
|
356
|
-
* 运行中默认不限但给上限(并发对话再多也不会撑爆 details 的 64KB)。 */
|
|
357
311
|
export const HISTORY_LIST_DEFAULT = 15;
|
|
358
312
|
export const RUNNING_LIST_CAP = 50;
|
|
359
|
-
/** action=read 单条消息默认截断(约 600 字符,超出标 “… +N chars”;
|
|
360
|
-
* 以前默认 2000,一条 bash 输出就能吃掉整个 maxChars 预算)。 */
|
|
361
313
|
export const READ_PER_MSG_CAP = 600;
|
|
362
314
|
export function makeConversationReadTool(host, lang, extras) {
|
|
363
315
|
const getLang = lang ?? (() => "en");
|
|
@@ -415,7 +367,6 @@ export function makeConversationReadTool(host, lang, extras) {
|
|
|
415
367
|
const cap = typeof p.limit === "number" && Number.isFinite(p.limit)
|
|
416
368
|
? Math.min(200, Math.max(1, Math.floor(p.limit)))
|
|
417
369
|
: undefined;
|
|
418
|
-
// kind 过滤掉的一整节直接不取不展(不为了它多一次 I/O)。
|
|
419
370
|
const running = kind === "history" ? [] : filterRunning(host.listRunningConversations(), query);
|
|
420
371
|
const history = kind === "running" ? [] : filterHistory(await host.listHistorySessions(scope, ctx.cwd), query);
|
|
421
372
|
const shownRunning = running.slice(0, cap ?? RUNNING_LIST_CAP);
|
|
@@ -423,7 +374,6 @@ export function makeConversationReadTool(host, lang, extras) {
|
|
|
423
374
|
const L = getLang();
|
|
424
375
|
const runLines = shownRunning.map((c) => `- ${c.id} · ${c.title} · ${c.isSubagent ? (L === "zh" ? "子代理" : "subagent") : L === "zh" ? "对话" : "chat"}${c.isStreaming ? (L === "zh" ? "(进行中)" : " (streaming)") : ""} · ${c.messageCount} msgs · ${c.cwd}`);
|
|
425
376
|
const histLines = shownHistory.map((s) => `- ${shortPath(s.path)} · ${s.name || s.firstMessage || (L === "zh" ? "(空对话)" : "(empty)")}${s.messageCount ? ` · ${s.messageCount} msgs` : ""}`);
|
|
426
|
-
// 超出 cap 时给计数 + 收窄指引(静默丢弃是大忌:调用方会以为这就是全量)。
|
|
427
377
|
if (running.length > shownRunning.length) {
|
|
428
378
|
runLines.push(pick(L, `… 还有 ${running.length - shownRunning.length} 条运行中(用 query 或 limit 收窄)。`, `… ${running.length - shownRunning.length} more running (narrow with query or limit).`, "convread.list.running.more", { n: running.length - shownRunning.length }));
|
|
429
379
|
}
|
|
@@ -447,8 +397,6 @@ export function makeConversationReadTool(host, lang, extras) {
|
|
|
447
397
|
: kind === "running"
|
|
448
398
|
? `${head}\n${runHead}\n${runLines.join("\n") || empty}`
|
|
449
399
|
: `${head}\n${runHead}\n${runLines.join("\n") || empty}\n${histHead}\n${histLines.join("\n") || empty}`;
|
|
450
|
-
// details 同样有界:只带展示出的条目(历史的 firstMessage 再掐到 160
|
|
451
|
-
// 字符),以前整量 history 进 details 会撑爆 64KB 被整段丢弃。
|
|
452
400
|
return text(`${sections}\n${tail}`, {
|
|
453
401
|
scope,
|
|
454
402
|
kind,
|
|
@@ -548,7 +496,6 @@ export function makeConversationReadTool(host, lang, extras) {
|
|
|
548
496
|
if ((id && path) || (!id && !path)) {
|
|
549
497
|
return text(pick(getLang(), `action=${action} 需要且只需要 id 或 path 其中之一(id 读运行中对话,path 读历史转录)。`, `action=${action} needs exactly one of id or path (id = running conversation, path = history transcript).`, action === "files" ? "convread.files.bad.args" : "convread.status.bad.args"));
|
|
550
498
|
}
|
|
551
|
-
// 取数(错误复用 read 的 not found 文案:同一个“找不到”语义)。
|
|
552
499
|
let title = "";
|
|
553
500
|
let cwd = "";
|
|
554
501
|
let messages = [];
|
|
@@ -574,7 +521,6 @@ export function makeConversationReadTool(host, lang, extras) {
|
|
|
574
521
|
const where = id ? { id } : { path };
|
|
575
522
|
if (action === "files") {
|
|
576
523
|
const fq = (typeof p.query === "string" ? p.query : "").trim().toLowerCase();
|
|
577
|
-
// sidecar(压缩前的触碰)∪ 实时转录:union 语义,见 unionTouchLists。
|
|
578
524
|
const all = unionTouchLists(host.readTouchSidecar?.(id, path) ?? [], extractTouches(messages));
|
|
579
525
|
const filtered = fq ? all.filter((t) => t.path.toLowerCase().includes(fq)) : all;
|
|
580
526
|
const listedClaims = (() => {
|
|
@@ -612,7 +558,6 @@ export function makeConversationReadTool(host, lang, extras) {
|
|
|
612
558
|
claims: listedClaims.map((c) => ({ path: c.path, ownerTitle: c.ownerTitle })),
|
|
613
559
|
});
|
|
614
560
|
}
|
|
615
|
-
// action === "status":一两行摘要,读全文前的低成本侦察。
|
|
616
561
|
const sum = summarizeConversation(messages);
|
|
617
562
|
const touched = unionTouchLists(host.readTouchSidecar?.(id, path) ?? [], extractTouches(messages)).slice(0, 6);
|
|
618
563
|
let statusClaims = [];
|
|
@@ -632,12 +577,9 @@ export function makeConversationReadTool(host, lang, extras) {
|
|
|
632
577
|
const touchLine = touched.length > 0
|
|
633
578
|
? pick(L, `最近动过:${formatTouchesCompact(touched, { maxItems: 5 })}。`, `Recently touched: ${formatTouchesCompact(touched, { maxItems: 5 })}.`, "convread.status.touched", { files: formatTouchesCompact(touched, { maxItems: 5 }) })
|
|
634
579
|
: pick(L, `最近没动过文件。`, `No files touched recently.`, "convread.status.touched.none");
|
|
635
|
-
// 等问卷只能从转录推断(ask_user_question 调了没回);DSH 问卷不走
|
|
636
|
-
// 工具调用,推断不出 —— 文案写“转录显示”,不夸大。
|
|
637
580
|
const waitLine = sum.waitingQuestion
|
|
638
581
|
? `\n${pick(L, `⚠ 转录显示它在等用户回答问卷(先回它,再干别的)。`, `⚠ The transcript shows it waiting for a question answer (answer first).`, "convread.status.waiting")}`
|
|
639
582
|
: "";
|
|
640
|
-
// 认领只在有的时候占一行(没有就不提,省 token)。
|
|
641
583
|
const linesZh = formatClaimLines(statusClaims, 3, "inline").join("、");
|
|
642
584
|
const linesEn = formatClaimLines(statusClaims, 3, "inline").join("; ");
|
|
643
585
|
const claimLine = statusClaims.length > 0
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SUBAGENT_TOOL_NAMES } from "./tool-manager.js";
|
|
2
|
-
/** Both public names share the same execution and permission boundary. */
|
|
3
2
|
export const CONVERSATION_TOOL_NAMES = SUBAGENT_TOOL_NAMES;
|
|
4
3
|
export const READ_ONLY_CONVERSATION_ACTIONS = ["get_result", "list", "templates", "read", "files", "status"];
|
|
5
4
|
export function isReadOnlyConversationAction(action) {
|
|
@@ -1,47 +1,3 @@
|
|
|
1
|
-
// ---------------------------------------------------------------------------
|
|
2
|
-
// conversation-touches.ts — 会话「触碰文件集」提取(纯函数,零 node 依赖)
|
|
3
|
-
// ---------------------------------------------------------------------------
|
|
4
|
-
// 背景:同项目多对话并行时,服务端完全知道「谁碰过哪些文件」(实时消息与落盘
|
|
5
|
-
// 转录里都有工具调用记录),但既没算也没给 AI,导致 AI 只能靠猜冲突。本模块
|
|
6
|
-
// 只实现一次触碰集解析器,三处复用:并行提醒(agent-service.ts)、
|
|
7
|
-
// conversation_read 的 action:"files" 与 action:"status"。
|
|
8
|
-
//
|
|
9
|
-
// 输入形状(两条路都已核实,见下「数据来源」):
|
|
10
|
-
// - 实时路:session.agent.state.messages(SDK AgentMessage),assistant 消息
|
|
11
|
-
// 的 content 里是 {type:"toolCall", id, name, arguments} 块;
|
|
12
|
-
// - 历史路:转录 jsonl 的 message.content,原样保留同一形状(parseTranscript
|
|
13
|
-
// Lines 透传 content)。
|
|
14
|
-
// 注意:textOfContent 只在「渲染文本」里丢了参数(仍渲染 `[tool call: name]`),
|
|
15
|
-
// content 结构里的 arguments 一直都在。所以 toolCalls 字段是 additive 的便捷
|
|
16
|
-
// 访问点(一处解析、多处复用,并行 toolCall 也能表示),不是新数据源;取不到
|
|
17
|
-
// 时回落扫 content,再取不到就给空集 —— 绝不伪造。
|
|
18
|
-
//
|
|
19
|
-
// 提取规则(只算写,不算读 —— 这是准确性的关键):
|
|
20
|
-
// 写工具白名单:edit / write / edit_soft(参数 path;兼容 file_path/filePath
|
|
21
|
-
// 别名)。白名单之外的一切工具调用一律忽略,所以 read/ls/glob/grep 等读操作
|
|
22
|
-
// 天然不算 —— 不需要也不维护「读工具黑名单」。
|
|
23
|
-
// bash 高置信度写入迹象(拿不准就丢,宁可漏报不要假阳性):
|
|
24
|
-
// - 重定向 `>` / `>>` 的目标词(含 `2> file` 这类 fd 前缀;排除 `>&N`、
|
|
25
|
-
// /dev/null、NUL、&N;heredoc `<<`/`<<<` 不算写入);
|
|
26
|
-
// - rm / rmdir / mkdir / touch 的非 flag 参数;
|
|
27
|
-
// - cp / mv 只取最后一个非 flag 参数(目标端;源端是读/被删,不算写)。
|
|
28
|
-
// 解析是轻量分词器(引号/转义感知,`;`/`&&`/`||`/`|`/`&`/`(`/`)` 切分命令
|
|
29
|
-
// 段),不是完整 shell 解析器。
|
|
30
|
-
//
|
|
31
|
-
// 已知局限(如实记录,调用方展示时不要夸大):
|
|
32
|
-
// 1. 压缩(compaction)后旧消息被摘要替代,压缩前的触碰会丢失 —— 触碰集是
|
|
33
|
-
// 「当前可见转录」的下界,不是全集。
|
|
34
|
-
// 2. 相对路径按字面记录(edit 常给绝对路径、bash 常给相对路径),跨会话交集
|
|
35
|
-
// 可能因此漏报;但绝不做后缀模糊匹配(同名不同目录会假阳性,比漏报更糟)。
|
|
36
|
-
// 3. 路径归一化只做:去首尾空白、反斜杠转斜杠、去 `./` 前缀。Windows 大小写
|
|
37
|
-
// 不敏感不做归一。
|
|
38
|
-
// 4. powershell/cmd 风格写入(Set-Content/Out-File/del/copy)、git apply、
|
|
39
|
-
// tee 落盘、xargs/timeout/nice 等包装词之后的子命令 —— 一律不提取
|
|
40
|
-
// (sudo/env/command/time/nohup/doas 这几个常见包装词能跳过)。
|
|
41
|
-
// 5. 引号内的 `>`(如 echo "a > b")不提取;但 `eval`/`sh -c` 套娃串内的重定
|
|
42
|
-
// 向会被当成普通命令解析 —— 置信度下降,属已知噪声源。
|
|
43
|
-
// ---------------------------------------------------------------------------
|
|
44
|
-
/** 工具调用的参数键:SDK 用 arguments,兼容 input/args 两种历史写法。 */
|
|
45
1
|
function argsOfBlock(blk) {
|
|
46
2
|
if (typeof blk.arguments !== "undefined")
|
|
47
3
|
return blk.arguments;
|
|
@@ -49,7 +5,6 @@ function argsOfBlock(blk) {
|
|
|
49
5
|
return blk.input;
|
|
50
6
|
return blk.args;
|
|
51
7
|
}
|
|
52
|
-
/** content 块数组里工具调用的 (name, args) 对(非 toolCall 块跳过)。 */
|
|
53
8
|
export function toolCallRefsOfContent(content) {
|
|
54
9
|
if (!Array.isArray(content))
|
|
55
10
|
return [];
|
|
@@ -68,7 +23,6 @@ export function toolCallRefsOfContent(content) {
|
|
|
68
23
|
}
|
|
69
24
|
return out;
|
|
70
25
|
}
|
|
71
|
-
/** 一条消息的全部工具调用:优先已解析的 toolCalls 字段,回落扫 content。 */
|
|
72
26
|
export function toolCallsOf(m) {
|
|
73
27
|
if (!m || typeof m !== "object")
|
|
74
28
|
return [];
|
|
@@ -77,7 +31,6 @@ export function toolCallsOf(m) {
|
|
|
77
31
|
}
|
|
78
32
|
return toolCallRefsOfContent(m.content);
|
|
79
33
|
}
|
|
80
|
-
/** 写工具白名单:只有这些工具的目标路径才算「写」。 */
|
|
81
34
|
const WRITE_TOOL_NAMES = new Set(["edit", "write", "edit_soft"]);
|
|
82
35
|
function pathOfWriteArgs(args) {
|
|
83
36
|
if (!args || typeof args !== "object")
|
|
@@ -90,14 +43,12 @@ function pathOfWriteArgs(args) {
|
|
|
90
43
|
}
|
|
91
44
|
return undefined;
|
|
92
45
|
}
|
|
93
|
-
/** 路径轻归一(见文件头局限 3):只做无损、低风险的规范化。 */
|
|
94
46
|
export function normalizeTouchPath(p) {
|
|
95
47
|
let s = p.trim().replace(/\\/g, "/");
|
|
96
48
|
while (s.startsWith("./"))
|
|
97
49
|
s = s.slice(2);
|
|
98
50
|
return s;
|
|
99
51
|
}
|
|
100
|
-
/** patch 补丁文本 → 目标路径集合(段头 [path#TAG]/[path] + MV 目标)。 */
|
|
101
52
|
export function patchWriteTargets(patchText) {
|
|
102
53
|
const out = [];
|
|
103
54
|
for (const m of patchText.matchAll(/^\s*\[([^#\]\r\n]+)(?:#[0-9A-Fa-f]{4})?\]\s*$/gm)) {
|
|
@@ -107,10 +58,6 @@ export function patchWriteTargets(patchText) {
|
|
|
107
58
|
out.push(m[1]);
|
|
108
59
|
return out;
|
|
109
60
|
}
|
|
110
|
-
// ---------------------------------------------------------------------------
|
|
111
|
-
// bash 命令解析(高置信度写入迹象,见文件头规则)
|
|
112
|
-
// ---------------------------------------------------------------------------
|
|
113
|
-
/** shell 分词:引号/反斜杠转义感知,引号剥掉(`echo "a > b"` 的 > 不会误报)。 */
|
|
114
61
|
function tokenizeShell(cmd) {
|
|
115
62
|
const toks = [];
|
|
116
63
|
let cur = "";
|
|
@@ -152,7 +99,6 @@ function tokenizeShell(cmd) {
|
|
|
152
99
|
i++;
|
|
153
100
|
continue;
|
|
154
101
|
}
|
|
155
|
-
// 多字符操作符先行:>>、<<、&&、||、2>、1>> 等。
|
|
156
102
|
const three = cmd.slice(i, i + 3);
|
|
157
103
|
const two = cmd.slice(i, i + 2);
|
|
158
104
|
if (/^\d>>/.test(three) || three === "<<<") {
|
|
@@ -180,12 +126,9 @@ function tokenizeShell(cmd) {
|
|
|
180
126
|
return toks;
|
|
181
127
|
}
|
|
182
128
|
const SEGMENT_SEPS = new Set([";", "&&", "||", "|", "&", "(", ")"]);
|
|
183
|
-
/** 命令段首可跳过的包装词(之后仍是命令位置)。 */
|
|
184
129
|
const WRAPPER_WORDS = new Set(["sudo", "env", "command", "time", "nohup", "doas"]);
|
|
185
130
|
const MULTI_TARGET_WRITES = new Set(["rm", "rmdir", "mkdir", "touch"]);
|
|
186
|
-
/** 只算目标端(最后一个非 flag 参数)的命令。 */
|
|
187
131
|
const DEST_ONLY_WRITES = new Set(["cp", "mv"]);
|
|
188
|
-
/** 重定向目标黑名单:不是文件。 */
|
|
189
132
|
function isNonFileTarget(t) {
|
|
190
133
|
if (t === "/dev/null" || t.toLowerCase() === "nul")
|
|
191
134
|
return true;
|
|
@@ -195,13 +138,11 @@ function isNonFileTarget(t) {
|
|
|
195
138
|
return true;
|
|
196
139
|
return false;
|
|
197
140
|
}
|
|
198
|
-
/** bash 命令 → 高置信度写入路径(去重前,调用方计数)。 */
|
|
199
141
|
export function bashWriteTargets(command) {
|
|
200
142
|
if (typeof command !== "string" || !command.trim())
|
|
201
143
|
return [];
|
|
202
144
|
const toks = tokenizeShell(command);
|
|
203
145
|
const out = [];
|
|
204
|
-
// 命令段内状态:cmd = 当前命令词(null = 还在找命令词),args = 该段非 flag 参数。
|
|
205
146
|
let cmd = null;
|
|
206
147
|
let pendingMulti = [];
|
|
207
148
|
let pendingDest = null;
|
|
@@ -226,8 +167,6 @@ export function bashWriteTargets(command) {
|
|
|
226
167
|
afterDoubleDash = false;
|
|
227
168
|
continue;
|
|
228
169
|
}
|
|
229
|
-
// 重定向:`[fd]>[>] 目标`;heredoc 一律跳过。分隔符不能当目标吃掉
|
|
230
|
-
// (`echo a > ; rm x` 里 `;` 必须保留,否则后半段命令会错位)。
|
|
231
170
|
if (/^(\d*)(>>?)$/.test(t) || t === "<<" || t === "<<<" || /^(\d*)<<<?$/.test(t)) {
|
|
232
171
|
const next = toks[i + 1];
|
|
233
172
|
if (typeof next !== "undefined" && !SEGMENT_SEPS.has(next)) {
|
|
@@ -245,25 +184,24 @@ export function bashWriteTargets(command) {
|
|
|
245
184
|
if (WRAPPER_WORDS.has(t))
|
|
246
185
|
continue;
|
|
247
186
|
if (t.includes("=") && !t.startsWith("-"))
|
|
248
|
-
continue;
|
|
187
|
+
continue;
|
|
249
188
|
cmd = t;
|
|
250
189
|
if (cmd === "xargs")
|
|
251
|
-
cmd = "\0xargs-opaque";
|
|
190
|
+
cmd = "\0xargs-opaque";
|
|
252
191
|
continue;
|
|
253
192
|
}
|
|
254
193
|
if (cmd === "\0xargs-opaque")
|
|
255
194
|
continue;
|
|
256
195
|
if (!afterDoubleDash && t.startsWith("-") && t.length > 1)
|
|
257
|
-
continue;
|
|
196
|
+
continue;
|
|
258
197
|
if (MULTI_TARGET_WRITES.has(cmd))
|
|
259
198
|
pendingMulti.push(t);
|
|
260
199
|
else if (DEST_ONLY_WRITES.has(cmd))
|
|
261
|
-
pendingDest = t;
|
|
200
|
+
pendingDest = t;
|
|
262
201
|
}
|
|
263
202
|
flush();
|
|
264
203
|
return out.filter((p) => p !== "" && !isNonFileTarget(p));
|
|
265
204
|
}
|
|
266
|
-
/** 转录消息 → 触碰文件集(按次数降序,次数相同按最后时间降序)。 */
|
|
267
205
|
export function extractTouches(messages, opts) {
|
|
268
206
|
if (!Array.isArray(messages) || messages.length === 0)
|
|
269
207
|
return [];
|
|
@@ -291,7 +229,6 @@ export function extractTouches(messages, opts) {
|
|
|
291
229
|
for (const call of toolCallsOf(m)) {
|
|
292
230
|
const name = call.name;
|
|
293
231
|
if (name === "patch") {
|
|
294
|
-
// patch 的目标路径在补丁文本里(无 args.path),按段头/MV 提取
|
|
295
232
|
const args = call.args;
|
|
296
233
|
if (args && typeof args.patch === "string") {
|
|
297
234
|
for (const p of patchWriteTargets(args.patch))
|
|
@@ -313,7 +250,6 @@ export function extractTouches(messages, opts) {
|
|
|
313
250
|
}
|
|
314
251
|
}
|
|
315
252
|
}
|
|
316
|
-
// `!` 命令 / bashExecution 转录消息:命令在顶层 command 字段。
|
|
317
253
|
if (m.role === "bashExecution" && typeof m.command === "string") {
|
|
318
254
|
for (const p of bashWriteTargets(m.command))
|
|
319
255
|
bump(p, ts);
|
|
@@ -323,9 +259,6 @@ export function extractTouches(messages, opts) {
|
|
|
323
259
|
.map(([path, e]) => ({ path, count: e.count, lastTs: e.lastTs }))
|
|
324
260
|
.sort((a, b) => b.count - a.count || b.lastTs - a.lastTs);
|
|
325
261
|
}
|
|
326
|
-
/** 两个触碰集求并(sidecar 合并用):sidecar 是历史快照、live 是当前全量,
|
|
327
|
-
* 两者消息集重叠,所以 count 取大不相加 —— 相加会把同一批触碰算两遍。
|
|
328
|
-
* 压缩后次数只能保证是下界(presence 与 lastTs 精确,交集计算不受影响)。 */
|
|
329
262
|
export function unionTouchLists(a, b) {
|
|
330
263
|
const acc = new Map();
|
|
331
264
|
for (const f of [...(Array.isArray(a) ? a : []), ...(Array.isArray(b) ? b : [])]) {
|
|
@@ -348,22 +281,18 @@ export function unionTouchLists(a, b) {
|
|
|
348
281
|
.map(([path, e]) => ({ path, count: e.count, lastTs: e.lastTs }))
|
|
349
282
|
.sort((x, y) => y.count - x.count || y.lastTs - x.lastTs);
|
|
350
283
|
}
|
|
351
|
-
/** 两个触碰集的交集:取 a 中同时出现在 b 里的条目(计数/时间沿用 a 的)。 */
|
|
352
284
|
export function intersectTouches(a, b) {
|
|
353
285
|
if (!Array.isArray(a) || !Array.isArray(b) || a.length === 0 || b.length === 0)
|
|
354
286
|
return [];
|
|
355
287
|
const inB = new Set(b.map((f) => f.path));
|
|
356
288
|
return a.filter((f) => inB.has(f.path));
|
|
357
289
|
}
|
|
358
|
-
/** 单条触碰格式化(供提醒用):条目超长时优先保路径完整 —— 路径永不截断
|
|
359
|
-
* (半截路径不可用,还可能误导 AI 去碰错文件),只丢 `×N` 后缀。 */
|
|
360
290
|
export function formatTouchEntry(f, perItemCap = 60) {
|
|
361
291
|
const full = f.count > 1 ? `${f.path} ×${f.count}` : f.path;
|
|
362
292
|
if (full.length <= perItemCap)
|
|
363
293
|
return full;
|
|
364
294
|
return f.path;
|
|
365
295
|
}
|
|
366
|
-
/** 触碰集紧凑格式化:前 N 条完整路径 + `… (+K)` 计数(静默丢弃是大忌)。 */
|
|
367
296
|
export function formatTouchesCompact(files, opts) {
|
|
368
297
|
if (!Array.isArray(files) || files.length === 0)
|
|
369
298
|
return "";
|
|
@@ -1,28 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 悬空 toolCall 检测与修复(issue #280、issue #332)。
|
|
3
|
-
*
|
|
4
|
-
* 背景:流式中模型卡死 → 工具看门狗 abort 无效 → forceResetConversation
|
|
5
|
-
* dispose 在飞运行时并从磁盘重建。内存里未落盘的工具结果静默蒸发,
|
|
6
|
-
* 会话文件尾留下一个「有调用、无结果」的悬空 toolCall;重建后继续
|
|
7
|
-
* prompt 会把非法转录链喂给 provider——请求有发起迹象但零落盘、零报错,
|
|
8
|
-
* 用户在往黑洞里打字。
|
|
9
|
-
*
|
|
10
|
-
* 缺陷与收紧(issue #332):
|
|
11
|
-
* 不能将全文件所有找不到 toolResult 的调用一律视为悬空并追加合成结果:
|
|
12
|
-
* 1. 上线检查:若 assistant 的 stopReason 是 "error" 或 "aborted",
|
|
13
|
-
* pi 在发送给 provider 前会丢弃该 assistant(transformMessages)。
|
|
14
|
-
* 该调用属于永不上线的幽灵调用,补合成结果反而会构造出没有前置 tool_calls
|
|
15
|
-
* 的孤儿 role: "tool",导致 provider 400(DeepSeek/OpenAI Responses 等);
|
|
16
|
-
* 2. 分支检查:会话文件由树状结构追加存储,老分支被遗弃的 toolCall 不在当前分支上;
|
|
17
|
-
* 若在文件尾(当前活跃分支末尾)追加老分支调用的合成结果,也会制造孤儿 toolResult。
|
|
18
|
-
* 因此落盘修复必须沿当前活跃分支(lastId 开始回溯)定位尾部生效 assistant。
|
|
19
|
-
*
|
|
20
|
-
* 本模块:
|
|
21
|
-
* - findDanglingToolCalls:纯函数,消息/条目数组里找「有调用、无后继结果」的 toolCall;
|
|
22
|
-
* - tailAssistantToolCallIds:沿当前分支回溯,定位尾部会上线的 assistant 的 toolCallId 集合;
|
|
23
|
-
* - healDanglingToolCallFile:落盘版,仅针对当前分支尾部生效的悬空调用追加合成 toolResult;
|
|
24
|
-
* - 合成结果文案:danglingToolResultText(cause)(按成因归因,中英各一,toolResult content 只带一条文本)。
|
|
25
|
-
*/
|
|
26
1
|
import { appendFileSync, existsSync, readFileSync, statSync } from "node:fs";
|
|
27
2
|
import { randomUUID } from "node:crypto";
|
|
28
3
|
const DANGLING_TEXT = {
|
|
@@ -35,7 +10,6 @@ const DANGLING_TEXT = {
|
|
|
35
10
|
en: "(System: the previous run was interrupted by a service restart and this tool call never returned — it may already have executed. A synthetic result was inserted automatically to keep the transcript valid. Confirm before re-running anything with side effects such as deletes, deploys or pushes.)",
|
|
36
11
|
},
|
|
37
12
|
};
|
|
38
|
-
/** 合成 toolResult 的文本(中英各一,content 只带一条文本)。 */
|
|
39
13
|
export function danglingToolResultText(cause = "generic") {
|
|
40
14
|
const t = DANGLING_TEXT[cause];
|
|
41
15
|
return `${t.zh}\n${t.en}`;
|
|
@@ -67,7 +41,6 @@ function toolResultIdsOfMessage(msg) {
|
|
|
67
41
|
const m = msg;
|
|
68
42
|
if (m.role === "toolResult" && typeof m.toolCallId === "string")
|
|
69
43
|
ids.add(m.toolCallId);
|
|
70
|
-
// 兼容:个别版本把结果放在 content 块里。
|
|
71
44
|
if (Array.isArray(m.content)) {
|
|
72
45
|
for (const b of m.content) {
|
|
73
46
|
if (typeof b !== "object" || b === null)
|
|
@@ -89,11 +62,6 @@ function messagesOfEntries(entries) {
|
|
|
89
62
|
return e;
|
|
90
63
|
});
|
|
91
64
|
}
|
|
92
|
-
/**
|
|
93
|
-
* 找悬空 toolCall:出现过调用、但之后没有任何 toolResult 与之配对的。
|
|
94
|
-
* 输入既可以是 Message[](内存 agent.state.messages),也可以是
|
|
95
|
-
* SessionManager entry[](带 { message } 包装的落盘条目)——统一按顺序扫。
|
|
96
|
-
*/
|
|
97
65
|
export function findDanglingToolCalls(messagesOrEntries) {
|
|
98
66
|
const messages = messagesOfEntries(messagesOrEntries);
|
|
99
67
|
const calls = [];
|
|
@@ -121,19 +89,6 @@ export function findDanglingToolCalls(messagesOrEntries) {
|
|
|
121
89
|
}
|
|
122
90
|
return out;
|
|
123
91
|
}
|
|
124
|
-
/**
|
|
125
|
-
* 沿当前分支从 lastId 往前回溯,定位当前分支尾部生效 assistant 的 toolCallId 集合(issue #332)。
|
|
126
|
-
*
|
|
127
|
-
* 两个守卫条件:
|
|
128
|
-
* 1. 分支检查:严格沿 parentId 链回溯,老分支(不在当前分支路径上)的条目绝不纳入,
|
|
129
|
-
* 避免在当前分支尾部追加针对老分支调用的合成结果而制造孤儿 toolResult;
|
|
130
|
-
* 2. 上线检查:若遇到的 assistant 是 stopReason: "error" | "aborted",
|
|
131
|
-
* 说明该 assistant 已被中断/报错,pi 在发送给模型前会直接跳过丢弃它(transformMessages),
|
|
132
|
-
* 其 toolCall 属于绝不上线的幽灵调用,必须跳过且绝不能为其补结果。
|
|
133
|
-
*
|
|
134
|
-
* 此外,若在回溯中遇到了 user 消息,说明当前尾部已经退出该回合(例如最新是 user 消息),
|
|
135
|
-
* 绝不能跨过 user 消息去为更早的 assistant 补 toolResult,应立即停止。
|
|
136
|
-
*/
|
|
137
92
|
export function tailAssistantToolCallIds(entries, lastId) {
|
|
138
93
|
if (!lastId)
|
|
139
94
|
return new Set();
|
|
@@ -156,14 +111,12 @@ export function tailAssistantToolCallIds(entries, lastId) {
|
|
|
156
111
|
if (msg && typeof msg === "object" && "role" in msg) {
|
|
157
112
|
const m = msg;
|
|
158
113
|
if (m.role === "user") {
|
|
159
|
-
// 跨入更早的用户回合,尾部无正在等待结果的 assistant
|
|
160
114
|
break;
|
|
161
115
|
}
|
|
162
116
|
if (m.role === "assistant") {
|
|
163
117
|
if (m.stopReason !== "error" && m.stopReason !== "aborted") {
|
|
164
118
|
return new Set(toolCallsOfMessage(m).map((c) => c.toolCallId));
|
|
165
119
|
}
|
|
166
|
-
// 尾部最新 assistant 处于 aborted/error 状态,幽灵调用不上线;且不可越过它去修更早回合
|
|
167
120
|
break;
|
|
168
121
|
}
|
|
169
122
|
}
|
|
@@ -172,14 +125,7 @@ export function tailAssistantToolCallIds(entries, lastId) {
|
|
|
172
125
|
}
|
|
173
126
|
return new Set();
|
|
174
127
|
}
|
|
175
|
-
/**
|
|
176
|
-
* 落盘修复:向会话文件尾追加合成 toolResult(仅针对当前分支尾部生效的悬空调用),
|
|
177
|
-
* parentId 链式接在当前尾行之后。append-only——历史字节不动,无需备份。
|
|
178
|
-
* 返回追加条数(0 = 健康,无需处理;-1 = 文件不可读/不可写)。
|
|
179
|
-
*/
|
|
180
128
|
export function healDanglingToolCallFile(filePath, cause = "generic") {
|
|
181
|
-
// 健康指纹命中:文件自上次判定"无悬空调用"后 mtime/size 未变,结果必然仍为 0,
|
|
182
|
-
// 跳过整文件同步读取(打开大转录时这是阻塞事件循环的主要来源之一)。
|
|
183
129
|
let sig = null;
|
|
184
130
|
try {
|
|
185
131
|
const st = statSync(filePath);
|
|
@@ -204,10 +150,8 @@ export function healDanglingToolCallFile(filePath, cause = "generic") {
|
|
|
204
150
|
healthyDanglingCache.delete(filePath);
|
|
205
151
|
return result;
|
|
206
152
|
}
|
|
207
|
-
/** 已判定无悬空调用的文件指纹(filePath -> `${mtimeMs}:${size}`,LRU)。 */
|
|
208
153
|
const healthyDanglingCache = new Map();
|
|
209
154
|
const HEALTHY_DANGLING_CACHE_MAX = 512;
|
|
210
|
-
/** 指纹命中即续期(LRU)。 */
|
|
211
155
|
export function isDanglingHealthyCached(filePath, sig) {
|
|
212
156
|
if (healthyDanglingCache.get(filePath) !== sig)
|
|
213
157
|
return false;
|
|
@@ -228,13 +172,10 @@ export function rememberHealthyDangling(filePath, sig) {
|
|
|
228
172
|
export function forgetHealthyDangling(filePath) {
|
|
229
173
|
healthyDanglingCache.delete(filePath);
|
|
230
174
|
}
|
|
231
|
-
/** 测试用:清空健康指纹缓存。 */
|
|
232
175
|
export function resetHealthyDanglingCacheForTest() {
|
|
233
176
|
healthyDanglingCache.clear();
|
|
234
177
|
}
|
|
235
|
-
/** 长行只取开头的这段做头字段提取(type/id/parentId 在 SDK 落盘格式里总是最前面几个键)。 */
|
|
236
178
|
const HEADER_SCAN_CHARS = 260;
|
|
237
|
-
/** 不超过此长度的行直接完整解析(成本可忽略)。 */
|
|
238
179
|
const FULL_PARSE_MAX_LINE = 512;
|
|
239
180
|
function parseLineFully(line) {
|
|
240
181
|
try {
|
|
@@ -245,11 +186,6 @@ function parseLineFully(line) {
|
|
|
245
186
|
return null;
|
|
246
187
|
}
|
|
247
188
|
}
|
|
248
|
-
/**
|
|
249
|
-
* 取一行的 id / parentId。长行(数十 KB~数 MB 的工具输出、图片)只扫开头一小段:
|
|
250
|
-
* 要求 id 与 parentId 都出现在第一个嵌套 `{` 之前,确保匹配的是顶层键;否则回退完整解析。
|
|
251
|
-
* 返回 null = 该行不是合法 JSON 对象(脏行,SDK 加载时同样跳过)。
|
|
252
|
-
*/
|
|
253
189
|
function lineHeader(line) {
|
|
254
190
|
if (line.length > FULL_PARSE_MAX_LINE) {
|
|
255
191
|
const head = line.slice(0, HEADER_SCAN_CHARS);
|
|
@@ -273,20 +209,6 @@ function lineHeader(line) {
|
|
|
273
209
|
entry,
|
|
274
210
|
};
|
|
275
211
|
}
|
|
276
|
-
/**
|
|
277
|
-
* 在转录文本上检测并落盘修复当前分支尾部的悬空 toolCall(语义同原全量版本)。
|
|
278
|
-
*
|
|
279
|
-
* 按需解析:先只取每行的 id/parentId(长行只扫行首),再沿 parentId 从尾部回溯,
|
|
280
|
-
* 只完整解析回溯经过的行与尾部 assistant 之后的行。健康长转录(最常见:尾部是
|
|
281
|
-
* 没有工具调用的 assistant 或 user)因此只需完整解析末尾几行,而不是逐行 JSON.parse
|
|
282
|
-
* 整个文件。
|
|
283
|
-
*
|
|
284
|
-
* 与全量版本等价性:某个 toolCallId 悬空 ⇔ 存在一次出现之后没有对应结果。尾部
|
|
285
|
-
* assistant 之前的同名调用若缺后继结果,尾部那次必然也缺,所以只看尾部 assistant
|
|
286
|
-
* 及其之后的行即可得到相同集合。
|
|
287
|
-
*
|
|
288
|
-
* 返回追加条数(0 = 健康;-1 = 写入失败)。
|
|
289
|
-
*/
|
|
290
212
|
export function healDanglingToolCallsInText(filePath, raw, cause = "generic") {
|
|
291
213
|
const lines = raw.split("\n");
|
|
292
214
|
const headers = new Array(lines.length).fill(null);
|
|
@@ -297,7 +219,6 @@ export function healDanglingToolCallsInText(filePath, raw, cause = "generic") {
|
|
|
297
219
|
continue;
|
|
298
220
|
const h = lineHeader(line);
|
|
299
221
|
headers[i] = h;
|
|
300
|
-
// 同名 id:后出现者覆盖(与全量版本 Map.set 语义一致)
|
|
301
222
|
if (h?.id)
|
|
302
223
|
byId.set(h.id, i);
|
|
303
224
|
}
|
|
@@ -309,8 +230,6 @@ export function healDanglingToolCallsInText(filePath, raw, cause = "generic") {
|
|
|
309
230
|
h.entry = parseLineFully(lines[i]);
|
|
310
231
|
return h.entry;
|
|
311
232
|
};
|
|
312
|
-
// lastId = 文件里最后一条「能解析且带字符串 id」的条目。头字段提取不验证整行 JSON,
|
|
313
|
-
// 崩溃残留的半截尾行可能被误认,所以这里从尾部往前逐行完整解析确认。
|
|
314
233
|
let lastId = null;
|
|
315
234
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
316
235
|
if (!headers[i])
|
|
@@ -327,7 +246,6 @@ export function healDanglingToolCallsInText(filePath, raw, cause = "generic") {
|
|
|
327
246
|
}
|
|
328
247
|
if (!lastId)
|
|
329
248
|
return 0;
|
|
330
|
-
// 沿当前分支回溯,定位尾部生效 assistant(规则同 tailAssistantToolCallIds)。
|
|
331
249
|
let tailIndex = -1;
|
|
332
250
|
let tailIds = new Set();
|
|
333
251
|
const seen = new Set();
|