@waq666/pneuma 0.7.1 → 0.8.1
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/README.md +242 -206
- package/bin/dsc.js +9 -3
- package/bin/headless.cjs +1 -1
- package/lib/adapter/transcript.d.ts +19 -2
- package/lib/adapter/transcript.js +71 -14
- package/lib/app/AgentsOverlay.js +7 -6
- package/lib/app/App.js +1 -1
- package/lib/app/ApprovalCard.js +15 -9
- package/lib/app/ChatView.d.ts +3 -1
- package/lib/app/ChatView.js +21 -17
- package/lib/app/Composer.js +22 -4
- package/lib/app/MarkdownView.js +2 -1
- package/lib/app/ModelPicker.js +7 -6
- package/lib/app/PickerFrame.d.ts +4 -0
- package/lib/app/PickerFrame.js +18 -0
- package/lib/app/PlanReviewCard.js +2 -1
- package/lib/app/PresetPicker.js +8 -7
- package/lib/app/SessionPicker.js +21 -20
- package/lib/app/SettingsOverlay.js +1 -1
- package/lib/app/SkillsPicker.js +7 -6
- package/lib/app/StatusBar.js +3 -15
- package/lib/app/TaskStrips.js +1 -4
- package/lib/app/TimelineRail.js +2 -1
- package/lib/app/ToolCard.js +2 -6
- package/lib/app/Welcome.d.ts +1 -0
- package/lib/app/Welcome.js +1 -4
- package/lib/app/click.d.ts +0 -2
- package/lib/app/click.js +2 -21
- package/lib/app/display-width.d.ts +16 -0
- package/lib/app/display-width.js +33 -0
- package/lib/app/markdown.d.ts +1 -3
- package/lib/app/markdown.js +2 -19
- package/lib/app/scroll-model.js +1 -1
- package/lib/contract/approval.d.ts +91 -0
- package/lib/contract/approval.js +1 -0
- package/lib/contract/mode.d.ts +69 -0
- package/lib/contract/mode.js +1 -0
- package/lib/contract/plugin.d.ts +240 -0
- package/lib/contract/plugin.js +1 -0
- package/lib/contract/runtime.d.ts +282 -0
- package/lib/contract/runtime.js +1 -0
- package/lib/contract/session.d.ts +208 -0
- package/lib/contract/session.js +36 -0
- package/lib/contract/settings.d.ts +242 -0
- package/lib/contract/settings.js +1 -0
- package/lib/contract/snapshot.d.ts +453 -0
- package/lib/contract/snapshot.js +1 -0
- package/lib/contract/task.d.ts +189 -0
- package/lib/contract/task.js +10 -0
- package/lib/contract/transcript.d.ts +358 -0
- package/lib/contract/transcript.js +1 -0
- package/lib/contract/usage.d.ts +132 -0
- package/lib/contract/usage.js +10 -0
- package/lib/contract.d.ts +20 -1968
- package/lib/contract.js +19 -30
- package/lib/core/agent-roles.d.ts +1 -1
- package/lib/core/agent-roles.js +6 -5
- package/lib/core/approval-floor.d.ts +9 -0
- package/lib/core/approval-floor.js +152 -25
- package/lib/core/attachments.d.ts +185 -0
- package/lib/core/attachments.js +425 -0
- package/lib/core/bytes.d.ts +14 -0
- package/lib/core/bytes.js +28 -0
- package/lib/core/call-meaning.d.ts +20 -0
- package/lib/core/call-meaning.js +347 -0
- package/lib/core/cdp/actions.js +6 -0
- package/lib/core/cdp/launch.js +2 -2
- package/lib/core/cdp/report.d.ts +27 -0
- package/lib/core/cdp/report.js +50 -0
- package/lib/core/cdp/ring-buffer.d.ts +25 -0
- package/lib/core/cdp/ring-buffer.js +44 -0
- package/lib/core/cdp/snapshot.js +5 -9
- package/lib/core/cdp/transport.js +1 -1
- package/lib/core/clamp.d.ts +20 -0
- package/lib/core/clamp.js +24 -0
- package/lib/core/clock.d.ts +16 -0
- package/lib/core/clock.js +20 -0
- package/lib/core/command-policy.js +33 -1
- package/lib/core/commands-completion.d.ts +28 -0
- package/lib/core/commands-completion.js +108 -30
- package/lib/core/compact.d.ts +36 -6
- package/lib/core/compact.js +89 -17
- package/lib/core/desktop-control.js +1 -3
- package/lib/core/dsh-compat/llm-usage-event.d.ts +78 -0
- package/lib/core/dsh-compat/llm-usage-event.js +91 -0
- package/lib/core/dsh-compat/presentation.d.ts +84 -0
- package/lib/core/dsh-compat/presentation.js +105 -0
- package/lib/core/dsh-compat/resolve-hook.d.ts +3 -3
- package/lib/core/dsh-compat/resolve-hook.js +41 -13
- package/lib/core/dsh-compat/service-map.d.ts +52 -0
- package/lib/core/dsh-compat/service-map.js +87 -0
- package/lib/core/dsh-compat/session-bridge.d.ts +107 -0
- package/lib/core/dsh-compat/session-bridge.js +376 -0
- package/lib/core/dsh-compat/session-events.d.ts +54 -0
- package/lib/core/dsh-compat/session-events.js +297 -0
- package/lib/core/dsh-compat/shims/credentials.d.ts +62 -0
- package/lib/core/dsh-compat/shims/credentials.js +86 -0
- package/lib/core/dsh-compat/shims/home-paths.d.ts +77 -0
- package/lib/core/dsh-compat/shims/home-paths.js +143 -0
- package/lib/core/dsh-compat/tools-facade.d.ts +31 -1
- package/lib/core/dsh-compat/tools-facade.js +207 -3
- package/lib/core/err-text.d.ts +5 -0
- package/lib/core/err-text.js +5 -0
- package/lib/core/events.d.ts +31 -2
- package/lib/core/git-info.d.ts +127 -15
- package/lib/core/git-info.js +315 -34
- package/lib/core/git-surface.d.ts +17 -0
- package/lib/core/git-surface.js +7 -0
- package/lib/core/hooks.d.ts +19 -2
- package/lib/core/hooks.js +57 -13
- package/lib/core/host-methods.d.ts +1 -1
- package/lib/core/host-methods.js +4 -0
- package/lib/core/image-diet.js +1 -4
- package/lib/core/json-text.d.ts +11 -0
- package/lib/core/json-text.js +18 -0
- package/lib/core/learnings/skill-write.d.ts +1 -7
- package/lib/core/learnings/skill-write.js +3 -37
- package/lib/core/lifecycle-hooks.d.ts +11 -3
- package/lib/core/lifecycle-hooks.js +33 -42
- package/lib/core/llm.d.ts +42 -0
- package/lib/core/llm.js +40 -25
- package/lib/core/loop.d.ts +11 -1
- package/lib/core/loop.js +95 -28
- package/lib/core/lsp/client.js +30 -17
- package/lib/core/lsp/normalize.d.ts +0 -2
- package/lib/core/lsp/normalize.js +1 -6
- package/lib/core/lsp/servers.js +1 -4
- package/lib/core/mcp.d.ts +18 -0
- package/lib/core/mcp.js +60 -16
- package/lib/core/microcompact.d.ts +45 -0
- package/lib/core/microcompact.js +128 -0
- package/lib/core/native-bridge.js +2 -10
- package/lib/core/path-policy.d.ts +13 -1
- package/lib/core/path-policy.js +87 -18
- package/lib/core/permission-presets.d.ts +9 -5
- package/lib/core/permission-presets.js +14 -7
- package/lib/core/permission-scope.d.ts +65 -0
- package/lib/core/permission-scope.js +109 -0
- package/lib/core/plugin-bundle.d.ts +95 -0
- package/lib/core/plugin-bundle.js +137 -0
- package/lib/core/plugin-loader.d.ts +36 -1
- package/lib/core/plugin-loader.js +336 -12
- package/lib/core/plugin-patch.d.ts +64 -0
- package/lib/core/plugin-patch.js +146 -0
- package/lib/core/plugin-registry.d.ts +14 -0
- package/lib/core/plugin-registry.js +2 -0
- package/lib/core/prefs.js +40 -2
- package/lib/core/presets.d.ts +11 -0
- package/lib/core/presets.js +61 -22
- package/lib/core/profile-dir.d.ts +5 -0
- package/lib/core/profile-dir.js +40 -0
- package/lib/core/prompt.js +55 -19
- package/lib/core/ptc.d.ts +8 -2
- package/lib/core/ptc.js +18 -4
- package/lib/core/records.d.ts +16 -0
- package/lib/core/records.js +22 -0
- package/lib/core/remote/notify.js +1 -3
- package/lib/core/remote/push.js +2 -6
- package/lib/core/sandbox/execpolicy.js +27 -3
- package/lib/core/sandbox/net-proxy.js +2 -2
- package/lib/core/sandbox/policy.d.ts +1 -1
- package/lib/core/sandbox/policy.js +21 -15
- package/lib/core/sandbox/win/account.js +1 -4
- package/lib/core/sandbox/win/acl.js +1 -6
- package/lib/core/sandbox/win/backend.d.ts +24 -3
- package/lib/core/sandbox/win/backend.js +73 -23
- package/lib/core/sandbox/win/doctor.js +1 -4
- package/lib/core/sandbox/win/runner-entry.js +1 -6
- package/lib/core/sandbox/win/setup.js +1 -4
- package/lib/core/sandbox/win/utf16.d.ts +11 -0
- package/lib/core/sandbox/win/utf16.js +15 -0
- package/lib/core/sandbox/win/wfp.js +1 -4
- package/lib/core/schedule/rule.d.ts +0 -17
- package/lib/core/schedule/rule.js +1 -3
- package/lib/core/schedule/runner.d.ts +5 -2
- package/lib/core/schedule/runner.js +32 -9
- package/lib/core/schedule/store.d.ts +0 -2
- package/lib/core/schedule/store.js +2 -9
- package/lib/core/session-index.d.ts +50 -0
- package/lib/core/session-index.js +169 -3
- package/lib/core/session.d.ts +89 -13
- package/lib/core/session.js +385 -32
- package/lib/core/shell-quote.d.ts +21 -0
- package/lib/core/shell-quote.js +24 -0
- package/lib/core/side-ask.d.ts +52 -0
- package/lib/core/side-ask.js +89 -0
- package/lib/core/skills.d.ts +16 -0
- package/lib/core/skills.js +45 -8
- package/lib/core/snapshot-throttle.d.ts +8 -0
- package/lib/core/snapshot-throttle.js +24 -0
- package/lib/core/spill.d.ts +11 -5
- package/lib/core/spill.js +35 -36
- package/lib/core/strings.d.ts +21 -0
- package/lib/core/strings.js +33 -0
- package/lib/core/terminal-env.d.ts +61 -0
- package/lib/core/terminal-env.js +327 -0
- package/lib/core/text-format.d.ts +17 -0
- package/lib/core/text-format.js +26 -0
- package/lib/core/todo-reminder.d.ts +19 -14
- package/lib/core/todo-reminder.js +14 -23
- package/lib/core/token-estimate.d.ts +18 -2
- package/lib/core/token-estimate.js +10 -2
- package/lib/core/tool-result-prune.d.ts +42 -0
- package/lib/core/tool-result-prune.js +47 -0
- package/lib/core/tool-search.d.ts +3 -2
- package/lib/core/tool-search.js +3 -2
- package/lib/core/tools/bash.d.ts +35 -3
- package/lib/core/tools/bash.js +168 -41
- package/lib/core/tools/fs-tools.js +18 -17
- package/lib/core/tools/image-tool.d.ts +2 -0
- package/lib/core/tools/image-tool.js +59 -0
- package/lib/core/tools/path-args.d.ts +4 -0
- package/lib/core/tools/path-args.js +22 -0
- package/lib/core/tools/search-tools.d.ts +30 -0
- package/lib/core/tools/search-tools.js +321 -34
- package/lib/core/tools.d.ts +82 -0
- package/lib/core/tools.js +21 -0
- package/lib/core/transcript-text.d.ts +19 -0
- package/lib/core/transcript-text.js +44 -0
- package/lib/core/ui-boot-source.d.ts +5 -0
- package/lib/core/ui-boot-source.js +10 -3
- package/lib/core/ui-bundles.d.ts +80 -6
- package/lib/core/ui-bundles.js +700 -76
- package/lib/core/ui-events.d.ts +10 -0
- package/lib/core/ui-events.js +25 -0
- package/lib/core/ui-methods.d.ts +1 -1
- package/lib/core/ui-methods.js +42 -13
- package/lib/core/ui-route.js +11 -7
- package/lib/core/ui-server.d.ts +6 -0
- package/lib/core/ui-server.js +106 -1
- package/lib/core/unified-diff.d.ts +35 -0
- package/lib/core/unified-diff.js +86 -0
- package/lib/core/usage-log.js +39 -0
- package/lib/core/web-http.d.ts +1 -1
- package/lib/core/web-http.js +1 -3
- package/lib/host/kernel.js +57 -41
- package/lib/plugins/agent.js +101 -20
- package/lib/plugins/approval-floor.js +12 -8
- package/lib/plugins/approval.js +252 -80
- package/lib/plugins/ask.js +60 -8
- package/lib/plugins/browser.js +32 -84
- package/lib/plugins/commands.js +167 -57
- package/lib/plugins/compact.d.ts +2 -2
- package/lib/plugins/compact.js +200 -30
- package/lib/plugins/computer-use.js +34 -18
- package/lib/plugins/dock-browser.js +24 -65
- package/lib/plugins/dsh-compat.js +7 -0
- package/lib/plugins/file-review.js +59 -15
- package/lib/plugins/git.js +16 -8
- package/lib/plugins/goal.js +9 -8
- package/lib/plugins/hooks.js +4 -2
- package/lib/plugins/host-stdio.js +14 -16
- package/lib/plugins/lifecycle-hooks.d.ts +5 -4
- package/lib/plugins/lifecycle-hooks.js +12 -10
- package/lib/plugins/llm.js +74 -33
- package/lib/plugins/lsp.js +22 -27
- package/lib/plugins/mcp.js +16 -17
- package/lib/plugins/memory.js +3 -24
- package/lib/plugins/microcompact.d.ts +4 -1
- package/lib/plugins/microcompact.js +117 -19
- package/lib/plugins/mode.js +30 -11
- package/lib/plugins/permission-presets.d.ts +2 -1
- package/lib/plugins/permission-presets.js +55 -35
- package/lib/plugins/plugin-manager.js +4 -6
- package/lib/plugins/presets.js +56 -27
- package/lib/plugins/prompt.js +54 -11
- package/lib/plugins/ptc.d.ts +13 -0
- package/lib/plugins/ptc.js +121 -24
- package/lib/plugins/remote/types.d.ts +1 -1
- package/lib/plugins/remote/types.js +11 -0
- package/lib/plugins/remote.js +14 -15
- package/lib/plugins/runtime.js +91 -14
- package/lib/plugins/sandbox.js +181 -60
- package/lib/plugins/schedule.js +12 -11
- package/lib/plugins/self-improve.js +28 -18
- package/lib/plugins/session-search.js +18 -13
- package/lib/plugins/session-title.js +1 -1
- package/lib/plugins/session.js +103 -25
- package/lib/plugins/settings.js +16 -40
- package/lib/plugins/skills.js +18 -1
- package/lib/plugins/spill.js +18 -11
- package/lib/plugins/subagent.js +208 -42
- package/lib/plugins/team.js +11 -5
- package/lib/plugins/todo.d.ts +1 -1
- package/lib/plugins/todo.js +25 -19
- package/lib/plugins/tool-search.js +47 -28
- package/lib/plugins/tools-default.js +89 -5
- package/lib/plugins/tools.js +3 -3
- package/lib/plugins/transcript.js +116 -9
- package/lib/plugins/web-search.d.ts +1 -1
- package/lib/plugins/web-search.js +25 -16
- package/lib/plugins/webserver.js +40 -7
- package/lib/remote/assets/app-B3Id1EBq.js +14 -0
- package/lib/remote/assets/index.html +2 -2
- package/lib/remote/assets/{style-DIB6729x.css → style-NtlpbKOI.css} +1 -1
- package/lib/services/types.d.ts +247 -29
- package/lib/tools/plugin-cli.d.ts +1 -0
- package/lib/tools/plugin-cli.js +209 -0
- package/lib/ui/assets/app-B-Jx5dnh.js +90 -0
- package/lib/ui/assets/{chunk-BajyYBss.js → chunk-Bfdlo8Me.js} +1 -1
- package/lib/ui/assets/chunk-DGX-i4eb.js +12 -0
- package/lib/ui/assets/index.html +62 -14
- package/lib/ui/assets/style-WzxwEPaE.css +1 -0
- package/lib/ui/frames.js +1 -3
- package/lib/ui/index.d.ts +30 -1
- package/lib/ui/index.js +29 -0
- package/lib/ui/manifest.d.ts +24 -6
- package/lib/ui/manifest.js +3 -2
- package/lib/ui/plugins/actions/bundle.json +8 -0
- package/lib/ui/plugins/actions/client.js +43 -0
- package/lib/ui/plugins/ask/bundle.json +8 -0
- package/lib/ui/plugins/ask/client.js +415 -0
- package/lib/ui/plugins/browser/bundle.json +8 -0
- package/lib/ui/plugins/composer/bundle.json +9 -0
- package/lib/ui/plugins/composer/client.js +1806 -1087
- package/lib/ui/plugins/files/bundle.json +8 -0
- package/lib/ui/plugins/files/client.js +13 -98
- package/lib/ui/plugins/manifest.json +1 -104
- package/lib/ui/plugins/palette/bundle.json +8 -0
- package/lib/ui/plugins/palette/client.js +360 -0
- package/lib/ui/plugins/plugins/bundle.json +8 -0
- package/lib/ui/plugins/plugins/client.js +116 -38
- package/lib/ui/plugins/preview/bundle.json +8 -0
- package/lib/ui/plugins/preview/client.js +6 -16
- package/lib/ui/plugins/prompt/bundle.json +8 -0
- package/lib/ui/plugins/prompt/client.js +81 -47
- package/lib/ui/plugins/sessions/bundle.json +8 -0
- package/lib/ui/plugins/sessions/client.js +157 -111
- package/lib/ui/plugins/settings/bundle.json +8 -0
- package/lib/ui/plugins/settings/client.js +184 -170
- package/lib/ui/plugins/skills/bundle.json +8 -0
- package/lib/ui/plugins/skills/client.js +161 -79
- package/lib/ui/plugins/status/bundle.json +8 -0
- package/lib/ui/plugins/status/client.js +165 -26
- package/lib/ui/plugins/statusbar/bundle.json +9 -0
- package/lib/ui/plugins/statusbar/client.js +100 -144
- package/lib/ui/plugins/tasks/bundle.json +8 -0
- package/lib/ui/plugins/team/bundle.json +8 -0
- package/lib/ui/plugins/team/client.js +60 -58
- package/lib/ui/plugins/terminal/bundle.json +8 -0
- package/lib/ui/plugins/terminal/client.js +1 -7
- package/lib/ui/plugins/trace/bundle.json +11 -0
- package/lib/ui/plugins/trace/client.js +86 -179
- package/lib/ui/plugins/transcript/bundle.json +8 -0
- package/lib/ui/plugins/transcript/client.js +1608 -1243
- package/lib/ui/sdk/@dsc/ui/index.d.ts +54 -16
- package/lib/ui/sdk/@dsc/ui/package.json +1 -1
- package/lib/ui/sdk/@dsc/ui-core/contract.d.ts +20 -1968
- package/lib/ui/sdk/@dsc/ui-core/core/attachments.d.ts +185 -0
- package/lib/ui/sdk/@dsc/ui-core/core/bytes.d.ts +14 -0
- package/lib/ui/sdk/@dsc/ui-core/core/err-text.d.ts +18 -0
- package/lib/ui/sdk/@dsc/ui-core/core/git-surface.d.ts +17 -0
- package/lib/ui/sdk/@dsc/ui-core/core/json-text.d.ts +11 -0
- package/lib/ui/sdk/@dsc/ui-core/core/path-policy.d.ts +44 -0
- package/lib/ui/sdk/@dsc/ui-core/core/records.d.ts +16 -0
- package/lib/ui/sdk/@dsc/ui-core/core/throughput.d.ts +46 -0
- package/lib/ui/sdk/@dsc/ui-core/core/token-estimate.d.ts +18 -2
- package/lib/ui/sdk/@dsc/ui-core/core/unified-diff.d.ts +35 -0
- package/lib/ui/sdk/@dsc/ui-core/package.json +1 -1
- package/lib/ui/sdk/@dsc/ui-core/ui/index.d.ts +30 -1
- package/lib/ui/sdk/@dsc/ui-core/ui/manifest.d.ts +24 -6
- package/lib/ui/sdk/@dsc/ui-core/ui/services.d.ts +19 -8
- package/lib/ui/sdk/@dsc/ui-core/ui/signal.d.ts +49 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-model.d.ts +17 -3
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-state.d.ts +1 -1
- package/lib/ui/sdk/@dsc/ui-dockkit/package.json +1 -1
- package/lib/ui/sdk/@dsc/ui-layout/app.d.ts +4 -0
- package/lib/ui/sdk/@dsc/ui-layout/appearance.d.ts +6 -1
- package/lib/ui/sdk/@dsc/ui-layout/host-channel.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-layout/index.d.ts +1 -0
- package/lib/ui/sdk/@dsc/ui-layout/package.json +1 -1
- package/lib/ui/sdk/@dsc/ui-layout/page-state.d.ts +1 -1
- package/lib/ui/sdk/@dsc/ui-layout/runtime-context.d.ts +10 -1
- package/lib/ui/sdk/@dsc/ui-layout/thread-view.d.ts +1 -1
- package/lib/ui/sdk/@dsc/ui-layout/usage-today.d.ts +11 -0
- package/lib/ui/sdk/@dsc/ui-primitives/dialog-focus.d.ts +30 -0
- package/lib/ui/sdk/@dsc/ui-primitives/error-text.d.ts +12 -0
- package/lib/ui/sdk/@dsc/ui-primitives/git-surface.d.ts +9 -0
- package/lib/ui/sdk/@dsc/ui-primitives/highlight.d.ts +23 -0
- package/lib/ui/sdk/@dsc/ui-primitives/humanize-error.d.ts +35 -0
- package/lib/ui/sdk/@dsc/ui-primitives/icons-workspace.d.ts +33 -0
- package/lib/ui/sdk/@dsc/ui-primitives/icons.d.ts +21 -3
- package/lib/ui/sdk/@dsc/ui-primitives/image-lightbox.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-primitives/index.d.ts +16 -0
- package/lib/ui/sdk/@dsc/ui-primitives/markdown.d.ts +10 -14
- package/lib/ui/sdk/@dsc/ui-primitives/package.json +1 -1
- package/lib/ui/sdk/@dsc/ui-primitives/panels.d.ts +31 -8
- package/lib/ui/sdk/@dsc/ui-primitives/paths.d.ts +2 -0
- package/lib/ui/sdk/@dsc/ui-primitives/review-findings-card.d.ts +25 -0
- package/lib/ui/sdk/@dsc/ui-primitives/review-findings.d.ts +64 -0
- package/lib/ui/sdk/@dsc/ui-primitives/review-notice-card.d.ts +27 -0
- package/lib/ui/sdk/@dsc/ui-primitives/review-notice.d.ts +80 -0
- package/lib/ui/sdk/@dsc/ui-primitives/signal.d.ts +9 -0
- package/lib/ui/sdk/@dsc/ui-primitives/sizes.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-primitives/skeleton.d.ts +39 -0
- package/lib/ui/sdk/@dsc/ui-primitives/snapshot.d.ts +46 -0
- package/lib/ui/sdk/@dsc/ui-primitives/thread-resizer.d.ts +3 -3
- package/lib/ui/sdk/@dsc/ui-primitives/throughput.d.ts +13 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tokens.d.ts +9 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tool-args.d.ts +1 -1
- package/lib/ui/sdk/@dsc/ui-primitives/tool-summary.d.ts +30 -6
- package/lib/ui/sdk/@dsc/ui-primitives/unified-diff.d.ts +10 -0
- package/lib/ui/sdk/@dsc/ui-renderer/boot.d.ts +10 -1
- package/lib/ui/sdk/@dsc/ui-renderer/cordis-host.d.ts +113 -0
- package/lib/ui/sdk/@dsc/ui-renderer/package.json +1 -1
- package/lib/ui/sdk/@dsc/ui-slots/package.json +1 -1
- package/lib/ui/services.d.ts +19 -8
- package/lib/ui/services.js +20 -12
- package/lib/ui/signal.d.ts +49 -0
- package/lib/ui/signal.js +57 -0
- package/lib/ui/tui-plugins.js +36 -16
- package/package.json +71 -58
- package/lib/remote/assets/app-DAcUCOEn.js +0 -14
- package/lib/ui/assets/app-B70nVIKd.js +0 -69
- package/lib/ui/assets/chunk-BGcgwlCI.js +0 -12
- package/lib/ui/assets/style-Bq01xH_b.css +0 -1
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 终端环境探测与「默认终端」选择:这台机器上有哪几个 shell 能当命令执行器。
|
|
3
|
+
*
|
|
4
|
+
* 为什么要有这一层(2026-10-30 需求):bash 工具长期以来在 Windows 上写死
|
|
5
|
+
* `powershell.exe`——也就是说不管机器上装了什么,模型跑命令永远走 Windows PowerShell 5.1。
|
|
6
|
+
* 装了 PowerShell 7 的人要 UTF-8 默认编码与更快的启动;用 Git Bash 的人希望
|
|
7
|
+
* `git`/`node` 的 POSIX 写法直接可用;WSL 里的人希望命令落在 Linux 里。
|
|
8
|
+
* 这些都不是"猜"得出来的:必须真去探一次,探到了才把选项摆出来。
|
|
9
|
+
*
|
|
10
|
+
* 探什么、怎么探(全部是**只读**、有超时的子进程调用,不做任何写操作):
|
|
11
|
+
* - PowerShell 5.1:`%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe`
|
|
12
|
+
* - PowerShell 7+:`pwsh.exe`(PATH,其次 `%ProgramFiles%\PowerShell\7\pwsh.exe`)
|
|
13
|
+
* - Git Bash:`where bash` 的第一条(排除 System32 下那个 WSL 转发壳),
|
|
14
|
+
* 其次三个常规安装路径
|
|
15
|
+
* - WSL:`wsl.exe --status`(`--version` 在旧版 Win10 上不存在,`-l -q` 可能弹安装提示)
|
|
16
|
+
*
|
|
17
|
+
* 探测结果缓存 {@link DETECT_TTL_MS},设置页每次打开都会现取一份(过期就重探);
|
|
18
|
+
* 「重新检测」按钮走 {@link detectShells} 的 force 分支。
|
|
19
|
+
*
|
|
20
|
+
* @module dsc/core/terminal-env
|
|
21
|
+
*/
|
|
22
|
+
import { spawnSync } from 'node:child_process';
|
|
23
|
+
import { existsSync } from 'node:fs';
|
|
24
|
+
import { join } from 'node:path';
|
|
25
|
+
import { resolvePluginConfig } from './plugin-registry.js';
|
|
26
|
+
/** 设置里认得的全部取值(写盘校验与探针共用一份)。 */
|
|
27
|
+
export const SHELL_CHOICES = ['auto', 'powershell', 'pwsh', 'gitbash', 'wsl', 'sh'];
|
|
28
|
+
/**
|
|
29
|
+
* 探测结果的缓存时长。
|
|
30
|
+
*
|
|
31
|
+
* 为什么给 5 分钟而不是几秒:设置页每次打开都会走一遍各分区的 `fields()`,而探测要起四个
|
|
32
|
+
* 子进程(冷启动约 2.5 秒,`spawnSync` 会挡住事件循环)。装 shell 是低频事件,
|
|
33
|
+
* 五分钟缓存 + 一个「重新检测」按钮就够;`tools-default` 挂载后还会后台预热一次。
|
|
34
|
+
*/
|
|
35
|
+
export const DETECT_TTL_MS = 5 * 60_000;
|
|
36
|
+
/** 单个探测子进程的超时。装了 WSL 但没装发行版时 `wsl.exe` 会慢一些。 */
|
|
37
|
+
const PROBE_TIMEOUT_MS = 4_000;
|
|
38
|
+
const isWin = process.platform === 'win32';
|
|
39
|
+
/** 认不出的值一律回落 auto(配置文件手改坏不至于起不来)。 */
|
|
40
|
+
export function parseShellChoice(value) {
|
|
41
|
+
return typeof value === 'string' && SHELL_CHOICES.includes(value)
|
|
42
|
+
? value
|
|
43
|
+
: 'auto';
|
|
44
|
+
}
|
|
45
|
+
/** 这个选择该按哪种语法做结构扫描:PowerShell 家族与 POSIX 家族。 */
|
|
46
|
+
export function shellFlavor(choice) {
|
|
47
|
+
if (choice === 'powershell' || choice === 'pwsh')
|
|
48
|
+
return 'powershell';
|
|
49
|
+
if (choice === 'auto')
|
|
50
|
+
return isWin ? 'powershell' : 'posix';
|
|
51
|
+
return 'posix';
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 起一个探测子进程并收输出。
|
|
55
|
+
*
|
|
56
|
+
* 为什么按字节收再自己解:`wsl.exe` 在旧版 Windows 上按 UTF-16LE 写 stdout,
|
|
57
|
+
* 直接按 utf8 解就是一堆 `U\0b\0u\0n\0t\0u\0`。见到成片的 NUL 就换 UTF-16LE 再解一次。
|
|
58
|
+
*/
|
|
59
|
+
function probe(file, args) {
|
|
60
|
+
try {
|
|
61
|
+
const done = spawnSync(file, [...args], {
|
|
62
|
+
windowsHide: true,
|
|
63
|
+
timeout: PROBE_TIMEOUT_MS,
|
|
64
|
+
encoding: 'buffer',
|
|
65
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
66
|
+
});
|
|
67
|
+
if (done.error !== undefined)
|
|
68
|
+
return { ok: false, text: '' };
|
|
69
|
+
const raw = Buffer.concat([done.stdout ?? Buffer.alloc(0), done.stderr ?? Buffer.alloc(0)]);
|
|
70
|
+
if (raw.length === 0)
|
|
71
|
+
return { ok: done.status === 0, text: '' };
|
|
72
|
+
const nul = raw.subarray(0, Math.min(raw.length, 64)).filter((byte) => byte === 0).length;
|
|
73
|
+
const text = nul > 8
|
|
74
|
+
? raw.toString('utf16le')
|
|
75
|
+
: new TextDecoder('utf-8').decode(raw);
|
|
76
|
+
return { ok: done.status === 0, text: text.replace(/\0/g, '').trim() };
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return { ok: false, text: '' };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** 取一段文本的第一行非空内容。 */
|
|
83
|
+
function firstLine(text) {
|
|
84
|
+
for (const line of text.split(/\r?\n/)) {
|
|
85
|
+
const trimmed = line.trim();
|
|
86
|
+
if (trimmed !== '')
|
|
87
|
+
return trimmed;
|
|
88
|
+
}
|
|
89
|
+
return '';
|
|
90
|
+
}
|
|
91
|
+
/** `where` / `which` 找可执行文件的第一条结果。 */
|
|
92
|
+
function which(name) {
|
|
93
|
+
const result = isWin ? probe('where.exe', [name]) : probe('which', [name]);
|
|
94
|
+
const line = firstLine(result.ok ? result.text : '');
|
|
95
|
+
if (line === '' || !existsSync(line))
|
|
96
|
+
return undefined;
|
|
97
|
+
return line;
|
|
98
|
+
}
|
|
99
|
+
/** 从 `X.Y.Z` 形式的版本串里取前两段(`5.1` / `7.4`),取不到就用原串。 */
|
|
100
|
+
function shortVersion(text) {
|
|
101
|
+
const match = /(\d+\.\d+(?:\.\d+)?)/.exec(text);
|
|
102
|
+
return match === null ? text.slice(0, 40) : match[1];
|
|
103
|
+
}
|
|
104
|
+
/** PowerShell 5.1:路径是固定的,探版本只为把版本号写进标签。 */
|
|
105
|
+
function detectWindowsPowerShell() {
|
|
106
|
+
const file = join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe');
|
|
107
|
+
if (!existsSync(file)) {
|
|
108
|
+
return { value: 'powershell', label: 'PowerShell 5.1', available: false, detail: '没找到 powershell.exe' };
|
|
109
|
+
}
|
|
110
|
+
const result = probe(file, ['-NoProfile', '-NonInteractive', '-Command', '$PSVersionTable.PSVersion.ToString()']);
|
|
111
|
+
const version = result.ok ? shortVersion(firstLine(result.text)) : '';
|
|
112
|
+
return {
|
|
113
|
+
value: 'powershell',
|
|
114
|
+
label: version === '' ? 'PowerShell 5.1' : `PowerShell ${version}`,
|
|
115
|
+
available: true,
|
|
116
|
+
detail: file,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** PowerShell 7+:先 PATH,再常见安装路径。 */
|
|
120
|
+
function detectPwsh() {
|
|
121
|
+
const candidates = [];
|
|
122
|
+
const found = which('pwsh.exe');
|
|
123
|
+
if (found !== undefined)
|
|
124
|
+
candidates.push(found);
|
|
125
|
+
if (process.env.ProgramFiles !== undefined) {
|
|
126
|
+
candidates.push(join(process.env.ProgramFiles, 'PowerShell', '7', 'pwsh.exe'));
|
|
127
|
+
}
|
|
128
|
+
if (process.env.LOCALAPPDATA !== undefined) {
|
|
129
|
+
candidates.push(join(process.env.LOCALAPPDATA, 'Microsoft', 'WindowsApps', 'pwsh.exe'));
|
|
130
|
+
}
|
|
131
|
+
for (const file of candidates) {
|
|
132
|
+
if (!existsSync(file))
|
|
133
|
+
continue;
|
|
134
|
+
const result = probe(file, ['-NoProfile', '-NonInteractive', '-Command', '$PSVersionTable.PSVersion.ToString()']);
|
|
135
|
+
if (!result.ok)
|
|
136
|
+
continue;
|
|
137
|
+
return {
|
|
138
|
+
value: 'pwsh',
|
|
139
|
+
label: `PowerShell ${shortVersion(firstLine(result.text))}`,
|
|
140
|
+
available: true,
|
|
141
|
+
detail: file,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
return { value: 'pwsh', label: 'PowerShell 7', available: false, detail: '没装 pwsh.exe' };
|
|
145
|
+
}
|
|
146
|
+
/** Git Bash:先试常规安装路径,再退回 `where bash`(排除 System32 里那个 WSL 转发壳)。 */
|
|
147
|
+
function detectGitBash() {
|
|
148
|
+
const candidates = [];
|
|
149
|
+
for (const root of [process.env.ProgramFiles, process.env['ProgramFiles(x86)'], process.env.LOCALAPPDATA]) {
|
|
150
|
+
if (root === undefined)
|
|
151
|
+
continue;
|
|
152
|
+
candidates.push(join(root, 'Git', 'bin', 'bash.exe'));
|
|
153
|
+
candidates.push(join(root, 'Programs', 'Git', 'bin', 'bash.exe'));
|
|
154
|
+
}
|
|
155
|
+
// `where bash` 排在最后:应用自带的 MSYS bash 也可能在 PATH 里(dsh 就自带一份),
|
|
156
|
+
// 用户自己装的 Git 才该排前面——两者的行为一致,但版本与 profile 未必一样。
|
|
157
|
+
const found = which('bash.exe');
|
|
158
|
+
if (found !== undefined && !/\\Windows\\System32\\/i.test(found))
|
|
159
|
+
candidates.push(found);
|
|
160
|
+
for (const file of candidates) {
|
|
161
|
+
if (!existsSync(file))
|
|
162
|
+
continue;
|
|
163
|
+
const result = probe(file, ['--version']);
|
|
164
|
+
if (!result.ok)
|
|
165
|
+
continue;
|
|
166
|
+
// 输出形如 `GNU bash, version 5.2.37(1)-release (x86_64-pc-msys)`
|
|
167
|
+
return {
|
|
168
|
+
value: 'gitbash',
|
|
169
|
+
label: `Git Bash ${shortVersion(firstLine(result.text))}`,
|
|
170
|
+
available: true,
|
|
171
|
+
detail: file,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
return { value: 'gitbash', label: 'Git Bash', available: false, detail: '没找到 Git 自带的 bash.exe' };
|
|
175
|
+
}
|
|
176
|
+
/** WSL:`--status` 最轻量(不会触发「要不要装发行版」的提示,也不会启动虚拟机)。 */
|
|
177
|
+
function detectWsl() {
|
|
178
|
+
const file = which('wsl.exe') ?? join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'wsl.exe');
|
|
179
|
+
if (!existsSync(file)) {
|
|
180
|
+
return { value: 'wsl', label: 'WSL', available: false, detail: '没装 WSL' };
|
|
181
|
+
}
|
|
182
|
+
const status = probe(file, ['--status']);
|
|
183
|
+
if (!status.ok)
|
|
184
|
+
return { value: 'wsl', label: 'WSL', available: false, detail: 'wsl.exe 不可用(没装发行版或没启用来宾机服务)' };
|
|
185
|
+
const distro = chooseWslDistro(file);
|
|
186
|
+
if (distro.kind === 'none') {
|
|
187
|
+
return { value: 'wsl', label: 'WSL', available: false, detail: '没有能跑命令的 Linux 发行版' };
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
value: 'wsl',
|
|
191
|
+
label: `WSL(${distro.name})`,
|
|
192
|
+
available: true,
|
|
193
|
+
detail: file,
|
|
194
|
+
distro: distro.name,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* 挑一个能跑用户命令的发行版。
|
|
199
|
+
*
|
|
200
|
+
* 为什么不能直接用 `wsl --list` 的第一行、也不是无脑用默认发行版(2026-10-30 实测):
|
|
201
|
+
* 装了 Docker Desktop 的机器上,默认发行版常常是 `docker-desktop`(一只只跑 Docker 的
|
|
202
|
+
* 微型发行版,里面没有 bash)。拿它跑 `bash -lc` 会报
|
|
203
|
+
* `/bin/sh: bash: Permission denied`——用户看到的是「选了 WSL,命令全挂」。
|
|
204
|
+
*
|
|
205
|
+
* 挑选顺序:默认发行版 → 其余非 Docker 管理的发行版 → 没有就判不可用。
|
|
206
|
+
* 只读 `wsl -l -v` 的输出,不启动任何发行版。
|
|
207
|
+
*/
|
|
208
|
+
function chooseWslDistro(file) {
|
|
209
|
+
const verbose = probe(file, ['-l', '-v']);
|
|
210
|
+
if (!verbose.ok)
|
|
211
|
+
return { kind: 'none' };
|
|
212
|
+
const rows = verbose.text
|
|
213
|
+
.split(/\r?\n/)
|
|
214
|
+
.map((line) => line.trim())
|
|
215
|
+
.filter((line) => line !== '' && !/^(NAME|名称)\b/i.test(line));
|
|
216
|
+
const parsed = rows
|
|
217
|
+
.map((line) => ({
|
|
218
|
+
isDefault: line.startsWith('*'),
|
|
219
|
+
name: line.replace(/^\*\s*/, '').split(/\s{2,}|\t/)[0]?.trim() ?? '',
|
|
220
|
+
}))
|
|
221
|
+
.filter((row) => row.name !== '');
|
|
222
|
+
// Docker Desktop 的两个管理发行版:能起容器,但不是给人跑命令的环境。
|
|
223
|
+
const managed = /^docker-desktop/i;
|
|
224
|
+
const fallback = parsed.find((row) => !managed.test(row.name));
|
|
225
|
+
const picked = parsed.find((row) => row.isDefault && !managed.test(row.name)) ?? fallback;
|
|
226
|
+
return picked === undefined ? { kind: 'none' } : { kind: 'distro', name: picked.name };
|
|
227
|
+
}
|
|
228
|
+
/** POSIX 平台上的 `sh`:不是选项,是 auto 的落地。 */
|
|
229
|
+
function detectPosixShell() {
|
|
230
|
+
const file = which('bash') ?? which('sh') ?? '/bin/sh';
|
|
231
|
+
const result = probe(file, ['--version']);
|
|
232
|
+
return {
|
|
233
|
+
value: 'sh',
|
|
234
|
+
label: result.ok ? `sh(${shortVersion(firstLine(result.text))})` : 'sh',
|
|
235
|
+
available: true,
|
|
236
|
+
detail: file,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/** 缓存:探测要起几次子进程,设置页反复打开不该重复付这份钱。 */
|
|
240
|
+
let cache;
|
|
241
|
+
/**
|
|
242
|
+
* 探测这台机器上能用的终端。
|
|
243
|
+
*
|
|
244
|
+
* @param force - true = 跳过缓存重探(设置页的「重新检测」按钮用)
|
|
245
|
+
* @returns 第一项永远是 `auto`,后面按平台给出各项(不可用的也在里面,界面据此显示"未检测到")
|
|
246
|
+
*/
|
|
247
|
+
export function detectShells(force = false) {
|
|
248
|
+
if (!force && cache !== undefined && Date.now() - cache.at < DETECT_TTL_MS)
|
|
249
|
+
return cache.list;
|
|
250
|
+
const auto = {
|
|
251
|
+
value: 'auto',
|
|
252
|
+
label: isWin ? '跟随平台默认(Windows PowerShell 5.1)' : '跟随平台默认(sh)',
|
|
253
|
+
available: true,
|
|
254
|
+
detail: '出厂值:Windows 走 powershell.exe,其他平台走 sh',
|
|
255
|
+
};
|
|
256
|
+
const rest = isWin
|
|
257
|
+
? [detectWindowsPowerShell(), detectPwsh(), detectGitBash(), detectWsl()]
|
|
258
|
+
: [detectPosixShell()];
|
|
259
|
+
const list = [auto, ...rest];
|
|
260
|
+
cache = { at: Date.now(), list };
|
|
261
|
+
return list;
|
|
262
|
+
}
|
|
263
|
+
/** 清掉探测缓存(配置改了、装完新 shell 之后调用)。 */
|
|
264
|
+
export function forgetShellDetection() {
|
|
265
|
+
cache = undefined;
|
|
266
|
+
choiceCache = undefined;
|
|
267
|
+
}
|
|
268
|
+
/** 当前选择缓存:每条命令都读一次 plugins.json 不值当,但改完要立刻生效。 */
|
|
269
|
+
let choiceCache;
|
|
270
|
+
const CHOICE_TTL_MS = 2_000;
|
|
271
|
+
/** 读 `plugins.json` 里 tools-default 的 `bashShell`;没配过 = auto。 */
|
|
272
|
+
export function readShellChoice() {
|
|
273
|
+
if (choiceCache !== undefined && Date.now() - choiceCache.at < CHOICE_TTL_MS)
|
|
274
|
+
return choiceCache.choice;
|
|
275
|
+
const raw = resolvePluginConfig('tools-default');
|
|
276
|
+
const choice = parseShellChoice(raw.bashShell);
|
|
277
|
+
choiceCache = { at: Date.now(), choice };
|
|
278
|
+
return choice;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* 这条命令该交给哪个 WSL 发行版(探测时挑好的那个)。
|
|
282
|
+
*
|
|
283
|
+
* @returns 发行版名;没装 WSL、或 wsl 不可用时给空串(调用方退回「不指定 -d」)
|
|
284
|
+
*/
|
|
285
|
+
export function wslDistroName() {
|
|
286
|
+
const hit = detectShells().find((item) => item.value === 'wsl');
|
|
287
|
+
return hit?.distro ?? '';
|
|
288
|
+
}
|
|
289
|
+
/** 给提示词/工具描述用的一句话(例如 `Git Bash`、`PowerShell 7.4.6`)。 */
|
|
290
|
+
export function shellLabel(choice) {
|
|
291
|
+
if (choice === 'auto')
|
|
292
|
+
return isWin ? 'Windows PowerShell 5.1' : 'sh';
|
|
293
|
+
const hit = detectShells().find((item) => item.value === choice);
|
|
294
|
+
if (hit !== undefined && hit.available)
|
|
295
|
+
return hit.label;
|
|
296
|
+
return choice;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* 一个选择该用哪个可执行文件起进程。
|
|
300
|
+
*
|
|
301
|
+
* @param choice - 用户选的值
|
|
302
|
+
* @returns 可执行文件绝对路径;`wsl` 给 wsl.exe,`auto` 按平台给默认 shell
|
|
303
|
+
*/
|
|
304
|
+
export function resolveShellExecutable(choice) {
|
|
305
|
+
const pick = (value) => {
|
|
306
|
+
const hit = detectShells().find((item) => item.value === value);
|
|
307
|
+
return hit !== undefined && hit.available ? hit.detail : undefined;
|
|
308
|
+
};
|
|
309
|
+
if (choice === 'powershell')
|
|
310
|
+
return pick('powershell') ?? 'powershell.exe';
|
|
311
|
+
if (choice === 'pwsh')
|
|
312
|
+
return pick('pwsh') ?? 'pwsh.exe';
|
|
313
|
+
if (choice === 'gitbash')
|
|
314
|
+
return pick('gitbash') ?? 'bash.exe';
|
|
315
|
+
if (choice === 'wsl')
|
|
316
|
+
return pick('wsl') ?? 'wsl.exe';
|
|
317
|
+
if (choice === 'sh')
|
|
318
|
+
return pick('sh') ?? 'sh';
|
|
319
|
+
return isWin ? (pick('powershell') ?? 'powershell.exe') : 'sh';
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* 这个选择在界面上标成什么(设置项的回执文案用)。
|
|
323
|
+
*/
|
|
324
|
+
export function shellChoiceLabel(choice) {
|
|
325
|
+
const hit = detectShells().find((item) => item.value === choice);
|
|
326
|
+
return hit === undefined ? choice : hit.label;
|
|
327
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 展示用的文本压缩(全仓库各一份):把大数字缩成 M / k,把长路径缩成末两级。
|
|
3
|
+
*
|
|
4
|
+
* 两处此前各抄两份,抄在 TUI 的界面文件里(状态栏、欢迎页、两个用量展示)。同一份
|
|
5
|
+
* 口径抄开之后最容易出现的不是崩溃,而是「同一个数字在两个地方长得不一样」——
|
|
6
|
+
* 排查时没人会怀疑到格式化上。
|
|
7
|
+
*
|
|
8
|
+
* @module dsc/core/text-format
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* 大数字缩写:1234 → `1.2k`,1234567 → `1.2M`,999 原样。
|
|
12
|
+
* 保留一位小数、不做万/亿换算——用量统计另有一份中文口径(万 / 亿),那是给人读的大数,
|
|
13
|
+
* 这两个函数不共用一个名字,免得哪天有人把它们「顺便合并」。
|
|
14
|
+
*/
|
|
15
|
+
export declare function compactTokens(value: number): string;
|
|
16
|
+
/** 路径缩成末两级:`/a/b/c/d` → `…/c/d`;两级以内原样给(短路径缩了反而看不懂)。 */
|
|
17
|
+
export declare function shortCwd(cwd: string): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 展示用的文本压缩(全仓库各一份):把大数字缩成 M / k,把长路径缩成末两级。
|
|
3
|
+
*
|
|
4
|
+
* 两处此前各抄两份,抄在 TUI 的界面文件里(状态栏、欢迎页、两个用量展示)。同一份
|
|
5
|
+
* 口径抄开之后最容易出现的不是崩溃,而是「同一个数字在两个地方长得不一样」——
|
|
6
|
+
* 排查时没人会怀疑到格式化上。
|
|
7
|
+
*
|
|
8
|
+
* @module dsc/core/text-format
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* 大数字缩写:1234 → `1.2k`,1234567 → `1.2M`,999 原样。
|
|
12
|
+
* 保留一位小数、不做万/亿换算——用量统计另有一份中文口径(万 / 亿),那是给人读的大数,
|
|
13
|
+
* 这两个函数不共用一个名字,免得哪天有人把它们「顺便合并」。
|
|
14
|
+
*/
|
|
15
|
+
export function compactTokens(value) {
|
|
16
|
+
if (value >= 1_000_000)
|
|
17
|
+
return `${(value / 1_000_000).toFixed(1)}M`;
|
|
18
|
+
if (value >= 1000)
|
|
19
|
+
return `${(value / 1000).toFixed(1)}k`;
|
|
20
|
+
return String(value);
|
|
21
|
+
}
|
|
22
|
+
/** 路径缩成末两级:`/a/b/c/d` → `…/c/d`;两级以内原样给(短路径缩了反而看不懂)。 */
|
|
23
|
+
export function shortCwd(cwd) {
|
|
24
|
+
const parts = cwd.split(/[\\/]/).filter((part) => part !== '');
|
|
25
|
+
return parts.length <= 2 ? cwd : `…${parts.slice(-2).join('/')}`;
|
|
26
|
+
}
|
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
* todo 节流提醒的纯逻辑(投影本体注册在 `plugins/todo.ts`,这里是可被探针直读的那层)。
|
|
3
3
|
*
|
|
4
4
|
* 为什么要有这条提醒:dsc 把「做完一步就改状态」写死在 todo_write 的工具说明里,
|
|
5
|
-
* 长会话里模型还是会忘(ZCode 的做法是每 N
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* 长会话里模型还是会忘(ZCode 的做法是每 N 个回合往历史尾巴补一条节流的提醒,
|
|
6
|
+
* 比静态叮嘱更能拉回注意力)。
|
|
7
|
+
*
|
|
8
|
+
* **2026-10-27 改口径:按「轮」数,不再按「用户回合」数,且默认开。**
|
|
9
|
+
* 原来的口径是「距上次写清单过了几个用户回合」,但用户看到的问题是「跑了几十轮,
|
|
10
|
+
* 清单还停在 0/4」——一轮里模型会发几十次请求,用户回合数根本不涨,提醒永远不触发。
|
|
11
|
+
* 现在数的是「距上次 todo_write 之后又发了几次请求」(一条 assistant 消息 = 一轮),
|
|
12
|
+
* 默认 8 轮提醒一次。代价是长清单任务里每轮多一条 user 文本(约 30 token),
|
|
13
|
+
* 只在「清单里确实还有未完成项」时才发。
|
|
8
14
|
*
|
|
9
15
|
* 纯函数、不改日志:它只往「发给模型的那份消息」末尾追加一条 user 消息,不碰会话记录
|
|
10
16
|
* (投影链的既有约定——日志存原文,模型看见的内容由这条链可复算)。提醒是提示不是事实,
|
|
@@ -17,28 +23,27 @@ import type { ChatMessage } from './llm.js';
|
|
|
17
23
|
export declare const TODO_REMINDER_TEXT = "\uFF08\u63D0\u9192\uFF1A\u4EFB\u52A1\u6E05\u5355\u6709\u672A\u5B8C\u6210\u9879\uFF0C\u505A\u5B8C\u4E00\u6B65\u5C31\u628A\u72B6\u6001\u6539\u6389\uFF09";
|
|
18
24
|
/** {@link appendTodoReminder} 的判断输入。 */
|
|
19
25
|
export interface TodoReminderOptions {
|
|
20
|
-
/** 总开关(默认
|
|
26
|
+
/** 总开关(默认 true,见 `plugins/todo.ts` 的 REMINDER_DEFAULTS)。 */
|
|
21
27
|
enabled: boolean;
|
|
22
|
-
/**
|
|
23
|
-
|
|
28
|
+
/** 距上次写清单过了几轮才提醒(默认 8)。「一轮」= 一次模型请求 = 一条 assistant 消息。 */
|
|
29
|
+
everyRounds: number;
|
|
24
30
|
/** 当前清单里还有 pending / in_progress 的条目——没有未完成项就没什么可提醒的。 */
|
|
25
31
|
hasOpenTodos: boolean;
|
|
26
32
|
}
|
|
27
33
|
/**
|
|
28
|
-
* 数「距最近一次 `todo_write`
|
|
34
|
+
* 数「距最近一次 `todo_write` 调用又发了几次请求」。
|
|
29
35
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
36
|
+
* 一条 assistant 消息就是一轮:工具调用的 assistant(含 todo_write 自己那条)与带正文的
|
|
37
|
+
* assistant 都算。请求尾巴上那条环境快照(env-facts,order 600,跑在本投影之前)是 user,
|
|
38
|
+
* 不参与计数——这也是**为什么不用 user 消息数**:那种口径在单轮长跑里永远不涨。
|
|
33
39
|
*
|
|
34
|
-
* 历史里没有 todo_write 时从第 0
|
|
35
|
-
* 已被压缩掉)。
|
|
40
|
+
* 历史里没有 todo_write 时从第 0 条起数(会话恢复:清单从状态条目回来,工具调用可能已被压缩掉)。
|
|
36
41
|
*/
|
|
37
|
-
export declare function
|
|
42
|
+
export declare function countRoundsSinceLastTodoWrite(messages: readonly ChatMessage[]): number;
|
|
38
43
|
/**
|
|
39
44
|
* 该不该注入提醒、注入后是什么样——纯函数,返回新数组(不就地改输入)。
|
|
40
45
|
*
|
|
41
46
|
* 幂等:已经有这条提醒就不再追加(同一份历史重复投影——校验重算、流中断后的整轮重试
|
|
42
|
-
* 会重新组装——必须逐字节同结果)。`
|
|
47
|
+
* 会重新组装——必须逐字节同结果)。`everyRounds` 夹到至少 1,免得配成 0 变成每轮都发。
|
|
43
48
|
*/
|
|
44
49
|
export declare function appendTodoReminder(messages: ChatMessage[], options: TodoReminderOptions): ChatMessage[];
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
/** 注入的那条提醒原文(user 角色;文案照 todo 工具说明的口径:2–4 字动词、无标点)。 */
|
|
2
2
|
export const TODO_REMINDER_TEXT = '(提醒:任务清单有未完成项,做完一步就把状态改掉)';
|
|
3
3
|
/**
|
|
4
|
-
* 数「距最近一次 `todo_write`
|
|
4
|
+
* 数「距最近一次 `todo_write` 调用又发了几次请求」。
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* 一条 assistant 消息就是一轮:工具调用的 assistant(含 todo_write 自己那条)与带正文的
|
|
7
|
+
* assistant 都算。请求尾巴上那条环境快照(env-facts,order 600,跑在本投影之前)是 user,
|
|
8
|
+
* 不参与计数——这也是**为什么不用 user 消息数**:那种口径在单轮长跑里永远不涨。
|
|
9
9
|
*
|
|
10
|
-
* 历史里没有 todo_write 时从第 0
|
|
11
|
-
* 已被压缩掉)。
|
|
10
|
+
* 历史里没有 todo_write 时从第 0 条起数(会话恢复:清单从状态条目回来,工具调用可能已被压缩掉)。
|
|
12
11
|
*/
|
|
13
|
-
export function
|
|
12
|
+
export function countRoundsSinceLastTodoWrite(messages) {
|
|
14
13
|
let lastWrite = -1;
|
|
15
14
|
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
16
15
|
const message = messages[index];
|
|
@@ -21,32 +20,24 @@ export function countUserTurnsSinceLastTodoWrite(messages) {
|
|
|
21
20
|
break;
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
|
-
let
|
|
25
|
-
for (let index =
|
|
26
|
-
if (messages[index].role === 'assistant')
|
|
27
|
-
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
let turns = 0;
|
|
32
|
-
// user 消息后面有 assistant ⟺ 它的下标小于最靠后的那条 assistant 的下标
|
|
33
|
-
for (let index = lastWrite + 1; index < lastAssistant; index += 1) {
|
|
34
|
-
if (messages[index].role === 'user')
|
|
35
|
-
turns += 1;
|
|
23
|
+
let rounds = 0;
|
|
24
|
+
for (let index = lastWrite + 1; index < messages.length; index += 1) {
|
|
25
|
+
if (messages[index].role === 'assistant')
|
|
26
|
+
rounds += 1;
|
|
36
27
|
}
|
|
37
|
-
return
|
|
28
|
+
return rounds;
|
|
38
29
|
}
|
|
39
30
|
/**
|
|
40
31
|
* 该不该注入提醒、注入后是什么样——纯函数,返回新数组(不就地改输入)。
|
|
41
32
|
*
|
|
42
33
|
* 幂等:已经有这条提醒就不再追加(同一份历史重复投影——校验重算、流中断后的整轮重试
|
|
43
|
-
* 会重新组装——必须逐字节同结果)。`
|
|
34
|
+
* 会重新组装——必须逐字节同结果)。`everyRounds` 夹到至少 1,免得配成 0 变成每轮都发。
|
|
44
35
|
*/
|
|
45
36
|
export function appendTodoReminder(messages, options) {
|
|
46
37
|
if (!options.enabled || !options.hasOpenTodos)
|
|
47
38
|
return messages;
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
39
|
+
const everyRounds = Math.max(1, Math.floor(options.everyRounds));
|
|
40
|
+
if (countRoundsSinceLastTodoWrite(messages) < everyRounds)
|
|
50
41
|
return messages;
|
|
51
42
|
if (messages.some((message) => message.role === 'user' && message.content === TODO_REMINDER_TEXT)) {
|
|
52
43
|
return messages;
|
|
@@ -32,13 +32,22 @@ export interface SegmentMessage {
|
|
|
32
32
|
};
|
|
33
33
|
}[];
|
|
34
34
|
}
|
|
35
|
-
/** 请求按内容类型的 token 估算分段(context
|
|
35
|
+
/** 请求按内容类型的 token 估算分段(context 进度条占用段的组成)。 */
|
|
36
36
|
export interface RequestSegments {
|
|
37
37
|
system: number;
|
|
38
38
|
prompt: number;
|
|
39
39
|
assistant: number;
|
|
40
40
|
thinking: number;
|
|
41
|
+
/**
|
|
42
|
+
* 工具**结果**(tool 消息的正文)。
|
|
43
|
+
*
|
|
44
|
+
* 名字容易误解(2026-10-30 追查):它不是工具定义,是模型读完工具输出之后留在历史里的
|
|
45
|
+
* 那一段。以前界面把这一段标成「工具定义」,用户看到 41.8K 以为工具描述太肥,实际是
|
|
46
|
+
* 62 条 run_code 的返回原文。工具定义见下面的 {@link RequestSegments.schema}。
|
|
47
|
+
*/
|
|
41
48
|
tools: number;
|
|
49
|
+
/** 工具**定义**(每次请求随 requests 一起发出去的 schema 文本;也算输入 token)。 */
|
|
50
|
+
schema: number;
|
|
42
51
|
}
|
|
43
52
|
/** 全零分段(新会话 / 尚无请求记录)。 */
|
|
44
53
|
export declare function emptySegments(): RequestSegments;
|
|
@@ -52,4 +61,11 @@ export declare function emptySegments(): RequestSegments;
|
|
|
52
61
|
* 这些零头体现在权威读数(真实 prompt_tokens)与分段之和的差上,界面只拿分段画颜色,
|
|
53
62
|
* 读数永远用服务端数字。
|
|
54
63
|
*/
|
|
55
|
-
export declare function estimateRequestSegments(messages: readonly SegmentMessage[]
|
|
64
|
+
export declare function estimateRequestSegments(messages: readonly SegmentMessage[],
|
|
65
|
+
/**
|
|
66
|
+
* 这次请求携带的工具定义(已序列化的 schema 文本)。空串 = 不发工具(压缩摘要调用那种)。
|
|
67
|
+
*
|
|
68
|
+
* 为什么单独一项(2026-10-30):工具定义同样占输入 token、同样被每次都发一遍,但以前
|
|
69
|
+
* 完全没进分段——界面把「工具结果」标成「工具定义」,真·定义反而一分钱都不显示。
|
|
70
|
+
*/
|
|
71
|
+
toolSchema?: string): RequestSegments;
|
|
@@ -31,7 +31,7 @@ export function estimateTextTokens(text) {
|
|
|
31
31
|
}
|
|
32
32
|
/** 全零分段(新会话 / 尚无请求记录)。 */
|
|
33
33
|
export function emptySegments() {
|
|
34
|
-
return { system: 0, prompt: 0, assistant: 0, thinking: 0, tools: 0 };
|
|
34
|
+
return { system: 0, prompt: 0, assistant: 0, thinking: 0, tools: 0, schema: 0 };
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* 对**组装完的整份请求**按内容类型现算分段(每次请求重算,天然带「历史被压缩 /
|
|
@@ -43,7 +43,14 @@ export function emptySegments() {
|
|
|
43
43
|
* 这些零头体现在权威读数(真实 prompt_tokens)与分段之和的差上,界面只拿分段画颜色,
|
|
44
44
|
* 读数永远用服务端数字。
|
|
45
45
|
*/
|
|
46
|
-
export function estimateRequestSegments(messages
|
|
46
|
+
export function estimateRequestSegments(messages,
|
|
47
|
+
/**
|
|
48
|
+
* 这次请求携带的工具定义(已序列化的 schema 文本)。空串 = 不发工具(压缩摘要调用那种)。
|
|
49
|
+
*
|
|
50
|
+
* 为什么单独一项(2026-10-30):工具定义同样占输入 token、同样被每次都发一遍,但以前
|
|
51
|
+
* 完全没进分段——界面把「工具结果」标成「工具定义」,真·定义反而一分钱都不显示。
|
|
52
|
+
*/
|
|
53
|
+
toolSchema = '') {
|
|
47
54
|
const textOf = (content) => {
|
|
48
55
|
if (content === null)
|
|
49
56
|
return '';
|
|
@@ -78,5 +85,6 @@ export function estimateRequestSegments(messages) {
|
|
|
78
85
|
assistant: Math.ceil(segments.assistant),
|
|
79
86
|
thinking: Math.ceil(segments.thinking),
|
|
80
87
|
tools: Math.ceil(segments.tools),
|
|
88
|
+
schema: Math.ceil(estimateTextTokens(toolSchema)),
|
|
81
89
|
};
|
|
82
90
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 历史里超长工具结果的**确定性**修剪(对标 dsh 的 `compaction-tool-result-pruner`)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要(2026-10-30):PTC 模式下一条 `run_code` 的返回常常是整份文件原文
|
|
5
|
+
* (实测一个 62 次调用的会话里,工具结果合计 43K token,最大一条 6.3K token),
|
|
6
|
+
* 而这些原文在历史里每轮都重发一遍。它们读一次就够了,留着中间那几万字只是花钱。
|
|
7
|
+
*
|
|
8
|
+
* 三条不肯让步的规矩:
|
|
9
|
+
* 1. **确定性**:同一条消息永远切成同一段文本。前缀缓存只在「第一次越过窗口」那一轮
|
|
10
|
+
* 失效一次,之后逐字节稳定——如果每次请求都按当时的指针重算,缓存等于每轮都废。
|
|
11
|
+
* 2. **只切中间,两头都留**:开头往往是命令 / 表头 / 关键结论,结尾往往是错误码与
|
|
12
|
+
* 汇总。切掉中间之后明说「省略了多少字符、原文还在日志里」,模型知道该怎么办
|
|
13
|
+
* (重读文件、或换更窄的范围再查一次),而不是以为结果本来就那么短。
|
|
14
|
+
* 3. **最近的几条不动**:刚跑完的工具结果模型马上要用,切了它等于让模型重新跑一遍。
|
|
15
|
+
*
|
|
16
|
+
* 作用点:请求投影链(见 plugins/prompt.ts 的 `tool-result-prune`),只改**发给模型的
|
|
17
|
+
* 那一份**;会话日志里永远是原文,重放与审计都不受影响(dsh 的 pruner 同款口径)。
|
|
18
|
+
*
|
|
19
|
+
* @module dsc/core/tool-result-prune
|
|
20
|
+
*/
|
|
21
|
+
import type { ChatMessage } from './llm.js';
|
|
22
|
+
/** 修剪口径。字符数按 Unicode 码点算,不会把 emoji 拆成两个半截。 */
|
|
23
|
+
export interface ToolResultPruneOptions {
|
|
24
|
+
/** 合并文本超过这个字符数才修剪(默认 8192)。 */
|
|
25
|
+
thresholdChars: number;
|
|
26
|
+
/** 保留开头多少个字符。 */
|
|
27
|
+
headChars: number;
|
|
28
|
+
/** 保留结尾多少个字符。 */
|
|
29
|
+
tailChars: number;
|
|
30
|
+
/** 最近多少条工具结果原样保留(不修剪)。 */
|
|
31
|
+
keepRecent: number;
|
|
32
|
+
}
|
|
33
|
+
/** 缺省口径:与 dsh 的 pruner 同一组数字(8K 阈值 / 4K 头 / 1K 尾),另留 4 条最近结果。 */
|
|
34
|
+
export declare const DEFAULT_TOOL_RESULT_PRUNE: ToolResultPruneOptions;
|
|
35
|
+
/**
|
|
36
|
+
* 修剪历史里的超长工具结果。
|
|
37
|
+
*
|
|
38
|
+
* @param messages 请求消息(已拼系统提示)
|
|
39
|
+
* @param options 口径;缺省用 {@link DEFAULT_TOOL_RESULT_PRUNE}
|
|
40
|
+
* @returns 新的消息数组(原数组不动);没有需要修剪的就原样返回同一个引用
|
|
41
|
+
*/
|
|
42
|
+
export declare function pruneToolResults(messages: ChatMessage[], options?: ToolResultPruneOptions): ChatMessage[];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** 缺省口径:与 dsh 的 pruner 同一组数字(8K 阈值 / 4K 头 / 1K 尾),另留 4 条最近结果。 */
|
|
2
|
+
export const DEFAULT_TOOL_RESULT_PRUNE = {
|
|
3
|
+
thresholdChars: 8192,
|
|
4
|
+
headChars: 4096,
|
|
5
|
+
tailChars: 1024,
|
|
6
|
+
keepRecent: 4,
|
|
7
|
+
};
|
|
8
|
+
/** 被切掉的那段占位。写清「省了多少」与「原文去哪儿找」,别让模型当成结果本来就短。 */
|
|
9
|
+
function pruneMarker(dropped) {
|
|
10
|
+
return (`\n\n…(这里省掉了 ${String(dropped)} 个字符的中间部分:完整输出还在会话日志里,` +
|
|
11
|
+
'要原文请重新读那个文件,或换更窄的范围再查一次)…\n\n');
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 修剪历史里的超长工具结果。
|
|
15
|
+
*
|
|
16
|
+
* @param messages 请求消息(已拼系统提示)
|
|
17
|
+
* @param options 口径;缺省用 {@link DEFAULT_TOOL_RESULT_PRUNE}
|
|
18
|
+
* @returns 新的消息数组(原数组不动);没有需要修剪的就原样返回同一个引用
|
|
19
|
+
*/
|
|
20
|
+
export function pruneToolResults(messages, options = DEFAULT_TOOL_RESULT_PRUNE) {
|
|
21
|
+
const { thresholdChars, headChars, tailChars, keepRecent } = options;
|
|
22
|
+
// 预算不自洽时别硬切(会切出负数区间):调用方把配置写错了,就当没开
|
|
23
|
+
if (thresholdChars <= headChars + tailChars)
|
|
24
|
+
return messages;
|
|
25
|
+
// 先从后往前找「最近 keepRecent 条工具消息」的下标,那几条一律不动
|
|
26
|
+
const recent = new Set();
|
|
27
|
+
for (let index = messages.length - 1; index >= 0 && recent.size < keepRecent; index -= 1) {
|
|
28
|
+
if (messages[index]?.role === 'tool')
|
|
29
|
+
recent.add(index);
|
|
30
|
+
}
|
|
31
|
+
let changed = false;
|
|
32
|
+
const out = messages.map((message, index) => {
|
|
33
|
+
if (message.role !== 'tool' || recent.has(index))
|
|
34
|
+
return message;
|
|
35
|
+
if (typeof message.content !== 'string')
|
|
36
|
+
return message;
|
|
37
|
+
const points = Array.from(message.content);
|
|
38
|
+
if (points.length <= thresholdChars)
|
|
39
|
+
return message;
|
|
40
|
+
const head = points.slice(0, headChars).join('');
|
|
41
|
+
const tail = points.slice(points.length - tailChars).join('');
|
|
42
|
+
const dropped = points.length - headChars - tailChars;
|
|
43
|
+
changed = true;
|
|
44
|
+
return { ...message, content: `${head}${pruneMarker(dropped)}${tail}` };
|
|
45
|
+
});
|
|
46
|
+
return changed ? out : messages;
|
|
47
|
+
}
|