personal-bot 0.3.6 → 0.4.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 (143) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +5 -8
  4. package/README.zh-CN.md +5 -8
  5. package/bin/pbot-pi-acp.mjs +1 -1
  6. package/docs/README.md +1 -1
  7. package/docs/architecture/design.md +2 -2
  8. package/docs/architecture/extensibility.md +1 -1
  9. package/docs/architecture/model-context.md +1 -2
  10. package/docs/guides/capabilities.md +4 -8
  11. package/docs/guides/cross-harness-workers.md +4 -4
  12. package/docs/guides/history.md +1 -3
  13. package/docs/guides/workspace-configuration.md +4 -4
  14. package/docs/hosts/claude-code.md +2 -2
  15. package/docs/hosts/codex-qoder.md +1 -1
  16. package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +1 -1
  17. package/lib/antigravity-plugin/lib/extension/acp/member.d.ts +1 -1
  18. package/lib/antigravity-plugin/lib/extension/acp/member.js +11 -10
  19. package/lib/antigravity-plugin/lib/extension/acp-worker.js +348 -203
  20. package/lib/antigravity-plugin/lib/extension/cli.js +574 -549
  21. package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.js +1 -1
  22. package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +3 -4
  23. package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +0 -11
  24. package/lib/antigravity-plugin/lib/extension/mcp.js +462 -326
  25. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +2 -2
  26. package/lib/antigravity-plugin/lib/model/acp.d.ts +29 -35
  27. package/lib/antigravity-plugin/lib/model/agent.d.ts +33 -17
  28. package/lib/antigravity-plugin/lib/model/agent.js +0 -1
  29. package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +5 -8
  30. package/lib/antigravity-plugin/lib/storage/acp-files.js +34 -40
  31. package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +19 -10
  32. package/lib/antigravity-plugin/lib/storage/agent-files.js +147 -43
  33. package/lib/antigravity-plugin/package.json +1 -1
  34. package/lib/antigravity-plugin/plugin.json +1 -1
  35. package/lib/antigravity-plugin/resources/agents/coordinator.md +3 -7
  36. package/lib/antigravity-plugin/resources/agents/general-purpose.md +3 -3
  37. package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -2
  38. package/lib/antigravity-plugin/resources/prompts/workspace.md +12 -16
  39. package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +7 -6
  40. package/lib/antigravity-plugin/resources/templates/workspace-agents.md +0 -4
  41. package/lib/antigravity-plugin/skills/pbot/SKILL.md +14 -6
  42. package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +7 -6
  43. package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +1 -1
  44. package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +2 -2
  45. package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +3 -3
  46. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +2 -2
  47. package/lib/extension/acp/member.d.ts +1 -1
  48. package/lib/extension/acp/member.js +11 -10
  49. package/lib/extension/acp/worker.js +34 -33
  50. package/lib/extension/acp-worker.js +348 -203
  51. package/lib/extension/cli.js +574 -549
  52. package/lib/extension/hosts/dsh/acp-member.js +1 -1
  53. package/lib/extension/hosts/dsh/command.js +1 -1
  54. package/lib/extension/hosts/dsh/workspace.js +1 -3
  55. package/lib/extension/hosts/pi/acp-member.js +3 -4
  56. package/lib/extension/hosts/plugin-runtime.js +0 -11
  57. package/lib/extension/mcp/tool-contract.d.ts +8 -50
  58. package/lib/extension/mcp/tool-contract.js +48 -62
  59. package/lib/extension/mcp/workers.d.ts +13 -27
  60. package/lib/extension/mcp/workers.js +60 -25
  61. package/lib/extension/mcp.js +462 -326
  62. package/lib/integrations/acp/agents.d.ts +2 -3
  63. package/lib/integrations/acp/agents.js +22 -22
  64. package/lib/integrations/acp/harnesses/claude.js +1 -1
  65. package/lib/integrations/agent-resources.js +2 -2
  66. package/lib/model/acp.d.ts +29 -35
  67. package/lib/model/agent.d.ts +33 -17
  68. package/lib/model/agent.js +0 -1
  69. package/lib/qoder-plugin/.mcp.json +2 -2
  70. package/lib/qoder-plugin/.qoder-plugin/plugin.json +1 -1
  71. package/lib/qoder-plugin/hooks/hooks.json +3 -3
  72. package/lib/qoder-plugin/skills/pbot/SKILL.md +2 -2
  73. package/lib/services/agents/acp-run.d.ts +6 -4
  74. package/lib/services/agents/acp-run.js +62 -43
  75. package/lib/services/agents/agent-run.d.ts +10 -6
  76. package/lib/services/agents/agent-run.js +142 -65
  77. package/lib/services/agents/agent-service.d.ts +3 -21
  78. package/lib/services/agents/agent-service.js +180 -126
  79. package/lib/storage/acp-files.d.ts +5 -8
  80. package/lib/storage/acp-files.js +34 -40
  81. package/lib/storage/agent-files.d.ts +19 -10
  82. package/lib/storage/agent-files.js +147 -43
  83. package/lib/tools/history/contract.js +12 -12
  84. package/package.json +1 -1
  85. package/resources/agents/coordinator.md +3 -7
  86. package/resources/agents/general-purpose.md +3 -3
  87. package/resources/antigravity/skills/pbot/SKILL.md +14 -6
  88. package/resources/claude/skills/pbot/SKILL.md +14 -6
  89. package/resources/plugin/skills/pbot/SKILL.md +2 -2
  90. package/resources/prompts/history-coordinator.md +1 -2
  91. package/resources/prompts/plugin-coordinator.md +1 -2
  92. package/resources/prompts/workspace.md +12 -16
  93. package/resources/skills/provider-connections/SKILL.md +7 -6
  94. package/resources/templates/workspace-agents.md +0 -4
  95. package/src/extension/acp/member.ts +14 -11
  96. package/src/extension/acp/worker.ts +31 -28
  97. package/src/extension/cli/commands/upgrade.ts +8 -36
  98. package/src/extension/cli/commands/workspace.ts +3 -8
  99. package/src/extension/cli/index.ts +1 -2
  100. package/src/extension/hosts/dsh/acp-member.ts +1 -1
  101. package/src/extension/hosts/dsh/command.ts +1 -1
  102. package/src/extension/hosts/dsh/workspace.ts +1 -3
  103. package/src/extension/hosts/pi/acp-member.ts +3 -4
  104. package/src/extension/hosts/pi/command.ts +1 -1
  105. package/src/extension/hosts/pi/lifecycle.ts +0 -2
  106. package/src/extension/hosts/plugin-runtime.ts +0 -10
  107. package/src/extension/mcp/tool-contract.ts +48 -62
  108. package/src/extension/mcp/workers.ts +66 -27
  109. package/src/integrations/acp/agents.ts +28 -27
  110. package/src/integrations/acp/harnesses/claude.ts +1 -1
  111. package/src/integrations/agent-resources.ts +2 -2
  112. package/src/integrations/hosts/dsh/session.ts +2 -2
  113. package/src/integrations/installation/cli-update.ts +2 -2
  114. package/src/integrations/installation/installers/claude.ts +4 -4
  115. package/src/integrations/installation/installers/qoder.ts +5 -5
  116. package/src/integrations/installation/upgraders/antigravity.ts +57 -15
  117. package/src/integrations/installation/upgraders/claude.ts +1 -4
  118. package/src/integrations/installation/upgraders/codex.ts +85 -15
  119. package/src/integrations/installation/upgraders/dsh.ts +46 -24
  120. package/src/integrations/installation/upgraders/pi.ts +18 -11
  121. package/src/integrations/installation/upgraders/qoder.ts +95 -20
  122. package/src/model/acp.ts +27 -29
  123. package/src/model/agent.ts +80 -16
  124. package/src/model/installation.ts +0 -2
  125. package/src/pbot.ts +2 -2
  126. package/src/services/agents/acp-run.ts +81 -49
  127. package/src/services/agents/agent-run.ts +154 -56
  128. package/src/services/agents/agent-service.ts +204 -133
  129. package/src/services/installation/upgrade-service.ts +1 -5
  130. package/src/storage/acp-files.ts +50 -45
  131. package/src/storage/agent-files.ts +159 -46
  132. package/src/tools/history/contract.ts +12 -12
  133. package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +0 -15
  134. package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +0 -126
  135. package/lib/antigravity-plugin/resources/references/compute-finance.md +0 -22
  136. package/lib/antigravity-plugin/resources/references/compute.md +0 -16
  137. package/lib/antigravity-plugin/resources/references/task-conductor.md +0 -25
  138. package/lib/services/workspace/plugin-releases.d.ts +0 -15
  139. package/lib/services/workspace/plugin-releases.js +0 -126
  140. package/resources/references/compute-finance.md +0 -22
  141. package/resources/references/compute.md +0 -16
  142. package/resources/references/task-conductor.md +0 -25
  143. package/src/services/workspace/plugin-releases.ts +0 -121
@@ -11,7 +11,7 @@ export const discoverTargets = ["overview", "workers", "backends", "models"] as
11
11
  function formatBackendItem(entry: ReturnType<typeof inspectAcpBackends>[number], defaultBackend?: string): string {
12
12
  const tags: string[] = [];
13
13
  if (entry.label) tags.push(entry.label);
14
- if (entry.backend === defaultBackend) tags.push("当前");
14
+ if (entry.backend === defaultBackend) tags.push("当前宿主");
15
15
  return tags.length ? `${entry.backend}(${tags.join(",")})` : entry.backend;
16
16
  }
17
17
 
@@ -34,8 +34,8 @@ function workspaceProperty(workspaceBound: boolean) {
34
34
  return {
35
35
  type: "string",
36
36
  description: workspaceBound
37
- ? "目标工作区根目录的绝对路径;默认使用当前工作区,通常省略。"
38
- : "目标工作区根目录的绝对路径(如上下文中提供了 workspaceRoot 则传该路径);请显式传入。",
37
+ ? "工作区根目录绝对路径;默认当前工作区,通常省略。"
38
+ : "目标工作区根目录绝对路径;请传入环境中的 workspaceRoot。",
39
39
  };
40
40
  }
41
41
 
@@ -50,8 +50,7 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
50
50
  {
51
51
  name: "worker_create" as const,
52
52
  description:
53
- "启动一个独立的外部 AI 助手会话(worker),用于将任务委派给其他助手或指定模型/思考深度来独立处理(如按用户要求切换助手、获取独立审查或第二意见、并行分担子任务)。" +
54
- "本工具仅建立会话并返回 workerId,随后通过 worker_request 发送具体任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。\n" +
53
+ "启动独立的外部助手会话并返回 workerId(不发送任务,随后用 worker_request 派发)。未指定其他助手或特定模型时,优先自行完成或使用当前内置子代理。\n" +
55
54
  overview,
56
55
  annotations: {
57
56
  title: "Create Worker",
@@ -67,19 +66,15 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
67
66
  properties: {
68
67
  backend: {
69
68
  type: "string",
70
- description: "要启动的外部助手标识(不区分大小写,支持常见别名,如 claude-code、agy)。",
69
+ description: "目标外部助手标识(不区分大小写,支持常见别名如 claude-code、agy)。",
71
70
  },
72
71
  model: {
73
72
  type: "string",
74
- description: "仅用户明确要求特定模型时指定(支持模型 ID、显示名或 provider/model,不区分大小写);不确定可用值时先用 worker_discover(target=\"models\") 查询;不填则使用该助手默认模型。",
73
+ description: "目标模型(模型 ID、显示名或 provider/model,不区分大小写);未明确指定时省略以用默认模型,不确定可选值时先查 worker_discover(target=\"models\")。",
75
74
  },
76
75
  thinking: {
77
76
  type: "string",
78
- description: "仅用户明确要求思考深度时指定(如 low / medium / high / xhigh / max,不区分大小写);不填则使用默认设置。",
79
- },
80
- cwd: {
81
- type: "string",
82
- description: "助手执行任务时的工作目录(绝对路径或相对工作区的路径),默认为当前工作区根目录。",
77
+ description: "思考深度(如 low / medium / high / xhigh / max,不区分大小写);未明确指定时省略以用默认设置。",
83
78
  },
84
79
  workspace,
85
80
  },
@@ -88,7 +83,7 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
88
83
  {
89
84
  name: "worker_close" as const,
90
85
  description:
91
- "结束不再需要的外部助手会话并释放资源。若该助手支持会话恢复,后续仍可直接用 worker_request 在原上下文中继续对话。",
86
+ "结束外部助手会话并释放进程。若该会话支持恢复(capabilities.resume),后续仍可直接用 worker_request 续接。",
92
87
  annotations: {
93
88
  title: "Close Worker",
94
89
  readOnlyHint: false,
@@ -103,18 +98,16 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
103
98
  properties: {
104
99
  workerId: {
105
100
  type: "string",
106
- description: "要结束的助手会话 ID(来自 worker_create 或 worker_discover)。",
101
+ description: "助手会话 ID(来自 worker_create 或 worker_discover)。",
107
102
  },
108
- workspace,
109
103
  },
110
104
  },
111
105
  },
112
106
  {
113
107
  name: "worker_request" as const,
114
108
  description:
115
- "向指定的外部助手派发任务,或在同一上下文中追问与补充要求,并获取执行结果(已关闭但支持恢复的会话会自动续接)。" +
116
- `默认最多等待 ${defaultWaitMs / 1000} 秒返回结果;将 waitMs 设为 0 可立即返回并转入后台执行,适合耗时任务或多助手并行。` +
117
- "若返回 timedOut 或结果含 nextOffset,用 worker_output 继续等待或翻页;若返回 needsResponse,先向用户确认再用 worker_response 回复。",
109
+ "向外部助手派发任务或在同一上下文中追问(已关闭且支持恢复的会话会自动续接)。" +
110
+ `默认最多等待 ${defaultWaitMs / 1000} 秒(waitMs 设为 0 可立即转后台并行);返回 timedOut 或 nextOffset 用 worker_output,返回 needsResponse 先向用户确认再用 worker_response。`,
118
111
  annotations: {
119
112
  title: "Send Request to Worker",
120
113
  readOnlyHint: false,
@@ -129,28 +122,26 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
129
122
  properties: {
130
123
  workerId: {
131
124
  type: "string",
132
- description: "目标助手会话 ID(来自 worker_create 或 worker_discover)。",
125
+ description: "助手会话 ID(来自 worker_create 或 worker_discover)。",
133
126
  },
134
127
  message: {
135
128
  type: "string",
136
- description: "要发送的任务说明或追问内容。外部助手看不到你与用户的对话历史,首次派发时请写清背景、目标、相关文件路径、约束条件和期望产出。",
129
+ description: "任务说明或追问内容。外部助手看不到当前会话历史,首次派发需写清背景、目标、相关文件路径、约束和期望产出。",
137
130
  },
138
131
  waitMs: {
139
132
  type: "integer",
140
133
  minimum: 0,
141
134
  maximum: maxWaitMs,
142
- description: `最多等待结果的毫秒数(默认 ${defaultWaitMs});设为 0 可立即返回并在后台执行。`,
135
+ description: `最多等待毫秒数(默认 ${defaultWaitMs});0 表示立即返回转后台执行。`,
143
136
  },
144
- workspace,
145
137
  },
146
138
  },
147
139
  },
148
140
  {
149
141
  name: "worker_response" as const,
150
142
  description:
151
- "当外部助手在执行过程中暂停并请求确认或补充信息(返回 needsResponse: true)时,向其提交决定以继续执行。" +
152
- "支持三类请求:操作授权(kind=\"permission\")、问答表单(kind=\"form\")和链接确认(kind=\"url\")。" +
153
- `提交前先向用户确认;提交后默认最多等待 ${defaultWaitMs / 1000} 秒返回后续结果(waitMs 设为 0 立即返回)。`,
143
+ "回复外部助手暂停时发出的待处理请求(needsResponse: true),支持操作授权、表单问答与链接确认。" +
144
+ `提交前先向用户确认;提交后默认等待最多 ${defaultWaitMs / 1000} 秒返回后续结果。`,
154
145
  annotations: {
155
146
  title: "Respond to Worker Request",
156
147
  readOnlyHint: false,
@@ -170,36 +161,34 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
170
161
  action: {
171
162
  type: "string",
172
163
  enum: [...acpElicitationActions],
173
- description: "处理方式:accept 表示同意授权、提交表单回答或确认链接;decline 表示拒绝;cancel 表示取消本次请求。",
164
+ description: "accept 同意/提交表单/确认链接;decline 拒绝;cancel 取消请求。",
174
165
  },
175
166
  requestId: {
176
167
  type: "string",
177
- description: "要回复的请求 ID(来自 pendingRequests[].requestId);仅一条待处理请求时可省略,多条时必填。",
168
+ description: "请求 ID(pendingRequests[].requestId);仅一条待处理请求时可省略,多条时必填。",
178
169
  },
179
170
  optionId: {
180
171
  type: "string",
181
- description: "仅授权请求(kind=\"permission\")且 action 不为 cancel 时可用:指定选项 ID(来自 pendingRequests[].options[].optionId),省略时默认单次允许或拒绝。",
172
+ description: "仅 permission 请求且 action≠cancel 时可用:指定 pendingRequests[].options[].optionId,省略则按 action 单次允许或拒绝。",
182
173
  },
183
174
  content: {
184
175
  type: "object",
185
176
  additionalProperties: true,
186
- description: "仅表单提问(kind=\"form\")且 action=\"accept\" 时可用:按 pendingRequests[].schema.properties 填写的回答对象(值为字符串、数字、布尔值或字符串数组)。",
177
+ description: "仅 form 请求且 action=\"accept\" 时可用:按 pendingRequests[].schema.properties 填写回答对象(值为字符串、数字、布尔值或字符串数组)。",
187
178
  },
188
179
  waitMs: {
189
180
  type: "integer",
190
181
  minimum: 0,
191
182
  maximum: maxWaitMs,
192
- description: `提交回复后最多等待后续结果的毫秒数(默认 ${defaultWaitMs});设为 0 立即返回。`,
183
+ description: `提交后最多等待毫秒数(默认 ${defaultWaitMs});0 表示立即返回。`,
193
184
  },
194
- workspace,
195
185
  },
196
186
  },
197
187
  },
198
188
  {
199
189
  name: "worker_output" as const,
200
190
  description:
201
- "获取或等待外部助手的最新执行结果。用于收取后台任务的产出、在等待超时(timedOut)后继续等待,或在长结果分页(含 nextOffset)时读取后续内容。" +
202
- "任务仍在运行时会等待其完成(也可能返回 timedOut 或 needsResponse),已结束则立即返回。",
191
+ "获取或等待外部助手的最新结果,用于收取后台产出、timedOut 后继续等待,或按 nextOffset 分页续读。任务已结束时立即返回,运行中最多等待 waitMs。",
203
192
  annotations: {
204
193
  title: "Get Worker Output",
205
194
  readOnlyHint: true,
@@ -214,28 +203,26 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
214
203
  properties: {
215
204
  workerId: {
216
205
  type: "string",
217
- description: "要等待或获取结果的助手会话 ID。",
206
+ description: "助手会话 ID。",
218
207
  },
219
208
  offset: {
220
209
  type: "integer",
221
210
  minimum: 0,
222
- description: "结果读取起始位置(默认 0);翻页读取剩余内容时传入上次返回的 nextOffset。",
211
+ description: "读取起始位置(默认 0);翻页续读时传上次返回的 nextOffset。",
223
212
  },
224
213
  waitMs: {
225
214
  type: "integer",
226
215
  minimum: 0,
227
216
  maximum: maxWaitMs,
228
- description: `任务仍在运行时最多等待的毫秒数(默认 ${defaultWaitMs});任务已结束或翻页读取时会立即返回。`,
217
+ description: `运行中最多等待毫秒数(默认 ${defaultWaitMs});已结束或翻页时立即返回。`,
229
218
  },
230
- workspace,
231
219
  },
232
220
  },
233
221
  },
234
222
  {
235
223
  name: "worker_discover" as const,
236
224
  description:
237
- "了解当前可以委派哪些外部助手、查看已有助手会话的运行状态以便复用,或查询某个助手支持的模型与思考深度选项。" +
238
- "默认(target=\"overview\")同时返回可用助手与已有会话;仅在需要核对模型或思考深度可选值时再查 target=\"models\"(耗时较长)。",
225
+ "查询可用外部助手、已有会话状态,或某个助手支持的模型与思考深度。默认(overview)返回可用助手与已有会话;仅需核对模型或思考深度可选值时再查 models(需启动探测,耗时较长)。",
239
226
  annotations: {
240
227
  title: "Discover Workers, Backends & Models",
241
228
  readOnlyHint: true,
@@ -251,21 +238,21 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
251
238
  target: {
252
239
  type: "string",
253
240
  enum: [...discoverTargets],
254
- description: "查询范围,默认 \"overview\"(同时返回可用助手与已有会话);\"workers\" 查全部或单个会话状态;\"backends\" 查可用助手列表;\"models\" 查指定助手支持的模型与思考深度。",
241
+ description: "overview(默认,可用助手与已有会话)、workers(全部或单个会话状态)、backends(可用助手)、models(指定助手的模型与思考深度)。",
255
242
  },
256
243
  workerId: {
257
244
  type: "string",
258
- description: "仅 target=\"workers\" 可用:指定单个助手会话 ID;不填则列出全部。",
245
+ description: "仅 target=\"workers\" 可用:指定单个会话 ID,省略列全部。",
259
246
  },
260
247
  backend: {
261
248
  type: "string",
262
249
  description: availableIds
263
- ? `仅 target="models" 可用(${modelsBackendHint}):目标外部助手标识,支持常见别名;当前可用:${availableIds}。`
264
- : `仅 target="models" 可用(${modelsBackendHint}):目标外部助手标识,支持常见别名。`,
250
+ ? `仅 target="models" 可用(${modelsBackendHint}):目标助手标识,支持别名;当前可用:${availableIds}。`
251
+ : `仅 target="models" 可用(${modelsBackendHint}):目标助手标识,支持别名。`,
265
252
  },
266
253
  model: {
267
254
  type: "string",
268
- description: "仅 target=\"models\" 可用:指定模型以查看该模型支持的思考深度选项。",
255
+ description: "仅 target=\"models\" 可用:指定模型以查看其支持的思考深度选项。",
269
256
  },
270
257
  workspace,
271
258
  },
@@ -280,7 +267,7 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
280
267
  {
281
268
  name: "workspace_mcp_discover" as const,
282
269
  description:
283
- "发现当前工作区共享的外部工具服务(MCP)及其可用工具。不传 server 时列出可用服务;传入 server 时返回该服务提供的工具清单与参数说明。",
270
+ "查询当前工作区共享 MCP 服务(.pbot/mcp.json)。省略 server 列出服务;传入 server 返回其工具列表与参数说明。",
284
271
  annotations: {
285
272
  title: "Discover Workspace MCP Servers & Tools",
286
273
  readOnlyHint: true,
@@ -295,7 +282,7 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
295
282
  properties: {
296
283
  server: {
297
284
  type: "string",
298
- description: "目标工具服务名称;不填时列出工作区全部可用服务。",
285
+ description: "服务名称;省略列出工作区全部已配置服务。",
299
286
  },
300
287
  workspace,
301
288
  },
@@ -304,8 +291,7 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
304
291
  {
305
292
  name: "workspace_mcp_call" as const,
306
293
  description:
307
- "调用当前工作区共享的外部工具服务(MCP)中的指定工具,用于访问工作区接入的外部能力与数据源。" +
308
- "不确定工具名或参数格式时,先用 workspace_mcp_discover(server) 查询。",
294
+ "调用工作区共享 MCP 服务中的指定工具。不确定工具名或参数时先用 workspace_mcp_discover(server) 查询。",
309
295
  annotations: {
310
296
  title: "Call Workspace MCP Tool",
311
297
  readOnlyHint: false,
@@ -320,16 +306,16 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
320
306
  properties: {
321
307
  server: {
322
308
  type: "string",
323
- description: "目标工具服务名称(可通过 workspace_mcp_discover 获取)。",
309
+ description: "服务名称(来自 workspace_mcp_discover)。",
324
310
  },
325
311
  tool: {
326
312
  type: "string",
327
- description: "要调用的工具名称。",
313
+ description: "工具名称。",
328
314
  },
329
315
  arguments: {
330
316
  type: "object",
331
317
  additionalProperties: true,
332
- description: "传给目标工具的参数对象,不填则为空对象。",
318
+ description: "传给目标工具的参数对象,默认空对象。",
333
319
  },
334
320
  workspace,
335
321
  },
@@ -344,7 +330,7 @@ export function buildHistoryMcpTools(workspaceBound = false) {
344
330
  {
345
331
  name: "history_search" as const,
346
332
  description:
347
- "搜索当前工作区跨宿主(pi、dsh、claude、antigravity 等)的历史问答与摘要归档。省略 query 时列出各会话;传入 query 按不区分大小写的连续关键词匹配原文与摘要。",
333
+ "搜索当前工作区跨宿主历史问答与摘要归档(不含工具调用日志)。省略 query 列出各会话或指定维度摘要;传入 query 按不区分大小写的连续关键词匹配。",
348
334
  annotations: {
349
335
  title: "Search Workspace History",
350
336
  readOnlyHint: true,
@@ -359,15 +345,15 @@ export function buildHistoryMcpTools(workspaceBound = false) {
359
345
  properties: {
360
346
  host: {
361
347
  type: "string",
362
- description: "可选来源筛选(如 pi、dsh、claude、antigravity);省略查全部宿主。",
348
+ description: "来源宿主筛选(如 pi、dsh、claude、antigravity、codex、qoder);省略查全部。",
363
349
  },
364
350
  dimension: {
365
351
  type: "string",
366
- description: "可选范围筛选:raw 表示仅搜原文,或指定摘要维度(如 monthly、session);省略查全部原文与维度摘要。",
352
+ description: "范围筛选:raw 仅原文,或指定摘要维度(如 monthly、session);省略查全部。",
367
353
  },
368
354
  query: {
369
355
  type: "string",
370
- description: "不区分大小写的连续关键词;省略时列出各会话(或指定维度摘要)。",
356
+ description: "连续关键词(不区分大小写);省略列会话或指定维度摘要。",
371
357
  },
372
358
  sessionId: {
373
359
  type: "string",
@@ -384,13 +370,13 @@ export function buildHistoryMcpTools(workspaceBound = false) {
384
370
  offset: {
385
371
  type: "integer",
386
372
  minimum: 0,
387
- description: "匹配结果偏移,默认 0。",
373
+ description: "结果偏移,默认 0。",
388
374
  },
389
375
  limit: {
390
376
  type: "integer",
391
377
  minimum: 1,
392
378
  maximum: historyPageLimits.search.max,
393
- description: `最多返回条数(1–${historyPageLimits.search.max}),默认 ${historyPageLimits.search.default}。`,
379
+ description: `返回条数(1–${historyPageLimits.search.max}),默认 ${historyPageLimits.search.default}。`,
394
380
  },
395
381
  workspace,
396
382
  },
@@ -399,7 +385,7 @@ export function buildHistoryMcpTools(workspaceBound = false) {
399
385
  {
400
386
  name: "history_read" as const,
401
387
  description:
402
- "按节点 id 读取当前工作区历史归档的正文与上下级节点(monthly、session、summary、exchange),支持从月度汇总下钻至单会话摘要与原始问答。正文过长时用 nextOffset 续读,子节点过多时用 nextChildrenOffset 续读。",
388
+ "按节点 id 读取历史正文与上下级(可从 monthly 汇总下钻至 session 摘要和 exchange 原文)。正文分页传 nextOffset,子节点分页传 nextChildrenOffset。",
403
389
  annotations: {
404
390
  title: "Read Workspace History Node",
405
391
  readOnlyHint: true,
@@ -414,16 +400,16 @@ export function buildHistoryMcpTools(workspaceBound = false) {
414
400
  properties: {
415
401
  id: {
416
402
  type: "string",
417
- description: "history_search 或上下级返回的节点 id。",
403
+ description: "节点 id(来自 history_search 或上下级)。",
418
404
  },
419
405
  host: {
420
406
  type: "string",
421
- description: "跨来源 ID 冲突时显式指定来源宿主。",
407
+ description: "跨宿主 id 冲突时指定来源宿主。",
422
408
  },
423
409
  offset: {
424
410
  type: "integer",
425
411
  minimum: 0,
426
- description: "正文字符偏移,默认 0。",
412
+ description: "正文字符偏移,默认 0;续读传上次 nextOffset。",
427
413
  },
428
414
  limit: {
429
415
  type: "integer",
@@ -434,7 +420,7 @@ export function buildHistoryMcpTools(workspaceBound = false) {
434
420
  childrenOffset: {
435
421
  type: "integer",
436
422
  minimum: 0,
437
- description: "子节点列表偏移,默认 0;续读传上页 nextChildrenOffset。",
423
+ description: "子节点偏移,默认 0;续读传上次 nextChildrenOffset。",
438
424
  },
439
425
  workspace,
440
426
  },
@@ -1,7 +1,6 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { existsSync } from "node:fs";
3
3
  import { realpath, stat } from "node:fs/promises";
4
- import { homedir } from "node:os";
5
4
  import { isAbsolute, join } from "node:path";
6
5
  import { setTimeout as delay } from "node:timers/promises";
7
6
  import { object } from "../../common/json.js";
@@ -40,20 +39,31 @@ const progressIntervalMs = 5_000;
40
39
 
41
40
  export type ProgressReporter = (message: string) => void;
42
41
 
43
- export const mcpWorkerOnlyInstructions =
44
- "提供跨助手协作能力(worker_*):可启动并调度其他外部 AI 助手在当前工作区中独立执行任务,适用于用户指定其他助手、需要特定模型或思考深度、获取独立审查/第二意见,或并行处理子任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。\n" +
45
- "使用流程:用 worker_create 启动目标助手(或用 worker_discover 复用已有会话)→ 用 worker_request 派发任务或继续追问 → 任务完成后可用 worker_close 结束会话。后台等待、超时续等(timedOut)或长结果翻页(nextOffset)用 worker_output;助手请求授权或提问(needsResponse)时,先向用户确认,再用 worker_response 回复。";
42
+ const workerCapabilityInstruction =
43
+ "跨助手委派(worker_*):启动并调度其他外部助手在当前工作区独立执行任务;无需外部助手时优先自行完成或使用内置子代理。" +
44
+ "流程:worker_create 启动(或 worker_discover 复用)→ worker_request 派发/追问 → 完成后 worker_close;" +
45
+ "后台取结果、超时续等(timedOut)或翻页(nextOffset)用 worker_output;返回 needsResponse 时先向用户确认,再用 worker_response 回复。";
46
46
 
47
- export const mcpInstructions =
48
- "提供三类能力:\n" +
49
- "1. 跨助手协作(worker_*):启动并调度其他外部 AI 助手在当前工作区中独立执行任务,适用于用户指定其他助手、需要特定模型或思考深度、获取独立审查/第二意见,或并行处理子任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。使用流程:worker_create 启动助手(或 worker_discover 复用已有会话)→ worker_request 派发任务或追问 → 完成后 worker_close 结束;后台等待、超时续等(timedOut)或长结果翻页(nextOffset)用 worker_output;返回 needsResponse 时先向用户确认,再用 worker_response 回复。\n" +
50
- "2. 工作区共享外部工具(workspace_mcp_*):发现并调用当前工作区接入的外部工具服务与数据源(可与当前环境原生工具同时使用)。先用 workspace_mcp_discover 查看可用服务与工具说明,再用 workspace_mcp_call 调用。\n" +
51
- "3. 跨宿主历史查询(history_search / history_read):只读检索当前工作区在 Pi、dsh、Claude Code、Antigravity 等宿主中记录的历史问答与摘要归档。";
47
+ const workspaceMcpCapabilityInstruction =
48
+ "工作区共享 MCP(workspace_mcp_*):先用 workspace_mcp_discover 查 .pbot/mcp.json 中的服务与工具,再用 workspace_mcp_call 调用。";
52
49
 
53
- export function defaultWorkerDirectory(): string {
50
+ const historyCapabilityInstruction =
51
+ "跨宿主历史(history_search / history_read):只读检索当前工作区跨宿主记录的历史问答与摘要归档。";
52
+
53
+ export function buildMcpInstructions(options: { workspaceMcp: boolean; history: boolean }): string {
54
+ const parts = [workerCapabilityInstruction];
55
+ if (options.workspaceMcp) parts.push(workspaceMcpCapabilityInstruction);
56
+ if (options.history) parts.push(historyCapabilityInstruction);
57
+ return parts.length === 1 ? parts[0]! : parts.map((text, index) => `${index + 1}. ${text}`).join("\n");
58
+ }
59
+
60
+ export const mcpWorkerOnlyInstructions = buildMcpInstructions({ workspaceMcp: false, history: false });
61
+
62
+ export const mcpInstructions = buildMcpInstructions({ workspaceMcp: true, history: true });
63
+
64
+ export function defaultWorkerDirectory(workspaceRoot: string): string {
54
65
  if (process.env.PBOT_MCP_AGENT_DIR) return process.env.PBOT_MCP_AGENT_DIR;
55
- if (process.env.PLUGIN_DATA) return join(process.env.PLUGIN_DATA, "subagents");
56
- return join(homedir(), ".pbot/subagents");
66
+ return join(workspaceRoot, ".pbot", "subagents");
57
67
  }
58
68
 
59
69
  function workerCommandTool(name: string): McpWorkerToolName | undefined {
@@ -171,16 +181,17 @@ function presentWorker(value: AgentView & {
171
181
 
172
182
  export class McpWorkerRuntime {
173
183
  readonly #services = new Map<string, { service: AgentService; host: AcpWorkerHost; owner: AgentOwner }>();
184
+ readonly #workerWorkspaces = new Map<string, string>();
174
185
  readonly #bridge = new WorkspaceMcpBridge();
175
186
  readonly #sessionId: string;
176
- readonly #directory: string;
187
+ readonly #directory: string | undefined;
177
188
  readonly #defaultBackend: string | undefined;
178
189
  readonly #nativeWorkspaceMcp: boolean;
179
190
  readonly #nativeHistory: boolean;
180
191
  #closing: Promise<void> | undefined;
181
192
 
182
193
  constructor(
183
- directory = defaultWorkerDirectory(),
194
+ directory?: string,
184
195
  sessionId = process.env.PBOT_MCP_SESSION_ID || ("mcp-" + randomUUID()),
185
196
  defaultBackend = process.env.PBOT_HOST || undefined,
186
197
  nativeWorkspaceMcp = /^(1|true)$/i.test(process.env.PBOT_NATIVE_WORKSPACE_MCP ?? ""),
@@ -204,7 +215,7 @@ export class McpWorkerRuntime {
204
215
  env: {
205
216
  PBOT_HOST: this.#defaultBackend,
206
217
  PBOT_WORKSPACE_ROOT: root,
207
- PBOT_MCP_AGENT_DIR: this.#directory,
218
+ PBOT_MCP_AGENT_DIR: this.#directory ?? defaultWorkerDirectory(root),
208
219
  PBOT_MCP_SESSION_ID: this.#sessionId,
209
220
  PBOT_NATIVE_WORKSPACE_MCP: "1",
210
221
  PBOT_NATIVE_HISTORY: "1",
@@ -236,13 +247,26 @@ export class McpWorkerRuntime {
236
247
  return root;
237
248
  }
238
249
 
250
+ private async resolveWorkerWorkspace(workerId: string, defaultWorkspace?: string): Promise<string> {
251
+ const known = this.#workerWorkspaces.get(workerId);
252
+ if (known) return known;
253
+ for (const [root, entry] of this.#services) {
254
+ if (entry.service.has(workerId, entry.owner)) {
255
+ this.#workerWorkspaces.set(workerId, root);
256
+ return root;
257
+ }
258
+ }
259
+ return this.resolveWorkspace(defaultWorkspace);
260
+ }
261
+
239
262
  private workerService(root: string, commands: AcpCommands = {}) {
240
263
  let entry = this.#services.get(root);
241
264
  if (!entry) {
242
- const host = new AcpWorkerHost(this.#directory, commands);
265
+ const directory = this.#directory ?? defaultWorkerDirectory(root);
266
+ const host = new AcpWorkerHost(directory, commands);
243
267
  entry = {
244
268
  host,
245
- service: new AgentService(root, this.#directory, host),
269
+ service: new AgentService(root, directory, host),
246
270
  owner: { sessionId: this.#sessionId, leaf: null, branch: [] },
247
271
  };
248
272
  this.#services.set(root, entry);
@@ -252,7 +276,7 @@ export class McpWorkerRuntime {
252
276
  return entry;
253
277
  }
254
278
 
255
- async toolDefinitions() {
279
+ private async resolveToolContext() {
256
280
  let commands: AcpCommands | undefined;
257
281
  let includeWorkspaceMcp = !this.#nativeWorkspaceMcp;
258
282
  let includeHistory = !this.#nativeHistory;
@@ -266,6 +290,16 @@ export class McpWorkerRuntime {
266
290
  includeHistory = !this.#nativeHistory && features.history;
267
291
  }
268
292
  } catch { /* Fall back to registered built-in harnesses when cwd is outside an enabled workspace. */ }
293
+ return { commands, includeWorkspaceMcp, includeHistory };
294
+ }
295
+
296
+ async serverInstructions(): Promise<string> {
297
+ const { includeWorkspaceMcp, includeHistory } = await this.resolveToolContext();
298
+ return buildMcpInstructions({ workspaceMcp: includeWorkspaceMcp, history: includeHistory });
299
+ }
300
+
301
+ async toolDefinitions() {
302
+ const { commands, includeWorkspaceMcp, includeHistory } = await this.resolveToolContext();
269
303
  const defaultBackend = this.#defaultBackend ? canonicalAcpBackend(this.#defaultBackend, commands) : undefined;
270
304
  const workspaceBound = Boolean(pluginMcpWorkspaceRoot());
271
305
  return [
@@ -353,10 +387,13 @@ export class McpWorkerRuntime {
353
387
  }
354
388
  }
355
389
 
356
- async callTool(toolName: string, input: unknown, progress?: ProgressReporter): Promise<unknown> {
390
+ async callTool(toolName: string, input: unknown, progress?: ProgressReporter, defaultWorkspace?: string): Promise<unknown> {
357
391
  const { name, args: rawArgs } = parseMcpToolCall(toolName, input);
358
392
  requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
359
- const root = await this.resolveWorkspace(asString(rawArgs, "workspace"));
393
+ const isWorkerScoped = name === "worker_close" || name === "worker_request" || name === "worker_response" || name === "worker_output";
394
+ const root = isWorkerScoped
395
+ ? await this.resolveWorkerWorkspace(asString(rawArgs, "workerId", true)!, defaultWorkspace)
396
+ : await this.resolveWorkspace(asString(rawArgs, "workspace") ?? defaultWorkspace);
360
397
  const configuration = await readWorkspaceConfig(root);
361
398
  requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
362
399
  requireThat(configuration.enabled, workspaceDisabledMessage(configuration));
@@ -416,13 +453,12 @@ export class McpWorkerRuntime {
416
453
  const backend = this.resolveBackend(rawArgs, configuration.acp, false);
417
454
  const model = asString(rawArgs, "model");
418
455
  const thinking = asString(rawArgs, "thinking");
419
- const cwd = asString(rawArgs, "cwd");
420
456
  const created = await service.start({
421
457
  backend,
422
458
  ...(model ? { model } : {}),
423
459
  ...(thinking ? { thinking } : {}),
424
- ...(cwd ? { cwd } : {}),
425
460
  }, owner);
461
+ this.#workerWorkspaces.set(created.agentId, root);
426
462
  const ready = await this.waitReady(service, owner, created.agentId, readyTimeoutMs, progress);
427
463
  return {
428
464
  ...presentWorker(ready),
@@ -493,21 +529,23 @@ export class McpWorkerRuntime {
493
529
  requireThat(backendRaw === undefined && model === undefined, '参数 backend / model 仅在 target="models" 时可用。');
494
530
  }
495
531
  if (target === "overview") {
532
+ const workers = service.list(owner);
533
+ for (const item of workers) this.#workerWorkspaces.set(item.agentId, root);
496
534
  return {
497
535
  target,
498
536
  backends: inspectAcpBackends(configuration.acp),
499
- workers: service.list(owner).map(presentWorker),
537
+ workers: workers.map(presentWorker),
500
538
  };
501
539
  }
502
540
  if (target === "backends") {
503
541
  return { target, backends: inspectAcpBackends(configuration.acp) };
504
542
  }
505
543
  if (target === "workers") {
544
+ const workers = workerId ? [service.status(workerId, owner)] : service.list(owner);
545
+ for (const item of workers) this.#workerWorkspaces.set(item.agentId, root);
506
546
  return {
507
547
  target,
508
- workers: workerId
509
- ? [presentWorker(service.status(workerId, owner))]
510
- : service.list(owner).map(presentWorker),
548
+ workers: workers.map(presentWorker),
511
549
  };
512
550
  }
513
551
  const backend = this.resolveBackend(rawArgs, configuration.acp, true);
@@ -524,6 +562,7 @@ export class McpWorkerRuntime {
524
562
  if (this.#closing) return this.#closing;
525
563
  const entries = [...this.#services.values()];
526
564
  this.#services.clear();
565
+ this.#workerWorkspaces.clear();
527
566
  this.#closing = Promise.allSettled([
528
567
  this.#bridge.close(),
529
568
  ...entries.map(({ service, owner }) => service.close(owner, preserve)),
@@ -556,7 +595,7 @@ export async function handleMcpRequest(
556
595
  protocolVersion: requested || protocolVersion,
557
596
  capabilities: { tools: {} },
558
597
  serverInfo: { name: "personal-bot", version: packageVersion },
559
- instructions: runtime.nativeWorkspaceMcp ? mcpWorkerOnlyInstructions : mcpInstructions,
598
+ instructions: await runtime.serverInstructions(),
560
599
  },
561
600
  };
562
601
  }