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,13 +1,13 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
1
|
import { requireThat } from "../../common/validation.js";
|
|
2
|
+
import { historyPageLimits } from "../../model/history.js";
|
|
3
3
|
import type { HistoryHost, HistoryQuery, RawHistory, SummaryArtifact } from "../../model/history.js";
|
|
4
4
|
import {
|
|
5
|
-
HistoryFiles,
|
|
5
|
+
type HistoryFiles,
|
|
6
6
|
historyBucketFromTimestamp,
|
|
7
7
|
rawHistoryBucket,
|
|
8
8
|
unknownHistoryBucket,
|
|
9
9
|
} from "../../storage/history-files.js";
|
|
10
|
-
import {
|
|
10
|
+
import { workspaceHistoryFiles } from "./workspace-history.js";
|
|
11
11
|
import { orderedRawExchanges, rawSessionSpan, rawSessionTitle } from "./history-index.js";
|
|
12
12
|
|
|
13
13
|
const summaryIdPrefix = "summary:";
|
|
@@ -147,37 +147,37 @@ function inTimeRange(from: string, to: string, after: number, before: number): b
|
|
|
147
147
|
* Uses ripgrep (with automatic Node fallback) to pre-filter candidate JSON files before parsing.
|
|
148
148
|
*/
|
|
149
149
|
export function searchWorkspaceHistory(root: string, query: HistoryQuery = {}): HistorySearchResult {
|
|
150
|
-
const { host, sessionId, dimension, from, to, offset = 0, limit =
|
|
150
|
+
const { host, sessionId, dimension, from, to, offset = 0, limit = historyPageLimits.search.default } = query;
|
|
151
151
|
const needle = (query.query ?? "").trim().toLowerCase();
|
|
152
152
|
const after = from === undefined ? -Infinity : Date.parse(from);
|
|
153
153
|
const before = to === undefined ? Infinity : Date.parse(to);
|
|
154
154
|
requireThat(!Number.isNaN(after) && !Number.isNaN(before) && after <= before, "时间范围无效,请使用 ISO 日期或时间。");
|
|
155
155
|
|
|
156
|
-
const
|
|
157
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", layout);
|
|
156
|
+
const files = workspaceHistoryFiles(root);
|
|
158
157
|
const warnings: string[] = [];
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (flatNotice) warnings.push(flatNotice);
|
|
162
|
-
}
|
|
158
|
+
const flatNotice = files.migrationNotice();
|
|
159
|
+
if (flatNotice) warnings.push(flatNotice);
|
|
163
160
|
const matches: HistorySearchMatch[] = [];
|
|
164
161
|
|
|
162
|
+
function collectSummaries(artifacts: SummaryArtifact[]) {
|
|
163
|
+
warnings.push(...files.warnings);
|
|
164
|
+
for (const artifact of artifacts) {
|
|
165
|
+
if (!inTimeRange(artifact.from, artifact.to, after, before)) continue;
|
|
166
|
+
if (needle && !`${artifact.title}\n${artifact.text}`.toLowerCase().includes(needle)) continue;
|
|
167
|
+
const brief = summaryBrief(artifact);
|
|
168
|
+
if (host && brief.host !== host || sessionId && brief.sessionId !== sessionId) continue;
|
|
169
|
+
matches.push({
|
|
170
|
+
...brief,
|
|
171
|
+
parents: artifact.dimension === "monthly" ? [] : artifact.source.rawIds,
|
|
172
|
+
snippet: sliceSnippet(artifact.text, needle),
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
165
177
|
if (!needle) {
|
|
166
178
|
// Empty query: list sessions (default / dimension="raw") or list summaries of a specific dimension.
|
|
167
179
|
if (dimension && dimension !== "raw") {
|
|
168
|
-
|
|
169
|
-
warnings.push(...files.warnings);
|
|
170
|
-
for (const artifact of summaries) {
|
|
171
|
-
if (host && artifact.host !== host) continue;
|
|
172
|
-
if (sessionId && artifact.sessionId !== sessionId) continue;
|
|
173
|
-
if (!inTimeRange(artifact.from, artifact.to, after, before)) continue;
|
|
174
|
-
const brief = summaryBrief(artifact);
|
|
175
|
-
matches.push({
|
|
176
|
-
...brief,
|
|
177
|
-
parents: artifact.dimension === "monthly" ? [] : artifact.source.rawIds,
|
|
178
|
-
snippet: sliceSnippet(artifact.text, ""),
|
|
179
|
-
});
|
|
180
|
-
}
|
|
180
|
+
collectSummaries(files.listSummaries(dimension));
|
|
181
181
|
} else {
|
|
182
182
|
const raws = files.listRaw(host);
|
|
183
183
|
warnings.push(...files.warnings);
|
|
@@ -225,20 +225,7 @@ export function searchWorkspaceHistory(root: string, query: HistoryQuery = {}):
|
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
for (const dim of summaryDimensions) {
|
|
228
|
-
|
|
229
|
-
warnings.push(...files.warnings);
|
|
230
|
-
for (const artifact of candidateSummaries) {
|
|
231
|
-
if (host && artifact.host !== host) continue;
|
|
232
|
-
if (sessionId && artifact.sessionId !== sessionId) continue;
|
|
233
|
-
const searchable = `${artifact.title}\n${artifact.text}`;
|
|
234
|
-
if (!searchable.toLowerCase().includes(needle)) continue;
|
|
235
|
-
if (!inTimeRange(artifact.from, artifact.to, after, before)) continue;
|
|
236
|
-
matches.push({
|
|
237
|
-
...summaryBrief(artifact),
|
|
238
|
-
parents: artifact.dimension === "monthly" ? [] : artifact.source.rawIds,
|
|
239
|
-
snippet: sliceSnippet(artifact.text, needle),
|
|
240
|
-
});
|
|
241
|
-
}
|
|
228
|
+
collectSummaries(files.searchCandidateSummaries(dim, needle));
|
|
242
229
|
}
|
|
243
230
|
}
|
|
244
231
|
|
|
@@ -277,23 +264,22 @@ export function readWorkspaceHistory(
|
|
|
277
264
|
root: string,
|
|
278
265
|
id: string,
|
|
279
266
|
offset = 0,
|
|
280
|
-
limit =
|
|
267
|
+
limit: number = historyPageLimits.read.default,
|
|
281
268
|
childrenOffset = 0,
|
|
282
269
|
host?: HistoryHost,
|
|
283
270
|
): HistoryReadNode {
|
|
284
|
-
const
|
|
285
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", layout);
|
|
271
|
+
const files = workspaceHistoryFiles(root);
|
|
286
272
|
const baseWarnings: string[] = [];
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
if (flatNotice) baseWarnings.push(flatNotice);
|
|
290
|
-
}
|
|
273
|
+
const flatNotice = files.migrationNotice();
|
|
274
|
+
if (flatNotice) baseWarnings.push(flatNotice);
|
|
291
275
|
|
|
292
276
|
// 1. Summary artifact: summary:<dimension>:<artifactId>
|
|
293
277
|
const parsedSummary = parseSummaryNodeId(id);
|
|
294
278
|
if (parsedSummary) {
|
|
295
279
|
const artifact = files.readSummary(parsedSummary.dimension, parsedSummary.artifactId);
|
|
296
|
-
requireThat(artifact
|
|
280
|
+
requireThat(artifact, "历史节点不存在,请重新搜索。");
|
|
281
|
+
const brief = summaryBrief(artifact);
|
|
282
|
+
requireThat(!host || brief.host === host, "历史节点不存在,请重新搜索。");
|
|
297
283
|
const parents: HistoryNodeBrief[] = [];
|
|
298
284
|
const children: HistoryNodeBrief[] = [];
|
|
299
285
|
|
|
@@ -332,14 +318,14 @@ export function readWorkspaceHistory(
|
|
|
332
318
|
const pagedChildren = page(children, childrenOffset, 20);
|
|
333
319
|
const sliced = sliceText(artifact.text, offset, limit);
|
|
334
320
|
return {
|
|
335
|
-
...
|
|
321
|
+
...brief,
|
|
336
322
|
...sliced,
|
|
337
323
|
parents,
|
|
338
324
|
children: pagedChildren.values,
|
|
339
325
|
nextChildrenOffset: pagedChildren.nextOffset,
|
|
340
326
|
source: {
|
|
341
|
-
host:
|
|
342
|
-
sessionId:
|
|
327
|
+
host: brief.host,
|
|
328
|
+
sessionId: brief.sessionId,
|
|
343
329
|
entryIds: artifact.source.exchangeIds,
|
|
344
330
|
dimension: artifact.dimension,
|
|
345
331
|
},
|
|
@@ -11,17 +11,18 @@ export type ParsedHistoryCommand =
|
|
|
11
11
|
export const historyCommandUsage =
|
|
12
12
|
'用法:/pbot history summary [维度...] [--force] [--backend <acp>] [--model <model>] [--thinking <level>] | migrate [--dry-run] | status | list | {"action":"search"|"read",...}';
|
|
13
13
|
|
|
14
|
-
export function parseHistoryCommand(raw: string): ParsedHistoryCommand {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
export function parseHistoryCommand(raw: string | readonly string[]): ParsedHistoryCommand {
|
|
15
|
+
const tokens = typeof raw === "string"
|
|
16
|
+
? raw.trim().startsWith("{") ? [raw.trim()] : raw.trim().split(/\s+/).filter(Boolean)
|
|
17
|
+
: raw;
|
|
18
|
+
const [sub] = tokens;
|
|
19
|
+
if (!sub || sub === "status" && tokens.length === 1) return { kind: "status" };
|
|
20
|
+
if (sub === "list" && tokens.length === 1) return { kind: "list" };
|
|
21
|
+
if (tokens.length === 1 && sub.startsWith("{")) {
|
|
22
|
+
const parsed: unknown = JSON.parse(sub);
|
|
20
23
|
requireThat(object(parsed), "历史查询参数必须是 JSON 对象。");
|
|
21
24
|
return { kind: "query", input: parsed };
|
|
22
25
|
}
|
|
23
|
-
const tokens = trimmed.split(/\s+/);
|
|
24
|
-
const sub = tokens[0];
|
|
25
26
|
if (sub === "migrate") {
|
|
26
27
|
let dryRun = false;
|
|
27
28
|
for (const token of tokens.slice(1)) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { requireThat } from "../../common/validation.js";
|
|
1
|
+
import { isHistoryIdentifier, requireThat } from "../../common/validation.js";
|
|
2
2
|
import type { HistoryLayout, SummaryDimension } from "../../model/history.js";
|
|
3
|
-
import { isSummaryDimension } from "../../storage/history-format.js";
|
|
4
3
|
import { monthlySummaryDimension } from "./summary-dimensions/monthly.js";
|
|
5
4
|
import { sessionSummaryDimension } from "./summary-dimensions/session.js";
|
|
6
5
|
|
|
@@ -11,7 +10,7 @@ const registry = new Map<string, SummaryDimension>([
|
|
|
11
10
|
|
|
12
11
|
/** Register a custom summary dimension (e.g. daily, decisions, topics). */
|
|
13
12
|
export function registerSummaryDimension(dimension: SummaryDimension): void {
|
|
14
|
-
requireThat(
|
|
13
|
+
requireThat(isHistoryIdentifier(dimension.id), "摘要维度 ID 无效:" + dimension.id);
|
|
15
14
|
registry.set(dimension.id, dimension);
|
|
16
15
|
}
|
|
17
16
|
|
|
@@ -1,4 +1,4 @@
|
|
|
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
4
|
import type {
|
|
@@ -12,13 +12,12 @@ import type {
|
|
|
12
12
|
SummaryRunProgress,
|
|
13
13
|
SummaryRunReport,
|
|
14
14
|
} from "../../model/history.js";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
15
|
+
import { summaryConcurrency } from "../../model/workspace-config.js";
|
|
16
|
+
import type { HistoryFiles } from "../../storage/history-files.js";
|
|
17
|
+
import { workspaceHistoryFiles } from "./workspace-history.js";
|
|
17
18
|
import { rawSessionSpan } from "./history-index.js";
|
|
18
19
|
import { resolveSummaryDimensions } from "./summary-registry.js";
|
|
19
20
|
|
|
20
|
-
const defaultConcurrency = 3;
|
|
21
|
-
const maxConcurrency = 8;
|
|
22
21
|
const lockRetryAttempts = 5;
|
|
23
22
|
const lockRetryDelayMs = 40;
|
|
24
23
|
export const defaultSummaryReminderDays = 7;
|
|
@@ -51,11 +50,7 @@ export interface InspectSummaryOptions {
|
|
|
51
50
|
now?: Date;
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
export
|
|
55
|
-
dimensions?: readonly string[];
|
|
56
|
-
thresholdDays?: number;
|
|
57
|
-
now?: Date;
|
|
58
|
-
}
|
|
53
|
+
export type CheckSummaryReminderOptions = InspectSummaryOptions;
|
|
59
54
|
|
|
60
55
|
function oldestRawTimestamp(raws: readonly RawHistory[]): number | undefined {
|
|
61
56
|
let oldest: number | undefined;
|
|
@@ -100,8 +95,8 @@ function evaluateSummaryReminder(
|
|
|
100
95
|
const rawAgeDays = Math.floor((nowMs - oldestRawMs) / dayMs);
|
|
101
96
|
const daysSinceLastSummary = latestSummaryMs === undefined ? undefined : Math.floor((nowMs - latestSummaryMs) / dayMs);
|
|
102
97
|
const message = daysSinceLastSummary === undefined
|
|
103
|
-
? `历史原文已累计 ${rawAgeDays} 天(待摘要 ${pendingCount}
|
|
104
|
-
: `历史原文已累计 ${rawAgeDays} 天,且已 ${daysSinceLastSummary} 天未触发摘要整理(待摘要 ${pendingCount}
|
|
98
|
+
? `历史原文已累计 ${rawAgeDays} 天(待摘要 ${pendingCount} 项),尚未触发过摘要整理;可在终端运行 pbot history summary 生成摘要(Pi/dsh 可用 /pbot history summary)。`
|
|
99
|
+
: `历史原文已累计 ${rawAgeDays} 天,且已 ${daysSinceLastSummary} 天未触发摘要整理(待摘要 ${pendingCount} 项);可在终端运行 pbot history summary 更新摘要(Pi/dsh 可用 /pbot history summary)。`;
|
|
105
100
|
|
|
106
101
|
return {
|
|
107
102
|
rawCount: raws.length,
|
|
@@ -120,8 +115,22 @@ export function checkHistorySummaryReminder(
|
|
|
120
115
|
root: string,
|
|
121
116
|
options: CheckSummaryReminderOptions = {},
|
|
122
117
|
): HistorySummaryReminder | undefined {
|
|
123
|
-
|
|
124
|
-
|
|
118
|
+
return summaryReminder(workspaceHistoryFiles(root), options);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function historyStartupNotices(root: string): string[] {
|
|
122
|
+
const notices: string[] = [];
|
|
123
|
+
try {
|
|
124
|
+
const files = workspaceHistoryFiles(root);
|
|
125
|
+
const migration = files.migrationNotice();
|
|
126
|
+
if (migration) notices.push(migration);
|
|
127
|
+
const reminder = summaryReminder(files, {});
|
|
128
|
+
if (reminder) notices.push(reminder.message);
|
|
129
|
+
} catch { /* History diagnostics are best effort during host startup. */ }
|
|
130
|
+
return notices;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function summaryReminder(files: HistoryFiles, options: CheckSummaryReminderOptions) {
|
|
125
134
|
const raws = files.listRaw();
|
|
126
135
|
if (!raws.length) return undefined;
|
|
127
136
|
|
|
@@ -131,52 +140,12 @@ export function checkHistorySummaryReminder(
|
|
|
131
140
|
const oldestRawMs = oldestRawTimestamp(raws);
|
|
132
141
|
if (oldestRawMs === undefined || nowMs - oldestRawMs < thresholdDays * dayMs) return undefined;
|
|
133
142
|
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
const summariesByDimension = new Map<string, Map<string, SummaryArtifact>>();
|
|
137
|
-
const allSummaries: SummaryArtifact[] = [];
|
|
138
|
-
let pendingCount = 0;
|
|
139
|
-
|
|
140
|
-
const loadDimension = (dimId: string) => {
|
|
141
|
-
const cached = summariesByDimension.get(dimId);
|
|
142
|
-
if (cached) return cached;
|
|
143
|
-
const list = files.listSummaries(dimId);
|
|
144
|
-
const map = new Map(list.map(item => [item.id, item]));
|
|
145
|
-
summariesByDimension.set(dimId, map);
|
|
146
|
-
return map;
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
for (const dimension of dimensions) {
|
|
150
|
-
seenDimensions.add(dimension.id);
|
|
151
|
-
if (dimension.id !== "session") loadDimension("session");
|
|
152
|
-
const existing = loadDimension(dimension.id);
|
|
153
|
-
allSummaries.push(...existing.values());
|
|
154
|
-
const plan = dimension.plan(raws, existing, { force: false, summariesByDimension });
|
|
155
|
-
pendingCount += plan.tasks.length;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
for (const dim of files.listDimensions()) {
|
|
159
|
-
if (seenDimensions.has(dim)) continue;
|
|
160
|
-
allSummaries.push(...loadDimension(dim).values());
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return evaluateSummaryReminder(raws, allSummaries, pendingCount, options);
|
|
143
|
+
const { totalPending, allSummaries } = inspectDimensions(files, raws, options, []);
|
|
144
|
+
return evaluateSummaryReminder(raws, allSummaries, totalPending, options);
|
|
164
145
|
}
|
|
165
146
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
root: string,
|
|
169
|
-
options: InspectSummaryOptions = {},
|
|
170
|
-
): { layout: HistoryLayout; rawCount: number; dimensions: SummaryDimensionStatus[]; warnings: string[]; reminder?: HistorySummaryReminder } {
|
|
171
|
-
const layout = readWorkspaceHistoryLayoutSync(root);
|
|
172
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", layout);
|
|
173
|
-
const raws = files.listRaw();
|
|
174
|
-
const warnings = [...files.warnings];
|
|
175
|
-
if (layout === "monthly") {
|
|
176
|
-
const flatNotice = files.detectFlatFiles().message;
|
|
177
|
-
if (flatNotice) warnings.push(flatNotice);
|
|
178
|
-
}
|
|
179
|
-
const dimensions = resolveSummaryDimensions(options.dimensions, layout);
|
|
147
|
+
function inspectDimensions(files: HistoryFiles, raws: RawHistory[], options: InspectSummaryOptions, warnings: string[]) {
|
|
148
|
+
const dimensions = resolveSummaryDimensions(options.dimensions, files.layout);
|
|
180
149
|
|
|
181
150
|
const statuses: SummaryDimensionStatus[] = [];
|
|
182
151
|
const seenDimensions = new Set<string>();
|
|
@@ -227,9 +196,23 @@ export function inspectWorkspaceSummaries(
|
|
|
227
196
|
allSummaries.push(...loadDimension(dim).values());
|
|
228
197
|
}
|
|
229
198
|
|
|
199
|
+
return { statuses, totalPending, allSummaries };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Read-only inspection of raw archives vs derived summaries across requested dimensions. */
|
|
203
|
+
export function inspectWorkspaceSummaries(
|
|
204
|
+
root: string,
|
|
205
|
+
options: InspectSummaryOptions = {},
|
|
206
|
+
): { layout: HistoryLayout; rawCount: number; dimensions: SummaryDimensionStatus[]; warnings: string[]; reminder?: HistorySummaryReminder } {
|
|
207
|
+
const files = workspaceHistoryFiles(root);
|
|
208
|
+
const raws = files.listRaw();
|
|
209
|
+
const warnings = [...files.warnings];
|
|
210
|
+
const flatNotice = files.migrationNotice();
|
|
211
|
+
if (flatNotice) warnings.push(flatNotice);
|
|
212
|
+
const { statuses, totalPending, allSummaries } = inspectDimensions(files, raws, options, warnings);
|
|
230
213
|
const reminder = evaluateSummaryReminder(raws, allSummaries, totalPending, options);
|
|
231
214
|
return {
|
|
232
|
-
layout,
|
|
215
|
+
layout: files.layout,
|
|
233
216
|
rawCount: raws.length,
|
|
234
217
|
dimensions: statuses,
|
|
235
218
|
warnings: [...new Set(warnings)],
|
|
@@ -257,30 +240,28 @@ export async function runWorkspaceSummaries(options: RunSummaryOptions): Promise
|
|
|
257
240
|
const signal = options.signal ?? new AbortController().signal;
|
|
258
241
|
signal.throwIfAborted();
|
|
259
242
|
|
|
260
|
-
const concurrency = Math.max(1, Math.min(
|
|
261
|
-
const
|
|
262
|
-
const dimensions = resolveSummaryDimensions(options.dimensions, layout);
|
|
263
|
-
const files = new HistoryFiles(join(options.root, ".pbot/history"), "pi", layout);
|
|
243
|
+
const concurrency = Math.max(1, Math.min(summaryConcurrency.max, Math.floor(options.concurrency ?? summaryConcurrency.default)));
|
|
244
|
+
const files = workspaceHistoryFiles(options.root);
|
|
245
|
+
const dimensions = resolveSummaryDimensions(options.dimensions, files.layout);
|
|
264
246
|
|
|
247
|
+
const warnings: string[] = [];
|
|
248
|
+
const loadSummaries = (id: string) => {
|
|
249
|
+
const items = files.listSummaries(id);
|
|
250
|
+
warnings.push(...files.warnings);
|
|
251
|
+
return new Map(items.map(item => [item.id, item]));
|
|
252
|
+
};
|
|
253
|
+
// Capture each publication baseline before reading the input it will summarize.
|
|
254
|
+
const plannedDimensions = dimensions.map(dimension => ({ dimension, existing: loadSummaries(dimension.id) }));
|
|
265
255
|
const raws = files.listRaw();
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if (flatNotice) warnings.push(flatNotice);
|
|
270
|
-
}
|
|
256
|
+
warnings.push(...files.warnings);
|
|
257
|
+
const flatNotice = files.migrationNotice();
|
|
258
|
+
if (flatNotice) warnings.push(flatNotice);
|
|
271
259
|
const summariesByDimension = new Map<string, Map<string, SummaryArtifact>>();
|
|
272
260
|
const reports: SummaryDimensionReport[] = [];
|
|
273
261
|
|
|
274
|
-
for (const dimension of
|
|
262
|
+
for (const { dimension, existing } of plannedDimensions) {
|
|
275
263
|
signal.throwIfAborted();
|
|
276
|
-
if (dimension.id !== "session"
|
|
277
|
-
const sessionList = files.listSummaries("session");
|
|
278
|
-
warnings.push(...files.warnings);
|
|
279
|
-
summariesByDimension.set("session", new Map(sessionList.map(item => [item.id, item])));
|
|
280
|
-
}
|
|
281
|
-
const existingList = files.listSummaries(dimension.id);
|
|
282
|
-
warnings.push(...files.warnings);
|
|
283
|
-
const existing = new Map(existingList.map(item => [item.id, item]));
|
|
264
|
+
if (dimension.id !== "session") summariesByDimension.set("session", loadSummaries("session"));
|
|
284
265
|
summariesByDimension.set(dimension.id, existing);
|
|
285
266
|
const plan = dimension.plan(raws, existing, { force: Boolean(options.force), summariesByDimension });
|
|
286
267
|
|
|
@@ -310,12 +291,22 @@ export async function runWorkspaceSummaries(options: RunSummaryOptions): Promise
|
|
|
310
291
|
const output = await options.summarizer(request, signal);
|
|
311
292
|
signal.throwIfAborted();
|
|
312
293
|
const artifact = dimension.finalize(task, output, new Date().toISOString());
|
|
313
|
-
await withSummaryLockRetry(files, dimension.id, () => {
|
|
294
|
+
const published = await withSummaryLockRetry(files, dimension.id, () => {
|
|
314
295
|
signal.throwIfAborted();
|
|
315
|
-
files.
|
|
296
|
+
const current = files.readSummary(dimension.id, artifact.id);
|
|
297
|
+
if (isDeepStrictEqual(current, existing.get(artifact.id))) {
|
|
298
|
+
files.saveSummary(artifact);
|
|
299
|
+
return artifact;
|
|
300
|
+
}
|
|
301
|
+
if (current) existing.set(artifact.id, current);
|
|
302
|
+
else existing.delete(artifact.id);
|
|
303
|
+
requireThat(current && isDeepStrictEqual(current.source, artifact.source),
|
|
304
|
+
"摘要在生成期间已变更,请重新运行摘要。");
|
|
305
|
+
return current;
|
|
316
306
|
}, signal);
|
|
317
|
-
existing.set(artifact.id,
|
|
318
|
-
if (
|
|
307
|
+
existing.set(artifact.id, published);
|
|
308
|
+
if (published !== artifact) report.skipped++;
|
|
309
|
+
else if (task.mode === "create") report.created++;
|
|
319
310
|
else if (task.mode === "incremental") report.incremental++;
|
|
320
311
|
else report.rebuilt++;
|
|
321
312
|
} catch (error) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import type { HistoryHost } from "../../model/history.js";
|
|
3
|
+
import { HistoryFiles } from "../../storage/history-files.js";
|
|
4
|
+
import { readWorkspaceHistoryLayoutSync } from "../workspace/workspace-config.js";
|
|
5
|
+
|
|
6
|
+
export function workspaceHistoryFiles(root: string, host?: HistoryHost): HistoryFiles {
|
|
7
|
+
return new HistoryFiles(join(root, ".pbot/history"), host, readWorkspaceHistoryLayoutSync(root));
|
|
8
|
+
}
|
|
@@ -1,46 +1,7 @@
|
|
|
1
1
|
import { npmName, ordinaryNpm } from "../../common/package-source.js";
|
|
2
|
+
import type { InstalledPackage, PackageChoice, PiInstallation, PluginSpec, SetupOperations, SetupPlan, SetupResult } from "../../model/installation.js";
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
-
id: string;
|
|
5
|
-
label: string;
|
|
6
|
-
description: string;
|
|
7
|
-
source: string;
|
|
8
|
-
defaultSelected: boolean;
|
|
9
|
-
}
|
|
10
|
-
export interface InstalledPackage {
|
|
11
|
-
source: string;
|
|
12
|
-
scope: "user" | "project";
|
|
13
|
-
name?: string;
|
|
14
|
-
version?: string;
|
|
15
|
-
installedPath?: string;
|
|
16
|
-
filtered: boolean;
|
|
17
|
-
entry: unknown;
|
|
18
|
-
}
|
|
19
|
-
export interface PackageChoice {
|
|
20
|
-
plugin: PluginSpec;
|
|
21
|
-
required: boolean;
|
|
22
|
-
existing: InstalledPackage[];
|
|
23
|
-
selected: boolean;
|
|
24
|
-
keep: boolean;
|
|
25
|
-
target?: string;
|
|
26
|
-
error?: string;
|
|
27
|
-
}
|
|
28
|
-
export interface PiInstallation { command: string; root: string; version: string }
|
|
29
|
-
export interface SystemCommand { command: string; args: string[] }
|
|
30
|
-
export interface SetupPlan {
|
|
31
|
-
workspace: string;
|
|
32
|
-
pi?: PiInstallation;
|
|
33
|
-
piVersion: string;
|
|
34
|
-
tmux?: SystemCommand;
|
|
35
|
-
packages: PackageChoice[];
|
|
36
|
-
}
|
|
37
|
-
export interface SetupResult { name: string; state: "done" | "kept" | "skipped" | "failed"; detail: string }
|
|
38
|
-
export interface SetupOperations {
|
|
39
|
-
installTmux(command: SystemCommand): Promise<void>;
|
|
40
|
-
ensurePi(existing: PiInstallation | undefined, version: string): Promise<PiInstallation>;
|
|
41
|
-
installPackage(pi: PiInstallation, workspace: string, choice: PackageChoice): Promise<string>;
|
|
42
|
-
verifyKeptPackage(pi: PiInstallation, workspace: string, choice: PackageChoice): Promise<string>;
|
|
43
|
-
}
|
|
4
|
+
export type { InstalledPackage, PackageChoice, PiInstallation, PluginSpec, SetupOperations, SetupPlan, SetupResult, SystemCommand } from "../../model/installation.js";
|
|
44
5
|
|
|
45
6
|
export const pbotPackage: PluginSpec = {
|
|
46
7
|
id: "pbot", label: "Personal Bot", description: "工作区个人助手", source: "npm:personal-bot", defaultSelected: true,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdirSync, readdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
5
|
+
import { object } from "../../common/json.js";
|
|
6
|
+
import { resourceRoot } from "../../common/paths.js";
|
|
7
|
+
import { requireThat } from "../../common/validation.js";
|
|
8
|
+
import { releaseLine } from "../../common/version.js";
|
|
9
|
+
import { readJsonFile, writeJsonFile } from "../../storage/atomic-json.js";
|
|
10
|
+
|
|
11
|
+
function bindingDirectory(root: string) {
|
|
12
|
+
const key = createHash("sha256").update(root).digest("hex");
|
|
13
|
+
return join(homedir(), ".pbot", "workspaces", key);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Full plugins own a local manifest. Thin clients can supply the release stamped into their cached hooks.
|
|
17
|
+
function pluginBinding(value: unknown): string {
|
|
18
|
+
requireThat(typeof value === "string", "无效的插件安装记录。");
|
|
19
|
+
if (!isAbsolute(value)) releaseLine(value);
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function permissionDenied(error: unknown): boolean {
|
|
24
|
+
return ["EACCES", "EPERM", "EROFS"].includes((error as NodeJS.ErrnoException).code ?? "");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Each host owns its file, including when two hosts activate the same canonical workspace concurrently. */
|
|
28
|
+
export function bindWorkspacePlugin(root: string, host: string, binding = resolve(resourceRoot, "../package.json")): void {
|
|
29
|
+
const directory = bindingDirectory(root);
|
|
30
|
+
const file = encodeURIComponent(host) + ".json";
|
|
31
|
+
try {
|
|
32
|
+
if (readJsonFile(directory, file, pluginBinding) === binding) return;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (permissionDenied(error)) return;
|
|
35
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
39
|
+
writeJsonFile(directory, file, binding, pluginBinding);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if (!permissionDenied(error)) throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function workspacePluginReleases(root: string): Record<string, string> {
|
|
46
|
+
const directory = bindingDirectory(root);
|
|
47
|
+
let files: string[];
|
|
48
|
+
try { files = readdirSync(directory); }
|
|
49
|
+
catch (error) {
|
|
50
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT" || permissionDenied(error)) return {};
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
const releases: Record<string, string> = Object.create(null);
|
|
54
|
+
for (const file of files.filter(name => name.endsWith(".json"))) {
|
|
55
|
+
const host = decodeURIComponent(file.slice(0, -5));
|
|
56
|
+
try {
|
|
57
|
+
const binding = readJsonFile(directory, file, pluginBinding);
|
|
58
|
+
if (!isAbsolute(binding)) { releases[host] = binding; continue; }
|
|
59
|
+
const manifest: unknown = JSON.parse(readFileSync(binding, "utf8"));
|
|
60
|
+
requireThat(object(manifest) && typeof manifest.version === "string", "无效的插件安装清单:" + binding);
|
|
61
|
+
releaseLine(manifest.version);
|
|
62
|
+
releases[host] = manifest.version;
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT" && !permissionDenied(error)) throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return releases;
|
|
68
|
+
}
|
|
@@ -2,7 +2,9 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
import { mkdir, readFile } from "node:fs/promises";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { object } from "../../common/json.js";
|
|
5
|
-
import {
|
|
5
|
+
import { acpPermissionPolicies } from "../../model/acp.js";
|
|
6
|
+
import { historyLayouts, summaryConcurrency } from "../../model/workspace-config.js";
|
|
7
|
+
import { isAcpBackend, isOneOf } from "../../common/validation.js";
|
|
6
8
|
import { readJsonFile, writeJsonFile } from "../../storage/atomic-json.js";
|
|
7
9
|
import type {
|
|
8
10
|
HistoryLayout,
|
|
@@ -19,7 +21,6 @@ import type {
|
|
|
19
21
|
const featureKeys = ["prompts", "skills", "mcp", "history"] as const;
|
|
20
22
|
const summaryKeys = ["backend", "model", "thinking", "concurrency"] as const;
|
|
21
23
|
const historyKeys = ["layout"] as const;
|
|
22
|
-
const historyLayouts = ["monthly", "flat"] as const;
|
|
23
24
|
|
|
24
25
|
function nonEmptyString(value: unknown): value is string {
|
|
25
26
|
return typeof value === "string" && value.trim().length > 0 && !value.includes("\0");
|
|
@@ -47,7 +48,7 @@ function config(value: unknown): Record<string, unknown> {
|
|
|
47
48
|
(command.args === undefined || (Array.isArray(command.args) && command.args.every(arg => typeof arg === "string" && !arg.includes("\0"))));
|
|
48
49
|
if (!object(command) || !launch ||
|
|
49
50
|
(command.env !== undefined && (!object(command.env) || Object.entries(command.env).some(([k, v]) => !k || k.includes("\0") || typeof v !== "string" || v.includes("\0")))) ||
|
|
50
|
-
(command.permission !== undefined && !
|
|
51
|
+
(command.permission !== undefined && !isOneOf(command.permission, acpPermissionPolicies)) ||
|
|
51
52
|
Object.keys(command).some(key => !["command", "args", "env", "permission"].includes(key))) {
|
|
52
53
|
throw new Error("ACP 配置需要 command(内置目标可省略)及可选 args 字符串数组、env 字符串映射、permission(ask、allow 或 deny)。");
|
|
53
54
|
}
|
|
@@ -67,15 +68,15 @@ function config(value: unknown): Record<string, unknown> {
|
|
|
67
68
|
throw new Error("summary.thinking 必须是非空字符串。");
|
|
68
69
|
}
|
|
69
70
|
if (value.summary.concurrency !== undefined &&
|
|
70
|
-
(typeof value.summary.concurrency !== "number" || !Number.isInteger(value.summary.concurrency) || value.summary.concurrency < 1 || value.summary.concurrency >
|
|
71
|
-
throw new Error(
|
|
71
|
+
(typeof value.summary.concurrency !== "number" || !Number.isInteger(value.summary.concurrency) || value.summary.concurrency < 1 || value.summary.concurrency > summaryConcurrency.max)) {
|
|
72
|
+
throw new Error(`summary.concurrency 必须是 1 到 ${summaryConcurrency.max} 之间的整数。`);
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
if (value.history !== undefined) {
|
|
75
76
|
if (!object(value.history) || Object.keys(value.history).some(key => !(historyKeys as readonly string[]).includes(key))) {
|
|
76
77
|
throw new Error("history 必须是 JSON 对象,仅支持 layout。");
|
|
77
78
|
}
|
|
78
|
-
if (value.history.layout !== undefined && !(
|
|
79
|
+
if (value.history.layout !== undefined && !isOneOf(value.history.layout, historyLayouts)) {
|
|
79
80
|
throw new Error('history.layout 必须是 "monthly" 或 "flat"。');
|
|
80
81
|
}
|
|
81
82
|
}
|
|
@@ -104,7 +105,7 @@ export function workspaceSummaryConfig(
|
|
|
104
105
|
backend: raw?.backend ?? "pi",
|
|
105
106
|
...(raw?.model ? { model: raw.model } : {}),
|
|
106
107
|
...(raw?.thinking ? { thinking: raw.thinking } : {}),
|
|
107
|
-
concurrency: raw?.concurrency ??
|
|
108
|
+
concurrency: raw?.concurrency ?? summaryConcurrency.default,
|
|
108
109
|
};
|
|
109
110
|
}
|
|
110
111
|
|
|
@@ -178,5 +179,5 @@ export async function initializeWorkspaceConfig(root: string): Promise<void> {
|
|
|
178
179
|
}
|
|
179
180
|
|
|
180
181
|
export function workspaceDisabledMessage(configuration: WorkspaceConfiguration): string {
|
|
181
|
-
return configuration.error ?? `Personal Bot
|
|
182
|
+
return configuration.error ?? `Personal Bot 未在此工作区启用。请在工作区根目录运行 pbot init,也可在 Pi 或 dsh 中执行 /pbot init。配置文件位于 ${configuration.path}`;
|
|
182
183
|
}
|