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
|
@@ -2,7 +2,7 @@ import { mkdir, readFile } from "node:fs/promises";
|
|
|
2
2
|
import { dirname, join, resolve } from "node:path";
|
|
3
3
|
import { object } from "../../common/json.js";
|
|
4
4
|
import { requireThat } from "../../common/validation.js";
|
|
5
|
-
import {
|
|
5
|
+
import { updateJsonFile } from "../../storage/atomic-json.js";
|
|
6
6
|
const serverNamePattern = /^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$/;
|
|
7
7
|
const reservedServerNames = new Set(["pbot"]);
|
|
8
8
|
const stdioKeys = new Set(["command", "args", "env", "cwd", "description", "timeout", "enabled"]);
|
|
@@ -17,12 +17,10 @@ export function isWorkspaceMcpHttpServer(server) {
|
|
|
17
17
|
}
|
|
18
18
|
function validateStringRecord(value, label) {
|
|
19
19
|
requireThat(object(value), `${label} 必须是字符串映射。`);
|
|
20
|
-
|
|
21
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
20
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => {
|
|
22
21
|
requireThat(key.length > 0 && !key.includes("\0") && typeof entry === "string" && !entry.includes("\0"), `${label}.${key} 必须是非空键与无空字节字符串值。`);
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
return result;
|
|
22
|
+
return [key, entry];
|
|
23
|
+
}));
|
|
26
24
|
}
|
|
27
25
|
export function validateWorkspaceMcpServer(name, value) {
|
|
28
26
|
requireThat(serverNamePattern.test(name), `MCP 服务名无效:${name}(需匹配 [A-Za-z0-9][A-Za-z0-9_-]{0,31})。`);
|
|
@@ -90,7 +88,7 @@ function validateMcpFile(value) {
|
|
|
90
88
|
for (const [name, entry] of Object.entries(rawServers)) {
|
|
91
89
|
servers[name] = validateWorkspaceMcpServer(name, entry);
|
|
92
90
|
}
|
|
93
|
-
return { mcpServers: servers };
|
|
91
|
+
return { ...value, mcpServers: servers };
|
|
94
92
|
}
|
|
95
93
|
export function workspaceMcpPath(root) {
|
|
96
94
|
return join(root, ".pbot", "mcp.json");
|
|
@@ -121,37 +119,32 @@ export function expandEnvTemplate(value, env, context) {
|
|
|
121
119
|
return resolved;
|
|
122
120
|
});
|
|
123
121
|
}
|
|
122
|
+
function expandEnvRecord(values, env, context) {
|
|
123
|
+
return Object.fromEntries(Object.entries(values ?? {}).map(([key, value]) => [key, expandEnvTemplate(value, env, `${context}.${key}`)]));
|
|
124
|
+
}
|
|
124
125
|
export function resolveWorkspaceMcpServer(root, name, server, env = process.env) {
|
|
125
126
|
const timeout = server.timeout ?? defaultTimeoutSeconds;
|
|
126
127
|
if (isWorkspaceMcpHttpServer(server)) {
|
|
127
128
|
const url = expandEnvTemplate(server.url, env, `MCP 服务 "${name}" 的 url`);
|
|
128
129
|
requireThat(/^https?:\/\/.+/.test(url), `MCP 服务 "${name}" 展开后的 url 必须以 http:// 或 https:// 开头。`);
|
|
129
|
-
const headers = {};
|
|
130
|
-
for (const [key, value] of Object.entries(server.headers ?? {})) {
|
|
131
|
-
headers[key] = expandEnvTemplate(value, env, `MCP 服务 "${name}" 的 headers.${key}`);
|
|
132
|
-
}
|
|
133
130
|
return {
|
|
134
131
|
transport: "http",
|
|
135
132
|
name,
|
|
136
133
|
url,
|
|
137
|
-
headers,
|
|
134
|
+
headers: expandEnvRecord(server.headers, env, `MCP 服务 "${name}" 的 headers`),
|
|
138
135
|
...(server.description ? { description: server.description } : {}),
|
|
139
136
|
timeout,
|
|
140
137
|
};
|
|
141
138
|
}
|
|
142
139
|
const command = expandEnvTemplate(server.command, env, `MCP 服务 "${name}" 的 command`);
|
|
143
140
|
const args = (server.args ?? []).map((arg, index) => expandEnvTemplate(arg, env, `MCP 服务 "${name}" 的 args[${index}]`));
|
|
144
|
-
const resolvedEnv = {};
|
|
145
|
-
for (const [key, value] of Object.entries(server.env ?? {})) {
|
|
146
|
-
resolvedEnv[key] = expandEnvTemplate(value, env, `MCP 服务 "${name}" 的 env.${key}`);
|
|
147
|
-
}
|
|
148
141
|
const cwd = server.cwd ? resolve(root, expandEnvTemplate(server.cwd, env, `MCP 服务 "${name}" 的 cwd`)) : root;
|
|
149
142
|
return {
|
|
150
143
|
transport: "stdio",
|
|
151
144
|
name,
|
|
152
145
|
command,
|
|
153
146
|
args,
|
|
154
|
-
env:
|
|
147
|
+
env: expandEnvRecord(server.env, env, `MCP 服务 "${name}" 的 env`),
|
|
155
148
|
cwd,
|
|
156
149
|
...(server.description ? { description: server.description } : {}),
|
|
157
150
|
timeout,
|
|
@@ -175,11 +168,10 @@ export async function upsertWorkspaceMcpServer(root, name, server) {
|
|
|
175
168
|
throw new Error(current.error);
|
|
176
169
|
const directory = dirname(current.path);
|
|
177
170
|
await mkdir(directory, { recursive: true });
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
return upsertWorkspaceMcpServer(root, name, server);
|
|
171
|
+
await updateJsonFile(directory, "mcp.json", validateMcpFile, existing => ({
|
|
172
|
+
...existing,
|
|
173
|
+
mcpServers: { ...existing?.mcpServers, [name]: validated },
|
|
174
|
+
}));
|
|
183
175
|
return readWorkspaceMcpConfig(root);
|
|
184
176
|
}
|
|
185
177
|
export async function removeWorkspaceMcpServer(root, name) {
|
|
@@ -190,11 +182,12 @@ export async function removeWorkspaceMcpServer(root, name) {
|
|
|
190
182
|
return { removed: false, configuration: current };
|
|
191
183
|
}
|
|
192
184
|
const directory = dirname(current.path);
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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) };
|
|
200
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));
|
package/lib/storage/acp-files.js
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
|
const text = (value) => typeof value === "string" && value.length > 0 && !value.includes("\0");
|
|
6
7
|
export function acpReference(value) {
|
|
7
8
|
requireThat(object(value) && value.host === "acp" && isAcpBackend(value.backend) &&
|
|
@@ -10,7 +11,7 @@ export function acpReference(value) {
|
|
|
10
11
|
if (value.env !== undefined) {
|
|
11
12
|
requireThat(object(value.env) && Object.entries(value.env).every(([k, v]) => text(k) && typeof v === "string" && !v.includes("\0")), "ACP 环境变量配置无效。");
|
|
12
13
|
}
|
|
13
|
-
requireThat(value.permission === undefined ||
|
|
14
|
+
requireThat(value.permission === undefined || isOneOf(value.permission, acpPermissionPolicies), "ACP 权限策略无效。");
|
|
14
15
|
const capabilities = value.capabilities;
|
|
15
16
|
if (capabilities !== undefined)
|
|
16
17
|
requireThat(object(capabilities) &&
|
|
@@ -33,7 +34,7 @@ export function acpInput(value) {
|
|
|
33
34
|
}
|
|
34
35
|
export function acpAnswer(value) {
|
|
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;
|
|
39
40
|
}
|
|
@@ -44,7 +45,7 @@ export function acpReport(value) {
|
|
|
44
45
|
}
|
|
45
46
|
export function acpPermission(value) {
|
|
46
47
|
acpInput(value);
|
|
47
|
-
requireThat(object(value) && typeof value.description === "string" && Array.isArray(value.options) && value.options.every(option => object(option) && text(option.optionId) && text(option.name) && ["allow_once", "allow_always", "reject_once", "reject_always"]
|
|
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 确认请求无效。");
|
|
48
49
|
return value;
|
|
49
50
|
}
|
|
50
51
|
export function acpPermissionReply(value) {
|
|
@@ -52,12 +53,6 @@ export function acpPermissionReply(value) {
|
|
|
52
53
|
requireThat(object(value) && (value.optionId === null || text(value.optionId)), "ACP 确认答复无效。");
|
|
53
54
|
return value;
|
|
54
55
|
}
|
|
55
|
-
function elicitationValue(value) {
|
|
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) {
|
|
62
57
|
acpInput(value);
|
|
63
58
|
requireThat(object(value) && (value.mode === "form" || value.mode === "url") && typeof value.message === "string", "ACP 交互请求无效。");
|
|
@@ -71,10 +66,10 @@ export function acpElicitation(value) {
|
|
|
71
66
|
}
|
|
72
67
|
export function acpElicitationReply(value) {
|
|
73
68
|
acpInput(value);
|
|
74
|
-
requireThat(object(value) &&
|
|
69
|
+
requireThat(object(value) && isOneOf(value.action, acpElicitationActions), "ACP 交互答复无效。");
|
|
75
70
|
if (value.content !== undefined) {
|
|
76
71
|
requireThat(value.action === "accept" && object(value.content) &&
|
|
77
|
-
Object.values(value.content).every(
|
|
72
|
+
Object.values(value.content).every(isAcpElicitationValue), "ACP 表单答复 content 无效。");
|
|
78
73
|
}
|
|
79
74
|
return value;
|
|
80
75
|
}
|
|
@@ -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 { acpElicitation, acpPermission, acpReference } from "./acp-files.js";
|
|
9
10
|
const text = (v) => typeof v === "string" && v.length > 0;
|
|
10
11
|
const number = (v) => typeof v === "number" && Number.isFinite(v);
|
|
@@ -20,18 +21,18 @@ export function launch(v) {
|
|
|
20
21
|
}
|
|
21
22
|
export function message(v) {
|
|
22
23
|
requireThat(object(v) && text(v.requestId) && text(v.generation) && Number.isSafeInteger(v.sequence) && typeof v.message === "string" &&
|
|
23
|
-
|
|
24
|
+
isOneOf(v.delivery, messageDeliveries) && Array.isArray(v.files) && v.files.every(text), "子会话消息无效。");
|
|
24
25
|
return v;
|
|
25
26
|
}
|
|
26
27
|
export function cycle(v) {
|
|
27
28
|
requireThat(object(v) && text(v.cycleId) && text(v.generation) && number(v.startedAt) &&
|
|
28
|
-
|
|
29
|
+
isOneOf(v.state, cycleStates) &&
|
|
29
30
|
(v.leaf === null || text(v.leaf)) && Array.isArray(v.requestIds) && v.requestIds.every(text) &&
|
|
30
|
-
|
|
31
|
+
isOneOf(v.source, cycleSources) && (v.finishedAt === undefined || number(v.finishedAt)), "子会话周期无效。");
|
|
31
32
|
return v;
|
|
32
33
|
}
|
|
33
34
|
export function status(v) {
|
|
34
|
-
requireThat(object(v) && text(v.generation) &&
|
|
35
|
+
requireThat(object(v) && text(v.generation) && isOneOf(v.state, agentStates) &&
|
|
35
36
|
typeof v.activity === "string" && number(v.updatedAt), "子会话状态无效。");
|
|
36
37
|
if (v.cycle)
|
|
37
38
|
cycle(v.cycle);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** The root must already exist. Never follow aliases inside internal storage. */
|
|
2
|
-
export declare function internalPath(directory: string, relative: string): string;
|
|
2
|
+
export declare function internalPath(directory: string, relative: string, allowMissingParents?: boolean): string;
|
|
3
3
|
export declare function syncDirectory(directory: string): void;
|
|
4
4
|
/** Validators return plain data and must reject incomplete contracts. */
|
|
5
5
|
export declare function readJsonFile<T>(directory: string, relative: string, validate: (value: unknown) => T): T;
|
|
@@ -9,3 +9,5 @@ export declare function readJsonFile<T>(directory: string, relative: string, val
|
|
|
9
9
|
* createOnly publishes by link, so an existing destination is never overwritten.
|
|
10
10
|
*/
|
|
11
11
|
export declare function writeJsonFile<T>(directory: string, relative: string, value: unknown, validate: (value: unknown) => T, createOnly?: boolean): boolean;
|
|
12
|
+
/** Serialize a read-modify-write across processes. An undefined replacement means no change. */
|
|
13
|
+
export declare function updateJsonFile<T>(directory: string, relative: string, validate: (value: unknown) => T, update: (current: T | undefined) => T | undefined): Promise<boolean>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { constants, closeSync, fstatSync, fsyncSync, linkSync, lstatSync, openSync, readFileSync, realpathSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { constants, closeSync, fstatSync, fsyncSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, rmdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
3
4
|
import { randomUUID } from "node:crypto";
|
|
4
5
|
import { canonical } from "../common/json.js";
|
|
5
6
|
import { requireThat } from "../common/validation.js";
|
|
6
7
|
/** The root must already exist. Never follow aliases inside internal storage. */
|
|
7
|
-
export function internalPath(directory, relative) {
|
|
8
|
+
export function internalPath(directory, relative, allowMissingParents = false) {
|
|
8
9
|
const parts = relative.split("/");
|
|
9
10
|
requireThat(parts.every(part => part && part !== "." && part !== ".." && !/[\\\x00-\x1f]/.test(part)), "内部状态路径无效。");
|
|
10
11
|
const info = lstatSync(directory);
|
|
@@ -17,7 +18,7 @@ export function internalPath(directory, relative) {
|
|
|
17
18
|
requireThat(!info.isSymbolicLink() && (index === parts.length - 1 ? info.isFile() : info.isDirectory()), "内部状态不能使用符号链接或特殊文件。");
|
|
18
19
|
}
|
|
19
20
|
catch (error) {
|
|
20
|
-
if (error.code !== "ENOENT" || index !== parts.length - 1)
|
|
21
|
+
if (error.code !== "ENOENT" || (!allowMissingParents && index !== parts.length - 1))
|
|
21
22
|
throw error;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
@@ -99,3 +100,42 @@ export function writeJsonFile(directory, relative, value, validate, createOnly =
|
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
}
|
|
103
|
+
/** Serialize a read-modify-write across processes. An undefined replacement means no change. */
|
|
104
|
+
export async function updateJsonFile(directory, relative, validate, update) {
|
|
105
|
+
const lock = internalPath(directory, relative) + ".lock";
|
|
106
|
+
const deadline = Date.now() + 3000;
|
|
107
|
+
for (;;) {
|
|
108
|
+
try {
|
|
109
|
+
mkdirSync(lock, { mode: 0o700 });
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (error.code !== "EEXIST")
|
|
114
|
+
throw error;
|
|
115
|
+
if (Date.now() >= deadline)
|
|
116
|
+
throw new Error(`写锁被占用:${lock}。若写入进程已退出,可手动移除遗留锁目录。`);
|
|
117
|
+
await delay(25);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
for (;;) {
|
|
122
|
+
let current;
|
|
123
|
+
try {
|
|
124
|
+
current = readJsonFile(directory, relative, validate);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
if (error.code !== "ENOENT")
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
const next = update(current);
|
|
131
|
+
if (next === undefined)
|
|
132
|
+
return false;
|
|
133
|
+
if (writeJsonFile(directory, relative, next, validate, current === undefined))
|
|
134
|
+
return true;
|
|
135
|
+
// An external writer created the file first. Apply the edit to its value.
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
rmdirSync(lock);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -31,6 +31,7 @@ export declare class HistoryFiles {
|
|
|
31
31
|
controlSummary<T>(dimension: string, operation: () => T): T;
|
|
32
32
|
/** Synchronous migration lock for explicit layout migration. */
|
|
33
33
|
controlMigration<T>(operation: () => T): T;
|
|
34
|
+
migrationNotice(): string | undefined;
|
|
34
35
|
/** Detect unmigrated top-level flat JSON files when running under monthly layout. */
|
|
35
36
|
detectFlatFiles(): FlatHistoryInventory;
|
|
36
37
|
listFlatRawFiles(): string[];
|
|
@@ -38,7 +39,7 @@ export declare class HistoryFiles {
|
|
|
38
39
|
readFlatRawFile(name: string): RawHistory;
|
|
39
40
|
readFlatSummaryFile(dimension: string, name: string): SummaryArtifact;
|
|
40
41
|
/** Atomically move a file within .pbot/history/ without ever overwriting an existing destination. */
|
|
41
|
-
moveHistoryFile(fromRelative: string, toRelative: string): "moved" | "conflict";
|
|
42
|
+
moveHistoryFile(fromRelative: string, toRelative: string, dryRun?: boolean): "moved" | "conflict";
|
|
42
43
|
listRaw(filterHost?: HistoryHost, onlyFiles?: readonly string[]): RawHistory[];
|
|
43
44
|
readRaw(id: string): RawHistory | undefined;
|
|
44
45
|
saveRaw(raw: RawHistory): void;
|
|
@@ -2,10 +2,10 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { linkSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmdirSync, unlinkSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
4
4
|
import { isDeepStrictEqual } from "node:util";
|
|
5
|
-
import { requireThat } from "../common/validation.js";
|
|
5
|
+
import { isHistoryIdentifier, requireThat } from "../common/validation.js";
|
|
6
6
|
import { internalPath, readJsonFile, syncDirectory, writeJsonFile } from "./atomic-json.js";
|
|
7
7
|
import { fileId, privateDirectory } from "./file-access.js";
|
|
8
|
-
import {
|
|
8
|
+
import { matchIdentity, rawHistory, summaryArtifact } from "./history-format.js";
|
|
9
9
|
const yearPattern = /^\d{4}$/;
|
|
10
10
|
const monthPattern = /^(?:0[1-9]|1[0-2])$/;
|
|
11
11
|
const monthlyIdPattern = /^(\d{4})-(0[1-9]|1[0-2])$/;
|
|
@@ -233,14 +233,14 @@ export class HistoryFiles {
|
|
|
233
233
|
this.directory = directory;
|
|
234
234
|
this.host = host;
|
|
235
235
|
this.layout = layout;
|
|
236
|
-
requireThat(
|
|
236
|
+
requireThat(isHistoryIdentifier(host), "历史来源无效。");
|
|
237
237
|
}
|
|
238
238
|
get warnings() { return this.#warnings; }
|
|
239
239
|
get rawWarnings() { return this.#rawWarnings; }
|
|
240
240
|
get rawDirectory() { return join(this.directory, "raw"); }
|
|
241
241
|
get summariesDirectory() { return join(this.directory, "summaries"); }
|
|
242
242
|
summaryDirectory(dimension) {
|
|
243
|
-
requireThat(
|
|
243
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
244
244
|
return join(this.summariesDirectory, dimension);
|
|
245
245
|
}
|
|
246
246
|
withLock(lockName, label, operation) {
|
|
@@ -268,13 +268,16 @@ export class HistoryFiles {
|
|
|
268
268
|
}
|
|
269
269
|
/** Synchronous dimension write lock for derived summary files. */
|
|
270
270
|
controlSummary(dimension, operation) {
|
|
271
|
-
requireThat(
|
|
271
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
272
272
|
return this.withLock(".write-summary-" + dimension, "summary:" + dimension, operation);
|
|
273
273
|
}
|
|
274
274
|
/** Synchronous migration lock for explicit layout migration. */
|
|
275
275
|
controlMigration(operation) {
|
|
276
276
|
return this.withLock(".write-migrate", "migrate", operation);
|
|
277
277
|
}
|
|
278
|
+
migrationNotice() {
|
|
279
|
+
return this.layout === "monthly" ? this.detectFlatFiles().message : undefined;
|
|
280
|
+
}
|
|
278
281
|
/** Detect unmigrated top-level flat JSON files when running under monthly layout. */
|
|
279
282
|
detectFlatFiles() {
|
|
280
283
|
if (!sharedDirectory(this.directory))
|
|
@@ -294,7 +297,7 @@ export class HistoryFiles {
|
|
|
294
297
|
summaryCount,
|
|
295
298
|
total,
|
|
296
299
|
message: `检测到 ${total} 个未迁移的平铺历史文件(raw ${rawCount},summaries ${summaryCount});当前为年月目录布局(history.layout: monthly),未迁移文件不会被读取。` +
|
|
297
|
-
|
|
300
|
+
`请在终端运行 pbot history migrate 整理到 YYYY/MM/ 目录(Pi/dsh 可用 /pbot history migrate),或在 .pbot/config.json 中设置 "history": { "layout": "flat" } 切回平铺布局。`,
|
|
298
301
|
};
|
|
299
302
|
}
|
|
300
303
|
listFlatRawFiles() {
|
|
@@ -303,7 +306,7 @@ export class HistoryFiles {
|
|
|
303
306
|
return topLevelJsonNames(this.rawDirectory);
|
|
304
307
|
}
|
|
305
308
|
listFlatSummaryFiles(dimension) {
|
|
306
|
-
requireThat(
|
|
309
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
307
310
|
const dir = this.summaryDirectory(dimension);
|
|
308
311
|
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory) || !ordinaryDirectory(dir))
|
|
309
312
|
return [];
|
|
@@ -313,13 +316,16 @@ export class HistoryFiles {
|
|
|
313
316
|
return readJsonFile(this.directory, "raw/" + name, value => namedRaw(value, name));
|
|
314
317
|
}
|
|
315
318
|
readFlatSummaryFile(dimension, name) {
|
|
316
|
-
requireThat(
|
|
319
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
317
320
|
return readJsonFile(this.directory, `summaries/${dimension}/${name}`, value => namedSummary(value, name, dimension));
|
|
318
321
|
}
|
|
319
322
|
/** Atomically move a file within .pbot/history/ without ever overwriting an existing destination. */
|
|
320
|
-
moveHistoryFile(fromRelative, toRelative) {
|
|
321
|
-
ensureDirectory(this.directory);
|
|
323
|
+
moveHistoryFile(fromRelative, toRelative, dryRun = false) {
|
|
322
324
|
const src = internalPath(this.directory, fromRelative);
|
|
325
|
+
if (dryRun) {
|
|
326
|
+
const target = internalPath(this.directory, toRelative, true);
|
|
327
|
+
return ordinaryFile(target) ? "conflict" : "moved";
|
|
328
|
+
}
|
|
323
329
|
const dstParentRel = dirname(toRelative);
|
|
324
330
|
if (dstParentRel && dstParentRel !== ".") {
|
|
325
331
|
privateDirectory(this.directory, dstParentRel);
|
|
@@ -333,8 +339,8 @@ export class HistoryFiles {
|
|
|
333
339
|
return "conflict";
|
|
334
340
|
throw error;
|
|
335
341
|
}
|
|
336
|
-
unlinkSync(src);
|
|
337
342
|
syncDirectory(dirname(dst));
|
|
343
|
+
unlinkSync(src);
|
|
338
344
|
syncDirectory(dirname(src));
|
|
339
345
|
return "moved";
|
|
340
346
|
}
|
|
@@ -373,7 +379,7 @@ export class HistoryFiles {
|
|
|
373
379
|
return optional(() => readJsonFile(this.directory, "raw/" + rel, value => namedRaw(value, rel)));
|
|
374
380
|
}
|
|
375
381
|
saveRaw(raw) {
|
|
376
|
-
requireThat(
|
|
382
|
+
requireThat(isHistoryIdentifier(raw.host) && raw.host === this.host, "历史归档只允许所属来源写入。");
|
|
377
383
|
rawHistory(raw);
|
|
378
384
|
ensureDirectory(this.directory);
|
|
379
385
|
const name = filename(raw.id);
|
|
@@ -398,7 +404,7 @@ export class HistoryFiles {
|
|
|
398
404
|
return [];
|
|
399
405
|
const entries = readdirSync(this.summariesDirectory, { withFileTypes: true });
|
|
400
406
|
return entries
|
|
401
|
-
.filter(entry => entry.isDirectory() && !entry.isSymbolicLink() &&
|
|
407
|
+
.filter(entry => entry.isDirectory() && !entry.isSymbolicLink() && isHistoryIdentifier(entry.name))
|
|
402
408
|
.map(entry => entry.name)
|
|
403
409
|
.sort();
|
|
404
410
|
}
|
|
@@ -406,7 +412,7 @@ export class HistoryFiles {
|
|
|
406
412
|
return dimension === "monthly" ? "year" : "month";
|
|
407
413
|
}
|
|
408
414
|
listSummaries(dimension, onlyFiles) {
|
|
409
|
-
requireThat(
|
|
415
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
410
416
|
const dir = this.summaryDirectory(dimension);
|
|
411
417
|
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory) || !ordinaryDirectory(dir))
|
|
412
418
|
return [];
|
|
@@ -426,7 +432,7 @@ export class HistoryFiles {
|
|
|
426
432
|
return results;
|
|
427
433
|
}
|
|
428
434
|
readSummary(dimension, id) {
|
|
429
|
-
requireThat(
|
|
435
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
430
436
|
const dir = this.summaryDirectory(dimension);
|
|
431
437
|
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory) || !ordinaryDirectory(dir))
|
|
432
438
|
return undefined;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export
|
|
3
|
-
export declare const isSummaryDimension: (value: unknown) => value is string;
|
|
1
|
+
import type { HistoryIdentity, RawHistory, SummaryArtifact } from "../model/history.js";
|
|
2
|
+
export { isHistoryIdentifier as isHistoryHost, isHistoryIdentifier as isSummaryDimension } from "../common/validation.js";
|
|
4
3
|
export declare function matchIdentity(value: HistoryIdentity, expected: HistoryIdentity): void;
|
|
5
4
|
export declare function rawHistory(value: unknown): RawHistory;
|
|
6
5
|
export declare function summaryArtifact(value: unknown, expectedDimension?: string): SummaryArtifact;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { object } from "../common/json.js";
|
|
2
|
-
import { requireThat } from "../common/validation.js";
|
|
2
|
+
import { isHistoryIdentifier, requireThat } from "../common/validation.js";
|
|
3
3
|
import { fileId } from "./file-access.js";
|
|
4
4
|
const strings = (value) => Array.isArray(value) && value.every(item => typeof item === "string");
|
|
5
5
|
const fields = (value, names) => Object.keys(value).every(key => names.includes(key));
|
|
@@ -7,11 +7,9 @@ const rawFields = ["host", "id", "sessionId", "name", "exchanges", "branches"];
|
|
|
7
7
|
const exchangeFields = ["id", "entryIds", "text", "from", "to", "completed"];
|
|
8
8
|
const summaryArtifactFields = ["id", "dimension", "host", "sessionId", "title", "text", "from", "to", "updatedAt", "source"];
|
|
9
9
|
const summarySourceFields = ["rawIds", "exchangeIds", "fingerprint"];
|
|
10
|
-
|
|
11
|
-
export const isHistoryHost = (value) => typeof value === "string" && identifierPattern.test(value);
|
|
12
|
-
export const isSummaryDimension = (value) => typeof value === "string" && identifierPattern.test(value);
|
|
10
|
+
export { isHistoryIdentifier as isHistoryHost, isHistoryIdentifier as isSummaryDimension } from "../common/validation.js";
|
|
13
11
|
function identity(value) {
|
|
14
|
-
requireThat(object(value) &&
|
|
12
|
+
requireThat(object(value) && isHistoryIdentifier(value.host) && typeof value.id === "string" &&
|
|
15
13
|
typeof value.sessionId === "string" && value.sessionId.length > 0, "历史归档身份无效。");
|
|
16
14
|
fileId(value.id);
|
|
17
15
|
}
|
|
@@ -43,12 +41,12 @@ export function summaryArtifact(value, expectedDimension) {
|
|
|
43
41
|
requireThat(object(value) && fields(value, summaryArtifactFields), "历史摘要产物格式无效。");
|
|
44
42
|
requireThat(typeof value.id === "string" && value.id.length > 0, "历史摘要 ID 无效。");
|
|
45
43
|
fileId(value.id);
|
|
46
|
-
requireThat(
|
|
44
|
+
requireThat(isHistoryIdentifier(value.dimension), "历史摘要维度无效。");
|
|
47
45
|
if (expectedDimension !== undefined) {
|
|
48
46
|
requireThat(value.dimension === expectedDimension, `历史摘要维度不匹配,预期 ${expectedDimension},实际 ${value.dimension}。`);
|
|
49
47
|
}
|
|
50
48
|
if (value.host !== undefined)
|
|
51
|
-
requireThat(
|
|
49
|
+
requireThat(isHistoryIdentifier(value.host), "历史摘要来源 host 无效。");
|
|
52
50
|
if (value.sessionId !== undefined)
|
|
53
51
|
requireThat(typeof value.sessionId === "string" && value.sessionId.length > 0, "历史摘要 sessionId 无效。");
|
|
54
52
|
requireThat(typeof value.title === "string" && typeof value.text === "string" && value.text.trim().length > 0 &&
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
|
-
import type
|
|
2
|
+
import { type HistoryHost, type HistoryQuery } from "../../model/history.js";
|
|
3
3
|
export declare const historyResultSchema: Type.TObject<{
|
|
4
4
|
matches: Type.TOptional<Type.TArray<Type.TObject<{
|
|
5
5
|
snippet: Type.TString;
|
|
@@ -84,17 +84,9 @@ export declare const historyParameters: Type.TObject<{
|
|
|
84
84
|
limit: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
|
|
85
85
|
childrenOffset: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
|
|
86
86
|
}>;
|
|
87
|
-
export type HistoryInput = {
|
|
87
|
+
export type HistoryInput = ({
|
|
88
88
|
action: "search";
|
|
89
|
-
|
|
90
|
-
dimension?: string;
|
|
91
|
-
query?: string;
|
|
92
|
-
sessionId?: string;
|
|
93
|
-
from?: string;
|
|
94
|
-
to?: string;
|
|
95
|
-
offset?: number;
|
|
96
|
-
limit?: number;
|
|
97
|
-
} | {
|
|
89
|
+
} & HistoryQuery) | {
|
|
98
90
|
action: "read";
|
|
99
91
|
id: string;
|
|
100
92
|
host?: HistoryHost;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Type } from "../../common/typebox.js";
|
|
2
|
-
import {
|
|
2
|
+
import { historyPageLimits } from "../../model/history.js";
|
|
3
|
+
import { historyIdentifierPattern, requireThat } from "../../common/validation.js";
|
|
3
4
|
import { schema } from "../../common/schema.js";
|
|
4
5
|
import { inputObject, need, nullable, pick } from "../input.js";
|
|
5
|
-
const identifier = Type.String({ pattern:
|
|
6
|
+
const identifier = Type.String({ pattern: historyIdentifierPattern.source });
|
|
6
7
|
const nullableOffset = Type.Union([Type.Integer(), Type.Null()]);
|
|
7
8
|
const node = Type.Object({
|
|
8
9
|
host: identifier,
|
|
@@ -52,23 +53,23 @@ export const historyParameters = Type.Object({
|
|
|
52
53
|
action: Type.Union([Type.Literal("search"), Type.Literal("read")], {
|
|
53
54
|
description: "search 搜索或列会话;read 读取指定节点正文与上下级。各动作仅读取自身字段,其余字段忽略。",
|
|
54
55
|
}),
|
|
55
|
-
host: nullable(Type.String({ pattern:
|
|
56
|
-
dimension: nullable(Type.String({ pattern:
|
|
56
|
+
host: nullable(Type.String({ pattern: historyIdentifierPattern.source, description: "可选来源筛选(如 pi、dsh、claude、antigravity)。" })),
|
|
57
|
+
dimension: nullable(Type.String({ pattern: historyIdentifierPattern.source, description: "仅 search:可选范围筛选(raw 表示仅原文,或指定摘要维度如 monthly、session;省略查全部)。" })),
|
|
57
58
|
query: nullable(Type.String({ description: "仅 search:不区分大小写的连续关键词;省略时列出各会话(或指定维度摘要)。" })),
|
|
58
59
|
sessionId: nullable(Type.String({ description: "仅 search:限定在指定会话 ID 内搜索。" })),
|
|
59
60
|
from: nullable(Type.String({ description: "仅 search:ISO 日期或时间下界。" })),
|
|
60
61
|
to: nullable(Type.String({ description: "仅 search:ISO 日期或时间上界。" })),
|
|
61
62
|
id: nullable(Type.String({ description: "仅 read,必填:search 或上下级返回的节点 id。" })),
|
|
62
63
|
offset: nullable(Type.Integer({ minimum: 0, description: "search:匹配结果偏移;read:正文字符偏移。默认 0。" })),
|
|
63
|
-
limit: nullable(Type.Integer({ minimum: 1, maximum:
|
|
64
|
+
limit: nullable(Type.Integer({ minimum: 1, maximum: historyPageLimits.read.max, description: `search:最多返回条数(默认 ${historyPageLimits.search.default},上限 ${historyPageLimits.search.max});read:正文字符数(默认 ${historyPageLimits.read.default})。` })),
|
|
64
65
|
childrenOffset: nullable(Type.Integer({ minimum: 0, description: "仅 read:子节点列表偏移,默认 0;续读传上页 nextChildrenOffset。" })),
|
|
65
66
|
}, { additionalProperties: false });
|
|
66
67
|
const valid = schema(historyParameters);
|
|
67
68
|
export function historyInput(value) {
|
|
68
69
|
const args = inputObject(value, valid, "历史参数格式无效");
|
|
69
70
|
if (args.action === "search") {
|
|
70
|
-
const limit = args.limit === undefined ?
|
|
71
|
-
requireThat(limit <=
|
|
71
|
+
const limit = args.limit === undefined ? historyPageLimits.search.default : args.limit;
|
|
72
|
+
requireThat(limit <= historyPageLimits.search.max, `search 的 limit 最多 ${historyPageLimits.search.max}。`);
|
|
72
73
|
return {
|
|
73
74
|
action: "search",
|
|
74
75
|
...pick(args, ["host", "dimension", "query", "sessionId", "from", "to", "offset", "limit"]),
|
package/lib/ui/dsh/elements.d.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
export declare const record: (value: unknown) => Record<string, unknown>;
|
|
2
2
|
export declare const rows: (value: unknown) => Record<string, unknown>[];
|
|
3
3
|
export declare const text: (value: unknown) => string;
|
|
4
|
-
export declare const objectInput: (value: string) => Record<string, unknown>;
|
|
5
|
-
export declare const lines: (value: string) => string[];
|
|
6
4
|
export declare function element<K extends keyof HTMLElementTagNameMap>(tag: K, content?: string, className?: string): HTMLElementTagNameMap[K];
|
|
7
5
|
export declare function block(value: unknown): HTMLPreElement;
|
|
8
6
|
export declare function note(value: string): HTMLParagraphElement;
|
|
9
7
|
export declare function group(parent: HTMLElement, className?: string): HTMLDivElement;
|
|
10
8
|
export declare function details(parent: HTMLElement, title: string): HTMLDetailsElement;
|
|
11
|
-
export declare function field(parent: HTMLElement, label: string
|
|
9
|
+
export declare function field(parent: HTMLElement, label: string): HTMLInputElement;
|
|
12
10
|
export declare function select(parent: HTMLElement, label: string, values: [string, string][]): HTMLSelectElement;
|
|
13
|
-
export declare function badge(state: unknown): HTMLSpanElement;
|
|
14
11
|
export declare function facts(values: [string, unknown][]): HTMLDListElement;
|
|
15
12
|
export declare function empty(title: string, description: string): HTMLDivElement;
|
|
16
|
-
export declare function pageTitle(parent: HTMLElement, title: string
|
|
13
|
+
export declare function pageTitle(parent: HTMLElement, title: string): HTMLElement;
|
|
17
14
|
export declare function time(value: unknown): string;
|