personal-bot 0.3.2 → 0.3.3
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 +8 -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 +7 -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 +31 -23
- 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 +20127 -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 +3 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +78 -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 +31 -23
- 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 +3 -0
- package/lib/extension/workspace-cli.js +20127 -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/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/workspace/plugin-releases.d.ts +3 -0
- package/lib/services/workspace/plugin-releases.js +78 -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 +32 -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 +4 -1
- package/src/extension/setup/workspace-cli.ts +159 -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 +116 -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/model/acp.ts +11 -3
- package/src/model/agent.ts +20 -4
- package/src/model/history.ts +5 -0
- package/src/model/installation.ts +41 -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 +2 -41
- package/src/services/workspace/plugin-releases.ts +68 -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";
|
|
@@ -168,7 +168,10 @@ export async function main(args: string[]): Promise<number> {
|
|
|
168
168
|
if (options.action === "help") {
|
|
169
169
|
console.log("Personal Bot " + manifest.version + "\n\n用法:pbot setup [--workspace <目录>]\n" +
|
|
170
170
|
" npx personal-bot@latest setup\n" +
|
|
171
|
+
" pbot init | status [--workspace <目录>] [--json]\n" +
|
|
172
|
+
" pbot history status|list|summary|migrate|search|read [参数] [--workspace <目录>] [--json]\n" +
|
|
171
173
|
" pbot install-antigravity\n" +
|
|
174
|
+
" pbot plugin <host> hook|init|status\n" +
|
|
172
175
|
" pbot mcp\n" +
|
|
173
176
|
" pbot mcp list|add|remove ...\n\n" +
|
|
174
177
|
"setup 安装或升级 Pi、pbot 和选中的插件,然后启动 Pi 执行 /pbot init。\n" +
|
|
@@ -0,0 +1,159 @@
|
|
|
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 { 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
|
+
print({ workspaceRoot: root, version: packageVersion, plugins, minimumCliVersion: required ?? null, configuration });
|
|
125
|
+
return configuration.error ? 1 : 0;
|
|
126
|
+
}
|
|
127
|
+
const command = historyAction(tail);
|
|
128
|
+
const controller = new AbortController();
|
|
129
|
+
let exitCode = 0;
|
|
130
|
+
const interrupt = () => { exitCode = 130; controller.abort(); };
|
|
131
|
+
const terminate = () => { exitCode = 143; controller.abort(); };
|
|
132
|
+
process.on("SIGINT", interrupt);
|
|
133
|
+
process.on("SIGTERM", terminate);
|
|
134
|
+
try {
|
|
135
|
+
const { runHistoryCommand } = await import("../history/command.js");
|
|
136
|
+
const result = await runHistoryCommand({ root, features: workspaceFeatures(configuration) }, command, controller.signal, {
|
|
137
|
+
start: backend => console.error("历史摘要生成中 (" + backend + ")"),
|
|
138
|
+
update: event => console.error(`${event.dimension} ${event.completed}/${event.total}`),
|
|
139
|
+
});
|
|
140
|
+
print(result);
|
|
141
|
+
if ("backend" in result && result.dimensions.some(dimension => dimension.failed.length)) return 1;
|
|
142
|
+
if ("errors" in result && (result.errors.length || result.skipped.length)) return 1;
|
|
143
|
+
return 0;
|
|
144
|
+
} catch (error) {
|
|
145
|
+
if (!exitCode) throw error;
|
|
146
|
+
console.error("历史操作已取消。");
|
|
147
|
+
return exitCode;
|
|
148
|
+
} finally {
|
|
149
|
+
process.off("SIGINT", interrupt);
|
|
150
|
+
process.off("SIGTERM", terminate);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
|
|
155
|
+
main(process.argv.slice(2)).then(code => { process.exitCode = code; }).catch(error => {
|
|
156
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
157
|
+
process.exitCode = 1;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { execFile, spawn } from "node:child_process";
|
|
2
|
+
import { lstat, mkdir, readFile, realpath, rmdir } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import { gt, lt, valid } from "semver";
|
|
7
|
+
import { object } from "../../common/json.js";
|
|
8
|
+
import { resourceRoot } from "../../common/paths.js";
|
|
9
|
+
import { requireThat } from "../../common/validation.js";
|
|
10
|
+
import { packageVersion } from "../../common/version.js";
|
|
11
|
+
|
|
12
|
+
/** Check exact installed manifests, never resolve dependencies in an ancestor workspace. */
|
|
13
|
+
export async function minimumCliRelease(root: string, plugins: Record<string, string>): Promise<string | undefined> {
|
|
14
|
+
const versions = Object.values(plugins);
|
|
15
|
+
if (process.env.PBOT_PLUGIN_VERSION) versions.push(process.env.PBOT_PLUGIN_VERSION);
|
|
16
|
+
for (const prefix of ["", ".pi/npm"]) {
|
|
17
|
+
const path = join(root, prefix, "node_modules/personal-bot/package.json");
|
|
18
|
+
try {
|
|
19
|
+
const manifest: unknown = JSON.parse(await readFile(path, "utf8"));
|
|
20
|
+
requireThat(object(manifest) && manifest.name === "personal-bot" && typeof manifest.version === "string",
|
|
21
|
+
"无效的 personal-bot 安装清单:" + path);
|
|
22
|
+
versions.push(manifest.version);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
let required: string | undefined;
|
|
28
|
+
for (const version of versions) {
|
|
29
|
+
requireThat(valid(version) && /^[0-9]/.test(version) && version === version.trim(), "无效的插件发布版本:" + version);
|
|
30
|
+
if (!required || gt(version, required)) required = version;
|
|
31
|
+
}
|
|
32
|
+
return required;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function runProgram(command: string, args: string[], env: NodeJS.ProcessEnv, install = false, input?: string): Promise<number> {
|
|
36
|
+
const child = spawn(command, args, install
|
|
37
|
+
? { cwd: homedir(), stdio: ["ignore", 2, 2], env }
|
|
38
|
+
: { stdio: input === undefined ? "inherit" : ["pipe", "inherit", "inherit"], env });
|
|
39
|
+
const interrupt = () => child.kill("SIGINT");
|
|
40
|
+
const terminate = () => child.kill("SIGTERM");
|
|
41
|
+
process.on("SIGINT", interrupt);
|
|
42
|
+
process.on("SIGTERM", terminate);
|
|
43
|
+
try {
|
|
44
|
+
return await new Promise<number>((resolveCode, reject) => {
|
|
45
|
+
child.once("error", reject);
|
|
46
|
+
child.once("close", (code, signal) => resolveCode(code ?? (signal === "SIGINT" ? 130 : 143)));
|
|
47
|
+
if (input !== undefined && child.stdin) {
|
|
48
|
+
child.stdin.on("error", (error: NodeJS.ErrnoException) => { if (error.code !== "EPIPE") reject(error); });
|
|
49
|
+
child.stdin.end(input);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
} finally {
|
|
53
|
+
process.off("SIGINT", interrupt);
|
|
54
|
+
process.off("SIGTERM", terminate);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function globalPackage(): Promise<string | undefined> {
|
|
59
|
+
const { stdout } = await promisify(execFile)("npm", ["root", "--global"], { cwd: homedir() });
|
|
60
|
+
const directory = join(stdout.trim(), "personal-bot");
|
|
61
|
+
try {
|
|
62
|
+
// An npm link points at a development checkout; keep updates out of that checkout.
|
|
63
|
+
if ((await lstat(directory)).isDirectory() && await realpath(directory) === await realpath(resolve(resourceRoot, ".."))) return directory;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function upgradeGlobal(directory: string, required: string, env: NodeJS.ProcessEnv): Promise<number | undefined> {
|
|
71
|
+
const lib = dirname(dirname(directory));
|
|
72
|
+
const lock = join(lib, ".pbot-cli-update.lock");
|
|
73
|
+
try { await mkdir(lock); }
|
|
74
|
+
catch (error) {
|
|
75
|
+
// A read-only prefix or an active updater can still use npm's per-user versioned cache.
|
|
76
|
+
if (["EEXIST", "EACCES", "EPERM", "EROFS"].includes((error as NodeJS.ErrnoException).code ?? "")) return undefined;
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
const installedVersion = async () => {
|
|
80
|
+
const installed: unknown = JSON.parse(await readFile(join(directory, "package.json"), "utf8"));
|
|
81
|
+
requireThat(object(installed) && installed.name === "personal-bot" && typeof installed.version === "string" && valid(installed.version),
|
|
82
|
+
"全局 CLI 安装清单无效:" + directory);
|
|
83
|
+
return installed.version;
|
|
84
|
+
};
|
|
85
|
+
try {
|
|
86
|
+
if (lt(await installedVersion(), required)) {
|
|
87
|
+
const code = await runProgram("npm", ["install", "--global", "--prefix", dirname(lib), "--ignore-scripts",
|
|
88
|
+
"--no-audit", "--no-fund", "--prefer-offline", "personal-bot@" + required], env, true);
|
|
89
|
+
if (code) return code;
|
|
90
|
+
requireThat(!lt(await installedVersion(), required), "npm 更新后的 CLI 低于插件所需版本:" + required);
|
|
91
|
+
}
|
|
92
|
+
return 0;
|
|
93
|
+
} finally {
|
|
94
|
+
await rmdir(lock);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Upgrade managed global installs in place. Project, npx and linked installs use npm's shared version cache. */
|
|
99
|
+
export async function runUpdatedCli(required: string | undefined, args: readonly string[], input?: string): Promise<number | undefined> {
|
|
100
|
+
if (!required) return undefined;
|
|
101
|
+
requireThat(valid(required) && /^[0-9]/.test(required) && required === required.trim(), "无效的插件发布版本:" + required);
|
|
102
|
+
if (!lt(packageVersion, required)) return undefined;
|
|
103
|
+
requireThat(process.env.PBOT_CLI_UPDATING !== required,
|
|
104
|
+
`npm 启动了 CLI ${packageVersion},工作区插件需要 ${required}。`);
|
|
105
|
+
console.error(`工作区需要 Personal Bot CLI ${required},正在更新 ${packageVersion}。`);
|
|
106
|
+
const env = { ...process.env, PBOT_CLI_UPDATING: required };
|
|
107
|
+
const global = await globalPackage();
|
|
108
|
+
if (global) {
|
|
109
|
+
const status = await upgradeGlobal(global, required, env);
|
|
110
|
+
if (status !== undefined) {
|
|
111
|
+
if (status !== 0) return status;
|
|
112
|
+
return runProgram(process.execPath, [join(global, "bin/pbot.mjs"), ...args], env, false, input);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return runProgram("npx", ["--yes", "--ignore-scripts", "--prefer-offline", "personal-bot@" + required, ...args], env, false, input);
|
|
116
|
+
}
|
|
@@ -2,7 +2,7 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
import { readFile, stat } from "node:fs/promises";
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
|
-
import type { InstalledPackage } from "../../
|
|
5
|
+
import type { InstalledPackage } from "../../model/installation.js";
|
|
6
6
|
import { npmName } from "../../common/package-source.js";
|
|
7
7
|
|
|
8
8
|
type PiSdk = typeof import("@earendil-works/pi-coding-agent");
|
|
@@ -4,7 +4,7 @@ import { dirname, join, resolve } from "node:path";
|
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { checkStableVersion, npmName } from "../../common/package-source.js";
|
|
7
|
-
import type { InstalledPackage, PackageChoice, PiInstallation, SetupOperations, SystemCommand } from "../../
|
|
7
|
+
import type { InstalledPackage, PackageChoice, PiInstallation, SetupOperations, SystemCommand } from "../../model/installation.js";
|
|
8
8
|
import { findExecutable, npmGlobalBinary, SetupProcesses } from "./processes.js";
|
|
9
9
|
|
|
10
10
|
export const piPackageName = "@earendil-works/pi-coding-agent";
|
|
@@ -2,7 +2,7 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { access, realpath, stat } from "node:fs/promises";
|
|
3
3
|
import { constants } from "node:fs";
|
|
4
4
|
import { delimiter, isAbsolute, join, resolve } from "node:path";
|
|
5
|
-
import type { SystemCommand } from "../../
|
|
5
|
+
import type { SystemCommand } from "../../model/installation.js";
|
|
6
6
|
|
|
7
7
|
export async function findExecutable(name: string, env: NodeJS.ProcessEnv = process.env): Promise<string | undefined> {
|
|
8
8
|
const directories = (env.PATH ?? "").split(delimiter).filter(Boolean);
|