personal-bot 0.2.20 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +2 -5
- package/.mcp.json +11 -0
- package/CONTEXT.md +17 -73
- package/README.md +41 -120
- package/README.zh-CN.md +41 -120
- package/docs/README.md +31 -23
- package/docs/architecture/design.md +74 -0
- package/docs/architecture/extensibility.md +78 -0
- package/docs/architecture/model-context.md +31 -0
- package/docs/architecture/model-instruction-guidelines.md +34 -0
- package/docs/architecture/principles.md +33 -0
- package/docs/guides/capabilities.md +36 -0
- package/docs/guides/cross-harness-workers.md +83 -0
- package/docs/guides/history.md +25 -0
- package/docs/guides/workspace-configuration.md +102 -0
- package/docs/hosts/antigravity.md +52 -0
- package/docs/hosts/claude-code.md +47 -0
- package/docs/hosts/dsh.md +67 -0
- package/docs/hosts/pi.md +49 -0
- package/docs/maintainers/release.md +59 -0
- package/hooks/hooks.json +0 -3
- package/lib/antigravity-plugin/hooks.json +23 -0
- package/lib/antigravity-plugin/lib/claude.d.ts +1 -0
- package/lib/antigravity-plugin/lib/claude.js +13 -0
- package/lib/antigravity-plugin/lib/common/json.d.ts +6 -0
- package/lib/antigravity-plugin/lib/common/json.js +16 -0
- package/lib/antigravity-plugin/lib/common/paths.d.ts +1 -0
- package/lib/antigravity-plugin/lib/common/paths.js +2 -0
- package/lib/antigravity-plugin/lib/common/validation.d.ts +3 -0
- package/lib/antigravity-plugin/lib/common/validation.js +8 -0
- package/lib/antigravity-plugin/lib/common/version.d.ts +3 -0
- package/lib/antigravity-plugin/lib/common/version.js +13 -0
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +11597 -0
- package/lib/antigravity-plugin/lib/extension/mcp.js +2715 -0
- package/lib/antigravity-plugin/lib/extension/plugin-runtime.d.ts +10 -0
- package/lib/antigravity-plugin/lib/extension/plugin-runtime.js +67 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +16 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +56 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.js +79 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/claude.d.ts +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/claude.js +60 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/registry.d.ts +15 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/registry.js +34 -0
- package/lib/antigravity-plugin/lib/model/acp.d.ts +164 -0
- package/lib/antigravity-plugin/lib/model/acp.js +12 -0
- package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +48 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +24 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.js +1 -0
- package/lib/antigravity-plugin/lib/model/workspace-mcp.d.ts +51 -0
- package/lib/antigravity-plugin/lib/model/workspace-mcp.js +4 -0
- package/lib/antigravity-plugin/lib/plugin.d.ts +1 -0
- package/lib/antigravity-plugin/lib/plugin.js +17 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +8 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +93 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-preparation.d.ts +3 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-preparation.js +26 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.d.ts +8 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.js +91 -0
- package/lib/antigravity-plugin/lib/storage/atomic-json.d.ts +11 -0
- package/lib/antigravity-plugin/lib/storage/atomic-json.js +101 -0
- package/lib/antigravity-plugin/mcp_config.json +13 -0
- package/lib/antigravity-plugin/package.json +6 -0
- package/lib/antigravity-plugin/plugin.json +7 -0
- package/lib/antigravity-plugin/resources/agents/coordinator.md +11 -0
- package/{resources/claude → lib/antigravity-plugin/resources}/agents/general-purpose.md +0 -5
- package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -0
- package/lib/antigravity-plugin/resources/prompts/workspace.md +31 -0
- package/lib/antigravity-plugin/resources/references/compute-finance.md +22 -0
- package/lib/antigravity-plugin/resources/references/compute.md +16 -0
- package/lib/antigravity-plugin/resources/references/task-conductor.md +25 -0
- package/lib/antigravity-plugin/resources/templates/workspace-agents.md +21 -0
- package/lib/antigravity-plugin/skills/pbot/SKILL.md +16 -0
- package/lib/antigravity-plugin/skills/project-maintenance/SKILL.md +35 -0
- package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +42 -0
- package/lib/claude.js +4 -11
- package/lib/client.js +14 -531
- package/lib/common/markdown.js +2 -3
- package/lib/common/validation.d.ts +2 -0
- package/lib/common/validation.js +4 -0
- package/lib/extension/acp-member.d.ts +2 -0
- package/lib/extension/acp-member.js +9 -8
- package/lib/extension/acp-worker.js +11578 -121
- package/lib/extension/dsh/acp-member.js +26 -2
- package/lib/extension/dsh/command.js +19 -57
- package/lib/extension/dsh/history.js +2 -4
- package/lib/extension/dsh/management.d.ts +0 -2
- package/lib/extension/dsh/management.js +27 -126
- package/lib/extension/dsh/workspace.d.ts +5 -47
- package/lib/extension/dsh/workspace.js +76 -108
- package/lib/extension/mcp-bridge.d.ts +41 -0
- package/lib/extension/mcp-bridge.js +412 -0
- package/lib/extension/mcp-workers.d.ts +980 -0
- package/lib/extension/mcp-workers.js +882 -0
- package/lib/extension/mcp.js +2715 -0
- package/lib/extension/plugin-runtime.d.ts +10 -0
- package/lib/extension/plugin-runtime.js +67 -0
- package/lib/extension/setup-cli.js +215 -2
- package/lib/integrations/acp/agents.d.ts +10 -11
- package/lib/integrations/acp/agents.js +65 -33
- package/lib/integrations/acp/claude.d.ts +2 -2
- package/lib/integrations/acp/claude.js +5 -3
- package/lib/integrations/acp/connection.d.ts +17 -4
- package/lib/integrations/acp/connection.js +53 -27
- package/lib/integrations/acp/executable.d.ts +3 -0
- package/lib/integrations/acp/executable.js +42 -0
- package/lib/integrations/acp/harnesses/claude.d.ts +2 -0
- package/lib/integrations/acp/harnesses/claude.js +49 -0
- package/lib/integrations/acp/harnesses/dsh.d.ts +2 -0
- package/lib/integrations/acp/harnesses/dsh.js +35 -0
- package/lib/integrations/acp/harnesses/generic.d.ts +13 -0
- package/lib/integrations/acp/harnesses/generic.js +37 -0
- package/lib/integrations/acp/harnesses/pi.d.ts +2 -0
- package/lib/integrations/acp/harnesses/pi.js +34 -0
- package/lib/integrations/acp/harnesses/presets.d.ts +3 -0
- package/lib/integrations/acp/harnesses/presets.js +20 -0
- package/lib/integrations/acp/launch.d.ts +33 -4
- package/lib/integrations/acp/launch.js +60 -48
- package/lib/integrations/acp/mcp.d.ts +6 -0
- package/lib/integrations/acp/mcp.js +40 -0
- package/lib/integrations/acp/model-selection.d.ts +9 -2
- package/lib/integrations/acp/model-selection.js +73 -27
- package/lib/integrations/acp/registry.d.ts +18 -0
- package/lib/integrations/acp/registry.js +50 -0
- package/lib/integrations/agent-resources.d.ts +16 -1
- package/lib/integrations/agent-resources.js +45 -9
- package/lib/integrations/dsh/mcp.d.ts +4 -0
- package/lib/integrations/dsh/mcp.js +28 -0
- package/lib/integrations/dsh/resources.d.ts +3 -3
- package/lib/integrations/dsh/resources.js +21 -12
- package/lib/integrations/dsh/skills.d.ts +5 -1
- package/lib/integrations/dsh/skills.js +10 -6
- package/lib/integrations/hosts/antigravity.d.ts +4 -0
- package/lib/integrations/hosts/antigravity.js +79 -0
- package/lib/integrations/hosts/claude.d.ts +3 -0
- package/lib/integrations/hosts/claude.js +60 -0
- package/lib/integrations/hosts/registry.d.ts +15 -0
- package/lib/integrations/hosts/registry.js +34 -0
- package/lib/model/acp.d.ts +107 -2
- package/lib/model/acp.js +12 -1
- package/lib/model/agent.d.ts +35 -33
- package/lib/model/plugin-host.d.ts +48 -0
- package/lib/model/plugin-host.js +1 -0
- package/lib/model/workspace-config.d.ts +12 -0
- package/lib/model/workspace-mcp.d.ts +51 -0
- package/lib/model/workspace-mcp.js +4 -0
- package/lib/plugin.d.ts +1 -0
- package/lib/plugin.js +17 -0
- package/lib/services/agents/acp-run.d.ts +13 -1
- package/lib/services/agents/acp-run.js +30 -2
- package/lib/services/agents/agent-service.d.ts +35 -120
- package/lib/services/agents/agent-service.js +156 -160
- package/lib/services/installation/setup-service.js +17 -1
- package/lib/services/workspace/workspace-config.d.ts +2 -1
- package/lib/services/workspace/workspace-config.js +39 -7
- package/lib/services/workspace/workspace-mcp.d.ts +14 -0
- package/lib/services/workspace/workspace-mcp.js +200 -0
- package/lib/services/workspace/workspace-skills.d.ts +8 -0
- package/lib/services/workspace/workspace-skills.js +91 -0
- package/lib/storage/acp-files.d.ts +3 -1
- package/lib/storage/acp-files.js +32 -2
- package/lib/storage/acp-history.d.ts +3 -2
- package/lib/storage/acp-history.js +19 -7
- package/lib/storage/agent-files.d.ts +8 -8
- package/lib/storage/agent-files.js +27 -47
- package/lib/tools/history/contract.d.ts +1 -1
- package/lib/tools/history/contract.js +17 -11
- package/lib/ui/dsh/index.js +8 -3
- package/lib/ui/dsh/management.d.ts +1 -1
- package/lib/ui/dsh/management.js +24 -456
- package/lib/ui/dsh/remote.d.ts +0 -2
- package/lib/ui/dsh/remote.js +1 -1
- package/package.json +12 -7
- package/resources/agents/coordinator.md +2 -2
- package/resources/antigravity/skills/pbot/SKILL.md +16 -0
- package/resources/claude/skills/pbot/SKILL.md +1 -1
- package/resources/prompts/history-coordinator.md +1 -0
- package/resources/prompts/plugin-coordinator.md +1 -0
- package/resources/prompts/workspace.md +9 -8
- package/resources/references/compute.md +9 -11
- package/resources/references/task-conductor.md +12 -26
- package/resources/skills/project-maintenance/SKILL.md +16 -21
- package/resources/skills/provider-connections/SKILL.md +24 -40
- package/resources/templates/workspace-agents.md +4 -0
- package/scripts/README.md +17 -34
- package/src/claude.ts +4 -8
- package/src/common/markdown.ts +2 -3
- package/src/common/validation.ts +6 -0
- package/src/extension/acp-member.ts +9 -8
- package/src/extension/acp-worker.ts +239 -97
- package/src/extension/command.ts +38 -36
- package/src/extension/dsh/acp-member.ts +21 -2
- package/src/extension/dsh/command.ts +21 -51
- package/src/extension/dsh/files.ts +1 -0
- package/src/extension/dsh/history.ts +9 -6
- package/src/extension/dsh/management.ts +27 -58
- package/src/extension/dsh/workspace.ts +88 -99
- package/src/extension/events.ts +13 -10
- package/src/extension/history.ts +2 -50
- package/src/extension/lifecycle.ts +37 -22
- package/src/extension/mcp-bridge.ts +412 -0
- package/src/extension/mcp-workers.ts +941 -0
- package/src/extension/pi-acp-member.ts +29 -5
- package/src/extension/plugin-runtime.ts +63 -0
- package/src/extension/setup-cli.ts +186 -2
- package/src/integrations/acp/agents.ts +70 -24
- package/src/integrations/acp/claude.ts +11 -4
- package/src/integrations/acp/connection.ts +63 -25
- package/src/integrations/acp/executable.ts +41 -0
- package/src/integrations/acp/harnesses/claude.ts +50 -0
- package/src/integrations/acp/harnesses/dsh.ts +40 -0
- package/src/integrations/acp/harnesses/generic.ts +52 -0
- package/src/integrations/acp/harnesses/pi.ts +35 -0
- package/src/integrations/acp/harnesses/presets.ts +22 -0
- package/src/integrations/acp/launch.ts +69 -47
- package/src/integrations/acp/mcp.ts +43 -0
- package/src/integrations/acp/model-selection.ts +68 -25
- package/src/integrations/acp/registry.ts +60 -0
- package/src/integrations/agent-resources.ts +70 -6
- package/src/integrations/dsh/mcp.ts +30 -0
- package/src/integrations/dsh/resources.ts +28 -13
- package/src/integrations/dsh/skills.ts +16 -6
- package/src/integrations/hosts/antigravity.ts +83 -0
- package/src/integrations/hosts/claude.ts +62 -0
- package/src/integrations/hosts/registry.ts +42 -0
- package/src/integrations/pi/mcp.ts +26 -0
- package/src/mcp.ts +14 -0
- package/src/model/acp.ts +113 -3
- package/src/model/agent.ts +18 -14
- package/src/model/plugin-host.ts +39 -0
- package/src/model/workspace-config.ts +14 -0
- package/src/model/workspace-mcp.ts +64 -0
- package/src/pbot.ts +69 -20
- package/src/plugin.ts +19 -0
- package/src/services/agents/acp-run.ts +35 -3
- package/src/services/agents/agent-service.ts +180 -160
- package/src/services/installation/setup-service.ts +17 -2
- package/src/services/workspace/workspace-config.ts +42 -6
- package/src/services/workspace/workspace-mcp.ts +242 -0
- package/src/services/workspace/workspace-skills.ts +78 -0
- package/src/storage/acp-files.ts +32 -3
- package/src/storage/acp-history.ts +18 -7
- package/src/storage/agent-files.ts +27 -41
- package/src/tools/history/contract.ts +17 -11
- package/src/tools/register.ts +4 -8
- package/src/ui/dsh/index.ts +8 -3
- package/src/ui/dsh/management.ts +40 -282
- package/src/ui/dsh/remote.ts +2 -2
- package/docs/adr/0001-claude-skill-discovery.md +0 -3
- package/docs/adr/0002-claude-native-collaboration.md +0 -3
- package/docs/agent-collaboration.md +0 -190
- package/docs/architecture-guidelines.md +0 -37
- package/docs/capability-design.md +0 -55
- package/docs/claude-code-design.md +0 -44
- package/docs/claude-code.md +0 -57
- package/docs/dsh.md +0 -337
- package/docs/file-storage.md +0 -97
- package/docs/history.md +0 -54
- package/docs/installation-design.md +0 -86
- package/docs/interaction-design.md +0 -21
- package/docs/model-context.md +0 -76
- package/docs/model-instruction-guidelines.md +0 -51
- package/docs/release.md +0 -108
- package/docs/technical-design.md +0 -163
- package/docs/workspace-configuration.md +0 -79
- package/lib/extension/claude-hooks.d.ts +0 -9
- package/lib/extension/claude-hooks.js +0 -78
- package/lib/extension/dsh/agent-events.d.ts +0 -24
- package/lib/extension/dsh/agent-events.js +0 -242
- package/lib/extension/dsh/agent-runtime.d.ts +0 -49
- package/lib/extension/dsh/agent-runtime.js +0 -351
- package/lib/integrations/dsh/dsh-agents.d.ts +0 -30
- package/lib/integrations/dsh/dsh-agents.js +0 -104
- package/lib/integrations/dsh/input.d.ts +0 -21
- package/lib/integrations/dsh/input.js +0 -62
- package/lib/integrations/dsh/notifications.d.ts +0 -8
- package/lib/integrations/dsh/notifications.js +0 -55
- package/lib/integrations/dsh/session.d.ts +0 -14
- package/lib/integrations/dsh/session.js +0 -60
- package/lib/integrations/team-context.d.ts +0 -18
- package/lib/integrations/team-context.js +0 -61
- package/lib/model/team.d.ts +0 -85
- package/lib/services/agents/agent-notices.d.ts +0 -13
- package/lib/services/agents/agent-notices.js +0 -25
- package/lib/services/agents/start-options.d.ts +0 -4
- package/lib/services/agents/start-options.js +0 -20
- package/lib/services/agents/team-service.d.ts +0 -168
- package/lib/services/agents/team-service.js +0 -345
- package/lib/storage/team-files.d.ts +0 -16
- package/lib/storage/team-files.js +0 -111
- package/lib/tools/agents/actions.d.ts +0 -62
- package/lib/tools/agents/actions.js +0 -62
- package/lib/tools/agents/contract.d.ts +0 -181
- package/lib/tools/agents/contract.js +0 -84
- package/lib/tools/agents/dsh-tool.d.ts +0 -5
- package/lib/tools/agents/dsh-tool.js +0 -34
- package/lib/tools/result.d.ts +0 -18
- package/lib/tools/result.js +0 -10
- package/lib/tools/teams/actions.d.ts +0 -23
- package/lib/tools/teams/actions.js +0 -40
- package/lib/tools/teams/contract.d.ts +0 -201
- package/lib/tools/teams/contract.js +0 -91
- package/lib/tools/teams/dsh-tool.d.ts +0 -8
- package/lib/tools/teams/dsh-tool.js +0 -39
- package/lib/ui/dsh/attachments.d.ts +0 -5
- package/lib/ui/dsh/attachments.js +0 -39
- package/resources/prompts/claude-coordinator.md +0 -1
- package/resources/prompts/native-coordinator.md +0 -1
- package/resources/prompts/team-member.md +0 -7
- package/src/extension/agent-events.ts +0 -210
- package/src/extension/agents-command.ts +0 -89
- package/src/extension/claude-hooks.ts +0 -74
- package/src/extension/dsh/agent-events.ts +0 -148
- package/src/extension/dsh/agent-runtime.ts +0 -252
- package/src/extension/subagent-entry.ts +0 -270
- package/src/extension/teams-command.ts +0 -67
- package/src/integrations/dsh/dsh-agents.ts +0 -97
- package/src/integrations/dsh/input.ts +0 -66
- package/src/integrations/dsh/notifications.ts +0 -46
- package/src/integrations/pi/agent-context.ts +0 -18
- package/src/integrations/pi/agent-input.ts +0 -19
- package/src/integrations/pi/pi-agents.ts +0 -84
- package/src/integrations/pi/team-context.ts +0 -26
- package/src/integrations/team-context.ts +0 -64
- package/src/model/team.ts +0 -29
- package/src/services/agents/agent-notices.ts +0 -28
- package/src/services/agents/start-options.ts +0 -19
- package/src/services/agents/team-service.ts +0 -275
- package/src/storage/team-files.ts +0 -93
- package/src/tools/agents/actions.ts +0 -57
- package/src/tools/agents/contract.ts +0 -101
- package/src/tools/agents/dsh-tool.ts +0 -37
- package/src/tools/agents/tool.ts +0 -20
- package/src/tools/teams/actions.ts +0 -34
- package/src/tools/teams/contract.ts +0 -109
- package/src/tools/teams/dsh-tool.ts +0 -45
- package/src/tools/teams/tool.ts +0 -29
- package/src/ui/agent-display.ts +0 -14
- package/src/ui/dsh/attachments.ts +0 -42
- package/src/ui/pi/menu.ts +0 -37
- package/src/ui/pi/reader.ts +0 -46
- /package/lib/{model/team.js → antigravity-plugin/lib/model/plugin-host.js} +0 -0
|
@@ -1,115 +1,257 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { dirname, resolve } from "node:path";
|
|
2
|
+
import type { RequestPermissionRequest } from "@agentclientprotocol/sdk";
|
|
3
3
|
import { AgentFiles, descriptor, launch, status } from "../storage/agent-files.js";
|
|
4
4
|
import { acpModelState, acpReference } from "../storage/acp-files.js";
|
|
5
|
-
import type { AcpModelSelection } from "../model/acp.js";
|
|
5
|
+
import type { AcpModelSelection, AcpSessionReference } from "../model/acp.js";
|
|
6
6
|
import { AcpAgentRun } from "../services/agents/acp-run.js";
|
|
7
7
|
import { openAcp } from "../integrations/acp/connection.js";
|
|
8
|
-
import { acpExecutable } from "../integrations/acp/launch.js";
|
|
9
|
-
import { claudeOptions } from "../integrations/acp/claude.js";
|
|
10
8
|
import { acpContent } from "../integrations/acp/input.js";
|
|
11
|
-
import {
|
|
9
|
+
import { toAcpMcpServers } from "../integrations/acp/mcp.js";
|
|
10
|
+
import { resolveAcpHarness } from "../integrations/acp/registry.js";
|
|
11
|
+
import { loadWorkspaceContext } from "../integrations/agent-resources.js";
|
|
12
|
+
import { readWorkspaceConfig, workspaceFeatures } from "../services/workspace/workspace-config.js";
|
|
13
|
+
import { readWorkspaceMcpConfig, resolveWorkspaceMcpServers } from "../services/workspace/workspace-mcp.js";
|
|
14
|
+
import { discoverWorkspaceSkills } from "../services/workspace/workspace-skills.js";
|
|
15
|
+
import { object } from "../common/json.js";
|
|
12
16
|
import { resourceRoot } from "../common/paths.js";
|
|
13
17
|
import { requireThat } from "../common/validation.js";
|
|
14
18
|
import { packageVersion, releaseLine } from "../common/version.js";
|
|
15
|
-
import type { NativeAgentHost } from "../model/agent.js";
|
|
16
19
|
|
|
17
|
-
const
|
|
18
|
-
const option = (name: string) => args[args.indexOf(name) + 1];
|
|
19
|
-
const directory = option("--directory"), id = option("--pbot-acp-agent"), generation = option("--generation");
|
|
20
|
-
requireThat(directory && id && generation, "缺少 ACP worker 启动信息。");
|
|
21
|
-
const files = new AgentFiles(dirname(directory), option("--host") as NativeAgentHost);
|
|
22
|
-
requireThat(files.directory(id) === directory, "ACP worker 目录不匹配。");
|
|
23
|
-
const d = files.read(id, "descriptor.json", descriptor), reference = files.read(id, "acp-session.json", acpReference);
|
|
24
|
-
requireThat(d.agentId === id && releaseLine(d.release) === releaseLine(packageVersion), "ACP worker 身份或版本不匹配。");
|
|
25
|
-
const validating = args.includes("--validate"), lifetime = new AbortController();
|
|
26
|
-
let execution: AcpAgentRun | undefined;
|
|
27
|
-
const stop = () => { void execution?.stop().catch(error => lifetime.abort(error)); if (!execution) lifetime.abort(); };
|
|
28
|
-
process.on("SIGTERM", stop); process.on("SIGINT", stop);
|
|
20
|
+
const errorMessage = (error: unknown) => error instanceof Error ? error.message : String(error);
|
|
29
21
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
const saveSelection = (selection: AcpModelSelection) => {
|
|
51
|
-
if (validating) return;
|
|
52
|
-
const run = files.read(id!, "launch.json", launch);
|
|
53
|
-
if (run.generation === generation && !run.stop) files.write(id!, "acp-model.json", { generation, ...selection }, acpModelState);
|
|
54
|
-
};
|
|
55
|
-
const claude = reference.backend === "claude" ? await claudeOptions(reference, d.cwd, d.options.thinking) : undefined;
|
|
56
|
-
const connection = await openAcp(command, d.cwd, env, {
|
|
57
|
-
selection: saveSelection,
|
|
58
|
-
update(update) {
|
|
59
|
-
if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") execution?.update({ kind: "text", text: update.content.text,
|
|
60
|
-
...(update.messageId ? { messageId: update.messageId } : {}) });
|
|
61
|
-
else if (update.sessionUpdate === "agent_thought_chunk") execution?.update({ kind: "thought" });
|
|
62
|
-
else if (update.sessionUpdate === "tool_call" || update.sessionUpdate === "tool_call_update") execution?.update({ kind: update.sessionUpdate === "tool_call" ? "tool" : "activity", activity: update.name ?? update.title ?? "工具" });
|
|
63
|
-
},
|
|
64
|
-
async permission(request, signal) {
|
|
65
|
-
if (!execution) return { outcome: { outcome: "cancelled" } };
|
|
66
|
-
const selected = await execution.permission(JSON.stringify(request.toolCall, null, 2), request.options, signal);
|
|
67
|
-
return { outcome: selected === null ? { outcome: "cancelled" } : { outcome: "selected", optionId: selected } };
|
|
68
|
-
},
|
|
69
|
-
}, lifetime.signal, prompt, claude);
|
|
22
|
+
function sendIpc(message: unknown): Promise<void> {
|
|
23
|
+
return new Promise(resolveSend => {
|
|
24
|
+
if (!process.connected || !process.send) { resolveSend(); return; }
|
|
25
|
+
process.send(message, undefined, undefined, () => resolveSend());
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function permissionDescription(request: RequestPermissionRequest) {
|
|
30
|
+
const call = request.toolCall;
|
|
31
|
+
const detail = call.rawInput === undefined ? "" : JSON.stringify(call.rawInput);
|
|
32
|
+
return [call.title ?? "工具调用", call.kind ? "类型:" + call.kind : "", call.locations?.length ? "路径:" + call.locations.map(item => item.path).join(", ") : "",
|
|
33
|
+
detail ? "参数:" + (detail.length > 2000 ? detail.slice(0, 2000) + "…" : detail) : ""].filter(Boolean).join("\n");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function runProbe() {
|
|
37
|
+
const lifetime = new AbortController();
|
|
38
|
+
const stop = () => lifetime.abort(new Error("ACP 模型探测已取消。"));
|
|
39
|
+
process.on("SIGTERM", stop);
|
|
40
|
+
process.on("SIGINT", stop);
|
|
70
41
|
try {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
42
|
+
const payload = await new Promise<{ reference: AcpSessionReference; cwd: string; provider?: string; model?: string }>((resolvePayload, rejectPayload) => {
|
|
43
|
+
const timer = setTimeout(() => rejectPayload(new Error("缺少 ACP 模型探测参数。")), 5000);
|
|
44
|
+
process.once("message", (value: unknown) => {
|
|
45
|
+
clearTimeout(timer);
|
|
46
|
+
if (!object(value)) { rejectPayload(new Error("ACP 模型探测参数必须是对象。")); return; }
|
|
47
|
+
resolvePayload(value as { reference: AcpSessionReference; cwd: string; provider?: string; model?: string });
|
|
48
|
+
});
|
|
49
|
+
process.once("disconnect", () => { clearTimeout(timer); rejectPayload(new Error("ACP 模型探测通道已断开。")); });
|
|
50
|
+
});
|
|
51
|
+
const reference = acpReference(payload.reference);
|
|
52
|
+
requireThat(typeof payload.cwd === "string" && payload.cwd.length > 0, "缺少 ACP 模型探测目录。");
|
|
53
|
+
const env: NodeJS.ProcessEnv = { ...process.env, ...(reference.env ?? {}) };
|
|
54
|
+
const connection = await openAcp(reference, payload.cwd, env, {
|
|
55
|
+
update() {},
|
|
56
|
+
async permission() { return { outcome: { outcome: "cancelled" } }; },
|
|
57
|
+
}, lifetime.signal);
|
|
58
|
+
try {
|
|
59
|
+
if (payload.model) {
|
|
60
|
+
await connection.configure({
|
|
61
|
+
...(payload.provider ? { provider: payload.provider } : {}),
|
|
62
|
+
model: payload.model,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
await sendIpc({
|
|
66
|
+
type: "models",
|
|
67
|
+
result: {
|
|
68
|
+
backend: reference.backend,
|
|
69
|
+
...connection.choices(),
|
|
70
|
+
selection: connection.selection(),
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
} finally {
|
|
74
|
+
await connection.close();
|
|
75
|
+
}
|
|
76
|
+
} catch (error) {
|
|
77
|
+
await sendIpc({ type: "error", error: errorMessage(error) });
|
|
78
|
+
process.exitCode = 1;
|
|
91
79
|
} finally {
|
|
92
|
-
|
|
80
|
+
lifetime.abort();
|
|
81
|
+
if (process.connected) process.disconnect();
|
|
93
82
|
}
|
|
94
83
|
}
|
|
95
84
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
85
|
+
async function runWorker(args: string[]) {
|
|
86
|
+
const option = (name: string) => args[args.indexOf(name) + 1];
|
|
87
|
+
const directory = option("--directory"), id = option("--pbot-acp-agent"), generation = option("--generation");
|
|
88
|
+
requireThat(directory && id && generation, "缺少 ACP worker 启动信息。");
|
|
89
|
+
const files = new AgentFiles(dirname(directory));
|
|
90
|
+
requireThat(files.directory(id) === directory, "ACP worker 目录不匹配。");
|
|
91
|
+
const d = files.read(id, "descriptor.json", descriptor), reference = files.read(id, "acp-session.json", acpReference);
|
|
92
|
+
requireThat(d.agentId === id && releaseLine(d.release) === releaseLine(packageVersion), "ACP worker 身份或版本不匹配。");
|
|
93
|
+
const validating = args.includes("--validate"), lifetime = new AbortController();
|
|
94
|
+
let execution: AcpAgentRun | undefined;
|
|
95
|
+
const stop = () => { void execution?.stop().catch(error => lifetime.abort(error)); if (!execution) lifetime.abort(); };
|
|
96
|
+
process.on("SIGTERM", stop); process.on("SIGINT", stop);
|
|
97
|
+
|
|
98
|
+
async function main() {
|
|
99
|
+
requireThat(files.read(id!, "launch.json", launch).generation === generation, "ACP worker 启动代次已失效。");
|
|
100
|
+
const harness = resolveAcpHarness(reference.backend);
|
|
101
|
+
const exactAnswer = Boolean(harness.exactAnswer);
|
|
102
|
+
const packageRoot = resolve(resourceRoot, "..");
|
|
103
|
+
const configuration = await readWorkspaceConfig(d.workspace);
|
|
104
|
+
const features = workspaceFeatures(configuration);
|
|
105
|
+
const baseEnv: NodeJS.ProcessEnv = {
|
|
106
|
+
...process.env,
|
|
107
|
+
PBOT_SUBAGENT_RUN_ID: id!,
|
|
108
|
+
PBOT_SUBAGENT_DIR: directory!,
|
|
109
|
+
PBOT_SUBAGENT_GENERATION: generation!,
|
|
110
|
+
...(validating ? { PBOT_ACP_VALIDATE: "1" } : {}),
|
|
111
|
+
};
|
|
112
|
+
const prepared = harness.prepareLaunch
|
|
113
|
+
? await harness.prepareLaunch({ reference, cwd: d.cwd, directory: directory!, packageRoot, options: d.options, env: baseEnv, features })
|
|
114
|
+
: { command: { ...reference, args: [...reference.args] }, env: { ...baseEnv, ...(reference.env ?? {}) } };
|
|
115
|
+
|
|
116
|
+
let prompt: string | undefined;
|
|
117
|
+
if (!exactAnswer) {
|
|
118
|
+
const workspaceSkills = features.skills && !harness.nativeWorkspaceSkills && !d.options.noSkills
|
|
119
|
+
? await discoverWorkspaceSkills(d.workspace)
|
|
120
|
+
: [];
|
|
121
|
+
if (features.prompts || workspaceSkills.length > 0) {
|
|
122
|
+
prompt = (await loadWorkspaceContext({
|
|
123
|
+
host: reference.backend,
|
|
124
|
+
root: d.workspace,
|
|
125
|
+
role: "general-purpose",
|
|
126
|
+
includePrompts: features.prompts,
|
|
127
|
+
workspaceSkills,
|
|
128
|
+
})).text;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let mcpServers: ReturnType<typeof toAcpMcpServers> | undefined;
|
|
133
|
+
if (features.mcp && !harness.nativeWorkspaceMcp && !validating) {
|
|
134
|
+
const mcpConfig = await readWorkspaceMcpConfig(d.workspace);
|
|
135
|
+
if (mcpConfig.present) {
|
|
136
|
+
const resolved = resolveWorkspaceMcpServers(d.workspace, mcpConfig, prepared.env);
|
|
137
|
+
if (resolved.length) mcpServers = toAcpMcpServers(resolved);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Only publish acp-model.json after requested model/thinking options are applied so callers can detect startup readiness.
|
|
142
|
+
let configured = false;
|
|
143
|
+
const saveSelection = (selection: AcpModelSelection) => {
|
|
144
|
+
if (validating || !configured) return;
|
|
145
|
+
const run = files.read(id!, "launch.json", launch);
|
|
146
|
+
if (run.generation === generation && !run.stop) files.write(id!, "acp-model.json", { generation, ...selection }, acpModelState);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const connection = await openAcp(prepared.command, d.cwd, prepared.env, {
|
|
150
|
+
selection: saveSelection,
|
|
151
|
+
update(update) {
|
|
152
|
+
if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
|
|
153
|
+
execution?.update({ kind: "text", text: update.content.text, ...(update.messageId ? { messageId: update.messageId } : {}) });
|
|
154
|
+
} else if (update.sessionUpdate === "agent_thought_chunk") {
|
|
155
|
+
execution?.update({ kind: "thought" });
|
|
156
|
+
} else if (update.sessionUpdate === "tool_call" || update.sessionUpdate === "tool_call_update") {
|
|
157
|
+
execution?.update({ kind: update.sessionUpdate === "tool_call" ? "tool" : "activity", activity: update.name ?? update.title ?? "工具" });
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
async permission(request, signal) {
|
|
161
|
+
if (!execution) return { outcome: { outcome: "cancelled" } };
|
|
162
|
+
const policy = reference.permission ?? "ask";
|
|
163
|
+
const pick = (...kinds: string[]) => kinds.map(kind => request.options.find(item => item.kind === kind)).find(Boolean)?.optionId;
|
|
164
|
+
// ask forwards the request to the parent session; allow/deny follow the workspace's explicit configuration.
|
|
165
|
+
const optionId = policy === "allow" ? pick("allow_once", "allow_always")
|
|
166
|
+
: policy === "deny" ? pick("reject_once", "reject_always")
|
|
167
|
+
: await execution.permission(permissionDescription(request),
|
|
168
|
+
request.options.map(({ optionId, name, kind }) => ({ optionId, name, kind })), signal);
|
|
169
|
+
return optionId ? { outcome: { outcome: "selected", optionId } } : { outcome: { outcome: "cancelled" } };
|
|
170
|
+
},
|
|
171
|
+
async elicitation(request, signal) {
|
|
172
|
+
if (!execution) return { action: "cancel" };
|
|
173
|
+
if (request.mode === "form") {
|
|
174
|
+
const schema = "requestedSchema" in request && object(request.requestedSchema)
|
|
175
|
+
? request.requestedSchema
|
|
176
|
+
: { type: "object", properties: {} };
|
|
177
|
+
const reply = await execution.elicitation({ mode: "form", message: request.message, schema }, signal);
|
|
178
|
+
if (reply.action === "accept") return { action: "accept", content: reply.content ?? {} };
|
|
179
|
+
return reply.action === "decline" ? { action: "decline" } : { action: "cancel" };
|
|
180
|
+
}
|
|
181
|
+
if (request.mode === "url" && "url" in request && typeof request.url === "string" && request.url.length > 0) {
|
|
182
|
+
const reply = await execution.elicitation({ mode: "url", message: request.message, url: request.url }, signal);
|
|
183
|
+
if (reply.action === "accept") return { action: "accept" };
|
|
184
|
+
return reply.action === "decline" ? { action: "decline" } : { action: "cancel" };
|
|
185
|
+
}
|
|
186
|
+
return { action: "decline" };
|
|
187
|
+
},
|
|
188
|
+
}, lifetime.signal, {
|
|
189
|
+
harness,
|
|
190
|
+
...(prompt ? { systemPrompt: prompt } : {}),
|
|
191
|
+
...(prepared.sessionMeta ? { sessionMeta: prepared.sessionMeta } : {}),
|
|
192
|
+
...(prepared.defaultThinking ? { defaultThinking: prepared.defaultThinking } : {}),
|
|
193
|
+
...(mcpServers ? { mcpServers } : {}),
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
requireThat(!prompt || !harness.requireSystemPrompt || connection.systemPrompt,
|
|
198
|
+
`${reference.backend} ACP 后端需要支持 systemPrompt,以加载专家职责与工作区资料。`);
|
|
199
|
+
if (validating) { await sendIpc({ type: "validated" }); return; }
|
|
200
|
+
if (reference.sessionId === null) await connection.configure(d.options);
|
|
201
|
+
requireThat(files.read(id!, "launch.json", launch).generation === generation && !files.read(id!, "launch.json", launch).stop, "ACP 启动已取消。");
|
|
202
|
+
files.write(id!, "acp-session.json", {
|
|
203
|
+
...reference,
|
|
204
|
+
sessionId: harness.eagerSessionId || reference.sessionId !== null ? connection.sessionId : null,
|
|
205
|
+
capabilities: connection.capabilities,
|
|
206
|
+
}, acpReference);
|
|
207
|
+
configured = true;
|
|
208
|
+
saveSelection(connection.selection());
|
|
209
|
+
let promptInjected = reference.sessionId !== null || connection.systemPrompt;
|
|
210
|
+
execution = new AcpAgentRun(files, d, generation!, {
|
|
211
|
+
signal: connection.signal,
|
|
212
|
+
async prompt(request) {
|
|
213
|
+
const effective = !exactAnswer && prompt && !promptInjected
|
|
214
|
+
? { ...request, message: prompt + "\n\n---\n\n" + request.message }
|
|
215
|
+
: request;
|
|
216
|
+
promptInjected = true;
|
|
217
|
+
const content = await acpContent(effective, connection.images, connection.signal);
|
|
218
|
+
const run = files.read(id!, "launch.json", launch);
|
|
219
|
+
requireThat(run.generation === generation && !run.stop, "ACP 输入已取消或启动代次变化。");
|
|
220
|
+
connection.signal.throwIfAborted();
|
|
221
|
+
const saved = files.read(id!, "acp-session.json", acpReference);
|
|
222
|
+
if (saved.sessionId === null) files.write(id!, "acp-session.json", { ...saved, sessionId: connection.sessionId }, acpReference);
|
|
223
|
+
return connection.prompt(content);
|
|
224
|
+
},
|
|
225
|
+
cancel: () => connection.cancel(),
|
|
226
|
+
}, exactAnswer);
|
|
227
|
+
await execution.run();
|
|
228
|
+
} finally {
|
|
229
|
+
try { await connection.close(); } finally { await execution?.settled(); }
|
|
230
|
+
}
|
|
101
231
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
232
|
+
|
|
233
|
+
try {
|
|
234
|
+
await main();
|
|
235
|
+
if (!validating && files.read(id, "launch.json", launch).generation === generation) {
|
|
236
|
+
if (execution) execution.execution.save({ state: "stopped", activity: "已停止" });
|
|
237
|
+
else files.write(id, "status.json", { generation, state: "stopped", activity: "已停止", updatedAt: Date.now() }, status);
|
|
238
|
+
}
|
|
239
|
+
} catch (error) {
|
|
240
|
+
if (validating) { await sendIpc({ type: "error", error: errorMessage(error) }); }
|
|
241
|
+
else if (files.read(id, "launch.json", launch).generation === generation) {
|
|
242
|
+
const stopped = files.read(id, "launch.json", launch).stop;
|
|
243
|
+
const patch = { state: stopped ? "stopped" as const : "error" as const, activity: stopped ? "已停止" : "ACP 执行失败", ...(stopped ? {} : { error: errorMessage(error) }) };
|
|
244
|
+
if (execution) execution.execution.save(patch);
|
|
245
|
+
else files.write(id, "status.json", { generation, ...patch, updatedAt: Date.now() }, status);
|
|
246
|
+
}
|
|
247
|
+
process.exitCode = 1;
|
|
248
|
+
} finally {
|
|
249
|
+
lifetime.abort();
|
|
250
|
+
if (process.connected) process.disconnect();
|
|
251
|
+
// Keep child processes in this worker's process group so forced release covers descendants.
|
|
109
252
|
}
|
|
110
|
-
process.exitCode = 1;
|
|
111
|
-
} finally {
|
|
112
|
-
lifetime.abort();
|
|
113
|
-
if (process.connected) process.disconnect();
|
|
114
|
-
// Keep child processes in this worker's process group so forced release covers descendants.
|
|
115
253
|
}
|
|
254
|
+
|
|
255
|
+
const args = process.argv.slice(2);
|
|
256
|
+
if (args.includes("--probe")) await runProbe();
|
|
257
|
+
else await runWorker(args);
|
package/src/extension/command.ts
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { packageVersion } from "../common/version.js";
|
|
3
3
|
import { initializeWorkspace } from "../services/workspace/workspace-preparation.js";
|
|
4
|
+
import { workspaceDisabledMessage } from "../services/workspace/workspace-config.js";
|
|
4
5
|
import type { Confirmations } from "../ui/confirmation.js";
|
|
5
|
-
import { readPage } from "../ui/pi/reader.js";
|
|
6
|
-
import { choose } from "../ui/pi/menu.js";
|
|
7
|
-
import { agentOwner } from "../integrations/pi/agent-context.js";
|
|
8
6
|
import type { Lifecycle } from "./lifecycle.js";
|
|
9
|
-
import {
|
|
10
|
-
import { showTeams } from "./teams-command.js";
|
|
11
|
-
import { showHistory } from "./history.js";
|
|
12
|
-
import { workspaceDisabledMessage } from "../services/workspace/workspace-config.js";
|
|
7
|
+
import { parseWorkerCommand } from "./mcp-workers.js";
|
|
13
8
|
|
|
14
9
|
export function registerCommand(pi: ExtensionAPI, lifecycle: Lifecycle, confirmations: Confirmations) {
|
|
15
10
|
pi.registerCommand("pbot", {
|
|
16
|
-
description: "
|
|
11
|
+
description: "工作区初始化、状态与跨 Harness worker 管理",
|
|
17
12
|
getArgumentCompletions: prefix => {
|
|
18
13
|
if (/\s/.test(prefix)) return null;
|
|
19
|
-
return ["init", "status", "
|
|
14
|
+
return ["init", "status", "worker"]
|
|
20
15
|
.filter(command => command.startsWith(prefix)).map(command => ({ value: command, label: command }));
|
|
21
16
|
},
|
|
22
17
|
handler: async (args, ctx) => {
|
|
@@ -32,43 +27,50 @@ export function registerCommand(pi: ExtensionAPI, lifecycle: Lifecycle, confirma
|
|
|
32
27
|
}
|
|
33
28
|
if (!lifecycle.active) {
|
|
34
29
|
const configuration = lifecycle.configuration;
|
|
35
|
-
const status = {
|
|
30
|
+
const status = {
|
|
31
|
+
workspaceRoot: lifecycle.root ?? ctx.cwd,
|
|
32
|
+
release: packageVersion,
|
|
33
|
+
enabled: false,
|
|
36
34
|
state: configuration?.error || configuration?.enabled ? "error" : "disabled",
|
|
37
|
-
nextStep: configuration?.error ?? "/pbot init",
|
|
35
|
+
nextStep: configuration?.error ?? "/pbot init",
|
|
36
|
+
configuration,
|
|
37
|
+
};
|
|
38
38
|
ctx.ui.notify(command === "status" ? JSON.stringify(status, null, 2)
|
|
39
39
|
: configuration ? workspaceDisabledMessage(configuration) : "pbot 工作区实例不可用。", configuration?.error ? "error" : "info");
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
const instance = lifecycle.get();
|
|
43
|
+
if (command === "status" && !argument) {
|
|
44
|
+
if (ctx.mode !== "tui") {
|
|
45
|
+
ctx.ui.notify(JSON.stringify({
|
|
46
|
+
workspaceRoot: instance.root,
|
|
47
|
+
release: packageVersion,
|
|
48
|
+
enabled: true,
|
|
49
|
+
state: "running",
|
|
50
|
+
configuration: lifecycle.configuration,
|
|
51
|
+
}, null, 2), "info");
|
|
52
|
+
return;
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
const history = instance.history.status;
|
|
55
|
+
ctx.ui.notify([
|
|
56
|
+
`工作区 ${instance.root}`,
|
|
57
|
+
`状态 已启动 · 版本 ${packageVersion}`,
|
|
58
|
+
`历史 ${history.organizing ? "整理中" : history.pending === null ? "查询时更新索引" : history.pending + " 项待整理"}`,
|
|
59
|
+
...history.warnings,
|
|
60
|
+
].join("\n"), "info");
|
|
61
|
+
return;
|
|
57
62
|
}
|
|
58
|
-
if (command
|
|
59
|
-
if (confirmations.presenting) { ctx.ui.notify("请先处理待确认操作。", "info"); return; }
|
|
60
|
-
for (;;) {
|
|
61
|
-
const instance = lifecycle.get(), agents = instance.agents.list(agentOwner(ctx));
|
|
62
|
-
const choices = ["专家 · " + agents.length, "团队", "历史", "工作区状态", "准备资料目录"];
|
|
63
|
-
const choice = await choose(ctx, "Personal Bot", choices);
|
|
64
|
-
if (!choice) return;
|
|
65
|
-
const command = ["agents", "teams", "history", "status", "init"][choices.indexOf(choice)]!;
|
|
63
|
+
if (command === "worker") {
|
|
66
64
|
try {
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
const { tool, args: payload } = parseWorkerCommand(argument);
|
|
66
|
+
const result = await instance.workers.callTool(tool, { workspace: instance.root, ...payload });
|
|
67
|
+
ctx.ui.notify(JSON.stringify(result, null, 2), "info");
|
|
68
|
+
} catch (error) {
|
|
69
|
+
ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
|
|
69
70
|
}
|
|
70
|
-
|
|
71
|
+
return;
|
|
71
72
|
}
|
|
73
|
+
ctx.ui.notify('/pbot init | status | worker [overview|status|backends|models|create|request|response|output|close] [JSON]', "info");
|
|
72
74
|
},
|
|
73
75
|
});
|
|
74
76
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import * as McpClient from "@deepseek-ai/dsh-mcp-client";
|
|
2
3
|
import type { AcpInput } from "../../model/acp.js";
|
|
3
4
|
import { acpMember } from "../acp-member.js";
|
|
4
5
|
import { rootAgents } from "../../integrations/dsh/root-agents.js";
|
|
5
6
|
import { dshResources, dshExpertTools } from "../../integrations/dsh/resources.js";
|
|
6
7
|
import { registerDshSkills } from "../../integrations/dsh/skills.js";
|
|
8
|
+
import { toDshMcpConfig } from "../../integrations/dsh/mcp.js";
|
|
7
9
|
import { finalDshAnswer } from "../../integrations/dsh/messages.js";
|
|
10
|
+
import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../../services/workspace/workspace-mcp.js";
|
|
8
11
|
import { registerDshFileEvents } from "./files.js";
|
|
9
12
|
import { requireThat } from "../../common/validation.js";
|
|
10
13
|
|
|
@@ -24,9 +27,25 @@ export async function apply(ctx: Context) {
|
|
|
24
27
|
requireThat(reference.host === "acp" && reference.backend === "dsh" && agent.session.header.cwd === member.d.cwd &&
|
|
25
28
|
(reference.sessionId === null || reference.sessionId === agent.id), "dsh ACP 会话身份或工作目录不匹配。");
|
|
26
29
|
await agent.ctx.plugin({ name: "pbot-acp-expert", inject, apply: async scope => {
|
|
27
|
-
registerDshSkills(scope, agent);
|
|
30
|
+
if (member.features.skills) registerDshSkills(scope, agent, { workspaceRoot: member.d.workspace });
|
|
31
|
+
if (member.features.mcp && process.env.PBOT_ACP_VALIDATE !== "1") {
|
|
32
|
+
const mcpConfig = await readWorkspaceMcpConfig(member.d.workspace);
|
|
33
|
+
if (mcpConfig.error) {
|
|
34
|
+
ctx.logger.warn(mcpConfig.error);
|
|
35
|
+
} else {
|
|
36
|
+
for (const [serverName, server] of Object.entries(mcpConfig.servers)) {
|
|
37
|
+
if (server.enabled === false) continue;
|
|
38
|
+
try {
|
|
39
|
+
const resolved = resolveWorkspaceMcpServer(member.d.workspace, serverName, server);
|
|
40
|
+
await scope.plugin(McpClient, toDshMcpConfig(resolved));
|
|
41
|
+
} catch (error) {
|
|
42
|
+
ctx.logger.warn(error instanceof Error ? error.message : String(error));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
28
47
|
dshExpertTools(scope, agent, member.d.options);
|
|
29
|
-
await dshResources(scope, agent, member.d.workspace, "general-purpose", member.check);
|
|
48
|
+
if (member.features.prompts) await dshResources(scope, agent, member.d.workspace, "general-purpose", member.check);
|
|
30
49
|
registerDshFileEvents(scope, agent, member.d.workspace, true, member.check);
|
|
31
50
|
let input: AcpInput | undefined, answer = "";
|
|
32
51
|
scope.on("session/event", (session, event) => {
|
|
@@ -1,38 +1,27 @@
|
|
|
1
1
|
import type { Context } from "@deepseek-ai/cordis";
|
|
2
2
|
import type {} from "@deepseek-ai/dsh-commands";
|
|
3
|
-
import { Type, type Static } from "typebox";
|
|
4
3
|
import { object, json } from "../../common/json.js";
|
|
5
4
|
import { requireThat } from "../../common/validation.js";
|
|
6
|
-
import { schema } from "../../common/schema.js";
|
|
7
|
-
import { executeAgent } from "../../tools/agents/actions.js";
|
|
8
|
-
import { agentInput } from "../../tools/agents/contract.js";
|
|
9
|
-
import { executeTeam, executeTeamMessage } from "../../tools/teams/actions.js";
|
|
10
|
-
import { teamInput, teamMessageInput } from "../../tools/teams/contract.js";
|
|
11
5
|
import { dshWorkspaceStatus, type PbotManagement } from "./management.js";
|
|
12
6
|
import type { DshWorkspaces } from "./workspace.js";
|
|
7
|
+
import { parseWorkerCommand } from "../mcp-workers.js";
|
|
13
8
|
|
|
14
|
-
const
|
|
15
|
-
delivery: Type.Optional(Type.Union([Type.Literal("steer"), Type.Literal("followUp")])),
|
|
16
|
-
files: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 32 })) }, { additionalProperties: false });
|
|
17
|
-
const validChat = schema(chatSchema);
|
|
18
|
-
const approvalSchema = Type.Object({ agentId: Type.String({ minLength: 1 }), requestId: Type.String({ minLength: 1 }),
|
|
19
|
-
optionId: Type.Union([Type.String({ minLength: 1 }), Type.Null()]) }, { additionalProperties: false });
|
|
20
|
-
const validApproval = schema(approvalSchema);
|
|
21
|
-
const usage = '用法:/pbot status | init | agent {"action":…} | chat {"agentId":…,"text":…} | team {"action":…} | messages {"teamId":…} | post {"teamId":…,"text":…} | history {"action":…} | records {"agentId":…}';
|
|
9
|
+
const usage = '用法:/pbot status | init | worker [overview|status|backends|models|create|request|response|output|close] [JSON] | history {"action":…}';
|
|
22
10
|
|
|
23
11
|
export function registerDshCommand(ctx: Context, workspaces: DshWorkspaces, management: PbotManagement) {
|
|
24
|
-
ctx.commands.register({
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
ctx.commands.register({
|
|
13
|
+
name: "pbot",
|
|
14
|
+
description: "Personal Bot 工作区、跨 Harness worker 与历史管理",
|
|
15
|
+
recordInput: false,
|
|
16
|
+
input: { hint: "status | init | worker ... | history JSON", attachments: false },
|
|
17
|
+
async handler({ agent, rawInput, signal }) {
|
|
27
18
|
signal.throwIfAborted();
|
|
28
19
|
const command = rawInput.trim(), split = command.search(/\s/);
|
|
29
20
|
if (!command || command === "status") {
|
|
30
|
-
requireThat(!attachments.length, "状态查询不接受附件。");
|
|
31
21
|
const status = await dshWorkspaceStatus(workspaces, agent);
|
|
32
22
|
signal.throwIfAborted(); return { kind: "success", text: JSON.stringify(status, null, 2) };
|
|
33
23
|
}
|
|
34
24
|
if (command === "init") {
|
|
35
|
-
requireThat(!attachments.length, "初始化不接受附件。");
|
|
36
25
|
await workspaces.initialize(agent);
|
|
37
26
|
signal.throwIfAborted();
|
|
38
27
|
return { kind: "success", text: JSON.stringify(await dshWorkspaceStatus(workspaces, agent), null, 2) };
|
|
@@ -40,42 +29,23 @@ export function registerDshCommand(ctx: Context, workspaces: DshWorkspaces, mana
|
|
|
40
29
|
const workspace = await workspaces.get(agent);
|
|
41
30
|
signal.throwIfAborted();
|
|
42
31
|
const verb = split < 0 ? command : command.slice(0, split);
|
|
43
|
-
|
|
44
|
-
requireThat(split >= 0, usage);
|
|
45
|
-
const input: unknown = JSON.parse(command.slice(split));
|
|
46
|
-
requireThat(object(input), "命令参数必须是 JSON 对象。");
|
|
32
|
+
const rest = split < 0 ? "" : command.slice(split).trim();
|
|
47
33
|
let result: unknown;
|
|
48
34
|
switch (verb) {
|
|
49
|
-
case "
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
...(selection.reasoningEffort ? { thinking: selection.reasoningEffort } : {}),
|
|
54
|
-
} : {});
|
|
55
|
-
result = output.structuredContent; break;
|
|
35
|
+
case "worker": {
|
|
36
|
+
const { tool, args } = parseWorkerCommand(rest);
|
|
37
|
+
result = await workspace.workers.callTool(tool, { workspace: workspace.root, ...args });
|
|
38
|
+
break;
|
|
56
39
|
}
|
|
57
|
-
case "
|
|
58
|
-
requireThat(
|
|
59
|
-
const
|
|
60
|
-
|
|
40
|
+
case "history": {
|
|
41
|
+
requireThat(rest.length > 0, usage);
|
|
42
|
+
const input: unknown = JSON.parse(rest);
|
|
43
|
+
requireThat(object(input), "命令参数必须是 JSON 对象。");
|
|
44
|
+
result = await management.history({ parentSessionId: agent.id, input: json(input) }, signal);
|
|
45
|
+
break;
|
|
61
46
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const args = input as Static<typeof approvalSchema>;
|
|
65
|
-
workspace.agents.answerPermission(args.agentId, args.requestId, args.optionId, workspace.owner);
|
|
66
|
-
result = { answered: true }; break;
|
|
67
|
-
}
|
|
68
|
-
case "team":
|
|
69
|
-
result = executeTeam(workspace.teams, workspace.agents, teamInput(input), workspace.owner).structuredContent; break;
|
|
70
|
-
case "messages":
|
|
71
|
-
result = executeTeamMessage(workspace.teams, teamMessageInput({ ...input, action: "read" }),
|
|
72
|
-
{ kind: "coordinator", owner: workspace.owner }, commandId).structuredContent; break;
|
|
73
|
-
case "post":
|
|
74
|
-
result = executeTeamMessage(workspace.teams, teamMessageInput({ ...input, action: "post" }),
|
|
75
|
-
{ kind: "user", owner: workspace.owner }, commandId).structuredContent; break;
|
|
76
|
-
case "history": result = await management.history({ parentSessionId: agent.id, input: json(input) }, signal); break;
|
|
77
|
-
case "records": result = await management.expert({ parentSessionId: agent.id, input: json(input) }, signal); break;
|
|
78
|
-
default: throw new Error(usage);
|
|
47
|
+
default:
|
|
48
|
+
throw new Error(usage);
|
|
79
49
|
}
|
|
80
50
|
workspace.check();
|
|
81
51
|
return { kind: "success", text: JSON.stringify(result, null, 2) };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type {} from "@deepseek-ai/dsh-fs";
|
|
2
3
|
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
4
|
import type { ToolExecution, ToolExecutionToken } from "@deepseek-ai/dsh-tools";
|
|
4
5
|
import { parsePatch } from "@deepseek-ai/dsh-fs-patch";
|