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,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Files service — 从 agent-service.ts 抽出(文件树列目录 / 预览读写 / 路径补全 /
|
|
3
|
-
* SCM 只读查询 / 目录与 git-dir watcher)。
|
|
4
|
-
*
|
|
5
|
-
* 全部为无状态 fs 操作 + 两个自持的 watcher(当前列出目录、git dir),
|
|
6
|
-
* 经 FilesHost 回调与 ClientSession 解耦。
|
|
7
|
-
*/
|
|
8
1
|
import { Dirent, existsSync, mkdirSync, readFileSync, statSync, watch } from "node:fs";
|
|
9
2
|
import { saveFilePreservingMetadata } from "./file-save.js";
|
|
10
3
|
import { isUploadDataTooLong, uploadLimitBytes } from "./payload-limits.js";
|
|
@@ -17,11 +10,7 @@ import { extractOfficeText, isOfficeFile, OFFICE_MAX_FILE_BYTES } from "./office
|
|
|
17
10
|
import { gitDirOf, isNotRepoError, scmStatus, scmHistory, scmFileDiff, scmCommitDetail } from "./scm.js";
|
|
18
11
|
import { getGlobalRemoteSshService, isRemoteWorkspaceUri, parseRemoteWorkspaceUri, resolveRemoteWorkspacePath, } from "./remote-ssh-service.js";
|
|
19
12
|
export const IS_WIN32 = process.platform === "win32";
|
|
20
|
-
/** 机器根虚拟路径:工作区「上一级」到达此处,列出所有盘符(Windows)/ "/"(posix)。
|
|
21
|
-
* 这是 wire 字面量,前端 web/src/components/{RightPanel,FooterBar}.tsx 里同值使用。 */
|
|
22
13
|
export const MACHINE_ROOT = "@root";
|
|
23
|
-
/** 桌面目录(wire 格式):存在且为目录才返回,否则空串(前端不渲染 🖥️)。
|
|
24
|
-
* Linux 优先读 XDG user-dirs(中文环境可能是 ~/桌面),其余平台即 ~/Desktop。 */
|
|
25
14
|
export function desktopDirWire(homeWire) {
|
|
26
15
|
const cands = [];
|
|
27
16
|
if (process.platform === "linux") {
|
|
@@ -34,9 +23,7 @@ export function desktopDirWire(homeWire) {
|
|
|
34
23
|
cands.push(dir);
|
|
35
24
|
}
|
|
36
25
|
}
|
|
37
|
-
catch {
|
|
38
|
-
// 无 XDG 配置就回落 ~/Desktop
|
|
39
|
-
}
|
|
26
|
+
catch { }
|
|
40
27
|
}
|
|
41
28
|
cands.push(`${homeWire}/Desktop`);
|
|
42
29
|
for (const c of cands) {
|
|
@@ -44,33 +31,20 @@ export function desktopDirWire(homeWire) {
|
|
|
44
31
|
if (statSync(wireToAbs(c)).isDirectory())
|
|
45
32
|
return c;
|
|
46
33
|
}
|
|
47
|
-
catch {
|
|
48
|
-
// 不存在就试下一个
|
|
49
|
-
}
|
|
34
|
+
catch { }
|
|
50
35
|
}
|
|
51
36
|
return "";
|
|
52
37
|
}
|
|
53
|
-
/** wire 路径统一用 "/"。绝对 = posix "/...";win32 还有 "C:/..." / 裸 "C:"。
|
|
54
|
-
* 机器浏览(越过工作区根换盘符)发送这些路径;工作区相对树不会产生它们(Windows
|
|
55
|
-
* 文件名不能含 ":",相对路径经 relative() 归一化后也不以 "/" 开头)。
|
|
56
|
-
* win32 还必须把盘符相对路径("D:x",冒号后无分隔符 —— resolve 会落到该盘的
|
|
57
|
-
* 当前目录)与 UNC("\\host\share";"//host/share" 已被上面的 "/" 前缀覆盖)
|
|
58
|
-
* 判为绝对:这些形态若被当工作区相对路径处理,会在跨盘/UNC 下绕过 ".." 检查
|
|
59
|
-
* 逃出工作区。posix 上 "C:x" 是合法文件名,故盘符检查必须限定在 win32。 */
|
|
60
38
|
export function isAbsoluteWirePath(p) {
|
|
61
39
|
if (p === MACHINE_ROOT || p.startsWith("/") || p.startsWith("\\\\"))
|
|
62
40
|
return true;
|
|
63
41
|
return IS_WIN32 && /^[A-Za-z]:/.test(p);
|
|
64
42
|
}
|
|
65
|
-
/** 去掉结尾 "/"(保留 posix 根 "/" 本身),归一成规范的 wire 形式。前端面包屑
|
|
66
|
-
* 不产生结尾斜杠,这里只对补全/直接输入做防御性清理。 */
|
|
67
43
|
export function normWirePath(p) {
|
|
68
44
|
if (p.endsWith("/") && p !== "/")
|
|
69
45
|
return p.replace(/\/+$/, "") || "/";
|
|
70
46
|
return p;
|
|
71
47
|
}
|
|
72
|
-
/** wire 绝对路径("C:/Users/x" / "/Users/x" / "C:")→ 原生绝对路径。
|
|
73
|
-
* 裸盘符根("C:")在 win32 的 resolve 里会落到「C: 上的当前目录」,必须显式转 "C:\\"。 */
|
|
74
48
|
export function wireToAbs(wire) {
|
|
75
49
|
const w = normWirePath(wire);
|
|
76
50
|
if (IS_WIN32) {
|
|
@@ -80,7 +54,6 @@ export function wireToAbs(wire) {
|
|
|
80
54
|
}
|
|
81
55
|
return resolve(w);
|
|
82
56
|
}
|
|
83
|
-
/** 机器浏览模式下某目录的父级 wire 路径:盘符根("C:")→ 机器根;posix "/" 无父级。 */
|
|
84
57
|
export function absoluteParent(wire) {
|
|
85
58
|
const s = normWirePath(wire);
|
|
86
59
|
if (s === "" || s === MACHINE_ROOT || s === "/")
|
|
@@ -89,13 +62,11 @@ export function absoluteParent(wire) {
|
|
|
89
62
|
if (i < 0)
|
|
90
63
|
return /^[A-Za-z]:$/.test(s) ? MACHINE_ROOT : null;
|
|
91
64
|
if (i === 0)
|
|
92
|
-
return "/";
|
|
65
|
+
return "/";
|
|
93
66
|
return s.slice(0, i);
|
|
94
67
|
}
|
|
95
|
-
/** 预览只读文件前 512KB。 */
|
|
96
68
|
export const MAX_PREVIEW_BYTES = 512 * 1024;
|
|
97
69
|
export { MAX_UPLOAD_BYTES, MAX_UPLOAD_BASE64_CHARS, WS_MAX_PAYLOAD_BYTES, isUploadDataTooLong, } from "./payload-limits.js";
|
|
98
|
-
// mac/linux: hide build & dependency noise (original behavior).
|
|
99
70
|
const IGNORED_ENTRIES = new Set([
|
|
100
71
|
"node_modules",
|
|
101
72
|
".git",
|
|
@@ -113,51 +84,17 @@ const IGNORED_ENTRIES = new Set([
|
|
|
113
84
|
".DS_Store",
|
|
114
85
|
"Thumbs.db",
|
|
115
86
|
]);
|
|
116
|
-
// Windows: the file tree is the primary way to navigate a project, so only
|
|
117
|
-
// hide what would flood or destabilize the panel (dependency trees, VCS
|
|
118
|
-
// internals, session data) plus pure junk. Build output (dist/.next/…) and
|
|
119
|
-
// local env dirs (venv/__pycache__/…) stay visible — "所有文件可查看".
|
|
120
87
|
const IGNORED_ENTRIES_WIN = new Set(["node_modules", ".git", ".pi-web", ".DS_Store", "Thumbs.db", "desktop.ini"]);
|
|
121
|
-
/** The ignore set for the current platform — keeps win/posix lists separate. */
|
|
122
88
|
function ignoredEntries() {
|
|
123
89
|
return IS_WIN32 ? IGNORED_ENTRIES_WIN : IGNORED_ENTRIES;
|
|
124
90
|
}
|
|
125
|
-
/**
|
|
126
|
-
* Resolve a workspace-relative path against a root, refusing traversal
|
|
127
|
-
* (".." escapes). Returns { abs, rel } — rel is normalized and slash-
|
|
128
|
-
* separated — or null when the path leaves the workspace.
|
|
129
|
-
*/
|
|
130
91
|
export function workspacePath(root, raw) {
|
|
131
92
|
const abs = resolve(root, raw);
|
|
132
93
|
const rawRel = relative(root, abs);
|
|
133
|
-
// 只查 ".." 拦不住 Windows 的跨盘/UNC:relative("C:/a","D:/x") 与
|
|
134
|
-
// relative("C:/a","//h/s") 返回绝对路径("D:\x"、"\\h\s\"),不以 ".." 开头;
|
|
135
|
-
// 盘符相对路径("D:x")经 resolve 落到该盘当前目录后也归此形 —— 必须同时
|
|
136
|
-
// 拒绝 isAbsolute 的结果,否则 "D:x" 这类输入可逃出工作区根。
|
|
137
94
|
if (rawRel.startsWith("..") || rawRel.includes(`${sep}..`) || isAbsolute(rawRel))
|
|
138
95
|
return null;
|
|
139
|
-
// Normalize to forward slashes: the wire protocol and the frontend always
|
|
140
|
-
// use "/", but relative() returns "\\" on Windows.
|
|
141
96
|
return { abs, rel: rawRel.split(sep).join("/") };
|
|
142
97
|
}
|
|
143
|
-
/**
|
|
144
|
-
* Read a directory for the file panel. The two platforms intentionally use
|
|
145
|
-
* different strategies — do NOT unify them:
|
|
146
|
-
*
|
|
147
|
-
* darwin/linux (posix): hide build/dependency noise, small cap; a listing
|
|
148
|
-
* failure (deleted/renamed dir → ENOENT/ENOTDIR, permission → EACCES/EPERM)
|
|
149
|
-
* degrades to an empty listing plus a notice chosen by errorCode — the server
|
|
150
|
-
* must NEVER crash on a vanished directory (issue #74).
|
|
151
|
-
*
|
|
152
|
-
* win32: stability and completeness first, preview second. ACL-protected
|
|
153
|
-
* system dirs (C:\$Recycle.Bin, Program Files internals, OneDrive placeholders)
|
|
154
|
-
* throw EPERM/EACCES on open — that must not kill the panel, so it degrades
|
|
155
|
-
* to an empty listing plus a warning. Directory symlinks/junctions are
|
|
156
|
-
* followed (all platforms — Android/Termux's ~/storage/* entries are symlinks
|
|
157
|
-
* too) so folder links stay navigable; broken links still show as files
|
|
158
|
-
* instead of vanishing. The cap is 4x posix and truncation is reported
|
|
159
|
-
* via `truncated` instead of happening silently.
|
|
160
|
-
*/
|
|
161
98
|
async function readDirForUI(abs, rel) {
|
|
162
99
|
const { join } = await import("node:path");
|
|
163
100
|
const fs = await import("node:fs/promises");
|
|
@@ -168,12 +105,6 @@ async function readDirForUI(abs, rel) {
|
|
|
168
105
|
dirents = await fs.readdir(abs, { withFileTypes: true });
|
|
169
106
|
}
|
|
170
107
|
catch (err) {
|
|
171
|
-
// 任何 readdir 失败都降级为“空列表 + notice”,绝不向上抛:listFiles 以
|
|
172
|
-
// fire-and-forget(void …)调用,未处理的 rejection 会成为 unhandled
|
|
173
|
-
// rejection 直接杀掉整个服务进程(issue #74:目录被删除/改名后刷新即崩)。
|
|
174
|
-
// 缺失(ENOENT/ENOTDIR)、权限拒绝(EACCES/EPERM)、系统 ACL 目录全部归此,
|
|
175
|
-
// 文案由 listFiles 按 errorCode 分类:缺失 = 软提示“目录不存在”,
|
|
176
|
-
// 权限/其余 = posix 硬错误 notice / win32 软提示(ACL 系统目录是常态)。
|
|
177
108
|
const e = err;
|
|
178
109
|
return { entries: [], truncated: false, error: e.message, errorCode: e.code };
|
|
179
110
|
}
|
|
@@ -183,9 +114,6 @@ async function readDirForUI(abs, rel) {
|
|
|
183
114
|
continue;
|
|
184
115
|
let type;
|
|
185
116
|
if (d.isSymbolicLink()) {
|
|
186
|
-
// Symlinks (mklink /D reparse points on win32, but also the directory
|
|
187
|
-
// links under Termux's ~/storage) are followed on ALL platforms so
|
|
188
|
-
// folder links stay navigable; broken links still show as files.
|
|
189
117
|
try {
|
|
190
118
|
const st = await fs.stat(join(abs, d.name));
|
|
191
119
|
type = st.isDirectory() ? "dir" : "file";
|
|
@@ -197,7 +125,6 @@ async function readDirForUI(abs, rel) {
|
|
|
197
125
|
else {
|
|
198
126
|
type = d.isDirectory() ? "dir" : "file";
|
|
199
127
|
}
|
|
200
|
-
// 机器浏览(绝对路径)下 rel 是绝对 wire 路径;posix 根 "/" 特殊处理避免 "//name"。
|
|
201
128
|
const entryPath = rel === "" ? d.name : rel.endsWith("/") ? `${rel.slice(0, -1)}/${d.name}` : `${rel}/${d.name}`;
|
|
202
129
|
const entry = {
|
|
203
130
|
name: d.name,
|
|
@@ -214,9 +141,6 @@ async function readDirForUI(abs, rel) {
|
|
|
214
141
|
out.length = MAX;
|
|
215
142
|
return { entries: out, truncated };
|
|
216
143
|
}
|
|
217
|
-
/** dirent → FileEntry classification: directory symlinks are resolved via
|
|
218
|
-
* stat() on ALL platforms (#262 — Termux's ~/storage/* entries are symlinks;
|
|
219
|
-
* the directory-only cwd picker renders an empty list if they type as files). */
|
|
220
144
|
async function classifyDirent(d, absDir) {
|
|
221
145
|
const fs = await import("node:fs/promises");
|
|
222
146
|
const { join } = await import("node:path");
|
|
@@ -226,7 +150,7 @@ async function classifyDirent(d, absDir) {
|
|
|
226
150
|
type = (await fs.stat(join(absDir, d.name))).isDirectory() ? "dir" : "file";
|
|
227
151
|
}
|
|
228
152
|
catch {
|
|
229
|
-
type = "file";
|
|
153
|
+
type = "file";
|
|
230
154
|
}
|
|
231
155
|
}
|
|
232
156
|
else {
|
|
@@ -236,25 +160,18 @@ async function classifyDirent(d, absDir) {
|
|
|
236
160
|
}
|
|
237
161
|
export class FilesService {
|
|
238
162
|
host;
|
|
239
|
-
// ---- 当前列出目录的 watcher ----
|
|
240
163
|
fsWatcher = null;
|
|
241
164
|
watchPath = null;
|
|
242
165
|
watchTimer = null;
|
|
243
|
-
/** Recursive-watch state (win32/darwin): one native recursive watcher on the
|
|
244
|
-
* workspace root covers the WHOLE tree; watchPath just tracks which listed
|
|
245
|
-
* directory file_changed should refresh. */
|
|
246
166
|
recursiveWatcher = false;
|
|
247
167
|
watchRoot = null;
|
|
248
|
-
/** 已对哪个工作区根提示过「实时监听不可用,已回落轮询」——只提示一次。 */
|
|
249
168
|
degradedNoticedFor = null;
|
|
250
|
-
// ---- git dir watcher ----
|
|
251
169
|
gitWatcher = null;
|
|
252
170
|
gitWatchCwd = null;
|
|
253
171
|
gitDirtyTimer = null;
|
|
254
172
|
constructor(host) {
|
|
255
173
|
this.host = host;
|
|
256
174
|
}
|
|
257
|
-
/** 机器根列目录(此电脑/盘符列表);posix 上就是根 "/"。 */
|
|
258
175
|
async machineRootEntries() {
|
|
259
176
|
const fsp = await import("node:fs/promises");
|
|
260
177
|
if (IS_WIN32) {
|
|
@@ -266,15 +183,10 @@ export class FilesService {
|
|
|
266
183
|
if (st.isDirectory())
|
|
267
184
|
out.push({ name: drive, path: drive, type: "dir" });
|
|
268
185
|
}
|
|
269
|
-
catch {
|
|
270
|
-
// 空口/未挂载盘符 —— 跳过
|
|
271
|
-
}
|
|
186
|
+
catch { }
|
|
272
187
|
}
|
|
273
188
|
return out;
|
|
274
189
|
}
|
|
275
|
-
// Android/Termux: "/" itself is not listable (even `ls /` is denied),
|
|
276
|
-
// so fall back to $HOME + shared storage as the machine-root landing
|
|
277
|
-
// spots — otherwise machine browsing is a dead end on Android.
|
|
278
190
|
try {
|
|
279
191
|
await fsp.readdir("/");
|
|
280
192
|
}
|
|
@@ -285,20 +197,14 @@ export class FilesService {
|
|
|
285
197
|
await fsp.readdir("/storage/emulated/0");
|
|
286
198
|
out.push({ name: "/storage/emulated/0", path: "/storage/emulated/0", type: "dir" });
|
|
287
199
|
}
|
|
288
|
-
catch {
|
|
289
|
-
// no shared storage
|
|
290
|
-
}
|
|
200
|
+
catch { }
|
|
291
201
|
return out;
|
|
292
202
|
}
|
|
293
203
|
return [{ name: "/", path: "/", type: "dir" }];
|
|
294
204
|
}
|
|
295
|
-
/** 单字段错误文本的语言(host 未接线时英文默认)。 */
|
|
296
205
|
lang() {
|
|
297
206
|
return this.host.getLang?.() ?? "en";
|
|
298
207
|
}
|
|
299
|
-
/** 目录列表失败的 notice:缺失路径(ENOENT/ENOTDIR)是删除/改名等正常场景,
|
|
300
|
-
* 软提示“目录不存在”;其余(权限拒绝等)保留原平台语义——win32 软提示
|
|
301
|
-
* (ACL 系统目录常见),posix 硬错误(error 级 notice,取代曾经的 throw)。 */
|
|
302
208
|
emitListError(path, error, code) {
|
|
303
209
|
if (code === "ENOENT") {
|
|
304
210
|
this.host.emit({
|
|
@@ -335,13 +241,9 @@ export class FilesService {
|
|
|
335
241
|
const { resolve, sep, relative } = await import("node:path");
|
|
336
242
|
const root = resolve(rawCwd);
|
|
337
243
|
let raw = relPath ?? "";
|
|
338
|
-
// Expand a leading "~/" (path-bar input) to the home directory — same
|
|
339
|
-
// rules as completePath/makeDir. The result is absolute, so it lands in
|
|
340
|
-
// the machine-browse branch below; wire paths always use "/".
|
|
341
244
|
if (raw === "~" || raw.startsWith("~/") || raw.startsWith("~\\")) {
|
|
342
245
|
raw = (raw === "~" ? homedir() : homedir() + raw.slice(1)).split(sep).join("/");
|
|
343
246
|
}
|
|
344
|
-
// ---- 机器根(此电脑:盘符列表)—— 工作区之上的虚拟层 ----
|
|
345
247
|
if (raw === MACHINE_ROOT || raw === MACHINE_ROOT + "/") {
|
|
346
248
|
const entries = await this.machineRootEntries();
|
|
347
249
|
this.host.emit({
|
|
@@ -354,8 +256,6 @@ export class FilesService {
|
|
|
354
256
|
});
|
|
355
257
|
return;
|
|
356
258
|
}
|
|
357
|
-
// ---- 绝对路径浏览(Windows 盘符 / posix "/"):允许越过工作区根 ----
|
|
358
|
-
// 机器模式不设 watcher(工作区递归 watch 不覆盖别的盘),文件变动靠 10s 轮询。
|
|
359
259
|
if (isAbsoluteWirePath(raw)) {
|
|
360
260
|
const wire = normWirePath(raw);
|
|
361
261
|
const abs = wireToAbs(wire);
|
|
@@ -372,17 +272,13 @@ export class FilesService {
|
|
|
372
272
|
this.emitListError(wire, error, errorCode);
|
|
373
273
|
return;
|
|
374
274
|
}
|
|
375
|
-
// ---- 工作区相对视图(原有行为) ----
|
|
376
275
|
const target = raw ? resolve(root, raw) : root;
|
|
377
|
-
// 若工作区根目录自身尚不存在,自动自愈创建,避免首帧报错
|
|
378
276
|
if (raw === "") {
|
|
379
277
|
try {
|
|
380
278
|
const fsp = await import("node:fs/promises");
|
|
381
279
|
await fsp.mkdir(target, { recursive: true });
|
|
382
280
|
}
|
|
383
|
-
catch {
|
|
384
|
-
/* ignore if exists */
|
|
385
|
-
}
|
|
281
|
+
catch { }
|
|
386
282
|
}
|
|
387
283
|
const rawRel = relative(root, target);
|
|
388
284
|
if (rawRel.startsWith("..") || rawRel.includes(`${sep}..`)) {
|
|
@@ -394,12 +290,8 @@ export class FilesService {
|
|
|
394
290
|
});
|
|
395
291
|
return;
|
|
396
292
|
}
|
|
397
|
-
// Normalize to forward slashes: the wire protocol and the frontend
|
|
398
|
-
// always use "/", but relative() returns "\\" on Windows.
|
|
399
293
|
const rel = rawRel.split(sep).join("/");
|
|
400
294
|
const { entries, truncated, error, errorCode } = await readDirForUI(target, rel);
|
|
401
|
-
// Watch the listed directory only after a successful read — a missing
|
|
402
|
-
// dir must not create a watcher on a phantom path (issue #74).
|
|
403
295
|
if (error) {
|
|
404
296
|
this.emitListError(rel === "" ? root : rel, error, errorCode);
|
|
405
297
|
}
|
|
@@ -410,7 +302,6 @@ export class FilesService {
|
|
|
410
302
|
this.host.emit({
|
|
411
303
|
type: "files",
|
|
412
304
|
path: rel === "" ? "" : rel,
|
|
413
|
-
// 工作区根也允许「上一级」→ 项目文件夹的上一级(盘符根则到机器根,posix 根无父级)。
|
|
414
305
|
parent: rel === "" ? absoluteParent(rootWire) : rel.includes("/") ? rel.slice(0, rel.lastIndexOf("/")) : "",
|
|
415
306
|
entries,
|
|
416
307
|
truncated,
|
|
@@ -446,7 +337,6 @@ export class FilesService {
|
|
|
446
337
|
const results = [];
|
|
447
338
|
let visited = 0;
|
|
448
339
|
let truncated = false;
|
|
449
|
-
// 1) 优先精确探测输入是否为已存在的绝对路径或相对路径
|
|
450
340
|
const normQuery = rawQuery.replace(/\\/g, "/");
|
|
451
341
|
const q = normQuery.toLowerCase();
|
|
452
342
|
try {
|
|
@@ -486,11 +376,8 @@ export class FilesService {
|
|
|
486
376
|
}
|
|
487
377
|
}
|
|
488
378
|
}
|
|
489
|
-
catch {
|
|
490
|
-
/* ignore probe failure */
|
|
491
|
-
}
|
|
379
|
+
catch { }
|
|
492
380
|
const budgetLeft = () => results.length < MAX_RESULTS && visited < MAX_VISITED && Date.now() - start < MAX_MS;
|
|
493
|
-
// Breadth-first-ish iterative stack; depth cap is a symlink-cycle guard.
|
|
494
381
|
const walk = async (abs, rel, depth) => {
|
|
495
382
|
if (!budgetLeft() || depth > 24) {
|
|
496
383
|
truncated = true;
|
|
@@ -501,7 +388,7 @@ export class FilesService {
|
|
|
501
388
|
dirents = await fsp.readdir(abs, { withFileTypes: true });
|
|
502
389
|
}
|
|
503
390
|
catch {
|
|
504
|
-
return;
|
|
391
|
+
return;
|
|
505
392
|
}
|
|
506
393
|
for (const d of dirents) {
|
|
507
394
|
visited++;
|
|
@@ -514,13 +401,11 @@ export class FilesService {
|
|
|
514
401
|
const childRel = rel ? `${rel}/${d.name}` : d.name;
|
|
515
402
|
let isDir = d.isDirectory();
|
|
516
403
|
if (d.isSymbolicLink()) {
|
|
517
|
-
// Follow directory symlinks (Termux's ~/storage/*); the depth
|
|
518
|
-
// cap doubles as a symlink-cycle guard, budgets bound the cost.
|
|
519
404
|
try {
|
|
520
405
|
isDir = (await fsp.stat(join(abs, d.name))).isDirectory();
|
|
521
406
|
}
|
|
522
407
|
catch {
|
|
523
|
-
isDir = false;
|
|
408
|
+
isDir = false;
|
|
524
409
|
}
|
|
525
410
|
}
|
|
526
411
|
const childRelLower = childRel.toLowerCase();
|
|
@@ -551,12 +436,6 @@ export class FilesService {
|
|
|
551
436
|
this.host.emit({ type: "search_files_result", reqId, ok: false, results: [] });
|
|
552
437
|
}
|
|
553
438
|
}
|
|
554
|
-
/**
|
|
555
|
-
* Source-control panel: read-only git queries via server-side execFile
|
|
556
|
-
* (no shell, no prompts). Always responds with an scm_data message echoing
|
|
557
|
-
* reqId so the client's request matching never stalls. Also (re)arms the
|
|
558
|
-
* git-dir watcher so external repo changes push scm_changed.
|
|
559
|
-
*/
|
|
560
439
|
async scmQuery(kind, reqId, arg) {
|
|
561
440
|
const cwd = this.host.getActiveCwd();
|
|
562
441
|
const isRemote = isRemoteWorkspaceUri(cwd);
|
|
@@ -582,8 +461,6 @@ export class FilesService {
|
|
|
582
461
|
}
|
|
583
462
|
}
|
|
584
463
|
else {
|
|
585
|
-
// Path stays inside the workspace (defense in depth — paths come
|
|
586
|
-
// from our own listing, and execFile passes args verbatim anyway).
|
|
587
464
|
const { resolve, relative } = await import("node:path");
|
|
588
465
|
const rel = relative(resolve(cwd), resolve(cwd, arg.path));
|
|
589
466
|
if (rel.startsWith("..") || rel === "")
|
|
@@ -609,7 +486,6 @@ export class FilesService {
|
|
|
609
486
|
}
|
|
610
487
|
catch (err) {
|
|
611
488
|
if (isNotRepoError(err)) {
|
|
612
|
-
// Not a repo — a valid empty answer so the panel shows its hint.
|
|
613
489
|
this.host.emit({
|
|
614
490
|
type: "scm_data",
|
|
615
491
|
reqId,
|
|
@@ -639,12 +515,6 @@ export class FilesService {
|
|
|
639
515
|
});
|
|
640
516
|
}
|
|
641
517
|
}
|
|
642
|
-
/**
|
|
643
|
-
* Watch the active repo's git dir (HEAD / index / packed-refs live at the
|
|
644
|
-
* top level, which covers commit / stage / checkout). Re-targets when the
|
|
645
|
-
* queried workspace changes. Uses `git rev-parse --absolute-git-dir` so
|
|
646
|
-
* worktrees and submodules resolve to the real dir.
|
|
647
|
-
*/
|
|
648
518
|
async watchGitDir(cwd) {
|
|
649
519
|
if (this.gitWatchCwd === cwd && this.gitWatcher)
|
|
650
520
|
return;
|
|
@@ -657,19 +527,16 @@ export class FilesService {
|
|
|
657
527
|
this.gitWatcher = watch(gitDir, { persistent: false }, () => {
|
|
658
528
|
if (this.host.isDisposed() || this.gitDirtyTimer)
|
|
659
529
|
return;
|
|
660
|
-
// Debounce: one checkout/commit fires several fs events.
|
|
661
530
|
this.gitDirtyTimer = setTimeout(() => {
|
|
662
531
|
this.gitDirtyTimer = null;
|
|
663
532
|
this.host.emit({ type: "scm_changed" });
|
|
664
533
|
}, 600);
|
|
665
534
|
});
|
|
666
535
|
this.gitWatcher.on("error", () => {
|
|
667
|
-
// Unsupported filesystem — silently fall back to manual refresh.
|
|
668
536
|
this.unwatchGit();
|
|
669
537
|
});
|
|
670
538
|
}
|
|
671
539
|
catch {
|
|
672
|
-
// no .git here (or git missing) — watcher stays off; queries still work
|
|
673
540
|
this.unwatchGit();
|
|
674
541
|
}
|
|
675
542
|
}
|
|
@@ -678,9 +545,7 @@ export class FilesService {
|
|
|
678
545
|
try {
|
|
679
546
|
this.gitWatcher.close();
|
|
680
547
|
}
|
|
681
|
-
catch {
|
|
682
|
-
// already gone
|
|
683
|
-
}
|
|
548
|
+
catch { }
|
|
684
549
|
}
|
|
685
550
|
this.gitWatcher = null;
|
|
686
551
|
this.gitWatchCwd = null;
|
|
@@ -692,34 +557,24 @@ export class FilesService {
|
|
|
692
557
|
watchDir(absPath, rel) {
|
|
693
558
|
if (this.host.isDisposed())
|
|
694
559
|
return;
|
|
695
|
-
// ---- Recursive mode (native on win32 / darwin): watch the workspace
|
|
696
|
-
// root once, so deep changes in NOT-listed subdirectories still refresh
|
|
697
|
-
// the panel (the old per-directory watch only saw the current level).
|
|
698
560
|
if (process.platform === "win32" || process.platform === "darwin") {
|
|
699
561
|
const root = resolve(this.host.getCwd());
|
|
700
562
|
if (this.recursiveWatcher) {
|
|
701
563
|
if (this.watchRoot === root) {
|
|
702
|
-
// Same workspace — only retarget the refresh path.
|
|
703
564
|
this.watchPath = rel;
|
|
704
565
|
return;
|
|
705
566
|
}
|
|
706
|
-
this.unwatchDir();
|
|
567
|
+
this.unwatchDir();
|
|
707
568
|
}
|
|
708
569
|
try {
|
|
709
570
|
const w = watch(root, { persistent: false, recursive: true }, (_event, filename) => {
|
|
710
|
-
// Skip high-churn subtrees (npm install storms); .git has its
|
|
711
|
-
// own watcher for the SCM panel. filename may be null on some
|
|
712
|
-
// platforms — let those through (debounce absorbs bursts).
|
|
713
571
|
if (filename) {
|
|
714
572
|
const f = String(filename).split("\\").join("/");
|
|
715
|
-
// Single-segment names (e.g. the dir itself) have no "/" —
|
|
716
|
-
// slice(0, -1) would corrupt them, so special-case that.
|
|
717
573
|
const slash = f.indexOf("/");
|
|
718
574
|
const top = slash === -1 ? f : f.slice(0, slash);
|
|
719
575
|
if (top === "node_modules" || top === ".git")
|
|
720
576
|
return;
|
|
721
577
|
}
|
|
722
|
-
// Burst events are debounced into a single refresh.
|
|
723
578
|
if (this.watchTimer)
|
|
724
579
|
return;
|
|
725
580
|
this.watchTimer = setTimeout(() => {
|
|
@@ -731,7 +586,6 @@ export class FilesService {
|
|
|
731
586
|
}, 400);
|
|
732
587
|
});
|
|
733
588
|
w.on("error", () => {
|
|
734
|
-
// Directory deleted / unsupported — fall back to poll semantics.
|
|
735
589
|
this.noticeDegraded(root);
|
|
736
590
|
this.unwatchDir();
|
|
737
591
|
});
|
|
@@ -742,23 +596,18 @@ export class FilesService {
|
|
|
742
596
|
return;
|
|
743
597
|
}
|
|
744
598
|
catch {
|
|
745
|
-
// recursive unsupported here — fall through to per-directory watch.
|
|
746
599
|
this.fsWatcher = null;
|
|
747
600
|
this.recursiveWatcher = false;
|
|
748
601
|
this.watchRoot = null;
|
|
749
602
|
this.noticeDegraded(root);
|
|
750
603
|
}
|
|
751
604
|
}
|
|
752
|
-
// ---- Fallback: single non-recursive watch on the LISTED directory.
|
|
753
605
|
if (!this.recursiveWatcher && this.watchPath === rel && this.fsWatcher)
|
|
754
606
|
return;
|
|
755
607
|
this.unwatchDir();
|
|
756
608
|
this.watchPath = rel;
|
|
757
609
|
try {
|
|
758
|
-
// persistent: false — the watcher must not keep the process alive.
|
|
759
610
|
this.fsWatcher = watch(absPath, { persistent: false }, () => {
|
|
760
|
-
// Burst events (npm install, git ops, editor save→rename) are
|
|
761
|
-
// debounced into a single refresh.
|
|
762
611
|
if (this.watchTimer)
|
|
763
612
|
return;
|
|
764
613
|
this.watchTimer = setTimeout(() => {
|
|
@@ -767,20 +616,15 @@ export class FilesService {
|
|
|
767
616
|
}, 400);
|
|
768
617
|
});
|
|
769
618
|
this.fsWatcher.on("error", () => {
|
|
770
|
-
// Directory deleted / unsupported fs — stop watching; the poll (or
|
|
771
|
-
// the next navigation) restores things.
|
|
772
619
|
this.unwatchDir();
|
|
773
620
|
});
|
|
774
621
|
}
|
|
775
622
|
catch {
|
|
776
|
-
// fs.watch unsupported (some network mounts, containers) — poll covers it.
|
|
777
623
|
this.fsWatcher = null;
|
|
778
624
|
this.watchPath = null;
|
|
779
625
|
this.noticeDegraded(absPath);
|
|
780
626
|
}
|
|
781
627
|
}
|
|
782
|
-
/** 实时监听不可用(网络盘/WSL/受限目录):一次性告知用户已回落 10s 轮询,
|
|
783
|
-
* 免得疑惑「面板为什么不实时」。每个工作区根只提示一次。 */
|
|
784
628
|
noticeDegraded(root) {
|
|
785
629
|
if (this.degradedNoticedFor === root)
|
|
786
630
|
return;
|
|
@@ -801,16 +645,13 @@ export class FilesService {
|
|
|
801
645
|
try {
|
|
802
646
|
this.fsWatcher.close();
|
|
803
647
|
}
|
|
804
|
-
catch {
|
|
805
|
-
// already closed
|
|
806
|
-
}
|
|
648
|
+
catch { }
|
|
807
649
|
this.fsWatcher = null;
|
|
808
650
|
}
|
|
809
651
|
this.recursiveWatcher = false;
|
|
810
652
|
this.watchRoot = null;
|
|
811
653
|
this.watchPath = null;
|
|
812
654
|
}
|
|
813
|
-
/** Read a workspace file for the preview panel (size-capped, binary-safe). */
|
|
814
655
|
async readFile(relPath) {
|
|
815
656
|
const root = this.host.getCwd();
|
|
816
657
|
if (isRemoteWorkspaceUri(root)) {
|
|
@@ -823,7 +664,6 @@ export class FilesService {
|
|
|
823
664
|
let abs;
|
|
824
665
|
let rel;
|
|
825
666
|
if (absWire) {
|
|
826
|
-
// 机器浏览:绝对路径直接读;回显用绝对 wire 形式(前端按 path 匹配)。
|
|
827
667
|
abs = wireToAbs(relPath);
|
|
828
668
|
rel = abs.split(sep).join("/");
|
|
829
669
|
}
|
|
@@ -852,8 +692,6 @@ export class FilesService {
|
|
|
852
692
|
return;
|
|
853
693
|
}
|
|
854
694
|
const name = relPath.split(/[\\/]/).pop() ?? relPath;
|
|
855
|
-
// Office 文档(docx/xlsx/xlsm):转 Markdown 文本下发,前端按 Markdown
|
|
856
|
-
// 渲染表格/段落——文件树、附件、预览弹窗随处可看。失败回落到底下旧分支。
|
|
857
695
|
if (isOfficeFile(name) && stat.size <= OFFICE_MAX_FILE_BYTES) {
|
|
858
696
|
try {
|
|
859
697
|
const data = await fs.readFile(abs);
|
|
@@ -874,13 +712,9 @@ export class FilesService {
|
|
|
874
712
|
return;
|
|
875
713
|
}
|
|
876
714
|
}
|
|
877
|
-
catch {
|
|
878
|
-
/* 解析失败(加密/损坏/非预期结构)→ 回落旧的二进制嗅探分支 */
|
|
879
|
-
}
|
|
715
|
+
catch { }
|
|
880
716
|
}
|
|
881
717
|
const kind = previewKind(name);
|
|
882
|
-
// Media previews stream over the /api/file HTTP endpoint, so only
|
|
883
|
-
// metadata is sent here — the raw bytes never touch the socket.
|
|
884
718
|
if (kind === "image" || kind === "video" || kind === "audio") {
|
|
885
719
|
this.host.emit({
|
|
886
720
|
type: "file_content",
|
|
@@ -895,10 +729,6 @@ export class FilesService {
|
|
|
895
729
|
});
|
|
896
730
|
return;
|
|
897
731
|
}
|
|
898
|
-
// Everything else: read a capped prefix and sniff the content.
|
|
899
|
-
// Anything that looks like text previews as text regardless of its
|
|
900
|
-
// extension (jsonl, .log.1, weird suffixes, …); binary content gets
|
|
901
|
-
// a hex dump of the first few KB instead of being refused.
|
|
902
732
|
const handle = await fs.open(abs, "r");
|
|
903
733
|
try {
|
|
904
734
|
const buf = Buffer.alloc(Math.min(stat.size, MAX_PREVIEW_BYTES));
|
|
@@ -944,7 +774,6 @@ export class FilesService {
|
|
|
944
774
|
});
|
|
945
775
|
}
|
|
946
776
|
}
|
|
947
|
-
/** Save text from the file preview panel within the active workspace. */
|
|
948
777
|
async writeFile(relPath, text) {
|
|
949
778
|
const root = this.host.getCwd();
|
|
950
779
|
if (isRemoteWorkspaceUri(root)) {
|
|
@@ -999,8 +828,6 @@ export class FilesService {
|
|
|
999
828
|
text: `已保存:${rel}`,
|
|
1000
829
|
textEn: `Saved: ${rel}`,
|
|
1001
830
|
});
|
|
1002
|
-
// Re-read through the same path as the preview request so the client
|
|
1003
|
-
// gets the canonical content, line count and file size after saving.
|
|
1004
831
|
await this.readFile(rel);
|
|
1005
832
|
}
|
|
1006
833
|
catch (err) {
|
|
@@ -1012,13 +839,6 @@ export class FilesService {
|
|
|
1012
839
|
});
|
|
1013
840
|
}
|
|
1014
841
|
}
|
|
1015
|
-
/**
|
|
1016
|
-
* Upload a file (base64, no data: prefix) INTO a workspace directory —
|
|
1017
|
-
* the file manager's right-click “upload here” action. The target dir may
|
|
1018
|
-
* be nested and is created on demand; the name is basename-sanitized so a
|
|
1019
|
-
* malicious payload can't escape the directory. Emits notice + file_changed
|
|
1020
|
-
* for the target dir (the recursive watcher may not cover it on posix).
|
|
1021
|
-
*/
|
|
1022
842
|
async uploadFile(relDir, name, data, uploadId) {
|
|
1023
843
|
const root = this.host.getCwd();
|
|
1024
844
|
if (isRemoteWorkspaceUri(root)) {
|
|
@@ -1041,15 +861,11 @@ export class FilesService {
|
|
|
1041
861
|
}
|
|
1042
862
|
}
|
|
1043
863
|
else if (relDir) {
|
|
1044
|
-
// 机器浏览的目录(可能是盘符根 "C:"):按绝对路径解析。
|
|
1045
864
|
wp = { abs: wireToAbs(relDir), rel: wireToAbs(relDir).split(sep).join("/") };
|
|
1046
865
|
}
|
|
1047
866
|
else {
|
|
1048
867
|
wp = { abs: root, rel: "" };
|
|
1049
868
|
}
|
|
1050
|
-
// 与 createEntry/renameEntry 同口径(this.sanitizeName):只取 basename,
|
|
1051
|
-
// 空 / "." / ".." / Windows 保留名 / 尾点空格一律拒绝 —— 旧的内联替换
|
|
1052
|
-
// 会放过 "con.txt"、"a.." 这类「建了删不掉」的名字。
|
|
1053
869
|
const safe = this.sanitizeName(name);
|
|
1054
870
|
if (!safe) {
|
|
1055
871
|
emitErr(`文件名不合法:${name}`, `Invalid file name: ${name}`);
|
|
@@ -1058,7 +874,6 @@ export class FilesService {
|
|
|
1058
874
|
const abs = resolve(wp.abs, safe);
|
|
1059
875
|
let uploadRel;
|
|
1060
876
|
if (absDir) {
|
|
1061
|
-
// 绝对目录模式不再校验工作区归属(机器浏览)。
|
|
1062
877
|
uploadRel = abs.split(sep).join("/");
|
|
1063
878
|
}
|
|
1064
879
|
else {
|
|
@@ -1088,9 +903,6 @@ export class FilesService {
|
|
|
1088
903
|
emitErr(`已存在:${uploadRel}`, `Already exists: ${uploadRel}`);
|
|
1089
904
|
return;
|
|
1090
905
|
}
|
|
1091
|
-
// wx:与预检之间存在窗口(TOCTOU),并发同名上传走 EEXIST 落到 catch
|
|
1092
|
-
// 报错 —— 两个上传路径语义统一为「目标已存在拒绝」,绝不静默截断覆盖
|
|
1093
|
-
// (/api/file-transfer/upload 一直是 open(dest, "wx") 拒绝)。
|
|
1094
906
|
writeUploadExclusiveSync(abs, buf);
|
|
1095
907
|
this.host.emit({
|
|
1096
908
|
type: "notice",
|
|
@@ -1098,9 +910,6 @@ export class FilesService {
|
|
|
1098
910
|
text: `已上传:${uploadRel}`,
|
|
1099
911
|
textEn: `Uploaded: ${uploadRel}`,
|
|
1100
912
|
});
|
|
1101
|
-
// Emit for the target directory itself so the panel refreshes even
|
|
1102
|
-
// when the active listing/preview isn't that dir (posix watcher only
|
|
1103
|
-
// sees the LISTED directory).
|
|
1104
913
|
this.host.emit({
|
|
1105
914
|
type: "file_changed",
|
|
1106
915
|
path: wp.rel,
|
|
@@ -1112,12 +921,6 @@ export class FilesService {
|
|
|
1112
921
|
emitErr(`上传文件失败:${err.message}`, `Upload failed: ${err.message}`);
|
|
1113
922
|
}
|
|
1114
923
|
}
|
|
1115
|
-
/**
|
|
1116
|
-
* Create a folder. Accepts absolute, ~-prefixed or session-relative paths
|
|
1117
|
-
* (same expansion rules as completePath — the cwd picker may browse outside
|
|
1118
|
-
* the session root, and set_cwd itself accepts any directory). Answers
|
|
1119
|
-
* with a notice; the picker refreshes its listing on its own.
|
|
1120
|
-
*/
|
|
1121
924
|
async makeDir(input) {
|
|
1122
925
|
const rawCwd = this.host.getCwd();
|
|
1123
926
|
if (isRemoteWorkspaceUri(rawCwd) || isRemoteWorkspaceUri(input)) {
|
|
@@ -1190,10 +993,6 @@ export class FilesService {
|
|
|
1190
993
|
return null;
|
|
1191
994
|
}
|
|
1192
995
|
}
|
|
1193
|
-
/* ---- 文件树右键菜单的文件操作(`contextmenu.file`,见 protocol.ts file_*) ---- */
|
|
1194
|
-
/** 右键文件操作共用的路径解析:绝对 wire(机器浏览)直接转原生绝对路径;
|
|
1195
|
-
* 相对路径限定在工作区内(越界 → null,与 readFile/writeFile 同口径)。
|
|
1196
|
-
* 空串(工作区根须由调用方特判)与机器根 "@root" 本身不可作为操作对象 → null。 */
|
|
1197
996
|
resolveOpTarget(raw) {
|
|
1198
997
|
const wire = normWirePath(raw.trim());
|
|
1199
998
|
if (!wire || wire === MACHINE_ROOT)
|
|
@@ -1203,8 +1002,6 @@ export class FilesService {
|
|
|
1203
1002
|
const w = workspacePath(resolve(this.host.getCwd()), wire);
|
|
1204
1003
|
return w ? { abs: w.abs } : null;
|
|
1205
1004
|
}
|
|
1206
|
-
/** 文件名清洗(与 uploadFile 同口径再收紧):只取 basename,去 Windows 非法字符;
|
|
1207
|
-
* 空/纯点/尾点空格/Windows 保留名 → null(建了删不掉的东西不如直接拒绝)。 */
|
|
1208
1005
|
sanitizeName(name) {
|
|
1209
1006
|
const base = name.split(/[\\/]/).pop() ?? "";
|
|
1210
1007
|
const safe = base
|
|
@@ -1217,31 +1014,25 @@ export class FilesService {
|
|
|
1217
1014
|
return null;
|
|
1218
1015
|
return safe;
|
|
1219
1016
|
}
|
|
1220
|
-
/** wire 路径的父目录(wire 字符串层面切分,保证 file_changed 与前端 currentPath 同形)。
|
|
1221
|
-
* 工作区根 "" / 机器根 / posix 根 "/" / 盘符根 → null(这些不可重命名/删除/作复制源)。 */
|
|
1222
1017
|
wireParent(wire) {
|
|
1223
1018
|
const w = normWirePath(wire.trim());
|
|
1224
1019
|
if (!w || w === MACHINE_ROOT || w === "/" || /^[A-Za-z]:$/.test(w))
|
|
1225
1020
|
return null;
|
|
1226
1021
|
const i = w.lastIndexOf("/");
|
|
1227
1022
|
if (i < 0)
|
|
1228
|
-
return "";
|
|
1023
|
+
return "";
|
|
1229
1024
|
if (i === 0)
|
|
1230
|
-
return "/";
|
|
1025
|
+
return "/";
|
|
1231
1026
|
return w.slice(0, i);
|
|
1232
1027
|
}
|
|
1233
|
-
/** destDir(wire,空串 = 工作区根)→ 原生绝对目录;不存在/非目录 → null(调用方报错)。 */
|
|
1234
1028
|
async resolveOpDir(dir) {
|
|
1235
1029
|
const fsp = await import("node:fs/promises");
|
|
1236
1030
|
if (!dir.trim()) {
|
|
1237
1031
|
const rootAbs = resolve(this.host.getCwd());
|
|
1238
|
-
// 工作区根目录在首次运行可能尚未落地,自愈创建以确保后续操作成功
|
|
1239
1032
|
try {
|
|
1240
1033
|
await fsp.mkdir(rootAbs, { recursive: true });
|
|
1241
1034
|
}
|
|
1242
|
-
catch {
|
|
1243
|
-
/* ignore if exists */
|
|
1244
|
-
}
|
|
1035
|
+
catch { }
|
|
1245
1036
|
return { abs: rootAbs, wire: "" };
|
|
1246
1037
|
}
|
|
1247
1038
|
const t = this.resolveOpTarget(dir);
|
|
@@ -1252,7 +1043,6 @@ export class FilesService {
|
|
|
1252
1043
|
return null;
|
|
1253
1044
|
return { abs: t.abs, wire: normWirePath(dir.trim()) };
|
|
1254
1045
|
}
|
|
1255
|
-
/** 在 dir 下新建空文件或空文件夹。已存在不覆盖(报错);成功后对 dir 推 file_changed。 */
|
|
1256
1046
|
async createEntry(dir, name, kind) {
|
|
1257
1047
|
const rawCwd = this.host.getCwd();
|
|
1258
1048
|
if (isRemoteWorkspaceUri(rawCwd)) {
|
|
@@ -1294,7 +1084,6 @@ export class FilesService {
|
|
|
1294
1084
|
err(`新建失败:${e.message}`, `Create failed: ${e.message}`);
|
|
1295
1085
|
}
|
|
1296
1086
|
}
|
|
1297
|
-
/** 同目录内重命名(newName 只取 basename,不跨目录)。成功后对父目录推 file_changed。 */
|
|
1298
1087
|
async renameEntry(path, newName) {
|
|
1299
1088
|
const rawCwd = this.host.getCwd();
|
|
1300
1089
|
if (isRemoteWorkspaceUri(rawCwd)) {
|
|
@@ -1334,7 +1123,6 @@ export class FilesService {
|
|
|
1334
1123
|
err(`重命名失败:${e.message}`, `Rename failed: ${e.message}`);
|
|
1335
1124
|
}
|
|
1336
1125
|
}
|
|
1337
|
-
/** 删除文件或目录(目录递归删)。工作区根/机器根/盘符根拒绝;成功后对父目录推 file_changed。 */
|
|
1338
1126
|
async deleteEntry(path) {
|
|
1339
1127
|
const rawCwd = this.host.getCwd();
|
|
1340
1128
|
if (isRemoteWorkspaceUri(rawCwd)) {
|
|
@@ -1363,8 +1151,6 @@ export class FilesService {
|
|
|
1363
1151
|
err(`删除失败:${e.message}`, `Delete failed: ${e.message}`);
|
|
1364
1152
|
}
|
|
1365
1153
|
}
|
|
1366
|
-
/** 复制或移动(move=true 即剪切粘贴)。destDir 与源同目录即「创建副本」;
|
|
1367
|
-
* 重名自动加 " copy" 后缀;目录搬进自身/子目录拒绝;跨盘移动回落为复制+删源。 */
|
|
1368
1154
|
async copyEntry(src, destDir, move) {
|
|
1369
1155
|
const rawCwd = this.host.getCwd();
|
|
1370
1156
|
if (isRemoteWorkspaceUri(rawCwd)) {
|
|
@@ -1386,7 +1172,6 @@ export class FilesService {
|
|
|
1386
1172
|
err(`目标目录不存在:${destDir || "根目录"}`, `Target directory not found: ${destDir || "root"}`);
|
|
1387
1173
|
return;
|
|
1388
1174
|
}
|
|
1389
|
-
// 目录搬进自身或子目录 → 无限递归,必须拒绝(文件无此问题,但统一判一次)。
|
|
1390
1175
|
if (target.abs === s.abs || target.abs.startsWith(s.abs + sep)) {
|
|
1391
1176
|
err("不可复制/移动到自身或子目录", "Cannot copy/move into itself");
|
|
1392
1177
|
return;
|
|
@@ -1405,7 +1190,6 @@ export class FilesService {
|
|
|
1405
1190
|
await fsp.rename(s.abs, dest);
|
|
1406
1191
|
}
|
|
1407
1192
|
catch (e) {
|
|
1408
|
-
// 跨盘/跨挂载点 rename 报 EXDEV → 回落复制+删源(与文件管理器同行为)。
|
|
1409
1193
|
if (e.code !== "EXDEV")
|
|
1410
1194
|
throw e;
|
|
1411
1195
|
await fsp.cp(s.abs, dest, { recursive: true, force: false });
|
|
@@ -1429,7 +1213,6 @@ export class FilesService {
|
|
|
1429
1213
|
err(`${move ? "移动" : "复制"}失败:${e.message}`, `${move ? "Move" : "Copy"} failed: ${e.message}`);
|
|
1430
1214
|
}
|
|
1431
1215
|
}
|
|
1432
|
-
/** 副本目标去重:"a.txt" → "a copy.txt" → "a copy 2.txt"…(目录/无后缀同理)。 */
|
|
1433
1216
|
async dedupeCopyDest(dest) {
|
|
1434
1217
|
const fsp = await import("node:fs/promises");
|
|
1435
1218
|
const { join, dirname, basename, extname } = await import("node:path");
|
|
@@ -1446,9 +1229,6 @@ export class FilesService {
|
|
|
1446
1229
|
}
|
|
1447
1230
|
return join(dir, `${stem} copy ${Date.now()}${ext}`);
|
|
1448
1231
|
}
|
|
1449
|
-
/** 系统原生打开/定位的公共执行体(issue #187):cmd/args 已按平台组装好。
|
|
1450
|
-
* spawn 成功即算送达(explorer/open 都是 daemon 式返回,exit code 不可信);
|
|
1451
|
-
* ENOENT(headless/无桌面)等失败一律 warning notice,绝不抛。 */
|
|
1452
1232
|
async spawnDetached(cmd, args, okText, okTextEn) {
|
|
1453
1233
|
const fail = (detail) => this.host.emit({
|
|
1454
1234
|
type: "notice",
|
|
@@ -1458,9 +1238,6 @@ export class FilesService {
|
|
|
1458
1238
|
});
|
|
1459
1239
|
try {
|
|
1460
1240
|
const { spawn } = await import("node:child_process");
|
|
1461
|
-
// ⚠ 这里绝不能加 windowsHide: true:它经 STARTF_USESHOWWINDOW + SW_HIDE 压住子进程首窗口,
|
|
1462
|
-
// explorer/open 起的是 GUI(无控制台可藏),加了之后进程在、窗口永远不出来
|
|
1463
|
-
// (2026-09 实测:notepad/explorer 同参数起,进程 session 1 正常、桌面无窗口;去掉即现)。
|
|
1464
1241
|
const child = spawn(cmd, args, { detached: true, stdio: "ignore" });
|
|
1465
1242
|
if (typeof child.unref === "function")
|
|
1466
1243
|
child.unref();
|
|
@@ -1474,7 +1251,6 @@ export class FilesService {
|
|
|
1474
1251
|
};
|
|
1475
1252
|
child.on("spawn", () => settle(true));
|
|
1476
1253
|
child.on("error", () => settle(false));
|
|
1477
|
-
// 极端平台无 spawn 事件时兜底放行(进程已脱离,成败不再可知)。
|
|
1478
1254
|
setTimeout(() => settle(true), 3000);
|
|
1479
1255
|
});
|
|
1480
1256
|
if (!launched) {
|
|
@@ -1487,8 +1263,6 @@ export class FilesService {
|
|
|
1487
1263
|
fail(e.message);
|
|
1488
1264
|
}
|
|
1489
1265
|
}
|
|
1490
|
-
/** 在系统资源管理器中定位(issue #187):文件→打开目录并选中该文件,目录→直接打开。
|
|
1491
|
-
* 只读操作(不改文件),保护根/盘符根也允许;@root 本体与越界路径拒绝。 */
|
|
1492
1266
|
async revealEntry(path) {
|
|
1493
1267
|
const err = (text, textEn) => this.host.emit({ type: "notice", level: "warning", text, textEn });
|
|
1494
1268
|
try {
|
|
@@ -1510,15 +1284,12 @@ export class FilesService {
|
|
|
1510
1284
|
const segs = trimmed.split("/");
|
|
1511
1285
|
const base = !trimmed ? t.abs.split(/[\\/]/).pop() || t.abs : (segs[segs.length - 1] ?? trimmed);
|
|
1512
1286
|
if (process.platform === "win32") {
|
|
1513
|
-
// /select, 与路径分两个 argv 传(explorer 对此格式稳定支持,路径含空格也无碍)。
|
|
1514
|
-
// 目录传 /n, 强制打开新窗口,防止若该目录已在后台打开时被 Windows 静默复用且因反抢焦点机制不置顶。
|
|
1515
1287
|
await this.spawnDetached("explorer.exe", isDir ? ["/n,", abs] : ["/select,", abs], "已在资源管理器中显示:" + base, "Revealed in File Explorer: " + base);
|
|
1516
1288
|
}
|
|
1517
1289
|
else if (process.platform === "darwin") {
|
|
1518
1290
|
await this.spawnDetached("open", isDir ? [abs] : ["-R", abs], "已在访达中显示:" + base, "Revealed in Finder: " + base);
|
|
1519
1291
|
}
|
|
1520
1292
|
else {
|
|
1521
|
-
// Linux 无统一选中语义:打开其父目录(目录则打开自身)。
|
|
1522
1293
|
await this.spawnDetached("xdg-open", [isDir ? abs : dirname(abs)], "已打开所在目录:" + base, "Opened containing folder: " + base);
|
|
1523
1294
|
}
|
|
1524
1295
|
}
|
|
@@ -1526,7 +1297,6 @@ export class FilesService {
|
|
|
1526
1297
|
err("定位失败:" + e.message, "Reveal failed: " + e.message);
|
|
1527
1298
|
}
|
|
1528
1299
|
}
|
|
1529
|
-
/** 用系统默认应用打开文件(issue #187):仅文件;目录请用 reveal。 */
|
|
1530
1300
|
async openDefaultEntry(path) {
|
|
1531
1301
|
const err = (text, textEn) => this.host.emit({ type: "notice", level: "warning", text, textEn });
|
|
1532
1302
|
try {
|
|
@@ -1547,7 +1317,6 @@ export class FilesService {
|
|
|
1547
1317
|
}
|
|
1548
1318
|
const segs = path.split("/");
|
|
1549
1319
|
const base = segs[segs.length - 1] ?? path;
|
|
1550
|
-
// explorer 直接跟路径即走默认关联打开(含空格路径单 argv,无拆分问题)。
|
|
1551
1320
|
const cmd = process.platform === "win32" ? "explorer.exe" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
1552
1321
|
await this.spawnDetached(cmd, [t.abs], "已用默认应用打开:" + base, "Opened with default app: " + base);
|
|
1553
1322
|
}
|
|
@@ -1555,10 +1324,6 @@ export class FilesService {
|
|
|
1555
1324
|
err("打开失败:" + e.message, "Open failed: " + e.message);
|
|
1556
1325
|
}
|
|
1557
1326
|
}
|
|
1558
|
-
/**
|
|
1559
|
-
* Path completion for the cwd input: expand ~/relative paths, list the parent
|
|
1560
|
-
* directory, and return prefix matches (dirs first, capped).
|
|
1561
|
-
*/
|
|
1562
1327
|
async completePath(input) {
|
|
1563
1328
|
const empty = () => this.host.emit({ type: "path_completions", completions: [] });
|
|
1564
1329
|
const cwd = this.host.getCwd();
|
|
@@ -1577,12 +1342,10 @@ export class FilesService {
|
|
|
1577
1342
|
empty();
|
|
1578
1343
|
return;
|
|
1579
1344
|
}
|
|
1580
|
-
// ---- 机器根(此电脑/盘符列表)----
|
|
1581
1345
|
if (rawInput === MACHINE_ROOT || rawInput === MACHINE_ROOT + "/") {
|
|
1582
1346
|
this.host.emit({ type: "path_completions", completions: await this.machineRootEntries() });
|
|
1583
1347
|
return;
|
|
1584
1348
|
}
|
|
1585
|
-
// ---- Windows 盘符输入:"D"(补全到盘符,Tab 即换盘)/ "D:"(列盘根)----
|
|
1586
1349
|
if (isWin && /^[A-Za-z]:?$/.test(rawInput)) {
|
|
1587
1350
|
const letter = rawInput[0].toUpperCase();
|
|
1588
1351
|
const drive = `${letter}:`;
|
|
@@ -1599,7 +1362,6 @@ export class FilesService {
|
|
|
1599
1362
|
return;
|
|
1600
1363
|
}
|
|
1601
1364
|
if (rawInput.length === 2) {
|
|
1602
|
-
// 已带冒号:直接列出盘根条目。
|
|
1603
1365
|
const dirents = await fs.readdir(`${drive}\\`, { withFileTypes: true }).catch(() => null);
|
|
1604
1366
|
if (!dirents) {
|
|
1605
1367
|
empty();
|
|
@@ -1620,12 +1382,9 @@ export class FilesService {
|
|
|
1620
1382
|
this.host.emit({ type: "path_completions", completions: items });
|
|
1621
1383
|
return;
|
|
1622
1384
|
}
|
|
1623
|
-
// 只有字母:补全到盘符本身。
|
|
1624
1385
|
this.host.emit({ type: "path_completions", completions: [{ name: drive, path: drive, type: "dir" }] });
|
|
1625
1386
|
return;
|
|
1626
1387
|
}
|
|
1627
|
-
// Expand ~ and relative inputs to an absolute path. Windows users type
|
|
1628
|
-
// backslashes (P:\agent) and ~\ — handle both separator styles.
|
|
1629
1388
|
let expanded = rawInput;
|
|
1630
1389
|
if (expanded === "~" || expanded === "~\\") {
|
|
1631
1390
|
expanded = home;
|
|
@@ -1636,8 +1395,6 @@ export class FilesService {
|
|
|
1636
1395
|
else if (!isAbsolute(expanded)) {
|
|
1637
1396
|
expanded = resolve(cwd, expanded);
|
|
1638
1397
|
}
|
|
1639
|
-
// Split into parent dir + prefix on the LAST separator of either style
|
|
1640
|
-
// (Windows accepts both / and \, so P:\agent/de must work too).
|
|
1641
1398
|
const lastSlash = Math.max(expanded.lastIndexOf("/"), expanded.lastIndexOf("\\"));
|
|
1642
1399
|
const dirPart = lastSlash >= 0 ? expanded.slice(0, lastSlash + 1) : "";
|
|
1643
1400
|
const prefix = lastSlash >= 0 ? expanded.slice(lastSlash + 1) : expanded;
|
|
@@ -1652,8 +1409,6 @@ export class FilesService {
|
|
|
1652
1409
|
.map((d) => classifyDirent(d, dirPart))))
|
|
1653
1410
|
.map((e) => ({
|
|
1654
1411
|
...e,
|
|
1655
|
-
// Windows users type backslashes — normalize the completion to the
|
|
1656
|
-
// wire format ("/") so the picked path round-trips cleanly.
|
|
1657
1412
|
path: IS_WIN32 ? join(dirPart, e.name).split(sep).join("/") : dirPart + e.name,
|
|
1658
1413
|
}))
|
|
1659
1414
|
.sort((a, b) => {
|
|
@@ -1672,9 +1427,6 @@ export class FilesService {
|
|
|
1672
1427
|
empty();
|
|
1673
1428
|
}
|
|
1674
1429
|
}
|
|
1675
|
-
// =========================================================================
|
|
1676
|
-
// 远程 SSH 工作区 (ssh://...) 专属文件操作实现
|
|
1677
|
-
// =========================================================================
|
|
1678
1430
|
resolveRemoteTarget(rawCwd, p, allowRoot = false) {
|
|
1679
1431
|
const parsed = parseRemoteWorkspaceUri(rawCwd);
|
|
1680
1432
|
if (!parsed)
|
|
@@ -1820,7 +1572,6 @@ export class FilesService {
|
|
|
1820
1572
|
const q = normQuery.toLowerCase();
|
|
1821
1573
|
const results = [];
|
|
1822
1574
|
let truncated = false;
|
|
1823
|
-
// 优先精确检查直接目标
|
|
1824
1575
|
const target = this.resolveRemoteTarget(rawCwd, normQuery);
|
|
1825
1576
|
if (target) {
|
|
1826
1577
|
try {
|
|
@@ -1832,9 +1583,7 @@ export class FilesService {
|
|
|
1832
1583
|
type: st.isDirectory ? "dir" : "file",
|
|
1833
1584
|
});
|
|
1834
1585
|
}
|
|
1835
|
-
catch {
|
|
1836
|
-
/* ignore stat error */
|
|
1837
|
-
}
|
|
1586
|
+
catch { }
|
|
1838
1587
|
}
|
|
1839
1588
|
const cmd = `find . -maxdepth 8 \\( -name node_modules -o -name .git -o -name .pi-web \\) -prune -o -print 2>/dev/null | head -n 5000`;
|
|
1840
1589
|
const res = await sshSvc.execInWorkspace(rawCwd, cmd, { timeoutMs: 8000 });
|
|
@@ -1993,8 +1742,6 @@ export class FilesService {
|
|
|
1993
1742
|
});
|
|
1994
1743
|
return;
|
|
1995
1744
|
}
|
|
1996
|
-
// Preserve the existing SFTP file object (ACLs, xattrs and symlink target).
|
|
1997
|
-
// Keep the established SFTP save path rather than GNU shell replacement.
|
|
1998
1745
|
const info = await sshSvc.sftpStat(rawCwd, t.abs);
|
|
1999
1746
|
if (!info.isFile || info.size > 2 * 1024 * 1024)
|
|
2000
1747
|
throw new Error("Remote save target must be a regular file no larger than 2MB");
|