personal-bot 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +2 -2
  3. package/README.md +4 -1
  4. package/README.zh-CN.md +4 -1
  5. package/docs/README.md +2 -3
  6. package/docs/architecture/design.md +41 -2
  7. package/docs/architecture/extensibility.md +3 -3
  8. package/docs/architecture/model-context.md +10 -4
  9. package/docs/architecture/principles.md +2 -2
  10. package/docs/guides/cross-harness-workers.md +27 -2
  11. package/docs/guides/workspace-configuration.md +3 -1
  12. package/docs/hosts/claude-code.md +1 -1
  13. package/docs/hosts/codex-qoder.md +3 -1
  14. package/hooks/hooks.json +3 -0
  15. package/lib/antigravity-plugin/lib/extension/acp-worker.js +22 -6
  16. package/lib/antigravity-plugin/lib/extension/cli.js +169 -95
  17. package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +3 -1
  18. package/lib/antigravity-plugin/lib/extension/mcp.js +163 -119
  19. package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +4 -2
  20. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +23 -5
  21. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.js +0 -1
  22. package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +1 -2
  23. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.d.ts +2 -1
  24. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.js +12 -13
  25. package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.js +4 -7
  26. package/lib/antigravity-plugin/lib/model/worker-template.d.ts +21 -0
  27. package/lib/antigravity-plugin/lib/model/worker-template.js +1 -0
  28. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.js +1 -1
  29. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.js +6 -3
  30. package/lib/antigravity-plugin/lib/services/history/summary-runner.js +3 -3
  31. package/lib/antigravity-plugin/lib/services/workspace/worker-templates.d.ts +17 -0
  32. package/lib/antigravity-plugin/lib/services/workspace/worker-templates.js +88 -0
  33. package/lib/antigravity-plugin/lib/storage/history-files.js +3 -2
  34. package/lib/antigravity-plugin/package.json +1 -1
  35. package/lib/antigravity-plugin/plugin.json +2 -2
  36. package/lib/antigravity-plugin/resources/agents/coordinator.md +2 -4
  37. package/lib/antigravity-plugin/resources/agents/general-purpose.md +2 -4
  38. package/lib/antigravity-plugin/resources/prompts/history-monthly-summary.md +6 -11
  39. package/lib/antigravity-plugin/resources/prompts/history-summary.md +6 -11
  40. package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -1
  41. package/lib/antigravity-plugin/resources/prompts/workspace.md +16 -23
  42. package/lib/antigravity-plugin/resources/skills/project-maintenance/SKILL.md +14 -21
  43. package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +23 -36
  44. package/lib/antigravity-plugin/resources/templates/workspace-agents.md +5 -13
  45. package/lib/antigravity-plugin/skills/pbot/SKILL.md +6 -23
  46. package/lib/antigravity-plugin/skills/project-maintenance/SKILL.md +14 -21
  47. package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +23 -36
  48. package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +2 -2
  49. package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +2 -2
  50. package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +3 -3
  51. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +11 -3
  52. package/lib/extension/acp-worker.js +22 -6
  53. package/lib/extension/cli.js +169 -95
  54. package/lib/extension/hosts/dsh/command.js +1 -1
  55. package/lib/extension/hosts/dsh/workspace.js +5 -2
  56. package/lib/extension/hosts/plugin-runtime.js +3 -1
  57. package/lib/extension/mcp/tool-contract.d.ts +3 -3
  58. package/lib/extension/mcp/tool-contract.js +63 -101
  59. package/lib/extension/mcp/workers.d.ts +1 -1
  60. package/lib/extension/mcp/workers.js +19 -13
  61. package/lib/extension/mcp.js +163 -119
  62. package/lib/integrations/agent-resources.d.ts +4 -2
  63. package/lib/integrations/agent-resources.js +23 -5
  64. package/lib/integrations/hosts/antigravity/adapter.js +0 -1
  65. package/lib/integrations/hosts/claude/adapter.js +1 -2
  66. package/lib/integrations/hosts/dsh/resources.d.ts +2 -1
  67. package/lib/integrations/hosts/dsh/resources.js +12 -13
  68. package/lib/integrations/hosts/prompt-hooks.js +4 -7
  69. package/lib/model/worker-template.d.ts +21 -0
  70. package/lib/model/worker-template.js +1 -0
  71. package/lib/qoder-plugin/.mcp.json +2 -2
  72. package/lib/qoder-plugin/.qoder-plugin/plugin.json +2 -2
  73. package/lib/qoder-plugin/hooks/hooks.json +3 -3
  74. package/lib/qoder-plugin/skills/pbot/SKILL.md +11 -3
  75. package/lib/services/agents/agent-service.js +2 -2
  76. package/lib/services/history/summary-dimensions/monthly.js +1 -1
  77. package/lib/services/history/summary-dimensions/session.js +6 -3
  78. package/lib/services/history/summary-runner.js +3 -3
  79. package/lib/services/workspace/worker-templates.d.ts +17 -0
  80. package/lib/services/workspace/worker-templates.js +88 -0
  81. package/lib/storage/history-files.js +3 -2
  82. package/lib/tools/history/contract.d.ts +1 -1
  83. package/lib/tools/history/contract.js +14 -16
  84. package/package.json +2 -2
  85. package/resources/agents/coordinator.md +2 -4
  86. package/resources/agents/general-purpose.md +2 -4
  87. package/resources/antigravity/skills/pbot/SKILL.md +6 -23
  88. package/resources/claude/skills/pbot/SKILL.md +6 -23
  89. package/resources/plugin/skills/pbot/SKILL.md +11 -3
  90. package/resources/prompts/history-coordinator.md +1 -1
  91. package/resources/prompts/history-monthly-summary.md +6 -11
  92. package/resources/prompts/history-summary.md +6 -11
  93. package/resources/prompts/plugin-coordinator.md +1 -1
  94. package/resources/prompts/workspace.md +16 -23
  95. package/resources/skills/project-maintenance/SKILL.md +14 -21
  96. package/resources/skills/provider-connections/SKILL.md +23 -36
  97. package/resources/templates/workspace-agents.md +5 -13
  98. package/src/extension/cli/commands/mcp.ts +1 -1
  99. package/src/extension/hosts/dsh/command.ts +1 -1
  100. package/src/extension/hosts/dsh/workspace.ts +5 -1
  101. package/src/extension/hosts/pi/command.ts +1 -1
  102. package/src/extension/hosts/pi/events.ts +3 -1
  103. package/src/extension/hosts/plugin-runtime.ts +3 -1
  104. package/src/extension/mcp/tool-contract.ts +63 -103
  105. package/src/extension/mcp/workers.ts +21 -14
  106. package/src/integrations/agent-resources.ts +27 -7
  107. package/src/integrations/hosts/antigravity/adapter.ts +0 -1
  108. package/src/integrations/hosts/claude/adapter.ts +1 -2
  109. package/src/integrations/hosts/dsh/resources.ts +14 -13
  110. package/src/integrations/hosts/prompt-hooks.ts +3 -6
  111. package/src/model/worker-template.ts +24 -0
  112. package/src/pbot.ts +2 -2
  113. package/src/services/agents/agent-service.ts +2 -2
  114. package/src/services/history/summary-dimensions/monthly.ts +1 -1
  115. package/src/services/history/summary-dimensions/session.ts +6 -3
  116. package/src/services/history/summary-runner.ts +3 -3
  117. package/src/services/workspace/worker-templates.ts +80 -0
  118. package/src/storage/history-files.ts +3 -2
  119. package/src/tools/history/contract.ts +14 -16
  120. package/docs/architecture/model-instruction-guidelines.md +0 -34
@@ -6,7 +6,7 @@ import { acpElicitationActions, type AcpCommands } from "../../model/acp.js";
6
6
 
7
7
  export const defaultWaitMs = 50_000;
8
8
  export const maxWaitMs = 600_000;
9
- export const discoverTargets = ["overview", "workers", "backends", "models"] as const;
9
+ export const discoverTargets = ["overview", "workers", "backends", "models", "templates"] as const;
10
10
 
11
11
  function formatBackendItem(entry: ReturnType<typeof inspectAcpBackends>[number], defaultBackend?: string): string {
12
12
  const tags: string[] = [];
@@ -15,42 +15,34 @@ function formatBackendItem(entry: ReturnType<typeof inspectAcpBackends>[number],
15
15
  return tags.length ? `${entry.backend}(${tags.join(",")})` : entry.backend;
16
16
  }
17
17
 
18
- function summarizeBackends(commands: AcpCommands = {}, defaultBackend?: string) {
19
- const entries = inspectAcpBackends(commands);
20
- const available = entries.filter(item => item.available);
21
- const unavailable = entries.filter(item => !item.available);
22
- const availableText = available.map(item => formatBackendItem(item, defaultBackend)).join("、");
23
- const unavailableText = unavailable.map(item => formatBackendItem(item, defaultBackend)).join("、");
24
- const overview = available.length
25
- ? unavailable.length
26
- ? `当前可用助手:${availableText};暂不可用:${unavailableText}。`
27
- : `当前可用助手:${availableText}。`
28
- : `当前无可用外部助手(暂不可用:${unavailableText})。`;
29
- const availableIds = available.map(item => item.backend).join("、");
30
- return { overview, availableIds };
31
- }
32
-
33
18
  function workspaceProperty(workspaceBound: boolean) {
34
19
  return {
35
20
  type: "string",
36
21
  description: workspaceBound
37
- ? "工作区根目录绝对路径;默认当前工作区,通常省略。"
38
- : "目标工作区根目录绝对路径;请传入环境中的 workspaceRoot。",
22
+ ? "工作区根目录的绝对路径,默认当前绑定的工作区。"
23
+ : "传目标工作区的绝对路径(workspaceRoot)。省略时使用服务的当前目录。",
39
24
  };
40
25
  }
41
26
 
42
27
  export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?: string, workspaceBound = false) {
43
- const { overview, availableIds } = summarizeBackends(commands, defaultBackend);
44
- const modelsBackendHint = defaultBackend
45
- ? `省略时默认查 ${defaultBackend}`
46
- : "必填";
28
+ const available = inspectAcpBackends(commands).filter(item => item.available);
29
+ const overview = available.length
30
+ ? "可用助手:" + available.map(item => formatBackendItem(item, defaultBackend)).join("、") + "。"
31
+ : "当前没有可用助手。用 worker_discover 的 backends 查看接入状态。";
47
32
  const workspace = workspaceProperty(workspaceBound);
33
+ const workerId = { type: "string", description: "助手会话 ID。" };
34
+ const waitMs = {
35
+ type: "integer",
36
+ minimum: 0,
37
+ maximum: maxWaitMs,
38
+ description: `等待本轮结果的毫秒数,默认 ${defaultWaitMs}。0 表示不等待结果。`,
39
+ };
48
40
 
49
41
  return [
50
42
  {
51
43
  name: "worker_create" as const,
52
44
  description:
53
- "启动独立的外部助手会话并返回 workerId(不发送任务,随后用 worker_request 派发)。未指定其他助手或特定模型时,优先自行完成或使用当前内置子代理。\n" +
45
+ "新建独立助手会话,返回 workerId。用 worker_request 发送首个任务。\n" +
54
46
  overview,
55
47
  annotations: {
56
48
  title: "Create Worker",
@@ -66,15 +58,15 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
66
58
  properties: {
67
59
  backend: {
68
60
  type: "string",
69
- description: "目标外部助手标识(不区分大小写,支持常见别名如 claude-code、agy)。",
61
+ description: "助手标识或别名,如 claude-code、agy。",
70
62
  },
71
63
  model: {
72
64
  type: "string",
73
- description: "目标模型(模型 ID、显示名或 provider/model,不区分大小写);未明确指定时省略以用默认模型,不确定可选值时先查 worker_discover(target=\"models\")。",
65
+ description: "模型 ID、显示名或 provider/model。未指定模型时省略,使用助手默认模型。",
74
66
  },
75
67
  thinking: {
76
68
  type: "string",
77
- description: "思考深度(如 low / medium / high / xhigh / max,不区分大小写);未明确指定时省略以用默认设置。",
69
+ description: "思考深度,如 high。未指定时省略,使用助手默认设置。",
78
70
  },
79
71
  workspace,
80
72
  },
@@ -83,7 +75,7 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
83
75
  {
84
76
  name: "worker_close" as const,
85
77
  description:
86
- "结束外部助手会话并释放进程。若该会话支持恢复(capabilities.resume),后续仍可直接用 worker_request 续接。",
78
+ "任务结束后关闭助手。提前关闭会中断执行。创建结果中 resume 为 true 时,可用原 workerId 续接。",
87
79
  annotations: {
88
80
  title: "Close Worker",
89
81
  readOnlyHint: false,
@@ -96,18 +88,14 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
96
88
  additionalProperties: false,
97
89
  required: ["workerId"],
98
90
  properties: {
99
- workerId: {
100
- type: "string",
101
- description: "助手会话 ID(来自 worker_create 或 worker_discover)。",
102
- },
91
+ workerId,
103
92
  },
104
93
  },
105
94
  },
106
95
  {
107
96
  name: "worker_request" as const,
108
97
  description:
109
- "向外部助手派发任务或在同一上下文中追问(已关闭且支持恢复的会话会自动续接)。" +
110
- `默认最多等待 ${defaultWaitMs / 1000} 秒(waitMs 设为 0 可立即转后台并行);返回 timedOut 或 nextOffset 用 worker_output,返回 needsResponse 先向用户确认再用 worker_response。`,
98
+ "向助手派发任务或在同一会话追问。后台结果用 worker_output 收取。",
111
99
  annotations: {
112
100
  title: "Send Request to Worker",
113
101
  readOnlyHint: false,
@@ -120,28 +108,19 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
120
108
  additionalProperties: false,
121
109
  required: ["workerId", "message"],
122
110
  properties: {
123
- workerId: {
124
- type: "string",
125
- description: "助手会话 ID(来自 worker_create 或 worker_discover)。",
126
- },
111
+ workerId,
127
112
  message: {
128
113
  type: "string",
129
- description: "任务说明或追问内容。外部助手看不到当前会话历史,首次派发需写清背景、目标、相关文件路径、约束和期望产出。",
130
- },
131
- waitMs: {
132
- type: "integer",
133
- minimum: 0,
134
- maximum: maxWaitMs,
135
- description: `最多等待毫秒数(默认 ${defaultWaitMs});0 表示立即返回转后台执行。`,
114
+ description: "任务或追问。助手看不到主会话历史,首次派发时写明背景、目标、文件路径、约束和交付要求。",
136
115
  },
116
+ waitMs,
137
117
  },
138
118
  },
139
119
  },
140
120
  {
141
121
  name: "worker_response" as const,
142
122
  description:
143
- "回复外部助手暂停时发出的待处理请求(needsResponse: true),支持操作授权、表单问答与链接确认。" +
144
- `提交前先向用户确认;提交后默认等待最多 ${defaultWaitMs / 1000} 秒返回后续结果。`,
123
+ "收到 needsResponse 时,将权限选项、表单问题或链接交给用户确认,再提交用户的决定。",
145
124
  annotations: {
146
125
  title: "Respond to Worker Request",
147
126
  readOnlyHint: false,
@@ -154,41 +133,33 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
154
133
  additionalProperties: false,
155
134
  required: ["workerId", "action"],
156
135
  properties: {
157
- workerId: {
158
- type: "string",
159
- description: "等待回复的助手会话 ID。",
160
- },
136
+ workerId,
161
137
  action: {
162
138
  type: "string",
163
139
  enum: [...acpElicitationActions],
164
- description: "accept 同意/提交表单/确认链接;decline 拒绝;cancel 取消请求。",
140
+ description: "accept 同意或提交答案,decline 拒绝,cancel 取消请求。",
165
141
  },
166
142
  requestId: {
167
143
  type: "string",
168
- description: "请求 ID(pendingRequests[].requestId);仅一条待处理请求时可省略,多条时必填。",
144
+ description: "待回复的请求 ID。仅有一条待处理请求时可省略。",
169
145
  },
170
146
  optionId: {
171
147
  type: "string",
172
- description: "仅 permission 请求且 action≠cancel 时可用:指定 pendingRequests[].options[].optionId,省略则按 action 单次允许或拒绝。",
148
+ description: "允许或拒绝操作时填用户所选权限的 ID。省略时优先单次,缺少单次选项时可能采用长期选项。",
173
149
  },
174
150
  content: {
175
151
  type: "object",
176
152
  additionalProperties: true,
177
- description: "仅 form 请求且 action=\"accept\" 时可用:按 pendingRequests[].schema.properties 填写回答对象(值为字符串、数字、布尔值或字符串数组)。",
178
- },
179
- waitMs: {
180
- type: "integer",
181
- minimum: 0,
182
- maximum: maxWaitMs,
183
- description: `提交后最多等待毫秒数(默认 ${defaultWaitMs});0 表示立即返回。`,
153
+ description: "接受表单时,按表单字段填写答案。值可为字符串、数字、布尔值或字符串数组。",
184
154
  },
155
+ waitMs,
185
156
  },
186
157
  },
187
158
  },
188
159
  {
189
160
  name: "worker_output" as const,
190
161
  description:
191
- "获取或等待外部助手的最新结果,用于收取后台产出、timedOut 后继续等待,或按 nextOffset 分页续读。任务已结束时立即返回,运行中最多等待 waitMs。",
162
+ "读取助手最近一轮的结果。后台执行或返回 timedOut 时,用原 workerId 继续等待。",
192
163
  annotations: {
193
164
  title: "Get Worker Output",
194
165
  readOnlyHint: true,
@@ -201,30 +172,21 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
201
172
  additionalProperties: false,
202
173
  required: ["workerId"],
203
174
  properties: {
204
- workerId: {
205
- type: "string",
206
- description: "助手会话 ID。",
207
- },
175
+ workerId,
208
176
  offset: {
209
177
  type: "integer",
210
178
  minimum: 0,
211
- description: "读取起始位置(默认 0);翻页续读时传上次返回的 nextOffset。",
212
- },
213
- waitMs: {
214
- type: "integer",
215
- minimum: 0,
216
- maximum: maxWaitMs,
217
- description: `运行中最多等待毫秒数(默认 ${defaultWaitMs});已结束或翻页时立即返回。`,
179
+ description: "续读传上页的 nextOffset,默认从 0 开始。",
218
180
  },
181
+ waitMs,
219
182
  },
220
183
  },
221
184
  },
222
185
  {
223
186
  name: "worker_discover" as const,
224
- description:
225
- "查询可用外部助手、已有会话状态,或某个助手支持的模型与思考深度。默认(overview)返回可用助手与已有会话;仅需核对模型或思考深度可选值时再查 models(需启动探测,耗时较长)。",
187
+ description: "查找可用助手、模板或已有会话。查询模型会临时启动所选助手。",
226
188
  annotations: {
227
- title: "Discover Workers, Backends & Models",
189
+ title: "Discover Workers, Templates, Backends & Models",
228
190
  readOnlyHint: true,
229
191
  destructiveHint: false,
230
192
  idempotentHint: true,
@@ -238,21 +200,19 @@ export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?
238
200
  target: {
239
201
  type: "string",
240
202
  enum: [...discoverTargets],
241
- description: "overview(默认,可用助手与已有会话)、workers(全部或单个会话状态)、backends(可用助手)、models(指定助手的模型与思考深度)。",
203
+ description: "overview(默认)列助手和本会话的 worker,workers 查会话状态,backends 查可用助手,models 查模型与思考深度。templates 列出工作区的助手模板,选中模板的 create 可直接传给 worker_create。",
242
204
  },
243
205
  workerId: {
244
206
  type: "string",
245
- description: "仅 target=\"workers\" 可用:指定单个会话 ID,省略列全部。",
207
+ description: "查 workers 时可指定单个会话,省略列出全部所属会话。",
246
208
  },
247
209
  backend: {
248
210
  type: "string",
249
- description: availableIds
250
- ? `仅 target="models" 可用(${modelsBackendHint}):目标助手标识,支持别名;当前可用:${availableIds}。`
251
- : `仅 target="models" 可用(${modelsBackendHint}):目标助手标识,支持别名。`,
211
+ description: defaultBackend ? `查 models 时选择助手,默认 ${defaultBackend}。` : "查 models 时必填助手标识。",
252
212
  },
253
213
  model: {
254
214
  type: "string",
255
- description: "仅 target=\"models\" 可用:指定模型以查看其支持的思考深度选项。",
215
+ description: "查 models 时可指定模型以查看它支持的思考深度。",
256
216
  },
257
217
  workspace,
258
218
  },
@@ -267,7 +227,7 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
267
227
  {
268
228
  name: "workspace_mcp_discover" as const,
269
229
  description:
270
- "查询当前工作区共享 MCP 服务(.pbot/mcp.json)。省略 server 列出服务;传入 server 返回其工具列表与参数说明。",
230
+ "查找工作区共享的 MCP 服务,以及服务提供的工具和参数。",
271
231
  annotations: {
272
232
  title: "Discover Workspace MCP Servers & Tools",
273
233
  readOnlyHint: true,
@@ -282,7 +242,7 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
282
242
  properties: {
283
243
  server: {
284
244
  type: "string",
285
- description: "服务名称;省略列出工作区全部已配置服务。",
245
+ description: "填服务名列出其工具,省略则列出已配置的服务。",
286
246
  },
287
247
  workspace,
288
248
  },
@@ -291,11 +251,11 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
291
251
  {
292
252
  name: "workspace_mcp_call" as const,
293
253
  description:
294
- "调用工作区共享 MCP 服务中的指定工具。不确定工具名或参数时先用 workspace_mcp_discover(server) 查询。",
254
+ "执行工作区共享 MCP 服务的工具,读写效果取决于所选工具。工具名和参数可用 workspace_mcp_discover 查询。",
295
255
  annotations: {
296
256
  title: "Call Workspace MCP Tool",
297
257
  readOnlyHint: false,
298
- destructiveHint: false,
258
+ destructiveHint: true,
299
259
  idempotentHint: false,
300
260
  openWorldHint: true,
301
261
  },
@@ -306,16 +266,16 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
306
266
  properties: {
307
267
  server: {
308
268
  type: "string",
309
- description: "服务名称(来自 workspace_mcp_discover)。",
269
+ description: "工作区中登记的服务名。",
310
270
  },
311
271
  tool: {
312
272
  type: "string",
313
- description: "工具名称。",
273
+ description: "该服务提供的工具名。",
314
274
  },
315
275
  arguments: {
316
276
  type: "object",
317
277
  additionalProperties: true,
318
- description: "传给目标工具的参数对象,默认空对象。",
278
+ description: "按所选工具的参数定义填写,默认 {}。",
319
279
  },
320
280
  workspace,
321
281
  },
@@ -330,7 +290,7 @@ export function buildHistoryMcpTools(workspaceBound = false) {
330
290
  {
331
291
  name: "history_search" as const,
332
292
  description:
333
- "搜索当前工作区跨宿主历史问答与摘要归档(不含工具调用日志)。省略 query 列出各会话或指定维度摘要;传入 query 按不区分大小写的连续关键词匹配。",
293
+ "查找工作区各宿主归档的问答或摘要。用命中项的 id 调用 history_read 可读全文。",
334
294
  annotations: {
335
295
  title: "Search Workspace History",
336
296
  readOnlyHint: true,
@@ -345,38 +305,38 @@ export function buildHistoryMcpTools(workspaceBound = false) {
345
305
  properties: {
346
306
  host: {
347
307
  type: "string",
348
- description: "来源宿主筛选(如 pi、dsh、claude、antigravity、codex、qoder);省略查全部。",
308
+ description: "按来源宿主筛选,如 pi 或 claude。默认查全部来源。",
349
309
  },
350
310
  dimension: {
351
311
  type: "string",
352
- description: "范围筛选:raw 仅原文,或指定摘要维度(如 monthly、session);省略查全部。",
312
+ description: "raw 为原始问答,session、monthly 等为摘要维度。关键词搜索默认查全部。",
353
313
  },
354
314
  query: {
355
315
  type: "string",
356
- description: "连续关键词(不区分大小写);省略列会话或指定维度摘要。",
316
+ description: "匹配连续文本,忽略大小写。省略时列会话,指定摘要维度则列该维度的摘要。",
357
317
  },
358
318
  sessionId: {
359
319
  type: "string",
360
- description: "限定在指定原始会话 ID 内搜索。",
320
+ description: "按原始会话 ID 筛选。",
361
321
  },
362
322
  from: {
363
323
  type: "string",
364
- description: "ISO 日期或时间下界。",
324
+ description: "时间区间起点(含),用 ISO 日期或时间。",
365
325
  },
366
326
  to: {
367
327
  type: "string",
368
- description: "ISO 日期或时间上界。",
328
+ description: "时间区间终点(含),仅填 ISO 日期表示该日 UTC 零点。",
369
329
  },
370
330
  offset: {
371
331
  type: "integer",
372
332
  minimum: 0,
373
- description: "结果偏移,默认 0。",
333
+ description: "结果起点,默认 0。翻页传上页的 nextOffset。",
374
334
  },
375
335
  limit: {
376
336
  type: "integer",
377
337
  minimum: 1,
378
338
  maximum: historyPageLimits.search.max,
379
- description: `返回条数(1–${historyPageLimits.search.max}),默认 ${historyPageLimits.search.default}。`,
339
+ description: `每页条数,默认 ${historyPageLimits.search.default}。`,
380
340
  },
381
341
  workspace,
382
342
  },
@@ -385,7 +345,7 @@ export function buildHistoryMcpTools(workspaceBound = false) {
385
345
  {
386
346
  name: "history_read" as const,
387
347
  description:
388
- "按节点 id 读取历史正文与上下级(可从 monthly 汇总下钻至 session 摘要和 exchange 原文)。正文分页传 nextOffset,子节点分页传 nextChildrenOffset。",
348
+ "读取历史节点的正文和上下级。沿子节点可从月度汇总找到会话摘要和原始问答。",
389
349
  annotations: {
390
350
  title: "Read Workspace History Node",
391
351
  readOnlyHint: true,
@@ -400,27 +360,27 @@ export function buildHistoryMcpTools(workspaceBound = false) {
400
360
  properties: {
401
361
  id: {
402
362
  type: "string",
403
- description: "节点 id(来自 history_search 或上下级)。",
363
+ description: "搜索结果、父节点或子节点的 id。",
404
364
  },
405
365
  host: {
406
366
  type: "string",
407
- description: "跨宿主 id 冲突时指定来源宿主。",
367
+ description: "节点 id 重名时填来源宿主。",
408
368
  },
409
369
  offset: {
410
370
  type: "integer",
411
371
  minimum: 0,
412
- description: "正文字符偏移,默认 0;续读传上次 nextOffset。",
372
+ description: "正文字符偏移,默认 0。续读传上页的 nextOffset。",
413
373
  },
414
374
  limit: {
415
375
  type: "integer",
416
376
  minimum: 1,
417
377
  maximum: historyPageLimits.read.max,
418
- description: `正文字符数(1–${historyPageLimits.read.max}),默认 ${historyPageLimits.read.default}。`,
378
+ description: `每页正文字符数,默认 ${historyPageLimits.read.default}。`,
419
379
  },
420
380
  childrenOffset: {
421
381
  type: "integer",
422
382
  minimum: 0,
423
- description: "子节点偏移,默认 0;续读传上次 nextChildrenOffset。",
383
+ description: "子节点起点,默认 0。翻页传上页的 nextChildrenOffset。",
424
384
  },
425
385
  workspace,
426
386
  },
@@ -28,6 +28,7 @@ import type { AgentCycle, AgentOwner, AgentView } from "../../model/agent.js";
28
28
  import { AgentService } from "../../services/agents/agent-service.js";
29
29
  import { readWorkspaceHistory, searchWorkspaceHistory } from "../../services/history/history-query.js";
30
30
  import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../services/workspace/workspace-config.js";
31
+ import { discoverWorkerTemplates } from "../../services/workspace/worker-templates.js";
31
32
  import { WorkspaceMcpBridge } from "./bridge.js";
32
33
 
33
34
  export { buildHistoryMcpTools, buildPbotWorkerTools, buildWorkspaceMcpTools, pbotWorkerTools } from "./tool-contract.js";
@@ -40,21 +41,19 @@ const progressIntervalMs = 5_000;
40
41
  export type ProgressReporter = (message: string) => void;
41
42
 
42
43
  const workerCapabilityInstruction =
43
- "跨助手委派(worker_*):启动并调度其他外部助手在当前工作区独立执行任务;无需外部助手时优先自行完成或使用内置子代理。" +
44
- "流程:worker_create 启动(或 worker_discover 复用)→ worker_request 派发/追问 → 完成后 worker_close;" +
45
- "后台取结果、超时续等(timedOut)或翻页(nextOffset)用 worker_output;返回 needsResponse 时先向用户确认,再用 worker_response 回复。";
44
+ "可查询工作区的助手模板,也可按用户要求或工作区分工委派给指定助手或模型。常规任务优先自行处理或使用宿主内置子代理。";
46
45
 
47
46
  const workspaceMcpCapabilityInstruction =
48
- "工作区共享 MCP(workspace_mcp_*):先用 workspace_mcp_discover 查 .pbot/mcp.json 中的服务与工具,再用 workspace_mcp_call 调用。";
47
+ "可调用本工作区 .pbot/mcp.json 中登记的 MCP 工具。";
49
48
 
50
49
  const historyCapabilityInstruction =
51
- "跨宿主历史(history_search / history_read):只读检索当前工作区跨宿主记录的历史问答与摘要归档。";
50
+ "可检索本工作区各宿主归档的问答和摘要。";
52
51
 
53
52
  export function buildMcpInstructions(options: { workspaceMcp: boolean; history: boolean }): string {
54
53
  const parts = [workerCapabilityInstruction];
55
54
  if (options.workspaceMcp) parts.push(workspaceMcpCapabilityInstruction);
56
55
  if (options.history) parts.push(historyCapabilityInstruction);
57
- return parts.length === 1 ? parts[0]! : parts.map((text, index) => `${index + 1}. ${text}`).join("\n");
56
+ return parts.join("\n");
58
57
  }
59
58
 
60
59
  export const mcpWorkerOnlyInstructions = buildMcpInstructions({ workspaceMcp: false, history: false });
@@ -63,7 +62,7 @@ export const mcpInstructions = buildMcpInstructions({ workspaceMcp: true, histor
63
62
 
64
63
  export function defaultWorkerDirectory(workspaceRoot: string): string {
65
64
  if (process.env.PBOT_MCP_AGENT_DIR) return process.env.PBOT_MCP_AGENT_DIR;
66
- return join(workspaceRoot, ".pbot", "subagents");
65
+ return join(workspaceRoot, ".pbot", "worker", "runtime");
67
66
  }
68
67
 
69
68
  function workerCommandTool(name: string): McpWorkerToolName | undefined {
@@ -391,17 +390,20 @@ export class McpWorkerRuntime {
391
390
  const { name, args: rawArgs } = parseMcpToolCall(toolName, input);
392
391
  requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
393
392
  const isWorkerScoped = name === "worker_close" || name === "worker_request" || name === "worker_response" || name === "worker_output";
393
+ const isTemplateQuery = name === "worker_discover" && rawArgs.target === "templates";
394
394
  const root = isWorkerScoped
395
395
  ? await this.resolveWorkerWorkspace(asString(rawArgs, "workerId", true)!, defaultWorkspace)
396
- : await this.resolveWorkspace(asString(rawArgs, "workspace") ?? defaultWorkspace);
396
+ : await this.resolveWorkspace(asString(rawArgs, "workspace", isTemplateQuery && rawArgs.workspace !== undefined) ?? defaultWorkspace);
397
397
  const configuration = await readWorkspaceConfig(root);
398
398
  requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
399
- requireThat(configuration.enabled, workspaceDisabledMessage(configuration));
399
+ requireThat(configuration.enabled, isTemplateQuery
400
+ ? `无法在工作区 ${root} 查询助手模板。`
401
+ : workspaceDisabledMessage(configuration));
400
402
 
401
403
  switch (name) {
402
404
  case "workspace_mcp_discover":
403
405
  case "workspace_mcp_call": {
404
- requireThat(!this.#nativeWorkspaceMcp, "当前宿主已原生挂载工作区 .pbot/mcp.json 服务,请直接调用对应原生 MCP 工具,勿重复经由 workspace_mcp_* 桥接。");
406
+ requireThat(!this.#nativeWorkspaceMcp, "当前宿主已原生挂载工作区 MCP 服务,请直接调用对应工具。");
405
407
  requireThat(workspaceFeatures(configuration).mcp, `工作区统一 MCP 功能已在 ${configuration.path} 中停用(features.mcp: false)。`);
406
408
  if (name === "workspace_mcp_discover") return this.#bridge.discover(root, asString(rawArgs, "server"));
407
409
  const server = asString(rawArgs, "server", true)!;
@@ -447,6 +449,12 @@ export class McpWorkerRuntime {
447
449
  }
448
450
  }
449
451
 
452
+ if (isTemplateQuery) {
453
+ const extra = Object.keys(rawArgs).find(key => key !== "target" && key !== "workspace");
454
+ requireThat(extra === undefined, `查询模板只接受 target 和 workspace,收到参数 ${extra}。`);
455
+ return discoverWorkerTemplates(root);
456
+ }
457
+
450
458
  const { host, service, owner } = this.workerService(root, configuration.acp);
451
459
  switch (name) {
452
460
  case "worker_create": {
@@ -515,10 +523,9 @@ export class McpWorkerRuntime {
515
523
  return this.waitFor(service, owner, workerId, undefined, waitMs, offset, progress);
516
524
  }
517
525
  case "worker_discover": {
518
- const rawTarget = asString(rawArgs, "target") ?? "overview";
519
- requireThat(isOneOf(rawTarget, discoverTargets),
520
- `参数 target 无效:${rawTarget}(可用:${discoverTargets.join(", ")})。`);
521
- const target = rawTarget;
526
+ const target = asString(rawArgs, "target") ?? "overview";
527
+ requireThat(isOneOf(target, discoverTargets),
528
+ `参数 target 无效:${target}(可用:${discoverTargets.join(", ")})。`);
522
529
  const workerId = asString(rawArgs, "workerId");
523
530
  const backendRaw = asString(rawArgs, "backend");
524
531
  const model = asString(rawArgs, "model");
@@ -3,6 +3,7 @@ import { join } from "node:path";
3
3
  import { resourceRoot } from "../common/paths.js";
4
4
  import { requireThat } from "../common/validation.js";
5
5
  import type { HostId, WorkspaceContext, WorkspaceRole } from "../model/plugin-host.js";
6
+ import type { ReadWorkerTemplates, WorkerTemplate } from "../model/worker-template.js";
6
7
  import type { WorkspaceSkillMeta } from "../model/workspace-mcp.js";
7
8
 
8
9
  export async function readOptionalFile(path: string): Promise<string> {
@@ -21,11 +22,11 @@ export async function readLocalRole(agent: WorkspaceRole, root: string): Promise
21
22
  export async function agentText(
22
23
  agent: WorkspaceRole,
23
24
  root: string,
24
- coordinatorPrompt = "plugin-coordinator.md",
25
+ coordinatorPrompt: string | null = "plugin-coordinator.md",
25
26
  ): Promise<string> {
26
27
  requireThat(agent === "coordinator" || agent === "general-purpose", "未知职责。");
27
28
  let text = await readFile(join(resourceRoot, "agents", agent + ".md"), "utf8");
28
- if (agent === "coordinator") {
29
+ if (agent === "coordinator" && coordinatorPrompt) {
29
30
  text += "\n\n" + await readFile(join(resourceRoot, "prompts", coordinatorPrompt), "utf8");
30
31
  }
31
32
  const local = await readLocalRole(agent, root);
@@ -37,17 +38,34 @@ export async function agentText(
37
38
  export function formatWorkspaceSkills(skills: readonly WorkspaceSkillMeta[]): string {
38
39
  if (!skills.length) return "";
39
40
  const lines = skills.map(skill => `- **${skill.name}**(\`${skill.path}\`):${skill.description}`);
40
- return "## 可用技能\n\n任务匹配时按需读取对应 `SKILL.md` 正文:\n" + lines.join("\n");
41
+ return "## 按需读取的技能\n\n" + lines.join("\n");
42
+ }
43
+
44
+ function formatWorkerTemplates(templates: readonly WorkerTemplate[]): string {
45
+ if (!templates.length) return "";
46
+ const lines = templates.map(({ id, name, description, create }) => {
47
+ const label = name === id ? id : `${name}(${id})`;
48
+ const settings = [
49
+ ["助手", create.backend],
50
+ ["执行工作区", create.workspace],
51
+ ["模型", create.model],
52
+ ["思考深度", create.thinking],
53
+ ].filter(([, value]) => value !== undefined)
54
+ .map(([field, value]) => `${field} ${JSON.stringify(value)}`).join(",");
55
+ return `- ${label} ${description}(${settings})`;
56
+ });
57
+ return "## 工作区助手模板\n\n选用模板时,用 worker_discover 查询最新设置(target=templates)。\n\n" + lines.join("\n");
41
58
  }
42
59
 
43
60
  export async function loadWorkspaceContext(options: {
44
61
  host: HostId;
45
62
  root: string;
46
63
  role: WorkspaceRole;
47
- coordinatorPrompt?: string;
64
+ coordinatorPrompt?: string | null;
48
65
  includePrompts?: boolean;
49
66
  includeRootAgents?: boolean;
50
67
  localRoleOnly?: boolean;
68
+ readWorkerTemplates?: ReadWorkerTemplates;
51
69
  workspaceSkills?: readonly WorkspaceSkillMeta[];
52
70
  notices?: readonly string[];
53
71
  }): Promise<WorkspaceContext> {
@@ -62,16 +80,18 @@ export async function loadWorkspaceContext(options: {
62
80
  workspaceSkills = [],
63
81
  notices = [],
64
82
  } = options;
65
- const [workspace, roleText, rootAgents] = includePrompts
83
+ const [workspace, baseRole, rootAgents, catalog] = includePrompts
66
84
  ? await Promise.all([
67
85
  readFile(join(resourceRoot, "prompts/workspace.md"), "utf8"),
68
86
  localRoleOnly ? readLocalRole(role, root) : agentText(role, root, coordinatorPrompt),
69
87
  includeRootAgents ? readOptionalFile(join(root, "AGENTS.md")) : Promise.resolve(""),
88
+ role === "coordinator" ? options.readWorkerTemplates?.(root) : undefined,
70
89
  ])
71
- : ["", "", ""];
90
+ : ["", "", "", undefined];
91
+ const roleText = [baseRole, formatWorkerTemplates(catalog?.templates ?? [])].filter(Boolean).join("\n\n");
72
92
  const skillsSection = formatWorkspaceSkills(workspaceSkills);
73
93
  const noticesSection = notices.length
74
- ? "## 启动提示\n\n以下为工作区维护提醒,适时顺带告知用户即可,勿未经用户要求自行执行:\n" + notices.map(item => `- ${item}`).join("\n")
94
+ ? "## 维护提醒\n\n告知用户,按用户要求执行。\n\n" + notices.map(item => `- ${item}`).join("\n")
75
95
  : "";
76
96
  const environment = { host, workspaceRoot: root, resourceRoot };
77
97
  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,