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,159 @@
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
+ AcpTransport
4
+ } from "./chunk-X6TERNVJ.js";
5
+ import {
6
+ getEnv,
7
+ init_env_schema
8
+ } from "./chunk-JCJS4ZIB.js";
9
+ import {
10
+ init_logger,
11
+ logInfo,
12
+ logWarn
13
+ } from "./chunk-BUUVFUPO.js";
14
+
15
+ // src/components/agent-registry.ts
16
+ init_env_schema();
17
+ init_logger();
18
+ var AGENT_ROLES = {
19
+ professor: { agent: "professor", model: null, persona: "persona/core/SOUL.md", autoReinit: true, tag: "acp-main", trust: 3 },
20
+ dreamy: { agent: "dreamy", model: null, persona: "persona/prompts/sleep/00-identity.md", autoReinit: false, tag: "acp-sleep", trust: 2 },
21
+ coding: { agent: "coding-agent", model: null, persona: null, autoReinit: true, tag: "acp-coding", trust: 2 },
22
+ browsie: { agent: "browsie", model: null, persona: null, autoReinit: false, tag: "acp-browsie", trust: 1 },
23
+ task: { agent: "professor", model: null, persona: null, autoReinit: false, tag: "acp-task", trust: 2 }
24
+ };
25
+ function resolveModel(role) {
26
+ switch (role) {
27
+ case "dreamy":
28
+ return getEnv().sleepModel;
29
+ case "browsie":
30
+ return getEnv().browsingAgent;
31
+ case "coding":
32
+ return getEnv().codingModel;
33
+ default:
34
+ return void 0;
35
+ }
36
+ }
37
+ function createAgentTransport(role, tc, overrides) {
38
+ const cfg = { ...AGENT_ROLES[role], ...overrides };
39
+ const cliArgs = tc.agentCli === "gemini" ? ["--acp", "-y"] : void 0;
40
+ const model = tc.model ?? resolveModel(role);
41
+ return new AcpTransport(tc.cliPath, tc.workingDir, {
42
+ agent: cfg.agent ?? void 0,
43
+ model,
44
+ autoReinit: cfg.autoReinit,
45
+ tag: cfg.tag,
46
+ cliArgs
47
+ });
48
+ }
49
+ var SUBAGENT_TO_AGENT = {
50
+ sleep: "dreamy",
51
+ browse: "browsie",
52
+ coding: "coding",
53
+ task: "professor"
54
+ };
55
+ var SUBAGENT_ACP_ROLE = {
56
+ sleep: "dreamy",
57
+ browse: "browsie",
58
+ coding: "coding",
59
+ task: "task"
60
+ };
61
+ async function createSubagentTransport(role, registry, currentModel) {
62
+ const { resolveAgent, getEnvFallback, loadTransport } = await import("./transport-config-YLXU33RO.js");
63
+ const tc = loadTransport();
64
+ const agentName = SUBAGENT_TO_AGENT[role];
65
+ const resolved = tc ? resolveAgent(agentName, tc) : null;
66
+ const profResolved = resolved ?? (tc ? resolveAgent("professor", tc) : null);
67
+ const agent = profResolved ?? (() => {
68
+ const fb = getEnvFallback();
69
+ return { model: fb.model, provider: fb.provider, providerName: fb.providerName, contextWindow: fb.contextWindow, maxOutput: fb.maxOutput, fallbacks: [] };
70
+ })();
71
+ if (agent.provider.transport === "api") {
72
+ const { DirectApiTransport } = await import("./direct-api-transport-YR7SXXNN.js");
73
+ const { FallbackPolicy } = await import("./fallback-policy-L4QV2PEJ.js");
74
+ const apiKey = getEnv().getApiKey(agent.provider.apiKeyEnv ?? "API_KEY");
75
+ const startModel = currentModel ?? agent.model;
76
+ const candidates = [
77
+ { endpoint: agent.provider.endpoint ?? "http://localhost:11434/v1", apiKey, model: startModel, maxContext: agent.contextWindow }
78
+ ];
79
+ if (agent.model !== startModel && !candidates.some((c) => c.model === agent.model)) {
80
+ candidates.push({ endpoint: agent.provider.endpoint ?? "http://localhost:11434/v1", apiKey, model: agent.model, maxContext: agent.contextWindow });
81
+ }
82
+ const profAgent = tc ? resolveAgent("professor", tc) : null;
83
+ const agentTransport = agent.provider.transport ?? "api";
84
+ if (profAgent && profAgent.model !== startModel && !candidates.some((c) => c.model === profAgent.model)) {
85
+ const profTransport = profAgent.provider.transport ?? "api";
86
+ if (profTransport === agentTransport && profAgent.provider.endpoint) {
87
+ candidates.push({
88
+ endpoint: profAgent.provider.endpoint,
89
+ apiKey: profAgent.provider.apiKeyEnv ? getEnv().getApiKey(profAgent.provider.apiKeyEnv) : apiKey,
90
+ model: profAgent.model,
91
+ maxContext: profAgent.contextWindow
92
+ });
93
+ }
94
+ }
95
+ for (const fb of agent.fallbacks) {
96
+ if (candidates.some((c) => c.model === fb.model)) continue;
97
+ const fbProvider = tc?.providers[fb.provider];
98
+ const fbEndpoint = fbProvider?.endpoint ?? agent.provider.endpoint ?? "http://localhost:11434/v1";
99
+ const fbApiKey = fbProvider?.apiKeyEnv ? getEnv().getApiKey(fbProvider.apiKeyEnv) : apiKey;
100
+ candidates.push({ endpoint: fbEndpoint, apiKey: fbApiKey, model: fb.model, maxContext: agent.contextWindow });
101
+ }
102
+ const chain2 = agent.provider.fallbackChain ?? [];
103
+ for (const chainModel of chain2) {
104
+ if (!candidates.some((c) => c.model === chainModel)) {
105
+ candidates.push({
106
+ endpoint: agent.provider.endpoint ?? "http://localhost:11434/v1",
107
+ apiKey,
108
+ model: chainModel,
109
+ maxContext: agent.contextWindow
110
+ });
111
+ }
112
+ }
113
+ const { ModelHealthRegistry } = await import("./model-health-registry-35LQNVQR.js");
114
+ const policy = new FallbackPolicy(candidates, registry ?? new ModelHealthRegistry());
115
+ const transport = new DirectApiTransport({
116
+ endpoint: agent.provider.endpoint ?? "http://localhost:11434/v1",
117
+ apiKey,
118
+ model: startModel,
119
+ maxContext: agent.contextWindow,
120
+ maxOutput: agent.maxOutput,
121
+ maxTurns: tc?.maxTurns ?? 50
122
+ }, policy);
123
+ await transport.initialize();
124
+ logInfo("subagent", `${role} transport: DirectAPI ${agent.providerName} (model=${startModel}, ${candidates.length} candidates, shared registry: ${!!registry})`);
125
+ return { transport, model: agent.model };
126
+ }
127
+ const { loadAndValidateConfig } = await import("./config-RGSDAPZN.js");
128
+ const config = await loadAndValidateConfig();
129
+ const chain = agent.provider.fallbackChain ?? [];
130
+ const modelsToTry = [agent.model, ...chain.filter((m) => m !== agent.model)];
131
+ for (let i = 0; i < modelsToTry.length; i++) {
132
+ const model = modelsToTry[i];
133
+ const transport = createAgentTransport(SUBAGENT_ACP_ROLE[role], {
134
+ cliPath: agent.provider.cli ?? config.transport.agentCliPath,
135
+ workingDir: config.transport.workingDir,
136
+ agentCli: agent.provider.cli ?? "kiro-cli",
137
+ model
138
+ });
139
+ try {
140
+ await transport.initialize();
141
+ if (i > 0) logWarn("subagent", `${role}: configured model failed, fell back to ${model}`);
142
+ logInfo("subagent", `${role} transport: ACP ${agent.providerName} (model=${model}${i > 0 ? ", fallback" : ""})`);
143
+ return { transport, model };
144
+ } catch (err) {
145
+ if (i < modelsToTry.length - 1) {
146
+ logWarn("subagent", `${role}: model ${model} init failed (${err instanceof Error ? err.message : String(err)}), trying ${modelsToTry[i + 1]}`);
147
+ continue;
148
+ }
149
+ throw err;
150
+ }
151
+ }
152
+ throw new Error(`${role}: all models exhausted (tried ${modelsToTry.join(", ")})`);
153
+ }
154
+
155
+ export {
156
+ createAgentTransport,
157
+ createSubagentTransport
158
+ };
159
+ //# sourceMappingURL=chunk-BSSBCSCL.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/components/agent-registry.ts"],
4
+ "sourcesContent": ["import { getEnv } from \"./env-schema.js\";\n/**\n * agent-registry.ts \u2014 Centralized agent role configuration.\n * Single factory for all agent transports. Transport-agnostic.\n */\n\nimport { AcpTransport } from \"./transport/acp-transport.js\";\nimport { logInfo, logWarn } from \"./logger.js\";\nimport type { IKiroTransport } from \"./transport/kiro-transport.js\";\n\nexport type AgentRole = \"professor\" | \"dreamy\" | \"browsie\" | \"coding\" | \"task\";\n\nexport interface AgentRoleConfig {\n agent: string | null;\n model: string | null;\n persona: string | null;\n autoReinit: boolean;\n tag: string;\n trust: number;\n}\n\nconst AGENT_ROLES: Record<AgentRole, AgentRoleConfig> = {\n professor: { agent: \"professor\", model: null, persona: \"persona/core/SOUL.md\", autoReinit: true, tag: \"acp-main\", trust: 3 },\n dreamy: { agent: \"dreamy\", model: null, persona: \"persona/prompts/sleep/00-identity.md\", autoReinit: false, tag: \"acp-sleep\", trust: 2 },\n coding: { agent: \"coding-agent\", model: null, persona: null, autoReinit: true, tag: \"acp-coding\", trust: 2 },\n browsie: { agent: \"browsie\", model: null, persona: null, autoReinit: false, tag: \"acp-browsie\", trust: 1 },\n task: { agent: \"professor\", model: null, persona: null, autoReinit: false, tag: \"acp-task\", trust: 2 },\n};\n\nfunction resolveModel(role: AgentRole): string | undefined {\n switch (role) {\n case \"dreamy\": return getEnv().sleepModel;\n case \"browsie\": return getEnv().browsingAgent;\n case \"coding\": return getEnv().codingModel;\n default: return undefined;\n }\n}\n\nexport interface TransportConfig {\n cliPath: string;\n workingDir: string;\n agentCli?: string;\n model?: string;\n}\n\nexport function createAgentTransport(\n role: AgentRole,\n tc: TransportConfig,\n overrides?: Partial<AgentRoleConfig>,\n): AcpTransport {\n const cfg = { ...AGENT_ROLES[role], ...overrides };\n const cliArgs = tc.agentCli === \"gemini\" ? [\"--acp\", \"-y\"] : undefined;\n const model = tc.model ?? resolveModel(role);\n\n return new AcpTransport(tc.cliPath, tc.workingDir, {\n agent: cfg.agent ?? undefined,\n model,\n autoReinit: cfg.autoReinit,\n tag: cfg.tag,\n cliArgs,\n });\n}\n\nexport type SubagentRole = \"sleep\" | \"browse\" | \"coding\" | \"task\";\n\nconst SUBAGENT_TO_AGENT: Record<SubagentRole, string> = {\n sleep: \"dreamy\",\n browse: \"browsie\",\n coding: \"coding\",\n task: \"professor\",\n};\n\nconst SUBAGENT_ACP_ROLE: Record<SubagentRole, AgentRole> = {\n sleep: \"dreamy\",\n browse: \"browsie\",\n coding: \"coding\",\n task: \"task\",\n};\n\n/** Unified transport factory for all subagents. Reads from transport.json + models.json. */\n/** @internal Used only by SubagentRuntime. Do not call directly. */\nexport async function createSubagentTransport(role: SubagentRole, registry?: import(\"./transport/model-health-registry.js\").ModelHealthRegistry, currentModel?: string): Promise<{ transport: IKiroTransport; model: string }> {\n const { resolveAgent, getEnvFallback, loadTransport } = await import(\"./transport-config.js\");\n const tc = loadTransport();\n const agentName = SUBAGENT_TO_AGENT[role];\n const resolved = tc ? resolveAgent(agentName, tc) : null;\n\n // Fallback: use professor's config. If that also fails, use .env defaults.\n const profResolved = resolved ?? (tc ? resolveAgent(\"professor\", tc) : null);\n const agent = profResolved ?? (() => {\n const fb = getEnvFallback();\n return { model: fb.model, provider: fb.provider, providerName: fb.providerName, contextWindow: fb.contextWindow, maxOutput: fb.maxOutput, fallbacks: [] };\n })();\n\n if (agent.provider.transport === \"api\") {\n const { DirectApiTransport } = await import(\"./transport/direct-api-transport.js\");\n const { FallbackPolicy } = await import(\"./transport/fallback-policy.js\");\n const apiKey = getEnv().getApiKey(agent.provider.apiKeyEnv ?? \"API_KEY\");\n\n // Use main transport's active model if available, else static config\n const startModel = currentModel ?? agent.model;\n\n // Build per-agent candidate list\n const candidates: Array<{ model: string; endpoint: string; apiKey?: string; maxContext: number }> = [\n { endpoint: agent.provider.endpoint ?? \"http://localhost:11434/v1\", apiKey, model: startModel, maxContext: agent.contextWindow },\n ];\n\n // Add static config model if different from startModel\n if (agent.model !== startModel && !candidates.some(c => c.model === agent.model)) {\n candidates.push({ endpoint: agent.provider.endpoint ?? \"http://localhost:11434/v1\", apiKey, model: agent.model, maxContext: agent.contextWindow });\n }\n\n // Add professor's model as fallback if different and transport-compatible\n const profAgent = tc ? resolveAgent(\"professor\", tc) : null;\n const agentTransport = agent.provider.transport ?? \"api\";\n if (profAgent && profAgent.model !== startModel && !candidates.some(c => c.model === profAgent.model)) {\n const profTransport = profAgent.provider.transport ?? \"api\";\n if (profTransport === agentTransport && profAgent.provider.endpoint) {\n candidates.push({\n endpoint: profAgent.provider.endpoint,\n apiKey: profAgent.provider.apiKeyEnv ? getEnv().getApiKey(profAgent.provider.apiKeyEnv) : apiKey,\n model: profAgent.model,\n maxContext: profAgent.contextWindow,\n });\n }\n }\n\n // Append agent-level cross-provider fallbacks\n for (const fb of agent.fallbacks) {\n if (candidates.some(c => c.model === fb.model)) continue;\n const fbProvider = tc?.providers[fb.provider];\n const fbEndpoint = fbProvider?.endpoint ?? agent.provider.endpoint ?? \"http://localhost:11434/v1\";\n const fbApiKey = fbProvider?.apiKeyEnv ? getEnv().getApiKey(fbProvider.apiKeyEnv) : apiKey;\n candidates.push({ endpoint: fbEndpoint, apiKey: fbApiKey, model: fb.model, maxContext: agent.contextWindow });\n }\n\n // Append fallbackChain entries as last-resort candidates\n const chain = agent.provider.fallbackChain ?? [];\n for (const chainModel of chain) {\n if (!candidates.some(c => c.model === chainModel)) {\n candidates.push({\n endpoint: agent.provider.endpoint ?? \"http://localhost:11434/v1\",\n apiKey, model: chainModel, maxContext: agent.contextWindow,\n });\n }\n }\n\n // Use shared registry if provided, otherwise create isolated one\n const { ModelHealthRegistry } = await import(\"./transport/model-health-registry.js\");\n const policy = new FallbackPolicy(candidates, registry ?? new ModelHealthRegistry());\n\n const transport = new DirectApiTransport({\n endpoint: agent.provider.endpoint ?? \"http://localhost:11434/v1\",\n apiKey, model: startModel,\n maxContext: agent.contextWindow, maxOutput: agent.maxOutput,\n maxTurns: tc?.maxTurns ?? 50,\n }, policy);\n await transport.initialize();\n logInfo(\"subagent\", `${role} transport: DirectAPI ${agent.providerName} (model=${startModel}, ${candidates.length} candidates, shared registry: ${!!registry})`);\n return { transport, model: agent.model };\n }\n\n // ACP path \u2014 try configured model, then fallbackChain on failure\n const { loadAndValidateConfig } = await import(\"./config.js\");\n const config = await loadAndValidateConfig();\n const chain = agent.provider.fallbackChain ?? [];\n const modelsToTry = [agent.model, ...chain.filter(m => m !== agent.model)];\n\n for (let i = 0; i < modelsToTry.length; i++) {\n const model = modelsToTry[i]!;\n const transport = createAgentTransport(SUBAGENT_ACP_ROLE[role], {\n cliPath: agent.provider.cli ?? config.transport.agentCliPath,\n workingDir: config.transport.workingDir,\n agentCli: agent.provider.cli ?? \"kiro-cli\",\n model,\n });\n try {\n await transport.initialize();\n if (i > 0) logWarn(\"subagent\", `${role}: configured model failed, fell back to ${model}`);\n logInfo(\"subagent\", `${role} transport: ACP ${agent.providerName} (model=${model}${i > 0 ? \", fallback\" : \"\"})`);\n return { transport, model };\n } catch (err) {\n if (i < modelsToTry.length - 1) {\n logWarn(\"subagent\", `${role}: model ${model} init failed (${err instanceof Error ? err.message : String(err)}), trying ${modelsToTry[i + 1]}`);\n continue;\n }\n throw err;\n }\n }\n throw new Error(`${role}: all models exhausted (tried ${modelsToTry.join(\", \")})`);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;AAAA;AAOA;AAcA,IAAM,cAAkD;AAAA,EACtD,WAAW,EAAE,OAAO,aAAa,OAAO,MAAM,SAAS,wBAAwB,YAAY,MAAM,KAAK,YAAY,OAAO,EAAE;AAAA,EAC3H,QAAQ,EAAE,OAAO,UAAU,OAAO,MAAM,SAAS,wCAAwC,YAAY,OAAO,KAAK,aAAa,OAAO,EAAE;AAAA,EACvI,QAAQ,EAAE,OAAO,gBAAgB,OAAO,MAAM,SAAS,MAAM,YAAY,MAAM,KAAK,cAAc,OAAO,EAAE;AAAA,EAC3G,SAAS,EAAE,OAAO,WAAW,OAAO,MAAM,SAAS,MAAM,YAAY,OAAO,KAAK,eAAe,OAAO,EAAE;AAAA,EACzG,MAAM,EAAE,OAAO,aAAa,OAAO,MAAM,SAAS,MAAM,YAAY,OAAO,KAAK,YAAY,OAAO,EAAE;AACvG;AAEA,SAAS,aAAa,MAAqC;AACzD,UAAQ,MAAM;AAAA,IACZ,KAAK;AAAU,aAAO,OAAO,EAAE;AAAA,IAC/B,KAAK;A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AAS,MAAM,SAAS,OAAO,OAAO,UAAU;AAAA,MAChD,YAAY,OAAO,UAAU;AAAA,MAC7B,UAAU,MAAM,SAAS,OAAO;AAAA,MAChC;AAAA,IACF,CAAC;AACD,QAAI;AACF,YAAM,UAAU,WAAW;AAC3B,UAAI,IAAI,EAAG,SAAQ,YAAY,GAAG,IAAI,2CAA2C,KAAK,EAAE;AACxF,cAAQ,YAAY,GAAG,IAAI,mBAAmB,MAAM,YAAY,WAAW,KAAK,GAAG,IAAI,IAAI,eAAe,EAAE,GAAG;AAC/G,aAAO,EAAE,WAAW,MAAM;AAAA,IAC5B,SAAS,KAAK;AACZ,UAAI,IAAI,YAAY,SAAS,GAAG;AAC9B,gBAAQ,YAAY,GAAG,IAAI,WAAW,KAAK,iBAAiB,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC,aAAa,YAAY,IAAI,CAAC,CAAC,EAAE;AAC7I;AAAA,MACF;AACA,YAAM;AAAA,IACR;AAAA,EACF;AACA,QAAM,IAAI,MAAM,GAAG,IAAI,iCAAiC,YAAY,KAAK,IAAI,CAAC,GAAG;AACnF;",
6
+ "names": ["chain"]
7
+ }
@@ -0,0 +1,157 @@
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
+ abtarsHome,
4
+ init_paths
5
+ } from "./chunk-X76UX47U.js";
6
+ import {
7
+ __esm
8
+ } from "./chunk-NWDBD4PA.js";
9
+
10
+ // src/components/logger.ts
11
+ import { appendFileSync, mkdirSync } from "node:fs";
12
+ import { join } from "node:path";
13
+ function getLogFile() {
14
+ const d = /* @__PURE__ */ new Date();
15
+ const date = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
16
+ return join(LOG_DIR, `bridge-${date}.log`);
17
+ }
18
+ function setLogLevel(level) {
19
+ currentLevel = level;
20
+ }
21
+ function shouldLog(minLevel) {
22
+ return LEVEL_ORDER[currentLevel] >= LEVEL_ORDER[minLevel];
23
+ }
24
+ function isLogLevel(minLevel) {
25
+ return LEVEL_ORDER[currentLevel] >= LEVEL_ORDER[minLevel];
26
+ }
27
+ function writeToFile(line) {
28
+ if (!fileLogging) return;
29
+ buffer.push(redactSecrets(line));
30
+ if (buffer.length >= 200) flush();
31
+ else if (!flushTimer) {
32
+ flushTimer = setTimeout(flush, 3e4);
33
+ flushTimer.unref();
34
+ }
35
+ }
36
+ function flush() {
37
+ if (flushTimer) {
38
+ clearTimeout(flushTimer);
39
+ flushTimer = null;
40
+ }
41
+ if (buffer.length === 0) return;
42
+ const lines = buffer;
43
+ buffer = [];
44
+ try {
45
+ mkdirSync(LOG_DIR, { recursive: true });
46
+ appendFileSync(getLogFile(), lines.join("\n") + "\n");
47
+ } catch {
48
+ }
49
+ }
50
+ function redactSecrets(text) {
51
+ let result = text;
52
+ for (const [pattern, replacement] of SECRET_PATTERNS) {
53
+ result = result.replace(pattern, replacement);
54
+ }
55
+ return result;
56
+ }
57
+ function ts() {
58
+ const d = /* @__PURE__ */ new Date();
59
+ const pad2 = (n) => String(n).padStart(2, "0");
60
+ const local = `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}T${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}.${String(d.getMilliseconds()).padStart(3, "0")}`;
61
+ return isTest ? `${local} TEST` : local;
62
+ }
63
+ function localIso() {
64
+ const d = /* @__PURE__ */ new Date();
65
+ const pad2 = (n) => String(n).padStart(2, "0");
66
+ return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}T${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`;
67
+ }
68
+ function formatLine(level, tag, msg) {
69
+ if (logFormat === "json") {
70
+ return JSON.stringify({ ts: ts(), level, tag, msg });
71
+ }
72
+ return `${ts()} ${level.toUpperCase().padEnd(5)} [${tag}] ${msg}`;
73
+ }
74
+ function logInfo(tag, msg) {
75
+ if (!shouldLog("low")) return;
76
+ const line = formatLine("info", tag, msg);
77
+ console.log(`[${tag}] ${msg}`);
78
+ writeToFile(line);
79
+ }
80
+ function logWarn(tag, msg) {
81
+ if (!shouldLog("low")) return;
82
+ const line = formatLine("warn", tag, msg);
83
+ console.warn(`[${tag}] ${msg}`);
84
+ writeToFile(line);
85
+ }
86
+ function logError(tag, msg, err) {
87
+ if (!shouldLog("low")) return;
88
+ const errStr = err instanceof Error ? err.message : typeof err === "object" && err !== null ? JSON.stringify(err) : String(err ?? "");
89
+ const fullMsg = errStr ? `${msg} \u2014 ${errStr}` : msg;
90
+ const line = formatLine("error", tag, fullMsg);
91
+ if (err) console.error(`[${tag}] ${msg}`, err);
92
+ else console.error(`[${tag}] ${msg}`);
93
+ writeToFile(line);
94
+ }
95
+ function logDebug(tag, msg) {
96
+ if (!shouldLog("debug")) return;
97
+ const line = formatLine("debug", tag, msg);
98
+ console.log(`[${tag}] ${msg}`);
99
+ writeToFile(line);
100
+ }
101
+ function logTrace(tag, msg) {
102
+ if (!shouldLog("trace")) return;
103
+ const line = formatLine("trace", tag, msg);
104
+ console.log(`[${tag}] ${msg}`);
105
+ writeToFile(line);
106
+ }
107
+ var LEVEL_ORDER, LOG_DIR, currentLevel, fileLogging, buffer, flushTimer, SECRET_PATTERNS, isTest, logFormat;
108
+ var init_logger = __esm({
109
+ "src/components/logger.ts"() {
110
+ "use strict";
111
+ init_paths();
112
+ LEVEL_ORDER = { off: 0, low: 1, debug: 2, trace: 3 };
113
+ LOG_DIR = join(abtarsHome(), "logs");
114
+ currentLevel = "low";
115
+ fileLogging = true;
116
+ buffer = [];
117
+ flushTimer = null;
118
+ process.on("exit", flush);
119
+ SECRET_PATTERNS = [
120
+ [/sk-[A-Za-z0-9_-]{20,}/g, "sk-***REDACTED***"],
121
+ [/sk-or-[A-Za-z0-9_-]{20,}/g, "sk-or-***REDACTED***"],
122
+ [/gsk_[A-Za-z0-9]{20,}/g, "gsk_***REDACTED***"],
123
+ [/ghp_[A-Za-z0-9]{36,}/g, "ghp_***REDACTED***"],
124
+ [/github_pat_[A-Za-z0-9_]{20,}/g, "github_pat_***REDACTED***"],
125
+ [/xox[baprs]-[A-Za-z0-9-]{10,}/g, "xox_-***REDACTED***"],
126
+ [/AIza[A-Za-z0-9_-]{30,}/g, "AIza***REDACTED***"],
127
+ [/AKIA[A-Z0-9]{16}/g, "AKIA***REDACTED***"],
128
+ [/\d{8,12}:[A-Za-z0-9_-]{35,}/g, "***BOT_TOKEN***"],
129
+ [/Bearer [A-Za-z0-9._-]{20,}/g, "Bearer ***REDACTED***"],
130
+ [/eyJ[A-Za-z0-9_-]{20,}\.eyJ[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}/g, "***JWT_REDACTED***"],
131
+ [/hf_[A-Za-z0-9]{20,}/g, "hf_***REDACTED***"],
132
+ [/npm_[A-Za-z0-9]{20,}/g, "npm_***REDACTED***"],
133
+ [/sk_live_[A-Za-z0-9]{20,}/g, "sk_live_***REDACTED***"],
134
+ [/sk_test_[A-Za-z0-9]{20,}/g, "sk_test_***REDACTED***"],
135
+ [/SG\.[A-Za-z0-9_-]{20,}/g, "SG.***REDACTED***"],
136
+ [/("(?:api[_-]?key|token|secret|password|authorization|credential)"\s*:\s*")[^"]{8,}"/gi, '$1***REDACTED***"'],
137
+ [/([A-Z_]*(?:KEY|TOKEN|SECRET|PASSWORD)=)[^\s]{8,}/g, "$1***REDACTED***"]
138
+ ];
139
+ isTest = process.env.VITEST === "true";
140
+ logFormat = process.env["LOG_FORMAT"] === "json" ? "json" : "text";
141
+ }
142
+ });
143
+
144
+ export {
145
+ getLogFile,
146
+ setLogLevel,
147
+ isLogLevel,
148
+ redactSecrets,
149
+ localIso,
150
+ logInfo,
151
+ logWarn,
152
+ logError,
153
+ logDebug,
154
+ logTrace,
155
+ init_logger
156
+ };
157
+ //# sourceMappingURL=chunk-BUUVFUPO.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/components/logger.ts"],
4
+ "sourcesContent": ["import { appendFileSync, mkdirSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { abtarsHome } from \"../paths.js\";\n\n/** Log levels: OFF = silent, LOW = operational info, DEBUG = verbose trace, TRACE = debug + anomaly diagnostics */\nexport type LogLevel = \"off\" | \"low\" | \"debug\" | \"trace\";\n\nconst LEVEL_ORDER: Record<LogLevel, number> = { off: 0, low: 1, debug: 2, trace: 3 };\nconst LOG_DIR = join(abtarsHome(), \"logs\");\n\n/** Get today's log filename: bridge-YYYY-MM-DD.log */\nexport function getLogFile(): string {\n const d = new Date();\n const date = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, \"0\")}-${String(d.getDate()).padStart(2, \"0\")}`;\n return join(LOG_DIR, `bridge-${date}.log`);\n}\n\nlet currentLevel: LogLevel = \"low\";\nlet fileLogging = true;\n\nexport function setLogLevel(level: LogLevel): void {\n currentLevel = level;\n}\n\nfunction shouldLog(minLevel: LogLevel): boolean {\n return LEVEL_ORDER[currentLevel] >= LEVEL_ORDER[minLevel];\n}\n\nexport function isLogLevel(minLevel: LogLevel): boolean {\n return LEVEL_ORDER[currentLevel] >= LEVEL_ORDER[minLevel];\n}\n\n// \u2500\u2500 Buffered file writer \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nlet buffer: string[] = [];\nlet flushTimer: ReturnType<typeof setTimeout> | null = null;\n\nfunction writeToFile(line: string): void {\n if (!fileLogging) return;\n buffer.push(redactSecrets(line));\n if (buffer.length >= 200) flush();\n else if (!flushTimer) {\n flushTimer = setTimeout(flush, 30000);\n flushTimer.unref();\n }\n}\n\nfunction flush(): void {\n if (flushTimer) { clearTimeout(flushTimer); flushTimer = null; }\n if (buffer.length === 0) return;\n const lines = buffer;\n buffer = [];\n try {\n mkdirSync(LOG_DIR, { recursive: true });\n appendFileSync(getLogFile(), lines.join(\"\\n\") + \"\\n\");\n } catch { /* silently ignore file write errors */ }\n}\n\n/** Flush buffered logs synchronously. Called on process exit. */\nexport function flushLogs(): void { flush(); }\n\nprocess.on(\"exit\", flush);\n\n// \u2500\u2500 Credential redaction \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// INTENTIONALLY DUPLICATED across abtars and abmind \u2014 they are\n// independent products that both need this utility. If you add or\n// modify a pattern here, also update the sibling file:\n// abtars/src/components/logger.ts (SECRET_PATTERNS + redactSecrets)\n// abmind/src/redact-secrets.ts (SECRET_PATTERNS + redactSecrets)\n//\n// Do NOT create an import relationship between them. Each product stays\n// independent so the bridge can run against a different memory backend\n// and abmind can ship as a standalone npm package without pulling\n// abtars in for a utility function.\n\nconst SECRET_PATTERNS: ReadonlyArray<[RegExp, string]> = [\n [/sk-[A-Za-z0-9_-]{20,}/g, \"sk-***REDACTED***\"],\n [/sk-or-[A-Za-z0-9_-]{20,}/g, \"sk-or-***REDACTED***\"],\n [/gsk_[A-Za-z0-9]{20,}/g, \"gsk_***REDACTED***\"],\n [/ghp_[A-Za-z0-9]{36,}/g, \"ghp_***REDACTED***\"],\n [/github_pat_[A-Za-z0-9_]{20,}/g, \"github_pat_***REDACTED***\"],\n [/xox[baprs]-[A-Za-z0-9-]{10,}/g, \"xox_-***REDACTED***\"],\n [/AIza[A-Za-z0-9_-]{30,}/g, \"AIza***REDACTED***\"],\n [/AKIA[A-Z0-9]{16}/g, \"AKIA***REDACTED***\"],\n [/\\d{8,12}:[A-Za-z0-9_-]{35,}/g, \"***BOT_TOKEN***\"],\n [/Bearer [A-Za-z0-9._-]{20,}/g, \"Bearer ***REDACTED***\"],\n [/eyJ[A-Za-z0-9_-]{20,}\\.eyJ[A-Za-z0-9_-]{20,}\\.[A-Za-z0-9_-]{20,}/g, \"***JWT_REDACTED***\"],\n [/hf_[A-Za-z0-9]{20,}/g, \"hf_***REDACTED***\"],\n [/npm_[A-Za-z0-9]{20,}/g, \"npm_***REDACTED***\"],\n [/sk_live_[A-Za-z0-9]{20,}/g, \"sk_live_***REDACTED***\"],\n [/sk_test_[A-Za-z0-9]{20,}/g, \"sk_test_***REDACTED***\"],\n [/SG\\.[A-Za-z0-9_-]{20,}/g, \"SG.***REDACTED***\"],\n [/(\"(?:api[_-]?key|token|secret|password|authorization|credential)\"\\s*:\\s*\")[^\"]{8,}\"/gi, '$1***REDACTED***\"'],\n [/([A-Z_]*(?:KEY|TOKEN|SECRET|PASSWORD)=)[^\\s]{8,}/g, \"$1***REDACTED***\"],\n];\n\n/** Strip known secret patterns from a log line. */\nexport function redactSecrets(text: string): string {\n let result = text;\n for (const [pattern, replacement] of SECRET_PATTERNS) {\n result = result.replace(pattern, replacement);\n }\n return result;\n}\n\nconst isTest = process.env.NODE_ENV === \"test\" || process.env.VITEST === \"true\";\n\nfunction ts(): string {\n const d = new Date();\n const pad2 = (n: number): string => String(n).padStart(2, \"0\");\n const local = `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}T${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}.${String(d.getMilliseconds()).padStart(3, \"0\")}`;\n return isTest ? `${local} TEST` : local;\n}\n\n/** Local ISO-ish timestamp for user-facing messages. */\nexport function localIso(): string {\n const d = new Date();\n const pad2 = (n: number): string => String(n).padStart(2, \"0\");\n return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}T${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`;\n}\n\nlet logFormat: \"text\" | \"json\" = (process.env[\"LOG_FORMAT\"] as \"json\" | undefined) === \"json\" ? \"json\" : \"text\";\n\nfunction formatLine(level: string, tag: string, msg: string): string {\n if (logFormat === \"json\") {\n return JSON.stringify({ ts: ts(), level, tag, msg });\n }\n return `${ts()} ${level.toUpperCase().padEnd(5)} [${tag}] ${msg}`;\n}\n\n/** LOW: operational milestones \u2014 startup, connections, errors */\nexport function logInfo(tag: string, msg: string): void {\n if (!shouldLog(\"low\")) return;\n const line = formatLine(\"info\", tag, msg);\n console.log(`[${tag}] ${msg}`);\n writeToFile(line);\n}\n\n/** LOW: warnings */\nexport function logWarn(tag: string, msg: string): void {\n if (!shouldLog(\"low\")) return;\n const line = formatLine(\"warn\", tag, msg);\n console.warn(`[${tag}] ${msg}`);\n writeToFile(line);\n}\n\n/** LOW: errors (always shown unless OFF) */\nexport function logError(tag: string, msg: string, err?: unknown): void {\n if (!shouldLog(\"low\")) return;\n const errStr = err instanceof Error ? err.message : (typeof err === \"object\" && err !== null ? JSON.stringify(err) : String(err ?? \"\"));\n const fullMsg = errStr ? `${msg} \u2014 ${errStr}` : msg;\n const line = formatLine(\"error\", tag, fullMsg);\n if (err) console.error(`[${tag}] ${msg}`, err);\n else console.error(`[${tag}] ${msg}`);\n writeToFile(line);\n}\n\n/** DEBUG: message content, full payloads, verbose tracing */\nexport function logDebug(tag: string, msg: string): void {\n if (!shouldLog(\"debug\")) return;\n const line = formatLine(\"debug\", tag, msg);\n console.log(`[${tag}] ${msg}`);\n writeToFile(line);\n}\n\n/** TRACE: debug + anomaly diagnostics (swallowed errors, catch-block traces) */\nexport function logTrace(tag: string, msg: string): void {\n if (!shouldLog(\"trace\")) return;\n const line = formatLine(\"trace\", tag, msg);\n console.log(`[${tag}] ${msg}`);\n writeToFile(line);\n}\n"],
5
+ "mappings": ";;;;;;;;;;AAAA,SAAS,gBAAgB,iBAAiB;AAC1C,SAAS,YAAY;AAUd,SAAS,aAAqB;AACnC,QAAM,IAAI,oBAAI,KAAK;AACnB,QAAM,OAAO,GAAG,EAAE,YAAY,CAAC,IAAI,OAAO,EAAE,SAAS,IAAI,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC,IAAI,OAAO,EAAE,QAAQ,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;AACpH,SAAO,KAAK,SAAS,UAAU,IAAI,MAAM;AAC3C;AAKO,SAAS,YAAY,OAAuB;AACjD,iBAAe;AACjB;AAEA,SAAS,UAAU,UAA6B;AAC9C,SAAO,YAAY,YAAY,KAAK,YAAY,QAAQ;AAC1D;AAEO,SAAS,WAAW,UAA6B;AACtD,SAAO,YAAY,YAAY,KAAK,YAAY,QAAQ;AAC1D;AAMA,SAAS,YAAY,MAAoB;AACvC,MAAI,CAAC,YAAa;AAClB,SAAO,KAAK,cAAc,IAAI,CAAC;AAC/B,MAAI,OAAO,UAAU,IAAK,OAAM;AAAA,WACvB,CAAC,YAAY;AACpB,iBAAa,WAAW,OAAO,GAAK;AACpC,eAAW,MAAM;AAAA,EACnB;AACF;AAEA,SAAS,QAAc;AACrB,MAAI,YAAY;AAAE,iBAAa,UAAU;AAAG,iBAAa;AAAA,EAAM;AAC/D,MAAI,OAAO,WAAW,EAAG;AACzB,QAAM,QAAQ;AACd,WAAS,CAAC;AACV,MAAI;AACF,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AACtC,mBAAe,WAAW,GAAG,MAAM,KAAK,IAAI,IAAI,IAAI;AAAA,EACtD,QAAQ;AAAA,EAA0C;AACpD;AA0CO,SAAS,cAAc,MAAsB;AAClD,MAAI,SAAS;AACb,aAAW,CAAC,SAAS,WAAW,KAAK,iB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nF,IAAM,UAAU,KAAK,WAAW,GAAG,MAAM;AASzC,IAAI,eAAyB;AAC7B,IAAI,cAAc;AAelB,IAAI,SAAmB,CAAC;AACxB,IAAI,aAAmD;AA0BvD,YAAQ,GAAG,QAAQ,KAAK;AAexB,IAAM,kBAAmD;AAAA,MACvD,CAAC,0BAA0B,mBAAmB;AAAA,MAC9C,CAAC,6BAA6B,sBAAsB;AAAA,MACpD,CAAC,yBAAyB,oBAAoB;AAAA,MAC9C,CAAC,yBAAyB,oBAAoB;AAAA,MAC9C,CAAC,iCAAiC,2BAA2B;AAAA,MAC7D,CAAC,iCAAiC,qBAAqB;AAAA,MACvD,CAAC,2BAA2B,oBAAoB;AAAA,MAChD,CAAC,qBAAqB,oBAAoB;AAAA,MAC1C,CAAC,gCAAgC,iBAAiB;AAAA,MAClD,CAAC,+BAA+B,uBAAuB;AAAA,MACvD,CAAC,qEAAqE,oBAAoB;AAAA,MAC1F,CAAC,wBAAwB,mBAAmB;AAAA,MAC5C,CAAC,yBAAyB,oBAAoB;AAAA,MAC9C,CAAC,6BAA6B,wBAAwB;AAAA,MACtD,CAAC,6BAA6B,wBAAwB;AAAA,MACtD,CAAC,2BAA2B,mBAAmB;AAAA,MAC/C,CAAC,yFAAyF,mBAAmB;AAAA,MAC7G,CAAC,qDAAqD,kBAAkB;AAAA,IAC1E;AAWA,IAAM,SAA4C,QAAQ,IAAI,WAAW;AAgBzE,IAAI,YAA8B,QAAQ,IAAI,YAAY,MAA6B,SAAS,SAAS;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,131 @@
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
+ localISO
4
+ } from "./chunk-M6VBAPNT.js";
5
+ import {
6
+ init_log_and_swallow,
7
+ logAndSwallow
8
+ } from "./chunk-FMWKEPM7.js";
9
+ import {
10
+ abtarsHome,
11
+ init_paths
12
+ } from "./chunk-X76UX47U.js";
13
+
14
+ // src/components/transport/bridge-lock-transport.ts
15
+ init_log_and_swallow();
16
+ import { readFileSync } from "node:fs";
17
+
18
+ // src/components/atomic-write.ts
19
+ import { writeFileSync, renameSync, openSync, fsyncSync, closeSync, unlinkSync } from "node:fs";
20
+ function atomicWriteSync(path, data) {
21
+ const tmp = path + ".tmp";
22
+ writeFileSync(tmp, data, "utf-8");
23
+ const fd = openSync(tmp, "r");
24
+ fsyncSync(fd);
25
+ closeSync(fd);
26
+ renameSync(tmp, path);
27
+ }
28
+
29
+ // src/components/transport/bridge-lock-transport.ts
30
+ init_paths();
31
+ import { join } from "node:path";
32
+ function readLastPromptAt() {
33
+ try {
34
+ const lock = JSON.parse(readFileSync(join(abtarsHome(), "bridge.lock"), "utf-8"));
35
+ return typeof lock.lastPromptAt === "number" ? lock.lastPromptAt : 0;
36
+ } catch (err) {
37
+ logAndSwallow("bridge_lock_transport", "readLastPromptAt", err);
38
+ return 0;
39
+ }
40
+ }
41
+ function updateBridgeLockField(key, value) {
42
+ const p = join(abtarsHome(), "bridge.lock");
43
+ try {
44
+ const lock = JSON.parse(readFileSync(p, "utf-8"));
45
+ lock[key] = value;
46
+ atomicWriteSync(p, JSON.stringify(lock));
47
+ } catch (err) {
48
+ logAndSwallow("bridge_lock_transport", "op", err);
49
+ }
50
+ }
51
+ function readBridgeLockField(key) {
52
+ try {
53
+ const lock = JSON.parse(readFileSync(join(abtarsHome(), "bridge.lock"), "utf-8"));
54
+ return lock[key] ?? null;
55
+ } catch (err) {
56
+ logAndSwallow("bridge_lock_transport", "readBridgeLockField", err);
57
+ return null;
58
+ }
59
+ }
60
+ function writeRestartReason(reason) {
61
+ updateBridgeLockField("restartReason", `${localISO()} ${reason}`);
62
+ }
63
+ function readAndClearRestartReason() {
64
+ const reason = readBridgeLockField("restartReason");
65
+ if (reason) updateBridgeLockField("restartReason", null);
66
+ return reason;
67
+ }
68
+ function writeRestartRequested(reason) {
69
+ updateBridgeLockField("restartRequested", `${localISO()} ${reason}`);
70
+ }
71
+ function readAndClearRestartRequested() {
72
+ const req = readBridgeLockField("restartRequested");
73
+ if (req) updateBridgeLockField("restartRequested", null);
74
+ return req;
75
+ }
76
+ function writeSleepStatus(status) {
77
+ updateBridgeLockField("sleepStatus", status);
78
+ }
79
+ function appendRestartTimestamp() {
80
+ const ts = readBridgeLockField("restartTimestamps") ?? [];
81
+ ts.push(Date.now());
82
+ if (ts.length > 10) ts.splice(0, ts.length - 10);
83
+ updateBridgeLockField("restartTimestamps", ts);
84
+ }
85
+ function readRestartTimestamps() {
86
+ return readBridgeLockField("restartTimestamps") ?? [];
87
+ }
88
+ function writeForceSleep(reason) {
89
+ updateBridgeLockField("forceSleep", `${localISO()} ${reason}`);
90
+ }
91
+ function readAndClearForceSleep() {
92
+ const v = readBridgeLockField("forceSleep");
93
+ if (v) updateBridgeLockField("forceSleep", null);
94
+ return v;
95
+ }
96
+ function initBridgeLock(opts) {
97
+ const p = join(abtarsHome(), "bridge.lock");
98
+ try {
99
+ atomicWriteSync(p, JSON.stringify({
100
+ pid: opts.pid,
101
+ startedAt: opts.startedAt,
102
+ version: opts.version,
103
+ sleepStatus: "awake",
104
+ argv: opts.argv,
105
+ lastHeartbeat: Date.now()
106
+ }));
107
+ } catch (err) {
108
+ logAndSwallow("bridge_lock_transport", "op", err);
109
+ }
110
+ }
111
+ function updateLastHeartbeat() {
112
+ updateBridgeLockField("lastHeartbeat", Date.now());
113
+ }
114
+
115
+ export {
116
+ readLastPromptAt,
117
+ updateBridgeLockField,
118
+ readBridgeLockField,
119
+ writeRestartReason,
120
+ readAndClearRestartReason,
121
+ writeRestartRequested,
122
+ readAndClearRestartRequested,
123
+ writeSleepStatus,
124
+ appendRestartTimestamp,
125
+ readRestartTimestamps,
126
+ writeForceSleep,
127
+ readAndClearForceSleep,
128
+ initBridgeLock,
129
+ updateLastHeartbeat
130
+ };
131
+ //# sourceMappingURL=chunk-CEVRHKJY.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/components/transport/bridge-lock-transport.ts", "../src/components/atomic-write.ts"],
4
+ "sourcesContent": ["/**\n * bridge.lock \u2014 single source of truth for bridge runtime state.\n * Fields: pid, startedAt, lastHeartbeat, lastPromptAt, version,\n * sleepStatus, restartReason, restartRequested, forceSleep.\n */\nimport { logAndSwallow } from \"../log-and-swallow.js\";\nimport { readFileSync } from \"node:fs\";\nimport { atomicWriteSync } from \"../atomic-write.js\";\nimport { join } from \"node:path\";\nimport { abtarsHome } from \"../../paths.js\";\nimport { localISO } from \"../../utils/local-time.js\";\n\nexport type SleepStatus = \"awake\" | \"sleeping\" | \"hw_sleep\";\n\n/** Read lastPromptAt from bridge.lock. Returns 0 if missing/unreadable. */\nexport function readLastPromptAt(): number {\n try {\n const lock = JSON.parse(readFileSync(join(abtarsHome(), \"bridge.lock\"), \"utf-8\"));\n return typeof lock.lastPromptAt === \"number\" ? lock.lastPromptAt : 0;\n } catch (err) { logAndSwallow(\"bridge_lock_transport\", \"readLastPromptAt\", err); return 0; }\n}\n\n/** Update a single field in bridge.lock (read-merge-write). */\nexport function updateBridgeLockField(key: string, value: unknown): void {\n const p = join(abtarsHome(), \"bridge.lock\");\n try {\n const lock = JSON.parse(readFileSync(p, \"utf-8\"));\n lock[key] = value;\n atomicWriteSync(p, JSON.stringify(lock));\n } catch (err) { logAndSwallow(\"bridge_lock_transport\", \"op\", err); }\n}\n\n/** Read a field from bridge.lock. Returns null if missing/unreadable. */\nexport function readBridgeLockField<T = unknown>(key: string): T | null {\n try {\n const lock = JSON.parse(readFileSync(join(abtarsHome(), \"bridge.lock\"), \"utf-8\"));\n return lock[key] ?? null;\n } catch (err) { logAndSwallow(\"bridge_lock_transport\", \"readBridgeLockField\", err); return null; }\n}\n\n/** Write restart reason to bridge.lock. */\nexport function writeRestartReason(reason: string): void {\n updateBridgeLockField(\"restartReason\", `${localISO()} ${reason}`);\n}\n\n/** Read and clear restart reason from bridge.lock. */\nexport function readAndClearRestartReason(): string | null {\n const reason = readBridgeLockField<string>(\"restartReason\");\n if (reason) updateBridgeLockField(\"restartReason\", null);\n return reason;\n}\n\n/** Write restart request to bridge.lock. */\nexport function writeRestartRequested(reason: string): void {\n updateBridgeLockField(\"restartRequested\", `${localISO()} ${reason}`);\n}\n\n/** Read and clear restart request from bridge.lock. */\nexport function readAndClearRestartRequested(): string | null {\n const req = readBridgeLockField<string>(\"restartRequested\");\n if (req) updateBridgeLockField(\"restartRequested\", null);\n return req;\n}\n\n/** Update sleep status in bridge.lock. */\nexport function writeSleepStatus(status: SleepStatus): void {\n updateBridgeLockField(\"sleepStatus\", status);\n}\n\n/** Append a restart timestamp to bridge.lock (capped at 10). Used by in-process watchdog circuit breaker. */\nexport function appendRestartTimestamp(): void {\n const ts = readBridgeLockField<number[]>(\"restartTimestamps\") ?? [];\n ts.push(Date.now());\n if (ts.length > 10) ts.splice(0, ts.length - 10);\n updateBridgeLockField(\"restartTimestamps\", ts);\n}\n\n/** Read recent restart timestamps from bridge.lock. */\nexport function readRestartTimestamps(): number[] {\n return readBridgeLockField<number[]>(\"restartTimestamps\") ?? [];\n}\n\n/** Request a forced sleep cycle on the next heartbeat tick.\n * See src/capabilities/sleep/index.ts spawnSleep() + src/components/daily-cycle.ts isDailyCycleDue().\n * Pattern mirrors writeRestartRequested/readAndClearRestartRequested. */\nexport function writeForceSleep(reason: string): void {\n updateBridgeLockField(\"forceSleep\", `${localISO()} ${reason}`);\n}\n\n/** Read and clear the force-sleep request from bridge.lock.\n * Sole deleter: spawnSleep. isDailyCycleDue peeks via readBridgeLockField. */\nexport function readAndClearForceSleep(): string | null {\n const v = readBridgeLockField<string>(\"forceSleep\");\n if (v) updateBridgeLockField(\"forceSleep\", null);\n return v;\n}\n\n/** Initialize bridge.lock with full boot state. Single writer for initial creation. */\nexport function initBridgeLock(opts: { pid: number; startedAt: number; version: string; argv: string[] }): void {\n const p = join(abtarsHome(), \"bridge.lock\");\n try {\n atomicWriteSync(p, JSON.stringify({\n pid: opts.pid, startedAt: opts.startedAt, version: opts.version,\n sleepStatus: \"awake\", argv: opts.argv, lastHeartbeat: Date.now(),\n }));\n } catch (err) { logAndSwallow(\"bridge_lock_transport\", \"op\", err); }\n}\n\n/** Update lastHeartbeat timestamp in bridge.lock (called every tick). */\nexport function updateLastHeartbeat(): void {\n updateBridgeLockField(\"lastHeartbeat\", Date.now());\n}\n", "import { writeFileSync, renameSync, openSync, fsyncSync, closeSync, unlinkSync } from \"node:fs\";\n\n/** Atomic write: .tmp \u2192 fsync \u2192 rename. Crash-safe on POSIX. */\nexport function atomicWriteSync(path: string, data: string): void {\n const tmp = path + \".tmp\";\n writeFileSync(tmp, data, \"utf-8\");\n const fd = openSync(tmp, \"r\");\n fsyncSync(fd);\n closeSync(fd);\n renameSync(tmp, path);\n}\n\n/** Clean orphan .tmp files left by crashes. Call on boot. */\nexport function cleanOrphanTmp(path: string): void {\n try { unlinkSync(path + \".tmp\"); } catch { /* no orphan */ }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAKA;AACA,SAAS,oBAAoB;;;ACN7B,SAAS,eAAe,YAAY,UAAU,WAAW,WAAW,kBAAkB;AAG/E,SAAS,gBAAgB,MAAc,MAAoB;AAChE,QAAM,MAAM,OAAO;AACnB,gBAAc,KAAK,MAAM,OAAO;AAChC,QAAM,KAAK,SAAS,KAAK,GAAG;AAC5B,YAAU,EAAE;AACZ,YAAU,EAAE;AACZ,aAAW,KAAK,IAAI;AACtB;;;ADDA;AADA,SAAS,YAAY;AAOd,SAAS,mBAA2B;AACzC,MAAI;AACF,UAAM,OAAO,KAAK,MAAM,aAAa,KAAK,WAAW,GAAG,aAAa,GAAG,OAAO,CAAC;AAChF,WAAO,OAAO,KAAK,iBAAiB,WAAW,KAAK,eAAe;AAAA,EACrE,SAAS,KAAK;AAA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AE;AAC/C,wBAAsB,qBAAqB,EAAE;AAC/C;AAGO,SAAS,wBAAkC;AAChD,SAAO,oBAA8B,mBAAmB,KAAK,CAAC;AAChE;AAKO,SAAS,gBAAgB,QAAsB;AACpD,wBAAsB,cAAc,GAAG,SAAS,CAAC,IAAI,MAAM,EAAE;AAC/D;AAIO,SAAS,yBAAwC;AACtD,QAAM,IAAI,oBAA4B,YAAY;AAClD,MAAI,EAAG,uBAAsB,cAAc,IAAI;AAC/C,SAAO;AACT;AAGO,SAAS,eAAe,MAAiF;AAC9G,QAAM,IAAI,KAAK,WAAW,GAAG,aAAa;AAC1C,MAAI;AACF,oBAAgB,GAAG,KAAK,UAAU;AAAA,MAChC,KAAK,KAAK;AAAA,MAAK,WAAW,KAAK;AAAA,MAAW,SAAS,KAAK;AAAA,MACxD,aAAa;AAAA,MAAS,MAAM,KAAK;AAAA,MAAM,eAAe,KAAK,IAAI;AAAA,IACjE,CAAC,CAAC;AAAA,EACJ,SAAS,KAAK;AAAE,kBAAc,yBAAyB,MAAM,GAAG;AAAA,EAAG;AACrE;AAGO,SAAS,sBAA4B;AAC1C,wBAAsB,iBAAiB,KAAK,IAAI,CAAC;AACnD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,39 @@
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
+
3
+ // src/components/digital-signature.ts
4
+ import { createPrivateKey, createPublicKey, sign, verify } from "node:crypto";
5
+ var MAX_AGE_SECONDS = 30;
6
+ var DELIMITER = "|";
7
+ function signMessage(privateKeyBase64, sender, context, text) {
8
+ const ts = Math.floor(Date.now() / 1e3);
9
+ const payload = `${sender}${DELIMITER}${context}${DELIMITER}${ts}${DELIMITER}${text}`;
10
+ const key = createPrivateKey({ key: Buffer.from(privateKeyBase64, "base64"), format: "der", type: "pkcs8" });
11
+ const sig = sign(null, Buffer.from(payload, "utf-8"), key);
12
+ return { tag: `[sig:${ts}:${sig.toString("base64")}]` };
13
+ }
14
+ function verifyMessage(publicKeyBase64, sender, context, rawText) {
15
+ const match = rawText.match(/\[sig:(\d+):([A-Za-z0-9+/=]+)\]$/);
16
+ if (!match) return { valid: false, reason: "no-signature", text: rawText };
17
+ const ts = parseInt(match[1], 10);
18
+ const sigBytes = Buffer.from(match[2], "base64");
19
+ const text = rawText.slice(0, match.index).trimEnd();
20
+ const now = Math.floor(Date.now() / 1e3);
21
+ if (Math.abs(now - ts) > MAX_AGE_SECONDS) {
22
+ return { valid: false, reason: "expired", text };
23
+ }
24
+ const payload = `${sender}${DELIMITER}${context}${DELIMITER}${ts}${DELIMITER}${text}`;
25
+ const key = createPublicKey({ key: Buffer.from(publicKeyBase64, "base64"), format: "der", type: "spki" });
26
+ const ok = verify(null, Buffer.from(payload, "utf-8"), key, sigBytes);
27
+ if (!ok) return { valid: false, reason: "bad-signature", text };
28
+ return { valid: true, text };
29
+ }
30
+ function stripSigTag(text) {
31
+ return text.replace(/\s*\[sig:\d+:[A-Za-z0-9+/=]+\]$/, "");
32
+ }
33
+
34
+ export {
35
+ signMessage,
36
+ verifyMessage,
37
+ stripSigTag
38
+ };
39
+ //# sourceMappingURL=chunk-CWOHNFUV.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/components/digital-signature.ts"],
4
+ "sourcesContent": ["import { createPrivateKey, createPublicKey, sign, verify } from \"node:crypto\";\n\nconst MAX_AGE_SECONDS = 30;\nconst DELIMITER = \"|\";\n\nexport interface SignResult {\n tag: string; // [sig:timestamp:base64signature]\n}\n\nexport function signMessage(privateKeyBase64: string, sender: string, context: string, text: string): SignResult {\n const ts = Math.floor(Date.now() / 1000);\n const payload = `${sender}${DELIMITER}${context}${DELIMITER}${ts}${DELIMITER}${text}`;\n const key = createPrivateKey({ key: Buffer.from(privateKeyBase64, \"base64\"), format: \"der\", type: \"pkcs8\" });\n const sig = sign(null, Buffer.from(payload, \"utf-8\"), key);\n return { tag: `[sig:${ts}:${sig.toString(\"base64\")}]` };\n}\n\nexport interface VerifyResult {\n valid: boolean;\n reason?: string;\n text: string; // text with sig tag stripped\n}\n\nexport function verifyMessage(publicKeyBase64: string, sender: string, context: string, rawText: string): VerifyResult {\n const match = rawText.match(/\\[sig:(\\d+):([A-Za-z0-9+/=]+)\\]$/);\n if (!match) return { valid: false, reason: \"no-signature\", text: rawText };\n\n const ts = parseInt(match[1]!, 10);\n const sigBytes = Buffer.from(match[2]!, \"base64\");\n const text = rawText.slice(0, match.index!).trimEnd();\n\n // Replay check\n const now = Math.floor(Date.now() / 1000);\n if (Math.abs(now - ts) > MAX_AGE_SECONDS) {\n return { valid: false, reason: \"expired\", text };\n }\n\n const payload = `${sender}${DELIMITER}${context}${DELIMITER}${ts}${DELIMITER}${text}`;\n const key = createPublicKey({ key: Buffer.from(publicKeyBase64, \"base64\"), format: \"der\", type: \"spki\" });\n const ok = verify(null, Buffer.from(payload, \"utf-8\"), key, sigBytes);\n if (!ok) return { valid: false, reason: \"bad-signature\", text };\n return { valid: true, text };\n}\n\nexport function stripSigTag(text: string): string {\n return text.replace(/\\s*\\[sig:\\d+:[A-Za-z0-9+/=]+\\]$/, \"\");\n}\n"],
5
+ "mappings": ";;;AAAA,SAAS,kBAAkB,iBAAiB,MAAM,cAAc;AAEhE,IAAM,kBAAkB;AACxB,IAAM,YAAY;AAMX,SAAS,YAAY,kBAA0B,QAAgB,SAAiB,MAA0B;AAC/G,QAAM,KAAK,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AACvC,QAAM,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,EAAE,GAAG,SAAS,GAAG,IAAI;AACnF,QAAM,MAAM,iBAAiB,EAAE,KAAK,OAAO,KAAK,kBAAkB,QAAQ,GAAG,QAAQ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