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.
Files changed (318) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +2 -1
  3. package/DISCLAIMER.md +17 -0
  4. package/LICENSE +21 -0
  5. package/README.md +15 -5
  6. package/README.zh-CN.md +15 -5
  7. package/bin/pbot-pi-acp.mjs +1 -1
  8. package/bin/pbot.mjs +22 -2
  9. package/docs/README.md +2 -0
  10. package/docs/architecture/design.md +16 -16
  11. package/docs/architecture/extensibility.md +29 -2
  12. package/docs/architecture/model-context.md +3 -2
  13. package/docs/architecture/principles.md +2 -2
  14. package/docs/guides/capabilities.md +1 -1
  15. package/docs/guides/cross-harness-workers.md +3 -1
  16. package/docs/guides/history.md +30 -7
  17. package/docs/guides/workspace-configuration.md +20 -3
  18. package/docs/hosts/antigravity.md +1 -1
  19. package/docs/hosts/claude-code.md +1 -1
  20. package/docs/hosts/codex-qoder.md +63 -0
  21. package/docs/maintainers/architecture-governance.md +78 -0
  22. package/lib/antigravity-plugin/DISCLAIMER.md +17 -0
  23. package/lib/antigravity-plugin/LICENSE +21 -0
  24. package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +36 -0
  25. package/lib/antigravity-plugin/lib/common/files.d.ts +2 -0
  26. package/lib/antigravity-plugin/lib/common/files.js +44 -0
  27. package/lib/antigravity-plugin/lib/common/validation.d.ts +4 -0
  28. package/lib/antigravity-plugin/lib/common/validation.js +8 -0
  29. package/lib/antigravity-plugin/lib/extension/acp/member.d.ts +18 -0
  30. package/lib/antigravity-plugin/lib/extension/acp/member.js +44 -0
  31. package/lib/antigravity-plugin/lib/extension/acp-worker.js +71 -45
  32. package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
  33. package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.js +22 -0
  34. package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.d.ts +4 -0
  35. package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.js +58 -0
  36. package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.d.ts +5 -0
  37. package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.js +67 -0
  38. package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.d.ts +3 -0
  39. package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +100 -0
  40. package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.d.ts +3 -1
  41. package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +37 -22
  42. package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.d.ts +6 -0
  43. package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.js +21 -0
  44. package/lib/antigravity-plugin/lib/extension/mcp.js +2577 -2255
  45. package/lib/antigravity-plugin/lib/extension/workspace-cli.js +20171 -0
  46. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +1 -1
  47. package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +7 -59
  48. package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.d.ts +2 -0
  49. package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.js +14 -0
  50. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.d.ts +4 -0
  51. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.js +28 -0
  52. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.d.ts +36 -0
  53. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.js +11 -0
  54. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.d.ts +6 -0
  55. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.js +47 -0
  56. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.d.ts +4 -0
  57. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.js +3 -0
  58. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.d.ts +8 -0
  59. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.js +31 -0
  60. package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
  61. package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.js +32 -0
  62. package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.d.ts +4 -0
  63. package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.js +23 -0
  64. package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.d.ts +1 -0
  65. package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.js +8 -1
  66. package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
  67. package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.js +76 -0
  68. package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
  69. package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.js +16 -0
  70. package/lib/antigravity-plugin/lib/model/acp.d.ts +7 -3
  71. package/lib/antigravity-plugin/lib/model/acp.js +8 -0
  72. package/lib/antigravity-plugin/lib/model/agent.d.ts +121 -0
  73. package/lib/antigravity-plugin/lib/model/agent.js +4 -0
  74. package/lib/antigravity-plugin/lib/model/history.d.ts +10 -0
  75. package/lib/antigravity-plugin/lib/model/history.js +4 -1
  76. package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +5 -0
  77. package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +8 -12
  78. package/lib/antigravity-plugin/lib/model/workspace-config.js +2 -1
  79. package/lib/antigravity-plugin/lib/plugin.d.ts +2 -1
  80. package/lib/antigravity-plugin/lib/plugin.js +2 -2
  81. package/lib/antigravity-plugin/lib/services/history/history-capture.js +34 -22
  82. package/lib/antigravity-plugin/lib/services/history/summary-registry.js +2 -3
  83. package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +2 -5
  84. package/lib/antigravity-plugin/lib/services/history/summary-runner.js +72 -74
  85. package/lib/antigravity-plugin/lib/services/history/workspace-history.d.ts +3 -0
  86. package/lib/antigravity-plugin/lib/services/history/workspace-history.js +6 -0
  87. package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +15 -0
  88. package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +126 -0
  89. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +9 -8
  90. package/lib/antigravity-plugin/lib/services/workspace/workspace-files.d.ts +2 -0
  91. package/lib/antigravity-plugin/lib/services/workspace/workspace-files.js +17 -0
  92. package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.d.ts +14 -0
  93. package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.js +193 -0
  94. package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.d.ts +1 -0
  95. package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.js +4 -2
  96. package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +11 -0
  97. package/lib/antigravity-plugin/lib/storage/acp-files.js +75 -0
  98. package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +31 -0
  99. package/lib/antigravity-plugin/lib/storage/agent-files.js +159 -0
  100. package/lib/antigravity-plugin/lib/storage/atomic-json.d.ts +3 -1
  101. package/lib/antigravity-plugin/lib/storage/atomic-json.js +43 -3
  102. package/lib/antigravity-plugin/lib/storage/history-files.d.ts +2 -1
  103. package/lib/antigravity-plugin/lib/storage/history-files.js +21 -15
  104. package/lib/antigravity-plugin/lib/storage/history-format.d.ts +2 -3
  105. package/lib/antigravity-plugin/lib/storage/history-format.js +5 -7
  106. package/lib/antigravity-plugin/package.json +1 -1
  107. package/lib/antigravity-plugin/plugin.json +1 -1
  108. package/lib/antigravity-plugin/resources/prompts/history-monthly-summary.md +13 -0
  109. package/lib/antigravity-plugin/resources/prompts/history-summary.md +13 -0
  110. package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -0
  111. package/lib/antigravity-plugin/resources/skills/.claude-plugin/plugin.json +4 -0
  112. package/lib/antigravity-plugin/resources/skills/project-maintenance/SKILL.md +35 -0
  113. package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +52 -0
  114. package/lib/antigravity-plugin/skills/pbot/SKILL.md +11 -1
  115. package/lib/client.js +22 -50
  116. package/lib/codex-marketplace/.agents/plugins/marketplace.json +17 -0
  117. package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +7 -0
  118. package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +17 -0
  119. package/lib/codex-marketplace/plugins/personal-bot/DISCLAIMER.md +17 -0
  120. package/lib/codex-marketplace/plugins/personal-bot/LICENSE +21 -0
  121. package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +37 -0
  122. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +9 -0
  123. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/agents/openai.yaml +2 -0
  124. package/lib/common/validation.d.ts +4 -0
  125. package/lib/common/validation.js +8 -0
  126. package/lib/dsh.js +2 -2
  127. package/lib/extension/acp/member.d.ts +1 -1
  128. package/lib/extension/acp-worker.js +71 -45
  129. package/lib/extension/history/command.d.ts +37 -0
  130. package/lib/extension/history/command.js +57 -0
  131. package/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
  132. package/lib/extension/hosts/dsh/acp-entry.js +22 -0
  133. package/lib/extension/hosts/dsh/acp-member.js +4 -18
  134. package/lib/extension/hosts/dsh/command.d.ts +1 -2
  135. package/lib/extension/hosts/dsh/command.js +5 -49
  136. package/lib/extension/hosts/dsh/workspace.js +13 -44
  137. package/lib/extension/hosts/pi/acp-member.d.ts +3 -0
  138. package/lib/extension/hosts/pi/acp-member.js +100 -0
  139. package/lib/extension/hosts/plugin-runtime.d.ts +3 -1
  140. package/lib/extension/hosts/plugin-runtime.js +37 -22
  141. package/lib/extension/hosts/workspace-mcp.d.ts +6 -0
  142. package/lib/extension/hosts/workspace-mcp.js +21 -0
  143. package/lib/extension/mcp/bridge.d.ts +6 -8
  144. package/lib/extension/mcp/bridge.js +66 -84
  145. package/lib/extension/mcp/tool-contract.d.ts +735 -0
  146. package/lib/extension/mcp/tool-contract.js +441 -0
  147. package/lib/extension/mcp/workers.d.ts +29 -742
  148. package/lib/extension/mcp/workers.js +75 -525
  149. package/lib/extension/mcp.js +2577 -2255
  150. package/lib/extension/setup/cli.js +15 -0
  151. package/lib/extension/setup/upgrade.js +153 -0
  152. package/lib/extension/workspace-cli.js +20171 -0
  153. package/lib/integrations/acp/agents.d.ts +2 -3
  154. package/lib/integrations/acp/harnesses/dsh.js +1 -1
  155. package/lib/integrations/acp/harnesses/presets.js +8 -0
  156. package/lib/integrations/acp/history-summary.js +2 -1
  157. package/lib/integrations/acp/launch.d.ts +2 -2
  158. package/lib/integrations/agent-resources.js +1 -1
  159. package/lib/integrations/hosts/claude/adapter.js +7 -59
  160. package/lib/integrations/hosts/codex/adapter.d.ts +2 -0
  161. package/lib/integrations/hosts/codex/adapter.js +14 -0
  162. package/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
  163. package/lib/integrations/hosts/pi/agent-tools.js +32 -0
  164. package/lib/integrations/hosts/pi/mcp.d.ts +4 -0
  165. package/lib/integrations/hosts/pi/mcp.js +23 -0
  166. package/lib/integrations/hosts/plugin-registry.d.ts +1 -0
  167. package/lib/integrations/hosts/plugin-registry.js +8 -1
  168. package/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
  169. package/lib/integrations/hosts/prompt-hooks.js +76 -0
  170. package/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
  171. package/lib/integrations/hosts/qoder/adapter.js +16 -0
  172. package/lib/integrations/installation/cli-update.js +146 -0
  173. package/lib/integrations/installation/upgraders/antigravity.js +67 -0
  174. package/lib/integrations/installation/upgraders/claude.js +123 -0
  175. package/lib/integrations/installation/upgraders/codex.js +73 -0
  176. package/lib/integrations/installation/upgraders/dsh.js +62 -0
  177. package/lib/integrations/installation/upgraders/pi.js +90 -0
  178. package/lib/integrations/installation/upgraders/qoder.js +67 -0
  179. package/lib/integrations/installation/upgraders/registry.js +40 -0
  180. package/lib/model/acp.d.ts +7 -3
  181. package/lib/model/acp.js +8 -0
  182. package/lib/model/agent.d.ts +18 -4
  183. package/lib/model/agent.js +4 -1
  184. package/lib/model/history.d.ts +10 -0
  185. package/lib/model/history.js +4 -1
  186. package/lib/model/installation.js +1 -0
  187. package/lib/model/plugin-host.d.ts +5 -0
  188. package/lib/model/workspace-config.d.ts +8 -12
  189. package/lib/model/workspace-config.js +2 -1
  190. package/lib/plugin.d.ts +2 -1
  191. package/lib/plugin.js +2 -2
  192. package/lib/qoder-plugin/.mcp.json +17 -0
  193. package/lib/qoder-plugin/.qoder-plugin/plugin.json +7 -0
  194. package/lib/qoder-plugin/DISCLAIMER.md +17 -0
  195. package/lib/qoder-plugin/LICENSE +21 -0
  196. package/lib/qoder-plugin/hooks/hooks.json +37 -0
  197. package/lib/qoder-plugin/skills/pbot/SKILL.md +9 -0
  198. package/lib/services/agents/agent-service.d.ts +15 -45
  199. package/lib/services/agents/agent-service.js +22 -3
  200. package/lib/services/history/history-capture.js +34 -22
  201. package/lib/services/history/history-migrate.js +26 -60
  202. package/lib/services/history/history-query.js +38 -57
  203. package/lib/services/history/summary-command.d.ts +1 -1
  204. package/lib/services/history/summary-command.js +8 -7
  205. package/lib/services/history/summary-registry.js +2 -3
  206. package/lib/services/history/summary-runner.d.ts +2 -5
  207. package/lib/services/history/summary-runner.js +72 -74
  208. package/lib/services/history/workspace-history.d.ts +3 -0
  209. package/lib/services/history/workspace-history.js +6 -0
  210. package/lib/services/installation/setup-service.js +4 -1
  211. package/lib/services/installation/upgrade-service.js +95 -0
  212. package/lib/services/workspace/plugin-releases.d.ts +15 -0
  213. package/lib/services/workspace/plugin-releases.js +126 -0
  214. package/lib/services/workspace/workspace-config.js +9 -8
  215. package/lib/services/workspace/workspace-mcp.js +22 -29
  216. package/lib/services/workspace/workspace-skills.d.ts +1 -0
  217. package/lib/services/workspace/workspace-skills.js +4 -2
  218. package/lib/storage/acp-files.js +7 -12
  219. package/lib/storage/agent-files.js +6 -5
  220. package/lib/storage/atomic-json.d.ts +3 -1
  221. package/lib/storage/atomic-json.js +43 -3
  222. package/lib/storage/history-files.d.ts +2 -1
  223. package/lib/storage/history-files.js +21 -15
  224. package/lib/storage/history-format.d.ts +2 -3
  225. package/lib/storage/history-format.js +5 -7
  226. package/lib/tools/history/contract.d.ts +3 -11
  227. package/lib/tools/history/contract.js +8 -7
  228. package/lib/ui/dsh/elements.d.ts +2 -5
  229. package/lib/ui/dsh/elements.js +3 -16
  230. package/lib/ui/dsh/management.js +9 -9
  231. package/lib/ui/dsh/styles.d.ts +1 -1
  232. package/lib/ui/dsh/styles.js +5 -33
  233. package/package.json +4 -1
  234. package/resources/antigravity/skills/pbot/SKILL.md +11 -1
  235. package/resources/claude/skills/pbot/SKILL.md +11 -1
  236. package/resources/plugin/skills/pbot/SKILL.md +9 -0
  237. package/resources/prompts/history-coordinator.md +1 -0
  238. package/resources/prompts/plugin-coordinator.md +1 -0
  239. package/scripts/README.md +3 -2
  240. package/src/common/validation.ts +10 -0
  241. package/src/dsh.ts +2 -2
  242. package/src/extension/history/command.ts +68 -0
  243. package/src/extension/hosts/dsh/acp-entry.ts +21 -0
  244. package/src/extension/hosts/dsh/acp-member.ts +4 -15
  245. package/src/extension/hosts/dsh/command.ts +6 -46
  246. package/src/extension/hosts/dsh/workspace.ts +12 -38
  247. package/src/extension/hosts/pi/acp-member.ts +4 -10
  248. package/src/extension/hosts/pi/command.ts +14 -63
  249. package/src/extension/hosts/pi/events.ts +2 -8
  250. package/src/extension/hosts/pi/lifecycle.ts +3 -2
  251. package/src/extension/hosts/plugin-runtime.ts +39 -19
  252. package/src/extension/hosts/workspace-mcp.ts +25 -0
  253. package/src/extension/mcp/bridge.ts +80 -80
  254. package/src/extension/mcp/tool-contract.ts +462 -0
  255. package/src/extension/mcp/workers.ts +81 -551
  256. package/src/extension/setup/cli.ts +11 -1
  257. package/src/extension/setup/upgrade.ts +158 -0
  258. package/src/extension/setup/workspace-cli.ts +167 -0
  259. package/src/integrations/acp/agents.ts +2 -3
  260. package/src/integrations/acp/harnesses/dsh.ts +1 -1
  261. package/src/integrations/acp/harnesses/presets.ts +8 -0
  262. package/src/integrations/acp/history-summary.ts +2 -1
  263. package/src/integrations/agent-resources.ts +1 -1
  264. package/src/integrations/hosts/claude/adapter.ts +7 -53
  265. package/src/integrations/hosts/codex/adapter.ts +16 -0
  266. package/src/integrations/hosts/plugin-registry.ts +9 -1
  267. package/src/integrations/hosts/prompt-hooks.ts +72 -0
  268. package/src/integrations/hosts/qoder/adapter.ts +19 -0
  269. package/src/integrations/installation/cli-update.ts +144 -0
  270. package/src/integrations/installation/pi-bridge.ts +1 -1
  271. package/src/integrations/installation/pi-setup.ts +1 -1
  272. package/src/integrations/installation/processes.ts +1 -1
  273. package/src/integrations/installation/upgraders/antigravity.ts +68 -0
  274. package/src/integrations/installation/upgraders/claude.ts +123 -0
  275. package/src/integrations/installation/upgraders/codex.ts +73 -0
  276. package/src/integrations/installation/upgraders/dsh.ts +63 -0
  277. package/src/integrations/installation/upgraders/pi.ts +87 -0
  278. package/src/integrations/installation/upgraders/qoder.ts +68 -0
  279. package/src/integrations/installation/upgraders/registry.ts +48 -0
  280. package/src/model/acp.ts +11 -3
  281. package/src/model/agent.ts +20 -4
  282. package/src/model/history.ts +5 -0
  283. package/src/model/installation.ts +86 -0
  284. package/src/model/plugin-host.ts +5 -1
  285. package/src/model/workspace-config.ts +6 -12
  286. package/src/pbot.ts +13 -32
  287. package/src/plugin.ts +3 -3
  288. package/src/services/agents/agent-service.ts +29 -17
  289. package/src/services/history/history-capture.ts +30 -22
  290. package/src/services/history/history-migrate.ts +23 -50
  291. package/src/services/history/history-query.ts +34 -48
  292. package/src/services/history/summary-command.ts +9 -8
  293. package/src/services/history/summary-registry.ts +2 -3
  294. package/src/services/history/summary-runner.ts +72 -81
  295. package/src/services/history/workspace-history.ts +8 -0
  296. package/src/services/installation/setup-service.ts +9 -43
  297. package/src/services/installation/upgrade-service.ts +127 -0
  298. package/src/services/workspace/plugin-releases.ts +121 -0
  299. package/src/services/workspace/workspace-config.ts +9 -8
  300. package/src/services/workspace/workspace-mcp.ts +23 -28
  301. package/src/services/workspace/workspace-skills.ts +5 -2
  302. package/src/storage/acp-files.ts +7 -12
  303. package/src/storage/agent-files.ts +6 -5
  304. package/src/storage/atomic-json.ts +31 -4
  305. package/src/storage/history-files.ts +22 -15
  306. package/src/storage/history-format.ts +6 -8
  307. package/src/tools/history/contract.ts +9 -9
  308. package/src/tools/history/pi-tool.ts +6 -4
  309. package/src/ui/dsh/elements.ts +5 -12
  310. package/src/ui/dsh/management.ts +10 -10
  311. package/src/ui/dsh/styles.ts +5 -33
  312. package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +0 -12
  313. package/lib/antigravity-plugin/lib/services/history/history-migrate.js +0 -88
  314. package/lib/ui/presentation.d.ts +0 -3
  315. package/lib/ui/presentation.js +0 -12
  316. package/src/tools/access.ts +0 -7
  317. package/src/tools/register.ts +0 -21
  318. package/src/ui/presentation.ts +0 -12
@@ -0,0 +1,121 @@
1
+ import type { AcpBackend, AcpElicitationAction, AcpElicitationContent, AcpModelSelection, AcpSessionReference, AcpStartOptions } from "./acp.js";
2
+ export type AgentOptions = AcpStartOptions;
3
+ export interface AgentStartOptions extends AgentOptions {
4
+ backend: AcpBackend;
5
+ }
6
+ export interface AgentOwner {
7
+ sessionId: string;
8
+ leaf: string | null;
9
+ branch: string[];
10
+ }
11
+ export interface AgentDescriptor {
12
+ agentId: string;
13
+ release: string;
14
+ workspace: string;
15
+ cwd: string;
16
+ parentSessionId: string;
17
+ parentLeaf: string | null;
18
+ createdAt: number;
19
+ options: AgentOptions;
20
+ }
21
+ export type AgentSessionReference = AcpSessionReference;
22
+ export interface AgentLaunch {
23
+ generation: string;
24
+ name: string;
25
+ sequence: number;
26
+ stop: boolean;
27
+ startedAt: number;
28
+ }
29
+ export declare const messageDeliveries: readonly ["steer", "followUp"];
30
+ export declare const cycleStates: readonly ["running", "completed", "failed", "cancelled", "interrupted"];
31
+ export declare const cycleSources: readonly ["parent", "interactive", "mixed"];
32
+ export declare const agentStates: readonly ["starting", "busy", "idle", "stopping", "stopped", "error"];
33
+ export interface AgentMessage {
34
+ requestId: string;
35
+ generation: string;
36
+ sequence: number;
37
+ message: string;
38
+ delivery: typeof messageDeliveries[number];
39
+ files: string[];
40
+ }
41
+ export interface AgentCycle {
42
+ cycleId: string;
43
+ generation: string;
44
+ startedAt: number;
45
+ finishedAt?: number;
46
+ state: typeof cycleStates[number];
47
+ leaf: string | null;
48
+ requestIds: string[];
49
+ source: typeof cycleSources[number];
50
+ error?: string;
51
+ }
52
+ export interface AgentStatus {
53
+ generation: string;
54
+ state: typeof agentStates[number];
55
+ activity: string;
56
+ updatedAt: number;
57
+ accepted?: string[];
58
+ cycle?: AgentCycle;
59
+ error?: string;
60
+ }
61
+ export interface AgentView extends AgentDescriptor {
62
+ name: string;
63
+ generation: string;
64
+ state: AgentStatus["state"];
65
+ activity: string;
66
+ alive: boolean;
67
+ backend: AcpBackend;
68
+ transport: "acp";
69
+ selection?: AcpModelSelection;
70
+ capabilities: {
71
+ steer: boolean;
72
+ resume: boolean;
73
+ transcript: boolean;
74
+ };
75
+ cycle?: AgentCycle;
76
+ error?: string;
77
+ owned: boolean;
78
+ pendingRequests?: AgentPendingRequest[];
79
+ }
80
+ export type AgentPendingRequest = {
81
+ requestId: string;
82
+ kind: "permission";
83
+ description: string;
84
+ options: {
85
+ optionId: string;
86
+ name: string;
87
+ kind: string;
88
+ }[];
89
+ } | {
90
+ requestId: string;
91
+ kind: "form";
92
+ message: string;
93
+ schema: Record<string, unknown>;
94
+ } | {
95
+ requestId: string;
96
+ kind: "url";
97
+ message: string;
98
+ url: string;
99
+ };
100
+ export interface AgentResponseInput {
101
+ requestId?: string;
102
+ action: AcpElicitationAction;
103
+ optionId?: string;
104
+ content?: AcpElicitationContent;
105
+ }
106
+ export interface AgentCompletion {
107
+ agentId: string;
108
+ name: string;
109
+ cycle: AgentCycle;
110
+ report: string;
111
+ }
112
+ export interface AgentHost {
113
+ available(backend: AcpBackend): void;
114
+ filterOptions?(backend: AcpBackend, options: AgentOptions): AgentOptions;
115
+ prepare(backend: AcpBackend, options: AgentOptions): AcpSessionReference;
116
+ alive(id: string): boolean;
117
+ validateSession(value: AgentDescriptor, reference: AgentSessionReference): void | Promise<void>;
118
+ launch(value: AgentDescriptor, directory: string, generation: string, reference: AgentSessionReference, resume: boolean, signal: AbortSignal): void | Promise<void>;
119
+ release(id: string, generation: string): void | Promise<void>;
120
+ report(value: AgentDescriptor, reference: AgentSessionReference, leaf: string): string | Promise<string>;
121
+ }
@@ -0,0 +1,4 @@
1
+ export const messageDeliveries = ["steer", "followUp"];
2
+ export const cycleStates = ["running", "completed", "failed", "cancelled", "interrupted"];
3
+ export const cycleSources = ["parent", "interactive", "mixed"];
4
+ export const agentStates = ["starting", "busy", "idle", "stopping", "stopped", "error"];
@@ -157,6 +157,16 @@ export interface SummaryRunReport {
157
157
  durationMs: number;
158
158
  warnings: string[];
159
159
  }
160
+ export declare const historyPageLimits: {
161
+ readonly search: {
162
+ readonly default: 20;
163
+ readonly max: 50;
164
+ };
165
+ readonly read: {
166
+ readonly default: 12000;
167
+ readonly max: 24000;
168
+ };
169
+ };
160
170
  export interface HistoryQuery {
161
171
  host?: HistoryHost;
162
172
  query?: string;
@@ -1 +1,4 @@
1
- export {};
1
+ export const historyPageLimits = {
2
+ search: { default: 20, max: 50 },
3
+ read: { default: 12_000, max: 24_000 },
4
+ };
@@ -19,11 +19,13 @@ export interface WorkspaceContext {
19
19
  export type HistoryCapture = {
20
20
  kind: "input";
21
21
  sessionId: string;
22
+ turnId?: string;
22
23
  text: string;
23
24
  timestamp?: string;
24
25
  } | {
25
26
  kind: "answer";
26
27
  sessionId: string;
28
+ turnId?: string;
27
29
  userText?: string;
28
30
  assistantText: string;
29
31
  completed: boolean;
@@ -40,6 +42,7 @@ export type HostEvent = {
40
42
  role: WorkspaceRole;
41
43
  localRoleOnly?: boolean;
42
44
  isSessionStart?: boolean;
45
+ noticesOnly?: boolean;
43
46
  cwd: string;
44
47
  raw: unknown;
45
48
  } | {
@@ -55,10 +58,12 @@ export type HostEvent = {
55
58
  export interface PluginHostAdapter {
56
59
  readonly host: PluginHostId;
57
60
  readonly nativeRootAgents: boolean;
61
+ readonly indexBundledSkills?: boolean;
58
62
  readonly nativeWorkspaceSkills?: boolean;
59
63
  readonly coordinatorPrompt?: string;
60
64
  readonly initCommandHint: string;
61
65
  readonly usage: string;
66
+ boundWorkspaceRoot?(): string | undefined;
62
67
  resolveRoot(cwd: string, rawPayload?: unknown): Promise<string>;
63
68
  parseEvent(payload: unknown): HostEvent;
64
69
  extractHistory?(event: Extract<HostEvent, {
@@ -5,12 +5,11 @@ export interface WorkspaceFeatures {
5
5
  mcp?: boolean;
6
6
  history?: boolean;
7
7
  }
8
- export interface ResolvedWorkspaceFeatures {
9
- readonly prompts: boolean;
10
- readonly skills: boolean;
11
- readonly mcp: boolean;
12
- readonly history: boolean;
13
- }
8
+ export type ResolvedWorkspaceFeatures = Readonly<Required<WorkspaceFeatures>>;
9
+ export declare const summaryConcurrency: {
10
+ readonly default: 3;
11
+ readonly max: 8;
12
+ };
14
13
  export interface WorkspaceSummaryConfig {
15
14
  backend?: string;
16
15
  model?: string;
@@ -23,7 +22,8 @@ export interface ResolvedWorkspaceSummaryConfig {
23
22
  readonly thinking?: string;
24
23
  readonly concurrency: number;
25
24
  }
26
- export type HistoryLayout = "monthly" | "flat";
25
+ export declare const historyLayouts: readonly ["monthly", "flat"];
26
+ export type HistoryLayout = typeof historyLayouts[number];
27
27
  export interface WorkspaceHistoryConfig {
28
28
  layout?: HistoryLayout;
29
29
  }
@@ -37,13 +37,9 @@ export interface WorkspaceConfig {
37
37
  summary?: WorkspaceSummaryConfig;
38
38
  history?: WorkspaceHistoryConfig;
39
39
  }
40
- export interface WorkspaceConfiguration {
40
+ export interface WorkspaceConfiguration extends WorkspaceConfig {
41
41
  path: string;
42
42
  present: boolean;
43
43
  enabled: boolean;
44
44
  error?: string;
45
- features?: WorkspaceFeatures;
46
- acp?: AcpCommands;
47
- summary?: WorkspaceSummaryConfig;
48
- history?: WorkspaceHistoryConfig;
49
45
  }
@@ -1 +1,2 @@
1
- export {};
1
+ export const summaryConcurrency = { default: 3, max: 8 };
2
+ export const historyLayouts = ["monthly", "flat"];
@@ -1 +1,2 @@
1
- export declare function main(args: readonly string[]): Promise<void>;
1
+ import { type ReplayPluginHook } from "./extension/hosts/plugin-runtime.js";
2
+ export declare function main(args: readonly string[], replayHook?: ReplayPluginHook): Promise<void>;
@@ -3,11 +3,11 @@ import { pathToFileURL } from "node:url";
3
3
  import { requireThat } from "./common/validation.js";
4
4
  import { runPluginHost } from "./extension/hosts/plugin-runtime.js";
5
5
  import { listPluginHosts, pluginHosts } from "./integrations/hosts/plugin-registry.js";
6
- export async function main(args) {
6
+ export async function main(args, replayHook) {
7
7
  const [host, ...rest] = args;
8
8
  const adapter = host ? pluginHosts.get(host) : undefined;
9
9
  requireThat(adapter, `用法:node <插件目录>/lib/plugin.js <${listPluginHosts().join("|")}> hook|init|status`);
10
- await runPluginHost(adapter, rest);
10
+ await runPluginHost(adapter, rest, replayHook);
11
11
  }
12
12
  if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
13
13
  void main(process.argv.slice(2)).catch(error => {
@@ -1,8 +1,6 @@
1
1
  import { randomUUID } from "node:crypto";
2
- import { join } from "node:path";
3
2
  import { isDeepStrictEqual } from "node:util";
4
- import { HistoryFiles } from "../../storage/history-files.js";
5
- import { readWorkspaceHistoryLayoutSync } from "../workspace/workspace-config.js";
3
+ import { workspaceHistoryFiles } from "./workspace-history.js";
6
4
  import { indexHistory, orderedRawExchanges } from "./history-index.js";
7
5
  function orderedExchanges(raw) {
8
6
  if (!raw)
@@ -17,10 +15,15 @@ function orderedExchanges(raw) {
17
15
  }
18
16
  function replaceAssistantSuffix(text, assistantText) {
19
17
  const marker = "\n\n助手:\n";
18
+ const section = `助手:\n${assistantText}`;
19
+ if (text === section || text.endsWith("\n\n" + section))
20
+ return text;
21
+ if (!text || text.startsWith("助手:\n"))
22
+ return section;
20
23
  const index = text.lastIndexOf(marker);
21
24
  if (index >= 0)
22
25
  return text.slice(0, index) + marker + assistantText;
23
- return text ? `${text}${marker}${assistantText}` : `助手:\n${assistantText}`;
26
+ return text + marker + assistantText;
24
27
  }
25
28
  function buildSession(host, capture, previous) {
26
29
  if (capture.kind === "session") {
@@ -28,34 +31,44 @@ function buildSession(host, capture, previous) {
28
31
  }
29
32
  const timestamp = capture.timestamp ?? new Date().toISOString();
30
33
  const branch = orderedExchanges(previous);
34
+ // entryIds already identify native observations on disk. A turn keeps its ID
35
+ // across steering, attachment-only inputs and Stop hooks arriving out of order.
36
+ const turnEntry = capture.turnId ? `${host}:turn:${capture.turnId}` : undefined;
37
+ const turn = turnEntry ? branch.find(item => item.entryIds.includes(turnEntry)) : undefined;
38
+ const entryId = () => turnEntry ?? `${host}:${Date.now()}:${randomUUID().slice(0, 8)}`;
31
39
  if (capture.kind === "input") {
32
40
  const text = capture.text.trim();
33
- if (!text)
41
+ if (!text && !turnEntry)
34
42
  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
+ const input = "用户:\n" + (text || "(无文本输入)");
44
+ if (turn) {
45
+ turn.text += "\n\n" + input;
46
+ turn.to = timestamp;
47
+ turn.completed = false;
48
+ }
49
+ else {
50
+ branch.push({ entryIds: [entryId()], text: input, from: timestamp, to: timestamp, completed: false });
51
+ }
43
52
  return { sessionId: capture.sessionId, name: previous?.name ?? "", branches: [branch] };
44
53
  }
45
54
  const assistantText = capture.assistantText.trim();
46
55
  if (!assistantText)
47
56
  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;
57
+ const target = turnEntry ? turn : branch.at(-1);
58
+ if (target && (turnEntry || !target.completed || capture.isContinuation)) {
59
+ const updated = turnEntry && !target.completed
60
+ ? target.text + "\n\n助手:\n" + assistantText
61
+ : replaceAssistantSuffix(target.text, assistantText);
62
+ if (target.text === updated && target.completed === capture.completed)
63
+ return undefined;
64
+ target.text = updated;
65
+ target.to = timestamp;
66
+ target.completed = capture.completed;
53
67
  }
54
68
  else {
55
- const entryId = `${host}:${Date.now()}:${randomUUID().slice(0, 8)}`;
56
69
  const userText = capture.userText?.trim();
57
70
  branch.push({
58
- entryIds: [entryId],
71
+ entryIds: [entryId()],
59
72
  text: userText ? `用户:\n${userText}\n\n助手:\n${assistantText}` : `助手:\n${assistantText}`,
60
73
  from: timestamp,
61
74
  to: timestamp,
@@ -69,8 +82,7 @@ export function recordHistoryCapture(root, host, capture) {
69
82
  const sessionId = capture.kind === "session" ? capture.session.sessionId : capture.sessionId;
70
83
  if (!sessionId)
71
84
  return;
72
- const layout = readWorkspaceHistoryLayoutSync(root);
73
- const files = new HistoryFiles(join(root, ".pbot/history"), host, layout);
85
+ const files = workspaceHistoryFiles(root, host);
74
86
  files.control(() => {
75
87
  const previous = files.listRaw(host).find(raw => raw.sessionId === sessionId);
76
88
  if (!previous && files.rawWarnings.length)
@@ -1,5 +1,4 @@
1
- import { requireThat } from "../../common/validation.js";
2
- import { isSummaryDimension } from "../../storage/history-format.js";
1
+ import { isHistoryIdentifier, requireThat } from "../../common/validation.js";
3
2
  import { monthlySummaryDimension } from "./summary-dimensions/monthly.js";
4
3
  import { sessionSummaryDimension } from "./summary-dimensions/session.js";
5
4
  const registry = new Map([
@@ -8,7 +7,7 @@ const registry = new Map([
8
7
  ]);
9
8
  /** Register a custom summary dimension (e.g. daily, decisions, topics). */
10
9
  export function registerSummaryDimension(dimension) {
11
- requireThat(isSummaryDimension(dimension.id), "摘要维度 ID 无效:" + dimension.id);
10
+ requireThat(isHistoryIdentifier(dimension.id), "摘要维度 ID 无效:" + dimension.id);
12
11
  registry.set(dimension.id, dimension);
13
12
  }
14
13
  export function unregisterSummaryDimension(id) {
@@ -5,13 +5,10 @@ export interface InspectSummaryOptions {
5
5
  thresholdDays?: number;
6
6
  now?: Date;
7
7
  }
8
- export interface CheckSummaryReminderOptions {
9
- dimensions?: readonly string[];
10
- thresholdDays?: number;
11
- now?: Date;
12
- }
8
+ export type CheckSummaryReminderOptions = InspectSummaryOptions;
13
9
  /** Read-only startup probe: reminds when raw history has existed >= thresholdDays and no summary ran within thresholdDays. */
14
10
  export declare function checkHistorySummaryReminder(root: string, options?: CheckSummaryReminderOptions): HistorySummaryReminder | undefined;
11
+ export declare function historyStartupNotices(root: string): string[];
15
12
  /** Read-only inspection of raw archives vs derived summaries across requested dimensions. */
16
13
  export declare function inspectWorkspaceSummaries(root: string, options?: InspectSummaryOptions): {
17
14
  layout: HistoryLayout;
@@ -1,12 +1,10 @@
1
- import { join } from "node:path";
1
+ import { isDeepStrictEqual } from "node:util";
2
2
  import { setTimeout as delay } from "node:timers/promises";
3
3
  import { requireThat } from "../../common/validation.js";
4
- import { HistoryFiles } from "../../storage/history-files.js";
5
- import { readWorkspaceHistoryLayoutSync } from "../workspace/workspace-config.js";
4
+ import { summaryConcurrency } from "../../model/workspace-config.js";
5
+ import { workspaceHistoryFiles } from "./workspace-history.js";
6
6
  import { rawSessionSpan } from "./history-index.js";
7
7
  import { resolveSummaryDimensions } from "./summary-registry.js";
8
- const defaultConcurrency = 3;
9
- const maxConcurrency = 8;
10
8
  const lockRetryAttempts = 5;
11
9
  const lockRetryDelayMs = 40;
12
10
  export const defaultSummaryReminderDays = 7;
@@ -70,8 +68,8 @@ function evaluateSummaryReminder(raws, allSummaries, pendingCount, options = {})
70
68
  const rawAgeDays = Math.floor((nowMs - oldestRawMs) / dayMs);
71
69
  const daysSinceLastSummary = latestSummaryMs === undefined ? undefined : Math.floor((nowMs - latestSummaryMs) / dayMs);
72
70
  const message = daysSinceLastSummary === undefined
73
- ? `历史原文已累计 ${rawAgeDays} 天(待摘要 ${pendingCount} 项),尚未触发过摘要整理;可运行 /pbot history summary 生成摘要。`
74
- : `历史原文已累计 ${rawAgeDays} 天,且已 ${daysSinceLastSummary} 天未触发摘要整理(待摘要 ${pendingCount} 项);可运行 /pbot history summary 更新摘要。`;
71
+ ? `历史原文已累计 ${rawAgeDays} 天(待摘要 ${pendingCount} 项),尚未触发过摘要整理;可在终端运行 pbot history summary 生成摘要(Pi/dsh 可用 /pbot history summary)。`
72
+ : `历史原文已累计 ${rawAgeDays} 天,且已 ${daysSinceLastSummary} 天未触发摘要整理(待摘要 ${pendingCount} 项);可在终端运行 pbot history summary 更新摘要(Pi/dsh 可用 /pbot history summary)。`;
75
73
  return {
76
74
  rawCount: raws.length,
77
75
  pendingCount,
@@ -85,8 +83,23 @@ function evaluateSummaryReminder(raws, allSummaries, pendingCount, options = {})
85
83
  }
86
84
  /** Read-only startup probe: reminds when raw history has existed >= thresholdDays and no summary ran within thresholdDays. */
87
85
  export function checkHistorySummaryReminder(root, options = {}) {
88
- const layout = readWorkspaceHistoryLayoutSync(root);
89
- const files = new HistoryFiles(join(root, ".pbot/history"), "pi", layout);
86
+ return summaryReminder(workspaceHistoryFiles(root), options);
87
+ }
88
+ export function historyStartupNotices(root) {
89
+ const notices = [];
90
+ try {
91
+ const files = workspaceHistoryFiles(root);
92
+ const migration = files.migrationNotice();
93
+ if (migration)
94
+ notices.push(migration);
95
+ const reminder = summaryReminder(files, {});
96
+ if (reminder)
97
+ notices.push(reminder.message);
98
+ }
99
+ catch { /* History diagnostics are best effort during host startup. */ }
100
+ return notices;
101
+ }
102
+ function summaryReminder(files, options) {
90
103
  const raws = files.listRaw();
91
104
  if (!raws.length)
92
105
  return undefined;
@@ -96,48 +109,11 @@ export function checkHistorySummaryReminder(root, options = {}) {
96
109
  const oldestRawMs = oldestRawTimestamp(raws);
97
110
  if (oldestRawMs === undefined || nowMs - oldestRawMs < thresholdDays * dayMs)
98
111
  return undefined;
99
- const dimensions = resolveSummaryDimensions(options.dimensions, layout);
100
- const seenDimensions = new Set();
101
- const summariesByDimension = new Map();
102
- const allSummaries = [];
103
- let pendingCount = 0;
104
- const loadDimension = (dimId) => {
105
- const cached = summariesByDimension.get(dimId);
106
- if (cached)
107
- return cached;
108
- const list = files.listSummaries(dimId);
109
- const map = new Map(list.map(item => [item.id, item]));
110
- summariesByDimension.set(dimId, map);
111
- return map;
112
- };
113
- for (const dimension of dimensions) {
114
- seenDimensions.add(dimension.id);
115
- if (dimension.id !== "session")
116
- loadDimension("session");
117
- const existing = loadDimension(dimension.id);
118
- allSummaries.push(...existing.values());
119
- const plan = dimension.plan(raws, existing, { force: false, summariesByDimension });
120
- pendingCount += plan.tasks.length;
121
- }
122
- for (const dim of files.listDimensions()) {
123
- if (seenDimensions.has(dim))
124
- continue;
125
- allSummaries.push(...loadDimension(dim).values());
126
- }
127
- return evaluateSummaryReminder(raws, allSummaries, pendingCount, options);
112
+ const { totalPending, allSummaries } = inspectDimensions(files, raws, options, []);
113
+ return evaluateSummaryReminder(raws, allSummaries, totalPending, options);
128
114
  }
129
- /** Read-only inspection of raw archives vs derived summaries across requested dimensions. */
130
- export function inspectWorkspaceSummaries(root, options = {}) {
131
- const layout = readWorkspaceHistoryLayoutSync(root);
132
- const files = new HistoryFiles(join(root, ".pbot/history"), "pi", layout);
133
- const raws = files.listRaw();
134
- const warnings = [...files.warnings];
135
- if (layout === "monthly") {
136
- const flatNotice = files.detectFlatFiles().message;
137
- if (flatNotice)
138
- warnings.push(flatNotice);
139
- }
140
- const dimensions = resolveSummaryDimensions(options.dimensions, layout);
115
+ function inspectDimensions(files, raws, options, warnings) {
116
+ const dimensions = resolveSummaryDimensions(options.dimensions, files.layout);
141
117
  const statuses = [];
142
118
  const seenDimensions = new Set();
143
119
  const summariesByDimension = new Map();
@@ -188,9 +164,20 @@ export function inspectWorkspaceSummaries(root, options = {}) {
188
164
  continue;
189
165
  allSummaries.push(...loadDimension(dim).values());
190
166
  }
167
+ return { statuses, totalPending, allSummaries };
168
+ }
169
+ /** Read-only inspection of raw archives vs derived summaries across requested dimensions. */
170
+ export function inspectWorkspaceSummaries(root, options = {}) {
171
+ const files = workspaceHistoryFiles(root);
172
+ const raws = files.listRaw();
173
+ const warnings = [...files.warnings];
174
+ const flatNotice = files.migrationNotice();
175
+ if (flatNotice)
176
+ warnings.push(flatNotice);
177
+ const { statuses, totalPending, allSummaries } = inspectDimensions(files, raws, options, warnings);
191
178
  const reminder = evaluateSummaryReminder(raws, allSummaries, totalPending, options);
192
179
  return {
193
- layout,
180
+ layout: files.layout,
194
181
  rawCount: raws.length,
195
182
  dimensions: statuses,
196
183
  warnings: [...new Set(warnings)],
@@ -206,29 +193,28 @@ export async function runWorkspaceSummaries(options) {
206
193
  const startedAt = Date.now();
207
194
  const signal = options.signal ?? new AbortController().signal;
208
195
  signal.throwIfAborted();
209
- const concurrency = Math.max(1, Math.min(maxConcurrency, Math.floor(options.concurrency ?? defaultConcurrency)));
210
- const layout = readWorkspaceHistoryLayoutSync(options.root);
211
- const dimensions = resolveSummaryDimensions(options.dimensions, layout);
212
- const files = new HistoryFiles(join(options.root, ".pbot/history"), "pi", layout);
196
+ const concurrency = Math.max(1, Math.min(summaryConcurrency.max, Math.floor(options.concurrency ?? summaryConcurrency.default)));
197
+ const files = workspaceHistoryFiles(options.root);
198
+ const dimensions = resolveSummaryDimensions(options.dimensions, files.layout);
199
+ const warnings = [];
200
+ const loadSummaries = (id) => {
201
+ const items = files.listSummaries(id);
202
+ warnings.push(...files.warnings);
203
+ return new Map(items.map(item => [item.id, item]));
204
+ };
205
+ // Capture each publication baseline before reading the input it will summarize.
206
+ const plannedDimensions = dimensions.map(dimension => ({ dimension, existing: loadSummaries(dimension.id) }));
213
207
  const raws = files.listRaw();
214
- const warnings = [...files.warnings];
215
- if (layout === "monthly") {
216
- const flatNotice = files.detectFlatFiles().message;
217
- if (flatNotice)
218
- warnings.push(flatNotice);
219
- }
208
+ warnings.push(...files.warnings);
209
+ const flatNotice = files.migrationNotice();
210
+ if (flatNotice)
211
+ warnings.push(flatNotice);
220
212
  const summariesByDimension = new Map();
221
213
  const reports = [];
222
- for (const dimension of dimensions) {
214
+ for (const { dimension, existing } of plannedDimensions) {
223
215
  signal.throwIfAborted();
224
- if (dimension.id !== "session" && !summariesByDimension.has("session")) {
225
- const sessionList = files.listSummaries("session");
226
- warnings.push(...files.warnings);
227
- summariesByDimension.set("session", new Map(sessionList.map(item => [item.id, item])));
228
- }
229
- const existingList = files.listSummaries(dimension.id);
230
- warnings.push(...files.warnings);
231
- const existing = new Map(existingList.map(item => [item.id, item]));
216
+ if (dimension.id !== "session")
217
+ summariesByDimension.set("session", loadSummaries("session"));
232
218
  summariesByDimension.set(dimension.id, existing);
233
219
  const plan = dimension.plan(raws, existing, { force: Boolean(options.force), summariesByDimension });
234
220
  const report = {
@@ -256,12 +242,24 @@ export async function runWorkspaceSummaries(options) {
256
242
  const output = await options.summarizer(request, signal);
257
243
  signal.throwIfAborted();
258
244
  const artifact = dimension.finalize(task, output, new Date().toISOString());
259
- await withSummaryLockRetry(files, dimension.id, () => {
245
+ const published = await withSummaryLockRetry(files, dimension.id, () => {
260
246
  signal.throwIfAborted();
261
- files.saveSummary(artifact);
247
+ const current = files.readSummary(dimension.id, artifact.id);
248
+ if (isDeepStrictEqual(current, existing.get(artifact.id))) {
249
+ files.saveSummary(artifact);
250
+ return artifact;
251
+ }
252
+ if (current)
253
+ existing.set(artifact.id, current);
254
+ else
255
+ existing.delete(artifact.id);
256
+ requireThat(current && isDeepStrictEqual(current.source, artifact.source), "摘要在生成期间已变更,请重新运行摘要。");
257
+ return current;
262
258
  }, signal);
263
- existing.set(artifact.id, artifact);
264
- if (task.mode === "create")
259
+ existing.set(artifact.id, published);
260
+ if (published !== artifact)
261
+ report.skipped++;
262
+ else if (task.mode === "create")
265
263
  report.created++;
266
264
  else if (task.mode === "incremental")
267
265
  report.incremental++;
@@ -0,0 +1,3 @@
1
+ import type { HistoryHost } from "../../model/history.js";
2
+ import { HistoryFiles } from "../../storage/history-files.js";
3
+ export declare function workspaceHistoryFiles(root: string, host?: HistoryHost): HistoryFiles;
@@ -0,0 +1,6 @@
1
+ import { join } from "node:path";
2
+ import { HistoryFiles } from "../../storage/history-files.js";
3
+ import { readWorkspaceHistoryLayoutSync } from "../workspace/workspace-config.js";
4
+ export function workspaceHistoryFiles(root, host) {
5
+ return new HistoryFiles(join(root, ".pbot/history"), host, readWorkspaceHistoryLayoutSync(root));
6
+ }
@@ -0,0 +1,15 @@
1
+ /** Each host owns its file, including when two hosts activate the same canonical workspace concurrently. */
2
+ export declare function bindWorkspacePlugin(root: string, host: string, binding?: string): void;
3
+ export interface WorkspacePluginBinding {
4
+ version: string;
5
+ bindingPath?: string;
6
+ }
7
+ export interface WorkspacePluginDrift {
8
+ outOfSync: boolean;
9
+ highest?: string;
10
+ lowest?: string;
11
+ versions: Record<string, string>;
12
+ }
13
+ export declare function workspacePluginBindings(root: string): Record<string, WorkspacePluginBinding>;
14
+ export declare function workspacePluginReleases(root: string): Record<string, string>;
15
+ export declare function workspacePluginDrift(releases: Record<string, string>): WorkspacePluginDrift;