personal-bot 0.2.19 → 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 +17 -22
- package/resources/skills/provider-connections/SKILL.md +24 -40
- package/resources/templates/workspace-agents.md +8 -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
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PluginHostAdapter } from "../model/plugin-host.js";
|
|
2
|
+
export declare function pluginCommand(adapter: PluginHostAdapter, args: readonly string[], cwd: string): Promise<{
|
|
3
|
+
version: string;
|
|
4
|
+
workspaceRoot: string;
|
|
5
|
+
resourceRoot: string;
|
|
6
|
+
configuration: import("../model/workspace-config.js").WorkspaceConfiguration;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function runPluginHost(adapter: PluginHostAdapter, args: readonly string[]): Promise<void>;
|
|
9
|
+
/** Shared hook execution engine; host-specific protocols stay in PluginHostAdapter implementations. */
|
|
10
|
+
export declare function pluginHook(adapter: PluginHostAdapter, payload: unknown): Promise<Record<string, unknown>>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { resourceRoot } from "../common/paths.js";
|
|
2
|
+
import { packageVersion } from "../common/version.js";
|
|
3
|
+
import { requireThat } from "../common/validation.js";
|
|
4
|
+
import { loadWorkspaceContext } from "../integrations/agent-resources.js";
|
|
5
|
+
import { readWorkspaceConfig, workspaceFeatures } from "../services/workspace/workspace-config.js";
|
|
6
|
+
import { initializeWorkspace } from "../services/workspace/workspace-preparation.js";
|
|
7
|
+
import { discoverWorkspaceSkills } from "../services/workspace/workspace-skills.js";
|
|
8
|
+
function disabledMessage(adapter, configuration) {
|
|
9
|
+
return configuration.error ?? `Personal Bot 未在此工作区启用。运行 ${adapter.initCommandHint};配置文件:${configuration.path}`;
|
|
10
|
+
}
|
|
11
|
+
export async function pluginCommand(adapter, args, cwd) {
|
|
12
|
+
const root = await adapter.resolveRoot(cwd);
|
|
13
|
+
const action = args.join(" ");
|
|
14
|
+
requireThat(["init", "status"].includes(action), adapter.usage);
|
|
15
|
+
if (action === "init")
|
|
16
|
+
await initializeWorkspace(root);
|
|
17
|
+
const configuration = await readWorkspaceConfig(root);
|
|
18
|
+
return { version: packageVersion, workspaceRoot: root, resourceRoot, configuration };
|
|
19
|
+
}
|
|
20
|
+
export async function runPluginHost(adapter, args) {
|
|
21
|
+
if (args[0] === "hook") {
|
|
22
|
+
let input = "";
|
|
23
|
+
process.stdin.setEncoding("utf8");
|
|
24
|
+
for await (const chunk of process.stdin)
|
|
25
|
+
input += String(chunk);
|
|
26
|
+
process.stdout.write(JSON.stringify(await pluginHook(adapter, JSON.parse(input))) + "\n");
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
process.stdout.write(JSON.stringify(await pluginCommand(adapter, args, process.cwd()), null, 2) + "\n");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Shared hook execution engine; host-specific protocols stay in PluginHostAdapter implementations. */
|
|
33
|
+
export async function pluginHook(adapter, payload) {
|
|
34
|
+
if (process.env.PBOT_SUBAGENT_RUN_ID)
|
|
35
|
+
return adapter.formatPass(payload);
|
|
36
|
+
const event = adapter.parseEvent(payload);
|
|
37
|
+
if (event.kind === "ignore")
|
|
38
|
+
return adapter.formatPass(payload);
|
|
39
|
+
const root = await adapter.resolveRoot(event.cwd, event.raw);
|
|
40
|
+
const configuration = await readWorkspaceConfig(root);
|
|
41
|
+
const features = workspaceFeatures(configuration);
|
|
42
|
+
if (event.kind === "check-skill") {
|
|
43
|
+
if (!configuration.enabled)
|
|
44
|
+
return adapter.formatDeny(event, disabledMessage(adapter, configuration));
|
|
45
|
+
if (!features.skills)
|
|
46
|
+
return adapter.formatDeny(event, `Personal Bot 工作区技能已在 ${configuration.path} 中停用(features.skills: false)。`);
|
|
47
|
+
return adapter.formatPass(payload);
|
|
48
|
+
}
|
|
49
|
+
if (!configuration.enabled)
|
|
50
|
+
return adapter.formatPass(payload);
|
|
51
|
+
const workspaceSkills = features.skills && !adapter.nativeWorkspaceSkills
|
|
52
|
+
? await discoverWorkspaceSkills(root)
|
|
53
|
+
: [];
|
|
54
|
+
if (!features.prompts && !workspaceSkills.length)
|
|
55
|
+
return adapter.formatPass(payload);
|
|
56
|
+
const context = await loadWorkspaceContext({
|
|
57
|
+
host: adapter.host,
|
|
58
|
+
root,
|
|
59
|
+
role: event.role,
|
|
60
|
+
...(adapter.coordinatorPrompt ? { coordinatorPrompt: adapter.coordinatorPrompt } : {}),
|
|
61
|
+
includePrompts: features.prompts,
|
|
62
|
+
includeRootAgents: features.prompts && !adapter.nativeRootAgents,
|
|
63
|
+
...(event.localRoleOnly ? { localRoleOnly: true } : {}),
|
|
64
|
+
workspaceSkills,
|
|
65
|
+
});
|
|
66
|
+
return adapter.formatContext(event, context);
|
|
67
|
+
}
|
|
@@ -1,14 +1,178 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
1
3
|
import { mkdir, readFile, realpath } from "node:fs/promises";
|
|
2
4
|
import { homedir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
3
6
|
import { fileURLToPath } from "node:url";
|
|
4
7
|
import { executeSetup, packageChoices, parseCatalog, parseSetupArgs } from "../services/installation/setup-service.js";
|
|
5
8
|
import { npmName, ordinaryNpm } from "../common/package-source.js";
|
|
6
9
|
import { PiBootstrapRequired, PiSetup, piPackageName } from "../integrations/installation/pi-setup.js";
|
|
7
|
-
import { inspectSystem, SetupProcesses } from "../integrations/installation/processes.js";
|
|
10
|
+
import { findExecutable, inspectSystem, SetupProcesses } from "../integrations/installation/processes.js";
|
|
8
11
|
import { resolveWorkspace } from "../integrations/installation/workspace.js";
|
|
12
|
+
import { readWorkspaceMcpConfig, removeWorkspaceMcpServer, upsertWorkspaceMcpServer, } from "../services/workspace/workspace-mcp.js";
|
|
9
13
|
import { SetupUI } from "../ui/setup.js";
|
|
10
14
|
const root = new URL("../../", import.meta.url);
|
|
11
15
|
const quote = (value) => "'" + value.replaceAll("'", "'\\''") + "'";
|
|
16
|
+
const mcpManageUsage = "用法:\n" +
|
|
17
|
+
" pbot mcp list [--workspace <目录>]\n" +
|
|
18
|
+
" pbot mcp add <name> --url <url> [--header K=V]... [--description <说明>] [--timeout <秒>] [--disabled] [--workspace <目录>]\n" +
|
|
19
|
+
" pbot mcp add <name> [--env K=V]... [--cwd <目录>] [--description <说明>] [--timeout <秒>] [--disabled] [--workspace <目录>] -- <command> [args...]\n" +
|
|
20
|
+
" pbot mcp remove <name> [--workspace <目录>]";
|
|
21
|
+
function parseKeyValue(raw, flag) {
|
|
22
|
+
const sep = raw.indexOf("=");
|
|
23
|
+
if (sep <= 0)
|
|
24
|
+
throw new Error(`${flag} 需要 KEY=VALUE 格式:${raw}`);
|
|
25
|
+
return [raw.slice(0, sep), raw.slice(sep + 1)];
|
|
26
|
+
}
|
|
27
|
+
async function runMcpManage(mcpArgs) {
|
|
28
|
+
const sub = mcpArgs[0];
|
|
29
|
+
if (!sub || ["--help", "-h"].includes(sub)) {
|
|
30
|
+
console.log(mcpManageUsage);
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
const rest = mcpArgs.slice(1);
|
|
34
|
+
if (sub === "list") {
|
|
35
|
+
let workspace;
|
|
36
|
+
for (let i = 0; i < rest.length; i++) {
|
|
37
|
+
if (rest[i] === "--workspace") {
|
|
38
|
+
workspace = rest[++i];
|
|
39
|
+
if (!workspace)
|
|
40
|
+
throw new Error("--workspace 需要目录。");
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error(`未知参数:${rest[i]}\n${mcpManageUsage}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const target = await resolveWorkspace(workspace ?? process.cwd(), process.cwd(), homedir());
|
|
47
|
+
const configuration = await readWorkspaceMcpConfig(target);
|
|
48
|
+
if (configuration.error)
|
|
49
|
+
throw new Error(configuration.error);
|
|
50
|
+
console.log(JSON.stringify({ workspaceRoot: target, path: configuration.path, mcpServers: configuration.servers }, null, 2));
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
if (sub === "remove") {
|
|
54
|
+
const name = rest[0];
|
|
55
|
+
if (!name || name.startsWith("-"))
|
|
56
|
+
throw new Error(`remove 需要服务名。\n${mcpManageUsage}`);
|
|
57
|
+
let workspace;
|
|
58
|
+
for (let i = 1; i < rest.length; i++) {
|
|
59
|
+
if (rest[i] === "--workspace") {
|
|
60
|
+
workspace = rest[++i];
|
|
61
|
+
if (!workspace)
|
|
62
|
+
throw new Error("--workspace 需要目录。");
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
throw new Error(`未知参数:${rest[i]}\n${mcpManageUsage}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const target = await resolveWorkspace(workspace ?? process.cwd(), process.cwd(), homedir());
|
|
69
|
+
const result = await removeWorkspaceMcpServer(target, name);
|
|
70
|
+
console.log(JSON.stringify({ workspaceRoot: target, path: result.configuration.path, removed: result.removed, name }, null, 2));
|
|
71
|
+
return result.removed ? 0 : 1;
|
|
72
|
+
}
|
|
73
|
+
if (sub === "add") {
|
|
74
|
+
const name = rest[0];
|
|
75
|
+
if (!name || name.startsWith("-"))
|
|
76
|
+
throw new Error(`add 需要服务名。\n${mcpManageUsage}`);
|
|
77
|
+
let workspace;
|
|
78
|
+
let url;
|
|
79
|
+
let cwd;
|
|
80
|
+
let description;
|
|
81
|
+
let timeout;
|
|
82
|
+
let enabled;
|
|
83
|
+
const env = {};
|
|
84
|
+
const headers = {};
|
|
85
|
+
let commandTokens = [];
|
|
86
|
+
for (let i = 1; i < rest.length; i++) {
|
|
87
|
+
const arg = rest[i];
|
|
88
|
+
if (arg === "--") {
|
|
89
|
+
commandTokens = rest.slice(i + 1);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
if (arg === "--workspace") {
|
|
93
|
+
workspace = rest[++i];
|
|
94
|
+
if (!workspace)
|
|
95
|
+
throw new Error("--workspace 需要目录。");
|
|
96
|
+
}
|
|
97
|
+
else if (arg === "--url") {
|
|
98
|
+
url = rest[++i];
|
|
99
|
+
if (!url)
|
|
100
|
+
throw new Error("--url 需要地址。");
|
|
101
|
+
}
|
|
102
|
+
else if (arg === "--cwd") {
|
|
103
|
+
cwd = rest[++i];
|
|
104
|
+
if (!cwd)
|
|
105
|
+
throw new Error("--cwd 需要目录。");
|
|
106
|
+
}
|
|
107
|
+
else if (arg === "--description") {
|
|
108
|
+
description = rest[++i];
|
|
109
|
+
if (description === undefined)
|
|
110
|
+
throw new Error("--description 需要说明文本。");
|
|
111
|
+
}
|
|
112
|
+
else if (arg === "--timeout") {
|
|
113
|
+
const raw = rest[++i];
|
|
114
|
+
timeout = Number(raw);
|
|
115
|
+
if (!raw || !Number.isInteger(timeout))
|
|
116
|
+
throw new Error("--timeout 需要整数秒。");
|
|
117
|
+
}
|
|
118
|
+
else if (arg === "--disabled") {
|
|
119
|
+
enabled = false;
|
|
120
|
+
}
|
|
121
|
+
else if (arg === "--env") {
|
|
122
|
+
const raw = rest[++i];
|
|
123
|
+
if (!raw)
|
|
124
|
+
throw new Error("--env 需要 KEY=VALUE。");
|
|
125
|
+
const [k, v] = parseKeyValue(raw, "--env");
|
|
126
|
+
env[k] = v;
|
|
127
|
+
}
|
|
128
|
+
else if (arg === "--header") {
|
|
129
|
+
const raw = rest[++i];
|
|
130
|
+
if (!raw)
|
|
131
|
+
throw new Error("--header 需要 KEY=VALUE。");
|
|
132
|
+
const [k, v] = parseKeyValue(raw, "--header");
|
|
133
|
+
headers[k] = v;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
throw new Error(`未知参数:${arg}\n${mcpManageUsage}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const base = {
|
|
140
|
+
...(description !== undefined ? { description } : {}),
|
|
141
|
+
...(timeout !== undefined ? { timeout } : {}),
|
|
142
|
+
...(enabled !== undefined ? { enabled } : {}),
|
|
143
|
+
};
|
|
144
|
+
let server;
|
|
145
|
+
if (url !== undefined) {
|
|
146
|
+
if (commandTokens.length || Object.keys(env).length || cwd !== undefined) {
|
|
147
|
+
throw new Error("--url(HTTP)不能与 stdio 命令/--env/--cwd 同时使用。");
|
|
148
|
+
}
|
|
149
|
+
server = {
|
|
150
|
+
url,
|
|
151
|
+
...(Object.keys(headers).length ? { headers } : {}),
|
|
152
|
+
...base,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
const [command, ...cmdArgs] = commandTokens;
|
|
157
|
+
if (!command)
|
|
158
|
+
throw new Error(`stdio 服务需要通过 -- <command> [args...] 指定启动命令。\n${mcpManageUsage}`);
|
|
159
|
+
if (Object.keys(headers).length)
|
|
160
|
+
throw new Error("--header 仅适用于 --url(HTTP)服务。");
|
|
161
|
+
server = {
|
|
162
|
+
command,
|
|
163
|
+
...(cmdArgs.length ? { args: cmdArgs } : {}),
|
|
164
|
+
...(Object.keys(env).length ? { env } : {}),
|
|
165
|
+
...(cwd !== undefined ? { cwd } : {}),
|
|
166
|
+
...base,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
const target = await resolveWorkspace(workspace ?? process.cwd(), process.cwd(), homedir());
|
|
170
|
+
const updated = await upsertWorkspaceMcpServer(target, name, server);
|
|
171
|
+
console.log(JSON.stringify({ workspaceRoot: target, path: updated.path, name, server: updated.servers[name] }, null, 2));
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
throw new Error(`未知 mcp 子命令:${sub}\n${mcpManageUsage}`);
|
|
175
|
+
}
|
|
12
176
|
export async function main(args) {
|
|
13
177
|
let options;
|
|
14
178
|
try {
|
|
@@ -25,10 +189,59 @@ export async function main(args) {
|
|
|
25
189
|
}
|
|
26
190
|
if (options.action === "help") {
|
|
27
191
|
console.log("Personal Bot " + manifest.version + "\n\n用法:pbot setup [--workspace <目录>]\n" +
|
|
28
|
-
" npx personal-bot@latest setup\n
|
|
192
|
+
" npx personal-bot@latest setup\n" +
|
|
193
|
+
" pbot install-antigravity\n" +
|
|
194
|
+
" pbot mcp\n" +
|
|
195
|
+
" pbot mcp list|add|remove ...\n\n" +
|
|
196
|
+
"setup 安装或升级 Pi、pbot 和选中的插件,然后启动 Pi 执行 /pbot init。\n" +
|
|
197
|
+
"install-antigravity 通过原生 agy plugin install 安装或更新 Antigravity 插件。\n" +
|
|
198
|
+
"mcp 无参数时启动统一 stdio MCP 服务(暴露 worker_* 与 workspace_mcp_*);带 list/add/remove 时管理工作区 .pbot/mcp.json。\n" +
|
|
29
199
|
"支持 Linux/macOS,需要 Node.js 22.19+ 和 npm。\n--help 显示帮助;--version 显示安装器版本。");
|
|
30
200
|
return 0;
|
|
31
201
|
}
|
|
202
|
+
if (options.action === "mcp-manage") {
|
|
203
|
+
try {
|
|
204
|
+
return await runMcpManage(options.mcpArgs ?? []);
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
208
|
+
return 2;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (options.action === "mcp") {
|
|
212
|
+
const entry = fileURLToPath(new URL("lib/extension/mcp.js", root));
|
|
213
|
+
if (!existsSync(entry)) {
|
|
214
|
+
console.error("缺少 MCP 构建产物:" + entry + "。请先运行 npm run build。");
|
|
215
|
+
return 1;
|
|
216
|
+
}
|
|
217
|
+
const child = spawnSync(process.execPath, [entry], { stdio: "inherit" });
|
|
218
|
+
if (child.error) {
|
|
219
|
+
console.error(String(child.error));
|
|
220
|
+
return 1;
|
|
221
|
+
}
|
|
222
|
+
return child.status ?? 0;
|
|
223
|
+
}
|
|
224
|
+
if (options.action === "install-antigravity") {
|
|
225
|
+
const pluginDir = fileURLToPath(new URL("lib/antigravity-plugin", root));
|
|
226
|
+
if (!existsSync(join(pluginDir, "plugin.json"))) {
|
|
227
|
+
console.error("缺少 Antigravity 插件构建产物:" + pluginDir + "。请先运行 npm run build。");
|
|
228
|
+
return 1;
|
|
229
|
+
}
|
|
230
|
+
const agy = process.env.PBOT_AGY_COMMAND || await findExecutable("agy", process.env);
|
|
231
|
+
if (!agy) {
|
|
232
|
+
console.error("未找到 Antigravity CLI(agy)。请先安装 agy,然后运行:\n agy plugin install " + quote(pluginDir));
|
|
233
|
+
return 1;
|
|
234
|
+
}
|
|
235
|
+
const installed = spawnSync(agy, ["plugin", "install", pluginDir], { stdio: "inherit" });
|
|
236
|
+
if (installed.error) {
|
|
237
|
+
console.error(String(installed.error));
|
|
238
|
+
return 1;
|
|
239
|
+
}
|
|
240
|
+
if (installed.status !== 0)
|
|
241
|
+
return installed.status ?? 1;
|
|
242
|
+
console.log("Antigravity 插件已安装。在目标工作区运行 /pbot init 启用 Personal Bot。");
|
|
243
|
+
return 0;
|
|
244
|
+
}
|
|
32
245
|
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
33
246
|
console.error("setup 需要交互终端。请在终端运行 npx personal-bot@latest setup。");
|
|
34
247
|
return 2;
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import type { AgentHost } from "../../services/agents/agent-service.js";
|
|
2
2
|
import type { AgentDescriptor, AgentOptions, AgentSessionReference } from "../../model/agent.js";
|
|
3
|
-
import type { AcpBackend, AcpCommands } from "../../model/acp.js";
|
|
3
|
+
import type { AcpBackend, AcpCommands, AcpModelsResult } from "../../model/acp.js";
|
|
4
4
|
import { AgentFiles } from "../../storage/agent-files.js";
|
|
5
|
-
/**
|
|
6
|
-
export declare class
|
|
7
|
-
readonly native: AgentHost;
|
|
5
|
+
/** Pure ACP v1 worker host; spawns isolated acp-worker child processes for any registered or custom harness. */
|
|
6
|
+
export declare class AcpWorkerHost implements AgentHost {
|
|
8
7
|
readonly commands: AcpCommands;
|
|
9
|
-
readonly kind: import("../../model/agent.js").NativeAgentHost;
|
|
10
8
|
readonly files: AgentFiles;
|
|
11
9
|
readonly worker: string;
|
|
12
|
-
constructor(
|
|
13
|
-
available(backend
|
|
10
|
+
constructor(directory: string, commands?: AcpCommands);
|
|
11
|
+
available(backend: AcpBackend): void;
|
|
12
|
+
filterOptions(backend: AcpBackend, options: AgentOptions): AgentOptions;
|
|
14
13
|
prepare(backend: AcpBackend, options: AgentOptions): import("../../model/acp.js").AcpSessionReference;
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
/** Probe a backend's advertised model and thinking choices in an isolated ACP process without prompting. */
|
|
15
|
+
inspectModels(backend: AcpBackend, cwd: string, options?: Pick<AgentOptions, "provider" | "model">): Promise<AcpModelsResult>;
|
|
17
16
|
private process;
|
|
18
17
|
alive(id: string): boolean;
|
|
19
18
|
validateSession(d: AgentDescriptor, reference: AgentSessionReference): Promise<void>;
|
|
20
19
|
private spawn;
|
|
21
|
-
launch(d: AgentDescriptor,
|
|
20
|
+
launch(d: AgentDescriptor, _directory: string, generation: string, _reference: AgentSessionReference, _resume: boolean, signal: AbortSignal): Promise<void>;
|
|
22
21
|
release(id: string, generation: string): Promise<void>;
|
|
23
|
-
report(d: AgentDescriptor,
|
|
22
|
+
report(d: AgentDescriptor, _reference: AgentSessionReference, leaf: string): string;
|
|
24
23
|
}
|
|
@@ -3,38 +3,77 @@ import { existsSync } from "node:fs";
|
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
4
|
import { setTimeout as delay } from "node:timers/promises";
|
|
5
5
|
import { AgentFiles, launch } from "../../storage/agent-files.js";
|
|
6
|
-
import { acpInput, acpProcess,
|
|
6
|
+
import { acpInput, acpProcess, acpReport } from "../../storage/acp-files.js";
|
|
7
7
|
import { fileId } from "../../storage/file-access.js";
|
|
8
8
|
import { requireThat } from "../../common/validation.js";
|
|
9
9
|
import { resourceRoot } from "../../common/paths.js";
|
|
10
|
-
import { acpLaunch } from "./launch.js";
|
|
11
|
-
/**
|
|
12
|
-
export class
|
|
13
|
-
native;
|
|
10
|
+
import { acpLaunch, filterAcpStartOptions } from "./launch.js";
|
|
11
|
+
/** Pure ACP v1 worker host; spawns isolated acp-worker child processes for any registered or custom harness. */
|
|
12
|
+
export class AcpWorkerHost {
|
|
14
13
|
commands;
|
|
15
|
-
kind;
|
|
16
14
|
files;
|
|
17
15
|
worker = resolve(resourceRoot, "../lib/extension/acp-worker.js");
|
|
18
|
-
constructor(
|
|
19
|
-
this.native = native;
|
|
16
|
+
constructor(directory, commands = {}) {
|
|
20
17
|
this.commands = commands;
|
|
21
|
-
this.
|
|
22
|
-
this.files = new AgentFiles(directory, native.kind);
|
|
18
|
+
this.files = new AgentFiles(directory);
|
|
23
19
|
}
|
|
24
20
|
available(backend) {
|
|
25
|
-
|
|
26
|
-
return this.native.available();
|
|
21
|
+
requireThat(backend, "通过 worker_create 委派跨 Harness 专家时必须指定 backend(例如 pi、dsh、claude、antigravity、codex 或自定义 ACP 名称)。");
|
|
27
22
|
requireThat(process.platform === "linux" || process.platform === "darwin", "ACP worker 当前支持 Linux 和 macOS。");
|
|
28
23
|
requireThat(existsSync(this.worker), "缺少 ACP worker 构建产物;请先运行 npm run build。");
|
|
29
24
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
filterOptions(backend, options) {
|
|
26
|
+
return filterAcpStartOptions(backend, options);
|
|
27
|
+
}
|
|
28
|
+
prepare(backend, options) {
|
|
29
|
+
return acpLaunch(backend, this.commands, options);
|
|
30
|
+
}
|
|
31
|
+
/** Probe a backend's advertised model and thinking choices in an isolated ACP process without prompting. */
|
|
32
|
+
async inspectModels(backend, cwd, options = {}) {
|
|
33
|
+
this.available(backend);
|
|
34
|
+
const filtered = this.filterOptions(backend, options);
|
|
35
|
+
const reference = this.prepare(backend, filtered);
|
|
36
|
+
return await new Promise((resolveResult, reject) => {
|
|
37
|
+
const child = fork(this.worker, ["--probe"], {
|
|
38
|
+
cwd, env: { ...process.env }, detached: true, stdio: ["ignore", "ignore", "ignore", "ipc"], execArgv: [],
|
|
39
|
+
});
|
|
40
|
+
let result, failure;
|
|
41
|
+
const timer = setTimeout(() => {
|
|
42
|
+
failure = new Error("ACP 模型探测超时。");
|
|
43
|
+
if (child.pid) {
|
|
44
|
+
try {
|
|
45
|
+
process.kill(-child.pid, "SIGKILL");
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (error.code !== "ESRCH")
|
|
49
|
+
reject(error);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}, 30_000);
|
|
53
|
+
child.on("message", (message) => {
|
|
54
|
+
if (message.type === "models" && message.result)
|
|
55
|
+
result = message.result;
|
|
56
|
+
if (message.type === "error")
|
|
57
|
+
failure = new Error(message.error ?? "ACP 模型探测失败。");
|
|
58
|
+
});
|
|
59
|
+
child.once("error", error => { failure = error; });
|
|
60
|
+
child.once("spawn", () => {
|
|
61
|
+
child.send({
|
|
62
|
+
reference,
|
|
63
|
+
cwd,
|
|
64
|
+
...(filtered.provider ? { provider: filtered.provider } : {}),
|
|
65
|
+
...(filtered.model ? { model: filtered.model } : {}),
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
child.once("close", code => {
|
|
69
|
+
clearTimeout(timer);
|
|
70
|
+
if (result && code === 0 && !failure)
|
|
71
|
+
resolveResult(result);
|
|
72
|
+
else
|
|
73
|
+
reject(failure ?? new Error("ACP 模型探测失败。"));
|
|
74
|
+
});
|
|
75
|
+
});
|
|
36
76
|
}
|
|
37
|
-
isAcp(id) { return Boolean(this.files.optional(id, "acp-session.json", acpReference)); }
|
|
38
77
|
process(id) {
|
|
39
78
|
const record = this.files.optional(id, "acp-process.json", acpProcess);
|
|
40
79
|
if (!record || this.files.read(id, "launch.json", launch).generation !== record.generation)
|
|
@@ -57,10 +96,10 @@ export class AgentBackends {
|
|
|
57
96
|
return;
|
|
58
97
|
return record;
|
|
59
98
|
}
|
|
60
|
-
alive(id) {
|
|
99
|
+
alive(id) {
|
|
100
|
+
return Boolean(this.process(id));
|
|
101
|
+
}
|
|
61
102
|
async validateSession(d, reference) {
|
|
62
|
-
if (reference.host !== "acp")
|
|
63
|
-
return this.native.validateSession(d, reference);
|
|
64
103
|
requireThat(!this.alive(d.agentId), "ACP 成员仍在运行,不能恢复。");
|
|
65
104
|
if (reference.sessionId === null) {
|
|
66
105
|
requireThat(!this.files.optional(d.agentId, "acp-input.json", acpInput), "ACP 输入交付状态不明;请核对原请求后新建成员。");
|
|
@@ -96,15 +135,12 @@ export class AgentBackends {
|
|
|
96
135
|
});
|
|
97
136
|
}
|
|
98
137
|
spawn(d, generation, validate = false) {
|
|
99
|
-
|
|
100
|
-
|
|
138
|
+
return fork(this.worker, ["--pbot-acp-agent", d.agentId, "--generation", generation, "--directory", this.files.directory(d.agentId),
|
|
139
|
+
...(validate ? ["--validate"] : [])], {
|
|
101
140
|
cwd: d.cwd, env: { ...process.env }, detached: true, stdio: ["ignore", "ignore", "ignore", "ipc"], execArgv: [],
|
|
102
141
|
});
|
|
103
|
-
return child;
|
|
104
142
|
}
|
|
105
|
-
async launch(d,
|
|
106
|
-
if (reference.host !== "acp")
|
|
107
|
-
return this.native.launch(d, directory, generation, reference, resume, signal);
|
|
143
|
+
async launch(d, _directory, generation, _reference, _resume, signal) {
|
|
108
144
|
signal.throwIfAborted();
|
|
109
145
|
const child = this.spawn(d, generation);
|
|
110
146
|
await new Promise((resolveResult, reject) => { child.once("spawn", resolveResult); child.once("error", reject); });
|
|
@@ -131,8 +167,6 @@ export class AgentBackends {
|
|
|
131
167
|
}
|
|
132
168
|
}
|
|
133
169
|
async release(id, generation) {
|
|
134
|
-
if (!this.isAcp(id))
|
|
135
|
-
return this.native.release(id, generation);
|
|
136
170
|
const record = this.process(id);
|
|
137
171
|
if (!record || record.generation !== generation)
|
|
138
172
|
return;
|
|
@@ -157,9 +191,7 @@ export class AgentBackends {
|
|
|
157
191
|
if (current?.generation === generation && current.pid === record.pid)
|
|
158
192
|
terminate("SIGKILL");
|
|
159
193
|
}
|
|
160
|
-
report(d,
|
|
161
|
-
if (reference.host !== "acp")
|
|
162
|
-
return this.native.report(d, reference, leaf);
|
|
194
|
+
report(d, _reference, leaf) {
|
|
163
195
|
requireThat(leaf.startsWith("acp:"), "ACP 报告引用无效。");
|
|
164
196
|
const cycleId = fileId(leaf.slice(4)), report = this.files.read(d.agentId, join("reports", cycleId + ".json"), acpReport);
|
|
165
197
|
requireThat(report.cycleId === cycleId, "ACP 报告周期不匹配。");
|
|
@@ -2,7 +2,7 @@ import type { AcpCommand } from "../../model/acp.js";
|
|
|
2
2
|
export interface ClaudeConfiguration {
|
|
3
3
|
thinking?: string;
|
|
4
4
|
options: {
|
|
5
|
-
plugins
|
|
5
|
+
plugins?: {
|
|
6
6
|
type: "local";
|
|
7
7
|
path: string;
|
|
8
8
|
}[];
|
|
@@ -15,4 +15,4 @@ export interface ClaudeConfiguration {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
/** Read the target installation's native settings without creating a model session. */
|
|
18
|
-
export declare function claudeOptions(command: AcpCommand, cwd: string,
|
|
18
|
+
export declare function claudeOptions(command: AcpCommand, cwd: string, supplied?: string, includeSkills?: boolean): Promise<ClaudeConfiguration>;
|
|
@@ -6,7 +6,9 @@ import { requireThat } from "../../common/validation.js";
|
|
|
6
6
|
import { resourceRoot } from "../../common/paths.js";
|
|
7
7
|
const levels = ["low", "medium", "high", "xhigh", "max"];
|
|
8
8
|
/** Read the target installation's native settings without creating a model session. */
|
|
9
|
-
export async function claudeOptions(command, cwd,
|
|
9
|
+
export async function claudeOptions(command, cwd, supplied, includeSkills = true) {
|
|
10
|
+
const normalized = supplied?.trim().toLowerCase().replace(/[^a-z0-9]+/g, "");
|
|
11
|
+
const requested = normalized === "extrahigh" ? "xhigh" : normalized;
|
|
10
12
|
const script = command.args[0];
|
|
11
13
|
const anchor = ["node", "node.exe"].includes(basename(command.command)) && script && !script.startsWith("-") ? resolve(cwd, script) : command.command;
|
|
12
14
|
const require = createRequire(pathToFileURL(anchor));
|
|
@@ -17,13 +19,13 @@ export async function claudeOptions(command, cwd, requested) {
|
|
|
17
19
|
const environment = object(resolved.effective.env) ? resolved.effective.env : {};
|
|
18
20
|
const configured = environment.CLAUDE_CODE_EFFORT_LEVEL ?? process.env.CLAUDE_CODE_EFFORT_LEVEL;
|
|
19
21
|
const explicit = requested !== undefined && requested !== "default";
|
|
20
|
-
requireThat(!explicit || levels.includes(requested), "Claude 思考等级不可用:" + requested);
|
|
22
|
+
requireThat(!explicit || levels.includes(requested), "Claude 思考等级不可用:" + requested + ";可用值:default, " + levels.join(", "));
|
|
21
23
|
const effort = explicit ? requested : typeof configured === "string" && levels.includes(configured) ? configured : undefined;
|
|
22
24
|
const thinking = effort ?? (configured === "unset" ? "unset" : undefined);
|
|
23
25
|
return {
|
|
24
26
|
...(thinking ? { thinking } : {}),
|
|
25
27
|
options: {
|
|
26
|
-
plugins: [{ type: "local", path: join(resourceRoot, "skills") }],
|
|
28
|
+
...(includeSkills ? { plugins: [{ type: "local", path: join(resourceRoot, "skills") }] } : {}),
|
|
27
29
|
...(effort ? { effort } : {}),
|
|
28
30
|
// SDK effort alone loses to CLAUDE_CODE_EFFORT_LEVEL. A flag-tier env entry
|
|
29
31
|
// applies the explicit choice to this invocation and preserves other settings.
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import * as acp from "@agentclientprotocol/sdk";
|
|
2
|
-
import type { AcpModelSelection, AcpSessionReference } from "../../model/acp.js";
|
|
2
|
+
import type { AcpHarnessAdapter, AcpModelSelection, AcpSessionReference } from "../../model/acp.js";
|
|
3
3
|
import type { AgentOptions } from "../../model/agent.js";
|
|
4
|
-
import type { ClaudeConfiguration } from "./claude.js";
|
|
5
4
|
export declare function acpFailure(error: unknown): unknown;
|
|
6
5
|
export interface AcpCallbacks {
|
|
7
6
|
update(update: acp.SessionUpdate): void | Promise<void>;
|
|
8
7
|
selection?(selection: AcpModelSelection): void;
|
|
9
8
|
permission(request: acp.RequestPermissionRequest, signal: AbortSignal): Promise<acp.RequestPermissionResponse>;
|
|
9
|
+
elicitation?(request: acp.CreateElicitationRequest, signal: AbortSignal): Promise<acp.CreateElicitationResponse>;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
export interface OpenAcpOptions {
|
|
12
|
+
readonly harness?: AcpHarnessAdapter;
|
|
13
|
+
readonly systemPrompt?: string;
|
|
14
|
+
readonly sessionMeta?: Record<string, unknown>;
|
|
15
|
+
readonly defaultThinking?: string;
|
|
16
|
+
readonly mcpServers?: readonly acp.McpServer[];
|
|
17
|
+
}
|
|
18
|
+
/** One ACP v1 connection. The worker owns its process group and business state; harness hooks stay in AcpHarnessAdapter. */
|
|
19
|
+
export declare function openAcp(reference: AcpSessionReference, cwd: string, env: NodeJS.ProcessEnv, callbacks: AcpCallbacks, signal: AbortSignal, openOptions?: OpenAcpOptions): Promise<{
|
|
13
20
|
sessionId: string;
|
|
14
21
|
capabilities: {
|
|
15
22
|
resume: boolean;
|
|
@@ -21,6 +28,12 @@ export declare function openAcp(reference: AcpSessionReference, cwd: string, env
|
|
|
21
28
|
images: boolean;
|
|
22
29
|
systemPrompt: boolean;
|
|
23
30
|
selection: () => AcpModelSelection;
|
|
31
|
+
choices: () => {
|
|
32
|
+
currentThinking?: string;
|
|
33
|
+
currentModel?: string;
|
|
34
|
+
models: import("../../model/acp.js").AcpChoice[];
|
|
35
|
+
thinking: import("../../model/acp.js").AcpChoice[];
|
|
36
|
+
};
|
|
24
37
|
configure(requested: AgentOptions): Promise<AcpModelSelection>;
|
|
25
38
|
prompt(content: acp.ContentBlock[]): Promise<acp.PromptResponse>;
|
|
26
39
|
cancel(): Promise<void>;
|