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
|
@@ -2,11 +2,9 @@ import { persistContextEvidence, contextEvidenceReference } from "./context-evid
|
|
|
2
2
|
const READ_ONLY_TOOLS = new Set(["read", "grep", "find"]);
|
|
3
3
|
const MIN_DUPLICATE_CHARS = 4096;
|
|
4
4
|
const evidenceReady = new WeakSet();
|
|
5
|
-
/** Enable only when the SDK permission hook and compaction adapters are compatible. */
|
|
6
5
|
export function enableRequestEvidence(sessionManager) {
|
|
7
6
|
evidenceReady.add(sessionManager);
|
|
8
7
|
}
|
|
9
|
-
/** Keep the first exact result, so appending messages does not rewrite earlier requests. */
|
|
10
8
|
export function deduplicateRequestContext(messages) {
|
|
11
9
|
const calls = new Map();
|
|
12
10
|
const originals = new Map();
|
|
@@ -14,7 +12,6 @@ export function deduplicateRequestContext(messages) {
|
|
|
14
12
|
for (let index = 0; index < messages.length; index++) {
|
|
15
13
|
const message = messages[index];
|
|
16
14
|
if (message.role === "user") {
|
|
17
|
-
// A human may have changed workspace files outside the agent.
|
|
18
15
|
calls.clear();
|
|
19
16
|
originals.clear();
|
|
20
17
|
continue;
|
|
@@ -22,7 +19,6 @@ export function deduplicateRequestContext(messages) {
|
|
|
22
19
|
if (message.role === "assistant") {
|
|
23
20
|
const toolCalls = message.content.filter((block) => block.type === "toolCall");
|
|
24
21
|
if (toolCalls.some((block) => !READ_ONLY_TOOLS.has(block.name))) {
|
|
25
|
-
// Mixed/parallel batches cannot establish a reliable read-before-write order.
|
|
26
22
|
calls.clear();
|
|
27
23
|
originals.clear();
|
|
28
24
|
continue;
|
|
@@ -35,7 +31,6 @@ export function deduplicateRequestContext(messages) {
|
|
|
35
31
|
if (message.role !== "toolResult")
|
|
36
32
|
continue;
|
|
37
33
|
if (!READ_ONLY_TOOLS.has(message.toolName)) {
|
|
38
|
-
// Unknown tools (including codemode and plugins) may mutate the workspace.
|
|
39
34
|
calls.clear();
|
|
40
35
|
originals.clear();
|
|
41
36
|
continue;
|
|
@@ -45,11 +40,9 @@ export function deduplicateRequestContext(messages) {
|
|
|
45
40
|
continue;
|
|
46
41
|
calls.delete(message.toolCallId);
|
|
47
42
|
const previous = originals.get(call);
|
|
48
|
-
// Even an ineligible result invalidates the previous observation for this query.
|
|
49
43
|
originals.delete(call);
|
|
50
44
|
if (message.isError || !message.content.length || message.content.some((block) => block.type !== "text"))
|
|
51
45
|
continue;
|
|
52
|
-
// Unknown/signed block fields and structured payloads must retain provider semantics.
|
|
53
46
|
if (message.content.some((block) => Object.keys(block).some((key) => key !== "type" && key !== "text")))
|
|
54
47
|
continue;
|
|
55
48
|
if ("structuredContent" in message)
|
|
@@ -76,7 +69,6 @@ export function deduplicateRequestContext(messages) {
|
|
|
76
69
|
}
|
|
77
70
|
return output;
|
|
78
71
|
}
|
|
79
|
-
/** Conservative estimates; never claim this is the provider's tokenizer. */
|
|
80
72
|
export function requestMessageBudget(model, systemPrompt, tools) {
|
|
81
73
|
const window = model?.contextWindow ?? 128000;
|
|
82
74
|
const output = Math.min(model?.maxTokens ?? 16384, Math.floor(window / 4));
|
|
@@ -157,7 +149,6 @@ export function requestContextExtension(pi) {
|
|
|
157
149
|
}
|
|
158
150
|
catch {
|
|
159
151
|
ctx.signal?.throwIfAborted();
|
|
160
|
-
// Optimization must never prevent a provider request.
|
|
161
152
|
return { messages: event.messages };
|
|
162
153
|
}
|
|
163
154
|
});
|
|
@@ -33,12 +33,7 @@ import { dirname, join } from "node:path";
|
|
|
33
33
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
34
34
|
import { compareVersions, sdkCopies } from "./sdk-origin.js";
|
|
35
35
|
const PKG = "@earendil-works/pi-coding-agent";
|
|
36
|
-
/** 显式强制自带副本的取值(旧默认;可复现、CI 覆盖的那份)。 */
|
|
37
36
|
const BUNDLED_MODES = new Set(["bundled", "0", "off", "false", "no"]);
|
|
38
|
-
/**
|
|
39
|
-
* 找出传入副本列表中的随包自带副本(如果有的话)。
|
|
40
|
-
* 自带副本必须位于 pi-web-ui 自身包根下的 node_modules/@earendil-works/pi-coding-agent/package.json。
|
|
41
|
-
*/
|
|
42
37
|
export function findBundledCopy(copies, fromFile = import.meta.url) {
|
|
43
38
|
const filePath = fromFile.startsWith("file:") ? fileURLToPath(fromFile) : fromFile;
|
|
44
39
|
let cur = dirname(filePath);
|
|
@@ -66,10 +61,6 @@ export function findBundledCopy(copies, fromFile = import.meta.url) {
|
|
|
66
61
|
const expectedBundledPath = join(pkgRoot, "node_modules", PKG, "package.json").replace(/\\/g, "/");
|
|
67
62
|
return copies.find((c) => c.path.replace(/\\/g, "/") === expectedBundledPath) ?? null;
|
|
68
63
|
}
|
|
69
|
-
/**
|
|
70
|
-
* 健全性检查:外部 SDK 副本是否完整可用(防止因中断安装/文件截断导致 SyntaxError 搞崩服务)。
|
|
71
|
-
* 纯内存虚拟测试(文件在磁盘上不存在)默认视为可用,避免破坏单测。
|
|
72
|
-
*/
|
|
73
64
|
export function isSdkCopyUsable(copy) {
|
|
74
65
|
if (!existsSync(copy.path))
|
|
75
66
|
return true;
|
|
@@ -79,12 +70,10 @@ export function isSdkCopyUsable(copy) {
|
|
|
79
70
|
const info = JSON.parse(raw);
|
|
80
71
|
if (info?.name && info.name !== PKG)
|
|
81
72
|
return false;
|
|
82
|
-
// 检查入口文件是否存在且非空
|
|
83
73
|
const mainRel = typeof info?.main === "string" ? info.main : "dist/index.js";
|
|
84
74
|
const mainFile = join(pkgDir, mainRel);
|
|
85
75
|
if (!existsSync(mainFile) || statSync(mainFile).size === 0)
|
|
86
76
|
return false;
|
|
87
|
-
// 检查核心 agent-session.js(若存在则防截断)
|
|
88
77
|
const sessionFile = join(pkgDir, "dist", "core", "agent-session.js");
|
|
89
78
|
if (existsSync(sessionFile)) {
|
|
90
79
|
const stat = statSync(sessionFile);
|
|
@@ -109,25 +98,17 @@ export function isSdkCopyUsable(copy) {
|
|
|
109
98
|
return false;
|
|
110
99
|
}
|
|
111
100
|
}
|
|
112
|
-
/**
|
|
113
|
-
* 该用哪一份对外解析(纯函数,便于单测)。
|
|
114
|
-
* `copies` 按 Node 的解析顺序,`bundledCopy` 为识别到的随包自带副本(null = 无自带副本)。
|
|
115
|
-
* 返回 null = 保持默认(用自带副本兜底)。
|
|
116
|
-
*/
|
|
117
101
|
export function pickGlobalSdk(copies, mode, bundledCopy = copies[0] ?? null, isUsable = isSdkCopyUsable) {
|
|
118
102
|
if (BUNDLED_MODES.has((mode ?? "global").trim().toLowerCase()))
|
|
119
103
|
return null;
|
|
120
104
|
const validCopies = copies.filter(isUsable);
|
|
121
105
|
const validBundled = bundledCopy && isUsable(bundledCopy) ? bundledCopy : null;
|
|
122
|
-
// 显式透传的宿主 SDK 路径(如 extensions/webui.ts 宿主传递,issue #482):若不降级优先选用
|
|
123
106
|
if (process.env.PI_WEB_SDK_DIR) {
|
|
124
107
|
const hostCopy = validCopies.find((c) => dirname(c.path) === process.env.PI_WEB_SDK_DIR);
|
|
125
108
|
if (hostCopy && (!validBundled || compareVersions(hostCopy.version, validBundled.version) >= 0)) {
|
|
126
109
|
return hostCopy;
|
|
127
110
|
}
|
|
128
111
|
}
|
|
129
|
-
// 如果没有随包自带副本(例如 pnpm 隔离安装未包含可选依赖,或轻量部署,issue #562):
|
|
130
|
-
// 机器上只要发现可用副本就必须选用,否则 Node 无法导入 SDK 会报错崩溃。
|
|
131
112
|
if (!validBundled) {
|
|
132
113
|
if (validCopies.length === 0)
|
|
133
114
|
return null;
|
|
@@ -139,7 +120,6 @@ export function pickGlobalSdk(copies, mode, bundledCopy = copies[0] ?? null, isU
|
|
|
139
120
|
}
|
|
140
121
|
return best;
|
|
141
122
|
}
|
|
142
|
-
// 存在自带副本:只考虑比自带副本**严格更新**的外部副本,多份取版本最高的(旧的/同版本的都不折腾)。
|
|
143
123
|
let best = null;
|
|
144
124
|
for (const copy of validCopies) {
|
|
145
125
|
if (copy.path === validBundled.path)
|
|
@@ -151,7 +131,6 @@ export function pickGlobalSdk(copies, mode, bundledCopy = copies[0] ?? null, isU
|
|
|
151
131
|
}
|
|
152
132
|
return best;
|
|
153
133
|
}
|
|
154
|
-
/** 注册钩子;返回实际选中的副本(null = 用自带副本)。 */
|
|
155
134
|
export function registerGlobalSdkPreference(mode = process.env.PI_WEB_SDK, fromFile = import.meta.url) {
|
|
156
135
|
try {
|
|
157
136
|
const copies = sdkCopies(fromFile);
|
|
@@ -167,8 +146,6 @@ export function registerGlobalSdkPreference(mode = process.env.PI_WEB_SDK, fromF
|
|
|
167
146
|
registerHooks({
|
|
168
147
|
resolve(specifier, context, nextResolve) {
|
|
169
148
|
if (specifier === PKG) {
|
|
170
|
-
// 以目标副本的 package.json 为父重新解析:Node 从那里往上找,
|
|
171
|
-
// 第一个命中的就是它自己 —— 等价于「从那个包内部 import 自己」。
|
|
172
149
|
try {
|
|
173
150
|
return nextResolve(specifier, { ...context, parentURL: pathToFileURL(chosen.path).href });
|
|
174
151
|
}
|
|
@@ -181,7 +158,6 @@ export function registerGlobalSdkPreference(mode = process.env.PI_WEB_SDK, fromF
|
|
|
181
158
|
return nextResolve(specifier, context);
|
|
182
159
|
}
|
|
183
160
|
catch {
|
|
184
|
-
// 本地缺少 typebox(如 pnpm 隔离安装)时,从已选中的 pi SDK 目录解析(issue #562)
|
|
185
161
|
try {
|
|
186
162
|
return nextResolve(specifier, { ...context, parentURL: pathToFileURL(chosen.path).href });
|
|
187
163
|
}
|
|
@@ -196,11 +172,9 @@ export function registerGlobalSdkPreference(mode = process.env.PI_WEB_SDK, fromF
|
|
|
196
172
|
return chosen;
|
|
197
173
|
}
|
|
198
174
|
catch {
|
|
199
|
-
// 钩子注册失败(Node 太老 / 环境怪异)→ 静默退回默认解析,绝不影响启动。
|
|
200
175
|
return null;
|
|
201
176
|
}
|
|
202
177
|
}
|
|
203
|
-
// ---- 副作用:被 `--import` 加载时立刻生效 --------------------------------
|
|
204
178
|
registerBashProcessPatch();
|
|
205
179
|
registerExecutableLookupPatch();
|
|
206
180
|
const used = registerGlobalSdkPreference();
|
|
@@ -589,7 +589,6 @@ export class SandboxManager {
|
|
|
589
589
|
await mkdir(path);
|
|
590
590
|
});
|
|
591
591
|
}
|
|
592
|
-
// Keep the import baseline: subsequent previews continue to show the sandbox's changes.
|
|
593
592
|
return { sandbox: info, sourcePath: info.sourcePath, copiedFiles, deletedFiles };
|
|
594
593
|
}
|
|
595
594
|
catch (error) {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { evaluateSandboxJail } from "./sandbox-service.js";
|
|
2
|
-
/** Only these host capabilities can be sealed. A matching name alone never grants trust. */
|
|
3
2
|
const HOST_CAPABILITIES = new Set(["read", "write", "edit", "edit_soft", "patch", "present_files", "sandbox"]);
|
|
4
|
-
/** Final SDK tool_call guard. Leases belong to the host wrappers, not this hook. */
|
|
5
3
|
export function createSandboxRuntimeGate(getSandbox, cwd) {
|
|
6
4
|
const trusted = new Map();
|
|
7
5
|
let session;
|
|
@@ -35,7 +33,6 @@ export function createSandboxRuntimeGate(getSandbox, cwd) {
|
|
|
35
33
|
},
|
|
36
34
|
};
|
|
37
35
|
}
|
|
38
|
-
/** noExtensions alone still permits explicit paths; keep both locked across reloads. */
|
|
39
36
|
export function sandboxExtensionOptions(sandbox) {
|
|
40
37
|
return sandbox ? { noExtensions: true, additionalExtensionPaths: [] } : {};
|
|
41
38
|
}
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 沙盒项目服务(Sandbox Project Service):
|
|
3
|
-
*
|
|
4
|
-
* 1. 隔离副本工作区管理(`<dataDir>/sandboxes/registry.json` + `<dataDir>/sandboxes/<id>/`):
|
|
5
|
-
* - 支持「空白沙盒」与「导入现有项目」(自动跳过 node_modules/.venv/target 等重型缓存目录与越界软链);
|
|
6
|
-
* - 支持「临时沙盒(用完即删)」与「永久沙盒(持久化保留,随时一键转正)」;
|
|
7
|
-
* - 支持一键重置(还原到初始空白或重新从源项目同步)、另存为正式项目(promote)、将修改写回源项目(applyToSource)、彻底销毁(destroy)。
|
|
8
|
-
*
|
|
9
|
-
* 2. 沙盒安全围栏(Sandbox Jail Gate):
|
|
10
|
-
* - 当会话处于受管沙盒目录内时,所有文件写入/编辑/补丁(write/edit/edit_soft/patch)必须严格落在
|
|
11
|
-
* `sandbox.path` 内部(含祖先目录 realpath 校验,防软链逃逸),越界直接硬拒绝(不走审批放行);
|
|
12
|
-
* - 没有操作系统隔离后端时拒绝宿主 shell、解释器、终端和任意代码执行;
|
|
13
|
-
* - 仅放行来源可信且能力明确的受限文件工具,未知工具和外部副作用默认拒绝。
|
|
14
|
-
*/
|
|
15
1
|
import { existsSync, realpathSync } from "node:fs";
|
|
16
2
|
import { homedir } from "node:os";
|
|
17
3
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
@@ -19,7 +5,6 @@ import * as sandboxJailFs from "node:fs";
|
|
|
19
5
|
import { normalizePathKey } from "./client-state.js";
|
|
20
6
|
import { isConversationTool } from "./conversation-tool-names.js";
|
|
21
7
|
import { pick } from "./i18n.js";
|
|
22
|
-
/** 导入项目进沙盒时默认跳过的重型依赖/构建缓存目录名。 */
|
|
23
8
|
export const SANDBOX_IGNORED_DIRS = new Set([
|
|
24
9
|
"node_modules",
|
|
25
10
|
".venv",
|
|
@@ -47,9 +32,6 @@ export function isSameOrSubpath(childAbs, parentAbs) {
|
|
|
47
32
|
const p = toComparablePath(parentAbs);
|
|
48
33
|
return c === p || c.startsWith(p + "/");
|
|
49
34
|
}
|
|
50
|
-
/**
|
|
51
|
-
* 解析目标路径并校验是否严格位于 `sandboxRoot` 内部(含祖先目录 realpath 校验,防软链逃逸)。
|
|
52
|
-
*/
|
|
53
35
|
export function isStrictlyInsideSandbox(targetPath, cwd, sandboxRoot) {
|
|
54
36
|
if (!targetPath || typeof targetPath !== "string")
|
|
55
37
|
return false;
|
|
@@ -63,11 +45,9 @@ export function isStrictlyInsideSandbox(targetPath, cwd, sandboxRoot) {
|
|
|
63
45
|
: trimmed;
|
|
64
46
|
const resolvedTarget = isAbsolute(expanded) ? resolve(expanded) : resolve(cwd, expanded);
|
|
65
47
|
const resolvedSandbox = resolve(sandboxRoot);
|
|
66
|
-
// 1. 词法路径必须在 sandboxRoot 之内
|
|
67
48
|
if (!isSameOrSubpath(resolvedTarget, resolvedSandbox)) {
|
|
68
49
|
return false;
|
|
69
50
|
}
|
|
70
|
-
// 2. 真实路径(realpath)校验:沿目标路径向上找到第一个已存在的祖先目录,防止通过沙盒内软链写到外部
|
|
71
51
|
let realSandbox;
|
|
72
52
|
try {
|
|
73
53
|
if (sandboxJailFs.lstatSync(resolvedSandbox).isSymbolicLink())
|
|
@@ -98,7 +78,6 @@ export function isStrictlyInsideSandbox(targetPath, cwd, sandboxRoot) {
|
|
|
98
78
|
}
|
|
99
79
|
return true;
|
|
100
80
|
}
|
|
101
|
-
/** 从 patch 工具的补丁文本中提取所有涉及的文件路径。 */
|
|
102
81
|
export function extractPatchTargetPaths(patchText) {
|
|
103
82
|
if (!patchText || typeof patchText !== "string")
|
|
104
83
|
return [];
|
|
@@ -115,9 +94,6 @@ export function extractPatchTargetPaths(patchText) {
|
|
|
115
94
|
paths.push(mUnified[1].trim());
|
|
116
95
|
continue;
|
|
117
96
|
}
|
|
118
|
-
// hashline 格式段头(本仓 patch 工具实际消费的唯一格式):[path#TAG] / [path]。
|
|
119
|
-
// 不识别的话 hashline 补丁提取出 0 个目标 → 围栏检查整体空转,patch 路径
|
|
120
|
-
// 只剩 hashline-engine 的词法 cwd 限制(无 realpath,沙盒内软链可逃逸)
|
|
121
97
|
const mHashline = rawLine.match(/^\s*\[([^#\]]+)(?:#[0-9a-fA-F]{4})?\]\s*$/);
|
|
122
98
|
if (mHashline?.[1]?.trim()) {
|
|
123
99
|
paths.push(mHashline[1].trim());
|
|
@@ -125,7 +101,6 @@ export function extractPatchTargetPaths(patchText) {
|
|
|
125
101
|
}
|
|
126
102
|
return paths;
|
|
127
103
|
}
|
|
128
|
-
/** Copy workspaces are not an OS execution boundary. Capabilities are opt-in. */
|
|
129
104
|
const SANDBOX_MANAGEMENT_ACTIONS = new Set([
|
|
130
105
|
"list",
|
|
131
106
|
"create",
|
|
@@ -136,13 +111,7 @@ const SANDBOX_MANAGEMENT_ACTIONS = new Set([
|
|
|
136
111
|
"apply_to_source",
|
|
137
112
|
"destroy",
|
|
138
113
|
]);
|
|
139
|
-
/** Reject links (including dangling links), special files and Windows alternate streams.
|
|
140
|
-
* This is a preflight for trusted local file tools, not protection against a hostile
|
|
141
|
-
* process racing filesystem changes; arbitrary host execution is therefore denied.
|
|
142
|
-
*/
|
|
143
114
|
function sandboxJailPath(raw, cwd, root) {
|
|
144
|
-
// SDK file tools strip a leading @ and normalize Unicode spaces. Refuse
|
|
145
|
-
// alternate spellings rather than checking a different path from execution.
|
|
146
115
|
if (typeof raw !== "string" ||
|
|
147
116
|
!raw.trim() ||
|
|
148
117
|
raw !== raw.trim() ||
|
|
@@ -198,8 +167,6 @@ export function evaluateSandboxJail(sandbox, toolName, params, cwd, policy = {})
|
|
|
198
167
|
}
|
|
199
168
|
if (!sandboxJailPath(".", cwd, sandbox.path))
|
|
200
169
|
return deny("Sandbox workspace is unavailable or outside its boundary.");
|
|
201
|
-
// The trusted host must validate both endpoints against the captured sandbox identity.
|
|
202
|
-
// Tool arguments cannot grant trust or select a different security boundary.
|
|
203
170
|
if (toolName === "communicate") {
|
|
204
171
|
return typeof p.action === "string" && ["read", "send", "request", "reply", "escalate"].includes(p.action)
|
|
205
172
|
? null
|
|
@@ -215,7 +182,6 @@ export function evaluateSandboxJail(sandbox, toolName, params, cwd, policy = {})
|
|
|
215
182
|
case "write":
|
|
216
183
|
case "edit":
|
|
217
184
|
case "edit_soft":
|
|
218
|
-
// Validate both aliases when present; different implementations choose different precedence.
|
|
219
185
|
if (p.path !== undefined)
|
|
220
186
|
paths.push(p.path);
|
|
221
187
|
if (p.file_path !== undefined)
|
|
@@ -223,15 +189,11 @@ export function evaluateSandboxJail(sandbox, toolName, params, cwd, policy = {})
|
|
|
223
189
|
break;
|
|
224
190
|
case "grep":
|
|
225
191
|
case "find":
|
|
226
|
-
// Host ownership alone does not make SDK search safe: inherited
|
|
227
|
-
// configuration (e.g. RIPGREP_CONFIG_PATH/--pre) can execute code.
|
|
228
|
-
// Reject direct wrapper calls too, until a safe search backend exists.
|
|
229
192
|
return deny("Search requires a verified safe backend without host execution or inherited executable configuration; trusted tool ownership alone is insufficient.");
|
|
230
193
|
case "patch": {
|
|
231
194
|
if (typeof p.patch !== "string" || !p.patch.trim())
|
|
232
195
|
return deny("Missing patch targets.");
|
|
233
196
|
paths.push(...extractPatchTargetPaths(p.patch));
|
|
234
|
-
// Hashline MV is an additional destination, not a section header.
|
|
235
197
|
for (const line of p.patch.split(/\r?\n/)) {
|
|
236
198
|
const move = line.trim().match(/^MV\s+([^\s]+)/i);
|
|
237
199
|
if (move)
|
|
@@ -253,9 +215,6 @@ export function evaluateSandboxJail(sandbox, toolName, params, cwd, policy = {})
|
|
|
253
215
|
}
|
|
254
216
|
return null;
|
|
255
217
|
}
|
|
256
|
-
/**
|
|
257
|
-
* 为工具包一层「沙盒硬围栏」:当 `getSandbox()` 返回非空时,对越界写操作与源项目触达直接硬拒绝。
|
|
258
|
-
*/
|
|
259
218
|
export function withSandboxJailGate(tool, getSandbox, getCwd, getLang, policy = {}, acquireExecution) {
|
|
260
219
|
return {
|
|
261
220
|
...tool,
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* sandbox — AI 智能体侧的隔离沙盒项目管理工具。
|
|
3
|
-
*
|
|
4
|
-
* 支持动作:
|
|
5
|
-
* - list: 列出当前受管的所有沙盒项目,并指出当前工作区是否处于沙盒内;
|
|
6
|
-
* - create: 创建「空白沙盒」或「导入现有项目」的隔离沙盒副本(可选 switchTo 切换工作区,或将返回的 path 传给 subagent cwd);
|
|
7
|
-
* - diff: 对比沙盒与源项目之间的新增/修改/删除文件清单;
|
|
8
|
-
* - reset: 将沙盒重置回初始干净状态(清空或重新从源项目复制);
|
|
9
|
-
* - persist: 将临时沙盒转为永久沙盒;
|
|
10
|
-
* - promote: 将沙盒导出为外部正式项目目录;
|
|
11
|
-
* - apply_to_source: 将导入型沙盒的修改同步写回源项目(强制触发用户审批确认 askApproval);
|
|
12
|
-
* - destroy: 销毁指定沙盒并回收磁盘空间。
|
|
13
|
-
*/
|
|
14
1
|
import { Type } from "typebox";
|
|
15
2
|
import { existsSync } from "node:fs";
|
|
16
3
|
import { homedir } from "node:os";
|
|
@@ -51,7 +38,6 @@ const SandboxParameters = Type.Object({
|
|
|
51
38
|
description: "promote: destination directory path outside sandboxes (must be a new or empty directory).",
|
|
52
39
|
})),
|
|
53
40
|
});
|
|
54
|
-
/** details 摘录中最多携带的文件路径条目数(严格守卫 details ≤ 64KB 预算)。 */
|
|
55
41
|
const MAX_DIFF_FILES_IN_DETAILS = 100;
|
|
56
42
|
export function makeSandboxTool(host, getLang) {
|
|
57
43
|
return {
|
|
@@ -265,7 +251,6 @@ export function makeSandboxTool(host, getLang) {
|
|
|
265
251
|
isError: true,
|
|
266
252
|
};
|
|
267
253
|
}
|
|
268
|
-
// 强制触发人工审批:写回源项目会修改真实工作区文件,绝不允许静默执行
|
|
269
254
|
if (host.askApproval) {
|
|
270
255
|
const diffSummaryZh = [
|
|
271
256
|
diff.added.length > 0 ? `新增 ${diff.added.length}` : "",
|
|
@@ -355,9 +340,6 @@ export function makeSandboxTool(host, getLang) {
|
|
|
355
340
|
isError: true,
|
|
356
341
|
};
|
|
357
342
|
}
|
|
358
|
-
// 销毁会 rm -rf 整个沙盒目录(可能含用户转正后的工作成果),
|
|
359
|
-
// 与 apply_to_source 同样强制人工审批——bash 跑 rm -rf 都会命中
|
|
360
|
-
// 内置审批规则,工具路径不该有绕过口
|
|
361
343
|
if (host.askApproval) {
|
|
362
344
|
const decision = await host.askApproval(toolCallId, SANDBOX_TOOL_NAME, {
|
|
363
345
|
action: "destroy",
|
|
@@ -382,8 +364,6 @@ export function makeSandboxTool(host, getLang) {
|
|
|
382
364
|
};
|
|
383
365
|
}
|
|
384
366
|
}
|
|
385
|
-
// 若当前工作区正好在该沙盒内,先切出去(源项目优先,空白沙盒回退
|
|
386
|
-
// homedir——否则销毁后 cwd 悬空,后续 bash/read/write 全部 ENOENT)
|
|
387
367
|
if (activeSbx?.id === targetInfo.id) {
|
|
388
368
|
await host.setCwd(targetInfo.sourcePath && existsSync(targetInfo.sourcePath) ? targetInfo.sourcePath : homedir());
|
|
389
369
|
}
|
|
@@ -1,38 +1,14 @@
|
|
|
1
|
-
// ---------------------------------------------------------------------------
|
|
2
|
-
// schedule-agent-tool.ts — 把内置调度器暴露给 Agent(issue #193)
|
|
3
|
-
// ---------------------------------------------------------------------------
|
|
4
|
-
// 背景:pi-web-ui 早有完整调度基建(SchedulerStore:cron/间隔触发+持久化+
|
|
5
|
-
// 无头执行,见 scheduler-tasks.ts),但只停留在插件 API 与图形面板层面 ——
|
|
6
|
-
// AI 被用户要求“每小时检查一次”“半小时后提醒我”时手里没有工具,只能用
|
|
7
|
-
// sleep 死循环假装答应(休眠的会话根本推不回消息)。
|
|
8
|
-
//
|
|
9
|
-
// 本文件注册一个标准 pi 引擎 customTool(DSH 引擎无 customTool 注册面,不接):
|
|
10
|
-
// schedule(action="create") → 建任务(默认绑定发起对话+单次,用熟即删);
|
|
11
|
-
// schedule(action="list") → 看全部任务(含下次触发/上次结果);
|
|
12
|
-
// schedule(action="cancel") → 按 id 删任务。
|
|
13
|
-
// (历史上是 schedule_task / schedule_list / schedule_cancel 三个独立工具,已合并为
|
|
14
|
-
// 单 action 工具以减少工具条目与上下文开销;旧工具名仍在持久化配置迁移里兼容。)
|
|
15
|
-
// 到期执行走 index.ts 的 executor:目标对话还在 → steer 语义唤醒它(不切用户
|
|
16
|
-
// 当前对话);不在了(关闭/重启)→ 回落原有无头执行;单次任务触发后自动删除。
|
|
17
|
-
//
|
|
18
|
-
// 文案约定:工具 definition(description/promptSnippet/promptGuidelines)为纯英文;per-call
|
|
19
|
-
// 返回文本按 lang 取 pick(lang, zh, en, key, vars),缺表回落英文内联。
|
|
20
|
-
// ---------------------------------------------------------------------------
|
|
21
1
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
22
2
|
import { Type } from "typebox";
|
|
23
3
|
import { pick } from "./i18n.js";
|
|
24
4
|
import { SCHEDULE_TOOL_NAME } from "./tool-manager.js";
|
|
25
5
|
import { computeNextFire, describeIntervalMs, SCHEDULER_MIN_INTERVAL_MS, SchedulerValidationError, } from "./scheduler-tasks.js";
|
|
26
6
|
import { parseCronSpec } from "./plugin-schedule.js";
|
|
27
|
-
/** 用户写法 → 调度规格。纯函数,可单测。
|
|
28
|
-
* 收:5 字段 cron("0 * * * *")、相对时间("in 30m" / "in 1h" / "in 2d")、
|
|
29
|
-
* 裸时长("30m" / "1h",裸数字按分钟)。单位 s/m/h/d/w(大小写不敏感)。 */
|
|
30
7
|
export function parseScheduleSpec(raw) {
|
|
31
8
|
const s = String(raw ?? "").trim();
|
|
32
9
|
if (!s)
|
|
33
10
|
throw new Error("empty");
|
|
34
11
|
const single = s.replace(/\s+/g, " ");
|
|
35
|
-
// 5 字段即按 cron 试("in 30m"是 2 段,不会误判)。
|
|
36
12
|
if (single.split(" ").length === 5 && parseCronSpec(single)) {
|
|
37
13
|
return { kind: "cron", spec: single };
|
|
38
14
|
}
|
|
@@ -50,7 +26,7 @@ export function parseScheduleSpec(raw) {
|
|
|
50
26
|
? 3_600_000
|
|
51
27
|
: unit.startsWith("d")
|
|
52
28
|
? 86_400_000
|
|
53
|
-
: 7 * 86_400_000;
|
|
29
|
+
: 7 * 86_400_000;
|
|
54
30
|
const ms = Math.floor(n * mult);
|
|
55
31
|
if (!Number.isFinite(ms) || ms <= 0)
|
|
56
32
|
throw new Error(`时长非法:${s}`);
|
|
@@ -66,7 +42,6 @@ function fmtTime(ms, lang) {
|
|
|
66
42
|
return new Date(ms).toISOString();
|
|
67
43
|
}
|
|
68
44
|
}
|
|
69
|
-
/** 任务一行摘要(列表用;cron 显示原样,interval 中文用“每 X”,英文用秒数)。 */
|
|
70
45
|
function taskLine(t, lang) {
|
|
71
46
|
const when = t.kind === "cron"
|
|
72
47
|
? `cron ${t.spec}`
|
|
@@ -183,8 +158,6 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
|
|
|
183
158
|
const name = labelRaw || prompt.split("\n")[0].slice(0, 40) || (isCanvas ? `Canvas ${graphId}` : "定时任务");
|
|
184
159
|
const convId = source?.conversationId ??
|
|
185
160
|
((ownerConversationId ?? "").trim() || String(host.activeConversationId() ?? "").trim());
|
|
186
|
-
// 稳定绑定(issue #231):owner 对话的落盘会话文件 —— 压缩/重启后靠它重认同一会话,
|
|
187
|
-
// 内存对话 id(c1/c2…)只做首选唤醒键。宿主没实现 conversationInfo 时按原来只绑 id。
|
|
188
161
|
let bindCwd = cwd;
|
|
189
162
|
let bindSessionFile = source?.sessionFile ?? "";
|
|
190
163
|
try {
|
|
@@ -199,9 +172,7 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
|
|
|
199
172
|
.slice(0, 1024);
|
|
200
173
|
}
|
|
201
174
|
}
|
|
202
|
-
catch {
|
|
203
|
-
/* 绑定快照尽力而为:拿不到稳定键就按原来的 id 绑定触发 */
|
|
204
|
-
}
|
|
175
|
+
catch { }
|
|
205
176
|
const recurring = p.recurring === true;
|
|
206
177
|
let task;
|
|
207
178
|
try {
|
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 内置定时任务调度(issue #184)。
|
|
3
|
-
*
|
|
4
|
-
* 面向普通用户的图形化调度器:任务 CRUD + cron/间隔触发 + 无头执行 +
|
|
5
|
-
* 执行历史 + 通知。底层 cron 解析复用 plugin-schedule.ts(parseCronSpec /
|
|
6
|
-
* nextCronFire),持久化走 <dataDir>/scheduler-tasks.json(全局共享,
|
|
7
|
-
* 与 client-state.json 同级),执行经调用方注入的 executor(index.ts 接
|
|
8
|
-
* AgentService.chatFromScheduler,无头伪客户端)。
|
|
9
|
-
*
|
|
10
|
-
* 定时策略:单个 10s ticker 检查到期任务(cron 下次触发 / 间隔毫秒),
|
|
11
|
-
* running 集合防重叠;catchUp "once" 在启动时补跑一次漏掉的触发。
|
|
12
|
-
*/
|
|
13
1
|
import { readFileSync } from "node:fs";
|
|
14
2
|
import { join } from "node:path";
|
|
15
3
|
import { nextCronFire, parseCronSpec } from "./plugin-schedule.js";
|
|
16
4
|
import { writeJsonAtomicSync } from "./atomic-file.js";
|
|
17
5
|
export const SCHEDULER_FILE = "scheduler-tasks.json";
|
|
18
|
-
/** 持久间隔底线 60s(与 host.schedule 持久任务同口径,防 token 烧穿)。 */
|
|
19
6
|
export const SCHEDULER_MIN_INTERVAL_MS = 60_000;
|
|
20
7
|
export const SCHEDULER_MAX_INTERVAL_MS = 30 * 24 * 60 * 60 * 1000;
|
|
21
8
|
export const SCHEDULER_HISTORY_MAX = 20;
|
|
@@ -43,7 +30,6 @@ export class SchedulerValidationError extends Error {
|
|
|
43
30
|
this.name = "SchedulerValidationError";
|
|
44
31
|
}
|
|
45
32
|
}
|
|
46
|
-
/** 归一化 + 校验用户输入;非法抛 SchedulerValidationError。纯函数,可单测。 */
|
|
47
33
|
export function normalizeSchedulerInput(input, now = Date.now()) {
|
|
48
34
|
const idRaw = String(input.id ?? "").trim();
|
|
49
35
|
const id = idRaw || randomTaskId();
|
|
@@ -110,8 +96,6 @@ export function normalizeSchedulerInput(input, now = Date.now()) {
|
|
|
110
96
|
const conversationId = String(input.conversationId ?? "")
|
|
111
97
|
.trim()
|
|
112
98
|
.slice(0, 128);
|
|
113
|
-
// 落盘会话文件:稳定身份键(issue #231)。只做归一化(去首尾空白、封顶),
|
|
114
|
-
// 不校验存在性 —— 创建时刻文件可能还没落盘,触发时按它匹配不上即回落。
|
|
115
99
|
const sessionFile = String(input.sessionFile ?? "")
|
|
116
100
|
.trim()
|
|
117
101
|
.slice(0, 1024);
|
|
@@ -136,7 +120,6 @@ export function normalizeSchedulerInput(input, now = Date.now()) {
|
|
|
136
120
|
updatedAt: now,
|
|
137
121
|
};
|
|
138
122
|
}
|
|
139
|
-
/** 下次触发毫秒时间戳;非法/禁用回 null。纯函数,可单测。 */
|
|
140
123
|
export function computeNextFire(task, fromMs) {
|
|
141
124
|
try {
|
|
142
125
|
if (task.kind === "cron") {
|
|
@@ -154,7 +137,6 @@ export function computeNextFire(task, fromMs) {
|
|
|
154
137
|
return null;
|
|
155
138
|
}
|
|
156
139
|
}
|
|
157
|
-
/** 间隔任务的人类可读描述(面板显示用)。纯函数。 */
|
|
158
140
|
export function describeIntervalMs(ms) {
|
|
159
141
|
const s = Math.round(ms / 1000);
|
|
160
142
|
if (s < 60)
|
|
@@ -205,9 +187,6 @@ function sanitizeHistory(v) {
|
|
|
205
187
|
}
|
|
206
188
|
return out.sort((a, b) => b.at - a.at).slice(0, SCHEDULER_HISTORY_MAX);
|
|
207
189
|
}
|
|
208
|
-
/** 落盘会话路径是否指向同一会话(纯函数,可单测)。
|
|
209
|
-
* Windows 上 `C:\a\b` 与 `C:/a/b`、尾部分隔符差异都算同一文件;
|
|
210
|
-
* 空串永不相等(没拿到稳定键的任务不配对)。 */
|
|
211
190
|
export function sameSessionFile(a, b) {
|
|
212
191
|
const x = String(a ?? "").trim();
|
|
213
192
|
const y = String(b ?? "").trim();
|
|
@@ -231,7 +210,6 @@ export class SchedulerStore {
|
|
|
231
210
|
setExecutor(executor) {
|
|
232
211
|
this.opts.executor = executor;
|
|
233
212
|
}
|
|
234
|
-
/** 启动 ticker + catchUp 补跑(幂等)。 */
|
|
235
213
|
start() {
|
|
236
214
|
this.load();
|
|
237
215
|
if (this.started)
|
|
@@ -246,7 +224,6 @@ export class SchedulerStore {
|
|
|
246
224
|
if (next === null)
|
|
247
225
|
continue;
|
|
248
226
|
if (next <= now && task.catchUp === "once" && lastAt < now) {
|
|
249
|
-
// 重启发现漏跑:补一次,补完按这次重排。
|
|
250
227
|
this.nextFire.set(task.id, now + 5000);
|
|
251
228
|
void this.fire(task.id, false).catch((err) => this.reportFailure(err));
|
|
252
229
|
}
|
|
@@ -267,7 +244,6 @@ export class SchedulerStore {
|
|
|
267
244
|
}
|
|
268
245
|
this.started = false;
|
|
269
246
|
}
|
|
270
|
-
/** 读盘;坏文件/形状不对当空表(读路径不回写)。 */
|
|
271
247
|
load() {
|
|
272
248
|
try {
|
|
273
249
|
const parsed = JSON.parse(readFileSync(schedulerFile(this.dataDir), "utf8"));
|
|
@@ -309,9 +285,7 @@ export class SchedulerStore {
|
|
|
309
285
|
history: sanitizeHistory(r.history),
|
|
310
286
|
});
|
|
311
287
|
}
|
|
312
|
-
catch {
|
|
313
|
-
// 单条坏记录跳过,不影响其他任务
|
|
314
|
-
}
|
|
288
|
+
catch { }
|
|
315
289
|
}
|
|
316
290
|
this.tasks = next;
|
|
317
291
|
}
|
|
@@ -339,9 +313,7 @@ export class SchedulerStore {
|
|
|
339
313
|
try {
|
|
340
314
|
this.opts.onChange?.();
|
|
341
315
|
}
|
|
342
|
-
catch {
|
|
343
|
-
/* 推送失败不影响调度 */
|
|
344
|
-
}
|
|
316
|
+
catch { }
|
|
345
317
|
}
|
|
346
318
|
list() {
|
|
347
319
|
const now = Date.now();
|
|
@@ -377,10 +349,6 @@ export class SchedulerStore {
|
|
|
377
349
|
})
|
|
378
350
|
.sort((a, b) => a.name.localeCompare(b.name, "zh"));
|
|
379
351
|
}
|
|
380
|
-
/** 新建或全量更新(同名 id 覆盖);返回归一化后的任务。
|
|
381
|
-
* issue #231:面板编辑不带绑定字段(conversationId/sessionFile 缺席)时保留旧绑定 ——
|
|
382
|
-
* 否则用户在面板改个名字就会把 AI 任务的会话绑定洗掉,下次触发直接变无头。
|
|
383
|
-
* 字段显式出现(含空串)仍按全量语义覆盖。 */
|
|
384
352
|
upsert(input, origin) {
|
|
385
353
|
if (origin !== undefined && !validOrigin(origin))
|
|
386
354
|
throw new Error("Invalid scheduled-task creation origin");
|
|
@@ -409,12 +377,10 @@ export class SchedulerStore {
|
|
|
409
377
|
this.opts.validateTask?.(task);
|
|
410
378
|
const history = prev?.history ? sanitizeHistory(prev.history) : [];
|
|
411
379
|
this.save(new Map(this.tasks).set(task.id, { ...task, history }));
|
|
412
|
-
// spec/cwd/开关变了 → 按现在重排下次触发
|
|
413
380
|
this.nextFire.set(task.id, computeNextFire(task, Date.now()) ?? Date.now() + TICK_MS);
|
|
414
381
|
this.changed();
|
|
415
382
|
return task;
|
|
416
383
|
}
|
|
417
|
-
/** Commit cancellation before the caller discards transcript evidence. No awaits can race fire(). */
|
|
418
384
|
cancelUnstartedFromCalls(sessionFile, toolCallIds, commit) {
|
|
419
385
|
const next = new Map(this.tasks);
|
|
420
386
|
const removed = [];
|
|
@@ -473,9 +439,7 @@ export class SchedulerStore {
|
|
|
473
439
|
try {
|
|
474
440
|
this.opts.onTaskRemoved?.(id);
|
|
475
441
|
}
|
|
476
|
-
catch {
|
|
477
|
-
/* 回调失败不影响删除 */
|
|
478
|
-
}
|
|
442
|
+
catch { }
|
|
479
443
|
}
|
|
480
444
|
return ok;
|
|
481
445
|
}
|
|
@@ -489,9 +453,6 @@ export class SchedulerStore {
|
|
|
489
453
|
this.changed();
|
|
490
454
|
return { ...t };
|
|
491
455
|
}
|
|
492
|
-
/** 会话重绑定(issue #231):触发时按稳定键找到了新的对话句柄,把任务的
|
|
493
|
-
* 投递目标迁移过去(只改 conversationId/sessionFile/updatedAt,不碰下次触发
|
|
494
|
-
* 与历史)。无变化回 false(调用方免一次落盘+推送);未知任务回 false。 */
|
|
495
456
|
rebind(id, binding) {
|
|
496
457
|
const prev = this.tasks.get(id);
|
|
497
458
|
if (!prev || prev.target === "canvas")
|
|
@@ -534,7 +495,6 @@ export class SchedulerStore {
|
|
|
534
495
|
}
|
|
535
496
|
if (this.running.has(task.id)) {
|
|
536
497
|
if (next <= now) {
|
|
537
|
-
// 任务已在执行中(单次执行耗时超过周期):顺延本次计划触发至下个周期,防同一任务并发重叠(issue #836)
|
|
538
498
|
const nextSlot = computeNextFire(task, now) ?? now + TICK_MS;
|
|
539
499
|
this.nextFire.set(task.id, nextSlot);
|
|
540
500
|
this.changed();
|
|
@@ -547,7 +507,6 @@ export class SchedulerStore {
|
|
|
547
507
|
}
|
|
548
508
|
}
|
|
549
509
|
}
|
|
550
|
-
/** 手动立即执行一次(面板 Run Now;调试用,不扰动下次触发)。 */
|
|
551
510
|
async runNow(id) {
|
|
552
511
|
const task = this.tasks.get(id);
|
|
553
512
|
if (!task)
|
|
@@ -561,7 +520,6 @@ export class SchedulerStore {
|
|
|
561
520
|
if (!task)
|
|
562
521
|
return { ok: false, error: "任务不存在" };
|
|
563
522
|
const executor = this.opts.executor;
|
|
564
|
-
// Remember the attempt before any external effect, even if run-history persistence later fails.
|
|
565
523
|
if (task.origin && task.startedAt === undefined) {
|
|
566
524
|
try {
|
|
567
525
|
this.save(new Map(this.tasks).set(id, { ...task, startedAt: Date.now() }));
|
|
@@ -574,9 +532,6 @@ export class SchedulerStore {
|
|
|
574
532
|
this.running.add(id);
|
|
575
533
|
const startedAt = Date.now();
|
|
576
534
|
const scheduleBase = triggerAt !== undefined ? Math.max(triggerAt, startedAt) : startedAt;
|
|
577
|
-
// issue #836:定时触发瞬间即刻推进 nextFire 到下一周期:
|
|
578
|
-
// 1. 面板在长任务执行期间不会停留在已过期的历史时间戳;
|
|
579
|
-
// 2. 执行时长 ≥ 任务间隔时,调度器不会停摆或遗漏后续排期。
|
|
580
535
|
if (!task.oneShot && !manual) {
|
|
581
536
|
this.nextFire.set(id, computeNextFire(task, scheduleBase) ?? scheduleBase + TICK_MS);
|
|
582
537
|
}
|
|
@@ -614,22 +569,16 @@ export class SchedulerStore {
|
|
|
614
569
|
this.reportFailure(err);
|
|
615
570
|
}
|
|
616
571
|
finally {
|
|
617
|
-
// 执行可能已产生外部副作用;记录写失败也不能在每个 tick 立即重试。
|
|
618
|
-
// 仅推进内存调度,使用执行期间更新后的配置,不伪造成功历史。
|
|
619
|
-
// 进程重启后仍可能补跑:本地记录与外部副作用不保证跨进程 exactly-once。
|
|
620
572
|
const cur = this.tasks.get(id);
|
|
621
573
|
if (cur && task.oneShot) {
|
|
622
|
-
// A failed history/removal write must not repeat an already attempted one-shot.
|
|
623
574
|
this.tasks.set(id, { ...cur, enabled: false });
|
|
624
575
|
this.nextFire.delete(id);
|
|
625
576
|
}
|
|
626
577
|
else if (cur && cur.enabled && !manual) {
|
|
627
578
|
if (cur.kind === "interval") {
|
|
628
|
-
// 间隔任务完成时按下一次周期排期(自执行结束起算,与既有单测契约对齐)
|
|
629
579
|
this.nextFire.set(id, computeNextFire(cur, Date.now()) ?? Date.now() + TICK_MS);
|
|
630
580
|
}
|
|
631
581
|
else {
|
|
632
|
-
// cron 任务若执行耗时超过原定时刻,顺延至下一个有效 cron 时间点(issue #836)
|
|
633
582
|
const currentNext = this.nextFire.get(id);
|
|
634
583
|
if (currentNext === undefined || currentNext <= Date.now()) {
|
|
635
584
|
this.nextFire.set(id, computeNextFire(cur, Date.now()) ?? Date.now() + TICK_MS);
|