Skip to content

fix: 让扩展/package 工具在 pi-web 新建 session 中可用(修复 #79) - #83

Merged
agegr merged 1 commit into
agegr:mainfrom
cking000bigdemon:fix/web-sessions-extension-tools
Jun 24, 2026
Merged

agegr merged 1 commit into
agegr:mainfrom
cking000bigdemon:fix/web-sessions-extension-tools

Conversation

@cking000bigdemon

Copy link
Copy Markdown
Contributor

问题

通过 pi-web 新建 / 配置带工具预设的 session 时,只有 4 个内置工具 read / bash / edit / write 可用,所有扩展 / package 提供的工具全部消失(如 pi-subagents 的 subagent、pi-web-access 的 web_search / code_search / fetch_content)。完全相同的 ~/.pi 配置在独立 pi CLI 里一切正常。对应 #79。

根因

lib/rpc-manager.ts 的 startRpcSession 在 toolNames 非空时,把写死的内置列表 allCodingToolNames(["read","bash","edit","write","grep","find","ls"])作为 tools 传给 createAgentSession。在 SDK 里 tools → allowedToolNames,而 isAllowedTool(name) 用它过滤工具注册表 —— 扩展工具不在白名单里 → 被挡在注册表外 → 既不出现也无法激活(includeAllExtensionTools 只对已通过 isAllowedTool 的工具生效)。

预设(components/ToolPanel.tsx 的 PRESET_NONE / PRESET_DEFAULT / PRESET_FULL)也只含内置工具,所以扩展工具在 Low/High 档结构上被排除。只有恢复已有会话(不传 toolNames)时 allowedToolNames === undefined,扩展工具才可用 —— 这也是「打开旧会话有工具、新建会话没工具、重启服务后又有」现象的来源。

修改(lib/rpc-manager.ts)

  • 非空预设时不再传 builtin-only 白名单(tools 留空 → allowedToolNames 为 undefined → 所有工具进注册表、扩展工具被激活);
  • 随后把激活集设为「请求的内置工具 + 所有扩展工具」,让预设继续控制内置工具档位,同时扩展工具像 CLI 一样保持可用;
  • 「Off」(空数组)与恢复会话路径行为不变。
-    toolsOption = toolNames.length === 0 ? [] : allCodingToolNames;
+    toolsOption = toolNames.length === 0 ? [] : undefined;   // 非空时不限制白名单
...
-    if (toolNames && toolNames.length > 0) {
-      inner.setActiveToolsByName(toolNames);
-    }
+    if (toolNames && toolNames.length > 0) {
+      const extensionToolNames = inner.getAllTools()
+        .map((t) => t.name)
+        .filter((name) => !allCodingToolNames.includes(name));
+      inner.setActiveToolsByName([...toolNames, ...extensionToolNames]);
+    }

测试

  • tsc --noEmit 通过;
  • 根因已对 SDK 源码逐层确认(createAgentSession → allowedToolNames / isAllowedTool / includeAllExtensionTools);
  • 建议在已装扩展的环境(如 pi install npm:pi-subagents)新建一个 session 验证 subagent 出现。

备注

更彻底的做法可让 ToolPanel 同时列出扩展工具供逐个开关;本 PR 先做最小后端修复,恢复「扩展工具默认可用」的预期行为。

Related: #79

startRpcSession passed a builtin-only allow-list (allCodingToolNames) to
createAgentSession for non-empty tool presets. In the SDK that sets
allowedToolNames, and isAllowedTool() filters the tool registry by it, so every
extension/package-provided tool (pi-subagents' `subagent`, pi-web-access' web
tools, ...) was dropped from the registry — web sessions exposed only
read/bash/edit/write while the `pi` CLI kept the extension tools.

Don't restrict the allow-list for non-empty presets (leave allowedToolNames
undefined so all tools register and extension tools activate); set the active
set to the requested builtin tools plus all extension tools. "Off" (empty
array) and resume (no toolNames) paths are unchanged.

Addresses the symptom reported in #79.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
cnbattle added a commit to cnbattle/pi-web that referenced this pull request Jun 23, 2026
…upstream

PR agegr#83: fix extension/package tools available in pi-web new sessions
PR agegr#80: load extension models in web model selector
PR agegr#78: add ToolsConfig panel with individual tool toggles
PR agegr#65: add scroll-to-bottom control for chat sessions
PR agegr#75: add rehype-raw plugin to render HTML tables in markdown
PR agegr#76: fix stack overflow on large session files (+TTL cache)
@agegr agegr mentioned this pull request Jun 24, 2026
@agegr
agegr merged commit 8b3fefd into agegr:main Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants