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
|
@@ -5,7 +5,7 @@ const usage = '用法:/pbot status | init | history [summary [维度] [--force
|
|
|
5
5
|
export function registerDshCommand(ctx, workspaces) {
|
|
6
6
|
ctx.commands.register({
|
|
7
7
|
name: "pbot",
|
|
8
|
-
description: "
|
|
8
|
+
description: "初始化或检查工作区,查询历史、更新摘要、管理委派的助手。",
|
|
9
9
|
recordInput: false,
|
|
10
10
|
input: { hint: "status | init | history ... | worker ...", attachments: false },
|
|
11
11
|
async handler({ agent, rawInput, signal }) {
|
|
@@ -9,6 +9,7 @@ import { requireThat } from "../../../common/validation.js";
|
|
|
9
9
|
import { toDshMcpConfig } from "../../../integrations/hosts/dsh/mcp.js";
|
|
10
10
|
import { registerDshSkills } from "../../../integrations/hosts/dsh/skills.js";
|
|
11
11
|
import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../../services/workspace/workspace-config.js";
|
|
12
|
+
import { readWorkerTemplates } from "../../../services/workspace/worker-templates.js";
|
|
12
13
|
import { loadNativeWorkspaceServers } from "../workspace-mcp.js";
|
|
13
14
|
import { initializeWorkspace } from "../../../services/workspace/workspace-preparation.js";
|
|
14
15
|
import { historyStartupNotices } from "../../../services/history/summary-runner.js";
|
|
@@ -41,8 +42,10 @@ export class DshWorkspace {
|
|
|
41
42
|
apply: async (ctx) => {
|
|
42
43
|
if (this.features.skills)
|
|
43
44
|
registerDshSkills(ctx, this.agent, { workspaceRoot: this.root });
|
|
44
|
-
if (this.features.prompts)
|
|
45
|
-
|
|
45
|
+
if (this.features.prompts) {
|
|
46
|
+
const historyPrompt = this.features.history ? "history-coordinator.md" : null;
|
|
47
|
+
await dshResources(ctx, this.agent, this.root, "coordinator", this.check, historyPrompt, readWorkerTemplates);
|
|
48
|
+
}
|
|
46
49
|
registerDshFileEvents(ctx, this.agent, this.root, false, this.check);
|
|
47
50
|
if (this.features.history) {
|
|
48
51
|
registerDshHistoryTool(ctx, this.agent, this.root, this.lifetime.signal, this.check);
|
|
@@ -6,6 +6,7 @@ import { loadWorkspaceContext } from "../../integrations/agent-resources.js";
|
|
|
6
6
|
import { recordHistoryCapture } from "../../services/history/history-capture.js";
|
|
7
7
|
import { historyStartupNotices } from "../../services/history/summary-runner.js";
|
|
8
8
|
import { readWorkspaceConfig, workspaceFeatures } from "../../services/workspace/workspace-config.js";
|
|
9
|
+
import { readWorkerTemplates } from "../../services/workspace/worker-templates.js";
|
|
9
10
|
import { initializeWorkspace } from "../../services/workspace/workspace-preparation.js";
|
|
10
11
|
import { discoverSkills, discoverWorkspaceSkills } from "../../services/workspace/workspace-skills.js";
|
|
11
12
|
function disabledMessage(adapter, configuration) {
|
|
@@ -86,7 +87,8 @@ export async function pluginHook(adapter, payload, replay) {
|
|
|
86
87
|
host: adapter.host,
|
|
87
88
|
root,
|
|
88
89
|
role: event.role,
|
|
89
|
-
|
|
90
|
+
readWorkerTemplates,
|
|
91
|
+
coordinatorPrompt: adapter.coordinatorPrompt ?? (features.history ? "plugin-coordinator.md" : null),
|
|
90
92
|
includePrompts,
|
|
91
93
|
includeRootAgents: includePrompts && !adapter.nativeRootAgents,
|
|
92
94
|
...(event.localRoleOnly ? { localRoleOnly: true } : {}),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type AcpCommands } from "../../model/acp.js";
|
|
2
2
|
export declare const defaultWaitMs = 50000;
|
|
3
3
|
export declare const maxWaitMs = 600000;
|
|
4
|
-
export declare const discoverTargets: readonly ["overview", "workers", "backends", "models"];
|
|
4
|
+
export declare const discoverTargets: readonly ["overview", "workers", "backends", "models", "templates"];
|
|
5
5
|
export declare function buildPbotWorkerTools(commands?: AcpCommands, defaultBackend?: string, workspaceBound?: boolean): ({
|
|
6
6
|
name: "worker_create";
|
|
7
7
|
description: string;
|
|
@@ -229,7 +229,7 @@ export declare function buildPbotWorkerTools(commands?: AcpCommands, defaultBack
|
|
|
229
229
|
properties: {
|
|
230
230
|
target: {
|
|
231
231
|
type: string;
|
|
232
|
-
enum: ("models" | "overview" | "workers" | "backends")[];
|
|
232
|
+
enum: ("templates" | "models" | "overview" | "workers" | "backends")[];
|
|
233
233
|
description: string;
|
|
234
234
|
};
|
|
235
235
|
workerId: {
|
|
@@ -657,7 +657,7 @@ export declare const pbotWorkerTools: ({
|
|
|
657
657
|
properties: {
|
|
658
658
|
target: {
|
|
659
659
|
type: string;
|
|
660
|
-
enum: ("models" | "overview" | "workers" | "backends")[];
|
|
660
|
+
enum: ("templates" | "models" | "overview" | "workers" | "backends")[];
|
|
661
661
|
description: string;
|
|
662
662
|
};
|
|
663
663
|
workerId: {
|
|
@@ -5,7 +5,7 @@ import { historyPageLimits } from "../../model/history.js";
|
|
|
5
5
|
import { acpElicitationActions } from "../../model/acp.js";
|
|
6
6
|
export const defaultWaitMs = 50_000;
|
|
7
7
|
export const maxWaitMs = 600_000;
|
|
8
|
-
export const discoverTargets = ["overview", "workers", "backends", "models"];
|
|
8
|
+
export const discoverTargets = ["overview", "workers", "backends", "models", "templates"];
|
|
9
9
|
function formatBackendItem(entry, defaultBackend) {
|
|
10
10
|
const tags = [];
|
|
11
11
|
if (entry.label)
|
|
@@ -14,38 +14,31 @@ function formatBackendItem(entry, defaultBackend) {
|
|
|
14
14
|
tags.push("当前宿主");
|
|
15
15
|
return tags.length ? `${entry.backend}(${tags.join(",")})` : entry.backend;
|
|
16
16
|
}
|
|
17
|
-
function summarizeBackends(commands = {}, defaultBackend) {
|
|
18
|
-
const entries = inspectAcpBackends(commands);
|
|
19
|
-
const available = entries.filter(item => item.available);
|
|
20
|
-
const unavailable = entries.filter(item => !item.available);
|
|
21
|
-
const availableText = available.map(item => formatBackendItem(item, defaultBackend)).join("、");
|
|
22
|
-
const unavailableText = unavailable.map(item => formatBackendItem(item, defaultBackend)).join("、");
|
|
23
|
-
const overview = available.length
|
|
24
|
-
? unavailable.length
|
|
25
|
-
? `当前可用助手:${availableText};暂不可用:${unavailableText}。`
|
|
26
|
-
: `当前可用助手:${availableText}。`
|
|
27
|
-
: `当前无可用外部助手(暂不可用:${unavailableText})。`;
|
|
28
|
-
const availableIds = available.map(item => item.backend).join("、");
|
|
29
|
-
return { overview, availableIds };
|
|
30
|
-
}
|
|
31
17
|
function workspaceProperty(workspaceBound) {
|
|
32
18
|
return {
|
|
33
19
|
type: "string",
|
|
34
20
|
description: workspaceBound
|
|
35
|
-
? "
|
|
36
|
-
: "
|
|
21
|
+
? "工作区根目录的绝对路径,默认当前绑定的工作区。"
|
|
22
|
+
: "传目标工作区的绝对路径(workspaceRoot)。省略时使用服务的当前目录。",
|
|
37
23
|
};
|
|
38
24
|
}
|
|
39
25
|
export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = false) {
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
?
|
|
43
|
-
: "
|
|
26
|
+
const available = inspectAcpBackends(commands).filter(item => item.available);
|
|
27
|
+
const overview = available.length
|
|
28
|
+
? "可用助手:" + available.map(item => formatBackendItem(item, defaultBackend)).join("、") + "。"
|
|
29
|
+
: "当前没有可用助手。用 worker_discover 的 backends 查看接入状态。";
|
|
44
30
|
const workspace = workspaceProperty(workspaceBound);
|
|
31
|
+
const workerId = { type: "string", description: "助手会话 ID。" };
|
|
32
|
+
const waitMs = {
|
|
33
|
+
type: "integer",
|
|
34
|
+
minimum: 0,
|
|
35
|
+
maximum: maxWaitMs,
|
|
36
|
+
description: `等待本轮结果的毫秒数,默认 ${defaultWaitMs}。0 表示不等待结果。`,
|
|
37
|
+
};
|
|
45
38
|
return [
|
|
46
39
|
{
|
|
47
40
|
name: "worker_create",
|
|
48
|
-
description: "
|
|
41
|
+
description: "新建独立助手会话,返回 workerId。用 worker_request 发送首个任务。\n" +
|
|
49
42
|
overview,
|
|
50
43
|
annotations: {
|
|
51
44
|
title: "Create Worker",
|
|
@@ -61,15 +54,15 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
61
54
|
properties: {
|
|
62
55
|
backend: {
|
|
63
56
|
type: "string",
|
|
64
|
-
description: "
|
|
57
|
+
description: "助手标识或别名,如 claude-code、agy。",
|
|
65
58
|
},
|
|
66
59
|
model: {
|
|
67
60
|
type: "string",
|
|
68
|
-
description: "
|
|
61
|
+
description: "模型 ID、显示名或 provider/model。未指定模型时省略,使用助手默认模型。",
|
|
69
62
|
},
|
|
70
63
|
thinking: {
|
|
71
64
|
type: "string",
|
|
72
|
-
description: "
|
|
65
|
+
description: "思考深度,如 high。未指定时省略,使用助手默认设置。",
|
|
73
66
|
},
|
|
74
67
|
workspace,
|
|
75
68
|
},
|
|
@@ -77,7 +70,7 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
77
70
|
},
|
|
78
71
|
{
|
|
79
72
|
name: "worker_close",
|
|
80
|
-
description: "
|
|
73
|
+
description: "任务结束后关闭助手。提前关闭会中断执行。创建结果中 resume 为 true 时,可用原 workerId 续接。",
|
|
81
74
|
annotations: {
|
|
82
75
|
title: "Close Worker",
|
|
83
76
|
readOnlyHint: false,
|
|
@@ -90,17 +83,13 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
90
83
|
additionalProperties: false,
|
|
91
84
|
required: ["workerId"],
|
|
92
85
|
properties: {
|
|
93
|
-
workerId
|
|
94
|
-
type: "string",
|
|
95
|
-
description: "助手会话 ID(来自 worker_create 或 worker_discover)。",
|
|
96
|
-
},
|
|
86
|
+
workerId,
|
|
97
87
|
},
|
|
98
88
|
},
|
|
99
89
|
},
|
|
100
90
|
{
|
|
101
91
|
name: "worker_request",
|
|
102
|
-
description: "
|
|
103
|
-
`默认最多等待 ${defaultWaitMs / 1000} 秒(waitMs 设为 0 可立即转后台并行);返回 timedOut 或 nextOffset 用 worker_output,返回 needsResponse 先向用户确认再用 worker_response。`,
|
|
92
|
+
description: "向助手派发任务或在同一会话追问。后台结果用 worker_output 收取。",
|
|
104
93
|
annotations: {
|
|
105
94
|
title: "Send Request to Worker",
|
|
106
95
|
readOnlyHint: false,
|
|
@@ -113,27 +102,18 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
113
102
|
additionalProperties: false,
|
|
114
103
|
required: ["workerId", "message"],
|
|
115
104
|
properties: {
|
|
116
|
-
workerId
|
|
117
|
-
type: "string",
|
|
118
|
-
description: "助手会话 ID(来自 worker_create 或 worker_discover)。",
|
|
119
|
-
},
|
|
105
|
+
workerId,
|
|
120
106
|
message: {
|
|
121
107
|
type: "string",
|
|
122
|
-
description: "
|
|
123
|
-
},
|
|
124
|
-
waitMs: {
|
|
125
|
-
type: "integer",
|
|
126
|
-
minimum: 0,
|
|
127
|
-
maximum: maxWaitMs,
|
|
128
|
-
description: `最多等待毫秒数(默认 ${defaultWaitMs});0 表示立即返回转后台执行。`,
|
|
108
|
+
description: "任务或追问。助手看不到主会话历史,首次派发时写明背景、目标、文件路径、约束和交付要求。",
|
|
129
109
|
},
|
|
110
|
+
waitMs,
|
|
130
111
|
},
|
|
131
112
|
},
|
|
132
113
|
},
|
|
133
114
|
{
|
|
134
115
|
name: "worker_response",
|
|
135
|
-
description: "
|
|
136
|
-
`提交前先向用户确认;提交后默认等待最多 ${defaultWaitMs / 1000} 秒返回后续结果。`,
|
|
116
|
+
description: "收到 needsResponse 时,将权限选项、表单问题或链接交给用户确认,再提交用户的决定。",
|
|
137
117
|
annotations: {
|
|
138
118
|
title: "Respond to Worker Request",
|
|
139
119
|
readOnlyHint: false,
|
|
@@ -146,40 +126,32 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
146
126
|
additionalProperties: false,
|
|
147
127
|
required: ["workerId", "action"],
|
|
148
128
|
properties: {
|
|
149
|
-
workerId
|
|
150
|
-
type: "string",
|
|
151
|
-
description: "等待回复的助手会话 ID。",
|
|
152
|
-
},
|
|
129
|
+
workerId,
|
|
153
130
|
action: {
|
|
154
131
|
type: "string",
|
|
155
132
|
enum: [...acpElicitationActions],
|
|
156
|
-
description: "accept
|
|
133
|
+
description: "accept 同意或提交答案,decline 拒绝,cancel 取消请求。",
|
|
157
134
|
},
|
|
158
135
|
requestId: {
|
|
159
136
|
type: "string",
|
|
160
|
-
description: "
|
|
137
|
+
description: "待回复的请求 ID。仅有一条待处理请求时可省略。",
|
|
161
138
|
},
|
|
162
139
|
optionId: {
|
|
163
140
|
type: "string",
|
|
164
|
-
description: "
|
|
141
|
+
description: "允许或拒绝操作时填用户所选权限的 ID。省略时优先单次,缺少单次选项时可能采用长期选项。",
|
|
165
142
|
},
|
|
166
143
|
content: {
|
|
167
144
|
type: "object",
|
|
168
145
|
additionalProperties: true,
|
|
169
|
-
description: "
|
|
170
|
-
},
|
|
171
|
-
waitMs: {
|
|
172
|
-
type: "integer",
|
|
173
|
-
minimum: 0,
|
|
174
|
-
maximum: maxWaitMs,
|
|
175
|
-
description: `提交后最多等待毫秒数(默认 ${defaultWaitMs});0 表示立即返回。`,
|
|
146
|
+
description: "接受表单时,按表单字段填写答案。值可为字符串、数字、布尔值或字符串数组。",
|
|
176
147
|
},
|
|
148
|
+
waitMs,
|
|
177
149
|
},
|
|
178
150
|
},
|
|
179
151
|
},
|
|
180
152
|
{
|
|
181
153
|
name: "worker_output",
|
|
182
|
-
description: "
|
|
154
|
+
description: "读取助手最近一轮的结果。后台执行或返回 timedOut 时,用原 workerId 继续等待。",
|
|
183
155
|
annotations: {
|
|
184
156
|
title: "Get Worker Output",
|
|
185
157
|
readOnlyHint: true,
|
|
@@ -192,29 +164,21 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
192
164
|
additionalProperties: false,
|
|
193
165
|
required: ["workerId"],
|
|
194
166
|
properties: {
|
|
195
|
-
workerId
|
|
196
|
-
type: "string",
|
|
197
|
-
description: "助手会话 ID。",
|
|
198
|
-
},
|
|
167
|
+
workerId,
|
|
199
168
|
offset: {
|
|
200
169
|
type: "integer",
|
|
201
170
|
minimum: 0,
|
|
202
|
-
description: "
|
|
203
|
-
},
|
|
204
|
-
waitMs: {
|
|
205
|
-
type: "integer",
|
|
206
|
-
minimum: 0,
|
|
207
|
-
maximum: maxWaitMs,
|
|
208
|
-
description: `运行中最多等待毫秒数(默认 ${defaultWaitMs});已结束或翻页时立即返回。`,
|
|
171
|
+
description: "续读传上页的 nextOffset,默认从 0 开始。",
|
|
209
172
|
},
|
|
173
|
+
waitMs,
|
|
210
174
|
},
|
|
211
175
|
},
|
|
212
176
|
},
|
|
213
177
|
{
|
|
214
178
|
name: "worker_discover",
|
|
215
|
-
description: "
|
|
179
|
+
description: "查找可用助手、模板或已有会话。查询模型会临时启动所选助手。",
|
|
216
180
|
annotations: {
|
|
217
|
-
title: "Discover Workers, Backends & Models",
|
|
181
|
+
title: "Discover Workers, Templates, Backends & Models",
|
|
218
182
|
readOnlyHint: true,
|
|
219
183
|
destructiveHint: false,
|
|
220
184
|
idempotentHint: true,
|
|
@@ -228,21 +192,19 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
228
192
|
target: {
|
|
229
193
|
type: "string",
|
|
230
194
|
enum: [...discoverTargets],
|
|
231
|
-
description: "overview
|
|
195
|
+
description: "overview(默认)列助手和本会话的 worker,workers 查会话状态,backends 查可用助手,models 查模型与思考深度。templates 列出工作区的助手模板,选中模板的 create 可直接传给 worker_create。",
|
|
232
196
|
},
|
|
233
197
|
workerId: {
|
|
234
198
|
type: "string",
|
|
235
|
-
description: "
|
|
199
|
+
description: "查 workers 时可指定单个会话,省略列出全部所属会话。",
|
|
236
200
|
},
|
|
237
201
|
backend: {
|
|
238
202
|
type: "string",
|
|
239
|
-
description:
|
|
240
|
-
? `仅 target="models" 可用(${modelsBackendHint}):目标助手标识,支持别名;当前可用:${availableIds}。`
|
|
241
|
-
: `仅 target="models" 可用(${modelsBackendHint}):目标助手标识,支持别名。`,
|
|
203
|
+
description: defaultBackend ? `查 models 时选择助手,默认 ${defaultBackend}。` : "查 models 时必填助手标识。",
|
|
242
204
|
},
|
|
243
205
|
model: {
|
|
244
206
|
type: "string",
|
|
245
|
-
description: "
|
|
207
|
+
description: "查 models 时可指定模型以查看它支持的思考深度。",
|
|
246
208
|
},
|
|
247
209
|
workspace,
|
|
248
210
|
},
|
|
@@ -255,7 +217,7 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
255
217
|
return [
|
|
256
218
|
{
|
|
257
219
|
name: "workspace_mcp_discover",
|
|
258
|
-
description: "
|
|
220
|
+
description: "查找工作区共享的 MCP 服务,以及服务提供的工具和参数。",
|
|
259
221
|
annotations: {
|
|
260
222
|
title: "Discover Workspace MCP Servers & Tools",
|
|
261
223
|
readOnlyHint: true,
|
|
@@ -270,7 +232,7 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
270
232
|
properties: {
|
|
271
233
|
server: {
|
|
272
234
|
type: "string",
|
|
273
|
-
description: "
|
|
235
|
+
description: "填服务名列出其工具,省略则列出已配置的服务。",
|
|
274
236
|
},
|
|
275
237
|
workspace,
|
|
276
238
|
},
|
|
@@ -278,11 +240,11 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
278
240
|
},
|
|
279
241
|
{
|
|
280
242
|
name: "workspace_mcp_call",
|
|
281
|
-
description: "
|
|
243
|
+
description: "执行工作区共享 MCP 服务的工具,读写效果取决于所选工具。工具名和参数可用 workspace_mcp_discover 查询。",
|
|
282
244
|
annotations: {
|
|
283
245
|
title: "Call Workspace MCP Tool",
|
|
284
246
|
readOnlyHint: false,
|
|
285
|
-
destructiveHint:
|
|
247
|
+
destructiveHint: true,
|
|
286
248
|
idempotentHint: false,
|
|
287
249
|
openWorldHint: true,
|
|
288
250
|
},
|
|
@@ -293,16 +255,16 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
293
255
|
properties: {
|
|
294
256
|
server: {
|
|
295
257
|
type: "string",
|
|
296
|
-
description: "
|
|
258
|
+
description: "工作区中登记的服务名。",
|
|
297
259
|
},
|
|
298
260
|
tool: {
|
|
299
261
|
type: "string",
|
|
300
|
-
description: "
|
|
262
|
+
description: "该服务提供的工具名。",
|
|
301
263
|
},
|
|
302
264
|
arguments: {
|
|
303
265
|
type: "object",
|
|
304
266
|
additionalProperties: true,
|
|
305
|
-
description: "
|
|
267
|
+
description: "按所选工具的参数定义填写,默认 {}。",
|
|
306
268
|
},
|
|
307
269
|
workspace,
|
|
308
270
|
},
|
|
@@ -315,7 +277,7 @@ export function buildHistoryMcpTools(workspaceBound = false) {
|
|
|
315
277
|
return [
|
|
316
278
|
{
|
|
317
279
|
name: "history_search",
|
|
318
|
-
description: "
|
|
280
|
+
description: "查找工作区各宿主归档的问答或摘要。用命中项的 id 调用 history_read 可读全文。",
|
|
319
281
|
annotations: {
|
|
320
282
|
title: "Search Workspace History",
|
|
321
283
|
readOnlyHint: true,
|
|
@@ -330,38 +292,38 @@ export function buildHistoryMcpTools(workspaceBound = false) {
|
|
|
330
292
|
properties: {
|
|
331
293
|
host: {
|
|
332
294
|
type: "string",
|
|
333
|
-
description: "
|
|
295
|
+
description: "按来源宿主筛选,如 pi 或 claude。默认查全部来源。",
|
|
334
296
|
},
|
|
335
297
|
dimension: {
|
|
336
298
|
type: "string",
|
|
337
|
-
description: "
|
|
299
|
+
description: "raw 为原始问答,session、monthly 等为摘要维度。关键词搜索默认查全部。",
|
|
338
300
|
},
|
|
339
301
|
query: {
|
|
340
302
|
type: "string",
|
|
341
|
-
description: "
|
|
303
|
+
description: "匹配连续文本,忽略大小写。省略时列会话,指定摘要维度则列该维度的摘要。",
|
|
342
304
|
},
|
|
343
305
|
sessionId: {
|
|
344
306
|
type: "string",
|
|
345
|
-
description: "
|
|
307
|
+
description: "按原始会话 ID 筛选。",
|
|
346
308
|
},
|
|
347
309
|
from: {
|
|
348
310
|
type: "string",
|
|
349
|
-
description: "ISO
|
|
311
|
+
description: "时间区间起点(含),用 ISO 日期或时间。",
|
|
350
312
|
},
|
|
351
313
|
to: {
|
|
352
314
|
type: "string",
|
|
353
|
-
description: "ISO
|
|
315
|
+
description: "时间区间终点(含),仅填 ISO 日期表示该日 UTC 零点。",
|
|
354
316
|
},
|
|
355
317
|
offset: {
|
|
356
318
|
type: "integer",
|
|
357
319
|
minimum: 0,
|
|
358
|
-
description: "
|
|
320
|
+
description: "结果起点,默认 0。翻页传上页的 nextOffset。",
|
|
359
321
|
},
|
|
360
322
|
limit: {
|
|
361
323
|
type: "integer",
|
|
362
324
|
minimum: 1,
|
|
363
325
|
maximum: historyPageLimits.search.max,
|
|
364
|
-
description:
|
|
326
|
+
description: `每页条数,默认 ${historyPageLimits.search.default}。`,
|
|
365
327
|
},
|
|
366
328
|
workspace,
|
|
367
329
|
},
|
|
@@ -369,7 +331,7 @@ export function buildHistoryMcpTools(workspaceBound = false) {
|
|
|
369
331
|
},
|
|
370
332
|
{
|
|
371
333
|
name: "history_read",
|
|
372
|
-
description: "
|
|
334
|
+
description: "读取历史节点的正文和上下级。沿子节点可从月度汇总找到会话摘要和原始问答。",
|
|
373
335
|
annotations: {
|
|
374
336
|
title: "Read Workspace History Node",
|
|
375
337
|
readOnlyHint: true,
|
|
@@ -384,27 +346,27 @@ export function buildHistoryMcpTools(workspaceBound = false) {
|
|
|
384
346
|
properties: {
|
|
385
347
|
id: {
|
|
386
348
|
type: "string",
|
|
387
|
-
description: "
|
|
349
|
+
description: "搜索结果、父节点或子节点的 id。",
|
|
388
350
|
},
|
|
389
351
|
host: {
|
|
390
352
|
type: "string",
|
|
391
|
-
description: "
|
|
353
|
+
description: "节点 id 重名时填来源宿主。",
|
|
392
354
|
},
|
|
393
355
|
offset: {
|
|
394
356
|
type: "integer",
|
|
395
357
|
minimum: 0,
|
|
396
|
-
description: "正文字符偏移,默认 0
|
|
358
|
+
description: "正文字符偏移,默认 0。续读传上页的 nextOffset。",
|
|
397
359
|
},
|
|
398
360
|
limit: {
|
|
399
361
|
type: "integer",
|
|
400
362
|
minimum: 1,
|
|
401
363
|
maximum: historyPageLimits.read.max,
|
|
402
|
-
description:
|
|
364
|
+
description: `每页正文字符数,默认 ${historyPageLimits.read.default}。`,
|
|
403
365
|
},
|
|
404
366
|
childrenOffset: {
|
|
405
367
|
type: "integer",
|
|
406
368
|
minimum: 0,
|
|
407
|
-
description: "
|
|
369
|
+
description: "子节点起点,默认 0。翻页传上页的 nextChildrenOffset。",
|
|
408
370
|
},
|
|
409
371
|
workspace,
|
|
410
372
|
},
|
|
@@ -264,7 +264,7 @@ export declare class McpWorkerRuntime {
|
|
|
264
264
|
properties: {
|
|
265
265
|
target: {
|
|
266
266
|
type: string;
|
|
267
|
-
enum: ("models" | "overview" | "workers" | "backends")[];
|
|
267
|
+
enum: ("templates" | "models" | "overview" | "workers" | "backends")[];
|
|
268
268
|
description: string;
|
|
269
269
|
};
|
|
270
270
|
workerId: {
|
|
@@ -16,31 +16,30 @@ import { historyPageLimits } from "../../model/history.js";
|
|
|
16
16
|
import { AgentService } from "../../services/agents/agent-service.js";
|
|
17
17
|
import { readWorkspaceHistory, searchWorkspaceHistory } from "../../services/history/history-query.js";
|
|
18
18
|
import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../services/workspace/workspace-config.js";
|
|
19
|
+
import { discoverWorkerTemplates } from "../../services/workspace/worker-templates.js";
|
|
19
20
|
import { WorkspaceMcpBridge } from "./bridge.js";
|
|
20
21
|
export { buildHistoryMcpTools, buildPbotWorkerTools, buildWorkspaceMcpTools, pbotWorkerTools } from "./tool-contract.js";
|
|
21
22
|
const protocolVersion = "2025-03-26";
|
|
22
23
|
const readyTimeoutMs = 45_000;
|
|
23
24
|
const reportPageSize = 16_000;
|
|
24
25
|
const progressIntervalMs = 5_000;
|
|
25
|
-
const workerCapabilityInstruction = "
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const workspaceMcpCapabilityInstruction = "工作区共享 MCP(workspace_mcp_*):先用 workspace_mcp_discover 查 .pbot/mcp.json 中的服务与工具,再用 workspace_mcp_call 调用。";
|
|
29
|
-
const historyCapabilityInstruction = "跨宿主历史(history_search / history_read):只读检索当前工作区跨宿主记录的历史问答与摘要归档。";
|
|
26
|
+
const workerCapabilityInstruction = "可查询工作区的助手模板,也可按用户要求或工作区分工委派给指定助手或模型。常规任务优先自行处理或使用宿主内置子代理。";
|
|
27
|
+
const workspaceMcpCapabilityInstruction = "可调用本工作区 .pbot/mcp.json 中登记的 MCP 工具。";
|
|
28
|
+
const historyCapabilityInstruction = "可检索本工作区各宿主归档的问答和摘要。";
|
|
30
29
|
export function buildMcpInstructions(options) {
|
|
31
30
|
const parts = [workerCapabilityInstruction];
|
|
32
31
|
if (options.workspaceMcp)
|
|
33
32
|
parts.push(workspaceMcpCapabilityInstruction);
|
|
34
33
|
if (options.history)
|
|
35
34
|
parts.push(historyCapabilityInstruction);
|
|
36
|
-
return parts.
|
|
35
|
+
return parts.join("\n");
|
|
37
36
|
}
|
|
38
37
|
export const mcpWorkerOnlyInstructions = buildMcpInstructions({ workspaceMcp: false, history: false });
|
|
39
38
|
export const mcpInstructions = buildMcpInstructions({ workspaceMcp: true, history: true });
|
|
40
39
|
export function defaultWorkerDirectory(workspaceRoot) {
|
|
41
40
|
if (process.env.PBOT_MCP_AGENT_DIR)
|
|
42
41
|
return process.env.PBOT_MCP_AGENT_DIR;
|
|
43
|
-
return join(workspaceRoot, ".pbot", "
|
|
42
|
+
return join(workspaceRoot, ".pbot", "worker", "runtime");
|
|
44
43
|
}
|
|
45
44
|
function workerCommandTool(name) {
|
|
46
45
|
const full = name.startsWith("worker_") ? name : `worker_${name}`;
|
|
@@ -334,16 +333,19 @@ export class McpWorkerRuntime {
|
|
|
334
333
|
const { name, args: rawArgs } = parseMcpToolCall(toolName, input);
|
|
335
334
|
requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
|
|
336
335
|
const isWorkerScoped = name === "worker_close" || name === "worker_request" || name === "worker_response" || name === "worker_output";
|
|
336
|
+
const isTemplateQuery = name === "worker_discover" && rawArgs.target === "templates";
|
|
337
337
|
const root = isWorkerScoped
|
|
338
338
|
? await this.resolveWorkerWorkspace(asString(rawArgs, "workerId", true), defaultWorkspace)
|
|
339
|
-
: await this.resolveWorkspace(asString(rawArgs, "workspace") ?? defaultWorkspace);
|
|
339
|
+
: await this.resolveWorkspace(asString(rawArgs, "workspace", isTemplateQuery && rawArgs.workspace !== undefined) ?? defaultWorkspace);
|
|
340
340
|
const configuration = await readWorkspaceConfig(root);
|
|
341
341
|
requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
|
|
342
|
-
requireThat(configuration.enabled,
|
|
342
|
+
requireThat(configuration.enabled, isTemplateQuery
|
|
343
|
+
? `无法在工作区 ${root} 查询助手模板。`
|
|
344
|
+
: workspaceDisabledMessage(configuration));
|
|
343
345
|
switch (name) {
|
|
344
346
|
case "workspace_mcp_discover":
|
|
345
347
|
case "workspace_mcp_call": {
|
|
346
|
-
requireThat(!this.#nativeWorkspaceMcp, "当前宿主已原生挂载工作区
|
|
348
|
+
requireThat(!this.#nativeWorkspaceMcp, "当前宿主已原生挂载工作区 MCP 服务,请直接调用对应工具。");
|
|
347
349
|
requireThat(workspaceFeatures(configuration).mcp, `工作区统一 MCP 功能已在 ${configuration.path} 中停用(features.mcp: false)。`);
|
|
348
350
|
if (name === "workspace_mcp_discover")
|
|
349
351
|
return this.#bridge.discover(root, asString(rawArgs, "server"));
|
|
@@ -392,6 +394,11 @@ export class McpWorkerRuntime {
|
|
|
392
394
|
return { node: readWorkspaceHistory(root, id, offset, limit, childrenOffset, hostFilter) };
|
|
393
395
|
}
|
|
394
396
|
}
|
|
397
|
+
if (isTemplateQuery) {
|
|
398
|
+
const extra = Object.keys(rawArgs).find(key => key !== "target" && key !== "workspace");
|
|
399
|
+
requireThat(extra === undefined, `查询模板只接受 target 和 workspace,收到参数 ${extra}。`);
|
|
400
|
+
return discoverWorkerTemplates(root);
|
|
401
|
+
}
|
|
395
402
|
const { host, service, owner } = this.workerService(root, configuration.acp);
|
|
396
403
|
switch (name) {
|
|
397
404
|
case "worker_create": {
|
|
@@ -461,9 +468,8 @@ export class McpWorkerRuntime {
|
|
|
461
468
|
return this.waitFor(service, owner, workerId, undefined, waitMs, offset, progress);
|
|
462
469
|
}
|
|
463
470
|
case "worker_discover": {
|
|
464
|
-
const
|
|
465
|
-
requireThat(isOneOf(
|
|
466
|
-
const target = rawTarget;
|
|
471
|
+
const target = asString(rawArgs, "target") ?? "overview";
|
|
472
|
+
requireThat(isOneOf(target, discoverTargets), `参数 target 无效:${target}(可用:${discoverTargets.join(", ")})。`);
|
|
467
473
|
const workerId = asString(rawArgs, "workerId");
|
|
468
474
|
const backendRaw = asString(rawArgs, "backend");
|
|
469
475
|
const model = asString(rawArgs, "model");
|