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,12 +1,12 @@
1
1
  import { dirname } from "node:path";
2
2
  import { realpathSync } from "node:fs";
3
- import { AgentFiles, descriptor, launch } from "../storage/agent-files.js";
4
- import { acpInput, acpAnswer } from "../storage/acp-files.js";
5
- import type { AcpInput, AcpAnswer } from "../model/acp.js";
6
- import { requireThat } from "../common/validation.js";
7
- import { packageVersion, releaseLine } from "../common/version.js";
8
- import { loadWorkspaceContext } from "../integrations/agent-resources.js";
9
- import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../services/workspace/workspace-config.js";
3
+ import { AgentFiles, descriptor, launch } from "../../storage/agent-files.js";
4
+ import { acpInput, acpAnswer } from "../../storage/acp-files.js";
5
+ import type { AcpInput, AcpAnswer } from "../../model/acp.js";
6
+ import { requireThat } from "../../common/validation.js";
7
+ import { packageVersion, releaseLine } from "../../common/version.js";
8
+ import { loadWorkspaceContext } from "../../integrations/agent-resources.js";
9
+ import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../services/workspace/workspace-config.js";
10
10
 
11
11
  export async function acpMember() {
12
12
  const id = process.env.PBOT_SUBAGENT_RUN_ID, directory = process.env.PBOT_SUBAGENT_DIR, generation = process.env.PBOT_SUBAGENT_GENERATION;
@@ -1,21 +1,23 @@
1
- import { dirname, resolve } from "node:path";
1
+ import { randomUUID } from "node:crypto";
2
+ import { dirname, join, resolve } from "node:path";
2
3
  import type { RequestPermissionRequest } from "@agentclientprotocol/sdk";
3
- import { AgentFiles, descriptor, launch, status } from "../storage/agent-files.js";
4
- import { acpModelState, acpReference } from "../storage/acp-files.js";
5
- import type { AcpModelSelection, AcpSessionReference } from "../model/acp.js";
6
- import { AcpAgentRun } from "../services/agents/acp-run.js";
7
- import { openAcp } from "../integrations/acp/connection.js";
8
- import { acpContent } from "../integrations/acp/input.js";
9
- import { toAcpMcpServers } from "../integrations/acp/mcp.js";
10
- import { resolveAcpHarness } from "../integrations/acp/registry.js";
11
- import { loadWorkspaceContext } from "../integrations/agent-resources.js";
12
- import { readWorkspaceConfig, workspaceFeatures } from "../services/workspace/workspace-config.js";
13
- import { readWorkspaceMcpConfig, resolveWorkspaceMcpServers } from "../services/workspace/workspace-mcp.js";
14
- import { discoverWorkspaceSkills } from "../services/workspace/workspace-skills.js";
15
- import { object } from "../common/json.js";
16
- import { resourceRoot } from "../common/paths.js";
17
- import { requireThat } from "../common/validation.js";
18
- import { packageVersion, releaseLine } from "../common/version.js";
4
+ import { AgentFiles, descriptor, launch, status } from "../../storage/agent-files.js";
5
+ import { acpModelState, acpReference } from "../../storage/acp-files.js";
6
+ import type { AcpModelSelection, AcpSessionReference } from "../../model/acp.js";
7
+ import { AcpAgentRun } from "../../services/agents/acp-run.js";
8
+ import { openAcp } from "../../integrations/acp/connection.js";
9
+ import { acpExecutable } from "../../integrations/acp/executable.js";
10
+ import { acpContent } from "../../integrations/acp/input.js";
11
+ import { toAcpMcpServers } from "../../integrations/acp/mcp.js";
12
+ import { resolveAcpHarness } from "../../integrations/acp/registry.js";
13
+ import { loadWorkspaceContext } from "../../integrations/agent-resources.js";
14
+ import { readWorkspaceConfig, workspaceFeatures } from "../../services/workspace/workspace-config.js";
15
+ import { readWorkspaceMcpConfig, resolveWorkspaceMcpServers } from "../../services/workspace/workspace-mcp.js";
16
+ import { discoverWorkspaceSkills } from "../../services/workspace/workspace-skills.js";
17
+ import { object } from "../../common/json.js";
18
+ import { resourceRoot } from "../../common/paths.js";
19
+ import { requireThat } from "../../common/validation.js";
20
+ import { packageVersion, releaseLine } from "../../common/version.js";
19
21
 
20
22
  const errorMessage = (error: unknown) => error instanceof Error ? error.message : String(error);
21
23
 
@@ -252,6 +254,118 @@ async function runWorker(args: string[]) {
252
254
  }
253
255
  }
254
256
 
257
+ async function runOneShotPrompt() {
258
+ const lifetime = new AbortController();
259
+ const stop = () => lifetime.abort(new Error("ACP 摘要任务已取消。"));
260
+ process.on("SIGTERM", stop);
261
+ process.on("SIGINT", stop);
262
+ try {
263
+ const payload = await new Promise<{
264
+ reference: AcpSessionReference;
265
+ cwd: string;
266
+ system: string;
267
+ prompt: string;
268
+ model?: string;
269
+ thinking?: string;
270
+ }>((resolvePayload, rejectPayload) => {
271
+ const timer = setTimeout(() => rejectPayload(new Error("缺少 ACP 摘要任务参数。")), 5000);
272
+ process.once("message", (value: unknown) => {
273
+ clearTimeout(timer);
274
+ if (!object(value)) { rejectPayload(new Error("ACP 摘要任务参数必须是对象。")); return; }
275
+ resolvePayload(value as {
276
+ reference: AcpSessionReference;
277
+ cwd: string;
278
+ system: string;
279
+ prompt: string;
280
+ model?: string;
281
+ thinking?: string;
282
+ });
283
+ });
284
+ process.once("disconnect", () => { clearTimeout(timer); rejectPayload(new Error("ACP 摘要任务通道已断开。")); });
285
+ });
286
+ const reference = acpReference(payload.reference);
287
+ requireThat(typeof payload.cwd === "string" && payload.cwd.length > 0, "缺少 ACP 摘要工作目录。");
288
+ requireThat(typeof payload.prompt === "string" && payload.prompt.trim().length > 0, "缺少 ACP 摘要输入内容。");
289
+ const harness = resolveAcpHarness(reference.backend);
290
+ const packageRoot = resolve(resourceRoot, "..");
291
+ // Mark as managed subagent so no host (Pi, dsh, Claude, Antigravity) ever records raw history for summary runs.
292
+ const env: NodeJS.ProcessEnv = {
293
+ ...process.env,
294
+ ...(reference.env ?? {}),
295
+ PBOT_SUBAGENT_RUN_ID: "pbot-summary-" + randomUUID(),
296
+ ...(reference.backend === "pi" ? {
297
+ PBOT_SUMMARY_WORKER: "1",
298
+ PI_OFFLINE: "1",
299
+ PBOT_ACP_PI_COMMAND: process.env.PI_ACP_PI_COMMAND ?? acpExecutable("pi", "pi"),
300
+ PI_ACP_PI_COMMAND: join(packageRoot, "bin/pbot-pi-acp.mjs"),
301
+ } : {}),
302
+ };
303
+ let collecting = false;
304
+ let text = "";
305
+ const connection = await openAcp(
306
+ reference,
307
+ payload.cwd,
308
+ env,
309
+ {
310
+ update(update) {
311
+ if (collecting && update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
312
+ text += update.content.text;
313
+ }
314
+ },
315
+ async permission() {
316
+ return { outcome: { outcome: "cancelled" } };
317
+ },
318
+ },
319
+ lifetime.signal,
320
+ {
321
+ harness,
322
+ ...(payload.system ? { systemPrompt: payload.system } : {}),
323
+ },
324
+ );
325
+ try {
326
+ if (payload.model || payload.thinking) {
327
+ const parsedModel = payload.model
328
+ ? (harness.parseModelValue ? harness.parseModelValue(payload.model) : { model: payload.model })
329
+ : undefined;
330
+ await connection.configure({
331
+ ...(parsedModel?.provider ? { provider: parsedModel.provider } : {}),
332
+ ...(parsedModel?.model ? { model: parsedModel.model } : {}),
333
+ ...(payload.thinking ? { thinking: payload.thinking } : {}),
334
+ });
335
+ }
336
+ const promptText = !connection.systemPrompt && payload.system
337
+ ? `${payload.system}\n\n---\n\n${payload.prompt}`
338
+ : payload.prompt;
339
+ collecting = true;
340
+ await connection.prompt([{ type: "text", text: promptText }]);
341
+ let cleaned = text;
342
+ if (connection.startupInfo) {
343
+ if (cleaned.startsWith(connection.startupInfo)) {
344
+ cleaned = cleaned.slice(connection.startupInfo.length);
345
+ } else {
346
+ const trimmedInfo = connection.startupInfo.trim();
347
+ const trimmedText = cleaned.trimStart();
348
+ if (trimmedInfo && trimmedText.startsWith(trimmedInfo)) {
349
+ cleaned = trimmedText.slice(trimmedInfo.length);
350
+ }
351
+ }
352
+ }
353
+ const answer = cleaned.trim();
354
+ requireThat(answer.length > 0, "ACP 摘要返回为空。");
355
+ await sendIpc({ type: "answer", text: answer });
356
+ } finally {
357
+ await connection.close();
358
+ }
359
+ } catch (error) {
360
+ await sendIpc({ type: "error", error: errorMessage(error) });
361
+ process.exitCode = 1;
362
+ } finally {
363
+ lifetime.abort();
364
+ if (process.connected) process.disconnect();
365
+ }
366
+ }
367
+
255
368
  const args = process.argv.slice(2);
256
369
  if (args.includes("--probe")) await runProbe();
370
+ else if (args.includes("--prompt")) await runOneShotPrompt();
257
371
  else await runWorker(args);
@@ -1,15 +1,15 @@
1
1
  import type { Context } from "@deepseek-ai/cordis";
2
2
  import * as McpClient from "@deepseek-ai/dsh-mcp-client";
3
- import type { AcpInput } from "../../model/acp.js";
4
- import { acpMember } from "../acp-member.js";
5
- import { rootAgents } from "../../integrations/dsh/root-agents.js";
6
- import { dshResources, dshExpertTools } from "../../integrations/dsh/resources.js";
7
- import { registerDshSkills } from "../../integrations/dsh/skills.js";
8
- import { toDshMcpConfig } from "../../integrations/dsh/mcp.js";
9
- import { finalDshAnswer } from "../../integrations/dsh/messages.js";
10
- import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../../services/workspace/workspace-mcp.js";
3
+ import type { AcpInput } from "../../../model/acp.js";
4
+ import { acpMember } from "../../acp/member.js";
5
+ import { rootAgents } from "../../../integrations/hosts/dsh/root-agents.js";
6
+ import { dshResources, dshExpertTools } from "../../../integrations/hosts/dsh/resources.js";
7
+ import { registerDshSkills } from "../../../integrations/hosts/dsh/skills.js";
8
+ import { toDshMcpConfig } from "../../../integrations/hosts/dsh/mcp.js";
9
+ import { finalDshAnswer } from "../../../integrations/hosts/dsh/messages.js";
10
+ import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../../../services/workspace/workspace-mcp.js";
11
11
  import { registerDshFileEvents } from "./files.js";
12
- import { requireThat } from "../../common/validation.js";
12
+ import { requireThat } from "../../../common/validation.js";
13
13
 
14
14
  export const name = "pbot-acp-member";
15
15
  export const inject = ["agents", "sessions", "llm", "tools", "systemPrompt", "skills", "fs", "workingDirectory", "approval"];
@@ -0,0 +1,92 @@
1
+ import type { Context } from "@deepseek-ai/cordis";
2
+ import type {} from "@deepseek-ai/dsh-commands";
3
+ import { json } from "../../../common/json.js";
4
+ import { requireThat } from "../../../common/validation.js";
5
+ import { createAcpHistorySummarizer } from "../../../integrations/acp/history-summary.js";
6
+ import { migrateWorkspaceHistory } from "../../../services/history/history-migrate.js";
7
+ import { parseHistoryCommand } from "../../../services/history/summary-command.js";
8
+ import { listSummaryDimensions } from "../../../services/history/summary-registry.js";
9
+ import { inspectWorkspaceSummaries, runWorkspaceSummaries } from "../../../services/history/summary-runner.js";
10
+ import { readWorkspaceConfig, readWorkspaceHistoryLayoutSync, workspaceDisabledMessage, workspaceSummaryConfig } from "../../../services/workspace/workspace-config.js";
11
+ import { dshWorkspaceStatus, type PbotManagement } from "./management.js";
12
+ import type { DshWorkspaces } from "./workspace.js";
13
+ import { parseWorkerCommand } from "../../mcp/workers.js";
14
+
15
+ const usage = '用法:/pbot status | init | history [summary [维度] [--force] [--backend <acp>] [--model <model>] | migrate [--dry-run] | status | list | {"action":…}] | worker [overview|status|backends|models|create|request|response|output|close] [JSON]';
16
+
17
+ export function registerDshCommand(ctx: Context, workspaces: DshWorkspaces, management: PbotManagement) {
18
+ ctx.commands.register({
19
+ name: "pbot",
20
+ description: "Personal Bot 工作区、历史摘要与跨 Harness worker 管理",
21
+ recordInput: false,
22
+ input: { hint: "status | init | history ... | worker ...", attachments: false },
23
+ async handler({ agent, rawInput, signal }) {
24
+ signal.throwIfAborted();
25
+ const command = rawInput.trim(), split = command.search(/\s/);
26
+ if (!command || command === "status") {
27
+ const status = await dshWorkspaceStatus(workspaces, agent);
28
+ signal.throwIfAborted(); return { kind: "success", text: JSON.stringify(status, null, 2) };
29
+ }
30
+ if (command === "init") {
31
+ await workspaces.initialize(agent);
32
+ signal.throwIfAborted();
33
+ return { kind: "success", text: JSON.stringify(await dshWorkspaceStatus(workspaces, agent), null, 2) };
34
+ }
35
+ const workspace = await workspaces.get(agent);
36
+ signal.throwIfAborted();
37
+ const verb = split < 0 ? command : command.slice(0, split);
38
+ const rest = split < 0 ? "" : command.slice(split).trim();
39
+ let result: unknown;
40
+ switch (verb) {
41
+ case "worker": {
42
+ const { tool, args } = parseWorkerCommand(rest);
43
+ result = await workspace.workers.callTool(tool, { workspace: workspace.root, ...args });
44
+ break;
45
+ }
46
+ case "history": {
47
+ requireThat(workspace.features.history, "当前工作区已停用历史功能(features.history: false)。");
48
+ const parsed = parseHistoryCommand(rest);
49
+ if (parsed.kind === "status") {
50
+ result = inspectWorkspaceSummaries(workspace.root);
51
+ } else if (parsed.kind === "list") {
52
+ const layout = readWorkspaceHistoryLayoutSync(workspace.root);
53
+ result = { layout, dimensions: listSummaryDimensions(layout).map(({ id, title, description }) => ({ id, title, description })) };
54
+ } else if (parsed.kind === "migrate") {
55
+ result = migrateWorkspaceHistory(workspace.root, { dryRun: parsed.dryRun });
56
+ } else if (parsed.kind === "query") {
57
+ result = await management.history({ parentSessionId: agent.id, input: json(parsed.input) }, signal);
58
+ } else {
59
+ const active = AbortSignal.any([signal, workspace.lifetime.signal]);
60
+ const config = await readWorkspaceConfig(workspace.root);
61
+ requireThat(config.enabled && !config.error, workspaceDisabledMessage(config));
62
+ const summaryCfg = workspaceSummaryConfig(config);
63
+ const backend = parsed.backend ?? summaryCfg.backend;
64
+ const model = parsed.model ?? summaryCfg.model;
65
+ const thinking = parsed.thinking ?? summaryCfg.thinking;
66
+ const summarizer = createAcpHistorySummarizer({
67
+ cwd: workspace.root,
68
+ backend,
69
+ ...(config.acp ? { commands: config.acp } : {}),
70
+ ...(model ? { model } : {}),
71
+ ...(thinking ? { thinking } : {}),
72
+ });
73
+ const report = await runWorkspaceSummaries({
74
+ root: workspace.root,
75
+ summarizer,
76
+ ...(parsed.dimensions ? { dimensions: parsed.dimensions } : {}),
77
+ force: parsed.force,
78
+ ...(summaryCfg.concurrency !== undefined ? { concurrency: summaryCfg.concurrency } : {}),
79
+ signal: active,
80
+ });
81
+ result = { backend, ...(model ? { model } : {}), ...report };
82
+ }
83
+ break;
84
+ }
85
+ default:
86
+ throw new Error(usage);
87
+ }
88
+ workspace.check();
89
+ return { kind: "success", text: JSON.stringify(result, null, 2) };
90
+ },
91
+ });
92
+ }
@@ -4,9 +4,9 @@ import type { Agent } from "@deepseek-ai/dsh-agent";
4
4
  import type { ToolExecution, ToolExecutionToken } from "@deepseek-ai/dsh-tools";
5
5
  import { parsePatch } from "@deepseek-ai/dsh-fs-patch";
6
6
  import type {} from "@deepseek-ai/dsh-user-approval";
7
- import { object } from "../../common/json.js";
8
- import { requireThat } from "../../common/validation.js";
9
- import { mutationScope } from "../../services/workspace/workspace-files.js";
7
+ import { object } from "../../../common/json.js";
8
+ import { requireThat } from "../../../common/validation.js";
9
+ import { mutationScope } from "../../../services/workspace/workspace-files.js";
10
10
 
11
11
  /** Native filesystem mutations share the original workspace's confirmation rule.
12
12
  * This does not confine Bash, Python, MCP, or other extensions. */
@@ -0,0 +1,67 @@
1
+ import type { Context } from "@deepseek-ai/cordis";
2
+ import type { Agent } from "@deepseek-ai/dsh-agent";
3
+ import type { SessionEvent } from "@deepseek-ai/dsh-session";
4
+ import { recordHistoryCapture } from "../../../services/history/history-capture.js";
5
+ import { finalDshAnswer } from "../../../integrations/hosts/dsh/messages.js";
6
+
7
+ type Question = Extract<SessionEvent, { type: "user/message" }>;
8
+
9
+ function userMessageText(content: Question["data"]["content"]): string {
10
+ return content.flatMap(block => block.type === "text" ? [block.text] :
11
+ block.type === "image" ? ["[图片 " + (block.attachment.name ?? block.attachment.attachmentId) + "]"] :
12
+ block.type === "file" ? ["[附件 " + (block.attachment.name ?? block.attachment.attachmentId) + "]"] : []).join("\n");
13
+ }
14
+
15
+ /** Capture root-session raw Q&A exchanges into .pbot/history/raw/. Summaries run on explicit trigger. */
16
+ export function registerDshHistoryEvents(ctx: Context, agent: Agent, root: string) {
17
+ let final = false;
18
+ let lastAnswer = "";
19
+ let lastAnswerTime: string | undefined;
20
+
21
+ ctx.on("session/event", (session, event) => {
22
+ if (session !== agent.session) return;
23
+ if (event.type === "turn/start") {
24
+ final = false;
25
+ lastAnswer = "";
26
+ lastAnswerTime = undefined;
27
+ }
28
+ if (event.type === "user/message" && event.data.source.kind === "user") {
29
+ const text = userMessageText(event.data.content).trim();
30
+ if (text) {
31
+ try {
32
+ recordHistoryCapture(root, "dsh", {
33
+ kind: "input",
34
+ sessionId: agent.id,
35
+ text,
36
+ timestamp: new Date(event.time).toISOString(),
37
+ });
38
+ } catch { /* Never block a user turn if history persistence fails. */ }
39
+ }
40
+ }
41
+ if (event.type === "assistant/message") {
42
+ const completeText = finalDshAnswer(event).trim();
43
+ final = Boolean(completeText);
44
+ const body = completeText || event.data.message.content.filter(block => block.type === "text").map(block => block.text).join("\n").trim();
45
+ if (body) {
46
+ lastAnswer = body;
47
+ lastAnswerTime = new Date(event.time).toISOString();
48
+ }
49
+ }
50
+ if (event.type === "turn/end") {
51
+ const completed = event.data.reason.kind === "completed" && final;
52
+ if (lastAnswer) {
53
+ try {
54
+ recordHistoryCapture(root, "dsh", {
55
+ kind: "answer",
56
+ sessionId: agent.id,
57
+ assistantText: lastAnswer,
58
+ completed,
59
+ ...(lastAnswerTime ? { timestamp: lastAnswerTime } : {}),
60
+ });
61
+ } catch { /* Never block turn completion if history persistence fails. */ }
62
+ }
63
+ lastAnswer = "";
64
+ lastAnswerTime = undefined;
65
+ }
66
+ });
67
+ }
@@ -4,13 +4,14 @@ import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
4
4
  import type {} from "@deepseek-ai/dsh-typert-registry";
5
5
  import { SessionId } from "@deepseek-ai/dsh-session";
6
6
  import { Type, type Static } from "typebox";
7
- import { json, type Json } from "../../common/json.js";
8
- import { requireThat } from "../../common/validation.js";
9
- import { schema } from "../../common/schema.js";
10
- import { packageVersion } from "../../common/version.js";
11
- import { historyInput } from "../../tools/history/contract.js";
12
- import { executeHistory } from "../../tools/history/actions.js";
13
- import { pbotReadRemote } from "../../ui/dsh/remote.js";
7
+ import { json, type Json } from "../../../common/json.js";
8
+ import { requireThat } from "../../../common/validation.js";
9
+ import { schema } from "../../../common/schema.js";
10
+ import { packageVersion } from "../../../common/version.js";
11
+ import { inspectWorkspaceSummaries } from "../../../services/history/summary-runner.js";
12
+ import { historyInput } from "../../../tools/history/contract.js";
13
+ import { executeHistory } from "../../../tools/history/actions.js";
14
+ import { pbotReadRemote } from "../../../ui/dsh/remote.js";
14
15
  import type { DshWorkspaces, DshWorkspace } from "./workspace.js";
15
16
 
16
17
  const requestSchema = Type.Object({ parentSessionId: Type.String({ minLength: 1 }), input: Type.Optional(Type.Unknown()) }, { additionalProperties: false });
@@ -26,7 +27,7 @@ export function dshStatus(workspace: DshWorkspace): Json {
26
27
  workspaceRoot: workspace.root,
27
28
  sessionId: workspace.agent.id,
28
29
  model: workspace.agent.model.current() ?? null,
29
- history: workspace.history.status,
30
+ history: workspace.features.history ? inspectWorkspaceSummaries(workspace.root) : null,
30
31
  });
31
32
  }
32
33
 
@@ -79,7 +80,8 @@ export class PbotManagement extends TypertRemoteService {
79
80
  @Remote
80
81
  async history(request: Json, signal: AbortSignal): Promise<Json> {
81
82
  const current = await this.workspace(request, signal), { workspace, input } = current;
82
- const result = await executeHistory(workspace.history, historyInput(input), { host: "dsh", sessionId: workspace.agent.id }, current.signal);
83
+ requireThat(workspace.features.history, "当前工作区已停用历史功能(features.history: false)。");
84
+ const result = executeHistory(workspace.root, historyInput(input), current.signal);
83
85
  workspace.check(); current.signal.throwIfAborted(); return json(result);
84
86
  }
85
87
  }
@@ -4,27 +4,27 @@ import { resolve } from "node:path";
4
4
  import type { Agent } from "@deepseek-ai/dsh-agent";
5
5
  import type { Context } from "@deepseek-ai/cordis";
6
6
  import * as McpClient from "@deepseek-ai/dsh-mcp-client";
7
- import { rootAgents } from "../../integrations/dsh/root-agents.js";
8
- import { dshResources } from "../../integrations/dsh/resources.js";
7
+ import { rootAgents } from "../../../integrations/hosts/dsh/root-agents.js";
8
+ import { dshResources } from "../../../integrations/hosts/dsh/resources.js";
9
9
  import { registerDshFileEvents } from "./files.js";
10
- import { DshHistoryWork, registerDshHistoryEvents } from "./history.js";
11
- import type { HistoryService } from "../../services/history/history-service.js";
12
- import { registerDshHistoryTool } from "../../tools/history/dsh-tool.js";
13
- import { resourceRoot } from "../../common/paths.js";
14
- import { requireThat } from "../../common/validation.js";
15
- import { toDshMcpConfig } from "../../integrations/dsh/mcp.js";
16
- import { registerDshSkills } from "../../integrations/dsh/skills.js";
17
- import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../services/workspace/workspace-config.js";
18
- import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../../services/workspace/workspace-mcp.js";
19
- import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration } from "../../model/workspace-config.js";
20
- import { initializeWorkspace } from "../../services/workspace/workspace-preparation.js";
21
- import { McpWorkerRuntime, defaultWorkerDirectory } from "../mcp-workers.js";
10
+ import { registerDshHistoryEvents } from "./history.js";
11
+ import { registerDshHistoryTool } from "../../../tools/history/dsh-tool.js";
12
+ import { resourceRoot } from "../../../common/paths.js";
13
+ import { requireThat } from "../../../common/validation.js";
14
+ import { toDshMcpConfig } from "../../../integrations/hosts/dsh/mcp.js";
15
+ import { registerDshSkills } from "../../../integrations/hosts/dsh/skills.js";
16
+ import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../../services/workspace/workspace-config.js";
17
+ import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../../../services/workspace/workspace-mcp.js";
18
+ import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration } from "../../../model/workspace-config.js";
19
+ import { initializeWorkspace } from "../../../services/workspace/workspace-preparation.js";
20
+ import { checkHistoryMigrationNotice } from "../../../services/history/history-migrate.js";
21
+ import { checkHistorySummaryReminder } from "../../../services/history/summary-runner.js";
22
+ import { McpWorkerRuntime, defaultWorkerDirectory } from "../../mcp/workers.js";
22
23
 
23
24
  export const dshDependencies = ["agents", "sessions", "sessionPersistence", "sessionQuery", "llm", "tools", "systemPrompt", "skills", "fs", "workingDirectory", "approval"];
24
25
 
25
26
  export class DshWorkspace {
26
27
  readonly lifetime = new AbortController();
27
- readonly history: HistoryService;
28
28
  readonly workers: McpWorkerRuntime;
29
29
  #scope: { dispose(): Promise<void> } | undefined;
30
30
  #closing: Promise<void> | undefined;
@@ -34,11 +34,8 @@ export class DshWorkspace {
34
34
  readonly root: string,
35
35
  readonly agent: Agent,
36
36
  readonly component: AbortSignal,
37
- private readonly historyWork: DshHistoryWork,
38
- private readonly releaseHistory: () => Promise<void>,
39
37
  readonly features: ResolvedWorkspaceFeatures = workspaceFeatures(),
40
38
  ) {
41
- this.history = historyWork.service;
42
39
  this.workers = new McpWorkerRuntime(defaultWorkerDirectory(), agent.id, "dsh");
43
40
  }
44
41
 
@@ -55,8 +52,16 @@ export class DshWorkspace {
55
52
  if (this.features.skills) registerDshSkills(ctx, this.agent, { workspaceRoot: this.root });
56
53
  if (this.features.prompts) await dshResources(ctx, this.agent, this.root, "coordinator", this.check, "history-coordinator.md");
57
54
  registerDshFileEvents(ctx, this.agent, this.root, false, this.check);
58
- registerDshHistoryTool(ctx, this.agent, this.history, this.lifetime.signal, this.check);
59
- registerDshHistoryEvents(ctx, this.agent, this.historyWork, this.check);
55
+ if (this.features.history) {
56
+ registerDshHistoryTool(ctx, this.agent, this.root, this.lifetime.signal, this.check);
57
+ registerDshHistoryEvents(ctx, this.agent, this.root);
58
+ try {
59
+ const migrationNotice = checkHistoryMigrationNotice(this.root);
60
+ if (migrationNotice) this.ctx.logger.info(migrationNotice);
61
+ const reminder = checkHistorySummaryReminder(this.root);
62
+ if (reminder) this.ctx.logger.info(reminder.message);
63
+ } catch { /* Never block workspace startup if history reminder probe fails. */ }
64
+ }
60
65
  if (existsSync(mcpEntry)) {
61
66
  await ctx.plugin(McpClient, McpClient.Config({
62
67
  transport: "stdio",
@@ -71,6 +76,8 @@ export class DshWorkspace {
71
76
  PBOT_WORKSPACE_ROOT: this.root,
72
77
  PBOT_MCP_AGENT_DIR: workerDir,
73
78
  PBOT_MCP_SESSION_ID: this.agent.id,
79
+ PBOT_NATIVE_WORKSPACE_MCP: "1",
80
+ PBOT_NATIVE_HISTORY: "1",
74
81
  },
75
82
  cwd: this.root,
76
83
  toolCallTimeoutMs: 600_000,
@@ -106,7 +113,6 @@ export class DshWorkspace {
106
113
  const errors: unknown[] = [];
107
114
  try { await this.workers.close(); } catch (error) { errors.push(error); }
108
115
  try { await this.#scope?.dispose(); } catch (error) { errors.push(error); }
109
- try { await this.releaseHistory(); } catch (error) { errors.push(error); }
110
116
  if (errors.length) throw new AggregateError(errors, "dsh 工作区关闭失败;请核对执行资源。");
111
117
  })();
112
118
  return this.#closing;
@@ -118,33 +124,10 @@ export class DshWorkspaces {
118
124
  readonly #initializing = new Map<string, Promise<void>>();
119
125
  readonly #configurations = new Map<Agent, { root: string; configuration: WorkspaceConfiguration }>();
120
126
  readonly #parentEffects = new Map<Agent, () => Promise<void>>();
121
- readonly #histories = new Map<string, { work: DshHistoryWork; users: number }>();
122
127
  readonly #lifetime = new AbortController();
123
128
  #closing: Promise<void> | undefined;
124
129
  constructor(readonly ctx: Context) {}
125
130
 
126
- private async history(root: string): Promise<{ work: DshHistoryWork; release(): Promise<void> }> {
127
- this.#lifetime.signal.throwIfAborted();
128
- let entry = this.#histories.get(root);
129
- if (entry && entry.users === 0) {
130
- await entry.work.close(); this.#lifetime.signal.throwIfAborted();
131
- if (this.#histories.get(root) === entry) this.#histories.delete(root);
132
- return this.history(root);
133
- }
134
- if (!entry) { entry = { work: new DshHistoryWork(this.ctx, root), users: 0 }; this.#histories.set(root, entry); }
135
- const owned = entry; owned.users++;
136
- let released = false;
137
- return {
138
- work: owned.work,
139
- release: async () => {
140
- if (released) return; released = true;
141
- if (--owned.users === 0) {
142
- try { await owned.work.close(); } finally { if (this.#histories.get(root) === owned) this.#histories.delete(root); }
143
- }
144
- },
145
- };
146
- }
147
-
148
131
  async open(agent: Agent) {
149
132
  this.#lifetime.signal.throwIfAborted();
150
133
  requireThat(rootAgents(this.ctx.agents).includes(agent), "子会话不拥有协调者管理入口。");
@@ -164,10 +147,9 @@ export class DshWorkspaces {
164
147
  this.#parentEffects.set(agent, dispose);
165
148
  return undefined;
166
149
  }
167
- const history = await this.history(root);
168
150
  let workspace: DshWorkspace | undefined;
169
151
  try {
170
- workspace = new DshWorkspace(this.ctx, root, agent, this.#lifetime.signal, history.work, history.release, workspaceFeatures(configuration));
152
+ workspace = new DshWorkspace(this.ctx, root, agent, this.#lifetime.signal, workspaceFeatures(configuration));
171
153
  const owned = workspace;
172
154
  const dispose = agent.ctx.effect(() => async () => {
173
155
  this.#parents.delete(agent); this.#configurations.delete(agent); this.#parentEffects.delete(agent); await owned.close();
@@ -178,7 +160,7 @@ export class DshWorkspaces {
178
160
  } catch (error) {
179
161
  try {
180
162
  const dispose = this.#parentEffects.get(agent);
181
- if (dispose) await dispose(); else if (workspace) await workspace.close(); else await history.release();
163
+ if (dispose) await dispose(); else if (workspace) await workspace.close();
182
164
  } catch (cleanup) { throw new AggregateError([error, cleanup], "dsh 工作区装配与清理均未完成。"); }
183
165
  throw error;
184
166
  }
@@ -240,10 +222,9 @@ export class DshWorkspaces {
240
222
  const opened = await Promise.allSettled(this.#parents.values());
241
223
  const closed = await Promise.allSettled(opened.flatMap(value => value.status === "fulfilled" && value.value ? [value.value.close()] : []));
242
224
  const effects = await Promise.allSettled([...this.#parentEffects.values()].map(dispose => dispose()));
243
- const histories = await Promise.allSettled([...this.#histories.values()].map(value => value.work.close()));
244
- const errors = [...new Set([...closed, ...effects, ...histories].flatMap(value => value.status === "rejected" ? [value.reason] : []))];
225
+ const errors = [...new Set([...closed, ...effects].flatMap(value => value.status === "rejected" ? [value.reason] : []))];
245
226
  if (errors.length) throw new AggregateError(errors, "部分 dsh 工作区未能完成关闭。");
246
- } finally { this.#parents.clear(); this.#configurations.clear(); this.#parentEffects.clear(); this.#histories.clear(); }
227
+ } finally { this.#parents.clear(); this.#configurations.clear(); this.#parentEffects.clear(); }
247
228
  })();
248
229
  return this.#closing;
249
230
  }
@@ -2,15 +2,15 @@ import { stat } from "node:fs/promises";
2
2
  import { realpathSync } from "node:fs";
3
3
  import { join } from "node:path";
4
4
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
5
- import { isMcpWorkerTool, type AcpInput } from "../model/acp.js";
6
- import { acpMember } from "./acp-member.js";
7
- import { agentFileTools } from "../integrations/pi/agent-tools.js";
8
- import { toPiMcpConfig } from "../integrations/pi/mcp.js";
9
- import { authorizeMutation } from "../services/workspace/workspace-files.js";
10
- import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../services/workspace/workspace-mcp.js";
11
- import { resourceRoot } from "../common/paths.js";
12
- import { launch } from "../storage/agent-files.js";
13
- import { requireThat } from "../common/validation.js";
5
+ import { isMcpWorkerTool, type AcpInput } from "../../../model/acp.js";
6
+ import { acpMember } from "../../acp/member.js";
7
+ import { agentFileTools } from "../../../integrations/hosts/pi/agent-tools.js";
8
+ import { toPiMcpConfig } from "../../../integrations/hosts/pi/mcp.js";
9
+ import { authorizeMutation } from "../../../services/workspace/workspace-files.js";
10
+ import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../../../services/workspace/workspace-mcp.js";
11
+ import { resourceRoot } from "../../../common/paths.js";
12
+ import { launch } from "../../../storage/agent-files.js";
13
+ import { requireThat } from "../../../common/validation.js";
14
14
 
15
15
  const isBlockedTool = (name: string) => name === "pbot_history" || isMcpWorkerTool(name);
16
16