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.
- package/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +2 -2
- package/README.md +4 -1
- package/README.zh-CN.md +4 -1
- package/docs/README.md +2 -3
- package/docs/architecture/design.md +41 -2
- package/docs/architecture/extensibility.md +3 -3
- package/docs/architecture/model-context.md +10 -4
- package/docs/architecture/principles.md +2 -2
- package/docs/guides/cross-harness-workers.md +27 -2
- package/docs/guides/workspace-configuration.md +3 -1
- package/docs/hosts/claude-code.md +1 -1
- package/docs/hosts/codex-qoder.md +3 -1
- package/hooks/hooks.json +3 -0
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +22 -6
- package/lib/antigravity-plugin/lib/extension/cli.js +169 -95
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +3 -1
- package/lib/antigravity-plugin/lib/extension/mcp.js +163 -119
- package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +4 -2
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +23 -5
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.js +0 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +1 -2
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.d.ts +2 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.js +12 -13
- package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.js +4 -7
- package/lib/antigravity-plugin/lib/model/worker-template.d.ts +21 -0
- package/lib/antigravity-plugin/lib/model/worker-template.js +1 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.js +1 -1
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.js +6 -3
- package/lib/antigravity-plugin/lib/services/history/summary-runner.js +3 -3
- package/lib/antigravity-plugin/lib/services/workspace/worker-templates.d.ts +17 -0
- package/lib/antigravity-plugin/lib/services/workspace/worker-templates.js +88 -0
- package/lib/antigravity-plugin/lib/storage/history-files.js +3 -2
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +2 -2
- package/lib/antigravity-plugin/resources/agents/coordinator.md +2 -4
- package/lib/antigravity-plugin/resources/agents/general-purpose.md +2 -4
- package/lib/antigravity-plugin/resources/prompts/history-monthly-summary.md +6 -11
- package/lib/antigravity-plugin/resources/prompts/history-summary.md +6 -11
- package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -1
- package/lib/antigravity-plugin/resources/prompts/workspace.md +16 -23
- package/lib/antigravity-plugin/resources/skills/project-maintenance/SKILL.md +14 -21
- package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +23 -36
- package/lib/antigravity-plugin/resources/templates/workspace-agents.md +5 -13
- package/lib/antigravity-plugin/skills/pbot/SKILL.md +6 -23
- package/lib/antigravity-plugin/skills/project-maintenance/SKILL.md +14 -21
- package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +23 -36
- package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +2 -2
- 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 +11 -3
- package/lib/extension/acp-worker.js +22 -6
- package/lib/extension/cli.js +169 -95
- package/lib/extension/hosts/dsh/command.js +1 -1
- package/lib/extension/hosts/dsh/workspace.js +5 -2
- package/lib/extension/hosts/plugin-runtime.js +3 -1
- package/lib/extension/mcp/tool-contract.d.ts +3 -3
- package/lib/extension/mcp/tool-contract.js +63 -101
- package/lib/extension/mcp/workers.d.ts +1 -1
- package/lib/extension/mcp/workers.js +19 -13
- package/lib/extension/mcp.js +163 -119
- package/lib/integrations/agent-resources.d.ts +4 -2
- package/lib/integrations/agent-resources.js +23 -5
- package/lib/integrations/hosts/antigravity/adapter.js +0 -1
- package/lib/integrations/hosts/claude/adapter.js +1 -2
- package/lib/integrations/hosts/dsh/resources.d.ts +2 -1
- package/lib/integrations/hosts/dsh/resources.js +12 -13
- package/lib/integrations/hosts/prompt-hooks.js +4 -7
- package/lib/model/worker-template.d.ts +21 -0
- package/lib/model/worker-template.js +1 -0
- package/lib/qoder-plugin/.mcp.json +2 -2
- package/lib/qoder-plugin/.qoder-plugin/plugin.json +2 -2
- package/lib/qoder-plugin/hooks/hooks.json +3 -3
- package/lib/qoder-plugin/skills/pbot/SKILL.md +11 -3
- package/lib/services/agents/agent-service.js +2 -2
- package/lib/services/history/summary-dimensions/monthly.js +1 -1
- package/lib/services/history/summary-dimensions/session.js +6 -3
- package/lib/services/history/summary-runner.js +3 -3
- package/lib/services/workspace/worker-templates.d.ts +17 -0
- package/lib/services/workspace/worker-templates.js +88 -0
- package/lib/storage/history-files.js +3 -2
- package/lib/tools/history/contract.d.ts +1 -1
- package/lib/tools/history/contract.js +14 -16
- package/package.json +2 -2
- package/resources/agents/coordinator.md +2 -4
- package/resources/agents/general-purpose.md +2 -4
- package/resources/antigravity/skills/pbot/SKILL.md +6 -23
- package/resources/claude/skills/pbot/SKILL.md +6 -23
- package/resources/plugin/skills/pbot/SKILL.md +11 -3
- package/resources/prompts/history-coordinator.md +1 -1
- package/resources/prompts/history-monthly-summary.md +6 -11
- package/resources/prompts/history-summary.md +6 -11
- package/resources/prompts/plugin-coordinator.md +1 -1
- package/resources/prompts/workspace.md +16 -23
- package/resources/skills/project-maintenance/SKILL.md +14 -21
- package/resources/skills/provider-connections/SKILL.md +23 -36
- package/resources/templates/workspace-agents.md +5 -13
- package/src/extension/cli/commands/mcp.ts +1 -1
- package/src/extension/hosts/dsh/command.ts +1 -1
- package/src/extension/hosts/dsh/workspace.ts +5 -1
- package/src/extension/hosts/pi/command.ts +1 -1
- package/src/extension/hosts/pi/events.ts +3 -1
- package/src/extension/hosts/plugin-runtime.ts +3 -1
- package/src/extension/mcp/tool-contract.ts +63 -103
- package/src/extension/mcp/workers.ts +21 -14
- package/src/integrations/agent-resources.ts +27 -7
- package/src/integrations/hosts/antigravity/adapter.ts +0 -1
- package/src/integrations/hosts/claude/adapter.ts +1 -2
- package/src/integrations/hosts/dsh/resources.ts +14 -13
- package/src/integrations/hosts/prompt-hooks.ts +3 -6
- package/src/model/worker-template.ts +24 -0
- package/src/pbot.ts +2 -2
- package/src/services/agents/agent-service.ts +2 -2
- package/src/services/history/summary-dimensions/monthly.ts +1 -1
- package/src/services/history/summary-dimensions/session.ts +6 -3
- package/src/services/history/summary-runner.ts +3 -3
- package/src/services/workspace/worker-templates.ts +80 -0
- package/src/storage/history-files.ts +3 -2
- package/src/tools/history/contract.ts +14 -16
- 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
|
-
: "
|
|
22
|
+
? "工作区根目录的绝对路径,默认当前绑定的工作区。"
|
|
23
|
+
: "传目标工作区的绝对路径(workspaceRoot)。省略时使用服务的当前目录。",
|
|
39
24
|
};
|
|
40
25
|
}
|
|
41
26
|
|
|
42
27
|
export function buildPbotWorkerTools(commands: AcpCommands = {}, defaultBackend?: string, workspaceBound = false) {
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
?
|
|
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
|
-
"
|
|
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: "
|
|
61
|
+
description: "助手标识或别名,如 claude-code、agy。",
|
|
70
62
|
},
|
|
71
63
|
model: {
|
|
72
64
|
type: "string",
|
|
73
|
-
description: "
|
|
65
|
+
description: "模型 ID、显示名或 provider/model。未指定模型时省略,使用助手默认模型。",
|
|
74
66
|
},
|
|
75
67
|
thinking: {
|
|
76
68
|
type: "string",
|
|
77
|
-
description: "
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|
|
140
|
+
description: "accept 同意或提交答案,decline 拒绝,cancel 取消请求。",
|
|
165
141
|
},
|
|
166
142
|
requestId: {
|
|
167
143
|
type: "string",
|
|
168
|
-
description: "
|
|
144
|
+
description: "待回复的请求 ID。仅有一条待处理请求时可省略。",
|
|
169
145
|
},
|
|
170
146
|
optionId: {
|
|
171
147
|
type: "string",
|
|
172
|
-
description: "
|
|
148
|
+
description: "允许或拒绝操作时填用户所选权限的 ID。省略时优先单次,缺少单次选项时可能采用长期选项。",
|
|
173
149
|
},
|
|
174
150
|
content: {
|
|
175
151
|
type: "object",
|
|
176
152
|
additionalProperties: true,
|
|
177
|
-
description: "
|
|
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
|
-
"
|
|
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: "
|
|
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
|
|
203
|
+
description: "overview(默认)列助手和本会话的 worker,workers 查会话状态,backends 查可用助手,models 查模型与思考深度。templates 列出工作区的助手模板,选中模板的 create 可直接传给 worker_create。",
|
|
242
204
|
},
|
|
243
205
|
workerId: {
|
|
244
206
|
type: "string",
|
|
245
|
-
description: "
|
|
207
|
+
description: "查 workers 时可指定单个会话,省略列出全部所属会话。",
|
|
246
208
|
},
|
|
247
209
|
backend: {
|
|
248
210
|
type: "string",
|
|
249
|
-
description:
|
|
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: "
|
|
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
|
-
"
|
|
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
|
-
"
|
|
254
|
+
"执行工作区共享 MCP 服务的工具,读写效果取决于所选工具。工具名和参数可用 workspace_mcp_discover 查询。",
|
|
295
255
|
annotations: {
|
|
296
256
|
title: "Call Workspace MCP Tool",
|
|
297
257
|
readOnlyHint: false,
|
|
298
|
-
destructiveHint:
|
|
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: "
|
|
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
|
-
"
|
|
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: "
|
|
308
|
+
description: "按来源宿主筛选,如 pi 或 claude。默认查全部来源。",
|
|
349
309
|
},
|
|
350
310
|
dimension: {
|
|
351
311
|
type: "string",
|
|
352
|
-
description: "
|
|
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: "
|
|
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: "
|
|
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:
|
|
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
|
-
"
|
|
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: "
|
|
363
|
+
description: "搜索结果、父节点或子节点的 id。",
|
|
404
364
|
},
|
|
405
365
|
host: {
|
|
406
366
|
type: "string",
|
|
407
|
-
description: "
|
|
367
|
+
description: "节点 id 重名时填来源宿主。",
|
|
408
368
|
},
|
|
409
369
|
offset: {
|
|
410
370
|
type: "integer",
|
|
411
371
|
minimum: 0,
|
|
412
|
-
description: "正文字符偏移,默认 0
|
|
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:
|
|
378
|
+
description: `每页正文字符数,默认 ${historyPageLimits.read.default}。`,
|
|
419
379
|
},
|
|
420
380
|
childrenOffset: {
|
|
421
381
|
type: "integer",
|
|
422
382
|
minimum: 0,
|
|
423
|
-
description: "
|
|
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
|
-
"
|
|
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
|
-
"
|
|
47
|
+
"可调用本工作区 .pbot/mcp.json 中登记的 MCP 工具。";
|
|
49
48
|
|
|
50
49
|
const historyCapabilityInstruction =
|
|
51
|
-
"
|
|
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.
|
|
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", "
|
|
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,
|
|
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, "当前宿主已原生挂载工作区
|
|
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
|
|
519
|
-
requireThat(isOneOf(
|
|
520
|
-
`参数 target 无效:${
|
|
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 "##
|
|
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,
|
|
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
|
-
? "##
|
|
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,
|