personal-bot 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (256) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +1 -1
  4. package/README.zh-CN.md +1 -1
  5. package/bin/pbot-pi-acp.mjs +27 -11
  6. package/bin/pbot.mjs +1 -1
  7. package/docs/README.md +1 -1
  8. package/docs/architecture/design.md +23 -10
  9. package/docs/architecture/extensibility.md +20 -18
  10. package/docs/architecture/model-context.md +2 -2
  11. package/docs/architecture/principles.md +4 -3
  12. package/docs/guides/capabilities.md +3 -3
  13. package/docs/guides/history.md +50 -16
  14. package/docs/guides/workspace-configuration.md +31 -6
  15. package/docs/hosts/antigravity.md +2 -0
  16. package/docs/hosts/claude-code.md +1 -1
  17. package/docs/hosts/dsh.md +1 -1
  18. package/docs/hosts/pi.md +1 -1
  19. package/hooks/hooks.json +3 -0
  20. package/lib/antigravity-plugin/hooks.json +7 -0
  21. package/lib/antigravity-plugin/lib/claude.js +2 -2
  22. package/lib/antigravity-plugin/lib/extension/acp-worker.js +156 -11
  23. package/lib/antigravity-plugin/lib/extension/{plugin-runtime.d.ts → hosts/plugin-runtime.d.ts} +2 -2
  24. package/lib/antigravity-plugin/lib/extension/{plugin-runtime.js → hosts/plugin-runtime.js} +34 -8
  25. package/lib/antigravity-plugin/lib/extension/mcp.js +1113 -78
  26. package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +1 -0
  27. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +5 -1
  28. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
  29. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.js +171 -0
  30. package/lib/antigravity-plugin/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
  31. package/lib/antigravity-plugin/lib/integrations/hosts/{claude.js → claude/adapter.js} +32 -4
  32. package/lib/antigravity-plugin/lib/integrations/hosts/{registry.js → plugin-registry.js} +2 -2
  33. package/lib/antigravity-plugin/lib/model/history.d.ts +169 -0
  34. package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +26 -0
  35. package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +25 -0
  36. package/lib/antigravity-plugin/lib/plugin.js +2 -2
  37. package/lib/antigravity-plugin/lib/services/history/history-capture.d.ts +4 -0
  38. package/lib/antigravity-plugin/lib/services/history/history-capture.js +86 -0
  39. package/lib/antigravity-plugin/lib/services/history/history-index.d.ts +17 -0
  40. package/lib/antigravity-plugin/lib/services/history/history-index.js +112 -0
  41. package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +12 -0
  42. package/lib/antigravity-plugin/lib/services/history/history-migrate.js +88 -0
  43. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
  44. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.js +121 -0
  45. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.d.ts +7 -0
  46. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.js +124 -0
  47. package/lib/antigravity-plugin/lib/services/history/summary-registry.d.ts +7 -0
  48. package/lib/antigravity-plugin/lib/services/history/summary-registry.js +36 -0
  49. package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +37 -0
  50. package/lib/antigravity-plugin/lib/services/history/summary-runner.js +301 -0
  51. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +5 -1
  52. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +75 -4
  53. package/lib/antigravity-plugin/lib/storage/file-access.d.ts +2 -0
  54. package/lib/antigravity-plugin/lib/storage/file-access.js +26 -0
  55. package/lib/antigravity-plugin/lib/storage/history-files.d.ts +54 -0
  56. package/lib/antigravity-plugin/lib/storage/history-files.js +467 -0
  57. package/lib/antigravity-plugin/lib/storage/history-format.d.ts +6 -0
  58. package/lib/antigravity-plugin/lib/storage/history-format.js +62 -0
  59. package/lib/antigravity-plugin/package.json +1 -1
  60. package/lib/antigravity-plugin/plugin.json +1 -1
  61. package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +22 -12
  62. package/lib/claude.js +2 -2
  63. package/lib/client.js +21 -11
  64. package/lib/dsh.js +4 -4
  65. package/lib/extension/{acp-member.d.ts → acp/member.d.ts} +5 -5
  66. package/lib/extension/{acp-member.js → acp/member.js} +6 -6
  67. package/lib/extension/acp/worker.d.ts +1 -0
  68. package/lib/extension/acp/worker.js +384 -0
  69. package/lib/extension/acp-worker.js +156 -11
  70. package/lib/extension/{dsh → hosts/dsh}/acp-member.js +8 -8
  71. package/lib/extension/hosts/dsh/command.js +92 -0
  72. package/lib/extension/{dsh → hosts/dsh}/files.js +3 -3
  73. package/lib/extension/hosts/dsh/history.d.ts +4 -0
  74. package/lib/extension/hosts/dsh/history.js +62 -0
  75. package/lib/extension/{dsh → hosts/dsh}/management.d.ts +1 -1
  76. package/lib/extension/{dsh → hosts/dsh}/management.js +12 -10
  77. package/lib/extension/{dsh → hosts/dsh}/workspace.d.ts +3 -9
  78. package/lib/extension/{dsh → hosts/dsh}/workspace.js +32 -70
  79. package/lib/extension/{plugin-runtime.d.ts → hosts/plugin-runtime.d.ts} +2 -2
  80. package/lib/extension/{plugin-runtime.js → hosts/plugin-runtime.js} +34 -8
  81. package/lib/extension/{mcp-bridge.d.ts → mcp/bridge.d.ts} +1 -1
  82. package/lib/extension/{mcp-bridge.js → mcp/bridge.js} +4 -4
  83. package/lib/extension/{mcp-workers.d.ts → mcp/workers.d.ts} +222 -2
  84. package/lib/extension/{mcp-workers.js → mcp/workers.js} +229 -63
  85. package/lib/extension/mcp.js +1113 -78
  86. package/lib/extension/{setup-cli.js → setup/cli.js} +9 -9
  87. package/lib/integrations/acp/connection.d.ts +11 -10
  88. package/lib/integrations/acp/connection.js +6 -0
  89. package/lib/integrations/acp/harnesses/claude.js +1 -1
  90. package/lib/integrations/acp/harnesses/dsh.js +1 -1
  91. package/lib/integrations/acp/history-summary.d.ts +17 -0
  92. package/lib/integrations/acp/history-summary.js +100 -0
  93. package/lib/integrations/agent-resources.d.ts +1 -0
  94. package/lib/integrations/agent-resources.js +5 -1
  95. package/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
  96. package/lib/integrations/hosts/antigravity/adapter.js +171 -0
  97. package/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
  98. package/lib/integrations/hosts/{claude.js → claude/adapter.js} +32 -4
  99. package/lib/integrations/{dsh → hosts/dsh}/mcp.d.ts +1 -1
  100. package/lib/integrations/{dsh → hosts/dsh}/resources.d.ts +1 -1
  101. package/lib/integrations/{dsh → hosts/dsh}/resources.js +4 -4
  102. package/lib/integrations/{dsh → hosts/dsh}/schema.js +1 -1
  103. package/lib/integrations/{dsh → hosts/dsh}/skills.js +1 -1
  104. package/lib/integrations/hosts/{registry.js → plugin-registry.js} +2 -2
  105. package/lib/integrations/installation/pi-setup.js +1 -1
  106. package/lib/model/history.d.ts +133 -34
  107. package/lib/model/plugin-host.d.ts +26 -0
  108. package/lib/model/workspace-config.d.ts +25 -0
  109. package/lib/plugin.js +2 -2
  110. package/lib/services/agents/agent-run.d.ts +1 -1
  111. package/lib/services/history/history-capture.d.ts +4 -0
  112. package/lib/services/history/history-capture.js +86 -0
  113. package/lib/services/history/history-index.d.ts +16 -7
  114. package/lib/services/history/history-index.js +48 -70
  115. package/lib/services/history/history-migrate.d.ts +12 -0
  116. package/lib/services/history/history-migrate.js +88 -0
  117. package/lib/services/history/history-query.d.ts +51 -0
  118. package/lib/services/history/history-query.js +371 -0
  119. package/lib/services/history/summary-command.d.ts +20 -0
  120. package/lib/services/history/summary-command.js +68 -0
  121. package/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
  122. package/lib/services/history/summary-dimensions/monthly.js +121 -0
  123. package/lib/services/history/summary-dimensions/session.d.ts +7 -0
  124. package/lib/services/history/summary-dimensions/session.js +124 -0
  125. package/lib/services/history/summary-registry.d.ts +7 -0
  126. package/lib/services/history/summary-registry.js +36 -0
  127. package/lib/services/history/summary-runner.d.ts +37 -0
  128. package/lib/services/history/summary-runner.js +301 -0
  129. package/lib/services/workspace/workspace-config.d.ts +5 -1
  130. package/lib/services/workspace/workspace-config.js +75 -4
  131. package/lib/storage/history-files.d.ts +45 -9
  132. package/lib/storage/history-files.js +373 -247
  133. package/lib/storage/history-format.d.ts +3 -12
  134. package/lib/storage/history-format.js +26 -50
  135. package/lib/tools/history/actions.d.ts +3 -68
  136. package/lib/tools/history/actions.js +7 -5
  137. package/lib/tools/history/contract.d.ts +14 -7
  138. package/lib/tools/history/contract.js +58 -18
  139. package/lib/tools/history/dsh-tool.d.ts +1 -2
  140. package/lib/tools/history/dsh-tool.js +11 -5
  141. package/lib/ui/dsh/management.js +18 -5
  142. package/package.json +1 -1
  143. package/resources/prompts/history-coordinator.md +1 -1
  144. package/resources/prompts/history-monthly-summary.md +13 -0
  145. package/resources/prompts/history-summary.md +10 -4
  146. package/resources/skills/provider-connections/SKILL.md +22 -12
  147. package/src/claude.ts +2 -2
  148. package/src/dsh.ts +4 -4
  149. package/src/extension/{acp-member.ts → acp/member.ts} +7 -7
  150. package/src/extension/{acp-worker.ts → acp/worker.ts} +131 -17
  151. package/src/extension/{dsh → hosts/dsh}/acp-member.ts +9 -9
  152. package/src/extension/hosts/dsh/command.ts +92 -0
  153. package/src/extension/{dsh → hosts/dsh}/files.ts +3 -3
  154. package/src/extension/hosts/dsh/history.ts +67 -0
  155. package/src/extension/{dsh → hosts/dsh}/management.ts +11 -9
  156. package/src/extension/{dsh → hosts/dsh}/workspace.ts +31 -50
  157. package/src/extension/{pi-acp-member.ts → hosts/pi/acp-member.ts} +9 -9
  158. package/src/extension/hosts/pi/command.ts +158 -0
  159. package/src/extension/{events.ts → hosts/pi/events.ts} +14 -4
  160. package/src/extension/hosts/pi/history.ts +45 -0
  161. package/src/extension/{lifecycle.ts → hosts/pi/lifecycle.ts} +7 -11
  162. package/src/extension/{plugin-runtime.ts → hosts/plugin-runtime.ts} +29 -9
  163. package/src/extension/{mcp-bridge.ts → mcp/bridge.ts} +5 -5
  164. package/src/extension/{mcp-workers.ts → mcp/workers.ts} +237 -64
  165. package/src/extension/{setup-cli.ts → setup/cli.ts} +11 -11
  166. package/src/integrations/acp/connection.ts +6 -0
  167. package/src/integrations/acp/harnesses/claude.ts +1 -1
  168. package/src/integrations/acp/harnesses/dsh.ts +1 -1
  169. package/src/integrations/acp/history-summary.ts +108 -0
  170. package/src/integrations/agent-resources.ts +6 -0
  171. package/src/integrations/hosts/antigravity/adapter.ts +161 -0
  172. package/src/integrations/hosts/{claude.ts → claude/adapter.ts} +28 -5
  173. package/src/integrations/{dsh → hosts/dsh}/mcp.ts +1 -1
  174. package/src/integrations/{dsh → hosts/dsh}/resources.ts +5 -5
  175. package/src/integrations/{dsh → hosts/dsh}/schema.ts +1 -1
  176. package/src/integrations/{dsh → hosts/dsh}/session.ts +2 -2
  177. package/src/integrations/{dsh → hosts/dsh}/skills.ts +1 -1
  178. package/src/integrations/{pi → hosts/pi}/mcp.ts +1 -1
  179. package/src/integrations/{pi → hosts/pi}/skills.ts +1 -1
  180. package/src/integrations/hosts/{registry.ts → plugin-registry.ts} +2 -2
  181. package/src/integrations/installation/pi-setup.ts +1 -1
  182. package/src/mcp.ts +1 -1
  183. package/src/model/history.ts +151 -26
  184. package/src/model/plugin-host.ts +26 -2
  185. package/src/model/workspace-config.ts +30 -0
  186. package/src/pbot.ts +13 -22
  187. package/src/plugin.ts +2 -2
  188. package/src/services/history/history-capture.ts +83 -0
  189. package/src/services/history/history-index.ts +48 -62
  190. package/src/services/history/history-migrate.ts +89 -0
  191. package/src/services/history/history-query.ts +415 -0
  192. package/src/services/history/summary-command.ts +69 -0
  193. package/src/services/history/summary-dimensions/monthly.ts +139 -0
  194. package/src/services/history/summary-dimensions/session.ts +149 -0
  195. package/src/services/history/summary-registry.ts +44 -0
  196. package/src/services/history/summary-runner.ts +352 -0
  197. package/src/services/workspace/workspace-config.ts +93 -5
  198. package/src/storage/history-files.ts +408 -188
  199. package/src/storage/history-format.ts +46 -60
  200. package/src/tools/history/actions.ts +8 -6
  201. package/src/tools/history/contract.ts +65 -20
  202. package/src/tools/history/dsh-tool.ts +17 -8
  203. package/src/tools/history/pi-tool.ts +21 -0
  204. package/src/tools/register.ts +3 -4
  205. package/src/ui/dsh/management.ts +27 -11
  206. package/src/ui/{confirmation.ts → pi/confirmation.ts} +1 -1
  207. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.d.ts +0 -4
  208. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.js +0 -79
  209. package/lib/extension/dsh/command.js +0 -50
  210. package/lib/extension/dsh/history.d.ts +0 -15
  211. package/lib/extension/dsh/history.js +0 -87
  212. package/lib/integrations/dsh/history-summary.d.ts +0 -11
  213. package/lib/integrations/dsh/history-summary.js +0 -36
  214. package/lib/integrations/dsh/history.d.ts +0 -16
  215. package/lib/integrations/dsh/history.js +0 -167
  216. package/lib/integrations/history-summary.d.ts +0 -4
  217. package/lib/integrations/history-summary.js +0 -32
  218. package/lib/integrations/hosts/antigravity.d.ts +0 -4
  219. package/lib/integrations/hosts/antigravity.js +0 -79
  220. package/lib/services/history/history-service.d.ts +0 -106
  221. package/lib/services/history/history-service.js +0 -242
  222. package/lib/storage/acp-history.d.ts +0 -10
  223. package/lib/storage/acp-history.js +0 -57
  224. package/src/extension/command.ts +0 -76
  225. package/src/extension/dsh/command.ts +0 -54
  226. package/src/extension/dsh/history.ts +0 -74
  227. package/src/extension/history.ts +0 -26
  228. package/src/integrations/dsh/history-summary.ts +0 -39
  229. package/src/integrations/dsh/history.ts +0 -84
  230. package/src/integrations/history-summary.ts +0 -30
  231. package/src/integrations/hosts/antigravity.ts +0 -83
  232. package/src/integrations/pi/history.ts +0 -99
  233. package/src/services/history/history-service.ts +0 -195
  234. package/src/storage/acp-history.ts +0 -49
  235. package/src/tools/history/tool.ts +0 -19
  236. /package/lib/antigravity-plugin/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +0 -0
  237. /package/lib/{extension/acp-worker.d.ts → antigravity-plugin/lib/model/history.js} +0 -0
  238. /package/lib/extension/{dsh → hosts/dsh}/acp-member.d.ts +0 -0
  239. /package/lib/extension/{dsh → hosts/dsh}/command.d.ts +0 -0
  240. /package/lib/extension/{dsh → hosts/dsh}/files.d.ts +0 -0
  241. /package/lib/extension/{setup-guard.js → setup/guard.js} +0 -0
  242. /package/lib/integrations/acp/{claude.d.ts → claude-settings.d.ts} +0 -0
  243. /package/lib/integrations/acp/{claude.js → claude-settings.js} +0 -0
  244. /package/lib/integrations/{dsh → hosts/dsh}/mcp.js +0 -0
  245. /package/lib/integrations/{dsh → hosts/dsh}/messages.d.ts +0 -0
  246. /package/lib/integrations/{dsh → hosts/dsh}/messages.js +0 -0
  247. /package/lib/integrations/{dsh → hosts/dsh}/root-agents.d.ts +0 -0
  248. /package/lib/integrations/{dsh → hosts/dsh}/root-agents.js +0 -0
  249. /package/lib/integrations/{dsh → hosts/dsh}/schema.d.ts +0 -0
  250. /package/lib/integrations/{dsh → hosts/dsh}/skills.d.ts +0 -0
  251. /package/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +0 -0
  252. /package/src/extension/{setup-guard.ts → setup/guard.ts} +0 -0
  253. /package/src/integrations/acp/{claude.ts → claude-settings.ts} +0 -0
  254. /package/src/integrations/{dsh → hosts/dsh}/messages.ts +0 -0
  255. /package/src/integrations/{dsh → hosts/dsh}/root-agents.ts +0 -0
  256. /package/src/integrations/{pi → hosts/pi}/agent-tools.ts +0 -0
@@ -1,242 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { isDeepStrictEqual } from "node:util";
4
- import { resourceRoot } from "../../common/paths.js";
5
- import { requireThat } from "../../common/validation.js";
6
- import { historySummaries, historyView, indexHistory, retainHistorySummaries } from "./history-index.js";
7
- const page = (values, offset, limit) => ({ values: values.slice(offset, offset + limit),
8
- nextOffset: offset + limit < values.length ? offset + limit : null });
9
- const brief = ({ host, record }, node) => ({ host, id: node.id, kind: node.kind, sessionId: record.sessionId,
10
- name: record.name, preview: node.text.replace(/\s+/g, " ").slice(0, 100), from: node.from, to: node.to, ready: node.ready, completed: node.completed });
11
- const view = ({ raw, summaries }) => ({ host: raw.host, record: historyView(raw, summaries) });
12
- const summarySource = (node) => [node.id, node.kind, node.level, node.entryIds, node.children, node.text, node.from, node.to, node.completed, node.ready];
13
- function nextSummary(archives) {
14
- for (const { raw, summaries } of archives) {
15
- if (summaries === null)
16
- continue;
17
- const record = historyView(raw, summaries), lookup = new Map(record.nodes.map(node => [node.id, node]));
18
- const node = record.nodes.find(node => node.kind === "summary" && !node.ready && node.children.every(id => lookup.get(id).ready));
19
- if (node)
20
- return { record, node, children: node.children.map(id => lookup.get(id)) };
21
- }
22
- }
23
- /** Validate the exact target and ordered inputs under the source lock. Only publish the derived file. */
24
- export function commitHistorySummary(files, identity, expected, children, text, signal) {
25
- return files.control(() => {
26
- signal?.throwIfAborted();
27
- const current = files.list().find(({ raw }) => raw.host === identity.host && raw.id === identity.id && raw.sessionId === identity.sessionId);
28
- if (!current || current.summaries === null)
29
- return;
30
- const record = historyView(current.raw, current.summaries), lookup = new Map(record.nodes.map(node => [node.id, node]));
31
- const node = lookup.get(expected.id);
32
- if (!node || node.kind !== "summary" || node.ready || !isDeepStrictEqual(summarySource(node), summarySource(expected)) ||
33
- !isDeepStrictEqual(node.children, children.map(child => child.id)))
34
- return;
35
- for (const child of children) {
36
- const input = lookup.get(child.id);
37
- if (!input?.ready || !isDeepStrictEqual(summarySource(input), summarySource(child)))
38
- return;
39
- }
40
- requireThat(text.trim(), "历史摘要为空。");
41
- node.text = text.trim();
42
- node.ready = true;
43
- files.saveSummaries(current.raw, historySummaries(record));
44
- return record;
45
- });
46
- }
47
- export class HistoryService {
48
- root;
49
- files;
50
- source;
51
- otherFiles;
52
- acpSessions;
53
- #records = [];
54
- #closed = false;
55
- #loaded = false;
56
- #refresh;
57
- #work;
58
- #controller = new AbortController();
59
- #sourceWarnings = [];
60
- #summaryError;
61
- constructor(root, files, source, otherFiles = [], acpSessions) {
62
- this.root = root;
63
- this.files = files;
64
- this.source = source;
65
- this.otherFiles = otherFiles;
66
- this.acpSessions = acpSessions;
67
- requireThat((source.host === "pi" || source.host === "dsh") && source.host === files.host &&
68
- new Set([files.host, ...otherFiles.map(value => value.host)]).size === otherFiles.length + 1, "历史来源与归档目录不匹配。");
69
- }
70
- check() { requireThat(!this.#closed, "历史服务已关闭。"); }
71
- get warnings() {
72
- return [...new Set([...this.#sourceWarnings, ...this.files.warnings, ...this.otherFiles.flatMap(value => value.warnings),
73
- ...(this.#summaryError ? [this.files.host + " 摘要:" + this.#summaryError] : [])])];
74
- }
75
- get status() {
76
- return { loaded: this.#loaded, organizing: Boolean(this.#work), pending: this.#loaded ? this.#records.filter(value => value.host === this.files.host)
77
- .reduce((total, value) => total + value.record.nodes.filter(node => node.kind === "summary" && !node.ready).length, 0) : null, warnings: this.warnings };
78
- }
79
- refresh(location, signal) {
80
- this.check();
81
- requireThat(location.host === this.source.host, "历史位置与来源不匹配。");
82
- // Each caller keeps its own cancellation. A closed page cannot cancel a server-owned refresh.
83
- const work = (this.#refresh ?? Promise.resolve()).catch(() => { }).then(() => this.load(location, signal));
84
- this.#refresh = work;
85
- return work.finally(() => { if (this.#refresh === work)
86
- this.#refresh = undefined; });
87
- }
88
- async load(location, signal) {
89
- this.check();
90
- signal?.throwIfAborted();
91
- const warnings = [], records = [];
92
- const warning = (host, error) => { this.check(); signal?.throwIfAborted(); warnings.push(host + ": " + String(error)); };
93
- let known = [], sessions = [];
94
- try {
95
- try {
96
- this.files.migrate(this.root);
97
- }
98
- finally {
99
- known = this.files.list(this.root);
100
- }
101
- const scanned = await this.source.scan(location, signal, this.acpSessions?.().ids[this.files.host]);
102
- sessions = scanned.sessions;
103
- warnings.push(...scanned.warnings.map(value => this.files.host + ": " + value));
104
- }
105
- catch (error) {
106
- warning(this.files.host, error);
107
- }
108
- this.check();
109
- signal?.throwIfAborted();
110
- // The worker binds the actual backend ID before delivery, possibly during the native scan.
111
- const excluded = this.acpSessions?.();
112
- if (excluded) {
113
- warnings.push(...excluded.warnings);
114
- sessions = sessions.filter(session => !excluded.ids[this.files.host].has(session.sessionId));
115
- }
116
- const visible = ({ raw }) => !excluded?.ids[raw.host].has(raw.sessionId);
117
- try {
118
- if (sessions.length) {
119
- const before = new Map(known.map(({ raw }) => [raw.sessionId, raw]));
120
- known = this.files.control(() => {
121
- this.check();
122
- signal?.throwIfAborted();
123
- const current = new Map(this.files.list().map(archive => [archive.raw.sessionId, archive]));
124
- for (const session of sessions) {
125
- const previous = current.get(session.sessionId);
126
- // A damaged raw file may own this session; a damaged summary cannot own a root ID.
127
- if (!previous && this.files.rawWarnings.length)
128
- continue;
129
- if (!isDeepStrictEqual(before.get(session.sessionId), previous?.raw))
130
- continue;
131
- const raw = indexHistory(session, previous?.raw, this.files.host);
132
- if (isDeepStrictEqual(raw, previous?.raw))
133
- continue;
134
- let summaries = previous ? previous.summaries : [];
135
- if (previous && summaries?.length) {
136
- const retained = retainHistorySummaries(previous.raw, raw, summaries);
137
- // Invalidate first: even an interrupted two-file update cannot attach old text to a corrected exchange.
138
- if (!isDeepStrictEqual(summaries, retained))
139
- this.files.saveSummaries(previous.raw, retained);
140
- summaries = retained;
141
- }
142
- this.files.saveRaw(raw);
143
- current.set(session.sessionId, { raw, summaries });
144
- }
145
- return [...current.values()];
146
- });
147
- }
148
- }
149
- catch (error) {
150
- warning(this.files.host, error);
151
- }
152
- records.push(...known.filter(visible).map(view));
153
- for (const files of this.otherFiles) {
154
- try {
155
- records.push(...files.list(this.root).filter(visible).map(view));
156
- }
157
- catch (error) {
158
- warning(files.host, error);
159
- }
160
- }
161
- this.check();
162
- signal?.throwIfAborted();
163
- this.#records = records;
164
- this.#sourceWarnings = warnings;
165
- this.#loaded = true;
166
- }
167
- search({ host, query = "", sessionId, from, to, offset = 0, limit = 20 } = {}) {
168
- this.check();
169
- const needle = query.trim().toLowerCase(), after = from === undefined ? -Infinity : Date.parse(from), before = to === undefined ? Infinity : Date.parse(to);
170
- requireThat(!Number.isNaN(after) && !Number.isNaN(before) && after <= before, "时间范围无效,请使用 ISO 日期或时间。");
171
- const matches = this.#records.filter(value => (!host || value.host === host) && (!sessionId || value.record.sessionId === sessionId)).flatMap(value => value.record.nodes
172
- .filter(node => (needle ? node.kind !== "session" && node.ready && node.text.toLowerCase().includes(needle) : node.kind === "session") &&
173
- Date.parse(node.to) >= after && Date.parse(node.from) <= before)
174
- .map(node => {
175
- const start = Math.max(0, node.text.toLowerCase().indexOf(needle) - 80);
176
- return { ...brief(value, node), parents: node.parents, snippet: node.text.slice(start, start + 400) };
177
- })).sort((a, b) => b.to.localeCompare(a.to) || a.id.localeCompare(b.id));
178
- const result = page(matches, offset, limit);
179
- return { matches: result.values, total: matches.length, nextOffset: result.nextOffset, warnings: this.warnings };
180
- }
181
- find(id, host) {
182
- const values = this.#records.filter(value => (!host || value.host === host) && value.record.nodes.some(node => node.id === id));
183
- requireThat(values.length, "历史节点不存在,请重新搜索。");
184
- requireThat(values.length === 1, "历史节点来源不明确,请指定 host。");
185
- const value = values[0], node = value.record.nodes.find(node => node.id === id);
186
- return { value, node };
187
- }
188
- read(id, offset = 0, limit = 12000, childrenOffset = 0, host) {
189
- this.check();
190
- const { value, node } = this.find(id, host), lookup = new Map(value.record.nodes.map(node => [node.id, node]));
191
- requireThat(offset <= node.text.length, "读取位置超出正文。");
192
- if (offset && /[\uDC00-\uDFFF]/.test(node.text[offset] ?? ""))
193
- offset--;
194
- let end = Math.min(node.text.length, offset + limit);
195
- if (end < node.text.length && /[\uD800-\uDBFF]/.test(node.text[end - 1] ?? ""))
196
- end += end - offset === 1 ? 1 : -1;
197
- const children = page(node.children, childrenOffset, 20);
198
- return { ...brief(value, node), text: node.text.slice(offset, end), totalLength: node.text.length,
199
- nextOffset: end < node.text.length ? end : null,
200
- parents: node.parents.map(id => brief(value, lookup.get(id))), children: children.values.map(id => brief(value, lookup.get(id))),
201
- nextChildrenOffset: children.nextOffset, source: { host: value.host, sessionId: value.record.sessionId, entryIds: node.entryIds }, warnings: this.warnings };
202
- }
203
- /** Retain exact inputs only for this call; model work never holds the source write lock. */
204
- organize(summarize, signal) {
205
- this.check();
206
- const active = AbortSignal.any([signal, this.#controller.signal]);
207
- const run = async () => {
208
- for (;;) {
209
- this.check();
210
- active.throwIfAborted();
211
- const archives = this.files.list(), excluded = this.acpSessions?.().ids[this.files.host];
212
- const pending = nextSummary(archives.filter(({ raw }) => !excluded?.has(raw.sessionId)));
213
- if (!pending)
214
- return;
215
- const { record, node, children } = pending;
216
- const text = await summarize({ system: readFileSync(join(resourceRoot, "prompts/history-summary.md"), "utf8"), maxTokens: 2048,
217
- prompt: children.map(child => `[${child.from} — ${child.to}${child.completed ? "" : ";未完成"}]\n${child.text}`).join("\n\n") }, active);
218
- this.check();
219
- active.throwIfAborted();
220
- const committed = commitHistorySummary(this.files, record, node, children, text, active);
221
- if (!committed)
222
- return;
223
- this.#records = this.#records.map(value => value.host === this.files.host && value.record.id === committed.id ? { host: value.host, record: committed } : value);
224
- }
225
- };
226
- const work = (this.#work ?? Promise.resolve()).catch(() => { }).then(run).then(() => { this.#summaryError = undefined; }).catch(error => {
227
- if (!active.aborted && !this.#closed)
228
- this.#summaryError = String(error);
229
- throw error;
230
- });
231
- this.#work = work;
232
- return work.finally(() => { if (this.#work === work)
233
- this.#work = undefined; });
234
- }
235
- async close() {
236
- this.#closed = true;
237
- this.#controller.abort();
238
- await Promise.allSettled([this.#work, this.#refresh]);
239
- this.#records = [];
240
- this.#loaded = false;
241
- }
242
- }
@@ -1,10 +0,0 @@
1
- import type { HistoryHost } from "../model/history.js";
2
- /** Exclude ACP worker sessions owned by MCP or legacy Pi/dsh control directories from native history. */
3
- export declare function acpHistorySessions(directories?: {
4
- pi?: string;
5
- dsh?: string;
6
- mcp?: string;
7
- }): {
8
- ids: Record<HistoryHost, Set<string>>;
9
- warnings: string[];
10
- };
@@ -1,57 +0,0 @@
1
- import { readdirSync } from "node:fs";
2
- import { homedir } from "node:os";
3
- import { join } from "node:path";
4
- import { fileURLToPath } from "node:url";
5
- import { readJsonFile } from "./atomic-json.js";
6
- import { acpReference } from "./acp-files.js";
7
- import { isHistoryHost } from "./history-format.js";
8
- function memberDirectory(home, host) {
9
- if (host === "pi" && home.startsWith("file://"))
10
- return join(fileURLToPath(home), "pbot/subagents");
11
- const tilde = home === "~" || home.startsWith("~/") || ((host === "dsh" || process.platform === "win32") && home.startsWith("~\\"));
12
- return join(tilde ? join(homedir(), home.slice(2)) : home, "pbot/subagents");
13
- }
14
- function defaultMcpWorkerDirectories() {
15
- const dirs = [join(homedir(), ".pbot/subagents")];
16
- if (process.env.PBOT_MCP_AGENT_DIR)
17
- dirs.push(process.env.PBOT_MCP_AGENT_DIR);
18
- if (process.env.PLUGIN_DATA)
19
- dirs.push(join(process.env.PLUGIN_DATA, "subagents"));
20
- return dirs;
21
- }
22
- /** Exclude ACP worker sessions owned by MCP or legacy Pi/dsh control directories from native history. */
23
- export function acpHistorySessions(directories = {}) {
24
- const ids = { pi: new Set(), dsh: new Set(), claude: new Set() };
25
- const warnings = [];
26
- const warn = (path, error) => {
27
- if (error.code !== "ENOENT")
28
- warnings.push(path + ": " + String(error));
29
- };
30
- const homes = { pi: process.env.PI_CODING_AGENT_DIR || "~/.pi/agent", dsh: process.env.DSH_HOME?.trim() ? process.env.DSH_HOME : "~/.dsh" };
31
- const scanDirs = new Set([
32
- directories.pi ?? memberDirectory(homes.pi, "pi"),
33
- directories.dsh ?? memberDirectory(homes.dsh, "dsh"),
34
- ...(directories.mcp ? [directories.mcp] : defaultMcpWorkerDirectories()),
35
- ]);
36
- for (const directory of scanDirs) {
37
- try {
38
- for (const entry of readdirSync(directory, { withFileTypes: true })) {
39
- if (!entry.isDirectory() || entry.name.startsWith("."))
40
- continue;
41
- const path = join(directory, entry.name);
42
- try {
43
- const ref = readJsonFile(path, "acp-session.json", acpReference);
44
- if (ref.sessionId !== null && isHistoryHost(ref.backend))
45
- ids[ref.backend].add(ref.sessionId);
46
- }
47
- catch (error) {
48
- warn(path, error);
49
- }
50
- }
51
- }
52
- catch (error) {
53
- warn(directory, error);
54
- }
55
- }
56
- return { ids, warnings };
57
- }
@@ -1,76 +0,0 @@
1
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import { packageVersion } from "../common/version.js";
3
- import { initializeWorkspace } from "../services/workspace/workspace-preparation.js";
4
- import { workspaceDisabledMessage } from "../services/workspace/workspace-config.js";
5
- import type { Confirmations } from "../ui/confirmation.js";
6
- import type { Lifecycle } from "./lifecycle.js";
7
- import { parseWorkerCommand } from "./mcp-workers.js";
8
-
9
- export function registerCommand(pi: ExtensionAPI, lifecycle: Lifecycle, confirmations: Confirmations) {
10
- pi.registerCommand("pbot", {
11
- description: "工作区初始化、状态与跨 Harness worker 管理",
12
- getArgumentCompletions: prefix => {
13
- if (/\s/.test(prefix)) return null;
14
- return ["init", "status", "worker"]
15
- .filter(command => command.startsWith(prefix)).map(command => ({ value: command, label: command }));
16
- },
17
- handler: async (args, ctx) => {
18
- const [, command, argument = ""] = args.trim().match(/^(\S+)(?:\s+([\s\S]*))?$/) ?? [];
19
- confirmations.resume();
20
- if (command === "init" && !argument) {
21
- await ctx.waitForIdle();
22
- const start = !lifecycle.active;
23
- await initializeWorkspace(lifecycle.root ?? ctx.cwd);
24
- ctx.ui.notify(start ? "工作区已初始化并启用,正在加载 Personal Bot。" : "资料目录已准备;新建的 AGENTS.md 经 /reload 加载。", "info");
25
- if (start) await ctx.reload();
26
- return;
27
- }
28
- if (!lifecycle.active) {
29
- const configuration = lifecycle.configuration;
30
- const status = {
31
- workspaceRoot: lifecycle.root ?? ctx.cwd,
32
- release: packageVersion,
33
- enabled: false,
34
- state: configuration?.error || configuration?.enabled ? "error" : "disabled",
35
- nextStep: configuration?.error ?? "/pbot init",
36
- configuration,
37
- };
38
- ctx.ui.notify(command === "status" ? JSON.stringify(status, null, 2)
39
- : configuration ? workspaceDisabledMessage(configuration) : "pbot 工作区实例不可用。", configuration?.error ? "error" : "info");
40
- return;
41
- }
42
- const instance = lifecycle.get();
43
- if (command === "status" && !argument) {
44
- if (ctx.mode !== "tui") {
45
- ctx.ui.notify(JSON.stringify({
46
- workspaceRoot: instance.root,
47
- release: packageVersion,
48
- enabled: true,
49
- state: "running",
50
- configuration: lifecycle.configuration,
51
- }, null, 2), "info");
52
- return;
53
- }
54
- const history = instance.history.status;
55
- ctx.ui.notify([
56
- `工作区 ${instance.root}`,
57
- `状态 已启动 · 版本 ${packageVersion}`,
58
- `历史 ${history.organizing ? "整理中" : history.pending === null ? "查询时更新索引" : history.pending + " 项待整理"}`,
59
- ...history.warnings,
60
- ].join("\n"), "info");
61
- return;
62
- }
63
- if (command === "worker") {
64
- try {
65
- const { tool, args: payload } = parseWorkerCommand(argument);
66
- const result = await instance.workers.callTool(tool, { workspace: instance.root, ...payload });
67
- ctx.ui.notify(JSON.stringify(result, null, 2), "info");
68
- } catch (error) {
69
- ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
70
- }
71
- return;
72
- }
73
- ctx.ui.notify('/pbot init | status | worker [overview|status|backends|models|create|request|response|output|close] [JSON]', "info");
74
- },
75
- });
76
- }
@@ -1,54 +0,0 @@
1
- import type { Context } from "@deepseek-ai/cordis";
2
- import type {} from "@deepseek-ai/dsh-commands";
3
- import { object, json } from "../../common/json.js";
4
- import { requireThat } from "../../common/validation.js";
5
- import { dshWorkspaceStatus, type PbotManagement } from "./management.js";
6
- import type { DshWorkspaces } from "./workspace.js";
7
- import { parseWorkerCommand } from "../mcp-workers.js";
8
-
9
- const usage = '用法:/pbot status | init | worker [overview|status|backends|models|create|request|response|output|close] [JSON] | history {"action":…}';
10
-
11
- export function registerDshCommand(ctx: Context, workspaces: DshWorkspaces, management: PbotManagement) {
12
- ctx.commands.register({
13
- name: "pbot",
14
- description: "Personal Bot 工作区、跨 Harness worker 与历史管理",
15
- recordInput: false,
16
- input: { hint: "status | init | worker ... | history JSON", attachments: false },
17
- async handler({ agent, rawInput, signal }) {
18
- signal.throwIfAborted();
19
- const command = rawInput.trim(), split = command.search(/\s/);
20
- if (!command || command === "status") {
21
- const status = await dshWorkspaceStatus(workspaces, agent);
22
- signal.throwIfAborted(); return { kind: "success", text: JSON.stringify(status, null, 2) };
23
- }
24
- if (command === "init") {
25
- await workspaces.initialize(agent);
26
- signal.throwIfAborted();
27
- return { kind: "success", text: JSON.stringify(await dshWorkspaceStatus(workspaces, agent), null, 2) };
28
- }
29
- const workspace = await workspaces.get(agent);
30
- signal.throwIfAborted();
31
- const verb = split < 0 ? command : command.slice(0, split);
32
- const rest = split < 0 ? "" : command.slice(split).trim();
33
- let result: unknown;
34
- switch (verb) {
35
- case "worker": {
36
- const { tool, args } = parseWorkerCommand(rest);
37
- result = await workspace.workers.callTool(tool, { workspace: workspace.root, ...args });
38
- break;
39
- }
40
- case "history": {
41
- requireThat(rest.length > 0, usage);
42
- const input: unknown = JSON.parse(rest);
43
- requireThat(object(input), "命令参数必须是 JSON 对象。");
44
- result = await management.history({ parentSessionId: agent.id, input: json(input) }, signal);
45
- break;
46
- }
47
- default:
48
- throw new Error(usage);
49
- }
50
- workspace.check();
51
- return { kind: "success", text: JSON.stringify(result, null, 2) };
52
- },
53
- });
54
- }
@@ -1,74 +0,0 @@
1
- import { join } from "node:path";
2
- import type { Context } from "@deepseek-ai/cordis";
3
- import type { Agent } from "@deepseek-ai/dsh-agent";
4
- import { acpHistorySessions } from "../../storage/acp-history.js";
5
- import { HistoryFiles } from "../../storage/history-files.js";
6
- import { HistoryService } from "../../services/history/history-service.js";
7
- import { DshHistory } from "../../integrations/dsh/history.js";
8
- import { dshHistorySummarizer } from "../../integrations/dsh/history-summary.js";
9
- import { finalDshAnswer } from "../../integrations/dsh/messages.js";
10
- import { defaultWorkerDirectory } from "../mcp-workers.js";
11
-
12
- /** One server-owned organizer per workspace, shared by its parent Sessions. */
13
- export class DshHistoryWork {
14
- readonly service: HistoryService;
15
- readonly #parents = new Set<Agent>();
16
- #controller: AbortController | undefined;
17
- #work: Promise<void> | undefined;
18
- #closing: Promise<void> | undefined;
19
-
20
- constructor(private readonly ctx: Context, root: string) {
21
- this.service = new HistoryService(
22
- root,
23
- new HistoryFiles(join(root, ".pbot/history"), "dsh"),
24
- new DshHistory(ctx, root),
25
- [new HistoryFiles(join(root, ".pbot/history"), "pi"), new HistoryFiles(join(root, ".pbot/history"), "claude")],
26
- () => acpHistorySessions({ mcp: defaultWorkerDirectory() }),
27
- );
28
- }
29
-
30
- attach(agent: Agent) { this.#parents.add(agent); return () => { this.#parents.delete(agent); }; }
31
- cancel() { this.#controller?.abort(); }
32
- schedule(agent: Agent) {
33
- if (this.#closing || [...this.#parents].some(parent => parent.status !== "idle" || parent.inbox.nextTurn.length || parent.inbox.nextStep.length)) return;
34
- this.cancel();
35
- const controller = new AbortController(), selection = agent.model.current(), sessionId = agent.id;
36
- this.#controller = controller;
37
- const signal = controller.signal;
38
- const work = (this.#work ?? Promise.resolve()).catch(() => {}).then(async () => {
39
- signal.throwIfAborted();
40
- await this.service.refresh({ host: "dsh", sessionId }, signal);
41
- signal.throwIfAborted();
42
- await this.service.organize(dshHistorySummarizer(this.ctx, selection, sessionId), signal);
43
- }).catch(error => { if (!signal.aborted) this.ctx.logger.warn("pbot 历史整理未完成:" + String(error)); });
44
- this.#work = work;
45
- void work.finally(() => { if (this.#work === work) { this.#work = undefined; this.#controller = undefined; } });
46
- }
47
- close() {
48
- if (this.#closing) return this.#closing;
49
- this.cancel();
50
- this.#closing = (async () => { await this.#work; await this.service.close(); this.#parents.clear(); })();
51
- return this.#closing;
52
- }
53
- }
54
-
55
- export function registerDshHistoryEvents(ctx: Context, agent: Agent, work: DshHistoryWork, check: () => void) {
56
- let normal = false, final = false;
57
- ctx.effect(() => work.attach(agent));
58
- ctx.on("session/event", (session, event) => {
59
- if (session !== agent.session) return;
60
- if (event.type === "turn/start") { normal = false; final = false; }
61
- if (event.type === "assistant/message") final = Boolean(finalDshAnswer(event).trim());
62
- if (event.type === "agent/inbox/spliced" && event.data.inserted.some(message => message.source.kind === "user")) { normal = false; work.cancel(); }
63
- if (event.type === "turn/end") normal = event.data.reason.kind === "completed" && final;
64
- });
65
- ctx.on("agent/pre-step", async (_payload, next) => { work.cancel(); check(); return next(); });
66
- ctx.on("agent/status", ({ agent: changed, status }) => {
67
- if (changed !== agent || status !== "idle" || !normal) return;
68
- normal = false;
69
- if (!agent.inbox.nextTurn.length && !agent.inbox.nextStep.length) {
70
- try { check(); } catch (error) { if ((error as Error).name === "AbortError") return; throw error; }
71
- work.schedule(agent);
72
- }
73
- });
74
- }
@@ -1,26 +0,0 @@
1
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import { historyLocation, historySummarizer } from "../integrations/pi/history.js";
3
- import type { Lifecycle } from "./lifecycle.js";
4
-
5
- export function registerHistoryEvents(pi: ExtensionAPI, lifecycle: Lifecycle) {
6
- pi.on("session_start", async (_event, ctx) => {
7
- const instance = lifecycle.active;
8
- if (!instance) return;
9
- try { await instance.history.refresh(historyLocation(ctx), instance.signal()); }
10
- catch (error) { ctx.ui.notify("历史索引:" + String(error), "warning"); }
11
- });
12
- pi.on("agent_settled", (event, ctx) => {
13
- const instance = lifecycle.active;
14
- if (!instance || event.aborted) return;
15
- const signal = instance.signal();
16
- void (async () => {
17
- await instance.history.refresh(historyLocation(ctx), signal);
18
- signal.throwIfAborted();
19
- const summarize = await historySummarizer(ctx);
20
- ctx.ui.setStatus("pbot-history", "历史整理中");
21
- await instance.history.organize(summarize, signal);
22
- })().catch(error => {
23
- if (!signal.aborted) ctx.ui.notify("历史摘要暂未完成,下次交互结束后重试:" + String(error), "warning");
24
- }).finally(() => { if (lifecycle.active === instance) ctx.ui.setStatus("pbot-history", undefined); });
25
- });
26
- }
@@ -1,39 +0,0 @@
1
- import type { Context } from "@deepseek-ai/cordis";
2
- import type { Agent } from "@deepseek-ai/dsh-agent";
3
- import type { SessionId } from "@deepseek-ai/dsh-session";
4
- import { BlockAssembler, type PreparedLlmCall } from "@deepseek-ai/dsh-llm";
5
- import type { HistorySummarizer } from "../../model/history.js";
6
- import { requireThat } from "../../common/validation.js";
7
- import { reduceHistorySummary } from "../history-summary.js";
8
-
9
- declare module "@deepseek-ai/dsh-llm" {
10
- interface LlmRequestPurposeMap { "pbot-history": true }
11
- }
12
-
13
- /** Independent text calls through the host's routing and authentication; no Agent or Session messages. */
14
- export function dshHistorySummarizer(ctx: Context, selection: ReturnType<Agent["model"]["current"]>, sessionId: SessionId): HistorySummarizer {
15
- return async (request, signal) => {
16
- requireThat(selection, "请先选择 dsh 模型。"); signal.throwIfAborted();
17
- const prepare = () => ctx.llm.prepareCall({ provider: selection.provider, model: selection.model, maxTokens: request.maxTokens }, signal,
18
- (controls, model) => ({ ...controls, ...(model.reasoning?.efforts[0] ? { reasoningEffort: model.reasoning.efforts[0].id } : {}) }));
19
- let first: PreparedLlmCall | undefined = await prepare();
20
- const budget = Math.max(2000, Math.min(24000, Math.floor((first.context?.contextWindow ?? 12000) / 2)));
21
- const ask: HistorySummarizer = async ({ system, prompt }, signal) => {
22
- signal.throwIfAborted();
23
- const prepared = first ?? await prepare(); first = undefined;
24
- const assembler = new BlockAssembler(); let finished = false;
25
- for await (const chunk of prepared.stream({ ...prepared.config, system, sessionId, purpose: "pbot-history", signal, tools: [],
26
- messages: [{ role: "user", content: [{ type: "text", text: prompt }] }] })) {
27
- signal.throwIfAborted(); assembler.push(chunk); if (chunk.type === "finish") finished = true;
28
- }
29
- signal.throwIfAborted();
30
- const reason = assembler.finish;
31
- requireThat(finished && reason.kind === "stop", reason.kind === "error" || reason.kind === "aborted" ? reason.failure.message : "历史摘要未正常结束:" + reason.kind);
32
- const blocks = assembler.blocks();
33
- requireThat(!blocks.some(block => block.type === "tool-call"), "历史摘要不能执行工具。");
34
- const answer = blocks.filter(block => block.type === "text").map(block => block.text).join("\n").trim();
35
- requireThat(answer, "历史摘要为空。"); return answer;
36
- };
37
- return reduceHistorySummary(budget, ask)(request, signal);
38
- };
39
- }