@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/session.js
CHANGED
|
@@ -14,6 +14,49 @@ import { summarizeChange } from './tools/fs-tools.js';
|
|
|
14
14
|
import { dropSessionMeta, patchSessionMeta, readSessionMeta } from './session-meta.js';
|
|
15
15
|
import { acquireLock, withExclusiveLock } from './lockfile.js';
|
|
16
16
|
import { dscPath } from './path-policy.js';
|
|
17
|
+
import { fileHandleText, parseAttachmentUrl, resolveImageForRequest } from './attachments.js';
|
|
18
|
+
import { REVIEW_FINDINGS_OPEN, TEAMMATE_REPORT_OPEN } from './team-board.js';
|
|
19
|
+
/**
|
|
20
|
+
* 组装一条用户消息的协议形态。
|
|
21
|
+
*
|
|
22
|
+
* 图片引用在这里读成 data URL(老会话的 data URL 原样过),视频 / 文件则把「路径 + 元数据」
|
|
23
|
+
* 拼进正文——模型侧没有文件内容块,给它一个可读、可复现的句柄才是 dsh 对非图片附件的做法。
|
|
24
|
+
* 只在这一处拼:实时写入与历史重放走同一个函数,两条路不会漂。
|
|
25
|
+
*
|
|
26
|
+
* 附件对象被删掉(用户手清 `~/.dsc/attachments`、换机器拷会话)不能让整个会话打不开:
|
|
27
|
+
* 读不出来的那张图换成一行「图片已丢失」的说明,其余照常重放——与 dsh「历史读取失败
|
|
28
|
+
* 以错误呈现、而不是给错误字节」同一个方向,代价更小。
|
|
29
|
+
*/
|
|
30
|
+
function userContent(text, images, files) {
|
|
31
|
+
const handle = files === undefined || files.length === 0 ? '' : fileHandleText(files);
|
|
32
|
+
const parts = [];
|
|
33
|
+
const missing = [];
|
|
34
|
+
const push = (url) => {
|
|
35
|
+
try {
|
|
36
|
+
parts.push({ type: 'image_url', image_url: { url: resolveImageForRequest(url) } });
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
missing.push((parseAttachmentUrl(url) ?? url).slice(0, 12));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
if (images !== undefined)
|
|
43
|
+
for (const url of images)
|
|
44
|
+
push(url);
|
|
45
|
+
// 视频关键帧跟着视频一起进这一次请求:模型看得到画面,日志只记引用,界面只画视频卡。
|
|
46
|
+
if (files !== undefined) {
|
|
47
|
+
for (const file of files) {
|
|
48
|
+
if (file.frames === undefined)
|
|
49
|
+
continue;
|
|
50
|
+
for (const frame of file.frames)
|
|
51
|
+
push(frame);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const lost = missing.length === 0 ? '' : `\n\n[图片已丢失:${missing.join('、')}]`;
|
|
55
|
+
const body = `${handle === '' ? text : `${text}\n\n${handle}`}${lost}`;
|
|
56
|
+
if (parts.length === 0)
|
|
57
|
+
return body;
|
|
58
|
+
return [{ type: 'text', text: body }, ...parts];
|
|
59
|
+
}
|
|
17
60
|
/**
|
|
18
61
|
* 用户拒绝某次工具调用时,写进那条工具结果的固定回执文案(由 loop 的拒绝分支产出)。
|
|
19
62
|
* 2026-02 之前的日志没有单独记 `error` 字段,{@link Session.load} 靠这句话把
|
|
@@ -130,6 +173,47 @@ function commonDirectory(paths) {
|
|
|
130
173
|
}
|
|
131
174
|
return candidate;
|
|
132
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* 这条用户消息是不是「人打的」。
|
|
178
|
+
*
|
|
179
|
+
* 三类不算:机器投递的唤醒(`origin: 'notice'`,2026-11-02)、队友汇报与审查结论
|
|
180
|
+
* (正文以 `<teammate-report ` / `<review-findings ` 开头,见 `core/team-board.ts`)。
|
|
181
|
+
*
|
|
182
|
+
* 为什么存储层要认这三类:界面上它们画成一行触发行 / 一张结论卡,**不开一轮对话**;
|
|
183
|
+
* 「编辑并重发」把「界面上第几轮」换算成消息下标时,两边必须是同一套判据,否则会
|
|
184
|
+
* 截到错的位置(少算=没截干净,多算=把还在用的历史截掉)。
|
|
185
|
+
*/
|
|
186
|
+
function isHumanUserMessage(message) {
|
|
187
|
+
if (message.role !== 'user')
|
|
188
|
+
return false;
|
|
189
|
+
if (message.origin === 'notice')
|
|
190
|
+
return false;
|
|
191
|
+
const text = typeof message.content === 'string'
|
|
192
|
+
? message.content
|
|
193
|
+
: (message.content?.find((part) => part.type === 'text')?.text ?? '');
|
|
194
|
+
return !text.startsWith(TEAMMATE_REPORT_OPEN) && !text.startsWith(REVIEW_FINDINGS_OPEN);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* 「第 keep 条**人打的**用户消息」在消息数组里的下标(0 基);没有这一条返回 -1。
|
|
198
|
+
*
|
|
199
|
+
* 为什么只数人打的:机器投递的通知与队友汇报在界面上都是一行触发行,不开一轮对话;
|
|
200
|
+
* 把界面上的「第几轮」换算成消息下标时,两种口径必须一致(判据见
|
|
201
|
+
* {@link isHumanUserMessage},界面对应 `entry.internal !== true`)。
|
|
202
|
+
*
|
|
203
|
+
* @param messages - 协议消息(`Session.messages` 或重放中的中间结果)。
|
|
204
|
+
* @param keep - 要保留几轮用户消息:下标落在这条消息上,它本身是要被作废的那条。
|
|
205
|
+
*/
|
|
206
|
+
function cutIndexBeforeUser(messages, keep) {
|
|
207
|
+
let seen = 0;
|
|
208
|
+
for (let index = 0; index < messages.length; index += 1) {
|
|
209
|
+
if (!isHumanUserMessage(messages[index]))
|
|
210
|
+
continue;
|
|
211
|
+
if (seen === keep)
|
|
212
|
+
return index;
|
|
213
|
+
seen += 1;
|
|
214
|
+
}
|
|
215
|
+
return -1;
|
|
216
|
+
}
|
|
133
217
|
/** 一个会话:内存消息 + 磁盘日志。 */
|
|
134
218
|
export class Session {
|
|
135
219
|
meta;
|
|
@@ -140,6 +224,26 @@ export class Session {
|
|
|
140
224
|
stream = null;
|
|
141
225
|
/** meta 首行是否已经写进磁盘。 */
|
|
142
226
|
metaWritten;
|
|
227
|
+
/**
|
|
228
|
+
* 还没落盘时攒下的 state 记账记录。
|
|
229
|
+
*
|
|
230
|
+
* 为什么要有这块缓冲:新会话一建出来,权限与模型插件就立刻补默认值,原先它们
|
|
231
|
+
* 各写一条 state 就把文件建了出来——用户只是点了「新会话」、一个字都没发,磁盘
|
|
232
|
+
* 和列表里却多了一条空会话。记账先攒在内存里,等第一条真正的日志(user /
|
|
233
|
+
* assistant / tool / summary / note)落地时,再按 meta → 攒下的记录 → 这一条
|
|
234
|
+
* 的顺序一次写出;会话 id 与路径仍由 create 当场定下,侧栏、轨迹、用量照旧按
|
|
235
|
+
* sessionId 取值,不依赖文件是否存在。
|
|
236
|
+
*/
|
|
237
|
+
pendingState = [];
|
|
238
|
+
/**
|
|
239
|
+
* 只改了内存、还没落盘的状态(id → 负载):读路径补默认值用。
|
|
240
|
+
*
|
|
241
|
+
* 为什么(2026-11-03「点一下老会话时间就变刚刚」):权限三项在**读**的时候补钉
|
|
242
|
+
* (见 core/permission-scope),以前一补就写盘,于是「只是点开看一眼」也会把
|
|
243
|
+
* 会话文件改一遍。改成先记在这里,等下一次真正要写日志(用户说话、切档位)时
|
|
244
|
+
* 跟着那一条一起落盘——同一进程里读到的值立刻生效,不会跟着偏好漂。
|
|
245
|
+
*/
|
|
246
|
+
deferredState = new Map();
|
|
143
247
|
/**
|
|
144
248
|
* T30 写租约:一份会话日志同一时刻只允许一个进程写。桌面端与 TUI 从同一份
|
|
145
249
|
* `.last-session` 取默认会话,没有这层时两边会交错 append、重放串线。
|
|
@@ -153,11 +257,19 @@ export class Session {
|
|
|
153
257
|
*/
|
|
154
258
|
toolErrors = new Map();
|
|
155
259
|
/**
|
|
156
|
-
* 成功的 write / edit 的实际改动(callId →
|
|
260
|
+
* 成功的 write / edit 的实际改动(callId → 变更摘要清单),轮尾「文件已更改」卡的数据源。
|
|
157
261
|
* 与 toolErrors 同一条旁路:不挂 `messages`(协议消息透传给端点),只在 jsonl 的
|
|
158
262
|
* tool 记录里存一份,重放历史时单独交给 transcript 折成 `kind: 'changes'` 条目。
|
|
263
|
+
*
|
|
264
|
+
* 为什么是清单(2026-10-30):PTC 的 `run_code` 一次调用能改好几个文件;以前这里只收
|
|
265
|
+
* 单个 `changes`,多文件场景要么丢、要么只剩最后一个。
|
|
159
266
|
*/
|
|
160
267
|
fileChanges = new Map();
|
|
268
|
+
/**
|
|
269
|
+
* dsh 插件给的卡片数据(callId → 卡片视图),与 fileChanges 同一条旁路:
|
|
270
|
+
* 只活在日志里,重放历史时交给 transcript 折成 tool/presentation 事件。
|
|
271
|
+
*/
|
|
272
|
+
presentations = new Map();
|
|
161
273
|
/**
|
|
162
274
|
* 回合内文件基线(codex `TurnDiffTracker` 的同款思路):本回合第一次动某个文件时
|
|
163
275
|
* 记下「动之前的全文」,回合收尾用它和盘上现值重算一份聚合 diff——同一文件改
|
|
@@ -219,6 +331,7 @@ export class Session {
|
|
|
219
331
|
const messages = [];
|
|
220
332
|
const toolErrors = new Map();
|
|
221
333
|
const fileChanges = new Map();
|
|
334
|
+
const presentations = new Map();
|
|
222
335
|
/** 已应答过的 callId(首条为准)。 */
|
|
223
336
|
const repliedCalls = new Set();
|
|
224
337
|
const state = new Map();
|
|
@@ -238,14 +351,12 @@ export class Session {
|
|
|
238
351
|
case 'user':
|
|
239
352
|
messages.push({
|
|
240
353
|
role: 'user',
|
|
241
|
-
content: record.
|
|
242
|
-
|
|
243
|
-
{ type: 'text', text: record.text },
|
|
244
|
-
...record.images.map((url) => ({ type: 'image_url', image_url: { url } })),
|
|
245
|
-
]
|
|
246
|
-
: record.text,
|
|
354
|
+
content: userContent(record.text, record.images, record.files),
|
|
355
|
+
...(record.files === undefined || record.files.length === 0 ? {} : { files: record.files }),
|
|
247
356
|
// 老日志没有 ts:这里就是 undefined,界面据此降级(不显示时间/用时)
|
|
248
357
|
...(record.ts === undefined ? {} : { ts: record.ts }),
|
|
358
|
+
// 机器投递的通知(老日志没有这个字段,按人打的字读)
|
|
359
|
+
...(record.origin === 'notice' ? { origin: record.origin } : {}),
|
|
249
360
|
});
|
|
250
361
|
break;
|
|
251
362
|
case 'assistant': {
|
|
@@ -289,8 +400,12 @@ export class Session {
|
|
|
289
400
|
const error = record.error ?? (record.text === REJECTED_TOOL_TEXT ? REJECTED_TOOL_ERROR : undefined);
|
|
290
401
|
if (error !== undefined)
|
|
291
402
|
toolErrors.set(record.callId, error);
|
|
292
|
-
|
|
293
|
-
|
|
403
|
+
// 老日志写的是单值,新日志写数组:两种都收(同一份记录不会两个形状都有)
|
|
404
|
+
if (record.changes !== undefined) {
|
|
405
|
+
fileChanges.set(record.callId, Array.isArray(record.changes) ? record.changes : [record.changes]);
|
|
406
|
+
}
|
|
407
|
+
if (record.presentation !== undefined)
|
|
408
|
+
presentations.set(record.callId, record.presentation);
|
|
294
409
|
break;
|
|
295
410
|
}
|
|
296
411
|
case 'summary': {
|
|
@@ -312,6 +427,16 @@ export class Session {
|
|
|
312
427
|
case 'state':
|
|
313
428
|
state.set(record.id, record.payload);
|
|
314
429
|
break;
|
|
430
|
+
case 'rewind': {
|
|
431
|
+
// 「从这里往后作废」(编辑并重发):截到第 keep 条人打的用户消息之前。
|
|
432
|
+
// 序号越界(老日志被别的东西改过)就当没看见——宁可多显示一段历史,也不能
|
|
433
|
+
// 把正常内容截没。
|
|
434
|
+
const keep = Number.isFinite(record.keep) && record.keep >= 0 ? Math.floor(record.keep) : 0;
|
|
435
|
+
const cut = cutIndexBeforeUser(messages, keep);
|
|
436
|
+
if (cut >= 0)
|
|
437
|
+
messages.length = cut;
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
315
440
|
case 'note':
|
|
316
441
|
notes.push({ id: record.id, text: record.text, ts: record.ts });
|
|
317
442
|
break;
|
|
@@ -339,13 +464,16 @@ export class Session {
|
|
|
339
464
|
session.toolErrors.set(callId, error);
|
|
340
465
|
for (const [callId, change] of fileChanges)
|
|
341
466
|
session.fileChanges.set(callId, change);
|
|
467
|
+
for (const [callId, presentation] of presentations)
|
|
468
|
+
session.presentations.set(callId, presentation);
|
|
342
469
|
// T32:修复只在「我们是写租约持有人」时做——修复要落盘,只读重放(队友记录 peek)不动它。
|
|
343
470
|
if (lease !== null) {
|
|
344
471
|
session.repairInterruptedTurns();
|
|
345
472
|
// 收件箱遗债:入箱后没等到边界就重启/切换的异步输入。修复完历史必然闭合,
|
|
346
|
-
// 直接落库(dsh
|
|
473
|
+
// 直接落库(dsh 的收件箱是持久投影,重启后同样要交货)。来源跟着走:
|
|
474
|
+
// 机器投递的那几条不能因为「重启过一次」就变回人打的字(见 InboxOrigin)。
|
|
347
475
|
for (const item of session.takeAsyncInbox())
|
|
348
|
-
session.appendUser(item.text, item.images);
|
|
476
|
+
session.appendUser(item.text, item.images, item.files, item.origin);
|
|
349
477
|
}
|
|
350
478
|
return session;
|
|
351
479
|
}
|
|
@@ -355,21 +483,69 @@ export class Session {
|
|
|
355
483
|
*
|
|
356
484
|
* `ts` 只写一份给内存与磁盘共用:界面按它显示「这条消息几点发的」,
|
|
357
485
|
* 也是这一轮「用时」的起点(见 contract.ts 的 TranscriptEntry.ts)。
|
|
486
|
+
*
|
|
487
|
+
* @param origin - 谁发起的这条(缺省 `'user'`)。只有 `'notice'`(机器投递)会写进日志,
|
|
488
|
+
* 界面与重放据此把它画成内部触发行而不是用户气泡(见 {@link InboxOrigin})。
|
|
358
489
|
*/
|
|
359
|
-
appendUser(text, images) {
|
|
490
|
+
appendUser(text, images, files, origin = 'user') {
|
|
360
491
|
const withImages = images !== undefined && images.length > 0;
|
|
492
|
+
const withFiles = files !== undefined && files.length > 0;
|
|
493
|
+
const notice = origin === 'notice';
|
|
361
494
|
const ts = Date.now();
|
|
362
495
|
this.messages.push({
|
|
363
496
|
role: 'user',
|
|
364
|
-
content:
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
497
|
+
content: userContent(text, images, files),
|
|
498
|
+
...(withFiles ? { files } : {}),
|
|
499
|
+
...(notice ? { origin } : {}),
|
|
500
|
+
ts,
|
|
501
|
+
});
|
|
502
|
+
this.write({
|
|
503
|
+
type: 'user',
|
|
504
|
+
text,
|
|
505
|
+
...(withImages ? { images } : {}),
|
|
506
|
+
...(withFiles ? { files } : {}),
|
|
507
|
+
...(notice ? { origin } : {}),
|
|
370
508
|
ts,
|
|
371
509
|
});
|
|
372
|
-
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* 作废第 keep 条用户消息及其之后的一切(「编辑并重发」用,2026-11-03)。
|
|
513
|
+
*
|
|
514
|
+
* 语义:保留前 keep 条人打的用户消息与它们各自的回答,从第 keep 条(0 基)开始整段丢掉,
|
|
515
|
+
* 之后由调用方 appendUser 把改过的文字重新写进去。**日志一个字都不删**——落一条
|
|
516
|
+
* `rewind` 记录声明「从这里往后作废」,重放按同一条规则截断(见 load 的 `case 'rewind'`)。
|
|
517
|
+
*
|
|
518
|
+
* @param keep - 保留几轮(人打的用户消息条数)。
|
|
519
|
+
* @returns false = 这条消息已经不在会话里(序号越界),调用方应当如实回报而不是硬改。
|
|
520
|
+
*/
|
|
521
|
+
rewindToUser(keep) {
|
|
522
|
+
const cut = cutIndexBeforeUser(this.messages, keep);
|
|
523
|
+
if (cut < 0)
|
|
524
|
+
return false;
|
|
525
|
+
const dropped = this.messages.splice(cut);
|
|
526
|
+
// 被丢掉那段的工具派生状态(错误标记 / 改动清单 / 卡片)一并清掉:它们按 callId 存,
|
|
527
|
+
// 作用域只到那些消息为止,留着就是纯占内存(同一个 callId 不会再来一次)。
|
|
528
|
+
const kept = new Set();
|
|
529
|
+
for (const message of this.messages) {
|
|
530
|
+
if (message.role === 'tool' && message.tool_call_id !== undefined)
|
|
531
|
+
kept.add(message.tool_call_id);
|
|
532
|
+
for (const call of message.tool_calls ?? [])
|
|
533
|
+
kept.add(call.id);
|
|
534
|
+
}
|
|
535
|
+
const forget = (callId) => {
|
|
536
|
+
this.toolErrors.delete(callId);
|
|
537
|
+
this.fileChanges.delete(callId);
|
|
538
|
+
this.presentations.delete(callId);
|
|
539
|
+
};
|
|
540
|
+
for (const message of dropped) {
|
|
541
|
+
if (message.role === 'tool' && message.tool_call_id !== undefined && !kept.has(message.tool_call_id))
|
|
542
|
+
forget(message.tool_call_id);
|
|
543
|
+
for (const call of message.tool_calls ?? [])
|
|
544
|
+
if (!kept.has(call.id))
|
|
545
|
+
forget(call.id);
|
|
546
|
+
}
|
|
547
|
+
this.write({ type: 'rewind', keep, ts: Date.now() });
|
|
548
|
+
return true;
|
|
373
549
|
}
|
|
374
550
|
appendAssistant(text, reasoning, toolCalls) {
|
|
375
551
|
const ts = Date.now();
|
|
@@ -412,6 +588,7 @@ export class Session {
|
|
|
412
588
|
const text = typeof output === 'string' ? output : output.text;
|
|
413
589
|
const images = typeof output === 'string' ? undefined : output.images;
|
|
414
590
|
const changes = typeof output === 'string' ? undefined : output.changes;
|
|
591
|
+
const presentation = typeof output === 'string' ? undefined : output.presentation;
|
|
415
592
|
const content = images !== undefined && images.length > 0
|
|
416
593
|
? [
|
|
417
594
|
{ type: 'text', text },
|
|
@@ -423,9 +600,11 @@ export class Session {
|
|
|
423
600
|
this.toolErrors.set(callId, error);
|
|
424
601
|
// baseline(改前全文)是循环回合基线记账的内存字段,进不了日志与旁路:
|
|
425
602
|
// 两处都在入口剥掉,上游忘了剥也漏不出去。
|
|
426
|
-
const
|
|
427
|
-
if (
|
|
428
|
-
this.fileChanges.set(callId,
|
|
603
|
+
const cleanList = changes === undefined ? [] : (Array.isArray(changes) ? changes : [changes]).map(stripBaseline);
|
|
604
|
+
if (cleanList.length > 0)
|
|
605
|
+
this.fileChanges.set(callId, cleanList);
|
|
606
|
+
if (presentation !== undefined)
|
|
607
|
+
this.presentations.set(callId, presentation);
|
|
429
608
|
this.write({
|
|
430
609
|
type: 'tool',
|
|
431
610
|
callId,
|
|
@@ -434,7 +613,8 @@ export class Session {
|
|
|
434
613
|
...(images !== undefined && images.length > 0 ? { images } : {}),
|
|
435
614
|
// 内存消息不带 changes(协议消息透传给端点,多字段可能被挑剔的网关判 400);
|
|
436
615
|
// 它只活在日志里,恢复会话时经 fileChanges 旁路还原成轮尾卡。
|
|
437
|
-
...(
|
|
616
|
+
...(cleanList.length === 0 ? {} : { changes: cleanList.length === 1 ? cleanList[0] : cleanList }),
|
|
617
|
+
...(presentation !== undefined ? { presentation } : {}),
|
|
438
618
|
...(error !== undefined ? { error } : {}),
|
|
439
619
|
ts,
|
|
440
620
|
});
|
|
@@ -541,8 +721,21 @@ export class Session {
|
|
|
541
721
|
*/
|
|
542
722
|
appendState(id, payload) {
|
|
543
723
|
this.stateById.set(id, payload);
|
|
724
|
+
// 这个 id 之前攒着的默认值被真实写入顶掉了,别再跟着下一条日志重复落一遍
|
|
725
|
+
this.deferredState.delete(id);
|
|
544
726
|
this.write({ type: 'state', id: String(id), payload });
|
|
545
727
|
}
|
|
728
|
+
/**
|
|
729
|
+
* 只改内存里的状态,等下一次真正写日志时再落盘(读路径补默认值专用)。
|
|
730
|
+
*
|
|
731
|
+
* 与 {@link appendState} 的区别:这里的值由后续写盘顺带带出,所以「只打开一次
|
|
732
|
+
* 会话、什么都没做」不会再改动文件(mtime 不变,侧栏的「最近使用」也就不会跳)。
|
|
733
|
+
* 同一进程里读到的值立刻生效,和落过盘没有区别。
|
|
734
|
+
*/
|
|
735
|
+
setState(id, payload) {
|
|
736
|
+
this.stateById.set(id, payload);
|
|
737
|
+
this.deferredState.set(id, payload);
|
|
738
|
+
}
|
|
546
739
|
/**
|
|
547
740
|
* 异步输入入箱:回合跑动中到达的输入先在这里排队(state 条目持久化,重启不丢),
|
|
548
741
|
* 等 loop 在步骤边界/回合收尾时出账落库。见 {@link SessionStateMap} 的
|
|
@@ -550,7 +743,7 @@ export class Session {
|
|
|
550
743
|
* @param origin - 这条是用户来源还是机器来源(缺省 `'user'`,老调用点行为不变)。
|
|
551
744
|
* 只有 `'notice'` 会被记进条目(`'user'` 保持条目形状与老状态一致,读时兜底)。
|
|
552
745
|
*/
|
|
553
|
-
enqueueAsync(text, images, origin = 'user') {
|
|
746
|
+
enqueueAsync(text, images, origin = 'user', files) {
|
|
554
747
|
const current = this.state('async-inbox')?.items ?? [];
|
|
555
748
|
this.appendState('async-inbox', {
|
|
556
749
|
items: [
|
|
@@ -558,6 +751,7 @@ export class Session {
|
|
|
558
751
|
{
|
|
559
752
|
text,
|
|
560
753
|
...(images !== undefined && images.length > 0 ? { images } : {}),
|
|
754
|
+
...(files !== undefined && files.length > 0 ? { files } : {}),
|
|
561
755
|
...(origin === 'notice' ? { origin } : {}),
|
|
562
756
|
},
|
|
563
757
|
],
|
|
@@ -657,10 +851,30 @@ export class Session {
|
|
|
657
851
|
return this.file;
|
|
658
852
|
}
|
|
659
853
|
write(record) {
|
|
660
|
-
//
|
|
854
|
+
// 还没说过话:state 这类记账先攒着,别为了补一个默认值就在磁盘上建出空会话
|
|
855
|
+
if (this.metaWritten !== true && record.type === 'state') {
|
|
856
|
+
this.pendingState.push(record);
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
// 第一条真正的日志顺带补上 meta 首行:jsonl 的 append-only 顺序不能变。
|
|
860
|
+
// 攒下的记账紧跟在 meta 后面、按产生顺序写出——恢复时会逐条重放、最后一条
|
|
861
|
+
// 生效,顺序反了就会读到错的默认值。
|
|
661
862
|
if (this.metaWritten !== true) {
|
|
662
863
|
this.metaWritten = true;
|
|
663
|
-
|
|
864
|
+
const stream = this.streamFor();
|
|
865
|
+
stream.write(`${JSON.stringify({ type: 'meta', ...this.meta })}\n`);
|
|
866
|
+
for (const pending of this.pendingState)
|
|
867
|
+
stream.write(`${JSON.stringify(pending)}\n`);
|
|
868
|
+
this.pendingState.length = 0;
|
|
869
|
+
}
|
|
870
|
+
// 读路径攒下的默认值跟着这一条一起落盘:顺序在触发它的记录之前,重放时最后一条
|
|
871
|
+
// 生效,与「先补钉、再做事」的因果一致。
|
|
872
|
+
if (this.deferredState.size > 0) {
|
|
873
|
+
const stream = this.streamFor();
|
|
874
|
+
for (const [id, payload] of this.deferredState) {
|
|
875
|
+
stream.write(`${JSON.stringify({ type: 'state', id, payload })}\n`);
|
|
876
|
+
}
|
|
877
|
+
this.deferredState.clear();
|
|
664
878
|
}
|
|
665
879
|
this.streamFor().write(`${JSON.stringify(record)}\n`);
|
|
666
880
|
}
|
|
@@ -727,10 +941,99 @@ function scanSessions(root, metas) {
|
|
|
727
941
|
}
|
|
728
942
|
return out.sort((a, b) => b.createdAt - a.createdAt);
|
|
729
943
|
}
|
|
944
|
+
/**
|
|
945
|
+
* 文件里有没有一条真正的对话记录(user 或 assistant)。
|
|
946
|
+
*
|
|
947
|
+
* 只有 meta 与 state 记账的文件是「点了新会话、一个字没发」留下的(缓冲上线之前的
|
|
948
|
+
* 存量文件、以及插件补默认值写出来的旧文件):它们不该在列表里占一行。记录都由本
|
|
949
|
+
* 模块写出,type 永远是第一个键,所以按行首前缀判断就够,不用逐行 JSON.parse。
|
|
950
|
+
*/
|
|
951
|
+
function hasConversation(lines) {
|
|
952
|
+
return lines.some((line) => line.startsWith('{"type":"user"') || line.startsWith('{"type":"assistant"'));
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* 侧栏一行的读盘缓存(2026-11-03):键 = 文件路径 + 侧栏属性(标题/置顶),
|
|
956
|
+
* 值 = 上次的 mtime、大小与读出来的那一行。
|
|
957
|
+
*
|
|
958
|
+
* 为什么加:`listSessions()` 每次都把**每个会话文件的整份内容**读一遍(只为拿 meta 行
|
|
959
|
+
* 与第一条用户消息),实测 76 条会话要 120–150ms;而界面**每点一次会话**就会
|
|
960
|
+
* `refreshSessions` 重扫一次——这一下比读会话本身还贵,且完全没必要:切会话不会
|
|
961
|
+
* 改动任何文件。
|
|
962
|
+
*
|
|
963
|
+
* 认 mtime + 大小:会话在长(append),那一条自己会失效重读;其余几十条一个字节没变,
|
|
964
|
+
* 直接复用。标题/置顶存在 meta.json sidecar 里、不碰 jsonl,所以把它们一起编进键,
|
|
965
|
+
* 改完名字立刻能看到(代价是这条会多读一次,改名是低频动作)。
|
|
966
|
+
*/
|
|
967
|
+
const sessionRowCache = new Map();
|
|
730
968
|
/** 读一个会话文件的前几行 + mtime;首行不是 meta(损坏/空文件)时尽量抢救(T31)。 */
|
|
731
969
|
function readSessionFile(filePath, sidecar) {
|
|
970
|
+
let stat;
|
|
732
971
|
try {
|
|
733
|
-
|
|
972
|
+
stat = statSync(filePath);
|
|
973
|
+
}
|
|
974
|
+
catch {
|
|
975
|
+
return null;
|
|
976
|
+
}
|
|
977
|
+
const key = `${filePath}\u0000${sidecar?.title ?? ''}\u0000${sidecar?.autoTitle ?? ''}\u0000${String(sidecar?.pinnedAt ?? '')}`;
|
|
978
|
+
const cached = sessionRowCache.get(key);
|
|
979
|
+
if (cached !== undefined && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size)
|
|
980
|
+
return cached.item;
|
|
981
|
+
const item = readSessionFileUncached(filePath, stat.mtimeMs, sidecar);
|
|
982
|
+
// 上限只是防御:正常是一个工作目录几十到几百条会话。
|
|
983
|
+
if (sessionRowCache.size > 512)
|
|
984
|
+
sessionRowCache.clear();
|
|
985
|
+
sessionRowCache.set(key, { mtimeMs: stat.mtimeMs, size: stat.size, item });
|
|
986
|
+
return item;
|
|
987
|
+
}
|
|
988
|
+
/** 读尾部找「最后一句话」时的窗口:state 记账一条不到 1KB,512KB 够翻过一大批。 */
|
|
989
|
+
const TAIL_SCAN_CHARS = 512 * 1024;
|
|
990
|
+
/**
|
|
991
|
+
* 「最近使用」的时刻 = 最后一条带 `ts` 的记录,不是文件 mtime。
|
|
992
|
+
*
|
|
993
|
+
* 为什么(2026-11-03 用户报障「点一下会话,时间就变刚刚」):mtime 只说明「这个文件
|
|
994
|
+
* 刚被写过」。权限三项的默认值、模型档位这些记账都会在**打开会话**时补写一条
|
|
995
|
+
* `state`,于是老会话被点开一次,侧栏时间就跳到「刚刚」——可它一个字都没多。
|
|
996
|
+
* 界面要的是「最后一步是什么时候」,所以取最后一条带 `ts` 的对话记录
|
|
997
|
+
* (user / assistant / tool / summary / rewind / note 都带),没有 `ts` 的 state
|
|
998
|
+
* 记账自然被跳过。
|
|
999
|
+
*
|
|
1000
|
+
* 老日志(`ts` 字段引入之前)整份都找不到 ts:回落到 mtime,至少排序不乱。
|
|
1001
|
+
* 只扫尾部:append-only 的日志里最后一条记录必定贴着文件尾,单独一段够用;
|
|
1002
|
+
* 万一最后一条本身超过窗口被切碎,解析失败就当没看见,继续往前找。
|
|
1003
|
+
*
|
|
1004
|
+
* @param text - 会话文件全文(调用方已经读出来了,不再读第二次)。
|
|
1005
|
+
* @param fallback - 找不到任何 `ts` 时用它(调用方传 mtime)。
|
|
1006
|
+
*/
|
|
1007
|
+
function lastActivityAt(text, fallback) {
|
|
1008
|
+
const tail = text.length > TAIL_SCAN_CHARS ? text.slice(text.length - TAIL_SCAN_CHARS) : text;
|
|
1009
|
+
const lines = tail.split(/\r?\n/);
|
|
1010
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
1011
|
+
const line = lines[index];
|
|
1012
|
+
// 便宜的先筛:没有 ts 字样的行(state 记账都是这种)直接跳过,不做 JSON.parse
|
|
1013
|
+
if (!line.includes('"ts"'))
|
|
1014
|
+
continue;
|
|
1015
|
+
try {
|
|
1016
|
+
const record = JSON.parse(line);
|
|
1017
|
+
if (typeof record.ts === 'number' && Number.isFinite(record.ts))
|
|
1018
|
+
return record.ts;
|
|
1019
|
+
}
|
|
1020
|
+
catch {
|
|
1021
|
+
// 窗口起点切碎的半行、坏行:跳过,继续往前找
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
return fallback;
|
|
1025
|
+
}
|
|
1026
|
+
/** {@link readSessionFile} 的真读:mtime 由调用方传进来,省一次 stat。 */
|
|
1027
|
+
function readSessionFileUncached(filePath, mtimeMs, sidecar) {
|
|
1028
|
+
try {
|
|
1029
|
+
const text = readFileSync(filePath, 'utf8');
|
|
1030
|
+
const head = text.split(/\r?\n/, 200);
|
|
1031
|
+
// 一条对话记录都没有:不进列表(T31「头行损坏也露脸」只放过真有对话的文件)。
|
|
1032
|
+
// 这里只读了前 200 行,state 攒得多时首条用户消息可能被挤出窗口;真截断了就
|
|
1033
|
+
// 把整份再看一眼,免得一条正常会话从列表里凭空消失。
|
|
1034
|
+
if (!hasConversation(head) && (head.length < 200 || !hasConversation(text.split(/\r?\n/)))) {
|
|
1035
|
+
return null;
|
|
1036
|
+
}
|
|
734
1037
|
let record;
|
|
735
1038
|
try {
|
|
736
1039
|
record = JSON.parse(head[0] ?? '');
|
|
@@ -750,7 +1053,7 @@ function readSessionFile(filePath, sidecar) {
|
|
|
750
1053
|
id: record.id,
|
|
751
1054
|
cwd: record.cwd,
|
|
752
1055
|
createdAt: record.createdAt,
|
|
753
|
-
updatedAt:
|
|
1056
|
+
updatedAt: lastActivityAt(text, mtimeMs),
|
|
754
1057
|
...(title !== undefined ? { title } : {}),
|
|
755
1058
|
...(sidecar?.pinnedAt !== undefined ? { pinnedAt: sidecar.pinnedAt } : {}),
|
|
756
1059
|
path: filePath,
|
|
@@ -789,7 +1092,7 @@ function readSessionFile(filePath, sidecar) {
|
|
|
789
1092
|
id: basename(filePath, '.jsonl'),
|
|
790
1093
|
cwd: commonDirectory(paths) ?? '',
|
|
791
1094
|
createdAt,
|
|
792
|
-
updatedAt:
|
|
1095
|
+
updatedAt: lastActivityAt(text, mtimeMs),
|
|
793
1096
|
...(title !== undefined ? { title } : {}),
|
|
794
1097
|
...(sidecar?.pinnedAt !== undefined ? { pinnedAt: sidecar.pinnedAt } : {}),
|
|
795
1098
|
path: filePath,
|
|
@@ -915,6 +1218,53 @@ export function countTrashFiles() {
|
|
|
915
1218
|
}
|
|
916
1219
|
return count;
|
|
917
1220
|
}
|
|
1221
|
+
/**
|
|
1222
|
+
* 把日志里的 `rewind` 指令**应用**到原始行上:返回「作废之后还剩哪些行」。
|
|
1223
|
+
*
|
|
1224
|
+
* 为什么需要它:`rewind` 是「从这里往后作废」的一条声明,内存与重放都认(见
|
|
1225
|
+
* {@link Session.rewindToUser} 与 load 的 `case 'rewind'`),但还有几条读盘的路是
|
|
1226
|
+
* **逐行扫原文**的——分叉、分叉菜单、标题推导。不在这里把 rewind 应用一遍,那些路就会
|
|
1227
|
+
* 把已经被作废的消息当成还在:分叉菜单里列着它们,从那里分叉出来的新会话还会把
|
|
1228
|
+
* `rewind` 记录一起带过去,重放时再把自己截空(2026-11-03 审查抓到)。
|
|
1229
|
+
*
|
|
1230
|
+
* 结果里的 `rewind` 记录本身不再保留:它已经生效了,留着会让下游再截一次。
|
|
1231
|
+
* 越界的 keep(比人打的消息还多)按「没看见」处理,与 load 同一条兜底。
|
|
1232
|
+
*
|
|
1233
|
+
* @param lines - 一份 jsonl 切出来的行(不含空行)。
|
|
1234
|
+
*/
|
|
1235
|
+
function applyRewinds(lines) {
|
|
1236
|
+
const out = [];
|
|
1237
|
+
/** 保留下来的行里,每条**人打的**用户消息落在 `out` 的哪个下标(0 基,按消息序)。 */
|
|
1238
|
+
const humanAt = [];
|
|
1239
|
+
for (const line of lines) {
|
|
1240
|
+
if (!line.startsWith('{"type":"')) {
|
|
1241
|
+
out.push(line);
|
|
1242
|
+
continue;
|
|
1243
|
+
}
|
|
1244
|
+
let record;
|
|
1245
|
+
try {
|
|
1246
|
+
record = JSON.parse(line);
|
|
1247
|
+
}
|
|
1248
|
+
catch {
|
|
1249
|
+
out.push(line);
|
|
1250
|
+
continue;
|
|
1251
|
+
}
|
|
1252
|
+
if (record.type === 'rewind') {
|
|
1253
|
+
const keep = Number.isFinite(record.keep) && record.keep >= 0 ? Math.floor(record.keep) : 0;
|
|
1254
|
+
const cut = humanAt[keep];
|
|
1255
|
+
if (cut !== undefined) {
|
|
1256
|
+
out.length = cut;
|
|
1257
|
+
humanAt.length = keep;
|
|
1258
|
+
}
|
|
1259
|
+
continue;
|
|
1260
|
+
}
|
|
1261
|
+
if (record.type === 'user' && record.origin !== 'notice' && !record.text.startsWith(TEAMMATE_REPORT_OPEN) && !record.text.startsWith(REVIEW_FINDINGS_OPEN)) {
|
|
1262
|
+
humanAt.push(out.length);
|
|
1263
|
+
}
|
|
1264
|
+
out.push(line);
|
|
1265
|
+
}
|
|
1266
|
+
return out;
|
|
1267
|
+
}
|
|
918
1268
|
/**
|
|
919
1269
|
* 分叉一个会话:复制日志到第 `beforeUserMessage` 条用户消息之前,
|
|
920
1270
|
* 首行 meta 换成新 uuid 与新创建时间,返回新文件路径。
|
|
@@ -924,7 +1274,9 @@ export function countTrashFiles() {
|
|
|
924
1274
|
*/
|
|
925
1275
|
export function forkSession(filePath, beforeUserMessage) {
|
|
926
1276
|
const source = assertLiveSessionFile(filePath);
|
|
927
|
-
|
|
1277
|
+
// 先应用 rewind:被作废的那段既不该出现在分叉菜单里,也不该被复制进新会话
|
|
1278
|
+
// (带着 rewind 记录复制的话,新会话重放时又会把自己截空——2026-11-03 审查抓到)。
|
|
1279
|
+
const lines = applyRewinds(readFileSync(source, 'utf8').split(/\r?\n/).filter((line) => line !== ''));
|
|
928
1280
|
const first = JSON.parse(lines[0] ?? '');
|
|
929
1281
|
if (first.type !== 'meta')
|
|
930
1282
|
throw new Error(`源会话首行不是 meta:${basename(source)}`);
|
|
@@ -962,7 +1314,8 @@ export function forkSession(filePath, beforeUserMessage) {
|
|
|
962
1314
|
}
|
|
963
1315
|
/** 读一个会话里的用户消息(分叉菜单用它选分叉位置,下标一一对应)。 */
|
|
964
1316
|
export function readUserMessages(filePath) {
|
|
965
|
-
|
|
1317
|
+
// 同样先应用 rewind:分叉菜单里不该列出已经被「编辑重发」作废的消息
|
|
1318
|
+
const lines = applyRewinds(readFileSync(filePath, 'utf8').split(/\r?\n/));
|
|
966
1319
|
const out = [];
|
|
967
1320
|
for (const line of lines) {
|
|
968
1321
|
if (!line.startsWith('{"type":"user"'))
|
|
@@ -978,7 +1331,7 @@ export function readUserMessages(filePath) {
|
|
|
978
1331
|
return out;
|
|
979
1332
|
}
|
|
980
1333
|
/** 文件名就是 `<uuid>.jsonl`,取 uuid 用来写 sidecar。 */
|
|
981
|
-
function uuidOf(filePath) {
|
|
1334
|
+
export function uuidOf(filePath) {
|
|
982
1335
|
return basename(filePath, '.jsonl');
|
|
983
1336
|
}
|
|
984
1337
|
/** T30:会话库操作撞上「另一个窗口开着它」时的统一说法。 */
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cmd.exe 那条路上的参数加引号(全仓库唯一一份)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独一个模块:`core/mcp.ts` 起 MCP server、`core/lsp/client.ts` 起语言服务器,
|
|
5
|
+
* 都在 Windows 上走 `shell: true`(命令由 cmd.exe 解析);带空格或 `&|<>^` 的参数
|
|
6
|
+
* 必须自己加双引号,否则会被 cmd 拆开。两处各写了一份逐字相同的实现,合并到这里。
|
|
7
|
+
*
|
|
8
|
+
* 顺带收着 `shellOf()`:两个跑钩子的模块(`core/hooks.ts`、`core/lifecycle-hooks.ts`)
|
|
9
|
+
* 也各写了一份「该用哪个 shell、带什么参数」的逐字相同实现,同属「起 shell」这件事。
|
|
10
|
+
*
|
|
11
|
+
* 只在 shell 模式用;直接 spawn(不经 cmd)的参数不要过这一道——会被多套一层引号。
|
|
12
|
+
*
|
|
13
|
+
* @module dsc/core/shell-quote
|
|
14
|
+
*/
|
|
15
|
+
/** 含空白或 cmd 元字符就加双引号,内部双引号转义成 \";否则原样返回。 */
|
|
16
|
+
export declare function quoteForCmd(arg: string): string;
|
|
17
|
+
/** 走 `-c` 那条路时该用哪个 shell:Windows 是 cmd.exe,其余是 /bin/sh。 */
|
|
18
|
+
export declare function shellOf(): {
|
|
19
|
+
file: string;
|
|
20
|
+
args: string[];
|
|
21
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cmd.exe 那条路上的参数加引号(全仓库唯一一份)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独一个模块:`core/mcp.ts` 起 MCP server、`core/lsp/client.ts` 起语言服务器,
|
|
5
|
+
* 都在 Windows 上走 `shell: true`(命令由 cmd.exe 解析);带空格或 `&|<>^` 的参数
|
|
6
|
+
* 必须自己加双引号,否则会被 cmd 拆开。两处各写了一份逐字相同的实现,合并到这里。
|
|
7
|
+
*
|
|
8
|
+
* 顺带收着 `shellOf()`:两个跑钩子的模块(`core/hooks.ts`、`core/lifecycle-hooks.ts`)
|
|
9
|
+
* 也各写了一份「该用哪个 shell、带什么参数」的逐字相同实现,同属「起 shell」这件事。
|
|
10
|
+
*
|
|
11
|
+
* 只在 shell 模式用;直接 spawn(不经 cmd)的参数不要过这一道——会被多套一层引号。
|
|
12
|
+
*
|
|
13
|
+
* @module dsc/core/shell-quote
|
|
14
|
+
*/
|
|
15
|
+
/** 含空白或 cmd 元字符就加双引号,内部双引号转义成 \";否则原样返回。 */
|
|
16
|
+
export function quoteForCmd(arg) {
|
|
17
|
+
return /[\s"&|<>^()]/.test(arg) ? `"${arg.replace(/"/g, '\\"')}"` : arg;
|
|
18
|
+
}
|
|
19
|
+
/** 走 `-c` 那条路时该用哪个 shell:Windows 是 cmd.exe,其余是 /bin/sh。 */
|
|
20
|
+
export function shellOf() {
|
|
21
|
+
return process.platform === 'win32'
|
|
22
|
+
? { file: 'cmd.exe', args: ['/d', '/s', '/c'] }
|
|
23
|
+
: { file: '/bin/sh', args: ['-c'] };
|
|
24
|
+
}
|