@waq666/pneuma 0.0.0-stage → 0.7.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/LICENSE +21 -0
- package/README.md +144 -2
- package/bin/dsc.js +91 -0
- package/bin/headless.cjs +40 -0
- package/lib/adapter/core-runtime.d.ts +11 -0
- package/lib/adapter/core-runtime.js +259 -0
- package/lib/adapter/host.d.ts +18 -0
- package/lib/adapter/host.js +14 -0
- package/lib/adapter/runtime.d.ts +15 -0
- package/lib/adapter/runtime.js +290 -0
- package/lib/adapter/transcript.d.ts +184 -0
- package/lib/adapter/transcript.js +605 -0
- package/lib/app/AgentsOverlay.d.ts +18 -0
- package/lib/app/AgentsOverlay.js +63 -0
- package/lib/app/App.d.ts +13 -0
- package/lib/app/App.js +1498 -0
- package/lib/app/ApprovalCard.d.ts +12 -0
- package/lib/app/ApprovalCard.js +76 -0
- package/lib/app/AskCard.d.ts +20 -0
- package/lib/app/AskCard.js +45 -0
- package/lib/app/ChatView.d.ts +32 -0
- package/lib/app/ChatView.js +198 -0
- package/lib/app/Composer.d.ts +50 -0
- package/lib/app/Composer.js +282 -0
- package/lib/app/DiffBlock.d.ts +6 -0
- package/lib/app/DiffBlock.js +37 -0
- package/lib/app/MarkdownView.d.ts +6 -0
- package/lib/app/MarkdownView.js +99 -0
- package/lib/app/ModelPicker.d.ts +7 -0
- package/lib/app/ModelPicker.js +18 -0
- package/lib/app/PlanReviewCard.d.ts +13 -0
- package/lib/app/PlanReviewCard.js +54 -0
- package/lib/app/PresetPicker.d.ts +11 -0
- package/lib/app/PresetPicker.js +19 -0
- package/lib/app/PreviewOverlay.d.ts +14 -0
- package/lib/app/PreviewOverlay.js +22 -0
- package/lib/app/SessionPicker.d.ts +43 -0
- package/lib/app/SessionPicker.js +56 -0
- package/lib/app/SettingsOverlay.d.ts +32 -0
- package/lib/app/SettingsOverlay.js +157 -0
- package/lib/app/SkillsPicker.d.ts +7 -0
- package/lib/app/SkillsPicker.js +19 -0
- package/lib/app/StatusBar.d.ts +22 -0
- package/lib/app/StatusBar.js +272 -0
- package/lib/app/TaskStrips.d.ts +13 -0
- package/lib/app/TaskStrips.js +40 -0
- package/lib/app/ToolCard.d.ts +5 -0
- package/lib/app/ToolCard.js +40 -0
- package/lib/app/TranscriptOverlay.d.ts +12 -0
- package/lib/app/TranscriptOverlay.js +17 -0
- package/lib/app/Welcome.d.ts +6 -0
- package/lib/app/Welcome.js +66 -0
- package/lib/app/attach.d.ts +16 -0
- package/lib/app/attach.js +58 -0
- package/lib/app/click.d.ts +27 -0
- package/lib/app/click.js +89 -0
- package/lib/app/clipboard-image.d.ts +11 -0
- package/lib/app/clipboard-image.js +66 -0
- package/lib/app/cursor.d.ts +4 -0
- package/lib/app/cursor.js +24 -0
- package/lib/app/hello.d.ts +11 -0
- package/lib/app/hello.js +8 -0
- package/lib/app/history-store.d.ts +4 -0
- package/lib/app/history-store.js +41 -0
- package/lib/app/image-blocks.d.ts +12 -0
- package/lib/app/image-blocks.js +125 -0
- package/lib/app/markdown.d.ts +54 -0
- package/lib/app/markdown.js +189 -0
- package/lib/app/settings-model.d.ts +69 -0
- package/lib/app/settings-model.js +114 -0
- package/lib/app/theme.d.ts +166 -0
- package/lib/app/theme.js +141 -0
- package/lib/boot.d.ts +1 -0
- package/lib/boot.js +34 -0
- package/lib/commands.d.ts +49 -0
- package/lib/commands.js +115 -0
- package/lib/contract.d.ts +1973 -0
- package/lib/contract.js +36 -0
- package/lib/core/agent-roles.d.ts +52 -0
- package/lib/core/agent-roles.js +274 -0
- package/lib/core/approval-floor.d.ts +183 -0
- package/lib/core/approval-floor.js +679 -0
- package/lib/core/approval.d.ts +42 -0
- package/lib/core/approval.js +8 -0
- package/lib/core/audit.d.ts +61 -0
- package/lib/core/audit.js +59 -0
- package/lib/core/boot-notices.d.ts +6 -0
- package/lib/core/boot-notices.js +61 -0
- package/lib/core/cdp/actions.d.ts +182 -0
- package/lib/core/cdp/actions.js +649 -0
- package/lib/core/cdp/launch.d.ts +192 -0
- package/lib/core/cdp/launch.js +491 -0
- package/lib/core/cdp/snapshot.d.ts +139 -0
- package/lib/core/cdp/snapshot.js +316 -0
- package/lib/core/cdp/transport.d.ts +160 -0
- package/lib/core/cdp/transport.js +359 -0
- package/lib/core/command-policy.d.ts +108 -0
- package/lib/core/command-policy.js +580 -0
- package/lib/core/commands-completion.d.ts +78 -0
- package/lib/core/commands-completion.js +167 -0
- package/lib/core/compact-anchors.d.ts +76 -0
- package/lib/core/compact-anchors.js +284 -0
- package/lib/core/compact.d.ts +110 -0
- package/lib/core/compact.js +210 -0
- package/lib/core/config-store.d.ts +38 -0
- package/lib/core/config-store.js +307 -0
- package/lib/core/config.d.ts +36 -0
- package/lib/core/config.js +124 -0
- package/lib/core/connection-test.d.ts +60 -0
- package/lib/core/connection-test.js +84 -0
- package/lib/core/desktop-control.d.ts +298 -0
- package/lib/core/desktop-control.js +1311 -0
- package/lib/core/diff-text.d.ts +74 -0
- package/lib/core/diff-text.js +257 -0
- package/lib/core/dock-browser.d.ts +137 -0
- package/lib/core/dock-browser.js +146 -0
- package/lib/core/dock-ops.d.ts +59 -0
- package/lib/core/dock-ops.js +104 -0
- package/lib/core/dock-session.d.ts +39 -0
- package/lib/core/dock-session.js +28 -0
- package/lib/core/dsh-compat/hook.d.ts +18 -0
- package/lib/core/dsh-compat/hook.js +52 -0
- package/lib/core/dsh-compat/resolve-hook.d.ts +5 -0
- package/lib/core/dsh-compat/resolve-hook.js +59 -0
- package/lib/core/dsh-compat/tools-facade.d.ts +47 -0
- package/lib/core/dsh-compat/tools-facade.js +108 -0
- package/lib/core/err-text.d.ts +13 -0
- package/lib/core/err-text.js +15 -0
- package/lib/core/events.d.ts +149 -0
- package/lib/core/events.js +1 -0
- package/lib/core/git-exec.d.ts +23 -0
- package/lib/core/git-exec.js +72 -0
- package/lib/core/git-info.d.ts +47 -0
- package/lib/core/git-info.js +157 -0
- package/lib/core/goal.d.ts +89 -0
- package/lib/core/goal.js +189 -0
- package/lib/core/hooks.d.ts +272 -0
- package/lib/core/hooks.js +818 -0
- package/lib/core/host-browser-link.d.ts +59 -0
- package/lib/core/host-browser-link.js +9 -0
- package/lib/core/host-methods.d.ts +25 -0
- package/lib/core/host-methods.js +103 -0
- package/lib/core/image-diet.d.ts +77 -0
- package/lib/core/image-diet.js +127 -0
- package/lib/core/learnings/ledger.d.ts +73 -0
- package/lib/core/learnings/ledger.js +273 -0
- package/lib/core/learnings/skill-write.d.ts +250 -0
- package/lib/core/learnings/skill-write.js +854 -0
- package/lib/core/learnings/store.d.ts +102 -0
- package/lib/core/learnings/store.js +266 -0
- package/lib/core/lifecycle-hooks.d.ts +189 -0
- package/lib/core/lifecycle-hooks.js +576 -0
- package/lib/core/llm.d.ts +272 -0
- package/lib/core/llm.js +548 -0
- package/lib/core/lockfile.d.ts +17 -0
- package/lib/core/lockfile.js +110 -0
- package/lib/core/loop.d.ts +185 -0
- package/lib/core/loop.js +587 -0
- package/lib/core/lsp/client.d.ts +189 -0
- package/lib/core/lsp/client.js +690 -0
- package/lib/core/lsp/framing.d.ts +84 -0
- package/lib/core/lsp/framing.js +181 -0
- package/lib/core/lsp/line-shift.d.ts +28 -0
- package/lib/core/lsp/line-shift.js +127 -0
- package/lib/core/lsp/manager.d.ts +93 -0
- package/lib/core/lsp/manager.js +418 -0
- package/lib/core/lsp/normalize.d.ts +32 -0
- package/lib/core/lsp/normalize.js +139 -0
- package/lib/core/lsp/servers.d.ts +106 -0
- package/lib/core/lsp/servers.js +352 -0
- package/lib/core/lsp/uri.d.ts +76 -0
- package/lib/core/lsp/uri.js +179 -0
- package/lib/core/market.d.ts +51 -0
- package/lib/core/market.js +358 -0
- package/lib/core/mcp.d.ts +201 -0
- package/lib/core/mcp.js +836 -0
- package/lib/core/memory-eval.d.ts +158 -0
- package/lib/core/memory-eval.js +215 -0
- package/lib/core/memory.d.ts +266 -0
- package/lib/core/memory.js +703 -0
- package/lib/core/mention.d.ts +57 -0
- package/lib/core/mention.js +129 -0
- package/lib/core/microcompact.d.ts +48 -0
- package/lib/core/microcompact.js +79 -0
- package/lib/core/migrate.d.ts +56 -0
- package/lib/core/migrate.js +134 -0
- package/lib/core/model-caps.d.ts +83 -0
- package/lib/core/model-caps.js +150 -0
- package/lib/core/model-discovery.d.ts +19 -0
- package/lib/core/model-discovery.js +69 -0
- package/lib/core/modes.d.ts +72 -0
- package/lib/core/modes.js +152 -0
- package/lib/core/native-bridge.d.ts +135 -0
- package/lib/core/native-bridge.js +563 -0
- package/lib/core/path-policy.d.ts +32 -0
- package/lib/core/path-policy.js +248 -0
- package/lib/core/permission-presets.d.ts +67 -0
- package/lib/core/permission-presets.js +75 -0
- package/lib/core/plugin-loader.d.ts +36 -0
- package/lib/core/plugin-loader.js +294 -0
- package/lib/core/plugin-registry.d.ts +113 -0
- package/lib/core/plugin-registry.js +256 -0
- package/lib/core/prefs.d.ts +82 -0
- package/lib/core/prefs.js +372 -0
- package/lib/core/presets.d.ts +80 -0
- package/lib/core/presets.js +373 -0
- package/lib/core/pricing.d.ts +90 -0
- package/lib/core/pricing.js +126 -0
- package/lib/core/prompt.d.ts +92 -0
- package/lib/core/prompt.js +339 -0
- package/lib/core/ptc.d.ts +66 -0
- package/lib/core/ptc.js +70 -0
- package/lib/core/remote/frames.d.ts +91 -0
- package/lib/core/remote/frames.js +174 -0
- package/lib/core/remote/notify.d.ts +54 -0
- package/lib/core/remote/notify.js +77 -0
- package/lib/core/remote/owner.d.ts +32 -0
- package/lib/core/remote/owner.js +75 -0
- package/lib/core/remote/pairing.d.ts +104 -0
- package/lib/core/remote/pairing.js +261 -0
- package/lib/core/remote/push.d.ts +80 -0
- package/lib/core/remote/push.js +222 -0
- package/lib/core/remote/store.d.ts +18 -0
- package/lib/core/remote/store.js +59 -0
- package/lib/core/remote/tickets.d.ts +20 -0
- package/lib/core/remote/tickets.js +49 -0
- package/lib/core/remote/uploads.d.ts +63 -0
- package/lib/core/remote/uploads.js +161 -0
- package/lib/core/request-attribution.d.ts +26 -0
- package/lib/core/request-attribution.js +86 -0
- package/lib/core/request-invariant.d.ts +61 -0
- package/lib/core/request-invariant.js +199 -0
- package/lib/core/sandbox/backends.d.ts +64 -0
- package/lib/core/sandbox/backends.js +194 -0
- package/lib/core/sandbox/execpolicy.d.ts +93 -0
- package/lib/core/sandbox/execpolicy.js +452 -0
- package/lib/core/sandbox/net-proxy.d.ts +31 -0
- package/lib/core/sandbox/net-proxy.js +162 -0
- package/lib/core/sandbox/policy.d.ts +211 -0
- package/lib/core/sandbox/policy.js +559 -0
- package/lib/core/sandbox/win/abi.d.ts +161 -0
- package/lib/core/sandbox/win/abi.js +169 -0
- package/lib/core/sandbox/win/account.d.ts +71 -0
- package/lib/core/sandbox/win/account.js +206 -0
- package/lib/core/sandbox/win/acl.d.ts +54 -0
- package/lib/core/sandbox/win/acl.js +339 -0
- package/lib/core/sandbox/win/backend.d.ts +61 -0
- package/lib/core/sandbox/win/backend.js +249 -0
- package/lib/core/sandbox/win/doctor.d.ts +24 -0
- package/lib/core/sandbox/win/doctor.js +272 -0
- package/lib/core/sandbox/win/ffi.d.ts +107 -0
- package/lib/core/sandbox/win/ffi.js +166 -0
- package/lib/core/sandbox/win/net-abi.d.ts +154 -0
- package/lib/core/sandbox/win/net-abi.js +316 -0
- package/lib/core/sandbox/win/runner-entry.d.ts +35 -0
- package/lib/core/sandbox/win/runner-entry.js +391 -0
- package/lib/core/sandbox/win/setup.d.ts +60 -0
- package/lib/core/sandbox/win/setup.js +986 -0
- package/lib/core/sandbox/win/token.d.ts +35 -0
- package/lib/core/sandbox/win/token.js +238 -0
- package/lib/core/sandbox/win/wfp.d.ts +41 -0
- package/lib/core/sandbox/win/wfp.js +200 -0
- package/lib/core/sandbox/win/workspace-sid.d.ts +9 -0
- package/lib/core/sandbox/win/workspace-sid.js +45 -0
- package/lib/core/schedule/rule.d.ts +184 -0
- package/lib/core/schedule/rule.js +745 -0
- package/lib/core/schedule/runner.d.ts +185 -0
- package/lib/core/schedule/runner.js +678 -0
- package/lib/core/schedule/store.d.ts +182 -0
- package/lib/core/schedule/store.js +455 -0
- package/lib/core/secrets.d.ts +41 -0
- package/lib/core/secrets.js +150 -0
- package/lib/core/session-export.d.ts +18 -0
- package/lib/core/session-export.js +73 -0
- package/lib/core/session-index.d.ts +159 -0
- package/lib/core/session-index.js +683 -0
- package/lib/core/session-meta.d.ts +41 -0
- package/lib/core/session-meta.js +97 -0
- package/lib/core/session.d.ts +356 -0
- package/lib/core/session.js +998 -0
- package/lib/core/skills.d.ts +60 -0
- package/lib/core/skills.js +171 -0
- package/lib/core/spill.d.ts +159 -0
- package/lib/core/spill.js +329 -0
- package/lib/core/surface-registry.d.ts +45 -0
- package/lib/core/surface-registry.js +67 -0
- package/lib/core/team-board.d.ts +95 -0
- package/lib/core/team-board.js +316 -0
- package/lib/core/throughput.d.ts +46 -0
- package/lib/core/throughput.js +40 -0
- package/lib/core/todo-reminder.d.ts +44 -0
- package/lib/core/todo-reminder.js +55 -0
- package/lib/core/todo.d.ts +81 -0
- package/lib/core/todo.js +222 -0
- package/lib/core/token-estimate.d.ts +55 -0
- package/lib/core/token-estimate.js +82 -0
- package/lib/core/tool-guards.d.ts +103 -0
- package/lib/core/tool-guards.js +77 -0
- package/lib/core/tool-search.d.ts +152 -0
- package/lib/core/tool-search.js +311 -0
- package/lib/core/tools/bash.d.ts +281 -0
- package/lib/core/tools/bash.js +871 -0
- package/lib/core/tools/command-runner.d.ts +84 -0
- package/lib/core/tools/command-runner.js +68 -0
- package/lib/core/tools/fs-tools.d.ts +23 -0
- package/lib/core/tools/fs-tools.js +247 -0
- package/lib/core/tools/index.d.ts +8 -0
- package/lib/core/tools/index.js +4 -0
- package/lib/core/tools/sandbox-args.d.ts +51 -0
- package/lib/core/tools/sandbox-args.js +90 -0
- package/lib/core/tools/search-tools.d.ts +3 -0
- package/lib/core/tools/search-tools.js +153 -0
- package/lib/core/tools.d.ts +96 -0
- package/lib/core/tools.js +53 -0
- package/lib/core/ui-boot-source.d.ts +71 -0
- package/lib/core/ui-boot-source.js +121 -0
- package/lib/core/ui-bundles.d.ts +249 -0
- package/lib/core/ui-bundles.js +830 -0
- package/lib/core/ui-combo.d.ts +49 -0
- package/lib/core/ui-combo.js +55 -0
- package/lib/core/ui-events.d.ts +81 -0
- package/lib/core/ui-events.js +364 -0
- package/lib/core/ui-hmr.d.ts +36 -0
- package/lib/core/ui-hmr.js +128 -0
- package/lib/core/ui-methods.d.ts +69 -0
- package/lib/core/ui-methods.js +341 -0
- package/lib/core/ui-route.d.ts +69 -0
- package/lib/core/ui-route.js +122 -0
- package/lib/core/ui-server.d.ts +75 -0
- package/lib/core/ui-server.js +369 -0
- package/lib/core/ui-trust.d.ts +47 -0
- package/lib/core/ui-trust.js +164 -0
- package/lib/core/untrusted.d.ts +30 -0
- package/lib/core/untrusted.js +48 -0
- package/lib/core/update-check.d.ts +81 -0
- package/lib/core/update-check.js +177 -0
- package/lib/core/usage-log.d.ts +82 -0
- package/lib/core/usage-log.js +306 -0
- package/lib/core/version.d.ts +1 -0
- package/lib/core/version.js +37 -0
- package/lib/core/web-http.d.ts +57 -0
- package/lib/core/web-http.js +137 -0
- package/lib/core/web-static.d.ts +31 -0
- package/lib/core/web-static.js +75 -0
- package/lib/headless.d.ts +1 -0
- package/lib/headless.js +31 -0
- package/lib/host/kernel.d.ts +33 -0
- package/lib/host/kernel.js +451 -0
- package/lib/index.d.ts +41 -0
- package/lib/index.js +35 -0
- package/lib/plugins/agent.d.ts +2 -0
- package/lib/plugins/agent.js +274 -0
- package/lib/plugins/approval-floor.d.ts +2 -0
- package/lib/plugins/approval-floor.js +223 -0
- package/lib/plugins/approval.d.ts +16 -0
- package/lib/plugins/approval.js +674 -0
- package/lib/plugins/ask.d.ts +2 -0
- package/lib/plugins/ask.js +245 -0
- package/lib/plugins/browser.d.ts +68 -0
- package/lib/plugins/browser.js +1341 -0
- package/lib/plugins/commands.d.ts +23 -0
- package/lib/plugins/commands.js +498 -0
- package/lib/plugins/compact.d.ts +21 -0
- package/lib/plugins/compact.js +274 -0
- package/lib/plugins/computer-use.d.ts +47 -0
- package/lib/plugins/computer-use.js +539 -0
- package/lib/plugins/desktop-dock.d.ts +2 -0
- package/lib/plugins/desktop-dock.js +626 -0
- package/lib/plugins/dock-browser.d.ts +34 -0
- package/lib/plugins/dock-browser.js +765 -0
- package/lib/plugins/dsh-compat.d.ts +25 -0
- package/lib/plugins/dsh-compat.js +37 -0
- package/lib/plugins/file-review.d.ts +108 -0
- package/lib/plugins/file-review.js +393 -0
- package/lib/plugins/git.d.ts +26 -0
- package/lib/plugins/git.js +132 -0
- package/lib/plugins/goal.d.ts +20 -0
- package/lib/plugins/goal.js +245 -0
- package/lib/plugins/guards.d.ts +14 -0
- package/lib/plugins/guards.js +18 -0
- package/lib/plugins/hooks.d.ts +19 -0
- package/lib/plugins/hooks.js +583 -0
- package/lib/plugins/host-stdio.d.ts +88 -0
- package/lib/plugins/host-stdio.js +317 -0
- package/lib/plugins/image-diet.d.ts +17 -0
- package/lib/plugins/image-diet.js +85 -0
- package/lib/plugins/lifecycle-hooks.d.ts +26 -0
- package/lib/plugins/lifecycle-hooks.js +338 -0
- package/lib/plugins/llm.d.ts +13 -0
- package/lib/plugins/llm.js +215 -0
- package/lib/plugins/lsp.d.ts +54 -0
- package/lib/plugins/lsp.js +608 -0
- package/lib/plugins/mcp.d.ts +16 -0
- package/lib/plugins/mcp.js +673 -0
- package/lib/plugins/memory.d.ts +17 -0
- package/lib/plugins/memory.js +858 -0
- package/lib/plugins/microcompact.d.ts +18 -0
- package/lib/plugins/microcompact.js +119 -0
- package/lib/plugins/mode.d.ts +18 -0
- package/lib/plugins/mode.js +115 -0
- package/lib/plugins/permission-presets.d.ts +18 -0
- package/lib/plugins/permission-presets.js +135 -0
- package/lib/plugins/plan.d.ts +2 -0
- package/lib/plugins/plan.js +192 -0
- package/lib/plugins/plugin-manager.d.ts +2 -0
- package/lib/plugins/plugin-manager.js +165 -0
- package/lib/plugins/presets.d.ts +2 -0
- package/lib/plugins/presets.js +182 -0
- package/lib/plugins/prompt.d.ts +2 -0
- package/lib/plugins/prompt.js +264 -0
- package/lib/plugins/ptc.d.ts +2 -0
- package/lib/plugins/ptc.js +272 -0
- package/lib/plugins/remote/http.d.ts +11 -0
- package/lib/plugins/remote/http.js +11 -0
- package/lib/plugins/remote/routes.d.ts +24 -0
- package/lib/plugins/remote/routes.js +384 -0
- package/lib/plugins/remote/types.d.ts +135 -0
- package/lib/plugins/remote/types.js +87 -0
- package/lib/plugins/remote.d.ts +17 -0
- package/lib/plugins/remote.js +1028 -0
- package/lib/plugins/runtime-api.d.ts +16 -0
- package/lib/plugins/runtime-api.js +99 -0
- package/lib/plugins/runtime.d.ts +10 -0
- package/lib/plugins/runtime.js +451 -0
- package/lib/plugins/sandbox.d.ts +2 -0
- package/lib/plugins/sandbox.js +761 -0
- package/lib/plugins/schedule.d.ts +26 -0
- package/lib/plugins/schedule.js +538 -0
- package/lib/plugins/self-improve.d.ts +61 -0
- package/lib/plugins/self-improve.js +953 -0
- package/lib/plugins/session-search.d.ts +16 -0
- package/lib/plugins/session-search.js +308 -0
- package/lib/plugins/session-title.d.ts +19 -0
- package/lib/plugins/session-title.js +109 -0
- package/lib/plugins/session.d.ts +7 -0
- package/lib/plugins/session.js +296 -0
- package/lib/plugins/settings.d.ts +3 -0
- package/lib/plugins/settings.js +705 -0
- package/lib/plugins/skills.d.ts +2 -0
- package/lib/plugins/skills.js +360 -0
- package/lib/plugins/spill.d.ts +16 -0
- package/lib/plugins/spill.js +200 -0
- package/lib/plugins/subagent.d.ts +2 -0
- package/lib/plugins/subagent.js +862 -0
- package/lib/plugins/surfaces.d.ts +11 -0
- package/lib/plugins/surfaces.js +20 -0
- package/lib/plugins/team.d.ts +16 -0
- package/lib/plugins/team.js +149 -0
- package/lib/plugins/todo.d.ts +19 -0
- package/lib/plugins/todo.js +188 -0
- package/lib/plugins/tool-search.d.ts +2 -0
- package/lib/plugins/tool-search.js +425 -0
- package/lib/plugins/tools-default.d.ts +12 -0
- package/lib/plugins/tools-default.js +275 -0
- package/lib/plugins/tools.d.ts +16 -0
- package/lib/plugins/tools.js +62 -0
- package/lib/plugins/transcript.d.ts +15 -0
- package/lib/plugins/transcript.js +311 -0
- package/lib/plugins/tui.d.ts +2 -0
- package/lib/plugins/tui.js +98 -0
- package/lib/plugins/waiting.d.ts +12 -0
- package/lib/plugins/waiting.js +34 -0
- package/lib/plugins/web-search.d.ts +14 -0
- package/lib/plugins/web-search.js +263 -0
- package/lib/plugins/webserver.d.ts +48 -0
- package/lib/plugins/webserver.js +228 -0
- package/lib/remote/assets/app-DAcUCOEn.js +14 -0
- package/lib/remote/assets/icon-192.png +0 -0
- package/lib/remote/assets/icon-512.png +0 -0
- package/lib/remote/assets/index.html +34 -0
- package/lib/remote/assets/manifest.json +27 -0
- package/lib/remote/assets/style-DIB6729x.css +1 -0
- package/lib/remote/assets/sw.js +66 -0
- package/lib/services/types.d.ts +1228 -0
- package/lib/services/types.js +1 -0
- package/lib/tools/config-cli.d.ts +1 -0
- package/lib/tools/config-cli.js +89 -0
- package/lib/ui/arrival.d.ts +72 -0
- package/lib/ui/arrival.js +105 -0
- package/lib/ui/assets/app-B70nVIKd.js +69 -0
- package/lib/ui/assets/chunk-2UxHyX5q.js +1 -0
- package/lib/ui/assets/chunk-B1dDrJ26.js +1 -0
- package/lib/ui/assets/chunk-B6aJPvgy.js +1 -0
- package/lib/ui/assets/chunk-BEwlwnbL.js +1 -0
- package/lib/ui/assets/chunk-BGcgwlCI.js +12 -0
- package/lib/ui/assets/chunk-BIGW1oBm.js +1 -0
- package/lib/ui/assets/chunk-BPQ3VLAy.js +1 -0
- package/lib/ui/assets/chunk-BRH0KZbk.js +141 -0
- package/lib/ui/assets/chunk-BX6H_ySx.js +1 -0
- package/lib/ui/assets/chunk-B_P3UbPa.js +1 -0
- package/lib/ui/assets/chunk-B_TYUkTI.js +1 -0
- package/lib/ui/assets/chunk-B_vNuMnf.js +1 -0
- package/lib/ui/assets/chunk-BajyYBss.js +10 -0
- package/lib/ui/assets/chunk-BdnUsdx6.js +1 -0
- package/lib/ui/assets/chunk-Buea-lGh.js +1 -0
- package/lib/ui/assets/chunk-C0PvZCCE.js +1 -0
- package/lib/ui/assets/chunk-C0m74zRD.js +1 -0
- package/lib/ui/assets/chunk-C27-OAKa.js +1 -0
- package/lib/ui/assets/chunk-C2oV4EkX.js +1 -0
- package/lib/ui/assets/chunk-C7zT0LnQ.js +1 -0
- package/lib/ui/assets/chunk-C9GSunVT.js +1 -0
- package/lib/ui/assets/chunk-C9tS-k6U.js +1 -0
- package/lib/ui/assets/chunk-CHLpvVh8.js +1 -0
- package/lib/ui/assets/chunk-CLxacb5B.js +1 -0
- package/lib/ui/assets/chunk-COt5Ahok.js +1 -0
- package/lib/ui/assets/chunk-CPTIWCL2.js +1 -0
- package/lib/ui/assets/chunk-CQLl-L-p.js +1 -0
- package/lib/ui/assets/chunk-CUWRgxuq.js +55 -0
- package/lib/ui/assets/chunk-CWanVSXC.js +1 -0
- package/lib/ui/assets/chunk-Cf5RLm7j.js +1 -0
- package/lib/ui/assets/chunk-CickPsom.js +1 -0
- package/lib/ui/assets/chunk-Cj5Yp3dK.js +1 -0
- package/lib/ui/assets/chunk-Cmh6b_Ma.js +1 -0
- package/lib/ui/assets/chunk-Cp-IABpG.js +1 -0
- package/lib/ui/assets/chunk-CqE71os6.js +1 -0
- package/lib/ui/assets/chunk-CtKP3W-j.js +1 -0
- package/lib/ui/assets/chunk-Cvjx9yec.js +1 -0
- package/lib/ui/assets/chunk-CxGP3dtY.js +1 -0
- package/lib/ui/assets/chunk-CylS5w8V.js +1 -0
- package/lib/ui/assets/chunk-D38fbIBN.js +1 -0
- package/lib/ui/assets/chunk-D97Zzqfu.js +1 -0
- package/lib/ui/assets/chunk-DAi9KRSo.js +1 -0
- package/lib/ui/assets/chunk-DHK4yRfg.js +1 -0
- package/lib/ui/assets/chunk-DJeabLx-.js +1 -0
- package/lib/ui/assets/chunk-DNRxmY5a.js +1 -0
- package/lib/ui/assets/chunk-DNSN1z5r.js +1 -0
- package/lib/ui/assets/chunk-DNasK_ZG.js +1 -0
- package/lib/ui/assets/chunk-DPvrY3IQ.js +1 -0
- package/lib/ui/assets/chunk-DXmwc3jG.js +1 -0
- package/lib/ui/assets/chunk-Dd0kTxKP.js +1 -0
- package/lib/ui/assets/chunk-De0Btta0.js +1 -0
- package/lib/ui/assets/chunk-Des-eS-w.js +1 -0
- package/lib/ui/assets/chunk-Df6bDoY_.js +1 -0
- package/lib/ui/assets/chunk-DijEV5ha.js +1 -0
- package/lib/ui/assets/chunk-DkvoVjww.js +1 -0
- package/lib/ui/assets/chunk-DlC-OlHO.js +1 -0
- package/lib/ui/assets/chunk-DnzrXTVv.js +1 -0
- package/lib/ui/assets/chunk-Dualf0xi.js +1 -0
- package/lib/ui/assets/chunk-EXT84bkm.js +1 -0
- package/lib/ui/assets/chunk-GwR3hkPK.js +1 -0
- package/lib/ui/assets/chunk-P80f7IUj.js +1 -0
- package/lib/ui/assets/chunk-VOosw3JB.js +1 -0
- package/lib/ui/assets/chunk-YQ4lDkt_.js +140 -0
- package/lib/ui/assets/chunk-Yzrsuije.js +1 -0
- package/lib/ui/assets/chunk-Z72CF80r.js +1 -0
- package/lib/ui/assets/chunk-g9-lgVsj.js +1 -0
- package/lib/ui/assets/chunk-vGWfd6FD.js +1 -0
- package/lib/ui/assets/chunk-wDzz0qaB.js +1 -0
- package/lib/ui/assets/chunk-ySF7HWmS.js +1 -0
- package/lib/ui/assets/icon.png +0 -0
- package/lib/ui/assets/index.html +14 -0
- package/lib/ui/assets/pdf.worker.min-CjEcRF4W.mjs +28 -0
- package/lib/ui/assets/style-Bq01xH_b.css +1 -0
- package/lib/ui/frames.d.ts +67 -0
- package/lib/ui/frames.js +146 -0
- package/lib/ui/index.d.ts +59 -0
- package/lib/ui/index.js +50 -0
- package/lib/ui/manifest.d.ts +172 -0
- package/lib/ui/manifest.js +158 -0
- package/lib/ui/plugin.d.ts +161 -0
- package/lib/ui/plugin.js +7 -0
- package/lib/ui/plugins/browser/client.js +290 -0
- package/lib/ui/plugins/browser/icon.png +0 -0
- package/lib/ui/plugins/composer/client.js +1843 -0
- package/lib/ui/plugins/composer/icon.png +0 -0
- package/lib/ui/plugins/files/client.js +646 -0
- package/lib/ui/plugins/files/icon.png +0 -0
- package/lib/ui/plugins/manifest.json +107 -0
- package/lib/ui/plugins/plugins/client.js +682 -0
- package/lib/ui/plugins/plugins/icon.png +0 -0
- package/lib/ui/plugins/preview/client.js +197 -0
- package/lib/ui/plugins/preview/icon.png +0 -0
- package/lib/ui/plugins/prompt/client.js +653 -0
- package/lib/ui/plugins/prompt/icon.png +0 -0
- package/lib/ui/plugins/sessions/client.js +1577 -0
- package/lib/ui/plugins/sessions/icon.png +0 -0
- package/lib/ui/plugins/settings/client.js +5470 -0
- package/lib/ui/plugins/settings/icon.png +0 -0
- package/lib/ui/plugins/skills/client.js +485 -0
- package/lib/ui/plugins/skills/icon.png +0 -0
- package/lib/ui/plugins/status/client.js +1420 -0
- package/lib/ui/plugins/status/icon.png +0 -0
- package/lib/ui/plugins/statusbar/client.js +504 -0
- package/lib/ui/plugins/statusbar/icon.png +0 -0
- package/lib/ui/plugins/tasks/client.js +52 -0
- package/lib/ui/plugins/tasks/icon.png +0 -0
- package/lib/ui/plugins/team/client.js +527 -0
- package/lib/ui/plugins/team/icon.png +0 -0
- package/lib/ui/plugins/terminal/client.js +232 -0
- package/lib/ui/plugins/terminal/icon.png +0 -0
- package/lib/ui/plugins/trace/client.js +1376 -0
- package/lib/ui/plugins/trace/icon.png +0 -0
- package/lib/ui/plugins/transcript/client.js +2661 -0
- package/lib/ui/plugins/transcript/icon.png +0 -0
- package/lib/ui/scoped-slots.d.ts +20 -0
- package/lib/ui/scoped-slots.js +21 -0
- package/lib/ui/sdk/@dsc/ui/index.d.ts +242 -0
- package/lib/ui/sdk/@dsc/ui/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-core/contract.d.ts +1973 -0
- package/lib/ui/sdk/@dsc/ui-core/core/diff-text.d.ts +74 -0
- package/lib/ui/sdk/@dsc/ui-core/core/dock-browser.d.ts +137 -0
- package/lib/ui/sdk/@dsc/ui-core/core/dock-ops.d.ts +59 -0
- package/lib/ui/sdk/@dsc/ui-core/core/model-caps.d.ts +83 -0
- package/lib/ui/sdk/@dsc/ui-core/core/native-bridge.d.ts +135 -0
- package/lib/ui/sdk/@dsc/ui-core/core/token-estimate.d.ts +55 -0
- package/lib/ui/sdk/@dsc/ui-core/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/arrival.d.ts +72 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/frames.d.ts +67 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/index.d.ts +59 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/manifest.d.ts +172 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/plugin.d.ts +161 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/scoped-slots.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/services-react.d.ts +27 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/services.d.ts +63 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/slots-react.d.ts +28 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/slots.d.ts +481 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/store.d.ts +89 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-model.d.ts +238 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-state.d.ts +163 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/index.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-layout/app.d.ts +74 -0
- package/lib/ui/sdk/@dsc/ui-layout/appearance.d.ts +70 -0
- package/lib/ui/sdk/@dsc/ui-layout/host-channel.d.ts +112 -0
- package/lib/ui/sdk/@dsc/ui-layout/index.d.ts +34 -0
- package/lib/ui/sdk/@dsc/ui-layout/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-layout/page-state.d.ts +14 -0
- package/lib/ui/sdk/@dsc/ui-layout/review-pane.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-layout/runtime-context.d.ts +44 -0
- package/lib/ui/sdk/@dsc/ui-layout/thread-view.d.ts +28 -0
- package/lib/ui/sdk/@dsc/ui-layout/update-button.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-primitives/code-file-icon-artwork.d.ts +53 -0
- package/lib/ui/sdk/@dsc/ui-primitives/code-view.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-primitives/compat.d.ts +27 -0
- package/lib/ui/sdk/@dsc/ui-primitives/completion-sound.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-primitives/confirm.d.ts +33 -0
- package/lib/ui/sdk/@dsc/ui-primitives/css.d.ts +47 -0
- package/lib/ui/sdk/@dsc/ui-primitives/diff-rows.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-icons.d.ts +38 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-type-classify.d.ts +66 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-type-icon.d.ts +57 -0
- package/lib/ui/sdk/@dsc/ui-primitives/highlight.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-primitives/hover-delay.d.ts +17 -0
- package/lib/ui/sdk/@dsc/ui-primitives/icons.d.ts +109 -0
- package/lib/ui/sdk/@dsc/ui-primitives/index.d.ts +55 -0
- package/lib/ui/sdk/@dsc/ui-primitives/lang-table.d.ts +10 -0
- package/lib/ui/sdk/@dsc/ui-primitives/markdown.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-primitives/native.d.ts +41 -0
- package/lib/ui/sdk/@dsc/ui-primitives/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-primitives/panels.d.ts +86 -0
- package/lib/ui/sdk/@dsc/ui-primitives/paths.d.ts +11 -0
- package/lib/ui/sdk/@dsc/ui-primitives/pdf-view.d.ts +13 -0
- package/lib/ui/sdk/@dsc/ui-primitives/plugin-text.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-primitives/select.d.ts +35 -0
- package/lib/ui/sdk/@dsc/ui-primitives/table-view.d.ts +23 -0
- package/lib/ui/sdk/@dsc/ui-primitives/thread-resizer.d.ts +22 -0
- package/lib/ui/sdk/@dsc/ui-primitives/time.d.ts +33 -0
- package/lib/ui/sdk/@dsc/ui-primitives/toast.d.ts +16 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tokens.d.ts +14 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tool-args.d.ts +49 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tool-summary.d.ts +64 -0
- package/lib/ui/sdk/@dsc/ui-renderer/boot.d.ts +121 -0
- package/lib/ui/sdk/@dsc/ui-renderer/hmr.d.ts +43 -0
- package/lib/ui/sdk/@dsc/ui-renderer/index.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-renderer/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-slots/index.d.ts +19 -0
- package/lib/ui/sdk/@dsc/ui-slots/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-slots/slots-react.d.ts +48 -0
- package/lib/ui/sdk/@dsc/ui-slots/slots.d.ts +102 -0
- package/lib/ui/services-react.d.ts +27 -0
- package/lib/ui/services-react.js +32 -0
- package/lib/ui/services.d.ts +63 -0
- package/lib/ui/services.js +121 -0
- package/lib/ui/slots-ink.d.ts +26 -0
- package/lib/ui/slots-ink.js +78 -0
- package/lib/ui/slots-react.d.ts +28 -0
- package/lib/ui/slots-react.js +88 -0
- package/lib/ui/slots.d.ts +481 -0
- package/lib/ui/slots.js +550 -0
- package/lib/ui/store.d.ts +89 -0
- package/lib/ui/store.js +62 -0
- package/lib/ui/tui-plugin-api.d.ts +23 -0
- package/lib/ui/tui-plugin-api.js +23 -0
- package/lib/ui/tui-plugins.d.ts +47 -0
- package/lib/ui/tui-plugins.js +220 -0
- package/package.json +58 -6
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* desktop-dock 插件:为桌面端 dock 面板提供工作区文件系统与 git 能力
|
|
3
|
+
* (renderer 经 DscRuntime.dock(op, payload) 透传调用)。
|
|
4
|
+
*
|
|
5
|
+
* 安全边界:路径限定在**当前会话的工作目录**内(fs-read 文本 ≤512KB、图片 ≤5MB、
|
|
6
|
+
* PDF/XLSX 整读 ≤10MB、二进制扩展名不读内容);git 全部 execFile 固定子命令 +
|
|
7
|
+
* safeArg 参数净化(拒绝选项注入),无 shell。
|
|
8
|
+
*
|
|
9
|
+
* 三档(2026-10-10,见 `core/dock-ops.ts` 的对照表):读类直接放行;**写类先过审批**
|
|
10
|
+
* (与工具调用同一套裁决,权限模式对它同样成立);终端那档**不进界面 HTTP 面**,
|
|
11
|
+
* 只从桌面窗口的原生桥进来。这里承担写类的闸门;终端那档由传输侧保证。
|
|
12
|
+
*
|
|
13
|
+
* @module dsc/plugins/desktop-dock
|
|
14
|
+
*/
|
|
15
|
+
import { spawn } from 'node:child_process';
|
|
16
|
+
import { readFileSync, readdirSync, statSync } from 'node:fs';
|
|
17
|
+
import { isAbsolute, join, relative, resolve } from 'node:path';
|
|
18
|
+
import { DOCK_WRITE_LABEL, isDockWriteOp } from '../core/dock-ops.js';
|
|
19
|
+
// 执行姿势与 porcelains 解析住在 core:git 插件(分支/改动读数那条快照面)读的是同一个
|
|
20
|
+
// 工作区,两处必须共用一份(尤其是 `-z` 的 rename 双记录),见 core/git-exec.ts。
|
|
21
|
+
import { git, parsePorcelainZ, repoPrefix, toWorkspacePath } from '../core/git-exec.js';
|
|
22
|
+
/** 参数净化:拒绝空字节/换行与选项注入位。 */
|
|
23
|
+
function safeArg(value, allowNewline = false) {
|
|
24
|
+
const text = String(value ?? '');
|
|
25
|
+
if (text.includes('\0'))
|
|
26
|
+
throw new Error('非法参数');
|
|
27
|
+
if (!allowNewline && text.includes('\n'))
|
|
28
|
+
throw new Error('非法参数:含换行');
|
|
29
|
+
if (text.startsWith('-'))
|
|
30
|
+
throw new Error('非法参数:以 - 开头');
|
|
31
|
+
return text;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* HEAD 是否已经出生(仓库里至少有一次提交)。
|
|
35
|
+
*
|
|
36
|
+
* 空仓库(`git init` 之后一次没提交)与 HEAD 指向不存在引用的坏仓库,`git diff HEAD`
|
|
37
|
+
* 都会直接报 `fatal: ambiguous argument 'HEAD'`——这个原始报错 2026-10-13 被用户当
|
|
38
|
+
* 面板故障报了上来。凡是要「相对 HEAD」的读取都先问这一句,问不到就换无 HEAD 的走法。
|
|
39
|
+
*/
|
|
40
|
+
async function hasHead(cwd) {
|
|
41
|
+
try {
|
|
42
|
+
await git(cwd, ['rev-parse', '--verify', '--quiet', 'HEAD']);
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** `--numstat -z` 的输出解析:`add\trem\tpath\0`;rename 是 `add\trem\t\0old\0new\0`(取新路径)。 */
|
|
50
|
+
function parseNumstatZ(text) {
|
|
51
|
+
const stats = new Map();
|
|
52
|
+
const records = text.split('\0');
|
|
53
|
+
for (let at = 0; at < records.length; at += 1) {
|
|
54
|
+
const record = records[at] ?? '';
|
|
55
|
+
if (record === '')
|
|
56
|
+
continue;
|
|
57
|
+
const fields = record.split('\t');
|
|
58
|
+
if (fields.length < 3)
|
|
59
|
+
continue;
|
|
60
|
+
// 二进制文件 numstat 给 `-\t-\tpath`:parseInt 得 NaN,按 0 计(与参考实现同口径)。
|
|
61
|
+
const addedRaw = Number.parseInt(fields[0] ?? '', 10);
|
|
62
|
+
const removedRaw = Number.parseInt(fields[1] ?? '', 10);
|
|
63
|
+
const added = Number.isFinite(addedRaw) ? addedRaw : 0;
|
|
64
|
+
const removed = Number.isFinite(removedRaw) ? removedRaw : 0;
|
|
65
|
+
const path = fields.slice(2).join('\t');
|
|
66
|
+
if (path !== '') {
|
|
67
|
+
stats.set(path, { added, removed });
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
// rename:紧跟两条路径记录(旧、新),取新路径
|
|
71
|
+
const renamed = records[at + 2] ?? '';
|
|
72
|
+
at += 2;
|
|
73
|
+
if (renamed !== '')
|
|
74
|
+
stats.set(renamed, { added, removed });
|
|
75
|
+
}
|
|
76
|
+
return stats;
|
|
77
|
+
}
|
|
78
|
+
/** 把一份 numstat -z 读数按工作目录范围过滤并剥前缀,得到「cwd 相对路径 → 增删行数」。 */
|
|
79
|
+
function workspaceNumstat(prefix, text) {
|
|
80
|
+
const out = {};
|
|
81
|
+
for (const [repoPath, stat] of parseNumstatZ(text)) {
|
|
82
|
+
const path = toWorkspacePath(repoPath, prefix);
|
|
83
|
+
if (path === null)
|
|
84
|
+
continue;
|
|
85
|
+
out[path] = stat;
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
/** 未跟踪条目的路径清单(含被折叠的目录条目,如 `deepseek-harness/`),已 rebase 到 cwd 相对。 */
|
|
90
|
+
async function untrackedPaths(cwd) {
|
|
91
|
+
const prefix = await repoPrefix(cwd);
|
|
92
|
+
const porcelain = await git(cwd, ['status', '--porcelain=v1', '-z']);
|
|
93
|
+
return parsePorcelainZ(porcelain)
|
|
94
|
+
.filter((entry) => entry.code === '??')
|
|
95
|
+
.map((entry) => toWorkspacePath(entry.file, prefix))
|
|
96
|
+
.filter((path) => path !== null);
|
|
97
|
+
}
|
|
98
|
+
/** 合成预览的上限:单文件 512KB(与 fs-read 文本同口径)。 */
|
|
99
|
+
const UNTRACKED_PREVIEW_MAX_BYTES = 512 * 1024;
|
|
100
|
+
/** 「全部改动」里合成未跟踪段的护栏:最多 40 个文件 / 合计 2MB(防一次点开撑爆 payload)。 */
|
|
101
|
+
const UNTRACKED_PREVIEW_MAX_FILES = 40;
|
|
102
|
+
const UNTRACKED_PREVIEW_MAX_TOTAL_BYTES = 2 * 1024 * 1024;
|
|
103
|
+
/** 未跟踪行数统计的单文件上限:超过就不数(口径与参考实现一致:1 MiB)。 */
|
|
104
|
+
const GIT_UNTRACKED_STAT_MAX_BYTES = 1024 * 1024;
|
|
105
|
+
/** 未跟踪行数统计的并发宽度(一次别把一堆小文件全读进内存)。 */
|
|
106
|
+
const GIT_UNTRACKED_STAT_CONCURRENCY = 4;
|
|
107
|
+
function readUntracked(cwd, file, maxBytes) {
|
|
108
|
+
const abs = resolve(cwd, file);
|
|
109
|
+
if (!inside(abs, cwd))
|
|
110
|
+
return { kind: 'outside' };
|
|
111
|
+
let stat;
|
|
112
|
+
try {
|
|
113
|
+
stat = statSync(abs);
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return { kind: 'missing' };
|
|
117
|
+
}
|
|
118
|
+
if (!stat.isFile())
|
|
119
|
+
return { kind: 'dir' };
|
|
120
|
+
if (stat.size > maxBytes)
|
|
121
|
+
return { kind: 'tooLarge', bytes: stat.size };
|
|
122
|
+
const bytes = readFileSync(abs);
|
|
123
|
+
if (bytes.includes(0))
|
|
124
|
+
return { kind: 'binary' };
|
|
125
|
+
// CRLF 归一:diff 行按 LF 切,行尾的 \r 留着会在行里显示成方块。
|
|
126
|
+
return { kind: 'text', text: bytes.toString('utf8').replace(/\r\n/g, '\n') };
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 按内容给未跟踪文件合成一段 unified diff。
|
|
130
|
+
*
|
|
131
|
+
* 为什么不用 `git diff --no-index`:Windows 上它会带平台相关的头,壳的解析对它并不
|
|
132
|
+
* 宽容(参考实现在这里同样退回最小形态)。自己拼的形态最稳,只需要
|
|
133
|
+
* `diff --git` / `--- /dev/null` / `+++ b/<路径>` / 全 `+` 行这几样。
|
|
134
|
+
* 读不成文本的(二进制、过大、目录条目、已消失)给一句说明,不假装「没有改动」。
|
|
135
|
+
*/
|
|
136
|
+
function untrackedPreview(cwd, file) {
|
|
137
|
+
const read = readUntracked(cwd, file, UNTRACKED_PREVIEW_MAX_BYTES);
|
|
138
|
+
if (read.kind === 'outside')
|
|
139
|
+
return { patch: '', note: `${file}:路径超出工作目录。` };
|
|
140
|
+
if (read.kind === 'missing')
|
|
141
|
+
return { patch: '', note: `${file}:读不到这个条目(未跟踪目录里的整体条目或文件已不在了)。` };
|
|
142
|
+
if (read.kind === 'dir')
|
|
143
|
+
return { patch: '', note: `${file}:未跟踪目录整条收录,展开看里面请用文件页签。` };
|
|
144
|
+
if (read.kind === 'tooLarge') {
|
|
145
|
+
return { patch: '', note: `${file}:${Math.round(read.bytes / 1024)}KB,超过 ${String(UNTRACKED_PREVIEW_MAX_BYTES / 1024)}KB 不合成预览。` };
|
|
146
|
+
}
|
|
147
|
+
if (read.kind === 'binary')
|
|
148
|
+
return { patch: '', note: `${file}:二进制文件,没有可预览的文本差异。` };
|
|
149
|
+
const text = read.text;
|
|
150
|
+
if (text === '')
|
|
151
|
+
return { patch: '', note: `${file}:空文件,没有内容可看。` };
|
|
152
|
+
const hasTrailingNewline = text.endsWith('\n');
|
|
153
|
+
const lines = text.split('\n');
|
|
154
|
+
if (hasTrailingNewline)
|
|
155
|
+
lines.pop();
|
|
156
|
+
const head = [`diff --git a/${file} b/${file}`, 'new file mode 100644', '--- /dev/null', `+++ b/${file}`];
|
|
157
|
+
const body = lines.length === 0
|
|
158
|
+
? []
|
|
159
|
+
: [`@@ -0,0 +1,${lines.length} @@`, ...lines.map((line) => `+${line}`), ...(hasTrailingNewline ? [] : ['\'])];
|
|
160
|
+
return { patch: `${[...head, ...body].join('\n')}\n`, note: '' };
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 未跟踪文件的行数(口径照参考实现:≤{@link GIT_UNTRACKED_STAT_MAX_BYTES} 才数、
|
|
164
|
+
* 含 NUL 即二进制记 0、读不到 / 目录 / 过大一律 0;未跟踪只有新增,`removed` 恒 0)。
|
|
165
|
+
* 数换行符而不是走 `diff --numstat`——未跟踪文件根本不在 diff 里。
|
|
166
|
+
*/
|
|
167
|
+
function countUntrackedLines(cwd, file) {
|
|
168
|
+
const read = readUntracked(cwd, file, GIT_UNTRACKED_STAT_MAX_BYTES);
|
|
169
|
+
if (read.kind !== 'text' || read.text === '')
|
|
170
|
+
return 0;
|
|
171
|
+
const newlines = read.text.split('\n').length - 1;
|
|
172
|
+
return read.text.endsWith('\n') ? newlines : newlines + 1;
|
|
173
|
+
}
|
|
174
|
+
/** 并发给多个未跟踪条目数行数(宽度 {@link GIT_UNTRACKED_STAT_CONCURRENCY})。 */
|
|
175
|
+
async function untrackedLineStats(cwd, paths) {
|
|
176
|
+
const stats = new Map();
|
|
177
|
+
let next = 0;
|
|
178
|
+
const worker = async () => {
|
|
179
|
+
while (next < paths.length) {
|
|
180
|
+
const path = paths[next];
|
|
181
|
+
next += 1;
|
|
182
|
+
if (path === undefined)
|
|
183
|
+
continue;
|
|
184
|
+
stats.set(path, countUntrackedLines(cwd, path));
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
const width = Math.max(1, Math.min(GIT_UNTRACKED_STAT_CONCURRENCY, paths.length));
|
|
188
|
+
await Promise.all(Array.from({ length: width }, () => worker()));
|
|
189
|
+
return stats;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* tracked 改动的 diff 文本:HEAD 在就一段 `diff HEAD`(已暂存 + 未暂存合并在一份里),
|
|
193
|
+
* HEAD 没出生就改成未暂存 + 已暂存两段拼——这是唯一能在空仓库里出 diff 的走法。
|
|
194
|
+
*
|
|
195
|
+
* `staged` 为真时只取已暂存段(index vs HEAD);`file` 为空时 pathspec 用 `.`,把范围
|
|
196
|
+
* 限定在**工作目录子树**内——git 从子目录跑 `diff HEAD` 默认会带上仓库根那侧别的目录的
|
|
197
|
+
* 改动,而「只列 cwd 之内的变更」这条在 diff 这一层同样要成立。
|
|
198
|
+
*/
|
|
199
|
+
async function trackedDiff(cwd, guard, file, staged = false) {
|
|
200
|
+
const tail = ['--', file ?? '.'];
|
|
201
|
+
if (staged)
|
|
202
|
+
return git(cwd, ['diff', '--cached', ...guard, ...tail]).catch(() => '');
|
|
203
|
+
if (await hasHead(cwd))
|
|
204
|
+
return git(cwd, ['diff', 'HEAD', ...guard, ...tail]);
|
|
205
|
+
const parts = await Promise.all([
|
|
206
|
+
git(cwd, ['diff', ...guard, ...tail]).catch(() => ''),
|
|
207
|
+
git(cwd, ['diff', '--cached', ...guard, ...tail]).catch(() => ''),
|
|
208
|
+
]);
|
|
209
|
+
return parts.filter((part) => part !== '').join('\n');
|
|
210
|
+
}
|
|
211
|
+
/** 文件面板可直接预览的图片扩展名 → MIME(fs-read 按 kind:'image' 回 base64)。 */
|
|
212
|
+
const IMAGE_MIME = {
|
|
213
|
+
png: 'image/png',
|
|
214
|
+
jpg: 'image/jpeg',
|
|
215
|
+
jpeg: 'image/jpeg',
|
|
216
|
+
gif: 'image/gif',
|
|
217
|
+
webp: 'image/webp',
|
|
218
|
+
bmp: 'image/bmp',
|
|
219
|
+
ico: 'image/x-icon',
|
|
220
|
+
svg: 'image/svg+xml',
|
|
221
|
+
};
|
|
222
|
+
/** 走 base64 整读再由 renderer 解析的格式(fs-read 按 kind:'bytes' 回)。 */
|
|
223
|
+
const BYTES_MIME = {
|
|
224
|
+
pdf: 'application/pdf',
|
|
225
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
226
|
+
xlsm: 'application/vnd.ms-excel.sheet.macroenabled.12',
|
|
227
|
+
};
|
|
228
|
+
/** 明确的二进制扩展名:不读内容,renderer 画「暂不支持预览」占位。 */
|
|
229
|
+
const BINARY_EXTS = new Set([
|
|
230
|
+
'exe', 'dll', 'so', 'dylib', 'node', 'bin', 'msi', 'apk',
|
|
231
|
+
'zip', '7z', 'rar', 'gz', 'tgz', 'bz2', 'xz', 'zst', 'tar',
|
|
232
|
+
'jar', 'class', 'pyc', 'pyd', 'wasm',
|
|
233
|
+
'woff', 'woff2', 'ttf', 'otf', 'eot',
|
|
234
|
+
'mp3', 'wav', 'flac', 'ogg', 'm4a',
|
|
235
|
+
'mp4', 'mov', 'avi', 'mkv', 'webm', 'flv',
|
|
236
|
+
'psd', 'ai', 'sketch', 'blend',
|
|
237
|
+
'db', 'sqlite', 'sqlite3', 'mdb', 'accdb',
|
|
238
|
+
'doc', 'docx', 'ppt', 'pptx', 'xls', 'odt', 'ods',
|
|
239
|
+
]);
|
|
240
|
+
/** 文件名的自然序(数字按值、大小写不敏感),移植 dsh orderEntries 的排序器。 */
|
|
241
|
+
const NAME_COLLATOR = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
|
|
242
|
+
/** 支持的终端 shell(payload.shell 白名单;spawn 首参必须是字面量——安全扫描静态规则)。 */
|
|
243
|
+
function spawnShell(shell, cwd) {
|
|
244
|
+
switch (shell) {
|
|
245
|
+
case 'pwsh':
|
|
246
|
+
return spawn('pwsh.exe', ['-NoProfile', '-NoLogo', '-NonInteractive', '-Command', '-'], { cwd, windowsHide: true });
|
|
247
|
+
case 'cmd':
|
|
248
|
+
return spawn('cmd.exe', ['/Q', '/K'], { cwd, windowsHide: true });
|
|
249
|
+
case 'bash':
|
|
250
|
+
return spawn('bash.exe', ['--noprofile', '--norc'], { cwd, windowsHide: true });
|
|
251
|
+
case 'node':
|
|
252
|
+
return spawn('node.exe', ['-i'], { cwd, windowsHide: true });
|
|
253
|
+
default:
|
|
254
|
+
return spawn('powershell.exe', ['-NoProfile', '-NoLogo', '-NonInteractive', '-Command', '-'], { cwd, windowsHide: true });
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
export const desktopDockPlugin = {
|
|
258
|
+
name: 'desktop-dock',
|
|
259
|
+
provide: 'dock',
|
|
260
|
+
apply(ctx, config) {
|
|
261
|
+
/**
|
|
262
|
+
* 兜底工作目录:插件挂载时进程的启动目录。只在拿不到当前会话时用它
|
|
263
|
+
* (宿主刚起来还没有会话的极短窗口)。它不是主基准——见 {@link baseCwd}。
|
|
264
|
+
*/
|
|
265
|
+
const fallbackCwd = config?.cwd ?? process.cwd();
|
|
266
|
+
/**
|
|
267
|
+
* 本次请求的工作目录基准:**当前会话的 cwd**,取不到才落回启动目录。
|
|
268
|
+
*
|
|
269
|
+
* 为什么不用挂载时定死的 `process.cwd()`:常驻多会话模型下(0.6.48 起),
|
|
270
|
+
* 同一宿主进程里不同会话的 cwd 不同,进程 cwd 只是「宿主从哪启动的」。
|
|
271
|
+
* 拿启动目录当基准,用户切到别的工作区的会话后,文件树 / git / 终端会
|
|
272
|
+
* 继续指着那个目录(0.6.67 报障:文件管理显示的不是对应工作区的文件)。
|
|
273
|
+
* 沙箱的 `canWrite(path, cwd)` 早就用「会话工作目录随会话走」的口径,
|
|
274
|
+
* 这一份与它对齐;安全边界(`inside` 检查)仍然在,只是基准从进程目录
|
|
275
|
+
* 换成了会话目录——越界读写与从前一样被拒。
|
|
276
|
+
*/
|
|
277
|
+
const baseCwd = () => {
|
|
278
|
+
const session = ctx.get('session');
|
|
279
|
+
const cwd = session?.current().meta?.cwd;
|
|
280
|
+
return typeof cwd === 'string' && cwd !== '' ? cwd : fallbackCwd;
|
|
281
|
+
};
|
|
282
|
+
// ---- 终端会话(管道模式:行缓冲输入由 renderer 负责,这里每行执行) ----
|
|
283
|
+
const terms = new Map();
|
|
284
|
+
let termSeq = 0;
|
|
285
|
+
/**
|
|
286
|
+
* 写类 op 的审批闸:与工具调用同一套裁决(`approval.decide`),所以权限模式
|
|
287
|
+
* (只读 / 自动编辑 / 完全访问 / AI 审查)对"文件面板里按一下暂存"同样成立,
|
|
288
|
+
* 不需要给界面另立一套策略。
|
|
289
|
+
*
|
|
290
|
+
* 不带 `sessionPath`:`ApprovalRequest` 缺它时归到**当前会话**(宿主的 `pathOf` 口径),
|
|
291
|
+
* 这与界面按钮"点的是我正在看的这个会话"一致。
|
|
292
|
+
*
|
|
293
|
+
* 失败方向:**审批服务没起来就拒**——宁可这次点不动,也不要在没有闸门的情况下改仓库。
|
|
294
|
+
*/
|
|
295
|
+
const requireWriteApproval = async (op, payload, cwd) => {
|
|
296
|
+
const approval = ctx.get('approval');
|
|
297
|
+
if (approval === undefined)
|
|
298
|
+
throw new Error(`写操作 ${op} 需要审批服务,但它没有起来`);
|
|
299
|
+
const label = DOCK_WRITE_LABEL[op];
|
|
300
|
+
const decision = await approval.decide({ toolName: label.toolName, argsSummary: label.summary(payload), args: { ...payload }, cwd }, new AbortController().signal);
|
|
301
|
+
if (decision === 'reject')
|
|
302
|
+
throw new Error(`已拒绝:${label.toolName}`);
|
|
303
|
+
};
|
|
304
|
+
const runOp = async (op, payload, cwd) => {
|
|
305
|
+
switch (op) {
|
|
306
|
+
// ---- 终端(管道模式;无 tty,交互式全屏程序不可用) ----
|
|
307
|
+
case 'term-spawn': {
|
|
308
|
+
const id = `t${++termSeq}`;
|
|
309
|
+
const dir = resolve(cwd, safeArg(payload.cwd ?? '.', true));
|
|
310
|
+
if (!inside(dir, cwd))
|
|
311
|
+
throw new Error('路径超出工作目录');
|
|
312
|
+
// shell 白名单:非白名单值回落 PowerShell
|
|
313
|
+
const shell = ['powershell', 'pwsh', 'cmd', 'bash', 'node'].includes(String(payload.shell ?? ''))
|
|
314
|
+
? String(payload.shell)
|
|
315
|
+
: 'powershell';
|
|
316
|
+
const child = spawnShell(shell, dir);
|
|
317
|
+
terms.set(id, child);
|
|
318
|
+
child.stdout?.on('data', (chunk) => ctx.emit('dsc/dock-data', id, chunk.toString()));
|
|
319
|
+
child.stderr?.on('data', (chunk) => ctx.emit('dsc/dock-data', id, chunk.toString()));
|
|
320
|
+
child.on('exit', (code) => {
|
|
321
|
+
terms.delete(id);
|
|
322
|
+
ctx.emit('dsc/dock-data', id, `\r\n[终端会话已退出(code ${code ?? 0})]\r\n`);
|
|
323
|
+
});
|
|
324
|
+
return { id, shell };
|
|
325
|
+
}
|
|
326
|
+
case 'term-input': {
|
|
327
|
+
const child = terms.get(String(payload.id ?? ''));
|
|
328
|
+
if (child === undefined)
|
|
329
|
+
throw new Error('终端会话不存在');
|
|
330
|
+
child.stdin?.write(String(payload.data ?? ''));
|
|
331
|
+
return { ok: true };
|
|
332
|
+
}
|
|
333
|
+
case 'term-kill': {
|
|
334
|
+
const child = terms.get(String(payload.id ?? ''));
|
|
335
|
+
if (child !== undefined) {
|
|
336
|
+
terms.delete(String(payload.id ?? ''));
|
|
337
|
+
child.kill();
|
|
338
|
+
}
|
|
339
|
+
return { ok: true };
|
|
340
|
+
}
|
|
341
|
+
// ---- 文件系统(限 cwd 内) ----
|
|
342
|
+
case 'fs-list': {
|
|
343
|
+
const dir = resolve(cwd, safeArg(payload.dir ?? '.'));
|
|
344
|
+
if (!inside(dir, cwd))
|
|
345
|
+
throw new Error('路径超出工作目录');
|
|
346
|
+
const maxEntries = typeof payload.maxEntries === 'number' && payload.maxEntries > 0 ? Math.floor(payload.maxEntries) : 2000;
|
|
347
|
+
const listed = readdirSync(dir, { withFileTypes: true });
|
|
348
|
+
const entries = listed.slice(0, maxEntries).map((entry) => {
|
|
349
|
+
let size = 0;
|
|
350
|
+
if (!entry.isDirectory()) {
|
|
351
|
+
try {
|
|
352
|
+
size = statSync(join(dir, entry.name)).size;
|
|
353
|
+
}
|
|
354
|
+
catch {
|
|
355
|
+
size = 0;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return { name: entry.name, dir: entry.isDirectory(), size };
|
|
359
|
+
});
|
|
360
|
+
entries.sort((a, b) => (a.dir === b.dir ? NAME_COLLATOR.compare(a.name, b.name) : a.dir ? -1 : 1));
|
|
361
|
+
return { cwd: dir, entries, truncated: listed.length > maxEntries };
|
|
362
|
+
}
|
|
363
|
+
case 'fs-read': {
|
|
364
|
+
const file = resolve(cwd, safeArg(payload.file ?? '.'));
|
|
365
|
+
if (!inside(file, cwd))
|
|
366
|
+
throw new Error('路径超出工作目录');
|
|
367
|
+
const stat = statSync(file);
|
|
368
|
+
const ext = file.slice(file.lastIndexOf('.') + 1).toLowerCase();
|
|
369
|
+
const mime = IMAGE_MIME[ext];
|
|
370
|
+
if (mime !== undefined) {
|
|
371
|
+
// 图片按 base64 回给 renderer 画 <img>(SVG 也是图片路,免得当文本读成 XML)
|
|
372
|
+
if (stat.size > 5 * 1024 * 1024)
|
|
373
|
+
return { path: file, kind: 'image', tooLarge: true, mime, base64: '' };
|
|
374
|
+
return { path: file, kind: 'image', tooLarge: false, mime, base64: readFileSync(file).toString('base64') };
|
|
375
|
+
}
|
|
376
|
+
const bytesMime = BYTES_MIME[ext];
|
|
377
|
+
if (bytesMime !== undefined) {
|
|
378
|
+
// PDF / XLSX 整读成 base64,renderer 侧再解析渲染(≤10MB,超限不读)
|
|
379
|
+
if (stat.size > 10 * 1024 * 1024)
|
|
380
|
+
return { path: file, kind: 'bytes', tooLarge: true, mime: bytesMime, base64: '', size: stat.size };
|
|
381
|
+
return { path: file, kind: 'bytes', tooLarge: false, mime: bytesMime, base64: readFileSync(file).toString('base64'), size: stat.size };
|
|
382
|
+
}
|
|
383
|
+
if (BINARY_EXTS.has(ext)) {
|
|
384
|
+
return { path: file, kind: 'binary', tooLarge: false, size: stat.size };
|
|
385
|
+
}
|
|
386
|
+
if (stat.size > 512 * 1024)
|
|
387
|
+
return { path: file, kind: 'text', tooLarge: true, text: '' };
|
|
388
|
+
return { path: file, kind: 'text', tooLarge: false, text: readFileSync(file, 'utf8') };
|
|
389
|
+
}
|
|
390
|
+
// ---- git(execFile 固定子命令) ----
|
|
391
|
+
case 'git-status': {
|
|
392
|
+
// 空仓库(尚无任何提交)时 HEAD 不存在:git 把分支名打到 stdout 但退出码 128,
|
|
393
|
+
// 这里按读不到处理,显示占位分支名
|
|
394
|
+
const branch = await git(cwd, ['rev-parse', '--abbrev-ref', 'HEAD'])
|
|
395
|
+
.then((out) => out.trim())
|
|
396
|
+
.catch(() => '(无提交)');
|
|
397
|
+
// 工作目录在仓库里的前缀:porcelain / numstat 报的都是仓库根相对路径,展示要剥掉
|
|
398
|
+
// 它、范围要收在它之内(见 toWorkspacePath)。
|
|
399
|
+
const prefix = await repoPrefix(cwd);
|
|
400
|
+
// `-z`:路径原样给(默认的 C 引号会把非 ASCII 路径写成 `"a\350b"`,界面点不动)
|
|
401
|
+
const porcelain = await git(cwd, ['status', '--porcelain=v1', '-z']);
|
|
402
|
+
const staged = [];
|
|
403
|
+
const unstaged = [];
|
|
404
|
+
const untrackedRepo = [];
|
|
405
|
+
let dirtyFileCount = 0;
|
|
406
|
+
for (const { code, file } of parsePorcelainZ(porcelain)) {
|
|
407
|
+
const path = toWorkspacePath(file, prefix);
|
|
408
|
+
// 工作目录之外的变更整条不列(对齐参考实现,也与 inside() 的安全边界一致)。
|
|
409
|
+
if (path === null)
|
|
410
|
+
continue;
|
|
411
|
+
dirtyFileCount += 1;
|
|
412
|
+
if (code === '??')
|
|
413
|
+
untrackedRepo.push(path);
|
|
414
|
+
else {
|
|
415
|
+
if (code[0] !== ' ' && code[0] !== '?')
|
|
416
|
+
staged.push(`${code} ${path}`);
|
|
417
|
+
if (code[1] !== ' ')
|
|
418
|
+
unstaged.push(`${code} ${path}`);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
// `stats: true` = 状态面板「Git 工具」区与 Git 页签文件行要的每文件增删行数。
|
|
422
|
+
// 已暂存 = index vs HEAD;未暂存 = worktree vs index——两段分开拿才给得出每文件
|
|
423
|
+
// 数字(空仓库里 `--cached` 是「相对空树」,照样算得出)。
|
|
424
|
+
if (payload.stats !== true)
|
|
425
|
+
return { branch, staged, unstaged, untracked: untrackedRepo };
|
|
426
|
+
const [stagedNumstat, unstagedNumstat] = await Promise.all([
|
|
427
|
+
git(cwd, ['diff', '--cached', '--numstat', '-z']).catch(() => ''),
|
|
428
|
+
git(cwd, ['diff', '--numstat', '-z']).catch(() => ''),
|
|
429
|
+
]);
|
|
430
|
+
const stagedStats = workspaceNumstat(prefix, stagedNumstat);
|
|
431
|
+
const unstagedStats = workspaceNumstat(prefix, unstagedNumstat);
|
|
432
|
+
// 未跟踪不在 diff 里:逐文件读内容数换行符(≤1MiB、含 NUL 记 0、removed 恒 0)。
|
|
433
|
+
const untrackedLineMap = await untrackedLineStats(cwd, untrackedRepo);
|
|
434
|
+
const untracked = [];
|
|
435
|
+
const untrackedStats = {};
|
|
436
|
+
for (const path of untrackedRepo) {
|
|
437
|
+
const added = untrackedLineMap.get(path) ?? 0;
|
|
438
|
+
// 0 增 0 删的未跟踪项不进列表(目录折叠条目 `…/` 结尾的保留)——空文件、构建
|
|
439
|
+
// 产物、读不动的二进制不该以 +0/−0 占着列表;目录条目仍留作暂存入口。
|
|
440
|
+
if (added === 0 && !path.endsWith('/'))
|
|
441
|
+
continue;
|
|
442
|
+
untracked.push(path);
|
|
443
|
+
untrackedStats[path] = { added, removed: 0 };
|
|
444
|
+
}
|
|
445
|
+
let added = 0;
|
|
446
|
+
let removed = 0;
|
|
447
|
+
for (const stat of [...Object.values(stagedStats), ...Object.values(unstagedStats), ...Object.values(untrackedStats)]) {
|
|
448
|
+
added += stat.added;
|
|
449
|
+
removed += stat.removed;
|
|
450
|
+
}
|
|
451
|
+
return { branch, staged, unstaged, untracked, added, removed, dirtyFileCount, stagedStats, unstagedStats, untrackedStats };
|
|
452
|
+
}
|
|
453
|
+
case 'git-branches': {
|
|
454
|
+
// 本地分支清单(输入框上那颗分支钮的菜单读它)。排序照参考实现:当前分支永远
|
|
455
|
+
// 第一,其余按「最后一次提交时间」从新到旧——刚动过的分支最可能是要切的那个。
|
|
456
|
+
// 空仓库(还没提交过)时 `refs/heads` 是空的,但 HEAD 那个分支名仍然有意义,
|
|
457
|
+
// 所以把 `rev-parse --abbrev-ref HEAD` 的结果补进清单里(它不在 refs 里)。
|
|
458
|
+
const head = await git(cwd, ['rev-parse', '--abbrev-ref', 'HEAD'])
|
|
459
|
+
.then((out) => out.trim())
|
|
460
|
+
.catch(() => '');
|
|
461
|
+
const detached = head === 'HEAD';
|
|
462
|
+
const current = detached ? '' : head;
|
|
463
|
+
const records = await git(cwd, [
|
|
464
|
+
'for-each-ref',
|
|
465
|
+
'refs/heads',
|
|
466
|
+
// 名字 + 最后一次提交的 unix 秒(排序用)。%00 是 NUL:分支名里可能有空格,
|
|
467
|
+
// 拿 \t 或空格切都会切坏。参考实现这一条还带 upstream 与 objectname,
|
|
468
|
+
// dsc 的菜单不显示它们,就不多取。
|
|
469
|
+
'--format=%(refname:short)%00%(committerdate:unix)',
|
|
470
|
+
])
|
|
471
|
+
.then((out) => out.split('\n').map((line) => line.trimEnd()).filter((line) => line !== ''))
|
|
472
|
+
.catch(() => []);
|
|
473
|
+
const rows = [];
|
|
474
|
+
for (const line of records) {
|
|
475
|
+
const [name = '', at = ''] = line.split('\0');
|
|
476
|
+
if (name === '')
|
|
477
|
+
continue;
|
|
478
|
+
const seconds = Number.parseInt(at, 10);
|
|
479
|
+
rows.push({ name, current: name === current, at: Number.isFinite(seconds) ? seconds : 0 });
|
|
480
|
+
}
|
|
481
|
+
if (current !== '' && !rows.some((row) => row.name === current)) {
|
|
482
|
+
rows.push({ name: current, current: true, at: Number.POSITIVE_INFINITY });
|
|
483
|
+
}
|
|
484
|
+
rows.sort((left, right) => (left.current !== right.current ? (left.current ? -1 : 1) : right.at - left.at));
|
|
485
|
+
return {
|
|
486
|
+
current,
|
|
487
|
+
detached,
|
|
488
|
+
// 空仓库时 current 是 git 给的那个默认分支名(如 master),但它还不在清单里
|
|
489
|
+
// 也算「当前」——前端拿 current 判重,所以这里不重复上报。
|
|
490
|
+
branches: rows.map((row) => ({ name: row.name, current: row.current })),
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
case 'git-stage': {
|
|
494
|
+
const files = (Array.isArray(payload.files) ? payload.files : []).map((file) => safeArg(file));
|
|
495
|
+
await git(cwd, ['add', '--', ...files]);
|
|
496
|
+
return { ok: true };
|
|
497
|
+
}
|
|
498
|
+
case 'git-unstage': {
|
|
499
|
+
const files = (Array.isArray(payload.files) ? payload.files : []).map((file) => safeArg(file));
|
|
500
|
+
await git(cwd, ['reset', 'HEAD', '--', ...files]);
|
|
501
|
+
return { ok: true };
|
|
502
|
+
}
|
|
503
|
+
case 'git-commit': {
|
|
504
|
+
const text = safeArg(payload.message, true);
|
|
505
|
+
if (text.trim() === '')
|
|
506
|
+
throw new Error('提交信息为空');
|
|
507
|
+
// 提交对话框勾了未暂存文件时一次带过来:先暂存这批路径再提交,两步同属这一条
|
|
508
|
+
// 写类 op(同一张审批卡覆盖),免得「暂存」与「提交」各弹一次。
|
|
509
|
+
const paths = (Array.isArray(payload.paths) ? payload.paths : []).map((file) => safeArg(file));
|
|
510
|
+
if (paths.length > 0)
|
|
511
|
+
await git(cwd, ['add', '--', ...paths]);
|
|
512
|
+
return { ok: true, output: (await git(cwd, ['commit', '-m', text])).slice(0, 1200) };
|
|
513
|
+
}
|
|
514
|
+
case 'git-checkout': {
|
|
515
|
+
// `switch --no-guess`(git ≥ 2.23):`checkout <名字>` 在同名文件存在时会有
|
|
516
|
+
// 「是分支还是路径」的歧义,`--no-guess` 也不会顺手替用户从远端建分支。
|
|
517
|
+
// 工作树有冲突性的改动时 git 自己会拒(stderr 里说得清清楚楚),原样抛给界面。
|
|
518
|
+
const branch = safeArg(payload.branch);
|
|
519
|
+
if (branch === '')
|
|
520
|
+
throw new Error('没有指定要切到哪个分支');
|
|
521
|
+
await git(cwd, ['switch', '--no-guess', branch]);
|
|
522
|
+
return { ok: true, branch };
|
|
523
|
+
}
|
|
524
|
+
case 'git-branch-create': {
|
|
525
|
+
const name = safeArg(payload.branch);
|
|
526
|
+
if (name.trim() === '')
|
|
527
|
+
throw new Error('没有指定新分支名');
|
|
528
|
+
await git(cwd, ['switch', '--no-guess', '-c', name]);
|
|
529
|
+
return { ok: true, branch: name };
|
|
530
|
+
}
|
|
531
|
+
case 'git-log': {
|
|
532
|
+
return {
|
|
533
|
+
log: await git(cwd, ['log', '--pretty=format:%h%x09%an%x09%ad%x09%s', '--date=short', '-n', '30']),
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
case 'git-diff': {
|
|
537
|
+
// file 为空 = 全部未提交改动(tracked 段含已暂存 + 未暂存,外加未跟踪的合成段);
|
|
538
|
+
// 指定文件 = 单文件。`staged: true` 时单文件只取已暂存段(index vs HEAD)。
|
|
539
|
+
// --no-textconv --no-ext-diff 是 codex /diff 的 git 安全姿势:文本转换与
|
|
540
|
+
// 外部 diff driver 都可能配置成执行任意程序,看个 diff 不该替用户跑它们。
|
|
541
|
+
const guard = ['--no-textconv', '--no-ext-diff'];
|
|
542
|
+
const file = typeof payload.file === 'string' ? safeArg(payload.file) : '';
|
|
543
|
+
const staged = payload.staged === true;
|
|
544
|
+
const untracked = await untrackedPaths(cwd);
|
|
545
|
+
if (file !== '') {
|
|
546
|
+
// 未跟踪的目录条目带尾斜杠(`dsh-TUI/`):两边都剥掉再比,别让尾斜杠把它
|
|
547
|
+
// 甩进 tracked 那一路(那样只会回一份空 diff,看着像「没改动」)。
|
|
548
|
+
const wanted = file.replace(/\/+$/, '');
|
|
549
|
+
if (!staged && untracked.some((path) => path.replace(/\/+$/, '') === wanted)) {
|
|
550
|
+
const preview = untrackedPreview(cwd, file);
|
|
551
|
+
return preview.patch === ''
|
|
552
|
+
? { diff: '', note: preview.note }
|
|
553
|
+
: { diff: preview.patch.slice(0, 20000) };
|
|
554
|
+
}
|
|
555
|
+
return { diff: (await trackedDiff(cwd, guard, file, staged)).slice(0, 20000) };
|
|
556
|
+
}
|
|
557
|
+
// 全量:tracked 段打头,未跟踪的按内容合成段跟上(git 自己不为未跟踪文件出
|
|
558
|
+
// patch,但「全部改动」的条数本来就含它们,看不到会像坏掉)。
|
|
559
|
+
const chunks = await trackedDiff(cwd, guard).then((text) => (text === '' ? [] : [text]));
|
|
560
|
+
let synthesized = 0;
|
|
561
|
+
let bytes = 0;
|
|
562
|
+
let skipped = 0;
|
|
563
|
+
for (const path of untracked) {
|
|
564
|
+
if (synthesized >= UNTRACKED_PREVIEW_MAX_FILES || bytes >= UNTRACKED_PREVIEW_MAX_TOTAL_BYTES) {
|
|
565
|
+
skipped += 1;
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
const preview = untrackedPreview(cwd, path);
|
|
569
|
+
if (preview.patch === '') {
|
|
570
|
+
skipped += 1;
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
synthesized += 1;
|
|
574
|
+
bytes += preview.patch.length;
|
|
575
|
+
chunks.push(preview.patch);
|
|
576
|
+
}
|
|
577
|
+
return {
|
|
578
|
+
diff: chunks.join('\n').slice(0, 20000),
|
|
579
|
+
note: skipped === 0 ? '' : `另有 ${skipped} 个未跟踪条目没有合成预览,点这些行看各自的原因。`,
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
default:
|
|
583
|
+
throw new Error(`dock 未知操作:${op}`);
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
/**
|
|
587
|
+
* 一次 dock 请求:取当前会话的工作目录 → 写类先过审批闸 → 执行 → 写类落盘后催一拍
|
|
588
|
+
* git 读数。
|
|
589
|
+
*
|
|
590
|
+
* 催拍那一步是给界面那颗分支钮(宿主快照面 `surfaces.git`)的:提交 / 暂存 / 切分支 /
|
|
591
|
+
* 建分支都改了「当前分支 + 改动计数」,界面正盯着这一步的结果,不该等下一个 12 秒。
|
|
592
|
+
*/
|
|
593
|
+
const handle = async (op, payload) => {
|
|
594
|
+
// 基准目录按「当前会话」现取:切会话后下一次读取就落到新工作区(终端/git 同理)。
|
|
595
|
+
const cwd = baseCwd();
|
|
596
|
+
// 写类先过闸,再进 switch(闸门只挡写类,读类与终端不受影响)。
|
|
597
|
+
const write = isDockWriteOp(op);
|
|
598
|
+
if (write)
|
|
599
|
+
await requireWriteApproval(op, payload, cwd);
|
|
600
|
+
const out = await runOp(op, payload, cwd);
|
|
601
|
+
if (write)
|
|
602
|
+
ctx.get('git')?.refresh();
|
|
603
|
+
return out;
|
|
604
|
+
};
|
|
605
|
+
ctx.provide('dock', { handle });
|
|
606
|
+
// 热卸载必须收干净(2026-09-29 审查):终端子进程不杀会继续往 dsc/dock-data 吐输出。
|
|
607
|
+
return () => {
|
|
608
|
+
for (const child of terms.values()) {
|
|
609
|
+
try {
|
|
610
|
+
child.kill();
|
|
611
|
+
}
|
|
612
|
+
catch {
|
|
613
|
+
// 已退出的进程 kill 会报错:忽略,目的已达到
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
terms.clear();
|
|
617
|
+
};
|
|
618
|
+
},
|
|
619
|
+
};
|
|
620
|
+
/** 路径是否落在 root 内(Windows 大小写归一)。 */
|
|
621
|
+
function inside(path, root) {
|
|
622
|
+
if (!isAbsolute(path))
|
|
623
|
+
return false;
|
|
624
|
+
const rel = relative(resolve(root), resolve(path)).toLowerCase();
|
|
625
|
+
return rel === '' || (!rel.startsWith('..') && !rel.split(/[\\/]/)[0].includes(':'));
|
|
626
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dock-browser 插件:让 agent 驱动**侧栏那台浏览器**(桌面主进程里的原生 WebContentsView)。
|
|
3
|
+
*
|
|
4
|
+
* 这条链路长什么样(与 `browser.ts` 那台自管 Chrome 是两回事):
|
|
5
|
+
*
|
|
6
|
+
* ```
|
|
7
|
+
* 工具 browser_dock / browser_dock_look(本文件)
|
|
8
|
+
* │ ctx.get('hostBrowser') ← 每次调用现取,取不到就报一句人话
|
|
9
|
+
* 宿主链路门面 HostBrowserLink(实现在 host-stdio 里)
|
|
10
|
+
* │ parentPort 消息:browser-call / browser-open / browser-close / browser-views
|
|
11
|
+
* 桌面主进程(desktop/electron/main/dock.ts)
|
|
12
|
+
* │ webContents.debugger.attach('1.3') + sendCommand
|
|
13
|
+
* dock 视图(WebContentsView,持久分区 persist:dsc-browser,带用户登录态)
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* 为什么和 `browser.ts` 分成两个插件、不合并:
|
|
17
|
+
* - 那台是**一次性 Chrome**——自己拉起进程、自建临时 profile、退出整树杀;生命周期全在本进程里;
|
|
18
|
+
* - 这台是**用户自己的侧栏浏览器**——视图的创建/聚焦/尺寸归桌面壳与渲染层管(`browser-open`
|
|
19
|
+
* 要先让壳把页签开出来并聚焦,否则被节流的页面上截图会卡死),分区是持久的、带着登录态。
|
|
20
|
+
* 两者的启动、生命周期、信任口径都不一样,合在一起会把既有那台的逻辑搅进来。
|
|
21
|
+
* 而「快照 + ref 定位 + CDP 动作」那套算法是共用的:直接复用 `src/core/cdp/`,
|
|
22
|
+
* 这里只做「薄薄一层」——动作映射、ref 代际、事件缓冲与给人看的输出。
|
|
23
|
+
*
|
|
24
|
+
* 信任模型的两条硬约束(详见 `docs/dock-browser-control.md`):
|
|
25
|
+
* - `browser_dock_look` **默认不注册**,只有设置里 `lookWithoutApproval` 打开才以 `read` 注册:
|
|
26
|
+
* 这台浏览器跑在用户自己的持久分区里(`persist:dsc-browser`、带登录态),
|
|
27
|
+
* 看一眼现状(快照/截图/控制台)不该无条件免审批——与 `computer-use.ts` 那条先例同口径;
|
|
28
|
+
* - `evaluate` 必须过与 `browser.ts` **同一道敏感原语黑名单**(`actions.scanExpression`):
|
|
29
|
+
* 换了后端也不许少一道闸。
|
|
30
|
+
*
|
|
31
|
+
* @module dsc/plugins/dock-browser
|
|
32
|
+
*/
|
|
33
|
+
import type { Plugin } from '@deepseek-ai/cordis';
|
|
34
|
+
export declare const dockBrowserPlugin: Plugin.Object;
|