@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,39 +1,39 @@
1
1
  import { extractCodePlugins } from './chunk-2SFBB54R.js';
2
- import { submit, emitRunEvent } from './chunk-HRA3CPGG.js';
3
- import { enqueueSessionWrite, hydrateSession, flushSessionWrites, descartarSessao, persistTurnToTranscript, appendSessionMessage, getSessionMessages, clearSession } from './chunk-7BTE3RXJ.js';
4
- import { FsSessionStore } from './chunk-OKXUMCGM.js';
5
- import { discoverProviderPlugins, CircuitBreaker, buildDefaultSummarizer, parseSseStream, resolveProviderChain, inferProviderFromApiKey, detectPrimaryProvider, tryFirstEvent, relayStream, mapOpenAICompatibleError, renderToolResultContentText } from './chunk-IX2LKBCD.js';
6
- import { IndexManager, writeSessionSummary, memoryDir, globalEmbeddingCache, appendFact, readFacts, legacyMemoryJsonPath, memoryMdPath, appendFactToMarkdown } from './chunk-XAUBQMQU.js';
7
- import { loadHookConfig, warnOnce, currentPersonalityContext, warnPersonalitySwitchInsideFork } from './chunk-XIG2IE3L.js';
2
+ import { submit, emitRunEvent } from './chunk-HEN5WXXI.js';
3
+ import { enqueueSessionWrite, hydrateSession, persistTurnToTranscript, flushSessionWrites, appendSessionMessage, getSessionMessages, descartarSessao, clearSession } from './chunk-5SB4V74H.js';
4
+ import { FsSessionStore } from './chunk-YVTNFKZO.js';
5
+ import { discoverProviderPlugins, getConfiguredBaseUrl, httpRequest, isFixtureApiKey, shouldUseRealLocalRuntime, CircuitBreaker, buildDefaultSummarizer, parseSseStream, resolveProviderChain, inferProviderFromApiKey, detectPrimaryProvider, tryFirstEvent, relayStream, mapOpenAICompatibleError, renderToolResultContentText } from './chunk-GL7CFBVC.js';
6
+ import { IndexManager, writeSessionSummary, memoryDir, globalEmbeddingCache, appendFact, readFacts, legacyMemoryJsonPath, memoryMdPath, appendFactToMarkdown } from './chunk-DCJ5MCJ3.js';
7
+ import { loadHookConfig, warnOnce, currentPersonalityContext, warnPersonalitySwitchInsideFork } from './chunk-F6Y4IEQM.js';
8
8
  import { resolveChildEnv } from './chunk-7GFX45DD.js';
9
- import { readVersionedJson, getTheokitHome, writeVersionedJson } from './chunk-XV2RBL6D.js';
9
+ import { readVersionedJson, getTheokitHome, writeVersionedJson } from './chunk-ZW345YOI.js';
10
10
  import { sanitizeToolInput } from './chunk-U54XCYG3.js';
11
11
  import { subAgentToolsFromDefinitions, inheritSubAgentCredentials } from './chunk-FV3YEMQ7.js';
12
12
  import { setAgentFacade } from './chunk-6X6ID4MO.js';
13
13
  import { findGitRoot, DEFAULT_DISCOVERY_SPECS, walkUpForFile, walkUpForGlob } from './chunk-UJ7IQJAG.js';
14
14
  import { withToolWhitelist, checkToolWhitelist } from './chunk-7AD3ZTZL.js';
15
- import { mapWithConcurrency } from './chunk-V4XRLPEF.js';
16
- import { withFileLock } from './chunk-UAYYNWYJ.js';
15
+ import { mapWithConcurrency } from './chunk-QGDKZDPN.js';
16
+ import { withFileLock } from './chunk-YHZXBDAW.js';
17
17
  import { withCwdMutex } from './chunk-2XLKLVVR.js';
18
- import { defaultBaseDir, expandTilde } from './chunk-Q56IYTBZ.js';
18
+ import { defaultBaseDir, expandTilde } from './chunk-XAEAMI5H.js';
19
19
  import { toJsonSchema } from './chunk-4VPXM6UU.js';
20
- import { atomicWriteJson } from './chunk-S2BBRVQX.js';
21
- import { loadSubagents } from './chunk-BNIFFFH3.js';
22
- import { resolveEffectiveContextWindow, CONTEXT_WINDOW_FLOOR, CONTEXT_WINDOW_MARGIN } from './chunk-RKG6QFCJ.js';
20
+ import { atomicWriteJson } from './chunk-56OXYUZE.js';
21
+ import { loadSubagents } from './chunk-YCXMSDSP.js';
22
+ import { resolveEffectiveContextWindow, CONTEXT_WINDOW_FLOOR, CONTEXT_WINDOW_MARGIN } from './chunk-6VP3XGEK.js';
23
23
  import { parseModelId } from './chunk-X2FR4OIT.js';
24
- import { getCatalogModelInfo, registerBuiltins, getProviderProfile, registerProvider, isPatchedModelKey } from './chunk-KAP4GJHO.js';
25
- import { escapeBlockBody, buildSkillsBlock, discoverSkills, stripSkillFrontmatter } from './chunk-5IB2UKSN.js';
26
- import { validateArtifactPath, PathTraversalError, safePathJoin } from './chunk-POQT2OIF.js';
27
- import { readWorkspaceDir, parseSimpleYaml } from './chunk-FKCC2MED.js';
28
- import { AgentRunError, coerceToKnownAgentRunErrorCode, UnknownAgentError, ConfigurationError, AuthenticationError, UnsupportedRunOperationError, AgentDisposedError, NetworkError, IntegrationNotConnectedError, RateLimitError, TheokitAgentError } from './chunk-WLKFWQSJ.js';
29
- import { redactSecrets } from './chunk-JTFYYKDT.js';
24
+ import { getCatalogModelInfo, registerBuiltins, getProviderProfile, registerProvider, isPatchedModelKey } from './chunk-77WHPVXE.js';
25
+ import { escapeBlockBody, buildSkillsBlock, discoverSkills, stripSkillFrontmatter } from './chunk-2WFB5ZOX.js';
26
+ import { validateArtifactPath, PathTraversalError, safePathJoin } from './chunk-WDGCZDRG.js';
27
+ import { readWorkspaceDir, parseSimpleYaml } from './chunk-UQPDFW4E.js';
28
+ import { AgentRunError, coerceToKnownAgentRunErrorCode, UnknownAgentError, ConfigurationError, AuthenticationError, UnsupportedRunOperationError, AgentDisposedError, NetworkError, TheokitAgentError } from './chunk-CD73YHEH.js';
29
+ import { diag, redactSecrets } from './chunk-TAPQWDW2.js';
30
30
  import { stat, mkdir, readFile, readdir, access, unlink } from 'fs/promises';
31
31
  import { randomUUID, createHash } from 'crypto';
32
- import { existsSync } from 'fs';
33
32
  import { join, dirname, resolve, relative, isAbsolute } from 'path';
34
33
  import { spawn } from 'child_process';
35
34
  import { z } from 'zod';
36
35
  import { createRequire } from 'module';
36
+ import { existsSync } from 'fs';
37
37
  import { homedir } from 'os';
38
38
 
39
39
  // src/agent-builder.ts
@@ -221,7 +221,7 @@ async function agentGenerate(agent, agentModel, agentApiKey, agentLocal, input,
221
221
  const { output, maxRetries, errorStrategy, ...sendOptions } = options;
222
222
  const run = await agent.send(input, sendOptions);
223
223
  const result = await run.wait();
224
- const { generateObjectImpl, GenerateObjectError } = await import('./generate-object-YJPDV5BS.js');
224
+ const { generateObjectImpl, GenerateObjectError } = await import('./generate-object-I7UD4NWN.js');
225
225
  const answer = structurableAnswerOrThrow(result, GenerateObjectError);
226
226
  const { getAgentFacade } = await import('./agent-factory-registry-ZVTABLEY.js');
227
227
  const facade = getAgentFacade();
@@ -317,58 +317,6 @@ function generateRequestId() {
317
317
  function isLocalAgentId(id) {
318
318
  return id.startsWith(PREFIX.localAgent);
319
319
  }
320
- var FIXTURE_API_KEY_PREFIX = "theo_test_";
321
- function isFixtureApiKey(apiKey) {
322
- if (apiKey === void 0) return false;
323
- return apiKey.startsWith(FIXTURE_API_KEY_PREFIX);
324
- }
325
- function getConfiguredBaseUrl() {
326
- const value = process.env.THEOKIT_API_BASE_URL;
327
- if (value === void 0 || value.length === 0) return void 0;
328
- return value;
329
- }
330
- function shouldUseFixtureMode(apiKey) {
331
- if (getConfiguredBaseUrl() !== void 0) return false;
332
- return isFixtureApiKey(apiKey);
333
- }
334
- function shouldUseRealLocalRuntime(apiKey) {
335
- if (isFixtureApiKey(apiKey)) return false;
336
- if (apiKey === void 0 || apiKey.length === 0) return false;
337
- 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();
338
- }
339
- function isAwsBedrockAuthAvailable() {
340
- if (typeof process.env.AWS_BEARER_TOKEN_BEDROCK === "string" && process.env.AWS_BEARER_TOKEN_BEDROCK.length > 0) {
341
- return true;
342
- }
343
- if (typeof process.env.AWS_ACCESS_KEY_ID === "string" && process.env.AWS_ACCESS_KEY_ID.length > 0) {
344
- return true;
345
- }
346
- if (typeof process.env.AWS_PROFILE === "string" && process.env.AWS_PROFILE.length > 0) {
347
- return true;
348
- }
349
- return awsCredentialsFileExists();
350
- }
351
- function awsCredentialsFileExists() {
352
- try {
353
- const home = process.env.HOME ?? process.env.USERPROFILE;
354
- if (home === void 0 || home.length === 0) return false;
355
- return existsSync(`${home}/.aws/credentials`) || existsSync(`${home}/.aws/config`);
356
- } catch {
357
- return false;
358
- }
359
- }
360
- function isGcpVertexAuthAvailable() {
361
- if (typeof process.env.GOOGLE_APPLICATION_CREDENTIALS === "string" && process.env.GOOGLE_APPLICATION_CREDENTIALS.length > 0) {
362
- return true;
363
- }
364
- if (typeof process.env.GOOGLE_CLOUD_PROJECT === "string" && process.env.GOOGLE_CLOUD_PROJECT.length > 0) {
365
- return true;
366
- }
367
- return false;
368
- }
369
- function isLocalNoAuthProviderAvailable() {
370
- return true;
371
- }
372
320
 
373
321
  // src/internal/runtime/model-selection.ts
374
322
  function normalizeModel(m) {
@@ -574,7 +522,7 @@ function fromSerialized(entry) {
574
522
 
575
523
  // src/internal/runtime/registry/agent-registry.ts
576
524
  var agents = /* @__PURE__ */ new Map();
577
- var hydratedCwds = /* @__PURE__ */ new Set();
525
+ var hydrations = /* @__PURE__ */ new Map();
578
526
  var pendingSaves = /* @__PURE__ */ new Map();
579
527
  var dirtyCwds = /* @__PURE__ */ new Set();
580
528
  function resolveRegistryCwd(agent) {
@@ -602,7 +550,7 @@ function scheduleSaveForCwd(cwd) {
602
550
  }
603
551
  } catch (cause) {
604
552
  const msg = cause instanceof Error ? cause.message : String(cause);
605
- process.stderr.write(`[theokit-sdk] registry persist failed (${cwd}): ${msg}
553
+ diag(`[theokit-sdk] registry persist failed (${cwd}): ${msg}
606
554
  `);
607
555
  } finally {
608
556
  pendingSaves.delete(cwd);
@@ -618,10 +566,11 @@ function registerAgent(agent) {
618
566
  function getRegisteredAgent(agentId) {
619
567
  return agents.get(agentId);
620
568
  }
621
- function listRegisteredAgents(runtime) {
622
- const all = Array.from(agents.values());
623
- if (runtime === void 0) return all;
624
- return all.filter((agent) => agent.runtime === runtime);
569
+ function listRegisteredAgents(runtime, cwd) {
570
+ let out = Array.from(agents.values());
571
+ if (runtime !== void 0) out = out.filter((agent) => agent.runtime === runtime);
572
+ if (cwd !== void 0) out = out.filter((agent) => resolveRegistryCwd(agent) === cwd);
573
+ return out;
625
574
  }
626
575
  function updateRegisteredAgent(agentId, update) {
627
576
  const existing = agents.get(agentId);
@@ -644,14 +593,21 @@ function removeRegisteredAgent(agentId) {
644
593
  return removed;
645
594
  }
646
595
  async function hydrateRegistryFromDisk(cwd) {
647
- if (hydratedCwds.has(cwd)) return;
648
- hydratedCwds.add(cwd);
649
- const persisted = await loadRegistry(cwd);
650
- for (const [id, entry] of Object.entries(persisted)) {
651
- if (!agents.has(id)) {
652
- agents.set(id, fromSerialized(entry));
596
+ const emAndamento = hydrations.get(cwd);
597
+ if (emAndamento !== void 0) return emAndamento;
598
+ const hidratacao = (async () => {
599
+ const persisted = await loadRegistry(cwd);
600
+ for (const [id, entry] of Object.entries(persisted)) {
601
+ if (!agents.has(id)) {
602
+ agents.set(id, fromSerialized(entry));
603
+ }
653
604
  }
654
- }
605
+ })().catch((cause) => {
606
+ hydrations.delete(cwd);
607
+ throw cause;
608
+ });
609
+ hydrations.set(cwd, hidratacao);
610
+ return hidratacao;
655
611
  }
656
612
  async function flushRegistrySaves(cwd) {
657
613
  if (cwd !== void 0) {
@@ -935,14 +891,12 @@ async function writeMigratedFacts(cwd, jsonPath, facts) {
935
891
  try {
936
892
  for (const fact of facts) await appendFactToMarkdown(cwd, fact);
937
893
  await unlink(jsonPath).catch(() => void 0);
938
- process.stderr.write(
939
- `[theokit-sdk] migrated ${facts.length} fact(s) from ${jsonPath} to MEMORY.md
940
- `
941
- );
894
+ diag(`[theokit-sdk] migrated ${facts.length} fact(s) from ${jsonPath} to MEMORY.md
895
+ `);
942
896
  return { migrated: true, factCount: facts.length };
943
897
  } catch (cause) {
944
898
  const message = cause instanceof Error ? cause.message : String(cause);
945
- process.stderr.write(`[theokit-sdk] memory migration failed (readonly fs?): ${message}
899
+ diag(`[theokit-sdk] memory migration failed (readonly fs?): ${message}
946
900
  `);
947
901
  return { migrated: false, factCount: 0, reason: "readonly-fs" };
948
902
  }
@@ -957,7 +911,7 @@ async function migrateLegacyJson(cwd, config) {
957
911
  return { migrated: false, factCount: 0, reason: "no-legacy-json" };
958
912
  }
959
913
  if (await fileExists(memoryMdPath(cwd))) {
960
- process.stderr.write(
914
+ diag(
961
915
  `[theokit-sdk] memory migration skipped: both MEMORY.md and legacy JSON exist at ${jsonPath}; leaving both intact
962
916
  `
963
917
  );
@@ -1401,6 +1355,37 @@ var FixtureRunBase = class {
1401
1355
  while (index < this.script.events.length) {
1402
1356
  yield this.script.events[index++];
1403
1357
  }
1358
+ yield* this.terminalErrorEvent();
1359
+ }
1360
+ /**
1361
+ * theokit#101 — quando o run termina em erro, `stream()` tem de DIZER.
1362
+ *
1363
+ * O erro sempre existiu: o loop o registra em `ctx.error` e `wait()` devolve
1364
+ * `status: 'error'` com a mensagem. Só o `stream()` não o mencionava — ele drena
1365
+ * `script.events` e para. Uma falha de provider (404 "No endpoints found", auth, timeout)
1366
+ * produzia um turno que parecia bem-sucedido e vazio, em TODA superfície que consome o
1367
+ * stream: HTTP web, MCP, stdio, TUI in-process.
1368
+ *
1369
+ * Erro silencioso é o pior tipo (Regra Inquebrável 8). E a assimetria era o que o tornava
1370
+ * difícil de diagnosticar: quem depurasse por `wait()` via o erro e não reproduziria o
1371
+ * relato de quem depurava pelo stream.
1372
+ *
1373
+ * Emite `SDKStatusMessage` com `status: "ERROR"` — o tipo JÁ EXISTE na união `SDKMessage`
1374
+ * e já é esperado por quem consome. Um tipo novo seria breaking para todo consumidor que
1375
+ * faz switch exaustivo; este é aditivo, e um consumidor que ignore `status` simplesmente
1376
+ * segue como antes — nunca pior que hoje.
1377
+ */
1378
+ *terminalErrorEvent() {
1379
+ if (this.status !== "error") return;
1380
+ const detail = this.script.errorDetail;
1381
+ yield {
1382
+ type: "status",
1383
+ agent_id: this.agentId,
1384
+ run_id: this.id,
1385
+ status: "ERROR",
1386
+ // Sem mensagem, o consumidor sabe QUE falhou e não O QUÊ — que é metade do defeito.
1387
+ ...detail?.message !== void 0 ? { message: detail.message } : {}
1388
+ };
1404
1389
  }
1405
1390
  wait() {
1406
1391
  return this.terminationPromise;
@@ -2036,96 +2021,6 @@ function isStdioCommandConfig(config) {
2036
2021
  function isLocalPath(command) {
2037
2022
  return command.startsWith("/") || command.startsWith("~/") || command.startsWith("./") || command.startsWith("../");
2038
2023
  }
2039
-
2040
- // src/internal/http.ts
2041
- var DEFAULT_BASE_URL = "https://api.usetheo.dev";
2042
- function resolveBaseUrl() {
2043
- return getConfiguredBaseUrl() ?? DEFAULT_BASE_URL;
2044
- }
2045
- async function httpRequest(path, options) {
2046
- const url = `${resolveBaseUrl()}${path}`;
2047
- const fetchFn = options.fetchFn ?? globalThis.fetch;
2048
- const headers = {
2049
- "content-type": "application/json",
2050
- authorization: `Bearer ${options.apiKey}`,
2051
- ...options.headers ?? {}
2052
- };
2053
- const body = options.body !== void 0 ? JSON.stringify(options.body) : void 0;
2054
- const response = await safeFetch(fetchFn, url, {
2055
- method: options.method ?? "GET",
2056
- headers,
2057
- body
2058
- });
2059
- if (!response.ok) {
2060
- const parsed = await safeParseJsonResponse(response);
2061
- throw mapHttpStatusToError(response.status, parsed);
2062
- }
2063
- return await safeParseJsonResponse(response);
2064
- }
2065
- async function safeFetch(fetchFn, url, init) {
2066
- try {
2067
- return await fetchFn(url, init);
2068
- } catch (cause) {
2069
- throw new NetworkError("HTTP request failed", { code: "network_error", cause });
2070
- }
2071
- }
2072
- async function safeParseJsonResponse(response) {
2073
- try {
2074
- return await response.json();
2075
- } catch {
2076
- return void 0;
2077
- }
2078
- }
2079
- function mapHttpStatusToError(status, body) {
2080
- const envelope = extractErrorEnvelope(body);
2081
- const message = envelope.message ?? `HTTP ${status}`;
2082
- const errorOptions = {
2083
- code: envelope.code,
2084
- protoErrorCode: envelope.protoErrorCode,
2085
- cause: body
2086
- };
2087
- if (envelope.code === "integration_not_connected") {
2088
- return new IntegrationNotConnectedError(message, {
2089
- provider: envelope.provider ?? "unknown",
2090
- helpUrl: envelope.helpUrl ?? "",
2091
- code: envelope.code,
2092
- cause: body
2093
- });
2094
- }
2095
- if (status === 401 || status === 403) {
2096
- return new AuthenticationError(message, errorOptions);
2097
- }
2098
- if (status === 429) {
2099
- return new RateLimitError(message, errorOptions);
2100
- }
2101
- if (status >= 400 && status < 500) {
2102
- return new ConfigurationError(message, errorOptions);
2103
- }
2104
- if (status >= 500) {
2105
- return new NetworkError(message, errorOptions);
2106
- }
2107
- return new UnknownAgentError(message, errorOptions);
2108
- }
2109
- function extractErrorEnvelope(body) {
2110
- if (!body || typeof body !== "object") return {};
2111
- const record = body;
2112
- const inner = record.error;
2113
- const source = inner && typeof inner === "object" ? inner : record;
2114
- return readEnvelopeFields(source);
2115
- }
2116
- function readEnvelopeFields(record) {
2117
- return {
2118
- code: pickString(record, "code"),
2119
- message: pickString(record, "message"),
2120
- protoErrorCode: pickString(record, "protoErrorCode"),
2121
- provider: pickString(record, "provider"),
2122
- helpUrl: pickString(record, "helpUrl")
2123
- };
2124
- }
2125
- function pickString(record, key) {
2126
- const value = record[key];
2127
- return typeof value === "string" ? value : void 0;
2128
- }
2129
2024
  var SCHEMA_VERSION2 = 1;
2130
2025
  var FILE_NAME = "personality.json";
2131
2026
  function emptyState() {
@@ -2258,7 +2153,7 @@ function createPluginContext() {
2258
2153
  },
2259
2154
  on(hook, handler) {
2260
2155
  if (typeof handler !== "function") {
2261
- process.stderr.write(`[theokit-sdk] ignoring non-function handler for hook "${hook}"
2156
+ diag(`[theokit-sdk] ignoring non-function handler for hook "${hook}"
2262
2157
  `);
2263
2158
  return;
2264
2159
  }
@@ -2311,7 +2206,7 @@ var PluginManager = class {
2311
2206
  const seen = /* @__PURE__ */ new Set();
2312
2207
  for (const plugin of plugins) {
2313
2208
  if (seen.has(plugin.name)) {
2314
- process.stderr.write(
2209
+ diag(
2315
2210
  `[theokit-sdk] duplicate plugin name "${plugin.name}" \u2014 both will register independently
2316
2211
  `
2317
2212
  );
@@ -2395,7 +2290,7 @@ var PluginManager = class {
2395
2290
  parts.push(result.recalledContext);
2396
2291
  }
2397
2292
  } catch (err) {
2398
- process.stderr.write(
2293
+ diag(
2399
2294
  `[theokit-sdk] pre_user_send hook failed: ${err instanceof Error ? err.message : String(err)}
2400
2295
  `
2401
2296
  );
@@ -2423,7 +2318,7 @@ var PluginManager = class {
2423
2318
  try {
2424
2319
  await h(ctx);
2425
2320
  } catch (err) {
2426
- process.stderr.write(
2321
+ diag(
2427
2322
  `[theokit-sdk] post_assistant_reply hook failed: ${err instanceof Error ? err.message : String(err)}
2428
2323
  `
2429
2324
  );
@@ -2439,7 +2334,7 @@ var PluginManager = class {
2439
2334
  try {
2440
2335
  await h(ctx);
2441
2336
  } catch (err) {
2442
- process.stderr.write(
2337
+ diag(
2443
2338
  `[theokit-sdk] ${name} hook failed: ${err instanceof Error ? err.message : String(err)}
2444
2339
  `
2445
2340
  );
@@ -2454,7 +2349,7 @@ var PluginManager = class {
2454
2349
  const out = await h(current, ctx);
2455
2350
  if (out !== void 0) current = out;
2456
2351
  } catch (err) {
2457
- process.stderr.write(
2352
+ diag(
2458
2353
  `[theokit-sdk] ${name} hook failed: ${err instanceof Error ? err.message : String(err)}
2459
2354
  `
2460
2355
  );
@@ -2737,7 +2632,7 @@ async function runPostRunLifecycle(inputs) {
2737
2632
  }
2738
2633
  } catch (cause) {
2739
2634
  const msg = cause instanceof Error ? cause.message : String(cause);
2740
- process.stderr.write(`[theokit-sdk] partial transcript write failed (${agentId}): ${msg}
2635
+ diag(`[theokit-sdk] partial transcript write failed (${agentId}): ${msg}
2741
2636
  `);
2742
2637
  }
2743
2638
  await flushSessionWrites();
@@ -2796,10 +2691,8 @@ async function runPostRunLifecycle(inputs) {
2796
2691
  }
2797
2692
  } catch (cause) {
2798
2693
  const message = cause instanceof Error ? cause.message : String(cause);
2799
- process.stderr.write(
2800
- `[theokit-sdk] session summary write failed (${result.id}): ${message}
2801
- `
2802
- );
2694
+ diag(`[theokit-sdk] session summary write failed (${result.id}): ${message}
2695
+ `);
2803
2696
  }
2804
2697
  }
2805
2698
  await hooksExecutor.run({
@@ -2821,174 +2714,6 @@ async function safeConversation(run) {
2821
2714
  }
2822
2715
  }
2823
2716
 
2824
- // src/internal/runtime/registry/live-agent-registry.ts
2825
- var DEFAULT_MAX_AGENTS = 100;
2826
- var DEFAULT_IDLE_TIMEOUT_MS = 30 * 60 * 1e3;
2827
- var DEFAULT_SWEEP_INTERVAL_MS = 6e4;
2828
- var LiveAgentRegistry = class {
2829
- #agents = /* @__PURE__ */ new Map();
2830
- #maxAgents = DEFAULT_MAX_AGENTS;
2831
- #idleTimeoutMs = DEFAULT_IDLE_TIMEOUT_MS;
2832
- #sweepIntervalMs = DEFAULT_SWEEP_INTERVAL_MS;
2833
- #onEvict;
2834
- #sweepTimer;
2835
- /**
2836
- * Reconfigure registry behavior. Process-wide singleton (D310) — last
2837
- * configure call wins for all subsequent operations.
2838
- */
2839
- configure(opts) {
2840
- if (opts.maxAgents !== void 0) this.#maxAgents = Math.max(0, opts.maxAgents);
2841
- if (opts.idleTimeoutMs !== void 0) this.#idleTimeoutMs = Math.max(0, opts.idleTimeoutMs);
2842
- if (opts.sweepIntervalMs !== void 0)
2843
- this.#sweepIntervalMs = Math.max(1e3, opts.sweepIntervalMs);
2844
- this.#onEvict = opts.onEvict;
2845
- this.#stopSweep();
2846
- if (this.#idleTimeoutMs > 0) this.#startSweep();
2847
- }
2848
- /**
2849
- * Lookup a cached agent. `get` is a use — refreshes `lastUsedAt` so the
2850
- * entry survives LRU eviction.
2851
- */
2852
- get(id) {
2853
- const entry = this.#agents.get(id);
2854
- if (entry === void 0) return void 0;
2855
- entry.lastUsedAt = Date.now();
2856
- return entry.agent;
2857
- }
2858
- /**
2859
- * Insert or overwrite an agent in the cache. Triggers fire-and-forget LRU
2860
- * eviction when `size > maxAgents`.
2861
- *
2862
- * EC-4: when `id` already maps to a DIFFERENT agent instance, dispose the
2863
- * old one before overwriting (race protection against two `getOrCreate`
2864
- * calls creating two agents but only the second being cached — the first
2865
- * would leak file handles + lifecycle controllers).
2866
- */
2867
- set(id, agent) {
2868
- if (this.#maxAgents === 0) return;
2869
- const existing = this.#agents.get(id);
2870
- if (existing !== void 0 && existing.agent !== agent) {
2871
- void existing.agent.dispose().catch(() => {
2872
- process.stderr.write(`[theokit-sdk] dispose during overwrite failed (${id})
2873
- `);
2874
- });
2875
- }
2876
- this.#agents.set(id, { agent, lastUsedAt: Date.now() });
2877
- if (this.#agents.size > this.#maxAgents) void this.#evictLRU();
2878
- }
2879
- /**
2880
- * Remove the entry from the cache WITHOUT calling `dispose()` or
2881
- * `onEvict`. Used by `LocalAgent.dispose()` itself so the disposed
2882
- * instance can never be returned by a subsequent `get(id)` (dispose-cache
2883
- * race fix). Idempotent — calling on an unknown id is a no-op.
2884
- *
2885
- * @internal
2886
- */
2887
- forget(id) {
2888
- this.#agents.delete(id);
2889
- }
2890
- /**
2891
- * Explicitly evict an agent by id. Returns `true` when the entry was
2892
- * present (false = already gone). Calls `agent.dispose()` + `onEvict`
2893
- * with reason `"explicit"`.
2894
- */
2895
- async evict(id) {
2896
- const entry = this.#agents.get(id);
2897
- if (entry === void 0) return false;
2898
- this.#agents.delete(id);
2899
- await this.#disposeAndNotify(id, entry.agent, "explicit");
2900
- return true;
2901
- }
2902
- /**
2903
- * Evict every cached agent. Used by graceful shutdown (`process.on('SIGTERM')`)
2904
- * or end-of-test cleanup.
2905
- */
2906
- async evictAll() {
2907
- const entries = Array.from(this.#agents.entries());
2908
- this.#agents.clear();
2909
- this.#stopSweep();
2910
- for (const [id, entry] of entries) {
2911
- await this.#disposeAndNotify(id, entry.agent, "explicit");
2912
- }
2913
- }
2914
- /** Number of currently cached agents. */
2915
- size() {
2916
- return this.#agents.size;
2917
- }
2918
- /** Ids of cached agents, newest first (by lastUsedAt). */
2919
- ids() {
2920
- return Array.from(this.#agents.entries()).sort((a, b) => b[1].lastUsedAt - a[1].lastUsedAt).map(([id]) => id);
2921
- }
2922
- /**
2923
- * LRU eviction: drop the entry with the smallest `lastUsedAt`. Runs only
2924
- * when `size > maxAgents`. Asynchronous because `dispose()` is a Promise;
2925
- * the hot-path caller (`set`) does not await.
2926
- *
2927
- * @internal
2928
- */
2929
- async #evictLRU() {
2930
- if (this.#agents.size <= this.#maxAgents) return;
2931
- let oldestId;
2932
- let oldestAt = Infinity;
2933
- for (const [id, entry2] of this.#agents) {
2934
- if (entry2.lastUsedAt < oldestAt) {
2935
- oldestAt = entry2.lastUsedAt;
2936
- oldestId = id;
2937
- }
2938
- }
2939
- if (oldestId === void 0) return;
2940
- const entry = this.#agents.get(oldestId);
2941
- if (entry === void 0) return;
2942
- this.#agents.delete(oldestId);
2943
- await this.#disposeAndNotify(oldestId, entry.agent, "lru");
2944
- }
2945
- /** Background sweep — drops entries whose `lastUsedAt < now - idleTimeoutMs`. */
2946
- async #sweepIdle() {
2947
- if (this.#idleTimeoutMs === 0) return;
2948
- const threshold = Date.now() - this.#idleTimeoutMs;
2949
- const toEvict = [];
2950
- for (const [id, entry] of this.#agents) {
2951
- if (entry.lastUsedAt < threshold) toEvict.push([id, entry]);
2952
- }
2953
- for (const [id, entry] of toEvict) {
2954
- const current = this.#agents.get(id);
2955
- if (current === void 0 || current.agent !== entry.agent) continue;
2956
- this.#agents.delete(id);
2957
- await this.#disposeAndNotify(id, entry.agent, "idle");
2958
- }
2959
- }
2960
- #startSweep() {
2961
- this.#sweepTimer = setInterval(() => void this.#sweepIdle(), this.#sweepIntervalMs);
2962
- this.#sweepTimer.unref?.();
2963
- }
2964
- #stopSweep() {
2965
- if (this.#sweepTimer !== void 0) {
2966
- clearInterval(this.#sweepTimer);
2967
- this.#sweepTimer = void 0;
2968
- }
2969
- }
2970
- /** Dispose + notify with errors swallowed (D309). Single chokepoint. */
2971
- async #disposeAndNotify(id, agent, reason) {
2972
- try {
2973
- await agent.dispose();
2974
- } catch (cause) {
2975
- const msg = cause instanceof Error ? cause.message : String(cause);
2976
- process.stderr.write(`[theokit-sdk] dispose during eviction failed (${id}): ${msg}
2977
- `);
2978
- }
2979
- if (this.#onEvict !== void 0) {
2980
- try {
2981
- this.#onEvict(id, reason);
2982
- } catch (cause) {
2983
- const msg = cause instanceof Error ? cause.message : String(cause);
2984
- process.stderr.write(`[theokit-sdk] onEvict listener threw (${id}): ${msg}
2985
- `);
2986
- }
2987
- }
2988
- }
2989
- };
2990
- var liveAgentRegistry = new LiveAgentRegistry();
2991
-
2992
2717
  // src/define-tool.ts
2993
2718
  var TOOL_SPLIT_RESOLVER = /* @__PURE__ */ Symbol("theokit.toolSplitResolver");
2994
2719
  async function runValidated(spec, input, ctx) {
@@ -3054,7 +2779,7 @@ var warned = /* @__PURE__ */ new Set();
3054
2779
  function warnDoubleReasoningOnce() {
3055
2780
  if (warned.has("double-reasoning")) return;
3056
2781
  warned.add("double-reasoning");
3057
- process.stderr.write(
2782
+ diag(
3058
2783
  "[theokit-sdk] `reasoning: true` skipped \u2014 a native reasoning model is configured (model.params thinking/reasoning); native reasoning wins. Remove one to silence.\n"
3059
2784
  );
3060
2785
  }
@@ -3089,10 +2814,8 @@ var SkillsManager = class {
3089
2814
  const skillsRoot = this.skillsDir ?? join(this.cwd, ".theokit", "skills");
3090
2815
  const discovered = await discoverSkills(skillsRoot, {
3091
2816
  onInvalidSkill: (info) => {
3092
- process.stderr.write(
3093
- `[theokit-sdk] skill ${info.name} skipped (${info.code}): ${info.message}
3094
- `
3095
- );
2817
+ diag(`[theokit-sdk] skill ${info.name} skipped (${info.code}): ${info.message}
2818
+ `);
3096
2819
  }
3097
2820
  });
3098
2821
  this.skills = this.mergeInline(discovered);
@@ -3201,7 +2924,7 @@ async function safeCall(fn, fallback, label = "safeCall") {
3201
2924
  return await fn();
3202
2925
  } catch (cause) {
3203
2926
  const message = cause instanceof Error ? cause.message : String(cause);
3204
- process.stderr.write(`[theokit-sdk] ${label} failed: ${message}
2927
+ diag(`[theokit-sdk] ${label} failed: ${message}
3205
2928
  `);
3206
2929
  return fallback;
3207
2930
  }
@@ -3647,7 +3370,7 @@ var langfuseAdapter = {
3647
3370
  }
3648
3371
  }
3649
3372
  if (lf.LangfuseSpanProcessor === void 0) {
3650
- process.stderr.write(
3373
+ diag(
3651
3374
  "[theokit-sdk] @langfuse/node detected but LangfuseSpanProcessor not found (v2?). Use Langfuse v3+ for auto-instrumentation.\n"
3652
3375
  );
3653
3376
  return;
@@ -3776,11 +3499,11 @@ function tryAutoRegisterAdapters(settings) {
3776
3499
  try {
3777
3500
  adapter.register();
3778
3501
  registered.add(adapter.moduleName);
3779
- process.stderr.write(`[theokit-sdk] telemetry: ${adapter.displayName} auto-instrumented.
3502
+ diag(`[theokit-sdk] telemetry: ${adapter.displayName} auto-instrumented.
3780
3503
  `);
3781
3504
  } catch (cause) {
3782
3505
  const message = cause instanceof Error ? cause.message : String(cause);
3783
- process.stderr.write(
3506
+ diag(
3784
3507
  `[theokit-sdk] telemetry: ${adapter.displayName} detected but failed to register: ${message}
3785
3508
  `
3786
3509
  );
@@ -3836,7 +3559,7 @@ function safe(op, fallback) {
3836
3559
  if (!warnedOnce) {
3837
3560
  warnedOnce = true;
3838
3561
  const message = cause instanceof Error ? cause.message : String(cause);
3839
- process.stderr.write(
3562
+ diag(
3840
3563
  `[theokit-sdk] telemetry exporter error (suppressed; agent.send continues): ${message}
3841
3564
  `
3842
3565
  );
@@ -3850,7 +3573,7 @@ function createTelemetry(settings) {
3850
3573
  if (otel === null) {
3851
3574
  if (!warnedOnce) {
3852
3575
  warnedOnce = true;
3853
- process.stderr.write(
3576
+ diag(
3854
3577
  "[theokit-sdk] telemetry.enabled = true but `@opentelemetry/api` is not installed; telemetry is a no-op.\n"
3855
3578
  );
3856
3579
  }
@@ -5378,7 +5101,7 @@ async function safeListTools(client, serverName) {
5378
5101
  } catch (cause) {
5379
5102
  const message = cause instanceof Error ? cause.message : String(cause);
5380
5103
  const server = serverName ?? "unknown";
5381
- process.stderr.write(`[theokit-sdk] mcp listTools failed (server=${server}): ${message}
5104
+ diag(`[theokit-sdk] mcp listTools failed (server=${server}): ${message}
5382
5105
  `);
5383
5106
  return [];
5384
5107
  }
@@ -5447,7 +5170,7 @@ function emitLlmMetrics(inputs, result, startAt) {
5447
5170
  inputs.telemetry?.recordHistogram(HISTOGRAM_NAMES.LLM_USAGE_MISSING, 1, {
5448
5171
  provider: inputs.llm.name
5449
5172
  });
5450
- process.stderr.write(
5173
+ diag(
5451
5174
  `[theokit-sdk] llm usage missing from ${inputs.llm.name} finish \u2014 budget may undercount
5452
5175
  `
5453
5176
  );
@@ -6124,7 +5847,7 @@ function finalizeSpanAndPostHook(inputs, call, callId, result, events, toolSpan)
6124
5847
  agentId: inputs.agentId,
6125
5848
  runId: inputs.runId
6126
5849
  }).catch((err) => {
6127
- process.stderr.write(
5850
+ diag(
6128
5851
  `[theokit-sdk] postToolUse hook error (swallowed): ${err instanceof Error ? err.message : String(err)}
6129
5852
  `
6130
5853
  );
@@ -6143,7 +5866,7 @@ async function emitToolLifecycleDelta(inputs, update) {
6143
5866
  try {
6144
5867
  await inputs.onDelta({ update });
6145
5868
  } catch (err) {
6146
- process.stderr.write(
5869
+ diag(
6147
5870
  `[theokit-sdk] onDelta tool-lifecycle emit error (swallowed): ${err instanceof Error ? err.message : String(err)}
6148
5871
  `
6149
5872
  );
@@ -6155,7 +5878,7 @@ async function safeEmitToolHook(callback, event) {
6155
5878
  await callback(event);
6156
5879
  } catch (cause) {
6157
5880
  const msg = cause instanceof Error ? cause.message : String(cause);
6158
- process.stderr.write(`[theokit-sdk] tool lifecycle hook threw: ${msg}
5881
+ diag(`[theokit-sdk] tool lifecycle hook threw: ${msg}
6159
5882
  `);
6160
5883
  }
6161
5884
  }
@@ -7382,10 +7105,8 @@ function resolveRunProvider(options) {
7382
7105
  if (registered2 > 0 && !pluginProvidersAnnounced) {
7383
7106
  pluginProvidersAnnounced = true;
7384
7107
  const names = profiles.map((e) => e.profile.name).join(", ");
7385
- process.stderr.write(
7386
- `[theokit-sdk] registered ${registered2} plugin provider profile(s): ${names}
7387
- `
7388
- );
7108
+ diag(`[theokit-sdk] registered ${registered2} plugin provider profile(s): ${names}
7109
+ `);
7389
7110
  }
7390
7111
  const parsedModel = parseModelId(options.model?.id);
7391
7112
  const modelInferredProvider = parsedModel.provider !== void 0 && getProviderProfile(parsedModel.provider) !== void 0 ? parsedModel.provider : void 0;
@@ -7698,25 +7419,21 @@ async function readProjectMcpServers(cwd) {
7698
7419
 
7699
7420
  // src/internal/local-agent/local-agent-invalidate.ts
7700
7421
  async function applyDeferredInvalidation(agentId, pending, refresh) {
7701
- process.stderr.write(
7702
- `[theokit-sdk] applying deferred cache invalidation (${agentId}): ${pending.reason}
7703
- `
7704
- );
7422
+ diag(`[theokit-sdk] applying deferred cache invalidation (${agentId}): ${pending.reason}
7423
+ `);
7705
7424
  try {
7706
7425
  await refresh();
7707
7426
  } catch (err) {
7708
7427
  const msg = err instanceof Error ? err.message : String(err);
7709
- process.stderr.write(`[theokit-sdk] invalidateCache reload failed (continuing): ${msg}
7428
+ diag(`[theokit-sdk] invalidateCache reload failed (continuing): ${msg}
7710
7429
  `);
7711
7430
  }
7712
7431
  }
7713
7432
  async function invalidateCacheImpl(agentId, reason, options, disposed, dispose, setPending) {
7714
7433
  if (disposed) return;
7715
7434
  if (options.applyNow === true) {
7716
- process.stderr.write(
7717
- `[theokit-sdk] invalidateCache applyNow disposing agent (${agentId}): ${reason}
7718
- `
7719
- );
7435
+ diag(`[theokit-sdk] invalidateCache applyNow disposing agent (${agentId}): ${reason}
7436
+ `);
7720
7437
  await dispose();
7721
7438
  return;
7722
7439
  }
@@ -7727,6 +7444,217 @@ async function consumePending(agentId, pending, clear, refresh) {
7727
7444
  clear();
7728
7445
  await applyDeferredInvalidation(agentId, pending, refresh);
7729
7446
  }
7447
+
7448
+ // src/internal/runtime/registry/live-agent-registry.ts
7449
+ var DEFAULT_MAX_AGENTS = 100;
7450
+ var DEFAULT_IDLE_TIMEOUT_MS = 30 * 60 * 1e3;
7451
+ var DEFAULT_SWEEP_INTERVAL_MS = 6e4;
7452
+ var LiveAgentRegistry = class {
7453
+ #agents = /* @__PURE__ */ new Map();
7454
+ #maxAgents = DEFAULT_MAX_AGENTS;
7455
+ #idleTimeoutMs = DEFAULT_IDLE_TIMEOUT_MS;
7456
+ #sweepIntervalMs = DEFAULT_SWEEP_INTERVAL_MS;
7457
+ #onEvict;
7458
+ #sweepTimer;
7459
+ /**
7460
+ * Reconfigure registry behavior. Process-wide singleton (D310) — last
7461
+ * configure call wins for all subsequent operations.
7462
+ */
7463
+ configure(opts) {
7464
+ if (opts.maxAgents !== void 0) this.#maxAgents = Math.max(0, opts.maxAgents);
7465
+ if (opts.idleTimeoutMs !== void 0) this.#idleTimeoutMs = Math.max(0, opts.idleTimeoutMs);
7466
+ if (opts.sweepIntervalMs !== void 0)
7467
+ this.#sweepIntervalMs = Math.max(1e3, opts.sweepIntervalMs);
7468
+ this.#onEvict = opts.onEvict;
7469
+ this.#stopSweep();
7470
+ if (this.#idleTimeoutMs > 0) this.#startSweep();
7471
+ }
7472
+ /**
7473
+ * Lookup a cached agent. `get` is a use — refreshes `lastUsedAt` so the
7474
+ * entry survives LRU eviction.
7475
+ */
7476
+ get(id) {
7477
+ const entry = this.#agents.get(id);
7478
+ if (entry === void 0) return void 0;
7479
+ entry.lastUsedAt = Date.now();
7480
+ return entry.agent;
7481
+ }
7482
+ /**
7483
+ * Insert or overwrite an agent in the cache. Triggers fire-and-forget LRU
7484
+ * eviction when `size > maxAgents`.
7485
+ *
7486
+ * EC-4: when `id` already maps to a DIFFERENT agent instance, dispose the
7487
+ * old one before overwriting (race protection against two `getOrCreate`
7488
+ * calls creating two agents but only the second being cached — the first
7489
+ * would leak file handles + lifecycle controllers).
7490
+ */
7491
+ set(id, agent) {
7492
+ if (this.#maxAgents === 0) return;
7493
+ const existing = this.#agents.get(id);
7494
+ if (existing !== void 0 && existing.agent !== agent) {
7495
+ void existing.agent.dispose().catch(() => {
7496
+ diag(`[theokit-sdk] dispose during overwrite failed (${id})
7497
+ `);
7498
+ });
7499
+ }
7500
+ this.#agents.set(id, { agent, lastUsedAt: Date.now() });
7501
+ if (this.#agents.size > this.#maxAgents) void this.#evictLRU();
7502
+ }
7503
+ /**
7504
+ * Remove the entry from the cache WITHOUT calling `dispose()` or
7505
+ * `onEvict`. Used by `LocalAgent.dispose()` itself so the disposed
7506
+ * instance can never be returned by a subsequent `get(id)` (dispose-cache
7507
+ * race fix). Idempotent — calling on an unknown id is a no-op.
7508
+ *
7509
+ * @internal
7510
+ */
7511
+ forget(id) {
7512
+ this.#agents.delete(id);
7513
+ }
7514
+ /**
7515
+ * Explicitly evict an agent by id. Returns `true` when the entry was
7516
+ * present (false = already gone). Calls `agent.dispose()` + `onEvict`
7517
+ * with reason `"explicit"`.
7518
+ */
7519
+ async evict(id) {
7520
+ const entry = this.#agents.get(id);
7521
+ if (entry === void 0) return false;
7522
+ this.#agents.delete(id);
7523
+ await this.#disposeAndNotify(id, entry.agent, "explicit");
7524
+ return true;
7525
+ }
7526
+ /**
7527
+ * Evict every cached agent. Used by graceful shutdown (`process.on('SIGTERM')`)
7528
+ * or end-of-test cleanup.
7529
+ */
7530
+ async evictAll() {
7531
+ const entries = Array.from(this.#agents.entries());
7532
+ this.#agents.clear();
7533
+ this.#stopSweep();
7534
+ for (const [id, entry] of entries) {
7535
+ await this.#disposeAndNotify(id, entry.agent, "explicit");
7536
+ }
7537
+ }
7538
+ /** Number of currently cached agents. */
7539
+ size() {
7540
+ return this.#agents.size;
7541
+ }
7542
+ /** Ids of cached agents, newest first (by lastUsedAt). */
7543
+ ids() {
7544
+ return Array.from(this.#agents.entries()).sort((a, b) => b[1].lastUsedAt - a[1].lastUsedAt).map(([id]) => id);
7545
+ }
7546
+ /**
7547
+ * LRU eviction: drop the entry with the smallest `lastUsedAt`. Runs only
7548
+ * when `size > maxAgents`. Asynchronous because `dispose()` is a Promise;
7549
+ * the hot-path caller (`set`) does not await.
7550
+ *
7551
+ * @internal
7552
+ */
7553
+ async #evictLRU() {
7554
+ if (this.#agents.size <= this.#maxAgents) return;
7555
+ let oldestId;
7556
+ let oldestAt = Infinity;
7557
+ for (const [id, entry2] of this.#agents) {
7558
+ if (entry2.lastUsedAt < oldestAt) {
7559
+ oldestAt = entry2.lastUsedAt;
7560
+ oldestId = id;
7561
+ }
7562
+ }
7563
+ if (oldestId === void 0) return;
7564
+ const entry = this.#agents.get(oldestId);
7565
+ if (entry === void 0) return;
7566
+ this.#agents.delete(oldestId);
7567
+ await this.#disposeAndNotify(oldestId, entry.agent, "lru");
7568
+ }
7569
+ /** Background sweep — drops entries whose `lastUsedAt < now - idleTimeoutMs`. */
7570
+ async #sweepIdle() {
7571
+ if (this.#idleTimeoutMs === 0) return;
7572
+ const threshold = Date.now() - this.#idleTimeoutMs;
7573
+ const toEvict = [];
7574
+ for (const [id, entry] of this.#agents) {
7575
+ if (entry.lastUsedAt < threshold) toEvict.push([id, entry]);
7576
+ }
7577
+ for (const [id, entry] of toEvict) {
7578
+ const current = this.#agents.get(id);
7579
+ if (current === void 0 || current.agent !== entry.agent) continue;
7580
+ this.#agents.delete(id);
7581
+ await this.#disposeAndNotify(id, entry.agent, "idle");
7582
+ }
7583
+ }
7584
+ #startSweep() {
7585
+ this.#sweepTimer = setInterval(() => void this.#sweepIdle(), this.#sweepIntervalMs);
7586
+ this.#sweepTimer.unref?.();
7587
+ }
7588
+ #stopSweep() {
7589
+ if (this.#sweepTimer !== void 0) {
7590
+ clearInterval(this.#sweepTimer);
7591
+ this.#sweepTimer = void 0;
7592
+ }
7593
+ }
7594
+ /** Dispose + notify with errors swallowed (D309). Single chokepoint. */
7595
+ async #disposeAndNotify(id, agent, reason) {
7596
+ try {
7597
+ await agent.dispose();
7598
+ } catch (cause) {
7599
+ const msg = cause instanceof Error ? cause.message : String(cause);
7600
+ diag(`[theokit-sdk] dispose during eviction failed (${id}): ${msg}
7601
+ `);
7602
+ }
7603
+ if (this.#onEvict !== void 0) {
7604
+ try {
7605
+ this.#onEvict(id, reason);
7606
+ } catch (cause) {
7607
+ const msg = cause instanceof Error ? cause.message : String(cause);
7608
+ diag(`[theokit-sdk] onEvict listener threw (${id}): ${msg}
7609
+ `);
7610
+ }
7611
+ }
7612
+ }
7613
+ };
7614
+ var liveAgentRegistry = new LiveAgentRegistry();
7615
+
7616
+ // src/internal/local-agent/local-agent-lifecycle.ts
7617
+ async function adquirirLeaseSePossivel(store, agentId) {
7618
+ const a = store.acquire;
7619
+ if (typeof a !== "function") return;
7620
+ try {
7621
+ await a.call(store, agentId);
7622
+ } catch (err) {
7623
+ if (err instanceof Error && err.name === "SessionBusyError") throw err;
7624
+ diag(
7625
+ `[theokit-sdk] writer lease unavailable for ${agentId} (${err instanceof Error ? err.message : String(err)}) \u2014 proceeding without single-writer protection
7626
+ `
7627
+ );
7628
+ }
7629
+ }
7630
+ async function soltarLeaseSePossivel(store, agentId) {
7631
+ const r = store.release;
7632
+ if (typeof r === "function") await r.call(store, agentId);
7633
+ }
7634
+ async function disposeSessionStore(store) {
7635
+ const d = store.dispose;
7636
+ if (typeof d === "function") await d.call(store);
7637
+ }
7638
+ async function disposeLocalAgentSession(agent) {
7639
+ liveAgentRegistry.forget(agent.agentId);
7640
+ agent.lifecycleAbortController.abort();
7641
+ await withCwdMutex(`agent-send:${agent.agentId}`, () => Promise.resolve());
7642
+ disposeSessionMcpClients(agent.agentId);
7643
+ await flushSessionWrites();
7644
+ await flushRegistrySaves(agent.workspaceCwd);
7645
+ await disposeSessionStore(agent.sessionStore);
7646
+ descartarSessao(agent.workspaceCwd, agent.agentId);
7647
+ }
7648
+ async function reloadLocalAgent(agent) {
7649
+ if (agent.context !== void 0) await agent.context.refresh();
7650
+ if (agent.skillsManager !== void 0) await agent.skillsManager.refresh();
7651
+ if (agent.pluginsManager !== void 0) await agent.pluginsManager.refresh();
7652
+ return await loadSubagents(
7653
+ agent.workspaceCwd,
7654
+ agent.settingSourcesIncludeProject,
7655
+ agent.options.agents
7656
+ );
7657
+ }
7730
7658
  async function persistActiveMemoryTranscript(cwd, transcript) {
7731
7659
  try {
7732
7660
  const dir = join(memoryDir(cwd), "transcripts", "active-memory");
@@ -7734,7 +7662,7 @@ async function persistActiveMemoryTranscript(cwd, transcript) {
7734
7662
  await atomicWriteJson(file, transcript);
7735
7663
  } catch (cause) {
7736
7664
  const message = cause instanceof Error ? cause.message : String(cause);
7737
- process.stderr.write(`[theokit-sdk] active-memory transcript persist failed: ${message}
7665
+ diag(`[theokit-sdk] active-memory transcript persist failed: ${message}
7738
7666
  `);
7739
7667
  }
7740
7668
  }
@@ -7855,7 +7783,7 @@ async function searchOnce(args, cfg, query, started) {
7855
7783
  return { summary, durationMs: Date.now() - started, status: "ok", hits };
7856
7784
  } catch (cause) {
7857
7785
  const message = cause instanceof Error ? cause.message : String(cause);
7858
- process.stderr.write(`[theokit-sdk] active-memory recall failed: ${message}
7786
+ diag(`[theokit-sdk] active-memory recall failed: ${message}
7859
7787
  `);
7860
7788
  return { summary: void 0, durationMs: Date.now() - started, status: "error", hits: [] };
7861
7789
  }
@@ -8635,7 +8563,7 @@ var LocalAgentMemory = class {
8635
8563
  const warned2 = g[sym];
8636
8564
  if (!warned2.has(message)) {
8637
8565
  warned2.add(message);
8638
- process.stderr.write(`[theokit-sdk] memory tools unavailable: ${message}
8566
+ diag(`[theokit-sdk] memory tools unavailable: ${message}
8639
8567
  `);
8640
8568
  }
8641
8569
  return void 0;
@@ -8694,7 +8622,7 @@ var LocalAgentMemory = class {
8694
8622
  await this.index.sync();
8695
8623
  } catch (cause) {
8696
8624
  const message = cause instanceof Error ? cause.message : String(cause);
8697
- process.stderr.write(`[theokit-sdk] session index sync failed: ${message}
8625
+ diag(`[theokit-sdk] session index sync failed: ${message}
8698
8626
  `);
8699
8627
  }
8700
8628
  }
@@ -8707,10 +8635,8 @@ var LocalAgentMemory = class {
8707
8635
  return await adapter.create(cfg.model !== void 0 ? { model: cfg.model } : {});
8708
8636
  } catch (cause) {
8709
8637
  const message = cause instanceof Error ? cause.message : String(cause);
8710
- process.stderr.write(
8711
- `[theokit-sdk] memory embedding ${cfg.provider} unavailable: ${message}
8712
- `
8713
- );
8638
+ diag(`[theokit-sdk] memory embedding ${cfg.provider} unavailable: ${message}
8639
+ `);
8714
8640
  return void 0;
8715
8641
  }
8716
8642
  }
@@ -9060,7 +8986,7 @@ function localAgentRunUntil(agent, goal, options) {
9060
8986
  async function* wrap() {
9061
8987
  const { runUntilImpl } = await import('./run-until-YZ2ODWOF.js');
9062
8988
  const buildDeps = async () => {
9063
- const { judgeCallImpl } = await import('./judge-call-D7R3ZTZS.js');
8989
+ const { judgeCallImpl } = await import('./judge-call-TAEIXMYG.js');
9064
8990
  const { getAgentFacade } = await import('./agent-factory-registry-ZVTABLEY.js');
9065
8991
  const create = getAgentFacade().create;
9066
8992
  return {
@@ -9093,7 +9019,7 @@ async function* localAgentStreamToCompletion(agent, message, options) {
9093
9019
  async function localAgentFork(parent, options) {
9094
9020
  const { forkAgentImpl } = await import('./fork-agent-RSV4E3EA.js');
9095
9021
  const { getAgentFacade } = await import('./agent-factory-registry-ZVTABLEY.js');
9096
- const { withPersonalityContext } = await import('./context-GWANQLX4.js');
9022
+ const { withPersonalityContext } = await import('./context-VAYLPT4O.js');
9097
9023
  const create = getAgentFacade().create;
9098
9024
  return withPersonalityContext(
9099
9025
  { slug: parent.personalitySlugSnapshot, isFork: true },
@@ -9468,7 +9394,7 @@ async function executeSendLocked(inputs, message, options) {
9468
9394
  function buildCompletionCheckDeps() {
9469
9395
  return {
9470
9396
  judge: async (ctx, opts) => {
9471
- const { judgeCallImpl } = await import('./judge-call-D7R3ZTZS.js');
9397
+ const { judgeCallImpl } = await import('./judge-call-TAEIXMYG.js');
9472
9398
  const { getAgentFacade } = await import('./agent-factory-registry-ZVTABLEY.js');
9473
9399
  return judgeCallImpl(ctx, opts, { create: getAgentFacade().create });
9474
9400
  }
@@ -9509,27 +9435,6 @@ function registerRunAsTask(run, agentId, taskOpt, userText) {
9509
9435
  }
9510
9436
 
9511
9437
  // src/internal/local-agent/local-agent.ts
9512
- async function adquirirLeaseSePossivel(store, agentId) {
9513
- const a = store.acquire;
9514
- if (typeof a !== "function") return;
9515
- try {
9516
- await a.call(store, agentId);
9517
- } catch (err) {
9518
- if (err instanceof Error && err.name === "SessionBusyError") throw err;
9519
- process.stderr.write(
9520
- `[theokit-sdk] writer lease unavailable for ${agentId} (${err instanceof Error ? err.message : String(err)}) \u2014 proceeding without single-writer protection
9521
- `
9522
- );
9523
- }
9524
- }
9525
- async function soltarLeaseSePossivel(store, agentId) {
9526
- const r = store.release;
9527
- if (typeof r === "function") await r.call(store, agentId);
9528
- }
9529
- async function disposeSessionStore(store) {
9530
- const d = store.dispose;
9531
- if (typeof d === "function") await d.call(store);
9532
- }
9533
9438
  var LocalAgent = class {
9534
9439
  agentId;
9535
9440
  model;
@@ -9824,26 +9729,12 @@ var LocalAgent = class {
9824
9729
  this.disposed = true;
9825
9730
  }
9826
9731
  async reload() {
9827
- if (this.context !== void 0) await this.context.refresh();
9828
- if (this.skillsManager !== void 0) await this.skillsManager.refresh();
9829
- if (this.pluginsManager !== void 0) await this.pluginsManager.refresh();
9830
- this.resolvedSubagents = await loadSubagents(
9831
- this.workspaceCwd,
9832
- this.settingSourcesIncludeProject,
9833
- this.options.agents
9834
- );
9732
+ this.resolvedSubagents = await reloadLocalAgent(this);
9835
9733
  }
9836
9734
  async dispose() {
9837
9735
  if (this.disposed) return;
9838
9736
  this.disposed = true;
9839
- liveAgentRegistry.forget(this.agentId);
9840
- this.lifecycleAbortController.abort();
9841
- await withCwdMutex(`agent-send:${this.agentId}`, () => Promise.resolve());
9842
- disposeSessionMcpClients(this.agentId);
9843
- await flushSessionWrites();
9844
- await flushRegistrySaves(this.workspaceCwd);
9845
- await disposeSessionStore(this.sessionStore);
9846
- descartarSessao(this.workspaceCwd, this.agentId);
9737
+ await disposeLocalAgentSession(this);
9847
9738
  }
9848
9739
  [Symbol.asyncDispose]() {
9849
9740
  return this.dispose();
@@ -10261,7 +10152,7 @@ var Agent = class _Agent {
10261
10152
  * @public
10262
10153
  */
10263
10154
  static async generateObject(options) {
10264
- const { generateObjectImpl } = await import('./generate-object-YJPDV5BS.js');
10155
+ const { generateObjectImpl } = await import('./generate-object-I7UD4NWN.js');
10265
10156
  return generateObjectImpl(options, {
10266
10157
  create: (opts) => _Agent.create(opts),
10267
10158
  delete: (agentId) => _Agent.delete(agentId)
@@ -10285,7 +10176,7 @@ var Agent = class _Agent {
10285
10176
  delete: (agentId) => _Agent.delete(agentId)
10286
10177
  };
10287
10178
  async function* wrapper() {
10288
- streamObjectImport ??= import('./stream-object-WUQSSRY2.js');
10179
+ streamObjectImport ??= import('./stream-object-OFM66VUT.js');
10289
10180
  const { streamObjectImpl } = await streamObjectImport;
10290
10181
  yield* streamObjectImpl(options, deps);
10291
10182
  }
@@ -10309,7 +10200,7 @@ var Agent = class _Agent {
10309
10200
  * @public
10310
10201
  */
10311
10202
  static async batch(prompts, options) {
10312
- const { batchImpl } = await import('./batch-MR2HKYMS.js');
10203
+ const { batchImpl } = await import('./batch-SY5GZLFD.js');
10313
10204
  return batchImpl(prompts, options, { create: (opts) => _Agent.create(opts) });
10314
10205
  }
10315
10206
  /**
@@ -10353,15 +10244,15 @@ var Agent = class _Agent {
10353
10244
  return fresh;
10354
10245
  }
10355
10246
  /**
10356
- * List agents (local or cloud).
10247
+ * List agents (local or cloud). M107 — `cwd` is READ now, not ignored;
10248
+ * `limit`/`cursor` still are not (see `tests/agent-list-cwd.test.ts`).
10357
10249
  *
10358
10250
  * @public
10359
10251
  */
10360
10252
  static async list(options = {}) {
10361
- await hydrateRegistryFromDisk(process.cwd());
10362
- const runtime = options.runtime;
10363
- const all = listRegisteredAgents(runtime);
10364
- const items = all.map((agent) => toAgentInfo(agent));
10253
+ const cwd = ("cwd" in options ? options.cwd : void 0) ?? process.cwd();
10254
+ await hydrateRegistryFromDisk(cwd);
10255
+ const items = listRegisteredAgents(options.runtime, cwd).map((agent) => toAgentInfo(agent));
10365
10256
  return { items };
10366
10257
  }
10367
10258
  /**
@@ -10447,7 +10338,7 @@ var Agent = class _Agent {
10447
10338
  `No local agent "${agentId}" registered \u2014 compact targets local sessions.`
10448
10339
  );
10449
10340
  }
10450
- const { compactSessionTranscript, buildDefaultSummarizer: buildDefaultSummarizer2 } = await import('./compact-session-5BDD4HIB.js');
10341
+ const { compactSessionTranscript, buildDefaultSummarizer: buildDefaultSummarizer2 } = await import('./compact-session-WNKKIIDW.js');
10451
10342
  const { cwd, model, store } = await abrirStoreLocal(reg);
10452
10343
  return enqueueSessionWrite(
10453
10344
  cwd,
@@ -10483,7 +10374,7 @@ var Agent = class _Agent {
10483
10374
  `No local agent "${agentId}" registered \u2014 injectSessionTurn targets local sessions.`
10484
10375
  );
10485
10376
  }
10486
- const { injectSessionTurn } = await import('./inject-session-V5FTK72N.js');
10377
+ const { injectSessionTurn } = await import('./inject-session-UXNJQTZ6.js');
10487
10378
  const { cwd, model, store } = await abrirStoreLocal(reg);
10488
10379
  await injectSessionTurn({
10489
10380
  store,
@@ -10530,12 +10421,12 @@ async function abrirStoreLocal(reg) {
10530
10421
  const cwd = reg.cwd ?? process.cwd();
10531
10422
  const optModel = reg.options.model;
10532
10423
  const model = reg.model?.id ?? (typeof optModel === "string" ? optModel : optModel?.id) ?? "unknown";
10533
- const { FsSessionStore: FsSessionStore2 } = await import('./fs-session-store-4ALCDU3K.js');
10534
- const { defaultBaseDir: defaultBaseDir2, expandTilde: expandTilde2 } = await import('./session-transcript-F2ANTA2M.js');
10424
+ const { FsSessionStore: FsSessionStore2 } = await import('./fs-session-store-6MY7PNI2.js');
10425
+ const { defaultBaseDir: defaultBaseDir2, expandTilde: expandTilde2 } = await import('./session-transcript-6WKLYIN4.js');
10535
10426
  const baseDir = reg.options.local?.baseDir !== void 0 ? expandTilde2(reg.options.local.baseDir) : defaultBaseDir2();
10536
10427
  return { cwd, model, store: new FsSessionStore2({ baseDir, cwd }) };
10537
10428
  }
10538
10429
 
10539
- export { Agent, AgentBuilder, DEFAULT_AGENTIC_MODEL_ID, MEMORY_EMBEDDING_ADAPTERS, Tool, ToolError, UsageAccumulator, computeCost, generateCronId, getPricingEntry, httpRequest, isFixtureApiKey, openRouterMemoryEmbeddingProviderAdapter, resolveApiKey, shouldUseFixtureMode };
10540
- //# sourceMappingURL=chunk-EKFA76N4.js.map
10541
- //# sourceMappingURL=chunk-EKFA76N4.js.map
10430
+ export { Agent, AgentBuilder, DEFAULT_AGENTIC_MODEL_ID, MEMORY_EMBEDDING_ADAPTERS, Tool, ToolError, UsageAccumulator, computeCost, generateCronId, getPricingEntry, openRouterMemoryEmbeddingProviderAdapter, resolveApiKey };
10431
+ //# sourceMappingURL=chunk-F3X7Q4BF.js.map
10432
+ //# sourceMappingURL=chunk-F3X7Q4BF.js.map