@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
|
@@ -1,13 +1,121 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 搜索工具两件套:glob(文件名匹配)/ grep(内容匹配)。
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* 三条口径(2026-10-30 重写,全部来自真实报障):
|
|
5
|
+
*
|
|
6
|
+
* 1. **遍历时必须按 `.gitignore` 跳过**:项目里 `uv sync` 一次,`.venv` 就是几千个文件;
|
|
7
|
+
* 以前的遍历把它们全收进列表再过滤,结果被这些噪声挤掉。
|
|
8
|
+
* 2. **边遍历边匹配,够数就停**:旧实现先收 10000 条再过滤,`.venv` 正好能把额度吃光,
|
|
9
|
+
* 于是根目录的 `main.py`、`README.md` 根本没进过列表——表现是「无匹配」,看起来像
|
|
10
|
+
* 文件不存在。这不是 .gitignore 的问题,是**静默截断**,比不给结果更坏。
|
|
11
|
+
* 3. **截断要说出来**:命中上限时明确写「还有更多」,不假装这就是全部。
|
|
12
|
+
*
|
|
13
|
+
* 跳过规则分两层:内置的大目录表(`.venv` / `node_modules` / `__pycache__` 等,即使仓库
|
|
14
|
+
* 没写 `.gitignore` 也不会被他们淹没)+ 仓库自己的 `.gitignore`(从 git 根逐层读到搜索根,
|
|
15
|
+
* 子目录的 `.gitignore` 在遍历到它时生效)。否定规则(`!`)按「后出现的赢」处理。
|
|
4
16
|
*
|
|
5
17
|
* @module dsc/core/tools/search-tools
|
|
6
18
|
*/
|
|
7
19
|
import { promises as fs } from 'node:fs';
|
|
8
|
-
import { isAbsolute, join, relative, resolve } from 'node:path';
|
|
9
|
-
|
|
20
|
+
import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
21
|
+
/**
|
|
22
|
+
* 无论 `.gitignore` 怎么写都跳过的目录:装依赖/缓存/编译产物,它们不是「别人的项目」,
|
|
23
|
+
* 是**当前项目的噪声**。留一个是留隐患——`uv sync` 出来的是 `.venv`,pnpm 出来的是
|
|
24
|
+
* `node_modules`,都会把遍历额度吃光。
|
|
25
|
+
*/
|
|
26
|
+
const IGNORED_DIRS = new Set([
|
|
27
|
+
'node_modules',
|
|
28
|
+
'.git',
|
|
29
|
+
'dist',
|
|
30
|
+
'build',
|
|
31
|
+
'coverage',
|
|
32
|
+
'__pycache__',
|
|
33
|
+
'.venv',
|
|
34
|
+
'venv',
|
|
35
|
+
'.pytest_cache',
|
|
36
|
+
'.mypy_cache',
|
|
37
|
+
'.ruff_cache',
|
|
38
|
+
'.tox',
|
|
39
|
+
'.next',
|
|
40
|
+
'.nuxt',
|
|
41
|
+
'.turbo',
|
|
42
|
+
'.cache',
|
|
43
|
+
'.parcel-cache',
|
|
44
|
+
'site-packages',
|
|
45
|
+
'target',
|
|
46
|
+
'Pods',
|
|
47
|
+
]);
|
|
10
48
|
const MAX_FILE_BYTES = 1024 * 1024;
|
|
49
|
+
/** 大括号展开最多出几条模式:`{a,b}{c,d}` 这种组合会指数增长,得有个头。 */
|
|
50
|
+
const BRACE_EXPANSION_LIMIT = 64;
|
|
51
|
+
/** 正则元字符:glob 里的字面量段搬进 RegExp 之前先过这一道。 */
|
|
52
|
+
const ESCAPE_RE = /[.*+?^${}()|[\]\\]/g;
|
|
53
|
+
/** 按顶层逗号切一段(`a,{b,c}` 里内层的逗号不切)。 */
|
|
54
|
+
function splitBraceOptions(body) {
|
|
55
|
+
const parts = [];
|
|
56
|
+
let depth = 0;
|
|
57
|
+
let current = '';
|
|
58
|
+
for (const ch of body) {
|
|
59
|
+
if (ch === '{')
|
|
60
|
+
depth += 1;
|
|
61
|
+
else if (ch === '}')
|
|
62
|
+
depth -= 1;
|
|
63
|
+
if (ch === ',' && depth === 0) {
|
|
64
|
+
parts.push(current);
|
|
65
|
+
current = '';
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
current += ch;
|
|
69
|
+
}
|
|
70
|
+
parts.push(current);
|
|
71
|
+
return parts;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 把 `{a,b}` 展开成多条模式(花括号展开的最小子集,支持嵌套)。
|
|
75
|
+
*
|
|
76
|
+
* 为什么要有(2026-10-30):反馈里那条 `{vue,ts,js,json}` 多选模式一条都没匹配上,
|
|
77
|
+
* 而且**不报错**,看起来就像「这个目录是空的」——一次误判足以让模型走错方向。
|
|
78
|
+
* 只有真带逗号的 `{a,b}` 才展开:`{single}` 在 shell 里是字面量,这里保持一致。
|
|
79
|
+
* `{` 没有配对的 `}` 直接报错,不静默返回空结果。
|
|
80
|
+
*
|
|
81
|
+
* @param pattern - 原始模式。
|
|
82
|
+
* @param limit - 最多展开出几条;超出后截断(宁少不多,避免一次请求铺开几百个匹配器)。
|
|
83
|
+
* @returns 展开后的模式列表(不需要展开时就是原样一条)。
|
|
84
|
+
*/
|
|
85
|
+
export function expandBraces(pattern, limit = BRACE_EXPANSION_LIMIT) {
|
|
86
|
+
const open = pattern.indexOf('{');
|
|
87
|
+
if (open < 0)
|
|
88
|
+
return [pattern];
|
|
89
|
+
let depth = 0;
|
|
90
|
+
let close = -1;
|
|
91
|
+
for (let i = open; i < pattern.length; i += 1) {
|
|
92
|
+
if (pattern[i] === '{')
|
|
93
|
+
depth += 1;
|
|
94
|
+
else if (pattern[i] === '}') {
|
|
95
|
+
depth -= 1;
|
|
96
|
+
if (depth === 0) {
|
|
97
|
+
close = i;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (close < 0)
|
|
103
|
+
throw new Error(`glob 模式里的 { 没有配对的 }:${pattern}`);
|
|
104
|
+
const options = splitBraceOptions(pattern.slice(open + 1, close));
|
|
105
|
+
if (options.length < 2)
|
|
106
|
+
return [pattern];
|
|
107
|
+
const prefix = pattern.slice(0, open);
|
|
108
|
+
const suffix = pattern.slice(close + 1);
|
|
109
|
+
const out = [];
|
|
110
|
+
for (const option of options) {
|
|
111
|
+
for (const expanded of expandBraces(`${prefix}${option}${suffix}`, limit)) {
|
|
112
|
+
out.push(expanded);
|
|
113
|
+
if (out.length >= limit)
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
11
119
|
/** 把 glob 模式转 RegExp:`**` 跨目录段,`*`/`?` 段内。 */
|
|
12
120
|
function globToRegExp(pattern) {
|
|
13
121
|
const normalized = pattern.replace(/\\/g, '/');
|
|
@@ -29,43 +137,193 @@ function globToRegExp(pattern) {
|
|
|
29
137
|
source += '[^/]';
|
|
30
138
|
}
|
|
31
139
|
else {
|
|
32
|
-
source += char.replace(
|
|
140
|
+
source += char.replace(ESCAPE_RE, '\\$&');
|
|
33
141
|
}
|
|
34
142
|
}
|
|
35
143
|
return new RegExp(`^${source}$`);
|
|
36
144
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
145
|
+
/**
|
|
146
|
+
* 把 `.gitignore` 的正文解析成规则表。
|
|
147
|
+
*
|
|
148
|
+
* 支持子集:注释、空行、`!` 否定、结尾 `/`(只匹配目录)、开头 `/`(锚定到本目录)、
|
|
149
|
+
* 含 `/` 的模式(相对本目录)、不含 `/` 的模式(匹配任意层级的同名项)、`*` `?` `**`。
|
|
150
|
+
* 不支持 `[a-z]` 字符集与 `\\` 转义——遇到就按字面量处理,宁可少忽略也不错忽略。
|
|
151
|
+
*/
|
|
152
|
+
export function parseGitignore(text, dir) {
|
|
153
|
+
const rules = [];
|
|
154
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
155
|
+
let line = raw.trim();
|
|
156
|
+
if (line === '' || line.startsWith('#'))
|
|
157
|
+
continue;
|
|
158
|
+
let negate = false;
|
|
159
|
+
if (line.startsWith('!')) {
|
|
160
|
+
negate = true;
|
|
161
|
+
line = line.slice(1);
|
|
162
|
+
}
|
|
163
|
+
// 结尾空白在 gitignore 里要靠反斜杠转义才算内容;行尾空格直接忽略即可(本实现不处理转义)
|
|
164
|
+
line = line.trimEnd();
|
|
165
|
+
if (line === '')
|
|
166
|
+
continue;
|
|
167
|
+
const dirOnly = line.endsWith('/');
|
|
168
|
+
if (dirOnly)
|
|
169
|
+
line = line.slice(0, -1);
|
|
170
|
+
const anchored = line.startsWith('/') || line.includes('/');
|
|
171
|
+
if (line.startsWith('/'))
|
|
172
|
+
line = line.slice(1);
|
|
173
|
+
if (line === '')
|
|
174
|
+
continue;
|
|
175
|
+
const body = globToRegExpSource(line);
|
|
176
|
+
// 不含 / 的模式匹配任意层级:`*.log` 等于 `**/*.log`
|
|
177
|
+
const source = anchored || line.includes('/') ? `^${body}$` : `^(?:.*/)?${body}$`;
|
|
178
|
+
rules.push({ dir, regex: new RegExp(source), negate, dirOnly });
|
|
179
|
+
}
|
|
180
|
+
return rules;
|
|
181
|
+
}
|
|
182
|
+
/** glob → 正则片段(不锚定,供 gitignore 复用;与 {@link globToRegExp} 同一套语义)。 */
|
|
183
|
+
function globToRegExpSource(pattern) {
|
|
184
|
+
const normalized = pattern.replace(/\\/g, '/');
|
|
185
|
+
let source = '';
|
|
186
|
+
for (let i = 0; i < normalized.length; i += 1) {
|
|
187
|
+
const char = normalized[i];
|
|
188
|
+
if (char === '*') {
|
|
189
|
+
if (normalized[i + 1] === '*') {
|
|
190
|
+
source += '.*';
|
|
191
|
+
i += 1;
|
|
192
|
+
if (normalized[i + 1] === '/')
|
|
193
|
+
i += 1;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
source += '[^/]*';
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else if (char === '?') {
|
|
200
|
+
source += '[^/]';
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
source += char.replace(ESCAPE_RE, '\\$&');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return source;
|
|
207
|
+
}
|
|
208
|
+
/** 这条规则对绝对路径成不成立:不在规则目录下面的直接不算。 */
|
|
209
|
+
function ruleMatches(rule, absPath, isDir) {
|
|
210
|
+
if (rule.dirOnly && !isDir)
|
|
211
|
+
return false;
|
|
212
|
+
const rel = relative(rule.dir, absPath).replace(/\\/g, '/');
|
|
213
|
+
if (rel === '' || rel.startsWith('../') || isAbsolute(rel))
|
|
214
|
+
return false;
|
|
215
|
+
return rule.regex.test(rel);
|
|
216
|
+
}
|
|
217
|
+
/** 后出现的规则赢:命中一条就翻转一次结论。 */
|
|
218
|
+
function isIgnored(rules, absPath, isDir) {
|
|
219
|
+
let ignored = false;
|
|
220
|
+
for (const rule of rules) {
|
|
221
|
+
if (ruleMatches(rule, absPath, isDir))
|
|
222
|
+
ignored = !rule.negate;
|
|
223
|
+
}
|
|
224
|
+
return ignored;
|
|
225
|
+
}
|
|
226
|
+
/** git 根:从 `dir` 往上找带 `.git` 的目录;找不到就用 `dir` 自己。 */
|
|
227
|
+
async function findGitRoot(dir) {
|
|
228
|
+
let current = resolve(dir);
|
|
229
|
+
for (;;) {
|
|
230
|
+
try {
|
|
231
|
+
await fs.stat(join(current, '.git'));
|
|
232
|
+
return current;
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
const parent = dirname(current);
|
|
236
|
+
if (parent === current)
|
|
237
|
+
return resolve(dir);
|
|
238
|
+
current = parent;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/** 从 git 根到 `root` 沿途每一层的 `.gitignore` 依次读进来(祖先的规则先于子目录)。 */
|
|
243
|
+
async function loadIgnoreChain(root) {
|
|
244
|
+
const gitRoot = await findGitRoot(root);
|
|
245
|
+
const chain = [];
|
|
246
|
+
let current = resolve(root);
|
|
247
|
+
for (;;) {
|
|
248
|
+
chain.unshift(current);
|
|
249
|
+
if (current === gitRoot)
|
|
250
|
+
break;
|
|
251
|
+
const parent = dirname(current);
|
|
252
|
+
if (parent === current)
|
|
253
|
+
break;
|
|
254
|
+
current = parent;
|
|
255
|
+
}
|
|
256
|
+
const rules = [];
|
|
257
|
+
for (const dir of chain) {
|
|
258
|
+
try {
|
|
259
|
+
const text = await fs.readFile(join(dir, '.gitignore'), 'utf8');
|
|
260
|
+
rules.push(...parseGitignore(text, dir));
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
// 没有 .gitignore 是常态
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return rules;
|
|
267
|
+
}
|
|
268
|
+
// ── 遍历 ────────────────────────────────────────────────────────────────────
|
|
269
|
+
/**
|
|
270
|
+
* 递归遍历,**边遍历边交给回调**:回调返回 false 表示「够了,别走了」。
|
|
271
|
+
*
|
|
272
|
+
* 与旧实现(先收 10000 条再过滤)的区别:额度按「命中的文件」算,不按「走过的文件」算,
|
|
273
|
+
* 所以 `.venv` 再大也挤不掉别的结果。目录级的忽略在这里判定——命中就整棵子树不进去。
|
|
274
|
+
*
|
|
275
|
+
* @param dir - 当前目录
|
|
276
|
+
* @param rules - 继承下来的忽略规则;本目录的 `.gitignore` 在这里读入并继续往下传
|
|
277
|
+
* @param visit - 对每个文件调用一次;返回 false 立刻停
|
|
278
|
+
*/
|
|
279
|
+
async function walkFiles(dir, rules, visit) {
|
|
280
|
+
let local = rules;
|
|
281
|
+
try {
|
|
282
|
+
const text = await fs.readFile(join(dir, '.gitignore'), 'utf8');
|
|
283
|
+
local = [...rules, ...parseGitignore(text, dir)];
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
// 没有就是没有
|
|
287
|
+
}
|
|
40
288
|
let entries;
|
|
41
289
|
try {
|
|
42
290
|
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
43
291
|
}
|
|
44
292
|
catch {
|
|
45
|
-
return;
|
|
293
|
+
return true;
|
|
46
294
|
}
|
|
47
295
|
for (const entry of entries) {
|
|
48
|
-
if (out.length >= limit)
|
|
49
|
-
return;
|
|
50
296
|
const full = join(dir, entry.name);
|
|
51
297
|
if (entry.isDirectory()) {
|
|
52
|
-
if (
|
|
298
|
+
if (IGNORED_DIRS.has(entry.name))
|
|
299
|
+
continue;
|
|
300
|
+
if (isIgnored(local, full, true))
|
|
53
301
|
continue;
|
|
54
|
-
await
|
|
302
|
+
const more = await walkFiles(full, local, visit);
|
|
303
|
+
if (!more)
|
|
304
|
+
return false;
|
|
55
305
|
}
|
|
56
306
|
else if (entry.isFile()) {
|
|
57
|
-
|
|
307
|
+
if (isIgnored(local, full, false))
|
|
308
|
+
continue;
|
|
309
|
+
if (!(await visit(full)))
|
|
310
|
+
return false;
|
|
58
311
|
}
|
|
59
312
|
}
|
|
313
|
+
return true;
|
|
60
314
|
}
|
|
61
315
|
const displayPath = (root, file) => relative(root, file).replace(/\\/g, '/');
|
|
316
|
+
/** 截断时补的那句话:说清「这不是全部」,并给出缩小范围的办法。 */
|
|
317
|
+
const truncatedNote = (shown) => `\n(只显示前 ${String(shown)} 条,还有更多;把 pattern 或 path 收窄一点再看全部)`;
|
|
62
318
|
export const globTool = {
|
|
63
319
|
name: 'glob',
|
|
64
|
-
description: '按文件名模式查找文件(相对当前目录)。支持 ** 跨目录、* 段内通配、?
|
|
320
|
+
description: '按文件名模式查找文件(相对当前目录)。支持 ** 跨目录、* 段内通配、? 单字符、{a,b} 花括号多选。' +
|
|
321
|
+
'默认跳过 .gitignore 命中的文件与 node_modules/.venv/__pycache__ 等大目录。' +
|
|
322
|
+
'例:**/*.ts、src/*.json、**/*.{vue,ts,js}。',
|
|
65
323
|
parameters: {
|
|
66
324
|
type: 'object',
|
|
67
325
|
properties: {
|
|
68
|
-
pattern: { type: 'string', description: 'glob
|
|
326
|
+
pattern: { type: 'string', description: 'glob 模式(支持 {a,b} 多选)' },
|
|
69
327
|
path: { type: 'string', description: '搜索根目录(默认当前目录)' },
|
|
70
328
|
limit: { type: 'number', description: '最多返回条数(默认 100)' },
|
|
71
329
|
},
|
|
@@ -79,16 +337,31 @@ export const globTool = {
|
|
|
79
337
|
? (isAbsolute(args.path) ? args.path : resolve(ctx.cwd, args.path))
|
|
80
338
|
: ctx.cwd;
|
|
81
339
|
const limit = Math.max(1, typeof args.limit === 'number' ? Math.floor(args.limit) : 100);
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
await
|
|
85
|
-
const hits =
|
|
86
|
-
|
|
340
|
+
// {a,b} 先展开成多条模式再逐条编译:`**/*.{vue,ts}` 以前被当成字面量,静默给「无匹配」。
|
|
341
|
+
const matchers = expandBraces(args.pattern).map(globToRegExp);
|
|
342
|
+
const rules = await loadIgnoreChain(root);
|
|
343
|
+
const hits = [];
|
|
344
|
+
let truncated = false;
|
|
345
|
+
await walkFiles(root, rules, (file) => {
|
|
346
|
+
const rel = displayPath(root, file);
|
|
347
|
+
if (!matchers.some((matcher) => matcher.test(rel)))
|
|
348
|
+
return true;
|
|
349
|
+
if (hits.length >= limit) {
|
|
350
|
+
truncated = true;
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
hits.push(rel);
|
|
354
|
+
return true;
|
|
355
|
+
});
|
|
356
|
+
if (hits.length === 0)
|
|
357
|
+
return `(无匹配:${args.pattern})`;
|
|
358
|
+
return `${hits.join('\n')}${truncated ? truncatedNote(limit) : ''}`;
|
|
87
359
|
},
|
|
88
360
|
};
|
|
89
361
|
export const grepTool = {
|
|
90
362
|
name: 'grep',
|
|
91
|
-
description: '在目录内按行搜索内容(正则或纯文本),返回 文件:行号:
|
|
363
|
+
description: '在目录内按行搜索内容(正则或纯文本),返回 文件:行号: 内容。跳过二进制与大文件,' +
|
|
364
|
+
'并默认跳过 .gitignore 命中的文件与 node_modules/.venv/__pycache__ 等大目录。',
|
|
92
365
|
parameters: {
|
|
93
366
|
type: 'object',
|
|
94
367
|
properties: {
|
|
@@ -114,40 +387,54 @@ export const grepTool = {
|
|
|
114
387
|
? (isAbsolute(args.path) ? args.path : resolve(ctx.cwd, args.path))
|
|
115
388
|
: ctx.cwd;
|
|
116
389
|
const rootStat = await fs.stat(root);
|
|
117
|
-
const files = rootStat.isFile() ? [root] : [];
|
|
118
|
-
if (files.length === 0)
|
|
119
|
-
await walk(root, root, files, 20_000);
|
|
120
390
|
const lines = [];
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
break;
|
|
391
|
+
/** 读一个文件、把命中的行攒进去;返回 false 表示「够数了」。 */
|
|
392
|
+
const scan = async (file) => {
|
|
124
393
|
let stat;
|
|
125
394
|
try {
|
|
126
395
|
stat = await fs.stat(file);
|
|
127
396
|
}
|
|
128
397
|
catch {
|
|
129
|
-
|
|
398
|
+
return true;
|
|
130
399
|
}
|
|
131
400
|
if (!stat.isFile() || stat.size > MAX_FILE_BYTES)
|
|
132
|
-
|
|
401
|
+
return true;
|
|
133
402
|
let content;
|
|
134
403
|
try {
|
|
135
404
|
content = await fs.readFile(file, 'utf8');
|
|
136
405
|
}
|
|
137
406
|
catch {
|
|
138
|
-
|
|
407
|
+
return true;
|
|
139
408
|
}
|
|
140
409
|
if (content.includes('\0'))
|
|
141
|
-
|
|
410
|
+
return true;
|
|
142
411
|
const split = content.split(/\r?\n/);
|
|
143
412
|
for (let index = 0; index < split.length; index += 1) {
|
|
144
413
|
if (lines.length >= maxResults)
|
|
145
|
-
|
|
414
|
+
return false;
|
|
146
415
|
if (matcher.test(split[index])) {
|
|
147
|
-
lines.push(`${displayPath(root, file)}:${index + 1}: ${split[index].trim().slice(0, 200)}`);
|
|
416
|
+
lines.push(`${displayPath(root, file)}:${String(index + 1)}: ${split[index].trim().slice(0, 200)}`);
|
|
148
417
|
}
|
|
149
418
|
}
|
|
419
|
+
return true;
|
|
420
|
+
};
|
|
421
|
+
let truncated = false;
|
|
422
|
+
if (rootStat.isFile()) {
|
|
423
|
+
await scan(root);
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
const rules = await loadIgnoreChain(root);
|
|
427
|
+
// 边遍历边扫:够数就停,不需要先把几千个路径攒进数组(旧毛病的来源之一)。
|
|
428
|
+
await walkFiles(root, rules, async (file) => {
|
|
429
|
+
if (lines.length >= maxResults) {
|
|
430
|
+
truncated = true;
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
return scan(file);
|
|
434
|
+
});
|
|
150
435
|
}
|
|
151
|
-
|
|
436
|
+
if (lines.length === 0)
|
|
437
|
+
return `(无匹配:${args.pattern})`;
|
|
438
|
+
return `${lines.join('\n')}${truncated ? truncatedNote(maxResults) : ''}`;
|
|
152
439
|
},
|
|
153
440
|
};
|
package/lib/core/tools.d.ts
CHANGED
|
@@ -44,15 +44,45 @@ export interface ToolContext {
|
|
|
44
44
|
background: boolean;
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* 一次工具调用的呈现数据(可选)。
|
|
49
|
+
*
|
|
50
|
+
* 谁写:dsh 兼容层——它把 dsh 工具的 presentCall / presentResult / presentationMeta
|
|
51
|
+
* 的产物塞进来(形状见 `core/dsh-compat/presentation.ts`)。
|
|
52
|
+
* 谁读:适配层把它缝到工具卡上(`ToolCallView.presentation`),界面按 `card` 标签
|
|
53
|
+
* 挑渲染形态;没认出来的卡片不至于丢数据,界面回落通用工具卡。
|
|
54
|
+
*
|
|
55
|
+
* 为什么放在核心契约而不是兼容层:它是「工具能对界面说什么」的一个槽,Pneuma 自己
|
|
56
|
+
* 的工具将来也可能往里写;词汇(六种卡片)属于 dsh 兼容层,槽本身不属于。
|
|
57
|
+
*/
|
|
58
|
+
export interface ToolPresentation {
|
|
59
|
+
/** 调用阶段的卡片(还没跑完时长什么样)。 */
|
|
60
|
+
call?: unknown;
|
|
61
|
+
/** 完成阶段的卡片(跑完长什么样)。 */
|
|
62
|
+
result?: unknown;
|
|
63
|
+
/** 可重放的展示投影(dsh 用它重建卡片,故必须是与值无关的纯数据)。 */
|
|
64
|
+
meta?: unknown;
|
|
65
|
+
}
|
|
47
66
|
/** 工具输出:纯文本,或文本 + 附带图像(data URL;需端点支持视觉)。 */
|
|
48
67
|
export interface ToolOutput {
|
|
49
68
|
text: string;
|
|
50
69
|
images?: string[];
|
|
70
|
+
/** 给界面的卡片数据(dsh 插件才有;见 {@link ToolPresentation})。 */
|
|
71
|
+
presentation?: ToolPresentation;
|
|
51
72
|
/**
|
|
52
73
|
* 落盘类工具(write / edit)附带的真实改动:循环会把它发成 `tool/changes` 事件、
|
|
53
74
|
* 随工具记录落盘(会话恢复时轮尾「文件已更改」卡据此还原)。执行失败时没有这一项。
|
|
54
75
|
*/
|
|
55
76
|
changes?: FileChangeSummary;
|
|
77
|
+
/**
|
|
78
|
+
* **一次调用动了多个文件**时的改动清单(PTC 的 `run_code` 就是这种:一段脚本里
|
|
79
|
+
* 可能调了五次 `sdk.write`)。
|
|
80
|
+
*
|
|
81
|
+
* 为什么不能只靠上面那个单值(2026-10-30 报障):PTC 以前只取工具返回的 `text`,
|
|
82
|
+
* 把 `changes` 连同回合基线一起丢了——用户在那个会话里改了十几个文件,会话底部
|
|
83
|
+
* 一张「文件已更改」卡都没有,非 git 工作区更是完全看不见。
|
|
84
|
+
*/
|
|
85
|
+
changesList?: FileChangeSummary[];
|
|
56
86
|
}
|
|
57
87
|
export interface ToolEntry {
|
|
58
88
|
name: string;
|
|
@@ -68,6 +98,43 @@ export interface ToolEntry {
|
|
|
68
98
|
* 也能看见它;真正的安全边界在守卫链与审批卡,跟这个字段无关。
|
|
69
99
|
*/
|
|
70
100
|
presets?: readonly string[];
|
|
101
|
+
/**
|
|
102
|
+
* 这次调用的超时预算(毫秒)。dsh 插件声明了 `timeoutMs` 时由兼容层填进来;
|
|
103
|
+
* 真正的到点放弃在兼容层的 `run` 里做(协作式:工具自己看 signal 才是真取消)。
|
|
104
|
+
*/
|
|
105
|
+
timeoutMs?: number;
|
|
106
|
+
/**
|
|
107
|
+
* 这个工具跑起来是在**等人**(提问卡、审批卡这类,人答完才返回)。
|
|
108
|
+
*
|
|
109
|
+
* 只有 PTC 的脚本时限认这一位:等人的时间不算脚本的时间。不声明的话,用户在卡上
|
|
110
|
+
* 想了三分钟,120 秒的脚本时限先把脚本掐死,答案再交回来也没有人接了
|
|
111
|
+
* (2026-10-29 报障:提问卡超时后答了,对话不动)。它不是权限声明,也不影响
|
|
112
|
+
* 单次调用本身的行为——工具自己怎么等、等多久,仍由工具决定。
|
|
113
|
+
*/
|
|
114
|
+
waitsForHuman?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* 这次调用能不能与同轮别的工具并行(dsh 的 `isConcurrencySafe(args)`)。
|
|
117
|
+
*
|
|
118
|
+
* 只认明确的 `true`:缺省、抛错、返回非 true 一律当独占(与 dsh 同一口径)。
|
|
119
|
+
* 现在只是把这个事实记下来,循环还没有并行调度器。
|
|
120
|
+
*/
|
|
121
|
+
isConcurrencySafe?(args: Record<string, unknown>): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* 这个工具是「转调别人」的桥:真名、真实风险与真实参数由它自己报上来。
|
|
124
|
+
*
|
|
125
|
+
* 为什么要有这一位(2026-10-30 用户报障):`tool_call` 这类桥接工具如果按自己的名字过
|
|
126
|
+
* 守卫链,审批卡上写的是「调用 tool_call」,用户看不出到底要动哪条工具;桥在内部再判一次,
|
|
127
|
+
* 同一个动作就要点两张卡。让桥提前交出目标身份,循环就能**只问一遍**,而模式闸门、安全钩子、
|
|
128
|
+
* 沙箱与审批卡看到的是被调的那条工具的真名、真实风险与真实写目标。
|
|
129
|
+
*
|
|
130
|
+
* 返回 undefined = 认不出目标(名字拼错、参数坏掉):这时按桥自己判定,一次调用照旧只问一遍。
|
|
131
|
+
* 它只影响「问谁」与「按什么风险排并发」,不改变 `run` 的执行权——桥仍负责真正执行。
|
|
132
|
+
*/
|
|
133
|
+
gateAs?(args: Record<string, unknown>, cwd: string): {
|
|
134
|
+
name: string;
|
|
135
|
+
risk: ToolRisk;
|
|
136
|
+
args: Record<string, unknown>;
|
|
137
|
+
} | undefined;
|
|
71
138
|
/** 执行并返回给模型的结果;失败时抛错(loop 转成 error 结果)。 */
|
|
72
139
|
run(args: Record<string, unknown>, ctx: ToolContext): Promise<string | ToolOutput>;
|
|
73
140
|
}
|
|
@@ -85,6 +152,21 @@ export declare function callFacts(args: Record<string, unknown>, cwd: string): {
|
|
|
85
152
|
target?: string;
|
|
86
153
|
command?: string;
|
|
87
154
|
};
|
|
155
|
+
/**
|
|
156
|
+
* 这次调用该按谁的身份过守卫链({@link ToolEntry.gateAs} 的唯一实现处)。
|
|
157
|
+
*
|
|
158
|
+
* 桥接工具(`tool_call`)报出被调工具的真名、真实风险与真实参数,循环与 PTC 都拿这一份去问;
|
|
159
|
+
* 两种退回情况按桥自己判定,保证一次调用**恰好问一遍**:桥不认(返回 undefined)、桥抛错。
|
|
160
|
+
*
|
|
161
|
+
* @param tool - 模型点名的那个工具(可能是桥)。
|
|
162
|
+
* @param args - 模型给它的参数。
|
|
163
|
+
* @param cwd - 会话工作目录。
|
|
164
|
+
*/
|
|
165
|
+
export declare function gateIdentity(tool: ToolEntry, args: Record<string, unknown>, cwd: string): {
|
|
166
|
+
name: string;
|
|
167
|
+
risk: ToolRisk;
|
|
168
|
+
args: Record<string, unknown>;
|
|
169
|
+
};
|
|
88
170
|
/**
|
|
89
171
|
* 把一次工具调用的参数压成一行文字,给审批卡、审计日志这类给人看的地方用。
|
|
90
172
|
*
|
package/lib/core/tools.js
CHANGED
|
@@ -37,6 +37,27 @@ export function callFacts(args, cwd) {
|
|
|
37
37
|
out.command = command;
|
|
38
38
|
return out;
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* 这次调用该按谁的身份过守卫链({@link ToolEntry.gateAs} 的唯一实现处)。
|
|
42
|
+
*
|
|
43
|
+
* 桥接工具(`tool_call`)报出被调工具的真名、真实风险与真实参数,循环与 PTC 都拿这一份去问;
|
|
44
|
+
* 两种退回情况按桥自己判定,保证一次调用**恰好问一遍**:桥不认(返回 undefined)、桥抛错。
|
|
45
|
+
*
|
|
46
|
+
* @param tool - 模型点名的那个工具(可能是桥)。
|
|
47
|
+
* @param args - 模型给它的参数。
|
|
48
|
+
* @param cwd - 会话工作目录。
|
|
49
|
+
*/
|
|
50
|
+
export function gateIdentity(tool, args, cwd) {
|
|
51
|
+
try {
|
|
52
|
+
const delegate = tool.gateAs?.(args, cwd);
|
|
53
|
+
if (delegate !== undefined)
|
|
54
|
+
return delegate;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// 桥自己报不出目标:退回按桥的名字问一遍,不让一个坏钩子断掉整轮
|
|
58
|
+
}
|
|
59
|
+
return { name: tool.name, risk: tool.risk, args };
|
|
60
|
+
}
|
|
40
61
|
/** 卡片上那行参数摘要的最长字符数(再长就是把整篇正文塞进按钮旁边)。 */
|
|
41
62
|
const ARGS_SUMMARY_MAX = 160;
|
|
42
63
|
/**
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 从会话消息里取文本(全仓库唯一一份)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独一个模块:「从末尾往回找最后一条 user / assistant 消息,取纯文本去首尾空白」
|
|
5
|
+
* 这段逻辑此前在手写三份(`core/learnings/skill-write.ts` 两份、
|
|
6
|
+
* `plugins/memory.ts` 两份同名本地函数),而它跟技能、记忆这两个业务域都没关系,
|
|
7
|
+
* 只是会话流的读法。放 core 让两边都引,不必让记忆插件去 import 技能模块。
|
|
8
|
+
*
|
|
9
|
+
* 依赖只有 `contentText`(把 string / 内容块数组都压成纯文本)。
|
|
10
|
+
*
|
|
11
|
+
* @module dsc/core/transcript-text
|
|
12
|
+
*/
|
|
13
|
+
import { type ChatMessage } from './llm.js';
|
|
14
|
+
/** 最后一条用户消息的纯文本;没有用户消息返回空串。 */
|
|
15
|
+
export declare function lastUserText(messages: readonly ChatMessage[]): string;
|
|
16
|
+
/** 倒数第二条用户消息的纯文本(「上一轮用户说了什么」);不足两条返回空串。 */
|
|
17
|
+
export declare function previousUserText(messages: readonly ChatMessage[]): string;
|
|
18
|
+
/** 最后一条 assistant 消息的正文;没有 assistant 消息返回空串。 */
|
|
19
|
+
export declare function lastAssistantText(messages: readonly ChatMessage[]): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 从会话消息里取文本(全仓库唯一一份)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独一个模块:「从末尾往回找最后一条 user / assistant 消息,取纯文本去首尾空白」
|
|
5
|
+
* 这段逻辑此前在手写三份(`core/learnings/skill-write.ts` 两份、
|
|
6
|
+
* `plugins/memory.ts` 两份同名本地函数),而它跟技能、记忆这两个业务域都没关系,
|
|
7
|
+
* 只是会话流的读法。放 core 让两边都引,不必让记忆插件去 import 技能模块。
|
|
8
|
+
*
|
|
9
|
+
* 依赖只有 `contentText`(把 string / 内容块数组都压成纯文本)。
|
|
10
|
+
*
|
|
11
|
+
* @module dsc/core/transcript-text
|
|
12
|
+
*/
|
|
13
|
+
import { contentText } from './llm.js';
|
|
14
|
+
/** 最后一条用户消息的纯文本;没有用户消息返回空串。 */
|
|
15
|
+
export function lastUserText(messages) {
|
|
16
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
17
|
+
const message = messages[index];
|
|
18
|
+
if (message !== undefined && message.role === 'user')
|
|
19
|
+
return contentText(message.content).trim();
|
|
20
|
+
}
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
/** 倒数第二条用户消息的纯文本(「上一轮用户说了什么」);不足两条返回空串。 */
|
|
24
|
+
export function previousUserText(messages) {
|
|
25
|
+
let seen = 0;
|
|
26
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
27
|
+
const message = messages[index];
|
|
28
|
+
if (message === undefined || message.role !== 'user')
|
|
29
|
+
continue;
|
|
30
|
+
seen += 1;
|
|
31
|
+
if (seen === 2)
|
|
32
|
+
return contentText(message.content).trim();
|
|
33
|
+
}
|
|
34
|
+
return '';
|
|
35
|
+
}
|
|
36
|
+
/** 最后一条 assistant 消息的正文;没有 assistant 消息返回空串。 */
|
|
37
|
+
export function lastAssistantText(messages) {
|
|
38
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
39
|
+
const message = messages[index];
|
|
40
|
+
if (message !== undefined && message.role === 'assistant')
|
|
41
|
+
return contentText(message.content).trim();
|
|
42
|
+
}
|
|
43
|
+
return '';
|
|
44
|
+
}
|
|
@@ -44,6 +44,11 @@ export interface UiBootSourceOptions {
|
|
|
44
44
|
builtinDir: string;
|
|
45
45
|
/** 第三方插件根目录;不给用标准落点。 */
|
|
46
46
|
thirdPartyDir?: string;
|
|
47
|
+
/**
|
|
48
|
+
* 组合包所在的 profile 目录;不给按 `DSC_PROFILE` / 配置里的 `profile` 现场解析。
|
|
49
|
+
* 本机界面服务与远程壳都走这里——手机端与本机看的是同一张图,包界面半自然也该一致。
|
|
50
|
+
*/
|
|
51
|
+
packageDir?: string | null;
|
|
47
52
|
}
|
|
48
53
|
/** 宿主侧共用的启动图快照口子。 */
|
|
49
54
|
export interface UiBootSource {
|