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.
Files changed (256) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +1 -1
  4. package/README.zh-CN.md +1 -1
  5. package/bin/pbot-pi-acp.mjs +27 -11
  6. package/bin/pbot.mjs +1 -1
  7. package/docs/README.md +1 -1
  8. package/docs/architecture/design.md +23 -10
  9. package/docs/architecture/extensibility.md +20 -18
  10. package/docs/architecture/model-context.md +2 -2
  11. package/docs/architecture/principles.md +4 -3
  12. package/docs/guides/capabilities.md +3 -3
  13. package/docs/guides/history.md +50 -16
  14. package/docs/guides/workspace-configuration.md +31 -6
  15. package/docs/hosts/antigravity.md +2 -0
  16. package/docs/hosts/claude-code.md +1 -1
  17. package/docs/hosts/dsh.md +1 -1
  18. package/docs/hosts/pi.md +1 -1
  19. package/hooks/hooks.json +3 -0
  20. package/lib/antigravity-plugin/hooks.json +7 -0
  21. package/lib/antigravity-plugin/lib/claude.js +2 -2
  22. package/lib/antigravity-plugin/lib/extension/acp-worker.js +156 -11
  23. package/lib/antigravity-plugin/lib/extension/{plugin-runtime.d.ts → hosts/plugin-runtime.d.ts} +2 -2
  24. package/lib/antigravity-plugin/lib/extension/{plugin-runtime.js → hosts/plugin-runtime.js} +34 -8
  25. package/lib/antigravity-plugin/lib/extension/mcp.js +1113 -78
  26. package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +1 -0
  27. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +5 -1
  28. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
  29. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.js +171 -0
  30. package/lib/antigravity-plugin/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
  31. package/lib/antigravity-plugin/lib/integrations/hosts/{claude.js → claude/adapter.js} +32 -4
  32. package/lib/antigravity-plugin/lib/integrations/hosts/{registry.js → plugin-registry.js} +2 -2
  33. package/lib/antigravity-plugin/lib/model/history.d.ts +169 -0
  34. package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +26 -0
  35. package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +25 -0
  36. package/lib/antigravity-plugin/lib/plugin.js +2 -2
  37. package/lib/antigravity-plugin/lib/services/history/history-capture.d.ts +4 -0
  38. package/lib/antigravity-plugin/lib/services/history/history-capture.js +86 -0
  39. package/lib/antigravity-plugin/lib/services/history/history-index.d.ts +17 -0
  40. package/lib/antigravity-plugin/lib/services/history/history-index.js +112 -0
  41. package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +12 -0
  42. package/lib/antigravity-plugin/lib/services/history/history-migrate.js +88 -0
  43. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
  44. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.js +121 -0
  45. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.d.ts +7 -0
  46. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.js +124 -0
  47. package/lib/antigravity-plugin/lib/services/history/summary-registry.d.ts +7 -0
  48. package/lib/antigravity-plugin/lib/services/history/summary-registry.js +36 -0
  49. package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +37 -0
  50. package/lib/antigravity-plugin/lib/services/history/summary-runner.js +301 -0
  51. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +5 -1
  52. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +75 -4
  53. package/lib/antigravity-plugin/lib/storage/file-access.d.ts +2 -0
  54. package/lib/antigravity-plugin/lib/storage/file-access.js +26 -0
  55. package/lib/antigravity-plugin/lib/storage/history-files.d.ts +54 -0
  56. package/lib/antigravity-plugin/lib/storage/history-files.js +467 -0
  57. package/lib/antigravity-plugin/lib/storage/history-format.d.ts +6 -0
  58. package/lib/antigravity-plugin/lib/storage/history-format.js +62 -0
  59. package/lib/antigravity-plugin/package.json +1 -1
  60. package/lib/antigravity-plugin/plugin.json +1 -1
  61. package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +22 -12
  62. package/lib/claude.js +2 -2
  63. package/lib/client.js +21 -11
  64. package/lib/dsh.js +4 -4
  65. package/lib/extension/{acp-member.d.ts → acp/member.d.ts} +5 -5
  66. package/lib/extension/{acp-member.js → acp/member.js} +6 -6
  67. package/lib/extension/acp/worker.d.ts +1 -0
  68. package/lib/extension/acp/worker.js +384 -0
  69. package/lib/extension/acp-worker.js +156 -11
  70. package/lib/extension/{dsh → hosts/dsh}/acp-member.js +8 -8
  71. package/lib/extension/hosts/dsh/command.js +92 -0
  72. package/lib/extension/{dsh → hosts/dsh}/files.js +3 -3
  73. package/lib/extension/hosts/dsh/history.d.ts +4 -0
  74. package/lib/extension/hosts/dsh/history.js +62 -0
  75. package/lib/extension/{dsh → hosts/dsh}/management.d.ts +1 -1
  76. package/lib/extension/{dsh → hosts/dsh}/management.js +12 -10
  77. package/lib/extension/{dsh → hosts/dsh}/workspace.d.ts +3 -9
  78. package/lib/extension/{dsh → hosts/dsh}/workspace.js +32 -70
  79. package/lib/extension/{plugin-runtime.d.ts → hosts/plugin-runtime.d.ts} +2 -2
  80. package/lib/extension/{plugin-runtime.js → hosts/plugin-runtime.js} +34 -8
  81. package/lib/extension/{mcp-bridge.d.ts → mcp/bridge.d.ts} +1 -1
  82. package/lib/extension/{mcp-bridge.js → mcp/bridge.js} +4 -4
  83. package/lib/extension/{mcp-workers.d.ts → mcp/workers.d.ts} +222 -2
  84. package/lib/extension/{mcp-workers.js → mcp/workers.js} +229 -63
  85. package/lib/extension/mcp.js +1113 -78
  86. package/lib/extension/{setup-cli.js → setup/cli.js} +9 -9
  87. package/lib/integrations/acp/connection.d.ts +11 -10
  88. package/lib/integrations/acp/connection.js +6 -0
  89. package/lib/integrations/acp/harnesses/claude.js +1 -1
  90. package/lib/integrations/acp/harnesses/dsh.js +1 -1
  91. package/lib/integrations/acp/history-summary.d.ts +17 -0
  92. package/lib/integrations/acp/history-summary.js +100 -0
  93. package/lib/integrations/agent-resources.d.ts +1 -0
  94. package/lib/integrations/agent-resources.js +5 -1
  95. package/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
  96. package/lib/integrations/hosts/antigravity/adapter.js +171 -0
  97. package/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
  98. package/lib/integrations/hosts/{claude.js → claude/adapter.js} +32 -4
  99. package/lib/integrations/{dsh → hosts/dsh}/mcp.d.ts +1 -1
  100. package/lib/integrations/{dsh → hosts/dsh}/resources.d.ts +1 -1
  101. package/lib/integrations/{dsh → hosts/dsh}/resources.js +4 -4
  102. package/lib/integrations/{dsh → hosts/dsh}/schema.js +1 -1
  103. package/lib/integrations/{dsh → hosts/dsh}/skills.js +1 -1
  104. package/lib/integrations/hosts/{registry.js → plugin-registry.js} +2 -2
  105. package/lib/integrations/installation/pi-setup.js +1 -1
  106. package/lib/model/history.d.ts +133 -34
  107. package/lib/model/plugin-host.d.ts +26 -0
  108. package/lib/model/workspace-config.d.ts +25 -0
  109. package/lib/plugin.js +2 -2
  110. package/lib/services/agents/agent-run.d.ts +1 -1
  111. package/lib/services/history/history-capture.d.ts +4 -0
  112. package/lib/services/history/history-capture.js +86 -0
  113. package/lib/services/history/history-index.d.ts +16 -7
  114. package/lib/services/history/history-index.js +48 -70
  115. package/lib/services/history/history-migrate.d.ts +12 -0
  116. package/lib/services/history/history-migrate.js +88 -0
  117. package/lib/services/history/history-query.d.ts +51 -0
  118. package/lib/services/history/history-query.js +371 -0
  119. package/lib/services/history/summary-command.d.ts +20 -0
  120. package/lib/services/history/summary-command.js +68 -0
  121. package/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
  122. package/lib/services/history/summary-dimensions/monthly.js +121 -0
  123. package/lib/services/history/summary-dimensions/session.d.ts +7 -0
  124. package/lib/services/history/summary-dimensions/session.js +124 -0
  125. package/lib/services/history/summary-registry.d.ts +7 -0
  126. package/lib/services/history/summary-registry.js +36 -0
  127. package/lib/services/history/summary-runner.d.ts +37 -0
  128. package/lib/services/history/summary-runner.js +301 -0
  129. package/lib/services/workspace/workspace-config.d.ts +5 -1
  130. package/lib/services/workspace/workspace-config.js +75 -4
  131. package/lib/storage/history-files.d.ts +45 -9
  132. package/lib/storage/history-files.js +373 -247
  133. package/lib/storage/history-format.d.ts +3 -12
  134. package/lib/storage/history-format.js +26 -50
  135. package/lib/tools/history/actions.d.ts +3 -68
  136. package/lib/tools/history/actions.js +7 -5
  137. package/lib/tools/history/contract.d.ts +14 -7
  138. package/lib/tools/history/contract.js +58 -18
  139. package/lib/tools/history/dsh-tool.d.ts +1 -2
  140. package/lib/tools/history/dsh-tool.js +11 -5
  141. package/lib/ui/dsh/management.js +18 -5
  142. package/package.json +1 -1
  143. package/resources/prompts/history-coordinator.md +1 -1
  144. package/resources/prompts/history-monthly-summary.md +13 -0
  145. package/resources/prompts/history-summary.md +10 -4
  146. package/resources/skills/provider-connections/SKILL.md +22 -12
  147. package/src/claude.ts +2 -2
  148. package/src/dsh.ts +4 -4
  149. package/src/extension/{acp-member.ts → acp/member.ts} +7 -7
  150. package/src/extension/{acp-worker.ts → acp/worker.ts} +131 -17
  151. package/src/extension/{dsh → hosts/dsh}/acp-member.ts +9 -9
  152. package/src/extension/hosts/dsh/command.ts +92 -0
  153. package/src/extension/{dsh → hosts/dsh}/files.ts +3 -3
  154. package/src/extension/hosts/dsh/history.ts +67 -0
  155. package/src/extension/{dsh → hosts/dsh}/management.ts +11 -9
  156. package/src/extension/{dsh → hosts/dsh}/workspace.ts +31 -50
  157. package/src/extension/{pi-acp-member.ts → hosts/pi/acp-member.ts} +9 -9
  158. package/src/extension/hosts/pi/command.ts +158 -0
  159. package/src/extension/{events.ts → hosts/pi/events.ts} +14 -4
  160. package/src/extension/hosts/pi/history.ts +45 -0
  161. package/src/extension/{lifecycle.ts → hosts/pi/lifecycle.ts} +7 -11
  162. package/src/extension/{plugin-runtime.ts → hosts/plugin-runtime.ts} +29 -9
  163. package/src/extension/{mcp-bridge.ts → mcp/bridge.ts} +5 -5
  164. package/src/extension/{mcp-workers.ts → mcp/workers.ts} +237 -64
  165. package/src/extension/{setup-cli.ts → setup/cli.ts} +11 -11
  166. package/src/integrations/acp/connection.ts +6 -0
  167. package/src/integrations/acp/harnesses/claude.ts +1 -1
  168. package/src/integrations/acp/harnesses/dsh.ts +1 -1
  169. package/src/integrations/acp/history-summary.ts +108 -0
  170. package/src/integrations/agent-resources.ts +6 -0
  171. package/src/integrations/hosts/antigravity/adapter.ts +161 -0
  172. package/src/integrations/hosts/{claude.ts → claude/adapter.ts} +28 -5
  173. package/src/integrations/{dsh → hosts/dsh}/mcp.ts +1 -1
  174. package/src/integrations/{dsh → hosts/dsh}/resources.ts +5 -5
  175. package/src/integrations/{dsh → hosts/dsh}/schema.ts +1 -1
  176. package/src/integrations/{dsh → hosts/dsh}/session.ts +2 -2
  177. package/src/integrations/{dsh → hosts/dsh}/skills.ts +1 -1
  178. package/src/integrations/{pi → hosts/pi}/mcp.ts +1 -1
  179. package/src/integrations/{pi → hosts/pi}/skills.ts +1 -1
  180. package/src/integrations/hosts/{registry.ts → plugin-registry.ts} +2 -2
  181. package/src/integrations/installation/pi-setup.ts +1 -1
  182. package/src/mcp.ts +1 -1
  183. package/src/model/history.ts +151 -26
  184. package/src/model/plugin-host.ts +26 -2
  185. package/src/model/workspace-config.ts +30 -0
  186. package/src/pbot.ts +13 -22
  187. package/src/plugin.ts +2 -2
  188. package/src/services/history/history-capture.ts +83 -0
  189. package/src/services/history/history-index.ts +48 -62
  190. package/src/services/history/history-migrate.ts +89 -0
  191. package/src/services/history/history-query.ts +415 -0
  192. package/src/services/history/summary-command.ts +69 -0
  193. package/src/services/history/summary-dimensions/monthly.ts +139 -0
  194. package/src/services/history/summary-dimensions/session.ts +149 -0
  195. package/src/services/history/summary-registry.ts +44 -0
  196. package/src/services/history/summary-runner.ts +352 -0
  197. package/src/services/workspace/workspace-config.ts +93 -5
  198. package/src/storage/history-files.ts +408 -188
  199. package/src/storage/history-format.ts +46 -60
  200. package/src/tools/history/actions.ts +8 -6
  201. package/src/tools/history/contract.ts +65 -20
  202. package/src/tools/history/dsh-tool.ts +17 -8
  203. package/src/tools/history/pi-tool.ts +21 -0
  204. package/src/tools/register.ts +3 -4
  205. package/src/ui/dsh/management.ts +27 -11
  206. package/src/ui/{confirmation.ts → pi/confirmation.ts} +1 -1
  207. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.d.ts +0 -4
  208. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.js +0 -79
  209. package/lib/extension/dsh/command.js +0 -50
  210. package/lib/extension/dsh/history.d.ts +0 -15
  211. package/lib/extension/dsh/history.js +0 -87
  212. package/lib/integrations/dsh/history-summary.d.ts +0 -11
  213. package/lib/integrations/dsh/history-summary.js +0 -36
  214. package/lib/integrations/dsh/history.d.ts +0 -16
  215. package/lib/integrations/dsh/history.js +0 -167
  216. package/lib/integrations/history-summary.d.ts +0 -4
  217. package/lib/integrations/history-summary.js +0 -32
  218. package/lib/integrations/hosts/antigravity.d.ts +0 -4
  219. package/lib/integrations/hosts/antigravity.js +0 -79
  220. package/lib/services/history/history-service.d.ts +0 -106
  221. package/lib/services/history/history-service.js +0 -242
  222. package/lib/storage/acp-history.d.ts +0 -10
  223. package/lib/storage/acp-history.js +0 -57
  224. package/src/extension/command.ts +0 -76
  225. package/src/extension/dsh/command.ts +0 -54
  226. package/src/extension/dsh/history.ts +0 -74
  227. package/src/extension/history.ts +0 -26
  228. package/src/integrations/dsh/history-summary.ts +0 -39
  229. package/src/integrations/dsh/history.ts +0 -84
  230. package/src/integrations/history-summary.ts +0 -30
  231. package/src/integrations/hosts/antigravity.ts +0 -83
  232. package/src/integrations/pi/history.ts +0 -99
  233. package/src/services/history/history-service.ts +0 -195
  234. package/src/storage/acp-history.ts +0 -49
  235. package/src/tools/history/tool.ts +0 -19
  236. /package/lib/antigravity-plugin/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +0 -0
  237. /package/lib/{extension/acp-worker.d.ts → antigravity-plugin/lib/model/history.js} +0 -0
  238. /package/lib/extension/{dsh → hosts/dsh}/acp-member.d.ts +0 -0
  239. /package/lib/extension/{dsh → hosts/dsh}/command.d.ts +0 -0
  240. /package/lib/extension/{dsh → hosts/dsh}/files.d.ts +0 -0
  241. /package/lib/extension/{setup-guard.js → setup/guard.js} +0 -0
  242. /package/lib/integrations/acp/{claude.d.ts → claude-settings.d.ts} +0 -0
  243. /package/lib/integrations/acp/{claude.js → claude-settings.js} +0 -0
  244. /package/lib/integrations/{dsh → hosts/dsh}/mcp.js +0 -0
  245. /package/lib/integrations/{dsh → hosts/dsh}/messages.d.ts +0 -0
  246. /package/lib/integrations/{dsh → hosts/dsh}/messages.js +0 -0
  247. /package/lib/integrations/{dsh → hosts/dsh}/root-agents.d.ts +0 -0
  248. /package/lib/integrations/{dsh → hosts/dsh}/root-agents.js +0 -0
  249. /package/lib/integrations/{dsh → hosts/dsh}/schema.d.ts +0 -0
  250. /package/lib/integrations/{dsh → hosts/dsh}/skills.d.ts +0 -0
  251. /package/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +0 -0
  252. /package/src/extension/{setup-guard.ts → setup/guard.ts} +0 -0
  253. /package/src/integrations/acp/{claude.ts → claude-settings.ts} +0 -0
  254. /package/src/integrations/{dsh → hosts/dsh}/messages.ts +0 -0
  255. /package/src/integrations/{dsh → hosts/dsh}/root-agents.ts +0 -0
  256. /package/src/integrations/{pi → hosts/pi}/agent-tools.ts +0 -0
@@ -1,3 +1,8 @@
1
+ import type { HistoryLayout } from "./workspace-config.js";
2
+
3
+ export type { HistoryLayout };
4
+ export type HistoryHost = string;
5
+
1
6
  export interface HistoryExchange {
2
7
  entryIds: string[];
3
8
  text: string;
@@ -5,6 +10,7 @@ export interface HistoryExchange {
5
10
  to: string;
6
11
  completed: boolean;
7
12
  }
13
+
8
14
  export interface HistorySession {
9
15
  sessionId: string;
10
16
  name: string;
@@ -12,48 +18,167 @@ export interface HistorySession {
12
18
  /** Earlier partial observations replaced along the same native branch or turn; never persisted. */
13
19
  supersededEntryIds?: string[];
14
20
  }
21
+
15
22
  export interface HistoryIdentity {
16
23
  host: HistoryHost;
17
24
  id: string;
18
25
  sessionId: string;
19
26
  }
27
+
20
28
  export interface RawHistory extends HistoryIdentity {
21
29
  name: string;
22
30
  /** One entry per archived exchange; array order does not describe a conversation. */
23
31
  exchanges: (HistoryExchange & { id: string })[];
24
- /** Ordered paths observed in the native source. Legacy exchanges can have no known path. */
32
+ /** Ordered paths observed in the native source. */
25
33
  branches: string[][];
26
34
  }
27
- export interface HistorySummary extends HistoryExchange {
28
- id: string;
29
- level: number;
30
- children: string[];
31
- ready: boolean;
32
- }
33
- export interface HistoryArchive {
34
- raw: RawHistory;
35
- /** Empty if absent; null if the derived file is unreadable. */
36
- summaries: HistorySummary[] | null;
37
- }
38
- export interface HistoryNode extends HistorySummary {
39
- kind: "session" | "exchange" | "summary";
40
- parents: string[];
41
- }
42
- /** Query view and legacy on-disk format. New writers persist raw exchanges and summaries separately. */
43
- export interface HistoryRecord extends HistoryIdentity {
44
- name: string;
45
- nodes: HistoryNode[];
35
+
36
+ export interface SummarySource {
37
+ rawIds: string[];
38
+ exchangeIds: string[];
39
+ fingerprint: string;
46
40
  }
47
- export type HistoryHost = "pi" | "dsh" | "claude";
48
- export type HistoryLocation = { host: "pi"; directory: string; file?: string } |
49
- { host: "dsh"; sessionId?: string };
50
- export interface HistorySource {
51
- readonly host: HistoryLocation["host"];
52
- scan(location: HistoryLocation, signal?: AbortSignal, excluded?: ReadonlySet<string>): Promise<{ sessions: HistorySession[]; warnings: string[] }>;
41
+
42
+ export interface SummaryArtifact {
43
+ id: string;
44
+ dimension: string;
45
+ host?: HistoryHost;
46
+ sessionId?: string;
47
+ title: string;
48
+ text: string;
49
+ from: string;
50
+ to: string;
51
+ updatedAt: string;
52
+ source: SummarySource;
53
53
  }
54
+
54
55
  export interface HistorySummaryRequest {
55
56
  system: string;
56
57
  prompt: string;
57
58
  maxTokens: number;
58
59
  }
60
+
59
61
  export type HistorySummarizer = (request: HistorySummaryRequest, signal: AbortSignal) => Promise<string>;
62
+
63
+ export type SummaryTaskMode = "create" | "incremental" | "rebuild";
64
+
65
+ export interface SummaryTask {
66
+ id: string;
67
+ dimension: string;
68
+ mode: SummaryTaskMode;
69
+ title: string;
70
+ host?: HistoryHost;
71
+ sessionId?: string;
72
+ from: string;
73
+ to: string;
74
+ source: SummarySource;
75
+ exchanges: readonly (HistoryExchange & { id: string })[];
76
+ existing?: SummaryArtifact;
77
+ addedExchanges?: readonly (HistoryExchange & { id: string })[];
78
+ sourceSummaries?: readonly SummaryArtifact[];
79
+ }
80
+
81
+ export interface SummaryPlanOptions {
82
+ force?: boolean;
83
+ summariesByDimension?: ReadonlyMap<string, ReadonlyMap<string, SummaryArtifact>>;
84
+ }
85
+
86
+ export interface SummaryPlanResult {
87
+ tasks: SummaryTask[];
88
+ skipped: number;
89
+ }
90
+
91
+ export interface SummaryDimension {
92
+ readonly id: string;
93
+ readonly title: string;
94
+ readonly description: string;
95
+ readonly requiresMonthlyLayout?: boolean;
96
+ plan(
97
+ raws: readonly RawHistory[],
98
+ existing: ReadonlyMap<string, SummaryArtifact>,
99
+ options?: SummaryPlanOptions,
100
+ ): SummaryPlanResult;
101
+ buildRequest(task: SummaryTask): HistorySummaryRequest;
102
+ finalize(task: SummaryTask, output: string, now: string): SummaryArtifact;
103
+ }
104
+
105
+ export interface HistoryMigrationItem {
106
+ kind: "raw" | "summary";
107
+ dimension?: string;
108
+ id: string;
109
+ from: string;
110
+ to: string;
111
+ }
112
+
113
+ export interface HistoryMigrationConflict {
114
+ kind: "raw" | "summary";
115
+ dimension?: string;
116
+ from: string;
117
+ to: string;
118
+ reason: string;
119
+ }
120
+
121
+ export interface HistoryMigrationReport {
122
+ layout: HistoryLayout;
123
+ dryRun: boolean;
124
+ moved: HistoryMigrationItem[];
125
+ skipped: HistoryMigrationConflict[];
126
+ errors: { path: string; error: string }[];
127
+ }
128
+
129
+ export interface SummaryDimensionStatus {
130
+ dimension: string;
131
+ title: string;
132
+ description: string;
133
+ total: number;
134
+ ready: number;
135
+ pendingCreate: number;
136
+ pendingIncremental: number;
137
+ pendingRebuild: number;
138
+ }
139
+
140
+ export interface HistorySummaryReminder {
141
+ rawCount: number;
142
+ pendingCount: number;
143
+ oldestRawAt: string;
144
+ latestSummaryAt?: string;
145
+ rawAgeDays: number;
146
+ daysSinceLastSummary?: number;
147
+ thresholdDays: number;
148
+ message: string;
149
+ }
150
+
151
+ export interface SummaryRunProgress {
152
+ dimension: string;
153
+ completed: number;
154
+ total: number;
155
+ currentId: string;
156
+ mode: SummaryTaskMode;
157
+ }
158
+
159
+ export interface SummaryDimensionReport {
160
+ dimension: string;
161
+ scanned: number;
162
+ skipped: number;
163
+ created: number;
164
+ incremental: number;
165
+ rebuilt: number;
166
+ failed: { id: string; error: string }[];
167
+ }
168
+
169
+ export interface SummaryRunReport {
170
+ dimensions: SummaryDimensionReport[];
171
+ durationMs: number;
172
+ warnings: string[];
173
+ }
174
+
175
+ export interface HistoryQuery {
176
+ host?: HistoryHost;
177
+ query?: string;
178
+ sessionId?: string;
179
+ dimension?: string;
180
+ from?: string;
181
+ to?: string;
182
+ offset?: number;
183
+ limit?: number;
184
+ }
@@ -1,3 +1,4 @@
1
+ import type { HistorySession } from "./history.js";
1
2
  import type { WorkspaceSkillMeta } from "./workspace-mcp.js";
2
3
 
3
4
  export type HostId = string;
@@ -19,10 +20,32 @@ export interface WorkspaceContext {
19
20
  text: string;
20
21
  }
21
22
 
23
+ export type HistoryCapture =
24
+ | {
25
+ kind: "input";
26
+ sessionId: string;
27
+ text: string;
28
+ timestamp?: string;
29
+ }
30
+ | {
31
+ kind: "answer";
32
+ sessionId: string;
33
+ userText?: string;
34
+ assistantText: string;
35
+ completed: boolean;
36
+ isContinuation?: boolean;
37
+ timestamp?: string;
38
+ }
39
+ | {
40
+ kind: "session";
41
+ session: HistorySession;
42
+ };
43
+
22
44
  export type HostEvent =
23
45
  | { kind: "ignore" }
24
- | { kind: "inject-context"; role: WorkspaceRole; localRoleOnly?: boolean; cwd: string; raw: unknown }
25
- | { kind: "check-skill"; skill: string; cwd: string; raw: unknown };
46
+ | { kind: "inject-context"; role: WorkspaceRole; localRoleOnly?: boolean; isSessionStart?: boolean; cwd: string; raw: unknown }
47
+ | { kind: "check-skill"; skill: string; cwd: string; raw: unknown }
48
+ | { kind: "record-history"; cwd: string; raw: unknown };
26
49
 
27
50
  export interface PluginHostAdapter {
28
51
  readonly host: PluginHostId;
@@ -33,6 +56,7 @@ export interface PluginHostAdapter {
33
56
  readonly usage: string;
34
57
  resolveRoot(cwd: string, rawPayload?: unknown): Promise<string>;
35
58
  parseEvent(payload: unknown): HostEvent;
59
+ extractHistory?(event: Extract<HostEvent, { kind: "inject-context" | "record-history" }>): Promise<HistoryCapture | undefined>;
36
60
  formatPass(payload: unknown): Record<string, unknown>;
37
61
  formatContext(event: Extract<HostEvent, { kind: "inject-context" }>, context: WorkspaceContext): Record<string, unknown>;
38
62
  formatDeny(event: Extract<HostEvent, { kind: "check-skill" }>, reason: string): Record<string, unknown>;
@@ -4,18 +4,46 @@ export interface WorkspaceFeatures {
4
4
  prompts?: boolean;
5
5
  skills?: boolean;
6
6
  mcp?: boolean;
7
+ history?: boolean;
7
8
  }
8
9
 
9
10
  export interface ResolvedWorkspaceFeatures {
10
11
  readonly prompts: boolean;
11
12
  readonly skills: boolean;
12
13
  readonly mcp: boolean;
14
+ readonly history: boolean;
15
+ }
16
+
17
+ export interface WorkspaceSummaryConfig {
18
+ backend?: string;
19
+ model?: string;
20
+ thinking?: string;
21
+ concurrency?: number;
22
+ }
23
+
24
+ export interface ResolvedWorkspaceSummaryConfig {
25
+ readonly backend: string;
26
+ readonly model?: string;
27
+ readonly thinking?: string;
28
+ readonly concurrency: number;
29
+ }
30
+
31
+ export type HistoryLayout = "monthly" | "flat";
32
+
33
+ export interface WorkspaceHistoryConfig {
34
+ layout?: HistoryLayout;
35
+ }
36
+
37
+ export interface ResolvedWorkspaceHistoryConfig {
38
+ readonly layout: HistoryLayout;
13
39
  }
14
40
 
15
41
  export interface WorkspaceConfig {
16
42
  enabled?: boolean;
17
43
  features?: WorkspaceFeatures;
18
44
  acp?: AcpCommands;
45
+ summary?: WorkspaceSummaryConfig;
46
+ history?: WorkspaceHistoryConfig;
19
47
  }
20
48
 
21
49
  export interface WorkspaceConfiguration {
@@ -25,4 +53,6 @@ export interface WorkspaceConfiguration {
25
53
  error?: string;
26
54
  features?: WorkspaceFeatures;
27
55
  acp?: AcpCommands;
56
+ summary?: WorkspaceSummaryConfig;
57
+ history?: WorkspaceHistoryConfig;
28
58
  }
package/src/pbot.ts CHANGED
@@ -1,21 +1,17 @@
1
1
  import { existsSync } from "node:fs";
2
- import { join, resolve } from "node:path";
2
+ import { resolve } from "node:path";
3
3
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
4
  import { resourceRoot } from "./common/paths.js";
5
- import { Confirmations } from "./ui/confirmation.js";
5
+ import { Confirmations } from "./ui/pi/confirmation.js";
6
6
  import { ToolRegistry, mainTools } from "./tools/register.js";
7
- import { Lifecycle, WorkspaceInstance } from "./extension/lifecycle.js";
8
- import { registerCommand } from "./extension/command.js";
9
- import { registerEvents } from "./extension/events.js";
10
- import { registerHistoryEvents } from "./extension/history.js";
11
- import { McpWorkerRuntime, defaultWorkerDirectory } from "./extension/mcp-workers.js";
12
- import { HistoryService } from "./services/history/history-service.js";
7
+ import { Lifecycle, WorkspaceInstance } from "./extension/hosts/pi/lifecycle.js";
8
+ import { registerCommand } from "./extension/hosts/pi/command.js";
9
+ import { registerEvents } from "./extension/hosts/pi/events.js";
10
+ import { registerHistoryEvents } from "./extension/hosts/pi/history.js";
11
+ import { McpWorkerRuntime, defaultWorkerDirectory } from "./extension/mcp/workers.js";
13
12
  import { workspaceFeatures } from "./services/workspace/workspace-config.js";
14
13
  import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "./services/workspace/workspace-mcp.js";
15
- import { HistoryFiles } from "./storage/history-files.js";
16
- import { PiHistory } from "./integrations/pi/history.js";
17
- import { toPiMcpConfig } from "./integrations/pi/mcp.js";
18
- import { acpHistorySessions } from "./storage/acp-history.js";
14
+ import { toPiMcpConfig } from "./integrations/hosts/pi/mcp.js";
19
15
 
20
16
  const mcpServerName = "pbot";
21
17
 
@@ -31,17 +27,10 @@ export default function pbot(pi: ExtensionAPI) {
31
27
  (root, sessionId, configuration) => {
32
28
  const workerDir = defaultWorkerDirectory();
33
29
  const workers = new McpWorkerRuntime(workerDir, sessionId, "pi");
34
- const history = new HistoryService(
35
- root,
36
- new HistoryFiles(join(root, ".pbot/history"), "pi"),
37
- new PiHistory(root),
38
- [new HistoryFiles(join(root, ".pbot/history"), "dsh"), new HistoryFiles(join(root, ".pbot/history"), "claude")],
39
- () => acpHistorySessions({ mcp: workerDir }),
40
- );
41
- return new WorkspaceInstance(root, sessionId, history, workers, workspaceFeatures(configuration));
30
+ return new WorkspaceInstance(root, sessionId, workers, workspaceFeatures(configuration));
42
31
  },
43
32
  async instance => {
44
- registry.register(mainTools(instance.history, instance));
33
+ if (instance.features.history) registry.register(mainTools(instance.root, instance));
45
34
  if (existsSync(mcpEntry)) {
46
35
  pi.registerMcpServer(mcpServerName, {
47
36
  type: "stdio",
@@ -52,10 +41,12 @@ export default function pbot(pi: ExtensionAPI) {
52
41
  PBOT_WORKSPACE_ROOT: instance.root,
53
42
  PBOT_MCP_AGENT_DIR: defaultWorkerDirectory(),
54
43
  PBOT_MCP_SESSION_ID: instance.sessionId,
44
+ PBOT_NATIVE_WORKSPACE_MCP: "1",
45
+ PBOT_NATIVE_HISTORY: "1",
55
46
  },
56
47
  exposure: "direct",
57
48
  timeout: 600,
58
- description: "跨代理程序委派(worker_*)与工作区统一 MCP 桥接(workspace_mcp_*)",
49
+ description: "跨代理程序委派(worker_*)",
59
50
  });
60
51
  registeredMcpServers.push(mcpServerName);
61
52
  }
package/src/plugin.ts 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
 
7
7
  export async function main(args: readonly string[]): Promise<void> {
8
8
  const [host, ...rest] = args;
@@ -0,0 +1,83 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { join } from "node:path";
3
+ import { isDeepStrictEqual } from "node:util";
4
+ import type { HistoryExchange, HistoryHost, HistorySession, RawHistory } from "../../model/history.js";
5
+ import type { HistoryCapture } from "../../model/plugin-host.js";
6
+ import { HistoryFiles } from "../../storage/history-files.js";
7
+ import { readWorkspaceHistoryLayoutSync } from "../workspace/workspace-config.js";
8
+ import { indexHistory, orderedRawExchanges } from "./history-index.js";
9
+
10
+ function orderedExchanges(raw?: RawHistory): HistoryExchange[] {
11
+ if (!raw) return [];
12
+ return orderedRawExchanges(raw).map(({ entryIds, text, from, to, completed }) => ({
13
+ entryIds: [...entryIds],
14
+ text,
15
+ from,
16
+ to,
17
+ completed,
18
+ }));
19
+ }
20
+
21
+ function replaceAssistantSuffix(text: string, assistantText: string): string {
22
+ const marker = "\n\n助手:\n";
23
+ const index = text.lastIndexOf(marker);
24
+ if (index >= 0) return text.slice(0, index) + marker + assistantText;
25
+ return text ? `${text}${marker}${assistantText}` : `助手:\n${assistantText}`;
26
+ }
27
+
28
+ function buildSession(host: HistoryHost, capture: HistoryCapture, previous?: RawHistory): HistorySession | undefined {
29
+ if (capture.kind === "session") {
30
+ return capture.session.branches.length ? capture.session : undefined;
31
+ }
32
+ const timestamp = capture.timestamp ?? new Date().toISOString();
33
+ const branch = orderedExchanges(previous);
34
+ if (capture.kind === "input") {
35
+ const text = capture.text.trim();
36
+ if (!text) return undefined;
37
+ const entryId = `${host}:${Date.now()}:${randomUUID().slice(0, 8)}`;
38
+ branch.push({
39
+ entryIds: [entryId],
40
+ text: "用户:\n" + text,
41
+ from: timestamp,
42
+ to: timestamp,
43
+ completed: false,
44
+ });
45
+ return { sessionId: capture.sessionId, name: previous?.name ?? "", branches: [branch] };
46
+ }
47
+ const assistantText = capture.assistantText.trim();
48
+ if (!assistantText) return undefined;
49
+ const last = branch.at(-1);
50
+ if (last && (!last.completed || capture.isContinuation)) {
51
+ last.text = replaceAssistantSuffix(last.text, assistantText);
52
+ last.to = timestamp;
53
+ last.completed = capture.completed;
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
+
68
+ /** Persist a host raw history observation atomically into .pbot/history/raw/. */
69
+ export function recordHistoryCapture(root: string, host: HistoryHost, capture: HistoryCapture): void {
70
+ const sessionId = capture.kind === "session" ? capture.session.sessionId : capture.sessionId;
71
+ if (!sessionId) 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) return;
77
+ const session = buildSession(host, capture, previous);
78
+ if (!session || !session.branches.length) return;
79
+ const raw = indexHistory(session, previous, host);
80
+ if (isDeepStrictEqual(raw, previous)) return;
81
+ files.saveRaw(raw);
82
+ });
83
+ }
@@ -1,6 +1,5 @@
1
- import { randomUUID } from "node:crypto";
2
- import { isDeepStrictEqual } from "node:util";
3
- import type { HistoryExchange, HistoryHost, HistoryNode, HistoryRecord, HistorySession, HistorySummary, RawHistory } from "../../model/history.js";
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import type { HistoryExchange, HistoryHost, HistorySession, RawHistory } from "../../model/history.js";
4
3
  import { requireThat } from "../../common/validation.js";
5
4
 
6
5
  /** Each native entry has one predecessor. A shortened observation can extend a known path, not erase its prefix. */
@@ -28,9 +27,9 @@ function mergeBranches(previous: string[][], observed: string[][], removed: Set<
28
27
  return branches;
29
28
  }
30
29
 
31
- /** Only a native observation can change exchanges or establish branch order. */
30
+ /** Merge a native session observation into its raw archive without modifying persisted order invariants. */
32
31
  export function indexHistory(session: HistorySession, previous?: RawHistory, host: HistoryHost = previous?.host ?? "pi"): RawHistory {
33
- requireThat(!previous || previous.host === host && previous.sessionId === session.sessionId, "历史会话与归档来源不匹配。");
32
+ requireThat(!previous || (previous.host === host && previous.sessionId === session.sessionId), "历史会话与归档来源不匹配。");
34
33
  const id = previous?.id ?? (host === "pi" ? "" : host + "-") + randomUUID();
35
34
  const exchanges = new Map(previous?.exchanges.map(item => [item.id, item]));
36
35
  const byEnd = new Map(previous?.exchanges.map(item => [item.entryIds.at(-1)!, item.id]));
@@ -57,69 +56,56 @@ export function indexHistory(session: HistorySession, previous?: RawHistory, hos
57
56
  removed.add(item.id); exchanges.delete(item.id);
58
57
  }
59
58
  }
60
- return { host, id, sessionId: session.sessionId, name: session.name, exchanges: [...exchanges.values()],
61
- branches: mergeBranches(previous?.branches ?? [], branches, removed) };
59
+ return {
60
+ host,
61
+ id,
62
+ sessionId: session.sessionId,
63
+ name: session.name,
64
+ exchanges: [...exchanges.values()],
65
+ branches: mergeBranches(previous?.branches ?? [], branches, removed),
66
+ };
62
67
  }
63
68
 
64
- function span(children: HistoryExchange[]) {
65
- const first = children[0]!, last = children.at(-1)!;
66
- return { entryIds: [first.entryIds[0]!, last.entryIds.at(-1)!], from: first.from, to: last.to, completed: children.every(child => child.completed) };
67
- }
68
-
69
- /** Retire results using changed inputs before publishing a native correction. New groups need no disk write. */
70
- export function retainHistorySummaries(before: RawHistory, after: RawHistory, summaries: HistorySummary[]): HistorySummary[] {
71
- const inputs = new Map<string, HistoryExchange>(after.exchanges.map(item => [item.id, item]));
72
- const changed = new Set(before.exchanges.filter(item => !isDeepStrictEqual(item, inputs.get(item.id))).map(item => item.id));
73
- if (!changed.size || !summaries.length) return summaries;
74
- const retained = new Map<string, HistorySummary>();
75
- for (const item of [...summaries].sort((a, b) => a.level - b.level)) {
76
- const children = item.children.map(id => inputs.get(id));
77
- if (!children.length || !children.every(child => child !== undefined)) { changed.add(item.id); continue; }
78
- let summary = item;
79
- if (item.children.some(id => changed.has(id))) {
80
- summary = { ...item, ...span(children), text: "", ready: false }; changed.add(item.id);
69
+ /** Return deduplicated exchanges in conversation order (branch order first, then any unbranched entries by timestamp). */
70
+ export function orderedRawExchanges(raw: RawHistory): (HistoryExchange & { id: string })[] {
71
+ const lookup = new Map(raw.exchanges.map(item => [item.id, item]));
72
+ const seen = new Set<string>();
73
+ const ordered: (HistoryExchange & { id: string })[] = [];
74
+ for (const branch of raw.branches) {
75
+ for (const id of branch) {
76
+ if (seen.has(id)) continue;
77
+ const item = lookup.get(id);
78
+ if (!item) continue;
79
+ seen.add(id);
80
+ ordered.push(item);
81
81
  }
82
- retained.set(item.id, summary); inputs.set(item.id, summary);
83
82
  }
84
- return summaries.flatMap(item => retained.get(item.id) ?? []);
83
+ const rest = raw.exchanges
84
+ .filter(item => !seen.has(item.id))
85
+ .sort((a, b) => a.from.localeCompare(b.from) || a.id.localeCompare(b.id));
86
+ ordered.push(...rest);
87
+ return ordered;
85
88
  }
86
89
 
87
- /** The four-way tree is a query view, never the source of native branch order. */
88
- export function historyView(raw: RawHistory, saved: readonly HistorySummary[] | null = []): HistoryRecord {
89
- const nodes = new Map<string, HistoryNode>(raw.exchanges.map(value => [value.id,
90
- { ...value, kind: "exchange", level: 0, ready: true, children: [], parents: [] }]));
91
- const stored = new Map(saved?.map(value => [value.id, value]));
92
- const groups = new Map<string, Pick<HistorySummary, "id" | "level" | "children">>(stored);
93
- for (const branch of raw.branches) {
94
- let layer = branch.map(id => ({ id, end: nodes.get(id)!.entryIds.at(-1)! }));
95
- for (let level = 1; layer.length >= 4; level++) {
96
- const next: typeof layer = [];
97
- for (let i = 0; i + 4 <= layer.length; i += 4) {
98
- const end = layer[i + 3]!.end, id = `${raw.id}:${level}:${end}`;
99
- groups.set(id, { id, level, children: layer.slice(i, i + 4).map(child => child.id) });
100
- next.push({ id, end });
101
- }
102
- layer = next;
103
- }
104
- }
105
- for (const group of [...groups.values()].sort((a, b) => a.level - b.level)) {
106
- const children = group.children.map(id => nodes.get(id));
107
- if (!children.length || !children.every(child => child !== undefined)) continue;
108
- const old = stored.get(group.id);
109
- const summary = old && isDeepStrictEqual(old.children, group.children) && (!old.ready || children.every(child => child.ready)) ? old :
110
- { ...group, ...span(children), text: "", ready: false };
111
- nodes.set(group.id, { ...summary, kind: "summary", parents: [] });
112
- }
113
- for (const node of nodes.values()) for (const child of node.children) nodes.get(child)!.parents.push(node.id);
114
- const top = [...nodes.values()].filter(node => !node.parents.length).sort((a, b) => a.from.localeCompare(b.from));
115
- for (const child of top) child.parents.push(raw.id);
116
- const dates = raw.exchanges.flatMap(item => [item.from, item.to]).sort();
117
- const name = raw.name || raw.exchanges[0]?.text.replace(/\s+/g, " ").slice(0, 80) || "";
118
- nodes.set(raw.id, { id: raw.id, kind: "session", level: -1, entryIds: [], text: name, ready: true,
119
- completed: raw.exchanges.every(item => item.completed), from: dates[0] ?? "", to: dates.at(-1) ?? "", parents: [], children: top.map(node => node.id) });
120
- return { host: raw.host, id: raw.id, sessionId: raw.sessionId, name, nodes: [...nodes.values()] };
90
+ export function rawSessionTitle(raw: RawHistory): string {
91
+ return raw.name.trim();
121
92
  }
122
93
 
123
- export function historySummaries(record: HistoryRecord): HistorySummary[] {
124
- return record.nodes.filter(node => node.kind === "summary").map(({ kind: _kind, parents: _parents, ...summary }) => summary);
94
+ export function rawSessionSpan(exchanges: readonly HistoryExchange[]): { from: string; to: string; completed: boolean } {
95
+ const dates = exchanges.flatMap(item => [item.from, item.to]).filter(Boolean).sort();
96
+ return {
97
+ from: dates[0] ?? "",
98
+ to: dates.at(-1) ?? "",
99
+ completed: exchanges.every(item => item.completed),
100
+ };
101
+ }
102
+
103
+ /** Stable SHA-256 fingerprint over ordered exchange contents for exact deduplication and prefix matching. */
104
+ export function fingerprintExchanges(exchanges: readonly (HistoryExchange & { id: string })[]): string {
105
+ const hash = createHash("sha256");
106
+ for (const item of exchanges) {
107
+ hash.update(JSON.stringify([item.id, item.entryIds, item.text, item.from, item.to, item.completed]));
108
+ hash.update("\n");
109
+ }
110
+ return hash.digest("hex");
125
111
  }