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,49 +1,23 @@
1
- /**
2
- * driver-base.ts — 通用 Agent 适配底座基础驱动契约与能力定义。
3
- *
4
- * 任何第三方 Agent(Claude Code、Aider、Codex、ACP 等)只要实现 BaseAgentDriver,
5
- * 并向 AgentEventSink 发射标准事件,即可通过 UniversalAgentHost 自动获得:
6
- * - Web 聊天界面渲染(文本、流式 Thinking 气泡、折叠工具调用卡片、Token 统计)
7
- * - 完整工作区文件树(代码查看、高亮、文件上传、图片音视频预览)
8
- * - 底部/侧边多终端(xterm.js + node-pty)
9
- * - Git SCM(代码差异、状态、提交历史)
10
- * - 后台服务检测与一键释放
11
- * - 60ms 增量快照广播与刷新后状态恢复
12
- */
13
1
  import { DEFAULT_UNIVERSAL_CAPABILITIES } from "../engine-capabilities.js";
14
- /**
15
- * 通用 Agent 驱动抽象基类。
16
- */
17
2
  export class BaseAgentDriver {
18
3
  cwd;
19
4
  constructor(cwd) {
20
5
  this.cwd = cwd;
21
6
  }
22
- /** 更新驱动运行的工作目录 */
23
7
  setCwd(cwd) {
24
8
  this.cwd = cwd;
25
9
  }
26
- /** 原生分叉一个会话分支(返回分支会话的 sessionId) */
27
10
  async forkSession(_sessionId, _atEntryId) {
28
11
  return "";
29
12
  }
30
- /** 列出可用的模型列表(若不支持返回空数组) */
31
13
  async listModels() {
32
14
  return [];
33
15
  }
34
- /** 切换当前模型(可选) */
35
- async setModel(_modelId) {
36
- /* 可由子类覆盖 */
37
- }
38
- /** 设置运行态思考强度档位(可选) */
39
- setThinkingLevel(_level) {
40
- /* 可由子类覆盖 */
41
- }
42
- /** 获取该驱动/运行态支持的思考档位列表(默认回落为标准档位) */
16
+ async setModel(_modelId) { }
17
+ setThinkingLevel(_level) { }
43
18
  getSupportedThinkingLevels(_modelId) {
44
19
  return ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
45
20
  }
46
- /** 转换为标准底座能力声明(AgentEngineCapabilities)供前端与快照使用 */
47
21
  getEngineCapabilities() {
48
22
  return {
49
23
  ...DEFAULT_UNIVERSAL_CAPABILITIES,
@@ -53,15 +27,12 @@ export class BaseAgentDriver {
53
27
  subagents: this.capabilities.supportsSubagents ?? DEFAULT_UNIVERSAL_CAPABILITIES.subagents,
54
28
  };
55
29
  }
56
- /** 驱动支持的自定义斜杠命令列表(供输入框 / 补全展示) */
57
30
  async getSlashCommands() {
58
31
  return [];
59
32
  }
60
- /** 驱动执行自定义斜杠命令(返回 true 表示已拦截处理,无需作为普通 prompt 投递) */
61
33
  async execSlashCommand(_name, _args, _context) {
62
34
  return false;
63
35
  }
64
- /** 驱动特定的额外技能列表 */
65
36
  async getSkills() {
66
37
  return [];
67
38
  }
@@ -1,141 +1,16 @@
1
- /**
2
- * claude-code.ts — Anthropic Claude Code CLI 驱动实现。
3
- *
4
- * 通过子进程拉起官方 `claude` CLI(--output-format stream-json),
5
- * 实时将 Claude Code 输出的 NDJSON 事件流映射为 Universal 底座的 AgentEventSink 事件。
6
- *
7
- * 特性:
8
- * 1. 原生支持流式正文输出与 Thinking 思考过程;
9
- * 2. 自动捕获 Bash / View / Edit / Glob / Grep 等工具调用并折叠展示;
10
- * 3. 会话自动维护:每次对话通过 --resume <sessionId> 保持上下文连续;
11
- * 4. 支持用户中断(abort)时向进程发送中断信号;
12
- * 5. 环境容错:未安装 claude 时输出清晰友好的中英文引导提示。
13
- */
14
- import { execFile, spawn } from "node:child_process";
15
- import { existsSync, readdirSync, writeFileSync } from "node:fs";
1
+ import { spawn } from "node:child_process";
2
+ import { existsSync, writeFileSync } from "node:fs";
16
3
  import { createInterface } from "node:readline";
17
4
  import { homedir } from "node:os";
18
- import { delimiter, isAbsolute, join } from "node:path";
5
+ import { join } from "node:path";
6
+ import { probeEngineCliVersion, resolveEngineCliLaunch } from "../../engine-cli.js";
19
7
  import { BaseAgentDriver } from "../driver-base.js";
20
8
  import { resolveProviderCredential, listCustomModelsFromConfig, isModelProtocolSupportedByEngine, } from "../../model-resolver.js";
21
9
  import { discoverDiskSkills } from "../../skill-discovery.js";
22
10
  import { formatUnavailableCanvasReference } from "../universal-attachments.js";
23
- /**
24
- * 探测可执行文件路径:若传入了绝对路径或在系统 PATH 中找到则直接使用;
25
- * 若未找到(尤其在 macOS launchd/GUI 等精简 PATH 环境),则自动扫描系统及版本管理器的常见安装目录。
26
- */
27
- export function resolveClaudeExecutable(cmd = "claude") {
28
- if (isAbsolute(cmd)) {
29
- if (existsSync(cmd))
30
- return cmd;
31
- if (process.platform === "win32") {
32
- for (const ext of [".cmd", ".exe", ".bat"]) {
33
- if (existsSync(cmd + ext))
34
- return cmd + ext;
35
- }
36
- }
37
- return cmd;
38
- }
39
- const isWin = process.platform === "win32";
40
- const exts = isWin ? [".cmd", ".exe", ".bat", ""] : [""];
41
- // 1. 优先从当前 process.env.PATH 寻找
42
- const pathDirs = (process.env.PATH || "").split(delimiter).filter(Boolean);
43
- for (const dir of pathDirs) {
44
- for (const ext of exts) {
45
- const target = join(dir, cmd + ext);
46
- if (existsSync(target))
47
- return target;
48
- }
49
- }
50
- // 2. 针对 macOS/Linux,自动扫描常见全局包管理器与 Homebrew 路径
51
- if (!isWin) {
52
- const home = homedir();
53
- const candidateDirs = [
54
- // macOS Homebrew (Apple Silicon & Intel)
55
- "/opt/homebrew/bin",
56
- "/usr/local/bin",
57
- // 用户目录下的标准与包管理器 bin 路径
58
- join(home, ".local", "bin"),
59
- join(home, "bin"),
60
- join(home, ".npm-global", "bin"),
61
- join(home, ".config", "yarn", "global", "node_modules", ".bin"),
62
- join(home, ".yarn", "bin"),
63
- join(home, ".pnpm-global", "bin"),
64
- join(home, "Library", "pnpm"),
65
- join(home, ".bun", "bin"),
66
- join(home, ".local", "share", "fnm", "current", "bin"),
67
- ];
68
- // fnm 当前或各 node 版本的 bin 目录与 multishells
69
- const fnmVersionsDir = join(home, ".local", "share", "fnm", "node-versions");
70
- if (existsSync(fnmVersionsDir)) {
71
- try {
72
- const vers = readdirSync(fnmVersionsDir);
73
- for (const v of vers) {
74
- candidateDirs.push(join(fnmVersionsDir, v, "installation", "bin"));
75
- }
76
- }
77
- catch {
78
- /* ignore */
79
- }
80
- }
81
- const fnmStateDir = join(home, ".local", "state", "fnm_multishells");
82
- if (existsSync(fnmStateDir)) {
83
- try {
84
- const shells = readdirSync(fnmStateDir);
85
- for (const s of shells) {
86
- candidateDirs.push(join(fnmStateDir, s, "bin"));
87
- }
88
- }
89
- catch {
90
- /* ignore */
91
- }
92
- }
93
- // nvm 当前或各 node 版本的 bin 目录
94
- const nvmVersionsDir = join(home, ".nvm", "versions", "node");
95
- if (existsSync(nvmVersionsDir)) {
96
- try {
97
- const vers = readdirSync(nvmVersionsDir);
98
- for (const v of vers) {
99
- candidateDirs.push(join(nvmVersionsDir, v, "bin"));
100
- }
101
- }
102
- catch {
103
- /* ignore */
104
- }
105
- }
106
- for (const dir of candidateDirs) {
107
- const target = join(dir, cmd);
108
- if (existsSync(target))
109
- return target;
110
- }
111
- }
112
- return cmd;
113
- }
114
- /**
115
- * 快速异步探测系统中是否安装了可用的 Claude Code CLI。
116
- */
117
- export async function probeClaudeCode(executablePath = "claude") {
118
- const resolvedPath = resolveClaudeExecutable(executablePath);
119
- return new Promise((resolve) => {
120
- try {
121
- execFile(resolvedPath, ["--version"], {
122
- timeout: 4000,
123
- shell: process.platform === "win32",
124
- }, (err, stdout) => {
125
- if (err) {
126
- resolve({ installed: false, error: err.message });
127
- }
128
- else {
129
- const v = stdout.trim();
130
- resolve({ installed: true, version: v || undefined });
131
- }
132
- });
133
- }
134
- catch (err) {
135
- const msg = err instanceof Error ? err.message : String(err);
136
- resolve({ installed: false, error: msg });
137
- }
138
- });
11
+ export async function probeClaudeCode(executablePath) {
12
+ const { available, ...result } = await probeEngineCliVersion("claude", executablePath);
13
+ return { installed: available, ...result };
139
14
  }
140
15
  export class ClaudeCodeDriver extends BaseAgentDriver {
141
16
  id = "claude-code";
@@ -155,8 +30,6 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
155
30
  activeSessionId = null;
156
31
  activeProcess = null;
157
32
  aborted = false;
158
- /** 单槽回合代际(#702):abort/新回合 +1;在途旧进程的迟到事件(close/stdout)一律按过期丢弃,
159
- * 不再清空新回合的 activeProcess、不再向旧 sink 误发输出。 */
160
33
  turnSeq = 0;
161
34
  lastErrorHint = "";
162
35
  turnHadText = false;
@@ -167,8 +40,7 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
167
40
  seenToolEnds = new Set();
168
41
  constructor(cwd, opts) {
169
42
  super(cwd);
170
- this.executablePath = resolveClaudeExecutable(opts?.executablePath ?? "claude");
171
- // 默认添加 --dangerously-skip-permissions,防止无头模式下因等待交互式 y/n 确认导致整个生成假死
43
+ this.executablePath = opts?.executablePath;
172
44
  this.extraArgs = opts?.extraArgs ?? ["--dangerously-skip-permissions"];
173
45
  this.currentModel = opts?.defaultModel ?? "claude-3-7-sonnet-20250219";
174
46
  this.agentDir = opts?.agentDir || process.env.PI_CODING_AGENT_DIR || join(homedir(), ".pi", "agent");
@@ -197,7 +69,6 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
197
69
  this.turnCompleteEmitted = false;
198
70
  this.seenToolStarts.clear();
199
71
  this.seenToolEnds.clear();
200
- // 格式化用户附件上下文
201
72
  let finalPrompt = prompt;
202
73
  if (attachments && attachments.length > 0) {
203
74
  const notes = [];
@@ -224,12 +95,7 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
224
95
  finalPrompt = `${notes.join("\n")}\n\n${prompt}`;
225
96
  }
226
97
  }
227
- // 提示词通过 stdin 管道写入,argv 仅保留参数选项:
228
- // 1. 规避 Windows 下 shell: true 拼接命令行导致的注入与 DEP0190 警告;
229
- // 2. 杜绝 Windows cmd.exe 遇换行 (\n) 截断丢弃后续多行 prompt 的严重缺陷;
230
- // 3. 避免单次 prompt 超出 Windows 命令行 8191 字符上限。
231
98
  const args = ["-p", "--output-format", "stream-json", "--verbose", ...this.extraArgs];
232
- // 解析目标模型与对应服务商凭据
233
99
  let targetModel = this.currentModel;
234
100
  let targetProvider = null;
235
101
  let isOfficial = false;
@@ -259,14 +125,12 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
259
125
  const spawnEnv = this.buildSpawnEnv(isOfficial, targetProvider);
260
126
  let proc;
261
127
  try {
262
- proc = spawn(this.executablePath, args, {
128
+ const launch = resolveEngineCliLaunch("claude", { executablePath: this.executablePath, cwd: this.cwd });
129
+ proc = spawn(launch.file, [...launch.args, ...args], {
263
130
  cwd: this.cwd,
264
131
  env: spawnEnv,
265
- // Windows 下处理 .cmd 包装脚本;Unix 下 detached 方便向进程组发送 SIGINT
266
- shell: process.platform === "win32",
267
132
  detached: process.platform !== "win32",
268
133
  });
269
- // 经 stdin 写入 prompt 并关闭管道,CLI 读完后流式处理
270
134
  if (proc.stdin) {
271
135
  proc.stdin.write(finalPrompt);
272
136
  proc.stdin.end();
@@ -291,9 +155,7 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
291
155
  const event = JSON.parse(trimmed);
292
156
  this.handleClaudeEvent(event, sink, activeToolJson);
293
157
  }
294
- catch {
295
- // 忽略非 JSON 行日志
296
- }
158
+ catch { }
297
159
  });
298
160
  }
299
161
  let stderrOutput = "";
@@ -340,17 +202,14 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
340
202
  });
341
203
  }
342
204
  handleClaudeEvent(event, sink, activeToolJson) {
343
- // 0. 支持解包 stream_event 包裹层(Claude Code 启用流式事件或内部代理时的标准结构)
344
205
  if (event.type === "stream_event" && event.event && typeof event.event === "object") {
345
206
  this.handleClaudeEvent(event.event, sink, activeToolJson);
346
207
  return;
347
208
  }
348
209
  const type = String(event.type ?? "");
349
- // 1. 会话建立或恢复事件
350
210
  if (type === "system" && typeof event.session_id === "string") {
351
211
  this.activeSessionId = event.session_id;
352
212
  }
353
- // 1.1 assistant 完整消息(含思考、正文、工具调用、错误或合成响应)
354
213
  if (type === "assistant") {
355
214
  const msg = event.message;
356
215
  if (msg && Array.isArray(msg.content)) {
@@ -381,7 +240,6 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
381
240
  this.lastErrorHint = errMsg;
382
241
  }
383
242
  }
384
- // 1.2 user 完整消息(Claude Code 执行工具后将 tool_result 以 user role 反馈)
385
243
  if (type === "user") {
386
244
  const msg = event.message;
387
245
  if (msg && Array.isArray(msg.content)) {
@@ -401,7 +259,6 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
401
259
  }
402
260
  }
403
261
  }
404
- // 2. 流式 Content Block 增量
405
262
  if (type === "content_block_delta") {
406
263
  const delta = event.delta;
407
264
  if (!delta)
@@ -418,7 +275,6 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
418
275
  activeToolJson.set(index, (activeToolJson.get(index) ?? "") + delta.partial_json);
419
276
  }
420
277
  }
421
- // 3. 工具调用开始 (content_block_start)
422
278
  if (type === "content_block_start") {
423
279
  const block = event.content_block;
424
280
  if (block && block.type === "tool_use") {
@@ -431,7 +287,6 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
431
287
  }
432
288
  }
433
289
  }
434
- // 4. 工具调用直接触发 (完整块)
435
290
  if (type === "tool_use") {
436
291
  const callId = String(event.id ?? `tool_${Date.now()}`);
437
292
  if (!this.seenToolStarts.has(callId)) {
@@ -441,7 +296,6 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
441
296
  sink.onToolStart(callId, toolName, input);
442
297
  }
443
298
  }
444
- // 5. 工具执行结果
445
299
  if (type === "tool_result") {
446
300
  const toolId = String(event.tool_use_id ?? event.id ?? "");
447
301
  if (toolId && !this.seenToolEnds.has(toolId)) {
@@ -451,7 +305,6 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
451
305
  sink.onToolEnd(toolId, isError ? { error: content } : { output: content });
452
306
  }
453
307
  }
454
- // 6. 最终完成统计
455
308
  if (type === "result") {
456
309
  if (event.is_error && event.result) {
457
310
  const resStr = typeof event.result === "string" ? event.result : JSON.stringify(event.result);
@@ -486,15 +339,6 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
486
339
  sink.onTurnComplete(turnMeta);
487
340
  }
488
341
  }
489
- /**
490
- * 构建子进程环境变量。
491
- * 关键安全防线:原生环境隔离与防封号保障:
492
- * 1. 若为官方内置 Claude 模型(isOfficial):严禁注入 models.json / auth.json / provider-keys.json
493
- * 中的任何 BaseURL、API Key 或 Auth Token,保证 100% 保持官方原生环境,完全交由 Claude Code
494
- * 自身的官方登录态(claude login OAuth 凭据,~/.claude.json)直接与 api.anthropic.com 通信;
495
- * 2. 仅当用户显式选择第三方自定义 Provider(!isOfficial 且 targetProvider 存在)时,
496
- * 才动态从配置解析中转 BaseURL 与 Key 注入环境变量。
497
- */
498
342
  buildSpawnEnv(isOfficial, targetProvider) {
499
343
  const spawnEnv = {
500
344
  ...process.env,
@@ -526,7 +370,6 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
526
370
  if (this.activeProcess) {
527
371
  try {
528
372
  if (process.platform === "win32") {
529
- // Windows 上 spawn 带有 shell 时通过 taskkill /t /f 终止整棵进程树
530
373
  spawn("taskkill", ["/pid", String(this.activeProcess.pid), "/t", "/f"]);
531
374
  }
532
375
  else {
@@ -538,9 +381,7 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
538
381
  }
539
382
  }
540
383
  }
541
- catch {
542
- /* best effort */
543
- }
384
+ catch { }
544
385
  this.activeProcess = null;
545
386
  }
546
387
  }
@@ -553,7 +394,6 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
553
394
  ];
554
395
  if (!this.agentDir)
555
396
  return official;
556
- // 仅继承 Claude / Anthropic 兼容协议的模型,过滤纯 OpenAI / Google 协议
557
397
  const custom = listCustomModelsFromConfig(this.agentDir, (entry) => isModelProtocolSupportedByEngine("claude", entry));
558
398
  const customRows = custom.map((c) => ({
559
399
  id: `${c.providerId}/${c.modelId}`,
@@ -1,38 +1,17 @@
1
- import { execFile, spawn } from "node:child_process";
2
- import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
1
+ import { spawn } from "node:child_process";
2
+ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { homedir, tmpdir } from "node:os";
4
- import { delimiter, join } from "node:path";
4
+ import { join } from "node:path";
5
5
  import { StringDecoder } from "node:string_decoder";
6
6
  import { BaseAgentDriver } from "../driver-base.js";
7
- import { probeGlobalPackage } from "../../global-loader.js";
7
+ import { probeEngineCliVersion, resolveEngineCliLaunch } from "../../engine-cli.js";
8
8
  import { killPidTree } from "../../process-utils.js";
9
9
  import { formatUnavailableCanvasReference } from "../universal-attachments.js";
10
- /** Resolve the npm launcher before PATH so Windows does not require a command shell. */
11
- function codexCommand(executablePath) {
12
- if (executablePath)
13
- return { command: executablePath, args: [] };
14
- const pkg = probeGlobalPackage("@openai/codex");
15
- if (pkg.packagePath) {
16
- const launcher = join(pkg.packagePath, "bin", "codex.js");
17
- if (existsSync(launcher))
18
- return { command: process.execPath, args: [launcher] };
19
- }
20
- for (const dir of (process.env.PATH ?? "").split(delimiter)) {
21
- const exe = join(dir, process.platform === "win32" ? "codex.exe" : "codex");
22
- if (existsSync(exe))
23
- return { command: exe, args: [] };
24
- }
25
- return { command: "codex", args: [] };
26
- }
27
10
  export async function probeCodex(executablePath) {
28
- const cmd = codexCommand(executablePath);
29
- return new Promise((resolve) => {
30
- execFile(cmd.command, [...cmd.args, "--version"], { timeout: 4000, windowsHide: true, maxBuffer: 8192 }, (err, stdout) => {
31
- resolve(err
32
- ? { available: false, error: err.message }
33
- : { available: true, version: stdout.trim().replace(/^codex(?:-cli)?\s+/i, "") });
34
- });
35
- });
11
+ const result = await probeEngineCliVersion("codex", executablePath);
12
+ return result.available && result.version
13
+ ? { ...result, version: result.version.replace(/^codex(?:-cli)?\s+/i, "") }
14
+ : result;
36
15
  }
37
16
  export class CodexDriver extends BaseAgentDriver {
38
17
  options;
@@ -84,9 +63,7 @@ export class CodexDriver extends BaseAgentDriver {
84
63
  rows.push({ id: model.slug, name: model.display_name || model.slug });
85
64
  }
86
65
  }
87
- catch {
88
- /* CLI populates the catalog after login. */
89
- }
66
+ catch { }
90
67
  return rows;
91
68
  }
92
69
  async sendPrompt(prompt, attachments, sink) {
@@ -126,9 +103,9 @@ export class CodexDriver extends BaseAgentDriver {
126
103
  else
127
104
  input += `\nFile reference: ${JSON.stringify(att.path)}${att.mode === "lines" ? ` (lines ${att.lines?.start ?? ""}-${att.lines?.end ?? ""})` : ""}`;
128
105
  }
129
- const cmd = codexCommand(this.options.executablePath);
106
+ const launch = resolveEngineCliLaunch("codex", { executablePath: this.options.executablePath, cwd });
130
107
  const args = [
131
- ...cmd.args,
108
+ ...launch.args,
132
109
  "--ask-for-approval",
133
110
  "never",
134
111
  "exec",
@@ -146,7 +123,7 @@ export class CodexDriver extends BaseAgentDriver {
146
123
  if (this.sessionId)
147
124
  args.push("resume", this.sessionId);
148
125
  args.push(...imageArgs, "-");
149
- const child = spawn(cmd.command, args, {
126
+ const child = spawn(launch.file, args, {
150
127
  cwd,
151
128
  windowsHide: true,
152
129
  detached: process.platform !== "win32",
@@ -1,7 +1,3 @@
1
- /**
2
- * mock-driver.ts — 用于单元测试与驱动开发的 Mock 驱动。
3
- * 演示了如何以极简代码向 AgentEventSink 发射思考流、正文流和工具调用。
4
- */
5
1
  import { BaseAgentDriver } from "../driver-base.js";
6
2
  export class MockAgentDriver extends BaseAgentDriver {
7
3
  id = "mock";
@@ -18,19 +14,15 @@ export class MockAgentDriver extends BaseAgentDriver {
18
14
  async createSession() {
19
15
  return `mock-session-${++this.sessionCounter}`;
20
16
  }
21
- async resumeSession(_sessionId) {
22
- /* no-op in mock */
23
- }
17
+ async resumeSession(_sessionId) { }
24
18
  async sendPrompt(prompt, _attachments, sink) {
25
19
  this.aborted = false;
26
- // 1. 发射思考过程
27
20
  sink.onThinkingDelta("Thinking about how to handle: ");
28
21
  if (this.aborted)
29
22
  return;
30
23
  sink.onThinkingDelta(prompt);
31
24
  if (this.aborted)
32
25
  return;
33
- // 2. 发射工具调用(如果 prompt 包含 "tool" 关键字)
34
26
  if (prompt.includes("tool")) {
35
27
  const callId = `call_${Date.now()}`;
36
28
  sink.onToolStart(callId, "bash", { command: "echo hello world" });
@@ -40,14 +32,12 @@ export class MockAgentDriver extends BaseAgentDriver {
40
32
  if (this.aborted)
41
33
  return;
42
34
  }
43
- // 3. 发射正文
44
35
  sink.onTextDelta("Response: ");
45
36
  if (this.aborted)
46
37
  return;
47
38
  sink.onTextDelta(`I have processed your request: "${prompt}".`);
48
39
  if (this.aborted)
49
40
  return;
50
- // 4. 发射完成事件
51
41
  sink.onTurnComplete({
52
42
  usage: {
53
43
  inputTokens: 100,
@@ -1,6 +1,3 @@
1
- /**
2
- * server/universal/index.ts — 通用 Agent 底座统一导出。
3
- */
4
1
  export { BaseAgentDriver } from "./driver-base.js";
5
2
  export { UniversalSessionStore } from "./session-store.js";
6
3
  export { UniversalSession } from "./universal-session.js";
@@ -1,9 +1,3 @@
1
- /**
2
- * session-store.ts — 通用 Agent 会话的轻量级磁盘持久化。
3
- *
4
- * 会话存储在 <dataDir>/universal-sessions/<engine>/<cwdHash>/<convId>.json 下。
5
- * 格式为纯 JSON,严格线性结构,便于直读、回放与恢复。
6
- */
7
1
  import { existsSync, mkdirSync, readFileSync, readdirSync, unlinkSync } from "node:fs";
8
2
  import { join } from "node:path";
9
3
  import { createHash } from "node:crypto";
@@ -20,9 +14,7 @@ export class UniversalSessionStore {
20
14
  try {
21
15
  mkdirSync(this.baseDir, { recursive: true });
22
16
  }
23
- catch {
24
- /* best effort */
25
- }
17
+ catch { }
26
18
  }
27
19
  cwdDir(cwd) {
28
20
  const normKey = normalizePathKey(cwd);
@@ -53,11 +45,8 @@ export class UniversalSessionStore {
53
45
  list.push(data);
54
46
  }
55
47
  }
56
- catch {
57
- /* skip corrupted files */
58
- }
48
+ catch { }
59
49
  }
60
- // 按更新时间降序排列
61
50
  return list.sort((a, b) => b.updatedAt - a.updatedAt);
62
51
  }
63
52
  loadConversation(cwd, convId) {
@@ -77,7 +66,6 @@ export class UniversalSessionStore {
77
66
  const p = this.convPath(cwd, conv.id);
78
67
  writeJsonAtomicSync(p, { ...conv, engine: this.engine });
79
68
  }
80
- /** Import legacy messages; ambiguous driver identities never cross engine boundaries. */
81
69
  importLegacy(cwd) {
82
70
  const hash = createHash("sha256").update(normalizePathKey(cwd)).digest("hex").slice(0, 16);
83
71
  const legacyDir = join(this.baseDir, "..", hash);
@@ -92,7 +80,6 @@ export class UniversalSessionStore {
92
80
  if ((conv.engine && conv.engine !== this.engine) || !conv.id || !Array.isArray(conv.messages))
93
81
  continue;
94
82
  if (!conv.engine) {
95
- // Ambiguous legacy transcripts are message-only imports. Never resume a foreign driver.
96
83
  const marker = `${this.convPath(cwd, conv.id)}.legacy-imported`;
97
84
  if (existsSync(marker))
98
85
  continue;
@@ -106,9 +93,7 @@ export class UniversalSessionStore {
106
93
  this.saveConversation(cwd, conv);
107
94
  unlinkSync(path);
108
95
  }
109
- catch {
110
- /* Leave unreadable or failed imports untouched. */
111
- }
96
+ catch { }
112
97
  }
113
98
  }
114
99
  deleteConversation(cwd, convId) {
@@ -118,9 +103,7 @@ export class UniversalSessionStore {
118
103
  try {
119
104
  unlinkSync(p);
120
105
  }
121
- catch {
122
- /* best effort */
123
- }
106
+ catch { }
124
107
  }
125
108
  }
126
109
  renameConversation(cwd, convId, title) {