personal-bot 0.3.1 → 0.3.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 +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/bin/pbot-pi-acp.mjs +27 -11
- package/bin/pbot.mjs +1 -1
- package/docs/README.md +1 -1
- package/docs/architecture/design.md +23 -10
- package/docs/architecture/extensibility.md +20 -18
- package/docs/architecture/model-context.md +2 -2
- package/docs/architecture/principles.md +4 -3
- package/docs/guides/capabilities.md +3 -3
- package/docs/guides/history.md +50 -16
- package/docs/guides/workspace-configuration.md +31 -6
- package/docs/hosts/antigravity.md +2 -0
- package/docs/hosts/claude-code.md +1 -1
- package/docs/hosts/dsh.md +1 -1
- package/docs/hosts/pi.md +1 -1
- package/hooks/hooks.json +3 -0
- package/lib/antigravity-plugin/hooks.json +7 -0
- package/lib/antigravity-plugin/lib/claude.js +2 -2
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +156 -11
- package/lib/antigravity-plugin/lib/extension/{plugin-runtime.d.ts → hosts/plugin-runtime.d.ts} +2 -2
- package/lib/antigravity-plugin/lib/extension/{plugin-runtime.js → hosts/plugin-runtime.js} +34 -8
- package/lib/antigravity-plugin/lib/extension/mcp.js +1113 -78
- package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +1 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +5 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.js +171 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/{claude.js → claude/adapter.js} +32 -4
- package/lib/antigravity-plugin/lib/integrations/hosts/{registry.js → plugin-registry.js} +2 -2
- package/lib/antigravity-plugin/lib/model/history.d.ts +169 -0
- package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +26 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +25 -0
- package/lib/antigravity-plugin/lib/plugin.js +2 -2
- package/lib/antigravity-plugin/lib/services/history/history-capture.d.ts +4 -0
- package/lib/antigravity-plugin/lib/services/history/history-capture.js +86 -0
- package/lib/antigravity-plugin/lib/services/history/history-index.d.ts +17 -0
- package/lib/antigravity-plugin/lib/services/history/history-index.js +112 -0
- package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +12 -0
- package/lib/antigravity-plugin/lib/services/history/history-migrate.js +88 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.js +121 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.d.ts +7 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.js +124 -0
- package/lib/antigravity-plugin/lib/services/history/summary-registry.d.ts +7 -0
- package/lib/antigravity-plugin/lib/services/history/summary-registry.js +36 -0
- package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +37 -0
- package/lib/antigravity-plugin/lib/services/history/summary-runner.js +301 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +5 -1
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +73 -4
- package/lib/antigravity-plugin/lib/storage/file-access.d.ts +2 -0
- package/lib/antigravity-plugin/lib/storage/file-access.js +26 -0
- package/lib/antigravity-plugin/lib/storage/history-files.d.ts +54 -0
- package/lib/antigravity-plugin/lib/storage/history-files.js +467 -0
- package/lib/antigravity-plugin/lib/storage/history-format.d.ts +6 -0
- package/lib/antigravity-plugin/lib/storage/history-format.js +62 -0
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +1 -1
- package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +22 -12
- package/lib/claude.js +2 -2
- package/lib/client.js +21 -11
- package/lib/dsh.js +4 -4
- package/lib/extension/{acp-member.d.ts → acp/member.d.ts} +5 -5
- package/lib/extension/{acp-member.js → acp/member.js} +6 -6
- package/lib/extension/acp/worker.d.ts +1 -0
- package/lib/extension/acp/worker.js +384 -0
- package/lib/extension/acp-worker.js +156 -11
- package/lib/extension/{dsh → hosts/dsh}/acp-member.js +8 -8
- package/lib/extension/hosts/dsh/command.js +92 -0
- package/lib/extension/{dsh → hosts/dsh}/files.js +3 -3
- package/lib/extension/hosts/dsh/history.d.ts +4 -0
- package/lib/extension/hosts/dsh/history.js +62 -0
- package/lib/extension/{dsh → hosts/dsh}/management.d.ts +1 -1
- package/lib/extension/{dsh → hosts/dsh}/management.js +12 -10
- package/lib/extension/{dsh → hosts/dsh}/workspace.d.ts +3 -9
- package/lib/extension/{dsh → hosts/dsh}/workspace.js +32 -70
- package/lib/extension/{plugin-runtime.d.ts → hosts/plugin-runtime.d.ts} +2 -2
- package/lib/extension/{plugin-runtime.js → hosts/plugin-runtime.js} +34 -8
- package/lib/extension/{mcp-bridge.d.ts → mcp/bridge.d.ts} +1 -1
- package/lib/extension/{mcp-bridge.js → mcp/bridge.js} +4 -4
- package/lib/extension/{mcp-workers.d.ts → mcp/workers.d.ts} +222 -2
- package/lib/extension/{mcp-workers.js → mcp/workers.js} +229 -63
- package/lib/extension/mcp.js +1113 -78
- package/lib/extension/{setup-cli.js → setup/cli.js} +9 -9
- package/lib/integrations/acp/connection.d.ts +11 -10
- package/lib/integrations/acp/connection.js +6 -0
- package/lib/integrations/acp/harnesses/claude.js +1 -1
- package/lib/integrations/acp/harnesses/dsh.js +1 -1
- package/lib/integrations/acp/history-summary.d.ts +17 -0
- package/lib/integrations/acp/history-summary.js +100 -0
- package/lib/integrations/agent-resources.d.ts +1 -0
- package/lib/integrations/agent-resources.js +5 -1
- package/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
- package/lib/integrations/hosts/antigravity/adapter.js +171 -0
- package/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
- package/lib/integrations/hosts/{claude.js → claude/adapter.js} +32 -4
- package/lib/integrations/{dsh → hosts/dsh}/mcp.d.ts +1 -1
- package/lib/integrations/{dsh → hosts/dsh}/resources.d.ts +1 -1
- package/lib/integrations/{dsh → hosts/dsh}/resources.js +4 -4
- package/lib/integrations/{dsh → hosts/dsh}/schema.js +1 -1
- package/lib/integrations/{dsh → hosts/dsh}/skills.js +1 -1
- package/lib/integrations/hosts/{registry.js → plugin-registry.js} +2 -2
- package/lib/integrations/installation/pi-setup.js +1 -1
- package/lib/model/history.d.ts +133 -34
- package/lib/model/plugin-host.d.ts +26 -0
- package/lib/model/workspace-config.d.ts +25 -0
- package/lib/plugin.js +2 -2
- package/lib/services/agents/agent-run.d.ts +1 -1
- package/lib/services/history/history-capture.d.ts +4 -0
- package/lib/services/history/history-capture.js +86 -0
- package/lib/services/history/history-index.d.ts +16 -7
- package/lib/services/history/history-index.js +48 -70
- package/lib/services/history/history-migrate.d.ts +12 -0
- package/lib/services/history/history-migrate.js +88 -0
- package/lib/services/history/history-query.d.ts +51 -0
- package/lib/services/history/history-query.js +371 -0
- package/lib/services/history/summary-command.d.ts +20 -0
- package/lib/services/history/summary-command.js +68 -0
- package/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
- package/lib/services/history/summary-dimensions/monthly.js +121 -0
- package/lib/services/history/summary-dimensions/session.d.ts +7 -0
- package/lib/services/history/summary-dimensions/session.js +124 -0
- package/lib/services/history/summary-registry.d.ts +7 -0
- package/lib/services/history/summary-registry.js +36 -0
- package/lib/services/history/summary-runner.d.ts +37 -0
- package/lib/services/history/summary-runner.js +301 -0
- package/lib/services/workspace/workspace-config.d.ts +5 -1
- package/lib/services/workspace/workspace-config.js +73 -4
- package/lib/storage/history-files.d.ts +45 -9
- package/lib/storage/history-files.js +373 -247
- package/lib/storage/history-format.d.ts +3 -12
- package/lib/storage/history-format.js +26 -50
- package/lib/tools/history/actions.d.ts +3 -68
- package/lib/tools/history/actions.js +7 -5
- package/lib/tools/history/contract.d.ts +14 -7
- package/lib/tools/history/contract.js +58 -18
- package/lib/tools/history/dsh-tool.d.ts +1 -2
- package/lib/tools/history/dsh-tool.js +11 -5
- package/lib/ui/dsh/management.js +18 -5
- package/package.json +1 -1
- package/resources/prompts/history-coordinator.md +1 -1
- package/resources/prompts/history-monthly-summary.md +13 -0
- package/resources/prompts/history-summary.md +10 -4
- package/resources/skills/provider-connections/SKILL.md +22 -12
- package/src/claude.ts +2 -2
- package/src/dsh.ts +4 -4
- package/src/extension/{acp-member.ts → acp/member.ts} +7 -7
- package/src/extension/{acp-worker.ts → acp/worker.ts} +131 -17
- package/src/extension/{dsh → hosts/dsh}/acp-member.ts +9 -9
- package/src/extension/hosts/dsh/command.ts +92 -0
- package/src/extension/{dsh → hosts/dsh}/files.ts +3 -3
- package/src/extension/hosts/dsh/history.ts +67 -0
- package/src/extension/{dsh → hosts/dsh}/management.ts +11 -9
- package/src/extension/{dsh → hosts/dsh}/workspace.ts +31 -50
- package/src/extension/{pi-acp-member.ts → hosts/pi/acp-member.ts} +9 -9
- package/src/extension/hosts/pi/command.ts +158 -0
- package/src/extension/{events.ts → hosts/pi/events.ts} +14 -4
- package/src/extension/hosts/pi/history.ts +45 -0
- package/src/extension/{lifecycle.ts → hosts/pi/lifecycle.ts} +7 -11
- package/src/extension/{plugin-runtime.ts → hosts/plugin-runtime.ts} +29 -9
- package/src/extension/{mcp-bridge.ts → mcp/bridge.ts} +5 -5
- package/src/extension/{mcp-workers.ts → mcp/workers.ts} +237 -64
- package/src/extension/{setup-cli.ts → setup/cli.ts} +11 -11
- package/src/integrations/acp/connection.ts +6 -0
- package/src/integrations/acp/harnesses/claude.ts +1 -1
- package/src/integrations/acp/harnesses/dsh.ts +1 -1
- package/src/integrations/acp/history-summary.ts +108 -0
- package/src/integrations/agent-resources.ts +6 -0
- package/src/integrations/hosts/antigravity/adapter.ts +161 -0
- package/src/integrations/hosts/{claude.ts → claude/adapter.ts} +28 -5
- package/src/integrations/{dsh → hosts/dsh}/mcp.ts +1 -1
- package/src/integrations/{dsh → hosts/dsh}/resources.ts +5 -5
- package/src/integrations/{dsh → hosts/dsh}/schema.ts +1 -1
- package/src/integrations/{dsh → hosts/dsh}/session.ts +2 -2
- package/src/integrations/{dsh → hosts/dsh}/skills.ts +1 -1
- package/src/integrations/{pi → hosts/pi}/mcp.ts +1 -1
- package/src/integrations/{pi → hosts/pi}/skills.ts +1 -1
- package/src/integrations/hosts/{registry.ts → plugin-registry.ts} +2 -2
- package/src/integrations/installation/pi-setup.ts +1 -1
- package/src/mcp.ts +1 -1
- package/src/model/history.ts +151 -26
- package/src/model/plugin-host.ts +26 -2
- package/src/model/workspace-config.ts +30 -0
- package/src/pbot.ts +13 -22
- package/src/plugin.ts +2 -2
- package/src/services/history/history-capture.ts +83 -0
- package/src/services/history/history-index.ts +48 -62
- package/src/services/history/history-migrate.ts +89 -0
- package/src/services/history/history-query.ts +415 -0
- package/src/services/history/summary-command.ts +69 -0
- package/src/services/history/summary-dimensions/monthly.ts +139 -0
- package/src/services/history/summary-dimensions/session.ts +149 -0
- package/src/services/history/summary-registry.ts +44 -0
- package/src/services/history/summary-runner.ts +352 -0
- package/src/services/workspace/workspace-config.ts +91 -5
- package/src/storage/history-files.ts +408 -188
- package/src/storage/history-format.ts +46 -60
- package/src/tools/history/actions.ts +8 -6
- package/src/tools/history/contract.ts +65 -20
- package/src/tools/history/dsh-tool.ts +17 -8
- package/src/tools/history/pi-tool.ts +21 -0
- package/src/tools/register.ts +3 -4
- package/src/ui/dsh/management.ts +27 -11
- package/src/ui/{confirmation.ts → pi/confirmation.ts} +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.d.ts +0 -4
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.js +0 -79
- package/lib/extension/dsh/command.js +0 -50
- package/lib/extension/dsh/history.d.ts +0 -15
- package/lib/extension/dsh/history.js +0 -87
- package/lib/integrations/dsh/history-summary.d.ts +0 -11
- package/lib/integrations/dsh/history-summary.js +0 -36
- package/lib/integrations/dsh/history.d.ts +0 -16
- package/lib/integrations/dsh/history.js +0 -167
- package/lib/integrations/history-summary.d.ts +0 -4
- package/lib/integrations/history-summary.js +0 -32
- package/lib/integrations/hosts/antigravity.d.ts +0 -4
- package/lib/integrations/hosts/antigravity.js +0 -79
- package/lib/services/history/history-service.d.ts +0 -106
- package/lib/services/history/history-service.js +0 -242
- package/lib/storage/acp-history.d.ts +0 -10
- package/lib/storage/acp-history.js +0 -57
- package/src/extension/command.ts +0 -76
- package/src/extension/dsh/command.ts +0 -54
- package/src/extension/dsh/history.ts +0 -74
- package/src/extension/history.ts +0 -26
- package/src/integrations/dsh/history-summary.ts +0 -39
- package/src/integrations/dsh/history.ts +0 -84
- package/src/integrations/history-summary.ts +0 -30
- package/src/integrations/hosts/antigravity.ts +0 -83
- package/src/integrations/pi/history.ts +0 -99
- package/src/services/history/history-service.ts +0 -195
- package/src/storage/acp-history.ts +0 -49
- package/src/tools/history/tool.ts +0 -19
- /package/lib/antigravity-plugin/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +0 -0
- /package/lib/{extension/acp-worker.d.ts → antigravity-plugin/lib/model/history.js} +0 -0
- /package/lib/extension/{dsh → hosts/dsh}/acp-member.d.ts +0 -0
- /package/lib/extension/{dsh → hosts/dsh}/command.d.ts +0 -0
- /package/lib/extension/{dsh → hosts/dsh}/files.d.ts +0 -0
- /package/lib/extension/{setup-guard.js → setup/guard.js} +0 -0
- /package/lib/integrations/acp/{claude.d.ts → claude-settings.d.ts} +0 -0
- /package/lib/integrations/acp/{claude.js → claude-settings.js} +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/mcp.js +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/messages.d.ts +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/messages.js +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/root-agents.d.ts +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/root-agents.js +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/schema.d.ts +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/skills.d.ts +0 -0
- /package/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +0 -0
- /package/src/extension/{setup-guard.ts → setup/guard.ts} +0 -0
- /package/src/integrations/acp/{claude.ts → claude-settings.ts} +0 -0
- /package/src/integrations/{dsh → hosts/dsh}/messages.ts +0 -0
- /package/src/integrations/{dsh → hosts/dsh}/root-agents.ts +0 -0
- /package/src/integrations/{pi → hosts/pi}/agent-tools.ts +0 -0
|
@@ -3,16 +3,18 @@ import { realpath, stat } from "node:fs/promises";
|
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { isAbsolute, join } from "node:path";
|
|
5
5
|
import { setTimeout as delay } from "node:timers/promises";
|
|
6
|
-
import { object } from "
|
|
7
|
-
import { isAcpBackend, requireThat } from "
|
|
8
|
-
import { packageVersion } from "
|
|
9
|
-
import { AcpWorkerHost } from "
|
|
10
|
-
import { canonicalAcpBackend, inspectAcpBackends, knownAcpBackends } from "
|
|
11
|
-
import { mcpWorkerToolNames, } from "
|
|
12
|
-
import { workspaceMcpToolNames } from "
|
|
13
|
-
import { AgentService } from "
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
6
|
+
import { object } from "../../common/json.js";
|
|
7
|
+
import { isAcpBackend, requireThat } from "../../common/validation.js";
|
|
8
|
+
import { packageVersion } from "../../common/version.js";
|
|
9
|
+
import { AcpWorkerHost } from "../../integrations/acp/agents.js";
|
|
10
|
+
import { canonicalAcpBackend, inspectAcpBackends, knownAcpBackends } from "../../integrations/acp/launch.js";
|
|
11
|
+
import { mcpWorkerToolNames, } from "../../model/acp.js";
|
|
12
|
+
import { workspaceMcpToolNames } from "../../model/workspace-mcp.js";
|
|
13
|
+
import { AgentService } from "../../services/agents/agent-service.js";
|
|
14
|
+
import { readWorkspaceHistory, searchWorkspaceHistory } from "../../services/history/history-query.js";
|
|
15
|
+
import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../services/workspace/workspace-config.js";
|
|
16
|
+
import { isHistoryHost, isSummaryDimension } from "../../storage/history-format.js";
|
|
17
|
+
import { WorkspaceMcpBridge } from "./bridge.js";
|
|
16
18
|
const protocolVersion = "2025-03-26";
|
|
17
19
|
const readyTimeoutMs = 45_000;
|
|
18
20
|
const defaultWaitMs = 50_000;
|
|
@@ -21,7 +23,8 @@ const reportPageSize = 16_000;
|
|
|
21
23
|
const progressIntervalMs = 5_000;
|
|
22
24
|
const responseActions = ["accept", "decline", "cancel"];
|
|
23
25
|
const discoverTargets = ["overview", "workers", "backends", "models"];
|
|
24
|
-
const
|
|
26
|
+
const mcpHistoryToolNames = ["history_search", "history_read"];
|
|
27
|
+
const allMcpToolNames = [...mcpWorkerToolNames, ...workspaceMcpToolNames, ...mcpHistoryToolNames];
|
|
25
28
|
const toolParams = {
|
|
26
29
|
worker_create: new Set(["backend", "model", "thinking", "cwd", "workspace"]),
|
|
27
30
|
worker_close: new Set(["workerId", "workspace"]),
|
|
@@ -31,6 +34,8 @@ const toolParams = {
|
|
|
31
34
|
worker_discover: new Set(["target", "workerId", "backend", "model", "workspace"]),
|
|
32
35
|
workspace_mcp_discover: new Set(["server", "workspace"]),
|
|
33
36
|
workspace_mcp_call: new Set(["server", "tool", "arguments", "workspace"]),
|
|
37
|
+
history_search: new Set(["host", "dimension", "query", "sessionId", "from", "to", "offset", "limit", "workspace"]),
|
|
38
|
+
history_read: new Set(["id", "host", "offset", "limit", "childrenOffset", "workspace"]),
|
|
34
39
|
};
|
|
35
40
|
const shortToolMap = {
|
|
36
41
|
create: "worker_create",
|
|
@@ -40,9 +45,12 @@ const shortToolMap = {
|
|
|
40
45
|
output: "worker_output",
|
|
41
46
|
discover: "worker_discover",
|
|
42
47
|
};
|
|
43
|
-
export const
|
|
44
|
-
"
|
|
45
|
-
|
|
48
|
+
export const mcpWorkerOnlyInstructions = "提供跨助手协作能力(worker_*):可启动并调度其他外部 AI 助手在当前工作区中独立执行任务,适用于用户指定其他助手、需要特定模型或思考深度、获取独立审查/第二意见,或并行处理子任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。\n" +
|
|
49
|
+
"使用流程:用 worker_create 启动目标助手(或用 worker_discover 复用已有会话)→ 用 worker_request 派发任务或继续追问 → 任务完成后可用 worker_close 结束会话。后台等待、超时续等(timedOut)或长结果翻页(nextOffset)用 worker_output;助手请求授权或提问(needsResponse)时,先向用户确认,再用 worker_response 回复。";
|
|
50
|
+
export const mcpInstructions = "提供三类能力:\n" +
|
|
51
|
+
"1. 跨助手协作(worker_*):启动并调度其他外部 AI 助手在当前工作区中独立执行任务,适用于用户指定其他助手、需要特定模型或思考深度、获取独立审查/第二意见,或并行处理子任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。使用流程:worker_create 启动助手(或 worker_discover 复用已有会话)→ worker_request 派发任务或追问 → 完成后 worker_close 结束;后台等待、超时续等(timedOut)或长结果翻页(nextOffset)用 worker_output;返回 needsResponse 时先向用户确认,再用 worker_response 回复。\n" +
|
|
52
|
+
"2. 工作区共享外部工具(workspace_mcp_*):发现并调用当前工作区接入的外部工具服务与数据源(可与当前环境原生工具同时使用)。先用 workspace_mcp_discover 查看可用服务与工具说明,再用 workspace_mcp_call 调用。\n" +
|
|
53
|
+
"3. 跨宿主历史查询(history_search / history_read):只读检索当前工作区在 Pi、dsh、Claude Code、Antigravity 等宿主中记录的历史问答与摘要归档。";
|
|
46
54
|
function formatBackendItem(entry, defaultBackend) {
|
|
47
55
|
const tags = [];
|
|
48
56
|
if (entry.label)
|
|
@@ -59,9 +67,9 @@ function summarizeBackends(commands = {}, defaultBackend) {
|
|
|
59
67
|
const unavailableText = unavailable.map(item => formatBackendItem(item, defaultBackend)).join("、");
|
|
60
68
|
const overview = available.length
|
|
61
69
|
? unavailable.length
|
|
62
|
-
?
|
|
63
|
-
:
|
|
64
|
-
:
|
|
70
|
+
? `当前可用助手:${availableText};暂不可用:${unavailableText}。`
|
|
71
|
+
: `当前可用助手:${availableText}。`
|
|
72
|
+
: `当前无可用外部助手(暂不可用:${unavailableText})。`;
|
|
65
73
|
const availableIds = available.map(item => item.backend).join("、");
|
|
66
74
|
return { overview, availableIds };
|
|
67
75
|
}
|
|
@@ -69,8 +77,8 @@ function workspaceProperty(workspaceBound) {
|
|
|
69
77
|
return {
|
|
70
78
|
type: "string",
|
|
71
79
|
description: workspaceBound
|
|
72
|
-
? "
|
|
73
|
-
: "
|
|
80
|
+
? "目标工作区根目录的绝对路径;默认使用当前工作区,通常省略。"
|
|
81
|
+
: "目标工作区根目录的绝对路径(如上下文中提供了 workspaceRoot 则传该路径);请显式传入。",
|
|
74
82
|
};
|
|
75
83
|
}
|
|
76
84
|
export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = false) {
|
|
@@ -82,8 +90,8 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
82
90
|
return [
|
|
83
91
|
{
|
|
84
92
|
name: "worker_create",
|
|
85
|
-
description: "
|
|
86
|
-
"
|
|
93
|
+
description: "启动一个独立的外部 AI 助手会话(worker),用于将任务委派给其他助手或指定模型/思考深度来独立处理(如按用户要求切换助手、获取独立审查或第二意见、并行分担子任务)。" +
|
|
94
|
+
"本工具仅建立会话并返回 workerId,随后通过 worker_request 发送具体任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。\n" +
|
|
87
95
|
overview,
|
|
88
96
|
annotations: {
|
|
89
97
|
title: "Create Worker",
|
|
@@ -99,19 +107,19 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
99
107
|
properties: {
|
|
100
108
|
backend: {
|
|
101
109
|
type: "string",
|
|
102
|
-
description: "
|
|
110
|
+
description: "要启动的外部助手标识(不区分大小写,支持常见别名,如 claude-code、agy)。",
|
|
103
111
|
},
|
|
104
112
|
model: {
|
|
105
113
|
type: "string",
|
|
106
|
-
description: "
|
|
114
|
+
description: "仅用户明确要求特定模型时指定(支持模型 ID、显示名或 provider/model,不区分大小写);不确定可用值时先用 worker_discover(target=\"models\") 查询;不填则使用该助手默认模型。",
|
|
107
115
|
},
|
|
108
116
|
thinking: {
|
|
109
117
|
type: "string",
|
|
110
|
-
description: "
|
|
118
|
+
description: "仅用户明确要求思考深度时指定(如 low / medium / high / xhigh / max,不区分大小写);不填则使用默认设置。",
|
|
111
119
|
},
|
|
112
120
|
cwd: {
|
|
113
121
|
type: "string",
|
|
114
|
-
description: "
|
|
122
|
+
description: "助手执行任务时的工作目录(绝对路径或相对工作区的路径),默认为当前工作区根目录。",
|
|
115
123
|
},
|
|
116
124
|
workspace,
|
|
117
125
|
},
|
|
@@ -119,7 +127,7 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
119
127
|
},
|
|
120
128
|
{
|
|
121
129
|
name: "worker_close",
|
|
122
|
-
description: "
|
|
130
|
+
description: "结束不再需要的外部助手会话并释放资源。若该助手支持会话恢复,后续仍可直接用 worker_request 在原上下文中继续对话。",
|
|
123
131
|
annotations: {
|
|
124
132
|
title: "Close Worker",
|
|
125
133
|
readOnlyHint: false,
|
|
@@ -134,7 +142,7 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
134
142
|
properties: {
|
|
135
143
|
workerId: {
|
|
136
144
|
type: "string",
|
|
137
|
-
description: "
|
|
145
|
+
description: "要结束的助手会话 ID(来自 worker_create 或 worker_discover)。",
|
|
138
146
|
},
|
|
139
147
|
workspace,
|
|
140
148
|
},
|
|
@@ -142,9 +150,9 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
142
150
|
},
|
|
143
151
|
{
|
|
144
152
|
name: "worker_request",
|
|
145
|
-
description: "
|
|
146
|
-
`默认最多等待 ${defaultWaitMs / 1000}
|
|
147
|
-
"若返回 timedOut
|
|
153
|
+
description: "向指定的外部助手派发任务,或在同一上下文中追问与补充要求,并获取执行结果(已关闭但支持恢复的会话会自动续接)。" +
|
|
154
|
+
`默认最多等待 ${defaultWaitMs / 1000} 秒返回结果;将 waitMs 设为 0 可立即返回并转入后台执行,适合耗时任务或多助手并行。` +
|
|
155
|
+
"若返回 timedOut 或结果含 nextOffset,用 worker_output 继续等待或翻页;若返回 needsResponse,先向用户确认再用 worker_response 回复。",
|
|
148
156
|
annotations: {
|
|
149
157
|
title: "Send Request to Worker",
|
|
150
158
|
readOnlyHint: false,
|
|
@@ -159,17 +167,17 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
159
167
|
properties: {
|
|
160
168
|
workerId: {
|
|
161
169
|
type: "string",
|
|
162
|
-
description: "
|
|
170
|
+
description: "目标助手会话 ID(来自 worker_create 或 worker_discover)。",
|
|
163
171
|
},
|
|
164
172
|
message: {
|
|
165
173
|
type: "string",
|
|
166
|
-
description: "
|
|
174
|
+
description: "要发送的任务说明或追问内容。外部助手看不到你与用户的对话历史,首次派发时请写清背景、目标、相关文件路径、约束条件和期望产出。",
|
|
167
175
|
},
|
|
168
176
|
waitMs: {
|
|
169
177
|
type: "integer",
|
|
170
178
|
minimum: 0,
|
|
171
179
|
maximum: maxWaitMs,
|
|
172
|
-
description:
|
|
180
|
+
description: `最多等待结果的毫秒数(默认 ${defaultWaitMs});设为 0 可立即返回并在后台执行。`,
|
|
173
181
|
},
|
|
174
182
|
workspace,
|
|
175
183
|
},
|
|
@@ -177,8 +185,9 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
177
185
|
},
|
|
178
186
|
{
|
|
179
187
|
name: "worker_response",
|
|
180
|
-
description: "
|
|
181
|
-
|
|
188
|
+
description: "当外部助手在执行过程中暂停并请求确认或补充信息(返回 needsResponse: true)时,向其提交决定以继续执行。" +
|
|
189
|
+
"支持三类请求:操作授权(kind=\"permission\")、问答表单(kind=\"form\")和链接确认(kind=\"url\")。" +
|
|
190
|
+
`提交前先向用户确认;提交后默认最多等待 ${defaultWaitMs / 1000} 秒返回后续结果(waitMs 设为 0 立即返回)。`,
|
|
182
191
|
annotations: {
|
|
183
192
|
title: "Respond to Worker Request",
|
|
184
193
|
readOnlyHint: false,
|
|
@@ -193,31 +202,31 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
193
202
|
properties: {
|
|
194
203
|
workerId: {
|
|
195
204
|
type: "string",
|
|
196
|
-
description: "
|
|
205
|
+
description: "等待回复的助手会话 ID。",
|
|
197
206
|
},
|
|
198
207
|
action: {
|
|
199
208
|
type: "string",
|
|
200
209
|
enum: [...responseActions],
|
|
201
|
-
description: "accept
|
|
210
|
+
description: "处理方式:accept 表示同意授权、提交表单回答或确认链接;decline 表示拒绝;cancel 表示取消本次请求。",
|
|
202
211
|
},
|
|
203
212
|
requestId: {
|
|
204
213
|
type: "string",
|
|
205
|
-
description: "
|
|
214
|
+
description: "要回复的请求 ID(来自 pendingRequests[].requestId);仅一条待处理请求时可省略,多条时必填。",
|
|
206
215
|
},
|
|
207
216
|
optionId: {
|
|
208
217
|
type: "string",
|
|
209
|
-
description: "
|
|
218
|
+
description: "仅授权请求(kind=\"permission\")且 action 不为 cancel 时可用:指定选项 ID(来自 pendingRequests[].options[].optionId),省略时默认单次允许或拒绝。",
|
|
210
219
|
},
|
|
211
220
|
content: {
|
|
212
221
|
type: "object",
|
|
213
222
|
additionalProperties: true,
|
|
214
|
-
description: "
|
|
223
|
+
description: "仅表单提问(kind=\"form\")且 action=\"accept\" 时可用:按 pendingRequests[].schema.properties 填写的回答对象(值为字符串、数字、布尔值或字符串数组)。",
|
|
215
224
|
},
|
|
216
225
|
waitMs: {
|
|
217
226
|
type: "integer",
|
|
218
227
|
minimum: 0,
|
|
219
228
|
maximum: maxWaitMs,
|
|
220
|
-
description:
|
|
229
|
+
description: `提交回复后最多等待后续结果的毫秒数(默认 ${defaultWaitMs});设为 0 立即返回。`,
|
|
221
230
|
},
|
|
222
231
|
workspace,
|
|
223
232
|
},
|
|
@@ -225,7 +234,8 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
225
234
|
},
|
|
226
235
|
{
|
|
227
236
|
name: "worker_output",
|
|
228
|
-
description: "
|
|
237
|
+
description: "获取或等待外部助手的最新执行结果。用于收取后台任务的产出、在等待超时(timedOut)后继续等待,或在长结果分页(含 nextOffset)时读取后续内容。" +
|
|
238
|
+
"任务仍在运行时会等待其完成(也可能返回 timedOut 或 needsResponse),已结束则立即返回。",
|
|
229
239
|
annotations: {
|
|
230
240
|
title: "Get Worker Output",
|
|
231
241
|
readOnlyHint: true,
|
|
@@ -240,18 +250,18 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
240
250
|
properties: {
|
|
241
251
|
workerId: {
|
|
242
252
|
type: "string",
|
|
243
|
-
description: "
|
|
253
|
+
description: "要等待或获取结果的助手会话 ID。",
|
|
244
254
|
},
|
|
245
255
|
offset: {
|
|
246
256
|
type: "integer",
|
|
247
257
|
minimum: 0,
|
|
248
|
-
description: "
|
|
258
|
+
description: "结果读取起始位置(默认 0);翻页读取剩余内容时传入上次返回的 nextOffset。",
|
|
249
259
|
},
|
|
250
260
|
waitMs: {
|
|
251
261
|
type: "integer",
|
|
252
262
|
minimum: 0,
|
|
253
263
|
maximum: maxWaitMs,
|
|
254
|
-
description: `任务仍在运行时最多等待的毫秒数(默认 ${defaultWaitMs}
|
|
264
|
+
description: `任务仍在运行时最多等待的毫秒数(默认 ${defaultWaitMs});任务已结束或翻页读取时会立即返回。`,
|
|
255
265
|
},
|
|
256
266
|
workspace,
|
|
257
267
|
},
|
|
@@ -259,8 +269,8 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
259
269
|
},
|
|
260
270
|
{
|
|
261
271
|
name: "worker_discover",
|
|
262
|
-
description: "
|
|
263
|
-
"默认(target=\"overview\"
|
|
272
|
+
description: "了解当前可以委派哪些外部助手、查看已有助手会话的运行状态以便复用,或查询某个助手支持的模型与思考深度选项。" +
|
|
273
|
+
"默认(target=\"overview\")同时返回可用助手与已有会话;仅在需要核对模型或思考深度可选值时再查 target=\"models\"(耗时较长)。",
|
|
264
274
|
annotations: {
|
|
265
275
|
title: "Discover Workers, Backends & Models",
|
|
266
276
|
readOnlyHint: true,
|
|
@@ -276,21 +286,21 @@ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBou
|
|
|
276
286
|
target: {
|
|
277
287
|
type: "string",
|
|
278
288
|
enum: [...discoverTargets],
|
|
279
|
-
description: "查询范围,默认 \"overview\"
|
|
289
|
+
description: "查询范围,默认 \"overview\"(同时返回可用助手与已有会话);\"workers\" 查全部或单个会话状态;\"backends\" 查可用助手列表;\"models\" 查指定助手支持的模型与思考深度。",
|
|
280
290
|
},
|
|
281
291
|
workerId: {
|
|
282
292
|
type: "string",
|
|
283
|
-
description: "仅 target=\"workers\"
|
|
293
|
+
description: "仅 target=\"workers\" 可用:指定单个助手会话 ID;不填则列出全部。",
|
|
284
294
|
},
|
|
285
295
|
backend: {
|
|
286
296
|
type: "string",
|
|
287
297
|
description: availableIds
|
|
288
|
-
? `仅 target="models" 可用(${modelsBackendHint}
|
|
289
|
-
: `仅 target="models" 可用(${modelsBackendHint}
|
|
298
|
+
? `仅 target="models" 可用(${modelsBackendHint}):目标外部助手标识,支持常见别名;当前可用:${availableIds}。`
|
|
299
|
+
: `仅 target="models" 可用(${modelsBackendHint}):目标外部助手标识,支持常见别名。`,
|
|
290
300
|
},
|
|
291
301
|
model: {
|
|
292
302
|
type: "string",
|
|
293
|
-
description: "仅 target=\"models\"
|
|
303
|
+
description: "仅 target=\"models\" 可用:指定模型以查看该模型支持的思考深度选项。",
|
|
294
304
|
},
|
|
295
305
|
workspace,
|
|
296
306
|
},
|
|
@@ -303,7 +313,7 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
303
313
|
return [
|
|
304
314
|
{
|
|
305
315
|
name: "workspace_mcp_discover",
|
|
306
|
-
description: "
|
|
316
|
+
description: "发现当前工作区共享的外部工具服务(MCP)及其可用工具。不传 server 时列出可用服务;传入 server 时返回该服务提供的工具清单与参数说明。",
|
|
307
317
|
annotations: {
|
|
308
318
|
title: "Discover Workspace MCP Servers & Tools",
|
|
309
319
|
readOnlyHint: true,
|
|
@@ -318,7 +328,7 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
318
328
|
properties: {
|
|
319
329
|
server: {
|
|
320
330
|
type: "string",
|
|
321
|
-
description: "
|
|
331
|
+
description: "目标工具服务名称;不填时列出工作区全部可用服务。",
|
|
322
332
|
},
|
|
323
333
|
workspace,
|
|
324
334
|
},
|
|
@@ -326,8 +336,8 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
326
336
|
},
|
|
327
337
|
{
|
|
328
338
|
name: "workspace_mcp_call",
|
|
329
|
-
description: "
|
|
330
|
-
"
|
|
339
|
+
description: "调用当前工作区共享的外部工具服务(MCP)中的指定工具,用于访问工作区接入的外部能力与数据源。" +
|
|
340
|
+
"不确定工具名或参数格式时,先用 workspace_mcp_discover(server) 查询。",
|
|
331
341
|
annotations: {
|
|
332
342
|
title: "Call Workspace MCP Tool",
|
|
333
343
|
readOnlyHint: false,
|
|
@@ -342,16 +352,118 @@ export function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
342
352
|
properties: {
|
|
343
353
|
server: {
|
|
344
354
|
type: "string",
|
|
345
|
-
description: "
|
|
355
|
+
description: "目标工具服务名称(可通过 workspace_mcp_discover 获取)。",
|
|
346
356
|
},
|
|
347
357
|
tool: {
|
|
348
358
|
type: "string",
|
|
349
|
-
description: "
|
|
359
|
+
description: "要调用的工具名称。",
|
|
350
360
|
},
|
|
351
361
|
arguments: {
|
|
352
362
|
type: "object",
|
|
353
363
|
additionalProperties: true,
|
|
354
|
-
description: "
|
|
364
|
+
description: "传给目标工具的参数对象,不填则为空对象。",
|
|
365
|
+
},
|
|
366
|
+
workspace,
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
];
|
|
371
|
+
}
|
|
372
|
+
export function buildHistoryMcpTools(workspaceBound = false) {
|
|
373
|
+
const workspace = workspaceProperty(workspaceBound);
|
|
374
|
+
return [
|
|
375
|
+
{
|
|
376
|
+
name: "history_search",
|
|
377
|
+
description: "搜索当前工作区跨宿主(pi、dsh、claude、antigravity 等)的历史问答与摘要归档。省略 query 时列出各会话;传入 query 按不区分大小写的连续关键词匹配原文与摘要。",
|
|
378
|
+
annotations: {
|
|
379
|
+
title: "Search Workspace History",
|
|
380
|
+
readOnlyHint: true,
|
|
381
|
+
destructiveHint: false,
|
|
382
|
+
idempotentHint: true,
|
|
383
|
+
openWorldHint: false,
|
|
384
|
+
},
|
|
385
|
+
inputSchema: {
|
|
386
|
+
type: "object",
|
|
387
|
+
additionalProperties: false,
|
|
388
|
+
required: [],
|
|
389
|
+
properties: {
|
|
390
|
+
host: {
|
|
391
|
+
type: "string",
|
|
392
|
+
description: "可选来源筛选(如 pi、dsh、claude、antigravity);省略查全部宿主。",
|
|
393
|
+
},
|
|
394
|
+
dimension: {
|
|
395
|
+
type: "string",
|
|
396
|
+
description: "可选范围筛选:raw 表示仅搜原文,或指定摘要维度(如 monthly、session);省略查全部原文与维度摘要。",
|
|
397
|
+
},
|
|
398
|
+
query: {
|
|
399
|
+
type: "string",
|
|
400
|
+
description: "不区分大小写的连续关键词;省略时列出各会话(或指定维度摘要)。",
|
|
401
|
+
},
|
|
402
|
+
sessionId: {
|
|
403
|
+
type: "string",
|
|
404
|
+
description: "限定在指定原始会话 ID 内搜索。",
|
|
405
|
+
},
|
|
406
|
+
from: {
|
|
407
|
+
type: "string",
|
|
408
|
+
description: "ISO 日期或时间下界。",
|
|
409
|
+
},
|
|
410
|
+
to: {
|
|
411
|
+
type: "string",
|
|
412
|
+
description: "ISO 日期或时间上界。",
|
|
413
|
+
},
|
|
414
|
+
offset: {
|
|
415
|
+
type: "integer",
|
|
416
|
+
minimum: 0,
|
|
417
|
+
description: "匹配结果偏移,默认 0。",
|
|
418
|
+
},
|
|
419
|
+
limit: {
|
|
420
|
+
type: "integer",
|
|
421
|
+
minimum: 1,
|
|
422
|
+
maximum: 50,
|
|
423
|
+
description: "最多返回条数(1–50),默认 20。",
|
|
424
|
+
},
|
|
425
|
+
workspace,
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
name: "history_read",
|
|
431
|
+
description: "按节点 id 读取当前工作区历史归档的正文与上下级节点(monthly、session、summary、exchange),支持从月度汇总下钻至单会话摘要与原始问答。正文过长时用 nextOffset 续读,子节点过多时用 nextChildrenOffset 续读。",
|
|
432
|
+
annotations: {
|
|
433
|
+
title: "Read Workspace History Node",
|
|
434
|
+
readOnlyHint: true,
|
|
435
|
+
destructiveHint: false,
|
|
436
|
+
idempotentHint: true,
|
|
437
|
+
openWorldHint: false,
|
|
438
|
+
},
|
|
439
|
+
inputSchema: {
|
|
440
|
+
type: "object",
|
|
441
|
+
additionalProperties: false,
|
|
442
|
+
required: ["id"],
|
|
443
|
+
properties: {
|
|
444
|
+
id: {
|
|
445
|
+
type: "string",
|
|
446
|
+
description: "history_search 或上下级返回的节点 id。",
|
|
447
|
+
},
|
|
448
|
+
host: {
|
|
449
|
+
type: "string",
|
|
450
|
+
description: "跨来源 ID 冲突时显式指定来源宿主。",
|
|
451
|
+
},
|
|
452
|
+
offset: {
|
|
453
|
+
type: "integer",
|
|
454
|
+
minimum: 0,
|
|
455
|
+
description: "正文字符偏移,默认 0。",
|
|
456
|
+
},
|
|
457
|
+
limit: {
|
|
458
|
+
type: "integer",
|
|
459
|
+
minimum: 1,
|
|
460
|
+
maximum: 24000,
|
|
461
|
+
description: "正文字符数(1–24000),默认 12000。",
|
|
462
|
+
},
|
|
463
|
+
childrenOffset: {
|
|
464
|
+
type: "integer",
|
|
465
|
+
minimum: 0,
|
|
466
|
+
description: "子节点列表偏移,默认 0;续读传上页 nextChildrenOffset。",
|
|
355
467
|
},
|
|
356
468
|
workspace,
|
|
357
469
|
},
|
|
@@ -494,11 +606,21 @@ export class McpWorkerRuntime {
|
|
|
494
606
|
#sessionId;
|
|
495
607
|
#directory;
|
|
496
608
|
#defaultBackend;
|
|
609
|
+
#nativeWorkspaceMcp;
|
|
610
|
+
#nativeHistory;
|
|
497
611
|
#closed = false;
|
|
498
|
-
constructor(directory = defaultWorkerDirectory(), sessionId = process.env.PBOT_MCP_SESSION_ID || ("mcp-" + randomUUID()), defaultBackend = process.env.PBOT_HOST || undefined) {
|
|
612
|
+
constructor(directory = defaultWorkerDirectory(), sessionId = process.env.PBOT_MCP_SESSION_ID || ("mcp-" + randomUUID()), defaultBackend = process.env.PBOT_HOST || undefined, nativeWorkspaceMcp = /^(1|true)$/i.test(process.env.PBOT_NATIVE_WORKSPACE_MCP ?? ""), nativeHistory = /^(1|true)$/i.test(process.env.PBOT_NATIVE_HISTORY ?? "")) {
|
|
499
613
|
this.#directory = directory;
|
|
500
614
|
this.#sessionId = sessionId;
|
|
501
615
|
this.#defaultBackend = defaultBackend?.trim() || undefined;
|
|
616
|
+
this.#nativeWorkspaceMcp = nativeWorkspaceMcp;
|
|
617
|
+
this.#nativeHistory = nativeHistory;
|
|
618
|
+
}
|
|
619
|
+
get nativeWorkspaceMcp() {
|
|
620
|
+
return this.#nativeWorkspaceMcp;
|
|
621
|
+
}
|
|
622
|
+
get nativeHistory() {
|
|
623
|
+
return this.#nativeHistory;
|
|
502
624
|
}
|
|
503
625
|
resolveBackend(rawArgs, commands, allowDefault) {
|
|
504
626
|
const raw = asString(rawArgs, "backend") ?? (allowDefault ? this.#defaultBackend : undefined);
|
|
@@ -536,13 +658,16 @@ export class McpWorkerRuntime {
|
|
|
536
658
|
}
|
|
537
659
|
async toolDefinitions() {
|
|
538
660
|
let commands;
|
|
539
|
-
let includeWorkspaceMcp =
|
|
661
|
+
let includeWorkspaceMcp = !this.#nativeWorkspaceMcp;
|
|
662
|
+
let includeHistory = !this.#nativeHistory;
|
|
540
663
|
try {
|
|
541
664
|
const root = await this.resolveWorkspace();
|
|
542
665
|
const configuration = await readWorkspaceConfig(root);
|
|
543
666
|
if (configuration.enabled) {
|
|
544
667
|
commands = configuration.acp;
|
|
545
|
-
|
|
668
|
+
const features = workspaceFeatures(configuration);
|
|
669
|
+
includeWorkspaceMcp = !this.#nativeWorkspaceMcp && features.mcp;
|
|
670
|
+
includeHistory = !this.#nativeHistory && features.history;
|
|
546
671
|
}
|
|
547
672
|
}
|
|
548
673
|
catch { /* Fall back to registered built-in harnesses when cwd is outside an enabled workspace. */ }
|
|
@@ -551,6 +676,7 @@ export class McpWorkerRuntime {
|
|
|
551
676
|
return [
|
|
552
677
|
...buildPbotWorkerTools(commands, defaultBackend, workspaceBound),
|
|
553
678
|
...(includeWorkspaceMcp ? buildWorkspaceMcpTools(workspaceBound) : []),
|
|
679
|
+
...(includeHistory ? buildHistoryMcpTools(workspaceBound) : []),
|
|
554
680
|
];
|
|
555
681
|
}
|
|
556
682
|
/** Wait until ACP handshake and model/thinking configuration finish so invalid options fail synchronously on create/resume. */
|
|
@@ -635,11 +761,13 @@ export class McpWorkerRuntime {
|
|
|
635
761
|
const { root, configuration, host, service, owner } = await this.workspace(asString(rawArgs, "workspace"));
|
|
636
762
|
switch (name) {
|
|
637
763
|
case "workspace_mcp_discover": {
|
|
764
|
+
requireThat(!this.#nativeWorkspaceMcp, "当前宿主已原生挂载工作区 .pbot/mcp.json 服务,请直接调用对应原生 MCP 工具,勿重复经由 workspace_mcp_* 桥接。");
|
|
638
765
|
requireThat(workspaceFeatures(configuration).mcp, `工作区统一 MCP 功能已在 ${configuration.path} 中停用(features.mcp: false)。`);
|
|
639
766
|
const server = asString(rawArgs, "server");
|
|
640
767
|
return this.#bridge.discover(root, server);
|
|
641
768
|
}
|
|
642
769
|
case "workspace_mcp_call": {
|
|
770
|
+
requireThat(!this.#nativeWorkspaceMcp, "当前宿主已原生挂载工作区 .pbot/mcp.json 服务,请直接调用对应原生 MCP 工具,勿重复经由 workspace_mcp_* 桥接。");
|
|
643
771
|
requireThat(workspaceFeatures(configuration).mcp, `工作区统一 MCP 功能已在 ${configuration.path} 中停用(features.mcp: false)。`);
|
|
644
772
|
const server = asString(rawArgs, "server", true);
|
|
645
773
|
const tool = asString(rawArgs, "tool", true);
|
|
@@ -647,6 +775,44 @@ export class McpWorkerRuntime {
|
|
|
647
775
|
requireThat(object(toolArgs), "参数 arguments 必须是 JSON 对象。");
|
|
648
776
|
return this.#bridge.call(root, server, tool, toolArgs);
|
|
649
777
|
}
|
|
778
|
+
case "history_search": {
|
|
779
|
+
requireThat(!this.#nativeHistory, "当前宿主已提供原生 pbot_history 工具,请直接调用 pbot_history。");
|
|
780
|
+
requireThat(workspaceFeatures(configuration).history, `工作区历史功能已在 ${configuration.path} 中停用(features.history: false)。`);
|
|
781
|
+
const hostFilter = asString(rawArgs, "host");
|
|
782
|
+
if (hostFilter !== undefined)
|
|
783
|
+
requireThat(isHistoryHost(hostFilter), "无效的 host 来源:" + hostFilter);
|
|
784
|
+
const dimension = asString(rawArgs, "dimension");
|
|
785
|
+
if (dimension !== undefined)
|
|
786
|
+
requireThat(isSummaryDimension(dimension), "无效的 dimension:" + dimension);
|
|
787
|
+
const query = asString(rawArgs, "query");
|
|
788
|
+
const sessionId = asString(rawArgs, "sessionId");
|
|
789
|
+
const from = asString(rawArgs, "from");
|
|
790
|
+
const to = asString(rawArgs, "to");
|
|
791
|
+
const offset = asInt(rawArgs, "offset", 0, 10_000_000) ?? 0;
|
|
792
|
+
const limit = asInt(rawArgs, "limit", 1, 50) ?? 20;
|
|
793
|
+
return searchWorkspaceHistory(root, {
|
|
794
|
+
...(hostFilter ? { host: hostFilter } : {}),
|
|
795
|
+
...(dimension ? { dimension } : {}),
|
|
796
|
+
...(query ? { query } : {}),
|
|
797
|
+
...(sessionId ? { sessionId } : {}),
|
|
798
|
+
...(from ? { from } : {}),
|
|
799
|
+
...(to ? { to } : {}),
|
|
800
|
+
offset,
|
|
801
|
+
limit,
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
case "history_read": {
|
|
805
|
+
requireThat(!this.#nativeHistory, "当前宿主已提供原生 pbot_history 工具,请直接调用 pbot_history。");
|
|
806
|
+
requireThat(workspaceFeatures(configuration).history, `工作区历史功能已在 ${configuration.path} 中停用(features.history: false)。`);
|
|
807
|
+
const id = asString(rawArgs, "id", true);
|
|
808
|
+
const hostFilter = asString(rawArgs, "host");
|
|
809
|
+
if (hostFilter !== undefined)
|
|
810
|
+
requireThat(isHistoryHost(hostFilter), "无效的 host 来源:" + hostFilter);
|
|
811
|
+
const offset = asInt(rawArgs, "offset", 0, 10_000_000) ?? 0;
|
|
812
|
+
const limit = asInt(rawArgs, "limit", 1, 24000) ?? 12000;
|
|
813
|
+
const childrenOffset = asInt(rawArgs, "childrenOffset", 0, 10_000_000) ?? 0;
|
|
814
|
+
return { node: readWorkspaceHistory(root, id, offset, limit, childrenOffset, hostFilter) };
|
|
815
|
+
}
|
|
650
816
|
case "worker_create": {
|
|
651
817
|
const backend = this.resolveBackend(rawArgs, configuration.acp, false);
|
|
652
818
|
const model = asString(rawArgs, "model");
|
|
@@ -786,7 +952,7 @@ export async function handleMcpRequest(runtime, message, notify) {
|
|
|
786
952
|
protocolVersion: requested || protocolVersion,
|
|
787
953
|
capabilities: { tools: {} },
|
|
788
954
|
serverInfo: { name: "personal-bot", version: packageVersion },
|
|
789
|
-
instructions: mcpInstructions,
|
|
955
|
+
instructions: runtime.nativeWorkspaceMcp ? mcpWorkerOnlyInstructions : mcpInstructions,
|
|
790
956
|
},
|
|
791
957
|
};
|
|
792
958
|
}
|