@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/ui-events.d.ts
CHANGED
|
@@ -54,6 +54,16 @@ export interface UiEventsOptions {
|
|
|
54
54
|
/** 订阅变更帧;返回退订函数。 */
|
|
55
55
|
subscribe(listener: (frame: unknown) => void): () => void;
|
|
56
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* 旁问的增量帧(2026-10-25)。
|
|
59
|
+
*
|
|
60
|
+
* 与 plugins 同一套做法(新事件名、不进帧 hub、无 seq):旁问的增量是**瞬时**的,
|
|
61
|
+
* 断线时丢一段就丢一段,最终答案仍由 `sideAsk` 的返回值补齐——界面会用它覆盖整个答案。
|
|
62
|
+
*/
|
|
63
|
+
ask?: {
|
|
64
|
+
/** 订阅增量;返回退订函数。 */
|
|
65
|
+
subscribe(listener: (chunk: unknown) => void): () => void;
|
|
66
|
+
};
|
|
57
67
|
throttleMs?: number;
|
|
58
68
|
heartbeatMs?: number;
|
|
59
69
|
/** 同时最多几条 SSE,缺省 8。 */
|
package/lib/core/ui-events.js
CHANGED
|
@@ -213,6 +213,30 @@ export function createUiEvents(options) {
|
|
|
213
213
|
forget(res);
|
|
214
214
|
}
|
|
215
215
|
};
|
|
216
|
+
/** 旁问增量帧:与启动图同一套「不补帧」口径。 */
|
|
217
|
+
const writeAsk = (res, data) => {
|
|
218
|
+
if (res.writableEnded || res.destroyed) {
|
|
219
|
+
forget(res);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
writeEvent(res, 'ask', data);
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
forget(res);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
const unsubscribeAsk = options.ask?.subscribe((chunk) => {
|
|
230
|
+
let data;
|
|
231
|
+
try {
|
|
232
|
+
data = JSON.stringify(chunk);
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
for (const res of [...clients])
|
|
238
|
+
writeAsk(res, data);
|
|
239
|
+
});
|
|
216
240
|
const unsubscribePlugins = options.plugins?.subscribe((frame) => {
|
|
217
241
|
let data;
|
|
218
242
|
try {
|
|
@@ -344,6 +368,7 @@ export function createUiEvents(options) {
|
|
|
344
368
|
timer = null;
|
|
345
369
|
unsubscribe();
|
|
346
370
|
unsubscribePlugins?.();
|
|
371
|
+
unsubscribeAsk?.();
|
|
347
372
|
for (const res of [...clients]) {
|
|
348
373
|
try {
|
|
349
374
|
res.end();
|
package/lib/core/ui-methods.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** 界面通道放行的方法。 */
|
|
2
|
-
export declare const UI_METHODS: readonly ["submit", "interrupt", "editQueued", "removeQueued", "steerQueued", "compact", "openSession", "newSessionIn", "refreshSessions", "archiveSessions", "restoreSessions", "renameSession", "setSessionPinned", "listUserMessages", "forkSession", "listArchivedSessions", "usageStats", "peekTranscript", "setModel", "listModels", "setEffort", "setMode", "getModelConfig", "discoverModels", "testConnection", "setDefaultModel", "answerApproval", "answerQuestion", "answerPlan", "getUiPrefs", "setUiPrefs", "listPlugins", "setPluginEnabled", "listUiTrust", "listTools", "listSkills", "readSkill", "setSkillEnabled", "browseMarket", "listPresets", "readPreset", "usePreset", "savePreset", "removePreset", "setDefaultPreset", "listPermissionPresets", "getSettingsSections", "getSectionValues", "setSettingValue", "runSettingAction", "listTeammates", "stopTeammate", "messageTeammate", "removeTeammate", "stopBackground", "readBackground", "clearTodos", "goalAction", "listUiCommands", "runUiCommand", "dock"];
|
|
2
|
+
export declare const UI_METHODS: readonly ["submit", "interrupt", "editQueued", "removeQueued", "steerQueued", "compact", "openSession", "newSessionIn", "refreshSessions", "archiveSessions", "restoreSessions", "renameSession", "setSessionPinned", "listUserMessages", "forkSession", "rewindSession", "listArchivedSessions", "usageStats", "sideAsk", "sideAskCancel", "peekTranscript", "setModel", "listModels", "setEffort", "setMode", "getModelConfig", "discoverModels", "testConnection", "setDefaultModel", "answerApproval", "answerQuestion", "answerPlan", "getUiPrefs", "setUiPrefs", "listPlugins", "setPluginEnabled", "listUiTrust", "listTools", "listSkills", "readSkill", "setSkillEnabled", "browseMarket", "listPresets", "readPreset", "usePreset", "savePreset", "removePreset", "setDefaultPreset", "listPermissionPresets", "getSettingsSections", "getSectionValues", "setSettingValue", "runSettingAction", "listTeammates", "stopTeammate", "messageTeammate", "removeTeammate", "stopBackground", "readBackground", "clearTodos", "goalAction", "listUiCommands", "runUiCommand", "dock"];
|
|
3
3
|
/** 界面通道认得的方法名。 */
|
|
4
4
|
export type UiMethod = (typeof UI_METHODS)[number];
|
|
5
5
|
/** 明确排除、且逐条写了理由的方法(见文件头注释)。 */
|
package/lib/core/ui-methods.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { DOCK_UI_OPS } from './dock-ops.js';
|
|
2
|
+
import { SIDE_ASK_MAX_QUESTION, SIDE_ASK_MAX_QUOTE } from './side-ask.js';
|
|
3
|
+
import { jsonText } from './json-text.js';
|
|
2
4
|
/** 界面通道放行的方法。 */
|
|
3
5
|
export const UI_METHODS = [
|
|
4
6
|
// 对话与回合
|
|
@@ -18,8 +20,12 @@ export const UI_METHODS = [
|
|
|
18
20
|
'setSessionPinned',
|
|
19
21
|
'listUserMessages',
|
|
20
22
|
'forkSession',
|
|
23
|
+
'rewindSession',
|
|
21
24
|
'listArchivedSessions',
|
|
22
25
|
'usageStats',
|
|
26
|
+
// 旁问(只读一次性问答):不建会话、不落盘、不带工具,见 core/side-ask.ts。
|
|
27
|
+
'sideAsk',
|
|
28
|
+
'sideAskCancel',
|
|
23
29
|
'peekTranscript',
|
|
24
30
|
// 模型与档位
|
|
25
31
|
'setModel',
|
|
@@ -119,13 +125,20 @@ const MAX_PATH = 4096;
|
|
|
119
125
|
const MAX_NAME = 200;
|
|
120
126
|
/** 用户消息 / 提问回答的上限(请求体本身另有 64KB 上限,见 core/web-http.ts)。 */
|
|
121
127
|
const MAX_TEXT = 32000;
|
|
122
|
-
/**
|
|
128
|
+
/**
|
|
129
|
+
* 图片元素的上限:正常情况这里是一个短引用(`/api/attachments/<sha>?name=…`,约 120 字节),
|
|
130
|
+
* 老调用点仍可能给 data URL。32KB 是给后者留的兼容位——请求体本身另有 64KB 上限,
|
|
131
|
+
* 新链路(先上传、再发引用)根本不碰这个数。
|
|
132
|
+
*/
|
|
123
133
|
const MAX_IMAGE = 32000;
|
|
124
|
-
|
|
134
|
+
/** 一条消息最多几张图(与 `core/attachments.ts` 的 `MAX_IMAGES_PER_MESSAGE` 同值)。 */
|
|
135
|
+
const MAX_IMAGES = 20;
|
|
125
136
|
/** 一批会话路径的条数上限(归档 / 恢复)。 */
|
|
126
137
|
const MAX_PATHS = 500;
|
|
127
138
|
/** 偏好 / 设置值 / 预设草稿这类 JSON 实参的上限(按序列化后的文本长度算)。 */
|
|
128
139
|
const MAX_PREF_JSON = 32000;
|
|
140
|
+
/** 取消票据(旁问 requestId)的长度上限:它是壳自己发的 uuid,不需要更长。 */
|
|
141
|
+
const MAX_TICKET = 64;
|
|
129
142
|
/** 枚举取值直接绑到契约的类型上:契约改了而这里没跟上,编译期就报错。 */
|
|
130
143
|
const EFFORT_LEVELS = ['default', 'off', 'low', 'high', 'max'];
|
|
131
144
|
const MODES = ['build', 'plan', 'explore', 'quiet'];
|
|
@@ -141,7 +154,12 @@ const GOAL_ACTIONS = ['pause', 'resume', 'clear', 'extend'];
|
|
|
141
154
|
*/
|
|
142
155
|
export const UI_ARG_SPECS = {
|
|
143
156
|
// ── 对话与回合 ─────────────────────────────────────────────────────────────
|
|
144
|
-
|
|
157
|
+
// 第二参是图片引用(老的 data URL 也收),第三参是视频 / 通用文件的落盘元数据。
|
|
158
|
+
submit: [
|
|
159
|
+
{ shape: { kind: 'string', max: MAX_TEXT } },
|
|
160
|
+
{ shape: { kind: 'strings', maxItems: MAX_IMAGES, max: MAX_IMAGE }, optional: true },
|
|
161
|
+
{ shape: { kind: 'json', maxBytes: MAX_PREF_JSON }, optional: true },
|
|
162
|
+
],
|
|
145
163
|
interrupt: [{ shape: { kind: 'string', max: MAX_PATH }, optional: true }],
|
|
146
164
|
editQueued: [{ shape: { kind: 'number' } }, { shape: { kind: 'string', max: MAX_TEXT } }],
|
|
147
165
|
removeQueued: [{ shape: { kind: 'number' } }],
|
|
@@ -161,13 +179,33 @@ export const UI_ARG_SPECS = {
|
|
|
161
179
|
setSessionPinned: [{ shape: { kind: 'string', max: MAX_PATH } }, { shape: { kind: 'boolean' } }],
|
|
162
180
|
listUserMessages: [{ shape: { kind: 'string', max: MAX_PATH } }],
|
|
163
181
|
forkSession: [{ shape: { kind: 'string', max: MAX_PATH } }, { shape: { kind: 'number' } }],
|
|
182
|
+
rewindSession: [
|
|
183
|
+
{ shape: { kind: 'string', max: MAX_PATH } },
|
|
184
|
+
{ shape: { kind: 'number' } },
|
|
185
|
+
{ shape: { kind: 'string', max: MAX_NAME }, optional: true },
|
|
186
|
+
],
|
|
164
187
|
listArchivedSessions: [],
|
|
165
188
|
usageStats: [],
|
|
189
|
+
// 旁问:问题 + 可选引用 + 取消票据。上限与 core/side-ask.ts 的常量对齐(那边截断引用、
|
|
190
|
+
// 这边拒超长问题)——两处都写死数字会漂,所以这边直接引用同一组常量。
|
|
191
|
+
sideAsk: [
|
|
192
|
+
{ shape: { kind: 'string', max: SIDE_ASK_MAX_QUESTION } },
|
|
193
|
+
{ shape: { kind: 'string', max: SIDE_ASK_MAX_QUOTE } },
|
|
194
|
+
{ shape: { kind: 'string', max: MAX_TICKET } },
|
|
195
|
+
// 空串 = 跟随主会话当前路由;都填了才用指定模型(见 runtime 的路由挑选)。
|
|
196
|
+
{ shape: { kind: 'string', max: MAX_NAME } },
|
|
197
|
+
{ shape: { kind: 'string', max: MAX_NAME } },
|
|
198
|
+
],
|
|
199
|
+
sideAskCancel: [{ shape: { kind: 'string', max: MAX_TICKET } }],
|
|
166
200
|
peekTranscript: [{ shape: { kind: 'string', max: MAX_PATH } }],
|
|
167
201
|
// ── 模型与档位 ────────────────────────────────────────────────────────────
|
|
168
202
|
setModel: [{ shape: { kind: 'string', max: MAX_NAME } }],
|
|
169
203
|
listModels: [],
|
|
170
|
-
|
|
204
|
+
// 第二个实参 quiet:输入区滑杆调档时不往对话里写那一行(见 services/types.ts 的说明)。
|
|
205
|
+
setEffort: [
|
|
206
|
+
{ shape: { kind: 'enum', values: EFFORT_LEVELS } },
|
|
207
|
+
{ shape: { kind: 'boolean' }, optional: true },
|
|
208
|
+
],
|
|
171
209
|
setMode: [{ shape: { kind: 'enum', values: MODES } }],
|
|
172
210
|
getModelConfig: [],
|
|
173
211
|
discoverModels: [{ shape: { kind: 'string', max: MAX_NAME } }],
|
|
@@ -330,12 +368,3 @@ function checkShape(shape, value) {
|
|
|
330
368
|
}
|
|
331
369
|
}
|
|
332
370
|
}
|
|
333
|
-
/** 一段 JSON 文本;序列化不了(循环引用、BigInt、函数)给 null。 */
|
|
334
|
-
function jsonText(value) {
|
|
335
|
-
try {
|
|
336
|
-
return JSON.stringify(value) ?? null;
|
|
337
|
-
}
|
|
338
|
-
catch {
|
|
339
|
-
return null;
|
|
340
|
-
}
|
|
341
|
-
}
|
package/lib/core/ui-route.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { lookupUiPluginBundle, lookupThirdPartyUiBundle, uiPluginsDir } from './ui-bundles.js';
|
|
1
|
+
import { lookupPackageUiBundle, lookupUiPluginBundle, lookupThirdPartyUiBundle, uiPluginsDir } from './ui-bundles.js';
|
|
2
|
+
import { activeProfileDir } from './profile-dir.js';
|
|
2
3
|
/** 插件资源的路由前缀。 */
|
|
3
4
|
export const UI_BUNDLE_ROUTE = '/plugins/';
|
|
4
5
|
/** 内容寻址的命中给一年不可变缓存(地址里带内容指纹,同一地址的内容永不改变)。 */
|
|
@@ -41,19 +42,22 @@ export function resolveUiBundleRequest(pathname, rev, dir = uiPluginsDir(), meth
|
|
|
41
42
|
const wantBody = method !== 'HEAD';
|
|
42
43
|
const found = lookupUiPluginBundle(id, file, rev, dir, wantBody);
|
|
43
44
|
if (!found.known) {
|
|
44
|
-
// 内置清单里没有 → 查第三方(~/.dsc/plugins/
|
|
45
|
+
// 内置清单里没有 → 查第三方(~/.dsc/plugins/ 的界面半边),再查组合包(profile 里装的包)。
|
|
46
|
+
// 三处同一份回话口径。
|
|
45
47
|
const third = lookupThirdPartyUiBundle(id, file, rev, undefined, wantBody);
|
|
46
|
-
|
|
48
|
+
const fromPackage = third.known ? third : lookupPackageUiBundle(id, file, rev, activeProfileDir(), wantBody);
|
|
49
|
+
const resolved = fromPackage;
|
|
50
|
+
if (resolved.known && (resolved.current || resolved.previous)) {
|
|
47
51
|
const headers = {
|
|
48
52
|
'content-type': 'text/javascript; charset=utf-8',
|
|
49
|
-
'content-length': String(
|
|
53
|
+
'content-length': String(resolved.size ?? 0),
|
|
50
54
|
'cache-control': IMMUTABLE_CACHE,
|
|
51
55
|
};
|
|
52
|
-
if (!wantBody ||
|
|
56
|
+
if (!wantBody || resolved.body === null)
|
|
53
57
|
return { status: 200, headers };
|
|
54
|
-
return { status: 200, headers, body:
|
|
58
|
+
return { status: 200, headers, body: resolved.body };
|
|
55
59
|
}
|
|
56
|
-
return { status: 404, reason:
|
|
60
|
+
return { status: 404, reason: resolved.known ? '插件版本对不上' : '没有这个插件' };
|
|
57
61
|
}
|
|
58
62
|
if (!found.current && !found.previous)
|
|
59
63
|
return { status: 404, reason: '插件版本对不上' };
|
package/lib/core/ui-server.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { UiBootGraph } from '../ui/manifest.js';
|
|
2
|
+
import { type AttachmentStore } from './attachments.js';
|
|
2
3
|
import { type UiBootRequestStats, type UiBootWatchRow } from './ui-boot-source.js';
|
|
3
4
|
import type { UiEventsHandle } from './ui-events.js';
|
|
4
5
|
/** 会话 Cookie 名。 */
|
|
@@ -25,6 +26,11 @@ export interface UiServerOptions {
|
|
|
25
26
|
* 单元测试与「只发页面不带数据」的场景都用得着。
|
|
26
27
|
*/
|
|
27
28
|
events?: UiEventsHandle;
|
|
29
|
+
/**
|
|
30
|
+
* 附件仓库(`/api/attachments` 两路由)。不给就没有上传与读取能力——
|
|
31
|
+
* 单元测试与「只发页面不带数据」的场景用不着。
|
|
32
|
+
*/
|
|
33
|
+
attachments?: AttachmentStore;
|
|
28
34
|
/** 监听端口,0 = 让系统分配(缺省 0)。 */
|
|
29
35
|
port?: number;
|
|
30
36
|
/** 一次性令牌有效期,缺省 10 分钟。 */
|
package/lib/core/ui-server.js
CHANGED
|
@@ -40,11 +40,13 @@
|
|
|
40
40
|
* @module dsc/core/ui-server
|
|
41
41
|
*/
|
|
42
42
|
import { randomBytes } from 'node:crypto';
|
|
43
|
-
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
43
|
+
import { createReadStream, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
44
44
|
import { createServer } from 'node:http';
|
|
45
45
|
import { dirname } from 'node:path';
|
|
46
|
+
import { AttachmentError } from './attachments.js';
|
|
46
47
|
import { createUiBootSource } from './ui-boot-source.js';
|
|
47
48
|
import { dscPath } from './path-policy.js';
|
|
49
|
+
import { activeProfileDir } from './profile-dir.js';
|
|
48
50
|
import { uiAssetsDir, uiPluginsDir } from './ui-bundles.js';
|
|
49
51
|
import { isUiBundleRequest, isUiComboRequest, resolveUiResourceRequest } from './ui-route.js';
|
|
50
52
|
import { checkUiRequestTrust, issueUiCookie, requestAuthority, timingSafeEqualText, verifyUiCookie } from './ui-trust.js';
|
|
@@ -122,6 +124,68 @@ function loadUiSigningKey(log) {
|
|
|
122
124
|
return key;
|
|
123
125
|
}
|
|
124
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* 解析 `Range: bytes=…`(只认单段)。
|
|
129
|
+
*
|
|
130
|
+
* 视频拖动进度条要靠它:浏览器会先发 `Range: bytes=0-`,再按需取后面的段。
|
|
131
|
+
* 头部形状不对、范围越界、`start > end` 一律当「没有 Range」——退回整段 200,
|
|
132
|
+
* 比回 416 更不容易把播放器卡死。
|
|
133
|
+
*/
|
|
134
|
+
function parseRange(header, size) {
|
|
135
|
+
if (header === undefined)
|
|
136
|
+
return null;
|
|
137
|
+
const match = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
|
|
138
|
+
if (match === null)
|
|
139
|
+
return null;
|
|
140
|
+
const startText = match[1] ?? '';
|
|
141
|
+
const endText = match[2] ?? '';
|
|
142
|
+
let start;
|
|
143
|
+
let end;
|
|
144
|
+
if (startText === '') {
|
|
145
|
+
const suffix = Number(endText);
|
|
146
|
+
if (!Number.isFinite(suffix) || suffix <= 0)
|
|
147
|
+
return null;
|
|
148
|
+
start = Math.max(0, size - suffix);
|
|
149
|
+
end = size - 1;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
start = Number(startText);
|
|
153
|
+
end = endText === '' ? size - 1 : Math.min(Number(endText), size - 1);
|
|
154
|
+
}
|
|
155
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || start > end || start >= size)
|
|
156
|
+
return null;
|
|
157
|
+
return { start, end };
|
|
158
|
+
}
|
|
159
|
+
/** 把仓库里的一段字节流出去(Range 命中回 206,否则 200)。 */
|
|
160
|
+
function sendAttachment(res, path, mime, size, range, headOnly) {
|
|
161
|
+
const base = {
|
|
162
|
+
'content-type': mime,
|
|
163
|
+
'cache-control': 'private, max-age=31536000, immutable',
|
|
164
|
+
'accept-ranges': 'bytes',
|
|
165
|
+
'content-disposition': 'inline',
|
|
166
|
+
'x-content-type-options': 'nosniff',
|
|
167
|
+
};
|
|
168
|
+
const span = parseRange(range, size);
|
|
169
|
+
if (span === null) {
|
|
170
|
+
res.writeHead(200, { ...base, 'content-length': String(size) });
|
|
171
|
+
if (headOnly) {
|
|
172
|
+
res.end();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
createReadStream(path).on('error', () => res.destroy()).pipe(res);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
res.writeHead(206, {
|
|
179
|
+
...base,
|
|
180
|
+
'content-length': String(span.end - span.start + 1),
|
|
181
|
+
'content-range': `bytes ${String(span.start)}-${String(span.end)}/${String(size)}`,
|
|
182
|
+
});
|
|
183
|
+
if (headOnly) {
|
|
184
|
+
res.end();
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
createReadStream(path, { start: span.start, end: span.end }).on('error', () => res.destroy()).pipe(res);
|
|
188
|
+
}
|
|
125
189
|
/** 把 bundle 解析结果写出去:200 给头(与体),其余给状态码 + 理由 + Allow 之类的头。 */
|
|
126
190
|
function sendBundleResponse(res, resolved) {
|
|
127
191
|
if (resolved.status === 200) {
|
|
@@ -166,6 +230,7 @@ export async function createUiServer(options) {
|
|
|
166
230
|
const assetsDir = options.assetsDir ?? uiAssetsDir();
|
|
167
231
|
const pluginsDir = options.pluginsDir ?? uiPluginsDir();
|
|
168
232
|
const events = options.events ?? null;
|
|
233
|
+
const attachments = options.attachments ?? null;
|
|
169
234
|
const log = options.log ?? ((line) => { process.stderr.write(`${line}\n`); });
|
|
170
235
|
const ttl = options.tokenTtlMs ?? DEFAULT_TOKEN_TTL_MS;
|
|
171
236
|
// 一次性令牌:换到 Cookie 就作废;过期也作废。比对用定长时间(时序侧信道)。
|
|
@@ -178,6 +243,8 @@ export async function createUiServer(options) {
|
|
|
178
243
|
const source = createUiBootSource({
|
|
179
244
|
host: options.host,
|
|
180
245
|
builtinDir: pluginsDir,
|
|
246
|
+
// 组合包的界面半也进启动图(profile 没配就是 null,什么也不多收)。
|
|
247
|
+
packageDir: activeProfileDir(),
|
|
181
248
|
});
|
|
182
249
|
const manifest = source.artifacts().entries;
|
|
183
250
|
/**
|
|
@@ -250,6 +317,44 @@ export async function createUiServer(options) {
|
|
|
250
317
|
res.end(UNAUTHORIZED_HTML);
|
|
251
318
|
return;
|
|
252
319
|
}
|
|
320
|
+
// 附件:上传走裸字节 POST(不受 64KB JSON 上限约束),读取走同源 GET。
|
|
321
|
+
// 鉴权就在上面那道 Cookie 闸——这里不再重复判,也不认任何查询参数里的凭据。
|
|
322
|
+
if (attachments !== null && url.pathname === '/api/attachments') {
|
|
323
|
+
if (method !== 'POST') {
|
|
324
|
+
sendText(res, 405, '上传只认 POST');
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const name = url.searchParams.get('name') ?? '';
|
|
328
|
+
try {
|
|
329
|
+
const meta = await attachments.saveStream(req, name);
|
|
330
|
+
sendJson(res, 200, { ok: true, attachment: meta });
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
334
|
+
// 上限类错误是客户端问题(413),其余(空文件、写盘失败)分开回。
|
|
335
|
+
const status = error instanceof AttachmentError && message.includes('上限') ? 413 : error instanceof AttachmentError ? 400 : 500;
|
|
336
|
+
sendJson(res, status, { ok: false, error: message });
|
|
337
|
+
}
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (attachments !== null && url.pathname.startsWith('/api/attachments/')) {
|
|
341
|
+
if (method !== 'GET' && method !== 'HEAD') {
|
|
342
|
+
sendText(res, 405, '附件只认 GET 与 HEAD');
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
const sha = url.pathname.slice('/api/attachments/'.length);
|
|
346
|
+
if (!/^[0-9a-f]{64}$/.test(sha)) {
|
|
347
|
+
sendText(res, 404, '没有这个附件');
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
const info = await attachments.mimeOf(sha);
|
|
351
|
+
if (info === null) {
|
|
352
|
+
sendText(res, 404, '没有这个附件');
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
sendAttachment(res, attachments.pathOf(sha), info.mime, info.size, req.headers.range, method === 'HEAD');
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
253
358
|
// 插件 bundle:内容寻址 + 批 combo;HEAD 复用 GET 的头,非 GET/HEAD 405。
|
|
254
359
|
// 解析口径与远程控制共用 core/ui-route.ts 那一份;combo 只认快照里登记过的精确地址。
|
|
255
360
|
if (isUiBundleRequest(url.pathname)) {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* git unified diff 文本 → 结构化 hunk(全仓唯一一份解析)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么会有一份「渲染用」的解析:dock 通道的 `git-diff` 回的是 diff 文本,
|
|
5
|
+
* 而审查面板与差异区只认结构化 hunk,这一层补上缺口。算法原先只长在旧渲染层
|
|
6
|
+
* (`desktop/src/renderer/unified-diff.ts`),界面壳又照它逐字搬了一份——两份
|
|
7
|
+
* 各自「以实际行数为准」的容错写在同一段注释里,改一处忘另一处就会表现成
|
|
8
|
+
* 「同一段 diff 在两个界面里行数不一样」。
|
|
9
|
+
*
|
|
10
|
+
* 现在实现只有这一份,两边的入口都只是转出:
|
|
11
|
+
* `@dsc/ui` → `@dsc/ui-primitives`(界面壳与插件),`@dsc/runtime/core/unified-diff.js`
|
|
12
|
+
* (旧渲染层,等它整体退役)。
|
|
13
|
+
*
|
|
14
|
+
* 只做渲染用解析:对不认识的行跳过、hunk 计数以实际行数为准(git 在文件末尾没换行等
|
|
15
|
+
* 场景下 `@@` 头的计数与实际行会差一),解析失败宁可少一段也不抛错。
|
|
16
|
+
*
|
|
17
|
+
* 零运行期依赖(只有 `import type`):`scripts/review-approval-test.mjs` 按 Node 的
|
|
18
|
+
* 类型擦除直读本文件逐条钉。
|
|
19
|
+
*
|
|
20
|
+
* @module dsc/core/unified-diff
|
|
21
|
+
*/
|
|
22
|
+
import type { DiffHunkView, DiffLineView } from '../contract.js';
|
|
23
|
+
export type { DiffHunkView, DiffLineView };
|
|
24
|
+
/** 从单文件(或全量)的 unified diff 文本解析出全部 hunk;没有 hunk 就给空数组。 */
|
|
25
|
+
export declare function parseUnifiedDiff(text: string): DiffHunkView[];
|
|
26
|
+
/** 全量 git diff 按文件切段后的每一段:git 相对路径 + 该文件的 hunk。 */
|
|
27
|
+
export interface UnifiedFileDiff {
|
|
28
|
+
/** git 报出的相对仓库根路径(`b/` 侧;rename 时也是新路径)。 */
|
|
29
|
+
path: string;
|
|
30
|
+
added: number;
|
|
31
|
+
removed: number;
|
|
32
|
+
hunks: DiffHunkView[];
|
|
33
|
+
}
|
|
34
|
+
/** 把全量 git diff 文本按 `diff --git` 行切成每文件一段;没有 diff 体(全是 clean)就给空数组。 */
|
|
35
|
+
export declare function splitUnifiedDiffByFile(text: string): UnifiedFileDiff[];
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const HUNK_HEAD = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
|
|
2
|
+
/** 从单文件(或全量)的 unified diff 文本解析出全部 hunk;没有 hunk 就给空数组。 */
|
|
3
|
+
export function parseUnifiedDiff(text) {
|
|
4
|
+
const hunks = [];
|
|
5
|
+
const lines = text.split(/\r?\n/);
|
|
6
|
+
let at = 0;
|
|
7
|
+
while (at < lines.length) {
|
|
8
|
+
const head = (lines[at] ?? '').match(HUNK_HEAD);
|
|
9
|
+
if (head === null) {
|
|
10
|
+
at += 1;
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
at += 1;
|
|
14
|
+
const rows = [];
|
|
15
|
+
let oldLine = Number(head[1]);
|
|
16
|
+
let newLine = Number(head[3]);
|
|
17
|
+
while (at < lines.length) {
|
|
18
|
+
const line = lines[at] ?? '';
|
|
19
|
+
if (HUNK_HEAD.test(line))
|
|
20
|
+
break;
|
|
21
|
+
const tag = line.charAt(0);
|
|
22
|
+
if (tag === '\\') {
|
|
23
|
+
// 「」:标注行,不进差异正文
|
|
24
|
+
at += 1;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (tag === ' ') {
|
|
28
|
+
rows.push({ kind: 'context', text: line.slice(1), oldLine, newLine });
|
|
29
|
+
oldLine += 1;
|
|
30
|
+
newLine += 1;
|
|
31
|
+
}
|
|
32
|
+
else if (tag === '-') {
|
|
33
|
+
rows.push({ kind: 'remove', text: line.slice(1), oldLine, newLine: null });
|
|
34
|
+
oldLine += 1;
|
|
35
|
+
}
|
|
36
|
+
else if (tag === '+') {
|
|
37
|
+
rows.push({ kind: 'add', text: line.slice(1), oldLine: null, newLine });
|
|
38
|
+
newLine += 1;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// `diff --git` / `index` / `---` / `+++` / 空行等:hunk 结束
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
at += 1;
|
|
45
|
+
}
|
|
46
|
+
if (rows.length > 0) {
|
|
47
|
+
hunks.push({
|
|
48
|
+
oldStart: Number(head[1]),
|
|
49
|
+
oldCount: rows.reduce((sum, row) => sum + (row.kind === 'add' ? 0 : 1), 0),
|
|
50
|
+
newStart: Number(head[3]),
|
|
51
|
+
newCount: rows.reduce((sum, row) => sum + (row.kind === 'remove' ? 0 : 1), 0),
|
|
52
|
+
lines: rows,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return hunks;
|
|
57
|
+
}
|
|
58
|
+
/** 把全量 git diff 文本按 `diff --git` 行切成每文件一段;没有 diff 体(全是 clean)就给空数组。 */
|
|
59
|
+
export function splitUnifiedDiffByFile(text) {
|
|
60
|
+
const files = [];
|
|
61
|
+
const chunks = text.split(/^diff --git /m).filter((chunk) => chunk.trim() !== '');
|
|
62
|
+
for (const chunk of chunks) {
|
|
63
|
+
const firstLineEnd = chunk.indexOf('\n');
|
|
64
|
+
const first = firstLineEnd < 0 ? chunk : chunk.slice(0, firstLineEnd);
|
|
65
|
+
// 首行形如 `a/src/x.ts b/src/x.ts`:取 `b/` 侧(rename 时它也是新路径)
|
|
66
|
+
const nameMatch = first.match(/^a\/(.*) b\/(.*)$/);
|
|
67
|
+
const path = (nameMatch !== null ? nameMatch[2] : first).trim();
|
|
68
|
+
if (path === '')
|
|
69
|
+
continue;
|
|
70
|
+
const hunks = parseUnifiedDiff(chunk);
|
|
71
|
+
if (hunks.length === 0)
|
|
72
|
+
continue;
|
|
73
|
+
let added = 0;
|
|
74
|
+
let removed = 0;
|
|
75
|
+
for (const hunk of hunks) {
|
|
76
|
+
for (const row of hunk.lines) {
|
|
77
|
+
if (row.kind === 'add')
|
|
78
|
+
added += 1;
|
|
79
|
+
else if (row.kind === 'remove')
|
|
80
|
+
removed += 1;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
files.push({ path, added, removed, hunks });
|
|
84
|
+
}
|
|
85
|
+
return files;
|
|
86
|
+
}
|
package/lib/core/usage-log.js
CHANGED
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
* @module dsc/core/usage-log
|
|
18
18
|
*/
|
|
19
19
|
import { appendFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs';
|
|
20
|
+
// 计价口径与 TUI 的「本会话花费」同一份(core/pricing.ts):逐笔按发生时刻分峰谷、
|
|
21
|
+
// 缓存命中与未命中分开算,不在这里另写一套乘法。
|
|
22
|
+
import { addUsageToBuckets, emptyCostBuckets, estimateSessionCostCny, isDeepseekProvider, isPeakHour } from './pricing.js';
|
|
20
23
|
import { dscPath } from './path-policy.js';
|
|
21
24
|
/** 用量日志的绝对路径(宿主写、壳进程读,两边都从这里取,绝不各拼一份)。 */
|
|
22
25
|
export function usageLogFile() {
|
|
@@ -94,6 +97,8 @@ const MAX_SPAN_DAYS = 370;
|
|
|
94
97
|
export function aggregateUsage(records) {
|
|
95
98
|
const days = new Map();
|
|
96
99
|
const models = new Map();
|
|
100
|
+
// 逐日逐模型的峰谷分桶:只装能计价的记录(DeepSeek 端点),零日与别家端点不进表。
|
|
101
|
+
const dayBuckets = new Map();
|
|
97
102
|
let totalInput = 0;
|
|
98
103
|
let totalOutput = 0;
|
|
99
104
|
let totalTurns = 0;
|
|
@@ -120,6 +125,26 @@ export function aggregateUsage(records) {
|
|
|
120
125
|
totalCacheMiss += record.cm ?? 0;
|
|
121
126
|
if (sinceTs === null || record.t < sinceTs)
|
|
122
127
|
sinceTs = record.t;
|
|
128
|
+
if (isDeepseekProvider(record.provider)) {
|
|
129
|
+
let byModel = dayBuckets.get(key);
|
|
130
|
+
if (byModel === undefined) {
|
|
131
|
+
byModel = new Map();
|
|
132
|
+
dayBuckets.set(key, byModel);
|
|
133
|
+
}
|
|
134
|
+
let bucket = byModel.get(record.model);
|
|
135
|
+
if (bucket === undefined) {
|
|
136
|
+
bucket = emptyCostBuckets();
|
|
137
|
+
byModel.set(record.model, bucket);
|
|
138
|
+
}
|
|
139
|
+
// 峰谷按**那一笔发生时刻**判(北京时间工作日 9-12 / 14-18 为峰),与 TUI 花费同口径。
|
|
140
|
+
// 字段名从压短的那套(i/o/ch/cm)换成计价函数要的长名,不在这里重排内存布局。
|
|
141
|
+
addUsageToBuckets(bucket, {
|
|
142
|
+
inputTokens: record.i,
|
|
143
|
+
outputTokens: record.o,
|
|
144
|
+
...(record.ch === undefined ? {} : { cacheHitTokens: record.ch }),
|
|
145
|
+
...(record.cm === undefined ? {} : { cacheMissTokens: record.cm }),
|
|
146
|
+
}, isPeakHour(new Date(record.t)));
|
|
147
|
+
}
|
|
123
148
|
let model = models.get(modelKey);
|
|
124
149
|
if (model === undefined) {
|
|
125
150
|
model = { key: modelKey, inputTokens: 0, outputTokens: 0, turns: 0, cacheHitTokens: 0, cacheMissTokens: 0 };
|
|
@@ -176,7 +201,21 @@ export function aggregateUsage(records) {
|
|
|
176
201
|
if (tokens > peakTokens)
|
|
177
202
|
peakDay = day;
|
|
178
203
|
}
|
|
204
|
+
// 逐日花费:把当天的峰谷分桶交给 pricing 的估算函数(元,未取整),算不出来的日子不写字段。
|
|
205
|
+
// 合计用「逐日相加」而不是重算一份:两者口径一致,且避免给零日编出一个 0 元。
|
|
206
|
+
let totalCostCny;
|
|
207
|
+
for (const day of filled) {
|
|
208
|
+
const byModel = dayBuckets.get(day.date);
|
|
209
|
+
if (byModel === undefined)
|
|
210
|
+
continue;
|
|
211
|
+
const priced = estimateSessionCostCny([...byModel.entries()].map(([model, buckets]) => ({ model, buckets })));
|
|
212
|
+
if (priced === undefined)
|
|
213
|
+
continue;
|
|
214
|
+
day.costCny = priced.total;
|
|
215
|
+
totalCostCny = (totalCostCny ?? 0) + priced.total;
|
|
216
|
+
}
|
|
179
217
|
return {
|
|
218
|
+
...(totalCostCny === undefined ? {} : { totalCostCny }),
|
|
180
219
|
sinceTs,
|
|
181
220
|
totalInputTokens: totalInput,
|
|
182
221
|
totalOutputTokens: totalOutput,
|
package/lib/core/web-http.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
|
15
15
|
export declare const MAX_BODY_BYTES: number;
|
|
16
16
|
/** 解析 lastSeq 查询参数:缺省、非数字、负数、0 一律 0(= 要全量)。 */
|
|
17
17
|
export declare function readLastSeq(raw: string | null): number;
|
|
18
|
-
export
|
|
18
|
+
export { isRecord } from './records.js';
|
|
19
19
|
/**
|
|
20
20
|
* 读请求体的原始字节。
|
|
21
21
|
*
|
package/lib/core/web-http.js
CHANGED
|
@@ -10,9 +10,7 @@ export function readLastSeq(raw) {
|
|
|
10
10
|
return 0;
|
|
11
11
|
return Math.trunc(value);
|
|
12
12
|
}
|
|
13
|
-
export
|
|
14
|
-
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
15
|
-
}
|
|
13
|
+
export { isRecord } from './records.js';
|
|
16
14
|
/**
|
|
17
15
|
* 读请求体的原始字节。
|
|
18
16
|
*
|