@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,862 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 子智能体(官方插件,默认关闭)。
|
|
3
|
+
*
|
|
4
|
+
* 打开后模型多出 `subagent` 工具:派活、传话、打断。关掉后这个工具、它注入的
|
|
5
|
+
* 提示词、以及在跑的队友一起消失——本插件不提供第二套 agent 实现,队友就是
|
|
6
|
+
* 「另一个 MiniAgent 实例 + 它自己的会话文件 + 一张冻结的工牌」。
|
|
7
|
+
*
|
|
8
|
+
* 队友按会话隔离(对照 dsh 的 parentSession 过滤):每个会话各自一份在队名单与
|
|
9
|
+
* 并发额度,`subagent list` 只报本会话派出的队友;共享任务看板在「智能体团队」
|
|
10
|
+
* 插件里,那是叠在这一层之上的协作层。
|
|
11
|
+
*
|
|
12
|
+
* 工牌(工具白名单 / 审批意愿 / 轮次预算 / 模型)在队友开工那一刻从角色文件复制进
|
|
13
|
+
* 运行时并冻结,所以中途改角色文件只影响下一个新队友,也堵住了「队友跑一半给自己提权」。
|
|
14
|
+
*
|
|
15
|
+
* 审批取「全局上限」与「角色意愿」里更严的那个:全局选「不允许」时谁都别想弹卡;
|
|
16
|
+
* 全局选「仅前台队友」时,后台队友自动退回不允许。弹出来的卡上写明是谁在请求。
|
|
17
|
+
*
|
|
18
|
+
* @module dsc/plugins/subagent
|
|
19
|
+
*/
|
|
20
|
+
import { randomUUID } from 'node:crypto';
|
|
21
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
22
|
+
import { join, resolve } from 'node:path';
|
|
23
|
+
import { Transcript } from '../adapter/transcript.js';
|
|
24
|
+
import { builtinRoleNames, builtinRole, DSC_AGENTS_DIR, ensureBuiltinRoles, findRole, listRoles, writeRole, } from '../core/agent-roles.js';
|
|
25
|
+
import { resolvePluginConfig, writePluginConfig } from '../core/plugin-registry.js';
|
|
26
|
+
import { MiniAgent } from '../core/loop.js';
|
|
27
|
+
import { subagentEnvironmentText } from '../core/prompt.js';
|
|
28
|
+
import { REJECTED_TOOL_TEXT, Session, teammateRoot } from '../core/session.js';
|
|
29
|
+
import { redact } from '../core/secrets.js';
|
|
30
|
+
import { argsSummary } from '../core/tools.js';
|
|
31
|
+
import { ToolGuardRegistry, toolApprovalGuard } from '../core/tool-guards.js';
|
|
32
|
+
import { inboxAppend, REVIEW_FINDINGS_OPEN, TEAMMATE_REPORT_OPEN } from '../core/team-board.js';
|
|
33
|
+
import { reviewMessage } from '../core/git-info.js';
|
|
34
|
+
const CONFIG_KEY = 'subagent';
|
|
35
|
+
const DEFAULTS = {
|
|
36
|
+
allowDelegation: true,
|
|
37
|
+
maxTeammates: 4,
|
|
38
|
+
maxDepth: 1,
|
|
39
|
+
approval: 'forbid',
|
|
40
|
+
notify: 'auto',
|
|
41
|
+
defaultModel: '',
|
|
42
|
+
};
|
|
43
|
+
const APPROVAL_RANK = { forbid: 0, foreground: 1, ask: 2 };
|
|
44
|
+
/** 收工的队友最多在名单里留这么多个,超了就挤掉最老的(不占并发额度,只是别把名单撑爆)。 */
|
|
45
|
+
const MAX_LISTED_FINISHED = 12;
|
|
46
|
+
/** 主会话这一方在任务板上的名字。 */
|
|
47
|
+
const LEAD = 'lead';
|
|
48
|
+
/** 名字合法字符,跟角色名同一套。 */
|
|
49
|
+
const NAME_OK = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
50
|
+
/** 工作目录名 → 可当目录名的短名(队友日志按它分堆)。 */
|
|
51
|
+
function cwdSlug(cwd) {
|
|
52
|
+
const cleaned = cwd.replace(/[^\w.-]+/g, '_').replace(/^_+|_+$/g, '');
|
|
53
|
+
return cleaned.slice(-40) === '' ? 'cwd' : cleaned.slice(-40);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 把父会话切到「上一个完整回合」为止的记录行(不含 meta)。
|
|
57
|
+
* 完整回合 = 一条没带工具调用的 assistant 回复;它的后面可能就是正干到一半的活,
|
|
58
|
+
* 那些不要,否则队友一睁眼就看到半截工具调用。
|
|
59
|
+
* @returns null = 这个会话还没有一个完整回合可带。
|
|
60
|
+
*/
|
|
61
|
+
function forkSeedLines(parentFile) {
|
|
62
|
+
let raw;
|
|
63
|
+
try {
|
|
64
|
+
raw = readFileSync(parentFile, 'utf8');
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const lines = raw.split(/\r?\n/).filter((line) => line !== '');
|
|
70
|
+
let cut = -1;
|
|
71
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
72
|
+
try {
|
|
73
|
+
const record = JSON.parse(lines[index]);
|
|
74
|
+
if (record.type === 'assistant' && record.toolCalls === undefined) {
|
|
75
|
+
cut = index;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// 坏行:跳过继续往前找,不影响切点
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (cut < 0)
|
|
84
|
+
return null;
|
|
85
|
+
// 第 0 行是父会话自己的 meta,队友要用自己那条
|
|
86
|
+
return lines.slice(1, cut + 1);
|
|
87
|
+
}
|
|
88
|
+
export const subagentPlugin = {
|
|
89
|
+
name: 'subagent',
|
|
90
|
+
inject: ['session', 'tools', 'llm', 'approval', 'transcript', 'prompt', 'settings', 'agent'],
|
|
91
|
+
apply(ctx, passed) {
|
|
92
|
+
ensureBuiltinRoles();
|
|
93
|
+
// ── 配置 ────────────────────────────────────────────────────────────────
|
|
94
|
+
const readConfig = () => {
|
|
95
|
+
const raw = resolvePluginConfig(CONFIG_KEY, passed);
|
|
96
|
+
const clamp = (value, min, max, fallback) => {
|
|
97
|
+
const num = Number(value);
|
|
98
|
+
return Number.isFinite(num) ? Math.min(Math.max(Math.round(num), min), max) : fallback;
|
|
99
|
+
};
|
|
100
|
+
const approval = APPROVAL_RANK[String(raw.approval)] === undefined
|
|
101
|
+
? DEFAULTS.approval
|
|
102
|
+
: String(raw.approval);
|
|
103
|
+
return {
|
|
104
|
+
allowDelegation: raw.allowDelegation !== false && raw.allowDelegation !== 'false',
|
|
105
|
+
maxTeammates: clamp(raw.maxTeammates, 1, 8, DEFAULTS.maxTeammates),
|
|
106
|
+
maxDepth: clamp(raw.maxDepth, 0, 2, DEFAULTS.maxDepth),
|
|
107
|
+
approval,
|
|
108
|
+
notify: raw.notify === 'quiet' ? 'quiet' : 'auto',
|
|
109
|
+
defaultModel: typeof raw.defaultModel === 'string' ? raw.defaultModel.trim() : '',
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
let config = readConfig();
|
|
113
|
+
const applyConfig = (patch) => {
|
|
114
|
+
writePluginConfig(CONFIG_KEY, patch);
|
|
115
|
+
config = readConfig();
|
|
116
|
+
};
|
|
117
|
+
// ── 名册持久化 ──────────────────────────────────────────────────────────
|
|
118
|
+
const rosterFile = join(ctx.settings.about().home, 'team', 'roster.json');
|
|
119
|
+
const readRoster = () => {
|
|
120
|
+
try {
|
|
121
|
+
const doc = JSON.parse(readFileSync(rosterFile, 'utf8'));
|
|
122
|
+
return Array.isArray(doc.teammates) ? doc.teammates : [];
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const writeRoster = (records) => {
|
|
129
|
+
try {
|
|
130
|
+
mkdirSync(join(ctx.settings.about().home, 'team'), { recursive: true });
|
|
131
|
+
writeFileSync(rosterFile, `${JSON.stringify({ teammates: records }, null, 2)}\n`, 'utf8');
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// 名册写不下去只影响重启后侧栏看不到收工的队友,不该让派活失败
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const remember = (teammate) => {
|
|
138
|
+
const record = {
|
|
139
|
+
name: teammate.name,
|
|
140
|
+
role: teammate.role,
|
|
141
|
+
state: teammate.state,
|
|
142
|
+
task: teammate.task,
|
|
143
|
+
file: teammate.session.filePath,
|
|
144
|
+
cwd: teammate.session.meta.cwd,
|
|
145
|
+
parent: teammate.parent,
|
|
146
|
+
depth: teammate.depth,
|
|
147
|
+
rounds: teammate.rounds,
|
|
148
|
+
startedAt: teammate.startedAt,
|
|
149
|
+
// 出生会话:队友从哪个会话派出去的,名册上永久记着(用户切走会话也认得出它属于谁)
|
|
150
|
+
sessionId: teammate.parentSession.meta.id,
|
|
151
|
+
...(teammate.finishedAt !== undefined ? { finishedAt: teammate.finishedAt } : {}),
|
|
152
|
+
};
|
|
153
|
+
const rest = readRoster().filter((entry) => entry.name !== teammate.name);
|
|
154
|
+
writeRoster([...rest, record].slice(-200));
|
|
155
|
+
};
|
|
156
|
+
// ── 队友运行时 ──────────────────────────────────────────────────────────
|
|
157
|
+
const teammates = new Map();
|
|
158
|
+
/** 正在干活的队友(并发额度按会话各计各的,对照 dsh 的 per-session 团队):收工的不占坑。 */
|
|
159
|
+
const busyFor = (sessionId) => [...teammates.values()].filter((entry) => entry.state === 'working' && entry.parentSession.meta.id === sessionId);
|
|
160
|
+
const waitForIdle = (teammate) => teammate.state !== 'working'
|
|
161
|
+
? Promise.resolve()
|
|
162
|
+
: new Promise((resolve) => teammate.waiters.push(resolve));
|
|
163
|
+
const settle = (teammate, reason, error) => {
|
|
164
|
+
teammate.finishedAt = Date.now();
|
|
165
|
+
const tail = [...teammate.session.messages].reverse().find((message) => message.role === 'assistant');
|
|
166
|
+
teammate.lastText = typeof tail?.content === 'string' ? tail.content : '';
|
|
167
|
+
if (reason === 'completed')
|
|
168
|
+
teammate.state = 'idle';
|
|
169
|
+
else if (reason === 'aborted')
|
|
170
|
+
teammate.state = 'stopped';
|
|
171
|
+
else {
|
|
172
|
+
teammate.state = 'failed';
|
|
173
|
+
teammate.error = error;
|
|
174
|
+
}
|
|
175
|
+
remember(teammate);
|
|
176
|
+
// T21:队友状态进了快照的跨会话状态面,动一下要跟着失效
|
|
177
|
+
ctx.transcript.touch();
|
|
178
|
+
const waiters = teammate.waiters.splice(0);
|
|
179
|
+
for (const resolve of waiters)
|
|
180
|
+
resolve();
|
|
181
|
+
};
|
|
182
|
+
/** 队友的工具表:按工牌白名单筛。subagent 换成它自己的署名;team_task(智能体团队
|
|
183
|
+
* 插件注册的)保留原实现,只把自己的身份塞进上下文,看板认领人才不会都算成 lead。 */
|
|
184
|
+
const toolsFor = (teammate) => {
|
|
185
|
+
const all = ctx.tools.list();
|
|
186
|
+
const allowed = teammate.badge.tools === null ? all : all.filter((entry) => teammate.badge.tools.includes(entry.name));
|
|
187
|
+
const self = () => ({ name: teammate.name, depth: teammate.depth, background: teammate.background });
|
|
188
|
+
return allowed.map((entry) => {
|
|
189
|
+
if (entry.name === 'subagent') {
|
|
190
|
+
return { ...entry, run: (args, runCtx) => runSubagent(args, runCtx, self()) };
|
|
191
|
+
}
|
|
192
|
+
if (entry.name === 'team_task') {
|
|
193
|
+
return { ...entry, run: (args, runCtx) => entry.run(args, { ...runCtx, caller: self() }) };
|
|
194
|
+
}
|
|
195
|
+
return entry;
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* 队友自己那条工具守卫链:全局上限与角色意愿取更严的那个,通过的请求在卡上署名。
|
|
200
|
+
* 每条链只有一位审批守卫——队友不该被主会话的协作模式闸门管着,也不该跟主会话共用一条链。
|
|
201
|
+
*/
|
|
202
|
+
const guardsFor = (teammate) => {
|
|
203
|
+
const chain = new ToolGuardRegistry();
|
|
204
|
+
chain.register(toolApprovalGuard({
|
|
205
|
+
id: `teammate:${teammate.name}`,
|
|
206
|
+
async approve(input) {
|
|
207
|
+
const rank = Math.min(APPROVAL_RANK[config.approval], APPROVAL_RANK[teammate.badge.approval]);
|
|
208
|
+
const canAsk = rank >= APPROVAL_RANK.foreground && (rank === APPROVAL_RANK.ask || !teammate.background);
|
|
209
|
+
if (!canAsk)
|
|
210
|
+
return false;
|
|
211
|
+
const decision = await ctx.approval.decide({
|
|
212
|
+
toolName: `队友 ${teammate.name}(${teammate.role})· ${input.toolName}`,
|
|
213
|
+
argsSummary: argsSummary(input.args),
|
|
214
|
+
args: input.args,
|
|
215
|
+
cwd: input.cwd,
|
|
216
|
+
}, input.signal);
|
|
217
|
+
return decision !== 'reject';
|
|
218
|
+
},
|
|
219
|
+
deniedReason: REJECTED_TOOL_TEXT,
|
|
220
|
+
}));
|
|
221
|
+
chain.registerObserver({ id: 'redact', order: 10, observe: (_toolName, text) => redact(text) });
|
|
222
|
+
return chain;
|
|
223
|
+
};
|
|
224
|
+
function startTeammate(input) {
|
|
225
|
+
const cwd = input.parentSession.meta.cwd;
|
|
226
|
+
const file = join(teammateRoot(), cwdSlug(cwd), `${randomUUID()}.jsonl`);
|
|
227
|
+
mkdirSync(join(teammateRoot(), cwdSlug(cwd)), { recursive: true });
|
|
228
|
+
const id = randomUUID();
|
|
229
|
+
let session;
|
|
230
|
+
if (input.seed === null) {
|
|
231
|
+
session = Session.create(cwd, file);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
const meta = JSON.stringify({ type: 'meta', id, cwd, createdAt: Date.now() });
|
|
235
|
+
writeFileSync(file, [meta, ...input.seed].join('\n') + '\n', 'utf8');
|
|
236
|
+
session = Session.load(file, true);
|
|
237
|
+
}
|
|
238
|
+
const model = input.role.model ?? (config.defaultModel === '' ? null : config.defaultModel);
|
|
239
|
+
const effort = input.role.effort;
|
|
240
|
+
const teammate = {
|
|
241
|
+
name: input.name,
|
|
242
|
+
role: input.role.name,
|
|
243
|
+
task: input.task,
|
|
244
|
+
// 工牌在此刻冻结:此后改角色文件不影响它
|
|
245
|
+
badge: {
|
|
246
|
+
tools: input.role.tools,
|
|
247
|
+
maxTurns: input.role.maxTurns,
|
|
248
|
+
approval: input.role.approval,
|
|
249
|
+
model,
|
|
250
|
+
effort,
|
|
251
|
+
},
|
|
252
|
+
session,
|
|
253
|
+
parentSession: input.parentSession,
|
|
254
|
+
state: 'working',
|
|
255
|
+
rounds: 0,
|
|
256
|
+
toolCalls: 0,
|
|
257
|
+
depth: input.caller.depth + 1,
|
|
258
|
+
parent: input.caller.name,
|
|
259
|
+
background: input.background,
|
|
260
|
+
startedAt: Date.now(),
|
|
261
|
+
lastText: '',
|
|
262
|
+
waiters: [],
|
|
263
|
+
outputLines: [],
|
|
264
|
+
tokens: 0,
|
|
265
|
+
agent: undefined,
|
|
266
|
+
};
|
|
267
|
+
/** 正文按行攒的缓冲(delta 碎片凑整行进瀑布)。 */
|
|
268
|
+
let lineBuffer = '';
|
|
269
|
+
teammate.agent = new MiniAgent({
|
|
270
|
+
route: () => {
|
|
271
|
+
if (teammate.badge.model === null)
|
|
272
|
+
return ctx.llm.route();
|
|
273
|
+
const at = teammate.badge.model.indexOf('/');
|
|
274
|
+
const provider = at > 0 ? teammate.badge.model.slice(0, at) : teammate.badge.model;
|
|
275
|
+
const modelId = at > 0 ? teammate.badge.model.slice(at + 1) : '';
|
|
276
|
+
return ctx.llm.routeTo(provider, modelId, teammate.badge.effort ?? 'default');
|
|
277
|
+
},
|
|
278
|
+
// 子代理的 deps 没有 rewrite(主会话的 env-facts 投影对子代理不生效),
|
|
279
|
+
// 又没有尾部快照那条路,所以环境/模型事实直接写进它自己的系统提示词。
|
|
280
|
+
// cwd 取派它的那个会话(子代理在父会话的 cwd 下干活),模型取冻结的工牌。
|
|
281
|
+
systemPrompt: () => `${input.role.prompt}
|
|
282
|
+
|
|
283
|
+
${subagentEnvironmentText(input.parentSession.meta.cwd, teammate.badge.model ?? ctx.llm.model)}
|
|
284
|
+
|
|
285
|
+
# 你在团队里的位置
|
|
286
|
+
你是队友「${teammate.name}」(角色 ${teammate.role}),派你活的是「${teammate.parent}」。
|
|
287
|
+
你最多能发 ${teammate.badge.maxTurns} 次模型请求,用完会被自动收手,请把力气花在关键处。
|
|
288
|
+
${teammate.badge.tools === null ? '' : `你只被授权这些工具:${teammate.badge.tools.join('、')}。用别的办法办不成就在最后一段说清楚,让 ${teammate.parent} 决定。`}
|
|
289
|
+
${teammate.badge.approval === 'forbid' ? '你不能向用户请求授权:需要授权的操作会被直接拒绝,不要反复尝试。' : '需要授权的操作可以向用户请求,审批卡上会写明是你(' + teammate.name + ')在请求。'}
|
|
290
|
+
干完活用一段话交结果:做了什么、看到什么证据(文件名:行号)、还有什么没做。`,
|
|
291
|
+
tools: () => toolsFor(teammate),
|
|
292
|
+
guards: guardsFor(teammate),
|
|
293
|
+
stream: (api, request, handlers) => ctx.llm.stream(api, request, handlers),
|
|
294
|
+
emit: (event) => {
|
|
295
|
+
if (event.type === 'message') {
|
|
296
|
+
teammate.rounds += 1;
|
|
297
|
+
// 轮次预算到点就收手:这就是「子智能体不许无限自转」的闸门
|
|
298
|
+
if (teammate.rounds >= teammate.badge.maxTurns)
|
|
299
|
+
teammate.agent.cancel();
|
|
300
|
+
}
|
|
301
|
+
else if (event.type === 'tool/call') {
|
|
302
|
+
teammate.toolCalls += 1;
|
|
303
|
+
teammate.lastTool = {
|
|
304
|
+
name: event.name,
|
|
305
|
+
args: event.args.replace(/\s+/g, ' ').trim().slice(0, 60),
|
|
306
|
+
status: 'running',
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
else if (event.type === 'tool/result') {
|
|
310
|
+
if (teammate.lastTool !== undefined) {
|
|
311
|
+
teammate.lastTool = {
|
|
312
|
+
...teammate.lastTool,
|
|
313
|
+
status: event.error !== undefined && event.error !== 'rejected' ? 'failed' : 'done',
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
// 工具结果首行进瀑布:跑动期间 teammate 说话少、动手多,结果行才是活信号
|
|
317
|
+
const firstLine = event.text.split('\n').map((line) => line.trim()).find((line) => line !== '');
|
|
318
|
+
if (firstLine !== undefined)
|
|
319
|
+
pushLines(teammate.outputLines, firstLine);
|
|
320
|
+
}
|
|
321
|
+
else if (event.type === 'delta' && event.kind === 'text') {
|
|
322
|
+
// 正文增量按行攒:成行的推进瀑布(跟主会话直播尾同一节奏,不需要节流器)
|
|
323
|
+
lineBuffer += event.text;
|
|
324
|
+
let newline = lineBuffer.indexOf('\n');
|
|
325
|
+
while (newline >= 0) {
|
|
326
|
+
pushLines(teammate.outputLines, lineBuffer.slice(0, newline));
|
|
327
|
+
lineBuffer = lineBuffer.slice(newline + 1);
|
|
328
|
+
newline = lineBuffer.indexOf('\n');
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
else if (event.type === 'usage') {
|
|
332
|
+
teammate.tokens += event.inputTokens + event.outputTokens;
|
|
333
|
+
}
|
|
334
|
+
else if (event.type === 'turn/end') {
|
|
335
|
+
if (lineBuffer.trim() !== '')
|
|
336
|
+
pushLines(teammate.outputLines, lineBuffer);
|
|
337
|
+
lineBuffer = '';
|
|
338
|
+
settle(teammate, event.reason, lastError.get(teammate.name));
|
|
339
|
+
}
|
|
340
|
+
else if (event.type === 'error') {
|
|
341
|
+
lastError.set(teammate.name, event.message);
|
|
342
|
+
}
|
|
343
|
+
forwardSubagent();
|
|
344
|
+
},
|
|
345
|
+
}, session);
|
|
346
|
+
teammates.set(teammate.name, teammate);
|
|
347
|
+
remember(teammate);
|
|
348
|
+
// T21:新队友一上场就是 working,快照的状态面跟着失效
|
|
349
|
+
ctx.transcript.touch();
|
|
350
|
+
teammate.agent.followup(input.task);
|
|
351
|
+
// 开卡先落一张头行(事件流到达前的 0 空窗),之后每次事件原位刷新
|
|
352
|
+
forwardSubagent();
|
|
353
|
+
return teammate;
|
|
354
|
+
/** 正文行进瀑布:只留最后 8 行,瀑布永远显示「最新发生的事」。 */
|
|
355
|
+
function pushLines(pool, line) {
|
|
356
|
+
const trimmed = line.trim();
|
|
357
|
+
if (trimmed === '')
|
|
358
|
+
return;
|
|
359
|
+
pool.push(trimmed);
|
|
360
|
+
if (pool.length > 8)
|
|
361
|
+
pool.splice(0, pool.length - 8);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* 把队友的当前快照转发给父会话的内联卡。只在父会话正被查看时投递——
|
|
365
|
+
* 转录是「当前查看会话」的那一份,往里折别家会话的卡就是串台;切回时
|
|
366
|
+
* 转录插件按名册种回头行卡,之后的转发接上原位刷新。
|
|
367
|
+
*/
|
|
368
|
+
function forwardSubagent() {
|
|
369
|
+
if (ctx.session.current() !== teammate.parentSession)
|
|
370
|
+
return;
|
|
371
|
+
ctx.transcript.emit({
|
|
372
|
+
type: 'subagent',
|
|
373
|
+
row: {
|
|
374
|
+
name: teammate.name,
|
|
375
|
+
role: teammate.role,
|
|
376
|
+
task: teammate.task,
|
|
377
|
+
state: teammate.state,
|
|
378
|
+
model: teammate.badge.model ?? ctx.llm.model,
|
|
379
|
+
rounds: teammate.rounds,
|
|
380
|
+
toolCalls: teammate.toolCalls,
|
|
381
|
+
startedAt: teammate.startedAt,
|
|
382
|
+
...(teammate.finishedAt !== undefined ? { finishedAt: teammate.finishedAt } : {}),
|
|
383
|
+
...(teammate.lastTool !== undefined ? { lastTool: { ...teammate.lastTool } } : {}),
|
|
384
|
+
...(teammate.outputLines.length > 0 ? { outputLines: [...teammate.outputLines] } : {}),
|
|
385
|
+
...(teammate.tokens > 0 ? { tokens: teammate.tokens } : {}),
|
|
386
|
+
...(teammate.error !== undefined ? { error: teammate.error } : {}),
|
|
387
|
+
file: teammate.session.filePath,
|
|
388
|
+
},
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/** 队友报错文本暂存(emit 的 error 事件比 turn/end 早一步)。 */
|
|
393
|
+
const lastError = new Map();
|
|
394
|
+
/** 后台队友干完,把汇报交给派它的那一方。 */
|
|
395
|
+
const reportHome = (teammate) => {
|
|
396
|
+
const state = teammate.state === 'idle' ? '已完成' : teammate.state === 'stopped' ? '已停止' : '已失败';
|
|
397
|
+
const body = teammate.state === 'failed'
|
|
398
|
+
? `(它失败了:${teammate.error ?? '未知错误'})`
|
|
399
|
+
: teammate.lastText === ''
|
|
400
|
+
? '(它没留下文字结论)'
|
|
401
|
+
: teammate.lastText;
|
|
402
|
+
const notice = `${TEAMMATE_REPORT_OPEN}from="${teammate.name}" role="${teammate.role}" state="${state}">
|
|
403
|
+
派给它的任务:${teammate.task}
|
|
404
|
+
它的汇报:
|
|
405
|
+
${body}
|
|
406
|
+
</teammate-report>`;
|
|
407
|
+
if (teammate.parent !== LEAD) {
|
|
408
|
+
// 派它的是另一个队友:直接投进它的信箱并叫醒它
|
|
409
|
+
const parent = teammates.get(teammate.parent);
|
|
410
|
+
if (parent !== undefined) {
|
|
411
|
+
inboxAppend(parent.name, notice);
|
|
412
|
+
parent.agent.followup(notice, undefined, 'notice');
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
const line = `队友 ${teammate.name},角色 ${teammate.role},${state}`;
|
|
417
|
+
const live = ctx.session.current() === teammate.parentSession;
|
|
418
|
+
// 0.6.48 常驻多 agent:父会话正被查看、或它的 agent 还常驻(后台跑着/刚切走),
|
|
419
|
+
// 汇报都投给那个 agent(跑动中进收件箱,闲置的唤起一轮后台回合);已经收摊的
|
|
420
|
+
// 才写文件等用户回去看到——不打断也不抢跑。
|
|
421
|
+
const parentResident = ctx.agent.hasAgent(teammate.parentSession.meta.id);
|
|
422
|
+
if (config.notify === 'auto' && (live || parentResident)) {
|
|
423
|
+
// 队友汇报是机器发起的唤醒:跑动中入箱时标 notice,界面画在输入框上方的
|
|
424
|
+
// 只读通知条(不是输入框下方的用户队列条),不给人编辑 / 撤掉 / 插话。
|
|
425
|
+
ctx.agent.followup(notice, undefined, teammate.parentSession.meta.id, 'notice');
|
|
426
|
+
ctx.transcript.system(`${line},汇报已${live ? '并入下一轮' : '投进后台会话'}`);
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
// 静默,或者父会话的 agent 已收摊:话写进它所属的那个会话文件,
|
|
430
|
+
// 等用户回到那个会话再说话时模型自然看到,不打断也不抢跑。
|
|
431
|
+
teammate.parentSession.appendUser(notice);
|
|
432
|
+
ctx.transcript.system(live
|
|
433
|
+
? `${line},汇报已写入会话,下一条消息时模型会看到`
|
|
434
|
+
: `${line},汇报写入了派出它的会话`);
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
// ── 侧栏要的服务 ────────────────────────────────────────────────────────
|
|
438
|
+
// 队友清单、只读查看与两条管理通道:UI 因此不必知道队友文件放在哪,
|
|
439
|
+
// 插件关着时这个服务也不存在。
|
|
440
|
+
const teamService = {
|
|
441
|
+
list: () => {
|
|
442
|
+
const views = [];
|
|
443
|
+
for (const record of readRoster()) {
|
|
444
|
+
// 在队的队友以内存为准(轮数、状态都在动),收工的以名册为准
|
|
445
|
+
const live = teammates.get(record.name);
|
|
446
|
+
const finishedAt = live?.finishedAt ?? record.finishedAt;
|
|
447
|
+
// 出生会话同理:在队的问内存里那个会话对象,收工的问名册(老记录没有这一项)
|
|
448
|
+
const sessionId = live?.parentSession.meta.id ?? record.sessionId;
|
|
449
|
+
views.push({
|
|
450
|
+
name: record.name,
|
|
451
|
+
role: record.role,
|
|
452
|
+
// 本进程里它并不活着,却按名册残留报「working」就是撒谎(上次进程没
|
|
453
|
+
// settle 就退了)——僵尸读作 stopped;远程待命的双进程共享名册,
|
|
454
|
+
// 所以只修读路径、不做启动清写,避免误标宿主进程的活队友。
|
|
455
|
+
state: live !== undefined ? live.state : record.state === 'working' ? 'stopped' : record.state,
|
|
456
|
+
task: record.task,
|
|
457
|
+
file: live === undefined ? record.file : live.session.filePath,
|
|
458
|
+
parent: record.parent,
|
|
459
|
+
depth: record.depth,
|
|
460
|
+
rounds: live === undefined ? record.rounds : live.rounds,
|
|
461
|
+
startedAt: record.startedAt,
|
|
462
|
+
...(finishedAt === undefined ? {} : { finishedAt }),
|
|
463
|
+
...(sessionId === undefined ? {} : { sessionId }),
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
return views.sort((a, b) => b.startedAt - a.startedAt);
|
|
467
|
+
},
|
|
468
|
+
peek: async (file) => {
|
|
469
|
+
const resolved = resolve(file);
|
|
470
|
+
if (!resolved.startsWith(resolve(teammateRoot()))) {
|
|
471
|
+
throw new Error('这里只能看队友的运行记录(其它会话请在左侧打开)');
|
|
472
|
+
}
|
|
473
|
+
// 只读:载入内存重放,不往那个文件写任何东西(也不拿写租约——队友可能正活着写它)
|
|
474
|
+
const session = Session.load(resolved, true, { lease: false });
|
|
475
|
+
const replay = new Transcript();
|
|
476
|
+
replay.replayHistory(session.messages, session.toolErrors, session.fileChanges);
|
|
477
|
+
return [...replay.entries, ...replay.liveEntries()];
|
|
478
|
+
},
|
|
479
|
+
// 用户从界面上管理队友的两条通道:与模型用的 subagent 工具走同一段逻辑,
|
|
480
|
+
// 只是署名换成 user(队友信箱里看得出这句话是人说的);
|
|
481
|
+
// 名字不存在时返回的那句话本身就是给用户看的错误说明。
|
|
482
|
+
stop: async (name) => stopTeammate(name, 'stop'),
|
|
483
|
+
message: async (name, text) => messageTeammate(name, text, 'user'),
|
|
484
|
+
remove: async (name) => {
|
|
485
|
+
// 还在干活的先停止(文件正被流式写入,删了也会被重建);收工的才许移除
|
|
486
|
+
const live = teammates.get(name);
|
|
487
|
+
if (live !== undefined && live.state === 'working') {
|
|
488
|
+
return `队友「${name}」还在干活:先停止,再从名册移除。`;
|
|
489
|
+
}
|
|
490
|
+
const record = readRoster().find((entry) => entry.name === name);
|
|
491
|
+
if (live === undefined && record === undefined)
|
|
492
|
+
return `名册里没有叫「${name}」的队友。`;
|
|
493
|
+
teammates.delete(name);
|
|
494
|
+
writeRoster(readRoster().filter((entry) => entry.name !== name));
|
|
495
|
+
// 运行记录文件一并删:它只在名册里可达,留着就是孤儿。只认 teammateRoot 下的路径,
|
|
496
|
+
// 删不动(被占用等)不算失败——名册已经摘掉,孤儿文件不影响任何列表。
|
|
497
|
+
const file = live?.session.filePath ?? record?.file;
|
|
498
|
+
let removedFile = false;
|
|
499
|
+
if (typeof file === 'string' && file !== '') {
|
|
500
|
+
const resolvedFile = resolve(file);
|
|
501
|
+
if (resolvedFile.startsWith(resolve(teammateRoot()))) {
|
|
502
|
+
try {
|
|
503
|
+
// rmSync 的 force 对不存在的文件也算成功:如实报告文件本来就在不在
|
|
504
|
+
const existed = existsSync(resolvedFile);
|
|
505
|
+
rmSync(resolvedFile, { force: true });
|
|
506
|
+
rmSync(`${resolvedFile}.lock`, { force: true });
|
|
507
|
+
removedFile = existed;
|
|
508
|
+
}
|
|
509
|
+
catch {
|
|
510
|
+
// 文件被占用:下次同位置的记录不冲突(uuid 命名),孤儿文件无害
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
// T21:队友名册进了快照的跨会话状态面,摘掉也要让侧栏/面板立刻知道
|
|
515
|
+
ctx.transcript.touch();
|
|
516
|
+
return removedFile
|
|
517
|
+
? `已把「${name}」从名册移除,运行记录一并删除。`
|
|
518
|
+
: `已把「${name}」从名册移除(它的运行记录文件不在了,跳过删除)。`;
|
|
519
|
+
},
|
|
520
|
+
};
|
|
521
|
+
ctx.provide('team', teamService);
|
|
522
|
+
// ── 只读代码审查通道(T18)─────────────────────────────────────────────
|
|
523
|
+
// /review 的升级路径:派一个工牌被强制压到只读交集的队友(工具 = read/glob/grep,
|
|
524
|
+
// 审批 = forbid,与角色文件怎么改无关),后台审查,findings 以 <review-findings>
|
|
525
|
+
// 包裹写回发起会话——渲染层解析成卡片,主会话不吃模型轮。
|
|
526
|
+
const READONLY_TOOLS = ['read', 'glob', 'grep'];
|
|
527
|
+
const spawnReviewer = (request) => {
|
|
528
|
+
const parentSession = ctx.session.current();
|
|
529
|
+
const working = busyFor(parentSession.meta.id);
|
|
530
|
+
if (working.length >= config.maxTeammates) {
|
|
531
|
+
return {
|
|
532
|
+
ok: false,
|
|
533
|
+
reason: `正在干活的队友已到上限 ${config.maxTeammates} 个(${working.map((entry) => entry.name).join('、')}),等一个收工再 /review`,
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
// 角色文件被用户删掉也照常可审:从出厂定义就地取(不落盘);无论来自哪个文件,
|
|
537
|
+
// 工牌都再压一次只读交集——审查通道的「天然安全」不依赖用户配置。
|
|
538
|
+
const base = findRole('reviewer') ?? builtinRole('reviewer');
|
|
539
|
+
if (base === null)
|
|
540
|
+
return { ok: false, reason: 'reviewer 角色定义不可用(内置角色缺失)' };
|
|
541
|
+
const role = { ...base, tools: [...READONLY_TOOLS], approval: 'forbid' };
|
|
542
|
+
const teammate = startTeammate({
|
|
543
|
+
name: uniqueName('reviewer'),
|
|
544
|
+
role,
|
|
545
|
+
task: reviewMessage(request, request.focus),
|
|
546
|
+
caller: { name: LEAD, depth: 0, background: true },
|
|
547
|
+
background: true,
|
|
548
|
+
seed: null,
|
|
549
|
+
parentSession,
|
|
550
|
+
});
|
|
551
|
+
void waitForIdle(teammate).then(() => deliverReview(teammate));
|
|
552
|
+
return { ok: true, name: teammate.name };
|
|
553
|
+
};
|
|
554
|
+
/** 审查收工:findings(或失败原因)写进发起会话,渲染层认 <review-findings> 标记出卡。 */
|
|
555
|
+
const deliverReview = (teammate) => {
|
|
556
|
+
const state = teammate.state === 'idle' ? '已完成' : teammate.state === 'stopped' ? '已停止' : '已失败';
|
|
557
|
+
const body = teammate.state === 'failed'
|
|
558
|
+
? `审查没有完成:${teammate.error ?? '未知错误'}`
|
|
559
|
+
: teammate.state === 'stopped'
|
|
560
|
+
? '审查被停止,没有交回结论。'
|
|
561
|
+
: teammate.lastText === ''
|
|
562
|
+
? '审查没有留下文字结论。'
|
|
563
|
+
: teammate.lastText;
|
|
564
|
+
const notice = `${REVIEW_FINDINGS_OPEN}teammate="${teammate.name}" state="${state}">\n${body}\n</review-findings>`;
|
|
565
|
+
const line = `审查队友 ${teammate.name},${state}`;
|
|
566
|
+
teammate.parentSession.appendUser(notice);
|
|
567
|
+
const live = ctx.session.current() === teammate.parentSession;
|
|
568
|
+
ctx.transcript.system(live ? `${line},findings 已写进会话` : `${line},findings 写入了派出它的会话`);
|
|
569
|
+
ctx.transcript.touch();
|
|
570
|
+
};
|
|
571
|
+
const reviewService = { spawn: spawnReviewer };
|
|
572
|
+
ctx.provide('review', reviewService);
|
|
573
|
+
// ── 模型侧工具 ──────────────────────────────────────────────────────────
|
|
574
|
+
function uniqueName(role) {
|
|
575
|
+
// 收工队友的名字也占着(名册里),不然两次启动会撞名
|
|
576
|
+
const remembered = new Set(readRoster().map((entry) => entry.name));
|
|
577
|
+
for (let index = 1; index < 100; index += 1) {
|
|
578
|
+
const candidate = `${role}-${index}`;
|
|
579
|
+
if (!teammates.has(candidate) && !remembered.has(candidate))
|
|
580
|
+
return candidate;
|
|
581
|
+
}
|
|
582
|
+
return `${role}-${Date.now()}`;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* `subagent` 的 interrupt/stop 与界面管理通道(TeamService.stop)共用的那一条。
|
|
586
|
+
* 两条路的话术刻意保持一字不差:模型与用户看到的是同一件事。
|
|
587
|
+
*/
|
|
588
|
+
function stopTeammate(name, mode) {
|
|
589
|
+
const teammate = teammates.get(name);
|
|
590
|
+
if (teammate === undefined)
|
|
591
|
+
return `没有叫 ${name} 的队友(subagent list 看现役名单)`;
|
|
592
|
+
teammate.agent.cancel();
|
|
593
|
+
if (mode === 'stop')
|
|
594
|
+
teammates.delete(name);
|
|
595
|
+
return `${name} ${mode === 'interrupt' ? '这一轮被打断了(信箱里的话还在,可以再传话叫醒它)' : '被收掉了'}`;
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* `subagent` 的 message 与界面传话通道(TeamService.message)共用的那一条。
|
|
599
|
+
* @param from - 署名:模型派话是派它的那一方,用户传话是 'user'。
|
|
600
|
+
*/
|
|
601
|
+
function messageTeammate(name, text, from) {
|
|
602
|
+
const trimmed = text.trim();
|
|
603
|
+
if (trimmed === '')
|
|
604
|
+
return 'message 要带上 text(想传的话)';
|
|
605
|
+
const teammate = teammates.get(name);
|
|
606
|
+
const wrapped = `<message from="${from}"> ${trimmed} </message>`;
|
|
607
|
+
inboxAppend(name === '' ? 'unknown' : name, wrapped);
|
|
608
|
+
if (teammate === undefined)
|
|
609
|
+
return `没有叫 ${name} 的队友,话写进了它的信箱(${join(ctx.settings.about().home, 'team', 'inbox')})但没人会读`;
|
|
610
|
+
teammate.agent.followup(wrapped);
|
|
611
|
+
return `话已投给 ${name}${teammate.state === 'working' ? '(它正在干,会在这轮结束后看到)' : '(已把它叫醒)'}`;
|
|
612
|
+
}
|
|
613
|
+
async function runSubagent(args, runCtx, caller) {
|
|
614
|
+
const action = String(args.action ?? '');
|
|
615
|
+
const roster = listRoles();
|
|
616
|
+
// 名单按会话隔离(对照 dsh 的 parentSession 过滤):本会话只能看见自己派出的队友,
|
|
617
|
+
// 别的会话的在队名单不外漏;跨会话管理请回到派出它的那个会话。
|
|
618
|
+
const currentId = ctx.session.current().meta.id;
|
|
619
|
+
const mine = [...teammates.values()].filter((entry) => entry.parentSession.meta.id === currentId);
|
|
620
|
+
if (action === 'list') {
|
|
621
|
+
const lines = mine.map((entry) => `- ${entry.name}(角色 ${entry.role},${entry.state},第 ${entry.rounds} 轮,${entry.toolCalls} 次工具调用)派给它的任务:${entry.task.slice(0, 60)}`);
|
|
622
|
+
const roles = roster.map((role) => `- ${role.name}${role.enabled ? '' : '(已停用)'}:${role.description || '(没写 description)'}`).join('\n');
|
|
623
|
+
return lines.length === 0
|
|
624
|
+
? `本会话没有在队或收工的队友。\n\n可用角色:\n${roles}`
|
|
625
|
+
: `本会话在队/收工的队友:\n${lines.join('\n')}\n\n可用角色:\n${roles}`;
|
|
626
|
+
}
|
|
627
|
+
if (action === 'interrupt' || action === 'stop') {
|
|
628
|
+
return stopTeammate(String(args.name ?? ''), action);
|
|
629
|
+
}
|
|
630
|
+
if (action === 'message') {
|
|
631
|
+
return messageTeammate(String(args.name ?? ''), String(args.text ?? ''), caller.name);
|
|
632
|
+
}
|
|
633
|
+
if (action !== 'spawn') {
|
|
634
|
+
return `不认识的 action「${action}」。要用的值:spawn / list / message / interrupt / stop`;
|
|
635
|
+
}
|
|
636
|
+
if (caller.depth >= config.maxDepth) {
|
|
637
|
+
return `你在第 ${caller.depth} 层,设置只允许到 ${config.maxDepth} 层,不能再往下派队友(要放开去设置「子智能体」调「允许层数」)`;
|
|
638
|
+
}
|
|
639
|
+
const roleName = String(args.role ?? '').trim();
|
|
640
|
+
const role = findRole(roleName);
|
|
641
|
+
if (role === null) {
|
|
642
|
+
const available = roster.filter((entry) => entry.enabled).map((entry) => entry.name);
|
|
643
|
+
return `角色 ${roleName || '(没填)'} 不可用。可用角色:${available.join('、') || '(无,去 ' + DSC_AGENTS_DIR + ' 建一个)'}${roster.some((entry) => entry.name === roleName && !entry.enabled) ? `;${roleName} 存在但被停用了,在设置「子智能体」里打开` : ''}`;
|
|
644
|
+
}
|
|
645
|
+
const task = String(args.task ?? '').trim();
|
|
646
|
+
if (task.length < 8)
|
|
647
|
+
return '任务描述太短:队友看不到你和用户的对话,请把背景、目标、交付格式写清楚';
|
|
648
|
+
const working = busyFor(currentId);
|
|
649
|
+
if (working.length >= config.maxTeammates) {
|
|
650
|
+
return `本会话正在干活的队友已到上限 ${config.maxTeammates} 个(${working.map((entry) => entry.name).join('、')})。等一个收工,或去设置「子智能体」里提高上限`;
|
|
651
|
+
}
|
|
652
|
+
// 收工的队友留着可以被追问,但攒太多就把最老的挤出名单(磁盘上的运行记录不动)
|
|
653
|
+
const finished = [...teammates.values()].filter((entry) => entry.state !== 'working');
|
|
654
|
+
if (finished.length > MAX_LISTED_FINISHED) {
|
|
655
|
+
for (const entry of finished
|
|
656
|
+
.sort((a, b) => (a.finishedAt ?? a.startedAt) - (b.finishedAt ?? b.startedAt))
|
|
657
|
+
.slice(0, finished.length - MAX_LISTED_FINISHED)) {
|
|
658
|
+
teammates.delete(entry.name);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
const requested = String(args.name ?? '').trim();
|
|
662
|
+
if (requested !== '' && !NAME_OK.test(requested)) {
|
|
663
|
+
return `队友名「${requested}」不合法:只能用小写字母、数字、连字符`;
|
|
664
|
+
}
|
|
665
|
+
const name = requested === '' ? uniqueName(role.name) : requested;
|
|
666
|
+
if (teammates.has(name))
|
|
667
|
+
return `队友名 ${name} 已经在用,换一个`;
|
|
668
|
+
const context = String(args.context ?? 'fresh');
|
|
669
|
+
let seed = null;
|
|
670
|
+
if (context === 'fork') {
|
|
671
|
+
const parent = ctx.session.current();
|
|
672
|
+
seed = parent.persisted ? forkSeedLines(parent.filePath) : null;
|
|
673
|
+
if (seed === null) {
|
|
674
|
+
return `带不上父会话的内容:这个会话还没有一个完整回合(它得先完整回答过一次),改用 context="fresh" 把背景写进任务描述`;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
else if (context !== 'fresh') {
|
|
678
|
+
return `不认识的 context「${context}」。要用的值:fresh / fork`;
|
|
679
|
+
}
|
|
680
|
+
const background = args.background === true || args.background === 'true';
|
|
681
|
+
const teammate = startTeammate({
|
|
682
|
+
name,
|
|
683
|
+
role,
|
|
684
|
+
task,
|
|
685
|
+
caller,
|
|
686
|
+
background,
|
|
687
|
+
seed,
|
|
688
|
+
parentSession: ctx.session.current(),
|
|
689
|
+
});
|
|
690
|
+
if (!background) {
|
|
691
|
+
// 用户取消这一轮就等于把队友也停下:先挂监听,再等它空下来
|
|
692
|
+
const onStop = () => teammate.agent.cancel();
|
|
693
|
+
runCtx.signal.addEventListener('abort', onStop, { once: true });
|
|
694
|
+
await waitForIdle(teammate);
|
|
695
|
+
runCtx.signal.removeEventListener('abort', onStop);
|
|
696
|
+
const head = `${teammate.name}(${teammate.role})${teammate.state === 'idle' ? '干完了' : teammate.state === 'stopped' ? '被打断' : '失败'}:第 ${teammate.rounds} 轮、${teammate.toolCalls} 次工具调用。运行记录:${teammate.session.filePath}`;
|
|
697
|
+
return teammate.lastText === '' && teammate.state !== 'idle'
|
|
698
|
+
? `${head}\n${teammate.error ?? '它没留下文字结论'}`
|
|
699
|
+
: `${head}\n\n${teammate.lastText === '' ? '(它没留下文字结论)' : teammate.lastText}`;
|
|
700
|
+
}
|
|
701
|
+
void waitForIdle(teammate).then(() => reportHome(teammate));
|
|
702
|
+
return `已派给 ${teammate.name}(角色 ${teammate.role},${teammate.badge.tools === null ? '不限工具' : `工具 ${teammate.badge.tools.join('、')}`})。它在后台干,不用等也不用问:干完我会把汇报接进来。你现在可以继续做别的,或者再派一个。`;
|
|
703
|
+
}
|
|
704
|
+
const subagentTool = () => ({
|
|
705
|
+
name: 'subagent',
|
|
706
|
+
description: '把一件可以独立完成的活派给一个有明确授权的队友(角色见 ~/.dsc/agents),或者给在队队友传话、打断它。' +
|
|
707
|
+
'background=true 时立刻返回,它干完后汇报会自己接进你的下一轮;background=false 时你这一轮会等它的结果。',
|
|
708
|
+
parameters: {
|
|
709
|
+
type: 'object',
|
|
710
|
+
properties: {
|
|
711
|
+
action: { type: 'string', enum: ['spawn', 'list', 'message', 'interrupt', 'stop'], description: '要做什么' },
|
|
712
|
+
role: { type: 'string', description: 'spawn 必填:角色名,例如 explorer / writer / critic' },
|
|
713
|
+
task: { type: 'string', description: 'spawn 必填:交给它的活。队友看不到你和用户的对话,把背景、目标、交付格式写全' },
|
|
714
|
+
name: { type: 'string', description: '队友名;不填自动生成「角色名-序号」。message/interrupt/stop 用它指定对象' },
|
|
715
|
+
context: { type: 'string', enum: ['fresh', 'fork'], description: 'fresh = 只知道这条任务;fork = 额外带上父会话到上一个完整回合为止的内容' },
|
|
716
|
+
background: { type: 'boolean', description: 'true = 后台干(推荐,可并行多个);false = 这一轮等它结果' },
|
|
717
|
+
text: { type: 'string', description: 'message 必填:要传的话' },
|
|
718
|
+
},
|
|
719
|
+
required: ['action'],
|
|
720
|
+
},
|
|
721
|
+
risk: 'read',
|
|
722
|
+
run: (args, runCtx) => runSubagent(args, runCtx, { name: LEAD, depth: 0, background: false }),
|
|
723
|
+
});
|
|
724
|
+
/** 委派开关注释:关掉时工具和名册提示一起撤下,模型看不到子智能体这件事。 */
|
|
725
|
+
let disposers = [];
|
|
726
|
+
const syncTools = () => {
|
|
727
|
+
for (const off of disposers)
|
|
728
|
+
off();
|
|
729
|
+
disposers = [];
|
|
730
|
+
if (!config.allowDelegation)
|
|
731
|
+
return;
|
|
732
|
+
disposers.push(ctx.tools.register(subagentTool()));
|
|
733
|
+
disposers.push(ctx.prompt.register('subagent', () => {
|
|
734
|
+
const roles = listRoles().filter((role) => role.enabled);
|
|
735
|
+
const lines = roles.map((role) => {
|
|
736
|
+
const tools = role.tools === null ? '不限工具' : role.tools.length === 0 ? '不带工具' : role.tools.join('/');
|
|
737
|
+
return `- ${role.name}:${role.description || '(没写 description)'}(${tools},最多 ${role.maxTurns} 轮)`;
|
|
738
|
+
});
|
|
739
|
+
return `# 子智能体
|
|
740
|
+
你可以用 subagent 工具把能独立完成的活派给队友。
|
|
741
|
+
可用角色(文件在 ${DSC_AGENTS_DIR},用户可以自己加):
|
|
742
|
+
${lines.join('\n') || '- (没有启用中的角色,先在设置「子智能体」里打开或新建)'}
|
|
743
|
+
|
|
744
|
+
派活的规矩:
|
|
745
|
+
1. 队友看不到你和用户的对话(context="fork" 只能带到上一个完整回合为止),所以任务描述里必须写清背景、目标、交付格式。
|
|
746
|
+
2. 本会话同时干活上限 ${config.maxTeammates} 个(收工的不占额度)。后台队友干完后汇报会自己接进你的下一轮,不要反复去问它好了没。
|
|
747
|
+
3. 只读角色改不了文件;要落地代码用 writer 或者你自己动手。
|
|
748
|
+
4. 派完活自己接着干别的,别闲着等。`;
|
|
749
|
+
}));
|
|
750
|
+
};
|
|
751
|
+
syncTools();
|
|
752
|
+
// ── 设置分区 ────────────────────────────────────────────────────────────
|
|
753
|
+
const fields = () => [
|
|
754
|
+
{
|
|
755
|
+
type: 'switch',
|
|
756
|
+
key: 'allowDelegation',
|
|
757
|
+
label: '允许模型自主分派任务给队友',
|
|
758
|
+
help: '关闭后 subagent 工具连同提示词一并撤下,运行中的队友会被停止。',
|
|
759
|
+
},
|
|
760
|
+
{ type: 'number', key: 'maxTeammates', label: '并行数量', min: 1, max: 8, step: 1, help: '每个会话各自的同时干活上限;已完成的队友不占额度,满了再派会被直接拒绝,不排队。' },
|
|
761
|
+
{ type: 'number', key: 'maxDepth', label: '递归层级', min: 0, max: 2, step: 1, help: '0 = 仅主会话可派队友,Lead 不可再下派;1 = Lead 可派队友,队友不可再下派。' },
|
|
762
|
+
{
|
|
763
|
+
type: 'select',
|
|
764
|
+
key: 'approval',
|
|
765
|
+
label: '队友是否可以请求授权',
|
|
766
|
+
options: [
|
|
767
|
+
{ value: 'forbid', label: '不允许,需要授权的操作直接失败并写入汇报' },
|
|
768
|
+
{ value: 'foreground', label: '仅前台队友,即正在等待结果的队友' },
|
|
769
|
+
{ value: 'ask', label: '允许,审批卡片标明请求的队友' },
|
|
770
|
+
],
|
|
771
|
+
help: '此为上限:角色文件中声明的 approval 只会更严,不会更松。',
|
|
772
|
+
},
|
|
773
|
+
{
|
|
774
|
+
type: 'select',
|
|
775
|
+
key: 'notify',
|
|
776
|
+
label: '后台队友完成后的汇报方式',
|
|
777
|
+
options: [
|
|
778
|
+
{ value: 'auto', label: '汇报自动并入 Lead 的下一轮' },
|
|
779
|
+
{ value: 'quiet', label: '仅写入会话,下次对话时模型可见' },
|
|
780
|
+
],
|
|
781
|
+
},
|
|
782
|
+
{ type: 'text', key: 'defaultModel', label: '队友默认模型', placeholder: '留空 = 跟随当前模型;形如 deepseek/deepseek-chat', help: '角色文件里写了 model 的角色用它自己的。' },
|
|
783
|
+
{ type: 'info', label: '角色目录', text: DSC_AGENTS_DIR, mono: true, copyable: true, help: `内置角色:${builtinRoleNames().join('、')}。修改文件仅影响之后创建的队友。` },
|
|
784
|
+
{ type: 'button', action: 'new-role', label: '新建示例角色', style: 'ghost', help: '在角色目录创建 starter.md 供参考修改。' },
|
|
785
|
+
];
|
|
786
|
+
const section = {
|
|
787
|
+
id: 'subagent',
|
|
788
|
+
title: '子智能体',
|
|
789
|
+
subtitle: '设置子智能体的递归层级、数量和模型',
|
|
790
|
+
order: 40,
|
|
791
|
+
fields,
|
|
792
|
+
values: () => ({
|
|
793
|
+
allowDelegation: config.allowDelegation,
|
|
794
|
+
maxTeammates: config.maxTeammates,
|
|
795
|
+
maxDepth: config.maxDepth,
|
|
796
|
+
approval: config.approval,
|
|
797
|
+
notify: config.notify,
|
|
798
|
+
defaultModel: config.defaultModel,
|
|
799
|
+
}),
|
|
800
|
+
// 契约:save 返回字符串 = 失败原因;action 返回字符串 = 完成后的提示文案,失败直接抛
|
|
801
|
+
save: (key, value) => {
|
|
802
|
+
switch (key) {
|
|
803
|
+
case 'allowDelegation':
|
|
804
|
+
applyConfig({ allowDelegation: value === true || value === 'true' });
|
|
805
|
+
break;
|
|
806
|
+
case 'maxTeammates':
|
|
807
|
+
applyConfig({ maxTeammates: Number(value) });
|
|
808
|
+
break;
|
|
809
|
+
case 'maxDepth':
|
|
810
|
+
applyConfig({ maxDepth: Number(value) });
|
|
811
|
+
break;
|
|
812
|
+
case 'approval': {
|
|
813
|
+
const next = String(value);
|
|
814
|
+
if (next !== 'forbid' && next !== 'ask' && next !== 'foreground') {
|
|
815
|
+
return `不认识的值 ${String(value)}`;
|
|
816
|
+
}
|
|
817
|
+
applyConfig({ approval: next });
|
|
818
|
+
break;
|
|
819
|
+
}
|
|
820
|
+
case 'notify':
|
|
821
|
+
applyConfig({ notify: String(value) === 'quiet' ? 'quiet' : 'auto' });
|
|
822
|
+
break;
|
|
823
|
+
case 'defaultModel': {
|
|
824
|
+
const text = String(value).trim();
|
|
825
|
+
if (text !== '' && !text.includes('/')) {
|
|
826
|
+
return '要写成「端点名/模型名」,例如 deepseek/deepseek-chat;留空表示跟随当前模型';
|
|
827
|
+
}
|
|
828
|
+
applyConfig({ defaultModel: text });
|
|
829
|
+
break;
|
|
830
|
+
}
|
|
831
|
+
default:
|
|
832
|
+
return `这个分区没有这项:${key}`;
|
|
833
|
+
}
|
|
834
|
+
// 开关会影响工具与名册提示在不在场,改完立刻重挂一次
|
|
835
|
+
syncTools();
|
|
836
|
+
},
|
|
837
|
+
action: (name) => {
|
|
838
|
+
if (name === 'new-role') {
|
|
839
|
+
const file = writeRole('starter', {
|
|
840
|
+
description: '我在这个角色里干什么(一句话,模型据此决定要不要派它)',
|
|
841
|
+
prompt: '把这一段改成这个角色的职责与做事步骤。它是模型看到的唯一说明书。',
|
|
842
|
+
});
|
|
843
|
+
return `已写好 ${file},改完保存就能被派活`;
|
|
844
|
+
}
|
|
845
|
+
throw new Error(`这个分区没有这个按钮:${name}`);
|
|
846
|
+
},
|
|
847
|
+
};
|
|
848
|
+
const offSection = ctx.settings.registerSection(section);
|
|
849
|
+
// ── 卸载 ────────────────────────────────────────────────────────────────
|
|
850
|
+
return () => {
|
|
851
|
+
offSection();
|
|
852
|
+
for (const off of disposers)
|
|
853
|
+
off();
|
|
854
|
+
disposers = [];
|
|
855
|
+
for (const teammate of teammates.values())
|
|
856
|
+
teammate.agent.cancel();
|
|
857
|
+
for (const teammate of teammates.values())
|
|
858
|
+
teammate.session.close();
|
|
859
|
+
teammates.clear();
|
|
860
|
+
};
|
|
861
|
+
},
|
|
862
|
+
};
|