@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/microcompact.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { estimateTextTokens } from './token-estimate.js';
|
|
2
|
+
import { TODO_REMINDER_TEXT } from './todo-reminder.js';
|
|
2
3
|
/** 占位符前缀:既是给模型看的正文,也是幂等的锚点——已经是占位符的条目不处理第二遍。 */
|
|
3
4
|
export const CLEARED_TOOL_RESULT_PREFIX = '[旧工具结果已清理';
|
|
4
5
|
/** 最近多少条工具结果原样保留(默认值;与 ZCode 的 DEFAULT_MICROCOMPACT_KEEP_RECENT_TOOL_RESULTS 同值)。 */
|
|
@@ -66,6 +67,133 @@ function placeholderFor(toolName) {
|
|
|
66
67
|
? `${CLEARED_TOOL_RESULT_PREFIX}]`
|
|
67
68
|
: `${CLEARED_TOOL_RESULT_PREFIX}:${toolName}]`;
|
|
68
69
|
}
|
|
70
|
+
/** 算出这次该清哪些工具结果(callId → 占位符);纯函数,不改输入。 */
|
|
71
|
+
export function planMicrocompact(messages, options = {}) {
|
|
72
|
+
const out = microcompact(messages, options);
|
|
73
|
+
const plan = new Map();
|
|
74
|
+
messages.forEach((message, index) => {
|
|
75
|
+
if (message.role !== 'tool')
|
|
76
|
+
return;
|
|
77
|
+
const id = message.tool_call_id;
|
|
78
|
+
if (id === undefined || id === '')
|
|
79
|
+
return;
|
|
80
|
+
if (out[index].content === message.content)
|
|
81
|
+
return;
|
|
82
|
+
plan.set(id, typeof out[index].content === 'string' ? out[index].content : '');
|
|
83
|
+
});
|
|
84
|
+
return plan;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 按冻结的计划改写请求体(只换 callId 命中且内容确实不同的那几条)。
|
|
88
|
+
* 计划里已经不在本次消息里的条目直接跳过(压缩可能把整段历史换掉了)。
|
|
89
|
+
*/
|
|
90
|
+
export function applyMicrocompactPlan(messages, plan) {
|
|
91
|
+
if (plan.size === 0)
|
|
92
|
+
return [...messages];
|
|
93
|
+
return messages.map((message) => {
|
|
94
|
+
if (message.role !== 'tool')
|
|
95
|
+
return message;
|
|
96
|
+
const id = message.tool_call_id;
|
|
97
|
+
if (id === undefined)
|
|
98
|
+
return message;
|
|
99
|
+
const placeholder = plan.get(id);
|
|
100
|
+
if (placeholder === undefined || message.content === placeholder)
|
|
101
|
+
return message;
|
|
102
|
+
return { ...message, content: placeholder };
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/** 一条消息正文的字符数:字符串按长度算,数组只数 text 部件(图片本身不按 url 长度算钱)。 */
|
|
106
|
+
function messageChars(message) {
|
|
107
|
+
const content = message.content;
|
|
108
|
+
if (typeof content === 'string')
|
|
109
|
+
return content.length;
|
|
110
|
+
if (!Array.isArray(content))
|
|
111
|
+
return 0;
|
|
112
|
+
let total = 0;
|
|
113
|
+
for (const part of content) {
|
|
114
|
+
if (part.type === 'text' && typeof part.text === 'string')
|
|
115
|
+
total += part.text.length;
|
|
116
|
+
}
|
|
117
|
+
return total;
|
|
118
|
+
}
|
|
119
|
+
/** 整段提示词的字符数:把所有消息正文加起来,不数 JSON 外壳与 tool_calls 参数(大头是正文)。 */
|
|
120
|
+
export function promptCharsOf(messages) {
|
|
121
|
+
let total = 0;
|
|
122
|
+
for (const message of messages)
|
|
123
|
+
total += messageChars(message);
|
|
124
|
+
return total;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 计划能省下的字符数:被替换正文长度减占位符长度,只算这次确实会改的那几条。
|
|
128
|
+
* 跟 {@link applyMicrocompactPlan} 用同一套命中条件(callId 在计划里且内容不同)。
|
|
129
|
+
*/
|
|
130
|
+
export function planFreeChars(messages, plan) {
|
|
131
|
+
let freed = 0;
|
|
132
|
+
for (const message of messages) {
|
|
133
|
+
if (message.role !== 'tool')
|
|
134
|
+
continue;
|
|
135
|
+
const id = message.tool_call_id;
|
|
136
|
+
if (id === undefined)
|
|
137
|
+
continue;
|
|
138
|
+
const placeholder = plan.get(id);
|
|
139
|
+
if (placeholder === undefined || message.content === placeholder)
|
|
140
|
+
continue;
|
|
141
|
+
if (typeof message.content !== 'string')
|
|
142
|
+
continue;
|
|
143
|
+
freed += message.content.length - placeholder.length;
|
|
144
|
+
}
|
|
145
|
+
return freed;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* 这份计划值不值得应用:省下的字符占整段提示词的百分比要达到门槛。
|
|
149
|
+
*
|
|
150
|
+
* 为什么要有这道门槛:前缀缓存里命中的 token 大约只按 1/10 价收,没命中的整段按全价
|
|
151
|
+
* 重读。清 1 个 token 只省下 1/10 的钱,可清理点一动、从那儿往后整段前缀作废,要按
|
|
152
|
+
* 全价重读一遍——省得少还不如不清。所以比例不够就先不动,等攒够一轮再说。
|
|
153
|
+
*
|
|
154
|
+
* @param minFreePercent - 门槛百分比(0–100);0 表示只要能省就应用。
|
|
155
|
+
*/
|
|
156
|
+
export function planWorthApplying(messages, plan, minFreePercent) {
|
|
157
|
+
if (plan.size === 0)
|
|
158
|
+
return false;
|
|
159
|
+
const total = promptCharsOf(messages);
|
|
160
|
+
if (total <= 0)
|
|
161
|
+
return false;
|
|
162
|
+
const threshold = Math.max(0, Math.min(100, minFreePercent));
|
|
163
|
+
return (planFreeChars(messages, plan) / total) * 100 >= threshold;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* 这条 user 消息是不是「程序塞进来的」(环境快照 / 任务清单提醒 / 钩子产出 / 队友汇报),
|
|
167
|
+
* 不算用户新开的一轮。轮次键只数真人发言,否则同一轮里 env 快照一刷就被判成
|
|
168
|
+
* 新一轮,冻结计划又白做了。
|
|
169
|
+
*
|
|
170
|
+
* 队友汇报(`<teammate-report `)也算:它是子代理干完活后由程序投进来的,不是真人开口。
|
|
171
|
+
* 如果把它算成新一轮,队友每汇报一次就翻一轮,冻结计划重算、清理点跟着移动,等于每份
|
|
172
|
+
* 汇报都花一次整段前缀重读的钱——汇报越勤,前缀缓存越碎。
|
|
173
|
+
*/
|
|
174
|
+
export function isSyntheticUserMessage(message) {
|
|
175
|
+
if (message.role !== 'user')
|
|
176
|
+
return false;
|
|
177
|
+
const text = typeof message.content === 'string' ? message.content : '';
|
|
178
|
+
if (text === TODO_REMINDER_TEXT)
|
|
179
|
+
return true;
|
|
180
|
+
if (text.includes('(本条是程序在每次请求时自动附上的当前环境快照'))
|
|
181
|
+
return true;
|
|
182
|
+
if (text.startsWith('<external_content source="hook:'))
|
|
183
|
+
return true;
|
|
184
|
+
if (text.startsWith('<teammate-report '))
|
|
185
|
+
return true;
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
/** 这次请求属于第几轮(真人 user 消息条数);同一轮内计划可以冻结复用。 */
|
|
189
|
+
export function roundKeyOf(messages) {
|
|
190
|
+
let count = 0;
|
|
191
|
+
for (const message of messages) {
|
|
192
|
+
if (message.role === 'user' && !isSyntheticUserMessage(message))
|
|
193
|
+
count += 1;
|
|
194
|
+
}
|
|
195
|
+
return count;
|
|
196
|
+
}
|
|
69
197
|
/** 扫一遍 assistant 的 tool_calls,建 callId → 工具名 的表(占位符要回填真名)。 */
|
|
70
198
|
function toolCallNames(messages) {
|
|
71
199
|
const names = new Map();
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
*/
|
|
55
55
|
import { DOCK_TAB_CLOSE_EVENT, DOCK_TAB_OPEN_EVENT } from './dock-browser.js';
|
|
56
56
|
import { DOCK_TERM_OPS } from './dock-ops.js';
|
|
57
|
+
import { jsonText } from './json-text.js';
|
|
57
58
|
/**
|
|
58
59
|
* 桥的协议版本:**加操作不涨**,改某个操作的实参或语义才涨。
|
|
59
60
|
* 桌面主进程与壳握手时对一下,不一致就在诊断区说明白(不静默降级)。
|
|
@@ -253,7 +254,7 @@ const MAX_PROVIDER_URL = 4096;
|
|
|
253
254
|
const MAX_PROVIDER_DRAFT = 65536;
|
|
254
255
|
/** API key 的长度上限(真实 key 几十字符,4KB 富余得多)。 */
|
|
255
256
|
const MAX_PROVIDER_KEY = 4096;
|
|
256
|
-
const THEME_SOURCES = ['dark', 'light', 'system'];
|
|
257
|
+
const THEME_SOURCES = ['dark', 'light', 'claude', 'system'];
|
|
257
258
|
const WORKSPACE_KINDS = ['terminal', 'explorer', 'vscode'];
|
|
258
259
|
/**
|
|
259
260
|
* 权限模式的三档(与 `contract.ts` 的 `ApprovalPolicy` 一字不差)。
|
|
@@ -552,12 +553,3 @@ function checkShape(shape, value) {
|
|
|
552
553
|
}
|
|
553
554
|
}
|
|
554
555
|
}
|
|
555
|
-
/** 一段 JSON 文本;序列化不了(循环引用、BigInt、函数)给 null。 */
|
|
556
|
-
function jsonText(value) {
|
|
557
|
-
try {
|
|
558
|
-
return JSON.stringify(value) ?? null;
|
|
559
|
-
}
|
|
560
|
-
catch {
|
|
561
|
-
return null;
|
|
562
|
-
}
|
|
563
|
-
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
export declare const DSC_HOME: string;
|
|
3
3
|
/** dsc 自有存储下的绝对路径(config、会话、用量、插件……隔离测试与迁移的单一坐标)。 */
|
|
4
4
|
export declare function dscPath(...parts: string[]): string;
|
|
5
|
+
/** `.env.xxx` 这一族(.env.production、.env.staging…)也拒读,只放行 .env.example。 */
|
|
6
|
+
export declare function isEnvFamily(name: string): boolean;
|
|
5
7
|
/** 判定结果:null = 允许;字符串 = 拒绝原因(会原样进工具结果,模型看得见)。 */
|
|
6
8
|
export type PathVerdict = string | null;
|
|
7
9
|
/** 目标是不是在工作目录内(跟着 symlink 判,堵住「建个软链指到工作区外」这条路)。 */
|
|
@@ -10,7 +12,11 @@ export declare function isInsideCwd(cwd: string, target: string): boolean;
|
|
|
10
12
|
export declare function readBlockReason(target: string): PathVerdict;
|
|
11
13
|
/** 写这个路径要不要硬拒(硬拒 = 任何模式都不放行,包括审批)。 */
|
|
12
14
|
export declare function writeHardBlockReason(target: string): PathVerdict;
|
|
13
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* 这个写操作是不是「说明书」类改动(永远要弹一次卡,不受权限模式影响)。
|
|
17
|
+
*
|
|
18
|
+
* 字面路径与真实路径各判一次:软链/junction 指到 dsc 的配置文件时,只判字面路径会漏。
|
|
19
|
+
*/
|
|
14
20
|
export declare function isProtectedInstruction(target: string, cwd: string): PathVerdict;
|
|
15
21
|
/** 记录一次读取(read 工具执行后调用),带上当时的修改时间。按会话记账(0.6.48)。 */
|
|
16
22
|
export declare function noteRead(target: string, sessionId: string): void;
|
|
@@ -28,5 +34,11 @@ export declare function staleOverwriteReason(target: string, sessionId: string):
|
|
|
28
34
|
export declare function staleEditReason(target: string, sessionId: string): PathVerdict;
|
|
29
35
|
/** 清掉某个会话的读取台账(agent 收摊时调用,防长会话窗口里台账无界增长)。 */
|
|
30
36
|
export declare function clearReadLedger(sessionId: string): void;
|
|
37
|
+
/** `~` 开头展开成用户目录;其余原样返回(相对路径交给后续文件操作按 cwd 解析)。
|
|
38
|
+
*
|
|
39
|
+
* 为什么放这里:此前 `core/spill.ts` 与 `core/lifecycle-hooks.ts` 各写了一份逐字相同的
|
|
40
|
+
* `expandHome` / `expandPath`,而「用户写的路径怎么解释」本来就是本模块的事。
|
|
41
|
+
*/
|
|
42
|
+
export declare function expandHome(text: string): string;
|
|
31
43
|
/** 主目录(测试与提示词用)。 */
|
|
32
44
|
export declare function userHome(): string;
|
package/lib/core/path-policy.js
CHANGED
|
@@ -53,7 +53,7 @@ const READ_DENIED_EXTENSIONS = [
|
|
|
53
53
|
/** 命中即拒读的目录片段(路径里出现这一截就整条拒)。 */
|
|
54
54
|
const READ_DENIED_DIR_SEGMENTS = ['.ssh', '.aws', '.gnupg', '.docker', 'credentials', 'vault'];
|
|
55
55
|
/** `.env.xxx` 这一族(.env.production、.env.staging…)也拒读,只放行 .env.example。 */
|
|
56
|
-
function isEnvFamily(name) {
|
|
56
|
+
export function isEnvFamily(name) {
|
|
57
57
|
const base = name.toLowerCase();
|
|
58
58
|
return base.startsWith('.env') && !base.includes('example') && !base.includes('sample') && !base.includes('template');
|
|
59
59
|
}
|
|
@@ -127,10 +127,37 @@ export function isInsideCwd(cwd, target) {
|
|
|
127
127
|
const base = realPath(cwd);
|
|
128
128
|
const child = realPath(target);
|
|
129
129
|
const rel = relative(base, child);
|
|
130
|
-
|
|
130
|
+
// 只有 `..` 本身或以 `..` + 分隔符开头才是父目录;`..foo` 是根内的普通文件。
|
|
131
|
+
const parent = rel === '..' || rel.startsWith(`..${sep}`);
|
|
132
|
+
return rel === '' || (!parent && !isAbsolute(rel));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 判路径策略时要看的所有写法:字面路径 + 跟到底的真实路径。
|
|
136
|
+
*
|
|
137
|
+
* 为什么必须跟一遍(2026-10-30 审查):以前只看字面路径,把 ~/.ssh/id_rsa 软链成
|
|
138
|
+
* notes.txt 之后读 notes.txt 就绕过了整张读禁清单——写侧同理(软链指到 dsc 的配置文件
|
|
139
|
+
* 就能免掉「改说明书必须当面确认」)。Windows 上文件软链要管理员/开发者模式,目录 junction
|
|
140
|
+
* 不需要,所以这条洞在默认环境里是真实可达的。真实路径与字面路径相同时只判一次。
|
|
141
|
+
*
|
|
142
|
+
* @param target - 调用方给的路径(相对路径按进程目录展开)。
|
|
143
|
+
* @returns 去重后的路径清单:字面路径在前,真实路径在后。
|
|
144
|
+
*/
|
|
145
|
+
function policyPaths(target) {
|
|
146
|
+
const literal = resolve(target);
|
|
147
|
+
const real = realPath(literal);
|
|
148
|
+
return normalizeKey(real) === normalizeKey(literal) ? [literal] : [literal, real];
|
|
131
149
|
}
|
|
132
150
|
/** 读这个路径要不要拒。 */
|
|
133
151
|
export function readBlockReason(target) {
|
|
152
|
+
for (const candidate of policyPaths(target)) {
|
|
153
|
+
const verdict = readBlockReasonOne(candidate);
|
|
154
|
+
if (verdict !== null)
|
|
155
|
+
return verdict;
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
/** 读禁判定的单路径版本(字面与真实路径各判一次)。 */
|
|
160
|
+
function readBlockReasonOne(target) {
|
|
134
161
|
const name = basename(target);
|
|
135
162
|
const lowered = name.toLowerCase();
|
|
136
163
|
if (isEnvFamily(lowered)) {
|
|
@@ -157,6 +184,15 @@ export function readBlockReason(target) {
|
|
|
157
184
|
}
|
|
158
185
|
/** 写这个路径要不要硬拒(硬拒 = 任何模式都不放行,包括审批)。 */
|
|
159
186
|
export function writeHardBlockReason(target) {
|
|
187
|
+
for (const candidate of policyPaths(target)) {
|
|
188
|
+
const verdict = writeHardBlockReasonOne(candidate);
|
|
189
|
+
if (verdict !== null)
|
|
190
|
+
return verdict;
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
/** 写硬拒的单路径版本:字面路径与真实路径各判一次,软链指到禁写区也拦得住。 */
|
|
195
|
+
function writeHardBlockReasonOne(target) {
|
|
160
196
|
const candidate = target.replace(/[\\/]+$/, '');
|
|
161
197
|
for (const { re, why } of WRITE_DENIED_PATTERNS) {
|
|
162
198
|
if (re.test(candidate) || re.test(candidate.replace(/\\/g, '/')))
|
|
@@ -168,29 +204,50 @@ export function writeHardBlockReason(target) {
|
|
|
168
204
|
}
|
|
169
205
|
return null;
|
|
170
206
|
}
|
|
171
|
-
/**
|
|
207
|
+
/**
|
|
208
|
+
* 这个写操作是不是「说明书」类改动(永远要弹一次卡,不受权限模式影响)。
|
|
209
|
+
*
|
|
210
|
+
* 字面路径与真实路径各判一次:软链/junction 指到 dsc 的配置文件时,只判字面路径会漏。
|
|
211
|
+
*/
|
|
172
212
|
export function isProtectedInstruction(target, cwd) {
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (normalizeKey(target).startsWith(normalizeKey(DSC_HOME))) {
|
|
178
|
-
return `${name} 是 dsc 的控制文件,改动它必须用户当面确认一次。`;
|
|
179
|
-
}
|
|
180
|
-
// 工作区外的 settings.json 多半是别的软件的(VS Code 用户设置这类),不归这层管。
|
|
181
|
-
if (name === 'settings.json' && !isInsideCwd(cwd, target))
|
|
182
|
-
return null;
|
|
183
|
-
return `${name} 是给 agent 看的说明书或 dsc 的配置,改动它必须用户当面确认一次。`;
|
|
213
|
+
for (const candidate of policyPaths(target)) {
|
|
214
|
+
const verdict = isProtectedInstructionOne(candidate, cwd);
|
|
215
|
+
if (verdict !== null)
|
|
216
|
+
return verdict;
|
|
184
217
|
}
|
|
185
218
|
return null;
|
|
186
219
|
}
|
|
220
|
+
/** 说明书写判定的单路径版本。 */
|
|
221
|
+
function isProtectedInstructionOne(target, cwd) {
|
|
222
|
+
const name = basename(target).toLowerCase();
|
|
223
|
+
if (!PROTECTED_INSTRUCTION_BASENAMES.has(name))
|
|
224
|
+
return null;
|
|
225
|
+
// dsc 自己目录下的控制文件不豁免:它们就是权限体系本身,模型改它们等于自己给自己改权限
|
|
226
|
+
// (2026-09-29 审查发现原来的豁免让 ~/.dsc/settings.json 与 plugins.json 免卡可写)。
|
|
227
|
+
if (normalizeKey(target).startsWith(normalizeKey(DSC_HOME))) {
|
|
228
|
+
return `${name} 是 dsc 的控制文件,改动它必须用户当面确认一次。`;
|
|
229
|
+
}
|
|
230
|
+
// 工作区外的 settings.json 多半是别的软件的(VS Code 用户设置这类),不归这层管。
|
|
231
|
+
if (name === 'settings.json' && !isInsideCwd(cwd, target))
|
|
232
|
+
return null;
|
|
233
|
+
return `${name} 是给 agent 看的说明书或 dsc 的配置,改动它必须用户当面确认一次。`;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* 台账的键:真实路径(软链别名与它指向的文件记同一笔)。
|
|
237
|
+
*
|
|
238
|
+
* 不跟真实路径的话,「读 link.txt、写真实文件」这一对就查不到记录,
|
|
239
|
+
* 整写覆盖检查(没读过就整写)会被一条软链绕过去。
|
|
240
|
+
*/
|
|
241
|
+
function ledgerKey(target) {
|
|
242
|
+
return normalizeKey(realPath(resolve(target)));
|
|
243
|
+
}
|
|
187
244
|
/** 记录一次读取(read 工具执行后调用),带上当时的修改时间。按会话记账(0.6.48)。 */
|
|
188
245
|
export function noteRead(target, sessionId) {
|
|
189
246
|
try {
|
|
190
|
-
ledgerOf(sessionId).set(
|
|
247
|
+
ledgerOf(sessionId).set(ledgerKey(target), statSync(target).mtimeMs);
|
|
191
248
|
}
|
|
192
249
|
catch {
|
|
193
|
-
ledgerOf(sessionId).delete(
|
|
250
|
+
ledgerOf(sessionId).delete(ledgerKey(target));
|
|
194
251
|
}
|
|
195
252
|
}
|
|
196
253
|
/** 记录一次写入(write/edit 成功后调用),免得刚写完的文件被自己拦成「已变」。 */
|
|
@@ -209,7 +266,7 @@ export function staleOverwriteReason(target, sessionId) {
|
|
|
209
266
|
catch {
|
|
210
267
|
return null; // 文件不存在 = 新建,没有覆盖问题
|
|
211
268
|
}
|
|
212
|
-
const seen = ledgerOf(sessionId).get(
|
|
269
|
+
const seen = ledgerOf(sessionId).get(ledgerKey(target));
|
|
213
270
|
if (seen === undefined) {
|
|
214
271
|
return `${basename(target)} 已存在但本次会话没读过它。先读一遍再整写,不然会把别人改过的内容整片抹掉。`;
|
|
215
272
|
}
|
|
@@ -223,7 +280,7 @@ export function staleOverwriteReason(target, sessionId) {
|
|
|
223
280
|
* edit 自己会现读盘上现值,没读过的文件也允许直接改(这是它与整写覆盖的语义差别)。
|
|
224
281
|
*/
|
|
225
282
|
export function staleEditReason(target, sessionId) {
|
|
226
|
-
const seen = ledgerOf(sessionId).get(
|
|
283
|
+
const seen = ledgerOf(sessionId).get(ledgerKey(target));
|
|
227
284
|
if (seen === undefined)
|
|
228
285
|
return null;
|
|
229
286
|
let mtime;
|
|
@@ -242,6 +299,18 @@ export function staleEditReason(target, sessionId) {
|
|
|
242
299
|
export function clearReadLedger(sessionId) {
|
|
243
300
|
readLedger.delete(sessionId);
|
|
244
301
|
}
|
|
302
|
+
/** `~` 开头展开成用户目录;其余原样返回(相对路径交给后续文件操作按 cwd 解析)。
|
|
303
|
+
*
|
|
304
|
+
* 为什么放这里:此前 `core/spill.ts` 与 `core/lifecycle-hooks.ts` 各写了一份逐字相同的
|
|
305
|
+
* `expandHome` / `expandPath`,而「用户写的路径怎么解释」本来就是本模块的事。
|
|
306
|
+
*/
|
|
307
|
+
export function expandHome(text) {
|
|
308
|
+
if (text === '~')
|
|
309
|
+
return homedir();
|
|
310
|
+
if (text.startsWith('~/') || text.startsWith('~\\'))
|
|
311
|
+
return join(homedir(), text.slice(2));
|
|
312
|
+
return text;
|
|
313
|
+
}
|
|
245
314
|
/** 主目录(测试与提示词用)。 */
|
|
246
315
|
export function userHome() {
|
|
247
316
|
return homedir();
|
|
@@ -37,11 +37,15 @@ export interface PermissionPreset {
|
|
|
37
37
|
/** 不匹配任何预设时读到的名字。它不是可选项:能停在上面,但 `use('custom')` 会被拒。 */
|
|
38
38
|
export declare const CUSTOM_PERMISSION_PRESET = "custom";
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
40
|
+
* 出厂四个。取值对齐 dsh(`packages/bundle/base/cordis.patch.yml:265-277` 与
|
|
41
|
+
* `packages/experimental/auto-review`):
|
|
42
|
+
* read-only —— read-only 沙箱 + ask(沙箱拦下、问一次才放行);
|
|
43
|
+
* workspace —— workspace-write 沙箱 + ask(默认档);
|
|
44
|
+
* full-access —— danger-full-access 沙箱 + never(不问);
|
|
45
|
+
* auto-review —— danger-full-access 沙箱 + ask + 每次调用先过模型判官。
|
|
46
|
+
*
|
|
47
|
+
* Pneuma 的 `ApprovalPolicy` 只有三档,没有单独的 `ask`:`auto-edit` 就是那根
|
|
48
|
+
* 「该问就问」的旋钮(工作区内写免卡、其余问),所以只读档与工作区档都读它。
|
|
45
49
|
*/
|
|
46
50
|
export declare const BUILTIN_PERMISSION_PRESETS: readonly PermissionPreset[];
|
|
47
51
|
/** 新会话默认落在哪一档(出厂 = 工作区可写;与内核的两根默认值一致)。 */
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
/** 不匹配任何预设时读到的名字。它不是可选项:能停在上面,但 `use('custom')` 会被拒。 */
|
|
2
2
|
export const CUSTOM_PERMISSION_PRESET = 'custom';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* 出厂四个。取值对齐 dsh(`packages/bundle/base/cordis.patch.yml:265-277` 与
|
|
5
|
+
* `packages/experimental/auto-review`):
|
|
6
|
+
* read-only —— read-only 沙箱 + ask(沙箱拦下、问一次才放行);
|
|
7
|
+
* workspace —— workspace-write 沙箱 + ask(默认档);
|
|
8
|
+
* full-access —— danger-full-access 沙箱 + never(不问);
|
|
9
|
+
* auto-review —— danger-full-access 沙箱 + ask + 每次调用先过模型判官。
|
|
10
|
+
*
|
|
11
|
+
* Pneuma 的 `ApprovalPolicy` 只有三档,没有单独的 `ask`:`auto-edit` 就是那根
|
|
12
|
+
* 「该问就问」的旋钮(工作区内写免卡、其余问),所以只读档与工作区档都读它。
|
|
9
13
|
*/
|
|
10
14
|
export const BUILTIN_PERMISSION_PRESETS = [
|
|
11
15
|
{
|
|
12
16
|
name: 'read-only',
|
|
13
17
|
label: '只读',
|
|
14
|
-
description: '
|
|
18
|
+
description: '读文件、查状态直接过;写盘、执行命令、改机器先问你,允许这一次才动手',
|
|
15
19
|
sandbox: 'read-only',
|
|
16
|
-
|
|
20
|
+
// 参考实现的只读档是「只读沙箱 + ask」:沙箱拦下,用户仍可点一次放行。
|
|
21
|
+
// 这里用 `auto-edit` 承担 ask 的角色(Pneuma 没有单独的 ask 档)——
|
|
22
|
+
// 沙箱边界由审批的第 4 层判定,不会因为这一档自动放行而消失。
|
|
23
|
+
policy: 'auto-edit',
|
|
17
24
|
reviewer: 'user',
|
|
18
25
|
builtin: true,
|
|
19
26
|
},
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 权限三项的「按会话」读写(沙箱档位 / 权限模式 / 审阅者)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单开一层:这三项原来分别是 approval 与 sandbox 插件里的进程级变量
|
|
5
|
+
* (2026-10-28 用户报障:在 A 会话切「只读」,B 会话和后台 agent 一起变)。
|
|
6
|
+
* 会话日志本来就带 `state` 条目,把三项写进去即可跟着会话走——切换、恢复、
|
|
7
|
+
* 分叉、归档都不用额外的登记表。
|
|
8
|
+
*
|
|
9
|
+
* 口径照 dsh 的 `permission-presets`:**会话值优先,缺项才用默认值**;默认值
|
|
10
|
+
* 只对「还没钉过的会话」生效,钉住之后改默认值不影响它(老会话第一次打开时
|
|
11
|
+
* 把当时生效的值钉进内存,而不是让它跟着偏好漂)。
|
|
12
|
+
*
|
|
13
|
+
* 补钉只改内存、不立刻写盘(2026-11-03):打开会话会补三条默认值,以前当场
|
|
14
|
+
* 追加进 jsonl,「只看一眼」也会刷新文件 mtime,侧栏的「最近使用」跟着跳成
|
|
15
|
+
* 「刚刚」。现在补钉值等下一次真正写日志时顺带落盘,见 {@link pinPermission}。
|
|
16
|
+
*
|
|
17
|
+
* 这一层是纯的:不读磁盘、不认识插件,只认一个最小的会话形状,探针可以直读。
|
|
18
|
+
*
|
|
19
|
+
* @module dsc/core/permission-scope
|
|
20
|
+
*/
|
|
21
|
+
import type { ApprovalPolicy, ApprovalReviewer, SandboxMode } from '../contract.js';
|
|
22
|
+
/** 会话里存的权限三项;`null` = 这一项还没钉过(读的时候补默认值并钉住)。 */
|
|
23
|
+
export interface SessionPermissionState {
|
|
24
|
+
sandbox: SandboxMode | null;
|
|
25
|
+
policy: ApprovalPolicy | null;
|
|
26
|
+
reviewer: ApprovalReviewer | null;
|
|
27
|
+
}
|
|
28
|
+
/** 解析后的三项(都有值)。 */
|
|
29
|
+
export interface PermissionKnobs {
|
|
30
|
+
sandbox: SandboxMode;
|
|
31
|
+
policy: ApprovalPolicy;
|
|
32
|
+
reviewer: ApprovalReviewer;
|
|
33
|
+
}
|
|
34
|
+
/** 存权限需要的会话最小面(`Session` 结构上满足它;探针用假对象也能测)。 */
|
|
35
|
+
export interface PermissionSession {
|
|
36
|
+
state(id: 'permissions'): SessionPermissionState | undefined;
|
|
37
|
+
/** 立刻落盘(用户真改了档位时用)。 */
|
|
38
|
+
appendState(id: 'permissions', payload: SessionPermissionState): void;
|
|
39
|
+
/**
|
|
40
|
+
* 只记内存、等下一次写日志时顺带落盘(读路径补默认值用)。
|
|
41
|
+
* 老调用方的假会话没有这一项,{@link pinPermission} 会退回 `appendState`。
|
|
42
|
+
*/
|
|
43
|
+
setState?(id: 'permissions', payload: SessionPermissionState): void;
|
|
44
|
+
}
|
|
45
|
+
/** 三项的中文名(诊断与报错用)。 */
|
|
46
|
+
export declare const PERMISSION_FIELD_LABEL: Record<keyof SessionPermissionState, string>;
|
|
47
|
+
/** 读会话里已经钉住的三项;没有就是全 `null`(老会话与刚建的会话都会走到这里)。 */
|
|
48
|
+
export declare function storedPermissions(session: PermissionSession): SessionPermissionState;
|
|
49
|
+
/**
|
|
50
|
+
* 把一批值并进会话状态;只有真变了才写一条(避免每次读都往日志里塞重复行)。
|
|
51
|
+
* @returns 这次有没有写。
|
|
52
|
+
*/
|
|
53
|
+
export declare function writePermissions(session: PermissionSession, patch: Partial<SessionPermissionState>): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* 取某一项:会话里钉过就用它,没钉过就落 `fallback` 并钉住。
|
|
56
|
+
*
|
|
57
|
+
* 为什么在读取时钉、而不是只在启动/切会话时钉:沙箱是官方可开关插件,挂载顺序
|
|
58
|
+
* 晚于 permission-presets;谁先被问谁完成钉住,三条插件都不会读到「半份状态」。
|
|
59
|
+
* 钉的动作只在内存里做(见 {@link pinPermission}),不为了「看一眼」改文件。
|
|
60
|
+
*/
|
|
61
|
+
export declare function permissionOf<K extends keyof SessionPermissionState>(session: PermissionSession, key: K, fallback: NonNullable<SessionPermissionState[K]>): NonNullable<SessionPermissionState[K]>;
|
|
62
|
+
/** 一次解析三项:缺哪项补哪项(三项的默认值由调用方各给各的)。 */
|
|
63
|
+
export declare function resolvePermissions(session: PermissionSession, defaults: PermissionKnobs): PermissionKnobs;
|
|
64
|
+
/** 三项是否完全一致(预设 apply 用它算「这次到底要改几根」)。 */
|
|
65
|
+
export declare function samePermissionKnobs(left: PermissionKnobs, right: PermissionKnobs): boolean;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/** 三项的中文名(诊断与报错用)。 */
|
|
2
|
+
export const PERMISSION_FIELD_LABEL = {
|
|
3
|
+
sandbox: '沙箱档位',
|
|
4
|
+
policy: '权限模式',
|
|
5
|
+
reviewer: '审阅者',
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* 最小假会话的兜底存储(探针与老调用方给的对象没有 state/appendState)。
|
|
9
|
+
* 真实 Session 永远走日志条目;这里只保证「同一个假对象读得到自己刚写的值」。
|
|
10
|
+
*/
|
|
11
|
+
const fallbackStates = new WeakMap();
|
|
12
|
+
/** 有 id 的假会话按 id 记:探针的 current() 每次返回新对象,按对象记会丢。 */
|
|
13
|
+
const fallbackById = new Map();
|
|
14
|
+
/** 假会话的兜底槽:有 meta.id 按 id,没有才按对象。 */
|
|
15
|
+
function fallbackOf(session) {
|
|
16
|
+
const id = session.meta?.id;
|
|
17
|
+
if (typeof id === 'string' && id !== '')
|
|
18
|
+
return fallbackById.get(id);
|
|
19
|
+
return fallbackStates.get(session);
|
|
20
|
+
}
|
|
21
|
+
/** 写假会话的兜底槽(与 {@link fallbackOf} 同一个键口径)。 */
|
|
22
|
+
function setFallbackOf(session, state) {
|
|
23
|
+
const id = session.meta?.id;
|
|
24
|
+
if (typeof id === 'string' && id !== '') {
|
|
25
|
+
fallbackById.set(id, state);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
fallbackStates.set(session, state);
|
|
29
|
+
}
|
|
30
|
+
/** 读会话里已经钉住的三项;没有就是全 `null`(老会话与刚建的会话都会走到这里)。 */
|
|
31
|
+
export function storedPermissions(session) {
|
|
32
|
+
const raw = typeof session.state === 'function'
|
|
33
|
+
? session.state('permissions')
|
|
34
|
+
: fallbackOf(session);
|
|
35
|
+
return {
|
|
36
|
+
sandbox: raw?.sandbox ?? null,
|
|
37
|
+
policy: raw?.policy ?? null,
|
|
38
|
+
reviewer: raw?.reviewer ?? null,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 把一批值并进会话状态;只有真变了才写一条(避免每次读都往日志里塞重复行)。
|
|
43
|
+
* @returns 这次有没有写。
|
|
44
|
+
*/
|
|
45
|
+
export function writePermissions(session, patch) {
|
|
46
|
+
const before = storedPermissions(session);
|
|
47
|
+
const after = {
|
|
48
|
+
sandbox: patch.sandbox ?? before.sandbox,
|
|
49
|
+
policy: patch.policy ?? before.policy,
|
|
50
|
+
reviewer: patch.reviewer ?? before.reviewer,
|
|
51
|
+
};
|
|
52
|
+
if (after.sandbox === before.sandbox && after.policy === before.policy && after.reviewer === before.reviewer)
|
|
53
|
+
return false;
|
|
54
|
+
if (typeof session.appendState === 'function')
|
|
55
|
+
session.appendState('permissions', after);
|
|
56
|
+
else
|
|
57
|
+
setFallbackOf(session, after);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 补默认值时的写入:先记内存,下一次真正写日志时再跟着落盘。
|
|
62
|
+
*
|
|
63
|
+
* 为什么单独一条(2026-11-03 用户报障「点一下会话,时间就变刚刚」):补钉发生在
|
|
64
|
+
* **读**的时候,以前直接 `appendState`,于是「只是点开看一眼」也会往会话日志里
|
|
65
|
+
* 追加三条 state、把文件 mtime 刷新成现在,侧栏的「最近使用」跟着跳到「刚刚」。
|
|
66
|
+
* 补钉值在同一进程里立刻生效,磁盘上等用户下一次说话/切档位时顺带带出即可。
|
|
67
|
+
*
|
|
68
|
+
* `appendState` 只留给用户真的动了档位那条路(见 {@link writePermissions})。
|
|
69
|
+
*/
|
|
70
|
+
function pinPermission(session, patch) {
|
|
71
|
+
const before = storedPermissions(session);
|
|
72
|
+
const after = {
|
|
73
|
+
sandbox: patch.sandbox ?? before.sandbox,
|
|
74
|
+
policy: patch.policy ?? before.policy,
|
|
75
|
+
reviewer: patch.reviewer ?? before.reviewer,
|
|
76
|
+
};
|
|
77
|
+
if (typeof session.setState === 'function')
|
|
78
|
+
session.setState('permissions', after);
|
|
79
|
+
else if (typeof session.appendState === 'function')
|
|
80
|
+
session.appendState('permissions', after);
|
|
81
|
+
else
|
|
82
|
+
setFallbackOf(session, after);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 取某一项:会话里钉过就用它,没钉过就落 `fallback` 并钉住。
|
|
86
|
+
*
|
|
87
|
+
* 为什么在读取时钉、而不是只在启动/切会话时钉:沙箱是官方可开关插件,挂载顺序
|
|
88
|
+
* 晚于 permission-presets;谁先被问谁完成钉住,三条插件都不会读到「半份状态」。
|
|
89
|
+
* 钉的动作只在内存里做(见 {@link pinPermission}),不为了「看一眼」改文件。
|
|
90
|
+
*/
|
|
91
|
+
export function permissionOf(session, key, fallback) {
|
|
92
|
+
const stored = storedPermissions(session)[key];
|
|
93
|
+
if (stored !== undefined && stored !== null)
|
|
94
|
+
return stored;
|
|
95
|
+
pinPermission(session, { [key]: fallback });
|
|
96
|
+
return fallback;
|
|
97
|
+
}
|
|
98
|
+
/** 一次解析三项:缺哪项补哪项(三项的默认值由调用方各给各的)。 */
|
|
99
|
+
export function resolvePermissions(session, defaults) {
|
|
100
|
+
return {
|
|
101
|
+
sandbox: permissionOf(session, 'sandbox', defaults.sandbox),
|
|
102
|
+
policy: permissionOf(session, 'policy', defaults.policy),
|
|
103
|
+
reviewer: permissionOf(session, 'reviewer', defaults.reviewer),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** 三项是否完全一致(预设 apply 用它算「这次到底要改几根」)。 */
|
|
107
|
+
export function samePermissionKnobs(left, right) {
|
|
108
|
+
return left.sandbox === right.sandbox && left.policy === right.policy && left.reviewer === right.reviewer;
|
|
109
|
+
}
|