personal-bot 0.3.2 → 0.3.4
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 +2 -1
- package/DISCLAIMER.md +17 -0
- package/LICENSE +21 -0
- package/README.md +15 -5
- package/README.zh-CN.md +15 -5
- package/bin/pbot-pi-acp.mjs +1 -1
- package/bin/pbot.mjs +22 -2
- package/docs/README.md +2 -0
- package/docs/architecture/design.md +16 -16
- package/docs/architecture/extensibility.md +29 -2
- package/docs/architecture/model-context.md +3 -2
- package/docs/architecture/principles.md +2 -2
- package/docs/guides/capabilities.md +1 -1
- package/docs/guides/cross-harness-workers.md +3 -1
- package/docs/guides/history.md +30 -7
- package/docs/guides/workspace-configuration.md +20 -3
- package/docs/hosts/antigravity.md +1 -1
- package/docs/hosts/claude-code.md +1 -1
- package/docs/hosts/codex-qoder.md +63 -0
- package/docs/maintainers/architecture-governance.md +78 -0
- package/lib/antigravity-plugin/DISCLAIMER.md +17 -0
- package/lib/antigravity-plugin/LICENSE +21 -0
- package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +36 -0
- package/lib/antigravity-plugin/lib/common/files.d.ts +2 -0
- package/lib/antigravity-plugin/lib/common/files.js +44 -0
- package/lib/antigravity-plugin/lib/common/validation.d.ts +4 -0
- package/lib/antigravity-plugin/lib/common/validation.js +8 -0
- package/lib/antigravity-plugin/lib/extension/acp/member.d.ts +18 -0
- package/lib/antigravity-plugin/lib/extension/acp/member.js +44 -0
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +71 -45
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.js +22 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.d.ts +4 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.js +58 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.d.ts +5 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.js +67 -0
- package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.d.ts +3 -0
- package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +100 -0
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.d.ts +3 -1
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +37 -22
- package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.d.ts +6 -0
- package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.js +21 -0
- package/lib/antigravity-plugin/lib/extension/mcp.js +2577 -2255
- package/lib/antigravity-plugin/lib/extension/workspace-cli.js +20171 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +7 -59
- package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.d.ts +2 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.js +14 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.js +28 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.d.ts +36 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.js +11 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.d.ts +6 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.js +47 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.js +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.d.ts +8 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.js +31 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.js +32 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.js +23 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.d.ts +1 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.js +8 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.js +76 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.js +16 -0
- package/lib/antigravity-plugin/lib/model/acp.d.ts +7 -3
- package/lib/antigravity-plugin/lib/model/acp.js +8 -0
- package/lib/antigravity-plugin/lib/model/agent.d.ts +121 -0
- package/lib/antigravity-plugin/lib/model/agent.js +4 -0
- package/lib/antigravity-plugin/lib/model/history.d.ts +10 -0
- package/lib/antigravity-plugin/lib/model/history.js +4 -1
- package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +5 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +8 -12
- package/lib/antigravity-plugin/lib/model/workspace-config.js +2 -1
- package/lib/antigravity-plugin/lib/plugin.d.ts +2 -1
- package/lib/antigravity-plugin/lib/plugin.js +2 -2
- package/lib/antigravity-plugin/lib/services/history/history-capture.js +34 -22
- package/lib/antigravity-plugin/lib/services/history/summary-registry.js +2 -3
- package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +2 -5
- package/lib/antigravity-plugin/lib/services/history/summary-runner.js +72 -74
- package/lib/antigravity-plugin/lib/services/history/workspace-history.d.ts +3 -0
- package/lib/antigravity-plugin/lib/services/history/workspace-history.js +6 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +15 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +126 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +9 -8
- package/lib/antigravity-plugin/lib/services/workspace/workspace-files.d.ts +2 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-files.js +17 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.d.ts +14 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.js +193 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.d.ts +1 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.js +4 -2
- package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +11 -0
- package/lib/antigravity-plugin/lib/storage/acp-files.js +75 -0
- package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +31 -0
- package/lib/antigravity-plugin/lib/storage/agent-files.js +159 -0
- package/lib/antigravity-plugin/lib/storage/atomic-json.d.ts +3 -1
- package/lib/antigravity-plugin/lib/storage/atomic-json.js +43 -3
- package/lib/antigravity-plugin/lib/storage/history-files.d.ts +2 -1
- package/lib/antigravity-plugin/lib/storage/history-files.js +21 -15
- package/lib/antigravity-plugin/lib/storage/history-format.d.ts +2 -3
- package/lib/antigravity-plugin/lib/storage/history-format.js +5 -7
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +1 -1
- package/lib/antigravity-plugin/resources/prompts/history-monthly-summary.md +13 -0
- package/lib/antigravity-plugin/resources/prompts/history-summary.md +13 -0
- package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -0
- package/lib/antigravity-plugin/resources/skills/.claude-plugin/plugin.json +4 -0
- package/lib/antigravity-plugin/resources/skills/project-maintenance/SKILL.md +35 -0
- package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +52 -0
- package/lib/antigravity-plugin/skills/pbot/SKILL.md +11 -1
- package/lib/client.js +22 -50
- package/lib/codex-marketplace/.agents/plugins/marketplace.json +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +7 -0
- package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/DISCLAIMER.md +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/LICENSE +21 -0
- package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +37 -0
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +9 -0
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/agents/openai.yaml +2 -0
- package/lib/common/validation.d.ts +4 -0
- package/lib/common/validation.js +8 -0
- package/lib/dsh.js +2 -2
- package/lib/extension/acp/member.d.ts +1 -1
- package/lib/extension/acp-worker.js +71 -45
- package/lib/extension/history/command.d.ts +37 -0
- package/lib/extension/history/command.js +57 -0
- package/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
- package/lib/extension/hosts/dsh/acp-entry.js +22 -0
- package/lib/extension/hosts/dsh/acp-member.js +4 -18
- package/lib/extension/hosts/dsh/command.d.ts +1 -2
- package/lib/extension/hosts/dsh/command.js +5 -49
- package/lib/extension/hosts/dsh/workspace.js +13 -44
- package/lib/extension/hosts/pi/acp-member.d.ts +3 -0
- package/lib/extension/hosts/pi/acp-member.js +100 -0
- package/lib/extension/hosts/plugin-runtime.d.ts +3 -1
- package/lib/extension/hosts/plugin-runtime.js +37 -22
- package/lib/extension/hosts/workspace-mcp.d.ts +6 -0
- package/lib/extension/hosts/workspace-mcp.js +21 -0
- package/lib/extension/mcp/bridge.d.ts +6 -8
- package/lib/extension/mcp/bridge.js +66 -84
- package/lib/extension/mcp/tool-contract.d.ts +735 -0
- package/lib/extension/mcp/tool-contract.js +441 -0
- package/lib/extension/mcp/workers.d.ts +29 -742
- package/lib/extension/mcp/workers.js +75 -525
- package/lib/extension/mcp.js +2577 -2255
- package/lib/extension/setup/cli.js +15 -0
- package/lib/extension/setup/upgrade.js +153 -0
- package/lib/extension/workspace-cli.js +20171 -0
- package/lib/integrations/acp/agents.d.ts +2 -3
- package/lib/integrations/acp/harnesses/dsh.js +1 -1
- package/lib/integrations/acp/harnesses/presets.js +8 -0
- package/lib/integrations/acp/history-summary.js +2 -1
- package/lib/integrations/acp/launch.d.ts +2 -2
- package/lib/integrations/agent-resources.js +1 -1
- package/lib/integrations/hosts/claude/adapter.js +7 -59
- package/lib/integrations/hosts/codex/adapter.d.ts +2 -0
- package/lib/integrations/hosts/codex/adapter.js +14 -0
- package/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
- package/lib/integrations/hosts/pi/agent-tools.js +32 -0
- package/lib/integrations/hosts/pi/mcp.d.ts +4 -0
- package/lib/integrations/hosts/pi/mcp.js +23 -0
- package/lib/integrations/hosts/plugin-registry.d.ts +1 -0
- package/lib/integrations/hosts/plugin-registry.js +8 -1
- package/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
- package/lib/integrations/hosts/prompt-hooks.js +76 -0
- package/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
- package/lib/integrations/hosts/qoder/adapter.js +16 -0
- package/lib/integrations/installation/cli-update.js +146 -0
- package/lib/integrations/installation/upgraders/antigravity.js +67 -0
- package/lib/integrations/installation/upgraders/claude.js +123 -0
- package/lib/integrations/installation/upgraders/codex.js +73 -0
- package/lib/integrations/installation/upgraders/dsh.js +62 -0
- package/lib/integrations/installation/upgraders/pi.js +90 -0
- package/lib/integrations/installation/upgraders/qoder.js +67 -0
- package/lib/integrations/installation/upgraders/registry.js +40 -0
- package/lib/model/acp.d.ts +7 -3
- package/lib/model/acp.js +8 -0
- package/lib/model/agent.d.ts +18 -4
- package/lib/model/agent.js +4 -1
- package/lib/model/history.d.ts +10 -0
- package/lib/model/history.js +4 -1
- package/lib/model/installation.js +1 -0
- package/lib/model/plugin-host.d.ts +5 -0
- package/lib/model/workspace-config.d.ts +8 -12
- package/lib/model/workspace-config.js +2 -1
- package/lib/plugin.d.ts +2 -1
- package/lib/plugin.js +2 -2
- package/lib/qoder-plugin/.mcp.json +17 -0
- package/lib/qoder-plugin/.qoder-plugin/plugin.json +7 -0
- package/lib/qoder-plugin/DISCLAIMER.md +17 -0
- package/lib/qoder-plugin/LICENSE +21 -0
- package/lib/qoder-plugin/hooks/hooks.json +37 -0
- package/lib/qoder-plugin/skills/pbot/SKILL.md +9 -0
- package/lib/services/agents/agent-service.d.ts +15 -45
- package/lib/services/agents/agent-service.js +22 -3
- package/lib/services/history/history-capture.js +34 -22
- package/lib/services/history/history-migrate.js +26 -60
- package/lib/services/history/history-query.js +38 -57
- package/lib/services/history/summary-command.d.ts +1 -1
- package/lib/services/history/summary-command.js +8 -7
- package/lib/services/history/summary-registry.js +2 -3
- package/lib/services/history/summary-runner.d.ts +2 -5
- package/lib/services/history/summary-runner.js +72 -74
- package/lib/services/history/workspace-history.d.ts +3 -0
- package/lib/services/history/workspace-history.js +6 -0
- package/lib/services/installation/setup-service.js +4 -1
- package/lib/services/installation/upgrade-service.js +95 -0
- package/lib/services/workspace/plugin-releases.d.ts +15 -0
- package/lib/services/workspace/plugin-releases.js +126 -0
- package/lib/services/workspace/workspace-config.js +9 -8
- package/lib/services/workspace/workspace-mcp.js +22 -29
- package/lib/services/workspace/workspace-skills.d.ts +1 -0
- package/lib/services/workspace/workspace-skills.js +4 -2
- package/lib/storage/acp-files.js +7 -12
- package/lib/storage/agent-files.js +6 -5
- package/lib/storage/atomic-json.d.ts +3 -1
- package/lib/storage/atomic-json.js +43 -3
- package/lib/storage/history-files.d.ts +2 -1
- package/lib/storage/history-files.js +21 -15
- package/lib/storage/history-format.d.ts +2 -3
- package/lib/storage/history-format.js +5 -7
- package/lib/tools/history/contract.d.ts +3 -11
- package/lib/tools/history/contract.js +8 -7
- package/lib/ui/dsh/elements.d.ts +2 -5
- package/lib/ui/dsh/elements.js +3 -16
- package/lib/ui/dsh/management.js +9 -9
- package/lib/ui/dsh/styles.d.ts +1 -1
- package/lib/ui/dsh/styles.js +5 -33
- package/package.json +4 -1
- package/resources/antigravity/skills/pbot/SKILL.md +11 -1
- package/resources/claude/skills/pbot/SKILL.md +11 -1
- package/resources/plugin/skills/pbot/SKILL.md +9 -0
- package/resources/prompts/history-coordinator.md +1 -0
- package/resources/prompts/plugin-coordinator.md +1 -0
- package/scripts/README.md +3 -2
- package/src/common/validation.ts +10 -0
- package/src/dsh.ts +2 -2
- package/src/extension/history/command.ts +68 -0
- package/src/extension/hosts/dsh/acp-entry.ts +21 -0
- package/src/extension/hosts/dsh/acp-member.ts +4 -15
- package/src/extension/hosts/dsh/command.ts +6 -46
- package/src/extension/hosts/dsh/workspace.ts +12 -38
- package/src/extension/hosts/pi/acp-member.ts +4 -10
- package/src/extension/hosts/pi/command.ts +14 -63
- package/src/extension/hosts/pi/events.ts +2 -8
- package/src/extension/hosts/pi/lifecycle.ts +3 -2
- package/src/extension/hosts/plugin-runtime.ts +39 -19
- package/src/extension/hosts/workspace-mcp.ts +25 -0
- package/src/extension/mcp/bridge.ts +80 -80
- package/src/extension/mcp/tool-contract.ts +462 -0
- package/src/extension/mcp/workers.ts +81 -551
- package/src/extension/setup/cli.ts +11 -1
- package/src/extension/setup/upgrade.ts +158 -0
- package/src/extension/setup/workspace-cli.ts +167 -0
- package/src/integrations/acp/agents.ts +2 -3
- package/src/integrations/acp/harnesses/dsh.ts +1 -1
- package/src/integrations/acp/harnesses/presets.ts +8 -0
- package/src/integrations/acp/history-summary.ts +2 -1
- package/src/integrations/agent-resources.ts +1 -1
- package/src/integrations/hosts/claude/adapter.ts +7 -53
- package/src/integrations/hosts/codex/adapter.ts +16 -0
- package/src/integrations/hosts/plugin-registry.ts +9 -1
- package/src/integrations/hosts/prompt-hooks.ts +72 -0
- package/src/integrations/hosts/qoder/adapter.ts +19 -0
- package/src/integrations/installation/cli-update.ts +144 -0
- package/src/integrations/installation/pi-bridge.ts +1 -1
- package/src/integrations/installation/pi-setup.ts +1 -1
- package/src/integrations/installation/processes.ts +1 -1
- package/src/integrations/installation/upgraders/antigravity.ts +68 -0
- package/src/integrations/installation/upgraders/claude.ts +123 -0
- package/src/integrations/installation/upgraders/codex.ts +73 -0
- package/src/integrations/installation/upgraders/dsh.ts +63 -0
- package/src/integrations/installation/upgraders/pi.ts +87 -0
- package/src/integrations/installation/upgraders/qoder.ts +68 -0
- package/src/integrations/installation/upgraders/registry.ts +48 -0
- package/src/model/acp.ts +11 -3
- package/src/model/agent.ts +20 -4
- package/src/model/history.ts +5 -0
- package/src/model/installation.ts +86 -0
- package/src/model/plugin-host.ts +5 -1
- package/src/model/workspace-config.ts +6 -12
- package/src/pbot.ts +13 -32
- package/src/plugin.ts +3 -3
- package/src/services/agents/agent-service.ts +29 -17
- package/src/services/history/history-capture.ts +30 -22
- package/src/services/history/history-migrate.ts +23 -50
- package/src/services/history/history-query.ts +34 -48
- package/src/services/history/summary-command.ts +9 -8
- package/src/services/history/summary-registry.ts +2 -3
- package/src/services/history/summary-runner.ts +72 -81
- package/src/services/history/workspace-history.ts +8 -0
- package/src/services/installation/setup-service.ts +9 -43
- package/src/services/installation/upgrade-service.ts +127 -0
- package/src/services/workspace/plugin-releases.ts +121 -0
- package/src/services/workspace/workspace-config.ts +9 -8
- package/src/services/workspace/workspace-mcp.ts +23 -28
- package/src/services/workspace/workspace-skills.ts +5 -2
- package/src/storage/acp-files.ts +7 -12
- package/src/storage/agent-files.ts +6 -5
- package/src/storage/atomic-json.ts +31 -4
- package/src/storage/history-files.ts +22 -15
- package/src/storage/history-format.ts +6 -8
- package/src/tools/history/contract.ts +9 -9
- package/src/tools/history/pi-tool.ts +6 -4
- package/src/ui/dsh/elements.ts +5 -12
- package/src/ui/dsh/management.ts +10 -10
- package/src/ui/dsh/styles.ts +5 -33
- package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +0 -12
- package/lib/antigravity-plugin/lib/services/history/history-migrate.js +0 -88
- package/lib/ui/presentation.d.ts +0 -3
- package/lib/ui/presentation.js +0 -12
- package/src/tools/access.ts +0 -7
- package/src/tools/register.ts +0 -21
- package/src/ui/presentation.ts +0 -12
|
@@ -1,477 +1,34 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
2
3
|
import { realpath, stat } from "node:fs/promises";
|
|
3
4
|
import { homedir } from "node:os";
|
|
4
5
|
import { isAbsolute, join } from "node:path";
|
|
5
6
|
import { setTimeout as delay } from "node:timers/promises";
|
|
6
7
|
import { object } from "../../common/json.js";
|
|
7
|
-
import { isAcpBackend, requireThat } from "../../common/validation.js";
|
|
8
|
+
import { isAcpBackend, isHistoryIdentifier, isOneOf, requireThat } from "../../common/validation.js";
|
|
9
|
+
import { resourceRoot } from "../../common/paths.js";
|
|
8
10
|
import { packageVersion } from "../../common/version.js";
|
|
9
11
|
import { AcpWorkerHost } from "../../integrations/acp/agents.js";
|
|
10
12
|
import { canonicalAcpBackend, inspectAcpBackends, knownAcpBackends } from "../../integrations/acp/launch.js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
+
import { pluginMcpWorkspaceRoot } from "../../integrations/hosts/plugin-registry.js";
|
|
14
|
+
import { mcpWorkerToolNames, acpElicitationActions, isAcpElicitationValue, } from "../../model/acp.js";
|
|
15
|
+
import { buildHistoryMcpTools, buildPbotWorkerTools, buildWorkspaceMcpTools, defaultWaitMs, discoverTargets, maxWaitMs, parseMcpToolCall, } from "./tool-contract.js";
|
|
16
|
+
import { historyPageLimits } from "../../model/history.js";
|
|
13
17
|
import { AgentService } from "../../services/agents/agent-service.js";
|
|
14
18
|
import { readWorkspaceHistory, searchWorkspaceHistory } from "../../services/history/history-query.js";
|
|
15
19
|
import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../services/workspace/workspace-config.js";
|
|
16
|
-
import { isHistoryHost, isSummaryDimension } from "../../storage/history-format.js";
|
|
17
20
|
import { WorkspaceMcpBridge } from "./bridge.js";
|
|
21
|
+
export { buildHistoryMcpTools, buildPbotWorkerTools, buildWorkspaceMcpTools, pbotWorkerTools } from "./tool-contract.js";
|
|
18
22
|
const protocolVersion = "2025-03-26";
|
|
19
23
|
const readyTimeoutMs = 45_000;
|
|
20
|
-
const defaultWaitMs = 50_000;
|
|
21
|
-
const maxWaitMs = 600_000;
|
|
22
24
|
const reportPageSize = 16_000;
|
|
23
25
|
const progressIntervalMs = 5_000;
|
|
24
|
-
const responseActions = ["accept", "decline", "cancel"];
|
|
25
|
-
const discoverTargets = ["overview", "workers", "backends", "models"];
|
|
26
|
-
const mcpHistoryToolNames = ["history_search", "history_read"];
|
|
27
|
-
const allMcpToolNames = [...mcpWorkerToolNames, ...workspaceMcpToolNames, ...mcpHistoryToolNames];
|
|
28
|
-
const toolParams = {
|
|
29
|
-
worker_create: new Set(["backend", "model", "thinking", "cwd", "workspace"]),
|
|
30
|
-
worker_close: new Set(["workerId", "workspace"]),
|
|
31
|
-
worker_request: new Set(["workerId", "message", "waitMs", "workspace"]),
|
|
32
|
-
worker_response: new Set(["workerId", "action", "requestId", "optionId", "content", "waitMs", "workspace"]),
|
|
33
|
-
worker_output: new Set(["workerId", "offset", "waitMs", "workspace"]),
|
|
34
|
-
worker_discover: new Set(["target", "workerId", "backend", "model", "workspace"]),
|
|
35
|
-
workspace_mcp_discover: new Set(["server", "workspace"]),
|
|
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"]),
|
|
39
|
-
};
|
|
40
|
-
const shortToolMap = {
|
|
41
|
-
create: "worker_create",
|
|
42
|
-
close: "worker_close",
|
|
43
|
-
request: "worker_request",
|
|
44
|
-
response: "worker_response",
|
|
45
|
-
output: "worker_output",
|
|
46
|
-
discover: "worker_discover",
|
|
47
|
-
};
|
|
48
26
|
export const mcpWorkerOnlyInstructions = "提供跨助手协作能力(worker_*):可启动并调度其他外部 AI 助手在当前工作区中独立执行任务,适用于用户指定其他助手、需要特定模型或思考深度、获取独立审查/第二意见,或并行处理子任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。\n" +
|
|
49
27
|
"使用流程:用 worker_create 启动目标助手(或用 worker_discover 复用已有会话)→ 用 worker_request 派发任务或继续追问 → 任务完成后可用 worker_close 结束会话。后台等待、超时续等(timedOut)或长结果翻页(nextOffset)用 worker_output;助手请求授权或提问(needsResponse)时,先向用户确认,再用 worker_response 回复。";
|
|
50
28
|
export const mcpInstructions = "提供三类能力:\n" +
|
|
51
29
|
"1. 跨助手协作(worker_*):启动并调度其他外部 AI 助手在当前工作区中独立执行任务,适用于用户指定其他助手、需要特定模型或思考深度、获取独立审查/第二意见,或并行处理子任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。使用流程:worker_create 启动助手(或 worker_discover 复用已有会话)→ worker_request 派发任务或追问 → 完成后 worker_close 结束;后台等待、超时续等(timedOut)或长结果翻页(nextOffset)用 worker_output;返回 needsResponse 时先向用户确认,再用 worker_response 回复。\n" +
|
|
52
30
|
"2. 工作区共享外部工具(workspace_mcp_*):发现并调用当前工作区接入的外部工具服务与数据源(可与当前环境原生工具同时使用)。先用 workspace_mcp_discover 查看可用服务与工具说明,再用 workspace_mcp_call 调用。\n" +
|
|
53
31
|
"3. 跨宿主历史查询(history_search / history_read):只读检索当前工作区在 Pi、dsh、Claude Code、Antigravity 等宿主中记录的历史问答与摘要归档。";
|
|
54
|
-
function formatBackendItem(entry, defaultBackend) {
|
|
55
|
-
const tags = [];
|
|
56
|
-
if (entry.label)
|
|
57
|
-
tags.push(entry.label);
|
|
58
|
-
if (entry.backend === defaultBackend)
|
|
59
|
-
tags.push("当前");
|
|
60
|
-
return tags.length ? `${entry.backend}(${tags.join(",")})` : entry.backend;
|
|
61
|
-
}
|
|
62
|
-
function summarizeBackends(commands = {}, defaultBackend) {
|
|
63
|
-
const entries = inspectAcpBackends(commands);
|
|
64
|
-
const available = entries.filter(item => item.available);
|
|
65
|
-
const unavailable = entries.filter(item => !item.available);
|
|
66
|
-
const availableText = available.map(item => formatBackendItem(item, defaultBackend)).join("、");
|
|
67
|
-
const unavailableText = unavailable.map(item => formatBackendItem(item, defaultBackend)).join("、");
|
|
68
|
-
const overview = available.length
|
|
69
|
-
? unavailable.length
|
|
70
|
-
? `当前可用助手:${availableText};暂不可用:${unavailableText}。`
|
|
71
|
-
: `当前可用助手:${availableText}。`
|
|
72
|
-
: `当前无可用外部助手(暂不可用:${unavailableText})。`;
|
|
73
|
-
const availableIds = available.map(item => item.backend).join("、");
|
|
74
|
-
return { overview, availableIds };
|
|
75
|
-
}
|
|
76
|
-
function workspaceProperty(workspaceBound) {
|
|
77
|
-
return {
|
|
78
|
-
type: "string",
|
|
79
|
-
description: workspaceBound
|
|
80
|
-
? "目标工作区根目录的绝对路径;默认使用当前工作区,通常省略。"
|
|
81
|
-
: "目标工作区根目录的绝对路径(如上下文中提供了 workspaceRoot 则传该路径);请显式传入。",
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = false) {
|
|
85
|
-
const { overview, availableIds } = summarizeBackends(commands, defaultBackend);
|
|
86
|
-
const modelsBackendHint = defaultBackend
|
|
87
|
-
? `省略时默认查 ${defaultBackend}`
|
|
88
|
-
: "必填";
|
|
89
|
-
const workspace = workspaceProperty(workspaceBound);
|
|
90
|
-
return [
|
|
91
|
-
{
|
|
92
|
-
name: "worker_create",
|
|
93
|
-
description: "启动一个独立的外部 AI 助手会话(worker),用于将任务委派给其他助手或指定模型/思考深度来独立处理(如按用户要求切换助手、获取独立审查或第二意见、并行分担子任务)。" +
|
|
94
|
-
"本工具仅建立会话并返回 workerId,随后通过 worker_request 发送具体任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。\n" +
|
|
95
|
-
overview,
|
|
96
|
-
annotations: {
|
|
97
|
-
title: "Create Worker",
|
|
98
|
-
readOnlyHint: false,
|
|
99
|
-
destructiveHint: false,
|
|
100
|
-
idempotentHint: false,
|
|
101
|
-
openWorldHint: true,
|
|
102
|
-
},
|
|
103
|
-
inputSchema: {
|
|
104
|
-
type: "object",
|
|
105
|
-
additionalProperties: false,
|
|
106
|
-
required: ["backend"],
|
|
107
|
-
properties: {
|
|
108
|
-
backend: {
|
|
109
|
-
type: "string",
|
|
110
|
-
description: "要启动的外部助手标识(不区分大小写,支持常见别名,如 claude-code、agy)。",
|
|
111
|
-
},
|
|
112
|
-
model: {
|
|
113
|
-
type: "string",
|
|
114
|
-
description: "仅用户明确要求特定模型时指定(支持模型 ID、显示名或 provider/model,不区分大小写);不确定可用值时先用 worker_discover(target=\"models\") 查询;不填则使用该助手默认模型。",
|
|
115
|
-
},
|
|
116
|
-
thinking: {
|
|
117
|
-
type: "string",
|
|
118
|
-
description: "仅用户明确要求思考深度时指定(如 low / medium / high / xhigh / max,不区分大小写);不填则使用默认设置。",
|
|
119
|
-
},
|
|
120
|
-
cwd: {
|
|
121
|
-
type: "string",
|
|
122
|
-
description: "助手执行任务时的工作目录(绝对路径或相对工作区的路径),默认为当前工作区根目录。",
|
|
123
|
-
},
|
|
124
|
-
workspace,
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
name: "worker_close",
|
|
130
|
-
description: "结束不再需要的外部助手会话并释放资源。若该助手支持会话恢复,后续仍可直接用 worker_request 在原上下文中继续对话。",
|
|
131
|
-
annotations: {
|
|
132
|
-
title: "Close Worker",
|
|
133
|
-
readOnlyHint: false,
|
|
134
|
-
destructiveHint: true,
|
|
135
|
-
idempotentHint: true,
|
|
136
|
-
openWorldHint: false,
|
|
137
|
-
},
|
|
138
|
-
inputSchema: {
|
|
139
|
-
type: "object",
|
|
140
|
-
additionalProperties: false,
|
|
141
|
-
required: ["workerId"],
|
|
142
|
-
properties: {
|
|
143
|
-
workerId: {
|
|
144
|
-
type: "string",
|
|
145
|
-
description: "要结束的助手会话 ID(来自 worker_create 或 worker_discover)。",
|
|
146
|
-
},
|
|
147
|
-
workspace,
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
name: "worker_request",
|
|
153
|
-
description: "向指定的外部助手派发任务,或在同一上下文中追问与补充要求,并获取执行结果(已关闭但支持恢复的会话会自动续接)。" +
|
|
154
|
-
`默认最多等待 ${defaultWaitMs / 1000} 秒返回结果;将 waitMs 设为 0 可立即返回并转入后台执行,适合耗时任务或多助手并行。` +
|
|
155
|
-
"若返回 timedOut 或结果含 nextOffset,用 worker_output 继续等待或翻页;若返回 needsResponse,先向用户确认再用 worker_response 回复。",
|
|
156
|
-
annotations: {
|
|
157
|
-
title: "Send Request to Worker",
|
|
158
|
-
readOnlyHint: false,
|
|
159
|
-
destructiveHint: false,
|
|
160
|
-
idempotentHint: false,
|
|
161
|
-
openWorldHint: true,
|
|
162
|
-
},
|
|
163
|
-
inputSchema: {
|
|
164
|
-
type: "object",
|
|
165
|
-
additionalProperties: false,
|
|
166
|
-
required: ["workerId", "message"],
|
|
167
|
-
properties: {
|
|
168
|
-
workerId: {
|
|
169
|
-
type: "string",
|
|
170
|
-
description: "目标助手会话 ID(来自 worker_create 或 worker_discover)。",
|
|
171
|
-
},
|
|
172
|
-
message: {
|
|
173
|
-
type: "string",
|
|
174
|
-
description: "要发送的任务说明或追问内容。外部助手看不到你与用户的对话历史,首次派发时请写清背景、目标、相关文件路径、约束条件和期望产出。",
|
|
175
|
-
},
|
|
176
|
-
waitMs: {
|
|
177
|
-
type: "integer",
|
|
178
|
-
minimum: 0,
|
|
179
|
-
maximum: maxWaitMs,
|
|
180
|
-
description: `最多等待结果的毫秒数(默认 ${defaultWaitMs});设为 0 可立即返回并在后台执行。`,
|
|
181
|
-
},
|
|
182
|
-
workspace,
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
name: "worker_response",
|
|
188
|
-
description: "当外部助手在执行过程中暂停并请求确认或补充信息(返回 needsResponse: true)时,向其提交决定以继续执行。" +
|
|
189
|
-
"支持三类请求:操作授权(kind=\"permission\")、问答表单(kind=\"form\")和链接确认(kind=\"url\")。" +
|
|
190
|
-
`提交前先向用户确认;提交后默认最多等待 ${defaultWaitMs / 1000} 秒返回后续结果(waitMs 设为 0 立即返回)。`,
|
|
191
|
-
annotations: {
|
|
192
|
-
title: "Respond to Worker Request",
|
|
193
|
-
readOnlyHint: false,
|
|
194
|
-
destructiveHint: false,
|
|
195
|
-
idempotentHint: false,
|
|
196
|
-
openWorldHint: true,
|
|
197
|
-
},
|
|
198
|
-
inputSchema: {
|
|
199
|
-
type: "object",
|
|
200
|
-
additionalProperties: false,
|
|
201
|
-
required: ["workerId", "action"],
|
|
202
|
-
properties: {
|
|
203
|
-
workerId: {
|
|
204
|
-
type: "string",
|
|
205
|
-
description: "等待回复的助手会话 ID。",
|
|
206
|
-
},
|
|
207
|
-
action: {
|
|
208
|
-
type: "string",
|
|
209
|
-
enum: [...responseActions],
|
|
210
|
-
description: "处理方式:accept 表示同意授权、提交表单回答或确认链接;decline 表示拒绝;cancel 表示取消本次请求。",
|
|
211
|
-
},
|
|
212
|
-
requestId: {
|
|
213
|
-
type: "string",
|
|
214
|
-
description: "要回复的请求 ID(来自 pendingRequests[].requestId);仅一条待处理请求时可省略,多条时必填。",
|
|
215
|
-
},
|
|
216
|
-
optionId: {
|
|
217
|
-
type: "string",
|
|
218
|
-
description: "仅授权请求(kind=\"permission\")且 action 不为 cancel 时可用:指定选项 ID(来自 pendingRequests[].options[].optionId),省略时默认单次允许或拒绝。",
|
|
219
|
-
},
|
|
220
|
-
content: {
|
|
221
|
-
type: "object",
|
|
222
|
-
additionalProperties: true,
|
|
223
|
-
description: "仅表单提问(kind=\"form\")且 action=\"accept\" 时可用:按 pendingRequests[].schema.properties 填写的回答对象(值为字符串、数字、布尔值或字符串数组)。",
|
|
224
|
-
},
|
|
225
|
-
waitMs: {
|
|
226
|
-
type: "integer",
|
|
227
|
-
minimum: 0,
|
|
228
|
-
maximum: maxWaitMs,
|
|
229
|
-
description: `提交回复后最多等待后续结果的毫秒数(默认 ${defaultWaitMs});设为 0 立即返回。`,
|
|
230
|
-
},
|
|
231
|
-
workspace,
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
name: "worker_output",
|
|
237
|
-
description: "获取或等待外部助手的最新执行结果。用于收取后台任务的产出、在等待超时(timedOut)后继续等待,或在长结果分页(含 nextOffset)时读取后续内容。" +
|
|
238
|
-
"任务仍在运行时会等待其完成(也可能返回 timedOut 或 needsResponse),已结束则立即返回。",
|
|
239
|
-
annotations: {
|
|
240
|
-
title: "Get Worker Output",
|
|
241
|
-
readOnlyHint: true,
|
|
242
|
-
destructiveHint: false,
|
|
243
|
-
idempotentHint: true,
|
|
244
|
-
openWorldHint: false,
|
|
245
|
-
},
|
|
246
|
-
inputSchema: {
|
|
247
|
-
type: "object",
|
|
248
|
-
additionalProperties: false,
|
|
249
|
-
required: ["workerId"],
|
|
250
|
-
properties: {
|
|
251
|
-
workerId: {
|
|
252
|
-
type: "string",
|
|
253
|
-
description: "要等待或获取结果的助手会话 ID。",
|
|
254
|
-
},
|
|
255
|
-
offset: {
|
|
256
|
-
type: "integer",
|
|
257
|
-
minimum: 0,
|
|
258
|
-
description: "结果读取起始位置(默认 0);翻页读取剩余内容时传入上次返回的 nextOffset。",
|
|
259
|
-
},
|
|
260
|
-
waitMs: {
|
|
261
|
-
type: "integer",
|
|
262
|
-
minimum: 0,
|
|
263
|
-
maximum: maxWaitMs,
|
|
264
|
-
description: `任务仍在运行时最多等待的毫秒数(默认 ${defaultWaitMs});任务已结束或翻页读取时会立即返回。`,
|
|
265
|
-
},
|
|
266
|
-
workspace,
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
},
|
|
270
|
-
{
|
|
271
|
-
name: "worker_discover",
|
|
272
|
-
description: "了解当前可以委派哪些外部助手、查看已有助手会话的运行状态以便复用,或查询某个助手支持的模型与思考深度选项。" +
|
|
273
|
-
"默认(target=\"overview\")同时返回可用助手与已有会话;仅在需要核对模型或思考深度可选值时再查 target=\"models\"(耗时较长)。",
|
|
274
|
-
annotations: {
|
|
275
|
-
title: "Discover Workers, Backends & Models",
|
|
276
|
-
readOnlyHint: true,
|
|
277
|
-
destructiveHint: false,
|
|
278
|
-
idempotentHint: true,
|
|
279
|
-
openWorldHint: false,
|
|
280
|
-
},
|
|
281
|
-
inputSchema: {
|
|
282
|
-
type: "object",
|
|
283
|
-
additionalProperties: false,
|
|
284
|
-
required: [],
|
|
285
|
-
properties: {
|
|
286
|
-
target: {
|
|
287
|
-
type: "string",
|
|
288
|
-
enum: [...discoverTargets],
|
|
289
|
-
description: "查询范围,默认 \"overview\"(同时返回可用助手与已有会话);\"workers\" 查全部或单个会话状态;\"backends\" 查可用助手列表;\"models\" 查指定助手支持的模型与思考深度。",
|
|
290
|
-
},
|
|
291
|
-
workerId: {
|
|
292
|
-
type: "string",
|
|
293
|
-
description: "仅 target=\"workers\" 可用:指定单个助手会话 ID;不填则列出全部。",
|
|
294
|
-
},
|
|
295
|
-
backend: {
|
|
296
|
-
type: "string",
|
|
297
|
-
description: availableIds
|
|
298
|
-
? `仅 target="models" 可用(${modelsBackendHint}):目标外部助手标识,支持常见别名;当前可用:${availableIds}。`
|
|
299
|
-
: `仅 target="models" 可用(${modelsBackendHint}):目标外部助手标识,支持常见别名。`,
|
|
300
|
-
},
|
|
301
|
-
model: {
|
|
302
|
-
type: "string",
|
|
303
|
-
description: "仅 target=\"models\" 可用:指定模型以查看该模型支持的思考深度选项。",
|
|
304
|
-
},
|
|
305
|
-
workspace,
|
|
306
|
-
},
|
|
307
|
-
},
|
|
308
|
-
},
|
|
309
|
-
];
|
|
310
|
-
}
|
|
311
|
-
export function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
312
|
-
const workspace = workspaceProperty(workspaceBound);
|
|
313
|
-
return [
|
|
314
|
-
{
|
|
315
|
-
name: "workspace_mcp_discover",
|
|
316
|
-
description: "发现当前工作区共享的外部工具服务(MCP)及其可用工具。不传 server 时列出可用服务;传入 server 时返回该服务提供的工具清单与参数说明。",
|
|
317
|
-
annotations: {
|
|
318
|
-
title: "Discover Workspace MCP Servers & Tools",
|
|
319
|
-
readOnlyHint: true,
|
|
320
|
-
destructiveHint: false,
|
|
321
|
-
idempotentHint: true,
|
|
322
|
-
openWorldHint: true,
|
|
323
|
-
},
|
|
324
|
-
inputSchema: {
|
|
325
|
-
type: "object",
|
|
326
|
-
additionalProperties: false,
|
|
327
|
-
required: [],
|
|
328
|
-
properties: {
|
|
329
|
-
server: {
|
|
330
|
-
type: "string",
|
|
331
|
-
description: "目标工具服务名称;不填时列出工作区全部可用服务。",
|
|
332
|
-
},
|
|
333
|
-
workspace,
|
|
334
|
-
},
|
|
335
|
-
},
|
|
336
|
-
},
|
|
337
|
-
{
|
|
338
|
-
name: "workspace_mcp_call",
|
|
339
|
-
description: "调用当前工作区共享的外部工具服务(MCP)中的指定工具,用于访问工作区接入的外部能力与数据源。" +
|
|
340
|
-
"不确定工具名或参数格式时,先用 workspace_mcp_discover(server) 查询。",
|
|
341
|
-
annotations: {
|
|
342
|
-
title: "Call Workspace MCP Tool",
|
|
343
|
-
readOnlyHint: false,
|
|
344
|
-
destructiveHint: false,
|
|
345
|
-
idempotentHint: false,
|
|
346
|
-
openWorldHint: true,
|
|
347
|
-
},
|
|
348
|
-
inputSchema: {
|
|
349
|
-
type: "object",
|
|
350
|
-
additionalProperties: false,
|
|
351
|
-
required: ["server", "tool"],
|
|
352
|
-
properties: {
|
|
353
|
-
server: {
|
|
354
|
-
type: "string",
|
|
355
|
-
description: "目标工具服务名称(可通过 workspace_mcp_discover 获取)。",
|
|
356
|
-
},
|
|
357
|
-
tool: {
|
|
358
|
-
type: "string",
|
|
359
|
-
description: "要调用的工具名称。",
|
|
360
|
-
},
|
|
361
|
-
arguments: {
|
|
362
|
-
type: "object",
|
|
363
|
-
additionalProperties: true,
|
|
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。",
|
|
467
|
-
},
|
|
468
|
-
workspace,
|
|
469
|
-
},
|
|
470
|
-
},
|
|
471
|
-
},
|
|
472
|
-
];
|
|
473
|
-
}
|
|
474
|
-
export const pbotWorkerTools = buildPbotWorkerTools();
|
|
475
32
|
export function defaultWorkerDirectory() {
|
|
476
33
|
if (process.env.PBOT_MCP_AGENT_DIR)
|
|
477
34
|
return process.env.PBOT_MCP_AGENT_DIR;
|
|
@@ -479,11 +36,9 @@ export function defaultWorkerDirectory() {
|
|
|
479
36
|
return join(process.env.PLUGIN_DATA, "subagents");
|
|
480
37
|
return join(homedir(), ".pbot/subagents");
|
|
481
38
|
}
|
|
482
|
-
function
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
function isKnownTool(name) {
|
|
486
|
-
return allMcpToolNames.includes(name);
|
|
39
|
+
function workerCommandTool(name) {
|
|
40
|
+
const full = name.startsWith("worker_") ? name : `worker_${name}`;
|
|
41
|
+
return isOneOf(full, mcpWorkerToolNames) ? full : undefined;
|
|
487
42
|
}
|
|
488
43
|
/** Parse Pi/dsh `/pbot worker ...` CLI arguments into a canonical MCP tool call. */
|
|
489
44
|
export function parseWorkerCommand(raw) {
|
|
@@ -517,8 +72,7 @@ export function parseWorkerCommand(raw) {
|
|
|
517
72
|
if (trimmed.startsWith("{")) {
|
|
518
73
|
const parsed = JSON.parse(trimmed);
|
|
519
74
|
requireThat(object(parsed), 'worker 参数必须是 JSON 对象,例如:/pbot worker create {"backend":"codex"}');
|
|
520
|
-
const
|
|
521
|
-
const resolved = rawTool ? (isKnownWorkerTool(rawTool) ? rawTool : shortToolMap[rawTool]) : undefined;
|
|
75
|
+
const resolved = typeof parsed.tool === "string" ? workerCommandTool(parsed.tool) : undefined;
|
|
522
76
|
requireThat(resolved, `JSON 形式需包含有效 tool 字段(${mcpWorkerToolNames.join(", ")}),或使用 /pbot worker <工具名> <JSON>。`);
|
|
523
77
|
const rest = Object.fromEntries(Object.entries(parsed).filter(([key]) => key !== "tool"));
|
|
524
78
|
return { tool: resolved, args: rest };
|
|
@@ -526,21 +80,14 @@ export function parseWorkerCommand(raw) {
|
|
|
526
80
|
const match = trimmed.match(/^(\S+)(?:\s+([\s\S]*))?$/);
|
|
527
81
|
const verb = match?.[1] ?? "";
|
|
528
82
|
const rest = (match?.[2] ?? "").trim();
|
|
529
|
-
const tool =
|
|
530
|
-
requireThat(tool, `未知 worker 命令:${verb}(支持:overview | status | backends | models |
|
|
83
|
+
const tool = workerCommandTool(verb);
|
|
84
|
+
requireThat(tool, `未知 worker 命令:${verb}(支持:overview | status | backends | models | ${mcpWorkerToolNames.map(name => name.slice("worker_".length)).join(" | ")})。`);
|
|
531
85
|
if (!rest)
|
|
532
86
|
return { tool, args: {} };
|
|
533
87
|
const parsed = JSON.parse(rest);
|
|
534
88
|
requireThat(object(parsed), `${tool} 的参数必须是 JSON 对象。`);
|
|
535
89
|
return { tool, args: parsed };
|
|
536
90
|
}
|
|
537
|
-
function rejectUnknownParams(tool, rawArgs) {
|
|
538
|
-
const allowed = toolParams[tool];
|
|
539
|
-
const unknown = Object.entries(rawArgs)
|
|
540
|
-
.filter(([key, value]) => value !== undefined && !allowed.has(key))
|
|
541
|
-
.map(([key]) => key);
|
|
542
|
-
requireThat(unknown.length === 0, `未知参数:${unknown.join(", ")}(${tool} 可用参数:${[...allowed].join(", ")})。`);
|
|
543
|
-
}
|
|
544
91
|
function asString(args, key, required = false) {
|
|
545
92
|
const value = args[key];
|
|
546
93
|
if (value === undefined || value === null) {
|
|
@@ -563,11 +110,7 @@ function asContent(args, key) {
|
|
|
563
110
|
return undefined;
|
|
564
111
|
requireThat(object(value), `参数 ${key} 必须是 JSON 对象。`);
|
|
565
112
|
for (const [field, entry] of Object.entries(value)) {
|
|
566
|
-
|
|
567
|
-
|| (typeof entry === "number" && Number.isFinite(entry))
|
|
568
|
-
|| typeof entry === "boolean"
|
|
569
|
-
|| (Array.isArray(entry) && entry.every(item => typeof item === "string"));
|
|
570
|
-
requireThat(valid, `参数 ${key}.${field} 必须是字符串、数字、布尔值或字符串数组。`);
|
|
113
|
+
requireThat(isAcpElicitationValue(entry), `参数 ${key}.${field} 必须是字符串、数字、布尔值或字符串数组。`);
|
|
571
114
|
}
|
|
572
115
|
return value;
|
|
573
116
|
}
|
|
@@ -608,7 +151,7 @@ export class McpWorkerRuntime {
|
|
|
608
151
|
#defaultBackend;
|
|
609
152
|
#nativeWorkspaceMcp;
|
|
610
153
|
#nativeHistory;
|
|
611
|
-
#
|
|
154
|
+
#closing;
|
|
612
155
|
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 ?? "")) {
|
|
613
156
|
this.#directory = directory;
|
|
614
157
|
this.#sessionId = sessionId;
|
|
@@ -616,6 +159,25 @@ export class McpWorkerRuntime {
|
|
|
616
159
|
this.#nativeWorkspaceMcp = nativeWorkspaceMcp;
|
|
617
160
|
this.#nativeHistory = nativeHistory;
|
|
618
161
|
}
|
|
162
|
+
/** Mount the stdio sibling with the same worker ownership as the native host command. */
|
|
163
|
+
nativeServer(root) {
|
|
164
|
+
const entry = join(resourceRoot, "../lib/extension/mcp.js");
|
|
165
|
+
if (!existsSync(entry))
|
|
166
|
+
return undefined;
|
|
167
|
+
requireThat(this.#defaultBackend, "原生 MCP 挂载需要宿主名称。");
|
|
168
|
+
return {
|
|
169
|
+
command: process.execPath,
|
|
170
|
+
args: [entry],
|
|
171
|
+
env: {
|
|
172
|
+
PBOT_HOST: this.#defaultBackend,
|
|
173
|
+
PBOT_WORKSPACE_ROOT: root,
|
|
174
|
+
PBOT_MCP_AGENT_DIR: this.#directory,
|
|
175
|
+
PBOT_MCP_SESSION_ID: this.#sessionId,
|
|
176
|
+
PBOT_NATIVE_WORKSPACE_MCP: "1",
|
|
177
|
+
PBOT_NATIVE_HISTORY: "1",
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
619
181
|
get nativeWorkspaceMcp() {
|
|
620
182
|
return this.#nativeWorkspaceMcp;
|
|
621
183
|
}
|
|
@@ -630,20 +192,16 @@ export class McpWorkerRuntime {
|
|
|
630
192
|
return backend;
|
|
631
193
|
}
|
|
632
194
|
async resolveWorkspace(supplied) {
|
|
633
|
-
const target = supplied ||
|
|
195
|
+
const target = supplied || pluginMcpWorkspaceRoot() || process.cwd();
|
|
634
196
|
requireThat(isAbsolute(target), "工作区需要绝对路径。");
|
|
635
197
|
const root = await realpath(target);
|
|
636
198
|
requireThat((await stat(root)).isDirectory(), "工作区路径不是目录。");
|
|
637
199
|
return root;
|
|
638
200
|
}
|
|
639
|
-
|
|
640
|
-
requireThat(!this.#closed, "Personal Bot MCP 服务已关闭。");
|
|
641
|
-
const root = await this.resolveWorkspace(supplied);
|
|
642
|
-
const configuration = await readWorkspaceConfig(root);
|
|
643
|
-
requireThat(configuration.enabled, workspaceDisabledMessage(configuration));
|
|
201
|
+
workerService(root, commands = {}) {
|
|
644
202
|
let entry = this.#services.get(root);
|
|
645
203
|
if (!entry) {
|
|
646
|
-
const host = new AcpWorkerHost(this.#directory,
|
|
204
|
+
const host = new AcpWorkerHost(this.#directory, commands);
|
|
647
205
|
entry = {
|
|
648
206
|
host,
|
|
649
207
|
service: new AgentService(root, this.#directory, host),
|
|
@@ -652,9 +210,9 @@ export class McpWorkerRuntime {
|
|
|
652
210
|
this.#services.set(root, entry);
|
|
653
211
|
}
|
|
654
212
|
else {
|
|
655
|
-
|
|
213
|
+
entry.host.commands = commands;
|
|
656
214
|
}
|
|
657
|
-
return
|
|
215
|
+
return entry;
|
|
658
216
|
}
|
|
659
217
|
async toolDefinitions() {
|
|
660
218
|
let commands;
|
|
@@ -672,7 +230,7 @@ export class McpWorkerRuntime {
|
|
|
672
230
|
}
|
|
673
231
|
catch { /* Fall back to registered built-in harnesses when cwd is outside an enabled workspace. */ }
|
|
674
232
|
const defaultBackend = this.#defaultBackend ? canonicalAcpBackend(this.#defaultBackend, commands) : undefined;
|
|
675
|
-
const workspaceBound = Boolean(
|
|
233
|
+
const workspaceBound = Boolean(pluginMcpWorkspaceRoot());
|
|
676
234
|
return [
|
|
677
235
|
...buildPbotWorkerTools(commands, defaultBackend, workspaceBound),
|
|
678
236
|
...(includeWorkspaceMcp ? buildWorkspaceMcpTools(workspaceBound) : []),
|
|
@@ -685,7 +243,7 @@ export class McpWorkerRuntime {
|
|
|
685
243
|
let lastProgressAt = 0;
|
|
686
244
|
let lastMarker = "";
|
|
687
245
|
for (;;) {
|
|
688
|
-
requireThat(!this.#
|
|
246
|
+
requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
|
|
689
247
|
const current = service.status(workerId, owner);
|
|
690
248
|
if (current.state === "error" || current.state === "stopped") {
|
|
691
249
|
throw new Error(current.error || "worker 启动失败。");
|
|
@@ -711,23 +269,13 @@ export class McpWorkerRuntime {
|
|
|
711
269
|
let lastProgressAt = 0;
|
|
712
270
|
let lastMarker = "";
|
|
713
271
|
for (;;) {
|
|
714
|
-
requireThat(!this.#
|
|
715
|
-
const current = service.
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
.filter(item => item.generation === current.generation)
|
|
719
|
-
.at(-1)?.requestId;
|
|
720
|
-
const targetCycle = latestRequest
|
|
721
|
-
? cycles.find(item => item.generation === current.generation && item.requestIds.includes(latestRequest))
|
|
722
|
-
: current.cycle ?? cycles.at(-1);
|
|
723
|
-
const settled = targetCycle && targetCycle.state !== "running";
|
|
724
|
-
const terminalWithoutCycle = !latestRequest && (current.state === "stopped" || current.state === "error" || (current.state === "idle" && !targetCycle));
|
|
725
|
-
const failedBeforeCycle = Boolean(latestRequest && !targetCycle && (current.state === "stopped" || current.state === "error"));
|
|
726
|
-
if (settled) {
|
|
727
|
-
const page = await service.read(workerId, owner, targetCycle.cycleId, offset, reportPageSize);
|
|
272
|
+
requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
|
|
273
|
+
const { current, cycle, terminal } = service.outputStatus(workerId, owner, requestId);
|
|
274
|
+
if (cycle && cycle.state !== "running") {
|
|
275
|
+
const page = await service.read(workerId, owner, cycle.cycleId, offset, reportPageSize);
|
|
728
276
|
return { settled: true, ...presentWorker(page) };
|
|
729
277
|
}
|
|
730
|
-
if (
|
|
278
|
+
if (terminal) {
|
|
731
279
|
if (offset > 0)
|
|
732
280
|
await service.read(workerId, owner, undefined, offset, reportPageSize);
|
|
733
281
|
return { settled: true, ...presentWorker(current) };
|
|
@@ -754,21 +302,20 @@ export class McpWorkerRuntime {
|
|
|
754
302
|
await delay(100);
|
|
755
303
|
}
|
|
756
304
|
}
|
|
757
|
-
async callTool(
|
|
758
|
-
|
|
759
|
-
requireThat(
|
|
760
|
-
|
|
761
|
-
const
|
|
305
|
+
async callTool(toolName, input, progress) {
|
|
306
|
+
const { name, args: rawArgs } = parseMcpToolCall(toolName, input);
|
|
307
|
+
requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
|
|
308
|
+
const root = await this.resolveWorkspace(asString(rawArgs, "workspace"));
|
|
309
|
+
const configuration = await readWorkspaceConfig(root);
|
|
310
|
+
requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
|
|
311
|
+
requireThat(configuration.enabled, workspaceDisabledMessage(configuration));
|
|
762
312
|
switch (name) {
|
|
763
|
-
case "workspace_mcp_discover":
|
|
764
|
-
requireThat(!this.#nativeWorkspaceMcp, "当前宿主已原生挂载工作区 .pbot/mcp.json 服务,请直接调用对应原生 MCP 工具,勿重复经由 workspace_mcp_* 桥接。");
|
|
765
|
-
requireThat(workspaceFeatures(configuration).mcp, `工作区统一 MCP 功能已在 ${configuration.path} 中停用(features.mcp: false)。`);
|
|
766
|
-
const server = asString(rawArgs, "server");
|
|
767
|
-
return this.#bridge.discover(root, server);
|
|
768
|
-
}
|
|
313
|
+
case "workspace_mcp_discover":
|
|
769
314
|
case "workspace_mcp_call": {
|
|
770
315
|
requireThat(!this.#nativeWorkspaceMcp, "当前宿主已原生挂载工作区 .pbot/mcp.json 服务,请直接调用对应原生 MCP 工具,勿重复经由 workspace_mcp_* 桥接。");
|
|
771
316
|
requireThat(workspaceFeatures(configuration).mcp, `工作区统一 MCP 功能已在 ${configuration.path} 中停用(features.mcp: false)。`);
|
|
317
|
+
if (name === "workspace_mcp_discover")
|
|
318
|
+
return this.#bridge.discover(root, asString(rawArgs, "server"));
|
|
772
319
|
const server = asString(rawArgs, "server", true);
|
|
773
320
|
const tool = asString(rawArgs, "tool", true);
|
|
774
321
|
const toolArgs = rawArgs.arguments === undefined ? {} : rawArgs.arguments;
|
|
@@ -780,16 +327,16 @@ export class McpWorkerRuntime {
|
|
|
780
327
|
requireThat(workspaceFeatures(configuration).history, `工作区历史功能已在 ${configuration.path} 中停用(features.history: false)。`);
|
|
781
328
|
const hostFilter = asString(rawArgs, "host");
|
|
782
329
|
if (hostFilter !== undefined)
|
|
783
|
-
requireThat(
|
|
330
|
+
requireThat(isHistoryIdentifier(hostFilter), "无效的 host 来源:" + hostFilter);
|
|
784
331
|
const dimension = asString(rawArgs, "dimension");
|
|
785
332
|
if (dimension !== undefined)
|
|
786
|
-
requireThat(
|
|
333
|
+
requireThat(isHistoryIdentifier(dimension), "无效的 dimension:" + dimension);
|
|
787
334
|
const query = asString(rawArgs, "query");
|
|
788
335
|
const sessionId = asString(rawArgs, "sessionId");
|
|
789
336
|
const from = asString(rawArgs, "from");
|
|
790
337
|
const to = asString(rawArgs, "to");
|
|
791
338
|
const offset = asInt(rawArgs, "offset", 0, 10_000_000) ?? 0;
|
|
792
|
-
const limit = asInt(rawArgs, "limit", 1,
|
|
339
|
+
const limit = asInt(rawArgs, "limit", 1, historyPageLimits.search.max) ?? historyPageLimits.search.default;
|
|
793
340
|
return searchWorkspaceHistory(root, {
|
|
794
341
|
...(hostFilter ? { host: hostFilter } : {}),
|
|
795
342
|
...(dimension ? { dimension } : {}),
|
|
@@ -807,12 +354,15 @@ export class McpWorkerRuntime {
|
|
|
807
354
|
const id = asString(rawArgs, "id", true);
|
|
808
355
|
const hostFilter = asString(rawArgs, "host");
|
|
809
356
|
if (hostFilter !== undefined)
|
|
810
|
-
requireThat(
|
|
357
|
+
requireThat(isHistoryIdentifier(hostFilter), "无效的 host 来源:" + hostFilter);
|
|
811
358
|
const offset = asInt(rawArgs, "offset", 0, 10_000_000) ?? 0;
|
|
812
|
-
const limit = asInt(rawArgs, "limit", 1,
|
|
359
|
+
const limit = asInt(rawArgs, "limit", 1, historyPageLimits.read.max) ?? historyPageLimits.read.default;
|
|
813
360
|
const childrenOffset = asInt(rawArgs, "childrenOffset", 0, 10_000_000) ?? 0;
|
|
814
361
|
return { node: readWorkspaceHistory(root, id, offset, limit, childrenOffset, hostFilter) };
|
|
815
362
|
}
|
|
363
|
+
}
|
|
364
|
+
const { host, service, owner } = this.workerService(root, configuration.acp);
|
|
365
|
+
switch (name) {
|
|
816
366
|
case "worker_create": {
|
|
817
367
|
const backend = this.resolveBackend(rawArgs, configuration.acp, false);
|
|
818
368
|
const model = asString(rawArgs, "model");
|
|
@@ -858,9 +408,8 @@ export class McpWorkerRuntime {
|
|
|
858
408
|
}
|
|
859
409
|
case "worker_response": {
|
|
860
410
|
const workerId = asString(rawArgs, "workerId", true);
|
|
861
|
-
const
|
|
862
|
-
requireThat(
|
|
863
|
-
const action = rawAction;
|
|
411
|
+
const action = asString(rawArgs, "action", true);
|
|
412
|
+
requireThat(isOneOf(action, acpElicitationActions), `参数 action 无效:${action}(可用:${acpElicitationActions.join(", ")})。`);
|
|
864
413
|
const requestId = asString(rawArgs, "requestId");
|
|
865
414
|
const optionId = asString(rawArgs, "optionId");
|
|
866
415
|
const content = asContent(rawArgs, "content");
|
|
@@ -883,7 +432,7 @@ export class McpWorkerRuntime {
|
|
|
883
432
|
}
|
|
884
433
|
case "worker_discover": {
|
|
885
434
|
const rawTarget = asString(rawArgs, "target") ?? "overview";
|
|
886
|
-
requireThat(
|
|
435
|
+
requireThat(isOneOf(rawTarget, discoverTargets), `参数 target 无效:${rawTarget}(可用:${discoverTargets.join(", ")})。`);
|
|
887
436
|
const target = rawTarget;
|
|
888
437
|
const workerId = asString(rawArgs, "workerId");
|
|
889
438
|
const backendRaw = asString(rawArgs, "backend");
|
|
@@ -919,17 +468,18 @@ export class McpWorkerRuntime {
|
|
|
919
468
|
};
|
|
920
469
|
}
|
|
921
470
|
}
|
|
471
|
+
throw new Error(`未知工具:${name}`);
|
|
922
472
|
}
|
|
923
|
-
|
|
924
|
-
if (this.#
|
|
925
|
-
return;
|
|
926
|
-
this.#closed = true;
|
|
473
|
+
close(preserve = false) {
|
|
474
|
+
if (this.#closing)
|
|
475
|
+
return this.#closing;
|
|
927
476
|
const entries = [...this.#services.values()];
|
|
928
477
|
this.#services.clear();
|
|
929
|
-
|
|
478
|
+
this.#closing = Promise.allSettled([
|
|
930
479
|
this.#bridge.close(),
|
|
931
480
|
...entries.map(({ service, owner }) => service.close(owner, preserve)),
|
|
932
|
-
]);
|
|
481
|
+
]).then(() => { });
|
|
482
|
+
return this.#closing;
|
|
933
483
|
}
|
|
934
484
|
}
|
|
935
485
|
export async function handleMcpRequest(runtime, message, notify) {
|