tenjin-cli 0.1.0-alpha.34 → 0.1.0-alpha.35

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 (332) hide show
  1. package/NOTICE.md +30 -0
  2. package/README.md +20 -18
  3. package/dist/{_esm-MMYV66AX.js → _esm-2KST7HQ7.js} +4 -4
  4. package/dist/{alive-VOIL5W3I.js → alive-5TV22PNF.js} +13 -13
  5. package/dist/{auth-UHD3QFX4.js → auth-XI7BJFLW.js} +4 -4
  6. package/dist/balance-DFHC6XEU.js +71 -0
  7. package/dist/{ccip-CS7K5QRQ.js → ccip-HOW3DZYF.js} +3 -3
  8. package/dist/{chunk-RJ5HRPAZ.js → chunk-24XKUN2S.js} +68 -10
  9. package/dist/chunk-24XKUN2S.js.map +1 -0
  10. package/dist/chunk-2L7TDGLV.js +56 -0
  11. package/dist/chunk-2L7TDGLV.js.map +1 -0
  12. package/dist/{chunk-PZHBPGDE.js → chunk-34SAECKZ.js} +34 -10
  13. package/dist/chunk-34SAECKZ.js.map +1 -0
  14. package/dist/{chunk-EQZ2CCWC.js → chunk-3Y2EHT4F.js} +5 -2
  15. package/dist/chunk-3Y2EHT4F.js.map +1 -0
  16. package/dist/{chunk-FSYH7J75.js → chunk-3Y6BHIN6.js} +3 -3
  17. package/dist/{chunk-FZZWTDWP.js → chunk-3YPL6T3P.js} +6 -6
  18. package/dist/{chunk-JEZMWJEF.js → chunk-44MVIRZH.js} +4 -4
  19. package/dist/{chunk-27FIHFXF.js → chunk-45MMSBHA.js} +5 -5
  20. package/dist/{chunk-QXP3Z3JN.js → chunk-4MBCJFY4.js} +35 -3
  21. package/dist/chunk-4MBCJFY4.js.map +1 -0
  22. package/dist/chunk-4TPL54KW.js +227 -0
  23. package/dist/chunk-4TPL54KW.js.map +1 -0
  24. package/dist/{chunk-7JB6SYJX.js → chunk-54ELBTKE.js} +2 -2
  25. package/dist/{chunk-6J64MQFD.js → chunk-5F4OB5B3.js} +21 -15
  26. package/dist/chunk-5F4OB5B3.js.map +1 -0
  27. package/dist/{chunk-PYVQ74D5.js → chunk-5HN4KVQU.js} +189 -117
  28. package/dist/chunk-5HN4KVQU.js.map +1 -0
  29. package/dist/{chunk-VFKPIIV2.js → chunk-5J4E5GYI.js} +35 -32
  30. package/dist/chunk-5J4E5GYI.js.map +1 -0
  31. package/dist/chunk-5USBZ2MU.js +58 -0
  32. package/dist/chunk-5USBZ2MU.js.map +1 -0
  33. package/dist/chunk-64WOMNYR.js +183 -0
  34. package/dist/chunk-64WOMNYR.js.map +1 -0
  35. package/dist/{chunk-APWELUI7.js → chunk-65RS4LQS.js} +57 -43
  36. package/dist/chunk-65RS4LQS.js.map +1 -0
  37. package/dist/{chunk-HWZO6HYZ.js → chunk-6QMDUDF2.js} +3 -3
  38. package/dist/{chunk-FNBGRKS6.js → chunk-7V25UAQO.js} +2 -2
  39. package/dist/chunk-BGA4DO5M.js +719 -0
  40. package/dist/chunk-BGA4DO5M.js.map +1 -0
  41. package/dist/chunk-BVP7YK2J.js +706 -0
  42. package/dist/chunk-BVP7YK2J.js.map +1 -0
  43. package/dist/chunk-C265QIMJ.js +83 -0
  44. package/dist/chunk-C265QIMJ.js.map +1 -0
  45. package/dist/{chunk-MXN2ZEUB.js → chunk-D6M3ZK66.js} +2 -2
  46. package/dist/chunk-D6M3ZK66.js.map +1 -0
  47. package/dist/chunk-DJ36BM62.js +78 -0
  48. package/dist/chunk-DJ36BM62.js.map +1 -0
  49. package/dist/{chunk-JOKPBYXP.js → chunk-DTEWAVNE.js} +2 -2
  50. package/dist/chunk-F2KJAJ7T.js +13 -0
  51. package/dist/chunk-F2KJAJ7T.js.map +1 -0
  52. package/dist/{chunk-KAILF7QA.js → chunk-F43CV6UC.js} +2 -2
  53. package/dist/{chunk-ACO7ZCR2.js → chunk-FKVJKLPI.js} +2 -2
  54. package/dist/{chunk-43HLS2HM.js → chunk-FYFHH7V5.js} +54 -3
  55. package/dist/{chunk-43HLS2HM.js.map → chunk-FYFHH7V5.js.map} +1 -1
  56. package/dist/{chunk-2F5JUAHZ.js → chunk-GAJC4BQZ.js} +3 -3
  57. package/dist/{chunk-L7N73ZAW.js → chunk-HAZAN4UM.js} +2 -2
  58. package/dist/{chunk-6QJZA6EX.js → chunk-HI5XQOX2.js} +2 -2
  59. package/dist/{chunk-BOENA6XR.js → chunk-HKGUKAQW.js} +6 -6
  60. package/dist/{chunk-LJSCGIYH.js → chunk-HPRVFJPM.js} +2 -2
  61. package/dist/{chunk-OO6FIBL7.js → chunk-HZKANST2.js} +3 -6
  62. package/dist/chunk-HZKANST2.js.map +1 -0
  63. package/dist/{chunk-UVDJ5SSQ.js → chunk-I557SAOM.js} +8 -2
  64. package/dist/chunk-I557SAOM.js.map +1 -0
  65. package/dist/{chunk-SDUOJRSV.js → chunk-IGLWLH73.js} +3 -3
  66. package/dist/{chunk-3AKH7ODX.js → chunk-INSIW65E.js} +5 -5
  67. package/dist/{chunk-PNHNXUSL.js → chunk-IULCDMVG.js} +12 -1
  68. package/dist/chunk-IULCDMVG.js.map +1 -0
  69. package/dist/{chunk-JF4T4HCQ.js → chunk-IVNSUAVC.js} +10 -5
  70. package/dist/chunk-IVNSUAVC.js.map +1 -0
  71. package/dist/chunk-JDQZCREI.js +87 -0
  72. package/dist/chunk-JDQZCREI.js.map +1 -0
  73. package/dist/{chunk-2P3NJTHE.js → chunk-JHFFUVON.js} +23 -23
  74. package/dist/{chunk-7JVARP5R.js → chunk-JTILUN4W.js} +55 -29
  75. package/dist/{chunk-7JVARP5R.js.map → chunk-JTILUN4W.js.map} +1 -1
  76. package/dist/{chunk-2TO5F6CT.js → chunk-K5KNGC4I.js} +8 -8
  77. package/dist/{chunk-HUWTFKEM.js → chunk-KAQ4Q3TO.js} +3 -3
  78. package/dist/{chunk-E6VP6MQM.js → chunk-KGUE5AVX.js} +4 -4
  79. package/dist/chunk-KGUE5AVX.js.map +1 -0
  80. package/dist/{chunk-GS5RZF7U.js → chunk-KLDMLWXT.js} +2 -2
  81. package/dist/{chunk-HN2EN6P4.js → chunk-KNKDMTHU.js} +5 -5
  82. package/dist/chunk-LDA6TAYQ.js +95 -0
  83. package/dist/chunk-LDA6TAYQ.js.map +1 -0
  84. package/dist/chunk-LWSSIZOY.js +347 -0
  85. package/dist/chunk-LWSSIZOY.js.map +1 -0
  86. package/dist/{chunk-5VWQSCDO.js → chunk-MAHNZA6C.js} +89 -9
  87. package/dist/chunk-MAHNZA6C.js.map +1 -0
  88. package/dist/{chunk-46HAB26L.js → chunk-MEWZCIA6.js} +56 -9
  89. package/dist/chunk-MEWZCIA6.js.map +1 -0
  90. package/dist/{chunk-R2KMLONN.js → chunk-MJDO4EXD.js} +4 -4
  91. package/dist/{chunk-IHVUE3XF.js → chunk-NJA6NT3A.js} +3 -3
  92. package/dist/{chunk-TSIID2LV.js → chunk-ODRPASFP.js} +375 -1166
  93. package/dist/chunk-ODRPASFP.js.map +1 -0
  94. package/dist/{chunk-S3JKF3IK.js → chunk-OJJFANO6.js} +3 -3
  95. package/dist/{chunk-56SOPRM2.js → chunk-OQWPRFAC.js} +344 -4
  96. package/dist/chunk-OQWPRFAC.js.map +1 -0
  97. package/dist/{chunk-QEZZDIQT.js → chunk-P6YQWIT2.js} +4053 -4039
  98. package/dist/chunk-P6YQWIT2.js.map +1 -0
  99. package/dist/{chunk-GGGEGMWC.js → chunk-Q6RSJCXB.js} +9 -9
  100. package/dist/{chunk-OTIUEUIS.js → chunk-QKEUKBRK.js} +7 -7
  101. package/dist/{chunk-X52BVGCJ.js → chunk-QQDPRTLP.js} +5 -5
  102. package/dist/chunk-QQYCYAKI.js +79 -0
  103. package/dist/chunk-QQYCYAKI.js.map +1 -0
  104. package/dist/chunk-R4KDH477.js +1064 -0
  105. package/dist/chunk-R4KDH477.js.map +1 -0
  106. package/dist/{chunk-6AQSUBNR.js → chunk-RGCPELQN.js} +2 -2
  107. package/dist/{chunk-AXODGQ23.js → chunk-RGVCOG2S.js} +9 -2
  108. package/dist/{chunk-AXODGQ23.js.map → chunk-RGVCOG2S.js.map} +1 -1
  109. package/dist/chunk-SOLNJ3AZ.js +209 -0
  110. package/dist/chunk-SOLNJ3AZ.js.map +1 -0
  111. package/dist/{chunk-LQ33RLHL.js → chunk-TFT2X7SH.js} +3 -3
  112. package/dist/chunk-TVWCLUBI.js +293 -0
  113. package/dist/chunk-TVWCLUBI.js.map +1 -0
  114. package/dist/{chunk-VH7JMLTG.js → chunk-UIB33QQP.js} +25 -16
  115. package/dist/chunk-UIB33QQP.js.map +1 -0
  116. package/dist/chunk-V6GIVALQ.js +1889 -0
  117. package/dist/chunk-V6GIVALQ.js.map +1 -0
  118. package/dist/{chunk-IVHGQNIN.js → chunk-VHXCPXUS.js} +8 -8
  119. package/dist/{chunk-7DW7GAM6.js → chunk-VU6GMWF6.js} +2 -2
  120. package/dist/chunk-VWZYE3NC.js +8415 -0
  121. package/dist/chunk-VWZYE3NC.js.map +1 -0
  122. package/dist/{chunk-3X4GOMXT.js → chunk-W2GXIARJ.js} +12 -7
  123. package/dist/chunk-W2GXIARJ.js.map +1 -0
  124. package/dist/chunk-W4G3K3V7.js +288 -0
  125. package/dist/chunk-W4G3K3V7.js.map +1 -0
  126. package/dist/{chunk-FHXTEVO7.js → chunk-W74LJ5OT.js} +21 -28
  127. package/dist/chunk-W74LJ5OT.js.map +1 -0
  128. package/dist/{chunk-FOEPH67T.js → chunk-W7ELYLYK.js} +1 -74
  129. package/dist/chunk-W7ELYLYK.js.map +1 -0
  130. package/dist/{chunk-YU3DLVSQ.js → chunk-XSCGUO2U.js} +5 -5
  131. package/dist/{chunk-EPCIJLLU.js → chunk-XWROSMI5.js} +9 -9
  132. package/dist/{chunk-HMT6L65V.js → chunk-YJGEVBKZ.js} +4 -4
  133. package/dist/{chunk-7U3P4PB7.js → chunk-ZEYA2WWX.js} +4 -4
  134. package/dist/chunk-ZEYA2WWX.js.map +1 -0
  135. package/dist/chunk-ZRC7Z5X3.js +82 -0
  136. package/dist/chunk-ZRC7Z5X3.js.map +1 -0
  137. package/dist/{chunk-I47ARU5G.js → chunk-ZS7JIUJ3.js} +2 -2
  138. package/dist/{claude-cli-2YKABJJZ.js → claude-cli-GIIHOBGT.js} +4 -2
  139. package/dist/claude-install-BAUSJMW3.js +64 -0
  140. package/dist/{cli-BFDKEX53.js → cli-QY4KKA3D.js} +116 -49
  141. package/dist/cli-QY4KKA3D.js.map +1 -0
  142. package/dist/{client-XMWEKXX7.js → client-3YQKORVK.js} +4 -4
  143. package/dist/{codex-host-B6NAUWL6.js → codex-host-ZON3S6HU.js} +5 -5
  144. package/dist/{codex-install-GTGO5FYN.js → codex-install-HZV2DOAB.js} +62 -47
  145. package/dist/codex-install-HZV2DOAB.js.map +1 -0
  146. package/dist/{config-THJANIU5.js → config-QZOBMTEL.js} +18 -18
  147. package/dist/{config-names-JU54HYWY.js → config-names-Z5NZD5R2.js} +18 -18
  148. package/dist/{config-rules-VNU23RL4.js → config-rules-YOYHS6YL.js} +19 -19
  149. package/dist/config-subagents-WQV2ZAD5.js +362 -0
  150. package/dist/config-subagents-WQV2ZAD5.js.map +1 -0
  151. package/dist/{connect-HPWS7U63.js → connect-YDWTYU4B.js} +28 -27
  152. package/dist/{connect-HPWS7U63.js.map → connect-YDWTYU4B.js.map} +1 -1
  153. package/dist/core-0a66n3e7-TTP554XV.js +127 -0
  154. package/dist/core-0a66n3e7-TTP554XV.js.map +1 -0
  155. package/dist/core-0bmnpbz2-C2JIRVZO.js +10790 -0
  156. package/dist/core-0bmnpbz2-C2JIRVZO.js.map +1 -0
  157. package/dist/core-9je8ee1j-74DGHWPV.js +30 -0
  158. package/dist/core-9je8ee1j-74DGHWPV.js.map +1 -0
  159. package/dist/core-wadgcjfh-TSZFQZGH.js +666 -0
  160. package/dist/core-wadgcjfh-TSZFQZGH.js.map +1 -0
  161. package/dist/core-zg882d22-LKV5DZYW.js +37 -0
  162. package/dist/core-zg882d22-LKV5DZYW.js.map +1 -0
  163. package/dist/{decision-JIIHDTOF.js → decision-QSKHOGCO.js} +6 -6
  164. package/dist/{doctor-4MMHBRDU.js → doctor-ZWJXRD75.js} +67 -66
  165. package/dist/doctor-ZWJXRD75.js.map +1 -0
  166. package/dist/{explicit-AGENAX6E.js → explicit-ME2NRADQ.js} +45 -42
  167. package/dist/{explicit-AGENAX6E.js.map → explicit-ME2NRADQ.js.map} +1 -1
  168. package/dist/flush-stdio-NYIJ3QXT.js +18 -0
  169. package/dist/{fund-MLXUH24Q.js → fund-VF7TLDJH.js} +110 -34
  170. package/dist/fund-VF7TLDJH.js.map +1 -0
  171. package/dist/{hook-command-UB7FOEUL.js → hook-command-VZ27MGWO.js} +21 -20
  172. package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
  173. package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +2 -2
  174. package/dist/hosts/claude/tenjin/hooks/hook-data.ts +152 -0
  175. package/dist/hosts/claude/tenjin/hooks/hooks.json +7 -0
  176. package/dist/hosts/claude/tenjin/hooks/model-viewer.tsx +2987 -0
  177. package/dist/hosts/claude/tenjin/hooks/register.tsx +265 -30
  178. package/dist/hosts/claude/tenjin/skills/tenjin-pay/SKILL.md +14 -4
  179. package/dist/hosts/claude/tenjin/types/index.d.ts +133 -0
  180. package/dist/{hosts-WNQKYKP2.js → hosts-3EMTVM4H.js} +5 -3
  181. package/dist/index.js +16 -13
  182. package/dist/index.js.map +1 -1
  183. package/dist/{install-Q5SHHEDH.js → install-ZA7L2UF3.js} +34 -30
  184. package/dist/{install-funding-EGSW2KEP.js → install-funding-JDGYTF72.js} +9 -13
  185. package/dist/{install-identity-OID43B4D.js → install-identity-FFAYEFLX.js} +8 -8
  186. package/dist/{install-wallet-TZFWY5GK.js → install-wallet-2SFOVE3Q.js} +48 -33
  187. package/dist/{install-wallet-TZFWY5GK.js.map → install-wallet-2SFOVE3Q.js.map} +1 -1
  188. package/dist/mcp-36S6MK3C.js +67642 -0
  189. package/dist/mcp-36S6MK3C.js.map +1 -0
  190. package/dist/new-install-5L4GY3LN.js +51 -0
  191. package/dist/{package-NRHU7HBR.js → package-BONDXSV3.js} +2 -2
  192. package/dist/{passphrase-3JEVW5XG.js → passphrase-T4ULBN4M.js} +4 -4
  193. package/dist/{pay-I47AIUQR.js → pay-CMV5KL74.js} +37 -30
  194. package/dist/{payments-A5FNI5GN.js → payments-Z6UBZL4Z.js} +10 -10
  195. package/dist/reclaim-subagent-credit-ABSF67SJ.js +105 -0
  196. package/dist/reclaim-subagent-credit-ABSF67SJ.js.map +1 -0
  197. package/dist/{routing-quote-QQW2I5MH.js → routing-quote-AHLAREXR.js} +16 -18
  198. package/dist/{run-4SHEOBIU.js → run-JH7ELYAM.js} +41 -38
  199. package/dist/{runtime-BABJMHY7.js → runtime-2GX4ALJP.js} +12 -12
  200. package/dist/{runtime-activate-N6VLQI2C.js → runtime-activate-IDQ2NCSP.js} +9 -9
  201. package/dist/{runtime-launchers-GMAUICRW.js → runtime-launchers-YAPKCBHV.js} +7 -7
  202. package/dist/{runtime-place-DOEWFTF3.js → runtime-place-4POL4KK4.js} +3 -3
  203. package/dist/{send-ECXS6JEO.js → send-ELXFKEKY.js} +17 -17
  204. package/dist/{status-AHE5HSR7.js → status-FXUFWJDM.js} +89 -36
  205. package/dist/status-FXUFWJDM.js.map +1 -0
  206. package/dist/{status-line-63XFJAXR.js → status-line-IH5JBWBC.js} +11 -11
  207. package/dist/{streamableHttp-Z3YF6LTQ.js → streamableHttp-CP2ZQBIK.js} +4 -4
  208. package/dist/{uninstall-YGQPRCVY.js → uninstall-LJZUKM4D.js} +42 -38
  209. package/dist/{uninstall-YGQPRCVY.js.map → uninstall-LJZUKM4D.js.map} +1 -1
  210. package/dist/{update-GTLMLFA3.js → update-EUIX72IX.js} +34 -30
  211. package/dist/{usage-FCWP2CHO.js → usage-EKDC7LUC.js} +13 -13
  212. package/dist/{usdc-25RNBYYR.js → usdc-YIHK2OMC.js} +5 -5
  213. package/dist/{viemAdapter-By13KInL-3CG63XDX.js → viemAdapter-By13KInL-PRLSIESK.js} +2 -2
  214. package/dist/viemAdapter-By13KInL-PRLSIESK.js.map +1 -0
  215. package/dist/wallet-HSW757W6.js +80 -0
  216. package/dist/wallet-HSW757W6.js.map +1 -0
  217. package/docs/agent-permissions.md +19 -11
  218. package/docs/router-reference.md +21 -12
  219. package/docs/safety-model.md +4 -2
  220. package/docs/subagents-internals.md +97 -0
  221. package/docs/subagents.md +348 -0
  222. package/package.json +4 -1
  223. package/dist/balance-RQW5T5FB.js +0 -55
  224. package/dist/chunk-3X4GOMXT.js.map +0 -1
  225. package/dist/chunk-46HAB26L.js.map +0 -1
  226. package/dist/chunk-56SOPRM2.js.map +0 -1
  227. package/dist/chunk-5VWQSCDO.js.map +0 -1
  228. package/dist/chunk-6J64MQFD.js.map +0 -1
  229. package/dist/chunk-7U3P4PB7.js.map +0 -1
  230. package/dist/chunk-APWELUI7.js.map +0 -1
  231. package/dist/chunk-E6VP6MQM.js.map +0 -1
  232. package/dist/chunk-EQZ2CCWC.js.map +0 -1
  233. package/dist/chunk-FHXTEVO7.js.map +0 -1
  234. package/dist/chunk-FOEPH67T.js.map +0 -1
  235. package/dist/chunk-IVXPIIZJ.js +0 -91
  236. package/dist/chunk-IVXPIIZJ.js.map +0 -1
  237. package/dist/chunk-JF4T4HCQ.js.map +0 -1
  238. package/dist/chunk-LPQNZKSG.js +0 -269
  239. package/dist/chunk-LPQNZKSG.js.map +0 -1
  240. package/dist/chunk-MXN2ZEUB.js.map +0 -1
  241. package/dist/chunk-OO6FIBL7.js.map +0 -1
  242. package/dist/chunk-PNHNXUSL.js.map +0 -1
  243. package/dist/chunk-PYVQ74D5.js.map +0 -1
  244. package/dist/chunk-PZHBPGDE.js.map +0 -1
  245. package/dist/chunk-QEZZDIQT.js.map +0 -1
  246. package/dist/chunk-QXP3Z3JN.js.map +0 -1
  247. package/dist/chunk-RJ5HRPAZ.js.map +0 -1
  248. package/dist/chunk-TSIID2LV.js.map +0 -1
  249. package/dist/chunk-UVDJ5SSQ.js.map +0 -1
  250. package/dist/chunk-VFKPIIV2.js.map +0 -1
  251. package/dist/chunk-VH7JMLTG.js.map +0 -1
  252. package/dist/claude-install-7CVYQ73E.js +0 -60
  253. package/dist/cli-BFDKEX53.js.map +0 -1
  254. package/dist/codex-install-GTGO5FYN.js.map +0 -1
  255. package/dist/doctor-4MMHBRDU.js.map +0 -1
  256. package/dist/fund-MLXUH24Q.js.map +0 -1
  257. package/dist/mcp-CC3H7LFO.js +0 -3655
  258. package/dist/mcp-CC3H7LFO.js.map +0 -1
  259. package/dist/status-AHE5HSR7.js.map +0 -1
  260. package/dist/wallet-CJGEHP2Q.js +0 -64
  261. /package/dist/{_esm-MMYV66AX.js.map → _esm-2KST7HQ7.js.map} +0 -0
  262. /package/dist/{alive-VOIL5W3I.js.map → alive-5TV22PNF.js.map} +0 -0
  263. /package/dist/{auth-UHD3QFX4.js.map → auth-XI7BJFLW.js.map} +0 -0
  264. /package/dist/{balance-RQW5T5FB.js.map → balance-DFHC6XEU.js.map} +0 -0
  265. /package/dist/{ccip-CS7K5QRQ.js.map → ccip-HOW3DZYF.js.map} +0 -0
  266. /package/dist/{chunk-FSYH7J75.js.map → chunk-3Y6BHIN6.js.map} +0 -0
  267. /package/dist/{chunk-FZZWTDWP.js.map → chunk-3YPL6T3P.js.map} +0 -0
  268. /package/dist/{chunk-JEZMWJEF.js.map → chunk-44MVIRZH.js.map} +0 -0
  269. /package/dist/{chunk-27FIHFXF.js.map → chunk-45MMSBHA.js.map} +0 -0
  270. /package/dist/{chunk-7JB6SYJX.js.map → chunk-54ELBTKE.js.map} +0 -0
  271. /package/dist/{chunk-HWZO6HYZ.js.map → chunk-6QMDUDF2.js.map} +0 -0
  272. /package/dist/{chunk-FNBGRKS6.js.map → chunk-7V25UAQO.js.map} +0 -0
  273. /package/dist/{chunk-JOKPBYXP.js.map → chunk-DTEWAVNE.js.map} +0 -0
  274. /package/dist/{chunk-KAILF7QA.js.map → chunk-F43CV6UC.js.map} +0 -0
  275. /package/dist/{chunk-ACO7ZCR2.js.map → chunk-FKVJKLPI.js.map} +0 -0
  276. /package/dist/{chunk-2F5JUAHZ.js.map → chunk-GAJC4BQZ.js.map} +0 -0
  277. /package/dist/{chunk-L7N73ZAW.js.map → chunk-HAZAN4UM.js.map} +0 -0
  278. /package/dist/{chunk-6QJZA6EX.js.map → chunk-HI5XQOX2.js.map} +0 -0
  279. /package/dist/{chunk-BOENA6XR.js.map → chunk-HKGUKAQW.js.map} +0 -0
  280. /package/dist/{chunk-LJSCGIYH.js.map → chunk-HPRVFJPM.js.map} +0 -0
  281. /package/dist/{chunk-SDUOJRSV.js.map → chunk-IGLWLH73.js.map} +0 -0
  282. /package/dist/{chunk-3AKH7ODX.js.map → chunk-INSIW65E.js.map} +0 -0
  283. /package/dist/{chunk-2P3NJTHE.js.map → chunk-JHFFUVON.js.map} +0 -0
  284. /package/dist/{chunk-2TO5F6CT.js.map → chunk-K5KNGC4I.js.map} +0 -0
  285. /package/dist/{chunk-HUWTFKEM.js.map → chunk-KAQ4Q3TO.js.map} +0 -0
  286. /package/dist/{chunk-GS5RZF7U.js.map → chunk-KLDMLWXT.js.map} +0 -0
  287. /package/dist/{chunk-HN2EN6P4.js.map → chunk-KNKDMTHU.js.map} +0 -0
  288. /package/dist/{chunk-R2KMLONN.js.map → chunk-MJDO4EXD.js.map} +0 -0
  289. /package/dist/{chunk-IHVUE3XF.js.map → chunk-NJA6NT3A.js.map} +0 -0
  290. /package/dist/{chunk-S3JKF3IK.js.map → chunk-OJJFANO6.js.map} +0 -0
  291. /package/dist/{chunk-GGGEGMWC.js.map → chunk-Q6RSJCXB.js.map} +0 -0
  292. /package/dist/{chunk-OTIUEUIS.js.map → chunk-QKEUKBRK.js.map} +0 -0
  293. /package/dist/{chunk-X52BVGCJ.js.map → chunk-QQDPRTLP.js.map} +0 -0
  294. /package/dist/{chunk-6AQSUBNR.js.map → chunk-RGCPELQN.js.map} +0 -0
  295. /package/dist/{chunk-LQ33RLHL.js.map → chunk-TFT2X7SH.js.map} +0 -0
  296. /package/dist/{chunk-IVHGQNIN.js.map → chunk-VHXCPXUS.js.map} +0 -0
  297. /package/dist/{chunk-7DW7GAM6.js.map → chunk-VU6GMWF6.js.map} +0 -0
  298. /package/dist/{chunk-YU3DLVSQ.js.map → chunk-XSCGUO2U.js.map} +0 -0
  299. /package/dist/{chunk-EPCIJLLU.js.map → chunk-XWROSMI5.js.map} +0 -0
  300. /package/dist/{chunk-HMT6L65V.js.map → chunk-YJGEVBKZ.js.map} +0 -0
  301. /package/dist/{chunk-I47ARU5G.js.map → chunk-ZS7JIUJ3.js.map} +0 -0
  302. /package/dist/{claude-cli-2YKABJJZ.js.map → claude-cli-GIIHOBGT.js.map} +0 -0
  303. /package/dist/{claude-install-7CVYQ73E.js.map → claude-install-BAUSJMW3.js.map} +0 -0
  304. /package/dist/{client-XMWEKXX7.js.map → client-3YQKORVK.js.map} +0 -0
  305. /package/dist/{codex-host-B6NAUWL6.js.map → codex-host-ZON3S6HU.js.map} +0 -0
  306. /package/dist/{config-THJANIU5.js.map → config-QZOBMTEL.js.map} +0 -0
  307. /package/dist/{config-names-JU54HYWY.js.map → config-names-Z5NZD5R2.js.map} +0 -0
  308. /package/dist/{config-rules-VNU23RL4.js.map → config-rules-YOYHS6YL.js.map} +0 -0
  309. /package/dist/{decision-JIIHDTOF.js.map → decision-QSKHOGCO.js.map} +0 -0
  310. /package/dist/{hook-command-UB7FOEUL.js.map → flush-stdio-NYIJ3QXT.js.map} +0 -0
  311. /package/dist/{hosts-WNQKYKP2.js.map → hook-command-VZ27MGWO.js.map} +0 -0
  312. /package/dist/{install-Q5SHHEDH.js.map → hosts-3EMTVM4H.js.map} +0 -0
  313. /package/dist/{install-funding-EGSW2KEP.js.map → install-ZA7L2UF3.js.map} +0 -0
  314. /package/dist/{install-identity-OID43B4D.js.map → install-funding-JDGYTF72.js.map} +0 -0
  315. /package/dist/{package-NRHU7HBR.js.map → install-identity-FFAYEFLX.js.map} +0 -0
  316. /package/dist/{passphrase-3JEVW5XG.js.map → new-install-5L4GY3LN.js.map} +0 -0
  317. /package/dist/{pay-I47AIUQR.js.map → package-BONDXSV3.js.map} +0 -0
  318. /package/dist/{routing-quote-QQW2I5MH.js.map → passphrase-T4ULBN4M.js.map} +0 -0
  319. /package/dist/{run-4SHEOBIU.js.map → pay-CMV5KL74.js.map} +0 -0
  320. /package/dist/{payments-A5FNI5GN.js.map → payments-Z6UBZL4Z.js.map} +0 -0
  321. /package/dist/{runtime-activate-N6VLQI2C.js.map → routing-quote-AHLAREXR.js.map} +0 -0
  322. /package/dist/{runtime-launchers-GMAUICRW.js.map → run-JH7ELYAM.js.map} +0 -0
  323. /package/dist/{runtime-BABJMHY7.js.map → runtime-2GX4ALJP.js.map} +0 -0
  324. /package/dist/{runtime-place-DOEWFTF3.js.map → runtime-activate-IDQ2NCSP.js.map} +0 -0
  325. /package/dist/{update-GTLMLFA3.js.map → runtime-launchers-YAPKCBHV.js.map} +0 -0
  326. /package/dist/{usdc-25RNBYYR.js.map → runtime-place-4POL4KK4.js.map} +0 -0
  327. /package/dist/{send-ECXS6JEO.js.map → send-ELXFKEKY.js.map} +0 -0
  328. /package/dist/{status-line-63XFJAXR.js.map → status-line-IH5JBWBC.js.map} +0 -0
  329. /package/dist/{streamableHttp-Z3YF6LTQ.js.map → streamableHttp-CP2ZQBIK.js.map} +0 -0
  330. /package/dist/{viemAdapter-By13KInL-3CG63XDX.js.map → update-EUIX72IX.js.map} +0 -0
  331. /package/dist/{usage-FCWP2CHO.js.map → usage-EKDC7LUC.js.map} +0 -0
  332. /package/dist/{wallet-CJGEHP2Q.js.map → usdc-YIHK2OMC.js.map} +0 -0
@@ -0,0 +1,706 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ canonicalHash,
4
+ stable
5
+ } from "./chunk-R4KDH477.js";
6
+ import {
7
+ holdLock,
8
+ isHeldLockName,
9
+ sweepHeldLocks,
10
+ withHeldLock
11
+ } from "./chunk-TVWCLUBI.js";
12
+ import {
13
+ modelConsentSchema
14
+ } from "./chunk-LDA6TAYQ.js";
15
+ import {
16
+ LockTimeoutError
17
+ } from "./chunk-2W4DQQUU.js";
18
+ import {
19
+ readJsonFile,
20
+ sweep,
21
+ writePrivate
22
+ } from "./chunk-ILWCKCOI.js";
23
+ import {
24
+ loadRawConfig
25
+ } from "./chunk-UIB33QQP.js";
26
+ import {
27
+ defaultDataDir,
28
+ passphraseRecordPath,
29
+ realOr,
30
+ spendLedgerPath,
31
+ walletPath
32
+ } from "./chunk-JTX3BUDK.js";
33
+ import {
34
+ external_exports
35
+ } from "./chunk-P6YQWIT2.js";
36
+
37
+ // src/router/model-job.ts
38
+ import { randomUUID } from "node:crypto";
39
+ import { lstat, mkdir, opendir } from "node:fs/promises";
40
+ import { join } from "node:path";
41
+
42
+ // src/router/model-worker-control.ts
43
+ var ModelCallFailed = class extends Error {
44
+ constructor(message, detail, options) {
45
+ super(message, options);
46
+ this.detail = detail;
47
+ this.name = "ModelCallFailed";
48
+ }
49
+ detail;
50
+ };
51
+ var MODEL_RETRY = { tries: 6, baseMs: 500, maxMs: 1e4, jitter: 0.1, hintMs: 6e4 };
52
+ var MODEL_REFUSED_CODE = "model_refused";
53
+ var MODEL_CUT_REPLY_CODES = /* @__PURE__ */ new Set([
54
+ "model_stream_idle",
55
+ "model_deadline_exceeded"
56
+ ]);
57
+ function retryableModelCall(error) {
58
+ if (!(error instanceof ModelCallFailed) || error.detail.uncharged !== true) return false;
59
+ if (error.detail.relayed === true) return false;
60
+ const { cause, status, code } = error.detail;
61
+ if (code === MODEL_REFUSED_CODE) return false;
62
+ if (cause === "provider" || cause === "timeout") return true;
63
+ return cause === "failed" && (status === void 0 || status === 429 || status >= 500);
64
+ }
65
+ async function withModelRetry(call, signal, onRetry, wait = sleepFor, random = Math.random) {
66
+ for (let attempt = 1; ; attempt++) {
67
+ try {
68
+ return await call();
69
+ } catch (error) {
70
+ if (attempt >= MODEL_RETRY.tries || signal.aborted || !retryableModelCall(error)) throw error;
71
+ const hint = error.detail.retryAfterMs;
72
+ const backoff = Math.min(MODEL_RETRY.maxMs, MODEL_RETRY.baseMs * 2 ** (attempt - 1));
73
+ const ms = hint !== void 0 ? Math.min(hint, MODEL_RETRY.hintMs) : Math.round(backoff * (1 + MODEL_RETRY.jitter * (2 * random() - 1)));
74
+ onRetry(attempt, error);
75
+ await wait(ms, signal);
76
+ }
77
+ }
78
+ }
79
+ function sleepFor(ms, signal) {
80
+ return new Promise((resolve, reject) => {
81
+ if (signal.aborted) return reject(signal.reason);
82
+ const timer = setTimeout(resolve, ms);
83
+ signal.addEventListener(
84
+ "abort",
85
+ () => {
86
+ clearTimeout(timer);
87
+ reject(signal.reason);
88
+ },
89
+ { once: true }
90
+ );
91
+ });
92
+ }
93
+ function retryAfterMs(header, now = Date.now()) {
94
+ if (!header) return void 0;
95
+ const seconds = Number(header);
96
+ if (Number.isFinite(seconds) && seconds >= 0) return Math.round(seconds * 1e3);
97
+ const at = Date.parse(header);
98
+ return Number.isNaN(at) ? void 0 : Math.max(0, at - now);
99
+ }
100
+ function timedOut(error) {
101
+ let current = error;
102
+ for (let depth = 0; depth < 4 && typeof current === "object" && current !== null; depth++) {
103
+ const value = current;
104
+ if (value.name === "TimeoutError") return true;
105
+ current = value.cause;
106
+ }
107
+ return false;
108
+ }
109
+ function modelCallStop(error) {
110
+ if (!(error instanceof ModelCallFailed)) return error;
111
+ const { cause, status, payer, code } = error.detail;
112
+ return new ModelWorkerStopped({
113
+ kind: cause === "budget" ? "harness_limit" : "execution_failure",
114
+ reason: cause === "budget" ? "budget_guard" : cause === "timeout" ? "model_call_timeout" : cause === "payment_refused" ? "payment_refused" : cause === "provider" ? "provider_failed" : "model_call_failed",
115
+ ...status !== void 0 && Number.isInteger(status) && status >= 100 && status <= 599 ? { status } : {},
116
+ ...payer !== void 0 && /^[a-z][a-z_]{0,47}$/.test(payer) ? { payer } : {},
117
+ ...code !== void 0 && /^[a-z][a-z0-9_]{0,63}$/.test(code) ? { code } : {}
118
+ });
119
+ }
120
+ var ModelWorkerStopped = class extends Error {
121
+ constructor(stop, options) {
122
+ super(`Worker stopped: ${stop.reason}`, options);
123
+ this.stop = stop;
124
+ this.name = "ModelWorkerStopped";
125
+ }
126
+ stop;
127
+ };
128
+ var WORKER_ENDS = {
129
+ parent_cancel: "The parent cancelled it with subagent({cancel}).",
130
+ agent_stopped: "The person stopped the worker's agent.",
131
+ host_aborted: "The host ended the call that was running it.",
132
+ session_ended: "Its session or its Tenjin process ended.",
133
+ turn_limit: "It reached the job's turn limit.",
134
+ budget: "It reached its spending limit.",
135
+ output_limit: "It reached the model's output limit.",
136
+ context_limit: "It reached the model's context limit.",
137
+ not_started: "Its Claude Code did not start.",
138
+ model_call_failed: "Its model call through Tenjin returned no result; that call stays reserved until its receipt is read.",
139
+ model_call_timeout: "Its model call through Tenjin timed out; that call stays reserved until its receipt is read.",
140
+ payment_refused: "Tenjin refused to pay for its next model call, and sent nothing for it.",
141
+ provider: "DeepSeek could not take its next request, and nothing was charged for that call.",
142
+ refused: "DeepSeek refused to answer this request, and nothing was charged for that call.",
143
+ worker_error: "The worker or the provider failed."
144
+ };
145
+ function workerEnd(stop) {
146
+ switch (stop?.reason) {
147
+ case "turn_guard":
148
+ return "turn_limit";
149
+ case "budget_guard":
150
+ return "budget";
151
+ case "output_limit":
152
+ case "context_limit":
153
+ case "model_call_failed":
154
+ case "model_call_timeout":
155
+ case "payment_refused":
156
+ return stop.reason;
157
+ case "provider_failed":
158
+ return stop.code === MODEL_REFUSED_CODE ? "refused" : "provider";
159
+ case "startup_timeout":
160
+ return "not_started";
161
+ default:
162
+ return "worker_error";
163
+ }
164
+ }
165
+ function workerStop(error) {
166
+ return error instanceof ModelWorkerStopped ? error.stop : void 0;
167
+ }
168
+ function workerResultError(result) {
169
+ const turns = Number.isSafeInteger(result.num_turns) && result.num_turns >= 0 && result.num_turns <= 1e6 ? result.num_turns : void 0;
170
+ let stop;
171
+ switch (result.subtype) {
172
+ case "error_max_turns":
173
+ stop = { kind: "harness_limit", reason: "turn_guard" };
174
+ break;
175
+ case "error_max_budget_usd":
176
+ stop = { kind: "harness_limit", reason: "budget_guard" };
177
+ break;
178
+ case "error_max_structured_output_retries":
179
+ stop = { kind: "harness_limit", reason: "structured_output_guard" };
180
+ break;
181
+ default:
182
+ stop = result.stop_reason === "max_tokens" || result.stop_reason === "max_output_tokens" ? { kind: "provider_limit", reason: "output_limit" } : result.stop_reason === "prompt_too_long" ? { kind: "provider_limit", reason: "context_limit" } : { kind: "execution_failure", reason: "worker_execution" };
183
+ }
184
+ return new ModelWorkerStopped({ ...stop, ...turns === void 0 ? {} : { turns } });
185
+ }
186
+ var REPEAT_COUNTS = [3, 5, 8];
187
+ var REPEAT_ARGUMENT_CHARS = 500;
188
+ var GENTLE_REPEAT_REMINDER = "You are repeating the exact same tool call with identical arguments. Carefully analyze the previous result before calling again: if the task is not complete, try a different approach or different arguments instead of repeating the call.";
189
+ function detailedRepeatReminder(tool, count, canonical) {
190
+ const shown = canonical.length <= REPEAT_ARGUMENT_CHARS ? canonical : `${canonical.slice(0, REPEAT_ARGUMENT_CHARS)}\u2026 (+${canonical.length - REPEAT_ARGUMENT_CHARS} more chars)`;
191
+ return `Repeated tool call detected:
192
+ - tool: ${tool}
193
+ - consecutive_calls: ${count}
194
+ - arguments: ${shown}
195
+ The repeated calls are not making progress. Do not call this tool with these exact arguments again. Inspect the latest result and choose a different action, different arguments, or finish the task if enough evidence has been gathered.`;
196
+ }
197
+ var WorkerRepeatReminder = class {
198
+ previous;
199
+ count = 0;
200
+ /** One call the model made: the reminder to hand it at a count of 3, 5 or 8. */
201
+ observe(tool, input) {
202
+ let canonical;
203
+ try {
204
+ canonical = stable(input);
205
+ } catch {
206
+ this.previous = void 0;
207
+ this.count = 0;
208
+ return;
209
+ }
210
+ const identity = JSON.stringify([tool, canonical]);
211
+ this.count = identity === this.previous ? this.count + 1 : 1;
212
+ this.previous = identity;
213
+ if (!REPEAT_COUNTS.includes(this.count)) return;
214
+ return {
215
+ count: this.count,
216
+ text: this.count === REPEAT_COUNTS[0] ? GENTLE_REPEAT_REMINDER : detailedRepeatReminder(tool, this.count, canonical)
217
+ };
218
+ }
219
+ };
220
+
221
+ // src/router/model-job.ts
222
+ var jobSchema = external_exports.object({
223
+ id: external_exports.uuid(),
224
+ sessionId: external_exports.string(),
225
+ turnId: external_exports.string(),
226
+ callId: external_exports.string(),
227
+ root: external_exports.string(),
228
+ task: external_exports.string(),
229
+ native: external_exports.record(external_exports.string(), external_exports.unknown()),
230
+ nativeTool: external_exports.enum(["Agent", "Task"]).optional(),
231
+ /** The parent's model request that made the call, as the host numbers it. */
232
+ step: external_exports.string().optional(),
233
+ /** The agent id of the native subagent that made the call and receives its offer; absent for the main loop. */
234
+ caller: external_exports.string().optional(),
235
+ decision: external_exports.record(external_exports.string(), external_exports.unknown()),
236
+ capAtomic: external_exports.string().regex(/^\d+$/),
237
+ state: external_exports.enum([
238
+ "routing",
239
+ "offered",
240
+ "native",
241
+ "running",
242
+ "cancelling",
243
+ "completed",
244
+ "cancelled",
245
+ "unknown"
246
+ ]),
247
+ expiresAt: external_exports.number(),
248
+ result: external_exports.string().optional(),
249
+ /**
250
+ * The process that accepted the job and runs its worker, and when. For diagnosis only: whether
251
+ * a runner is alive is the runner lock (see {@link ModelJobStore.holdRunner}), never this pid.
252
+ */
253
+ runner: external_exports.object({ pid: external_exports.number().int(), acceptedAt: external_exports.number() }).optional()
254
+ });
255
+ var modelJobSchema = jobSchema;
256
+ var modelLock = (path, fn) => withHeldLock(path, fn);
257
+ var MODEL_RECORD_TTL_MS = 7 * 24 * 60 * 6e4;
258
+ var STRANDED_HANDBACK = {
259
+ status: "unknown",
260
+ endedBy: "session_ended",
261
+ ended: WORKER_ENDS.session_ended,
262
+ stopReason: { kind: "interrupted", reason: "session_ended" },
263
+ nextStep: "This worker stopped when its session or Tenjin process ended, as a native subagent does. It cannot be continued. If the work is still needed, start a fresh assignment with the needed context."
264
+ };
265
+ async function sweepModelRecords(dataDir, now = Date.now()) {
266
+ const live = /* @__PURE__ */ new Set();
267
+ const uuid = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
268
+ for (const job of await new ModelJobStore(dataDir).unfinished().catch(() => [])) {
269
+ live.add(job.id.toLowerCase());
270
+ for (const named of [job.decision.jobId, job.decision.workerHandle]) {
271
+ const id = typeof named === "string" ? uuid.exec(named)?.[0] : void 0;
272
+ if (id) live.add(id.toLowerCase());
273
+ }
274
+ }
275
+ const jobId = (name) => /^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/i.exec(name)?.[1];
276
+ const idle = async (name, path) => {
277
+ const id = jobId(name);
278
+ if (id && live.has(id.toLowerCase())) return false;
279
+ return now - (await lstat(path)).mtimeMs > MODEL_RECORD_TTL_MS;
280
+ };
281
+ const old = async (name, path) => isHeldLockName(name) ? false : idle(name, path);
282
+ for (const store of ["model-jobs", "model-conversations"]) {
283
+ const dir = join(dataDir, store);
284
+ await sweep(dir, old, { limit: 5e4 });
285
+ await sweepHeldLocks(
286
+ dir,
287
+ async (name) => jobId(name) !== void 0 && idle(name, join(dir, name))
288
+ );
289
+ }
290
+ }
291
+ var REPEATABLE = ["offered", "cancelled", "unknown"];
292
+ var OFFER_MS = 15 * 6e4;
293
+ var unresolved = (job) => job.state !== "native" && job.state !== "completed" && (job.expiresAt > Date.now() || ["running", "cancelling"].includes(job.state));
294
+ function routingAuthorizedAtomic(decision) {
295
+ const value = decision.routingAuthorizedAtomic;
296
+ if (typeof value !== "string" || !/^\d{1,30}$/.test(value))
297
+ throw new Error("The job has no routing authorization");
298
+ return BigInt(value);
299
+ }
300
+ var NO_OFFER_CODES = [
301
+ "kept_native",
302
+ "no_session",
303
+ "host_unqualified",
304
+ "no_consent",
305
+ "permission_mode",
306
+ "worker_unqualified",
307
+ "input_filter",
308
+ "caller_unqualified",
309
+ "scope_not_covered",
310
+ "parent_context_unavailable",
311
+ "over_size_limit",
312
+ "job_cap_too_low",
313
+ "job_cap_lowered",
314
+ "capture_error",
315
+ "route_error",
316
+ "fee_above_ceiling",
317
+ "server_declined",
318
+ "invalid_offer",
319
+ "superseded",
320
+ "expired",
321
+ "interrupted"
322
+ ];
323
+ var noOfferSchema = external_exports.object({
324
+ at: external_exports.number(),
325
+ sessionId: external_exports.string(),
326
+ tool: external_exports.string(),
327
+ code: external_exports.enum(NO_OFFER_CODES),
328
+ /** A field name, a mode or the server's own code. */
329
+ detail: external_exports.string().regex(/^[A-Za-z0-9_.:-]{1,64}$/).optional(),
330
+ bytes: external_exports.number().optional(),
331
+ limit: external_exports.number().optional(),
332
+ offerId: external_exports.uuid().optional(),
333
+ /** Set when a native subagent made the call, not the main loop. */
334
+ from: external_exports.literal("subagent").optional()
335
+ });
336
+ var NO_OFFERS_KEPT = 200;
337
+ var NO_OFFERS_FILE = "no-offers.json";
338
+ var REPEATS_KEPT = 16;
339
+ function repeatKey(native) {
340
+ return Object.fromEntries(
341
+ Object.entries(native).flatMap(([key, raw]) => {
342
+ const value = typeof raw === "string" ? raw.trim() : raw;
343
+ return value === null || value === false || key === "subagent_type" && value === "general-purpose" ? [] : [[key, value]];
344
+ })
345
+ );
346
+ }
347
+ var ModelJobStore = class {
348
+ dir;
349
+ constructor(dataDir) {
350
+ this.dir = join(dataDir, "model-jobs");
351
+ }
352
+ path(id) {
353
+ if (!external_exports.uuid().safeParse(id).success) throw new Error("Invalid model job");
354
+ return join(this.dir, `${id}.json`);
355
+ }
356
+ callPath(sessionId, callId) {
357
+ return join(this.dir, `call-${canonicalHash({ sessionId, callId })}.json`);
358
+ }
359
+ /** The held Claude calls with this content in this session and root, oldest first. */
360
+ async repeatIds(path) {
361
+ const index = await readJsonFile(path, 4e3);
362
+ return (Array.isArray(index?.ids) ? index.ids : []).filter(
363
+ (id) => external_exports.uuid().safeParse(id).success
364
+ );
365
+ }
366
+ repeatPath(sessionId, root, tool, native) {
367
+ return join(
368
+ this.dir,
369
+ `repeat-${canonicalHash({ sessionId, root, tool, native: repeatKey(native) })}.json`
370
+ );
371
+ }
372
+ async locked(fn) {
373
+ await mkdir(this.dir, { recursive: true, mode: 448 });
374
+ return modelLock(join(this.dir, "lock"), fn);
375
+ }
376
+ async read(id) {
377
+ const raw = await readJsonFile(this.path(id), 1e6);
378
+ const p = jobSchema.safeParse(raw);
379
+ return p.success ? p.data : null;
380
+ }
381
+ /** Every held call is its own job, whatever else its session has open or running. */
382
+ async offer(input, state = "offered") {
383
+ return this.locked(async () => {
384
+ const index = this.callPath(input.sessionId, input.callId);
385
+ const previous = await readJsonFile(index, 1e3);
386
+ const old = typeof previous?.id === "string" ? await this.read(previous.id) : null;
387
+ if (old && unresolved(old)) {
388
+ if (old.callId === input.callId && canonicalHash(old.native) === canonicalHash(input.native))
389
+ return old;
390
+ throw new Error("This call id already names another unresolved delegation");
391
+ }
392
+ const job = {
393
+ ...input,
394
+ id: randomUUID(),
395
+ state,
396
+ expiresAt: Date.now() + OFFER_MS
397
+ };
398
+ const serialized = JSON.stringify(job);
399
+ if (Buffer.byteLength(serialized) > 1e6)
400
+ throw new Error("Complete model assignment exceeds private record size limit");
401
+ await writePrivate(this.path(job.id), serialized);
402
+ await writePrivate(index, JSON.stringify({ id: job.id }));
403
+ if (input.nativeTool) {
404
+ const path = this.repeatPath(input.sessionId, input.root, input.nativeTool, input.native);
405
+ const ids = [...await this.repeatIds(path), job.id].slice(-REPEATS_KEPT);
406
+ await writePrivate(path, JSON.stringify({ ids }));
407
+ }
408
+ return job;
409
+ });
410
+ }
411
+ /**
412
+ * A job by its own id, in any turn and from any process, for the session
413
+ * that owns it. Another session gets nothing, as for an id that never was.
414
+ */
415
+ async owned(id, session) {
416
+ if (!external_exports.uuid().safeParse(id).success) return null;
417
+ const job = await this.read(id);
418
+ return job?.sessionId === session ? job : null;
419
+ }
420
+ /** Fences one job by its own id, for its session: nothing else of the session is touched. */
421
+ async fenceOwned(id, session, state = "cancelled") {
422
+ return this.locked(async () => this.fenced(await this.owned(id, session), state));
423
+ }
424
+ async fenced(job, state) {
425
+ if (!job || ["native", "completed", "cancelled", "unknown"].includes(job.state)) return;
426
+ await writePrivate(this.path(job.id), JSON.stringify({ ...job, state }));
427
+ }
428
+ async decided(id, decision) {
429
+ return this.locked(async () => {
430
+ const job = await this.read(id);
431
+ if (!job || job.state !== "routing") return;
432
+ await writePrivate(
433
+ this.path(id),
434
+ JSON.stringify({
435
+ ...job,
436
+ decision,
437
+ state: decision.action === "model" ? "offered" : "native"
438
+ })
439
+ );
440
+ });
441
+ }
442
+ /** Every record still `running` or `cancelling`, whichever session owns it. Never throws. */
443
+ async unfinished() {
444
+ const found = [];
445
+ try {
446
+ let seen = 0;
447
+ for await (const entry of await opendir(this.dir)) {
448
+ if (++seen > 5e4) break;
449
+ const id = /^(.+)\.json$/.exec(entry.name)?.[1];
450
+ if (!entry.isFile() || !id || !external_exports.uuid().safeParse(id).success) continue;
451
+ const job = await this.read(id);
452
+ if (job && ["running", "cancelling"].includes(job.state)) found.push(job);
453
+ }
454
+ } catch {
455
+ }
456
+ return found;
457
+ }
458
+ /** The runner lock of a job: `<id>.runner.held` in the store. */
459
+ runnerPath(id) {
460
+ if (!external_exports.uuid().safeParse(id).success) throw new Error("Invalid model job");
461
+ return join(this.dir, `${id}.runner`);
462
+ }
463
+ /**
464
+ * Takes the job's runner lock, which the process that accepts the job holds from BEFORE
465
+ * {@link accept} until after the job's last `finish`: a runner is alive exactly while its
466
+ * lock is held, in any process, pid namespace or platform, and no pid is consulted. Waits up
467
+ * to 5 s (a second accept of the same offer), then throws LockTimeoutError. Release it when
468
+ * accept returns null.
469
+ */
470
+ async holdRunner(id) {
471
+ const path = this.runnerPath(id);
472
+ await mkdir(this.dir, { recursive: true, mode: 448 });
473
+ return holdLock(path);
474
+ }
475
+ /** Once, on disk. The offer is accepted from any turn of its session. */
476
+ async accept(id, session) {
477
+ return this.locked(async () => {
478
+ const job = await this.read(id);
479
+ if (!job || job.sessionId !== session || job.expiresAt <= Date.now() || job.state !== "offered")
480
+ return null;
481
+ job.state = "running";
482
+ job.runner = { pid: process.pid, acceptedAt: Date.now() };
483
+ await writePrivate(this.path(id), JSON.stringify(job));
484
+ return job;
485
+ });
486
+ }
487
+ /**
488
+ * Ends a record whose runner is gone: no process holds its runner lock, so the process that
489
+ * accepted it has ended (or never held it). The record becomes `unknown` and is returned. Null
490
+ * while a runner holds the lock, in this process or another. The probe is one attempt and
491
+ * holds the lock while the record is rewritten, so no runner can start under it. The lock
492
+ * order is runner, then job, as in `accept`.
493
+ */
494
+ async strand(id) {
495
+ const first = await this.read(id);
496
+ if (!first || !["running", "cancelling"].includes(first.state)) return first;
497
+ await mkdir(this.dir, { recursive: true, mode: 448 });
498
+ let release;
499
+ try {
500
+ release = await holdLock(this.runnerPath(id), { timeoutMs: 0 });
501
+ } catch (error) {
502
+ if (error instanceof LockTimeoutError) return null;
503
+ throw error;
504
+ }
505
+ try {
506
+ return await this.locked(async () => {
507
+ const job = await this.read(id);
508
+ if (!job || !["running", "cancelling"].includes(job.state)) return job;
509
+ const ended = {
510
+ ...job,
511
+ state: "unknown",
512
+ expiresAt: Math.max(job.expiresAt, Date.now() + OFFER_MS),
513
+ result: JSON.stringify(STRANDED_HANDBACK)
514
+ };
515
+ await writePrivate(this.path(id), JSON.stringify(ended));
516
+ return ended;
517
+ });
518
+ } finally {
519
+ release();
520
+ }
521
+ }
522
+ /**
523
+ * Claude: the parent keeps an offered call native by sending it again
524
+ * unchanged. Matched by content, never by call ID, so the host's permission
525
+ * review sees the call that runs. Once per offer: a match ends the offer, so
526
+ * it cannot be accepted after, and a later repeat is a new call. It matches
527
+ * in the same session, workspace root and agent loop (`caller`, the native
528
+ * subagent that made the offered call, or none for the main loop) until the
529
+ * offer expires, or for the same time after its accepted worker stopped. No
530
+ * turn boundary is read.
531
+ *
532
+ * Several open offers can hold the same content. One repeat settles one of
533
+ * them, the oldest first. A call made by the same model request (`step`) as
534
+ * an offered call was written before that offer was read: it is a second
535
+ * call, not its repeat, and is judged by itself.
536
+ *
537
+ * @returns the offer the repeat settled, else null.
538
+ */
539
+ async nativeRepeat(session, root, tool, native, step, caller) {
540
+ return this.locked(async () => {
541
+ for (const id of await this.repeatIds(this.repeatPath(session, root, tool, native))) {
542
+ const job = await this.read(id);
543
+ if (!job || job.sessionId !== session || job.root !== root || job.nativeTool !== tool || !REPEATABLE.includes(job.state) || job.expiresAt <= Date.now() || // An offer is kept native by the loop it was made to, not by another's same call.
544
+ job.caller !== caller || step !== void 0 && job.step === step || canonicalHash(repeatKey(job.native)) !== canonicalHash(repeatKey(native)))
545
+ continue;
546
+ await writePrivate(this.path(job.id), JSON.stringify({ ...job, state: "native" }));
547
+ return job.id;
548
+ }
549
+ return null;
550
+ });
551
+ }
552
+ async finish(id, state, result) {
553
+ return this.locked(async () => {
554
+ const job = await this.read(id);
555
+ if (!job || !["running", "cancelling"].includes(job.state)) return;
556
+ await writePrivate(
557
+ this.path(id),
558
+ JSON.stringify({
559
+ ...job,
560
+ state,
561
+ // A worker that stopped leaves its call a free native repeat, from now.
562
+ ...state === "completed" ? {} : { expiresAt: Math.max(job.expiresAt, Date.now() + OFFER_MS) },
563
+ ...result ? { result } : {}
564
+ })
565
+ );
566
+ });
567
+ }
568
+ /** Records why a call got no offer, newest last, in one bounded private file. Never throws. */
569
+ async noOffer(entry) {
570
+ try {
571
+ const parsed = noOfferSchema.safeParse({ ...entry, at: Date.now() });
572
+ if (!parsed.success) return;
573
+ await this.locked(async () => {
574
+ const kept = (await this.noOffers()).filter(
575
+ (old) => parsed.data.at - old.at < MODEL_RECORD_TTL_MS
576
+ );
577
+ await writePrivate(
578
+ join(this.dir, NO_OFFERS_FILE),
579
+ JSON.stringify({ records: [...kept, parsed.data].slice(-NO_OFFERS_KEPT) })
580
+ );
581
+ });
582
+ } catch {
583
+ }
584
+ }
585
+ /** The kept no-offer records, oldest first. */
586
+ async noOffers() {
587
+ const raw = await readJsonFile(join(this.dir, NO_OFFERS_FILE), 2e5).catch(() => null);
588
+ return Array.isArray(raw?.records) ? raw.records.flatMap((entry) => {
589
+ const parsed = noOfferSchema.safeParse(entry);
590
+ return parsed.success ? [parsed.data] : [];
591
+ }) : [];
592
+ }
593
+ };
594
+
595
+ // src/router/windows-worker-config.ts
596
+ import { constants } from "node:fs";
597
+ import { access, lstat as lstat2, realpath, stat } from "node:fs/promises";
598
+ import { homedir } from "node:os";
599
+ import { win32 } from "node:path";
600
+ var localPath = external_exports.string().regex(/^[A-Za-z]:[\\/][^:"<>|?*]+$/).refine((path) => Array.from(path).every((character) => character.charCodeAt(0) >= 32));
601
+ var executablePath = localPath.refine((path) => win32.extname(path).toLowerCase() === ".exe");
602
+ var configSchema = external_exports.strictObject({
603
+ version: external_exports.literal(1),
604
+ workerSid: external_exports.string().regex(/^S-1-5-21-(?:\d{1,10}-){3}\d{1,10}$/),
605
+ launcherPath: executablePath,
606
+ claudePath: executablePath,
607
+ configDir: localPath,
608
+ routerOrigin: external_exports.url().refine((url) => URL.canParse(url) && new URL(url).origin === url),
609
+ shellAccess: external_exports.literal("native-windows")
610
+ });
611
+ function within(root, path) {
612
+ const relative = win32.relative(root, path);
613
+ return relative === "" || relative !== ".." && !relative.startsWith("..\\") && !win32.isAbsolute(relative);
614
+ }
615
+ async function validateWindowsWorkerConfig(input, dataDir) {
616
+ if (process.platform !== "win32") return null;
617
+ const parsed = configSchema.safeParse(input);
618
+ if (!parsed.success) return null;
619
+ const { launcherPath, claudePath, configDir } = parsed.data;
620
+ try {
621
+ const [launcherExe, claudeExe, profile, controllerData, defaultData, controllerProfile] = await Promise.all([
622
+ realpath(launcherPath),
623
+ realpath(claudePath),
624
+ realpath(configDir),
625
+ realOr(dataDir),
626
+ realOr(defaultDataDir()),
627
+ realOr(win32.join(homedir(), ".claude"))
628
+ ]);
629
+ const canonical = configSchema.safeParse({
630
+ ...parsed.data,
631
+ launcherPath: launcherExe,
632
+ claudePath: claudeExe,
633
+ configDir: profile
634
+ });
635
+ if (!canonical.success || win32.relative(launcherExe, claudeExe) === "") return null;
636
+ for (const privateDir of [controllerData, defaultData, controllerProfile]) {
637
+ if (within(privateDir, profile) || within(profile, privateDir) || within(privateDir, launcherExe) || within(privateDir, claudeExe))
638
+ return null;
639
+ }
640
+ const [launcherStat, claudeStat, profileStat] = await Promise.all([
641
+ stat(launcherExe),
642
+ stat(claudeExe),
643
+ stat(profile)
644
+ ]);
645
+ if (!launcherStat.isFile() || !claudeStat.isFile() || !profileStat.isDirectory()) return null;
646
+ await Promise.all(
647
+ [launcherExe, claudeExe, profile].map((path) => access(path, constants.R_OK))
648
+ );
649
+ for (const privateFile of [
650
+ win32.join(profile, ".credentials.json"),
651
+ walletPath(profile),
652
+ spendLedgerPath(profile),
653
+ passphraseRecordPath(profile)
654
+ ]) {
655
+ const exists = await lstat2(privateFile).then(
656
+ () => true,
657
+ (error) => {
658
+ if (error.code === "ENOENT") return false;
659
+ throw error;
660
+ }
661
+ );
662
+ if (exists) return null;
663
+ }
664
+ return canonical.data;
665
+ } catch {
666
+ return null;
667
+ }
668
+ }
669
+ async function loadWindowsWorkerConfig(dataDir) {
670
+ if (process.platform !== "win32") return null;
671
+ const router = (await loadRawConfig(dataDir).catch(() => null))?.router;
672
+ if (router?.subagents !== true) return null;
673
+ const record = configSchema.safeParse(router.windowsWorker);
674
+ const consent = modelConsentSchema.safeParse(router.subagentConsent);
675
+ if (!record.success || !consent.success || consent.data.routerOrigin !== record.data.routerOrigin)
676
+ return null;
677
+ const config = await validateWindowsWorkerConfig(record.data, dataDir);
678
+ if (!config || win32.relative(config.launcherPath, record.data.launcherPath) !== "" || win32.relative(config.claudePath, record.data.claudePath) !== "" || win32.relative(config.configDir, record.data.configDir) !== "")
679
+ return null;
680
+ return config;
681
+ }
682
+
683
+ export {
684
+ ModelCallFailed,
685
+ MODEL_REFUSED_CODE,
686
+ MODEL_CUT_REPLY_CODES,
687
+ withModelRetry,
688
+ sleepFor,
689
+ retryAfterMs,
690
+ timedOut,
691
+ modelCallStop,
692
+ ModelWorkerStopped,
693
+ WORKER_ENDS,
694
+ workerEnd,
695
+ workerStop,
696
+ workerResultError,
697
+ WorkerRepeatReminder,
698
+ modelJobSchema,
699
+ modelLock,
700
+ sweepModelRecords,
701
+ routingAuthorizedAtomic,
702
+ ModelJobStore,
703
+ validateWindowsWorkerConfig,
704
+ loadWindowsWorkerConfig
705
+ };
706
+ //# sourceMappingURL=chunk-BVP7YK2J.js.map