@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
package/lib/core/loop.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LlmError, StreamInterruptedError } from './llm.js';
|
|
2
|
-
import { callFacts, stripBaseline } from './tools.js';
|
|
2
|
+
import { callFacts, gateIdentity, stripBaseline } from './tools.js';
|
|
3
3
|
import { collectGitTurnChanges, snapshotGitStatus } from './git-info.js';
|
|
4
4
|
import { errText } from './err-text.js';
|
|
5
5
|
import { estimateRequestSegments } from './token-estimate.js';
|
|
@@ -64,6 +64,15 @@ export class MiniAgent {
|
|
|
64
64
|
* 而这个 agent 从生到死只认一个会话,一个字段就是「按会话去重」。
|
|
65
65
|
*/
|
|
66
66
|
lastInvariantDigest = null;
|
|
67
|
+
/**
|
|
68
|
+
* 本轮请求发给模型的那份工具目录(requestOnce 现取、executeToolCalls 用它解析)。
|
|
69
|
+
*
|
|
70
|
+
* 为什么执行不重新取一次:模型是照着**发出去的那份 schema** 喊名字的。取两次的话,
|
|
71
|
+
* 请求与执行之间只要注册表变过(换模式、插件热插拔),模型明明喊的是它刚被告诉的
|
|
72
|
+
* 工具,也会落到「未知工具」——2026-10-28 用户报的那一串就是这么来的。
|
|
73
|
+
* 换模式的影响因此从**下一轮请求**起生效,同一轮里模型面前与手上是同一份。
|
|
74
|
+
*/
|
|
75
|
+
requestTools = null;
|
|
67
76
|
constructor(deps, session) {
|
|
68
77
|
this.deps = deps;
|
|
69
78
|
this.session = session;
|
|
@@ -97,7 +106,7 @@ export class MiniAgent {
|
|
|
97
106
|
* 回合跑动中入箱时,`'notice'` 会记进收件箱条目,界面据此把它画在输入框上方的
|
|
98
107
|
* 只读通知条(而不是输入框下方的队列条);出账落库后两者都是同一条 user 消息。
|
|
99
108
|
*/
|
|
100
|
-
followup(text, images, origin = 'user') {
|
|
109
|
+
followup(text, images, origin = 'user', files) {
|
|
101
110
|
// 回合还没跑完就收到的消息算「轮中途到达」(对照 dsh 的 steering/inject,生产者
|
|
102
111
|
// 有用户插话、后台作业完成、定时补投、goal 提醒……)。它们一律先进收件箱:
|
|
103
112
|
// 直接 appendUser 会落在「还没落结果的 tool 调用」和它的结果中间——比如调用正
|
|
@@ -105,17 +114,21 @@ export class MiniAgent {
|
|
|
105
114
|
// 都 400(0.6.46 那次卡死会话的新形状)。到达与入史拆成两段,见 drainInbox。
|
|
106
115
|
// 要在 enqueueTurn 之前读 running——那之后 running 会被置真,再来一条就分不出先后了。
|
|
107
116
|
if (this.running) {
|
|
108
|
-
this.session.enqueueAsync(text, images, origin);
|
|
117
|
+
this.session.enqueueAsync(text, images, origin, files);
|
|
109
118
|
// 入箱只是「排队」,还没进对话:这里不发 user 事件(0.6.67 起出账时才发),
|
|
110
119
|
// 只报一条「收件箱变了」,界面据此把队列条 / 通知条画出来 / 刷新。
|
|
111
120
|
this.deps.emit({ type: 'inbox' });
|
|
112
121
|
return;
|
|
113
122
|
}
|
|
114
|
-
this.session.appendUser(text, images);
|
|
123
|
+
this.session.appendUser(text, images, files, origin);
|
|
115
124
|
this.deps.emit({
|
|
116
125
|
type: 'user',
|
|
117
126
|
text,
|
|
118
127
|
...(images !== undefined && images.length > 0 ? { images } : {}),
|
|
128
|
+
...(files !== undefined && files.length > 0 ? { files } : {}),
|
|
129
|
+
// 机器投递的要带上来源:界面据此画内部触发行,而不是一个能编辑的用户气泡。
|
|
130
|
+
// 日志里同一条记录也写了 origin,重放时走同一条判据(见 adapter/transcript)。
|
|
131
|
+
...(origin === 'notice' ? { origin } : {}),
|
|
119
132
|
});
|
|
120
133
|
this.enqueueTurn();
|
|
121
134
|
}
|
|
@@ -212,12 +225,16 @@ export class MiniAgent {
|
|
|
212
225
|
if (items.length === 0)
|
|
213
226
|
return;
|
|
214
227
|
for (const item of items) {
|
|
215
|
-
this.session.appendUser(item.text, item.images);
|
|
228
|
+
this.session.appendUser(item.text, item.images, item.files, item.origin);
|
|
216
229
|
this.deps.emit({
|
|
217
230
|
type: 'user',
|
|
218
231
|
text: item.text,
|
|
219
232
|
...(item.images !== undefined && item.images.length > 0 ? { images: item.images } : {}),
|
|
233
|
+
...(item.files !== undefined && item.files.length > 0 ? { files: item.files } : {}),
|
|
220
234
|
...(midTurn ? { steering: true } : {}),
|
|
235
|
+
// 来源跟着出账(出账前它只用来分「队列条 / 通知条」两种排队画法):机器投递的
|
|
236
|
+
// 那几条出账后仍是内部触发行,不会变成用户气泡(2026-11-02 报障)。
|
|
237
|
+
...(item.origin === 'notice' ? { origin: item.origin } : {}),
|
|
221
238
|
});
|
|
222
239
|
}
|
|
223
240
|
if (!midTurn)
|
|
@@ -311,6 +328,8 @@ export class MiniAgent {
|
|
|
311
328
|
for (let attempt = 1;; attempt += 1) {
|
|
312
329
|
const route = this.deps.route();
|
|
313
330
|
const tools = this.deps.tools();
|
|
331
|
+
// 这一刻的目录就是这一轮模型看到的目录,执行也按它解析(见 requestTools)
|
|
332
|
+
this.requestTools = tools;
|
|
314
333
|
// 系统提示只拼一次:真请求与 invariant 重建侧用同一份文本(重建比的是投影链,
|
|
315
334
|
// 不是提示词生成本身)。
|
|
316
335
|
const systemText = this.deps.systemPrompt();
|
|
@@ -325,7 +344,12 @@ export class MiniAgent {
|
|
|
325
344
|
this.checkRequestInvariant(messages, pristine, assembled, systemText);
|
|
326
345
|
// context 条的分段在请求组装完、流还没开的时候画出来:模型还没吐字,
|
|
327
346
|
// 界面就能显示这次的上下文由什么组成(每次重算,压缩/滚出自动重置)。
|
|
328
|
-
this.deps.emit({
|
|
347
|
+
this.deps.emit({
|
|
348
|
+
type: 'context',
|
|
349
|
+
// 第二项是工具定义(本次请求的 schema 文本):它同样每次都被发一遍、同样计输入 token,
|
|
350
|
+
// 以前完全没进分段,界面上那一段「工具定义」其实指的是工具结果(见 token-estimate.ts)。
|
|
351
|
+
segments: estimateRequestSegments(messages, describeToolSchema(this.requestTools)),
|
|
352
|
+
});
|
|
329
353
|
try {
|
|
330
354
|
const result = await this.deps.stream(route.api, {
|
|
331
355
|
baseUrl: route.baseUrl,
|
|
@@ -378,6 +402,9 @@ export class MiniAgent {
|
|
|
378
402
|
text: result.text,
|
|
379
403
|
reasoning: result.reasoning,
|
|
380
404
|
finishReason: result.finishReason,
|
|
405
|
+
// 工具调用跟消息一起给:dsh 的 assistant/message 是「正文 + 工具调用」一条,
|
|
406
|
+
// 只听 tool/call 重建不出这条消息(兼容层派发 session/event 时要用)。
|
|
407
|
+
toolCalls: result.toolCalls.map((call) => ({ id: call.id, name: call.name, arguments: call.arguments })),
|
|
381
408
|
});
|
|
382
409
|
if (result.usage !== null) {
|
|
383
410
|
this.deps.emit({
|
|
@@ -454,7 +481,10 @@ export class MiniAgent {
|
|
|
454
481
|
* 或本轮收尾时一起收割;结果永远按模型给的顺序落库,协议形状不变。
|
|
455
482
|
*/
|
|
456
483
|
async executeToolCalls(result, signal) {
|
|
457
|
-
|
|
484
|
+
// 用**这一轮请求发出去的那份**目录解析名字,不再现取一次:模型是照那份 schema
|
|
485
|
+
// 喊名字的,两次取值之间注册表一变(换模式、插件热插拔),合法调用会被判成
|
|
486
|
+
// 「未知工具」——错的不是模型,是这里取了第二份。没有快照时(不该发生)才现取。
|
|
487
|
+
const registry = new Map((this.requestTools ?? this.deps.tools()).map((tool) => [tool.name, tool]));
|
|
458
488
|
/** 已起飞还没落库的只读调用。 */
|
|
459
489
|
let flying = [];
|
|
460
490
|
const flushFlying = async () => {
|
|
@@ -498,23 +528,29 @@ export class MiniAgent {
|
|
|
498
528
|
}
|
|
499
529
|
// 一次调用动手之前先问守卫链:模式档不许改文件、免打扰档不许弹卡、审批卡等人点头,
|
|
500
530
|
// 这些都是链上的人自己说的,循环不知道也不该知道是谁。守卫(含审批卡)必须串行问。
|
|
531
|
+
//
|
|
532
|
+
// 桥接工具(tool_call)在这里脱下自己的名字:问的是被它转调的那条工具的真名、真实风险与
|
|
533
|
+
// 真实参数(2026-10-30 修)。不这么做就有两张卡:第一张写「调用 tool_call」,第二张才
|
|
534
|
+
// 写真实工具,用户既看不出要动什么、又要为同一件事点两次。桥自己不再判一遍——
|
|
535
|
+
// 它只认 gateAs 认不出的情况(名字拼错、参数坏掉),那时按桥判定,仍然只问一遍。
|
|
536
|
+
const gateInput = gateIdentity(tool, args, this.cwd);
|
|
501
537
|
const verdict = await this.deps.guards.gate({
|
|
502
|
-
toolName:
|
|
503
|
-
risk:
|
|
538
|
+
toolName: gateInput.name,
|
|
539
|
+
risk: gateInput.risk,
|
|
504
540
|
cwd: this.cwd,
|
|
505
|
-
args,
|
|
541
|
+
args: gateInput.args,
|
|
506
542
|
signal,
|
|
507
543
|
// 发起调用的会话身份:审批授权按会话记账、审批卡标明来处都靠它(0.6.48)
|
|
508
544
|
sessionId: this.session.meta.id,
|
|
509
545
|
sessionPath: this.session.filePath,
|
|
510
|
-
...callFacts(args, this.cwd),
|
|
546
|
+
...callFacts(gateInput.args, this.cwd),
|
|
511
547
|
});
|
|
512
548
|
if (verdict.action === 'deny') {
|
|
513
549
|
await flushFlying();
|
|
514
550
|
this.finishCall(call, { text: verdict.reason, stored: verdict.reason, error: 'rejected' });
|
|
515
551
|
continue;
|
|
516
552
|
}
|
|
517
|
-
if (
|
|
553
|
+
if (gateInput.risk === 'read') {
|
|
518
554
|
// 只读且放行:起飞不阻塞;落库顺序由 flushFlying 保证。
|
|
519
555
|
flying.push({ call, outcome: this.runTool(call, tool, args, signal) });
|
|
520
556
|
continue;
|
|
@@ -539,21 +575,32 @@ export class MiniAgent {
|
|
|
539
575
|
// 工具结果里的密钥形状字符串不进会话日志,也不回显给模型(遮红挂在观察者链上)。
|
|
540
576
|
const text = this.deps.guards.observe(call.name, rawText);
|
|
541
577
|
const images = typeof output === 'string' ? undefined : output.images;
|
|
542
|
-
|
|
543
|
-
// baseline
|
|
544
|
-
const
|
|
545
|
-
|
|
546
|
-
|
|
578
|
+
// 改动清单:单值(write / edit 一刀一个文件)与清单(PTC 一段脚本改多个文件)合起来看。
|
|
579
|
+
// 这里保留 baseline,落盘时再剥——回合基线记账要它(见 finishCall)。
|
|
580
|
+
const changesList = typeof output === 'string'
|
|
581
|
+
? []
|
|
582
|
+
: [...(output.changes === undefined ? [] : [output.changes]), ...(output.changesList ?? [])];
|
|
583
|
+
// dsh 插件给的卡片数据(presentCall / presentResult / presentationMeta):原样带走,
|
|
584
|
+
// 让它随工具记录落盘、重放时还能重建卡片。
|
|
585
|
+
const presentation = typeof output === 'string' ? undefined : output.presentation;
|
|
586
|
+
// baseline 是回合基线记账的内存字段:落盘形状里不留它(事件走 stripBaseline)。
|
|
587
|
+
const clean = changesList.map(stripBaseline);
|
|
588
|
+
const untouched = text === rawText && clean.length === 0 && presentation === undefined;
|
|
589
|
+
const stored = untouched
|
|
547
590
|
? output
|
|
548
|
-
:
|
|
549
|
-
|
|
550
|
-
|
|
591
|
+
: {
|
|
592
|
+
text,
|
|
593
|
+
...(images !== undefined && images.length > 0 ? { images } : {}),
|
|
594
|
+
// 单个文件写单值(与老日志同形,读的时候两边都认),多个文件写数组
|
|
595
|
+
...(clean.length === 0 ? {} : { changes: clean.length === 1 ? clean[0] : clean }),
|
|
596
|
+
...(presentation === undefined ? {} : { presentation }),
|
|
597
|
+
};
|
|
551
598
|
const imageNote = images !== undefined && images.length > 0 ? `\n[附 ${images.length} 张截图]` : '';
|
|
552
599
|
return {
|
|
553
600
|
text: text + imageNote,
|
|
554
601
|
stored,
|
|
555
|
-
...(
|
|
556
|
-
...(
|
|
602
|
+
...(changesList.length === 0 ? {} : { changesList }),
|
|
603
|
+
...(presentation === undefined ? {} : { presentation }),
|
|
557
604
|
};
|
|
558
605
|
}
|
|
559
606
|
catch (error) {
|
|
@@ -575,13 +622,33 @@ export class MiniAgent {
|
|
|
575
622
|
// 占用了这段时间(与 adapter 里工具卡 durationMs 同一口径)
|
|
576
623
|
...(startedAt === undefined ? {} : { ms: Math.max(0, Date.now() - startedAt) }),
|
|
577
624
|
});
|
|
578
|
-
//
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
625
|
+
// 成功的落盘类调用随带真实改动:界面聚合成轮尾「文件已更改」卡。
|
|
626
|
+
// 一次调用可能动了多个文件(PTC 的 run_code):逐个记基线、逐个发事件,
|
|
627
|
+
// 同文件多刀由 recordTurnChange 的「首次为准」保证基线还是回合起点。
|
|
628
|
+
if (outcome.error === undefined && outcome.changesList !== undefined) {
|
|
629
|
+
for (const change of outcome.changesList) {
|
|
630
|
+
// 改前全文记进回合基线:轮尾聚合 diff = 回合起点 vs 盘上终态(同文件多刀合一)
|
|
631
|
+
if (change.baseline !== undefined)
|
|
632
|
+
this.session.recordTurnChange(change.path, change.baseline);
|
|
633
|
+
this.deps.emit({ type: 'tool/changes', callId: call.id, change: stripBaseline(change) });
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
// dsh 插件的卡片数据(没失败才发):界面按 card 标签挑形态,没认出来的回落通用卡
|
|
637
|
+
if (outcome.error === undefined && outcome.presentation !== undefined) {
|
|
638
|
+
this.deps.emit({ type: 'tool/presentation', callId: call.id, presentation: outcome.presentation });
|
|
584
639
|
}
|
|
585
640
|
}
|
|
586
641
|
}
|
|
587
642
|
export { LlmError };
|
|
643
|
+
/**
|
|
644
|
+
* 把本次要发的工具定义拼成一段可估算的文本。
|
|
645
|
+
*
|
|
646
|
+
* 只取 name / description / parameters 三个真正上线的字段——别的字段(risk、presets 这类
|
|
647
|
+
* 本地元数据)不随请求发出去,算进去就成了虚数。数组顺序就是发送顺序,同一份工具集
|
|
648
|
+
* 每次拼出来逐字节一致(估算值因此也稳定)。
|
|
649
|
+
*/
|
|
650
|
+
function describeToolSchema(tools) {
|
|
651
|
+
if (tools.length === 0)
|
|
652
|
+
return '';
|
|
653
|
+
return JSON.stringify(tools.map((tool) => ({ name: tool.name, description: tool.description, parameters: tool.parameters })));
|
|
654
|
+
}
|
package/lib/core/lsp/client.js
CHANGED
|
@@ -25,10 +25,12 @@
|
|
|
25
25
|
*
|
|
26
26
|
* @module dsc/core/lsp/client
|
|
27
27
|
*/
|
|
28
|
-
import { spawn } from 'node:child_process';
|
|
28
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
29
29
|
import { readFileSync } from 'node:fs';
|
|
30
30
|
import { MAX_MESSAGE_BYTES, MAX_STDERR_TAIL_BYTES, MessageDecoder, StderrTail, encodeMessage, } from './framing.js';
|
|
31
|
-
import {
|
|
31
|
+
import { normalizeDiagnostics, normalizeHover, normalizeLocations } from './normalize.js';
|
|
32
|
+
import { asRecord } from '../records.js';
|
|
33
|
+
import { quoteForCmd } from '../shell-quote.js';
|
|
32
34
|
import { languageIdFor } from './servers.js';
|
|
33
35
|
import { pathToUri } from './uri.js';
|
|
34
36
|
/** 操作清单(工具 schema 的 enum 与自检共用一份)。 */
|
|
@@ -229,31 +231,46 @@ class LspConnection {
|
|
|
229
231
|
forgetPush(uri) {
|
|
230
232
|
this.pushes.delete(uri);
|
|
231
233
|
}
|
|
232
|
-
/**
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
234
|
+
/**
|
|
235
|
+
* 结束语言服务器进程(含它拉起的孙进程)。
|
|
236
|
+
*
|
|
237
|
+
* Windows 上 `child.kill()` 只结束直接子进程:`npx` / `cmd.exe` / `pyright.cmd` 这一层退出后,
|
|
238
|
+
* 它拉起的 node 仍在跑,下次查询又起一条,慢慢堆成一群孤儿。`taskkill /T /F` 按进程树收,
|
|
239
|
+
* 这是 Windows 上唯一不依赖额外依赖的做法。
|
|
240
|
+
*/
|
|
241
|
+
killTree(force) {
|
|
236
242
|
const child = this.child;
|
|
243
|
+
if (process.platform === 'win32' && child.pid !== undefined) {
|
|
244
|
+
// 控制台进程不认温和信号,这里直接 /F 整树收;协议层的 shutdown 已经在调用方走过一遍。
|
|
245
|
+
const result = spawnSync('taskkill', ['/pid', String(child.pid), '/T', '/F'], {
|
|
246
|
+
stdio: 'ignore',
|
|
247
|
+
windowsHide: true,
|
|
248
|
+
});
|
|
249
|
+
if (result.error === undefined && result.status === 0)
|
|
250
|
+
return;
|
|
251
|
+
// taskkill 不可用时退回单进程 kill(至少把直接子进程收掉)
|
|
252
|
+
}
|
|
237
253
|
try {
|
|
238
254
|
if (process.platform === 'win32')
|
|
239
255
|
child.kill();
|
|
240
256
|
else
|
|
241
|
-
child.kill('SIGTERM');
|
|
257
|
+
child.kill(force ? 'SIGKILL' : 'SIGTERM');
|
|
242
258
|
}
|
|
243
259
|
catch {
|
|
244
260
|
// 已经退了的进程再 kill 会抛,无害
|
|
245
261
|
}
|
|
262
|
+
}
|
|
263
|
+
/** 先温和结束,宽限期内没退就强杀整棵树。幂等。 */
|
|
264
|
+
terminate() {
|
|
265
|
+
if (this.exited)
|
|
266
|
+
return;
|
|
267
|
+
this.killTree(false);
|
|
246
268
|
if (this.exited)
|
|
247
269
|
return;
|
|
248
270
|
this.killTimer = setTimeout(() => {
|
|
249
271
|
if (this.exited)
|
|
250
272
|
return;
|
|
251
|
-
|
|
252
|
-
child.kill('SIGKILL');
|
|
253
|
-
}
|
|
254
|
-
catch {
|
|
255
|
-
// 同上
|
|
256
|
-
}
|
|
273
|
+
this.killTree(true);
|
|
257
274
|
}, this.options.killGraceMs);
|
|
258
275
|
this.killTimer.unref();
|
|
259
276
|
}
|
|
@@ -376,10 +393,6 @@ class LspConnection {
|
|
|
376
393
|
this.write({ jsonrpc: '2.0', id, result: null });
|
|
377
394
|
}
|
|
378
395
|
}
|
|
379
|
-
/** shell 那条路上参数由 cmd.exe 解析,带空格或元字符的要自己加引号(照 `core/mcp.ts`)。 */
|
|
380
|
-
function quoteForCmd(arg) {
|
|
381
|
-
return /[\s"&|<>^()]/.test(arg) ? `"${arg.replace(/"/g, '\\"')}"` : arg;
|
|
382
|
-
}
|
|
383
396
|
/** 一个已经握过手的语言服务器实例。串行化在管理器那一层(按 key 排队)。 */
|
|
384
397
|
export class LspInstance {
|
|
385
398
|
options;
|
|
@@ -12,8 +12,6 @@
|
|
|
12
12
|
* @module dsc/core/lsp/normalize
|
|
13
13
|
*/
|
|
14
14
|
import type { LspDiagnostic, LspHover, LspLocation } from './client.js';
|
|
15
|
-
/** 认得出是个普通对象就返回,否则 null。 */
|
|
16
|
-
export declare function asRecord(value: unknown): Record<string, unknown> | null;
|
|
17
15
|
/**
|
|
18
16
|
* 归并导航结果:`Location` / `Location[]` / `LocationLink[]` / `null` 都收成 {@link LspLocation} 数组。
|
|
19
17
|
* `LocationLink` 取 `targetUri` + `targetSelectionRange`(要的是符号本身的区间,不是整块上下文)。
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export function asRecord(value) {
|
|
3
|
-
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
4
|
-
? value
|
|
5
|
-
: null;
|
|
6
|
-
}
|
|
1
|
+
import { asRecord } from '../records.js';
|
|
7
2
|
/** 线上坐标是不是非负整数。 */
|
|
8
3
|
function isProtocolPosition(value) {
|
|
9
4
|
const doc = asRecord(value);
|
package/lib/core/lsp/servers.js
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { accessSync, constants, existsSync, statSync } from 'node:fs';
|
|
20
20
|
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
21
|
+
import { nonEmptyString } from '../strings.js';
|
|
21
22
|
/** 内置服务器表(按认领优先级排列)。 */
|
|
22
23
|
export const BUILTIN_SERVERS = [
|
|
23
24
|
{
|
|
@@ -228,10 +229,6 @@ export function parseServerOverrides(text) {
|
|
|
228
229
|
}
|
|
229
230
|
return { servers, problem: null };
|
|
230
231
|
}
|
|
231
|
-
/** 非空字符串才要,其余(含非字符串)当没给。 */
|
|
232
|
-
function nonEmptyString(value) {
|
|
233
|
-
return typeof value === 'string' && value.trim() !== '' ? value : undefined;
|
|
234
|
-
}
|
|
235
232
|
/** 字符串数组才要;元素必须都是非空字符串。没给(undefined)返回空数组,给了但畸形返回 undefined。 */
|
|
236
233
|
function stringList(value) {
|
|
237
234
|
if (value === undefined || value === null)
|
package/lib/core/mcp.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 支持的 MCP 协议版本(新到旧)。
|
|
3
|
+
*
|
|
4
|
+
* 握手时客户端报最新一条,server 可以回它自己支持的那条;只有回包落在这一组里才算谈成。
|
|
5
|
+
* 三条版本上 dsc 用到的 initialize / tools/list / tools/call 语义一致,所以都收。
|
|
6
|
+
*/
|
|
7
|
+
export declare const MCP_PROTOCOL_VERSIONS: readonly ["2025-06-18", "2025-03-26", "2024-11-05"];
|
|
8
|
+
/**
|
|
9
|
+
* 把 server 回包里的 `protocolVersion` 对到支持集合里。
|
|
10
|
+
*
|
|
11
|
+
* 只认精确匹配:MCP 没有「主版本兼容」的约定,版本号不同就是语义可能不同;
|
|
12
|
+
* 未知版本按规范断开,不带着猜到的语义继续调工具。
|
|
13
|
+
* @param value - initialize 应答里的原值(可能是任何 JSON)。
|
|
14
|
+
* @returns 谈成的版本;不认识给 null。
|
|
15
|
+
*/
|
|
16
|
+
export declare function negotiateProtocolVersion(value: unknown): string | null;
|
|
1
17
|
/**
|
|
2
18
|
* 允许带进子进程的系统环境变量。
|
|
3
19
|
* 其余一律不传:`process.env` 里有用户的模型 key 与各种令牌,MCP server 是第三方程序,
|
|
@@ -98,6 +114,8 @@ export interface McpConnection {
|
|
|
98
114
|
readonly instructions: string;
|
|
99
115
|
/** T24:server 声明的能力(resources/prompts 有没有;elicitation 是 client 能力,不在这)。 */
|
|
100
116
|
readonly capabilities: McpCapabilities;
|
|
117
|
+
/** 握手谈成的协议版本(server 回的那条;不在支持集合里会直接握手失败)。 */
|
|
118
|
+
readonly protocolVersion: string;
|
|
101
119
|
listTools(signal: AbortSignal): Promise<McpToolSpec[]>;
|
|
102
120
|
callTool(name: string, args: Record<string, unknown>, signal: AbortSignal): Promise<McpCallResult>;
|
|
103
121
|
/** T24:列资源(resources/list 翻页到底)。server 没声明 resources 时抛错。 */
|
package/lib/core/mcp.js
CHANGED
|
@@ -12,15 +12,40 @@ import { spawn } from 'node:child_process';
|
|
|
12
12
|
import { createHash } from 'node:crypto';
|
|
13
13
|
import { existsSync } from 'node:fs';
|
|
14
14
|
import { isAbsolute, join, resolve } from 'node:path';
|
|
15
|
+
import { errText as errorText } from './err-text.js';
|
|
16
|
+
import { asRecord } from './records.js';
|
|
17
|
+
import { quoteForCmd } from './shell-quote.js';
|
|
15
18
|
// ── 协议与命名常量(协议常量不随部署变,固定在这里) ──────────────────────────
|
|
16
|
-
/**
|
|
17
|
-
|
|
19
|
+
/**
|
|
20
|
+
* 支持的 MCP 协议版本(新到旧)。
|
|
21
|
+
*
|
|
22
|
+
* 握手时客户端报最新一条,server 可以回它自己支持的那条;只有回包落在这一组里才算谈成。
|
|
23
|
+
* 三条版本上 dsc 用到的 initialize / tools/list / tools/call 语义一致,所以都收。
|
|
24
|
+
*/
|
|
25
|
+
export const MCP_PROTOCOL_VERSIONS = ['2025-06-18', '2025-03-26', '2024-11-05'];
|
|
26
|
+
/** 握手时自报的版本:支持集合里最新的一条。 */
|
|
27
|
+
const MCP_PROTOCOL_VERSION = MCP_PROTOCOL_VERSIONS[0];
|
|
28
|
+
/**
|
|
29
|
+
* 把 server 回包里的 `protocolVersion` 对到支持集合里。
|
|
30
|
+
*
|
|
31
|
+
* 只认精确匹配:MCP 没有「主版本兼容」的约定,版本号不同就是语义可能不同;
|
|
32
|
+
* 未知版本按规范断开,不带着猜到的语义继续调工具。
|
|
33
|
+
* @param value - initialize 应答里的原值(可能是任何 JSON)。
|
|
34
|
+
* @returns 谈成的版本;不认识给 null。
|
|
35
|
+
*/
|
|
36
|
+
export function negotiateProtocolVersion(value) {
|
|
37
|
+
if (typeof value !== 'string')
|
|
38
|
+
return null;
|
|
39
|
+
return MCP_PROTOCOL_VERSIONS.includes(value) ? value : null;
|
|
40
|
+
}
|
|
18
41
|
/** initialize 里自报的客户端身份。 */
|
|
19
42
|
const CLIENT_INFO = { name: 'pneuma', version: '0.1.0' };
|
|
20
43
|
/** 工具名长度上限(照 codex / dsh:超长的截断后用哈希尾巴防撞)。 */
|
|
21
44
|
const TOOL_NAME_MAX = 64;
|
|
22
45
|
/** 哈希尾巴的位数。 */
|
|
23
46
|
const TOOL_NAME_HASH = 12;
|
|
47
|
+
/** 片段被清洗过时补的短哈希位数(见 sanitize:a.b 与 a_b 不能撞成一个名字)。 */
|
|
48
|
+
const TOOL_NAME_PART_HASH = 8;
|
|
24
49
|
/** tools/list 翻页上限:server 一直给新游标时也不能转死。 */
|
|
25
50
|
const MAX_TOOL_PAGES = 100;
|
|
26
51
|
/** 子进程 stderr 最多留多少字符进错误消息(这个是给人看的原因,不是日志)。 */
|
|
@@ -122,14 +147,20 @@ function needsShell(file) {
|
|
|
122
147
|
const lower = file.toLowerCase();
|
|
123
148
|
return lower.endsWith('.cmd') || lower.endsWith('.bat');
|
|
124
149
|
}
|
|
125
|
-
/** shell 那条路上参数由 cmd.exe 解析,带空格或元字符的要自己加引号。 */
|
|
126
|
-
function quoteForCmd(arg) {
|
|
127
|
-
return /[\s"&|<>^()]/.test(arg) ? `"${arg.replace(/"/g, '\\"')}"` : arg;
|
|
128
|
-
}
|
|
129
150
|
// ── 工具命名与风险等级 ───────────────────────────────────────────────────────
|
|
130
|
-
/**
|
|
151
|
+
/**
|
|
152
|
+
* 把片段里不能出现在工具名里的字符换掉。
|
|
153
|
+
*
|
|
154
|
+
* 换过的片段补 8 位短哈希(2026-10-30 修):`a.b` 与 `a_b` 都清洗成 `a_b`,不补哈希就是
|
|
155
|
+
* 同一个工具名——后注册的把先注册的顶掉,模型看到的目录少一条、调用时还可能打到错的工具。
|
|
156
|
+
* 原样合法的片段不动(`create_issue` 还是 `create_issue`,不打扰用户手上的配置与延后规则)。
|
|
157
|
+
*/
|
|
131
158
|
function sanitize(part) {
|
|
132
|
-
|
|
159
|
+
const clean = part.replace(/[^A-Za-z0-9_-]/g, '_');
|
|
160
|
+
if (clean === part)
|
|
161
|
+
return clean;
|
|
162
|
+
const digest = createHash('sha256').update(part).digest('hex').slice(0, TOOL_NAME_PART_HASH);
|
|
163
|
+
return `${clean}_${digest}`;
|
|
133
164
|
}
|
|
134
165
|
/**
|
|
135
166
|
* 拼完整工具名:`mcp__<server>__<tool>`。
|
|
@@ -281,10 +312,6 @@ function asRiskMap(value) {
|
|
|
281
312
|
export function asRisk(value) {
|
|
282
313
|
return value === 'read' || value === 'write' || value === 'exec' ? value : undefined;
|
|
283
314
|
}
|
|
284
|
-
/** 错误对象取一句话;不是 Error 就字符串化。 */
|
|
285
|
-
function errorText(error) {
|
|
286
|
-
return error instanceof Error ? error.message : String(error);
|
|
287
|
-
}
|
|
288
315
|
/** JSON-RPC 错误对象压成一句话。 */
|
|
289
316
|
function rpcErrorMessage(error) {
|
|
290
317
|
if (error === null || typeof error !== 'object')
|
|
@@ -299,10 +326,6 @@ function unwrapRpc(message) {
|
|
|
299
326
|
throw new Error(rpcErrorMessage(message.error));
|
|
300
327
|
return message.result;
|
|
301
328
|
}
|
|
302
|
-
/** 认得出是个对象就返回,否则 null。 */
|
|
303
|
-
function asRecord(value) {
|
|
304
|
-
return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
305
|
-
}
|
|
306
329
|
/** 超时或取消,给一句能直接进 problem 的话。 */
|
|
307
330
|
function abortReason(signal, timeoutMs) {
|
|
308
331
|
return signal.aborted ? `请求被取消(超过 ${timeoutMs}ms 的闸门已开)` : `请求超过 ${timeoutMs}ms 没回`;
|
|
@@ -510,7 +533,18 @@ class HttpChannel {
|
|
|
510
533
|
void this.post(doc, null, new AbortController().signal).catch(() => { });
|
|
511
534
|
}
|
|
512
535
|
close() {
|
|
536
|
+
if (this.closed)
|
|
537
|
+
return;
|
|
513
538
|
this.closed = true;
|
|
539
|
+
// streamable-http 的会话归 server 持有:不发 DELETE,server 会一直挂着这条 session。
|
|
540
|
+
// 接口是同步的,所以只发不等;失败也只是会话晚一点过期,不影响本地状态。
|
|
541
|
+
if (this.sessionId !== undefined) {
|
|
542
|
+
void fetch(this.url, {
|
|
543
|
+
method: 'DELETE',
|
|
544
|
+
headers: { ...this.extraHeaders, 'mcp-session-id': this.sessionId },
|
|
545
|
+
signal: AbortSignal.timeout(5000),
|
|
546
|
+
}).catch(() => { });
|
|
547
|
+
}
|
|
514
548
|
}
|
|
515
549
|
/** 发一条 JSON-RPC 消息;expectId 非 null 时等那条 id 的应答。 */
|
|
516
550
|
async post(payload, expectId, signal) {
|
|
@@ -633,6 +667,7 @@ export async function openConnection(server, options) {
|
|
|
633
667
|
: new HttpChannel(server.url, server.headers, options.callTimeoutMs);
|
|
634
668
|
let instructions = '';
|
|
635
669
|
let capabilities = { resources: false, prompts: false };
|
|
670
|
+
let protocolVersion = MCP_PROTOCOL_VERSION;
|
|
636
671
|
try {
|
|
637
672
|
// T37:initialize 的应答不再整个丢掉——里面的 `instructions` 是 server 交代
|
|
638
673
|
// 自家工具怎么用的说明书,摘出来随连接交还。
|
|
@@ -645,6 +680,14 @@ export async function openConnection(server, options) {
|
|
|
645
680
|
clientInfo: CLIENT_INFO,
|
|
646
681
|
}, AbortSignal.timeout(options.connectTimeoutMs));
|
|
647
682
|
const initDoc = asRecord(initResult);
|
|
683
|
+
// 协议版本必须回看:server 可以回它自己支持的那一条,可能是旧版;
|
|
684
|
+
// 落在支持集合之外就按 MCP 规范断开,不带着未知语义继续发 tools/call。
|
|
685
|
+
const agreed = negotiateProtocolVersion(initDoc?.protocolVersion);
|
|
686
|
+
if (agreed === null) {
|
|
687
|
+
throw new Error(`MCP server 回应协议版本 ${JSON.stringify(initDoc?.protocolVersion ?? null)},` +
|
|
688
|
+
`不在 dsc 支持的范围(${MCP_PROTOCOL_VERSIONS.join(' / ')})内`);
|
|
689
|
+
}
|
|
690
|
+
protocolVersion = agreed;
|
|
648
691
|
const declared = initDoc?.instructions;
|
|
649
692
|
if (typeof declared === 'string')
|
|
650
693
|
instructions = declared;
|
|
@@ -675,6 +718,7 @@ export async function openConnection(server, options) {
|
|
|
675
718
|
},
|
|
676
719
|
instructions,
|
|
677
720
|
capabilities,
|
|
721
|
+
protocolVersion,
|
|
678
722
|
listTools: (signal) => listAllTools(channel, signal),
|
|
679
723
|
callTool: (name, args, signal) => callTool(channel, name, args, signal),
|
|
680
724
|
listResources: (signal) => paginate(channel, 'resources/list', 'resources', signal, readResourceSpec, '这个 server 没有声明 resources 能力'),
|
|
@@ -46,3 +46,48 @@ export interface MicrocompactOptions {
|
|
|
46
46
|
* @param options - 可调值与错误 id 集合。
|
|
47
47
|
*/
|
|
48
48
|
export declare function microcompact(messages: readonly ChatMessage[], options?: MicrocompactOptions): ChatMessage[];
|
|
49
|
+
/**
|
|
50
|
+
* 一次清理的「计划」:callId → 要换成的占位符正文。
|
|
51
|
+
*
|
|
52
|
+
* 为什么要把计划单独留一份(2026-10-28):每轮请求都重新数「最近 5 条」,
|
|
53
|
+
* 工具结果一多,几乎每一步都会有一条刚滑出窗口被清掉——清理点一改,从那条往后
|
|
54
|
+
* 整段前缀作废,服务端前缀缓存命中率被拖到 60% 上下(实测会话 bb13f0b5)。
|
|
55
|
+
* 把计划冻结到「轮到轮之间」复用,同一轮内 30 多步的前缀就是稳的。
|
|
56
|
+
*/
|
|
57
|
+
export type MicrocompactPlan = ReadonlyMap<string, string>;
|
|
58
|
+
/** 算出这次该清哪些工具结果(callId → 占位符);纯函数,不改输入。 */
|
|
59
|
+
export declare function planMicrocompact(messages: readonly ChatMessage[], options?: MicrocompactOptions): MicrocompactPlan;
|
|
60
|
+
/**
|
|
61
|
+
* 按冻结的计划改写请求体(只换 callId 命中且内容确实不同的那几条)。
|
|
62
|
+
* 计划里已经不在本次消息里的条目直接跳过(压缩可能把整段历史换掉了)。
|
|
63
|
+
*/
|
|
64
|
+
export declare function applyMicrocompactPlan(messages: readonly ChatMessage[], plan: MicrocompactPlan): ChatMessage[];
|
|
65
|
+
/** 整段提示词的字符数:把所有消息正文加起来,不数 JSON 外壳与 tool_calls 参数(大头是正文)。 */
|
|
66
|
+
export declare function promptCharsOf(messages: readonly ChatMessage[]): number;
|
|
67
|
+
/**
|
|
68
|
+
* 计划能省下的字符数:被替换正文长度减占位符长度,只算这次确实会改的那几条。
|
|
69
|
+
* 跟 {@link applyMicrocompactPlan} 用同一套命中条件(callId 在计划里且内容不同)。
|
|
70
|
+
*/
|
|
71
|
+
export declare function planFreeChars(messages: readonly ChatMessage[], plan: MicrocompactPlan): number;
|
|
72
|
+
/**
|
|
73
|
+
* 这份计划值不值得应用:省下的字符占整段提示词的百分比要达到门槛。
|
|
74
|
+
*
|
|
75
|
+
* 为什么要有这道门槛:前缀缓存里命中的 token 大约只按 1/10 价收,没命中的整段按全价
|
|
76
|
+
* 重读。清 1 个 token 只省下 1/10 的钱,可清理点一动、从那儿往后整段前缀作废,要按
|
|
77
|
+
* 全价重读一遍——省得少还不如不清。所以比例不够就先不动,等攒够一轮再说。
|
|
78
|
+
*
|
|
79
|
+
* @param minFreePercent - 门槛百分比(0–100);0 表示只要能省就应用。
|
|
80
|
+
*/
|
|
81
|
+
export declare function planWorthApplying(messages: readonly ChatMessage[], plan: MicrocompactPlan, minFreePercent: number): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* 这条 user 消息是不是「程序塞进来的」(环境快照 / 任务清单提醒 / 钩子产出 / 队友汇报),
|
|
84
|
+
* 不算用户新开的一轮。轮次键只数真人发言,否则同一轮里 env 快照一刷就被判成
|
|
85
|
+
* 新一轮,冻结计划又白做了。
|
|
86
|
+
*
|
|
87
|
+
* 队友汇报(`<teammate-report `)也算:它是子代理干完活后由程序投进来的,不是真人开口。
|
|
88
|
+
* 如果把它算成新一轮,队友每汇报一次就翻一轮,冻结计划重算、清理点跟着移动,等于每份
|
|
89
|
+
* 汇报都花一次整段前缀重读的钱——汇报越勤,前缀缓存越碎。
|
|
90
|
+
*/
|
|
91
|
+
export declare function isSyntheticUserMessage(message: ChatMessage): boolean;
|
|
92
|
+
/** 这次请求属于第几轮(真人 user 消息条数);同一轮内计划可以冻结复用。 */
|
|
93
|
+
export declare function roundKeyOf(messages: readonly ChatMessage[]): number;
|