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";
@@ -41,31 +40,28 @@ const progressIntervalMs = 5_000;
41
40
  export type ProgressReporter = (message: string) => void;
42
41
 
43
42
  const workerCapabilityInstruction =
44
- "跨助手委派(worker_*):启动并调度其他外部助手在当前工作区独立执行任务;无需外部助手时优先自行完成或使用内置子代理。" +
45
- "流程:worker_create 启动(或 worker_discover 复用)→ worker_request 派发/追问 → 完成后 worker_close;" +
46
- "后台取结果、超时续等(timedOut)或翻页(nextOffset)用 worker_output;返回 needsResponse 时先向用户确认,再用 worker_response 回复。";
43
+ "用户或工作区分工指定其他助手或特定模型时,可在当前工作区委派任务。常规任务优先自行处理或使用宿主内置子代理。";
47
44
 
48
45
  const workspaceMcpCapabilityInstruction =
49
- "工作区共享 MCP(workspace_mcp_*):先用 workspace_mcp_discover 查 .pbot/mcp.json 中的服务与工具,再用 workspace_mcp_call 调用。";
46
+ "可调用本工作区 .pbot/mcp.json 中登记的 MCP 工具。";
50
47
 
51
48
  const historyCapabilityInstruction =
52
- "跨宿主历史(history_search / history_read):只读检索当前工作区跨宿主记录的历史问答与摘要归档。";
49
+ "可检索本工作区各宿主归档的问答和摘要。";
53
50
 
54
51
  export function buildMcpInstructions(options: { workspaceMcp: boolean; history: boolean }): string {
55
52
  const parts = [workerCapabilityInstruction];
56
53
  if (options.workspaceMcp) parts.push(workspaceMcpCapabilityInstruction);
57
54
  if (options.history) parts.push(historyCapabilityInstruction);
58
- return parts.length === 1 ? parts[0]! : parts.map((text, index) => `${index + 1}. ${text}`).join("\n");
55
+ return parts.join("\n");
59
56
  }
60
57
 
61
58
  export const mcpWorkerOnlyInstructions = buildMcpInstructions({ workspaceMcp: false, history: false });
62
59
 
63
60
  export const mcpInstructions = buildMcpInstructions({ workspaceMcp: true, history: true });
64
61
 
65
- export function defaultWorkerDirectory(): string {
62
+ export function defaultWorkerDirectory(workspaceRoot: string): string {
66
63
  if (process.env.PBOT_MCP_AGENT_DIR) return process.env.PBOT_MCP_AGENT_DIR;
67
- if (process.env.PLUGIN_DATA) return join(process.env.PLUGIN_DATA, "subagents");
68
- return join(homedir(), ".pbot/subagents");
64
+ return join(workspaceRoot, ".pbot", "subagents");
69
65
  }
70
66
 
71
67
  function workerCommandTool(name: string): McpWorkerToolName | undefined {
@@ -183,16 +179,17 @@ function presentWorker(value: AgentView & {
183
179
 
184
180
  export class McpWorkerRuntime {
185
181
  readonly #services = new Map<string, { service: AgentService; host: AcpWorkerHost; owner: AgentOwner }>();
182
+ readonly #workerWorkspaces = new Map<string, string>();
186
183
  readonly #bridge = new WorkspaceMcpBridge();
187
184
  readonly #sessionId: string;
188
- readonly #directory: string;
185
+ readonly #directory: string | undefined;
189
186
  readonly #defaultBackend: string | undefined;
190
187
  readonly #nativeWorkspaceMcp: boolean;
191
188
  readonly #nativeHistory: boolean;
192
189
  #closing: Promise<void> | undefined;
193
190
 
194
191
  constructor(
195
- directory = defaultWorkerDirectory(),
192
+ directory?: string,
196
193
  sessionId = process.env.PBOT_MCP_SESSION_ID || ("mcp-" + randomUUID()),
197
194
  defaultBackend = process.env.PBOT_HOST || undefined,
198
195
  nativeWorkspaceMcp = /^(1|true)$/i.test(process.env.PBOT_NATIVE_WORKSPACE_MCP ?? ""),
@@ -216,7 +213,7 @@ export class McpWorkerRuntime {
216
213
  env: {
217
214
  PBOT_HOST: this.#defaultBackend,
218
215
  PBOT_WORKSPACE_ROOT: root,
219
- PBOT_MCP_AGENT_DIR: this.#directory,
216
+ PBOT_MCP_AGENT_DIR: this.#directory ?? defaultWorkerDirectory(root),
220
217
  PBOT_MCP_SESSION_ID: this.#sessionId,
221
218
  PBOT_NATIVE_WORKSPACE_MCP: "1",
222
219
  PBOT_NATIVE_HISTORY: "1",
@@ -248,13 +245,26 @@ export class McpWorkerRuntime {
248
245
  return root;
249
246
  }
250
247
 
248
+ private async resolveWorkerWorkspace(workerId: string, defaultWorkspace?: string): Promise<string> {
249
+ const known = this.#workerWorkspaces.get(workerId);
250
+ if (known) return known;
251
+ for (const [root, entry] of this.#services) {
252
+ if (entry.service.has(workerId, entry.owner)) {
253
+ this.#workerWorkspaces.set(workerId, root);
254
+ return root;
255
+ }
256
+ }
257
+ return this.resolveWorkspace(defaultWorkspace);
258
+ }
259
+
251
260
  private workerService(root: string, commands: AcpCommands = {}) {
252
261
  let entry = this.#services.get(root);
253
262
  if (!entry) {
254
- const host = new AcpWorkerHost(this.#directory, commands);
263
+ const directory = this.#directory ?? defaultWorkerDirectory(root);
264
+ const host = new AcpWorkerHost(directory, commands);
255
265
  entry = {
256
266
  host,
257
- service: new AgentService(root, this.#directory, host),
267
+ service: new AgentService(root, directory, host),
258
268
  owner: { sessionId: this.#sessionId, leaf: null, branch: [] },
259
269
  };
260
270
  this.#services.set(root, entry);
@@ -375,10 +385,13 @@ export class McpWorkerRuntime {
375
385
  }
376
386
  }
377
387
 
378
- async callTool(toolName: string, input: unknown, progress?: ProgressReporter): Promise<unknown> {
388
+ async callTool(toolName: string, input: unknown, progress?: ProgressReporter, defaultWorkspace?: string): Promise<unknown> {
379
389
  const { name, args: rawArgs } = parseMcpToolCall(toolName, input);
380
390
  requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
381
- const root = await this.resolveWorkspace(asString(rawArgs, "workspace"));
391
+ const isWorkerScoped = name === "worker_close" || name === "worker_request" || name === "worker_response" || name === "worker_output";
392
+ const root = isWorkerScoped
393
+ ? await this.resolveWorkerWorkspace(asString(rawArgs, "workerId", true)!, defaultWorkspace)
394
+ : await this.resolveWorkspace(asString(rawArgs, "workspace") ?? defaultWorkspace);
382
395
  const configuration = await readWorkspaceConfig(root);
383
396
  requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
384
397
  requireThat(configuration.enabled, workspaceDisabledMessage(configuration));
@@ -386,7 +399,7 @@ export class McpWorkerRuntime {
386
399
  switch (name) {
387
400
  case "workspace_mcp_discover":
388
401
  case "workspace_mcp_call": {
389
- requireThat(!this.#nativeWorkspaceMcp, "当前宿主已原生挂载工作区 .pbot/mcp.json 服务,请直接调用对应原生 MCP 工具,勿重复经由 workspace_mcp_* 桥接。");
402
+ requireThat(!this.#nativeWorkspaceMcp, "当前宿主已原生挂载工作区 MCP 服务,请直接调用对应工具。");
390
403
  requireThat(workspaceFeatures(configuration).mcp, `工作区统一 MCP 功能已在 ${configuration.path} 中停用(features.mcp: false)。`);
391
404
  if (name === "workspace_mcp_discover") return this.#bridge.discover(root, asString(rawArgs, "server"));
392
405
  const server = asString(rawArgs, "server", true)!;
@@ -438,13 +451,12 @@ export class McpWorkerRuntime {
438
451
  const backend = this.resolveBackend(rawArgs, configuration.acp, false);
439
452
  const model = asString(rawArgs, "model");
440
453
  const thinking = asString(rawArgs, "thinking");
441
- const cwd = asString(rawArgs, "cwd");
442
454
  const created = await service.start({
443
455
  backend,
444
456
  ...(model ? { model } : {}),
445
457
  ...(thinking ? { thinking } : {}),
446
- ...(cwd ? { cwd } : {}),
447
458
  }, owner);
459
+ this.#workerWorkspaces.set(created.agentId, root);
448
460
  const ready = await this.waitReady(service, owner, created.agentId, readyTimeoutMs, progress);
449
461
  return {
450
462
  ...presentWorker(ready),
@@ -515,21 +527,23 @@ export class McpWorkerRuntime {
515
527
  requireThat(backendRaw === undefined && model === undefined, '参数 backend / model 仅在 target="models" 时可用。');
516
528
  }
517
529
  if (target === "overview") {
530
+ const workers = service.list(owner);
531
+ for (const item of workers) this.#workerWorkspaces.set(item.agentId, root);
518
532
  return {
519
533
  target,
520
534
  backends: inspectAcpBackends(configuration.acp),
521
- workers: service.list(owner).map(presentWorker),
535
+ workers: workers.map(presentWorker),
522
536
  };
523
537
  }
524
538
  if (target === "backends") {
525
539
  return { target, backends: inspectAcpBackends(configuration.acp) };
526
540
  }
527
541
  if (target === "workers") {
542
+ const workers = workerId ? [service.status(workerId, owner)] : service.list(owner);
543
+ for (const item of workers) this.#workerWorkspaces.set(item.agentId, root);
528
544
  return {
529
545
  target,
530
- workers: workerId
531
- ? [presentWorker(service.status(workerId, owner))]
532
- : service.list(owner).map(presentWorker),
546
+ workers: workers.map(presentWorker),
533
547
  };
534
548
  }
535
549
  const backend = this.resolveBackend(rawArgs, configuration.acp, true);
@@ -546,6 +560,7 @@ export class McpWorkerRuntime {
546
560
  if (this.#closing) return this.#closing;
547
561
  const entries = [...this.#services.values()];
548
562
  this.#services.clear();
563
+ this.#workerWorkspaces.clear();
549
564
  this.#closing = Promise.allSettled([
550
565
  this.#bridge.close(),
551
566
  ...entries.map(({ service, owner }) => service.close(owner, preserve)),
@@ -1,12 +1,10 @@
1
1
  import { fork, spawnSync } from "node:child_process";
2
2
  import { existsSync } from "node:fs";
3
- import { join, resolve } from "node:path";
3
+ import { resolve } from "node:path";
4
4
  import { setTimeout as delay } from "node:timers/promises";
5
- import type { AgentHost, AgentDescriptor, AgentOptions, AgentSessionReference } from "../../model/agent.js";
5
+ import type { AgentDescriptor, AgentHost, AgentOptions, AgentSessionReference } from "../../model/agent.js";
6
6
  import type { AcpBackend, AcpCommands, AcpModelsResult } from "../../model/acp.js";
7
- import { AgentFiles, launch } from "../../storage/agent-files.js";
8
- import { acpInput, acpProcess, acpReport } from "../../storage/acp-files.js";
9
- import { fileId } from "../../storage/file-access.js";
7
+ import { AgentFiles, status, workerRecord } from "../../storage/agent-files.js";
10
8
  import { requireThat } from "../../common/validation.js";
11
9
  import { resourceRoot } from "../../common/paths.js";
12
10
  import { acpLaunch, filterAcpStartOptions } from "./launch.js";
@@ -35,13 +33,13 @@ export class AcpWorkerHost implements AgentHost {
35
33
  }
36
34
 
37
35
  /** Probe a backend's advertised model and thinking choices in an isolated ACP process without prompting. */
38
- async inspectModels(backend: AcpBackend, cwd: string, options: Pick<AgentOptions, "provider" | "model"> = {}): Promise<AcpModelsResult> {
36
+ async inspectModels(backend: AcpBackend, workspace: string, options: Pick<AgentOptions, "provider" | "model"> = {}): Promise<AcpModelsResult> {
39
37
  this.available(backend);
40
38
  const filtered = this.filterOptions(backend, options);
41
39
  const reference = this.prepare(backend, filtered);
42
40
  return await new Promise<AcpModelsResult>((resolveResult, reject) => {
43
41
  const child = fork(this.worker, ["--probe"], {
44
- cwd, env: { ...process.env }, detached: true, stdio: ["ignore", "ignore", "ignore", "ipc"], execArgv: [],
42
+ cwd: workspace, env: { ...process.env }, detached: true, stdio: ["ignore", "ignore", "ignore", "ipc"], execArgv: [],
45
43
  });
46
44
  let result: AcpModelsResult | undefined, failure: Error | undefined;
47
45
  const timer = setTimeout(() => {
@@ -59,7 +57,7 @@ export class AcpWorkerHost implements AgentHost {
59
57
  child.once("spawn", () => {
60
58
  child.send({
61
59
  reference,
62
- cwd,
60
+ cwd: workspace,
63
61
  ...(filtered.provider ? { provider: filtered.provider } : {}),
64
62
  ...(filtered.model ? { model: filtered.model } : {}),
65
63
  });
@@ -72,9 +70,9 @@ export class AcpWorkerHost implements AgentHost {
72
70
  });
73
71
  }
74
72
 
75
- private process(id: string) {
76
- const record = this.files.optional(id, "acp-process.json", acpProcess);
77
- if (!record || this.files.read(id, "launch.json", launch).generation !== record.generation) return;
73
+ private process(id: string): { generation: string; pid: number } | undefined {
74
+ const record = this.files.optional(id, "worker.json", workerRecord);
75
+ if (!record?.pid) return;
78
76
  let denied = false;
79
77
  try { process.kill(-record.pid, 0); }
80
78
  catch (error) {
@@ -86,7 +84,7 @@ export class AcpWorkerHost implements AgentHost {
86
84
  const leader = spawnSync("ps", ["-p", String(record.pid), "-o", "args="], { encoding: "utf8" });
87
85
  // A dead leader can leave its group alive. A reused leader must match our exact launch identity.
88
86
  if (leader.status === 0 && !leader.stdout.includes("--pbot-acp-agent " + id + " --generation " + record.generation) || denied && leader.status !== 0) return;
89
- return record;
87
+ return { generation: record.generation, pid: record.pid };
90
88
  }
91
89
 
92
90
  alive(id: string) {
@@ -96,10 +94,11 @@ export class AcpWorkerHost implements AgentHost {
96
94
  async validateSession(d: AgentDescriptor, reference: AgentSessionReference) {
97
95
  requireThat(!this.alive(d.agentId), "ACP 成员仍在运行,不能恢复。");
98
96
  if (reference.sessionId === null) {
99
- requireThat(!this.files.optional(d.agentId, "acp-input.json", acpInput), "ACP 输入交付状态不明;请核对原请求后新建成员。");
97
+ const saved = this.files.optional(d.agentId, "state.json", status);
98
+ requireThat(!saved?.activeRequestId, "ACP 输入交付状态不明;请核对原请求后新建成员。");
100
99
  return;
101
100
  }
102
- const generation = this.files.read(d.agentId, "launch.json", launch).generation;
101
+ const generation = this.files.worker(d.agentId).generation;
103
102
  await new Promise<void>((resolveResult, reject) => {
104
103
  const child = this.spawn(d, generation, true);
105
104
  let validated = false, failure: Error | undefined;
@@ -119,7 +118,7 @@ export class AcpWorkerHost implements AgentHost {
119
118
  private spawn(d: AgentDescriptor, generation: string, validate = false) {
120
119
  return fork(this.worker, ["--pbot-acp-agent", d.agentId, "--generation", generation, "--directory", this.files.directory(d.agentId),
121
120
  ...(validate ? ["--validate"] : [])], {
122
- cwd: d.cwd, env: { ...process.env }, detached: true, stdio: ["ignore", "ignore", "ignore", "ipc"], execArgv: [],
121
+ cwd: d.workspace, env: { ...process.env }, detached: true, stdio: ["ignore", "ignore", "ignore", "ipc"], execArgv: [],
123
122
  });
124
123
  }
125
124
 
@@ -127,13 +126,22 @@ export class AcpWorkerHost implements AgentHost {
127
126
  signal.throwIfAborted();
128
127
  const child = this.spawn(d, generation);
129
128
  await new Promise<void>((resolveResult, reject) => { child.once("spawn", resolveResult); child.once("error", reject); });
130
- requireThat(child.pid, "ACP worker 没有进程身份。");
131
- try { this.files.write(d.agentId, "acp-process.json", { generation, pid: child.pid, startedAt: Date.now() }, acpProcess); }
132
- catch (error) {
133
- try { process.kill(-child.pid, "SIGKILL"); } catch (failure) { if ((failure as NodeJS.ErrnoException).code !== "ESRCH") throw new AggregateError([error, failure], "ACP 启动与清理失败。"); }
129
+ const pid = child.pid;
130
+ requireThat(pid, "ACP worker 没有进程身份。");
131
+ try {
132
+ this.files.control(() => {
133
+ const w = this.files.worker(d.agentId);
134
+ if (w.generation === generation) {
135
+ w.pid = pid;
136
+ this.files.write(d.agentId, "worker.json", w, workerRecord);
137
+ }
138
+ });
139
+ } catch (error) {
140
+ try { process.kill(-pid, "SIGKILL"); } catch (failure) { if ((failure as NodeJS.ErrnoException).code !== "ESRCH") throw new AggregateError([error, failure], "ACP 启动与清理失败。"); }
134
141
  throw error;
135
142
  }
136
- if (child.connected) child.disconnect(); child.unref();
143
+ if (child.connected) child.disconnect();
144
+ child.unref();
137
145
  if (signal.aborted) { await this.release(d.agentId, generation); signal.throwIfAborted(); }
138
146
  }
139
147
 
@@ -153,11 +161,4 @@ export class AcpWorkerHost implements AgentHost {
153
161
  const current = this.process(id);
154
162
  if (current?.generation === generation && current.pid === record.pid) terminate("SIGKILL");
155
163
  }
156
-
157
- report(d: AgentDescriptor, _reference: AgentSessionReference, leaf: string) {
158
- requireThat(leaf.startsWith("acp:"), "ACP 报告引用无效。");
159
- const cycleId = fileId(leaf.slice(4)), report = this.files.read(d.agentId, join("reports", cycleId + ".json"), acpReport);
160
- requireThat(report.cycleId === cycleId, "ACP 报告周期不匹配。");
161
- return report.text;
162
- }
163
164
  }
@@ -26,7 +26,7 @@ export const claudeAcpHarness: AcpHarnessAdapter = {
26
26
  },
27
27
  async prepareLaunch(context) {
28
28
  const base = defaultPrepareLaunch(context);
29
- const claude = await claudeOptions(base.command, context.cwd, context.options.thinking, context.features?.skills !== false);
29
+ const claude = await claudeOptions(base.command, context.workspace, context.options.thinking, context.features?.skills !== false);
30
30
  return {
31
31
  ...base,
32
32
  ...(claude.thinking ? { defaultThinking: claude.thinking } : {}),
@@ -21,11 +21,11 @@ export async function readLocalRole(agent: WorkspaceRole, root: string): Promise
21
21
  export async function agentText(
22
22
  agent: WorkspaceRole,
23
23
  root: string,
24
- coordinatorPrompt = "plugin-coordinator.md",
24
+ coordinatorPrompt: string | null = "plugin-coordinator.md",
25
25
  ): Promise<string> {
26
26
  requireThat(agent === "coordinator" || agent === "general-purpose", "未知职责。");
27
27
  let text = await readFile(join(resourceRoot, "agents", agent + ".md"), "utf8");
28
- if (agent === "coordinator") {
28
+ if (agent === "coordinator" && coordinatorPrompt) {
29
29
  text += "\n\n" + await readFile(join(resourceRoot, "prompts", coordinatorPrompt), "utf8");
30
30
  }
31
31
  const local = await readLocalRole(agent, root);
@@ -37,14 +37,14 @@ export async function agentText(
37
37
  export function formatWorkspaceSkills(skills: readonly WorkspaceSkillMeta[]): string {
38
38
  if (!skills.length) return "";
39
39
  const lines = skills.map(skill => `- **${skill.name}**(\`${skill.path}\`):${skill.description}`);
40
- return "## 可用技能\n\n任务匹配时按需读取对应 `SKILL.md` 正文:\n" + lines.join("\n");
40
+ return "## 按需读取的技能\n\n" + lines.join("\n");
41
41
  }
42
42
 
43
43
  export async function loadWorkspaceContext(options: {
44
44
  host: HostId;
45
45
  root: string;
46
46
  role: WorkspaceRole;
47
- coordinatorPrompt?: string;
47
+ coordinatorPrompt?: string | null;
48
48
  includePrompts?: boolean;
49
49
  includeRootAgents?: boolean;
50
50
  localRoleOnly?: boolean;
@@ -71,7 +71,7 @@ export async function loadWorkspaceContext(options: {
71
71
  : ["", "", ""];
72
72
  const skillsSection = formatWorkspaceSkills(workspaceSkills);
73
73
  const noticesSection = notices.length
74
- ? "## 启动提示\n\n以下为工作区维护提醒,适时顺带告知用户即可,勿未经用户要求自行执行:\n" + notices.map(item => `- ${item}`).join("\n")
74
+ ? "## 维护提醒\n\n告知用户,按用户要求执行。\n\n" + notices.map(item => `- ${item}`).join("\n")
75
75
  : "";
76
76
  const environment = { host, workspaceRoot: root, resourceRoot };
77
77
  const text = [
@@ -98,7 +98,6 @@ export const antigravityAdapter: PluginHostAdapter = {
98
98
  host: "antigravity",
99
99
  nativeRootAgents: true,
100
100
  nativeWorkspaceSkills: true,
101
- coordinatorPrompt: "plugin-coordinator.md",
102
101
  initCommandHint: "/pbot init",
103
102
  usage: "用法:node <插件目录>/lib/plugin.js antigravity init|status",
104
103
  resolveRoot(cwd, rawPayload) {
@@ -3,7 +3,7 @@ import { requireThat } from "../../../common/validation.js";
3
3
  import type { HostEvent, PluginHostAdapter } from "../../../model/plugin-host.js";
4
4
  import { parsePromptEvent, pluginWorkspaceRoot, promptHooks } from "../prompt-hooks.js";
5
5
 
6
- const supportedEvents = ["UserPromptSubmit", "PreToolUse", "UserPromptExpansion", "Stop"];
6
+ const supportedEvents = ["SessionStart", "UserPromptSubmit", "PreToolUse", "UserPromptExpansion", "Stop"];
7
7
  const boundWorkspaceRoot = () => process.env.CLAUDE_PROJECT_DIR;
8
8
 
9
9
  export async function claudeWorkspaceRoot(cwd: string, projectDirectory = boundWorkspaceRoot()): Promise<string> {
@@ -14,7 +14,6 @@ export const claudeAdapter: PluginHostAdapter = {
14
14
  host: "claude",
15
15
  nativeRootAgents: false,
16
16
  nativeWorkspaceSkills: false,
17
- coordinatorPrompt: "plugin-coordinator.md",
18
17
  initCommandHint: "/personal-bot:pbot init",
19
18
  usage: "用法:node <插件目录>/lib/claude.js init|status",
20
19
  boundWorkspaceRoot,
@@ -17,7 +17,7 @@ export async function dshResources(
17
17
  root: string,
18
18
  role: "coordinator" | "general-purpose",
19
19
  check: () => void,
20
- coordinatorPrompt = "history-coordinator.md",
20
+ coordinatorPrompt: string | null = "history-coordinator.md",
21
21
  ) {
22
22
  const read = () => Promise.all([agentText(role, root, coordinatorPrompt), readFile(join(resourceRoot, "prompts/workspace.md"), "utf8")]);
23
23
  const [text, workspace] = await read();
@@ -9,7 +9,7 @@ import type { AgentDescriptor } from "../../../model/agent.js";
9
9
  import { requireThat } from "../../../common/validation.js";
10
10
 
11
11
  function validateHeader(d: AgentDescriptor, header: SessionHeader) {
12
- requireThat(header.id === d.agentId && header.cwd === d.cwd && header.parentSession === d.parentSessionId &&
12
+ requireThat(header.id === d.agentId && header.cwd === d.workspace && header.parentSession === d.parentSessionId &&
13
13
  header.origin === "subagent" && !header.isSeeded, "dsh 专家会话身份、父会话或工作目录不匹配。");
14
14
  }
15
15
 
@@ -50,7 +50,7 @@ export async function openDshAgent(ctx: Context, d: AgentDescriptor, parent: Age
50
50
  return resume
51
51
  ? ctx.agents.resume({ resumeSessionId: SessionId(d.agentId), parentAgent: parent, agentOptions, setup: compose, signal })
52
52
  : ctx.agents.create({ sessionId: SessionId(d.agentId), parentAgent: parent,
53
- meta: { cwd: d.cwd, parentSession: parent.id, origin: "subagent", delegationDepth: 1 },
53
+ meta: { cwd: d.workspace, parentSession: parent.id, origin: "subagent", delegationDepth: 1 },
54
54
  agentOptions, setup: compose, signal });
55
55
  }
56
56
 
@@ -18,12 +18,9 @@ export function parsePromptEvent(value: unknown): HostEvent {
18
18
  if (name !== "Stop" && name !== "UserPromptSubmit" && name !== "SessionStart") return { kind: "ignore" };
19
19
  if (typeof value.agent_id === "string") return { kind: "ignore" };
20
20
  requireThat(typeof value.cwd === "string", "插件 hook 缺少工作目录。");
21
- if (name === "Stop") return { kind: "record-history", cwd: value.cwd, raw: value };
22
- if (name === "SessionStart") {
23
- if (value.source === "resume" || value.source === "compact") return { kind: "ignore" };
24
- return { kind: "inject-context", role: "coordinator", isSessionStart: true, noticesOnly: true, cwd: value.cwd, raw: value };
25
- }
26
- return { kind: "inject-context", role: "coordinator", cwd: value.cwd, raw: value };
21
+ if (name !== "SessionStart") return { kind: "record-history", cwd: value.cwd, raw: value };
22
+ if (value.source === "resume" || value.source === "compact") return { kind: "ignore" };
23
+ return { kind: "inject-context", role: "coordinator", isSessionStart: true, cwd: value.cwd, raw: value };
27
24
  }
28
25
 
29
26
  export const promptHooks = {
@@ -10,8 +10,8 @@ import { requireThat } from "../../common/validation.js";
10
10
  import { packageVersion } from "../../common/version.js";
11
11
 
12
12
  /** Check exact installed manifests, never resolve dependencies in an ancestor workspace. */
13
- export async function minimumCliRelease(root: string, plugins: Record<string, string>): Promise<string | undefined> {
14
- const versions = Object.values(plugins);
13
+ export async function minimumCliRelease(root: string): Promise<string | undefined> {
14
+ const versions: string[] = [];
15
15
  if (process.env.PBOT_PLUGIN_VERSION) versions.push(process.env.PBOT_PLUGIN_VERSION);
16
16
  for (const prefix of ["", ".pi/npm"]) {
17
17
  const path = join(root, prefix, "node_modules/personal-bot/package.json");
@@ -10,20 +10,20 @@ export const claudeInstaller: HostInstaller = {
10
10
  return {
11
11
  host: this.host,
12
12
  state: context.explicit ? "failed" : "skipped",
13
- scope: "user",
13
+ scope: "project",
14
14
  detail: "未找到 Claude Code CLI(claude)。请先安装 Claude Code 后重试。",
15
15
  };
16
16
  }
17
17
  await context.run(
18
18
  claude,
19
- ["plugin", "install", "personal-bot", "--marketplace", claudeMarketplace, "--yes"],
19
+ ["plugin", "install", "personal-bot", "--marketplace", claudeMarketplace, "--scope", "project", "--yes"],
20
20
  context.workspace,
21
21
  );
22
22
  return {
23
23
  host: this.host,
24
24
  state: "installed",
25
- scope: "user",
26
- detail: `已通过 claude plugin install 从 ${claudeMarketplace} 安装 personal-bot。`,
25
+ scope: "project",
26
+ detail: `已通过 claude plugin install(project 作用域)从 ${claudeMarketplace} 安装 personal-bot。`,
27
27
  nextStep: "在 Claude Code 目标工作区执行 /personal-bot:pbot init 启用 Personal Bot。",
28
28
  };
29
29
  },
@@ -22,7 +22,7 @@ export const qoderInstaller: HostInstaller = {
22
22
  return {
23
23
  host: this.host,
24
24
  state: context.explicit ? "failed" : "skipped",
25
- scope: "user",
25
+ scope: "project",
26
26
  detail: "未找到 Qoder CLI(qodercli)。请先安装 Qoder CLI 后重试。",
27
27
  };
28
28
  }
@@ -32,17 +32,17 @@ export const qoderInstaller: HostInstaller = {
32
32
  return {
33
33
  host: this.host,
34
34
  state: "failed",
35
- scope: "user",
35
+ scope: "project",
36
36
  detail: `缺少 Qoder CLI 插件构建产物:${pluginDir}。请先运行 npm run build。`,
37
37
  };
38
38
  }
39
- await context.run(qodercli, ["plugin", "install", pluginDir], context.workspace);
39
+ await context.run(qodercli, ["plugin", "install", pluginDir, "--scope", "project"], context.workspace);
40
40
  return {
41
41
  host: this.host,
42
42
  state: "installed",
43
43
  version: bundledVersion,
44
- scope: "user",
45
- detail: `已通过 qodercli plugin install 安装 Qoder CLI 插件(${bundledVersion})。`,
44
+ scope: "project",
45
+ detail: `已通过 qodercli plugin install(project 作用域)安装 Qoder CLI 插件(${bundledVersion})。`,
46
46
  nextStep: "在目标工作区执行 pbot plugin qoder init 启用 Personal Bot。",
47
47
  };
48
48
  },
@@ -4,6 +4,11 @@ import { gte, lt, valid } from "semver";
4
4
  import { object } from "../../../common/json.js";
5
5
  import type { HostUpgradeContext, HostUpgradeResult, HostUpgrader } from "../../../model/installation.js";
6
6
 
7
+ interface AntigravityPluginEntry {
8
+ name: string;
9
+ version?: string;
10
+ }
11
+
7
12
  async function readManifestVersion(path: string): Promise<string | undefined> {
8
13
  try {
9
14
  const data: unknown = JSON.parse(await readFile(path, "utf8"));
@@ -14,15 +19,61 @@ async function readManifestVersion(path: string): Promise<string | undefined> {
14
19
  }
15
20
  }
16
21
 
22
+ function parsePluginList(raw: string): AntigravityPluginEntry[] {
23
+ const parsed: unknown = JSON.parse(raw);
24
+ const items = Array.isArray(parsed)
25
+ ? parsed
26
+ : object(parsed) && Array.isArray(parsed.plugins)
27
+ ? parsed.plugins
28
+ : [];
29
+ const entries: AntigravityPluginEntry[] = [];
30
+ for (const item of items) {
31
+ if (!object(item) || typeof item.name !== "string") continue;
32
+ entries.push({
33
+ name: item.name,
34
+ ...(typeof item.version === "string" ? { version: item.version } : {}),
35
+ });
36
+ }
37
+ return entries;
38
+ }
39
+
17
40
  export const antigravityUpgrader: HostUpgrader = {
18
41
  host: "antigravity",
19
42
  async upgrade(context: HostUpgradeContext): Promise<HostUpgradeResult> {
20
- if (context.currentVersion && valid(context.currentVersion) && gte(context.currentVersion, context.targetVersion)) {
43
+ const agy = context.env.PBOT_AGY_COMMAND || await context.findExecutable("agy");
44
+ if (!agy) {
45
+ return {
46
+ host: this.host,
47
+ state: "skipped",
48
+ detail: "未找到 Antigravity CLI(agy),已跳过。",
49
+ };
50
+ }
51
+ let entries: AntigravityPluginEntry[];
52
+ try {
53
+ const raw = await context.run(agy, ["plugin", "list", "--json"], context.workspace);
54
+ entries = parsePluginList(raw);
55
+ } catch (error) {
56
+ return {
57
+ host: this.host,
58
+ state: "failed",
59
+ detail: `查询 Antigravity 插件列表失败:${error instanceof Error ? error.message : String(error)}`,
60
+ };
61
+ }
62
+ const entry = entries.find(item => item.name === "personal-bot");
63
+ if (!entry) {
64
+ return {
65
+ host: this.host,
66
+ state: "skipped",
67
+ detail: "未在 Antigravity 插件列表中找到 personal-bot,已跳过。",
68
+ };
69
+ }
70
+ const installedVersion = entry.version;
71
+ if (installedVersion && valid(installedVersion) && gte(installedVersion, context.targetVersion)) {
21
72
  return {
22
73
  host: this.host,
23
74
  state: "up-to-date",
24
- previousVersion: context.currentVersion,
25
- version: context.currentVersion,
75
+ previousVersion: installedVersion,
76
+ version: installedVersion,
26
77
  scope: "user",
27
78
  detail: "已是最新版本。",
28
79
  };
@@ -33,7 +84,7 @@ export const antigravityUpgrader: HostUpgrader = {
33
84
  return {
34
85
  host: this.host,
35
86
  state: "skipped",
36
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
87
+ ...(installedVersion ? { previousVersion: installedVersion } : {}),
37
88
  detail: `缺少 Antigravity 插件构建产物:${pluginDir}`,
38
89
  };
39
90
  }
@@ -41,24 +92,15 @@ export const antigravityUpgrader: HostUpgrader = {
41
92
  return {
42
93
  host: this.host,
43
94
  state: "skipped",
44
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
95
+ ...(installedVersion ? { previousVersion: installedVersion } : {}),
45
96
  detail: `当前本地包产物版本为 ${bundledVersion},低于目标版本 ${context.targetVersion};请先更新全局 personal-bot 包。`,
46
97
  };
47
98
  }
48
- const agy = context.env.PBOT_AGY_COMMAND || await context.findExecutable("agy");
49
- if (!agy) {
50
- return {
51
- host: this.host,
52
- state: "skipped",
53
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
54
- detail: "未找到 Antigravity CLI(agy),已跳过。",
55
- };
56
- }
57
99
  await context.run(agy, ["plugin", "install", pluginDir], context.workspace);
58
100
  return {
59
101
  host: this.host,
60
102
  state: "updated",
61
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
103
+ ...(installedVersion ? { previousVersion: installedVersion } : {}),
62
104
  version: bundledVersion,
63
105
  scope: "user",
64
106
  detail: `已通过 agy plugin install 更新到 ${bundledVersion}。`,
@@ -61,7 +61,6 @@ export const claudeUpgrader: HostUpgrader = {
61
61
  return {
62
62
  host: this.host,
63
63
  state: "skipped",
64
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
65
64
  detail: "未找到 Claude Code CLI(claude),已跳过。",
66
65
  };
67
66
  }
@@ -73,7 +72,6 @@ export const claudeUpgrader: HostUpgrader = {
73
72
  return {
74
73
  host: this.host,
75
74
  state: "failed",
76
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
77
75
  detail: `查询 Claude 插件列表失败:${error instanceof Error ? error.message : String(error)}`,
78
76
  };
79
77
  }
@@ -82,11 +80,10 @@ export const claudeUpgrader: HostUpgrader = {
82
80
  return {
83
81
  host: this.host,
84
82
  state: "skipped",
85
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
86
83
  detail: "未在 Claude 插件列表中找到 personal-bot(可能通过 --plugin-dir 本地加载),已跳过。",
87
84
  };
88
85
  }
89
- const installedVersion = entry.version ?? context.currentVersion;
86
+ const installedVersion = entry.version;
90
87
  const scope = entry.scope ?? "user";
91
88
  if (installedVersion && valid(installedVersion) && gte(installedVersion, context.targetVersion)) {
92
89
  return {