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
@@ -1,9 +1,13 @@
1
1
  import { type McpWorkerToolName } from "../../model/acp.js";
2
2
  export { buildHistoryMcpTools, buildPbotWorkerTools, buildWorkspaceMcpTools, pbotWorkerTools } from "./tool-contract.js";
3
3
  export type ProgressReporter = (message: string) => void;
4
+ export declare function buildMcpInstructions(options: {
5
+ workspaceMcp: boolean;
6
+ history: boolean;
7
+ }): string;
4
8
  export declare const mcpWorkerOnlyInstructions: string;
5
9
  export declare const mcpInstructions: string;
6
- export declare function defaultWorkerDirectory(): string;
10
+ export declare function defaultWorkerDirectory(workspaceRoot: string): string;
7
11
  /** Parse Pi/dsh `/pbot worker ...` CLI arguments into a canonical MCP tool call. */
8
12
  export declare function parseWorkerCommand(raw: string): {
9
13
  tool: McpWorkerToolName;
@@ -29,7 +33,10 @@ export declare class McpWorkerRuntime {
29
33
  get nativeHistory(): boolean;
30
34
  private resolveBackend;
31
35
  private resolveWorkspace;
36
+ private resolveWorkerWorkspace;
32
37
  private workerService;
38
+ private resolveToolContext;
39
+ serverInstructions(): Promise<string>;
33
40
  toolDefinitions(): Promise<({
34
41
  name: "worker_create";
35
42
  description: string;
@@ -57,10 +64,6 @@ export declare class McpWorkerRuntime {
57
64
  type: string;
58
65
  description: string;
59
66
  };
60
- cwd: {
61
- type: string;
62
- description: string;
63
- };
64
67
  workspace: {
65
68
  type: string;
66
69
  description: string;
@@ -95,14 +98,10 @@ export declare class McpWorkerRuntime {
95
98
  type: string;
96
99
  description: string;
97
100
  };
98
- workspace: {
99
- type: string;
100
- description: string;
101
- };
102
101
  backend?: never;
103
102
  model?: never;
104
103
  thinking?: never;
105
- cwd?: never;
104
+ workspace?: never;
106
105
  message?: never;
107
106
  waitMs?: never;
108
107
  action?: never;
@@ -142,14 +141,10 @@ export declare class McpWorkerRuntime {
142
141
  maximum: number;
143
142
  description: string;
144
143
  };
145
- workspace: {
146
- type: string;
147
- description: string;
148
- };
149
144
  backend?: never;
150
145
  model?: never;
151
146
  thinking?: never;
152
- cwd?: never;
147
+ workspace?: never;
153
148
  action?: never;
154
149
  requestId?: never;
155
150
  optionId?: never;
@@ -201,14 +196,10 @@ export declare class McpWorkerRuntime {
201
196
  maximum: number;
202
197
  description: string;
203
198
  };
204
- workspace: {
205
- type: string;
206
- description: string;
207
- };
208
199
  backend?: never;
209
200
  model?: never;
210
201
  thinking?: never;
211
- cwd?: never;
202
+ workspace?: never;
212
203
  message?: never;
213
204
  offset?: never;
214
205
  target?: never;
@@ -244,14 +235,10 @@ export declare class McpWorkerRuntime {
244
235
  maximum: number;
245
236
  description: string;
246
237
  };
247
- workspace: {
248
- type: string;
249
- description: string;
250
- };
251
238
  backend?: never;
252
239
  model?: never;
253
240
  thinking?: never;
254
- cwd?: never;
241
+ workspace?: never;
255
242
  message?: never;
256
243
  action?: never;
257
244
  requestId?: never;
@@ -297,7 +284,6 @@ export declare class McpWorkerRuntime {
297
284
  description: string;
298
285
  };
299
286
  thinking?: never;
300
- cwd?: never;
301
287
  message?: never;
302
288
  waitMs?: never;
303
289
  action?: never;
@@ -480,7 +466,7 @@ export declare class McpWorkerRuntime {
480
466
  /** Wait until ACP handshake and model/thinking configuration finish so invalid options fail synchronously on create/resume. */
481
467
  private waitReady;
482
468
  private waitFor;
483
- callTool(toolName: string, input: unknown, progress?: ProgressReporter): Promise<unknown>;
469
+ callTool(toolName: string, input: unknown, progress?: ProgressReporter, defaultWorkspace?: string): Promise<unknown>;
484
470
  close(preserve?: boolean): Promise<void>;
485
471
  }
486
472
  export declare function handleMcpRequest(runtime: McpWorkerRuntime, message: unknown, notify?: (notification: Record<string, unknown>) => void): Promise<Record<string, unknown> | null>;
@@ -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";
@@ -23,18 +22,25 @@ const protocolVersion = "2025-03-26";
23
22
  const readyTimeoutMs = 45_000;
24
23
  const reportPageSize = 16_000;
25
24
  const progressIntervalMs = 5_000;
26
- export const mcpWorkerOnlyInstructions = "提供跨助手协作能力(worker_*):可启动并调度其他外部 AI 助手在当前工作区中独立执行任务,适用于用户指定其他助手、需要特定模型或思考深度、获取独立审查/第二意见,或并行处理子任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。\n" +
27
- "使用流程:用 worker_create 启动目标助手(或用 worker_discover 复用已有会话)→ 用 worker_request 派发任务或继续追问 → 任务完成后可用 worker_close 结束会话。后台等待、超时续等(timedOut)或长结果翻页(nextOffset)用 worker_output;助手请求授权或提问(needsResponse)时,先向用户确认,再用 worker_response 回复。";
28
- export const mcpInstructions = "提供三类能力:\n" +
29
- "1. 跨助手协作(worker_*):启动并调度其他外部 AI 助手在当前工作区中独立执行任务,适用于用户指定其他助手、需要特定模型或思考深度、获取独立审查/第二意见,或并行处理子任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。使用流程:worker_create 启动助手(或 worker_discover 复用已有会话)→ worker_request 派发任务或追问 → 完成后 worker_close 结束;后台等待、超时续等(timedOut)或长结果翻页(nextOffset)用 worker_output;返回 needsResponse 时先向用户确认,再用 worker_response 回复。\n" +
30
- "2. 工作区共享外部工具(workspace_mcp_*):发现并调用当前工作区接入的外部工具服务与数据源(可与当前环境原生工具同时使用)。先用 workspace_mcp_discover 查看可用服务与工具说明,再用 workspace_mcp_call 调用。\n" +
31
- "3. 跨宿主历史查询(history_search / history_read):只读检索当前工作区在 Pi、dsh、Claude Code、Antigravity 等宿主中记录的历史问答与摘要归档。";
32
- export function defaultWorkerDirectory() {
25
+ const workerCapabilityInstruction = "跨助手委派(worker_*):启动并调度其他外部助手在当前工作区独立执行任务;无需外部助手时优先自行完成或使用内置子代理。" +
26
+ "流程:worker_create 启动(或 worker_discover 复用)→ worker_request 派发/追问 → 完成后 worker_close;" +
27
+ "后台取结果、超时续等(timedOut)或翻页(nextOffset)用 worker_output;返回 needsResponse 时先向用户确认,再用 worker_response 回复。";
28
+ const workspaceMcpCapabilityInstruction = "工作区共享 MCP(workspace_mcp_*):先用 workspace_mcp_discover 查 .pbot/mcp.json 中的服务与工具,再用 workspace_mcp_call 调用。";
29
+ const historyCapabilityInstruction = "跨宿主历史(history_search / history_read):只读检索当前工作区跨宿主记录的历史问答与摘要归档。";
30
+ export function buildMcpInstructions(options) {
31
+ const parts = [workerCapabilityInstruction];
32
+ if (options.workspaceMcp)
33
+ parts.push(workspaceMcpCapabilityInstruction);
34
+ if (options.history)
35
+ parts.push(historyCapabilityInstruction);
36
+ return parts.length === 1 ? parts[0] : parts.map((text, index) => `${index + 1}. ${text}`).join("\n");
37
+ }
38
+ export const mcpWorkerOnlyInstructions = buildMcpInstructions({ workspaceMcp: false, history: false });
39
+ export const mcpInstructions = buildMcpInstructions({ workspaceMcp: true, history: true });
40
+ export function defaultWorkerDirectory(workspaceRoot) {
33
41
  if (process.env.PBOT_MCP_AGENT_DIR)
34
42
  return process.env.PBOT_MCP_AGENT_DIR;
35
- if (process.env.PLUGIN_DATA)
36
- return join(process.env.PLUGIN_DATA, "subagents");
37
- return join(homedir(), ".pbot/subagents");
43
+ return join(workspaceRoot, ".pbot", "subagents");
38
44
  }
39
45
  function workerCommandTool(name) {
40
46
  const full = name.startsWith("worker_") ? name : `worker_${name}`;
@@ -145,6 +151,7 @@ function presentWorker(value) {
145
151
  }
146
152
  export class McpWorkerRuntime {
147
153
  #services = new Map();
154
+ #workerWorkspaces = new Map();
148
155
  #bridge = new WorkspaceMcpBridge();
149
156
  #sessionId;
150
157
  #directory;
@@ -152,7 +159,7 @@ export class McpWorkerRuntime {
152
159
  #nativeWorkspaceMcp;
153
160
  #nativeHistory;
154
161
  #closing;
155
- constructor(directory = defaultWorkerDirectory(), sessionId = process.env.PBOT_MCP_SESSION_ID || ("mcp-" + randomUUID()), defaultBackend = process.env.PBOT_HOST || undefined, nativeWorkspaceMcp = /^(1|true)$/i.test(process.env.PBOT_NATIVE_WORKSPACE_MCP ?? ""), nativeHistory = /^(1|true)$/i.test(process.env.PBOT_NATIVE_HISTORY ?? "")) {
162
+ constructor(directory, sessionId = process.env.PBOT_MCP_SESSION_ID || ("mcp-" + randomUUID()), defaultBackend = process.env.PBOT_HOST || undefined, nativeWorkspaceMcp = /^(1|true)$/i.test(process.env.PBOT_NATIVE_WORKSPACE_MCP ?? ""), nativeHistory = /^(1|true)$/i.test(process.env.PBOT_NATIVE_HISTORY ?? "")) {
156
163
  this.#directory = directory;
157
164
  this.#sessionId = sessionId;
158
165
  this.#defaultBackend = defaultBackend?.trim() || undefined;
@@ -171,7 +178,7 @@ export class McpWorkerRuntime {
171
178
  env: {
172
179
  PBOT_HOST: this.#defaultBackend,
173
180
  PBOT_WORKSPACE_ROOT: root,
174
- PBOT_MCP_AGENT_DIR: this.#directory,
181
+ PBOT_MCP_AGENT_DIR: this.#directory ?? defaultWorkerDirectory(root),
175
182
  PBOT_MCP_SESSION_ID: this.#sessionId,
176
183
  PBOT_NATIVE_WORKSPACE_MCP: "1",
177
184
  PBOT_NATIVE_HISTORY: "1",
@@ -198,13 +205,26 @@ export class McpWorkerRuntime {
198
205
  requireThat((await stat(root)).isDirectory(), "工作区路径不是目录。");
199
206
  return root;
200
207
  }
208
+ async resolveWorkerWorkspace(workerId, defaultWorkspace) {
209
+ const known = this.#workerWorkspaces.get(workerId);
210
+ if (known)
211
+ return known;
212
+ for (const [root, entry] of this.#services) {
213
+ if (entry.service.has(workerId, entry.owner)) {
214
+ this.#workerWorkspaces.set(workerId, root);
215
+ return root;
216
+ }
217
+ }
218
+ return this.resolveWorkspace(defaultWorkspace);
219
+ }
201
220
  workerService(root, commands = {}) {
202
221
  let entry = this.#services.get(root);
203
222
  if (!entry) {
204
- const host = new AcpWorkerHost(this.#directory, commands);
223
+ const directory = this.#directory ?? defaultWorkerDirectory(root);
224
+ const host = new AcpWorkerHost(directory, commands);
205
225
  entry = {
206
226
  host,
207
- service: new AgentService(root, this.#directory, host),
227
+ service: new AgentService(root, directory, host),
208
228
  owner: { sessionId: this.#sessionId, leaf: null, branch: [] },
209
229
  };
210
230
  this.#services.set(root, entry);
@@ -214,7 +234,7 @@ export class McpWorkerRuntime {
214
234
  }
215
235
  return entry;
216
236
  }
217
- async toolDefinitions() {
237
+ async resolveToolContext() {
218
238
  let commands;
219
239
  let includeWorkspaceMcp = !this.#nativeWorkspaceMcp;
220
240
  let includeHistory = !this.#nativeHistory;
@@ -229,6 +249,14 @@ export class McpWorkerRuntime {
229
249
  }
230
250
  }
231
251
  catch { /* Fall back to registered built-in harnesses when cwd is outside an enabled workspace. */ }
252
+ return { commands, includeWorkspaceMcp, includeHistory };
253
+ }
254
+ async serverInstructions() {
255
+ const { includeWorkspaceMcp, includeHistory } = await this.resolveToolContext();
256
+ return buildMcpInstructions({ workspaceMcp: includeWorkspaceMcp, history: includeHistory });
257
+ }
258
+ async toolDefinitions() {
259
+ const { commands, includeWorkspaceMcp, includeHistory } = await this.resolveToolContext();
232
260
  const defaultBackend = this.#defaultBackend ? canonicalAcpBackend(this.#defaultBackend, commands) : undefined;
233
261
  const workspaceBound = Boolean(pluginMcpWorkspaceRoot());
234
262
  return [
@@ -302,10 +330,13 @@ export class McpWorkerRuntime {
302
330
  await delay(100);
303
331
  }
304
332
  }
305
- async callTool(toolName, input, progress) {
333
+ async callTool(toolName, input, progress, defaultWorkspace) {
306
334
  const { name, args: rawArgs } = parseMcpToolCall(toolName, input);
307
335
  requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
308
- const root = await this.resolveWorkspace(asString(rawArgs, "workspace"));
336
+ const isWorkerScoped = name === "worker_close" || name === "worker_request" || name === "worker_response" || name === "worker_output";
337
+ const root = isWorkerScoped
338
+ ? await this.resolveWorkerWorkspace(asString(rawArgs, "workerId", true), defaultWorkspace)
339
+ : await this.resolveWorkspace(asString(rawArgs, "workspace") ?? defaultWorkspace);
309
340
  const configuration = await readWorkspaceConfig(root);
310
341
  requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
311
342
  requireThat(configuration.enabled, workspaceDisabledMessage(configuration));
@@ -367,13 +398,12 @@ export class McpWorkerRuntime {
367
398
  const backend = this.resolveBackend(rawArgs, configuration.acp, false);
368
399
  const model = asString(rawArgs, "model");
369
400
  const thinking = asString(rawArgs, "thinking");
370
- const cwd = asString(rawArgs, "cwd");
371
401
  const created = await service.start({
372
402
  backend,
373
403
  ...(model ? { model } : {}),
374
404
  ...(thinking ? { thinking } : {}),
375
- ...(cwd ? { cwd } : {}),
376
405
  }, owner);
406
+ this.#workerWorkspaces.set(created.agentId, root);
377
407
  const ready = await this.waitReady(service, owner, created.agentId, readyTimeoutMs, progress);
378
408
  return {
379
409
  ...presentWorker(ready),
@@ -444,21 +474,25 @@ export class McpWorkerRuntime {
444
474
  requireThat(backendRaw === undefined && model === undefined, '参数 backend / model 仅在 target="models" 时可用。');
445
475
  }
446
476
  if (target === "overview") {
477
+ const workers = service.list(owner);
478
+ for (const item of workers)
479
+ this.#workerWorkspaces.set(item.agentId, root);
447
480
  return {
448
481
  target,
449
482
  backends: inspectAcpBackends(configuration.acp),
450
- workers: service.list(owner).map(presentWorker),
483
+ workers: workers.map(presentWorker),
451
484
  };
452
485
  }
453
486
  if (target === "backends") {
454
487
  return { target, backends: inspectAcpBackends(configuration.acp) };
455
488
  }
456
489
  if (target === "workers") {
490
+ const workers = workerId ? [service.status(workerId, owner)] : service.list(owner);
491
+ for (const item of workers)
492
+ this.#workerWorkspaces.set(item.agentId, root);
457
493
  return {
458
494
  target,
459
- workers: workerId
460
- ? [presentWorker(service.status(workerId, owner))]
461
- : service.list(owner).map(presentWorker),
495
+ workers: workers.map(presentWorker),
462
496
  };
463
497
  }
464
498
  const backend = this.resolveBackend(rawArgs, configuration.acp, true);
@@ -475,6 +509,7 @@ export class McpWorkerRuntime {
475
509
  return this.#closing;
476
510
  const entries = [...this.#services.values()];
477
511
  this.#services.clear();
512
+ this.#workerWorkspaces.clear();
478
513
  this.#closing = Promise.allSettled([
479
514
  this.#bridge.close(),
480
515
  ...entries.map(({ service, owner }) => service.close(owner, preserve)),
@@ -502,7 +537,7 @@ export async function handleMcpRequest(runtime, message, notify) {
502
537
  protocolVersion: requested || protocolVersion,
503
538
  capabilities: { tools: {} },
504
539
  serverInfo: { name: "personal-bot", version: packageVersion },
505
- instructions: runtime.nativeWorkspaceMcp ? mcpWorkerOnlyInstructions : mcpInstructions,
540
+ instructions: await runtime.serverInstructions(),
506
541
  },
507
542
  };
508
543
  }