personal-bot 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (256) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +1 -1
  4. package/README.zh-CN.md +1 -1
  5. package/bin/pbot-pi-acp.mjs +27 -11
  6. package/bin/pbot.mjs +1 -1
  7. package/docs/README.md +1 -1
  8. package/docs/architecture/design.md +23 -10
  9. package/docs/architecture/extensibility.md +20 -18
  10. package/docs/architecture/model-context.md +2 -2
  11. package/docs/architecture/principles.md +4 -3
  12. package/docs/guides/capabilities.md +3 -3
  13. package/docs/guides/history.md +50 -16
  14. package/docs/guides/workspace-configuration.md +31 -6
  15. package/docs/hosts/antigravity.md +2 -0
  16. package/docs/hosts/claude-code.md +1 -1
  17. package/docs/hosts/dsh.md +1 -1
  18. package/docs/hosts/pi.md +1 -1
  19. package/hooks/hooks.json +3 -0
  20. package/lib/antigravity-plugin/hooks.json +7 -0
  21. package/lib/antigravity-plugin/lib/claude.js +2 -2
  22. package/lib/antigravity-plugin/lib/extension/acp-worker.js +156 -11
  23. package/lib/antigravity-plugin/lib/extension/{plugin-runtime.d.ts → hosts/plugin-runtime.d.ts} +2 -2
  24. package/lib/antigravity-plugin/lib/extension/{plugin-runtime.js → hosts/plugin-runtime.js} +34 -8
  25. package/lib/antigravity-plugin/lib/extension/mcp.js +1113 -78
  26. package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +1 -0
  27. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +5 -1
  28. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
  29. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.js +171 -0
  30. package/lib/antigravity-plugin/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
  31. package/lib/antigravity-plugin/lib/integrations/hosts/{claude.js → claude/adapter.js} +32 -4
  32. package/lib/antigravity-plugin/lib/integrations/hosts/{registry.js → plugin-registry.js} +2 -2
  33. package/lib/antigravity-plugin/lib/model/history.d.ts +169 -0
  34. package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +26 -0
  35. package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +25 -0
  36. package/lib/antigravity-plugin/lib/plugin.js +2 -2
  37. package/lib/antigravity-plugin/lib/services/history/history-capture.d.ts +4 -0
  38. package/lib/antigravity-plugin/lib/services/history/history-capture.js +86 -0
  39. package/lib/antigravity-plugin/lib/services/history/history-index.d.ts +17 -0
  40. package/lib/antigravity-plugin/lib/services/history/history-index.js +112 -0
  41. package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +12 -0
  42. package/lib/antigravity-plugin/lib/services/history/history-migrate.js +88 -0
  43. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
  44. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.js +121 -0
  45. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.d.ts +7 -0
  46. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.js +124 -0
  47. package/lib/antigravity-plugin/lib/services/history/summary-registry.d.ts +7 -0
  48. package/lib/antigravity-plugin/lib/services/history/summary-registry.js +36 -0
  49. package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +37 -0
  50. package/lib/antigravity-plugin/lib/services/history/summary-runner.js +301 -0
  51. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +5 -1
  52. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +75 -4
  53. package/lib/antigravity-plugin/lib/storage/file-access.d.ts +2 -0
  54. package/lib/antigravity-plugin/lib/storage/file-access.js +26 -0
  55. package/lib/antigravity-plugin/lib/storage/history-files.d.ts +54 -0
  56. package/lib/antigravity-plugin/lib/storage/history-files.js +467 -0
  57. package/lib/antigravity-plugin/lib/storage/history-format.d.ts +6 -0
  58. package/lib/antigravity-plugin/lib/storage/history-format.js +62 -0
  59. package/lib/antigravity-plugin/package.json +1 -1
  60. package/lib/antigravity-plugin/plugin.json +1 -1
  61. package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +22 -12
  62. package/lib/claude.js +2 -2
  63. package/lib/client.js +21 -11
  64. package/lib/dsh.js +4 -4
  65. package/lib/extension/{acp-member.d.ts → acp/member.d.ts} +5 -5
  66. package/lib/extension/{acp-member.js → acp/member.js} +6 -6
  67. package/lib/extension/acp/worker.d.ts +1 -0
  68. package/lib/extension/acp/worker.js +384 -0
  69. package/lib/extension/acp-worker.js +156 -11
  70. package/lib/extension/{dsh → hosts/dsh}/acp-member.js +8 -8
  71. package/lib/extension/hosts/dsh/command.js +92 -0
  72. package/lib/extension/{dsh → hosts/dsh}/files.js +3 -3
  73. package/lib/extension/hosts/dsh/history.d.ts +4 -0
  74. package/lib/extension/hosts/dsh/history.js +62 -0
  75. package/lib/extension/{dsh → hosts/dsh}/management.d.ts +1 -1
  76. package/lib/extension/{dsh → hosts/dsh}/management.js +12 -10
  77. package/lib/extension/{dsh → hosts/dsh}/workspace.d.ts +3 -9
  78. package/lib/extension/{dsh → hosts/dsh}/workspace.js +32 -70
  79. package/lib/extension/{plugin-runtime.d.ts → hosts/plugin-runtime.d.ts} +2 -2
  80. package/lib/extension/{plugin-runtime.js → hosts/plugin-runtime.js} +34 -8
  81. package/lib/extension/{mcp-bridge.d.ts → mcp/bridge.d.ts} +1 -1
  82. package/lib/extension/{mcp-bridge.js → mcp/bridge.js} +4 -4
  83. package/lib/extension/{mcp-workers.d.ts → mcp/workers.d.ts} +222 -2
  84. package/lib/extension/{mcp-workers.js → mcp/workers.js} +229 -63
  85. package/lib/extension/mcp.js +1113 -78
  86. package/lib/extension/{setup-cli.js → setup/cli.js} +9 -9
  87. package/lib/integrations/acp/connection.d.ts +11 -10
  88. package/lib/integrations/acp/connection.js +6 -0
  89. package/lib/integrations/acp/harnesses/claude.js +1 -1
  90. package/lib/integrations/acp/harnesses/dsh.js +1 -1
  91. package/lib/integrations/acp/history-summary.d.ts +17 -0
  92. package/lib/integrations/acp/history-summary.js +100 -0
  93. package/lib/integrations/agent-resources.d.ts +1 -0
  94. package/lib/integrations/agent-resources.js +5 -1
  95. package/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
  96. package/lib/integrations/hosts/antigravity/adapter.js +171 -0
  97. package/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
  98. package/lib/integrations/hosts/{claude.js → claude/adapter.js} +32 -4
  99. package/lib/integrations/{dsh → hosts/dsh}/mcp.d.ts +1 -1
  100. package/lib/integrations/{dsh → hosts/dsh}/resources.d.ts +1 -1
  101. package/lib/integrations/{dsh → hosts/dsh}/resources.js +4 -4
  102. package/lib/integrations/{dsh → hosts/dsh}/schema.js +1 -1
  103. package/lib/integrations/{dsh → hosts/dsh}/skills.js +1 -1
  104. package/lib/integrations/hosts/{registry.js → plugin-registry.js} +2 -2
  105. package/lib/integrations/installation/pi-setup.js +1 -1
  106. package/lib/model/history.d.ts +133 -34
  107. package/lib/model/plugin-host.d.ts +26 -0
  108. package/lib/model/workspace-config.d.ts +25 -0
  109. package/lib/plugin.js +2 -2
  110. package/lib/services/agents/agent-run.d.ts +1 -1
  111. package/lib/services/history/history-capture.d.ts +4 -0
  112. package/lib/services/history/history-capture.js +86 -0
  113. package/lib/services/history/history-index.d.ts +16 -7
  114. package/lib/services/history/history-index.js +48 -70
  115. package/lib/services/history/history-migrate.d.ts +12 -0
  116. package/lib/services/history/history-migrate.js +88 -0
  117. package/lib/services/history/history-query.d.ts +51 -0
  118. package/lib/services/history/history-query.js +371 -0
  119. package/lib/services/history/summary-command.d.ts +20 -0
  120. package/lib/services/history/summary-command.js +68 -0
  121. package/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
  122. package/lib/services/history/summary-dimensions/monthly.js +121 -0
  123. package/lib/services/history/summary-dimensions/session.d.ts +7 -0
  124. package/lib/services/history/summary-dimensions/session.js +124 -0
  125. package/lib/services/history/summary-registry.d.ts +7 -0
  126. package/lib/services/history/summary-registry.js +36 -0
  127. package/lib/services/history/summary-runner.d.ts +37 -0
  128. package/lib/services/history/summary-runner.js +301 -0
  129. package/lib/services/workspace/workspace-config.d.ts +5 -1
  130. package/lib/services/workspace/workspace-config.js +75 -4
  131. package/lib/storage/history-files.d.ts +45 -9
  132. package/lib/storage/history-files.js +373 -247
  133. package/lib/storage/history-format.d.ts +3 -12
  134. package/lib/storage/history-format.js +26 -50
  135. package/lib/tools/history/actions.d.ts +3 -68
  136. package/lib/tools/history/actions.js +7 -5
  137. package/lib/tools/history/contract.d.ts +14 -7
  138. package/lib/tools/history/contract.js +58 -18
  139. package/lib/tools/history/dsh-tool.d.ts +1 -2
  140. package/lib/tools/history/dsh-tool.js +11 -5
  141. package/lib/ui/dsh/management.js +18 -5
  142. package/package.json +1 -1
  143. package/resources/prompts/history-coordinator.md +1 -1
  144. package/resources/prompts/history-monthly-summary.md +13 -0
  145. package/resources/prompts/history-summary.md +10 -4
  146. package/resources/skills/provider-connections/SKILL.md +22 -12
  147. package/src/claude.ts +2 -2
  148. package/src/dsh.ts +4 -4
  149. package/src/extension/{acp-member.ts → acp/member.ts} +7 -7
  150. package/src/extension/{acp-worker.ts → acp/worker.ts} +131 -17
  151. package/src/extension/{dsh → hosts/dsh}/acp-member.ts +9 -9
  152. package/src/extension/hosts/dsh/command.ts +92 -0
  153. package/src/extension/{dsh → hosts/dsh}/files.ts +3 -3
  154. package/src/extension/hosts/dsh/history.ts +67 -0
  155. package/src/extension/{dsh → hosts/dsh}/management.ts +11 -9
  156. package/src/extension/{dsh → hosts/dsh}/workspace.ts +31 -50
  157. package/src/extension/{pi-acp-member.ts → hosts/pi/acp-member.ts} +9 -9
  158. package/src/extension/hosts/pi/command.ts +158 -0
  159. package/src/extension/{events.ts → hosts/pi/events.ts} +14 -4
  160. package/src/extension/hosts/pi/history.ts +45 -0
  161. package/src/extension/{lifecycle.ts → hosts/pi/lifecycle.ts} +7 -11
  162. package/src/extension/{plugin-runtime.ts → hosts/plugin-runtime.ts} +29 -9
  163. package/src/extension/{mcp-bridge.ts → mcp/bridge.ts} +5 -5
  164. package/src/extension/{mcp-workers.ts → mcp/workers.ts} +237 -64
  165. package/src/extension/{setup-cli.ts → setup/cli.ts} +11 -11
  166. package/src/integrations/acp/connection.ts +6 -0
  167. package/src/integrations/acp/harnesses/claude.ts +1 -1
  168. package/src/integrations/acp/harnesses/dsh.ts +1 -1
  169. package/src/integrations/acp/history-summary.ts +108 -0
  170. package/src/integrations/agent-resources.ts +6 -0
  171. package/src/integrations/hosts/antigravity/adapter.ts +161 -0
  172. package/src/integrations/hosts/{claude.ts → claude/adapter.ts} +28 -5
  173. package/src/integrations/{dsh → hosts/dsh}/mcp.ts +1 -1
  174. package/src/integrations/{dsh → hosts/dsh}/resources.ts +5 -5
  175. package/src/integrations/{dsh → hosts/dsh}/schema.ts +1 -1
  176. package/src/integrations/{dsh → hosts/dsh}/session.ts +2 -2
  177. package/src/integrations/{dsh → hosts/dsh}/skills.ts +1 -1
  178. package/src/integrations/{pi → hosts/pi}/mcp.ts +1 -1
  179. package/src/integrations/{pi → hosts/pi}/skills.ts +1 -1
  180. package/src/integrations/hosts/{registry.ts → plugin-registry.ts} +2 -2
  181. package/src/integrations/installation/pi-setup.ts +1 -1
  182. package/src/mcp.ts +1 -1
  183. package/src/model/history.ts +151 -26
  184. package/src/model/plugin-host.ts +26 -2
  185. package/src/model/workspace-config.ts +30 -0
  186. package/src/pbot.ts +13 -22
  187. package/src/plugin.ts +2 -2
  188. package/src/services/history/history-capture.ts +83 -0
  189. package/src/services/history/history-index.ts +48 -62
  190. package/src/services/history/history-migrate.ts +89 -0
  191. package/src/services/history/history-query.ts +415 -0
  192. package/src/services/history/summary-command.ts +69 -0
  193. package/src/services/history/summary-dimensions/monthly.ts +139 -0
  194. package/src/services/history/summary-dimensions/session.ts +149 -0
  195. package/src/services/history/summary-registry.ts +44 -0
  196. package/src/services/history/summary-runner.ts +352 -0
  197. package/src/services/workspace/workspace-config.ts +93 -5
  198. package/src/storage/history-files.ts +408 -188
  199. package/src/storage/history-format.ts +46 -60
  200. package/src/tools/history/actions.ts +8 -6
  201. package/src/tools/history/contract.ts +65 -20
  202. package/src/tools/history/dsh-tool.ts +17 -8
  203. package/src/tools/history/pi-tool.ts +21 -0
  204. package/src/tools/register.ts +3 -4
  205. package/src/ui/dsh/management.ts +27 -11
  206. package/src/ui/{confirmation.ts → pi/confirmation.ts} +1 -1
  207. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.d.ts +0 -4
  208. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.js +0 -79
  209. package/lib/extension/dsh/command.js +0 -50
  210. package/lib/extension/dsh/history.d.ts +0 -15
  211. package/lib/extension/dsh/history.js +0 -87
  212. package/lib/integrations/dsh/history-summary.d.ts +0 -11
  213. package/lib/integrations/dsh/history-summary.js +0 -36
  214. package/lib/integrations/dsh/history.d.ts +0 -16
  215. package/lib/integrations/dsh/history.js +0 -167
  216. package/lib/integrations/history-summary.d.ts +0 -4
  217. package/lib/integrations/history-summary.js +0 -32
  218. package/lib/integrations/hosts/antigravity.d.ts +0 -4
  219. package/lib/integrations/hosts/antigravity.js +0 -79
  220. package/lib/services/history/history-service.d.ts +0 -106
  221. package/lib/services/history/history-service.js +0 -242
  222. package/lib/storage/acp-history.d.ts +0 -10
  223. package/lib/storage/acp-history.js +0 -57
  224. package/src/extension/command.ts +0 -76
  225. package/src/extension/dsh/command.ts +0 -54
  226. package/src/extension/dsh/history.ts +0 -74
  227. package/src/extension/history.ts +0 -26
  228. package/src/integrations/dsh/history-summary.ts +0 -39
  229. package/src/integrations/dsh/history.ts +0 -84
  230. package/src/integrations/history-summary.ts +0 -30
  231. package/src/integrations/hosts/antigravity.ts +0 -83
  232. package/src/integrations/pi/history.ts +0 -99
  233. package/src/services/history/history-service.ts +0 -195
  234. package/src/storage/acp-history.ts +0 -49
  235. package/src/tools/history/tool.ts +0 -19
  236. /package/lib/antigravity-plugin/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +0 -0
  237. /package/lib/{extension/acp-worker.d.ts → antigravity-plugin/lib/model/history.js} +0 -0
  238. /package/lib/extension/{dsh → hosts/dsh}/acp-member.d.ts +0 -0
  239. /package/lib/extension/{dsh → hosts/dsh}/command.d.ts +0 -0
  240. /package/lib/extension/{dsh → hosts/dsh}/files.d.ts +0 -0
  241. /package/lib/extension/{setup-guard.js → setup/guard.js} +0 -0
  242. /package/lib/integrations/acp/{claude.d.ts → claude-settings.d.ts} +0 -0
  243. /package/lib/integrations/acp/{claude.js → claude-settings.js} +0 -0
  244. /package/lib/integrations/{dsh → hosts/dsh}/mcp.js +0 -0
  245. /package/lib/integrations/{dsh → hosts/dsh}/messages.d.ts +0 -0
  246. /package/lib/integrations/{dsh → hosts/dsh}/messages.js +0 -0
  247. /package/lib/integrations/{dsh → hosts/dsh}/root-agents.d.ts +0 -0
  248. /package/lib/integrations/{dsh → hosts/dsh}/root-agents.js +0 -0
  249. /package/lib/integrations/{dsh → hosts/dsh}/schema.d.ts +0 -0
  250. /package/lib/integrations/{dsh → hosts/dsh}/skills.d.ts +0 -0
  251. /package/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +0 -0
  252. /package/src/extension/{setup-guard.ts → setup/guard.ts} +0 -0
  253. /package/src/integrations/acp/{claude.ts → claude-settings.ts} +0 -0
  254. /package/src/integrations/{dsh → hosts/dsh}/messages.ts +0 -0
  255. /package/src/integrations/{dsh → hosts/dsh}/root-agents.ts +0 -0
  256. /package/src/integrations/{pi → hosts/pi}/agent-tools.ts +0 -0
@@ -0,0 +1,158 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import { packageVersion } from "../../../common/version.js";
3
+ import { requireThat } from "../../../common/validation.js";
4
+ import { createAcpHistorySummarizer } from "../../../integrations/acp/history-summary.js";
5
+ import { migrateWorkspaceHistory } from "../../../services/history/history-migrate.js";
6
+ import { parseHistoryCommand } from "../../../services/history/summary-command.js";
7
+ import { listSummaryDimensions } from "../../../services/history/summary-registry.js";
8
+ import { inspectWorkspaceSummaries, runWorkspaceSummaries } from "../../../services/history/summary-runner.js";
9
+ import { initializeWorkspace } from "../../../services/workspace/workspace-preparation.js";
10
+ import { readWorkspaceConfig, readWorkspaceHistoryLayoutSync, workspaceDisabledMessage, workspaceSummaryConfig } from "../../../services/workspace/workspace-config.js";
11
+ import { executeHistory } from "../../../tools/history/actions.js";
12
+ import { historyInput } from "../../../tools/history/contract.js";
13
+ import type { Confirmations } from "../../../ui/pi/confirmation.js";
14
+ import type { Lifecycle } from "./lifecycle.js";
15
+ import { parseWorkerCommand } from "../../mcp/workers.js";
16
+
17
+ function formatHistoryStatusLine(root: string): string[] {
18
+ const status = inspectWorkspaceSummaries(root);
19
+ const parts = status.dimensions.map(dim => {
20
+ const pending = dim.pendingCreate + dim.pendingIncremental + dim.pendingRebuild;
21
+ return `${dim.dimension} ${dim.ready}/${dim.total}` + (pending ? `(待处理 ${pending})` : "");
22
+ });
23
+ return [
24
+ `历史 原始会话 ${status.rawCount}` + (parts.length ? ` · ${parts.join(",")}` : ""),
25
+ ...(status.reminder ? [`提示 ${status.reminder.message}`] : []),
26
+ ...status.warnings,
27
+ ];
28
+ }
29
+
30
+ export function registerCommand(pi: ExtensionAPI, lifecycle: Lifecycle, confirmations: Confirmations) {
31
+ pi.registerCommand("pbot", {
32
+ description: "工作区初始化、状态、历史摘要与跨 Harness worker 管理",
33
+ getArgumentCompletions: prefix => {
34
+ if (/\s/.test(prefix)) return null;
35
+ return ["init", "status", "history", "worker"]
36
+ .filter(command => command.startsWith(prefix)).map(command => ({ value: command, label: command }));
37
+ },
38
+ handler: async (args, ctx) => {
39
+ const [, command, argument = ""] = args.trim().match(/^(\S+)(?:\s+([\s\S]*))?$/) ?? [];
40
+ confirmations.resume();
41
+ if (command === "init" && !argument) {
42
+ await ctx.waitForIdle();
43
+ const start = !lifecycle.active;
44
+ await initializeWorkspace(lifecycle.root ?? ctx.cwd);
45
+ ctx.ui.notify(start ? "工作区已初始化并启用,正在加载 Personal Bot。" : "资料目录已准备;新建的 AGENTS.md 经 /reload 加载。", "info");
46
+ if (start) await ctx.reload();
47
+ return;
48
+ }
49
+ if (!lifecycle.active) {
50
+ const configuration = lifecycle.configuration;
51
+ const status = {
52
+ workspaceRoot: lifecycle.root ?? ctx.cwd,
53
+ release: packageVersion,
54
+ enabled: false,
55
+ state: configuration?.error || configuration?.enabled ? "error" : "disabled",
56
+ nextStep: configuration?.error ?? "/pbot init",
57
+ configuration,
58
+ };
59
+ ctx.ui.notify(command === "status" ? JSON.stringify(status, null, 2)
60
+ : configuration ? workspaceDisabledMessage(configuration) : "pbot 工作区实例不可用。", configuration?.error ? "error" : "info");
61
+ return;
62
+ }
63
+ const instance = lifecycle.get();
64
+ if (command === "status" && !argument) {
65
+ if (ctx.mode !== "tui") {
66
+ ctx.ui.notify(JSON.stringify({
67
+ workspaceRoot: instance.root,
68
+ release: packageVersion,
69
+ enabled: true,
70
+ state: "running",
71
+ configuration: lifecycle.configuration,
72
+ ...(instance.features.history ? { history: inspectWorkspaceSummaries(instance.root) } : {}),
73
+ }, null, 2), "info");
74
+ return;
75
+ }
76
+ ctx.ui.notify([
77
+ `工作区 ${instance.root}`,
78
+ `状态 已启动 · 版本 ${packageVersion}`,
79
+ ...(instance.features.history ? formatHistoryStatusLine(instance.root) : ["历史 已停用"]),
80
+ ].join("\n"), "info");
81
+ return;
82
+ }
83
+ if (command === "history") {
84
+ try {
85
+ requireThat(instance.features.history, "当前工作区已停用历史功能(features.history: false)。");
86
+ const parsed = parseHistoryCommand(argument);
87
+ if (parsed.kind === "status") {
88
+ ctx.ui.notify(JSON.stringify(inspectWorkspaceSummaries(instance.root), null, 2), "info");
89
+ return;
90
+ }
91
+ if (parsed.kind === "list") {
92
+ const layout = readWorkspaceHistoryLayoutSync(instance.root);
93
+ const dims = listSummaryDimensions(layout).map(({ id, title, description }) => ({ id, title, description }));
94
+ ctx.ui.notify(JSON.stringify({ layout, dimensions: dims }, null, 2), "info");
95
+ return;
96
+ }
97
+ if (parsed.kind === "migrate") {
98
+ const report = migrateWorkspaceHistory(instance.root, { dryRun: parsed.dryRun });
99
+ ctx.ui.notify(JSON.stringify(report, null, 2), "info");
100
+ return;
101
+ }
102
+ if (parsed.kind === "query") {
103
+ const result = executeHistory(instance.root, historyInput(parsed.input), instance.signal());
104
+ ctx.ui.notify(JSON.stringify(result, null, 2), "info");
105
+ return;
106
+ }
107
+ const signal = instance.signal();
108
+ const config = await readWorkspaceConfig(instance.root);
109
+ requireThat(config.enabled && !config.error, workspaceDisabledMessage(config));
110
+ const summaryCfg = workspaceSummaryConfig(config);
111
+ const backend = parsed.backend ?? summaryCfg.backend;
112
+ const model = parsed.model ?? summaryCfg.model;
113
+ const thinking = parsed.thinking ?? summaryCfg.thinking;
114
+ const summarizer = createAcpHistorySummarizer({
115
+ cwd: instance.root,
116
+ backend,
117
+ ...(config.acp ? { commands: config.acp } : {}),
118
+ ...(model ? { model } : {}),
119
+ ...(thinking ? { thinking } : {}),
120
+ });
121
+ ctx.ui.setStatus("pbot-history", `历史摘要生成中 (${backend})`);
122
+ try {
123
+ const report = await runWorkspaceSummaries({
124
+ root: instance.root,
125
+ summarizer,
126
+ ...(parsed.dimensions ? { dimensions: parsed.dimensions } : {}),
127
+ force: parsed.force,
128
+ ...(summaryCfg.concurrency !== undefined ? { concurrency: summaryCfg.concurrency } : {}),
129
+ signal,
130
+ onProgress: progress => {
131
+ if (lifecycle.active === instance) {
132
+ ctx.ui.setStatus("pbot-history", `历史摘要 ${progress.dimension} (${progress.completed}/${progress.total})`);
133
+ }
134
+ },
135
+ });
136
+ ctx.ui.notify(JSON.stringify({ backend, ...(model ? { model } : {}), ...report }, null, 2), "info");
137
+ } finally {
138
+ if (lifecycle.active === instance) ctx.ui.setStatus("pbot-history", undefined);
139
+ }
140
+ } catch (error) {
141
+ ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
142
+ }
143
+ return;
144
+ }
145
+ if (command === "worker") {
146
+ try {
147
+ const { tool, args: payload } = parseWorkerCommand(argument);
148
+ const result = await instance.workers.callTool(tool, { workspace: instance.root, ...payload });
149
+ ctx.ui.notify(JSON.stringify(result, null, 2), "info");
150
+ } catch (error) {
151
+ ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
152
+ }
153
+ return;
154
+ }
155
+ ctx.ui.notify('/pbot init | status | history [summary [维度] [--force] [--backend <acp>] [--model <model>]|migrate [--dry-run]|status|list|JSON] | worker [overview|status|backends|models|create|request|response|output|close] [JSON]', "info");
156
+ },
157
+ });
158
+ }
@@ -2,11 +2,13 @@ import { join, resolve } from "node:path";
2
2
  import { homedir } from "node:os";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
5
- import { loadWorkspaceContext } from "../integrations/agent-resources.js";
6
- import type { Confirmations } from "../ui/confirmation.js";
5
+ import { loadWorkspaceContext } from "../../../integrations/agent-resources.js";
6
+ import type { Confirmations } from "../../../ui/pi/confirmation.js";
7
7
  import type { Lifecycle } from "./lifecycle.js";
8
- import { readWorkspaceConfig, workspaceDisabledMessage } from "../services/workspace/workspace-config.js";
9
- import { workspaceSkillPaths } from "../integrations/pi/skills.js";
8
+ import { readWorkspaceConfig, workspaceDisabledMessage } from "../../../services/workspace/workspace-config.js";
9
+ import { checkHistoryMigrationNotice } from "../../../services/history/history-migrate.js";
10
+ import { checkHistorySummaryReminder } from "../../../services/history/summary-runner.js";
11
+ import { workspaceSkillPaths } from "../../../integrations/hosts/pi/skills.js";
10
12
 
11
13
  export function registerEvents(pi: ExtensionAPI, lifecycle: Lifecycle, confirmations: Confirmations) {
12
14
  pi.on("session_start", async (_event, ctx) => {
@@ -18,6 +20,14 @@ export function registerEvents(pi: ExtensionAPI, lifecycle: Lifecycle, confirmat
18
20
  return;
19
21
  }
20
22
  ctx.ui.setStatus("pbot", "PBot 已启动");
23
+ if (lifecycle.active.features.history && ctx.hasUI) {
24
+ try {
25
+ const migrationNotice = checkHistoryMigrationNotice(lifecycle.active.root);
26
+ if (migrationNotice) ctx.ui.notify(migrationNotice, "info");
27
+ const reminder = checkHistorySummaryReminder(lifecycle.active.root);
28
+ if (reminder) ctx.ui.notify(reminder.message, "info");
29
+ } catch { /* Never block session startup if history reminder probe fails. */ }
30
+ }
21
31
  } catch (error) {
22
32
  ctx.ui.setStatus("pbot", "PBot 启动失败");
23
33
  if (ctx.hasUI) ctx.ui.notify(error instanceof Error ? error.message : "pbot 启动失败。", "error");
@@ -0,0 +1,45 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import { recordHistoryCapture } from "../../../services/history/history-capture.js";
3
+ import type { Lifecycle } from "./lifecycle.js";
4
+
5
+ function messageText(content: unknown): string {
6
+ if (typeof content === "string") return content;
7
+ if (!Array.isArray(content)) return "";
8
+ return content.flatMap(block => block?.type === "text" ? [String(block.text)] : block?.type === "image" ? ["[图片]"] : []).join("\n");
9
+ }
10
+
11
+ /** Capture main-session raw Q&A exchanges into .pbot/history/raw/. Summaries run on explicit trigger. */
12
+ export function registerHistoryEvents(pi: ExtensionAPI, lifecycle: Lifecycle) {
13
+ pi.on("before_agent_start", (event, ctx) => {
14
+ const instance = lifecycle.active;
15
+ if (!instance || !instance.features.history || event.messageType !== "user") return;
16
+ const text = event.prompt.trim();
17
+ if (!text) return;
18
+ try {
19
+ recordHistoryCapture(instance.root, "pi", {
20
+ kind: "input",
21
+ sessionId: ctx.sessionManager.getSessionId(),
22
+ text,
23
+ });
24
+ } catch { /* Never block a user turn if history persistence fails. */ }
25
+ });
26
+
27
+ pi.on("agent_end", (event, ctx) => {
28
+ const instance = lifecycle.active;
29
+ if (!instance || !instance.features.history) return;
30
+ const assistant = [...event.messages].reverse().find(message => message.role === "assistant");
31
+ if (!assistant || !("content" in assistant)) return;
32
+ const text = messageText(assistant.content).trim();
33
+ if (!text) return;
34
+ const completed = "stopReason" in assistant && assistant.stopReason === "stop" &&
35
+ !(Array.isArray(assistant.content) && assistant.content.some(block => block.type === "toolCall"));
36
+ try {
37
+ recordHistoryCapture(instance.root, "pi", {
38
+ kind: "answer",
39
+ sessionId: ctx.sessionManager.getSessionId(),
40
+ assistantText: text,
41
+ completed,
42
+ });
43
+ } catch { /* Never block turn completion if history persistence fails. */ }
44
+ });
45
+ }
@@ -1,11 +1,10 @@
1
1
  import { realpath } from "node:fs/promises";
2
- import { requireThat } from "../common/validation.js";
3
- import { authorizeMutation } from "../services/workspace/workspace-files.js";
4
- import type { CallAccess } from "../tools/access.js";
5
- import type { HistoryService } from "../services/history/history-service.js";
6
- import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../services/workspace/workspace-config.js";
7
- import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration } from "../model/workspace-config.js";
8
- import type { McpWorkerRuntime } from "./mcp-workers.js";
2
+ import { requireThat } from "../../../common/validation.js";
3
+ import { authorizeMutation } from "../../../services/workspace/workspace-files.js";
4
+ import type { CallAccess } from "../../../tools/access.js";
5
+ import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../../services/workspace/workspace-config.js";
6
+ import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration } from "../../../model/workspace-config.js";
7
+ import type { McpWorkerRuntime } from "../../mcp/workers.js";
9
8
 
10
9
  export class WorkspaceInstance implements CallAccess {
11
10
  readonly #controller = new AbortController();
@@ -15,7 +14,6 @@ export class WorkspaceInstance implements CallAccess {
15
14
  constructor(
16
15
  readonly root: string,
17
16
  readonly sessionId: string,
18
- readonly history: HistoryService,
19
17
  readonly workers: McpWorkerRuntime,
20
18
  readonly features: ResolvedWorkspaceFeatures = workspaceFeatures(),
21
19
  ) {}
@@ -45,9 +43,7 @@ export class WorkspaceInstance implements CallAccess {
45
43
  this.#controller.abort();
46
44
  this.#work.abort();
47
45
  this.#closing = (async () => {
48
- const results = await Promise.allSettled([this.workers.close(preserveWorkers), this.history.close()]);
49
- const errors = results.filter(result => result.status === "rejected").map(result => result.reason);
50
- if (errors.length) throw new AggregateError(errors, "工作区关闭失败。");
46
+ await this.workers.close(preserveWorkers);
51
47
  })();
52
48
  return this.#closing;
53
49
  }
@@ -1,11 +1,14 @@
1
- import { resourceRoot } from "../common/paths.js";
2
- import { packageVersion } from "../common/version.js";
3
- import { requireThat } from "../common/validation.js";
4
- import { loadWorkspaceContext } from "../integrations/agent-resources.js";
5
- import type { PluginHostAdapter } from "../model/plugin-host.js";
6
- import { readWorkspaceConfig, workspaceFeatures } from "../services/workspace/workspace-config.js";
7
- import { initializeWorkspace } from "../services/workspace/workspace-preparation.js";
8
- import { discoverWorkspaceSkills } from "../services/workspace/workspace-skills.js";
1
+ import { resourceRoot } from "../../common/paths.js";
2
+ import { packageVersion } from "../../common/version.js";
3
+ import { requireThat } from "../../common/validation.js";
4
+ import { loadWorkspaceContext } from "../../integrations/agent-resources.js";
5
+ import type { PluginHostAdapter } from "../../model/plugin-host.js";
6
+ import { recordHistoryCapture } from "../../services/history/history-capture.js";
7
+ import { checkHistoryMigrationNotice } from "../../services/history/history-migrate.js";
8
+ import { checkHistorySummaryReminder } from "../../services/history/summary-runner.js";
9
+ import { readWorkspaceConfig, workspaceFeatures } from "../../services/workspace/workspace-config.js";
10
+ import { initializeWorkspace } from "../../services/workspace/workspace-preparation.js";
11
+ import { discoverWorkspaceSkills } from "../../services/workspace/workspace-skills.js";
9
12
 
10
13
  function disabledMessage(adapter: PluginHostAdapter, configuration: Awaited<ReturnType<typeof readWorkspaceConfig>>) {
11
14
  return configuration.error ?? `Personal Bot 未在此工作区启用。运行 ${adapter.initCommandHint};配置文件:${configuration.path}`;
@@ -45,10 +48,26 @@ export async function pluginHook(adapter: PluginHostAdapter, payload: unknown):
45
48
  return adapter.formatPass(payload);
46
49
  }
47
50
  if (!configuration.enabled) return adapter.formatPass(payload);
51
+ if (features.history && adapter.extractHistory) {
52
+ try {
53
+ const capture = await adapter.extractHistory(event);
54
+ if (capture) recordHistoryCapture(root, adapter.host, capture);
55
+ } catch { /* Never block a host turn if history persistence encounters a transient error or busy lock. */ }
56
+ }
57
+ if (event.kind === "record-history") return adapter.formatPass(payload);
48
58
  const workspaceSkills = features.skills && !adapter.nativeWorkspaceSkills
49
59
  ? await discoverWorkspaceSkills(root)
50
60
  : [];
51
- if (!features.prompts && !workspaceSkills.length) return adapter.formatPass(payload);
61
+ const notices: string[] = [];
62
+ if (event.isSessionStart && features.history) {
63
+ try {
64
+ const migrationNotice = checkHistoryMigrationNotice(root);
65
+ if (migrationNotice) notices.push(migrationNotice);
66
+ const reminder = checkHistorySummaryReminder(root);
67
+ if (reminder) notices.push(reminder.message);
68
+ } catch { /* Never block session start if history reminder probe fails. */ }
69
+ }
70
+ if (!features.prompts && !workspaceSkills.length && !notices.length) return adapter.formatPass(payload);
52
71
  const context = await loadWorkspaceContext({
53
72
  host: adapter.host,
54
73
  root,
@@ -58,6 +77,7 @@ export async function pluginHook(adapter: PluginHostAdapter, payload: unknown):
58
77
  includeRootAgents: features.prompts && !adapter.nativeRootAgents,
59
78
  ...(event.localRoleOnly ? { localRoleOnly: true } : {}),
60
79
  workspaceSkills,
80
+ notices,
61
81
  });
62
82
  return adapter.formatContext(event, context);
63
83
  }
@@ -1,18 +1,18 @@
1
1
  import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
2
2
  import { setTimeout as delay } from "node:timers/promises";
3
- import { object } from "../common/json.js";
4
- import { requireThat } from "../common/validation.js";
5
- import { packageVersion } from "../common/version.js";
3
+ import { object } from "../../common/json.js";
4
+ import { requireThat } from "../../common/validation.js";
5
+ import { packageVersion } from "../../common/version.js";
6
6
  import type {
7
7
  ResolvedWorkspaceMcpHttpServer,
8
8
  ResolvedWorkspaceMcpServer,
9
9
  ResolvedWorkspaceMcpStdioServer,
10
- } from "../model/workspace-mcp.js";
10
+ } from "../../model/workspace-mcp.js";
11
11
  import {
12
12
  readWorkspaceMcpConfig,
13
13
  resolveWorkspaceMcpServer,
14
14
  resolveWorkspaceMcpServers,
15
- } from "../services/workspace/workspace-mcp.js";
15
+ } from "../../services/workspace/workspace-mcp.js";
16
16
 
17
17
  const protocolVersion = "2025-03-26";
18
18
  const maxStderrBytes = 4096;