abtars 0.1.0-alpha.1

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 (312) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +84 -0
  3. package/bundle/_registry.generated-M4WY2MMI.js +35 -0
  4. package/bundle/_registry.generated-M4WY2MMI.js.map +7 -0
  5. package/bundle/abtars-browser.js +162 -0
  6. package/bundle/abtars-browser.js.map +7 -0
  7. package/bundle/abtars-cli.js +1438 -0
  8. package/bundle/abtars-cli.js.map +7 -0
  9. package/bundle/abtars-restart.js +12 -0
  10. package/bundle/abtars-restart.js.map +7 -0
  11. package/bundle/abtars-rss.js +165 -0
  12. package/bundle/abtars-rss.js.map +7 -0
  13. package/bundle/abtars-task.js +258 -0
  14. package/bundle/abtars-task.js.map +7 -0
  15. package/bundle/abtars.js +4072 -0
  16. package/bundle/abtars.js.map +7 -0
  17. package/bundle/agent-api-rate-limit-OQNFMXTZ.js +38 -0
  18. package/bundle/agent-api-rate-limit-OQNFMXTZ.js.map +7 -0
  19. package/bundle/agent-registry-LT4JNQH6.js +18 -0
  20. package/bundle/agent-registry-LT4JNQH6.js.map +7 -0
  21. package/bundle/agents/default.md +29 -0
  22. package/bundle/anthropic-adapter-2APTH3LA.js +40 -0
  23. package/bundle/anthropic-adapter-2APTH3LA.js.map +7 -0
  24. package/bundle/bridge-lock-transport-4AC2G5G6.js +39 -0
  25. package/bundle/bridge-lock-transport-4AC2G5G6.js.map +7 -0
  26. package/bundle/browse-delivery-JXBY36GK.js +17 -0
  27. package/bundle/browse-delivery-JXBY36GK.js.map +7 -0
  28. package/bundle/browser-ELNDVPLC.js +18 -0
  29. package/bundle/browser-ELNDVPLC.js.map +7 -0
  30. package/bundle/capability-CIL3G4FI.js +17 -0
  31. package/bundle/capability-CIL3G4FI.js.map +7 -0
  32. package/bundle/chunk-265TPOPC.js +289 -0
  33. package/bundle/chunk-265TPOPC.js.map +7 -0
  34. package/bundle/chunk-2UENBO6M.js +223 -0
  35. package/bundle/chunk-2UENBO6M.js.map +7 -0
  36. package/bundle/chunk-2UPU3OW6.js +67 -0
  37. package/bundle/chunk-2UPU3OW6.js.map +7 -0
  38. package/bundle/chunk-2XU2X4OI.js +125 -0
  39. package/bundle/chunk-2XU2X4OI.js.map +7 -0
  40. package/bundle/chunk-3B7BBE4F.js +758 -0
  41. package/bundle/chunk-3B7BBE4F.js.map +7 -0
  42. package/bundle/chunk-3E545J66.js +69 -0
  43. package/bundle/chunk-3E545J66.js.map +7 -0
  44. package/bundle/chunk-5R2ANXQ7.js +510 -0
  45. package/bundle/chunk-5R2ANXQ7.js.map +7 -0
  46. package/bundle/chunk-6CPN4IGS.js +507 -0
  47. package/bundle/chunk-6CPN4IGS.js.map +7 -0
  48. package/bundle/chunk-6NR3OHEW.js +88 -0
  49. package/bundle/chunk-6NR3OHEW.js.map +7 -0
  50. package/bundle/chunk-6SETMHNN.js +206 -0
  51. package/bundle/chunk-6SETMHNN.js.map +7 -0
  52. package/bundle/chunk-6UCRKRWR.js +644 -0
  53. package/bundle/chunk-6UCRKRWR.js.map +7 -0
  54. package/bundle/chunk-AR6GO6YC.js +83 -0
  55. package/bundle/chunk-AR6GO6YC.js.map +7 -0
  56. package/bundle/chunk-AZJIODTQ.js +54 -0
  57. package/bundle/chunk-AZJIODTQ.js.map +7 -0
  58. package/bundle/chunk-BHMZ4RCC.js +3706 -0
  59. package/bundle/chunk-BHMZ4RCC.js.map +7 -0
  60. package/bundle/chunk-BQ2L4GMG.js +9175 -0
  61. package/bundle/chunk-BQ2L4GMG.js.map +7 -0
  62. package/bundle/chunk-BSSBCSCL.js +159 -0
  63. package/bundle/chunk-BSSBCSCL.js.map +7 -0
  64. package/bundle/chunk-BUUVFUPO.js +157 -0
  65. package/bundle/chunk-BUUVFUPO.js.map +7 -0
  66. package/bundle/chunk-CEVRHKJY.js +131 -0
  67. package/bundle/chunk-CEVRHKJY.js.map +7 -0
  68. package/bundle/chunk-CWOHNFUV.js +39 -0
  69. package/bundle/chunk-CWOHNFUV.js.map +7 -0
  70. package/bundle/chunk-D2DCBO6M.js +228 -0
  71. package/bundle/chunk-D2DCBO6M.js.map +7 -0
  72. package/bundle/chunk-FMWKEPM7.js +31 -0
  73. package/bundle/chunk-FMWKEPM7.js.map +7 -0
  74. package/bundle/chunk-GRNENTPA.js +145 -0
  75. package/bundle/chunk-GRNENTPA.js.map +7 -0
  76. package/bundle/chunk-GST5T3WZ.js +93 -0
  77. package/bundle/chunk-GST5T3WZ.js.map +7 -0
  78. package/bundle/chunk-GUQVJC3U.js +299 -0
  79. package/bundle/chunk-GUQVJC3U.js.map +7 -0
  80. package/bundle/chunk-HX7Y7EYP.js +3659 -0
  81. package/bundle/chunk-HX7Y7EYP.js.map +7 -0
  82. package/bundle/chunk-JCJS4ZIB.js +296 -0
  83. package/bundle/chunk-JCJS4ZIB.js.map +7 -0
  84. package/bundle/chunk-JW6RU47G.js +184 -0
  85. package/bundle/chunk-JW6RU47G.js.map +7 -0
  86. package/bundle/chunk-LSPKJQCI.js +24 -0
  87. package/bundle/chunk-LSPKJQCI.js.map +7 -0
  88. package/bundle/chunk-M6VBAPNT.js +16 -0
  89. package/bundle/chunk-M6VBAPNT.js.map +7 -0
  90. package/bundle/chunk-MPX525QO.js +129 -0
  91. package/bundle/chunk-MPX525QO.js.map +7 -0
  92. package/bundle/chunk-MW6WDLU7.js +130 -0
  93. package/bundle/chunk-MW6WDLU7.js.map +7 -0
  94. package/bundle/chunk-NT3OBORC.js +215 -0
  95. package/bundle/chunk-NT3OBORC.js.map +7 -0
  96. package/bundle/chunk-NWDBD4PA.js +50 -0
  97. package/bundle/chunk-NWDBD4PA.js.map +7 -0
  98. package/bundle/chunk-OP7BTAWY.js +29 -0
  99. package/bundle/chunk-OP7BTAWY.js.map +7 -0
  100. package/bundle/chunk-PLCY3GFH.js +77 -0
  101. package/bundle/chunk-PLCY3GFH.js.map +7 -0
  102. package/bundle/chunk-PNEDC45Y.js +97 -0
  103. package/bundle/chunk-PNEDC45Y.js.map +7 -0
  104. package/bundle/chunk-QBGBT5QS.js +81 -0
  105. package/bundle/chunk-QBGBT5QS.js.map +7 -0
  106. package/bundle/chunk-RVE2N7FA.js +70 -0
  107. package/bundle/chunk-RVE2N7FA.js.map +7 -0
  108. package/bundle/chunk-TZHIDLDS.js +71910 -0
  109. package/bundle/chunk-TZHIDLDS.js.map +7 -0
  110. package/bundle/chunk-UCQ2WC3B.js +126 -0
  111. package/bundle/chunk-UCQ2WC3B.js.map +7 -0
  112. package/bundle/chunk-UHRP745J.js +214 -0
  113. package/bundle/chunk-UHRP745J.js.map +7 -0
  114. package/bundle/chunk-V76TVMCM.js +58 -0
  115. package/bundle/chunk-V76TVMCM.js.map +7 -0
  116. package/bundle/chunk-VVEDVGCR.js +981 -0
  117. package/bundle/chunk-VVEDVGCR.js.map +7 -0
  118. package/bundle/chunk-W6FAL35D.js +102 -0
  119. package/bundle/chunk-W6FAL35D.js.map +7 -0
  120. package/bundle/chunk-X6TERNVJ.js +15902 -0
  121. package/bundle/chunk-X6TERNVJ.js.map +7 -0
  122. package/bundle/chunk-X76UX47U.js +47 -0
  123. package/bundle/chunk-X76UX47U.js.map +7 -0
  124. package/bundle/chunk-XREWVCUO.js +518 -0
  125. package/bundle/chunk-XREWVCUO.js.map +7 -0
  126. package/bundle/chunk-Y6XAEX2Q.js +408 -0
  127. package/bundle/chunk-Y6XAEX2Q.js.map +7 -0
  128. package/bundle/chunk-YOCTDKKL.js +28 -0
  129. package/bundle/chunk-YOCTDKKL.js.map +7 -0
  130. package/bundle/chunk-ZXPXCDA6.js +160 -0
  131. package/bundle/chunk-ZXPXCDA6.js.map +7 -0
  132. package/bundle/commands-BHVUOU3V.js +31 -0
  133. package/bundle/commands-BHVUOU3V.js.map +7 -0
  134. package/bundle/completion-buffer-P253ONKF.js +13 -0
  135. package/bundle/completion-buffer-P253ONKF.js.map +7 -0
  136. package/bundle/config-RGSDAPZN.js +19 -0
  137. package/bundle/config-RGSDAPZN.js.map +7 -0
  138. package/bundle/config-show-ERTATR6E.js +40 -0
  139. package/bundle/config-show-ERTATR6E.js.map +7 -0
  140. package/bundle/context-HCEGZNDC.js +72 -0
  141. package/bundle/context-HCEGZNDC.js.map +7 -0
  142. package/bundle/delegation-tools-GYTS2D6A.js +27 -0
  143. package/bundle/delegation-tools-GYTS2D6A.js.map +7 -0
  144. package/bundle/deploy-lib-import-32ZFKHWP.js +49 -0
  145. package/bundle/deploy-lib-import-32ZFKHWP.js.map +7 -0
  146. package/bundle/digital-signature-OFCGSHWO.js +13 -0
  147. package/bundle/digital-signature-OFCGSHWO.js.map +7 -0
  148. package/bundle/direct-api-transport-YR7SXXNN.js +860 -0
  149. package/bundle/direct-api-transport-YR7SXXNN.js.map +7 -0
  150. package/bundle/discord-adapter-YYWVMPPU.js +584 -0
  151. package/bundle/discord-adapter-YYWVMPPU.js.map +7 -0
  152. package/bundle/dist-MTMKARCP.js +1969 -0
  153. package/bundle/dist-MTMKARCP.js.map +7 -0
  154. package/bundle/dns-wakeup-27M7D2MR.js +107 -0
  155. package/bundle/dns-wakeup-27M7D2MR.js.map +7 -0
  156. package/bundle/doctor-QNUSDY73.js +248 -0
  157. package/bundle/doctor-QNUSDY73.js.map +7 -0
  158. package/bundle/ensure-invariants-NMXNS476.js +49 -0
  159. package/bundle/ensure-invariants-NMXNS476.js.map +7 -0
  160. package/bundle/env-schema-2KBHBDGN.js +19 -0
  161. package/bundle/env-schema-2KBHBDGN.js.map +7 -0
  162. package/bundle/esm-DDP6NCZG.js +100663 -0
  163. package/bundle/esm-DDP6NCZG.js.map +7 -0
  164. package/bundle/fallback-policy-L4QV2PEJ.js +46 -0
  165. package/bundle/fallback-policy-L4QV2PEJ.js.map +7 -0
  166. package/bundle/health-check-SPA7NT6N.js +56 -0
  167. package/bundle/health-check-SPA7NT6N.js.map +7 -0
  168. package/bundle/hook-system-6Q5YTR53.js +17 -0
  169. package/bundle/hook-system-6Q5YTR53.js.map +7 -0
  170. package/bundle/hotskills-K7BM4YLB.js +12 -0
  171. package/bundle/hotskills-K7BM4YLB.js.map +7 -0
  172. package/bundle/install-6HRZVKUM.js +15 -0
  173. package/bundle/install-6HRZVKUM.js.map +7 -0
  174. package/bundle/install-log-IAPHYKD4.js +28 -0
  175. package/bundle/install-log-IAPHYKD4.js.map +7 -0
  176. package/bundle/install-manifest-SPQRUNXL.js +102 -0
  177. package/bundle/install-manifest-SPQRUNXL.js.map +7 -0
  178. package/bundle/install-validate-PVLZXYLQ.js +53 -0
  179. package/bundle/install-validate-PVLZXYLQ.js.map +7 -0
  180. package/bundle/irc-adapter-OI5UZSQF.js +293 -0
  181. package/bundle/irc-adapter-OI5UZSQF.js.map +7 -0
  182. package/bundle/irc-config-55YO6EGB.js +88 -0
  183. package/bundle/irc-config-55YO6EGB.js.map +7 -0
  184. package/bundle/logs-ZNYXX5PA.js +19 -0
  185. package/bundle/logs-ZNYXX5PA.js.map +7 -0
  186. package/bundle/media-utils-XNNDTYFI.js +4662 -0
  187. package/bundle/media-utils-XNNDTYFI.js.map +7 -0
  188. package/bundle/message-pipeline-LLH5SYMO.js +33 -0
  189. package/bundle/message-pipeline-LLH5SYMO.js.map +7 -0
  190. package/bundle/meta.json +41304 -0
  191. package/bundle/model-health-registry-35LQNVQR.js +11 -0
  192. package/bundle/model-health-registry-35LQNVQR.js.map +7 -0
  193. package/bundle/notification-Y5S5MMLV.js +13 -0
  194. package/bundle/notification-Y5S5MMLV.js.map +7 -0
  195. package/bundle/openrouter-credits-EDY7ETAU.js +32 -0
  196. package/bundle/openrouter-credits-EDY7ETAU.js.map +7 -0
  197. package/bundle/passwd-RRFV4CC5.js +133 -0
  198. package/bundle/passwd-RRFV4CC5.js.map +7 -0
  199. package/bundle/paths-G33RZWZ7.js +17 -0
  200. package/bundle/paths-G33RZWZ7.js.map +7 -0
  201. package/bundle/peer-client-52XYMNI7.js +156 -0
  202. package/bundle/peer-client-52XYMNI7.js.map +7 -0
  203. package/bundle/peer-config-VK6EDLN5.js +16 -0
  204. package/bundle/peer-config-VK6EDLN5.js.map +7 -0
  205. package/bundle/peer-sessions-EAXTNQ36.js +49 -0
  206. package/bundle/peer-sessions-EAXTNQ36.js.map +7 -0
  207. package/bundle/pending-callback-RIMQZ7FJ.js +40 -0
  208. package/bundle/pending-callback-RIMQZ7FJ.js.map +7 -0
  209. package/bundle/phase-transport-KYERDL2O.js +22 -0
  210. package/bundle/phase-transport-KYERDL2O.js.map +7 -0
  211. package/bundle/public/css/dashboard.css +542 -0
  212. package/bundle/public/index.html +180 -0
  213. package/bundle/public/js/app.js +437 -0
  214. package/bundle/public/memory-universe.js +384 -0
  215. package/bundle/responses-adapter-AAQTY3K4.js +30 -0
  216. package/bundle/responses-adapter-AAQTY3K4.js.map +7 -0
  217. package/bundle/restore-ZE3SEPSS.js +46 -0
  218. package/bundle/restore-ZE3SEPSS.js.map +7 -0
  219. package/bundle/self-healer-utils-DMUUXC47.js +43 -0
  220. package/bundle/self-healer-utils-DMUUXC47.js.map +7 -0
  221. package/bundle/skill-stats-LLEXEXLR.js +22 -0
  222. package/bundle/skill-stats-LLEXEXLR.js.map +7 -0
  223. package/bundle/sleep-OYIUOVQD.js +19 -0
  224. package/bundle/sleep-OYIUOVQD.js.map +7 -0
  225. package/bundle/soul-loader-54WCVNLJ.js +16 -0
  226. package/bundle/soul-loader-54WCVNLJ.js.map +7 -0
  227. package/bundle/src-JL4PVO23.js +8 -0
  228. package/bundle/src-JL4PVO23.js.map +7 -0
  229. package/bundle/sse-parser-anthropic-P7CE2MH2.js +72 -0
  230. package/bundle/sse-parser-anthropic-P7CE2MH2.js.map +7 -0
  231. package/bundle/sse-parser-responses-EQQA5FWN.js +63 -0
  232. package/bundle/sse-parser-responses-EQQA5FWN.js.map +7 -0
  233. package/bundle/ssrf-guard-FZCBYIVW.js +64 -0
  234. package/bundle/ssrf-guard-FZCBYIVW.js.map +7 -0
  235. package/bundle/start-FH3GRMJ4.js +35 -0
  236. package/bundle/start-FH3GRMJ4.js.map +7 -0
  237. package/bundle/stream-single-WSG4D53C.js +33 -0
  238. package/bundle/stream-single-WSG4D53C.js.map +7 -0
  239. package/bundle/stt-2UH3RITX.js +14 -0
  240. package/bundle/stt-2UH3RITX.js.map +7 -0
  241. package/bundle/subagent-runtime-LE2ZXH3G.js +12 -0
  242. package/bundle/subagent-runtime-LE2ZXH3G.js.map +7 -0
  243. package/bundle/system-message-T5R3EYYN.js +30 -0
  244. package/bundle/system-message-T5R3EYYN.js.map +7 -0
  245. package/bundle/system-status-KQ6KHFJ6.js +189 -0
  246. package/bundle/system-status-KQ6KHFJ6.js.map +7 -0
  247. package/bundle/task-store-K7CQDEPI.js +22 -0
  248. package/bundle/task-store-K7CQDEPI.js.map +7 -0
  249. package/bundle/telegram-adapter-2V3XUMT5.js +1060 -0
  250. package/bundle/telegram-adapter-2V3XUMT5.js.map +7 -0
  251. package/bundle/tool-registry-MU3OX4UI.js +38 -0
  252. package/bundle/tool-registry-MU3OX4UI.js.map +7 -0
  253. package/bundle/tool-sandbox-VYOK4ZOA.js +20 -0
  254. package/bundle/tool-sandbox-VYOK4ZOA.js.map +7 -0
  255. package/bundle/transport-config-YLXU33RO.js +57 -0
  256. package/bundle/transport-config-YLXU33RO.js.map +7 -0
  257. package/bundle/update-QCW5LXRN.js +13 -0
  258. package/bundle/update-QCW5LXRN.js.map +7 -0
  259. package/bundle/update-check-27KZSAP6.js +12 -0
  260. package/bundle/update-check-27KZSAP6.js.map +7 -0
  261. package/bundle/usage-tracker-OVVEVMOY.js +17 -0
  262. package/bundle/usage-tracker-OVVEVMOY.js.map +7 -0
  263. package/bundle/user-registry-D4SD73UV.js +16 -0
  264. package/bundle/user-registry-D4SD73UV.js.map +7 -0
  265. package/core/professor.json +14 -0
  266. package/core/prompts/browsing_prompt.md +39 -0
  267. package/core/prompts/compaction.md +32 -0
  268. package/core/skills/memory/classification/SKILL.md +37 -0
  269. package/core/skills/memory/memory-anomalies/SKILL.md +39 -0
  270. package/core/skills/memory/memory-search/SKILL.md +48 -0
  271. package/core/skills/memory/topic-save/SKILL.md +44 -0
  272. package/core/skills/ops/cron/SKILL.md +51 -0
  273. package/core/skills/ops/gdrive-backup/SKILL.md +15 -0
  274. package/core/skills/ops/session-start/SKILL.md +11 -0
  275. package/core/skills/ops/skill-authoring/SKILL.md +54 -0
  276. package/core/skills/ops/system-health/SKILL.md +104 -0
  277. package/core/skills/ops/troubleshooting/SKILL.md +48 -0
  278. package/core/skills/ops/trust-gating/SKILL.md +30 -0
  279. package/core/skills/tools/a2a-communication/SKILL.md +68 -0
  280. package/core/skills/tools/browse-delegate/SKILL.md +27 -0
  281. package/core/skills/tools/browser/SKILL.md +36 -0
  282. package/core/skills/tools/clawhub/SKILL.md +44 -0
  283. package/core/skills/tools/delegation/SKILL.md +48 -0
  284. package/core/skills/tools/fxtwitter/SKILL.md +52 -0
  285. package/core/skills/tools/gmail/SKILL.md +44 -0
  286. package/core/skills/tools/irc-chat/SKILL.md +84 -0
  287. package/core/skills/tools/linear/SKILL.md +90 -0
  288. package/core/skills/tools/mcporter/SKILL.md +46 -0
  289. package/core/skills/tools/model-scout/SKILL.md +132 -0
  290. package/core/skills/tools/model-scout/scout-add-model.py +67 -0
  291. package/core/skills/tools/model-scout/scout-ollama.py +116 -0
  292. package/core/skills/tools/model-scout/scout-openrouter.py +85 -0
  293. package/core/skills/tools/nlm/SKILL.md +40 -0
  294. package/core/skills/tools/todo/SKILL.md +30 -0
  295. package/core/skills/tools/twitterX/SKILL.md +52 -0
  296. package/core/skills/tools/twitterX/scripts/abtars-tweet.js +532 -0
  297. package/core/skills/tools/twitterX/scripts/package.json +1 -0
  298. package/core/skills/tools/web-fetch/SKILL.md +29 -0
  299. package/package.json +59 -0
  300. package/scripts/abtars-daemon.service +23 -0
  301. package/scripts/abtars-fetch.sh +42 -0
  302. package/scripts/abtars-watchdog.service +13 -0
  303. package/scripts/abtars.sh +14 -0
  304. package/scripts/abtars@.service +21 -0
  305. package/scripts/browser-patchright.sh +79 -0
  306. package/scripts/com.abtars.daemon.plist +24 -0
  307. package/scripts/com.abtars.watchdog.plist +27 -0
  308. package/scripts/daily-backup.sh +62 -0
  309. package/scripts/doctor.sh +553 -0
  310. package/scripts/hooks/audit-logger.sh +22 -0
  311. package/scripts/upgrade-deps.sh +64 -0
  312. package/scripts/watchdog.sh +309 -0
@@ -0,0 +1,644 @@
1
+ import { createRequire as __bundleCreateRequire } from 'node:module'; import { fileURLToPath as __bundleFileURLToPath } from 'node:url'; import { dirname as __bundleDirname } from 'node:path'; const require = __bundleCreateRequire(import.meta.url); const __chunk_filename = __bundleFileURLToPath(import.meta.url); const __chunk_dirname = __bundleDirname(__chunk_filename);
2
+ import {
3
+ createAgentTransport
4
+ } from "./chunk-BSSBCSCL.js";
5
+ import {
6
+ loadUsers
7
+ } from "./chunk-GST5T3WZ.js";
8
+ import {
9
+ init_log_and_swallow,
10
+ logAndSwallow
11
+ } from "./chunk-FMWKEPM7.js";
12
+ import {
13
+ getEnv,
14
+ init_env_schema
15
+ } from "./chunk-JCJS4ZIB.js";
16
+ import {
17
+ init_logger,
18
+ isLogLevel,
19
+ logDebug,
20
+ logError,
21
+ logInfo,
22
+ logWarn
23
+ } from "./chunk-BUUVFUPO.js";
24
+ import {
25
+ abtarsHome,
26
+ init_paths
27
+ } from "./chunk-X76UX47U.js";
28
+
29
+ // src/boot/phase-transport.ts
30
+ init_log_and_swallow();
31
+ init_env_schema();
32
+ import { execSync as execSync2 } from "node:child_process";
33
+
34
+ // src/components/transport/tmux-client.ts
35
+ init_logger();
36
+ init_log_and_swallow();
37
+ init_paths();
38
+ import { execSync } from "node:child_process";
39
+ import { writeFileSync, unlinkSync, mkdirSync } from "node:fs";
40
+ import { join } from "node:path";
41
+ var TAG = "tmux";
42
+ var KIRO_PROMPT_RE = /^\d+%\s*!?>/;
43
+ var SHELL_PROMPT_RE = /[$❯%#]\s*$/;
44
+ var TmuxClient = class {
45
+ sessionName;
46
+ captureDelaySec;
47
+ maxWaitSec;
48
+ ready = false;
49
+ /** Optional callback for streaming intermediate responses before final prompt. */
50
+ onIntermediateResponse;
51
+ /** Tracks the cumulative text delivered via intermediate chunks (for tail detection). */
52
+ lastIntermediateDelivered = "";
53
+ constructor(sessionName, captureDelaySec, maxWaitSec) {
54
+ this.sessionName = sessionName;
55
+ this.captureDelaySec = captureDelaySec;
56
+ this.maxWaitSec = maxWaitSec;
57
+ }
58
+ async initialize() {
59
+ if (!this.sessionExists()) {
60
+ throw new Error(
61
+ `tmux session "${this.sessionName}" not found. Run: scripts/tmux-session.sh to start it.`
62
+ );
63
+ }
64
+ this.ready = true;
65
+ logInfo("tmux", `Session "${this.sessionName}" found`);
66
+ }
67
+ get isReady() {
68
+ return this.ready && this.sessionExists();
69
+ }
70
+ transportCommands = [];
71
+ async sendPrompt(_sessionKey, message) {
72
+ if (!this.isReady) {
73
+ throw new Error("tmux session not available");
74
+ }
75
+ this.lastIntermediateDelivered = "";
76
+ const maxAttempts = 2;
77
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
78
+ const before = this.capturePaneRaw();
79
+ if (attempt === 1) {
80
+ logDebug("tmux", `Sending: "${message.slice(0, 80)}"`);
81
+ } else {
82
+ logInfo("tmux", `Retry #${attempt}: resending prompt`);
83
+ }
84
+ try {
85
+ if (message.length > 4e3) {
86
+ const tmpDir = join(abtarsHome(), "tmp");
87
+ mkdirSync(tmpDir, { recursive: true });
88
+ const tmpFile = join(tmpDir, `prompt-${Date.now()}.txt`);
89
+ writeFileSync(tmpFile, message);
90
+ const readCmd = `My full message is in ${tmpFile} \u2014 please read it and respond.`;
91
+ const escaped = readCmd.replace(/'/g, "'\\''");
92
+ this.exec(`tmux send-keys -t ${this.sessionName} '${escaped}' Enter`);
93
+ setTimeout(() => {
94
+ try {
95
+ unlinkSync(tmpFile);
96
+ } catch (err) {
97
+ logAndSwallow(TAG, "unlink tmpFile", err);
98
+ }
99
+ }, 12e4);
100
+ } else {
101
+ const escaped = message.replace(/'/g, "'\\''");
102
+ this.exec(`tmux send-keys -t ${this.sessionName} '${escaped}' Enter`);
103
+ }
104
+ } catch (err) {
105
+ logWarn("tmux", `send-keys failed: ${err instanceof Error ? err.message : String(err)}`);
106
+ return "\u26A0\uFE0F Failed to send message to Kiro session. The tmux session may be in copy mode or unresponsive. Try /reset.";
107
+ }
108
+ await sleep(this.captureDelaySec * 1e3);
109
+ const response = await this.pollForResponse(before);
110
+ if (response.startsWith("Kiro is having trouble") && attempt < maxAttempts) {
111
+ logInfo("tmux", `Kiro trouble detected, will retry in 5s...`);
112
+ await sleep(5e3);
113
+ continue;
114
+ }
115
+ logDebug("tmux", `Got response (${response.length} chars)`);
116
+ return response;
117
+ }
118
+ return "\u26A0\uFE0F Kiro is having trouble responding. Try again or /reset.";
119
+ }
120
+ async resetSession(_sessionKey) {
121
+ if (!this.sessionExists()) return;
122
+ this.exec(`tmux send-keys -t ${this.sessionName} C-c`);
123
+ await sleep(1e3);
124
+ this.exec(`tmux send-keys -t ${this.sessionName} '/clear' Enter`);
125
+ await sleep(2e3);
126
+ this.exec(`tmux send-keys -t ${this.sessionName} 'y' Enter`);
127
+ await sleep(1e3);
128
+ }
129
+ async restartSession(workingDir, kiroModel) {
130
+ if (this.sessionExists()) {
131
+ this.exec(`tmux kill-session -t ${this.sessionName}`);
132
+ await sleep(1e3);
133
+ }
134
+ let cmd = `kiro-cli chat --trust-all-tools`;
135
+ if (kiroModel) cmd += ` --model ${kiroModel}`;
136
+ this.exec(`tmux new-session -d -s ${this.sessionName} -c '${workingDir}' '${cmd}'`);
137
+ this.exec(`tmux set-option -t ${this.sessionName} history-limit 5000`);
138
+ await sleep(3e3);
139
+ this.exec(`tmux send-keys -t ${this.sessionName} '/settings chat.enableThinking true' Enter`);
140
+ await sleep(2e3);
141
+ this.ready = this.sessionExists();
142
+ logInfo("tmux", `Session restarted (ready=${this.ready})`);
143
+ }
144
+ async sendInterrupt() {
145
+ if (!this.sessionExists()) return;
146
+ logInfo("tmux", "Sending Ctrl+C interrupt");
147
+ this.exec(`tmux send-keys -t ${this.sessionName} C-c`);
148
+ }
149
+ destroy() {
150
+ this.ready = false;
151
+ }
152
+ /**
153
+ * Poll capture-pane until Kiro's prompt reappears (N% >).
154
+ * Delivers intermediate purple-line responses via onIntermediateResponse callback
155
+ * so the user sees partial answers while Kiro continues with tools.
156
+ * Only returns when the actual Kiro prompt appears or timeout.
157
+ */
158
+ async pollForResponse(beforeSnapshot) {
159
+ const startTime = Date.now();
160
+ const maxWaitMs = this.maxWaitSec * 1e3;
161
+ let lastCapture = "";
162
+ let stableCount = 0;
163
+ let lastDeliveredAnswer = "";
164
+ while (Date.now() - startTime < maxWaitMs) {
165
+ const capture = this.capturePaneRaw();
166
+ const newContent = this.diffOutput(beforeSnapshot, capture);
167
+ if (newContent.length === 0) {
168
+ await sleep(2e3);
169
+ continue;
170
+ }
171
+ const lines = capture.split("\n");
172
+ const lastNonEmpty = this.getLastNonEmptyLine(lines);
173
+ const lastClean = this.stripAnsi(lastNonEmpty);
174
+ if (KIRO_PROMPT_RE.test(lastClean)) {
175
+ const pctMatch = lastClean.match(/^(\d+)%/);
176
+ if (pctMatch) {
177
+ this.lastContextPercent = parseInt(pctMatch[1], 10);
178
+ logDebug("tmux", `Context window: ${this.lastContextPercent}%`);
179
+ }
180
+ logDebug("tmux", `Detected Kiro prompt: "${lastClean}"`);
181
+ return this.extractResponse(newContent);
182
+ }
183
+ if (SHELL_PROMPT_RE.test(lastClean) && newContent.length > 10) {
184
+ logDebug("tmux", `Detected shell prompt: "${lastClean}"`);
185
+ return this.extractResponse(newContent);
186
+ }
187
+ if (this.onIntermediateResponse && capture !== lastCapture) {
188
+ const intermediateAnswer = this.extractAnswerOnly(newContent);
189
+ if (intermediateAnswer && intermediateAnswer !== lastDeliveredAnswer) {
190
+ const newPart = intermediateAnswer.startsWith(lastDeliveredAnswer) ? intermediateAnswer.slice(lastDeliveredAnswer.length).trim() : intermediateAnswer;
191
+ if (newPart) {
192
+ logDebug("tmux", `Delivering intermediate chunk (${newPart.length} chars)`);
193
+ this.onIntermediateResponse(newPart);
194
+ lastDeliveredAnswer = intermediateAnswer;
195
+ this.lastIntermediateDelivered = intermediateAnswer;
196
+ }
197
+ }
198
+ }
199
+ if (capture === lastCapture) {
200
+ stableCount++;
201
+ } else {
202
+ stableCount = 0;
203
+ lastCapture = capture;
204
+ }
205
+ await sleep(2e3);
206
+ }
207
+ const finalCapture = this.capturePaneRaw();
208
+ const finalNew = this.diffOutput(beforeSnapshot, finalCapture);
209
+ if (finalNew.length > 0) {
210
+ return this.extractResponse(finalNew) + "\n\n\u23F1\uFE0F (response may be incomplete \u2014 timed out)";
211
+ }
212
+ return "\u23F1\uFE0F Kiro is still processing. Check the tmux session directly.";
213
+ }
214
+ /**
215
+ * Extract the meaningful response from the diff.
216
+ * Removes the echoed user input line and Kiro's prompt lines.
217
+ * Stores the "answer only" portion (lines that were "> " prefixed)
218
+ * separately for TTS use.
219
+ *
220
+ * Kiro output format:
221
+ * N% > <echoed user input>
222
+ * > <response line 1>
223
+ * > <response line 2>
224
+ * ▸ Time: Ns
225
+ * M% >
226
+ */
227
+ lastAnswerOnly = "";
228
+ lastContextPercent = -1;
229
+ /** Get just the Kiro answer lines ("> " prefixed) from the last response — for TTS. */
230
+ get answerOnly() {
231
+ return this.lastAnswerOnly;
232
+ }
233
+ get toolCallsSucceeded() {
234
+ return 0;
235
+ }
236
+ /** Get the context window usage percentage from the last Kiro prompt (e.g. 10 for "10% >"). Returns -1 if unknown. */
237
+ get contextPercent() {
238
+ return this.lastContextPercent;
239
+ }
240
+ /** Get the cumulative text that was delivered via intermediate streaming. */
241
+ get intermediateDeliveredText() {
242
+ return this.lastIntermediateDelivered;
243
+ }
244
+ /** Extract just the purple "> " answer lines from raw tmux output (no side effects). */
245
+ extractAnswerOnly(raw) {
246
+ const PURPLE_PREFIX = /\x1b\[38;5;141m>\s/;
247
+ const lines = raw.split("\n");
248
+ let blockStart = -1;
249
+ for (let i = lines.length - 1; i >= 0; i--) {
250
+ if (PURPLE_PREFIX.test(lines[i])) {
251
+ blockStart = i;
252
+ while (blockStart > 0 && PURPLE_PREFIX.test(lines[blockStart - 1])) blockStart--;
253
+ break;
254
+ }
255
+ }
256
+ if (blockStart < 0) return "";
257
+ const answerLines = [];
258
+ for (let i = blockStart; i < lines.length; i++) {
259
+ const clean = this.stripAnsi(lines[i]).trim();
260
+ if (KIRO_PROMPT_RE.test(clean)) break;
261
+ if (clean.startsWith("\u25B8 Time:")) break;
262
+ if (clean.startsWith("> ")) answerLines.push(clean.slice(2));
263
+ else if (clean === ">") answerLines.push("");
264
+ else if (clean === "") answerLines.push("");
265
+ else answerLines.push(clean);
266
+ }
267
+ return answerLines.join("\n").trim();
268
+ }
269
+ extractResponse(raw) {
270
+ const PURPLE_PREFIX = /\x1b\[38;5;141m>\s/;
271
+ const lines = raw.split("\n");
272
+ const answerLines = [];
273
+ let lastPurpleBlockStart = -1;
274
+ for (let i = 0; i < lines.length; i++) {
275
+ if (PURPLE_PREFIX.test(lines[i])) {
276
+ if (lastPurpleBlockStart === -1) lastPurpleBlockStart = i;
277
+ }
278
+ }
279
+ let blockStart = -1;
280
+ for (let i = lines.length - 1; i >= 0; i--) {
281
+ if (PURPLE_PREFIX.test(lines[i])) {
282
+ blockStart = i;
283
+ while (blockStart > 0) {
284
+ const prev = lines[blockStart - 1];
285
+ if (PURPLE_PREFIX.test(prev) || !KIRO_PROMPT_RE.test(this.stripAnsi(prev).trim()) && !prev.includes("\u25B8 Time:") && this.stripAnsi(prev).trim() !== "" && !PURPLE_PREFIX.test(prev) && blockStart === i) {
286
+ if (PURPLE_PREFIX.test(prev)) {
287
+ blockStart--;
288
+ } else {
289
+ break;
290
+ }
291
+ } else {
292
+ break;
293
+ }
294
+ }
295
+ break;
296
+ }
297
+ }
298
+ if (blockStart >= 0) {
299
+ for (let i = blockStart; i < lines.length; i++) {
300
+ const line = lines[i];
301
+ const clean = this.stripAnsi(line).trim();
302
+ if (KIRO_PROMPT_RE.test(clean)) break;
303
+ if (clean.startsWith("\u25B8 Time:") || clean.startsWith("\u25B8 Time:")) break;
304
+ if (clean === "") {
305
+ answerLines.push("");
306
+ continue;
307
+ }
308
+ if (clean.startsWith("> ")) {
309
+ answerLines.push(clean.slice(2));
310
+ } else if (clean === ">") {
311
+ answerLines.push("");
312
+ } else {
313
+ answerLines.push(clean);
314
+ }
315
+ }
316
+ this.lastAnswerOnly = answerLines.join("\n").trim();
317
+ } else {
318
+ this.lastAnswerOnly = "";
319
+ }
320
+ const cleaned = this.stripAnsi(raw);
321
+ const allLines = cleaned.split("\n");
322
+ const result = [];
323
+ for (const line of allLines) {
324
+ const trimmed = line.trim();
325
+ if (result.length === 0 && trimmed === "") continue;
326
+ if (KIRO_PROMPT_RE.test(trimmed)) continue;
327
+ if (trimmed.startsWith("\u25B8 Time:") || trimmed.startsWith("\u25B8 Time:")) continue;
328
+ if (/^-{4,}$/.test(trimmed)) continue;
329
+ result.push(line);
330
+ }
331
+ const stripped = result.map((line) => {
332
+ const trimmed = line.trimStart();
333
+ if (trimmed.startsWith("> ")) return trimmed.slice(2);
334
+ if (trimmed === ">") return "";
335
+ return line;
336
+ });
337
+ const final = stripped.join("\n").trim();
338
+ logDebug("tmux", `extractResponse: ${result.length} lines \u2192 "${final.slice(0, 120)}"`);
339
+ if (this.lastAnswerOnly) {
340
+ logDebug("tmux", `answerOnly (${this.lastAnswerOnly.length} chars): "${this.lastAnswerOnly.slice(0, 120)}"`);
341
+ }
342
+ return final;
343
+ }
344
+ /** Get new content by diffing before/after snapshots. */
345
+ diffOutput(before, after) {
346
+ const beforeLines = before.split("\n");
347
+ const afterLines = after.split("\n");
348
+ let commonPrefix = 0;
349
+ while (commonPrefix < beforeLines.length && commonPrefix < afterLines.length && beforeLines[commonPrefix] === afterLines[commonPrefix]) {
350
+ commonPrefix++;
351
+ }
352
+ return afterLines.slice(commonPrefix).join("\n").trim();
353
+ }
354
+ /** Get the last non-empty line from an array. */
355
+ getLastNonEmptyLine(lines) {
356
+ for (let i = lines.length - 1; i >= 0; i--) {
357
+ const trimmed = lines[i].trim();
358
+ if (trimmed.length > 0) return trimmed;
359
+ }
360
+ return "";
361
+ }
362
+ /** Strip ANSI escape codes. */
363
+ stripAnsi(text) {
364
+ return text.replace(/\x1B\[[0-9;]*[a-zA-Z]/g, "").replace(/\x1B\][^\x07]*\x07/g, "");
365
+ }
366
+ capturePaneRaw() {
367
+ try {
368
+ return this.exec(`tmux capture-pane -t ${this.sessionName} -p -e -S -2000`);
369
+ } catch (err) {
370
+ logAndSwallow(TAG, "capturePaneRaw", err);
371
+ return "";
372
+ }
373
+ }
374
+ sessionExists() {
375
+ try {
376
+ this.exec(`tmux has-session -t ${this.sessionName}`);
377
+ return true;
378
+ } catch (err) {
379
+ logAndSwallow(TAG, "sessionExists check", err);
380
+ return false;
381
+ }
382
+ }
383
+ exec(command) {
384
+ return execSync(command, {
385
+ encoding: "utf-8",
386
+ timeout: 15e3,
387
+ stdio: ["pipe", "pipe", "pipe"]
388
+ }).trim();
389
+ }
390
+ };
391
+ function sleep(ms) {
392
+ return new Promise((resolve) => setTimeout(resolve, ms));
393
+ }
394
+
395
+ // src/boot/phase-transport.ts
396
+ init_logger();
397
+
398
+ // src/boot/ctx-start.ts
399
+ init_log_and_swallow();
400
+ import { readFileSync, writeFileSync as writeFileSync2 } from "node:fs";
401
+ import { join as join2 } from "node:path";
402
+ function updateCtxStart(memoryDir, userId, ts = Date.now()) {
403
+ const p = join2(memoryDir, "context-window-start.json");
404
+ let data = {};
405
+ try {
406
+ data = JSON.parse(readFileSync(p, "utf-8"));
407
+ } catch (err) {
408
+ logAndSwallow("ctx_start", "op", err);
409
+ }
410
+ data[userId] = ts;
411
+ writeFileSync2(p, JSON.stringify(data), "utf-8");
412
+ }
413
+ function resetAllCtxStarts(memoryDir) {
414
+ const p = join2(memoryDir, "context-window-start.json");
415
+ let data = {};
416
+ try {
417
+ data = JSON.parse(readFileSync(p, "utf-8"));
418
+ } catch (err) {
419
+ logAndSwallow("ctx_start", "read ctx-start json", err);
420
+ return;
421
+ }
422
+ const now = Date.now();
423
+ for (const key of Object.keys(data)) data[key] = now;
424
+ writeFileSync2(p, JSON.stringify(data), "utf-8");
425
+ }
426
+
427
+ // src/boot/phase-transport.ts
428
+ var TAG2 = "transport";
429
+ async function phaseTransport(ctx) {
430
+ const { memoryConfig } = ctx;
431
+ await buildTransport(ctx);
432
+ if (memoryConfig.memoryEnabled) {
433
+ const reg = loadUsers();
434
+ for (const user of reg.users) updateCtxStart(memoryConfig.memoryDir, user.userId, ctx.startedAt);
435
+ }
436
+ return "ran";
437
+ }
438
+ async function buildTransport(ctx) {
439
+ const { config, memoryConfig } = ctx;
440
+ let transport;
441
+ const { resolveAgent, getEnvFallback, loadTransport, resolveHailMary, clearTransportCache, validateProviderReady } = await import("./transport-config-YLXU33RO.js");
442
+ clearTransportCache();
443
+ const tc = loadTransport();
444
+ const prof = tc ? resolveAgent("professor", tc) : null;
445
+ const hm = resolveHailMary(tc);
446
+ if (hm) {
447
+ ctx.hailMary = {
448
+ model: hm.model,
449
+ endpoint: hm.endpoint,
450
+ apiKey: hm.apiKeyEnv ? getEnv().getApiKey(hm.apiKeyEnv) : void 0
451
+ };
452
+ logInfo("main", `\u{1F6A8} hailMary configured: ${hm.model} (manual /model emergency only)`);
453
+ } else {
454
+ ctx.hailMary = null;
455
+ }
456
+ let resolved = prof ?? (() => {
457
+ const fb = getEnvFallback();
458
+ logWarn("main", `\u26A0\uFE0F Using .env fallback: ${fb.model} via ${fb.providerName}`);
459
+ return { model: fb.model, provider: fb.provider, providerName: fb.providerName, contextWindow: fb.contextWindow, maxOutput: fb.maxOutput, fallbacks: [] };
460
+ })();
461
+ const validation = validateProviderReady(resolved.providerName, resolved.provider, getEnv());
462
+ if (!validation.ok) {
463
+ const errMsg = `transport.json configures '${resolved.providerName}' but ${validation.reason}. Fix: ${validation.fix}`;
464
+ if (ctx.transport) {
465
+ logError("main", `${errMsg} \u2014 keeping existing transport up (skipping rebuild)`);
466
+ return "ran";
467
+ }
468
+ if (prof) {
469
+ const fb = getEnvFallback();
470
+ logError("main", `${errMsg} \u2014 falling back to .env config (${fb.model} via ${fb.providerName})`);
471
+ resolved = { model: fb.model, provider: fb.provider, providerName: fb.providerName, contextWindow: fb.contextWindow, maxOutput: fb.maxOutput, fallbacks: [] };
472
+ const fbValidation = validateProviderReady(resolved.providerName, resolved.provider, getEnv());
473
+ if (!fbValidation.ok) {
474
+ logError("main", `.env fallback '${resolved.providerName}' also invalid: ${fbValidation.reason}`);
475
+ throw new Error(`${errMsg} (and .env fallback is also invalid: ${fbValidation.reason})`);
476
+ }
477
+ } else {
478
+ throw new Error(errMsg);
479
+ }
480
+ }
481
+ if (ctx.transport) {
482
+ try {
483
+ await ctx.transport.destroy();
484
+ } catch (err) {
485
+ logWarn("main", `Old transport destroy failed: ${err instanceof Error ? err.message : String(err)}`);
486
+ }
487
+ ctx.transport = null;
488
+ }
489
+ if (resolved.provider.transport === "tmux") {
490
+ const defaults = tc?.transportDefaults?.tmux;
491
+ logInfo("main", `\u{1F5A5}\uFE0F tmux transport (${resolved.providerName})`);
492
+ transport = new TmuxClient(
493
+ defaults?.session ?? config.transport.tmuxSession,
494
+ defaults?.captureDelaySec ?? config.transport.tmuxCaptureDelaySec,
495
+ defaults?.maxWaitSec ?? config.transport.tmuxMaxWaitSec
496
+ );
497
+ } else if (resolved.provider.transport === "api") {
498
+ const { DirectApiTransport } = await import("./direct-api-transport-YR7SXXNN.js");
499
+ const { ModelHealthRegistry } = await import("./model-health-registry-35LQNVQR.js");
500
+ const { FallbackPolicy } = await import("./fallback-policy-L4QV2PEJ.js");
501
+ const apiKey = getEnv().getApiKey(resolved.provider.apiKeyEnv ?? "API_KEY");
502
+ const candidates = [
503
+ { endpoint: resolved.provider.endpoint ?? "http://localhost:11434/v1", apiKey, model: resolved.model, maxContext: resolved.contextWindow }
504
+ ];
505
+ for (const fb of resolved.fallbacks) {
506
+ const fbResolved = tc ? resolveAgent("_fallback", { ...tc, agents: { ...tc.agents, _fallback: { model: fb.model, provider: fb.provider } } }) : null;
507
+ candidates.push({
508
+ endpoint: fbResolved?.provider.endpoint ?? resolved.provider.endpoint,
509
+ apiKey: fbResolved?.provider.apiKeyEnv ? getEnv().getApiKey(fbResolved.provider.apiKeyEnv) : apiKey,
510
+ model: fb.model,
511
+ maxContext: fbResolved?.contextWindow ?? resolved.contextWindow
512
+ });
513
+ }
514
+ if (!ctx.modelHealthRegistry) {
515
+ ctx.modelHealthRegistry = new ModelHealthRegistry(tc?.healthPolicy);
516
+ }
517
+ if (!ctx.modelHealthRegistry.onDemote) {
518
+ ctx.modelHealthRegistry.onDemote = (model, _endpoint, reason) => {
519
+ import("./transport-config-YLXU33RO.js").then(({ demoteModel }) => demoteModel(model, reason));
520
+ import("./notification-Y5S5MMLV.js").then(({ sendNotification }) => sendNotification(ctx, `\u26A0\uFE0F ${model} demoted (${reason}). Next healthy model promoted.`)).catch((err) => logAndSwallow(TAG2, "sendNotification model-demote", err));
521
+ };
522
+ }
523
+ const policy = new FallbackPolicy(candidates, ctx.modelHealthRegistry);
524
+ transport = new DirectApiTransport({
525
+ endpoint: resolved.provider.endpoint ?? "http://localhost:11434/v1",
526
+ apiKey,
527
+ model: resolved.model,
528
+ maxContext: resolved.contextWindow,
529
+ maxOutput: resolved.maxOutput,
530
+ maxTurns: tc?.maxTurns ?? 50,
531
+ apiFormat: resolved.provider.apiFormat,
532
+ thinking: resolved.provider.thinking
533
+ }, policy);
534
+ logInfo("main", `\u{1F50C} Direct API transport (${resolved.providerName}, model=${resolved.model}, ${candidates.length} candidates)`);
535
+ } else {
536
+ try {
537
+ execSync2("pkill -f 'kiro-cli.*acp.*professor' 2>/dev/null || true", { timeout: 3e3 });
538
+ } catch (err) {
539
+ logAndSwallow("phase_transport", "op", err);
540
+ }
541
+ logInfo("main", `\u{1F50C} ACP transport (${resolved.provider.cli ?? "kiro-cli"}, model=${resolved.model})`);
542
+ transport = createAgentTransport("professor", {
543
+ cliPath: resolved.provider.cli ?? config.transport.agentCliPath,
544
+ workingDir: config.transport.workingDir,
545
+ agentCli: resolved.provider.cli ?? "kiro-cli",
546
+ model: resolved.model
547
+ });
548
+ }
549
+ await transport.initialize();
550
+ if ("setSystemPrompt" in transport && typeof transport.setSystemPrompt === "function") {
551
+ const { loadSoulBundle } = await import("./soul-loader-54WCVNLJ.js");
552
+ const soul = loadSoulBundle();
553
+ if (soul) transport.setSystemPrompt(soul);
554
+ }
555
+ if (resolved.fallbacks.length > 0 && resolved.provider.transport !== "api") {
556
+ logWarn("main", `\u26A0\uFE0F Fallbacks configured for ${resolved.provider.transport} transport \u2014 only API transport supports model fallback`);
557
+ }
558
+ ctx.transport = transport;
559
+ ctx.modelName = resolved.model;
560
+ ctx.modelProvider = resolved.providerName;
561
+ ctx.fallbackChain = resolved.fallbacks.map((f) => f.model);
562
+ if (ctx.modelHealthRegistry) {
563
+ ctx.runtime.setRegistry(ctx.modelHealthRegistry);
564
+ }
565
+ ctx.runtime.setMainTransport(transport);
566
+ ctx.runtime.setSessionManager(ctx.sessionManager);
567
+ if (getEnv().enableAsyncDelegation) {
568
+ const { setDelegationDeps } = await import("./delegation-tools-GYTS2D6A.js");
569
+ setDelegationDeps(ctx.runtime, ctx.sessionManager);
570
+ }
571
+ logInfo("main", "\u2705 Transport ready");
572
+ if (resolved.provider.transport === "api" && ctx.memory) {
573
+ const { setMemoryBackend } = await import("./tool-registry-MU3OX4UI.js");
574
+ const { SqliteBackend } = await import("abmind");
575
+ const backend = new SqliteBackend(memoryConfig);
576
+ await backend.initialize();
577
+ setMemoryBackend(backend);
578
+ logInfo("main", "\u{1F9E0} In-process memory wired to tool registry");
579
+ const db = ctx.memory.getDb?.() ?? ctx.memory.getDatabase?.();
580
+ if (db && resolved.contextWindow >= 128e3) {
581
+ const { ContextEngine } = await import("abmind");
582
+ const { createContextOrchestrator } = await import("./context-HCEGZNDC.js");
583
+ const contextEngine = new ContextEngine(db);
584
+ const orchestrator = createContextOrchestrator(
585
+ contextEngine,
586
+ async (systemPrompt, userPrompt) => {
587
+ const { streamSingleCompletion } = await import("./stream-single-WSG4D53C.js");
588
+ return streamSingleCompletion({
589
+ endpoint: resolved.provider.endpoint ?? "http://localhost:11434/v1",
590
+ apiKey: getEnv().getApiKey(resolved.provider.apiKeyEnv ?? "API_KEY") ?? void 0,
591
+ model: resolved.model,
592
+ systemPrompt,
593
+ userPrompt,
594
+ maxTokens: 4096
595
+ });
596
+ },
597
+ (_chatId) => {
598
+ try {
599
+ return ctx.memory?.getLastMessageTimestamp(true) ?? null;
600
+ } catch (err) {
601
+ logAndSwallow(TAG2, "getLastMessageTimestamp", err);
602
+ return null;
603
+ }
604
+ }
605
+ );
606
+ transport.contextOrchestrator = orchestrator;
607
+ logInfo("main", "\u{1F4E6} Context engine wired (auto-compaction active)");
608
+ }
609
+ }
610
+ if ("onFallback" in transport) {
611
+ let lastNotifiedModel = null;
612
+ transport.onFallback = (model, ctxPct, reason) => {
613
+ const reasonTag = reason ? ` (${reason})` : "";
614
+ const msg = `\u26A1 Fallback${reasonTag}: ${model}${ctxPct >= 0 ? ` (ctx: ~${ctxPct}%)` : ""}`;
615
+ logInfo("main", msg);
616
+ if (model !== lastNotifiedModel || isLogLevel("debug")) {
617
+ lastNotifiedModel = model;
618
+ import("./notification-Y5S5MMLV.js").then(({ sendNotification }) => sendNotification(ctx, msg)).catch((err) => logAndSwallow(TAG2, "sendNotification fallback", err));
619
+ }
620
+ };
621
+ }
622
+ return "ran";
623
+ }
624
+ async function rebuildTransport(ctx) {
625
+ logInfo("main", "\u{1F504} Rebuilding transport...");
626
+ await buildTransport(ctx);
627
+ if (ctx.pipelineDeps && ctx.transport) {
628
+ ctx.pipelineDeps.transport = ctx.transport;
629
+ }
630
+ if (ctx.idleSave && ctx.transport) {
631
+ ctx.idleSave.transport = ctx.transport;
632
+ }
633
+ logInfo("main", "\u2705 Transport rebuilt");
634
+ return "ran";
635
+ }
636
+
637
+ export {
638
+ updateCtxStart,
639
+ resetAllCtxStarts,
640
+ phaseTransport,
641
+ buildTransport,
642
+ rebuildTransport
643
+ };
644
+ //# sourceMappingURL=chunk-6UCRKRWR.js.map