personal-bot 0.3.0 → 0.3.2

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 (256) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +1 -1
  4. package/README.zh-CN.md +1 -1
  5. package/bin/pbot-pi-acp.mjs +27 -11
  6. package/bin/pbot.mjs +1 -1
  7. package/docs/README.md +1 -1
  8. package/docs/architecture/design.md +23 -10
  9. package/docs/architecture/extensibility.md +20 -18
  10. package/docs/architecture/model-context.md +2 -2
  11. package/docs/architecture/principles.md +4 -3
  12. package/docs/guides/capabilities.md +3 -3
  13. package/docs/guides/history.md +50 -16
  14. package/docs/guides/workspace-configuration.md +31 -6
  15. package/docs/hosts/antigravity.md +2 -0
  16. package/docs/hosts/claude-code.md +1 -1
  17. package/docs/hosts/dsh.md +1 -1
  18. package/docs/hosts/pi.md +1 -1
  19. package/hooks/hooks.json +3 -0
  20. package/lib/antigravity-plugin/hooks.json +7 -0
  21. package/lib/antigravity-plugin/lib/claude.js +2 -2
  22. package/lib/antigravity-plugin/lib/extension/acp-worker.js +156 -11
  23. package/lib/antigravity-plugin/lib/extension/{plugin-runtime.d.ts → hosts/plugin-runtime.d.ts} +2 -2
  24. package/lib/antigravity-plugin/lib/extension/{plugin-runtime.js → hosts/plugin-runtime.js} +34 -8
  25. package/lib/antigravity-plugin/lib/extension/mcp.js +1113 -78
  26. package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +1 -0
  27. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +5 -1
  28. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
  29. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.js +171 -0
  30. package/lib/antigravity-plugin/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
  31. package/lib/antigravity-plugin/lib/integrations/hosts/{claude.js → claude/adapter.js} +32 -4
  32. package/lib/antigravity-plugin/lib/integrations/hosts/{registry.js → plugin-registry.js} +2 -2
  33. package/lib/antigravity-plugin/lib/model/history.d.ts +169 -0
  34. package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +26 -0
  35. package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +25 -0
  36. package/lib/antigravity-plugin/lib/plugin.js +2 -2
  37. package/lib/antigravity-plugin/lib/services/history/history-capture.d.ts +4 -0
  38. package/lib/antigravity-plugin/lib/services/history/history-capture.js +86 -0
  39. package/lib/antigravity-plugin/lib/services/history/history-index.d.ts +17 -0
  40. package/lib/antigravity-plugin/lib/services/history/history-index.js +112 -0
  41. package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +12 -0
  42. package/lib/antigravity-plugin/lib/services/history/history-migrate.js +88 -0
  43. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
  44. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.js +121 -0
  45. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.d.ts +7 -0
  46. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.js +124 -0
  47. package/lib/antigravity-plugin/lib/services/history/summary-registry.d.ts +7 -0
  48. package/lib/antigravity-plugin/lib/services/history/summary-registry.js +36 -0
  49. package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +37 -0
  50. package/lib/antigravity-plugin/lib/services/history/summary-runner.js +301 -0
  51. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +5 -1
  52. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +75 -4
  53. package/lib/antigravity-plugin/lib/storage/file-access.d.ts +2 -0
  54. package/lib/antigravity-plugin/lib/storage/file-access.js +26 -0
  55. package/lib/antigravity-plugin/lib/storage/history-files.d.ts +54 -0
  56. package/lib/antigravity-plugin/lib/storage/history-files.js +467 -0
  57. package/lib/antigravity-plugin/lib/storage/history-format.d.ts +6 -0
  58. package/lib/antigravity-plugin/lib/storage/history-format.js +62 -0
  59. package/lib/antigravity-plugin/package.json +1 -1
  60. package/lib/antigravity-plugin/plugin.json +1 -1
  61. package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +22 -12
  62. package/lib/claude.js +2 -2
  63. package/lib/client.js +21 -11
  64. package/lib/dsh.js +4 -4
  65. package/lib/extension/{acp-member.d.ts → acp/member.d.ts} +5 -5
  66. package/lib/extension/{acp-member.js → acp/member.js} +6 -6
  67. package/lib/extension/acp/worker.d.ts +1 -0
  68. package/lib/extension/acp/worker.js +384 -0
  69. package/lib/extension/acp-worker.js +156 -11
  70. package/lib/extension/{dsh → hosts/dsh}/acp-member.js +8 -8
  71. package/lib/extension/hosts/dsh/command.js +92 -0
  72. package/lib/extension/{dsh → hosts/dsh}/files.js +3 -3
  73. package/lib/extension/hosts/dsh/history.d.ts +4 -0
  74. package/lib/extension/hosts/dsh/history.js +62 -0
  75. package/lib/extension/{dsh → hosts/dsh}/management.d.ts +1 -1
  76. package/lib/extension/{dsh → hosts/dsh}/management.js +12 -10
  77. package/lib/extension/{dsh → hosts/dsh}/workspace.d.ts +3 -9
  78. package/lib/extension/{dsh → hosts/dsh}/workspace.js +32 -70
  79. package/lib/extension/{plugin-runtime.d.ts → hosts/plugin-runtime.d.ts} +2 -2
  80. package/lib/extension/{plugin-runtime.js → hosts/plugin-runtime.js} +34 -8
  81. package/lib/extension/{mcp-bridge.d.ts → mcp/bridge.d.ts} +1 -1
  82. package/lib/extension/{mcp-bridge.js → mcp/bridge.js} +4 -4
  83. package/lib/extension/{mcp-workers.d.ts → mcp/workers.d.ts} +222 -2
  84. package/lib/extension/{mcp-workers.js → mcp/workers.js} +229 -63
  85. package/lib/extension/mcp.js +1113 -78
  86. package/lib/extension/{setup-cli.js → setup/cli.js} +9 -9
  87. package/lib/integrations/acp/connection.d.ts +11 -10
  88. package/lib/integrations/acp/connection.js +6 -0
  89. package/lib/integrations/acp/harnesses/claude.js +1 -1
  90. package/lib/integrations/acp/harnesses/dsh.js +1 -1
  91. package/lib/integrations/acp/history-summary.d.ts +17 -0
  92. package/lib/integrations/acp/history-summary.js +100 -0
  93. package/lib/integrations/agent-resources.d.ts +1 -0
  94. package/lib/integrations/agent-resources.js +5 -1
  95. package/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
  96. package/lib/integrations/hosts/antigravity/adapter.js +171 -0
  97. package/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
  98. package/lib/integrations/hosts/{claude.js → claude/adapter.js} +32 -4
  99. package/lib/integrations/{dsh → hosts/dsh}/mcp.d.ts +1 -1
  100. package/lib/integrations/{dsh → hosts/dsh}/resources.d.ts +1 -1
  101. package/lib/integrations/{dsh → hosts/dsh}/resources.js +4 -4
  102. package/lib/integrations/{dsh → hosts/dsh}/schema.js +1 -1
  103. package/lib/integrations/{dsh → hosts/dsh}/skills.js +1 -1
  104. package/lib/integrations/hosts/{registry.js → plugin-registry.js} +2 -2
  105. package/lib/integrations/installation/pi-setup.js +1 -1
  106. package/lib/model/history.d.ts +133 -34
  107. package/lib/model/plugin-host.d.ts +26 -0
  108. package/lib/model/workspace-config.d.ts +25 -0
  109. package/lib/plugin.js +2 -2
  110. package/lib/services/agents/agent-run.d.ts +1 -1
  111. package/lib/services/history/history-capture.d.ts +4 -0
  112. package/lib/services/history/history-capture.js +86 -0
  113. package/lib/services/history/history-index.d.ts +16 -7
  114. package/lib/services/history/history-index.js +48 -70
  115. package/lib/services/history/history-migrate.d.ts +12 -0
  116. package/lib/services/history/history-migrate.js +88 -0
  117. package/lib/services/history/history-query.d.ts +51 -0
  118. package/lib/services/history/history-query.js +371 -0
  119. package/lib/services/history/summary-command.d.ts +20 -0
  120. package/lib/services/history/summary-command.js +68 -0
  121. package/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
  122. package/lib/services/history/summary-dimensions/monthly.js +121 -0
  123. package/lib/services/history/summary-dimensions/session.d.ts +7 -0
  124. package/lib/services/history/summary-dimensions/session.js +124 -0
  125. package/lib/services/history/summary-registry.d.ts +7 -0
  126. package/lib/services/history/summary-registry.js +36 -0
  127. package/lib/services/history/summary-runner.d.ts +37 -0
  128. package/lib/services/history/summary-runner.js +301 -0
  129. package/lib/services/workspace/workspace-config.d.ts +5 -1
  130. package/lib/services/workspace/workspace-config.js +75 -4
  131. package/lib/storage/history-files.d.ts +45 -9
  132. package/lib/storage/history-files.js +373 -247
  133. package/lib/storage/history-format.d.ts +3 -12
  134. package/lib/storage/history-format.js +26 -50
  135. package/lib/tools/history/actions.d.ts +3 -68
  136. package/lib/tools/history/actions.js +7 -5
  137. package/lib/tools/history/contract.d.ts +14 -7
  138. package/lib/tools/history/contract.js +58 -18
  139. package/lib/tools/history/dsh-tool.d.ts +1 -2
  140. package/lib/tools/history/dsh-tool.js +11 -5
  141. package/lib/ui/dsh/management.js +18 -5
  142. package/package.json +1 -1
  143. package/resources/prompts/history-coordinator.md +1 -1
  144. package/resources/prompts/history-monthly-summary.md +13 -0
  145. package/resources/prompts/history-summary.md +10 -4
  146. package/resources/skills/provider-connections/SKILL.md +22 -12
  147. package/src/claude.ts +2 -2
  148. package/src/dsh.ts +4 -4
  149. package/src/extension/{acp-member.ts → acp/member.ts} +7 -7
  150. package/src/extension/{acp-worker.ts → acp/worker.ts} +131 -17
  151. package/src/extension/{dsh → hosts/dsh}/acp-member.ts +9 -9
  152. package/src/extension/hosts/dsh/command.ts +92 -0
  153. package/src/extension/{dsh → hosts/dsh}/files.ts +3 -3
  154. package/src/extension/hosts/dsh/history.ts +67 -0
  155. package/src/extension/{dsh → hosts/dsh}/management.ts +11 -9
  156. package/src/extension/{dsh → hosts/dsh}/workspace.ts +31 -50
  157. package/src/extension/{pi-acp-member.ts → hosts/pi/acp-member.ts} +9 -9
  158. package/src/extension/hosts/pi/command.ts +158 -0
  159. package/src/extension/{events.ts → hosts/pi/events.ts} +14 -4
  160. package/src/extension/hosts/pi/history.ts +45 -0
  161. package/src/extension/{lifecycle.ts → hosts/pi/lifecycle.ts} +7 -11
  162. package/src/extension/{plugin-runtime.ts → hosts/plugin-runtime.ts} +29 -9
  163. package/src/extension/{mcp-bridge.ts → mcp/bridge.ts} +5 -5
  164. package/src/extension/{mcp-workers.ts → mcp/workers.ts} +237 -64
  165. package/src/extension/{setup-cli.ts → setup/cli.ts} +11 -11
  166. package/src/integrations/acp/connection.ts +6 -0
  167. package/src/integrations/acp/harnesses/claude.ts +1 -1
  168. package/src/integrations/acp/harnesses/dsh.ts +1 -1
  169. package/src/integrations/acp/history-summary.ts +108 -0
  170. package/src/integrations/agent-resources.ts +6 -0
  171. package/src/integrations/hosts/antigravity/adapter.ts +161 -0
  172. package/src/integrations/hosts/{claude.ts → claude/adapter.ts} +28 -5
  173. package/src/integrations/{dsh → hosts/dsh}/mcp.ts +1 -1
  174. package/src/integrations/{dsh → hosts/dsh}/resources.ts +5 -5
  175. package/src/integrations/{dsh → hosts/dsh}/schema.ts +1 -1
  176. package/src/integrations/{dsh → hosts/dsh}/session.ts +2 -2
  177. package/src/integrations/{dsh → hosts/dsh}/skills.ts +1 -1
  178. package/src/integrations/{pi → hosts/pi}/mcp.ts +1 -1
  179. package/src/integrations/{pi → hosts/pi}/skills.ts +1 -1
  180. package/src/integrations/hosts/{registry.ts → plugin-registry.ts} +2 -2
  181. package/src/integrations/installation/pi-setup.ts +1 -1
  182. package/src/mcp.ts +1 -1
  183. package/src/model/history.ts +151 -26
  184. package/src/model/plugin-host.ts +26 -2
  185. package/src/model/workspace-config.ts +30 -0
  186. package/src/pbot.ts +13 -22
  187. package/src/plugin.ts +2 -2
  188. package/src/services/history/history-capture.ts +83 -0
  189. package/src/services/history/history-index.ts +48 -62
  190. package/src/services/history/history-migrate.ts +89 -0
  191. package/src/services/history/history-query.ts +415 -0
  192. package/src/services/history/summary-command.ts +69 -0
  193. package/src/services/history/summary-dimensions/monthly.ts +139 -0
  194. package/src/services/history/summary-dimensions/session.ts +149 -0
  195. package/src/services/history/summary-registry.ts +44 -0
  196. package/src/services/history/summary-runner.ts +352 -0
  197. package/src/services/workspace/workspace-config.ts +93 -5
  198. package/src/storage/history-files.ts +408 -188
  199. package/src/storage/history-format.ts +46 -60
  200. package/src/tools/history/actions.ts +8 -6
  201. package/src/tools/history/contract.ts +65 -20
  202. package/src/tools/history/dsh-tool.ts +17 -8
  203. package/src/tools/history/pi-tool.ts +21 -0
  204. package/src/tools/register.ts +3 -4
  205. package/src/ui/dsh/management.ts +27 -11
  206. package/src/ui/{confirmation.ts → pi/confirmation.ts} +1 -1
  207. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.d.ts +0 -4
  208. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.js +0 -79
  209. package/lib/extension/dsh/command.js +0 -50
  210. package/lib/extension/dsh/history.d.ts +0 -15
  211. package/lib/extension/dsh/history.js +0 -87
  212. package/lib/integrations/dsh/history-summary.d.ts +0 -11
  213. package/lib/integrations/dsh/history-summary.js +0 -36
  214. package/lib/integrations/dsh/history.d.ts +0 -16
  215. package/lib/integrations/dsh/history.js +0 -167
  216. package/lib/integrations/history-summary.d.ts +0 -4
  217. package/lib/integrations/history-summary.js +0 -32
  218. package/lib/integrations/hosts/antigravity.d.ts +0 -4
  219. package/lib/integrations/hosts/antigravity.js +0 -79
  220. package/lib/services/history/history-service.d.ts +0 -106
  221. package/lib/services/history/history-service.js +0 -242
  222. package/lib/storage/acp-history.d.ts +0 -10
  223. package/lib/storage/acp-history.js +0 -57
  224. package/src/extension/command.ts +0 -76
  225. package/src/extension/dsh/command.ts +0 -54
  226. package/src/extension/dsh/history.ts +0 -74
  227. package/src/extension/history.ts +0 -26
  228. package/src/integrations/dsh/history-summary.ts +0 -39
  229. package/src/integrations/dsh/history.ts +0 -84
  230. package/src/integrations/history-summary.ts +0 -30
  231. package/src/integrations/hosts/antigravity.ts +0 -83
  232. package/src/integrations/pi/history.ts +0 -99
  233. package/src/services/history/history-service.ts +0 -195
  234. package/src/storage/acp-history.ts +0 -49
  235. package/src/tools/history/tool.ts +0 -19
  236. /package/lib/antigravity-plugin/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +0 -0
  237. /package/lib/{extension/acp-worker.d.ts → antigravity-plugin/lib/model/history.js} +0 -0
  238. /package/lib/extension/{dsh → hosts/dsh}/acp-member.d.ts +0 -0
  239. /package/lib/extension/{dsh → hosts/dsh}/command.d.ts +0 -0
  240. /package/lib/extension/{dsh → hosts/dsh}/files.d.ts +0 -0
  241. /package/lib/extension/{setup-guard.js → setup/guard.js} +0 -0
  242. /package/lib/integrations/acp/{claude.d.ts → claude-settings.d.ts} +0 -0
  243. /package/lib/integrations/acp/{claude.js → claude-settings.js} +0 -0
  244. /package/lib/integrations/{dsh → hosts/dsh}/mcp.js +0 -0
  245. /package/lib/integrations/{dsh → hosts/dsh}/messages.d.ts +0 -0
  246. /package/lib/integrations/{dsh → hosts/dsh}/messages.js +0 -0
  247. /package/lib/integrations/{dsh → hosts/dsh}/root-agents.d.ts +0 -0
  248. /package/lib/integrations/{dsh → hosts/dsh}/root-agents.js +0 -0
  249. /package/lib/integrations/{dsh → hosts/dsh}/schema.d.ts +0 -0
  250. /package/lib/integrations/{dsh → hosts/dsh}/skills.d.ts +0 -0
  251. /package/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +0 -0
  252. /package/src/extension/{setup-guard.ts → setup/guard.ts} +0 -0
  253. /package/src/integrations/acp/{claude.ts → claude-settings.ts} +0 -0
  254. /package/src/integrations/{dsh → hosts/dsh}/messages.ts +0 -0
  255. /package/src/integrations/{dsh → hosts/dsh}/root-agents.ts +0 -0
  256. /package/src/integrations/{pi → hosts/pi}/agent-tools.ts +0 -0
@@ -3,11 +3,11 @@ import { realpath, stat } from "node:fs/promises";
3
3
  import { homedir } from "node:os";
4
4
  import { isAbsolute, join } from "node:path";
5
5
  import { setTimeout as delay } from "node:timers/promises";
6
- import { object } from "../common/json.js";
7
- import { isAcpBackend, requireThat } from "../common/validation.js";
8
- import { packageVersion } from "../common/version.js";
9
- import { AcpWorkerHost } from "../integrations/acp/agents.js";
10
- import { canonicalAcpBackend, inspectAcpBackends, knownAcpBackends } from "../integrations/acp/launch.js";
6
+ import { object } from "../../common/json.js";
7
+ import { isAcpBackend, requireThat } from "../../common/validation.js";
8
+ import { packageVersion } from "../../common/version.js";
9
+ import { AcpWorkerHost } from "../../integrations/acp/agents.js";
10
+ import { canonicalAcpBackend, inspectAcpBackends, knownAcpBackends } from "../../integrations/acp/launch.js";
11
11
  import {
12
12
  mcpWorkerToolNames,
13
13
  type AcpCommands,
@@ -15,12 +15,14 @@ import {
15
15
  type AcpElicitationContent,
16
16
  type AcpModelSelection,
17
17
  type McpWorkerToolName,
18
- } from "../model/acp.js";
19
- import { workspaceMcpToolNames, type WorkspaceMcpToolName } from "../model/workspace-mcp.js";
20
- import type { AgentCycle, AgentOwner, AgentView } from "../model/agent.js";
21
- import { AgentService } from "../services/agents/agent-service.js";
22
- import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../services/workspace/workspace-config.js";
23
- import { WorkspaceMcpBridge } from "./mcp-bridge.js";
18
+ } from "../../model/acp.js";
19
+ import { workspaceMcpToolNames, type WorkspaceMcpToolName } from "../../model/workspace-mcp.js";
20
+ import type { AgentCycle, AgentOwner, AgentView } from "../../model/agent.js";
21
+ import { AgentService } from "../../services/agents/agent-service.js";
22
+ import { readWorkspaceHistory, searchWorkspaceHistory } from "../../services/history/history-query.js";
23
+ import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../services/workspace/workspace-config.js";
24
+ import { isHistoryHost, isSummaryDimension } from "../../storage/history-format.js";
25
+ import { WorkspaceMcpBridge } from "./bridge.js";
24
26
 
25
27
  const protocolVersion = "2025-03-26";
26
28
  const readyTimeoutMs = 45_000;
@@ -33,8 +35,10 @@ const responseActions = ["accept", "decline", "cancel"] as const;
33
35
  const discoverTargets = ["overview", "workers", "backends", "models"] as const;
34
36
  type DiscoverTarget = typeof discoverTargets[number];
35
37
 
36
- type AllMcpToolName = McpWorkerToolName | WorkspaceMcpToolName;
37
- const allMcpToolNames: readonly AllMcpToolName[] = [...mcpWorkerToolNames, ...workspaceMcpToolNames];
38
+ const mcpHistoryToolNames = ["history_search", "history_read"] as const;
39
+ type McpHistoryToolName = typeof mcpHistoryToolNames[number];
40
+ type AllMcpToolName = McpWorkerToolName | WorkspaceMcpToolName | McpHistoryToolName;
41
+ const allMcpToolNames: readonly AllMcpToolName[] = [...mcpWorkerToolNames, ...workspaceMcpToolNames, ...mcpHistoryToolNames];
38
42
 
39
43
  const toolParams: Record<AllMcpToolName, ReadonlySet<string>> = {
40
44
  worker_create: new Set(["backend", "model", "thinking", "cwd", "workspace"]),
@@ -45,6 +49,8 @@ const toolParams: Record<AllMcpToolName, ReadonlySet<string>> = {
45
49
  worker_discover: new Set(["target", "workerId", "backend", "model", "workspace"]),
46
50
  workspace_mcp_discover: new Set(["server", "workspace"]),
47
51
  workspace_mcp_call: new Set(["server", "tool", "arguments", "workspace"]),
52
+ history_search: new Set(["host", "dimension", "query", "sessionId", "from", "to", "offset", "limit", "workspace"]),
53
+ history_read: new Set(["id", "host", "offset", "limit", "childrenOffset", "workspace"]),
48
54
  };
49
55
 
50
56
  const shortToolMap: Record<string, McpWorkerToolName> = {
@@ -58,10 +64,15 @@ const shortToolMap: Record<string, McpWorkerToolName> = {
58
64
 
59
65
  export type ProgressReporter = (message: string) => void;
60
66
 
67
+ export const mcpWorkerOnlyInstructions =
68
+ "提供跨助手协作能力(worker_*):可启动并调度其他外部 AI 助手在当前工作区中独立执行任务,适用于用户指定其他助手、需要特定模型或思考深度、获取独立审查/第二意见,或并行处理子任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。\n" +
69
+ "使用流程:用 worker_create 启动目标助手(或用 worker_discover 复用已有会话)→ 用 worker_request 派发任务或继续追问 → 任务完成后可用 worker_close 结束会话。后台等待、超时续等(timedOut)或长结果翻页(nextOffset)用 worker_output;助手请求授权或提问(needsResponse)时,先向用户确认,再用 worker_response 回复。";
70
+
61
71
  export const mcpInstructions =
62
- "用于跨代理程序委派任务(worker_*)与调用工作区统一注册的外部 MCP 服务(workspace_mcp_*);未指定其他程序时,优先由当前程序或其原生子代理直接完成。\n" +
63
- "跨程序委派:worker_create 创建 worker(或用 worker_discover 复用已有 worker)→ worker_request 发送任务或后续消息 → 用完可用 worker_close 关闭;后台等待、超时续等(timedOut)或长报告翻页(nextOffset)用 worker_output;返回 needsResponse 时向用户确认后用 worker_response 回复。\n" +
64
- "工作区统一 MCP(.pbot/mcp.json):先用 workspace_mcp_discover 查看已注册服务或指定服务的工具清单,再用 workspace_mcp_call 调用目标工具;可与宿主原生 MCP 同时使用。";
72
+ "提供三类能力:\n" +
73
+ "1. 跨助手协作(worker_*):启动并调度其他外部 AI 助手在当前工作区中独立执行任务,适用于用户指定其他助手、需要特定模型或思考深度、获取独立审查/第二意见,或并行处理子任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。使用流程:worker_create 启动助手(或 worker_discover 复用已有会话)→ worker_request 派发任务或追问 → 完成后 worker_close 结束;后台等待、超时续等(timedOut)或长结果翻页(nextOffset)用 worker_output;返回 needsResponse 时先向用户确认,再用 worker_response 回复。\n" +
74
+ "2. 工作区共享外部工具(workspace_mcp_*):发现并调用当前工作区接入的外部工具服务与数据源(可与当前环境原生工具同时使用)。先用 workspace_mcp_discover 查看可用服务与工具说明,再用 workspace_mcp_call 调用。\n" +
75
+ "3. 跨宿主历史查询(history_search / history_read):只读检索当前工作区在 Pi、dsh、Claude Code、Antigravity 等宿主中记录的历史问答与摘要归档。";
65
76
 
66
77
  function formatBackendItem(entry: ReturnType<typeof inspectAcpBackends>[number], defaultBackend?: string): string {
67
78
  const tags: string[] = [];
@@ -78,9 +89,9 @@ function summarizeBackends(commands: AcpCommands = {}, defaultBackend?: string)
78
89
  const unavailableText = unavailable.map(item => formatBackendItem(item, defaultBackend)).join("、");
79
90
  const overview = available.length
80
91
  ? unavailable.length
81
- ? `可用 backend:${availableText};不可用:${unavailableText}。`
82
- : `可用 backend:${availableText}。`
83
- : `当前无可用 backend(不可用:${unavailableText})。`;
92
+ ? `当前可用助手:${availableText};暂不可用:${unavailableText}。`
93
+ : `当前可用助手:${availableText}。`
94
+ : `当前无可用外部助手(暂不可用:${unavailableText})。`;
84
95
  const availableIds = available.map(item => item.backend).join("、");
85
96
  return { overview, availableIds };
86
97
  }
@@ -89,8 +100,8 @@ function workspaceProperty(workspaceBound: boolean) {
89
100
  return {
90
101
  type: "string",
91
102
  description: workspaceBound
92
- ? "工作区根目录绝对路径;已默认绑定当前工作区,通常省略。"
93
- : "工作区根目录绝对路径(上下文提供 workspaceRoot 时传该路径);当前未默认绑定,请显式传入。",
103
+ ? "目标工作区根目录的绝对路径;默认使用当前工作区,通常省略。"
104
+ : "目标工作区根目录的绝对路径(如上下文中提供了 workspaceRoot 则传该路径);请显式传入。",
94
105
  };
95
106
  }
96
107
 
@@ -105,8 +116,8 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
105
116
  {
106
117
  name: "worker_create",
107
118
  description:
108
- "创建一个新的 worker 并返回其 workerId(仅创建,不发送任务;随后用 worker_request 派发任务)。" +
109
- "未指定其他程序时优先由当前程序或其原生子代理完成。\n" +
119
+ "启动一个独立的外部 AI 助手会话(worker),用于将任务委派给其他助手或指定模型/思考深度来独立处理(如按用户要求切换助手、获取独立审查或第二意见、并行分担子任务)。" +
120
+ "本工具仅建立会话并返回 workerId,随后通过 worker_request 发送具体任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。\n" +
110
121
  overview,
111
122
  annotations: {
112
123
  title: "Create Worker",
@@ -122,19 +133,19 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
122
133
  properties: {
123
134
  backend: {
124
135
  type: "string",
125
- description: "目标代理程序名称,不区分大小写,支持常见别名(如 claude-code、agy)。",
136
+ description: "要启动的外部助手标识(不区分大小写,支持常见别名,如 claude-code、agy)。",
126
137
  },
127
138
  model: {
128
139
  type: "string",
129
- description: "仅用户明确指定模型时传入(支持模型 ID、显示名或 provider/model,不区分大小写);不确定合法值可用 worker_discover(target=\"models\") 查询;省略则使用目标默认。",
140
+ description: "仅用户明确要求特定模型时指定(支持模型 ID、显示名或 provider/model,不区分大小写);不确定可用值时先用 worker_discover(target=\"models\") 查询;不填则使用该助手默认模型。",
130
141
  },
131
142
  thinking: {
132
143
  type: "string",
133
- description: "仅用户明确指定思考力度时传入(如 low / medium / high / xhigh / max,不区分大小写);省略则使用目标默认。",
144
+ description: "仅用户明确要求思考深度时指定(如 low / medium / high / xhigh / max,不区分大小写);不填则使用默认设置。",
134
145
  },
135
146
  cwd: {
136
147
  type: "string",
137
- description: "worker 工作目录(相对工作区根目录或绝对路径),默认为工作区根目录。",
148
+ description: "助手执行任务时的工作目录(绝对路径或相对工作区的路径),默认为当前工作区根目录。",
138
149
  },
139
150
  workspace,
140
151
  },
@@ -143,7 +154,7 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
143
154
  {
144
155
  name: "worker_close",
145
156
  description:
146
- "关闭指定 worker。若该 worker 支持恢复(capabilities.resume 为 true),后续仍可直接用 worker_request 继续会话。",
157
+ "结束不再需要的外部助手会话并释放资源。若该助手支持会话恢复,后续仍可直接用 worker_request 在原上下文中继续对话。",
147
158
  annotations: {
148
159
  title: "Close Worker",
149
160
  readOnlyHint: false,
@@ -158,7 +169,7 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
158
169
  properties: {
159
170
  workerId: {
160
171
  type: "string",
161
- description: "要关闭的 worker ID(来自 worker_create 或 worker_discover)。",
172
+ description: "要结束的助手会话 ID(来自 worker_create 或 worker_discover)。",
162
173
  },
163
174
  workspace,
164
175
  },
@@ -167,9 +178,9 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
167
178
  {
168
179
  name: "worker_request",
169
180
  description:
170
- "向指定 worker 发送任务或后续消息(若已关闭且支持恢复,会自动续接会话)。" +
171
- `默认最多等待 ${defaultWaitMs / 1000} 秒返回报告(waitMs 设为 0 立即返回并在后台执行);` +
172
- "若返回 timedOut 或报告含 nextOffset 用 worker_output 继续,返回 needsResponse 时向用户确认后用 worker_response 回复。",
181
+ "向指定的外部助手派发任务,或在同一上下文中追问与补充要求,并获取执行结果(已关闭但支持恢复的会话会自动续接)。" +
182
+ `默认最多等待 ${defaultWaitMs / 1000} 秒返回结果;将 waitMs 设为 0 可立即返回并转入后台执行,适合耗时任务或多助手并行。` +
183
+ "若返回 timedOut 或结果含 nextOffset,用 worker_output 继续等待或翻页;若返回 needsResponse,先向用户确认再用 worker_response 回复。",
173
184
  annotations: {
174
185
  title: "Send Request to Worker",
175
186
  readOnlyHint: false,
@@ -184,17 +195,17 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
184
195
  properties: {
185
196
  workerId: {
186
197
  type: "string",
187
- description: "目标 worker ID(来自 worker_create 或 worker_discover)。",
198
+ description: "目标助手会话 ID(来自 worker_create 或 worker_discover)。",
188
199
  },
189
200
  message: {
190
201
  type: "string",
191
- description: "发给 worker 的任务说明或后续消息。worker 看不到当前对话历史,首次派发时请写清目标、相关文件路径、约束和交付要求。",
202
+ description: "要发送的任务说明或追问内容。外部助手看不到你与用户的对话历史,首次派发时请写清背景、目标、相关文件路径、约束条件和期望产出。",
192
203
  },
193
204
  waitMs: {
194
205
  type: "integer",
195
206
  minimum: 0,
196
207
  maximum: maxWaitMs,
197
- description: `最多等待的毫秒数(默认 ${defaultWaitMs});传 0 立即返回并在后台执行。`,
208
+ description: `最多等待结果的毫秒数(默认 ${defaultWaitMs});设为 0 可立即返回并在后台执行。`,
198
209
  },
199
210
  workspace,
200
211
  },
@@ -203,8 +214,9 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
203
214
  {
204
215
  name: "worker_response",
205
216
  description:
206
- "回复 worker 返回 needsResponse: true 时的待处理请求(pendingRequests),用于权限审批(kind=\"permission\")、表单提问(kind=\"form\")和 URL 确认(kind=\"url\")。" +
207
- `回复前先向用户确认;回复后默认最多等待 ${defaultWaitMs / 1000} 秒返回后续结果(waitMs 设为 0 立即返回)。`,
217
+ "当外部助手在执行过程中暂停并请求确认或补充信息(返回 needsResponse: true)时,向其提交决定以继续执行。" +
218
+ "支持三类请求:操作授权(kind=\"permission\")、问答表单(kind=\"form\")和链接确认(kind=\"url\")。" +
219
+ `提交前先向用户确认;提交后默认最多等待 ${defaultWaitMs / 1000} 秒返回后续结果(waitMs 设为 0 立即返回)。`,
208
220
  annotations: {
209
221
  title: "Respond to Worker Request",
210
222
  readOnlyHint: false,
@@ -219,31 +231,31 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
219
231
  properties: {
220
232
  workerId: {
221
233
  type: "string",
222
- description: "存在待处理请求的 worker ID。",
234
+ description: "等待回复的助手会话 ID。",
223
235
  },
224
236
  action: {
225
237
  type: "string",
226
238
  enum: [...responseActions],
227
- description: "accept:同意权限、提交表单或确认 URL;decline:拒绝;cancel:取消。",
239
+ description: "处理方式:accept 表示同意授权、提交表单回答或确认链接;decline 表示拒绝;cancel 表示取消本次请求。",
228
240
  },
229
241
  requestId: {
230
242
  type: "string",
231
- description: "待回复的 pendingRequests[].requestId;仅一条请求时可省略,多条时必填。",
243
+ description: "要回复的请求 ID(来自 pendingRequests[].requestId);仅一条待处理请求时可省略,多条时必填。",
232
244
  },
233
245
  optionId: {
234
246
  type: "string",
235
- description: "仅 kind=\"permission\" 且 action 不为 cancel 时可用:指定 pendingRequests[].options[].optionId(省略时默认单次允许或拒绝)。",
247
+ description: "仅授权请求(kind=\"permission\")且 action 不为 cancel 时可用:指定选项 ID(来自 pendingRequests[].options[].optionId),省略时默认单次允许或拒绝。",
236
248
  },
237
249
  content: {
238
250
  type: "object",
239
251
  additionalProperties: true,
240
- description: "仅 kind=\"form\" 且 action=\"accept\" 时可用:按 pendingRequests[].schema.properties 填写的答案对象(字段值支持字符串、数字、布尔或字符串数组)。",
252
+ description: "仅表单提问(kind=\"form\")且 action=\"accept\" 时可用:按 pendingRequests[].schema.properties 填写的回答对象(值为字符串、数字、布尔值或字符串数组)。",
241
253
  },
242
254
  waitMs: {
243
255
  type: "integer",
244
256
  minimum: 0,
245
257
  maximum: maxWaitMs,
246
- description: `回复后最多等待的毫秒数(默认 ${defaultWaitMs});传 0 立即返回。`,
258
+ description: `提交回复后最多等待后续结果的毫秒数(默认 ${defaultWaitMs});设为 0 立即返回。`,
247
259
  },
248
260
  workspace,
249
261
  },
@@ -252,7 +264,8 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
252
264
  {
253
265
  name: "worker_output",
254
266
  description:
255
- "获取指定 worker 最新一轮的执行报告:仍在运行时等待其完成(也可能返回 timedOut 或 needsResponse),已结束则立即返回;报告含 nextOffset 时传入 offset 翻页续读。",
267
+ "获取或等待外部助手的最新执行结果。用于收取后台任务的产出、在等待超时(timedOut)后继续等待,或在长结果分页(含 nextOffset)时读取后续内容。" +
268
+ "任务仍在运行时会等待其完成(也可能返回 timedOut 或 needsResponse),已结束则立即返回。",
256
269
  annotations: {
257
270
  title: "Get Worker Output",
258
271
  readOnlyHint: true,
@@ -267,18 +280,18 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
267
280
  properties: {
268
281
  workerId: {
269
282
  type: "string",
270
- description: "要等待或读取报告的 worker ID。",
283
+ description: "要等待或获取结果的助手会话 ID。",
271
284
  },
272
285
  offset: {
273
286
  type: "integer",
274
287
  minimum: 0,
275
- description: "报告字符偏移量(默认 0);翻页续读时传上次返回的 nextOffset。",
288
+ description: "结果读取起始位置(默认 0);翻页读取剩余内容时传入上次返回的 nextOffset。",
276
289
  },
277
290
  waitMs: {
278
291
  type: "integer",
279
292
  minimum: 0,
280
293
  maximum: maxWaitMs,
281
- description: `任务仍在运行时最多等待的毫秒数(默认 ${defaultWaitMs});已结束或翻页时立即返回。`,
294
+ description: `任务仍在运行时最多等待的毫秒数(默认 ${defaultWaitMs});任务已结束或翻页读取时会立即返回。`,
282
295
  },
283
296
  workspace,
284
297
  },
@@ -287,8 +300,8 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
287
300
  {
288
301
  name: "worker_discover",
289
302
  description:
290
- "查询可用 backend、当前会话已有 worker 的状态,或指定 backend 可选的模型与思考力度。" +
291
- "默认(target=\"overview\")返回可用 backend 与已有 worker;仅需确认模型或思考力度可选值时再查 target=\"models\"(耗时较长)。",
303
+ "了解当前可以委派哪些外部助手、查看已有助手会话的运行状态以便复用,或查询某个助手支持的模型与思考深度选项。" +
304
+ "默认(target=\"overview\")同时返回可用助手与已有会话;仅在需要核对模型或思考深度可选值时再查 target=\"models\"(耗时较长)。",
292
305
  annotations: {
293
306
  title: "Discover Workers, Backends & Models",
294
307
  readOnlyHint: true,
@@ -304,21 +317,21 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
304
317
  target: {
305
318
  type: "string",
306
319
  enum: [...discoverTargets],
307
- description: "查询范围,默认 \"overview\"(同时返回 backends 与 workers);\"workers\" 查全部或单个 worker 状态;\"backends\" 查可用 backend 列表;\"models\" 查指定 backend 的可选模型与思考力度。",
320
+ description: "查询范围,默认 \"overview\"(同时返回可用助手与已有会话);\"workers\" 查全部或单个会话状态;\"backends\" 查可用助手列表;\"models\" 查指定助手支持的模型与思考深度。",
308
321
  },
309
322
  workerId: {
310
323
  type: "string",
311
- description: "仅 target=\"workers\" 可用:指定单个 worker ID;省略时列出全部。",
324
+ description: "仅 target=\"workers\" 可用:指定单个助手会话 ID;不填则列出全部。",
312
325
  },
313
326
  backend: {
314
327
  type: "string",
315
328
  description: availableIds
316
- ? `仅 target="models" 可用(${modelsBackendHint}):目标代理程序名称,支持常见别名;可用:${availableIds}。`
317
- : `仅 target="models" 可用(${modelsBackendHint}):目标代理程序名称,支持常见别名。`,
329
+ ? `仅 target="models" 可用(${modelsBackendHint}):目标外部助手标识,支持常见别名;当前可用:${availableIds}。`
330
+ : `仅 target="models" 可用(${modelsBackendHint}):目标外部助手标识,支持常见别名。`,
318
331
  },
319
332
  model: {
320
333
  type: "string",
321
- description: "仅 target=\"models\" 可用:指定模型以查询该模型支持的思考力度选项。",
334
+ description: "仅 target=\"models\" 可用:指定模型以查看该模型支持的思考深度选项。",
322
335
  },
323
336
  workspace,
324
337
  },
@@ -333,7 +346,7 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
333
346
  {
334
347
  name: "workspace_mcp_discover",
335
348
  description:
336
- "查看工作区 .pbot/mcp.json 中统一注册的 MCP 服务列表;传入 server 时按需连接该服务并返回其全部工具及参数 schema。",
349
+ "发现当前工作区共享的外部工具服务(MCP)及其可用工具。不传 server 时列出可用服务;传入 server 时返回该服务提供的工具清单与参数说明。",
337
350
  annotations: {
338
351
  title: "Discover Workspace MCP Servers & Tools",
339
352
  readOnlyHint: true,
@@ -348,7 +361,7 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
348
361
  properties: {
349
362
  server: {
350
363
  type: "string",
351
- description: "目标 MCP 服务名(来自 .pbot/mcp.json 的键名);省略时仅列出已注册服务摘要。",
364
+ description: "目标工具服务名称;不填时列出工作区全部可用服务。",
352
365
  },
353
366
  workspace,
354
367
  },
@@ -357,8 +370,8 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
357
370
  {
358
371
  name: "workspace_mcp_call",
359
372
  description:
360
- "调用工作区 .pbot/mcp.json 中指定 MCP 服务的工具(首次调用按需连接并复用连接,配置变更自动热更新)。" +
361
- "不确定工具名或参数 schema 时,先用 workspace_mcp_discover(server) 查询。",
373
+ "调用当前工作区共享的外部工具服务(MCP)中的指定工具,用于访问工作区接入的外部能力与数据源。" +
374
+ "不确定工具名或参数格式时,先用 workspace_mcp_discover(server) 查询。",
362
375
  annotations: {
363
376
  title: "Call Workspace MCP Tool",
364
377
  readOnlyHint: false,
@@ -373,16 +386,121 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
373
386
  properties: {
374
387
  server: {
375
388
  type: "string",
376
- description: "目标 MCP 服务名(来自 .pbot/mcp.json)。",
389
+ description: "目标工具服务名称(可通过 workspace_mcp_discover 获取)。",
377
390
  },
378
391
  tool: {
379
392
  type: "string",
380
- description: "要调用的下游 MCP 工具名称。",
393
+ description: "要调用的工具名称。",
381
394
  },
382
395
  arguments: {
383
396
  type: "object",
384
397
  additionalProperties: true,
385
- description: "传递给下游 MCP 工具的参数对象,省略时为空对象。",
398
+ description: "传给目标工具的参数对象,不填则为空对象。",
399
+ },
400
+ workspace,
401
+ },
402
+ },
403
+ },
404
+ ];
405
+ }
406
+
407
+ export function buildHistoryMcpTools(workspaceBound = false) {
408
+ const workspace = workspaceProperty(workspaceBound);
409
+ return [
410
+ {
411
+ name: "history_search",
412
+ description:
413
+ "搜索当前工作区跨宿主(pi、dsh、claude、antigravity 等)的历史问答与摘要归档。省略 query 时列出各会话;传入 query 按不区分大小写的连续关键词匹配原文与摘要。",
414
+ annotations: {
415
+ title: "Search Workspace History",
416
+ readOnlyHint: true,
417
+ destructiveHint: false,
418
+ idempotentHint: true,
419
+ openWorldHint: false,
420
+ },
421
+ inputSchema: {
422
+ type: "object",
423
+ additionalProperties: false,
424
+ required: [],
425
+ properties: {
426
+ host: {
427
+ type: "string",
428
+ description: "可选来源筛选(如 pi、dsh、claude、antigravity);省略查全部宿主。",
429
+ },
430
+ dimension: {
431
+ type: "string",
432
+ description: "可选范围筛选:raw 表示仅搜原文,或指定摘要维度(如 monthly、session);省略查全部原文与维度摘要。",
433
+ },
434
+ query: {
435
+ type: "string",
436
+ description: "不区分大小写的连续关键词;省略时列出各会话(或指定维度摘要)。",
437
+ },
438
+ sessionId: {
439
+ type: "string",
440
+ description: "限定在指定原始会话 ID 内搜索。",
441
+ },
442
+ from: {
443
+ type: "string",
444
+ description: "ISO 日期或时间下界。",
445
+ },
446
+ to: {
447
+ type: "string",
448
+ description: "ISO 日期或时间上界。",
449
+ },
450
+ offset: {
451
+ type: "integer",
452
+ minimum: 0,
453
+ description: "匹配结果偏移,默认 0。",
454
+ },
455
+ limit: {
456
+ type: "integer",
457
+ minimum: 1,
458
+ maximum: 50,
459
+ description: "最多返回条数(1–50),默认 20。",
460
+ },
461
+ workspace,
462
+ },
463
+ },
464
+ },
465
+ {
466
+ name: "history_read",
467
+ description:
468
+ "按节点 id 读取当前工作区历史归档的正文与上下级节点(monthly、session、summary、exchange),支持从月度汇总下钻至单会话摘要与原始问答。正文过长时用 nextOffset 续读,子节点过多时用 nextChildrenOffset 续读。",
469
+ annotations: {
470
+ title: "Read Workspace History Node",
471
+ readOnlyHint: true,
472
+ destructiveHint: false,
473
+ idempotentHint: true,
474
+ openWorldHint: false,
475
+ },
476
+ inputSchema: {
477
+ type: "object",
478
+ additionalProperties: false,
479
+ required: ["id"],
480
+ properties: {
481
+ id: {
482
+ type: "string",
483
+ description: "history_search 或上下级返回的节点 id。",
484
+ },
485
+ host: {
486
+ type: "string",
487
+ description: "跨来源 ID 冲突时显式指定来源宿主。",
488
+ },
489
+ offset: {
490
+ type: "integer",
491
+ minimum: 0,
492
+ description: "正文字符偏移,默认 0。",
493
+ },
494
+ limit: {
495
+ type: "integer",
496
+ minimum: 1,
497
+ maximum: 24000,
498
+ description: "正文字符数(1–24000),默认 12000。",
499
+ },
500
+ childrenOffset: {
501
+ type: "integer",
502
+ minimum: 0,
503
+ description: "子节点列表偏移,默认 0;续读传上页 nextChildrenOffset。",
386
504
  },
387
505
  workspace,
388
506
  },
@@ -534,16 +652,30 @@ export class McpWorkerRuntime {
534
652
  readonly #sessionId: string;
535
653
  readonly #directory: string;
536
654
  readonly #defaultBackend: string | undefined;
655
+ readonly #nativeWorkspaceMcp: boolean;
656
+ readonly #nativeHistory: boolean;
537
657
  #closed = false;
538
658
 
539
659
  constructor(
540
660
  directory = defaultWorkerDirectory(),
541
661
  sessionId = process.env.PBOT_MCP_SESSION_ID || ("mcp-" + randomUUID()),
542
662
  defaultBackend = process.env.PBOT_HOST || undefined,
663
+ nativeWorkspaceMcp = /^(1|true)$/i.test(process.env.PBOT_NATIVE_WORKSPACE_MCP ?? ""),
664
+ nativeHistory = /^(1|true)$/i.test(process.env.PBOT_NATIVE_HISTORY ?? ""),
543
665
  ) {
544
666
  this.#directory = directory;
545
667
  this.#sessionId = sessionId;
546
668
  this.#defaultBackend = defaultBackend?.trim() || undefined;
669
+ this.#nativeWorkspaceMcp = nativeWorkspaceMcp;
670
+ this.#nativeHistory = nativeHistory;
671
+ }
672
+
673
+ get nativeWorkspaceMcp(): boolean {
674
+ return this.#nativeWorkspaceMcp;
675
+ }
676
+
677
+ get nativeHistory(): boolean {
678
+ return this.#nativeHistory;
547
679
  }
548
680
 
549
681
  private resolveBackend(rawArgs: Record<string, unknown>, commands: AcpCommands | undefined, allowDefault: boolean): string {
@@ -584,13 +716,16 @@ export class McpWorkerRuntime {
584
716
 
585
717
  async toolDefinitions() {
586
718
  let commands: AcpCommands | undefined;
587
- let includeWorkspaceMcp = true;
719
+ let includeWorkspaceMcp = !this.#nativeWorkspaceMcp;
720
+ let includeHistory = !this.#nativeHistory;
588
721
  try {
589
722
  const root = await this.resolveWorkspace();
590
723
  const configuration = await readWorkspaceConfig(root);
591
724
  if (configuration.enabled) {
592
725
  commands = configuration.acp;
593
- includeWorkspaceMcp = workspaceFeatures(configuration).mcp;
726
+ const features = workspaceFeatures(configuration);
727
+ includeWorkspaceMcp = !this.#nativeWorkspaceMcp && features.mcp;
728
+ includeHistory = !this.#nativeHistory && features.history;
594
729
  }
595
730
  } catch { /* Fall back to registered built-in harnesses when cwd is outside an enabled workspace. */ }
596
731
  const defaultBackend = this.#defaultBackend ? canonicalAcpBackend(this.#defaultBackend, commands) : undefined;
@@ -598,6 +733,7 @@ export class McpWorkerRuntime {
598
733
  return [
599
734
  ...buildPbotWorkerTools(commands, defaultBackend, workspaceBound),
600
735
  ...(includeWorkspaceMcp ? buildWorkspaceMcpTools(workspaceBound) : []),
736
+ ...(includeHistory ? buildHistoryMcpTools(workspaceBound) : []),
601
737
  ];
602
738
  }
603
739
 
@@ -697,11 +833,13 @@ export class McpWorkerRuntime {
697
833
 
698
834
  switch (name) {
699
835
  case "workspace_mcp_discover": {
836
+ requireThat(!this.#nativeWorkspaceMcp, "当前宿主已原生挂载工作区 .pbot/mcp.json 服务,请直接调用对应原生 MCP 工具,勿重复经由 workspace_mcp_* 桥接。");
700
837
  requireThat(workspaceFeatures(configuration).mcp, `工作区统一 MCP 功能已在 ${configuration.path} 中停用(features.mcp: false)。`);
701
838
  const server = asString(rawArgs, "server");
702
839
  return this.#bridge.discover(root, server);
703
840
  }
704
841
  case "workspace_mcp_call": {
842
+ requireThat(!this.#nativeWorkspaceMcp, "当前宿主已原生挂载工作区 .pbot/mcp.json 服务,请直接调用对应原生 MCP 工具,勿重复经由 workspace_mcp_* 桥接。");
705
843
  requireThat(workspaceFeatures(configuration).mcp, `工作区统一 MCP 功能已在 ${configuration.path} 中停用(features.mcp: false)。`);
706
844
  const server = asString(rawArgs, "server", true)!;
707
845
  const tool = asString(rawArgs, "tool", true)!;
@@ -709,6 +847,41 @@ export class McpWorkerRuntime {
709
847
  requireThat(object(toolArgs), "参数 arguments 必须是 JSON 对象。");
710
848
  return this.#bridge.call(root, server, tool, toolArgs);
711
849
  }
850
+ case "history_search": {
851
+ requireThat(!this.#nativeHistory, "当前宿主已提供原生 pbot_history 工具,请直接调用 pbot_history。");
852
+ requireThat(workspaceFeatures(configuration).history, `工作区历史功能已在 ${configuration.path} 中停用(features.history: false)。`);
853
+ const hostFilter = asString(rawArgs, "host");
854
+ if (hostFilter !== undefined) requireThat(isHistoryHost(hostFilter), "无效的 host 来源:" + hostFilter);
855
+ const dimension = asString(rawArgs, "dimension");
856
+ if (dimension !== undefined) requireThat(isSummaryDimension(dimension), "无效的 dimension:" + dimension);
857
+ const query = asString(rawArgs, "query");
858
+ const sessionId = asString(rawArgs, "sessionId");
859
+ const from = asString(rawArgs, "from");
860
+ const to = asString(rawArgs, "to");
861
+ const offset = asInt(rawArgs, "offset", 0, 10_000_000) ?? 0;
862
+ const limit = asInt(rawArgs, "limit", 1, 50) ?? 20;
863
+ return searchWorkspaceHistory(root, {
864
+ ...(hostFilter ? { host: hostFilter } : {}),
865
+ ...(dimension ? { dimension } : {}),
866
+ ...(query ? { query } : {}),
867
+ ...(sessionId ? { sessionId } : {}),
868
+ ...(from ? { from } : {}),
869
+ ...(to ? { to } : {}),
870
+ offset,
871
+ limit,
872
+ });
873
+ }
874
+ case "history_read": {
875
+ requireThat(!this.#nativeHistory, "当前宿主已提供原生 pbot_history 工具,请直接调用 pbot_history。");
876
+ requireThat(workspaceFeatures(configuration).history, `工作区历史功能已在 ${configuration.path} 中停用(features.history: false)。`);
877
+ const id = asString(rawArgs, "id", true)!;
878
+ const hostFilter = asString(rawArgs, "host");
879
+ if (hostFilter !== undefined) requireThat(isHistoryHost(hostFilter), "无效的 host 来源:" + hostFilter);
880
+ const offset = asInt(rawArgs, "offset", 0, 10_000_000) ?? 0;
881
+ const limit = asInt(rawArgs, "limit", 1, 24000) ?? 12000;
882
+ const childrenOffset = asInt(rawArgs, "childrenOffset", 0, 10_000_000) ?? 0;
883
+ return { node: readWorkspaceHistory(root, id, offset, limit, childrenOffset, hostFilter) };
884
+ }
712
885
  case "worker_create": {
713
886
  const backend = this.resolveBackend(rawArgs, configuration.acp, false);
714
887
  const model = asString(rawArgs, "model");
@@ -853,7 +1026,7 @@ export async function handleMcpRequest(
853
1026
  protocolVersion: requested || protocolVersion,
854
1027
  capabilities: { tools: {} },
855
1028
  serverInfo: { name: "personal-bot", version: packageVersion },
856
- instructions: mcpInstructions,
1029
+ instructions: runtime.nativeWorkspaceMcp ? mcpWorkerOnlyInstructions : mcpInstructions,
857
1030
  },
858
1031
  };
859
1032
  }
@@ -4,21 +4,21 @@ import { mkdir, readFile, realpath } from "node:fs/promises";
4
4
  import { homedir } from "node:os";
5
5
  import { join } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
- import { executeSetup, packageChoices, parseCatalog, parseSetupArgs } from "../services/installation/setup-service.js";
8
- import { npmName, ordinaryNpm } from "../common/package-source.js";
9
- import type { InstalledPackage, SetupPlan } from "../services/installation/setup-service.js";
10
- import { PiBootstrapRequired, PiSetup, piPackageName } from "../integrations/installation/pi-setup.js";
11
- import { findExecutable, inspectSystem, SetupProcesses } from "../integrations/installation/processes.js";
12
- import { resolveWorkspace } from "../integrations/installation/workspace.js";
13
- import type { WorkspaceMcpServer } from "../model/workspace-mcp.js";
7
+ import { executeSetup, packageChoices, parseCatalog, parseSetupArgs } from "../../services/installation/setup-service.js";
8
+ import { npmName, ordinaryNpm } from "../../common/package-source.js";
9
+ import type { InstalledPackage, SetupPlan } from "../../services/installation/setup-service.js";
10
+ import { PiBootstrapRequired, PiSetup, piPackageName } from "../../integrations/installation/pi-setup.js";
11
+ import { findExecutable, inspectSystem, SetupProcesses } from "../../integrations/installation/processes.js";
12
+ import { resolveWorkspace } from "../../integrations/installation/workspace.js";
13
+ import type { WorkspaceMcpServer } from "../../model/workspace-mcp.js";
14
14
  import {
15
15
  readWorkspaceMcpConfig,
16
16
  removeWorkspaceMcpServer,
17
17
  upsertWorkspaceMcpServer,
18
- } from "../services/workspace/workspace-mcp.js";
19
- import { SetupUI } from "../ui/setup.js";
18
+ } from "../../services/workspace/workspace-mcp.js";
19
+ import { SetupUI } from "../../ui/setup.js";
20
20
 
21
- const root = new URL("../../", import.meta.url);
21
+ const root = new URL("../../../", import.meta.url);
22
22
  const quote = (value: string) => "'" + value.replaceAll("'", "'\\''") + "'";
23
23
 
24
24
  const mcpManageUsage =
@@ -281,7 +281,7 @@ export async function main(args: string[]): Promise<number> {
281
281
  await host.start(result.pi, workspace);
282
282
  } else {
283
283
  ui.text("稍后执行:\ncd " + quote(workspace) + "\n" + quote(result.pi.command) + " --extension " +
284
- quote(fileURLToPath(new URL("extension/setup-guard.js", new URL("../", import.meta.url)))) + " '/pbot init'");
284
+ quote(fileURLToPath(new URL("extension/setup/guard.js", new URL("../../", import.meta.url)))) + " '/pbot init'");
285
285
  }
286
286
  return failed ? 1 : 0;
287
287
  } catch (error) {