@theokit/sdk 4.36.0 → 4.37.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 (301) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/agent-K5LYVJGJ.cjs +51 -0
  3. package/dist/{agent-P77NPBF4.cjs.map → agent-K5LYVJGJ.cjs.map} +1 -1
  4. package/dist/agent-ODWMOAEC.js +42 -0
  5. package/dist/{agent-H6HL5ITH.js.map → agent-ODWMOAEC.js.map} +1 -1
  6. package/dist/agent.d.ts +2 -1
  7. package/dist/auth/index.cjs +15 -15
  8. package/dist/auth/index.js +4 -4
  9. package/dist/{batch-2FSD2UNL.cjs → batch-3SEPDXCU.cjs} +23 -23
  10. package/dist/{batch-2FSD2UNL.cjs.map → batch-3SEPDXCU.cjs.map} +1 -1
  11. package/dist/{batch-MR2HKYMS.js → batch-SY5GZLFD.js} +9 -9
  12. package/dist/{batch-MR2HKYMS.js.map → batch-SY5GZLFD.js.map} +1 -1
  13. package/dist/{chunk-JLMXKTBX.cjs → chunk-2423XDPT.cjs} +26 -26
  14. package/dist/{chunk-JLMXKTBX.cjs.map → chunk-2423XDPT.cjs.map} +1 -1
  15. package/dist/{chunk-5IB2UKSN.js → chunk-2WFB5ZOX.js} +5 -5
  16. package/dist/{chunk-5IB2UKSN.js.map → chunk-2WFB5ZOX.js.map} +1 -1
  17. package/dist/{chunk-EPYZOCOL.cjs → chunk-3ILFUXNE.cjs} +5 -5
  18. package/dist/{chunk-EPYZOCOL.cjs.map → chunk-3ILFUXNE.cjs.map} +1 -1
  19. package/dist/{chunk-KSKU6JY6.cjs → chunk-3O2ELBST.cjs} +5 -5
  20. package/dist/{chunk-KSKU6JY6.cjs.map → chunk-3O2ELBST.cjs.map} +1 -1
  21. package/dist/{chunk-M2PU44HP.cjs → chunk-4YB7B3RP.cjs} +8 -8
  22. package/dist/{chunk-M2PU44HP.cjs.map → chunk-4YB7B3RP.cjs.map} +1 -1
  23. package/dist/{chunk-S2BBRVQX.js → chunk-56OXYUZE.js} +8 -7
  24. package/dist/chunk-56OXYUZE.js.map +1 -0
  25. package/dist/{chunk-D42XHI4O.cjs → chunk-56ZM6P7Z.cjs} +13 -14
  26. package/dist/chunk-56ZM6P7Z.cjs.map +1 -0
  27. package/dist/{chunk-7BTE3RXJ.js → chunk-5SB4V74H.js} +7 -8
  28. package/dist/chunk-5SB4V74H.js.map +1 -0
  29. package/dist/{chunk-MZ5ZRORA.cjs → chunk-6EDQBX7U.cjs} +17 -16
  30. package/dist/chunk-6EDQBX7U.cjs.map +1 -0
  31. package/dist/{chunk-RKG6QFCJ.js → chunk-6VP3XGEK.js} +4 -4
  32. package/dist/{chunk-RKG6QFCJ.js.map → chunk-6VP3XGEK.js.map} +1 -1
  33. package/dist/{chunk-KAP4GJHO.js → chunk-77WHPVXE.js} +10 -11
  34. package/dist/chunk-77WHPVXE.js.map +1 -0
  35. package/dist/{chunk-LALRCFSN.cjs → chunk-7DXLNNKH.cjs} +4 -4
  36. package/dist/{chunk-LALRCFSN.cjs.map → chunk-7DXLNNKH.cjs.map} +1 -1
  37. package/dist/{chunk-WEHUJ7ZS.cjs → chunk-ALU3KC4G.cjs} +267 -120
  38. package/dist/chunk-ALU3KC4G.cjs.map +1 -0
  39. package/dist/{chunk-Z2OC3UIW.cjs → chunk-BJMKQOY2.cjs} +11 -11
  40. package/dist/{chunk-Z2OC3UIW.cjs.map → chunk-BJMKQOY2.cjs.map} +1 -1
  41. package/dist/{chunk-WLKFWQSJ.js → chunk-CD73YHEH.js} +3 -3
  42. package/dist/{chunk-WLKFWQSJ.js.map → chunk-CD73YHEH.js.map} +1 -1
  43. package/dist/{chunk-BXV2QUIC.js → chunk-CSZRJ4RE.js} +6 -5
  44. package/dist/chunk-CSZRJ4RE.js.map +1 -0
  45. package/dist/{chunk-6M6A6WWW.cjs → chunk-D4ZUJTFB.cjs} +9 -10
  46. package/dist/chunk-D4ZUJTFB.cjs.map +1 -0
  47. package/dist/{chunk-XAUBQMQU.js → chunk-DCJ5MCJ3.js} +7 -7
  48. package/dist/{chunk-XAUBQMQU.js.map → chunk-DCJ5MCJ3.js.map} +1 -1
  49. package/dist/{chunk-Y66627E4.cjs → chunk-E7X2B66S.cjs} +24 -24
  50. package/dist/{chunk-Y66627E4.cjs.map → chunk-E7X2B66S.cjs.map} +1 -1
  51. package/dist/{chunk-6CLRANZA.js → chunk-EXQV452X.js} +3 -3
  52. package/dist/{chunk-6CLRANZA.js.map → chunk-EXQV452X.js.map} +1 -1
  53. package/dist/{chunk-EKFA76N4.js → chunk-F3X7Q4BF.js} +344 -453
  54. package/dist/chunk-F3X7Q4BF.js.map +1 -0
  55. package/dist/{chunk-XIG2IE3L.js → chunk-F6Y4IEQM.js} +5 -4
  56. package/dist/chunk-F6Y4IEQM.js.map +1 -0
  57. package/dist/{chunk-N24XBYNX.cjs → chunk-FAY3QDGC.cjs} +11 -10
  58. package/dist/chunk-FAY3QDGC.cjs.map +1 -0
  59. package/dist/{chunk-JD74LN7R.cjs → chunk-FK4EJD2I.cjs} +7 -6
  60. package/dist/chunk-FK4EJD2I.cjs.map +1 -0
  61. package/dist/{chunk-IX2LKBCD.js → chunk-GL7CFBVC.js} +176 -35
  62. package/dist/chunk-GL7CFBVC.js.map +1 -0
  63. package/dist/{chunk-77FOZCOT.js → chunk-GLUWH6JO.js} +6 -5
  64. package/dist/chunk-GLUWH6JO.js.map +1 -0
  65. package/dist/{chunk-RZQ6E5YZ.cjs → chunk-GM7QDQ24.cjs} +11 -11
  66. package/dist/{chunk-RZQ6E5YZ.cjs.map → chunk-GM7QDQ24.cjs.map} +1 -1
  67. package/dist/{chunk-G4WI3VW2.cjs → chunk-H5YVJB4K.cjs} +9 -10
  68. package/dist/chunk-H5YVJB4K.cjs.map +1 -0
  69. package/dist/{chunk-HRA3CPGG.js → chunk-HEN5WXXI.js} +9 -8
  70. package/dist/chunk-HEN5WXXI.js.map +1 -0
  71. package/dist/{chunk-LU7VALW5.js → chunk-I35DI7ES.js} +3 -3
  72. package/dist/{chunk-LU7VALW5.js.map → chunk-I35DI7ES.js.map} +1 -1
  73. package/dist/{chunk-TIZ4TS5V.cjs → chunk-ICYBIC6N.cjs} +8 -7
  74. package/dist/chunk-ICYBIC6N.cjs.map +1 -0
  75. package/dist/{chunk-2DYI7MIF.cjs → chunk-IEUDKUPM.cjs} +8 -8
  76. package/dist/{chunk-2DYI7MIF.cjs.map → chunk-IEUDKUPM.cjs.map} +1 -1
  77. package/dist/{chunk-AIDNODHJ.cjs → chunk-ITLS5LRF.cjs} +11 -11
  78. package/dist/{chunk-AIDNODHJ.cjs.map → chunk-ITLS5LRF.cjs.map} +1 -1
  79. package/dist/{chunk-M72RJVPC.js → chunk-JNIWFCKI.js} +3 -3
  80. package/dist/{chunk-M72RJVPC.js.map → chunk-JNIWFCKI.js.map} +1 -1
  81. package/dist/{chunk-LEJXBUBD.js → chunk-LISL36B6.js} +5 -5
  82. package/dist/{chunk-LEJXBUBD.js.map → chunk-LISL36B6.js.map} +1 -1
  83. package/dist/{chunk-3XJ7CS2C.cjs → chunk-LMWXF4LL.cjs} +554 -666
  84. package/dist/chunk-LMWXF4LL.cjs.map +1 -0
  85. package/dist/{chunk-BEURCLDV.cjs → chunk-LTCOPATU.cjs} +9 -3
  86. package/dist/chunk-LTCOPATU.cjs.map +1 -0
  87. package/dist/{chunk-TQKCU7CL.js → chunk-M5ZQBOIZ.js} +3 -3
  88. package/dist/{chunk-TQKCU7CL.js.map → chunk-M5ZQBOIZ.js.map} +1 -1
  89. package/dist/{chunk-A44COQJJ.cjs → chunk-MHCKWQR3.cjs} +8 -8
  90. package/dist/{chunk-A44COQJJ.cjs.map → chunk-MHCKWQR3.cjs.map} +1 -1
  91. package/dist/{chunk-7S7KKUO6.cjs → chunk-MRODLUGY.cjs} +4 -4
  92. package/dist/{chunk-7S7KKUO6.cjs.map → chunk-MRODLUGY.cjs.map} +1 -1
  93. package/dist/{chunk-BOTK6ZUP.js → chunk-MXSMAGDU.js} +3 -3
  94. package/dist/{chunk-BOTK6ZUP.js.map → chunk-MXSMAGDU.js.map} +1 -1
  95. package/dist/{chunk-5PZMMF4H.js → chunk-NFCKEBHI.js} +3 -3
  96. package/dist/{chunk-5PZMMF4H.js.map → chunk-NFCKEBHI.js.map} +1 -1
  97. package/dist/{chunk-6M4ODB2V.cjs → chunk-NNSKJCBM.cjs} +10 -10
  98. package/dist/{chunk-6M4ODB2V.cjs.map → chunk-NNSKJCBM.cjs.map} +1 -1
  99. package/dist/{chunk-4WL52CXU.cjs → chunk-NQ4AC2U4.cjs} +9 -9
  100. package/dist/{chunk-4WL52CXU.cjs.map → chunk-NQ4AC2U4.cjs.map} +1 -1
  101. package/dist/{chunk-YRXTIESB.cjs → chunk-P34DHHYQ.cjs} +4 -4
  102. package/dist/{chunk-YRXTIESB.cjs.map → chunk-P34DHHYQ.cjs.map} +1 -1
  103. package/dist/{chunk-HFPGOTVF.cjs → chunk-PAEJPLVN.cjs} +4 -4
  104. package/dist/{chunk-HFPGOTVF.cjs.map → chunk-PAEJPLVN.cjs.map} +1 -1
  105. package/dist/{chunk-S5RCBTSF.js → chunk-QFMXXUUT.js} +3 -3
  106. package/dist/{chunk-S5RCBTSF.js.map → chunk-QFMXXUUT.js.map} +1 -1
  107. package/dist/{chunk-V4XRLPEF.js → chunk-QGDKZDPN.js} +3 -3
  108. package/dist/{chunk-V4XRLPEF.js.map → chunk-QGDKZDPN.js.map} +1 -1
  109. package/dist/{chunk-DHLZIMP6.cjs → chunk-QUFSDDNU.cjs} +15 -15
  110. package/dist/{chunk-DHLZIMP6.cjs.map → chunk-QUFSDDNU.cjs.map} +1 -1
  111. package/dist/{chunk-BFWPZMG7.js → chunk-SDIBMLL5.js} +8 -8
  112. package/dist/{chunk-BFWPZMG7.js.map → chunk-SDIBMLL5.js.map} +1 -1
  113. package/dist/{chunk-GIW4L6HY.cjs → chunk-SWIBQFPH.cjs} +4 -4
  114. package/dist/{chunk-GIW4L6HY.cjs.map → chunk-SWIBQFPH.cjs.map} +1 -1
  115. package/dist/{chunk-JTFYYKDT.js → chunk-TAPQWDW2.js} +9 -4
  116. package/dist/chunk-TAPQWDW2.js.map +1 -0
  117. package/dist/{chunk-4GTXATWK.cjs → chunk-THEYGCYS.cjs} +4 -4
  118. package/dist/{chunk-4GTXATWK.cjs.map → chunk-THEYGCYS.cjs.map} +1 -1
  119. package/dist/{chunk-CJVMDRQB.cjs → chunk-TQI3KRXZ.cjs} +5 -4
  120. package/dist/chunk-TQI3KRXZ.cjs.map +1 -0
  121. package/dist/{chunk-LUSXDZPV.cjs → chunk-U2WLFOA3.cjs} +4 -4
  122. package/dist/{chunk-LUSXDZPV.cjs.map → chunk-U2WLFOA3.cjs.map} +1 -1
  123. package/dist/{chunk-FKCC2MED.js → chunk-UQPDFW4E.js} +3 -3
  124. package/dist/{chunk-FKCC2MED.js.map → chunk-UQPDFW4E.js.map} +1 -1
  125. package/dist/{chunk-CR3DGWUQ.js → chunk-VNNK6AKU.js} +3 -3
  126. package/dist/{chunk-CR3DGWUQ.js.map → chunk-VNNK6AKU.js.map} +1 -1
  127. package/dist/{chunk-ANIZEWTU.cjs → chunk-W4QN5CMG.cjs} +9 -8
  128. package/dist/chunk-W4QN5CMG.cjs.map +1 -0
  129. package/dist/{chunk-POQT2OIF.js → chunk-WDGCZDRG.js} +3 -3
  130. package/dist/{chunk-POQT2OIF.js.map → chunk-WDGCZDRG.js.map} +1 -1
  131. package/dist/{chunk-Q56IYTBZ.js → chunk-XAEAMI5H.js} +4 -4
  132. package/dist/{chunk-Q56IYTBZ.js.map → chunk-XAEAMI5H.js.map} +1 -1
  133. package/dist/{chunk-BWT67BI4.cjs → chunk-XAYVHS2B.cjs} +4 -4
  134. package/dist/{chunk-BWT67BI4.cjs.map → chunk-XAYVHS2B.cjs.map} +1 -1
  135. package/dist/{chunk-KIO7QFIV.cjs → chunk-YBFDBOUN.cjs} +8 -8
  136. package/dist/{chunk-KIO7QFIV.cjs.map → chunk-YBFDBOUN.cjs.map} +1 -1
  137. package/dist/{chunk-BNIFFFH3.js → chunk-YCXMSDSP.js} +4 -4
  138. package/dist/{chunk-BNIFFFH3.js.map → chunk-YCXMSDSP.js.map} +1 -1
  139. package/dist/{chunk-UVNG67DG.js → chunk-YDLNI7J6.js} +3 -3
  140. package/dist/{chunk-UVNG67DG.js.map → chunk-YDLNI7J6.js.map} +1 -1
  141. package/dist/{chunk-UAYYNWYJ.js → chunk-YHZXBDAW.js} +5 -4
  142. package/dist/chunk-YHZXBDAW.js.map +1 -0
  143. package/dist/{chunk-OKXUMCGM.js → chunk-YVTNFKZO.js} +5 -5
  144. package/dist/{chunk-OKXUMCGM.js.map → chunk-YVTNFKZO.js.map} +1 -1
  145. package/dist/{chunk-GJAGKFTR.js → chunk-ZJN6NTHE.js} +3 -3
  146. package/dist/{chunk-GJAGKFTR.js.map → chunk-ZJN6NTHE.js.map} +1 -1
  147. package/dist/{chunk-XV2RBL6D.js → chunk-ZW345YOI.js} +8 -9
  148. package/dist/chunk-ZW345YOI.js.map +1 -0
  149. package/dist/compact-session-H5TKLD55.cjs +54 -0
  150. package/dist/{compact-session-BEA3IOON.cjs.map → compact-session-H5TKLD55.cjs.map} +1 -1
  151. package/dist/compact-session-WNKKIIDW.js +17 -0
  152. package/dist/{compact-session-5BDD4HIB.js.map → compact-session-WNKKIIDW.js.map} +1 -1
  153. package/dist/compaction.cjs +16 -16
  154. package/dist/compaction.js +3 -3
  155. package/dist/concurrency.cjs +6 -6
  156. package/dist/concurrency.js +4 -4
  157. package/dist/context-VAYLPT4O.js +5 -0
  158. package/dist/{context-GWANQLX4.js.map → context-VAYLPT4O.js.map} +1 -1
  159. package/dist/context-ZV33V4DC.cjs +22 -0
  160. package/dist/{context-KNWVTZSY.cjs.map → context-ZV33V4DC.cjs.map} +1 -1
  161. package/dist/cron.cjs +28 -28
  162. package/dist/cron.js +27 -27
  163. package/dist/errors.cjs +21 -21
  164. package/dist/errors.js +2 -2
  165. package/dist/eval.cjs +31 -31
  166. package/dist/eval.js +27 -27
  167. package/dist/{executor-Y4MKPIUD.cjs → executor-OZSYXDKF.cjs} +23 -23
  168. package/dist/{executor-Y4MKPIUD.cjs.map → executor-OZSYXDKF.cjs.map} +1 -1
  169. package/dist/{executor-ORJS5GV2.js → executor-PAH72CB5.js} +7 -7
  170. package/dist/{executor-ORJS5GV2.js.map → executor-PAH72CB5.js.map} +1 -1
  171. package/dist/filesystem/index.cjs +7 -7
  172. package/dist/filesystem/index.js +3 -3
  173. package/dist/fs-session-store-6MY7PNI2.js +10 -0
  174. package/dist/{fs-session-store-4ALCDU3K.js.map → fs-session-store-6MY7PNI2.js.map} +1 -1
  175. package/dist/fs-session-store-7E7UPLF2.cjs +19 -0
  176. package/dist/{fs-session-store-IQYE35HX.cjs.map → fs-session-store-7E7UPLF2.cjs.map} +1 -1
  177. package/dist/generate-object-5SCEH2EE.cjs +20 -0
  178. package/dist/{generate-object-H3RNAM6S.cjs.map → generate-object-5SCEH2EE.cjs.map} +1 -1
  179. package/dist/generate-object-I7UD4NWN.js +7 -0
  180. package/dist/{generate-object-YJPDV5BS.js.map → generate-object-I7UD4NWN.js.map} +1 -1
  181. package/dist/index-manager-KKAK7NT3.js +10 -0
  182. package/dist/{index-manager-P7ZUX2RG.js.map → index-manager-KKAK7NT3.js.map} +1 -1
  183. package/dist/index-manager-R6ZJFEZF.cjs +19 -0
  184. package/dist/{index-manager-H7HUMW52.cjs.map → index-manager-R6ZJFEZF.cjs.map} +1 -1
  185. package/dist/index.cjs +124 -129
  186. package/dist/index.cjs.map +1 -1
  187. package/dist/index.d.cts +2 -1
  188. package/dist/index.d.ts +2 -1
  189. package/dist/index.js +45 -50
  190. package/dist/index.js.map +1 -1
  191. package/dist/{inject-session-SMH56NXP.cjs → inject-session-DM4SKTZO.cjs} +8 -8
  192. package/dist/{inject-session-SMH56NXP.cjs.map → inject-session-DM4SKTZO.cjs.map} +1 -1
  193. package/dist/{inject-session-V5FTK72N.js → inject-session-UXNJQTZ6.js} +6 -6
  194. package/dist/{inject-session-V5FTK72N.js.map → inject-session-UXNJQTZ6.js.map} +1 -1
  195. package/dist/internal/diagnostics.d.ts +54 -0
  196. package/dist/internal/local-agent/local-agent-invalidate.d.ts +0 -7
  197. package/dist/internal/local-agent/local-agent-lifecycle.d.ts +13 -0
  198. package/dist/internal/local-agent/local-agent.d.ts +1 -93
  199. package/dist/internal/persistence/index.cjs +25 -25
  200. package/dist/internal/persistence/index.js +6 -6
  201. package/dist/internal/persistence/sqlite-wal.d.cts +0 -9
  202. package/dist/internal/persistence/sqlite-wal.d.ts +0 -9
  203. package/dist/internal/persistence/transcript-ops.d.cts +14 -0
  204. package/dist/internal/persistence/transcript-ops.d.ts +14 -0
  205. package/dist/internal/plugins/lifecycle.d.cts +1 -0
  206. package/dist/internal/plugins/lifecycle.d.ts +1 -0
  207. package/dist/internal/runtime/fixtures/fixture-run-base.d.ts +19 -0
  208. package/dist/internal/runtime/registry/agent-registry.d.ts +0 -1
  209. package/dist/internal/security/index.cjs +13 -13
  210. package/dist/internal/security/index.js +3 -3
  211. package/dist/internal/security/redact.d.cts +0 -18
  212. package/dist/internal/security/redact.d.ts +0 -18
  213. package/dist/judge-call-SP3G3X2Y.cjs +22 -0
  214. package/dist/{judge-call-2FULQ6KL.cjs.map → judge-call-SP3G3X2Y.cjs.map} +1 -1
  215. package/dist/judge-call-TAEIXMYG.js +5 -0
  216. package/dist/{judge-call-D7R3ZTZS.js.map → judge-call-TAEIXMYG.js.map} +1 -1
  217. package/dist/models.cjs +22 -26
  218. package/dist/models.cjs.map +1 -1
  219. package/dist/models.js +13 -17
  220. package/dist/models.js.map +1 -1
  221. package/dist/path-safety.cjs +10 -10
  222. package/dist/path-safety.js +3 -3
  223. package/dist/persistence.cjs +27 -27
  224. package/dist/persistence.cjs.map +1 -1
  225. package/dist/persistence.js +8 -8
  226. package/dist/persistence.js.map +1 -1
  227. package/dist/project.cjs +5 -5
  228. package/dist/project.js +3 -3
  229. package/dist/registry-N3GTKYCI.cjs +46 -0
  230. package/dist/{registry-APYDISL6.cjs.map → registry-N3GTKYCI.cjs.map} +1 -1
  231. package/dist/registry-SOXE4RY6.js +9 -0
  232. package/dist/{registry-34IWWDQQ.js.map → registry-SOXE4RY6.js.map} +1 -1
  233. package/dist/retry.cjs +4 -4
  234. package/dist/retry.js +3 -3
  235. package/dist/sandbox/index.cjs +6 -6
  236. package/dist/sandbox/index.js +2 -2
  237. package/dist/server/errors-envelope.cjs +14 -14
  238. package/dist/server/errors-envelope.js +3 -3
  239. package/dist/session-transcript-6WKLYIN4.js +5 -0
  240. package/dist/{session-transcript-F2ANTA2M.js.map → session-transcript-6WKLYIN4.js.map} +1 -1
  241. package/dist/session-transcript-EAKR4D2W.cjs +50 -0
  242. package/dist/{session-transcript-JXFMPLOT.cjs.map → session-transcript-EAKR4D2W.cjs.map} +1 -1
  243. package/dist/skills.cjs +7 -7
  244. package/dist/skills.js +5 -5
  245. package/dist/stream-object-OFM66VUT.js +7 -0
  246. package/dist/{stream-object-WUQSSRY2.js.map → stream-object-OFM66VUT.js.map} +1 -1
  247. package/dist/stream-object-Y7YCX3BI.cjs +20 -0
  248. package/dist/{stream-object-QEQJJDTI.cjs.map → stream-object-Y7YCX3BI.cjs.map} +1 -1
  249. package/dist/subagents-loader.cjs +6 -6
  250. package/dist/subagents-loader.js +4 -4
  251. package/dist/subscription/index.cjs +3 -3
  252. package/dist/subscription/index.js +2 -2
  253. package/dist/task-store.cjs +7 -7
  254. package/dist/task-store.js +4 -4
  255. package/dist/workflow.cjs +27 -27
  256. package/dist/workflow.js +6 -6
  257. package/package.json +13 -12
  258. package/dist/agent-H6HL5ITH.js +0 -42
  259. package/dist/agent-P77NPBF4.cjs +0 -51
  260. package/dist/chunk-3XJ7CS2C.cjs.map +0 -1
  261. package/dist/chunk-6M6A6WWW.cjs.map +0 -1
  262. package/dist/chunk-77FOZCOT.js.map +0 -1
  263. package/dist/chunk-7BTE3RXJ.js.map +0 -1
  264. package/dist/chunk-ANIZEWTU.cjs.map +0 -1
  265. package/dist/chunk-BEURCLDV.cjs.map +0 -1
  266. package/dist/chunk-BXV2QUIC.js.map +0 -1
  267. package/dist/chunk-CJVMDRQB.cjs.map +0 -1
  268. package/dist/chunk-D42XHI4O.cjs.map +0 -1
  269. package/dist/chunk-EKFA76N4.js.map +0 -1
  270. package/dist/chunk-G4WI3VW2.cjs.map +0 -1
  271. package/dist/chunk-HRA3CPGG.js.map +0 -1
  272. package/dist/chunk-IX2LKBCD.js.map +0 -1
  273. package/dist/chunk-JD74LN7R.cjs.map +0 -1
  274. package/dist/chunk-JTFYYKDT.js.map +0 -1
  275. package/dist/chunk-KAP4GJHO.js.map +0 -1
  276. package/dist/chunk-MZ5ZRORA.cjs.map +0 -1
  277. package/dist/chunk-N24XBYNX.cjs.map +0 -1
  278. package/dist/chunk-S2BBRVQX.js.map +0 -1
  279. package/dist/chunk-TIZ4TS5V.cjs.map +0 -1
  280. package/dist/chunk-UAYYNWYJ.js.map +0 -1
  281. package/dist/chunk-WEHUJ7ZS.cjs.map +0 -1
  282. package/dist/chunk-XIG2IE3L.js.map +0 -1
  283. package/dist/chunk-XV2RBL6D.js.map +0 -1
  284. package/dist/compact-session-5BDD4HIB.js +0 -17
  285. package/dist/compact-session-BEA3IOON.cjs +0 -54
  286. package/dist/context-GWANQLX4.js +0 -5
  287. package/dist/context-KNWVTZSY.cjs +0 -22
  288. package/dist/fs-session-store-4ALCDU3K.js +0 -10
  289. package/dist/fs-session-store-IQYE35HX.cjs +0 -19
  290. package/dist/generate-object-H3RNAM6S.cjs +0 -20
  291. package/dist/generate-object-YJPDV5BS.js +0 -7
  292. package/dist/index-manager-H7HUMW52.cjs +0 -19
  293. package/dist/index-manager-P7ZUX2RG.js +0 -10
  294. package/dist/judge-call-2FULQ6KL.cjs +0 -22
  295. package/dist/judge-call-D7R3ZTZS.js +0 -5
  296. package/dist/registry-34IWWDQQ.js +0 -9
  297. package/dist/registry-APYDISL6.cjs +0 -46
  298. package/dist/session-transcript-F2ANTA2M.js +0 -5
  299. package/dist/session-transcript-JXFMPLOT.cjs +0 -50
  300. package/dist/stream-object-QEQJJDTI.cjs +0 -20
  301. package/dist/stream-object-WUQSSRY2.js +0 -7
@@ -1,41 +1,41 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkBV2MWEMV_cjs = require('./chunk-BV2MWEMV.cjs');
4
- var chunkMZ5ZRORA_cjs = require('./chunk-MZ5ZRORA.cjs');
5
- var chunkG4WI3VW2_cjs = require('./chunk-G4WI3VW2.cjs');
6
- var chunkAIDNODHJ_cjs = require('./chunk-AIDNODHJ.cjs');
7
- var chunkWEHUJ7ZS_cjs = require('./chunk-WEHUJ7ZS.cjs');
8
- var chunkJLMXKTBX_cjs = require('./chunk-JLMXKTBX.cjs');
9
- var chunkN24XBYNX_cjs = require('./chunk-N24XBYNX.cjs');
4
+ var chunk6EDQBX7U_cjs = require('./chunk-6EDQBX7U.cjs');
5
+ var chunkH5YVJB4K_cjs = require('./chunk-H5YVJB4K.cjs');
6
+ var chunkITLS5LRF_cjs = require('./chunk-ITLS5LRF.cjs');
7
+ var chunkALU3KC4G_cjs = require('./chunk-ALU3KC4G.cjs');
8
+ var chunk2423XDPT_cjs = require('./chunk-2423XDPT.cjs');
9
+ var chunkFAY3QDGC_cjs = require('./chunk-FAY3QDGC.cjs');
10
10
  var chunkWPZTYOUX_cjs = require('./chunk-WPZTYOUX.cjs');
11
- var chunk6M6A6WWW_cjs = require('./chunk-6M6A6WWW.cjs');
11
+ var chunkD4ZUJTFB_cjs = require('./chunk-D4ZUJTFB.cjs');
12
12
  var chunk6JSIEDKL_cjs = require('./chunk-6JSIEDKL.cjs');
13
13
  var chunkG2F67XUR_cjs = require('./chunk-G2F67XUR.cjs');
14
14
  var chunkNINIJCHU_cjs = require('./chunk-NINIJCHU.cjs');
15
15
  var chunkYPEPCZHF_cjs = require('./chunk-YPEPCZHF.cjs');
16
16
  var chunkVJ26EKGJ_cjs = require('./chunk-VJ26EKGJ.cjs');
17
- var chunkGIW4L6HY_cjs = require('./chunk-GIW4L6HY.cjs');
18
- var chunkCJVMDRQB_cjs = require('./chunk-CJVMDRQB.cjs');
17
+ var chunkSWIBQFPH_cjs = require('./chunk-SWIBQFPH.cjs');
18
+ var chunkTQI3KRXZ_cjs = require('./chunk-TQI3KRXZ.cjs');
19
19
  var chunkYLQQX5W2_cjs = require('./chunk-YLQQX5W2.cjs');
20
- var chunk2DYI7MIF_cjs = require('./chunk-2DYI7MIF.cjs');
20
+ var chunkIEUDKUPM_cjs = require('./chunk-IEUDKUPM.cjs');
21
21
  var chunkWJVHMTKB_cjs = require('./chunk-WJVHMTKB.cjs');
22
- var chunkTIZ4TS5V_cjs = require('./chunk-TIZ4TS5V.cjs');
23
- var chunkRZQ6E5YZ_cjs = require('./chunk-RZQ6E5YZ.cjs');
24
- var chunkM2PU44HP_cjs = require('./chunk-M2PU44HP.cjs');
22
+ var chunkICYBIC6N_cjs = require('./chunk-ICYBIC6N.cjs');
23
+ var chunkGM7QDQ24_cjs = require('./chunk-GM7QDQ24.cjs');
24
+ var chunk4YB7B3RP_cjs = require('./chunk-4YB7B3RP.cjs');
25
25
  var chunkVYHJZVL5_cjs = require('./chunk-VYHJZVL5.cjs');
26
- var chunkD42XHI4O_cjs = require('./chunk-D42XHI4O.cjs');
27
- var chunkDHLZIMP6_cjs = require('./chunk-DHLZIMP6.cjs');
28
- var chunkKIO7QFIV_cjs = require('./chunk-KIO7QFIV.cjs');
29
- var chunkLALRCFSN_cjs = require('./chunk-LALRCFSN.cjs');
30
- var chunkA44COQJJ_cjs = require('./chunk-A44COQJJ.cjs');
31
- var chunkBEURCLDV_cjs = require('./chunk-BEURCLDV.cjs');
26
+ var chunk56ZM6P7Z_cjs = require('./chunk-56ZM6P7Z.cjs');
27
+ var chunkQUFSDDNU_cjs = require('./chunk-QUFSDDNU.cjs');
28
+ var chunkYBFDBOUN_cjs = require('./chunk-YBFDBOUN.cjs');
29
+ var chunk7DXLNNKH_cjs = require('./chunk-7DXLNNKH.cjs');
30
+ var chunkMHCKWQR3_cjs = require('./chunk-MHCKWQR3.cjs');
31
+ var chunkLTCOPATU_cjs = require('./chunk-LTCOPATU.cjs');
32
32
  var promises = require('fs/promises');
33
33
  var crypto = require('crypto');
34
- var fs = require('fs');
35
34
  var path = require('path');
36
35
  var child_process = require('child_process');
37
36
  var zod = require('zod');
38
37
  var module$1 = require('module');
38
+ var fs = require('fs');
39
39
  var os = require('os');
40
40
 
41
41
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
@@ -224,7 +224,7 @@ async function agentGenerate(agent, agentModel, agentApiKey, agentLocal, input,
224
224
  const { output, maxRetries, errorStrategy, ...sendOptions } = options;
225
225
  const run = await agent.send(input, sendOptions);
226
226
  const result = await run.wait();
227
- const { generateObjectImpl, GenerateObjectError } = await import('./generate-object-H3RNAM6S.cjs');
227
+ const { generateObjectImpl, GenerateObjectError } = await import('./generate-object-5SCEH2EE.cjs');
228
228
  const answer = structurableAnswerOrThrow(result, GenerateObjectError);
229
229
  const { getAgentFacade } = await import('./agent-factory-registry-UU46BUMU.cjs');
230
230
  const facade = getAgentFacade();
@@ -320,65 +320,13 @@ function generateRequestId() {
320
320
  function isLocalAgentId(id) {
321
321
  return id.startsWith(PREFIX.localAgent);
322
322
  }
323
- var FIXTURE_API_KEY_PREFIX = "theo_test_";
324
- function isFixtureApiKey(apiKey) {
325
- if (apiKey === void 0) return false;
326
- return apiKey.startsWith(FIXTURE_API_KEY_PREFIX);
327
- }
328
- function getConfiguredBaseUrl() {
329
- const value = process.env.THEOKIT_API_BASE_URL;
330
- if (value === void 0 || value.length === 0) return void 0;
331
- return value;
332
- }
333
- function shouldUseFixtureMode(apiKey) {
334
- if (getConfiguredBaseUrl() !== void 0) return false;
335
- return isFixtureApiKey(apiKey);
336
- }
337
- function shouldUseRealLocalRuntime(apiKey) {
338
- if (isFixtureApiKey(apiKey)) return false;
339
- if (apiKey === void 0 || apiKey.length === 0) return false;
340
- return typeof process.env.ANTHROPIC_API_KEY === "string" && process.env.ANTHROPIC_API_KEY.length > 0 || typeof process.env.OPENAI_API_KEY === "string" && process.env.OPENAI_API_KEY.length > 0 || typeof process.env.OPENROUTER_API_KEY === "string" && process.env.OPENROUTER_API_KEY.length > 0 || isAwsBedrockAuthAvailable() || isGcpVertexAuthAvailable() || isLocalNoAuthProviderAvailable();
341
- }
342
- function isAwsBedrockAuthAvailable() {
343
- if (typeof process.env.AWS_BEARER_TOKEN_BEDROCK === "string" && process.env.AWS_BEARER_TOKEN_BEDROCK.length > 0) {
344
- return true;
345
- }
346
- if (typeof process.env.AWS_ACCESS_KEY_ID === "string" && process.env.AWS_ACCESS_KEY_ID.length > 0) {
347
- return true;
348
- }
349
- if (typeof process.env.AWS_PROFILE === "string" && process.env.AWS_PROFILE.length > 0) {
350
- return true;
351
- }
352
- return awsCredentialsFileExists();
353
- }
354
- function awsCredentialsFileExists() {
355
- try {
356
- const home = process.env.HOME ?? process.env.USERPROFILE;
357
- if (home === void 0 || home.length === 0) return false;
358
- return fs.existsSync(`${home}/.aws/credentials`) || fs.existsSync(`${home}/.aws/config`);
359
- } catch {
360
- return false;
361
- }
362
- }
363
- function isGcpVertexAuthAvailable() {
364
- if (typeof process.env.GOOGLE_APPLICATION_CREDENTIALS === "string" && process.env.GOOGLE_APPLICATION_CREDENTIALS.length > 0) {
365
- return true;
366
- }
367
- if (typeof process.env.GOOGLE_CLOUD_PROJECT === "string" && process.env.GOOGLE_CLOUD_PROJECT.length > 0) {
368
- return true;
369
- }
370
- return false;
371
- }
372
- function isLocalNoAuthProviderAvailable() {
373
- return true;
374
- }
375
323
 
376
324
  // src/internal/runtime/model-selection.ts
377
325
  function normalizeModel(m) {
378
326
  if (m === void 0 || typeof m !== "string") return m;
379
327
  const id = m.trim();
380
328
  if (id.length === 0) {
381
- throw new chunkA44COQJJ_cjs.ConfigurationError(
329
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
382
330
  'model must be a non-empty "provider/model" id string or a ModelSelection object',
383
331
  { code: "invalid_model_selection" }
384
332
  );
@@ -514,7 +462,7 @@ function registryPath(cwd) {
514
462
  return path.join(cwd, REGISTRY_RELATIVE_PATH);
515
463
  }
516
464
  async function loadRegistry(cwd) {
517
- return chunk6M6A6WWW_cjs.readVersionedJson({
465
+ return chunkD4ZUJTFB_cjs.readVersionedJson({
518
466
  path: registryPath(cwd),
519
467
  currentVersion: SCHEMA_VERSION,
520
468
  defaultValue: () => ({}),
@@ -538,7 +486,7 @@ async function saveRegistry(cwd, agents2) {
538
486
  }
539
487
  const path = registryPath(cwd);
540
488
  await chunkYLQQX5W2_cjs.withCwdMutex(`registry:${cwd}`, async () => {
541
- await chunk6M6A6WWW_cjs.writeVersionedJson(path, serialized, SCHEMA_VERSION);
489
+ await chunkD4ZUJTFB_cjs.writeVersionedJson(path, serialized, SCHEMA_VERSION);
542
490
  });
543
491
  }
544
492
  function toSerialized(agent) {
@@ -577,7 +525,7 @@ function fromSerialized(entry) {
577
525
 
578
526
  // src/internal/runtime/registry/agent-registry.ts
579
527
  var agents = /* @__PURE__ */ new Map();
580
- var hydratedCwds = /* @__PURE__ */ new Set();
528
+ var hydrations = /* @__PURE__ */ new Map();
581
529
  var pendingSaves = /* @__PURE__ */ new Map();
582
530
  var dirtyCwds = /* @__PURE__ */ new Set();
583
531
  function resolveRegistryCwd(agent) {
@@ -605,7 +553,7 @@ function scheduleSaveForCwd(cwd) {
605
553
  }
606
554
  } catch (cause) {
607
555
  const msg = cause instanceof Error ? cause.message : String(cause);
608
- process.stderr.write(`[theokit-sdk] registry persist failed (${cwd}): ${msg}
556
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] registry persist failed (${cwd}): ${msg}
609
557
  `);
610
558
  } finally {
611
559
  pendingSaves.delete(cwd);
@@ -621,10 +569,11 @@ function registerAgent(agent) {
621
569
  function getRegisteredAgent(agentId) {
622
570
  return agents.get(agentId);
623
571
  }
624
- function listRegisteredAgents(runtime) {
625
- const all = Array.from(agents.values());
626
- if (runtime === void 0) return all;
627
- return all.filter((agent) => agent.runtime === runtime);
572
+ function listRegisteredAgents(runtime, cwd) {
573
+ let out = Array.from(agents.values());
574
+ if (runtime !== void 0) out = out.filter((agent) => agent.runtime === runtime);
575
+ if (cwd !== void 0) out = out.filter((agent) => resolveRegistryCwd(agent) === cwd);
576
+ return out;
628
577
  }
629
578
  function updateRegisteredAgent(agentId, update) {
630
579
  const existing = agents.get(agentId);
@@ -647,14 +596,21 @@ function removeRegisteredAgent(agentId) {
647
596
  return removed;
648
597
  }
649
598
  async function hydrateRegistryFromDisk(cwd) {
650
- if (hydratedCwds.has(cwd)) return;
651
- hydratedCwds.add(cwd);
652
- const persisted = await loadRegistry(cwd);
653
- for (const [id, entry] of Object.entries(persisted)) {
654
- if (!agents.has(id)) {
655
- agents.set(id, fromSerialized(entry));
599
+ const emAndamento = hydrations.get(cwd);
600
+ if (emAndamento !== void 0) return emAndamento;
601
+ const hidratacao = (async () => {
602
+ const persisted = await loadRegistry(cwd);
603
+ for (const [id, entry] of Object.entries(persisted)) {
604
+ if (!agents.has(id)) {
605
+ agents.set(id, fromSerialized(entry));
606
+ }
656
607
  }
657
- }
608
+ })().catch((cause) => {
609
+ hydrations.delete(cwd);
610
+ throw cause;
611
+ });
612
+ hydrations.set(cwd, hidratacao);
613
+ return hidratacao;
658
614
  }
659
615
  async function flushRegistrySaves(cwd) {
660
616
  if (cwd !== void 0) {
@@ -936,16 +892,14 @@ async function readLegacyFacts(jsonPath) {
936
892
  }
937
893
  async function writeMigratedFacts(cwd, jsonPath, facts) {
938
894
  try {
939
- for (const fact of facts) await chunkJLMXKTBX_cjs.appendFactToMarkdown(cwd, fact);
895
+ for (const fact of facts) await chunk2423XDPT_cjs.appendFactToMarkdown(cwd, fact);
940
896
  await promises.unlink(jsonPath).catch(() => void 0);
941
- process.stderr.write(
942
- `[theokit-sdk] migrated ${facts.length} fact(s) from ${jsonPath} to MEMORY.md
943
- `
944
- );
897
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] migrated ${facts.length} fact(s) from ${jsonPath} to MEMORY.md
898
+ `);
945
899
  return { migrated: true, factCount: facts.length };
946
900
  } catch (cause) {
947
901
  const message = cause instanceof Error ? cause.message : String(cause);
948
- process.stderr.write(`[theokit-sdk] memory migration failed (readonly fs?): ${message}
902
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] memory migration failed (readonly fs?): ${message}
949
903
  `);
950
904
  return { migrated: false, factCount: 0, reason: "readonly-fs" };
951
905
  }
@@ -955,12 +909,12 @@ async function migrateLegacyJson(cwd, config) {
955
909
  const key = `${cwd}::${config.namespace ?? "default"}::${config.scope ?? "agent"}::${config.userId ?? "default"}`;
956
910
  if (migrationRun.has(key)) return { migrated: false, factCount: 0, reason: "already-migrated" };
957
911
  migrationRun.add(key);
958
- const jsonPath = chunkJLMXKTBX_cjs.legacyMemoryJsonPath(cwd, config);
912
+ const jsonPath = chunk2423XDPT_cjs.legacyMemoryJsonPath(cwd, config);
959
913
  if (!await fileExists(jsonPath)) {
960
914
  return { migrated: false, factCount: 0, reason: "no-legacy-json" };
961
915
  }
962
- if (await fileExists(chunkJLMXKTBX_cjs.memoryMdPath(cwd))) {
963
- process.stderr.write(
916
+ if (await fileExists(chunk2423XDPT_cjs.memoryMdPath(cwd))) {
917
+ chunkLTCOPATU_cjs.diag(
964
918
  `[theokit-sdk] memory migration skipped: both MEMORY.md and legacy JSON exist at ${jsonPath}; leaving both intact
965
919
  `
966
920
  );
@@ -984,13 +938,13 @@ function extractMemoryFact(message) {
984
938
  async function readMemoryFacts(cwd, config) {
985
939
  if (!config.enabled) return [];
986
940
  await migrateLegacyJson(cwd, config);
987
- return chunkJLMXKTBX_cjs.readFacts(cwd, config);
941
+ return chunk2423XDPT_cjs.readFacts(cwd, config);
988
942
  }
989
943
  async function appendMemoryFact(cwd, config, fact) {
990
944
  if (!config.enabled) return;
991
945
  await migrateLegacyJson(cwd, config);
992
- const sanitized = { text: chunkBEURCLDV_cjs.redactSecrets(fact.text) };
993
- await chunkJLMXKTBX_cjs.appendFact(cwd, config, sanitized);
946
+ const sanitized = { text: chunkLTCOPATU_cjs.redactSecrets(fact.text) };
947
+ await chunk2423XDPT_cjs.appendFact(cwd, config, sanitized);
994
948
  }
995
949
 
996
950
  // src/internal/runtime/fixtures/fixture-scripts.ts
@@ -1338,7 +1292,7 @@ function redactScriptSecrets(script) {
1338
1292
  function redactEventSecrets(event) {
1339
1293
  const serialized = JSON.stringify(event);
1340
1294
  const localStripped = serialized.replace(FIXTURE_SENTINEL, "***");
1341
- const redacted = chunkBEURCLDV_cjs.redactSecrets(localStripped);
1295
+ const redacted = chunkLTCOPATU_cjs.redactSecrets(localStripped);
1342
1296
  if (redacted === serialized) return event;
1343
1297
  return JSON.parse(redacted);
1344
1298
  }
@@ -1404,6 +1358,37 @@ var FixtureRunBase = class {
1404
1358
  while (index < this.script.events.length) {
1405
1359
  yield this.script.events[index++];
1406
1360
  }
1361
+ yield* this.terminalErrorEvent();
1362
+ }
1363
+ /**
1364
+ * theokit#101 — quando o run termina em erro, `stream()` tem de DIZER.
1365
+ *
1366
+ * O erro sempre existiu: o loop o registra em `ctx.error` e `wait()` devolve
1367
+ * `status: 'error'` com a mensagem. Só o `stream()` não o mencionava — ele drena
1368
+ * `script.events` e para. Uma falha de provider (404 "No endpoints found", auth, timeout)
1369
+ * produzia um turno que parecia bem-sucedido e vazio, em TODA superfície que consome o
1370
+ * stream: HTTP web, MCP, stdio, TUI in-process.
1371
+ *
1372
+ * Erro silencioso é o pior tipo (Regra Inquebrável 8). E a assimetria era o que o tornava
1373
+ * difícil de diagnosticar: quem depurasse por `wait()` via o erro e não reproduziria o
1374
+ * relato de quem depurava pelo stream.
1375
+ *
1376
+ * Emite `SDKStatusMessage` com `status: "ERROR"` — o tipo JÁ EXISTE na união `SDKMessage`
1377
+ * e já é esperado por quem consome. Um tipo novo seria breaking para todo consumidor que
1378
+ * faz switch exaustivo; este é aditivo, e um consumidor que ignore `status` simplesmente
1379
+ * segue como antes — nunca pior que hoje.
1380
+ */
1381
+ *terminalErrorEvent() {
1382
+ if (this.status !== "error") return;
1383
+ const detail = this.script.errorDetail;
1384
+ yield {
1385
+ type: "status",
1386
+ agent_id: this.agentId,
1387
+ run_id: this.id,
1388
+ status: "ERROR",
1389
+ // Sem mensagem, o consumidor sabe QUE falhou e não O QUÊ — que é metade do defeito.
1390
+ ...detail?.message !== void 0 ? { message: detail.message } : {}
1391
+ };
1407
1392
  }
1408
1393
  wait() {
1409
1394
  return this.terminationPromise;
@@ -1580,7 +1565,7 @@ function createRealCloudRun(options) {
1580
1565
  conversation: []
1581
1566
  };
1582
1567
  const apiKey = resolveApiKey(options.agentOptions.apiKey);
1583
- const baseUrl = getConfiguredBaseUrl();
1568
+ const baseUrl = chunkALU3KC4G_cjs.getConfiguredBaseUrl();
1584
1569
  const handle = new RealCloudRun(
1585
1570
  {
1586
1571
  id,
@@ -1653,7 +1638,7 @@ var RealCloudRun = class extends FixtureRunBase {
1653
1638
  });
1654
1639
  if (!response.ok) {
1655
1640
  const text = await response.text().catch(() => "");
1656
- throw new chunkA44COQJJ_cjs.NetworkError(
1641
+ throw new chunkMHCKWQR3_cjs.NetworkError(
1657
1642
  `Cloud Run endpoint returned ${response.status}: ${text.slice(0, 200)}`,
1658
1643
  { code: "cloud_run_http_error" }
1659
1644
  );
@@ -1663,7 +1648,7 @@ var RealCloudRun = class extends FixtureRunBase {
1663
1648
  async consumeStream(response) {
1664
1649
  let finalStatus = "finished";
1665
1650
  let finalText = "";
1666
- for await (const record of chunkWEHUJ7ZS_cjs.parseSseStream(response.body, this.controller.signal)) {
1651
+ for await (const record of chunkALU3KC4G_cjs.parseSseStream(response.body, this.controller.signal)) {
1667
1652
  const parsed = safeParse(record.data);
1668
1653
  if (parsed === void 0) continue;
1669
1654
  const update = this.applyRecord(record.event, parsed);
@@ -1772,7 +1757,7 @@ var CloudAgent = class {
1772
1757
  */
1773
1758
  isFixtureMode() {
1774
1759
  const apiKey = resolveApiKey(this.options.apiKey);
1775
- return isFixtureApiKey(apiKey) && getConfiguredBaseUrl() === void 0;
1760
+ return chunkALU3KC4G_cjs.isFixtureApiKey(apiKey) && chunkALU3KC4G_cjs.getConfiguredBaseUrl() === void 0;
1776
1761
  }
1777
1762
  // SE9 — integrated structured output; delegates to the shared helper.
1778
1763
  generate(message, options) {
@@ -1787,7 +1772,7 @@ var CloudAgent = class {
1787
1772
  }
1788
1773
  async send(message, options = {}) {
1789
1774
  if (options.tools !== void 0 && options.tools.length > 0) {
1790
- throw new chunkA44COQJJ_cjs.ConfigurationError(
1775
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
1791
1776
  "Custom inline tools are local-only in SDK v1.0 \u2014 cloud agents cannot serialize handler functions",
1792
1777
  { code: "cloud_custom_tools_rejected" }
1793
1778
  );
@@ -1823,7 +1808,7 @@ var CloudAgent = class {
1823
1808
  const userText = typeof message === "string" ? message : message.text;
1824
1809
  const systemPrompt = await this.resolveSystemPromptForSend(userText, options);
1825
1810
  const apiKey = resolveApiKey(this.options.apiKey);
1826
- const useRealRuntime = apiKey !== void 0 && !isFixtureApiKey(apiKey) && getConfiguredBaseUrl() !== void 0;
1811
+ const useRealRuntime = apiKey !== void 0 && !chunkALU3KC4G_cjs.isFixtureApiKey(apiKey) && chunkALU3KC4G_cjs.getConfiguredBaseUrl() !== void 0;
1827
1812
  return useRealRuntime ? createRealCloudRun({
1828
1813
  agentId: this.agentId,
1829
1814
  model: this.model ?? { id: DEFAULT_AGENTIC_MODEL_ID },
@@ -1872,7 +1857,7 @@ var CloudAgent = class {
1872
1857
  listArtifacts() {
1873
1858
  if (!this.isFixtureMode()) {
1874
1859
  return Promise.reject(
1875
- new chunkA44COQJJ_cjs.ConfigurationError(
1860
+ new chunkMHCKWQR3_cjs.ConfigurationError(
1876
1861
  "Cloud runtime is pre-release. listArtifacts() will return real artifacts when Theo PaaS ships; today it is only available in fixture mode (theo_test_* keys).",
1877
1862
  { code: "cloud_runtime_pre_release" }
1878
1863
  )
@@ -1882,11 +1867,11 @@ var CloudAgent = class {
1882
1867
  }
1883
1868
  downloadArtifact(path) {
1884
1869
  try {
1885
- chunkKIO7QFIV_cjs.validateArtifactPath(path);
1870
+ chunkYBFDBOUN_cjs.validateArtifactPath(path);
1886
1871
  } catch (cause) {
1887
- if (cause instanceof chunkKIO7QFIV_cjs.PathTraversalError) {
1872
+ if (cause instanceof chunkYBFDBOUN_cjs.PathTraversalError) {
1888
1873
  return Promise.reject(
1889
- new chunkA44COQJJ_cjs.ConfigurationError(`Artifact path must stay inside the workspace: ${path}`, {
1874
+ new chunkMHCKWQR3_cjs.ConfigurationError(`Artifact path must stay inside the workspace: ${path}`, {
1890
1875
  code: "artifact_path_traversal",
1891
1876
  cause
1892
1877
  })
@@ -1896,7 +1881,7 @@ var CloudAgent = class {
1896
1881
  }
1897
1882
  if (!this.isFixtureMode()) {
1898
1883
  return Promise.reject(
1899
- new chunkA44COQJJ_cjs.ConfigurationError(
1884
+ new chunkMHCKWQR3_cjs.ConfigurationError(
1900
1885
  "Cloud runtime is pre-release. downloadArtifact() will fetch real PaaS artifacts when the cloud runtime ships; today it is only available in fixture mode (theo_test_* keys).",
1901
1886
  { code: "cloud_runtime_pre_release" }
1902
1887
  )
@@ -1905,7 +1890,7 @@ var CloudAgent = class {
1905
1890
  const match = buildFixtureArtifacts().find((artifact) => artifact.path === path);
1906
1891
  if (match === void 0) {
1907
1892
  return Promise.reject(
1908
- new chunkA44COQJJ_cjs.UnknownAgentError(`Artifact ${path} not found`, { code: "unknown_artifact" })
1893
+ new chunkMHCKWQR3_cjs.UnknownAgentError(`Artifact ${path} not found`, { code: "unknown_artifact" })
1909
1894
  );
1910
1895
  }
1911
1896
  return Promise.resolve(Buffer.from(`fixture artifact content for ${path}
@@ -1919,7 +1904,7 @@ var CloudAgent = class {
1919
1904
  * @public
1920
1905
  */
1921
1906
  runUntil() {
1922
- throw new chunkA44COQJJ_cjs.UnsupportedRunOperationError(
1907
+ throw new chunkMHCKWQR3_cjs.UnsupportedRunOperationError(
1923
1908
  "Agent.runUntil() is not supported on cloud agents. Cloud runtime manages goal loops server-side. Use a local agent for autonomous Ralph loops.",
1924
1909
  "runUntil"
1925
1910
  );
@@ -1930,7 +1915,7 @@ var CloudAgent = class {
1930
1915
  * @public
1931
1916
  */
1932
1917
  fork() {
1933
- throw new chunkA44COQJJ_cjs.UnsupportedRunOperationError(
1918
+ throw new chunkMHCKWQR3_cjs.UnsupportedRunOperationError(
1934
1919
  "Agent.fork() is not supported on cloud agents. Fork inheritance requires local credential + system-prompt access. Use a local agent.",
1935
1920
  "fork"
1936
1921
  );
@@ -1942,7 +1927,7 @@ var CloudAgent = class {
1942
1927
  * @public
1943
1928
  */
1944
1929
  runToCompletion() {
1945
- throw new chunkA44COQJJ_cjs.UnsupportedRunOperationError(
1930
+ throw new chunkMHCKWQR3_cjs.UnsupportedRunOperationError(
1946
1931
  "Agent.runToCompletion() is not supported on cloud agents. Cloud runtime manages continuation server-side. Use a local agent.",
1947
1932
  "runToCompletion"
1948
1933
  );
@@ -1954,7 +1939,7 @@ var CloudAgent = class {
1954
1939
  * @public
1955
1940
  */
1956
1941
  streamToCompletion() {
1957
- throw new chunkA44COQJJ_cjs.UnsupportedRunOperationError(
1942
+ throw new chunkMHCKWQR3_cjs.UnsupportedRunOperationError(
1958
1943
  "Agent.streamToCompletion() is not supported on cloud agents. Cloud runtime manages continuation server-side. Use a local agent.",
1959
1944
  "streamToCompletion"
1960
1945
  );
@@ -1968,7 +1953,7 @@ var CloudAgent = class {
1968
1953
  */
1969
1954
  usePersonality() {
1970
1955
  return Promise.reject(
1971
- new chunkA44COQJJ_cjs.UnsupportedRunOperationError(
1956
+ new chunkMHCKWQR3_cjs.UnsupportedRunOperationError(
1972
1957
  "Agent.usePersonality() is not supported on cloud agents (pre-release). Use a local agent or wait for cloud GA.",
1973
1958
  "usePersonality"
1974
1959
  )
@@ -1996,7 +1981,7 @@ function validateCloudToolParity(options) {
1996
1981
  function rejectProcessors(options) {
1997
1982
  const hasProcessors = (options.inputProcessors?.length ?? 0) > 0 || (options.outputProcessors?.length ?? 0) > 0;
1998
1983
  if (hasProcessors) {
1999
- throw new chunkA44COQJJ_cjs.ConfigurationError(
1984
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
2000
1985
  "Cloud agents can't run guardrail processors \u2014 a Processor carries function handlers that don't survive serialization to PaaS. Run processors on a local agent, or move the guardrail into a server-side gateway in front of TheoCloud.",
2001
1986
  { code: "cloud_incompatible_function_resolver" }
2002
1987
  );
@@ -2004,7 +1989,7 @@ function rejectProcessors(options) {
2004
1989
  }
2005
1990
  function rejectFunctionSystemPrompt(options) {
2006
1991
  if (typeof options.systemPrompt === "function") {
2007
- throw new chunkA44COQJJ_cjs.ConfigurationError(
1992
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
2008
1993
  "Cloud agents require systemPrompt as a serializable string. SystemPromptResolver functions can't run on PaaS \u2014 resolve to a string before Agent.create() or move the dynamic logic into a hook rule.",
2009
1994
  { code: "cloud_incompatible_function_resolver" }
2010
1995
  );
@@ -2012,7 +1997,7 @@ function rejectFunctionSystemPrompt(options) {
2012
1997
  }
2013
1998
  function rejectFunctionSkills(options) {
2014
1999
  if (typeof options.skills === "function") {
2015
- throw new chunkA44COQJJ_cjs.ConfigurationError(
2000
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
2016
2001
  "Cloud agents require skills as a static settings object. SkillsResolver functions can't run on PaaS \u2014 resolve to a SkillsSettings object before Agent.create() or move the dynamic logic into a hook rule.",
2017
2002
  { code: "cloud_incompatible_function_resolver" }
2018
2003
  );
@@ -2024,7 +2009,7 @@ function rejectStdioMcpLocalPaths(options) {
2024
2009
  if (!isStdioCommandConfig(config)) continue;
2025
2010
  const command = config.command ?? "";
2026
2011
  if (isLocalPath(command)) {
2027
- throw new chunkA44COQJJ_cjs.ConfigurationError(
2012
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
2028
2013
  `MCP server "${name}" uses a local-FS command path (${command}). Cloud agents can't reach local binaries \u2014 use a bare command (npx, uvx, node, \u2026) that the PaaS VM image provides, or switch to an HTTP MCP server.`,
2029
2014
  { code: "cloud_incompatible_mcp_stdio_local" }
2030
2015
  );
@@ -2039,96 +2024,6 @@ function isStdioCommandConfig(config) {
2039
2024
  function isLocalPath(command) {
2040
2025
  return command.startsWith("/") || command.startsWith("~/") || command.startsWith("./") || command.startsWith("../");
2041
2026
  }
2042
-
2043
- // src/internal/http.ts
2044
- var DEFAULT_BASE_URL = "https://api.usetheo.dev";
2045
- function resolveBaseUrl() {
2046
- return getConfiguredBaseUrl() ?? DEFAULT_BASE_URL;
2047
- }
2048
- async function httpRequest(path, options) {
2049
- const url = `${resolveBaseUrl()}${path}`;
2050
- const fetchFn = options.fetchFn ?? globalThis.fetch;
2051
- const headers = {
2052
- "content-type": "application/json",
2053
- authorization: `Bearer ${options.apiKey}`,
2054
- ...options.headers ?? {}
2055
- };
2056
- const body = options.body !== void 0 ? JSON.stringify(options.body) : void 0;
2057
- const response = await safeFetch(fetchFn, url, {
2058
- method: options.method ?? "GET",
2059
- headers,
2060
- body
2061
- });
2062
- if (!response.ok) {
2063
- const parsed = await safeParseJsonResponse(response);
2064
- throw mapHttpStatusToError(response.status, parsed);
2065
- }
2066
- return await safeParseJsonResponse(response);
2067
- }
2068
- async function safeFetch(fetchFn, url, init) {
2069
- try {
2070
- return await fetchFn(url, init);
2071
- } catch (cause) {
2072
- throw new chunkA44COQJJ_cjs.NetworkError("HTTP request failed", { code: "network_error", cause });
2073
- }
2074
- }
2075
- async function safeParseJsonResponse(response) {
2076
- try {
2077
- return await response.json();
2078
- } catch {
2079
- return void 0;
2080
- }
2081
- }
2082
- function mapHttpStatusToError(status, body) {
2083
- const envelope = extractErrorEnvelope(body);
2084
- const message = envelope.message ?? `HTTP ${status}`;
2085
- const errorOptions = {
2086
- code: envelope.code,
2087
- protoErrorCode: envelope.protoErrorCode,
2088
- cause: body
2089
- };
2090
- if (envelope.code === "integration_not_connected") {
2091
- return new chunkA44COQJJ_cjs.IntegrationNotConnectedError(message, {
2092
- provider: envelope.provider ?? "unknown",
2093
- helpUrl: envelope.helpUrl ?? "",
2094
- code: envelope.code,
2095
- cause: body
2096
- });
2097
- }
2098
- if (status === 401 || status === 403) {
2099
- return new chunkA44COQJJ_cjs.AuthenticationError(message, errorOptions);
2100
- }
2101
- if (status === 429) {
2102
- return new chunkA44COQJJ_cjs.RateLimitError(message, errorOptions);
2103
- }
2104
- if (status >= 400 && status < 500) {
2105
- return new chunkA44COQJJ_cjs.ConfigurationError(message, errorOptions);
2106
- }
2107
- if (status >= 500) {
2108
- return new chunkA44COQJJ_cjs.NetworkError(message, errorOptions);
2109
- }
2110
- return new chunkA44COQJJ_cjs.UnknownAgentError(message, errorOptions);
2111
- }
2112
- function extractErrorEnvelope(body) {
2113
- if (!body || typeof body !== "object") return {};
2114
- const record = body;
2115
- const inner = record.error;
2116
- const source = inner && typeof inner === "object" ? inner : record;
2117
- return readEnvelopeFields(source);
2118
- }
2119
- function readEnvelopeFields(record) {
2120
- return {
2121
- code: pickString(record, "code"),
2122
- message: pickString(record, "message"),
2123
- protoErrorCode: pickString(record, "protoErrorCode"),
2124
- provider: pickString(record, "provider"),
2125
- helpUrl: pickString(record, "helpUrl")
2126
- };
2127
- }
2128
- function pickString(record, key) {
2129
- const value = record[key];
2130
- return typeof value === "string" ? value : void 0;
2131
- }
2132
2027
  var SCHEMA_VERSION2 = 1;
2133
2028
  var FILE_NAME = "personality.json";
2134
2029
  function emptyState() {
@@ -2154,14 +2049,14 @@ async function readState(filePath) {
2154
2049
  try {
2155
2050
  parsed = JSON.parse(raw);
2156
2051
  } catch {
2157
- chunkN24XBYNX_cjs.warnOnce(
2052
+ chunkFAY3QDGC_cjs.warnOnce(
2158
2053
  "personality-store-json-parse",
2159
2054
  "[theokit-sdk] personality.json is malformed; treating as empty"
2160
2055
  );
2161
2056
  return emptyState();
2162
2057
  }
2163
2058
  if (!isStateV1(parsed)) {
2164
- chunkN24XBYNX_cjs.warnOnce(
2059
+ chunkFAY3QDGC_cjs.warnOnce(
2165
2060
  "personality-store-bad-version",
2166
2061
  `[theokit-sdk] personality.json has unknown version; treating as empty (file kept untouched)`
2167
2062
  );
@@ -2192,9 +2087,9 @@ var PersonalityStore = class {
2192
2087
  try {
2193
2088
  await this.#persist(agentId, slug);
2194
2089
  } catch (err) {
2195
- chunkN24XBYNX_cjs.warnOnce(
2090
+ chunkFAY3QDGC_cjs.warnOnce(
2196
2091
  `personality-store-persist-failure-${agentId}`,
2197
- `[theokit-sdk] personality persist failed for ${chunkBEURCLDV_cjs.redactSecrets(agentId)}: ${chunkBEURCLDV_cjs.redactSecrets(
2092
+ `[theokit-sdk] personality persist failed for ${chunkLTCOPATU_cjs.redactSecrets(agentId)}: ${chunkLTCOPATU_cjs.redactSecrets(
2198
2093
  err.message
2199
2094
  )}`
2200
2095
  );
@@ -2209,9 +2104,9 @@ var PersonalityStore = class {
2209
2104
  try {
2210
2105
  state = await readState(filePath);
2211
2106
  } catch (err) {
2212
- chunkN24XBYNX_cjs.warnOnce(
2107
+ chunkFAY3QDGC_cjs.warnOnce(
2213
2108
  `personality-store-hydrate-failure-${agentId}`,
2214
- `[theokit-sdk] personality hydrate failed for ${chunkBEURCLDV_cjs.redactSecrets(agentId)}: ${chunkBEURCLDV_cjs.redactSecrets(
2109
+ `[theokit-sdk] personality hydrate failed for ${chunkLTCOPATU_cjs.redactSecrets(agentId)}: ${chunkLTCOPATU_cjs.redactSecrets(
2215
2110
  err.message
2216
2111
  )}`
2217
2112
  );
@@ -2228,17 +2123,17 @@ var PersonalityStore = class {
2228
2123
  async #persist(agentId, slug) {
2229
2124
  const filePath = this.#filePath();
2230
2125
  await promises.mkdir(path.dirname(filePath), { recursive: true });
2231
- await chunkCJVMDRQB_cjs.withFileLock(filePath, async () => {
2126
+ await chunkTQI3KRXZ_cjs.withFileLock(filePath, async () => {
2232
2127
  const current = await readState(filePath);
2233
2128
  const nextAgents = { ...current.agents };
2234
2129
  if (slug === void 0) delete nextAgents[agentId];
2235
2130
  else nextAgents[agentId] = slug;
2236
2131
  const next = { version: SCHEMA_VERSION2, agents: nextAgents };
2237
- await chunkTIZ4TS5V_cjs.atomicWriteJson(filePath, next);
2132
+ await chunkICYBIC6N_cjs.atomicWriteJson(filePath, next);
2238
2133
  });
2239
2134
  }
2240
2135
  #filePath() {
2241
- return path.join(chunk6M6A6WWW_cjs.getTheokitHome(this.#cwd), FILE_NAME);
2136
+ return path.join(chunkD4ZUJTFB_cjs.getTheokitHome(this.#cwd), FILE_NAME);
2242
2137
  }
2243
2138
  };
2244
2139
 
@@ -2261,7 +2156,7 @@ function createPluginContext() {
2261
2156
  },
2262
2157
  on(hook, handler) {
2263
2158
  if (typeof handler !== "function") {
2264
- process.stderr.write(`[theokit-sdk] ignoring non-function handler for hook "${hook}"
2159
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] ignoring non-function handler for hook "${hook}"
2265
2160
  `);
2266
2161
  return;
2267
2162
  }
@@ -2314,7 +2209,7 @@ var PluginManager = class {
2314
2209
  const seen = /* @__PURE__ */ new Set();
2315
2210
  for (const plugin of plugins) {
2316
2211
  if (seen.has(plugin.name)) {
2317
- process.stderr.write(
2212
+ chunkLTCOPATU_cjs.diag(
2318
2213
  `[theokit-sdk] duplicate plugin name "${plugin.name}" \u2014 both will register independently
2319
2214
  `
2320
2215
  );
@@ -2341,7 +2236,7 @@ var PluginManager = class {
2341
2236
  */
2342
2237
  async register(plugin) {
2343
2238
  if (plugin.kind !== "general") {
2344
- throw new chunkA44COQJJ_cjs.ConfigurationError(
2239
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
2345
2240
  `late register supports general plugins only (got "${plugin.kind}" for "${plugin.name}")`,
2346
2241
  { code: "plugin_late_register_kind" }
2347
2242
  );
@@ -2398,7 +2293,7 @@ var PluginManager = class {
2398
2293
  parts.push(result.recalledContext);
2399
2294
  }
2400
2295
  } catch (err) {
2401
- process.stderr.write(
2296
+ chunkLTCOPATU_cjs.diag(
2402
2297
  `[theokit-sdk] pre_user_send hook failed: ${err instanceof Error ? err.message : String(err)}
2403
2298
  `
2404
2299
  );
@@ -2426,7 +2321,7 @@ var PluginManager = class {
2426
2321
  try {
2427
2322
  await h(ctx);
2428
2323
  } catch (err) {
2429
- process.stderr.write(
2324
+ chunkLTCOPATU_cjs.diag(
2430
2325
  `[theokit-sdk] post_assistant_reply hook failed: ${err instanceof Error ? err.message : String(err)}
2431
2326
  `
2432
2327
  );
@@ -2442,7 +2337,7 @@ var PluginManager = class {
2442
2337
  try {
2443
2338
  await h(ctx);
2444
2339
  } catch (err) {
2445
- process.stderr.write(
2340
+ chunkLTCOPATU_cjs.diag(
2446
2341
  `[theokit-sdk] ${name} hook failed: ${err instanceof Error ? err.message : String(err)}
2447
2342
  `
2448
2343
  );
@@ -2457,7 +2352,7 @@ var PluginManager = class {
2457
2352
  const out = await h(current, ctx);
2458
2353
  if (out !== void 0) current = out;
2459
2354
  } catch (err) {
2460
- process.stderr.write(
2355
+ chunkLTCOPATU_cjs.diag(
2461
2356
  `[theokit-sdk] ${name} hook failed: ${err instanceof Error ? err.message : String(err)}
2462
2357
  `
2463
2358
  );
@@ -2599,7 +2494,7 @@ var HooksExecutor = class {
2599
2494
  this.config = {};
2600
2495
  return;
2601
2496
  }
2602
- this.config = await chunkN24XBYNX_cjs.loadHookConfig(this.cwd);
2497
+ this.config = await chunkFAY3QDGC_cjs.loadHookConfig(this.cwd);
2603
2498
  }
2604
2499
  /** Fire every hook registered for `event` and aggregate the decisions. */
2605
2500
  async run(payload) {
@@ -2705,11 +2600,11 @@ function buildContextBudgetEvent(model, resolved) {
2705
2600
  // src/internal/runtime/lifecycle/post-run-lifecycle.ts
2706
2601
  function resolveWindowForRun(model, contextWindow) {
2707
2602
  const override = contextWindow !== void 0 && contextWindow > 0 ? contextWindow : void 0;
2708
- return chunkM2PU44HP_cjs.resolveEffectiveContextWindow({
2603
+ return chunk4YB7B3RP_cjs.resolveEffectiveContextWindow({
2709
2604
  ...override !== void 0 ? { override } : {},
2710
- catalog: chunkD42XHI4O_cjs.getCatalogModelInfo(model)?.limit?.context,
2711
- margin: chunkM2PU44HP_cjs.CONTEXT_WINDOW_MARGIN,
2712
- floor: chunkM2PU44HP_cjs.CONTEXT_WINDOW_FLOOR
2605
+ catalog: chunk56ZM6P7Z_cjs.getCatalogModelInfo(model)?.limit?.context,
2606
+ margin: chunk4YB7B3RP_cjs.CONTEXT_WINDOW_MARGIN,
2607
+ floor: chunk4YB7B3RP_cjs.CONTEXT_WINDOW_FLOOR
2713
2608
  });
2714
2609
  }
2715
2610
  async function runPostRunLifecycle(inputs) {
@@ -2733,32 +2628,32 @@ async function runPostRunLifecycle(inputs) {
2733
2628
  try {
2734
2629
  const parcial = await safeConversation(run);
2735
2630
  if (parcial !== void 0) {
2736
- chunkG4WI3VW2_cjs.persistTurnToTranscript(sessionStore, { cwd: workspaceCwd, agentId, model }, agentId, {
2631
+ chunkH5YVJB4K_cjs.persistTurnToTranscript(sessionStore, { cwd: workspaceCwd, agentId, model }, agentId, {
2737
2632
  userText,
2738
2633
  conversation: parcial
2739
2634
  });
2740
2635
  }
2741
2636
  } catch (cause) {
2742
2637
  const msg = cause instanceof Error ? cause.message : String(cause);
2743
- process.stderr.write(`[theokit-sdk] partial transcript write failed (${agentId}): ${msg}
2638
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] partial transcript write failed (${agentId}): ${msg}
2744
2639
  `);
2745
2640
  }
2746
- await chunkG4WI3VW2_cjs.flushSessionWrites();
2641
+ await chunkH5YVJB4K_cjs.flushSessionWrites();
2747
2642
  return;
2748
2643
  }
2749
2644
  if (result.result !== void 0) {
2750
- chunkG4WI3VW2_cjs.appendSessionMessage(agentId, { role: "assistant", text: result.result });
2645
+ chunkH5YVJB4K_cjs.appendSessionMessage(agentId, { role: "assistant", text: result.result });
2751
2646
  }
2752
2647
  const conversation = await safeConversation(run);
2753
2648
  const resolvedWindow = resolveWindowForRun(model, contextWindow);
2754
2649
  const janelaEfetiva = resolvedWindow.window;
2755
2650
  const budgetEvent = buildContextBudgetEvent(model, resolvedWindow);
2756
2651
  if (budgetEvent !== void 0 && onRunEvent !== void 0) {
2757
- chunkMZ5ZRORA_cjs.emitRunEvent(onRunEvent, budgetEvent);
2652
+ chunk6EDQBX7U_cjs.emitRunEvent(onRunEvent, budgetEvent);
2758
2653
  }
2759
2654
  const lastRequestUsage = result.usage?.requests?.at(-1)?.totalTokens;
2760
2655
  const usageForTrigger = lastRequestUsage ?? result.usage?.totalTokens;
2761
- chunkG4WI3VW2_cjs.persistTurnToTranscript(
2656
+ chunkH5YVJB4K_cjs.persistTurnToTranscript(
2762
2657
  sessionStore,
2763
2658
  { cwd: workspaceCwd, agentId, model },
2764
2659
  agentId,
@@ -2770,13 +2665,13 @@ async function runPostRunLifecycle(inputs) {
2770
2665
  // A janela EFETIVA (após override, clamp e margem) — não a declarada. Trocar por
2771
2666
  // `contextWindow` aqui orçaria contra um número que o clamp já rejeitou.
2772
2667
  contextWindow: janelaEfetiva,
2773
- summarize: chunkWEHUJ7ZS_cjs.buildDefaultSummarizer({
2668
+ summarize: chunkALU3KC4G_cjs.buildDefaultSummarizer({
2774
2669
  agentModel: model,
2775
2670
  ...inputs.apiKey !== void 0 ? { apiKey: inputs.apiKey } : {}
2776
2671
  })
2777
2672
  }
2778
2673
  },
2779
- onRunEvent !== void 0 ? () => chunkMZ5ZRORA_cjs.emitRunEvent(onRunEvent, { type: "compact_boundary", trigger: "auto" }) : void 0
2674
+ onRunEvent !== void 0 ? () => chunk6EDQBX7U_cjs.emitRunEvent(onRunEvent, { type: "compact_boundary", trigger: "auto" }) : void 0
2780
2675
  );
2781
2676
  if (result.status === "finished" && result.result !== void 0) {
2782
2677
  const summaryArgs = {
@@ -2792,17 +2687,15 @@ async function runPostRunLifecycle(inputs) {
2792
2687
  if (memoryProvider?.recordSessionSummary !== void 0) {
2793
2688
  await memoryProvider.recordSessionSummary(summaryArgs);
2794
2689
  } else {
2795
- await chunkJLMXKTBX_cjs.writeSessionSummary(summaryArgs);
2690
+ await chunk2423XDPT_cjs.writeSessionSummary(summaryArgs);
2796
2691
  }
2797
2692
  if (!shouldUsePortMemoryPath()) {
2798
2693
  void memoryGlue.syncIfReady();
2799
2694
  }
2800
2695
  } catch (cause) {
2801
2696
  const message = cause instanceof Error ? cause.message : String(cause);
2802
- process.stderr.write(
2803
- `[theokit-sdk] session summary write failed (${result.id}): ${message}
2804
- `
2805
- );
2697
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] session summary write failed (${result.id}): ${message}
2698
+ `);
2806
2699
  }
2807
2700
  }
2808
2701
  await hooksExecutor.run({
@@ -2814,7 +2707,7 @@ async function runPostRunLifecycle(inputs) {
2814
2707
  agentId,
2815
2708
  runId: result.id
2816
2709
  });
2817
- await chunkG4WI3VW2_cjs.flushSessionWrites();
2710
+ await chunkH5YVJB4K_cjs.flushSessionWrites();
2818
2711
  }
2819
2712
  async function safeConversation(run) {
2820
2713
  try {
@@ -2824,174 +2717,6 @@ async function safeConversation(run) {
2824
2717
  }
2825
2718
  }
2826
2719
 
2827
- // src/internal/runtime/registry/live-agent-registry.ts
2828
- var DEFAULT_MAX_AGENTS = 100;
2829
- var DEFAULT_IDLE_TIMEOUT_MS = 30 * 60 * 1e3;
2830
- var DEFAULT_SWEEP_INTERVAL_MS = 6e4;
2831
- var LiveAgentRegistry = class {
2832
- #agents = /* @__PURE__ */ new Map();
2833
- #maxAgents = DEFAULT_MAX_AGENTS;
2834
- #idleTimeoutMs = DEFAULT_IDLE_TIMEOUT_MS;
2835
- #sweepIntervalMs = DEFAULT_SWEEP_INTERVAL_MS;
2836
- #onEvict;
2837
- #sweepTimer;
2838
- /**
2839
- * Reconfigure registry behavior. Process-wide singleton (D310) — last
2840
- * configure call wins for all subsequent operations.
2841
- */
2842
- configure(opts) {
2843
- if (opts.maxAgents !== void 0) this.#maxAgents = Math.max(0, opts.maxAgents);
2844
- if (opts.idleTimeoutMs !== void 0) this.#idleTimeoutMs = Math.max(0, opts.idleTimeoutMs);
2845
- if (opts.sweepIntervalMs !== void 0)
2846
- this.#sweepIntervalMs = Math.max(1e3, opts.sweepIntervalMs);
2847
- this.#onEvict = opts.onEvict;
2848
- this.#stopSweep();
2849
- if (this.#idleTimeoutMs > 0) this.#startSweep();
2850
- }
2851
- /**
2852
- * Lookup a cached agent. `get` is a use — refreshes `lastUsedAt` so the
2853
- * entry survives LRU eviction.
2854
- */
2855
- get(id) {
2856
- const entry = this.#agents.get(id);
2857
- if (entry === void 0) return void 0;
2858
- entry.lastUsedAt = Date.now();
2859
- return entry.agent;
2860
- }
2861
- /**
2862
- * Insert or overwrite an agent in the cache. Triggers fire-and-forget LRU
2863
- * eviction when `size > maxAgents`.
2864
- *
2865
- * EC-4: when `id` already maps to a DIFFERENT agent instance, dispose the
2866
- * old one before overwriting (race protection against two `getOrCreate`
2867
- * calls creating two agents but only the second being cached — the first
2868
- * would leak file handles + lifecycle controllers).
2869
- */
2870
- set(id, agent) {
2871
- if (this.#maxAgents === 0) return;
2872
- const existing = this.#agents.get(id);
2873
- if (existing !== void 0 && existing.agent !== agent) {
2874
- void existing.agent.dispose().catch(() => {
2875
- process.stderr.write(`[theokit-sdk] dispose during overwrite failed (${id})
2876
- `);
2877
- });
2878
- }
2879
- this.#agents.set(id, { agent, lastUsedAt: Date.now() });
2880
- if (this.#agents.size > this.#maxAgents) void this.#evictLRU();
2881
- }
2882
- /**
2883
- * Remove the entry from the cache WITHOUT calling `dispose()` or
2884
- * `onEvict`. Used by `LocalAgent.dispose()` itself so the disposed
2885
- * instance can never be returned by a subsequent `get(id)` (dispose-cache
2886
- * race fix). Idempotent — calling on an unknown id is a no-op.
2887
- *
2888
- * @internal
2889
- */
2890
- forget(id) {
2891
- this.#agents.delete(id);
2892
- }
2893
- /**
2894
- * Explicitly evict an agent by id. Returns `true` when the entry was
2895
- * present (false = already gone). Calls `agent.dispose()` + `onEvict`
2896
- * with reason `"explicit"`.
2897
- */
2898
- async evict(id) {
2899
- const entry = this.#agents.get(id);
2900
- if (entry === void 0) return false;
2901
- this.#agents.delete(id);
2902
- await this.#disposeAndNotify(id, entry.agent, "explicit");
2903
- return true;
2904
- }
2905
- /**
2906
- * Evict every cached agent. Used by graceful shutdown (`process.on('SIGTERM')`)
2907
- * or end-of-test cleanup.
2908
- */
2909
- async evictAll() {
2910
- const entries = Array.from(this.#agents.entries());
2911
- this.#agents.clear();
2912
- this.#stopSweep();
2913
- for (const [id, entry] of entries) {
2914
- await this.#disposeAndNotify(id, entry.agent, "explicit");
2915
- }
2916
- }
2917
- /** Number of currently cached agents. */
2918
- size() {
2919
- return this.#agents.size;
2920
- }
2921
- /** Ids of cached agents, newest first (by lastUsedAt). */
2922
- ids() {
2923
- return Array.from(this.#agents.entries()).sort((a, b) => b[1].lastUsedAt - a[1].lastUsedAt).map(([id]) => id);
2924
- }
2925
- /**
2926
- * LRU eviction: drop the entry with the smallest `lastUsedAt`. Runs only
2927
- * when `size > maxAgents`. Asynchronous because `dispose()` is a Promise;
2928
- * the hot-path caller (`set`) does not await.
2929
- *
2930
- * @internal
2931
- */
2932
- async #evictLRU() {
2933
- if (this.#agents.size <= this.#maxAgents) return;
2934
- let oldestId;
2935
- let oldestAt = Infinity;
2936
- for (const [id, entry2] of this.#agents) {
2937
- if (entry2.lastUsedAt < oldestAt) {
2938
- oldestAt = entry2.lastUsedAt;
2939
- oldestId = id;
2940
- }
2941
- }
2942
- if (oldestId === void 0) return;
2943
- const entry = this.#agents.get(oldestId);
2944
- if (entry === void 0) return;
2945
- this.#agents.delete(oldestId);
2946
- await this.#disposeAndNotify(oldestId, entry.agent, "lru");
2947
- }
2948
- /** Background sweep — drops entries whose `lastUsedAt < now - idleTimeoutMs`. */
2949
- async #sweepIdle() {
2950
- if (this.#idleTimeoutMs === 0) return;
2951
- const threshold = Date.now() - this.#idleTimeoutMs;
2952
- const toEvict = [];
2953
- for (const [id, entry] of this.#agents) {
2954
- if (entry.lastUsedAt < threshold) toEvict.push([id, entry]);
2955
- }
2956
- for (const [id, entry] of toEvict) {
2957
- const current = this.#agents.get(id);
2958
- if (current === void 0 || current.agent !== entry.agent) continue;
2959
- this.#agents.delete(id);
2960
- await this.#disposeAndNotify(id, entry.agent, "idle");
2961
- }
2962
- }
2963
- #startSweep() {
2964
- this.#sweepTimer = setInterval(() => void this.#sweepIdle(), this.#sweepIntervalMs);
2965
- this.#sweepTimer.unref?.();
2966
- }
2967
- #stopSweep() {
2968
- if (this.#sweepTimer !== void 0) {
2969
- clearInterval(this.#sweepTimer);
2970
- this.#sweepTimer = void 0;
2971
- }
2972
- }
2973
- /** Dispose + notify with errors swallowed (D309). Single chokepoint. */
2974
- async #disposeAndNotify(id, agent, reason) {
2975
- try {
2976
- await agent.dispose();
2977
- } catch (cause) {
2978
- const msg = cause instanceof Error ? cause.message : String(cause);
2979
- process.stderr.write(`[theokit-sdk] dispose during eviction failed (${id}): ${msg}
2980
- `);
2981
- }
2982
- if (this.#onEvict !== void 0) {
2983
- try {
2984
- this.#onEvict(id, reason);
2985
- } catch (cause) {
2986
- const msg = cause instanceof Error ? cause.message : String(cause);
2987
- process.stderr.write(`[theokit-sdk] onEvict listener threw (${id}): ${msg}
2988
- `);
2989
- }
2990
- }
2991
- }
2992
- };
2993
- var liveAgentRegistry = new LiveAgentRegistry();
2994
-
2995
2720
  // src/define-tool.ts
2996
2721
  var TOOL_SPLIT_RESOLVER = /* @__PURE__ */ Symbol("theokit.toolSplitResolver");
2997
2722
  async function runValidated(spec, input, ctx) {
@@ -3057,7 +2782,7 @@ var warned = /* @__PURE__ */ new Set();
3057
2782
  function warnDoubleReasoningOnce() {
3058
2783
  if (warned.has("double-reasoning")) return;
3059
2784
  warned.add("double-reasoning");
3060
- process.stderr.write(
2785
+ chunkLTCOPATU_cjs.diag(
3061
2786
  "[theokit-sdk] `reasoning: true` skipped \u2014 a native reasoning model is configured (model.params thinking/reasoning); native reasoning wins. Remove one to silence.\n"
3062
2787
  );
3063
2788
  }
@@ -3090,12 +2815,10 @@ var SkillsManager = class {
3090
2815
  }
3091
2816
  async refresh() {
3092
2817
  const skillsRoot = this.skillsDir ?? path.join(this.cwd, ".theokit", "skills");
3093
- const discovered = await chunkDHLZIMP6_cjs.discoverSkills(skillsRoot, {
2818
+ const discovered = await chunkQUFSDDNU_cjs.discoverSkills(skillsRoot, {
3094
2819
  onInvalidSkill: (info) => {
3095
- process.stderr.write(
3096
- `[theokit-sdk] skill ${info.name} skipped (${info.code}): ${info.message}
3097
- `
3098
- );
2820
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] skill ${info.name} skipped (${info.code}): ${info.message}
2821
+ `);
3099
2822
  }
3100
2823
  });
3101
2824
  this.skills = this.mergeInline(discovered);
@@ -3118,7 +2841,7 @@ var SkillsManager = class {
3118
2841
  async get(name) {
3119
2842
  const skill = this.skills.find((s) => s.name === name);
3120
2843
  if (skill === void 0) return void 0;
3121
- const instructions = typeof skill.instructions === "string" ? skill.instructions : chunkDHLZIMP6_cjs.stripSkillFrontmatter(await promises.readFile(skill.source, "utf8"));
2844
+ const instructions = typeof skill.instructions === "string" ? skill.instructions : chunkQUFSDDNU_cjs.stripSkillFrontmatter(await promises.readFile(skill.source, "utf8"));
3122
2845
  const references = skill.references;
3123
2846
  return {
3124
2847
  name: skill.name,
@@ -3204,7 +2927,7 @@ async function safeCall(fn, fallback, label = "safeCall") {
3204
2927
  return await fn();
3205
2928
  } catch (cause) {
3206
2929
  const message = cause instanceof Error ? cause.message : String(cause);
3207
- process.stderr.write(`[theokit-sdk] ${label} failed: ${message}
2930
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] ${label} failed: ${message}
3208
2931
  `);
3209
2932
  return fallback;
3210
2933
  }
@@ -3218,7 +2941,7 @@ var ActiveMemoryPromptProvider = class {
3218
2941
  if (ctx.activeMemorySummary === void 0 || ctx.activeMemorySummary.length === 0) {
3219
2942
  return Promise.resolve(void 0);
3220
2943
  }
3221
- const body = chunkDHLZIMP6_cjs.escapeBlockBody(ctx.activeMemorySummary);
2944
+ const body = chunkQUFSDDNU_cjs.escapeBlockBody(ctx.activeMemorySummary);
3222
2945
  return Promise.resolve(`<active-memory>
3223
2946
  ${body}
3224
2947
  </active-memory>`);
@@ -3271,7 +2994,7 @@ function formatSource(name, tokens) {
3271
2994
  if (tokens.length === 0) {
3272
2995
  return ` <source name="${escapeAttribute(name)}" />`;
3273
2996
  }
3274
- const body = chunkDHLZIMP6_cjs.escapeBlockBody(tokens.join(" "));
2997
+ const body = chunkQUFSDDNU_cjs.escapeBlockBody(tokens.join(" "));
3275
2998
  return ` <source name="${escapeAttribute(name)}">
3276
2999
  ${body}
3277
3000
  </source>`;
@@ -3287,7 +3010,7 @@ var MemoryPromptProvider = class {
3287
3010
  contribute(ctx) {
3288
3011
  if (ctx.memoryAutoInject === false) return Promise.resolve(void 0);
3289
3012
  if (ctx.memory.length === 0) return Promise.resolve(void 0);
3290
- const lines = ctx.memory.map((fact) => ` - ${chunkDHLZIMP6_cjs.escapeBlockBody(fact.text)}`);
3013
+ const lines = ctx.memory.map((fact) => ` - ${chunkQUFSDDNU_cjs.escapeBlockBody(fact.text)}`);
3291
3014
  return Promise.resolve(`<memory>
3292
3015
  ${lines.join("\n")}
3293
3016
  </memory>`);
@@ -3309,7 +3032,7 @@ var SkillsPromptProvider = class {
3309
3032
  priority = 20;
3310
3033
  contribute(ctx) {
3311
3034
  if (ctx.skillsAutoInject === false) return Promise.resolve(void 0);
3312
- return Promise.resolve(chunkDHLZIMP6_cjs.buildSkillsBlock(ctx.skills));
3035
+ return Promise.resolve(chunkQUFSDDNU_cjs.buildSkillsBlock(ctx.skills));
3313
3036
  }
3314
3037
  };
3315
3038
 
@@ -3321,7 +3044,7 @@ var SystemPromptPipeline = class _SystemPromptPipeline {
3321
3044
  for (const p of providers) {
3322
3045
  const key = `${p.priority}:${p.id}`;
3323
3046
  if (seen.has(key)) {
3324
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Duplicate system-prompt provider ${key}`, {
3047
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Duplicate system-prompt provider ${key}`, {
3325
3048
  code: "pipeline_duplicate_provider"
3326
3049
  });
3327
3050
  }
@@ -3368,7 +3091,7 @@ function validateAgentOptions(options) {
3368
3091
  ensureRuntimeShape(options);
3369
3092
  if (options.local !== void 0) {
3370
3093
  if (options.model === void 0) {
3371
- throw new chunkA44COQJJ_cjs.ConfigurationError("Local agents require a model selection", {
3094
+ throw new chunkMHCKWQR3_cjs.ConfigurationError("Local agents require a model selection", {
3372
3095
  code: "missing_model"
3373
3096
  });
3374
3097
  }
@@ -3392,7 +3115,7 @@ function validateCredentialPoolShape(options) {
3392
3115
  ([, arr]) => Array.isArray(arr) && arr.some((k) => typeof k === "string" && k.length > 0)
3393
3116
  );
3394
3117
  if (populated.length === 0) return;
3395
- throw new chunkA44COQJJ_cjs.ConfigurationError(
3118
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
3396
3119
  "Ambiguous credential configuration: use either `apiKey: '...'` (single-key, simplest) OR `apiKeys: { provider: [...] }` (multi-key pool), not both.",
3397
3120
  { code: "credential_pool_ambiguous" }
3398
3121
  );
@@ -3401,7 +3124,7 @@ function validatePlugins(options) {
3401
3124
  const plugins = options.plugins;
3402
3125
  if (plugins?.paths === void 0) return;
3403
3126
  if (options.cloud !== void 0 && plugins.paths.length > 0) {
3404
- throw new chunkA44COQJJ_cjs.ConfigurationError(
3127
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
3405
3128
  "Cloud agents require committed plugin manifests; local plugin paths are not supported",
3406
3129
  { code: "cloud_plugin_path_rejected" }
3407
3130
  );
@@ -3409,7 +3132,7 @@ function validatePlugins(options) {
3409
3132
  }
3410
3133
  function ensureRuntimeShape(options) {
3411
3134
  if (options.local !== void 0 && options.cloud !== void 0) {
3412
- throw new chunkA44COQJJ_cjs.ConfigurationError(
3135
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
3413
3136
  "Pass either local or cloud \u2014 they are mutually exclusive runtimes",
3414
3137
  { code: "runtime_exclusive" }
3415
3138
  );
@@ -3417,7 +3140,7 @@ function ensureRuntimeShape(options) {
3417
3140
  }
3418
3141
  function rejectProgrammaticHooks(options) {
3419
3142
  if (options.hooks !== void 0) {
3420
- throw new chunkA44COQJJ_cjs.ConfigurationError(
3143
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
3421
3144
  "Programmatic hooks are not supported \u2014 hooks are file-based only (.theokit/hooks.json)",
3422
3145
  { code: "programmatic_hooks_rejected" }
3423
3146
  );
@@ -3427,7 +3150,7 @@ function validateCloud(cloud) {
3427
3150
  if (cloud.envVars !== void 0) {
3428
3151
  for (const key of Object.keys(cloud.envVars)) {
3429
3152
  if (key.startsWith("THEOKIT_")) {
3430
- throw new chunkA44COQJJ_cjs.ConfigurationError(
3153
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
3431
3154
  `Cloud envVars cannot use the reserved THEOKIT_ prefix (got "${key}")`,
3432
3155
  { code: "reserved_env_prefix" }
3433
3156
  );
@@ -3439,7 +3162,7 @@ function validateMcpServers(options) {
3439
3162
  if (options.mcpServers === void 0) return;
3440
3163
  for (const [name, config] of Object.entries(options.mcpServers)) {
3441
3164
  if (options.cloud !== void 0 && isStdioWithCwd(config)) {
3442
- throw new chunkA44COQJJ_cjs.ConfigurationError(
3165
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
3443
3166
  `MCP server "${name}" uses stdio with cwd, which is rejected for cloud agents`,
3444
3167
  { code: "cloud_stdio_cwd_rejected" }
3445
3168
  );
@@ -3458,12 +3181,12 @@ function validateSubagents(agents2) {
3458
3181
  if (agents2 === void 0) return;
3459
3182
  for (const [name, definition] of Object.entries(agents2)) {
3460
3183
  if (typeof definition.description !== "string" || definition.description.length === 0) {
3461
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Subagent "${name}" requires a non-empty description`, {
3184
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Subagent "${name}" requires a non-empty description`, {
3462
3185
  code: "subagent_missing_description"
3463
3186
  });
3464
3187
  }
3465
3188
  if (typeof definition.prompt !== "string" || definition.prompt.length === 0) {
3466
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Subagent "${name}" requires a non-empty prompt`, {
3189
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Subagent "${name}" requires a non-empty prompt`, {
3467
3190
  code: "subagent_missing_prompt"
3468
3191
  });
3469
3192
  }
@@ -3476,7 +3199,7 @@ function validateToolCatalog(tools) {
3476
3199
  for (const tool of tools) {
3477
3200
  validateSingleTool(tool);
3478
3201
  if (seen.has(tool.name)) {
3479
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Duplicate custom tool name "${tool.name}"`, {
3202
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Duplicate custom tool name "${tool.name}"`, {
3480
3203
  code: "duplicate_tool_name"
3481
3204
  });
3482
3205
  }
@@ -3487,7 +3210,7 @@ function validateCustomTools(options) {
3487
3210
  const tools = options.tools;
3488
3211
  if (tools === void 0 || tools.length === 0) return;
3489
3212
  if (options.cloud !== void 0) {
3490
- throw new chunkA44COQJJ_cjs.ConfigurationError(
3213
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
3491
3214
  "Custom inline tools are local-only in SDK v1.0 \u2014 cloud agents cannot serialize handler functions",
3492
3215
  { code: "cloud_custom_tools_rejected" }
3493
3216
  );
@@ -3499,25 +3222,25 @@ function validateSingleTool(tool) {
3499
3222
  validateToolDescription(tool);
3500
3223
  validateToolSchema(tool);
3501
3224
  if (typeof tool.handler !== "function") {
3502
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Custom tool "${tool.name}" requires a handler function`, {
3225
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Custom tool "${tool.name}" requires a handler function`, {
3503
3226
  code: "tool_missing_handler"
3504
3227
  });
3505
3228
  }
3506
3229
  }
3507
3230
  function validateToolName(tool) {
3508
3231
  if (typeof tool.name !== "string" || tool.name.length === 0) {
3509
- throw new chunkA44COQJJ_cjs.ConfigurationError("Custom tool requires a non-empty name", {
3232
+ throw new chunkMHCKWQR3_cjs.ConfigurationError("Custom tool requires a non-empty name", {
3510
3233
  code: "tool_missing_name"
3511
3234
  });
3512
3235
  }
3513
3236
  if (!TOOL_NAME_PATTERN.test(tool.name)) {
3514
- throw new chunkA44COQJJ_cjs.ConfigurationError(
3237
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
3515
3238
  `Custom tool name "${tool.name}" must match /^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/`,
3516
3239
  { code: "tool_invalid_name" }
3517
3240
  );
3518
3241
  }
3519
3242
  if (RESERVED_TOOL_NAMES.has(tool.name) || tool.name.startsWith("mcp_")) {
3520
- throw new chunkA44COQJJ_cjs.ConfigurationError(
3243
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
3521
3244
  `Custom tool name "${tool.name}" collides with a reserved SDK tool name`,
3522
3245
  { code: "tool_reserved_name" }
3523
3246
  );
@@ -3525,7 +3248,7 @@ function validateToolName(tool) {
3525
3248
  }
3526
3249
  function validateToolDescription(tool) {
3527
3250
  if (typeof tool.description !== "string" || tool.description.length === 0) {
3528
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Custom tool "${tool.name}" requires a non-empty description`, {
3251
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Custom tool "${tool.name}" requires a non-empty description`, {
3529
3252
  code: "tool_missing_description"
3530
3253
  });
3531
3254
  }
@@ -3533,12 +3256,12 @@ function validateToolDescription(tool) {
3533
3256
  function validateToolSchema(tool) {
3534
3257
  const schema = tool.inputSchema;
3535
3258
  if (schema === null || schema === void 0 || typeof schema !== "object") {
3536
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Custom tool "${tool.name}" requires an inputSchema object`, {
3259
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Custom tool "${tool.name}" requires an inputSchema object`, {
3537
3260
  code: "tool_missing_schema"
3538
3261
  });
3539
3262
  }
3540
3263
  if (schema.type !== "object") {
3541
- throw new chunkA44COQJJ_cjs.ConfigurationError(
3264
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
3542
3265
  `Custom tool "${tool.name}" inputSchema must declare \`type: "object"\``,
3543
3266
  { code: "tool_invalid_schema_type" }
3544
3267
  );
@@ -3549,7 +3272,7 @@ function validateMemory(options) {
3549
3272
  if (memory?.storePath === void 0) return;
3550
3273
  const storePath = memory.storePath;
3551
3274
  if (storePath.includes("..") || storePath.startsWith("/") || /^[A-Z]:/i.test(storePath)) {
3552
- throw new chunkA44COQJJ_cjs.ConfigurationError(
3275
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
3553
3276
  `Memory storePath must stay inside the workspace; got "${storePath}"`,
3554
3277
  { code: "memory_path_traversal" }
3555
3278
  );
@@ -3571,7 +3294,7 @@ var HISTOGRAM_NAMES = {
3571
3294
  };
3572
3295
  function safeRequire(moduleName) {
3573
3296
  try {
3574
- const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-3XJ7CS2C.cjs', document.baseURI).href)));
3297
+ const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-LMWXF4LL.cjs', document.baseURI).href)));
3575
3298
  return r(moduleName);
3576
3299
  } catch {
3577
3300
  return void 0;
@@ -3650,7 +3373,7 @@ var langfuseAdapter = {
3650
3373
  }
3651
3374
  }
3652
3375
  if (lf.LangfuseSpanProcessor === void 0) {
3653
- process.stderr.write(
3376
+ chunkLTCOPATU_cjs.diag(
3654
3377
  "[theokit-sdk] @langfuse/node detected but LangfuseSpanProcessor not found (v2?). Use Langfuse v3+ for auto-instrumentation.\n"
3655
3378
  );
3656
3379
  return;
@@ -3779,11 +3502,11 @@ function tryAutoRegisterAdapters(settings) {
3779
3502
  try {
3780
3503
  adapter.register();
3781
3504
  registered.add(adapter.moduleName);
3782
- process.stderr.write(`[theokit-sdk] telemetry: ${adapter.displayName} auto-instrumented.
3505
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] telemetry: ${adapter.displayName} auto-instrumented.
3783
3506
  `);
3784
3507
  } catch (cause) {
3785
3508
  const message = cause instanceof Error ? cause.message : String(cause);
3786
- process.stderr.write(
3509
+ chunkLTCOPATU_cjs.diag(
3787
3510
  `[theokit-sdk] telemetry: ${adapter.displayName} detected but failed to register: ${message}
3788
3511
  `
3789
3512
  );
@@ -3796,7 +3519,7 @@ var cachedOtel;
3796
3519
  function loadOtel() {
3797
3520
  if (cachedOtel === void 0) {
3798
3521
  try {
3799
- const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-3XJ7CS2C.cjs', document.baseURI).href)));
3522
+ const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-LMWXF4LL.cjs', document.baseURI).href)));
3800
3523
  const mod = r("@opentelemetry/api");
3801
3524
  cachedOtel = mod;
3802
3525
  } catch {
@@ -3839,7 +3562,7 @@ function safe(op, fallback) {
3839
3562
  if (!warnedOnce) {
3840
3563
  warnedOnce = true;
3841
3564
  const message = cause instanceof Error ? cause.message : String(cause);
3842
- process.stderr.write(
3565
+ chunkLTCOPATU_cjs.diag(
3843
3566
  `[theokit-sdk] telemetry exporter error (suppressed; agent.send continues): ${message}
3844
3567
  `
3845
3568
  );
@@ -3853,7 +3576,7 @@ function createTelemetry(settings) {
3853
3576
  if (otel === null) {
3854
3577
  if (!warnedOnce) {
3855
3578
  warnedOnce = true;
3856
- process.stderr.write(
3579
+ chunkLTCOPATU_cjs.diag(
3857
3580
  "[theokit-sdk] telemetry.enabled = true but `@opentelemetry/api` is not installed; telemetry is a no-op.\n"
3858
3581
  );
3859
3582
  }
@@ -3947,12 +3670,12 @@ function wrapSpan(span, openSpans) {
3947
3670
  }
3948
3671
  function redactAttrValue(value) {
3949
3672
  if (typeof value !== "string") return value;
3950
- return chunkBEURCLDV_cjs.redactSecrets(value);
3673
+ return chunkLTCOPATU_cjs.redactSecrets(value);
3951
3674
  }
3952
3675
  function redactAttrs(attrs) {
3953
3676
  const out = {};
3954
3677
  for (const [k, v] of Object.entries(attrs)) {
3955
- out[k] = typeof v === "string" ? chunkBEURCLDV_cjs.redactSecrets(v) : v;
3678
+ out[k] = typeof v === "string" ? chunkLTCOPATU_cjs.redactSecrets(v) : v;
3956
3679
  }
3957
3680
  return out;
3958
3681
  }
@@ -4034,10 +3757,10 @@ async function loadMarkdownEntities(opts) {
4034
3757
  const raw = await promises.readFile(resolved.source, "utf8").catch(() => null);
4035
3758
  if (raw === null) continue;
4036
3759
  const split = splitFrontmatter(raw, resolved.source, errorCodePrefix);
4037
- const fields = chunkLALRCFSN_cjs.parseSimpleYaml(split.frontmatter);
3760
+ const fields = chunk7DXLNNKH_cjs.parseSimpleYaml(split.frontmatter);
4038
3761
  const parsed = schema.safeParse(fields);
4039
3762
  if (!parsed.success) {
4040
- throw new chunkA44COQJJ_cjs.ConfigurationError(
3763
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
4041
3764
  `Invalid frontmatter in ${resolved.source}: ${parsed.error.message}`,
4042
3765
  { code: `${errorCodePrefix}_frontmatter_invalid` }
4043
3766
  );
@@ -4055,13 +3778,13 @@ async function assertFileSizeUnderCap(source, errorCodePrefix) {
4055
3778
  try {
4056
3779
  const info = await promises.stat(source);
4057
3780
  if (info.size > MAX_MD_FILE_BYTES) {
4058
- throw new chunkA44COQJJ_cjs.ConfigurationError(
3781
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
4059
3782
  `Config file ${source} exceeds 1 MB size limit (${info.size} bytes). Reduce the file or split into multiple entities.`,
4060
3783
  { code: `${errorCodePrefix}_file_too_large` }
4061
3784
  );
4062
3785
  }
4063
3786
  } catch (cause) {
4064
- if (cause instanceof chunkA44COQJJ_cjs.ConfigurationError) throw cause;
3787
+ if (cause instanceof chunkMHCKWQR3_cjs.ConfigurationError) throw cause;
4065
3788
  }
4066
3789
  }
4067
3790
  async function readDirSafe(dir, errorCodePrefix) {
@@ -4070,7 +3793,7 @@ async function readDirSafe(dir, errorCodePrefix) {
4070
3793
  } catch (cause) {
4071
3794
  const code = cause.code;
4072
3795
  if (code === "ENOENT") return null;
4073
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Failed to read ${dir}`, {
3796
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Failed to read ${dir}`, {
4074
3797
  code: `${errorCodePrefix}_dir_read_error`,
4075
3798
  cause
4076
3799
  });
@@ -4087,7 +3810,7 @@ function resolveEntryPath(entry, pattern, dir) {
4087
3810
  function splitFrontmatter(raw, source, errorCodePrefix) {
4088
3811
  const match = /^---\s*\n([\s\S]*?)\n---\s*(?:\n|$)/.exec(raw);
4089
3812
  if (match === null) {
4090
- throw new chunkA44COQJJ_cjs.ConfigurationError(
3813
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
4091
3814
  `Missing or malformed frontmatter in ${source} (expected \`---\` delimited block at file head)`,
4092
3815
  { code: `${errorCodePrefix}_missing_frontmatter` }
4093
3816
  );
@@ -4571,7 +4294,7 @@ async function loadContextConfig(cwd) {
4571
4294
  });
4572
4295
  if (mdEntities.length > 0) {
4573
4296
  if (fs.existsSync(jsonPath)) {
4574
- chunkN24XBYNX_cjs.warnOnce(
4297
+ chunkFAY3QDGC_cjs.warnOnce(
4575
4298
  "context-both-present",
4576
4299
  "[theokit-sdk] both .theokit/context/ and .theokit/context.json detected \u2014 using markdown; remove context.json"
4577
4300
  );
@@ -4581,7 +4304,7 @@ async function loadContextConfig(cwd) {
4581
4304
  };
4582
4305
  }
4583
4306
  if (!fs.existsSync(jsonPath)) return { sources: [] };
4584
- chunkN24XBYNX_cjs.warnOnce(
4307
+ chunkFAY3QDGC_cjs.warnOnce(
4585
4308
  "context-json-deprecated",
4586
4309
  "[theokit-sdk] .theokit/context.json is deprecated; migrate to .theokit/context/<name>.md via theokit-migrate-config"
4587
4310
  );
@@ -4589,7 +4312,7 @@ async function loadContextConfig(cwd) {
4589
4312
  try {
4590
4313
  raw = await promises.readFile(jsonPath, "utf8");
4591
4314
  } catch (cause) {
4592
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Failed to read context config: ${jsonPath}`, {
4315
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Failed to read context config: ${jsonPath}`, {
4593
4316
  code: "context_read_error",
4594
4317
  cause
4595
4318
  });
@@ -4601,13 +4324,13 @@ function parseConfig(raw, configPath) {
4601
4324
  try {
4602
4325
  parsed = JSON.parse(raw);
4603
4326
  } catch (cause) {
4604
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Invalid JSON in context config: ${configPath}`, {
4327
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Invalid JSON in context config: ${configPath}`, {
4605
4328
  code: "context_json_invalid",
4606
4329
  cause
4607
4330
  });
4608
4331
  }
4609
4332
  if (!parsed || typeof parsed !== "object") {
4610
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Context config must be an object: ${configPath}`, {
4333
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Context config must be an object: ${configPath}`, {
4611
4334
  code: "context_config_shape"
4612
4335
  });
4613
4336
  }
@@ -4622,7 +4345,7 @@ function parseConfig(raw, configPath) {
4622
4345
  }
4623
4346
  function readSources(sourcesRaw, configPath) {
4624
4347
  if (!Array.isArray(sourcesRaw)) {
4625
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Context config sources must be an array: ${configPath}`, {
4348
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Context config sources must be an array: ${configPath}`, {
4626
4349
  code: "context_sources_shape"
4627
4350
  });
4628
4351
  }
@@ -4720,7 +4443,7 @@ var PluginsManager = class {
4720
4443
  async refresh() {
4721
4444
  this.plugins = [];
4722
4445
  const pluginsRoot = path.join(this.cwd, ".theokit", "plugins");
4723
- const entries = await chunkLALRCFSN_cjs.readWorkspaceDir(pluginsRoot, "plugins_read_error", "plugins directory");
4446
+ const entries = await chunk7DXLNNKH_cjs.readWorkspaceDir(pluginsRoot, "plugins_read_error", "plugins directory");
4724
4447
  for (const entry of entries) {
4725
4448
  if (!entry.isDirectory()) continue;
4726
4449
  const folderName = entry.name;
@@ -4728,13 +4451,13 @@ var PluginsManager = class {
4728
4451
  const jsonPath = path.join(pluginsRoot, folderName, "plugin.json");
4729
4452
  const metadata = fs.existsSync(mdPath) ? await loadPluginManifestFromMarkdown(pluginsRoot, folderName) : await loadPluginManifestFromJson(jsonPath, folderName);
4730
4453
  if (fs.existsSync(mdPath) && fs.existsSync(jsonPath)) {
4731
- chunkN24XBYNX_cjs.warnOnce(
4454
+ chunkFAY3QDGC_cjs.warnOnce(
4732
4455
  `plugin-${folderName}-both`,
4733
4456
  `[theokit-sdk] both ${folderName}/PLUGIN.md and ${folderName}/plugin.json detected \u2014 using markdown; remove plugin.json`
4734
4457
  );
4735
4458
  }
4736
4459
  if (!fs.existsSync(mdPath) && fs.existsSync(jsonPath)) {
4737
- chunkN24XBYNX_cjs.warnOnce(
4460
+ chunkFAY3QDGC_cjs.warnOnce(
4738
4461
  "plugin-json-deprecated",
4739
4462
  "[theokit-sdk] plugin.json manifests are deprecated; migrate to PLUGIN.md via theokit-migrate-config"
4740
4463
  );
@@ -4752,11 +4475,11 @@ var PluginsManager = class {
4752
4475
  const entry = metadata.entry;
4753
4476
  if (entry === void 0) return;
4754
4477
  const pluginRoot = path.join(this.cwd, ".theokit", "plugins", folderName);
4755
- const entryPath = chunkKIO7QFIV_cjs.safePathJoin(pluginRoot, entry);
4478
+ const entryPath = chunkYBFDBOUN_cjs.safePathJoin(pluginRoot, entry);
4756
4479
  try {
4757
4480
  await promises.readFile(entryPath, "utf8");
4758
4481
  } catch (cause) {
4759
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Plugin ${metadata.name} entry file is missing: ${entry}`, {
4482
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Plugin ${metadata.name} entry file is missing: ${entry}`, {
4760
4483
  code: "plugin_entry_missing",
4761
4484
  cause
4762
4485
  });
@@ -4765,7 +4488,7 @@ var PluginsManager = class {
4765
4488
  assertCloudRules() {
4766
4489
  if (!this.cloud) return;
4767
4490
  if (this.localPaths !== void 0 && this.localPaths.length > 0) {
4768
- throw new chunkA44COQJJ_cjs.ConfigurationError(
4491
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
4769
4492
  "Cloud agents reject local plugin paths \u2014 plugins must come from committed repo files",
4770
4493
  { code: "cloud_plugin_path_rejected" }
4771
4494
  );
@@ -4777,7 +4500,7 @@ async function loadPluginManifestFromJson(manifestPath, folderName) {
4777
4500
  try {
4778
4501
  raw = await promises.readFile(manifestPath, "utf8");
4779
4502
  } catch (cause) {
4780
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Plugin ${folderName} is missing plugin.json`, {
4503
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Plugin ${folderName} is missing plugin.json`, {
4781
4504
  code: "plugin_missing_manifest",
4782
4505
  cause
4783
4506
  });
@@ -4786,13 +4509,13 @@ async function loadPluginManifestFromJson(manifestPath, folderName) {
4786
4509
  try {
4787
4510
  parsed = JSON.parse(raw);
4788
4511
  } catch (cause) {
4789
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Plugin ${folderName} manifest is invalid JSON`, {
4512
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Plugin ${folderName} manifest is invalid JSON`, {
4790
4513
  code: "plugin_manifest_invalid",
4791
4514
  cause
4792
4515
  });
4793
4516
  }
4794
4517
  if (!parsed || typeof parsed !== "object") {
4795
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Plugin ${folderName} manifest must be an object`, {
4518
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Plugin ${folderName} manifest must be an object`, {
4796
4519
  code: "plugin_manifest_shape"
4797
4520
  });
4798
4521
  }
@@ -4811,7 +4534,7 @@ async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
4811
4534
  try {
4812
4535
  raw = await promises.readFile(mdPath, "utf8");
4813
4536
  } catch (cause) {
4814
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Plugin ${folderName} is missing PLUGIN.md`, {
4537
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Plugin ${folderName} is missing PLUGIN.md`, {
4815
4538
  code: "plugin_missing_manifest",
4816
4539
  cause
4817
4540
  });
@@ -4826,7 +4549,7 @@ async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
4826
4549
  });
4827
4550
  const entity = entities.find((e) => e.slug === "PLUGIN");
4828
4551
  if (entity === void 0) {
4829
- throw new chunkA44COQJJ_cjs.ConfigurationError(`Plugin ${folderName} PLUGIN.md not parseable`, {
4552
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`Plugin ${folderName} PLUGIN.md not parseable`, {
4830
4553
  code: "plugin_missing_manifest"
4831
4554
  });
4832
4555
  }
@@ -5100,7 +4823,7 @@ function assertValidThresholds(soft, hard) {
5100
4823
  ["hardThreshold", hard]
5101
4824
  ]) {
5102
4825
  if (!Number.isInteger(value) || value < 1) {
5103
- throw new chunkA44COQJJ_cjs.ConfigurationError(
4826
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
5104
4827
  `doomLoop.${label} must be a positive integer (received ${value}).`,
5105
4828
  { code: "invalid_doom_loop_threshold" }
5106
4829
  );
@@ -5381,7 +5104,7 @@ async function safeListTools(client, serverName) {
5381
5104
  } catch (cause) {
5382
5105
  const message = cause instanceof Error ? cause.message : String(cause);
5383
5106
  const server = serverName ?? "unknown";
5384
- process.stderr.write(`[theokit-sdk] mcp listTools failed (server=${server}): ${message}
5107
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] mcp listTools failed (server=${server}): ${message}
5385
5108
  `);
5386
5109
  return [];
5387
5110
  }
@@ -5450,7 +5173,7 @@ function emitLlmMetrics(inputs, result, startAt) {
5450
5173
  inputs.telemetry?.recordHistogram(HISTOGRAM_NAMES.LLM_USAGE_MISSING, 1, {
5451
5174
  provider: inputs.llm.name
5452
5175
  });
5453
- process.stderr.write(
5176
+ chunkLTCOPATU_cjs.diag(
5454
5177
  `[theokit-sdk] llm usage missing from ${inputs.llm.name} finish \u2014 budget may undercount
5455
5178
  `
5456
5179
  );
@@ -5699,7 +5422,7 @@ function coerceArgsToSchema(args, schema) {
5699
5422
  }
5700
5423
 
5701
5424
  // src/tool-error.ts
5702
- var ToolError = class extends chunkA44COQJJ_cjs.TheokitAgentError {
5425
+ var ToolError = class extends chunkMHCKWQR3_cjs.TheokitAgentError {
5703
5426
  name = "ToolError";
5704
5427
  /** The error content surfaced to the model: a string, or text/image blocks. */
5705
5428
  content;
@@ -5893,7 +5616,7 @@ function raceToolExecution(exec, opts) {
5893
5616
  // src/internal/agent-loop/tool-dispatch.ts
5894
5617
  async function dispatchTools(inputs, tools, toolCalls, events, parentSpan) {
5895
5618
  const maxConcurrent = inputs.maxConcurrentTools ?? 4;
5896
- return chunkGIW4L6HY_cjs.mapWithConcurrency(
5619
+ return chunkSWIBQFPH_cjs.mapWithConcurrency(
5897
5620
  toolCalls,
5898
5621
  maxConcurrent,
5899
5622
  (call) => dispatchSingleCall(inputs, tools, call, events, parentSpan)
@@ -5921,7 +5644,7 @@ async function dispatchSingleCall(inputs, tools, call, events, parentSpan) {
5921
5644
  toolSpan?.end();
5922
5645
  return fileVeto;
5923
5646
  }
5924
- chunkMZ5ZRORA_cjs.emitRunEvent(inputs.runEventSink, {
5647
+ chunk6EDQBX7U_cjs.emitRunEvent(inputs.runEventSink, {
5925
5648
  type: "tool_progress",
5926
5649
  toolName: workingCall.name,
5927
5650
  toolCallId: callId
@@ -5952,7 +5675,7 @@ function applyRepairAndExtractCall(tools, call) {
5952
5675
  function vetoFromForkWhitelist(inputs, call, callId, events) {
5953
5676
  const whitelistDecision = chunkVJ26EKGJ_cjs.checkToolWhitelist(call.name);
5954
5677
  if (whitelistDecision.allowed) return void 0;
5955
- chunkMZ5ZRORA_cjs.emitRunEvent(inputs.runEventSink, {
5678
+ chunk6EDQBX7U_cjs.emitRunEvent(inputs.runEventSink, {
5956
5679
  type: "permission_denied",
5957
5680
  toolName: call.name,
5958
5681
  toolCallId: callId,
@@ -5997,7 +5720,7 @@ async function vetoFromPluginPreHook(inputs, call, callId, events) {
5997
5720
  ...inputs.permissionMode !== void 0 ? { permissionMode: inputs.permissionMode } : {}
5998
5721
  });
5999
5722
  if (pluginVeto === void 0) return void 0;
6000
- chunkMZ5ZRORA_cjs.emitRunEvent(inputs.runEventSink, {
5723
+ chunk6EDQBX7U_cjs.emitRunEvent(inputs.runEventSink, {
6001
5724
  type: "permission_denied",
6002
5725
  toolName: call.name,
6003
5726
  toolCallId: callId,
@@ -6026,7 +5749,7 @@ async function vetoFromFileHookPreDecision(inputs, call, callId, events) {
6026
5749
  runId: inputs.runId
6027
5750
  });
6028
5751
  if (!preDecision.blocked) return void 0;
6029
- chunkMZ5ZRORA_cjs.emitRunEvent(inputs.runEventSink, {
5752
+ chunk6EDQBX7U_cjs.emitRunEvent(inputs.runEventSink, {
6030
5753
  type: "permission_denied",
6031
5754
  toolName: call.name,
6032
5755
  toolCallId: callId,
@@ -6127,7 +5850,7 @@ function finalizeSpanAndPostHook(inputs, call, callId, result, events, toolSpan)
6127
5850
  agentId: inputs.agentId,
6128
5851
  runId: inputs.runId
6129
5852
  }).catch((err) => {
6130
- process.stderr.write(
5853
+ chunkLTCOPATU_cjs.diag(
6131
5854
  `[theokit-sdk] postToolUse hook error (swallowed): ${err instanceof Error ? err.message : String(err)}
6132
5855
  `
6133
5856
  );
@@ -6146,7 +5869,7 @@ async function emitToolLifecycleDelta(inputs, update) {
6146
5869
  try {
6147
5870
  await inputs.onDelta({ update });
6148
5871
  } catch (err) {
6149
- process.stderr.write(
5872
+ chunkLTCOPATU_cjs.diag(
6150
5873
  `[theokit-sdk] onDelta tool-lifecycle emit error (swallowed): ${err instanceof Error ? err.message : String(err)}
6151
5874
  `
6152
5875
  );
@@ -6158,7 +5881,7 @@ async function safeEmitToolHook(callback, event) {
6158
5881
  await callback(event);
6159
5882
  } catch (cause) {
6160
5883
  const msg = cause instanceof Error ? cause.message : String(cause);
6161
- process.stderr.write(`[theokit-sdk] tool lifecycle hook threw: ${msg}
5884
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] tool lifecycle hook threw: ${msg}
6162
5885
  `);
6163
5886
  }
6164
5887
  }
@@ -6225,7 +5948,7 @@ function applyToolResultGuard(parts, opts) {
6225
5948
  (p) => (
6226
5949
  // SE7 — guard the TEXT of a tool result (string or the text blocks of a
6227
5950
  // structured content); image blocks pass through untouched.
6228
- p.type === "tool_result" ? { ...p, content: chunkWEHUJ7ZS_cjs.renderToolResultContentText(p.content, (t) => guardText(t, opts)) } : p
5951
+ p.type === "tool_result" ? { ...p, content: chunkALU3KC4G_cjs.renderToolResultContentText(p.content, (t) => guardText(t, opts)) } : p
6229
5952
  )
6230
5953
  );
6231
5954
  }
@@ -6420,7 +6143,7 @@ function catalogCostFallback(provider, cleanedModel) {
6420
6143
  const candidates = [`${provider}/${cleanedModel}`, cleanedModel];
6421
6144
  if (stripped !== cleanedModel) candidates.push(`${provider}/${stripped}`, stripped);
6422
6145
  for (const key of candidates) {
6423
- const info = chunkD42XHI4O_cjs.getCatalogModelInfo(key);
6146
+ const info = chunk56ZM6P7Z_cjs.getCatalogModelInfo(key);
6424
6147
  const cost = info?.cost;
6425
6148
  if (cost === void 0) continue;
6426
6149
  const [prov, ...modelParts] = key.split("/");
@@ -6432,7 +6155,7 @@ function catalogCostFallback(provider, cleanedModel) {
6432
6155
  ...cost.cache_read !== void 0 ? { cacheReadCostPerMillion: cost.cache_read } : {},
6433
6156
  ...cost.cache_write !== void 0 ? { cacheWriteCostPerMillion: cost.cache_write } : {},
6434
6157
  // M44 M5 fix — honest provenance: a key patched by the LIVE models-dev source is not "vendored".
6435
- pricingVersion: chunkD42XHI4O_cjs.isPatchedModelKey(key) ? "catalog-models-dev" : "catalog-vendored"
6158
+ pricingVersion: chunk56ZM6P7Z_cjs.isPatchedModelKey(key) ? "catalog-models-dev" : "catalog-vendored"
6436
6159
  };
6437
6160
  }
6438
6161
  return void 0;
@@ -6880,15 +6603,15 @@ var FallbackLlmClient = class {
6880
6603
  let lastError;
6881
6604
  for (const client of this.clients) {
6882
6605
  if (signal.aborted) throw abortError(signal);
6883
- const attempt = await chunkWEHUJ7ZS_cjs.tryFirstEvent(client, request, signal, true);
6606
+ const attempt = await chunkALU3KC4G_cjs.tryFirstEvent(client, request, signal, true);
6884
6607
  if (attempt.kind === "handshake_error") {
6885
6608
  lastError = attempt.error;
6886
6609
  continue;
6887
6610
  }
6888
- return yield* chunkWEHUJ7ZS_cjs.relayStream(attempt.generator, attempt.firstResult);
6611
+ return yield* chunkALU3KC4G_cjs.relayStream(attempt.generator, attempt.firstResult);
6889
6612
  }
6890
6613
  if (lastError !== void 0) throw lastError;
6891
- throw new chunkA44COQJJ_cjs.NetworkError("FallbackLlmClient has no providers configured", {
6614
+ throw new chunkMHCKWQR3_cjs.NetworkError("FallbackLlmClient has no providers configured", {
6892
6615
  code: "fallback_empty_chain"
6893
6616
  });
6894
6617
  }
@@ -6911,7 +6634,7 @@ function reconnectDelay(attempt) {
6911
6634
  return ms <= 0 ? Promise.resolve() : new Promise((resolve) => setTimeout(resolve, ms));
6912
6635
  }
6913
6636
  function mcpTimeoutError(name, timeoutMs) {
6914
- return new chunkA44COQJJ_cjs.NetworkError(`MCP ${name} request timed out after ${timeoutMs}ms`, {
6637
+ return new chunkMHCKWQR3_cjs.NetworkError(`MCP ${name} request timed out after ${timeoutMs}ms`, {
6915
6638
  code: "mcp_timeout"
6916
6639
  });
6917
6640
  }
@@ -6994,7 +6717,7 @@ var StdioMcpClient = class extends BaseMcpClient {
6994
6717
  child.stdin.on("error", () => void 0);
6995
6718
  child.on("error", () => {
6996
6719
  this.rejectAllPending(
6997
- new chunkA44COQJJ_cjs.NetworkError(`MCP ${this.name} process crashed`, { code: "mcp_crashed" })
6720
+ new chunkMHCKWQR3_cjs.NetworkError(`MCP ${this.name} process crashed`, { code: "mcp_crashed" })
6998
6721
  );
6999
6722
  });
7000
6723
  child.on("exit", () => {
@@ -7002,7 +6725,7 @@ var StdioMcpClient = class extends BaseMcpClient {
7002
6725
  this.child = void 0;
7003
6726
  this.dropped = true;
7004
6727
  this.rejectAllPending(
7005
- new chunkA44COQJJ_cjs.NetworkError(`MCP ${this.name} disconnected`, { code: "mcp_disconnected" })
6728
+ new chunkMHCKWQR3_cjs.NetworkError(`MCP ${this.name} disconnected`, { code: "mcp_disconnected" })
7006
6729
  );
7007
6730
  });
7008
6731
  }
@@ -7017,7 +6740,7 @@ var StdioMcpClient = class extends BaseMcpClient {
7017
6740
  if (this.child !== void 0) return Promise.resolve();
7018
6741
  if (!this.dropped) {
7019
6742
  return Promise.reject(
7020
- new chunkA44COQJJ_cjs.ConfigurationError(`MCP ${this.name} is not initialized`, { code: "mcp_not_init" })
6743
+ new chunkMHCKWQR3_cjs.ConfigurationError(`MCP ${this.name} is not initialized`, { code: "mcp_not_init" })
7021
6744
  );
7022
6745
  }
7023
6746
  this.reconnectPromise ??= this.reconnect().finally(() => {
@@ -7038,13 +6761,13 @@ var StdioMcpClient = class extends BaseMcpClient {
7038
6761
  lastErr = err;
7039
6762
  }
7040
6763
  }
7041
- throw new chunkA44COQJJ_cjs.NetworkError(`MCP ${this.name} reconnect exhausted`, {
6764
+ throw new chunkMHCKWQR3_cjs.NetworkError(`MCP ${this.name} reconnect exhausted`, {
7042
6765
  code: "mcp_disconnected",
7043
6766
  ...lastErr instanceof Error ? { cause: lastErr } : {}
7044
6767
  });
7045
6768
  }
7046
6769
  async close() {
7047
- this.rejectAllPending(new chunkA44COQJJ_cjs.NetworkError(`MCP ${this.name} closed`, { code: "mcp_closed" }));
6770
+ this.rejectAllPending(new chunkMHCKWQR3_cjs.NetworkError(`MCP ${this.name} closed`, { code: "mcp_closed" }));
7048
6771
  const child = this.child;
7049
6772
  this.child = void 0;
7050
6773
  this.dropped = false;
@@ -7063,7 +6786,7 @@ var StdioMcpClient = class extends BaseMcpClient {
7063
6786
  if (this.buffer.length > MAX_STDIO_BUFFER_BYTES) {
7064
6787
  this.buffer = "";
7065
6788
  this.rejectAllPending(
7066
- new chunkA44COQJJ_cjs.NetworkError(`MCP ${this.name} exceeded stdout buffer limit`, {
6789
+ new chunkMHCKWQR3_cjs.NetworkError(`MCP ${this.name} exceeded stdout buffer limit`, {
7067
6790
  code: "mcp_buffer_overflow"
7068
6791
  })
7069
6792
  );
@@ -7098,7 +6821,7 @@ var StdioMcpClient = class extends BaseMcpClient {
7098
6821
  if (child !== void 0) return this.send(child, method, params);
7099
6822
  if (this.dropped) return this.reconnectAndRequest(method, params);
7100
6823
  return Promise.reject(
7101
- new chunkA44COQJJ_cjs.ConfigurationError(`MCP ${this.name} is not initialized`, { code: "mcp_not_init" })
6824
+ new chunkMHCKWQR3_cjs.ConfigurationError(`MCP ${this.name} is not initialized`, { code: "mcp_not_init" })
7102
6825
  );
7103
6826
  }
7104
6827
  /** M2 #59 — reconnect a dropped client, then send. Separate async path so the
@@ -7107,7 +6830,7 @@ var StdioMcpClient = class extends BaseMcpClient {
7107
6830
  await this.ensureConnected();
7108
6831
  const child = this.child;
7109
6832
  if (child === void 0) {
7110
- throw new chunkA44COQJJ_cjs.ConfigurationError(`MCP ${this.name} is not initialized`, { code: "mcp_not_init" });
6833
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(`MCP ${this.name} is not initialized`, { code: "mcp_not_init" });
7111
6834
  }
7112
6835
  return this.send(child, method, params);
7113
6836
  }
@@ -7124,7 +6847,7 @@ var StdioMcpClient = class extends BaseMcpClient {
7124
6847
  this.child = void 0;
7125
6848
  this.dropped = true;
7126
6849
  this.rejectAllPending(
7127
- new chunkA44COQJJ_cjs.NetworkError(`MCP ${this.name} disconnected`, { code: "mcp_disconnected" })
6850
+ new chunkMHCKWQR3_cjs.NetworkError(`MCP ${this.name} disconnected`, { code: "mcp_disconnected" })
7128
6851
  );
7129
6852
  }, this.timeoutMs);
7130
6853
  this.pending.set(id, { resolve, reject, timer });
@@ -7168,7 +6891,7 @@ var HttpMcpClient = class extends BaseMcpClient {
7168
6891
  throw cause;
7169
6892
  }
7170
6893
  if (!response.ok) {
7171
- throw new chunkA44COQJJ_cjs.NetworkError(`MCP ${this.name} returned ${response.status}`, {
6894
+ throw new chunkMHCKWQR3_cjs.NetworkError(`MCP ${this.name} returned ${response.status}`, {
7172
6895
  code: "mcp_http_error"
7173
6896
  });
7174
6897
  }
@@ -7183,14 +6906,14 @@ var HttpMcpClient = class extends BaseMcpClient {
7183
6906
  function resolveMcpCwd(configCwd) {
7184
6907
  if (configCwd === void 0) return process.cwd();
7185
6908
  if (path.isAbsolute(configCwd)) return configCwd;
7186
- return chunkKIO7QFIV_cjs.safePathJoin(process.cwd(), configCwd);
6909
+ return chunkYBFDBOUN_cjs.safePathJoin(process.cwd(), configCwd);
7187
6910
  }
7188
6911
 
7189
6912
  // src/internal/providers/register-plugin-providers.ts
7190
6913
  function registerPluginProviderProfiles(entries) {
7191
6914
  let registered2 = 0;
7192
6915
  for (const entry of entries) {
7193
- chunkD42XHI4O_cjs.registerProvider(entry.profile);
6916
+ chunk56ZM6P7Z_cjs.registerProvider(entry.profile);
7194
6917
  registered2 += 1;
7195
6918
  }
7196
6919
  return registered2;
@@ -7270,7 +6993,7 @@ function applyPersonalityFilter(exposedTools, whitelist, opts) {
7270
6993
  if (exposedSet.has(name)) continue;
7271
6994
  const hint = suggestClosest(name, exposedSet);
7272
6995
  const message = hint !== void 0 ? `[theokit-sdk] personality "${opts?.personalityName ?? "?"}" references unknown tool "${name}"; did you mean "${hint}"?` : `[theokit-sdk] personality "${opts?.personalityName ?? "?"}" references unknown tool "${name}" (not exposed)`;
7273
- chunkN24XBYNX_cjs.warnOnce(
6996
+ chunkFAY3QDGC_cjs.warnOnce(
7274
6997
  `personality-tool-missing|${opts?.agentId ?? "?"}|${opts?.personalityName ?? "?"}|${name}`,
7275
6998
  message
7276
6999
  );
@@ -7379,27 +7102,25 @@ function createRealLocalRun(options) {
7379
7102
  }
7380
7103
  var pluginProvidersAnnounced = false;
7381
7104
  function resolveRunProvider(options) {
7382
- chunkD42XHI4O_cjs.registerBuiltins();
7105
+ chunk56ZM6P7Z_cjs.registerBuiltins();
7383
7106
  const profiles = options.pluginManager?.aggregated.providerProfiles ?? [];
7384
7107
  const registered2 = registerPluginProviderProfiles(profiles);
7385
7108
  if (registered2 > 0 && !pluginProvidersAnnounced) {
7386
7109
  pluginProvidersAnnounced = true;
7387
7110
  const names = profiles.map((e) => e.profile.name).join(", ");
7388
- process.stderr.write(
7389
- `[theokit-sdk] registered ${registered2} plugin provider profile(s): ${names}
7390
- `
7391
- );
7111
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] registered ${registered2} plugin provider profile(s): ${names}
7112
+ `);
7392
7113
  }
7393
7114
  const parsedModel = chunkVYHJZVL5_cjs.parseModelId(options.model?.id);
7394
- const modelInferredProvider = parsedModel.provider !== void 0 && chunkD42XHI4O_cjs.getProviderProfile(parsedModel.provider) !== void 0 ? parsedModel.provider : void 0;
7395
- const keyInferredProvider = chunkWEHUJ7ZS_cjs.inferProviderFromApiKey(options.agentOptions.apiKey);
7396
- const primary = options.agentOptions.providers?.routes?.[0]?.provider ?? keyInferredProvider ?? modelInferredProvider ?? chunkWEHUJ7ZS_cjs.detectPrimaryProvider();
7115
+ const modelInferredProvider = parsedModel.provider !== void 0 && chunk56ZM6P7Z_cjs.getProviderProfile(parsedModel.provider) !== void 0 ? parsedModel.provider : void 0;
7116
+ const keyInferredProvider = chunkALU3KC4G_cjs.inferProviderFromApiKey(options.agentOptions.apiKey);
7117
+ const primary = options.agentOptions.providers?.routes?.[0]?.provider ?? keyInferredProvider ?? modelInferredProvider ?? chunkALU3KC4G_cjs.detectPrimaryProvider();
7397
7118
  const effectiveModelId = modelInferredProvider !== void 0 && modelInferredProvider === primary ? parsedModel.name : options.model?.id ?? "claude-sonnet-4-6";
7398
7119
  return { primary, effectiveModelId };
7399
7120
  }
7400
7121
  function mergeExplicitApiKey(pools, primary, apiKey) {
7401
7122
  if (apiKey === void 0 || apiKey.length === 0) return pools;
7402
- if (isFixtureApiKey(apiKey) || apiKey === LOCAL_RUNTIME_MOCK_KEY) return pools;
7123
+ if (chunkALU3KC4G_cjs.isFixtureApiKey(apiKey) || apiKey === LOCAL_RUNTIME_MOCK_KEY) return pools;
7403
7124
  const existing = pools?.[primary];
7404
7125
  if (existing !== void 0 && existing.length > 0) return pools;
7405
7126
  return { ...pools ?? {}, [primary]: [apiKey] };
@@ -7407,7 +7128,7 @@ function mergeExplicitApiKey(pools, primary, apiKey) {
7407
7128
  function buildLoopInputs(options, runId, userText, userImages) {
7408
7129
  const maxIterations = options.sendOptions.maxIterations;
7409
7130
  if (maxIterations !== void 0 && (!Number.isInteger(maxIterations) || maxIterations < 1)) {
7410
- throw new chunkA44COQJJ_cjs.ConfigurationError(
7131
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
7411
7132
  `SendOptions.maxIterations must be a positive integer, got ${maxIterations}`,
7412
7133
  { code: "invalid_max_iterations" }
7413
7134
  );
@@ -7422,14 +7143,14 @@ function buildLoopInputs(options, runId, userText, userImages) {
7422
7143
  const credentialPoolStrategy = options.agentOptions.providers?.credentialPoolStrategy;
7423
7144
  const extractToolCallsFromContent = options.agentOptions.providers?.routes?.[0]?.extractToolCallsFromContent;
7424
7145
  const rateLimitSink = options.sendOptions.onRunEvent;
7425
- const chain = chunkWEHUJ7ZS_cjs.resolveProviderChain({
7146
+ const chain = chunkALU3KC4G_cjs.resolveProviderChain({
7426
7147
  primary,
7427
7148
  ...fallback !== void 0 ? { fallback } : {},
7428
7149
  ...apiKeys !== void 0 ? { apiKeys } : {},
7429
7150
  ...credentialPoolStrategy !== void 0 ? { credentialPoolStrategy } : {},
7430
7151
  ...extractToolCallsFromContent === true ? { extractToolCallsFromContent: true } : {},
7431
7152
  ...rateLimitSink !== void 0 ? {
7432
- onRateLimit: (info) => chunkMZ5ZRORA_cjs.emitRunEvent(rateLimitSink, { type: "rate_limit", ...info })
7153
+ onRateLimit: (info) => chunk6EDQBX7U_cjs.emitRunEvent(rateLimitSink, { type: "rate_limit", ...info })
7433
7154
  } : {}
7434
7155
  });
7435
7156
  const llm = chain.length === 1 ? chain[0] : new FallbackLlmClient(chain);
@@ -7647,7 +7368,7 @@ function buildRealRunOptions(args) {
7647
7368
  };
7648
7369
  }
7649
7370
  async function createFixtureRunHelper(args) {
7650
- const sessionMessages = chunkG4WI3VW2_cjs.getSessionMessages(args.inputs.agentId);
7371
+ const sessionMessages = chunkH5YVJB4K_cjs.getSessionMessages(args.inputs.agentId);
7651
7372
  const projectMcpServers = args.inputs.settingSourcesIncludeProject ? await readProjectMcpServers(args.inputs.workspaceCwd) : {};
7652
7373
  return createLocalRun({
7653
7374
  agentId: args.inputs.agentId,
@@ -7666,7 +7387,7 @@ async function createFixtureRunHelper(args) {
7666
7387
  }
7667
7388
  async function dispatchLocalRun(args) {
7668
7389
  const apiKey = resolveApiKey(args.inputs.options.apiKey);
7669
- if (shouldUseRealLocalRuntime(apiKey)) {
7390
+ if (chunkALU3KC4G_cjs.shouldUseRealLocalRuntime(apiKey)) {
7670
7391
  return createRealLocalRun(
7671
7392
  buildRealRunOptions({
7672
7393
  inputs: args.inputs,
@@ -7701,25 +7422,21 @@ async function readProjectMcpServers(cwd) {
7701
7422
 
7702
7423
  // src/internal/local-agent/local-agent-invalidate.ts
7703
7424
  async function applyDeferredInvalidation(agentId, pending, refresh) {
7704
- process.stderr.write(
7705
- `[theokit-sdk] applying deferred cache invalidation (${agentId}): ${pending.reason}
7706
- `
7707
- );
7425
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] applying deferred cache invalidation (${agentId}): ${pending.reason}
7426
+ `);
7708
7427
  try {
7709
7428
  await refresh();
7710
7429
  } catch (err) {
7711
7430
  const msg = err instanceof Error ? err.message : String(err);
7712
- process.stderr.write(`[theokit-sdk] invalidateCache reload failed (continuing): ${msg}
7431
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] invalidateCache reload failed (continuing): ${msg}
7713
7432
  `);
7714
7433
  }
7715
7434
  }
7716
7435
  async function invalidateCacheImpl(agentId, reason, options, disposed, dispose, setPending) {
7717
7436
  if (disposed) return;
7718
7437
  if (options.applyNow === true) {
7719
- process.stderr.write(
7720
- `[theokit-sdk] invalidateCache applyNow disposing agent (${agentId}): ${reason}
7721
- `
7722
- );
7438
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] invalidateCache applyNow disposing agent (${agentId}): ${reason}
7439
+ `);
7723
7440
  await dispose();
7724
7441
  return;
7725
7442
  }
@@ -7730,14 +7447,225 @@ async function consumePending(agentId, pending, clear, refresh) {
7730
7447
  clear();
7731
7448
  await applyDeferredInvalidation(agentId, pending, refresh);
7732
7449
  }
7450
+
7451
+ // src/internal/runtime/registry/live-agent-registry.ts
7452
+ var DEFAULT_MAX_AGENTS = 100;
7453
+ var DEFAULT_IDLE_TIMEOUT_MS = 30 * 60 * 1e3;
7454
+ var DEFAULT_SWEEP_INTERVAL_MS = 6e4;
7455
+ var LiveAgentRegistry = class {
7456
+ #agents = /* @__PURE__ */ new Map();
7457
+ #maxAgents = DEFAULT_MAX_AGENTS;
7458
+ #idleTimeoutMs = DEFAULT_IDLE_TIMEOUT_MS;
7459
+ #sweepIntervalMs = DEFAULT_SWEEP_INTERVAL_MS;
7460
+ #onEvict;
7461
+ #sweepTimer;
7462
+ /**
7463
+ * Reconfigure registry behavior. Process-wide singleton (D310) — last
7464
+ * configure call wins for all subsequent operations.
7465
+ */
7466
+ configure(opts) {
7467
+ if (opts.maxAgents !== void 0) this.#maxAgents = Math.max(0, opts.maxAgents);
7468
+ if (opts.idleTimeoutMs !== void 0) this.#idleTimeoutMs = Math.max(0, opts.idleTimeoutMs);
7469
+ if (opts.sweepIntervalMs !== void 0)
7470
+ this.#sweepIntervalMs = Math.max(1e3, opts.sweepIntervalMs);
7471
+ this.#onEvict = opts.onEvict;
7472
+ this.#stopSweep();
7473
+ if (this.#idleTimeoutMs > 0) this.#startSweep();
7474
+ }
7475
+ /**
7476
+ * Lookup a cached agent. `get` is a use — refreshes `lastUsedAt` so the
7477
+ * entry survives LRU eviction.
7478
+ */
7479
+ get(id) {
7480
+ const entry = this.#agents.get(id);
7481
+ if (entry === void 0) return void 0;
7482
+ entry.lastUsedAt = Date.now();
7483
+ return entry.agent;
7484
+ }
7485
+ /**
7486
+ * Insert or overwrite an agent in the cache. Triggers fire-and-forget LRU
7487
+ * eviction when `size > maxAgents`.
7488
+ *
7489
+ * EC-4: when `id` already maps to a DIFFERENT agent instance, dispose the
7490
+ * old one before overwriting (race protection against two `getOrCreate`
7491
+ * calls creating two agents but only the second being cached — the first
7492
+ * would leak file handles + lifecycle controllers).
7493
+ */
7494
+ set(id, agent) {
7495
+ if (this.#maxAgents === 0) return;
7496
+ const existing = this.#agents.get(id);
7497
+ if (existing !== void 0 && existing.agent !== agent) {
7498
+ void existing.agent.dispose().catch(() => {
7499
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] dispose during overwrite failed (${id})
7500
+ `);
7501
+ });
7502
+ }
7503
+ this.#agents.set(id, { agent, lastUsedAt: Date.now() });
7504
+ if (this.#agents.size > this.#maxAgents) void this.#evictLRU();
7505
+ }
7506
+ /**
7507
+ * Remove the entry from the cache WITHOUT calling `dispose()` or
7508
+ * `onEvict`. Used by `LocalAgent.dispose()` itself so the disposed
7509
+ * instance can never be returned by a subsequent `get(id)` (dispose-cache
7510
+ * race fix). Idempotent — calling on an unknown id is a no-op.
7511
+ *
7512
+ * @internal
7513
+ */
7514
+ forget(id) {
7515
+ this.#agents.delete(id);
7516
+ }
7517
+ /**
7518
+ * Explicitly evict an agent by id. Returns `true` when the entry was
7519
+ * present (false = already gone). Calls `agent.dispose()` + `onEvict`
7520
+ * with reason `"explicit"`.
7521
+ */
7522
+ async evict(id) {
7523
+ const entry = this.#agents.get(id);
7524
+ if (entry === void 0) return false;
7525
+ this.#agents.delete(id);
7526
+ await this.#disposeAndNotify(id, entry.agent, "explicit");
7527
+ return true;
7528
+ }
7529
+ /**
7530
+ * Evict every cached agent. Used by graceful shutdown (`process.on('SIGTERM')`)
7531
+ * or end-of-test cleanup.
7532
+ */
7533
+ async evictAll() {
7534
+ const entries = Array.from(this.#agents.entries());
7535
+ this.#agents.clear();
7536
+ this.#stopSweep();
7537
+ for (const [id, entry] of entries) {
7538
+ await this.#disposeAndNotify(id, entry.agent, "explicit");
7539
+ }
7540
+ }
7541
+ /** Number of currently cached agents. */
7542
+ size() {
7543
+ return this.#agents.size;
7544
+ }
7545
+ /** Ids of cached agents, newest first (by lastUsedAt). */
7546
+ ids() {
7547
+ return Array.from(this.#agents.entries()).sort((a, b) => b[1].lastUsedAt - a[1].lastUsedAt).map(([id]) => id);
7548
+ }
7549
+ /**
7550
+ * LRU eviction: drop the entry with the smallest `lastUsedAt`. Runs only
7551
+ * when `size > maxAgents`. Asynchronous because `dispose()` is a Promise;
7552
+ * the hot-path caller (`set`) does not await.
7553
+ *
7554
+ * @internal
7555
+ */
7556
+ async #evictLRU() {
7557
+ if (this.#agents.size <= this.#maxAgents) return;
7558
+ let oldestId;
7559
+ let oldestAt = Infinity;
7560
+ for (const [id, entry2] of this.#agents) {
7561
+ if (entry2.lastUsedAt < oldestAt) {
7562
+ oldestAt = entry2.lastUsedAt;
7563
+ oldestId = id;
7564
+ }
7565
+ }
7566
+ if (oldestId === void 0) return;
7567
+ const entry = this.#agents.get(oldestId);
7568
+ if (entry === void 0) return;
7569
+ this.#agents.delete(oldestId);
7570
+ await this.#disposeAndNotify(oldestId, entry.agent, "lru");
7571
+ }
7572
+ /** Background sweep — drops entries whose `lastUsedAt < now - idleTimeoutMs`. */
7573
+ async #sweepIdle() {
7574
+ if (this.#idleTimeoutMs === 0) return;
7575
+ const threshold = Date.now() - this.#idleTimeoutMs;
7576
+ const toEvict = [];
7577
+ for (const [id, entry] of this.#agents) {
7578
+ if (entry.lastUsedAt < threshold) toEvict.push([id, entry]);
7579
+ }
7580
+ for (const [id, entry] of toEvict) {
7581
+ const current = this.#agents.get(id);
7582
+ if (current === void 0 || current.agent !== entry.agent) continue;
7583
+ this.#agents.delete(id);
7584
+ await this.#disposeAndNotify(id, entry.agent, "idle");
7585
+ }
7586
+ }
7587
+ #startSweep() {
7588
+ this.#sweepTimer = setInterval(() => void this.#sweepIdle(), this.#sweepIntervalMs);
7589
+ this.#sweepTimer.unref?.();
7590
+ }
7591
+ #stopSweep() {
7592
+ if (this.#sweepTimer !== void 0) {
7593
+ clearInterval(this.#sweepTimer);
7594
+ this.#sweepTimer = void 0;
7595
+ }
7596
+ }
7597
+ /** Dispose + notify with errors swallowed (D309). Single chokepoint. */
7598
+ async #disposeAndNotify(id, agent, reason) {
7599
+ try {
7600
+ await agent.dispose();
7601
+ } catch (cause) {
7602
+ const msg = cause instanceof Error ? cause.message : String(cause);
7603
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] dispose during eviction failed (${id}): ${msg}
7604
+ `);
7605
+ }
7606
+ if (this.#onEvict !== void 0) {
7607
+ try {
7608
+ this.#onEvict(id, reason);
7609
+ } catch (cause) {
7610
+ const msg = cause instanceof Error ? cause.message : String(cause);
7611
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] onEvict listener threw (${id}): ${msg}
7612
+ `);
7613
+ }
7614
+ }
7615
+ }
7616
+ };
7617
+ var liveAgentRegistry = new LiveAgentRegistry();
7618
+
7619
+ // src/internal/local-agent/local-agent-lifecycle.ts
7620
+ async function adquirirLeaseSePossivel(store, agentId) {
7621
+ const a = store.acquire;
7622
+ if (typeof a !== "function") return;
7623
+ try {
7624
+ await a.call(store, agentId);
7625
+ } catch (err) {
7626
+ if (err instanceof Error && err.name === "SessionBusyError") throw err;
7627
+ chunkLTCOPATU_cjs.diag(
7628
+ `[theokit-sdk] writer lease unavailable for ${agentId} (${err instanceof Error ? err.message : String(err)}) \u2014 proceeding without single-writer protection
7629
+ `
7630
+ );
7631
+ }
7632
+ }
7633
+ async function soltarLeaseSePossivel(store, agentId) {
7634
+ const r = store.release;
7635
+ if (typeof r === "function") await r.call(store, agentId);
7636
+ }
7637
+ async function disposeSessionStore(store) {
7638
+ const d = store.dispose;
7639
+ if (typeof d === "function") await d.call(store);
7640
+ }
7641
+ async function disposeLocalAgentSession(agent) {
7642
+ liveAgentRegistry.forget(agent.agentId);
7643
+ agent.lifecycleAbortController.abort();
7644
+ await chunkYLQQX5W2_cjs.withCwdMutex(`agent-send:${agent.agentId}`, () => Promise.resolve());
7645
+ disposeSessionMcpClients(agent.agentId);
7646
+ await chunkH5YVJB4K_cjs.flushSessionWrites();
7647
+ await flushRegistrySaves(agent.workspaceCwd);
7648
+ await disposeSessionStore(agent.sessionStore);
7649
+ chunkH5YVJB4K_cjs.descartarSessao(agent.workspaceCwd, agent.agentId);
7650
+ }
7651
+ async function reloadLocalAgent(agent) {
7652
+ if (agent.context !== void 0) await agent.context.refresh();
7653
+ if (agent.skillsManager !== void 0) await agent.skillsManager.refresh();
7654
+ if (agent.pluginsManager !== void 0) await agent.pluginsManager.refresh();
7655
+ return await chunkGM7QDQ24_cjs.loadSubagents(
7656
+ agent.workspaceCwd,
7657
+ agent.settingSourcesIncludeProject,
7658
+ agent.options.agents
7659
+ );
7660
+ }
7733
7661
  async function persistActiveMemoryTranscript(cwd, transcript) {
7734
7662
  try {
7735
- const dir = path.join(chunkJLMXKTBX_cjs.memoryDir(cwd), "transcripts", "active-memory");
7663
+ const dir = path.join(chunk2423XDPT_cjs.memoryDir(cwd), "transcripts", "active-memory");
7736
7664
  const file = path.join(dir, `${transcript.runId}.json`);
7737
- await chunkTIZ4TS5V_cjs.atomicWriteJson(file, transcript);
7665
+ await chunkICYBIC6N_cjs.atomicWriteJson(file, transcript);
7738
7666
  } catch (cause) {
7739
7667
  const message = cause instanceof Error ? cause.message : String(cause);
7740
- process.stderr.write(`[theokit-sdk] active-memory transcript persist failed: ${message}
7668
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] active-memory transcript persist failed: ${message}
7741
7669
  `);
7742
7670
  }
7743
7671
  }
@@ -7858,7 +7786,7 @@ async function searchOnce(args, cfg, query, started) {
7858
7786
  return { summary, durationMs: Date.now() - started, status: "ok", hits };
7859
7787
  } catch (cause) {
7860
7788
  const message = cause instanceof Error ? cause.message : String(cause);
7861
- process.stderr.write(`[theokit-sdk] active-memory recall failed: ${message}
7789
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] active-memory recall failed: ${message}
7862
7790
  `);
7863
7791
  return { summary: void 0, durationMs: Date.now() - started, status: "error", hits: [] };
7864
7792
  }
@@ -7970,17 +7898,17 @@ async function createOpenAiCompatibleRuntime(cfg, options) {
7970
7898
  const model = options.model ?? cfg.defaultModel;
7971
7899
  const apiKey = options.apiKey ?? process.env[cfg.apiKeyEnv];
7972
7900
  if (apiKey === void 0 || apiKey.length === 0) {
7973
- throw new chunkA44COQJJ_cjs.AuthenticationError(`${cfg.apiKeyEnv} missing`, {
7901
+ throw new chunkMHCKWQR3_cjs.AuthenticationError(`${cfg.apiKeyEnv} missing`, {
7974
7902
  code: "embedding_missing_api_key"
7975
7903
  });
7976
7904
  }
7977
7905
  const envBaseUrl = cfg.baseUrlEnv !== void 0 ? process.env[cfg.baseUrlEnv] : void 0;
7978
7906
  const baseUrl = options.baseUrl ?? envBaseUrl ?? cfg.defaultBaseUrl;
7979
7907
  const fetchImpl = options.fetch ?? fetch;
7980
- const cache = options.cache ?? chunkJLMXKTBX_cjs.globalEmbeddingCache;
7908
+ const cache = options.cache ?? chunk2423XDPT_cjs.globalEmbeddingCache;
7981
7909
  const dimension = cfg.dimensionByModel[model];
7982
7910
  if (dimension === void 0) {
7983
- throw new chunkA44COQJJ_cjs.ConfigurationError(
7911
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
7984
7912
  `${cfg.id} adapter: model "${model}" is not in the dimension table. Use one of: ${Object.keys(cfg.dimensionByModel).join(", ")}. To add it, update dimensionByModel in the adapter source.`,
7985
7913
  { code: "embedding_unknown_model" }
7986
7914
  );
@@ -8051,7 +7979,7 @@ async function embedInBoundedBatches(input, pending, results) {
8051
7979
  for (let offset = 0; offset < pending.length; offset += MAX_BATCH) {
8052
7980
  batches.push(pending.slice(offset, offset + MAX_BATCH));
8053
7981
  }
8054
- await chunkGIW4L6HY_cjs.mapWithConcurrency(
7982
+ await chunkSWIBQFPH_cjs.mapWithConcurrency(
8055
7983
  batches,
8056
7984
  MAX_CONCURRENT_BATCHES,
8057
7985
  (batch) => processBatch(input, batch, results)
@@ -8096,7 +8024,7 @@ async function embedBatch(opts) {
8096
8024
  body = JSON.parse(text);
8097
8025
  } catch {
8098
8026
  }
8099
- throw chunkWEHUJ7ZS_cjs.mapOpenAICompatibleError({
8027
+ throw chunkALU3KC4G_cjs.mapOpenAICompatibleError({
8100
8028
  providerId: opts.providerId,
8101
8029
  status: response.status,
8102
8030
  body,
@@ -8118,7 +8046,7 @@ async function postEmbedRequest(opts, url) {
8118
8046
  async function parseEmbedResponse(response, providerId, endpoint) {
8119
8047
  const json = await response.json();
8120
8048
  if (!Array.isArray(json.data)) {
8121
- throw new chunkA44COQJJ_cjs.NetworkError(`${providerId} ${endpoint} returned no data`, {
8049
+ throw new chunkMHCKWQR3_cjs.NetworkError(`${providerId} ${endpoint} returned no data`, {
8122
8050
  code: "embedding_invalid_response",
8123
8051
  metadata: {
8124
8052
  provider: providerId,
@@ -8516,7 +8444,7 @@ function createMemorySearchTool(opts) {
8516
8444
  };
8517
8445
  }
8518
8446
  function createMemoryGetTool(opts) {
8519
- const memoryRoot = path.resolve(chunkJLMXKTBX_cjs.memoryDir(opts.cwd));
8447
+ const memoryRoot = path.resolve(chunk2423XDPT_cjs.memoryDir(opts.cwd));
8520
8448
  return {
8521
8449
  name: "memory_get",
8522
8450
  description: GET_DESCRIPTION,
@@ -8527,7 +8455,7 @@ function createMemoryGetTool(opts) {
8527
8455
  const lines = readNumber(input.lines);
8528
8456
  const resolved = path.resolve(memoryRoot, relPath);
8529
8457
  if (!isPathInside(memoryRoot, resolved)) {
8530
- throw new chunkA44COQJJ_cjs.ConfigurationError(
8458
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
8531
8459
  `memory_get rejected path that escapes memory root: ${relPath}`,
8532
8460
  { code: "memory_path_escapes_root" }
8533
8461
  );
@@ -8547,7 +8475,7 @@ function readString(value, errorIfMissing, allowUndefined = false) {
8547
8475
  if (typeof value === "string") return value;
8548
8476
  if (allowUndefined && (value === void 0 || value === null)) return "";
8549
8477
  if (errorIfMissing !== void 0) {
8550
- throw new chunkA44COQJJ_cjs.ConfigurationError(errorIfMissing, { code: "memory_tool_bad_args" });
8478
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(errorIfMissing, { code: "memory_tool_bad_args" });
8551
8479
  }
8552
8480
  return "";
8553
8481
  }
@@ -8623,7 +8551,7 @@ var LocalAgentMemory = class {
8623
8551
  const openOpts = { cwd: this.workspaceCwd };
8624
8552
  if (embedding !== void 0) openOpts.embedding = embedding;
8625
8553
  if (cfg?.backend !== void 0) openOpts.backend = cfg.backend;
8626
- this.index = await chunkJLMXKTBX_cjs.IndexManager.open(openOpts);
8554
+ this.index = await chunk2423XDPT_cjs.IndexManager.open(openOpts);
8627
8555
  await this.index.sync();
8628
8556
  this.toolsCache = [
8629
8557
  createMemorySearchTool({ index: this.index }),
@@ -8638,7 +8566,7 @@ var LocalAgentMemory = class {
8638
8566
  const warned2 = g[sym];
8639
8567
  if (!warned2.has(message)) {
8640
8568
  warned2.add(message);
8641
- process.stderr.write(`[theokit-sdk] memory tools unavailable: ${message}
8569
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] memory tools unavailable: ${message}
8642
8570
  `);
8643
8571
  }
8644
8572
  return void 0;
@@ -8647,7 +8575,7 @@ var LocalAgentMemory = class {
8647
8575
  async runActiveMemoryIfEnabled(userText, priorMessages, telemetry) {
8648
8576
  const cfg = this.options.memory?.activeRecall;
8649
8577
  if (cfg?.enabled !== true || this.index === void 0) return void 0;
8650
- if (this.breaker === void 0) this.breaker = new chunkWEHUJ7ZS_cjs.CircuitBreaker();
8578
+ if (this.breaker === void 0) this.breaker = new chunkALU3KC4G_cjs.CircuitBreaker();
8651
8579
  if (this.cache === void 0) this.cache = new ActiveMemoryCache();
8652
8580
  const result = await runActiveMemory({
8653
8581
  userText,
@@ -8697,7 +8625,7 @@ var LocalAgentMemory = class {
8697
8625
  await this.index.sync();
8698
8626
  } catch (cause) {
8699
8627
  const message = cause instanceof Error ? cause.message : String(cause);
8700
- process.stderr.write(`[theokit-sdk] session index sync failed: ${message}
8628
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] session index sync failed: ${message}
8701
8629
  `);
8702
8630
  }
8703
8631
  }
@@ -8710,10 +8638,8 @@ var LocalAgentMemory = class {
8710
8638
  return await adapter.create(cfg.model !== void 0 ? { model: cfg.model } : {});
8711
8639
  } catch (cause) {
8712
8640
  const message = cause instanceof Error ? cause.message : String(cause);
8713
- process.stderr.write(
8714
- `[theokit-sdk] memory embedding ${cfg.provider} unavailable: ${message}
8715
- `
8716
- );
8641
+ chunkLTCOPATU_cjs.diag(`[theokit-sdk] memory embedding ${cfg.provider} unavailable: ${message}
8642
+ `);
8717
8643
  return void 0;
8718
8644
  }
8719
8645
  }
@@ -8748,7 +8674,7 @@ function buildAgentMemory(pluginManager, workspaceCwd, defaultContext) {
8748
8674
  ...partial?.metadata !== void 0 ? { metadata: partial.metadata } : defaultContext?.metadata !== void 0 ? { metadata: defaultContext.metadata } : {}
8749
8675
  };
8750
8676
  if (merged.userId === "") {
8751
- throw new chunkA44COQJJ_cjs.ConfigurationError(
8677
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
8752
8678
  "agent.memory requires a userId \u2014 either set AgentOptions.memoryContext.userId or pass ctx.userId at call time.",
8753
8679
  { code: "memory_context_missing_user_id" }
8754
8680
  );
@@ -8758,7 +8684,7 @@ function buildAgentMemory(pluginManager, workspaceCwd, defaultContext) {
8758
8684
  async function requireAdapters() {
8759
8685
  const r = await ensure();
8760
8686
  if (r.adapters.length === 0) {
8761
- throw new chunkA44COQJJ_cjs.ConfigurationError(
8687
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
8762
8688
  "No memory adapter registered. Pass a memory plugin in AgentOptions.plugins (e.g. supermemoryMemory({...})).",
8763
8689
  { code: "no_memory_adapter" }
8764
8690
  );
@@ -8799,7 +8725,7 @@ function buildAgentMemory(pluginManager, workspaceCwd, defaultContext) {
8799
8725
  const prefix = id.split(":", 1)[0] ?? "";
8800
8726
  const target = adapters.find((a) => a.id === prefix);
8801
8727
  if (target === void 0) {
8802
- throw new chunkA44COQJJ_cjs.ConfigurationError(
8728
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
8803
8729
  `No adapter found for MemoryId prefix "${prefix}" (registered: ${adapters.map((a) => a.id).join(", ")}).`,
8804
8730
  { code: "no_memory_adapter" }
8805
8731
  );
@@ -8872,7 +8798,7 @@ function createLocalAgentMemoryProvider(opts) {
8872
8798
  return { facts: [], systemPromptAdditions: summary };
8873
8799
  },
8874
8800
  async recordSessionSummary(args) {
8875
- await chunkJLMXKTBX_cjs.writeSessionSummary(args);
8801
+ await chunk2423XDPT_cjs.writeSessionSummary(args);
8876
8802
  },
8877
8803
  async sync(handle) {
8878
8804
  const state = handle[INTERNAL_LAM_KEY];
@@ -8950,19 +8876,19 @@ var PersonalityRegistry = class _PersonalityRegistry {
8950
8876
  function addEntity(byName, entity, origin, collisionMap) {
8951
8877
  const fm = entity.frontmatter;
8952
8878
  if (PersonalityRegistry.isReservedClearSlug(fm.name)) {
8953
- throw new chunkA44COQJJ_cjs.ConfigurationError(
8879
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
8954
8880
  `Personality name "${fm.name}" is reserved (used to clear active preset)`,
8955
8881
  { code: "personality_reserved_name" }
8956
8882
  );
8957
8883
  }
8958
8884
  if (entity.body.trim().length === 0) {
8959
- throw new chunkA44COQJJ_cjs.ConfigurationError(
8885
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
8960
8886
  `Personality "${fm.name}" has empty body (system prompt required)`,
8961
8887
  { code: "personality_empty_body" }
8962
8888
  );
8963
8889
  }
8964
8890
  if (origin === "project" && collisionMap?.has(fm.name)) {
8965
- chunkN24XBYNX_cjs.warnOnce(
8891
+ chunkFAY3QDGC_cjs.warnOnce(
8966
8892
  `personality-collision-${fm.name}`,
8967
8893
  `[theokit-sdk] personality "${fm.name}" overridden by project preset`
8968
8894
  );
@@ -8991,7 +8917,7 @@ async function performPersonalitySwitch(args) {
8991
8917
  const preset = args.registry.get(args.requestedName);
8992
8918
  if (preset === void 0) {
8993
8919
  const available = args.registry.all().map((p) => p.name).join(", ") || "(none)";
8994
- throw new chunkA44COQJJ_cjs.ConfigurationError(
8920
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
8995
8921
  `Personality "${args.requestedName}" not found. Available: ${available}`,
8996
8922
  { code: "personality_not_found" }
8997
8923
  );
@@ -9012,14 +8938,14 @@ async function performPersonalitySwitch(args) {
9012
8938
 
9013
8939
  // src/internal/local-agent/local-agent-personality-extensions.ts
9014
8940
  function resolveActivePersonalityPreset(args) {
9015
- const forkCtx = chunkN24XBYNX_cjs.currentPersonalityContext();
8941
+ const forkCtx = chunkFAY3QDGC_cjs.currentPersonalityContext();
9016
8942
  const slug = forkCtx !== void 0 ? forkCtx.slug : args.personalityStore.active(args.agentId);
9017
8943
  if (slug === void 0) return void 0;
9018
8944
  return args.personalityRegistry?.get(slug);
9019
8945
  }
9020
8946
  async function ensurePersonalityRegistryIfNeeded(args) {
9021
8947
  if (args.personalityRegistry !== void 0) return args.personalityRegistry;
9022
- const forkSlug = chunkN24XBYNX_cjs.currentPersonalityContext()?.slug;
8948
+ const forkSlug = chunkFAY3QDGC_cjs.currentPersonalityContext()?.slug;
9023
8949
  const ownSlug = args.personalityStore.active(args.agentId);
9024
8950
  if (forkSlug === void 0 && ownSlug === void 0) return void 0;
9025
8951
  return await PersonalityRegistry.load(args.workspaceCwd);
@@ -9033,8 +8959,8 @@ ${preset.systemPrompt}`;
9033
8959
  }
9034
8960
  async function localAgentUsePersonality(args) {
9035
8961
  if (args.disposed) throw new Error("Agent has been disposed");
9036
- if (chunkN24XBYNX_cjs.currentPersonalityContext() !== void 0) {
9037
- chunkN24XBYNX_cjs.warnPersonalitySwitchInsideFork(args.agentId);
8962
+ if (chunkFAY3QDGC_cjs.currentPersonalityContext() !== void 0) {
8963
+ chunkFAY3QDGC_cjs.warnPersonalitySwitchInsideFork(args.agentId);
9038
8964
  return null;
9039
8965
  }
9040
8966
  let registry = args.personalityRegistry;
@@ -9051,8 +8977,8 @@ async function localAgentUsePersonality(args) {
9051
8977
  registry,
9052
8978
  store: args.personalityStore,
9053
8979
  invalidateCache: (reason) => args.invalidateCache(reason),
9054
- appendSessionMessage: (msg) => chunkG4WI3VW2_cjs.appendSessionMessage(args.agentId, msg),
9055
- clearSession: () => chunkG4WI3VW2_cjs.clearSession(args.agentId),
8980
+ appendSessionMessage: (msg) => chunkH5YVJB4K_cjs.appendSessionMessage(args.agentId, msg),
8981
+ clearSession: () => chunkH5YVJB4K_cjs.clearSession(args.agentId),
9056
8982
  opts: args.opts ?? {}
9057
8983
  })
9058
8984
  );
@@ -9063,7 +8989,7 @@ function localAgentRunUntil(agent, goal, options) {
9063
8989
  async function* wrap() {
9064
8990
  const { runUntilImpl } = await import('./run-until-ZZ2JLPJM.cjs');
9065
8991
  const buildDeps = async () => {
9066
- const { judgeCallImpl } = await import('./judge-call-2FULQ6KL.cjs');
8992
+ const { judgeCallImpl } = await import('./judge-call-SP3G3X2Y.cjs');
9067
8993
  const { getAgentFacade } = await import('./agent-factory-registry-UU46BUMU.cjs');
9068
8994
  const create = getAgentFacade().create;
9069
8995
  return {
@@ -9096,7 +9022,7 @@ async function* localAgentStreamToCompletion(agent, message, options) {
9096
9022
  async function localAgentFork(parent, options) {
9097
9023
  const { forkAgentImpl } = await import('./fork-agent-Y2IK2RYU.cjs');
9098
9024
  const { getAgentFacade } = await import('./agent-factory-registry-UU46BUMU.cjs');
9099
- const { withPersonalityContext } = await import('./context-KNWVTZSY.cjs');
9025
+ const { withPersonalityContext } = await import('./context-ZV33V4DC.cjs');
9100
9026
  const create = getAgentFacade().create;
9101
9027
  return withPersonalityContext(
9102
9028
  { slug: parent.personalitySlugSnapshot, isFork: true },
@@ -9156,7 +9082,7 @@ function wrapRunWithCompletionCheck(args) {
9156
9082
  judgeOpts
9157
9083
  );
9158
9084
  const complete = !verdict.parseFailed && verdict.verdict === "done";
9159
- chunkMZ5ZRORA_cjs.emitRunEvent(args.onRunEvent, {
9085
+ chunk6EDQBX7U_cjs.emitRunEvent(args.onRunEvent, {
9160
9086
  type: "completion_check",
9161
9087
  complete,
9162
9088
  reason: verdict.reason
@@ -9297,7 +9223,7 @@ function wrapRunWithOutputProcessors(args) {
9297
9223
  if (result.status !== "finished" || result.result === void 0) return result;
9298
9224
  const res = await runOutputProcessors(args.processors, result.result, args.agentId);
9299
9225
  if (res.kind === "ok") return { ...result, result: res.value };
9300
- chunkMZ5ZRORA_cjs.emitRunEvent(args.onRunEvent, {
9226
+ chunk6EDQBX7U_cjs.emitRunEvent(args.onRunEvent, {
9301
9227
  type: "tripwire",
9302
9228
  reason: res.tripwire.reason,
9303
9229
  processorId: res.tripwire.processorId
@@ -9372,7 +9298,7 @@ async function applyInputProcessors(inputs, message, rawUserText, options, sendM
9372
9298
  }
9373
9299
  const res = await runInputProcessors(processors, rawUserText, inputs.agentId);
9374
9300
  if (res.kind === "tripwire") {
9375
- chunkMZ5ZRORA_cjs.emitRunEvent(options.onRunEvent, {
9301
+ chunk6EDQBX7U_cjs.emitRunEvent(options.onRunEvent, {
9376
9302
  type: "tripwire",
9377
9303
  reason: res.tripwire.reason,
9378
9304
  processorId: res.tripwire.processorId
@@ -9389,7 +9315,7 @@ async function applyInputProcessors(inputs, message, rawUserText, options, sendM
9389
9315
  return { userText: res.value, effectiveMessage };
9390
9316
  }
9391
9317
  async function executeSendLocked(inputs, message, options) {
9392
- if (inputs.disposed) throw new chunkA44COQJJ_cjs.AgentDisposedError(inputs.agentId);
9318
+ if (inputs.disposed) throw new chunkMHCKWQR3_cjs.AgentDisposedError(inputs.agentId);
9393
9319
  await consumePending(inputs.agentId, inputs.invalidationPending, inputs.clearInvalidation, inputs.reload);
9394
9320
  const sendModel = normalizeModel(options.model);
9395
9321
  inputs.applyModelOverride(sendModel);
@@ -9400,7 +9326,7 @@ async function executeSendLocked(inputs, message, options) {
9400
9326
  if (inputs.options.onBeforeSend !== void 0) {
9401
9327
  await inputs.options.onBeforeSend({
9402
9328
  conversationId: inputs.agentId,
9403
- previousMessageCount: chunkG4WI3VW2_cjs.getSessionMessages(inputs.agentId).length
9329
+ previousMessageCount: chunkH5YVJB4K_cjs.getSessionMessages(inputs.agentId).length
9404
9330
  });
9405
9331
  }
9406
9332
  await inputs.runPreHook(userText);
@@ -9412,8 +9338,8 @@ async function executeSendLocked(inputs, message, options) {
9412
9338
  userText,
9413
9339
  sendOptions: options
9414
9340
  });
9415
- const priorMessages = [...chunkG4WI3VW2_cjs.getSessionMessages(inputs.agentId)];
9416
- chunkG4WI3VW2_cjs.appendSessionMessage(inputs.agentId, { role: "user", text: userText });
9341
+ const priorMessages = [...chunkH5YVJB4K_cjs.getSessionMessages(inputs.agentId)];
9342
+ chunkH5YVJB4K_cjs.appendSessionMessage(inputs.agentId, { role: "user", text: userText });
9417
9343
  await persistMemoryFactIfWritePrompt(inputs.workspaceCwd, inputs.options.memory, userText);
9418
9344
  const memoryFacts = await readMemoryForSend(inputs.workspaceCwd, inputs.options.memory);
9419
9345
  const portPathActive = shouldUsePortMemoryPath();
@@ -9471,7 +9397,7 @@ async function executeSendLocked(inputs, message, options) {
9471
9397
  function buildCompletionCheckDeps() {
9472
9398
  return {
9473
9399
  judge: async (ctx, opts) => {
9474
- const { judgeCallImpl } = await import('./judge-call-2FULQ6KL.cjs');
9400
+ const { judgeCallImpl } = await import('./judge-call-SP3G3X2Y.cjs');
9475
9401
  const { getAgentFacade } = await import('./agent-factory-registry-UU46BUMU.cjs');
9476
9402
  return judgeCallImpl(ctx, opts, { create: getAgentFacade().create });
9477
9403
  }
@@ -9491,7 +9417,7 @@ function registerRunAsTask(run, agentId, taskOpt, userText) {
9491
9417
  promptPreview: userText.slice(0, 120),
9492
9418
  ...opts.meta ?? {}
9493
9419
  };
9494
- void chunkMZ5ZRORA_cjs.submit({
9420
+ void chunk6EDQBX7U_cjs.submit({
9495
9421
  kind: "run",
9496
9422
  work: async (ctx) => {
9497
9423
  ctx.signal.addEventListener(
@@ -9512,27 +9438,6 @@ function registerRunAsTask(run, agentId, taskOpt, userText) {
9512
9438
  }
9513
9439
 
9514
9440
  // src/internal/local-agent/local-agent.ts
9515
- async function adquirirLeaseSePossivel(store, agentId) {
9516
- const a = store.acquire;
9517
- if (typeof a !== "function") return;
9518
- try {
9519
- await a.call(store, agentId);
9520
- } catch (err) {
9521
- if (err instanceof Error && err.name === "SessionBusyError") throw err;
9522
- process.stderr.write(
9523
- `[theokit-sdk] writer lease unavailable for ${agentId} (${err instanceof Error ? err.message : String(err)}) \u2014 proceeding without single-writer protection
9524
- `
9525
- );
9526
- }
9527
- }
9528
- async function soltarLeaseSePossivel(store, agentId) {
9529
- const r = store.release;
9530
- if (typeof r === "function") await r.call(store, agentId);
9531
- }
9532
- async function disposeSessionStore(store) {
9533
- const d = store.dispose;
9534
- if (typeof d === "function") await d.call(store);
9535
- }
9536
9441
  var LocalAgent = class {
9537
9442
  agentId;
9538
9443
  model;
@@ -9596,7 +9501,7 @@ var LocalAgent = class {
9596
9501
  this.options = options;
9597
9502
  this.workspaceCwd = resolveCwd(options.local?.cwd);
9598
9503
  this.transcriptBaseDir = resolveBaseDir(options.local?.baseDir);
9599
- this.sessionStore = options.local?.sessionStore ?? new chunkAIDNODHJ_cjs.FsSessionStore({ baseDir: this.transcriptBaseDir, cwd: this.workspaceCwd });
9504
+ this.sessionStore = options.local?.sessionStore ?? new chunkITLS5LRF_cjs.FsSessionStore({ baseDir: this.transcriptBaseDir, cwd: this.workspaceCwd });
9600
9505
  this.settingSourcesIncludeProject = includesSetting(options, "project");
9601
9506
  this.settingSourcesIncludePlugins = includesSetting(options, "plugins");
9602
9507
  const sub = bootstrapSubmanagers({
@@ -9639,14 +9544,14 @@ var LocalAgent = class {
9639
9544
  if (this.pluginsManager !== void 0) await this.pluginsManager.initialize();
9640
9545
  const codePlugins = chunkBV2MWEMV_cjs.extractCodePlugins(this.options.plugins);
9641
9546
  await this.pluginManagerCode.initialize(codePlugins);
9642
- this.resolvedSubagents = await chunkRZQ6E5YZ_cjs.loadSubagents(
9547
+ this.resolvedSubagents = await chunkGM7QDQ24_cjs.loadSubagents(
9643
9548
  this.workspaceCwd,
9644
9549
  this.settingSourcesIncludeProject,
9645
9550
  this.options.agents
9646
9551
  );
9647
9552
  await adquirirLeaseSePossivel(this.sessionStore, this.agentId);
9648
9553
  try {
9649
- await chunkG4WI3VW2_cjs.hydrateSession(this.agentId, { store: this.sessionStore, cwd: this.workspaceCwd });
9554
+ await chunkH5YVJB4K_cjs.hydrateSession(this.agentId, { store: this.sessionStore, cwd: this.workspaceCwd });
9650
9555
  await this.personalityStore.hydrate(this.agentId);
9651
9556
  } catch (err) {
9652
9557
  await soltarLeaseSePossivel(this.sessionStore, this.agentId);
@@ -9795,7 +9700,7 @@ var LocalAgent = class {
9795
9700
  agentId: this.agentId
9796
9701
  });
9797
9702
  if (preRun.blocked) {
9798
- throw new chunkA44COQJJ_cjs.ConfigurationError(
9703
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
9799
9704
  `preRun hook denied execution: ${preRun.reason ?? "unspecified"}`,
9800
9705
  { code: "hook_denied" }
9801
9706
  );
@@ -9827,26 +9732,12 @@ var LocalAgent = class {
9827
9732
  this.disposed = true;
9828
9733
  }
9829
9734
  async reload() {
9830
- if (this.context !== void 0) await this.context.refresh();
9831
- if (this.skillsManager !== void 0) await this.skillsManager.refresh();
9832
- if (this.pluginsManager !== void 0) await this.pluginsManager.refresh();
9833
- this.resolvedSubagents = await chunkRZQ6E5YZ_cjs.loadSubagents(
9834
- this.workspaceCwd,
9835
- this.settingSourcesIncludeProject,
9836
- this.options.agents
9837
- );
9735
+ this.resolvedSubagents = await reloadLocalAgent(this);
9838
9736
  }
9839
9737
  async dispose() {
9840
9738
  if (this.disposed) return;
9841
9739
  this.disposed = true;
9842
- liveAgentRegistry.forget(this.agentId);
9843
- this.lifecycleAbortController.abort();
9844
- await chunkYLQQX5W2_cjs.withCwdMutex(`agent-send:${this.agentId}`, () => Promise.resolve());
9845
- disposeSessionMcpClients(this.agentId);
9846
- await chunkG4WI3VW2_cjs.flushSessionWrites();
9847
- await flushRegistrySaves(this.workspaceCwd);
9848
- await disposeSessionStore(this.sessionStore);
9849
- chunkG4WI3VW2_cjs.descartarSessao(this.workspaceCwd, this.agentId);
9740
+ await disposeLocalAgentSession(this);
9850
9741
  }
9851
9742
  [Symbol.asyncDispose]() {
9852
9743
  return this.dispose();
@@ -9890,7 +9781,7 @@ var LocalAgent = class {
9890
9781
  }
9891
9782
  // biome-ignore format: G8 budget — see listArtifacts.
9892
9783
  downloadArtifact(_path) {
9893
- return Promise.reject(new chunkA44COQJJ_cjs.UnsupportedRunOperationError("Artifacts are not supported for local agents", "downloadArtifact"));
9784
+ return Promise.reject(new chunkMHCKWQR3_cjs.UnsupportedRunOperationError("Artifacts are not supported for local agents", "downloadArtifact"));
9894
9785
  }
9895
9786
  // biome-ignore format: G8 budget — delegates to `local-agent-runtime-extensions.ts`; kept 1-line.
9896
9787
  runUntil(goal, options) {
@@ -9913,7 +9804,7 @@ function resolveCwd(cwd) {
9913
9804
  return (Array.isArray(cwd) ? cwd[0] : cwd) ?? process.cwd();
9914
9805
  }
9915
9806
  function resolveBaseDir(baseDir) {
9916
- return baseDir === void 0 ? chunk2DYI7MIF_cjs.defaultBaseDir() : chunk2DYI7MIF_cjs.expandTilde(baseDir);
9807
+ return baseDir === void 0 ? chunkIEUDKUPM_cjs.defaultBaseDir() : chunkIEUDKUPM_cjs.expandTilde(baseDir);
9917
9808
  }
9918
9809
  function includesSetting(options, source) {
9919
9810
  const sources = options.local?.settingSources;
@@ -9938,7 +9829,7 @@ async function guardAgainstIdCollision(options) {
9938
9829
  const persistenceCwd = resolveAgentPersistenceCwd(options);
9939
9830
  await hydrateRegistryFromDisk(persistenceCwd);
9940
9831
  if (getRegisteredAgent(options.agentId) !== void 0) {
9941
- throw new chunkA44COQJJ_cjs.ConfigurationError(
9832
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
9942
9833
  `Agent "${options.agentId}" already exists. Use Agent.resume("${options.agentId}") to reattach, or pick a different agentId.`,
9943
9834
  { code: "agent_id_already_exists" }
9944
9835
  );
@@ -9971,7 +9862,7 @@ async function maybeInjectHandoffTools(options) {
9971
9862
  const spec = "@theokit/sdk-handoff/internal/tool-injector";
9972
9863
  mod = await import(spec);
9973
9864
  } catch (err) {
9974
- throw new chunkA44COQJJ_cjs.ConfigurationError(
9865
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
9975
9866
  "Agent.create({ handoffs: [...] }) requires @theokit/sdk-handoff. Install it: pnpm add @theokit/sdk-handoff. Or migrate to the preferred plugin pattern: plugins: [Handoff.asPlugin({ targets: [...] })] (see docs/migration/1-x-to-2-0.md#handoff).",
9976
9867
  { code: "handoff_package_missing", cause: err }
9977
9868
  );
@@ -9991,9 +9882,9 @@ async function maybeInjectHandoffTools(options) {
9991
9882
  async function createLocalAgent(options) {
9992
9883
  const apiKey = resolveApiKey(options.apiKey);
9993
9884
  if (apiKey === void 0) {
9994
- throw new chunkA44COQJJ_cjs.AuthenticationError("Missing API key", { code: "missing_api_key" });
9885
+ throw new chunkMHCKWQR3_cjs.AuthenticationError("Missing API key", { code: "missing_api_key" });
9995
9886
  }
9996
- const willFlowToProvider = !isFixtureApiKey(apiKey) && !shouldUseRealLocalRuntime(apiKey);
9887
+ const willFlowToProvider = !chunkALU3KC4G_cjs.isFixtureApiKey(apiKey) && !chunkALU3KC4G_cjs.shouldUseRealLocalRuntime(apiKey);
9997
9888
  const shape = validateApiKeyShape(apiKey, {
9998
9889
  strict: willFlowToProvider,
9999
9890
  // `options.model` is already normalized by `runCreateUnderSpan`; `normalizeModel`
@@ -10002,10 +9893,10 @@ async function createLocalAgent(options) {
10002
9893
  ...willFlowToProvider ? { provider: providerFromModelId(normalizeModel(options.model)?.id) } : {}
10003
9894
  });
10004
9895
  if (shape.malformed) {
10005
- throw new chunkA44COQJJ_cjs.AuthenticationError(shape.message, { code: "malformed_api_key" });
9896
+ throw new chunkMHCKWQR3_cjs.AuthenticationError(shape.message, { code: "malformed_api_key" });
10006
9897
  }
10007
- if (!isFixtureApiKey(apiKey) && getConfiguredBaseUrl() === void 0 && !shouldUseRealLocalRuntime(apiKey)) {
10008
- throw new chunkA44COQJJ_cjs.AuthenticationError("Invalid API key", {
9898
+ if (!chunkALU3KC4G_cjs.isFixtureApiKey(apiKey) && chunkALU3KC4G_cjs.getConfiguredBaseUrl() === void 0 && !chunkALU3KC4G_cjs.shouldUseRealLocalRuntime(apiKey)) {
9899
+ throw new chunkMHCKWQR3_cjs.AuthenticationError("Invalid API key", {
10009
9900
  code: "authentication_error"
10010
9901
  });
10011
9902
  }
@@ -10016,19 +9907,19 @@ async function createLocalAgent(options) {
10016
9907
  async function createCloudAgent(options) {
10017
9908
  const apiKey = resolveApiKey(options.apiKey);
10018
9909
  if (apiKey === void 0) {
10019
- throw new chunkA44COQJJ_cjs.ConfigurationError("Missing API key for cloud agent", {
9910
+ throw new chunkMHCKWQR3_cjs.ConfigurationError("Missing API key for cloud agent", {
10020
9911
  code: "missing_api_key"
10021
9912
  });
10022
9913
  }
10023
9914
  const shape = validateApiKeyShape(apiKey);
10024
9915
  if (shape.malformed) {
10025
- throw new chunkA44COQJJ_cjs.AuthenticationError(shape.message, { code: "malformed_api_key" });
9916
+ throw new chunkMHCKWQR3_cjs.AuthenticationError(shape.message, { code: "malformed_api_key" });
10026
9917
  }
10027
- const baseUrl = getConfiguredBaseUrl();
9918
+ const baseUrl = chunkALU3KC4G_cjs.getConfiguredBaseUrl();
10028
9919
  if (baseUrl === void 0) {
10029
9920
  return new CloudAgent(options);
10030
9921
  }
10031
- const response = await httpRequest("/v1/agents", {
9922
+ const response = await chunkALU3KC4G_cjs.httpRequest("/v1/agents", {
10032
9923
  apiKey,
10033
9924
  method: "POST",
10034
9925
  body: {
@@ -10053,7 +9944,7 @@ function resolveAgentPersistenceCwd(options) {
10053
9944
  return process.cwd();
10054
9945
  }
10055
9946
  async function rehydrateExistingAgent(agentId, existing, options) {
10056
- await chunkWEHUJ7ZS_cjs.discoverProviderPlugins();
9947
+ await chunkALU3KC4G_cjs.discoverProviderPlugins();
10057
9948
  await validateRehydratedAgent(agentId, existing);
10058
9949
  const mergedLocal = options.local !== void 0 && existing.options.local !== void 0 ? { ...existing.options.local, ...options.local } : options.local ?? existing.options.local;
10059
9950
  const mergedOptions = {
@@ -10084,7 +9975,7 @@ async function validateRehydratedAgent(agentId, entry) {
10084
9975
  throw new Error(`Workspace path is not a directory: ${candidate}`);
10085
9976
  }
10086
9977
  } catch (cause) {
10087
- throw new chunkA44COQJJ_cjs.UnknownAgentError(
9978
+ throw new chunkMHCKWQR3_cjs.UnknownAgentError(
10088
9979
  `Agent "${agentId}" cannot be rehydrated \u2014 workspace cwd "${candidate}" is missing or inaccessible.`,
10089
9980
  { code: "agent_rehydration_failed", cause }
10090
9981
  );
@@ -10136,7 +10027,7 @@ async function getRegisteredAgentOrThrow(agentId) {
10136
10027
  agent = getRegisteredAgent(agentId);
10137
10028
  }
10138
10029
  if (agent === void 0) {
10139
- throw new chunkA44COQJJ_cjs.UnknownAgentError(`Agent ${agentId} not found`, { code: "unknown_agent" });
10030
+ throw new chunkMHCKWQR3_cjs.UnknownAgentError(`Agent ${agentId} not found`, { code: "unknown_agent" });
10140
10031
  }
10141
10032
  return agent;
10142
10033
  }
@@ -10181,7 +10072,7 @@ var Agent = class _Agent {
10181
10072
  pluginCount: enabledPluginNames(options.plugins).length
10182
10073
  });
10183
10074
  try {
10184
- await chunkWEHUJ7ZS_cjs.discoverProviderPlugins();
10075
+ await chunkALU3KC4G_cjs.discoverProviderPlugins();
10185
10076
  const agent = await runCreateUnderSpan(options, span);
10186
10077
  return agent;
10187
10078
  } catch (err) {
@@ -10207,8 +10098,8 @@ var Agent = class _Agent {
10207
10098
  const run = await agent.send(message);
10208
10099
  const result = await run.wait();
10209
10100
  if (options.throwOnError === true && result.status === "error" && result.error !== void 0) {
10210
- throw new chunkA44COQJJ_cjs.AgentRunError(result.error.message, {
10211
- code: chunkA44COQJJ_cjs.coerceToKnownAgentRunErrorCode(result.error.code),
10101
+ throw new chunkMHCKWQR3_cjs.AgentRunError(result.error.message, {
10102
+ code: chunkMHCKWQR3_cjs.coerceToKnownAgentRunErrorCode(result.error.code),
10212
10103
  cause: result.error.cause
10213
10104
  });
10214
10105
  }
@@ -10235,7 +10126,7 @@ var Agent = class _Agent {
10235
10126
  if (existing !== void 0) {
10236
10127
  return await rehydrateExistingAgent(agentId, existing, options);
10237
10128
  }
10238
- throw new chunkA44COQJJ_cjs.UnknownAgentError(
10129
+ throw new chunkMHCKWQR3_cjs.UnknownAgentError(
10239
10130
  `Agent "${agentId}" not found. Use Agent.create({ agentId, ... }) for first-time setup, or catch UnknownAgentError to branch resume-vs-create.`,
10240
10131
  { code: "unknown_agent" }
10241
10132
  );
@@ -10264,7 +10155,7 @@ var Agent = class _Agent {
10264
10155
  * @public
10265
10156
  */
10266
10157
  static async generateObject(options) {
10267
- const { generateObjectImpl } = await import('./generate-object-H3RNAM6S.cjs');
10158
+ const { generateObjectImpl } = await import('./generate-object-5SCEH2EE.cjs');
10268
10159
  return generateObjectImpl(options, {
10269
10160
  create: (opts) => _Agent.create(opts),
10270
10161
  delete: (agentId) => _Agent.delete(agentId)
@@ -10288,7 +10179,7 @@ var Agent = class _Agent {
10288
10179
  delete: (agentId) => _Agent.delete(agentId)
10289
10180
  };
10290
10181
  async function* wrapper() {
10291
- streamObjectImport ??= import('./stream-object-QEQJJDTI.cjs');
10182
+ streamObjectImport ??= import('./stream-object-Y7YCX3BI.cjs');
10292
10183
  const { streamObjectImpl } = await streamObjectImport;
10293
10184
  yield* streamObjectImpl(options, deps);
10294
10185
  }
@@ -10312,7 +10203,7 @@ var Agent = class _Agent {
10312
10203
  * @public
10313
10204
  */
10314
10205
  static async batch(prompts, options) {
10315
- const { batchImpl } = await import('./batch-2FSD2UNL.cjs');
10206
+ const { batchImpl } = await import('./batch-3SEPDXCU.cjs');
10316
10207
  return batchImpl(prompts, options, { create: (opts) => _Agent.create(opts) });
10317
10208
  }
10318
10209
  /**
@@ -10356,15 +10247,15 @@ var Agent = class _Agent {
10356
10247
  return fresh;
10357
10248
  }
10358
10249
  /**
10359
- * List agents (local or cloud).
10250
+ * List agents (local or cloud). M107 — `cwd` is READ now, not ignored;
10251
+ * `limit`/`cursor` still are not (see `tests/agent-list-cwd.test.ts`).
10360
10252
  *
10361
10253
  * @public
10362
10254
  */
10363
10255
  static async list(options = {}) {
10364
- await hydrateRegistryFromDisk(process.cwd());
10365
- const runtime = options.runtime;
10366
- const all = listRegisteredAgents(runtime);
10367
- const items = all.map((agent) => toAgentInfo(agent));
10256
+ const cwd = ("cwd" in options ? options.cwd : void 0) ?? process.cwd();
10257
+ await hydrateRegistryFromDisk(cwd);
10258
+ const items = listRegisteredAgents(options.runtime, cwd).map((agent) => toAgentInfo(agent));
10368
10259
  return { items };
10369
10260
  }
10370
10261
  /**
@@ -10392,14 +10283,14 @@ var Agent = class _Agent {
10392
10283
  */
10393
10284
  static async getRun(runId, options = {}) {
10394
10285
  if (options.runtime === "cloud") {
10395
- throw new chunkA44COQJJ_cjs.ConfigurationError(
10286
+ throw new chunkMHCKWQR3_cjs.ConfigurationError(
10396
10287
  "Cloud runtime is pre-release. Theo PaaS endpoints are not wired yet \u2014 getRun({ runtime: 'cloud' }) will be enabled when the PaaS ships.",
10397
10288
  { code: "cloud_runtime_pre_release" }
10398
10289
  );
10399
10290
  }
10400
10291
  const existing = getRun(runId);
10401
10292
  if (existing !== void 0) return existing;
10402
- throw new chunkA44COQJJ_cjs.UnknownAgentError(
10293
+ throw new chunkMHCKWQR3_cjs.UnknownAgentError(
10403
10294
  `Run ${runId} is not in this process's registry. It may have been disposed, persisted in a previous process, or never created.`,
10404
10295
  { code: "run_not_found" }
10405
10296
  );
@@ -10446,13 +10337,13 @@ var Agent = class _Agent {
10446
10337
  reg = getRegisteredAgent(agentId);
10447
10338
  }
10448
10339
  if (reg === void 0 || reg.runtime !== "local") {
10449
- throw new chunkA44COQJJ_cjs.UnknownAgentError(
10340
+ throw new chunkMHCKWQR3_cjs.UnknownAgentError(
10450
10341
  `No local agent "${agentId}" registered \u2014 compact targets local sessions.`
10451
10342
  );
10452
10343
  }
10453
- const { compactSessionTranscript, buildDefaultSummarizer: buildDefaultSummarizer2 } = await import('./compact-session-BEA3IOON.cjs');
10344
+ const { compactSessionTranscript, buildDefaultSummarizer: buildDefaultSummarizer2 } = await import('./compact-session-H5TKLD55.cjs');
10454
10345
  const { cwd, model, store } = await abrirStoreLocal(reg);
10455
- return chunkG4WI3VW2_cjs.enqueueSessionWrite(
10346
+ return chunkH5YVJB4K_cjs.enqueueSessionWrite(
10456
10347
  cwd,
10457
10348
  agentId,
10458
10349
  () => compactSessionTranscript({
@@ -10482,11 +10373,11 @@ var Agent = class _Agent {
10482
10373
  reg = getRegisteredAgent(agentId);
10483
10374
  }
10484
10375
  if (reg === void 0 || reg.runtime !== "local") {
10485
- throw new chunkA44COQJJ_cjs.UnknownAgentError(
10376
+ throw new chunkMHCKWQR3_cjs.UnknownAgentError(
10486
10377
  `No local agent "${agentId}" registered \u2014 injectSessionTurn targets local sessions.`
10487
10378
  );
10488
10379
  }
10489
- const { injectSessionTurn } = await import('./inject-session-SMH56NXP.cjs');
10380
+ const { injectSessionTurn } = await import('./inject-session-DM4SKTZO.cjs');
10490
10381
  const { cwd, model, store } = await abrirStoreLocal(reg);
10491
10382
  await injectSessionTurn({
10492
10383
  store,
@@ -10510,12 +10401,12 @@ async function getOrCreateUncached(agentId, options) {
10510
10401
  try {
10511
10402
  return await Agent.resume(agentId, options);
10512
10403
  } catch (err) {
10513
- if (!(err instanceof chunkA44COQJJ_cjs.UnknownAgentError)) throw err;
10404
+ if (!(err instanceof chunkMHCKWQR3_cjs.UnknownAgentError)) throw err;
10514
10405
  }
10515
10406
  try {
10516
10407
  return await Agent.create({ ...options, agentId });
10517
10408
  } catch (err) {
10518
- if (err instanceof chunkA44COQJJ_cjs.ConfigurationError && err.code === "agent_id_already_exists") {
10409
+ if (err instanceof chunkMHCKWQR3_cjs.ConfigurationError && err.code === "agent_id_already_exists") {
10519
10410
  return await Agent.resume(agentId, options);
10520
10411
  }
10521
10412
  throw err;
@@ -10533,8 +10424,8 @@ async function abrirStoreLocal(reg) {
10533
10424
  const cwd = reg.cwd ?? process.cwd();
10534
10425
  const optModel = reg.options.model;
10535
10426
  const model = reg.model?.id ?? (typeof optModel === "string" ? optModel : optModel?.id) ?? "unknown";
10536
- const { FsSessionStore: FsSessionStore2 } = await import('./fs-session-store-IQYE35HX.cjs');
10537
- const { defaultBaseDir: defaultBaseDir2, expandTilde: expandTilde2 } = await import('./session-transcript-JXFMPLOT.cjs');
10427
+ const { FsSessionStore: FsSessionStore2 } = await import('./fs-session-store-7E7UPLF2.cjs');
10428
+ const { defaultBaseDir: defaultBaseDir2, expandTilde: expandTilde2 } = await import('./session-transcript-EAKR4D2W.cjs');
10538
10429
  const baseDir = reg.options.local?.baseDir !== void 0 ? expandTilde2(reg.options.local.baseDir) : defaultBaseDir2();
10539
10430
  return { cwd, model, store: new FsSessionStore2({ baseDir, cwd }) };
10540
10431
  }
@@ -10549,10 +10440,7 @@ exports.UsageAccumulator = UsageAccumulator;
10549
10440
  exports.computeCost = computeCost;
10550
10441
  exports.generateCronId = generateCronId;
10551
10442
  exports.getPricingEntry = getPricingEntry;
10552
- exports.httpRequest = httpRequest;
10553
- exports.isFixtureApiKey = isFixtureApiKey;
10554
10443
  exports.openRouterMemoryEmbeddingProviderAdapter = openRouterMemoryEmbeddingProviderAdapter;
10555
10444
  exports.resolveApiKey = resolveApiKey;
10556
- exports.shouldUseFixtureMode = shouldUseFixtureMode;
10557
- //# sourceMappingURL=chunk-3XJ7CS2C.cjs.map
10558
- //# sourceMappingURL=chunk-3XJ7CS2C.cjs.map
10445
+ //# sourceMappingURL=chunk-LMWXF4LL.cjs.map
10446
+ //# sourceMappingURL=chunk-LMWXF4LL.cjs.map