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