personal-bot 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +2 -1
- package/DISCLAIMER.md +17 -0
- package/LICENSE +21 -0
- package/README.md +15 -5
- package/README.zh-CN.md +15 -5
- package/bin/pbot-pi-acp.mjs +1 -1
- package/bin/pbot.mjs +22 -2
- package/docs/README.md +2 -0
- package/docs/architecture/design.md +16 -16
- package/docs/architecture/extensibility.md +29 -2
- package/docs/architecture/model-context.md +3 -2
- package/docs/architecture/principles.md +2 -2
- package/docs/guides/capabilities.md +1 -1
- package/docs/guides/cross-harness-workers.md +3 -1
- package/docs/guides/history.md +30 -7
- package/docs/guides/workspace-configuration.md +20 -3
- package/docs/hosts/antigravity.md +1 -1
- package/docs/hosts/claude-code.md +1 -1
- package/docs/hosts/codex-qoder.md +63 -0
- package/docs/maintainers/architecture-governance.md +78 -0
- package/lib/antigravity-plugin/DISCLAIMER.md +17 -0
- package/lib/antigravity-plugin/LICENSE +21 -0
- package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +36 -0
- package/lib/antigravity-plugin/lib/common/files.d.ts +2 -0
- package/lib/antigravity-plugin/lib/common/files.js +44 -0
- package/lib/antigravity-plugin/lib/common/validation.d.ts +4 -0
- package/lib/antigravity-plugin/lib/common/validation.js +8 -0
- package/lib/antigravity-plugin/lib/extension/acp/member.d.ts +18 -0
- package/lib/antigravity-plugin/lib/extension/acp/member.js +44 -0
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +71 -45
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.js +22 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.d.ts +4 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.js +58 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.d.ts +5 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.js +67 -0
- package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.d.ts +3 -0
- package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +100 -0
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.d.ts +3 -1
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +37 -22
- package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.d.ts +6 -0
- package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.js +21 -0
- package/lib/antigravity-plugin/lib/extension/mcp.js +2577 -2255
- package/lib/antigravity-plugin/lib/extension/workspace-cli.js +20171 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +7 -59
- package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.d.ts +2 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.js +14 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.js +28 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.d.ts +36 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.js +11 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.d.ts +6 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.js +47 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.js +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.d.ts +8 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.js +31 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.js +32 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.js +23 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.d.ts +1 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.js +8 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.js +76 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.js +16 -0
- package/lib/antigravity-plugin/lib/model/acp.d.ts +7 -3
- package/lib/antigravity-plugin/lib/model/acp.js +8 -0
- package/lib/antigravity-plugin/lib/model/agent.d.ts +121 -0
- package/lib/antigravity-plugin/lib/model/agent.js +4 -0
- package/lib/antigravity-plugin/lib/model/history.d.ts +10 -0
- package/lib/antigravity-plugin/lib/model/history.js +4 -1
- package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +5 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +8 -12
- package/lib/antigravity-plugin/lib/model/workspace-config.js +2 -1
- package/lib/antigravity-plugin/lib/plugin.d.ts +2 -1
- package/lib/antigravity-plugin/lib/plugin.js +2 -2
- package/lib/antigravity-plugin/lib/services/history/history-capture.js +34 -22
- package/lib/antigravity-plugin/lib/services/history/summary-registry.js +2 -3
- package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +2 -5
- package/lib/antigravity-plugin/lib/services/history/summary-runner.js +72 -74
- package/lib/antigravity-plugin/lib/services/history/workspace-history.d.ts +3 -0
- package/lib/antigravity-plugin/lib/services/history/workspace-history.js +6 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +15 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +126 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +9 -8
- package/lib/antigravity-plugin/lib/services/workspace/workspace-files.d.ts +2 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-files.js +17 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.d.ts +14 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.js +193 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.d.ts +1 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.js +4 -2
- package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +11 -0
- package/lib/antigravity-plugin/lib/storage/acp-files.js +75 -0
- package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +31 -0
- package/lib/antigravity-plugin/lib/storage/agent-files.js +159 -0
- package/lib/antigravity-plugin/lib/storage/atomic-json.d.ts +3 -1
- package/lib/antigravity-plugin/lib/storage/atomic-json.js +43 -3
- package/lib/antigravity-plugin/lib/storage/history-files.d.ts +2 -1
- package/lib/antigravity-plugin/lib/storage/history-files.js +21 -15
- package/lib/antigravity-plugin/lib/storage/history-format.d.ts +2 -3
- package/lib/antigravity-plugin/lib/storage/history-format.js +5 -7
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +1 -1
- package/lib/antigravity-plugin/resources/prompts/history-monthly-summary.md +13 -0
- package/lib/antigravity-plugin/resources/prompts/history-summary.md +13 -0
- package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -0
- package/lib/antigravity-plugin/resources/skills/.claude-plugin/plugin.json +4 -0
- package/lib/antigravity-plugin/resources/skills/project-maintenance/SKILL.md +35 -0
- package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +52 -0
- package/lib/antigravity-plugin/skills/pbot/SKILL.md +11 -1
- package/lib/client.js +22 -50
- package/lib/codex-marketplace/.agents/plugins/marketplace.json +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +7 -0
- package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/DISCLAIMER.md +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/LICENSE +21 -0
- package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +37 -0
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +9 -0
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/agents/openai.yaml +2 -0
- package/lib/common/validation.d.ts +4 -0
- package/lib/common/validation.js +8 -0
- package/lib/dsh.js +2 -2
- package/lib/extension/acp/member.d.ts +1 -1
- package/lib/extension/acp-worker.js +71 -45
- package/lib/extension/history/command.d.ts +37 -0
- package/lib/extension/history/command.js +57 -0
- package/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
- package/lib/extension/hosts/dsh/acp-entry.js +22 -0
- package/lib/extension/hosts/dsh/acp-member.js +4 -18
- package/lib/extension/hosts/dsh/command.d.ts +1 -2
- package/lib/extension/hosts/dsh/command.js +5 -49
- package/lib/extension/hosts/dsh/workspace.js +13 -44
- package/lib/extension/hosts/pi/acp-member.d.ts +3 -0
- package/lib/extension/hosts/pi/acp-member.js +100 -0
- package/lib/extension/hosts/plugin-runtime.d.ts +3 -1
- package/lib/extension/hosts/plugin-runtime.js +37 -22
- package/lib/extension/hosts/workspace-mcp.d.ts +6 -0
- package/lib/extension/hosts/workspace-mcp.js +21 -0
- package/lib/extension/mcp/bridge.d.ts +6 -8
- package/lib/extension/mcp/bridge.js +66 -84
- package/lib/extension/mcp/tool-contract.d.ts +735 -0
- package/lib/extension/mcp/tool-contract.js +441 -0
- package/lib/extension/mcp/workers.d.ts +29 -742
- package/lib/extension/mcp/workers.js +75 -525
- package/lib/extension/mcp.js +2577 -2255
- package/lib/extension/setup/cli.js +15 -0
- package/lib/extension/setup/upgrade.js +153 -0
- package/lib/extension/workspace-cli.js +20171 -0
- package/lib/integrations/acp/agents.d.ts +2 -3
- package/lib/integrations/acp/harnesses/dsh.js +1 -1
- package/lib/integrations/acp/harnesses/presets.js +8 -0
- package/lib/integrations/acp/history-summary.js +2 -1
- package/lib/integrations/acp/launch.d.ts +2 -2
- package/lib/integrations/agent-resources.js +1 -1
- package/lib/integrations/hosts/claude/adapter.js +7 -59
- package/lib/integrations/hosts/codex/adapter.d.ts +2 -0
- package/lib/integrations/hosts/codex/adapter.js +14 -0
- package/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
- package/lib/integrations/hosts/pi/agent-tools.js +32 -0
- package/lib/integrations/hosts/pi/mcp.d.ts +4 -0
- package/lib/integrations/hosts/pi/mcp.js +23 -0
- package/lib/integrations/hosts/plugin-registry.d.ts +1 -0
- package/lib/integrations/hosts/plugin-registry.js +8 -1
- package/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
- package/lib/integrations/hosts/prompt-hooks.js +76 -0
- package/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
- package/lib/integrations/hosts/qoder/adapter.js +16 -0
- package/lib/integrations/installation/cli-update.js +146 -0
- package/lib/integrations/installation/upgraders/antigravity.js +67 -0
- package/lib/integrations/installation/upgraders/claude.js +123 -0
- package/lib/integrations/installation/upgraders/codex.js +73 -0
- package/lib/integrations/installation/upgraders/dsh.js +62 -0
- package/lib/integrations/installation/upgraders/pi.js +90 -0
- package/lib/integrations/installation/upgraders/qoder.js +67 -0
- package/lib/integrations/installation/upgraders/registry.js +40 -0
- package/lib/model/acp.d.ts +7 -3
- package/lib/model/acp.js +8 -0
- package/lib/model/agent.d.ts +18 -4
- package/lib/model/agent.js +4 -1
- package/lib/model/history.d.ts +10 -0
- package/lib/model/history.js +4 -1
- package/lib/model/installation.js +1 -0
- package/lib/model/plugin-host.d.ts +5 -0
- package/lib/model/workspace-config.d.ts +8 -12
- package/lib/model/workspace-config.js +2 -1
- package/lib/plugin.d.ts +2 -1
- package/lib/plugin.js +2 -2
- package/lib/qoder-plugin/.mcp.json +17 -0
- package/lib/qoder-plugin/.qoder-plugin/plugin.json +7 -0
- package/lib/qoder-plugin/DISCLAIMER.md +17 -0
- package/lib/qoder-plugin/LICENSE +21 -0
- package/lib/qoder-plugin/hooks/hooks.json +37 -0
- package/lib/qoder-plugin/skills/pbot/SKILL.md +9 -0
- package/lib/services/agents/agent-service.d.ts +15 -45
- package/lib/services/agents/agent-service.js +22 -3
- package/lib/services/history/history-capture.js +34 -22
- package/lib/services/history/history-migrate.js +26 -60
- package/lib/services/history/history-query.js +38 -57
- package/lib/services/history/summary-command.d.ts +1 -1
- package/lib/services/history/summary-command.js +8 -7
- package/lib/services/history/summary-registry.js +2 -3
- package/lib/services/history/summary-runner.d.ts +2 -5
- package/lib/services/history/summary-runner.js +72 -74
- package/lib/services/history/workspace-history.d.ts +3 -0
- package/lib/services/history/workspace-history.js +6 -0
- package/lib/services/installation/setup-service.js +4 -1
- package/lib/services/installation/upgrade-service.js +95 -0
- package/lib/services/workspace/plugin-releases.d.ts +15 -0
- package/lib/services/workspace/plugin-releases.js +126 -0
- package/lib/services/workspace/workspace-config.js +9 -8
- package/lib/services/workspace/workspace-mcp.js +22 -29
- package/lib/services/workspace/workspace-skills.d.ts +1 -0
- package/lib/services/workspace/workspace-skills.js +4 -2
- package/lib/storage/acp-files.js +7 -12
- package/lib/storage/agent-files.js +6 -5
- package/lib/storage/atomic-json.d.ts +3 -1
- package/lib/storage/atomic-json.js +43 -3
- package/lib/storage/history-files.d.ts +2 -1
- package/lib/storage/history-files.js +21 -15
- package/lib/storage/history-format.d.ts +2 -3
- package/lib/storage/history-format.js +5 -7
- package/lib/tools/history/contract.d.ts +3 -11
- package/lib/tools/history/contract.js +8 -7
- package/lib/ui/dsh/elements.d.ts +2 -5
- package/lib/ui/dsh/elements.js +3 -16
- package/lib/ui/dsh/management.js +9 -9
- package/lib/ui/dsh/styles.d.ts +1 -1
- package/lib/ui/dsh/styles.js +5 -33
- package/package.json +4 -1
- package/resources/antigravity/skills/pbot/SKILL.md +11 -1
- package/resources/claude/skills/pbot/SKILL.md +11 -1
- package/resources/plugin/skills/pbot/SKILL.md +9 -0
- package/resources/prompts/history-coordinator.md +1 -0
- package/resources/prompts/plugin-coordinator.md +1 -0
- package/scripts/README.md +3 -2
- package/src/common/validation.ts +10 -0
- package/src/dsh.ts +2 -2
- package/src/extension/history/command.ts +68 -0
- package/src/extension/hosts/dsh/acp-entry.ts +21 -0
- package/src/extension/hosts/dsh/acp-member.ts +4 -15
- package/src/extension/hosts/dsh/command.ts +6 -46
- package/src/extension/hosts/dsh/workspace.ts +12 -38
- package/src/extension/hosts/pi/acp-member.ts +4 -10
- package/src/extension/hosts/pi/command.ts +14 -63
- package/src/extension/hosts/pi/events.ts +2 -8
- package/src/extension/hosts/pi/lifecycle.ts +3 -2
- package/src/extension/hosts/plugin-runtime.ts +39 -19
- package/src/extension/hosts/workspace-mcp.ts +25 -0
- package/src/extension/mcp/bridge.ts +80 -80
- package/src/extension/mcp/tool-contract.ts +462 -0
- package/src/extension/mcp/workers.ts +81 -551
- package/src/extension/setup/cli.ts +11 -1
- package/src/extension/setup/upgrade.ts +158 -0
- package/src/extension/setup/workspace-cli.ts +167 -0
- package/src/integrations/acp/agents.ts +2 -3
- package/src/integrations/acp/harnesses/dsh.ts +1 -1
- package/src/integrations/acp/harnesses/presets.ts +8 -0
- package/src/integrations/acp/history-summary.ts +2 -1
- package/src/integrations/agent-resources.ts +1 -1
- package/src/integrations/hosts/claude/adapter.ts +7 -53
- package/src/integrations/hosts/codex/adapter.ts +16 -0
- package/src/integrations/hosts/plugin-registry.ts +9 -1
- package/src/integrations/hosts/prompt-hooks.ts +72 -0
- package/src/integrations/hosts/qoder/adapter.ts +19 -0
- package/src/integrations/installation/cli-update.ts +144 -0
- package/src/integrations/installation/pi-bridge.ts +1 -1
- package/src/integrations/installation/pi-setup.ts +1 -1
- package/src/integrations/installation/processes.ts +1 -1
- package/src/integrations/installation/upgraders/antigravity.ts +68 -0
- package/src/integrations/installation/upgraders/claude.ts +123 -0
- package/src/integrations/installation/upgraders/codex.ts +73 -0
- package/src/integrations/installation/upgraders/dsh.ts +63 -0
- package/src/integrations/installation/upgraders/pi.ts +87 -0
- package/src/integrations/installation/upgraders/qoder.ts +68 -0
- package/src/integrations/installation/upgraders/registry.ts +48 -0
- package/src/model/acp.ts +11 -3
- package/src/model/agent.ts +20 -4
- package/src/model/history.ts +5 -0
- package/src/model/installation.ts +86 -0
- package/src/model/plugin-host.ts +5 -1
- package/src/model/workspace-config.ts +6 -12
- package/src/pbot.ts +13 -32
- package/src/plugin.ts +3 -3
- package/src/services/agents/agent-service.ts +29 -17
- package/src/services/history/history-capture.ts +30 -22
- package/src/services/history/history-migrate.ts +23 -50
- package/src/services/history/history-query.ts +34 -48
- package/src/services/history/summary-command.ts +9 -8
- package/src/services/history/summary-registry.ts +2 -3
- package/src/services/history/summary-runner.ts +72 -81
- package/src/services/history/workspace-history.ts +8 -0
- package/src/services/installation/setup-service.ts +9 -43
- package/src/services/installation/upgrade-service.ts +127 -0
- package/src/services/workspace/plugin-releases.ts +121 -0
- package/src/services/workspace/workspace-config.ts +9 -8
- package/src/services/workspace/workspace-mcp.ts +23 -28
- package/src/services/workspace/workspace-skills.ts +5 -2
- package/src/storage/acp-files.ts +7 -12
- package/src/storage/agent-files.ts +6 -5
- package/src/storage/atomic-json.ts +31 -4
- package/src/storage/history-files.ts +22 -15
- package/src/storage/history-format.ts +6 -8
- package/src/tools/history/contract.ts +9 -9
- package/src/tools/history/pi-tool.ts +6 -4
- package/src/ui/dsh/elements.ts +5 -12
- package/src/ui/dsh/management.ts +10 -10
- package/src/ui/dsh/styles.ts +5 -33
- package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +0 -12
- package/lib/antigravity-plugin/lib/services/history/history-migrate.js +0 -88
- package/lib/ui/presentation.d.ts +0 -3
- package/lib/ui/presentation.js +0 -12
- package/src/tools/access.ts +0 -7
- package/src/tools/register.ts +0 -21
- package/src/ui/presentation.ts +0 -12
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { lstatSync } from "node:fs";
|
|
2
1
|
import { join } from "node:path";
|
|
3
2
|
import { requireThat } from "../../common/validation.js";
|
|
4
3
|
import type { HistoryMigrationConflict, HistoryMigrationItem, HistoryMigrationReport } from "../../model/history.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { rawHistoryBucket, summaryArtifactBucket } from "../../storage/history-files.js";
|
|
5
|
+
import { workspaceHistoryFiles } from "./workspace-history.js";
|
|
7
6
|
|
|
8
7
|
export interface MigrateHistoryOptions {
|
|
9
8
|
dryRun?: boolean;
|
|
@@ -11,10 +10,7 @@ export interface MigrateHistoryOptions {
|
|
|
11
10
|
|
|
12
11
|
/** Read-only check for unmigrated flat history files when running under monthly layout. */
|
|
13
12
|
export function checkHistoryMigrationNotice(root: string): string | undefined {
|
|
14
|
-
|
|
15
|
-
if (layout !== "monthly") return undefined;
|
|
16
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", layout);
|
|
17
|
-
return files.detectFlatFiles().message;
|
|
13
|
+
return workspaceHistoryFiles(root).migrationNotice();
|
|
18
14
|
}
|
|
19
15
|
|
|
20
16
|
/**
|
|
@@ -23,62 +19,39 @@ export function checkHistoryMigrationNotice(root: string): string | undefined {
|
|
|
23
19
|
* and never modifies .pbot/config.json or overwrites existing destinations.
|
|
24
20
|
*/
|
|
25
21
|
export function migrateWorkspaceHistory(root: string, options: MigrateHistoryOptions = {}): HistoryMigrationReport {
|
|
26
|
-
const
|
|
22
|
+
const files = workspaceHistoryFiles(root);
|
|
23
|
+
const { layout } = files;
|
|
27
24
|
requireThat(
|
|
28
25
|
layout === "monthly",
|
|
29
26
|
'当前工作区配置为平铺布局(history.layout: "flat"),无需迁移到年月目录;如需迁移,请先在 .pbot/config.json 中将 history.layout 设为 "monthly" 或移除该配置项。',
|
|
30
27
|
);
|
|
31
28
|
const dryRun = Boolean(options.dryRun);
|
|
32
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", "monthly");
|
|
33
29
|
const moved: HistoryMigrationItem[] = [];
|
|
34
30
|
const skipped: HistoryMigrationConflict[] = [];
|
|
35
31
|
const errors: { path: string; error: string }[] = [];
|
|
36
32
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
const outcome = files.moveHistoryFile(from, to);
|
|
52
|
-
if (outcome === "moved") moved.push({ kind: "raw", id: raw.id, from, to });
|
|
53
|
-
else skipped.push({ kind: "raw", from, to, reason: "目标路径已存在同名文件。" });
|
|
54
|
-
}
|
|
55
|
-
} catch (error) {
|
|
56
|
-
errors.push({ path: join(files.directory, from), error: error instanceof Error ? error.message : String(error) });
|
|
33
|
+
function migrateFile(name: string, dimension?: string) {
|
|
34
|
+
const directory = dimension ? `summaries/${dimension}` : "raw";
|
|
35
|
+
const from = `${directory}/${name}`;
|
|
36
|
+
try {
|
|
37
|
+
const record = dimension ? files.readFlatSummaryFile(dimension, name) : files.readFlatRawFile(name);
|
|
38
|
+
const bucket = "dimension" in record ? summaryArtifactBucket(record) : rawHistoryBucket(record);
|
|
39
|
+
const to = `${directory}/${bucket}/${name}`;
|
|
40
|
+
const source = dimension ? { kind: "summary" as const, dimension } : { kind: "raw" as const };
|
|
41
|
+
if (files.moveHistoryFile(from, to, dryRun) === "conflict") {
|
|
42
|
+
skipped.push({ ...source, from, to, reason: "目标路径已存在同名文件。" });
|
|
43
|
+
} else {
|
|
44
|
+
moved.push({ ...source, id: record.id, from, to });
|
|
57
45
|
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
errors.push({ path: join(files.directory, from), error: error instanceof Error ? error.message : String(error) });
|
|
58
48
|
}
|
|
49
|
+
}
|
|
59
50
|
|
|
51
|
+
const run = () => {
|
|
52
|
+
for (const name of files.listFlatRawFiles()) migrateFile(name);
|
|
60
53
|
for (const dimension of files.listDimensions()) {
|
|
61
|
-
for (const name of files.listFlatSummaryFiles(dimension))
|
|
62
|
-
const from = `summaries/${dimension}/${name}`;
|
|
63
|
-
try {
|
|
64
|
-
const artifact = files.readFlatSummaryFile(dimension, name);
|
|
65
|
-
const bucket = summaryArtifactBucket(artifact);
|
|
66
|
-
const to = `summaries/${dimension}/${bucket}/${name}`;
|
|
67
|
-
if (dryRun) {
|
|
68
|
-
if (lstatSync(join(files.directory, to), { throwIfNoEntry: false })) {
|
|
69
|
-
skipped.push({ kind: "summary", dimension, from, to, reason: "目标路径已存在同名文件。" });
|
|
70
|
-
} else {
|
|
71
|
-
moved.push({ kind: "summary", dimension, id: artifact.id, from, to });
|
|
72
|
-
}
|
|
73
|
-
} else {
|
|
74
|
-
const outcome = files.moveHistoryFile(from, to);
|
|
75
|
-
if (outcome === "moved") moved.push({ kind: "summary", dimension, id: artifact.id, from, to });
|
|
76
|
-
else skipped.push({ kind: "summary", dimension, from, to, reason: "目标路径已存在同名文件。" });
|
|
77
|
-
}
|
|
78
|
-
} catch (error) {
|
|
79
|
-
errors.push({ path: join(files.directory, from), error: error instanceof Error ? error.message : String(error) });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
54
|
+
for (const name of files.listFlatSummaryFiles(dimension)) migrateFile(name, dimension);
|
|
82
55
|
}
|
|
83
56
|
};
|
|
84
57
|
|
|
@@ -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,
|
|
@@ -81,12 +42,17 @@ export function packageChoices(catalog: PluginSpec[], installed: InstalledPackag
|
|
|
81
42
|
});
|
|
82
43
|
}
|
|
83
44
|
export function parseSetupArgs(args: string[]): {
|
|
84
|
-
action: "help" | "version" | "setup" | "install-antigravity" | "mcp" | "mcp-manage";
|
|
45
|
+
action: "help" | "version" | "setup" | "upgrade" | "install-antigravity" | "mcp" | "mcp-manage";
|
|
85
46
|
workspace?: string;
|
|
86
47
|
mcpArgs?: string[];
|
|
48
|
+
upgradeArgs?: string[];
|
|
49
|
+
upgradeVerb?: "upgrade" | "update";
|
|
87
50
|
} {
|
|
88
51
|
if (!args.length || args.length === 1 && ["--help", "-h"].includes(args[0]!)) return { action: "help" };
|
|
89
52
|
if (args.length === 1 && ["--version", "-v"].includes(args[0]!)) return { action: "version" };
|
|
53
|
+
if (args[0] === "upgrade" || args[0] === "update") {
|
|
54
|
+
return { action: "upgrade", upgradeArgs: args.slice(1), upgradeVerb: args[0] };
|
|
55
|
+
}
|
|
90
56
|
if (args[0] === "install-antigravity") {
|
|
91
57
|
if (args.length === 1) return { action: "install-antigravity" };
|
|
92
58
|
if (args.length === 2 && ["--help", "-h"].includes(args[1]!)) return { action: "help" };
|
|
@@ -98,7 +64,7 @@ export function parseSetupArgs(args: string[]): {
|
|
|
98
64
|
if (["list", "add", "remove"].includes(args[1]!)) return { action: "mcp-manage", mcpArgs: args.slice(1) };
|
|
99
65
|
throw new Error("用法:pbot mcp [list|add|remove ...]");
|
|
100
66
|
}
|
|
101
|
-
if (args[0] !== "setup") throw new Error("用法:pbot setup [--workspace <目录>] | pbot install-antigravity | pbot mcp [list|add|remove ...]");
|
|
67
|
+
if (args[0] !== "setup") throw new Error("用法:pbot setup [--workspace <目录>] | pbot upgrade|update [--workspace <目录>] | pbot install-antigravity | pbot mcp [list|add|remove ...]");
|
|
102
68
|
let workspace: string | undefined;
|
|
103
69
|
for (let index = 1; index < args.length; index++) {
|
|
104
70
|
const arg = args[index]!;
|