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
|
@@ -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,4 @@
|
|
|
1
|
+
import * as McpClient from "@deepseek-ai/dsh-mcp-client";
|
|
2
|
+
import type { ResolvedWorkspaceMcpServer } from "../../../model/workspace-mcp.js";
|
|
3
|
+
/** Translate a resolved workspace MCP entry into dsh's native `@deepseek-ai/dsh-mcp-client` config. */
|
|
4
|
+
export declare function toDshMcpConfig(server: ResolvedWorkspaceMcpServer): McpClient.Config;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as McpClient from "@deepseek-ai/dsh-mcp-client";
|
|
2
|
+
/** Translate a resolved workspace MCP entry into dsh's native `@deepseek-ai/dsh-mcp-client` config. */
|
|
3
|
+
export function toDshMcpConfig(server) {
|
|
4
|
+
if (server.transport === "http") {
|
|
5
|
+
return McpClient.Config({
|
|
6
|
+
transport: "streamable-http",
|
|
7
|
+
serverName: server.name,
|
|
8
|
+
url: server.url,
|
|
9
|
+
headers: { ...server.headers },
|
|
10
|
+
toolCallTimeoutMs: server.timeout * 1000,
|
|
11
|
+
failOnStartupError: false,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return McpClient.Config({
|
|
15
|
+
transport: "stdio",
|
|
16
|
+
serverName: server.name,
|
|
17
|
+
command: server.command,
|
|
18
|
+
args: [...server.args],
|
|
19
|
+
env: {
|
|
20
|
+
...(process.env.PATH ? { PATH: process.env.PATH } : {}),
|
|
21
|
+
...(process.env.HOME ? { HOME: process.env.HOME } : {}),
|
|
22
|
+
...server.env,
|
|
23
|
+
},
|
|
24
|
+
cwd: server.cwd,
|
|
25
|
+
toolCallTimeoutMs: server.timeout * 1000,
|
|
26
|
+
failOnStartupError: false,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type UserMessage } from "@deepseek-ai/dsh-llm";
|
|
2
|
+
import type { SessionEvent } from "@deepseek-ai/dsh-session";
|
|
3
|
+
/** Producer metadata travels with native messages and never grants task authorization. */
|
|
4
|
+
declare module "@deepseek-ai/dsh-llm" {
|
|
5
|
+
interface MessageSourceMap {
|
|
6
|
+
"pbot-input": {
|
|
7
|
+
kind: "pbot-input";
|
|
8
|
+
form: "relay";
|
|
9
|
+
requestId: string;
|
|
10
|
+
generation: string;
|
|
11
|
+
parentSessionId: string;
|
|
12
|
+
};
|
|
13
|
+
"pbot-team-context": {
|
|
14
|
+
kind: "pbot-team-context";
|
|
15
|
+
form: "relay";
|
|
16
|
+
teamId: string;
|
|
17
|
+
seqs: number[];
|
|
18
|
+
};
|
|
19
|
+
"pbot-results": {
|
|
20
|
+
kind: "pbot-results";
|
|
21
|
+
form: "notice";
|
|
22
|
+
summary: string;
|
|
23
|
+
keys: string[];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export declare function finalDshAnswer(event: Extract<SessionEvent, {
|
|
28
|
+
type: "assistant/message";
|
|
29
|
+
}>): string;
|
|
30
|
+
export declare function requestSource(message: UserMessage, generation: string): {
|
|
31
|
+
kind: "pbot-input";
|
|
32
|
+
form: "relay";
|
|
33
|
+
requestId: string;
|
|
34
|
+
generation: string;
|
|
35
|
+
parentSessionId: string;
|
|
36
|
+
} | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { lastAssistantStreamChunk } from "@deepseek-ai/dsh-llm";
|
|
2
|
+
export function finalDshAnswer(event) {
|
|
3
|
+
const { message, interrupted, stream } = event.data;
|
|
4
|
+
if (interrupted || message.content.some(block => block.type === "tool-call") || lastAssistantStreamChunk(stream, "finish")?.reason.kind !== "stop")
|
|
5
|
+
return "";
|
|
6
|
+
return message.content.filter(block => block.type === "text").map(block => block.text).join("\n");
|
|
7
|
+
}
|
|
8
|
+
export function requestSource(message, generation) {
|
|
9
|
+
const source = message.source;
|
|
10
|
+
return source.kind === "pbot-input" && source.generation === generation ? source : undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
import type { AgentOptions } from "../../../model/agent.js";
|
|
4
|
+
export declare function dshResources(ctx: Context, _agent: Agent, root: string, role: "coordinator" | "general-purpose", check: () => void, coordinatorPrompt?: string): Promise<void>;
|
|
5
|
+
/** Map an ACP dsh worker's native loadout without interfering with coordinator sessions. */
|
|
6
|
+
export declare function dshExpertTools(ctx: Context, agent: Agent, options: AgentOptions): void;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { agentText } from "../../agent-resources.js";
|
|
4
|
+
import { resourceRoot } from "../../../common/paths.js";
|
|
5
|
+
import { requireThat } from "../../../common/validation.js";
|
|
6
|
+
import { isMcpWorkerTool } from "../../../model/acp.js";
|
|
7
|
+
export async function dshResources(ctx, _agent, root, role, check, coordinatorPrompt = "history-coordinator.md") {
|
|
8
|
+
const read = () => Promise.all([agentText(role, root, coordinatorPrompt), readFile(join(resourceRoot, "prompts/workspace.md"), "utf8")]);
|
|
9
|
+
const [text, workspace] = await read();
|
|
10
|
+
check();
|
|
11
|
+
ctx.systemPrompt.section({ name: "pbot:role", order: 1, text, interpolate: false });
|
|
12
|
+
ctx.systemPrompt.section({ name: "pbot:workspace", order: 2, text: workspace, interpolate: false });
|
|
13
|
+
ctx.systemPrompt.context({
|
|
14
|
+
name: "pbot:environment", order: 300, required: true, interpolate: false,
|
|
15
|
+
text: JSON.stringify({ host: "dsh", workspaceRoot: root, resourceRoot }),
|
|
16
|
+
});
|
|
17
|
+
ctx.on("system-prompt/assemble", async (_assembly, _context, next) => {
|
|
18
|
+
check();
|
|
19
|
+
const [roleText, workspaceText] = await read();
|
|
20
|
+
check();
|
|
21
|
+
const assembly = await next();
|
|
22
|
+
return {
|
|
23
|
+
...assembly,
|
|
24
|
+
sections: assembly.sections.map(section => section.name === "pbot:role" ? { ...section, text: roleText }
|
|
25
|
+
: section.name === "pbot:workspace" ? { ...section, text: workspaceText } : section),
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/** Map an ACP dsh worker's native loadout without interfering with coordinator sessions. */
|
|
30
|
+
export function dshExpertTools(ctx, agent, options) {
|
|
31
|
+
const names = new Set(ctx.tools.definitions(agent).map(tool => tool.name));
|
|
32
|
+
const forbidden = new Set([
|
|
33
|
+
"pbot_history",
|
|
34
|
+
"subagent", "subagent_fork", "list_subagent_models", "list_agents", "send_message", "interrupt_agent",
|
|
35
|
+
]);
|
|
36
|
+
if (options.noSkills)
|
|
37
|
+
forbidden.add("skill");
|
|
38
|
+
const isForbidden = (name) => forbidden.has(name) || isMcpWorkerTool(name);
|
|
39
|
+
if (options.tools) {
|
|
40
|
+
for (const name of options.tools)
|
|
41
|
+
requireThat(names.has(name) && !isForbidden(name), "专家工具不可用:" + name);
|
|
42
|
+
ctx.tools.restrict({ allow: options.tools });
|
|
43
|
+
}
|
|
44
|
+
const deny = [...names].filter(isForbidden);
|
|
45
|
+
if (deny.length)
|
|
46
|
+
ctx.tools.restrict({ deny });
|
|
47
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
export interface DshSkillsOptions {
|
|
4
|
+
/** Also register `<workspaceRoot>/.agents/skills` (useful when agent cwd is nested inside the workspace). */
|
|
5
|
+
workspaceRoot?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Keep bundled methods local to this Agent without overriding its native project/user methods. */
|
|
8
|
+
export declare function registerDshSkills(ctx: Context, agent: Agent, options?: DshSkillsOptions): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { scopeParentOf } from "@deepseek-ai/dsh-scope";
|
|
3
|
+
import { FileSystemSkillProvider } from "@deepseek-ai/dsh-skill-filesystem";
|
|
4
|
+
import { resourceRoot } from "../../../common/paths.js";
|
|
5
|
+
/** Keep bundled methods local to this Agent without overriding its native project/user methods. */
|
|
6
|
+
export function registerDshSkills(ctx, agent, options = {}) {
|
|
7
|
+
const customSkillDirs = options.workspaceRoot ? [join(options.workspaceRoot, ".agents", "skills")] : undefined;
|
|
8
|
+
let filesystem;
|
|
9
|
+
ctx.skills.registerProvider(control => {
|
|
10
|
+
filesystem = new FileSystemSkillProvider(ctx, control, {
|
|
11
|
+
providerName: "pbot",
|
|
12
|
+
includeDefaultRoots: false,
|
|
13
|
+
bundledSkillDir: join(resourceRoot, "skills"),
|
|
14
|
+
...(customSkillDirs ? { customSkillDirs } : {}),
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
name: "pbot",
|
|
18
|
+
async list(listOptions) {
|
|
19
|
+
const inherited = await ctx.skills.snapshot({ ...listOptions, scope: scopeParentOf(agent) });
|
|
20
|
+
const preferred = new Set(inherited.skills.filter(skill => skill.provider !== "pbot").map(skill => skill.name));
|
|
21
|
+
const listed = await filesystem.list(listOptions);
|
|
22
|
+
const candidates = Array.isArray(listed) ? listed : listed.candidates;
|
|
23
|
+
return { candidates: candidates.filter(skill => !preferred.has(skill.name)),
|
|
24
|
+
complete: inherited.complete && (Array.isArray(listed) || listed.complete) };
|
|
25
|
+
},
|
|
26
|
+
get: (candidate, getOptions) => filesystem.get(candidate, getOptions),
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
ctx.effect(() => () => filesystem.dispose());
|
|
30
|
+
ctx.on("fs/observed", target => { filesystem.observeHostMutation(target.displayPath); });
|
|
31
|
+
}
|
|
@@ -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
|
+
};
|
|
@@ -8,7 +8,8 @@ export interface AcpCommand {
|
|
|
8
8
|
env?: Record<string, string>;
|
|
9
9
|
}
|
|
10
10
|
/** ask: forward target permission requests to the parent session; allow/deny: answer them automatically. */
|
|
11
|
-
export
|
|
11
|
+
export declare const acpPermissionPolicies: readonly ["ask", "allow", "deny"];
|
|
12
|
+
export type AcpPermissionPolicy = typeof acpPermissionPolicies[number];
|
|
12
13
|
/** Workspace `acp.<name>` entry; omitting `command` keeps a registered harness's default command. */
|
|
13
14
|
export interface AcpHarnessConfig {
|
|
14
15
|
command?: string;
|
|
@@ -59,9 +60,10 @@ export interface AcpInput {
|
|
|
59
60
|
generation: string;
|
|
60
61
|
requestId: string;
|
|
61
62
|
}
|
|
63
|
+
export declare const acpAnswerStates: readonly ["completed", "failed", "cancelled"];
|
|
62
64
|
export interface AcpAnswer extends AcpInput {
|
|
63
65
|
answer: string;
|
|
64
|
-
state:
|
|
66
|
+
state: typeof acpAnswerStates[number];
|
|
65
67
|
error?: string;
|
|
66
68
|
}
|
|
67
69
|
export interface AcpReport {
|
|
@@ -84,8 +86,10 @@ export interface AcpPermissionReply {
|
|
|
84
86
|
requestId: string;
|
|
85
87
|
optionId: string | null;
|
|
86
88
|
}
|
|
87
|
-
export
|
|
89
|
+
export declare const acpElicitationActions: readonly ["accept", "decline", "cancel"];
|
|
90
|
+
export type AcpElicitationAction = typeof acpElicitationActions[number];
|
|
88
91
|
export type AcpElicitationValue = string | number | boolean | string[];
|
|
92
|
+
export declare function isAcpElicitationValue(value: unknown): value is AcpElicitationValue;
|
|
89
93
|
export type AcpElicitationContent = Record<string, AcpElicitationValue>;
|
|
90
94
|
export interface AcpElicitation {
|
|
91
95
|
generation: string;
|
|
@@ -10,3 +10,11 @@ export function isMcpWorkerTool(name) {
|
|
|
10
10
|
const bare = name.startsWith("mcp__pbot__") ? name.slice("mcp__pbot__".length) : name;
|
|
11
11
|
return bare === "pbot_worker" || mcpWorkerToolNames.includes(bare);
|
|
12
12
|
}
|
|
13
|
+
/** ask: forward target permission requests to the parent session; allow/deny: answer them automatically. */
|
|
14
|
+
export const acpPermissionPolicies = ["ask", "allow", "deny"];
|
|
15
|
+
export const acpAnswerStates = ["completed", "failed", "cancelled"];
|
|
16
|
+
export const acpElicitationActions = ["accept", "decline", "cancel"];
|
|
17
|
+
export function isAcpElicitationValue(value) {
|
|
18
|
+
return typeof value === "string" || typeof value === "boolean" || (typeof value === "number" && Number.isFinite(value))
|
|
19
|
+
|| (Array.isArray(value) && value.every(item => typeof item === "string"));
|
|
20
|
+
}
|