personal-bot 0.3.7 → 0.4.1

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 (172) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +2 -2
  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/architecture/design.md +2 -2
  7. package/docs/architecture/extensibility.md +4 -4
  8. package/docs/architecture/model-context.md +6 -3
  9. package/docs/guides/cross-harness-workers.md +5 -5
  10. package/docs/guides/history.md +1 -3
  11. package/docs/guides/workspace-configuration.md +5 -5
  12. package/docs/hosts/claude-code.md +3 -3
  13. package/docs/hosts/codex-qoder.md +4 -2
  14. package/hooks/hooks.json +3 -0
  15. package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +1 -1
  16. package/lib/antigravity-plugin/lib/extension/acp/member.d.ts +1 -1
  17. package/lib/antigravity-plugin/lib/extension/acp/member.js +11 -10
  18. package/lib/antigravity-plugin/lib/extension/acp-worker.js +349 -204
  19. package/lib/antigravity-plugin/lib/extension/cli.js +596 -572
  20. package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.js +1 -1
  21. package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +3 -4
  22. package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +1 -12
  23. package/lib/antigravity-plugin/lib/extension/mcp.js +463 -379
  24. package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +2 -2
  25. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +3 -3
  26. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.js +0 -1
  27. package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +1 -2
  28. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.d.ts +1 -1
  29. package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.js +4 -7
  30. package/lib/antigravity-plugin/lib/model/acp.d.ts +29 -35
  31. package/lib/antigravity-plugin/lib/model/agent.d.ts +33 -17
  32. package/lib/antigravity-plugin/lib/model/agent.js +0 -1
  33. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.js +1 -1
  34. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.js +6 -3
  35. package/lib/antigravity-plugin/lib/services/history/summary-runner.js +3 -3
  36. package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +5 -8
  37. package/lib/antigravity-plugin/lib/storage/acp-files.js +34 -40
  38. package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +19 -10
  39. package/lib/antigravity-plugin/lib/storage/agent-files.js +147 -43
  40. package/lib/antigravity-plugin/lib/storage/history-files.js +3 -2
  41. package/lib/antigravity-plugin/package.json +1 -1
  42. package/lib/antigravity-plugin/plugin.json +2 -2
  43. package/lib/antigravity-plugin/resources/agents/coordinator.md +2 -4
  44. package/lib/antigravity-plugin/resources/agents/general-purpose.md +2 -4
  45. package/lib/antigravity-plugin/resources/prompts/history-monthly-summary.md +6 -11
  46. package/lib/antigravity-plugin/resources/prompts/history-summary.md +6 -11
  47. package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -1
  48. package/lib/antigravity-plugin/resources/prompts/workspace.md +16 -23
  49. package/lib/antigravity-plugin/resources/skills/project-maintenance/SKILL.md +14 -21
  50. package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +23 -36
  51. package/lib/antigravity-plugin/resources/templates/workspace-agents.md +5 -13
  52. package/lib/antigravity-plugin/skills/pbot/SKILL.md +6 -23
  53. package/lib/antigravity-plugin/skills/project-maintenance/SKILL.md +14 -21
  54. package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +23 -36
  55. package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +2 -2
  56. package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +2 -2
  57. package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +3 -3
  58. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +11 -3
  59. package/lib/extension/acp/member.d.ts +1 -1
  60. package/lib/extension/acp/member.js +11 -10
  61. package/lib/extension/acp/worker.js +34 -33
  62. package/lib/extension/acp-worker.js +349 -204
  63. package/lib/extension/cli.js +596 -572
  64. package/lib/extension/hosts/dsh/acp-member.js +1 -1
  65. package/lib/extension/hosts/dsh/command.js +2 -2
  66. package/lib/extension/hosts/dsh/workspace.js +5 -5
  67. package/lib/extension/hosts/pi/acp-member.js +3 -4
  68. package/lib/extension/hosts/plugin-runtime.js +1 -12
  69. package/lib/extension/mcp/tool-contract.d.ts +8 -50
  70. package/lib/extension/mcp/tool-contract.js +61 -107
  71. package/lib/extension/mcp/workers.d.ts +7 -27
  72. package/lib/extension/mcp/workers.js +40 -24
  73. package/lib/extension/mcp.js +463 -379
  74. package/lib/integrations/acp/agents.d.ts +2 -3
  75. package/lib/integrations/acp/agents.js +22 -22
  76. package/lib/integrations/acp/harnesses/claude.js +1 -1
  77. package/lib/integrations/agent-resources.d.ts +2 -2
  78. package/lib/integrations/agent-resources.js +3 -3
  79. package/lib/integrations/hosts/antigravity/adapter.js +0 -1
  80. package/lib/integrations/hosts/claude/adapter.js +1 -2
  81. package/lib/integrations/hosts/dsh/resources.d.ts +1 -1
  82. package/lib/integrations/hosts/prompt-hooks.js +4 -7
  83. package/lib/model/acp.d.ts +29 -35
  84. package/lib/model/agent.d.ts +33 -17
  85. package/lib/model/agent.js +0 -1
  86. package/lib/qoder-plugin/.mcp.json +2 -2
  87. package/lib/qoder-plugin/.qoder-plugin/plugin.json +2 -2
  88. package/lib/qoder-plugin/hooks/hooks.json +3 -3
  89. package/lib/qoder-plugin/skills/pbot/SKILL.md +11 -3
  90. package/lib/services/agents/acp-run.d.ts +6 -4
  91. package/lib/services/agents/acp-run.js +62 -43
  92. package/lib/services/agents/agent-run.d.ts +10 -6
  93. package/lib/services/agents/agent-run.js +142 -65
  94. package/lib/services/agents/agent-service.d.ts +3 -21
  95. package/lib/services/agents/agent-service.js +182 -128
  96. package/lib/services/history/summary-dimensions/monthly.js +1 -1
  97. package/lib/services/history/summary-dimensions/session.js +6 -3
  98. package/lib/services/history/summary-runner.js +3 -3
  99. package/lib/storage/acp-files.d.ts +5 -8
  100. package/lib/storage/acp-files.js +34 -40
  101. package/lib/storage/agent-files.d.ts +19 -10
  102. package/lib/storage/agent-files.js +147 -43
  103. package/lib/storage/history-files.js +3 -2
  104. package/lib/tools/history/contract.d.ts +1 -1
  105. package/lib/tools/history/contract.js +14 -16
  106. package/package.json +2 -2
  107. package/resources/agents/coordinator.md +2 -4
  108. package/resources/agents/general-purpose.md +2 -4
  109. package/resources/antigravity/skills/pbot/SKILL.md +6 -23
  110. package/resources/claude/skills/pbot/SKILL.md +6 -23
  111. package/resources/plugin/skills/pbot/SKILL.md +11 -3
  112. package/resources/prompts/history-coordinator.md +1 -1
  113. package/resources/prompts/history-monthly-summary.md +6 -11
  114. package/resources/prompts/history-summary.md +6 -11
  115. package/resources/prompts/plugin-coordinator.md +1 -1
  116. package/resources/prompts/workspace.md +16 -23
  117. package/resources/skills/project-maintenance/SKILL.md +14 -21
  118. package/resources/skills/provider-connections/SKILL.md +23 -36
  119. package/resources/templates/workspace-agents.md +5 -13
  120. package/src/extension/acp/member.ts +14 -11
  121. package/src/extension/acp/worker.ts +31 -28
  122. package/src/extension/cli/commands/mcp.ts +1 -1
  123. package/src/extension/cli/commands/upgrade.ts +8 -36
  124. package/src/extension/cli/commands/workspace.ts +3 -8
  125. package/src/extension/cli/index.ts +1 -2
  126. package/src/extension/hosts/dsh/acp-member.ts +1 -1
  127. package/src/extension/hosts/dsh/command.ts +2 -2
  128. package/src/extension/hosts/dsh/workspace.ts +5 -4
  129. package/src/extension/hosts/pi/acp-member.ts +3 -4
  130. package/src/extension/hosts/pi/command.ts +2 -2
  131. package/src/extension/hosts/pi/events.ts +1 -1
  132. package/src/extension/hosts/pi/lifecycle.ts +0 -2
  133. package/src/extension/hosts/plugin-runtime.ts +1 -11
  134. package/src/extension/mcp/tool-contract.ts +61 -108
  135. package/src/extension/mcp/workers.ts +39 -24
  136. package/src/integrations/acp/agents.ts +28 -27
  137. package/src/integrations/acp/harnesses/claude.ts +1 -1
  138. package/src/integrations/agent-resources.ts +5 -5
  139. package/src/integrations/hosts/antigravity/adapter.ts +0 -1
  140. package/src/integrations/hosts/claude/adapter.ts +1 -2
  141. package/src/integrations/hosts/dsh/resources.ts +1 -1
  142. package/src/integrations/hosts/dsh/session.ts +2 -2
  143. package/src/integrations/hosts/prompt-hooks.ts +3 -6
  144. package/src/integrations/installation/cli-update.ts +2 -2
  145. package/src/integrations/installation/installers/claude.ts +4 -4
  146. package/src/integrations/installation/installers/qoder.ts +5 -5
  147. package/src/integrations/installation/upgraders/antigravity.ts +57 -15
  148. package/src/integrations/installation/upgraders/claude.ts +1 -4
  149. package/src/integrations/installation/upgraders/codex.ts +85 -15
  150. package/src/integrations/installation/upgraders/dsh.ts +46 -24
  151. package/src/integrations/installation/upgraders/pi.ts +18 -11
  152. package/src/integrations/installation/upgraders/qoder.ts +95 -20
  153. package/src/model/acp.ts +27 -29
  154. package/src/model/agent.ts +80 -16
  155. package/src/model/installation.ts +0 -2
  156. package/src/pbot.ts +3 -3
  157. package/src/services/agents/acp-run.ts +81 -49
  158. package/src/services/agents/agent-run.ts +154 -56
  159. package/src/services/agents/agent-service.ts +206 -135
  160. package/src/services/history/summary-dimensions/monthly.ts +1 -1
  161. package/src/services/history/summary-dimensions/session.ts +6 -3
  162. package/src/services/history/summary-runner.ts +3 -3
  163. package/src/services/installation/upgrade-service.ts +1 -5
  164. package/src/storage/acp-files.ts +50 -45
  165. package/src/storage/agent-files.ts +159 -46
  166. package/src/storage/history-files.ts +3 -2
  167. package/src/tools/history/contract.ts +14 -16
  168. package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +0 -15
  169. package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +0 -126
  170. package/lib/services/workspace/plugin-releases.d.ts +0 -15
  171. package/lib/services/workspace/plugin-releases.js +0 -126
  172. package/src/services/workspace/plugin-releases.ts +0 -121
@@ -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,27 +22,23 @@ const protocolVersion = "2025-03-26";
23
22
  const readyTimeoutMs = 45_000;
24
23
  const reportPageSize = 16_000;
25
24
  const progressIntervalMs = 5_000;
26
- const workerCapabilityInstruction = "跨助手委派(worker_*):启动并调度其他外部助手在当前工作区独立执行任务;无需外部助手时优先自行完成或使用内置子代理。" +
27
- "流程:worker_create 启动(或 worker_discover 复用)→ worker_request 派发/追问 → 完成后 worker_close;" +
28
- "后台取结果、超时续等(timedOut)或翻页(nextOffset)用 worker_output;返回 needsResponse 时先向用户确认,再用 worker_response 回复。";
29
- const workspaceMcpCapabilityInstruction = "工作区共享 MCP(workspace_mcp_*):先用 workspace_mcp_discover 查 .pbot/mcp.json 中的服务与工具,再用 workspace_mcp_call 调用。";
30
- const historyCapabilityInstruction = "跨宿主历史(history_search / history_read):只读检索当前工作区跨宿主记录的历史问答与摘要归档。";
25
+ const workerCapabilityInstruction = "用户或工作区分工指定其他助手或特定模型时,可在当前工作区委派任务。常规任务优先自行处理或使用宿主内置子代理。";
26
+ const workspaceMcpCapabilityInstruction = "可调用本工作区 .pbot/mcp.json 中登记的 MCP 工具。";
27
+ const historyCapabilityInstruction = "可检索本工作区各宿主归档的问答和摘要。";
31
28
  export function buildMcpInstructions(options) {
32
29
  const parts = [workerCapabilityInstruction];
33
30
  if (options.workspaceMcp)
34
31
  parts.push(workspaceMcpCapabilityInstruction);
35
32
  if (options.history)
36
33
  parts.push(historyCapabilityInstruction);
37
- return parts.length === 1 ? parts[0] : parts.map((text, index) => `${index + 1}. ${text}`).join("\n");
34
+ return parts.join("\n");
38
35
  }
39
36
  export const mcpWorkerOnlyInstructions = buildMcpInstructions({ workspaceMcp: false, history: false });
40
37
  export const mcpInstructions = buildMcpInstructions({ workspaceMcp: true, history: true });
41
- export function defaultWorkerDirectory() {
38
+ export function defaultWorkerDirectory(workspaceRoot) {
42
39
  if (process.env.PBOT_MCP_AGENT_DIR)
43
40
  return process.env.PBOT_MCP_AGENT_DIR;
44
- if (process.env.PLUGIN_DATA)
45
- return join(process.env.PLUGIN_DATA, "subagents");
46
- return join(homedir(), ".pbot/subagents");
41
+ return join(workspaceRoot, ".pbot", "subagents");
47
42
  }
48
43
  function workerCommandTool(name) {
49
44
  const full = name.startsWith("worker_") ? name : `worker_${name}`;
@@ -154,6 +149,7 @@ function presentWorker(value) {
154
149
  }
155
150
  export class McpWorkerRuntime {
156
151
  #services = new Map();
152
+ #workerWorkspaces = new Map();
157
153
  #bridge = new WorkspaceMcpBridge();
158
154
  #sessionId;
159
155
  #directory;
@@ -161,7 +157,7 @@ export class McpWorkerRuntime {
161
157
  #nativeWorkspaceMcp;
162
158
  #nativeHistory;
163
159
  #closing;
164
- 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 ?? "")) {
160
+ 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 ?? "")) {
165
161
  this.#directory = directory;
166
162
  this.#sessionId = sessionId;
167
163
  this.#defaultBackend = defaultBackend?.trim() || undefined;
@@ -180,7 +176,7 @@ export class McpWorkerRuntime {
180
176
  env: {
181
177
  PBOT_HOST: this.#defaultBackend,
182
178
  PBOT_WORKSPACE_ROOT: root,
183
- PBOT_MCP_AGENT_DIR: this.#directory,
179
+ PBOT_MCP_AGENT_DIR: this.#directory ?? defaultWorkerDirectory(root),
184
180
  PBOT_MCP_SESSION_ID: this.#sessionId,
185
181
  PBOT_NATIVE_WORKSPACE_MCP: "1",
186
182
  PBOT_NATIVE_HISTORY: "1",
@@ -207,13 +203,26 @@ export class McpWorkerRuntime {
207
203
  requireThat((await stat(root)).isDirectory(), "工作区路径不是目录。");
208
204
  return root;
209
205
  }
206
+ async resolveWorkerWorkspace(workerId, defaultWorkspace) {
207
+ const known = this.#workerWorkspaces.get(workerId);
208
+ if (known)
209
+ return known;
210
+ for (const [root, entry] of this.#services) {
211
+ if (entry.service.has(workerId, entry.owner)) {
212
+ this.#workerWorkspaces.set(workerId, root);
213
+ return root;
214
+ }
215
+ }
216
+ return this.resolveWorkspace(defaultWorkspace);
217
+ }
210
218
  workerService(root, commands = {}) {
211
219
  let entry = this.#services.get(root);
212
220
  if (!entry) {
213
- const host = new AcpWorkerHost(this.#directory, commands);
221
+ const directory = this.#directory ?? defaultWorkerDirectory(root);
222
+ const host = new AcpWorkerHost(directory, commands);
214
223
  entry = {
215
224
  host,
216
- service: new AgentService(root, this.#directory, host),
225
+ service: new AgentService(root, directory, host),
217
226
  owner: { sessionId: this.#sessionId, leaf: null, branch: [] },
218
227
  };
219
228
  this.#services.set(root, entry);
@@ -319,17 +328,20 @@ export class McpWorkerRuntime {
319
328
  await delay(100);
320
329
  }
321
330
  }
322
- async callTool(toolName, input, progress) {
331
+ async callTool(toolName, input, progress, defaultWorkspace) {
323
332
  const { name, args: rawArgs } = parseMcpToolCall(toolName, input);
324
333
  requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
325
- const root = await this.resolveWorkspace(asString(rawArgs, "workspace"));
334
+ const isWorkerScoped = name === "worker_close" || name === "worker_request" || name === "worker_response" || name === "worker_output";
335
+ const root = isWorkerScoped
336
+ ? await this.resolveWorkerWorkspace(asString(rawArgs, "workerId", true), defaultWorkspace)
337
+ : await this.resolveWorkspace(asString(rawArgs, "workspace") ?? defaultWorkspace);
326
338
  const configuration = await readWorkspaceConfig(root);
327
339
  requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
328
340
  requireThat(configuration.enabled, workspaceDisabledMessage(configuration));
329
341
  switch (name) {
330
342
  case "workspace_mcp_discover":
331
343
  case "workspace_mcp_call": {
332
- requireThat(!this.#nativeWorkspaceMcp, "当前宿主已原生挂载工作区 .pbot/mcp.json 服务,请直接调用对应原生 MCP 工具,勿重复经由 workspace_mcp_* 桥接。");
344
+ requireThat(!this.#nativeWorkspaceMcp, "当前宿主已原生挂载工作区 MCP 服务,请直接调用对应工具。");
333
345
  requireThat(workspaceFeatures(configuration).mcp, `工作区统一 MCP 功能已在 ${configuration.path} 中停用(features.mcp: false)。`);
334
346
  if (name === "workspace_mcp_discover")
335
347
  return this.#bridge.discover(root, asString(rawArgs, "server"));
@@ -384,13 +396,12 @@ export class McpWorkerRuntime {
384
396
  const backend = this.resolveBackend(rawArgs, configuration.acp, false);
385
397
  const model = asString(rawArgs, "model");
386
398
  const thinking = asString(rawArgs, "thinking");
387
- const cwd = asString(rawArgs, "cwd");
388
399
  const created = await service.start({
389
400
  backend,
390
401
  ...(model ? { model } : {}),
391
402
  ...(thinking ? { thinking } : {}),
392
- ...(cwd ? { cwd } : {}),
393
403
  }, owner);
404
+ this.#workerWorkspaces.set(created.agentId, root);
394
405
  const ready = await this.waitReady(service, owner, created.agentId, readyTimeoutMs, progress);
395
406
  return {
396
407
  ...presentWorker(ready),
@@ -461,21 +472,25 @@ export class McpWorkerRuntime {
461
472
  requireThat(backendRaw === undefined && model === undefined, '参数 backend / model 仅在 target="models" 时可用。');
462
473
  }
463
474
  if (target === "overview") {
475
+ const workers = service.list(owner);
476
+ for (const item of workers)
477
+ this.#workerWorkspaces.set(item.agentId, root);
464
478
  return {
465
479
  target,
466
480
  backends: inspectAcpBackends(configuration.acp),
467
- workers: service.list(owner).map(presentWorker),
481
+ workers: workers.map(presentWorker),
468
482
  };
469
483
  }
470
484
  if (target === "backends") {
471
485
  return { target, backends: inspectAcpBackends(configuration.acp) };
472
486
  }
473
487
  if (target === "workers") {
488
+ const workers = workerId ? [service.status(workerId, owner)] : service.list(owner);
489
+ for (const item of workers)
490
+ this.#workerWorkspaces.set(item.agentId, root);
474
491
  return {
475
492
  target,
476
- workers: workerId
477
- ? [presentWorker(service.status(workerId, owner))]
478
- : service.list(owner).map(presentWorker),
493
+ workers: workers.map(presentWorker),
479
494
  };
480
495
  }
481
496
  const backend = this.resolveBackend(rawArgs, configuration.acp, true);
@@ -492,6 +507,7 @@ export class McpWorkerRuntime {
492
507
  return this.#closing;
493
508
  const entries = [...this.#services.values()];
494
509
  this.#services.clear();
510
+ this.#workerWorkspaces.clear();
495
511
  this.#closing = Promise.allSettled([
496
512
  this.#bridge.close(),
497
513
  ...entries.map(({ service, owner }) => service.close(owner, preserve)),