personal-bot 0.3.1 → 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 +73 -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 +73 -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 +91 -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,20 +1,26 @@
1
1
  import { object } from "../common/json.js";
2
2
  import { requireThat } from "../common/validation.js";
3
- import type { HistoryExchange, HistoryHost, HistoryIdentity, HistoryRecord, HistorySummary, RawHistory } from "../model/history.js";
3
+ import type { HistoryExchange, HistoryHost, HistoryIdentity, RawHistory, SummaryArtifact } from "../model/history.js";
4
4
  import { fileId } from "./file-access.js";
5
5
 
6
6
  const strings = (value: unknown): value is string[] => Array.isArray(value) && value.every(item => typeof item === "string");
7
7
  const fields = (value: object, names: readonly string[]) => Object.keys(value).every(key => names.includes(key));
8
+
8
9
  const rawFields = ["host", "id", "sessionId", "name", "exchanges", "branches"];
9
- const hierarchyFields = ["host", "id", "sessionId", "summaries"];
10
10
  const exchangeFields = ["id", "entryIds", "text", "from", "to", "completed"];
11
- const summaryFields = [...exchangeFields, "level", "children", "ready"];
11
+ const summaryArtifactFields = ["id", "dimension", "host", "sessionId", "title", "text", "from", "to", "updatedAt", "source"];
12
+ const summarySourceFields = ["rawIds", "exchangeIds", "fingerprint"];
12
13
 
13
- export const isHistoryHost = (value: unknown): value is HistoryHost => value === "pi" || value === "dsh" || value === "claude";
14
+ const identifierPattern = /^[a-z0-9][a-z0-9-]{0,63}$/;
15
+ export const isHistoryHost = (value: unknown): value is HistoryHost => typeof value === "string" && identifierPattern.test(value);
16
+ export const isSummaryDimension = (value: unknown): value is string => typeof value === "string" && identifierPattern.test(value);
14
17
 
15
18
  function identity(value: unknown): asserts value is HistoryIdentity {
16
- requireThat(object(value) && isHistoryHost(value.host) && typeof value.id === "string" &&
17
- typeof value.sessionId === "string" && value.sessionId.length > 0, "历史归档身份无效。");
19
+ requireThat(
20
+ object(value) && isHistoryHost(value.host) && typeof value.id === "string" &&
21
+ typeof value.sessionId === "string" && value.sessionId.length > 0,
22
+ "历史归档身份无效。",
23
+ );
18
24
  fileId(value.id);
19
25
  }
20
26
 
@@ -31,68 +37,48 @@ function exchange(value: unknown): value is HistoryExchange & { id: string } {
31
37
 
32
38
  export function rawHistory(value: unknown): RawHistory {
33
39
  identity(value);
34
- requireThat(object(value) && fields(value, rawFields) && typeof value.name === "string" &&
35
- Array.isArray(value.exchanges) && Array.isArray(value.branches), "历史原文归档无效。");
40
+ requireThat(
41
+ object(value) && fields(value, rawFields) && typeof value.name === "string" &&
42
+ Array.isArray(value.exchanges) && Array.isArray(value.branches),
43
+ "历史原文归档无效。",
44
+ );
36
45
  const ids = new Set<string>();
37
46
  for (const item of value.exchanges) {
38
47
  requireThat(exchange(item) && fields(item, exchangeFields) && item.entryIds.length > 0, "历史问答或其来源消息 ID 无效。");
39
48
  requireThat(item.id !== value.id && !ids.has(item.id), "历史问答 ID 重复:" + item.id);
40
49
  ids.add(item.id);
41
50
  }
42
- for (const branch of value.branches) requireThat(strings(branch) && new Set(branch).size === branch.length && branch.every(id => ids.has(id)),
43
- "历史分支包含重复或未知的问答 ID。");
44
- return value as unknown as RawHistory;
45
- }
46
-
47
- export interface HierarchicalHistory extends HistoryIdentity { summaries: HistorySummary[] }
48
-
49
- export function hierarchicalHistory(value: unknown, raw: RawHistory): HierarchicalHistory {
50
- identity(value);
51
- matchIdentity(value, raw);
52
- requireThat(object(value) && fields(value, hierarchyFields) && Array.isArray(value.summaries), "历史摘要归档无效。");
53
- const levels = new Map(raw.exchanges.map(item => [item.id, 0]));
54
- for (const item of value.summaries) {
55
- requireThat(object(item) && exchange(item) && fields(item, summaryFields) && item.entryIds.length > 0 &&
56
- typeof item.level === "number" && Number.isSafeInteger(item.level) && item.level > 0 && strings(item.children) && typeof item.ready === "boolean", "历史摘要节点无效。");
57
- requireThat(item.id !== raw.id && !levels.has(item.id), "历史摘要 ID 重复:" + item.id);
58
- levels.set(item.id, item.level);
51
+ for (const branch of value.branches) {
52
+ requireThat(
53
+ strings(branch) && new Set(branch).size === branch.length && branch.every(id => ids.has(id)),
54
+ "历史分支包含重复或未知的问答 ID。",
55
+ );
59
56
  }
60
- const result = value as unknown as HierarchicalHistory;
61
- for (const item of result.summaries) requireThat(item.children.length > 0 && new Set(item.children).size === item.children.length &&
62
- item.children.every(id => levels.get(id) === item.level - 1), "历史摘要子节点缺失、重复或层级不匹配:" + item.id);
63
- return result;
57
+ return value as unknown as RawHistory;
64
58
  }
65
59
 
66
- /** Old private directories carried the host in their path. Shared records must declare it. */
67
- export function legacyHistory(value: unknown, host?: HistoryHost): HistoryRecord {
68
- if (host !== undefined) {
69
- requireThat(object(value) && (value.host === undefined || value.host === host), "旧历史归档与来源目录不匹配。");
70
- value = { ...value, host };
60
+ export function summaryArtifact(value: unknown, expectedDimension?: string): SummaryArtifact {
61
+ requireThat(object(value) && fields(value, summaryArtifactFields), "历史摘要产物格式无效。");
62
+ requireThat(typeof value.id === "string" && value.id.length > 0, "历史摘要 ID 无效。");
63
+ fileId(value.id);
64
+ requireThat(isSummaryDimension(value.dimension), "历史摘要维度无效。");
65
+ if (expectedDimension !== undefined) {
66
+ requireThat(value.dimension === expectedDimension, `历史摘要维度不匹配,预期 ${expectedDimension},实际 ${value.dimension}。`);
71
67
  }
72
- identity(value);
73
- requireThat(object(value) && typeof value.name === "string" && Array.isArray(value.nodes) &&
74
- !("exchanges" in value) && !("branches" in value) && !("summaries" in value), "旧历史归档无效。");
75
- for (const node of value.nodes) requireThat(object(node) && exchange(node) &&
76
- (node.kind === "session" || node.kind === "exchange" || node.kind === "summary") && Number.isInteger(node.level) &&
77
- strings(node.parents) && strings(node.children) && typeof node.ready === "boolean", "旧历史节点无效。");
78
- const result = value as unknown as HistoryRecord, ids = new Set(result.nodes.map(node => node.id));
79
- const roots = result.nodes.filter(node => node.kind === "session");
80
- requireThat(ids.size === result.nodes.length && roots.length === 1 && roots[0]!.id === result.id &&
81
- result.nodes.every(node => [...node.parents, ...node.children].every(id => ids.has(id))), "旧历史节点关系无效。");
82
- return result;
83
- }
84
-
85
- function exchangeData({ id, entryIds, text, from, to, completed }: HistoryExchange & { id: string }) {
86
- return { id, entryIds, text, from, to, completed };
87
- }
88
-
89
- export function summaryData(item: HistorySummary): HistorySummary {
90
- return { ...exchangeData(item), level: item.level, children: item.children, ready: item.ready };
91
- }
92
-
93
- export function splitLegacy(record: HistoryRecord): { raw: RawHistory; summaries: HistorySummary[] } {
94
- const { host, id, sessionId, name } = record;
95
- const raw = rawHistory({ host, id, sessionId, name, exchanges: record.nodes.filter(node => node.kind === "exchange").map(exchangeData), branches: [] });
96
- const summaries = record.nodes.filter(node => node.kind === "summary").map(summaryData);
97
- return { raw, summaries: hierarchicalHistory({ host, id, sessionId, summaries }, raw).summaries };
68
+ if (value.host !== undefined) requireThat(isHistoryHost(value.host), "历史摘要来源 host 无效。");
69
+ if (value.sessionId !== undefined) requireThat(typeof value.sessionId === "string" && value.sessionId.length > 0, "历史摘要 sessionId 无效。");
70
+ requireThat(
71
+ typeof value.title === "string" && typeof value.text === "string" && value.text.trim().length > 0 &&
72
+ typeof value.from === "string" && typeof value.to === "string" && typeof value.updatedAt === "string",
73
+ "历史摘要正文或时间字段无效。",
74
+ );
75
+ const source = value.source;
76
+ requireThat(
77
+ object(source) && fields(source, summarySourceFields) &&
78
+ strings(source.rawIds) && source.rawIds.length > 0 &&
79
+ strings(source.exchangeIds) &&
80
+ typeof source.fingerprint === "string" && source.fingerprint.length > 0,
81
+ "历史摘要来源指纹无效。",
82
+ );
83
+ return value as unknown as SummaryArtifact;
98
84
  }
@@ -1,9 +1,11 @@
1
- import type { HistoryLocation } from "../../model/history.js";
2
- import type { HistoryService } from "../../services/history/history-service.js";
1
+ import { readWorkspaceHistory, searchWorkspaceHistory } from "../../services/history/history-query.js";
3
2
  import type { HistoryInput } from "./contract.js";
4
3
 
5
- export async function executeHistory(service: HistoryService, args: HistoryInput, location: HistoryLocation, signal?: AbortSignal) {
6
- signal?.throwIfAborted(); await service.refresh(location, signal); signal?.throwIfAborted();
7
- return args.action === "search" ? service.search(args) :
8
- { node: service.read(args.id, args.offset, args.limit, args.childrenOffset, args.host), warnings: service.warnings };
4
+ export function executeHistory(root: string, args: HistoryInput, signal?: AbortSignal) {
5
+ signal?.throwIfAborted();
6
+ if (args.action === "search") {
7
+ return searchWorkspaceHistory(root, args);
8
+ }
9
+ const node = readWorkspaceHistory(root, args.id, args.offset, args.limit, args.childrenOffset, args.host);
10
+ return { node, warnings: node.warnings };
9
11
  }
@@ -4,26 +4,63 @@ import { requireThat } from "../../common/validation.js";
4
4
  import { schema } from "../../common/schema.js";
5
5
  import { inputObject, need, nullable, pick } from "../input.js";
6
6
 
7
- const host = Type.Union([Type.Literal("pi"), Type.Literal("dsh"), Type.Literal("claude")]);
7
+ const identifier = Type.String({ pattern: "^[a-z0-9][a-z0-9-]{0,63}$" });
8
8
  const nullableOffset = Type.Union([Type.Integer(), Type.Null()]);
9
- const node = Type.Object({ host, id: Type.String(),
10
- kind: Type.Union([Type.Literal("session"), Type.Literal("exchange"), Type.Literal("summary")], { description: "session=会话根;summary=摘要;exchange=单轮问答原文。" }),
11
- sessionId: Type.String(), name: Type.String(), preview: Type.String(), from: Type.String(), to: Type.String(),
9
+ const node = Type.Object({
10
+ host: identifier,
11
+ id: Type.String(),
12
+ kind: Type.Union([Type.Literal("session"), Type.Literal("exchange"), Type.Literal("summary")], {
13
+ description: "session=会话根;summary=维度摘要;exchange=单轮问答原文。",
14
+ }),
15
+ dimension: Type.Optional(identifier),
16
+ sessionId: Type.String(),
17
+ name: Type.String(),
18
+ preview: Type.String(),
19
+ from: Type.String(),
20
+ to: Type.String(),
12
21
  ready: Type.Boolean({ description: "正文或摘要是否已生成。" }),
13
- completed: Type.Boolean({ description: "该对话或问答是否正常结束(false 表示中断或未完)。" }) });
22
+ completed: Type.Boolean({ description: "该对话或问答是否正常结束(false 表示中断或未完)。" }),
23
+ });
24
+
14
25
  export const historyResultSchema = Type.Object({
15
- matches: Type.Optional(Type.Array(Type.Object({ ...node.properties, snippet: Type.String(), parents: Type.Array(Type.String()) }))),
16
- total: Type.Optional(Type.Integer()), nextOffset: Type.Optional(nullableOffset),
17
- node: Type.Optional(Type.Object({ ...node.properties, text: Type.String(), totalLength: Type.Integer(), nextOffset: nullableOffset,
18
- parents: Type.Array(node), children: Type.Array(node), nextChildrenOffset: nullableOffset,
19
- source: Type.Object({ host, sessionId: Type.String({ description: "原始宿主会话 ID。" }), entryIds: Type.Array(Type.String()) }), warnings: Type.Array(Type.String()) })),
26
+ matches: Type.Optional(Type.Array(Type.Object({
27
+ ...node.properties,
28
+ snippet: Type.String(),
29
+ parents: Type.Array(Type.String()),
30
+ }))),
31
+ total: Type.Optional(Type.Integer()),
32
+ nextOffset: Type.Optional(nullableOffset),
33
+ node: Type.Optional(Type.Object({
34
+ ...node.properties,
35
+ text: Type.String(),
36
+ totalLength: Type.Integer(),
37
+ nextOffset: nullableOffset,
38
+ parents: Type.Array(node),
39
+ children: Type.Array(node),
40
+ nextChildrenOffset: nullableOffset,
41
+ source: Type.Object({
42
+ host: identifier,
43
+ sessionId: Type.String({ description: "原始宿主会话 ID。" }),
44
+ entryIds: Type.Array(Type.String()),
45
+ dimension: Type.Optional(identifier),
46
+ }),
47
+ warnings: Type.Array(Type.String()),
48
+ })),
20
49
  warnings: Type.Array(Type.String()),
21
50
  });
22
- export const historyDescription = "查询当前工作区的历史问答与归档,host 可筛选来源(pi/dsh/claude)。search 按不区分大小写的连续关键词匹配原文和摘要,省略 query 列出各会话;无匹配时换词。read 按节点 id 展开正文与上下级,nextOffset 续读正文,nextChildrenOffset 续读子节点;需要细节时读取 exchange 原文。归档不含工具调用日志。";
51
+
52
+ export const historyDescription =
53
+ "查询当前工作区的历史问答与各维度摘要,host 可筛选来源(如 pi、dsh、claude、antigravity),dimension 可筛选 raw 原文或特定摘要维度(如 monthly 月度汇总、session 会话摘要)。" +
54
+ "search 按不区分大小写的连续关键词匹配原文和摘要,省略 query 列出各会话或指定维度摘要;无匹配时换词。" +
55
+ "read 按节点 id 展开正文与上下级(可从 monthly 下钻至 session 摘要,再下钻至 exchange 原文),nextOffset 续读正文,nextChildrenOffset 续读子节点。归档不含工具调用日志。";
56
+
23
57
  export const historyParameters = Type.Object({
24
- action: Type.Union([Type.Literal("search"), Type.Literal("read")], { description: "search 搜索或列会话;read 读取指定节点正文与上下级。各动作仅读取自身字段,其余字段忽略。" }),
25
- host: nullable(Type.Union([Type.Literal("pi"), Type.Literal("dsh"), Type.Literal("claude")], { description: "可选来源筛选:pi、dsh 或 claude。" })),
26
- query: nullable(Type.String({ description: "仅 search:不区分大小写的连续关键词;省略时列出各会话。" })),
58
+ action: Type.Union([Type.Literal("search"), Type.Literal("read")], {
59
+ description: "search 搜索或列会话;read 读取指定节点正文与上下级。各动作仅读取自身字段,其余字段忽略。",
60
+ }),
61
+ host: nullable(Type.String({ pattern: "^[a-z0-9][a-z0-9-]{0,63}$", description: "可选来源筛选(如 pi、dsh、claude、antigravity)。" })),
62
+ dimension: nullable(Type.String({ pattern: "^[a-z0-9][a-z0-9-]{0,63}$", description: "仅 search:可选范围筛选(raw 表示仅原文,或指定摘要维度如 monthly、session;省略查全部)。" })),
63
+ query: nullable(Type.String({ description: "仅 search:不区分大小写的连续关键词;省略时列出各会话(或指定维度摘要)。" })),
27
64
  sessionId: nullable(Type.String({ description: "仅 search:限定在指定会话 ID 内搜索。" })),
28
65
  from: nullable(Type.String({ description: "仅 search:ISO 日期或时间下界。" })),
29
66
  to: nullable(Type.String({ description: "仅 search:ISO 日期或时间上界。" })),
@@ -34,7 +71,7 @@ export const historyParameters = Type.Object({
34
71
  }, { additionalProperties: false });
35
72
 
36
73
  export type HistoryInput =
37
- | { action: "search"; host?: HistoryHost; query?: string; sessionId?: string; from?: string; to?: string; offset?: number; limit?: number }
74
+ | { action: "search"; host?: HistoryHost; dimension?: string; query?: string; sessionId?: string; from?: string; to?: string; offset?: number; limit?: number }
38
75
  | { action: "read"; id: string; host?: HistoryHost; offset?: number; limit?: number; childrenOffset?: number };
39
76
 
40
77
  const valid = schema(historyParameters);
@@ -44,11 +81,19 @@ export function historyInput(value: unknown): HistoryInput {
44
81
  if (args.action === "search") {
45
82
  const limit = args.limit === undefined ? 20 : args.limit as number;
46
83
  requireThat(limit <= 50, "search 的 limit 最多 50。");
47
- return { action: "search", ...(pick(args, ["host", "query", "sessionId", "from", "to", "offset", "limit"]) as
48
- Omit<Extract<HistoryInput, { action: "search" }>, "action">) };
84
+ return {
85
+ action: "search",
86
+ ...(pick(args, ["host", "dimension", "query", "sessionId", "from", "to", "offset", "limit"]) as
87
+ Omit<Extract<HistoryInput, { action: "search" }>, "action">),
88
+ };
89
+ }
90
+ if (args.action === "read") {
91
+ return {
92
+ action: "read",
93
+ id: need("read", args, "id"),
94
+ ...(pick(args, ["host", "offset", "limit", "childrenOffset"]) as
95
+ Omit<Extract<HistoryInput, { action: "read" }>, "action" | "id">),
96
+ };
49
97
  }
50
- if (args.action === "read") return { action: "read", id: need("read", args, "id"),
51
- ...(pick(args, ["host", "offset", "limit", "childrenOffset"]) as
52
- Omit<Extract<HistoryInput, { action: "read" }>, "action" | "id">) };
53
98
  throw new Error("未知的历史 action。");
54
99
  }
@@ -1,7 +1,6 @@
1
1
  import type { Context } from "@deepseek-ai/cordis";
2
2
  import type { Agent } from "@deepseek-ai/dsh-agent";
3
- import type { HistoryService } from "../../services/history/history-service.js";
4
- import { dshParameters, dshOutputSchema } from "../../integrations/dsh/schema.js";
3
+ import { dshParameters, dshOutputSchema } from "../../integrations/hosts/dsh/schema.js";
5
4
  import { requireThat } from "../../common/validation.js";
6
5
  import { schema } from "../../common/schema.js";
7
6
  import { json } from "../../common/json.js";
@@ -9,15 +8,25 @@ import { markdownFields } from "../../common/markdown.js";
9
8
  import { historyDescription, historyInput, historyParameters, historyResultSchema } from "./contract.js";
10
9
  import { executeHistory } from "./actions.js";
11
10
 
12
- export function registerDshHistoryTool(ctx: Context, agent: Agent, service: HistoryService, lifetime: AbortSignal, check: () => void) {
11
+ export function registerDshHistoryTool(ctx: Context, agent: Agent, root: string, lifetime: AbortSignal, check: () => void) {
13
12
  const valid = schema(historyResultSchema);
14
- ctx.tools.register({ name: "pbot_history", description: historyDescription, parameters: dshParameters(historyParameters),
15
- output: { schema: dshOutputSchema(historyResultSchema), render: (_args, value) => [{ type: "text", text: "# 历史\n\n" + markdownFields(value) }] },
13
+ ctx.tools.register({
14
+ name: "pbot_history",
15
+ description: historyDescription,
16
+ parameters: dshParameters(historyParameters),
17
+ output: {
18
+ schema: dshOutputSchema(historyResultSchema),
19
+ render: (_args, value) => [{ type: "text", text: "# 历史\n\n" + markdownFields(value) }],
20
+ },
16
21
  async execute(value, exec) {
17
- check(); requireThat(exec.agent === agent, "历史工具不属于当前会话。");
22
+ check();
23
+ requireThat(exec.agent === agent, "历史工具不属于当前会话。");
18
24
  const signal = AbortSignal.any([exec.signal, lifetime]);
19
- const result = await executeHistory(service, historyInput(value), { host: "dsh", sessionId: agent.id }, signal);
20
- check(); signal.throwIfAborted(); requireThat(valid(result), "历史输出不符合契约。"); return json(result);
25
+ const result = executeHistory(root, historyInput(value), signal);
26
+ check();
27
+ signal.throwIfAborted();
28
+ requireThat(valid(result), "历史输出不符合契约。");
29
+ return json(result);
21
30
  },
22
31
  });
23
32
  }
@@ -0,0 +1,21 @@
1
+ import { defineTool } from "@earendil-works/pi-coding-agent";
2
+ import type { CallAccess } from "../access.js";
3
+ import { markdownResult } from "../result.js";
4
+ import { historyDescription, historyInput, historyParameters, historyResultSchema } from "./contract.js";
5
+ import { executeHistory } from "./actions.js";
6
+
7
+ export function historyTool(root: string, access: CallAccess) {
8
+ return defineTool({
9
+ name: "pbot_history",
10
+ label: "历史对话",
11
+ description: historyDescription,
12
+ parameters: historyParameters,
13
+ outputSchema: historyResultSchema,
14
+ async execute(_id, args, signal) {
15
+ access.check();
16
+ const result = executeHistory(root, historyInput(args), signal);
17
+ access.check();
18
+ return markdownResult(result, args.action === "search" ? "历史搜索" : "历史正文");
19
+ },
20
+ });
21
+ }
@@ -1,10 +1,9 @@
1
1
  import type { ExtensionAPI, ToolDefinition } from "@earendil-works/pi-coding-agent";
2
2
  import type { CallAccess } from "./access.js";
3
- import type { HistoryService } from "../services/history/history-service.js";
4
- import { historyTool } from "./history/tool.js";
3
+ import { historyTool } from "./history/pi-tool.js";
5
4
 
6
- export function mainTools(history: HistoryService, access: CallAccess): ToolDefinition[] {
7
- return [historyTool(history, access)];
5
+ export function mainTools(root: string, access: CallAccess): ToolDefinition[] {
6
+ return [historyTool(root, access)];
8
7
  }
9
8
 
10
9
  export class ToolRegistry {
@@ -90,7 +90,7 @@ export function showManagement(ctx: Context, parentSessionId: SessionId) {
90
90
 
91
91
  const history = section("history", "历史"); pageTitle(history, "历史", "");
92
92
  const searchForm = form(history); searchForm.className = "pbot-search";
93
- const historyQuery = field(searchForm, "关键词"), host = select(searchForm, "来源", [["", "全部"], ["pi", "Pi"], ["dsh", "dsh"], ["claude", "Claude Code"]]);
93
+ const historyQuery = field(searchForm, "关键词"), host = select(searchForm, "来源", [["", "全部"], ["pi", "Pi"], ["dsh", "dsh"], ["claude", "Claude Code"], ["antigravity", "Antigravity"]]);
94
94
  historyQuery.placeholder = "留空查看最近会话"; submit(searchForm, "查询", () => searchHistory());
95
95
  const dateFilters = details(history, "时间范围"), dateGrid = group(dateFilters, "pbot-grid");
96
96
  const historyFrom = field(dateGrid, "开始时间"), historyTo = field(dateGrid, "结束时间");
@@ -114,7 +114,8 @@ export function showManagement(ctx: Context, parentSessionId: SessionId) {
114
114
  for (const match of rows(data.matches)) {
115
115
  const item = element("article"), meta = group(item, "pbot-between"); item.dataset.id = text(match.id); item.dataset.host = text(match.host);
116
116
  meta.append(element("h4", text(match.name)), element("span", text(match.host), "pbot-badge"));
117
- item.append(note(`${time(match.from)} · ${match.kind === "session" ? "会话" : match.kind === "summary" ? "摘要" : "问答"}`), block(match.snippet || match.preview));
117
+ const kindLabel = match.kind === "session" ? "会话" : match.kind === "summary" ? `摘要${match.dimension ? "·" + text(match.dimension) : ""}` : "问答";
118
+ item.append(note(`${time(match.from)} · ${kindLabel}`), block(match.snippet || match.preview));
118
119
  button(item, "读取", () => readHistory(text(match.id), text(match.host)), "pbot-quiet"); historyBody.append(item);
119
120
  }
120
121
  if (!rows(data.matches).length) historyBody.append(empty("没有找到匹配内容", "试试更短的关键词,或调整来源和时间范围。"));
@@ -166,17 +167,32 @@ export function showManagement(ctx: Context, parentSessionId: SessionId) {
166
167
  }
167
168
  for (const control of tabs.values()) enabled(control, true);
168
169
  materials.hidden = false; initializeButton.textContent = "准备目录"; enabled(initializeButton, true);
169
- const historyState = record(snapshot.history);
170
+ const historyState = object(snapshot.history) ? snapshot.history : null;
171
+ const historyDims = historyState && Array.isArray(historyState.dimensions) ? rows(historyState.dimensions) : [];
172
+ const historySummaryText = !historyState
173
+ ? "已停用"
174
+ : `原始会话 ${text(historyState.rawCount ?? 0)}` + (historyDims.length
175
+ ? " · " + historyDims.map(dim => {
176
+ const pending = Number(dim.pendingCreate ?? 0) + Number(dim.pendingIncremental ?? 0) + Number(dim.pendingRebuild ?? 0);
177
+ return `${text(dim.dimension)} ${text(dim.ready ?? 0)}/${text(dim.total ?? 0)}${pending ? `(待处理 ${pending})` : ""}`;
178
+ }).join(",")
179
+ : "");
180
+ const historyReminder = historyState && object(historyState.reminder) && typeof historyState.reminder.message === "string"
181
+ ? historyState.reminder.message
182
+ : "";
170
183
  counts.textContent = "Personal Bot 已启动 · 跨 Harness 调度通过 MCP worker_* 提供";
171
184
  const model = object(snapshot.model) ? snapshot.model : {};
172
- workspaceInfo.replaceChildren(facts([
173
- ["状态", "已启动"],
174
- ["工作区", snapshot.workspaceRoot],
175
- ["配置文件", record(snapshot.configuration).path],
176
- ["模型", model.model || "尚未选择"],
177
- ["Provider", model.provider || "—"],
178
- ["历史", historyState.organizing ? "整理中" : historyState.pending === null ? "查询时更新索引" : `${historyState.pending} 项待整理`],
179
- ]));
185
+ workspaceInfo.replaceChildren(
186
+ facts([
187
+ ["状态", "已启动"],
188
+ ["工作区", snapshot.workspaceRoot],
189
+ ["配置文件", record(snapshot.configuration).path],
190
+ ["模型", model.model || "尚未选择"],
191
+ ["Provider", model.provider || "—"],
192
+ ["历史", historySummaryText],
193
+ ]),
194
+ ...(historyReminder ? [note(historyReminder)] : []),
195
+ );
180
196
  statusBody.textContent = JSON.stringify(snapshot, null, 2);
181
197
  }
182
198
 
@@ -1,7 +1,7 @@
1
1
  import type { ExtensionContext, KeybindingsManager, Theme } from "@earendil-works/pi-coding-agent";
2
2
  import { ScrollView, SelectList, Text, matchesKey, truncateToWidth } from "@earendil-works/pi-tui";
3
3
  import type { Component } from "@earendil-works/pi-tui";
4
- import { requireThat } from "../common/validation.js";
4
+ import { requireThat } from "../../common/validation.js";
5
5
 
6
6
  /** One confirmation owns its viewport, selection, and abort listener. */
7
7
  export class ConfirmationDialog implements Component {
@@ -1,4 +0,0 @@
1
- import type { PluginHostAdapter } from "../../model/plugin-host.js";
2
- export declare function antigravityWorkspaceRoot(cwd: string, payload?: unknown): Promise<string>;
3
- export declare const antigravityAdapter: PluginHostAdapter;
4
- export declare const antigravitySkillPath: (pluginRoot: string, skill: string) => string;
@@ -1,79 +0,0 @@
1
- import { realpath, stat } from "node:fs/promises";
2
- import { isAbsolute, join, relative, resolve, sep } from "node:path";
3
- import { object } from "../../common/json.js";
4
- import { resourceRoot } from "../../common/paths.js";
5
- import { requireThat } from "../../common/validation.js";
6
- const supportedEvents = ["SessionStart", "PreToolUse"];
7
- function workspaceFromPayload(cwd, payload) {
8
- if (object(payload) && Array.isArray(payload.workspacePaths)) {
9
- const first = payload.workspacePaths.find(value => typeof value === "string" && value.length > 0);
10
- if (typeof first === "string")
11
- return first;
12
- }
13
- return cwd;
14
- }
15
- function skillFromReadPath(targetPath, pluginRoot = process.env.PLUGIN_ROOT || resolve(resourceRoot, "..")) {
16
- const skillsRoot = resolve(pluginRoot, "skills");
17
- const rel = relative(skillsRoot, resolve(targetPath));
18
- if (!rel || rel.startsWith("..") || isAbsolute(rel))
19
- return undefined;
20
- const skill = rel.split(sep)[0];
21
- if (!skill || skill === "pbot")
22
- return undefined;
23
- return skill;
24
- }
25
- function isPreToolUse(payload) {
26
- return object(payload) && payload.hookEventName === "PreToolUse";
27
- }
28
- export async function antigravityWorkspaceRoot(cwd, payload) {
29
- const directory = workspaceFromPayload(cwd, payload);
30
- requireThat(isAbsolute(directory), "Antigravity 工作区需要绝对路径。");
31
- const root = await realpath(directory);
32
- requireThat((await stat(root)).isDirectory(), "Antigravity 工作区需要目录。");
33
- return root;
34
- }
35
- export const antigravityAdapter = {
36
- host: "antigravity",
37
- nativeRootAgents: true,
38
- nativeWorkspaceSkills: true,
39
- coordinatorPrompt: "plugin-coordinator.md",
40
- initCommandHint: "/pbot init",
41
- usage: "用法:node <插件目录>/lib/plugin.js antigravity init|status",
42
- resolveRoot(cwd, rawPayload) {
43
- return antigravityWorkspaceRoot(cwd, rawPayload);
44
- },
45
- parseEvent(value) {
46
- requireThat(object(value) && typeof value.hookEventName === "string", "Antigravity hook 输入无效。");
47
- const event = value.hookEventName;
48
- requireThat(supportedEvents.includes(event), "Antigravity hook 事件未支持。");
49
- const cwd = typeof value.cwd === "string" && value.cwd ? value.cwd : workspaceFromPayload("", value);
50
- requireThat(cwd, "Antigravity hook 缺少工作目录。");
51
- if (event === "SessionStart") {
52
- return { kind: "inject-context", role: "coordinator", cwd, raw: value };
53
- }
54
- if (!object(value.toolCall) || typeof value.toolCall.name !== "string" || !object(value.toolCall.args)) {
55
- return { kind: "ignore" };
56
- }
57
- const { name, args } = value.toolCall;
58
- if (name === "read_file" && typeof args.Path === "string") {
59
- const skill = skillFromReadPath(args.Path);
60
- if (skill)
61
- return { kind: "check-skill", skill, cwd, raw: value };
62
- }
63
- return { kind: "ignore" };
64
- },
65
- formatPass(payload) {
66
- return isPreToolUse(payload) ? { decision: "allow" } : {};
67
- },
68
- formatContext(_event, context) {
69
- return {
70
- injectSteps: [
71
- { systemMessage: { systemMessage: context.text } },
72
- ],
73
- };
74
- },
75
- formatDeny(_event, reason) {
76
- return { decision: "deny", reason };
77
- },
78
- };
79
- export const antigravitySkillPath = (pluginRoot, skill) => join(pluginRoot, "skills", skill, "SKILL.md");
@@ -1,50 +0,0 @@
1
- import { object, json } from "../../common/json.js";
2
- import { requireThat } from "../../common/validation.js";
3
- import { dshWorkspaceStatus } from "./management.js";
4
- import { parseWorkerCommand } from "../mcp-workers.js";
5
- const usage = '用法:/pbot status | init | worker [overview|status|backends|models|create|request|response|output|close] [JSON] | history {"action":…}';
6
- export function registerDshCommand(ctx, workspaces, management) {
7
- ctx.commands.register({
8
- name: "pbot",
9
- description: "Personal Bot 工作区、跨 Harness worker 与历史管理",
10
- recordInput: false,
11
- input: { hint: "status | init | worker ... | history JSON", attachments: false },
12
- async handler({ agent, rawInput, signal }) {
13
- signal.throwIfAborted();
14
- const command = rawInput.trim(), split = command.search(/\s/);
15
- if (!command || command === "status") {
16
- const status = await dshWorkspaceStatus(workspaces, agent);
17
- signal.throwIfAborted();
18
- return { kind: "success", text: JSON.stringify(status, null, 2) };
19
- }
20
- if (command === "init") {
21
- await workspaces.initialize(agent);
22
- signal.throwIfAborted();
23
- return { kind: "success", text: JSON.stringify(await dshWorkspaceStatus(workspaces, agent), null, 2) };
24
- }
25
- const workspace = await workspaces.get(agent);
26
- signal.throwIfAborted();
27
- const verb = split < 0 ? command : command.slice(0, split);
28
- const rest = split < 0 ? "" : command.slice(split).trim();
29
- let result;
30
- switch (verb) {
31
- case "worker": {
32
- const { tool, args } = parseWorkerCommand(rest);
33
- result = await workspace.workers.callTool(tool, { workspace: workspace.root, ...args });
34
- break;
35
- }
36
- case "history": {
37
- requireThat(rest.length > 0, usage);
38
- const input = JSON.parse(rest);
39
- requireThat(object(input), "命令参数必须是 JSON 对象。");
40
- result = await management.history({ parentSessionId: agent.id, input: json(input) }, signal);
41
- break;
42
- }
43
- default:
44
- throw new Error(usage);
45
- }
46
- workspace.check();
47
- return { kind: "success", text: JSON.stringify(result, null, 2) };
48
- },
49
- });
50
- }
@@ -1,15 +0,0 @@
1
- import type { Context } from "@deepseek-ai/cordis";
2
- import type { Agent } from "@deepseek-ai/dsh-agent";
3
- import { HistoryService } from "../../services/history/history-service.js";
4
- /** One server-owned organizer per workspace, shared by its parent Sessions. */
5
- export declare class DshHistoryWork {
6
- #private;
7
- private readonly ctx;
8
- readonly service: HistoryService;
9
- constructor(ctx: Context, root: string);
10
- attach(agent: Agent): () => void;
11
- cancel(): void;
12
- schedule(agent: Agent): void;
13
- close(): Promise<void>;
14
- }
15
- export declare function registerDshHistoryEvents(ctx: Context, agent: Agent, work: DshHistoryWork, check: () => void): void;