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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
1
|
import { requireThat } from "../../common/validation.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { historyPageLimits } from "../../model/history.js";
|
|
3
|
+
import { historyBucketFromTimestamp, rawHistoryBucket, unknownHistoryBucket, } from "../../storage/history-files.js";
|
|
4
|
+
import { workspaceHistoryFiles } from "./workspace-history.js";
|
|
5
5
|
import { orderedRawExchanges, rawSessionSpan, rawSessionTitle } from "./history-index.js";
|
|
6
6
|
const summaryIdPrefix = "summary:";
|
|
7
7
|
const page = (values, offset, limit) => ({
|
|
@@ -93,39 +93,38 @@ function inTimeRange(from, to, after, before) {
|
|
|
93
93
|
* Uses ripgrep (with automatic Node fallback) to pre-filter candidate JSON files before parsing.
|
|
94
94
|
*/
|
|
95
95
|
export function searchWorkspaceHistory(root, query = {}) {
|
|
96
|
-
const { host, sessionId, dimension, from, to, offset = 0, limit =
|
|
96
|
+
const { host, sessionId, dimension, from, to, offset = 0, limit = historyPageLimits.search.default } = query;
|
|
97
97
|
const needle = (query.query ?? "").trim().toLowerCase();
|
|
98
98
|
const after = from === undefined ? -Infinity : Date.parse(from);
|
|
99
99
|
const before = to === undefined ? Infinity : Date.parse(to);
|
|
100
100
|
requireThat(!Number.isNaN(after) && !Number.isNaN(before) && after <= before, "时间范围无效,请使用 ISO 日期或时间。");
|
|
101
|
-
const
|
|
102
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", layout);
|
|
101
|
+
const files = workspaceHistoryFiles(root);
|
|
103
102
|
const warnings = [];
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
warnings.push(flatNotice);
|
|
108
|
-
}
|
|
103
|
+
const flatNotice = files.migrationNotice();
|
|
104
|
+
if (flatNotice)
|
|
105
|
+
warnings.push(flatNotice);
|
|
109
106
|
const matches = [];
|
|
107
|
+
function collectSummaries(artifacts) {
|
|
108
|
+
warnings.push(...files.warnings);
|
|
109
|
+
for (const artifact of artifacts) {
|
|
110
|
+
if (!inTimeRange(artifact.from, artifact.to, after, before))
|
|
111
|
+
continue;
|
|
112
|
+
if (needle && !`${artifact.title}\n${artifact.text}`.toLowerCase().includes(needle))
|
|
113
|
+
continue;
|
|
114
|
+
const brief = summaryBrief(artifact);
|
|
115
|
+
if (host && brief.host !== host || sessionId && brief.sessionId !== sessionId)
|
|
116
|
+
continue;
|
|
117
|
+
matches.push({
|
|
118
|
+
...brief,
|
|
119
|
+
parents: artifact.dimension === "monthly" ? [] : artifact.source.rawIds,
|
|
120
|
+
snippet: sliceSnippet(artifact.text, needle),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
110
124
|
if (!needle) {
|
|
111
125
|
// Empty query: list sessions (default / dimension="raw") or list summaries of a specific dimension.
|
|
112
126
|
if (dimension && dimension !== "raw") {
|
|
113
|
-
|
|
114
|
-
warnings.push(...files.warnings);
|
|
115
|
-
for (const artifact of summaries) {
|
|
116
|
-
if (host && artifact.host !== host)
|
|
117
|
-
continue;
|
|
118
|
-
if (sessionId && artifact.sessionId !== sessionId)
|
|
119
|
-
continue;
|
|
120
|
-
if (!inTimeRange(artifact.from, artifact.to, after, before))
|
|
121
|
-
continue;
|
|
122
|
-
const brief = summaryBrief(artifact);
|
|
123
|
-
matches.push({
|
|
124
|
-
...brief,
|
|
125
|
-
parents: artifact.dimension === "monthly" ? [] : artifact.source.rawIds,
|
|
126
|
-
snippet: sliceSnippet(artifact.text, ""),
|
|
127
|
-
});
|
|
128
|
-
}
|
|
127
|
+
collectSummaries(files.listSummaries(dimension));
|
|
129
128
|
}
|
|
130
129
|
else {
|
|
131
130
|
const raws = files.listRaw(host);
|
|
@@ -179,24 +178,7 @@ export function searchWorkspaceHistory(root, query = {}) {
|
|
|
179
178
|
}
|
|
180
179
|
}
|
|
181
180
|
for (const dim of summaryDimensions) {
|
|
182
|
-
|
|
183
|
-
warnings.push(...files.warnings);
|
|
184
|
-
for (const artifact of candidateSummaries) {
|
|
185
|
-
if (host && artifact.host !== host)
|
|
186
|
-
continue;
|
|
187
|
-
if (sessionId && artifact.sessionId !== sessionId)
|
|
188
|
-
continue;
|
|
189
|
-
const searchable = `${artifact.title}\n${artifact.text}`;
|
|
190
|
-
if (!searchable.toLowerCase().includes(needle))
|
|
191
|
-
continue;
|
|
192
|
-
if (!inTimeRange(artifact.from, artifact.to, after, before))
|
|
193
|
-
continue;
|
|
194
|
-
matches.push({
|
|
195
|
-
...summaryBrief(artifact),
|
|
196
|
-
parents: artifact.dimension === "monthly" ? [] : artifact.source.rawIds,
|
|
197
|
-
snippet: sliceSnippet(artifact.text, needle),
|
|
198
|
-
});
|
|
199
|
-
}
|
|
181
|
+
collectSummaries(files.searchCandidateSummaries(dim, needle));
|
|
200
182
|
}
|
|
201
183
|
}
|
|
202
184
|
matches.sort((a, b) => b.to.localeCompare(a.to) || a.id.localeCompare(b.id));
|
|
@@ -231,20 +213,19 @@ function findMonthlyParent(files, bucket, rawId) {
|
|
|
231
213
|
return summaryBrief(monthly);
|
|
232
214
|
}
|
|
233
215
|
/** O(1) read of a session root, summary artifact, or individual raw exchange. */
|
|
234
|
-
export function readWorkspaceHistory(root, id, offset = 0, limit =
|
|
235
|
-
const
|
|
236
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", layout);
|
|
216
|
+
export function readWorkspaceHistory(root, id, offset = 0, limit = historyPageLimits.read.default, childrenOffset = 0, host) {
|
|
217
|
+
const files = workspaceHistoryFiles(root);
|
|
237
218
|
const baseWarnings = [];
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
baseWarnings.push(flatNotice);
|
|
242
|
-
}
|
|
219
|
+
const flatNotice = files.migrationNotice();
|
|
220
|
+
if (flatNotice)
|
|
221
|
+
baseWarnings.push(flatNotice);
|
|
243
222
|
// 1. Summary artifact: summary:<dimension>:<artifactId>
|
|
244
223
|
const parsedSummary = parseSummaryNodeId(id);
|
|
245
224
|
if (parsedSummary) {
|
|
246
225
|
const artifact = files.readSummary(parsedSummary.dimension, parsedSummary.artifactId);
|
|
247
|
-
requireThat(artifact
|
|
226
|
+
requireThat(artifact, "历史节点不存在,请重新搜索。");
|
|
227
|
+
const brief = summaryBrief(artifact);
|
|
228
|
+
requireThat(!host || brief.host === host, "历史节点不存在,请重新搜索。");
|
|
248
229
|
const parents = [];
|
|
249
230
|
const children = [];
|
|
250
231
|
if (artifact.dimension === "monthly") {
|
|
@@ -285,14 +266,14 @@ export function readWorkspaceHistory(root, id, offset = 0, limit = 12000, childr
|
|
|
285
266
|
const pagedChildren = page(children, childrenOffset, 20);
|
|
286
267
|
const sliced = sliceText(artifact.text, offset, limit);
|
|
287
268
|
return {
|
|
288
|
-
...
|
|
269
|
+
...brief,
|
|
289
270
|
...sliced,
|
|
290
271
|
parents,
|
|
291
272
|
children: pagedChildren.values,
|
|
292
273
|
nextChildrenOffset: pagedChildren.nextOffset,
|
|
293
274
|
source: {
|
|
294
|
-
host:
|
|
295
|
-
sessionId:
|
|
275
|
+
host: brief.host,
|
|
276
|
+
sessionId: brief.sessionId,
|
|
296
277
|
entryIds: artifact.source.exchangeIds,
|
|
297
278
|
dimension: artifact.dimension,
|
|
298
279
|
},
|
|
@@ -17,4 +17,4 @@ export type ParsedHistoryCommand = {
|
|
|
17
17
|
input: Record<string, unknown>;
|
|
18
18
|
};
|
|
19
19
|
export declare const historyCommandUsage = "\u7528\u6CD5\uFF1A/pbot history summary [\u7EF4\u5EA6...] [--force] [--backend <acp>] [--model <model>] [--thinking <level>] | migrate [--dry-run] | status | list | {\"action\":\"search\"|\"read\",...}";
|
|
20
|
-
export declare function parseHistoryCommand(raw: string): ParsedHistoryCommand;
|
|
20
|
+
export declare function parseHistoryCommand(raw: string | readonly string[]): ParsedHistoryCommand;
|
|
@@ -2,18 +2,19 @@ import { object } from "../../common/json.js";
|
|
|
2
2
|
import { requireThat } from "../../common/validation.js";
|
|
3
3
|
export const historyCommandUsage = '用法:/pbot history summary [维度...] [--force] [--backend <acp>] [--model <model>] [--thinking <level>] | migrate [--dry-run] | status | list | {"action":"search"|"read",...}';
|
|
4
4
|
export function parseHistoryCommand(raw) {
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const tokens = typeof raw === "string"
|
|
6
|
+
? raw.trim().startsWith("{") ? [raw.trim()] : raw.trim().split(/\s+/).filter(Boolean)
|
|
7
|
+
: raw;
|
|
8
|
+
const [sub] = tokens;
|
|
9
|
+
if (!sub || sub === "status" && tokens.length === 1)
|
|
7
10
|
return { kind: "status" };
|
|
8
|
-
if (
|
|
11
|
+
if (sub === "list" && tokens.length === 1)
|
|
9
12
|
return { kind: "list" };
|
|
10
|
-
if (
|
|
11
|
-
const parsed = JSON.parse(
|
|
13
|
+
if (tokens.length === 1 && sub.startsWith("{")) {
|
|
14
|
+
const parsed = JSON.parse(sub);
|
|
12
15
|
requireThat(object(parsed), "历史查询参数必须是 JSON 对象。");
|
|
13
16
|
return { kind: "query", input: parsed };
|
|
14
17
|
}
|
|
15
|
-
const tokens = trimmed.split(/\s+/);
|
|
16
|
-
const sub = tokens[0];
|
|
17
18
|
if (sub === "migrate") {
|
|
18
19
|
let dryRun = false;
|
|
19
20
|
for (const token of tokens.slice(1)) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { requireThat } from "../../common/validation.js";
|
|
2
|
-
import { isSummaryDimension } from "../../storage/history-format.js";
|
|
1
|
+
import { isHistoryIdentifier, requireThat } from "../../common/validation.js";
|
|
3
2
|
import { monthlySummaryDimension } from "./summary-dimensions/monthly.js";
|
|
4
3
|
import { sessionSummaryDimension } from "./summary-dimensions/session.js";
|
|
5
4
|
const registry = new Map([
|
|
@@ -8,7 +7,7 @@ const registry = new Map([
|
|
|
8
7
|
]);
|
|
9
8
|
/** Register a custom summary dimension (e.g. daily, decisions, topics). */
|
|
10
9
|
export function registerSummaryDimension(dimension) {
|
|
11
|
-
requireThat(
|
|
10
|
+
requireThat(isHistoryIdentifier(dimension.id), "摘要维度 ID 无效:" + dimension.id);
|
|
12
11
|
registry.set(dimension.id, dimension);
|
|
13
12
|
}
|
|
14
13
|
export function unregisterSummaryDimension(id) {
|
|
@@ -5,13 +5,10 @@ export interface InspectSummaryOptions {
|
|
|
5
5
|
thresholdDays?: number;
|
|
6
6
|
now?: Date;
|
|
7
7
|
}
|
|
8
|
-
export
|
|
9
|
-
dimensions?: readonly string[];
|
|
10
|
-
thresholdDays?: number;
|
|
11
|
-
now?: Date;
|
|
12
|
-
}
|
|
8
|
+
export type CheckSummaryReminderOptions = InspectSummaryOptions;
|
|
13
9
|
/** Read-only startup probe: reminds when raw history has existed >= thresholdDays and no summary ran within thresholdDays. */
|
|
14
10
|
export declare function checkHistorySummaryReminder(root: string, options?: CheckSummaryReminderOptions): HistorySummaryReminder | undefined;
|
|
11
|
+
export declare function historyStartupNotices(root: string): string[];
|
|
15
12
|
/** Read-only inspection of raw archives vs derived summaries across requested dimensions. */
|
|
16
13
|
export declare function inspectWorkspaceSummaries(root: string, options?: InspectSummaryOptions): {
|
|
17
14
|
layout: HistoryLayout;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
2
|
import { setTimeout as delay } from "node:timers/promises";
|
|
3
3
|
import { requireThat } from "../../common/validation.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { summaryConcurrency } from "../../model/workspace-config.js";
|
|
5
|
+
import { workspaceHistoryFiles } from "./workspace-history.js";
|
|
6
6
|
import { rawSessionSpan } from "./history-index.js";
|
|
7
7
|
import { resolveSummaryDimensions } from "./summary-registry.js";
|
|
8
|
-
const defaultConcurrency = 3;
|
|
9
|
-
const maxConcurrency = 8;
|
|
10
8
|
const lockRetryAttempts = 5;
|
|
11
9
|
const lockRetryDelayMs = 40;
|
|
12
10
|
export const defaultSummaryReminderDays = 7;
|
|
@@ -70,8 +68,8 @@ function evaluateSummaryReminder(raws, allSummaries, pendingCount, options = {})
|
|
|
70
68
|
const rawAgeDays = Math.floor((nowMs - oldestRawMs) / dayMs);
|
|
71
69
|
const daysSinceLastSummary = latestSummaryMs === undefined ? undefined : Math.floor((nowMs - latestSummaryMs) / dayMs);
|
|
72
70
|
const message = daysSinceLastSummary === undefined
|
|
73
|
-
? `历史原文已累计 ${rawAgeDays} 天(待摘要 ${pendingCount}
|
|
74
|
-
: `历史原文已累计 ${rawAgeDays} 天,且已 ${daysSinceLastSummary} 天未触发摘要整理(待摘要 ${pendingCount}
|
|
71
|
+
? `历史原文已累计 ${rawAgeDays} 天(待摘要 ${pendingCount} 项),尚未触发过摘要整理;可在终端运行 pbot history summary 生成摘要(Pi/dsh 可用 /pbot history summary)。`
|
|
72
|
+
: `历史原文已累计 ${rawAgeDays} 天,且已 ${daysSinceLastSummary} 天未触发摘要整理(待摘要 ${pendingCount} 项);可在终端运行 pbot history summary 更新摘要(Pi/dsh 可用 /pbot history summary)。`;
|
|
75
73
|
return {
|
|
76
74
|
rawCount: raws.length,
|
|
77
75
|
pendingCount,
|
|
@@ -85,8 +83,23 @@ function evaluateSummaryReminder(raws, allSummaries, pendingCount, options = {})
|
|
|
85
83
|
}
|
|
86
84
|
/** Read-only startup probe: reminds when raw history has existed >= thresholdDays and no summary ran within thresholdDays. */
|
|
87
85
|
export function checkHistorySummaryReminder(root, options = {}) {
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
return summaryReminder(workspaceHistoryFiles(root), options);
|
|
87
|
+
}
|
|
88
|
+
export function historyStartupNotices(root) {
|
|
89
|
+
const notices = [];
|
|
90
|
+
try {
|
|
91
|
+
const files = workspaceHistoryFiles(root);
|
|
92
|
+
const migration = files.migrationNotice();
|
|
93
|
+
if (migration)
|
|
94
|
+
notices.push(migration);
|
|
95
|
+
const reminder = summaryReminder(files, {});
|
|
96
|
+
if (reminder)
|
|
97
|
+
notices.push(reminder.message);
|
|
98
|
+
}
|
|
99
|
+
catch { /* History diagnostics are best effort during host startup. */ }
|
|
100
|
+
return notices;
|
|
101
|
+
}
|
|
102
|
+
function summaryReminder(files, options) {
|
|
90
103
|
const raws = files.listRaw();
|
|
91
104
|
if (!raws.length)
|
|
92
105
|
return undefined;
|
|
@@ -96,48 +109,11 @@ export function checkHistorySummaryReminder(root, options = {}) {
|
|
|
96
109
|
const oldestRawMs = oldestRawTimestamp(raws);
|
|
97
110
|
if (oldestRawMs === undefined || nowMs - oldestRawMs < thresholdDays * dayMs)
|
|
98
111
|
return undefined;
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
const summariesByDimension = new Map();
|
|
102
|
-
const allSummaries = [];
|
|
103
|
-
let pendingCount = 0;
|
|
104
|
-
const loadDimension = (dimId) => {
|
|
105
|
-
const cached = summariesByDimension.get(dimId);
|
|
106
|
-
if (cached)
|
|
107
|
-
return cached;
|
|
108
|
-
const list = files.listSummaries(dimId);
|
|
109
|
-
const map = new Map(list.map(item => [item.id, item]));
|
|
110
|
-
summariesByDimension.set(dimId, map);
|
|
111
|
-
return map;
|
|
112
|
-
};
|
|
113
|
-
for (const dimension of dimensions) {
|
|
114
|
-
seenDimensions.add(dimension.id);
|
|
115
|
-
if (dimension.id !== "session")
|
|
116
|
-
loadDimension("session");
|
|
117
|
-
const existing = loadDimension(dimension.id);
|
|
118
|
-
allSummaries.push(...existing.values());
|
|
119
|
-
const plan = dimension.plan(raws, existing, { force: false, summariesByDimension });
|
|
120
|
-
pendingCount += plan.tasks.length;
|
|
121
|
-
}
|
|
122
|
-
for (const dim of files.listDimensions()) {
|
|
123
|
-
if (seenDimensions.has(dim))
|
|
124
|
-
continue;
|
|
125
|
-
allSummaries.push(...loadDimension(dim).values());
|
|
126
|
-
}
|
|
127
|
-
return evaluateSummaryReminder(raws, allSummaries, pendingCount, options);
|
|
112
|
+
const { totalPending, allSummaries } = inspectDimensions(files, raws, options, []);
|
|
113
|
+
return evaluateSummaryReminder(raws, allSummaries, totalPending, options);
|
|
128
114
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const layout = readWorkspaceHistoryLayoutSync(root);
|
|
132
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", layout);
|
|
133
|
-
const raws = files.listRaw();
|
|
134
|
-
const warnings = [...files.warnings];
|
|
135
|
-
if (layout === "monthly") {
|
|
136
|
-
const flatNotice = files.detectFlatFiles().message;
|
|
137
|
-
if (flatNotice)
|
|
138
|
-
warnings.push(flatNotice);
|
|
139
|
-
}
|
|
140
|
-
const dimensions = resolveSummaryDimensions(options.dimensions, layout);
|
|
115
|
+
function inspectDimensions(files, raws, options, warnings) {
|
|
116
|
+
const dimensions = resolveSummaryDimensions(options.dimensions, files.layout);
|
|
141
117
|
const statuses = [];
|
|
142
118
|
const seenDimensions = new Set();
|
|
143
119
|
const summariesByDimension = new Map();
|
|
@@ -188,9 +164,20 @@ export function inspectWorkspaceSummaries(root, options = {}) {
|
|
|
188
164
|
continue;
|
|
189
165
|
allSummaries.push(...loadDimension(dim).values());
|
|
190
166
|
}
|
|
167
|
+
return { statuses, totalPending, allSummaries };
|
|
168
|
+
}
|
|
169
|
+
/** Read-only inspection of raw archives vs derived summaries across requested dimensions. */
|
|
170
|
+
export function inspectWorkspaceSummaries(root, options = {}) {
|
|
171
|
+
const files = workspaceHistoryFiles(root);
|
|
172
|
+
const raws = files.listRaw();
|
|
173
|
+
const warnings = [...files.warnings];
|
|
174
|
+
const flatNotice = files.migrationNotice();
|
|
175
|
+
if (flatNotice)
|
|
176
|
+
warnings.push(flatNotice);
|
|
177
|
+
const { statuses, totalPending, allSummaries } = inspectDimensions(files, raws, options, warnings);
|
|
191
178
|
const reminder = evaluateSummaryReminder(raws, allSummaries, totalPending, options);
|
|
192
179
|
return {
|
|
193
|
-
layout,
|
|
180
|
+
layout: files.layout,
|
|
194
181
|
rawCount: raws.length,
|
|
195
182
|
dimensions: statuses,
|
|
196
183
|
warnings: [...new Set(warnings)],
|
|
@@ -206,29 +193,28 @@ export async function runWorkspaceSummaries(options) {
|
|
|
206
193
|
const startedAt = Date.now();
|
|
207
194
|
const signal = options.signal ?? new AbortController().signal;
|
|
208
195
|
signal.throwIfAborted();
|
|
209
|
-
const concurrency = Math.max(1, Math.min(
|
|
210
|
-
const
|
|
211
|
-
const dimensions = resolveSummaryDimensions(options.dimensions, layout);
|
|
212
|
-
const
|
|
196
|
+
const concurrency = Math.max(1, Math.min(summaryConcurrency.max, Math.floor(options.concurrency ?? summaryConcurrency.default)));
|
|
197
|
+
const files = workspaceHistoryFiles(options.root);
|
|
198
|
+
const dimensions = resolveSummaryDimensions(options.dimensions, files.layout);
|
|
199
|
+
const warnings = [];
|
|
200
|
+
const loadSummaries = (id) => {
|
|
201
|
+
const items = files.listSummaries(id);
|
|
202
|
+
warnings.push(...files.warnings);
|
|
203
|
+
return new Map(items.map(item => [item.id, item]));
|
|
204
|
+
};
|
|
205
|
+
// Capture each publication baseline before reading the input it will summarize.
|
|
206
|
+
const plannedDimensions = dimensions.map(dimension => ({ dimension, existing: loadSummaries(dimension.id) }));
|
|
213
207
|
const raws = files.listRaw();
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
warnings.push(flatNotice);
|
|
219
|
-
}
|
|
208
|
+
warnings.push(...files.warnings);
|
|
209
|
+
const flatNotice = files.migrationNotice();
|
|
210
|
+
if (flatNotice)
|
|
211
|
+
warnings.push(flatNotice);
|
|
220
212
|
const summariesByDimension = new Map();
|
|
221
213
|
const reports = [];
|
|
222
|
-
for (const dimension of
|
|
214
|
+
for (const { dimension, existing } of plannedDimensions) {
|
|
223
215
|
signal.throwIfAborted();
|
|
224
|
-
if (dimension.id !== "session"
|
|
225
|
-
|
|
226
|
-
warnings.push(...files.warnings);
|
|
227
|
-
summariesByDimension.set("session", new Map(sessionList.map(item => [item.id, item])));
|
|
228
|
-
}
|
|
229
|
-
const existingList = files.listSummaries(dimension.id);
|
|
230
|
-
warnings.push(...files.warnings);
|
|
231
|
-
const existing = new Map(existingList.map(item => [item.id, item]));
|
|
216
|
+
if (dimension.id !== "session")
|
|
217
|
+
summariesByDimension.set("session", loadSummaries("session"));
|
|
232
218
|
summariesByDimension.set(dimension.id, existing);
|
|
233
219
|
const plan = dimension.plan(raws, existing, { force: Boolean(options.force), summariesByDimension });
|
|
234
220
|
const report = {
|
|
@@ -256,12 +242,24 @@ export async function runWorkspaceSummaries(options) {
|
|
|
256
242
|
const output = await options.summarizer(request, signal);
|
|
257
243
|
signal.throwIfAborted();
|
|
258
244
|
const artifact = dimension.finalize(task, output, new Date().toISOString());
|
|
259
|
-
await withSummaryLockRetry(files, dimension.id, () => {
|
|
245
|
+
const published = await withSummaryLockRetry(files, dimension.id, () => {
|
|
260
246
|
signal.throwIfAborted();
|
|
261
|
-
files.
|
|
247
|
+
const current = files.readSummary(dimension.id, artifact.id);
|
|
248
|
+
if (isDeepStrictEqual(current, existing.get(artifact.id))) {
|
|
249
|
+
files.saveSummary(artifact);
|
|
250
|
+
return artifact;
|
|
251
|
+
}
|
|
252
|
+
if (current)
|
|
253
|
+
existing.set(artifact.id, current);
|
|
254
|
+
else
|
|
255
|
+
existing.delete(artifact.id);
|
|
256
|
+
requireThat(current && isDeepStrictEqual(current.source, artifact.source), "摘要在生成期间已变更,请重新运行摘要。");
|
|
257
|
+
return current;
|
|
262
258
|
}, signal);
|
|
263
|
-
existing.set(artifact.id,
|
|
264
|
-
if (
|
|
259
|
+
existing.set(artifact.id, published);
|
|
260
|
+
if (published !== artifact)
|
|
261
|
+
report.skipped++;
|
|
262
|
+
else if (task.mode === "create")
|
|
265
263
|
report.created++;
|
|
266
264
|
else if (task.mode === "incremental")
|
|
267
265
|
report.incremental++;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { HistoryFiles } from "../../storage/history-files.js";
|
|
3
|
+
import { readWorkspaceHistoryLayoutSync } from "../workspace/workspace-config.js";
|
|
4
|
+
export function workspaceHistoryFiles(root, host) {
|
|
5
|
+
return new HistoryFiles(join(root, ".pbot/history"), host, readWorkspaceHistoryLayoutSync(root));
|
|
6
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Each host owns its file, including when two hosts activate the same canonical workspace concurrently. */
|
|
2
|
+
export declare function bindWorkspacePlugin(root: string, host: string, binding?: string): void;
|
|
3
|
+
export declare function workspacePluginReleases(root: string): Record<string, string>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdirSync, readdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
5
|
+
import { object } from "../../common/json.js";
|
|
6
|
+
import { resourceRoot } from "../../common/paths.js";
|
|
7
|
+
import { requireThat } from "../../common/validation.js";
|
|
8
|
+
import { releaseLine } from "../../common/version.js";
|
|
9
|
+
import { readJsonFile, writeJsonFile } from "../../storage/atomic-json.js";
|
|
10
|
+
function bindingDirectory(root) {
|
|
11
|
+
const key = createHash("sha256").update(root).digest("hex");
|
|
12
|
+
return join(homedir(), ".pbot", "workspaces", key);
|
|
13
|
+
}
|
|
14
|
+
// Full plugins own a local manifest. Thin clients can supply the release stamped into their cached hooks.
|
|
15
|
+
function pluginBinding(value) {
|
|
16
|
+
requireThat(typeof value === "string", "无效的插件安装记录。");
|
|
17
|
+
if (!isAbsolute(value))
|
|
18
|
+
releaseLine(value);
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function permissionDenied(error) {
|
|
22
|
+
return ["EACCES", "EPERM", "EROFS"].includes(error.code ?? "");
|
|
23
|
+
}
|
|
24
|
+
/** Each host owns its file, including when two hosts activate the same canonical workspace concurrently. */
|
|
25
|
+
export function bindWorkspacePlugin(root, host, binding = resolve(resourceRoot, "../package.json")) {
|
|
26
|
+
const directory = bindingDirectory(root);
|
|
27
|
+
const file = encodeURIComponent(host) + ".json";
|
|
28
|
+
try {
|
|
29
|
+
if (readJsonFile(directory, file, pluginBinding) === binding)
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (permissionDenied(error))
|
|
34
|
+
return;
|
|
35
|
+
if (error.code !== "ENOENT")
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
40
|
+
writeJsonFile(directory, file, binding, pluginBinding);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (!permissionDenied(error))
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function workspacePluginReleases(root) {
|
|
48
|
+
const directory = bindingDirectory(root);
|
|
49
|
+
let files;
|
|
50
|
+
try {
|
|
51
|
+
files = readdirSync(directory);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error.code === "ENOENT" || permissionDenied(error))
|
|
55
|
+
return {};
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
const releases = Object.create(null);
|
|
59
|
+
for (const file of files.filter(name => name.endsWith(".json"))) {
|
|
60
|
+
const host = decodeURIComponent(file.slice(0, -5));
|
|
61
|
+
try {
|
|
62
|
+
const binding = readJsonFile(directory, file, pluginBinding);
|
|
63
|
+
if (!isAbsolute(binding)) {
|
|
64
|
+
releases[host] = binding;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const manifest = JSON.parse(readFileSync(binding, "utf8"));
|
|
68
|
+
requireThat(object(manifest) && typeof manifest.version === "string", "无效的插件安装清单:" + binding);
|
|
69
|
+
releaseLine(manifest.version);
|
|
70
|
+
releases[host] = manifest.version;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error.code !== "ENOENT" && !permissionDenied(error))
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return releases;
|
|
78
|
+
}
|
|
@@ -2,12 +2,13 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
import { mkdir, readFile } from "node:fs/promises";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { object } from "../../common/json.js";
|
|
5
|
-
import {
|
|
5
|
+
import { acpPermissionPolicies } from "../../model/acp.js";
|
|
6
|
+
import { historyLayouts, summaryConcurrency } from "../../model/workspace-config.js";
|
|
7
|
+
import { isAcpBackend, isOneOf } from "../../common/validation.js";
|
|
6
8
|
import { readJsonFile, writeJsonFile } from "../../storage/atomic-json.js";
|
|
7
9
|
const featureKeys = ["prompts", "skills", "mcp", "history"];
|
|
8
10
|
const summaryKeys = ["backend", "model", "thinking", "concurrency"];
|
|
9
11
|
const historyKeys = ["layout"];
|
|
10
|
-
const historyLayouts = ["monthly", "flat"];
|
|
11
12
|
function nonEmptyString(value) {
|
|
12
13
|
return typeof value === "string" && value.trim().length > 0 && !value.includes("\0");
|
|
13
14
|
}
|
|
@@ -33,7 +34,7 @@ function config(value) {
|
|
|
33
34
|
(command.args === undefined || (Array.isArray(command.args) && command.args.every(arg => typeof arg === "string" && !arg.includes("\0"))));
|
|
34
35
|
if (!object(command) || !launch ||
|
|
35
36
|
(command.env !== undefined && (!object(command.env) || Object.entries(command.env).some(([k, v]) => !k || k.includes("\0") || typeof v !== "string" || v.includes("\0")))) ||
|
|
36
|
-
(command.permission !== undefined && !
|
|
37
|
+
(command.permission !== undefined && !isOneOf(command.permission, acpPermissionPolicies)) ||
|
|
37
38
|
Object.keys(command).some(key => !["command", "args", "env", "permission"].includes(key))) {
|
|
38
39
|
throw new Error("ACP 配置需要 command(内置目标可省略)及可选 args 字符串数组、env 字符串映射、permission(ask、allow 或 deny)。");
|
|
39
40
|
}
|
|
@@ -53,15 +54,15 @@ function config(value) {
|
|
|
53
54
|
throw new Error("summary.thinking 必须是非空字符串。");
|
|
54
55
|
}
|
|
55
56
|
if (value.summary.concurrency !== undefined &&
|
|
56
|
-
(typeof value.summary.concurrency !== "number" || !Number.isInteger(value.summary.concurrency) || value.summary.concurrency < 1 || value.summary.concurrency >
|
|
57
|
-
throw new Error(
|
|
57
|
+
(typeof value.summary.concurrency !== "number" || !Number.isInteger(value.summary.concurrency) || value.summary.concurrency < 1 || value.summary.concurrency > summaryConcurrency.max)) {
|
|
58
|
+
throw new Error(`summary.concurrency 必须是 1 到 ${summaryConcurrency.max} 之间的整数。`);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
if (value.history !== undefined) {
|
|
61
62
|
if (!object(value.history) || Object.keys(value.history).some(key => !historyKeys.includes(key))) {
|
|
62
63
|
throw new Error("history 必须是 JSON 对象,仅支持 layout。");
|
|
63
64
|
}
|
|
64
|
-
if (value.history.layout !== undefined && !
|
|
65
|
+
if (value.history.layout !== undefined && !isOneOf(value.history.layout, historyLayouts)) {
|
|
65
66
|
throw new Error('history.layout 必须是 "monthly" 或 "flat"。');
|
|
66
67
|
}
|
|
67
68
|
}
|
|
@@ -86,7 +87,7 @@ export function workspaceSummaryConfig(configuration) {
|
|
|
86
87
|
backend: raw?.backend ?? "pi",
|
|
87
88
|
...(raw?.model ? { model: raw.model } : {}),
|
|
88
89
|
...(raw?.thinking ? { thinking: raw.thinking } : {}),
|
|
89
|
-
concurrency: raw?.concurrency ??
|
|
90
|
+
concurrency: raw?.concurrency ?? summaryConcurrency.default,
|
|
90
91
|
};
|
|
91
92
|
}
|
|
92
93
|
export function workspaceHistoryConfig(configuration) {
|
|
@@ -160,5 +161,5 @@ export async function initializeWorkspaceConfig(root) {
|
|
|
160
161
|
await initializeWorkspaceConfig(root);
|
|
161
162
|
}
|
|
162
163
|
export function workspaceDisabledMessage(configuration) {
|
|
163
|
-
return configuration.error ?? `Personal Bot
|
|
164
|
+
return configuration.error ?? `Personal Bot 未在此工作区启用。请在工作区根目录运行 pbot init,也可在 Pi 或 dsh 中执行 /pbot init。配置文件位于 ${configuration.path}`;
|
|
164
165
|
}
|