pi-web-ui 0.104.2 → 0.104.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -12,6 +12,45 @@
12
12
 
13
13
  暂无未发布内容。
14
14
 
15
+ ## [0.104.4] — 2026-10-12
16
+
17
+ ### Fixed
18
+
19
+ - **流式输出跟手滚动与物理向上手势即时打断**:
20
+ - 重构 `MessageList` 滚动捕获与吸底总闸门:捕获用户滚轮向上、触控向上滑动、按住滚动条滑块拖动及 PageUp 物理手势时当场立即切断自动吸底并作废保护窗,绝不等异步 `onScroll` 事件,彻底避免浏览器平滑滚动第一帧被流式 MutationObserver 强行拉回底部;
21
+ - 流式渲染平滑收尾(`StreamMarkdown` draining):流式结束到转为静态 Markdown 之间引入缓冲排水状态,避免 DOM 瞬间跳变导致高度突变或文字闪烁;加固思考折叠块(`ThinkingBlock`)与工具卡片(`ToolCallBlock`)展开收起时的视口锚定与高度补偿。
22
+ - **内部基础设施扩展隔离与启停白名单保护** —— 将 codemode、tool-search、persona 等宿主注入的内部基础设施扩展标为 `hidden: true`,明确排除在扩展设置列表之外,避免污染设置项与幽灵扩展检测;在子代理白名单(`isExtensionEnabled`)及全局扩展禁用(`isExtensionDisabled`)判定中始终放行内部扩展,防止被意外拦截或被子代理模板白名单误剔除。
23
+
24
+ ## [0.104.3] — 2026-10-12
25
+
26
+ ### Added
27
+
28
+ - **面包屑与帮助提示统一使用 SVG 图标并支持无延迟 TipButton** —— 全站统一采用基于 SVG 的提示图标与面包屑组件,新增支持零等待延迟的 `TipButton`,提升界面的视觉一致性与响应交互体验。
29
+
30
+ ### Fixed
31
+
32
+ - **沙盒硬围栏强化与启发式命令拦截** —— 完善 bash 沙盒围栏规则,深度拦截越界 `cd`、重定向、系统特权命令以及越界写删行为;补齐 `[path#TAG]` / `[path]` hashline 段头解析,避免 patch 围栏空转;`sandbox` 工具的 `action=destroy` 接入强制审批保护,销毁后安全回退当前目录;完善沙盒重置容错与写回删除同步机制。
33
+ - **IM 通道插件群聊触发收敛与稳定性修复**:
34
+ - **Telegram / Slack**:收敛群聊触发面,Telegram 仅响应针对机器人自身的精确 @mention 实体,Slack 频道内仅响应包含 `<@botId>` 的明确提及,彻底避免被动误触发与刷屏。
35
+ - **企业微信 (WeCom)**:AI 回复切块逻辑严格按 UTF-8 字节数(4096 字节限制)处理,消除纯中文超限被拒;回复链路补齐 `errcode` 校验,防止消息静默丢失。
36
+ - **飞书 (Feishu)**:移除空轮询假降级,WS 断开时如实报错并反馈真实原因,杜绝面板虚假“已连接”。
37
+ - **QQ 开放平台**:同一消息的多段分块回复补齐 `msg_seq` 自增序号,修复长回答分块被平台丢弃;新增 Access Token 惰性提前刷新机制,解决 Token 过期后 401 永久重试问题。
38
+ - **Matrix**:持久化 sync 游标到 `host.storage`,重启或热重载后不再重放历史消息;主动过滤 `m.notice` 类型机器人消息,避免死循环互聊。
39
+ - **iMessage**:非 macOS 环境不再返回假成功,如实反馈 unsupported 状态。
40
+ - **MCP 服务重名保护与热重载口径对齐** —— `install` 操作对同名已有服务默认拒绝,提供显式 `spec.overwrite` 选项;放宽热重载 legacy 回退逻辑,确保与服务端启动阶段加载行为完全一致。
41
+ - **项目列表多端派生视图缓存隔离** —— 静态 `projectsCache` 仅用于派生视图广播,不再跨客户端写回静态内存,杜绝客户端工作区视图相互污染;引入 TTL 后台续期机制,兼顾磁盘发现能力与切换性能。
42
+ - **目标审查写闸门补拦 CodeMode** —— 目标审查回路严格禁止写操作,写工具拦截名单补齐 `codemode`,防止通过内嵌 QuickJS 沙箱绕过只读限制;附件存储遇到 EPERM 锁定故障时安全回退 Data URL,防止写入失效的死链记录。
43
+ - **插件宿主控制面兼容 API 补齐** —— 扩展并兼容插件宿主常用控制面调用接口,提升外部插件运行与交互兼容性。
44
+
45
+ <!-- auto-i18n:start -->
46
+
47
+ ### i18n
48
+
49
+ - 前端中文变更(1):`sandboxDiffDeletedNote`
50
+ - 前端英文变更(1):`sandboxDiffDeletedNote`
51
+
52
+ <!-- auto-i18n:end -->
53
+
15
54
  ## [0.104.2] — 2026-10-11
16
55
 
17
56
  ### Added
@@ -1709,6 +1748,8 @@ when?, children?}`,也收 `topbar` / `settings` 这类简写别名);宿主
1709
1748
  [0.64.4]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.64.4
1710
1749
  [0.64.3]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.64.3
1711
1750
  [0.64.2]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.64.2
1751
+ [0.104.4]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.104.4
1752
+ [0.104.3]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.104.3
1712
1753
  [0.104.2]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.104.2
1713
1754
  [0.64.1]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.64.1
1714
1755
  [0.64.0]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.64.0
@@ -47,7 +47,7 @@ import { SlashCommandsService, parseSlash } from "./slash-commands.js";
47
47
  import { ModelAdminService } from "./model-admin.js";
48
48
  import { FilesService, MACHINE_ROOT, desktopDirWire, workspacePath } from "./files-service.js";
49
49
  import { buildRemoteWorkspacePersona, createRemoteSdkOperations, formatCwdForPrompt, getGlobalRemoteSshService, isRemoteWorkspaceUri, RemoteSshService, resolveWorkspaceSessionDir, restoreWorkspaceUriFromSessionDir, setGlobalRemoteSshService, } from "./remote-ssh-service.js";
50
- import { DEFAULT_TOOL_WATCHDOG_TIMEOUT_MS, effectiveToolWatchdogMs, isExtensionDisabled, isExtensionEnabled, normalizeDisabledPluginTools, normalizePathKey, normalizeRetryMaxAttempts, normalizeSkillList, ClientStateStore, } from "./client-state.js";
50
+ import { DEFAULT_TOOL_WATCHDOG_TIMEOUT_MS, effectiveToolWatchdogMs, isExtensionDisabled, isExtensionEnabled, isInternalExtension, normalizeDisabledPluginTools, normalizePathKey, normalizeRetryMaxAttempts, normalizeSkillList, ClientStateStore, } from "./client-state.js";
51
51
  import { pick, resolveServerLang } from "./i18n.js";
52
52
  import { SubagentTemplatesStore, pickTemplatePrompt } from "./subagent-templates.js";
53
53
  import { ApprovalRulesStore, extractTargetPath } from "./approval-rules.js";
@@ -195,7 +195,7 @@ export class QuiesceRejectedError extends Error {
195
195
  // /api/file HTTP endpoint instead of the WebSocket, so they are classified
196
196
  // here but never read into the snapshot path.
197
197
  // ---------------------------------------------------------------------------
198
- import { INLINE_PERSONA_EXT, splitAgentStartPrompt, PI_DOC_PATHS, WINDOWS_PERSONA } from "./persona-chain.js";
198
+ import { splitAgentStartPrompt, PI_DOC_PATHS, WINDOWS_PERSONA } from "./persona-chain.js";
199
199
  export { splitAgentStartPrompt };
200
200
  import { makeKillableBashTool, makeAdaptiveBashTool } from "./bash-tool.js";
201
201
  export { makeKillableBashTool, makeAdaptiveBashTool };
@@ -2066,8 +2066,8 @@ export class ClientSession {
2066
2066
  // 注意 SDK 在 extensionsOverride 之后才补 sourceInfo,包扩展此处只能靠路径
2067
2067
  // 匹配 —— isExtensionDisabled / isExtensionEnabled 同时比对 npm:<pkg> 候选键。
2068
2068
  extensionsOverride: (res) => {
2069
- // 自家内联扩展(灵魂替换)是基础设施,不参与白名单/禁用过滤。
2070
- const keepOwn = (e) => !e.path.startsWith(INLINE_PERSONA_EXT);
2069
+ // 内部基础设施扩展(codemode、tool-search、persona 等)不参与白名单/禁用过滤。
2070
+ const keepOwn = (e) => isInternalExtension(e);
2071
2071
  if (apply && apply.enabledExtensions.length > 0) {
2072
2072
  const set = new Set(apply.enabledExtensions);
2073
2073
  return {
@@ -2085,8 +2085,18 @@ export class ClientSession {
2085
2085
  // 覆盖,则用 composer 把 {{token}} 展开为各来源文本(工具列表/项目上下文/技能
2086
2086
  // 等都取自本次 run 的 systemPromptOptions,永远最新)。
2087
2087
  extensionFactories: [
2088
- createCodemodeExtension(),
2089
- createToolSearchExtension(),
2088
+ {
2089
+ name: "codemode",
2090
+ hidden: true,
2091
+ replaceable: true,
2092
+ factory: createCodemodeExtension(),
2093
+ },
2094
+ {
2095
+ name: "tool-search",
2096
+ hidden: true,
2097
+ replaceable: true,
2098
+ factory: createToolSearchExtension(),
2099
+ },
2090
2100
  {
2091
2101
  name: "pi-webui-persona",
2092
2102
  hidden: true,
@@ -10839,18 +10849,30 @@ export class ClientSession {
10839
10849
  const cached = ClientSession.projectsCache;
10840
10850
  // TTL 命中(或已建立过项目缓存):直接把当前 cwd 合并重排并续期,
10841
10851
  // 避免切换工作区时因为刚好跨过 60s TTL 而触发全盘 30 个会话子目录重扫。
10852
+ // 已建立过缓存:emit 本客户端的派生视图即可,**绝不把派生结果写回静态缓存**
10853
+ // ——withCurrentCwd 注入了本客户端的 cwd/lastUsed/removedKeys 过滤与沙盒
10854
+ // 元数据,写回会把 A 客户端的视图固化给 B(静态缓存跨客户端共享);
10855
+ // 底层超过 TTL 后后台重扫一次,磁盘上新工作区不会被永久挡在列表外。
10842
10856
  if (cached) {
10843
- const updated = this.withCurrentCwd(cached.projects, now);
10844
- ClientSession.projectsCache = { at: now, projects: updated };
10845
- this.emit({ type: "projects", projects: updated });
10857
+ this.emit({ type: "projects", projects: this.withCurrentCwd(cached.projects, now) });
10858
+ if (now - cached.at >= ClientSession.PROJECTS_CACHE_TTL)
10859
+ void this.ensureProjectsCache(false);
10846
10860
  return;
10847
10861
  }
10848
- // 已有扫描在跑:搭车等它,不要并发扫两遍盘。
10862
+ await this.ensureProjectsCache(true);
10863
+ }
10864
+ /**
10865
+ * 确保静态缓存有基底(单飞:已有扫描在跑则搭车,不并发扫两遍盘)。
10866
+ * `emitResult`:首发扫描把结果 emit 给客户端;后台续期扫描只更新缓存——
10867
+ * 当前视图已由命中分支 emit 过,续期完成后客户端下次 pushProjects 自然拿到新基底。
10868
+ */
10869
+ async ensureProjectsCache(emitResult) {
10849
10870
  if (ClientSession.projectsInFlight) {
10850
10871
  try {
10851
10872
  const projects = await ClientSession.projectsInFlight;
10852
- if (projects)
10873
+ if (projects && emitResult) {
10853
10874
  this.emit({ type: "projects", projects: this.withCurrentCwd(projects, Date.now()) });
10875
+ }
10854
10876
  }
10855
10877
  catch {
10856
10878
  /* 首发扫描已自行 emit 错误结果,这里不再补 */
@@ -10868,13 +10890,16 @@ export class ClientSession {
10868
10890
  this.stateStore.mergeDiscoveredProjects(discovered);
10869
10891
  const merged = await this.stateStore.getRecentProjects(this.clientId);
10870
10892
  ClientSession.projectsCache = { at: Date.now(), projects: merged };
10871
- const result = this.withCurrentCwd(merged, Date.now());
10872
- this.emit({ type: "projects", projects: result });
10893
+ if (emitResult) {
10894
+ this.emit({ type: "projects", projects: this.withCurrentCwd(merged, Date.now()) });
10895
+ }
10873
10896
  return merged;
10874
10897
  }
10875
10898
  catch {
10876
10899
  const fallback = this.withCurrentCwd(await this.stateStore.getRecentProjects(this.clientId), Date.now());
10877
- this.emit({ type: "projects", projects: fallback });
10900
+ if (emitResult) {
10901
+ this.emit({ type: "projects", projects: fallback });
10902
+ }
10878
10903
  return fallback;
10879
10904
  }
10880
10905
  finally {
@@ -11467,16 +11492,18 @@ export class ClientSession {
11467
11492
  });
11468
11493
  }
11469
11494
  }
11470
- /** 将导入型沙盒的改动写回源项目(保留源项目 .git 与依赖缓存)。 */
11495
+ /** 将导入型沙盒的改动写回源项目(保留源项目 .git 与依赖缓存,并清理已删除文件)。 */
11471
11496
  async applySandboxToSource(path) {
11472
11497
  const target = path?.trim() || this.cwd;
11473
11498
  try {
11474
- const { sandbox, sourcePath, copiedFiles } = await this.sandboxes.applyToSource(target);
11499
+ const { sandbox, sourcePath, copiedFiles, deletedFiles } = await this.sandboxes.applyToSource(target);
11500
+ const delSuffixZh = deletedFiles ? `,清理 ${deletedFiles} 个已删除文件` : "";
11501
+ const delSuffixEn = deletedFiles ? `, pruned ${deletedFiles} deleted files` : "";
11475
11502
  this.emit({
11476
11503
  type: "notice",
11477
11504
  level: "info",
11478
- text: `✅ 已将沙盒「${sandbox.name}」中的 ${copiedFiles} 个文件同步回源项目:${sourcePath}`,
11479
- textEn: `✅ Applied ${copiedFiles} files from sandbox "${sandbox.name}" back to source project: ${sourcePath}`,
11505
+ text: `✅ 已将沙盒「${sandbox.name}」中的改动同步回源项目:${sourcePath}(同步 ${copiedFiles} 个文件${delSuffixZh})`,
11506
+ textEn: `✅ Applied changes from sandbox "${sandbox.name}" back to source project: ${sourcePath} (${copiedFiles} files synced${delSuffixEn})`,
11480
11507
  });
11481
11508
  }
11482
11509
  catch (err) {
@@ -11513,9 +11540,10 @@ export class ClientSession {
11513
11540
  }
11514
11541
  await this.setCwd(fallbackCwd);
11515
11542
  }
11516
- // 清理仍挂在该沙盒下的后台会话
11543
+ // 清理仍挂在该沙盒下的后台会话(cwd 在沙盒**子目录**的也算——
11544
+ // 精确相等比较会让 <sandbox>/src 里的子代理/后台对话销毁后悬空)
11517
11545
  for (const [cid, c] of this.convs) {
11518
- if (cid !== this.activeId && normalizePathKey(c.cwd) === normalizePathKey(sbx.path)) {
11546
+ if (cid !== this.activeId && isSameOrSubpath(c.cwd, sbx.path)) {
11519
11547
  this.removeConversation(cid);
11520
11548
  }
11521
11549
  }
@@ -103,8 +103,17 @@ export function saveAttachmentSync(buffer, mimeType = "application/octet-stream"
103
103
  }
104
104
  catch { }
105
105
  const code = err.code;
106
- if (code !== "EEXIST" && code !== "EPERM")
106
+ if (code === "EEXIST") {
107
+ // 并发写同哈希:目标已在,按「已存在」成功路径返回
108
+ }
109
+ else if (code === "EPERM" && existsSync(filePath)) {
110
+ // Windows 杀软/OneDrive 锁住的是 tmp 源而目标已由并发方写好:等同已存在
111
+ }
112
+ else {
113
+ // EPERM 且目标不存在 / 其他错误:照常抛出。吞掉会返回指向缺失文件的
114
+ // 坏记录,消息里图片 404;抛出让 serialize 回退 dataUrl(转录里 base64 仍在)
107
115
  throw err;
116
+ }
108
117
  }
109
118
  }
110
119
  return {
@@ -312,8 +312,16 @@ export function extensionKeyCandidates(e) {
312
312
  }
313
313
  return [...keys];
314
314
  }
315
- /** Whether an extension is covered by the disabled list (any identity match). */
315
+ /** 判断一个扩展是否为宿主或 SDK 内部注入的基础设施扩展(如 codemode、tool_search、persona 等),
316
+ * 这些扩展不属于用户安装的业务扩展,不应在设置面板显示,也不受用户启停配置控制。 */
317
+ export function isInternalExtension(e) {
318
+ return Boolean(e.hidden) || e.path.startsWith("<inline:") || e.path.startsWith("<builtin:");
319
+ }
320
+ /** Whether an extension is covered by the disabled list (any identity match).
321
+ * Internal / hidden infrastructure extensions are always exempt. */
316
322
  export function isExtensionDisabled(e, disabled) {
323
+ if (isInternalExtension(e))
324
+ return false;
317
325
  if (disabled.length === 0)
318
326
  return false;
319
327
  const keys = extensionKeyCandidates(e);
@@ -321,8 +329,11 @@ export function isExtensionDisabled(e, disabled) {
321
329
  }
322
330
  /** Whether an extension is covered by an ENABLED whitelist (any identity
323
331
  * match). Empty whitelist = not whitelisting = everything allowed. Used by
324
- * subagent templates(白名单语义:模板勾选 = 子代理只加载这些扩展)。 */
332
+ * subagent templates(白名单语义:模板勾选 = 子代理只加载这些扩展)。
333
+ * Internal / hidden infrastructure extensions are always kept. */
325
334
  export function isExtensionEnabled(e, enabled) {
335
+ if (isInternalExtension(e))
336
+ return true;
326
337
  if (enabled.length === 0)
327
338
  return true;
328
339
  const keys = extensionKeyCandidates(e);
@@ -2582,12 +2582,14 @@ export class DshClientSession {
2582
2582
  async applySandboxToSource(path) {
2583
2583
  const target = path?.trim() || this.cwd;
2584
2584
  try {
2585
- const { sandbox, sourcePath, copiedFiles } = await this.sandboxes.applyToSource(target);
2585
+ const { sandbox, sourcePath, copiedFiles, deletedFiles } = await this.sandboxes.applyToSource(target);
2586
+ const delSuffixZh = deletedFiles ? `,清理 ${deletedFiles} 个已删除文件` : "";
2587
+ const delSuffixEn = deletedFiles ? `, pruned ${deletedFiles} deleted files` : "";
2586
2588
  this.emit({
2587
2589
  type: "notice",
2588
2590
  level: "info",
2589
- text: `✅ 已将沙盒「${sandbox.name}」中的 ${copiedFiles} 个文件同步回源项目:${sourcePath}`,
2590
- textEn: `✅ Applied ${copiedFiles} files from sandbox "${sandbox.name}" back to source project: ${sourcePath}`,
2591
+ text: `✅ 已将沙盒「${sandbox.name}」中的改动同步回源项目:${sourcePath}(同步 ${copiedFiles} 个文件${delSuffixZh})`,
2592
+ textEn: `✅ Applied changes from sandbox "${sandbox.name}" back to source project: ${sourcePath} (${copiedFiles} files synced${delSuffixEn})`,
2591
2593
  });
2592
2594
  }
2593
2595
  catch (err) {
@@ -2621,6 +2623,13 @@ export class DshClientSession {
2621
2623
  }
2622
2624
  await this.setCwd(fallbackCwd);
2623
2625
  }
2626
+ // 清理仍挂在该沙盒下的后台会话(含子目录 cwd)——ClientSession 版有此步,
2627
+ // DSH 版此前完全没有:销毁后这些对话的 runtime/终端指向已删目录
2628
+ for (const [id, conv] of this.convs) {
2629
+ if (id !== this.activeId && isSameOrSubpath(conv.cwd, sbx.path)) {
2630
+ this.removeConversation(id);
2631
+ }
2632
+ }
2624
2633
  await this.sandboxes.destroy(sbx.id);
2625
2634
  this.stateStore.removeProject(this.clientId, sbx.path);
2626
2635
  await this.pushProjects();
@@ -53,6 +53,8 @@ const WRITE_TOOLS = new Set([
53
53
  "git",
54
54
  // 代码求值(eval 沙箱可写真实文件系统 —— 审查回合只读核实,#436)
55
55
  "eval",
56
+ // QuickJS 沙箱代码执行(可嵌套调用写工具/命令;与 plan-mode/delegate-mode 同口径)
57
+ "codemode",
56
58
  "mcp_manage",
57
59
  "sandbox",
58
60
  // 形态变换(会重写整个文件树)
@@ -31,6 +31,7 @@ export function makeMcpManageTool(host, lang) {
31
31
  promptSnippet: "check whether an MCP server is installed or install/configure one",
32
32
  promptGuidelines: [
33
33
  "Run mcp_manage with action='check' before installing an MCP server to avoid duplicate entries.",
34
+ "install refuses to overwrite an existing server with the same name unless overwrite=true (it would replace command/args/env).",
34
35
  "Prefer package shorthand (e.g. package='@modelcontextprotocol/server-filesystem') for npm-based stdio MCP servers.",
35
36
  ],
36
37
  parameters: Type.Object({
@@ -76,6 +77,9 @@ export function makeMcpManageTool(host, lang) {
76
77
  scope: Type.Optional(Type.Union([Type.Literal("project"), Type.Literal("global")], {
77
78
  description: "install/remove: config scope ('project' = .pi/mcp.json, 'global' = ~/.pi/agent/mcp.json).",
78
79
  })),
80
+ overwrite: Type.Optional(Type.Boolean({
81
+ description: "install: set true to replace an existing server with the same name (its command/args/env get overwritten).",
82
+ })),
79
83
  description: Type.Optional(Type.String({
80
84
  description: "install: human-readable server note.",
81
85
  })),
@@ -55,7 +55,12 @@ export function createMcpHotReload(deps) {
55
55
  const g = readOneFile(globalFile);
56
56
  let globalServers = g.servers;
57
57
  let gFp = g.fp;
58
- if (g.fp === "empty" && legacyFile !== globalFile) {
58
+ // 与 mcp-bridge 的启动加载同口径:全局文件**不存在或存在但 0 个服务器**都
59
+ // 回退 dataDir legacy 配置。只判「文件不存在」时,「全局空配置 + legacy 有
60
+ // 服务」的部署里启动用 legacy 起服务、热加载却跳过 legacy——改 legacy 的
61
+ // 增删在重启前永不生效。
62
+ const globalHasNoServers = g.servers !== null && Object.keys(g.servers).length === 0;
63
+ if ((g.fp === "empty" || globalHasNoServers) && legacyFile !== globalFile) {
59
64
  const leg = readOneFile(legacyFile);
60
65
  if (leg.servers) {
61
66
  globalServers = leg.servers;
@@ -343,6 +343,15 @@ export async function installMcpServer(opts) {
343
343
  };
344
344
  }
345
345
  const scope = spec.scope === "global" ? "global" : "project";
346
+ // 重名保护:install 默认拒绝覆盖——promptGuidelines 里的"先 check"只是给模型
347
+ // 的建议,不拦运行时;静默覆盖会吃掉用户手工配置的同名条目(含私有 token env)
348
+ const existing = listAllMcpServers({ agentDir: opts.agentDir, cwd: opts.cwd, dataDir: opts.dataDir }).servers.find((s) => s.name === rawName && s.scope === scope);
349
+ if (existing && spec.overwrite !== true) {
350
+ return {
351
+ ok: false,
352
+ error: `已存在同名服务器「${rawName}」(${scope})——确认要覆盖请传 overwrite=true(将替换其命令/参数/环境变量)`,
353
+ };
354
+ }
346
355
  const uiServer = {
347
356
  name: rawName,
348
357
  scope,
@@ -282,6 +282,15 @@ export class PluginSecrets {
282
282
  list() {
283
283
  return Object.keys(this.load().items);
284
284
  }
285
+ getAll() {
286
+ const out = {};
287
+ for (const name of this.list()) {
288
+ const val = this.get(name);
289
+ if (val !== undefined)
290
+ out[name] = val;
291
+ }
292
+ return out;
293
+ }
285
294
  }
286
295
  // ---------------------------------------------------------------------------
287
296
  // deps(宿主代插件自动补装运行时依赖)
@@ -2917,6 +2917,29 @@ export class PluginManager {
2917
2917
  handlers.add(h);
2918
2918
  return () => handlers.delete(h);
2919
2919
  },
2920
+ onClientMessage: (h) => {
2921
+ return host.onMessage((payload, from) => {
2922
+ const reply = (res) => {
2923
+ if (from) {
2924
+ host.sendTo(from, res);
2925
+ }
2926
+ else {
2927
+ host.broadcast(res);
2928
+ }
2929
+ };
2930
+ try {
2931
+ const ret = h(payload, reply);
2932
+ if (ret instanceof Promise) {
2933
+ ret.catch((err) => {
2934
+ console.error(`[plugin:${info.id}] onClientMessage async handler failed:`, err);
2935
+ });
2936
+ }
2937
+ }
2938
+ catch (err) {
2939
+ console.error(`[plugin:${info.id}] onClientMessage handler failed:`, err);
2940
+ }
2941
+ });
2942
+ },
2920
2943
  onToolEvent: (h) => {
2921
2944
  toolHandlers.add(h);
2922
2945
  return () => toolHandlers.delete(h);
@@ -3189,6 +3212,31 @@ export class PluginManager {
3189
3212
  const off = this.registerAgentTool(info.id, tool);
3190
3213
  return effects.add(`agentTool:${String(tool?.name ?? "?")}`, off);
3191
3214
  },
3215
+ registerTool: (tool) => {
3216
+ if (!can("tools"))
3217
+ return () => { };
3218
+ if (!tool || typeof tool !== "object")
3219
+ return () => { };
3220
+ const exec = tool.execute;
3221
+ const adaptedTool = {
3222
+ name: tool.name,
3223
+ description: tool.description,
3224
+ label: tool.label,
3225
+ promptSnippet: tool.promptSnippet,
3226
+ promptGuidelines: tool.promptGuidelines,
3227
+ parameters: tool.parameters,
3228
+ execute: async (toolCallId, params, signal, onUpdate) => {
3229
+ if (typeof exec !== "function")
3230
+ return "";
3231
+ if (exec.length <= 1) {
3232
+ return await exec(params);
3233
+ }
3234
+ const multiFn = exec;
3235
+ return await multiFn(toolCallId, params, signal, onUpdate);
3236
+ },
3237
+ };
3238
+ return host.registerAgentTool(adaptedTool);
3239
+ },
3192
3240
  dir,
3193
3241
  dataDir: this.dataDir,
3194
3242
  get cwd() {