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
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type { AgentHost } from "../../
|
|
2
|
-
import type { AgentDescriptor, AgentOptions, AgentSessionReference } from "../../model/agent.js";
|
|
1
|
+
import type { AgentHost, AgentDescriptor, AgentOptions, AgentSessionReference } from "../../model/agent.js";
|
|
3
2
|
import type { AcpBackend, AcpCommands, AcpModelsResult } from "../../model/acp.js";
|
|
4
3
|
import { AgentFiles } from "../../storage/agent-files.js";
|
|
5
4
|
/** Pure ACP v1 worker host; spawns isolated acp-worker child processes for any registered or custom harness. */
|
|
6
5
|
export declare class AcpWorkerHost implements AgentHost {
|
|
7
|
-
|
|
6
|
+
commands: AcpCommands;
|
|
8
7
|
readonly files: AgentFiles;
|
|
9
8
|
readonly worker: string;
|
|
10
9
|
constructor(directory: string, commands?: AcpCommands);
|
|
@@ -16,7 +16,7 @@ export const dshAcpHarness = {
|
|
|
16
16
|
async prepareLaunch(context) {
|
|
17
17
|
const base = defaultPrepareLaunch(context);
|
|
18
18
|
const patch = join(context.directory, "acp-dsh-patch.json");
|
|
19
|
-
await writeFile(patch, JSON.stringify([{ insert: [{ id: "pbot-acp-member", name: join(context.packageRoot, "lib/extension/hosts/dsh/acp-
|
|
19
|
+
await writeFile(patch, JSON.stringify([{ insert: [{ id: "pbot-acp-member", name: join(context.packageRoot, "lib/extension/hosts/dsh/acp-entry.js") }] }]) + "\n", { mode: 0o600 });
|
|
20
20
|
return {
|
|
21
21
|
...base,
|
|
22
22
|
command: { ...base.command, args: [...base.command.args, "--patch", patch] },
|
|
@@ -9,6 +9,14 @@ export const standardAcpPresets = [
|
|
|
9
9
|
configureHint: "运行 agy 完成登录与默认模型配置。",
|
|
10
10
|
nativeWorkspaceSkills: true,
|
|
11
11
|
}),
|
|
12
|
+
createGenericAcpHarness("qoder", {
|
|
13
|
+
label: "Qoder CLI",
|
|
14
|
+
aliases: ["qodercli", "qoder-cli"],
|
|
15
|
+
nativeWorkspaceSkills: true,
|
|
16
|
+
defaultCommand: { command: "qodercli", args: ["--acp"] },
|
|
17
|
+
installHint: "安装 Qoder CLI(qodercli)",
|
|
18
|
+
configureHint: "运行 qodercli login 完成登录。",
|
|
19
|
+
}),
|
|
12
20
|
createGenericAcpHarness("codex", {
|
|
13
21
|
label: "OpenAI Codex",
|
|
14
22
|
aliases: ["openai-codex", "codex-cli"],
|
|
@@ -17,10 +17,11 @@ export function createAcpHistorySummarizer(options) {
|
|
|
17
17
|
requireThat(existsSync(workerPath), "缺少 ACP worker 构建产物;请先运行 npm run build。");
|
|
18
18
|
const commands = options.commands ?? {};
|
|
19
19
|
const backend = canonicalAcpBackend(options.backend ?? "pi", commands);
|
|
20
|
-
|
|
20
|
+
let resolvedReference;
|
|
21
21
|
const timeoutMs = options.timeoutMs ?? defaultTimeoutMs;
|
|
22
22
|
return async (request, signal) => {
|
|
23
23
|
signal.throwIfAborted();
|
|
24
|
+
const reference = (resolvedReference ??= acpLaunch(backend, commands, {}));
|
|
24
25
|
return await new Promise((resolveAnswer, reject) => {
|
|
25
26
|
const child = fork(workerPath, ["--prompt"], {
|
|
26
27
|
cwd: options.cwd,
|
|
@@ -11,7 +11,7 @@ export declare function inspectAcpBackends(commands?: AcpCommands): ({
|
|
|
11
11
|
available: boolean;
|
|
12
12
|
builtin: boolean;
|
|
13
13
|
configured: boolean;
|
|
14
|
-
permission:
|
|
14
|
+
permission: "ask" | "allow" | "deny";
|
|
15
15
|
command: string;
|
|
16
16
|
args: string[];
|
|
17
17
|
aliases?: string[];
|
|
@@ -22,7 +22,7 @@ export declare function inspectAcpBackends(commands?: AcpCommands): ({
|
|
|
22
22
|
available: boolean;
|
|
23
23
|
builtin: boolean;
|
|
24
24
|
configured: boolean;
|
|
25
|
-
permission:
|
|
25
|
+
permission: "ask" | "allow" | "deny";
|
|
26
26
|
command: string;
|
|
27
27
|
args: string[];
|
|
28
28
|
aliases?: string[];
|
|
@@ -32,7 +32,7 @@ export function formatWorkspaceSkills(skills) {
|
|
|
32
32
|
if (!skills.length)
|
|
33
33
|
return "";
|
|
34
34
|
const lines = skills.map(skill => `- **${skill.name}**(\`${skill.path}\`):${skill.description}`);
|
|
35
|
-
return "## 工作区技能\n\n
|
|
35
|
+
return "## 工作区技能\n\n匹配任务时按需读取对应 `SKILL.md` 正文:\n" + lines.join("\n");
|
|
36
36
|
}
|
|
37
37
|
export async function loadWorkspaceContext(options) {
|
|
38
38
|
const { host, root, role, coordinatorPrompt, includePrompts = true, includeRootAgents = false, localRoleOnly = false, workspaceSkills = [], notices = [], } = options;
|
|
@@ -1,14 +1,10 @@
|
|
|
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";
|
|
3
|
+
import { parsePromptEvent, pluginWorkspaceRoot, promptHooks } from "../prompt-hooks.js";
|
|
5
4
|
const supportedEvents = ["UserPromptSubmit", "PreToolUse", "UserPromptExpansion", "Stop"];
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const root = await realpath(directory);
|
|
10
|
-
requireThat((await stat(root)).isDirectory(), "Claude 工作区需要目录。");
|
|
11
|
-
return root;
|
|
5
|
+
const boundWorkspaceRoot = () => process.env.CLAUDE_PROJECT_DIR;
|
|
6
|
+
export async function claudeWorkspaceRoot(cwd, projectDirectory = boundWorkspaceRoot()) {
|
|
7
|
+
return pluginWorkspaceRoot(projectDirectory || cwd);
|
|
12
8
|
}
|
|
13
9
|
export const claudeAdapter = {
|
|
14
10
|
host: "claude",
|
|
@@ -17,6 +13,7 @@ export const claudeAdapter = {
|
|
|
17
13
|
coordinatorPrompt: "plugin-coordinator.md",
|
|
18
14
|
initCommandHint: "/personal-bot:pbot init",
|
|
19
15
|
usage: "用法:node <插件目录>/lib/claude.js init|status",
|
|
16
|
+
boundWorkspaceRoot,
|
|
20
17
|
resolveRoot(cwd) {
|
|
21
18
|
return claudeWorkspaceRoot(cwd);
|
|
22
19
|
},
|
|
@@ -33,56 +30,7 @@ export const claudeAdapter = {
|
|
|
33
30
|
requireThat(typeof value.cwd === "string", "Claude hook 缺少工作目录。");
|
|
34
31
|
return { kind: "check-skill", skill, cwd: value.cwd, raw: value };
|
|
35
32
|
}
|
|
36
|
-
|
|
37
|
-
if (typeof value.agent_id === "string")
|
|
38
|
-
return { kind: "ignore" };
|
|
39
|
-
requireThat(typeof value.cwd === "string", "Claude hook 缺少工作目录。");
|
|
40
|
-
if (event === "Stop")
|
|
41
|
-
return { kind: "record-history", cwd: value.cwd, raw: value };
|
|
42
|
-
return { kind: "inject-context", role: "coordinator", cwd: value.cwd, raw: value };
|
|
43
|
-
},
|
|
44
|
-
async extractHistory(event) {
|
|
45
|
-
if (!object(event.raw))
|
|
46
|
-
return undefined;
|
|
47
|
-
const sessionId = typeof event.raw.session_id === "string" ? event.raw.session_id.trim() : "";
|
|
48
|
-
if (!sessionId)
|
|
49
|
-
return undefined;
|
|
50
|
-
if (event.raw.hook_event_name === "UserPromptSubmit") {
|
|
51
|
-
const text = typeof event.raw.prompt === "string" ? event.raw.prompt.trim() : "";
|
|
52
|
-
if (!text)
|
|
53
|
-
return undefined;
|
|
54
|
-
return { kind: "input", sessionId, text };
|
|
55
|
-
}
|
|
56
|
-
if (event.raw.hook_event_name === "Stop") {
|
|
57
|
-
const assistantText = typeof event.raw.last_assistant_message === "string" ? event.raw.last_assistant_message.trim() : "";
|
|
58
|
-
if (!assistantText)
|
|
59
|
-
return undefined;
|
|
60
|
-
return {
|
|
61
|
-
kind: "answer",
|
|
62
|
-
sessionId,
|
|
63
|
-
assistantText,
|
|
64
|
-
completed: true,
|
|
65
|
-
...(event.raw.stop_hook_active === true ? { isContinuation: true } : {}),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
return undefined;
|
|
69
|
-
},
|
|
70
|
-
formatPass() {
|
|
71
|
-
return {};
|
|
72
|
-
},
|
|
73
|
-
formatContext(event, context) {
|
|
74
|
-
const raw = event.raw;
|
|
75
|
-
return {
|
|
76
|
-
hookSpecificOutput: {
|
|
77
|
-
hookEventName: raw.hook_event_name,
|
|
78
|
-
additionalContext: context.text,
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
},
|
|
82
|
-
formatDeny(event, reason) {
|
|
83
|
-
const raw = event.raw;
|
|
84
|
-
return raw.hook_event_name === "UserPromptExpansion"
|
|
85
|
-
? { decision: "block", reason }
|
|
86
|
-
: { hookSpecificOutput: { hookEventName: raw.hook_event_name, permissionDecision: "deny", permissionDecisionReason: reason } };
|
|
33
|
+
return parsePromptEvent(value);
|
|
87
34
|
},
|
|
35
|
+
...promptHooks,
|
|
88
36
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { parsePromptEvent, pluginWorkspaceRoot, promptHooks } from "../prompt-hooks.js";
|
|
2
|
+
export const codexAdapter = {
|
|
3
|
+
host: "codex",
|
|
4
|
+
nativeRootAgents: true,
|
|
5
|
+
nativeWorkspaceSkills: true,
|
|
6
|
+
indexBundledSkills: true,
|
|
7
|
+
initCommandHint: "pbot plugin codex init",
|
|
8
|
+
usage: "用法:pbot plugin codex init|status",
|
|
9
|
+
resolveRoot(cwd) {
|
|
10
|
+
return pluginWorkspaceRoot(cwd);
|
|
11
|
+
},
|
|
12
|
+
parseEvent: parsePromptEvent,
|
|
13
|
+
...promptHooks,
|
|
14
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
/** Native tools still own parsing, mutation queues and results; authorize at the actual file write. */
|
|
3
|
+
export declare function agentFileTools(root: string, signal: AbortSignal, authorize: (path: string, change: unknown, signal: AbortSignal) => Promise<void>): ToolDefinition[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { access as fileAccess, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
|
+
import { defineTool, createWriteToolDefinition, createEditToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
/** Native tools still own parsing, mutation queues and results; authorize at the actual file write. */
|
|
6
|
+
export function agentFileTools(root, signal, authorize) {
|
|
7
|
+
const guardedWrite = (cancel, parameters) => async (path, content) => {
|
|
8
|
+
await authorize(path, { parameters, content }, cancel);
|
|
9
|
+
await mkdir(dirname(path), { recursive: true });
|
|
10
|
+
cancel.throwIfAborted();
|
|
11
|
+
await writeFile(path, content, "utf8");
|
|
12
|
+
};
|
|
13
|
+
return [
|
|
14
|
+
defineTool({ ...createWriteToolDefinition(root),
|
|
15
|
+
execute(id, args, inner, update, child) {
|
|
16
|
+
const cancel = AbortSignal.any([signal, ...(inner ? [inner] : [])]);
|
|
17
|
+
return createWriteToolDefinition(root, { operations: {
|
|
18
|
+
// Directory creation belongs to guardedWrite, after authorization.
|
|
19
|
+
mkdir: async () => { }, writeFile: guardedWrite(cancel, args),
|
|
20
|
+
} }).execute(id, args, cancel, update, child);
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
defineTool({ ...createEditToolDefinition(root),
|
|
24
|
+
execute(id, args, inner, update, child) {
|
|
25
|
+
const cancel = AbortSignal.any([signal, ...(inner ? [inner] : [])]);
|
|
26
|
+
return createEditToolDefinition(root, { operations: {
|
|
27
|
+
readFile, access: path => fileAccess(path, constants.R_OK | constants.W_OK), writeFile: guardedWrite(cancel, args),
|
|
28
|
+
} }).execute(id, args, cancel, update, child);
|
|
29
|
+
},
|
|
30
|
+
}),
|
|
31
|
+
];
|
|
32
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { McpServerConfig } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { ResolvedWorkspaceMcpServer } from "../../../model/workspace-mcp.js";
|
|
3
|
+
/** Translate a resolved workspace MCP entry into Pi's native `registerMcpServer` config. */
|
|
4
|
+
export declare function toPiMcpConfig(server: ResolvedWorkspaceMcpServer): McpServerConfig;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Translate a resolved workspace MCP entry into Pi's native `registerMcpServer` config. */
|
|
2
|
+
export function toPiMcpConfig(server) {
|
|
3
|
+
if (server.transport === "http") {
|
|
4
|
+
return {
|
|
5
|
+
type: "http",
|
|
6
|
+
url: server.url,
|
|
7
|
+
...(Object.keys(server.headers).length ? { headers: { ...server.headers } } : {}),
|
|
8
|
+
exposure: "direct",
|
|
9
|
+
timeout: server.timeout,
|
|
10
|
+
...(server.description ? { description: server.description } : {}),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
type: "stdio",
|
|
15
|
+
command: server.command,
|
|
16
|
+
args: [...server.args],
|
|
17
|
+
...(Object.keys(server.env).length ? { env: { ...server.env } } : {}),
|
|
18
|
+
cwd: server.cwd,
|
|
19
|
+
exposure: "direct",
|
|
20
|
+
timeout: server.timeout,
|
|
21
|
+
...(server.description ? { description: server.description } : {}),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -13,3 +13,4 @@ export declare const pluginHosts: PluginHostRegistry;
|
|
|
13
13
|
export declare const registerPluginHost: (adapter: PluginHostAdapter) => PluginHostRegistry;
|
|
14
14
|
export declare const getPluginHost: (host: PluginHostId) => PluginHostAdapter | undefined;
|
|
15
15
|
export declare const listPluginHosts: () => string[];
|
|
16
|
+
export declare function pluginMcpWorkspaceRoot(): string | undefined;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { requireThat } from "../../common/validation.js";
|
|
2
2
|
import { antigravityAdapter } from "./antigravity/adapter.js";
|
|
3
3
|
import { claudeAdapter } from "./claude/adapter.js";
|
|
4
|
+
import { codexAdapter } from "./codex/adapter.js";
|
|
5
|
+
import { qoderAdapter } from "./qoder/adapter.js";
|
|
4
6
|
/** Extensible registry of hook-based plugin host adapters; runtime never branches on host IDs. */
|
|
5
7
|
export class PluginHostRegistry {
|
|
6
8
|
#adapters = new Map();
|
|
@@ -28,7 +30,12 @@ export class PluginHostRegistry {
|
|
|
28
30
|
return [...this.#adapters.keys()];
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
|
-
export const pluginHosts = new PluginHostRegistry([claudeAdapter, antigravityAdapter]);
|
|
33
|
+
export const pluginHosts = new PluginHostRegistry([claudeAdapter, antigravityAdapter, codexAdapter, qoderAdapter]);
|
|
32
34
|
export const registerPluginHost = (adapter) => pluginHosts.register(adapter);
|
|
33
35
|
export const getPluginHost = (host) => pluginHosts.get(host);
|
|
34
36
|
export const listPluginHosts = () => pluginHosts.list();
|
|
37
|
+
export function pluginMcpWorkspaceRoot() {
|
|
38
|
+
// Older standalone Claude mounts supply the project directory without PBOT_HOST.
|
|
39
|
+
const adapter = process.env.PBOT_HOST ? pluginHosts.get(process.env.PBOT_HOST) : claudeAdapter;
|
|
40
|
+
return adapter?.boundWorkspaceRoot?.() || process.env.PBOT_WORKSPACE_ROOT;
|
|
41
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { HostEvent } from "../../model/plugin-host.js";
|
|
2
|
+
/** Shared stdin/stdout contract for hosts with Claude-compatible prompt and stop hooks. */
|
|
3
|
+
export declare function pluginWorkspaceRoot(directory: string): Promise<string>;
|
|
4
|
+
export declare function parsePromptEvent(value: unknown): HostEvent;
|
|
5
|
+
export declare const promptHooks: {
|
|
6
|
+
extractHistory(event: {
|
|
7
|
+
kind: "inject-context";
|
|
8
|
+
role: import("../../model/plugin-host.js").WorkspaceRole;
|
|
9
|
+
localRoleOnly?: boolean;
|
|
10
|
+
isSessionStart?: boolean;
|
|
11
|
+
noticesOnly?: boolean;
|
|
12
|
+
cwd: string;
|
|
13
|
+
raw: unknown;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "record-history";
|
|
16
|
+
cwd: string;
|
|
17
|
+
raw: unknown;
|
|
18
|
+
}): Promise<{
|
|
19
|
+
text: string;
|
|
20
|
+
sessionId: string;
|
|
21
|
+
turnId: string;
|
|
22
|
+
kind: "input";
|
|
23
|
+
} | {
|
|
24
|
+
text: string;
|
|
25
|
+
sessionId: string;
|
|
26
|
+
turnId?: never;
|
|
27
|
+
kind: "input";
|
|
28
|
+
} | {
|
|
29
|
+
isContinuation?: true;
|
|
30
|
+
assistantText: string;
|
|
31
|
+
completed: true;
|
|
32
|
+
sessionId: string;
|
|
33
|
+
turnId: string;
|
|
34
|
+
kind: "answer";
|
|
35
|
+
} | {
|
|
36
|
+
isContinuation?: true;
|
|
37
|
+
assistantText: string;
|
|
38
|
+
completed: true;
|
|
39
|
+
sessionId: string;
|
|
40
|
+
turnId?: never;
|
|
41
|
+
kind: "answer";
|
|
42
|
+
} | undefined>;
|
|
43
|
+
formatPass(): {};
|
|
44
|
+
formatContext(event: {
|
|
45
|
+
kind: "inject-context";
|
|
46
|
+
role: import("../../model/plugin-host.js").WorkspaceRole;
|
|
47
|
+
localRoleOnly?: boolean;
|
|
48
|
+
isSessionStart?: boolean;
|
|
49
|
+
noticesOnly?: boolean;
|
|
50
|
+
cwd: string;
|
|
51
|
+
raw: unknown;
|
|
52
|
+
}, context: import("../../model/plugin-host.js").WorkspaceContext): {
|
|
53
|
+
hookSpecificOutput: {
|
|
54
|
+
hookEventName: string;
|
|
55
|
+
additionalContext: string;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
formatDeny(event: {
|
|
59
|
+
kind: "check-skill";
|
|
60
|
+
skill: string;
|
|
61
|
+
cwd: string;
|
|
62
|
+
raw: unknown;
|
|
63
|
+
}, reason: string): {
|
|
64
|
+
decision: string;
|
|
65
|
+
reason: string;
|
|
66
|
+
hookSpecificOutput?: never;
|
|
67
|
+
} | {
|
|
68
|
+
hookSpecificOutput: {
|
|
69
|
+
hookEventName: string;
|
|
70
|
+
permissionDecision: string;
|
|
71
|
+
permissionDecisionReason: string;
|
|
72
|
+
};
|
|
73
|
+
decision?: never;
|
|
74
|
+
reason?: never;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
/** Shared stdin/stdout contract for hosts with Claude-compatible prompt and stop hooks. */
|
|
6
|
+
export async function pluginWorkspaceRoot(directory) {
|
|
7
|
+
requireThat(isAbsolute(directory), "插件工作区需要绝对路径。");
|
|
8
|
+
const root = await realpath(directory);
|
|
9
|
+
requireThat((await stat(root)).isDirectory(), "插件工作区需要目录。");
|
|
10
|
+
return root;
|
|
11
|
+
}
|
|
12
|
+
export function parsePromptEvent(value) {
|
|
13
|
+
requireThat(object(value), "插件 hook 输入无效。");
|
|
14
|
+
const name = value.hook_event_name;
|
|
15
|
+
if (name !== "Stop" && name !== "UserPromptSubmit" && name !== "SessionStart")
|
|
16
|
+
return { kind: "ignore" };
|
|
17
|
+
if (typeof value.agent_id === "string")
|
|
18
|
+
return { kind: "ignore" };
|
|
19
|
+
requireThat(typeof value.cwd === "string", "插件 hook 缺少工作目录。");
|
|
20
|
+
if (name === "Stop")
|
|
21
|
+
return { kind: "record-history", cwd: value.cwd, raw: value };
|
|
22
|
+
if (name === "SessionStart") {
|
|
23
|
+
if (value.source === "resume" || value.source === "compact")
|
|
24
|
+
return { kind: "ignore" };
|
|
25
|
+
return { kind: "inject-context", role: "coordinator", isSessionStart: true, noticesOnly: true, cwd: value.cwd, raw: value };
|
|
26
|
+
}
|
|
27
|
+
return { kind: "inject-context", role: "coordinator", cwd: value.cwd, raw: value };
|
|
28
|
+
}
|
|
29
|
+
export const promptHooks = {
|
|
30
|
+
async extractHistory(event) {
|
|
31
|
+
if (!object(event.raw))
|
|
32
|
+
return undefined;
|
|
33
|
+
const sessionId = typeof event.raw.session_id === "string" ? event.raw.session_id.trim() : "";
|
|
34
|
+
if (!sessionId)
|
|
35
|
+
return undefined;
|
|
36
|
+
const turnId = typeof event.raw.turn_id === "string" ? event.raw.turn_id.trim() : "";
|
|
37
|
+
const identity = turnId ? { sessionId, turnId } : { sessionId };
|
|
38
|
+
if (event.raw.hook_event_name === "UserPromptSubmit") {
|
|
39
|
+
const text = typeof event.raw.prompt === "string" ? event.raw.prompt.trim() : "";
|
|
40
|
+
if (!text && !turnId)
|
|
41
|
+
return undefined;
|
|
42
|
+
return { kind: "input", ...identity, text };
|
|
43
|
+
}
|
|
44
|
+
if (event.raw.hook_event_name === "Stop") {
|
|
45
|
+
const assistantText = typeof event.raw.last_assistant_message === "string" ? event.raw.last_assistant_message.trim() : "";
|
|
46
|
+
if (!assistantText)
|
|
47
|
+
return undefined;
|
|
48
|
+
return {
|
|
49
|
+
kind: "answer",
|
|
50
|
+
...identity,
|
|
51
|
+
assistantText,
|
|
52
|
+
completed: true,
|
|
53
|
+
...(event.raw.stop_hook_active === true ? { isContinuation: true } : {}),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
},
|
|
58
|
+
formatPass() {
|
|
59
|
+
return {};
|
|
60
|
+
},
|
|
61
|
+
formatContext(event, context) {
|
|
62
|
+
const raw = event.raw;
|
|
63
|
+
return {
|
|
64
|
+
hookSpecificOutput: {
|
|
65
|
+
hookEventName: raw.hook_event_name,
|
|
66
|
+
additionalContext: context.text,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
formatDeny(event, reason) {
|
|
71
|
+
const raw = event.raw;
|
|
72
|
+
return raw.hook_event_name === "UserPromptExpansion"
|
|
73
|
+
? { decision: "block", reason }
|
|
74
|
+
: { hookSpecificOutput: { hookEventName: raw.hook_event_name, permissionDecision: "deny", permissionDecisionReason: reason } };
|
|
75
|
+
},
|
|
76
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { parsePromptEvent, pluginWorkspaceRoot, promptHooks } from "../prompt-hooks.js";
|
|
2
|
+
const boundWorkspaceRoot = () => process.env.QODER_PROJECT_DIR || process.env.PBOT_WORKSPACE_ROOT;
|
|
3
|
+
export const qoderAdapter = {
|
|
4
|
+
host: "qoder",
|
|
5
|
+
nativeRootAgents: true,
|
|
6
|
+
nativeWorkspaceSkills: true,
|
|
7
|
+
indexBundledSkills: true,
|
|
8
|
+
initCommandHint: "pbot plugin qoder init",
|
|
9
|
+
usage: "用法:pbot plugin qoder init|status",
|
|
10
|
+
boundWorkspaceRoot,
|
|
11
|
+
resolveRoot(cwd) {
|
|
12
|
+
return pluginWorkspaceRoot(boundWorkspaceRoot() || cwd);
|
|
13
|
+
},
|
|
14
|
+
parseEvent: parsePromptEvent,
|
|
15
|
+
...promptHooks,
|
|
16
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
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
|
+
/** Check exact installed manifests, never resolve dependencies in an ancestor workspace. */
|
|
12
|
+
export async function minimumCliRelease(root, plugins) {
|
|
13
|
+
const versions = Object.values(plugins);
|
|
14
|
+
if (process.env.PBOT_PLUGIN_VERSION)
|
|
15
|
+
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 = JSON.parse(await readFile(path, "utf8"));
|
|
20
|
+
requireThat(object(manifest) && manifest.name === "personal-bot" && typeof manifest.version === "string", "无效的 personal-bot 安装清单:" + path);
|
|
21
|
+
versions.push(manifest.version);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (error.code !== "ENOENT")
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
let required;
|
|
29
|
+
for (const version of versions) {
|
|
30
|
+
requireThat(valid(version) && /^[0-9]/.test(version) && version === version.trim(), "无效的插件发布版本:" + version);
|
|
31
|
+
if (!required || gt(version, required))
|
|
32
|
+
required = version;
|
|
33
|
+
}
|
|
34
|
+
return required;
|
|
35
|
+
}
|
|
36
|
+
async function runProgram(command, args, env, install = false, input) {
|
|
37
|
+
const child = spawn(command, args, install
|
|
38
|
+
? { cwd: homedir(), stdio: ["ignore", 2, 2], env }
|
|
39
|
+
: { stdio: input === undefined ? "inherit" : ["pipe", "inherit", "inherit"], env });
|
|
40
|
+
const interrupt = () => child.kill("SIGINT");
|
|
41
|
+
const terminate = () => child.kill("SIGTERM");
|
|
42
|
+
process.on("SIGINT", interrupt);
|
|
43
|
+
process.on("SIGTERM", terminate);
|
|
44
|
+
try {
|
|
45
|
+
return await new Promise((resolveCode, reject) => {
|
|
46
|
+
child.once("error", reject);
|
|
47
|
+
child.once("close", (code, signal) => resolveCode(code ?? (signal === "SIGINT" ? 130 : 143)));
|
|
48
|
+
if (input !== undefined && child.stdin) {
|
|
49
|
+
child.stdin.on("error", (error) => { if (error.code !== "EPIPE")
|
|
50
|
+
reject(error); });
|
|
51
|
+
child.stdin.end(input);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
process.off("SIGINT", interrupt);
|
|
57
|
+
process.off("SIGTERM", terminate);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function globalPackage() {
|
|
61
|
+
const { stdout } = await promisify(execFile)("npm", ["root", "--global"], { cwd: homedir() });
|
|
62
|
+
const directory = join(stdout.trim(), "personal-bot");
|
|
63
|
+
try {
|
|
64
|
+
// An npm link points at a development checkout; keep updates out of that checkout.
|
|
65
|
+
if ((await lstat(directory)).isDirectory() && await realpath(directory) === await realpath(resolve(resourceRoot, "..")))
|
|
66
|
+
return directory;
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (error.code !== "ENOENT")
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
async function upgradeGlobal(directory, required, env) {
|
|
75
|
+
const lib = dirname(dirname(directory));
|
|
76
|
+
const lock = join(lib, ".pbot-cli-update.lock");
|
|
77
|
+
try {
|
|
78
|
+
await mkdir(lock);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
// A read-only prefix or an active updater can still use npm's per-user versioned cache.
|
|
82
|
+
if (["EEXIST", "EACCES", "EPERM", "EROFS"].includes(error.code ?? ""))
|
|
83
|
+
return undefined;
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
const installedVersion = async () => {
|
|
87
|
+
const installed = JSON.parse(await readFile(join(directory, "package.json"), "utf8"));
|
|
88
|
+
requireThat(object(installed) && installed.name === "personal-bot" && typeof installed.version === "string" && valid(installed.version), "全局 CLI 安装清单无效:" + directory);
|
|
89
|
+
return installed.version;
|
|
90
|
+
};
|
|
91
|
+
try {
|
|
92
|
+
if (lt(await installedVersion(), required)) {
|
|
93
|
+
const code = await runProgram("npm", ["install", "--global", "--prefix", dirname(lib), "--ignore-scripts",
|
|
94
|
+
"--no-audit", "--no-fund", "--prefer-offline", "personal-bot@" + required], env, true);
|
|
95
|
+
if (code)
|
|
96
|
+
return code;
|
|
97
|
+
requireThat(!lt(await installedVersion(), required), "npm 更新后的 CLI 低于插件所需版本:" + required);
|
|
98
|
+
}
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
await rmdir(lock);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export async function upgradeManagedGlobalCli(required, env = process.env) {
|
|
106
|
+
requireThat(valid(required) && /^[0-9]/.test(required) && required === required.trim(), "无效的插件发布版本:" + required);
|
|
107
|
+
if (!lt(packageVersion, required)) {
|
|
108
|
+
return { state: "up-to-date", detail: `CLI 已是 ${packageVersion}。` };
|
|
109
|
+
}
|
|
110
|
+
const global = await globalPackage();
|
|
111
|
+
if (!global) {
|
|
112
|
+
return { state: "skipped", detail: `当前运行的是本地或非全局安装(${packageVersion}),跳过全局 CLI 覆盖。` };
|
|
113
|
+
}
|
|
114
|
+
const status = await upgradeGlobal(global, required, env);
|
|
115
|
+
if (status === undefined) {
|
|
116
|
+
return { state: "skipped", globalDirectory: global, detail: "全局 npm 目录不可写或正被其他进程更新,已跳过全局 CLI 覆盖。" };
|
|
117
|
+
}
|
|
118
|
+
if (status !== 0) {
|
|
119
|
+
return { state: "failed", globalDirectory: global, exitCode: status, detail: `npm 更新全局 personal-bot@${required} 失败(退出码 ${status})。` };
|
|
120
|
+
}
|
|
121
|
+
return { state: "updated", globalDirectory: global, detail: `已将全局 CLI 从 ${packageVersion} 更新到 ${required}。` };
|
|
122
|
+
}
|
|
123
|
+
export function execCliEntry(entry, args, env = process.env) {
|
|
124
|
+
return runProgram(process.execPath, [entry, ...args], env, false);
|
|
125
|
+
}
|
|
126
|
+
/** Upgrade managed global installs in place. Project, npx and linked installs use npm's shared version cache. */
|
|
127
|
+
export async function runUpdatedCli(required, args, input) {
|
|
128
|
+
if (!required)
|
|
129
|
+
return undefined;
|
|
130
|
+
requireThat(valid(required) && /^[0-9]/.test(required) && required === required.trim(), "无效的插件发布版本:" + required);
|
|
131
|
+
if (!lt(packageVersion, required))
|
|
132
|
+
return undefined;
|
|
133
|
+
requireThat(process.env.PBOT_CLI_UPDATING !== required, `npm 启动了 CLI ${packageVersion},工作区插件需要 ${required}。`);
|
|
134
|
+
console.error(`工作区需要 Personal Bot CLI ${required},正在更新 ${packageVersion}。`);
|
|
135
|
+
const env = { ...process.env, PBOT_CLI_UPDATING: required };
|
|
136
|
+
const global = await globalPackage();
|
|
137
|
+
if (global) {
|
|
138
|
+
const status = await upgradeGlobal(global, required, env);
|
|
139
|
+
if (status !== undefined) {
|
|
140
|
+
if (status !== 0)
|
|
141
|
+
return status;
|
|
142
|
+
return runProgram(process.execPath, [join(global, "bin/pbot.mjs"), ...args], env, false, input);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return runProgram("npx", ["--yes", "--ignore-scripts", "--prefer-offline", "personal-bot@" + required, ...args], env, false, input);
|
|
146
|
+
}
|