@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/plugins/approval.js
CHANGED
|
@@ -32,12 +32,19 @@ import { argsSummary, callFacts, stripBaseline } from '../core/tools.js';
|
|
|
32
32
|
import { summarizeChange } from '../core/tools/fs-tools.js';
|
|
33
33
|
import { SANDBOX_PERMISSION_EFFECT, readSandboxRequest } from '../core/tools/sandbox-args.js';
|
|
34
34
|
import { REJECTED_TOOL_TEXT } from '../core/session.js';
|
|
35
|
+
import { permissionOf, writePermissions } from '../core/permission-scope.js';
|
|
35
36
|
import { resolvePluginConfig } from '../core/plugin-registry.js';
|
|
36
37
|
import { toolApprovalGuard } from '../core/tool-guards.js';
|
|
37
38
|
import { activeRules, appendRule, classifyCommand, reloadActiveRules } from '../core/command-policy.js';
|
|
38
39
|
import { isInsideCwd, isProtectedInstruction, writeHardBlockReason } from '../core/path-policy.js';
|
|
39
40
|
import { audit } from '../core/audit.js';
|
|
40
41
|
import { redact } from '../core/secrets.js';
|
|
42
|
+
import { callMeaning } from '../core/call-meaning.js';
|
|
43
|
+
import { appendUsageRecord } from '../core/usage-log.js';
|
|
44
|
+
import { SUMMARY_BANNER } from '../core/compact-anchors.js';
|
|
45
|
+
import { TEAMMATE_REPORT_OPEN } from '../core/team-board.js';
|
|
46
|
+
import { TODO_REMINDER_TEXT } from '../core/todo-reminder.js';
|
|
47
|
+
import { contentText } from '../core/llm.js';
|
|
41
48
|
/** 配置键(`~/.dsc/plugins.json` 条目树里 `file` 等于这个名字那一项的 `config`)。 */
|
|
42
49
|
const CONFIG_KEY = 'approval';
|
|
43
50
|
/** 审批卡等多久没人答就按拒处理(抄 Hermes 的 approvals.timeout 默认 300s);配置没给时用这个。 */
|
|
@@ -71,17 +78,6 @@ const REVIEWER_OPTIONS = [
|
|
|
71
78
|
hint: '要问的事先给模型判官看:判放行就直接过,判高风险或判不出来再落回你的审批卡',
|
|
72
79
|
},
|
|
73
80
|
];
|
|
74
|
-
/** 权限模式的中文长说法(通知、审计与设置回执共用一份,免得三处各写一套)。 */
|
|
75
|
-
function policyLabel(policy) {
|
|
76
|
-
switch (policy) {
|
|
77
|
-
case 'readonly':
|
|
78
|
-
return '仅查看(读类操作放行,写/执行类一律拒绝)';
|
|
79
|
-
case 'auto-edit':
|
|
80
|
-
return '工作区自动编辑(工作区内写操作自动放行,其余审批)';
|
|
81
|
-
default:
|
|
82
|
-
return '完全访问(全部工具自动放行,灾难性命令仍然拒)';
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
81
|
/** 写类工具里「目标在工作区内就能自动放行」的那几个。 */
|
|
86
82
|
const PATH_WRITE_TOOLS = new Set(['write', 'edit']);
|
|
87
83
|
/**
|
|
@@ -158,17 +154,68 @@ export async function approvalDiffOf(request) {
|
|
|
158
154
|
...(mismatch !== undefined ? { mismatch } : {}),
|
|
159
155
|
};
|
|
160
156
|
}
|
|
157
|
+
/** 复核时最多带上多少字用户原话:再多读者就分不清这是「这一轮的请求」还是整篇文档。 */
|
|
158
|
+
const REVIEW_USER_QUOTE_CHARS = 500;
|
|
159
|
+
/**
|
|
160
|
+
* 发起这次调用的会话里,用户这一轮到底说了什么。
|
|
161
|
+
*
|
|
162
|
+
* 从最后一条往前找真人 user 消息,跳过程序注入的几类(环境快照、todo 提醒、
|
|
163
|
+
* 钩子产出、队友汇报、压缩摘要)。这些消息也是 user 角色,但它们是程序写的,
|
|
164
|
+
* 拿它们当「用户原话」会让判官把系统的提醒当成用户的要求。
|
|
165
|
+
*
|
|
166
|
+
* 环境快照的「这是程序自动附上」那句话在正文**末尾**(前面是环境正文),
|
|
167
|
+
* 所以这里用 includes 而不是 startsWith;其余几类都按开头认。
|
|
168
|
+
*/
|
|
169
|
+
function lastUserWords(session) {
|
|
170
|
+
for (let i = session.messages.length - 1; i >= 0; i -= 1) {
|
|
171
|
+
const message = session.messages[i];
|
|
172
|
+
if (message.role !== 'user')
|
|
173
|
+
continue;
|
|
174
|
+
const text = contentText(message.content).trim();
|
|
175
|
+
if (text === '')
|
|
176
|
+
continue;
|
|
177
|
+
if (text === TODO_REMINDER_TEXT)
|
|
178
|
+
continue;
|
|
179
|
+
if (text.includes('(本条是程序在每次请求时自动附上的当前环境快照'))
|
|
180
|
+
continue;
|
|
181
|
+
if (text.startsWith('<external_content source="hook:'))
|
|
182
|
+
continue;
|
|
183
|
+
if (text.startsWith(TEAMMATE_REPORT_OPEN))
|
|
184
|
+
continue;
|
|
185
|
+
if (text.startsWith(SUMMARY_BANNER))
|
|
186
|
+
continue;
|
|
187
|
+
return text.length > REVIEW_USER_QUOTE_CHARS ? text.slice(0, REVIEW_USER_QUOTE_CHARS) : text;
|
|
188
|
+
}
|
|
189
|
+
return '';
|
|
190
|
+
}
|
|
161
191
|
export const approvalPlugin = {
|
|
162
192
|
name: 'approval',
|
|
163
193
|
inject: ['llm', 'session', 'guards', 'surfaces', 'waiting'],
|
|
164
194
|
provide: 'approval',
|
|
165
195
|
apply(ctx, passed) {
|
|
166
|
-
|
|
196
|
+
/**
|
|
197
|
+
* 三项权限**按会话**读(2026-10-28):这里不再是进程级变量。
|
|
198
|
+
* 会话没钉过时用偏好里的默认值,并在第一次读时钉进会话(见 core/permission-scope)。
|
|
199
|
+
*/
|
|
200
|
+
const defaultPolicy = () => ctx.get('settings')?.prefs().defaultPolicy ?? 'auto-edit';
|
|
167
201
|
/**
|
|
168
202
|
* 「要问的事先给谁看」——与权限模式正交的一根轴。
|
|
169
203
|
* `user` = 弹卡等用户点(出厂默认);`auto-review` = 先给模型判官,判不出来再落人工卡。
|
|
170
204
|
*/
|
|
171
|
-
|
|
205
|
+
const defaultReviewer = () => ctx.get('settings')?.prefs().defaultReviewer ?? 'user';
|
|
206
|
+
/** 这次判定属于哪个会话:请求带了路径就找那个常驻会话,否则看当前查看的。 */
|
|
207
|
+
const sessionOf = (sessionPath) => {
|
|
208
|
+
if (sessionPath !== undefined && sessionPath !== '') {
|
|
209
|
+
const found = ctx.get('agent')?.sessionFor(sessionPath);
|
|
210
|
+
if (found !== undefined)
|
|
211
|
+
return found;
|
|
212
|
+
}
|
|
213
|
+
return ctx.session.current();
|
|
214
|
+
};
|
|
215
|
+
/** 某个会话现在生效的权限模式。 */
|
|
216
|
+
const policyOf = (session) => permissionOf(session, 'policy', defaultPolicy());
|
|
217
|
+
/** 某个会话现在生效的审阅者。 */
|
|
218
|
+
const reviewerOf = (session) => permissionOf(session, 'reviewer', defaultReviewer());
|
|
172
219
|
// 每次弹卡现读:改了等待时限不必重启宿主,下一张卡就用新值。
|
|
173
220
|
const timeoutMs = () => readTimeout(passed);
|
|
174
221
|
/**
|
|
@@ -189,6 +236,17 @@ export const approvalPlugin = {
|
|
|
189
236
|
reloadRules();
|
|
190
237
|
/** 当前会话 id(授权键与审计都挂在它下面)。 */
|
|
191
238
|
const sessionId = () => ctx.session.current().meta.id;
|
|
239
|
+
/**
|
|
240
|
+
* 只取一句话(到第一个句号或换行为止)。
|
|
241
|
+
*
|
|
242
|
+
* 沙箱守卫的越界说明里带着「可写根:D:\dsh、D:\dsc\…\tmp\<uuid>」这一长串——那是给
|
|
243
|
+
* 排查用的,摆在卡片上换来的是用户根本读不完的一行字。卡片要的是「哪个路径不在范围内」,
|
|
244
|
+
* 后面那一串留在工具结果里。
|
|
245
|
+
*/
|
|
246
|
+
function firstSentence(text) {
|
|
247
|
+
const cut = text.search(/[。\n]/);
|
|
248
|
+
return cut < 0 ? text : text.slice(0, cut);
|
|
249
|
+
}
|
|
192
250
|
/** 这次判定属于哪个会话:请求带了发起方就按发起方(0.6.48 多 agent),否则看当前查看的。 */
|
|
193
251
|
const sidOf = (request) => request.sessionId ?? sessionId();
|
|
194
252
|
/** 这次判定的会话 jsonl 路径(侧栏状态点的键口径)。 */
|
|
@@ -242,6 +300,12 @@ export const approvalPlugin = {
|
|
|
242
300
|
};
|
|
243
301
|
/** 挂起人工审批卡:等到答案、等到超时、或等到本轮被打断。 */
|
|
244
302
|
const askHuman = (request, signal, input) => new Promise((resolveDone) => {
|
|
303
|
+
// 已经中止就是「这一轮已经取消」:这时再登记卡,abort 事件不会补发(EventTarget 语义),
|
|
304
|
+
// 卡要挂满超时才自解,用户看到的是一张没人管的幽灵卡。所以先看信号再决定要不要登记。
|
|
305
|
+
if (signal.aborted) {
|
|
306
|
+
resolveDone('reject');
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
245
309
|
// 没人能回答就不弹卡:超时按拒是同一条结论,只是早 300 秒给出,并且理由说清了为什么。
|
|
246
310
|
if (!someoneCanAnswer()) {
|
|
247
311
|
autoLog('auto-deny', request, '当前没有界面能回答审批卡(没有终端界面,也没有桌面客户端),按拒处理');
|
|
@@ -253,16 +317,17 @@ export const approvalPlugin = {
|
|
|
253
317
|
const view = {
|
|
254
318
|
id,
|
|
255
319
|
toolName: request.toolName,
|
|
256
|
-
argsSummary: redact(
|
|
320
|
+
argsSummary: redact(input.summary),
|
|
321
|
+
...(input.meaning === null ? {} : { meaning: input.meaning }),
|
|
257
322
|
reason: input.reason,
|
|
258
323
|
risk: input.risk,
|
|
259
324
|
suggestedRule: input.suggestedRule,
|
|
260
325
|
hardline: input.hardline,
|
|
261
326
|
scopes: input.scopes,
|
|
262
327
|
...(input.escalation === null ? {} : { escalation: input.escalation }),
|
|
263
|
-
policy,
|
|
264
|
-
reviewer,
|
|
265
|
-
mode:
|
|
328
|
+
policy: input.policy,
|
|
329
|
+
reviewer: input.reviewer,
|
|
330
|
+
mode: input.mode,
|
|
266
331
|
// 发起会话归属(0.6.49):卡片是全局渲染的,后台会话的卡弹出来时界面要标得清是谁家的
|
|
267
332
|
sessionPath: pathOf(request),
|
|
268
333
|
...(input.diff === null ? {} : { diff: input.diff }),
|
|
@@ -275,8 +340,8 @@ export const approvalPlugin = {
|
|
|
275
340
|
tool: request.toolName,
|
|
276
341
|
summary: view.argsSummary,
|
|
277
342
|
reason: input.reason,
|
|
278
|
-
policy,
|
|
279
|
-
mode:
|
|
343
|
+
policy: input.policy,
|
|
344
|
+
mode: input.mode,
|
|
280
345
|
sessionId: sid,
|
|
281
346
|
cwd: request.cwd,
|
|
282
347
|
});
|
|
@@ -301,8 +366,8 @@ export const approvalPlugin = {
|
|
|
301
366
|
summary: view.argsSummary,
|
|
302
367
|
decision: decision === 'reject' ? (phase === 'decided' ? 'reject' : phase) : decision,
|
|
303
368
|
reason: input.reason,
|
|
304
|
-
policy,
|
|
305
|
-
mode:
|
|
369
|
+
policy: input.policy,
|
|
370
|
+
mode: input.mode,
|
|
306
371
|
sessionId: sid,
|
|
307
372
|
...(source === undefined ? {} : { source }),
|
|
308
373
|
});
|
|
@@ -332,8 +397,8 @@ export const approvalPlugin = {
|
|
|
332
397
|
tool: request.toolName,
|
|
333
398
|
summary: redact(request.argsSummary),
|
|
334
399
|
reason,
|
|
335
|
-
policy,
|
|
336
|
-
mode: modeForCard,
|
|
400
|
+
policy: policyOf(sessionOf(request.sessionPath)),
|
|
401
|
+
mode: ctx.get('mode')?.modeFor(sidOf(request)) ?? modeForCard,
|
|
337
402
|
sessionId: sidOf(request),
|
|
338
403
|
cwd: request.cwd,
|
|
339
404
|
...extra,
|
|
@@ -344,10 +409,21 @@ export const approvalPlugin = {
|
|
|
344
409
|
* 风险分类照 Codex 的 guardian policy(数据外泄 / 凭据探测 / 持久性安全弱化 /
|
|
345
410
|
* 破坏性动作 / 低风险白名单,`prompts/templates/guardian/policy.md`)。
|
|
346
411
|
* 判到 high 或 critical 一律回落到人工卡——AI 不许替用户承担这个责任。
|
|
412
|
+
*
|
|
413
|
+
* 三种结局都要留痕:判官放行、判官否决、判官没跑完。少了任何一条,用户看到卡
|
|
414
|
+
* 就查不出「凭什么没自动过」——0.7.1 的实况是 91a667f5 会话弹了 3 张卡、审计里
|
|
415
|
+
* 0 条 auto-deny,连是不是判官挂了都答不上来。
|
|
347
416
|
*/
|
|
348
417
|
const aiReview = async (request, signal) => {
|
|
349
418
|
try {
|
|
350
|
-
|
|
419
|
+
// 判官跑在「发起这次调用的会话」的模型上(后台会话不拿当前视图的模型)
|
|
420
|
+
const reviewSession = sessionOf(request.sessionPath);
|
|
421
|
+
const route = ctx.llm.routeForSession(reviewSession);
|
|
422
|
+
// 判官要判断「用户有没有明确要求」,光看工具名与参数只能猜:把这一轮用户的原话
|
|
423
|
+
// 带上,它才知道这次调用是用户点名的、还是模型自己扩出来的。
|
|
424
|
+
const userWords = lastUserWords(reviewSession);
|
|
425
|
+
const startedAt = Date.now();
|
|
426
|
+
let firstDeltaAt = null;
|
|
351
427
|
const result = await ctx.llm.stream(route.api, {
|
|
352
428
|
baseUrl: route.baseUrl,
|
|
353
429
|
apiKey: route.apiKey,
|
|
@@ -368,70 +444,128 @@ export const approvalPlugin = {
|
|
|
368
444
|
'- 破坏性动作:递归删除、强推、清库、销毁基础设施、覆盖未读过的文件;\n' +
|
|
369
445
|
'- 低风险:读文件、查状态、跑测试、工作目录内的常规改动。\n' +
|
|
370
446
|
'判断要点:用户这一轮有没有明确要求做这件事?范围有没有被扩大?\n' +
|
|
447
|
+
'判断「用户有没有明确要求」以下面那段用户原话为准;用户自己点过名的本地路径,读它属于低风险。\n' +
|
|
371
448
|
'只输出一个 JSON:{"risk":"low|medium|high|critical","authorized":true|false,"reason":"一句话中文理由"}',
|
|
372
449
|
},
|
|
373
450
|
{
|
|
374
451
|
role: 'user',
|
|
375
|
-
content: redact(`工具:${request.toolName}\n参数:${JSON.stringify(request.args ?? request.argsSummary)}\n工作目录:${baseCwd(request)}`
|
|
452
|
+
content: redact(`工具:${request.toolName}\n参数:${JSON.stringify(request.args ?? request.argsSummary)}\n工作目录:${baseCwd(request)}` +
|
|
453
|
+
(userWords === '' ? '' : `\n用户这一轮的原话:${userWords}`)),
|
|
376
454
|
},
|
|
377
455
|
],
|
|
378
|
-
}, {
|
|
456
|
+
}, {
|
|
457
|
+
onDelta: () => {
|
|
458
|
+
if (firstDeltaAt === null)
|
|
459
|
+
firstDeltaAt = Date.now();
|
|
460
|
+
},
|
|
461
|
+
});
|
|
462
|
+
const finishedAt = Date.now();
|
|
463
|
+
// 判官这次请求也是真花掉的钱:有 usage 就按同一本账记一笔。记账放在解析裁决
|
|
464
|
+
// 之前(判官答非所问也照样计费),整段包在 try 里——少一条统计无所谓,
|
|
465
|
+
// 绝不能让记账改变复核结论或异常分支。
|
|
466
|
+
try {
|
|
467
|
+
if (result.usage) {
|
|
468
|
+
appendUsageRecord({
|
|
469
|
+
// route 里没有端点名,端点取这条会话现在生效的那一个(与请求实发的一路)
|
|
470
|
+
provider: ctx.llm.providerOf(reviewSession),
|
|
471
|
+
model: route.model,
|
|
472
|
+
i: result.usage.inputTokens,
|
|
473
|
+
o: result.usage.outputTokens,
|
|
474
|
+
...(result.usage.cacheHitTokens === undefined ? {} : { ch: result.usage.cacheHitTokens }),
|
|
475
|
+
...(result.usage.cacheMissTokens === undefined ? {} : { cm: result.usage.cacheMissTokens }),
|
|
476
|
+
sid: request.sessionId ?? reviewSession.meta.id,
|
|
477
|
+
lm: finishedAt - startedAt,
|
|
478
|
+
...(firstDeltaAt === null ? {} : { ft: firstDeltaAt - startedAt, d: finishedAt - firstDeltaAt }),
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
catch {
|
|
483
|
+
// 记账失败(端点名取不到等)不打断复核
|
|
484
|
+
}
|
|
379
485
|
const raw = result.text.slice(result.text.indexOf('{'), result.text.lastIndexOf('}') + 1);
|
|
380
486
|
const verdict = JSON.parse(raw);
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
487
|
+
// 只有 high / critical 必须落回人工卡;medium 与 low 走同一条路(放行),
|
|
488
|
+
// 所以这里是个布尔而不是三档——别把它读成「medium 被降级」。
|
|
489
|
+
const highRisk = verdict.risk === 'critical' || verdict.risk === 'high';
|
|
490
|
+
if (highRisk) {
|
|
491
|
+
const why = verdict.reason ?? '未说明';
|
|
492
|
+
autoLog('auto-deny', request, `AI 审查判为高风险:${why}`);
|
|
493
|
+
return { decision: null, note: `AI 复核判为高风险:${why}`, failed: false };
|
|
494
|
+
}
|
|
495
|
+
if (verdict.authorized === false) {
|
|
496
|
+
const why = verdict.reason?.trim() ?? '';
|
|
497
|
+
const said = why === '' ? '判官没给理由' : why;
|
|
498
|
+
autoLog('auto-deny', request, `AI 复核判不放行:${said}`);
|
|
499
|
+
return { decision: null, note: `AI 复核判不放行:${said}`, failed: false };
|
|
385
500
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
return 'allow-once';
|
|
501
|
+
autoLog('auto-allow', request, 'AI 复核放行');
|
|
502
|
+
return { decision: 'allow-once', note: 'AI 复核放行', failed: false };
|
|
389
503
|
}
|
|
390
|
-
catch {
|
|
391
|
-
|
|
504
|
+
catch (error) {
|
|
505
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
506
|
+
// 这一轮被用户打断:不是判官的问题,也别写成「回落到人工卡」——卡不会弹。
|
|
507
|
+
if (signal.aborted) {
|
|
508
|
+
autoLog('auto-deny', request, `AI 复核被这一轮的中止打断:${why}`);
|
|
509
|
+
return { decision: null, note: `AI 复核被中止(${why}),这次不执行`, failed: true };
|
|
510
|
+
}
|
|
511
|
+
// 判官超时、网络断、返回的不是 JSON:都算「没跑完」。这一类的去向由上面的调用方定
|
|
512
|
+
// (判官缺席就按权限档自己的结论走),这里只负责把原因写清楚。
|
|
513
|
+
autoLog('auto-deny', request, `AI 复核没跑完:${why}(这次不按复核否决处理)`);
|
|
514
|
+
return { decision: null, note: `AI 复核没跑完(${why}),这次交给你决定`, failed: true };
|
|
392
515
|
}
|
|
393
516
|
};
|
|
394
517
|
const service = {
|
|
395
518
|
get policy() {
|
|
396
|
-
return
|
|
519
|
+
return policyOf(ctx.session.current());
|
|
397
520
|
},
|
|
398
521
|
setPolicy(next) {
|
|
399
|
-
policy
|
|
400
|
-
//
|
|
401
|
-
|
|
522
|
+
writePermissions(ctx.session.current(), { policy: next });
|
|
523
|
+
// 不往对话里写「权限模式切换为…」(2026-10-28 用户报障):启动时 settings 与
|
|
524
|
+
// permission-presets 会各自按偏好复算一遍,同一组值能被写两三行;而这些值在输入框
|
|
525
|
+
// 那颗旋钮上一直看得见。要留痕的是审计(下一行),不是对话流。用户主动切换的回执
|
|
526
|
+
// 由调用方给:界面走 permission-presets 的那一句,斜杠命令由 commands 自己写。
|
|
402
527
|
audit({
|
|
403
528
|
ts: Date.now(),
|
|
404
529
|
kind: 'mode-change',
|
|
405
530
|
reason: `权限模式 → ${next}`,
|
|
406
531
|
policy: next,
|
|
407
|
-
mode: modeForCard,
|
|
532
|
+
mode: ctx.get('mode')?.modeFor(sessionId()) ?? modeForCard,
|
|
408
533
|
sessionId: sessionId(),
|
|
409
534
|
});
|
|
410
535
|
},
|
|
411
536
|
get reviewer() {
|
|
412
|
-
return
|
|
537
|
+
return reviewerOf(ctx.session.current());
|
|
413
538
|
},
|
|
414
539
|
setReviewer(next) {
|
|
415
|
-
reviewer
|
|
416
|
-
|
|
417
|
-
ctx.emit('dsc/notice', `审批审阅者切换为「${label}」${next === 'auto-review' ? ':要问的事先给模型判官,判不出来仍会问你' : ''}`);
|
|
540
|
+
writePermissions(ctx.session.current(), { reviewer: next });
|
|
541
|
+
// 与 setPolicy 同一条理由:这行曾是「新会话一进来就刷四五行」的一半噪声。
|
|
418
542
|
audit({
|
|
419
543
|
ts: Date.now(),
|
|
420
544
|
kind: 'mode-change',
|
|
421
545
|
reason: `审批审阅者 → ${next}`,
|
|
422
|
-
policy,
|
|
423
|
-
mode: modeForCard,
|
|
546
|
+
policy: policyOf(ctx.session.current()),
|
|
547
|
+
mode: ctx.get('mode')?.modeFor(sessionId()) ?? modeForCard,
|
|
424
548
|
sessionId: sessionId(),
|
|
425
549
|
});
|
|
426
550
|
},
|
|
427
551
|
async decide(request, signal, options) {
|
|
428
552
|
const cwd = baseCwd(request);
|
|
553
|
+
// 这个请求所属会话的三项权限:卡面、自动放行与审计都按它,不再读进程级变量。
|
|
554
|
+
const session = sessionOf(request.sessionPath);
|
|
555
|
+
const policy = permissionOf(session, 'policy', defaultPolicy());
|
|
556
|
+
const reviewer = permissionOf(session, 'reviewer', defaultReviewer());
|
|
557
|
+
// 卡面写「这次属于哪个模式」:按请求会话取,后台会话的卡不会标成当前视图的模式。
|
|
558
|
+
const cardMode = ctx.get('mode')?.modeFor(session.meta.id) ?? modeForCard;
|
|
429
559
|
// 安全钩子可以要求「这一次必须问人」:非空时下面所有自动放行档一律跳过。
|
|
430
560
|
const forced = options?.forceAskReason?.trim() ?? '';
|
|
431
561
|
const facts = callFacts(request.args ?? {}, cwd);
|
|
432
562
|
const target = facts.target ?? null;
|
|
433
563
|
const command = facts.command ?? null;
|
|
434
564
|
const insideCwd = target !== null && isInsideCwd(cwd, target);
|
|
565
|
+
// 卡片上给人看的两样东西:一行「这次要干什么」,一行命令原文。
|
|
566
|
+
// 命令原文直接当参数摘要用(不再套 JSON 壳),认不出命令时退回原来的摘要。
|
|
567
|
+
const meaning = callMeaning({ toolName: request.toolName, command, target });
|
|
568
|
+
const summary = command ?? request.argsSummary;
|
|
435
569
|
const verdict = command === null ? null : classifyCommand(command, { rules: activeRules() });
|
|
436
570
|
// 模型这次有没有在请求放宽沙箱(工具参数那条路)。有就摊到卡上,并据此收窄授权档位。
|
|
437
571
|
const request0 = readSandboxRequest(request.args ?? {});
|
|
@@ -488,12 +622,19 @@ export const approvalPlugin = {
|
|
|
488
622
|
if (forced === '' && protectedWhy === null && command !== null && floor !== undefined) {
|
|
489
623
|
const prefix = floor.whitelist(command);
|
|
490
624
|
if (prefix !== null) {
|
|
491
|
-
autoLog('auto-allow', request,
|
|
625
|
+
autoLog('auto-allow', request, `命中危险命令硬拦截白名单「${prefix.join(' ')}」,免审批卡`);
|
|
492
626
|
return 'allow-once';
|
|
493
627
|
}
|
|
494
628
|
}
|
|
629
|
+
// 第 4 层:沙箱边界。沙箱守卫(order 8)对「能问的越界」只 defer,
|
|
630
|
+
// 最后一道落在这里:越过沙箱的事一律跳过所有自动放行,直接弹卡(只给一次)。
|
|
631
|
+
// 这一层必须排在权限模式与审阅者之前——否则「完全访问」会把沙箱的拒绝吃掉。
|
|
632
|
+
const fence = ctx.get('sandbox')?.check(target ?? undefined, command ?? undefined, cwd, request.sessionPath);
|
|
633
|
+
const fenced = fence !== undefined && !fence.allowed;
|
|
634
|
+
/** 复核给出的「为什么没自动过」;null = 没跑复核,或复核放行了。要进卡片的理由。 */
|
|
635
|
+
let reviewNote = null;
|
|
495
636
|
// 第 5 层:权限模式自己的裁决(protected 文件不参与,强制走人工卡)。
|
|
496
|
-
if (protectedWhy === null && forced === '') {
|
|
637
|
+
if (protectedWhy === null && forced === '' && !fenced) {
|
|
497
638
|
if (policy === 'readonly') {
|
|
498
639
|
// 「仅查看」的字面意思就是只读:策略引擎判成 allow 的命令(查看目录、看 git 状态、
|
|
499
640
|
// 管道里只做筛选与格式化)原样放行,只有写与执行类才一律拒。
|
|
@@ -505,43 +646,68 @@ export const approvalPlugin = {
|
|
|
505
646
|
autoLog('auto-deny', request, '当前是「仅查看」权限模式,写与执行类工具一律拒绝');
|
|
506
647
|
return 'reject';
|
|
507
648
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
if (
|
|
514
|
-
|
|
649
|
+
// 权限档自己会不会放行这一次:返回放行理由,不放行给 null。
|
|
650
|
+
// 单独抽出来是为了让「复核没跑完」能走同一份判断(见下),两处不必各写一遍。
|
|
651
|
+
const policyAutoReason = () => {
|
|
652
|
+
if (policy === 'full-access')
|
|
653
|
+
return '当前是「完全访问」权限模式';
|
|
654
|
+
if (policy !== 'auto-edit')
|
|
655
|
+
return null;
|
|
656
|
+
// 工作区内免卡还要沙箱同意:沙箱档位是 read-only 时,同一个路径也不许写。
|
|
657
|
+
// 少了这一半,只读档会先被审批放行、再被沙箱拒,模型拿到的是「自动放行失败」。
|
|
658
|
+
const writable = PATH_WRITE_TOOLS.has(request.toolName) && insideCwd && (fence?.allowed ?? true);
|
|
659
|
+
if (writable)
|
|
660
|
+
return '工作区内的文件改动,按「工作区自动编辑」放行';
|
|
661
|
+
if (verdict !== null && verdict.decision === 'allow')
|
|
662
|
+
return `只读命令:${verdict.reason}`;
|
|
663
|
+
return null;
|
|
664
|
+
};
|
|
665
|
+
// 第 5.5 层(顺序在自动放行之前,2026-10-28 修):审阅者 auto-review 时
|
|
666
|
+
// **每一次走到这里的事**都先给模型判官看一眼——包括「完全访问」本来会直接
|
|
667
|
+
// 放行的那些。判 allow 直接过;判高风险或判不放行落回第 6 层人工卡。
|
|
668
|
+
// 只读档在上面已经拒了,轮不到判官放宽。
|
|
669
|
+
if (reviewer === 'auto-review') {
|
|
670
|
+
const reviewed = await aiReview(request, signal);
|
|
671
|
+
if (reviewed.decision !== null)
|
|
672
|
+
return reviewed.decision;
|
|
673
|
+
reviewNote = reviewed.note;
|
|
674
|
+
// 判官**没给意见**(超时、网络断、返回的不是 JSON)不等于判官否决:
|
|
675
|
+
// 这时结论回到用户自己选的那一档,不能因为对方网络抖一下就让用户来点卡。
|
|
676
|
+
// 判官明确说不放行的(deny)不在此列,它照旧弹卡;这一轮被打断时也不放行。
|
|
677
|
+
const fallback = reviewed.failed && !signal.aborted ? policyAutoReason() : null;
|
|
678
|
+
if (fallback !== null) {
|
|
679
|
+
autoLog('auto-allow', request, `AI 复核没跑完,按权限档放行:${fallback}`);
|
|
515
680
|
return 'allow-once';
|
|
516
681
|
}
|
|
517
|
-
|
|
518
|
-
|
|
682
|
+
}
|
|
683
|
+
else {
|
|
684
|
+
const allowed = policyAutoReason();
|
|
685
|
+
if (allowed !== null) {
|
|
686
|
+
autoLog('auto-allow', request, allowed);
|
|
519
687
|
return 'allow-once';
|
|
520
688
|
}
|
|
521
689
|
}
|
|
522
690
|
}
|
|
523
|
-
// 第 5.5 层:审阅者。`auto-review` 时**每一次走到这里的事**都先给模型判官看一眼
|
|
524
|
-
// ——这一步排在档位自动放行**之前**(等价于参考实现的 `strict_auto_review`),
|
|
525
|
-
// 所以「完全访问 + AI 复核」就是旧版的「AI 审查」档:谁也不自动放行,全过模型。
|
|
526
|
-
// 判 allow 直接过;判高风险或判不出来(含网络/超时/解析失败)落回第 6 层人工卡。
|
|
527
|
-
if (reviewer === 'auto-review' && protectedWhy === null && forced === '') {
|
|
528
|
-
const reviewed = await aiReview(request, signal);
|
|
529
|
-
if (reviewed !== null) {
|
|
530
|
-
autoLog('auto-allow', request, 'AI 复核放行');
|
|
531
|
-
return reviewed;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
691
|
// 第 6 层:人工审批卡。钩子要求确认时卡片上的原因就用它,用户才知道这张卡为什么非弹不可。
|
|
535
|
-
const
|
|
536
|
-
?
|
|
537
|
-
:
|
|
538
|
-
?
|
|
539
|
-
:
|
|
540
|
-
?
|
|
541
|
-
:
|
|
542
|
-
|
|
692
|
+
const baseReason = fenced
|
|
693
|
+
? `沙箱边界:${firstSentence(fence?.reason ?? '这次调用越界')}(允许这一次就破例执行,沙箱对这一次不再拦)`
|
|
694
|
+
: escalation !== null
|
|
695
|
+
? `模型请求放宽沙箱(${escalation.effect}):${escalation.justification}`
|
|
696
|
+
: forced !== ''
|
|
697
|
+
? forced
|
|
698
|
+
: protectedWhy !== null
|
|
699
|
+
? protectedWhy
|
|
700
|
+
: (verdict?.reason ?? (insideCwd ? '工作区内的改动需要确认' : '工作区外的改动需要确认'));
|
|
701
|
+
// 卡上写「为什么现在才问你」:复核否决或没跑完时以它为准。命令层那句「需要授权」
|
|
702
|
+
// 是兜底说法,用户对着它猜不出是判官不放行还是判官挂了(0.7.1 的实况)。
|
|
703
|
+
const reason = reviewNote ?? baseReason;
|
|
704
|
+
const risk = fenced || protectedWhy !== null ? 'high' : forced !== '' ? 'medium' : verdict?.decision === 'ask' ? 'medium' : insideCwd ? 'low' : 'medium';
|
|
543
705
|
const scopes = ['once'];
|
|
544
|
-
|
|
706
|
+
// 沙箱越界只给「这一次」:放宽写边界是逐次决定,跨调用持久化没人能替用户担保。
|
|
707
|
+
if (fenced) {
|
|
708
|
+
// 只留 once
|
|
709
|
+
}
|
|
710
|
+
else if (escalation === null) {
|
|
545
711
|
if (protectedWhy === null)
|
|
546
712
|
scopes.push('session');
|
|
547
713
|
if (suggested !== null && protectedWhy === null)
|
|
@@ -558,8 +724,13 @@ export const approvalPlugin = {
|
|
|
558
724
|
return askHuman(request, signal, {
|
|
559
725
|
reason,
|
|
560
726
|
risk,
|
|
727
|
+
summary,
|
|
728
|
+
meaning,
|
|
561
729
|
suggestedRule: suggested,
|
|
562
730
|
scopes,
|
|
731
|
+
policy,
|
|
732
|
+
reviewer,
|
|
733
|
+
mode: cardMode,
|
|
563
734
|
grantKey: key,
|
|
564
735
|
hardline: false,
|
|
565
736
|
diff,
|
|
@@ -568,10 +739,11 @@ export const approvalPlugin = {
|
|
|
568
739
|
});
|
|
569
740
|
},
|
|
570
741
|
surface() {
|
|
742
|
+
const current = ctx.session.current();
|
|
571
743
|
return {
|
|
572
|
-
current:
|
|
744
|
+
current: policyOf(current),
|
|
573
745
|
options: [...POLICY_OPTIONS],
|
|
574
|
-
reviewer,
|
|
746
|
+
reviewer: reviewerOf(current),
|
|
575
747
|
reviewerOptions: [...REVIEWER_OPTIONS],
|
|
576
748
|
};
|
|
577
749
|
},
|
|
@@ -612,7 +784,7 @@ export const approvalPlugin = {
|
|
|
612
784
|
tool: current.view.toolName,
|
|
613
785
|
rule: current.suggestedRule,
|
|
614
786
|
reason: '用户在审批卡上永久允许',
|
|
615
|
-
policy,
|
|
787
|
+
policy: current.view.policy,
|
|
616
788
|
sessionId: current.sessionId,
|
|
617
789
|
source,
|
|
618
790
|
});
|