personal-bot 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +2 -1
- package/DISCLAIMER.md +17 -0
- package/LICENSE +21 -0
- package/README.md +15 -5
- package/README.zh-CN.md +15 -5
- package/bin/pbot-pi-acp.mjs +1 -1
- package/bin/pbot.mjs +22 -2
- package/docs/README.md +2 -0
- package/docs/architecture/design.md +16 -16
- package/docs/architecture/extensibility.md +8 -2
- package/docs/architecture/model-context.md +3 -2
- package/docs/architecture/principles.md +2 -2
- package/docs/guides/capabilities.md +1 -1
- package/docs/guides/cross-harness-workers.md +3 -1
- package/docs/guides/history.md +30 -7
- package/docs/guides/workspace-configuration.md +7 -3
- package/docs/hosts/antigravity.md +1 -1
- package/docs/hosts/claude-code.md +1 -1
- package/docs/hosts/codex-qoder.md +63 -0
- package/docs/maintainers/architecture-governance.md +78 -0
- package/lib/antigravity-plugin/DISCLAIMER.md +17 -0
- package/lib/antigravity-plugin/LICENSE +21 -0
- package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +36 -0
- package/lib/antigravity-plugin/lib/common/files.d.ts +2 -0
- package/lib/antigravity-plugin/lib/common/files.js +44 -0
- package/lib/antigravity-plugin/lib/common/validation.d.ts +4 -0
- package/lib/antigravity-plugin/lib/common/validation.js +8 -0
- package/lib/antigravity-plugin/lib/extension/acp/member.d.ts +18 -0
- package/lib/antigravity-plugin/lib/extension/acp/member.js +44 -0
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +71 -45
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.js +22 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.d.ts +4 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.js +58 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.d.ts +5 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.js +67 -0
- package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.d.ts +3 -0
- package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +100 -0
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.d.ts +3 -1
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +31 -23
- package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.d.ts +6 -0
- package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.js +21 -0
- package/lib/antigravity-plugin/lib/extension/mcp.js +2577 -2255
- package/lib/antigravity-plugin/lib/extension/workspace-cli.js +20127 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +7 -59
- package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.d.ts +2 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.js +14 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.js +28 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.d.ts +36 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.js +11 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.d.ts +6 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.js +47 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.js +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.d.ts +8 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.js +31 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.js +32 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.js +23 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.d.ts +1 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.js +8 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.js +76 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.js +16 -0
- package/lib/antigravity-plugin/lib/model/acp.d.ts +7 -3
- package/lib/antigravity-plugin/lib/model/acp.js +8 -0
- package/lib/antigravity-plugin/lib/model/agent.d.ts +121 -0
- package/lib/antigravity-plugin/lib/model/agent.js +4 -0
- package/lib/antigravity-plugin/lib/model/history.d.ts +10 -0
- package/lib/antigravity-plugin/lib/model/history.js +4 -1
- package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +5 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +8 -12
- package/lib/antigravity-plugin/lib/model/workspace-config.js +2 -1
- package/lib/antigravity-plugin/lib/plugin.d.ts +2 -1
- package/lib/antigravity-plugin/lib/plugin.js +2 -2
- package/lib/antigravity-plugin/lib/services/history/history-capture.js +34 -22
- package/lib/antigravity-plugin/lib/services/history/summary-registry.js +2 -3
- package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +2 -5
- package/lib/antigravity-plugin/lib/services/history/summary-runner.js +72 -74
- package/lib/antigravity-plugin/lib/services/history/workspace-history.d.ts +3 -0
- package/lib/antigravity-plugin/lib/services/history/workspace-history.js +6 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +3 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +78 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +9 -8
- package/lib/antigravity-plugin/lib/services/workspace/workspace-files.d.ts +2 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-files.js +17 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.d.ts +14 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.js +193 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.d.ts +1 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.js +4 -2
- package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +11 -0
- package/lib/antigravity-plugin/lib/storage/acp-files.js +75 -0
- package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +31 -0
- package/lib/antigravity-plugin/lib/storage/agent-files.js +159 -0
- package/lib/antigravity-plugin/lib/storage/atomic-json.d.ts +3 -1
- package/lib/antigravity-plugin/lib/storage/atomic-json.js +43 -3
- package/lib/antigravity-plugin/lib/storage/history-files.d.ts +2 -1
- package/lib/antigravity-plugin/lib/storage/history-files.js +21 -15
- package/lib/antigravity-plugin/lib/storage/history-format.d.ts +2 -3
- package/lib/antigravity-plugin/lib/storage/history-format.js +5 -7
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +1 -1
- package/lib/antigravity-plugin/resources/prompts/history-monthly-summary.md +13 -0
- package/lib/antigravity-plugin/resources/prompts/history-summary.md +13 -0
- package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -0
- package/lib/antigravity-plugin/resources/skills/.claude-plugin/plugin.json +4 -0
- package/lib/antigravity-plugin/resources/skills/project-maintenance/SKILL.md +35 -0
- package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +52 -0
- package/lib/antigravity-plugin/skills/pbot/SKILL.md +11 -1
- package/lib/client.js +22 -50
- package/lib/codex-marketplace/.agents/plugins/marketplace.json +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +7 -0
- package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/DISCLAIMER.md +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/LICENSE +21 -0
- package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +37 -0
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +9 -0
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/agents/openai.yaml +2 -0
- package/lib/common/validation.d.ts +4 -0
- package/lib/common/validation.js +8 -0
- package/lib/dsh.js +2 -2
- package/lib/extension/acp/member.d.ts +1 -1
- package/lib/extension/acp-worker.js +71 -45
- package/lib/extension/history/command.d.ts +37 -0
- package/lib/extension/history/command.js +57 -0
- package/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
- package/lib/extension/hosts/dsh/acp-entry.js +22 -0
- package/lib/extension/hosts/dsh/acp-member.js +4 -18
- package/lib/extension/hosts/dsh/command.d.ts +1 -2
- package/lib/extension/hosts/dsh/command.js +5 -49
- package/lib/extension/hosts/dsh/workspace.js +13 -44
- package/lib/extension/hosts/pi/acp-member.d.ts +3 -0
- package/lib/extension/hosts/pi/acp-member.js +100 -0
- package/lib/extension/hosts/plugin-runtime.d.ts +3 -1
- package/lib/extension/hosts/plugin-runtime.js +31 -23
- package/lib/extension/hosts/workspace-mcp.d.ts +6 -0
- package/lib/extension/hosts/workspace-mcp.js +21 -0
- package/lib/extension/mcp/bridge.d.ts +6 -8
- package/lib/extension/mcp/bridge.js +66 -84
- package/lib/extension/mcp/tool-contract.d.ts +735 -0
- package/lib/extension/mcp/tool-contract.js +441 -0
- package/lib/extension/mcp/workers.d.ts +29 -742
- package/lib/extension/mcp/workers.js +75 -525
- package/lib/extension/mcp.js +2577 -2255
- package/lib/extension/setup/cli.js +3 -0
- package/lib/extension/workspace-cli.js +20127 -0
- package/lib/integrations/acp/agents.d.ts +2 -3
- package/lib/integrations/acp/harnesses/dsh.js +1 -1
- package/lib/integrations/acp/harnesses/presets.js +8 -0
- package/lib/integrations/acp/history-summary.js +2 -1
- package/lib/integrations/acp/launch.d.ts +2 -2
- package/lib/integrations/agent-resources.js +1 -1
- package/lib/integrations/hosts/claude/adapter.js +7 -59
- package/lib/integrations/hosts/codex/adapter.d.ts +2 -0
- package/lib/integrations/hosts/codex/adapter.js +14 -0
- package/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
- package/lib/integrations/hosts/pi/agent-tools.js +32 -0
- package/lib/integrations/hosts/pi/mcp.d.ts +4 -0
- package/lib/integrations/hosts/pi/mcp.js +23 -0
- package/lib/integrations/hosts/plugin-registry.d.ts +1 -0
- package/lib/integrations/hosts/plugin-registry.js +8 -1
- package/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
- package/lib/integrations/hosts/prompt-hooks.js +76 -0
- package/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
- package/lib/integrations/hosts/qoder/adapter.js +16 -0
- package/lib/model/acp.d.ts +7 -3
- package/lib/model/acp.js +8 -0
- package/lib/model/agent.d.ts +18 -4
- package/lib/model/agent.js +4 -1
- package/lib/model/history.d.ts +10 -0
- package/lib/model/history.js +4 -1
- package/lib/model/installation.js +1 -0
- package/lib/model/plugin-host.d.ts +5 -0
- package/lib/model/workspace-config.d.ts +8 -12
- package/lib/model/workspace-config.js +2 -1
- package/lib/plugin.d.ts +2 -1
- package/lib/plugin.js +2 -2
- package/lib/qoder-plugin/.mcp.json +17 -0
- package/lib/qoder-plugin/.qoder-plugin/plugin.json +7 -0
- package/lib/qoder-plugin/DISCLAIMER.md +17 -0
- package/lib/qoder-plugin/LICENSE +21 -0
- package/lib/qoder-plugin/hooks/hooks.json +37 -0
- package/lib/qoder-plugin/skills/pbot/SKILL.md +9 -0
- package/lib/services/agents/agent-service.d.ts +15 -45
- package/lib/services/agents/agent-service.js +22 -3
- package/lib/services/history/history-capture.js +34 -22
- package/lib/services/history/history-migrate.js +26 -60
- package/lib/services/history/history-query.js +38 -57
- package/lib/services/history/summary-command.d.ts +1 -1
- package/lib/services/history/summary-command.js +8 -7
- package/lib/services/history/summary-registry.js +2 -3
- package/lib/services/history/summary-runner.d.ts +2 -5
- package/lib/services/history/summary-runner.js +72 -74
- package/lib/services/history/workspace-history.d.ts +3 -0
- package/lib/services/history/workspace-history.js +6 -0
- package/lib/services/workspace/plugin-releases.d.ts +3 -0
- package/lib/services/workspace/plugin-releases.js +78 -0
- package/lib/services/workspace/workspace-config.js +9 -8
- package/lib/services/workspace/workspace-mcp.js +22 -29
- package/lib/services/workspace/workspace-skills.d.ts +1 -0
- package/lib/services/workspace/workspace-skills.js +4 -2
- package/lib/storage/acp-files.js +7 -12
- package/lib/storage/agent-files.js +6 -5
- package/lib/storage/atomic-json.d.ts +3 -1
- package/lib/storage/atomic-json.js +43 -3
- package/lib/storage/history-files.d.ts +2 -1
- package/lib/storage/history-files.js +21 -15
- package/lib/storage/history-format.d.ts +2 -3
- package/lib/storage/history-format.js +5 -7
- package/lib/tools/history/contract.d.ts +3 -11
- package/lib/tools/history/contract.js +8 -7
- package/lib/ui/dsh/elements.d.ts +2 -5
- package/lib/ui/dsh/elements.js +3 -16
- package/lib/ui/dsh/management.js +9 -9
- package/lib/ui/dsh/styles.d.ts +1 -1
- package/lib/ui/dsh/styles.js +5 -33
- package/package.json +4 -1
- package/resources/antigravity/skills/pbot/SKILL.md +11 -1
- package/resources/claude/skills/pbot/SKILL.md +11 -1
- package/resources/plugin/skills/pbot/SKILL.md +9 -0
- package/resources/prompts/history-coordinator.md +1 -0
- package/resources/prompts/plugin-coordinator.md +1 -0
- package/scripts/README.md +3 -2
- package/src/common/validation.ts +10 -0
- package/src/dsh.ts +2 -2
- package/src/extension/history/command.ts +68 -0
- package/src/extension/hosts/dsh/acp-entry.ts +21 -0
- package/src/extension/hosts/dsh/acp-member.ts +4 -15
- package/src/extension/hosts/dsh/command.ts +6 -46
- package/src/extension/hosts/dsh/workspace.ts +12 -38
- package/src/extension/hosts/pi/acp-member.ts +4 -10
- package/src/extension/hosts/pi/command.ts +14 -63
- package/src/extension/hosts/pi/events.ts +2 -8
- package/src/extension/hosts/pi/lifecycle.ts +3 -2
- package/src/extension/hosts/plugin-runtime.ts +32 -19
- package/src/extension/hosts/workspace-mcp.ts +25 -0
- package/src/extension/mcp/bridge.ts +80 -80
- package/src/extension/mcp/tool-contract.ts +462 -0
- package/src/extension/mcp/workers.ts +81 -551
- package/src/extension/setup/cli.ts +4 -1
- package/src/extension/setup/workspace-cli.ts +159 -0
- package/src/integrations/acp/agents.ts +2 -3
- package/src/integrations/acp/harnesses/dsh.ts +1 -1
- package/src/integrations/acp/harnesses/presets.ts +8 -0
- package/src/integrations/acp/history-summary.ts +2 -1
- package/src/integrations/agent-resources.ts +1 -1
- package/src/integrations/hosts/claude/adapter.ts +7 -53
- package/src/integrations/hosts/codex/adapter.ts +16 -0
- package/src/integrations/hosts/plugin-registry.ts +9 -1
- package/src/integrations/hosts/prompt-hooks.ts +72 -0
- package/src/integrations/hosts/qoder/adapter.ts +19 -0
- package/src/integrations/installation/cli-update.ts +116 -0
- package/src/integrations/installation/pi-bridge.ts +1 -1
- package/src/integrations/installation/pi-setup.ts +1 -1
- package/src/integrations/installation/processes.ts +1 -1
- package/src/model/acp.ts +11 -3
- package/src/model/agent.ts +20 -4
- package/src/model/history.ts +5 -0
- package/src/model/installation.ts +41 -0
- package/src/model/plugin-host.ts +5 -1
- package/src/model/workspace-config.ts +6 -12
- package/src/pbot.ts +13 -32
- package/src/plugin.ts +3 -3
- package/src/services/agents/agent-service.ts +29 -17
- package/src/services/history/history-capture.ts +30 -22
- package/src/services/history/history-migrate.ts +23 -50
- package/src/services/history/history-query.ts +34 -48
- package/src/services/history/summary-command.ts +9 -8
- package/src/services/history/summary-registry.ts +2 -3
- package/src/services/history/summary-runner.ts +72 -81
- package/src/services/history/workspace-history.ts +8 -0
- package/src/services/installation/setup-service.ts +2 -41
- package/src/services/workspace/plugin-releases.ts +68 -0
- package/src/services/workspace/workspace-config.ts +9 -8
- package/src/services/workspace/workspace-mcp.ts +23 -28
- package/src/services/workspace/workspace-skills.ts +5 -2
- package/src/storage/acp-files.ts +7 -12
- package/src/storage/agent-files.ts +6 -5
- package/src/storage/atomic-json.ts +31 -4
- package/src/storage/history-files.ts +22 -15
- package/src/storage/history-format.ts +6 -8
- package/src/tools/history/contract.ts +9 -9
- package/src/tools/history/pi-tool.ts +6 -4
- package/src/ui/dsh/elements.ts +5 -12
- package/src/ui/dsh/management.ts +10 -10
- package/src/ui/dsh/styles.ts +5 -33
- package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +0 -12
- package/lib/antigravity-plugin/lib/services/history/history-migrate.js +0 -88
- package/lib/ui/presentation.d.ts +0 -3
- package/lib/ui/presentation.js +0 -12
- package/src/tools/access.ts +0 -7
- package/src/tools/register.ts +0 -21
- package/src/ui/presentation.ts +0 -12
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdirSync, readdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
5
|
+
import { object } from "../../common/json.js";
|
|
6
|
+
import { resourceRoot } from "../../common/paths.js";
|
|
7
|
+
import { requireThat } from "../../common/validation.js";
|
|
8
|
+
import { releaseLine } from "../../common/version.js";
|
|
9
|
+
import { readJsonFile, writeJsonFile } from "../../storage/atomic-json.js";
|
|
10
|
+
function bindingDirectory(root) {
|
|
11
|
+
const key = createHash("sha256").update(root).digest("hex");
|
|
12
|
+
return join(homedir(), ".pbot", "workspaces", key);
|
|
13
|
+
}
|
|
14
|
+
// Full plugins own a local manifest. Thin clients can supply the release stamped into their cached hooks.
|
|
15
|
+
function pluginBinding(value) {
|
|
16
|
+
requireThat(typeof value === "string", "无效的插件安装记录。");
|
|
17
|
+
if (!isAbsolute(value))
|
|
18
|
+
releaseLine(value);
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function permissionDenied(error) {
|
|
22
|
+
return ["EACCES", "EPERM", "EROFS"].includes(error.code ?? "");
|
|
23
|
+
}
|
|
24
|
+
/** Each host owns its file, including when two hosts activate the same canonical workspace concurrently. */
|
|
25
|
+
export function bindWorkspacePlugin(root, host, binding = resolve(resourceRoot, "../package.json")) {
|
|
26
|
+
const directory = bindingDirectory(root);
|
|
27
|
+
const file = encodeURIComponent(host) + ".json";
|
|
28
|
+
try {
|
|
29
|
+
if (readJsonFile(directory, file, pluginBinding) === binding)
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (permissionDenied(error))
|
|
34
|
+
return;
|
|
35
|
+
if (error.code !== "ENOENT")
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
40
|
+
writeJsonFile(directory, file, binding, pluginBinding);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (!permissionDenied(error))
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function workspacePluginReleases(root) {
|
|
48
|
+
const directory = bindingDirectory(root);
|
|
49
|
+
let files;
|
|
50
|
+
try {
|
|
51
|
+
files = readdirSync(directory);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error.code === "ENOENT" || permissionDenied(error))
|
|
55
|
+
return {};
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
const releases = Object.create(null);
|
|
59
|
+
for (const file of files.filter(name => name.endsWith(".json"))) {
|
|
60
|
+
const host = decodeURIComponent(file.slice(0, -5));
|
|
61
|
+
try {
|
|
62
|
+
const binding = readJsonFile(directory, file, pluginBinding);
|
|
63
|
+
if (!isAbsolute(binding)) {
|
|
64
|
+
releases[host] = binding;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const manifest = JSON.parse(readFileSync(binding, "utf8"));
|
|
68
|
+
requireThat(object(manifest) && typeof manifest.version === "string", "无效的插件安装清单:" + binding);
|
|
69
|
+
releaseLine(manifest.version);
|
|
70
|
+
releases[host] = manifest.version;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error.code !== "ENOENT" && !permissionDenied(error))
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return releases;
|
|
78
|
+
}
|
|
@@ -2,12 +2,13 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
import { mkdir, readFile } from "node:fs/promises";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { object } from "../../common/json.js";
|
|
5
|
-
import {
|
|
5
|
+
import { acpPermissionPolicies } from "../../model/acp.js";
|
|
6
|
+
import { historyLayouts, summaryConcurrency } from "../../model/workspace-config.js";
|
|
7
|
+
import { isAcpBackend, isOneOf } from "../../common/validation.js";
|
|
6
8
|
import { readJsonFile, writeJsonFile } from "../../storage/atomic-json.js";
|
|
7
9
|
const featureKeys = ["prompts", "skills", "mcp", "history"];
|
|
8
10
|
const summaryKeys = ["backend", "model", "thinking", "concurrency"];
|
|
9
11
|
const historyKeys = ["layout"];
|
|
10
|
-
const historyLayouts = ["monthly", "flat"];
|
|
11
12
|
function nonEmptyString(value) {
|
|
12
13
|
return typeof value === "string" && value.trim().length > 0 && !value.includes("\0");
|
|
13
14
|
}
|
|
@@ -33,7 +34,7 @@ function config(value) {
|
|
|
33
34
|
(command.args === undefined || (Array.isArray(command.args) && command.args.every(arg => typeof arg === "string" && !arg.includes("\0"))));
|
|
34
35
|
if (!object(command) || !launch ||
|
|
35
36
|
(command.env !== undefined && (!object(command.env) || Object.entries(command.env).some(([k, v]) => !k || k.includes("\0") || typeof v !== "string" || v.includes("\0")))) ||
|
|
36
|
-
(command.permission !== undefined && !
|
|
37
|
+
(command.permission !== undefined && !isOneOf(command.permission, acpPermissionPolicies)) ||
|
|
37
38
|
Object.keys(command).some(key => !["command", "args", "env", "permission"].includes(key))) {
|
|
38
39
|
throw new Error("ACP 配置需要 command(内置目标可省略)及可选 args 字符串数组、env 字符串映射、permission(ask、allow 或 deny)。");
|
|
39
40
|
}
|
|
@@ -53,15 +54,15 @@ function config(value) {
|
|
|
53
54
|
throw new Error("summary.thinking 必须是非空字符串。");
|
|
54
55
|
}
|
|
55
56
|
if (value.summary.concurrency !== undefined &&
|
|
56
|
-
(typeof value.summary.concurrency !== "number" || !Number.isInteger(value.summary.concurrency) || value.summary.concurrency < 1 || value.summary.concurrency >
|
|
57
|
-
throw new Error(
|
|
57
|
+
(typeof value.summary.concurrency !== "number" || !Number.isInteger(value.summary.concurrency) || value.summary.concurrency < 1 || value.summary.concurrency > summaryConcurrency.max)) {
|
|
58
|
+
throw new Error(`summary.concurrency 必须是 1 到 ${summaryConcurrency.max} 之间的整数。`);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
if (value.history !== undefined) {
|
|
61
62
|
if (!object(value.history) || Object.keys(value.history).some(key => !historyKeys.includes(key))) {
|
|
62
63
|
throw new Error("history 必须是 JSON 对象,仅支持 layout。");
|
|
63
64
|
}
|
|
64
|
-
if (value.history.layout !== undefined && !
|
|
65
|
+
if (value.history.layout !== undefined && !isOneOf(value.history.layout, historyLayouts)) {
|
|
65
66
|
throw new Error('history.layout 必须是 "monthly" 或 "flat"。');
|
|
66
67
|
}
|
|
67
68
|
}
|
|
@@ -86,7 +87,7 @@ export function workspaceSummaryConfig(configuration) {
|
|
|
86
87
|
backend: raw?.backend ?? "pi",
|
|
87
88
|
...(raw?.model ? { model: raw.model } : {}),
|
|
88
89
|
...(raw?.thinking ? { thinking: raw.thinking } : {}),
|
|
89
|
-
concurrency: raw?.concurrency ??
|
|
90
|
+
concurrency: raw?.concurrency ?? summaryConcurrency.default,
|
|
90
91
|
};
|
|
91
92
|
}
|
|
92
93
|
export function workspaceHistoryConfig(configuration) {
|
|
@@ -160,5 +161,5 @@ export async function initializeWorkspaceConfig(root) {
|
|
|
160
161
|
await initializeWorkspaceConfig(root);
|
|
161
162
|
}
|
|
162
163
|
export function workspaceDisabledMessage(configuration) {
|
|
163
|
-
return configuration.error ?? `Personal Bot
|
|
164
|
+
return configuration.error ?? `Personal Bot 未在此工作区启用。请在工作区根目录运行 pbot init,也可在 Pi 或 dsh 中执行 /pbot init。配置文件位于 ${configuration.path}`;
|
|
164
165
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { relative, isAbsolute } from "node:path";
|
|
2
|
+
import { mutationTarget } from "../../common/files.js";
|
|
3
|
+
import { requireThat } from "../../common/validation.js";
|
|
4
|
+
export function mutationScope(root, target) {
|
|
5
|
+
const rel = relative(root, target);
|
|
6
|
+
if (rel === ".." || rel.startsWith("../") || isAbsolute(rel))
|
|
7
|
+
return "outside";
|
|
8
|
+
return "inside";
|
|
9
|
+
}
|
|
10
|
+
export async function authorizeMutation(root, path, change, confirm, signal) {
|
|
11
|
+
signal.throwIfAborted();
|
|
12
|
+
const target = await mutationTarget(path), scope = mutationScope(root, target);
|
|
13
|
+
if (scope === "outside")
|
|
14
|
+
requireThat(await confirm({ path: target, change }), "用户未确认文件修改。");
|
|
15
|
+
signal.throwIfAborted();
|
|
16
|
+
requireThat(await mutationTarget(path) === target, "确认期间文件路径已变化。");
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ResolvedWorkspaceMcpServer, WorkspaceMcpConfiguration, WorkspaceMcpHttpServer, WorkspaceMcpServer } from "../../model/workspace-mcp.js";
|
|
2
|
+
export declare function isWorkspaceMcpServerName(name: string): boolean;
|
|
3
|
+
export declare function isWorkspaceMcpHttpServer(server: WorkspaceMcpServer): server is WorkspaceMcpHttpServer;
|
|
4
|
+
export declare function validateWorkspaceMcpServer(name: string, value: unknown): WorkspaceMcpServer;
|
|
5
|
+
export declare function workspaceMcpPath(root: string): string;
|
|
6
|
+
export declare function readWorkspaceMcpConfig(root: string): Promise<WorkspaceMcpConfiguration>;
|
|
7
|
+
export declare function expandEnvTemplate(value: string, env: NodeJS.ProcessEnv, context: string): string;
|
|
8
|
+
export declare function resolveWorkspaceMcpServer(root: string, name: string, server: WorkspaceMcpServer, env?: NodeJS.ProcessEnv): ResolvedWorkspaceMcpServer;
|
|
9
|
+
export declare function resolveWorkspaceMcpServers(root: string, configuration: WorkspaceMcpConfiguration, env?: NodeJS.ProcessEnv): ResolvedWorkspaceMcpServer[];
|
|
10
|
+
export declare function upsertWorkspaceMcpServer(root: string, name: string, server: WorkspaceMcpServer): Promise<WorkspaceMcpConfiguration>;
|
|
11
|
+
export declare function removeWorkspaceMcpServer(root: string, name: string): Promise<{
|
|
12
|
+
removed: boolean;
|
|
13
|
+
configuration: WorkspaceMcpConfiguration;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { object } from "../../common/json.js";
|
|
4
|
+
import { requireThat } from "../../common/validation.js";
|
|
5
|
+
import { updateJsonFile } from "../../storage/atomic-json.js";
|
|
6
|
+
const serverNamePattern = /^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$/;
|
|
7
|
+
const reservedServerNames = new Set(["pbot"]);
|
|
8
|
+
const stdioKeys = new Set(["command", "args", "env", "cwd", "description", "timeout", "enabled"]);
|
|
9
|
+
const httpKeys = new Set(["url", "headers", "description", "timeout", "enabled"]);
|
|
10
|
+
const defaultTimeoutSeconds = 60;
|
|
11
|
+
const envPattern = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
12
|
+
export function isWorkspaceMcpServerName(name) {
|
|
13
|
+
return serverNamePattern.test(name) && !reservedServerNames.has(name.toLowerCase());
|
|
14
|
+
}
|
|
15
|
+
export function isWorkspaceMcpHttpServer(server) {
|
|
16
|
+
return "url" in server && typeof server.url === "string";
|
|
17
|
+
}
|
|
18
|
+
function validateStringRecord(value, label) {
|
|
19
|
+
requireThat(object(value), `${label} 必须是字符串映射。`);
|
|
20
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => {
|
|
21
|
+
requireThat(key.length > 0 && !key.includes("\0") && typeof entry === "string" && !entry.includes("\0"), `${label}.${key} 必须是非空键与无空字节字符串值。`);
|
|
22
|
+
return [key, entry];
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
export function validateWorkspaceMcpServer(name, value) {
|
|
26
|
+
requireThat(serverNamePattern.test(name), `MCP 服务名无效:${name}(需匹配 [A-Za-z0-9][A-Za-z0-9_-]{0,31})。`);
|
|
27
|
+
requireThat(!reservedServerNames.has(name.toLowerCase()), `MCP 服务名 "${name}" 为 Personal Bot 保留名称。`);
|
|
28
|
+
requireThat(object(value), `MCP 服务 "${name}" 配置必须是 JSON 对象。`);
|
|
29
|
+
const hasCommand = value.command !== undefined;
|
|
30
|
+
const hasUrl = value.url !== undefined;
|
|
31
|
+
requireThat(hasCommand !== hasUrl, `MCP 服务 "${name}" 必须且只能声明 command(stdio)或 url(Streamable HTTP)之一。`);
|
|
32
|
+
const allowed = hasCommand ? stdioKeys : httpKeys;
|
|
33
|
+
const unknown = Object.keys(value).filter(key => !allowed.has(key));
|
|
34
|
+
requireThat(unknown.length === 0, `MCP 服务 "${name}" 包含未知字段:${unknown.join(", ")}。`);
|
|
35
|
+
if (value.description !== undefined) {
|
|
36
|
+
requireThat(typeof value.description === "string" && !value.description.includes("\0"), `MCP 服务 "${name}" 的 description 必须是字符串。`);
|
|
37
|
+
}
|
|
38
|
+
if (value.timeout !== undefined) {
|
|
39
|
+
requireThat(typeof value.timeout === "number" && Number.isInteger(value.timeout) && value.timeout >= 1 && value.timeout <= 3600, `MCP 服务 "${name}" 的 timeout 必须是 1–3600 的整数秒。`);
|
|
40
|
+
}
|
|
41
|
+
if (value.enabled !== undefined) {
|
|
42
|
+
requireThat(typeof value.enabled === "boolean", `MCP 服务 "${name}" 的 enabled 必须是布尔值。`);
|
|
43
|
+
}
|
|
44
|
+
const base = {
|
|
45
|
+
...(value.description !== undefined ? { description: value.description } : {}),
|
|
46
|
+
...(value.timeout !== undefined ? { timeout: value.timeout } : {}),
|
|
47
|
+
...(value.enabled !== undefined ? { enabled: value.enabled } : {}),
|
|
48
|
+
};
|
|
49
|
+
if (hasCommand) {
|
|
50
|
+
requireThat(typeof value.command === "string" && value.command.trim().length > 0 && !value.command.includes("\0"), `MCP 服务 "${name}" 的 command 必须是非空字符串。`);
|
|
51
|
+
let args;
|
|
52
|
+
if (value.args !== undefined) {
|
|
53
|
+
requireThat(Array.isArray(value.args) && value.args.every(item => typeof item === "string" && !item.includes("\0")), `MCP 服务 "${name}" 的 args 必须是字符串数组。`);
|
|
54
|
+
args = [...value.args];
|
|
55
|
+
}
|
|
56
|
+
const env = value.env !== undefined ? validateStringRecord(value.env, `MCP 服务 "${name}" 的 env`) : undefined;
|
|
57
|
+
let cwd;
|
|
58
|
+
if (value.cwd !== undefined) {
|
|
59
|
+
requireThat(typeof value.cwd === "string" && value.cwd.trim().length > 0 && !value.cwd.includes("\0"), `MCP 服务 "${name}" 的 cwd 必须是非空字符串。`);
|
|
60
|
+
cwd = value.cwd;
|
|
61
|
+
}
|
|
62
|
+
const entry = {
|
|
63
|
+
command: value.command,
|
|
64
|
+
...(args ? { args } : {}),
|
|
65
|
+
...(env ? { env } : {}),
|
|
66
|
+
...(cwd ? { cwd } : {}),
|
|
67
|
+
...base,
|
|
68
|
+
};
|
|
69
|
+
return entry;
|
|
70
|
+
}
|
|
71
|
+
requireThat(typeof value.url === "string" && value.url.trim().length > 0 && !value.url.includes("\0"), `MCP 服务 "${name}" 的 url 必须是非空字符串。`);
|
|
72
|
+
const rawUrl = value.url.trim();
|
|
73
|
+
requireThat(/^https?:\/\/.+/.test(rawUrl) || envPattern.test(rawUrl), `MCP 服务 "${name}" 的 url 必须以 http:// 或 https:// 开头。`);
|
|
74
|
+
envPattern.lastIndex = 0;
|
|
75
|
+
const headers = value.headers !== undefined ? validateStringRecord(value.headers, `MCP 服务 "${name}" 的 headers`) : undefined;
|
|
76
|
+
const entry = {
|
|
77
|
+
url: rawUrl,
|
|
78
|
+
...(headers ? { headers } : {}),
|
|
79
|
+
...base,
|
|
80
|
+
};
|
|
81
|
+
return entry;
|
|
82
|
+
}
|
|
83
|
+
function validateMcpFile(value) {
|
|
84
|
+
requireThat(object(value), "工作区 MCP 配置必须是 JSON 对象。");
|
|
85
|
+
const rawServers = value.mcpServers;
|
|
86
|
+
requireThat(rawServers !== undefined && object(rawServers), "工作区 MCP 配置需要 mcpServers 对象。");
|
|
87
|
+
const servers = {};
|
|
88
|
+
for (const [name, entry] of Object.entries(rawServers)) {
|
|
89
|
+
servers[name] = validateWorkspaceMcpServer(name, entry);
|
|
90
|
+
}
|
|
91
|
+
return { ...value, mcpServers: servers };
|
|
92
|
+
}
|
|
93
|
+
export function workspaceMcpPath(root) {
|
|
94
|
+
return join(root, ".pbot", "mcp.json");
|
|
95
|
+
}
|
|
96
|
+
export async function readWorkspaceMcpConfig(root) {
|
|
97
|
+
const path = workspaceMcpPath(root);
|
|
98
|
+
let content;
|
|
99
|
+
try {
|
|
100
|
+
content = await readFile(path, "utf8");
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (error.code === "ENOENT")
|
|
104
|
+
return { path, present: false, servers: {} };
|
|
105
|
+
return { path, present: true, servers: {}, error: `无法读取工作区 MCP 配置 ${path}: ${String(error)}` };
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
const parsed = validateMcpFile(JSON.parse(content));
|
|
109
|
+
return { path, present: true, servers: parsed.mcpServers };
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
return { path, present: true, servers: {}, error: `工作区 MCP 配置无效 ${path}: ${error instanceof Error ? error.message : String(error)}` };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export function expandEnvTemplate(value, env, context) {
|
|
116
|
+
return value.replace(envPattern, (_match, variable) => {
|
|
117
|
+
const resolved = env[variable];
|
|
118
|
+
requireThat(resolved !== undefined, `${context} 引用的环境变量 ${variable} 未设置。`);
|
|
119
|
+
return resolved;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function expandEnvRecord(values, env, context) {
|
|
123
|
+
return Object.fromEntries(Object.entries(values ?? {}).map(([key, value]) => [key, expandEnvTemplate(value, env, `${context}.${key}`)]));
|
|
124
|
+
}
|
|
125
|
+
export function resolveWorkspaceMcpServer(root, name, server, env = process.env) {
|
|
126
|
+
const timeout = server.timeout ?? defaultTimeoutSeconds;
|
|
127
|
+
if (isWorkspaceMcpHttpServer(server)) {
|
|
128
|
+
const url = expandEnvTemplate(server.url, env, `MCP 服务 "${name}" 的 url`);
|
|
129
|
+
requireThat(/^https?:\/\/.+/.test(url), `MCP 服务 "${name}" 展开后的 url 必须以 http:// 或 https:// 开头。`);
|
|
130
|
+
return {
|
|
131
|
+
transport: "http",
|
|
132
|
+
name,
|
|
133
|
+
url,
|
|
134
|
+
headers: expandEnvRecord(server.headers, env, `MCP 服务 "${name}" 的 headers`),
|
|
135
|
+
...(server.description ? { description: server.description } : {}),
|
|
136
|
+
timeout,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const command = expandEnvTemplate(server.command, env, `MCP 服务 "${name}" 的 command`);
|
|
140
|
+
const args = (server.args ?? []).map((arg, index) => expandEnvTemplate(arg, env, `MCP 服务 "${name}" 的 args[${index}]`));
|
|
141
|
+
const cwd = server.cwd ? resolve(root, expandEnvTemplate(server.cwd, env, `MCP 服务 "${name}" 的 cwd`)) : root;
|
|
142
|
+
return {
|
|
143
|
+
transport: "stdio",
|
|
144
|
+
name,
|
|
145
|
+
command,
|
|
146
|
+
args,
|
|
147
|
+
env: expandEnvRecord(server.env, env, `MCP 服务 "${name}" 的 env`),
|
|
148
|
+
cwd,
|
|
149
|
+
...(server.description ? { description: server.description } : {}),
|
|
150
|
+
timeout,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
export function resolveWorkspaceMcpServers(root, configuration, env = process.env) {
|
|
154
|
+
if (configuration.error)
|
|
155
|
+
throw new Error(configuration.error);
|
|
156
|
+
const resolved = [];
|
|
157
|
+
for (const [name, server] of Object.entries(configuration.servers)) {
|
|
158
|
+
if (server.enabled === false)
|
|
159
|
+
continue;
|
|
160
|
+
resolved.push(resolveWorkspaceMcpServer(root, name, server, env));
|
|
161
|
+
}
|
|
162
|
+
return resolved;
|
|
163
|
+
}
|
|
164
|
+
export async function upsertWorkspaceMcpServer(root, name, server) {
|
|
165
|
+
const validated = validateWorkspaceMcpServer(name, server);
|
|
166
|
+
const current = await readWorkspaceMcpConfig(root);
|
|
167
|
+
if (current.error)
|
|
168
|
+
throw new Error(current.error);
|
|
169
|
+
const directory = dirname(current.path);
|
|
170
|
+
await mkdir(directory, { recursive: true });
|
|
171
|
+
await updateJsonFile(directory, "mcp.json", validateMcpFile, existing => ({
|
|
172
|
+
...existing,
|
|
173
|
+
mcpServers: { ...existing?.mcpServers, [name]: validated },
|
|
174
|
+
}));
|
|
175
|
+
return readWorkspaceMcpConfig(root);
|
|
176
|
+
}
|
|
177
|
+
export async function removeWorkspaceMcpServer(root, name) {
|
|
178
|
+
const current = await readWorkspaceMcpConfig(root);
|
|
179
|
+
if (current.error)
|
|
180
|
+
throw new Error(current.error);
|
|
181
|
+
if (!current.present || !Object.hasOwn(current.servers, name)) {
|
|
182
|
+
return { removed: false, configuration: current };
|
|
183
|
+
}
|
|
184
|
+
const directory = dirname(current.path);
|
|
185
|
+
const removed = await updateJsonFile(directory, "mcp.json", validateMcpFile, existing => {
|
|
186
|
+
if (!existing || !Object.hasOwn(existing.mcpServers, name))
|
|
187
|
+
return undefined;
|
|
188
|
+
const remaining = { ...existing.mcpServers };
|
|
189
|
+
delete remaining[name];
|
|
190
|
+
return { ...existing, mcpServers: remaining };
|
|
191
|
+
});
|
|
192
|
+
return { removed, configuration: await readWorkspaceMcpConfig(root) };
|
|
193
|
+
}
|
|
@@ -6,3 +6,4 @@ export declare function parseSkillFrontmatter(content: string): {
|
|
|
6
6
|
} | undefined;
|
|
7
7
|
/** Scan `<workspace>/.agents/skills/<dir>/SKILL.md` for workspace-authored skills. */
|
|
8
8
|
export declare function discoverWorkspaceSkills(root: string): Promise<WorkspaceSkillMeta[]>;
|
|
9
|
+
export declare function discoverSkills(skillsDir: string, indexPath: string): Promise<WorkspaceSkillMeta[]>;
|
|
@@ -55,7 +55,9 @@ export function parseSkillFrontmatter(content) {
|
|
|
55
55
|
}
|
|
56
56
|
/** Scan `<workspace>/.agents/skills/<dir>/SKILL.md` for workspace-authored skills. */
|
|
57
57
|
export async function discoverWorkspaceSkills(root) {
|
|
58
|
-
|
|
58
|
+
return discoverSkills(join(root, ".agents", "skills"), ".agents/skills");
|
|
59
|
+
}
|
|
60
|
+
export async function discoverSkills(skillsDir, indexPath) {
|
|
59
61
|
let entries;
|
|
60
62
|
try {
|
|
61
63
|
entries = await readdir(skillsDir, { withFileTypes: true });
|
|
@@ -83,7 +85,7 @@ export async function discoverWorkspaceSkills(root) {
|
|
|
83
85
|
results.push({
|
|
84
86
|
name: meta.name,
|
|
85
87
|
description: meta.description,
|
|
86
|
-
path:
|
|
88
|
+
path: join(indexPath, entry.name, "SKILL.md"),
|
|
87
89
|
});
|
|
88
90
|
}
|
|
89
91
|
results.sort((a, b) => a.name.localeCompare(b.name));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AcpAnswer, AcpElicitation, AcpElicitationReply, AcpInput, AcpPermission, AcpPermissionReply, AcpModelState, AcpProcess, AcpReport, AcpSessionReference } from "../model/acp.js";
|
|
2
|
+
export declare function acpReference(value: unknown): AcpSessionReference;
|
|
3
|
+
export declare function acpModelState(value: unknown): AcpModelState;
|
|
4
|
+
export declare function acpProcess(value: unknown): AcpProcess;
|
|
5
|
+
export declare function acpInput(value: unknown): AcpInput;
|
|
6
|
+
export declare function acpAnswer(value: unknown): AcpAnswer;
|
|
7
|
+
export declare function acpReport(value: unknown): AcpReport;
|
|
8
|
+
export declare function acpPermission(value: unknown): AcpPermission;
|
|
9
|
+
export declare function acpPermissionReply(value: unknown): AcpPermissionReply;
|
|
10
|
+
export declare function acpElicitation(value: unknown): AcpElicitation;
|
|
11
|
+
export declare function acpElicitationReply(value: unknown): AcpElicitationReply;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
2
|
+
import { object } from "../common/json.js";
|
|
3
|
+
import { isAcpBackend, isOneOf, requireThat } from "../common/validation.js";
|
|
4
|
+
import { fileId } from "./file-access.js";
|
|
5
|
+
import { acpAnswerStates, acpElicitationActions, acpPermissionPolicies, isAcpElicitationValue } from "../model/acp.js";
|
|
6
|
+
const text = (value) => typeof value === "string" && value.length > 0 && !value.includes("\0");
|
|
7
|
+
export function acpReference(value) {
|
|
8
|
+
requireThat(object(value) && value.host === "acp" && isAcpBackend(value.backend) &&
|
|
9
|
+
text(value.command) && isAbsolute(value.command) && Array.isArray(value.args) && value.args.every(arg => typeof arg === "string" && !arg.includes("\0")) &&
|
|
10
|
+
(value.sessionId === null || text(value.sessionId)), "ACP 会话引用无效。");
|
|
11
|
+
if (value.env !== undefined) {
|
|
12
|
+
requireThat(object(value.env) && Object.entries(value.env).every(([k, v]) => text(k) && typeof v === "string" && !v.includes("\0")), "ACP 环境变量配置无效。");
|
|
13
|
+
}
|
|
14
|
+
requireThat(value.permission === undefined || isOneOf(value.permission, acpPermissionPolicies), "ACP 权限策略无效。");
|
|
15
|
+
const capabilities = value.capabilities;
|
|
16
|
+
if (capabilities !== undefined)
|
|
17
|
+
requireThat(object(capabilities) &&
|
|
18
|
+
["resume", "load", "close"].every(key => typeof capabilities[key] === "boolean"), "ACP 会话能力无效。");
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
export function acpModelState(value) {
|
|
22
|
+
requireThat(object(value) && text(value.generation) && ["provider", "model", "resolvedModel", "thinking"].every(key => value[key] === undefined || text(value[key])), "ACP 模型选择无效。");
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
export function acpProcess(value) {
|
|
26
|
+
requireThat(object(value) && text(value.generation) && Number.isSafeInteger(value.pid) && Number(value.pid) > 1 &&
|
|
27
|
+
typeof value.startedAt === "number" && Number.isFinite(value.startedAt), "ACP 进程记录无效。");
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
export function acpInput(value) {
|
|
31
|
+
requireThat(object(value) && text(value.generation) && text(value.requestId), "ACP 输入关联无效。");
|
|
32
|
+
fileId(value.requestId);
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
export function acpAnswer(value) {
|
|
36
|
+
acpInput(value);
|
|
37
|
+
requireThat(object(value) && typeof value.answer === "string" && isOneOf(value.state, acpAnswerStates) &&
|
|
38
|
+
(value.error === undefined || typeof value.error === "string"), "ACP 最终回答无效。");
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
export function acpReport(value) {
|
|
42
|
+
requireThat(object(value) && text(value.generation) && text(value.cycleId) && typeof value.text === "string", "ACP 周期报告无效。");
|
|
43
|
+
fileId(value.cycleId);
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
export function acpPermission(value) {
|
|
47
|
+
acpInput(value);
|
|
48
|
+
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 确认请求无效。");
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
export function acpPermissionReply(value) {
|
|
52
|
+
acpInput(value);
|
|
53
|
+
requireThat(object(value) && (value.optionId === null || text(value.optionId)), "ACP 确认答复无效。");
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
export function acpElicitation(value) {
|
|
57
|
+
acpInput(value);
|
|
58
|
+
requireThat(object(value) && (value.mode === "form" || value.mode === "url") && typeof value.message === "string", "ACP 交互请求无效。");
|
|
59
|
+
if (value.mode === "form") {
|
|
60
|
+
requireThat(object(value.schema) && value.url === undefined, "ACP 表单交互请求缺少有效 schema。");
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
requireThat(text(value.url) && value.schema === undefined, "ACP URL 交互请求缺少有效 url。");
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
export function acpElicitationReply(value) {
|
|
68
|
+
acpInput(value);
|
|
69
|
+
requireThat(object(value) && isOneOf(value.action, acpElicitationActions), "ACP 交互答复无效。");
|
|
70
|
+
if (value.content !== undefined) {
|
|
71
|
+
requireThat(value.action === "accept" && object(value.content) &&
|
|
72
|
+
Object.values(value.content).every(isAcpElicitationValue), "ACP 表单答复 content 无效。");
|
|
73
|
+
}
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AgentDescriptor, AgentLaunch, AgentMessage, AgentStatus, AgentCycle, AgentSessionReference } from "../model/agent.js";
|
|
2
|
+
import type { AcpSessionReference } from "../model/acp.js";
|
|
3
|
+
export declare function descriptor(v: unknown): AgentDescriptor;
|
|
4
|
+
export declare function launch(v: unknown): AgentLaunch;
|
|
5
|
+
export declare function message(v: unknown): AgentMessage;
|
|
6
|
+
export declare function cycle(v: unknown): AgentCycle;
|
|
7
|
+
export declare function status(v: unknown): AgentStatus;
|
|
8
|
+
export declare class AgentFiles {
|
|
9
|
+
#private;
|
|
10
|
+
readonly root: string;
|
|
11
|
+
constructor(root: string);
|
|
12
|
+
check(): void;
|
|
13
|
+
fail(error: unknown): void;
|
|
14
|
+
directory(id: string): string;
|
|
15
|
+
read<T>(id: string, path: string, parse: (v: unknown) => T): T;
|
|
16
|
+
optional<T>(id: string, path: string, parse: (v: unknown) => T): T | undefined;
|
|
17
|
+
write<T>(id: string, path: string, value: T, parse: (v: unknown) => T, create?: boolean): void;
|
|
18
|
+
create(value: AgentDescriptor, run: AgentLaunch, acp: AcpSessionReference): void;
|
|
19
|
+
list(): AgentDescriptor[];
|
|
20
|
+
messages(id: string): AgentMessage[];
|
|
21
|
+
completions(id: string): AgentCycle[];
|
|
22
|
+
/** Permission requests of a generation that have no reply yet. */
|
|
23
|
+
pendingPermissions(id: string, generation: string): import("../model/acp.js").AcpPermission[];
|
|
24
|
+
/** Elicitation requests (forms, choices, text inputs, URL confirmations) of a generation that have no reply yet. */
|
|
25
|
+
pendingElicitations(id: string, generation: string): import("../model/acp.js").AcpElicitation[];
|
|
26
|
+
ensureSubdirectory(id: string, name: string): void;
|
|
27
|
+
reference(id: string): AgentSessionReference;
|
|
28
|
+
/** Short controller edits are serialized; an abandoned lock fails closed. */
|
|
29
|
+
control<T>(work: () => T): T;
|
|
30
|
+
enqueue(id: string, text: string, delivery: AgentMessage["delivery"], files?: string[], requestId?: string): AgentMessage;
|
|
31
|
+
}
|