@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/git-info.js
CHANGED
|
@@ -9,19 +9,33 @@
|
|
|
9
9
|
* 安全姿势照 codex /diff:execFile 固定子命令数组(无 shell、无拼接);
|
|
10
10
|
* `--no-textconv --no-ext-diff` 防文本转换与外部 diff driver 当场执行程序。
|
|
11
11
|
*
|
|
12
|
+
* 本模块同时放 /review 的「审查范围 + 完整 diff 落盘 + 会话账本(状态/取消)」:
|
|
13
|
+
* 这三件事是同一个功能的宿主侧基础设施,命令侧(派审查前后)与审查通道(收工/叫停)
|
|
14
|
+
* 都要读写同一份口径;分开两个文件只会多出一处「记录字段与谁对得上」的维护负担。
|
|
15
|
+
*
|
|
12
16
|
* @module dsc/core/git-info
|
|
13
17
|
*/
|
|
14
18
|
import { execFile } from 'node:child_process';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
19
|
+
import { createHash } from 'node:crypto';
|
|
20
|
+
import { mkdirSync, promises as fsp, readFileSync, writeFileSync } from 'node:fs';
|
|
21
|
+
import { dirname, join } from 'node:path';
|
|
22
|
+
import { dscPath } from './path-policy.js';
|
|
17
23
|
import { stripBaseline } from './tools.js';
|
|
18
24
|
import { summarizeChange } from './tools/fs-tools.js';
|
|
19
|
-
/** 审查 diff 塞进上下文的字符预算(约 1.5 万 token;超了从尾部截,头部是改动清单更值钱)。 */
|
|
20
|
-
export const REVIEW_DIFF_BUDGET = 60_000;
|
|
21
25
|
/** 受控执行 git(execFile 固定首参字面量 + 参数数组;无 shell)。 */
|
|
22
26
|
export function gitExec(cwd, args) {
|
|
27
|
+
return runGit(cwd, args, 8 * 1024 * 1024, 15000);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 受控执行 git 的唯一实现({@link gitExec} 与取数那几次调用都走它)。
|
|
31
|
+
*
|
|
32
|
+
* 为什么缓冲与超时要能传:一次审查的 diff 不再截断(截断会把「后面还有问题」的改动
|
|
33
|
+
* 整段藏起来),8 MB 的默认上限在中等规模仓库里就会 ENOBUFS 当场失败,而不是「慢一点」。
|
|
34
|
+
* 128 MB 的上限是防跑飞的闸,不是预期用量;超过它的 diff 本来也不该一次读进内存。
|
|
35
|
+
*/
|
|
36
|
+
function runGit(cwd, args, maxBuffer, timeout) {
|
|
23
37
|
return new Promise((resolveDone, rejectDone) => {
|
|
24
|
-
execFile('git', args, { cwd, maxBuffer
|
|
38
|
+
execFile('git', args, { cwd, maxBuffer, windowsHide: true, timeout, killSignal: 'SIGKILL' }, (error, stdout, stderr) => {
|
|
25
39
|
if (error !== undefined && error !== null)
|
|
26
40
|
rejectDone(new Error(String(stderr || error.message).slice(0, 400)));
|
|
27
41
|
else
|
|
@@ -29,12 +43,69 @@ export function gitExec(cwd, args) {
|
|
|
29
43
|
});
|
|
30
44
|
});
|
|
31
45
|
}
|
|
46
|
+
/** 取 diff 那几次 git 调用共用:缓冲 128 MB、超时 5 分钟(大仓库的一次 diff 就够慢)。 */
|
|
47
|
+
const gitForDiff = (cwd, args) => runGit(cwd, args, 128 * 1024 * 1024, 300_000);
|
|
48
|
+
/** 超过这个字节数的 diff 在「改动清单」末尾补一句读法提示(20 MB,见下)。 */
|
|
49
|
+
const HUGE_DIFF_BYTES = 20 * 1024 * 1024;
|
|
50
|
+
/**
|
|
51
|
+
* 校验用户给的分支 / 提交引用。
|
|
52
|
+
*
|
|
53
|
+
* 为什么非校验不可:`git show <ref>` 的 ref 来自 `/review` 后面的自由输入,而
|
|
54
|
+
* `execFile` 只挡得住 shell 拼接、挡不住**选项注入**——填 `--output=D:\\任意路径` 时
|
|
55
|
+
* git 会把它当选项执行(把补丁写进那个文件)。所以只放行正常引用字符,并且不许以
|
|
56
|
+
* `-` 开头(那就是选项的地盘)。`~`、`^`、`@{` 这些 rev 语法照常可用。
|
|
57
|
+
*
|
|
58
|
+
* @param ref - 用户输入或候选里的原始值
|
|
59
|
+
* @returns 去掉首尾空白的引用
|
|
60
|
+
*/
|
|
61
|
+
export function assertReviewRef(ref) {
|
|
62
|
+
const trimmed = ref.trim();
|
|
63
|
+
if (trimmed === '' || trimmed.startsWith('-') || !/^[A-Za-z0-9._~^@{}/:-]+$/.test(trimmed)) {
|
|
64
|
+
throw new Error(`不像一个分支或提交引用:${ref}`);
|
|
65
|
+
}
|
|
66
|
+
return trimmed;
|
|
67
|
+
}
|
|
68
|
+
/** 未跟踪文件名单:`git status --porcelain` 里 `??` 那几行。 */
|
|
69
|
+
async function listUntracked(cwd) {
|
|
70
|
+
const porcelain = await gitExec(cwd, ['-c', 'core.quotePath=false', 'status', '--porcelain=v1']);
|
|
71
|
+
return porcelain
|
|
72
|
+
.split('\n')
|
|
73
|
+
.filter((line) => line.startsWith('??'))
|
|
74
|
+
.map((line) => line.slice(3).trim())
|
|
75
|
+
.filter((file) => file !== '');
|
|
76
|
+
}
|
|
77
|
+
/** 短哈希:会话 id 或工作目录都行,只用来让同一个会话的 diff 文件名彼此认得出来。 */
|
|
78
|
+
function shortHash(seed) {
|
|
79
|
+
return createHash('sha256').update(seed).digest('hex').slice(0, 8);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 把完整 diff 写进 `<数据目录>/cache/review/<会话短哈希>-<时间戳>.diff`,返回绝对路径。
|
|
83
|
+
*
|
|
84
|
+
* 为什么落盘而不是塞进任务描述:审查队友的上下文有预算,塞进去就得截断;落盘之后
|
|
85
|
+
* 它可以按需 `read` 的 offset/limit 分批看完整内容,截断这件事就不存在了。
|
|
86
|
+
* 数据目录复用 path-policy 的 DSC_HOME(`DSC_HOME` 环境变量优先),与配置、会话同一处。
|
|
87
|
+
*/
|
|
88
|
+
async function writeReviewDiff(seed, diff) {
|
|
89
|
+
const dir = dscPath('cache', 'review');
|
|
90
|
+
await fsp.mkdir(dir, { recursive: true });
|
|
91
|
+
const file = join(dir, `${shortHash(seed)}-${String(Date.now())}.diff`);
|
|
92
|
+
await fsp.writeFile(file, diff, 'utf8');
|
|
93
|
+
return file;
|
|
94
|
+
}
|
|
32
95
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
96
|
+
* 按范围取一次审查的完整数据(不截断)。
|
|
97
|
+
*
|
|
98
|
+
* 取数口径(`--no-textconv --no-ext-diff` 防文本转换与外部 diff driver 当场跑程序):
|
|
99
|
+
* - worktree / custom:`git diff HEAD`(含已暂存;未跟踪只列名单);
|
|
100
|
+
* - base:先 `git merge-base HEAD <ref>` 拿到共同祖先,再 `git diff <祖先>`;
|
|
101
|
+
* - commit:`git show <ref> --format=fuller`(连提交信息一起给队友)。
|
|
102
|
+
*
|
|
103
|
+
* @param cwd - 会话工作目录
|
|
104
|
+
* @param target - 审查范围
|
|
105
|
+
* @param sessionId - 会话 id(只用于 diff 文件名;不传就按 cwd 哈希,探针里两参调用即可)
|
|
106
|
+
* @returns 不是 git 仓库时 null;ref 不存在等 git 报错按异常抛出(调用方给用户看原文)
|
|
36
107
|
*/
|
|
37
|
-
export async function
|
|
108
|
+
export async function collectReviewScope(cwd, target, sessionId) {
|
|
38
109
|
try {
|
|
39
110
|
const inside = (await gitExec(cwd, ['rev-parse', '--is-inside-work-tree'])).trim();
|
|
40
111
|
if (inside !== 'true')
|
|
@@ -43,42 +114,252 @@ export async function collectWorkingTree(cwd) {
|
|
|
43
114
|
catch {
|
|
44
115
|
return null;
|
|
45
116
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
117
|
+
let diff;
|
|
118
|
+
let stat;
|
|
119
|
+
let label;
|
|
120
|
+
let base;
|
|
121
|
+
// 未跟踪文件只在「工作区」口径里有意义:对比分支与某次提交看的是已入库的改动。
|
|
122
|
+
const untracked = target.kind === 'worktree' || target.kind === 'custom' ? await listUntracked(cwd) : [];
|
|
123
|
+
if (target.kind === 'commit') {
|
|
124
|
+
const ref = assertReviewRef(target.ref);
|
|
125
|
+
diff = await gitForDiff(cwd, ['show', ref, '--no-textconv', '--no-ext-diff', '--format=fuller']);
|
|
126
|
+
stat = await gitForDiff(cwd, ['show', ref, '--stat', '--format=']);
|
|
127
|
+
const sha = (await gitExec(cwd, ['rev-parse', ref])).trim();
|
|
128
|
+
const title = target.title ?? (await gitExec(cwd, ['log', '-1', '--format=%s', ref])).trim();
|
|
129
|
+
label = `提交 ${sha.slice(0, 10)}${title === '' ? '' : ` ${title}`}`;
|
|
130
|
+
}
|
|
131
|
+
else if (target.kind === 'base') {
|
|
132
|
+
const ref = assertReviewRef(target.ref);
|
|
133
|
+
base = (await gitExec(cwd, ['merge-base', 'HEAD', ref])).trim();
|
|
134
|
+
diff = await gitForDiff(cwd, ['diff', base, '--no-textconv', '--no-ext-diff']);
|
|
135
|
+
stat = await gitForDiff(cwd, ['diff', base, '--stat']);
|
|
136
|
+
label = `对比基准分支 ${ref} 的差异(共同祖先 ${base.slice(0, 10)})`;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
diff = await gitForDiff(cwd, ['diff', 'HEAD', '--no-textconv', '--no-ext-diff']);
|
|
140
|
+
stat = await gitForDiff(cwd, ['diff', 'HEAD', '--stat']);
|
|
141
|
+
label = target.kind === 'custom' ? '未提交改动(自定义审查要求)' : '未提交改动';
|
|
142
|
+
}
|
|
143
|
+
const diffBytes = Buffer.byteLength(diff, 'utf8');
|
|
144
|
+
// 超大 diff 照样写全(写文件没有上下文压力),只在清单末尾教队友怎么读。
|
|
145
|
+
if (diffBytes > HUGE_DIFF_BYTES) {
|
|
146
|
+
stat = `${stat.trimEnd()}\n\ndiff 很大(${(diffBytes / 1024 / 1024).toFixed(1)} MB),用 read 的 offset/limit 分批读,别一次全读。`;
|
|
147
|
+
}
|
|
148
|
+
const diffPath = await writeReviewDiff(sessionId ?? cwd, diff);
|
|
149
|
+
return {
|
|
150
|
+
target,
|
|
151
|
+
label,
|
|
152
|
+
diffPath,
|
|
153
|
+
diffBytes,
|
|
154
|
+
stat,
|
|
155
|
+
untracked,
|
|
156
|
+
...(base === undefined ? {} : { base }),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/** 本地分支清单(「对比基准分支」的候选项);不是 git 仓库或没有分支时给空数组。 */
|
|
160
|
+
export async function listReviewBranches(cwd) {
|
|
161
|
+
try {
|
|
162
|
+
const text = await gitExec(cwd, ['for-each-ref', '--format=%(refname:short)', 'refs/heads']);
|
|
163
|
+
return text.split('\n').map((line) => line.trim()).filter((line) => line !== '');
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** 最近 100 条提交(「审查某次提交」的候选项);取不到给空数组,用户仍可手填 SHA。 */
|
|
170
|
+
export async function listReviewCommits(cwd) {
|
|
171
|
+
try {
|
|
172
|
+
const text = await gitExec(cwd, ['log', '-n', '100', '--format=%H%x09%s']);
|
|
173
|
+
return text
|
|
174
|
+
.split('\n')
|
|
175
|
+
.filter((line) => line !== '')
|
|
176
|
+
.map((line) => {
|
|
177
|
+
const at = line.indexOf('\t');
|
|
178
|
+
return at < 0
|
|
179
|
+
? { sha: line, subject: '' }
|
|
180
|
+
: { sha: line.slice(0, at), subject: line.slice(at + 1) };
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return [];
|
|
185
|
+
}
|
|
55
186
|
}
|
|
56
187
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
188
|
+
* 给审查队友的任务书(/review 的唯一组装点:派队友走它,回落主会话轮也走它)。
|
|
189
|
+
*
|
|
190
|
+
* 为什么要把「diff 已落盘」写进任务书:队友只有读类工具,不知道文件在哪就只能
|
|
191
|
+
* 在上下文里找,而完整 diff 可能几十 MB——先告诉它路径与读法,它才可能读全。
|
|
192
|
+
*
|
|
193
|
+
* @param scope - 取数结果
|
|
194
|
+
* @param focus - 用户写在 /review 后面的关注点(空串 = 不限)
|
|
60
195
|
*/
|
|
61
|
-
export function
|
|
196
|
+
export function reviewTaskText(scope, focus) {
|
|
62
197
|
const lines = [
|
|
63
|
-
'
|
|
64
|
-
|
|
198
|
+
'你是一次代码审查的审查员:只读代码,不改任何文件。',
|
|
199
|
+
'',
|
|
200
|
+
'## 本次审查范围',
|
|
201
|
+
scope.label,
|
|
65
202
|
];
|
|
66
|
-
if (
|
|
67
|
-
lines.push(
|
|
68
|
-
if (collected.diff !== '') {
|
|
69
|
-
lines.push('', '## 未提交改动(git diff HEAD --no-textconv --no-ext-diff)', '', collected.diff);
|
|
203
|
+
if (scope.target.kind === 'custom') {
|
|
204
|
+
lines.push('', '## 自定义审查要求', scope.target.instructions);
|
|
70
205
|
}
|
|
71
|
-
|
|
72
|
-
|
|
206
|
+
lines.push('', '## 完整 diff 已落盘', scope.diffPath, `用 read 分批读(offset / limit),别只看开头:这份 diff 共 ${String(scope.diffBytes)} 字节。`);
|
|
207
|
+
if (scope.diffBytes === 0) {
|
|
208
|
+
lines.push('(这个范围里没有已跟踪文件的改动,只有下面列出的未跟踪新文件。)');
|
|
209
|
+
}
|
|
210
|
+
if (scope.stat.trim() !== '') {
|
|
211
|
+
lines.push('', '## 改动清单', scope.stat.trimEnd());
|
|
212
|
+
}
|
|
213
|
+
if (scope.untracked.length > 0) {
|
|
214
|
+
lines.push('', '## 未跟踪文件(diff 里没有,逐个 read 再评)', ...scope.untracked.map((file) => `- ${file}`));
|
|
215
|
+
}
|
|
216
|
+
if (focus !== '') {
|
|
217
|
+
lines.push('', '## 关注点', focus);
|
|
218
|
+
}
|
|
219
|
+
lines.push('', '## 输出要求', '按 P0–P3 分级:P0 = 必须修(必然出错、安全漏洞、数据丢失);'
|
|
220
|
+
+ 'P1 = 正确性或安全问题;P2 = 边界、健壮性、性能问题;P3 = 可读性、风格、更好的写法。', '每条按这个格式写(渲染层按它解析成卡片,字段一个都不能少):', '', '### [P0] 一句话标题', '位置:相对路径:行号', '说明:问题是什么、证据是什么', '建议:怎么改', '', '最后单起一段给整体结论,只能二选一:`整体结论:可提交` 或 `整体结论:需修改后提交`。', '没有发现问题就明说没有,并交代你查过的文件与维度。');
|
|
221
|
+
return lines.join('\n');
|
|
222
|
+
}
|
|
223
|
+
// ── /review 的会话账本(状态回看 / 取消)────────────────────────────────────
|
|
224
|
+
/** 取消之后记进记录文件的那句话(/review-status 会原样回看)。 */
|
|
225
|
+
export const REVIEW_CANCELED_TEXT = '审查被取消。';
|
|
226
|
+
/**
|
|
227
|
+
* /review 的会话账本:内存里记「这个会话有没有在跑的审查」,磁盘上留「最近一次长什么样」。
|
|
228
|
+
*
|
|
229
|
+
* 为什么放在这里:命令侧(派审查前写 running)、审查通道(收工写 findings、取消时改状态)
|
|
230
|
+
* 与自检探针要共用同一份读写口径。各自拼路径、各自猜字段,重启后就对不上了。
|
|
231
|
+
* 记录文件 `<数据目录>/code-review/<会话 id>.json`,一个会话一份,后一次覆盖前一次。
|
|
232
|
+
*/
|
|
233
|
+
export class ReviewJournal {
|
|
234
|
+
runs = new Map();
|
|
235
|
+
views = new Map();
|
|
236
|
+
home;
|
|
237
|
+
/** @param home - 数据目录(`ctx.settings.about().home`,与 DSC_HOME 同一个) */
|
|
238
|
+
constructor(home) {
|
|
239
|
+
this.home = home;
|
|
240
|
+
}
|
|
241
|
+
/** 这个会话的记录文件路径(会话 id 先洗一遍,别让奇怪的 id 拼出目录穿越)。 */
|
|
242
|
+
recordPath(sessionId) {
|
|
243
|
+
const safe = sessionId.replace(/[^A-Za-z0-9_-]/g, '_');
|
|
244
|
+
return join(this.home, 'code-review', `${safe}.json`);
|
|
245
|
+
}
|
|
246
|
+
/** 读记录文件;没有、读不动、字段对不上都算「没有记录」。 */
|
|
247
|
+
read(sessionId) {
|
|
248
|
+
try {
|
|
249
|
+
const parsed = JSON.parse(readFileSync(this.recordPath(sessionId), 'utf8'));
|
|
250
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
251
|
+
return null;
|
|
252
|
+
const record = parsed;
|
|
253
|
+
if (record['version'] !== 1)
|
|
254
|
+
return null;
|
|
255
|
+
const state = record['state'];
|
|
256
|
+
if (state !== 'running' && state !== 'finished')
|
|
257
|
+
return null;
|
|
258
|
+
if (typeof record['startedAt'] !== 'number' || typeof record['target'] !== 'string')
|
|
259
|
+
return null;
|
|
260
|
+
const findings = record['findings'];
|
|
261
|
+
return {
|
|
262
|
+
state,
|
|
263
|
+
startedAt: record['startedAt'],
|
|
264
|
+
target: record['target'],
|
|
265
|
+
...(typeof findings === 'string' ? { findings } : {}),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/** 写记录文件(写不下去只让 /review-status 回看少一份,不影响审查本身)。 */
|
|
273
|
+
write(sessionId, view) {
|
|
274
|
+
this.views.set(sessionId, view);
|
|
275
|
+
try {
|
|
276
|
+
const path = this.recordPath(sessionId);
|
|
277
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
278
|
+
writeFileSync(path, `${JSON.stringify({ version: 1, ...view }, null, 2)}\n`, 'utf8');
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
// 记录落盘失败不该让审查失败:内存里那份还在,本进程内的 /review-status 照常能看
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/** 最近一次审查的状态;没有记录返回 null。 */
|
|
285
|
+
status(sessionId) {
|
|
286
|
+
return this.views.get(sessionId) ?? this.read(sessionId);
|
|
287
|
+
}
|
|
288
|
+
/** 这个会话正在跑的那次审查;没有返回 undefined(取消要按它拿队友名)。 */
|
|
289
|
+
running(sessionId) {
|
|
290
|
+
return this.runs.get(sessionId);
|
|
291
|
+
}
|
|
292
|
+
/** 派出去之后登记「在跑」并落一份 running 记录。 */
|
|
293
|
+
begin(sessionId, input) {
|
|
294
|
+
const startedAt = input.startedAt ?? Date.now();
|
|
295
|
+
this.runs.set(sessionId, { startedAt, target: input.target, handle: input.handle, cancelled: false });
|
|
296
|
+
this.write(sessionId, { state: 'running', startedAt, target: input.target });
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* 标记取消:记录立刻变成 finished +「审查被取消」,但**保留** runs 里那条,
|
|
300
|
+
* 好让随后的收工回调还知道这次审查的起始时间与范围(它会把同一句话再写一遍)。
|
|
301
|
+
* @returns 没有在跑的审查时 false
|
|
302
|
+
*/
|
|
303
|
+
cancel(sessionId) {
|
|
304
|
+
const run = this.runs.get(sessionId);
|
|
305
|
+
if (run === undefined)
|
|
306
|
+
return false;
|
|
307
|
+
run.cancelled = true;
|
|
308
|
+
this.write(sessionId, {
|
|
309
|
+
state: 'finished',
|
|
310
|
+
startedAt: run.startedAt,
|
|
311
|
+
target: run.target,
|
|
312
|
+
findings: REVIEW_CANCELED_TEXT,
|
|
313
|
+
});
|
|
314
|
+
return true;
|
|
73
315
|
}
|
|
74
|
-
|
|
75
|
-
|
|
316
|
+
/** 这次审查是不是被用户取消的(收工时用来决定写哪句话)。 */
|
|
317
|
+
wasCancelled(sessionId) {
|
|
318
|
+
return this.runs.get(sessionId)?.cancelled === true;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* 收工:把 findings 写进记录并清掉「在跑」那一笔。
|
|
322
|
+
* @param handle - 收工的是哪个队友;同一会话里前一次没收工又派了新的时,
|
|
323
|
+
* 旧那次收工不能把新那次的状态改成 finished(传了就按它比对,不传一律照写)
|
|
324
|
+
*/
|
|
325
|
+
finish(sessionId, findings, handle) {
|
|
326
|
+
const run = this.runs.get(sessionId);
|
|
327
|
+
if (handle !== undefined && run !== undefined && run.handle !== handle)
|
|
328
|
+
return;
|
|
329
|
+
this.runs.delete(sessionId);
|
|
330
|
+
this.write(sessionId, {
|
|
331
|
+
state: 'finished',
|
|
332
|
+
startedAt: run?.startedAt ?? Date.now(),
|
|
333
|
+
target: run?.target ?? '(范围未知)',
|
|
334
|
+
findings: run?.cancelled === true ? REVIEW_CANCELED_TEXT : findings,
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/** `/review-status` 上屏的那段文本(命令与探针共用一份,不许各写一套)。 */
|
|
339
|
+
export function reviewStatusText(view) {
|
|
340
|
+
if (view === null)
|
|
341
|
+
return '还没有审查记录。';
|
|
342
|
+
const when = new Date(view.startedAt).toLocaleString('zh-CN', { hour12: false });
|
|
343
|
+
const lines = [
|
|
344
|
+
view.state === 'running' ? `审查进行中(开始于 ${when})` : `审查已完成(开始于 ${when})`,
|
|
345
|
+
`范围:${view.target}`,
|
|
346
|
+
];
|
|
347
|
+
if (view.state === 'running')
|
|
348
|
+
lines.push('用 /review-cancel 可以取消这次审查。');
|
|
349
|
+
if (view.findings !== undefined && view.findings.trim() !== '') {
|
|
350
|
+
lines.push('', '结论:', view.findings.trimEnd());
|
|
76
351
|
}
|
|
77
352
|
return lines.join('\n');
|
|
78
353
|
}
|
|
79
354
|
// ── T42:回合首尾快照(轮尾「文件已更改」卡对 bash/脚本改动的兜底)─────────────
|
|
80
|
-
/**
|
|
81
|
-
|
|
355
|
+
/**
|
|
356
|
+
* 一轮最多补多少个 git 兜底条目。
|
|
357
|
+
*
|
|
358
|
+
* 上限本身要有(一个脚本扫动几千个文件会把轮尾卡撑爆),但 20 太小:真实的一次
|
|
359
|
+
* 「按需求文档补一堆文件」很容易超过 20,用户看到的就是「文件显示不全」
|
|
360
|
+
* (2026-10-30 报障)。200 够覆盖正常一轮的重构,真超了也只是少列,不影响功能。
|
|
361
|
+
*/
|
|
362
|
+
const MAX_GIT_TURN_FILES = 200;
|
|
82
363
|
/**
|
|
83
364
|
* 回合起点的 git 状态快照:仓库根 + porcelain 一行一条。非 git 仓库、git 跑不动
|
|
84
365
|
* (超时/没装)一律返回 null——兜底只在确定拿得到的时候参与,绝不挡回合本身。
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工作区 git 读数的相等判断(全仓库唯一一份)。
|
|
3
|
+
*
|
|
4
|
+
* 同一份读数有两个地方要「比一比」:
|
|
5
|
+
* - 宿主侧 `plugins/git.ts`:读数没变就别推帧(干净仓库每 30 秒白推一帧是纯浪费);
|
|
6
|
+
* - 界面侧 `composer/ui.tsx`:读数没变就别重画输入区底栏。
|
|
7
|
+
* 两处原先各写一份四字段比较。它们**必须**同口径:一边认为变了、另一边认为没变,
|
|
8
|
+
* 界面就会停在旧分支名上且再也不刷新——这类 bug 只在分支切换时出现,最难查。
|
|
9
|
+
*
|
|
10
|
+
* 只比 `GitSurface` 这四个字段(repo / branch / detached / dirtyFileCount)。
|
|
11
|
+
* 状态栏那份 `GitSummary`(branch / added / removed / files)是另一种读数,不在这里合并。
|
|
12
|
+
*
|
|
13
|
+
* @module dsc/core/git-surface
|
|
14
|
+
*/
|
|
15
|
+
import type { GitSurface } from '../contract.js';
|
|
16
|
+
/** 两份读数是不是同一份(四个字段逐个比,比让界面每帧重画便宜)。 */
|
|
17
|
+
export declare function sameGitSurface(left: GitSurface, right: GitSurface): boolean;
|
package/lib/core/hooks.d.ts
CHANGED
|
@@ -161,8 +161,25 @@ export declare function patchHookSettings(patch: Partial<HookSettings>): HookSet
|
|
|
161
161
|
* @param command - 命令原文。
|
|
162
162
|
*/
|
|
163
163
|
export declare function scriptFileOf(command: string): string;
|
|
164
|
-
/**
|
|
165
|
-
|
|
164
|
+
/**
|
|
165
|
+
* 命令里写的脚本路径,**不管文件在不在**。
|
|
166
|
+
*
|
|
167
|
+
* 为什么要和 {@link scriptFileOf} 分开:那个只认「真的存在」的文件,脚本被删掉之后
|
|
168
|
+
* 它返回空串,漂移检查于是整段跳过、这条钩子被当成「已批准且没改过」照样执行,
|
|
169
|
+
* 最后才在 `node` 那一步以「退出码 1」炸掉(2026-10-28 用户报障:删除命令被拦,
|
|
170
|
+
* 理由却是「钩子脚本失败」)。这一份只看命令写了什么,用来认出「配了但文件没了」。
|
|
171
|
+
*
|
|
172
|
+
* @param command - 命令原文。
|
|
173
|
+
*/
|
|
174
|
+
export declare function scriptTokenOf(command: string): string;
|
|
175
|
+
/**
|
|
176
|
+
* 一条脚本的批准状态。
|
|
177
|
+
*
|
|
178
|
+
* `missing` = 命令里写了脚本路径,但那个文件不存在(被删了、路径改名了)。
|
|
179
|
+
* 它不是「批准过没过期」的问题,是配置已经坏了:这条钩子一律停跑并说清缺哪个文件,
|
|
180
|
+
* 免得拿「脚本以 1 退出」这种间接症状去猜。
|
|
181
|
+
*/
|
|
182
|
+
export type HookTrustState = 'trusted' | 'untrusted' | 'changed' | 'missing';
|
|
166
183
|
/** 批准状态的投影(界面上那一行字由它出)。 */
|
|
167
184
|
export interface HookTrust {
|
|
168
185
|
state: HookTrustState;
|
package/lib/core/hooks.js
CHANGED
|
@@ -26,6 +26,8 @@ import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'no
|
|
|
26
26
|
import { randomUUID } from 'node:crypto';
|
|
27
27
|
import { redact, scrubChildEnv } from './secrets.js';
|
|
28
28
|
import { dscPath } from './path-policy.js';
|
|
29
|
+
import { clampInt as clamp } from './clamp.js';
|
|
30
|
+
import { shellOf } from './shell-quote.js';
|
|
29
31
|
/** 钩子配置文件(与 settings.json、audit.jsonl 同级)。 */
|
|
30
32
|
export const HOOKS_FILE = dscPath('hooks.json');
|
|
31
33
|
/** 脚本钩子的批准名单(与配置文件分开存:批准是「人对某条命令表过态」,不该跟着配置一起被覆盖)。 */
|
|
@@ -64,10 +66,6 @@ const EMPTY_DOC = { settings: { ...DEFAULT_SETTINGS }, rules: [], scripts: [], p
|
|
|
64
66
|
// ── 读写配置文件 ─────────────────────────────────────────────────────────────
|
|
65
67
|
/** 配置文件的缓存(按 mtime + 大小判新,免得每次工具调用都重读重解析一遍磁盘)。 */
|
|
66
68
|
let cache = null;
|
|
67
|
-
function clamp(value, min, max, fallback) {
|
|
68
|
-
const num = Number(value);
|
|
69
|
-
return Number.isFinite(num) ? Math.min(Math.max(Math.round(num), min), max) : fallback;
|
|
70
|
-
}
|
|
71
69
|
function asString(value, max) {
|
|
72
70
|
return typeof value === 'string' ? value.slice(0, max).trim() : '';
|
|
73
71
|
}
|
|
@@ -353,6 +351,24 @@ export function scriptFileOf(command) {
|
|
|
353
351
|
}
|
|
354
352
|
return '';
|
|
355
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* 命令里写的脚本路径,**不管文件在不在**。
|
|
356
|
+
*
|
|
357
|
+
* 为什么要和 {@link scriptFileOf} 分开:那个只认「真的存在」的文件,脚本被删掉之后
|
|
358
|
+
* 它返回空串,漂移检查于是整段跳过、这条钩子被当成「已批准且没改过」照样执行,
|
|
359
|
+
* 最后才在 `node` 那一步以「退出码 1」炸掉(2026-10-28 用户报障:删除命令被拦,
|
|
360
|
+
* 理由却是「钩子脚本失败」)。这一份只看命令写了什么,用来认出「配了但文件没了」。
|
|
361
|
+
*
|
|
362
|
+
* @param command - 命令原文。
|
|
363
|
+
*/
|
|
364
|
+
export function scriptTokenOf(command) {
|
|
365
|
+
for (const token of tokenize(command)) {
|
|
366
|
+
const lower = token.toLowerCase();
|
|
367
|
+
if (SCRIPT_SUFFIXES.some((suffix) => lower.endsWith(suffix)))
|
|
368
|
+
return token;
|
|
369
|
+
}
|
|
370
|
+
return '';
|
|
371
|
+
}
|
|
356
372
|
function readTrust() {
|
|
357
373
|
try {
|
|
358
374
|
if (!existsSync(HOOK_TRUST_FILE))
|
|
@@ -399,6 +415,21 @@ function writeTrust(doc) {
|
|
|
399
415
|
*/
|
|
400
416
|
export function trustOf(script, autoAccept = false) {
|
|
401
417
|
const scriptPath = scriptFileOf(script.command);
|
|
418
|
+
// 命令里点了脚本文件、文件却不在:配置坏了,不是「批准过没过期」。
|
|
419
|
+
// 放在最前面判,是因为这种状态跟批没批准无关——真跑起来只会得到一句
|
|
420
|
+
// 「Cannot find module」加退出码 1,然后被 fail-closed 当成「钩子拦了这次操作」。
|
|
421
|
+
if (scriptPath === '') {
|
|
422
|
+
const declared = scriptTokenOf(script.command);
|
|
423
|
+
if (declared !== '') {
|
|
424
|
+
return {
|
|
425
|
+
state: 'missing',
|
|
426
|
+
detail: `钩子脚本文件不存在:${declared}(这条钩子已停用;改 \`~/.dsc/hooks.json\` 里的路径,或删掉这条脚本)`,
|
|
427
|
+
scriptPath: declared,
|
|
428
|
+
trustedAt: 0,
|
|
429
|
+
runnable: false,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
}
|
|
402
433
|
const entry = readTrust().trusted.find((item) => item.event === script.event && item.command === script.command);
|
|
403
434
|
if (entry === undefined) {
|
|
404
435
|
return {
|
|
@@ -530,11 +561,6 @@ export function matcherHits(matcher, toolName) {
|
|
|
530
561
|
const { regex, literal } = ruleRegex(trimmed);
|
|
531
562
|
return regex !== null ? regex.test(toolName) : toolName.toLowerCase().includes(literal.toLowerCase());
|
|
532
563
|
}
|
|
533
|
-
function shellOf() {
|
|
534
|
-
return process.platform === 'win32'
|
|
535
|
-
? { file: 'cmd.exe', args: ['/d', '/s', '/c'] }
|
|
536
|
-
: { file: '/bin/sh', args: ['-c'] };
|
|
537
|
-
}
|
|
538
564
|
/**
|
|
539
565
|
* 跑一条脚本钩子。
|
|
540
566
|
*
|
|
@@ -738,6 +764,21 @@ export function parseScriptVerdict(stdout) {
|
|
|
738
764
|
}
|
|
739
765
|
return { action: 'pass', message: '' };
|
|
740
766
|
}
|
|
767
|
+
/**
|
|
768
|
+
* stderr 的第一行非空内容(截到消息上限)。
|
|
769
|
+
*
|
|
770
|
+
* 钩子脚本失败时,真正的原因几乎都写在这里:文件不存在是 `Cannot find module`、
|
|
771
|
+
* 语法错是 `SyntaxError`、命令不存在是 `not recognized`。只回一个退出码,
|
|
772
|
+
* 用户只能看到「钩子失败」四个字,猜不到是脚本被删了。
|
|
773
|
+
*/
|
|
774
|
+
function firstStderrLine(stderr) {
|
|
775
|
+
for (const line of stderr.split(/\r?\n/)) {
|
|
776
|
+
const trimmed = line.trim();
|
|
777
|
+
if (trimmed !== '')
|
|
778
|
+
return trimmed.slice(0, HOOK_STDERR_MAX);
|
|
779
|
+
}
|
|
780
|
+
return '';
|
|
781
|
+
}
|
|
741
782
|
/** 把一次执行结果折成结论(这里决定 fail-closed 的三种失败形态)。 */
|
|
742
783
|
export function judgeScriptRun(run, script, settings) {
|
|
743
784
|
const source = `脚本 ${script.command.slice(0, 40)}`;
|
|
@@ -781,17 +822,20 @@ export function judgeScriptRun(run, script, settings) {
|
|
|
781
822
|
? note(`脚本以 ${run.exitCode} 退出但给出了放行结论`, 'block', `钩子脚本退出码是 ${run.exitCode},按「脚本没跑成就算拦」处理。`)
|
|
782
823
|
: note(`脚本以 ${run.exitCode} 退出,仍按它的结论放行`);
|
|
783
824
|
}
|
|
825
|
+
// stderr 的第一行往往就是真相(「Cannot find module …」这种),以前只留退出码,
|
|
826
|
+
// 用户看到的「钩子失败」和真实原因之间隔着一条要自己去猜的沟(2026-10-28 报障)。
|
|
827
|
+
const stderrLine = firstStderrLine(run.stderr);
|
|
784
828
|
if (run.exitCode === 0) {
|
|
785
829
|
if (run.stdout.trim() === '')
|
|
786
830
|
return note('');
|
|
787
|
-
const problem =
|
|
831
|
+
const problem = `脚本输出不是能看懂的 JSON${stderrLine === '' ? '' : `(stderr:${stderrLine})`}`;
|
|
788
832
|
return failClosed
|
|
789
|
-
? note(problem, 'block',
|
|
833
|
+
? note(problem, 'block', `钩子脚本的输出读不懂(既不是 JSON 也没用退出码 2 表达阻断)${stderrLine === '' ? '' : `:${stderrLine}`}。按「脚本没跑成就算拦」处理。`)
|
|
790
834
|
: note(problem);
|
|
791
835
|
}
|
|
792
|
-
const problem = `脚本以 ${run.exitCode}
|
|
836
|
+
const problem = `脚本以 ${run.exitCode} 退出,没有给出结论${stderrLine === '' ? '' : `(stderr:${stderrLine})`}`;
|
|
793
837
|
return failClosed
|
|
794
|
-
? note(problem, 'block', `钩子脚本失败(退出码 ${run.exitCode}
|
|
838
|
+
? note(problem, 'block', `钩子脚本失败(退出码 ${run.exitCode})${stderrLine === '' ? '' : `:${stderrLine}`}。按「脚本没跑成就算拦」处理。`)
|
|
795
839
|
: note(problem);
|
|
796
840
|
}
|
|
797
841
|
/** 结论的优先次序:拦 > 问人 > 只留话 > 不表态(与注册顺序无关,多条命中全部跑完再比)。 */
|
|
@@ -19,7 +19,7 @@ export type InvokableMethod = Exclude<keyof DscRuntime, LocalOnlyMethod>;
|
|
|
19
19
|
* 这份清单就是协议的全部可调用面:写成 `satisfies` 是为了让编译器逐条核对方法名,
|
|
20
20
|
* 拼错一个字母当场报错,而不是等到运行时才「协议不允许调用」。
|
|
21
21
|
*/
|
|
22
|
-
export declare const INVOKABLE_METHODS: readonly ["submit", "interrupt", "editQueued", "removeQueued", "steerQueued", "openSession", "newSessionIn", "compact", "setModel", "setEffort", "refreshSessions", "listModels", "listPlugins", "setPluginEnabled", "listTeammates", "stopTeammate", "messageTeammate", "removeTeammate", "stopBackground", "readBackground", "peekTranscript", "runCommand", "listUiCommands", "runUiCommand", "setPolicy", "setReviewer", "listPermissionPresets", "usePermissionPreset", "setDefaultPermissionPreset", "dock", "answerApproval", "setMode", "listPresets", "readPreset", "usePreset", "savePreset", "removePreset", "setDefaultPreset", "listTools", "clearTodos", "goalAction", "answerQuestion", "answerPlan", "archiveSessions", "listArchivedSessions", "usageStats", "restoreSessions", "purgeSessions", "renameSession", "setSessionPinned", "listUserMessages", "forkSession", "getUiPrefs", "setUiPrefs", "listSkills", "readSkill", "setSkillEnabled", "browseMarket", "installMarketSkill", "setMarketSources", "listUiTrust", "setUiTrust", "getSettingsSections", "getSectionValues", "setSettingValue", "runSettingAction", "getModelConfig", "saveProvider", "discoverModels", "testConnection", "removeProvider", "setProviderKey", "setDefaultModel", "setConfigFile"];
|
|
22
|
+
export declare const INVOKABLE_METHODS: readonly ["submit", "interrupt", "editQueued", "removeQueued", "steerQueued", "openSession", "newSessionIn", "compact", "setModel", "setEffort", "refreshSessions", "listModels", "listPlugins", "setPluginEnabled", "listTeammates", "stopTeammate", "messageTeammate", "removeTeammate", "stopBackground", "readBackground", "peekTranscript", "runCommand", "listUiCommands", "runUiCommand", "setPolicy", "setReviewer", "listPermissionPresets", "usePermissionPreset", "setDefaultPermissionPreset", "dock", "answerApproval", "setMode", "listPresets", "readPreset", "usePreset", "savePreset", "removePreset", "setDefaultPreset", "listTools", "clearTodos", "goalAction", "answerQuestion", "answerPlan", "archiveSessions", "listArchivedSessions", "usageStats", "sideAsk", "sideAskCancel", "restoreSessions", "purgeSessions", "renameSession", "setSessionPinned", "listUserMessages", "forkSession", "rewindSession", "getUiPrefs", "setUiPrefs", "listSkills", "readSkill", "setSkillEnabled", "browseMarket", "installMarketSkill", "setMarketSources", "listUiTrust", "setUiTrust", "getSettingsSections", "getSectionValues", "setSettingValue", "runSettingAction", "getModelConfig", "saveProvider", "discoverModels", "testConnection", "removeProvider", "setProviderKey", "setDefaultModel", "setConfigFile"];
|
|
23
23
|
/** 把线上来的方法名收窄成「协议允许调用的方法」。 */
|
|
24
24
|
export declare const isInvokableMethod: (method: string) => method is InvokableMethod;
|
|
25
25
|
export {};
|
package/lib/core/host-methods.js
CHANGED
|
@@ -59,12 +59,16 @@ export const INVOKABLE_METHODS = [
|
|
|
59
59
|
'archiveSessions',
|
|
60
60
|
'listArchivedSessions',
|
|
61
61
|
'usageStats',
|
|
62
|
+
// 旁问:只读一次性问答(不建会话、不落盘、不带工具),见 core/side-ask.ts
|
|
63
|
+
'sideAsk',
|
|
64
|
+
'sideAskCancel',
|
|
62
65
|
'restoreSessions',
|
|
63
66
|
'purgeSessions',
|
|
64
67
|
'renameSession',
|
|
65
68
|
'setSessionPinned',
|
|
66
69
|
'listUserMessages',
|
|
67
70
|
'forkSession',
|
|
71
|
+
'rewindSession',
|
|
68
72
|
'getUiPrefs',
|
|
69
73
|
'setUiPrefs',
|
|
70
74
|
// 技能中心
|
package/lib/core/image-diet.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { clampIntIn as clamp } from './clamp.js';
|
|
1
2
|
/** 卸载后留在原位的那句话:模型看得见「这里本来有图」,只是它不再随请求发送。 */
|
|
2
3
|
export const IMAGE_DIET_PLACEHOLDER = '(图片已卸载,原文里这里是一张图)';
|
|
3
4
|
/** 缺省口径:用户图 4 张、工具图 2 张、保留最近 2 个用户回合。 */
|
|
@@ -16,10 +17,6 @@ export const DEFAULT_IMAGE_DIET_CONFIG = { enabled: true, ...DEFAULT_IMAGE_DIET
|
|
|
16
17
|
*/
|
|
17
18
|
export function readImageDietConfig(raw) {
|
|
18
19
|
const source = raw === null || typeof raw !== 'object' || Array.isArray(raw) ? {} : raw;
|
|
19
|
-
const clamp = (value, range, fallback) => {
|
|
20
|
-
const num = Number(value);
|
|
21
|
-
return Number.isFinite(num) ? Math.min(Math.max(Math.round(num), range.min), range.max) : fallback;
|
|
22
|
-
};
|
|
23
20
|
return {
|
|
24
21
|
// 只认字面 false 关:设置分区写的就是布尔;缺省(undefined/没配过)按「开」算。
|
|
25
22
|
enabled: source.enabled === undefined ? DEFAULT_IMAGE_DIET_CONFIG.enabled : source.enabled !== false,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 安全序列化(全仓库唯一一份)。
|
|
3
|
+
*
|
|
4
|
+
* `JSON.stringify` 遇到循环引用、BigInt、函数会抛;这条路上抛出来会连累整个
|
|
5
|
+
* 界面帧或原生命令的应答。两处(原生桥、界面方法)此前各包了一个 try/catch,
|
|
6
|
+
* 合并到这里,口径固定成「序列化不了就 null」。
|
|
7
|
+
*
|
|
8
|
+
* @module dsc/core/json-text
|
|
9
|
+
*/
|
|
10
|
+
/** 一段 JSON 文本;序列化不了(循环引用、BigInt、函数)给 null。 */
|
|
11
|
+
export declare function jsonText(value: unknown): string | null;
|