pi-web-ui 0.117.0 → 0.118.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.
Files changed (512) hide show
  1. package/CHANGELOG.md +48 -2
  2. package/README.md +69 -138
  3. package/README.zh-CN.md +70 -179
  4. package/README.zh-TW.md +3 -1
  5. package/bin/device-hub-cli.mjs +147 -43
  6. package/bin/frp-manager.mjs +4 -80
  7. package/bin/hub-upgrade.mjs +561 -0
  8. package/bin/pi-device-hub.mjs +0 -1
  9. package/bin/pi-web-ui.mjs +56 -444
  10. package/deploy/nginx-subpath.conf +0 -33
  11. package/deploy/pi-web-ui.service +0 -20
  12. package/dist/server/agent-formatters.js +4 -38
  13. package/dist/server/agent-service-daemon.js +160 -374
  14. package/dist/server/agent-service.js +875 -2978
  15. package/dist/server/approval-audit.js +2 -23
  16. package/dist/server/approval-default-rules.js +0 -6
  17. package/dist/server/approval-rules.js +7 -105
  18. package/dist/server/ask-user-question-tool.js +1 -12
  19. package/dist/server/atomic-file.js +33 -5
  20. package/dist/server/attachment-store.js +0 -36
  21. package/dist/server/attachments.js +3 -112
  22. package/dist/server/auth-cookie.js +0 -21
  23. package/dist/server/bash-tool.js +1 -32
  24. package/dist/server/bg-servers.js +0 -96
  25. package/dist/server/browser-page-tool.js +11 -62
  26. package/dist/server/builtin-modules.js +7 -0
  27. package/dist/server/canvas/canvas-agent-tool.js +58 -47
  28. package/dist/server/canvas/canvas-cards.js +0 -14
  29. package/dist/server/canvas/canvas-dispatch.js +7 -4
  30. package/dist/server/canvas/canvas-orchestrator.js +167 -181
  31. package/dist/server/canvas/canvas-runtime-messages.js +30 -0
  32. package/dist/server/canvas/canvas-scheduled-task.js +0 -3
  33. package/dist/server/canvas/canvas-scheduler.js +5 -7
  34. package/dist/server/canvas/canvas-store.js +24 -35
  35. package/dist/server/canvas/canvas-validation.js +17 -14
  36. package/dist/server/canvas/canvas-workspace.js +26 -30
  37. package/dist/server/canvas/pstack-skills-data.js +0 -5
  38. package/dist/server/claim-files-tool.js +1 -15
  39. package/dist/server/claim-store.js +5 -49
  40. package/dist/server/client-id-utils.js +0 -16
  41. package/dist/server/client-state.js +6 -213
  42. package/dist/server/communicate-tool.js +0 -3
  43. package/dist/server/compact-context-tool.js +0 -30
  44. package/dist/server/compacted-history.js +0 -35
  45. package/dist/server/compaction-instructions.js +0 -13
  46. package/dist/server/compaction-markers.js +3 -76
  47. package/dist/server/compaction-state.js +0 -21
  48. package/dist/server/composer-drafts.js +0 -34
  49. package/dist/server/context-budget-runner.js +0 -11
  50. package/dist/server/context-budget.js +1 -70
  51. package/dist/server/context-evidence.js +0 -14
  52. package/dist/server/context-usage.js +0 -12
  53. package/dist/server/control-socket.js +4 -48
  54. package/dist/server/conversation-communication.js +0 -10
  55. package/dist/server/conversation-identity.js +0 -1
  56. package/dist/server/conversation-read-tool.js +0 -58
  57. package/dist/server/conversation-tool-names.js +0 -1
  58. package/dist/server/conversation-tool.js +0 -1
  59. package/dist/server/conversation-touches.js +4 -75
  60. package/dist/server/dangling-tools.js +0 -82
  61. package/dist/server/delegate-mode.js +0 -36
  62. package/dist/server/delegate-task.js +2 -28
  63. package/dist/server/device-center/approval-summary.js +0 -1
  64. package/dist/server/device-center/bot-catalog.js +0 -3
  65. package/dist/server/device-center/bot-execution.js +0 -8
  66. package/dist/server/device-center/bot-presets.js +0 -1
  67. package/dist/server/device-center/bots.js +0 -1
  68. package/dist/server/device-center/collab-service.js +1 -3
  69. package/dist/server/device-center/collab-tool.js +0 -10
  70. package/dist/server/device-center/connector.js +21 -11
  71. package/dist/server/device-center/delivery-authority.js +0 -3
  72. package/dist/server/device-center/delivery-subject.js +0 -1
  73. package/dist/server/device-center/desktop-linux.js +3 -15
  74. package/dist/server/device-center/desktop-native.js +1 -10
  75. package/dist/server/device-center/desktop-page.js +2 -3
  76. package/dist/server/device-center/desktop-setup.js +1 -3
  77. package/dist/server/device-center/desktop.js +1 -7
  78. package/dist/server/device-center/device-integration.js +1 -27
  79. package/dist/server/device-center/device-lan-access.js +403 -0
  80. package/dist/server/device-center/device-lan.js +484 -0
  81. package/dist/server/device-center/device-portals.js +0 -3
  82. package/dist/server/device-center/execution-failure.js +0 -2
  83. package/dist/server/device-center/execution-guides.js +0 -1
  84. package/dist/server/device-center/execution-instructions.js +0 -1
  85. package/dist/server/device-center/execution-settings.js +0 -1
  86. package/dist/server/device-center/execution-system-prompt.js +0 -3
  87. package/dist/server/device-center/execution-workspace.js +1 -4
  88. package/dist/server/device-center/executor.js +0 -27
  89. package/dist/server/device-center/file-sync-paths.js +0 -5
  90. package/dist/server/device-center/file-sync.js +0 -10
  91. package/dist/server/device-center/group-context-delta.js +0 -8
  92. package/dist/server/device-center/group-context-message.js +0 -14
  93. package/dist/server/device-center/group-context.js +0 -19
  94. package/dist/server/device-center/group-events.js +0 -2
  95. package/dist/server/device-center/group-plan-guard.js +1 -35
  96. package/dist/server/device-center/group-router-runtime.js +182 -0
  97. package/dist/server/device-center/group-router-worker.js +178 -0
  98. package/dist/server/device-center/group-router.js +359 -0
  99. package/dist/server/device-center/hub-auth.js +24 -2
  100. package/dist/server/device-center/hub-conversations.js +0 -12
  101. package/dist/server/device-center/hub-deliveries.js +0 -1
  102. package/dist/server/device-center/hub-integration.js +0 -8
  103. package/dist/server/device-center/hub-locks.js +1 -5
  104. package/dist/server/device-center/hub-mobile.js +147 -0
  105. package/dist/server/device-center/hub-orchestration.js +400 -0
  106. package/dist/server/device-center/hub-page.js +25 -7
  107. package/dist/server/device-center/hub-setup.js +0 -6
  108. package/dist/server/device-center/hub-transaction-log.js +0 -22
  109. package/dist/server/device-center/hub-upgrade.js +162 -0
  110. package/dist/server/device-center/hub-webhooks.js +1 -3
  111. package/dist/server/device-center/hub.js +210 -86
  112. package/dist/server/device-center/human-interaction.js +1 -4
  113. package/dist/server/device-center/integration-errors.js +0 -2
  114. package/dist/server/device-center/integration-verification.js +0 -2
  115. package/dist/server/device-center/local-hub.js +0 -2
  116. package/dist/server/device-center/local-publication.js +1 -8
  117. package/dist/server/device-center/local-verification-job.js +0 -2
  118. package/dist/server/device-center/local-verification.js +0 -1
  119. package/dist/server/device-center/local.js +267 -39
  120. package/dist/server/device-center/main.js +14 -1
  121. package/dist/server/device-center/mobile-notification-forwarder.js +292 -0
  122. package/dist/server/device-center/native-desktop/macos.js +0 -1
  123. package/dist/server/device-center/native-desktop/windows.js +0 -1
  124. package/dist/server/device-center/partition-log.js +0 -31
  125. package/dist/server/device-center/path-portal.js +42 -12
  126. package/dist/server/device-center/publication-journal.js +0 -7
  127. package/dist/server/device-center/publish-intent.js +0 -5
  128. package/dist/server/device-center/relay.js +85 -30
  129. package/dist/server/device-center/report-upload.js +0 -1
  130. package/dist/server/device-center/runtime.js +1 -18
  131. package/dist/server/device-center/store.js +13 -33
  132. package/dist/server/device-center/task-context-budget.js +0 -3
  133. package/dist/server/device-center/task-error.js +0 -1
  134. package/dist/server/device-center/task-journal.js +6 -23
  135. package/dist/server/device-center/task-outcome.js +0 -13
  136. package/dist/server/device-center/task-plan.js +0 -1
  137. package/dist/server/device-center/task-progress.js +0 -16
  138. package/dist/server/device-center/task-recovery.js +5 -88
  139. package/dist/server/device-center/task-report-outbox.js +0 -4
  140. package/dist/server/device-center/task-report.js +2 -10
  141. package/dist/server/device-center/task-scheduler.js +1 -35
  142. package/dist/server/device-center/task-settlement.js +0 -18
  143. package/dist/server/device-center/task-state.js +0 -12
  144. package/dist/server/device-center/task-workspace.js +0 -50
  145. package/dist/server/device-center/transfer-stream.js +5 -45
  146. package/dist/server/device-center/transfers.js +2 -10
  147. package/dist/server/device-center/verification-limits.js +0 -1
  148. package/dist/server/device-center/work-contract.js +1 -73
  149. package/dist/server/device-center/work-items.js +317 -0
  150. package/dist/server/device-center/workspaces.js +0 -1
  151. package/dist/server/dispatch-domain-handlers.js +190 -32
  152. package/dist/server/dispatch-plugin-handlers.js +2 -19
  153. package/dist/server/dsh/dsh-agent-service.js +69 -599
  154. package/dist/server/dsh/dsh-client.js +7 -111
  155. package/dist/server/dsh/dsh-market-service.js +4 -25
  156. package/dist/server/dsh/dsh-serialize.js +0 -49
  157. package/dist/server/dsh/dsh-sessions.js +0 -37
  158. package/dist/server/dsh/dsh-usage.js +0 -37
  159. package/dist/server/dsh/preset-clones.js +1 -65
  160. package/dist/server/dsh/runtime/custom-prompt.mjs +0 -14
  161. package/dist/server/dsh/runtime/goal-rpc.mjs +7 -176
  162. package/dist/server/dsh/runtime/launcher.mjs +2 -53
  163. package/dist/server/dsh/runtime/override.patch.yml +0 -29
  164. package/dist/server/dsh/runtime/runtime-root.mjs +0 -54
  165. package/dist/server/durable/durable-agent-service.js +5 -23
  166. package/dist/server/durable/durable-driver.js +12 -73
  167. package/dist/server/durable/durable-event-projector.js +1 -50
  168. package/dist/server/durable/durable-loader.js +0 -12
  169. package/dist/server/durable/durable-models.js +11 -80
  170. package/dist/server/durable/durable-storage.js +1 -17
  171. package/dist/server/durable/durable-tools.js +2 -20
  172. package/dist/server/durable/index.js +0 -3
  173. package/dist/server/edit-soft-tool.js +2 -81
  174. package/dist/server/engine-capabilities.js +0 -13
  175. package/dist/server/engine-catalog.js +74 -0
  176. package/dist/server/engine-cli.js +89 -0
  177. package/dist/server/engine-probe.js +35 -217
  178. package/dist/server/ensure-bash.js +2 -28
  179. package/dist/server/eval-tool.js +1 -50
  180. package/dist/server/evidence-tool-hooks.js +0 -2
  181. package/dist/server/file-archives.js +0 -10
  182. package/dist/server/file-save.js +1 -12
  183. package/dist/server/file-transfer-routes.js +0 -11
  184. package/dist/server/files-service.js +18 -271
  185. package/dist/server/global-loader.js +9 -89
  186. package/dist/server/goal-evidence.js +1 -35
  187. package/dist/server/goal-review-gate.js +0 -58
  188. package/dist/server/goal-service.js +19 -422
  189. package/dist/server/hashline-engine.js +8 -112
  190. package/dist/server/host-guard.js +0 -24
  191. package/dist/server/host-metrics.js +0 -6
  192. package/dist/server/http-proxy.js +1 -7
  193. package/dist/server/i18n.js +5 -72
  194. package/dist/server/icon-svg.js +0 -15
  195. package/dist/server/index.js +177 -680
  196. package/dist/server/json-utils.js +0 -12
  197. package/dist/server/launch-origin.js +0 -44
  198. package/dist/server/left-panel-running.js +0 -9
  199. package/dist/server/load-timing.js +1 -4
  200. package/dist/server/load-tools-tool.js +0 -20
  201. package/dist/server/locales.js +1 -46
  202. package/dist/server/lsp-tool.js +13 -126
  203. package/dist/server/managed.js +0 -48
  204. package/dist/server/marker-service.js +1 -22
  205. package/dist/server/markers/builtins/action.js +0 -19
  206. package/dist/server/markers/builtins/notify.js +1 -9
  207. package/dist/server/markers/builtins/rename.js +0 -13
  208. package/dist/server/markers/index.js +0 -3
  209. package/dist/server/markers/marker.js +0 -13
  210. package/dist/server/markers/registry.js +0 -3
  211. package/dist/server/markers/store.js +1 -12
  212. package/dist/server/market-service.js +7 -43
  213. package/dist/server/mcp-agent-tool.js +0 -10
  214. package/dist/server/mcp-bridge.js +6 -138
  215. package/dist/server/mcp-hot-reload.js +0 -25
  216. package/dist/server/mcp-manager.js +2 -44
  217. package/dist/server/mcp-oauth-login.js +0 -2
  218. package/dist/server/mcp-oauth-ui.js +1 -4
  219. package/dist/server/mcp-oauth.js +5 -79
  220. package/dist/server/mcp-project-runtime.js +0 -4
  221. package/dist/server/message-deletion.js +0 -2
  222. package/dist/server/message-entry-resolver.js +0 -8
  223. package/dist/server/message-window.js +0 -71
  224. package/dist/server/mobile-notification-events.js +16 -0
  225. package/dist/server/mobile-origin.js +79 -0
  226. package/dist/server/mobile-push.js +523 -0
  227. package/dist/server/model-admin.js +19 -358
  228. package/dist/server/model-enrich.js +0 -19
  229. package/dist/server/model-resolver.js +2 -61
  230. package/dist/server/native-cli-discovery.js +115 -0
  231. package/dist/server/native-cli-model.js +71 -0
  232. package/dist/server/native-cli-references.js +214 -0
  233. package/dist/server/native-cli-remote-cleanup.js +58 -0
  234. package/dist/server/native-cli-remote-files.js +282 -0
  235. package/dist/server/native-cli-routes.js +68 -0
  236. package/dist/server/native-cli-runtime.js +1 -0
  237. package/dist/server/native-cli-session-hooks.js +170 -0
  238. package/dist/server/native-cli-session.js +585 -0
  239. package/dist/server/native-cli-state.js +82 -0
  240. package/dist/server/native-cli.js +210 -0
  241. package/dist/server/net-guard.js +9 -71
  242. package/dist/server/office-parse.js +0 -50
  243. package/dist/server/orphan-manager.js +0 -18
  244. package/dist/server/patch-bash-process.js +0 -4
  245. package/dist/server/patch-executable-lookup.js +0 -77
  246. package/dist/server/patch-node-pty.js +3 -43
  247. package/dist/server/patch-remote-catalog.js +1 -32
  248. package/dist/server/patch-tool.js +0 -15
  249. package/dist/server/payload-limits.js +0 -5
  250. package/dist/server/pending-question.js +0 -5
  251. package/dist/server/permission-preset.js +4 -33
  252. package/dist/server/persona-chain.js +0 -26
  253. package/dist/server/pkg-info.js +1 -17
  254. package/dist/server/plan-manager.js +2 -49
  255. package/dist/server/plan-mode.js +0 -97
  256. package/dist/server/plan-update-tool.js +1 -15
  257. package/dist/server/plugin-api-catalog.js +6 -4
  258. package/dist/server/plugin-assets.js +1 -35
  259. package/dist/server/plugin-bundled.js +68 -0
  260. package/dist/server/plugin-catalog-sync.js +0 -37
  261. package/dist/server/plugin-catalog.js +13 -67
  262. package/dist/server/plugin-chat-attachments.js +0 -1
  263. package/dist/server/plugin-conversation-view.js +0 -20
  264. package/dist/server/plugin-dom.js +1 -23
  265. package/dist/server/plugin-facilities.js +4 -115
  266. package/dist/server/plugin-grants.js +2 -90
  267. package/dist/server/plugin-install-spec.js +0 -43
  268. package/dist/server/plugin-installer.js +34 -75
  269. package/dist/server/plugin-llm.js +4 -38
  270. package/dist/server/plugin-manifest-validate.js +0 -31
  271. package/dist/server/plugin-permissions.js +1 -24
  272. package/dist/server/plugin-project.js +7 -129
  273. package/dist/server/plugin-removal.js +1 -8
  274. package/dist/server/plugin-schedule.js +1 -38
  275. package/dist/server/plugin-secrets.js +3 -16
  276. package/dist/server/plugin-tool-guard.js +1 -28
  277. package/dist/server/plugin-ui-slots.js +0 -4
  278. package/dist/server/plugin-updater.js +15 -90
  279. package/dist/server/plugins.js +71 -619
  280. package/dist/server/present-files-tool.js +0 -57
  281. package/dist/server/preset-fields.js +9 -62
  282. package/dist/server/preset-plugin-dependencies.js +0 -2
  283. package/dist/server/preset-share.js +3 -172
  284. package/dist/server/process-utils.js +4 -80
  285. package/dist/server/prompt-assembler.js +2 -30
  286. package/dist/server/prompt-base-store.js +0 -47
  287. package/dist/server/prompt-composer.js +21 -98
  288. package/dist/server/prompt-templates.js +0 -2
  289. package/dist/server/protocol-version.js +1 -11
  290. package/dist/server/protocol.js +0 -5
  291. package/dist/server/queue-modes.js +0 -3
  292. package/dist/server/queue-utils.js +0 -40
  293. package/dist/server/quick-ask-context.js +384 -0
  294. package/dist/server/quick-ask-settings.js +34 -1
  295. package/dist/server/quick-ask.js +123 -27
  296. package/dist/server/read-tool.js +0 -65
  297. package/dist/server/reasoning-registry.js +1 -29
  298. package/dist/server/remote-cli-persistence.js +373 -0
  299. package/dist/server/remote-native-cli.js +78 -0
  300. package/dist/server/remote-ssh-service.js +481 -190
  301. package/dist/server/request-context.js +0 -9
  302. package/dist/server/resolve-global-sdk.js +0 -26
  303. package/dist/server/sandbox-data.js +0 -1
  304. package/dist/server/sandbox-engines.js +0 -1
  305. package/dist/server/sandbox-runtime-gate.js +0 -3
  306. package/dist/server/sandbox-service.js +0 -41
  307. package/dist/server/sandbox-tool.js +0 -20
  308. package/dist/server/schedule-agent-tool.js +2 -31
  309. package/dist/server/scheduler-tasks.js +3 -54
  310. package/dist/server/scm-commitmsg.js +0 -53
  311. package/dist/server/scm.js +3 -48
  312. package/dist/server/sdk-builtin-extensions.js +2 -29
  313. package/dist/server/sdk-origin.js +0 -45
  314. package/dist/server/serialize.js +2 -92
  315. package/dist/server/server-config.js +0 -11
  316. package/dist/server/session-branch.js +1 -87
  317. package/dist/server/session-list-scan.js +17 -25
  318. package/dist/server/session-open.js +2 -26
  319. package/dist/server/session-parser.js +1 -55
  320. package/dist/server/session-scan.js +1 -17
  321. package/dist/server/session-search.js +0 -56
  322. package/dist/server/settings-service.js +11 -126
  323. package/dist/server/setup-config.js +0 -2
  324. package/dist/server/setup-page.js +0 -9
  325. package/dist/server/skill-content-filler.js +0 -17
  326. package/dist/server/skill-discovery.js +5 -92
  327. package/dist/server/skill-maintenance.js +1 -28
  328. package/dist/server/skill-tool.js +0 -30
  329. package/dist/server/slash-commands.js +5 -50
  330. package/dist/server/soft-cap.js +0 -42
  331. package/dist/server/startup-banner.js +0 -8
  332. package/dist/server/subagent-handoff.js +0 -11
  333. package/dist/server/subagent-helpers.js +2 -17
  334. package/dist/server/subagent-notify.js +0 -19
  335. package/dist/server/subagent-security-gate.js +0 -50
  336. package/dist/server/subagent-task.js +0 -9
  337. package/dist/server/subagent-templates-hant.js +0 -10
  338. package/dist/server/subagent-templates.js +3 -103
  339. package/dist/server/subagents.js +1 -87
  340. package/dist/server/system-screenshot-windows.js +259 -0
  341. package/dist/server/system-screenshot.js +77 -0
  342. package/dist/server/tabs.js +3 -48
  343. package/dist/server/terminals.js +559 -586
  344. package/dist/server/text-quote.js +0 -12
  345. package/dist/server/text-sniff.js +2 -52
  346. package/dist/server/themes.js +2 -41
  347. package/dist/server/tool-approval.js +0 -47
  348. package/dist/server/tool-guards.js +0 -90
  349. package/dist/server/tool-host-factories.js +1 -16
  350. package/dist/server/tool-info.js +0 -13
  351. package/dist/server/tool-manager.js +1 -229
  352. package/dist/server/tool-overrides.js +1 -46
  353. package/dist/server/tool-prompt-overrides.js +1 -30
  354. package/dist/server/tool-prompts.js +0 -14
  355. package/dist/server/tool-signature.js +0 -25
  356. package/dist/server/transcript-prepare.js +1 -19
  357. package/dist/server/tts-routes.js +58 -0
  358. package/dist/server/tts-service.js +106 -0
  359. package/dist/server/tts-system.js +160 -0
  360. package/dist/server/turn-timing.js +0 -1
  361. package/dist/server/unauthorized-page.js +0 -8
  362. package/dist/server/universal/driver-base.js +2 -31
  363. package/dist/server/universal/drivers/claude-code.js +12 -172
  364. package/dist/server/universal/drivers/codex.js +12 -35
  365. package/dist/server/universal/drivers/mock-driver.js +1 -11
  366. package/dist/server/universal/index.js +0 -3
  367. package/dist/server/universal/session-store.js +4 -21
  368. package/dist/server/universal/universal-attachments.js +2 -36
  369. package/dist/server/universal/universal-service.js +5 -24
  370. package/dist/server/universal/universal-session.js +26 -148
  371. package/dist/server/universal/universal-types.js +0 -3
  372. package/dist/server/update-check.js +6 -182
  373. package/dist/server/uploads.js +4 -43
  374. package/dist/server/virtual-tui.js +2 -27
  375. package/dist/server/vision-bridge.js +0 -27
  376. package/dist/server/wait-subscription-scan.js +13 -115
  377. package/dist/server/webui-context.js +2 -87
  378. package/dist/server/workspace-handle.js +1 -56
  379. package/dist/server/workspace-snapshot.js +7 -113
  380. package/dist/server/worktree-service.js +2 -53
  381. package/dist/server/worktree-tool.js +0 -11
  382. package/dist/server/ws-client-id.js +0 -18
  383. package/dist/server/ws-pending-queue.js +0 -7
  384. package/dist/server/ws-unknown-types.js +0 -17
  385. package/docs/README.md +24 -17
  386. package/docs/architecture-plugins.md +37 -1
  387. package/docs/device-center.md +28 -2
  388. package/docs/device-desktop.md +3 -3
  389. package/docs/group-orchestration.md +142 -0
  390. package/docs/hub-upgrade-release-testing.md +46 -0
  391. package/extensions/webui.ts +3 -74
  392. package/package.json +7 -3
  393. package/plugin-sdk/README.md +6 -0
  394. package/plugin-sdk/client-utils.mjs +0 -7
  395. package/plugin-sdk/client.d.ts +0 -1
  396. package/plugin-sdk/client.mjs +1 -31
  397. package/plugin-sdk/import-check.mjs +4 -51
  398. package/plugin-sdk/index.d.ts +120 -119
  399. package/plugin-sdk/index.mjs +0 -6
  400. package/plugin-sdk/ssh-host-trust.mjs +0 -12
  401. package/plugin-sdk/testing.d.ts +0 -1
  402. package/plugin-sdk/testing.mjs +31 -86
  403. package/plugins/catalog.json +52 -4
  404. package/plugins/superagent/README.md +110 -0
  405. package/plugins/superagent/client/entry.mjs +21 -0
  406. package/plugins/superagent/index.mjs +8 -0
  407. package/plugins/superagent/main.mjs +218 -0
  408. package/plugins/superagent/manifest.json +15 -0
  409. package/plugins/superagent/server.mjs +572 -0
  410. package/plugins/superagent/style.css +167 -0
  411. package/themes/aetheris.css +1 -31
  412. package/themes/ayu-light.css +0 -1
  413. package/themes/bases/flow-base.css +2 -83
  414. package/themes/bases/obsidian-base.css +2 -37
  415. package/themes/bases/statusbar-flat-base.css +0 -1
  416. package/themes/bases/zhujian-base.css +0 -63
  417. package/themes/bases/zhupi-base.css +0 -64
  418. package/themes/catppuccin-latte.css +0 -1
  419. package/themes/catppuccin.css +0 -1
  420. package/themes/claude-code-dark.css +0 -1
  421. package/themes/codex.css +0 -1
  422. package/themes/dark-teal.css +22 -54
  423. package/themes/everforest-light.css +0 -1
  424. package/themes/flow-cristallo.css +1 -9
  425. package/themes/flow-ink.css +1 -10
  426. package/themes/flow-light.css +1 -10
  427. package/themes/flow-obsidian.css +1 -10
  428. package/themes/flow-zurich.css +1 -10
  429. package/themes/flow.css +1 -9
  430. package/themes/geist.css +0 -1
  431. package/themes/gruvbox-light.css +0 -1
  432. package/themes/kanagawa-lotus.css +0 -1
  433. package/themes/md-preview.css +1 -2
  434. package/themes/mist.css +0 -1
  435. package/themes/nord.css +0 -1
  436. package/themes/one-dark.css +0 -1
  437. package/themes/paper.css +0 -1
  438. package/themes/rose-pine-dawn.css +0 -1
  439. package/themes/sakura.css +0 -1
  440. package/themes/solarized-light.css +0 -1
  441. package/themes/tokyo-night.css +0 -1
  442. package/themes/translucent.css +4 -35
  443. package/themes/transparent.css +4 -41
  444. package/themes/vs-code-dark.css +0 -1
  445. package/themes/wallpaper-flow.css +3 -17
  446. package/themes/wallpaper-obsidian.css +1 -4
  447. package/themes/white.css +0 -1
  448. package/web/dist/.build-assets.json +1 -1
  449. package/web/dist/assets/{BgTasksModal-BjNRIUIc.js → BgTasksModal-D-x7kA63.js} +1 -1
  450. package/web/dist/assets/CanvasStudio-CAWcs9tm.js +1579 -0
  451. package/web/dist/assets/DeviceCenter-Dc0whRcu.js +3 -0
  452. package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +1 -0
  453. package/web/dist/assets/DeviceGroups-C_fZMNeK.js +1 -0
  454. package/web/dist/assets/{Dropdown-CQtstPGv.js → Dropdown-CTgVLUbp.js} +1 -1
  455. package/web/dist/assets/FilePreview-C6W0PvaK.js +2 -0
  456. package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +1 -0
  457. package/web/dist/assets/GroupConversation-C81YjF2C.js +61 -0
  458. package/web/dist/assets/GroupWorkItems-BIvZtr10.js +1 -0
  459. package/web/dist/assets/{HintTip-ChTW8o1m.js → HintTip-Da6qc566.js} +1 -1
  460. package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +2 -0
  461. package/web/dist/assets/NativeCliPanel-CU1rZmyu.js +5 -0
  462. package/web/dist/assets/{PiSetupModal-BX5rUuoI.js → PiSetupModal-DZKY5Wiw.js} +1 -1
  463. package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +1 -0
  464. package/web/dist/assets/{SCMPanel-DPAyY2sW.js → SCMPanel-CuEgzAlO.js} +2 -2
  465. package/web/dist/assets/SettingsModal-Cdu5h29p.js +33 -0
  466. package/web/dist/assets/TermXterm-Bt5WKAxP.js +3 -0
  467. package/web/dist/assets/TerminalPanel-BCIBV8se.js +1 -0
  468. package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +1 -0
  469. package/web/dist/assets/app-globals-CZjFtI4F.js +129 -0
  470. package/web/dist/assets/canvas-client-WkhM55mR.js +1 -0
  471. package/web/dist/assets/composer-bridge-CImnjDHq.js +1 -0
  472. package/web/dist/assets/desktop-B8NZ3KW-.js +1 -0
  473. package/web/dist/assets/index-CQc3VrWa.css +1 -0
  474. package/web/dist/assets/index-D_AGu4Zv.js +404 -0
  475. package/web/dist/assets/plugin-host-uqZGpvCs.js +1 -0
  476. package/web/dist/assets/{remote-ssh-client-Dzi-eEyE.js → remote-ssh-client-Cdf-cTUe.js} +1 -1
  477. package/web/dist/assets/theme-DGL7hLUs.js +1 -0
  478. package/web/dist/index.html +11 -10
  479. package/web/dist/sw.js +15 -61
  480. package/web/public/sw.js +14 -60
  481. package/web/dist/assets/BgTasksModal-C0zuU8FE.js +0 -1
  482. package/web/dist/assets/CanvasStudio-BWvdmJ0M.js +0 -1579
  483. package/web/dist/assets/CanvasStudio-VQFjmTGq.js +0 -1579
  484. package/web/dist/assets/DeviceCenter-DI9_0aBB.js +0 -3
  485. package/web/dist/assets/DeviceCenter-DsNtXqzY.js +0 -3
  486. package/web/dist/assets/DeviceExecutionSettings-BLP1Su5G.js +0 -1
  487. package/web/dist/assets/DeviceGroups-2Pvk0Cds.js +0 -1
  488. package/web/dist/assets/DeviceGroups-CP7CcyPD.js +0 -1
  489. package/web/dist/assets/FilePreview-BMB2tNyT.js +0 -2
  490. package/web/dist/assets/FilePreview-RGFQUbJo.js +0 -2
  491. package/web/dist/assets/GlobalSearchModal-BM5wxiqU.js +0 -1
  492. package/web/dist/assets/GlobalSearchModal-DGv_WINq.js +0 -1
  493. package/web/dist/assets/GroupConversation-B7SnuXj1.js +0 -61
  494. package/web/dist/assets/GroupConversation-Dda69q-2.js +0 -61
  495. package/web/dist/assets/ModelConfigModal-C-0Z4hUZ.js +0 -2
  496. package/web/dist/assets/ModelConfigModal-yqeadyab.js +0 -2
  497. package/web/dist/assets/ProviderOAuthControls-DY4SCfXg.js +0 -1
  498. package/web/dist/assets/SCMPanel-C4KbQvvK.js +0 -2
  499. package/web/dist/assets/SettingsModal-DxZp6D_g.js +0 -32
  500. package/web/dist/assets/SettingsModal-WhQzaOPt.js +0 -32
  501. package/web/dist/assets/TerminalPanel-D4By_RVc.js +0 -3
  502. package/web/dist/assets/TerminalPanel-lZw8-i3j.js +0 -3
  503. package/web/dist/assets/TuiOverlayModal-C3pAVuC8.js +0 -1
  504. package/web/dist/assets/TuiOverlayModal-D7_rEXcJ.js +0 -1
  505. package/web/dist/assets/app-globals-KqOVtmp1.js +0 -123
  506. package/web/dist/assets/canvas-client-BY6ojmle.js +0 -1
  507. package/web/dist/assets/desktop-CV6KKp9R.js +0 -1
  508. package/web/dist/assets/index-BawF7ZP5.js +0 -397
  509. package/web/dist/assets/index-BoGCoq5X.js +0 -397
  510. package/web/dist/assets/index-CVW9FoY2.css +0 -1
  511. package/web/dist/assets/plugin-host-Dn8Dd6SC.js +0 -1
  512. package/web/dist/assets/theme-D_bihpdN.js +0 -1
@@ -1,25 +1,3 @@
1
- /**
2
- * goal-service — 目标模式 2.0:目标状态机 + 服务端驱动的「执行 ↔ 审查」循环 + 调研向导,
3
- * 从 agent-service.ts 抽出。
4
- *
5
- * 职责:
6
- * - setGoal/clearGoal/setGoalPrefs:目标状态机 + 偏好「全局记忆」(client-state.json)
7
- * - 委托循环(**唯一**的审查/执行路径,目标模式 2.0):主对话 = 审查者,服务端另起一个
8
- * 常驻执行对话干活。一轮 = 派活 → 等它结束 → 取样(工作区 diff 指纹 + 执行者会话的
9
- * 错误特征)→ 把审查指令交给主对话 → 解析 verdict → 判定(pass / 再来一轮 /
10
- * 熔断 / 预算用尽)。轮次、熔断、代次全在服务端,模型不得自循环。
11
- * - startGoalWizard:AI 提炼——独立调研会话经 goal_ask 工具逐题提问(对话框桥接浏览器),
12
- * 收敛出 GOAL: 后自动设为目标并启动循环
13
- *
14
- * 历史说明:v1 的「隐藏隔离审查会话 + 自治标记」路径(runGoalReview / isAutonomous /
15
- * GOAL_COMPLETION_RE)已按产品决策删除,只留委托一条。`GoalStatus.reviewModel` 字段名
16
- * 保留(DSH 引擎仍在构造该状态),pi 侧语义已变为「调研(向导)模型」记忆位 ——
17
- * 审查者在委托模式下就是主对话,不再有独立的审查模型。
18
- *
19
- * 经 GoalHost 窄接口与 ClientSession 解耦(同 settings-service 模式):对话记录按
20
- * 结构化子集 GoalConversation 传入(真实 Conversation 满足该结构),会话创建/对话框
21
- * 取消/git diff 等宿主能力走回调,便于独立测试。UI 文案直接中文(服务端 notice 约定)。
22
- */
23
1
  import { mkdirSync, rmSync } from "node:fs";
24
2
  import { join } from "node:path";
25
3
  import { Type } from "typebox";
@@ -59,17 +37,12 @@ function allBalancedJsonObjects(raw) {
59
37
  }
60
38
  return out;
61
39
  }
62
- /** 剥离复制调研草案卡片时带入的前缀(支持中英文与多层重复,纯函数供单测共用)。 */
63
40
  export function stripGoalDraftPrefix(raw) {
64
41
  return (raw ?? "")
65
42
  .trim()
66
43
  .replace(/^(?:(?:🎯\s*)?(?:Initial goal draft|原始目标草案)\s*[::]\s*)+/i, "")
67
44
  .trim();
68
45
  }
69
- /**
70
- * 从主会话消息列表中提取结构化上下文(压缩摘要 + 近期轮次),注入向导 prompt,
71
- * 避免向导会话处于无上下文的盲搜状态(借鉴 pi-goal-x / pi-plan 的 warm context 设计)。
72
- */
73
46
  export function buildWizardConversationContext(messages, maxChars = 16_000) {
74
47
  if (!Array.isArray(messages) || messages.length === 0)
75
48
  return "";
@@ -124,14 +97,6 @@ export function buildWizardConversationContext(messages, maxChars = 16_000) {
124
97
  sections.push(`## Recent Conversation Turns\n${recentAcc}`);
125
98
  return sections.join("\n\n").slice(0, maxChars);
126
99
  }
127
- /**
128
- * 解析审查模型的 verdict 输出(纯函数)。扫描全文所有平衡 {...} 做 JSON.parse,
129
- * **最后一个合法 verdict 胜出**:模型常先复述契约里的示例 JSON 再给真正结论,
130
- * 取第一个会被示例带偏(复述 pass 示例 + 真结论 fail → 假通过)。feedback 里的
131
- * \" 转义与嵌套引号由 JSON 语义天然处理;都不是合法 JSON(单引号/尾逗号等)
132
- * 再退回宽松正则逐字段抠(同样以后出现者为准)。两者都失败返回 undefined,
133
- * 调用方按「无 JSON」处理。
134
- */
135
100
  export function parseReviewerVerdict(raw) {
136
101
  let found;
137
102
  for (const json of allBalancedJsonObjects(raw)) {
@@ -143,9 +108,7 @@ export function parseReviewerVerdict(raw) {
143
108
  }
144
109
  }
145
110
  }
146
- catch {
147
- // 不是合法 JSON(围栏残留/单引号/尾逗号)→ 继续扫下一个,实在没有落正则兜底
148
- }
111
+ catch { }
149
112
  }
150
113
  if (found)
151
114
  return found;
@@ -159,22 +122,10 @@ export function parseReviewerVerdict(raw) {
159
122
  }
160
123
  return last;
161
124
  }
162
- /** diff 正文进审查 prompt 的截断上限(完整规模信息走 [diff-meta] 尾段)。 */
163
125
  export const GIT_DIFF_CAP = 60_000;
164
- /**
165
- * 由 git 原始输出构造「变更指纹」(纯函数,供 AgentService.gitDiff 与单测共用)。
166
- * - diff 正文非空 → 截断正文 + [diff-meta] 尾段(完整字符数 + 排序后的 status
167
- * 指纹)。尾段永不参与截断:大 diff 两轮的前 60_000 字符可能完全相同(改动
168
- * 落在截断线之后),只比截断正文会把持续推进误判成停滞;对内容变化敏感的
169
- * 完整字符数让 prevDiff 等值比较能区分「真没变」与「变了但被截断」。
170
- * - diff 正文为空 → 排序后的 `git status --porcelain` 指纹(未跟踪文件不进
171
- * diff,却是新工作区最常见的实际进展);两段都空(返回 "")才算真停滞。
172
- * - status 输出为空/拍不到 → 对应段省略,退化为旧版纯 diff 行为。
173
- */
174
126
  export function buildDiffFingerprint(diffOut, statusOut) {
175
127
  let status = "";
176
128
  if (statusOut.trim() !== "") {
177
- // porcelain 不承诺输出有序,显式排序保证指纹逐轮稳定可比。
178
129
  status = statusOut
179
130
  .split("\n")
180
131
  .filter((line) => line.trim() !== "")
@@ -187,12 +138,6 @@ export function buildDiffFingerprint(diffOut, statusOut) {
187
138
  const meta = `\n[diff-meta] chars=${diffOut.length}${status ? `\n[git-status]\n${status}` : ""}`;
188
139
  return diffOut.slice(0, GIT_DIFF_CAP) + meta;
189
140
  }
190
- /**
191
- * 提取会话最近产生的错误特征(纯函数,供停滞与相同报错检测)。
192
- * 从后往前扫最近 6 条消息:toolResult.isError 优先,其次非 0 退出的 bashExecution;
193
- * 都没有再退回从最终文本里找 Error/Exception/Fail/Fatal 行。
194
- * 抽成纯函数是因为委托执行(Plan A)要拿**执行者子代理**的错误特征(而不是主对话的)。
195
- */
196
141
  export function extractErrorSnippetFromSession(session, text) {
197
142
  try {
198
143
  const messages = session?.agent?.state?.messages;
@@ -215,20 +160,13 @@ export function extractErrorSnippetFromSession(session, text) {
215
160
  }
216
161
  }
217
162
  }
218
- catch {
219
- // Ignore
220
- }
163
+ catch { }
221
164
  const errMatch = text.match(/(?:(?:Error|Exception|Fail|Fatal):[^\n]+)/i);
222
165
  if (errMatch) {
223
166
  return errMatch[0].trim().slice(0, 300);
224
167
  }
225
168
  return undefined;
226
169
  }
227
- /**
228
- * 该会话最近用过的工具名(纯函数,供目标条「执行者在干什么」用)。
229
- * 从后往前扫最近 6 条消息,最新的一次 toolCall 即结果;6 条里没有则返回
230
- * undefined(不翻旧账:几轮前的工具不是「正在干」)。
231
- */
232
170
  export function lastToolNameOfSession(session) {
233
171
  try {
234
172
  const messages = session?.agent?.state?.messages;
@@ -246,36 +184,26 @@ export function lastToolNameOfSession(session) {
246
184
  }
247
185
  }
248
186
  }
249
- catch {
250
- // Ignore
251
- }
187
+ catch { }
252
188
  return undefined;
253
189
  }
254
- /**
255
- * 解析向导输出中的目标与结构化执行计划(纯函数)。
256
- * - 目标从 `GOAL: ...` 提取;
257
- * - 步骤从 `STEPS:` 或后续数字/无序列表行提取(若有),作为 PlanStep 供看板使用。
258
- */
259
190
  export function parseWizardOutput(raw) {
260
191
  const trimmed = (raw ?? "").trim();
261
192
  if (!trimmed)
262
193
  return { goal: "", steps: [] };
263
194
  let goalText = "";
264
195
  let stepsPart = "";
265
- // 先看是否有明确的 STEPS: / PLAN: / TASKS: 标头
266
196
  const stepsHeaderMatch = trimmed.match(/\n\s*(?:STEPS|PLAN|TASKS)\s*[::]\s*([\s\S]*)/i);
267
197
  let preSteps = trimmed;
268
198
  if (stepsHeaderMatch) {
269
199
  preSteps = trimmed.slice(0, stepsHeaderMatch.index).trim();
270
200
  stepsPart = stepsHeaderMatch[1].trim();
271
201
  }
272
- // 从前半部分提取 GOAL:
273
202
  const goalMatch = preSteps.match(/GOAL\s*[::]\s*([\s\S]*)/i);
274
203
  if (goalMatch) {
275
204
  goalText = goalMatch[1].trim();
276
205
  }
277
206
  else {
278
- // 没有显式 GOAL: 标头时,按原来逻辑去掉前导前言行
279
207
  const lines = preSteps.split("\n").filter((l) => l.trim());
280
208
  if (lines.length > 1 && !/[。.!??]\s*$/.test(lines[0])) {
281
209
  goalText = lines.slice(1).join(" ").trim();
@@ -284,7 +212,6 @@ export function parseWizardOutput(raw) {
284
212
  goalText = preSteps;
285
213
  }
286
214
  }
287
- // 解析 stepsPart
288
215
  const steps = [];
289
216
  if (stepsPart) {
290
217
  const stepLines = stepsPart
@@ -331,9 +258,6 @@ export function parseWizardOutput(raw) {
331
258
  steps,
332
259
  };
333
260
  }
334
- /** System prompt for the goal-wizard session. The wizard asks the user a few
335
- * questions (via its goal_ask tool) to scope a raw requirement into a precise,
336
- * reviewable goal, then emits ONLY the final goal text as its last message. */
337
261
  function wizardPrompt(draft, contextSummary = "") {
338
262
  return [
339
263
  `You are a goal-clarification wizard. The user has stated a raw requirement. Your job is to turn it into ONE precise, actionable goal that a coding agent can fully satisfy and that can be strictly reviewed.`, // eslint-disable-line max-len
@@ -360,50 +284,25 @@ function wizardPrompt(draft, contextSummary = "") {
360
284
  }
361
285
  export class GoalService {
362
286
  host;
363
- /** Defaults remembered for newly-created conversations. Each conversation
364
- * receives its own GoalStatus, so reviews can run concurrently. */
365
287
  prefs = {
366
288
  reviewModel: null,
367
289
  maxRounds: 0,
368
290
  locked: true,
369
- /** 目标模式 2.0:委托执行者模型。 */
370
291
  execModel: null,
371
292
  };
372
- /** Aborts the currently-running goal wizard (user clicked ✗ / timed out). Drives
373
- * the in-flight goal_ask dialog to resolve as cancelled and (via the run
374
- * signal) stops the wizard session's agent run. Recreated per wizard. */
375
293
  wizardAbort = null;
376
- /** The wizard's AgentSession while it runs — lets clearGoal truly terminate it
377
- * (abort the run), not just flip a flag. */
378
294
  wizardSession = null;
379
- /** Conversation that owns the one browser wizard currently in flight. */
380
295
  wizardOwnerId = null;
381
- /** True when the wizard was cancelled externally (✗ / clear_goal / timeout) —
382
- * startGoalWizard reads this after the run to avoid setting a goal. */
383
296
  wizardCancelled = false;
384
- // ---------------------------------------------------------------------
385
- // 目标模式 2.0(只有委托执行)的循环状态。
386
- // ---------------------------------------------------------------------
387
- /** 正在等主对话(审查者)verdict 的循环:convId → resolve。 */
388
297
  verdictWaiters = new Map();
389
- /** 「已把审查指令交给主对话」的观测点(waitForVerdict 登记后触发;测试/宿主观测用)。 */
390
298
  verdictSignals = new Map();
391
- /** 每个对话至多一个在飞循环(convid → promise)。 */
392
299
  delegatedLoops = new Map();
393
- /** 旧循环还在退场时到来的新启动请求(convId → 最新一次):旧循环收束后接力
394
- * 启动。没有它的话,setGoal 紧跟 clearGoal 会因「表里还有旧循环」而静默早退,
395
- * 新目标永远不派活(状态却写着「等待生成」)。 */
396
300
  delegatedPending = new Map();
397
- /** Idle-timeout for the wizard: if no answer arrives within this window (a
398
- * dialog is up but the user doesn't respond), the wizard is auto-cancelled. */
399
301
  static WIZARD_IDLE_TIMEOUT_MS = 5 * 60_000;
400
- /** Absolute deadline for the whole wizard session (model latency guard). */
401
302
  static WIZARD_MAX_TOTAL_MS = 20 * 60_000;
402
- /** 执行者连续 error/timeout 超过该轮数 → 直接受阻(不限轮下也不会无限空转)。 */
403
303
  static EXEC_FAILED_ROUNDS_LIMIT = 2;
404
304
  constructor(host) {
405
305
  this.host = host;
406
- // Restore last-used goal/review preferences so model & rounds survive reload.
407
306
  const gPrefs = host.stateStore.getGoalPrefs(host.clientId);
408
307
  if (gPrefs) {
409
308
  this.prefs = {
@@ -414,17 +313,12 @@ export class GoalService {
414
313
  };
415
314
  }
416
315
  }
417
- /** Remembered defaults (model choice / rounds cap / lock). */
418
- /** 当前服务端语言(英文默认,未接线前保持原有英文行为)。 */
419
316
  lang() {
420
317
  return this.host.lang?.() ?? "en";
421
318
  }
422
- /** 目标模式总开关(设置面板可关)。关 → 所有目标入口拒绝、审查不再触发。 */
423
319
  goalEnabled() {
424
320
  return this.host.goalModeEnabled();
425
321
  }
426
- /** Create independent goal state for one conversation. Preferences are
427
- * client-wide defaults, while goal text/review progress is not shared. */
428
322
  makeGoalStatus() {
429
323
  return {
430
324
  conversationId: null,
@@ -448,19 +342,15 @@ export class GoalService {
448
342
  },
449
343
  };
450
344
  }
451
- /** Push the active conversation's goal status to the client (the goal bar
452
- * restores remembered prefs when nothing is active). */
453
345
  emitGoalStatus() {
454
346
  const conv = this.host.activeConv();
455
347
  const goal = conv.goal;
456
- // 本目标累计用量随状态下发(目标条展示用;无累计即不发字段)。
457
348
  if (conv.goalUsage) {
458
349
  goal.usage = { inputTokens: conv.goalUsage.input, outputTokens: conv.goalUsage.output };
459
350
  }
460
351
  else {
461
352
  goal.usage = undefined;
462
353
  }
463
- // 目标历史随状态下发(清目标不清空,内存态)。
464
354
  goal.history = conv.goalHistory && conv.goalHistory.length > 0 ? [...conv.goalHistory] : undefined;
465
355
  if (!goal.goal && !goal.reviewing && !goal.wizard.active) {
466
356
  goal.reviewModel = this.prefs.reviewModel;
@@ -470,21 +360,9 @@ export class GoalService {
470
360
  }
471
361
  this.host.emit({ type: "goal_status", status: { ...goal } });
472
362
  }
473
- /**
474
- * Set (or clear) the active goal. `goal === ""` clears it. The goal is
475
- * applied to the CURRENT active conversation of this project; reviews check
476
- * whatever run finishes next (agent_end).
477
- *
478
- * `opts.targetConvId` retargets the write to a specific conversation — used by
479
- * the goal wizard, which runs in the background while the user may have
480
- * switched away: the refined goal must land in the conversation that LAUNCHED
481
- * the survey (issue #292), not in whatever conversation happens to be active
482
- * and not be thrown away.
483
- */
484
363
  async setGoal(goalText, opts) {
485
364
  await this.commitGoal(goalText, opts);
486
365
  }
487
- /** Return the exact committed request so callers can guard follow-up work. */
488
366
  async commitGoal(goalText, opts) {
489
367
  const text = (goalText ?? "").trim();
490
368
  if (!text) {
@@ -500,13 +378,8 @@ export class GoalService {
500
378
  });
501
379
  return;
502
380
  }
503
- // quiesce(服务排空):新目标是新工作,直接拒绝(宿主的 quiesceBlocked
504
- // 自带「正在排空」notice,与 prompt/编辑入口同口径)。清目标不受影响。
505
381
  if (this.host.quiesceBlocked())
506
382
  return;
507
- // 目标模式 2.0 只有一条路径(执行对话干活 + 当前对话验收),需要宿主提供角色
508
- // 对话桥(spawn/wait/send/read/stop/dismiss);缺任何一个(未接线 / 非 pi
509
- // 引擎)则在**动目标状态之前**就拒绝并说明原因。
510
383
  if (!this.roleBridgeReady()) {
511
384
  this.host.emit({
512
385
  type: "notice",
@@ -516,13 +389,8 @@ export class GoalService {
516
389
  });
517
390
  return;
518
391
  }
519
- // A goal is scoped to the conversation it is set on (default: the active
520
- // one). This prevents an agent_end from a newly-created/switched conversation
521
- // from consuming the previous conversation's goal.
522
392
  const targetConv = opts?.targetConvId ? this.host.getConv(opts.targetConvId) : undefined;
523
393
  if (opts?.targetConvId && !targetConv) {
524
- // The targeted conversation is gone (closed / disposed) — refuse loudly
525
- // instead of silently landing the goal somewhere else.
526
394
  this.host.emit({
527
395
  type: "notice",
528
396
  level: "warning",
@@ -534,10 +402,6 @@ export class GoalService {
534
402
  const conv = targetConv ?? this.host.activeConv();
535
403
  const goalConversationId = conv.id;
536
404
  const gen = ++conv.goalGeneration;
537
- // 上一轮目标可能还留着常驻执行者子代理(委托执行):先停掉再开新的,
538
- // 否则旧循环会在新目标上继续派活(代次已作废,但角色对话得收)。
539
- // await 到 dismiss 完全落定:后面的 spawn 名额检查才不会数到还在收尾的
540
- // 旧执行者而误报上限(issue #464;stopDelegated 自身已按会话串行化)。
541
405
  await this.stopDelegated(conv);
542
406
  if (!this.isCurrentGoalRequest(conv, gen))
543
407
  return;
@@ -545,9 +409,6 @@ export class GoalService {
545
409
  goal.reviewing = false;
546
410
  goal.conversationId = goalConversationId;
547
411
  goal.goal = text;
548
- // Model & rounds preference semantics ("全局记忆"):
549
- // - reviewModel undefined → keep the remembered choice; empty → main model.
550
- // - maxRounds 0 = unlimited (default); >0 = finite cap (clamped to 50).
551
412
  if (opts?.reviewModel !== undefined)
552
413
  goal.reviewModel = opts.reviewModel || null;
553
414
  if (typeof opts?.maxRounds === "number") {
@@ -564,14 +425,12 @@ export class GoalService {
564
425
  locked: goal.locked,
565
426
  execModel: goal.execModel ?? null,
566
427
  };
567
- // Persist the chosen preferences so they survive reload.
568
428
  this.host.stateStore.saveGoalPrefs(this.host.clientId, {
569
429
  reviewModel: goal.reviewModel,
570
430
  maxRounds: goal.maxRounds,
571
431
  locked: goal.locked,
572
432
  execModel: this.prefs.execModel,
573
433
  });
574
- // Reset the loop for a freshly-set goal (single-shot goals start at 0).
575
434
  this.resetLoopCounters(conv);
576
435
  conv.awaitingVerdict = undefined;
577
436
  goal.round = 0;
@@ -592,29 +451,15 @@ export class GoalService {
592
451
  text: `🎯 已设目标:${text.slice(0, 80)}${text.length > 80 ? "…" : ""}`,
593
452
  textEn: `🎯 Goal set: ${text.slice(0, 80)}${text.length > 80 ? "…" : ""}`,
594
453
  });
595
- // Direct requests auto-start; the wizard commits its plan before starting.
596
454
  if (opts?.autoStart !== false) {
597
- // #591:主对话若仍在跑设目标前的旧任务,首轮派发执行者前先中断让位,
598
- // 避免主对话与目标执行者在同一工作区并行动工、污染采样 diff。
599
455
  await this.preemptMainRunForGoal(conv, gen);
600
456
  if (!this.isCurrentDelegated(conv, gen))
601
457
  return;
602
- // 目标模式 2.0(唯一路径):主对话当审查者,干活的是常驻执行对话 ——
603
- // 不向主对话注入「请开始实现」,改由服务端驱动循环(等执行者跑完再把
604
- // 审查指令交给主对话)。
605
458
  this.startDelegatedLoop(conv, gen, text);
606
459
  this.host.flushSnapshot();
607
460
  }
608
461
  return { conv, generation: gen };
609
462
  }
610
- /**
611
- * Collaborative target wizard. Turns a raw user requirement into a refined
612
- * goal by spinning up an ISOLATED wizard session (own fresh ModelRuntime +
613
- * in-memory session, so its model choice is its own) that questions the user
614
- * via `goal_ask` (multiple-choice + free-text, bridged to the browser through
615
- * the existing select/input dialog), converging on a goal, then auto-sets it.
616
- * Mutually exclusive with the review loop of the same conversation.
617
- */
618
463
  async startGoalWizard(text, opts, target) {
619
464
  if (this.host.quiesceBlocked())
620
465
  return;
@@ -630,16 +475,11 @@ export class GoalService {
630
475
  const draft = stripGoalDraftPrefix(text);
631
476
  if (!draft)
632
477
  return;
633
- // The wizard and its progress cards belong to the conversation that
634
- // launched it. If the user switches away, do not later set a goal on the
635
- // new active conversation while the wizard is still finishing.
636
478
  const wizardConversation = target ?? this.host.activeConv();
637
479
  if (this.host.getConv(wizardConversation.id) !== wizardConversation)
638
480
  return;
639
481
  const wizardConversationId = wizardConversation.id;
640
482
  const wizardGeneration = wizardConversation.goalGeneration;
641
- // Human-readable name for notices that must say WHICH conversation the survey
642
- // belongs to (issue #292: the user is expected to switch away mid-survey).
643
483
  const wizardConversationTitle = wizardConversation.title;
644
484
  if (wizardConversation.wizardRunning || this.wizardOwnerId !== null) {
645
485
  this.host.emit({
@@ -659,9 +499,6 @@ export class GoalService {
659
499
  });
660
500
  return;
661
501
  }
662
- // Questions are NOT capped (调研不限制) — the wizard converges on its own;
663
- // the idle- and total-timeouts are the only guards. maxSteps is purely a
664
- // soft UI indicator, not a hard stop.
665
502
  const maxSteps = 20;
666
503
  wizardConversation.wizardRunning = true;
667
504
  this.wizardOwnerId = wizardConversationId;
@@ -700,11 +537,6 @@ export class GoalService {
700
537
  wgoal.status = "目标调研中…";
701
538
  wgoal.statusEn = "Scoping the goal…";
702
539
  this.emitGoalStatus();
703
- // Idle-timeout: cancel the wizard if the user does NOT answer a pending dialog
704
- // within the window (a stale dialog with no user response must not hang forever).
705
- // Note: armed strictly while waiting for the user's answer in goal_ask, and
706
- // cleared once the user answers — model thinking / read-only checks are governed
707
- // by totalTimer, avoiding false "waited too long for an answer" timeouts.
708
540
  const ac = this.wizardAbort;
709
541
  let idleTimer = null;
710
542
  const armIdle = () => {
@@ -724,8 +556,6 @@ export class GoalService {
724
556
  idleTimer = null;
725
557
  }
726
558
  };
727
- // Total-duration guard: hard cap on the whole wizard session (model
728
- // latency / unexpected loops must not run forever).
729
559
  const totalTimer = setTimeout(() => {
730
560
  if (!ac.signal.aborted) {
731
561
  this.wizardCancelled = true;
@@ -739,13 +569,7 @@ export class GoalService {
739
569
  text: `🔍 正在围绕需求展开调研:${draft.slice(0, 60)}${draft.length > 60 ? "…" : ""}`,
740
570
  textEn: `🔍 Surveying the requirement: ${draft.slice(0, 60)}${draft.length > 60 ? "…" : ""}`,
741
571
  });
742
- // The main conversation to show wizard progress cards in.
743
572
  const mainSession = wizardConversation.session;
744
- // The raw draft gets its own read-only card BEFORE the first question, so the
745
- // flow starts from a visible anchor. If the survey is interrupted (idle/total
746
- // timeout, ✗, or the user switching away and never coming back), the original
747
- // requirement is still readable and copyable in THIS conversation instead of
748
- // having to be retyped (issue #292).
749
573
  await this.pushWizardCard(mainSession, pick(this.lang(), `🎯 原始目标草案:${draft}`, `🎯 Initial goal draft: ${draft}`, "goal.wizard.draft.card", {
750
574
  draft,
751
575
  }), { draft });
@@ -754,7 +578,7 @@ export class GoalService {
754
578
  let goalEphemeralDir;
755
579
  let srvSession;
756
580
  try {
757
- const wmSpec = opts?.wizardModel ? parseModelSpec(opts.wizardModel) : null; // "provider/id" 解析(唯一事实源)
581
+ const wmSpec = opts?.wizardModel ? parseModelSpec(opts.wizardModel) : null;
758
582
  const services = await createAgentSessionServices({
759
583
  cwd: wizardConversation.cwd,
760
584
  agentDir: this.host.agentDir,
@@ -774,8 +598,6 @@ export class GoalService {
774
598
  if (mainModel?.provider && mainModel.id)
775
599
  model = services.modelRuntime.getModel(mainModel.provider, mainModel.id);
776
600
  }
777
- // The wizard asks the user questions via this tool; each call bridges one
778
- // select/input dialog to the browser and returns the user's answer.
779
601
  let qStep = 0;
780
602
  const goalAsk = defineTool({
781
603
  name: "goal_ask",
@@ -789,10 +611,6 @@ export class GoalService {
789
611
  description: "2-4 mutually exclusive options (recommended option first)",
790
612
  })),
791
613
  }),
792
- // ONE question at a time. Sequential execution prevents the agent from
793
- // firing parallel goal_ask calls whose dialogs would overwrite each other
794
- // in the single browser modal (leaving earlier ones deadlocked — the
795
- // reported "调研卡住").
796
614
  executionMode: "sequential",
797
615
  execute: async (_id, params, _sig, _onUpdate, ctx) => {
798
616
  const lang = this.lang();
@@ -808,8 +626,6 @@ export class GoalService {
808
626
  details: {},
809
627
  };
810
628
  }
811
- // Show the question in the main flow BEFORE blocking on the dialog, so
812
- // the user sees the wizard working even before answering.
813
629
  wgoal.wizard.step = qStep;
814
630
  wgoal.wizard.status = `调研中:请回答第 ${qStep} 题`;
815
631
  wgoal.wizard.statusEn = `Scoping: please answer question ${qStep}`;
@@ -827,7 +643,6 @@ export class GoalService {
827
643
  choiceSuffixZh: choiceSuffixZh,
828
644
  choiceSuffixEn: choiceSuffixEn,
829
645
  }), { question: params.question });
830
- // Resolve the pending dialog as cancelled if the wizard is aborted.
831
646
  let aborted = false;
832
647
  const onAbort = () => {
833
648
  aborted = true;
@@ -864,7 +679,6 @@ export class GoalService {
864
679
  details: {},
865
680
  };
866
681
  }
867
- // Record the answer in the flow too (instant append, main session idle).
868
682
  await this.pushWizardCard(mainSession, pick(lang, `↳ 您的回答:${ans}`, `↳ Your answer: ${ans}`, "goal.wizard.answer.card", { ans: ans }), {
869
683
  question: params.question,
870
684
  answer: String(ans),
@@ -910,8 +724,6 @@ export class GoalService {
910
724
  services,
911
725
  sessionManager: sm,
912
726
  customTools: [goalAsk],
913
- // 仅暴露提问工具与只读检索工具:允许向导在提问前查阅工作区文件细节,
914
- // 但严禁调用 bash/edit/write 等具破坏性或耗时不可控的写/执行工具。
915
727
  tools: ["goal_ask", "read", "ls", "find", "grep"],
916
728
  ...(model ? { model } : {}),
917
729
  });
@@ -919,7 +731,6 @@ export class GoalService {
919
731
  const wizard = srv.session;
920
732
  this.wizardSession = wizard;
921
733
  await wizard.bindExtensions({ mode: "rpc", uiContext: this.host.webUi });
922
- // 实时反馈:向导查阅上下文文件时,在目标栏展示当前动作,告别黑盒等待
923
734
  const unsubscribe = wizard.subscribe((event) => {
924
735
  if (event.type === "tool_execution_start" && event.toolName !== "goal_ask") {
925
736
  const argHint = typeof event.args === "object" && event.args !== null
@@ -943,7 +754,6 @@ export class GoalService {
943
754
  this.emitGoalStatus();
944
755
  }
945
756
  });
946
- // 扩展动态注册的模型(如 cliproxyapi/grok-4.7)在 bindExtensions 后才进入 ModelRuntime,此处兜底补绑
947
757
  if (!model) {
948
758
  if (wmSpec)
949
759
  model = services.modelRuntime.getModel(wmSpec.provider, wmSpec.id);
@@ -957,21 +767,15 @@ export class GoalService {
957
767
  try {
958
768
  await wizard.setModel(model);
959
769
  }
960
- catch {
961
- /* best-effort */
962
- }
770
+ catch { }
963
771
  }
964
772
  }
965
- // Cancel watcher: when the user ✗s / idle-timeout fires, truly stop the
966
- // wizard's agent run (not just mark it).
967
773
  if (!ac.signal.aborted) {
968
774
  ac.signal.addEventListener("abort", () => {
969
775
  void wizard.abort().catch(() => { });
970
- // Close the unanswered browser dialog(s) the wizard may have up.
971
776
  this.host.webUi.cancelPendingDialogs();
972
777
  }, { once: true });
973
778
  }
974
- // 从发起调研的主会话中提取上下文历史(摘要与近期轮次),避免孤立向导完全失忆
975
779
  const mainMessages = mainSession.sessionManager?.buildSessionContext?.()?.messages ??
976
780
  mainSession.messages ??
977
781
  [];
@@ -1021,9 +825,6 @@ export class GoalService {
1021
825
  }
1022
826
  this.emitGoalStatus();
1023
827
  }
1024
- // Aborted externally (✗ / clear_goal / idle-timeout): do NOT set a goal. The raw
1025
- // draft card stays in the launching conversation's flow, so the user can read
1026
- // it back (and retry) instead of having to retype it (issue #292).
1027
828
  if (ac.signal.aborted || this.wizardCancelled) {
1028
829
  this.host.emit({
1029
830
  type: "notice",
@@ -1044,10 +845,6 @@ export class GoalService {
1044
845
  });
1045
846
  return;
1046
847
  }
1047
- // The survey belongs to the conversation that launched it. The user is EXPECTED
1048
- // to switch away while the questions are being answered (check code, read docs),
1049
- // so "active ≠ launcher" is the normal case, not an error: land the refined goal
1050
- // on the launcher instead of discarding the work (issue #292).
1051
848
  const targetConv = this.host.getConv(wizardConversationId);
1052
849
  if (!targetConv) {
1053
850
  this.host.emit({
@@ -1062,19 +859,12 @@ export class GoalService {
1062
859
  return;
1063
860
  }
1064
861
  const switchedAway = this.host.activeConvId() !== wizardConversationId;
1065
- // Auto-set the refined goal. The wizard workflow implies "set a goal and
1066
- // work until it passes", so default LOCKED=true unless the user explicitly
1067
- // turned the lock off (a lock lets the review loop keep revising to pass;
1068
- // without it the review is single-shot).
1069
862
  const wantLocked = opts?.locked === undefined ? true : opts.locked;
1070
863
  const committed = await this.commitGoal(refinedGoal, {
1071
864
  reviewModel: wgoal.reviewModel ?? undefined,
1072
865
  maxRounds: opts?.maxRounds,
1073
866
  locked: wantLocked,
1074
- // 目标模式 2.0:执行者模型随调研一起带过去(wizard 与目标条共用记忆偏好)。
1075
867
  execModel: wgoal.execModel ?? undefined,
1076
- // Land the goal on the conversation that launched the survey, even if the
1077
- // user is looking at another one right now (issue #292).
1078
868
  targetConvId: wizardConversationId,
1079
869
  autoStart: false,
1080
870
  });
@@ -1083,7 +873,6 @@ export class GoalService {
1083
873
  if (parsedSteps.length > 0) {
1084
874
  this.host.setPlan?.(wizardConversationId, parsedSteps);
1085
875
  }
1086
- // Preserve plan-before-execution ordering, and retain the commit token across preemption.
1087
876
  if (!this.isCurrentDelegated(committed.conv, committed.generation))
1088
877
  return;
1089
878
  await this.preemptMainRunForGoal(committed.conv, committed.generation);
@@ -1103,9 +892,6 @@ export class GoalService {
1103
892
  : `🎯 Survey done, goal set: ${refinedGoal.slice(0, 80)}${refinedGoal.length > 80 ? "…" : ""}`,
1104
893
  });
1105
894
  }
1106
- /** Persist goal/review preference defaults (model, rounds cap, locked) without
1107
- * touching the active goal — so changes in the goal bar are remembered across
1108
- * reloads. maxRounds 0 = unlimited. Emits goal_status so the UI stays synced. */
1109
895
  async setGoalPrefs(opts, target) {
1110
896
  if (!this.goalEnabled())
1111
897
  return;
@@ -1121,8 +907,6 @@ export class GoalService {
1121
907
  }
1122
908
  if (opts?.locked !== undefined)
1123
909
  goal.locked = opts.locked;
1124
- // 执行者模型:目标进行中不换轨(换模型对已存在的执行对话无效)——只记偏好,
1125
- // 下一个目标生效并明确告知。
1126
910
  const hasExecOpt = opts?.execModel !== undefined;
1127
911
  if (goal.goal && hasExecOpt) {
1128
912
  this.host.emit({
@@ -1149,30 +933,21 @@ export class GoalService {
1149
933
  });
1150
934
  this.emitGoalStatus();
1151
935
  }
1152
- /** Clear the specified conversation's goal, or the active one by default.
1153
- * Cancels its review loop and any running goal wizard. */
1154
936
  async clearGoal(target) {
1155
937
  const conv = typeof target === "string" ? this.host.getConv(target) : (target ?? this.host.activeConv());
1156
- // Missing/stale explicit targets must never fall back to the active conversation.
1157
938
  if (!conv || this.host.isDisposed() || this.host.getConv(conv.id) !== conv)
1158
939
  return;
1159
940
  const gen = ++conv.goalGeneration;
1160
- // 委托执行:停掉在飞的执行者(循环靠代次作废 + 代次守卫退出)。
1161
- // await 落定,保证旧执行者已移出会话表,后续重设目标不再误报名额(issue #464)。
1162
941
  await this.stopDelegated(conv);
1163
942
  if (!this.isCurrentGoalRequest(conv, gen))
1164
943
  return;
1165
944
  this.resetLoopCounters(conv);
1166
945
  this.clearGoalFields(conv);
1167
946
  this.emitGoalStatus();
1168
- // Abort a running wizard for real (✗ in the goal bar while scoping).
1169
947
  if (this.wizardOwnerId === conv.id) {
1170
948
  await this.abortWizard();
1171
949
  }
1172
950
  }
1173
- /** 真正中止在飞的调研向导(对话框按取消返回 + agent run 停掉),返回是否停掉了一个。
1174
- * 注意:不碰 wizardOwnerId —— 它由向导 run 自己的 finally 清理;提前清掉会让
1175
- * 旧向导还没退完时就能开新向导(两个 run 并发)。 */
1176
951
  async abortWizard() {
1177
952
  if (this.wizardOwnerId === null)
1178
953
  return false;
@@ -1188,21 +963,13 @@ export class GoalService {
1188
963
  this.wizardAbort = null;
1189
964
  return true;
1190
965
  }
1191
- /**
1192
- * 目标模式总开关关闭:停掉所有在飞的委托循环并收掉各自的执行者(幂等),
1193
- * 在跑的调研向导一并中止。已受阻/未通过的目标只留文本(不运行,无需处理),
1194
- * 开关重开后仍可继续处置。无在飞目标/调研时无声无 notice。
1195
- */
1196
966
  async stopAllGoals() {
1197
967
  let stopped = 0;
1198
- // 快照迭代:await stopDelegated 期间,循环退出的回调可能增删这张表。
1199
968
  for (const convId of Array.from(this.delegatedLoops.keys())) {
1200
969
  const conv = this.host.getConv(convId);
1201
970
  if (!conv)
1202
971
  continue;
1203
- const gen = ++conv.goalGeneration; // 作废在飞回调(循环靠代次守卫退出)
1204
- // 逐个 await 停/收落定(stopDelegated 已按会话串行化,issue #464):
1205
- // 停执行者 + 唤醒 verdict 等待者 + 清 roles/phase
972
+ const gen = ++conv.goalGeneration;
1206
973
  await this.stopDelegated(conv);
1207
974
  if (!this.isCurrentGoalRequest(conv, gen))
1208
975
  continue;
@@ -1222,26 +989,14 @@ export class GoalService {
1222
989
  this.host.flushSnapshot();
1223
990
  }
1224
991
  }
1225
- /**
1226
- * agent_end hook. `aborted` = the finished run ended by manual stop; in that
1227
- * case any active goal of THIS conversation is cleared so the review loop
1228
- * stops too (a half-finished run must not be reviewed — endless loop).
1229
- * Otherwise, spawn the isolated reviewer if a goal is pending. Returns a
1230
- * notice text for the host to emit (manual-stop case), or null.
1231
- */
1232
992
  onAgentEnd(conv, aborted) {
1233
993
  const g = conv.goal;
1234
994
  if (aborted) {
1235
- // #591:设目标时服务端主动中断主对话的旧运行以让位给执行者 —— 该次 abort
1236
- // 是预期交接,不是用户按了 Stop,不得把刚设好的目标清掉。
1237
995
  if (conv.preemptingMainRun) {
1238
996
  conv.preemptingMainRun = false;
1239
997
  return null;
1240
998
  }
1241
999
  if (g.goal && g.conversationId === conv.id) {
1242
- // 中止的若是审查回合(服务端正在等 verdict):只作废这一次审查(走无 JSON
1243
- // 重试/受阻),目标与执行对话都保留 —— 用户按 Stop 往往只是想掐掉那段机器
1244
- // JSON 回合,不是要把整个目标连执行者一起清掉。
1245
1000
  if (conv.awaitingVerdict) {
1246
1001
  const settle = this.verdictWaiters.get(conv.id);
1247
1002
  this.verdictWaiters.delete(conv.id);
@@ -1254,9 +1009,6 @@ export class GoalService {
1254
1009
  };
1255
1010
  }
1256
1011
  conv.goalGeneration += 1;
1257
- // 委托执行:手动停止也要把在飞的执行者停掉(否则它还在后台改工作区)。
1258
- // 本钩子是同步上下文,fire-and-forget 即可:stopDelegated 已按会话
1259
- // 串行化(issue #464),重设/清除目标的一方会先等这次 dismiss 落定。
1260
1012
  this.stopDelegated(conv);
1261
1013
  this.resetLoopCounters(conv);
1262
1014
  g.conversationId = null;
@@ -1265,7 +1017,6 @@ export class GoalService {
1265
1017
  g.verdict = "pending";
1266
1018
  g.feedback = undefined;
1267
1019
  g.phase = "idle";
1268
- // roles 已由上面的 stopDelegated 经 detachRoleExec 清掉。
1269
1020
  g.status = "已手动停止,目标审查已中止";
1270
1021
  g.statusEn = "Stopped manually, goal review aborted";
1271
1022
  this.emitGoalStatus();
@@ -1276,19 +1027,11 @@ export class GoalService {
1276
1027
  }
1277
1028
  return null;
1278
1029
  }
1279
- // 本对话就是审查者:只有服务端把审查指令交给它之后结束的那个回合才是审查回合
1280
- // (awaitingVerdict 非空);其余 agent_end(用户在执行期聊天/插话)一律不当
1281
- // 审查结果,也不会重新触发任何循环(目标模式 2.0 只有委托一条路径)。
1282
1030
  if (g.goal && g.conversationId === conv.id && conv.awaitingVerdict) {
1283
1031
  this.deliverDelegatedVerdict(conv);
1284
1032
  }
1285
1033
  return null;
1286
1034
  }
1287
- // =====================================================================
1288
- /** Insert a wizard progress card into the MAIN conversation flow and render it
1289
- * IMMEDIATELY (the main session is idle while the wizard runs in its own
1290
- * session, so — unlike nextTurn, which queues until the next user prompt —
1291
- * sending without a delivery option appends + persists + emits at once). */
1292
1035
  async pushWizardCard(sess, text, details) {
1293
1036
  try {
1294
1037
  await sess.sendCustomMessage({
@@ -1298,34 +1041,19 @@ export class GoalService {
1298
1041
  details: { type: "goal-wizard", ...details },
1299
1042
  });
1300
1043
  }
1301
- catch {
1302
- // Card insertion is cosmetic — never block the question flow on it.
1303
- }
1304
- }
1305
- /** 目标模式 2.0(唯一路径:主对话 = 审查者 + 常驻执行对话)
1306
- //
1307
- // 干活的是服务端拉起的常驻执行对话(落盘、左栏可见可点开)。服务端持有整台
1308
- // 状态机,一轮 = 派活 → 等它结束 → 取样(工作区 diff 指纹 + **执行者会话**
1309
- // 错误特征)→ 把审查指令交给主对话 → 解析 verdict → 判定(pass / 再来一轮 /
1310
- // 熔断 / 预算用尽)。模型不得自循环,轮次与熔断全在服务端
1311
- // (详见 docs/goal-conversation-design.md §3/§4)。
1312
- // =====================================================================
1313
-
1314
- /** 角色对话桥是否齐备(缺一即无法运行目标模式:setGoal 直接拒绝)。 */
1044
+ catch { }
1045
+ }
1315
1046
  roleBridgeReady() {
1316
1047
  const h = this.host;
1317
1048
  return !!(h.spawnRoleAgent && h.waitRoleAgent && h.sendRoleAgent && h.readRoleAgent && h.hasConv);
1318
1049
  }
1319
- /** 角色轮等待上限:与工具看门狗同口径(默认 20 分钟)。 */
1320
1050
  roleDeadline() {
1321
1051
  const v = this.host.roleDeadlineMs?.();
1322
1052
  return typeof v === "number" && v > 0 ? v : 20 * 60_000;
1323
1053
  }
1324
- /** Mutation requests remain valid even before a goal exists. Never adopt a newer generation. */
1325
1054
  isCurrentGoalRequest(conv, goalGeneration) {
1326
1055
  return !this.host.isDisposed() && this.host.getConv(conv.id) === conv && conv.goalGeneration === goalGeneration;
1327
1056
  }
1328
- /** 代次守卫:目标没被改/清、会话还在才算本轮有效。 */
1329
1057
  isCurrentDelegated(conv, goalGeneration) {
1330
1058
  return this.isCurrentGoalRequest(conv, goalGeneration) && conv.goal.conversationId === conv.id && !!conv.goal.goal;
1331
1059
  }
@@ -1344,10 +1072,6 @@ export class GoalService {
1344
1072
  return false;
1345
1073
  }
1346
1074
  }
1347
- /**
1348
- * #591:首轮派发目标执行者前,若主对话仍在执行设目标之前的旧任务,先中断它并提示用户。
1349
- * 仅在首轮派发前生效(按 goalGeneration 去重),委托执行期间用户在主对话发起的新聊天不受影响。
1350
- */
1351
1075
  async preemptMainRunForGoal(conv, goalGeneration) {
1352
1076
  if (!this.isCurrentDelegated(conv, goalGeneration))
1353
1077
  return;
@@ -1366,7 +1090,6 @@ export class GoalService {
1366
1090
  }
1367
1091
  }
1368
1092
  catch {
1369
- // best-effort
1370
1093
  }
1371
1094
  finally {
1372
1095
  conv.preemptingMainRun = false;
@@ -1380,7 +1103,6 @@ export class GoalService {
1380
1103
  textEn: "🎯 Goal set: stopped the main conversation's current run so the goal executor can take over",
1381
1104
  });
1382
1105
  }
1383
- /** 启动委托循环(同一对话同时只允许一个在飞;旧循环退场中到来的请求排队接力)。 */
1384
1106
  startDelegatedLoop(conv, goalGeneration, goalText) {
1385
1107
  if (!this.isCurrentDelegated(conv, goalGeneration))
1386
1108
  return;
@@ -1396,7 +1118,6 @@ export class GoalService {
1396
1118
  .finally(() => {
1397
1119
  if (this.delegatedLoops.get(convId) === loop)
1398
1120
  this.delegatedLoops.delete(convId);
1399
- // 接力:退场期间排队的新请求现在启动(代次已过期则首个守卫即退出,无副作用)。
1400
1121
  const pending = this.delegatedPending.get(convId);
1401
1122
  if (pending) {
1402
1123
  this.delegatedPending.delete(convId);
@@ -1407,7 +1128,6 @@ export class GoalService {
1407
1128
  });
1408
1129
  this.delegatedLoops.set(conv.id, loop);
1409
1130
  }
1410
- /** 观测/测试用:等某对话的委托循环走到「已把审查指令交给主对话」这一步。 */
1411
1131
  whenAwaitingVerdict(convId, timeoutMs = 5000) {
1412
1132
  if (this.verdictWaiters.has(convId))
1413
1133
  return Promise.resolve(true);
@@ -1438,11 +1158,6 @@ export class GoalService {
1438
1158
  set.add(fire);
1439
1159
  });
1440
1160
  }
1441
- /**
1442
- * 观测/测试用:等某对话的委托循环收束(循环已结束后立刻返回)。
1443
- * 注意:循环在「等执行者」或「等 verdict」时不会收束 —— 那两个时点用
1444
- * whenAwaitingVerdict / 脚本化的 waitRoleAgent 推进。
1445
- */
1446
1161
  async whenDelegatedSettled(convId) {
1447
1162
  const loop = this.delegatedLoops.get(convId);
1448
1163
  if (loop)
@@ -1455,8 +1170,6 @@ export class GoalService {
1455
1170
  for (const fn of set)
1456
1171
  fn();
1457
1172
  }
1458
- /** 停掉该对话的委托循环并收掉常驻执行者(幂等;清目标/重设目标/中止时调)。 */
1459
- /** 一轮循环的计数器归零(新目标/清目标/中止/总开关停摆时调;目标文本与历史不动)。 */
1460
1173
  resetLoopCounters(conv) {
1461
1174
  conv.stagnantRounds = 0;
1462
1175
  conv.failedRounds = 0;
@@ -1467,7 +1180,6 @@ export class GoalService {
1467
1180
  conv.lastErrorSnippet = undefined;
1468
1181
  conv.sameErrorRounds = 0;
1469
1182
  }
1470
- /** 目标字段清空(清目标/总开关停摆时调;历史与偏好保留)。 */
1471
1183
  clearGoalFields(conv) {
1472
1184
  const goal = conv.goal;
1473
1185
  goal.reviewing = false;
@@ -1483,12 +1195,9 @@ export class GoalService {
1483
1195
  goal.wizard.status = "";
1484
1196
  goal.wizard.statusEn = "";
1485
1197
  }
1486
- /** 轮次预算(locked=false = 单次;locked + maxRounds>0 = 有限轮并夹到 50;否则不限)。 */
1487
1198
  roundBudget(goal) {
1488
1199
  return goal.locked ? (goal.maxRounds > 0 ? Math.min(goal.maxRounds, 50) : Number.POSITIVE_INFINITY) : 1;
1489
1200
  }
1490
- /** 摘掉常驻执行者引用并清 roles(停/收由调用方按 sync/async 上下文自行处理,
1491
- * 停与收本身都是 best-effort)。返回被摘掉的执行者对话 id(没有则 undefined)。 */
1492
1201
  detachRoleExec(conv) {
1493
1202
  const exec = conv.roleExec;
1494
1203
  conv.roleExec = undefined;
@@ -1496,12 +1205,6 @@ export class GoalService {
1496
1205
  return exec?.convId;
1497
1206
  }
1498
1207
  stopInflight = new Map();
1499
- /**
1500
- * 停掉委托执行者(stop + dismiss + 唤醒等待者)。同一会话并发调用时按序串行:
1501
- * 上一次 stop/dismiss 未落定前,下一次先等它 —— 否则重设目标时旧执行者尚未
1502
- * 移出会话表,随后 spawn 的名额检查会数到它而误报容量上限(issue #464)。
1503
- * 同步上下文(onAgentEnd 等钩子)可以继续 fire-and-forget,串行化由这里兜住。
1504
- */
1505
1208
  stopDelegated(conv) {
1506
1209
  const prev = this.stopInflight.get(conv.id);
1507
1210
  const run = prev ? prev.catch(() => { }).then(() => this.stopDelegatedNow(conv)) : this.stopDelegatedNow(conv);
@@ -1514,11 +1217,8 @@ export class GoalService {
1514
1217
  }
1515
1218
  async stopDelegatedNow(conv) {
1516
1219
  const gen = conv.goalGeneration;
1517
- // 排队的启动请求一并作废:setGoal 会在后面按新代次重新排,clearGoal 则不需要。
1518
1220
  this.delegatedPending.delete(conv.id);
1519
1221
  conv.awaitingVerdict = undefined;
1520
- // 审查回合里排队的用户插话在这里也顺带发出(take 语义,与 deliverAndWait 的
1521
- // flush 互斥 —— 先到先得,清目标/停循环不断用户的话)。
1522
1222
  void this.flushDeferredPrompts(conv);
1523
1223
  const settle = this.verdictWaiters.get(conv.id);
1524
1224
  if (settle) {
@@ -1532,7 +1232,6 @@ export class GoalService {
1532
1232
  }
1533
1233
  catch { }
1534
1234
  try {
1535
- // issue #464: 必须等待执行者完全 dismiss 移出会话表,避免立即重设目标时误报容量超限
1536
1235
  await this.host.dismissRoleAgent?.(execId);
1537
1236
  }
1538
1237
  catch { }
@@ -1540,7 +1239,6 @@ export class GoalService {
1540
1239
  if (this.isCurrentGoalRequest(conv, gen))
1541
1240
  conv.goal.phase = "idle";
1542
1241
  }
1543
- /** 会话过户时清理目标审查态并唤醒等待者(issue #457)。 */
1544
1242
  notifyTakeover(conv) {
1545
1243
  conv.goalGeneration = (conv.goalGeneration ?? 0) + 1;
1546
1244
  conv.goal.reviewing = false;
@@ -1560,14 +1258,12 @@ export class GoalService {
1560
1258
  }
1561
1259
  conv.goal.phase = "idle";
1562
1260
  }
1563
- /** 会话关闭/移除时(removeConversation)彻底终止目标循环并清理关联的执行者与向导。 */
1564
1261
  notifyConversationRemoved(conv) {
1565
1262
  this.notifyTakeover(conv);
1566
1263
  if (this.wizardOwnerId === conv.id) {
1567
1264
  void this.abortWizard();
1568
1265
  }
1569
1266
  }
1570
- /** 读某会话累计用量(取不到返回 undefined;getSessionStats 会遍历转写,只在轮次边界调)。 */
1571
1267
  sessionUsage(session) {
1572
1268
  try {
1573
1269
  const t = session.getSessionStats()?.tokens;
@@ -1575,12 +1271,9 @@ export class GoalService {
1575
1271
  return { input: t.input, output: t.output };
1576
1272
  }
1577
1273
  }
1578
- catch {
1579
- // Ignore
1580
- }
1274
+ catch { }
1581
1275
  return undefined;
1582
1276
  }
1583
- /** 把一轮增量并入本目标累计(任一端缺失即跳过,不污染总数)。 */
1584
1277
  addGoalUsage(conv, before) {
1585
1278
  const after = this.sessionUsage(conv.session);
1586
1279
  if (!after || !before)
@@ -1590,7 +1283,6 @@ export class GoalService {
1590
1283
  output: (conv.goalUsage?.output ?? 0) + Math.max(0, after.output - before.output),
1591
1284
  };
1592
1285
  }
1593
- /** 轮次标签("/M";不限轮时为空串)。 */
1594
1286
  roundsLabel(budget) {
1595
1287
  return budget > 0 && Number.isFinite(budget) ? `/${budget}` : "";
1596
1288
  }
@@ -1600,13 +1292,10 @@ export class GoalService {
1600
1292
  if (!this.isCurrentDelegated(conv, goalGeneration))
1601
1293
  return;
1602
1294
  const g = conv.goal;
1603
- // quiesce(服务排空):中途不再派单 —— 存量回合跑完,下一轮不再派
1604
- // (设计文档 §4.6;与 prompt/编辑入口「新的拒绝、存量跑完」同口径)。
1605
1295
  if (this.host.quiesceBlocked()) {
1606
1296
  await this.finishDelegated(conv, goalGeneration, "blocked", g.round, this.roleFailureText("quiesce"), goalText);
1607
1297
  return;
1608
1298
  }
1609
- // 轮次预算:locked=false = 单次(一轮就收);locked=true 且 maxRounds>0 = 有限轮。
1610
1299
  const budget = this.roundBudget(g);
1611
1300
  if (g.round >= budget) {
1612
1301
  await this.finishDelegated(conv, goalGeneration, "exhausted", g.round, feedback, goalText);
@@ -1621,24 +1310,17 @@ export class GoalService {
1621
1310
  g.status = `执行中(第 ${round}${this.roundsLabel(budget)} 轮)…`;
1622
1311
  g.statusEn = `Executing (round ${round}${this.roundsLabel(budget)})…`;
1623
1312
  this.emitGoalStatus();
1624
- // ① 派发:首轮 spawn 常驻执行者,之后向同一个它追加回合(记忆连续)。
1625
1313
  const execId = await this.dispatchExecutor(conv, goalGeneration, goalText, round, budget, feedback);
1626
1314
  if (!execId)
1627
- return; // 已降级 / 已收尾
1315
+ return;
1628
1316
  if (!this.isCurrentDelegated(conv, goalGeneration))
1629
1317
  return;
1630
- // ② 等执行者本轮结束(事件驱动,上限 = 看门狗口径)。
1631
1318
  const outcome = await this.host.waitRoleAgent(execId, this.roleDeadline());
1632
1319
  if (!this.isCurrentDelegated(conv, goalGeneration))
1633
1320
  return;
1634
- // ③ 取样:工作区 diff 指纹 + 执行者会话的错误特征(主对话是审查者,它的
1635
- // 工具报错不代表执行受挫 —— 取数口径见设计文档 §4.5)。
1636
1321
  const sample = await this.sampleRound(conv, execId);
1637
1322
  if (!this.isCurrentDelegated(conv, goalGeneration))
1638
1323
  return;
1639
- // 熔断先于一切分支:停滞 / 同错 / 执行连败连续两轮 → 直接终止(不问审查者,
1640
- // 省 token;判定权始终在服务端)。注意它必须在 outcome 分支之前 —— 否则
1641
- // error/timeout 轮会经由下面的 continue 跳过熔断,在「不限轮」下无限空转。
1642
1324
  if ((conv.sameErrorRounds ?? 0) >= 2 ||
1643
1325
  (conv.stagnantRounds ?? 0) >= 2 ||
1644
1326
  (conv.failedRounds ?? 0) >= GoalService.EXEC_FAILED_ROUNDS_LIMIT) {
@@ -1646,8 +1328,6 @@ export class GoalService {
1646
1328
  return;
1647
1329
  }
1648
1330
  if (outcome !== "done") {
1649
- // 「人为中止」与「对话失联」是终点事件:用户按了子代理的 ⏹ / 把执行对话关了,
1650
- // 就是要停下 —— 这里绝不能再派一轮(否则看起来像「关了自己又启动」)。
1651
1331
  if (outcome === "gone" || outcome === "canceled") {
1652
1332
  const reason = outcome === "gone"
1653
1333
  ? this.roleFailureText("exec-gone")
@@ -1655,8 +1335,6 @@ export class GoalService {
1655
1335
  await this.finishDelegated(conv, goalGeneration, "blocked", round, reason, goalText);
1656
1336
  return;
1657
1337
  }
1658
- // 超时 / 报错:不花审查 token,直接进下一轮(预算内)。连败计数在这里累加,
1659
- // 阈值见本轮顶部的熔断(连续 2 轮都起不来就停,不烧无限 token)。
1660
1338
  conv.failedRounds = (conv.failedRounds ?? 0) + 1;
1661
1339
  if (conv.failedRounds >= GoalService.EXEC_FAILED_ROUNDS_LIMIT) {
1662
1340
  await this.finishDelegated(conv, goalGeneration, "blocked", round, this.roleFailureText(outcome === "timeout" ? "timeout-repeat" : "error-repeat", sample.errorSnippet ?? ""), goalText);
@@ -1665,11 +1343,9 @@ export class GoalService {
1665
1343
  feedback = this.roleFailureText(outcome === "timeout" ? "timeout" : "error", sample.errorSnippet ?? "");
1666
1344
  if (outcome === "timeout")
1667
1345
  await this.host.stopRoleAgent?.(execId).catch(() => { });
1668
- continue; // 顶部自增轮次后重新派活
1346
+ continue;
1669
1347
  }
1670
- // 执行者本轮正常结束:连败清零。
1671
1348
  conv.failedRounds = 0;
1672
- // ④⑤ 把审查指令交给主对话(= 审查者),等它的 verdict。
1673
1349
  g.phase = "reviewing";
1674
1350
  g.reviewing = true;
1675
1351
  g.status = `审查中(第 ${round}${this.roundsLabel(budget)} 轮)…`;
@@ -1682,10 +1358,7 @@ export class GoalService {
1682
1358
  await this.finishDelegated(conv, goalGeneration, "blocked", round, this.roleFailureText(`review-${verdict}`), goalText);
1683
1359
  return;
1684
1360
  }
1685
- // #543 §2:空 feedback 兜底 —— verdict JSON 允许 `{"verdict":"fail","feedback":""}`,
1686
- // 照原样传下去,下一轮执行者只会收到「上一轮审查意见:」+ 空行,白烧一轮。
1687
1361
  const verdictFeedback = this.ensureReviewerFeedback(verdict.verdict, verdict.feedback, feedback);
1688
- // 审查结论卡:把 verdict JSON 翻译成人话框住(裸 JSON 留在流里,但不再是唯一载体)。
1689
1362
  if (this.isCurrentDelegated(conv, goalGeneration)) {
1690
1363
  await this.pushReviewCard(conv, this.reviewCardText(verdict.verdict, round, budget, verdictFeedback), {
1691
1364
  phase: "result",
@@ -1700,17 +1373,13 @@ export class GoalService {
1700
1373
  return;
1701
1374
  }
1702
1375
  feedback = verdictFeedback;
1703
- // fail:回到循环顶部(预算检查在那里兜底)。
1704
1376
  }
1705
1377
  }
1706
- /** 派发一轮执行:首轮 spawn 常驻执行者,之后 steer 同一个(记忆连续)。 */
1707
1378
  async dispatchExecutor(conv, goalGeneration, goalText, round, budget, feedback) {
1708
1379
  const host = this.host;
1709
1380
  const g = conv.goal;
1710
1381
  const existing = conv.roleExec;
1711
1382
  if (existing) {
1712
- // 执行对话被移出 / 服务重启 → 执行者记忆已丢:重建会静默换个「新人」,
1713
- // 按受阻收尾比悄悄换人可靠(设计文档 §4.6 失效矩阵)。
1714
1383
  const alive = host.hasConv ? host.hasConv(existing.convId) : true;
1715
1384
  if (!alive) {
1716
1385
  await this.finishDelegated(conv, goalGeneration, "blocked", round, this.roleFailureText("exec-gone"), goalText);
@@ -1724,7 +1393,6 @@ export class GoalService {
1724
1393
  this.beginRoundVitals(conv, existing.convId);
1725
1394
  return existing.convId;
1726
1395
  }
1727
- // #591:向导结束 / 排队接力等路径直接进 startDelegatedLoop 时,首轮 spawn 前同样保证主对话旧运行已让位。
1728
1396
  await this.preemptMainRunForGoal(conv, goalGeneration);
1729
1397
  if (!this.isCurrentDelegated(conv, goalGeneration))
1730
1398
  return undefined;
@@ -1735,13 +1403,8 @@ export class GoalService {
1735
1403
  cwd: conv.cwd,
1736
1404
  model: g.execModel ?? null,
1737
1405
  parentId: conv.id,
1738
- // 落盘对话在左栏/历史里没有「子代理」微标,用带前缀的标题保持可辨识。
1739
1406
  title: this.roleConvTitle(goalText),
1740
1407
  });
1741
- // #490/案1:spawn 的长 await 期间目标可能被重设/清除(goalGeneration 已变,
1742
- // stopDelegated 当时无可停执行者)——老循环不得把带着老目标首轮 prompt 的
1743
- // 执行者写回 conv.roleExec,否则新循环会把它当现役执行者 steer(上下文被
1744
- // 老目标污染,新目标首轮产出混入老目标工作)。就地停掉并让老循环按代次退出。
1745
1408
  if (conv.goalGeneration !== goalGeneration) {
1746
1409
  void host.stopRoleAgent?.(convId).catch(() => { });
1747
1410
  return undefined;
@@ -1753,13 +1416,10 @@ export class GoalService {
1753
1416
  return convId;
1754
1417
  }
1755
1418
  catch (err) {
1756
- // 配额满 / runtime 创建失败:目标模式只有委托一条路径,没有可降级对象。
1757
1419
  await this.abortOnSpawnFailure(conv, goalGeneration, goalText, err instanceof Error ? err.message : String(err));
1758
1420
  return undefined;
1759
1421
  }
1760
1422
  }
1761
- /** 派活后记一笔本轮 vitals 基线:执行者用量起点 + 快照(目标条实时进度用)。
1762
- * 取数失败不阻断派活(read 缺字段即跳过,老 host 照常工作)。 */
1763
1423
  beginRoundVitals(conv, execId) {
1764
1424
  let read;
1765
1425
  try {
@@ -1771,8 +1431,6 @@ export class GoalService {
1771
1431
  conv.execUsageBefore = read?.usage;
1772
1432
  this.snapshotExecutor(conv, execId, read);
1773
1433
  }
1774
- /** 刷新执行者快照进 `goal.roles.executor`(目标条实时进度用;轮次边界调用)。
1775
- * 在跑且有最近工具 → 「xx 运行中」;否则取自述头 60 字;都没有则清空(不留脏数据)。 */
1776
1434
  snapshotExecutor(conv, execId, read) {
1777
1435
  const g = conv.goal;
1778
1436
  const role = g.roles?.executor;
@@ -1792,7 +1450,6 @@ export class GoalService {
1792
1450
  }
1793
1451
  g.roles = { ...g.roles, executor: { ...role, streaming, activity, activityEn } };
1794
1452
  }
1795
- /** 取样一轮:工作区 diff 指纹 + 执行者会话错误特征(熔断信号独立于 verdict)。 */
1796
1453
  async sampleRound(conv, execId) {
1797
1454
  const read = this.host.readRoleAgent?.(execId);
1798
1455
  const output = read?.text ?? "";
@@ -1814,9 +1471,6 @@ export class GoalService {
1814
1471
  conv.sameErrorRounds = currentError ? 1 : 0;
1815
1472
  }
1816
1473
  conv.lastErrorSnippet = currentError;
1817
- // 非 git 目录(git diff 恒为空)下没有可信的工作区进展信号:跳过停滞计数
1818
- // (不清零也不累加),否则纯问答/回答类目标会在第 2 轮被误判「无进展」。
1819
- // 错误特征与连败熔断不受影响,仍正常计数。
1820
1474
  let repoAvailable = true;
1821
1475
  try {
1822
1476
  if (this.host.isGitRepo)
@@ -1832,7 +1486,6 @@ export class GoalService {
1832
1486
  conv.stagnantRounds = noChange ? (conv.stagnantRounds ?? 0) + 1 : 0;
1833
1487
  conv.lastDiff = trimmed;
1834
1488
  }
1835
- // 本轮执行者用量 = 取样点累计 - 派活点累计(取不到任一端即跳过,不污染总数)。
1836
1489
  const after = read?.usage;
1837
1490
  const before = conv.execUsageBefore;
1838
1491
  if (after && before) {
@@ -1844,15 +1497,11 @@ export class GoalService {
1844
1497
  };
1845
1498
  }
1846
1499
  conv.execUsageBefore = undefined;
1847
- // 取样即轮次边界:执行者快照同步刷新(目标条实时进度用)。
1848
1500
  this.snapshotExecutor(conv, execId, read);
1849
1501
  return { output, errorSnippet: currentError };
1850
1502
  }
1851
- /** 审查:把审查指令交给主对话,等 verdict;无 JSON 允许重试一次。 */
1852
1503
  async askDelegatedReview(conv, goalGeneration, round, budget, execOutput, execId) {
1853
1504
  for (let attempt = 0; attempt < 2; attempt++) {
1854
- // 委托执行下用户仍可自由聊天:先等主对话空闲,否则审查指令会被当成
1855
- // steer 插进用户自己的回合里(语义冲突)。
1856
1505
  const idle = await this.waitMainIdle(conv);
1857
1506
  if (!this.isCurrentDelegated(conv, goalGeneration))
1858
1507
  return "gone";
@@ -1868,8 +1517,6 @@ export class GoalService {
1868
1517
  }
1869
1518
  return "invalid";
1870
1519
  }
1871
- /** 执行者会话最近的工具/命令证据(#543 §1)。宿主未接线 / 读失败 / 空会话 → 空串,
1872
- * 提示词据此跳过整段(不注入空标题、不改变老行为)。 */
1873
1520
  readExecutorEvidence(execId) {
1874
1521
  try {
1875
1522
  return this.host.readRoleEvidence?.(execId)?.trim() ?? "";
@@ -1878,11 +1525,6 @@ export class GoalService {
1878
1525
  return "";
1879
1526
  }
1880
1527
  }
1881
- /** 审查结论 feedback 为空时的兜底(#543 §2;调用点见 runDelegatedLoop)。
1882
- * - 有内容 → 原样返回(不动审查者的措辞);
1883
- * - pass 且无说明 → 不编造通过理由,只补一句中性标注;
1884
- * - fail 且上一轮有意见 → 沿用上一轮(标注是沿用的,避免执行者以为拿到了新指令);
1885
- * - fail 且两轮都空 → 给一条可执行的失败说明(复核目标 + 补证据),别让执行者空转。 */
1886
1528
  ensureReviewerFeedback(verdict, feedback, prevFeedback) {
1887
1529
  const fb = feedback.trim();
1888
1530
  if (fb)
@@ -1896,7 +1538,6 @@ export class GoalService {
1896
1538
  }
1897
1539
  return pick(this.lang(), "审查者判 fail 但未给出说明。请复核目标的每一条要求,补齐尚未完成或尚未验证的部分,并在自述里给出可核验的证据(跑过的命令与输出)。", "The reviewer returned fail without a note. Re-check every requirement in the goal, finish what is unfinished or unverified, and back it up with verifiable evidence (the commands you ran and their output).", "goal.role.review.feedback.empty");
1898
1540
  }
1899
- /** 等主对话空闲(事件驱动,不轮询);超上限返回 false。 */
1900
1541
  async waitMainIdle(conv) {
1901
1542
  const end = Date.now() + this.roleDeadline();
1902
1543
  for (;;) {
@@ -1909,10 +1550,6 @@ export class GoalService {
1909
1550
  return false;
1910
1551
  }
1911
1552
  }
1912
- /** 投递审查指令并等 onAgentEnd 送来 verdict(登记 waiter 后再投递,防抢跑)。 */
1913
- /** 往主对话消息流里插一张目标审查卡(customType "goal-review",前端有专属卡片样式)。
1914
- * 纯妆点:审查指令(user 消息)与 verdict JSON(assistant 消息)之间本来没有任何
1915
- * 视觉分隔,用户看到的是裸 JSON;起止两张卡把一轮审查框起来。失败不阻断循环。 */
1916
1553
  async pushReviewCard(conv, text, details) {
1917
1554
  try {
1918
1555
  await conv.session.sendCustomMessage({
@@ -1922,12 +1559,8 @@ export class GoalService {
1922
1559
  details: { type: "goal-review", ...details },
1923
1560
  });
1924
1561
  }
1925
- catch {
1926
- // Card insertion is cosmetic — never block the review loop on it.
1927
- }
1562
+ catch { }
1928
1563
  }
1929
- /** 取出该对话在审查回合里排队的用户插话并按序发出(take 语义,防重复投递)。
1930
- * followUp 投递:在跑回合结束后送达,不污染已结算的 verdict;空闲则直接开新回合。 */
1931
1564
  async flushDeferredPrompts(conv) {
1932
1565
  const queued = conv.deferredPrompts;
1933
1566
  conv.deferredPrompts = undefined;
@@ -1937,7 +1570,7 @@ export class GoalService {
1937
1570
  try {
1938
1571
  const ok = await this.host.sendRoleAgent(conv.id, text, "followUp");
1939
1572
  if (!ok)
1940
- break; // 对话已不在,剩下发不出去,直接丢(排队时已告知用户)
1573
+ break;
1941
1574
  }
1942
1575
  catch {
1943
1576
  break;
@@ -1948,17 +1581,11 @@ export class GoalService {
1948
1581
  async deliverAndWait(conv, round, text) {
1949
1582
  const host = this.host;
1950
1583
  conv.awaitingVerdict = { round };
1951
- // 审查者(主对话)本轮用量基线:verdict 落定点相减即审查增量。
1952
1584
  conv.reviewUsageBefore = this.sessionUsage(conv.session);
1953
- // 审查开始卡:先框住本轮,再投递审查指令(主对话空闲,顺序即流序)。
1954
1585
  await this.pushReviewCard(conv, this.reviewCardText("start", round, this.roundBudget(conv.goal), ""), {
1955
1586
  phase: "start",
1956
1587
  round,
1957
1588
  });
1958
- // #490/案2:pushReviewCard 的 await 窗口里 setGoal/clearGoal 可能已清掉
1959
- // awaitingVerdict(此刻 verdictWaiters 尚未登记,stopDelegated 的 settle 落空)
1960
- // ——不复检就会继续登记 waiter 并把老目标的审查指令投进主对话:主对话白烧
1961
- // 一轮审查、老循环干等 20 分钟超时,新目标的 pending 循环全程无法启动。
1962
1589
  if (!conv.awaitingVerdict || conv.awaitingVerdict.round !== round) {
1963
1590
  return "gone";
1964
1591
  }
@@ -1988,18 +1615,15 @@ export class GoalService {
1988
1615
  });
1989
1616
  if (conv.awaitingVerdict?.round === round)
1990
1617
  conv.awaitingVerdict = undefined;
1991
- // verdict 已结算(任何结局):把审查回合里排队的用户插话按序发出去。
1992
1618
  await this.flushDeferredPrompts(conv);
1993
1619
  return verdict;
1994
1620
  }
1995
- /** onAgentEnd 钩子:审查回合结束 → 取主对话最后一条 assistant 文本解析 verdict。 */
1996
1621
  deliverDelegatedVerdict(conv) {
1997
1622
  const settle = this.verdictWaiters.get(conv.id);
1998
1623
  if (!settle)
1999
1624
  return;
2000
1625
  this.verdictWaiters.delete(conv.id);
2001
1626
  conv.awaitingVerdict = undefined;
2002
- // 审查回合结束:审查者本轮用量落袋(下一轮投递前会重记基线,重试轮不丢数)。
2003
1627
  this.addGoalUsage(conv, conv.reviewUsageBefore);
2004
1628
  conv.reviewUsageBefore = undefined;
2005
1629
  let text = "";
@@ -2011,7 +1635,6 @@ export class GoalService {
2011
1635
  }
2012
1636
  settle(parseReviewerVerdict(text) ?? "invalid");
2013
1637
  }
2014
- /** 终态落历史(本对话最近 20 个;调用点在状态清空之前,保证目标文本还在)。 */
2015
1638
  recordHistory(conv, verdict, rounds, feedback) {
2016
1639
  const text = (conv.goal.goal ?? "").trim();
2017
1640
  if (!text)
@@ -2027,12 +1650,10 @@ export class GoalService {
2027
1650
  ...(conv.goalHistory ?? []),
2028
1651
  ].slice(0, 20);
2029
1652
  }
2030
- /** 收尾:pass / blocked / exhausted / 异常 → 状态、通知、角色对话清理。 */
2031
1653
  async finishDelegated(conv, goalGeneration, kind, round, feedback, goalText) {
2032
1654
  if (!this.isCurrentDelegated(conv, goalGeneration))
2033
1655
  return;
2034
1656
  const g = conv.goal;
2035
- // 先落历史(此时目标文本还在;pass 分支后面会清掉它)。
2036
1657
  this.recordHistory(conv, kind === "pass" ? "pass" : kind === "exhausted" ? "fail" : "blocked", round, feedback);
2037
1658
  if (conv.awaitingVerdict) {
2038
1659
  const settle = this.verdictWaiters.get(conv.id);
@@ -2044,12 +1665,6 @@ export class GoalService {
2044
1665
  const roundsZh = budget > 0 ? `第 ${round}/${budget} 轮` : `第 ${round} 轮(不限)`;
2045
1666
  const roundsEn = budget > 0 ? `Round ${round}/${budget}` : `Round ${round} (unlimited)`;
2046
1667
  g.reviewing = false;
2047
- // 角色对话收尾:停掉在飞的回合并一律移出左栏(转录已落盘,历史里仍可回看)。
2048
- // 受阻/未通过也不再常驻:落盘执行对话占「每项目 8 个普通对话」名额之一,
2049
- // 连续几个失败目标就会把名额吃满、新目标连执行者都拉不起来。
2050
- // (用户正看着执行对话时 dismiss 是 no-op,它会暂留,用户可自行关闭。)
2051
- // 与 stopDelegated 共用 detachRoleExec;这里 await 是为了收尾顺序确定,
2052
- // 那边 fire-and-forget 是因为调它的都是同步上下文。
2053
1668
  const execId = this.detachRoleExec(conv);
2054
1669
  if (execId) {
2055
1670
  await this.host.stopRoleAgent?.(execId).catch(() => { });
@@ -2059,7 +1674,6 @@ export class GoalService {
2059
1674
  g.verdict = "pass";
2060
1675
  g.feedback = feedback;
2061
1676
  g.phase = "idle";
2062
- // roles 已由函数顶部的 detachRoleExec 清掉。
2063
1677
  g.status = "✅ 已通过目标审查";
2064
1678
  g.statusEn = "✅ Goal review passed";
2065
1679
  g.conversationId = null;
@@ -2072,9 +1686,7 @@ export class GoalService {
2072
1686
  deliverAs: conv.session.isStreaming ? "steer" : "followUp",
2073
1687
  });
2074
1688
  }
2075
- catch {
2076
- // Best-effort.
2077
- }
1689
+ catch { }
2078
1690
  this.host.flushSnapshot();
2079
1691
  return;
2080
1692
  }
@@ -2101,16 +1713,12 @@ export class GoalService {
2101
1713
  const cappedEn = budget > 0 ? budget : "unlimited";
2102
1714
  await conv.session.sendUserMessage(pick(this.lang(), `❌ 目标未通过审查(第 ${round}/${capped} 轮)。\n\n目标:${goalText}\n\n审查意见:${feedback}`, `❌ Goal failed review (round ${round}/${cappedEn}).\n\nGoal: ${goalText}\n\nFeedback: ${feedback}`, "goal.review.fail", { round: round, capped: capped, goalText: goalText, feedback: feedback, cappedEn: cappedEn }), { deliverAs: conv.session.isStreaming ? "steer" : "followUp" });
2103
1715
  }
2104
- catch {
2105
- // Best-effort.
2106
- }
1716
+ catch { }
2107
1717
  g.reviewing = false;
2108
1718
  this.emitGoalStatus();
2109
1719
  this.host.flushSnapshot();
2110
1720
  return;
2111
1721
  }
2112
- // blocked:保留目标文本让用户看见并处置(与既有熔断口径一致)。
2113
- // 执行对话在函数顶部已统一收掉(roles 已清,不留指向死对话的「执行对话」按钮)。
2114
1722
  const reason = feedback.trim() !== ""
2115
1723
  ? feedback.trim()
2116
1724
  : (conv.sameErrorRounds ?? 0) >= 2
@@ -2130,27 +1738,20 @@ export class GoalService {
2130
1738
  try {
2131
1739
  await conv.session.sendUserMessage(pick(this.lang(), `⚠️ 目标执行受阻(${roundsZh})。\n\n目标:${goalText}\n\n原因:${reason}\n\n(委托执行已暂停,不会自己重新派活。要彻底退出目标模式:点目标条右侧的 ■ 停止目标(取消);想继续就重新设定目标。)`, `⚠️ Goal execution blocked (${roundsEn}).\n\nGoal: ${goalText}\n\nReason: ${reason}\n\n(Delegated execution is paused and will not dispatch again by itself. To leave goal mode entirely, press ■ Stop goal (cancel) in the goal bar; to resume, set the goal again.)`, "goal.role.blocked", { round, goalText, reason, rounds: roundsEn, roundsZh, roundsEn }), { deliverAs: conv.session.isStreaming ? "steer" : "followUp" });
2132
1740
  }
2133
- catch {
2134
- // Best-effort.
2135
- }
1741
+ catch { }
2136
1742
  this.emitGoalStatus();
2137
1743
  this.host.flushSnapshot();
2138
1744
  }
2139
- /** 角色对话在左栏/历史里的标题(落盘对话没有「子代理」微标,靠前缀可辨识)。 */
2140
1745
  roleConvTitle(goalText) {
2141
1746
  const brief = goalText.replace(/\s+/g, " ").trim().slice(0, 40);
2142
1747
  const withTail = goalText.trim().length > 40 ? "…" : "";
2143
1748
  return pick(this.lang(), `[目标执行] ${brief}${withTail}`, `[Goal executor] ${brief}${withTail}`, "goal.role.conv_title", { brief, withTail });
2144
1749
  }
2145
- /** 拉起执行对话失败(配额满 / runtime 创建失败):目标模式只有这一条路径,
2146
- * 没有可降级的对象 —— 当场中止循环并把原因摆到目标条上(用户可在左栏关掉几个
2147
- * 对话后重新设定目标)。 */
2148
1750
  async abortOnSpawnFailure(conv, goalGeneration, goalText, reason) {
2149
1751
  const g = conv.goal;
2150
1752
  this.recordHistory(conv, "blocked", conv.goal.round, reason);
2151
1753
  g.verdict = "blocked";
2152
1754
  g.phase = "blocked";
2153
- // 执行者都没建出来,不会有角色引用;roles 不动(setGoal 前的 stopDelegated 已清过)。
2154
1755
  g.feedback = reason;
2155
1756
  g.status = "执行对话创建失败,目标未开始";
2156
1757
  g.statusEn = "Failed to create the executor conversation; the goal did not start";
@@ -2165,18 +1766,17 @@ export class GoalService {
2165
1766
  this.host.emit({
2166
1767
  type: "notice",
2167
1768
  level: "warning",
2168
- text: "提示:执行对话会占掉本项目的一个普通对话名额(上限 8 个),可在左栏关掉几个对话后重新设定目标。",
2169
- textEn: "Tip: the executor conversation takes one of the project's regular conversation slots (max 8) — close a few chats in the left panel, then set the goal again.",
1769
+ text: "提示:执行对话会占用本项目显式配置的普通对话名额,可在左栏移出不需要的对话后重新设定目标。",
1770
+ textEn: "Tip: the executor conversation counts toward the project's configured open-conversation limit. Remove unneeded conversations in the left panel, then set the goal again.",
2170
1771
  });
2171
1772
  }
2172
1773
  this.host.flushSnapshot();
2173
1774
  }
2174
- /** 委托执行的角色轮提示词:执行者(干活)与审查者(判定)。双语走 pick。 */ executorRoundPrompt(goalText, round, budget, feedback) {
1775
+ executorRoundPrompt(goalText, round, budget, feedback) {
2175
1776
  const rounds = this.roundsLabel(budget);
2176
1777
  const prev = feedback.trim();
2177
1778
  return pick(this.lang(), `【目标 · 第 ${round}${rounds} 轮】\n\n${goalText}\n\n${prev ? `上一轮审查意见:\n${prev}\n\n` : ""}要求:\n- 直接修改工作区(不要只在回复里描述改动),做完用一段话说明「改了什么、怎么验证的」。\n- 禁止向用户提问(本对话由服务端自动驱动,弹窗会被按取消返回)。\n- 禁止派生或等待其他子代理(轮次由服务端控制,你只负责这一轮)。`, `[Goal · round ${round}${rounds}]\n\n${goalText}\n\n${prev ? `Review feedback from the previous round:\n${prev}\n\n` : ""}Requirements:\n- Change the workspace directly (don't just describe it), then summarize in one paragraph what you changed and how you verified it.\n- Do NOT ask the user anything (this conversation is server-driven; dialogs are auto-cancelled).\n- Do NOT spawn or wait for other subagents (the server owns the rounds; you own this one only).`, "goal.role.exec", { round, rounds, goalText, prev });
2178
1779
  }
2179
- /** 审查起止卡的文案(进消息流给人看的;结论 feedback 截断,details 不进大文本)。 */
2180
1780
  reviewCardText(kind, round, budget, feedback) {
2181
1781
  const rounds = this.roundsLabel(budget);
2182
1782
  const fb = feedback.trim().replace(/\s+/g, " ").slice(0, 300);
@@ -2200,8 +1800,6 @@ export class GoalService {
2200
1800
  const planBlockEn = planDesc && planDesc !== "No active plan."
2201
1801
  ? `\n\n# Task Plan Board\n${planDesc}\nWhen verifying, also check whether the above plan steps have been legitimately advanced or completed.`
2202
1802
  : "";
2203
- // #543 §1:执行者的工具/命令证据(服务端自动采集)。只保留输出尾部、可能被截断 ——
2204
- // 契约里写明这一点,免得审查者把「没看到」读成「没发生」。
2205
1803
  const ev = evidence.trim();
2206
1804
  const evidenceBlockZh = ev
2207
1805
  ? `\n\n【执行者最近的工具与命令证据(服务端自动采集,只保留输出尾部,可能被截断)】\n${ev}`
@@ -2223,7 +1821,6 @@ export class GoalService {
2223
1821
  verdictRetryPrompt() {
2224
1822
  return pick(this.lang(), `你上一条回复没有给出约定的 JSON。现在只回一个 JSON 对象,不要有任何其他文本或代码围栏:\n{"verdict":"pass|fail","feedback":"…"}\n[goal-review]`, `Your last reply did not contain the required JSON. Reply with ONLY one JSON object now — no other text, no code fences:\n{"verdict":"pass|fail","feedback":"..."}\n[goal-review]`, "goal.role.review.retry");
2225
1823
  }
2226
- /** 委托执行受阻时的原因文案(双语走 pick,key 全局唯一)。 */
2227
1824
  roleFailureText(kind, detail = "") {
2228
1825
  const detailZh = detail ? `(${detail.slice(0, 160)})` : "";
2229
1826
  const detailEn = detail ? ` (${detail.slice(0, 160)})` : "";