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
|
@@ -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
|
+
}
|
|
@@ -2,11 +2,11 @@ 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 type { HistoryHost, HistoryLayout, RawHistory, SummaryArtifact } from "../model/history.js";
|
|
7
7
|
import { internalPath, readJsonFile, syncDirectory, writeJsonFile } from "./atomic-json.js";
|
|
8
8
|
import { fileId, privateDirectory } from "./file-access.js";
|
|
9
|
-
import {
|
|
9
|
+
import { matchIdentity, rawHistory, summaryArtifact } from "./history-format.js";
|
|
10
10
|
|
|
11
11
|
const yearPattern = /^\d{4}$/;
|
|
12
12
|
const monthPattern = /^(?:0[1-9]|1[0-2])$/;
|
|
@@ -243,7 +243,7 @@ export class HistoryFiles {
|
|
|
243
243
|
readonly host: HistoryHost = "pi",
|
|
244
244
|
readonly layout: HistoryLayout = "monthly",
|
|
245
245
|
) {
|
|
246
|
-
requireThat(
|
|
246
|
+
requireThat(isHistoryIdentifier(host), "历史来源无效。");
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
get warnings(): readonly string[] { return this.#warnings; }
|
|
@@ -252,7 +252,7 @@ export class HistoryFiles {
|
|
|
252
252
|
get rawDirectory(): string { return join(this.directory, "raw"); }
|
|
253
253
|
get summariesDirectory(): string { return join(this.directory, "summaries"); }
|
|
254
254
|
summaryDirectory(dimension: string): string {
|
|
255
|
-
requireThat(
|
|
255
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
256
256
|
return join(this.summariesDirectory, dimension);
|
|
257
257
|
}
|
|
258
258
|
|
|
@@ -276,7 +276,7 @@ export class HistoryFiles {
|
|
|
276
276
|
|
|
277
277
|
/** Synchronous dimension write lock for derived summary files. */
|
|
278
278
|
controlSummary<T>(dimension: string, operation: () => T): T {
|
|
279
|
-
requireThat(
|
|
279
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
280
280
|
return this.withLock(".write-summary-" + dimension, "summary:" + dimension, operation);
|
|
281
281
|
}
|
|
282
282
|
|
|
@@ -285,6 +285,10 @@ export class HistoryFiles {
|
|
|
285
285
|
return this.withLock(".write-migrate", "migrate", operation);
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
+
migrationNotice(): string | undefined {
|
|
289
|
+
return this.layout === "monthly" ? this.detectFlatFiles().message : undefined;
|
|
290
|
+
}
|
|
291
|
+
|
|
288
292
|
/** Detect unmigrated top-level flat JSON files when running under monthly layout. */
|
|
289
293
|
detectFlatFiles(): FlatHistoryInventory {
|
|
290
294
|
if (!sharedDirectory(this.directory)) return { rawCount: 0, summaryCount: 0, total: 0 };
|
|
@@ -302,7 +306,7 @@ export class HistoryFiles {
|
|
|
302
306
|
total,
|
|
303
307
|
message:
|
|
304
308
|
`检测到 ${total} 个未迁移的平铺历史文件(raw ${rawCount},summaries ${summaryCount});当前为年月目录布局(history.layout: monthly),未迁移文件不会被读取。` +
|
|
305
|
-
|
|
309
|
+
`请在终端运行 pbot history migrate 整理到 YYYY/MM/ 目录(Pi/dsh 可用 /pbot history migrate),或在 .pbot/config.json 中设置 "history": { "layout": "flat" } 切回平铺布局。`,
|
|
306
310
|
};
|
|
307
311
|
}
|
|
308
312
|
|
|
@@ -312,7 +316,7 @@ export class HistoryFiles {
|
|
|
312
316
|
}
|
|
313
317
|
|
|
314
318
|
listFlatSummaryFiles(dimension: string): string[] {
|
|
315
|
-
requireThat(
|
|
319
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
316
320
|
const dir = this.summaryDirectory(dimension);
|
|
317
321
|
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory) || !ordinaryDirectory(dir)) return [];
|
|
318
322
|
return topLevelJsonNames(dir);
|
|
@@ -323,14 +327,17 @@ export class HistoryFiles {
|
|
|
323
327
|
}
|
|
324
328
|
|
|
325
329
|
readFlatSummaryFile(dimension: string, name: string): SummaryArtifact {
|
|
326
|
-
requireThat(
|
|
330
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
327
331
|
return readJsonFile(this.directory, `summaries/${dimension}/${name}`, value => namedSummary(value, name, dimension));
|
|
328
332
|
}
|
|
329
333
|
|
|
330
334
|
/** Atomically move a file within .pbot/history/ without ever overwriting an existing destination. */
|
|
331
|
-
moveHistoryFile(fromRelative: string, toRelative: string): "moved" | "conflict" {
|
|
332
|
-
ensureDirectory(this.directory);
|
|
335
|
+
moveHistoryFile(fromRelative: string, toRelative: string, dryRun = false): "moved" | "conflict" {
|
|
333
336
|
const src = internalPath(this.directory, fromRelative);
|
|
337
|
+
if (dryRun) {
|
|
338
|
+
const target = internalPath(this.directory, toRelative, true);
|
|
339
|
+
return ordinaryFile(target) ? "conflict" : "moved";
|
|
340
|
+
}
|
|
334
341
|
const dstParentRel = dirname(toRelative);
|
|
335
342
|
if (dstParentRel && dstParentRel !== ".") {
|
|
336
343
|
privateDirectory(this.directory, dstParentRel);
|
|
@@ -342,8 +349,8 @@ export class HistoryFiles {
|
|
|
342
349
|
if ((error as NodeJS.ErrnoException).code === "EEXIST") return "conflict";
|
|
343
350
|
throw error;
|
|
344
351
|
}
|
|
345
|
-
unlinkSync(src);
|
|
346
352
|
syncDirectory(dirname(dst));
|
|
353
|
+
unlinkSync(src);
|
|
347
354
|
syncDirectory(dirname(src));
|
|
348
355
|
return "moved";
|
|
349
356
|
}
|
|
@@ -380,7 +387,7 @@ export class HistoryFiles {
|
|
|
380
387
|
}
|
|
381
388
|
|
|
382
389
|
saveRaw(raw: RawHistory) {
|
|
383
|
-
requireThat(
|
|
390
|
+
requireThat(isHistoryIdentifier(raw.host) && raw.host === this.host, "历史归档只允许所属来源写入。");
|
|
384
391
|
rawHistory(raw);
|
|
385
392
|
ensureDirectory(this.directory);
|
|
386
393
|
const name = filename(raw.id);
|
|
@@ -403,7 +410,7 @@ export class HistoryFiles {
|
|
|
403
410
|
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory)) return [];
|
|
404
411
|
const entries = readdirSync(this.summariesDirectory, { withFileTypes: true });
|
|
405
412
|
return entries
|
|
406
|
-
.filter(entry => entry.isDirectory() && !entry.isSymbolicLink() &&
|
|
413
|
+
.filter(entry => entry.isDirectory() && !entry.isSymbolicLink() && isHistoryIdentifier(entry.name))
|
|
407
414
|
.map(entry => entry.name)
|
|
408
415
|
.sort();
|
|
409
416
|
}
|
|
@@ -413,7 +420,7 @@ export class HistoryFiles {
|
|
|
413
420
|
}
|
|
414
421
|
|
|
415
422
|
listSummaries(dimension: string, onlyFiles?: readonly string[]): SummaryArtifact[] {
|
|
416
|
-
requireThat(
|
|
423
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
417
424
|
const dir = this.summaryDirectory(dimension);
|
|
418
425
|
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory) || !ordinaryDirectory(dir)) return [];
|
|
419
426
|
const files = onlyFiles ?? listLayoutJsonFiles(dir, this.layout, this.summaryBucketDepth(dimension));
|
|
@@ -432,7 +439,7 @@ export class HistoryFiles {
|
|
|
432
439
|
}
|
|
433
440
|
|
|
434
441
|
readSummary(dimension: string, id: string): SummaryArtifact | undefined {
|
|
435
|
-
requireThat(
|
|
442
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
436
443
|
const dir = this.summaryDirectory(dimension);
|
|
437
444
|
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory) || !ordinaryDirectory(dir)) return undefined;
|
|
438
445
|
const name = filename(id);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { object } from "../common/json.js";
|
|
2
|
-
import { requireThat } from "../common/validation.js";
|
|
3
|
-
import type { HistoryExchange,
|
|
2
|
+
import { isHistoryIdentifier, requireThat } from "../common/validation.js";
|
|
3
|
+
import type { HistoryExchange, HistoryIdentity, RawHistory, SummaryArtifact } from "../model/history.js";
|
|
4
4
|
import { fileId } from "./file-access.js";
|
|
5
5
|
|
|
6
6
|
const strings = (value: unknown): value is string[] => Array.isArray(value) && value.every(item => typeof item === "string");
|
|
@@ -11,13 +11,11 @@ const exchangeFields = ["id", "entryIds", "text", "from", "to", "completed"];
|
|
|
11
11
|
const summaryArtifactFields = ["id", "dimension", "host", "sessionId", "title", "text", "from", "to", "updatedAt", "source"];
|
|
12
12
|
const summarySourceFields = ["rawIds", "exchangeIds", "fingerprint"];
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
export const isHistoryHost = (value: unknown): value is HistoryHost => typeof value === "string" && identifierPattern.test(value);
|
|
16
|
-
export const isSummaryDimension = (value: unknown): value is string => typeof value === "string" && identifierPattern.test(value);
|
|
14
|
+
export { isHistoryIdentifier as isHistoryHost, isHistoryIdentifier as isSummaryDimension } from "../common/validation.js";
|
|
17
15
|
|
|
18
16
|
function identity(value: unknown): asserts value is HistoryIdentity {
|
|
19
17
|
requireThat(
|
|
20
|
-
object(value) &&
|
|
18
|
+
object(value) && isHistoryIdentifier(value.host) && typeof value.id === "string" &&
|
|
21
19
|
typeof value.sessionId === "string" && value.sessionId.length > 0,
|
|
22
20
|
"历史归档身份无效。",
|
|
23
21
|
);
|
|
@@ -61,11 +59,11 @@ export function summaryArtifact(value: unknown, expectedDimension?: string): Sum
|
|
|
61
59
|
requireThat(object(value) && fields(value, summaryArtifactFields), "历史摘要产物格式无效。");
|
|
62
60
|
requireThat(typeof value.id === "string" && value.id.length > 0, "历史摘要 ID 无效。");
|
|
63
61
|
fileId(value.id);
|
|
64
|
-
requireThat(
|
|
62
|
+
requireThat(isHistoryIdentifier(value.dimension), "历史摘要维度无效。");
|
|
65
63
|
if (expectedDimension !== undefined) {
|
|
66
64
|
requireThat(value.dimension === expectedDimension, `历史摘要维度不匹配,预期 ${expectedDimension},实际 ${value.dimension}。`);
|
|
67
65
|
}
|
|
68
|
-
if (value.host !== undefined) requireThat(
|
|
66
|
+
if (value.host !== undefined) requireThat(isHistoryIdentifier(value.host), "历史摘要来源 host 无效。");
|
|
69
67
|
if (value.sessionId !== undefined) requireThat(typeof value.sessionId === "string" && value.sessionId.length > 0, "历史摘要 sessionId 无效。");
|
|
70
68
|
requireThat(
|
|
71
69
|
typeof value.title === "string" && typeof value.text === "string" && value.text.trim().length > 0 &&
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
|
-
import type
|
|
3
|
-
import { requireThat } from "../../common/validation.js";
|
|
2
|
+
import { historyPageLimits, type HistoryHost, type HistoryQuery } from "../../model/history.js";
|
|
3
|
+
import { historyIdentifierPattern, requireThat } from "../../common/validation.js";
|
|
4
4
|
import { schema } from "../../common/schema.js";
|
|
5
5
|
import { inputObject, need, nullable, pick } from "../input.js";
|
|
6
6
|
|
|
7
|
-
const identifier = Type.String({ pattern:
|
|
7
|
+
const identifier = Type.String({ pattern: historyIdentifierPattern.source });
|
|
8
8
|
const nullableOffset = Type.Union([Type.Integer(), Type.Null()]);
|
|
9
9
|
const node = Type.Object({
|
|
10
10
|
host: identifier,
|
|
@@ -58,20 +58,20 @@ export const historyParameters = Type.Object({
|
|
|
58
58
|
action: Type.Union([Type.Literal("search"), Type.Literal("read")], {
|
|
59
59
|
description: "search 搜索或列会话;read 读取指定节点正文与上下级。各动作仅读取自身字段,其余字段忽略。",
|
|
60
60
|
}),
|
|
61
|
-
host: nullable(Type.String({ pattern:
|
|
62
|
-
dimension: nullable(Type.String({ pattern:
|
|
61
|
+
host: nullable(Type.String({ pattern: historyIdentifierPattern.source, description: "可选来源筛选(如 pi、dsh、claude、antigravity)。" })),
|
|
62
|
+
dimension: nullable(Type.String({ pattern: historyIdentifierPattern.source, description: "仅 search:可选范围筛选(raw 表示仅原文,或指定摘要维度如 monthly、session;省略查全部)。" })),
|
|
63
63
|
query: nullable(Type.String({ description: "仅 search:不区分大小写的连续关键词;省略时列出各会话(或指定维度摘要)。" })),
|
|
64
64
|
sessionId: nullable(Type.String({ description: "仅 search:限定在指定会话 ID 内搜索。" })),
|
|
65
65
|
from: nullable(Type.String({ description: "仅 search:ISO 日期或时间下界。" })),
|
|
66
66
|
to: nullable(Type.String({ description: "仅 search:ISO 日期或时间上界。" })),
|
|
67
67
|
id: nullable(Type.String({ description: "仅 read,必填:search 或上下级返回的节点 id。" })),
|
|
68
68
|
offset: nullable(Type.Integer({ minimum: 0, description: "search:匹配结果偏移;read:正文字符偏移。默认 0。" })),
|
|
69
|
-
limit: nullable(Type.Integer({ minimum: 1, maximum:
|
|
69
|
+
limit: nullable(Type.Integer({ minimum: 1, maximum: historyPageLimits.read.max, description: `search:最多返回条数(默认 ${historyPageLimits.search.default},上限 ${historyPageLimits.search.max});read:正文字符数(默认 ${historyPageLimits.read.default})。` })),
|
|
70
70
|
childrenOffset: nullable(Type.Integer({ minimum: 0, description: "仅 read:子节点列表偏移,默认 0;续读传上页 nextChildrenOffset。" })),
|
|
71
71
|
}, { additionalProperties: false });
|
|
72
72
|
|
|
73
73
|
export type HistoryInput =
|
|
74
|
-
| { action: "search"
|
|
74
|
+
| ({ action: "search" } & HistoryQuery)
|
|
75
75
|
| { action: "read"; id: string; host?: HistoryHost; offset?: number; limit?: number; childrenOffset?: number };
|
|
76
76
|
|
|
77
77
|
const valid = schema(historyParameters);
|
|
@@ -79,8 +79,8 @@ const valid = schema(historyParameters);
|
|
|
79
79
|
export function historyInput(value: unknown): HistoryInput {
|
|
80
80
|
const args = inputObject(value, valid, "历史参数格式无效");
|
|
81
81
|
if (args.action === "search") {
|
|
82
|
-
const limit = args.limit === undefined ?
|
|
83
|
-
requireThat(limit <=
|
|
82
|
+
const limit = args.limit === undefined ? historyPageLimits.search.default : args.limit as number;
|
|
83
|
+
requireThat(limit <= historyPageLimits.search.max, `search 的 limit 最多 ${historyPageLimits.search.max}。`);
|
|
84
84
|
return {
|
|
85
85
|
action: "search",
|
|
86
86
|
...(pick(args, ["host", "dimension", "query", "sessionId", "from", "to", "offset", "limit"]) as
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type { CallAccess } from "../access.js";
|
|
1
|
+
import { defineTool, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
2
|
import { markdownResult } from "../result.js";
|
|
4
3
|
import { historyDescription, historyInput, historyParameters, historyResultSchema } from "./contract.js";
|
|
5
4
|
import { executeHistory } from "./actions.js";
|
|
6
5
|
|
|
7
|
-
export function
|
|
8
|
-
|
|
6
|
+
export function registerPiHistoryTool(pi: ExtensionAPI, root: string, access: { check(): void }) {
|
|
7
|
+
const tool = defineTool({
|
|
8
|
+
namespace: { name: "pbot", description: "工作区历史查询。" },
|
|
9
9
|
name: "pbot_history",
|
|
10
10
|
label: "历史对话",
|
|
11
11
|
description: historyDescription,
|
|
@@ -18,4 +18,6 @@ export function historyTool(root: string, access: CallAccess) {
|
|
|
18
18
|
return markdownResult(result, args.action === "search" ? "历史搜索" : "历史正文");
|
|
19
19
|
},
|
|
20
20
|
});
|
|
21
|
+
pi.registerTool(tool);
|
|
22
|
+
return () => pi.registerTool({ ...tool, exposure: "hidden" });
|
|
21
23
|
}
|
package/src/ui/dsh/elements.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { object } from "../../common/json.js";
|
|
2
|
-
import { stateLabel } from "../presentation.js";
|
|
3
2
|
|
|
4
3
|
export const record = (value: unknown): Record<string, unknown> => { if (!object(value)) throw new Error("管理数据无效。"); return value; };
|
|
5
4
|
export const rows = (value: unknown) => Array.isArray(value) ? value.map(record) : [];
|
|
6
5
|
export const text = (value: unknown) => value === null || value === undefined ? "" : String(value);
|
|
7
|
-
export const objectInput = (value: string) => record(JSON.parse(value || "{}"));
|
|
8
|
-
export const lines = (value: string) => value.split(/\r?\n/).map(item => item.trim()).filter(Boolean);
|
|
9
6
|
|
|
10
7
|
export function element<K extends keyof HTMLElementTagNameMap>(tag: K, content = "", className = "") {
|
|
11
8
|
const node = document.createElement(tag); node.textContent = content; node.className = className; return node;
|
|
@@ -18,10 +15,9 @@ export function group(parent: HTMLElement, className = "pbot-stack") {
|
|
|
18
15
|
export function details(parent: HTMLElement, title: string) {
|
|
19
16
|
const node = element("details", "", "pbot-disclosure"); node.append(element("summary", title)); parent.append(node); return node;
|
|
20
17
|
}
|
|
21
|
-
export function field(parent: HTMLElement, label: string
|
|
22
|
-
const wrapper = element("label", "", "pbot-field"), input =
|
|
23
|
-
wrapper.append(element("span", label)); input.
|
|
24
|
-
if (input instanceof HTMLTextAreaElement) input.rows = 3;
|
|
18
|
+
export function field(parent: HTMLElement, label: string) {
|
|
19
|
+
const wrapper = element("label", "", "pbot-field"), input = element("input");
|
|
20
|
+
wrapper.append(element("span", label)); input.setAttribute("aria-label", label);
|
|
25
21
|
wrapper.append(input); parent.append(wrapper); return input;
|
|
26
22
|
}
|
|
27
23
|
export function select(parent: HTMLElement, label: string, values: [string, string][]) {
|
|
@@ -30,9 +26,6 @@ export function select(parent: HTMLElement, label: string, values: [string, stri
|
|
|
30
26
|
for (const [value, title] of values) { const option = element("option", title); option.value = value; input.append(option); }
|
|
31
27
|
wrapper.append(input); parent.append(wrapper); return input;
|
|
32
28
|
}
|
|
33
|
-
export function badge(state: unknown) {
|
|
34
|
-
const node = element("span", stateLabel(state), "pbot-badge"); node.dataset.state = text(state); return node;
|
|
35
|
-
}
|
|
36
29
|
export function facts(values: [string, unknown][]) {
|
|
37
30
|
const node = element("dl", "", "pbot-facts");
|
|
38
31
|
for (const [label, value] of values) node.append(element("dt", label), element("dd", text(value) || "—"));
|
|
@@ -41,8 +34,8 @@ export function facts(values: [string, unknown][]) {
|
|
|
41
34
|
export function empty(title: string, description: string) {
|
|
42
35
|
const node = element("div", "", "pbot-empty"); node.append(element("h3", title), note(description)); return node;
|
|
43
36
|
}
|
|
44
|
-
export function pageTitle(parent: HTMLElement, title: string
|
|
45
|
-
const node = element("header", "", "pbot-page-title"); node.append(element("h2", title));
|
|
37
|
+
export function pageTitle(parent: HTMLElement, title: string) {
|
|
38
|
+
const node = element("header", "", "pbot-page-title"); node.append(element("h2", title)); parent.append(node); return node;
|
|
46
39
|
}
|
|
47
40
|
export function time(value: unknown) {
|
|
48
41
|
const date = new Date(typeof value === "number" ? value : text(value));
|