personal-bot 0.3.0 → 0.3.2
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 +1 -1
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/bin/pbot-pi-acp.mjs +27 -11
- package/bin/pbot.mjs +1 -1
- package/docs/README.md +1 -1
- package/docs/architecture/design.md +23 -10
- package/docs/architecture/extensibility.md +20 -18
- package/docs/architecture/model-context.md +2 -2
- package/docs/architecture/principles.md +4 -3
- package/docs/guides/capabilities.md +3 -3
- package/docs/guides/history.md +50 -16
- package/docs/guides/workspace-configuration.md +31 -6
- package/docs/hosts/antigravity.md +2 -0
- package/docs/hosts/claude-code.md +1 -1
- package/docs/hosts/dsh.md +1 -1
- package/docs/hosts/pi.md +1 -1
- package/hooks/hooks.json +3 -0
- package/lib/antigravity-plugin/hooks.json +7 -0
- package/lib/antigravity-plugin/lib/claude.js +2 -2
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +156 -11
- package/lib/antigravity-plugin/lib/extension/{plugin-runtime.d.ts → hosts/plugin-runtime.d.ts} +2 -2
- package/lib/antigravity-plugin/lib/extension/{plugin-runtime.js → hosts/plugin-runtime.js} +34 -8
- package/lib/antigravity-plugin/lib/extension/mcp.js +1113 -78
- package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +1 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +5 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.js +171 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/{claude.js → claude/adapter.js} +32 -4
- package/lib/antigravity-plugin/lib/integrations/hosts/{registry.js → plugin-registry.js} +2 -2
- package/lib/antigravity-plugin/lib/model/history.d.ts +169 -0
- package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +26 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +25 -0
- package/lib/antigravity-plugin/lib/plugin.js +2 -2
- package/lib/antigravity-plugin/lib/services/history/history-capture.d.ts +4 -0
- package/lib/antigravity-plugin/lib/services/history/history-capture.js +86 -0
- package/lib/antigravity-plugin/lib/services/history/history-index.d.ts +17 -0
- package/lib/antigravity-plugin/lib/services/history/history-index.js +112 -0
- package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +12 -0
- package/lib/antigravity-plugin/lib/services/history/history-migrate.js +88 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.js +121 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.d.ts +7 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.js +124 -0
- package/lib/antigravity-plugin/lib/services/history/summary-registry.d.ts +7 -0
- package/lib/antigravity-plugin/lib/services/history/summary-registry.js +36 -0
- package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +37 -0
- package/lib/antigravity-plugin/lib/services/history/summary-runner.js +301 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +5 -1
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +75 -4
- package/lib/antigravity-plugin/lib/storage/file-access.d.ts +2 -0
- package/lib/antigravity-plugin/lib/storage/file-access.js +26 -0
- package/lib/antigravity-plugin/lib/storage/history-files.d.ts +54 -0
- package/lib/antigravity-plugin/lib/storage/history-files.js +467 -0
- package/lib/antigravity-plugin/lib/storage/history-format.d.ts +6 -0
- package/lib/antigravity-plugin/lib/storage/history-format.js +62 -0
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +1 -1
- package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +22 -12
- package/lib/claude.js +2 -2
- package/lib/client.js +21 -11
- package/lib/dsh.js +4 -4
- package/lib/extension/{acp-member.d.ts → acp/member.d.ts} +5 -5
- package/lib/extension/{acp-member.js → acp/member.js} +6 -6
- package/lib/extension/acp/worker.d.ts +1 -0
- package/lib/extension/acp/worker.js +384 -0
- package/lib/extension/acp-worker.js +156 -11
- package/lib/extension/{dsh → hosts/dsh}/acp-member.js +8 -8
- package/lib/extension/hosts/dsh/command.js +92 -0
- package/lib/extension/{dsh → hosts/dsh}/files.js +3 -3
- package/lib/extension/hosts/dsh/history.d.ts +4 -0
- package/lib/extension/hosts/dsh/history.js +62 -0
- package/lib/extension/{dsh → hosts/dsh}/management.d.ts +1 -1
- package/lib/extension/{dsh → hosts/dsh}/management.js +12 -10
- package/lib/extension/{dsh → hosts/dsh}/workspace.d.ts +3 -9
- package/lib/extension/{dsh → hosts/dsh}/workspace.js +32 -70
- package/lib/extension/{plugin-runtime.d.ts → hosts/plugin-runtime.d.ts} +2 -2
- package/lib/extension/{plugin-runtime.js → hosts/plugin-runtime.js} +34 -8
- package/lib/extension/{mcp-bridge.d.ts → mcp/bridge.d.ts} +1 -1
- package/lib/extension/{mcp-bridge.js → mcp/bridge.js} +4 -4
- package/lib/extension/{mcp-workers.d.ts → mcp/workers.d.ts} +222 -2
- package/lib/extension/{mcp-workers.js → mcp/workers.js} +229 -63
- package/lib/extension/mcp.js +1113 -78
- package/lib/extension/{setup-cli.js → setup/cli.js} +9 -9
- package/lib/integrations/acp/connection.d.ts +11 -10
- package/lib/integrations/acp/connection.js +6 -0
- package/lib/integrations/acp/harnesses/claude.js +1 -1
- package/lib/integrations/acp/harnesses/dsh.js +1 -1
- package/lib/integrations/acp/history-summary.d.ts +17 -0
- package/lib/integrations/acp/history-summary.js +100 -0
- package/lib/integrations/agent-resources.d.ts +1 -0
- package/lib/integrations/agent-resources.js +5 -1
- package/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
- package/lib/integrations/hosts/antigravity/adapter.js +171 -0
- package/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
- package/lib/integrations/hosts/{claude.js → claude/adapter.js} +32 -4
- package/lib/integrations/{dsh → hosts/dsh}/mcp.d.ts +1 -1
- package/lib/integrations/{dsh → hosts/dsh}/resources.d.ts +1 -1
- package/lib/integrations/{dsh → hosts/dsh}/resources.js +4 -4
- package/lib/integrations/{dsh → hosts/dsh}/schema.js +1 -1
- package/lib/integrations/{dsh → hosts/dsh}/skills.js +1 -1
- package/lib/integrations/hosts/{registry.js → plugin-registry.js} +2 -2
- package/lib/integrations/installation/pi-setup.js +1 -1
- package/lib/model/history.d.ts +133 -34
- package/lib/model/plugin-host.d.ts +26 -0
- package/lib/model/workspace-config.d.ts +25 -0
- package/lib/plugin.js +2 -2
- package/lib/services/agents/agent-run.d.ts +1 -1
- package/lib/services/history/history-capture.d.ts +4 -0
- package/lib/services/history/history-capture.js +86 -0
- package/lib/services/history/history-index.d.ts +16 -7
- package/lib/services/history/history-index.js +48 -70
- package/lib/services/history/history-migrate.d.ts +12 -0
- package/lib/services/history/history-migrate.js +88 -0
- package/lib/services/history/history-query.d.ts +51 -0
- package/lib/services/history/history-query.js +371 -0
- package/lib/services/history/summary-command.d.ts +20 -0
- package/lib/services/history/summary-command.js +68 -0
- package/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
- package/lib/services/history/summary-dimensions/monthly.js +121 -0
- package/lib/services/history/summary-dimensions/session.d.ts +7 -0
- package/lib/services/history/summary-dimensions/session.js +124 -0
- package/lib/services/history/summary-registry.d.ts +7 -0
- package/lib/services/history/summary-registry.js +36 -0
- package/lib/services/history/summary-runner.d.ts +37 -0
- package/lib/services/history/summary-runner.js +301 -0
- package/lib/services/workspace/workspace-config.d.ts +5 -1
- package/lib/services/workspace/workspace-config.js +75 -4
- package/lib/storage/history-files.d.ts +45 -9
- package/lib/storage/history-files.js +373 -247
- package/lib/storage/history-format.d.ts +3 -12
- package/lib/storage/history-format.js +26 -50
- package/lib/tools/history/actions.d.ts +3 -68
- package/lib/tools/history/actions.js +7 -5
- package/lib/tools/history/contract.d.ts +14 -7
- package/lib/tools/history/contract.js +58 -18
- package/lib/tools/history/dsh-tool.d.ts +1 -2
- package/lib/tools/history/dsh-tool.js +11 -5
- package/lib/ui/dsh/management.js +18 -5
- package/package.json +1 -1
- package/resources/prompts/history-coordinator.md +1 -1
- package/resources/prompts/history-monthly-summary.md +13 -0
- package/resources/prompts/history-summary.md +10 -4
- package/resources/skills/provider-connections/SKILL.md +22 -12
- package/src/claude.ts +2 -2
- package/src/dsh.ts +4 -4
- package/src/extension/{acp-member.ts → acp/member.ts} +7 -7
- package/src/extension/{acp-worker.ts → acp/worker.ts} +131 -17
- package/src/extension/{dsh → hosts/dsh}/acp-member.ts +9 -9
- package/src/extension/hosts/dsh/command.ts +92 -0
- package/src/extension/{dsh → hosts/dsh}/files.ts +3 -3
- package/src/extension/hosts/dsh/history.ts +67 -0
- package/src/extension/{dsh → hosts/dsh}/management.ts +11 -9
- package/src/extension/{dsh → hosts/dsh}/workspace.ts +31 -50
- package/src/extension/{pi-acp-member.ts → hosts/pi/acp-member.ts} +9 -9
- package/src/extension/hosts/pi/command.ts +158 -0
- package/src/extension/{events.ts → hosts/pi/events.ts} +14 -4
- package/src/extension/hosts/pi/history.ts +45 -0
- package/src/extension/{lifecycle.ts → hosts/pi/lifecycle.ts} +7 -11
- package/src/extension/{plugin-runtime.ts → hosts/plugin-runtime.ts} +29 -9
- package/src/extension/{mcp-bridge.ts → mcp/bridge.ts} +5 -5
- package/src/extension/{mcp-workers.ts → mcp/workers.ts} +237 -64
- package/src/extension/{setup-cli.ts → setup/cli.ts} +11 -11
- package/src/integrations/acp/connection.ts +6 -0
- package/src/integrations/acp/harnesses/claude.ts +1 -1
- package/src/integrations/acp/harnesses/dsh.ts +1 -1
- package/src/integrations/acp/history-summary.ts +108 -0
- package/src/integrations/agent-resources.ts +6 -0
- package/src/integrations/hosts/antigravity/adapter.ts +161 -0
- package/src/integrations/hosts/{claude.ts → claude/adapter.ts} +28 -5
- package/src/integrations/{dsh → hosts/dsh}/mcp.ts +1 -1
- package/src/integrations/{dsh → hosts/dsh}/resources.ts +5 -5
- package/src/integrations/{dsh → hosts/dsh}/schema.ts +1 -1
- package/src/integrations/{dsh → hosts/dsh}/session.ts +2 -2
- package/src/integrations/{dsh → hosts/dsh}/skills.ts +1 -1
- package/src/integrations/{pi → hosts/pi}/mcp.ts +1 -1
- package/src/integrations/{pi → hosts/pi}/skills.ts +1 -1
- package/src/integrations/hosts/{registry.ts → plugin-registry.ts} +2 -2
- package/src/integrations/installation/pi-setup.ts +1 -1
- package/src/mcp.ts +1 -1
- package/src/model/history.ts +151 -26
- package/src/model/plugin-host.ts +26 -2
- package/src/model/workspace-config.ts +30 -0
- package/src/pbot.ts +13 -22
- package/src/plugin.ts +2 -2
- package/src/services/history/history-capture.ts +83 -0
- package/src/services/history/history-index.ts +48 -62
- package/src/services/history/history-migrate.ts +89 -0
- package/src/services/history/history-query.ts +415 -0
- package/src/services/history/summary-command.ts +69 -0
- package/src/services/history/summary-dimensions/monthly.ts +139 -0
- package/src/services/history/summary-dimensions/session.ts +149 -0
- package/src/services/history/summary-registry.ts +44 -0
- package/src/services/history/summary-runner.ts +352 -0
- package/src/services/workspace/workspace-config.ts +93 -5
- package/src/storage/history-files.ts +408 -188
- package/src/storage/history-format.ts +46 -60
- package/src/tools/history/actions.ts +8 -6
- package/src/tools/history/contract.ts +65 -20
- package/src/tools/history/dsh-tool.ts +17 -8
- package/src/tools/history/pi-tool.ts +21 -0
- package/src/tools/register.ts +3 -4
- package/src/ui/dsh/management.ts +27 -11
- package/src/ui/{confirmation.ts → pi/confirmation.ts} +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.d.ts +0 -4
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.js +0 -79
- package/lib/extension/dsh/command.js +0 -50
- package/lib/extension/dsh/history.d.ts +0 -15
- package/lib/extension/dsh/history.js +0 -87
- package/lib/integrations/dsh/history-summary.d.ts +0 -11
- package/lib/integrations/dsh/history-summary.js +0 -36
- package/lib/integrations/dsh/history.d.ts +0 -16
- package/lib/integrations/dsh/history.js +0 -167
- package/lib/integrations/history-summary.d.ts +0 -4
- package/lib/integrations/history-summary.js +0 -32
- package/lib/integrations/hosts/antigravity.d.ts +0 -4
- package/lib/integrations/hosts/antigravity.js +0 -79
- package/lib/services/history/history-service.d.ts +0 -106
- package/lib/services/history/history-service.js +0 -242
- package/lib/storage/acp-history.d.ts +0 -10
- package/lib/storage/acp-history.js +0 -57
- package/src/extension/command.ts +0 -76
- package/src/extension/dsh/command.ts +0 -54
- package/src/extension/dsh/history.ts +0 -74
- package/src/extension/history.ts +0 -26
- package/src/integrations/dsh/history-summary.ts +0 -39
- package/src/integrations/dsh/history.ts +0 -84
- package/src/integrations/history-summary.ts +0 -30
- package/src/integrations/hosts/antigravity.ts +0 -83
- package/src/integrations/pi/history.ts +0 -99
- package/src/services/history/history-service.ts +0 -195
- package/src/storage/acp-history.ts +0 -49
- package/src/tools/history/tool.ts +0 -19
- /package/lib/antigravity-plugin/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +0 -0
- /package/lib/{extension/acp-worker.d.ts → antigravity-plugin/lib/model/history.js} +0 -0
- /package/lib/extension/{dsh → hosts/dsh}/acp-member.d.ts +0 -0
- /package/lib/extension/{dsh → hosts/dsh}/command.d.ts +0 -0
- /package/lib/extension/{dsh → hosts/dsh}/files.d.ts +0 -0
- /package/lib/extension/{setup-guard.js → setup/guard.js} +0 -0
- /package/lib/integrations/acp/{claude.d.ts → claude-settings.d.ts} +0 -0
- /package/lib/integrations/acp/{claude.js → claude-settings.js} +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/mcp.js +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/messages.d.ts +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/messages.js +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/root-agents.d.ts +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/root-agents.js +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/schema.d.ts +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/skills.d.ts +0 -0
- /package/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +0 -0
- /package/src/extension/{setup-guard.ts → setup/guard.ts} +0 -0
- /package/src/integrations/acp/{claude.ts → claude-settings.ts} +0 -0
- /package/src/integrations/{dsh → hosts/dsh}/messages.ts +0 -0
- /package/src/integrations/{dsh → hosts/dsh}/root-agents.ts +0 -0
- /package/src/integrations/{pi → hosts/pi}/agent-tools.ts +0 -0
package/lib/model/history.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { HistoryLayout } from "./workspace-config.js";
|
|
2
|
+
export type { HistoryLayout };
|
|
3
|
+
export type HistoryHost = string;
|
|
1
4
|
export interface HistoryExchange {
|
|
2
5
|
entryIds: string[];
|
|
3
6
|
text: string;
|
|
@@ -23,44 +26,25 @@ export interface RawHistory extends HistoryIdentity {
|
|
|
23
26
|
exchanges: (HistoryExchange & {
|
|
24
27
|
id: string;
|
|
25
28
|
})[];
|
|
26
|
-
/** Ordered paths observed in the native source.
|
|
29
|
+
/** Ordered paths observed in the native source. */
|
|
27
30
|
branches: string[][];
|
|
28
31
|
}
|
|
29
|
-
export interface
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
ready: boolean;
|
|
34
|
-
}
|
|
35
|
-
export interface HistoryArchive {
|
|
36
|
-
raw: RawHistory;
|
|
37
|
-
/** Empty if absent; null if the derived file is unreadable. */
|
|
38
|
-
summaries: HistorySummary[] | null;
|
|
39
|
-
}
|
|
40
|
-
export interface HistoryNode extends HistorySummary {
|
|
41
|
-
kind: "session" | "exchange" | "summary";
|
|
42
|
-
parents: string[];
|
|
32
|
+
export interface SummarySource {
|
|
33
|
+
rawIds: string[];
|
|
34
|
+
exchangeIds: string[];
|
|
35
|
+
fingerprint: string;
|
|
43
36
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
export type HistoryHost = "pi" | "dsh" | "claude";
|
|
50
|
-
export type HistoryLocation = {
|
|
51
|
-
host: "pi";
|
|
52
|
-
directory: string;
|
|
53
|
-
file?: string;
|
|
54
|
-
} | {
|
|
55
|
-
host: "dsh";
|
|
37
|
+
export interface SummaryArtifact {
|
|
38
|
+
id: string;
|
|
39
|
+
dimension: string;
|
|
40
|
+
host?: HistoryHost;
|
|
56
41
|
sessionId?: string;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}>;
|
|
42
|
+
title: string;
|
|
43
|
+
text: string;
|
|
44
|
+
from: string;
|
|
45
|
+
to: string;
|
|
46
|
+
updatedAt: string;
|
|
47
|
+
source: SummarySource;
|
|
64
48
|
}
|
|
65
49
|
export interface HistorySummaryRequest {
|
|
66
50
|
system: string;
|
|
@@ -68,3 +52,118 @@ export interface HistorySummaryRequest {
|
|
|
68
52
|
maxTokens: number;
|
|
69
53
|
}
|
|
70
54
|
export type HistorySummarizer = (request: HistorySummaryRequest, signal: AbortSignal) => Promise<string>;
|
|
55
|
+
export type SummaryTaskMode = "create" | "incremental" | "rebuild";
|
|
56
|
+
export interface SummaryTask {
|
|
57
|
+
id: string;
|
|
58
|
+
dimension: string;
|
|
59
|
+
mode: SummaryTaskMode;
|
|
60
|
+
title: string;
|
|
61
|
+
host?: HistoryHost;
|
|
62
|
+
sessionId?: string;
|
|
63
|
+
from: string;
|
|
64
|
+
to: string;
|
|
65
|
+
source: SummarySource;
|
|
66
|
+
exchanges: readonly (HistoryExchange & {
|
|
67
|
+
id: string;
|
|
68
|
+
})[];
|
|
69
|
+
existing?: SummaryArtifact;
|
|
70
|
+
addedExchanges?: readonly (HistoryExchange & {
|
|
71
|
+
id: string;
|
|
72
|
+
})[];
|
|
73
|
+
sourceSummaries?: readonly SummaryArtifact[];
|
|
74
|
+
}
|
|
75
|
+
export interface SummaryPlanOptions {
|
|
76
|
+
force?: boolean;
|
|
77
|
+
summariesByDimension?: ReadonlyMap<string, ReadonlyMap<string, SummaryArtifact>>;
|
|
78
|
+
}
|
|
79
|
+
export interface SummaryPlanResult {
|
|
80
|
+
tasks: SummaryTask[];
|
|
81
|
+
skipped: number;
|
|
82
|
+
}
|
|
83
|
+
export interface SummaryDimension {
|
|
84
|
+
readonly id: string;
|
|
85
|
+
readonly title: string;
|
|
86
|
+
readonly description: string;
|
|
87
|
+
readonly requiresMonthlyLayout?: boolean;
|
|
88
|
+
plan(raws: readonly RawHistory[], existing: ReadonlyMap<string, SummaryArtifact>, options?: SummaryPlanOptions): SummaryPlanResult;
|
|
89
|
+
buildRequest(task: SummaryTask): HistorySummaryRequest;
|
|
90
|
+
finalize(task: SummaryTask, output: string, now: string): SummaryArtifact;
|
|
91
|
+
}
|
|
92
|
+
export interface HistoryMigrationItem {
|
|
93
|
+
kind: "raw" | "summary";
|
|
94
|
+
dimension?: string;
|
|
95
|
+
id: string;
|
|
96
|
+
from: string;
|
|
97
|
+
to: string;
|
|
98
|
+
}
|
|
99
|
+
export interface HistoryMigrationConflict {
|
|
100
|
+
kind: "raw" | "summary";
|
|
101
|
+
dimension?: string;
|
|
102
|
+
from: string;
|
|
103
|
+
to: string;
|
|
104
|
+
reason: string;
|
|
105
|
+
}
|
|
106
|
+
export interface HistoryMigrationReport {
|
|
107
|
+
layout: HistoryLayout;
|
|
108
|
+
dryRun: boolean;
|
|
109
|
+
moved: HistoryMigrationItem[];
|
|
110
|
+
skipped: HistoryMigrationConflict[];
|
|
111
|
+
errors: {
|
|
112
|
+
path: string;
|
|
113
|
+
error: string;
|
|
114
|
+
}[];
|
|
115
|
+
}
|
|
116
|
+
export interface SummaryDimensionStatus {
|
|
117
|
+
dimension: string;
|
|
118
|
+
title: string;
|
|
119
|
+
description: string;
|
|
120
|
+
total: number;
|
|
121
|
+
ready: number;
|
|
122
|
+
pendingCreate: number;
|
|
123
|
+
pendingIncremental: number;
|
|
124
|
+
pendingRebuild: number;
|
|
125
|
+
}
|
|
126
|
+
export interface HistorySummaryReminder {
|
|
127
|
+
rawCount: number;
|
|
128
|
+
pendingCount: number;
|
|
129
|
+
oldestRawAt: string;
|
|
130
|
+
latestSummaryAt?: string;
|
|
131
|
+
rawAgeDays: number;
|
|
132
|
+
daysSinceLastSummary?: number;
|
|
133
|
+
thresholdDays: number;
|
|
134
|
+
message: string;
|
|
135
|
+
}
|
|
136
|
+
export interface SummaryRunProgress {
|
|
137
|
+
dimension: string;
|
|
138
|
+
completed: number;
|
|
139
|
+
total: number;
|
|
140
|
+
currentId: string;
|
|
141
|
+
mode: SummaryTaskMode;
|
|
142
|
+
}
|
|
143
|
+
export interface SummaryDimensionReport {
|
|
144
|
+
dimension: string;
|
|
145
|
+
scanned: number;
|
|
146
|
+
skipped: number;
|
|
147
|
+
created: number;
|
|
148
|
+
incremental: number;
|
|
149
|
+
rebuilt: number;
|
|
150
|
+
failed: {
|
|
151
|
+
id: string;
|
|
152
|
+
error: string;
|
|
153
|
+
}[];
|
|
154
|
+
}
|
|
155
|
+
export interface SummaryRunReport {
|
|
156
|
+
dimensions: SummaryDimensionReport[];
|
|
157
|
+
durationMs: number;
|
|
158
|
+
warnings: string[];
|
|
159
|
+
}
|
|
160
|
+
export interface HistoryQuery {
|
|
161
|
+
host?: HistoryHost;
|
|
162
|
+
query?: string;
|
|
163
|
+
sessionId?: string;
|
|
164
|
+
dimension?: string;
|
|
165
|
+
from?: string;
|
|
166
|
+
to?: string;
|
|
167
|
+
offset?: number;
|
|
168
|
+
limit?: number;
|
|
169
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HistorySession } from "./history.js";
|
|
1
2
|
import type { WorkspaceSkillMeta } from "./workspace-mcp.js";
|
|
2
3
|
export type HostId = string;
|
|
3
4
|
export type PluginHostId = string;
|
|
@@ -15,12 +16,30 @@ export interface WorkspaceContext {
|
|
|
15
16
|
environment: WorkspaceEnvironment;
|
|
16
17
|
text: string;
|
|
17
18
|
}
|
|
19
|
+
export type HistoryCapture = {
|
|
20
|
+
kind: "input";
|
|
21
|
+
sessionId: string;
|
|
22
|
+
text: string;
|
|
23
|
+
timestamp?: string;
|
|
24
|
+
} | {
|
|
25
|
+
kind: "answer";
|
|
26
|
+
sessionId: string;
|
|
27
|
+
userText?: string;
|
|
28
|
+
assistantText: string;
|
|
29
|
+
completed: boolean;
|
|
30
|
+
isContinuation?: boolean;
|
|
31
|
+
timestamp?: string;
|
|
32
|
+
} | {
|
|
33
|
+
kind: "session";
|
|
34
|
+
session: HistorySession;
|
|
35
|
+
};
|
|
18
36
|
export type HostEvent = {
|
|
19
37
|
kind: "ignore";
|
|
20
38
|
} | {
|
|
21
39
|
kind: "inject-context";
|
|
22
40
|
role: WorkspaceRole;
|
|
23
41
|
localRoleOnly?: boolean;
|
|
42
|
+
isSessionStart?: boolean;
|
|
24
43
|
cwd: string;
|
|
25
44
|
raw: unknown;
|
|
26
45
|
} | {
|
|
@@ -28,6 +47,10 @@ export type HostEvent = {
|
|
|
28
47
|
skill: string;
|
|
29
48
|
cwd: string;
|
|
30
49
|
raw: unknown;
|
|
50
|
+
} | {
|
|
51
|
+
kind: "record-history";
|
|
52
|
+
cwd: string;
|
|
53
|
+
raw: unknown;
|
|
31
54
|
};
|
|
32
55
|
export interface PluginHostAdapter {
|
|
33
56
|
readonly host: PluginHostId;
|
|
@@ -38,6 +61,9 @@ export interface PluginHostAdapter {
|
|
|
38
61
|
readonly usage: string;
|
|
39
62
|
resolveRoot(cwd: string, rawPayload?: unknown): Promise<string>;
|
|
40
63
|
parseEvent(payload: unknown): HostEvent;
|
|
64
|
+
extractHistory?(event: Extract<HostEvent, {
|
|
65
|
+
kind: "inject-context" | "record-history";
|
|
66
|
+
}>): Promise<HistoryCapture | undefined>;
|
|
41
67
|
formatPass(payload: unknown): Record<string, unknown>;
|
|
42
68
|
formatContext(event: Extract<HostEvent, {
|
|
43
69
|
kind: "inject-context";
|
|
@@ -3,16 +3,39 @@ export interface WorkspaceFeatures {
|
|
|
3
3
|
prompts?: boolean;
|
|
4
4
|
skills?: boolean;
|
|
5
5
|
mcp?: boolean;
|
|
6
|
+
history?: boolean;
|
|
6
7
|
}
|
|
7
8
|
export interface ResolvedWorkspaceFeatures {
|
|
8
9
|
readonly prompts: boolean;
|
|
9
10
|
readonly skills: boolean;
|
|
10
11
|
readonly mcp: boolean;
|
|
12
|
+
readonly history: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface WorkspaceSummaryConfig {
|
|
15
|
+
backend?: string;
|
|
16
|
+
model?: string;
|
|
17
|
+
thinking?: string;
|
|
18
|
+
concurrency?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface ResolvedWorkspaceSummaryConfig {
|
|
21
|
+
readonly backend: string;
|
|
22
|
+
readonly model?: string;
|
|
23
|
+
readonly thinking?: string;
|
|
24
|
+
readonly concurrency: number;
|
|
25
|
+
}
|
|
26
|
+
export type HistoryLayout = "monthly" | "flat";
|
|
27
|
+
export interface WorkspaceHistoryConfig {
|
|
28
|
+
layout?: HistoryLayout;
|
|
29
|
+
}
|
|
30
|
+
export interface ResolvedWorkspaceHistoryConfig {
|
|
31
|
+
readonly layout: HistoryLayout;
|
|
11
32
|
}
|
|
12
33
|
export interface WorkspaceConfig {
|
|
13
34
|
enabled?: boolean;
|
|
14
35
|
features?: WorkspaceFeatures;
|
|
15
36
|
acp?: AcpCommands;
|
|
37
|
+
summary?: WorkspaceSummaryConfig;
|
|
38
|
+
history?: WorkspaceHistoryConfig;
|
|
16
39
|
}
|
|
17
40
|
export interface WorkspaceConfiguration {
|
|
18
41
|
path: string;
|
|
@@ -21,4 +44,6 @@ export interface WorkspaceConfiguration {
|
|
|
21
44
|
error?: string;
|
|
22
45
|
features?: WorkspaceFeatures;
|
|
23
46
|
acp?: AcpCommands;
|
|
47
|
+
summary?: WorkspaceSummaryConfig;
|
|
48
|
+
history?: WorkspaceHistoryConfig;
|
|
24
49
|
}
|
package/lib/plugin.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { realpathSync } from "node:fs";
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
3
|
import { requireThat } from "./common/validation.js";
|
|
4
|
-
import { runPluginHost } from "./extension/plugin-runtime.js";
|
|
5
|
-
import { listPluginHosts, pluginHosts } from "./integrations/hosts/registry.js";
|
|
4
|
+
import { runPluginHost } from "./extension/hosts/plugin-runtime.js";
|
|
5
|
+
import { listPluginHosts, pluginHosts } from "./integrations/hosts/plugin-registry.js";
|
|
6
6
|
export async function main(args) {
|
|
7
7
|
const [host, ...rest] = args;
|
|
8
8
|
const adapter = host ? pluginHosts.get(host) : undefined;
|
|
@@ -8,7 +8,7 @@ export declare class AgentRun {
|
|
|
8
8
|
readonly generation: string;
|
|
9
9
|
constructor(files: AgentFiles, id: string, generation: string);
|
|
10
10
|
get current(): Readonly<AgentCycle> | undefined;
|
|
11
|
-
get state(): "starting" | "busy" | "idle" | "stopping" | "stopped"
|
|
11
|
+
get state(): "error" | "starting" | "busy" | "idle" | "stopping" | "stopped";
|
|
12
12
|
get pending(): number;
|
|
13
13
|
get interactive(): boolean;
|
|
14
14
|
accepted(requestId: string): boolean;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HistoryHost } from "../../model/history.js";
|
|
2
|
+
import type { HistoryCapture } from "../../model/plugin-host.js";
|
|
3
|
+
/** Persist a host raw history observation atomically into .pbot/history/raw/. */
|
|
4
|
+
export declare function recordHistoryCapture(root: string, host: HistoryHost, capture: HistoryCapture): void;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { isDeepStrictEqual } from "node:util";
|
|
4
|
+
import { HistoryFiles } from "../../storage/history-files.js";
|
|
5
|
+
import { readWorkspaceHistoryLayoutSync } from "../workspace/workspace-config.js";
|
|
6
|
+
import { indexHistory, orderedRawExchanges } from "./history-index.js";
|
|
7
|
+
function orderedExchanges(raw) {
|
|
8
|
+
if (!raw)
|
|
9
|
+
return [];
|
|
10
|
+
return orderedRawExchanges(raw).map(({ entryIds, text, from, to, completed }) => ({
|
|
11
|
+
entryIds: [...entryIds],
|
|
12
|
+
text,
|
|
13
|
+
from,
|
|
14
|
+
to,
|
|
15
|
+
completed,
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
function replaceAssistantSuffix(text, assistantText) {
|
|
19
|
+
const marker = "\n\n助手:\n";
|
|
20
|
+
const index = text.lastIndexOf(marker);
|
|
21
|
+
if (index >= 0)
|
|
22
|
+
return text.slice(0, index) + marker + assistantText;
|
|
23
|
+
return text ? `${text}${marker}${assistantText}` : `助手:\n${assistantText}`;
|
|
24
|
+
}
|
|
25
|
+
function buildSession(host, capture, previous) {
|
|
26
|
+
if (capture.kind === "session") {
|
|
27
|
+
return capture.session.branches.length ? capture.session : undefined;
|
|
28
|
+
}
|
|
29
|
+
const timestamp = capture.timestamp ?? new Date().toISOString();
|
|
30
|
+
const branch = orderedExchanges(previous);
|
|
31
|
+
if (capture.kind === "input") {
|
|
32
|
+
const text = capture.text.trim();
|
|
33
|
+
if (!text)
|
|
34
|
+
return undefined;
|
|
35
|
+
const entryId = `${host}:${Date.now()}:${randomUUID().slice(0, 8)}`;
|
|
36
|
+
branch.push({
|
|
37
|
+
entryIds: [entryId],
|
|
38
|
+
text: "用户:\n" + text,
|
|
39
|
+
from: timestamp,
|
|
40
|
+
to: timestamp,
|
|
41
|
+
completed: false,
|
|
42
|
+
});
|
|
43
|
+
return { sessionId: capture.sessionId, name: previous?.name ?? "", branches: [branch] };
|
|
44
|
+
}
|
|
45
|
+
const assistantText = capture.assistantText.trim();
|
|
46
|
+
if (!assistantText)
|
|
47
|
+
return undefined;
|
|
48
|
+
const last = branch.at(-1);
|
|
49
|
+
if (last && (!last.completed || capture.isContinuation)) {
|
|
50
|
+
last.text = replaceAssistantSuffix(last.text, assistantText);
|
|
51
|
+
last.to = timestamp;
|
|
52
|
+
last.completed = capture.completed;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const entryId = `${host}:${Date.now()}:${randomUUID().slice(0, 8)}`;
|
|
56
|
+
const userText = capture.userText?.trim();
|
|
57
|
+
branch.push({
|
|
58
|
+
entryIds: [entryId],
|
|
59
|
+
text: userText ? `用户:\n${userText}\n\n助手:\n${assistantText}` : `助手:\n${assistantText}`,
|
|
60
|
+
from: timestamp,
|
|
61
|
+
to: timestamp,
|
|
62
|
+
completed: capture.completed,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return { sessionId: capture.sessionId, name: previous?.name ?? "", branches: [branch] };
|
|
66
|
+
}
|
|
67
|
+
/** Persist a host raw history observation atomically into .pbot/history/raw/. */
|
|
68
|
+
export function recordHistoryCapture(root, host, capture) {
|
|
69
|
+
const sessionId = capture.kind === "session" ? capture.session.sessionId : capture.sessionId;
|
|
70
|
+
if (!sessionId)
|
|
71
|
+
return;
|
|
72
|
+
const layout = readWorkspaceHistoryLayoutSync(root);
|
|
73
|
+
const files = new HistoryFiles(join(root, ".pbot/history"), host, layout);
|
|
74
|
+
files.control(() => {
|
|
75
|
+
const previous = files.listRaw(host).find(raw => raw.sessionId === sessionId);
|
|
76
|
+
if (!previous && files.rawWarnings.length)
|
|
77
|
+
return;
|
|
78
|
+
const session = buildSession(host, capture, previous);
|
|
79
|
+
if (!session || !session.branches.length)
|
|
80
|
+
return;
|
|
81
|
+
const raw = indexHistory(session, previous, host);
|
|
82
|
+
if (isDeepStrictEqual(raw, previous))
|
|
83
|
+
return;
|
|
84
|
+
files.saveRaw(raw);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/**
|
|
1
|
+
import type { HistoryExchange, HistoryHost, HistorySession, RawHistory } from "../../model/history.js";
|
|
2
|
+
/** Merge a native session observation into its raw archive without modifying persisted order invariants. */
|
|
3
3
|
export declare function indexHistory(session: HistorySession, previous?: RawHistory, host?: HistoryHost): RawHistory;
|
|
4
|
-
/**
|
|
5
|
-
export declare function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export declare function
|
|
4
|
+
/** Return deduplicated exchanges in conversation order (branch order first, then any unbranched entries by timestamp). */
|
|
5
|
+
export declare function orderedRawExchanges(raw: RawHistory): (HistoryExchange & {
|
|
6
|
+
id: string;
|
|
7
|
+
})[];
|
|
8
|
+
export declare function rawSessionTitle(raw: RawHistory): string;
|
|
9
|
+
export declare function rawSessionSpan(exchanges: readonly HistoryExchange[]): {
|
|
10
|
+
from: string;
|
|
11
|
+
to: string;
|
|
12
|
+
completed: boolean;
|
|
13
|
+
};
|
|
14
|
+
/** Stable SHA-256 fingerprint over ordered exchange contents for exact deduplication and prefix matching. */
|
|
15
|
+
export declare function fingerprintExchanges(exchanges: readonly (HistoryExchange & {
|
|
16
|
+
id: string;
|
|
17
|
+
})[]): string;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { isDeepStrictEqual } from "node:util";
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
2
|
import { requireThat } from "../../common/validation.js";
|
|
4
3
|
/** Each native entry has one predecessor. A shortened observation can extend a known path, not erase its prefix. */
|
|
5
4
|
function mergeBranches(previous, observed, removed) {
|
|
@@ -31,9 +30,9 @@ function mergeBranches(previous, observed, removed) {
|
|
|
31
30
|
requireThat(seen.size === parents.size, "历史分支包含循环引用。");
|
|
32
31
|
return branches;
|
|
33
32
|
}
|
|
34
|
-
/**
|
|
33
|
+
/** Merge a native session observation into its raw archive without modifying persisted order invariants. */
|
|
35
34
|
export function indexHistory(session, previous, host = previous?.host ?? "pi") {
|
|
36
|
-
requireThat(!previous || previous.host === host && previous.sessionId === session.sessionId, "历史会话与归档来源不匹配。");
|
|
35
|
+
requireThat(!previous || (previous.host === host && previous.sessionId === session.sessionId), "历史会话与归档来源不匹配。");
|
|
37
36
|
const id = previous?.id ?? (host === "pi" ? "" : host + "-") + randomUUID();
|
|
38
37
|
const exchanges = new Map(previous?.exchanges.map(item => [item.id, item]));
|
|
39
38
|
const byEnd = new Map(previous?.exchanges.map(item => [item.entryIds.at(-1), item.id]));
|
|
@@ -60,75 +59,54 @@ export function indexHistory(session, previous, host = previous?.host ?? "pi") {
|
|
|
60
59
|
exchanges.delete(item.id);
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
|
-
return {
|
|
64
|
-
|
|
62
|
+
return {
|
|
63
|
+
host,
|
|
64
|
+
id,
|
|
65
|
+
sessionId: session.sessionId,
|
|
66
|
+
name: session.name,
|
|
67
|
+
exchanges: [...exchanges.values()],
|
|
68
|
+
branches: mergeBranches(previous?.branches ?? [], branches, removed),
|
|
69
|
+
};
|
|
65
70
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
export function retainHistorySummaries(before, after, summaries) {
|
|
72
|
-
const inputs = new Map(after.exchanges.map(item => [item.id, item]));
|
|
73
|
-
const changed = new Set(before.exchanges.filter(item => !isDeepStrictEqual(item, inputs.get(item.id))).map(item => item.id));
|
|
74
|
-
if (!changed.size || !summaries.length)
|
|
75
|
-
return summaries;
|
|
76
|
-
const retained = new Map();
|
|
77
|
-
for (const item of [...summaries].sort((a, b) => a.level - b.level)) {
|
|
78
|
-
const children = item.children.map(id => inputs.get(id));
|
|
79
|
-
if (!children.length || !children.every(child => child !== undefined)) {
|
|
80
|
-
changed.add(item.id);
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
let summary = item;
|
|
84
|
-
if (item.children.some(id => changed.has(id))) {
|
|
85
|
-
summary = { ...item, ...span(children), text: "", ready: false };
|
|
86
|
-
changed.add(item.id);
|
|
87
|
-
}
|
|
88
|
-
retained.set(item.id, summary);
|
|
89
|
-
inputs.set(item.id, summary);
|
|
90
|
-
}
|
|
91
|
-
return summaries.flatMap(item => retained.get(item.id) ?? []);
|
|
92
|
-
}
|
|
93
|
-
/** The four-way tree is a query view, never the source of native branch order. */
|
|
94
|
-
export function historyView(raw, saved = []) {
|
|
95
|
-
const nodes = new Map(raw.exchanges.map(value => [value.id,
|
|
96
|
-
{ ...value, kind: "exchange", level: 0, ready: true, children: [], parents: [] }]));
|
|
97
|
-
const stored = new Map(saved?.map(value => [value.id, value]));
|
|
98
|
-
const groups = new Map(stored);
|
|
71
|
+
/** Return deduplicated exchanges in conversation order (branch order first, then any unbranched entries by timestamp). */
|
|
72
|
+
export function orderedRawExchanges(raw) {
|
|
73
|
+
const lookup = new Map(raw.exchanges.map(item => [item.id, item]));
|
|
74
|
+
const seen = new Set();
|
|
75
|
+
const ordered = [];
|
|
99
76
|
for (const branch of raw.branches) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
layer = next;
|
|
77
|
+
for (const id of branch) {
|
|
78
|
+
if (seen.has(id))
|
|
79
|
+
continue;
|
|
80
|
+
const item = lookup.get(id);
|
|
81
|
+
if (!item)
|
|
82
|
+
continue;
|
|
83
|
+
seen.add(id);
|
|
84
|
+
ordered.push(item);
|
|
109
85
|
}
|
|
110
86
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
for (const node of nodes.values())
|
|
121
|
-
for (const child of node.children)
|
|
122
|
-
nodes.get(child).parents.push(node.id);
|
|
123
|
-
const top = [...nodes.values()].filter(node => !node.parents.length).sort((a, b) => a.from.localeCompare(b.from));
|
|
124
|
-
for (const child of top)
|
|
125
|
-
child.parents.push(raw.id);
|
|
126
|
-
const dates = raw.exchanges.flatMap(item => [item.from, item.to]).sort();
|
|
127
|
-
const name = raw.name || raw.exchanges[0]?.text.replace(/\s+/g, " ").slice(0, 80) || "";
|
|
128
|
-
nodes.set(raw.id, { id: raw.id, kind: "session", level: -1, entryIds: [], text: name, ready: true,
|
|
129
|
-
completed: raw.exchanges.every(item => item.completed), from: dates[0] ?? "", to: dates.at(-1) ?? "", parents: [], children: top.map(node => node.id) });
|
|
130
|
-
return { host: raw.host, id: raw.id, sessionId: raw.sessionId, name, nodes: [...nodes.values()] };
|
|
87
|
+
const rest = raw.exchanges
|
|
88
|
+
.filter(item => !seen.has(item.id))
|
|
89
|
+
.sort((a, b) => a.from.localeCompare(b.from) || a.id.localeCompare(b.id));
|
|
90
|
+
ordered.push(...rest);
|
|
91
|
+
return ordered;
|
|
92
|
+
}
|
|
93
|
+
export function rawSessionTitle(raw) {
|
|
94
|
+
return raw.name.trim();
|
|
131
95
|
}
|
|
132
|
-
export function
|
|
133
|
-
|
|
96
|
+
export function rawSessionSpan(exchanges) {
|
|
97
|
+
const dates = exchanges.flatMap(item => [item.from, item.to]).filter(Boolean).sort();
|
|
98
|
+
return {
|
|
99
|
+
from: dates[0] ?? "",
|
|
100
|
+
to: dates.at(-1) ?? "",
|
|
101
|
+
completed: exchanges.every(item => item.completed),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** Stable SHA-256 fingerprint over ordered exchange contents for exact deduplication and prefix matching. */
|
|
105
|
+
export function fingerprintExchanges(exchanges) {
|
|
106
|
+
const hash = createHash("sha256");
|
|
107
|
+
for (const item of exchanges) {
|
|
108
|
+
hash.update(JSON.stringify([item.id, item.entryIds, item.text, item.from, item.to, item.completed]));
|
|
109
|
+
hash.update("\n");
|
|
110
|
+
}
|
|
111
|
+
return hash.digest("hex");
|
|
134
112
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { HistoryMigrationReport } from "../../model/history.js";
|
|
2
|
+
export interface MigrateHistoryOptions {
|
|
3
|
+
dryRun?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/** Read-only check for unmigrated flat history files when running under monthly layout. */
|
|
6
|
+
export declare function checkHistoryMigrationNotice(root: string): string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Explicitly migrate flat .pbot/history/raw/*.json and .pbot/history/summaries/<dim>/*.json
|
|
9
|
+
* into UTC YYYY/MM/ (or unknown/) buckets. Moves files directly without keeping duplicates
|
|
10
|
+
* and never modifies .pbot/config.json or overwrites existing destinations.
|
|
11
|
+
*/
|
|
12
|
+
export declare function migrateWorkspaceHistory(root: string, options?: MigrateHistoryOptions): HistoryMigrationReport;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { lstatSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { requireThat } from "../../common/validation.js";
|
|
4
|
+
import { HistoryFiles, rawHistoryBucket, summaryArtifactBucket } from "../../storage/history-files.js";
|
|
5
|
+
import { readWorkspaceHistoryLayoutSync } from "../workspace/workspace-config.js";
|
|
6
|
+
/** Read-only check for unmigrated flat history files when running under monthly layout. */
|
|
7
|
+
export function checkHistoryMigrationNotice(root) {
|
|
8
|
+
const layout = readWorkspaceHistoryLayoutSync(root);
|
|
9
|
+
if (layout !== "monthly")
|
|
10
|
+
return undefined;
|
|
11
|
+
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", layout);
|
|
12
|
+
return files.detectFlatFiles().message;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Explicitly migrate flat .pbot/history/raw/*.json and .pbot/history/summaries/<dim>/*.json
|
|
16
|
+
* into UTC YYYY/MM/ (or unknown/) buckets. Moves files directly without keeping duplicates
|
|
17
|
+
* and never modifies .pbot/config.json or overwrites existing destinations.
|
|
18
|
+
*/
|
|
19
|
+
export function migrateWorkspaceHistory(root, options = {}) {
|
|
20
|
+
const layout = readWorkspaceHistoryLayoutSync(root);
|
|
21
|
+
requireThat(layout === "monthly", '当前工作区配置为平铺布局(history.layout: "flat"),无需迁移到年月目录;如需迁移,请先在 .pbot/config.json 中将 history.layout 设为 "monthly" 或移除该配置项。');
|
|
22
|
+
const dryRun = Boolean(options.dryRun);
|
|
23
|
+
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", "monthly");
|
|
24
|
+
const moved = [];
|
|
25
|
+
const skipped = [];
|
|
26
|
+
const errors = [];
|
|
27
|
+
const run = () => {
|
|
28
|
+
for (const name of files.listFlatRawFiles()) {
|
|
29
|
+
const from = `raw/${name}`;
|
|
30
|
+
try {
|
|
31
|
+
const raw = files.readFlatRawFile(name);
|
|
32
|
+
const bucket = rawHistoryBucket(raw);
|
|
33
|
+
const to = `raw/${bucket}/${name}`;
|
|
34
|
+
if (dryRun) {
|
|
35
|
+
if (lstatSync(join(files.directory, to), { throwIfNoEntry: false })) {
|
|
36
|
+
skipped.push({ kind: "raw", from, to, reason: "目标路径已存在同名文件。" });
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
moved.push({ kind: "raw", id: raw.id, from, to });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const outcome = files.moveHistoryFile(from, to);
|
|
44
|
+
if (outcome === "moved")
|
|
45
|
+
moved.push({ kind: "raw", id: raw.id, from, to });
|
|
46
|
+
else
|
|
47
|
+
skipped.push({ kind: "raw", from, to, reason: "目标路径已存在同名文件。" });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
errors.push({ path: join(files.directory, from), error: error instanceof Error ? error.message : String(error) });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (const dimension of files.listDimensions()) {
|
|
55
|
+
for (const name of files.listFlatSummaryFiles(dimension)) {
|
|
56
|
+
const from = `summaries/${dimension}/${name}`;
|
|
57
|
+
try {
|
|
58
|
+
const artifact = files.readFlatSummaryFile(dimension, name);
|
|
59
|
+
const bucket = summaryArtifactBucket(artifact);
|
|
60
|
+
const to = `summaries/${dimension}/${bucket}/${name}`;
|
|
61
|
+
if (dryRun) {
|
|
62
|
+
if (lstatSync(join(files.directory, to), { throwIfNoEntry: false })) {
|
|
63
|
+
skipped.push({ kind: "summary", dimension, from, to, reason: "目标路径已存在同名文件。" });
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
moved.push({ kind: "summary", dimension, id: artifact.id, from, to });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const outcome = files.moveHistoryFile(from, to);
|
|
71
|
+
if (outcome === "moved")
|
|
72
|
+
moved.push({ kind: "summary", dimension, id: artifact.id, from, to });
|
|
73
|
+
else
|
|
74
|
+
skipped.push({ kind: "summary", dimension, from, to, reason: "目标路径已存在同名文件。" });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
errors.push({ path: join(files.directory, from), error: error instanceof Error ? error.message : String(error) });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
if (dryRun)
|
|
84
|
+
run();
|
|
85
|
+
else
|
|
86
|
+
files.controlMigration(run);
|
|
87
|
+
return { layout, dryRun, moved, skipped, errors };
|
|
88
|
+
}
|