@e4779/pi-fabric 0.92.24-fork.4 → 0.92.41-fork.6

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 (271) hide show
  1. package/README.md +2 -1
  2. package/dist/actors/host-event-payload.d.ts.map +1 -1
  3. package/dist/actors/types.d.ts +1 -1
  4. package/dist/actors/types.d.ts.map +1 -1
  5. package/dist/agents/completion-inbox.d.ts +15 -0
  6. package/dist/agents/completion-inbox.d.ts.map +1 -0
  7. package/dist/agents/handoff.d.ts.map +1 -1
  8. package/dist/agents/manager.d.ts +1 -0
  9. package/dist/agents/manager.d.ts.map +1 -1
  10. package/dist/agents/request.d.ts +4 -0
  11. package/dist/agents/request.d.ts.map +1 -1
  12. package/dist/agents/thinking-transfer.d.ts.map +1 -1
  13. package/dist/agents/transports/process-utils.d.ts.map +1 -1
  14. package/dist/agents.js +3 -2
  15. package/dist/agents.js.map +1 -1
  16. package/dist/build-identity.d.ts +21 -0
  17. package/dist/build-identity.d.ts.map +1 -0
  18. package/dist/chunks/{chunk-RERA6YWA.js → chunk-2A2NWQ36.js} +13 -5
  19. package/dist/chunks/chunk-2A2NWQ36.js.map +7 -0
  20. package/dist/chunks/{chunk-OTCASLY2.js → chunk-2QAOC3BO.js} +1 -1
  21. package/dist/chunks/chunk-2QAOC3BO.js.map +7 -0
  22. package/dist/chunks/{chunk-2PZWDVJB.js → chunk-2SWRVIYJ.js} +21 -9
  23. package/dist/chunks/chunk-2SWRVIYJ.js.map +7 -0
  24. package/dist/chunks/{chunk-4JETKRFE.js → chunk-36B4AIRT.js} +2 -2
  25. package/dist/chunks/{chunk-KFZYTGF5.js → chunk-3TXOQ5MG.js} +60 -46
  26. package/dist/chunks/chunk-3TXOQ5MG.js.map +7 -0
  27. package/dist/chunks/{chunk-VWSXAEX6.js → chunk-4NUTVNS2.js} +44 -202
  28. package/dist/chunks/chunk-4NUTVNS2.js.map +7 -0
  29. package/dist/chunks/{chunk-VYXFSUWU.js → chunk-77PDIBK2.js} +12 -1
  30. package/dist/chunks/{chunk-VYXFSUWU.js.map → chunk-77PDIBK2.js.map} +2 -2
  31. package/dist/chunks/{chunk-X7G62ZGH.js → chunk-7BG5COXB.js} +8 -3
  32. package/dist/chunks/{chunk-X7G62ZGH.js.map → chunk-7BG5COXB.js.map} +2 -2
  33. package/dist/chunks/{chunk-IYQ5MNCW.js → chunk-7VAZ4N43.js} +42 -24
  34. package/dist/chunks/chunk-7VAZ4N43.js.map +7 -0
  35. package/dist/chunks/chunk-A4VP7HDF.js +226 -0
  36. package/dist/chunks/chunk-A4VP7HDF.js.map +7 -0
  37. package/dist/chunks/chunk-B54Z662X.js +127 -0
  38. package/dist/chunks/chunk-B54Z662X.js.map +7 -0
  39. package/dist/chunks/{chunk-4SSMGBF4.js → chunk-CGL7QP4A.js} +58 -8
  40. package/dist/chunks/chunk-CGL7QP4A.js.map +7 -0
  41. package/dist/chunks/{chunk-32BNQ75J.js → chunk-FLKGJPCN.js} +99 -3
  42. package/dist/chunks/chunk-FLKGJPCN.js.map +7 -0
  43. package/dist/chunks/{chunk-QX3TUAWO.js → chunk-GGETIGM5.js} +487 -707
  44. package/dist/chunks/chunk-GGETIGM5.js.map +7 -0
  45. package/dist/chunks/{chunk-WVH324VF.js → chunk-IJL3QK3J.js} +3 -1
  46. package/dist/chunks/chunk-IJL3QK3J.js.map +7 -0
  47. package/dist/chunks/{chunk-3CPWRPCE.js → chunk-IK6PPFWG.js} +17 -6
  48. package/dist/chunks/chunk-IK6PPFWG.js.map +7 -0
  49. package/dist/chunks/{chunk-ZMIJ6AT4.js → chunk-IUCVOZRX.js} +3 -3
  50. package/dist/chunks/{chunk-3ZX76BVU.js → chunk-K6DHXXF5.js} +12 -10
  51. package/dist/chunks/chunk-K6DHXXF5.js.map +7 -0
  52. package/dist/chunks/{chunk-NPHCGLGH.js → chunk-MW5VI7IW.js} +135 -31
  53. package/dist/chunks/chunk-MW5VI7IW.js.map +7 -0
  54. package/dist/chunks/{chunk-BOTRGFQQ.js → chunk-NHMICIEU.js} +26 -19
  55. package/dist/chunks/chunk-NHMICIEU.js.map +7 -0
  56. package/dist/chunks/{chunk-Y7KNRAFL.js → chunk-PMSIZLV6.js} +29 -3
  57. package/dist/chunks/chunk-PMSIZLV6.js.map +7 -0
  58. package/dist/chunks/{chunk-7OH6DD3S.js → chunk-Q4XJ4PYL.js} +529 -168
  59. package/dist/chunks/chunk-Q4XJ4PYL.js.map +7 -0
  60. package/dist/chunks/chunk-RKRVOBVO.js +134 -0
  61. package/dist/chunks/chunk-RKRVOBVO.js.map +7 -0
  62. package/dist/chunks/{chunk-M3S7XITB.js → chunk-TGAVMUOS.js} +29 -13
  63. package/dist/chunks/chunk-TGAVMUOS.js.map +7 -0
  64. package/dist/chunks/chunk-TX6E5W7H.js +50 -0
  65. package/dist/chunks/chunk-TX6E5W7H.js.map +7 -0
  66. package/dist/chunks/{chunk-X3OD47CL.js → chunk-UR2K6WK6.js} +8 -11
  67. package/dist/chunks/chunk-UR2K6WK6.js.map +7 -0
  68. package/dist/chunks/{chunk-Z63R5GVN.js → chunk-WHBJDTCR.js} +6 -2
  69. package/dist/chunks/chunk-WHBJDTCR.js.map +7 -0
  70. package/dist/chunks/{chunk-RRGTKHXZ.js → chunk-X7XFT57O.js} +9 -140
  71. package/dist/chunks/{chunk-RRGTKHXZ.js.map → chunk-X7XFT57O.js.map} +4 -4
  72. package/dist/chunks/chunk-YV2PHCDB.js +108 -0
  73. package/dist/chunks/chunk-YV2PHCDB.js.map +7 -0
  74. package/dist/chunks/chunk-Z64PRP7A.js +156 -0
  75. package/dist/chunks/chunk-Z64PRP7A.js.map +7 -0
  76. package/dist/components/configuration.d.ts +42 -0
  77. package/dist/components/configuration.d.ts.map +1 -0
  78. package/dist/components/configuration.js +19 -0
  79. package/dist/components/configuration.js.map +7 -0
  80. package/dist/components/control.d.ts +76 -0
  81. package/dist/components/control.d.ts.map +1 -0
  82. package/dist/components/loader.d.ts +12 -0
  83. package/dist/components/loader.d.ts.map +1 -1
  84. package/dist/components/provider-component.d.ts +1 -1
  85. package/dist/components/provider-component.d.ts.map +1 -1
  86. package/dist/components/supervisor.d.ts.map +1 -1
  87. package/dist/components/types.d.ts +2 -0
  88. package/dist/components/types.d.ts.map +1 -1
  89. package/dist/components/validation.d.ts +6 -0
  90. package/dist/components/validation.d.ts.map +1 -0
  91. package/dist/config.d.ts +14 -2
  92. package/dist/config.d.ts.map +1 -1
  93. package/dist/core/action-registry.d.ts +9 -0
  94. package/dist/core/action-registry.d.ts.map +1 -1
  95. package/dist/core/action-registry.js +6 -4
  96. package/dist/core/approval-controller.d.ts +5 -1
  97. package/dist/core/approval-controller.d.ts.map +1 -1
  98. package/dist/core/auto-approval-classifier.d.ts +11 -0
  99. package/dist/core/auto-approval-classifier.d.ts.map +1 -1
  100. package/dist/core/compact-controller.d.ts.map +1 -1
  101. package/dist/core/fabric-state-paths.d.ts +2 -0
  102. package/dist/core/fabric-state-paths.d.ts.map +1 -0
  103. package/dist/core/media-sanitize.d.ts +46 -0
  104. package/dist/core/media-sanitize.d.ts.map +1 -0
  105. package/dist/core/model-resolution.d.ts +23 -5
  106. package/dist/core/model-resolution.d.ts.map +1 -1
  107. package/dist/core/semantic-search.d.ts +56 -0
  108. package/dist/core/semantic-search.d.ts.map +1 -0
  109. package/dist/core/shell-jobs.d.ts.map +1 -1
  110. package/dist/core/shell-middleware.d.ts +4 -0
  111. package/dist/core/shell-middleware.d.ts.map +1 -0
  112. package/dist/execution-service.d.ts +3 -1
  113. package/dist/execution-service.d.ts.map +1 -1
  114. package/dist/fabric-exec-tool.d.ts.map +1 -1
  115. package/dist/fabric-runtime-state.d.ts +2 -0
  116. package/dist/fabric-runtime-state.d.ts.map +1 -1
  117. package/dist/fabric-runtime-state.js +1595 -239
  118. package/dist/fabric-runtime-state.js.map +4 -4
  119. package/dist/fabric-state.d.ts +2 -0
  120. package/dist/fabric-state.d.ts.map +1 -1
  121. package/dist/index.d.ts.map +1 -1
  122. package/dist/index.js +284 -60
  123. package/dist/index.js.map +4 -4
  124. package/dist/jev/browser.d.ts.map +1 -1
  125. package/dist/jev/browser.js +1 -1
  126. package/dist/jev/client.d.ts +8 -2
  127. package/dist/jev/client.d.ts.map +1 -1
  128. package/dist/jev/client.js +3 -2
  129. package/dist/jev/config.d.ts.map +1 -1
  130. package/dist/jev/model-key.d.ts +9 -2
  131. package/dist/jev/model-key.d.ts.map +1 -1
  132. package/dist/jev/observation.js +4 -3
  133. package/dist/jev/routes.d.ts +69 -0
  134. package/dist/jev/routes.d.ts.map +1 -0
  135. package/dist/jev/validation.d.ts.map +1 -1
  136. package/dist/jev.d.ts +1 -0
  137. package/dist/jev.d.ts.map +1 -1
  138. package/dist/jev.js +35 -9
  139. package/dist/mcp.d.ts.map +1 -1
  140. package/dist/mcp.js +9 -2
  141. package/dist/mcp.js.map +2 -2
  142. package/dist/output-budget.d.ts.map +1 -1
  143. package/dist/prewalk/arm.d.ts.map +1 -1
  144. package/dist/prewalk/controller.d.ts +57 -6
  145. package/dist/prewalk/controller.d.ts.map +1 -1
  146. package/dist/prewalk/fs-drift.d.ts.map +1 -1
  147. package/dist/prewalk/handoff.d.ts +5 -25
  148. package/dist/prewalk/handoff.d.ts.map +1 -1
  149. package/dist/prewalk/messages.d.ts +24 -0
  150. package/dist/prewalk/messages.d.ts.map +1 -0
  151. package/dist/prewalk/model-switch.d.ts +3 -0
  152. package/dist/prewalk/model-switch.d.ts.map +1 -0
  153. package/dist/prewalk/plan.d.ts +46 -0
  154. package/dist/prewalk/plan.d.ts.map +1 -0
  155. package/dist/prewalk/return.d.ts +16 -0
  156. package/dist/prewalk/return.d.ts.map +1 -0
  157. package/dist/protocol.d.ts +11 -1
  158. package/dist/protocol.d.ts.map +1 -1
  159. package/dist/protocol.js +3 -1
  160. package/dist/providers/agents-actions.d.ts.map +1 -1
  161. package/dist/providers/agents-provider.d.ts.map +1 -1
  162. package/dist/providers/captured-tools-provider.d.ts.map +1 -1
  163. package/dist/providers/components-provider.d.ts +5 -3
  164. package/dist/providers/components-provider.d.ts.map +1 -1
  165. package/dist/providers/jev-provider.d.ts +2 -0
  166. package/dist/providers/jev-provider.d.ts.map +1 -1
  167. package/dist/providers/jev-provider.js +8 -7
  168. package/dist/providers/mcp-descriptor-cache.d.ts +2 -0
  169. package/dist/providers/mcp-descriptor-cache.d.ts.map +1 -1
  170. package/dist/providers/pi-tools-provider.d.ts.map +1 -1
  171. package/dist/providers/prewalk-provider.d.ts +19 -0
  172. package/dist/providers/prewalk-provider.d.ts.map +1 -0
  173. package/dist/repeat-guard.d.ts +4 -0
  174. package/dist/repeat-guard.d.ts.map +1 -1
  175. package/dist/residency/actor-client.d.ts +2 -2
  176. package/dist/residency/actor-client.d.ts.map +1 -1
  177. package/dist/residency/actor-client.js +2 -2
  178. package/dist/residency/client.d.ts +3 -0
  179. package/dist/residency/client.d.ts.map +1 -1
  180. package/dist/residency/host.d.ts.map +1 -1
  181. package/dist/residency/host.js +10 -8
  182. package/dist/residency/pi-entry.js +10 -8
  183. package/dist/residency/pi-entry.js.map +1 -1
  184. package/dist/residency/protocol.d.ts +15 -2
  185. package/dist/residency/protocol.d.ts.map +1 -1
  186. package/dist/runtime/core-override-guest-types.js +2 -2
  187. package/dist/runtime/cpython-runtime.d.ts +2 -0
  188. package/dist/runtime/cpython-runtime.d.ts.map +1 -1
  189. package/dist/runtime/cpython-runtime.js +7 -3
  190. package/dist/runtime/cpython-runtime.js.map +2 -2
  191. package/dist/runtime/guest-types.d.ts +1 -1
  192. package/dist/runtime/guest-types.d.ts.map +1 -1
  193. package/dist/runtime/guest-types.js +1 -1
  194. package/dist/runtime/monty-runtime.js +5 -3
  195. package/dist/runtime/monty-runtime.js.map +2 -2
  196. package/dist/runtime/node-process-runtime.d.ts.map +1 -1
  197. package/dist/runtime/node-process-runtime.js +3 -3
  198. package/dist/runtime/quickjs-runtime.d.ts.map +1 -1
  199. package/dist/runtime/quickjs-runtime.js +1 -1
  200. package/dist/runtime/typescript-kernel.js +8 -8
  201. package/dist/runtime-state-builtins.d.ts.map +1 -1
  202. package/dist/schema/policy.d.ts.map +1 -1
  203. package/dist/ui/code-preview-shell.d.ts.map +1 -1
  204. package/dist/ui/controller.d.ts.map +1 -1
  205. package/dist/ui/conversation-native-reader.d.ts.map +1 -1
  206. package/dist/ui/conversation-native-reader.js.map +2 -2
  207. package/dist/ui/dashboard.js +2 -2
  208. package/dist/ui/settings-section-context.d.ts +1 -0
  209. package/dist/ui/settings-section-context.d.ts.map +1 -1
  210. package/dist/ui/settings-sections-agents.d.ts.map +1 -1
  211. package/dist/ui/settings-sections-execution.d.ts +1 -1
  212. package/dist/ui/settings-sections-execution.d.ts.map +1 -1
  213. package/dist/ui/settings-sections.d.ts +1 -0
  214. package/dist/ui/settings-sections.d.ts.map +1 -1
  215. package/dist/ui/settings-values.d.ts +1 -0
  216. package/dist/ui/settings-values.d.ts.map +1 -1
  217. package/dist/ui/settings.d.ts.map +1 -1
  218. package/dist/ui/settings.js +57 -17
  219. package/dist/ui/settings.js.map +2 -2
  220. package/dist/ui/spinner.d.ts +8 -1
  221. package/dist/ui/spinner.d.ts.map +1 -1
  222. package/dist/ui/widget.d.ts +12 -1
  223. package/dist/ui/widget.d.ts.map +1 -1
  224. package/dist/worker.js +1 -3
  225. package/dist/worker.js.map +2 -2
  226. package/docs/agents.md +35 -11
  227. package/docs/architecture.md +1 -1
  228. package/docs/components.md +30 -1
  229. package/docs/configuration.md +23 -15
  230. package/docs/foreman.md +65 -0
  231. package/docs/jev.md +77 -4
  232. package/docs/programmatic-compaction.md +12 -7
  233. package/docs/shell-middleware.md +61 -0
  234. package/docs/skills.md +2 -1
  235. package/package.json +5 -4
  236. package/skillsets/python/fabric-exec/SKILL.md +1 -1
  237. package/skillsets/python/fabric-exec/references/agents.md +1 -1
  238. package/skillsets/python/fabric-exec/references/mcp.md +1 -1
  239. package/skillsets/python/fabric-foreman/SKILL.md +249 -0
  240. package/skillsets/python/fabric-guide/SKILL.md +2 -1
  241. package/skillsets/python/fabric-jev/SKILL.md +2 -2
  242. package/skillsets/typescript/fabric-exec/SKILL.md +9 -3
  243. package/skillsets/typescript/fabric-exec/references/agents.md +5 -3
  244. package/skillsets/typescript/fabric-foreman/SKILL.md +240 -0
  245. package/skillsets/typescript/fabric-guide/SKILL.md +2 -1
  246. package/skillsets/typescript/fabric-jev/SKILL.md +2 -2
  247. package/dist/chunks/chunk-2IAVP4O2.js +0 -447
  248. package/dist/chunks/chunk-2IAVP4O2.js.map +0 -7
  249. package/dist/chunks/chunk-2PZWDVJB.js.map +0 -7
  250. package/dist/chunks/chunk-32BNQ75J.js.map +0 -7
  251. package/dist/chunks/chunk-3CPWRPCE.js.map +0 -7
  252. package/dist/chunks/chunk-3ZX76BVU.js.map +0 -7
  253. package/dist/chunks/chunk-4SSMGBF4.js.map +0 -7
  254. package/dist/chunks/chunk-7OH6DD3S.js.map +0 -7
  255. package/dist/chunks/chunk-BOTRGFQQ.js.map +0 -7
  256. package/dist/chunks/chunk-IYQ5MNCW.js.map +0 -7
  257. package/dist/chunks/chunk-KFZYTGF5.js.map +0 -7
  258. package/dist/chunks/chunk-M3S7XITB.js.map +0 -7
  259. package/dist/chunks/chunk-NPHCGLGH.js.map +0 -7
  260. package/dist/chunks/chunk-OTCASLY2.js.map +0 -7
  261. package/dist/chunks/chunk-QX3TUAWO.js.map +0 -7
  262. package/dist/chunks/chunk-RERA6YWA.js.map +0 -7
  263. package/dist/chunks/chunk-TSRKCXNI.js +0 -17
  264. package/dist/chunks/chunk-TSRKCXNI.js.map +0 -7
  265. package/dist/chunks/chunk-VWSXAEX6.js.map +0 -7
  266. package/dist/chunks/chunk-WVH324VF.js.map +0 -7
  267. package/dist/chunks/chunk-X3OD47CL.js.map +0 -7
  268. package/dist/chunks/chunk-Y7KNRAFL.js.map +0 -7
  269. package/dist/chunks/chunk-Z63R5GVN.js.map +0 -7
  270. /package/dist/chunks/{chunk-4JETKRFE.js.map → chunk-36B4AIRT.js.map} +0 -0
  271. /package/dist/chunks/{chunk-ZMIJ6AT4.js.map → chunk-IUCVOZRX.js.map} +0 -0
@@ -5,7 +5,7 @@ import {
5
5
  scriptSpawnArgs,
6
6
  spawnDetached,
7
7
  workerCommand
8
- } from "./chunk-X7G62ZGH.js";
8
+ } from "./chunk-7BG5COXB.js";
9
9
  import {
10
10
  mapVedaTools,
11
11
  normalizeVedaModel
@@ -16,9 +16,8 @@ import {
16
16
  normalizeClaudeModel
17
17
  } from "./chunk-PM5I335G.js";
18
18
  import {
19
- peerLabelPrefix,
20
- writeHandoffSession
21
- } from "./chunk-2IAVP4O2.js";
19
+ peerLabelPrefix
20
+ } from "./chunk-YV2PHCDB.js";
22
21
  import {
23
22
  resolveAgentDir
24
23
  } from "./chunk-PXAICAUT.js";
@@ -30,11 +29,15 @@ import {
30
29
  MAX_AGENT_TIMEOUT_MS,
31
30
  MIN_AGENT_TIMEOUT_MS,
32
31
  quarantineDamagedFile
33
- } from "./chunk-VWSXAEX6.js";
32
+ } from "./chunk-4NUTVNS2.js";
34
33
  import {
35
34
  ownedStat,
36
35
  processAlive
37
36
  } from "./chunk-RAO6TQFP.js";
37
+ import {
38
+ compileFabricSummary,
39
+ rawContextTokens
40
+ } from "./chunk-MQG5QKGI.js";
38
41
  import {
39
42
  writeFileAtomic,
40
43
  writeJsonAtomic
@@ -56,10 +59,14 @@ import {
56
59
  } from "./chunk-AYBIR4YV.js";
57
60
  import {
58
61
  FABRIC_ACTOR_HOST_EVENTS
59
- } from "./chunk-OTCASLY2.js";
62
+ } from "./chunk-2QAOC3BO.js";
60
63
  import {
61
64
  isFabricThinking
62
65
  } from "./chunk-MGWQOKBV.js";
66
+ import {
67
+ compactionRequestBoundsError,
68
+ encodeCompactionRequest
69
+ } from "./chunk-3H7SDWZI.js";
63
70
 
64
71
  // src/core/model-usage.ts
65
72
  import { readFileSync } from "node:fs";
@@ -951,10 +958,10 @@ function appendBudgetLedger(file, entry) {
951
958
  }
952
959
 
953
960
  // src/agents/manager.ts
954
- import { randomUUID as randomUUID4 } from "node:crypto";
955
- import fs9 from "node:fs";
961
+ import { randomUUID as randomUUID5 } from "node:crypto";
962
+ import fs10 from "node:fs";
956
963
  import os3 from "node:os";
957
- import path11 from "node:path";
964
+ import path12 from "node:path";
958
965
  import { fileURLToPath } from "node:url";
959
966
 
960
967
  // src/core/child-tool-allowlist.ts
@@ -1478,17 +1485,350 @@ var WorktreeManager = class {
1478
1485
  }
1479
1486
  };
1480
1487
 
1481
- // src/storage/retention.ts
1488
+ // src/agents/handoff.ts
1489
+ import { randomUUID as randomUUID4 } from "node:crypto";
1482
1490
  import fs8 from "node:fs";
1483
1491
  import path9 from "node:path";
1492
+ import {
1493
+ CURRENT_SESSION_VERSION,
1494
+ SessionManager
1495
+ } from "@earendil-works/pi-coding-agent";
1496
+
1497
+ // src/agents/thinking-transfer.ts
1498
+ var REASONING_CONTENT_SIGNATURE = "reasoning_content";
1499
+ var OPENAI_COMPLETIONS_API = "openai-completions";
1500
+ var thinkingTransferPolicy = (input) => {
1501
+ const { source, target } = input;
1502
+ if (source && source.provider === target.provider && (source.api === void 0 || target.api === void 0 || source.api === target.api)) {
1503
+ return "preserved";
1504
+ }
1505
+ if (target.api === OPENAI_COMPLETIONS_API && target.reasoning === true && target.requiresThinkingAsText !== true) {
1506
+ return "re-signed";
1507
+ }
1508
+ return "stripped";
1509
+ };
1510
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1511
+ var isThinkingPart = (part) => isRecord(part) && part.type === "thinking";
1512
+ var translateThinkingForExecutor = (entries, policy) => {
1513
+ if (policy === "preserved") {
1514
+ return { entries, report: { policy, translated: 0, dropped: 0 } };
1515
+ }
1516
+ const clone = structuredClone(entries);
1517
+ let translated = 0;
1518
+ let dropped = 0;
1519
+ for (const entry of clone) {
1520
+ if (entry.type !== "message") continue;
1521
+ const message = entry.message;
1522
+ if (message.role !== "assistant" || !Array.isArray(message.content)) continue;
1523
+ const kept = [];
1524
+ for (const part of message.content) {
1525
+ if (isRecord(part) && part.type === "toolCall") {
1526
+ delete part.thoughtSignature;
1527
+ kept.push(part);
1528
+ continue;
1529
+ }
1530
+ if (!isThinkingPart(part)) {
1531
+ kept.push(part);
1532
+ continue;
1533
+ }
1534
+ const text = typeof part.thinking === "string" ? part.thinking : "";
1535
+ if (policy === "re-signed" && part.redacted !== true && text.trim().length > 0) {
1536
+ part.thinkingSignature = REASONING_CONTENT_SIGNATURE;
1537
+ translated += 1;
1538
+ kept.push(part);
1539
+ continue;
1540
+ }
1541
+ dropped += 1;
1542
+ }
1543
+ message.content = kept;
1544
+ }
1545
+ return { entries: clone, report: { policy, translated, dropped } };
1546
+ };
1547
+ var THINKING_DIGEST_CUSTOM_TYPE = "pi-fabric-handoff-thinking";
1548
+ var MAX_DIGEST_BLOCKS = 8;
1549
+ var MAX_DIGEST_LINE = 80;
1550
+ var MAX_DIGEST_BYTES = 2048;
1551
+ var firstLineOf = (text) => {
1552
+ const end = text.indexOf("\n");
1553
+ return end === -1 ? text : text.slice(0, end);
1554
+ };
1555
+ var truncate = (text, max) => text.length > max ? text.slice(0, max) : text;
1556
+ var clipUtf8 = (text, maxBytes) => {
1557
+ if (Buffer.byteLength(text, "utf8") <= maxBytes) return text;
1558
+ let out = "";
1559
+ let bytes = 0;
1560
+ for (const char of text) {
1561
+ const size = Buffer.byteLength(char, "utf8");
1562
+ if (bytes + size > maxBytes) break;
1563
+ out += char;
1564
+ bytes += size;
1565
+ }
1566
+ return out;
1567
+ };
1568
+ var buildThinkingDigest = (entries, input) => {
1569
+ const blocks = [];
1570
+ let hasTask = false;
1571
+ for (const entry of entries) {
1572
+ if (entry.type !== "message") continue;
1573
+ const message = entry.message;
1574
+ if (message.role === "user") {
1575
+ hasTask = true;
1576
+ blocks.length = 0;
1577
+ continue;
1578
+ }
1579
+ if (!hasTask || message.role !== "assistant" || !Array.isArray(message.content)) continue;
1580
+ if (input.source && (message.provider !== input.source.provider || message.model !== input.source.modelId)) continue;
1581
+ for (const part of message.content) {
1582
+ if (!isThinkingPart(part)) continue;
1583
+ const text = typeof part.thinking === "string" ? part.thinking : "";
1584
+ const line = truncate(firstLineOf(text).trim(), MAX_DIGEST_LINE);
1585
+ if (line) blocks.push({ entryId: entry.id, line });
1586
+ }
1587
+ }
1588
+ if (blocks.length === 0) return void 0;
1589
+ const recent = blocks.slice(-MAX_DIGEST_BLOCKS);
1590
+ const omitted = blocks.length - recent.length;
1591
+ const sourceId = input.source ? `${input.source.provider}/${input.source.modelId}` : "the prior model";
1592
+ const targetId = `${input.target.provider}/${input.target.modelId}`;
1593
+ const lines = [
1594
+ "Prewalk handoff continuity digest (deliberation, not commitments).",
1595
+ `Thinking from ${sourceId} was not transferred: ${targetId} cannot replay it (incompatible reasoning channels). Most recent lines:`,
1596
+ ...recent.map((block) => `- [entry ${block.entryId}] ${block.line}`)
1597
+ ];
1598
+ if (omitted > 0) lines.push(`(omitted ${omitted} older thinking blocks)`);
1599
+ lines.push("Full thinking remains addressable in the source session by entry id.");
1600
+ return {
1601
+ content: clipUtf8(lines.join("\n"), MAX_DIGEST_BYTES),
1602
+ citedBlocks: recent.length
1603
+ };
1604
+ };
1605
+
1606
+ // src/agents/handoff.ts
1607
+ var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1608
+ var checkedHandoffCompaction = (value) => {
1609
+ if (value === void 0 || value === false) return void 0;
1610
+ const input = value === true ? {} : value;
1611
+ if (!isRecord2(input)) {
1612
+ throw new Error(
1613
+ "Invalid agents.handoff compact arguments: compact must be true or an object with instructions/preserve"
1614
+ );
1615
+ }
1616
+ if (input.instructions !== void 0 && typeof input.instructions !== "string") {
1617
+ throw new Error("Invalid agents.handoff compact arguments: instructions must be a string");
1618
+ }
1619
+ if (input.preserve !== void 0 && (!Array.isArray(input.preserve) || input.preserve.some((item) => typeof item !== "string"))) {
1620
+ throw new Error(
1621
+ "Invalid agents.handoff compact arguments: preserve must be an array of strings"
1622
+ );
1623
+ }
1624
+ const request = {
1625
+ ...typeof input.instructions === "string" ? { instructions: input.instructions } : {},
1626
+ ...input.preserve !== void 0 ? { preserve: input.preserve } : {}
1627
+ };
1628
+ const boundsError = compactionRequestBoundsError(request);
1629
+ if (boundsError) {
1630
+ throw new Error(`Invalid agents.handoff compact arguments: ${boundsError.message}`);
1631
+ }
1632
+ return request;
1633
+ };
1634
+ var isToolCall = (value) => isRecord2(value) && value.type === "toolCall" && typeof value.id === "string" && typeof value.name === "string" && isRecord2(value.arguments);
1635
+ var activeFabricTurn = (source, outerToolCallId) => {
1636
+ const leafId = source.getLeafId();
1637
+ const entry = leafId ? source.getEntry(leafId) : void 0;
1638
+ if (entry?.type !== "message" || entry.message.role !== "assistant") {
1639
+ throw new Error(
1640
+ "Trajectory handoff requires the active fabric_exec assistant turn to be the session leaf"
1641
+ );
1642
+ }
1643
+ const content = Array.isArray(entry.message.content) ? entry.message.content : [];
1644
+ const toolCalls = content.filter(isToolCall);
1645
+ if (!toolCalls.some((call) => call.id === outerToolCallId)) {
1646
+ throw new Error(
1647
+ "Trajectory handoff could not find the active fabric_exec assistant turn in the Pi session"
1648
+ );
1649
+ }
1650
+ if (toolCalls.length !== 1 || toolCalls[0]?.name !== "fabric_exec") {
1651
+ throw new Error(
1652
+ "Trajectory handoff requires fabric_exec to be the only top-level tool call in its assistant turn"
1653
+ );
1654
+ }
1655
+ return entry;
1656
+ };
1657
+ var snapshotHandoffSession = (source, currentModel, outerToolResult, outerToolCallId) => {
1658
+ if (outerToolResult.toolCallId !== outerToolCallId || outerToolResult.toolName !== "fabric_exec") {
1659
+ throw new Error("Trajectory handoff requires the finalized outer fabric_exec result");
1660
+ }
1661
+ const active = activeFabricTurn(source, outerToolCallId);
1662
+ const sourceSessionFile = source.getSessionFile();
1663
+ const branch = source.getBranch();
1664
+ let model = currentModel ? { provider: currentModel.provider, modelId: currentModel.id } : void 0;
1665
+ let thinkingLevel;
1666
+ for (let index = branch.length - 1; index >= 0; index--) {
1667
+ const entry = branch[index];
1668
+ if (!thinkingLevel && entry?.type === "thinking_level_change") {
1669
+ thinkingLevel = entry.thinkingLevel;
1670
+ }
1671
+ if (!model && entry?.type === "model_change") {
1672
+ model = { provider: entry.provider, modelId: entry.modelId };
1673
+ }
1674
+ if (model && thinkingLevel) break;
1675
+ }
1676
+ return {
1677
+ sourceSessionId: source.getSessionId(),
1678
+ ...sourceSessionFile ? { sourceSessionFile } : {},
1679
+ sourceBranchLeafId: active.id,
1680
+ ...!sourceSessionFile ? { sourceBranch: structuredClone(branch) } : {},
1681
+ ...model ? { sourceModel: model } : {},
1682
+ ...thinkingLevel ? { sourceThinkingLevel: thinkingLevel } : {},
1683
+ outerToolResult: structuredClone(outerToolResult)
1684
+ };
1685
+ };
1686
+ var materializeBranch = (seed, cwd, directory) => {
1687
+ if (!seed.sourceBranch) {
1688
+ throw new Error("In-memory trajectory handoff is missing its source branch");
1689
+ }
1690
+ const id = randomUUID4();
1691
+ const sessionFile = path9.join(directory, `handoff-${id}.jsonl`);
1692
+ const header = {
1693
+ type: "session",
1694
+ version: CURRENT_SESSION_VERSION,
1695
+ id,
1696
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1697
+ cwd,
1698
+ ...seed.sourceSessionFile ? { parentSession: seed.sourceSessionFile } : {}
1699
+ };
1700
+ fs8.writeFileSync(
1701
+ sessionFile,
1702
+ `${[header, ...seed.sourceBranch].map((entry) => JSON.stringify(entry)).join("\n")}
1703
+ `,
1704
+ { encoding: "utf8", mode: 384, flag: "wx" }
1705
+ );
1706
+ return SessionManager.open(sessionFile, directory, cwd);
1707
+ };
1708
+ var forkBranch = (seed, cwd, directory) => {
1709
+ if (!seed.sourceSessionFile) return materializeBranch(seed, cwd, directory);
1710
+ const fork = SessionManager.open(seed.sourceSessionFile, directory, cwd);
1711
+ if (!fork.getEntry(seed.sourceBranchLeafId)) {
1712
+ throw new Error(
1713
+ `Trajectory handoff branch point ${seed.sourceBranchLeafId} is missing from the persisted Pi session`
1714
+ );
1715
+ }
1716
+ const sessionFile = fork.createBranchedSession(seed.sourceBranchLeafId);
1717
+ if (!sessionFile) {
1718
+ throw new Error("Trajectory handoff could not create a persisted Pi session branch");
1719
+ }
1720
+ return fork;
1721
+ };
1722
+ var persistedBranch = (seed, cwd, directory) => {
1723
+ if (!seed.sourceSessionFile) {
1724
+ throw new Error("Persisted trajectory handoff is missing its source session file");
1725
+ }
1726
+ const source = SessionManager.open(seed.sourceSessionFile, directory, cwd);
1727
+ if (!source.getEntry(seed.sourceBranchLeafId)) {
1728
+ throw new Error(
1729
+ `Trajectory handoff branch point ${seed.sourceBranchLeafId} is missing from the persisted Pi session`
1730
+ );
1731
+ }
1732
+ return structuredClone(source.getBranch(seed.sourceBranchLeafId));
1733
+ };
1734
+ var synchronizeSourceSettings = (session, seed) => {
1735
+ const context = session.buildSessionContext();
1736
+ if (seed.sourceModel && (context.model?.provider !== seed.sourceModel.provider || context.model.modelId !== seed.sourceModel.modelId)) {
1737
+ session.appendModelChange(seed.sourceModel.provider, seed.sourceModel.modelId);
1738
+ }
1739
+ if (seed.sourceThinkingLevel && context.thinkingLevel !== seed.sourceThinkingLevel) {
1740
+ session.appendThinkingLevelChange(seed.sourceThinkingLevel);
1741
+ }
1742
+ };
1743
+ var writeHandoffSession = (seed, cwd, directory, transfer, compaction) => {
1744
+ fs8.mkdirSync(directory, { recursive: true, mode: 448 });
1745
+ const policy = transfer ? thinkingTransferPolicy(transfer) : "preserved";
1746
+ let session;
1747
+ let report;
1748
+ let digest;
1749
+ if (!transfer || policy === "preserved") {
1750
+ session = forkBranch(seed, cwd, directory);
1751
+ } else {
1752
+ const rawBranch = seed.sourceSessionFile ? persistedBranch(seed, cwd, directory) : structuredClone(seed.sourceBranch ?? (() => {
1753
+ throw new Error("Trajectory handoff transfer is missing its source branch");
1754
+ })());
1755
+ if (policy === "stripped") digest = buildThinkingDigest(rawBranch, transfer);
1756
+ const translated = translateThinkingForExecutor(rawBranch, policy);
1757
+ report = translated.report;
1758
+ session = materializeBranch({ ...seed, sourceBranch: translated.entries }, cwd, directory);
1759
+ }
1760
+ let compactionOutcome;
1761
+ if (compaction) {
1762
+ const branchEntries = session.getBranch();
1763
+ const customInstructions = compaction.preserve ? encodeCompactionRequest({
1764
+ ...compaction.instructions !== void 0 ? { instructions: compaction.instructions } : {},
1765
+ preserve: compaction.preserve
1766
+ }) : compaction.instructions;
1767
+ const tokensBefore = rawContextTokens(branchEntries);
1768
+ const compiled = compileFabricSummary(branchEntries, tokensBefore, void 0, customInstructions);
1769
+ if ("cancel" in compiled) {
1770
+ compactionOutcome = { applied: false, reason: compiled.reason };
1771
+ } else {
1772
+ session.appendCompaction(
1773
+ compiled.compaction.summary,
1774
+ compiled.compaction.firstKeptEntryId,
1775
+ tokensBefore,
1776
+ compiled.compaction.details,
1777
+ true
1778
+ );
1779
+ compactionOutcome = {
1780
+ applied: true,
1781
+ sections: compiled.compaction.details?.sections ?? [],
1782
+ tokensBefore,
1783
+ firstKeptEntryId: compiled.compaction.firstKeptEntryId
1784
+ };
1785
+ }
1786
+ }
1787
+ synchronizeSourceSettings(session, seed);
1788
+ session.appendMessage(seed.outerToolResult);
1789
+ if (digest) {
1790
+ session.appendCustomMessageEntry(THINKING_DIGEST_CUSTOM_TYPE, digest.content, false, {
1791
+ policy,
1792
+ citedBlocks: digest.citedBlocks
1793
+ });
1794
+ }
1795
+ session.appendCustomEntry("pi-fabric-handoff", {
1796
+ sourceSessionId: seed.sourceSessionId,
1797
+ boundary: "fabric_exec_end",
1798
+ ...compactionOutcome ? {
1799
+ compaction: compactionOutcome.applied ? {
1800
+ applied: true,
1801
+ sections: compactionOutcome.sections,
1802
+ tokensBefore: compactionOutcome.tokensBefore,
1803
+ firstKeptEntryId: compactionOutcome.firstKeptEntryId
1804
+ } : { applied: false, reason: compactionOutcome.reason }
1805
+ } : {},
1806
+ ...transfer && report ? {
1807
+ thinkingTransfer: {
1808
+ policy: report.policy,
1809
+ translated: report.translated,
1810
+ dropped: report.dropped,
1811
+ target: `${transfer.target.provider}/${transfer.target.modelId}`
1812
+ }
1813
+ } : {}
1814
+ });
1815
+ const sessionFile = session.getSessionFile();
1816
+ if (!sessionFile) throw new Error("Trajectory handoff did not produce a Pi session file");
1817
+ fs8.chmodSync(sessionFile, 384);
1818
+ return sessionFile;
1819
+ };
1820
+
1821
+ // src/storage/retention.ts
1822
+ import fs9 from "node:fs";
1823
+ import path10 from "node:path";
1484
1824
  var RUN_ROOT_OWNER_FILE = ".fabric-owner.json";
1485
1825
  var TERMINAL_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "stopped", "timed_out"]);
1486
- var ownerPath = (root) => path9.join(root, RUN_ROOT_OWNER_FILE);
1826
+ var ownerPath = (root) => path10.join(root, RUN_ROOT_OWNER_FILE);
1487
1827
  var readJson = (file) => {
1488
1828
  try {
1489
1829
  const stat = ownedStat(file);
1490
1830
  if (!stat?.isFile() || stat.size > 1024 * 1024) return;
1491
- return JSON.parse(fs8.readFileSync(file, "utf8"));
1831
+ return JSON.parse(fs9.readFileSync(file, "utf8"));
1492
1832
  } catch {
1493
1833
  return;
1494
1834
  }
@@ -1496,9 +1836,9 @@ var readJson = (file) => {
1496
1836
  var time = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
1497
1837
  var validOwner = (owner) => !!owner && Number.isSafeInteger(owner.pid) && owner.pid > 0 && time(owner.startedAt) && time(owner.heartbeatAt) && (owner.closedAt === void 0 || time(owner.closedAt)) && (owner.orphanedAt === void 0 || time(owner.orphanedAt)) && (owner.childrenStopped === void 0 || typeof owner.childrenStopped === "boolean");
1498
1838
  var writeOwner = (root, owner) => {
1499
- if (fs8.existsSync(root) && !ownedStat(root)?.isDirectory()) throw new Error("Unsafe Fabric run root");
1839
+ if (fs9.existsSync(root) && !ownedStat(root)?.isDirectory()) throw new Error("Unsafe Fabric run root");
1500
1840
  const file = ownerPath(root);
1501
- if (fs8.existsSync(file)) {
1841
+ if (fs9.existsSync(file)) {
1502
1842
  const existing = readJson(file);
1503
1843
  if (!validOwner(existing) || existing.pid !== owner.pid) throw new Error("Unsafe Fabric run owner marker");
1504
1844
  }
@@ -1517,25 +1857,25 @@ var recordAgeReference = (record, fallback) => time(record.finishedAt) ? record.
1517
1857
  var runFiles = /* @__PURE__ */ new Set(["task.txt", "status.json", "events.jsonl", "lifecycle.jsonl", "steer.jsonl", "schema.json", "images.json"]);
1518
1858
  var safeRunTree = (root, childrenStopped, depth = 0) => {
1519
1859
  if (depth > 32 || !ownedStat(root)?.isDirectory()) return false;
1520
- const record = readJson(path9.join(root, "status.json"));
1860
+ const record = readJson(path10.join(root, "status.json"));
1521
1861
  const pid = record?.transport === "process" && typeof record.sessionId === "string" && /^\d+$/.test(record.sessionId) ? Number(record.sessionId) : void 0;
1522
1862
  if (pid !== void 0 && processAlive(pid)) return false;
1523
1863
  if (!record?.status || !TERMINAL_STATUSES.has(record.status)) {
1524
1864
  if (!childrenStopped && pid === void 0) return false;
1525
- if (!ownedStat(path9.join(root, "task.txt"))?.isFile()) return false;
1865
+ if (!ownedStat(path10.join(root, "task.txt"))?.isFile()) return false;
1526
1866
  }
1527
1867
  try {
1528
- for (const name of fs8.readdirSync(root)) {
1529
- const file = path9.join(root, name);
1868
+ for (const name of fs9.readdirSync(root)) {
1869
+ const file = path10.join(root, name);
1530
1870
  const stat = ownedStat(file);
1531
1871
  if (!stat) return false;
1532
1872
  if (stat.isFile() && runFiles.has(name)) continue;
1533
1873
  if (stat.isDirectory() && name === "handoff-session") {
1534
- if (fs8.readdirSync(file).some((child) => !child.endsWith(".jsonl") || !ownedStat(path9.join(file, child))?.isFile())) return false;
1874
+ if (fs9.readdirSync(file).some((child) => !child.endsWith(".jsonl") || !ownedStat(path10.join(file, child))?.isFile())) return false;
1535
1875
  continue;
1536
1876
  }
1537
1877
  if (stat.isDirectory() && name === "nested") {
1538
- for (const child of fs8.readdirSync(file)) if (!safeRunTree(path9.join(file, child), false, depth + 1)) return false;
1878
+ for (const child of fs9.readdirSync(file)) if (!safeRunTree(path10.join(file, child), false, depth + 1)) return false;
1539
1879
  continue;
1540
1880
  }
1541
1881
  return false;
@@ -1547,7 +1887,7 @@ var safeRunTree = (root, childrenStopped, depth = 0) => {
1547
1887
  };
1548
1888
  var safeRootContents = (root, childrenStopped) => {
1549
1889
  try {
1550
- return fs8.readdirSync(root).every((name) => name === RUN_ROOT_OWNER_FILE || safeRunTree(path9.join(root, name), childrenStopped));
1890
+ return fs9.readdirSync(root).every((name) => name === RUN_ROOT_OWNER_FILE || safeRunTree(path10.join(root, name), childrenStopped));
1551
1891
  } catch {
1552
1892
  return false;
1553
1893
  }
@@ -1560,8 +1900,8 @@ var canRemoveManagedRunRoot = (root) => {
1560
1900
  var removeEmptyRunRoot = (root) => {
1561
1901
  try {
1562
1902
  if (!ownedStat(root)?.isDirectory() || !validOwner(readJson(ownerPath(root)))) return false;
1563
- if (fs8.readdirSync(root).some((name) => name !== RUN_ROOT_OWNER_FILE)) return false;
1564
- fs8.rmSync(root, { recursive: true, force: true });
1903
+ if (fs9.readdirSync(root).some((name) => name !== RUN_ROOT_OWNER_FILE)) return false;
1904
+ fs9.rmSync(root, { recursive: true, force: true });
1565
1905
  return true;
1566
1906
  } catch {
1567
1907
  return false;
@@ -1571,21 +1911,21 @@ var pruneClosedRunRoot = (root, owner, orphanMs, oneShotMs, now) => {
1571
1911
  const removed = [];
1572
1912
  let entries;
1573
1913
  try {
1574
- entries = fs8.readdirSync(root, { withFileTypes: true });
1914
+ entries = fs9.readdirSync(root, { withFileTypes: true });
1575
1915
  } catch {
1576
1916
  return removed;
1577
1917
  }
1578
1918
  for (const entry of entries) {
1579
1919
  if (!entry.isDirectory()) continue;
1580
- const directory = path9.join(root, entry.name);
1920
+ const directory = path10.join(root, entry.name);
1581
1921
  if (!safeRunTree(directory, owner.childrenStopped === true)) continue;
1582
- const record = readJson(path9.join(directory, "status.json"));
1922
+ const record = readJson(path10.join(directory, "status.json"));
1583
1923
  const terminal = !!record?.status && TERMINAL_STATUSES.has(record.status);
1584
1924
  const reference = terminal ? recordAgeReference(record, ownedStat(directory)?.mtimeMs ?? now) : owner.closedAt;
1585
1925
  const retention = terminal && !record?.actorId ? oneShotMs : orphanMs;
1586
1926
  if (now - reference < retention) continue;
1587
1927
  try {
1588
- fs8.rmSync(directory, { recursive: true, force: true });
1928
+ fs9.rmSync(directory, { recursive: true, force: true });
1589
1929
  removed.push(directory);
1590
1930
  } catch {
1591
1931
  }
@@ -1597,14 +1937,14 @@ var sweepTempRunRoots = (options) => {
1597
1937
  const result = { removedRoots: [], removedRuns: [] };
1598
1938
  let entries;
1599
1939
  try {
1600
- entries = fs8.readdirSync(options.tempRoot, { withFileTypes: true });
1940
+ entries = fs9.readdirSync(options.tempRoot, { withFileTypes: true });
1601
1941
  } catch {
1602
1942
  return result;
1603
1943
  }
1604
1944
  for (const entry of entries) {
1605
1945
  if (!entry.isDirectory() || !/^pi-fabric-runs-[A-Za-z0-9_-]+$/.test(entry.name)) continue;
1606
- const root = path9.join(options.tempRoot, entry.name);
1607
- if (options.currentRoot && path9.resolve(root) === path9.resolve(options.currentRoot)) continue;
1946
+ const root = path10.join(options.tempRoot, entry.name);
1947
+ if (options.currentRoot && path10.resolve(root) === path10.resolve(options.currentRoot)) continue;
1608
1948
  if (!ownedStat(root)?.isDirectory()) continue;
1609
1949
  const owner = readJson(ownerPath(root));
1610
1950
  if (!validOwner(owner)) continue;
@@ -1623,7 +1963,7 @@ var sweepTempRunRoots = (options) => {
1623
1963
  }
1624
1964
  if (now - owner.orphanedAt < options.orphanedTempRunRetentionMs || !safeRootContents(root, false)) continue;
1625
1965
  try {
1626
- fs8.rmSync(root, { recursive: true, force: true });
1966
+ fs9.rmSync(root, { recursive: true, force: true });
1627
1967
  result.removedRoots.push(root);
1628
1968
  } catch {
1629
1969
  }
@@ -1636,18 +1976,18 @@ var pruneActorRunArchives = (options) => {
1636
1976
  if (!ownedStat(options.runsDirectory)?.isDirectory()) return removed;
1637
1977
  let entries;
1638
1978
  try {
1639
- entries = fs8.readdirSync(options.runsDirectory, { withFileTypes: true });
1979
+ entries = fs9.readdirSync(options.runsDirectory, { withFileTypes: true });
1640
1980
  } catch {
1641
1981
  return removed;
1642
1982
  }
1643
1983
  for (const entry of entries) {
1644
1984
  if (!entry.isDirectory() || entry.name === options.latestRunId) continue;
1645
- const directory = path9.join(options.runsDirectory, entry.name);
1646
- const record = readJson(path9.join(directory, "status.json"));
1985
+ const directory = path10.join(options.runsDirectory, entry.name);
1986
+ const record = readJson(path10.join(directory, "status.json"));
1647
1987
  if (!record?.status || !TERMINAL_STATUSES.has(record.status) || !safeRunTree(directory, false)) continue;
1648
1988
  if (now - recordAgeReference(record, ownedStat(directory)?.mtimeMs ?? now) < options.retentionMs) continue;
1649
1989
  try {
1650
- fs8.rmSync(directory, { recursive: true, force: true });
1990
+ fs9.rmSync(directory, { recursive: true, force: true });
1651
1991
  removed.push(directory);
1652
1992
  } catch {
1653
1993
  }
@@ -1657,21 +1997,21 @@ var pruneActorRunArchives = (options) => {
1657
1997
 
1658
1998
  // src/agents/session-export.ts
1659
1999
  import os2 from "node:os";
1660
- import path10 from "node:path";
2000
+ import path11 from "node:path";
1661
2001
  var SESSION_EXPORT_ENV = "PI_FABRIC_AGENT_DIR";
1662
- var expandHome = (value) => value === "~" ? os2.homedir() : value.startsWith("~/") || value.startsWith(`~${path10.win32.sep}`) ? path10.join(os2.homedir(), value.slice(2)) : value;
2002
+ var expandHome = (value) => value === "~" ? os2.homedir() : value.startsWith("~/") || value.startsWith(`~${path11.win32.sep}`) ? path11.join(os2.homedir(), value.slice(2)) : value;
1663
2003
  var encodeSessionExportCwd = (cwd) => {
1664
- const absolute = path10.isAbsolute(cwd) || path10.win32.isAbsolute(cwd) ? cwd : path10.resolve(cwd);
2004
+ const absolute = path11.isAbsolute(cwd) || path11.win32.isAbsolute(cwd) ? cwd : path11.resolve(cwd);
1665
2005
  return `--${absolute.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
1666
2006
  };
1667
2007
  var resolveSessionExportDir = (config) => {
1668
2008
  if (!config.sessionExport) return void 0;
1669
- const raw = process.env[SESSION_EXPORT_ENV]?.trim() || config.sessionExportDir.trim() || path10.join(os2.homedir(), ".pi", "agent");
2009
+ const raw = process.env[SESSION_EXPORT_ENV]?.trim() || config.sessionExportDir.trim() || path11.join(os2.homedir(), ".pi", "agent");
1670
2010
  return expandHome(raw);
1671
2011
  };
1672
2012
  var sessionExportFileFor = (root, cwd, runId, at) => {
1673
2013
  const fileTimestamp = at.toISOString().replace(/[:.]/g, "-");
1674
- return path10.join(
2014
+ return path11.join(
1675
2015
  root,
1676
2016
  "sessions",
1677
2017
  ".fabric",
@@ -1711,11 +2051,11 @@ var resolveAgentCwd = (parentCwd, requestedCwd) => {
1711
2051
  if (typeof requested !== "string" || requested.trim().length === 0) {
1712
2052
  throw new Error(`Invalid Fabric agent cwd ${JSON.stringify(requested)}: path must not be empty`);
1713
2053
  }
1714
- const candidate = path11.isAbsolute(requested) ? requested : path11.resolve(parentCwd, requested);
2054
+ const candidate = path12.isAbsolute(requested) ? requested : path12.resolve(parentCwd, requested);
1715
2055
  try {
1716
- const canonical = fs9.realpathSync(candidate);
1717
- fs9.accessSync(canonical, fs9.constants.R_OK | fs9.constants.X_OK);
1718
- if (!fs9.statSync(canonical).isDirectory()) {
2056
+ const canonical = fs10.realpathSync(candidate);
2057
+ fs10.accessSync(canonical, fs10.constants.R_OK | fs10.constants.X_OK);
2058
+ if (!fs10.statSync(canonical).isDirectory()) {
1719
2059
  throw new Error("path is not a directory");
1720
2060
  }
1721
2061
  return canonical;
@@ -1755,7 +2095,7 @@ var retryablePiStartupError = (error) => typeof error === "string" && /\b(?:no|m
1755
2095
  var safeName = (value) => value.replace(/[\r\n\t]+/g, " ").trim().slice(0, MAX_NAME_LENGTH) || "Fabric agent";
1756
2096
  var readRecord = (filePath) => {
1757
2097
  try {
1758
- const parsed = JSON.parse(fs9.readFileSync(filePath, "utf8"));
2098
+ const parsed = JSON.parse(fs10.readFileSync(filePath, "utf8"));
1759
2099
  if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return void 0;
1760
2100
  const record = parsed;
1761
2101
  return {
@@ -1795,24 +2135,24 @@ var compactUiRecord = (record) => {
1795
2135
  };
1796
2136
  var readNestedAgents = (runDirectory, depth = 0) => {
1797
2137
  if (depth >= 8) return [];
1798
- const nestedRoot = path11.join(runDirectory, "nested");
2138
+ const nestedRoot = path12.join(runDirectory, "nested");
1799
2139
  let entries;
1800
2140
  try {
1801
- entries = fs9.readdirSync(nestedRoot);
2141
+ entries = fs10.readdirSync(nestedRoot);
1802
2142
  } catch {
1803
2143
  return [];
1804
2144
  }
1805
2145
  const agents = [];
1806
2146
  for (const entry of entries.slice(0, 200)) {
1807
- const runDirectory2 = path11.join(nestedRoot, entry);
1808
- const record = readRecord(path11.join(runDirectory2, "status.json"));
2147
+ const runDirectory2 = path12.join(nestedRoot, entry);
2148
+ const record = readRecord(path12.join(runDirectory2, "status.json"));
1809
2149
  if (!record) continue;
1810
2150
  const nestedAgents = readNestedAgents(runDirectory2, depth + 1);
1811
2151
  const { logFile: _logFile, nestedAgents: _nestedAgents, ...safeRecord } = record;
1812
2152
  agents.push(
1813
2153
  compactUiRecord({
1814
2154
  ...safeRecord,
1815
- logFile: path11.join(runDirectory2, "events.jsonl"),
2155
+ logFile: path12.join(runDirectory2, "events.jsonl"),
1816
2156
  ...nestedAgents.length > 0 ? { nestedAgents } : {}
1817
2157
  })
1818
2158
  );
@@ -1820,7 +2160,7 @@ var readNestedAgents = (runDirectory, depth = 0) => {
1820
2160
  return agents;
1821
2161
  };
1822
2162
  var summarizeRunLog = (runDirectory, lines) => {
1823
- const page = readJsonlPage(path11.join(runDirectory, "events.jsonl"), lines);
2163
+ const page = readJsonlPage(path12.join(runDirectory, "events.jsonl"), lines);
1824
2164
  const summary = [];
1825
2165
  for (const entry of page.lines) {
1826
2166
  const parsed = entry.parsed;
@@ -1872,7 +2212,7 @@ var AgentManager = class {
1872
2212
  this.config = config;
1873
2213
  this.#semaphore = new AgentAdmission(config.maxConcurrent, Infinity, config.maxDepth);
1874
2214
  this.#managedTempRoot = options.runRoot === void 0 && process.env.PI_FABRIC_RUN_ROOT === void 0;
1875
- this.#runRoot = options.runRoot ?? process.env.PI_FABRIC_RUN_ROOT ?? fs9.mkdtempSync(path11.join(os3.tmpdir(), "pi-fabric-runs-"));
2215
+ this.#runRoot = options.runRoot ?? process.env.PI_FABRIC_RUN_ROOT ?? fs10.mkdtempSync(path12.join(os3.tmpdir(), "pi-fabric-runs-"));
1876
2216
  this.#retention = options.retention ?? DEFAULT_FABRIC_CONFIG.retention;
1877
2217
  this.#workerPath = options.workerPath ?? fileURLToPath(new URL("../worker.js", import.meta.url));
1878
2218
  this.#fabricExtensionPath = options.fabricExtensionPath ?? fileURLToPath(new URL("../index.js", import.meta.url));
@@ -1880,6 +2220,7 @@ var AgentManager = class {
1880
2220
  this.#claudeBinary = options.claudeBinary ?? process.env.PI_FABRIC_CLAUDE_BINARY ?? config.claude.binary;
1881
2221
  this.#vedaBinary = options.vedaBinary ?? process.env.PI_FABRIC_VEDA_BINARY ?? config.veda.binary;
1882
2222
  this.#onBackgroundComplete = options.onBackgroundComplete;
2223
+ this.#onResultConsumed = options.onResultConsumed;
1883
2224
  this.#onLifecycle = options.onLifecycle;
1884
2225
  this.#preparePiModel = options.preparePiModel;
1885
2226
  this.#resolveParticipantGuidance = options.resolveParticipantGuidance;
@@ -1932,6 +2273,7 @@ var AgentManager = class {
1932
2273
  #identityId;
1933
2274
  #transports;
1934
2275
  #onBackgroundComplete;
2276
+ #onResultConsumed;
1935
2277
  #onLifecycle;
1936
2278
  #preparePiModel;
1937
2279
  #resolveParticipantGuidance;
@@ -2101,31 +2443,31 @@ var AgentManager = class {
2101
2443
  release();
2102
2444
  throw error;
2103
2445
  }
2104
- const id = randomUUID4().replaceAll("-", "");
2446
+ const id = randomUUID5().replaceAll("-", "");
2105
2447
  const name = safeName(request.name ?? request.task.split("\n", 1)[0] ?? "Fabric agent");
2106
- const runDirectory = path11.join(this.#runRoot, id);
2107
- fs9.mkdirSync(runDirectory, { recursive: true });
2448
+ const runDirectory = path12.join(this.#runRoot, id);
2449
+ fs10.mkdirSync(runDirectory, { recursive: true });
2108
2450
  if (this.#managedTempRoot && !this.#retentionTimer) {
2109
2451
  this.#retentionTimer = setInterval(() => this.#scheduleRetentionSweep(), RETENTION_SWEEP_INTERVAL_MS);
2110
2452
  this.#retentionTimer.unref();
2111
2453
  this.#scheduleRetentionSweep();
2112
2454
  }
2113
- const taskFile = path11.join(runDirectory, "task.txt");
2114
- const statusFile = path11.join(runDirectory, "status.json");
2115
- const lifecycleFile = path11.join(runDirectory, "lifecycle.jsonl");
2116
- const logFile = path11.join(runDirectory, "events.jsonl");
2117
- const steerFile = path11.join(runDirectory, "steer.jsonl");
2118
- const schemaFile = request.schema ? path11.join(runDirectory, "schema.json") : void 0;
2119
- const imagesFile = request.images && request.images.length > 0 ? path11.join(runDirectory, "images.json") : void 0;
2120
- fs9.writeFileSync(taskFile, request.task, { encoding: "utf8", mode: 384 });
2455
+ const taskFile = path12.join(runDirectory, "task.txt");
2456
+ const statusFile = path12.join(runDirectory, "status.json");
2457
+ const lifecycleFile = path12.join(runDirectory, "lifecycle.jsonl");
2458
+ const logFile = path12.join(runDirectory, "events.jsonl");
2459
+ const steerFile = path12.join(runDirectory, "steer.jsonl");
2460
+ const schemaFile = request.schema ? path12.join(runDirectory, "schema.json") : void 0;
2461
+ const imagesFile = request.images && request.images.length > 0 ? path12.join(runDirectory, "images.json") : void 0;
2462
+ fs10.writeFileSync(taskFile, request.task, { encoding: "utf8", mode: 384 });
2121
2463
  if (imagesFile) {
2122
- fs9.writeFileSync(imagesFile, JSON.stringify(request.images), {
2464
+ fs10.writeFileSync(imagesFile, JSON.stringify(request.images), {
2123
2465
  encoding: "utf8",
2124
2466
  mode: 384
2125
2467
  });
2126
2468
  }
2127
2469
  if (schemaFile) {
2128
- fs9.writeFileSync(schemaFile, JSON.stringify(request.schema, null, 2), {
2470
+ fs10.writeFileSync(schemaFile, JSON.stringify(request.schema, null, 2), {
2129
2471
  encoding: "utf8",
2130
2472
  mode: 384
2131
2473
  });
@@ -2148,7 +2490,7 @@ var AgentManager = class {
2148
2490
  const sessionFile = request.sessionSeed ? writeHandoffSession(
2149
2491
  request.sessionSeed,
2150
2492
  agentCwd,
2151
- path11.join(runDirectory, "handoff-session"),
2493
+ path12.join(runDirectory, "handoff-session"),
2152
2494
  request.thinkingTransfer,
2153
2495
  request.handoffCompact
2154
2496
  ) : request.sessionFile;
@@ -2231,7 +2573,7 @@ var AgentManager = class {
2231
2573
  ...this.#identityId ? ["--owner-identity-id", this.#identityId] : [],
2232
2574
  ...request.runnerSessionId ? ["--runner-session-id", request.runnerSessionId] : [],
2233
2575
  "--run-root",
2234
- path11.join(runDirectory, "nested"),
2576
+ path12.join(runDirectory, "nested"),
2235
2577
  "--steer-file",
2236
2578
  steerFile,
2237
2579
  ...schemaFile ? ["--schema-file", schemaFile] : [],
@@ -2319,16 +2661,20 @@ var AgentManager = class {
2319
2661
  managed.background = false;
2320
2662
  if (!managed.settled) {
2321
2663
  if (!managed.result) throw new Error(`Agent ${id} has no pending result`);
2322
- return managed.result;
2664
+ const result = await managed.result;
2665
+ this.#onResultConsumed?.(id);
2666
+ return result;
2323
2667
  }
2324
2668
  const record = readRecord(managed.statusFile) ?? managed.latestRecord;
2325
2669
  if (!record || !terminalStatuses.has(record.status)) {
2326
2670
  throw new Error(`Agent ${id} settled without a result`);
2327
2671
  }
2672
+ this.#onResultConsumed?.(id);
2328
2673
  return this.#withTransportMetadata(record, managed);
2329
2674
  }
2330
2675
  markForeground(id) {
2331
2676
  this.#requireRun(id).background = false;
2677
+ this.#onResultConsumed?.(id);
2332
2678
  }
2333
2679
  detachSignal(id) {
2334
2680
  this.#detach(this.#requireRun(id), "caller detached; the run continues");
@@ -2358,6 +2704,12 @@ var AgentManager = class {
2358
2704
  managed.abortHandler = void 0;
2359
2705
  if (managed.background) return;
2360
2706
  managed.background = true;
2707
+ if (managed.settled) {
2708
+ const record = readRecord(managed.statusFile) ?? managed.latestRecord;
2709
+ if (record && terminalStatuses.has(record.status)) {
2710
+ this.#notifyBackgroundComplete(managed, this.#withTransportMetadata(record, managed));
2711
+ }
2712
+ }
2361
2713
  if (attached) {
2362
2714
  this.#emitLifecycle(managed, "run.detached", Date.now(), { data: { reason } });
2363
2715
  }
@@ -2460,6 +2812,7 @@ var AgentManager = class {
2460
2812
  async cleanup(id, deleteBranch = false) {
2461
2813
  const managed = this.#requireRun(id);
2462
2814
  if (!managed.settled) throw new Error("Cannot clean up a running agent");
2815
+ this.markForeground(id);
2463
2816
  const cleaned = await this.#worktrees.cleanup(id, deleteBranch);
2464
2817
  if (!this.config.retainRuns) {
2465
2818
  await removeTree(managed.runDirectory);
@@ -2467,15 +2820,15 @@ var AgentManager = class {
2467
2820
  this.#runs.delete(id);
2468
2821
  this.#pruneRetainedUiRecords();
2469
2822
  this.#invalidateUiList();
2470
- return { cleaned: cleaned || !fs9.existsSync(managed.runDirectory) };
2823
+ return { cleaned: cleaned || !fs10.existsSync(managed.runDirectory) };
2471
2824
  }
2472
2825
  readLog(id, opts = {}) {
2473
2826
  const managed = this.#requireRun(id);
2474
2827
  const runDirectory = managed.runDirectory;
2475
- const logFile = path11.join(runDirectory, "events.jsonl");
2828
+ const logFile = path12.join(runDirectory, "events.jsonl");
2476
2829
  const lines = Math.max(1, Math.min(opts.lines ?? 200, 5e3));
2477
2830
  const page = readJsonlPage(logFile, lines, opts.before);
2478
- const statusRecord = readRecord(path11.join(runDirectory, "status.json"));
2831
+ const statusRecord = readRecord(path12.join(runDirectory, "status.json"));
2479
2832
  return {
2480
2833
  id,
2481
2834
  runDirectory,
@@ -2536,10 +2889,10 @@ var AgentManager = class {
2536
2889
  `Fabric agent ${id} already finished (${record.status}); steering has no target`
2537
2890
  );
2538
2891
  }
2539
- const steerFile = path11.join(managed.runDirectory, "steer.jsonl");
2540
- const messageId = randomUUID4();
2892
+ const steerFile = path12.join(managed.runDirectory, "steer.jsonl");
2893
+ const messageId = randomUUID5();
2541
2894
  const line = JSON.stringify({ ...entry, id: messageId, ts: Date.now() }) + "\n";
2542
- fs9.appendFileSync(steerFile, line, { encoding: "utf8", mode: 384 });
2895
+ fs10.appendFileSync(steerFile, line, { encoding: "utf8", mode: 384 });
2543
2896
  return { queued: true, messageId };
2544
2897
  }
2545
2898
  close() {
@@ -2575,7 +2928,7 @@ var AgentManager = class {
2575
2928
  removeEmptyRunRoot(this.#runRoot);
2576
2929
  }
2577
2930
  if (storageSafe && this.#budgetOwned && this.#budget) {
2578
- await removeTree(path11.dirname(this.#budget.file)).catch(() => void 0);
2931
+ await removeTree(path12.dirname(this.#budget.file)).catch(() => void 0);
2579
2932
  }
2580
2933
  }
2581
2934
  if (this.#budgetOwned) clearOwnedBudgetEnv();
@@ -2617,7 +2970,7 @@ var AgentManager = class {
2617
2970
  });
2618
2971
  for (const managed of expired) {
2619
2972
  await removeTree(managed.runDirectory).catch(() => void 0);
2620
- if (!fs9.existsSync(managed.runDirectory)) this.#runs.delete(managed.id);
2973
+ if (!fs10.existsSync(managed.runDirectory)) this.#runs.delete(managed.id);
2621
2974
  }
2622
2975
  if (expired.length > 0) {
2623
2976
  this.#pruneRetainedUiRecords();
@@ -2688,7 +3041,7 @@ var AgentManager = class {
2688
3041
  }
2689
3042
  }
2690
3043
  if (resume) {
2691
- fs9.writeFileSync(path11.join(managed.runDirectory, "task.txt"), resume.task, {
3044
+ fs10.writeFileSync(path12.join(managed.runDirectory, "task.txt"), resume.task, {
2692
3045
  encoding: "utf8",
2693
3046
  mode: 384
2694
3047
  });
@@ -2699,7 +3052,7 @@ var AgentManager = class {
2699
3052
  );
2700
3053
  }
2701
3054
  this.#drainLifecycle(managed);
2702
- fs9.rmSync(managed.statusFile, { force: true });
3055
+ fs10.rmSync(managed.statusFile, { force: true });
2703
3056
  if (managed.settled || this.#closing || managed.stopRequested) return false;
2704
3057
  managed.transport = await this.#launchTransport(managed.adapter, managed.launch);
2705
3058
  this.#unregisteredTransports.delete(managed.transport);
@@ -2712,7 +3065,7 @@ var AgentManager = class {
2712
3065
  managed.lastLivenessCheckAt = 0;
2713
3066
  managed.lifecycleOffset = 0;
2714
3067
  managed.lifecycleRemainder = Buffer.alloc(0);
2715
- fs9.rmSync(managed.lifecycleFile, { force: true });
3068
+ fs10.rmSync(managed.lifecycleFile, { force: true });
2716
3069
  if (resume) {
2717
3070
  this.#emitLifecycle(managed, "run.resumed", Date.now(), {
2718
3071
  data: {
@@ -2830,7 +3183,7 @@ var AgentManager = class {
2830
3183
  if (managed.settled) return;
2831
3184
  this.#drainLifecycle(managed);
2832
3185
  if (!beginAgentSettlement(managed)) return;
2833
- fs9.rmSync(path11.join(managed.runDirectory, "images.json"), { force: true });
3186
+ fs10.rmSync(path12.join(managed.runDirectory, "images.json"), { force: true });
2834
3187
  this.#emitLifecycle(managed, `run.${result.status}`, result.finishedAt ?? Date.now(), {
2835
3188
  status: result.status
2836
3189
  });
@@ -2851,7 +3204,11 @@ var AgentManager = class {
2851
3204
  this.#invalidateUiList();
2852
3205
  finishAgentSettlement(managed, result);
2853
3206
  managed.task = "";
2854
- if (managed.background && !this.#closing && this.config.notifyOnComplete && this.#onBackgroundComplete) {
3207
+ this.#notifyBackgroundComplete(managed, result);
3208
+ }
3209
+ #notifyBackgroundComplete(managed, result) {
3210
+ if (managed.background && !managed.completionNotified && !this.#closing && this.config.notifyOnComplete && this.#onBackgroundComplete) {
3211
+ managed.completionNotified = true;
2855
3212
  try {
2856
3213
  this.#onBackgroundComplete(result);
2857
3214
  } catch {
@@ -2861,7 +3218,7 @@ var AgentManager = class {
2861
3218
  #drainLifecycle(managed) {
2862
3219
  let content;
2863
3220
  try {
2864
- content = fs9.readFileSync(managed.lifecycleFile);
3221
+ content = fs10.readFileSync(managed.lifecycleFile);
2865
3222
  } catch {
2866
3223
  return;
2867
3224
  }
@@ -3059,7 +3416,7 @@ var AgentManager = class {
3059
3416
  // in the parent run until that parent is explicitly cleaned up.
3060
3417
  #nestedAgents(managed, force = false) {
3061
3418
  const now = Date.now();
3062
- const needsInitialDiscovery = managed.nestedSnapshot === void 0 && fs9.existsSync(path11.join(managed.runDirectory, "nested"));
3419
+ const needsInitialDiscovery = managed.nestedSnapshot === void 0 && fs10.existsSync(path12.join(managed.runDirectory, "nested"));
3063
3420
  if (!force && !needsInitialDiscovery && managed.nestedSnapshotAt !== void 0 && now - managed.nestedSnapshotAt < NESTED_SNAPSHOT_POLL_MS) {
3064
3421
  return managed.nestedSnapshot ? structuredClone(managed.nestedSnapshot) : [];
3065
3422
  }
@@ -3086,7 +3443,7 @@ var AgentManager = class {
3086
3443
  runner: managed.runner,
3087
3444
  ...managed.kernel ? { kernel: managed.kernel } : {},
3088
3445
  ...managed.residency === "durable" ? { residency: "durable" } : {},
3089
- logFile: path11.join(managed.runDirectory, "events.jsonl"),
3446
+ logFile: path12.join(managed.runDirectory, "events.jsonl"),
3090
3447
  ...nestedAgents.length > 0 ? { nestedAgents } : {},
3091
3448
  ...budget ? { budget } : {},
3092
3449
  ...model ? { model } : {},
@@ -3139,15 +3496,15 @@ var actorDeliveryNotice = (delivery, triggerTurn) => {
3139
3496
  };
3140
3497
 
3141
3498
  // src/actors/directory.ts
3142
- import fs15 from "node:fs";
3499
+ import fs16 from "node:fs";
3143
3500
 
3144
3501
  // src/actors/manager.ts
3145
- import { randomUUID as randomUUID7 } from "node:crypto";
3146
- import fs14 from "node:fs";
3502
+ import { randomUUID as randomUUID8 } from "node:crypto";
3503
+ import fs15 from "node:fs";
3147
3504
 
3148
3505
  // src/actors/mesh-monitor.ts
3149
- import fs10 from "node:fs";
3150
- import path12 from "node:path";
3506
+ import fs11 from "node:fs";
3507
+ import path13 from "node:path";
3151
3508
  var MESH_WATCH_RECONCILE_MS = 2e3;
3152
3509
  var ActorMeshMonitor = class {
3153
3510
  constructor(mesh, config, callbacks) {
@@ -3172,8 +3529,8 @@ var ActorMeshMonitor = class {
3172
3529
  return;
3173
3530
  }
3174
3531
  try {
3175
- const watcher = fs10.watch(this.mesh.root, { persistent: false }, (_event, filename) => {
3176
- if (filename !== null && path12.basename(filename.toString()) !== "events.jsonl") return;
3532
+ const watcher = fs11.watch(this.mesh.root, { persistent: false }, (_event, filename) => {
3533
+ if (filename !== null && path13.basename(filename.toString()) !== "events.jsonl") return;
3177
3534
  this.schedule();
3178
3535
  });
3179
3536
  this.#watcher = watcher;
@@ -3228,7 +3585,7 @@ var ActorMeshMonitor = class {
3228
3585
  #readCursor() {
3229
3586
  if (!this.callbacks.cursorPath) return void 0;
3230
3587
  try {
3231
- const value = JSON.parse(fs10.readFileSync(this.callbacks.cursorPath, "utf8"));
3588
+ const value = JSON.parse(fs11.readFileSync(this.callbacks.cursorPath, "utf8"));
3232
3589
  return value.format === 1 && typeof value.cursor === "number" && value.cursor >= 0 ? value.cursor : void 0;
3233
3590
  } catch {
3234
3591
  return void 0;
@@ -3245,11 +3602,11 @@ var ActorMeshMonitor = class {
3245
3602
 
3246
3603
  // src/actors/manager.ts
3247
3604
  import os4 from "node:os";
3248
- import path16 from "node:path";
3605
+ import path17 from "node:path";
3249
3606
 
3250
3607
  // src/actors/log-store.ts
3251
- import fs11 from "node:fs";
3252
- import path13 from "node:path";
3608
+ import fs12 from "node:fs";
3609
+ import path14 from "node:path";
3253
3610
  var ACTOR_MESSAGE_HISTORY_LIMIT = 100;
3254
3611
  var ACTOR_MESSAGE_ENVELOPE_BYTES = 4096;
3255
3612
  var ACTOR_TRUNCATION_SUFFIX = "\n[actor message truncated]";
@@ -3307,17 +3664,17 @@ var ActorLogStore = class {
3307
3664
  this.retention = retention;
3308
3665
  }
3309
3666
  async retainRun(actor, runId, runDirectory) {
3310
- if (!runDirectory || !fs11.existsSync(runDirectory)) return;
3311
- const dest = path13.join(path13.dirname(actor.sessionFile), "runs", runId);
3312
- fs11.mkdirSync(dest, { recursive: true, mode: 448 });
3667
+ if (!runDirectory || !fs12.existsSync(runDirectory)) return;
3668
+ const dest = path14.join(path14.dirname(actor.sessionFile), "runs", runId);
3669
+ fs12.mkdirSync(dest, { recursive: true, mode: 448 });
3313
3670
  for (const file of ["events.jsonl", "status.json", "task.txt"]) {
3314
- const src = path13.join(runDirectory, file);
3315
- if (fs11.existsSync(src)) fs11.copyFileSync(src, path13.join(dest, file));
3671
+ const src = path14.join(runDirectory, file);
3672
+ if (fs12.existsSync(src)) fs12.copyFileSync(src, path14.join(dest, file));
3316
3673
  }
3317
- const nested = path13.join(runDirectory, "nested");
3318
- if (fs11.existsSync(nested)) {
3674
+ const nested = path14.join(runDirectory, "nested");
3675
+ if (fs12.existsSync(nested)) {
3319
3676
  try {
3320
- fs11.cpSync(nested, path13.join(dest, "nested"), { recursive: true });
3677
+ fs12.cpSync(nested, path14.join(dest, "nested"), { recursive: true });
3321
3678
  } catch {
3322
3679
  }
3323
3680
  }
@@ -3325,16 +3682,16 @@ var ActorLogStore = class {
3325
3682
  }
3326
3683
  pruneRuns(actor, now = Date.now()) {
3327
3684
  pruneActorRunArchives({
3328
- runsDirectory: path13.join(path13.dirname(actor.sessionFile), "runs"),
3685
+ runsDirectory: path14.join(path14.dirname(actor.sessionFile), "runs"),
3329
3686
  ...actor.lastRunId ? { latestRunId: actor.lastRunId } : {},
3330
3687
  retentionMs: this.retention.actorRunArchiveMs,
3331
3688
  now
3332
3689
  });
3333
3690
  }
3334
3691
  retainedRunIds(actor) {
3335
- const runsDir = path13.join(path13.dirname(actor.sessionFile), "runs");
3692
+ const runsDir = path14.join(path14.dirname(actor.sessionFile), "runs");
3336
3693
  try {
3337
- return fs11.readdirSync(runsDir).sort();
3694
+ return fs12.readdirSync(runsDir).sort();
3338
3695
  } catch {
3339
3696
  return [];
3340
3697
  }
@@ -3455,9 +3812,9 @@ var evaluateActorValidWhile = async (source, facts) => {
3455
3812
  };
3456
3813
 
3457
3814
  // src/actors/binding-store.ts
3458
- import { createHash, randomUUID as randomUUID5 } from "node:crypto";
3459
- import fs12 from "node:fs";
3460
- import path14 from "node:path";
3815
+ import { createHash, randomUUID as randomUUID6 } from "node:crypto";
3816
+ import fs13 from "node:fs";
3817
+ import path15 from "node:path";
3461
3818
  var BINDING_LOCK_TIMEOUT_MS = 5e3;
3462
3819
  var BINDING_STALE_LOCK_MS = 3e4;
3463
3820
  var bindingFileName = (sessionId) => `${createHash("sha256").update(sessionId).digest("hex")}.json`;
@@ -3467,7 +3824,7 @@ var delay3 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
3467
3824
  var ActorBindingStore = class {
3468
3825
  constructor(sessionId, root) {
3469
3826
  this.sessionId = sessionId;
3470
- this.filePath = root ? path14.join(root, "bindings", bindingFileName(sessionId)) : void 0;
3827
+ this.filePath = root ? path15.join(root, "bindings", bindingFileName(sessionId)) : void 0;
3471
3828
  this.#sync(true);
3472
3829
  }
3473
3830
  #bindings = /* @__PURE__ */ new Map();
@@ -3533,7 +3890,7 @@ var ActorBindingStore = class {
3533
3890
  if (!this.filePath) return bindings;
3534
3891
  let parsed;
3535
3892
  try {
3536
- parsed = JSON.parse(fs12.readFileSync(this.filePath, "utf8"));
3893
+ parsed = JSON.parse(fs13.readFileSync(this.filePath, "utf8"));
3537
3894
  } catch {
3538
3895
  return bindings;
3539
3896
  }
@@ -3574,7 +3931,7 @@ var ActorBindingStore = class {
3574
3931
  #currentFingerprint() {
3575
3932
  if (!this.filePath) return void 0;
3576
3933
  try {
3577
- const stat = fs12.statSync(this.filePath);
3934
+ const stat = fs13.statSync(this.filePath);
3578
3935
  return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeMs}`;
3579
3936
  } catch {
3580
3937
  return void 0;
@@ -3583,9 +3940,9 @@ var ActorBindingStore = class {
3583
3940
  async #withLock(operation) {
3584
3941
  if (!this.filePath) return operation();
3585
3942
  const lockPath = `${this.filePath}.lock`;
3586
- const ownerPath2 = path14.join(lockPath, "owner");
3943
+ const ownerPath2 = path15.join(lockPath, "owner");
3587
3944
  const deadline = Date.now() + BINDING_LOCK_TIMEOUT_MS;
3588
- const token = randomUUID5();
3945
+ const token = randomUUID6();
3589
3946
  const processAlive3 = (pid) => {
3590
3947
  if (!Number.isSafeInteger(pid) || pid <= 0) return false;
3591
3948
  try {
@@ -3595,11 +3952,11 @@ var ActorBindingStore = class {
3595
3952
  return false;
3596
3953
  }
3597
3954
  };
3598
- fs12.mkdirSync(path14.dirname(this.filePath), { recursive: true, mode: 448 });
3955
+ fs13.mkdirSync(path15.dirname(this.filePath), { recursive: true, mode: 448 });
3599
3956
  while (true) {
3600
3957
  try {
3601
- fs12.mkdirSync(lockPath, { mode: 448 });
3602
- fs12.writeFileSync(ownerPath2, `${token}
3958
+ fs13.mkdirSync(lockPath, { mode: 448 });
3959
+ fs13.writeFileSync(ownerPath2, `${token}
3603
3960
  ${process.pid}
3604
3961
  ${Date.now()}
3605
3962
  `, {
@@ -3610,13 +3967,13 @@ ${Date.now()}
3610
3967
  } catch (error) {
3611
3968
  if (errorCode2(error) !== "EEXIST") throw error;
3612
3969
  try {
3613
- const firstOwner = fs12.readFileSync(ownerPath2, "utf8");
3970
+ const firstOwner = fs13.readFileSync(ownerPath2, "utf8");
3614
3971
  const [, pidText, createdText] = firstOwner.trim().split("\n");
3615
3972
  const stale = Date.now() - Number(createdText) > BINDING_STALE_LOCK_MS;
3616
3973
  if (stale && !processAlive3(Number(pidText))) {
3617
- const secondOwner = fs12.readFileSync(ownerPath2, "utf8");
3974
+ const secondOwner = fs13.readFileSync(ownerPath2, "utf8");
3618
3975
  if (secondOwner === firstOwner) {
3619
- fs12.rmSync(lockPath, { recursive: true, force: true });
3976
+ fs13.rmSync(lockPath, { recursive: true, force: true });
3620
3977
  continue;
3621
3978
  }
3622
3979
  }
@@ -3632,10 +3989,10 @@ ${Date.now()}
3632
3989
  return operation();
3633
3990
  } finally {
3634
3991
  try {
3635
- const owner = fs12.readFileSync(ownerPath2, "utf8");
3992
+ const owner = fs13.readFileSync(ownerPath2, "utf8");
3636
3993
  if (owner.startsWith(`${token}
3637
3994
  `)) {
3638
- fs12.rmSync(lockPath, { recursive: true, force: true });
3995
+ fs13.rmSync(lockPath, { recursive: true, force: true });
3639
3996
  }
3640
3997
  } catch {
3641
3998
  }
@@ -3644,9 +4001,9 @@ ${Date.now()}
3644
4001
  };
3645
4002
 
3646
4003
  // src/actors/registry-store.ts
3647
- import { randomUUID as randomUUID6 } from "node:crypto";
3648
- import fs13 from "node:fs";
3649
- import path15 from "node:path";
4004
+ import { randomUUID as randomUUID7 } from "node:crypto";
4005
+ import fs14 from "node:fs";
4006
+ import path16 from "node:path";
3650
4007
  var ACTOR_REGISTRY_LOCK_TIMEOUT_MS = 5e3;
3651
4008
  var ACTOR_REGISTRY_STALE_LOCK_MS = 3e4;
3652
4009
  var delay4 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -3656,11 +4013,11 @@ var ActorRegistryStore = class {
3656
4013
  #actorRoot;
3657
4014
  constructor(actorRoot) {
3658
4015
  this.#actorRoot = actorRoot;
3659
- this.#registryPath = path15.join(actorRoot, "actors.json");
4016
+ this.#registryPath = path16.join(actorRoot, "actors.json");
3660
4017
  }
3661
4018
  records() {
3662
4019
  try {
3663
- const parsed = JSON.parse(fs13.readFileSync(this.#registryPath, "utf8"));
4020
+ const parsed = JSON.parse(fs14.readFileSync(this.#registryPath, "utf8"));
3664
4021
  if (!Array.isArray(parsed.actors)) return [];
3665
4022
  return parsed.actors.flatMap(
3666
4023
  (record) => typeof record === "object" && record !== null && !Array.isArray(record) && typeof record.id === "string" ? [record] : []
@@ -3672,9 +4029,9 @@ var ActorRegistryStore = class {
3672
4029
  /** The callback must be synchronous: release precedes promise assimilation. */
3673
4030
  async withLock(operation) {
3674
4031
  const lockPath = `${this.#registryPath}.lock`;
3675
- const ownerPath2 = path15.join(lockPath, "owner");
4032
+ const ownerPath2 = path16.join(lockPath, "owner");
3676
4033
  const deadline = Date.now() + ACTOR_REGISTRY_LOCK_TIMEOUT_MS;
3677
- const token = randomUUID6();
4034
+ const token = randomUUID7();
3678
4035
  const processAlive3 = (pid) => {
3679
4036
  if (!Number.isSafeInteger(pid) || pid <= 0) return false;
3680
4037
  try {
@@ -3684,11 +4041,11 @@ var ActorRegistryStore = class {
3684
4041
  return false;
3685
4042
  }
3686
4043
  };
3687
- fs13.mkdirSync(this.#actorRoot, { recursive: true, mode: 448 });
4044
+ fs14.mkdirSync(this.#actorRoot, { recursive: true, mode: 448 });
3688
4045
  while (true) {
3689
4046
  try {
3690
- fs13.mkdirSync(lockPath, { mode: 448 });
3691
- fs13.writeFileSync(ownerPath2, `${token}
4047
+ fs14.mkdirSync(lockPath, { mode: 448 });
4048
+ fs14.writeFileSync(ownerPath2, `${token}
3692
4049
  ${process.pid}
3693
4050
  ${Date.now()}
3694
4051
  `, {
@@ -3699,13 +4056,13 @@ ${Date.now()}
3699
4056
  } catch (error) {
3700
4057
  if (errorCode3(error) !== "EEXIST") throw error;
3701
4058
  try {
3702
- const firstOwner = fs13.readFileSync(ownerPath2, "utf8");
4059
+ const firstOwner = fs14.readFileSync(ownerPath2, "utf8");
3703
4060
  const [, pidText, createdText] = firstOwner.trim().split("\n");
3704
4061
  const stale = Date.now() - Number(createdText) > ACTOR_REGISTRY_STALE_LOCK_MS;
3705
4062
  if (stale && !processAlive3(Number(pidText))) {
3706
- const secondOwner = fs13.readFileSync(ownerPath2, "utf8");
4063
+ const secondOwner = fs14.readFileSync(ownerPath2, "utf8");
3707
4064
  if (secondOwner === firstOwner) {
3708
- fs13.rmSync(lockPath, { recursive: true, force: true });
4065
+ fs14.rmSync(lockPath, { recursive: true, force: true });
3709
4066
  continue;
3710
4067
  }
3711
4068
  }
@@ -3721,10 +4078,10 @@ ${Date.now()}
3721
4078
  return operation();
3722
4079
  } finally {
3723
4080
  try {
3724
- const owner = fs13.readFileSync(ownerPath2, "utf8");
4081
+ const owner = fs14.readFileSync(ownerPath2, "utf8");
3725
4082
  if (owner.startsWith(`${token}
3726
4083
  `)) {
3727
- fs13.rmSync(lockPath, { recursive: true, force: true });
4084
+ fs14.rmSync(lockPath, { recursive: true, force: true });
3728
4085
  }
3729
4086
  } catch {
3730
4087
  }
@@ -3732,14 +4089,14 @@ ${Date.now()}
3732
4089
  }
3733
4090
  fingerprint() {
3734
4091
  try {
3735
- const stat = fs13.statSync(this.#registryPath);
4092
+ const stat = fs14.statSync(this.#registryPath);
3736
4093
  return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeMs}`;
3737
4094
  } catch {
3738
4095
  return void 0;
3739
4096
  }
3740
4097
  }
3741
4098
  read() {
3742
- return JSON.parse(fs13.readFileSync(this.#registryPath, "utf8"));
4099
+ return JSON.parse(fs14.readFileSync(this.#registryPath, "utf8"));
3743
4100
  }
3744
4101
  /** Call within withLock for read-modify-write operations. */
3745
4102
  write(actors) {
@@ -3777,7 +4134,7 @@ var normalizeCapabilityRequirements = (requirements = []) => {
3777
4134
  };
3778
4135
  var readRunRecord = (filePath) => {
3779
4136
  try {
3780
- const parsed = JSON.parse(fs14.readFileSync(filePath, "utf8"));
4137
+ const parsed = JSON.parse(fs15.readFileSync(filePath, "utf8"));
3781
4138
  if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return void 0;
3782
4139
  return parsed;
3783
4140
  } catch {
@@ -3827,7 +4184,7 @@ var ActorManager = class {
3827
4184
  this.meshConfig = meshConfig;
3828
4185
  this.agents = agents;
3829
4186
  this.onDeliver = onDeliver;
3830
- this.#actorRoot = options.actorRoot ?? fs14.mkdtempSync(path16.join(os4.tmpdir(), "pi-fabric-actors-"));
4187
+ this.#actorRoot = options.actorRoot ?? fs15.mkdtempSync(path17.join(os4.tmpdir(), "pi-fabric-actors-"));
3831
4188
  this.#actorScope = options.actorScope ?? meshConfig.actorScope;
3832
4189
  this.#persistent = options.persistent ?? false;
3833
4190
  this.#mainAgent = options.mainAgent;
@@ -3978,9 +4335,9 @@ var ActorManager = class {
3978
4335
  if (requirements.length > 0 && !this.#acquireCapabilityView) {
3979
4336
  throw new Error("This Fabric host cannot commit actor capability requirements");
3980
4337
  }
3981
- const id = randomUUID7().replaceAll("-", "");
3982
- const actorDirectory = path16.join(this.#actorRoot, id);
3983
- fs14.mkdirSync(actorDirectory, { recursive: true, mode: 448 });
4338
+ const id = randomUUID8().replaceAll("-", "");
4339
+ const actorDirectory = path17.join(this.#actorRoot, id);
4340
+ fs15.mkdirSync(actorDirectory, { recursive: true, mode: 448 });
3984
4341
  const actor = {
3985
4342
  id,
3986
4343
  name,
@@ -4006,7 +4363,7 @@ var ActorManager = class {
4006
4363
  requirements,
4007
4364
  ...request.validWhile ? { validWhile: structuredClone(request.validWhile) } : {},
4008
4365
  latestActivationSequence: 0,
4009
- sessionFile: path16.join(actorDirectory, "session.jsonl"),
4366
+ sessionFile: path17.join(actorDirectory, "session.jsonl"),
4010
4367
  queue: [],
4011
4368
  draining: false,
4012
4369
  messages: [],
@@ -4341,17 +4698,17 @@ var ActorManager = class {
4341
4698
  const type = opts.type ?? "session";
4342
4699
  const lines = Math.max(1, Math.min(opts.lines ?? 200, 5e3));
4343
4700
  const sessionFile = actor.sessionFile;
4344
- const logDir = path16.join(path16.dirname(sessionFile), "runs");
4701
+ const logDir = path17.join(path17.dirname(sessionFile), "runs");
4345
4702
  const sessionPage = type === "run" ? { lines: [], hasMore: false } : readJsonlPage(sessionFile, lines, opts.before);
4346
4703
  const session = sessionPage.lines;
4347
4704
  let run;
4348
4705
  if (type !== "session") {
4349
4706
  const targetRunId = opts.runId ?? actor.lastRunId;
4350
4707
  if (targetRunId) {
4351
- const runPath = path16.join(logDir, targetRunId);
4352
- if (fs14.existsSync(runPath)) {
4353
- const statusRecord = readRunRecord(path16.join(runPath, "status.json"));
4354
- const eventsFile = path16.join(runPath, "events.jsonl");
4708
+ const runPath = path17.join(logDir, targetRunId);
4709
+ if (fs15.existsSync(runPath)) {
4710
+ const statusRecord = readRunRecord(path17.join(runPath, "status.json"));
4711
+ const eventsFile = path17.join(runPath, "events.jsonl");
4355
4712
  const page = readJsonlPage(eventsFile, lines, opts.before);
4356
4713
  run = {
4357
4714
  runId: targetRunId,
@@ -4552,7 +4909,7 @@ var ActorManager = class {
4552
4909
  await this.#bindings.delete(actor.id);
4553
4910
  this.#actors.delete(actor.id);
4554
4911
  this.#emitChange();
4555
- fs14.rmSync(path16.dirname(actor.sessionFile), { recursive: true, force: true });
4912
+ fs15.rmSync(path17.dirname(actor.sessionFile), { recursive: true, force: true });
4556
4913
  await this.#saveActors(/* @__PURE__ */ new Set([actor.id]));
4557
4914
  await this.mesh.delete({ key: this.#presenceKey(actor.id) }).catch(() => ({ deleted: false }));
4558
4915
  if (retainedRunId) await this.agents.cleanup(retainedRunId).catch(() => ({ cleaned: false }));
@@ -4592,7 +4949,7 @@ var ActorManager = class {
4592
4949
  await Promise.allSettled(
4593
4950
  [...this.#actors.values()].map((actor) => actor.drain ?? Promise.resolve())
4594
4951
  );
4595
- fs14.rmSync(this.#actorRoot, { recursive: true, force: true });
4952
+ fs15.rmSync(this.#actorRoot, { recursive: true, force: true });
4596
4953
  }
4597
4954
  #enqueue(actor, source, payload, options = {}) {
4598
4955
  const canManage = options.ownershipChecked ? this.#canManageCached(actor.id) : this.#canManage(actor.id);
@@ -4632,7 +4989,7 @@ var ActorManager = class {
4632
4989
  `Fabric actor queue limit reached for ${actor.name} (${this.meshConfig.actorQueueLimit})`
4633
4990
  );
4634
4991
  }
4635
- const itemId = randomUUID7();
4992
+ const itemId = randomUUID8();
4636
4993
  const item = {
4637
4994
  id: itemId,
4638
4995
  source,
@@ -4745,7 +5102,7 @@ var ActorManager = class {
4745
5102
  if (actor.responseMode === "directive") {
4746
5103
  const reason = result.error || `Actor run ${result.status}`;
4747
5104
  const silent = {
4748
- id: randomUUID7(),
5105
+ id: randomUUID8(),
4749
5106
  actorId: actor.id,
4750
5107
  actorName: actor.name,
4751
5108
  direction: "out",
@@ -4810,7 +5167,7 @@ var ActorManager = class {
4810
5167
  }
4811
5168
  actor.lastError = message;
4812
5169
  const failed = {
4813
- id: randomUUID7(),
5170
+ id: randomUUID8(),
4814
5171
  actorId: actor.id,
4815
5172
  actorName: actor.name,
4816
5173
  direction: "out",
@@ -4894,7 +5251,7 @@ var ActorManager = class {
4894
5251
  if (actor.responseMode === "directive") {
4895
5252
  const directive = asDirective(result);
4896
5253
  return {
4897
- id: randomUUID7(),
5254
+ id: randomUUID8(),
4898
5255
  actorId: actor.id,
4899
5256
  actorName: actor.name,
4900
5257
  direction: "out",
@@ -4908,7 +5265,7 @@ var ActorManager = class {
4908
5265
  };
4909
5266
  }
4910
5267
  return {
4911
- id: randomUUID7(),
5268
+ id: randomUUID8(),
4912
5269
  actorId: actor.id,
4913
5270
  actorName: actor.name,
4914
5271
  direction: "out",
@@ -4963,7 +5320,7 @@ var ActorManager = class {
4963
5320
  }
4964
5321
  #recordStale(actor, item, reason = "validWhile returned false", runId, usage) {
4965
5322
  const message = {
4966
- id: randomUUID7(),
5323
+ id: randomUUID8(),
4967
5324
  actorId: actor.id,
4968
5325
  actorName: actor.name,
4969
5326
  direction: "out",
@@ -5241,7 +5598,7 @@ var ActorManager = class {
5241
5598
  ...typeof record.capabilityDigest === "string" ? { capabilityDigest: record.capabilityDigest } : {},
5242
5599
  ...record.validWhile?.version === 1 && typeof record.validWhile.source === "string" ? { validWhile: record.validWhile } : {},
5243
5600
  latestActivationSequence: 0,
5244
- sessionFile: path16.join(this.#actorRoot, record.id, "session.jsonl"),
5601
+ sessionFile: path17.join(this.#actorRoot, record.id, "session.jsonl"),
5245
5602
  queue: [],
5246
5603
  draining: false,
5247
5604
  messages: [],
@@ -5335,7 +5692,7 @@ var ActorManager = class {
5335
5692
  ...actor.lastRunId ? { lastRunId: actor.lastRunId } : {},
5336
5693
  ...actor.lastError ? { lastError: actor.lastError } : {},
5337
5694
  sessionFile: actor.sessionFile,
5338
- logDir: path16.join(path16.dirname(actor.sessionFile), "runs")
5695
+ logDir: path17.join(path17.dirname(actor.sessionFile), "runs")
5339
5696
  };
5340
5697
  }
5341
5698
  validateDirectMessage(message, data) {
@@ -5503,10 +5860,10 @@ var ActorDirectory = class extends ActorManager {
5503
5860
  delete options.actorRoot;
5504
5861
  delete options.meshCursorPath;
5505
5862
  const cursorPaths = meshCursorPath ? { project: `${meshCursorPath}.project`, session: `${meshCursorPath}.session` } : void 0;
5506
- if (meshCursorPath && fs15.existsSync(meshCursorPath)) {
5863
+ if (meshCursorPath && fs16.existsSync(meshCursorPath)) {
5507
5864
  for (const cursorPath of Object.values(cursorPaths)) {
5508
5865
  try {
5509
- if (!fs15.existsSync(cursorPath)) fs15.copyFileSync(meshCursorPath, cursorPath);
5866
+ if (!fs16.existsSync(cursorPath)) fs16.copyFileSync(meshCursorPath, cursorPath);
5510
5867
  } catch {
5511
5868
  }
5512
5869
  }
@@ -5662,7 +6019,7 @@ var ActorDirectory = class extends ActorManager {
5662
6019
  };
5663
6020
 
5664
6021
  // src/lifecycle/broker.ts
5665
- import { randomUUID as randomUUID8 } from "node:crypto";
6022
+ import { randomUUID as randomUUID9 } from "node:crypto";
5666
6023
  var subscriptionKey = (id) => FABRIC_LIFECYCLE_SUBSCRIPTION_PREFIX + id;
5667
6024
  var LifecycleBroker = class {
5668
6025
  constructor(mesh, identity, participants, options, deliver) {
@@ -5741,7 +6098,7 @@ var LifecycleBroker = class {
5741
6098
  const now = Date.now();
5742
6099
  const subscription = {
5743
6100
  format: 1,
5744
- id: randomUUID8().replaceAll("-", ""),
6101
+ id: randomUUID9().replaceAll("-", ""),
5745
6102
  from,
5746
6103
  events,
5747
6104
  to,
@@ -5906,7 +6263,7 @@ var LifecycleBroker = class {
5906
6263
  };
5907
6264
 
5908
6265
  // src/topology/control-plane.ts
5909
- import { createHash as createHash2, randomUUID as randomUUID9 } from "node:crypto";
6266
+ import { createHash as createHash2, randomUUID as randomUUID10 } from "node:crypto";
5910
6267
  var CONTROL_TOPIC = "fabric.control.command";
5911
6268
  var ACK_TOPIC = "fabric.control.ack";
5912
6269
  var CONTROL_SEEN_PREFIX = "topology/control-seen/";
@@ -6001,7 +6358,7 @@ var FabricControlPlane = class {
6001
6358
  this.#pollMs * 4,
6002
6359
  Math.min(MAX_CONTROL_TIMEOUT_MS, Math.floor(options.timeoutMs ?? this.#ackTimeoutMs))
6003
6360
  );
6004
- const commandId = randomUUID9();
6361
+ const commandId = randomUUID10();
6005
6362
  const requestedAt = Date.now();
6006
6363
  let pendingRequest;
6007
6364
  const acceptance = new Promise((resolve, reject) => {
@@ -6093,7 +6450,7 @@ var FabricControlPlane = class {
6093
6450
  to: pending.ownerHostId,
6094
6451
  data: {
6095
6452
  version: 1,
6096
- commandId: randomUUID9(),
6453
+ commandId: randomUUID10(),
6097
6454
  targetId: pending.targetId,
6098
6455
  operation: "cancel",
6099
6456
  cancelCommandId: commandId,
@@ -6948,6 +7305,10 @@ export {
6948
7305
  withInheritedSessionPins,
6949
7306
  isFabricWorktreePath,
6950
7307
  addCloneFirstWorktree,
7308
+ thinkingTransferPolicy,
7309
+ buildThinkingDigest,
7310
+ checkedHandoffCompaction,
7311
+ snapshotHandoffSession,
6951
7312
  useBudgetLedger,
6952
7313
  effectiveAgentTimeoutMs,
6953
7314
  resolveAgentCwd,
@@ -6962,4 +7323,4 @@ export {
6962
7323
  agentParticipantRecords,
6963
7324
  actorParticipantRecord
6964
7325
  };
6965
- //# sourceMappingURL=chunk-7OH6DD3S.js.map
7326
+ //# sourceMappingURL=chunk-Q4XJ4PYL.js.map