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
|
@@ -9,7 +9,7 @@ import { randomUUID as randomUUID5 } from "node:crypto";
|
|
|
9
9
|
import { dirname as dirname4, join as join11, resolve as resolve5 } from "node:path";
|
|
10
10
|
|
|
11
11
|
// src/storage/agent-files.ts
|
|
12
|
-
import { existsSync, mkdirSync as
|
|
12
|
+
import { existsSync, mkdirSync as mkdirSync3, readdirSync, rmSync } from "node:fs";
|
|
13
13
|
import { join as join3 } from "node:path";
|
|
14
14
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
15
15
|
|
|
@@ -35,6 +35,9 @@ function isAcpBackend(value) {
|
|
|
35
35
|
function requireThat(condition, message2) {
|
|
36
36
|
if (!condition) throw new Error(message2);
|
|
37
37
|
}
|
|
38
|
+
function isOneOf(value, choices) {
|
|
39
|
+
return typeof value === "string" && choices.includes(value);
|
|
40
|
+
}
|
|
38
41
|
|
|
39
42
|
// src/storage/atomic-json.ts
|
|
40
43
|
import {
|
|
@@ -44,16 +47,18 @@ import {
|
|
|
44
47
|
fsyncSync,
|
|
45
48
|
linkSync,
|
|
46
49
|
lstatSync,
|
|
50
|
+
mkdirSync,
|
|
47
51
|
openSync,
|
|
48
52
|
readFileSync,
|
|
49
53
|
realpathSync,
|
|
50
54
|
renameSync,
|
|
55
|
+
rmdirSync,
|
|
51
56
|
unlinkSync,
|
|
52
57
|
writeFileSync
|
|
53
58
|
} from "node:fs";
|
|
54
59
|
import { dirname, join } from "node:path";
|
|
55
60
|
import { randomUUID } from "node:crypto";
|
|
56
|
-
function internalPath(directory, relative) {
|
|
61
|
+
function internalPath(directory, relative, allowMissingParents = false) {
|
|
57
62
|
const parts = relative.split("/");
|
|
58
63
|
requireThat(parts.every((part) => part && part !== "." && part !== ".." && !/[\\\x00-\x1f]/.test(part)), "\u5185\u90E8\u72B6\u6001\u8DEF\u5F84\u65E0\u6548\u3002");
|
|
59
64
|
const info = lstatSync(directory);
|
|
@@ -65,7 +70,7 @@ function internalPath(directory, relative) {
|
|
|
65
70
|
const info2 = lstatSync(path);
|
|
66
71
|
requireThat(!info2.isSymbolicLink() && (index === parts.length - 1 ? info2.isFile() : info2.isDirectory()), "\u5185\u90E8\u72B6\u6001\u4E0D\u80FD\u4F7F\u7528\u7B26\u53F7\u94FE\u63A5\u6216\u7279\u6B8A\u6587\u4EF6\u3002");
|
|
67
72
|
} catch (error2) {
|
|
68
|
-
if (error2.code !== "ENOENT" || index !== parts.length - 1) throw error2;
|
|
73
|
+
if (error2.code !== "ENOENT" || !allowMissingParents && index !== parts.length - 1) throw error2;
|
|
69
74
|
}
|
|
70
75
|
}
|
|
71
76
|
return path;
|
|
@@ -130,7 +135,7 @@ function writeJsonFile(directory, relative, value, validate2, createOnly = false
|
|
|
130
135
|
}
|
|
131
136
|
|
|
132
137
|
// src/storage/file-access.ts
|
|
133
|
-
import { lstatSync as lstatSync2, mkdirSync } from "node:fs";
|
|
138
|
+
import { lstatSync as lstatSync2, mkdirSync as mkdirSync2 } from "node:fs";
|
|
134
139
|
import { join as join2 } from "node:path";
|
|
135
140
|
function fileId(id) {
|
|
136
141
|
requireThat(/^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/.test(id), "\u5185\u90E8\u8BB0\u5F55 ID \u65E0\u6548\u3002");
|
|
@@ -143,7 +148,7 @@ function privateDirectory(root, relative) {
|
|
|
143
148
|
fileId(part);
|
|
144
149
|
const path = join2(parent, part);
|
|
145
150
|
try {
|
|
146
|
-
|
|
151
|
+
mkdirSync2(path, { mode: 448 });
|
|
147
152
|
syncDirectory(parent);
|
|
148
153
|
} catch (error2) {
|
|
149
154
|
if (error2.code !== "EEXIST") throw error2;
|
|
@@ -153,15 +158,31 @@ function privateDirectory(root, relative) {
|
|
|
153
158
|
}
|
|
154
159
|
}
|
|
155
160
|
|
|
161
|
+
// src/model/agent.ts
|
|
162
|
+
var messageDeliveries = ["steer", "followUp"];
|
|
163
|
+
var cycleStates = ["running", "completed", "failed", "cancelled", "interrupted"];
|
|
164
|
+
var cycleSources = ["parent", "interactive", "mixed"];
|
|
165
|
+
var agentStates = ["starting", "busy", "idle", "stopping", "stopped", "error"];
|
|
166
|
+
|
|
156
167
|
// src/storage/acp-files.ts
|
|
157
168
|
import { isAbsolute } from "node:path";
|
|
169
|
+
|
|
170
|
+
// src/model/acp.ts
|
|
171
|
+
var acpPermissionPolicies = ["ask", "allow", "deny"];
|
|
172
|
+
var acpAnswerStates = ["completed", "failed", "cancelled"];
|
|
173
|
+
var acpElicitationActions = ["accept", "decline", "cancel"];
|
|
174
|
+
function isAcpElicitationValue(value) {
|
|
175
|
+
return typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value) || Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// src/storage/acp-files.ts
|
|
158
179
|
var text = (value) => typeof value === "string" && value.length > 0 && !value.includes("\0");
|
|
159
180
|
function acpReference(value) {
|
|
160
181
|
requireThat(object(value) && value.host === "acp" && isAcpBackend(value.backend) && text(value.command) && isAbsolute(value.command) && Array.isArray(value.args) && value.args.every((arg) => typeof arg === "string" && !arg.includes("\0")) && (value.sessionId === null || text(value.sessionId)), "ACP \u4F1A\u8BDD\u5F15\u7528\u65E0\u6548\u3002");
|
|
161
182
|
if (value.env !== void 0) {
|
|
162
183
|
requireThat(object(value.env) && Object.entries(value.env).every(([k, v]) => text(k) && typeof v === "string" && !v.includes("\0")), "ACP \u73AF\u5883\u53D8\u91CF\u914D\u7F6E\u65E0\u6548\u3002");
|
|
163
184
|
}
|
|
164
|
-
requireThat(value.permission === void 0 ||
|
|
185
|
+
requireThat(value.permission === void 0 || isOneOf(value.permission, acpPermissionPolicies), "ACP \u6743\u9650\u7B56\u7565\u65E0\u6548\u3002");
|
|
165
186
|
const capabilities = value.capabilities;
|
|
166
187
|
if (capabilities !== void 0) requireThat(object(capabilities) && ["resume", "load", "close"].every((key) => typeof capabilities[key] === "boolean"), "ACP \u4F1A\u8BDD\u80FD\u529B\u65E0\u6548\u3002");
|
|
167
188
|
return value;
|
|
@@ -177,7 +198,7 @@ function acpInput(value) {
|
|
|
177
198
|
}
|
|
178
199
|
function acpAnswer(value) {
|
|
179
200
|
acpInput(value);
|
|
180
|
-
requireThat(object(value) && typeof value.answer === "string" &&
|
|
201
|
+
requireThat(object(value) && typeof value.answer === "string" && isOneOf(value.state, acpAnswerStates) && (value.error === void 0 || typeof value.error === "string"), "ACP \u6700\u7EC8\u56DE\u7B54\u65E0\u6548\u3002");
|
|
181
202
|
return value;
|
|
182
203
|
}
|
|
183
204
|
function acpReport(value) {
|
|
@@ -187,7 +208,7 @@ function acpReport(value) {
|
|
|
187
208
|
}
|
|
188
209
|
function acpPermission(value) {
|
|
189
210
|
acpInput(value);
|
|
190
|
-
requireThat(object(value) && typeof value.description === "string" && Array.isArray(value.options) && value.options.every((option) => object(option) && text(option.optionId) && text(option.name) && ["allow_once", "allow_always", "reject_once", "reject_always"]
|
|
211
|
+
requireThat(object(value) && typeof value.description === "string" && Array.isArray(value.options) && value.options.every((option) => object(option) && text(option.optionId) && text(option.name) && isOneOf(option.kind, ["allow_once", "allow_always", "reject_once", "reject_always"])), "ACP \u786E\u8BA4\u8BF7\u6C42\u65E0\u6548\u3002");
|
|
191
212
|
return value;
|
|
192
213
|
}
|
|
193
214
|
function acpPermissionReply(value) {
|
|
@@ -195,9 +216,6 @@ function acpPermissionReply(value) {
|
|
|
195
216
|
requireThat(object(value) && (value.optionId === null || text(value.optionId)), "ACP \u786E\u8BA4\u7B54\u590D\u65E0\u6548\u3002");
|
|
196
217
|
return value;
|
|
197
218
|
}
|
|
198
|
-
function elicitationValue(value) {
|
|
199
|
-
return typeof value === "string" || typeof value === "number" && Number.isFinite(value) || typeof value === "boolean" || Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
200
|
-
}
|
|
201
219
|
function acpElicitation(value) {
|
|
202
220
|
acpInput(value);
|
|
203
221
|
requireThat(object(value) && (value.mode === "form" || value.mode === "url") && typeof value.message === "string", "ACP \u4EA4\u4E92\u8BF7\u6C42\u65E0\u6548\u3002");
|
|
@@ -210,9 +228,9 @@ function acpElicitation(value) {
|
|
|
210
228
|
}
|
|
211
229
|
function acpElicitationReply(value) {
|
|
212
230
|
acpInput(value);
|
|
213
|
-
requireThat(object(value) &&
|
|
231
|
+
requireThat(object(value) && isOneOf(value.action, acpElicitationActions), "ACP \u4EA4\u4E92\u7B54\u590D\u65E0\u6548\u3002");
|
|
214
232
|
if (value.content !== void 0) {
|
|
215
|
-
requireThat(value.action === "accept" && object(value.content) && Object.values(value.content).every(
|
|
233
|
+
requireThat(value.action === "accept" && object(value.content) && Object.values(value.content).every(isAcpElicitationValue), "ACP \u8868\u5355\u7B54\u590D content \u65E0\u6548\u3002");
|
|
216
234
|
}
|
|
217
235
|
return value;
|
|
218
236
|
}
|
|
@@ -230,15 +248,15 @@ function launch(v) {
|
|
|
230
248
|
return v;
|
|
231
249
|
}
|
|
232
250
|
function message(v) {
|
|
233
|
-
requireThat(object(v) && text2(v.requestId) && text2(v.generation) && Number.isSafeInteger(v.sequence) && typeof v.message === "string" &&
|
|
251
|
+
requireThat(object(v) && text2(v.requestId) && text2(v.generation) && Number.isSafeInteger(v.sequence) && typeof v.message === "string" && isOneOf(v.delivery, messageDeliveries) && Array.isArray(v.files) && v.files.every(text2), "\u5B50\u4F1A\u8BDD\u6D88\u606F\u65E0\u6548\u3002");
|
|
234
252
|
return v;
|
|
235
253
|
}
|
|
236
254
|
function cycle(v) {
|
|
237
|
-
requireThat(object(v) && text2(v.cycleId) && text2(v.generation) && number(v.startedAt) &&
|
|
255
|
+
requireThat(object(v) && text2(v.cycleId) && text2(v.generation) && number(v.startedAt) && isOneOf(v.state, cycleStates) && (v.leaf === null || text2(v.leaf)) && Array.isArray(v.requestIds) && v.requestIds.every(text2) && isOneOf(v.source, cycleSources) && (v.finishedAt === void 0 || number(v.finishedAt)), "\u5B50\u4F1A\u8BDD\u5468\u671F\u65E0\u6548\u3002");
|
|
238
256
|
return v;
|
|
239
257
|
}
|
|
240
258
|
function status(v) {
|
|
241
|
-
requireThat(object(v) && text2(v.generation) &&
|
|
259
|
+
requireThat(object(v) && text2(v.generation) && isOneOf(v.state, agentStates) && typeof v.activity === "string" && number(v.updatedAt), "\u5B50\u4F1A\u8BDD\u72B6\u6001\u65E0\u6548\u3002");
|
|
242
260
|
if (v.cycle) cycle(v.cycle);
|
|
243
261
|
return v;
|
|
244
262
|
}
|
|
@@ -282,8 +300,8 @@ var AgentFiles = class {
|
|
|
282
300
|
create(value, run, acp) {
|
|
283
301
|
this.check();
|
|
284
302
|
acpReference(acp);
|
|
285
|
-
|
|
286
|
-
|
|
303
|
+
mkdirSync3(this.root, { recursive: true, mode: 448 });
|
|
304
|
+
mkdirSync3(this.directory(value.agentId), { mode: 448 });
|
|
287
305
|
for (const dir of ["inbox", "completions", "reports", "permissions", "elicitations"]) privateDirectory(this.directory(value.agentId), dir);
|
|
288
306
|
this.write(value.agentId, "descriptor.json", value, descriptor, true);
|
|
289
307
|
this.write(value.agentId, "launch.json", run, launch, true);
|
|
@@ -325,10 +343,10 @@ var AgentFiles = class {
|
|
|
325
343
|
/** Short controller edits are serialized; an abandoned lock fails closed. */
|
|
326
344
|
control(work) {
|
|
327
345
|
this.check();
|
|
328
|
-
|
|
346
|
+
mkdirSync3(this.root, { recursive: true, mode: 448 });
|
|
329
347
|
const path = join3(this.root, ".control");
|
|
330
348
|
try {
|
|
331
|
-
|
|
349
|
+
mkdirSync3(path, { mode: 448 });
|
|
332
350
|
} catch (error2) {
|
|
333
351
|
if (error2.code !== "EEXIST") throw error2;
|
|
334
352
|
throw Object.assign(new Error("\u5B50\u4F1A\u8BDD\u63A7\u5236\u6B63\u5728\u8FDB\u884C\uFF1B\u7A0D\u540E\u91CD\u8BD5\u3002\u5D29\u6E83\u9057\u7559\u7684 .control \u9700\u505C\u6B62\u76F8\u5173\u6267\u884C\u5B9E\u4F8B\u540E\u624B\u52A8\u79FB\u9664\u3002"), { code: "PBOT_CONTROL_BUSY" });
|
|
@@ -10477,7 +10495,7 @@ var dshAcpHarness = {
|
|
|
10477
10495
|
const patch = join5(context.directory, "acp-dsh-patch.json");
|
|
10478
10496
|
await writeFile(
|
|
10479
10497
|
patch,
|
|
10480
|
-
JSON.stringify([{ insert: [{ id: "pbot-acp-member", name: join5(context.packageRoot, "lib/extension/hosts/dsh/acp-
|
|
10498
|
+
JSON.stringify([{ insert: [{ id: "pbot-acp-member", name: join5(context.packageRoot, "lib/extension/hosts/dsh/acp-entry.js") }] }]) + "\n",
|
|
10481
10499
|
{ mode: 384 }
|
|
10482
10500
|
);
|
|
10483
10501
|
return {
|
|
@@ -10576,6 +10594,14 @@ var standardAcpPresets = [
|
|
|
10576
10594
|
configureHint: "\u8FD0\u884C agy \u5B8C\u6210\u767B\u5F55\u4E0E\u9ED8\u8BA4\u6A21\u578B\u914D\u7F6E\u3002",
|
|
10577
10595
|
nativeWorkspaceSkills: true
|
|
10578
10596
|
}),
|
|
10597
|
+
createGenericAcpHarness("qoder", {
|
|
10598
|
+
label: "Qoder CLI",
|
|
10599
|
+
aliases: ["qodercli", "qoder-cli"],
|
|
10600
|
+
nativeWorkspaceSkills: true,
|
|
10601
|
+
defaultCommand: { command: "qodercli", args: ["--acp"] },
|
|
10602
|
+
installHint: "\u5B89\u88C5 Qoder CLI\uFF08qodercli\uFF09",
|
|
10603
|
+
configureHint: "\u8FD0\u884C qodercli login \u5B8C\u6210\u767B\u5F55\u3002"
|
|
10604
|
+
}),
|
|
10579
10605
|
createGenericAcpHarness("codex", {
|
|
10580
10606
|
label: "OpenAI Codex",
|
|
10581
10607
|
aliases: ["openai-codex", "codex-cli"],
|
|
@@ -10998,7 +11024,7 @@ async function agentText(agent, root, coordinatorPrompt = "plugin-coordinator.md
|
|
|
10998
11024
|
function formatWorkspaceSkills(skills) {
|
|
10999
11025
|
if (!skills.length) return "";
|
|
11000
11026
|
const lines = skills.map((skill) => `- **${skill.name}**\uFF08\`${skill.path}\`\uFF09\uFF1A${skill.description}`);
|
|
11001
|
-
return "## \u5DE5\u4F5C\u533A\u6280\u80FD\n\n\
|
|
11027
|
+
return "## \u5DE5\u4F5C\u533A\u6280\u80FD\n\n\u5339\u914D\u4EFB\u52A1\u65F6\u6309\u9700\u8BFB\u53D6\u5BF9\u5E94 `SKILL.md` \u6B63\u6587\uFF1A\n" + lines.join("\n");
|
|
11002
11028
|
}
|
|
11003
11029
|
async function loadWorkspaceContext(options) {
|
|
11004
11030
|
const {
|
|
@@ -11034,10 +11060,15 @@ async function loadWorkspaceContext(options) {
|
|
|
11034
11060
|
// src/services/workspace/workspace-config.ts
|
|
11035
11061
|
import { mkdir, readFile as readFile2 } from "node:fs/promises";
|
|
11036
11062
|
import { dirname as dirname2, join as join8 } from "node:path";
|
|
11063
|
+
|
|
11064
|
+
// src/model/workspace-config.ts
|
|
11065
|
+
var summaryConcurrency = { default: 3, max: 8 };
|
|
11066
|
+
var historyLayouts = ["monthly", "flat"];
|
|
11067
|
+
|
|
11068
|
+
// src/services/workspace/workspace-config.ts
|
|
11037
11069
|
var featureKeys = ["prompts", "skills", "mcp", "history"];
|
|
11038
11070
|
var summaryKeys = ["backend", "model", "thinking", "concurrency"];
|
|
11039
11071
|
var historyKeys = ["layout"];
|
|
11040
|
-
var historyLayouts = ["monthly", "flat"];
|
|
11041
11072
|
function nonEmptyString(value) {
|
|
11042
11073
|
return typeof value === "string" && value.trim().length > 0 && !value.includes("\0");
|
|
11043
11074
|
}
|
|
@@ -11056,7 +11087,7 @@ function config2(value) {
|
|
|
11056
11087
|
}
|
|
11057
11088
|
for (const command of Object.values(value.acp)) {
|
|
11058
11089
|
const launch2 = !object(command) ? false : command.command === void 0 ? command.args === void 0 : typeof command.command === "string" && command.command.trim() && !command.command.includes("\0") && (command.args === void 0 || Array.isArray(command.args) && command.args.every((arg) => typeof arg === "string" && !arg.includes("\0")));
|
|
11059
|
-
if (!object(command) || !launch2 || command.env !== void 0 && (!object(command.env) || Object.entries(command.env).some(([k, v]) => !k || k.includes("\0") || typeof v !== "string" || v.includes("\0"))) || command.permission !== void 0 && !
|
|
11090
|
+
if (!object(command) || !launch2 || command.env !== void 0 && (!object(command.env) || Object.entries(command.env).some(([k, v]) => !k || k.includes("\0") || typeof v !== "string" || v.includes("\0"))) || command.permission !== void 0 && !isOneOf(command.permission, acpPermissionPolicies) || Object.keys(command).some((key) => !["command", "args", "env", "permission"].includes(key))) {
|
|
11060
11091
|
throw new Error("ACP \u914D\u7F6E\u9700\u8981 command\uFF08\u5185\u7F6E\u76EE\u6807\u53EF\u7701\u7565\uFF09\u53CA\u53EF\u9009 args \u5B57\u7B26\u4E32\u6570\u7EC4\u3001env \u5B57\u7B26\u4E32\u6620\u5C04\u3001permission\uFF08ask\u3001allow \u6216 deny\uFF09\u3002");
|
|
11061
11092
|
}
|
|
11062
11093
|
}
|
|
@@ -11074,15 +11105,15 @@ function config2(value) {
|
|
|
11074
11105
|
if (value.summary.thinking !== void 0 && !nonEmptyString(value.summary.thinking)) {
|
|
11075
11106
|
throw new Error("summary.thinking \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\u3002");
|
|
11076
11107
|
}
|
|
11077
|
-
if (value.summary.concurrency !== void 0 && (typeof value.summary.concurrency !== "number" || !Number.isInteger(value.summary.concurrency) || value.summary.concurrency < 1 || value.summary.concurrency >
|
|
11078
|
-
throw new Error(
|
|
11108
|
+
if (value.summary.concurrency !== void 0 && (typeof value.summary.concurrency !== "number" || !Number.isInteger(value.summary.concurrency) || value.summary.concurrency < 1 || value.summary.concurrency > summaryConcurrency.max)) {
|
|
11109
|
+
throw new Error(`summary.concurrency \u5FC5\u987B\u662F 1 \u5230 ${summaryConcurrency.max} \u4E4B\u95F4\u7684\u6574\u6570\u3002`);
|
|
11079
11110
|
}
|
|
11080
11111
|
}
|
|
11081
11112
|
if (value.history !== void 0) {
|
|
11082
11113
|
if (!object(value.history) || Object.keys(value.history).some((key) => !historyKeys.includes(key))) {
|
|
11083
11114
|
throw new Error("history \u5FC5\u987B\u662F JSON \u5BF9\u8C61\uFF0C\u4EC5\u652F\u6301 layout\u3002");
|
|
11084
11115
|
}
|
|
11085
|
-
if (value.history.layout !== void 0 && !
|
|
11116
|
+
if (value.history.layout !== void 0 && !isOneOf(value.history.layout, historyLayouts)) {
|
|
11086
11117
|
throw new Error('history.layout \u5FC5\u987B\u662F "monthly" \u6216 "flat"\u3002');
|
|
11087
11118
|
}
|
|
11088
11119
|
}
|
|
@@ -11140,15 +11171,13 @@ function isWorkspaceMcpHttpServer(server) {
|
|
|
11140
11171
|
}
|
|
11141
11172
|
function validateStringRecord(value, label) {
|
|
11142
11173
|
requireThat(object(value), `${label} \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6620\u5C04\u3002`);
|
|
11143
|
-
|
|
11144
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
11174
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => {
|
|
11145
11175
|
requireThat(
|
|
11146
11176
|
key.length > 0 && !key.includes("\0") && typeof entry === "string" && !entry.includes("\0"),
|
|
11147
11177
|
`${label}.${key} \u5FC5\u987B\u662F\u975E\u7A7A\u952E\u4E0E\u65E0\u7A7A\u5B57\u8282\u5B57\u7B26\u4E32\u503C\u3002`
|
|
11148
11178
|
);
|
|
11149
|
-
|
|
11150
|
-
}
|
|
11151
|
-
return result;
|
|
11179
|
+
return [key, entry];
|
|
11180
|
+
}));
|
|
11152
11181
|
}
|
|
11153
11182
|
function validateWorkspaceMcpServer(name, value) {
|
|
11154
11183
|
requireThat(serverNamePattern.test(name), `MCP \u670D\u52A1\u540D\u65E0\u6548\uFF1A${name}\uFF08\u9700\u5339\u914D [A-Za-z0-9][A-Za-z0-9_-]{0,31}\uFF09\u3002`);
|
|
@@ -11237,7 +11266,7 @@ function validateMcpFile(value) {
|
|
|
11237
11266
|
for (const [name, entry] of Object.entries(rawServers)) {
|
|
11238
11267
|
servers[name] = validateWorkspaceMcpServer(name, entry);
|
|
11239
11268
|
}
|
|
11240
|
-
return { mcpServers: servers };
|
|
11269
|
+
return { ...value, mcpServers: servers };
|
|
11241
11270
|
}
|
|
11242
11271
|
function workspaceMcpPath(root) {
|
|
11243
11272
|
return join9(root, ".pbot", "mcp.json");
|
|
@@ -11265,37 +11294,32 @@ function expandEnvTemplate(value, env, context) {
|
|
|
11265
11294
|
return resolved;
|
|
11266
11295
|
});
|
|
11267
11296
|
}
|
|
11297
|
+
function expandEnvRecord(values2, env, context) {
|
|
11298
|
+
return Object.fromEntries(Object.entries(values2 ?? {}).map(([key, value]) => [key, expandEnvTemplate(value, env, `${context}.${key}`)]));
|
|
11299
|
+
}
|
|
11268
11300
|
function resolveWorkspaceMcpServer(root, name, server, env = process.env) {
|
|
11269
11301
|
const timeout = server.timeout ?? defaultTimeoutSeconds;
|
|
11270
11302
|
if (isWorkspaceMcpHttpServer(server)) {
|
|
11271
11303
|
const url2 = expandEnvTemplate(server.url, env, `MCP \u670D\u52A1 "${name}" \u7684 url`);
|
|
11272
11304
|
requireThat(/^https?:\/\/.+/.test(url2), `MCP \u670D\u52A1 "${name}" \u5C55\u5F00\u540E\u7684 url \u5FC5\u987B\u4EE5 http:// \u6216 https:// \u5F00\u5934\u3002`);
|
|
11273
|
-
const headers = {};
|
|
11274
|
-
for (const [key, value] of Object.entries(server.headers ?? {})) {
|
|
11275
|
-
headers[key] = expandEnvTemplate(value, env, `MCP \u670D\u52A1 "${name}" \u7684 headers.${key}`);
|
|
11276
|
-
}
|
|
11277
11305
|
return {
|
|
11278
11306
|
transport: "http",
|
|
11279
11307
|
name,
|
|
11280
11308
|
url: url2,
|
|
11281
|
-
headers,
|
|
11309
|
+
headers: expandEnvRecord(server.headers, env, `MCP \u670D\u52A1 "${name}" \u7684 headers`),
|
|
11282
11310
|
...server.description ? { description: server.description } : {},
|
|
11283
11311
|
timeout
|
|
11284
11312
|
};
|
|
11285
11313
|
}
|
|
11286
11314
|
const command = expandEnvTemplate(server.command, env, `MCP \u670D\u52A1 "${name}" \u7684 command`);
|
|
11287
11315
|
const args2 = (server.args ?? []).map((arg, index) => expandEnvTemplate(arg, env, `MCP \u670D\u52A1 "${name}" \u7684 args[${index}]`));
|
|
11288
|
-
const resolvedEnv = {};
|
|
11289
|
-
for (const [key, value] of Object.entries(server.env ?? {})) {
|
|
11290
|
-
resolvedEnv[key] = expandEnvTemplate(value, env, `MCP \u670D\u52A1 "${name}" \u7684 env.${key}`);
|
|
11291
|
-
}
|
|
11292
11316
|
const cwd = server.cwd ? resolve4(root, expandEnvTemplate(server.cwd, env, `MCP \u670D\u52A1 "${name}" \u7684 cwd`)) : root;
|
|
11293
11317
|
return {
|
|
11294
11318
|
transport: "stdio",
|
|
11295
11319
|
name,
|
|
11296
11320
|
command,
|
|
11297
11321
|
args: args2,
|
|
11298
|
-
env:
|
|
11322
|
+
env: expandEnvRecord(server.env, env, `MCP \u670D\u52A1 "${name}" \u7684 env`),
|
|
11299
11323
|
cwd,
|
|
11300
11324
|
...server.description ? { description: server.description } : {},
|
|
11301
11325
|
timeout
|
|
@@ -11361,7 +11385,9 @@ function parseSkillFrontmatter(content) {
|
|
|
11361
11385
|
};
|
|
11362
11386
|
}
|
|
11363
11387
|
async function discoverWorkspaceSkills(root) {
|
|
11364
|
-
|
|
11388
|
+
return discoverSkills(join10(root, ".agents", "skills"), ".agents/skills");
|
|
11389
|
+
}
|
|
11390
|
+
async function discoverSkills(skillsDir, indexPath) {
|
|
11365
11391
|
let entries;
|
|
11366
11392
|
try {
|
|
11367
11393
|
entries = await readdir(skillsDir, { withFileTypes: true });
|
|
@@ -11384,7 +11410,7 @@ async function discoverWorkspaceSkills(root) {
|
|
|
11384
11410
|
results.push({
|
|
11385
11411
|
name: meta2.name,
|
|
11386
11412
|
description: meta2.description,
|
|
11387
|
-
path:
|
|
11413
|
+
path: join10(indexPath, entry.name, "SKILL.md")
|
|
11388
11414
|
});
|
|
11389
11415
|
}
|
|
11390
11416
|
results.sort((a, b) => a.name.localeCompare(b.name));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const name: string, inject: string[], apply: typeof import("./acp-member.js").apply;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { registerHooks } from "node:module";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
// Keep normal dsh profile resolution. A standalone plugin cache has no SDK
|
|
5
|
+
// peers of its own, so resolve missing peers from the running dsh installation.
|
|
6
|
+
const memberLib = new URL("../../../", import.meta.url).href;
|
|
7
|
+
const peers = registerHooks({
|
|
8
|
+
resolve(specifier, context, nextResolve) {
|
|
9
|
+
if (specifier.startsWith("@deepseek-ai/") && context.parentURL?.startsWith(memberLib)) {
|
|
10
|
+
try {
|
|
11
|
+
return nextResolve(specifier, context);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (error.code !== "ERR_MODULE_NOT_FOUND" || !process.argv[1])
|
|
15
|
+
throw error;
|
|
16
|
+
return nextResolve(specifier, { ...context, parentURL: pathToFileURL(realpathSync(process.argv[1])).href });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return nextResolve(specifier, context);
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
export const { name, inject, apply } = await import("./acp-member.js").finally(() => peers.deregister());
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as McpClient from "@deepseek-ai/dsh-mcp-client";
|
|
2
|
+
import { acpMember } from "../../acp/member.js";
|
|
3
|
+
import { rootAgents } from "../../../integrations/hosts/dsh/root-agents.js";
|
|
4
|
+
import { dshResources, dshExpertTools } from "../../../integrations/hosts/dsh/resources.js";
|
|
5
|
+
import { registerDshSkills } from "../../../integrations/hosts/dsh/skills.js";
|
|
6
|
+
import { toDshMcpConfig } from "../../../integrations/hosts/dsh/mcp.js";
|
|
7
|
+
import { finalDshAnswer } from "../../../integrations/hosts/dsh/messages.js";
|
|
8
|
+
import { loadNativeWorkspaceServers } from "../workspace-mcp.js";
|
|
9
|
+
import { registerDshFileEvents } from "./files.js";
|
|
10
|
+
import { requireThat } from "../../../common/validation.js";
|
|
11
|
+
export const name = "pbot-acp-member";
|
|
12
|
+
export const inject = ["agents", "sessions", "llm", "tools", "systemPrompt", "skills", "fs", "workingDirectory", "approval"];
|
|
13
|
+
export async function apply(ctx) {
|
|
14
|
+
const member = await acpMember();
|
|
15
|
+
ctx.on("agent/pre-step", async (_event, next) => {
|
|
16
|
+
if (process.env.PBOT_ACP_VALIDATE === "1")
|
|
17
|
+
return { kind: "reject" };
|
|
18
|
+
member.input();
|
|
19
|
+
return next();
|
|
20
|
+
});
|
|
21
|
+
ctx.on("agent/created", async ({ agent, source }) => {
|
|
22
|
+
if (!rootAgents(ctx.agents).includes(agent))
|
|
23
|
+
return;
|
|
24
|
+
if (source === "resume")
|
|
25
|
+
agent.inbox.clear();
|
|
26
|
+
const reference = member.files.reference(member.id);
|
|
27
|
+
requireThat(reference.host === "acp" && reference.backend === "dsh" && agent.session.header.cwd === member.d.cwd &&
|
|
28
|
+
(reference.sessionId === null || reference.sessionId === agent.id), "dsh ACP 会话身份或工作目录不匹配。");
|
|
29
|
+
await agent.ctx.plugin({ name: "pbot-acp-expert", inject, apply: async (scope) => {
|
|
30
|
+
if (member.features.skills)
|
|
31
|
+
registerDshSkills(scope, agent, { workspaceRoot: member.d.workspace });
|
|
32
|
+
if (member.features.mcp && process.env.PBOT_ACP_VALIDATE !== "1") {
|
|
33
|
+
await loadNativeWorkspaceServers(member.d.workspace, async (server) => {
|
|
34
|
+
await scope.plugin(McpClient, toDshMcpConfig(server));
|
|
35
|
+
}, { warn: message => ctx.logger.warn(message) });
|
|
36
|
+
}
|
|
37
|
+
dshExpertTools(scope, agent, member.d.options);
|
|
38
|
+
if (member.features.prompts)
|
|
39
|
+
await dshResources(scope, agent, member.d.workspace, "general-purpose", member.check);
|
|
40
|
+
registerDshFileEvents(scope, agent, member.d.workspace, true, member.check);
|
|
41
|
+
let input, answer = "";
|
|
42
|
+
scope.on("session/event", (session, event) => {
|
|
43
|
+
if (session !== agent.session)
|
|
44
|
+
return;
|
|
45
|
+
if (event.type === "turn/start") {
|
|
46
|
+
input = member.input();
|
|
47
|
+
answer = "";
|
|
48
|
+
}
|
|
49
|
+
if (event.type === "assistant/message")
|
|
50
|
+
answer = finalDshAnswer(event);
|
|
51
|
+
if (event.type === "turn/end" && input) {
|
|
52
|
+
const reason = event.data.reason;
|
|
53
|
+
member.answer(input, reason.kind === "completed" && answer.trim() ? "completed" : reason.kind === "aborted" ? "cancelled" : "failed", answer, reason.kind === "error" ? reason.error.message : reason.kind === "completed" ? undefined : reason.kind);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
} });
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
/** Native filesystem mutations share the original workspace's confirmation rule.
|
|
4
|
+
* This does not confine Bash, Python, MCP, or other extensions. */
|
|
5
|
+
export declare function registerDshFileEvents(ctx: Context, agent: Agent, root: string, expert: boolean, check: () => void): void;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { parsePatch } from "@deepseek-ai/dsh-fs-patch";
|
|
2
|
+
import { object } from "../../../common/json.js";
|
|
3
|
+
import { requireThat } from "../../../common/validation.js";
|
|
4
|
+
import { mutationScope } from "../../../services/workspace/workspace-files.js";
|
|
5
|
+
/** Native filesystem mutations share the original workspace's confirmation rule.
|
|
6
|
+
* This does not confine Bash, Python, MCP, or other extensions. */
|
|
7
|
+
export function registerDshFileEvents(ctx, agent, root, expert, check) {
|
|
8
|
+
const lifetime = new AbortController();
|
|
9
|
+
const mutations = new Set(["write", "edit", "apply_patch"]);
|
|
10
|
+
const captured = new Map();
|
|
11
|
+
ctx.effect(() => () => { lifetime.abort(); captured.clear(); });
|
|
12
|
+
async function targets(exec) {
|
|
13
|
+
check();
|
|
14
|
+
const args = exec.arguments;
|
|
15
|
+
requireThat(exec.agent === agent && object(args), "文件操作会话或参数无效。");
|
|
16
|
+
const signal = AbortSignal.any([lifetime.signal, exec.signal]);
|
|
17
|
+
signal.throwIfAborted();
|
|
18
|
+
let paths;
|
|
19
|
+
if (exec.name === "apply_patch") {
|
|
20
|
+
requireThat(typeof args.input === "string", "补丁参数无效。");
|
|
21
|
+
paths = parsePatch(args.input).flatMap(operation => [operation.path, ...(operation.kind === "update" && operation.moveTo ? [operation.moveTo] : [])]);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
requireThat(typeof args.file_path === "string" && args.file_path.trim().length > 0, "文件路径无效。");
|
|
25
|
+
paths = [args.file_path];
|
|
26
|
+
}
|
|
27
|
+
const anchor = ctx.fs.processPathFromHostPath(root);
|
|
28
|
+
requireThat(anchor !== undefined, "原生文件系统未映射当前工作区。");
|
|
29
|
+
const cwd = ctx.workingDirectory.get(agent.session);
|
|
30
|
+
const resolved = await Promise.all(paths.map(path => ctx.fs.resolve(path, { cwd, signal })));
|
|
31
|
+
signal.throwIfAborted();
|
|
32
|
+
check();
|
|
33
|
+
const outside = resolved.map(target => ctx.fs.processPath(target)).filter(path => mutationScope(anchor, path) === "outside");
|
|
34
|
+
return { cwd, keys: resolved.map(target => target.targetKey), outside, signal };
|
|
35
|
+
}
|
|
36
|
+
ctx.on("tools/pre-execute", async (exec, next) => {
|
|
37
|
+
if (!mutations.has(exec.name))
|
|
38
|
+
return next();
|
|
39
|
+
const value = await targets(exec), record = { cwd: value.cwd, keys: value.keys, approved: !value.outside.length };
|
|
40
|
+
captured.set(exec.token, record);
|
|
41
|
+
if (value.outside.length && expert)
|
|
42
|
+
return { kind: "deny", reason: "专家不能修改工作区外文件。" };
|
|
43
|
+
const policy = await next();
|
|
44
|
+
value.signal.throwIfAborted();
|
|
45
|
+
check();
|
|
46
|
+
if (policy.kind === "deny" || policy.kind === "cancel" || !value.outside.length)
|
|
47
|
+
return policy;
|
|
48
|
+
const scopeReason = "Personal Bot: confirm changes outside the original workspace: " + JSON.stringify(value.outside);
|
|
49
|
+
const reason = [policy.kind === "ask" ? policy.reason : undefined, scopeReason].filter(Boolean).join("\n");
|
|
50
|
+
const outcome = await ctx.approval.request({ agent, toolName: exec.name, callId: exec.callId, signal: value.signal, reason,
|
|
51
|
+
displayReason: { en: reason, "zh-CN": "允许本次修改原工作区之外的文件:" + value.outside.join("、") + (policy.kind === "ask" && policy.reason ? "\n" + policy.reason : "") } });
|
|
52
|
+
value.signal.throwIfAborted();
|
|
53
|
+
check();
|
|
54
|
+
record.approved = outcome === "allowed-once";
|
|
55
|
+
return record.approved ? { kind: "allow" } : { kind: "deny", reason: "用户未确认文件修改。" };
|
|
56
|
+
});
|
|
57
|
+
ctx.on("tools/execute", async (exec, next) => {
|
|
58
|
+
if (!mutations.has(exec.name))
|
|
59
|
+
return next();
|
|
60
|
+
const record = captured.get(exec.token);
|
|
61
|
+
requireThat(record?.approved, "文件操作没有有效的范围检查或确认。");
|
|
62
|
+
const value = await targets(exec);
|
|
63
|
+
requireThat(record.cwd === value.cwd && record.keys.length === value.keys.length && record.keys.every((key, index) => key === value.keys[index]), "确认期间文件路径或工作目录已变化。");
|
|
64
|
+
return next();
|
|
65
|
+
});
|
|
66
|
+
ctx.on("tools/result", exec => { captured.delete(exec.token); });
|
|
67
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { isMcpWorkerTool } from "../../../model/acp.js";
|
|
5
|
+
import { acpMember } from "../../acp/member.js";
|
|
6
|
+
import { agentFileTools } from "../../../integrations/hosts/pi/agent-tools.js";
|
|
7
|
+
import { toPiMcpConfig } from "../../../integrations/hosts/pi/mcp.js";
|
|
8
|
+
import { authorizeMutation } from "../../../services/workspace/workspace-files.js";
|
|
9
|
+
import { loadNativeWorkspaceServers } from "../workspace-mcp.js";
|
|
10
|
+
import { resourceRoot } from "../../../common/paths.js";
|
|
11
|
+
import { launch } from "../../../storage/agent-files.js";
|
|
12
|
+
import { requireThat } from "../../../common/validation.js";
|
|
13
|
+
const isBlockedTool = (name) => name === "pbot_history" || isMcpWorkerTool(name);
|
|
14
|
+
/** Member resources and authoritative final answers; ACP owns input delivery. */
|
|
15
|
+
export default async function piAcpMember(pi) {
|
|
16
|
+
const member = await acpMember(), lifetime = new AbortController();
|
|
17
|
+
const registeredMcp = [];
|
|
18
|
+
let input, startLeaf = null;
|
|
19
|
+
const checkSession = (ctx) => {
|
|
20
|
+
const reference = member.files.reference(member.id);
|
|
21
|
+
requireThat(reference.host === "acp" && reference.backend === "pi" && realpathSync(ctx.cwd) === member.d.cwd &&
|
|
22
|
+
(reference.sessionId === null || reference.sessionId === ctx.sessionManager.getSessionId()), "Pi ACP 会话身份或工作目录不匹配。");
|
|
23
|
+
};
|
|
24
|
+
const workspaceMcpServers = [];
|
|
25
|
+
if (member.features.mcp && process.env.PBOT_ACP_VALIDATE !== "1") {
|
|
26
|
+
await loadNativeWorkspaceServers(member.d.workspace, server => { workspaceMcpServers.push(server); });
|
|
27
|
+
}
|
|
28
|
+
pi.on("resources_discover", async () => {
|
|
29
|
+
if (!member.features.skills || member.d.options.noSkills)
|
|
30
|
+
return {};
|
|
31
|
+
const skillPaths = [join(resourceRoot, "skills")], workspaceSkills = join(member.d.workspace, ".agents/skills");
|
|
32
|
+
try {
|
|
33
|
+
if ((await stat(workspaceSkills)).isDirectory())
|
|
34
|
+
skillPaths.push(workspaceSkills);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (error.code !== "ENOENT")
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
return { skillPaths };
|
|
41
|
+
});
|
|
42
|
+
pi.on("session_start", (_event, ctx) => {
|
|
43
|
+
checkSession(ctx);
|
|
44
|
+
const active = pi.getActiveTools();
|
|
45
|
+
for (const tool of agentFileTools(member.d.cwd, lifetime.signal, async (path, change, signal) => {
|
|
46
|
+
member.check();
|
|
47
|
+
await authorizeMutation(member.d.workspace, path, change, async () => false, signal);
|
|
48
|
+
member.check();
|
|
49
|
+
}))
|
|
50
|
+
pi.registerTool(tool);
|
|
51
|
+
for (const server of workspaceMcpServers) {
|
|
52
|
+
pi.registerMcpServer(server.name, toPiMcpConfig(server));
|
|
53
|
+
registeredMcp.push(server.name);
|
|
54
|
+
}
|
|
55
|
+
pi.setActiveTools(active.filter(name => !isBlockedTool(name)));
|
|
56
|
+
pi.setSessionName(member.files.read(member.id, "launch.json", launch).name);
|
|
57
|
+
startLeaf = ctx.sessionManager.getLeafId();
|
|
58
|
+
});
|
|
59
|
+
pi.on("before_agent_start", async (event, ctx) => {
|
|
60
|
+
try {
|
|
61
|
+
checkSession(ctx);
|
|
62
|
+
const current = member.input();
|
|
63
|
+
if (current.requestId !== input?.requestId) {
|
|
64
|
+
input = current;
|
|
65
|
+
startLeaf = ctx.sessionManager.getLeafId();
|
|
66
|
+
}
|
|
67
|
+
if (!member.features.prompts)
|
|
68
|
+
return;
|
|
69
|
+
const context = await member.context();
|
|
70
|
+
member.check();
|
|
71
|
+
Object.assign(event.systemPromptOptions.sections, { pbot_workspace: context.workspace, pbot_child: context.role, pbot_environment: context.environment });
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
ctx.abort();
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
pi.on("tool_call", event => {
|
|
79
|
+
member.check();
|
|
80
|
+
if (isBlockedTool(event.toolName))
|
|
81
|
+
return { block: true, reason: "专家不提供协调管理工具。" };
|
|
82
|
+
return;
|
|
83
|
+
});
|
|
84
|
+
pi.on("agent_settled", (event, ctx) => {
|
|
85
|
+
if (!input)
|
|
86
|
+
return;
|
|
87
|
+
const branch = ctx.sessionManager.getBranch(), at = startLeaf === null ? -1 : branch.findIndex(entry => entry.id === startLeaf);
|
|
88
|
+
const last = branch.slice(at + 1).findLast(entry => entry.type === "message" && entry.message.role === "assistant");
|
|
89
|
+
const assistant = last?.type === "message" && last.message.role === "assistant" ? last.message : undefined;
|
|
90
|
+
const answer = assistant?.content.filter(block => block.type === "text").map(block => block.text).join("\n") ?? "";
|
|
91
|
+
member.answer(input, event.aborted ? "cancelled" : assistant?.stopReason === "stop" ? "completed" : "failed", answer, assistant?.errorMessage);
|
|
92
|
+
});
|
|
93
|
+
pi.on("session_before_switch", () => ({ cancel: true }));
|
|
94
|
+
pi.on("session_before_fork", () => ({ cancel: true }));
|
|
95
|
+
pi.on("session_shutdown", () => {
|
|
96
|
+
for (const name of registeredMcp.splice(0))
|
|
97
|
+
pi.unregisterMcpServer(name);
|
|
98
|
+
lifetime.abort();
|
|
99
|
+
});
|
|
100
|
+
}
|
|
@@ -5,6 +5,8 @@ export declare function pluginCommand(adapter: PluginHostAdapter, args: readonly
|
|
|
5
5
|
resourceRoot: string;
|
|
6
6
|
configuration: import("../../model/workspace-config.js").WorkspaceConfiguration;
|
|
7
7
|
}>;
|
|
8
|
-
export
|
|
8
|
+
export type ReplayPluginHook = (root: string, input: string) => Promise<number | undefined>;
|
|
9
|
+
export declare function runPluginHost(adapter: PluginHostAdapter, args: readonly string[], replay?: ReplayPluginHook): Promise<void>;
|
|
9
10
|
/** Shared hook execution engine; host-specific protocols stay in PluginHostAdapter implementations. */
|
|
10
11
|
export declare function pluginHook(adapter: PluginHostAdapter, payload: unknown): Promise<Record<string, unknown>>;
|
|
12
|
+
export declare function pluginHook(adapter: PluginHostAdapter, payload: unknown, replay: ((root: string) => Promise<number | undefined>) | undefined): Promise<Record<string, unknown> | number>;
|