pi-web-ui 0.113.1 → 0.114.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 (222) hide show
  1. package/CHANGELOG.md +43 -1
  2. package/README.md +117 -246
  3. package/README.zh-CN.md +145 -217
  4. package/README.zh-TW.md +145 -217
  5. package/bin/device-hub-cli.mjs +577 -0
  6. package/bin/pi-device-hub.mjs +9 -0
  7. package/bin/pi-web-ui.mjs +47 -15
  8. package/dist/server/agent-service-daemon.js +102 -24
  9. package/dist/server/agent-service.js +2289 -1120
  10. package/dist/server/approval-rules.js +29 -3
  11. package/dist/server/ask-user-question-tool.js +8 -8
  12. package/dist/server/atomic-file.js +35 -14
  13. package/dist/server/attachment-store.js +71 -35
  14. package/dist/server/attachments.js +18 -8
  15. package/dist/server/canvas/canvas-agent-tool.js +65 -15
  16. package/dist/server/canvas/canvas-dispatch.js +61 -20
  17. package/dist/server/canvas/canvas-orchestrator.js +516 -199
  18. package/dist/server/canvas/canvas-scheduler.js +99 -0
  19. package/dist/server/canvas/canvas-store.js +107 -54
  20. package/dist/server/canvas/canvas-validation.js +131 -0
  21. package/dist/server/canvas/canvas-workspace.js +284 -0
  22. package/dist/server/client-id-utils.js +8 -0
  23. package/dist/server/client-state.js +104 -22
  24. package/dist/server/communicate-tool.js +76 -0
  25. package/dist/server/compact-context-tool.js +2 -3
  26. package/dist/server/compaction-instructions.js +75 -0
  27. package/dist/server/compaction-markers.js +7 -2
  28. package/dist/server/compaction-state.js +84 -0
  29. package/dist/server/composer-drafts.js +43 -40
  30. package/dist/server/context-evidence.js +346 -0
  31. package/dist/server/conversation-communication.js +368 -0
  32. package/dist/server/conversation-read-tool.js +3 -4
  33. package/dist/server/conversation-tool-names.js +14 -0
  34. package/dist/server/conversation-tool.js +57 -0
  35. package/dist/server/delegate-mode.js +17 -4
  36. package/dist/server/device-center/bot-catalog.js +88 -0
  37. package/dist/server/device-center/bot-execution.js +106 -0
  38. package/dist/server/device-center/bots.js +170 -0
  39. package/dist/server/device-center/collab-service.js +153 -0
  40. package/dist/server/device-center/collab-tool.js +184 -0
  41. package/dist/server/device-center/connector.js +332 -0
  42. package/dist/server/device-center/desktop-linux.js +372 -0
  43. package/dist/server/device-center/desktop-native.js +413 -0
  44. package/dist/server/device-center/desktop-page.js +232 -0
  45. package/dist/server/device-center/desktop-setup.js +30 -0
  46. package/dist/server/device-center/desktop.js +387 -0
  47. package/dist/server/device-center/device-portals.js +241 -0
  48. package/dist/server/device-center/execution-failure.js +70 -0
  49. package/dist/server/device-center/executor.js +371 -0
  50. package/dist/server/device-center/file-sync.js +493 -0
  51. package/dist/server/device-center/hub-auth.js +69 -0
  52. package/dist/server/device-center/hub-page.js +68 -0
  53. package/dist/server/device-center/hub-setup.js +214 -0
  54. package/dist/server/device-center/hub.js +829 -0
  55. package/dist/server/device-center/local-page.js +17 -0
  56. package/dist/server/device-center/local.js +476 -0
  57. package/dist/server/device-center/main.js +118 -0
  58. package/dist/server/device-center/native-desktop/macos.js +192 -0
  59. package/dist/server/device-center/native-desktop/windows.js +118 -0
  60. package/dist/server/device-center/path-portal.js +120 -0
  61. package/dist/server/device-center/relay.js +959 -0
  62. package/dist/server/device-center/runtime.js +253 -0
  63. package/dist/server/device-center/smoke-preview.js +3 -0
  64. package/dist/server/device-center/store.js +122 -0
  65. package/dist/server/device-center/task-error.js +14 -0
  66. package/dist/server/device-center/transfers.js +293 -0
  67. package/dist/server/device-center/workspaces.js +45 -0
  68. package/dist/server/dispatch-domain-handlers.js +83 -27
  69. package/dist/server/dsh/dsh-agent-service.js +277 -158
  70. package/dist/server/dsh/dsh-client.js +12 -2
  71. package/dist/server/durable/durable-agent-service.js +1 -1
  72. package/dist/server/evidence-tool-hooks.js +49 -0
  73. package/dist/server/file-save.js +95 -0
  74. package/dist/server/file-transfer-routes.js +97 -47
  75. package/dist/server/files-service.js +38 -26
  76. package/dist/server/goal-review-gate.js +16 -6
  77. package/dist/server/goal-service.js +54 -30
  78. package/dist/server/http-proxy.js +120 -0
  79. package/dist/server/index.js +229 -223
  80. package/dist/server/load-timing.js +31 -0
  81. package/dist/server/mcp-bridge.js +219 -94
  82. package/dist/server/mcp-hot-reload.js +31 -5
  83. package/dist/server/mcp-manager.js +192 -93
  84. package/dist/server/mcp-oauth-login.js +169 -0
  85. package/dist/server/mcp-oauth-ui.js +137 -0
  86. package/dist/server/mcp-oauth.js +395 -0
  87. package/dist/server/mcp-project-runtime.js +207 -0
  88. package/dist/server/message-window.js +74 -21
  89. package/dist/server/net-guard.js +122 -20
  90. package/dist/server/payload-limits.js +17 -0
  91. package/dist/server/pending-question.js +82 -0
  92. package/dist/server/plan-mode.js +338 -137
  93. package/dist/server/plugin-assets.js +8 -4
  94. package/dist/server/plugin-chat-attachments.js +48 -0
  95. package/dist/server/plugin-facilities.js +67 -220
  96. package/dist/server/plugin-installer.js +2 -1
  97. package/dist/server/plugin-removal.js +49 -0
  98. package/dist/server/plugin-secrets.js +179 -0
  99. package/dist/server/plugins.js +262 -92
  100. package/dist/server/preset-fields.js +49 -0
  101. package/dist/server/preset-plugin-dependencies.js +57 -0
  102. package/dist/server/preset-share.js +112 -72
  103. package/dist/server/protocol-version.js +1 -1
  104. package/dist/server/queue-modes.js +10 -0
  105. package/dist/server/remote-ssh-service.js +160 -67
  106. package/dist/server/request-context.js +164 -0
  107. package/dist/server/sandbox-data.js +655 -0
  108. package/dist/server/sandbox-engines.js +7 -0
  109. package/dist/server/sandbox-runtime-gate.js +41 -0
  110. package/dist/server/sandbox-service.js +139 -698
  111. package/dist/server/sandbox-tool.js +21 -4
  112. package/dist/server/scheduler-tasks.js +63 -48
  113. package/dist/server/serialize.js +48 -19
  114. package/dist/server/session-branch.js +25 -3
  115. package/dist/server/session-parser.js +28 -18
  116. package/dist/server/session-scan.js +130 -0
  117. package/dist/server/session-search.js +51 -37
  118. package/dist/server/settings-service.js +267 -111
  119. package/dist/server/setup-config.js +58 -0
  120. package/dist/server/skill-maintenance.js +112 -24
  121. package/dist/server/subagent-helpers.js +4 -1
  122. package/dist/server/subagent-notify.js +4 -1
  123. package/dist/server/subagent-security-gate.js +52 -11
  124. package/dist/server/subagent-task.js +27 -0
  125. package/dist/server/subagents.js +217 -46
  126. package/dist/server/tabs.js +9 -1
  127. package/dist/server/terminals.js +467 -363
  128. package/dist/server/tool-guards.js +42 -6
  129. package/dist/server/tool-manager.js +47 -20
  130. package/dist/server/tool-overrides.js +13 -11
  131. package/dist/server/tool-prompt-overrides.js +32 -2
  132. package/dist/server/tool-prompts.js +1 -1
  133. package/dist/server/turn-timing.js +11 -0
  134. package/dist/server/universal/session-store.js +48 -6
  135. package/dist/server/universal/universal-service.js +1 -1
  136. package/dist/server/universal/universal-session.js +334 -231
  137. package/dist/server/uploads.js +64 -5
  138. package/dist/server/worktree-service.js +32 -24
  139. package/dist/server/ws-pending-queue.js +73 -27
  140. package/docs/device-center.md +142 -0
  141. package/docs/device-desktop.md +48 -0
  142. package/package.json +4 -1
  143. package/plugin-sdk/index.d.ts +28 -6
  144. package/plugin-sdk/ssh-host-trust.mjs +225 -0
  145. package/plugins/catalog.json +1 -1
  146. package/themes/aetheris.css +1 -107
  147. package/themes/ayu-light.css +5 -29
  148. package/themes/bases/flow-base.css +0 -6
  149. package/themes/bases/statusbar-flat-base.css +112 -0
  150. package/themes/bases/zhujian-base.css +1 -0
  151. package/themes/bases/zhupi-base.css +1 -0
  152. package/themes/catppuccin-latte.css +4 -27
  153. package/themes/catppuccin.css +4 -35
  154. package/themes/claude-code-dark.css +1 -0
  155. package/themes/codex.css +4 -28
  156. package/themes/cyberpunk.css +3 -61
  157. package/themes/dark-teal.css +0 -1
  158. package/themes/dazzle.css +3 -73
  159. package/themes/everforest-light.css +4 -27
  160. package/themes/geist.css +4 -28
  161. package/themes/gruvbox-light.css +4 -27
  162. package/themes/kanagawa-lotus.css +4 -27
  163. package/themes/md-preview.css +3 -213
  164. package/themes/mist.css +4 -24
  165. package/themes/nord.css +4 -35
  166. package/themes/one-dark.css +4 -37
  167. package/themes/paper.css +4 -16
  168. package/themes/rose-pine-dawn.css +4 -28
  169. package/themes/sakura.css +4 -24
  170. package/themes/solarized-light.css +4 -27
  171. package/themes/tokyo-night.css +3 -34
  172. package/themes/white.css +4 -26
  173. package/themes/zhujian-dark.css +1 -0
  174. package/themes/zhupi-dark.css +1 -0
  175. package/web/dist/.build-assets.json +1 -0
  176. package/web/dist/assets/BgTasksModal-CS7UNzcw.js +1 -0
  177. package/web/dist/assets/BgTasksModal-Dk-tp78W.js +1 -0
  178. package/web/dist/assets/CanvasStudio-BEJZE5BI.js +1579 -0
  179. package/web/dist/assets/CanvasStudio-CgUNHqos.js +1579 -0
  180. package/web/dist/assets/DeviceCenter-C8_CbxQ3.js +3 -0
  181. package/web/dist/assets/DeviceCenter-CVblvhNX.js +3 -0
  182. package/web/dist/assets/Dropdown-Oug0DDte.js +1 -0
  183. package/web/dist/assets/FilePreview-CvdX6nr6.js +2 -0
  184. package/web/dist/assets/FilePreview-kCZhfBAF.js +2 -0
  185. package/web/dist/assets/GlobalSearchModal-BLH63yYP.js +1 -0
  186. package/web/dist/assets/GlobalSearchModal-DAkvlvp6.js +1 -0
  187. package/web/dist/assets/GroupConversation-Cgo4xbpa.js +1 -0
  188. package/web/dist/assets/GroupConversation-DZ71jEi8.js +1 -0
  189. package/web/dist/assets/ModelConfigModal-BpWdFdQC.js +2 -0
  190. package/web/dist/assets/PiSetupModal-mkWPSxMj.js +1 -0
  191. package/web/dist/assets/ProviderOAuthControls-VK_jqXYS.js +1 -0
  192. package/web/dist/assets/SCMPanel-BP1TUT-V.js +2 -0
  193. package/web/dist/assets/SCMPanel-BscPm9kf.js +2 -0
  194. package/web/dist/assets/SettingsModal-C8UgMjVM.js +20 -0
  195. package/web/dist/assets/SettingsModal-VynB7jNb.js +20 -0
  196. package/web/dist/assets/TerminalPanel-D6cPRFei.js +3 -0
  197. package/web/dist/assets/TerminalPanel-DL20uKgU.js +3 -0
  198. package/web/dist/assets/TuiOverlayModal-Dst3BmT8.js +1 -0
  199. package/web/dist/assets/TuiOverlayModal-NCkpNtTp.js +1 -0
  200. package/web/dist/assets/UniversalPathPicker-CfQFc_c3.js +1 -0
  201. package/web/dist/assets/UniversalPathPicker-DwxwNcFw.js +1 -0
  202. package/web/dist/assets/app-globals-CnO6KlEM.js +325 -0
  203. package/web/dist/assets/desktop-DPyTy4M3.js +1 -0
  204. package/web/dist/assets/es-DWMIuDU2.js +2 -0
  205. package/web/dist/assets/index-CPgAH5q7.js +83 -0
  206. package/web/dist/assets/index-Cje8iugL.js +83 -0
  207. package/web/dist/assets/index-DnKeiDbj.css +1 -0
  208. package/web/dist/assets/markdown-BggnuQ4H.js +40 -0
  209. package/web/dist/assets/markdown-C8LL_u4z.css +1 -0
  210. package/web/dist/assets/math-1uRJCsA9.js +257 -0
  211. package/web/dist/assets/math-BorAY7qD.css +1 -0
  212. package/web/dist/assets/plugin-host-CqA4yW6w.js +1 -0
  213. package/web/dist/assets/shortcut-stack-hhrDyRBn.js +1 -0
  214. package/web/dist/assets/theme-BqdAjEjF.js +1 -0
  215. package/web/dist/assets/uuid-BzDIGCwP.js +1 -0
  216. package/web/dist/index.html +15 -9
  217. package/web/dist/sw.js +1 -1
  218. package/web/dist/assets/TerminalPanel-Ci55JtJL.js +0 -3
  219. package/web/dist/assets/index-ByiO9f-N.js +0 -2008
  220. package/web/dist/assets/index-ycGLh4a4.css +0 -1
  221. package/web/dist/assets/markdown-BJZlfvdP.js +0 -296
  222. package/web/dist/assets/markdown-DSNUiDzp.css +0 -1
package/bin/pi-web-ui.mjs CHANGED
@@ -28,14 +28,17 @@ import { spawn, spawnSync } from "node:child_process";
28
28
  import { createConnection } from "node:net";
29
29
  import { get as httpGet } from "node:http";
30
30
  import { createInterface } from "node:readline/promises";
31
- import { frpCmd } from "./frp-manager.mjs";
32
- import {
33
- ensureBackup as ensurePluginBackup,
34
- restoreBackup as restorePluginBackup,
35
- checkPluginUpdates,
36
- resolveRemoteSha,
37
- compareVersions,
38
- } from "../dist/server/plugin-updater.js";
31
+ // Dispatch Hub before loading optional plugin/FRP dependencies or the server build.
32
+ if (process.argv[2] === "hub") {
33
+ try {
34
+ const { runHubCliEntry } = await import("./device-hub-cli.mjs");
35
+ await runHubCliEntry(process.argv.slice(3));
36
+ } catch (error) {
37
+ console.error(`[device-hub] ${error.message}`);
38
+ process.exitCode = 1;
39
+ }
40
+ }
41
+
39
42
  import {
40
43
  chmodSync,
41
44
  copyFileSync,
@@ -55,6 +58,16 @@ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
55
58
  import { pathToFileURL } from "node:url";
56
59
  import { fileURLToPath } from "node:url";
57
60
 
61
+ const isHubCommand = process.argv[2] === "hub";
62
+ const { frpCmd } = isHubCommand ? {} : await import("./frp-manager.mjs");
63
+ const {
64
+ ensureBackup: ensurePluginBackup,
65
+ restoreBackup: restorePluginBackup,
66
+ checkPluginUpdates,
67
+ resolveRemoteSha,
68
+ compareVersions,
69
+ } = isHubCommand ? {} : await import("../dist/server/plugin-updater.js");
70
+
58
71
  const BIN_DIR = dirname(fileURLToPath(import.meta.url));
59
72
  /** <pkg>/dist/server/index.js — the actual server entry. */
60
73
  const SERVER_ENTRY = join(BIN_DIR, "..", "dist", "server", "index.js");
@@ -3728,7 +3741,7 @@ async function pluginInstallCmd(argv) {
3728
3741
  }
3729
3742
  }
3730
3743
 
3731
- function pluginUninstallCmd(argv) {
3744
+ async function pluginUninstallCmd(argv) {
3732
3745
  const { opts, positionals } = parseFlags(argv);
3733
3746
  if (opts.help || positionals.length !== 1) {
3734
3747
  console.log(PLUGIN_HELP);
@@ -3744,7 +3757,20 @@ function pluginUninstallCmd(argv) {
3744
3757
  ? `未安装插件 "${id}"(pi-web-ui plugins 查看已装列表)`
3745
3758
  : `Plugin not installed: "${id}" (pi-web-ui plugins to see installed list)`,
3746
3759
  );
3747
- rmSync(target, { recursive: true, force: true });
3760
+ const { removePlugin } = await import("../dist/server/plugin-removal.js");
3761
+ let deferred;
3762
+ try {
3763
+ ({ deferred } = removePlugin(pluginDataDir(opts), id));
3764
+ } catch (err) {
3765
+ fail(`${err?.message ?? err}`);
3766
+ }
3767
+ if (deferred) {
3768
+ console.log(
3769
+ ZH
3770
+ ? "部分文件仍被进程占用,将在服务重启后清理。"
3771
+ : "Some files are still in use and will be cleaned up after the service restarts.",
3772
+ );
3773
+ }
3748
3774
  console.log(
3749
3775
  ZH
3750
3776
  ? `✔ 已卸载插件 ${id} —— 运行中的服务刷新浏览器后消失。`
@@ -3994,6 +4020,11 @@ async function main() {
3994
4020
  console.log(HELP);
3995
4021
  return;
3996
4022
  }
4023
+ if (first === "hub") {
4024
+ const { runHubCli } = await import("./device-hub-cli.mjs");
4025
+ await runHubCli(argv.slice(1));
4026
+ return;
4027
+ }
3997
4028
  if (first === "server") {
3998
4029
  await serverCmd(argv.slice(1));
3999
4030
  return;
@@ -4007,7 +4038,7 @@ async function main() {
4007
4038
  return;
4008
4039
  }
4009
4040
  if (first === "uninstall") {
4010
- pluginUninstallCmd(argv.slice(1));
4041
+ await pluginUninstallCmd(argv.slice(1));
4011
4042
  return;
4012
4043
  }
4013
4044
  if (first === "plugins" || first === "plugin") {
@@ -4035,7 +4066,8 @@ async function main() {
4035
4066
  await startForeground(opts);
4036
4067
  }
4037
4068
 
4038
- main().catch((err) => {
4039
- console.error(`✖ ${err instanceof Error ? err.message : String(err)}`);
4040
- process.exit(1);
4041
- });
4069
+ if (!isHubCommand)
4070
+ main().catch((err) => {
4071
+ console.error(`✖ ${err instanceof Error ? err.message : String(err)}`);
4072
+ process.exit(1);
4073
+ });
@@ -18,14 +18,16 @@ import { randomUUID } from "node:crypto";
18
18
  import { VERSION, getAgentDir } from "@earendil-works/pi-coding-agent";
19
19
  import { ClientStateStore } from "./client-state.js";
20
20
  import { ClaimStore } from "./claim-store.js";
21
+ import { isBotExecutionRegistered } from "./device-center/bot-execution.js";
21
22
  import { toServiceInfo, launchOrigin } from "./launch-origin.js";
22
- import { isPseudoClientId, checkPluginCwd } from "./client-id-utils.js";
23
+ import { isPseudoClientId, isOrphanAdoptionExcludedClientId, checkPluginCwd } from "./client-id-utils.js";
23
24
  import { pickAdoptableOrphan } from "./orphan-manager.js";
24
25
  import { findMostRecentSessionFileFast } from "./session-parser.js";
25
26
  import { isRemoteWorkspaceUri, resolveWorkspaceSessionDir } from "./remote-ssh-service.js";
26
27
  import { getMaxOpenConversations } from "./agent-formatters.js";
27
28
  import { collectSubagentDescendantIds } from "./subagents.js";
28
29
  import { pickLatestClientSnapshot } from "./plugin-conversation-view.js";
30
+ import { normalizePluginChatAttachments } from "./plugin-chat-attachments.js";
29
31
  import { DEFAULT_PI_CAPABILITIES } from "./engine-capabilities.js";
30
32
  import { ClientSession, QuiesceRejectedError, OFFLINE_ROW_TTL_MS, } from "./agent-service.js";
31
33
  export class AgentService {
@@ -590,6 +592,7 @@ export class AgentService {
590
592
  const acct = String(req?.accountId ?? "default").replace(/[^A-Za-z0-9_-]/g, "") || "default";
591
593
  const clientId = `plugin:${safe}:${acct}`;
592
594
  const text = String(req?.text ?? "");
595
+ const attachments = normalizePluginChatAttachments(req?.attachments);
593
596
  if (!text.trim())
594
597
  throw new Error("chatFromPlugin: text 为空");
595
598
  if (this.quiesced)
@@ -602,20 +605,41 @@ export class AgentService {
602
605
  // miss/已回收时不抛错,回落无头伪客户端(浏览器关着时微信照常可用)。
603
606
  const target = String(req?.conversationId ?? "").trim();
604
607
  if (target) {
605
- const w = await this.wakeConversation(target, text);
606
- if (w.ok) {
607
- // 投递成功:给该对话打上运行 token(过户后事件依旧带它)。
608
- const owner = w.clientId ? this.clients.get(w.clientId) : undefined;
609
- if (owner) {
610
- try {
611
- const conv = w.conversationId ? owner.getConversation(w.conversationId) : undefined;
612
- owner.markPluginRun(runId, conv);
613
- }
614
- catch {
615
- /* 打标尽力而为,不影响已投递的请求 */
616
- }
608
+ // Conversation ids are local to a client. Prefer this channel's own
609
+ // client; otherwise require an unambiguous target instead of guessing.
610
+ const own = this.clients.get(clientId);
611
+ const ownConv = own?.getConversation(target);
612
+ const hits = [];
613
+ if (own && ownConv)
614
+ hits.push({ owner: own, conv: ownConv, ownerId: clientId });
615
+ else {
616
+ for (const [ownerId, owner] of this.clients) {
617
+ const conv = owner.getConversation(target);
618
+ if (conv)
619
+ hits.push({ owner, conv, ownerId });
617
620
  }
618
- return { conversationId: w.conversationId ?? target, clientId: w.clientId ?? clientId, runId };
621
+ }
622
+ if (hits.length > 1)
623
+ throw new Error("chatFromPlugin: ambiguous conversation id; rebind the channel");
624
+ if (hits.length === 1) {
625
+ const { owner, conv, ownerId } = hits[0];
626
+ if (req.cwd && resolve(req.cwd) !== resolve(conv.cwd))
627
+ throw new Error("chatFromPlugin: bound conversation cwd differs; start a new channel conversation");
628
+ if (req.model || req.thinkingLevel) {
629
+ // Apply overrides only when the captured conversation is active;
630
+ // these APIs address the owner's active conversation.
631
+ if (owner.readConversationForPlugins()?.conversationId !== conv.id)
632
+ throw new Error("chatFromPlugin: cannot change settings of an inactive bound conversation");
633
+ if (req.model)
634
+ await owner.switchModelOrThrow(req.model);
635
+ if (req.thinkingLevel)
636
+ owner.setThinking(req.thinkingLevel);
637
+ }
638
+ owner.markPluginRun(runId, conv);
639
+ void owner
640
+ .prompt(text, attachments, false, conv)
641
+ .catch((err) => console.error("[plugin chat] prompt failed", err));
642
+ return { conversationId: conv.id, clientId: ownerId, runId };
619
643
  }
620
644
  }
621
645
  // 2. 工作空间:不传回落伪客户端当前目录;传了必须存在且非系统目录。
@@ -662,9 +686,18 @@ export class AgentService {
662
686
  /* 打标尽力而为 */
663
687
  }
664
688
  const conversationId = stampedId || (cs.readConversationForPlugins()?.conversationId ?? "");
665
- void cs.prompt(text);
689
+ const conv = cs.getConversation(conversationId);
690
+ void cs.prompt(text, attachments, false, conv).catch((err) => console.error("[plugin chat] prompt failed", err));
666
691
  return { conversationId, clientId, runId };
667
692
  }
693
+ /** Abort by the stable plugin run token, including after conversation takeover. */
694
+ async abortPluginRun(runId) {
695
+ for (const owner of this.clients.values()) {
696
+ if (owner.findPluginRun(runId))
697
+ return owner.abortPluginRun(runId);
698
+ }
699
+ return { ok: false, error: "Plugin run is no longer active" };
700
+ }
668
701
  /** 内置定时任务的无头执行(issue #184,server/scheduler-tasks.ts 的 executor)。
669
702
  * 每个任务独立伪客户端 `scheduler:<taskId>`(专属会话连续、无浏览器也能跑);
670
703
  * cwd 按任务配置 pin 住(不存在即失败,不默默跑错目录);可选模型/思考强度
@@ -807,7 +840,7 @@ export class AgentService {
807
840
  for (const [id, cs] of this.clients) {
808
841
  if (id === excludeClientId)
809
842
  continue;
810
- const pseudo = AgentService.isPseudoClientId(id);
843
+ const pseudo = isOrphanAdoptionExcludedClientId(id);
811
844
  let live = false;
812
845
  let streaming = 0;
813
846
  let adoptable = false;
@@ -1078,6 +1111,31 @@ export class AgentService {
1078
1111
  target.refreshExternalRunning();
1079
1112
  }
1080
1113
  }
1114
+ /** Locate the live request again after takeover; conversation IDs may have changed. */
1115
+ async navigateQuestion(targetId, id) {
1116
+ const target = this.clients.get(targetId);
1117
+ if (!target)
1118
+ return;
1119
+ for (const [ownerId, source] of this.clients) {
1120
+ if (AgentService.isPseudoClientId(ownerId))
1121
+ continue;
1122
+ const request = source.getQuestionNavigation(id);
1123
+ if (!request || resolve(request.cwd) !== resolve(target.cwd))
1124
+ continue;
1125
+ if (source !== target)
1126
+ await this.takeOverConversation(targetId, ownerId, request.rootConversationId);
1127
+ const moved = target.getQuestionNavigation(id);
1128
+ if (moved)
1129
+ await target.switchConversation(moved.conversationId);
1130
+ return;
1131
+ }
1132
+ target.sendNotice({
1133
+ type: "notice",
1134
+ level: "warning",
1135
+ text: "问卷已结束,无法定位来源",
1136
+ textEn: "The question has ended; its source is no longer available.",
1137
+ });
1138
+ }
1081
1139
  /** Get or create the session for a client, racing attach calls safely. */
1082
1140
  async attach(clientId, send) {
1083
1141
  let cs = this.clients.get(clientId);
@@ -1094,9 +1152,9 @@ export class AgentService {
1094
1152
  // 流式增量经尾部 attachSink 直接推给新 socket)。
1095
1153
  // 有其他在线标签时不认领(issue #10 隔离优先);quiesce 排空期也放行
1096
1154
  // (这是重连既有工作,不是新工作)。本段无 await,并发 attach 原子。
1097
- // 伪客户端(scheduler:/plugin:,定时任务/插件的无头调用)绝不认领:
1098
- // 否则无头会话会改键劫持用户关浏览器留下的残会话。
1099
- const orphan = AgentService.isPseudoClientId(clientId) ? null : this.findAdoptableOrphan(clientId);
1155
+ // 伪客户端(含 device-task- 私有 Bot capability)绝不认领;
1156
+ // 候选端同样排除伪客户端,禁止浏览器接管 Bot 或新任务复用旧 capability。
1157
+ const orphan = isOrphanAdoptionExcludedClientId(clientId) ? null : this.findAdoptableOrphan(clientId);
1100
1158
  if (orphan) {
1101
1159
  this.clients.delete(orphan.oldId);
1102
1160
  // 残骸被本页认领:它的离线行状态随 id 作废(行归到新 id 名下)。
@@ -1148,9 +1206,9 @@ export class AgentService {
1148
1206
  // 也无需事后拆 runtime)。之前只拦 running:空闲持有照样恢复出双
1149
1207
  // writer,两边轮流发送分叉历史。其他客户端不存在时不扫目录。
1150
1208
  let createOpts;
1151
- const isPseudo = AgentService.isPseudoClientId(clientId);
1152
- if (isPseudo) {
1153
- // 伪客户端(插件无头调用、定时调度任务、Canvas专用通道等):严禁自动恢复并占有工作区历史会话,强制空白
1209
+ const requiresBlankSession = isOrphanAdoptionExcludedClientId(clientId);
1210
+ if (requiresBlankSession) {
1211
+ // 伪客户端(插件、调度、Canvas、Bot):禁止自动恢复工作区历史或旧任务,强制空白
1154
1212
  createOpts = { blank: true };
1155
1213
  }
1156
1214
  else if (this.clients.size > 0) {
@@ -1198,6 +1256,11 @@ export class AgentService {
1198
1256
  detachedSinks.delete(send);
1199
1257
  if (detachedSinks.size === 0)
1200
1258
  this.pendingDetaches.delete(clientId);
1259
+ if (clientId.startsWith("device-task-") && !isBotExecutionRegistered(clientId) && cs.sinkCount() === 0) {
1260
+ this.clients.delete(clientId);
1261
+ await cs.dispose();
1262
+ return cs;
1263
+ }
1201
1264
  }
1202
1265
  else {
1203
1266
  cs.attachSink(send);
@@ -1230,6 +1293,18 @@ export class AgentService {
1230
1293
  for (const cs of this.clients.values())
1231
1294
  cs.refreshPluginTools();
1232
1295
  }
1296
+ mcpProjectCwds() {
1297
+ return [...new Set([...this.clients.values()].flatMap((cs) => cs.mcpProjectCwds()))];
1298
+ }
1299
+ /** Runtime initialization/reload also updates management UI, including clients without conversations. */
1300
+ refreshMcpProject(cwd) {
1301
+ for (const cs of this.clients.values()) {
1302
+ if (resolve(cs.cwd) !== resolve(cwd))
1303
+ continue;
1304
+ cs.broadcastMcpServers();
1305
+ cs.pushSettings();
1306
+ }
1307
+ }
1233
1308
  /** Browser UI locale report (hello.locale / set_locale): persist per client
1234
1309
  * and refresh lang-aware prompts (streaming-safe via ClientSession). */
1235
1310
  async setLocale(clientId, locale) {
@@ -1270,8 +1345,11 @@ export class AgentService {
1270
1345
  if (cs) {
1271
1346
  cs.detachSink(send);
1272
1347
  if (cs.sinkCount() === 0) {
1273
- if (clientId.startsWith("canvas:") || clientId.startsWith("canvas-")) {
1274
- // Canvas 辅助连接一旦关闭,立即从客户端池回收并释放资源,绝不残留
1348
+ if (clientId.startsWith("canvas:") ||
1349
+ clientId.startsWith("canvas-") ||
1350
+ (clientId.startsWith("device-task-") && !isBotExecutionRegistered(clientId))) {
1351
+ // Bot registration is released only after the executor confirms stop.
1352
+ // Keep uncertain/disconnected executions owned until that confirmation.
1275
1353
  this.clients.delete(clientId);
1276
1354
  void cs.dispose().catch(() => { });
1277
1355
  return;