personal-bot 0.3.2 → 0.3.4
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 +2 -2
- package/.claude-plugin/plugin.json +2 -1
- package/DISCLAIMER.md +17 -0
- package/LICENSE +21 -0
- package/README.md +15 -5
- package/README.zh-CN.md +15 -5
- package/bin/pbot-pi-acp.mjs +1 -1
- package/bin/pbot.mjs +22 -2
- package/docs/README.md +2 -0
- package/docs/architecture/design.md +16 -16
- package/docs/architecture/extensibility.md +29 -2
- package/docs/architecture/model-context.md +3 -2
- package/docs/architecture/principles.md +2 -2
- package/docs/guides/capabilities.md +1 -1
- package/docs/guides/cross-harness-workers.md +3 -1
- package/docs/guides/history.md +30 -7
- package/docs/guides/workspace-configuration.md +20 -3
- package/docs/hosts/antigravity.md +1 -1
- package/docs/hosts/claude-code.md +1 -1
- package/docs/hosts/codex-qoder.md +63 -0
- package/docs/maintainers/architecture-governance.md +78 -0
- package/lib/antigravity-plugin/DISCLAIMER.md +17 -0
- package/lib/antigravity-plugin/LICENSE +21 -0
- package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +36 -0
- package/lib/antigravity-plugin/lib/common/files.d.ts +2 -0
- package/lib/antigravity-plugin/lib/common/files.js +44 -0
- package/lib/antigravity-plugin/lib/common/validation.d.ts +4 -0
- package/lib/antigravity-plugin/lib/common/validation.js +8 -0
- package/lib/antigravity-plugin/lib/extension/acp/member.d.ts +18 -0
- package/lib/antigravity-plugin/lib/extension/acp/member.js +44 -0
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +71 -45
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.js +22 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.d.ts +4 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.js +58 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.d.ts +5 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.js +67 -0
- package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.d.ts +3 -0
- package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +100 -0
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.d.ts +3 -1
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +37 -22
- package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.d.ts +6 -0
- package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.js +21 -0
- package/lib/antigravity-plugin/lib/extension/mcp.js +2577 -2255
- package/lib/antigravity-plugin/lib/extension/workspace-cli.js +20171 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +7 -59
- package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.d.ts +2 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.js +14 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.js +28 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.d.ts +36 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.js +11 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.d.ts +6 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.js +47 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.js +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.d.ts +8 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.js +31 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.js +32 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.js +23 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.d.ts +1 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.js +8 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.js +76 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.js +16 -0
- package/lib/antigravity-plugin/lib/model/acp.d.ts +7 -3
- package/lib/antigravity-plugin/lib/model/acp.js +8 -0
- package/lib/antigravity-plugin/lib/model/agent.d.ts +121 -0
- package/lib/antigravity-plugin/lib/model/agent.js +4 -0
- package/lib/antigravity-plugin/lib/model/history.d.ts +10 -0
- package/lib/antigravity-plugin/lib/model/history.js +4 -1
- package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +5 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +8 -12
- package/lib/antigravity-plugin/lib/model/workspace-config.js +2 -1
- package/lib/antigravity-plugin/lib/plugin.d.ts +2 -1
- package/lib/antigravity-plugin/lib/plugin.js +2 -2
- package/lib/antigravity-plugin/lib/services/history/history-capture.js +34 -22
- package/lib/antigravity-plugin/lib/services/history/summary-registry.js +2 -3
- package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +2 -5
- package/lib/antigravity-plugin/lib/services/history/summary-runner.js +72 -74
- package/lib/antigravity-plugin/lib/services/history/workspace-history.d.ts +3 -0
- package/lib/antigravity-plugin/lib/services/history/workspace-history.js +6 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +15 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +126 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +9 -8
- package/lib/antigravity-plugin/lib/services/workspace/workspace-files.d.ts +2 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-files.js +17 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.d.ts +14 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.js +193 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.d.ts +1 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.js +4 -2
- package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +11 -0
- package/lib/antigravity-plugin/lib/storage/acp-files.js +75 -0
- package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +31 -0
- package/lib/antigravity-plugin/lib/storage/agent-files.js +159 -0
- package/lib/antigravity-plugin/lib/storage/atomic-json.d.ts +3 -1
- package/lib/antigravity-plugin/lib/storage/atomic-json.js +43 -3
- package/lib/antigravity-plugin/lib/storage/history-files.d.ts +2 -1
- package/lib/antigravity-plugin/lib/storage/history-files.js +21 -15
- package/lib/antigravity-plugin/lib/storage/history-format.d.ts +2 -3
- package/lib/antigravity-plugin/lib/storage/history-format.js +5 -7
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +1 -1
- package/lib/antigravity-plugin/resources/prompts/history-monthly-summary.md +13 -0
- package/lib/antigravity-plugin/resources/prompts/history-summary.md +13 -0
- package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -0
- package/lib/antigravity-plugin/resources/skills/.claude-plugin/plugin.json +4 -0
- package/lib/antigravity-plugin/resources/skills/project-maintenance/SKILL.md +35 -0
- package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +52 -0
- package/lib/antigravity-plugin/skills/pbot/SKILL.md +11 -1
- package/lib/client.js +22 -50
- package/lib/codex-marketplace/.agents/plugins/marketplace.json +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +7 -0
- package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/DISCLAIMER.md +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/LICENSE +21 -0
- package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +37 -0
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +9 -0
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/agents/openai.yaml +2 -0
- package/lib/common/validation.d.ts +4 -0
- package/lib/common/validation.js +8 -0
- package/lib/dsh.js +2 -2
- package/lib/extension/acp/member.d.ts +1 -1
- package/lib/extension/acp-worker.js +71 -45
- package/lib/extension/history/command.d.ts +37 -0
- package/lib/extension/history/command.js +57 -0
- package/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
- package/lib/extension/hosts/dsh/acp-entry.js +22 -0
- package/lib/extension/hosts/dsh/acp-member.js +4 -18
- package/lib/extension/hosts/dsh/command.d.ts +1 -2
- package/lib/extension/hosts/dsh/command.js +5 -49
- package/lib/extension/hosts/dsh/workspace.js +13 -44
- package/lib/extension/hosts/pi/acp-member.d.ts +3 -0
- package/lib/extension/hosts/pi/acp-member.js +100 -0
- package/lib/extension/hosts/plugin-runtime.d.ts +3 -1
- package/lib/extension/hosts/plugin-runtime.js +37 -22
- package/lib/extension/hosts/workspace-mcp.d.ts +6 -0
- package/lib/extension/hosts/workspace-mcp.js +21 -0
- package/lib/extension/mcp/bridge.d.ts +6 -8
- package/lib/extension/mcp/bridge.js +66 -84
- package/lib/extension/mcp/tool-contract.d.ts +735 -0
- package/lib/extension/mcp/tool-contract.js +441 -0
- package/lib/extension/mcp/workers.d.ts +29 -742
- package/lib/extension/mcp/workers.js +75 -525
- package/lib/extension/mcp.js +2577 -2255
- package/lib/extension/setup/cli.js +15 -0
- package/lib/extension/setup/upgrade.js +153 -0
- package/lib/extension/workspace-cli.js +20171 -0
- package/lib/integrations/acp/agents.d.ts +2 -3
- package/lib/integrations/acp/harnesses/dsh.js +1 -1
- package/lib/integrations/acp/harnesses/presets.js +8 -0
- package/lib/integrations/acp/history-summary.js +2 -1
- package/lib/integrations/acp/launch.d.ts +2 -2
- package/lib/integrations/agent-resources.js +1 -1
- package/lib/integrations/hosts/claude/adapter.js +7 -59
- package/lib/integrations/hosts/codex/adapter.d.ts +2 -0
- package/lib/integrations/hosts/codex/adapter.js +14 -0
- package/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
- package/lib/integrations/hosts/pi/agent-tools.js +32 -0
- package/lib/integrations/hosts/pi/mcp.d.ts +4 -0
- package/lib/integrations/hosts/pi/mcp.js +23 -0
- package/lib/integrations/hosts/plugin-registry.d.ts +1 -0
- package/lib/integrations/hosts/plugin-registry.js +8 -1
- package/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
- package/lib/integrations/hosts/prompt-hooks.js +76 -0
- package/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
- package/lib/integrations/hosts/qoder/adapter.js +16 -0
- package/lib/integrations/installation/cli-update.js +146 -0
- package/lib/integrations/installation/upgraders/antigravity.js +67 -0
- package/lib/integrations/installation/upgraders/claude.js +123 -0
- package/lib/integrations/installation/upgraders/codex.js +73 -0
- package/lib/integrations/installation/upgraders/dsh.js +62 -0
- package/lib/integrations/installation/upgraders/pi.js +90 -0
- package/lib/integrations/installation/upgraders/qoder.js +67 -0
- package/lib/integrations/installation/upgraders/registry.js +40 -0
- package/lib/model/acp.d.ts +7 -3
- package/lib/model/acp.js +8 -0
- package/lib/model/agent.d.ts +18 -4
- package/lib/model/agent.js +4 -1
- package/lib/model/history.d.ts +10 -0
- package/lib/model/history.js +4 -1
- package/lib/model/installation.js +1 -0
- package/lib/model/plugin-host.d.ts +5 -0
- package/lib/model/workspace-config.d.ts +8 -12
- package/lib/model/workspace-config.js +2 -1
- package/lib/plugin.d.ts +2 -1
- package/lib/plugin.js +2 -2
- package/lib/qoder-plugin/.mcp.json +17 -0
- package/lib/qoder-plugin/.qoder-plugin/plugin.json +7 -0
- package/lib/qoder-plugin/DISCLAIMER.md +17 -0
- package/lib/qoder-plugin/LICENSE +21 -0
- package/lib/qoder-plugin/hooks/hooks.json +37 -0
- package/lib/qoder-plugin/skills/pbot/SKILL.md +9 -0
- package/lib/services/agents/agent-service.d.ts +15 -45
- package/lib/services/agents/agent-service.js +22 -3
- package/lib/services/history/history-capture.js +34 -22
- package/lib/services/history/history-migrate.js +26 -60
- package/lib/services/history/history-query.js +38 -57
- package/lib/services/history/summary-command.d.ts +1 -1
- package/lib/services/history/summary-command.js +8 -7
- package/lib/services/history/summary-registry.js +2 -3
- package/lib/services/history/summary-runner.d.ts +2 -5
- package/lib/services/history/summary-runner.js +72 -74
- package/lib/services/history/workspace-history.d.ts +3 -0
- package/lib/services/history/workspace-history.js +6 -0
- package/lib/services/installation/setup-service.js +4 -1
- package/lib/services/installation/upgrade-service.js +95 -0
- package/lib/services/workspace/plugin-releases.d.ts +15 -0
- package/lib/services/workspace/plugin-releases.js +126 -0
- package/lib/services/workspace/workspace-config.js +9 -8
- package/lib/services/workspace/workspace-mcp.js +22 -29
- package/lib/services/workspace/workspace-skills.d.ts +1 -0
- package/lib/services/workspace/workspace-skills.js +4 -2
- package/lib/storage/acp-files.js +7 -12
- package/lib/storage/agent-files.js +6 -5
- package/lib/storage/atomic-json.d.ts +3 -1
- package/lib/storage/atomic-json.js +43 -3
- package/lib/storage/history-files.d.ts +2 -1
- package/lib/storage/history-files.js +21 -15
- package/lib/storage/history-format.d.ts +2 -3
- package/lib/storage/history-format.js +5 -7
- package/lib/tools/history/contract.d.ts +3 -11
- package/lib/tools/history/contract.js +8 -7
- package/lib/ui/dsh/elements.d.ts +2 -5
- package/lib/ui/dsh/elements.js +3 -16
- package/lib/ui/dsh/management.js +9 -9
- package/lib/ui/dsh/styles.d.ts +1 -1
- package/lib/ui/dsh/styles.js +5 -33
- package/package.json +4 -1
- package/resources/antigravity/skills/pbot/SKILL.md +11 -1
- package/resources/claude/skills/pbot/SKILL.md +11 -1
- package/resources/plugin/skills/pbot/SKILL.md +9 -0
- package/resources/prompts/history-coordinator.md +1 -0
- package/resources/prompts/plugin-coordinator.md +1 -0
- package/scripts/README.md +3 -2
- package/src/common/validation.ts +10 -0
- package/src/dsh.ts +2 -2
- package/src/extension/history/command.ts +68 -0
- package/src/extension/hosts/dsh/acp-entry.ts +21 -0
- package/src/extension/hosts/dsh/acp-member.ts +4 -15
- package/src/extension/hosts/dsh/command.ts +6 -46
- package/src/extension/hosts/dsh/workspace.ts +12 -38
- package/src/extension/hosts/pi/acp-member.ts +4 -10
- package/src/extension/hosts/pi/command.ts +14 -63
- package/src/extension/hosts/pi/events.ts +2 -8
- package/src/extension/hosts/pi/lifecycle.ts +3 -2
- package/src/extension/hosts/plugin-runtime.ts +39 -19
- package/src/extension/hosts/workspace-mcp.ts +25 -0
- package/src/extension/mcp/bridge.ts +80 -80
- package/src/extension/mcp/tool-contract.ts +462 -0
- package/src/extension/mcp/workers.ts +81 -551
- package/src/extension/setup/cli.ts +11 -1
- package/src/extension/setup/upgrade.ts +158 -0
- package/src/extension/setup/workspace-cli.ts +167 -0
- package/src/integrations/acp/agents.ts +2 -3
- package/src/integrations/acp/harnesses/dsh.ts +1 -1
- package/src/integrations/acp/harnesses/presets.ts +8 -0
- package/src/integrations/acp/history-summary.ts +2 -1
- package/src/integrations/agent-resources.ts +1 -1
- package/src/integrations/hosts/claude/adapter.ts +7 -53
- package/src/integrations/hosts/codex/adapter.ts +16 -0
- package/src/integrations/hosts/plugin-registry.ts +9 -1
- package/src/integrations/hosts/prompt-hooks.ts +72 -0
- package/src/integrations/hosts/qoder/adapter.ts +19 -0
- package/src/integrations/installation/cli-update.ts +144 -0
- package/src/integrations/installation/pi-bridge.ts +1 -1
- package/src/integrations/installation/pi-setup.ts +1 -1
- package/src/integrations/installation/processes.ts +1 -1
- package/src/integrations/installation/upgraders/antigravity.ts +68 -0
- package/src/integrations/installation/upgraders/claude.ts +123 -0
- package/src/integrations/installation/upgraders/codex.ts +73 -0
- package/src/integrations/installation/upgraders/dsh.ts +63 -0
- package/src/integrations/installation/upgraders/pi.ts +87 -0
- package/src/integrations/installation/upgraders/qoder.ts +68 -0
- package/src/integrations/installation/upgraders/registry.ts +48 -0
- package/src/model/acp.ts +11 -3
- package/src/model/agent.ts +20 -4
- package/src/model/history.ts +5 -0
- package/src/model/installation.ts +86 -0
- package/src/model/plugin-host.ts +5 -1
- package/src/model/workspace-config.ts +6 -12
- package/src/pbot.ts +13 -32
- package/src/plugin.ts +3 -3
- package/src/services/agents/agent-service.ts +29 -17
- package/src/services/history/history-capture.ts +30 -22
- package/src/services/history/history-migrate.ts +23 -50
- package/src/services/history/history-query.ts +34 -48
- package/src/services/history/summary-command.ts +9 -8
- package/src/services/history/summary-registry.ts +2 -3
- package/src/services/history/summary-runner.ts +72 -81
- package/src/services/history/workspace-history.ts +8 -0
- package/src/services/installation/setup-service.ts +9 -43
- package/src/services/installation/upgrade-service.ts +127 -0
- package/src/services/workspace/plugin-releases.ts +121 -0
- package/src/services/workspace/workspace-config.ts +9 -8
- package/src/services/workspace/workspace-mcp.ts +23 -28
- package/src/services/workspace/workspace-skills.ts +5 -2
- package/src/storage/acp-files.ts +7 -12
- package/src/storage/agent-files.ts +6 -5
- package/src/storage/atomic-json.ts +31 -4
- package/src/storage/history-files.ts +22 -15
- package/src/storage/history-format.ts +6 -8
- package/src/tools/history/contract.ts +9 -9
- package/src/tools/history/pi-tool.ts +6 -4
- package/src/ui/dsh/elements.ts +5 -12
- package/src/ui/dsh/management.ts +10 -10
- package/src/ui/dsh/styles.ts +5 -33
- package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +0 -12
- package/lib/antigravity-plugin/lib/services/history/history-migrate.js +0 -88
- package/lib/ui/presentation.d.ts +0 -3
- package/lib/ui/presentation.js +0 -12
- package/src/tools/access.ts +0 -7
- package/src/tools/register.ts +0 -21
- package/src/ui/presentation.ts +0 -12
|
@@ -6,7 +6,7 @@ import { join } from "node:path";
|
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { executeSetup, packageChoices, parseCatalog, parseSetupArgs } from "../../services/installation/setup-service.js";
|
|
8
8
|
import { npmName, ordinaryNpm } from "../../common/package-source.js";
|
|
9
|
-
import type { InstalledPackage, SetupPlan } from "../../
|
|
9
|
+
import type { InstalledPackage, SetupPlan } from "../../model/installation.js";
|
|
10
10
|
import { PiBootstrapRequired, PiSetup, piPackageName } from "../../integrations/installation/pi-setup.js";
|
|
11
11
|
import { findExecutable, inspectSystem, SetupProcesses } from "../../integrations/installation/processes.js";
|
|
12
12
|
import { resolveWorkspace } from "../../integrations/installation/workspace.js";
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
upsertWorkspaceMcpServer,
|
|
18
18
|
} from "../../services/workspace/workspace-mcp.js";
|
|
19
19
|
import { SetupUI } from "../../ui/setup.js";
|
|
20
|
+
import { runUpgradeCommand } from "./upgrade.js";
|
|
20
21
|
|
|
21
22
|
const root = new URL("../../../", import.meta.url);
|
|
22
23
|
const quote = (value: string) => "'" + value.replaceAll("'", "'\\''") + "'";
|
|
@@ -168,15 +169,24 @@ export async function main(args: string[]): Promise<number> {
|
|
|
168
169
|
if (options.action === "help") {
|
|
169
170
|
console.log("Personal Bot " + manifest.version + "\n\n用法:pbot setup [--workspace <目录>]\n" +
|
|
170
171
|
" npx personal-bot@latest setup\n" +
|
|
172
|
+
" pbot upgrade|update [--workspace <目录>] [--version <版本>] [--hosts <列表>] [--dsh-profile <名称>] [--json]\n" +
|
|
173
|
+
" pbot init | status [--workspace <目录>] [--json]\n" +
|
|
174
|
+
" pbot history status|list|summary|migrate|search|read [参数] [--workspace <目录>] [--json]\n" +
|
|
171
175
|
" pbot install-antigravity\n" +
|
|
176
|
+
" pbot plugin <host> hook|init|status\n" +
|
|
172
177
|
" pbot mcp\n" +
|
|
173
178
|
" pbot mcp list|add|remove ...\n\n" +
|
|
174
179
|
"setup 安装或升级 Pi、pbot 和选中的插件,然后启动 Pi 执行 /pbot init。\n" +
|
|
180
|
+
"upgrade|update 将全局 CLI 与当前工作区已绑定的各宿主插件统一升级到 npm 最新稳定版。\n" +
|
|
175
181
|
"install-antigravity 通过原生 agy plugin install 安装或更新 Antigravity 插件。\n" +
|
|
176
182
|
"mcp 无参数时启动统一 stdio MCP 服务(暴露 worker_* 与 workspace_mcp_*);带 list/add/remove 时管理工作区 .pbot/mcp.json。\n" +
|
|
177
183
|
"支持 Linux/macOS,需要 Node.js 22.19+ 和 npm。\n--help 显示帮助;--version 显示安装器版本。");
|
|
178
184
|
return 0;
|
|
179
185
|
}
|
|
186
|
+
if (options.action === "upgrade") {
|
|
187
|
+
try { return await runUpgradeCommand(options.upgradeArgs ?? [], options.upgradeVerb ?? "upgrade"); }
|
|
188
|
+
catch (error) { console.error(error instanceof Error ? error.message : String(error)); return 2; }
|
|
189
|
+
}
|
|
180
190
|
if (options.action === "mcp-manage") {
|
|
181
191
|
try { return await runMcpManage(options.mcpArgs ?? []); }
|
|
182
192
|
catch (error) { console.error(error instanceof Error ? error.message : String(error)); return 2; }
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { valid } from "semver";
|
|
6
|
+
import { object } from "../../common/json.js";
|
|
7
|
+
import { checkStableVersion } from "../../common/package-source.js";
|
|
8
|
+
import { packageVersion } from "../../common/version.js";
|
|
9
|
+
import { execCliEntry, upgradeManagedGlobalCli } from "../../integrations/installation/cli-update.js";
|
|
10
|
+
import { findExecutable, SetupProcesses } from "../../integrations/installation/processes.js";
|
|
11
|
+
import { getHostUpgrader } from "../../integrations/installation/upgraders/registry.js";
|
|
12
|
+
import { resolveWorkspace } from "../../integrations/installation/workspace.js";
|
|
13
|
+
import type { CliUpgradeSummary, HostUpgradeResult, WorkspaceUpgradeSummary } from "../../model/installation.js";
|
|
14
|
+
import {
|
|
15
|
+
executeWorkspaceUpgrade,
|
|
16
|
+
parseUpgradeArgs,
|
|
17
|
+
upgradeUsage,
|
|
18
|
+
type WorkspaceUpgradeTarget,
|
|
19
|
+
} from "../../services/installation/upgrade-service.js";
|
|
20
|
+
import { workspacePluginBindings } from "../../services/workspace/plugin-releases.js";
|
|
21
|
+
|
|
22
|
+
const packageRoot = fileURLToPath(new URL("../../../", import.meta.url));
|
|
23
|
+
|
|
24
|
+
async function latestStableVersion(processes: SetupProcesses, cwd: string): Promise<string> {
|
|
25
|
+
const npm = await findExecutable("npm", processes.env);
|
|
26
|
+
if (!npm) throw new Error("未找到 npm,无法查询 personal-bot 最新稳定版。");
|
|
27
|
+
const text = await processes.run(npm, ["view", "personal-bot@latest", "version", "engines", "--json",
|
|
28
|
+
"--fetch-retries=0", "--fetch-timeout=15000"], cwd);
|
|
29
|
+
const value = JSON.parse(text) as { version?: string; engines?: { node?: string } };
|
|
30
|
+
if (typeof value.version !== "string") throw new Error("无法取得 personal-bot 的最新版本。");
|
|
31
|
+
return checkStableVersion(value.version, value.engines?.node);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function discoverWorkspaceTargets(workspace: string, requestedHosts?: readonly string[]): Promise<WorkspaceUpgradeTarget[]> {
|
|
35
|
+
const bindings = workspacePluginBindings(workspace);
|
|
36
|
+
const byHost = new Map<string, WorkspaceUpgradeTarget>();
|
|
37
|
+
for (const [host, entry] of Object.entries(bindings)) {
|
|
38
|
+
byHost.set(host, {
|
|
39
|
+
host,
|
|
40
|
+
currentVersion: entry.version,
|
|
41
|
+
...(entry.bindingPath ? { bindingPath: entry.bindingPath } : {}),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (!byHost.has("pi")) {
|
|
45
|
+
const localPiManifest = join(workspace, ".pi", "npm", "node_modules", "personal-bot", "package.json");
|
|
46
|
+
try {
|
|
47
|
+
const manifest: unknown = JSON.parse(await readFile(localPiManifest, "utf8"));
|
|
48
|
+
if (object(manifest) && manifest.name === "personal-bot" && typeof manifest.version === "string" && valid(manifest.version)) {
|
|
49
|
+
byHost.set("pi", { host: "pi", currentVersion: manifest.version, bindingPath: localPiManifest });
|
|
50
|
+
}
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (requestedHosts) {
|
|
56
|
+
return requestedHosts.map(host => byHost.get(host) ?? { host });
|
|
57
|
+
}
|
|
58
|
+
return [...byHost.values()].sort((a, b) => a.host.localeCompare(b.host));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function formatLine(result: HostUpgradeResult): string {
|
|
62
|
+
const transition = result.previousVersion && result.version && result.previousVersion !== result.version
|
|
63
|
+
? `${result.previousVersion} → ${result.version}`
|
|
64
|
+
: result.version ?? result.previousVersion ?? "";
|
|
65
|
+
const scope = result.scope ? ` (${result.scope})` : "";
|
|
66
|
+
const head = `[${result.state}] ${result.host}${scope}${transition ? " " + transition : ""}: ${result.detail}`;
|
|
67
|
+
return result.nextStep ? `${head}\n 下一步:${result.nextStep}` : head;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function printHumanSummary(summary: WorkspaceUpgradeSummary): void {
|
|
71
|
+
console.log(`工作区:${summary.workspaceRoot}`);
|
|
72
|
+
console.log(`目标版本:${summary.targetVersion}`);
|
|
73
|
+
console.log(`[${summary.cli.state}] cli ${summary.cli.previousVersion} → ${summary.cli.version}: ${summary.cli.detail}`);
|
|
74
|
+
if (!summary.results.length) {
|
|
75
|
+
console.log("当前工作区尚未绑定任何宿主插件。如需指定宿主,可传入 --hosts <宿主列表>。");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
for (const result of summary.results) console.log(formatLine(result));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function runUpgradeCommand(rawArgs: string[], rawVerb: "upgrade" | "update" = "upgrade"): Promise<number> {
|
|
82
|
+
const options = parseUpgradeArgs(rawArgs);
|
|
83
|
+
if (options.help) {
|
|
84
|
+
console.log(upgradeUsage);
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
const controller = new AbortController();
|
|
88
|
+
const cancel = () => controller.abort(new Error("升级已取消。"));
|
|
89
|
+
process.on("SIGINT", cancel);
|
|
90
|
+
process.on("SIGTERM", cancel);
|
|
91
|
+
try {
|
|
92
|
+
const cwd = process.cwd();
|
|
93
|
+
const workspace = await resolveWorkspace(options.workspace ?? cwd, cwd, homedir());
|
|
94
|
+
const processes = new SetupProcesses(controller.signal, process.env);
|
|
95
|
+
const targetVersion = options.version ?? await latestStableVersion(processes, cwd);
|
|
96
|
+
|
|
97
|
+
let cli: CliUpgradeSummary;
|
|
98
|
+
if (process.env.PBOT_UPGRADING_CLI === targetVersion) {
|
|
99
|
+
cli = {
|
|
100
|
+
state: "updated",
|
|
101
|
+
previousVersion: process.env.PBOT_UPGRADING_PREVIOUS_VERSION || packageVersion,
|
|
102
|
+
version: packageVersion,
|
|
103
|
+
detail: `已将全局 CLI 更新到 ${packageVersion}。`,
|
|
104
|
+
};
|
|
105
|
+
} else {
|
|
106
|
+
const cliResult = await upgradeManagedGlobalCli(targetVersion, process.env);
|
|
107
|
+
if (cliResult.state === "updated" && cliResult.globalDirectory) {
|
|
108
|
+
const nextEnv = {
|
|
109
|
+
...process.env,
|
|
110
|
+
PBOT_UPGRADING_CLI: targetVersion,
|
|
111
|
+
PBOT_UPGRADING_PREVIOUS_VERSION: packageVersion,
|
|
112
|
+
};
|
|
113
|
+
return await execCliEntry(join(cliResult.globalDirectory, "bin", "pbot.mjs"), [rawVerb, ...rawArgs], nextEnv);
|
|
114
|
+
}
|
|
115
|
+
cli = {
|
|
116
|
+
state: cliResult.state,
|
|
117
|
+
previousVersion: packageVersion,
|
|
118
|
+
version: packageVersion,
|
|
119
|
+
detail: cliResult.detail,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const targets = await discoverWorkspaceTargets(workspace, options.hosts);
|
|
124
|
+
const summary = await executeWorkspaceUpgrade({
|
|
125
|
+
workspaceRoot: workspace,
|
|
126
|
+
targetVersion,
|
|
127
|
+
cli,
|
|
128
|
+
targets,
|
|
129
|
+
resolveUpgrader: getHostUpgrader,
|
|
130
|
+
createContext: target => ({
|
|
131
|
+
workspace,
|
|
132
|
+
targetVersion,
|
|
133
|
+
...(target.currentVersion ? { currentVersion: target.currentVersion } : {}),
|
|
134
|
+
packageRoot,
|
|
135
|
+
...(target.bindingPath ? { bindingPath: target.bindingPath } : {}),
|
|
136
|
+
env: process.env,
|
|
137
|
+
signal: controller.signal,
|
|
138
|
+
options: { dshProfile: options.dshProfile },
|
|
139
|
+
run: (command, args, runCwd, runOptions) => processes.run(command, args, runCwd, runOptions),
|
|
140
|
+
findExecutable: name => findExecutable(name, process.env),
|
|
141
|
+
}),
|
|
142
|
+
signal: controller.signal,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (options.json) console.log(JSON.stringify(summary, null, 2));
|
|
146
|
+
else printHumanSummary(summary);
|
|
147
|
+
return summary.ok ? 0 : 1;
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (controller.signal.aborted) {
|
|
150
|
+
console.error("升级已取消。");
|
|
151
|
+
return 130;
|
|
152
|
+
}
|
|
153
|
+
throw error;
|
|
154
|
+
} finally {
|
|
155
|
+
process.off("SIGINT", cancel);
|
|
156
|
+
process.off("SIGTERM", cancel);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { mkdir, stat } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { parseArgs } from "node:util";
|
|
6
|
+
import { gte, valid } from "semver";
|
|
7
|
+
import { requireThat } from "../../common/validation.js";
|
|
8
|
+
import { packageVersion } from "../../common/version.js";
|
|
9
|
+
import { getPluginHost, pluginMcpWorkspaceRoot } from "../../integrations/hosts/plugin-registry.js";
|
|
10
|
+
import { minimumCliRelease, runUpdatedCli } from "../../integrations/installation/cli-update.js";
|
|
11
|
+
import { resolveWorkspace } from "../../integrations/installation/workspace.js";
|
|
12
|
+
import { parseHistoryCommand, type ParsedHistoryCommand } from "../../services/history/summary-command.js";
|
|
13
|
+
import { workspacePluginDrift, workspacePluginReleases } from "../../services/workspace/plugin-releases.js";
|
|
14
|
+
import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../services/workspace/workspace-config.js";
|
|
15
|
+
import { initializeWorkspace } from "../../services/workspace/workspace-preparation.js";
|
|
16
|
+
|
|
17
|
+
const usage = `pbot init | status [--workspace <目录>] [--json]
|
|
18
|
+
pbot history status | list
|
|
19
|
+
pbot history summary [维度...] [--force] [--backend <acp>] [--model <模型>] [--thinking <级别>]
|
|
20
|
+
pbot history migrate [--dry-run]
|
|
21
|
+
pbot history search [关键词] [--host <来源>] [--dimension <维度>] [--session-id <ID>] [--from <时间>] [--to <时间>] [--offset N] [--limit N]
|
|
22
|
+
pbot history read <节点ID> [--host <来源>] [--offset N] [--limit N] [--children-offset N]
|
|
23
|
+
所有工作区命令支持 --workspace <目录> 和 --json。默认工作区为当前目录。`;
|
|
24
|
+
|
|
25
|
+
function workspaceArgs(args: readonly string[]) {
|
|
26
|
+
const rest: string[] = [];
|
|
27
|
+
let workspace: string | undefined;
|
|
28
|
+
let json = false;
|
|
29
|
+
for (let index = 0; index < args.length; index++) {
|
|
30
|
+
const token = args[index]!;
|
|
31
|
+
if (token === "--") { rest.push(...args.slice(index)); break; }
|
|
32
|
+
if (token === "--workspace" || token.startsWith("--workspace=")) {
|
|
33
|
+
requireThat(workspace === undefined, "--workspace 只能指定一次。");
|
|
34
|
+
workspace = token === "--workspace" ? args[++index] : token.slice("--workspace=".length);
|
|
35
|
+
requireThat(workspace && !workspace.startsWith("-"), "--workspace 需要目录。");
|
|
36
|
+
} else if (token === "--json") json = true;
|
|
37
|
+
else rest.push(token);
|
|
38
|
+
}
|
|
39
|
+
return { workspace, json, rest };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function historyAction(args: string[]): ParsedHistoryCommand {
|
|
43
|
+
const [action, ...rest] = args;
|
|
44
|
+
if (action !== "search" && action !== "read") return parseHistoryCommand(args);
|
|
45
|
+
const string = { type: "string" } as const;
|
|
46
|
+
const { values, positionals } = parseArgs({
|
|
47
|
+
args: rest, allowPositionals: true,
|
|
48
|
+
options: {
|
|
49
|
+
host: string, offset: string, limit: string,
|
|
50
|
+
...(action === "search" ? { dimension: string, "session-id": string, from: string, to: string } : { "children-offset": string }),
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
requireThat(positionals.length <= 1 && (action === "search" || positionals[0]), usage);
|
|
54
|
+
const input: Record<string, unknown> = { action };
|
|
55
|
+
if (positionals.length) input[action === "search" ? "query" : "id"] = positionals[0];
|
|
56
|
+
for (const [key, value] of Object.entries(values)) {
|
|
57
|
+
if (["offset", "limit", "children-offset"].includes(key)) {
|
|
58
|
+
requireThat(typeof value === "string" && /^\d+$/.test(value) && Number.isSafeInteger(Number(value)), "--" + key + " 需要非负整数。");
|
|
59
|
+
input[key === "children-offset" ? "childrenOffset" : key] = Number(value);
|
|
60
|
+
} else input[key === "session-id" ? "sessionId" : key] = value;
|
|
61
|
+
}
|
|
62
|
+
return { kind: "query", input };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function updateForWorkspace(root: string, args: string[], input?: string): Promise<number | undefined> {
|
|
66
|
+
return runUpdatedCli(await minimumCliRelease(root, workspacePluginReleases(root)), args, input);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Hook workspaces are resolved by the adapter from the event on stdin. */
|
|
70
|
+
export async function updateForCommand(args: string[]): Promise<number | undefined> {
|
|
71
|
+
if (args[0] === "plugin" && args[2] === "hook") return undefined;
|
|
72
|
+
const cwd = process.cwd();
|
|
73
|
+
let workspace: string;
|
|
74
|
+
if (args[0] === "plugin" && args[1]) {
|
|
75
|
+
workspace = await getPluginHost(args[1])?.resolveRoot(cwd) ?? cwd;
|
|
76
|
+
} else if (args[0] === "mcp" && args.length === 1) {
|
|
77
|
+
workspace = pluginMcpWorkspaceRoot() ?? cwd;
|
|
78
|
+
} else {
|
|
79
|
+
workspace = workspaceArgs(args).workspace ?? cwd;
|
|
80
|
+
}
|
|
81
|
+
const root = await resolveWorkspace(workspace, cwd, homedir());
|
|
82
|
+
const configuration = await readWorkspaceConfig(root);
|
|
83
|
+
const initializing = args[0] === "plugin" && args[2] === "init" && args.length === 3;
|
|
84
|
+
if (!configuration.enabled && !(initializing && !configuration.error)) return undefined;
|
|
85
|
+
return updateForWorkspace(root, args);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function main(args: string[]): Promise<number> {
|
|
89
|
+
if (args[0] === "--at-least") {
|
|
90
|
+
const version = args[1];
|
|
91
|
+
requireThat(args.length === 2 && version && valid(version), "用法:pbot --at-least <MAJOR.MINOR.PATCH>");
|
|
92
|
+
return gte(packageVersion, version) ? 0 : 1;
|
|
93
|
+
}
|
|
94
|
+
const { workspace, json, rest } = workspaceArgs(args);
|
|
95
|
+
const [verb, ...tail] = rest;
|
|
96
|
+
const delimiter = rest.indexOf("--");
|
|
97
|
+
if (rest.slice(0, delimiter < 0 ? rest.length : delimiter).some(token => token === "--help" || token === "-h")) {
|
|
98
|
+
console.log(usage);
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
requireThat(verb === "history" || ["init", "status", "--version", "-v"].includes(verb ?? "") && !tail.length, usage);
|
|
102
|
+
if (verb === "--version" || verb === "-v") { console.log(packageVersion); return 0; }
|
|
103
|
+
const cwd = process.cwd();
|
|
104
|
+
const root = await resolveWorkspace(workspace ?? cwd, cwd, homedir());
|
|
105
|
+
let configuration = await readWorkspaceConfig(root);
|
|
106
|
+
if (verb === "init" && configuration.error) throw new Error(configuration.error);
|
|
107
|
+
if (verb === "history") {
|
|
108
|
+
requireThat(configuration.enabled, workspaceDisabledMessage(configuration));
|
|
109
|
+
requireThat(workspaceFeatures(configuration).history, "当前工作区已停用历史功能(features.history: false)。");
|
|
110
|
+
}
|
|
111
|
+
const checkRelease = configuration.enabled || verb === "init";
|
|
112
|
+
const plugins = checkRelease ? workspacePluginReleases(root) : {};
|
|
113
|
+
const required = checkRelease ? await minimumCliRelease(root, plugins) : undefined;
|
|
114
|
+
const updated = await runUpdatedCli(required, args);
|
|
115
|
+
if (updated !== undefined) return updated;
|
|
116
|
+
const print = (result: unknown) => console.log(JSON.stringify(result, null, json ? undefined : 2));
|
|
117
|
+
if (verb === "init") {
|
|
118
|
+
await mkdir(root, { recursive: true });
|
|
119
|
+
await initializeWorkspace(root);
|
|
120
|
+
configuration = await readWorkspaceConfig(root);
|
|
121
|
+
}
|
|
122
|
+
requireThat((await stat(root)).isDirectory(), "工作区必须是目录。");
|
|
123
|
+
if (verb !== "history") {
|
|
124
|
+
const drift = workspacePluginDrift(plugins);
|
|
125
|
+
print({
|
|
126
|
+
workspaceRoot: root,
|
|
127
|
+
version: packageVersion,
|
|
128
|
+
plugins,
|
|
129
|
+
outOfSync: drift.outOfSync,
|
|
130
|
+
minimumCliVersion: required ?? null,
|
|
131
|
+
configuration,
|
|
132
|
+
});
|
|
133
|
+
return configuration.error ? 1 : 0;
|
|
134
|
+
}
|
|
135
|
+
const command = historyAction(tail);
|
|
136
|
+
const controller = new AbortController();
|
|
137
|
+
let exitCode = 0;
|
|
138
|
+
const interrupt = () => { exitCode = 130; controller.abort(); };
|
|
139
|
+
const terminate = () => { exitCode = 143; controller.abort(); };
|
|
140
|
+
process.on("SIGINT", interrupt);
|
|
141
|
+
process.on("SIGTERM", terminate);
|
|
142
|
+
try {
|
|
143
|
+
const { runHistoryCommand } = await import("../history/command.js");
|
|
144
|
+
const result = await runHistoryCommand({ root, features: workspaceFeatures(configuration) }, command, controller.signal, {
|
|
145
|
+
start: backend => console.error("历史摘要生成中 (" + backend + ")"),
|
|
146
|
+
update: event => console.error(`${event.dimension} ${event.completed}/${event.total}`),
|
|
147
|
+
});
|
|
148
|
+
print(result);
|
|
149
|
+
if ("backend" in result && result.dimensions.some(dimension => dimension.failed.length)) return 1;
|
|
150
|
+
if ("errors" in result && (result.errors.length || result.skipped.length)) return 1;
|
|
151
|
+
return 0;
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (!exitCode) throw error;
|
|
154
|
+
console.error("历史操作已取消。");
|
|
155
|
+
return exitCode;
|
|
156
|
+
} finally {
|
|
157
|
+
process.off("SIGINT", interrupt);
|
|
158
|
+
process.off("SIGTERM", terminate);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
|
|
163
|
+
main(process.argv.slice(2)).then(code => { process.exitCode = code; }).catch(error => {
|
|
164
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
165
|
+
process.exitCode = 1;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
@@ -2,8 +2,7 @@ import { fork, spawnSync } from "node:child_process";
|
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
4
|
import { setTimeout as delay } from "node:timers/promises";
|
|
5
|
-
import type { AgentHost } from "../../
|
|
6
|
-
import type { AgentDescriptor, AgentOptions, AgentSessionReference } from "../../model/agent.js";
|
|
5
|
+
import type { AgentHost, AgentDescriptor, AgentOptions, AgentSessionReference } from "../../model/agent.js";
|
|
7
6
|
import type { AcpBackend, AcpCommands, AcpModelsResult } from "../../model/acp.js";
|
|
8
7
|
import { AgentFiles, launch } from "../../storage/agent-files.js";
|
|
9
8
|
import { acpInput, acpProcess, acpReport } from "../../storage/acp-files.js";
|
|
@@ -17,7 +16,7 @@ export class AcpWorkerHost implements AgentHost {
|
|
|
17
16
|
readonly files: AgentFiles;
|
|
18
17
|
readonly worker = resolve(resourceRoot, "../lib/extension/acp-worker.js");
|
|
19
18
|
|
|
20
|
-
constructor(directory: string,
|
|
19
|
+
constructor(directory: string, public commands: AcpCommands = {}) {
|
|
21
20
|
this.files = new AgentFiles(directory);
|
|
22
21
|
}
|
|
23
22
|
|
|
@@ -20,7 +20,7 @@ export const dshAcpHarness: AcpHarnessAdapter = {
|
|
|
20
20
|
const patch = join(context.directory, "acp-dsh-patch.json");
|
|
21
21
|
await writeFile(
|
|
22
22
|
patch,
|
|
23
|
-
JSON.stringify([{ insert: [{ id: "pbot-acp-member", name: join(context.packageRoot, "lib/extension/hosts/dsh/acp-
|
|
23
|
+
JSON.stringify([{ insert: [{ id: "pbot-acp-member", name: join(context.packageRoot, "lib/extension/hosts/dsh/acp-entry.js") }] }]) + "\n",
|
|
24
24
|
{ mode: 0o600 },
|
|
25
25
|
);
|
|
26
26
|
return {
|
|
@@ -11,6 +11,14 @@ export const standardAcpPresets: readonly AcpHarnessAdapter[] = [
|
|
|
11
11
|
configureHint: "运行 agy 完成登录与默认模型配置。",
|
|
12
12
|
nativeWorkspaceSkills: true,
|
|
13
13
|
}),
|
|
14
|
+
createGenericAcpHarness("qoder", {
|
|
15
|
+
label: "Qoder CLI",
|
|
16
|
+
aliases: ["qodercli", "qoder-cli"],
|
|
17
|
+
nativeWorkspaceSkills: true,
|
|
18
|
+
defaultCommand: { command: "qodercli", args: ["--acp"] },
|
|
19
|
+
installHint: "安装 Qoder CLI(qodercli)",
|
|
20
|
+
configureHint: "运行 qodercli login 完成登录。",
|
|
21
|
+
}),
|
|
14
22
|
createGenericAcpHarness("codex", {
|
|
15
23
|
label: "OpenAI Codex",
|
|
16
24
|
aliases: ["openai-codex", "codex-cli"],
|
|
@@ -31,11 +31,12 @@ export function createAcpHistorySummarizer(options: AcpHistorySummarizerOptions)
|
|
|
31
31
|
|
|
32
32
|
const commands = options.commands ?? {};
|
|
33
33
|
const backend = canonicalAcpBackend(options.backend ?? "pi", commands);
|
|
34
|
-
|
|
34
|
+
let resolvedReference: ReturnType<typeof acpLaunch> | undefined;
|
|
35
35
|
const timeoutMs = options.timeoutMs ?? defaultTimeoutMs;
|
|
36
36
|
|
|
37
37
|
return async (request, signal) => {
|
|
38
38
|
signal.throwIfAborted();
|
|
39
|
+
const reference = (resolvedReference ??= acpLaunch(backend, commands, {}));
|
|
39
40
|
return await new Promise<string>((resolveAnswer, reject) => {
|
|
40
41
|
const child = fork(workerPath, ["--prompt"], {
|
|
41
42
|
cwd: options.cwd,
|
|
@@ -37,7 +37,7 @@ export async function agentText(
|
|
|
37
37
|
export function formatWorkspaceSkills(skills: readonly WorkspaceSkillMeta[]): string {
|
|
38
38
|
if (!skills.length) return "";
|
|
39
39
|
const lines = skills.map(skill => `- **${skill.name}**(\`${skill.path}\`):${skill.description}`);
|
|
40
|
-
return "## 工作区技能\n\n
|
|
40
|
+
return "## 工作区技能\n\n匹配任务时按需读取对应 `SKILL.md` 正文:\n" + lines.join("\n");
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export async function loadWorkspaceContext(options: {
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import { realpath, stat } from "node:fs/promises";
|
|
2
|
-
import { isAbsolute } from "node:path";
|
|
3
1
|
import { object } from "../../../common/json.js";
|
|
4
2
|
import { requireThat } from "../../../common/validation.js";
|
|
5
3
|
import type { HostEvent, PluginHostAdapter } from "../../../model/plugin-host.js";
|
|
4
|
+
import { parsePromptEvent, pluginWorkspaceRoot, promptHooks } from "../prompt-hooks.js";
|
|
6
5
|
|
|
7
6
|
const supportedEvents = ["UserPromptSubmit", "PreToolUse", "UserPromptExpansion", "Stop"];
|
|
7
|
+
const boundWorkspaceRoot = () => process.env.CLAUDE_PROJECT_DIR;
|
|
8
8
|
|
|
9
|
-
export async function claudeWorkspaceRoot(cwd: string, projectDirectory =
|
|
10
|
-
|
|
11
|
-
requireThat(isAbsolute(directory), "Claude 工作区需要绝对路径。");
|
|
12
|
-
const root = await realpath(directory);
|
|
13
|
-
requireThat((await stat(root)).isDirectory(), "Claude 工作区需要目录。");
|
|
14
|
-
return root;
|
|
9
|
+
export async function claudeWorkspaceRoot(cwd: string, projectDirectory = boundWorkspaceRoot()): Promise<string> {
|
|
10
|
+
return pluginWorkspaceRoot(projectDirectory || cwd);
|
|
15
11
|
}
|
|
16
12
|
|
|
17
13
|
export const claudeAdapter: PluginHostAdapter = {
|
|
@@ -21,6 +17,7 @@ export const claudeAdapter: PluginHostAdapter = {
|
|
|
21
17
|
coordinatorPrompt: "plugin-coordinator.md",
|
|
22
18
|
initCommandHint: "/personal-bot:pbot init",
|
|
23
19
|
usage: "用法:node <插件目录>/lib/claude.js init|status",
|
|
20
|
+
boundWorkspaceRoot,
|
|
24
21
|
resolveRoot(cwd) {
|
|
25
22
|
return claudeWorkspaceRoot(cwd);
|
|
26
23
|
},
|
|
@@ -36,50 +33,7 @@ export const claudeAdapter: PluginHostAdapter = {
|
|
|
36
33
|
requireThat(typeof value.cwd === "string", "Claude hook 缺少工作目录。");
|
|
37
34
|
return { kind: "check-skill", skill, cwd: value.cwd, raw: value };
|
|
38
35
|
}
|
|
39
|
-
|
|
40
|
-
if (typeof value.agent_id === "string") return { kind: "ignore" };
|
|
41
|
-
requireThat(typeof value.cwd === "string", "Claude hook 缺少工作目录。");
|
|
42
|
-
if (event === "Stop") return { kind: "record-history", cwd: value.cwd, raw: value };
|
|
43
|
-
return { kind: "inject-context", role: "coordinator", cwd: value.cwd, raw: value };
|
|
44
|
-
},
|
|
45
|
-
async extractHistory(event) {
|
|
46
|
-
if (!object(event.raw)) return undefined;
|
|
47
|
-
const sessionId = typeof event.raw.session_id === "string" ? event.raw.session_id.trim() : "";
|
|
48
|
-
if (!sessionId) return undefined;
|
|
49
|
-
if (event.raw.hook_event_name === "UserPromptSubmit") {
|
|
50
|
-
const text = typeof event.raw.prompt === "string" ? event.raw.prompt.trim() : "";
|
|
51
|
-
if (!text) return undefined;
|
|
52
|
-
return { kind: "input", sessionId, text };
|
|
53
|
-
}
|
|
54
|
-
if (event.raw.hook_event_name === "Stop") {
|
|
55
|
-
const assistantText = typeof event.raw.last_assistant_message === "string" ? event.raw.last_assistant_message.trim() : "";
|
|
56
|
-
if (!assistantText) return undefined;
|
|
57
|
-
return {
|
|
58
|
-
kind: "answer",
|
|
59
|
-
sessionId,
|
|
60
|
-
assistantText,
|
|
61
|
-
completed: true,
|
|
62
|
-
...(event.raw.stop_hook_active === true ? { isContinuation: true } : {}),
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
return undefined;
|
|
66
|
-
},
|
|
67
|
-
formatPass() {
|
|
68
|
-
return {};
|
|
69
|
-
},
|
|
70
|
-
formatContext(event, context) {
|
|
71
|
-
const raw = event.raw as { hook_event_name: string };
|
|
72
|
-
return {
|
|
73
|
-
hookSpecificOutput: {
|
|
74
|
-
hookEventName: raw.hook_event_name,
|
|
75
|
-
additionalContext: context.text,
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
formatDeny(event, reason) {
|
|
80
|
-
const raw = event.raw as { hook_event_name: string };
|
|
81
|
-
return raw.hook_event_name === "UserPromptExpansion"
|
|
82
|
-
? { decision: "block", reason }
|
|
83
|
-
: { hookSpecificOutput: { hookEventName: raw.hook_event_name, permissionDecision: "deny", permissionDecisionReason: reason } };
|
|
36
|
+
return parsePromptEvent(value);
|
|
84
37
|
},
|
|
38
|
+
...promptHooks,
|
|
85
39
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PluginHostAdapter } from "../../../model/plugin-host.js";
|
|
2
|
+
import { parsePromptEvent, pluginWorkspaceRoot, promptHooks } from "../prompt-hooks.js";
|
|
3
|
+
|
|
4
|
+
export const codexAdapter: PluginHostAdapter = {
|
|
5
|
+
host: "codex",
|
|
6
|
+
nativeRootAgents: true,
|
|
7
|
+
nativeWorkspaceSkills: true,
|
|
8
|
+
indexBundledSkills: true,
|
|
9
|
+
initCommandHint: "pbot plugin codex init",
|
|
10
|
+
usage: "用法:pbot plugin codex init|status",
|
|
11
|
+
resolveRoot(cwd) {
|
|
12
|
+
return pluginWorkspaceRoot(cwd);
|
|
13
|
+
},
|
|
14
|
+
parseEvent: parsePromptEvent,
|
|
15
|
+
...promptHooks,
|
|
16
|
+
};
|
|
@@ -2,6 +2,8 @@ import { requireThat } from "../../common/validation.js";
|
|
|
2
2
|
import type { PluginHostAdapter, PluginHostId } from "../../model/plugin-host.js";
|
|
3
3
|
import { antigravityAdapter } from "./antigravity/adapter.js";
|
|
4
4
|
import { claudeAdapter } from "./claude/adapter.js";
|
|
5
|
+
import { codexAdapter } from "./codex/adapter.js";
|
|
6
|
+
import { qoderAdapter } from "./qoder/adapter.js";
|
|
5
7
|
|
|
6
8
|
/** Extensible registry of hook-based plugin host adapters; runtime never branches on host IDs. */
|
|
7
9
|
export class PluginHostRegistry {
|
|
@@ -36,7 +38,13 @@ export class PluginHostRegistry {
|
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
export const pluginHosts = new PluginHostRegistry([claudeAdapter, antigravityAdapter]);
|
|
41
|
+
export const pluginHosts = new PluginHostRegistry([claudeAdapter, antigravityAdapter, codexAdapter, qoderAdapter]);
|
|
40
42
|
export const registerPluginHost = (adapter: PluginHostAdapter) => pluginHosts.register(adapter);
|
|
41
43
|
export const getPluginHost = (host: PluginHostId) => pluginHosts.get(host);
|
|
42
44
|
export const listPluginHosts = () => pluginHosts.list();
|
|
45
|
+
|
|
46
|
+
export function pluginMcpWorkspaceRoot(): string | undefined {
|
|
47
|
+
// Older standalone Claude mounts supply the project directory without PBOT_HOST.
|
|
48
|
+
const adapter = process.env.PBOT_HOST ? pluginHosts.get(process.env.PBOT_HOST) : claudeAdapter;
|
|
49
|
+
return adapter?.boundWorkspaceRoot?.() || process.env.PBOT_WORKSPACE_ROOT;
|
|
50
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
/** Shared stdin/stdout contract for hosts with Claude-compatible prompt and stop hooks. */
|
|
8
|
+
export async function pluginWorkspaceRoot(directory: string): Promise<string> {
|
|
9
|
+
requireThat(isAbsolute(directory), "插件工作区需要绝对路径。");
|
|
10
|
+
const root = await realpath(directory);
|
|
11
|
+
requireThat((await stat(root)).isDirectory(), "插件工作区需要目录。");
|
|
12
|
+
return root;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function parsePromptEvent(value: unknown): HostEvent {
|
|
16
|
+
requireThat(object(value), "插件 hook 输入无效。");
|
|
17
|
+
const name = value.hook_event_name;
|
|
18
|
+
if (name !== "Stop" && name !== "UserPromptSubmit" && name !== "SessionStart") return { kind: "ignore" };
|
|
19
|
+
if (typeof value.agent_id === "string") return { kind: "ignore" };
|
|
20
|
+
requireThat(typeof value.cwd === "string", "插件 hook 缺少工作目录。");
|
|
21
|
+
if (name === "Stop") return { kind: "record-history", cwd: value.cwd, raw: value };
|
|
22
|
+
if (name === "SessionStart") {
|
|
23
|
+
if (value.source === "resume" || value.source === "compact") return { kind: "ignore" };
|
|
24
|
+
return { kind: "inject-context", role: "coordinator", isSessionStart: true, noticesOnly: true, cwd: value.cwd, raw: value };
|
|
25
|
+
}
|
|
26
|
+
return { kind: "inject-context", role: "coordinator", cwd: value.cwd, raw: value };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const promptHooks = {
|
|
30
|
+
async extractHistory(event) {
|
|
31
|
+
if (!object(event.raw)) return undefined;
|
|
32
|
+
const sessionId = typeof event.raw.session_id === "string" ? event.raw.session_id.trim() : "";
|
|
33
|
+
if (!sessionId) return undefined;
|
|
34
|
+
const turnId = typeof event.raw.turn_id === "string" ? event.raw.turn_id.trim() : "";
|
|
35
|
+
const identity = turnId ? { sessionId, turnId } : { sessionId };
|
|
36
|
+
if (event.raw.hook_event_name === "UserPromptSubmit") {
|
|
37
|
+
const text = typeof event.raw.prompt === "string" ? event.raw.prompt.trim() : "";
|
|
38
|
+
if (!text && !turnId) return undefined;
|
|
39
|
+
return { kind: "input", ...identity, text };
|
|
40
|
+
}
|
|
41
|
+
if (event.raw.hook_event_name === "Stop") {
|
|
42
|
+
const assistantText = typeof event.raw.last_assistant_message === "string" ? event.raw.last_assistant_message.trim() : "";
|
|
43
|
+
if (!assistantText) return undefined;
|
|
44
|
+
return {
|
|
45
|
+
kind: "answer",
|
|
46
|
+
...identity,
|
|
47
|
+
assistantText,
|
|
48
|
+
completed: true,
|
|
49
|
+
...(event.raw.stop_hook_active === true ? { isContinuation: true } : {}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
},
|
|
54
|
+
formatPass() {
|
|
55
|
+
return {};
|
|
56
|
+
},
|
|
57
|
+
formatContext(event, context) {
|
|
58
|
+
const raw = event.raw as { hook_event_name: string };
|
|
59
|
+
return {
|
|
60
|
+
hookSpecificOutput: {
|
|
61
|
+
hookEventName: raw.hook_event_name,
|
|
62
|
+
additionalContext: context.text,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
formatDeny(event, reason) {
|
|
67
|
+
const raw = event.raw as { hook_event_name: string };
|
|
68
|
+
return raw.hook_event_name === "UserPromptExpansion"
|
|
69
|
+
? { decision: "block", reason }
|
|
70
|
+
: { hookSpecificOutput: { hookEventName: raw.hook_event_name, permissionDecision: "deny", permissionDecisionReason: reason } };
|
|
71
|
+
},
|
|
72
|
+
} satisfies Pick<PluginHostAdapter, "extractHistory" | "formatPass" | "formatContext" | "formatDeny">;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PluginHostAdapter } from "../../../model/plugin-host.js";
|
|
2
|
+
import { parsePromptEvent, pluginWorkspaceRoot, promptHooks } from "../prompt-hooks.js";
|
|
3
|
+
|
|
4
|
+
const boundWorkspaceRoot = () => process.env.QODER_PROJECT_DIR || process.env.PBOT_WORKSPACE_ROOT;
|
|
5
|
+
|
|
6
|
+
export const qoderAdapter: PluginHostAdapter = {
|
|
7
|
+
host: "qoder",
|
|
8
|
+
nativeRootAgents: true,
|
|
9
|
+
nativeWorkspaceSkills: true,
|
|
10
|
+
indexBundledSkills: true,
|
|
11
|
+
initCommandHint: "pbot plugin qoder init",
|
|
12
|
+
usage: "用法:pbot plugin qoder init|status",
|
|
13
|
+
boundWorkspaceRoot,
|
|
14
|
+
resolveRoot(cwd) {
|
|
15
|
+
return pluginWorkspaceRoot(boundWorkspaceRoot() || cwd);
|
|
16
|
+
},
|
|
17
|
+
parseEvent: parsePromptEvent,
|
|
18
|
+
...promptHooks,
|
|
19
|
+
};
|