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
@@ -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"];
package/lib/plugin.d.ts CHANGED
@@ -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>;
package/lib/plugin.js CHANGED
@@ -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 => {
@@ -0,0 +1,17 @@
1
+ {
2
+ "mcpServers": {
3
+ "pbot": {
4
+ "command": "sh",
5
+ "args": [
6
+ "-c",
7
+ "if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.4 \"$@\"",
8
+ "pbot",
9
+ "mcp"
10
+ ],
11
+ "env": {
12
+ "PBOT_HOST": "qoder",
13
+ "PBOT_PLUGIN_VERSION": "0.3.4"
14
+ }
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "personal-bot",
3
+ "version": "0.3.4",
4
+ "description": "Personal Bot workspace context and cross-harness workers.",
5
+ "skills": "./skills/",
6
+ "mcpServers": "./.mcp.json"
7
+ }
@@ -0,0 +1,17 @@
1
+ # Disclaimer / 免责声明
2
+
3
+ ## English
4
+
5
+ AI models can produce incorrect answers, commands, and code. Verify information before relying on it. Review proposed changes before applying them to important files or systems.
6
+
7
+ Workers and MCP tools may read or change files, run commands, or send workspace data to services you configure. Check which data and credentials a worker or service can access when granting permissions. Third-party providers may charge for requests and process data under their own terms and privacy policies.
8
+
9
+ Personal Bot is provided “as is”. Its warranty disclaimer and limitation of liability are set out in the project license. Third-party software is subject to its own licenses. [MIT License](LICENSE)
10
+
11
+ ## 中文
12
+
13
+ AI 模型生成的回答、命令和代码可能有误。请在据此作出决定前核实关键信息,在将更改应用到重要文件或系统前审查具体内容。
14
+
15
+ Worker 和 MCP 工具可能读取或修改文件、执行命令,或将工作区数据发送给你配置的服务。授予权限时,请确认对方能够访问哪些数据和凭据。第三方服务可能按请求收费,并按各自的条款和隐私政策处理数据。
16
+
17
+ Personal Bot 按现状提供,担保免责和责任限制条款见项目许可证。第三方软件适用其各自的许可证。[MIT 许可证全文](LICENSE)
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Personal Bot contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,37 @@
1
+ {
2
+ "hooks": {
3
+ "SessionStart": [
4
+ {
5
+ "hooks": [
6
+ {
7
+ "type": "command",
8
+ "command": "PBOT_PLUGIN_VERSION=0.3.4 PBOT_PLUGIN_MANIFEST=\"${QODER_PLUGIN_ROOT:+$QODER_PLUGIN_ROOT/.qoder-plugin/plugin.json}\" sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.4 \"$@\"' pbot plugin qoder hook",
9
+ "timeout": 120
10
+ }
11
+ ]
12
+ }
13
+ ],
14
+ "UserPromptSubmit": [
15
+ {
16
+ "hooks": [
17
+ {
18
+ "type": "command",
19
+ "command": "PBOT_PLUGIN_VERSION=0.3.4 PBOT_PLUGIN_MANIFEST=\"${QODER_PLUGIN_ROOT:+$QODER_PLUGIN_ROOT/.qoder-plugin/plugin.json}\" sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.4 \"$@\"' pbot plugin qoder hook",
20
+ "timeout": 120
21
+ }
22
+ ]
23
+ }
24
+ ],
25
+ "Stop": [
26
+ {
27
+ "hooks": [
28
+ {
29
+ "type": "command",
30
+ "command": "PBOT_PLUGIN_VERSION=0.3.4 PBOT_PLUGIN_MANIFEST=\"${QODER_PLUGIN_ROOT:+$QODER_PLUGIN_ROOT/.qoder-plugin/plugin.json}\" sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.4 \"$@\"' pbot plugin qoder hook",
31
+ "timeout": 120
32
+ }
33
+ ]
34
+ }
35
+ ]
36
+ }
37
+ }
@@ -0,0 +1,9 @@
1
+ ---
2
+ name: pbot
3
+ description: 初始化 Personal Bot 工作区、查看状态、搜索归档或生成历史摘要。
4
+ disable-model-invocation: true
5
+ ---
6
+
7
+ 使用当前会话的 `workspaceRoot` 作为 `--workspace`。省略子命令时使用 `status`。可执行 `init`、`status`、`history status|list|summary|migrate|search|read`。保留用户指定的维度、模型和筛选参数。
8
+
9
+ 运行 `npx --yes personal-bot@0.3.4 <子命令> --workspace "<workspaceRoot>"`。如果 `pbot --at-least 0.3.4` 返回 0,也可以用 `pbot` 执行同一条命令。返回实际结果。
@@ -1,22 +1,11 @@
1
- import { AgentFiles } from "../../storage/agent-files.js";
2
- import type { AgentOwner, AgentOptions, AgentPendingRequest, AgentResponseInput, AgentStartOptions, AgentDescriptor, AgentCycle, AgentSessionReference, AgentView } from "../../model/agent.js";
3
- import type { AcpBackend, AcpSessionReference } from "../../model/acp.js";
4
- export interface AgentHost {
5
- available(backend: AcpBackend): void;
6
- filterOptions?(backend: AcpBackend, options: AgentOptions): AgentOptions;
7
- prepare(backend: AcpBackend, options: AgentOptions): AcpSessionReference;
8
- alive(id: string): boolean;
9
- validateSession(value: AgentDescriptor, reference: AgentSessionReference): void | Promise<void>;
10
- launch(value: AgentDescriptor, directory: string, generation: string, reference: AgentSessionReference, resume: boolean, signal: AbortSignal): void | Promise<void>;
11
- release(id: string, generation: string): void | Promise<void>;
12
- report(value: AgentDescriptor, reference: AgentSessionReference, leaf: string): string | Promise<string>;
13
- }
1
+ import type { AgentOwner, AgentOptions, AgentMessage, AgentPendingRequest, AgentResponseInput, AgentStartOptions, AgentCycle, AgentHost, AgentView } from "../../model/agent.js";
2
+ export type { AgentHost } from "../../model/agent.js";
14
3
  /** Host-neutral lifecycle manager for cross-harness ACP workers. */
15
4
  export declare class AgentService {
16
5
  #private;
17
6
  readonly root: string;
18
7
  readonly host: AgentHost;
19
- readonly files: AgentFiles;
8
+ private readonly files;
20
9
  constructor(root: string, directory: string, host: AgentHost);
21
10
  private alive;
22
11
  private check;
@@ -35,7 +24,7 @@ export declare class AgentService {
35
24
  state: import("../../model/agent.js").AgentStatus["state"];
36
25
  activity: string;
37
26
  alive: boolean;
38
- backend: AcpBackend;
27
+ backend: import("../../model/acp.js").AcpBackend;
39
28
  transport: "acp";
40
29
  selection?: import("../../model/acp.js").AcpModelSelection;
41
30
  capabilities: {
@@ -57,7 +46,7 @@ export declare class AgentService {
57
46
  options: AgentOptions;
58
47
  }>;
59
48
  private launch;
60
- send(id: string, text: string, delivery: "steer" | "followUp", owner: AgentOwner, attachments?: readonly string[]): {
49
+ send(id: string, text: string, delivery: AgentMessage["delivery"], owner: AgentOwner, attachments?: readonly string[]): {
61
50
  requestId: string;
62
51
  messageStatus: "queued";
63
52
  name: string;
@@ -65,7 +54,7 @@ export declare class AgentService {
65
54
  state: import("../../model/agent.js").AgentStatus["state"];
66
55
  activity: string;
67
56
  alive: boolean;
68
- backend: AcpBackend;
57
+ backend: import("../../model/acp.js").AcpBackend;
69
58
  transport: "acp";
70
59
  selection?: import("../../model/acp.js").AcpModelSelection;
71
60
  capabilities: {
@@ -98,7 +87,7 @@ export declare class AgentService {
98
87
  state: import("../../model/agent.js").AgentStatus["state"];
99
88
  activity: string;
100
89
  alive: boolean;
101
- backend: AcpBackend;
90
+ backend: import("../../model/acp.js").AcpBackend;
102
91
  transport: "acp";
103
92
  selection?: import("../../model/acp.js").AcpModelSelection;
104
93
  capabilities: {
@@ -121,32 +110,13 @@ export declare class AgentService {
121
110
  }>;
122
111
  private restart;
123
112
  cycles(id: string, owner: AgentOwner): AgentCycle[];
124
- status(id: string, owner: AgentOwner): {
125
- cycle?: AgentCycle;
126
- name: string;
127
- generation: string;
128
- state: import("../../model/agent.js").AgentStatus["state"];
129
- activity: string;
130
- alive: boolean;
131
- backend: AcpBackend;
132
- transport: "acp";
133
- selection?: import("../../model/acp.js").AcpModelSelection;
134
- capabilities: {
135
- steer: boolean;
136
- resume: boolean;
137
- transcript: boolean;
138
- };
139
- error?: string;
140
- owned: boolean;
141
- pendingRequests?: AgentPendingRequest[];
142
- agentId: string;
143
- release: string;
144
- workspace: string;
145
- cwd: string;
146
- parentSessionId: string;
147
- parentLeaf: string | null;
148
- createdAt: number;
149
- options: AgentOptions;
113
+ private cyclesFor;
114
+ private snapshot;
115
+ status(id: string, owner: AgentOwner): AgentView;
116
+ outputStatus(id: string, owner: AgentOwner, requestId?: string): {
117
+ current: AgentView;
118
+ cycle: AgentCycle | undefined;
119
+ terminal: boolean;
150
120
  };
151
121
  read(id: string, owner: AgentOwner, cycleId?: string, offset?: number, limit?: number): Promise<{
152
122
  cycles: {
@@ -162,7 +132,7 @@ export declare class AgentService {
162
132
  state: import("../../model/agent.js").AgentStatus["state"];
163
133
  activity: string;
164
134
  alive: boolean;
165
- backend: AcpBackend;
135
+ backend: import("../../model/acp.js").AcpBackend;
166
136
  transport: "acp";
167
137
  selection?: import("../../model/acp.js").AcpModelSelection;
168
138
  capabilities: {
@@ -298,7 +298,11 @@ export class AgentService {
298
298
  }
299
299
  }
300
300
  cycles(id, owner) {
301
- const d = this.get(id, owner), view = this.view(d, owner), values = this.files.completions(id);
301
+ return this.cyclesFor(this.view(this.get(id, owner), owner));
302
+ }
303
+ cyclesFor(view) {
304
+ const id = view.agentId;
305
+ const values = this.files.completions(id);
302
306
  if (view.cycle && !values.some(c => c.cycleId === view.cycle.cycleId)) {
303
307
  values.push(view.state === "stopped" || view.state === "error" ? { ...view.cycle, state: "interrupted", finishedAt: view.cycle.finishedAt ?? Date.now() } : view.cycle);
304
308
  }
@@ -321,9 +325,24 @@ export class AgentService {
321
325
  }
322
326
  return values;
323
327
  }
328
+ snapshot(id, owner) {
329
+ const view = this.view(this.get(id, owner), owner);
330
+ const cycles = this.cyclesFor(view);
331
+ const latest = cycles.at(-1);
332
+ return { current: latest ? { ...view, cycle: latest } : view, cycles };
333
+ }
324
334
  status(id, owner) {
325
- const d = this.get(id, owner), latest = this.cycles(id, owner).at(-1);
326
- return { ...this.view(d, owner), ...(latest ? { cycle: latest } : {}) };
335
+ return this.snapshot(id, owner).current;
336
+ }
337
+ outputStatus(id, owner, requestId) {
338
+ const { current, cycles } = this.snapshot(id, owner);
339
+ const request = requestId ?? this.files.messages(id).findLast(item => item.generation === current.generation)?.requestId;
340
+ const cycle = request
341
+ ? cycles.find(item => item.generation === current.generation && item.requestIds.includes(request))
342
+ : current.cycle;
343
+ const stopped = current.state === "stopped" || current.state === "error";
344
+ const terminal = request ? stopped && !cycle : stopped || (current.state === "idle" && !cycle);
345
+ return { current, cycle, terminal };
327
346
  }
328
347
  async read(id, owner, cycleId, offset = 0, limit = 16000) {
329
348
  const d = this.get(id, owner), cycles = this.cycles(id, owner);
@@ -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,15 +1,10 @@
1
- import { lstatSync } from "node:fs";
2
1
  import { join } from "node:path";
3
2
  import { requireThat } from "../../common/validation.js";
4
- import { HistoryFiles, rawHistoryBucket, summaryArtifactBucket } from "../../storage/history-files.js";
5
- import { readWorkspaceHistoryLayoutSync } from "../workspace/workspace-config.js";
3
+ import { rawHistoryBucket, summaryArtifactBucket } from "../../storage/history-files.js";
4
+ import { workspaceHistoryFiles } from "./workspace-history.js";
6
5
  /** Read-only check for unmigrated flat history files when running under monthly layout. */
7
6
  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;
7
+ return workspaceHistoryFiles(root).migrationNotice();
13
8
  }
14
9
  /**
15
10
  * Explicitly migrate flat .pbot/history/raw/*.json and .pbot/history/summaries/<dim>/*.json
@@ -17,67 +12,38 @@ export function checkHistoryMigrationNotice(root) {
17
12
  * and never modifies .pbot/config.json or overwrites existing destinations.
18
13
  */
19
14
  export function migrateWorkspaceHistory(root, options = {}) {
20
- const layout = readWorkspaceHistoryLayoutSync(root);
15
+ const files = workspaceHistoryFiles(root);
16
+ const { layout } = files;
21
17
  requireThat(layout === "monthly", '当前工作区配置为平铺布局(history.layout: "flat"),无需迁移到年月目录;如需迁移,请先在 .pbot/config.json 中将 history.layout 设为 "monthly" 或移除该配置项。');
22
18
  const dryRun = Boolean(options.dryRun);
23
- const files = new HistoryFiles(join(root, ".pbot/history"), "pi", "monthly");
24
19
  const moved = [];
25
20
  const skipped = [];
26
21
  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
- }
22
+ function migrateFile(name, dimension) {
23
+ const directory = dimension ? `summaries/${dimension}` : "raw";
24
+ const from = `${directory}/${name}`;
25
+ try {
26
+ const record = dimension ? files.readFlatSummaryFile(dimension, name) : files.readFlatRawFile(name);
27
+ const bucket = "dimension" in record ? summaryArtifactBucket(record) : rawHistoryBucket(record);
28
+ const to = `${directory}/${bucket}/${name}`;
29
+ const source = dimension ? { kind: "summary", dimension } : { kind: "raw" };
30
+ if (files.moveHistoryFile(from, to, dryRun) === "conflict") {
31
+ skipped.push({ ...source, from, to, reason: "目标路径已存在同名文件。" });
49
32
  }
50
- catch (error) {
51
- errors.push({ path: join(files.directory, from), error: error instanceof Error ? error.message : String(error) });
33
+ else {
34
+ moved.push({ ...source, id: record.id, from, to });
52
35
  }
53
36
  }
37
+ catch (error) {
38
+ errors.push({ path: join(files.directory, from), error: error instanceof Error ? error.message : String(error) });
39
+ }
40
+ }
41
+ const run = () => {
42
+ for (const name of files.listFlatRawFiles())
43
+ migrateFile(name);
54
44
  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
- }
45
+ for (const name of files.listFlatSummaryFiles(dimension))
46
+ migrateFile(name, dimension);
81
47
  }
82
48
  };
83
49
  if (dryRun)