personal-bot 0.2.20 → 0.3.1
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 +95 -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 +43 -9
- 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 +46 -8
- package/src/services/workspace/workspace-mcp.ts +242 -0
- package/src/services/workspace/workspace-skills.ts +78 -0
- package/src/storage/acp-files.ts +32 -3
- package/src/storage/acp-history.ts +18 -7
- package/src/storage/agent-files.ts +27 -41
- package/src/tools/history/contract.ts +17 -11
- package/src/tools/register.ts +4 -8
- package/src/ui/dsh/index.ts +8 -3
- package/src/ui/dsh/management.ts +40 -282
- package/src/ui/dsh/remote.ts +2 -2
- package/docs/adr/0001-claude-skill-discovery.md +0 -3
- package/docs/adr/0002-claude-native-collaboration.md +0 -3
- package/docs/agent-collaboration.md +0 -190
- package/docs/architecture-guidelines.md +0 -37
- package/docs/capability-design.md +0 -55
- package/docs/claude-code-design.md +0 -44
- package/docs/claude-code.md +0 -57
- package/docs/dsh.md +0 -337
- package/docs/file-storage.md +0 -97
- package/docs/history.md +0 -54
- package/docs/installation-design.md +0 -86
- package/docs/interaction-design.md +0 -21
- package/docs/model-context.md +0 -76
- package/docs/model-instruction-guidelines.md +0 -51
- package/docs/release.md +0 -108
- package/docs/technical-design.md +0 -163
- package/docs/workspace-configuration.md +0 -79
- package/lib/extension/claude-hooks.d.ts +0 -9
- package/lib/extension/claude-hooks.js +0 -78
- package/lib/extension/dsh/agent-events.d.ts +0 -24
- package/lib/extension/dsh/agent-events.js +0 -242
- package/lib/extension/dsh/agent-runtime.d.ts +0 -49
- package/lib/extension/dsh/agent-runtime.js +0 -351
- package/lib/integrations/dsh/dsh-agents.d.ts +0 -30
- package/lib/integrations/dsh/dsh-agents.js +0 -104
- package/lib/integrations/dsh/input.d.ts +0 -21
- package/lib/integrations/dsh/input.js +0 -62
- package/lib/integrations/dsh/notifications.d.ts +0 -8
- package/lib/integrations/dsh/notifications.js +0 -55
- package/lib/integrations/dsh/session.d.ts +0 -14
- package/lib/integrations/dsh/session.js +0 -60
- package/lib/integrations/team-context.d.ts +0 -18
- package/lib/integrations/team-context.js +0 -61
- package/lib/model/team.d.ts +0 -85
- package/lib/services/agents/agent-notices.d.ts +0 -13
- package/lib/services/agents/agent-notices.js +0 -25
- package/lib/services/agents/start-options.d.ts +0 -4
- package/lib/services/agents/start-options.js +0 -20
- package/lib/services/agents/team-service.d.ts +0 -168
- package/lib/services/agents/team-service.js +0 -345
- package/lib/storage/team-files.d.ts +0 -16
- package/lib/storage/team-files.js +0 -111
- package/lib/tools/agents/actions.d.ts +0 -62
- package/lib/tools/agents/actions.js +0 -62
- package/lib/tools/agents/contract.d.ts +0 -181
- package/lib/tools/agents/contract.js +0 -84
- package/lib/tools/agents/dsh-tool.d.ts +0 -5
- package/lib/tools/agents/dsh-tool.js +0 -34
- package/lib/tools/result.d.ts +0 -18
- package/lib/tools/result.js +0 -10
- package/lib/tools/teams/actions.d.ts +0 -23
- package/lib/tools/teams/actions.js +0 -40
- package/lib/tools/teams/contract.d.ts +0 -201
- package/lib/tools/teams/contract.js +0 -91
- package/lib/tools/teams/dsh-tool.d.ts +0 -8
- package/lib/tools/teams/dsh-tool.js +0 -39
- package/lib/ui/dsh/attachments.d.ts +0 -5
- package/lib/ui/dsh/attachments.js +0 -39
- package/resources/prompts/claude-coordinator.md +0 -1
- package/resources/prompts/native-coordinator.md +0 -1
- package/resources/prompts/team-member.md +0 -7
- package/src/extension/agent-events.ts +0 -210
- package/src/extension/agents-command.ts +0 -89
- package/src/extension/claude-hooks.ts +0 -74
- package/src/extension/dsh/agent-events.ts +0 -148
- package/src/extension/dsh/agent-runtime.ts +0 -252
- package/src/extension/subagent-entry.ts +0 -270
- package/src/extension/teams-command.ts +0 -67
- package/src/integrations/dsh/dsh-agents.ts +0 -97
- package/src/integrations/dsh/input.ts +0 -66
- package/src/integrations/dsh/notifications.ts +0 -46
- package/src/integrations/pi/agent-context.ts +0 -18
- package/src/integrations/pi/agent-input.ts +0 -19
- package/src/integrations/pi/pi-agents.ts +0 -84
- package/src/integrations/pi/team-context.ts +0 -26
- package/src/integrations/team-context.ts +0 -64
- package/src/model/team.ts +0 -29
- package/src/services/agents/agent-notices.ts +0 -28
- package/src/services/agents/start-options.ts +0 -19
- package/src/services/agents/team-service.ts +0 -275
- package/src/storage/team-files.ts +0 -93
- package/src/tools/agents/actions.ts +0 -57
- package/src/tools/agents/contract.ts +0 -101
- package/src/tools/agents/dsh-tool.ts +0 -37
- package/src/tools/agents/tool.ts +0 -20
- package/src/tools/teams/actions.ts +0 -34
- package/src/tools/teams/contract.ts +0 -109
- package/src/tools/teams/dsh-tool.ts +0 -45
- package/src/tools/teams/tool.ts +0 -29
- package/src/ui/agent-display.ts +0 -14
- package/src/ui/dsh/attachments.ts +0 -42
- package/src/ui/pi/menu.ts +0 -37
- package/src/ui/pi/reader.ts +0 -46
- /package/lib/{model/team.js → antigravity-plugin/lib/model/plugin-host.js} +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { SessionConfigOption } from "@agentclientprotocol/sdk";
|
|
2
|
-
import type { AcpBackend, AcpModelSelection } from "../../model/acp.js";
|
|
2
|
+
import type { AcpBackend, AcpChoice, AcpModelSelection } from "../../model/acp.js";
|
|
3
3
|
import { requireThat } from "../../common/validation.js";
|
|
4
|
+
import { resolveAcpHarness } from "./registry.js";
|
|
4
5
|
|
|
5
6
|
type SelectOption = Extract<SessionConfigOption, { type: "select" }>;
|
|
6
7
|
|
|
@@ -13,49 +14,79 @@ function values(option: SelectOption) {
|
|
|
13
14
|
return [...new Map(option.options.flatMap(item => "options" in item ? item.options : [item]).map(item => [item.value, item])).values()];
|
|
14
15
|
}
|
|
15
16
|
function modelIdentity(backend: AcpBackend, value: string): { provider?: string; model: string } {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const parts: unknown = JSON.parse(value);
|
|
19
|
-
if (Array.isArray(parts) && parts.length === 2 && parts.every(part => typeof part === "string" && part.length > 0)) {
|
|
20
|
-
return { provider: parts[0], model: parts[1] };
|
|
21
|
-
}
|
|
22
|
-
} catch { /* Unencoded identifiers remain usable as exact ACP option values. */ }
|
|
23
|
-
}
|
|
24
|
-
if (backend === "pi") {
|
|
25
|
-
const separator = value.indexOf("/");
|
|
26
|
-
if (separator > 0) return { provider: value.slice(0, separator), model: value.slice(separator + 1) };
|
|
27
|
-
}
|
|
28
|
-
return { model: value };
|
|
17
|
+
const harness = resolveAcpHarness(backend);
|
|
18
|
+
return harness.parseModelValue ? harness.parseModelValue(value) : { model: value };
|
|
29
19
|
}
|
|
20
|
+
/** Case, spacing and punctuation-insensitive form so "Opus 4.5" meets "claude-opus-4-5". */
|
|
21
|
+
const compact = (value: string) => value.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "");
|
|
22
|
+
const listing = (items: { value: string; name?: string }[]) =>
|
|
23
|
+
items.map(item => item.name && item.name !== item.value ? `${item.value}(${item.name})` : item.value).join(", ");
|
|
30
24
|
|
|
31
|
-
/** Resolve a native model ID against the peer's advertised values. */
|
|
25
|
+
/** Resolve a native model ID against the peer's advertised values using the harness adapter. */
|
|
32
26
|
export function acpModelValue(backend: AcpBackend, options: SessionConfigOption[], model: string, provider?: string) {
|
|
33
27
|
const option = optionFor(options, "model");
|
|
34
28
|
requireThat(option, "ACP 后端未提供可选择的模型。");
|
|
35
29
|
const choices = values(option);
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
const harness = resolveAcpHarness(backend);
|
|
31
|
+
const formatted = harness.formatModelQuery?.(model, provider);
|
|
32
|
+
if (formatted) {
|
|
33
|
+
const qualified = choices.find(item => item.value === formatted);
|
|
38
34
|
if (qualified) return { configId: option.id, value: qualified.value };
|
|
39
35
|
}
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
const entries = choices.map(item => ({ ...modelIdentity(backend, item.value), value: item.value, name: item.name }));
|
|
37
|
+
const matchEntries = (pool: typeof entries, target: string) => {
|
|
38
|
+
let matched = pool.filter(item => item.value === target || item.model === target);
|
|
39
|
+
const exact = matched.filter(item => item.value === target);
|
|
40
|
+
if (exact.length) matched = exact;
|
|
41
|
+
if (!matched.length) {
|
|
42
|
+
// Users name models loosely; accept a unique case-insensitive or partial match on the value, model ID or display name.
|
|
43
|
+
const query = compact(target);
|
|
44
|
+
if (query) {
|
|
45
|
+
const keys = (item: typeof pool[number]) => [item.value, item.model, item.name].map(compact);
|
|
46
|
+
matched = pool.filter(item => keys(item).includes(query));
|
|
47
|
+
if (!matched.length && query.length >= 2) matched = pool.filter(item => keys(item).some(key => key.includes(query)));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return matched;
|
|
51
|
+
};
|
|
52
|
+
const filterByProvider = (targetProvider: string) => {
|
|
53
|
+
const exactProvider = entries.filter(item => item.provider === targetProvider);
|
|
54
|
+
if (exactProvider.length) return exactProvider;
|
|
55
|
+
const providerQuery = compact(targetProvider);
|
|
56
|
+
return providerQuery ? entries.filter(item => item.provider && compact(item.provider) === providerQuery) : [];
|
|
57
|
+
};
|
|
58
|
+
const available = provider ? filterByProvider(provider) : entries;
|
|
59
|
+
let matches = matchEntries(available, model);
|
|
60
|
+
if (!matches.length && !provider && model.includes("/")) {
|
|
61
|
+
// Support "provider/model" syntax for multi-provider harnesses without requiring a separate provider parameter.
|
|
62
|
+
for (let index = model.indexOf("/"); index > 0; index = model.indexOf("/", index + 1)) {
|
|
63
|
+
const candidateProvider = model.slice(0, index);
|
|
64
|
+
const candidateModel = model.slice(index + 1);
|
|
65
|
+
if (!candidateModel) continue;
|
|
66
|
+
const scoped = filterByProvider(candidateProvider);
|
|
67
|
+
if (!scoped.length) continue;
|
|
68
|
+
const scopedMatches = matchEntries(scoped, candidateModel);
|
|
69
|
+
if (scopedMatches.length) { matches = scopedMatches; break; }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
44
72
|
if (matches.length > 1 && !provider) {
|
|
45
73
|
const current = modelIdentity(backend, option.currentValue);
|
|
46
74
|
const sameProvider = matches.filter(item => item.provider === current.provider);
|
|
47
75
|
if (sameProvider.length === 1) matches = sameProvider;
|
|
48
76
|
}
|
|
49
|
-
|
|
50
|
-
requireThat(matches.length
|
|
77
|
+
const all = choices.map(item => ({ value: item.value, name: item.name }));
|
|
78
|
+
requireThat(matches.length, "ACP 模型不可用:" + [provider, model].filter(Boolean).join("/") + ";可用值:" + listing(all));
|
|
79
|
+
requireThat(matches.length === 1, "多个模型与该名称匹配,请指定完整模型值(或 provider/model):" + listing(matches));
|
|
51
80
|
return { configId: option.id, value: matches[0]!.value };
|
|
52
81
|
}
|
|
53
82
|
export function acpThinkingValue(options: SessionConfigOption[], thinking: string) {
|
|
54
83
|
const option = optionFor(options, "thought_level");
|
|
55
84
|
requireThat(option, "目标模型未提供可选择的思考等级。");
|
|
56
85
|
const available = values(option);
|
|
57
|
-
const
|
|
58
|
-
|
|
86
|
+
const query = compact(thinking);
|
|
87
|
+
const chosen = available.find(item => item.value === thinking) ??
|
|
88
|
+
(query ? (([match, ...rest]) => match && !rest.length ? match : undefined)(available.filter(item => compact(item.value) === query || compact(item.name) === query)) : undefined);
|
|
89
|
+
requireThat(chosen, "ACP 思考等级不可用:" + thinking + ";可用值:" + listing(available));
|
|
59
90
|
return { configId: option.id, value: chosen.value };
|
|
60
91
|
}
|
|
61
92
|
export function acpModelSelection(backend: AcpBackend, options: SessionConfigOption[], effectiveThinking?: string): AcpModelSelection {
|
|
@@ -64,3 +95,15 @@ export function acpModelSelection(backend: AcpBackend, options: SessionConfigOpt
|
|
|
64
95
|
: thinking && effectiveThinking && values(thinking).some(item => item.value === effectiveThinking) ? effectiveThinking : thinking?.currentValue;
|
|
65
96
|
return { ...(model ? modelIdentity(backend, model.currentValue) : {}), ...(selectedThinking ? { thinking: selectedThinking } : {}) };
|
|
66
97
|
}
|
|
98
|
+
/** Advertised model and thinking choices, for callers that must pick valid values. */
|
|
99
|
+
export function acpChoices(options: SessionConfigOption[]) {
|
|
100
|
+
const choice = (item: { value: string; name: string; description?: string | null }): AcpChoice =>
|
|
101
|
+
({ value: item.value, name: item.name, ...(item.description ? { description: item.description } : {}) });
|
|
102
|
+
const model = optionFor(options, "model"), thinking = optionFor(options, "thought_level");
|
|
103
|
+
return {
|
|
104
|
+
models: model ? values(model).map(choice) : [],
|
|
105
|
+
thinking: thinking ? values(thinking).map(choice) : [],
|
|
106
|
+
...(model ? { currentModel: model.currentValue } : {}),
|
|
107
|
+
...(thinking ? { currentThinking: thinking.currentValue } : {}),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isAcpBackend, requireThat } from "../../common/validation.js";
|
|
2
|
+
import type { AcpBackend, AcpHarnessAdapter } from "../../model/acp.js";
|
|
3
|
+
import { claudeAcpHarness } from "./harnesses/claude.js";
|
|
4
|
+
import { dshAcpHarness } from "./harnesses/dsh.js";
|
|
5
|
+
import { createGenericAcpHarness } from "./harnesses/generic.js";
|
|
6
|
+
import { piAcpHarness } from "./harnesses/pi.js";
|
|
7
|
+
import { standardAcpPresets } from "./harnesses/presets.js";
|
|
8
|
+
|
|
9
|
+
/** Extensible registry of ACP harness adapters; arbitrary custom harnesses resolve to generic ACP v1. */
|
|
10
|
+
export class AcpHarnessRegistry {
|
|
11
|
+
readonly #adapters = new Map<AcpBackend, AcpHarnessAdapter>();
|
|
12
|
+
|
|
13
|
+
constructor(initial: readonly AcpHarnessAdapter[] = []) {
|
|
14
|
+
for (const adapter of initial) this.register(adapter);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
register(adapter: AcpHarnessAdapter): this {
|
|
18
|
+
requireThat(isAcpBackend(adapter.id), "ACP harness 标识无效:" + String(adapter.id));
|
|
19
|
+
this.#adapters.set(adapter.id, adapter);
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
unregister(id: AcpBackend): boolean {
|
|
24
|
+
return this.#adapters.delete(id);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get(id: AcpBackend): AcpHarnessAdapter | undefined {
|
|
28
|
+
return this.#adapters.get(id);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
resolve(id: AcpBackend): AcpHarnessAdapter {
|
|
32
|
+
requireThat(isAcpBackend(id), "无效的 ACP harness 标识:" + String(id));
|
|
33
|
+
return this.#adapters.get(id) ?? createGenericAcpHarness(id);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
list(): AcpBackend[] {
|
|
37
|
+
return [...this.#adapters.keys()];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Map a caller-supplied name ("Claude Code", "agy") to a backend ID; configured names win over aliases. */
|
|
41
|
+
canonical(name: string, configured: readonly string[] = []): AcpBackend {
|
|
42
|
+
const normalized = name.trim().toLowerCase().replace(/[\s_]+/g, "-");
|
|
43
|
+
if (configured.includes(normalized) || this.#adapters.has(normalized)) return normalized;
|
|
44
|
+
const compact = normalized.replace(/-/g, "");
|
|
45
|
+
return [...this.#adapters.values()].find(adapter =>
|
|
46
|
+
adapter.id.replace(/-/g, "") === compact || adapter.aliases?.some(alias => alias === normalized || alias.replace(/-/g, "") === compact))?.id ?? normalized;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const acpHarnesses = new AcpHarnessRegistry([
|
|
51
|
+
piAcpHarness,
|
|
52
|
+
dshAcpHarness,
|
|
53
|
+
claudeAcpHarness,
|
|
54
|
+
...standardAcpPresets,
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
export const registerAcpHarness = (adapter: AcpHarnessAdapter) => acpHarnesses.register(adapter);
|
|
58
|
+
export const getAcpHarness = (id: AcpBackend) => acpHarnesses.get(id);
|
|
59
|
+
export const resolveAcpHarness = (id: AcpBackend) => acpHarnesses.resolve(id);
|
|
60
|
+
export const listAcpHarnesses = () => acpHarnesses.list();
|
|
@@ -2,15 +2,79 @@ import { readFile } from "node:fs/promises";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { resourceRoot } from "../common/paths.js";
|
|
4
4
|
import { requireThat } from "../common/validation.js";
|
|
5
|
+
import type { HostId, WorkspaceContext, WorkspaceRole } from "../model/plugin-host.js";
|
|
6
|
+
import type { WorkspaceSkillMeta } from "../model/workspace-mcp.js";
|
|
5
7
|
|
|
6
|
-
export async function
|
|
8
|
+
export async function readOptionalFile(path: string): Promise<string> {
|
|
9
|
+
try { return await readFile(path, "utf8"); }
|
|
10
|
+
catch (error) {
|
|
11
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return "";
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function readLocalRole(agent: WorkspaceRole, root: string): Promise<string> {
|
|
17
|
+
const local = await readOptionalFile(join(root, "agents", agent + ".md"));
|
|
18
|
+
return local.trim() ? "工作区职责补充:\n" + local : "";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function agentText(
|
|
22
|
+
agent: WorkspaceRole,
|
|
23
|
+
root: string,
|
|
24
|
+
coordinatorPrompt = "plugin-coordinator.md",
|
|
25
|
+
): Promise<string> {
|
|
7
26
|
requireThat(agent === "coordinator" || agent === "general-purpose", "未知职责。");
|
|
8
27
|
let text = await readFile(join(resourceRoot, "agents", agent + ".md"), "utf8");
|
|
9
|
-
if (agent === "coordinator")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
28
|
+
if (agent === "coordinator") {
|
|
29
|
+
text += "\n\n" + await readFile(join(resourceRoot, "prompts", coordinatorPrompt), "utf8");
|
|
30
|
+
}
|
|
31
|
+
const local = await readLocalRole(agent, root);
|
|
32
|
+
if (local) text += "\n\n" + local;
|
|
14
33
|
requireThat(text.trim(), "专家职责为空。");
|
|
15
34
|
return text;
|
|
16
35
|
}
|
|
36
|
+
|
|
37
|
+
export function formatWorkspaceSkills(skills: readonly WorkspaceSkillMeta[]): string {
|
|
38
|
+
if (!skills.length) return "";
|
|
39
|
+
const lines = skills.map(skill => `- **${skill.name}**(\`${skill.path}\`):${skill.description}`);
|
|
40
|
+
return "## 工作区技能\n\n以下为工作区自有专业方法(位于 `.agents/skills/`),匹配任务时按需读取对应 `SKILL.md` 正文:\n" + lines.join("\n");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function loadWorkspaceContext(options: {
|
|
44
|
+
host: HostId;
|
|
45
|
+
root: string;
|
|
46
|
+
role: WorkspaceRole;
|
|
47
|
+
coordinatorPrompt?: string;
|
|
48
|
+
includePrompts?: boolean;
|
|
49
|
+
includeRootAgents?: boolean;
|
|
50
|
+
localRoleOnly?: boolean;
|
|
51
|
+
workspaceSkills?: readonly WorkspaceSkillMeta[];
|
|
52
|
+
}): Promise<WorkspaceContext> {
|
|
53
|
+
const {
|
|
54
|
+
host,
|
|
55
|
+
root,
|
|
56
|
+
role,
|
|
57
|
+
coordinatorPrompt,
|
|
58
|
+
includePrompts = true,
|
|
59
|
+
includeRootAgents = false,
|
|
60
|
+
localRoleOnly = false,
|
|
61
|
+
workspaceSkills = [],
|
|
62
|
+
} = options;
|
|
63
|
+
const [workspace, roleText, rootAgents] = includePrompts
|
|
64
|
+
? await Promise.all([
|
|
65
|
+
readFile(join(resourceRoot, "prompts/workspace.md"), "utf8"),
|
|
66
|
+
localRoleOnly ? readLocalRole(role, root) : agentText(role, root, coordinatorPrompt),
|
|
67
|
+
includeRootAgents ? readOptionalFile(join(root, "AGENTS.md")) : Promise.resolve(""),
|
|
68
|
+
])
|
|
69
|
+
: ["", "", ""];
|
|
70
|
+
const skillsSection = formatWorkspaceSkills(workspaceSkills);
|
|
71
|
+
const environment = { host, workspaceRoot: root, resourceRoot };
|
|
72
|
+
const text = [
|
|
73
|
+
workspace,
|
|
74
|
+
roleText,
|
|
75
|
+
rootAgents,
|
|
76
|
+
skillsSection,
|
|
77
|
+
"## 环境\n\n" + JSON.stringify(environment),
|
|
78
|
+
].filter(Boolean).join("\n\n");
|
|
79
|
+
return { workspace, role: roleText, rootAgents, workspaceSkills: [...workspaceSkills], environment, text };
|
|
80
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as McpClient from "@deepseek-ai/dsh-mcp-client";
|
|
2
|
+
import type { ResolvedWorkspaceMcpServer } from "../../model/workspace-mcp.js";
|
|
3
|
+
|
|
4
|
+
/** Translate a resolved workspace MCP entry into dsh's native `@deepseek-ai/dsh-mcp-client` config. */
|
|
5
|
+
export function toDshMcpConfig(server: ResolvedWorkspaceMcpServer): McpClient.Config {
|
|
6
|
+
if (server.transport === "http") {
|
|
7
|
+
return McpClient.Config({
|
|
8
|
+
transport: "streamable-http",
|
|
9
|
+
serverName: server.name,
|
|
10
|
+
url: server.url,
|
|
11
|
+
headers: { ...server.headers },
|
|
12
|
+
toolCallTimeoutMs: server.timeout * 1000,
|
|
13
|
+
failOnStartupError: false,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return McpClient.Config({
|
|
17
|
+
transport: "stdio",
|
|
18
|
+
serverName: server.name,
|
|
19
|
+
command: server.command,
|
|
20
|
+
args: [...server.args],
|
|
21
|
+
env: {
|
|
22
|
+
...(process.env.PATH ? { PATH: process.env.PATH } : {}),
|
|
23
|
+
...(process.env.HOME ? { HOME: process.env.HOME } : {}),
|
|
24
|
+
...server.env,
|
|
25
|
+
},
|
|
26
|
+
cwd: server.cwd,
|
|
27
|
+
toolCallTimeoutMs: server.timeout * 1000,
|
|
28
|
+
failOnStartupError: false,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -8,37 +8,52 @@ import type {} from "@deepseek-ai/dsh-tools";
|
|
|
8
8
|
import { agentText } from "../agent-resources.js";
|
|
9
9
|
import { resourceRoot } from "../../common/paths.js";
|
|
10
10
|
import { requireThat } from "../../common/validation.js";
|
|
11
|
+
import { isMcpWorkerTool } from "../../model/acp.js";
|
|
11
12
|
import type { AgentOptions } from "../../model/agent.js";
|
|
12
13
|
|
|
13
|
-
export async function dshResources(
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
export async function dshResources(
|
|
15
|
+
ctx: Context,
|
|
16
|
+
_agent: Agent,
|
|
17
|
+
root: string,
|
|
18
|
+
role: "coordinator" | "general-purpose",
|
|
19
|
+
check: () => void,
|
|
20
|
+
coordinatorPrompt = "history-coordinator.md",
|
|
21
|
+
) {
|
|
22
|
+
const read = () => Promise.all([agentText(role, root, coordinatorPrompt), readFile(join(resourceRoot, "prompts/workspace.md"), "utf8")]);
|
|
16
23
|
const [text, workspace] = await read();
|
|
17
24
|
check();
|
|
18
25
|
ctx.systemPrompt.section({ name: "pbot:role", order: 1, text, interpolate: false });
|
|
19
26
|
ctx.systemPrompt.section({ name: "pbot:workspace", order: 2, text: workspace, interpolate: false });
|
|
20
|
-
ctx.systemPrompt.context({
|
|
21
|
-
|
|
27
|
+
ctx.systemPrompt.context({
|
|
28
|
+
name: "pbot:environment", order: 300, required: true, interpolate: false,
|
|
29
|
+
text: JSON.stringify({ host: "dsh", workspaceRoot: root, resourceRoot }),
|
|
30
|
+
});
|
|
22
31
|
ctx.on("system-prompt/assemble", async (_assembly, _context, next) => {
|
|
23
32
|
check();
|
|
24
33
|
const [roleText, workspaceText] = await read();
|
|
25
34
|
check();
|
|
26
35
|
const assembly = await next();
|
|
27
|
-
return {
|
|
28
|
-
|
|
36
|
+
return {
|
|
37
|
+
...assembly,
|
|
38
|
+
sections: assembly.sections.map(section => section.name === "pbot:role" ? { ...section, text: roleText }
|
|
39
|
+
: section.name === "pbot:workspace" ? { ...section, text: workspaceText } : section),
|
|
40
|
+
};
|
|
29
41
|
});
|
|
30
42
|
}
|
|
31
43
|
|
|
32
|
-
/** Map
|
|
44
|
+
/** Map an ACP dsh worker's native loadout without interfering with coordinator sessions. */
|
|
33
45
|
export function dshExpertTools(ctx: Context, agent: Agent, options: AgentOptions) {
|
|
34
46
|
const names = new Set(ctx.tools.definitions(agent).map(tool => tool.name));
|
|
35
|
-
const forbidden = new Set([
|
|
47
|
+
const forbidden = new Set([
|
|
48
|
+
"pbot_history",
|
|
49
|
+
"subagent", "subagent_fork", "list_subagent_models", "list_agents", "send_message", "interrupt_agent",
|
|
50
|
+
]);
|
|
36
51
|
if (options.noSkills) forbidden.add("skill");
|
|
52
|
+
const isForbidden = (name: string) => forbidden.has(name) || isMcpWorkerTool(name);
|
|
37
53
|
if (options.tools) {
|
|
38
|
-
for (const name of options.tools) requireThat(
|
|
39
|
-
ctx.tools.restrict({ allow: options.tools
|
|
54
|
+
for (const name of options.tools) requireThat(names.has(name) && !isForbidden(name), "专家工具不可用:" + name);
|
|
55
|
+
ctx.tools.restrict({ allow: options.tools });
|
|
40
56
|
}
|
|
41
|
-
const deny = [...
|
|
57
|
+
const deny = [...names].filter(isForbidden);
|
|
42
58
|
if (deny.length) ctx.tools.restrict({ deny });
|
|
43
|
-
return !options.tools || options.tools.includes("pbot_team_message");
|
|
44
59
|
}
|
|
@@ -1,28 +1,38 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
+
import type {} from "@deepseek-ai/dsh-fs";
|
|
3
4
|
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
4
5
|
import { scopeParentOf } from "@deepseek-ai/dsh-scope";
|
|
5
6
|
import { FileSystemSkillProvider } from "@deepseek-ai/dsh-skill-filesystem";
|
|
6
7
|
import { resourceRoot } from "../../common/paths.js";
|
|
7
8
|
|
|
9
|
+
export interface DshSkillsOptions {
|
|
10
|
+
/** Also register `<workspaceRoot>/.agents/skills` (useful when agent cwd is nested inside the workspace). */
|
|
11
|
+
workspaceRoot?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
8
14
|
/** Keep bundled methods local to this Agent without overriding its native project/user methods. */
|
|
9
|
-
export function registerDshSkills(ctx: Context, agent: Agent): void {
|
|
15
|
+
export function registerDshSkills(ctx: Context, agent: Agent, options: DshSkillsOptions = {}): void {
|
|
16
|
+
const customSkillDirs = options.workspaceRoot ? [join(options.workspaceRoot, ".agents", "skills")] : undefined;
|
|
10
17
|
let filesystem: FileSystemSkillProvider;
|
|
11
18
|
ctx.skills.registerProvider(control => {
|
|
12
19
|
filesystem = new FileSystemSkillProvider(ctx, control, {
|
|
13
|
-
providerName: "pbot",
|
|
20
|
+
providerName: "pbot",
|
|
21
|
+
includeDefaultRoots: false,
|
|
22
|
+
bundledSkillDir: join(resourceRoot, "skills"),
|
|
23
|
+
...(customSkillDirs ? { customSkillDirs } : {}),
|
|
14
24
|
});
|
|
15
25
|
return {
|
|
16
26
|
name: "pbot",
|
|
17
|
-
async list(
|
|
18
|
-
const inherited = await ctx.skills.snapshot({ ...
|
|
27
|
+
async list(listOptions) {
|
|
28
|
+
const inherited = await ctx.skills.snapshot({ ...listOptions, scope: scopeParentOf(agent) });
|
|
19
29
|
const preferred = new Set(inherited.skills.filter(skill => skill.provider !== "pbot").map(skill => skill.name));
|
|
20
|
-
const listed = await filesystem.list(
|
|
30
|
+
const listed = await filesystem.list(listOptions);
|
|
21
31
|
const candidates = Array.isArray(listed) ? listed : listed.candidates;
|
|
22
32
|
return { candidates: candidates.filter(skill => !preferred.has(skill.name)),
|
|
23
33
|
complete: inherited.complete && (Array.isArray(listed) || listed.complete) };
|
|
24
34
|
},
|
|
25
|
-
get: (candidate,
|
|
35
|
+
get: (candidate, getOptions) => filesystem.get(candidate, getOptions),
|
|
26
36
|
};
|
|
27
37
|
});
|
|
28
38
|
ctx.effect(() => () => filesystem.dispose());
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { realpath, stat } from "node:fs/promises";
|
|
2
|
+
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { object } from "../../common/json.js";
|
|
4
|
+
import { resourceRoot } from "../../common/paths.js";
|
|
5
|
+
import { requireThat } from "../../common/validation.js";
|
|
6
|
+
import type { HostEvent, PluginHostAdapter } from "../../model/plugin-host.js";
|
|
7
|
+
|
|
8
|
+
const supportedEvents = ["SessionStart", "PreToolUse"];
|
|
9
|
+
|
|
10
|
+
function workspaceFromPayload(cwd: string, payload?: unknown): string {
|
|
11
|
+
if (object(payload) && Array.isArray(payload.workspacePaths)) {
|
|
12
|
+
const first = payload.workspacePaths.find(value => typeof value === "string" && value.length > 0);
|
|
13
|
+
if (typeof first === "string") return first;
|
|
14
|
+
}
|
|
15
|
+
return cwd;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function skillFromReadPath(targetPath: string, pluginRoot = process.env.PLUGIN_ROOT || resolve(resourceRoot, "..")): string | undefined {
|
|
19
|
+
const skillsRoot = resolve(pluginRoot, "skills");
|
|
20
|
+
const rel = relative(skillsRoot, resolve(targetPath));
|
|
21
|
+
if (!rel || rel.startsWith("..") || isAbsolute(rel)) return undefined;
|
|
22
|
+
const skill = rel.split(sep)[0];
|
|
23
|
+
if (!skill || skill === "pbot") return undefined;
|
|
24
|
+
return skill;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isPreToolUse(payload: unknown): boolean {
|
|
28
|
+
return object(payload) && payload.hookEventName === "PreToolUse";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function antigravityWorkspaceRoot(cwd: string, payload?: unknown): Promise<string> {
|
|
32
|
+
const directory = workspaceFromPayload(cwd, payload);
|
|
33
|
+
requireThat(isAbsolute(directory), "Antigravity 工作区需要绝对路径。");
|
|
34
|
+
const root = await realpath(directory);
|
|
35
|
+
requireThat((await stat(root)).isDirectory(), "Antigravity 工作区需要目录。");
|
|
36
|
+
return root;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const antigravityAdapter: PluginHostAdapter = {
|
|
40
|
+
host: "antigravity",
|
|
41
|
+
nativeRootAgents: true,
|
|
42
|
+
nativeWorkspaceSkills: true,
|
|
43
|
+
coordinatorPrompt: "plugin-coordinator.md",
|
|
44
|
+
initCommandHint: "/pbot init",
|
|
45
|
+
usage: "用法:node <插件目录>/lib/plugin.js antigravity init|status",
|
|
46
|
+
resolveRoot(cwd, rawPayload) {
|
|
47
|
+
return antigravityWorkspaceRoot(cwd, rawPayload);
|
|
48
|
+
},
|
|
49
|
+
parseEvent(value): HostEvent {
|
|
50
|
+
requireThat(object(value) && typeof value.hookEventName === "string", "Antigravity hook 输入无效。");
|
|
51
|
+
const event = value.hookEventName;
|
|
52
|
+
requireThat(supportedEvents.includes(event), "Antigravity hook 事件未支持。");
|
|
53
|
+
const cwd = typeof value.cwd === "string" && value.cwd ? value.cwd : workspaceFromPayload("", value);
|
|
54
|
+
requireThat(cwd, "Antigravity hook 缺少工作目录。");
|
|
55
|
+
if (event === "SessionStart") {
|
|
56
|
+
return { kind: "inject-context", role: "coordinator", cwd, raw: value };
|
|
57
|
+
}
|
|
58
|
+
if (!object(value.toolCall) || typeof value.toolCall.name !== "string" || !object(value.toolCall.args)) {
|
|
59
|
+
return { kind: "ignore" };
|
|
60
|
+
}
|
|
61
|
+
const { name, args } = value.toolCall;
|
|
62
|
+
if (name === "read_file" && typeof args.Path === "string") {
|
|
63
|
+
const skill = skillFromReadPath(args.Path);
|
|
64
|
+
if (skill) return { kind: "check-skill", skill, cwd, raw: value };
|
|
65
|
+
}
|
|
66
|
+
return { kind: "ignore" };
|
|
67
|
+
},
|
|
68
|
+
formatPass(payload) {
|
|
69
|
+
return isPreToolUse(payload) ? { decision: "allow" } : {};
|
|
70
|
+
},
|
|
71
|
+
formatContext(_event, context) {
|
|
72
|
+
return {
|
|
73
|
+
injectSteps: [
|
|
74
|
+
{ systemMessage: { systemMessage: context.text } },
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
formatDeny(_event, reason) {
|
|
79
|
+
return { decision: "deny", reason };
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const antigravitySkillPath = (pluginRoot: string, skill: string) => join(pluginRoot, "skills", skill, "SKILL.md");
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { realpath, stat } from "node:fs/promises";
|
|
2
|
+
import { isAbsolute } from "node:path";
|
|
3
|
+
import { object } from "../../common/json.js";
|
|
4
|
+
import { requireThat } from "../../common/validation.js";
|
|
5
|
+
import type { HostEvent, PluginHostAdapter } from "../../model/plugin-host.js";
|
|
6
|
+
|
|
7
|
+
const supportedEvents = ["UserPromptSubmit", "PreToolUse", "UserPromptExpansion"];
|
|
8
|
+
|
|
9
|
+
export async function claudeWorkspaceRoot(cwd: string, projectDirectory = process.env.CLAUDE_PROJECT_DIR): Promise<string> {
|
|
10
|
+
const directory = projectDirectory || cwd;
|
|
11
|
+
requireThat(isAbsolute(directory), "Claude 工作区需要绝对路径。");
|
|
12
|
+
const root = await realpath(directory);
|
|
13
|
+
requireThat((await stat(root)).isDirectory(), "Claude 工作区需要目录。");
|
|
14
|
+
return root;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const claudeAdapter: PluginHostAdapter = {
|
|
18
|
+
host: "claude",
|
|
19
|
+
nativeRootAgents: false,
|
|
20
|
+
nativeWorkspaceSkills: false,
|
|
21
|
+
coordinatorPrompt: "plugin-coordinator.md",
|
|
22
|
+
initCommandHint: "/personal-bot:pbot init",
|
|
23
|
+
usage: "用法:node <插件目录>/lib/claude.js init|status",
|
|
24
|
+
resolveRoot(cwd) {
|
|
25
|
+
return claudeWorkspaceRoot(cwd);
|
|
26
|
+
},
|
|
27
|
+
parseEvent(value): HostEvent {
|
|
28
|
+
requireThat(object(value) && typeof value.hook_event_name === "string", "Claude hook 输入无效。");
|
|
29
|
+
const event = value.hook_event_name;
|
|
30
|
+
requireThat(supportedEvents.includes(event), "Claude hook 事件未支持。");
|
|
31
|
+
if (event === "PreToolUse" || event === "UserPromptExpansion") {
|
|
32
|
+
const skill = event === "UserPromptExpansion"
|
|
33
|
+
? value.expansion_type === "slash_command" ? value.command_name : undefined
|
|
34
|
+
: value.tool_name === "Skill" && object(value.tool_input) ? value.tool_input.skill : undefined;
|
|
35
|
+
if (typeof skill !== "string" || !skill.startsWith("personal-bot:") || skill === "personal-bot:pbot") return { kind: "ignore" };
|
|
36
|
+
requireThat(typeof value.cwd === "string", "Claude hook 缺少工作目录。");
|
|
37
|
+
return { kind: "check-skill", skill, cwd: value.cwd, raw: value };
|
|
38
|
+
}
|
|
39
|
+
// Leave Claude's native subagents untouched; only inject coordinator context into main sessions.
|
|
40
|
+
if (typeof value.agent_id === "string") return { kind: "ignore" };
|
|
41
|
+
requireThat(typeof value.cwd === "string", "Claude hook 缺少工作目录。");
|
|
42
|
+
return { kind: "inject-context", role: "coordinator", cwd: value.cwd, raw: value };
|
|
43
|
+
},
|
|
44
|
+
formatPass() {
|
|
45
|
+
return {};
|
|
46
|
+
},
|
|
47
|
+
formatContext(event, context) {
|
|
48
|
+
const raw = event.raw as { hook_event_name: string };
|
|
49
|
+
return {
|
|
50
|
+
hookSpecificOutput: {
|
|
51
|
+
hookEventName: raw.hook_event_name,
|
|
52
|
+
additionalContext: context.text,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
formatDeny(event, reason) {
|
|
57
|
+
const raw = event.raw as { hook_event_name: string };
|
|
58
|
+
return raw.hook_event_name === "UserPromptExpansion"
|
|
59
|
+
? { decision: "block", reason }
|
|
60
|
+
: { hookSpecificOutput: { hookEventName: raw.hook_event_name, permissionDecision: "deny", permissionDecisionReason: reason } };
|
|
61
|
+
},
|
|
62
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { requireThat } from "../../common/validation.js";
|
|
2
|
+
import type { PluginHostAdapter, PluginHostId } from "../../model/plugin-host.js";
|
|
3
|
+
import { antigravityAdapter } from "./antigravity.js";
|
|
4
|
+
import { claudeAdapter } from "./claude.js";
|
|
5
|
+
|
|
6
|
+
/** Extensible registry of hook-based plugin host adapters; runtime never branches on host IDs. */
|
|
7
|
+
export class PluginHostRegistry {
|
|
8
|
+
readonly #adapters = new Map<PluginHostId, PluginHostAdapter>();
|
|
9
|
+
|
|
10
|
+
constructor(initial: readonly PluginHostAdapter[] = []) {
|
|
11
|
+
for (const adapter of initial) this.register(adapter);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
register(adapter: PluginHostAdapter): this {
|
|
15
|
+
requireThat(typeof adapter.host === "string" && adapter.host.length > 0, "插件宿主标识无效。");
|
|
16
|
+
this.#adapters.set(adapter.host, adapter);
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
unregister(host: PluginHostId): boolean {
|
|
21
|
+
return this.#adapters.delete(host);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get(host: PluginHostId): PluginHostAdapter | undefined {
|
|
25
|
+
return this.#adapters.get(host);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
require(host: PluginHostId): PluginHostAdapter {
|
|
29
|
+
const adapter = this.#adapters.get(host);
|
|
30
|
+
requireThat(adapter, `未注册的插件宿主:${host}。可用宿主:${this.list().join(", ")}`);
|
|
31
|
+
return adapter;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
list(): PluginHostId[] {
|
|
35
|
+
return [...this.#adapters.keys()];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const pluginHosts = new PluginHostRegistry([claudeAdapter, antigravityAdapter]);
|
|
40
|
+
export const registerPluginHost = (adapter: PluginHostAdapter) => pluginHosts.register(adapter);
|
|
41
|
+
export const getPluginHost = (host: PluginHostId) => pluginHosts.get(host);
|
|
42
|
+
export const listPluginHosts = () => pluginHosts.list();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { McpServerConfig } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { ResolvedWorkspaceMcpServer } from "../../model/workspace-mcp.js";
|
|
3
|
+
|
|
4
|
+
/** Translate a resolved workspace MCP entry into Pi's native `registerMcpServer` config. */
|
|
5
|
+
export function toPiMcpConfig(server: ResolvedWorkspaceMcpServer): McpServerConfig {
|
|
6
|
+
if (server.transport === "http") {
|
|
7
|
+
return {
|
|
8
|
+
type: "http",
|
|
9
|
+
url: server.url,
|
|
10
|
+
...(Object.keys(server.headers).length ? { headers: { ...server.headers } } : {}),
|
|
11
|
+
exposure: "direct",
|
|
12
|
+
timeout: server.timeout,
|
|
13
|
+
...(server.description ? { description: server.description } : {}),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
type: "stdio",
|
|
18
|
+
command: server.command,
|
|
19
|
+
args: [...server.args],
|
|
20
|
+
...(Object.keys(server.env).length ? { env: { ...server.env } } : {}),
|
|
21
|
+
cwd: server.cwd,
|
|
22
|
+
exposure: "direct",
|
|
23
|
+
timeout: server.timeout,
|
|
24
|
+
...(server.description ? { description: server.description } : {}),
|
|
25
|
+
};
|
|
26
|
+
}
|
package/src/mcp.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { serveMcpStdio } from "./extension/mcp-workers.js";
|
|
4
|
+
|
|
5
|
+
export function main(): Promise<void> {
|
|
6
|
+
return serveMcpStdio();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
|
|
10
|
+
void main().catch(error => {
|
|
11
|
+
process.stderr.write("Personal Bot MCP: " + (error instanceof Error ? error.message : String(error)) + "\n");
|
|
12
|
+
process.exitCode = 1;
|
|
13
|
+
});
|
|
14
|
+
}
|