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