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
|
@@ -2,13 +2,13 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { Readable, Writable } from "node:stream";
|
|
3
3
|
import { setTimeout as delay } from "node:timers/promises";
|
|
4
4
|
import * as acp from "@agentclientprotocol/sdk";
|
|
5
|
-
import type { AcpModelSelection, AcpSessionReference } from "../../model/acp.js";
|
|
5
|
+
import type { AcpHarnessAdapter, AcpModelSelection, AcpSessionReference } from "../../model/acp.js";
|
|
6
6
|
import type { AgentOptions } from "../../model/agent.js";
|
|
7
7
|
import { requireThat } from "../../common/validation.js";
|
|
8
8
|
import { packageVersion } from "../../common/version.js";
|
|
9
|
-
import { acpModelSelection, acpModelValue, acpThinkingValue } from "./model-selection.js";
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
9
|
+
import { acpChoices, acpModelSelection, acpModelValue, acpThinkingValue } from "./model-selection.js";
|
|
10
|
+
import { filterAcpMcpServers } from "./mcp.js";
|
|
11
|
+
import { resolveAcpHarness } from "./registry.js";
|
|
12
12
|
|
|
13
13
|
export function acpFailure(error: unknown): unknown {
|
|
14
14
|
return error instanceof acp.RequestError && error.data !== undefined
|
|
@@ -19,12 +19,28 @@ export interface AcpCallbacks {
|
|
|
19
19
|
update(update: acp.SessionUpdate): void | Promise<void>;
|
|
20
20
|
selection?(selection: AcpModelSelection): void;
|
|
21
21
|
permission(request: acp.RequestPermissionRequest, signal: AbortSignal): Promise<acp.RequestPermissionResponse>;
|
|
22
|
+
elicitation?(request: acp.CreateElicitationRequest, signal: AbortSignal): Promise<acp.CreateElicitationResponse>;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
export interface OpenAcpOptions {
|
|
26
|
+
readonly harness?: AcpHarnessAdapter;
|
|
27
|
+
readonly systemPrompt?: string;
|
|
28
|
+
readonly sessionMeta?: Record<string, unknown>;
|
|
29
|
+
readonly defaultThinking?: string;
|
|
30
|
+
readonly mcpServers?: readonly acp.McpServer[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** One ACP v1 connection. The worker owns its process group and business state; harness hooks stay in AcpHarnessAdapter. */
|
|
34
|
+
export async function openAcp(
|
|
35
|
+
reference: AcpSessionReference,
|
|
36
|
+
cwd: string,
|
|
37
|
+
env: NodeJS.ProcessEnv,
|
|
38
|
+
callbacks: AcpCallbacks,
|
|
39
|
+
signal: AbortSignal,
|
|
40
|
+
openOptions: OpenAcpOptions = {},
|
|
41
|
+
) {
|
|
27
42
|
signal.throwIfAborted();
|
|
43
|
+
const harness = openOptions.harness ?? resolveAcpHarness(reference.backend);
|
|
28
44
|
const child = spawn(reference.command, reference.args, { cwd, env, stdio: ["pipe", "pipe", "pipe"] });
|
|
29
45
|
const lifetime = new AbortController();
|
|
30
46
|
const cancel = AbortSignal.any([signal, lifetime.signal]);
|
|
@@ -36,14 +52,21 @@ export async function openAcp(reference: AcpSessionReference, cwd: string, env:
|
|
|
36
52
|
let sessionId: string | undefined;
|
|
37
53
|
let options: acp.SessionConfigOption[] = [];
|
|
38
54
|
let resolvedModel: string | undefined;
|
|
39
|
-
const selection = (): AcpModelSelection => ({
|
|
40
|
-
...(
|
|
55
|
+
const selection = (): AcpModelSelection => ({
|
|
56
|
+
...acpModelSelection(reference.backend, options, openOptions.defaultThinking),
|
|
57
|
+
...(resolvedModel ? { resolvedModel } : {}),
|
|
58
|
+
});
|
|
41
59
|
let updating = Promise.resolve();
|
|
42
|
-
|
|
60
|
+
let app = acp.client({ name: "personal-bot" })
|
|
43
61
|
.onRequest(acp.methods.client.session.requestPermission, async ctx => {
|
|
44
62
|
if (cancel.aborted || ctx.params.sessionId !== sessionId) return { outcome: { outcome: "cancelled" as const } };
|
|
45
63
|
return callbacks.permission(ctx.params, cancel);
|
|
46
64
|
})
|
|
65
|
+
.onRequest(acp.methods.client.elicitation.create, async ctx => {
|
|
66
|
+
if (cancel.aborted || !callbacks.elicitation) return { action: "cancel" as const };
|
|
67
|
+
if ("sessionId" in ctx.params && ctx.params.sessionId !== sessionId) return { action: "cancel" as const };
|
|
68
|
+
return callbacks.elicitation(ctx.params, cancel);
|
|
69
|
+
})
|
|
47
70
|
.onNotification(acp.methods.client.session.update, ctx => {
|
|
48
71
|
// Load may replay before its response. Output from replay never becomes a new report.
|
|
49
72
|
if (ctx.params.sessionId !== sessionId || cancel.aborted) return;
|
|
@@ -58,16 +81,19 @@ export async function openAcp(reference: AcpSessionReference, cwd: string, env:
|
|
|
58
81
|
});
|
|
59
82
|
void updating.catch(error => lifetime.abort(error));
|
|
60
83
|
return updating;
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (!
|
|
66
|
-
const
|
|
84
|
+
});
|
|
85
|
+
if (harness.customNotificationMethod && harness.parseCustomNotification) {
|
|
86
|
+
const parse = harness.parseCustomNotification;
|
|
87
|
+
app = app.onNotification(harness.customNotificationMethod, (value: unknown) => value, ctx => {
|
|
88
|
+
if (!sessionId || cancel.aborted) return;
|
|
89
|
+
const parsed = parse(ctx.params, sessionId);
|
|
90
|
+
if (!parsed?.resolvedModel) return;
|
|
91
|
+
const model = parsed.resolvedModel;
|
|
67
92
|
updating = updating.then(() => { resolvedModel = model; callbacks.selection?.(selection()); });
|
|
68
93
|
void updating.catch(error => lifetime.abort(error));
|
|
69
94
|
return updating;
|
|
70
95
|
});
|
|
96
|
+
}
|
|
71
97
|
const connection = await app.connect(acp.ndJsonStream(Writable.toWeb(child.stdin), Readable.toWeb(child.stdout) as ReadableStream<Uint8Array>, { maxMessageBytes: 8 * 1024 * 1024 }));
|
|
72
98
|
const abort = () => connection.close(cancel.reason);
|
|
73
99
|
cancel.addEventListener("abort", abort, { once: true });
|
|
@@ -94,22 +120,33 @@ export async function openAcp(reference: AcpSessionReference, cwd: string, env:
|
|
|
94
120
|
let initialized: acp.InitializeResponse | undefined;
|
|
95
121
|
try {
|
|
96
122
|
initialized = await connection.agent.request(acp.methods.agent.initialize, {
|
|
97
|
-
protocolVersion: 1,
|
|
123
|
+
protocolVersion: 1,
|
|
124
|
+
clientCapabilities: callbacks.elicitation ? { elicitation: { form: {}, url: {} } } : {},
|
|
125
|
+
clientInfo: { name: "personal-bot", version: packageVersion },
|
|
98
126
|
}, { cancellationSignal: AbortSignal.any([cancel, AbortSignal.timeout(30_000)]), stopWaitingOnCancel: true });
|
|
99
127
|
requireThat(initialized.protocolVersion === 1, "目标宿主没有协商 ACP v1。");
|
|
100
128
|
const advertised = initialized.agentCapabilities;
|
|
101
|
-
const capabilities = {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
129
|
+
const capabilities = {
|
|
130
|
+
resume: Boolean(advertised?.sessionCapabilities?.resume),
|
|
131
|
+
load: advertised?.loadSession === true,
|
|
132
|
+
close: Boolean(advertised?.sessionCapabilities?.close),
|
|
133
|
+
};
|
|
134
|
+
const mcpServers = openOptions.mcpServers?.length
|
|
135
|
+
? filterAcpMcpServers(openOptions.mcpServers, advertised?.mcpCapabilities)
|
|
136
|
+
: [];
|
|
137
|
+
const setup = {
|
|
138
|
+
cwd,
|
|
139
|
+
mcpServers,
|
|
140
|
+
...(openOptions.sessionMeta ? { _meta: openOptions.sessionMeta } : {}),
|
|
141
|
+
...(openOptions.systemPrompt && advertised?.sessionCapabilities?.systemPrompt ? {
|
|
142
|
+
systemPrompt: { mode: "append" as const, content: [{ type: "text" as const, text: openOptions.systemPrompt }] },
|
|
143
|
+
} : {}),
|
|
144
|
+
};
|
|
108
145
|
if (reference.sessionId === null) {
|
|
109
146
|
const created = await connection.agent.request<acp.NewSessionResponse>(acp.methods.agent.session.new, setup, { cancellationSignal: AbortSignal.any([cancel, AbortSignal.timeout(30_000)]), stopWaitingOnCancel: true });
|
|
110
147
|
sessionId = created.sessionId; options = created.configOptions ?? [];
|
|
111
148
|
} else {
|
|
112
|
-
requireThat(capabilities.resume || capabilities.load, "目标 ACP
|
|
149
|
+
requireThat(capabilities.resume || capabilities.load, "目标 ACP 后端不支持恢复已有会话,请新建 worker。");
|
|
113
150
|
const restored = capabilities.resume
|
|
114
151
|
? await connection.agent.request<acp.ResumeSessionResponse>(acp.methods.agent.session.resume, { ...setup, sessionId: reference.sessionId }, { cancellationSignal: AbortSignal.any([cancel, AbortSignal.timeout(30_000)]), stopWaitingOnCancel: true })
|
|
115
152
|
: await connection.agent.request<acp.LoadSessionResponse>(acp.methods.agent.session.load, { ...setup, sessionId: reference.sessionId }, { cancellationSignal: AbortSignal.any([cancel, AbortSignal.timeout(30_000)]), stopWaitingOnCancel: true });
|
|
@@ -121,6 +158,7 @@ export async function openAcp(reference: AcpSessionReference, cwd: string, env:
|
|
|
121
158
|
sessionId: activeId, capabilities, signal: connected, close, images: advertised?.promptCapabilities?.image === true,
|
|
122
159
|
systemPrompt: Boolean(advertised?.sessionCapabilities?.systemPrompt),
|
|
123
160
|
selection,
|
|
161
|
+
choices: () => acpChoices(options),
|
|
124
162
|
async configure(requested: AgentOptions) {
|
|
125
163
|
requireThat(!requested.provider || requested.model, "provider 需要同时指定目标 model。");
|
|
126
164
|
for (const kind of ["model", "thinking"] as const) {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { accessSync, constants, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import { delimiter, isAbsolute, resolve } from "node:path";
|
|
3
|
+
import type { AcpBackend, AcpHarnessAdapter } from "../../model/acp.js";
|
|
4
|
+
|
|
5
|
+
export function findAcpExecutable(command: string): string | undefined {
|
|
6
|
+
const candidates = isAbsolute(command)
|
|
7
|
+
? [command]
|
|
8
|
+
: (process.env.PATH ?? "").split(delimiter).filter(Boolean).map(directory => resolve(directory, command));
|
|
9
|
+
for (const candidate of candidates) {
|
|
10
|
+
try {
|
|
11
|
+
accessSync(candidate, constants.X_OK);
|
|
12
|
+
if (statSync(candidate).isFile()) return realpathSync(candidate);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
if (!["ENOENT", "ENOTDIR", "EACCES", "EPERM"].includes((error as NodeJS.ErrnoException).code ?? "")) throw error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function acpExecutable(command: string, backend: AcpBackend, harness?: AcpHarnessAdapter): string {
|
|
21
|
+
const found = findAcpExecutable(command);
|
|
22
|
+
if (found) return found;
|
|
23
|
+
const nativePi = backend === "pi" && command === "pi";
|
|
24
|
+
const targetCommand = harness?.defaultCommand?.command ?? command;
|
|
25
|
+
const targetArgs = harness?.defaultCommand?.args ?? [];
|
|
26
|
+
const install = nativePi
|
|
27
|
+
? "npm install -g @earendil-works/pi-coding-agent"
|
|
28
|
+
: harness?.installHint ?? `请确认 ${backend} 对应的 ACP 可执行文件已安装。`;
|
|
29
|
+
const configured = JSON.stringify({ command: "/absolute/path/to/" + targetCommand, args: targetArgs });
|
|
30
|
+
const pathHint = nativePi
|
|
31
|
+
? "Pi 已安装但 PATH 不可见时,启动主宿主前将 PI_ACP_PI_COMMAND 设置为 pi 的绝对路径。"
|
|
32
|
+
: "已安装但 PATH 不可见时,在 .pbot/config.json 设置 acp." + backend + ":" + configured + ",command 使用实际绝对路径。";
|
|
33
|
+
throw new Error([
|
|
34
|
+
"未找到子代理程序:" + command + "。",
|
|
35
|
+
"安装提示:" + install,
|
|
36
|
+
...(harness?.configureHint ? [harness.configureHint] : []),
|
|
37
|
+
"检查安装路径:command -v " + (nativePi ? "pi" : targetCommand) + (!nativePi && backend === "pi" ? ";另用 command -v pi 检查 Pi。" : "。"),
|
|
38
|
+
pathHint,
|
|
39
|
+
"安装后重试原 start 请求;PATH 变化时重启主宿主。配置修改后,Pi 执行 /reload,dsh 重启宿主。",
|
|
40
|
+
].join("\n"));
|
|
41
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { object } from "../../../common/json.js";
|
|
2
|
+
import { requireThat } from "../../../common/validation.js";
|
|
3
|
+
import type { AcpHarnessAdapter } from "../../../model/acp.js";
|
|
4
|
+
import { claudeOptions } from "../claude.js";
|
|
5
|
+
import { defaultPrepareLaunch, filterStandardAcpOptions, validateStandardAcpOptions } from "./generic.js";
|
|
6
|
+
|
|
7
|
+
export const claudeAcpHarness: AcpHarnessAdapter = {
|
|
8
|
+
id: "claude",
|
|
9
|
+
label: "Claude Code",
|
|
10
|
+
aliases: ["claude-code", "claudecode"],
|
|
11
|
+
defaultCommand: { command: "claude-agent-acp", args: [] },
|
|
12
|
+
installHint: "npm install -g @agentclientprotocol/claude-agent-acp",
|
|
13
|
+
configureHint: "在 Claude Code 中完成登录或 API 配置,并设置默认模型。",
|
|
14
|
+
requireSystemPrompt: true,
|
|
15
|
+
nativeWorkspaceSkills: false,
|
|
16
|
+
customNotificationMethod: "_claude/sdkMessage",
|
|
17
|
+
filterStartOptions(options) {
|
|
18
|
+
const filtered = filterStandardAcpOptions(options);
|
|
19
|
+
delete filtered.provider;
|
|
20
|
+
return filtered;
|
|
21
|
+
},
|
|
22
|
+
validateStartOptions(options) {
|
|
23
|
+
validateStandardAcpOptions("claude", options);
|
|
24
|
+
requireThat(options.noSkills === undefined && options.tools === undefined, "Claude 子代理的技能和工具通过 Claude 原生配置选择。");
|
|
25
|
+
requireThat(options.provider === undefined, "Claude 子代理使用原生提供方配置;请仅指定目标 model。");
|
|
26
|
+
},
|
|
27
|
+
async prepareLaunch(context) {
|
|
28
|
+
const base = defaultPrepareLaunch(context);
|
|
29
|
+
const claude = await claudeOptions(base.command, context.cwd, context.options.thinking, context.features?.skills !== false);
|
|
30
|
+
return {
|
|
31
|
+
...base,
|
|
32
|
+
...(claude.thinking ? { defaultThinking: claude.thinking } : {}),
|
|
33
|
+
sessionMeta: {
|
|
34
|
+
claudeCode: {
|
|
35
|
+
options: { ...claude.options, disallowedTools: ["Agent", "Task"] },
|
|
36
|
+
emitRawSDKMessages: [{ type: "system", subtype: "init" }],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
parseModelValue: value => ({ model: value }),
|
|
42
|
+
parseCustomNotification(params, sessionId) {
|
|
43
|
+
if (!object(params) || params.sessionId !== sessionId) return undefined;
|
|
44
|
+
const message = params.message;
|
|
45
|
+
if (!object(message) || message.type !== "system" || message.subtype !== "init" || typeof message.model !== "string" || !message.model) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
return { resolvedModel: message.model };
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import type { AcpHarnessAdapter } from "../../../model/acp.js";
|
|
4
|
+
import { defaultPrepareLaunch, filterStandardAcpOptions, validateStandardAcpOptions } from "./generic.js";
|
|
5
|
+
|
|
6
|
+
export const dshAcpHarness: AcpHarnessAdapter = {
|
|
7
|
+
id: "dsh",
|
|
8
|
+
label: "DeepSeek dsh",
|
|
9
|
+
defaultCommand: { command: "dsh", args: ["--profile", "acp"] },
|
|
10
|
+
installHint: "npm install -g @deepseek-ai/dsh@latest",
|
|
11
|
+
configureHint: "按 dsh 原生方式配置目标 profile 的模型与认证。",
|
|
12
|
+
exactAnswer: true,
|
|
13
|
+
eagerSessionId: true,
|
|
14
|
+
nativeWorkspaceSkills: true,
|
|
15
|
+
nativeWorkspaceMcp: true,
|
|
16
|
+
filterStartOptions: filterStandardAcpOptions,
|
|
17
|
+
validateStartOptions: options => validateStandardAcpOptions("dsh", options),
|
|
18
|
+
async prepareLaunch(context) {
|
|
19
|
+
const base = defaultPrepareLaunch(context);
|
|
20
|
+
const patch = join(context.directory, "acp-dsh-patch.json");
|
|
21
|
+
await writeFile(
|
|
22
|
+
patch,
|
|
23
|
+
JSON.stringify([{ insert: [{ id: "pbot-acp-member", name: join(context.packageRoot, "lib/extension/dsh/acp-member.js") }] }]) + "\n",
|
|
24
|
+
{ mode: 0o600 },
|
|
25
|
+
);
|
|
26
|
+
return {
|
|
27
|
+
...base,
|
|
28
|
+
command: { ...base.command, args: [...base.command.args, "--patch", patch] },
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
parseModelValue(value) {
|
|
32
|
+
try {
|
|
33
|
+
const parts: unknown = JSON.parse(value);
|
|
34
|
+
if (Array.isArray(parts) && parts.length === 2 && parts.every(part => typeof part === "string" && part.length > 0)) {
|
|
35
|
+
return { provider: parts[0], model: parts[1] };
|
|
36
|
+
}
|
|
37
|
+
} catch { /* Unencoded identifiers remain usable as exact ACP option values. */ }
|
|
38
|
+
return { model: value };
|
|
39
|
+
},
|
|
40
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { requireThat } from "../../../common/validation.js";
|
|
2
|
+
import type { AcpBackend, AcpCommand, AcpHarnessAdapter, AcpLaunchContext, AcpPreparedLaunch, AcpStartOptions } from "../../../model/acp.js";
|
|
3
|
+
|
|
4
|
+
const piOnlyOptions = ["noExtensions", "noPromptTemplates", "noContextFiles"] as const;
|
|
5
|
+
|
|
6
|
+
export function filterStandardAcpOptions(options: AcpStartOptions): AcpStartOptions {
|
|
7
|
+
const result: AcpStartOptions = { ...options };
|
|
8
|
+
for (const key of piOnlyOptions) delete result[key];
|
|
9
|
+
delete result.noSkills;
|
|
10
|
+
delete result.tools;
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function validateStandardAcpOptions(backend: AcpBackend, options: AcpStartOptions): void {
|
|
15
|
+
for (const key of piOnlyOptions) {
|
|
16
|
+
requireThat(options[key] === undefined, backend + " 子代理不支持启动选项:" + key);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function defaultPrepareLaunch(context: AcpLaunchContext): AcpPreparedLaunch {
|
|
21
|
+
return {
|
|
22
|
+
command: { ...context.reference, args: [...context.reference.args] },
|
|
23
|
+
env: { ...context.env, ...(context.reference.env ?? {}) },
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Generic ACP v1 harness adapter; works for any standard ACP v1 executable without special cases. */
|
|
28
|
+
export function createGenericAcpHarness(
|
|
29
|
+
id: AcpBackend,
|
|
30
|
+
preset: {
|
|
31
|
+
label?: string;
|
|
32
|
+
aliases?: readonly string[];
|
|
33
|
+
defaultCommand?: AcpCommand;
|
|
34
|
+
installHint?: string;
|
|
35
|
+
configureHint?: string;
|
|
36
|
+
nativeWorkspaceSkills?: boolean;
|
|
37
|
+
} = {},
|
|
38
|
+
): AcpHarnessAdapter {
|
|
39
|
+
return {
|
|
40
|
+
id,
|
|
41
|
+
...(preset.label ? { label: preset.label } : {}),
|
|
42
|
+
...(preset.aliases ? { aliases: preset.aliases } : {}),
|
|
43
|
+
...(preset.defaultCommand ? { defaultCommand: preset.defaultCommand } : {}),
|
|
44
|
+
...(preset.installHint ? { installHint: preset.installHint } : {}),
|
|
45
|
+
...(preset.configureHint ? { configureHint: preset.configureHint } : {}),
|
|
46
|
+
...(preset.nativeWorkspaceSkills !== undefined ? { nativeWorkspaceSkills: preset.nativeWorkspaceSkills } : {}),
|
|
47
|
+
filterStartOptions: filterStandardAcpOptions,
|
|
48
|
+
validateStartOptions: options => validateStandardAcpOptions(id, options),
|
|
49
|
+
prepareLaunch: defaultPrepareLaunch,
|
|
50
|
+
parseModelValue: value => ({ model: value }),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import type { AcpHarnessAdapter } from "../../../model/acp.js";
|
|
3
|
+
import { acpExecutable } from "../executable.js";
|
|
4
|
+
import { defaultPrepareLaunch } from "./generic.js";
|
|
5
|
+
|
|
6
|
+
export const piAcpHarness: AcpHarnessAdapter = {
|
|
7
|
+
id: "pi",
|
|
8
|
+
label: "Pi",
|
|
9
|
+
defaultCommand: { command: "pi-acp", args: [] },
|
|
10
|
+
installHint: "npm install -g pi-acp",
|
|
11
|
+
configureHint: "Pi 也需已安装;运行 pi 完成登录和默认模型配置。",
|
|
12
|
+
exactAnswer: true,
|
|
13
|
+
nativeWorkspaceSkills: true,
|
|
14
|
+
nativeWorkspaceMcp: true,
|
|
15
|
+
filterStartOptions: options => ({ ...options }),
|
|
16
|
+
prepareLaunch(context) {
|
|
17
|
+
const base = defaultPrepareLaunch(context);
|
|
18
|
+
return {
|
|
19
|
+
...base,
|
|
20
|
+
env: {
|
|
21
|
+
...base.env,
|
|
22
|
+
PBOT_ACP_PI_COMMAND: process.env.PI_ACP_PI_COMMAND ?? acpExecutable("pi", "pi"),
|
|
23
|
+
PI_ACP_PI_COMMAND: join(context.packageRoot, "bin/pbot-pi-acp.mjs"),
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
parseModelValue(value) {
|
|
28
|
+
const separator = value.indexOf("/");
|
|
29
|
+
if (separator > 0) return { provider: value.slice(0, separator), model: value.slice(separator + 1) };
|
|
30
|
+
return { model: value };
|
|
31
|
+
},
|
|
32
|
+
formatModelQuery(model, provider) {
|
|
33
|
+
return provider ? provider + "/" + model : undefined;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AcpHarnessAdapter } from "../../../model/acp.js";
|
|
2
|
+
import { createGenericAcpHarness } from "./generic.js";
|
|
3
|
+
|
|
4
|
+
/** Declarative standard ACP v1 presets requiring no host-specific adapter code. */
|
|
5
|
+
export const standardAcpPresets: readonly AcpHarnessAdapter[] = [
|
|
6
|
+
createGenericAcpHarness("antigravity", {
|
|
7
|
+
label: "Google Antigravity",
|
|
8
|
+
aliases: ["agy"],
|
|
9
|
+
defaultCommand: { command: "agy", args: ["acp"] },
|
|
10
|
+
installHint: "安装 Google Antigravity CLI(agy)",
|
|
11
|
+
configureHint: "运行 agy 完成登录与默认模型配置。",
|
|
12
|
+
nativeWorkspaceSkills: true,
|
|
13
|
+
}),
|
|
14
|
+
createGenericAcpHarness("codex", {
|
|
15
|
+
label: "OpenAI Codex",
|
|
16
|
+
aliases: ["openai-codex", "codex-cli"],
|
|
17
|
+
defaultCommand: { command: "codex-acp", args: [] },
|
|
18
|
+
installHint: "npm install -g @agentclientprotocol/codex-acp",
|
|
19
|
+
configureHint: "在 Codex 中完成登录或 API 配置。",
|
|
20
|
+
nativeWorkspaceSkills: true,
|
|
21
|
+
}),
|
|
22
|
+
];
|
|
@@ -1,50 +1,72 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
accessSync(candidate, constants.X_OK);
|
|
21
|
-
if (statSync(candidate).isFile()) return realpathSync(candidate);
|
|
22
|
-
} catch (error) { if (!["ENOENT", "ENOTDIR", "EACCES"].includes((error as NodeJS.ErrnoException).code ?? "")) throw error; }
|
|
23
|
-
}
|
|
24
|
-
const target = targets[backend], nativePi = backend === "pi" && command === "pi";
|
|
25
|
-
const install = nativePi ? "npm install -g @earendil-works/pi-coding-agent" : target.install;
|
|
26
|
-
const configured = JSON.stringify({ command: "/absolute/path/to/" + target.command, args: target.args });
|
|
27
|
-
const path = nativePi ? "Pi 已安装但 PATH 不可见时,启动主宿主前将 PI_ACP_PI_COMMAND 设置为 pi 的绝对路径。"
|
|
28
|
-
: "已安装但 PATH 不可见时,在 .pbot/config.json 设置 acp." + backend + ":" + configured + ",command 使用实际绝对路径。";
|
|
29
|
-
throw new Error([
|
|
30
|
-
"未找到子代理程序:" + command + "。",
|
|
31
|
-
"在运行 Pi/dsh 的机器上安装:" + install,
|
|
32
|
-
target.configure,
|
|
33
|
-
"检查安装路径:command -v " + (nativePi ? "pi" : target.command) + (!nativePi && backend === "pi" ? ";另用 command -v pi 检查 Pi。" : "。"),
|
|
34
|
-
path,
|
|
35
|
-
"安装后重试原 start 请求;PATH 变化时重启主宿主。配置修改后,Pi 执行 /reload,dsh 重启宿主。",
|
|
36
|
-
].join("\n"));
|
|
1
|
+
import { isAcpBackend, requireThat } from "../../common/validation.js";
|
|
2
|
+
import type { AcpBackend, AcpCommand, AcpCommands, AcpPermissionPolicy, AcpSessionReference, AcpStartOptions } from "../../model/acp.js";
|
|
3
|
+
import { acpExecutable, findAcpExecutable } from "./executable.js";
|
|
4
|
+
import { acpHarnesses, resolveAcpHarness } from "./registry.js";
|
|
5
|
+
|
|
6
|
+
export { acpExecutable, findAcpExecutable } from "./executable.js";
|
|
7
|
+
|
|
8
|
+
/** Workspace entries override a registered default command; an entry without `command` only adjusts env or permission. */
|
|
9
|
+
export function configuredAcpCommand(backend: AcpBackend, commands: AcpCommands = {}): AcpCommand | undefined {
|
|
10
|
+
const entry = Object.hasOwn(commands, backend) ? commands[backend] : undefined;
|
|
11
|
+
const base = entry?.command ? { command: entry.command, args: entry.args ?? [] } : acpHarnesses.get(backend)?.defaultCommand;
|
|
12
|
+
if (!base) return undefined;
|
|
13
|
+
const env = { ...base.env, ...entry?.env };
|
|
14
|
+
return { command: base.command, args: [...base.args], ...(Object.keys(env).length ? { env } : {}) };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function acpPermissionPolicy(backend: AcpBackend, commands: AcpCommands = {}): AcpPermissionPolicy {
|
|
18
|
+
return (Object.hasOwn(commands, backend) ? commands[backend]?.permission : undefined) ?? "ask";
|
|
37
19
|
}
|
|
38
|
-
|
|
39
|
-
|
|
20
|
+
|
|
21
|
+
/** Names callers may use: registered harnesses plus workspace-configured custom harnesses. */
|
|
22
|
+
export function knownAcpBackends(commands: AcpCommands = {}): AcpBackend[] {
|
|
23
|
+
return [...new Set([...acpHarnesses.list(), ...Object.keys(commands)])].filter(backend => configuredAcpCommand(backend, commands));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function canonicalAcpBackend(name: string, commands: AcpCommands = {}): AcpBackend {
|
|
27
|
+
return acpHarnesses.canonical(name, Object.keys(commands));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function inspectAcpBackends(commands: AcpCommands = {}) {
|
|
31
|
+
return knownAcpBackends(commands).map(backend => {
|
|
32
|
+
const harness = acpHarnesses.get(backend);
|
|
33
|
+
const selected = configuredAcpCommand(backend, commands)!;
|
|
34
|
+
const resolved = findAcpExecutable(selected.command);
|
|
35
|
+
return {
|
|
36
|
+
backend,
|
|
37
|
+
...(harness?.label ? { label: harness.label } : {}),
|
|
38
|
+
...(harness?.aliases?.length ? { aliases: [...harness.aliases] } : {}),
|
|
39
|
+
available: Boolean(resolved),
|
|
40
|
+
builtin: Boolean(harness?.defaultCommand),
|
|
41
|
+
configured: Object.hasOwn(commands, backend),
|
|
42
|
+
permission: acpPermissionPolicy(backend, commands),
|
|
43
|
+
command: selected.command,
|
|
44
|
+
args: [...selected.args],
|
|
45
|
+
...(resolved ? { resolvedCommand: resolved } : { installHint: harness?.installHint ?? "在 .pbot/config.json 的 acp 字段配置可执行命令。" }),
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function filterAcpStartOptions(backend: AcpBackend, options: AcpStartOptions): AcpStartOptions {
|
|
51
|
+
const harness = resolveAcpHarness(backend);
|
|
52
|
+
return harness.filterStartOptions ? harness.filterStartOptions(options) : { ...options };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function acpLaunch(backend: AcpBackend, commands: AcpCommands, options: AcpStartOptions): AcpSessionReference {
|
|
56
|
+
requireThat(isAcpBackend(backend), "未知子代理程序:" + String(backend));
|
|
57
|
+
const harness = resolveAcpHarness(backend);
|
|
58
|
+
const selected = configuredAcpCommand(backend, commands);
|
|
59
|
+
requireThat(selected, `未知子代理程序:${backend}。可用目标:${knownAcpBackends(commands).join(", ")};自定义目标请在 .pbot/config.json 的 acp 字段中配置。`);
|
|
40
60
|
requireThat(!options.provider || options.model, "provider 需要同时指定目标 model。");
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
61
|
+
harness.validateStartOptions?.(options);
|
|
62
|
+
const permission = acpPermissionPolicy(backend, commands);
|
|
63
|
+
return {
|
|
64
|
+
host: "acp",
|
|
65
|
+
backend,
|
|
66
|
+
command: acpExecutable(selected.command, backend, harness),
|
|
67
|
+
args: [...selected.args],
|
|
68
|
+
...(selected.env ? { env: { ...selected.env } } : {}),
|
|
69
|
+
...(permission !== "ask" ? { permission } : {}),
|
|
70
|
+
sessionId: null,
|
|
71
|
+
};
|
|
50
72
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isAbsolute, resolve } from "node:path";
|
|
2
|
+
import type * as acp from "@agentclientprotocol/sdk";
|
|
3
|
+
import type { ResolvedWorkspaceMcpServer } from "../../model/workspace-mcp.js";
|
|
4
|
+
import { findAcpExecutable } from "./executable.js";
|
|
5
|
+
|
|
6
|
+
function resolveStdioCommand(command: string, cwd: string): string {
|
|
7
|
+
if (isAbsolute(command)) return command;
|
|
8
|
+
if (command.includes("/") || command.includes("\\")) return resolve(cwd, command);
|
|
9
|
+
return findAcpExecutable(command) ?? command;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Convert resolved workspace MCP entries into ACP v1 `McpServer` descriptors. */
|
|
13
|
+
export function toAcpMcpServers(servers: readonly ResolvedWorkspaceMcpServer[]): acp.McpServer[] {
|
|
14
|
+
return servers.map(server => {
|
|
15
|
+
if (server.transport === "http") {
|
|
16
|
+
return {
|
|
17
|
+
type: "http" as const,
|
|
18
|
+
name: server.name,
|
|
19
|
+
url: server.url,
|
|
20
|
+
headers: Object.entries(server.headers).map(([name, value]) => ({ name, value })),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
name: server.name,
|
|
25
|
+
command: resolveStdioCommand(server.command, server.cwd),
|
|
26
|
+
args: [...server.args],
|
|
27
|
+
env: Object.entries(server.env).map(([name, value]) => ({ name, value })),
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Filter ACP MCP servers to the transports advertised by the peer's `mcpCapabilities`. */
|
|
33
|
+
export function filterAcpMcpServers(
|
|
34
|
+
servers: readonly acp.McpServer[],
|
|
35
|
+
capabilities?: acp.McpCapabilities,
|
|
36
|
+
): acp.McpServer[] {
|
|
37
|
+
return servers.filter(server => {
|
|
38
|
+
if (!("type" in server)) return true; // stdio is baseline in ACP v1.
|
|
39
|
+
if (server.type === "http") return capabilities?.http === true;
|
|
40
|
+
if (server.type === "sse") return capabilities?.sse === true;
|
|
41
|
+
return false;
|
|
42
|
+
});
|
|
43
|
+
}
|