@e4779/pi-fabric 0.92.17-fork.3

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 (1044) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +181 -0
  3. package/THIRD_PARTY_NOTICES.md +33 -0
  4. package/dist/activity/store.d.ts +33 -0
  5. package/dist/activity/store.d.ts.map +1 -0
  6. package/dist/activity/types.d.ts +104 -0
  7. package/dist/activity/types.d.ts.map +1 -0
  8. package/dist/actors/binding-store.d.ts +17 -0
  9. package/dist/actors/binding-store.d.ts.map +1 -0
  10. package/dist/actors/context.d.ts +13 -0
  11. package/dist/actors/context.d.ts.map +1 -0
  12. package/dist/actors/delivery-policy.d.ts +8 -0
  13. package/dist/actors/delivery-policy.d.ts.map +1 -0
  14. package/dist/actors/directory.d.ts +47 -0
  15. package/dist/actors/directory.d.ts.map +1 -0
  16. package/dist/actors/global-registry.d.ts +47 -0
  17. package/dist/actors/global-registry.d.ts.map +1 -0
  18. package/dist/actors/host-event-observer.d.ts +5 -0
  19. package/dist/actors/host-event-observer.d.ts.map +1 -0
  20. package/dist/actors/host-event-payload.d.ts +14 -0
  21. package/dist/actors/host-event-payload.d.ts.map +1 -0
  22. package/dist/actors/log-store.d.ts +22 -0
  23. package/dist/actors/log-store.d.ts.map +1 -0
  24. package/dist/actors/manager.d.ts +175 -0
  25. package/dist/actors/manager.d.ts.map +1 -0
  26. package/dist/actors/mesh-monitor.d.ts +22 -0
  27. package/dist/actors/mesh-monitor.d.ts.map +1 -0
  28. package/dist/actors/predicate.d.ts +7 -0
  29. package/dist/actors/predicate.d.ts.map +1 -0
  30. package/dist/actors/registry-store.d.ts +15 -0
  31. package/dist/actors/registry-store.d.ts.map +1 -0
  32. package/dist/actors/types.d.ts +218 -0
  33. package/dist/actors/types.d.ts.map +1 -0
  34. package/dist/agents/bash-worktree-add.d.ts +24 -0
  35. package/dist/agents/bash-worktree-add.d.ts.map +1 -0
  36. package/dist/agents/budget-ledger.d.ts +88 -0
  37. package/dist/agents/budget-ledger.d.ts.map +1 -0
  38. package/dist/agents/claude-cli.d.ts +32 -0
  39. package/dist/agents/claude-cli.d.ts.map +1 -0
  40. package/dist/agents/claude-cli.js +17 -0
  41. package/dist/agents/claude-cli.js.map +7 -0
  42. package/dist/agents/clone-first-worktree.d.ts +17 -0
  43. package/dist/agents/clone-first-worktree.d.ts.map +1 -0
  44. package/dist/agents/compact-control.d.ts +32 -0
  45. package/dist/agents/compact-control.d.ts.map +1 -0
  46. package/dist/agents/compact-control.js +129 -0
  47. package/dist/agents/compact-control.js.map +7 -0
  48. package/dist/agents/constants.d.ts +9 -0
  49. package/dist/agents/constants.d.ts.map +1 -0
  50. package/dist/agents/cow-clone.d.ts +8 -0
  51. package/dist/agents/cow-clone.d.ts.map +1 -0
  52. package/dist/agents/handoff-completion.d.ts +4 -0
  53. package/dist/agents/handoff-completion.d.ts.map +1 -0
  54. package/dist/agents/handoff.d.ts +19 -0
  55. package/dist/agents/handoff.d.ts.map +1 -0
  56. package/dist/agents/lifecycle.d.ts +32 -0
  57. package/dist/agents/lifecycle.d.ts.map +1 -0
  58. package/dist/agents/manager.d.ts +75 -0
  59. package/dist/agents/manager.d.ts.map +1 -0
  60. package/dist/agents/pi-binary.d.ts +7 -0
  61. package/dist/agents/pi-binary.d.ts.map +1 -0
  62. package/dist/agents/request.d.ts +13 -0
  63. package/dist/agents/request.d.ts.map +1 -0
  64. package/dist/agents/result.d.ts +8 -0
  65. package/dist/agents/result.d.ts.map +1 -0
  66. package/dist/agents/result.js +9 -0
  67. package/dist/agents/result.js.map +7 -0
  68. package/dist/agents/rm.d.ts +15 -0
  69. package/dist/agents/rm.d.ts.map +1 -0
  70. package/dist/agents/semaphore.d.ts +7 -0
  71. package/dist/agents/semaphore.d.ts.map +1 -0
  72. package/dist/agents/service-provider.d.ts +9 -0
  73. package/dist/agents/service-provider.d.ts.map +1 -0
  74. package/dist/agents/service-schema.d.ts +6 -0
  75. package/dist/agents/service-schema.d.ts.map +1 -0
  76. package/dist/agents/service-types.d.ts +192 -0
  77. package/dist/agents/service-types.d.ts.map +1 -0
  78. package/dist/agents/service.d.ts +36 -0
  79. package/dist/agents/service.d.ts.map +1 -0
  80. package/dist/agents/session-export.d.ts +39 -0
  81. package/dist/agents/session-export.d.ts.map +1 -0
  82. package/dist/agents/session-pins.d.ts +24 -0
  83. package/dist/agents/session-pins.d.ts.map +1 -0
  84. package/dist/agents/thinking-transfer.d.ts +39 -0
  85. package/dist/agents/thinking-transfer.d.ts.map +1 -0
  86. package/dist/agents/transports/herdr-transport.d.ts +10 -0
  87. package/dist/agents/transports/herdr-transport.d.ts.map +1 -0
  88. package/dist/agents/transports/localterm-transport.d.ts +7 -0
  89. package/dist/agents/transports/localterm-transport.d.ts.map +1 -0
  90. package/dist/agents/transports/process-transport.d.ts +7 -0
  91. package/dist/agents/transports/process-transport.d.ts.map +1 -0
  92. package/dist/agents/transports/process-utils.d.ts +33 -0
  93. package/dist/agents/transports/process-utils.d.ts.map +1 -0
  94. package/dist/agents/transports/screen-transport.d.ts +7 -0
  95. package/dist/agents/transports/screen-transport.d.ts.map +1 -0
  96. package/dist/agents/transports/tmux-transport.d.ts +7 -0
  97. package/dist/agents/transports/tmux-transport.d.ts.map +1 -0
  98. package/dist/agents/types.d.ts +280 -0
  99. package/dist/agents/types.d.ts.map +1 -0
  100. package/dist/agents/veda-cli.d.ts +22 -0
  101. package/dist/agents/veda-cli.d.ts.map +1 -0
  102. package/dist/agents/veda-cli.js +13 -0
  103. package/dist/agents/veda-cli.js.map +7 -0
  104. package/dist/agents/worktree-manager.d.ts +14 -0
  105. package/dist/agents/worktree-manager.d.ts.map +1 -0
  106. package/dist/agents/worktree-paths.d.ts +5 -0
  107. package/dist/agents/worktree-paths.d.ts.map +1 -0
  108. package/dist/agents.d.ts +8 -0
  109. package/dist/agents.d.ts.map +1 -0
  110. package/dist/agents.js +761 -0
  111. package/dist/agents.js.map +7 -0
  112. package/dist/async-settlement.d.ts +4 -0
  113. package/dist/async-settlement.d.ts.map +1 -0
  114. package/dist/audit/details.d.ts +86 -0
  115. package/dist/audit/details.d.ts.map +1 -0
  116. package/dist/audit/index.d.ts +4 -0
  117. package/dist/audit/index.d.ts.map +1 -0
  118. package/dist/audit/projection.d.ts +20 -0
  119. package/dist/audit/projection.d.ts.map +1 -0
  120. package/dist/audit/trace.d.ts +99 -0
  121. package/dist/audit/trace.d.ts.map +1 -0
  122. package/dist/capture/catalog.d.ts +30 -0
  123. package/dist/capture/catalog.d.ts.map +1 -0
  124. package/dist/capture/interceptor.d.ts +20 -0
  125. package/dist/capture/interceptor.d.ts.map +1 -0
  126. package/dist/capture/wrapper.d.ts +15 -0
  127. package/dist/capture/wrapper.d.ts.map +1 -0
  128. package/dist/chunks/chunk-2DMJ7MEI.js +1984 -0
  129. package/dist/chunks/chunk-2DMJ7MEI.js.map +7 -0
  130. package/dist/chunks/chunk-2PZWDVJB.js +738 -0
  131. package/dist/chunks/chunk-2PZWDVJB.js.map +7 -0
  132. package/dist/chunks/chunk-2UQV52II.js +440 -0
  133. package/dist/chunks/chunk-2UQV52II.js.map +7 -0
  134. package/dist/chunks/chunk-32BNQ75J.js +1445 -0
  135. package/dist/chunks/chunk-32BNQ75J.js.map +7 -0
  136. package/dist/chunks/chunk-3H7SDWZI.js +467 -0
  137. package/dist/chunks/chunk-3H7SDWZI.js.map +7 -0
  138. package/dist/chunks/chunk-3MEHEH6B.js +41 -0
  139. package/dist/chunks/chunk-3MEHEH6B.js.map +7 -0
  140. package/dist/chunks/chunk-3QECYQGA.js +70 -0
  141. package/dist/chunks/chunk-3QECYQGA.js.map +7 -0
  142. package/dist/chunks/chunk-3WIGAX56.js +644 -0
  143. package/dist/chunks/chunk-3WIGAX56.js.map +7 -0
  144. package/dist/chunks/chunk-3YZUQESG.js +16 -0
  145. package/dist/chunks/chunk-3YZUQESG.js.map +7 -0
  146. package/dist/chunks/chunk-4JETKRFE.js +287 -0
  147. package/dist/chunks/chunk-4JETKRFE.js.map +7 -0
  148. package/dist/chunks/chunk-4SSMGBF4.js +93 -0
  149. package/dist/chunks/chunk-4SSMGBF4.js.map +7 -0
  150. package/dist/chunks/chunk-5SU3YXBS.js +15 -0
  151. package/dist/chunks/chunk-5SU3YXBS.js.map +7 -0
  152. package/dist/chunks/chunk-656HWVFU.js +409 -0
  153. package/dist/chunks/chunk-656HWVFU.js.map +7 -0
  154. package/dist/chunks/chunk-7A6NVHB5.js +1242 -0
  155. package/dist/chunks/chunk-7A6NVHB5.js.map +7 -0
  156. package/dist/chunks/chunk-7TB7NXSL.js +58 -0
  157. package/dist/chunks/chunk-7TB7NXSL.js.map +7 -0
  158. package/dist/chunks/chunk-AAHHYDTO.js +24 -0
  159. package/dist/chunks/chunk-AAHHYDTO.js.map +7 -0
  160. package/dist/chunks/chunk-ARLYAW2A.js +95 -0
  161. package/dist/chunks/chunk-ARLYAW2A.js.map +7 -0
  162. package/dist/chunks/chunk-AYBIR4YV.js +210 -0
  163. package/dist/chunks/chunk-AYBIR4YV.js.map +7 -0
  164. package/dist/chunks/chunk-BOTRGFQQ.js +87 -0
  165. package/dist/chunks/chunk-BOTRGFQQ.js.map +7 -0
  166. package/dist/chunks/chunk-CGPK5WHX.js +96 -0
  167. package/dist/chunks/chunk-CGPK5WHX.js.map +7 -0
  168. package/dist/chunks/chunk-CI56CW53.js +470 -0
  169. package/dist/chunks/chunk-CI56CW53.js.map +7 -0
  170. package/dist/chunks/chunk-CPSW2GW4.js +1466 -0
  171. package/dist/chunks/chunk-CPSW2GW4.js.map +7 -0
  172. package/dist/chunks/chunk-CQFP2RCP.js +64 -0
  173. package/dist/chunks/chunk-CQFP2RCP.js.map +7 -0
  174. package/dist/chunks/chunk-D5WKZONW.js +797 -0
  175. package/dist/chunks/chunk-D5WKZONW.js.map +7 -0
  176. package/dist/chunks/chunk-DLXPTBPL.js +151 -0
  177. package/dist/chunks/chunk-DLXPTBPL.js.map +7 -0
  178. package/dist/chunks/chunk-G4LADAYY.js +287 -0
  179. package/dist/chunks/chunk-G4LADAYY.js.map +7 -0
  180. package/dist/chunks/chunk-GXNR6NRU.js +447 -0
  181. package/dist/chunks/chunk-GXNR6NRU.js.map +7 -0
  182. package/dist/chunks/chunk-IGVDD2HT.js +10 -0
  183. package/dist/chunks/chunk-IGVDD2HT.js.map +7 -0
  184. package/dist/chunks/chunk-J2HV2URQ.js +1125 -0
  185. package/dist/chunks/chunk-J2HV2URQ.js.map +7 -0
  186. package/dist/chunks/chunk-KAD7UWT2.js +99 -0
  187. package/dist/chunks/chunk-KAD7UWT2.js.map +7 -0
  188. package/dist/chunks/chunk-KYXZJNV6.js +227 -0
  189. package/dist/chunks/chunk-KYXZJNV6.js.map +7 -0
  190. package/dist/chunks/chunk-LMAVZN7J.js +8 -0
  191. package/dist/chunks/chunk-LMAVZN7J.js.map +7 -0
  192. package/dist/chunks/chunk-M3S7XITB.js +110 -0
  193. package/dist/chunks/chunk-M3S7XITB.js.map +7 -0
  194. package/dist/chunks/chunk-MGDLRV2R.js +112 -0
  195. package/dist/chunks/chunk-MGDLRV2R.js.map +7 -0
  196. package/dist/chunks/chunk-MGWQOKBV.js +30 -0
  197. package/dist/chunks/chunk-MGWQOKBV.js.map +7 -0
  198. package/dist/chunks/chunk-N5GUXC6F.js +184 -0
  199. package/dist/chunks/chunk-N5GUXC6F.js.map +7 -0
  200. package/dist/chunks/chunk-NQOEHX62.js +215 -0
  201. package/dist/chunks/chunk-NQOEHX62.js.map +7 -0
  202. package/dist/chunks/chunk-OKOHRXGF.js +100 -0
  203. package/dist/chunks/chunk-OKOHRXGF.js.map +7 -0
  204. package/dist/chunks/chunk-OP2KTYQB.js +286 -0
  205. package/dist/chunks/chunk-OP2KTYQB.js.map +7 -0
  206. package/dist/chunks/chunk-OTCASLY2.js +52 -0
  207. package/dist/chunks/chunk-OTCASLY2.js.map +7 -0
  208. package/dist/chunks/chunk-PAN6C3JM.js +42 -0
  209. package/dist/chunks/chunk-PAN6C3JM.js.map +7 -0
  210. package/dist/chunks/chunk-PH7ZJ27F.js +6873 -0
  211. package/dist/chunks/chunk-PH7ZJ27F.js.map +7 -0
  212. package/dist/chunks/chunk-PM5I335G.js +225 -0
  213. package/dist/chunks/chunk-PM5I335G.js.map +7 -0
  214. package/dist/chunks/chunk-PSNXUZMY.js +218 -0
  215. package/dist/chunks/chunk-PSNXUZMY.js.map +7 -0
  216. package/dist/chunks/chunk-PXAICAUT.js +24 -0
  217. package/dist/chunks/chunk-PXAICAUT.js.map +7 -0
  218. package/dist/chunks/chunk-RERA6YWA.js +359 -0
  219. package/dist/chunks/chunk-RERA6YWA.js.map +7 -0
  220. package/dist/chunks/chunk-RNOPHITP.js +1720 -0
  221. package/dist/chunks/chunk-RNOPHITP.js.map +7 -0
  222. package/dist/chunks/chunk-RRGTKHXZ.js +931 -0
  223. package/dist/chunks/chunk-RRGTKHXZ.js.map +7 -0
  224. package/dist/chunks/chunk-SWB2OHYW.js +93 -0
  225. package/dist/chunks/chunk-SWB2OHYW.js.map +7 -0
  226. package/dist/chunks/chunk-T3A5GNCW.js +19 -0
  227. package/dist/chunks/chunk-T3A5GNCW.js.map +7 -0
  228. package/dist/chunks/chunk-TPLMVELH.js +118 -0
  229. package/dist/chunks/chunk-TPLMVELH.js.map +7 -0
  230. package/dist/chunks/chunk-TSRKCXNI.js +17 -0
  231. package/dist/chunks/chunk-TSRKCXNI.js.map +7 -0
  232. package/dist/chunks/chunk-U5FYOMG5.js +119 -0
  233. package/dist/chunks/chunk-U5FYOMG5.js.map +7 -0
  234. package/dist/chunks/chunk-U6CTHPZC.js +1924 -0
  235. package/dist/chunks/chunk-U6CTHPZC.js.map +7 -0
  236. package/dist/chunks/chunk-UDFDF7IY.js +1572 -0
  237. package/dist/chunks/chunk-UDFDF7IY.js.map +7 -0
  238. package/dist/chunks/chunk-UKMQK5VP.js +231 -0
  239. package/dist/chunks/chunk-UKMQK5VP.js.map +7 -0
  240. package/dist/chunks/chunk-UQ4LTUH4.js +2181 -0
  241. package/dist/chunks/chunk-UQ4LTUH4.js.map +7 -0
  242. package/dist/chunks/chunk-UTR3I23Z.js +65 -0
  243. package/dist/chunks/chunk-UTR3I23Z.js.map +7 -0
  244. package/dist/chunks/chunk-VPPIJRNZ.js +50 -0
  245. package/dist/chunks/chunk-VPPIJRNZ.js.map +7 -0
  246. package/dist/chunks/chunk-VRYEGVHR.js +195 -0
  247. package/dist/chunks/chunk-VRYEGVHR.js.map +7 -0
  248. package/dist/chunks/chunk-VRZNFNPB.js +4218 -0
  249. package/dist/chunks/chunk-VRZNFNPB.js.map +7 -0
  250. package/dist/chunks/chunk-VXZZJ44D.js +295 -0
  251. package/dist/chunks/chunk-VXZZJ44D.js.map +7 -0
  252. package/dist/chunks/chunk-W3FRE4VI.js +297 -0
  253. package/dist/chunks/chunk-W3FRE4VI.js.map +7 -0
  254. package/dist/chunks/chunk-WVH324VF.js +60 -0
  255. package/dist/chunks/chunk-WVH324VF.js.map +7 -0
  256. package/dist/chunks/chunk-X7G62ZGH.js +151 -0
  257. package/dist/chunks/chunk-X7G62ZGH.js.map +7 -0
  258. package/dist/chunks/chunk-XB3RJVT4.js +17 -0
  259. package/dist/chunks/chunk-XB3RJVT4.js.map +7 -0
  260. package/dist/chunks/chunk-XT4346N7.js +651 -0
  261. package/dist/chunks/chunk-XT4346N7.js.map +7 -0
  262. package/dist/chunks/chunk-Y7KNRAFL.js +1180 -0
  263. package/dist/chunks/chunk-Y7KNRAFL.js.map +7 -0
  264. package/dist/chunks/chunk-YK5AZ7CZ.js +692 -0
  265. package/dist/chunks/chunk-YK5AZ7CZ.js.map +7 -0
  266. package/dist/chunks/chunk-YU4O6SWQ.js +246 -0
  267. package/dist/chunks/chunk-YU4O6SWQ.js.map +7 -0
  268. package/dist/chunks/chunk-YU62DDKK.js +22 -0
  269. package/dist/chunks/chunk-YU62DDKK.js.map +7 -0
  270. package/dist/chunks/chunk-Z63R5GVN.js +121 -0
  271. package/dist/chunks/chunk-Z63R5GVN.js.map +7 -0
  272. package/dist/chunks/chunk-ZDNGXLEC.js +221 -0
  273. package/dist/chunks/chunk-ZDNGXLEC.js.map +7 -0
  274. package/dist/chunks/chunk-ZZ4LHQYJ.js +777 -0
  275. package/dist/chunks/chunk-ZZ4LHQYJ.js.map +7 -0
  276. package/dist/commands/fabric.d.ts +17 -0
  277. package/dist/commands/fabric.d.ts.map +1 -0
  278. package/dist/compaction/bounds.d.ts +23 -0
  279. package/dist/compaction/bounds.d.ts.map +1 -0
  280. package/dist/compaction/branch-details.d.ts +83 -0
  281. package/dist/compaction/branch-details.d.ts.map +1 -0
  282. package/dist/compaction/branch-summary.d.ts +9 -0
  283. package/dist/compaction/branch-summary.d.ts.map +1 -0
  284. package/dist/compaction/enrichers.d.ts +10 -0
  285. package/dist/compaction/enrichers.d.ts.map +1 -0
  286. package/dist/compaction/hook.d.ts +99 -0
  287. package/dist/compaction/hook.d.ts.map +1 -0
  288. package/dist/compaction/hook.js +22 -0
  289. package/dist/compaction/hook.js.map +7 -0
  290. package/dist/compaction/instructions.d.ts +38 -0
  291. package/dist/compaction/instructions.d.ts.map +1 -0
  292. package/dist/compaction/normalize.d.ts +83 -0
  293. package/dist/compaction/normalize.d.ts.map +1 -0
  294. package/dist/compaction/projections.d.ts +31 -0
  295. package/dist/compaction/projections.d.ts.map +1 -0
  296. package/dist/compaction/qa.d.ts +27 -0
  297. package/dist/compaction/qa.d.ts.map +1 -0
  298. package/dist/compaction/render.d.ts +10 -0
  299. package/dist/compaction/render.d.ts.map +1 -0
  300. package/dist/compaction/threshold.d.ts +5 -0
  301. package/dist/compaction/threshold.d.ts.map +1 -0
  302. package/dist/compaction/trace-events.d.ts +23 -0
  303. package/dist/compaction/trace-events.d.ts.map +1 -0
  304. package/dist/components/catalog.d.ts +25 -0
  305. package/dist/components/catalog.d.ts.map +1 -0
  306. package/dist/components/effect-policy.d.ts +21 -0
  307. package/dist/components/effect-policy.d.ts.map +1 -0
  308. package/dist/components/effect-scope.d.ts +31 -0
  309. package/dist/components/effect-scope.d.ts.map +1 -0
  310. package/dist/components/loader.d.ts +27 -0
  311. package/dist/components/loader.d.ts.map +1 -0
  312. package/dist/components/model-guidance.d.ts +48 -0
  313. package/dist/components/model-guidance.d.ts.map +1 -0
  314. package/dist/components/provider-component.d.ts +31 -0
  315. package/dist/components/provider-component.d.ts.map +1 -0
  316. package/dist/components/supervisor.d.ts +29 -0
  317. package/dist/components/supervisor.d.ts.map +1 -0
  318. package/dist/components/types.d.ts +140 -0
  319. package/dist/components/types.d.ts.map +1 -0
  320. package/dist/config-migrations.d.ts +11 -0
  321. package/dist/config-migrations.d.ts.map +1 -0
  322. package/dist/config.d.ts +282 -0
  323. package/dist/config.d.ts.map +1 -0
  324. package/dist/core/action-arguments.d.ts +12 -0
  325. package/dist/core/action-arguments.d.ts.map +1 -0
  326. package/dist/core/action-registry.d.ts +170 -0
  327. package/dist/core/action-registry.d.ts.map +1 -0
  328. package/dist/core/action-registry.js +20 -0
  329. package/dist/core/action-registry.js.map +7 -0
  330. package/dist/core/action-repair.d.ts +15 -0
  331. package/dist/core/action-repair.d.ts.map +1 -0
  332. package/dist/core/action-result.d.ts +13 -0
  333. package/dist/core/action-result.d.ts.map +1 -0
  334. package/dist/core/agent-dir.d.ts +2 -0
  335. package/dist/core/agent-dir.d.ts.map +1 -0
  336. package/dist/core/approval-controller.d.ts +31 -0
  337. package/dist/core/approval-controller.d.ts.map +1 -0
  338. package/dist/core/atomic-write.d.ts +15 -0
  339. package/dist/core/atomic-write.d.ts.map +1 -0
  340. package/dist/core/auto-approval-classifier.d.ts +17 -0
  341. package/dist/core/auto-approval-classifier.d.ts.map +1 -0
  342. package/dist/core/call-preview.d.ts +8 -0
  343. package/dist/core/call-preview.d.ts.map +1 -0
  344. package/dist/core/child-tool-allowlist.d.ts +3 -0
  345. package/dist/core/child-tool-allowlist.d.ts.map +1 -0
  346. package/dist/core/compact-controller.d.ts +42 -0
  347. package/dist/core/compact-controller.d.ts.map +1 -0
  348. package/dist/core/core-override-guidance.d.ts +7 -0
  349. package/dist/core/core-override-guidance.d.ts.map +1 -0
  350. package/dist/core/damaged-file.d.ts +6 -0
  351. package/dist/core/damaged-file.d.ts.map +1 -0
  352. package/dist/core/direct-tool-approval.d.ts +19 -0
  353. package/dist/core/direct-tool-approval.d.ts.map +1 -0
  354. package/dist/core/effect-conflict.d.ts +3 -0
  355. package/dist/core/effect-conflict.d.ts.map +1 -0
  356. package/dist/core/file-lock.d.ts +12 -0
  357. package/dist/core/file-lock.d.ts.map +1 -0
  358. package/dist/core/kernel-skills.d.ts +3 -0
  359. package/dist/core/kernel-skills.d.ts.map +1 -0
  360. package/dist/core/model-resolution.d.ts +62 -0
  361. package/dist/core/model-resolution.d.ts.map +1 -0
  362. package/dist/core/model-usage.d.ts +8 -0
  363. package/dist/core/model-usage.d.ts.map +1 -0
  364. package/dist/core/pi-arguments.d.ts +3 -0
  365. package/dist/core/pi-arguments.d.ts.map +1 -0
  366. package/dist/core/pi-bash-error.d.ts +9 -0
  367. package/dist/core/pi-bash-error.d.ts.map +1 -0
  368. package/dist/core/pi-tools.d.ts +9 -0
  369. package/dist/core/pi-tools.d.ts.map +1 -0
  370. package/dist/core/provider-bindings.d.ts +47 -0
  371. package/dist/core/provider-bindings.d.ts.map +1 -0
  372. package/dist/core/proxy-contract.d.ts +18 -0
  373. package/dist/core/proxy-contract.d.ts.map +1 -0
  374. package/dist/core/session-context.d.ts +14 -0
  375. package/dist/core/session-context.d.ts.map +1 -0
  376. package/dist/core/shell-jobs.d.ts +99 -0
  377. package/dist/core/shell-jobs.d.ts.map +1 -0
  378. package/dist/core/skill-block.d.ts +10 -0
  379. package/dist/core/skill-block.d.ts.map +1 -0
  380. package/dist/core/skill-dir.d.ts +4 -0
  381. package/dist/core/skill-dir.d.ts.map +1 -0
  382. package/dist/core/skill-prompt.d.ts +3 -0
  383. package/dist/core/skill-prompt.d.ts.map +1 -0
  384. package/dist/core/skill-references.d.ts +7 -0
  385. package/dist/core/skill-references.d.ts.map +1 -0
  386. package/dist/core/stable-hash.d.ts +3 -0
  387. package/dist/core/stable-hash.d.ts.map +1 -0
  388. package/dist/core/system-guidance.d.ts +13 -0
  389. package/dist/core/system-guidance.d.ts.map +1 -0
  390. package/dist/core/token-math.d.ts +16 -0
  391. package/dist/core/token-math.d.ts.map +1 -0
  392. package/dist/core/tool-ownership.d.ts +47 -0
  393. package/dist/core/tool-ownership.d.ts.map +1 -0
  394. package/dist/core/tool-result-proxy.d.ts +18 -0
  395. package/dist/core/tool-result-proxy.d.ts.map +1 -0
  396. package/dist/entropy/active.d.ts +9 -0
  397. package/dist/entropy/active.d.ts.map +1 -0
  398. package/dist/entropy/compiled-store.d.ts +16 -0
  399. package/dist/entropy/compiled-store.d.ts.map +1 -0
  400. package/dist/entropy/compiled-surface.d.ts +57 -0
  401. package/dist/entropy/compiled-surface.d.ts.map +1 -0
  402. package/dist/entropy/compiler.d.ts +27 -0
  403. package/dist/entropy/compiler.d.ts.map +1 -0
  404. package/dist/entropy/corpus.d.ts +22 -0
  405. package/dist/entropy/corpus.d.ts.map +1 -0
  406. package/dist/entropy/fingerprint.d.ts +9 -0
  407. package/dist/entropy/fingerprint.d.ts.map +1 -0
  408. package/dist/entropy/index.d.ts +16 -0
  409. package/dist/entropy/index.d.ts.map +1 -0
  410. package/dist/entropy/index.js +194 -0
  411. package/dist/entropy/index.js.map +7 -0
  412. package/dist/entropy/meter.d.ts +10 -0
  413. package/dist/entropy/meter.d.ts.map +1 -0
  414. package/dist/entropy/normal-form.d.ts +40 -0
  415. package/dist/entropy/normal-form.d.ts.map +1 -0
  416. package/dist/entropy/passes.d.ts +13 -0
  417. package/dist/entropy/passes.d.ts.map +1 -0
  418. package/dist/entropy/pool-store.d.ts +15 -0
  419. package/dist/entropy/pool-store.d.ts.map +1 -0
  420. package/dist/entropy/pool.d.ts +41 -0
  421. package/dist/entropy/pool.d.ts.map +1 -0
  422. package/dist/entropy/presentation.d.ts +12 -0
  423. package/dist/entropy/presentation.d.ts.map +1 -0
  424. package/dist/entropy/sessions.d.ts +47 -0
  425. package/dist/entropy/sessions.d.ts.map +1 -0
  426. package/dist/entropy/surface.d.ts +30 -0
  427. package/dist/entropy/surface.d.ts.map +1 -0
  428. package/dist/entropy/trial.d.ts +38 -0
  429. package/dist/entropy/trial.d.ts.map +1 -0
  430. package/dist/entropy/types.d.ts +181 -0
  431. package/dist/entropy/types.d.ts.map +1 -0
  432. package/dist/execution-service.d.ts +66 -0
  433. package/dist/execution-service.d.ts.map +1 -0
  434. package/dist/fabric-exec-arguments.d.ts +7 -0
  435. package/dist/fabric-exec-arguments.d.ts.map +1 -0
  436. package/dist/fabric-exec-tool.d.ts +8 -0
  437. package/dist/fabric-exec-tool.d.ts.map +1 -0
  438. package/dist/fabric-runtime-state.d.ts +96 -0
  439. package/dist/fabric-runtime-state.d.ts.map +1 -0
  440. package/dist/fabric-runtime-state.js +11928 -0
  441. package/dist/fabric-runtime-state.js.map +7 -0
  442. package/dist/fabric-state.d.ts +95 -0
  443. package/dist/fabric-state.d.ts.map +1 -0
  444. package/dist/failure-progress.d.ts +3 -0
  445. package/dist/failure-progress.d.ts.map +1 -0
  446. package/dist/host-compatibility.d.ts +5 -0
  447. package/dist/host-compatibility.d.ts.map +1 -0
  448. package/dist/index.d.ts +11 -0
  449. package/dist/index.d.ts.map +1 -0
  450. package/dist/index.js +6094 -0
  451. package/dist/index.js.map +7 -0
  452. package/dist/jev/auth.d.ts +5 -0
  453. package/dist/jev/auth.d.ts.map +1 -0
  454. package/dist/jev/browser.d.ts +37 -0
  455. package/dist/jev/browser.d.ts.map +1 -0
  456. package/dist/jev/browser.js +13 -0
  457. package/dist/jev/browser.js.map +7 -0
  458. package/dist/jev/client.d.ts +29 -0
  459. package/dist/jev/client.d.ts.map +1 -0
  460. package/dist/jev/client.js +11 -0
  461. package/dist/jev/client.js.map +7 -0
  462. package/dist/jev/config.d.ts +17 -0
  463. package/dist/jev/config.d.ts.map +1 -0
  464. package/dist/jev/guest-types.d.ts +2 -0
  465. package/dist/jev/guest-types.d.ts.map +1 -0
  466. package/dist/jev/manager.d.ts +36 -0
  467. package/dist/jev/manager.d.ts.map +1 -0
  468. package/dist/jev/observation.d.ts +59 -0
  469. package/dist/jev/observation.d.ts.map +1 -0
  470. package/dist/jev/observation.js +20 -0
  471. package/dist/jev/observation.js.map +7 -0
  472. package/dist/jev/types.d.ts +142 -0
  473. package/dist/jev/types.d.ts.map +1 -0
  474. package/dist/jev/validation.d.ts +8 -0
  475. package/dist/jev/validation.d.ts.map +1 -0
  476. package/dist/jev.d.ts +9 -0
  477. package/dist/jev.d.ts.map +1 -0
  478. package/dist/jev.js +49 -0
  479. package/dist/jev.js.map +7 -0
  480. package/dist/lifecycle/broker.d.ts +30 -0
  481. package/dist/lifecycle/broker.d.ts.map +1 -0
  482. package/dist/lifecycle/delivery-scheduler.d.ts +30 -0
  483. package/dist/lifecycle/delivery-scheduler.d.ts.map +1 -0
  484. package/dist/lifecycle/types.d.ts +91 -0
  485. package/dist/lifecycle/types.d.ts.map +1 -0
  486. package/dist/log-tail.d.ts +11 -0
  487. package/dist/log-tail.d.ts.map +1 -0
  488. package/dist/main-agent.d.ts +70 -0
  489. package/dist/main-agent.d.ts.map +1 -0
  490. package/dist/managed-host.d.ts +22 -0
  491. package/dist/managed-host.d.ts.map +1 -0
  492. package/dist/mcp.d.ts +9 -0
  493. package/dist/mcp.d.ts.map +1 -0
  494. package/dist/mcp.js +21 -0
  495. package/dist/mcp.js.map +7 -0
  496. package/dist/memory/client.d.ts +31 -0
  497. package/dist/memory/client.d.ts.map +1 -0
  498. package/dist/memory/context.d.ts +114 -0
  499. package/dist/memory/context.d.ts.map +1 -0
  500. package/dist/memory/digest.d.ts +48 -0
  501. package/dist/memory/digest.d.ts.map +1 -0
  502. package/dist/memory/digest.js +7 -0
  503. package/dist/memory/digest.js.map +7 -0
  504. package/dist/memory/discovery.d.ts +43 -0
  505. package/dist/memory/discovery.d.ts.map +1 -0
  506. package/dist/memory/discovery.js +25 -0
  507. package/dist/memory/discovery.js.map +7 -0
  508. package/dist/memory/expand-service.d.ts +4 -0
  509. package/dist/memory/expand-service.d.ts.map +1 -0
  510. package/dist/memory/host-source.d.ts +60 -0
  511. package/dist/memory/host-source.d.ts.map +1 -0
  512. package/dist/memory/index.d.ts +113 -0
  513. package/dist/memory/index.d.ts.map +1 -0
  514. package/dist/memory/lineage.d.ts +25 -0
  515. package/dist/memory/lineage.d.ts.map +1 -0
  516. package/dist/memory/normalize.d.ts +188 -0
  517. package/dist/memory/normalize.d.ts.map +1 -0
  518. package/dist/memory/normalize.js +26 -0
  519. package/dist/memory/normalize.js.map +7 -0
  520. package/dist/memory/portable.d.ts +66 -0
  521. package/dist/memory/portable.d.ts.map +1 -0
  522. package/dist/memory/provider.d.ts +15 -0
  523. package/dist/memory/provider.d.ts.map +1 -0
  524. package/dist/memory/recall-service.d.ts +5 -0
  525. package/dist/memory/recall-service.d.ts.map +1 -0
  526. package/dist/memory/regex.d.ts +19 -0
  527. package/dist/memory/regex.d.ts.map +1 -0
  528. package/dist/memory/request-cache.d.ts +49 -0
  529. package/dist/memory/request-cache.d.ts.map +1 -0
  530. package/dist/memory/request-context.d.ts +57 -0
  531. package/dist/memory/request-context.d.ts.map +1 -0
  532. package/dist/memory/request-limits.d.ts +8 -0
  533. package/dist/memory/request-limits.d.ts.map +1 -0
  534. package/dist/memory/search.d.ts +98 -0
  535. package/dist/memory/search.d.ts.map +1 -0
  536. package/dist/memory/search.js +24 -0
  537. package/dist/memory/search.js.map +7 -0
  538. package/dist/memory/sessions-service.d.ts +3 -0
  539. package/dist/memory/sessions-service.d.ts.map +1 -0
  540. package/dist/memory/source-observation.d.ts +28 -0
  541. package/dist/memory/source-observation.d.ts.map +1 -0
  542. package/dist/memory/tokenize.d.ts +24 -0
  543. package/dist/memory/tokenize.d.ts.map +1 -0
  544. package/dist/memory.d.ts +8 -0
  545. package/dist/memory.d.ts.map +1 -0
  546. package/dist/memory.js +119 -0
  547. package/dist/memory.js.map +7 -0
  548. package/dist/mesh/store.d.ts +78 -0
  549. package/dist/mesh/store.d.ts.map +1 -0
  550. package/dist/output-budget.d.ts +12 -0
  551. package/dist/output-budget.d.ts.map +1 -0
  552. package/dist/prewalk/arm.d.ts +8 -0
  553. package/dist/prewalk/arm.d.ts.map +1 -0
  554. package/dist/prewalk/controller.d.ts +66 -0
  555. package/dist/prewalk/controller.d.ts.map +1 -0
  556. package/dist/prewalk/fs-drift.d.ts +19 -0
  557. package/dist/prewalk/fs-drift.d.ts.map +1 -0
  558. package/dist/prewalk/handoff.d.ts +46 -0
  559. package/dist/prewalk/handoff.d.ts.map +1 -0
  560. package/dist/protocol.d.ts +275 -0
  561. package/dist/protocol.d.ts.map +1 -0
  562. package/dist/protocol.js +46 -0
  563. package/dist/protocol.js.map +7 -0
  564. package/dist/providers/agents-actions.d.ts +3 -0
  565. package/dist/providers/agents-actions.d.ts.map +1 -0
  566. package/dist/providers/agents-message-router.d.ts +29 -0
  567. package/dist/providers/agents-message-router.d.ts.map +1 -0
  568. package/dist/providers/agents-progress.d.ts +18 -0
  569. package/dist/providers/agents-progress.d.ts.map +1 -0
  570. package/dist/providers/agents-provider.d.ts +51 -0
  571. package/dist/providers/agents-provider.d.ts.map +1 -0
  572. package/dist/providers/arg-normalization.d.ts +15 -0
  573. package/dist/providers/arg-normalization.d.ts.map +1 -0
  574. package/dist/providers/captured-tools-provider.d.ts +23 -0
  575. package/dist/providers/captured-tools-provider.d.ts.map +1 -0
  576. package/dist/providers/compact-provider.d.ts +14 -0
  577. package/dist/providers/compact-provider.d.ts.map +1 -0
  578. package/dist/providers/components-provider.d.ts +12 -0
  579. package/dist/providers/components-provider.d.ts.map +1 -0
  580. package/dist/providers/jev-provider.d.ts +70 -0
  581. package/dist/providers/jev-provider.d.ts.map +1 -0
  582. package/dist/providers/jev-provider.js +28 -0
  583. package/dist/providers/jev-provider.js.map +7 -0
  584. package/dist/providers/mcp-descriptor-cache.d.ts +47 -0
  585. package/dist/providers/mcp-descriptor-cache.d.ts.map +1 -0
  586. package/dist/providers/mcp-provider.d.ts +47 -0
  587. package/dist/providers/mcp-provider.d.ts.map +1 -0
  588. package/dist/providers/memory-provider.d.ts +32 -0
  589. package/dist/providers/memory-provider.d.ts.map +1 -0
  590. package/dist/providers/memory-provider.js +23 -0
  591. package/dist/providers/memory-provider.js.map +7 -0
  592. package/dist/providers/mesh-provider.d.ts +17 -0
  593. package/dist/providers/mesh-provider.d.ts.map +1 -0
  594. package/dist/providers/pi-bash-cwd.d.ts +49 -0
  595. package/dist/providers/pi-bash-cwd.d.ts.map +1 -0
  596. package/dist/providers/pi-tools-provider.d.ts +25 -0
  597. package/dist/providers/pi-tools-provider.d.ts.map +1 -0
  598. package/dist/providers/schema-provider.d.ts +15 -0
  599. package/dist/providers/schema-provider.d.ts.map +1 -0
  600. package/dist/providers/state-provider.d.ts +16 -0
  601. package/dist/providers/state-provider.d.ts.map +1 -0
  602. package/dist/providers/write-diff-limits.d.ts +5 -0
  603. package/dist/providers/write-diff-limits.d.ts.map +1 -0
  604. package/dist/providers/write-preview.d.ts +3 -0
  605. package/dist/providers/write-preview.d.ts.map +1 -0
  606. package/dist/ref-names.d.ts +2 -0
  607. package/dist/ref-names.d.ts.map +1 -0
  608. package/dist/repairs/active.d.ts +7 -0
  609. package/dist/repairs/active.d.ts.map +1 -0
  610. package/dist/repairs/apply.d.ts +7 -0
  611. package/dist/repairs/apply.d.ts.map +1 -0
  612. package/dist/repairs/catalog-digest.d.ts +5 -0
  613. package/dist/repairs/catalog-digest.d.ts.map +1 -0
  614. package/dist/repairs/classify.d.ts +10 -0
  615. package/dist/repairs/classify.d.ts.map +1 -0
  616. package/dist/repairs/compiler.d.ts +33 -0
  617. package/dist/repairs/compiler.d.ts.map +1 -0
  618. package/dist/repairs/promote.d.ts +4 -0
  619. package/dist/repairs/promote.d.ts.map +1 -0
  620. package/dist/repairs/store.d.ts +10 -0
  621. package/dist/repairs/store.d.ts.map +1 -0
  622. package/dist/repairs/types.d.ts +49 -0
  623. package/dist/repairs/types.d.ts.map +1 -0
  624. package/dist/repeat-guard.d.ts +25 -0
  625. package/dist/repeat-guard.d.ts.map +1 -0
  626. package/dist/residency/actor-client.d.ts +16 -0
  627. package/dist/residency/actor-client.d.ts.map +1 -0
  628. package/dist/residency/actor-client.js +9 -0
  629. package/dist/residency/actor-client.js.map +7 -0
  630. package/dist/residency/client.d.ts +44 -0
  631. package/dist/residency/client.d.ts.map +1 -0
  632. package/dist/residency/host.d.ts +3 -0
  633. package/dist/residency/host.d.ts.map +1 -0
  634. package/dist/residency/host.js +32 -0
  635. package/dist/residency/host.js.map +7 -0
  636. package/dist/residency/launcher-owner.d.ts +7 -0
  637. package/dist/residency/launcher-owner.d.ts.map +1 -0
  638. package/dist/residency/launcher.d.ts +3 -0
  639. package/dist/residency/launcher.d.ts.map +1 -0
  640. package/dist/residency/launcher.js +154 -0
  641. package/dist/residency/launcher.js.map +7 -0
  642. package/dist/residency/pi-entry.d.ts +3 -0
  643. package/dist/residency/pi-entry.d.ts.map +1 -0
  644. package/dist/residency/pi-entry.js +48 -0
  645. package/dist/residency/pi-entry.js.map +7 -0
  646. package/dist/residency/protocol.d.ts +122 -0
  647. package/dist/residency/protocol.d.ts.map +1 -0
  648. package/dist/run-display.d.ts +3 -0
  649. package/dist/run-display.d.ts.map +1 -0
  650. package/dist/runtime/core-override-guest-types.d.ts +15 -0
  651. package/dist/runtime/core-override-guest-types.d.ts.map +1 -0
  652. package/dist/runtime/core-override-guest-types.js +9 -0
  653. package/dist/runtime/core-override-guest-types.js.map +7 -0
  654. package/dist/runtime/core-tool-properties.d.ts +6 -0
  655. package/dist/runtime/core-tool-properties.d.ts.map +1 -0
  656. package/dist/runtime/cpython-child-source.d.ts +2 -0
  657. package/dist/runtime/cpython-child-source.d.ts.map +1 -0
  658. package/dist/runtime/cpython-linux-sandbox.d.ts +2 -0
  659. package/dist/runtime/cpython-linux-sandbox.d.ts.map +1 -0
  660. package/dist/runtime/cpython-runtime.d.ts +9 -0
  661. package/dist/runtime/cpython-runtime.d.ts.map +1 -0
  662. package/dist/runtime/cpython-runtime.js +677 -0
  663. package/dist/runtime/cpython-runtime.js.map +7 -0
  664. package/dist/runtime/dynamic-guest-types.d.ts +3 -0
  665. package/dist/runtime/dynamic-guest-types.d.ts.map +1 -0
  666. package/dist/runtime/dynamic-guest-types.js +8 -0
  667. package/dist/runtime/dynamic-guest-types.js.map +7 -0
  668. package/dist/runtime/guest-code-repair.d.ts +2 -0
  669. package/dist/runtime/guest-code-repair.d.ts.map +1 -0
  670. package/dist/runtime/guest-stack-map.d.ts +11 -0
  671. package/dist/runtime/guest-stack-map.d.ts.map +1 -0
  672. package/dist/runtime/guest-types.d.ts +40 -0
  673. package/dist/runtime/guest-types.d.ts.map +1 -0
  674. package/dist/runtime/guest-types.js +13 -0
  675. package/dist/runtime/guest-types.js.map +7 -0
  676. package/dist/runtime/kernel.d.ts +30 -0
  677. package/dist/runtime/kernel.d.ts.map +1 -0
  678. package/dist/runtime/monty-bridge.d.ts +4 -0
  679. package/dist/runtime/monty-bridge.d.ts.map +1 -0
  680. package/dist/runtime/monty-runtime.d.ts +6 -0
  681. package/dist/runtime/monty-runtime.d.ts.map +1 -0
  682. package/dist/runtime/monty-runtime.js +485 -0
  683. package/dist/runtime/monty-runtime.js.map +7 -0
  684. package/dist/runtime/monty-source.d.ts +10 -0
  685. package/dist/runtime/monty-source.d.ts.map +1 -0
  686. package/dist/runtime/monty-values.d.ts +7 -0
  687. package/dist/runtime/monty-values.d.ts.map +1 -0
  688. package/dist/runtime/node-process-child-source.d.ts +2 -0
  689. package/dist/runtime/node-process-child-source.d.ts.map +1 -0
  690. package/dist/runtime/node-process-runtime.d.ts +10 -0
  691. package/dist/runtime/node-process-runtime.d.ts.map +1 -0
  692. package/dist/runtime/node-process-runtime.js +16 -0
  693. package/dist/runtime/node-process-runtime.js.map +7 -0
  694. package/dist/runtime/orchestration.d.ts +3 -0
  695. package/dist/runtime/orchestration.d.ts.map +1 -0
  696. package/dist/runtime/python-arguments.d.ts +2 -0
  697. package/dist/runtime/python-arguments.d.ts.map +1 -0
  698. package/dist/runtime/python-error-guidance.d.ts +6 -0
  699. package/dist/runtime/python-error-guidance.d.ts.map +1 -0
  700. package/dist/runtime/quickjs-runtime.d.ts +8 -0
  701. package/dist/runtime/quickjs-runtime.d.ts.map +1 -0
  702. package/dist/runtime/quickjs-runtime.js +15 -0
  703. package/dist/runtime/quickjs-runtime.js.map +7 -0
  704. package/dist/runtime/type-checker.d.ts +18 -0
  705. package/dist/runtime/type-checker.d.ts.map +1 -0
  706. package/dist/runtime/type-checker.js +11 -0
  707. package/dist/runtime/type-checker.js.map +7 -0
  708. package/dist/runtime/typescript-kernel.d.ts +14 -0
  709. package/dist/runtime/typescript-kernel.d.ts.map +1 -0
  710. package/dist/runtime/typescript-kernel.js +53 -0
  711. package/dist/runtime/typescript-kernel.js.map +7 -0
  712. package/dist/runtime-paths.d.ts +7 -0
  713. package/dist/runtime-paths.d.ts.map +1 -0
  714. package/dist/runtime-state-builtins.d.ts +26 -0
  715. package/dist/runtime-state-builtins.d.ts.map +1 -0
  716. package/dist/runtime-state-speculation.d.ts +16 -0
  717. package/dist/runtime-state-speculation.d.ts.map +1 -0
  718. package/dist/schema/controller.d.ts +35 -0
  719. package/dist/schema/controller.d.ts.map +1 -0
  720. package/dist/schema/policy.d.ts +2 -0
  721. package/dist/schema/policy.d.ts.map +1 -0
  722. package/dist/schema/types.d.ts +86 -0
  723. package/dist/schema/types.d.ts.map +1 -0
  724. package/dist/schema/workspace.d.ts +19 -0
  725. package/dist/schema/workspace.d.ts.map +1 -0
  726. package/dist/speculation/eligibility.d.ts +22 -0
  727. package/dist/speculation/eligibility.d.ts.map +1 -0
  728. package/dist/speculation/freshness.d.ts +10 -0
  729. package/dist/speculation/freshness.d.ts.map +1 -0
  730. package/dist/speculation/partial-json.d.ts +9 -0
  731. package/dist/speculation/partial-json.d.ts.map +1 -0
  732. package/dist/speculation/python-scanner.d.ts +7 -0
  733. package/dist/speculation/python-scanner.d.ts.map +1 -0
  734. package/dist/speculation/python-scanner.js +166 -0
  735. package/dist/speculation/python-scanner.js.map +7 -0
  736. package/dist/speculation/scanner.d.ts +13 -0
  737. package/dist/speculation/scanner.d.ts.map +1 -0
  738. package/dist/speculation/scanner.js +182 -0
  739. package/dist/speculation/scanner.js.map +7 -0
  740. package/dist/speculation/store.d.ts +41 -0
  741. package/dist/speculation/store.d.ts.map +1 -0
  742. package/dist/speculation/stream-tap.d.ts +30 -0
  743. package/dist/speculation/stream-tap.d.ts.map +1 -0
  744. package/dist/speculation/types.d.ts +44 -0
  745. package/dist/speculation/types.d.ts.map +1 -0
  746. package/dist/state/complexity.d.ts +13 -0
  747. package/dist/state/complexity.d.ts.map +1 -0
  748. package/dist/state/evidence-runner.d.ts +17 -0
  749. package/dist/state/evidence-runner.d.ts.map +1 -0
  750. package/dist/state/store.d.ts +76 -0
  751. package/dist/state/store.d.ts.map +1 -0
  752. package/dist/state/types.d.ts +165 -0
  753. package/dist/state/types.d.ts.map +1 -0
  754. package/dist/storage/retention.d.ts +22 -0
  755. package/dist/storage/retention.d.ts.map +1 -0
  756. package/dist/thinking.d.ts +19 -0
  757. package/dist/thinking.d.ts.map +1 -0
  758. package/dist/topology/control-plane.d.ts +58 -0
  759. package/dist/topology/control-plane.d.ts.map +1 -0
  760. package/dist/topology/participant-directory.d.ts +33 -0
  761. package/dist/topology/participant-directory.d.ts.map +1 -0
  762. package/dist/topology/peer-settle.d.ts +51 -0
  763. package/dist/topology/peer-settle.d.ts.map +1 -0
  764. package/dist/topology/records.d.ts +6 -0
  765. package/dist/topology/records.d.ts.map +1 -0
  766. package/dist/topology/types.d.ts +89 -0
  767. package/dist/topology/types.d.ts.map +1 -0
  768. package/dist/type-error-guidance.d.ts +3 -0
  769. package/dist/type-error-guidance.d.ts.map +1 -0
  770. package/dist/ui/arc-group.d.ts +17 -0
  771. package/dist/ui/arc-group.d.ts.map +1 -0
  772. package/dist/ui/border-status-editor.d.ts +22 -0
  773. package/dist/ui/border-status-editor.d.ts.map +1 -0
  774. package/dist/ui/code-preview-shell.d.ts +11 -0
  775. package/dist/ui/code-preview-shell.d.ts.map +1 -0
  776. package/dist/ui/code-preview.d.ts +53 -0
  777. package/dist/ui/code-preview.d.ts.map +1 -0
  778. package/dist/ui/controller.d.ts +20 -0
  779. package/dist/ui/controller.d.ts.map +1 -0
  780. package/dist/ui/conversation-chrome.d.ts +16 -0
  781. package/dist/ui/conversation-chrome.d.ts.map +1 -0
  782. package/dist/ui/conversation-chrome.js +11 -0
  783. package/dist/ui/conversation-chrome.js.map +7 -0
  784. package/dist/ui/conversation-commands.d.ts +12 -0
  785. package/dist/ui/conversation-commands.d.ts.map +1 -0
  786. package/dist/ui/conversation-history.d.ts +6 -0
  787. package/dist/ui/conversation-history.d.ts.map +1 -0
  788. package/dist/ui/conversation-host.d.ts +7 -0
  789. package/dist/ui/conversation-host.d.ts.map +1 -0
  790. package/dist/ui/conversation-host.js +9 -0
  791. package/dist/ui/conversation-host.js.map +7 -0
  792. package/dist/ui/conversation-native-reader-checkpoint.d.ts +8 -0
  793. package/dist/ui/conversation-native-reader-checkpoint.d.ts.map +1 -0
  794. package/dist/ui/conversation-native-reader-replay.d.ts +10 -0
  795. package/dist/ui/conversation-native-reader-replay.d.ts.map +1 -0
  796. package/dist/ui/conversation-native-reader.d.ts +110 -0
  797. package/dist/ui/conversation-native-reader.d.ts.map +1 -0
  798. package/dist/ui/conversation-native-reader.js +1050 -0
  799. package/dist/ui/conversation-native-reader.js.map +7 -0
  800. package/dist/ui/conversation-queue-store.d.ts +14 -0
  801. package/dist/ui/conversation-queue-store.d.ts.map +1 -0
  802. package/dist/ui/conversation-queue.d.ts +244 -0
  803. package/dist/ui/conversation-queue.d.ts.map +1 -0
  804. package/dist/ui/conversation-render.d.ts +104 -0
  805. package/dist/ui/conversation-render.d.ts.map +1 -0
  806. package/dist/ui/conversation-selection.d.ts +18 -0
  807. package/dist/ui/conversation-selection.d.ts.map +1 -0
  808. package/dist/ui/conversation-shortcut.d.ts +3 -0
  809. package/dist/ui/conversation-shortcut.d.ts.map +1 -0
  810. package/dist/ui/conversation-targets.d.ts +7 -0
  811. package/dist/ui/conversation-targets.d.ts.map +1 -0
  812. package/dist/ui/conversation-targets.js +12 -0
  813. package/dist/ui/conversation-targets.js.map +7 -0
  814. package/dist/ui/conversation-transcript.d.ts +25 -0
  815. package/dist/ui/conversation-transcript.d.ts.map +1 -0
  816. package/dist/ui/conversation.d.ts +219 -0
  817. package/dist/ui/conversation.d.ts.map +1 -0
  818. package/dist/ui/conversation.js +2861 -0
  819. package/dist/ui/conversation.js.map +7 -0
  820. package/dist/ui/core-tool-render.d.ts +20 -0
  821. package/dist/ui/core-tool-render.d.ts.map +1 -0
  822. package/dist/ui/dashboard-detail.d.ts +68 -0
  823. package/dist/ui/dashboard-detail.d.ts.map +1 -0
  824. package/dist/ui/dashboard-fabric-graph.d.ts +50 -0
  825. package/dist/ui/dashboard-fabric-graph.d.ts.map +1 -0
  826. package/dist/ui/dashboard-graph-controller.d.ts +52 -0
  827. package/dist/ui/dashboard-graph-controller.d.ts.map +1 -0
  828. package/dist/ui/dashboard-modal-controller.d.ts +36 -0
  829. package/dist/ui/dashboard-modal-controller.d.ts.map +1 -0
  830. package/dist/ui/dashboard-model.d.ts +111 -0
  831. package/dist/ui/dashboard-model.d.ts.map +1 -0
  832. package/dist/ui/dashboard-presentation.d.ts +6 -0
  833. package/dist/ui/dashboard-presentation.d.ts.map +1 -0
  834. package/dist/ui/dashboard.d.ts +156 -0
  835. package/dist/ui/dashboard.d.ts.map +1 -0
  836. package/dist/ui/dashboard.js +4622 -0
  837. package/dist/ui/dashboard.js.map +7 -0
  838. package/dist/ui/diff-background.d.ts +12 -0
  839. package/dist/ui/diff-background.d.ts.map +1 -0
  840. package/dist/ui/dynamic-border.d.ts +8 -0
  841. package/dist/ui/dynamic-border.d.ts.map +1 -0
  842. package/dist/ui/escape-halt.d.ts +11 -0
  843. package/dist/ui/escape-halt.d.ts.map +1 -0
  844. package/dist/ui/fabric-actor-delivery-selector.d.ts +17 -0
  845. package/dist/ui/fabric-actor-delivery-selector.d.ts.map +1 -0
  846. package/dist/ui/fabric-actor-tool-selector.d.ts +22 -0
  847. package/dist/ui/fabric-actor-tool-selector.d.ts.map +1 -0
  848. package/dist/ui/fabric-code-parser.d.ts +9 -0
  849. package/dist/ui/fabric-code-parser.d.ts.map +1 -0
  850. package/dist/ui/fabric-host-event-selector.d.ts +29 -0
  851. package/dist/ui/fabric-host-event-selector.d.ts.map +1 -0
  852. package/dist/ui/fabric-model-selector.d.ts +64 -0
  853. package/dist/ui/fabric-model-selector.d.ts.map +1 -0
  854. package/dist/ui/fabric-render.d.ts +113 -0
  855. package/dist/ui/fabric-render.d.ts.map +1 -0
  856. package/dist/ui/fabric-thinking-selector.d.ts +26 -0
  857. package/dist/ui/fabric-thinking-selector.d.ts.map +1 -0
  858. package/dist/ui/fabric-title-hint.d.ts +3 -0
  859. package/dist/ui/fabric-title-hint.d.ts.map +1 -0
  860. package/dist/ui/format.d.ts +9 -0
  861. package/dist/ui/format.d.ts.map +1 -0
  862. package/dist/ui/handoff-completion.d.ts +3 -0
  863. package/dist/ui/handoff-completion.d.ts.map +1 -0
  864. package/dist/ui/highlight.d.ts +69 -0
  865. package/dist/ui/highlight.d.ts.map +1 -0
  866. package/dist/ui/model-picker.d.ts +46 -0
  867. package/dist/ui/model-picker.d.ts.map +1 -0
  868. package/dist/ui/model-picker.js +17 -0
  869. package/dist/ui/model-picker.js.map +7 -0
  870. package/dist/ui/preview-lines.d.ts +16 -0
  871. package/dist/ui/preview-lines.d.ts.map +1 -0
  872. package/dist/ui/row-balance.d.ts +29 -0
  873. package/dist/ui/row-balance.d.ts.map +1 -0
  874. package/dist/ui/settings-component.d.ts +26 -0
  875. package/dist/ui/settings-component.d.ts.map +1 -0
  876. package/dist/ui/settings-rpc.d.ts +15 -0
  877. package/dist/ui/settings-rpc.d.ts.map +1 -0
  878. package/dist/ui/settings-section-context.d.ts +18 -0
  879. package/dist/ui/settings-section-context.d.ts.map +1 -0
  880. package/dist/ui/settings-sections-agents.d.ts +5 -0
  881. package/dist/ui/settings-sections-agents.d.ts.map +1 -0
  882. package/dist/ui/settings-sections-execution.d.ts +8 -0
  883. package/dist/ui/settings-sections-execution.d.ts.map +1 -0
  884. package/dist/ui/settings-sections-lifecycle.d.ts +6 -0
  885. package/dist/ui/settings-sections-lifecycle.d.ts.map +1 -0
  886. package/dist/ui/settings-sections-presentation.d.ts +6 -0
  887. package/dist/ui/settings-sections-presentation.d.ts.map +1 -0
  888. package/dist/ui/settings-sections.d.ts +12 -0
  889. package/dist/ui/settings-sections.d.ts.map +1 -0
  890. package/dist/ui/settings-submenus.d.ts +74 -0
  891. package/dist/ui/settings-submenus.d.ts.map +1 -0
  892. package/dist/ui/settings-values.d.ts +63 -0
  893. package/dist/ui/settings-values.d.ts.map +1 -0
  894. package/dist/ui/settings.d.ts +21 -0
  895. package/dist/ui/settings.d.ts.map +1 -0
  896. package/dist/ui/settings.js +1985 -0
  897. package/dist/ui/settings.js.map +7 -0
  898. package/dist/ui/shell-hang-keys.d.ts +11 -0
  899. package/dist/ui/shell-hang-keys.d.ts.map +1 -0
  900. package/dist/ui/shiki-language.d.ts +7 -0
  901. package/dist/ui/shiki-language.d.ts.map +1 -0
  902. package/dist/ui/shiki-theme.d.ts +7 -0
  903. package/dist/ui/shiki-theme.d.ts.map +1 -0
  904. package/dist/ui/snapshot.d.ts +17 -0
  905. package/dist/ui/snapshot.d.ts.map +1 -0
  906. package/dist/ui/spinner.d.ts +6 -0
  907. package/dist/ui/spinner.d.ts.map +1 -0
  908. package/dist/ui/state-file-preview.d.ts +13 -0
  909. package/dist/ui/state-file-preview.d.ts.map +1 -0
  910. package/dist/ui/structured.d.ts +9 -0
  911. package/dist/ui/structured.d.ts.map +1 -0
  912. package/dist/ui/tool-call-timing.d.ts +2 -0
  913. package/dist/ui/tool-call-timing.d.ts.map +1 -0
  914. package/dist/ui/tool-display.d.ts +8 -0
  915. package/dist/ui/tool-display.d.ts.map +1 -0
  916. package/dist/ui/topology.d.ts +162 -0
  917. package/dist/ui/topology.d.ts.map +1 -0
  918. package/dist/ui/transcript-parser.d.ts +18 -0
  919. package/dist/ui/transcript-parser.d.ts.map +1 -0
  920. package/dist/ui/transcript-reader.d.ts +10 -0
  921. package/dist/ui/transcript-reader.d.ts.map +1 -0
  922. package/dist/ui/transcript-sanitization.d.ts +14 -0
  923. package/dist/ui/transcript-sanitization.d.ts.map +1 -0
  924. package/dist/ui/transcript.d.ts +52 -0
  925. package/dist/ui/transcript.d.ts.map +1 -0
  926. package/dist/ui/types.d.ts +84 -0
  927. package/dist/ui/types.d.ts.map +1 -0
  928. package/dist/ui/widget.d.ts +16 -0
  929. package/dist/ui/widget.d.ts.map +1 -0
  930. package/dist/ui/word-diff/alignment.d.ts +6 -0
  931. package/dist/ui/word-diff/alignment.d.ts.map +1 -0
  932. package/dist/ui/word-diff/change-block.d.ts +18 -0
  933. package/dist/ui/word-diff/change-block.d.ts.map +1 -0
  934. package/dist/ui/word-diff/changed-line.d.ts +14 -0
  935. package/dist/ui/word-diff/changed-line.d.ts.map +1 -0
  936. package/dist/ui/word-diff/emphasis.d.ts +9 -0
  937. package/dist/ui/word-diff/emphasis.d.ts.map +1 -0
  938. package/dist/ui/word-diff/line-emphasis.d.ts +7 -0
  939. package/dist/ui/word-diff/line-emphasis.d.ts.map +1 -0
  940. package/dist/ui/word-diff/line-matching.d.ts +10 -0
  941. package/dist/ui/word-diff/line-matching.d.ts.map +1 -0
  942. package/dist/ui/word-diff/line-similarity.d.ts +16 -0
  943. package/dist/ui/word-diff/line-similarity.d.ts.map +1 -0
  944. package/dist/ui/word-diff/normalize.d.ts +3 -0
  945. package/dist/ui/word-diff/normalize.d.ts.map +1 -0
  946. package/dist/ui/word-diff/parse.d.ts +17 -0
  947. package/dist/ui/word-diff/parse.d.ts.map +1 -0
  948. package/dist/ui/word-diff/range-refinement.d.ts +5 -0
  949. package/dist/ui/word-diff/range-refinement.d.ts.map +1 -0
  950. package/dist/ui/word-diff/ranges.d.ts +11 -0
  951. package/dist/ui/word-diff/ranges.d.ts.map +1 -0
  952. package/dist/ui/word-diff/smart-filter.d.ts +3 -0
  953. package/dist/ui/word-diff/smart-filter.d.ts.map +1 -0
  954. package/dist/ui/word-diff/sparse-line-matching.d.ts +25 -0
  955. package/dist/ui/word-diff/sparse-line-matching.d.ts.map +1 -0
  956. package/dist/ui/word-diff/text-boundaries.d.ts +11 -0
  957. package/dist/ui/word-diff/text-boundaries.d.ts.map +1 -0
  958. package/dist/ui/word-diff/token-alignment.d.ts +9 -0
  959. package/dist/ui/word-diff/token-alignment.d.ts.map +1 -0
  960. package/dist/ui/word-diff/token-text-refinement.d.ts +4 -0
  961. package/dist/ui/word-diff/token-text-refinement.d.ts.map +1 -0
  962. package/dist/ui/word-diff/tokens.d.ts +16 -0
  963. package/dist/ui/word-diff/tokens.d.ts.map +1 -0
  964. package/dist/ui/word-diff/types.d.ts +10 -0
  965. package/dist/ui/word-diff/types.d.ts.map +1 -0
  966. package/dist/util.d.ts +3 -0
  967. package/dist/util.d.ts.map +1 -0
  968. package/dist/worker/model-control.d.ts +14 -0
  969. package/dist/worker/model-control.d.ts.map +1 -0
  970. package/dist/worker/model-control.js +118 -0
  971. package/dist/worker/model-control.js.map +7 -0
  972. package/dist/worker/options.d.ts +3 -0
  973. package/dist/worker/options.d.ts.map +1 -0
  974. package/dist/worker/options.js +156 -0
  975. package/dist/worker/options.js.map +7 -0
  976. package/dist/worker/run-record.d.ts +22 -0
  977. package/dist/worker/run-record.d.ts.map +1 -0
  978. package/dist/worker/run-record.js +124 -0
  979. package/dist/worker/run-record.js.map +7 -0
  980. package/dist/worker/session-export.d.ts +45 -0
  981. package/dist/worker/session-export.d.ts.map +1 -0
  982. package/dist/worker/session-export.js +91 -0
  983. package/dist/worker/session-export.js.map +7 -0
  984. package/dist/worker.d.ts +3 -0
  985. package/dist/worker.d.ts.map +1 -0
  986. package/dist/worker.js +1074 -0
  987. package/dist/worker.js.map +7 -0
  988. package/docs/agents.md +618 -0
  989. package/docs/architecture.md +141 -0
  990. package/docs/audit-trace.md +116 -0
  991. package/docs/certification.md +166 -0
  992. package/docs/compaction.md +345 -0
  993. package/docs/component-calculus.md +191 -0
  994. package/docs/components.md +330 -0
  995. package/docs/configuration.md +529 -0
  996. package/docs/entropy.md +214 -0
  997. package/docs/interface.md +210 -0
  998. package/docs/jev.md +289 -0
  999. package/docs/kernels.md +186 -0
  1000. package/docs/memory-recall.md +664 -0
  1001. package/docs/programmatic-compaction.md +205 -0
  1002. package/docs/provider-component-calculus.md +378 -0
  1003. package/docs/providers.md +163 -0
  1004. package/docs/repairs.md +90 -0
  1005. package/docs/residency-runtime.md +82 -0
  1006. package/docs/schema-enforcement.md +166 -0
  1007. package/docs/skills.md +50 -0
  1008. package/docs/speculation.md +171 -0
  1009. package/docs/state-layer.md +197 -0
  1010. package/package.json +135 -0
  1011. package/skillsets/python/fabric-advisor/SKILL.md +29 -0
  1012. package/skillsets/python/fabric-ambient/SKILL.md +44 -0
  1013. package/skillsets/python/fabric-ambient/references/setup.md +67 -0
  1014. package/skillsets/python/fabric-council/SKILL.md +54 -0
  1015. package/skillsets/python/fabric-exec/SKILL.md +74 -0
  1016. package/skillsets/python/fabric-exec/references/agents.md +65 -0
  1017. package/skillsets/python/fabric-exec/references/mcp.md +23 -0
  1018. package/skillsets/python/fabric-exec/references/mesh.md +27 -0
  1019. package/skillsets/python/fabric-fusion/SKILL.md +112 -0
  1020. package/skillsets/python/fabric-guide/SKILL.md +29 -0
  1021. package/skillsets/python/fabric-jev/SKILL.md +162 -0
  1022. package/skillsets/python/fabric-rlm/SKILL.md +120 -0
  1023. package/skillsets/python/fabric-schema/SKILL.md +55 -0
  1024. package/skillsets/python/fabric-spec/SKILL.md +42 -0
  1025. package/skillsets/python/fabric-supervisor/SKILL.md +37 -0
  1026. package/skillsets/python/fabric-swarm/SKILL.md +40 -0
  1027. package/skillsets/python/fabric-workflow/SKILL.md +62 -0
  1028. package/skillsets/typescript/fabric-advisor/SKILL.md +29 -0
  1029. package/skillsets/typescript/fabric-ambient/SKILL.md +44 -0
  1030. package/skillsets/typescript/fabric-ambient/references/setup.md +90 -0
  1031. package/skillsets/typescript/fabric-council/SKILL.md +94 -0
  1032. package/skillsets/typescript/fabric-exec/SKILL.md +142 -0
  1033. package/skillsets/typescript/fabric-exec/references/agents.md +218 -0
  1034. package/skillsets/typescript/fabric-exec/references/mcp.md +49 -0
  1035. package/skillsets/typescript/fabric-exec/references/mesh.md +51 -0
  1036. package/skillsets/typescript/fabric-fusion/SKILL.md +332 -0
  1037. package/skillsets/typescript/fabric-guide/SKILL.md +29 -0
  1038. package/skillsets/typescript/fabric-jev/SKILL.md +159 -0
  1039. package/skillsets/typescript/fabric-rlm/SKILL.md +284 -0
  1040. package/skillsets/typescript/fabric-schema/SKILL.md +121 -0
  1041. package/skillsets/typescript/fabric-spec/SKILL.md +42 -0
  1042. package/skillsets/typescript/fabric-supervisor/SKILL.md +37 -0
  1043. package/skillsets/typescript/fabric-swarm/SKILL.md +80 -0
  1044. package/skillsets/typescript/fabric-workflow/SKILL.md +133 -0
@@ -0,0 +1,2181 @@
1
+ import {
2
+ DEFAULT_HOT_SESSIONS,
3
+ DEFAULT_REGEX_MAX_HAYSTACK_BYTES,
4
+ DEFAULT_REGEX_MAX_HAYSTACK_TERMS,
5
+ DEFAULT_REGEX_MAX_PATTERN_BYTES,
6
+ DEFAULT_REGEX_TIMEOUT_MS,
7
+ MEMORY_CACHE_VERSION,
8
+ classifySessionTiers,
9
+ digestPolicy,
10
+ fingerprintSource,
11
+ fitDigestCache,
12
+ loadTieredIndex,
13
+ reconstructRecordsLineage,
14
+ reconstructSessionLineage,
15
+ searchMemoryIndex,
16
+ shardPolicy
17
+ } from "./chunk-7A6NVHB5.js";
18
+ import {
19
+ compareLexical,
20
+ foldSessionDigest,
21
+ normalizeMemoryPhrase,
22
+ tokenizeLexical
23
+ } from "./chunk-U5FYOMG5.js";
24
+ import {
25
+ AmbiguousSessionError,
26
+ enumerateAllSessions,
27
+ resolveScope,
28
+ resolveSessionTarget
29
+ } from "./chunk-MGDLRV2R.js";
30
+ import {
31
+ expandSessionEntriesChecked,
32
+ normalizeRecords,
33
+ normalizeSession
34
+ } from "./chunk-XT4346N7.js";
35
+ import {
36
+ actionArgNormalizer
37
+ } from "./chunk-NQOEHX62.js";
38
+
39
+ // src/memory/context.ts
40
+ var RECALL_DEFAULT_PAGE_SIZE = 10;
41
+ var RECALL_MAX_PAGE_SIZE = 50;
42
+ var RECALL_DEFAULT_SNIPPET_CHARS = 480;
43
+ var RECALL_MAX_SNIPPET_CHARS = 2e3;
44
+ var RECALL_MAX_RESPONSE_CHARS = 3e4;
45
+ var boundedMetadata = (value, max = 512) => {
46
+ if (value === void 0 || value === null) return null;
47
+ return value.length <= max ? value : `${value.slice(0, Math.max(1, max - 1))}\u2026`;
48
+ };
49
+ var safeSlice = (text, start, end) => {
50
+ let safeStart = Math.max(0, start);
51
+ let safeEnd = Math.min(text.length, end);
52
+ const startCode = text.charCodeAt(safeStart);
53
+ if (safeStart > 0 && startCode >= 56320 && startCode <= 57343) safeStart += 1;
54
+ const endCode = text.charCodeAt(safeEnd - 1);
55
+ if (safeEnd < text.length && endCode >= 55296 && endCode <= 56319) safeEnd -= 1;
56
+ return text.slice(safeStart, safeEnd);
57
+ };
58
+ var snippetAnchor = (text, query, queryMode) => {
59
+ if (!query) return 0;
60
+ const normalized = normalizeMemoryPhrase(text);
61
+ if (queryMode === "phrase") {
62
+ const phrase = normalizeMemoryPhrase(query.trim());
63
+ return Math.max(0, normalized.indexOf(phrase));
64
+ }
65
+ if (queryMode === "literal") {
66
+ const terms = [...new Set(tokenizeLexical(query))].sort(
67
+ (left, right) => right.length - left.length || left.localeCompare(right)
68
+ );
69
+ for (const term of terms) {
70
+ const index = normalized.indexOf(term);
71
+ if (index >= 0) return index;
72
+ }
73
+ }
74
+ return 0;
75
+ };
76
+ var makeSnippet = (text, query, queryMode, maxChars) => {
77
+ if (text.length <= maxChars) return { text, truncated: false };
78
+ const anchor = snippetAnchor(text, query, queryMode);
79
+ const leadingContext = Math.floor(maxChars / 3);
80
+ let start = Math.max(0, anchor - leadingContext);
81
+ let end = Math.min(text.length, start + maxChars);
82
+ if (end - start < maxChars) start = Math.max(0, end - maxChars);
83
+ const body = safeSlice(text, start, end);
84
+ return {
85
+ text: `${start > 0 ? "\u2026" : ""}${body}${end < text.length ? "\u2026" : ""}`,
86
+ truncated: true
87
+ };
88
+ };
89
+ var sourceFromSegment = (segment, sourceId) => ({
90
+ sessionId: boundedMetadata(segment.sessionId) ?? "",
91
+ sessionFile: segment.sessionFile,
92
+ ...sourceId ? { source: sourceId } : {},
93
+ sourceHash: segment.sourceHash,
94
+ branches: segment.branches,
95
+ lineageFingerprint: segment.lineageFingerprint,
96
+ tier: segment.tier
97
+ });
98
+ var sourceFromDigest = (digest, sourceId) => ({
99
+ sessionId: boundedMetadata(digest.sessionId) ?? "",
100
+ sessionFile: digest.sessionFile,
101
+ ...sourceId ? { source: sourceId } : {},
102
+ sourceHash: digest.sourceHash,
103
+ branches: digest.branches,
104
+ lineageFingerprint: digest.lineageFingerprint,
105
+ tier: "cold"
106
+ });
107
+ var expandArgs = (source, entry) => ({
108
+ session: source.sessionFile,
109
+ ...source.source ? { source: source.source } : {},
110
+ expectedSourceHash: source.sourceHash,
111
+ expectedLineageFingerprint: source.lineageFingerprint,
112
+ branches: source.branches,
113
+ indices: [entry.index]
114
+ });
115
+ var entryHit = (segment, item, query, queryMode, snippetChars, sourceId) => {
116
+ const entry = item.entry;
117
+ const source = sourceFromSegment(segment, sourceId);
118
+ const snippet = makeSnippet(entry.text, query, queryMode, snippetChars);
119
+ return {
120
+ kind: "entry",
121
+ sessionId: source.sessionId,
122
+ tier: source.tier,
123
+ index: entry.index,
124
+ entryId: boundedMetadata(entry.entryId),
125
+ parentId: boundedMetadata(entry.parentId),
126
+ operationAddress: boundedMetadata(entry.operationAddress),
127
+ type: boundedMetadata(entry.type) ?? "entry",
128
+ role: boundedMetadata(entry.role),
129
+ tool: boundedMetadata(entry.toolName),
130
+ ref: boundedMetadata(entry.ref),
131
+ provider: boundedMetadata(entry.provider),
132
+ action: boundedMetadata(entry.action),
133
+ timestamp: entry.timestamp,
134
+ isError: entry.isError,
135
+ ...entry.outcome ? { outcome: entry.outcome } : {},
136
+ score: item.score,
137
+ snippet: snippet.text,
138
+ truncated: snippet.truncated || entry.truncated,
139
+ follow: { ref: "memory.expand", args: expandArgs(source, entry) }
140
+ };
141
+ };
142
+ var hydrationArgs = (digest, request) => {
143
+ const { offset: _offset, entryRange: _entryRange, ...base } = request;
144
+ return {
145
+ ...base,
146
+ scope: `session:${digest.sessionFile}`,
147
+ branches: digest.branches,
148
+ expectedSourceHash: digest.sourceHash,
149
+ expectedLineageFingerprint: digest.lineageFingerprint
150
+ };
151
+ };
152
+ var sessionHit = (digest, request, sourceId) => {
153
+ const source = sourceFromDigest(digest, sourceId);
154
+ return {
155
+ kind: "session",
156
+ sessionId: source.sessionId,
157
+ tier: "cold",
158
+ cwd: boundedMetadata(digest.cwd, 2048) ?? "",
159
+ lastTimestamp: digest.lastTs,
160
+ score: digest.score,
161
+ matchedTerms: digest.matchedTerms,
162
+ matchedStructuralEntries: digest.matchedStructuralEntries,
163
+ follow: { ref: "memory.recall", args: hydrationArgs(digest, request) }
164
+ };
165
+ };
166
+ var recallCandidateCache = /* @__PURE__ */ new WeakMap();
167
+ var flattenCandidates = (result) => {
168
+ const cached = recallCandidateCache.get(result);
169
+ if (cached) return cached;
170
+ const candidates = [];
171
+ for (const item of result.items) {
172
+ if (item.kind === "digest") {
173
+ candidates.push({ kind: "session", digest: item.digest });
174
+ continue;
175
+ }
176
+ for (const entry of item.segment.entries) {
177
+ if (entry.matched) candidates.push({ kind: "entry", segment: item.segment, item: entry });
178
+ }
179
+ }
180
+ candidates.sort((left, right) => {
181
+ const leftScore = left.kind === "entry" ? left.item.score : left.digest.score;
182
+ const rightScore = right.kind === "entry" ? right.item.score : right.digest.score;
183
+ if (rightScore !== leftScore) return rightScore - leftScore;
184
+ const leftMtime = left.kind === "entry" ? left.segment.sessionMtime : left.digest.sessionMtime;
185
+ const rightMtime = right.kind === "entry" ? right.segment.sessionMtime : right.digest.sessionMtime;
186
+ if (rightMtime !== leftMtime) return rightMtime - leftMtime;
187
+ if (left.kind !== right.kind) return left.kind === "entry" ? -1 : 1;
188
+ if (left.kind === "entry" && right.kind === "entry") {
189
+ if (left.item.entry.index !== right.item.entry.index) {
190
+ return left.item.entry.index - right.item.entry.index;
191
+ }
192
+ return compareLexical(left.segment.sessionFile, right.segment.sessionFile);
193
+ }
194
+ if (left.kind === "session" && right.kind === "session") {
195
+ return compareLexical(left.digest.sessionFile, right.digest.sessionFile);
196
+ }
197
+ return 0;
198
+ });
199
+ recallCandidateCache.set(result, candidates);
200
+ return candidates;
201
+ };
202
+ var materializeCandidate = (candidate, query, queryMode, snippetChars, request, sourceId) => candidate.kind === "session" ? sessionHit(candidate.digest, request, sourceId) : entryHit(candidate.segment, candidate.item, query, queryMode, snippetChars, sourceId);
203
+ var canonicalNextArgs = (request, offset) => {
204
+ const { offset: _offset, ...base } = request;
205
+ return { ...base, offset };
206
+ };
207
+ var presentRecall = (input) => {
208
+ const candidates = flattenCandidates(input.result);
209
+ const start = input.offset ?? 0;
210
+ let selected = candidates.slice(start, start + input.pageSize);
211
+ const build = (pageCandidates) => {
212
+ const hits = pageCandidates.map(
213
+ (candidate) => materializeCandidate(
214
+ candidate,
215
+ input.query,
216
+ input.queryMode,
217
+ input.snippetChars,
218
+ input.requestArgs,
219
+ input.requestArgs.source
220
+ )
221
+ );
222
+ return {
223
+ total: candidates.length,
224
+ hits,
225
+ next: start + hits.length < candidates.length ? { ref: "memory.recall", args: canonicalNextArgs(input.requestArgs, start + hits.length) } : null,
226
+ coverage: input.coverage
227
+ };
228
+ };
229
+ let response = build(selected);
230
+ while (selected.length > 1 && JSON.stringify(response).length > RECALL_MAX_RESPONSE_CHARS) {
231
+ selected = selected.slice(0, -1);
232
+ response = build(selected);
233
+ }
234
+ return response;
235
+ };
236
+
237
+ // src/memory/request-limits.ts
238
+ var EXPAND_DEFAULT_MAX_CHARS = 2e4;
239
+ var EXPAND_MAX_CHARS = 24e3;
240
+ var EXPAND_DEFAULT_MAX_ENTRIES = 10;
241
+ var EXPAND_MAX_ENTRIES = 20;
242
+ var EXPAND_MAX_CONTEXT = 100;
243
+ var EXPAND_MAX_EXACT_SELECTORS = 100;
244
+ var SESSIONS_MAX = 500;
245
+
246
+ // src/memory/request-context.ts
247
+ import path from "node:path";
248
+ var parseBranches = (value, action) => {
249
+ if (value === void 0) return "active";
250
+ if (value === "active" || value === "all") return value;
251
+ throw new Error(`${action} branches must be "active" or "all"`);
252
+ };
253
+ var resolveIndexOptions = (config, agentDir, branches, liveBranchForFile) => ({
254
+ indexDir: config.indexDir ?? `${agentDir}/fabric/memory-index`,
255
+ maxEntryChars: config.maxEntryChars,
256
+ branches,
257
+ indexThinking: config.indexThinking ?? false,
258
+ indexToolOutput: config.indexToolOutput ?? true,
259
+ ...liveBranchForFile ? { liveBranchForFile } : {},
260
+ hotSessions: config.hotSessions ?? DEFAULT_HOT_SESSIONS,
261
+ digestTerms: config.digestTerms ?? 200,
262
+ ...config.maxColdVocabularyBytes === void 0 ? {} : { maxColdVocabularyBytes: config.maxColdVocabularyBytes },
263
+ ...config.maxColdCacheBytes === void 0 ? {} : { maxColdCacheBytes: config.maxColdCacheBytes },
264
+ ...config.maxSyncSessions === void 0 ? {} : { maxSyncSessions: config.maxSyncSessions },
265
+ ...config.maxSyncSourceBytes === void 0 ? {} : { maxSyncSourceBytes: config.maxSyncSourceBytes },
266
+ ...config.maxCacheCleanupFiles === void 0 ? {} : { maxCacheCleanupFiles: config.maxCacheCleanupFiles }
267
+ });
268
+ var resolveTierRefs = (refs, context) => {
269
+ const all = enumerateAllSessions(context.agentDir, Number.MAX_SAFE_INTEGER);
270
+ const known = new Set(all.map((ref) => ref.file));
271
+ for (const ref of refs) {
272
+ if (!known.has(ref.file)) all.push(ref);
273
+ }
274
+ return all;
275
+ };
276
+ var resolveRefs = (scope, context, boundedBrowse) => {
277
+ const effectiveScope = scope ?? "session";
278
+ const input = {
279
+ agentDir: context.agentDir,
280
+ cwd: context.cwd,
281
+ scope: effectiveScope,
282
+ maxSessions: boundedBrowse ? context.config.maxSessions : Number.MAX_SAFE_INTEGER
283
+ };
284
+ if (context.sessionId) input.sessionId = context.sessionId;
285
+ if (context.sessionFile) input.sessionFile = context.sessionFile;
286
+ return resolveScope(input);
287
+ };
288
+ var liveBranchResolver = (context) => {
289
+ if (!context.sessionFile || !context.getLiveBranch) return void 0;
290
+ const current = path.resolve(context.sessionFile);
291
+ return (sessionFile) => path.resolve(sessionFile) === current ? context.getLiveBranch?.() : void 0;
292
+ };
293
+ var stalePointerError = (sessionFile, expectedSourceHash, actualSourceHash, expectedLineageFingerprint, actualLineageFingerprint) => ({
294
+ code: "stale_pointer",
295
+ message: expectedLineageFingerprint !== void 0 && expectedLineageFingerprint !== actualLineageFingerprint ? "Session active lineage changed after the pointer was issued." : "Session source changed after the pointer was issued.",
296
+ sessionFile,
297
+ ...expectedSourceHash === void 0 ? {} : { expectedSourceHash },
298
+ actualSourceHash,
299
+ ...expectedLineageFingerprint === void 0 ? {} : { expectedLineageFingerprint },
300
+ ...actualLineageFingerprint === void 0 ? {} : { actualLineageFingerprint }
301
+ });
302
+ var addressError = (message, entryCount) => ({
303
+ code: "index_out_of_bounds",
304
+ message,
305
+ ...entryCount === void 0 ? {} : { entryCount }
306
+ });
307
+ var recallFailure = (error) => ({
308
+ total: 0,
309
+ hits: [],
310
+ next: null,
311
+ coverage: {
312
+ complete: false,
313
+ indexedSessions: 0,
314
+ eligibleSessions: 0,
315
+ staleSessions: 0,
316
+ incompleteSessions: 0,
317
+ reasons: [error.code]
318
+ },
319
+ error
320
+ });
321
+
322
+ // src/memory/request-cache.ts
323
+ import path3 from "node:path";
324
+
325
+ // src/memory/source-observation.ts
326
+ import crypto from "node:crypto";
327
+ import fs from "node:fs";
328
+ import path2 from "node:path";
329
+ var sourceIdentity = (file) => {
330
+ try {
331
+ const stat = fs.statSync(file, { bigint: true });
332
+ if (!stat.isFile()) return null;
333
+ return {
334
+ device: stat.dev,
335
+ inode: stat.ino,
336
+ size: stat.size,
337
+ modifiedAt: stat.mtimeNs,
338
+ changedAt: stat.ctimeNs
339
+ };
340
+ } catch {
341
+ return null;
342
+ }
343
+ };
344
+ var sameSourceIdentity = (left, right) => left.device === right.device && left.inode === right.inode && left.size === right.size && left.modifiedAt === right.modifiedAt && left.changedAt === right.changedAt;
345
+ var liveBranchSignature = (branch) => branch ? `${branch.leafId ?? ""}\0${branch.entries.length}` : null;
346
+ var observeSource = (file, branches, liveBranch) => {
347
+ const identity = sourceIdentity(file);
348
+ if (!identity) return null;
349
+ return {
350
+ file: path2.resolve(file),
351
+ identity,
352
+ liveBranchSignature: branches === "active" ? liveBranchSignature(liveBranch) : null
353
+ };
354
+ };
355
+ var hostIdentity = (revision, sourceHash) => {
356
+ const digest = crypto.createHash("sha256").update(`${revision}\0${sourceHash}`).digest("hex");
357
+ return {
358
+ device: BigInt(parseInt(digest.slice(0, 8), 16)),
359
+ inode: BigInt(parseInt(digest.slice(8, 16), 16)),
360
+ size: BigInt(parseInt(digest.slice(16, 24), 16)),
361
+ modifiedAt: BigInt(parseInt(digest.slice(24, 32), 16)),
362
+ changedAt: BigInt(parseInt(digest.slice(32, 40), 16))
363
+ };
364
+ };
365
+ var observeHostSource = (displayKey, revision, sourceHash) => ({
366
+ file: displayKey,
367
+ identity: hostIdentity(revision, sourceHash),
368
+ liveBranchSignature: null
369
+ });
370
+ var observeSources = (refs, branches, liveResolver) => {
371
+ const observations = [];
372
+ for (const ref of refs) {
373
+ const liveBranch = branches === "active" ? liveResolver?.(ref.file) : void 0;
374
+ const observation = observeSource(ref.file, branches, liveBranch);
375
+ if (!observation) return null;
376
+ observations.push(observation);
377
+ }
378
+ return observations;
379
+ };
380
+ var sameSourceObservation = (left, right) => left.file === right.file && sameSourceIdentity(left.identity, right.identity) && left.liveBranchSignature === right.liveBranchSignature;
381
+ var sameSourceObservations = (left, right) => left.length === right.length && left.every(
382
+ (item, index) => sameSourceObservation(item, right[index])
383
+ );
384
+
385
+ // src/memory/request-cache.ts
386
+ var CONTINUATION_CACHE_TTL_MS = 5 * 6e4;
387
+ var EXPANSION_SNAPSHOT_LIMIT = 2;
388
+ var EXPANSION_SELECTION_LIMIT = 16;
389
+ var recallContinuationKey = (args) => JSON.stringify([
390
+ args.query ?? null,
391
+ args.queryMode ?? "literal",
392
+ args.queryMatch ?? null,
393
+ args.expectedSourceHash ?? null,
394
+ args.expectedLineageFingerprint ?? null,
395
+ args.branches ?? "active",
396
+ args.scope ?? "session",
397
+ args.pageSize ?? RECALL_DEFAULT_PAGE_SIZE,
398
+ args.snippetChars ?? RECALL_DEFAULT_SNIPPET_CHARS,
399
+ args.role ?? null,
400
+ args.tool ?? null,
401
+ args.ref ?? null,
402
+ args.provider ?? null,
403
+ args.action ?? null,
404
+ args.outcome ?? null,
405
+ args.since ?? null,
406
+ args.until ?? null,
407
+ args.entryRange ? [args.entryRange.first, args.entryRange.last] : null
408
+ ]);
409
+ var expansionSnapshotKey = (file, branches) => `${path3.resolve(file)}\0${branches}`;
410
+ var expansionSelectionKey = (selection) => JSON.stringify([
411
+ selection.indices ?? null,
412
+ selection.entryIds ?? null,
413
+ selection.operationAddresses ?? null,
414
+ selection.entryRange ? [selection.entryRange.first, selection.entryRange.last] : null,
415
+ selection.before ?? 0,
416
+ selection.after ?? 0
417
+ ]);
418
+ var MemoryRequestCache = class {
419
+ recallContinuation;
420
+ expansionSnapshots = /* @__PURE__ */ new Map();
421
+ cachedRecallContinuation(key, observations) {
422
+ const cached = this.recallContinuation;
423
+ if (!cached || cached.key !== key) return void 0;
424
+ if (!observations || Date.now() - cached.touchedAt > CONTINUATION_CACHE_TTL_MS || !sameSourceObservations(cached.observations, observations)) {
425
+ this.recallContinuation = void 0;
426
+ return void 0;
427
+ }
428
+ cached.touchedAt = Date.now();
429
+ return cached;
430
+ }
431
+ rememberRecallContinuation(cached) {
432
+ this.recallContinuation = cached;
433
+ }
434
+ forgetRecallContinuation(cached) {
435
+ if (this.recallContinuation === cached) this.recallContinuation = void 0;
436
+ }
437
+ cachedExpansionSnapshot(file, branches, observation) {
438
+ const key = expansionSnapshotKey(file, branches);
439
+ const cached = this.expansionSnapshots.get(key);
440
+ if (!cached) return void 0;
441
+ if (!observation || Date.now() - cached.touchedAt > CONTINUATION_CACHE_TTL_MS || !sameSourceObservation(cached.observation, observation)) {
442
+ this.expansionSnapshots.delete(key);
443
+ return void 0;
444
+ }
445
+ cached.touchedAt = Date.now();
446
+ this.expansionSnapshots.delete(key);
447
+ this.expansionSnapshots.set(key, cached);
448
+ return cached;
449
+ }
450
+ rememberExpansionSnapshot(snapshot) {
451
+ const key = expansionSnapshotKey(snapshot.file, snapshot.branches);
452
+ this.expansionSnapshots.delete(key);
453
+ this.expansionSnapshots.set(key, snapshot);
454
+ while (this.expansionSnapshots.size > EXPANSION_SNAPSHOT_LIMIT) {
455
+ const oldest = this.expansionSnapshots.keys().next().value;
456
+ if (oldest === void 0) break;
457
+ this.expansionSnapshots.delete(oldest);
458
+ }
459
+ }
460
+ rememberExpansionSelection(snapshot, keys, selection) {
461
+ for (const key of new Set(keys)) {
462
+ snapshot.selections.delete(key);
463
+ snapshot.selections.set(key, selection);
464
+ }
465
+ while (snapshot.selections.size > EXPANSION_SELECTION_LIMIT) {
466
+ const oldest = snapshot.selections.keys().next().value;
467
+ if (oldest === void 0) break;
468
+ snapshot.selections.delete(oldest);
469
+ }
470
+ }
471
+ forgetExpansionSnapshot(snapshot) {
472
+ const key = expansionSnapshotKey(snapshot.file, snapshot.branches);
473
+ if (this.expansionSnapshots.get(key) === snapshot) this.expansionSnapshots.delete(key);
474
+ }
475
+ };
476
+
477
+ // src/memory/host-source.ts
478
+ import crypto2 from "node:crypto";
479
+
480
+ // src/memory/portable.ts
481
+ var MEMORY_SOURCE_INTERFACE_VERSION = 1;
482
+ var MemorySourceError = class extends Error {
483
+ constructor(code, message) {
484
+ super(message);
485
+ this.code = code;
486
+ this.name = "MemorySourceError";
487
+ }
488
+ };
489
+ var SOURCE_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
490
+ var isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
491
+ var assertValidSource = (source) => {
492
+ if (!isRecord(source) || typeof source !== "object") {
493
+ throw new TypeError("A portable memory source must be an object");
494
+ }
495
+ if (source.interfaceVersion !== MEMORY_SOURCE_INTERFACE_VERSION) {
496
+ throw new TypeError(
497
+ `Portable memory source interface version must be ${MEMORY_SOURCE_INTERFACE_VERSION}`
498
+ );
499
+ }
500
+ if (typeof source.id !== "string" || !SOURCE_ID_PATTERN.test(source.id)) {
501
+ throw new TypeError(
502
+ "Portable memory source id must be 1-128 chars of letters, digits, dot, underscore, or dash"
503
+ );
504
+ }
505
+ if (typeof source.listSessions !== "function" || typeof source.loadSession !== "function") {
506
+ throw new TypeError("A portable memory source requires listSessions and loadSession");
507
+ }
508
+ };
509
+ var defineMemorySource = (source) => {
510
+ assertValidSource(source);
511
+ return source;
512
+ };
513
+ var createMemorySourceRegistry = () => {
514
+ const sources = /* @__PURE__ */ new Map();
515
+ return {
516
+ register(source) {
517
+ assertValidSource(source);
518
+ sources.set(source.id, source);
519
+ },
520
+ get(id) {
521
+ return sources.get(id);
522
+ },
523
+ ids() {
524
+ return [...sources.keys()].sort();
525
+ }
526
+ };
527
+ };
528
+
529
+ // src/memory/host-source.ts
530
+ var HOST_KEY_PREFIX = "memory-source:";
531
+ var REASON_PATTERN = /^[a-z0-9_.:-]{1,64}$/;
532
+ var hostDisplayKey = (sourceId, sessionKey) => `${HOST_KEY_PREFIX}${sourceId}/${sessionKey}`;
533
+ var hostSessionKey = (sourceId, session) => {
534
+ const prefix = `${HOST_KEY_PREFIX}${sourceId}/`;
535
+ return session.startsWith(prefix) ? session.slice(prefix.length) : session;
536
+ };
537
+ var resolveRegisteredSource = (registry, sourceId) => {
538
+ const source = registry?.get(sourceId);
539
+ if (!source) throw new MemorySourceError("source_not_found", `Memory source not registered: ${sourceId}`);
540
+ return source;
541
+ };
542
+ var memorySourceFailure = (error) => error instanceof MemorySourceError ? { code: error.code, message: error.message } : null;
543
+ var checkAbort = (signal) => {
544
+ if (signal?.aborted) throw new MemorySourceError("aborted", "Memory source call was aborted.");
545
+ };
546
+ var assertAuthorized = async (source, action, sessionKey) => {
547
+ if (!source.authorize) return;
548
+ let allowed;
549
+ try {
550
+ allowed = await source.authorize(action, sessionKey);
551
+ } catch {
552
+ throw new MemorySourceError("source_unauthorized", "Memory source authorization failed.");
553
+ }
554
+ if (allowed !== true) {
555
+ throw new MemorySourceError("source_unauthorized", "Memory source denied access.");
556
+ }
557
+ };
558
+ var coverageReasons = (coverage) => {
559
+ if (!coverage || coverage.complete !== false) return [];
560
+ const reason = typeof coverage.reason === "string" && REASON_PATTERN.test(coverage.reason) ? `source_coverage:${coverage.reason}` : "source_coverage_incomplete";
561
+ return [reason];
562
+ };
563
+ var asSessionKey = (value) => typeof value === "string" && value.length > 0 ? value : "";
564
+ var normalizeListResponse = (response) => Array.isArray(response) ? { sessions: response, coverageReasons: [] } : { sessions: response.sessions, coverageReasons: coverageReasons(response.coverage) };
565
+ var loadHostSnapshot = async (source, sessionKey, action, signal) => {
566
+ checkAbort(signal);
567
+ await assertAuthorized(source, action, sessionKey);
568
+ const response = await source.loadSession(sessionKey, signal === void 0 ? {} : { signal });
569
+ checkAbort(signal);
570
+ await assertAuthorized(source, action, sessionKey);
571
+ if (response === null || response === void 0) return null;
572
+ const key = asSessionKey(response.sessionKey);
573
+ const revision = asSessionKey(response.revision);
574
+ if (!revision || !Array.isArray(response.records) || key !== sessionKey) {
575
+ throw new MemorySourceError("invalid_source_response", "Memory source returned an invalid snapshot.");
576
+ }
577
+ if (!response.records.every((record) => record !== null && typeof record === "object" && !Array.isArray(record))) {
578
+ throw new MemorySourceError("invalid_source_response", "Memory source snapshot has non-object records.");
579
+ }
580
+ let records;
581
+ try {
582
+ records = JSON.parse(JSON.stringify(response.records));
583
+ } catch {
584
+ throw new MemorySourceError(
585
+ "invalid_source_response",
586
+ "Memory source snapshot records are not JSON-serializable."
587
+ );
588
+ }
589
+ if (response.selectedLeafId !== void 0 && response.selectedLeafId !== null && (typeof response.selectedLeafId !== "string" || !records.some((record) => record.type !== "session" && record.id === response.selectedLeafId))) {
590
+ throw new MemorySourceError("invalid_source_response", "Memory source selected leaf is invalid.");
591
+ }
592
+ return {
593
+ sourceId: source.id,
594
+ sessionKey,
595
+ displayKey: hostDisplayKey(source.id, sessionKey),
596
+ sessionId: response.sessionId ?? sessionKey,
597
+ revision,
598
+ metadata: { ...response.metadata ?? {} },
599
+ records,
600
+ ...response.selectedLeafId !== void 0 ? { selectedLeafId: response.selectedLeafId } : {},
601
+ coverageReasons: coverageReasons(response.coverage)
602
+ };
603
+ };
604
+ var listHostSnapshots = async (source, limit, action, signal) => {
605
+ checkAbort(signal);
606
+ await assertAuthorized(source, action, null);
607
+ const boundedLimit = Math.max(0, Math.floor(limit));
608
+ const listed = normalizeListResponse(
609
+ await source.listSessions(signal === void 0 ? { limit: boundedLimit } : { limit: boundedLimit, signal })
610
+ );
611
+ checkAbort(signal);
612
+ const snapshots = [];
613
+ const coverageReasons2 = new Set(listed.coverageReasons);
614
+ if (listed.sessions.length > boundedLimit) {
615
+ coverageReasons2.add("source_limit_exceeded");
616
+ }
617
+ for (const descriptor of listed.sessions.slice(0, boundedLimit)) {
618
+ checkAbort(signal);
619
+ const key = asSessionKey(descriptor.sessionKey);
620
+ if (!key) {
621
+ coverageReasons2.add("invalid_source_response");
622
+ continue;
623
+ }
624
+ const snapshot = await loadHostSnapshot(source, key, action, signal);
625
+ if (!snapshot) {
626
+ coverageReasons2.add("source_unavailable");
627
+ continue;
628
+ }
629
+ for (const reason of snapshot.coverageReasons) coverageReasons2.add(reason);
630
+ snapshots.push(snapshot);
631
+ }
632
+ if (snapshots.length === 0) {
633
+ await assertAuthorized(source, action, null);
634
+ }
635
+ return { snapshots, coverageReasons: [...coverageReasons2] };
636
+ };
637
+ var hostSourceState = (snapshot) => {
638
+ const canonical = JSON.stringify(snapshot.records);
639
+ const sourceHash = crypto2.createHash("sha256").update(`${snapshot.revision}\0${canonical}`).digest("hex");
640
+ return {
641
+ mtime: snapshot.metadata.updatedAt ?? 0,
642
+ size: Buffer.byteLength(canonical, "utf8"),
643
+ sourceHash
644
+ };
645
+ };
646
+ var hostRef = (snapshot) => ({
647
+ id: snapshot.sessionId,
648
+ file: snapshot.displayKey,
649
+ cwd: snapshot.metadata.cwd ?? "",
650
+ mtime: snapshot.metadata.updatedAt ?? 0
651
+ });
652
+ var hostLineage = (snapshot, branches) => reconstructRecordsLineage(snapshot.records, branches, void 0, snapshot.selectedLeafId);
653
+ var hostIdentity2 = (sessionFile, sessionId, cwd) => ({
654
+ sessionFile,
655
+ ...sessionId !== void 0 ? { sessionId } : {},
656
+ ...cwd !== void 0 ? { cwd } : {}
657
+ });
658
+ var mergedCoverage = (base, extra) => {
659
+ if (extra.length === 0) return base;
660
+ const reasons = [.../* @__PURE__ */ new Set([...base.reasons, ...extra])].sort();
661
+ return { complete: false, reasons };
662
+ };
663
+ var buildHostShard = (snapshot, options, tier, entryRange) => {
664
+ const state = hostSourceState(snapshot);
665
+ const lineage = hostLineage(snapshot, options.branches ?? "active");
666
+ const { entries, header, indexCoverage } = normalizeRecords(
667
+ snapshot.records,
668
+ hostIdentity2(snapshot.displayKey, snapshot.sessionId, snapshot.metadata.cwd),
669
+ options.maxEntryChars,
670
+ {
671
+ lineage,
672
+ indexThinking: options.indexThinking ?? false,
673
+ indexToolOutput: options.indexToolOutput ?? true
674
+ }
675
+ );
676
+ const selected = entryRange ? entries.filter((entry) => entry.index >= entryRange.first && entry.index <= entryRange.last) : entries;
677
+ return {
678
+ cacheVersion: MEMORY_CACHE_VERSION,
679
+ kind: "shard",
680
+ sessionFile: snapshot.displayKey,
681
+ sessionId: header?.sessionId ?? snapshot.sessionId,
682
+ mtime: state.mtime,
683
+ size: state.size,
684
+ sourceHash: state.sourceHash,
685
+ branches: lineage.branches,
686
+ lineageFingerprint: lineage.fingerprint,
687
+ policy: shardPolicy(options, lineage),
688
+ cacheBytes: 0,
689
+ cacheSourceRatio: 0,
690
+ entries: selected,
691
+ totalEntryCount: entries.length,
692
+ indexCoverage: mergedCoverage(indexCoverage, snapshot.coverageReasons),
693
+ tier
694
+ };
695
+ };
696
+ var buildHostDigest = (snapshot, options) => {
697
+ const state = hostSourceState(snapshot);
698
+ const lineage = hostLineage(snapshot, options.branches ?? "active");
699
+ const { entries, header, indexCoverage } = normalizeRecords(
700
+ snapshot.records,
701
+ hostIdentity2(snapshot.displayKey, snapshot.sessionId, snapshot.metadata.cwd),
702
+ Number.MAX_SAFE_INTEGER,
703
+ {
704
+ lineage,
705
+ indexThinking: options.indexThinking ?? false,
706
+ indexToolOutput: options.indexToolOutput ?? true
707
+ }
708
+ );
709
+ const digest = foldSessionDigest({
710
+ sessionId: header?.sessionId ?? snapshot.sessionId,
711
+ file: snapshot.displayKey,
712
+ cwd: header?.cwd ?? snapshot.metadata.cwd ?? "",
713
+ entries,
714
+ maxVocabularyBytes: options.maxColdVocabularyBytes ?? 512 * 1024,
715
+ normalizationCoverage: mergedCoverage(indexCoverage, snapshot.coverageReasons)
716
+ });
717
+ return fitDigestCache({
718
+ cacheVersion: MEMORY_CACHE_VERSION,
719
+ kind: "digest",
720
+ ...digest,
721
+ mtime: state.mtime,
722
+ size: state.size,
723
+ sourceHash: state.sourceHash,
724
+ branches: lineage.branches,
725
+ lineageFingerprint: lineage.fingerprint,
726
+ policy: digestPolicy(options, lineage),
727
+ cacheBytes: 0,
728
+ cacheSourceRatio: 0
729
+ }, options.maxColdCacheBytes ?? 1024 * 1024);
730
+ };
731
+ var loadHostTieredIndex = (snapshots, options, hydrate = false, entryRange, extraReasons = []) => {
732
+ const refs = snapshots.map(hostRef);
733
+ const tiers = classifySessionTiers(refs, options.hotSessions ?? 50);
734
+ const maxSessions = options.maxSyncSessions ?? 1e4;
735
+ const maxSourceBytes = options.maxSyncSourceBytes ?? 512 * 1024 * 1024;
736
+ const shards = [];
737
+ const digests = [];
738
+ const reasons = new Set(extraReasons);
739
+ let indexedSessions = 0;
740
+ let incompleteSessions = 0;
741
+ let processedSessions = 0;
742
+ let processedSourceBytes = 0;
743
+ const byKey = new Map(snapshots.map((snapshot) => [snapshot.displayKey, snapshot]));
744
+ for (const ref of refs) {
745
+ const snapshot = byKey.get(ref.file);
746
+ if (!snapshot) {
747
+ reasons.add("source_unavailable");
748
+ continue;
749
+ }
750
+ const size = hostSourceState(snapshot).size;
751
+ if (processedSessions >= maxSessions) {
752
+ reasons.add("max_sync_sessions");
753
+ continue;
754
+ }
755
+ const tier = tiers.get(ref.file) ?? "cold";
756
+ const sourceWorkBytes = size * (hydrate && tier === "cold" ? 6 : 3);
757
+ if (processedSourceBytes + sourceWorkBytes > maxSourceBytes) {
758
+ reasons.add("max_sync_source_bytes");
759
+ continue;
760
+ }
761
+ processedSessions += 1;
762
+ processedSourceBytes += sourceWorkBytes;
763
+ if (hydrate) {
764
+ if (tier === "cold") digests.push(buildHostDigest(snapshot, options));
765
+ const shard = buildHostShard(snapshot, options, "cold", entryRange);
766
+ shards.push(shard);
767
+ if (shard.sourceHash) indexedSessions += 1;
768
+ if (shard.sourceHash && !shard.indexCoverage.complete) {
769
+ incompleteSessions += 1;
770
+ for (const reason of shard.indexCoverage.reasons) reasons.add(reason);
771
+ }
772
+ } else if (tier === "hot") {
773
+ const shard = buildHostShard(snapshot, options, "hot");
774
+ shards.push(shard);
775
+ if (shard.sourceHash) indexedSessions += 1;
776
+ if (shard.sourceHash && !shard.indexCoverage.complete) {
777
+ incompleteSessions += 1;
778
+ for (const reason of shard.indexCoverage.reasons) reasons.add(reason);
779
+ }
780
+ } else {
781
+ const digest = buildHostDigest(snapshot, options);
782
+ digests.push(digest);
783
+ if (digest.sourceHash) indexedSessions += 1;
784
+ if (!digest.indexCoverage.complete) {
785
+ incompleteSessions += 1;
786
+ for (const reason of digest.indexCoverage.reasons) reasons.add(reason);
787
+ }
788
+ }
789
+ }
790
+ const eligibleSessions = refs.length;
791
+ const staleSessions = eligibleSessions - indexedSessions;
792
+ const coverage = {
793
+ complete: reasons.size === 0 && staleSessions === 0 && incompleteSessions === 0,
794
+ indexedSessions,
795
+ eligibleSessions,
796
+ staleSessions,
797
+ incompleteSessions,
798
+ reasons: [...reasons].sort()
799
+ };
800
+ return { shards, digests, refs, tiers, coverage };
801
+ };
802
+ var fileRecallPlan = (refs, context) => {
803
+ const liveResolver = liveBranchResolver(context);
804
+ return {
805
+ refs,
806
+ sessionKey: null,
807
+ observeAll: (branches) => observeSources(refs, branches, liveResolver),
808
+ stateFor: (ref) => fingerprintSource(ref.file),
809
+ lineageFor: (ref, branches) => reconstructSessionLineage(ref.file, branches, liveResolver?.(ref.file)),
810
+ loadIndex: (options, hydrate, entryRange) => loadTieredIndex(refs, resolveTierRefs(refs, context), options, hydrate, entryRange)
811
+ };
812
+ };
813
+ var hostRecallPlan = async (source, sourceId, sessionKey, context, signal) => {
814
+ const loaded = sessionKey !== null ? await (async () => {
815
+ const snapshot = await loadHostSnapshot(source, sessionKey, "recall", signal);
816
+ return snapshot ? { snapshots: [snapshot], coverageReasons: [] } : null;
817
+ })() : await listHostSnapshots(source, context.config.maxSessions, "recall", signal);
818
+ if (!loaded) throw new MemorySourceError("session_not_found", `Session not found in source ${sourceId}: ${sessionKey}`);
819
+ const snapshots = loaded.snapshots;
820
+ const refs = snapshots.map(hostRef);
821
+ const byKey = new Map(snapshots.map((snapshot) => [snapshot.displayKey, snapshot]));
822
+ const stateByKey = /* @__PURE__ */ new Map();
823
+ const stateOf = (snapshot) => {
824
+ let state = stateByKey.get(snapshot.displayKey);
825
+ if (!state) {
826
+ state = hostSourceState(snapshot);
827
+ stateByKey.set(snapshot.displayKey, state);
828
+ }
829
+ return state;
830
+ };
831
+ return {
832
+ refs,
833
+ sessionKey,
834
+ observeAll: (branches) => snapshots.map((snapshot) => ({ ...observeHostSource(snapshot.displayKey, snapshot.revision, stateOf(snapshot).sourceHash), liveBranchSignature: hostLineage(snapshot, branches).fingerprint })),
835
+ stateFor: (ref) => {
836
+ const snapshot = byKey.get(ref.file);
837
+ return snapshot ? stateOf(snapshot) : null;
838
+ },
839
+ lineageFor: (ref, branches) => {
840
+ const snapshot = byKey.get(ref.file);
841
+ return snapshot ? hostLineage(snapshot, branches) : reconstructSessionLineage(ref.file, branches);
842
+ },
843
+ loadIndex: (options, hydrate, entryRange) => loadHostTieredIndex(snapshots, options, hydrate, entryRange, loaded.coverageReasons)
844
+ };
845
+ };
846
+ var fileExpansionAccess = (session, context) => {
847
+ const ref = resolveSessionTarget(context.agentDir, session);
848
+ if (!ref) return null;
849
+ const liveResolver = liveBranchResolver(context);
850
+ return {
851
+ ref,
852
+ state: () => fingerprintSource(ref.file),
853
+ lineage: (branches) => reconstructSessionLineage(ref.file, branches, liveResolver?.(ref.file)),
854
+ observe: (branches) => observeSource(ref.file, branches, branches === "active" ? liveResolver?.(ref.file) : void 0),
855
+ normalizeFull: (branches, policy, lineage) => {
856
+ const resolvedLineage = lineage ?? reconstructSessionLineage(ref.file, branches, liveResolver?.(ref.file));
857
+ const normalized = normalizeSession(ref.file, Number.MAX_SAFE_INTEGER, {
858
+ lineage: resolvedLineage,
859
+ ...policy
860
+ });
861
+ return normalized.header === null && normalized.entries.length === 0 && normalized.indexCoverage.reasons.includes("source_unavailable") ? null : { entries: normalized.entries, indexCoverage: normalized.indexCoverage };
862
+ }
863
+ };
864
+ };
865
+ var hostExpansionAccess = async (sourceId, session, context, signal) => {
866
+ const source = resolveRegisteredSource(context.sources, sourceId);
867
+ const sessionKey = hostSessionKey(sourceId, session);
868
+ const snapshot = await loadHostSnapshot(source, sessionKey, "expand", signal);
869
+ if (!snapshot) {
870
+ throw new MemorySourceError("session_not_found", `Session not found in source ${sourceId}: ${sessionKey}`);
871
+ }
872
+ const state = hostSourceState(snapshot);
873
+ const ref = hostRef(snapshot);
874
+ return {
875
+ ref,
876
+ state: () => state,
877
+ lineage: (branches) => hostLineage(snapshot, branches),
878
+ observe: (branches) => ({ ...observeHostSource(snapshot.displayKey, snapshot.revision, state.sourceHash), liveBranchSignature: hostLineage(snapshot, branches).fingerprint }),
879
+ normalizeFull: (branches, policy) => {
880
+ const normalized = normalizeRecords(
881
+ snapshot.records,
882
+ hostIdentity2(snapshot.displayKey, snapshot.sessionId, snapshot.metadata.cwd),
883
+ Number.MAX_SAFE_INTEGER,
884
+ { lineage: hostLineage(snapshot, branches), ...policy }
885
+ );
886
+ return {
887
+ entries: normalized.entries,
888
+ indexCoverage: mergedCoverage(normalized.indexCoverage, snapshot.coverageReasons)
889
+ };
890
+ }
891
+ };
892
+ };
893
+
894
+ // src/memory/recall-service.ts
895
+ async function processMemoryRecall(args, invocationContext, context, cache) {
896
+ const query = typeof args.query === "string" ? args.query : void 0;
897
+ const rawQueryMode = args.queryMode;
898
+ if (rawQueryMode !== void 0 && rawQueryMode !== "literal" && rawQueryMode !== "phrase" && rawQueryMode !== "regex") {
899
+ throw new Error('memory.recall queryMode must be "literal", "phrase", or "regex"');
900
+ }
901
+ const queryMode = rawQueryMode === "phrase" ? "phrase" : rawQueryMode === "regex" ? "regex" : "literal";
902
+ const rawQueryMatch = args.queryMatch;
903
+ if (rawQueryMatch !== void 0 && rawQueryMatch !== "all" && rawQueryMatch !== "any") {
904
+ throw new Error('memory.recall queryMatch must be "all" or "any"');
905
+ }
906
+ if (queryMode !== "literal" && rawQueryMatch !== void 0) {
907
+ throw new Error("memory.recall queryMatch is only valid with literal queryMode");
908
+ }
909
+ const queryMatch = rawQueryMatch === "all" ? "all" : "any";
910
+ const expectedSourceHash = typeof args.expectedSourceHash === "string" ? args.expectedSourceHash : void 0;
911
+ const expectedLineageFingerprint = typeof args.expectedLineageFingerprint === "string" ? args.expectedLineageFingerprint : void 0;
912
+ const branches = parseBranches(args.branches, "memory.recall");
913
+ const scope = typeof args.scope === "string" ? args.scope : void 0;
914
+ const role = typeof args.role === "string" ? args.role : void 0;
915
+ const tool = typeof args.tool === "string" ? args.tool : void 0;
916
+ const ref = typeof args.ref === "string" ? args.ref : void 0;
917
+ const provider = typeof args.provider === "string" ? args.provider : void 0;
918
+ const action = typeof args.action === "string" ? args.action : void 0;
919
+ const rawOutcome = args.outcome;
920
+ if (rawOutcome !== void 0 && rawOutcome !== "succeeded" && rawOutcome !== "failed" && rawOutcome !== "aborted" && rawOutcome !== "timed_out") {
921
+ throw new Error("memory.recall outcome must be succeeded, failed, aborted, or timed_out");
922
+ }
923
+ const outcome = rawOutcome;
924
+ const since = typeof args.since === "number" ? args.since : void 0;
925
+ const until = typeof args.until === "number" ? args.until : void 0;
926
+ const offset = typeof args.offset === "number" && args.offset >= 0 ? Math.floor(args.offset) : void 0;
927
+ const pageSize = typeof args.pageSize === "number" && args.pageSize >= 1 ? Math.min(Math.floor(args.pageSize), RECALL_MAX_PAGE_SIZE) : RECALL_DEFAULT_PAGE_SIZE;
928
+ const snippetChars = typeof args.snippetChars === "number" && args.snippetChars >= 80 ? Math.min(Math.floor(args.snippetChars), RECALL_MAX_SNIPPET_CHARS) : RECALL_DEFAULT_SNIPPET_CHARS;
929
+ const sourceId = typeof args.source === "string" && args.source.length > 0 ? args.source : void 0;
930
+ let plan;
931
+ if (sourceId !== void 0) {
932
+ if (scope !== void 0 && scope !== `source:${sourceId}` && !scope.startsWith("session:")) {
933
+ throw new Error(
934
+ "memory.recall scope must name the selected source, one of its sessions, or be omitted"
935
+ );
936
+ }
937
+ try {
938
+ plan = await hostRecallPlan(
939
+ resolveRegisteredSource(context.sources, sourceId),
940
+ sourceId,
941
+ scope?.startsWith("session:") ? scope.slice("session:".length).trim() : null,
942
+ context,
943
+ invocationContext.signal
944
+ );
945
+ } catch (error) {
946
+ const failure = memorySourceFailure(error);
947
+ if (!failure) throw error;
948
+ return recallFailure(failure);
949
+ }
950
+ } else {
951
+ plan = fileRecallPlan(resolveRefs(scope, context, false), context);
952
+ }
953
+ const refs = plan.refs;
954
+ const options = resolveIndexOptions(
955
+ context.config,
956
+ context.agentDir,
957
+ branches,
958
+ sourceId === void 0 ? liveBranchResolver(context) : void 0
959
+ );
960
+ const hydrate = sourceId !== void 0 ? plan.sessionKey !== null : scope?.trim().startsWith("session:") ?? false;
961
+ if ((expectedSourceHash !== void 0 || expectedLineageFingerprint !== void 0) && !hydrate) {
962
+ throw new Error("memory.recall integrity expectations require scope session:<id-or-path>");
963
+ }
964
+ const rawRange = args.entryRange;
965
+ const entryRange = rawRange && typeof rawRange === "object" && !Array.isArray(rawRange) ? rawRange : void 0;
966
+ const first = entryRange?.first;
967
+ const last = entryRange?.last;
968
+ if (first === void 0 !== (last === void 0)) {
969
+ throw new Error("memory.recall entryRange requires both first and last");
970
+ }
971
+ if ((first !== void 0 || last !== void 0) && !hydrate) {
972
+ throw new Error("memory.recall entryRange requires scope session:<id-or-path>");
973
+ }
974
+ if (first !== void 0 && (typeof first !== "number" || typeof last !== "number" || !Number.isSafeInteger(first) || !Number.isSafeInteger(last) || first < 0 || last < first)) {
975
+ return recallFailure(addressError("Entry range requires safe integers with 0 <= first <= last."));
976
+ }
977
+ const selectedRange = typeof first === "number" && typeof last === "number" ? { first, last } : void 0;
978
+ const filters = {};
979
+ if (role) filters.role = role;
980
+ if (tool) filters.tool = tool;
981
+ if (ref) filters.ref = ref;
982
+ if (provider) filters.provider = provider;
983
+ if (action) filters.action = action;
984
+ if (outcome) filters.outcome = outcome;
985
+ if (since !== void 0) filters.since = since;
986
+ if (until !== void 0) filters.until = until;
987
+ const baseRequestArgs = {
988
+ ...sourceId ? { source: sourceId } : {},
989
+ ...query === void 0 ? {} : { query },
990
+ queryMode,
991
+ ...queryMode === "literal" ? { queryMatch } : {},
992
+ ...expectedSourceHash ? { expectedSourceHash } : {},
993
+ ...expectedLineageFingerprint ? { expectedLineageFingerprint } : {},
994
+ branches,
995
+ scope: sourceId ? plan.sessionKey !== null ? `session:${plan.refs[0]?.file ?? plan.sessionKey}` : `source:${sourceId}` : scope ?? "session",
996
+ ...offset === void 0 ? {} : { offset },
997
+ pageSize,
998
+ snippetChars,
999
+ ...role ? { role } : {},
1000
+ ...tool ? { tool } : {},
1001
+ ...ref ? { ref } : {},
1002
+ ...provider ? { provider } : {},
1003
+ ...action ? { action } : {},
1004
+ ...outcome ? { outcome } : {},
1005
+ ...since !== void 0 ? { since } : {},
1006
+ ...until !== void 0 ? { until } : {},
1007
+ ...selectedRange ? { entryRange: selectedRange } : {}
1008
+ };
1009
+ const updateProgress = (searchResult) => {
1010
+ invocationContext.update(
1011
+ searchResult.matchMode === "structural" ? `memory.recall: ${searchResult.matchedCount} structural matches` : searchResult.matchMode === "combined" ? `memory.recall: ${searchResult.matchedCount} filtered matches` : query ? `memory.recall: ${searchResult.matchedCount} matches` : `memory.recall: ${searchResult.matchedCount} recent entries`
1012
+ );
1013
+ };
1014
+ const observationsBefore = await plan.observeAll(branches);
1015
+ const cached = offset === void 0 ? void 0 : cache.cachedRecallContinuation(
1016
+ recallContinuationKey(baseRequestArgs),
1017
+ observationsBefore
1018
+ );
1019
+ if (cached) {
1020
+ const response2 = presentRecall({
1021
+ result: cached.result,
1022
+ ...query === void 0 ? {} : { query },
1023
+ queryMode,
1024
+ coverage: cached.coverage,
1025
+ ...offset === void 0 ? {} : { offset },
1026
+ pageSize,
1027
+ snippetChars,
1028
+ requestArgs: cached.requestArgs
1029
+ });
1030
+ const observationsAfterCachedPage = await plan.observeAll(branches);
1031
+ if (observationsBefore && observationsAfterCachedPage && sameSourceObservations(observationsBefore, observationsAfterCachedPage)) {
1032
+ if (response2.next === null) cache.forgetRecallContinuation(cached);
1033
+ updateProgress(cached.result);
1034
+ return response2;
1035
+ }
1036
+ cache.forgetRecallContinuation(cached);
1037
+ }
1038
+ if (hydrate && refs[0]) {
1039
+ const state = plan.stateFor(refs[0]);
1040
+ const lineage = plan.lineageFor(refs[0], branches);
1041
+ const sourceChanged = expectedSourceHash !== void 0 && state?.sourceHash !== expectedSourceHash;
1042
+ const lineageChanged = expectedLineageFingerprint !== void 0 && lineage.fingerprint !== expectedLineageFingerprint;
1043
+ if (state && (sourceChanged || lineageChanged)) {
1044
+ return recallFailure(stalePointerError(
1045
+ refs[0].file,
1046
+ expectedSourceHash,
1047
+ state.sourceHash,
1048
+ expectedLineageFingerprint,
1049
+ lineage.fingerprint
1050
+ ));
1051
+ }
1052
+ }
1053
+ const index = plan.loadIndex(options, hydrate, selectedRange);
1054
+ const hydratedShard = index.shards[0];
1055
+ const hydratedSourceChanged = expectedSourceHash !== void 0 && hydratedShard?.sourceHash !== expectedSourceHash;
1056
+ const hydratedLineageChanged = expectedLineageFingerprint !== void 0 && hydratedShard?.lineageFingerprint !== expectedLineageFingerprint;
1057
+ if (hydrate && hydratedShard && (hydratedSourceChanged || hydratedLineageChanged)) {
1058
+ return recallFailure(stalePointerError(
1059
+ hydratedShard.sessionFile,
1060
+ expectedSourceHash,
1061
+ hydratedShard.sourceHash,
1062
+ expectedLineageFingerprint,
1063
+ hydratedShard.lineageFingerprint
1064
+ ));
1065
+ }
1066
+ if (hydrate && selectedRange && index.shards[0] && selectedRange.last >= index.shards[0].totalEntryCount) {
1067
+ return recallFailure(addressError(
1068
+ `Entry range ends at ${selectedRange.last}, but the session has ${index.shards[0].totalEntryCount} entries.`,
1069
+ index.shards[0].totalEntryCount
1070
+ ));
1071
+ }
1072
+ const searchQuery = {
1073
+ ...query === void 0 ? {} : { query },
1074
+ queryMode,
1075
+ queryMatch,
1076
+ filters,
1077
+ regexLimits: {
1078
+ maxPatternBytes: context.config.regexMaxPatternBytes ?? DEFAULT_REGEX_MAX_PATTERN_BYTES,
1079
+ maxHaystackTerms: context.config.regexMaxHaystackTerms ?? DEFAULT_REGEX_MAX_HAYSTACK_TERMS,
1080
+ maxHaystackBytes: context.config.regexMaxHaystackBytes ?? DEFAULT_REGEX_MAX_HAYSTACK_BYTES,
1081
+ timeoutMs: context.config.regexTimeoutMs ?? DEFAULT_REGEX_TIMEOUT_MS
1082
+ }
1083
+ };
1084
+ const result = await searchMemoryIndex(index.shards, index.digests, searchQuery);
1085
+ const coverage = {
1086
+ ...index.coverage,
1087
+ complete: index.coverage.complete && result.queryCoverage.complete,
1088
+ reasons: [.../* @__PURE__ */ new Set([...index.coverage.reasons, ...result.queryCoverage.reasons])].sort(),
1089
+ ...result.queryCoverage.error ? { error: result.queryCoverage.error } : {}
1090
+ };
1091
+ const soleRef = refs.length === 1 ? refs[0] : void 0;
1092
+ const soleShard = soleRef ? index.shards.find((candidate) => candidate.sessionFile === soleRef.file) : void 0;
1093
+ const soleDigest = soleRef ? index.digests.find((candidate) => candidate.file === soleRef.file) : void 0;
1094
+ const continuationBinding = soleRef && (soleShard?.sourceHash || soleDigest?.sourceHash) ? {
1095
+ file: soleRef.file,
1096
+ sourceHash: soleShard?.sourceHash ?? soleDigest.sourceHash,
1097
+ lineageFingerprint: soleShard?.lineageFingerprint ?? soleDigest.lineageFingerprint
1098
+ } : void 0;
1099
+ const requestArgs = {
1100
+ ...baseRequestArgs,
1101
+ ...expectedSourceHash ?? continuationBinding?.sourceHash ? { expectedSourceHash: expectedSourceHash ?? continuationBinding.sourceHash } : {},
1102
+ ...expectedLineageFingerprint ?? continuationBinding?.lineageFingerprint ? {
1103
+ expectedLineageFingerprint: expectedLineageFingerprint ?? continuationBinding.lineageFingerprint
1104
+ } : {},
1105
+ scope: continuationBinding ? `session:${continuationBinding.file}` : baseRequestArgs.scope ?? "session"
1106
+ };
1107
+ const response = presentRecall({
1108
+ result,
1109
+ ...query === void 0 ? {} : { query },
1110
+ queryMode,
1111
+ coverage,
1112
+ ...offset === void 0 ? {} : { offset },
1113
+ pageSize,
1114
+ snippetChars,
1115
+ requestArgs
1116
+ });
1117
+ const observationsAfter = await plan.observeAll(branches);
1118
+ if (response.next !== null && observationsBefore && observationsAfter && sameSourceObservations(observationsBefore, observationsAfter)) {
1119
+ cache.rememberRecallContinuation({
1120
+ key: recallContinuationKey(requestArgs),
1121
+ result,
1122
+ coverage,
1123
+ requestArgs,
1124
+ observations: observationsAfter,
1125
+ touchedAt: Date.now()
1126
+ });
1127
+ }
1128
+ updateProgress(result);
1129
+ return response;
1130
+ }
1131
+
1132
+ // src/memory/expand-service.ts
1133
+ async function processMemoryExpand(args, context, cache, signal) {
1134
+ const session = typeof args.session === "string" ? args.session : "";
1135
+ const sourceId = typeof args.source === "string" && args.source.length > 0 ? args.source : void 0;
1136
+ const expectedSourceHash = typeof args.expectedSourceHash === "string" ? args.expectedSourceHash : void 0;
1137
+ const expectedLineageFingerprint = typeof args.expectedLineageFingerprint === "string" ? args.expectedLineageFingerprint : void 0;
1138
+ const branches = parseBranches(args.branches, "memory.expand");
1139
+ const rawIndices = args.indices;
1140
+ if (rawIndices !== void 0 && !Array.isArray(rawIndices)) {
1141
+ throw new Error("memory.expand indices must be an array");
1142
+ }
1143
+ if (Array.isArray(rawIndices) && !rawIndices.every((index) => typeof index === "number" && Number.isSafeInteger(index) && index >= 0)) {
1144
+ return { session, error: addressError("Every entry index must be a non-negative safe integer."), entries: [] };
1145
+ }
1146
+ const indices = rawIndices ?? [];
1147
+ const entryIds = Array.isArray(args.entryIds) ? args.entryIds.filter(
1148
+ (entryId) => typeof entryId === "string" && entryId.length > 0
1149
+ ) : [];
1150
+ const operationAddresses = Array.isArray(args.operationAddresses) ? args.operationAddresses.filter(
1151
+ (address) => typeof address === "string" && address.length > 0
1152
+ ) : [];
1153
+ if (indices.length + entryIds.length + operationAddresses.length > EXPAND_MAX_EXACT_SELECTORS) {
1154
+ throw new Error(`memory.expand accepts at most ${EXPAND_MAX_EXACT_SELECTORS} exact selectors per call`);
1155
+ }
1156
+ const rawRange = args.entryRange;
1157
+ const rangeRecord = rawRange && typeof rawRange === "object" && !Array.isArray(rawRange) ? rawRange : void 0;
1158
+ const first = rangeRecord?.first;
1159
+ const last = rangeRecord?.last;
1160
+ if (!session) throw new Error("memory.expand requires a session");
1161
+ if (first === void 0 !== (last === void 0)) {
1162
+ throw new Error("memory.expand entryRange requires both first and last");
1163
+ }
1164
+ if (first !== void 0 && (typeof first !== "number" || typeof last !== "number" || !Number.isSafeInteger(first) || !Number.isSafeInteger(last) || first < 0 || last < first)) {
1165
+ return { session, error: addressError("Entry range requires safe integers with 0 <= first <= last."), entries: [] };
1166
+ }
1167
+ const numeric = (value, fallback, maximum) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? Math.min(value, maximum) : fallback;
1168
+ const before = numeric(args.before, 0, EXPAND_MAX_CONTEXT);
1169
+ const after = numeric(args.after, 0, EXPAND_MAX_CONTEXT);
1170
+ const entryOffset = numeric(args.entryOffset, 0, Number.MAX_SAFE_INTEGER);
1171
+ const textOffset = numeric(args.textOffset, 0, Number.MAX_SAFE_INTEGER);
1172
+ const maxChars = Math.max(256, numeric(args.maxChars, EXPAND_DEFAULT_MAX_CHARS, EXPAND_MAX_CHARS));
1173
+ const maxEntries = Math.max(1, numeric(args.maxEntries, EXPAND_DEFAULT_MAX_ENTRIES, EXPAND_MAX_ENTRIES));
1174
+ let access;
1175
+ if (sourceId !== void 0) {
1176
+ try {
1177
+ access = await hostExpansionAccess(sourceId, session, context, signal);
1178
+ } catch (error) {
1179
+ const failure = memorySourceFailure(error);
1180
+ if (!failure) throw error;
1181
+ return { session, error: failure, entries: [] };
1182
+ }
1183
+ } else {
1184
+ access = fileExpansionAccess(session, context);
1185
+ }
1186
+ if (!access) {
1187
+ return {
1188
+ session,
1189
+ error: { code: "session_not_found", message: `Session not found: ${session}` },
1190
+ entries: []
1191
+ };
1192
+ }
1193
+ const ref = access.ref;
1194
+ const observedSource = access.observe(branches);
1195
+ let snapshot = cache.cachedExpansionSnapshot(ref.file, branches, observedSource);
1196
+ if (snapshot) {
1197
+ const sourceChanged = expectedSourceHash !== void 0 && snapshot.sourceHash !== expectedSourceHash;
1198
+ const lineageChanged = expectedLineageFingerprint !== void 0 && snapshot.lineageFingerprint !== expectedLineageFingerprint;
1199
+ if (sourceChanged || lineageChanged) {
1200
+ return {
1201
+ session: ref.file,
1202
+ branches,
1203
+ error: stalePointerError(
1204
+ ref.file,
1205
+ expectedSourceHash,
1206
+ snapshot.sourceHash,
1207
+ expectedLineageFingerprint,
1208
+ snapshot.lineageFingerprint
1209
+ ),
1210
+ entries: []
1211
+ };
1212
+ }
1213
+ }
1214
+ if (!snapshot) {
1215
+ const initialState = access.state();
1216
+ if (!initialState) {
1217
+ return {
1218
+ session: ref.file,
1219
+ error: { code: "source_unavailable", message: `Session source is unavailable: ${ref.file}` },
1220
+ entries: []
1221
+ };
1222
+ }
1223
+ const initialLineage = access.lineage(branches);
1224
+ const sourceChanged = expectedSourceHash !== void 0 && initialState.sourceHash !== expectedSourceHash;
1225
+ const lineageChanged = expectedLineageFingerprint !== void 0 && initialLineage.fingerprint !== expectedLineageFingerprint;
1226
+ if (sourceChanged || lineageChanged) {
1227
+ return {
1228
+ session: ref.file,
1229
+ branches,
1230
+ error: stalePointerError(
1231
+ ref.file,
1232
+ expectedSourceHash,
1233
+ initialState.sourceHash,
1234
+ expectedLineageFingerprint,
1235
+ initialLineage.fingerprint
1236
+ ),
1237
+ entries: []
1238
+ };
1239
+ }
1240
+ const normalizedFull = access.normalizeFull(
1241
+ branches,
1242
+ { indexThinking: true, indexToolOutput: true },
1243
+ initialLineage
1244
+ );
1245
+ if (!normalizedFull) {
1246
+ return {
1247
+ session: ref.file,
1248
+ error: stalePointerError(
1249
+ ref.file,
1250
+ expectedSourceHash ?? initialState.sourceHash,
1251
+ initialState.sourceHash,
1252
+ expectedLineageFingerprint ?? initialLineage.fingerprint,
1253
+ initialLineage.fingerprint
1254
+ ),
1255
+ entries: []
1256
+ };
1257
+ }
1258
+ const normalized = normalizedFull.entries;
1259
+ const finalState2 = access.state();
1260
+ const finalLineage2 = access.lineage(branches);
1261
+ const finalObservation = access.observe(branches);
1262
+ if (!finalState2 || !finalObservation || finalState2.sourceHash !== initialState.sourceHash || finalLineage2.fingerprint !== initialLineage.fingerprint) {
1263
+ return {
1264
+ session: ref.file,
1265
+ error: stalePointerError(
1266
+ ref.file,
1267
+ expectedSourceHash ?? initialState.sourceHash,
1268
+ finalState2?.sourceHash ?? "",
1269
+ expectedLineageFingerprint ?? initialLineage.fingerprint,
1270
+ finalLineage2.fingerprint
1271
+ ),
1272
+ entries: []
1273
+ };
1274
+ }
1275
+ snapshot = {
1276
+ file: ref.file,
1277
+ branches,
1278
+ sourceHash: finalState2.sourceHash,
1279
+ lineageFingerprint: finalLineage2.fingerprint,
1280
+ observation: finalObservation,
1281
+ entries: normalized,
1282
+ selections: /* @__PURE__ */ new Map(),
1283
+ touchedAt: Date.now()
1284
+ };
1285
+ }
1286
+ const entryCount = snapshot.entries.length;
1287
+ const outOfBounds = indices.find((index) => index >= entryCount);
1288
+ if (outOfBounds !== void 0) {
1289
+ return {
1290
+ session: ref.file,
1291
+ error: addressError(`Entry index ${outOfBounds} is outside 0..${Math.max(0, entryCount - 1)}.`, entryCount),
1292
+ entries: []
1293
+ };
1294
+ }
1295
+ if (typeof last === "number" && last >= entryCount) {
1296
+ return {
1297
+ session: ref.file,
1298
+ error: addressError(`Entry range ends at ${last}, but the session has ${entryCount} entries.`, entryCount),
1299
+ entries: []
1300
+ };
1301
+ }
1302
+ if (indices.length === 0 && entryIds.length === 0 && operationAddresses.length === 0 && (first === void 0 || last === void 0)) {
1303
+ if (before > 0 || after > 0) {
1304
+ throw new Error("memory.expand before/after requires one selected anchor");
1305
+ }
1306
+ cache.forgetExpansionSnapshot(snapshot);
1307
+ return {
1308
+ session: ref.file,
1309
+ sourceHash: snapshot.sourceHash,
1310
+ branches,
1311
+ lineageFingerprint: snapshot.lineageFingerprint,
1312
+ entryCount,
1313
+ entries: [],
1314
+ next: null
1315
+ };
1316
+ }
1317
+ const requestedSelection = {};
1318
+ if (indices.length > 0) requestedSelection.indices = indices;
1319
+ if (entryIds.length > 0) requestedSelection.entryIds = entryIds;
1320
+ if (operationAddresses.length > 0) requestedSelection.operationAddresses = operationAddresses;
1321
+ if (typeof first === "number" && typeof last === "number") {
1322
+ requestedSelection.entryRange = { first, last };
1323
+ }
1324
+ const requestedWithContext = {
1325
+ ...requestedSelection,
1326
+ ...before > 0 ? { before } : {},
1327
+ ...after > 0 ? { after } : {}
1328
+ };
1329
+ const requestedKey = expansionSelectionKey(requestedWithContext);
1330
+ let resolved = snapshot.selections.get(requestedKey);
1331
+ if (!resolved) {
1332
+ let expansion = expandSessionEntriesChecked(snapshot.entries, requestedSelection);
1333
+ if ("error" in expansion) {
1334
+ return {
1335
+ session: ref.file,
1336
+ sourceHash: snapshot.sourceHash,
1337
+ branches,
1338
+ lineageFingerprint: snapshot.lineageFingerprint,
1339
+ error: expansion.error,
1340
+ entries: []
1341
+ };
1342
+ }
1343
+ let anchorIndex2 = null;
1344
+ let canonical;
1345
+ if (before > 0 || after > 0) {
1346
+ if (expansion.expanded.length !== 1) {
1347
+ throw new Error("memory.expand before/after requires exactly one resolved anchor");
1348
+ }
1349
+ anchorIndex2 = expansion.expanded[0].index;
1350
+ const contextRange = {
1351
+ first: Math.max(0, anchorIndex2 - before),
1352
+ last: Math.min(Math.max(0, entryCount - 1), anchorIndex2 + after)
1353
+ };
1354
+ canonical = requestedWithContext;
1355
+ expansion = expandSessionEntriesChecked(snapshot.entries, { entryRange: contextRange });
1356
+ if ("error" in expansion) {
1357
+ return {
1358
+ session: ref.file,
1359
+ sourceHash: snapshot.sourceHash,
1360
+ branches,
1361
+ lineageFingerprint: snapshot.lineageFingerprint,
1362
+ error: expansion.error,
1363
+ entries: []
1364
+ };
1365
+ }
1366
+ } else if (requestedSelection.entryRange) {
1367
+ canonical = { entryRange: requestedSelection.entryRange };
1368
+ } else {
1369
+ canonical = { indices: expansion.expanded.map((entry) => entry.index) };
1370
+ }
1371
+ resolved = { entries: expansion.expanded, canonical, anchorIndex: anchorIndex2 };
1372
+ cache.rememberExpansionSelection(
1373
+ snapshot,
1374
+ [requestedKey, expansionSelectionKey(canonical)],
1375
+ resolved
1376
+ );
1377
+ }
1378
+ const selected = resolved.entries;
1379
+ const canonicalSelection = resolved.canonical;
1380
+ const anchorIndex = resolved.anchorIndex;
1381
+ const finalState = snapshot;
1382
+ const finalLineage = { fingerprint: snapshot.lineageFingerprint };
1383
+ if (entryOffset > selected.length) {
1384
+ return {
1385
+ session: ref.file,
1386
+ error: addressError(`Entry offset ${entryOffset} is outside 0..${selected.length}.`, selected.length),
1387
+ entries: []
1388
+ };
1389
+ }
1390
+ if (entryOffset < selected.length && textOffset > selected[entryOffset].text.length) {
1391
+ return {
1392
+ session: ref.file,
1393
+ error: {
1394
+ code: "text_offset_out_of_bounds",
1395
+ message: `Text offset ${textOffset} exceeds entry #${selected[entryOffset].index} length ${selected[entryOffset].text.length}.`,
1396
+ textLength: selected[entryOffset].text.length
1397
+ },
1398
+ entries: []
1399
+ };
1400
+ }
1401
+ const bounded = (value, maximum = 512) => value === null || value.length <= maximum ? value : `${value.slice(0, Math.max(1, maximum - 1))}\u2026`;
1402
+ const compactStructure = (value) => {
1403
+ if (value === void 0) return void 0;
1404
+ const serialized = JSON.stringify(value);
1405
+ return serialized.length <= 2e3 ? value : void 0;
1406
+ };
1407
+ const output = [];
1408
+ const cursors = [];
1409
+ let position = entryOffset;
1410
+ let currentTextOffset = textOffset;
1411
+ let remainingChars = maxChars;
1412
+ while (position < selected.length && output.length < maxEntries && remainingChars > 0) {
1413
+ const entry = selected[position];
1414
+ let end = Math.min(entry.text.length, currentTextOffset + remainingChars);
1415
+ if (end < entry.text.length && end > currentTextOffset && entry.text.charCodeAt(end) >= 56320 && entry.text.charCodeAt(end) <= 57343) {
1416
+ end -= 1;
1417
+ }
1418
+ if (end === currentTextOffset && currentTextOffset < entry.text.length) {
1419
+ end = Math.min(entry.text.length, currentTextOffset + 2);
1420
+ }
1421
+ const chunk = entry.text.slice(currentTextOffset, end);
1422
+ const textComplete = end >= entry.text.length;
1423
+ const operation = compactStructure(entry.operation);
1424
+ const branchFact = compactStructure(entry.branchFact);
1425
+ output.push({
1426
+ index: entry.index,
1427
+ entryId: bounded(entry.entryId),
1428
+ parentId: bounded(entry.parentId),
1429
+ type: bounded(entry.type),
1430
+ role: bounded(entry.role),
1431
+ timestamp: entry.timestamp,
1432
+ isError: entry.isError,
1433
+ ...anchorIndex !== null ? { anchor: entry.index === anchorIndex } : {},
1434
+ text: chunk,
1435
+ textRange: {
1436
+ start: currentTextOffset,
1437
+ end,
1438
+ total: entry.text.length,
1439
+ complete: textComplete
1440
+ },
1441
+ ...entry.parentEntryId !== void 0 ? { parentEntryId: bounded(entry.parentEntryId) } : {},
1442
+ ...entry.operationAddress ? { operationAddress: bounded(entry.operationAddress) } : {},
1443
+ ...entry.toolName ? { tool: bounded(entry.toolName) } : {},
1444
+ ...entry.ref ? { ref: bounded(entry.ref) } : {},
1445
+ ...entry.provider ? { provider: bounded(entry.provider) } : {},
1446
+ ...entry.action ? { action: bounded(entry.action) } : {},
1447
+ ...entry.outcome ? { outcome: entry.outcome } : {},
1448
+ ...entry.filesTouched ? { filesTouched: entry.filesTouched.slice(0, 20).map((file) => bounded(file, 1024)) } : {},
1449
+ ...operation !== void 0 ? { operation } : {},
1450
+ ...branchFact !== void 0 ? { branchFact } : {},
1451
+ ...entry.operation !== void 0 && operation === void 0 || entry.branchFact !== void 0 && branchFact === void 0 ? { structuredTruncated: true } : {},
1452
+ ...entry.factAddress ? { factAddress: bounded(entry.factAddress) } : {},
1453
+ ...entry.carrierEntryId ? { carrierEntryId: bounded(entry.carrierEntryId) } : {},
1454
+ ...entry.carrierParentId !== void 0 ? { carrierParentId: bounded(entry.carrierParentId) } : {},
1455
+ ...entry.carrierFromId !== void 0 ? { carrierFromId: bounded(entry.carrierFromId) } : {}
1456
+ });
1457
+ remainingChars -= chunk.length;
1458
+ if (!textComplete) {
1459
+ currentTextOffset = end;
1460
+ cursors.push({ position, textOffset: currentTextOffset });
1461
+ break;
1462
+ }
1463
+ position += 1;
1464
+ currentTextOffset = 0;
1465
+ cursors.push({ position, textOffset: 0 });
1466
+ }
1467
+ const responseAt = (records, cursor2) => {
1468
+ const hasNext = cursor2.position < selected.length;
1469
+ const nextArgs = hasNext ? {
1470
+ ...sourceId ? { source: sourceId } : {},
1471
+ session: ref.file,
1472
+ expectedSourceHash: finalState.sourceHash,
1473
+ expectedLineageFingerprint: finalLineage.fingerprint,
1474
+ branches,
1475
+ ...canonicalSelection,
1476
+ entryOffset: cursor2.position,
1477
+ ...cursor2.textOffset > 0 ? { textOffset: cursor2.textOffset } : {},
1478
+ maxChars,
1479
+ maxEntries
1480
+ } : null;
1481
+ return {
1482
+ session: ref.file,
1483
+ sourceHash: finalState.sourceHash,
1484
+ branches,
1485
+ lineageFingerprint: finalLineage.fingerprint,
1486
+ entryCount,
1487
+ entries: records,
1488
+ next: nextArgs ? { ref: "memory.expand", args: nextArgs } : null
1489
+ };
1490
+ };
1491
+ let cursor = { position, textOffset: currentTextOffset };
1492
+ let response = responseAt(output, cursor);
1493
+ while (output.length > 1 && JSON.stringify(response).length > RECALL_MAX_RESPONSE_CHARS) {
1494
+ output.pop();
1495
+ cursors.pop();
1496
+ cursor = cursors.at(-1) ?? { position: entryOffset, textOffset };
1497
+ response = responseAt(output, cursor);
1498
+ }
1499
+ if (output.length === 1 && JSON.stringify(response).length > RECALL_MAX_RESPONSE_CHARS) {
1500
+ const record = output[0];
1501
+ const range = record.textRange;
1502
+ const chunk = record.text;
1503
+ const excess = JSON.stringify(response).length - RECALL_MAX_RESPONSE_CHARS;
1504
+ let keep = Math.max(1, chunk.length - excess - 256);
1505
+ if (keep < chunk.length && keep > 0 && chunk.charCodeAt(keep) >= 56320 && chunk.charCodeAt(keep) <= 57343) {
1506
+ keep -= 1;
1507
+ }
1508
+ if (keep > 0 && keep < chunk.length) {
1509
+ record.text = chunk.slice(0, keep);
1510
+ range.end = range.start + keep;
1511
+ range.complete = false;
1512
+ cursor = { position: entryOffset, textOffset: range.end };
1513
+ response = responseAt(output, cursor);
1514
+ }
1515
+ if (JSON.stringify(response).length > RECALL_MAX_RESPONSE_CHARS) {
1516
+ delete record.operation;
1517
+ delete record.branchFact;
1518
+ if (Array.isArray(record.filesTouched)) {
1519
+ record.filesTouched = record.filesTouched.slice(0, 4).map((file) => bounded(String(file), 256));
1520
+ }
1521
+ record.structuredTruncated = true;
1522
+ response = responseAt(output, cursor);
1523
+ }
1524
+ if (JSON.stringify(response).length > RECALL_MAX_RESPONSE_CHARS) {
1525
+ const current = String(record.text);
1526
+ const firstCodePointChars = (current.codePointAt(0) ?? 0) > 65535 ? 2 : 1;
1527
+ const minimalText = current.slice(0, Math.min(current.length, firstCodePointChars));
1528
+ const minimalRange = record.textRange;
1529
+ minimalRange.end = minimalRange.start + minimalText.length;
1530
+ minimalRange.complete = minimalRange.end >= minimalRange.total;
1531
+ output[0] = {
1532
+ index: record.index,
1533
+ entryId: record.entryId,
1534
+ parentId: record.parentId,
1535
+ type: record.type,
1536
+ role: record.role,
1537
+ timestamp: record.timestamp,
1538
+ isError: record.isError,
1539
+ ...record.anchor !== void 0 ? { anchor: record.anchor } : {},
1540
+ text: minimalText,
1541
+ textRange: minimalRange,
1542
+ structuredTruncated: true
1543
+ };
1544
+ cursor = minimalRange.complete ? { position: entryOffset + 1, textOffset: 0 } : { position: entryOffset, textOffset: minimalRange.end };
1545
+ response = responseAt(output, cursor);
1546
+ }
1547
+ }
1548
+ const endingObservation = access.observe(branches);
1549
+ if (!endingObservation || !sameSourceObservation(snapshot.observation, endingObservation)) {
1550
+ cache.forgetExpansionSnapshot(snapshot);
1551
+ const actualState = access.state();
1552
+ const actualLineage = access.lineage(branches);
1553
+ if (!actualState || !endingObservation || actualState.sourceHash !== snapshot.sourceHash || actualLineage.fingerprint !== snapshot.lineageFingerprint) {
1554
+ return {
1555
+ session: ref.file,
1556
+ error: stalePointerError(
1557
+ ref.file,
1558
+ expectedSourceHash ?? snapshot.sourceHash,
1559
+ actualState?.sourceHash ?? "",
1560
+ expectedLineageFingerprint ?? snapshot.lineageFingerprint,
1561
+ actualLineage.fingerprint
1562
+ ),
1563
+ entries: []
1564
+ };
1565
+ }
1566
+ snapshot.observation = endingObservation;
1567
+ }
1568
+ if (response.next === null) {
1569
+ cache.forgetExpansionSnapshot(snapshot);
1570
+ } else {
1571
+ snapshot.touchedAt = Date.now();
1572
+ cache.rememberExpansionSnapshot(snapshot);
1573
+ }
1574
+ return response;
1575
+ }
1576
+
1577
+ // src/memory/sessions-service.ts
1578
+ async function processMemorySessions(args, context, signal) {
1579
+ const sourceId = typeof args.source === "string" && args.source.length > 0 ? args.source : void 0;
1580
+ const scope = typeof args.scope === "string" ? args.scope : void 0;
1581
+ const branches = parseBranches(args.branches, "memory.sessions");
1582
+ const limit = typeof args.limit === "number" && Number.isSafeInteger(args.limit) && args.limit >= 1 ? Math.min(args.limit, SESSIONS_MAX) : SESSIONS_MAX;
1583
+ if (sourceId !== void 0) {
1584
+ try {
1585
+ const source = resolveRegisteredSource(context.sources, sourceId);
1586
+ const { snapshots, coverageReasons: coverageReasons2 } = await listHostSnapshots(source, limit, "list", signal);
1587
+ const options2 = resolveIndexOptions(context.config, context.agentDir, branches);
1588
+ const index2 = loadHostTieredIndex(snapshots, options2, false, void 0, coverageReasons2);
1589
+ const shards2 = new Map(index2.shards.map((shard) => [shard.sessionFile, shard]));
1590
+ const digests2 = new Map(index2.digests.map((digest) => [digest.file, digest]));
1591
+ const sessions2 = snapshots.map((snapshot) => {
1592
+ const tier = index2.tiers.get(snapshot.displayKey) ?? "cold";
1593
+ const shard = shards2.get(snapshot.displayKey);
1594
+ const digest = digests2.get(snapshot.displayKey);
1595
+ return {
1596
+ id: shard?.sessionId ?? digest?.sessionId ?? snapshot.sessionId,
1597
+ file: snapshot.displayKey,
1598
+ cwd: digest?.cwd ?? snapshot.metadata.cwd ?? "",
1599
+ mtime: snapshot.metadata.updatedAt ?? 0,
1600
+ entryCount: shard?.entries.length ?? digest?.entryCount ?? 0,
1601
+ tier,
1602
+ branches,
1603
+ lineageFingerprint: shard?.lineageFingerprint ?? digest?.lineageFingerprint ?? null
1604
+ };
1605
+ });
1606
+ return {
1607
+ scope: `source:${sourceId}`,
1608
+ branches,
1609
+ sessions: sessions2,
1610
+ ...index2.coverage.complete ? {} : { coverage: index2.coverage }
1611
+ };
1612
+ } catch (error) {
1613
+ const failure = memorySourceFailure(error);
1614
+ if (!failure) throw error;
1615
+ return {
1616
+ scope: `source:${sourceId}`,
1617
+ branches,
1618
+ sessions: [],
1619
+ error: failure
1620
+ };
1621
+ }
1622
+ }
1623
+ const refs = resolveRefs(scope, context, true).slice(0, limit);
1624
+ const options = resolveIndexOptions(
1625
+ context.config,
1626
+ context.agentDir,
1627
+ branches,
1628
+ liveBranchResolver(context)
1629
+ );
1630
+ const index = loadTieredIndex(refs, resolveTierRefs(refs, context), options);
1631
+ const shards = new Map(index.shards.map((shard) => [shard.sessionFile, shard]));
1632
+ const digests = new Map(index.digests.map((digest) => [digest.file, digest]));
1633
+ const sessions = refs.map((ref) => {
1634
+ const tier = index.tiers.get(ref.file) ?? "cold";
1635
+ const shard = shards.get(ref.file);
1636
+ const digest = digests.get(ref.file);
1637
+ return {
1638
+ id: shard?.sessionId ?? digest?.sessionId ?? ref.id,
1639
+ file: ref.file,
1640
+ cwd: digest?.cwd ?? ref.cwd,
1641
+ mtime: ref.mtime,
1642
+ entryCount: shard?.entries.length ?? digest?.entryCount ?? 0,
1643
+ tier,
1644
+ branches,
1645
+ lineageFingerprint: shard?.lineageFingerprint ?? digest?.lineageFingerprint ?? null
1646
+ };
1647
+ });
1648
+ return { scope: scope ?? "session", branches, sessions };
1649
+ }
1650
+
1651
+ // src/providers/memory-provider.ts
1652
+ var errorOutputSchema = {
1653
+ type: "object",
1654
+ properties: {
1655
+ code: { type: "string" },
1656
+ message: { type: "string" }
1657
+ },
1658
+ required: ["code", "message"]
1659
+ };
1660
+ var coverageOutputSchema = {
1661
+ type: "object",
1662
+ properties: {
1663
+ complete: { type: "boolean" },
1664
+ indexedSessions: { type: "number" },
1665
+ eligibleSessions: { type: "number" },
1666
+ staleSessions: { type: "number" },
1667
+ incompleteSessions: { type: "number" },
1668
+ reasons: {
1669
+ type: "array",
1670
+ items: { type: "string" },
1671
+ description: "Stable machine-readable incompleteness codes; empty when complete is true."
1672
+ },
1673
+ error: errorOutputSchema
1674
+ },
1675
+ required: [
1676
+ "complete",
1677
+ "indexedSessions",
1678
+ "eligibleSessions",
1679
+ "staleSessions",
1680
+ "incompleteSessions",
1681
+ "reasons"
1682
+ ]
1683
+ };
1684
+ var callOutputSchema = (ref) => ({
1685
+ type: "object",
1686
+ properties: {
1687
+ ref: { const: ref },
1688
+ args: { type: "object" }
1689
+ },
1690
+ required: ["ref", "args"]
1691
+ });
1692
+ var recallEntryOutputSchema = {
1693
+ type: "object",
1694
+ properties: {
1695
+ kind: { const: "entry" },
1696
+ sessionId: { type: "string" },
1697
+ tier: { type: "string", enum: ["hot", "cold"] },
1698
+ index: { type: "number" },
1699
+ entryId: { type: ["string", "null"] },
1700
+ parentId: { type: ["string", "null"] },
1701
+ operationAddress: { type: ["string", "null"] },
1702
+ type: { type: "string" },
1703
+ role: { type: ["string", "null"] },
1704
+ tool: { type: ["string", "null"] },
1705
+ ref: { type: ["string", "null"] },
1706
+ provider: { type: ["string", "null"] },
1707
+ action: { type: ["string", "null"] },
1708
+ timestamp: { type: ["number", "null"] },
1709
+ isError: { type: "boolean" },
1710
+ outcome: { type: "string", enum: ["succeeded", "failed", "aborted", "timed_out"] },
1711
+ score: { type: "number" },
1712
+ snippet: { type: "string" },
1713
+ truncated: { type: "boolean" },
1714
+ follow: callOutputSchema("memory.expand")
1715
+ },
1716
+ required: [
1717
+ "kind",
1718
+ "sessionId",
1719
+ "tier",
1720
+ "index",
1721
+ "entryId",
1722
+ "parentId",
1723
+ "operationAddress",
1724
+ "type",
1725
+ "role",
1726
+ "tool",
1727
+ "ref",
1728
+ "provider",
1729
+ "action",
1730
+ "timestamp",
1731
+ "isError",
1732
+ "score",
1733
+ "snippet",
1734
+ "truncated",
1735
+ "follow"
1736
+ ]
1737
+ };
1738
+ var recallSessionOutputSchema = {
1739
+ type: "object",
1740
+ properties: {
1741
+ kind: { const: "session" },
1742
+ sessionId: { type: "string" },
1743
+ tier: { const: "cold" },
1744
+ cwd: { type: "string" },
1745
+ lastTimestamp: { type: ["number", "null"] },
1746
+ score: { type: "number" },
1747
+ matchedTerms: { type: "number" },
1748
+ matchedStructuralEntries: { type: "number" },
1749
+ follow: callOutputSchema("memory.recall")
1750
+ },
1751
+ required: [
1752
+ "kind",
1753
+ "sessionId",
1754
+ "tier",
1755
+ "cwd",
1756
+ "lastTimestamp",
1757
+ "score",
1758
+ "matchedTerms",
1759
+ "matchedStructuralEntries",
1760
+ "follow"
1761
+ ]
1762
+ };
1763
+ var recallOutputSchema = {
1764
+ type: "object",
1765
+ description: "Bounded ranked memory hits with uniform follow and pagination calls.",
1766
+ properties: {
1767
+ total: { type: "number" },
1768
+ hits: {
1769
+ type: "array",
1770
+ description: "Call tools.call(hit.follow) to expand an entry or resolve a cold session.",
1771
+ items: { oneOf: [recallEntryOutputSchema, recallSessionOutputSchema] }
1772
+ },
1773
+ next: {
1774
+ oneOf: [callOutputSchema("memory.recall"), { type: "null" }],
1775
+ description: "When non-null, call tools.call(next)."
1776
+ },
1777
+ coverage: coverageOutputSchema,
1778
+ error: errorOutputSchema
1779
+ },
1780
+ required: ["total", "hits", "next", "coverage"]
1781
+ };
1782
+ var expandOutputSchema = {
1783
+ type: "object",
1784
+ description: "Integrity-bound session entries returned as lossless bounded text chunks.",
1785
+ properties: {
1786
+ session: { type: "string" },
1787
+ sourceHash: { type: "string" },
1788
+ branches: { type: "string", enum: ["active", "all"] },
1789
+ lineageFingerprint: { type: "string" },
1790
+ entryCount: { type: "number" },
1791
+ entries: {
1792
+ type: "array",
1793
+ items: {
1794
+ type: "object",
1795
+ properties: {
1796
+ index: { type: "number" },
1797
+ entryId: { type: ["string", "null"] },
1798
+ parentId: { type: ["string", "null"] },
1799
+ type: { type: ["string", "null"] },
1800
+ role: { type: ["string", "null"] },
1801
+ timestamp: { type: ["number", "null"] },
1802
+ isError: { type: "boolean" },
1803
+ text: { type: "string" },
1804
+ textRange: {
1805
+ type: "object",
1806
+ properties: {
1807
+ start: { type: "number" },
1808
+ end: { type: "number" },
1809
+ total: { type: "number" },
1810
+ complete: { type: "boolean" }
1811
+ },
1812
+ required: ["start", "end", "total", "complete"]
1813
+ },
1814
+ anchor: { type: "boolean" },
1815
+ parentEntryId: { type: ["string", "null"] },
1816
+ operationAddress: { type: ["string", "null"] },
1817
+ tool: { type: ["string", "null"] },
1818
+ ref: { type: ["string", "null"] },
1819
+ provider: { type: ["string", "null"] },
1820
+ action: { type: ["string", "null"] },
1821
+ outcome: { type: "string", enum: ["succeeded", "failed", "aborted", "timed_out"] },
1822
+ filesTouched: { type: "array", items: { type: ["string", "null"] } },
1823
+ operation: { type: "object" },
1824
+ branchFact: { type: "object" },
1825
+ structuredTruncated: { type: "boolean" },
1826
+ factAddress: { type: ["string", "null"] },
1827
+ carrierEntryId: { type: ["string", "null"] },
1828
+ carrierParentId: { type: ["string", "null"] },
1829
+ carrierFromId: { type: ["string", "null"] }
1830
+ },
1831
+ required: ["index", "entryId", "parentId", "type", "role", "timestamp", "isError", "text", "textRange"]
1832
+ }
1833
+ },
1834
+ next: {
1835
+ oneOf: [callOutputSchema("memory.expand"), { type: "null" }],
1836
+ description: "When non-null, call tools.call(next)."
1837
+ },
1838
+ error: errorOutputSchema
1839
+ },
1840
+ required: ["entries"]
1841
+ };
1842
+ var sessionsOutputSchema = {
1843
+ type: "object",
1844
+ properties: {
1845
+ scope: { type: "string" },
1846
+ branches: { type: "string", enum: ["active", "all"] },
1847
+ sessions: {
1848
+ type: "array",
1849
+ items: {
1850
+ type: "object",
1851
+ properties: {
1852
+ id: { type: "string" },
1853
+ file: { type: "string" },
1854
+ cwd: { type: "string" },
1855
+ mtime: { type: "number" },
1856
+ entryCount: { type: "number" },
1857
+ tier: { type: "string", enum: ["hot", "cold"] },
1858
+ branches: { type: "string", enum: ["active", "all"] },
1859
+ lineageFingerprint: { type: ["string", "null"] }
1860
+ },
1861
+ required: [
1862
+ "id",
1863
+ "file",
1864
+ "cwd",
1865
+ "mtime",
1866
+ "entryCount",
1867
+ "tier",
1868
+ "branches",
1869
+ "lineageFingerprint"
1870
+ ]
1871
+ }
1872
+ },
1873
+ error: errorOutputSchema
1874
+ }
1875
+ };
1876
+ var SOURCE_ARG_SCHEMA = {
1877
+ type: "string",
1878
+ minLength: 1,
1879
+ description: "Registered portable memory source id. When set, the call resolves against that source only \u2014 filesystem scopes are never consulted and there is no filesystem fallback."
1880
+ };
1881
+ var memoryActionDescriptors = [
1882
+ {
1883
+ name: "recall",
1884
+ description: "Search session memory as bounded ranked snippets. Literal queries rank any matching term by default; queryMatch all narrows to co-located terms. Call tools.call(hit.follow) for either an exact entry or a cold-session candidate, and tools.call(next) to continue.",
1885
+ inputSchema: {
1886
+ type: "object",
1887
+ properties: {
1888
+ source: SOURCE_ARG_SCHEMA,
1889
+ query: { type: "string", maxLength: 4096 },
1890
+ queryMode: {
1891
+ type: "string",
1892
+ enum: ["literal", "phrase", "regex"],
1893
+ default: "literal",
1894
+ description: "Canonical tokens (default), one case-insensitive exact phrase, or explicitly bounded regex."
1895
+ },
1896
+ queryMatch: {
1897
+ type: "string",
1898
+ enum: ["all", "any"],
1899
+ default: "any",
1900
+ description: "For literal mode, accept any term (default) or require all terms in one hot entry."
1901
+ },
1902
+ expectedSourceHash: {
1903
+ type: "string",
1904
+ description: "SHA-256 from a prior pointer; stale sources are refused."
1905
+ },
1906
+ expectedLineageFingerprint: {
1907
+ type: "string",
1908
+ description: "Active-lineage fingerprint from a prior pointer; changed leaves are refused."
1909
+ },
1910
+ branches: {
1911
+ type: "string",
1912
+ enum: ["active", "all"],
1913
+ description: "Search the active parent-linked path (default) or every branch."
1914
+ },
1915
+ scope: {
1916
+ type: "string",
1917
+ description: "session | project | global | session:<id-or-path>. Defaults to session."
1918
+ },
1919
+ offset: {
1920
+ type: "number",
1921
+ minimum: 0,
1922
+ description: "Exact ranked-hit offset, normally copied from next.args."
1923
+ },
1924
+ pageSize: { type: "number", minimum: 1, maximum: RECALL_MAX_PAGE_SIZE, default: RECALL_DEFAULT_PAGE_SIZE },
1925
+ snippetChars: {
1926
+ type: "number",
1927
+ minimum: 80,
1928
+ maximum: RECALL_MAX_SNIPPET_CHARS,
1929
+ default: RECALL_DEFAULT_SNIPPET_CHARS,
1930
+ description: "Maximum indexed-text characters shown per hit; full text remains in memory.expand."
1931
+ },
1932
+ role: {
1933
+ type: "string",
1934
+ enum: [
1935
+ "assistant",
1936
+ "bashExecution",
1937
+ "branchCustomMessage",
1938
+ "branchSummary",
1939
+ "branchUser",
1940
+ "compaction",
1941
+ "compactionSummary",
1942
+ "custom",
1943
+ "fabricOperation",
1944
+ "fabricPhase",
1945
+ "fabricRun",
1946
+ "toolResult",
1947
+ "user"
1948
+ ],
1949
+ description: "Exact normalized entry role to filter by: the closed set the session normalizer can produce."
1950
+ },
1951
+ tool: { type: "string" },
1952
+ ref: {
1953
+ type: "string",
1954
+ minLength: 1,
1955
+ description: "Exact persisted Fabric action ref, such as pi.grep. This is structural selection, not lexical expansion."
1956
+ },
1957
+ provider: {
1958
+ type: "string",
1959
+ minLength: 1,
1960
+ description: "Exact persisted Fabric provider identity."
1961
+ },
1962
+ action: {
1963
+ type: "string",
1964
+ minLength: 1,
1965
+ description: "Exact persisted Fabric action name."
1966
+ },
1967
+ outcome: {
1968
+ type: "string",
1969
+ enum: ["succeeded", "failed", "aborted", "timed_out"],
1970
+ description: "Exact persisted Fabric execution outcome."
1971
+ },
1972
+ since: { type: "number" },
1973
+ until: { type: "number" },
1974
+ entryRange: {
1975
+ type: "object",
1976
+ description: "Inclusive normalized-entry range for an explicit session:<id> resolution.",
1977
+ properties: {
1978
+ first: { type: "number", minimum: 0 },
1979
+ last: { type: "number", minimum: 0 }
1980
+ },
1981
+ required: ["first", "last"],
1982
+ additionalProperties: false
1983
+ }
1984
+ },
1985
+ additionalProperties: false
1986
+ },
1987
+ outputSchema: recallOutputSchema,
1988
+ risk: "read",
1989
+ namespace: "memory"
1990
+ },
1991
+ {
1992
+ name: "expand",
1993
+ description: "Read exact normalized session entries and nearby context as bounded lossless chunks. Call tools.call(next) to continue, or use guest-side memory.walk(args, visitor) to traverse complete reassembled entries.",
1994
+ inputSchema: {
1995
+ type: "object",
1996
+ properties: {
1997
+ source: SOURCE_ARG_SCHEMA,
1998
+ session: { type: "string", description: "Exact session file path, unambiguous id, or source session key." },
1999
+ expectedSourceHash: {
2000
+ type: "string",
2001
+ description: "SHA-256 from a prior pointer; stale sources are refused."
2002
+ },
2003
+ expectedLineageFingerprint: {
2004
+ type: "string",
2005
+ description: "Active-lineage fingerprint from a prior pointer; changed leaves are refused."
2006
+ },
2007
+ branches: {
2008
+ type: "string",
2009
+ enum: ["active", "all"],
2010
+ description: "Expand on the active parent-linked path (default) or across every branch."
2011
+ },
2012
+ indices: { type: "array", maxItems: EXPAND_MAX_EXACT_SELECTORS, items: { type: "number", minimum: 0 } },
2013
+ entryIds: { type: "array", maxItems: EXPAND_MAX_EXACT_SELECTORS, items: { type: "string", maxLength: 512 } },
2014
+ operationAddresses: { type: "array", maxItems: EXPAND_MAX_EXACT_SELECTORS, items: { type: "string", maxLength: 512 } },
2015
+ entryRange: {
2016
+ type: "object",
2017
+ properties: {
2018
+ first: { type: "number", minimum: 0 },
2019
+ last: { type: "number", minimum: 0 }
2020
+ },
2021
+ required: ["first", "last"],
2022
+ additionalProperties: false
2023
+ },
2024
+ before: {
2025
+ type: "number",
2026
+ minimum: 0,
2027
+ maximum: EXPAND_MAX_CONTEXT,
2028
+ default: 0,
2029
+ description: "Entries before one exact selected anchor."
2030
+ },
2031
+ after: {
2032
+ type: "number",
2033
+ minimum: 0,
2034
+ maximum: EXPAND_MAX_CONTEXT,
2035
+ default: 0,
2036
+ description: "Entries after one exact selected anchor."
2037
+ },
2038
+ entryOffset: {
2039
+ type: "number",
2040
+ minimum: 0,
2041
+ description: "Continuation offset within the resolved selection; copy from next.args."
2042
+ },
2043
+ textOffset: {
2044
+ type: "number",
2045
+ minimum: 0,
2046
+ description: "Continuation offset within the first returned entry; copy from next.args."
2047
+ },
2048
+ maxChars: {
2049
+ type: "number",
2050
+ minimum: 256,
2051
+ maximum: EXPAND_MAX_CHARS,
2052
+ default: EXPAND_DEFAULT_MAX_CHARS,
2053
+ description: "Total entry-text characters returned in this chunk."
2054
+ },
2055
+ maxEntries: {
2056
+ type: "number",
2057
+ minimum: 1,
2058
+ maximum: EXPAND_MAX_ENTRIES,
2059
+ default: EXPAND_DEFAULT_MAX_ENTRIES,
2060
+ description: "Maximum complete or partial entries returned in this chunk."
2061
+ }
2062
+ },
2063
+ required: ["session"],
2064
+ additionalProperties: false
2065
+ },
2066
+ outputSchema: expandOutputSchema,
2067
+ risk: "read",
2068
+ namespace: "memory"
2069
+ },
2070
+ {
2071
+ name: "sessions",
2072
+ description: "List known sessions in scope with id, file, cwd, mtime, entry count, and hot/cold tier.",
2073
+ inputSchema: {
2074
+ type: "object",
2075
+ properties: {
2076
+ source: SOURCE_ARG_SCHEMA,
2077
+ scope: { type: "string" },
2078
+ branches: {
2079
+ type: "string",
2080
+ enum: ["active", "all"],
2081
+ description: "Count the active parent-linked path (default) or every branch."
2082
+ },
2083
+ limit: {
2084
+ type: "number",
2085
+ minimum: 1,
2086
+ description: "Maximum sessions returned; capped at the internal session ceiling."
2087
+ }
2088
+ },
2089
+ additionalProperties: false
2090
+ },
2091
+ outputSchema: sessionsOutputSchema,
2092
+ risk: "read",
2093
+ namespace: "memory"
2094
+ }
2095
+ ];
2096
+ var descriptors = memoryActionDescriptors;
2097
+ var MEMORY_SCOPE_VALUE_ALIASES = {
2098
+ cwd: "project",
2099
+ repo: "project",
2100
+ directory: "project",
2101
+ folder: "project",
2102
+ all: "global",
2103
+ current: "session"
2104
+ };
2105
+ var MEMORY_ARG_NORMALIZATION = {
2106
+ recall: { values: { scope: MEMORY_SCOPE_VALUE_ALIASES } },
2107
+ sessions: { values: { scope: MEMORY_SCOPE_VALUE_ALIASES } }
2108
+ };
2109
+ var normalizeMemoryArgs = actionArgNormalizer(
2110
+ () => descriptors,
2111
+ MEMORY_ARG_NORMALIZATION
2112
+ );
2113
+ var memoryActionSchemas = Object.fromEntries(
2114
+ descriptors.map((descriptor) => [
2115
+ descriptor.name,
2116
+ { inputSchema: descriptor.inputSchema, outputSchema: descriptor.outputSchema }
2117
+ ])
2118
+ );
2119
+ var MemoryProvider = class {
2120
+ constructor(context) {
2121
+ this.context = context;
2122
+ }
2123
+ name = "memory";
2124
+ description = "Cross-session memory: a search engine over every Pi session timeline on this machine";
2125
+ cache = new MemoryRequestCache();
2126
+ async list(request, _context) {
2127
+ const query = request.query?.toLowerCase();
2128
+ return query ? descriptors.filter(
2129
+ (descriptor) => `${descriptor.name} ${descriptor.description}`.toLowerCase().includes(query)
2130
+ ) : descriptors;
2131
+ }
2132
+ async describe(actionName, _context) {
2133
+ return descriptors.find((descriptor) => descriptor.name === actionName);
2134
+ }
2135
+ prepareArguments(actionName, args) {
2136
+ return normalizeMemoryArgs(actionName, args);
2137
+ }
2138
+ async invoke(actionName, args, invocationContext) {
2139
+ try {
2140
+ switch (actionName) {
2141
+ case "recall":
2142
+ return await processMemoryRecall(args, invocationContext, this.context, this.cache);
2143
+ case "expand":
2144
+ return await processMemoryExpand(args, this.context, this.cache, invocationContext.signal);
2145
+ case "sessions":
2146
+ return await processMemorySessions(args, this.context, invocationContext.signal);
2147
+ default:
2148
+ throw new Error(`Unknown memory action: ${actionName}`);
2149
+ }
2150
+ } catch (error) {
2151
+ if (error instanceof AmbiguousSessionError) {
2152
+ const detail = {
2153
+ code: error.code,
2154
+ message: error.message,
2155
+ session: error.session,
2156
+ candidates: error.candidates
2157
+ };
2158
+ if (actionName === "recall") return recallFailure(detail);
2159
+ if (actionName === "expand") return { entries: [], next: null, error: detail };
2160
+ return { error: detail };
2161
+ }
2162
+ throw error;
2163
+ }
2164
+ }
2165
+ };
2166
+
2167
+ export {
2168
+ MemoryRequestCache,
2169
+ MEMORY_SOURCE_INTERFACE_VERSION,
2170
+ MemorySourceError,
2171
+ defineMemorySource,
2172
+ createMemorySourceRegistry,
2173
+ processMemoryRecall,
2174
+ processMemoryExpand,
2175
+ processMemorySessions,
2176
+ memoryActionDescriptors,
2177
+ normalizeMemoryArgs,
2178
+ memoryActionSchemas,
2179
+ MemoryProvider
2180
+ };
2181
+ //# sourceMappingURL=chunk-UQ4LTUH4.js.map