@theokit/sdk 4.37.2 → 4.38.0

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 (364) hide show
  1. package/CHANGELOG.md +72 -72
  2. package/dist/agent-2GZC4W2A.cjs +51 -0
  3. package/dist/{agent-IE6IE4NW.cjs.map → agent-2GZC4W2A.cjs.map} +1 -1
  4. package/dist/agent-3H3UKD6U.js +42 -0
  5. package/dist/{agent-DW2J37IH.js.map → agent-3H3UKD6U.js.map} +1 -1
  6. package/dist/{agent-SmxntivO.d.ts → agent-C3AEtM-W.d.ts} +39 -37
  7. package/dist/{agent-DGv1-d81.d.cts → agent-U3lBX-5t.d.cts} +39 -37
  8. package/dist/agent.d.ts +1 -1
  9. package/dist/auth/index.cjs +15 -15
  10. package/dist/auth/index.js +4 -4
  11. package/dist/{batch-SY5GZLFD.js → batch-LXSALQC3.js} +9 -9
  12. package/dist/{batch-SY5GZLFD.js.map → batch-LXSALQC3.js.map} +1 -1
  13. package/dist/{batch-3SEPDXCU.cjs → batch-NZGN6SFV.cjs} +23 -23
  14. package/dist/{batch-3SEPDXCU.cjs.map → batch-NZGN6SFV.cjs.map} +1 -1
  15. package/dist/{chunk-D4ZUJTFB.cjs → chunk-2K7PRHDB.cjs} +8 -8
  16. package/dist/{chunk-D4ZUJTFB.cjs.map → chunk-2K7PRHDB.cjs.map} +1 -1
  17. package/dist/chunk-2R6NBT5F.cjs +112 -0
  18. package/dist/chunk-2R6NBT5F.cjs.map +1 -0
  19. package/dist/{chunk-2423XDPT.cjs → chunk-3BSP7LSG.cjs} +26 -26
  20. package/dist/{chunk-2423XDPT.cjs.map → chunk-3BSP7LSG.cjs.map} +1 -1
  21. package/dist/{chunk-6EDQBX7U.cjs → chunk-3MUIYMUG.cjs} +17 -17
  22. package/dist/{chunk-6EDQBX7U.cjs.map → chunk-3MUIYMUG.cjs.map} +1 -1
  23. package/dist/{chunk-P34DHHYQ.cjs → chunk-3VKTDQMX.cjs} +34 -27
  24. package/dist/chunk-3VKTDQMX.cjs.map +1 -0
  25. package/dist/{chunk-77WHPVXE.js → chunk-3XKVRLR2.js} +4 -4
  26. package/dist/chunk-3XKVRLR2.js.map +1 -0
  27. package/dist/{chunk-SWIBQFPH.cjs → chunk-3XRXORBS.cjs} +4 -4
  28. package/dist/{chunk-SWIBQFPH.cjs.map → chunk-3XRXORBS.cjs.map} +1 -1
  29. package/dist/{chunk-DCJ5MCJ3.js → chunk-4APWS2YF.js} +7 -7
  30. package/dist/{chunk-DCJ5MCJ3.js.map → chunk-4APWS2YF.js.map} +1 -1
  31. package/dist/{chunk-56ZM6P7Z.cjs → chunk-4MWBKBS4.cjs} +12 -12
  32. package/dist/chunk-4MWBKBS4.cjs.map +1 -0
  33. package/dist/chunk-4NVV3GRU.js +110 -0
  34. package/dist/chunk-4NVV3GRU.js.map +1 -0
  35. package/dist/{chunk-QGDKZDPN.js → chunk-4WIJSKFA.js} +3 -3
  36. package/dist/{chunk-QGDKZDPN.js.map → chunk-4WIJSKFA.js.map} +1 -1
  37. package/dist/{chunk-VNNK6AKU.js → chunk-5BVBNE2F.js} +3 -3
  38. package/dist/chunk-5BVBNE2F.js.map +1 -0
  39. package/dist/{chunk-EEZ7CFMM.js → chunk-5KOW3GLE.js} +2 -2
  40. package/dist/chunk-5KOW3GLE.js.map +1 -0
  41. package/dist/{chunk-FK4EJD2I.cjs → chunk-6OIO4FYX.cjs} +7 -7
  42. package/dist/{chunk-FK4EJD2I.cjs.map → chunk-6OIO4FYX.cjs.map} +1 -1
  43. package/dist/{chunk-IEUDKUPM.cjs → chunk-6OKPJZMX.cjs} +8 -8
  44. package/dist/{chunk-IEUDKUPM.cjs.map → chunk-6OKPJZMX.cjs.map} +1 -1
  45. package/dist/{chunk-QFMXXUUT.js → chunk-6XZBKFQ7.js} +3 -3
  46. package/dist/{chunk-QFMXXUUT.js.map → chunk-6XZBKFQ7.js.map} +1 -1
  47. package/dist/{chunk-H5YVJB4K.cjs → chunk-6ZGD7R27.cjs} +37 -37
  48. package/dist/chunk-6ZGD7R27.cjs.map +1 -0
  49. package/dist/{chunk-HEN5WXXI.js → chunk-7QDTZJRV.js} +6 -6
  50. package/dist/{chunk-HEN5WXXI.js.map → chunk-7QDTZJRV.js.map} +1 -1
  51. package/dist/{chunk-MHCKWQR3.cjs → chunk-A3MHE2MQ.cjs} +8 -8
  52. package/dist/{chunk-MHCKWQR3.cjs.map → chunk-A3MHE2MQ.cjs.map} +1 -1
  53. package/dist/{chunk-5SB4V74H.js → chunk-A4XXV2C6.js} +18 -18
  54. package/dist/chunk-A4XXV2C6.js.map +1 -0
  55. package/dist/{chunk-6VP3XGEK.js → chunk-A6GXYF2Q.js} +9 -9
  56. package/dist/{chunk-6VP3XGEK.js.map → chunk-A6GXYF2Q.js.map} +1 -1
  57. package/dist/{chunk-SDIBMLL5.js → chunk-ACHGT3D2.js} +8 -8
  58. package/dist/{chunk-SDIBMLL5.js.map → chunk-ACHGT3D2.js.map} +1 -1
  59. package/dist/{chunk-XAEAMI5H.js → chunk-AOZYORH7.js} +4 -4
  60. package/dist/chunk-AOZYORH7.js.map +1 -0
  61. package/dist/{chunk-LTCOPATU.cjs → chunk-BE3W4HYV.cjs} +2 -2
  62. package/dist/chunk-BE3W4HYV.cjs.map +1 -0
  63. package/dist/{chunk-NQ4AC2U4.cjs → chunk-BT6DFWZB.cjs} +9 -9
  64. package/dist/{chunk-NQ4AC2U4.cjs.map → chunk-BT6DFWZB.cjs.map} +1 -1
  65. package/dist/{chunk-XAYVHS2B.cjs → chunk-BUGVDCI5.cjs} +4 -4
  66. package/dist/{chunk-XAYVHS2B.cjs.map → chunk-BUGVDCI5.cjs.map} +1 -1
  67. package/dist/{chunk-IT3PWBW4.cjs → chunk-BURYFNOM.cjs} +2 -2
  68. package/dist/chunk-BURYFNOM.cjs.map +1 -0
  69. package/dist/{chunk-NNSKJCBM.cjs → chunk-D3SJLXYZ.cjs} +10 -10
  70. package/dist/{chunk-NNSKJCBM.cjs.map → chunk-D3SJLXYZ.cjs.map} +1 -1
  71. package/dist/{chunk-MRODLUGY.cjs → chunk-ED7ANP6W.cjs} +4 -4
  72. package/dist/{chunk-MRODLUGY.cjs.map → chunk-ED7ANP6W.cjs.map} +1 -1
  73. package/dist/{chunk-MXSMAGDU.js → chunk-EDI7DBWO.js} +33 -26
  74. package/dist/chunk-EDI7DBWO.js.map +1 -0
  75. package/dist/{chunk-T4QWDOG6.js → chunk-EE24WJJR.js} +5 -5
  76. package/dist/{chunk-T4QWDOG6.js.map → chunk-EE24WJJR.js.map} +1 -1
  77. package/dist/{chunk-ZJN6NTHE.js → chunk-EUB7YLU2.js} +3 -3
  78. package/dist/{chunk-ZJN6NTHE.js.map → chunk-EUB7YLU2.js.map} +1 -1
  79. package/dist/{chunk-ALU3KC4G.cjs → chunk-G7X2Y7Y2.cjs} +156 -156
  80. package/dist/chunk-G7X2Y7Y2.cjs.map +1 -0
  81. package/dist/{chunk-YCXMSDSP.js → chunk-HHUDNTZC.js} +4 -4
  82. package/dist/{chunk-YCXMSDSP.js.map → chunk-HHUDNTZC.js.map} +1 -1
  83. package/dist/{chunk-GL7CFBVC.js → chunk-HI6G3SNY.js} +48 -48
  84. package/dist/chunk-HI6G3SNY.js.map +1 -0
  85. package/dist/{chunk-G6AASL5T.cjs → chunk-HLK35TD7.cjs} +24 -24
  86. package/dist/{chunk-G6AASL5T.cjs.map → chunk-HLK35TD7.cjs.map} +1 -1
  87. package/dist/{chunk-4YB7B3RP.cjs → chunk-IBDE4R5L.cjs} +13 -13
  88. package/dist/{chunk-4YB7B3RP.cjs.map → chunk-IBDE4R5L.cjs.map} +1 -1
  89. package/dist/{chunk-WDGCZDRG.js → chunk-JCXIDFRI.js} +3 -3
  90. package/dist/{chunk-WDGCZDRG.js.map → chunk-JCXIDFRI.js.map} +1 -1
  91. package/dist/{chunk-I35DI7ES.js → chunk-JI34KBNC.js} +3 -3
  92. package/dist/{chunk-I35DI7ES.js.map → chunk-JI34KBNC.js.map} +1 -1
  93. package/dist/{chunk-TAPQWDW2.js → chunk-KCZW75PI.js} +2 -2
  94. package/dist/chunk-KCZW75PI.js.map +1 -0
  95. package/dist/{chunk-U2WLFOA3.cjs → chunk-KL7E244K.cjs} +4 -4
  96. package/dist/{chunk-U2WLFOA3.cjs.map → chunk-KL7E244K.cjs.map} +1 -1
  97. package/dist/{chunk-PAEJPLVN.cjs → chunk-KTXOHCAE.cjs} +4 -4
  98. package/dist/{chunk-PAEJPLVN.cjs.map → chunk-KTXOHCAE.cjs.map} +1 -1
  99. package/dist/{chunk-2WFB5ZOX.js → chunk-KWXC6ERT.js} +5 -5
  100. package/dist/{chunk-2WFB5ZOX.js.map → chunk-KWXC6ERT.js.map} +1 -1
  101. package/dist/{chunk-56OXYUZE.js → chunk-LGCEYEU2.js} +3 -3
  102. package/dist/chunk-LGCEYEU2.js.map +1 -0
  103. package/dist/{chunk-FAY3QDGC.cjs → chunk-M4OGSS66.cjs} +11 -11
  104. package/dist/{chunk-FAY3QDGC.cjs.map → chunk-M4OGSS66.cjs.map} +1 -1
  105. package/dist/{chunk-F6Y4IEQM.js → chunk-M6UUTNDT.js} +4 -4
  106. package/dist/{chunk-F6Y4IEQM.js.map → chunk-M6UUTNDT.js.map} +1 -1
  107. package/dist/{chunk-GM7QDQ24.cjs → chunk-MXRBNJ6D.cjs} +11 -11
  108. package/dist/{chunk-GM7QDQ24.cjs.map → chunk-MXRBNJ6D.cjs.map} +1 -1
  109. package/dist/{chunk-YPQF26X7.cjs → chunk-OBA6YK2R.cjs} +2 -2
  110. package/dist/chunk-OBA6YK2R.cjs.map +1 -0
  111. package/dist/{chunk-BJMKQOY2.cjs → chunk-OFWU6UKF.cjs} +11 -11
  112. package/dist/{chunk-BJMKQOY2.cjs.map → chunk-OFWU6UKF.cjs.map} +1 -1
  113. package/dist/{chunk-3O2ELBST.cjs → chunk-PG3QQLWS.cjs} +5 -5
  114. package/dist/{chunk-3O2ELBST.cjs.map → chunk-PG3QQLWS.cjs.map} +1 -1
  115. package/dist/{chunk-2ONFGMBV.js → chunk-PY2RQOA7.js} +2 -2
  116. package/dist/chunk-PY2RQOA7.js.map +1 -0
  117. package/dist/{chunk-UQPDFW4E.js → chunk-QFWQLXCL.js} +3 -3
  118. package/dist/{chunk-UQPDFW4E.js.map → chunk-QFWQLXCL.js.map} +1 -1
  119. package/dist/{chunk-YBFDBOUN.cjs → chunk-QJQ2MAZF.cjs} +8 -8
  120. package/dist/{chunk-YBFDBOUN.cjs.map → chunk-QJQ2MAZF.cjs.map} +1 -1
  121. package/dist/{chunk-QUFSDDNU.cjs → chunk-R4AMI7KD.cjs} +15 -15
  122. package/dist/{chunk-QUFSDDNU.cjs.map → chunk-R4AMI7KD.cjs.map} +1 -1
  123. package/dist/{chunk-CSZRJ4RE.js → chunk-SGTMDQ4O.js} +5 -5
  124. package/dist/{chunk-CSZRJ4RE.js.map → chunk-SGTMDQ4O.js.map} +1 -1
  125. package/dist/{chunk-3ILFUXNE.cjs → chunk-SRIF7HMN.cjs} +5 -5
  126. package/dist/{chunk-3ILFUXNE.cjs.map → chunk-SRIF7HMN.cjs.map} +1 -1
  127. package/dist/{chunk-THEYGCYS.cjs → chunk-TKDWD3MU.cjs} +4 -4
  128. package/dist/chunk-TKDWD3MU.cjs.map +1 -0
  129. package/dist/{chunk-ZW345YOI.js → chunk-UD2T7ISG.js} +4 -4
  130. package/dist/{chunk-ZW345YOI.js.map → chunk-UD2T7ISG.js.map} +1 -1
  131. package/dist/{chunk-EXQV452X.js → chunk-UWEALKAN.js} +3 -3
  132. package/dist/{chunk-EXQV452X.js.map → chunk-UWEALKAN.js.map} +1 -1
  133. package/dist/{chunk-W52DKZBR.cjs → chunk-UZBA6YYP.cjs} +454 -333
  134. package/dist/chunk-UZBA6YYP.cjs.map +1 -0
  135. package/dist/{chunk-VYJSHGAY.js → chunk-VUDH4D2M.js} +201 -80
  136. package/dist/chunk-VUDH4D2M.js.map +1 -0
  137. package/dist/{chunk-W4QN5CMG.cjs → chunk-VVMLMKYZ.cjs} +9 -9
  138. package/dist/{chunk-W4QN5CMG.cjs.map → chunk-VVMLMKYZ.cjs.map} +1 -1
  139. package/dist/{chunk-JNIWFCKI.js → chunk-VYD6BGKK.js} +3 -3
  140. package/dist/{chunk-JNIWFCKI.js.map → chunk-VYD6BGKK.js.map} +1 -1
  141. package/dist/{chunk-YHZXBDAW.js → chunk-XJ5TMOGA.js} +16 -16
  142. package/dist/{chunk-YHZXBDAW.js.map → chunk-XJ5TMOGA.js.map} +1 -1
  143. package/dist/{chunk-7DXLNNKH.cjs → chunk-XKBJT7WI.cjs} +4 -4
  144. package/dist/{chunk-7DXLNNKH.cjs.map → chunk-XKBJT7WI.cjs.map} +1 -1
  145. package/dist/{chunk-YDLNI7J6.js → chunk-XS7SKY2F.js} +3 -3
  146. package/dist/{chunk-YDLNI7J6.js.map → chunk-XS7SKY2F.js.map} +1 -1
  147. package/dist/{chunk-NFCKEBHI.js → chunk-YCHC45BY.js} +3 -3
  148. package/dist/{chunk-NFCKEBHI.js.map → chunk-YCHC45BY.js.map} +1 -1
  149. package/dist/{chunk-ICYBIC6N.cjs → chunk-YVI4YPUP.cjs} +4 -4
  150. package/dist/chunk-YVI4YPUP.cjs.map +1 -0
  151. package/dist/{chunk-TQI3KRXZ.cjs → chunk-ZET34IZE.cjs} +18 -18
  152. package/dist/{chunk-TQI3KRXZ.cjs.map → chunk-ZET34IZE.cjs.map} +1 -1
  153. package/dist/{chunk-GLUWH6JO.js → chunk-ZFZYPLQI.js} +4 -4
  154. package/dist/{chunk-GLUWH6JO.js.map → chunk-ZFZYPLQI.js.map} +1 -1
  155. package/dist/{chunk-M5ZQBOIZ.js → chunk-ZK3BJ4XQ.js} +3 -3
  156. package/dist/{chunk-M5ZQBOIZ.js.map → chunk-ZK3BJ4XQ.js.map} +1 -1
  157. package/dist/{chunk-CD73YHEH.js → chunk-ZYOHF37V.js} +3 -3
  158. package/dist/{chunk-CD73YHEH.js.map → chunk-ZYOHF37V.js.map} +1 -1
  159. package/dist/compact-session-RR3ILTES.js +17 -0
  160. package/dist/{compact-session-WNKKIIDW.js.map → compact-session-RR3ILTES.js.map} +1 -1
  161. package/dist/compact-session-YOWJJPPB.cjs +54 -0
  162. package/dist/{compact-session-H5TKLD55.cjs.map → compact-session-YOWJJPPB.cjs.map} +1 -1
  163. package/dist/compaction.cjs +19 -19
  164. package/dist/compaction.d.cts +9 -9
  165. package/dist/compaction.d.ts +9 -9
  166. package/dist/compaction.js +3 -3
  167. package/dist/concurrency.cjs +6 -6
  168. package/dist/concurrency.js +4 -4
  169. package/dist/context-Q6ISOCN2.cjs +22 -0
  170. package/dist/{context-ZV33V4DC.cjs.map → context-Q6ISOCN2.cjs.map} +1 -1
  171. package/dist/context-ZDBBPIHY.js +5 -0
  172. package/dist/{context-VAYLPT4O.js.map → context-ZDBBPIHY.js.map} +1 -1
  173. package/dist/{cron-BiK_aNJI.d.cts → cron-BdXOZco9.d.cts} +2 -2
  174. package/dist/{cron-Dx7B-3WB.d.ts → cron-ChQ6zcW2.d.ts} +2 -2
  175. package/dist/cron.cjs +29 -29
  176. package/dist/cron.d.cts +3 -3
  177. package/dist/cron.d.ts +3 -3
  178. package/dist/cron.js +28 -28
  179. package/dist/{errors-DyVbXdR4.d.cts → errors-BUVjJGJA.d.cts} +1 -1
  180. package/dist/{errors-Cua4WC9H.d.ts → errors-CZIUKLHt.d.ts} +1 -1
  181. package/dist/errors.cjs +21 -21
  182. package/dist/errors.d.cts +2 -2
  183. package/dist/errors.d.ts +2 -2
  184. package/dist/errors.js +2 -2
  185. package/dist/eval.cjs +32 -32
  186. package/dist/eval.js +28 -28
  187. package/dist/{executor-PAH72CB5.js → executor-ASDDIM2X.js} +7 -7
  188. package/dist/{executor-PAH72CB5.js.map → executor-ASDDIM2X.js.map} +1 -1
  189. package/dist/{executor-OZSYXDKF.cjs → executor-DPCBSI35.cjs} +23 -23
  190. package/dist/{executor-OZSYXDKF.cjs.map → executor-DPCBSI35.cjs.map} +1 -1
  191. package/dist/filesystem/index.cjs +7 -7
  192. package/dist/filesystem/index.js +3 -3
  193. package/dist/fs-session-store-K5QUPNJZ.js +10 -0
  194. package/dist/{fs-session-store-6MY7PNI2.js.map → fs-session-store-K5QUPNJZ.js.map} +1 -1
  195. package/dist/fs-session-store-T5ZLQX42.cjs +19 -0
  196. package/dist/{fs-session-store-7E7UPLF2.cjs.map → fs-session-store-T5ZLQX42.cjs.map} +1 -1
  197. package/dist/generate-object-F56VIZ6U.cjs +20 -0
  198. package/dist/{generate-object-5SCEH2EE.cjs.map → generate-object-F56VIZ6U.cjs.map} +1 -1
  199. package/dist/generate-object-LPSO6GVW.js +7 -0
  200. package/dist/{generate-object-I7UD4NWN.js.map → generate-object-LPSO6GVW.js.map} +1 -1
  201. package/dist/index-manager-DBJ55ZSO.cjs +19 -0
  202. package/dist/{index-manager-R6ZJFEZF.cjs.map → index-manager-DBJ55ZSO.cjs.map} +1 -1
  203. package/dist/index-manager-F2H2RCZU.js +10 -0
  204. package/dist/{index-manager-KKAK7NT3.js.map → index-manager-F2H2RCZU.js.map} +1 -1
  205. package/dist/index.cjs +140 -140
  206. package/dist/index.cjs.map +1 -1
  207. package/dist/index.d.cts +42 -42
  208. package/dist/index.d.ts +42 -42
  209. package/dist/index.js +54 -54
  210. package/dist/index.js.map +1 -1
  211. package/dist/{inject-session-DM4SKTZO.cjs → inject-session-25EC74WV.cjs} +10 -10
  212. package/dist/{inject-session-DM4SKTZO.cjs.map → inject-session-25EC74WV.cjs.map} +1 -1
  213. package/dist/{inject-session-UXNJQTZ6.js → inject-session-RKNLUE72.js} +7 -7
  214. package/dist/{inject-session-UXNJQTZ6.js.map → inject-session-RKNLUE72.js.map} +1 -1
  215. package/dist/internal/agent-loop/live-events.d.ts +46 -0
  216. package/dist/internal/budget/compute-cost.d.ts +1 -1
  217. package/dist/internal/diagnostics.d.ts +31 -29
  218. package/dist/internal/error-mappers/anthropic.d.ts +1 -1
  219. package/dist/internal/global-singleton.d.ts +7 -7
  220. package/dist/internal/judge/judge-call.d.ts +14 -14
  221. package/dist/internal/llm/retrying-client.d.ts +29 -29
  222. package/dist/internal/llm/transport-error.d.ts +2 -2
  223. package/dist/internal/persistence/exclusive-create.d.cts +2 -2
  224. package/dist/internal/persistence/exclusive-create.d.ts +2 -2
  225. package/dist/internal/persistence/fs-session-store.d.cts +18 -18
  226. package/dist/internal/persistence/fs-session-store.d.ts +18 -18
  227. package/dist/internal/persistence/index.cjs +25 -25
  228. package/dist/internal/persistence/index.cjs.map +1 -1
  229. package/dist/internal/persistence/index.js +6 -6
  230. package/dist/internal/persistence/index.js.map +1 -1
  231. package/dist/internal/persistence/paths.d.cts +7 -7
  232. package/dist/internal/persistence/paths.d.ts +7 -7
  233. package/dist/internal/persistence/session-transcript.d.cts +7 -7
  234. package/dist/internal/persistence/session-transcript.d.ts +7 -7
  235. package/dist/internal/persistence/session-writer.d.cts +30 -13
  236. package/dist/internal/persistence/session-writer.d.ts +30 -13
  237. package/dist/internal/runtime/fixtures/fixture-run-base.d.ts +45 -13
  238. package/dist/internal/runtime/lifecycle/goal-marker.d.ts +8 -8
  239. package/dist/internal/security/index.cjs +13 -13
  240. package/dist/internal/security/index.js +3 -3
  241. package/dist/internal/session/agent-session.d.ts +14 -14
  242. package/dist/internal/session/session-cache.d.ts +9 -9
  243. package/dist/judge-call-3S3T6O2Z.js +5 -0
  244. package/dist/{judge-call-TAEIXMYG.js.map → judge-call-3S3T6O2Z.js.map} +1 -1
  245. package/dist/judge-call-XIQJ5GIE.cjs +22 -0
  246. package/dist/{judge-call-SP3G3X2Y.cjs.map → judge-call-XIQJ5GIE.cjs.map} +1 -1
  247. package/dist/models.cjs +20 -20
  248. package/dist/models.cjs.map +1 -1
  249. package/dist/models.js +5 -5
  250. package/dist/models.js.map +1 -1
  251. package/dist/path-safety.cjs +10 -10
  252. package/dist/path-safety.js +3 -3
  253. package/dist/persistence.cjs +34 -34
  254. package/dist/persistence.cjs.map +1 -1
  255. package/dist/persistence.d.cts +1 -1
  256. package/dist/persistence.d.ts +1 -1
  257. package/dist/persistence.js +14 -14
  258. package/dist/persistence.js.map +1 -1
  259. package/dist/project.cjs +5 -5
  260. package/dist/project.js +3 -3
  261. package/dist/registry-BA3SLAN7.cjs +46 -0
  262. package/dist/{registry-N3GTKYCI.cjs.map → registry-BA3SLAN7.cjs.map} +1 -1
  263. package/dist/registry-KMI5RA22.js +9 -0
  264. package/dist/{registry-SOXE4RY6.js.map → registry-KMI5RA22.js.map} +1 -1
  265. package/dist/retry.cjs +4 -4
  266. package/dist/retry.js +3 -3
  267. package/dist/{run-until-YZ2ODWOF.js → run-until-BK56WG4P.js} +3 -3
  268. package/dist/{run-until-YZ2ODWOF.js.map → run-until-BK56WG4P.js.map} +1 -1
  269. package/dist/{run-until-ZZ2JLPJM.cjs → run-until-L5KQD3PV.cjs} +4 -4
  270. package/dist/{run-until-ZZ2JLPJM.cjs.map → run-until-L5KQD3PV.cjs.map} +1 -1
  271. package/dist/{run-CwEJtLPE.d.ts → run-vJHg2eGw.d.cts} +201 -174
  272. package/dist/{run-CwEJtLPE.d.cts → run-vJHg2eGw.d.ts} +201 -174
  273. package/dist/sandbox/bwrap.d.cts +20 -20
  274. package/dist/sandbox/bwrap.d.ts +20 -20
  275. package/dist/sandbox/index.cjs +39 -39
  276. package/dist/sandbox/index.cjs.map +1 -1
  277. package/dist/sandbox/index.d.cts +1 -1
  278. package/dist/sandbox/index.d.ts +1 -1
  279. package/dist/sandbox/index.js +35 -35
  280. package/dist/sandbox/index.js.map +1 -1
  281. package/dist/sandbox/linux-sandbox.d.cts +26 -21
  282. package/dist/sandbox/linux-sandbox.d.ts +26 -21
  283. package/dist/server/auth/index.cjs.map +1 -1
  284. package/dist/server/auth/index.d.cts +6 -6
  285. package/dist/server/auth/index.d.ts +6 -6
  286. package/dist/server/auth/index.js.map +1 -1
  287. package/dist/server/auth/orchestrator.d.cts +2 -2
  288. package/dist/server/auth/orchestrator.d.ts +2 -2
  289. package/dist/server/auth/types.d.cts +4 -4
  290. package/dist/server/auth/types.d.ts +4 -4
  291. package/dist/server/errors-envelope.cjs +14 -14
  292. package/dist/server/errors-envelope.d.cts +3 -3
  293. package/dist/server/errors-envelope.d.ts +3 -3
  294. package/dist/server/errors-envelope.js +3 -3
  295. package/dist/session-transcript-DFGX6WNL.cjs +50 -0
  296. package/dist/{session-transcript-EAKR4D2W.cjs.map → session-transcript-DFGX6WNL.cjs.map} +1 -1
  297. package/dist/session-transcript-MMPWCESR.js +5 -0
  298. package/dist/{session-transcript-6WKLYIN4.js.map → session-transcript-MMPWCESR.js.map} +1 -1
  299. package/dist/skills.cjs +7 -7
  300. package/dist/skills.js +5 -5
  301. package/dist/stream-object-AFERZU63.js +7 -0
  302. package/dist/{stream-object-OFM66VUT.js.map → stream-object-AFERZU63.js.map} +1 -1
  303. package/dist/stream-object-YPXZ4F5P.cjs +20 -0
  304. package/dist/{stream-object-Y7YCX3BI.cjs.map → stream-object-YPXZ4F5P.cjs.map} +1 -1
  305. package/dist/subagents-loader.cjs +6 -6
  306. package/dist/subagents-loader.d.cts +2 -2
  307. package/dist/subagents-loader.d.ts +2 -2
  308. package/dist/subagents-loader.js +4 -4
  309. package/dist/subscription/index.cjs +3 -3
  310. package/dist/subscription/index.js +2 -2
  311. package/dist/task-store.cjs +7 -7
  312. package/dist/task-store.js +4 -4
  313. package/dist/types/agent-prims.d.ts +4 -4
  314. package/dist/types/goal-events.d.ts +24 -23
  315. package/dist/types/run.d.ts +27 -0
  316. package/dist/types/session-record.d.ts +14 -13
  317. package/dist/workflow.cjs +27 -27
  318. package/dist/workflow.js +6 -6
  319. package/package.json +12 -13
  320. package/dist/agent-DW2J37IH.js +0 -42
  321. package/dist/agent-IE6IE4NW.cjs +0 -51
  322. package/dist/chunk-2ONFGMBV.js.map +0 -1
  323. package/dist/chunk-56OXYUZE.js.map +0 -1
  324. package/dist/chunk-56ZM6P7Z.cjs.map +0 -1
  325. package/dist/chunk-5SB4V74H.js.map +0 -1
  326. package/dist/chunk-77WHPVXE.js.map +0 -1
  327. package/dist/chunk-ALU3KC4G.cjs.map +0 -1
  328. package/dist/chunk-EEZ7CFMM.js.map +0 -1
  329. package/dist/chunk-GL7CFBVC.js.map +0 -1
  330. package/dist/chunk-H5YVJB4K.cjs.map +0 -1
  331. package/dist/chunk-ICYBIC6N.cjs.map +0 -1
  332. package/dist/chunk-IT3PWBW4.cjs.map +0 -1
  333. package/dist/chunk-ITLS5LRF.cjs +0 -105
  334. package/dist/chunk-ITLS5LRF.cjs.map +0 -1
  335. package/dist/chunk-LTCOPATU.cjs.map +0 -1
  336. package/dist/chunk-MXSMAGDU.js.map +0 -1
  337. package/dist/chunk-P34DHHYQ.cjs.map +0 -1
  338. package/dist/chunk-TAPQWDW2.js.map +0 -1
  339. package/dist/chunk-THEYGCYS.cjs.map +0 -1
  340. package/dist/chunk-VNNK6AKU.js.map +0 -1
  341. package/dist/chunk-VYJSHGAY.js.map +0 -1
  342. package/dist/chunk-W52DKZBR.cjs.map +0 -1
  343. package/dist/chunk-XAEAMI5H.js.map +0 -1
  344. package/dist/chunk-YPQF26X7.cjs.map +0 -1
  345. package/dist/chunk-YVTNFKZO.js +0 -103
  346. package/dist/chunk-YVTNFKZO.js.map +0 -1
  347. package/dist/compact-session-H5TKLD55.cjs +0 -54
  348. package/dist/compact-session-WNKKIIDW.js +0 -17
  349. package/dist/context-VAYLPT4O.js +0 -5
  350. package/dist/context-ZV33V4DC.cjs +0 -22
  351. package/dist/fs-session-store-6MY7PNI2.js +0 -10
  352. package/dist/fs-session-store-7E7UPLF2.cjs +0 -19
  353. package/dist/generate-object-5SCEH2EE.cjs +0 -20
  354. package/dist/generate-object-I7UD4NWN.js +0 -7
  355. package/dist/index-manager-KKAK7NT3.js +0 -10
  356. package/dist/index-manager-R6ZJFEZF.cjs +0 -19
  357. package/dist/judge-call-SP3G3X2Y.cjs +0 -22
  358. package/dist/judge-call-TAEIXMYG.js +0 -5
  359. package/dist/registry-N3GTKYCI.cjs +0 -46
  360. package/dist/registry-SOXE4RY6.js +0 -9
  361. package/dist/session-transcript-6WKLYIN4.js +0 -5
  362. package/dist/session-transcript-EAKR4D2W.cjs +0 -50
  363. package/dist/stream-object-OFM66VUT.js +0 -7
  364. package/dist/stream-object-Y7YCX3BI.cjs +0 -20
@@ -1,5 +1,5 @@
1
- export { ForbiddenPathError, PathTraversalError, assertNoSymlinkEscape, isForbiddenPath, safeFilenameForId, safePathJoin, sanitizeIdentifier } from './chunk-WDGCZDRG.js';
2
- import './chunk-CD73YHEH.js';
3
- import './chunk-TAPQWDW2.js';
1
+ export { ForbiddenPathError, PathTraversalError, assertNoSymlinkEscape, isForbiddenPath, safeFilenameForId, safePathJoin, sanitizeIdentifier } from './chunk-JCXIDFRI.js';
2
+ import './chunk-ZYOHF37V.js';
3
+ import './chunk-KCZW75PI.js';
4
4
  //# sourceMappingURL=path-safety.js.map
5
5
  //# sourceMappingURL=path-safety.js.map
@@ -1,17 +1,17 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkPNVDQL5Y_cjs = require('./chunk-PNVDQL5Y.cjs');
4
- var chunkP34DHHYQ_cjs = require('./chunk-P34DHHYQ.cjs');
5
- var chunkTQI3KRXZ_cjs = require('./chunk-TQI3KRXZ.cjs');
6
- var chunkFK4EJD2I_cjs = require('./chunk-FK4EJD2I.cjs');
4
+ var chunk3VKTDQMX_cjs = require('./chunk-3VKTDQMX.cjs');
5
+ var chunkZET34IZE_cjs = require('./chunk-ZET34IZE.cjs');
6
+ var chunk6OIO4FYX_cjs = require('./chunk-6OIO4FYX.cjs');
7
7
  var chunkYLQQX5W2_cjs = require('./chunk-YLQQX5W2.cjs');
8
- var chunkIEUDKUPM_cjs = require('./chunk-IEUDKUPM.cjs');
9
- var chunkICYBIC6N_cjs = require('./chunk-ICYBIC6N.cjs');
10
- var chunkMHCKWQR3_cjs = require('./chunk-MHCKWQR3.cjs');
11
- require('./chunk-LTCOPATU.cjs');
8
+ var chunk6OKPJZMX_cjs = require('./chunk-6OKPJZMX.cjs');
9
+ var chunkYVI4YPUP_cjs = require('./chunk-YVI4YPUP.cjs');
10
+ var chunkA3MHE2MQ_cjs = require('./chunk-A3MHE2MQ.cjs');
11
+ require('./chunk-BE3W4HYV.cjs');
12
12
  var fs = require('fs');
13
13
 
14
- var LiveSessionError = class extends chunkMHCKWQR3_cjs.TheokitAgentError {
14
+ var LiveSessionError = class extends chunkA3MHE2MQ_cjs.TheokitAgentError {
15
15
  constructor(path) {
16
16
  super(
17
17
  `refusing to write over a live session transcript: ${path}. Fork to a new id instead \u2014 the live pointer, the most recent transcript and any active registry entry are never overwritten (audit-trail rotation, M60).`,
@@ -52,21 +52,21 @@ function lerCaudaBruta(path, want) {
52
52
  fs.readSync(fd, buf, 0, len, pos);
53
53
  bytesRead += len;
54
54
  tail = buf.toString("utf8") + tail;
55
- if (naoVazias(tail).length > want) break;
55
+ if (nonEmptyLines(tail).length > want) break;
56
56
  }
57
57
  } finally {
58
58
  fs.closeSync(fd);
59
59
  }
60
- const linhas = naoVazias(tail);
61
- return { linhas: pos > 0 ? linhas.slice(1) : linhas, bytesRead };
60
+ const lines = nonEmptyLines(tail);
61
+ return { lines: pos > 0 ? lines.slice(1) : lines, bytesRead };
62
62
  }
63
- function naoVazias(texto) {
64
- return texto.split("\n").filter((l) => l.trim().length > 0);
63
+ function nonEmptyLines(text) {
64
+ return text.split("\n").filter((l) => l.trim().length > 0);
65
65
  }
66
66
  function readJsonlTail(path, options = {}) {
67
67
  const want = options.maxRecords ?? Number.POSITIVE_INFINITY;
68
- const { linhas, bytesRead } = lerCaudaBruta(path, want);
69
- let sel = linhas;
68
+ const { lines, bytesRead } = lerCaudaBruta(path, want);
69
+ let sel = lines;
70
70
  if (options.sinceMarker !== void 0) {
71
71
  const marcador = options.sinceMarker;
72
72
  const idx = sel.findLastIndex((l) => l.includes(marcador));
@@ -83,51 +83,51 @@ Object.defineProperty(exports, "PersistenceSchema", {
83
83
  });
84
84
  Object.defineProperty(exports, "SessionBusyError", {
85
85
  enumerable: true,
86
- get: function () { return chunkP34DHHYQ_cjs.SessionBusyError; }
86
+ get: function () { return chunk3VKTDQMX_cjs.SessionBusyError; }
87
87
  });
88
88
  Object.defineProperty(exports, "acquireSessionWriter", {
89
89
  enumerable: true,
90
- get: function () { return chunkP34DHHYQ_cjs.acquireSessionWriter; }
90
+ get: function () { return chunk3VKTDQMX_cjs.acquireSessionWriter; }
91
91
  });
92
- Object.defineProperty(exports, "sessaoTemEscritor", {
92
+ Object.defineProperty(exports, "sessionHasWriter", {
93
93
  enumerable: true,
94
- get: function () { return chunkP34DHHYQ_cjs.sessaoTemEscritor; }
94
+ get: function () { return chunk3VKTDQMX_cjs.sessionHasWriter; }
95
95
  });
96
96
  Object.defineProperty(exports, "JsonlParseError", {
97
97
  enumerable: true,
98
- get: function () { return chunkTQI3KRXZ_cjs.JsonlParseError; }
98
+ get: function () { return chunkZET34IZE_cjs.JsonlParseError; }
99
99
  });
100
100
  Object.defineProperty(exports, "appendJsonl", {
101
101
  enumerable: true,
102
- get: function () { return chunkTQI3KRXZ_cjs.appendJsonl; }
102
+ get: function () { return chunkZET34IZE_cjs.appendJsonl; }
103
103
  });
104
104
  Object.defineProperty(exports, "loadJsonl", {
105
105
  enumerable: true,
106
- get: function () { return chunkTQI3KRXZ_cjs.loadJsonl; }
106
+ get: function () { return chunkZET34IZE_cjs.loadJsonl; }
107
107
  });
108
108
  Object.defineProperty(exports, "readJsonlIds", {
109
109
  enumerable: true,
110
- get: function () { return chunkTQI3KRXZ_cjs.readJsonlIds; }
110
+ get: function () { return chunkZET34IZE_cjs.readJsonlIds; }
111
111
  });
112
112
  Object.defineProperty(exports, "withFileLock", {
113
113
  enumerable: true,
114
- get: function () { return chunkTQI3KRXZ_cjs.withFileLock; }
114
+ get: function () { return chunkZET34IZE_cjs.withFileLock; }
115
115
  });
116
116
  Object.defineProperty(exports, "applyWalWithFallback", {
117
117
  enumerable: true,
118
- get: function () { return chunkFK4EJD2I_cjs.applyWalWithFallback; }
118
+ get: function () { return chunk6OIO4FYX_cjs.applyWalWithFallback; }
119
119
  });
120
120
  Object.defineProperty(exports, "isCorruptionError", {
121
121
  enumerable: true,
122
- get: function () { return chunkFK4EJD2I_cjs.isCorruptionError; }
122
+ get: function () { return chunk6OIO4FYX_cjs.isCorruptionError; }
123
123
  });
124
124
  Object.defineProperty(exports, "openSqliteResilient", {
125
125
  enumerable: true,
126
- get: function () { return chunkFK4EJD2I_cjs.openSqliteResilient; }
126
+ get: function () { return chunk6OIO4FYX_cjs.openSqliteResilient; }
127
127
  });
128
128
  Object.defineProperty(exports, "sanitizeFts5Query", {
129
129
  enumerable: true,
130
- get: function () { return chunkFK4EJD2I_cjs.sanitizeFts5Query; }
130
+ get: function () { return chunk6OIO4FYX_cjs.sanitizeFts5Query; }
131
131
  });
132
132
  Object.defineProperty(exports, "withCwdMutex", {
133
133
  enumerable: true,
@@ -135,27 +135,27 @@ Object.defineProperty(exports, "withCwdMutex", {
135
135
  });
136
136
  Object.defineProperty(exports, "encodeProjectDir", {
137
137
  enumerable: true,
138
- get: function () { return chunkIEUDKUPM_cjs.encodeProjectDir; }
138
+ get: function () { return chunk6OKPJZMX_cjs.encodeProjectDir; }
139
139
  });
140
140
  Object.defineProperty(exports, "transcriptPath", {
141
141
  enumerable: true,
142
- get: function () { return chunkIEUDKUPM_cjs.transcriptPath; }
142
+ get: function () { return chunk6OKPJZMX_cjs.transcriptPath; }
143
143
  });
144
144
  Object.defineProperty(exports, "transcriptRoot", {
145
145
  enumerable: true,
146
- get: function () { return chunkIEUDKUPM_cjs.transcriptRoot; }
146
+ get: function () { return chunk6OKPJZMX_cjs.transcriptRoot; }
147
147
  });
148
148
  Object.defineProperty(exports, "atomicWriteJson", {
149
149
  enumerable: true,
150
- get: function () { return chunkICYBIC6N_cjs.atomicWriteJson; }
150
+ get: function () { return chunkYVI4YPUP_cjs.atomicWriteJson; }
151
151
  });
152
152
  Object.defineProperty(exports, "atomicWriteText", {
153
153
  enumerable: true,
154
- get: function () { return chunkICYBIC6N_cjs.atomicWriteText; }
154
+ get: function () { return chunkYVI4YPUP_cjs.atomicWriteText; }
155
155
  });
156
156
  Object.defineProperty(exports, "replaceFileAtomic", {
157
157
  enumerable: true,
158
- get: function () { return chunkICYBIC6N_cjs.replaceFileAtomic; }
158
+ get: function () { return chunkYVI4YPUP_cjs.replaceFileAtomic; }
159
159
  });
160
160
  exports.LiveSessionError = LiveSessionError;
161
161
  exports.forkTranscript = forkTranscript;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/internal/persistence/transcript-ops.ts"],"names":["TheokitAgentError","readFileSync","openSync","writeSync","closeSync","statSync","readSync"],"mappings":";;;;;;;;;;;;;AAkCO,IAAM,gBAAA,GAAN,cAA+BA,mCAAA,CAAkB;AAAA,EAGtD,YAAqB,IAAA,EAAc;AACjC,IAAA,KAAA;AAAA,MACE,qDAAqD,IAAI,CAAA,+JAAA,CAAA;AAAA,MAGzD,EAAE,IAAA,EAAM,wBAAA,EAA0B,WAAA,EAAa,KAAA;AAAM,KACvD;AANmB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAOrB;AAAA,EAPqB,IAAA;AAAA,EAFH,IAAA,GAAO,kBAAA;AAU3B;AAmCO,SAAS,cAAA,CACd,GAAA,EACA,GAAA,EACA,OAAA,GAAiC,EAAC,EAC5B;AACN,EAAA,KAAA,MAAW,IAAA,IAAQ,OAAA,CAAQ,gBAAA,IAAoB,EAAC,EAAG;AACjD,IAAA,IAAI,IAAA,KAAS,GAAA,EAAK,MAAM,IAAI,iBAAiB,GAAG,CAAA;AAAA,EAClD;AAEA,EAAA,MAAM,KAAA,GAAQC,eAAA,CAAa,GAAA,EAAK,MAAM,EACnC,KAAA,CAAM,IAAI,CAAA,CACV,MAAA,CAAO,CAAC,CAAA,KAAM,CAAA,CAAE,IAAA,EAAK,CAAE,SAAS,CAAC,CAAA;AACpC,EAAA,MAAM,IAAA,GACJ,QAAQ,iBAAA,KAAs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,OAAA,CAAQ,WAAW,IAAA,GAAQ,MAAA,CAAO,OAAO,GAAA,EAAK,EAAE,SAAA,EAAW,CAAA,GAAY,GAAA;AAChF","file":"persistence.cjs","sourcesContent":["/**\n * M81 — transcript operations the consumer was doing by hand INSIDE the framework's own store.\n *\n * ## What this replaces\n *\n * `agents/lib/session/backtrack.ts:188` (agent-builder) wrote straight into the session store with a\n * bare `writeFileSync` — no atomicity, no lock, no API. 243 lines re-implementing parse, cut and\n * write for a format the framework owns. The consumer is not at fault: nothing here was reachable.\n *\n * ## The rule that travels WITH the operation\n *\n * `rules/audit-trail-rotation.md § Session transcripts (M60)` defines a NEVER-delete list — the live\n * pointer, the most recent transcript, and any active registry entry. That rule lived in the\n * CONSUMER. Moving the operation here without moving the rule would ship an API able to destroy\n * exactly what the rule protects — the same shape of defect as M80's `reconcileUpdateGoalStatus`:\n * critical knowledge outside the module that needs it, applied by convention.\n *\n * So `forkTranscript` takes `liveSessionPaths` and refuses, with a TYPED error, to write over any of\n * them. The caller supplies the list because only the caller knows which session is live; the\n * enforcement lives here because that is where the write happens.\n *\n * @internal\n */\n\nimport { closeSync, openSync, readFileSync, readSync, statSync, writeSync } from \"node:fs\";\n\nimport { TheokitAgentError } from \"../../errors.js\";\n\n/**\n * M81 — the target is a protected session (live pointer / most-recent transcript / active entry).\n *\n * Typed rather than a bare `Error` because the caller must distinguish \"this session is protected\"\n * from \"the disk is full\": the first is a correct refusal, the second is an incident.\n */\nexport class LiveSessionError extends TheokitAgentError {\n override readonly name = \"LiveSessionError\";\n\n constructor(readonly path: string) {\n super(\n `refusing to write over a live session transcript: ${path}. ` +\n \"Fork to a new id instead — the live pointer, the most recent transcript and any active \" +\n \"registry entry are never overwritten (audit-trail rotation, M60).\",\n { code: \"live_session_protected\", isRetryable: false },\n );\n }\n}\n\n/** Options for {@link forkTranscript}. */\nexport interface ForkTranscriptOptions {\n /** Keep records `[0, beforeRecordIndex)`. Omit to copy the whole transcript. */\n readonly beforeRecordIndex?: number;\n /**\n * Paths that must never be written over — the live pointer, the most recent transcript, any active\n * registry entry. The caller supplies them because only the caller knows which session is live.\n */\n readonly liveSessionPaths?: readonly string[];\n /**\n * M107 — permission bits for the created destination. Default: `0o600`.\n *\n * A transcript carries the conversation. Before M107 no mode was passed at all, so the file was\n * born `0o666 & ~umask` — measured `0o664` (group-WRITABLE) on a `umask 002` machine, `0o644` on\n * `umask 022`, `0o466` on `umask 0200`. This is a DEFAULT and not a required knob on purpose: a\n * knob would reach zero consumers by omission, which is the failure mode that matters.\n *\n * As with any `open` mode, the `umask` may still CLEAR bits — under `umask 0200` the result is\n * `0o400`. That is accepted: the invariant bought here is \"neither group nor others\", and `0o400`\n * satisfies it more strictly. The SDK deliberately does not `fchmod` the default back, because\n * that would hand back a bit the operator asked to remove.\n */\n readonly mode?: number;\n}\n\n/**\n * Copy `src` into `dst`, keeping the first `beforeRecordIndex` records. The SOURCE is never touched.\n *\n * Atomicity comes from `wx` (exclusive create): two concurrent forks to the same destination cannot\n * both succeed — the loser gets `EEXIST` rather than writing over a half-written file. That is also\n * why an existing destination is a refusal, not a silent overwrite: losing a transcript without an\n * error is the worst failure mode for an operation that touches user sessions.\n */\nexport function forkTranscript(\n src: string,\n dst: string,\n options: ForkTranscriptOptions = {},\n): void {\n for (const live of options.liveSessionPaths ?? []) {\n if (live === dst) throw new LiveSessionError(dst);\n }\n\n const lines = readFileSync(src, \"utf8\")\n .split(\"\\n\")\n .filter((l) => l.trim().length > 0);\n const kept =\n options.beforeRecordIndex === undefined ? lines : lines.slice(0, options.beforeRecordIndex);\n const body = kept.length > 0 ? `${kept.join(\"\\n\")}\\n` : \"\";\n\n // `wx` — fails with EEXIST instead of truncating. The exclusivity IS the concurrency guarantee,\n // and M107 only added the third argument: the mode. See `ForkTranscriptOptions.mode`.\n const fd = openSync(dst, \"wx\", options.mode ?? 0o600);\n try {\n writeSync(fd, body);\n } finally {\n closeSync(fd);\n }\n}\n\n/** Options for {@link readJsonlTail}. */\nexport interface ReadJsonlTailOptions {\n /** Maximum records to return, counted from the END. */\n readonly maxRecords?: number;\n /** Stop once a line contains this marker (exclusive). */\n readonly sinceMarker?: string;\n /** Test-only: also report how many bytes were read, to prove the read is not whole-file. */\n readonly _stats?: boolean;\n}\n\nconst TAIL_CHUNK = 64 * 1024;\n\n/**\n * Lê chunks de trás para frente até acumular linhas completas suficientes.\n *\n * Extraído de `readJsonlTail` porque o laço de leitura e a seleção de registros são duas\n * responsabilidades — e juntas passavam do teto de complexidade. A primeira linha do buffer pode\n * estar cortada ao meio quando a leitura parou antes do início do arquivo; por isso ela é descartada.\n */\nfunction lerCaudaBruta(path: string, want: number): { linhas: string[]; bytesRead: number } {\n const size = statSync(path).size;\n const fd = openSync(path, \"r\");\n let bytesRead = 0;\n let tail = \"\";\n let pos = size;\n try {\n while (pos > 0) {\n const len = Math.min(TAIL_CHUNK, pos);\n pos -= len;\n const buf = Buffer.alloc(len);\n readSync(fd, buf, 0, len, pos);\n bytesRead += len;\n tail = buf.toString(\"utf8\") + tail;\n if (naoVazias(tail).length > want) break;\n }\n } finally {\n closeSync(fd);\n }\n const linhas = naoVazias(tail);\n return { linhas: pos > 0 ? linhas.slice(1) : linhas, bytesRead };\n}\n\n/** Linhas com conteúdo, na ordem do arquivo. */\nfunction naoVazias(texto: string): string[] {\n return texto.split(\"\\n\").filter((l) => l.trim().length > 0);\n}\n\n/**\n * Read the LAST records of a JSONL file without loading the whole thing.\n *\n * Reads fixed-size chunks backwards from EOF until enough newlines have been seen. A session\n * transcript grows without bound; loading megabytes to show the last three turns is the cost this\n * exists to avoid — and a `slice` over a full read would be that same cost with a better name.\n */\nexport function readJsonlTail<T = Record<string, unknown>>(\n path: string,\n options: ReadJsonlTailOptions = {},\n): T[] {\n const want = options.maxRecords ?? Number.POSITIVE_INFINITY;\n const { linhas, bytesRead } = lerCaudaBruta(path, want);\n\n let sel = linhas;\n if (options.sinceMarker !== undefined) {\n const marcador = options.sinceMarker;\n const idx = sel.findLastIndex((l) => l.includes(marcador));\n if (idx >= 0) sel = sel.slice(idx + 1);\n }\n if (Number.isFinite(want)) sel = sel.slice(-want);\n\n const out = sel.map((l) => JSON.parse(l) as T);\n return options._stats === true ? (Object.assign(out, { bytesRead }) as T[]) : out;\n}\n"]}
1
+ {"version":3,"sources":["../src/internal/persistence/transcript-ops.ts"],"names":["TheokitAgentError","readFileSync","openSync","writeSync","closeSync","statSync","readSync"],"mappings":";;;;;;;;;;;;;AAkCO,IAAM,gBAAA,GAAN,cAA+BA,mCAAA,CAAkB;AAAA,EAGtD,YAAqB,IAAA,EAAc;AACjC,IAAA,KAAA;AAAA,MACE,qDAAqD,IAAI,CAAA,+JAAA,CAAA;AAAA,MAGzD,EAAE,IAAA,EAAM,wBAAA,EAA0B,WAAA,EAAa,KAAA;AAAM,KACvD;AANmB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAOrB;AAAA,EAPqB,IAAA;AAAA,EAFH,IAAA,GAAO,kBAAA;AAU3B;AAmCO,SAAS,cAAA,CACd,GAAA,EACA,GAAA,EACA,OAAA,GAAiC,EAAC,EAC5B;AACN,EAAA,KAAA,MAAW,IAAA,IAAQ,OAAA,CAAQ,gBAAA,IAAoB,EAAC,EAAG;AACjD,IAAA,IAAI,IAAA,KAAS,GAAA,EAAK,MAAM,IAAI,iBAAiB,GAAG,CAAA;AAAA,EAClD;AAEA,EAAA,MAAM,KAAA,GAAQC,eAAA,CAAa,GAAA,EAAK,MAAM,EACnC,KAAA,CAAM,IAAI,CAAA,CACV,MAAA,CAAO,CAAC,CAAA,KAAM,CAAA,CAAE,IAAA,EAAK,CAAE,SAAS,CAAC,CAAA;AACpC,EAAA,MAAM,IAAA,GACJ,QAAQ,iBAAA,KAAsB,MAAA,GAAY,QAAQ,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,OAAA,CAAQ,iBAAiB,CAAA;AAC5F,EAAA,MAAM,IAAA,GAAO,KAAK,MAAA,GAAS,CAAA,GAAI,GAAG,IAAA,CA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ework's own store.\n *\n * ## What this replaces\n *\n * `agents/lib/session/backtrack.ts:188` (agent-builder) wrote straight into the session store with a\n * bare `writeFileSync` — no atomicity, no lock, no API. 243 lines re-implementing parse, cut and\n * write for a format the framework owns. The consumer is not at fault: nothing here was reachable.\n *\n * ## The rule that travels WITH the operation\n *\n * `rules/audit-trail-rotation.md § Session transcripts (M60)` defines a NEVER-delete list — the live\n * pointer, the most recent transcript, and any active registry entry. That rule lived in the\n * CONSUMER. Moving the operation here without moving the rule would ship an API able to destroy\n * exactly what the rule protects — the same shape of defect as M80's `reconcileUpdateGoalStatus`:\n * critical knowledge outside the module that needs it, applied by convention.\n *\n * So `forkTranscript` takes `liveSessionPaths` and refuses, with a TYPED error, to write over any of\n * them. The caller supplies the list because only the caller knows which session is live; the\n * enforcement lives here because that is where the write happens.\n *\n * @internal\n */\n\nimport { closeSync, openSync, readFileSync, readSync, statSync, writeSync } from \"node:fs\";\n\nimport { TheokitAgentError } from \"../../errors.js\";\n\n/**\n * M81 — the target is a protected session (live pointer / most-recent transcript / active entry).\n *\n * Typed rather than a bare `Error` because the caller must distinguish \"this session is protected\"\n * from \"the disk is full\": the first is a correct refusal, the second is an incident.\n */\nexport class LiveSessionError extends TheokitAgentError {\n override readonly name = \"LiveSessionError\";\n\n constructor(readonly path: string) {\n super(\n `refusing to write over a live session transcript: ${path}. ` +\n \"Fork to a new id instead — the live pointer, the most recent transcript and any active \" +\n \"registry entry are never overwritten (audit-trail rotation, M60).\",\n { code: \"live_session_protected\", isRetryable: false },\n );\n }\n}\n\n/** Options for {@link forkTranscript}. */\nexport interface ForkTranscriptOptions {\n /** Keep records `[0, beforeRecordIndex)`. Omit to copy the whole transcript. */\n readonly beforeRecordIndex?: number;\n /**\n * Paths that must never be written over — the live pointer, the most recent transcript, any active\n * registry entry. The caller supplies them because only the caller knows which session is live.\n */\n readonly liveSessionPaths?: readonly string[];\n /**\n * M107 — permission bits for the created destination. Default: `0o600`.\n *\n * A transcript carries the conversation. Before M107 no mode was passed at all, so the file was\n * born `0o666 & ~umask` — measured `0o664` (group-WRITABLE) on a `umask 002` machine, `0o644` on\n * `umask 022`, `0o466` on `umask 0200`. This is a DEFAULT and not a required knob on purpose: a\n * knob would reach zero consumers by omission, which is the failure mode that matters.\n *\n * As with any `open` mode, the `umask` may still CLEAR bits — under `umask 0200` the result is\n * `0o400`. That is accepted: the invariant bought here is \"neither group nor others\", and `0o400`\n * satisfies it more strictly. The SDK deliberately does not `fchmod` the default back, because\n * that would hand back a bit the operator asked to remove.\n */\n readonly mode?: number;\n}\n\n/**\n * Copy `src` into `dst`, keeping the first `beforeRecordIndex` records. The SOURCE is never touched.\n *\n * Atomicity comes from `wx` (exclusive create): two concurrent forks to the same destination cannot\n * both succeed — the loser gets `EEXIST` rather than writing over a half-written file. That is also\n * why an existing destination is a refusal, not a silent overwrite: losing a transcript without an\n * error is the worst failure mode for an operation that touches user sessions.\n */\nexport function forkTranscript(\n src: string,\n dst: string,\n options: ForkTranscriptOptions = {},\n): void {\n for (const live of options.liveSessionPaths ?? []) {\n if (live === dst) throw new LiveSessionError(dst);\n }\n\n const lines = readFileSync(src, \"utf8\")\n .split(\"\\n\")\n .filter((l) => l.trim().length > 0);\n const kept =\n options.beforeRecordIndex === undefined ? lines : lines.slice(0, options.beforeRecordIndex);\n const body = kept.length > 0 ? `${kept.join(\"\\n\")}\\n` : \"\";\n\n // `wx` — fails with EEXIST instead of truncating. The exclusivity IS the concurrency guarantee,\n // and M107 only added the third argument: the mode. See `ForkTranscriptOptions.mode`.\n const fd = openSync(dst, \"wx\", options.mode ?? 0o600);\n try {\n writeSync(fd, body);\n } finally {\n closeSync(fd);\n }\n}\n\n/** Options for {@link readJsonlTail}. */\nexport interface ReadJsonlTailOptions {\n /** Maximum records to return, counted from the END. */\n readonly maxRecords?: number;\n /** Stop once a line contains this marker (exclusive). */\n readonly sinceMarker?: string;\n /** Test-only: also report how many bytes were read, to prove the read is not whole-file. */\n readonly _stats?: boolean;\n}\n\nconst TAIL_CHUNK = 64 * 1024;\n\n/**\n * Reads chunks backwards until enough complete lines have accumulated.\n *\n * Extracted from `readJsonlTail` because the read loop and the record selection are two\n * responsibilities — and together they exceeded the complexity ceiling. The buffer's first line may\n * be cut in half when the read stopped before the start of the file; that is why it is discarded.\n */\nfunction lerCaudaBruta(path: string, want: number): { lines: string[]; bytesRead: number } {\n const size = statSync(path).size;\n const fd = openSync(path, \"r\");\n let bytesRead = 0;\n let tail = \"\";\n let pos = size;\n try {\n while (pos > 0) {\n const len = Math.min(TAIL_CHUNK, pos);\n pos -= len;\n const buf = Buffer.alloc(len);\n readSync(fd, buf, 0, len, pos);\n bytesRead += len;\n tail = buf.toString(\"utf8\") + tail;\n if (nonEmptyLines(tail).length > want) break;\n }\n } finally {\n closeSync(fd);\n }\n const lines = nonEmptyLines(tail);\n return { lines: pos > 0 ? lines.slice(1) : lines, bytesRead };\n}\n\n/** Non-empty lines, in file order. */\nfunction nonEmptyLines(text: string): string[] {\n return text.split(\"\\n\").filter((l) => l.trim().length > 0);\n}\n\n/**\n * Read the LAST records of a JSONL file without loading the whole thing.\n *\n * Reads fixed-size chunks backwards from EOF until enough newlines have been seen. A session\n * transcript grows without bound; loading megabytes to show the last three turns is the cost this\n * exists to avoid — and a `slice` over a full read would be that same cost with a better name.\n */\nexport function readJsonlTail<T = Record<string, unknown>>(\n path: string,\n options: ReadJsonlTailOptions = {},\n): T[] {\n const want = options.maxRecords ?? Number.POSITIVE_INFINITY;\n const { lines, bytesRead } = lerCaudaBruta(path, want);\n\n let sel = lines;\n if (options.sinceMarker !== undefined) {\n const marcador = options.sinceMarker;\n const idx = sel.findLastIndex((l) => l.includes(marcador));\n if (idx >= 0) sel = sel.slice(idx + 1);\n }\n if (Number.isFinite(want)) sel = sel.slice(-want);\n\n const out = sel.map((l) => JSON.parse(l) as T);\n return options._stats === true ? (Object.assign(out, { bytesRead }) as T[]) : out;\n}\n"]}
@@ -22,7 +22,7 @@ export { sanitizeFts5Query } from "./internal/persistence/fts5-sanitize.js";
22
22
  export { appendJsonl, JsonlParseError, loadJsonl, readJsonlIds, } from "./internal/persistence/jsonl.js";
23
23
  export { PersistenceSchema } from "./internal/persistence/persistence-schema.js";
24
24
  export { encodeProjectDir, transcriptPath, transcriptRoot, } from "./internal/persistence/session-transcript.js";
25
- export { acquireSessionWriter, SessionBusyError, type SessionWriterLease, sessaoTemEscritor, } from "./internal/persistence/session-writer.js";
25
+ export { acquireSessionWriter, SessionBusyError, type SessionWriterLease, sessionHasWriter, } from "./internal/persistence/session-writer.js";
26
26
  export type { OpenSqliteResilientOptions, ResilientSqliteDb, } from "./internal/persistence/sqlite-open.js";
27
27
  export { isCorruptionError, openSqliteResilient } from "./internal/persistence/sqlite-open.js";
28
28
  export type { WalApplyResult } from "./internal/persistence/sqlite-wal.js";
@@ -22,7 +22,7 @@ export { sanitizeFts5Query } from "./internal/persistence/fts5-sanitize.js";
22
22
  export { appendJsonl, JsonlParseError, loadJsonl, readJsonlIds, } from "./internal/persistence/jsonl.js";
23
23
  export { PersistenceSchema } from "./internal/persistence/persistence-schema.js";
24
24
  export { encodeProjectDir, transcriptPath, transcriptRoot, } from "./internal/persistence/session-transcript.js";
25
- export { acquireSessionWriter, SessionBusyError, type SessionWriterLease, sessaoTemEscritor, } from "./internal/persistence/session-writer.js";
25
+ export { acquireSessionWriter, SessionBusyError, type SessionWriterLease, sessionHasWriter, } from "./internal/persistence/session-writer.js";
26
26
  export type { OpenSqliteResilientOptions, ResilientSqliteDb, } from "./internal/persistence/sqlite-open.js";
27
27
  export { isCorruptionError, openSqliteResilient } from "./internal/persistence/sqlite-open.js";
28
28
  export type { WalApplyResult } from "./internal/persistence/sqlite-wal.js";
@@ -1,12 +1,12 @@
1
1
  export { PersistenceSchema } from './chunk-CAH3G4IS.js';
2
- export { SessionBusyError, acquireSessionWriter, sessaoTemEscritor } from './chunk-MXSMAGDU.js';
3
- export { JsonlParseError, appendJsonl, loadJsonl, readJsonlIds, withFileLock } from './chunk-YHZXBDAW.js';
4
- export { applyWalWithFallback, isCorruptionError, openSqliteResilient, sanitizeFts5Query } from './chunk-GLUWH6JO.js';
2
+ export { SessionBusyError, acquireSessionWriter, sessionHasWriter } from './chunk-EDI7DBWO.js';
3
+ export { JsonlParseError, appendJsonl, loadJsonl, readJsonlIds, withFileLock } from './chunk-XJ5TMOGA.js';
4
+ export { applyWalWithFallback, isCorruptionError, openSqliteResilient, sanitizeFts5Query } from './chunk-ZFZYPLQI.js';
5
5
  export { withCwdMutex } from './chunk-2XLKLVVR.js';
6
- export { encodeProjectDir, transcriptPath, transcriptRoot } from './chunk-XAEAMI5H.js';
7
- export { atomicWriteJson, atomicWriteText, replaceFileAtomic } from './chunk-56OXYUZE.js';
8
- import { TheokitAgentError } from './chunk-CD73YHEH.js';
9
- import './chunk-TAPQWDW2.js';
6
+ export { encodeProjectDir, transcriptPath, transcriptRoot } from './chunk-AOZYORH7.js';
7
+ export { atomicWriteJson, atomicWriteText, replaceFileAtomic } from './chunk-LGCEYEU2.js';
8
+ import { TheokitAgentError } from './chunk-ZYOHF37V.js';
9
+ import './chunk-KCZW75PI.js';
10
10
  import { readFileSync, openSync, writeSync, closeSync, statSync, readSync } from 'fs';
11
11
 
12
12
  var LiveSessionError = class extends TheokitAgentError {
@@ -50,21 +50,21 @@ function lerCaudaBruta(path, want) {
50
50
  readSync(fd, buf, 0, len, pos);
51
51
  bytesRead += len;
52
52
  tail = buf.toString("utf8") + tail;
53
- if (naoVazias(tail).length > want) break;
53
+ if (nonEmptyLines(tail).length > want) break;
54
54
  }
55
55
  } finally {
56
56
  closeSync(fd);
57
57
  }
58
- const linhas = naoVazias(tail);
59
- return { linhas: pos > 0 ? linhas.slice(1) : linhas, bytesRead };
58
+ const lines = nonEmptyLines(tail);
59
+ return { lines: pos > 0 ? lines.slice(1) : lines, bytesRead };
60
60
  }
61
- function naoVazias(texto) {
62
- return texto.split("\n").filter((l) => l.trim().length > 0);
61
+ function nonEmptyLines(text) {
62
+ return text.split("\n").filter((l) => l.trim().length > 0);
63
63
  }
64
64
  function readJsonlTail(path, options = {}) {
65
65
  const want = options.maxRecords ?? Number.POSITIVE_INFINITY;
66
- const { linhas, bytesRead } = lerCaudaBruta(path, want);
67
- let sel = linhas;
66
+ const { lines, bytesRead } = lerCaudaBruta(path, want);
67
+ let sel = lines;
68
68
  if (options.sinceMarker !== void 0) {
69
69
  const marcador = options.sinceMarker;
70
70
  const idx = sel.findLastIndex((l) => l.includes(marcador));
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/internal/persistence/transcript-ops.ts"],"names":[],"mappings":";;;;;;;;;;;AAkCO,IAAM,gBAAA,GAAN,cAA+B,iBAAA,CAAkB;AAAA,EAGtD,YAAqB,IAAA,EAAc;AACjC,IAAA,KAAA;AAAA,MACE,qDAAqD,IAAI,CAAA,+JAAA,CAAA;AAAA,MAGzD,EAAE,IAAA,EAAM,wBAAA,EAA0B,WAAA,EAAa,KAAA;AAAM,KACvD;AANmB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAOrB;AAAA,EAPqB,IAAA;AAAA,EAFH,IAAA,GAAO,kBAAA;AAU3B;AAmCO,SAAS,cAAA,CACd,GAAA,EACA,GAAA,EACA,OAAA,GAAiC,EAAC,EAC5B;AACN,EAAA,KAAA,MAAW,IAAA,IAAQ,OAAA,CAAQ,gBAAA,IAAoB,EAAC,EAAG;AACjD,IAAA,IAAI,IAAA,KAAS,GAAA,EAAK,MAAM,IAAI,iBAAiB,GAAG,CAAA;AAAA,EAClD;AAEA,EAAA,MAAM,KAAA,GAAQ,YAAA,CAAa,GAAA,EAAK,MAAM,EACnC,KAAA,CAAM,IAAI,CAAA,CACV,MAAA,CAAO,CAAC,CAAA,KAAM,CAAA,CAAE,IAAA,EAAK,CAAE,SAAS,CAAC,CAAA;AACpC,EAAA,MAAM,IAAA,GACJ,QAAQ,iBAAA,KAAsB,MAAA,GAAY,QAAQ,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,OAAA,CAAQ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AAW,CAAA,GAAY,GAAA;AAChF","file":"persistence.js","sourcesContent":["/**\n * M81 — transcript operations the consumer was doing by hand INSIDE the framework's own store.\n *\n * ## What this replaces\n *\n * `agents/lib/session/backtrack.ts:188` (agent-builder) wrote straight into the session store with a\n * bare `writeFileSync` — no atomicity, no lock, no API. 243 lines re-implementing parse, cut and\n * write for a format the framework owns. The consumer is not at fault: nothing here was reachable.\n *\n * ## The rule that travels WITH the operation\n *\n * `rules/audit-trail-rotation.md § Session transcripts (M60)` defines a NEVER-delete list — the live\n * pointer, the most recent transcript, and any active registry entry. That rule lived in the\n * CONSUMER. Moving the operation here without moving the rule would ship an API able to destroy\n * exactly what the rule protects — the same shape of defect as M80's `reconcileUpdateGoalStatus`:\n * critical knowledge outside the module that needs it, applied by convention.\n *\n * So `forkTranscript` takes `liveSessionPaths` and refuses, with a TYPED error, to write over any of\n * them. The caller supplies the list because only the caller knows which session is live; the\n * enforcement lives here because that is where the write happens.\n *\n * @internal\n */\n\nimport { closeSync, openSync, readFileSync, readSync, statSync, writeSync } from \"node:fs\";\n\nimport { TheokitAgentError } from \"../../errors.js\";\n\n/**\n * M81 — the target is a protected session (live pointer / most-recent transcript / active entry).\n *\n * Typed rather than a bare `Error` because the caller must distinguish \"this session is protected\"\n * from \"the disk is full\": the first is a correct refusal, the second is an incident.\n */\nexport class LiveSessionError extends TheokitAgentError {\n override readonly name = \"LiveSessionError\";\n\n constructor(readonly path: string) {\n super(\n `refusing to write over a live session transcript: ${path}. ` +\n \"Fork to a new id instead — the live pointer, the most recent transcript and any active \" +\n \"registry entry are never overwritten (audit-trail rotation, M60).\",\n { code: \"live_session_protected\", isRetryable: false },\n );\n }\n}\n\n/** Options for {@link forkTranscript}. */\nexport interface ForkTranscriptOptions {\n /** Keep records `[0, beforeRecordIndex)`. Omit to copy the whole transcript. */\n readonly beforeRecordIndex?: number;\n /**\n * Paths that must never be written over — the live pointer, the most recent transcript, any active\n * registry entry. The caller supplies them because only the caller knows which session is live.\n */\n readonly liveSessionPaths?: readonly string[];\n /**\n * M107 — permission bits for the created destination. Default: `0o600`.\n *\n * A transcript carries the conversation. Before M107 no mode was passed at all, so the file was\n * born `0o666 & ~umask` — measured `0o664` (group-WRITABLE) on a `umask 002` machine, `0o644` on\n * `umask 022`, `0o466` on `umask 0200`. This is a DEFAULT and not a required knob on purpose: a\n * knob would reach zero consumers by omission, which is the failure mode that matters.\n *\n * As with any `open` mode, the `umask` may still CLEAR bits — under `umask 0200` the result is\n * `0o400`. That is accepted: the invariant bought here is \"neither group nor others\", and `0o400`\n * satisfies it more strictly. The SDK deliberately does not `fchmod` the default back, because\n * that would hand back a bit the operator asked to remove.\n */\n readonly mode?: number;\n}\n\n/**\n * Copy `src` into `dst`, keeping the first `beforeRecordIndex` records. The SOURCE is never touched.\n *\n * Atomicity comes from `wx` (exclusive create): two concurrent forks to the same destination cannot\n * both succeed — the loser gets `EEXIST` rather than writing over a half-written file. That is also\n * why an existing destination is a refusal, not a silent overwrite: losing a transcript without an\n * error is the worst failure mode for an operation that touches user sessions.\n */\nexport function forkTranscript(\n src: string,\n dst: string,\n options: ForkTranscriptOptions = {},\n): void {\n for (const live of options.liveSessionPaths ?? []) {\n if (live === dst) throw new LiveSessionError(dst);\n }\n\n const lines = readFileSync(src, \"utf8\")\n .split(\"\\n\")\n .filter((l) => l.trim().length > 0);\n const kept =\n options.beforeRecordIndex === undefined ? lines : lines.slice(0, options.beforeRecordIndex);\n const body = kept.length > 0 ? `${kept.join(\"\\n\")}\\n` : \"\";\n\n // `wx` — fails with EEXIST instead of truncating. The exclusivity IS the concurrency guarantee,\n // and M107 only added the third argument: the mode. See `ForkTranscriptOptions.mode`.\n const fd = openSync(dst, \"wx\", options.mode ?? 0o600);\n try {\n writeSync(fd, body);\n } finally {\n closeSync(fd);\n }\n}\n\n/** Options for {@link readJsonlTail}. */\nexport interface ReadJsonlTailOptions {\n /** Maximum records to return, counted from the END. */\n readonly maxRecords?: number;\n /** Stop once a line contains this marker (exclusive). */\n readonly sinceMarker?: string;\n /** Test-only: also report how many bytes were read, to prove the read is not whole-file. */\n readonly _stats?: boolean;\n}\n\nconst TAIL_CHUNK = 64 * 1024;\n\n/**\n * Lê chunks de trás para frente até acumular linhas completas suficientes.\n *\n * Extraído de `readJsonlTail` porque o laço de leitura e a seleção de registros são duas\n * responsabilidades — e juntas passavam do teto de complexidade. A primeira linha do buffer pode\n * estar cortada ao meio quando a leitura parou antes do início do arquivo; por isso ela é descartada.\n */\nfunction lerCaudaBruta(path: string, want: number): { linhas: string[]; bytesRead: number } {\n const size = statSync(path).size;\n const fd = openSync(path, \"r\");\n let bytesRead = 0;\n let tail = \"\";\n let pos = size;\n try {\n while (pos > 0) {\n const len = Math.min(TAIL_CHUNK, pos);\n pos -= len;\n const buf = Buffer.alloc(len);\n readSync(fd, buf, 0, len, pos);\n bytesRead += len;\n tail = buf.toString(\"utf8\") + tail;\n if (naoVazias(tail).length > want) break;\n }\n } finally {\n closeSync(fd);\n }\n const linhas = naoVazias(tail);\n return { linhas: pos > 0 ? linhas.slice(1) : linhas, bytesRead };\n}\n\n/** Linhas com conteúdo, na ordem do arquivo. */\nfunction naoVazias(texto: string): string[] {\n return texto.split(\"\\n\").filter((l) => l.trim().length > 0);\n}\n\n/**\n * Read the LAST records of a JSONL file without loading the whole thing.\n *\n * Reads fixed-size chunks backwards from EOF until enough newlines have been seen. A session\n * transcript grows without bound; loading megabytes to show the last three turns is the cost this\n * exists to avoid — and a `slice` over a full read would be that same cost with a better name.\n */\nexport function readJsonlTail<T = Record<string, unknown>>(\n path: string,\n options: ReadJsonlTailOptions = {},\n): T[] {\n const want = options.maxRecords ?? Number.POSITIVE_INFINITY;\n const { linhas, bytesRead } = lerCaudaBruta(path, want);\n\n let sel = linhas;\n if (options.sinceMarker !== undefined) {\n const marcador = options.sinceMarker;\n const idx = sel.findLastIndex((l) => l.includes(marcador));\n if (idx >= 0) sel = sel.slice(idx + 1);\n }\n if (Number.isFinite(want)) sel = sel.slice(-want);\n\n const out = sel.map((l) => JSON.parse(l) as T);\n return options._stats === true ? (Object.assign(out, { bytesRead }) as T[]) : out;\n}\n"]}
1
+ {"version":3,"sources":["../src/internal/persistence/transcript-ops.ts"],"names":[],"mappings":";;;;;;;;;;;AAkCO,IAAM,gBAAA,GAAN,cAA+B,iBAAA,CAAkB;AAAA,EAGtD,YAAqB,IAAA,EAAc;AACjC,IAAA,KAAA;AAAA,MACE,qDAAqD,IAAI,CAAA,+JAAA,CAAA;AAAA,MAGzD,EAAE,IAAA,EAAM,wBAAA,EAA0B,WAAA,EAAa,KAAA;AAAM,KACvD;AANmB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAOrB;AAAA,EAPqB,IAAA;AAAA,EAFH,IAAA,GAAO,kBAAA;AAU3B;AAmCO,SAAS,cAAA,CACd,GAAA,EACA,GAAA,EACA,OAAA,GAAiC,EAAC,EAC5B;AACN,EAAA,KAAA,MAAW,IAAA,IAAQ,OAAA,CAAQ,gBAAA,IAAoB,EAAC,EAAG;AACjD,IAAA,IAAI,IAAA,KAAS,GAAA,EAAK,MAAM,IAAI,iBAAiB,GAAG,CAAA;AAAA,EAClD;AAEA,EAAA,MAAM,KAAA,GAAQ,YAAA,CAAa,GAAA,EAAK,MAAM,EACnC,KAAA,CAAM,IAAI,CAAA,CACV,MAAA,CAAO,CAAC,CAAA,KAAM,CAAA,CAAE,IAAA,EAAK,CAAE,SAAS,CAAC,CAAA;AACpC,EAAA,MAAM,IAAA,GACJ,QAAQ,iBAAA,KAAsB,MAAA,GAAY,QAAQ,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,OAAA,CAAQ,iBAAiB,CAAA;AAC5F,EAAA,MAAM,IAAA,GAAO,KAAK,MAAA,GAAS,CAAA,GAAI,GAAG,IAAA,CAAK,IAAA,CAAK,IAAI,CAAC;AAAA,CAAA,GAAO,EAAA;AAIxD,EAAA,MAAM,KAAK,QAAA,CAAS,GAAA,EAAK,IAAA,EAAM,OAAA,CAAQ,Q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EAAwB;AAC7C,EAAA,OAAO,IAAA,CAAK,KAAA,CAAM,IAAI,CAAA,CAAE,MAAA,CAAO,CAAC,CAAA,KAAM,CAAA,CAAE,IAAA,EAAK,CAAE,MAAA,GAAS,CAAC,CAAA;AAC3D;AASO,SAAS,aAAA,CACd,IAAA,EACA,OAAA,GAAgC,EAAC,EAC5B;AACL,EAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,UAAA,IAAc,MAAA,CAAO,iBAAA;AAC1C,EAAA,MAAM,EAAE,KAAA,EAAO,SAAA,EAAU,GAAI,aAAA,CAAc,MAAM,IAAI,CAAA;AAErD,EAAA,IAAI,GAAA,GAAM,KAAA;AACV,EAAA,IAAI,OAAA,CAAQ,gBAAgB,MAAA,EAAW;AACrC,IAAA,MAAM,WAAW,OAAA,CAAQ,WAAA;AACzB,IAAA,MAAM,GAAA,GAAM,IAAI,aAAA,CAAc,CAAC,MAAM,CAAA,CAAE,QAAA,CAAS,QAAQ,CAAC,CAAA;AACzD,IAAA,IAAI,OAAO,CAAA,EAAG,GAAA,GAAM,GAAA,CAAI,KAAA,CAAM,MAAM,CAAC,CAAA;AAAA,EACvC;AACA,EAAA,IAAI,MAAA,CAAO,SAAS,IAAI,CAAA,QAAS,GAAA,CAAI,KAAA,CAAM,CAAC,IAAI,CAAA;AAEhD,EAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,CAAC,MAAM,IAAA,CAAK,KAAA,CAAM,CAAC,CAAM,CAAA;AAC7C,EAAA,OAAO,OAAA,CAAQ,WAAW,IAAA,GAAQ,MAAA,CAAO,OAAO,GAAA,EAAK,EAAE,SAAA,EAAW,CAAA,GAAY,GAAA;AAChF","file":"persistence.js","sourcesContent":["/**\n * M81 — transcript operations the consumer was doing by hand INSIDE the framework's own store.\n *\n * ## What this replaces\n *\n * `agents/lib/session/backtrack.ts:188` (agent-builder) wrote straight into the session store with a\n * bare `writeFileSync` — no atomicity, no lock, no API. 243 lines re-implementing parse, cut and\n * write for a format the framework owns. The consumer is not at fault: nothing here was reachable.\n *\n * ## The rule that travels WITH the operation\n *\n * `rules/audit-trail-rotation.md § Session transcripts (M60)` defines a NEVER-delete list — the live\n * pointer, the most recent transcript, and any active registry entry. That rule lived in the\n * CONSUMER. Moving the operation here without moving the rule would ship an API able to destroy\n * exactly what the rule protects — the same shape of defect as M80's `reconcileUpdateGoalStatus`:\n * critical knowledge outside the module that needs it, applied by convention.\n *\n * So `forkTranscript` takes `liveSessionPaths` and refuses, with a TYPED error, to write over any of\n * them. The caller supplies the list because only the caller knows which session is live; the\n * enforcement lives here because that is where the write happens.\n *\n * @internal\n */\n\nimport { closeSync, openSync, readFileSync, readSync, statSync, writeSync } from \"node:fs\";\n\nimport { TheokitAgentError } from \"../../errors.js\";\n\n/**\n * M81 — the target is a protected session (live pointer / most-recent transcript / active entry).\n *\n * Typed rather than a bare `Error` because the caller must distinguish \"this session is protected\"\n * from \"the disk is full\": the first is a correct refusal, the second is an incident.\n */\nexport class LiveSessionError extends TheokitAgentError {\n override readonly name = \"LiveSessionError\";\n\n constructor(readonly path: string) {\n super(\n `refusing to write over a live session transcript: ${path}. ` +\n \"Fork to a new id instead — the live pointer, the most recent transcript and any active \" +\n \"registry entry are never overwritten (audit-trail rotation, M60).\",\n { code: \"live_session_protected\", isRetryable: false },\n );\n }\n}\n\n/** Options for {@link forkTranscript}. */\nexport interface ForkTranscriptOptions {\n /** Keep records `[0, beforeRecordIndex)`. Omit to copy the whole transcript. */\n readonly beforeRecordIndex?: number;\n /**\n * Paths that must never be written over — the live pointer, the most recent transcript, any active\n * registry entry. The caller supplies them because only the caller knows which session is live.\n */\n readonly liveSessionPaths?: readonly string[];\n /**\n * M107 — permission bits for the created destination. Default: `0o600`.\n *\n * A transcript carries the conversation. Before M107 no mode was passed at all, so the file was\n * born `0o666 & ~umask` — measured `0o664` (group-WRITABLE) on a `umask 002` machine, `0o644` on\n * `umask 022`, `0o466` on `umask 0200`. This is a DEFAULT and not a required knob on purpose: a\n * knob would reach zero consumers by omission, which is the failure mode that matters.\n *\n * As with any `open` mode, the `umask` may still CLEAR bits — under `umask 0200` the result is\n * `0o400`. That is accepted: the invariant bought here is \"neither group nor others\", and `0o400`\n * satisfies it more strictly. The SDK deliberately does not `fchmod` the default back, because\n * that would hand back a bit the operator asked to remove.\n */\n readonly mode?: number;\n}\n\n/**\n * Copy `src` into `dst`, keeping the first `beforeRecordIndex` records. The SOURCE is never touched.\n *\n * Atomicity comes from `wx` (exclusive create): two concurrent forks to the same destination cannot\n * both succeed — the loser gets `EEXIST` rather than writing over a half-written file. That is also\n * why an existing destination is a refusal, not a silent overwrite: losing a transcript without an\n * error is the worst failure mode for an operation that touches user sessions.\n */\nexport function forkTranscript(\n src: string,\n dst: string,\n options: ForkTranscriptOptions = {},\n): void {\n for (const live of options.liveSessionPaths ?? []) {\n if (live === dst) throw new LiveSessionError(dst);\n }\n\n const lines = readFileSync(src, \"utf8\")\n .split(\"\\n\")\n .filter((l) => l.trim().length > 0);\n const kept =\n options.beforeRecordIndex === undefined ? lines : lines.slice(0, options.beforeRecordIndex);\n const body = kept.length > 0 ? `${kept.join(\"\\n\")}\\n` : \"\";\n\n // `wx` — fails with EEXIST instead of truncating. The exclusivity IS the concurrency guarantee,\n // and M107 only added the third argument: the mode. See `ForkTranscriptOptions.mode`.\n const fd = openSync(dst, \"wx\", options.mode ?? 0o600);\n try {\n writeSync(fd, body);\n } finally {\n closeSync(fd);\n }\n}\n\n/** Options for {@link readJsonlTail}. */\nexport interface ReadJsonlTailOptions {\n /** Maximum records to return, counted from the END. */\n readonly maxRecords?: number;\n /** Stop once a line contains this marker (exclusive). */\n readonly sinceMarker?: string;\n /** Test-only: also report how many bytes were read, to prove the read is not whole-file. */\n readonly _stats?: boolean;\n}\n\nconst TAIL_CHUNK = 64 * 1024;\n\n/**\n * Reads chunks backwards until enough complete lines have accumulated.\n *\n * Extracted from `readJsonlTail` because the read loop and the record selection are two\n * responsibilities — and together they exceeded the complexity ceiling. The buffer's first line may\n * be cut in half when the read stopped before the start of the file; that is why it is discarded.\n */\nfunction lerCaudaBruta(path: string, want: number): { lines: string[]; bytesRead: number } {\n const size = statSync(path).size;\n const fd = openSync(path, \"r\");\n let bytesRead = 0;\n let tail = \"\";\n let pos = size;\n try {\n while (pos > 0) {\n const len = Math.min(TAIL_CHUNK, pos);\n pos -= len;\n const buf = Buffer.alloc(len);\n readSync(fd, buf, 0, len, pos);\n bytesRead += len;\n tail = buf.toString(\"utf8\") + tail;\n if (nonEmptyLines(tail).length > want) break;\n }\n } finally {\n closeSync(fd);\n }\n const lines = nonEmptyLines(tail);\n return { lines: pos > 0 ? lines.slice(1) : lines, bytesRead };\n}\n\n/** Non-empty lines, in file order. */\nfunction nonEmptyLines(text: string): string[] {\n return text.split(\"\\n\").filter((l) => l.trim().length > 0);\n}\n\n/**\n * Read the LAST records of a JSONL file without loading the whole thing.\n *\n * Reads fixed-size chunks backwards from EOF until enough newlines have been seen. A session\n * transcript grows without bound; loading megabytes to show the last three turns is the cost this\n * exists to avoid — and a `slice` over a full read would be that same cost with a better name.\n */\nexport function readJsonlTail<T = Record<string, unknown>>(\n path: string,\n options: ReadJsonlTailOptions = {},\n): T[] {\n const want = options.maxRecords ?? Number.POSITIVE_INFINITY;\n const { lines, bytesRead } = lerCaudaBruta(path, want);\n\n let sel = lines;\n if (options.sinceMarker !== undefined) {\n const marcador = options.sinceMarker;\n const idx = sel.findLastIndex((l) => l.includes(marcador));\n if (idx >= 0) sel = sel.slice(idx + 1);\n }\n if (Number.isFinite(want)) sel = sel.slice(-want);\n\n const out = sel.map((l) => JSON.parse(l) as T);\n return options._stats === true ? (Object.assign(out, { bytesRead }) as T[]) : out;\n}\n"]}
package/dist/project.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkYPEPCZHF_cjs = require('./chunk-YPEPCZHF.cjs');
4
- var chunkICYBIC6N_cjs = require('./chunk-ICYBIC6N.cjs');
5
- var chunkMHCKWQR3_cjs = require('./chunk-MHCKWQR3.cjs');
6
- require('./chunk-LTCOPATU.cjs');
4
+ var chunkYVI4YPUP_cjs = require('./chunk-YVI4YPUP.cjs');
5
+ var chunkA3MHE2MQ_cjs = require('./chunk-A3MHE2MQ.cjs');
6
+ require('./chunk-BE3W4HYV.cjs');
7
7
  var promises = require('fs/promises');
8
8
  var path = require('path');
9
9
 
@@ -31,12 +31,12 @@ function reduceContent(files, scope) {
31
31
  async function writeProjectInstructions(cwd, content, options) {
32
32
  const filename = options?.filename ?? DEFAULT_FILENAME;
33
33
  if (!chunkYPEPCZHF_cjs.isSafePattern(filename)) {
34
- throw new chunkMHCKWQR3_cjs.ConfigurationError(
34
+ throw new chunkA3MHE2MQ_cjs.ConfigurationError(
35
35
  `writeProjectInstructions: unsafe filename ${JSON.stringify(filename)} (no path traversal, separators, or absolute paths)`,
36
36
  { code: "unsafe_filename" }
37
37
  );
38
38
  }
39
- await chunkICYBIC6N_cjs.replaceFileAtomic(path.join(cwd, filename), content);
39
+ await chunkYVI4YPUP_cjs.replaceFileAtomic(path.join(cwd, filename), content);
40
40
  }
41
41
 
42
42
  exports.readProjectInstructions = readProjectInstructions;
package/dist/project.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { walkUpForFile, isSafePattern } from './chunk-UJ7IQJAG.js';
2
- import { replaceFileAtomic } from './chunk-56OXYUZE.js';
3
- import { ConfigurationError } from './chunk-CD73YHEH.js';
4
- import './chunk-TAPQWDW2.js';
2
+ import { replaceFileAtomic } from './chunk-LGCEYEU2.js';
3
+ import { ConfigurationError } from './chunk-ZYOHF37V.js';
4
+ import './chunk-KCZW75PI.js';
5
5
  import { readFile } from 'fs/promises';
6
6
  import { join } from 'path';
7
7
 
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ var chunk3MUIYMUG_cjs = require('./chunk-3MUIYMUG.cjs');
4
+ require('./chunk-BUUUWQMB.cjs');
5
+ require('./chunk-ED7ANP6W.cjs');
6
+ require('./chunk-VVMLMKYZ.cjs');
7
+ require('./chunk-YVI4YPUP.cjs');
8
+ require('./chunk-A3MHE2MQ.cjs');
9
+ require('./chunk-BE3W4HYV.cjs');
10
+
11
+
12
+
13
+ Object.defineProperty(exports, "__getSubscribersCountForTests", {
14
+ enumerable: true,
15
+ get: function () { return chunk3MUIYMUG_cjs.__getSubscribersCountForTests; }
16
+ });
17
+ Object.defineProperty(exports, "__resetTaskRegistryForTests", {
18
+ enumerable: true,
19
+ get: function () { return chunk3MUIYMUG_cjs.__resetTaskRegistryForTests; }
20
+ });
21
+ Object.defineProperty(exports, "cancel", {
22
+ enumerable: true,
23
+ get: function () { return chunk3MUIYMUG_cjs.cancel; }
24
+ });
25
+ Object.defineProperty(exports, "configure", {
26
+ enumerable: true,
27
+ get: function () { return chunk3MUIYMUG_cjs.configure; }
28
+ });
29
+ Object.defineProperty(exports, "get", {
30
+ enumerable: true,
31
+ get: function () { return chunk3MUIYMUG_cjs.get; }
32
+ });
33
+ Object.defineProperty(exports, "list", {
34
+ enumerable: true,
35
+ get: function () { return chunk3MUIYMUG_cjs.list; }
36
+ });
37
+ Object.defineProperty(exports, "submit", {
38
+ enumerable: true,
39
+ get: function () { return chunk3MUIYMUG_cjs.submit; }
40
+ });
41
+ Object.defineProperty(exports, "subscribe", {
42
+ enumerable: true,
43
+ get: function () { return chunk3MUIYMUG_cjs.subscribe; }
44
+ });
45
+ //# sourceMappingURL=registry-BA3SLAN7.cjs.map
46
+ //# sourceMappingURL=registry-BA3SLAN7.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"registry-N3GTKYCI.cjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"registry-BA3SLAN7.cjs"}
@@ -0,0 +1,9 @@
1
+ export { __getSubscribersCountForTests, __resetTaskRegistryForTests, cancel, configure, get, list, submit, subscribe } from './chunk-7QDTZJRV.js';
2
+ import './chunk-K2BQQ445.js';
3
+ import './chunk-YCHC45BY.js';
4
+ import './chunk-SGTMDQ4O.js';
5
+ import './chunk-LGCEYEU2.js';
6
+ import './chunk-ZYOHF37V.js';
7
+ import './chunk-KCZW75PI.js';
8
+ //# sourceMappingURL=registry-KMI5RA22.js.map
9
+ //# sourceMappingURL=registry-KMI5RA22.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"registry-SOXE4RY6.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"registry-KMI5RA22.js"}
package/dist/retry.cjs CHANGED
@@ -1,14 +1,14 @@
1
1
  'use strict';
2
2
 
3
- var chunk3O2ELBST_cjs = require('./chunk-3O2ELBST.cjs');
4
- require('./chunk-MHCKWQR3.cjs');
5
- require('./chunk-LTCOPATU.cjs');
3
+ var chunkPG3QQLWS_cjs = require('./chunk-PG3QQLWS.cjs');
4
+ require('./chunk-A3MHE2MQ.cjs');
5
+ require('./chunk-BE3W4HYV.cjs');
6
6
 
7
7
 
8
8
 
9
9
  Object.defineProperty(exports, "Retry", {
10
10
  enumerable: true,
11
- get: function () { return chunk3O2ELBST_cjs.Retry; }
11
+ get: function () { return chunkPG3QQLWS_cjs.Retry; }
12
12
  });
13
13
  //# sourceMappingURL=retry.cjs.map
14
14
  //# sourceMappingURL=retry.cjs.map
package/dist/retry.js CHANGED
@@ -1,5 +1,5 @@
1
- export { Retry } from './chunk-JNIWFCKI.js';
2
- import './chunk-CD73YHEH.js';
3
- import './chunk-TAPQWDW2.js';
1
+ export { Retry } from './chunk-VYD6BGKK.js';
2
+ import './chunk-ZYOHF37V.js';
3
+ import './chunk-KCZW75PI.js';
4
4
  //# sourceMappingURL=retry.js.map
5
5
  //# sourceMappingURL=retry.js.map
@@ -1,4 +1,4 @@
1
- import { GOAL_CONTINUATION_MARKER } from './chunk-2ONFGMBV.js';
1
+ import { GOAL_CONTINUATION_MARKER } from './chunk-PY2RQOA7.js';
2
2
 
3
3
  // src/internal/runtime/lifecycle/run-until.ts
4
4
  async function* runUntilImpl(agent, goal, options, deps) {
@@ -174,5 +174,5 @@ ${lastResponse.slice(-1e3)}`
174
174
  }
175
175
 
176
176
  export { composeContinuation, runUntilImpl };
177
- //# sourceMappingURL=run-until-YZ2ODWOF.js.map
178
- //# sourceMappingURL=run-until-YZ2ODWOF.js.map
177
+ //# sourceMappingURL=run-until-BK56WG4P.js.map
178
+ //# sourceMappingURL=run-until-BK56WG4P.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/internal/runtime/lifecycle/run-until.ts"],"names":[],"mappings":";;;AA+BA,gBAAuB,YAAA,CACrB,KAAA,EACA,IAAA,EACA,OAAA,EACA,IAAA,EAC6C;AAC7C,EAAA,MAAM,QAAA,GAAW,SAAS,QAAA,IAAY,EAAA;AACtC,EAAA,MAAM,QAAA,GAAW,SAAS,2BAAA,IAA+B,CAAA;AACzD,EAAA,MAAM,cAAc,OAAA,EAAS,WAAA;AAC7B,EAAA,MAAM,SAAS,OAAA,EAAS,MAAA;AAKxB,EAAA,MAAM,SAAA,GAAY,MAAe,MAAA,KAAW,MAAA,IAAa,MAAA,CAAO,OAAA;AAChE,EAAA,IAAI,IAAA,GAAO,CAAA;AACX,EAAA,IAAI,mBAAA,GAAsB,CAAA;AAC1B,EAAA,IAAI,UAAA,GAAa,CAAA;AACjB,EAAA,IAAI,YAAA,GAAe,EAAA;AAGnB,EAAA,IAAI,WAAU,EAAG;AACf,IAAA,MAAM;AAAA,MACJ,IAAA,EAAM,eAAA;AAAA,MACN,MAAA,EAAQ,QAAA;AAAA,MACR,MAAA,EAAQ;AAAA,KACV;AACA,IAAA,OAAO,EAAE,MAAA,EAAQ,QAAA,EAAU,WAAW,CAAA,EAAG,UAAA,EAAY,eAAe,MAAA,EAAU;AAAA,EAChF;AAEA,EAAA,MAAM,EAAE,IAAA,EAAM,eAAA,EAAiB,MAAA,EAAQ,QAAA,EAAU,QAAQ,cAAA,EAAe;AAExE,EAAA,OAAO,OAAO,QAAA,EAAU;AACtB,IAAA,IAAI,WAAU,EAAG;AACf,MAAA,MAAM,EA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\n *\n * `runUntilImpl` is an `AsyncGenerator<GoalEvent, GoalResult, void>`:\n * yields events as the loop progresses, returns the final result when\n * the goal completes, fails, or is paused. The auxiliary judge model is\n * injected via `deps.judge` so the generator stays free of the `Agent`\n * façade import.\n *\n * EC-C fix: pre-aborted signals emit only `[paused]`, not `[active, paused]`.\n * EC-D: `maxTurns: 0` is supported (vacuous yield active → failed).\n *\n * @internal\n */\n\nimport type { SDKAgent } from \"../../../types/agent.js\";\nimport type {\n GoalEvent,\n GoalOptions,\n GoalResult,\n JudgeResult,\n} from \"../../../types/goal-events.js\";\nimport type { JudgeContext, JudgeOptions } from \"../../judge/judge-call.js\";\nimport { GOAL_CONTINUATION_MARKER } from \"./goal-marker.js\";\n\n/** DI contract: the judge is the only external touchpoint. */\nexport interface RunUntilDeps {\n judge: (ctx: JudgeContext, opts?: JudgeOptions) => Promise<JudgeResult>;\n}\n\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: the goal-loop interleaves turn-start, send, judge, continuation, abort-check, and failure-bail — extracting helpers harms the linear narrative.\nexport async function* runUntilImpl(\n agent: SDKAgent,\n goal: string,\n options: GoalOptions | undefined,\n deps: RunUntilDeps,\n): AsyncGenerator<GoalEvent, GoalResult, void> {\n const maxTurns = options?.maxTurns ?? 20;\n const maxFails = options?.maxConsecutiveJudgeFailures ?? 3;\n const tokenBudget = options?.tokenBudget; // M55 — undefined ⇒ ilimitado\n const signal = options?.signal;\n // Use a function (not direct property access) so TS does not narrow\n // `signal.aborted` to `false | undefined` after the initial check.\n // AbortSignal.aborted is a getter that can flip true between calls.\n // biome-ignore lint/complexity/useOptionalChain: optional-chain would re-narrow signal?.aborted to `false | undefined` after the first check, defeating the purpose of this helper.\n const isAborted = (): boolean => signal !== undefined && signal.aborted;\n let turn = 0;\n let consecutiveFailures = 0;\n let tokensUsed = 0; // M55 — soma observada (0 se usage ausente — fail-open)\n let lastResponse = \"\";\n\n // EC-C: signal already aborted BEFORE first event → emit only [paused].\n if (isAborted()) {\n yield {\n type: \"status_change\",\n status: \"paused\",\n reason: \"aborted via AbortSignal before first turn\",\n };\n return { status: \"paused\", turnsUsed: 0, tokensUsed, finalResponse: undefined };\n }\n\n yield { type: \"status_change\", status: \"active\", reason: \"Goal started\" };\n\n while (turn < maxTurns) {\n if (isAborted()) {\n yield { type: \"status_change\", status: \"paused\", reason: \"aborted via AbortSignal\" };\n return {\n status: \"paused\",\n turnsUsed: turn,\n tokensUsed,\n finalResponse: lastResponse || undefined,\n };\n }\n\n turn += 1;\n yield { type: \"turn_start\", turn, goal };\n\n const continuationPrompt = turn === 1 ? goal : composeContinuation(goal, lastResponse);\n\n const run = await agent.send(continuationPrompt);\n // M55 review HIGH — thread the abort INTO the in-flight run: without this, Esc mid-turn is\n // cosmetic (the turn keeps mutating the workspace until it finishes on its own). `run.cancel()`\n // aborts the stream + in-flight tool calls (types/run.ts contract).\n const cancelOnAbort = (): void => {\n void (run as { cancel?: () => Promise<void> }).cancel?.();\n };\n if (signal !== undefined) {\n if (signal.aborted) cancelOnAbort();\n else signal.addEventListener(\"abort\", cancelOnAbort, { once: true });\n }\n const result = await run.wait();\n if (signal !== undefined) signal.removeEventListener(\"abort\", cancelOnAbort);\n lastResponse = result.result ?? \"\";\n // M55 — token accounting fail-open: só soma quando o run reporta usage.\n const turnTokens = (result as { usage?: { totalTokens?: number } }).usage?.totalTokens;\n if (typeof turnTokens === \"number\") tokensUsed += turnTokens;\n // Re-check aborted right after the turn lands: a cancelled turn must NOT spend a judge call.\n if (isAborted()) {\n yield { type: \"status_change\", status: \"paused\", reason: \"aborted via AbortSignal\" };\n return {\n status: \"paused\",\n turnsUsed: turn,\n tokensUsed,\n finalResponse: lastResponse || undefined,\n };\n }\n yield { type: \"agent_response\", turn, content: lastResponse };\n\n const judgeOpts: JudgeOptions = {};\n if (options?.judgeModel !== undefined) judgeOpts.judgeModel = options.judgeModel;\n if (options?.judgeApiKey !== undefined) judgeOpts.apiKey = options.judgeApiKey;\n // M80 — encaminha o modelo do agente conduzido para o judge derivar quando `judgeModel` é omitido.\n if (options?.agentModel !== undefined) judgeOpts.agentModel = options.agentModel;\n const judgeCtx: JudgeContext = { goal, lastResponse };\n if (options?.subgoals !== undefined) judgeCtx.subgoals = options.subgoals;\n const judgment = await deps.judge(judgeCtx, judgeOpts);\n yield {\n type: \"judge_verdict\",\n turn,\n verdict: judgment.verdict,\n reason: judgment.reason,\n parseFailed: judgment.parseFailed,\n };\n\n if (judgment.parseFailed) {\n consecutiveFailures += 1;\n if (consecutiveFailures >= maxFails) {\n yield {\n type: \"status_change\",\n status: \"failed\",\n reason: `judge model too unreliable (${consecutiveFailures} parse failures in a row)`,\n };\n return {\n status: \"failed\",\n turnsUsed: turn,\n tokensUsed,\n finalResponse: lastResponse || undefined,\n };\n }\n } else {\n consecutiveFailures = 0;\n }\n\n if (judgment.verdict === \"done\") {\n yield { type: \"status_change\", status: \"completed\", reason: judgment.reason };\n return {\n status: \"completed\",\n turnsUsed: turn,\n tokensUsed,\n finalResponse: lastResponse || undefined,\n };\n }\n // M80 — o braço que faltava. Sem ele, um judge que reconhecesse impossibilidade só podia dizer\n // \"continue\", e o loop repetia o mesmo turno até estourar o orçamento — reportando `failed` por\n // limite em vez de `blocked` por impossibilidade. Duas causas distintas com o mesmo desfecho\n // visível, e o consumidor precisava reconciliar depois do loop para distingui-las.\n if (judgment.verdict === \"blocked\") {\n yield { type: \"status_change\", status: \"blocked\", reason: judgment.reason };\n return {\n status: \"blocked\",\n turnsUsed: turn,\n tokensUsed,\n finalResponse: lastResponse || undefined,\n };\n }\n if (judgment.verdict === \"skipped\") {\n yield {\n type: \"status_change\",\n status: \"completed\",\n reason: `skipped: ${judgment.reason}`,\n };\n return {\n status: \"completed\",\n turnsUsed: turn,\n tokensUsed,\n finalResponse: lastResponse || undefined,\n };\n }\n\n // M55 — checagem de token budget APÓS o turno (Codex: wind-down suave, para o loop).\n if (tokenBudget !== undefined && tokensUsed >= tokenBudget) {\n yield {\n type: \"status_change\",\n status: \"budget_limited\",\n reason: `token budget (${tokenBudget}) reached: ${tokensUsed} used`,\n };\n return {\n status: \"budget_limited\",\n turnsUsed: turn,\n tokensUsed,\n finalResponse: lastResponse || undefined,\n };\n }\n\n yield { type: \"continuation\", turn, prompt: continuationPrompt };\n }\n\n yield {\n type: \"status_change\",\n status: \"failed\",\n reason: `max turns (${maxTurns}) exhausted`,\n };\n return {\n status: \"failed\",\n turnsUsed: turn,\n tokensUsed,\n finalResponse: lastResponse || undefined,\n };\n}\n\n/**\n * Build the continuation user message for turns 2+. Keeps last response\n * preview short so we don't bloat the prompt cache.\n *\n * @internal\n */\n\nexport function composeContinuation(goal: string, lastResponse: string): string {\n // M55 — Codex-faithful continuation (ext/goal templates/goals/continuation.md): keep the FULL\n // objective intact, work from current-state evidence, and audit completion requirement-by-requirement\n // before declaring done. Improves the quality of what the judge then evaluates.\n return [\n GOAL_CONTINUATION_MARKER,\n \"Continue working toward the active goal.\",\n \"\",\n `<objective>\\n${goal}\\n</objective>`,\n \"\",\n \"Continuation behavior:\",\n \"- This goal persists across turns. Keep the full objective intact; if it cannot be finished now,\",\n \" make concrete progress toward the real requested end state and do not redefine success around a\",\n \" smaller or easier task.\",\n \"\",\n \"Work from evidence:\",\n \"- Use the current worktree and external state as authoritative. Inspect the current state before\",\n \" relying on it. Improve, replace, or remove existing work as needed to satisfy the actual objective.\",\n \"\",\n \"Completion audit:\",\n \"- Before deciding the goal is achieved, treat completion as unproven and verify it against the actual\",\n \" current state, requirement by requirement. Treat uncertain or indirect evidence as not achieved.\",\n \"\",\n `Your last response was:\\n${lastResponse.slice(-1000)}`,\n ].join(\"\\n\");\n}\n"]}
1
+ {"version":3,"sources":["../src/internal/runtime/lifecycle/run-until.ts"],"names":[],"mappings":";;;AA+BA,gBAAuB,YAAA,CACrB,KAAA,EACA,IAAA,EACA,OAAA,EACA,IAAA,EAC6C;AAC7C,EAAA,MAAM,QAAA,GAAW,SAAS,QAAA,IAAY,EAAA;AACtC,EAAA,MAAM,Q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Ac,QAAQ,CAAA,WAAA;AAAA,GAChC;AACA,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ,QAAA;AAAA,IACR,SAAA,EAAW,IAAA;AAAA,IACX,UAAA;AAAA,IACA,eAAe,YAAA,IAAgB;AAAA,GACjC;AACF;AASO,SAAS,mBAAA,CAAoB,MAAc,YAAA,EAA8B;AAI9E,EAAA,OAAO;AAAA,IACL,wBAAA;AAAA,IACA,0CAAA;AAAA,IACA,EAAA;AAAA,IACA,CAAA;AAAA,EAAgB,IAAI;AAAA,YAAA,CAAA;AAAA,IACpB,EAAA;AAAA,IACA,wBAAA;AAAA,IACA,kGAAA;AAAA,IACA,mGAAA;AAAA,IACA,2BAAA;AAAA,IACA,EAAA;AAAA,IACA,qBAAA;AAAA,IACA,kGAAA;AAAA,IACA,uGAAA;AAAA,IACA,EAAA;AAAA,IACA,mBAAA;AAAA,IACA,uGAAA;AAAA,IACA,oGAAA;AAAA,IACA,EAAA;AAAA,IACA,CAAA;AAAA,EAA4B,YAAA,CAAa,KAAA,CAAM,IAAK,CAAC,CAAA;AAAA,GACvD,CAAE,KAAK,IAAI,CAAA;AACb","file":"run-until-BK56WG4P.js","sourcesContent":["/**\n * Goal-driven Ralph loop (T3.2, ADRs D115-D121).\n *\n * `runUntilImpl` is an `AsyncGenerator<GoalEvent, GoalResult, void>`:\n * yields events as the loop progresses, returns the final result when\n * the goal completes, fails, or is paused. The auxiliary judge model is\n * injected via `deps.judge` so the generator stays free of the `Agent`\n * façade import.\n *\n * EC-C fix: pre-aborted signals emit only `[paused]`, not `[active, paused]`.\n * EC-D: `maxTurns: 0` is supported (vacuous yield active → failed).\n *\n * @internal\n */\n\nimport type { SDKAgent } from \"../../../types/agent.js\";\nimport type {\n GoalEvent,\n GoalOptions,\n GoalResult,\n JudgeResult,\n} from \"../../../types/goal-events.js\";\nimport type { JudgeContext, JudgeOptions } from \"../../judge/judge-call.js\";\nimport { GOAL_CONTINUATION_MARKER } from \"./goal-marker.js\";\n\n/** DI contract: the judge is the only external touchpoint. */\nexport interface RunUntilDeps {\n judge: (ctx: JudgeContext, opts?: JudgeOptions) => Promise<JudgeResult>;\n}\n\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: the goal-loop interleaves turn-start, send, judge, continuation, abort-check, and failure-bail — extracting helpers harms the linear narrative.\nexport async function* runUntilImpl(\n agent: SDKAgent,\n goal: string,\n options: GoalOptions | undefined,\n deps: RunUntilDeps,\n): AsyncGenerator<GoalEvent, GoalResult, void> {\n const maxTurns = options?.maxTurns ?? 20;\n const maxFails = options?.maxConsecutiveJudgeFailures ?? 3;\n const tokenBudget = options?.tokenBudget; // M55 — undefined ⇒ ilimitado\n const signal = options?.signal;\n // Use a function (not direct property access) so TS does not narrow\n // `signal.aborted` to `false | undefined` after the initial check.\n // AbortSignal.aborted is a getter that can flip true between calls.\n // biome-ignore lint/complexity/useOptionalChain: optional-chain would re-narrow signal?.aborted to `false | undefined` after the first check, defeating the purpose of this helper.\n const isAborted = (): boolean => signal !== undefined && signal.aborted;\n let turn = 0;\n let consecutiveFailures = 0;\n let tokensUsed = 0; // M55 — soma observada (0 se usage ausente — fail-open)\n let lastResponse = \"\";\n\n // EC-C: signal already aborted BEFORE first event → emit only [paused].\n if (isAborted()) {\n yield {\n type: \"status_change\",\n status: \"paused\",\n reason: \"aborted via AbortSignal before first turn\",\n };\n return { status: \"paused\", turnsUsed: 0, tokensUsed, finalResponse: undefined };\n }\n\n yield { type: \"status_change\", status: \"active\", reason: \"Goal started\" };\n\n while (turn < maxTurns) {\n if (isAborted()) {\n yield { type: \"status_change\", status: \"paused\", reason: \"aborted via AbortSignal\" };\n return {\n status: \"paused\",\n turnsUsed: turn,\n tokensUsed,\n finalResponse: lastResponse || undefined,\n };\n }\n\n turn += 1;\n yield { type: \"turn_start\", turn, goal };\n\n const continuationPrompt = turn === 1 ? goal : composeContinuation(goal, lastResponse);\n\n const run = await agent.send(continuationPrompt);\n // M55 review HIGH — thread the abort INTO the in-flight run: without this, Esc mid-turn is\n // cosmetic (the turn keeps mutating the workspace until it finishes on its own). `run.cancel()`\n // aborts the stream + in-flight tool calls (types/run.ts contract).\n const cancelOnAbort = (): void => {\n void (run as { cancel?: () => Promise<void> }).cancel?.();\n };\n if (signal !== undefined) {\n if (signal.aborted) cancelOnAbort();\n else signal.addEventListener(\"abort\", cancelOnAbort, { once: true });\n }\n const result = await run.wait();\n if (signal !== undefined) signal.removeEventListener(\"abort\", cancelOnAbort);\n lastResponse = result.result ?? \"\";\n // M55 — token accounting fails open: it only sums when the run reports usage.\n const turnTokens = (result as { usage?: { totalTokens?: number } }).usage?.totalTokens;\n if (typeof turnTokens === \"number\") tokensUsed += turnTokens;\n // Re-check aborted right after the turn lands: a cancelled turn must NOT spend a judge call.\n if (isAborted()) {\n yield { type: \"status_change\", status: \"paused\", reason: \"aborted via AbortSignal\" };\n return {\n status: \"paused\",\n turnsUsed: turn,\n tokensUsed,\n finalResponse: lastResponse || undefined,\n };\n }\n yield { type: \"agent_response\", turn, content: lastResponse };\n\n const judgeOpts: JudgeOptions = {};\n if (options?.judgeModel !== undefined) judgeOpts.judgeModel = options.judgeModel;\n if (options?.judgeApiKey !== undefined) judgeOpts.apiKey = options.judgeApiKey;\n // M80 — forwards the driven agent's model so the judge can derive when `judgeModel` is omitted.\n if (options?.agentModel !== undefined) judgeOpts.agentModel = options.agentModel;\n const judgeCtx: JudgeContext = { goal, lastResponse };\n if (options?.subgoals !== undefined) judgeCtx.subgoals = options.subgoals;\n const judgment = await deps.judge(judgeCtx, judgeOpts);\n yield {\n type: \"judge_verdict\",\n turn,\n verdict: judgment.verdict,\n reason: judgment.reason,\n parseFailed: judgment.parseFailed,\n };\n\n if (judgment.parseFailed) {\n consecutiveFailures += 1;\n if (consecutiveFailures >= maxFails) {\n yield {\n type: \"status_change\",\n status: \"failed\",\n reason: `judge model too unreliable (${consecutiveFailures} parse failures in a row)`,\n };\n return {\n status: \"failed\",\n turnsUsed: turn,\n tokensUsed,\n finalResponse: lastResponse || undefined,\n };\n }\n } else {\n consecutiveFailures = 0;\n }\n\n if (judgment.verdict === \"done\") {\n yield { type: \"status_change\", status: \"completed\", reason: judgment.reason };\n return {\n status: \"completed\",\n turnsUsed: turn,\n tokensUsed,\n finalResponse: lastResponse || undefined,\n };\n }\n // M80 — the missing arm. Without it, a judge recognizing impossibility could only say\n // \"continue\", and the loop repeated the same turn until it blew the budget — reporting `failed` on\n // a limit rather than `blocked` on impossibility. Two distinct causes with the same\n // visible outcome, and the consumer had to reconcile after the loop to tell them apart.\n if (judgment.verdict === \"blocked\") {\n yield { type: \"status_change\", status: \"blocked\", reason: judgment.reason };\n return {\n status: \"blocked\",\n turnsUsed: turn,\n tokensUsed,\n finalResponse: lastResponse || undefined,\n };\n }\n if (judgment.verdict === \"skipped\") {\n yield {\n type: \"status_change\",\n status: \"completed\",\n reason: `skipped: ${judgment.reason}`,\n };\n return {\n status: \"completed\",\n turnsUsed: turn,\n tokensUsed,\n finalResponse: lastResponse || undefined,\n };\n }\n\n // M55 — token-budget check AFTER the turn (Codex: gentle wind-down, stops the loop).\n if (tokenBudget !== undefined && tokensUsed >= tokenBudget) {\n yield {\n type: \"status_change\",\n status: \"budget_limited\",\n reason: `token budget (${tokenBudget}) reached: ${tokensUsed} used`,\n };\n return {\n status: \"budget_limited\",\n turnsUsed: turn,\n tokensUsed,\n finalResponse: lastResponse || undefined,\n };\n }\n\n yield { type: \"continuation\", turn, prompt: continuationPrompt };\n }\n\n yield {\n type: \"status_change\",\n status: \"failed\",\n reason: `max turns (${maxTurns}) exhausted`,\n };\n return {\n status: \"failed\",\n turnsUsed: turn,\n tokensUsed,\n finalResponse: lastResponse || undefined,\n };\n}\n\n/**\n * Build the continuation user message for turns 2+. Keeps last response\n * preview short so we don't bloat the prompt cache.\n *\n * @internal\n */\n\nexport function composeContinuation(goal: string, lastResponse: string): string {\n // M55 — Codex-faithful continuation (ext/goal templates/goals/continuation.md): keep the FULL\n // objective intact, work from current-state evidence, and audit completion requirement-by-requirement\n // before declaring done. Improves the quality of what the judge then evaluates.\n return [\n GOAL_CONTINUATION_MARKER,\n \"Continue working toward the active goal.\",\n \"\",\n `<objective>\\n${goal}\\n</objective>`,\n \"\",\n \"Continuation behavior:\",\n \"- This goal persists across turns. Keep the full objective intact; if it cannot be finished now,\",\n \" make concrete progress toward the real requested end state and do not redefine success around a\",\n \" smaller or easier task.\",\n \"\",\n \"Work from evidence:\",\n \"- Use the current worktree and external state as authoritative. Inspect the current state before\",\n \" relying on it. Improve, replace, or remove existing work as needed to satisfy the actual objective.\",\n \"\",\n \"Completion audit:\",\n \"- Before deciding the goal is achieved, treat completion as unproven and verify it against the actual\",\n \" current state, requirement by requirement. Treat uncertain or indirect evidence as not achieved.\",\n \"\",\n `Your last response was:\\n${lastResponse.slice(-1000)}`,\n ].join(\"\\n\");\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkYPQF26X7_cjs = require('./chunk-YPQF26X7.cjs');
3
+ var chunkOBA6YK2R_cjs = require('./chunk-OBA6YK2R.cjs');
4
4
 
5
5
  // src/internal/runtime/lifecycle/run-until.ts
6
6
  async function* runUntilImpl(agent, goal, options, deps) {
@@ -150,7 +150,7 @@ async function* runUntilImpl(agent, goal, options, deps) {
150
150
  }
151
151
  function composeContinuation(goal, lastResponse) {
152
152
  return [
153
- chunkYPQF26X7_cjs.GOAL_CONTINUATION_MARKER,
153
+ chunkOBA6YK2R_cjs.GOAL_CONTINUATION_MARKER,
154
154
  "Continue working toward the active goal.",
155
155
  "",
156
156
  `<objective>
@@ -177,5 +177,5 @@ ${lastResponse.slice(-1e3)}`
177
177
 
178
178
  exports.composeContinuation = composeContinuation;
179
179
  exports.runUntilImpl = runUntilImpl;
180
- //# sourceMappingURL=run-until-ZZ2JLPJM.cjs.map
181
- //# sourceMappingURL=run-until-ZZ2JLPJM.cjs.map
180
+ //# sourceMappingURL=run-until-L5KQD3PV.cjs.map
181
+ //# sourceMappingURL=run-until-L5KQD3PV.cjs.map