@waq666/pneuma 0.0.0-stage → 0.7.0
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/LICENSE +21 -0
- package/README.md +144 -2
- package/bin/dsc.js +91 -0
- package/bin/headless.cjs +40 -0
- package/lib/adapter/core-runtime.d.ts +11 -0
- package/lib/adapter/core-runtime.js +259 -0
- package/lib/adapter/host.d.ts +18 -0
- package/lib/adapter/host.js +14 -0
- package/lib/adapter/runtime.d.ts +15 -0
- package/lib/adapter/runtime.js +290 -0
- package/lib/adapter/transcript.d.ts +184 -0
- package/lib/adapter/transcript.js +605 -0
- package/lib/app/AgentsOverlay.d.ts +18 -0
- package/lib/app/AgentsOverlay.js +63 -0
- package/lib/app/App.d.ts +13 -0
- package/lib/app/App.js +1498 -0
- package/lib/app/ApprovalCard.d.ts +12 -0
- package/lib/app/ApprovalCard.js +76 -0
- package/lib/app/AskCard.d.ts +20 -0
- package/lib/app/AskCard.js +45 -0
- package/lib/app/ChatView.d.ts +32 -0
- package/lib/app/ChatView.js +198 -0
- package/lib/app/Composer.d.ts +50 -0
- package/lib/app/Composer.js +282 -0
- package/lib/app/DiffBlock.d.ts +6 -0
- package/lib/app/DiffBlock.js +37 -0
- package/lib/app/MarkdownView.d.ts +6 -0
- package/lib/app/MarkdownView.js +99 -0
- package/lib/app/ModelPicker.d.ts +7 -0
- package/lib/app/ModelPicker.js +18 -0
- package/lib/app/PlanReviewCard.d.ts +13 -0
- package/lib/app/PlanReviewCard.js +54 -0
- package/lib/app/PresetPicker.d.ts +11 -0
- package/lib/app/PresetPicker.js +19 -0
- package/lib/app/PreviewOverlay.d.ts +14 -0
- package/lib/app/PreviewOverlay.js +22 -0
- package/lib/app/SessionPicker.d.ts +43 -0
- package/lib/app/SessionPicker.js +56 -0
- package/lib/app/SettingsOverlay.d.ts +32 -0
- package/lib/app/SettingsOverlay.js +157 -0
- package/lib/app/SkillsPicker.d.ts +7 -0
- package/lib/app/SkillsPicker.js +19 -0
- package/lib/app/StatusBar.d.ts +22 -0
- package/lib/app/StatusBar.js +272 -0
- package/lib/app/TaskStrips.d.ts +13 -0
- package/lib/app/TaskStrips.js +40 -0
- package/lib/app/ToolCard.d.ts +5 -0
- package/lib/app/ToolCard.js +40 -0
- package/lib/app/TranscriptOverlay.d.ts +12 -0
- package/lib/app/TranscriptOverlay.js +17 -0
- package/lib/app/Welcome.d.ts +6 -0
- package/lib/app/Welcome.js +66 -0
- package/lib/app/attach.d.ts +16 -0
- package/lib/app/attach.js +58 -0
- package/lib/app/click.d.ts +27 -0
- package/lib/app/click.js +89 -0
- package/lib/app/clipboard-image.d.ts +11 -0
- package/lib/app/clipboard-image.js +66 -0
- package/lib/app/cursor.d.ts +4 -0
- package/lib/app/cursor.js +24 -0
- package/lib/app/hello.d.ts +11 -0
- package/lib/app/hello.js +8 -0
- package/lib/app/history-store.d.ts +4 -0
- package/lib/app/history-store.js +41 -0
- package/lib/app/image-blocks.d.ts +12 -0
- package/lib/app/image-blocks.js +125 -0
- package/lib/app/markdown.d.ts +54 -0
- package/lib/app/markdown.js +189 -0
- package/lib/app/settings-model.d.ts +69 -0
- package/lib/app/settings-model.js +114 -0
- package/lib/app/theme.d.ts +166 -0
- package/lib/app/theme.js +141 -0
- package/lib/boot.d.ts +1 -0
- package/lib/boot.js +34 -0
- package/lib/commands.d.ts +49 -0
- package/lib/commands.js +115 -0
- package/lib/contract.d.ts +1973 -0
- package/lib/contract.js +36 -0
- package/lib/core/agent-roles.d.ts +52 -0
- package/lib/core/agent-roles.js +274 -0
- package/lib/core/approval-floor.d.ts +183 -0
- package/lib/core/approval-floor.js +679 -0
- package/lib/core/approval.d.ts +42 -0
- package/lib/core/approval.js +8 -0
- package/lib/core/audit.d.ts +61 -0
- package/lib/core/audit.js +59 -0
- package/lib/core/boot-notices.d.ts +6 -0
- package/lib/core/boot-notices.js +61 -0
- package/lib/core/cdp/actions.d.ts +182 -0
- package/lib/core/cdp/actions.js +649 -0
- package/lib/core/cdp/launch.d.ts +192 -0
- package/lib/core/cdp/launch.js +491 -0
- package/lib/core/cdp/snapshot.d.ts +139 -0
- package/lib/core/cdp/snapshot.js +316 -0
- package/lib/core/cdp/transport.d.ts +160 -0
- package/lib/core/cdp/transport.js +359 -0
- package/lib/core/command-policy.d.ts +108 -0
- package/lib/core/command-policy.js +580 -0
- package/lib/core/commands-completion.d.ts +78 -0
- package/lib/core/commands-completion.js +167 -0
- package/lib/core/compact-anchors.d.ts +76 -0
- package/lib/core/compact-anchors.js +284 -0
- package/lib/core/compact.d.ts +110 -0
- package/lib/core/compact.js +210 -0
- package/lib/core/config-store.d.ts +38 -0
- package/lib/core/config-store.js +307 -0
- package/lib/core/config.d.ts +36 -0
- package/lib/core/config.js +124 -0
- package/lib/core/connection-test.d.ts +60 -0
- package/lib/core/connection-test.js +84 -0
- package/lib/core/desktop-control.d.ts +298 -0
- package/lib/core/desktop-control.js +1311 -0
- package/lib/core/diff-text.d.ts +74 -0
- package/lib/core/diff-text.js +257 -0
- package/lib/core/dock-browser.d.ts +137 -0
- package/lib/core/dock-browser.js +146 -0
- package/lib/core/dock-ops.d.ts +59 -0
- package/lib/core/dock-ops.js +104 -0
- package/lib/core/dock-session.d.ts +39 -0
- package/lib/core/dock-session.js +28 -0
- package/lib/core/dsh-compat/hook.d.ts +18 -0
- package/lib/core/dsh-compat/hook.js +52 -0
- package/lib/core/dsh-compat/resolve-hook.d.ts +5 -0
- package/lib/core/dsh-compat/resolve-hook.js +59 -0
- package/lib/core/dsh-compat/tools-facade.d.ts +47 -0
- package/lib/core/dsh-compat/tools-facade.js +108 -0
- package/lib/core/err-text.d.ts +13 -0
- package/lib/core/err-text.js +15 -0
- package/lib/core/events.d.ts +149 -0
- package/lib/core/events.js +1 -0
- package/lib/core/git-exec.d.ts +23 -0
- package/lib/core/git-exec.js +72 -0
- package/lib/core/git-info.d.ts +47 -0
- package/lib/core/git-info.js +157 -0
- package/lib/core/goal.d.ts +89 -0
- package/lib/core/goal.js +189 -0
- package/lib/core/hooks.d.ts +272 -0
- package/lib/core/hooks.js +818 -0
- package/lib/core/host-browser-link.d.ts +59 -0
- package/lib/core/host-browser-link.js +9 -0
- package/lib/core/host-methods.d.ts +25 -0
- package/lib/core/host-methods.js +103 -0
- package/lib/core/image-diet.d.ts +77 -0
- package/lib/core/image-diet.js +127 -0
- package/lib/core/learnings/ledger.d.ts +73 -0
- package/lib/core/learnings/ledger.js +273 -0
- package/lib/core/learnings/skill-write.d.ts +250 -0
- package/lib/core/learnings/skill-write.js +854 -0
- package/lib/core/learnings/store.d.ts +102 -0
- package/lib/core/learnings/store.js +266 -0
- package/lib/core/lifecycle-hooks.d.ts +189 -0
- package/lib/core/lifecycle-hooks.js +576 -0
- package/lib/core/llm.d.ts +272 -0
- package/lib/core/llm.js +548 -0
- package/lib/core/lockfile.d.ts +17 -0
- package/lib/core/lockfile.js +110 -0
- package/lib/core/loop.d.ts +185 -0
- package/lib/core/loop.js +587 -0
- package/lib/core/lsp/client.d.ts +189 -0
- package/lib/core/lsp/client.js +690 -0
- package/lib/core/lsp/framing.d.ts +84 -0
- package/lib/core/lsp/framing.js +181 -0
- package/lib/core/lsp/line-shift.d.ts +28 -0
- package/lib/core/lsp/line-shift.js +127 -0
- package/lib/core/lsp/manager.d.ts +93 -0
- package/lib/core/lsp/manager.js +418 -0
- package/lib/core/lsp/normalize.d.ts +32 -0
- package/lib/core/lsp/normalize.js +139 -0
- package/lib/core/lsp/servers.d.ts +106 -0
- package/lib/core/lsp/servers.js +352 -0
- package/lib/core/lsp/uri.d.ts +76 -0
- package/lib/core/lsp/uri.js +179 -0
- package/lib/core/market.d.ts +51 -0
- package/lib/core/market.js +358 -0
- package/lib/core/mcp.d.ts +201 -0
- package/lib/core/mcp.js +836 -0
- package/lib/core/memory-eval.d.ts +158 -0
- package/lib/core/memory-eval.js +215 -0
- package/lib/core/memory.d.ts +266 -0
- package/lib/core/memory.js +703 -0
- package/lib/core/mention.d.ts +57 -0
- package/lib/core/mention.js +129 -0
- package/lib/core/microcompact.d.ts +48 -0
- package/lib/core/microcompact.js +79 -0
- package/lib/core/migrate.d.ts +56 -0
- package/lib/core/migrate.js +134 -0
- package/lib/core/model-caps.d.ts +83 -0
- package/lib/core/model-caps.js +150 -0
- package/lib/core/model-discovery.d.ts +19 -0
- package/lib/core/model-discovery.js +69 -0
- package/lib/core/modes.d.ts +72 -0
- package/lib/core/modes.js +152 -0
- package/lib/core/native-bridge.d.ts +135 -0
- package/lib/core/native-bridge.js +563 -0
- package/lib/core/path-policy.d.ts +32 -0
- package/lib/core/path-policy.js +248 -0
- package/lib/core/permission-presets.d.ts +67 -0
- package/lib/core/permission-presets.js +75 -0
- package/lib/core/plugin-loader.d.ts +36 -0
- package/lib/core/plugin-loader.js +294 -0
- package/lib/core/plugin-registry.d.ts +113 -0
- package/lib/core/plugin-registry.js +256 -0
- package/lib/core/prefs.d.ts +82 -0
- package/lib/core/prefs.js +372 -0
- package/lib/core/presets.d.ts +80 -0
- package/lib/core/presets.js +373 -0
- package/lib/core/pricing.d.ts +90 -0
- package/lib/core/pricing.js +126 -0
- package/lib/core/prompt.d.ts +92 -0
- package/lib/core/prompt.js +339 -0
- package/lib/core/ptc.d.ts +66 -0
- package/lib/core/ptc.js +70 -0
- package/lib/core/remote/frames.d.ts +91 -0
- package/lib/core/remote/frames.js +174 -0
- package/lib/core/remote/notify.d.ts +54 -0
- package/lib/core/remote/notify.js +77 -0
- package/lib/core/remote/owner.d.ts +32 -0
- package/lib/core/remote/owner.js +75 -0
- package/lib/core/remote/pairing.d.ts +104 -0
- package/lib/core/remote/pairing.js +261 -0
- package/lib/core/remote/push.d.ts +80 -0
- package/lib/core/remote/push.js +222 -0
- package/lib/core/remote/store.d.ts +18 -0
- package/lib/core/remote/store.js +59 -0
- package/lib/core/remote/tickets.d.ts +20 -0
- package/lib/core/remote/tickets.js +49 -0
- package/lib/core/remote/uploads.d.ts +63 -0
- package/lib/core/remote/uploads.js +161 -0
- package/lib/core/request-attribution.d.ts +26 -0
- package/lib/core/request-attribution.js +86 -0
- package/lib/core/request-invariant.d.ts +61 -0
- package/lib/core/request-invariant.js +199 -0
- package/lib/core/sandbox/backends.d.ts +64 -0
- package/lib/core/sandbox/backends.js +194 -0
- package/lib/core/sandbox/execpolicy.d.ts +93 -0
- package/lib/core/sandbox/execpolicy.js +452 -0
- package/lib/core/sandbox/net-proxy.d.ts +31 -0
- package/lib/core/sandbox/net-proxy.js +162 -0
- package/lib/core/sandbox/policy.d.ts +211 -0
- package/lib/core/sandbox/policy.js +559 -0
- package/lib/core/sandbox/win/abi.d.ts +161 -0
- package/lib/core/sandbox/win/abi.js +169 -0
- package/lib/core/sandbox/win/account.d.ts +71 -0
- package/lib/core/sandbox/win/account.js +206 -0
- package/lib/core/sandbox/win/acl.d.ts +54 -0
- package/lib/core/sandbox/win/acl.js +339 -0
- package/lib/core/sandbox/win/backend.d.ts +61 -0
- package/lib/core/sandbox/win/backend.js +249 -0
- package/lib/core/sandbox/win/doctor.d.ts +24 -0
- package/lib/core/sandbox/win/doctor.js +272 -0
- package/lib/core/sandbox/win/ffi.d.ts +107 -0
- package/lib/core/sandbox/win/ffi.js +166 -0
- package/lib/core/sandbox/win/net-abi.d.ts +154 -0
- package/lib/core/sandbox/win/net-abi.js +316 -0
- package/lib/core/sandbox/win/runner-entry.d.ts +35 -0
- package/lib/core/sandbox/win/runner-entry.js +391 -0
- package/lib/core/sandbox/win/setup.d.ts +60 -0
- package/lib/core/sandbox/win/setup.js +986 -0
- package/lib/core/sandbox/win/token.d.ts +35 -0
- package/lib/core/sandbox/win/token.js +238 -0
- package/lib/core/sandbox/win/wfp.d.ts +41 -0
- package/lib/core/sandbox/win/wfp.js +200 -0
- package/lib/core/sandbox/win/workspace-sid.d.ts +9 -0
- package/lib/core/sandbox/win/workspace-sid.js +45 -0
- package/lib/core/schedule/rule.d.ts +184 -0
- package/lib/core/schedule/rule.js +745 -0
- package/lib/core/schedule/runner.d.ts +185 -0
- package/lib/core/schedule/runner.js +678 -0
- package/lib/core/schedule/store.d.ts +182 -0
- package/lib/core/schedule/store.js +455 -0
- package/lib/core/secrets.d.ts +41 -0
- package/lib/core/secrets.js +150 -0
- package/lib/core/session-export.d.ts +18 -0
- package/lib/core/session-export.js +73 -0
- package/lib/core/session-index.d.ts +159 -0
- package/lib/core/session-index.js +683 -0
- package/lib/core/session-meta.d.ts +41 -0
- package/lib/core/session-meta.js +97 -0
- package/lib/core/session.d.ts +356 -0
- package/lib/core/session.js +998 -0
- package/lib/core/skills.d.ts +60 -0
- package/lib/core/skills.js +171 -0
- package/lib/core/spill.d.ts +159 -0
- package/lib/core/spill.js +329 -0
- package/lib/core/surface-registry.d.ts +45 -0
- package/lib/core/surface-registry.js +67 -0
- package/lib/core/team-board.d.ts +95 -0
- package/lib/core/team-board.js +316 -0
- package/lib/core/throughput.d.ts +46 -0
- package/lib/core/throughput.js +40 -0
- package/lib/core/todo-reminder.d.ts +44 -0
- package/lib/core/todo-reminder.js +55 -0
- package/lib/core/todo.d.ts +81 -0
- package/lib/core/todo.js +222 -0
- package/lib/core/token-estimate.d.ts +55 -0
- package/lib/core/token-estimate.js +82 -0
- package/lib/core/tool-guards.d.ts +103 -0
- package/lib/core/tool-guards.js +77 -0
- package/lib/core/tool-search.d.ts +152 -0
- package/lib/core/tool-search.js +311 -0
- package/lib/core/tools/bash.d.ts +281 -0
- package/lib/core/tools/bash.js +871 -0
- package/lib/core/tools/command-runner.d.ts +84 -0
- package/lib/core/tools/command-runner.js +68 -0
- package/lib/core/tools/fs-tools.d.ts +23 -0
- package/lib/core/tools/fs-tools.js +247 -0
- package/lib/core/tools/index.d.ts +8 -0
- package/lib/core/tools/index.js +4 -0
- package/lib/core/tools/sandbox-args.d.ts +51 -0
- package/lib/core/tools/sandbox-args.js +90 -0
- package/lib/core/tools/search-tools.d.ts +3 -0
- package/lib/core/tools/search-tools.js +153 -0
- package/lib/core/tools.d.ts +96 -0
- package/lib/core/tools.js +53 -0
- package/lib/core/ui-boot-source.d.ts +71 -0
- package/lib/core/ui-boot-source.js +121 -0
- package/lib/core/ui-bundles.d.ts +249 -0
- package/lib/core/ui-bundles.js +830 -0
- package/lib/core/ui-combo.d.ts +49 -0
- package/lib/core/ui-combo.js +55 -0
- package/lib/core/ui-events.d.ts +81 -0
- package/lib/core/ui-events.js +364 -0
- package/lib/core/ui-hmr.d.ts +36 -0
- package/lib/core/ui-hmr.js +128 -0
- package/lib/core/ui-methods.d.ts +69 -0
- package/lib/core/ui-methods.js +341 -0
- package/lib/core/ui-route.d.ts +69 -0
- package/lib/core/ui-route.js +122 -0
- package/lib/core/ui-server.d.ts +75 -0
- package/lib/core/ui-server.js +369 -0
- package/lib/core/ui-trust.d.ts +47 -0
- package/lib/core/ui-trust.js +164 -0
- package/lib/core/untrusted.d.ts +30 -0
- package/lib/core/untrusted.js +48 -0
- package/lib/core/update-check.d.ts +81 -0
- package/lib/core/update-check.js +177 -0
- package/lib/core/usage-log.d.ts +82 -0
- package/lib/core/usage-log.js +306 -0
- package/lib/core/version.d.ts +1 -0
- package/lib/core/version.js +37 -0
- package/lib/core/web-http.d.ts +57 -0
- package/lib/core/web-http.js +137 -0
- package/lib/core/web-static.d.ts +31 -0
- package/lib/core/web-static.js +75 -0
- package/lib/headless.d.ts +1 -0
- package/lib/headless.js +31 -0
- package/lib/host/kernel.d.ts +33 -0
- package/lib/host/kernel.js +451 -0
- package/lib/index.d.ts +41 -0
- package/lib/index.js +35 -0
- package/lib/plugins/agent.d.ts +2 -0
- package/lib/plugins/agent.js +274 -0
- package/lib/plugins/approval-floor.d.ts +2 -0
- package/lib/plugins/approval-floor.js +223 -0
- package/lib/plugins/approval.d.ts +16 -0
- package/lib/plugins/approval.js +674 -0
- package/lib/plugins/ask.d.ts +2 -0
- package/lib/plugins/ask.js +245 -0
- package/lib/plugins/browser.d.ts +68 -0
- package/lib/plugins/browser.js +1341 -0
- package/lib/plugins/commands.d.ts +23 -0
- package/lib/plugins/commands.js +498 -0
- package/lib/plugins/compact.d.ts +21 -0
- package/lib/plugins/compact.js +274 -0
- package/lib/plugins/computer-use.d.ts +47 -0
- package/lib/plugins/computer-use.js +539 -0
- package/lib/plugins/desktop-dock.d.ts +2 -0
- package/lib/plugins/desktop-dock.js +626 -0
- package/lib/plugins/dock-browser.d.ts +34 -0
- package/lib/plugins/dock-browser.js +765 -0
- package/lib/plugins/dsh-compat.d.ts +25 -0
- package/lib/plugins/dsh-compat.js +37 -0
- package/lib/plugins/file-review.d.ts +108 -0
- package/lib/plugins/file-review.js +393 -0
- package/lib/plugins/git.d.ts +26 -0
- package/lib/plugins/git.js +132 -0
- package/lib/plugins/goal.d.ts +20 -0
- package/lib/plugins/goal.js +245 -0
- package/lib/plugins/guards.d.ts +14 -0
- package/lib/plugins/guards.js +18 -0
- package/lib/plugins/hooks.d.ts +19 -0
- package/lib/plugins/hooks.js +583 -0
- package/lib/plugins/host-stdio.d.ts +88 -0
- package/lib/plugins/host-stdio.js +317 -0
- package/lib/plugins/image-diet.d.ts +17 -0
- package/lib/plugins/image-diet.js +85 -0
- package/lib/plugins/lifecycle-hooks.d.ts +26 -0
- package/lib/plugins/lifecycle-hooks.js +338 -0
- package/lib/plugins/llm.d.ts +13 -0
- package/lib/plugins/llm.js +215 -0
- package/lib/plugins/lsp.d.ts +54 -0
- package/lib/plugins/lsp.js +608 -0
- package/lib/plugins/mcp.d.ts +16 -0
- package/lib/plugins/mcp.js +673 -0
- package/lib/plugins/memory.d.ts +17 -0
- package/lib/plugins/memory.js +858 -0
- package/lib/plugins/microcompact.d.ts +18 -0
- package/lib/plugins/microcompact.js +119 -0
- package/lib/plugins/mode.d.ts +18 -0
- package/lib/plugins/mode.js +115 -0
- package/lib/plugins/permission-presets.d.ts +18 -0
- package/lib/plugins/permission-presets.js +135 -0
- package/lib/plugins/plan.d.ts +2 -0
- package/lib/plugins/plan.js +192 -0
- package/lib/plugins/plugin-manager.d.ts +2 -0
- package/lib/plugins/plugin-manager.js +165 -0
- package/lib/plugins/presets.d.ts +2 -0
- package/lib/plugins/presets.js +182 -0
- package/lib/plugins/prompt.d.ts +2 -0
- package/lib/plugins/prompt.js +264 -0
- package/lib/plugins/ptc.d.ts +2 -0
- package/lib/plugins/ptc.js +272 -0
- package/lib/plugins/remote/http.d.ts +11 -0
- package/lib/plugins/remote/http.js +11 -0
- package/lib/plugins/remote/routes.d.ts +24 -0
- package/lib/plugins/remote/routes.js +384 -0
- package/lib/plugins/remote/types.d.ts +135 -0
- package/lib/plugins/remote/types.js +87 -0
- package/lib/plugins/remote.d.ts +17 -0
- package/lib/plugins/remote.js +1028 -0
- package/lib/plugins/runtime-api.d.ts +16 -0
- package/lib/plugins/runtime-api.js +99 -0
- package/lib/plugins/runtime.d.ts +10 -0
- package/lib/plugins/runtime.js +451 -0
- package/lib/plugins/sandbox.d.ts +2 -0
- package/lib/plugins/sandbox.js +761 -0
- package/lib/plugins/schedule.d.ts +26 -0
- package/lib/plugins/schedule.js +538 -0
- package/lib/plugins/self-improve.d.ts +61 -0
- package/lib/plugins/self-improve.js +953 -0
- package/lib/plugins/session-search.d.ts +16 -0
- package/lib/plugins/session-search.js +308 -0
- package/lib/plugins/session-title.d.ts +19 -0
- package/lib/plugins/session-title.js +109 -0
- package/lib/plugins/session.d.ts +7 -0
- package/lib/plugins/session.js +296 -0
- package/lib/plugins/settings.d.ts +3 -0
- package/lib/plugins/settings.js +705 -0
- package/lib/plugins/skills.d.ts +2 -0
- package/lib/plugins/skills.js +360 -0
- package/lib/plugins/spill.d.ts +16 -0
- package/lib/plugins/spill.js +200 -0
- package/lib/plugins/subagent.d.ts +2 -0
- package/lib/plugins/subagent.js +862 -0
- package/lib/plugins/surfaces.d.ts +11 -0
- package/lib/plugins/surfaces.js +20 -0
- package/lib/plugins/team.d.ts +16 -0
- package/lib/plugins/team.js +149 -0
- package/lib/plugins/todo.d.ts +19 -0
- package/lib/plugins/todo.js +188 -0
- package/lib/plugins/tool-search.d.ts +2 -0
- package/lib/plugins/tool-search.js +425 -0
- package/lib/plugins/tools-default.d.ts +12 -0
- package/lib/plugins/tools-default.js +275 -0
- package/lib/plugins/tools.d.ts +16 -0
- package/lib/plugins/tools.js +62 -0
- package/lib/plugins/transcript.d.ts +15 -0
- package/lib/plugins/transcript.js +311 -0
- package/lib/plugins/tui.d.ts +2 -0
- package/lib/plugins/tui.js +98 -0
- package/lib/plugins/waiting.d.ts +12 -0
- package/lib/plugins/waiting.js +34 -0
- package/lib/plugins/web-search.d.ts +14 -0
- package/lib/plugins/web-search.js +263 -0
- package/lib/plugins/webserver.d.ts +48 -0
- package/lib/plugins/webserver.js +228 -0
- package/lib/remote/assets/app-DAcUCOEn.js +14 -0
- package/lib/remote/assets/icon-192.png +0 -0
- package/lib/remote/assets/icon-512.png +0 -0
- package/lib/remote/assets/index.html +34 -0
- package/lib/remote/assets/manifest.json +27 -0
- package/lib/remote/assets/style-DIB6729x.css +1 -0
- package/lib/remote/assets/sw.js +66 -0
- package/lib/services/types.d.ts +1228 -0
- package/lib/services/types.js +1 -0
- package/lib/tools/config-cli.d.ts +1 -0
- package/lib/tools/config-cli.js +89 -0
- package/lib/ui/arrival.d.ts +72 -0
- package/lib/ui/arrival.js +105 -0
- package/lib/ui/assets/app-B70nVIKd.js +69 -0
- package/lib/ui/assets/chunk-2UxHyX5q.js +1 -0
- package/lib/ui/assets/chunk-B1dDrJ26.js +1 -0
- package/lib/ui/assets/chunk-B6aJPvgy.js +1 -0
- package/lib/ui/assets/chunk-BEwlwnbL.js +1 -0
- package/lib/ui/assets/chunk-BGcgwlCI.js +12 -0
- package/lib/ui/assets/chunk-BIGW1oBm.js +1 -0
- package/lib/ui/assets/chunk-BPQ3VLAy.js +1 -0
- package/lib/ui/assets/chunk-BRH0KZbk.js +141 -0
- package/lib/ui/assets/chunk-BX6H_ySx.js +1 -0
- package/lib/ui/assets/chunk-B_P3UbPa.js +1 -0
- package/lib/ui/assets/chunk-B_TYUkTI.js +1 -0
- package/lib/ui/assets/chunk-B_vNuMnf.js +1 -0
- package/lib/ui/assets/chunk-BajyYBss.js +10 -0
- package/lib/ui/assets/chunk-BdnUsdx6.js +1 -0
- package/lib/ui/assets/chunk-Buea-lGh.js +1 -0
- package/lib/ui/assets/chunk-C0PvZCCE.js +1 -0
- package/lib/ui/assets/chunk-C0m74zRD.js +1 -0
- package/lib/ui/assets/chunk-C27-OAKa.js +1 -0
- package/lib/ui/assets/chunk-C2oV4EkX.js +1 -0
- package/lib/ui/assets/chunk-C7zT0LnQ.js +1 -0
- package/lib/ui/assets/chunk-C9GSunVT.js +1 -0
- package/lib/ui/assets/chunk-C9tS-k6U.js +1 -0
- package/lib/ui/assets/chunk-CHLpvVh8.js +1 -0
- package/lib/ui/assets/chunk-CLxacb5B.js +1 -0
- package/lib/ui/assets/chunk-COt5Ahok.js +1 -0
- package/lib/ui/assets/chunk-CPTIWCL2.js +1 -0
- package/lib/ui/assets/chunk-CQLl-L-p.js +1 -0
- package/lib/ui/assets/chunk-CUWRgxuq.js +55 -0
- package/lib/ui/assets/chunk-CWanVSXC.js +1 -0
- package/lib/ui/assets/chunk-Cf5RLm7j.js +1 -0
- package/lib/ui/assets/chunk-CickPsom.js +1 -0
- package/lib/ui/assets/chunk-Cj5Yp3dK.js +1 -0
- package/lib/ui/assets/chunk-Cmh6b_Ma.js +1 -0
- package/lib/ui/assets/chunk-Cp-IABpG.js +1 -0
- package/lib/ui/assets/chunk-CqE71os6.js +1 -0
- package/lib/ui/assets/chunk-CtKP3W-j.js +1 -0
- package/lib/ui/assets/chunk-Cvjx9yec.js +1 -0
- package/lib/ui/assets/chunk-CxGP3dtY.js +1 -0
- package/lib/ui/assets/chunk-CylS5w8V.js +1 -0
- package/lib/ui/assets/chunk-D38fbIBN.js +1 -0
- package/lib/ui/assets/chunk-D97Zzqfu.js +1 -0
- package/lib/ui/assets/chunk-DAi9KRSo.js +1 -0
- package/lib/ui/assets/chunk-DHK4yRfg.js +1 -0
- package/lib/ui/assets/chunk-DJeabLx-.js +1 -0
- package/lib/ui/assets/chunk-DNRxmY5a.js +1 -0
- package/lib/ui/assets/chunk-DNSN1z5r.js +1 -0
- package/lib/ui/assets/chunk-DNasK_ZG.js +1 -0
- package/lib/ui/assets/chunk-DPvrY3IQ.js +1 -0
- package/lib/ui/assets/chunk-DXmwc3jG.js +1 -0
- package/lib/ui/assets/chunk-Dd0kTxKP.js +1 -0
- package/lib/ui/assets/chunk-De0Btta0.js +1 -0
- package/lib/ui/assets/chunk-Des-eS-w.js +1 -0
- package/lib/ui/assets/chunk-Df6bDoY_.js +1 -0
- package/lib/ui/assets/chunk-DijEV5ha.js +1 -0
- package/lib/ui/assets/chunk-DkvoVjww.js +1 -0
- package/lib/ui/assets/chunk-DlC-OlHO.js +1 -0
- package/lib/ui/assets/chunk-DnzrXTVv.js +1 -0
- package/lib/ui/assets/chunk-Dualf0xi.js +1 -0
- package/lib/ui/assets/chunk-EXT84bkm.js +1 -0
- package/lib/ui/assets/chunk-GwR3hkPK.js +1 -0
- package/lib/ui/assets/chunk-P80f7IUj.js +1 -0
- package/lib/ui/assets/chunk-VOosw3JB.js +1 -0
- package/lib/ui/assets/chunk-YQ4lDkt_.js +140 -0
- package/lib/ui/assets/chunk-Yzrsuije.js +1 -0
- package/lib/ui/assets/chunk-Z72CF80r.js +1 -0
- package/lib/ui/assets/chunk-g9-lgVsj.js +1 -0
- package/lib/ui/assets/chunk-vGWfd6FD.js +1 -0
- package/lib/ui/assets/chunk-wDzz0qaB.js +1 -0
- package/lib/ui/assets/chunk-ySF7HWmS.js +1 -0
- package/lib/ui/assets/icon.png +0 -0
- package/lib/ui/assets/index.html +14 -0
- package/lib/ui/assets/pdf.worker.min-CjEcRF4W.mjs +28 -0
- package/lib/ui/assets/style-Bq01xH_b.css +1 -0
- package/lib/ui/frames.d.ts +67 -0
- package/lib/ui/frames.js +146 -0
- package/lib/ui/index.d.ts +59 -0
- package/lib/ui/index.js +50 -0
- package/lib/ui/manifest.d.ts +172 -0
- package/lib/ui/manifest.js +158 -0
- package/lib/ui/plugin.d.ts +161 -0
- package/lib/ui/plugin.js +7 -0
- package/lib/ui/plugins/browser/client.js +290 -0
- package/lib/ui/plugins/browser/icon.png +0 -0
- package/lib/ui/plugins/composer/client.js +1843 -0
- package/lib/ui/plugins/composer/icon.png +0 -0
- package/lib/ui/plugins/files/client.js +646 -0
- package/lib/ui/plugins/files/icon.png +0 -0
- package/lib/ui/plugins/manifest.json +107 -0
- package/lib/ui/plugins/plugins/client.js +682 -0
- package/lib/ui/plugins/plugins/icon.png +0 -0
- package/lib/ui/plugins/preview/client.js +197 -0
- package/lib/ui/plugins/preview/icon.png +0 -0
- package/lib/ui/plugins/prompt/client.js +653 -0
- package/lib/ui/plugins/prompt/icon.png +0 -0
- package/lib/ui/plugins/sessions/client.js +1577 -0
- package/lib/ui/plugins/sessions/icon.png +0 -0
- package/lib/ui/plugins/settings/client.js +5470 -0
- package/lib/ui/plugins/settings/icon.png +0 -0
- package/lib/ui/plugins/skills/client.js +485 -0
- package/lib/ui/plugins/skills/icon.png +0 -0
- package/lib/ui/plugins/status/client.js +1420 -0
- package/lib/ui/plugins/status/icon.png +0 -0
- package/lib/ui/plugins/statusbar/client.js +504 -0
- package/lib/ui/plugins/statusbar/icon.png +0 -0
- package/lib/ui/plugins/tasks/client.js +52 -0
- package/lib/ui/plugins/tasks/icon.png +0 -0
- package/lib/ui/plugins/team/client.js +527 -0
- package/lib/ui/plugins/team/icon.png +0 -0
- package/lib/ui/plugins/terminal/client.js +232 -0
- package/lib/ui/plugins/terminal/icon.png +0 -0
- package/lib/ui/plugins/trace/client.js +1376 -0
- package/lib/ui/plugins/trace/icon.png +0 -0
- package/lib/ui/plugins/transcript/client.js +2661 -0
- package/lib/ui/plugins/transcript/icon.png +0 -0
- package/lib/ui/scoped-slots.d.ts +20 -0
- package/lib/ui/scoped-slots.js +21 -0
- package/lib/ui/sdk/@dsc/ui/index.d.ts +242 -0
- package/lib/ui/sdk/@dsc/ui/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-core/contract.d.ts +1973 -0
- package/lib/ui/sdk/@dsc/ui-core/core/diff-text.d.ts +74 -0
- package/lib/ui/sdk/@dsc/ui-core/core/dock-browser.d.ts +137 -0
- package/lib/ui/sdk/@dsc/ui-core/core/dock-ops.d.ts +59 -0
- package/lib/ui/sdk/@dsc/ui-core/core/model-caps.d.ts +83 -0
- package/lib/ui/sdk/@dsc/ui-core/core/native-bridge.d.ts +135 -0
- package/lib/ui/sdk/@dsc/ui-core/core/token-estimate.d.ts +55 -0
- package/lib/ui/sdk/@dsc/ui-core/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/arrival.d.ts +72 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/frames.d.ts +67 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/index.d.ts +59 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/manifest.d.ts +172 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/plugin.d.ts +161 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/scoped-slots.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/services-react.d.ts +27 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/services.d.ts +63 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/slots-react.d.ts +28 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/slots.d.ts +481 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/store.d.ts +89 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-model.d.ts +238 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-state.d.ts +163 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/index.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-layout/app.d.ts +74 -0
- package/lib/ui/sdk/@dsc/ui-layout/appearance.d.ts +70 -0
- package/lib/ui/sdk/@dsc/ui-layout/host-channel.d.ts +112 -0
- package/lib/ui/sdk/@dsc/ui-layout/index.d.ts +34 -0
- package/lib/ui/sdk/@dsc/ui-layout/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-layout/page-state.d.ts +14 -0
- package/lib/ui/sdk/@dsc/ui-layout/review-pane.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-layout/runtime-context.d.ts +44 -0
- package/lib/ui/sdk/@dsc/ui-layout/thread-view.d.ts +28 -0
- package/lib/ui/sdk/@dsc/ui-layout/update-button.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-primitives/code-file-icon-artwork.d.ts +53 -0
- package/lib/ui/sdk/@dsc/ui-primitives/code-view.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-primitives/compat.d.ts +27 -0
- package/lib/ui/sdk/@dsc/ui-primitives/completion-sound.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-primitives/confirm.d.ts +33 -0
- package/lib/ui/sdk/@dsc/ui-primitives/css.d.ts +47 -0
- package/lib/ui/sdk/@dsc/ui-primitives/diff-rows.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-icons.d.ts +38 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-type-classify.d.ts +66 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-type-icon.d.ts +57 -0
- package/lib/ui/sdk/@dsc/ui-primitives/highlight.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-primitives/hover-delay.d.ts +17 -0
- package/lib/ui/sdk/@dsc/ui-primitives/icons.d.ts +109 -0
- package/lib/ui/sdk/@dsc/ui-primitives/index.d.ts +55 -0
- package/lib/ui/sdk/@dsc/ui-primitives/lang-table.d.ts +10 -0
- package/lib/ui/sdk/@dsc/ui-primitives/markdown.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-primitives/native.d.ts +41 -0
- package/lib/ui/sdk/@dsc/ui-primitives/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-primitives/panels.d.ts +86 -0
- package/lib/ui/sdk/@dsc/ui-primitives/paths.d.ts +11 -0
- package/lib/ui/sdk/@dsc/ui-primitives/pdf-view.d.ts +13 -0
- package/lib/ui/sdk/@dsc/ui-primitives/plugin-text.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-primitives/select.d.ts +35 -0
- package/lib/ui/sdk/@dsc/ui-primitives/table-view.d.ts +23 -0
- package/lib/ui/sdk/@dsc/ui-primitives/thread-resizer.d.ts +22 -0
- package/lib/ui/sdk/@dsc/ui-primitives/time.d.ts +33 -0
- package/lib/ui/sdk/@dsc/ui-primitives/toast.d.ts +16 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tokens.d.ts +14 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tool-args.d.ts +49 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tool-summary.d.ts +64 -0
- package/lib/ui/sdk/@dsc/ui-renderer/boot.d.ts +121 -0
- package/lib/ui/sdk/@dsc/ui-renderer/hmr.d.ts +43 -0
- package/lib/ui/sdk/@dsc/ui-renderer/index.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-renderer/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-slots/index.d.ts +19 -0
- package/lib/ui/sdk/@dsc/ui-slots/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-slots/slots-react.d.ts +48 -0
- package/lib/ui/sdk/@dsc/ui-slots/slots.d.ts +102 -0
- package/lib/ui/services-react.d.ts +27 -0
- package/lib/ui/services-react.js +32 -0
- package/lib/ui/services.d.ts +63 -0
- package/lib/ui/services.js +121 -0
- package/lib/ui/slots-ink.d.ts +26 -0
- package/lib/ui/slots-ink.js +78 -0
- package/lib/ui/slots-react.d.ts +28 -0
- package/lib/ui/slots-react.js +88 -0
- package/lib/ui/slots.d.ts +481 -0
- package/lib/ui/slots.js +550 -0
- package/lib/ui/store.d.ts +89 -0
- package/lib/ui/store.js +62 -0
- package/lib/ui/tui-plugin-api.d.ts +23 -0
- package/lib/ui/tui-plugin-api.js +23 -0
- package/lib/ui/tui-plugins.d.ts +47 -0
- package/lib/ui/tui-plugins.js +220 -0
- package/package.json +58 -6
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { HOOK_TIMEOUT_MAX, HOOK_TIMEOUT_MIN } from '../core/hooks.js';
|
|
2
|
+
import { commandAllowed, denyReasonFor, judgeBlockedByAllowlist, judgeLifecycleRun, lifecycleReport, readLifecycleDoc, resolveLifecycleConfig, runLifecycleCommand, subjectHits, wrapHookOutput, } from '../core/lifecycle-hooks.js';
|
|
3
|
+
import { contentText } from '../core/llm.js';
|
|
4
|
+
import { writePluginConfig } from '../core/plugin-registry.js';
|
|
5
|
+
/** 插件在条目树里的键,也是设置分区 id。 */
|
|
6
|
+
const CONFIG_KEY = 'lifecycle-hooks';
|
|
7
|
+
/** 事件档位在界面上的说法。 */
|
|
8
|
+
const TIER_LABELS = { wired: '已接通', partial: '部分接通', unwired: '未接通' };
|
|
9
|
+
function errText(error) {
|
|
10
|
+
return error instanceof Error ? error.message : String(error);
|
|
11
|
+
}
|
|
12
|
+
export const lifecycleHooksPlugin = {
|
|
13
|
+
name: 'lifecycle-hooks',
|
|
14
|
+
inject: ['session', 'llm', 'approval', 'guards', 'prompt', 'settings', 'commands'],
|
|
15
|
+
apply(ctx, passed) {
|
|
16
|
+
/** 每次都现读:设置里改完不必重启宿主。 */
|
|
17
|
+
const config = () => resolveLifecycleConfig(passed);
|
|
18
|
+
const cwdOf = () => ctx.session.current().meta.cwd;
|
|
19
|
+
/** 后台跑的钩子统一挂这个信号:插件卸载时一起掐掉,不留悬挂的子进程。 */
|
|
20
|
+
const lifetime = new AbortController();
|
|
21
|
+
/** 攒着等下一次请求的围栏文本(只能「留话」的那几类事件都往这儿放)。 */
|
|
22
|
+
let pending = [];
|
|
23
|
+
/** 上一次见过的用户消息原文:变了才算新提交,同一轮里问一次不重复触发。 */
|
|
24
|
+
let lastPrompt = '';
|
|
25
|
+
/** 同一句提示只说一次,不然每次工具调用都刷屏。 */
|
|
26
|
+
const announced = new Set();
|
|
27
|
+
const notify = (key, text) => {
|
|
28
|
+
if (announced.has(key))
|
|
29
|
+
return;
|
|
30
|
+
announced.add(key);
|
|
31
|
+
ctx.emit('dsc/notice', text);
|
|
32
|
+
};
|
|
33
|
+
/** 载荷的公共字段,字段名照 codex。 */
|
|
34
|
+
const basePayload = (event, cwd) => ({
|
|
35
|
+
session_id: ctx.session.current().meta.id,
|
|
36
|
+
// dsc 的 Session 上取不到自己的 jsonl 路径,这一项恒为 null(钩子脚本读它是 null,不是空串)
|
|
37
|
+
transcript_path: null,
|
|
38
|
+
cwd,
|
|
39
|
+
hook_event_name: event,
|
|
40
|
+
model: ctx.llm.model,
|
|
41
|
+
permission_mode: ctx.approval.policy,
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* 跑一条事件上全部命中的钩子,按配置里的顺序依次跑完(不并行:这些命令要读同一份现场)。
|
|
45
|
+
* 只执行与裁决,不碰上下文——调用方决定结论怎么用。
|
|
46
|
+
*/
|
|
47
|
+
const runHooks = async (event, subject, extra, cwd, signal) => {
|
|
48
|
+
const cfg = config();
|
|
49
|
+
if (!cfg.enabled)
|
|
50
|
+
return [];
|
|
51
|
+
const judgements = [];
|
|
52
|
+
for (const hook of readLifecycleDoc(cfg.configPath).hooks) {
|
|
53
|
+
if (!hook.enabled || hook.event !== event)
|
|
54
|
+
continue;
|
|
55
|
+
if (!subjectHits(event, hook.matcher, subject))
|
|
56
|
+
continue;
|
|
57
|
+
if (!commandAllowed(hook.command, cfg.commandAllowlist)) {
|
|
58
|
+
const blocked = judgeBlockedByAllowlist(hook, cfg);
|
|
59
|
+
notify(`allowlist:${hook.id}`, `生命周期钩子(${event})有一条没生效:${blocked.problem}`);
|
|
60
|
+
judgements.push(blocked);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const run = await runLifecycleCommand(hook.command, hook.timeoutMs > 0 ? hook.timeoutMs : cfg.timeoutMs, { ...basePayload(event, cwd), ...extra }, cwd, signal);
|
|
64
|
+
judgements.push(judgeLifecycleRun(run, hook, cfg));
|
|
65
|
+
}
|
|
66
|
+
return judgements;
|
|
67
|
+
};
|
|
68
|
+
/** 只能「留话」的事件:把裁决里的话与毛病收下(话等下一次请求带出去)。 */
|
|
69
|
+
const absorb = (event, judgements) => {
|
|
70
|
+
for (const judgement of judgements) {
|
|
71
|
+
if (judgement.problem !== '')
|
|
72
|
+
notify(`${event}:${judgement.source}:${judgement.problem}`, `生命周期钩子(${event})没跑好:${judgement.problem}`);
|
|
73
|
+
if (judgement.message !== '')
|
|
74
|
+
pending.push(wrapHookOutput(event, judgement.message));
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
/** 后台跑一条观察型事件,不挡当前这一步。 */
|
|
78
|
+
const fire = (event, subject, extra, cwd = cwdOf()) => {
|
|
79
|
+
void runHooks(event, subject, extra, cwd, lifetime.signal)
|
|
80
|
+
.then((judgements) => absorb(event, judgements))
|
|
81
|
+
.catch((error) => {
|
|
82
|
+
// runHooks 自己把所有执行失败都摊在返回值里,走到这儿的是读配置之类的意外:说一句,别变成未处理的拒绝
|
|
83
|
+
notify(`fire:${event}`, `生命周期钩子(${event})执行出错:${errText(error)}`);
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
/** 最后一条 assistant 消息的正文(Stop 事件要带上它,钩子才知道刚说完什么)。 */
|
|
87
|
+
const lastAssistantText = () => {
|
|
88
|
+
const messages = ctx.session.current().messages;
|
|
89
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
90
|
+
const message = messages[index];
|
|
91
|
+
if (message.role === 'assistant')
|
|
92
|
+
return contentText(message.content);
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
};
|
|
96
|
+
// ── PreToolUse:守卫 order 25(协作模式 10 之后、审批 30 之前) ──────────────
|
|
97
|
+
const guard = {
|
|
98
|
+
id: 'lifecycle-hooks',
|
|
99
|
+
order: 25,
|
|
100
|
+
async decide(input) {
|
|
101
|
+
if (!config().enabled)
|
|
102
|
+
return { action: 'defer' };
|
|
103
|
+
const judgements = await runHooks('PreToolUse', input.toolName, { tool_name: input.toolName, tool_input: input.args }, input.cwd, input.signal);
|
|
104
|
+
for (const judgement of judgements) {
|
|
105
|
+
if (judgement.problem !== '')
|
|
106
|
+
notify(`PreToolUse:${judgement.source}:${judgement.problem}`, `生命周期钩子(PreToolUse)没跑好:${judgement.problem}`);
|
|
107
|
+
}
|
|
108
|
+
const blocker = judgements.find((judgement) => judgement.action === 'block');
|
|
109
|
+
if (blocker !== undefined)
|
|
110
|
+
return { action: 'deny', reason: denyReasonFor('PreToolUse', blocker) };
|
|
111
|
+
const asker = judgements.find((judgement) => judgement.action === 'ask');
|
|
112
|
+
if (asker !== undefined) {
|
|
113
|
+
// 这个位置在审批环节之前,没有卡可弹;钩子要人确认就先按拒绝回话,让模型去问用户
|
|
114
|
+
return {
|
|
115
|
+
action: 'deny',
|
|
116
|
+
reason: denyReasonFor('PreToolUse', {
|
|
117
|
+
...asker,
|
|
118
|
+
message: `钩子要求有人确认,但工具动手之前这个位置没有审批卡可弹,先按拒绝处理。${asker.message}`,
|
|
119
|
+
}),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
for (const judgement of judgements) {
|
|
123
|
+
if (judgement.action === 'note' && judgement.message !== '')
|
|
124
|
+
pending.push(wrapHookOutput('PreToolUse', judgement.message));
|
|
125
|
+
}
|
|
126
|
+
return { action: 'defer' };
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
// ── PostToolUse:观察者 order 45(同步点,钩子挂后台,话进下一次请求) ───────
|
|
130
|
+
const observer = {
|
|
131
|
+
id: 'lifecycle-hooks',
|
|
132
|
+
order: 45,
|
|
133
|
+
observe(toolName, text) {
|
|
134
|
+
fire('PostToolUse', toolName, { tool_name: toolName, tool_response: text });
|
|
135
|
+
return text;
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
// ── 请求组装:UserPromptSubmit 认新消息 + 把攒下的话补在末尾 ─────────────────
|
|
139
|
+
// 钩子产出不在会话日志里,塞进请求的同时必须落一条 note(Model-visible ⟺ logged):
|
|
140
|
+
// 只投给主会话——队友的请求不走投影链,不会错拿主会话的 pending。
|
|
141
|
+
const offProjection = ctx.prompt.registerProjection('user-prompt-submit', (messages) => {
|
|
142
|
+
submitIfNewPrompt(messages);
|
|
143
|
+
if (pending.length === 0)
|
|
144
|
+
return messages;
|
|
145
|
+
const blocks = pending;
|
|
146
|
+
pending = [];
|
|
147
|
+
// 补在末尾、user 角色(2026-10-03):system 段会被 fold-system 并进头部、改写前缀缓存;
|
|
148
|
+
// user 只往历史尾巴追加。内容自带 <external_content source="hook:…"> 围栏,出处已标明。
|
|
149
|
+
ctx.session.current().appendNote('lifecycle-hooks', blocks.join('\n\n'));
|
|
150
|
+
return [...messages, { role: 'user', content: blocks.join('\n\n') }];
|
|
151
|
+
});
|
|
152
|
+
/** 认出这次请求里新的那条用户消息,跑一遍 UserPromptSubmit(只能把话留到下一次请求)。 */
|
|
153
|
+
function submitIfNewPrompt(messages) {
|
|
154
|
+
let prompt = '';
|
|
155
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
156
|
+
const message = messages[index];
|
|
157
|
+
if (message.role === 'user') {
|
|
158
|
+
prompt = contentText(message.content);
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (prompt === '' || prompt === lastPrompt)
|
|
163
|
+
return;
|
|
164
|
+
lastPrompt = prompt;
|
|
165
|
+
fire('UserPromptSubmit', '', { prompt });
|
|
166
|
+
}
|
|
167
|
+
// ── 事件监听 ─────────────────────────────────────────────────────────────
|
|
168
|
+
const offs = [ctx.guards.register(guard), ctx.guards.registerObserver(observer), offProjection];
|
|
169
|
+
offs.push(ctx.on('dsc/session-open', ({ session, filePath }) => {
|
|
170
|
+
announced.clear();
|
|
171
|
+
lastPrompt = '';
|
|
172
|
+
// codex 的 SessionStart matcher 比的来源:新开是 startup,接着老的跑是 resume
|
|
173
|
+
const source = filePath === undefined ? 'startup' : 'resume';
|
|
174
|
+
fire('SessionStart', source, { source }, session.meta.cwd);
|
|
175
|
+
}));
|
|
176
|
+
offs.push(ctx.on('dsc/compacted', () => fire('PostCompact', '', {})));
|
|
177
|
+
offs.push(ctx.on('dsc/exit', () => fire('SessionEnd', '', { reason: 'exit' })));
|
|
178
|
+
offs.push(ctx.on('dsc/turn-end', (reason, signal) => {
|
|
179
|
+
// 0.6.48:只认当前查看会话的回合。Stop/Interrupt 钩子取的
|
|
180
|
+
// lastAssistantText 来自当前会话,后台 agent 收工时触发会拿错文本。
|
|
181
|
+
// 载荷缺省(老式直接 emit)按当前会话算。
|
|
182
|
+
if (signal !== undefined && signal.sessionId !== ctx.session.current().meta.id)
|
|
183
|
+
return;
|
|
184
|
+
if (reason === 'completed') {
|
|
185
|
+
fire('Stop', '', {
|
|
186
|
+
reason,
|
|
187
|
+
// dsc 没有 codex 的「这已经是钩子推起来的续跑」这个标记,恒为 false(不再二次刹车)
|
|
188
|
+
stop_hook_active: false,
|
|
189
|
+
last_assistant_message: lastAssistantText(),
|
|
190
|
+
});
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (reason === 'aborted')
|
|
194
|
+
fire('Interrupt', '', { reason });
|
|
195
|
+
}));
|
|
196
|
+
// ── 设置分区 ─────────────────────────────────────────────────────────────
|
|
197
|
+
const fields = () => {
|
|
198
|
+
const cfg = config();
|
|
199
|
+
const report = lifecycleReport(cfg.configPath);
|
|
200
|
+
const list = [
|
|
201
|
+
{
|
|
202
|
+
type: 'switch',
|
|
203
|
+
key: 'enabled',
|
|
204
|
+
label: '启用生命周期钩子',
|
|
205
|
+
help: '关掉之后一个钩子都不跑(配置文件留着,随时开回来)。',
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
type: 'text',
|
|
209
|
+
key: 'configPath',
|
|
210
|
+
label: '钩子配置文件',
|
|
211
|
+
mono: true,
|
|
212
|
+
placeholder: 'C:\\Users\\me\\.dsc\\lifecycle-hooks.json',
|
|
213
|
+
help: 'codex 形态的 JSON:`{ "hooks": { "PreToolUse": [{ "matcher": "bash", "hooks": [{ "type": "command", "command": "node guard.js", "timeout": 5 }] }] } }`。timeout 按秒算。',
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
type: 'number',
|
|
217
|
+
key: 'timeoutMs',
|
|
218
|
+
label: '钩子缺省超时(毫秒)',
|
|
219
|
+
min: HOOK_TIMEOUT_MIN,
|
|
220
|
+
max: HOOK_TIMEOUT_MAX,
|
|
221
|
+
step: 500,
|
|
222
|
+
help: `钩子自己没写 timeout 时给多少。范围 ${HOOK_TIMEOUT_MIN}~${HOOK_TIMEOUT_MAX} 毫秒。`,
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
type: 'switch',
|
|
226
|
+
key: 'failClosed',
|
|
227
|
+
label: '钩子没跑成就算拦',
|
|
228
|
+
help: '超时、命令起不来、输出看不懂、退出码非 0 时按「拦下来」处理。关掉就退回「跑不成当没这条钩子」——出了事更难查,建议留着。',
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
type: 'text',
|
|
232
|
+
key: 'commandAllowlist',
|
|
233
|
+
label: '命令白名单',
|
|
234
|
+
mono: true,
|
|
235
|
+
placeholder: '留空 = 不限制;例如 node, uv',
|
|
236
|
+
help: '填了之后只有入口在白名单里的钩子会执行,按命令的第一个词比(`node` 放行 `node guard.js`,不放行 `nodejs-evil`)。被挡下的钩子按「没跑成」处理。',
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
type: 'info',
|
|
240
|
+
label: '十二个事件的接通情况',
|
|
241
|
+
mono: true,
|
|
242
|
+
text: report.capabilities.map((item) => `${item.event}|${TIER_LABELS[item.tier]}|${item.extension}`).join('\n'),
|
|
243
|
+
help: '「未接通」的事件 dsc 现在没有可挂的扩展点,配了钩子也不会执行,原因见下面那条。',
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
type: 'info',
|
|
247
|
+
label: '已加载的钩子',
|
|
248
|
+
mono: true,
|
|
249
|
+
text: report.hooks.length === 0
|
|
250
|
+
? '(配置文件里还没有钩子)'
|
|
251
|
+
: report.hooks
|
|
252
|
+
.map((hook) => `[${hook.event}]${hook.enabled ? '' : '[已停用]'} ${hook.command.slice(0, 60)}`)
|
|
253
|
+
.join('\n'),
|
|
254
|
+
},
|
|
255
|
+
];
|
|
256
|
+
if (report.problems.length > 0) {
|
|
257
|
+
list.push({
|
|
258
|
+
type: 'info',
|
|
259
|
+
label: '没接通与没生效的部分',
|
|
260
|
+
text: report.problems.join('\n'),
|
|
261
|
+
help: '坏掉的条目被跳过了,其余钩子照样生效。',
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
list.push({ type: 'info', label: '配置文件', text: cfg.configPath, mono: true, copyable: true });
|
|
265
|
+
return list;
|
|
266
|
+
};
|
|
267
|
+
const section = {
|
|
268
|
+
id: CONFIG_KEY,
|
|
269
|
+
title: '生命周期钩子',
|
|
270
|
+
subtitle: '按 codex 的事件名跑外部命令钩子',
|
|
271
|
+
order: 36,
|
|
272
|
+
fields,
|
|
273
|
+
values() {
|
|
274
|
+
const cfg = config();
|
|
275
|
+
return {
|
|
276
|
+
enabled: cfg.enabled,
|
|
277
|
+
configPath: cfg.configPath,
|
|
278
|
+
timeoutMs: cfg.timeoutMs,
|
|
279
|
+
failClosed: cfg.failClosed,
|
|
280
|
+
commandAllowlist: cfg.commandAllowlist,
|
|
281
|
+
};
|
|
282
|
+
},
|
|
283
|
+
save(key, value) {
|
|
284
|
+
switch (key) {
|
|
285
|
+
case 'enabled':
|
|
286
|
+
writePluginConfig(CONFIG_KEY, { enabled: value === true });
|
|
287
|
+
return;
|
|
288
|
+
case 'failClosed':
|
|
289
|
+
writePluginConfig(CONFIG_KEY, { failClosed: value === true });
|
|
290
|
+
return;
|
|
291
|
+
case 'timeoutMs': {
|
|
292
|
+
const num = Number(value);
|
|
293
|
+
if (!Number.isFinite(num))
|
|
294
|
+
return '这里要填一个数字(毫秒)';
|
|
295
|
+
writePluginConfig(CONFIG_KEY, { timeoutMs: Math.min(Math.max(Math.round(num), HOOK_TIMEOUT_MIN), HOOK_TIMEOUT_MAX) });
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
case 'configPath': {
|
|
299
|
+
const text = String(value).trim();
|
|
300
|
+
if (text === '')
|
|
301
|
+
return '钩子配置文件路径不能空着';
|
|
302
|
+
writePluginConfig(CONFIG_KEY, { configPath: text });
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
case 'commandAllowlist':
|
|
306
|
+
writePluginConfig(CONFIG_KEY, { commandAllowlist: String(value).trim() });
|
|
307
|
+
return;
|
|
308
|
+
default:
|
|
309
|
+
return `这个分区没有这项:${key}`;
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
offs.push(ctx.settings.registerSection(section));
|
|
314
|
+
// ── /lifecycle-hooks 命令 ────────────────────────────────────────────────
|
|
315
|
+
offs.push(ctx.commands.register({ name: 'lifecycle-hooks', args: '', description: '看生命周期钩子的能力清单与已加载的钩子' }, ({ ui }) => {
|
|
316
|
+
const cfg = config();
|
|
317
|
+
const report = lifecycleReport(cfg.configPath);
|
|
318
|
+
const lines = [
|
|
319
|
+
`生命周期钩子:${cfg.enabled ? '开着' : '关着'}|配置文件 ${cfg.configPath}`,
|
|
320
|
+
`十二个事件(${report.capabilities.length} 个):`,
|
|
321
|
+
];
|
|
322
|
+
for (const item of report.capabilities)
|
|
323
|
+
lines.push(` ${item.event}|${TIER_LABELS[item.tier]}|${item.extension}`);
|
|
324
|
+
lines.push(`已加载钩子 ${report.hooks.length} 条:`);
|
|
325
|
+
for (const hook of report.hooks) {
|
|
326
|
+
lines.push(` [${hook.event}]${hook.enabled ? '' : '[已停用]'} ${hook.command.slice(0, 60)}`);
|
|
327
|
+
}
|
|
328
|
+
for (const problem of report.problems)
|
|
329
|
+
lines.push(` ⚠ ${problem}`);
|
|
330
|
+
ui.notice(lines.join('\n'));
|
|
331
|
+
}));
|
|
332
|
+
return () => {
|
|
333
|
+
lifetime.abort();
|
|
334
|
+
for (const off of offs)
|
|
335
|
+
off();
|
|
336
|
+
};
|
|
337
|
+
},
|
|
338
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* llm 插件:provide `llm` 服务(端点路由 + 模型热切换的唯一状态持有者)。
|
|
3
|
+
* 逻辑迁自 v2 adapter/core-runtime 的 route/setModel 段;提示文本改由
|
|
4
|
+
* runtime 插件经 transcript 呈现,本插件只做校验与状态。
|
|
5
|
+
*
|
|
6
|
+
* 思考档位怎么发、这个模型收不收图,都由 config.yaml 里那一行的能力声明决定
|
|
7
|
+
* (见 core/model-caps.ts);界面上选了模型不支持的档位会在这里被拦住。
|
|
8
|
+
*
|
|
9
|
+
* @module dsc/plugins/llm
|
|
10
|
+
*/
|
|
11
|
+
import type { Plugin } from '@deepseek-ai/cordis';
|
|
12
|
+
import type { DscCoreConfig } from '../core/config.js';
|
|
13
|
+
export declare const llmPlugin: Plugin.Object<DscCoreConfig>;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { DEFAULT_CAPS, clampEffort, effortToWire, hasEffortLevel, THINKING_LEVEL_LABELS } from '../core/model-caps.js';
|
|
2
|
+
import { OPENAI_COMPLETIONS_API, streamChat } from '../core/llm.js';
|
|
3
|
+
/** 请求侧清洗提醒的账:会话 id → 上次报过的报告形状(同形状不重复报,形状变了再报一次)。 */
|
|
4
|
+
const sanitizeNotices = new Map();
|
|
5
|
+
/**
|
|
6
|
+
* 当前会话 id;读不到(没有会话、最小假 ctx)就当没有。
|
|
7
|
+
* 请求归因头靠它兜底:拿不到会话 id 时省略那个头,比编一个稳。
|
|
8
|
+
*/
|
|
9
|
+
function currentSessionId(ctx) {
|
|
10
|
+
try {
|
|
11
|
+
return ctx.session.current().meta.id;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** 历史有协议残留、请求侧兜底清洗过:给用户说一声(同一个会话同一种残留只报一次)。 */
|
|
18
|
+
function noticeSanitize(ctx, report) {
|
|
19
|
+
const sid = ctx.session.current().meta.id;
|
|
20
|
+
const shape = `${String(report.droppedResults)}/${String(report.droppedCalls)}/${String(report.droppedMessages)}/${String(report.reordered)}`;
|
|
21
|
+
if (sanitizeNotices.get(sid) === shape)
|
|
22
|
+
return;
|
|
23
|
+
sanitizeNotices.set(sid, shape);
|
|
24
|
+
const parts = [];
|
|
25
|
+
if (report.droppedResults > 0)
|
|
26
|
+
parts.push(`丢弃重复/孤儿的工具结果 ${String(report.droppedResults)} 条`);
|
|
27
|
+
if (report.droppedCalls > 0)
|
|
28
|
+
parts.push(`剔掉没有回应的工具调用 ${String(report.droppedCalls)} 个`);
|
|
29
|
+
if (report.droppedMessages > 0)
|
|
30
|
+
parts.push(`整条删除已无内容的回复 ${String(report.droppedMessages)} 条`);
|
|
31
|
+
if (report.reordered > 0)
|
|
32
|
+
parts.push(`把 ${String(report.reordered)} 条插队的消息移回工具结果之后`);
|
|
33
|
+
ctx.emit('dsc/notice', `会话日志里有协议残留(多半来自上一次中断),这次请求已自动清洗:${parts.join('、')}。只影响发给模型的这一份,日志文件不动。`);
|
|
34
|
+
}
|
|
35
|
+
export const llmPlugin = {
|
|
36
|
+
name: 'llm',
|
|
37
|
+
inject: ['session'],
|
|
38
|
+
provide: 'llm',
|
|
39
|
+
apply(ctx, config) {
|
|
40
|
+
let currentProvider = config.defaultProvider;
|
|
41
|
+
let currentModel = config.defaultModel;
|
|
42
|
+
// 'default' = 不发思考字段(跟随端点默认行为)
|
|
43
|
+
let currentEffort = 'default';
|
|
44
|
+
// T39:会话里记过模型选择就先恢复它(/model 切过的不丢);没记过才用配置默认。
|
|
45
|
+
const remembered = ctx.session.current().state('model');
|
|
46
|
+
if (remembered !== undefined && findModel(remembered.provider, remembered.model) !== undefined) {
|
|
47
|
+
currentProvider = remembered.provider;
|
|
48
|
+
currentModel = remembered.model;
|
|
49
|
+
}
|
|
50
|
+
// 切会话跟着切模型:新会话记过谁就用谁,没记过保持当前选择(与 /model 的
|
|
51
|
+
// 进程级热切换同一手感)。配置里已经没有的模型不恢复,静默留在当前选择上。
|
|
52
|
+
ctx.on('dsc/session-open', ({ session }) => {
|
|
53
|
+
const recalled = session.state('model');
|
|
54
|
+
if (recalled === undefined || findModel(recalled.provider, recalled.model) === undefined)
|
|
55
|
+
return;
|
|
56
|
+
if (recalled.provider === currentProvider && recalled.model === currentModel)
|
|
57
|
+
return;
|
|
58
|
+
currentProvider = recalled.provider;
|
|
59
|
+
currentModel = recalled.model;
|
|
60
|
+
// 原来选的档位在新模型上未必存在,退回「默认」比留着发不出去的值强
|
|
61
|
+
currentEffort = clampEffort(capsFor(currentProvider, currentModel), currentEffort);
|
|
62
|
+
ctx.emit('dsc/changed');
|
|
63
|
+
});
|
|
64
|
+
/** 协议适配器表:id → 适配器。内置 openai-completions 预注册,插件可补新的协议。 */
|
|
65
|
+
const adapters = new Map([
|
|
66
|
+
[OPENAI_COMPLETIONS_API, { id: OPENAI_COMPLETIONS_API, stream: streamChat }],
|
|
67
|
+
]);
|
|
68
|
+
function findModel(providerName, modelName) {
|
|
69
|
+
// provider 表可能缺(最小假 ctx 的测试/插件环境),空表按查不到算
|
|
70
|
+
return (config.providers ?? {})[providerName]?.models.find((model) => model.id === modelName);
|
|
71
|
+
}
|
|
72
|
+
/** 这个模型声明了什么能力;查不到(老配置、临时路由)按旧行为算。 */
|
|
73
|
+
function capsFor(providerName, modelName) {
|
|
74
|
+
return findModel(providerName, modelName) ?? DEFAULT_CAPS;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 按给定的端点/模型/档位组一份请求路由,不动当前选择。
|
|
78
|
+
* 子智能体拿它跑角色自己指定的模型,父会话不受影响。
|
|
79
|
+
* 档位在这个模型上不存在时退回「默认」(不发字段),而不是把端点不认识的值发出去。
|
|
80
|
+
*/
|
|
81
|
+
function routeFor(providerName, modelName, effort) {
|
|
82
|
+
const provider = (config.providers ?? {})[providerName];
|
|
83
|
+
if (provider === undefined) {
|
|
84
|
+
throw new Error(`没有名为 ${providerName} 的模型端点(检查 ~/.dsc/config.yaml 的 providers 段与对应 API key 环境变量)`);
|
|
85
|
+
}
|
|
86
|
+
const model = findModel(providerName, modelName);
|
|
87
|
+
const wire = effortToWire(capsFor(providerName, modelName), clampEffort(capsFor(providerName, modelName), effort));
|
|
88
|
+
return {
|
|
89
|
+
api: provider.api ?? OPENAI_COMPLETIONS_API,
|
|
90
|
+
baseUrl: provider.baseUrl,
|
|
91
|
+
apiKey: provider.apiKey,
|
|
92
|
+
model: modelName,
|
|
93
|
+
maxTokens: model?.maxTokens,
|
|
94
|
+
temperature: config.temperature,
|
|
95
|
+
thinking: wire.thinking,
|
|
96
|
+
reasoningEffort: wire.reasoningEffort,
|
|
97
|
+
// 显式缓存断点:只有端点自己声明了才带(缺省不带 = DeepSeek 请求体逐字节不变)
|
|
98
|
+
...(provider.cacheControl === true ? { cacheControl: true } : {}),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const service = {
|
|
102
|
+
get provider() {
|
|
103
|
+
return currentProvider;
|
|
104
|
+
},
|
|
105
|
+
get model() {
|
|
106
|
+
return currentModel;
|
|
107
|
+
},
|
|
108
|
+
get effort() {
|
|
109
|
+
return currentEffort;
|
|
110
|
+
},
|
|
111
|
+
get contextWindow() {
|
|
112
|
+
return findModel(currentProvider, currentModel)?.contextWindow ?? 128_000;
|
|
113
|
+
},
|
|
114
|
+
get inputModalities() {
|
|
115
|
+
return capsFor(currentProvider, currentModel).modalities;
|
|
116
|
+
},
|
|
117
|
+
route() {
|
|
118
|
+
return routeFor(currentProvider, currentModel, currentEffort);
|
|
119
|
+
},
|
|
120
|
+
routeTo(provider, model, effort) {
|
|
121
|
+
return routeFor(provider, model, effort);
|
|
122
|
+
},
|
|
123
|
+
registerAdapter(adapter) {
|
|
124
|
+
if (adapters.has(adapter.id)) {
|
|
125
|
+
throw new Error(`协议适配器 ${adapter.id} 已经注册过(内置与插件不允许重名,换个 id)`);
|
|
126
|
+
}
|
|
127
|
+
adapters.set(adapter.id, adapter);
|
|
128
|
+
return () => {
|
|
129
|
+
if (adapters.get(adapter.id) === adapter)
|
|
130
|
+
adapters.delete(adapter.id);
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
stream(api, request, handlers) {
|
|
134
|
+
const adapter = adapters.get(api);
|
|
135
|
+
if (adapter === undefined) {
|
|
136
|
+
const known = [...adapters.keys()].map((id) => (id === api ? `「${id}」` : id)).join('、');
|
|
137
|
+
throw new Error(`端点声明的协议 ${api} 没有对应的适配器(已注册:${known})。\n` +
|
|
138
|
+
'检查 config.yaml 里这个端点的 api 字段,或启用提供该协议的插件。');
|
|
139
|
+
}
|
|
140
|
+
// 会话归因(opencode Go 要求每条会话带一个稳定 id):这里是所有模型请求的
|
|
141
|
+
// **唯一汇聚点**——回合轮次、压缩、标题、审批、子智能体都从这条缝过,
|
|
142
|
+
// 默认值在这里补一次全体受益。调用方手里有更准的会话(后台 agent 跑的
|
|
143
|
+
// 不是「当前查看的会话」,见 core/loop)会自己填,填了就听它的。
|
|
144
|
+
return adapter.stream({ ...request, sessionId: request.sessionId ?? currentSessionId(ctx) }, { ...handlers, onSanitize: (report) => noticeSanitize(ctx, report) });
|
|
145
|
+
},
|
|
146
|
+
setEffort(effort) {
|
|
147
|
+
const caps = capsFor(currentProvider, currentModel);
|
|
148
|
+
if (!hasEffortLevel(caps, effort)) {
|
|
149
|
+
const declared = caps.thinkingLevels.length === 0
|
|
150
|
+
? '这个模型没声明思考能力,只有「默认」可选'
|
|
151
|
+
: `这个模型只支持:${caps.thinkingLevels.map((level) => THINKING_LEVEL_LABELS[level]).join('、')}`;
|
|
152
|
+
const wanted = effort === 'default' ? '默认' : THINKING_LEVEL_LABELS[effort];
|
|
153
|
+
throw new Error(`思考档位「${wanted}」用不了 —— ${declared}(在设置 → 模型里给它勾上)`);
|
|
154
|
+
}
|
|
155
|
+
currentEffort = effort;
|
|
156
|
+
ctx.emit('dsc/changed');
|
|
157
|
+
},
|
|
158
|
+
setModel(provider, model) {
|
|
159
|
+
const target = (config.providers ?? {})[provider];
|
|
160
|
+
if (target === undefined) {
|
|
161
|
+
throw new Error(`没有名为 ${provider} 的端点;可用:${Object.keys(config.providers ?? {}).join('、') || '(无)'}`);
|
|
162
|
+
}
|
|
163
|
+
if (!target.models.some((entry) => entry.id === model)) {
|
|
164
|
+
throw new Error(`端点 ${provider} 没有模型 ${model};可用:${target.models.map((entry) => entry.id).join('、')}`);
|
|
165
|
+
}
|
|
166
|
+
currentProvider = provider;
|
|
167
|
+
currentModel = model;
|
|
168
|
+
// 原来选的档位在新模型上未必存在,退回「默认」比留着发不出去的值强
|
|
169
|
+
currentEffort = clampEffort(capsFor(provider, model), currentEffort);
|
|
170
|
+
// T39:记进当前会话——恢复会话时优先用它,重启/重开不再回落配置默认
|
|
171
|
+
ctx.session.current().appendState('model', { provider, model });
|
|
172
|
+
ctx.emit('dsc/changed');
|
|
173
|
+
},
|
|
174
|
+
parseModelRef(ref) {
|
|
175
|
+
// 长端点名优先:「command/deepseek/deepseek-v4.1-flash」必须命中 command,
|
|
176
|
+
// 而不是被前缀更短的「deepseek/」抢走(那会把模型名连斜杠一起切碎)。
|
|
177
|
+
const names = Object.keys(config.providers ?? {}).sort((a, b) => b.length - a.length);
|
|
178
|
+
for (const name of names) {
|
|
179
|
+
if (ref.startsWith(`${name}/`))
|
|
180
|
+
return { provider: name, model: ref.slice(name.length + 1) };
|
|
181
|
+
}
|
|
182
|
+
return { provider: currentProvider, model: ref };
|
|
183
|
+
},
|
|
184
|
+
listModels() {
|
|
185
|
+
const choices = [];
|
|
186
|
+
for (const provider of Object.values(config.providers)) {
|
|
187
|
+
for (const model of provider.models) {
|
|
188
|
+
const extra = model.modalities.filter((modality) => modality !== 'text');
|
|
189
|
+
choices.push({
|
|
190
|
+
value: `${provider.name}/${model.id}`,
|
|
191
|
+
provider: provider.name,
|
|
192
|
+
// 一级菜单按显示名画(用户填了 `displayName` 就用它,没填等于端点名);
|
|
193
|
+
// 二级列表里仍按模型「自己的」id 画,不替它加前缀。
|
|
194
|
+
providerDisplayName: provider.displayName === '' ? provider.name : provider.displayName,
|
|
195
|
+
model: model.id,
|
|
196
|
+
description: [
|
|
197
|
+
provider.displayName,
|
|
198
|
+
`${Math.round(model.contextWindow / 1000)}k 上下文`,
|
|
199
|
+
extra.length > 0 ? extra.map((modality) => (modality === 'image' ? '照片' : '视频')).join('·') : '',
|
|
200
|
+
model.thinkingLevels.length > 0 ? `思考 ${model.thinkingLevels.length} 档` : '无思考档位',
|
|
201
|
+
]
|
|
202
|
+
.filter((part) => part !== '')
|
|
203
|
+
.join(' · '),
|
|
204
|
+
contextWindow: model.contextWindow,
|
|
205
|
+
thinkingLevels: model.thinkingLevels,
|
|
206
|
+
modalities: model.modalities,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return choices;
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
ctx.provide('llm', service);
|
|
214
|
+
},
|
|
215
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lsp 插件:LSP 代码智能。**默认关**(会按需拉起语言服务器子进程,属于默认关那一档)。
|
|
3
|
+
*
|
|
4
|
+
* 形制照 dsh 的 `packages/lsp/*`(单工具按 operation 分发 + 无状态文档同步)
|
|
5
|
+
* 加 hermes 的 `agent/lsp`(内置服务器表 + marker 找根 + idle 回收 + 退避 + 编辑后诊断注入):
|
|
6
|
+
* - 只暴露「导航」四件事:goToDefinition / findReferences(含声明)/
|
|
7
|
+
* goToImplementation / hover;rename / codeAction / format 不做(要 ApplyEdit + 审批,
|
|
8
|
+
* 且与 write/edit 重复);
|
|
9
|
+
* - 同步策略:**读盘 → didOpen(全量)→ 请求 → didClose**,天然没有脏文档;
|
|
10
|
+
* - 生命周期:每 (server, root) 一进程 + 该 root 串行队列;idle 600s 回收(下限 30s);
|
|
11
|
+
* 启动失败对破键退避;60s 请求预算,取消先 `$/cancelRequest` 再宽限杀实例;
|
|
12
|
+
* - 降级永不抛错给模型:没装 / 起不来 / 初始化超时 / 无 root →
|
|
13
|
+
* 「无数据 + 原因 + stderr 尾巴 30 行」。
|
|
14
|
+
*
|
|
15
|
+
* ## 诊断注入为什么落在「下一次请求」而不是 write 工具的输出里
|
|
16
|
+
*
|
|
17
|
+
* 观察者的签名是 `observe(toolName, text) => text`,**同步**——它没法在里面等一次 LSP 往返
|
|
18
|
+
* (等不了,也没法把结果塞回这次的工具输出)。所以本插件用的是内核另一条现成通道:
|
|
19
|
+
* 观察者只负责把「写后诊断」挂到后台,算完攒进 `pending`,由 `ctx.prompt.transformMessages`
|
|
20
|
+
* 在下一次请求的末尾补一条 system 段(`core/lifecycle-hooks.ts` 的 PostToolUse 走的是同一条路)。
|
|
21
|
+
* 于是:写前基线由守卫 order 7 同步排队(`decide` 只做「读盘 + 入队」,**不阻塞这一次写**),
|
|
22
|
+
* 写后诊断由观察者 order 46 入队;两侧都排在同一个 (server, root) 串行队列上,
|
|
23
|
+
* 顺序天然是「写前 → 写后」。判定用**行位移映射**(`buildLineShift`)后的集合差,
|
|
24
|
+
* 只报本次改动**新引入**的 ERROR——被插入行推下去的旧报错不会当成新错误。
|
|
25
|
+
*
|
|
26
|
+
* 两个实测过的坑(自检必须覆盖):
|
|
27
|
+
* - URI 必须**先解码成路径再比内外**(Node 的 `pathToFileURL` 产出 `file:///C:/…`,
|
|
28
|
+
* 有的服务器回 `file:///c%3A/…`;盘符大小写、UNC、`%5C`、`%00` 都要过);
|
|
29
|
+
* - 列偏移不用换算:JS 字符串长度天然是 UTF-16 code unit,只做一基/零基转换。
|
|
30
|
+
*
|
|
31
|
+
* 支撑模块(本插件独占):`src/core/lsp/{framing,client,manager,normalize,line-shift,servers,uri}.ts`
|
|
32
|
+
*
|
|
33
|
+
* @module dsc/plugins/lsp
|
|
34
|
+
*/
|
|
35
|
+
import type { Plugin } from '@deepseek-ai/cordis';
|
|
36
|
+
import { type LspStatusEntry } from '../core/lsp/client.js';
|
|
37
|
+
import { type LspServerInfo } from '../core/lsp/servers.js';
|
|
38
|
+
/** 工具与 `ctx.get('lsp')` 共用的能力面。 */
|
|
39
|
+
export interface LspService {
|
|
40
|
+
/**
|
|
41
|
+
* 查一次并返回已经过围栏与截断的文本(与 `lsp` 工具的返回一致)。
|
|
42
|
+
*
|
|
43
|
+
* @param operation - 四个操作之一。
|
|
44
|
+
* @param filePath - 目标文件(相对路径按会话工作目录展开)。
|
|
45
|
+
* @param line - 一基行号。
|
|
46
|
+
* @param character - 一基列号。
|
|
47
|
+
*/
|
|
48
|
+
query(operation: string, filePath: string, line: number, character: number): Promise<string>;
|
|
49
|
+
/** 每个服务器的状态与实例数。 */
|
|
50
|
+
status(): LspStatusEntry[];
|
|
51
|
+
/** 现在生效的服务器表(含「PATH 里有没有」)。 */
|
|
52
|
+
servers(): LspServerInfo[];
|
|
53
|
+
}
|
|
54
|
+
export declare const lspPlugin: Plugin.Object;
|