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
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { valid } from "semver";
|
|
2
|
+
import { requireThat } from "../../common/validation.js";
|
|
3
|
+
import type {
|
|
4
|
+
CliUpgradeSummary,
|
|
5
|
+
HostUpgradeContext,
|
|
6
|
+
HostUpgradeResult,
|
|
7
|
+
HostUpgrader,
|
|
8
|
+
WorkspaceUpgradeSummary,
|
|
9
|
+
} from "../../model/installation.js";
|
|
10
|
+
|
|
11
|
+
export interface UpgradeArgs {
|
|
12
|
+
help: boolean;
|
|
13
|
+
workspace?: string;
|
|
14
|
+
version?: string;
|
|
15
|
+
hosts?: string[];
|
|
16
|
+
dshProfile?: string;
|
|
17
|
+
json: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface WorkspaceUpgradeTarget {
|
|
21
|
+
host: string;
|
|
22
|
+
currentVersion?: string;
|
|
23
|
+
bindingPath?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const upgradeUsage =
|
|
27
|
+
"用法:pbot upgrade|update [--workspace <目录>] [--version <MAJOR.MINOR.PATCH>] [--hosts <h1,h2>] [--dsh-profile <名称>] [--json]\n" +
|
|
28
|
+
"将全局 CLI 与当前工作区已绑定的各宿主插件统一升级到 npm 最新稳定版(或指定版本)。";
|
|
29
|
+
|
|
30
|
+
export function parseUpgradeArgs(args: readonly string[]): UpgradeArgs {
|
|
31
|
+
let workspace: string | undefined;
|
|
32
|
+
let version: string | undefined;
|
|
33
|
+
let hosts: string[] | undefined;
|
|
34
|
+
let dshProfile: string | undefined;
|
|
35
|
+
let json = false;
|
|
36
|
+
for (let index = 0; index < args.length; index++) {
|
|
37
|
+
const token = args[index]!;
|
|
38
|
+
if (token === "--help" || token === "-h") return { help: true, json: false };
|
|
39
|
+
if (token === "--json") { json = true; continue; }
|
|
40
|
+
if (token === "--workspace" || token.startsWith("--workspace=")) {
|
|
41
|
+
requireThat(workspace === undefined, "--workspace 只能指定一次。");
|
|
42
|
+
workspace = token === "--workspace" ? args[++index] : token.slice("--workspace=".length);
|
|
43
|
+
requireThat(workspace && !workspace.startsWith("-"), "--workspace 需要目录。");
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (token === "--version" || token.startsWith("--version=")) {
|
|
47
|
+
requireThat(version === undefined, "--version 只能指定一次。");
|
|
48
|
+
version = token === "--version" ? args[++index] : token.slice("--version=".length);
|
|
49
|
+
requireThat(version && valid(version) && /^[0-9]/.test(version) && version === version.trim(),
|
|
50
|
+
"--version 需要合法的 MAJOR.MINOR.PATCH 版本号。");
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (token === "--hosts" || token.startsWith("--hosts=")) {
|
|
54
|
+
requireThat(hosts === undefined, "--hosts 只能指定一次。");
|
|
55
|
+
const raw = token === "--hosts" ? args[++index] : token.slice("--hosts=".length);
|
|
56
|
+
requireThat(raw && !raw.startsWith("-"), "--hosts 需要逗号分隔的宿主名称。");
|
|
57
|
+
hosts = [...new Set(raw.split(",").map(item => item.trim()).filter(Boolean))];
|
|
58
|
+
requireThat(hosts.length > 0, "--hosts 不能为空。");
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (token === "--dsh-profile" || token.startsWith("--dsh-profile=")) {
|
|
62
|
+
requireThat(dshProfile === undefined, "--dsh-profile 只能指定一次。");
|
|
63
|
+
dshProfile = token === "--dsh-profile" ? args[++index] : token.slice("--dsh-profile=".length);
|
|
64
|
+
requireThat(dshProfile && !dshProfile.startsWith("-"), "--dsh-profile 需要 profile 名称。");
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
throw new Error(`不支持的参数:${token}\n${upgradeUsage}`);
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
help: false,
|
|
71
|
+
...(workspace !== undefined ? { workspace } : {}),
|
|
72
|
+
...(version !== undefined ? { version } : {}),
|
|
73
|
+
...(hosts !== undefined ? { hosts } : {}),
|
|
74
|
+
...(dshProfile !== undefined ? { dshProfile } : {}),
|
|
75
|
+
json,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function executeWorkspaceUpgrade(
|
|
80
|
+
input: {
|
|
81
|
+
workspaceRoot: string;
|
|
82
|
+
targetVersion: string;
|
|
83
|
+
cli: CliUpgradeSummary;
|
|
84
|
+
targets: readonly WorkspaceUpgradeTarget[];
|
|
85
|
+
resolveUpgrader: (host: string) => HostUpgrader | undefined;
|
|
86
|
+
createContext: (target: WorkspaceUpgradeTarget) => HostUpgradeContext;
|
|
87
|
+
onResult?: (result: HostUpgradeResult) => void;
|
|
88
|
+
signal: AbortSignal;
|
|
89
|
+
},
|
|
90
|
+
): Promise<WorkspaceUpgradeSummary> {
|
|
91
|
+
const results: HostUpgradeResult[] = [];
|
|
92
|
+
for (const target of input.targets) {
|
|
93
|
+
input.signal.throwIfAborted();
|
|
94
|
+
const upgrader = input.resolveUpgrader(target.host);
|
|
95
|
+
let result: HostUpgradeResult;
|
|
96
|
+
if (!upgrader) {
|
|
97
|
+
result = {
|
|
98
|
+
host: target.host,
|
|
99
|
+
state: "skipped",
|
|
100
|
+
...(target.currentVersion ? { previousVersion: target.currentVersion } : {}),
|
|
101
|
+
detail: "未注册该宿主的自动升级适配器,已跳过。",
|
|
102
|
+
};
|
|
103
|
+
} else {
|
|
104
|
+
try {
|
|
105
|
+
result = await upgrader.upgrade(input.createContext(target));
|
|
106
|
+
} catch (error) {
|
|
107
|
+
input.signal.throwIfAborted();
|
|
108
|
+
result = {
|
|
109
|
+
host: target.host,
|
|
110
|
+
state: "failed",
|
|
111
|
+
...(target.currentVersion ? { previousVersion: target.currentVersion } : {}),
|
|
112
|
+
detail: error instanceof Error ? error.message : String(error),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
results.push(result);
|
|
117
|
+
input.onResult?.(result);
|
|
118
|
+
}
|
|
119
|
+
const ok = input.cli.state !== "failed" && !results.some(item => item.state === "failed");
|
|
120
|
+
return {
|
|
121
|
+
workspaceRoot: input.workspaceRoot,
|
|
122
|
+
targetVersion: input.targetVersion,
|
|
123
|
+
cli: input.cli,
|
|
124
|
+
results,
|
|
125
|
+
ok,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
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
|
+
|
|
11
|
+
function compareSemver(a: string, b: string): number {
|
|
12
|
+
const parse = (value: string) => {
|
|
13
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?/.exec(value);
|
|
14
|
+
return match
|
|
15
|
+
? { major: Number(match[1]), minor: Number(match[2]), patch: Number(match[3]), pre: match[4] ?? "" }
|
|
16
|
+
: undefined;
|
|
17
|
+
};
|
|
18
|
+
const left = parse(a);
|
|
19
|
+
const right = parse(b);
|
|
20
|
+
if (!left || !right) return a.localeCompare(b);
|
|
21
|
+
if (left.major !== right.major) return left.major - right.major;
|
|
22
|
+
if (left.minor !== right.minor) return left.minor - right.minor;
|
|
23
|
+
if (left.patch !== right.patch) return left.patch - right.patch;
|
|
24
|
+
if (left.pre === right.pre) return 0;
|
|
25
|
+
if (!left.pre) return 1;
|
|
26
|
+
if (!right.pre) return -1;
|
|
27
|
+
return left.pre.localeCompare(right.pre);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function bindingDirectory(root: string) {
|
|
31
|
+
const key = createHash("sha256").update(root).digest("hex");
|
|
32
|
+
return join(homedir(), ".pbot", "workspaces", key);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Full plugins own a local manifest. Thin clients can supply the release stamped into their cached hooks.
|
|
36
|
+
function pluginBinding(value: unknown): string {
|
|
37
|
+
requireThat(typeof value === "string", "无效的插件安装记录。");
|
|
38
|
+
if (!isAbsolute(value)) releaseLine(value);
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function permissionDenied(error: unknown): boolean {
|
|
43
|
+
return ["EACCES", "EPERM", "EROFS"].includes((error as NodeJS.ErrnoException).code ?? "");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Each host owns its file, including when two hosts activate the same canonical workspace concurrently. */
|
|
47
|
+
export function bindWorkspacePlugin(root: string, host: string, binding = resolve(resourceRoot, "../package.json")): void {
|
|
48
|
+
const directory = bindingDirectory(root);
|
|
49
|
+
const file = encodeURIComponent(host) + ".json";
|
|
50
|
+
try {
|
|
51
|
+
if (readJsonFile(directory, file, pluginBinding) === binding) return;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (permissionDenied(error)) return;
|
|
54
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
58
|
+
writeJsonFile(directory, file, binding, pluginBinding);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (!permissionDenied(error)) throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface WorkspacePluginBinding {
|
|
65
|
+
version: string;
|
|
66
|
+
bindingPath?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface WorkspacePluginDrift {
|
|
70
|
+
outOfSync: boolean;
|
|
71
|
+
highest?: string;
|
|
72
|
+
lowest?: string;
|
|
73
|
+
versions: Record<string, string>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function workspacePluginBindings(root: string): Record<string, WorkspacePluginBinding> {
|
|
77
|
+
const directory = bindingDirectory(root);
|
|
78
|
+
let files: string[];
|
|
79
|
+
try { files = readdirSync(directory); }
|
|
80
|
+
catch (error) {
|
|
81
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT" || permissionDenied(error)) return {};
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
const bindings: Record<string, WorkspacePluginBinding> = Object.create(null);
|
|
85
|
+
for (const file of files.filter(name => name.endsWith(".json"))) {
|
|
86
|
+
const host = decodeURIComponent(file.slice(0, -5));
|
|
87
|
+
try {
|
|
88
|
+
const binding = readJsonFile(directory, file, pluginBinding);
|
|
89
|
+
if (!isAbsolute(binding)) { bindings[host] = { version: binding }; continue; }
|
|
90
|
+
const manifest: unknown = JSON.parse(readFileSync(binding, "utf8"));
|
|
91
|
+
requireThat(object(manifest) && typeof manifest.version === "string", "无效的插件安装清单:" + binding);
|
|
92
|
+
releaseLine(manifest.version);
|
|
93
|
+
bindings[host] = { version: manifest.version, bindingPath: binding };
|
|
94
|
+
} catch (error) {
|
|
95
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT" && !permissionDenied(error)) throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return bindings;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function workspacePluginReleases(root: string): Record<string, string> {
|
|
102
|
+
const bindings = workspacePluginBindings(root);
|
|
103
|
+
const releases: Record<string, string> = Object.create(null);
|
|
104
|
+
for (const [host, entry] of Object.entries(bindings)) releases[host] = entry.version;
|
|
105
|
+
return releases;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function workspacePluginDrift(releases: Record<string, string>): WorkspacePluginDrift {
|
|
109
|
+
let highest: string | undefined;
|
|
110
|
+
let lowest: string | undefined;
|
|
111
|
+
for (const version of Object.values(releases)) {
|
|
112
|
+
if (!highest || compareSemver(version, highest) > 0) highest = version;
|
|
113
|
+
if (!lowest || compareSemver(version, lowest) < 0) lowest = version;
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
outOfSync: Boolean(highest && lowest && highest !== lowest),
|
|
117
|
+
...(highest ? { highest } : {}),
|
|
118
|
+
...(lowest ? { lowest } : {}),
|
|
119
|
+
versions: releases,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
@@ -2,7 +2,9 @@ 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
|
import type {
|
|
8
10
|
HistoryLayout,
|
|
@@ -19,7 +21,6 @@ import type {
|
|
|
19
21
|
const featureKeys = ["prompts", "skills", "mcp", "history"] as const;
|
|
20
22
|
const summaryKeys = ["backend", "model", "thinking", "concurrency"] as const;
|
|
21
23
|
const historyKeys = ["layout"] as const;
|
|
22
|
-
const historyLayouts = ["monthly", "flat"] as const;
|
|
23
24
|
|
|
24
25
|
function nonEmptyString(value: unknown): value is string {
|
|
25
26
|
return typeof value === "string" && value.trim().length > 0 && !value.includes("\0");
|
|
@@ -47,7 +48,7 @@ function config(value: unknown): Record<string, unknown> {
|
|
|
47
48
|
(command.args === undefined || (Array.isArray(command.args) && command.args.every(arg => typeof arg === "string" && !arg.includes("\0"))));
|
|
48
49
|
if (!object(command) || !launch ||
|
|
49
50
|
(command.env !== undefined && (!object(command.env) || Object.entries(command.env).some(([k, v]) => !k || k.includes("\0") || typeof v !== "string" || v.includes("\0")))) ||
|
|
50
|
-
(command.permission !== undefined && !
|
|
51
|
+
(command.permission !== undefined && !isOneOf(command.permission, acpPermissionPolicies)) ||
|
|
51
52
|
Object.keys(command).some(key => !["command", "args", "env", "permission"].includes(key))) {
|
|
52
53
|
throw new Error("ACP 配置需要 command(内置目标可省略)及可选 args 字符串数组、env 字符串映射、permission(ask、allow 或 deny)。");
|
|
53
54
|
}
|
|
@@ -67,15 +68,15 @@ function config(value: unknown): Record<string, unknown> {
|
|
|
67
68
|
throw new Error("summary.thinking 必须是非空字符串。");
|
|
68
69
|
}
|
|
69
70
|
if (value.summary.concurrency !== undefined &&
|
|
70
|
-
(typeof value.summary.concurrency !== "number" || !Number.isInteger(value.summary.concurrency) || value.summary.concurrency < 1 || value.summary.concurrency >
|
|
71
|
-
throw new Error(
|
|
71
|
+
(typeof value.summary.concurrency !== "number" || !Number.isInteger(value.summary.concurrency) || value.summary.concurrency < 1 || value.summary.concurrency > summaryConcurrency.max)) {
|
|
72
|
+
throw new Error(`summary.concurrency 必须是 1 到 ${summaryConcurrency.max} 之间的整数。`);
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
if (value.history !== undefined) {
|
|
75
76
|
if (!object(value.history) || Object.keys(value.history).some(key => !(historyKeys as readonly string[]).includes(key))) {
|
|
76
77
|
throw new Error("history 必须是 JSON 对象,仅支持 layout。");
|
|
77
78
|
}
|
|
78
|
-
if (value.history.layout !== undefined && !(
|
|
79
|
+
if (value.history.layout !== undefined && !isOneOf(value.history.layout, historyLayouts)) {
|
|
79
80
|
throw new Error('history.layout 必须是 "monthly" 或 "flat"。');
|
|
80
81
|
}
|
|
81
82
|
}
|
|
@@ -104,7 +105,7 @@ export function workspaceSummaryConfig(
|
|
|
104
105
|
backend: raw?.backend ?? "pi",
|
|
105
106
|
...(raw?.model ? { model: raw.model } : {}),
|
|
106
107
|
...(raw?.thinking ? { thinking: raw.thinking } : {}),
|
|
107
|
-
concurrency: raw?.concurrency ??
|
|
108
|
+
concurrency: raw?.concurrency ?? summaryConcurrency.default,
|
|
108
109
|
};
|
|
109
110
|
}
|
|
110
111
|
|
|
@@ -178,5 +179,5 @@ export async function initializeWorkspaceConfig(root: string): Promise<void> {
|
|
|
178
179
|
}
|
|
179
180
|
|
|
180
181
|
export function workspaceDisabledMessage(configuration: WorkspaceConfiguration): string {
|
|
181
|
-
return configuration.error ?? `Personal Bot
|
|
182
|
+
return configuration.error ?? `Personal Bot 未在此工作区启用。请在工作区根目录运行 pbot init,也可在 Pi 或 dsh 中执行 /pbot init。配置文件位于 ${configuration.path}`;
|
|
182
183
|
}
|
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
WorkspaceMcpServer,
|
|
11
11
|
WorkspaceMcpStdioServer,
|
|
12
12
|
} from "../../model/workspace-mcp.js";
|
|
13
|
-
import {
|
|
13
|
+
import { updateJsonFile } from "../../storage/atomic-json.js";
|
|
14
14
|
|
|
15
15
|
const serverNamePattern = /^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$/;
|
|
16
16
|
const reservedServerNames = new Set(["pbot"]);
|
|
@@ -29,13 +29,11 @@ export function isWorkspaceMcpHttpServer(server: WorkspaceMcpServer): server is
|
|
|
29
29
|
|
|
30
30
|
function validateStringRecord(value: unknown, label: string): Record<string, string> {
|
|
31
31
|
requireThat(object(value), `${label} 必须是字符串映射。`);
|
|
32
|
-
|
|
33
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
32
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => {
|
|
34
33
|
requireThat(key.length > 0 && !key.includes("\0") && typeof entry === "string" && !entry.includes("\0"),
|
|
35
34
|
`${label}.${key} 必须是非空键与无空字节字符串值。`);
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
return result;
|
|
35
|
+
return [key, entry];
|
|
36
|
+
}));
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
export function validateWorkspaceMcpServer(name: string, value: unknown): WorkspaceMcpServer {
|
|
@@ -117,7 +115,7 @@ function validateMcpFile(value: unknown): WorkspaceMcpConfig {
|
|
|
117
115
|
for (const [name, entry] of Object.entries(rawServers)) {
|
|
118
116
|
servers[name] = validateWorkspaceMcpServer(name, entry);
|
|
119
117
|
}
|
|
120
|
-
return { mcpServers: servers };
|
|
118
|
+
return { ...value, mcpServers: servers };
|
|
121
119
|
}
|
|
122
120
|
|
|
123
121
|
export function workspaceMcpPath(root: string): string {
|
|
@@ -148,6 +146,11 @@ export function expandEnvTemplate(value: string, env: NodeJS.ProcessEnv, context
|
|
|
148
146
|
});
|
|
149
147
|
}
|
|
150
148
|
|
|
149
|
+
function expandEnvRecord(values: Record<string, string> | undefined, env: NodeJS.ProcessEnv, context: string) {
|
|
150
|
+
return Object.fromEntries(Object.entries(values ?? {}).map(([key, value]) =>
|
|
151
|
+
[key, expandEnvTemplate(value, env, `${context}.${key}`)]));
|
|
152
|
+
}
|
|
153
|
+
|
|
151
154
|
export function resolveWorkspaceMcpServer(
|
|
152
155
|
root: string,
|
|
153
156
|
name: string,
|
|
@@ -158,15 +161,11 @@ export function resolveWorkspaceMcpServer(
|
|
|
158
161
|
if (isWorkspaceMcpHttpServer(server)) {
|
|
159
162
|
const url = expandEnvTemplate(server.url, env, `MCP 服务 "${name}" 的 url`);
|
|
160
163
|
requireThat(/^https?:\/\/.+/.test(url), `MCP 服务 "${name}" 展开后的 url 必须以 http:// 或 https:// 开头。`);
|
|
161
|
-
const headers: Record<string, string> = {};
|
|
162
|
-
for (const [key, value] of Object.entries(server.headers ?? {})) {
|
|
163
|
-
headers[key] = expandEnvTemplate(value, env, `MCP 服务 "${name}" 的 headers.${key}`);
|
|
164
|
-
}
|
|
165
164
|
return {
|
|
166
165
|
transport: "http",
|
|
167
166
|
name,
|
|
168
167
|
url,
|
|
169
|
-
headers,
|
|
168
|
+
headers: expandEnvRecord(server.headers, env, `MCP 服务 "${name}" 的 headers`),
|
|
170
169
|
...(server.description ? { description: server.description } : {}),
|
|
171
170
|
timeout,
|
|
172
171
|
};
|
|
@@ -174,17 +173,13 @@ export function resolveWorkspaceMcpServer(
|
|
|
174
173
|
|
|
175
174
|
const command = expandEnvTemplate(server.command, env, `MCP 服务 "${name}" 的 command`);
|
|
176
175
|
const args = (server.args ?? []).map((arg, index) => expandEnvTemplate(arg, env, `MCP 服务 "${name}" 的 args[${index}]`));
|
|
177
|
-
const resolvedEnv: Record<string, string> = {};
|
|
178
|
-
for (const [key, value] of Object.entries(server.env ?? {})) {
|
|
179
|
-
resolvedEnv[key] = expandEnvTemplate(value, env, `MCP 服务 "${name}" 的 env.${key}`);
|
|
180
|
-
}
|
|
181
176
|
const cwd = server.cwd ? resolve(root, expandEnvTemplate(server.cwd, env, `MCP 服务 "${name}" 的 cwd`)) : root;
|
|
182
177
|
return {
|
|
183
178
|
transport: "stdio",
|
|
184
179
|
name,
|
|
185
180
|
command,
|
|
186
181
|
args,
|
|
187
|
-
env:
|
|
182
|
+
env: expandEnvRecord(server.env, env, `MCP 服务 "${name}" 的 env`),
|
|
188
183
|
cwd,
|
|
189
184
|
...(server.description ? { description: server.description } : {}),
|
|
190
185
|
timeout,
|
|
@@ -215,10 +210,10 @@ export async function upsertWorkspaceMcpServer(
|
|
|
215
210
|
if (current.error) throw new Error(current.error);
|
|
216
211
|
const directory = dirname(current.path);
|
|
217
212
|
await mkdir(directory, { recursive: true });
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
213
|
+
await updateJsonFile(directory, "mcp.json", validateMcpFile, existing => ({
|
|
214
|
+
...existing,
|
|
215
|
+
mcpServers: { ...existing?.mcpServers, [name]: validated },
|
|
216
|
+
}));
|
|
222
217
|
return readWorkspaceMcpConfig(root);
|
|
223
218
|
}
|
|
224
219
|
|
|
@@ -232,11 +227,11 @@ export async function removeWorkspaceMcpServer(
|
|
|
232
227
|
return { removed: false, configuration: current };
|
|
233
228
|
}
|
|
234
229
|
const directory = dirname(current.path);
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return { removed
|
|
230
|
+
const removed = await updateJsonFile(directory, "mcp.json", validateMcpFile, existing => {
|
|
231
|
+
if (!existing || !Object.hasOwn(existing.mcpServers, name)) return undefined;
|
|
232
|
+
const remaining = { ...existing.mcpServers };
|
|
233
|
+
delete remaining[name];
|
|
234
|
+
return { ...existing, mcpServers: remaining };
|
|
235
|
+
});
|
|
236
|
+
return { removed, configuration: await readWorkspaceMcpConfig(root) };
|
|
242
237
|
}
|
|
@@ -51,7 +51,10 @@ export function parseSkillFrontmatter(content: string): { name?: string; descrip
|
|
|
51
51
|
|
|
52
52
|
/** Scan `<workspace>/.agents/skills/<dir>/SKILL.md` for workspace-authored skills. */
|
|
53
53
|
export async function discoverWorkspaceSkills(root: string): Promise<WorkspaceSkillMeta[]> {
|
|
54
|
-
|
|
54
|
+
return discoverSkills(join(root, ".agents", "skills"), ".agents/skills");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function discoverSkills(skillsDir: string, indexPath: string): Promise<WorkspaceSkillMeta[]> {
|
|
55
58
|
let entries;
|
|
56
59
|
try { entries = await readdir(skillsDir, { withFileTypes: true }); }
|
|
57
60
|
catch (error) {
|
|
@@ -70,7 +73,7 @@ export async function discoverWorkspaceSkills(root: string): Promise<WorkspaceSk
|
|
|
70
73
|
results.push({
|
|
71
74
|
name: meta.name,
|
|
72
75
|
description: meta.description,
|
|
73
|
-
path:
|
|
76
|
+
path: join(indexPath, entry.name, "SKILL.md"),
|
|
74
77
|
});
|
|
75
78
|
}
|
|
76
79
|
results.sort((a, b) => a.name.localeCompare(b.name));
|
package/src/storage/acp-files.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isAbsolute } from "node:path";
|
|
2
2
|
import { object } from "../common/json.js";
|
|
3
|
-
import { isAcpBackend, requireThat } from "../common/validation.js";
|
|
3
|
+
import { isAcpBackend, isOneOf, requireThat } from "../common/validation.js";
|
|
4
4
|
import { fileId } from "./file-access.js";
|
|
5
|
+
import { acpAnswerStates, acpElicitationActions, acpPermissionPolicies, isAcpElicitationValue } from "../model/acp.js";
|
|
5
6
|
import type { AcpAnswer, AcpElicitation, AcpElicitationReply, AcpInput, AcpPermission, AcpPermissionReply, AcpModelState, AcpProcess, AcpReport, AcpSessionReference } from "../model/acp.js";
|
|
6
7
|
|
|
7
8
|
const text = (value: unknown): value is string => typeof value === "string" && value.length > 0 && !value.includes("\0");
|
|
@@ -12,7 +13,7 @@ export function acpReference(value: unknown): AcpSessionReference {
|
|
|
12
13
|
if (value.env !== undefined) {
|
|
13
14
|
requireThat(object(value.env) && Object.entries(value.env).every(([k, v]) => text(k) && typeof v === "string" && !v.includes("\0")), "ACP 环境变量配置无效。");
|
|
14
15
|
}
|
|
15
|
-
requireThat(value.permission === undefined ||
|
|
16
|
+
requireThat(value.permission === undefined || isOneOf(value.permission, acpPermissionPolicies), "ACP 权限策略无效。");
|
|
16
17
|
const capabilities = value.capabilities;
|
|
17
18
|
if (capabilities !== undefined) requireThat(object(capabilities) &&
|
|
18
19
|
["resume", "load", "close"].every(key => typeof capabilities[key] === "boolean"), "ACP 会话能力无效。");
|
|
@@ -33,7 +34,7 @@ export function acpInput(value: unknown): AcpInput {
|
|
|
33
34
|
}
|
|
34
35
|
export function acpAnswer(value: unknown): AcpAnswer {
|
|
35
36
|
acpInput(value);
|
|
36
|
-
requireThat(object(value) && typeof value.answer === "string" &&
|
|
37
|
+
requireThat(object(value) && typeof value.answer === "string" && isOneOf(value.state, acpAnswerStates) &&
|
|
37
38
|
(value.error === undefined || typeof value.error === "string"), "ACP 最终回答无效。");
|
|
38
39
|
return value as unknown as AcpAnswer;
|
|
39
40
|
}
|
|
@@ -44,7 +45,7 @@ export function acpReport(value: unknown): AcpReport {
|
|
|
44
45
|
export function acpPermission(value: unknown): AcpPermission {
|
|
45
46
|
acpInput(value);
|
|
46
47
|
requireThat(object(value) && typeof value.description === "string" && Array.isArray(value.options) && value.options.every(option =>
|
|
47
|
-
object(option) && text(option.optionId) && text(option.name) && ["allow_once", "allow_always", "reject_once", "reject_always"]
|
|
48
|
+
object(option) && text(option.optionId) && text(option.name) && isOneOf(option.kind, ["allow_once", "allow_always", "reject_once", "reject_always"])), "ACP 确认请求无效。");
|
|
48
49
|
return value as unknown as AcpPermission;
|
|
49
50
|
}
|
|
50
51
|
export function acpPermissionReply(value: unknown): AcpPermissionReply {
|
|
@@ -52,12 +53,6 @@ export function acpPermissionReply(value: unknown): AcpPermissionReply {
|
|
|
52
53
|
requireThat(object(value) && (value.optionId === null || text(value.optionId)), "ACP 确认答复无效。");
|
|
53
54
|
return value as unknown as AcpPermissionReply;
|
|
54
55
|
}
|
|
55
|
-
function elicitationValue(value: unknown): boolean {
|
|
56
|
-
return typeof value === "string"
|
|
57
|
-
|| (typeof value === "number" && Number.isFinite(value))
|
|
58
|
-
|| typeof value === "boolean"
|
|
59
|
-
|| (Array.isArray(value) && value.every(item => typeof item === "string"));
|
|
60
|
-
}
|
|
61
56
|
export function acpElicitation(value: unknown): AcpElicitation {
|
|
62
57
|
acpInput(value);
|
|
63
58
|
requireThat(object(value) && (value.mode === "form" || value.mode === "url") && typeof value.message === "string", "ACP 交互请求无效。");
|
|
@@ -70,10 +65,10 @@ export function acpElicitation(value: unknown): AcpElicitation {
|
|
|
70
65
|
}
|
|
71
66
|
export function acpElicitationReply(value: unknown): AcpElicitationReply {
|
|
72
67
|
acpInput(value);
|
|
73
|
-
requireThat(object(value) &&
|
|
68
|
+
requireThat(object(value) && isOneOf(value.action, acpElicitationActions), "ACP 交互答复无效。");
|
|
74
69
|
if (value.content !== undefined) {
|
|
75
70
|
requireThat(value.action === "accept" && object(value.content) &&
|
|
76
|
-
Object.values(value.content).every(
|
|
71
|
+
Object.values(value.content).every(isAcpElicitationValue), "ACP 表单答复 content 无效。");
|
|
77
72
|
}
|
|
78
73
|
return value as unknown as AcpElicitationReply;
|
|
79
74
|
}
|
|
@@ -2,9 +2,10 @@ import { existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { canonical, object } from "../common/json.js";
|
|
5
|
-
import { requireThat } from "../common/validation.js";
|
|
5
|
+
import { isOneOf, requireThat } from "../common/validation.js";
|
|
6
6
|
import { readJsonFile, writeJsonFile } from "./atomic-json.js";
|
|
7
7
|
import { fileId, privateDirectory } from "./file-access.js";
|
|
8
|
+
import { agentStates, cycleSources, cycleStates, messageDeliveries } from "../model/agent.js";
|
|
8
9
|
import type { AgentDescriptor, AgentLaunch, AgentMessage, AgentStatus, AgentCycle, AgentSessionReference } from "../model/agent.js";
|
|
9
10
|
import type { AcpSessionReference } from "../model/acp.js";
|
|
10
11
|
import { acpElicitation, acpPermission, acpReference } from "./acp-files.js";
|
|
@@ -22,18 +23,18 @@ export function launch(v: unknown): AgentLaunch {
|
|
|
22
23
|
}
|
|
23
24
|
export function message(v: unknown): AgentMessage {
|
|
24
25
|
requireThat(object(v) && text(v.requestId) && text(v.generation) && Number.isSafeInteger(v.sequence) && typeof v.message === "string" &&
|
|
25
|
-
|
|
26
|
+
isOneOf(v.delivery, messageDeliveries) && Array.isArray(v.files) && v.files.every(text), "子会话消息无效。");
|
|
26
27
|
return v as unknown as AgentMessage;
|
|
27
28
|
}
|
|
28
29
|
export function cycle(v: unknown): AgentCycle {
|
|
29
30
|
requireThat(object(v) && text(v.cycleId) && text(v.generation) && number(v.startedAt) &&
|
|
30
|
-
|
|
31
|
+
isOneOf(v.state, cycleStates) &&
|
|
31
32
|
(v.leaf === null || text(v.leaf)) && Array.isArray(v.requestIds) && v.requestIds.every(text) &&
|
|
32
|
-
|
|
33
|
+
isOneOf(v.source, cycleSources) && (v.finishedAt === undefined || number(v.finishedAt)), "子会话周期无效。");
|
|
33
34
|
return v as unknown as AgentCycle;
|
|
34
35
|
}
|
|
35
36
|
export function status(v: unknown): AgentStatus {
|
|
36
|
-
requireThat(object(v) && text(v.generation) &&
|
|
37
|
+
requireThat(object(v) && text(v.generation) && isOneOf(v.state, agentStates) &&
|
|
37
38
|
typeof v.activity === "string" && number(v.updatedAt), "子会话状态无效。");
|
|
38
39
|
if (v.cycle) cycle(v.cycle); return v as unknown as AgentStatus;
|
|
39
40
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { constants, closeSync, fstatSync, fsyncSync, linkSync, lstatSync, openSync, readFileSync, realpathSync,
|
|
2
|
-
renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { constants, closeSync, fstatSync, fsyncSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync,
|
|
2
|
+
renameSync, rmdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
4
5
|
import { randomUUID } from "node:crypto";
|
|
5
6
|
import { canonical } from "../common/json.js";
|
|
6
7
|
import { requireThat } from "../common/validation.js";
|
|
7
8
|
|
|
8
9
|
/** The root must already exist. Never follow aliases inside internal storage. */
|
|
9
|
-
export function internalPath(directory: string, relative: string): string {
|
|
10
|
+
export function internalPath(directory: string, relative: string, allowMissingParents = false): string {
|
|
10
11
|
const parts = relative.split("/");
|
|
11
12
|
requireThat(parts.every(part => part && part !== "." && part !== ".." && !/[\\\x00-\x1f]/.test(part)), "内部状态路径无效。");
|
|
12
13
|
const info = lstatSync(directory);
|
|
@@ -18,7 +19,7 @@ export function internalPath(directory: string, relative: string): string {
|
|
|
18
19
|
const info = lstatSync(path);
|
|
19
20
|
requireThat(!info.isSymbolicLink() && (index === parts.length - 1 ? info.isFile() : info.isDirectory()), "内部状态不能使用符号链接或特殊文件。");
|
|
20
21
|
} catch (error) {
|
|
21
|
-
if ((error as NodeJS.ErrnoException).code !== "ENOENT" || index !== parts.length - 1) throw error;
|
|
22
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT" || (!allowMissingParents && index !== parts.length - 1)) throw error;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
return path;
|
|
@@ -72,3 +73,29 @@ export function writeJsonFile<T>(directory: string, relative: string, value: unk
|
|
|
72
73
|
catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; }
|
|
73
74
|
}
|
|
74
75
|
}
|
|
76
|
+
|
|
77
|
+
/** Serialize a read-modify-write across processes. An undefined replacement means no change. */
|
|
78
|
+
export async function updateJsonFile<T>(directory: string, relative: string, validate: (value: unknown) => T,
|
|
79
|
+
update: (current: T | undefined) => T | undefined): Promise<boolean> {
|
|
80
|
+
const lock = internalPath(directory, relative) + ".lock";
|
|
81
|
+
const deadline = Date.now() + 3000;
|
|
82
|
+
for (;;) {
|
|
83
|
+
try { mkdirSync(lock, { mode: 0o700 }); break; }
|
|
84
|
+
catch (error) {
|
|
85
|
+
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
86
|
+
if (Date.now() >= deadline) throw new Error(`写锁被占用:${lock}。若写入进程已退出,可手动移除遗留锁目录。`);
|
|
87
|
+
await delay(25);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
for (;;) {
|
|
92
|
+
let current: T | undefined;
|
|
93
|
+
try { current = readJsonFile(directory, relative, validate); }
|
|
94
|
+
catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; }
|
|
95
|
+
const next = update(current);
|
|
96
|
+
if (next === undefined) return false;
|
|
97
|
+
if (writeJsonFile(directory, relative, next, validate, current === undefined)) return true;
|
|
98
|
+
// An external writer created the file first. Apply the edit to its value.
|
|
99
|
+
}
|
|
100
|
+
} finally { rmdirSync(lock); }
|
|
101
|
+
}
|