pi-web-ui 0.116.0 → 0.118.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +83 -3
- package/README.md +69 -138
- package/README.zh-CN.md +70 -179
- package/README.zh-TW.md +3 -1
- package/bin/device-hub-cli.mjs +163 -36
- package/bin/frp-manager.mjs +4 -80
- package/bin/hub-upgrade.mjs +561 -0
- package/bin/pi-device-hub.mjs +0 -1
- package/bin/pi-web-ui.mjs +184 -504
- package/deploy/nginx-subpath.conf +0 -33
- package/deploy/pi-web-ui.service +0 -20
- package/dist/server/agent-formatters.js +4 -38
- package/dist/server/agent-service-daemon.js +203 -371
- package/dist/server/agent-service.js +1281 -3030
- package/dist/server/approval-audit.js +2 -23
- package/dist/server/approval-default-rules.js +0 -6
- package/dist/server/approval-rules.js +7 -105
- package/dist/server/ask-user-question-tool.js +1 -12
- package/dist/server/atomic-file.js +33 -5
- package/dist/server/attachment-store.js +0 -36
- package/dist/server/attachments.js +3 -112
- package/dist/server/auth-cookie.js +0 -21
- package/dist/server/bash-tool.js +1 -32
- package/dist/server/bg-servers.js +0 -96
- package/dist/server/browser-page-tool.js +11 -62
- package/dist/server/builtin-modules.js +7 -0
- package/dist/server/canvas/canvas-agent-tool.js +58 -47
- package/dist/server/canvas/canvas-cards.js +0 -14
- package/dist/server/canvas/canvas-dispatch.js +7 -4
- package/dist/server/canvas/canvas-orchestrator.js +167 -181
- package/dist/server/canvas/canvas-runtime-messages.js +30 -0
- package/dist/server/canvas/canvas-scheduled-task.js +0 -3
- package/dist/server/canvas/canvas-scheduler.js +5 -7
- package/dist/server/canvas/canvas-store.js +24 -35
- package/dist/server/canvas/canvas-validation.js +17 -14
- package/dist/server/canvas/canvas-workspace.js +42 -114
- package/dist/server/canvas/pstack-skills-data.js +0 -5
- package/dist/server/claim-files-tool.js +1 -15
- package/dist/server/claim-store.js +5 -49
- package/dist/server/client-id-utils.js +0 -16
- package/dist/server/client-state.js +36 -214
- package/dist/server/communicate-tool.js +0 -3
- package/dist/server/compact-context-tool.js +0 -30
- package/dist/server/compacted-history.js +0 -35
- package/dist/server/compaction-instructions.js +0 -13
- package/dist/server/compaction-markers.js +38 -92
- package/dist/server/compaction-state.js +0 -21
- package/dist/server/composer-drafts.js +0 -34
- package/dist/server/context-budget-runner.js +0 -11
- package/dist/server/context-budget.js +1 -70
- package/dist/server/context-evidence.js +0 -14
- package/dist/server/context-usage.js +0 -12
- package/dist/server/control-socket.js +4 -48
- package/dist/server/conversation-communication.js +0 -10
- package/dist/server/conversation-identity.js +0 -1
- package/dist/server/conversation-read-tool.js +0 -58
- package/dist/server/conversation-tool-names.js +0 -1
- package/dist/server/conversation-tool.js +0 -1
- package/dist/server/conversation-touches.js +4 -75
- package/dist/server/dangling-tools.js +142 -68
- package/dist/server/delegate-mode.js +0 -36
- package/dist/server/delegate-task.js +2 -28
- package/dist/server/device-center/approval-summary.js +0 -1
- package/dist/server/device-center/bot-catalog.js +0 -3
- package/dist/server/device-center/bot-execution.js +48 -9
- package/dist/server/device-center/bot-presets.js +0 -1
- package/dist/server/device-center/bots.js +0 -1
- package/dist/server/device-center/collab-service.js +27 -11
- package/dist/server/device-center/collab-tool.js +393 -27
- package/dist/server/device-center/connector.js +128 -48
- package/dist/server/device-center/delivery-authority.js +95 -0
- package/dist/server/device-center/delivery-subject.js +29 -0
- package/dist/server/device-center/desktop-linux.js +3 -15
- package/dist/server/device-center/desktop-native.js +1 -10
- package/dist/server/device-center/desktop-page.js +2 -3
- package/dist/server/device-center/desktop-setup.js +1 -3
- package/dist/server/device-center/desktop.js +1 -7
- package/dist/server/device-center/device-integration.js +452 -208
- package/dist/server/device-center/device-lan-access.js +403 -0
- package/dist/server/device-center/device-lan.js +484 -0
- package/dist/server/device-center/device-portals.js +0 -3
- package/dist/server/device-center/execution-failure.js +0 -2
- package/dist/server/device-center/execution-guides.js +15 -6
- package/dist/server/device-center/execution-instructions.js +0 -1
- package/dist/server/device-center/execution-settings.js +0 -1
- package/dist/server/device-center/execution-system-prompt.js +0 -3
- package/dist/server/device-center/execution-workspace.js +1 -4
- package/dist/server/device-center/executor.js +46 -31
- package/dist/server/device-center/file-sync-paths.js +0 -5
- package/dist/server/device-center/file-sync.js +0 -10
- package/dist/server/device-center/group-context-delta.js +0 -8
- package/dist/server/device-center/group-context-message.js +0 -14
- package/dist/server/device-center/group-context.js +0 -19
- package/dist/server/device-center/group-events.js +0 -2
- package/dist/server/device-center/group-plan-guard.js +1 -35
- package/dist/server/device-center/group-router-runtime.js +182 -0
- package/dist/server/device-center/group-router-worker.js +178 -0
- package/dist/server/device-center/group-router.js +359 -0
- package/dist/server/device-center/hub-auth.js +24 -2
- package/dist/server/device-center/hub-conversations.js +13 -15
- package/dist/server/device-center/hub-deliveries.js +119 -15
- package/dist/server/device-center/hub-integration.js +647 -334
- package/dist/server/device-center/hub-locks.js +1 -5
- package/dist/server/device-center/hub-mobile.js +147 -0
- package/dist/server/device-center/hub-orchestration.js +400 -0
- package/dist/server/device-center/hub-page.js +28 -9
- package/dist/server/device-center/hub-setup.js +23 -7
- package/dist/server/device-center/hub-transaction-log.js +175 -0
- package/dist/server/device-center/hub-upgrade.js +162 -0
- package/dist/server/device-center/hub-webhooks.js +1 -3
- package/dist/server/device-center/hub.js +946 -404
- package/dist/server/device-center/human-interaction.js +1 -4
- package/dist/server/device-center/integration-errors.js +0 -2
- package/dist/server/device-center/integration-verification.js +111 -0
- package/dist/server/device-center/local-hub.js +6 -4
- package/dist/server/device-center/local-publication.js +416 -0
- package/dist/server/device-center/local-verification-job.js +95 -0
- package/dist/server/device-center/local-verification.js +273 -0
- package/dist/server/device-center/local.js +341 -18
- package/dist/server/device-center/main.js +18 -2
- package/dist/server/device-center/mobile-notification-forwarder.js +292 -0
- package/dist/server/device-center/native-desktop/macos.js +0 -1
- package/dist/server/device-center/native-desktop/windows.js +0 -1
- package/dist/server/device-center/partition-log.js +52 -46
- package/dist/server/device-center/path-portal.js +42 -12
- package/dist/server/device-center/publication-journal.js +305 -0
- package/dist/server/device-center/publish-intent.js +374 -0
- package/dist/server/device-center/relay.js +217 -52
- package/dist/server/device-center/report-upload.js +0 -1
- package/dist/server/device-center/runtime.js +419 -52
- package/dist/server/device-center/store.js +223 -65
- package/dist/server/device-center/task-context-budget.js +0 -3
- package/dist/server/device-center/task-error.js +0 -1
- package/dist/server/device-center/task-journal.js +6 -23
- package/dist/server/device-center/task-outcome.js +68 -0
- package/dist/server/device-center/task-plan.js +0 -1
- package/dist/server/device-center/task-progress.js +0 -16
- package/dist/server/device-center/task-recovery.js +569 -227
- package/dist/server/device-center/task-report-outbox.js +0 -4
- package/dist/server/device-center/task-report.js +2 -10
- package/dist/server/device-center/task-scheduler.js +1 -35
- package/dist/server/device-center/task-settlement.js +335 -0
- package/dist/server/device-center/task-state.js +0 -12
- package/dist/server/device-center/task-workspace.js +393 -0
- package/dist/server/device-center/transfer-stream.js +5 -45
- package/dist/server/device-center/transfers.js +2 -10
- package/dist/server/device-center/verification-limits.js +9 -0
- package/dist/server/device-center/work-contract.js +923 -0
- package/dist/server/device-center/work-items.js +317 -0
- package/dist/server/device-center/workspaces.js +0 -1
- package/dist/server/dispatch-domain-handlers.js +202 -29
- package/dist/server/dispatch-plugin-handlers.js +2 -19
- package/dist/server/dsh/dsh-agent-service.js +78 -601
- package/dist/server/dsh/dsh-client.js +7 -111
- package/dist/server/dsh/dsh-market-service.js +4 -25
- package/dist/server/dsh/dsh-serialize.js +0 -49
- package/dist/server/dsh/dsh-sessions.js +0 -37
- package/dist/server/dsh/dsh-usage.js +0 -37
- package/dist/server/dsh/preset-clones.js +1 -65
- package/dist/server/dsh/runtime/custom-prompt.mjs +0 -14
- package/dist/server/dsh/runtime/goal-rpc.mjs +7 -176
- package/dist/server/dsh/runtime/launcher.mjs +2 -53
- package/dist/server/dsh/runtime/override.patch.yml +0 -29
- package/dist/server/dsh/runtime/runtime-root.mjs +0 -54
- package/dist/server/durable/durable-agent-service.js +5 -23
- package/dist/server/durable/durable-driver.js +12 -73
- package/dist/server/durable/durable-event-projector.js +1 -50
- package/dist/server/durable/durable-loader.js +0 -12
- package/dist/server/durable/durable-models.js +11 -80
- package/dist/server/durable/durable-storage.js +1 -17
- package/dist/server/durable/durable-tools.js +2 -20
- package/dist/server/durable/index.js +0 -3
- package/dist/server/edit-soft-tool.js +2 -81
- package/dist/server/engine-capabilities.js +0 -13
- package/dist/server/engine-catalog.js +74 -0
- package/dist/server/engine-cli.js +89 -0
- package/dist/server/engine-probe.js +35 -217
- package/dist/server/ensure-bash.js +2 -28
- package/dist/server/eval-tool.js +1 -50
- package/dist/server/evidence-tool-hooks.js +0 -2
- package/dist/server/file-archives.js +0 -10
- package/dist/server/file-save.js +1 -12
- package/dist/server/file-transfer-routes.js +0 -11
- package/dist/server/files-service.js +18 -271
- package/dist/server/global-loader.js +9 -89
- package/dist/server/goal-evidence.js +1 -35
- package/dist/server/goal-review-gate.js +0 -58
- package/dist/server/goal-service.js +19 -422
- package/dist/server/hashline-engine.js +8 -112
- package/dist/server/host-guard.js +0 -24
- package/dist/server/host-metrics.js +0 -6
- package/dist/server/http-proxy.js +1 -7
- package/dist/server/i18n.js +5 -72
- package/dist/server/icon-svg.js +0 -15
- package/dist/server/index.js +199 -677
- package/dist/server/json-utils.js +0 -12
- package/dist/server/launch-origin.js +0 -44
- package/dist/server/left-panel-running.js +0 -9
- package/dist/server/load-timing.js +1 -4
- package/dist/server/load-tools-tool.js +0 -20
- package/dist/server/locales.js +1 -46
- package/dist/server/lsp-tool.js +13 -126
- package/dist/server/managed.js +0 -48
- package/dist/server/marker-service.js +1 -22
- package/dist/server/markers/builtins/action.js +0 -19
- package/dist/server/markers/builtins/notify.js +1 -9
- package/dist/server/markers/builtins/rename.js +0 -13
- package/dist/server/markers/index.js +0 -3
- package/dist/server/markers/marker.js +0 -13
- package/dist/server/markers/registry.js +0 -3
- package/dist/server/markers/store.js +1 -12
- package/dist/server/market-service.js +7 -43
- package/dist/server/mcp-agent-tool.js +0 -10
- package/dist/server/mcp-bridge.js +6 -138
- package/dist/server/mcp-hot-reload.js +0 -25
- package/dist/server/mcp-manager.js +2 -44
- package/dist/server/mcp-oauth-login.js +0 -2
- package/dist/server/mcp-oauth-ui.js +1 -4
- package/dist/server/mcp-oauth.js +5 -79
- package/dist/server/mcp-project-runtime.js +0 -4
- package/dist/server/message-deletion.js +0 -2
- package/dist/server/message-entry-resolver.js +0 -8
- package/dist/server/message-window.js +0 -71
- package/dist/server/mobile-notification-events.js +16 -0
- package/dist/server/mobile-origin.js +79 -0
- package/dist/server/mobile-push.js +523 -0
- package/dist/server/model-admin.js +19 -358
- package/dist/server/model-enrich.js +0 -19
- package/dist/server/model-resolver.js +2 -61
- package/dist/server/native-cli-discovery.js +115 -0
- package/dist/server/native-cli-model.js +71 -0
- package/dist/server/native-cli-references.js +214 -0
- package/dist/server/native-cli-remote-cleanup.js +58 -0
- package/dist/server/native-cli-remote-files.js +282 -0
- package/dist/server/native-cli-routes.js +68 -0
- package/dist/server/native-cli-runtime.js +1 -0
- package/dist/server/native-cli-session-hooks.js +170 -0
- package/dist/server/native-cli-session.js +585 -0
- package/dist/server/native-cli-state.js +82 -0
- package/dist/server/native-cli.js +210 -0
- package/dist/server/net-guard.js +9 -71
- package/dist/server/office-parse.js +0 -50
- package/dist/server/orphan-manager.js +0 -18
- package/dist/server/patch-bash-process.js +0 -4
- package/dist/server/patch-executable-lookup.js +0 -77
- package/dist/server/patch-node-pty.js +6 -45
- package/dist/server/patch-remote-catalog.js +4 -34
- package/dist/server/patch-tool.js +0 -15
- package/dist/server/payload-limits.js +0 -5
- package/dist/server/pending-question.js +0 -5
- package/dist/server/permission-preset.js +4 -33
- package/dist/server/persona-chain.js +0 -26
- package/dist/server/pkg-info.js +1 -17
- package/dist/server/plan-manager.js +2 -49
- package/dist/server/plan-mode.js +0 -97
- package/dist/server/plan-update-tool.js +1 -15
- package/dist/server/plugin-api-catalog.js +6 -4
- package/dist/server/plugin-assets.js +1 -35
- package/dist/server/plugin-bundled.js +68 -0
- package/dist/server/plugin-catalog-sync.js +0 -37
- package/dist/server/plugin-catalog.js +13 -67
- package/dist/server/plugin-chat-attachments.js +0 -1
- package/dist/server/plugin-conversation-view.js +0 -20
- package/dist/server/plugin-dom.js +1 -23
- package/dist/server/plugin-facilities.js +4 -115
- package/dist/server/plugin-grants.js +2 -90
- package/dist/server/plugin-install-spec.js +0 -43
- package/dist/server/plugin-installer.js +34 -75
- package/dist/server/plugin-llm.js +4 -38
- package/dist/server/plugin-manifest-validate.js +0 -31
- package/dist/server/plugin-permissions.js +1 -24
- package/dist/server/plugin-project.js +7 -129
- package/dist/server/plugin-removal.js +1 -8
- package/dist/server/plugin-schedule.js +1 -38
- package/dist/server/plugin-secrets.js +3 -16
- package/dist/server/plugin-tool-guard.js +1 -28
- package/dist/server/plugin-ui-slots.js +0 -4
- package/dist/server/plugin-updater.js +15 -90
- package/dist/server/plugins.js +71 -619
- package/dist/server/present-files-tool.js +0 -57
- package/dist/server/preset-fields.js +24 -61
- package/dist/server/preset-plugin-dependencies.js +0 -2
- package/dist/server/preset-share.js +4 -172
- package/dist/server/process-utils.js +4 -80
- package/dist/server/prompt-assembler.js +2 -30
- package/dist/server/prompt-base-store.js +0 -47
- package/dist/server/prompt-composer.js +21 -98
- package/dist/server/prompt-templates.js +0 -2
- package/dist/server/protocol-version.js +1 -11
- package/dist/server/protocol.js +0 -5
- package/dist/server/queue-modes.js +0 -3
- package/dist/server/queue-utils.js +0 -40
- package/dist/server/quick-ask-context.js +384 -0
- package/dist/server/quick-ask-settings.js +61 -0
- package/dist/server/quick-ask.js +260 -0
- package/dist/server/read-tool.js +0 -65
- package/dist/server/reasoning-registry.js +1 -29
- package/dist/server/remote-cli-persistence.js +373 -0
- package/dist/server/remote-native-cli.js +78 -0
- package/dist/server/remote-ssh-service.js +481 -190
- package/dist/server/request-context.js +0 -9
- package/dist/server/resolve-global-sdk.js +55 -31
- package/dist/server/sandbox-data.js +0 -1
- package/dist/server/sandbox-engines.js +0 -1
- package/dist/server/sandbox-runtime-gate.js +0 -3
- package/dist/server/sandbox-service.js +0 -41
- package/dist/server/sandbox-tool.js +0 -20
- package/dist/server/schedule-agent-tool.js +2 -31
- package/dist/server/scheduler-tasks.js +32 -56
- package/dist/server/scm-commitmsg.js +0 -53
- package/dist/server/scm.js +3 -48
- package/dist/server/sdk-builtin-extensions.js +2 -29
- package/dist/server/sdk-origin.js +0 -45
- package/dist/server/serialize.js +2 -92
- package/dist/server/server-config.js +0 -11
- package/dist/server/session-branch.js +1 -87
- package/dist/server/session-list-scan.js +215 -0
- package/dist/server/session-open.js +69 -0
- package/dist/server/session-parser.js +4 -54
- package/dist/server/session-scan.js +81 -45
- package/dist/server/session-search.js +0 -56
- package/dist/server/settings-service.js +19 -126
- package/dist/server/setup-config.js +0 -2
- package/dist/server/setup-page.js +0 -9
- package/dist/server/skill-content-filler.js +0 -17
- package/dist/server/skill-discovery.js +5 -92
- package/dist/server/skill-maintenance.js +1 -28
- package/dist/server/skill-tool.js +0 -30
- package/dist/server/slash-commands.js +5 -50
- package/dist/server/soft-cap.js +3 -40
- package/dist/server/startup-banner.js +0 -8
- package/dist/server/subagent-handoff.js +0 -11
- package/dist/server/subagent-helpers.js +2 -17
- package/dist/server/subagent-notify.js +0 -19
- package/dist/server/subagent-security-gate.js +0 -50
- package/dist/server/subagent-task.js +0 -9
- package/dist/server/subagent-templates-hant.js +0 -10
- package/dist/server/subagent-templates.js +3 -103
- package/dist/server/subagents.js +1 -87
- package/dist/server/system-screenshot-windows.js +259 -0
- package/dist/server/system-screenshot.js +77 -0
- package/dist/server/tabs.js +3 -48
- package/dist/server/terminals.js +559 -586
- package/dist/server/text-quote.js +0 -12
- package/dist/server/text-sniff.js +2 -52
- package/dist/server/themes.js +2 -41
- package/dist/server/tool-approval.js +0 -47
- package/dist/server/tool-guards.js +0 -90
- package/dist/server/tool-host-factories.js +1 -16
- package/dist/server/tool-info.js +0 -13
- package/dist/server/tool-manager.js +1 -229
- package/dist/server/tool-overrides.js +1 -46
- package/dist/server/tool-prompt-overrides.js +1 -30
- package/dist/server/tool-prompts.js +0 -14
- package/dist/server/tool-signature.js +0 -25
- package/dist/server/transcript-prepare.js +55 -0
- package/dist/server/tts-routes.js +58 -0
- package/dist/server/tts-service.js +106 -0
- package/dist/server/tts-system.js +160 -0
- package/dist/server/turn-timing.js +0 -1
- package/dist/server/unauthorized-page.js +0 -8
- package/dist/server/universal/driver-base.js +2 -31
- package/dist/server/universal/drivers/claude-code.js +98 -194
- package/dist/server/universal/drivers/codex.js +12 -35
- package/dist/server/universal/drivers/mock-driver.js +1 -11
- package/dist/server/universal/index.js +0 -3
- package/dist/server/universal/session-store.js +4 -21
- package/dist/server/universal/universal-attachments.js +2 -36
- package/dist/server/universal/universal-service.js +5 -24
- package/dist/server/universal/universal-session.js +30 -148
- package/dist/server/universal/universal-types.js +0 -3
- package/dist/server/update-check.js +6 -182
- package/dist/server/uploads.js +4 -43
- package/dist/server/virtual-tui.js +2 -27
- package/dist/server/vision-bridge.js +0 -27
- package/dist/server/wait-subscription-scan.js +13 -115
- package/dist/server/webui-context.js +2 -87
- package/dist/server/workspace-handle.js +373 -0
- package/dist/server/workspace-snapshot.js +7 -113
- package/dist/server/worktree-service.js +2 -53
- package/dist/server/worktree-tool.js +0 -11
- package/dist/server/ws-client-id.js +0 -18
- package/dist/server/ws-pending-queue.js +0 -7
- package/dist/server/ws-unknown-types.js +0 -17
- package/docs/README.md +24 -17
- package/docs/architecture-plugins.md +55 -6
- package/docs/device-center.md +57 -23
- package/docs/device-desktop.md +3 -3
- package/docs/group-orchestration.md +142 -0
- package/docs/hub-upgrade-release-testing.md +46 -0
- package/extensions/webui.ts +3 -74
- package/package.json +9 -6
- package/plugin-sdk/README.md +22 -8
- package/plugin-sdk/client-utils.mjs +0 -7
- package/plugin-sdk/client.d.ts +26 -0
- package/plugin-sdk/client.mjs +52 -0
- package/plugin-sdk/import-check.mjs +4 -51
- package/plugin-sdk/index.d.ts +128 -117
- package/plugin-sdk/index.mjs +2 -687
- package/plugin-sdk/package.json +15 -4
- package/plugin-sdk/ssh-host-trust.mjs +0 -12
- package/plugin-sdk/testing.d.ts +9 -0
- package/plugin-sdk/testing.mjs +511 -0
- package/plugins/catalog.json +52 -4
- package/plugins/superagent/README.md +110 -0
- package/plugins/superagent/client/entry.mjs +21 -0
- package/plugins/superagent/index.mjs +8 -0
- package/plugins/superagent/main.mjs +218 -0
- package/plugins/superagent/manifest.json +15 -0
- package/plugins/superagent/server.mjs +572 -0
- package/plugins/superagent/style.css +167 -0
- package/themes/aetheris.css +1 -31
- package/themes/ayu-light.css +0 -1
- package/themes/bases/flow-base.css +2 -83
- package/themes/bases/obsidian-base.css +2 -37
- package/themes/bases/statusbar-flat-base.css +0 -1
- package/themes/bases/zhujian-base.css +0 -63
- package/themes/bases/zhupi-base.css +0 -64
- package/themes/catppuccin-latte.css +0 -1
- package/themes/catppuccin.css +0 -1
- package/themes/claude-code-dark.css +0 -1
- package/themes/codex.css +0 -1
- package/themes/dark-teal.css +22 -54
- package/themes/everforest-light.css +0 -1
- package/themes/flow-cristallo.css +160 -0
- package/themes/flow-ink.css +160 -0
- package/themes/flow-light.css +1 -10
- package/themes/flow-obsidian.css +160 -0
- package/themes/flow-zurich.css +160 -0
- package/themes/flow.css +1 -9
- package/themes/geist.css +0 -1
- package/themes/gruvbox-light.css +0 -1
- package/themes/kanagawa-lotus.css +0 -1
- package/themes/md-preview.css +1 -2
- package/themes/mist.css +0 -1
- package/themes/nord.css +0 -1
- package/themes/one-dark.css +0 -1
- package/themes/paper.css +0 -1
- package/themes/rose-pine-dawn.css +0 -1
- package/themes/sakura.css +0 -1
- package/themes/solarized-light.css +0 -1
- package/themes/tokyo-night.css +0 -1
- package/themes/translucent.css +4 -35
- package/themes/transparent.css +4 -41
- package/themes/vs-code-dark.css +0 -1
- package/themes/wallpaper-flow.css +3 -17
- package/themes/wallpaper-obsidian.css +1 -4
- package/themes/white.css +0 -1
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/{BgTasksModal-BDoOpj-F.js → BgTasksModal-D-x7kA63.js} +1 -1
- package/web/dist/assets/CanvasStudio-CAWcs9tm.js +1579 -0
- package/web/dist/assets/DeviceCenter-Dc0whRcu.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +1 -0
- package/web/dist/assets/DeviceGroups-C_fZMNeK.js +1 -0
- package/web/dist/assets/{Dropdown-C4LIhshN.js → Dropdown-CTgVLUbp.js} +1 -1
- package/web/dist/assets/FilePreview-C6W0PvaK.js +2 -0
- package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +1 -0
- package/web/dist/assets/GroupConversation-C81YjF2C.js +61 -0
- package/web/dist/assets/GroupWorkItems-BIvZtr10.js +1 -0
- package/web/dist/assets/{HintTip-c6d0TJoh.js → HintTip-Da6qc566.js} +1 -1
- package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +2 -0
- package/web/dist/assets/NativeCliPanel-CU1rZmyu.js +5 -0
- package/web/dist/assets/{PiSetupModal-BmMrrgB9.js → PiSetupModal-DZKY5Wiw.js} +1 -1
- package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +1 -0
- package/web/dist/assets/SCMPanel-CuEgzAlO.js +2 -0
- package/web/dist/assets/SettingsModal-Cdu5h29p.js +33 -0
- package/web/dist/assets/TermXterm-Bt5WKAxP.js +3 -0
- package/web/dist/assets/TerminalPanel-BCIBV8se.js +1 -0
- package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +1 -0
- package/web/dist/assets/app-globals-CZjFtI4F.js +129 -0
- package/web/dist/assets/canvas-client-WkhM55mR.js +1 -0
- package/web/dist/assets/composer-bridge-CImnjDHq.js +1 -0
- package/web/dist/assets/desktop-B8NZ3KW-.js +1 -0
- package/web/dist/assets/index-CQc3VrWa.css +1 -0
- package/web/dist/assets/index-D_AGu4Zv.js +404 -0
- package/web/dist/assets/plugin-host-uqZGpvCs.js +1 -0
- package/web/dist/assets/{remote-ssh-client-CfYSMEZg.js → remote-ssh-client-Cdf-cTUe.js} +1 -1
- package/web/dist/assets/theme-DGL7hLUs.js +1 -0
- package/web/dist/index.html +12 -11
- package/web/dist/sw.js +15 -61
- package/web/public/sw.js +14 -60
- package/dist/gh-comment-781.md +0 -5
- package/dist/server/device-center/local-page.js +0 -17
- package/dist/server/device-center/smoke-preview.js +0 -3
- package/dist/server/durable/durable-capabilities.js +0 -11
- package/dist/server/markers/builtins/services.js +0 -123
- package/dist/server/markers/builtins/todo.js +0 -189
- package/dist/server/markers-list-tool.js +0 -34
- package/dist/server/orchestrator.js +0 -109
- package/dist/server/patch-turn-end-boundary.js +0 -77
- package/dist/server/system-prompt-soul.js +0 -41
- package/dist/server/univer-service.js +0 -448
- package/dist/server/universal/drivers/dsh-driver.js +0 -379
- package/dist/test-artifact.md +0 -9
- package/dist/test-preview-modal.md +0 -11
- package/dist/test-report.html +0 -20
- package/web/dist/assets/BgTasksModal-C0i3O1FT.js +0 -1
- package/web/dist/assets/CanvasStudio-B8thymBN.js +0 -1579
- package/web/dist/assets/CanvasStudio-zSxyIx1R.js +0 -1579
- package/web/dist/assets/DeviceCenter-DfAHKcid.js +0 -3
- package/web/dist/assets/DeviceCenter-ydvOTlzE.js +0 -3
- package/web/dist/assets/DeviceExecutionSettings-q5Ik8oXg.js +0 -1
- package/web/dist/assets/DeviceGroups-CI14_SRb.js +0 -1
- package/web/dist/assets/DeviceGroups-DvsB5IEU.js +0 -1
- package/web/dist/assets/FilePreview-BgGongmv.js +0 -2
- package/web/dist/assets/FilePreview-D4NrhF-U.js +0 -2
- package/web/dist/assets/GlobalSearchModal-BWgU8yPd.js +0 -1
- package/web/dist/assets/GlobalSearchModal-F7fNimKk.js +0 -1
- package/web/dist/assets/GroupConversation-Dh71Pdb-.js +0 -17
- package/web/dist/assets/GroupConversation-ZK3nRmNm.js +0 -17
- package/web/dist/assets/ModelConfigModal-YVEgyy34.js +0 -2
- package/web/dist/assets/ModelConfigModal-vWtg3srp.js +0 -2
- package/web/dist/assets/ProviderOAuthControls-BGSBIKD7.js +0 -1
- package/web/dist/assets/SCMPanel-B8_EDxNr.js +0 -2
- package/web/dist/assets/SCMPanel-BU58qk3T.js +0 -2
- package/web/dist/assets/SettingsModal-CMUybq3J.js +0 -32
- package/web/dist/assets/SettingsModal-OBmGTh-5.js +0 -32
- package/web/dist/assets/TerminalPanel-0CYvD72B.js +0 -3
- package/web/dist/assets/TerminalPanel-DDavKvFr.js +0 -3
- package/web/dist/assets/TuiOverlayModal-BsA-QTvN.js +0 -1
- package/web/dist/assets/TuiOverlayModal-DzoVQBuG.js +0 -1
- package/web/dist/assets/app-globals-CZxzGvIo.js +0 -123
- package/web/dist/assets/canvas-client-CUnXlQYX.js +0 -1
- package/web/dist/assets/desktop-aAKpvKJV.js +0 -1
- package/web/dist/assets/index-C6DwztqE.css +0 -1
- package/web/dist/assets/index-CuN802Sj.js +0 -93
- package/web/dist/assets/index-EH5Fw9fa.js +0 -93
- package/web/dist/assets/plugin-host-BRWib9DF.js +0 -1
- package/web/dist/assets/theme-D2l_mLNo.js +0 -1
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* server/approval-audit.ts
|
|
3
|
-
*
|
|
4
|
-
* 审批决策与安全拦截审计日志(Append-Only Structured Audit Trail,Issue #722)。
|
|
5
|
-
*
|
|
6
|
-
* 记录每一个高危操作与自定义规则的安全事件:
|
|
7
|
-
* - 规则直接阻断(rule_denied)
|
|
8
|
-
* - 弹窗审批答复(user_approved / user_denied / user_edited)
|
|
9
|
-
* - 策略静默放行(suppressed_category / suppressed_all / suppressed_disabled)
|
|
10
|
-
* - 批量自动放行(batch_approved_policy / batch_approved_disabled)
|
|
11
|
-
*
|
|
12
|
-
* 存储路径:<dataDir>/audit/approvals.jsonl
|
|
13
|
-
* 轮转规则:单文件达到 10MB 自动轮转,最多保留 3 份归档。
|
|
14
|
-
*/
|
|
15
1
|
import { existsSync, mkdirSync, statSync, renameSync, unlinkSync, appendFileSync, readFileSync } from "node:fs";
|
|
16
2
|
import { dirname, join } from "node:path";
|
|
17
|
-
const MAX_AUDIT_FILE_SIZE = 10 * 1024 * 1024;
|
|
3
|
+
const MAX_AUDIT_FILE_SIZE = 10 * 1024 * 1024;
|
|
18
4
|
const MAX_BACKUP_FILES = 3;
|
|
19
|
-
/** 参数摘录与截断(单个字段最长 1024 字符,防止长文本撑爆审计日志)。 */
|
|
20
5
|
export function sanitizeAuditParams(params) {
|
|
21
6
|
if (params === null || params === undefined)
|
|
22
7
|
return params;
|
|
@@ -44,7 +29,6 @@ export class ApprovalAuditLogger {
|
|
|
44
29
|
getFilePath() {
|
|
45
30
|
return this.logPath;
|
|
46
31
|
}
|
|
47
|
-
/** 记录一条审批/安全决策。 */
|
|
48
32
|
record(entry) {
|
|
49
33
|
try {
|
|
50
34
|
const now = Date.now();
|
|
@@ -63,11 +47,9 @@ export class ApprovalAuditLogger {
|
|
|
63
47
|
appendFileSync(this.logPath, JSON.stringify(fullEntry) + "\n", "utf8");
|
|
64
48
|
}
|
|
65
49
|
catch (err) {
|
|
66
|
-
// 审计日志写入为旁路监控,绝不中断正常业务流,仅记录调试警告
|
|
67
50
|
console.warn("[approval-audit] Failed to write audit log:", err);
|
|
68
51
|
}
|
|
69
52
|
}
|
|
70
|
-
/** 检查文件大小并按需轮转。 */
|
|
71
53
|
rotateIfNeeded() {
|
|
72
54
|
if (!existsSync(this.logPath))
|
|
73
55
|
return;
|
|
@@ -94,7 +76,6 @@ export class ApprovalAuditLogger {
|
|
|
94
76
|
console.warn("[approval-audit] Log rotation failed:", err);
|
|
95
77
|
}
|
|
96
78
|
}
|
|
97
|
-
/** 读取最近 N 条审计记录(主要供单测和审计查看)。 */
|
|
98
79
|
readRecentEntries(limit = 100) {
|
|
99
80
|
if (!existsSync(this.logPath))
|
|
100
81
|
return [];
|
|
@@ -106,9 +87,7 @@ export class ApprovalAuditLogger {
|
|
|
106
87
|
try {
|
|
107
88
|
out.push(JSON.parse(lines[i]));
|
|
108
89
|
}
|
|
109
|
-
catch {
|
|
110
|
-
// 忽略单行解析异常
|
|
111
|
-
}
|
|
90
|
+
catch { }
|
|
112
91
|
}
|
|
113
92
|
return out;
|
|
114
93
|
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 内置默认审批规则(与 server/tool-approval.ts 既有内置检测表保持 100% 同口径与同一 id)。
|
|
3
|
-
*/
|
|
4
1
|
export const DEFAULT_APPROVAL_RULES = [
|
|
5
2
|
{
|
|
6
3
|
id: "builtin.bash.rm-rf",
|
|
@@ -53,9 +50,6 @@ export const DEFAULT_APPROVAL_RULES = [
|
|
|
53
50
|
tools: ["bash"],
|
|
54
51
|
field: "command",
|
|
55
52
|
match: "regex",
|
|
56
|
-
// git 全局选项前缀(-C <path> / -c k=v / --git-dir=…)、git.exe;push 强推 / +refspec / :branch 删远端;
|
|
57
|
-
// checkout . / restore . / stash drop|clear 丢弃未提交修改(restore --staged 只取消暂存,排除)。
|
|
58
|
-
// push 的参数区不跨 ; & | 换行,避免把后续命令里的 -f(如 `rm -f`)算进来(#578)。
|
|
59
53
|
value: "\\bgit(?:\\.exe)?(?:\\s+(?:-[cC]\\s+\\S+|--[a-zA-Z-]+=\\S+))*\\s+(?:push\\s+(?:[^;&|\\n]*?\\s)?(?:--force|-[a-zA-Z0-9]*f)\\b|push\\s+(?:[^;&|\\n]*?\\s)?(?:\\+\\S+|:[^\\s/]\\S*)|reset\\s+--hard|clean\\s+(?:-[a-zA-Z]+\\s+)*-[a-zA-Z0-9]*f[a-zA-Z0-9]*|branch\\s+-[dD]\\b|checkout\\s+(?:--\\s+)?\\.(?=\\s|$|[;&|])|restore\\s+(?:--(?!staged\\b)\\S+\\s+)*\\.(?=\\s|$|[;&|])|stash\\s+(?:drop|clear)\\b)",
|
|
60
54
|
action: "ask",
|
|
61
55
|
label: "破坏性 Git 操作",
|
|
@@ -1,34 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* server/approval-rules.ts
|
|
3
|
-
*
|
|
4
|
-
* 审批规则库与多维匹配引擎(Approval Rules Store & Match Engine)。
|
|
5
|
-
*
|
|
6
|
-
* 功能:
|
|
7
|
-
* 1. 规则数据模型(ApprovalRule / UiApprovalRule):
|
|
8
|
-
* - 工具名单(tools:["bash"]、["write", "edit"]、["*"])
|
|
9
|
-
* - 匹配字段(field:"command" | "path" | "params")
|
|
10
|
-
* - 匹配方式(match:"regex" | "glob" | "contains" | "prefix" | "outside_workspace")
|
|
11
|
-
* - 命中动作(action:"ask" | "deny" | "allow")
|
|
12
|
-
* - "deny":直接阻断执行并向模型报错(不弹窗、不产生 pending)
|
|
13
|
-
* - "ask":触发人工协同审批(弹窗让用户决定,带档位可「允许同类」)
|
|
14
|
-
* - "allow":免审直接放行(白名单,跳过后续规则与内置高危检测)
|
|
15
|
-
* - 启停开关(enabled)+ 内置标记(builtin)
|
|
16
|
-
* - 双语名称与拦截原因(label/labelEn, reason/reasonEn)
|
|
17
|
-
*
|
|
18
|
-
* 2. 匹配与判定纯函数(matchApprovalRule / evaluateApprovalRules):
|
|
19
|
-
* - 优先级规则:
|
|
20
|
-
* 先按规则列表自顶向下顺序遍历,遇到第一个匹配成功的启用规则即返回其判决;
|
|
21
|
-
* 若命中 "allow",直接免审放行;
|
|
22
|
-
* 若命中 "deny",直接拒绝执行;
|
|
23
|
-
* 若命中 "ask",挂起审批弹窗;
|
|
24
|
-
* 若所有规则均未命中,回落至内置默认安全策略(兼容旧硬编码逻辑)。
|
|
25
|
-
*
|
|
26
|
-
* 3. 存储与多客户端同步(ApprovalRulesStore):
|
|
27
|
-
* - 存储路径:<dataDir>/approval-rules.json(所有客户端共享同一份)
|
|
28
|
-
* - 播种 sidecar:<dataDir>/approval-rules.seeded.json(记录已播种过的内置规则 id,
|
|
29
|
-
* 老用户删掉的内置规则不会在重启后复活;发版新增的内置规则可安全合并进老用户文件)。
|
|
30
|
-
* - 内存缓存 + 文件 mtime 感知,支持直接编辑 JSON 文件热生效。
|
|
31
|
-
*/
|
|
32
1
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
33
2
|
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
34
3
|
import { writeJsonAtomicSync } from "./atomic-file.js";
|
|
@@ -36,18 +5,10 @@ import { DEFAULT_APPROVAL_RULES } from "./approval-default-rules.js";
|
|
|
36
5
|
import { LEGACY_TERMINAL_TOOL_NAMES } from "./tool-manager.js";
|
|
37
6
|
import { conversationToolAllowed } from "./conversation-tool-names.js";
|
|
38
7
|
export { DEFAULT_APPROVAL_RULES };
|
|
39
|
-
/**
|
|
40
|
-
* 检测命令字符串中是否包含 Shell 复合操作符或子命令执行结构(分号、逻辑与/或、管道、反引号、换行、$())。
|
|
41
|
-
* 用于白名单(allow)规则防止借由安全前缀在复合命令中夹带高危操作(Issue #722)。
|
|
42
|
-
*/
|
|
43
8
|
export const SHELL_COMPOUND_OPERATOR_RE = /(?:[;&|`\n]|\$\()/;
|
|
44
9
|
export function hasShellCompoundOperator(command) {
|
|
45
10
|
return SHELL_COMPOUND_OPERATOR_RE.test(command);
|
|
46
11
|
}
|
|
47
|
-
/**
|
|
48
|
-
* 跨平台判定 target 路径是否严格位于 root 目录内部或就是 root 本身。
|
|
49
|
-
* 针对 Windows 盘符大小写不敏感及正反斜杠统一进行规范化,防止 .. 路径穿越逃逸。
|
|
50
|
-
*/
|
|
51
12
|
export function isPathInsideRoot(target, root) {
|
|
52
13
|
const fold = (p) => (process.platform === "win32" ? p.toLowerCase() : p);
|
|
53
14
|
const rel = relative(fold(resolve(root)), fold(resolve(target)));
|
|
@@ -57,10 +18,6 @@ export function isPathInsideRoot(target, root) {
|
|
|
57
18
|
return false;
|
|
58
19
|
return rel !== ".." && !rel.startsWith(`..${sep}`) && !rel.startsWith("../");
|
|
59
20
|
}
|
|
60
|
-
/**
|
|
61
|
-
* 极简 glob 转 RegExp(只支持 * 单段、? 单字符、** 跨段)。
|
|
62
|
-
* 纯函数,支持正反斜杠统一归一为 /。
|
|
63
|
-
*/
|
|
64
21
|
export function globToRegex(pattern) {
|
|
65
22
|
const src = String(pattern ?? "")
|
|
66
23
|
.trim()
|
|
@@ -92,11 +49,6 @@ export function globToRegex(pattern) {
|
|
|
92
49
|
}
|
|
93
50
|
return new RegExp(`^${re}$`, "i");
|
|
94
51
|
}
|
|
95
|
-
/**
|
|
96
|
-
* 从工具参数里取「这次调用动的是哪个文件」。SDK 内置 read/write/edit 用 `path`,read 还有
|
|
97
|
-
* `file_path` 别名,部分扩展(如 pi-better-edit 的 edit)用 `file` —— 三种都认,否则叠在
|
|
98
|
-
* 扩展实现之上的权限沙箱与审批规则会静默放行(取不到 → 空串 → 被判成工作区内)。
|
|
99
|
-
*/
|
|
100
52
|
export function extractTargetPath(params) {
|
|
101
53
|
if (!params || typeof params !== "object")
|
|
102
54
|
return "";
|
|
@@ -108,9 +60,6 @@ export function extractTargetPath(params) {
|
|
|
108
60
|
}
|
|
109
61
|
return "";
|
|
110
62
|
}
|
|
111
|
-
/**
|
|
112
|
-
* 从工具参数对象中提取待检查文本。
|
|
113
|
-
*/
|
|
114
63
|
export function extractRuleFieldValue(field, toolName, params) {
|
|
115
64
|
if (!params || typeof params !== "object") {
|
|
116
65
|
return typeof params === "string" ? params : "";
|
|
@@ -132,12 +81,6 @@ export function extractRuleFieldValue(field, toolName, params) {
|
|
|
132
81
|
}
|
|
133
82
|
return "";
|
|
134
83
|
}
|
|
135
|
-
/**
|
|
136
|
-
* 单条规则针对具体工具调用的匹配详情判定(纯函数,issue #566)。
|
|
137
|
-
* 匹配成功时返回匹配区间信息 { index, length, text },否则返回 null。
|
|
138
|
-
*/
|
|
139
|
-
/** 单条规则在一段字段文本里的全部命中区间(issue #578)。regex 规则逐次扫描、不只取首个。 */
|
|
140
|
-
/** Keep persisted per-action rules scoped to exactly the corresponding merged action. */
|
|
141
84
|
function legacyTerminalRuleCall(rule, toolName, params) {
|
|
142
85
|
if (toolName.trim().toLowerCase() !== "terminal" || !params || typeof params !== "object")
|
|
143
86
|
return null;
|
|
@@ -178,7 +121,7 @@ export function matchApprovalRuleDetails(rule, toolName, params, cwd, workspaceR
|
|
|
178
121
|
const out = [];
|
|
179
122
|
for (let m = re.exec(fieldValue); m; m = re.exec(fieldValue)) {
|
|
180
123
|
if (m[0].length === 0) {
|
|
181
|
-
re.lastIndex++;
|
|
124
|
+
re.lastIndex++;
|
|
182
125
|
continue;
|
|
183
126
|
}
|
|
184
127
|
out.push({ index: m.index, length: m[0].length, text: m[0] });
|
|
@@ -194,17 +137,14 @@ export function matchApprovalRuleDetail(rule, toolName, params, cwd, workspaceRo
|
|
|
194
137
|
return matchApprovalRuleDetail(rule, legacy.toolName, legacy.params, cwd, workspaceRoots);
|
|
195
138
|
if (!rule.enabled)
|
|
196
139
|
return null;
|
|
197
|
-
// 1. 工具名匹配
|
|
198
140
|
const targetTools = rule.tools.map((t) => t.trim().toLowerCase());
|
|
199
141
|
const toolMatches = targetTools.includes("*") || conversationToolAllowed(new Set(targetTools), toolName.trim().toLowerCase());
|
|
200
142
|
if (!toolMatches)
|
|
201
143
|
return null;
|
|
202
|
-
// 2. 特殊匹配方式:outside_workspace(工作区外路径)
|
|
203
144
|
if (rule.match === "outside_workspace") {
|
|
204
145
|
const targetPath = extractRuleFieldValue("path", toolName, params);
|
|
205
146
|
if (!targetPath)
|
|
206
147
|
return null;
|
|
207
|
-
// 无论相对或绝对路径,统一经 resolve(cwd, targetPath) 规范化并消除 ".."
|
|
208
148
|
const abs = resolve(cwd, targetPath);
|
|
209
149
|
const allRoots = [resolve(cwd), ...workspaceRoots.map((r) => resolve(r))];
|
|
210
150
|
const inside = allRoots.some((r) => isPathInsideRoot(abs, r));
|
|
@@ -213,11 +153,9 @@ export function matchApprovalRuleDetail(rule, toolName, params, cwd, workspaceRo
|
|
|
213
153
|
}
|
|
214
154
|
return null;
|
|
215
155
|
}
|
|
216
|
-
// 3. 提取字段文本
|
|
217
156
|
const fieldValue = extractRuleFieldValue(rule.field, toolName, params);
|
|
218
157
|
if (!fieldValue)
|
|
219
158
|
return null;
|
|
220
|
-
// 4. 按 match kind 进行文本判定并提取命中区间
|
|
221
159
|
let matched = null;
|
|
222
160
|
switch (rule.match) {
|
|
223
161
|
case "regex": {
|
|
@@ -276,10 +214,6 @@ export function matchApprovalRuleDetail(rule, toolName, params, cwd, workspaceRo
|
|
|
276
214
|
}
|
|
277
215
|
if (!matched)
|
|
278
216
|
return null;
|
|
279
|
-
// 复合命令白名单防逃逸(Issue #722):
|
|
280
|
-
// 当动作为 allow(免审放行)且字段为 command 时,如果整段命令包含复合操作符(; && || | \n $() `),
|
|
281
|
-
// 且该白名单匹配未完全覆盖整条命令输入,禁止仅凭前缀、子串或通配符放行整条复合命令,
|
|
282
|
-
// 防止如 `git status && rm -rf /` 借由安全前缀绕过后续的高危规则拦截。
|
|
283
217
|
if (rule.action === "allow" &&
|
|
284
218
|
rule.field === "command" &&
|
|
285
219
|
hasShellCompoundOperator(fieldValue) &&
|
|
@@ -288,22 +222,14 @@ export function matchApprovalRuleDetail(rule, toolName, params, cwd, workspaceRo
|
|
|
288
222
|
}
|
|
289
223
|
return matched;
|
|
290
224
|
}
|
|
291
|
-
/**
|
|
292
|
-
* 单条规则针对具体工具调用的匹配判定(纯函数)。
|
|
293
|
-
*/
|
|
294
225
|
export function matchApprovalRule(rule, toolName, params, cwd, workspaceRoots = []) {
|
|
295
226
|
return matchApprovalRuleDetail(rule, toolName, params, cwd, workspaceRoots) !== null;
|
|
296
227
|
}
|
|
297
|
-
/**
|
|
298
|
-
* 完整评估规则列表对工具调用的决策(纯函数,按列表顺序首个匹配胜出,收集全部命中清单,issue #566)。
|
|
299
|
-
*/
|
|
300
228
|
export function evaluateApprovalRules(rules, toolName, params, cwd, workspaceRoots = []) {
|
|
301
229
|
let primary = null;
|
|
302
230
|
const hits = [];
|
|
303
231
|
for (const rule of rules) {
|
|
304
|
-
// 同一规则可在一段命令里出现多次(如 `git reset --hard && git clean -fd`),全部列出(#578)。
|
|
305
232
|
for (const detail of matchApprovalRuleDetails(rule, toolName, params, cwd, workspaceRoots)) {
|
|
306
|
-
// A migrated allow must never preempt a new terminal deny/ask rule.
|
|
307
233
|
if (!primary ||
|
|
308
234
|
(primary.action === "allow" &&
|
|
309
235
|
legacyTerminalRuleCall(primary.matchedRule, toolName, params) &&
|
|
@@ -322,7 +248,6 @@ export function evaluateApprovalRules(rules, toolName, params, cwd, workspaceRoo
|
|
|
322
248
|
};
|
|
323
249
|
}
|
|
324
250
|
if (hits.length < 10) {
|
|
325
|
-
// 单条 text 超长时做截断,防止塞满 details 预算(硬限制 ≤64KB)
|
|
326
251
|
const safeText = detail.text.length > 200 ? `${detail.text.slice(0, 200)}…` : detail.text;
|
|
327
252
|
hits.push({
|
|
328
253
|
ruleId: rule.id,
|
|
@@ -350,7 +275,6 @@ export function checkBashCommandDanger(command, rules = DEFAULT_APPROVAL_RULES)
|
|
|
350
275
|
const res = evaluateApprovalRules(rules, "bash", { command }, "");
|
|
351
276
|
return res.hits ?? [];
|
|
352
277
|
}
|
|
353
|
-
/** 归一化输入规则。脏数据或非法规则返回 null。 */
|
|
354
278
|
export function normalizeApprovalRule(raw) {
|
|
355
279
|
if (!raw || typeof raw !== "object")
|
|
356
280
|
return null;
|
|
@@ -381,7 +305,7 @@ export function normalizeApprovalRule(raw) {
|
|
|
381
305
|
new RegExp(value);
|
|
382
306
|
}
|
|
383
307
|
catch {
|
|
384
|
-
return null;
|
|
308
|
+
return null;
|
|
385
309
|
}
|
|
386
310
|
}
|
|
387
311
|
const tools = Array.isArray(o.tools)
|
|
@@ -405,7 +329,6 @@ export function normalizeApprovalRule(raw) {
|
|
|
405
329
|
builtin: o.builtin === true,
|
|
406
330
|
};
|
|
407
331
|
}
|
|
408
|
-
/** 全局审批规则库持久化与操作类。 */
|
|
409
332
|
export class ApprovalRulesStore {
|
|
410
333
|
filePath;
|
|
411
334
|
rules = null;
|
|
@@ -429,18 +352,14 @@ export class ApprovalRulesStore {
|
|
|
429
352
|
}
|
|
430
353
|
}
|
|
431
354
|
}
|
|
432
|
-
catch {
|
|
433
|
-
// 文件不存在时返回空集合
|
|
434
|
-
}
|
|
355
|
+
catch { }
|
|
435
356
|
return out;
|
|
436
357
|
}
|
|
437
358
|
saveSeeded(names) {
|
|
438
359
|
try {
|
|
439
360
|
writeJsonAtomicSync(this.seededPath(), [...names].sort());
|
|
440
361
|
}
|
|
441
|
-
catch {
|
|
442
|
-
// best effort
|
|
443
|
-
}
|
|
362
|
+
catch { }
|
|
444
363
|
}
|
|
445
364
|
load() {
|
|
446
365
|
let currentMtime = 0;
|
|
@@ -463,10 +382,8 @@ export class ApprovalRulesStore {
|
|
|
463
382
|
}
|
|
464
383
|
}
|
|
465
384
|
catch {
|
|
466
|
-
// 文件不存在或格式损坏,以默认规则初始化
|
|
467
385
|
list = DEFAULT_APPROVAL_RULES.map((r) => ({ ...r, tools: [...r.tools] }));
|
|
468
386
|
}
|
|
469
|
-
// 检查播种:老用户新增内置规则自动合并
|
|
470
387
|
const seeded = this.loadSeeded();
|
|
471
388
|
const existingIds = new Set(list.map((r) => r.id));
|
|
472
389
|
let grown = false;
|
|
@@ -491,19 +408,13 @@ export class ApprovalRulesStore {
|
|
|
491
408
|
try {
|
|
492
409
|
this.lastMtime = statSync(this.filePath).mtimeMs;
|
|
493
410
|
}
|
|
494
|
-
catch {
|
|
495
|
-
// ignore
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
catch {
|
|
499
|
-
// best effort
|
|
411
|
+
catch { }
|
|
500
412
|
}
|
|
413
|
+
catch { }
|
|
501
414
|
}
|
|
502
|
-
/** 获取全部有效规则清单(深拷贝返回)。 */
|
|
503
415
|
list() {
|
|
504
416
|
return this.load().map((r) => ({ ...r, tools: [...r.tools] }));
|
|
505
417
|
}
|
|
506
|
-
/** Upsert 一条规则(同 id 替换,新 id 追加到列表末尾)。返回错误提示,成功返回 null。 */
|
|
507
418
|
upsert(input) {
|
|
508
419
|
const rule = normalizeApprovalRule(input);
|
|
509
420
|
if (!rule)
|
|
@@ -511,7 +422,6 @@ export class ApprovalRulesStore {
|
|
|
511
422
|
const list = this.load();
|
|
512
423
|
const idx = list.findIndex((r) => r.id === rule.id);
|
|
513
424
|
if (idx >= 0) {
|
|
514
|
-
// 内置规则保留 builtin 标记
|
|
515
425
|
if (list[idx].builtin) {
|
|
516
426
|
rule.builtin = true;
|
|
517
427
|
}
|
|
@@ -523,7 +433,6 @@ export class ApprovalRulesStore {
|
|
|
523
433
|
this.persist();
|
|
524
434
|
return null;
|
|
525
435
|
}
|
|
526
|
-
/** 批量重排/替换整份规则(供前端拖拽排序后保存)。 */
|
|
527
436
|
saveAll(inputs) {
|
|
528
437
|
if (!Array.isArray(inputs))
|
|
529
438
|
return "规则列表必须是数组";
|
|
@@ -538,11 +447,6 @@ export class ApprovalRulesStore {
|
|
|
538
447
|
ids.add(r.id);
|
|
539
448
|
normalized.push(r);
|
|
540
449
|
}
|
|
541
|
-
// 内置规则是安全底线:整表替换绝不能把它们裁掉(旧客户端 / 并发竞态都
|
|
542
|
-
// 可能送来缺内置规则的清单)。缺失的按默认定义补种、追加到队尾——与
|
|
543
|
-
// load/resetBuiltin 同口径;插队首会改变用户 allow 规则的 first-match
|
|
544
|
-
// 语义。id 命中内置定义的一律强制 builtin 标记(同 upsert 的保护),
|
|
545
|
-
// 防止 remove() 的内置不可删保护被绕过。
|
|
546
450
|
for (const def of DEFAULT_APPROVAL_RULES) {
|
|
547
451
|
if (!ids.has(def.id)) {
|
|
548
452
|
normalized.push({ ...def, tools: [...def.tools] });
|
|
@@ -557,19 +461,17 @@ export class ApprovalRulesStore {
|
|
|
557
461
|
this.persist();
|
|
558
462
|
return null;
|
|
559
463
|
}
|
|
560
|
-
/** 删除一条自定义规则(内置规则不可删除)。 */
|
|
561
464
|
remove(id) {
|
|
562
465
|
const list = this.load();
|
|
563
466
|
const idx = list.findIndex((r) => r.id === id);
|
|
564
467
|
if (idx < 0)
|
|
565
468
|
return false;
|
|
566
469
|
if (list[idx].builtin)
|
|
567
|
-
return false;
|
|
470
|
+
return false;
|
|
568
471
|
list.splice(idx, 1);
|
|
569
472
|
this.persist();
|
|
570
473
|
return true;
|
|
571
474
|
}
|
|
572
|
-
/** 恢复某条内置规则到系统默认设定。 */
|
|
573
475
|
resetBuiltin(id) {
|
|
574
476
|
const def = DEFAULT_APPROVAL_RULES.find((r) => r.id === id);
|
|
575
477
|
if (!def)
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ask_user_question customTool:人机协作提问问卷工具。
|
|
3
|
-
*
|
|
4
|
-
* 模型需要澄清歧义需求、做重大技术路线决策时调用,向客户端弹出结构化问卷卡片。
|
|
5
|
-
* 从 agent-service.ts 抽出为独立模块。
|
|
6
|
-
*/
|
|
7
1
|
import { Type } from "typebox";
|
|
8
|
-
|
|
9
|
-
export function makeAskUserQuestionTool(clientSession,
|
|
10
|
-
/** 本 runtime 所属会话:提问跟着对话走,快照只把当前对话的问卷推给客户端。 */
|
|
11
|
-
ownerId) {
|
|
2
|
+
export function makeAskUserQuestionTool(clientSession, ownerId) {
|
|
12
3
|
const QuestionOptionSchema = Type.Object({
|
|
13
4
|
label: Type.String({ description: "Display label (1-5 words)" }),
|
|
14
5
|
description: Type.Optional(Type.String({
|
|
@@ -84,7 +75,6 @@ ownerId) {
|
|
|
84
75
|
throw new Error(`User cancelled the question.${note}\n用户取消了提问。${noteZh}`);
|
|
85
76
|
}
|
|
86
77
|
const answers = res;
|
|
87
|
-
// 工具结果:把每道题的回答拼成简洁文本给模型,同时留 details 供 UI 展示。
|
|
88
78
|
const lines = answers.map((a) => {
|
|
89
79
|
const q = qs.find((q) => q.id === a.id);
|
|
90
80
|
const label = a.selected.join(", ");
|
|
@@ -98,7 +88,6 @@ ownerId) {
|
|
|
98
88
|
},
|
|
99
89
|
};
|
|
100
90
|
}
|
|
101
|
-
/** 判定是否应当即时向前端推送问卷弹窗(只推给当前前台会话,未指定会话按全局放行)。 */
|
|
102
91
|
export function shouldPopQuestion(conversationId, activeId) {
|
|
103
92
|
return conversationId === undefined || conversationId === activeId;
|
|
104
93
|
}
|
|
@@ -47,14 +47,42 @@ export function writeAtomicSync(file, data, options = {}) {
|
|
|
47
47
|
try {
|
|
48
48
|
rmSync(tmp, { force: true });
|
|
49
49
|
}
|
|
50
|
-
catch {
|
|
51
|
-
|
|
50
|
+
catch { }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function writeAtomicPortableSync(fs, file, data, nonce, mode = 0o600) {
|
|
54
|
+
if (!nonce || nonce.length > 128 || !/^[A-Za-z0-9_.-]+$/.test(nonce))
|
|
55
|
+
throw new Error("Invalid atomic-write nonce");
|
|
56
|
+
const temporary = `${file}.${nonce}.tmp`;
|
|
57
|
+
try {
|
|
58
|
+
const descriptor = fs.openSync(temporary, "wx", mode);
|
|
59
|
+
try {
|
|
60
|
+
fs.writeFileSync(descriptor, data, "utf8");
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
fs.closeSync(descriptor);
|
|
64
|
+
}
|
|
65
|
+
for (let attempt = 0;; attempt++) {
|
|
66
|
+
try {
|
|
67
|
+
fs.renameSync(temporary, file);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (attempt >= 2 || !["EPERM", "EACCES", "EBUSY"].includes(error.code ?? ""))
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
52
74
|
}
|
|
53
75
|
}
|
|
76
|
+
finally {
|
|
77
|
+
try {
|
|
78
|
+
fs.rmSync(temporary, { force: true });
|
|
79
|
+
}
|
|
80
|
+
catch { }
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export function portableAtomicWriteSyncSource() {
|
|
84
|
+
return `const writeAtomicPortable = (${writeAtomicPortableSync.toString()});`;
|
|
54
85
|
}
|
|
55
|
-
/**
|
|
56
|
-
* 原子写 JSON 辅助函数(默认 2 空格缩进 + 末尾换行)。
|
|
57
|
-
*/
|
|
58
86
|
export function writeJsonAtomicSync(file, data, indent = 2) {
|
|
59
87
|
const text = JSON.stringify(data, null, indent) + "\n";
|
|
60
88
|
writeAtomicSync(file, text);
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* attachment-store.ts — 基于 SHA-256 内容寻址(CAS)的附件存储。
|
|
3
|
-
*
|
|
4
|
-
* 借鉴 DSH 的 dsh-attachment 机制:
|
|
5
|
-
* - 图片与大二进制附件以 sha256 哈希落盘到 `<dataDir>/attachments/<hash>.<ext>`;
|
|
6
|
-
* - WebSocket 快照与会话转录中仅传递紧凑的 hash 引用与 URL;
|
|
7
|
-
* - 浏览器通过 `/api/attachment/:hash` 经 HTTP 访问,带永久强缓存(immutable);
|
|
8
|
-
* - 避免快照和消息列表随会话进行出现数兆字节 base64 的膨胀。
|
|
9
|
-
*/
|
|
10
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
11
2
|
import { mkdirSync, existsSync } from "node:fs";
|
|
12
3
|
import { readFile, readdir, rename, rm, writeFile, stat } from "node:fs/promises";
|
|
@@ -14,7 +5,6 @@ import { join, extname } from "node:path";
|
|
|
14
5
|
import { writeAtomicSync } from "./atomic-file.js";
|
|
15
6
|
let store;
|
|
16
7
|
function indexFile(target, fileName) {
|
|
17
|
-
// Accept legacy hash.ext names, but never unfinished atomic writes.
|
|
18
8
|
const match = /^([a-f0-9]{64})\..+$/i.exec(fileName);
|
|
19
9
|
if (!match || fileName.endsWith(".tmp"))
|
|
20
10
|
return;
|
|
@@ -36,7 +26,6 @@ function ensureIndex(target) {
|
|
|
36
26
|
throw error;
|
|
37
27
|
}));
|
|
38
28
|
}
|
|
39
|
-
/** 初始化附件存储目录(服务启动时调用)。 */
|
|
40
29
|
export function initAttachmentStore(dataDir) {
|
|
41
30
|
const dir = join(dataDir, "attachments");
|
|
42
31
|
if (!existsSync(dir))
|
|
@@ -64,10 +53,6 @@ const EXT_MIME_MAP = {
|
|
|
64
53
|
".bmp": "image/bmp",
|
|
65
54
|
".pdf": "application/pdf",
|
|
66
55
|
};
|
|
67
|
-
/**
|
|
68
|
-
* 将二进制内容写入附件存储(内容寻址,幂等):
|
|
69
|
-
* 已存在同哈希文件则直接返回元数据,不重复写盘。
|
|
70
|
-
*/
|
|
71
56
|
export async function saveAttachment(buffer, mimeType = "application/octet-stream", preferredExt) {
|
|
72
57
|
if (!store) {
|
|
73
58
|
throw new Error("AttachmentStore has not been initialized with initAttachmentStore(dataDir)");
|
|
@@ -78,11 +63,6 @@ export async function saveAttachment(buffer, mimeType = "application/octet-strea
|
|
|
78
63
|
const target = store;
|
|
79
64
|
const filePath = join(target.dir, fileName);
|
|
80
65
|
if (!existsSync(filePath)) {
|
|
81
|
-
// 原地 writeFile 有两个问题:a) 同 hash 并发写时两个 writeFileSync
|
|
82
|
-
// 交错会留下半个文件;b) 读方(/api/attachment/:hash)可能在写完前就命中。
|
|
83
|
-
// 因此先写私有 tmp 再 rename(同目录内原子生效)。POSIX rename 原子覆盖;
|
|
84
|
-
// Windows 目标已存在时报 EEXIST/EPERM —— 内容寻址同 hash 即同内容,
|
|
85
|
-
// 并发对手落盘视为成功。tmp 命名带 uuid,绝不与真实附件名冲突。
|
|
86
66
|
const tmpPath = `${filePath}.${randomUUID()}.tmp`;
|
|
87
67
|
try {
|
|
88
68
|
await writeFile(tmpPath, buffer);
|
|
@@ -105,10 +85,6 @@ export async function saveAttachment(buffer, mimeType = "application/octet-strea
|
|
|
105
85
|
filePath,
|
|
106
86
|
};
|
|
107
87
|
}
|
|
108
|
-
/**
|
|
109
|
-
* 将二进制内容写入附件存储(同步版本,供消息序列化等纯同步链路使用):
|
|
110
|
-
* 已存在同哈希文件则直接返回元数据,不重复写盘。
|
|
111
|
-
*/
|
|
112
88
|
export function saveAttachmentSync(buffer, mimeType = "application/octet-stream", preferredExt) {
|
|
113
89
|
if (!store) {
|
|
114
90
|
throw new Error("AttachmentStore has not been initialized with initAttachmentStore(dataDir)");
|
|
@@ -125,14 +101,10 @@ export function saveAttachmentSync(buffer, mimeType = "application/octet-stream"
|
|
|
125
101
|
catch (err) {
|
|
126
102
|
const code = err.code;
|
|
127
103
|
if (code === "EEXIST") {
|
|
128
|
-
// 并发写同哈希:目标已在,按「已存在」成功路径返回
|
|
129
104
|
}
|
|
130
105
|
else if (code === "EPERM" && existsSync(filePath)) {
|
|
131
|
-
// Windows 杀软/OneDrive 锁住的是 tmp 源而目标已由并发方写好:等同已存在
|
|
132
106
|
}
|
|
133
107
|
else {
|
|
134
|
-
// EPERM 且目标不存在 / 其他错误:照常抛出。吞掉会返回指向缺失文件的
|
|
135
|
-
// 坏记录,消息里图片 404;抛出让 serialize 回退 dataUrl(转录里 base64 仍在)
|
|
136
108
|
throw err;
|
|
137
109
|
}
|
|
138
110
|
}
|
|
@@ -152,11 +124,6 @@ export function saveAttachmentSync(buffer, mimeType = "application/octet-stream"
|
|
|
152
124
|
filePath,
|
|
153
125
|
};
|
|
154
126
|
}
|
|
155
|
-
/**
|
|
156
|
-
* 根据哈希定位附件;filePath、size、mimeType 可直接用于 HTTP 流式发送。
|
|
157
|
-
* 首次有效查询惰性异步扫描旧目录,并发查询共享扫描;后续查询只访问索引。
|
|
158
|
-
* 保存成功会增量更新索引。外部导入文件后需重新 initAttachmentStore。
|
|
159
|
-
*/
|
|
160
127
|
export async function findAttachment(hash) {
|
|
161
128
|
const target = store;
|
|
162
129
|
if (!target || !/^[a-f0-9]{64}$/i.test(hash))
|
|
@@ -194,9 +161,6 @@ export async function findAttachment(hash) {
|
|
|
194
161
|
}
|
|
195
162
|
return null;
|
|
196
163
|
}
|
|
197
|
-
/**
|
|
198
|
-
* 读取附件二进制数据。
|
|
199
|
-
*/
|
|
200
164
|
export async function readAttachment(hash) {
|
|
201
165
|
const record = await findAttachment(hash);
|
|
202
166
|
if (!record)
|