jialing-code 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (460) hide show
  1. package/README.md +97 -0
  2. package/dist/chunk-065m026w.js +97 -0
  3. package/dist/chunk-06saje2v.js +39 -0
  4. package/dist/chunk-0731m51q.js +8 -0
  5. package/dist/chunk-0975ccyw.js +265 -0
  6. package/dist/chunk-09n3fjx5.js +67 -0
  7. package/dist/chunk-0bdjdzew.js +41 -0
  8. package/dist/chunk-0ce6kd7y.js +212 -0
  9. package/dist/chunk-0e1xsncc.js +969 -0
  10. package/dist/chunk-0m2861gw.js +154 -0
  11. package/dist/chunk-0paqc2yw.js +15 -0
  12. package/dist/chunk-0rg6yrhy.js +99 -0
  13. package/dist/chunk-0sakxrcf.js +643 -0
  14. package/dist/chunk-0v9hwxvz.js +105 -0
  15. package/dist/chunk-0vkfrmqm.js +690 -0
  16. package/dist/chunk-0vvfnhhv.js +248 -0
  17. package/dist/chunk-0w4rsycj.js +145 -0
  18. package/dist/chunk-0x9b2nmd.js +63 -0
  19. package/dist/chunk-0xjaqda8.js +1124 -0
  20. package/dist/chunk-1141xmr4.js +8 -0
  21. package/dist/chunk-13d1842d.js +154 -0
  22. package/dist/chunk-1921a6yb.js +32 -0
  23. package/dist/chunk-1ad8mk9g.js +527 -0
  24. package/dist/chunk-1ax41pws.js +28 -0
  25. package/dist/chunk-1c8z1b5v.js +16 -0
  26. package/dist/chunk-1cbn5kxf.js +7 -0
  27. package/dist/chunk-1eapde8a.js +726 -0
  28. package/dist/chunk-1h2famwb.js +49 -0
  29. package/dist/chunk-1jggnf7z.js +85 -0
  30. package/dist/chunk-1k92pn9c.js +32 -0
  31. package/dist/chunk-1qakq4sn.js +802 -0
  32. package/dist/chunk-1rvz0433.js +722 -0
  33. package/dist/chunk-1xkekb9y.js +19 -0
  34. package/dist/chunk-238g70xa.js +36 -0
  35. package/dist/chunk-24ge0eqa.js +106 -0
  36. package/dist/chunk-278vghwm.js +5395 -0
  37. package/dist/chunk-27xc1csx.js +104 -0
  38. package/dist/chunk-2a42s11t.js +412 -0
  39. package/dist/chunk-2aa02aw6.js +438 -0
  40. package/dist/chunk-2eykm0j0.js +20 -0
  41. package/dist/chunk-2gzv8nrw.js +205 -0
  42. package/dist/chunk-2k995y2x.js +880 -0
  43. package/dist/chunk-2nayx6q1.js +63 -0
  44. package/dist/chunk-2sd2w2h4.js +44 -0
  45. package/dist/chunk-2tw2ve8h.js +145 -0
  46. package/dist/chunk-30rst83v.js +168 -0
  47. package/dist/chunk-3aavh06g.js +1581 -0
  48. package/dist/chunk-3b0yvt2h.js +469 -0
  49. package/dist/chunk-3be7ka25.js +56 -0
  50. package/dist/chunk-3c25bcsw.js +17 -0
  51. package/dist/chunk-3dyxka97.js +584 -0
  52. package/dist/chunk-3f7rypmf.js +16544 -0
  53. package/dist/chunk-3fsd7f51.js +93 -0
  54. package/dist/chunk-3gqdqmzb.js +75 -0
  55. package/dist/chunk-3h8a89gy.js +46 -0
  56. package/dist/chunk-3m84sret.js +71 -0
  57. package/dist/chunk-3nb7j3js.js +96 -0
  58. package/dist/chunk-3p08nvn2.js +98 -0
  59. package/dist/chunk-3r09htpc.js +318 -0
  60. package/dist/chunk-3r24h7t6.js +113 -0
  61. package/dist/chunk-3rkfxjtq.js +80 -0
  62. package/dist/chunk-3tmk7dc2.js +604 -0
  63. package/dist/chunk-3w6s9m5w.js +16 -0
  64. package/dist/chunk-43qjymy5.js +92 -0
  65. package/dist/chunk-44fpr6jq.js +434 -0
  66. package/dist/chunk-45kxdsp8.js +444 -0
  67. package/dist/chunk-495d85x1.js +8066 -0
  68. package/dist/chunk-4ba796se.js +1095 -0
  69. package/dist/chunk-4g3v8y12.js +23 -0
  70. package/dist/chunk-4h53xj8n.js +3445 -0
  71. package/dist/chunk-4jm600zv.js +13 -0
  72. package/dist/chunk-4jy9dtwk.js +116 -0
  73. package/dist/chunk-4p60dd45.js +55 -0
  74. package/dist/chunk-4z0jsrqg.js +81 -0
  75. package/dist/chunk-4zfkzkt6.js +37 -0
  76. package/dist/chunk-55wgxwa9.js +13877 -0
  77. package/dist/chunk-5dbk24zg.js +890 -0
  78. package/dist/chunk-5hzvp4va.js +115 -0
  79. package/dist/chunk-5kbt1mbt.js +500 -0
  80. package/dist/chunk-5pen7vr8.js +176 -0
  81. package/dist/chunk-5r280eng.js +198 -0
  82. package/dist/chunk-5srym52s.js +88 -0
  83. package/dist/chunk-600kg7k6.js +41 -0
  84. package/dist/chunk-616w0qj3.js +160 -0
  85. package/dist/chunk-62jw1t8c.js +94 -0
  86. package/dist/chunk-62xmt9mk.js +372 -0
  87. package/dist/chunk-64bvg7c3.js +229 -0
  88. package/dist/chunk-65yhe4s0.js +281 -0
  89. package/dist/chunk-6aewh27m.js +102 -0
  90. package/dist/chunk-6bd8brc4.js +48 -0
  91. package/dist/chunk-6dj5t602.js +341 -0
  92. package/dist/chunk-6exxdk1p.js +6956 -0
  93. package/dist/chunk-6f5j8fs0.js +752 -0
  94. package/dist/chunk-6g62sjpf.js +328 -0
  95. package/dist/chunk-6gecq2ta.js +1493 -0
  96. package/dist/chunk-6gr3c3w9.js +378 -0
  97. package/dist/chunk-6kpbgc5w.js +23 -0
  98. package/dist/chunk-6kseqw79.js +154 -0
  99. package/dist/chunk-6mxm1qd0.js +40764 -0
  100. package/dist/chunk-6n2qgm9v.js +8 -0
  101. package/dist/chunk-6tq2v3rk.js +186 -0
  102. package/dist/chunk-6wsdhj3v.js +93 -0
  103. package/dist/chunk-6zw9fhgb.js +4389 -0
  104. package/dist/chunk-71grc1mw.js +111 -0
  105. package/dist/chunk-73rpbt04.js +1947 -0
  106. package/dist/chunk-748feghg.js +604 -0
  107. package/dist/chunk-75e8gtg9.js +84 -0
  108. package/dist/chunk-75th4717.js +780 -0
  109. package/dist/chunk-760252na.js +101 -0
  110. package/dist/chunk-7739pg2c.js +4261 -0
  111. package/dist/chunk-778fnx46.js +472 -0
  112. package/dist/chunk-77g09znh.js +391 -0
  113. package/dist/chunk-7aw745vx.js +40175 -0
  114. package/dist/chunk-7m2nd8da.js +110 -0
  115. package/dist/chunk-7n35vjtw.js +444 -0
  116. package/dist/chunk-7n5ss4sh.js +144 -0
  117. package/dist/chunk-7rjnxcfe.js +107 -0
  118. package/dist/chunk-7sb5axvf.js +122 -0
  119. package/dist/chunk-7wm5s02e.js +216 -0
  120. package/dist/chunk-7ymfj7m3.js +151 -0
  121. package/dist/chunk-7z8j9qfn.js +121 -0
  122. package/dist/chunk-7zsapntc.js +216 -0
  123. package/dist/chunk-805fhkfh.js +908 -0
  124. package/dist/chunk-80k1nj24.js +253 -0
  125. package/dist/chunk-83hfzbx3.js +10 -0
  126. package/dist/chunk-85cypsdd.js +92 -0
  127. package/dist/chunk-8760caxf.js +2644 -0
  128. package/dist/chunk-88f6egg6.js +387 -0
  129. package/dist/chunk-88r7kwgj.js +22 -0
  130. package/dist/chunk-89e1v45e.js +463 -0
  131. package/dist/chunk-8bedvdm1.js +32 -0
  132. package/dist/chunk-8c4x4vdz.js +177 -0
  133. package/dist/chunk-8hq5kk3y.js +44 -0
  134. package/dist/chunk-8ngxagxq.js +18 -0
  135. package/dist/chunk-8tnsngw2.js +31 -0
  136. package/dist/chunk-8wjnca8h.js +307 -0
  137. package/dist/chunk-8y12jxg8.js +10 -0
  138. package/dist/chunk-8ymf4e6z.js +48 -0
  139. package/dist/chunk-90wp6wez.js +10510 -0
  140. package/dist/chunk-92bp5bnf.js +650 -0
  141. package/dist/chunk-92q8sx5z.js +90 -0
  142. package/dist/chunk-958rtmtx.js +10476 -0
  143. package/dist/chunk-9e2kqv5g.js +125 -0
  144. package/dist/chunk-9f4f1hy5.js +281 -0
  145. package/dist/chunk-9gbamk79.js +93 -0
  146. package/dist/chunk-9k5s3ryh.js +167 -0
  147. package/dist/chunk-9xzfqm15.js +97 -0
  148. package/dist/chunk-9zgdvbm6.js +110 -0
  149. package/dist/chunk-a0p3q8jw.js +24 -0
  150. package/dist/chunk-a22sayzp.js +220 -0
  151. package/dist/chunk-a8ejc632.js +3094 -0
  152. package/dist/chunk-a8gj9d9z.js +120 -0
  153. package/dist/chunk-a9vdeb6y.js +258 -0
  154. package/dist/chunk-a9yev47v.js +674 -0
  155. package/dist/chunk-a9zh40sj.js +48 -0
  156. package/dist/chunk-ack5mfba.js +105 -0
  157. package/dist/chunk-ae76ded0.js +30 -0
  158. package/dist/chunk-akjw4dh6.js +538 -0
  159. package/dist/chunk-asc6wz4q.js +1188 -0
  160. package/dist/chunk-atqejh3p.js +273 -0
  161. package/dist/chunk-atv2e6b7.js +61 -0
  162. package/dist/chunk-axvvkwz8.js +1551 -0
  163. package/dist/chunk-azgz7kj9.js +38 -0
  164. package/dist/chunk-b3zave8q.js +275 -0
  165. package/dist/chunk-b4wg70y1.js +54 -0
  166. package/dist/chunk-b8b13qn2.js +100 -0
  167. package/dist/chunk-bg3mt9bm.js +28 -0
  168. package/dist/chunk-bh4jvcjn.js +91 -0
  169. package/dist/chunk-bhdt6k7w.js +15 -0
  170. package/dist/chunk-bm1qb16p.js +17 -0
  171. package/dist/chunk-bpvsd1j1.js +266 -0
  172. package/dist/chunk-bqfnp99q.js +477 -0
  173. package/dist/chunk-bsbmmfyt.js +17 -0
  174. package/dist/chunk-bsbt34jm.js +42 -0
  175. package/dist/chunk-c78akdhr.js +458 -0
  176. package/dist/chunk-cdz5yb0r.js +57 -0
  177. package/dist/chunk-cfv996bs.js +22 -0
  178. package/dist/chunk-cgfdkzhb.js +12 -0
  179. package/dist/chunk-ckh4r5er.js +257 -0
  180. package/dist/chunk-cmgjnvn9.js +89 -0
  181. package/dist/chunk-cpjgvay8.js +687 -0
  182. package/dist/chunk-crfryjx9.js +276 -0
  183. package/dist/chunk-ctw5jwcd.js +213 -0
  184. package/dist/chunk-cvy3vntc.js +65 -0
  185. package/dist/chunk-cwbzz504.js +94 -0
  186. package/dist/chunk-cy2hswr1.js +15 -0
  187. package/dist/chunk-cyejkay3.js +222 -0
  188. package/dist/chunk-d18z9pna.js +106 -0
  189. package/dist/chunk-d5cq0n0v.js +162 -0
  190. package/dist/chunk-db45aryp.js +50 -0
  191. package/dist/chunk-de8nqh0z.js +790 -0
  192. package/dist/chunk-dfw6h350.js +2336 -0
  193. package/dist/chunk-dgqrcy74.js +48 -0
  194. package/dist/chunk-dn75ptgd.js +184 -0
  195. package/dist/chunk-dnh7jtpb.js +37 -0
  196. package/dist/chunk-dpshyv9m.js +90 -0
  197. package/dist/chunk-dt8cdvnm.js +642 -0
  198. package/dist/chunk-dtxby6fr.js +306 -0
  199. package/dist/chunk-dv1wfr85.js +6373 -0
  200. package/dist/chunk-dw363edx.js +1154 -0
  201. package/dist/chunk-dwrdacck.js +62 -0
  202. package/dist/chunk-dxnnv5e3.js +276 -0
  203. package/dist/chunk-e3g8q4cn.js +1646 -0
  204. package/dist/chunk-e3m9k9s2.js +542 -0
  205. package/dist/chunk-e4q49asn.js +155 -0
  206. package/dist/chunk-e5pntxye.js +37 -0
  207. package/dist/chunk-e7393td6.js +42 -0
  208. package/dist/chunk-ead42yrh.js +87 -0
  209. package/dist/chunk-eb90vwvr.js +152 -0
  210. package/dist/chunk-ecvwk9hg.js +250 -0
  211. package/dist/chunk-edjd6aay.js +173 -0
  212. package/dist/chunk-eg0h8mtm.js +130 -0
  213. package/dist/chunk-ehtwnxpg.js +1591 -0
  214. package/dist/chunk-ek686gx1.js +94 -0
  215. package/dist/chunk-eqp1rfft.js +17 -0
  216. package/dist/chunk-evhwt0ar.js +1015 -0
  217. package/dist/chunk-ewadzrm8.js +103 -0
  218. package/dist/chunk-ewsgsw9h.js +172291 -0
  219. package/dist/chunk-f0pa0r7e.js +3198 -0
  220. package/dist/chunk-f2mhrmww.js +62 -0
  221. package/dist/chunk-f39zxvwn.js +401 -0
  222. package/dist/chunk-f46z54tq.js +374 -0
  223. package/dist/chunk-f5ma3nh5.js +3436 -0
  224. package/dist/chunk-f60q23az.js +3038 -0
  225. package/dist/chunk-f6v2nz57.js +107 -0
  226. package/dist/chunk-f6yjan38.js +38 -0
  227. package/dist/chunk-fbv4apne.js +51 -0
  228. package/dist/chunk-fem4s778.js +70 -0
  229. package/dist/chunk-fezm1kn8.js +376 -0
  230. package/dist/chunk-fm1n3ysp.js +6108 -0
  231. package/dist/chunk-frg83bfw.js +225 -0
  232. package/dist/chunk-fscm8db0.js +692 -0
  233. package/dist/chunk-fyc5fepv.js +10 -0
  234. package/dist/chunk-g0j0t6qk.js +26 -0
  235. package/dist/chunk-g0nc1ftf.js +849 -0
  236. package/dist/chunk-g338npwr.js +1061 -0
  237. package/dist/chunk-g3t0act8.js +8 -0
  238. package/dist/chunk-g75w4hw3.js +26 -0
  239. package/dist/chunk-g8vp82en.js +1866 -0
  240. package/dist/chunk-gax0fcbx.js +182 -0
  241. package/dist/chunk-gsz4dh3y.js +606 -0
  242. package/dist/chunk-gtfffm7h.js +440 -0
  243. package/dist/chunk-gver9zb9.js +420 -0
  244. package/dist/chunk-gyj242zr.js +20 -0
  245. package/dist/chunk-h0qngp9w.js +157 -0
  246. package/dist/chunk-h14kemnk.js +123 -0
  247. package/dist/chunk-h8wj1a74.js +8960 -0
  248. package/dist/chunk-h9mcb2eg.js +87 -0
  249. package/dist/chunk-h9nh2980.js +91 -0
  250. package/dist/chunk-hakdhagh.js +16606 -0
  251. package/dist/chunk-hbc6ymdv.js +55 -0
  252. package/dist/chunk-hh7cmy4k.js +20 -0
  253. package/dist/chunk-hjhc4cpt.js +69 -0
  254. package/dist/chunk-hjwez8qc.js +5018 -0
  255. package/dist/chunk-hk9xz7gk.js +118 -0
  256. package/dist/chunk-hqmz36b3.js +552 -0
  257. package/dist/chunk-hrzerbfw.js +1299 -0
  258. package/dist/chunk-hs8ph4p8.js +8 -0
  259. package/dist/chunk-ht1xwrnd.js +716 -0
  260. package/dist/chunk-hvmfg2dc.js +338 -0
  261. package/dist/chunk-hx2tr4ep.js +7189 -0
  262. package/dist/chunk-hzhe8ygc.js +547 -0
  263. package/dist/chunk-j2k4p94p.js +55 -0
  264. package/dist/chunk-j3a4p81y.js +184 -0
  265. package/dist/chunk-j49g6g3s.js +57 -0
  266. package/dist/chunk-j5d5hp9h.js +71 -0
  267. package/dist/chunk-j64ga6ta.js +8035 -0
  268. package/dist/chunk-j7tyxan1.js +116 -0
  269. package/dist/chunk-j8v4774z.js +424 -0
  270. package/dist/chunk-jafes477.js +29 -0
  271. package/dist/chunk-jd32zbps.js +15 -0
  272. package/dist/chunk-jdgeec04.js +4249 -0
  273. package/dist/chunk-jftd4jq5.js +4521 -0
  274. package/dist/chunk-jkxqhv6y.js +812 -0
  275. package/dist/chunk-jmfr6h0n.js +120 -0
  276. package/dist/chunk-jn4aabmx.js +40 -0
  277. package/dist/chunk-jnhkref0.js +30 -0
  278. package/dist/chunk-jsbpm1gz.js +27 -0
  279. package/dist/chunk-jtcyjc3k.js +5802 -0
  280. package/dist/chunk-jx817w05.js +11 -0
  281. package/dist/chunk-jzmz18nn.js +65 -0
  282. package/dist/chunk-k0p9w03v.js +4957 -0
  283. package/dist/chunk-k3dcdnck.js +89 -0
  284. package/dist/chunk-k3wadzcd.js +88 -0
  285. package/dist/chunk-kaeshsk1.js +713 -0
  286. package/dist/chunk-kbkey9ed.js +522 -0
  287. package/dist/chunk-kcwfhqbb.js +196 -0
  288. package/dist/chunk-key6jr7p.js +224 -0
  289. package/dist/chunk-knay8cy9.js +173 -0
  290. package/dist/chunk-kr3rg2y1.js +95 -0
  291. package/dist/chunk-kwekc97v.js +18 -0
  292. package/dist/chunk-m06q12hg.js +61 -0
  293. package/dist/chunk-m2mcpbhk.js +43 -0
  294. package/dist/chunk-m8v220gz.js +71 -0
  295. package/dist/chunk-mgpqy78h.js +208 -0
  296. package/dist/chunk-mkejwh4t.js +16 -0
  297. package/dist/chunk-mptyw5n1.js +107 -0
  298. package/dist/chunk-mqajm0dp.js +66 -0
  299. package/dist/chunk-mrksbgxj.js +490 -0
  300. package/dist/chunk-msjfc5ba.js +246 -0
  301. package/dist/chunk-mt25echc.js +6157 -0
  302. package/dist/chunk-mt3jfnr8.js +277 -0
  303. package/dist/chunk-mtn242d4.js +9300 -0
  304. package/dist/chunk-mzfkvave.js +169 -0
  305. package/dist/chunk-n0qaeaa5.js +256 -0
  306. package/dist/chunk-n1erf6kh.js +22820 -0
  307. package/dist/chunk-n2avk1r2.js +61 -0
  308. package/dist/chunk-n6atnpcq.js +765 -0
  309. package/dist/chunk-n7ttdtk0.js +641 -0
  310. package/dist/chunk-ncnfzby5.js +822 -0
  311. package/dist/chunk-ncnr1jtf.js +2058 -0
  312. package/dist/chunk-nerv0jvx.js +74 -0
  313. package/dist/chunk-ngd2abep.js +90 -0
  314. package/dist/chunk-nka1g8f4.js +773 -0
  315. package/dist/chunk-nnaxkc2z.js +128 -0
  316. package/dist/chunk-npyrtj8j.js +691 -0
  317. package/dist/chunk-nq0fxyxh.js +752 -0
  318. package/dist/chunk-nrmffak7.js +114 -0
  319. package/dist/chunk-nsz546wq.js +1170 -0
  320. package/dist/chunk-nt837qt9.js +21 -0
  321. package/dist/chunk-nv64x1z5.js +86 -0
  322. package/dist/chunk-nxsh6de2.js +1711 -0
  323. package/dist/chunk-nz4getcr.js +40 -0
  324. package/dist/chunk-p1f607pa.js +83 -0
  325. package/dist/chunk-p2816w9z.js +1486 -0
  326. package/dist/chunk-p2d5nh3g.js +342 -0
  327. package/dist/chunk-p4r5y02t.js +90 -0
  328. package/dist/chunk-p7g7pf3f.js +336 -0
  329. package/dist/chunk-pb4ad8r2.js +110 -0
  330. package/dist/chunk-pbrhz0zr.js +716 -0
  331. package/dist/chunk-ps49ymvj.js +43 -0
  332. package/dist/chunk-pwnt3veb.js +103 -0
  333. package/dist/chunk-pwwa7s62.js +11 -0
  334. package/dist/chunk-px3w0kde.js +299 -0
  335. package/dist/chunk-pzn777jb.js +756 -0
  336. package/dist/chunk-q25bjaev.js +15 -0
  337. package/dist/chunk-q5by3da6.js +8 -0
  338. package/dist/chunk-q6av622g.js +38 -0
  339. package/dist/chunk-q6xkvtf2.js +1318 -0
  340. package/dist/chunk-q81jx1tq.js +476 -0
  341. package/dist/chunk-qehb6fk5.js +339 -0
  342. package/dist/chunk-qj1avx1q.js +87 -0
  343. package/dist/chunk-qn2dxr66.js +105 -0
  344. package/dist/chunk-qnfx3qtx.js +617 -0
  345. package/dist/chunk-qp18kd4h.js +48 -0
  346. package/dist/chunk-qp2qdcda.js +100 -0
  347. package/dist/chunk-qpjy9tcf.js +133 -0
  348. package/dist/chunk-qqfa0dqg.js +2343 -0
  349. package/dist/chunk-qwh3htcz.js +202 -0
  350. package/dist/chunk-qz2x630m.js +49145 -0
  351. package/dist/chunk-r3vakcs1.js +496 -0
  352. package/dist/chunk-r66hz8j6.js +34 -0
  353. package/dist/chunk-r6b58y3x.js +17 -0
  354. package/dist/chunk-rekp48rk.js +62 -0
  355. package/dist/chunk-rn0v1hk8.js +34 -0
  356. package/dist/chunk-rs1xrs6m.js +534 -0
  357. package/dist/chunk-rs45skes.js +123 -0
  358. package/dist/chunk-rzszqp82.js +524 -0
  359. package/dist/chunk-s274nv8k.js +8 -0
  360. package/dist/chunk-s3pzvdss.js +50 -0
  361. package/dist/chunk-s9mesaw0.js +26840 -0
  362. package/dist/chunk-sd36yzx8.js +954 -0
  363. package/dist/chunk-sdj9b9wh.js +782 -0
  364. package/dist/chunk-sdw2q69p.js +227 -0
  365. package/dist/chunk-sfgp9cc0.js +130 -0
  366. package/dist/chunk-spqaamnc.js +63 -0
  367. package/dist/chunk-spzrs4df.js +73 -0
  368. package/dist/chunk-sxkr7k43.js +55 -0
  369. package/dist/chunk-szj5wvdy.js +28 -0
  370. package/dist/chunk-t0rgmccj.js +39 -0
  371. package/dist/chunk-t1nnzjgg.js +17 -0
  372. package/dist/chunk-t94fcnt8.js +566 -0
  373. package/dist/chunk-tjaqa99q.js +125 -0
  374. package/dist/chunk-tjq2evtw.js +328 -0
  375. package/dist/chunk-ts2p6bv1.js +224 -0
  376. package/dist/chunk-ttk5dzz8.js +25 -0
  377. package/dist/chunk-tw0q7ynt.js +59 -0
  378. package/dist/chunk-v02jkvgy.js +131 -0
  379. package/dist/chunk-v084bqt3.js +1529 -0
  380. package/dist/chunk-v0amythm.js +164 -0
  381. package/dist/chunk-v1kzp02e.js +785 -0
  382. package/dist/chunk-v1mgv1et.js +15 -0
  383. package/dist/chunk-v399mzxk.js +58 -0
  384. package/dist/chunk-v3gm2day.js +8 -0
  385. package/dist/chunk-v43hrrxp.js +71 -0
  386. package/dist/chunk-v6aqb2aj.js +102 -0
  387. package/dist/chunk-v78fj8by.js +145 -0
  388. package/dist/chunk-v7qmhjdn.js +1921 -0
  389. package/dist/chunk-v9smspw2.js +4301 -0
  390. package/dist/chunk-vdw93s4h.js +2431 -0
  391. package/dist/chunk-vest0y6x.js +3830 -0
  392. package/dist/chunk-vf5sd1nq.js +12 -0
  393. package/dist/chunk-vratq94g.js +349 -0
  394. package/dist/chunk-vrz7t3m3.js +20 -0
  395. package/dist/chunk-vtb185z9.js +70 -0
  396. package/dist/chunk-vx01rvg8.js +654 -0
  397. package/dist/chunk-vyc0rjyx.js +31 -0
  398. package/dist/chunk-vyjeh50y.js +2149 -0
  399. package/dist/chunk-vzpffsza.js +269 -0
  400. package/dist/chunk-w2ef3kxk.js +3353 -0
  401. package/dist/chunk-w2z5pqd3.js +336 -0
  402. package/dist/chunk-w3whm4mn.js +432 -0
  403. package/dist/chunk-w7wgpqcp.js +157 -0
  404. package/dist/chunk-waa00cvb.js +301 -0
  405. package/dist/chunk-wb0qm4es.js +155 -0
  406. package/dist/chunk-wbkahkdc.js +27 -0
  407. package/dist/chunk-wfz0qffj.js +3939 -0
  408. package/dist/chunk-wn0cx0pt.js +283 -0
  409. package/dist/chunk-wv6gzt9c.js +726 -0
  410. package/dist/chunk-wx42ycm4.js +998 -0
  411. package/dist/chunk-wxkpgy05.js +268 -0
  412. package/dist/chunk-wzpdet3m.js +843 -0
  413. package/dist/chunk-x0mwzt38.js +714 -0
  414. package/dist/chunk-x592wbfh.js +244 -0
  415. package/dist/chunk-x5pqsp9r.js +100 -0
  416. package/dist/chunk-x679thag.js +825 -0
  417. package/dist/chunk-x8b7vft8.js +132 -0
  418. package/dist/chunk-x8cftch7.js +119 -0
  419. package/dist/chunk-x9q7r885.js +348 -0
  420. package/dist/chunk-xawkt0vb.js +1585 -0
  421. package/dist/chunk-xdw5dv00.js +8 -0
  422. package/dist/chunk-xe9cc860.js +287 -0
  423. package/dist/chunk-xjr9c3vt.js +101 -0
  424. package/dist/chunk-xk7zaqta.js +21933 -0
  425. package/dist/chunk-xktbmawc.js +678 -0
  426. package/dist/chunk-xn6yw46v.js +140 -0
  427. package/dist/chunk-xsq9ae7x.js +90 -0
  428. package/dist/chunk-xszk7n10.js +14358 -0
  429. package/dist/chunk-xt8a5r1t.js +84 -0
  430. package/dist/chunk-xydyndkv.js +195 -0
  431. package/dist/chunk-xzt10yc5.js +60 -0
  432. package/dist/chunk-y04y95dr.js +91 -0
  433. package/dist/chunk-y1784krc.js +19 -0
  434. package/dist/chunk-y1x32h3x.js +128 -0
  435. package/dist/chunk-y3s7aww5.js +99 -0
  436. package/dist/chunk-y47cg3kz.js +42 -0
  437. package/dist/chunk-y7kzvepn.js +469 -0
  438. package/dist/chunk-y89kbsyc.js +287 -0
  439. package/dist/chunk-yd87p1c3.js +159 -0
  440. package/dist/chunk-yf3yw8fw.js +105 -0
  441. package/dist/chunk-ygbf0ezx.js +1391 -0
  442. package/dist/chunk-yjbxnshv.js +208 -0
  443. package/dist/chunk-ynednmqd.js +192 -0
  444. package/dist/chunk-yvhez44y.js +259 -0
  445. package/dist/chunk-ywxd4qw4.js +22 -0
  446. package/dist/chunk-yzrmgpy4.js +117 -0
  447. package/dist/chunk-z0b2vb24.js +862 -0
  448. package/dist/chunk-z1zj044v.js +655 -0
  449. package/dist/chunk-z2dp53wn.js +17 -0
  450. package/dist/chunk-z3w0xasa.js +165 -0
  451. package/dist/chunk-z7ycmrb3.js +644 -0
  452. package/dist/chunk-zh11tdkb.js +347 -0
  453. package/dist/chunk-zk2wsm7d.js +15 -0
  454. package/dist/chunk-zqfqcf22.js +229 -0
  455. package/dist/chunk-zqk2j8px.js +699 -0
  456. package/dist/chunk-zqvsc10j.js +2833 -0
  457. package/dist/chunk-zsfxha74.js +17655 -0
  458. package/dist/chunk-zvc4snyb.js +117 -0
  459. package/dist/cli.js +194 -0
  460. package/package.json +173 -0
@@ -0,0 +1,3198 @@
1
+ // @bun
2
+ import {
3
+ normalizeControlMessageKeys
4
+ } from "./chunk-nt837qt9.js";
5
+ import {
6
+ notifySessionStateChanged
7
+ } from "./chunk-n2avk1r2.js";
8
+ import {
9
+ init_slashCommandParsing,
10
+ parseSlashCommand
11
+ } from "./chunk-rn0v1hk8.js";
12
+ import {
13
+ AccountInfoSchema,
14
+ AgentDefinitionSchema,
15
+ AgentInfoSchema,
16
+ DEFAULT_CRON_JITTER_CONFIG,
17
+ DEFAULT_OUTPUT_STYLE_NAME,
18
+ FastModeStateSchema,
19
+ HookEventSchema,
20
+ HookInputSchema,
21
+ McpServerConfigForProcessTransportSchema,
22
+ McpServerStatusSchema,
23
+ ModelInfoSchema,
24
+ PermissionModeSchema,
25
+ PermissionUpdateSchema,
26
+ SDKMessageSchema,
27
+ SDKPostTurnSummaryMessageSchema,
28
+ SDKStreamlinedTextMessageSchema,
29
+ SDKStreamlinedToolUseSummaryMessageSchema,
30
+ SDKUserMessageSchema,
31
+ Select,
32
+ SlashCommandSchema,
33
+ Spinner,
34
+ Stream,
35
+ addMarketplaceSource,
36
+ applyPermissionUpdates,
37
+ createAttachmentMessage,
38
+ createCommandInputMessage,
39
+ createImageMetadataText,
40
+ createSystemMessage,
41
+ createUserMessage,
42
+ cronToHuman,
43
+ detectImageFormatFromBase64,
44
+ executePermissionRequestHooks,
45
+ executeUserPromptSubmitHooks,
46
+ extractTag,
47
+ fileHistoryCanRestore,
48
+ fileHistoryEnabled,
49
+ fileHistoryGetDiffStats,
50
+ findCommand,
51
+ findMissedTasks,
52
+ getAttachmentMessages,
53
+ getCommandName,
54
+ getContentText,
55
+ getCronFilePath,
56
+ getDeclaredMarketplaces,
57
+ getUserPromptSubmitHookBlockingMessage,
58
+ hasCronTasksSync,
59
+ hasPermissionsToUseTool,
60
+ hookJSONOutputSchema,
61
+ init_AppState,
62
+ init_PermissionUpdate,
63
+ init_PermissionUpdateSchema,
64
+ init_Spinner,
65
+ init_attachments,
66
+ init_commandLifecycle,
67
+ init_commands1 as init_commands,
68
+ init_coreSchemas,
69
+ init_cron,
70
+ init_cronTasks,
71
+ init_fileHistory,
72
+ init_generators,
73
+ init_hooks,
74
+ init_hooks1 as init_hooks2,
75
+ init_imageResizer,
76
+ init_imageStore,
77
+ init_marketplaceManager,
78
+ init_messages1 as init_messages,
79
+ init_outputStyles,
80
+ init_permissions,
81
+ init_queryProfiler,
82
+ init_select,
83
+ init_stream,
84
+ init_textInputTypes,
85
+ isBridgeSafeCommand,
86
+ isEmptyMessageText,
87
+ isSyntheticMessage,
88
+ isToolUseResultMessage,
89
+ isValidImagePaste,
90
+ jitteredNextCronRunMs,
91
+ loadKnownMarketplacesConfig,
92
+ markCronTasksFired,
93
+ maybeResizeAndDownsampleImageBlock,
94
+ notifyCommandLifecycle,
95
+ oneShotJitteredNextCronRunMs,
96
+ permissionUpdateSchema,
97
+ persistPermissionUpdates,
98
+ queryCheckpoint,
99
+ readCronTasks,
100
+ removeCronTasks,
101
+ storeImages,
102
+ toArray,
103
+ useAppState
104
+ } from "./chunk-ewsgsw9h.js";
105
+ import {
106
+ init_useExitOnCtrlCDWithKeybindings,
107
+ useExitOnCtrlCDWithKeybindings
108
+ } from "./chunk-0rg6yrhy.js";
109
+ import {
110
+ Divider,
111
+ init_Divider,
112
+ init_useKeybinding,
113
+ init_useTerminalSize,
114
+ useKeybinding,
115
+ useKeybindings,
116
+ useTerminalSize
117
+ } from "./chunk-1qakq4sn.js";
118
+ import {
119
+ ThemedBox_default,
120
+ ThemedText,
121
+ init_ink,
122
+ require_compiler_runtime
123
+ } from "./chunk-s9mesaw0.js";
124
+ import {
125
+ require_jsx_dev_runtime,
126
+ require_react
127
+ } from "./chunk-g338npwr.js";
128
+ import {
129
+ init_events,
130
+ init_sessionTracing,
131
+ logOTelEvent,
132
+ redactIfDisabled,
133
+ startInteractionSpan
134
+ } from "./chunk-ygbf0ezx.js";
135
+ import {
136
+ AGENT_TOOL_NAME,
137
+ LEGACY_AGENT_TOOL_NAME,
138
+ getAnthropicApiKeyWithSource,
139
+ getFastModeState,
140
+ getFeatureValue_CACHED_WITH_REFRESH,
141
+ getSettings_DEPRECATED,
142
+ init_auth,
143
+ init_constants1 as init_constants,
144
+ init_fastMode,
145
+ init_file,
146
+ init_genericProcessUtils,
147
+ init_growthbook,
148
+ init_isEqual,
149
+ init_schemas,
150
+ init_settings1 as init_settings,
151
+ isEqual_default,
152
+ isLocalMarketplaceSource,
153
+ isProcessRunning,
154
+ pathExists
155
+ } from "./chunk-3f7rypmf.js";
156
+ import {
157
+ init_json,
158
+ safeParseJSON
159
+ } from "./chunk-e3g8q4cn.js";
160
+ import {
161
+ count,
162
+ init_array
163
+ } from "./chunk-0e1xsncc.js";
164
+ import {
165
+ init_v4,
166
+ v4_default
167
+ } from "./chunk-g0j0t6qk.js";
168
+ import {
169
+ exports_external,
170
+ init_lazySchema,
171
+ lazySchema
172
+ } from "./chunk-55wgxwa9.js";
173
+ import {
174
+ formatRelativeTimeAgo,
175
+ init_format,
176
+ truncate
177
+ } from "./chunk-1rvz0433.js";
178
+ import {
179
+ init_analytics,
180
+ logEvent
181
+ } from "./chunk-f2mhrmww.js";
182
+ import {
183
+ findCanonicalGitRoot,
184
+ init_diagLogs,
185
+ init_git,
186
+ logForDiagnosticsNoPII
187
+ } from "./chunk-hrzerbfw.js";
188
+ import {
189
+ figures_default,
190
+ init_figures
191
+ } from "./chunk-hx2tr4ep.js";
192
+ import {
193
+ BASH_STDERR_TAG,
194
+ BASH_STDOUT_TAG,
195
+ COMMAND_MESSAGE_TAG,
196
+ LOCAL_COMMAND_STDERR_TAG,
197
+ LOCAL_COMMAND_STDOUT_TAG,
198
+ TASK_NOTIFICATION_TAG,
199
+ TEAMMATE_MESSAGE_TAG,
200
+ TICK_TAG,
201
+ init_displayTags,
202
+ init_log,
203
+ init_xml,
204
+ logError,
205
+ stripDisplayTags
206
+ } from "./chunk-p7g7pf3f.js";
207
+ import {
208
+ getCwd,
209
+ init_cwd
210
+ } from "./chunk-8bedvdm1.js";
211
+ import {
212
+ AbortError,
213
+ errorMessage,
214
+ getErrnoCode,
215
+ init_cleanupRegistry,
216
+ init_debug,
217
+ init_errors,
218
+ init_slowOperations,
219
+ jsonParse,
220
+ jsonStringify,
221
+ logForDebugging,
222
+ registerCleanup
223
+ } from "./chunk-nxsh6de2.js";
224
+ import {
225
+ init_process,
226
+ writeToStdout
227
+ } from "./chunk-fbv4apne.js";
228
+ import {
229
+ getOriginalCwd,
230
+ getProjectRoot,
231
+ getScheduledTasksEnabled,
232
+ getSdkBetas,
233
+ getSessionCronTasks,
234
+ getSessionId,
235
+ init_state,
236
+ removeSessionCronTasks,
237
+ setPromptId,
238
+ setScheduledTasksEnabled
239
+ } from "./chunk-qqfa0dqg.js";
240
+ import {
241
+ __esm,
242
+ __export,
243
+ __require,
244
+ __toESM
245
+ } from "./chunk-qp2qdcda.js";
246
+
247
+ // src/components/MessageSelector.tsx
248
+ var exports_MessageSelector = {};
249
+ __export(exports_MessageSelector, {
250
+ selectableUserMessagesFilter: () => selectableUserMessagesFilter,
251
+ messagesAfterAreOnlySynthetic: () => messagesAfterAreOnlySynthetic,
252
+ MessageSelector: () => MessageSelector
253
+ });
254
+ import { randomUUID } from "crypto";
255
+ import * as path from "path";
256
+ function isTextBlock(block) {
257
+ return block.type === "text";
258
+ }
259
+ function isSummarizeOption(option) {
260
+ return option === "summarize" || option === "summarize_up_to";
261
+ }
262
+ function MessageSelector({
263
+ messages,
264
+ onPreRestore,
265
+ onRestoreMessage,
266
+ onRestoreCode,
267
+ onSummarize,
268
+ onClose,
269
+ preselectedMessage
270
+ }) {
271
+ const fileHistory = useAppState((s) => s.fileHistory);
272
+ const [error, setError] = import_react.useState(undefined);
273
+ const isFileHistoryEnabled = fileHistoryEnabled();
274
+ const currentUUID = import_react.useMemo(randomUUID, []);
275
+ const messageOptions = import_react.useMemo(() => [...messages.filter(selectableUserMessagesFilter), {
276
+ ...createUserMessage({
277
+ content: ""
278
+ }),
279
+ uuid: currentUUID
280
+ }], [messages, currentUUID]);
281
+ const [selectedIndex, setSelectedIndex] = import_react.useState(messageOptions.length - 1);
282
+ const firstVisibleIndex = Math.max(0, Math.min(selectedIndex - Math.floor(MAX_VISIBLE_MESSAGES / 2), messageOptions.length - MAX_VISIBLE_MESSAGES));
283
+ const hasMessagesToSelect = messageOptions.length > 1;
284
+ const [messageToRestore, setMessageToRestore] = import_react.useState(preselectedMessage);
285
+ const [diffStatsForRestore, setDiffStatsForRestore] = import_react.useState(undefined);
286
+ import_react.useEffect(() => {
287
+ if (!preselectedMessage || !isFileHistoryEnabled)
288
+ return;
289
+ let cancelled = false;
290
+ fileHistoryGetDiffStats(fileHistory, preselectedMessage.uuid).then((stats) => {
291
+ if (!cancelled)
292
+ setDiffStatsForRestore(stats);
293
+ });
294
+ return () => {
295
+ cancelled = true;
296
+ };
297
+ }, [preselectedMessage, isFileHistoryEnabled, fileHistory]);
298
+ const [isRestoring, setIsRestoring] = import_react.useState(false);
299
+ const [restoringOption, setRestoringOption] = import_react.useState(null);
300
+ const [selectedRestoreOption, setSelectedRestoreOption] = import_react.useState("both");
301
+ const [summarizeFromFeedback, setSummarizeFromFeedback] = import_react.useState("");
302
+ const [summarizeUpToFeedback, setSummarizeUpToFeedback] = import_react.useState("");
303
+ function getRestoreOptions(canRestoreCode) {
304
+ const baseOptions = canRestoreCode ? [{
305
+ value: "both",
306
+ label: "Restore code and conversation"
307
+ }, {
308
+ value: "conversation",
309
+ label: "Restore conversation"
310
+ }, {
311
+ value: "code",
312
+ label: "Restore code"
313
+ }] : [{
314
+ value: "conversation",
315
+ label: "Restore conversation"
316
+ }];
317
+ const summarizeInputProps = {
318
+ type: "input",
319
+ placeholder: "add context (optional)",
320
+ initialValue: "",
321
+ allowEmptySubmitToCancel: true,
322
+ showLabelWithValue: true,
323
+ labelValueSeparator: ": "
324
+ };
325
+ baseOptions.push({
326
+ value: "summarize",
327
+ label: "Summarize from here",
328
+ ...summarizeInputProps,
329
+ onChange: setSummarizeFromFeedback
330
+ });
331
+ if (false) {}
332
+ baseOptions.push({
333
+ value: "nevermind",
334
+ label: "Never mind"
335
+ });
336
+ return baseOptions;
337
+ }
338
+ import_react.useEffect(() => {
339
+ logEvent("tengu_message_selector_opened", {});
340
+ }, []);
341
+ async function restoreConversationDirectly(message) {
342
+ onPreRestore();
343
+ setIsRestoring(true);
344
+ try {
345
+ await onRestoreMessage(message);
346
+ setIsRestoring(false);
347
+ onClose();
348
+ } catch (error_0) {
349
+ logError(error_0);
350
+ setIsRestoring(false);
351
+ setError(`Failed to restore the conversation:
352
+ ${error_0}`);
353
+ }
354
+ }
355
+ async function handleSelect(message_0) {
356
+ const index = messages.indexOf(message_0);
357
+ const indexFromEnd = messages.length - 1 - index;
358
+ logEvent("tengu_message_selector_selected", {
359
+ index_from_end: indexFromEnd,
360
+ message_type: message_0.type,
361
+ is_current_prompt: false
362
+ });
363
+ if (!messages.includes(message_0)) {
364
+ onClose();
365
+ return;
366
+ }
367
+ if (!isFileHistoryEnabled) {
368
+ await restoreConversationDirectly(message_0);
369
+ return;
370
+ }
371
+ const diffStats = await fileHistoryGetDiffStats(fileHistory, message_0.uuid);
372
+ setMessageToRestore(message_0);
373
+ setDiffStatsForRestore(diffStats);
374
+ }
375
+ async function onSelectRestoreOption(option) {
376
+ logEvent("tengu_message_selector_restore_option_selected", {
377
+ option
378
+ });
379
+ if (!messageToRestore) {
380
+ setError("Message not found.");
381
+ return;
382
+ }
383
+ if (option === "nevermind") {
384
+ if (preselectedMessage)
385
+ onClose();
386
+ else
387
+ setMessageToRestore(undefined);
388
+ return;
389
+ }
390
+ if (isSummarizeOption(option)) {
391
+ onPreRestore();
392
+ setIsRestoring(true);
393
+ setRestoringOption(option);
394
+ setError(undefined);
395
+ try {
396
+ const direction = option === "summarize_up_to" ? "up_to" : "from";
397
+ const feedback = (direction === "up_to" ? summarizeUpToFeedback : summarizeFromFeedback).trim() || undefined;
398
+ await onSummarize(messageToRestore, feedback, direction);
399
+ setIsRestoring(false);
400
+ setRestoringOption(null);
401
+ setMessageToRestore(undefined);
402
+ onClose();
403
+ } catch (error_1) {
404
+ logError(error_1);
405
+ setIsRestoring(false);
406
+ setRestoringOption(null);
407
+ setMessageToRestore(undefined);
408
+ setError(`Failed to summarize:
409
+ ${error_1}`);
410
+ }
411
+ return;
412
+ }
413
+ onPreRestore();
414
+ setIsRestoring(true);
415
+ setError(undefined);
416
+ let codeError = null;
417
+ let conversationError = null;
418
+ if (option === "code" || option === "both") {
419
+ try {
420
+ await onRestoreCode(messageToRestore);
421
+ } catch (error_2) {
422
+ codeError = error_2;
423
+ logError(codeError);
424
+ }
425
+ }
426
+ if (option === "conversation" || option === "both") {
427
+ try {
428
+ await onRestoreMessage(messageToRestore);
429
+ } catch (error_3) {
430
+ conversationError = error_3;
431
+ logError(conversationError);
432
+ }
433
+ }
434
+ setIsRestoring(false);
435
+ setMessageToRestore(undefined);
436
+ if (conversationError && codeError) {
437
+ setError(`Failed to restore the conversation and code:
438
+ ${conversationError}
439
+ ${codeError}`);
440
+ } else if (conversationError) {
441
+ setError(`Failed to restore the conversation:
442
+ ${conversationError}`);
443
+ } else if (codeError) {
444
+ setError(`Failed to restore the code:
445
+ ${codeError}`);
446
+ } else {
447
+ onClose();
448
+ }
449
+ }
450
+ const exitState = useExitOnCtrlCDWithKeybindings();
451
+ const handleEscape = import_react.useCallback(() => {
452
+ if (messageToRestore && !preselectedMessage) {
453
+ setMessageToRestore(undefined);
454
+ return;
455
+ }
456
+ logEvent("tengu_message_selector_cancelled", {});
457
+ onClose();
458
+ }, [onClose, messageToRestore, preselectedMessage]);
459
+ const moveUp = import_react.useCallback(() => setSelectedIndex((prev) => Math.max(0, prev - 1)), []);
460
+ const moveDown = import_react.useCallback(() => setSelectedIndex((prev_0) => Math.min(messageOptions.length - 1, prev_0 + 1)), [messageOptions.length]);
461
+ const jumpToTop = import_react.useCallback(() => setSelectedIndex(0), []);
462
+ const jumpToBottom = import_react.useCallback(() => setSelectedIndex(messageOptions.length - 1), [messageOptions.length]);
463
+ const handleSelectCurrent = import_react.useCallback(() => {
464
+ const selected = messageOptions[selectedIndex];
465
+ if (selected) {
466
+ handleSelect(selected);
467
+ }
468
+ }, [messageOptions, selectedIndex, handleSelect]);
469
+ useKeybinding("confirm:no", handleEscape, {
470
+ context: "Confirmation",
471
+ isActive: !messageToRestore
472
+ });
473
+ useKeybindings({
474
+ "messageSelector:up": moveUp,
475
+ "messageSelector:down": moveDown,
476
+ "messageSelector:top": jumpToTop,
477
+ "messageSelector:bottom": jumpToBottom,
478
+ "messageSelector:select": handleSelectCurrent
479
+ }, {
480
+ context: "MessageSelector",
481
+ isActive: !isRestoring && !error && !messageToRestore && hasMessagesToSelect
482
+ });
483
+ const [fileHistoryMetadata, setFileHistoryMetadata] = import_react.useState({});
484
+ import_react.useEffect(() => {
485
+ async function loadFileHistoryMetadata() {
486
+ if (!isFileHistoryEnabled) {
487
+ return;
488
+ }
489
+ Promise.all(messageOptions.map(async (userMessage, itemIndex) => {
490
+ if (userMessage.uuid !== currentUUID) {
491
+ const canRestore = fileHistoryCanRestore(fileHistory, userMessage.uuid);
492
+ const nextUserMessage = messageOptions.at(itemIndex + 1);
493
+ const diffStats_0 = canRestore ? computeDiffStatsBetweenMessages(messages, userMessage.uuid, nextUserMessage?.uuid !== currentUUID ? nextUserMessage?.uuid : undefined) : undefined;
494
+ if (diffStats_0 !== undefined) {
495
+ setFileHistoryMetadata((prev_1) => ({
496
+ ...prev_1,
497
+ [itemIndex]: diffStats_0
498
+ }));
499
+ } else {
500
+ setFileHistoryMetadata((prev_2) => ({
501
+ ...prev_2,
502
+ [itemIndex]: undefined
503
+ }));
504
+ }
505
+ }
506
+ }));
507
+ }
508
+ loadFileHistoryMetadata();
509
+ }, [messageOptions, messages, currentUUID, fileHistory, isFileHistoryEnabled]);
510
+ const canRestoreCode_0 = isFileHistoryEnabled && diffStatsForRestore?.filesChanged && diffStatsForRestore.filesChanged.length > 0;
511
+ const showPickList = !error && !messageToRestore && !preselectedMessage && hasMessagesToSelect;
512
+ return /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
513
+ flexDirection: "column",
514
+ width: "100%",
515
+ children: [
516
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Divider, {
517
+ color: "suggestion"
518
+ }, undefined, false, undefined, this),
519
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
520
+ flexDirection: "column",
521
+ marginX: 1,
522
+ gap: 1,
523
+ children: [
524
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
525
+ bold: true,
526
+ color: "suggestion",
527
+ children: "Rewind"
528
+ }, undefined, false, undefined, this),
529
+ error && /* @__PURE__ */ jsx_dev_runtime.jsxDEV(jsx_dev_runtime.Fragment, {
530
+ children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
531
+ color: "error",
532
+ children: [
533
+ "Error: ",
534
+ error
535
+ ]
536
+ }, undefined, true, undefined, this)
537
+ }, undefined, false, undefined, this),
538
+ !hasMessagesToSelect && /* @__PURE__ */ jsx_dev_runtime.jsxDEV(jsx_dev_runtime.Fragment, {
539
+ children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
540
+ children: "Nothing to rewind to yet."
541
+ }, undefined, false, undefined, this)
542
+ }, undefined, false, undefined, this),
543
+ !error && messageToRestore && hasMessagesToSelect && /* @__PURE__ */ jsx_dev_runtime.jsxDEV(jsx_dev_runtime.Fragment, {
544
+ children: [
545
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
546
+ children: [
547
+ "Confirm you want to restore",
548
+ " ",
549
+ !diffStatsForRestore && "the conversation ",
550
+ "to the point before you sent this message:"
551
+ ]
552
+ }, undefined, true, undefined, this),
553
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
554
+ flexDirection: "column",
555
+ paddingLeft: 1,
556
+ borderStyle: "single",
557
+ borderRight: false,
558
+ borderTop: false,
559
+ borderBottom: false,
560
+ borderLeft: true,
561
+ borderLeftDimColor: true,
562
+ children: [
563
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(UserMessageOption, {
564
+ userMessage: messageToRestore,
565
+ color: "text",
566
+ isCurrent: false
567
+ }, undefined, false, undefined, this),
568
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
569
+ dimColor: true,
570
+ children: [
571
+ "(",
572
+ formatRelativeTimeAgo(new Date(messageToRestore.timestamp)),
573
+ ")"
574
+ ]
575
+ }, undefined, true, undefined, this)
576
+ ]
577
+ }, undefined, true, undefined, this),
578
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(RestoreOptionDescription, {
579
+ selectedRestoreOption,
580
+ canRestoreCode: !!canRestoreCode_0,
581
+ diffStatsForRestore
582
+ }, undefined, false, undefined, this),
583
+ isRestoring && isSummarizeOption(restoringOption) ? /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
584
+ flexDirection: "row",
585
+ gap: 1,
586
+ children: [
587
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Spinner, {}, undefined, false, undefined, this),
588
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
589
+ children: "Summarizing\u2026"
590
+ }, undefined, false, undefined, this)
591
+ ]
592
+ }, undefined, true, undefined, this) : /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Select, {
593
+ isDisabled: isRestoring,
594
+ options: getRestoreOptions(!!canRestoreCode_0),
595
+ defaultFocusValue: canRestoreCode_0 ? "both" : "conversation",
596
+ onFocus: (value) => setSelectedRestoreOption(value),
597
+ onChange: (value_0) => onSelectRestoreOption(value_0),
598
+ onCancel: () => preselectedMessage ? onClose() : setMessageToRestore(undefined)
599
+ }, undefined, false, undefined, this),
600
+ canRestoreCode_0 && /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
601
+ marginBottom: 1,
602
+ children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
603
+ dimColor: true,
604
+ children: [
605
+ figures_default.warning,
606
+ " Rewinding does not affect files edited manually or via bash."
607
+ ]
608
+ }, undefined, true, undefined, this)
609
+ }, undefined, false, undefined, this)
610
+ ]
611
+ }, undefined, true, undefined, this),
612
+ showPickList && /* @__PURE__ */ jsx_dev_runtime.jsxDEV(jsx_dev_runtime.Fragment, {
613
+ children: [
614
+ isFileHistoryEnabled ? /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
615
+ children: "Restore the code and/or conversation to the point before\u2026"
616
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
617
+ children: "Restore and fork the conversation to the point before\u2026"
618
+ }, undefined, false, undefined, this),
619
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
620
+ width: "100%",
621
+ flexDirection: "column",
622
+ children: messageOptions.slice(firstVisibleIndex, firstVisibleIndex + MAX_VISIBLE_MESSAGES).map((msg, visibleOptionIndex) => {
623
+ const optionIndex = firstVisibleIndex + visibleOptionIndex;
624
+ const isSelected = optionIndex === selectedIndex;
625
+ const isCurrent = msg.uuid === currentUUID;
626
+ const metadataLoaded = optionIndex in fileHistoryMetadata;
627
+ const metadata = fileHistoryMetadata[optionIndex];
628
+ const numFilesChanged = metadata?.filesChanged && metadata.filesChanged.length;
629
+ return /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
630
+ height: isFileHistoryEnabled ? 3 : 2,
631
+ overflow: "hidden",
632
+ width: "100%",
633
+ flexDirection: "row",
634
+ children: [
635
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
636
+ width: 2,
637
+ minWidth: 2,
638
+ children: isSelected ? /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
639
+ color: "permission",
640
+ bold: true,
641
+ children: [
642
+ figures_default.pointer,
643
+ " "
644
+ ]
645
+ }, undefined, true, undefined, this) : /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
646
+ children: " "
647
+ }, undefined, false, undefined, this)
648
+ }, undefined, false, undefined, this),
649
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
650
+ flexDirection: "column",
651
+ children: [
652
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
653
+ flexShrink: 1,
654
+ height: 1,
655
+ overflow: "hidden",
656
+ children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(UserMessageOption, {
657
+ userMessage: msg,
658
+ color: isSelected ? "suggestion" : undefined,
659
+ isCurrent,
660
+ paddingRight: 10
661
+ }, undefined, false, undefined, this)
662
+ }, undefined, false, undefined, this),
663
+ isFileHistoryEnabled && metadataLoaded && /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
664
+ height: 1,
665
+ flexDirection: "row",
666
+ children: metadata ? /* @__PURE__ */ jsx_dev_runtime.jsxDEV(jsx_dev_runtime.Fragment, {
667
+ children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
668
+ dimColor: !isSelected,
669
+ color: "inactive",
670
+ children: numFilesChanged ? /* @__PURE__ */ jsx_dev_runtime.jsxDEV(jsx_dev_runtime.Fragment, {
671
+ children: [
672
+ numFilesChanged === 1 && metadata.filesChanged[0] ? `${path.basename(metadata.filesChanged[0])} ` : `${numFilesChanged} files changed `,
673
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(DiffStatsText, {
674
+ diffStats: metadata
675
+ }, undefined, false, undefined, this)
676
+ ]
677
+ }, undefined, true, undefined, this) : /* @__PURE__ */ jsx_dev_runtime.jsxDEV(jsx_dev_runtime.Fragment, {
678
+ children: "No code changes"
679
+ }, undefined, false, undefined, this)
680
+ }, undefined, false, undefined, this)
681
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
682
+ dimColor: true,
683
+ color: "warning",
684
+ children: [
685
+ figures_default.warning,
686
+ " No code restore"
687
+ ]
688
+ }, undefined, true, undefined, this)
689
+ }, undefined, false, undefined, this)
690
+ ]
691
+ }, undefined, true, undefined, this)
692
+ ]
693
+ }, msg.uuid, true, undefined, this);
694
+ })
695
+ }, undefined, false, undefined, this)
696
+ ]
697
+ }, undefined, true, undefined, this),
698
+ !messageToRestore && /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
699
+ dimColor: true,
700
+ italic: true,
701
+ children: exitState.pending ? /* @__PURE__ */ jsx_dev_runtime.jsxDEV(jsx_dev_runtime.Fragment, {
702
+ children: [
703
+ "Press ",
704
+ exitState.keyName,
705
+ " again to exit"
706
+ ]
707
+ }, undefined, true, undefined, this) : /* @__PURE__ */ jsx_dev_runtime.jsxDEV(jsx_dev_runtime.Fragment, {
708
+ children: [
709
+ !error && hasMessagesToSelect && "Enter to continue \xB7 ",
710
+ "Esc to exit"
711
+ ]
712
+ }, undefined, true, undefined, this)
713
+ }, undefined, false, undefined, this)
714
+ ]
715
+ }, undefined, true, undefined, this)
716
+ ]
717
+ }, undefined, true, undefined, this);
718
+ }
719
+ function getRestoreOptionConversationText(option) {
720
+ switch (option) {
721
+ case "summarize":
722
+ return "Messages after this point will be summarized.";
723
+ case "summarize_up_to":
724
+ return "Preceding messages will be summarized. This and subsequent messages will remain unchanged \u2014 you will stay at the end of the conversation.";
725
+ case "both":
726
+ case "conversation":
727
+ return "The conversation will be forked.";
728
+ case "code":
729
+ case "nevermind":
730
+ return "The conversation will be unchanged.";
731
+ }
732
+ }
733
+ function RestoreOptionDescription(t0) {
734
+ const $ = import_compiler_runtime.c(11);
735
+ const {
736
+ selectedRestoreOption,
737
+ canRestoreCode,
738
+ diffStatsForRestore
739
+ } = t0;
740
+ const showCodeRestore = canRestoreCode && (selectedRestoreOption === "both" || selectedRestoreOption === "code");
741
+ let t1;
742
+ if ($[0] !== selectedRestoreOption) {
743
+ t1 = getRestoreOptionConversationText(selectedRestoreOption);
744
+ $[0] = selectedRestoreOption;
745
+ $[1] = t1;
746
+ } else {
747
+ t1 = $[1];
748
+ }
749
+ let t2;
750
+ if ($[2] !== t1) {
751
+ t2 = /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
752
+ dimColor: true,
753
+ children: t1
754
+ }, undefined, false, undefined, this);
755
+ $[2] = t1;
756
+ $[3] = t2;
757
+ } else {
758
+ t2 = $[3];
759
+ }
760
+ let t3;
761
+ if ($[4] !== diffStatsForRestore || $[5] !== selectedRestoreOption || $[6] !== showCodeRestore) {
762
+ t3 = !isSummarizeOption(selectedRestoreOption) && (showCodeRestore ? /* @__PURE__ */ jsx_dev_runtime.jsxDEV(RestoreCodeConfirmation, {
763
+ diffStatsForRestore
764
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
765
+ dimColor: true,
766
+ children: "The code will be unchanged."
767
+ }, undefined, false, undefined, this));
768
+ $[4] = diffStatsForRestore;
769
+ $[5] = selectedRestoreOption;
770
+ $[6] = showCodeRestore;
771
+ $[7] = t3;
772
+ } else {
773
+ t3 = $[7];
774
+ }
775
+ let t4;
776
+ if ($[8] !== t2 || $[9] !== t3) {
777
+ t4 = /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
778
+ flexDirection: "column",
779
+ children: [
780
+ t2,
781
+ t3
782
+ ]
783
+ }, undefined, true, undefined, this);
784
+ $[8] = t2;
785
+ $[9] = t3;
786
+ $[10] = t4;
787
+ } else {
788
+ t4 = $[10];
789
+ }
790
+ return t4;
791
+ }
792
+ function RestoreCodeConfirmation(t0) {
793
+ const $ = import_compiler_runtime.c(14);
794
+ const {
795
+ diffStatsForRestore
796
+ } = t0;
797
+ if (diffStatsForRestore === undefined) {
798
+ return;
799
+ }
800
+ if (!diffStatsForRestore.filesChanged || !diffStatsForRestore.filesChanged[0]) {
801
+ let t12;
802
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
803
+ t12 = /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
804
+ dimColor: true,
805
+ children: "The code has not changed (nothing will be restored)."
806
+ }, undefined, false, undefined, this);
807
+ $[0] = t12;
808
+ } else {
809
+ t12 = $[0];
810
+ }
811
+ return t12;
812
+ }
813
+ const numFilesChanged = diffStatsForRestore.filesChanged.length;
814
+ let fileLabel;
815
+ if (numFilesChanged === 1) {
816
+ let t12;
817
+ if ($[1] !== diffStatsForRestore.filesChanged[0]) {
818
+ t12 = path.basename(diffStatsForRestore.filesChanged[0] || "");
819
+ $[1] = diffStatsForRestore.filesChanged[0];
820
+ $[2] = t12;
821
+ } else {
822
+ t12 = $[2];
823
+ }
824
+ fileLabel = t12;
825
+ } else {
826
+ if (numFilesChanged === 2) {
827
+ let t12;
828
+ if ($[3] !== diffStatsForRestore.filesChanged[0]) {
829
+ t12 = path.basename(diffStatsForRestore.filesChanged[0] || "");
830
+ $[3] = diffStatsForRestore.filesChanged[0];
831
+ $[4] = t12;
832
+ } else {
833
+ t12 = $[4];
834
+ }
835
+ const file1 = t12;
836
+ let t22;
837
+ if ($[5] !== diffStatsForRestore.filesChanged[1]) {
838
+ t22 = path.basename(diffStatsForRestore.filesChanged[1] || "");
839
+ $[5] = diffStatsForRestore.filesChanged[1];
840
+ $[6] = t22;
841
+ } else {
842
+ t22 = $[6];
843
+ }
844
+ const file2 = t22;
845
+ fileLabel = `${file1} and ${file2}`;
846
+ } else {
847
+ let t12;
848
+ if ($[7] !== diffStatsForRestore.filesChanged[0]) {
849
+ t12 = path.basename(diffStatsForRestore.filesChanged[0] || "");
850
+ $[7] = diffStatsForRestore.filesChanged[0];
851
+ $[8] = t12;
852
+ } else {
853
+ t12 = $[8];
854
+ }
855
+ const file1_0 = t12;
856
+ fileLabel = `${file1_0} and ${diffStatsForRestore.filesChanged.length - 1} other files`;
857
+ }
858
+ }
859
+ let t1;
860
+ if ($[9] !== diffStatsForRestore) {
861
+ t1 = /* @__PURE__ */ jsx_dev_runtime.jsxDEV(DiffStatsText, {
862
+ diffStats: diffStatsForRestore
863
+ }, undefined, false, undefined, this);
864
+ $[9] = diffStatsForRestore;
865
+ $[10] = t1;
866
+ } else {
867
+ t1 = $[10];
868
+ }
869
+ let t2;
870
+ if ($[11] !== fileLabel || $[12] !== t1) {
871
+ t2 = /* @__PURE__ */ jsx_dev_runtime.jsxDEV(jsx_dev_runtime.Fragment, {
872
+ children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
873
+ dimColor: true,
874
+ children: [
875
+ "The code will be restored",
876
+ " ",
877
+ t1,
878
+ " in ",
879
+ fileLabel,
880
+ "."
881
+ ]
882
+ }, undefined, true, undefined, this)
883
+ }, undefined, false, undefined, this);
884
+ $[11] = fileLabel;
885
+ $[12] = t1;
886
+ $[13] = t2;
887
+ } else {
888
+ t2 = $[13];
889
+ }
890
+ return t2;
891
+ }
892
+ function DiffStatsText(t0) {
893
+ const $ = import_compiler_runtime.c(7);
894
+ const {
895
+ diffStats
896
+ } = t0;
897
+ if (!diffStats || !diffStats.filesChanged) {
898
+ return;
899
+ }
900
+ let t1;
901
+ if ($[0] !== diffStats.insertions) {
902
+ t1 = /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
903
+ color: "diffAddedWord",
904
+ children: [
905
+ "+",
906
+ diffStats.insertions,
907
+ " "
908
+ ]
909
+ }, undefined, true, undefined, this);
910
+ $[0] = diffStats.insertions;
911
+ $[1] = t1;
912
+ } else {
913
+ t1 = $[1];
914
+ }
915
+ let t2;
916
+ if ($[2] !== diffStats.deletions) {
917
+ t2 = /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
918
+ color: "diffRemovedWord",
919
+ children: [
920
+ "-",
921
+ diffStats.deletions
922
+ ]
923
+ }, undefined, true, undefined, this);
924
+ $[2] = diffStats.deletions;
925
+ $[3] = t2;
926
+ } else {
927
+ t2 = $[3];
928
+ }
929
+ let t3;
930
+ if ($[4] !== t1 || $[5] !== t2) {
931
+ t3 = /* @__PURE__ */ jsx_dev_runtime.jsxDEV(jsx_dev_runtime.Fragment, {
932
+ children: [
933
+ t1,
934
+ t2
935
+ ]
936
+ }, undefined, true, undefined, this);
937
+ $[4] = t1;
938
+ $[5] = t2;
939
+ $[6] = t3;
940
+ } else {
941
+ t3 = $[6];
942
+ }
943
+ return t3;
944
+ }
945
+ function UserMessageOption(t0) {
946
+ const $ = import_compiler_runtime.c(31);
947
+ const {
948
+ userMessage,
949
+ color,
950
+ dimColor,
951
+ isCurrent,
952
+ paddingRight
953
+ } = t0;
954
+ const {
955
+ columns
956
+ } = useTerminalSize();
957
+ if (isCurrent) {
958
+ let t12;
959
+ if ($[0] !== color || $[1] !== dimColor) {
960
+ t12 = /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
961
+ width: "100%",
962
+ children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
963
+ italic: true,
964
+ color,
965
+ dimColor,
966
+ children: "(current)"
967
+ }, undefined, false, undefined, this)
968
+ }, undefined, false, undefined, this);
969
+ $[0] = color;
970
+ $[1] = dimColor;
971
+ $[2] = t12;
972
+ } else {
973
+ t12 = $[2];
974
+ }
975
+ return t12;
976
+ }
977
+ const content = userMessage.message.content;
978
+ const lastBlock = typeof content === "string" ? null : content[content.length - 1];
979
+ let T0;
980
+ let T1;
981
+ let t1;
982
+ let t2;
983
+ let t3;
984
+ let t4;
985
+ let t5;
986
+ let t6;
987
+ if ($[3] !== color || $[4] !== columns || $[5] !== content || $[6] !== dimColor || $[7] !== lastBlock || $[8] !== paddingRight) {
988
+ t6 = Symbol.for("react.early_return_sentinel");
989
+ bb0: {
990
+ const rawMessageText = typeof content === "string" ? content.trim() : lastBlock && isTextBlock(lastBlock) ? lastBlock.text.trim() : "(no prompt)";
991
+ const messageText = stripDisplayTags(rawMessageText);
992
+ if (isEmptyMessageText(messageText)) {
993
+ let t72;
994
+ if ($[17] !== color || $[18] !== dimColor) {
995
+ t72 = /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
996
+ flexDirection: "row",
997
+ width: "100%",
998
+ children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
999
+ italic: true,
1000
+ color,
1001
+ dimColor,
1002
+ children: "((empty message))"
1003
+ }, undefined, false, undefined, this)
1004
+ }, undefined, false, undefined, this);
1005
+ $[17] = color;
1006
+ $[18] = dimColor;
1007
+ $[19] = t72;
1008
+ } else {
1009
+ t72 = $[19];
1010
+ }
1011
+ t6 = t72;
1012
+ break bb0;
1013
+ }
1014
+ if (messageText.includes("<bash-input>")) {
1015
+ const input = extractTag(messageText, "bash-input");
1016
+ if (input) {
1017
+ let t72;
1018
+ if ($[20] === Symbol.for("react.memo_cache_sentinel")) {
1019
+ t72 = /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
1020
+ color: "bashBorder",
1021
+ children: "!"
1022
+ }, undefined, false, undefined, this);
1023
+ $[20] = t72;
1024
+ } else {
1025
+ t72 = $[20];
1026
+ }
1027
+ t6 = /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
1028
+ flexDirection: "row",
1029
+ width: "100%",
1030
+ children: [
1031
+ t72,
1032
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
1033
+ color,
1034
+ dimColor,
1035
+ children: [
1036
+ " ",
1037
+ input
1038
+ ]
1039
+ }, undefined, true, undefined, this)
1040
+ ]
1041
+ }, undefined, true, undefined, this);
1042
+ break bb0;
1043
+ }
1044
+ }
1045
+ if (messageText.includes(`<${COMMAND_MESSAGE_TAG}>`)) {
1046
+ const commandMessage = extractTag(messageText, COMMAND_MESSAGE_TAG);
1047
+ const args = extractTag(messageText, "command-args");
1048
+ const isSkillFormat = extractTag(messageText, "skill-format") === "true";
1049
+ if (commandMessage) {
1050
+ if (isSkillFormat) {
1051
+ t6 = /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
1052
+ flexDirection: "row",
1053
+ width: "100%",
1054
+ children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
1055
+ color,
1056
+ dimColor,
1057
+ children: [
1058
+ "Skill(",
1059
+ commandMessage,
1060
+ ")"
1061
+ ]
1062
+ }, undefined, true, undefined, this)
1063
+ }, undefined, false, undefined, this);
1064
+ break bb0;
1065
+ } else {
1066
+ t6 = /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
1067
+ flexDirection: "row",
1068
+ width: "100%",
1069
+ children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
1070
+ color,
1071
+ dimColor,
1072
+ children: [
1073
+ "/",
1074
+ commandMessage,
1075
+ " ",
1076
+ args
1077
+ ]
1078
+ }, undefined, true, undefined, this)
1079
+ }, undefined, false, undefined, this);
1080
+ break bb0;
1081
+ }
1082
+ }
1083
+ }
1084
+ T1 = ThemedBox_default;
1085
+ t4 = "row";
1086
+ t5 = "100%";
1087
+ T0 = ThemedText;
1088
+ t1 = color;
1089
+ t2 = dimColor;
1090
+ t3 = paddingRight ? truncate(messageText, columns - paddingRight, true) : messageText.slice(0, 500).split(`
1091
+ `).slice(0, 4).join(`
1092
+ `);
1093
+ }
1094
+ $[3] = color;
1095
+ $[4] = columns;
1096
+ $[5] = content;
1097
+ $[6] = dimColor;
1098
+ $[7] = lastBlock;
1099
+ $[8] = paddingRight;
1100
+ $[9] = T0;
1101
+ $[10] = T1;
1102
+ $[11] = t1;
1103
+ $[12] = t2;
1104
+ $[13] = t3;
1105
+ $[14] = t4;
1106
+ $[15] = t5;
1107
+ $[16] = t6;
1108
+ } else {
1109
+ T0 = $[9];
1110
+ T1 = $[10];
1111
+ t1 = $[11];
1112
+ t2 = $[12];
1113
+ t3 = $[13];
1114
+ t4 = $[14];
1115
+ t5 = $[15];
1116
+ t6 = $[16];
1117
+ }
1118
+ if (t6 !== Symbol.for("react.early_return_sentinel")) {
1119
+ return t6;
1120
+ }
1121
+ let t7;
1122
+ if ($[21] !== T0 || $[22] !== t1 || $[23] !== t2 || $[24] !== t3) {
1123
+ t7 = /* @__PURE__ */ jsx_dev_runtime.jsxDEV(T0, {
1124
+ color: t1,
1125
+ dimColor: t2,
1126
+ children: t3
1127
+ }, undefined, false, undefined, this);
1128
+ $[21] = T0;
1129
+ $[22] = t1;
1130
+ $[23] = t2;
1131
+ $[24] = t3;
1132
+ $[25] = t7;
1133
+ } else {
1134
+ t7 = $[25];
1135
+ }
1136
+ let t8;
1137
+ if ($[26] !== T1 || $[27] !== t4 || $[28] !== t5 || $[29] !== t7) {
1138
+ t8 = /* @__PURE__ */ jsx_dev_runtime.jsxDEV(T1, {
1139
+ flexDirection: t4,
1140
+ width: t5,
1141
+ children: t7
1142
+ }, undefined, false, undefined, this);
1143
+ $[26] = T1;
1144
+ $[27] = t4;
1145
+ $[28] = t5;
1146
+ $[29] = t7;
1147
+ $[30] = t8;
1148
+ } else {
1149
+ t8 = $[30];
1150
+ }
1151
+ return t8;
1152
+ }
1153
+ function computeDiffStatsBetweenMessages(messages, fromMessageId, toMessageId) {
1154
+ const startIndex = messages.findIndex((msg) => msg.uuid === fromMessageId);
1155
+ if (startIndex === -1) {
1156
+ return;
1157
+ }
1158
+ let endIndex = toMessageId ? messages.findIndex((msg) => msg.uuid === toMessageId) : messages.length;
1159
+ if (endIndex === -1) {
1160
+ endIndex = messages.length;
1161
+ }
1162
+ const filesChanged = [];
1163
+ let insertions = 0;
1164
+ let deletions = 0;
1165
+ for (let i = startIndex + 1;i < endIndex; i++) {
1166
+ const msg = messages[i];
1167
+ if (!msg || !isToolUseResultMessage(msg)) {
1168
+ continue;
1169
+ }
1170
+ const result = msg.toolUseResult;
1171
+ if (!result || !result.filePath || !result.structuredPatch) {
1172
+ continue;
1173
+ }
1174
+ if (!filesChanged.includes(result.filePath)) {
1175
+ filesChanged.push(result.filePath);
1176
+ }
1177
+ try {
1178
+ if ("type" in result && result.type === "create") {
1179
+ insertions += result.content.split(/\r?\n/).length;
1180
+ } else {
1181
+ for (const hunk of result.structuredPatch) {
1182
+ const additions = count(hunk.lines, (line) => line.startsWith("+"));
1183
+ const removals = count(hunk.lines, (line) => line.startsWith("-"));
1184
+ insertions += additions;
1185
+ deletions += removals;
1186
+ }
1187
+ }
1188
+ } catch {
1189
+ continue;
1190
+ }
1191
+ }
1192
+ return {
1193
+ filesChanged,
1194
+ insertions,
1195
+ deletions
1196
+ };
1197
+ }
1198
+ function selectableUserMessagesFilter(message) {
1199
+ if (message.type !== "user") {
1200
+ return false;
1201
+ }
1202
+ if (Array.isArray(message.message.content) && message.message.content[0]?.type === "tool_result") {
1203
+ return false;
1204
+ }
1205
+ if (isSyntheticMessage(message)) {
1206
+ return false;
1207
+ }
1208
+ if (message.isMeta) {
1209
+ return false;
1210
+ }
1211
+ if (message.isCompactSummary || message.isVisibleInTranscriptOnly) {
1212
+ return false;
1213
+ }
1214
+ const content = message.message.content;
1215
+ const lastBlock = typeof content === "string" ? null : content[content.length - 1];
1216
+ const messageText = typeof content === "string" ? content.trim() : lastBlock && isTextBlock(lastBlock) ? lastBlock.text.trim() : "";
1217
+ if (messageText.indexOf(`<${LOCAL_COMMAND_STDOUT_TAG}>`) !== -1 || messageText.indexOf(`<${LOCAL_COMMAND_STDERR_TAG}>`) !== -1 || messageText.indexOf(`<${BASH_STDOUT_TAG}>`) !== -1 || messageText.indexOf(`<${BASH_STDERR_TAG}>`) !== -1 || messageText.indexOf(`<${TASK_NOTIFICATION_TAG}>`) !== -1 || messageText.indexOf(`<${TICK_TAG}>`) !== -1 || messageText.indexOf(`<${TEAMMATE_MESSAGE_TAG}`) !== -1) {
1218
+ return false;
1219
+ }
1220
+ return true;
1221
+ }
1222
+ function messagesAfterAreOnlySynthetic(messages, fromIndex) {
1223
+ for (let i = fromIndex + 1;i < messages.length; i++) {
1224
+ const msg = messages[i];
1225
+ if (!msg)
1226
+ continue;
1227
+ if (isSyntheticMessage(msg))
1228
+ continue;
1229
+ if (isToolUseResultMessage(msg))
1230
+ continue;
1231
+ if (msg.type === "progress")
1232
+ continue;
1233
+ if (msg.type === "system")
1234
+ continue;
1235
+ if (msg.type === "attachment")
1236
+ continue;
1237
+ if (msg.type === "user" && msg.isMeta)
1238
+ continue;
1239
+ if (msg.type === "assistant") {
1240
+ const content = msg.message.content;
1241
+ if (Array.isArray(content)) {
1242
+ const hasMeaningfulContent = content.some((block) => block.type === "text" && block.text.trim() || block.type === "tool_use");
1243
+ if (hasMeaningfulContent)
1244
+ return false;
1245
+ }
1246
+ continue;
1247
+ }
1248
+ if (msg.type === "user") {
1249
+ return false;
1250
+ }
1251
+ }
1252
+ return true;
1253
+ }
1254
+ var import_compiler_runtime, import_react, jsx_dev_runtime, MAX_VISIBLE_MESSAGES = 7;
1255
+ var init_MessageSelector = __esm(() => {
1256
+ init_figures();
1257
+ init_analytics();
1258
+ init_AppState();
1259
+ init_fileHistory();
1260
+ init_log();
1261
+ init_useExitOnCtrlCDWithKeybindings();
1262
+ init_ink();
1263
+ init_useKeybinding();
1264
+ init_displayTags();
1265
+ init_messages();
1266
+ init_select();
1267
+ init_Spinner();
1268
+ init_useTerminalSize();
1269
+ init_xml();
1270
+ init_array();
1271
+ init_format();
1272
+ init_Divider();
1273
+ import_compiler_runtime = __toESM(require_compiler_runtime(), 1);
1274
+ import_react = __toESM(require_react(), 1);
1275
+ jsx_dev_runtime = __toESM(require_jsx_dev_runtime(), 1);
1276
+ });
1277
+
1278
+ // src/utils/cronJitterConfig.ts
1279
+ var exports_cronJitterConfig = {};
1280
+ __export(exports_cronJitterConfig, {
1281
+ getCronJitterConfig: () => getCronJitterConfig
1282
+ });
1283
+ function getCronJitterConfig() {
1284
+ const raw = getFeatureValue_CACHED_WITH_REFRESH("tengu_kairos_cron_config", DEFAULT_CRON_JITTER_CONFIG, JITTER_CONFIG_REFRESH_MS);
1285
+ const parsed = cronJitterConfigSchema().safeParse(raw);
1286
+ return parsed.success ? parsed.data : DEFAULT_CRON_JITTER_CONFIG;
1287
+ }
1288
+ var JITTER_CONFIG_REFRESH_MS, HALF_HOUR_MS, THIRTY_DAYS_MS, cronJitterConfigSchema;
1289
+ var init_cronJitterConfig = __esm(() => {
1290
+ init_v4();
1291
+ init_growthbook();
1292
+ init_cronTasks();
1293
+ init_lazySchema();
1294
+ JITTER_CONFIG_REFRESH_MS = 60 * 1000;
1295
+ HALF_HOUR_MS = 30 * 60 * 1000;
1296
+ THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1000;
1297
+ cronJitterConfigSchema = lazySchema(() => exports_external.object({
1298
+ recurringFrac: exports_external.number().min(0).max(1),
1299
+ recurringCapMs: exports_external.number().int().min(0).max(HALF_HOUR_MS),
1300
+ oneShotMaxMs: exports_external.number().int().min(0).max(HALF_HOUR_MS),
1301
+ oneShotFloorMs: exports_external.number().int().min(0).max(HALF_HOUR_MS),
1302
+ oneShotMinuteMod: exports_external.number().int().min(1).max(60),
1303
+ recurringMaxAgeMs: exports_external.number().int().min(0).max(THIRTY_DAYS_MS).default(DEFAULT_CRON_JITTER_CONFIG.recurringMaxAgeMs)
1304
+ }).refine((c) => c.oneShotFloorMs <= c.oneShotMaxMs));
1305
+ });
1306
+
1307
+ // src/utils/cronTasksLock.ts
1308
+ import { mkdir, readFile, unlink, writeFile } from "fs/promises";
1309
+ import { dirname, join } from "path";
1310
+ function getLockPath(dir) {
1311
+ return join(dir ?? getProjectRoot(), LOCK_FILE_REL);
1312
+ }
1313
+ async function readLock(dir) {
1314
+ let raw;
1315
+ try {
1316
+ raw = await readFile(getLockPath(dir), "utf8");
1317
+ } catch {
1318
+ return;
1319
+ }
1320
+ const result = schedulerLockSchema().safeParse(safeParseJSON(raw, false));
1321
+ return result.success ? result.data : undefined;
1322
+ }
1323
+ async function tryCreateExclusive(lock, dir) {
1324
+ const path2 = getLockPath(dir);
1325
+ const body = jsonStringify(lock);
1326
+ try {
1327
+ await writeFile(path2, body, { flag: "wx" });
1328
+ return true;
1329
+ } catch (e) {
1330
+ const code = getErrnoCode(e);
1331
+ if (code === "EEXIST")
1332
+ return false;
1333
+ if (code === "ENOENT") {
1334
+ await mkdir(dirname(path2), { recursive: true });
1335
+ try {
1336
+ await writeFile(path2, body, { flag: "wx" });
1337
+ return true;
1338
+ } catch (retryErr) {
1339
+ if (getErrnoCode(retryErr) === "EEXIST")
1340
+ return false;
1341
+ throw retryErr;
1342
+ }
1343
+ }
1344
+ throw e;
1345
+ }
1346
+ }
1347
+ function registerLockCleanup(opts) {
1348
+ unregisterCleanup?.();
1349
+ unregisterCleanup = registerCleanup(async () => {
1350
+ await releaseSchedulerLock(opts);
1351
+ });
1352
+ }
1353
+ async function tryAcquireSchedulerLock(opts) {
1354
+ const dir = opts?.dir;
1355
+ const sessionId = opts?.lockIdentity ?? getSessionId();
1356
+ const lock = {
1357
+ sessionId,
1358
+ pid: process.pid,
1359
+ acquiredAt: Date.now()
1360
+ };
1361
+ if (await tryCreateExclusive(lock, dir)) {
1362
+ lastBlockedBy = undefined;
1363
+ registerLockCleanup(opts);
1364
+ logForDebugging(`[ScheduledTasks] acquired scheduler lock (PID ${process.pid})`);
1365
+ return true;
1366
+ }
1367
+ const existing = await readLock(dir);
1368
+ if (existing?.sessionId === sessionId) {
1369
+ if (existing.pid !== process.pid) {
1370
+ await writeFile(getLockPath(dir), jsonStringify(lock));
1371
+ registerLockCleanup(opts);
1372
+ }
1373
+ return true;
1374
+ }
1375
+ if (existing && isProcessRunning(existing.pid)) {
1376
+ if (lastBlockedBy !== existing.sessionId) {
1377
+ lastBlockedBy = existing.sessionId;
1378
+ logForDebugging(`[ScheduledTasks] scheduler lock held by session ${existing.sessionId} (PID ${existing.pid})`);
1379
+ }
1380
+ return false;
1381
+ }
1382
+ if (existing) {
1383
+ logForDebugging(`[ScheduledTasks] recovering stale scheduler lock from PID ${existing.pid}`);
1384
+ }
1385
+ await unlink(getLockPath(dir)).catch(() => {});
1386
+ if (await tryCreateExclusive(lock, dir)) {
1387
+ lastBlockedBy = undefined;
1388
+ registerLockCleanup(opts);
1389
+ return true;
1390
+ }
1391
+ return false;
1392
+ }
1393
+ async function releaseSchedulerLock(opts) {
1394
+ unregisterCleanup?.();
1395
+ unregisterCleanup = undefined;
1396
+ lastBlockedBy = undefined;
1397
+ const dir = opts?.dir;
1398
+ const sessionId = opts?.lockIdentity ?? getSessionId();
1399
+ const existing = await readLock(dir);
1400
+ if (!existing || existing.sessionId !== sessionId)
1401
+ return;
1402
+ try {
1403
+ await unlink(getLockPath(dir));
1404
+ logForDebugging("[ScheduledTasks] released scheduler lock");
1405
+ } catch {}
1406
+ }
1407
+ var LOCK_FILE_REL, schedulerLockSchema, unregisterCleanup, lastBlockedBy;
1408
+ var init_cronTasksLock = __esm(() => {
1409
+ init_v4();
1410
+ init_state();
1411
+ init_cleanupRegistry();
1412
+ init_debug();
1413
+ init_errors();
1414
+ init_genericProcessUtils();
1415
+ init_json();
1416
+ init_lazySchema();
1417
+ init_slowOperations();
1418
+ LOCK_FILE_REL = join(".claude", "scheduled_tasks.lock");
1419
+ schedulerLockSchema = lazySchema(() => exports_external.object({
1420
+ sessionId: exports_external.string(),
1421
+ pid: exports_external.number(),
1422
+ acquiredAt: exports_external.number()
1423
+ }));
1424
+ });
1425
+
1426
+ // src/utils/cronScheduler.ts
1427
+ var exports_cronScheduler = {};
1428
+ __export(exports_cronScheduler, {
1429
+ isRecurringTaskAged: () => isRecurringTaskAged,
1430
+ createCronScheduler: () => createCronScheduler,
1431
+ buildMissedTaskNotification: () => buildMissedTaskNotification
1432
+ });
1433
+ function isRecurringTaskAged(t, nowMs, maxAgeMs) {
1434
+ if (maxAgeMs === 0)
1435
+ return false;
1436
+ return Boolean(t.recurring && !t.permanent && nowMs - t.createdAt >= maxAgeMs);
1437
+ }
1438
+ function createCronScheduler(options) {
1439
+ const {
1440
+ onFire,
1441
+ isLoading,
1442
+ assistantMode = false,
1443
+ onFireTask,
1444
+ onMissed,
1445
+ dir,
1446
+ lockIdentity,
1447
+ getJitterConfig,
1448
+ isKilled,
1449
+ filter
1450
+ } = options;
1451
+ const lockOpts = dir || lockIdentity ? { dir, lockIdentity } : undefined;
1452
+ let tasks = [];
1453
+ const nextFireAt = new Map;
1454
+ const missedAsked = new Set;
1455
+ const inFlight = new Set;
1456
+ let enablePoll = null;
1457
+ let checkTimer = null;
1458
+ let lockProbeTimer = null;
1459
+ let watcher = null;
1460
+ let stopped = false;
1461
+ let isOwner = false;
1462
+ async function load(initial) {
1463
+ const next = await readCronTasks(dir);
1464
+ if (stopped)
1465
+ return;
1466
+ tasks = next;
1467
+ if (!initial)
1468
+ return;
1469
+ const now = Date.now();
1470
+ const missed = findMissedTasks(next, now).filter((t) => !t.recurring && !missedAsked.has(t.id) && (!filter || filter(t)));
1471
+ if (missed.length > 0) {
1472
+ for (const t of missed) {
1473
+ missedAsked.add(t.id);
1474
+ nextFireAt.set(t.id, Infinity);
1475
+ }
1476
+ logEvent("tengu_scheduled_task_missed", {
1477
+ count: missed.length,
1478
+ taskIds: missed.map((t) => t.id).join(",")
1479
+ });
1480
+ if (onMissed) {
1481
+ onMissed(missed);
1482
+ } else {
1483
+ onFire(buildMissedTaskNotification(missed));
1484
+ }
1485
+ removeCronTasks(missed.map((t) => t.id), dir).catch((e) => logForDebugging(`[ScheduledTasks] failed to remove missed tasks: ${e}`));
1486
+ logForDebugging(`[ScheduledTasks] surfaced ${missed.length} missed one-shot task(s)`);
1487
+ }
1488
+ }
1489
+ function check() {
1490
+ if (isKilled?.())
1491
+ return;
1492
+ if (isLoading() && !assistantMode)
1493
+ return;
1494
+ const now = Date.now();
1495
+ const seen = new Set;
1496
+ const firedFileRecurring = [];
1497
+ const jitterCfg = getJitterConfig?.() ?? DEFAULT_CRON_JITTER_CONFIG;
1498
+ function process2(t, isSession) {
1499
+ if (filter && !filter(t))
1500
+ return;
1501
+ seen.add(t.id);
1502
+ if (inFlight.has(t.id))
1503
+ return;
1504
+ let next = nextFireAt.get(t.id);
1505
+ if (next === undefined) {
1506
+ next = t.recurring ? jitteredNextCronRunMs(t.cron, t.lastFiredAt ?? t.createdAt, t.id, jitterCfg) ?? Infinity : oneShotJitteredNextCronRunMs(t.cron, t.createdAt, t.id, jitterCfg) ?? Infinity;
1507
+ nextFireAt.set(t.id, next);
1508
+ logForDebugging(`[ScheduledTasks] scheduled ${t.id} for ${next === Infinity ? "never" : new Date(next).toISOString()}`);
1509
+ }
1510
+ if (now < next)
1511
+ return;
1512
+ logForDebugging(`[ScheduledTasks] firing ${t.id}${t.recurring ? " (recurring)" : ""}`);
1513
+ logEvent("tengu_scheduled_task_fire", {
1514
+ recurring: t.recurring ?? false,
1515
+ taskId: t.id
1516
+ });
1517
+ if (onFireTask) {
1518
+ onFireTask(t);
1519
+ } else {
1520
+ onFire(t.prompt);
1521
+ }
1522
+ const aged = isRecurringTaskAged(t, now, jitterCfg.recurringMaxAgeMs);
1523
+ if (aged) {
1524
+ const ageHours = Math.floor((now - t.createdAt) / 1000 / 60 / 60);
1525
+ logForDebugging(`[ScheduledTasks] recurring task ${t.id} aged out (${ageHours}h since creation), deleting after final fire`);
1526
+ logEvent("tengu_scheduled_task_expired", {
1527
+ taskId: t.id,
1528
+ ageHours
1529
+ });
1530
+ }
1531
+ if (t.recurring && !aged) {
1532
+ const newNext = jitteredNextCronRunMs(t.cron, now, t.id, jitterCfg) ?? Infinity;
1533
+ nextFireAt.set(t.id, newNext);
1534
+ if (!isSession)
1535
+ firedFileRecurring.push(t.id);
1536
+ } else if (isSession) {
1537
+ removeSessionCronTasks([t.id]);
1538
+ nextFireAt.delete(t.id);
1539
+ } else {
1540
+ inFlight.add(t.id);
1541
+ removeCronTasks([t.id], dir).catch((e) => logForDebugging(`[ScheduledTasks] failed to remove task ${t.id}: ${e}`)).finally(() => inFlight.delete(t.id));
1542
+ nextFireAt.delete(t.id);
1543
+ }
1544
+ }
1545
+ if (isOwner) {
1546
+ for (const t of tasks)
1547
+ process2(t, false);
1548
+ if (firedFileRecurring.length > 0) {
1549
+ for (const id of firedFileRecurring)
1550
+ inFlight.add(id);
1551
+ markCronTasksFired(firedFileRecurring, now, dir).catch((e) => logForDebugging(`[ScheduledTasks] failed to persist lastFiredAt: ${e}`)).finally(() => {
1552
+ for (const id of firedFileRecurring)
1553
+ inFlight.delete(id);
1554
+ });
1555
+ }
1556
+ }
1557
+ if (dir === undefined) {
1558
+ for (const t of getSessionCronTasks())
1559
+ process2(t, true);
1560
+ }
1561
+ if (seen.size === 0) {
1562
+ nextFireAt.clear();
1563
+ return;
1564
+ }
1565
+ for (const id of nextFireAt.keys()) {
1566
+ if (!seen.has(id))
1567
+ nextFireAt.delete(id);
1568
+ }
1569
+ }
1570
+ async function enable() {
1571
+ if (stopped)
1572
+ return;
1573
+ if (enablePoll) {
1574
+ clearInterval(enablePoll);
1575
+ enablePoll = null;
1576
+ }
1577
+ const { default: chokidar } = await import("./chunk-eqp1rfft.js");
1578
+ if (stopped)
1579
+ return;
1580
+ isOwner = await tryAcquireSchedulerLock(lockOpts).catch(() => false);
1581
+ if (stopped) {
1582
+ if (isOwner) {
1583
+ isOwner = false;
1584
+ releaseSchedulerLock(lockOpts);
1585
+ }
1586
+ return;
1587
+ }
1588
+ if (!isOwner) {
1589
+ lockProbeTimer = setInterval(() => {
1590
+ tryAcquireSchedulerLock(lockOpts).then((owned) => {
1591
+ if (stopped) {
1592
+ if (owned)
1593
+ releaseSchedulerLock(lockOpts);
1594
+ return;
1595
+ }
1596
+ if (owned) {
1597
+ isOwner = true;
1598
+ if (lockProbeTimer) {
1599
+ clearInterval(lockProbeTimer);
1600
+ lockProbeTimer = null;
1601
+ }
1602
+ }
1603
+ }).catch((e) => logForDebugging(String(e), { level: "error" }));
1604
+ }, LOCK_PROBE_INTERVAL_MS);
1605
+ lockProbeTimer.unref?.();
1606
+ }
1607
+ load(true);
1608
+ const path2 = getCronFilePath(dir);
1609
+ watcher = chokidar.watch(path2, {
1610
+ persistent: false,
1611
+ ignoreInitial: true,
1612
+ awaitWriteFinish: { stabilityThreshold: FILE_STABILITY_MS },
1613
+ ignorePermissionErrors: true
1614
+ });
1615
+ watcher.on("add", () => void load(false));
1616
+ watcher.on("change", () => void load(false));
1617
+ watcher.on("unlink", () => {
1618
+ if (!stopped) {
1619
+ tasks = [];
1620
+ nextFireAt.clear();
1621
+ }
1622
+ });
1623
+ checkTimer = setInterval(check, CHECK_INTERVAL_MS);
1624
+ checkTimer.unref?.();
1625
+ }
1626
+ return {
1627
+ start() {
1628
+ stopped = false;
1629
+ if (dir !== undefined) {
1630
+ logForDebugging(`[ScheduledTasks] scheduler start() \u2014 dir=${dir}, hasTasks=${hasCronTasksSync(dir)}`);
1631
+ enable();
1632
+ return;
1633
+ }
1634
+ logForDebugging(`[ScheduledTasks] scheduler start() \u2014 enabled=${getScheduledTasksEnabled()}, hasTasks=${hasCronTasksSync()}`);
1635
+ if (!getScheduledTasksEnabled() && (assistantMode || hasCronTasksSync())) {
1636
+ setScheduledTasksEnabled(true);
1637
+ }
1638
+ if (getScheduledTasksEnabled()) {
1639
+ enable();
1640
+ return;
1641
+ }
1642
+ enablePoll = setInterval((en) => {
1643
+ if (getScheduledTasksEnabled())
1644
+ en();
1645
+ }, CHECK_INTERVAL_MS, enable);
1646
+ enablePoll.unref?.();
1647
+ },
1648
+ stop() {
1649
+ stopped = true;
1650
+ if (enablePoll) {
1651
+ clearInterval(enablePoll);
1652
+ enablePoll = null;
1653
+ }
1654
+ if (checkTimer) {
1655
+ clearInterval(checkTimer);
1656
+ checkTimer = null;
1657
+ }
1658
+ if (lockProbeTimer) {
1659
+ clearInterval(lockProbeTimer);
1660
+ lockProbeTimer = null;
1661
+ }
1662
+ watcher?.close();
1663
+ watcher = null;
1664
+ if (isOwner) {
1665
+ isOwner = false;
1666
+ releaseSchedulerLock(lockOpts);
1667
+ }
1668
+ },
1669
+ getNextFireTime() {
1670
+ let min = Infinity;
1671
+ for (const t of nextFireAt.values()) {
1672
+ if (t < min)
1673
+ min = t;
1674
+ }
1675
+ return min === Infinity ? null : min;
1676
+ }
1677
+ };
1678
+ }
1679
+ function buildMissedTaskNotification(missed) {
1680
+ const plural = missed.length > 1;
1681
+ const header = `The following one-shot scheduled task${plural ? "s were" : " was"} missed while Claude was not running. ${plural ? "They have" : "It has"} already been removed from .claude/scheduled_tasks.json.
1682
+
1683
+ Do NOT execute ${plural ? "these prompts" : "this prompt"} yet. First use the AskUserQuestion tool to ask whether to run ${plural ? "each one" : "it"} now. Only execute if the user confirms.`;
1684
+ const blocks = missed.map((t) => {
1685
+ const meta = `[${cronToHuman(t.cron)}, created ${new Date(t.createdAt).toLocaleString()}]`;
1686
+ const longestRun = (t.prompt.match(/`+/g) ?? []).reduce((max, run) => Math.max(max, run.length), 0);
1687
+ const fence = "`".repeat(Math.max(3, longestRun + 1));
1688
+ return `${meta}
1689
+ ${fence}
1690
+ ${t.prompt}
1691
+ ${fence}`;
1692
+ });
1693
+ return `${header}
1694
+
1695
+ ${blocks.join(`
1696
+
1697
+ `)}`;
1698
+ }
1699
+ var CHECK_INTERVAL_MS = 1000, FILE_STABILITY_MS = 300, LOCK_PROBE_INTERVAL_MS = 5000;
1700
+ var init_cronScheduler = __esm(() => {
1701
+ init_state();
1702
+ init_analytics();
1703
+ init_cron();
1704
+ init_cronTasks();
1705
+ init_cronTasksLock();
1706
+ init_debug();
1707
+ });
1708
+
1709
+ // src/bridge/inboundMessages.ts
1710
+ init_imageResizer();
1711
+ function extractInboundMessageFields(msg) {
1712
+ if (msg.type !== "user")
1713
+ return;
1714
+ const content = msg.message?.content;
1715
+ if (!content)
1716
+ return;
1717
+ if (Array.isArray(content) && content.length === 0)
1718
+ return;
1719
+ const uuid = "uuid" in msg && typeof msg.uuid === "string" ? msg.uuid : undefined;
1720
+ return {
1721
+ content: Array.isArray(content) ? normalizeImageBlocks(content) : content,
1722
+ uuid
1723
+ };
1724
+ }
1725
+ function normalizeImageBlocks(blocks) {
1726
+ if (!blocks.some(isMalformedBase64Image))
1727
+ return blocks;
1728
+ return blocks.map((block) => {
1729
+ if (!isMalformedBase64Image(block))
1730
+ return block;
1731
+ const src = block.source;
1732
+ const mediaType = typeof src.mediaType === "string" && src.mediaType ? src.mediaType : detectImageFormatFromBase64(block.source.data);
1733
+ return {
1734
+ ...block,
1735
+ source: {
1736
+ type: "base64",
1737
+ media_type: mediaType,
1738
+ data: block.source.data
1739
+ }
1740
+ };
1741
+ });
1742
+ }
1743
+ function isMalformedBase64Image(block) {
1744
+ if (block.type !== "image" || block.source?.type !== "base64")
1745
+ return false;
1746
+ return !block.source.media_type;
1747
+ }
1748
+
1749
+ // src/utils/permissions/PermissionPromptToolResultSchema.ts
1750
+ init_v4();
1751
+ init_debug();
1752
+ init_lazySchema();
1753
+ init_PermissionUpdate();
1754
+ init_PermissionUpdateSchema();
1755
+ var inputSchema = lazySchema(() => v4_default.object({
1756
+ tool_name: v4_default.string().describe("The name of the tool requesting permission"),
1757
+ input: v4_default.record(v4_default.string(), v4_default.unknown()).describe("The input for the tool"),
1758
+ tool_use_id: v4_default.string().optional().describe("The unique tool use request ID")
1759
+ }));
1760
+ var decisionClassificationField = lazySchema(() => v4_default.enum(["user_temporary", "user_permanent", "user_reject"]).optional().catch(undefined));
1761
+ var PermissionAllowResultSchema = lazySchema(() => v4_default.object({
1762
+ behavior: v4_default.literal("allow"),
1763
+ updatedInput: v4_default.record(v4_default.string(), v4_default.unknown()),
1764
+ updatedPermissions: v4_default.array(permissionUpdateSchema()).optional().catch((ctx) => {
1765
+ logForDebugging(`Malformed updatedPermissions from SDK host ignored: ${ctx.error.issues[0]?.message ?? "unknown"}`, { level: "warn" });
1766
+ return;
1767
+ }),
1768
+ toolUseID: v4_default.string().optional(),
1769
+ decisionClassification: decisionClassificationField()
1770
+ }));
1771
+ var PermissionDenyResultSchema = lazySchema(() => v4_default.object({
1772
+ behavior: v4_default.literal("deny"),
1773
+ message: v4_default.string(),
1774
+ interrupt: v4_default.boolean().optional(),
1775
+ toolUseID: v4_default.string().optional(),
1776
+ decisionClassification: decisionClassificationField()
1777
+ }));
1778
+ var outputSchema = lazySchema(() => v4_default.union([PermissionAllowResultSchema(), PermissionDenyResultSchema()]));
1779
+ function permissionPromptToolResultToPermissionDecision(result, tool, input, toolUseContext) {
1780
+ const decisionReason = {
1781
+ type: "permissionPromptTool",
1782
+ permissionPromptToolName: tool.name,
1783
+ toolResult: result
1784
+ };
1785
+ if (result.behavior === "allow") {
1786
+ const updatedPermissions = result.updatedPermissions;
1787
+ if (updatedPermissions) {
1788
+ toolUseContext.setAppState((prev) => ({
1789
+ ...prev,
1790
+ toolPermissionContext: applyPermissionUpdates(prev.toolPermissionContext, updatedPermissions)
1791
+ }));
1792
+ persistPermissionUpdates(updatedPermissions);
1793
+ }
1794
+ const updatedInput = Object.keys(result.updatedInput).length > 0 ? result.updatedInput : input;
1795
+ return {
1796
+ ...result,
1797
+ updatedInput,
1798
+ decisionReason
1799
+ };
1800
+ } else if (result.behavior === "deny" && result.interrupt) {
1801
+ logForDebugging(`SDK permission prompt deny+interrupt: tool=${tool.name} message=${result.message}`);
1802
+ toolUseContext.abortController.abort();
1803
+ }
1804
+ return {
1805
+ ...result,
1806
+ decisionReason
1807
+ };
1808
+ }
1809
+
1810
+ // src/cli/structuredIO.ts
1811
+ import { randomUUID as randomUUID2 } from "crypto";
1812
+
1813
+ // src/entrypoints/sdk/controlSchemas.ts
1814
+ init_v4();
1815
+ init_lazySchema();
1816
+ init_coreSchemas();
1817
+ var JSONRPCMessagePlaceholder = lazySchema(() => exports_external.unknown());
1818
+ var SDKHookCallbackMatcherSchema = lazySchema(() => exports_external.object({
1819
+ matcher: exports_external.string().optional(),
1820
+ hookCallbackIds: exports_external.array(exports_external.string()),
1821
+ timeout: exports_external.number().optional()
1822
+ }).describe("Configuration for matching and routing hook callbacks."));
1823
+ var SDKControlInitializeRequestSchema = lazySchema(() => exports_external.object({
1824
+ subtype: exports_external.literal("initialize"),
1825
+ hooks: exports_external.record(HookEventSchema(), exports_external.array(SDKHookCallbackMatcherSchema())).optional(),
1826
+ sdkMcpServers: exports_external.array(exports_external.string()).optional(),
1827
+ jsonSchema: exports_external.record(exports_external.string(), exports_external.unknown()).optional(),
1828
+ systemPrompt: exports_external.string().optional(),
1829
+ appendSystemPrompt: exports_external.string().optional(),
1830
+ agents: exports_external.record(exports_external.string(), AgentDefinitionSchema()).optional(),
1831
+ promptSuggestions: exports_external.boolean().optional(),
1832
+ agentProgressSummaries: exports_external.boolean().optional()
1833
+ }).describe("Initializes the SDK session with hooks, MCP servers, and agent configuration."));
1834
+ var SDKControlInitializeResponseSchema = lazySchema(() => exports_external.object({
1835
+ commands: exports_external.array(SlashCommandSchema()),
1836
+ agents: exports_external.array(AgentInfoSchema()),
1837
+ output_style: exports_external.string(),
1838
+ available_output_styles: exports_external.array(exports_external.string()),
1839
+ models: exports_external.array(ModelInfoSchema()),
1840
+ account: AccountInfoSchema(),
1841
+ pid: exports_external.number().optional().describe("@internal CLI process PID for tmux socket isolation"),
1842
+ fast_mode_state: FastModeStateSchema().optional()
1843
+ }).describe("Response from session initialization with available commands, models, and account info."));
1844
+ var SDKControlInterruptRequestSchema = lazySchema(() => exports_external.object({
1845
+ subtype: exports_external.literal("interrupt")
1846
+ }).describe("Interrupts the currently running conversation turn."));
1847
+ var SDKControlPermissionRequestSchema = lazySchema(() => exports_external.object({
1848
+ subtype: exports_external.literal("can_use_tool"),
1849
+ tool_name: exports_external.string(),
1850
+ input: exports_external.record(exports_external.string(), exports_external.unknown()),
1851
+ permission_suggestions: exports_external.array(PermissionUpdateSchema()).optional(),
1852
+ blocked_path: exports_external.string().optional(),
1853
+ decision_reason: exports_external.string().optional(),
1854
+ title: exports_external.string().optional(),
1855
+ display_name: exports_external.string().optional(),
1856
+ tool_use_id: exports_external.string(),
1857
+ agent_id: exports_external.string().optional(),
1858
+ description: exports_external.string().optional()
1859
+ }).describe("Requests permission to use a tool with the given input."));
1860
+ var SDKControlSetPermissionModeRequestSchema = lazySchema(() => exports_external.object({
1861
+ subtype: exports_external.literal("set_permission_mode"),
1862
+ mode: PermissionModeSchema(),
1863
+ ultraplan: exports_external.boolean().optional().describe("@internal CCR ultraplan session marker.")
1864
+ }).describe("Sets the permission mode for tool execution handling."));
1865
+ var SDKControlSetModelRequestSchema = lazySchema(() => exports_external.object({
1866
+ subtype: exports_external.literal("set_model"),
1867
+ model: exports_external.string().optional()
1868
+ }).describe("Sets the model to use for subsequent conversation turns."));
1869
+ var SDKControlSetMaxThinkingTokensRequestSchema = lazySchema(() => exports_external.object({
1870
+ subtype: exports_external.literal("set_max_thinking_tokens"),
1871
+ max_thinking_tokens: exports_external.number().nullable()
1872
+ }).describe("Sets the maximum number of thinking tokens for extended thinking."));
1873
+ var SDKControlMcpStatusRequestSchema = lazySchema(() => exports_external.object({
1874
+ subtype: exports_external.literal("mcp_status")
1875
+ }).describe("Requests the current status of all MCP server connections."));
1876
+ var SDKControlMcpStatusResponseSchema = lazySchema(() => exports_external.object({
1877
+ mcpServers: exports_external.array(McpServerStatusSchema())
1878
+ }).describe("Response containing the current status of all MCP server connections."));
1879
+ var SDKControlGetContextUsageRequestSchema = lazySchema(() => exports_external.object({
1880
+ subtype: exports_external.literal("get_context_usage")
1881
+ }).describe("Requests a breakdown of current context window usage by category."));
1882
+ var ContextCategorySchema = lazySchema(() => exports_external.object({
1883
+ name: exports_external.string(),
1884
+ tokens: exports_external.number(),
1885
+ color: exports_external.string(),
1886
+ isDeferred: exports_external.boolean().optional()
1887
+ }));
1888
+ var ContextGridSquareSchema = lazySchema(() => exports_external.object({
1889
+ color: exports_external.string(),
1890
+ isFilled: exports_external.boolean(),
1891
+ categoryName: exports_external.string(),
1892
+ tokens: exports_external.number(),
1893
+ percentage: exports_external.number(),
1894
+ squareFullness: exports_external.number()
1895
+ }));
1896
+ var SDKControlGetContextUsageResponseSchema = lazySchema(() => exports_external.object({
1897
+ categories: exports_external.array(ContextCategorySchema()),
1898
+ totalTokens: exports_external.number(),
1899
+ maxTokens: exports_external.number(),
1900
+ rawMaxTokens: exports_external.number(),
1901
+ percentage: exports_external.number(),
1902
+ gridRows: exports_external.array(exports_external.array(ContextGridSquareSchema())),
1903
+ model: exports_external.string(),
1904
+ memoryFiles: exports_external.array(exports_external.object({
1905
+ path: exports_external.string(),
1906
+ type: exports_external.string(),
1907
+ tokens: exports_external.number()
1908
+ })),
1909
+ mcpTools: exports_external.array(exports_external.object({
1910
+ name: exports_external.string(),
1911
+ serverName: exports_external.string(),
1912
+ tokens: exports_external.number(),
1913
+ isLoaded: exports_external.boolean().optional()
1914
+ })),
1915
+ deferredBuiltinTools: exports_external.array(exports_external.object({
1916
+ name: exports_external.string(),
1917
+ tokens: exports_external.number(),
1918
+ isLoaded: exports_external.boolean()
1919
+ })).optional(),
1920
+ systemTools: exports_external.array(exports_external.object({ name: exports_external.string(), tokens: exports_external.number() })).optional(),
1921
+ systemPromptSections: exports_external.array(exports_external.object({ name: exports_external.string(), tokens: exports_external.number() })).optional(),
1922
+ agents: exports_external.array(exports_external.object({
1923
+ agentType: exports_external.string(),
1924
+ source: exports_external.string(),
1925
+ tokens: exports_external.number()
1926
+ })),
1927
+ slashCommands: exports_external.object({
1928
+ totalCommands: exports_external.number(),
1929
+ includedCommands: exports_external.number(),
1930
+ tokens: exports_external.number()
1931
+ }).optional(),
1932
+ skills: exports_external.object({
1933
+ totalSkills: exports_external.number(),
1934
+ includedSkills: exports_external.number(),
1935
+ tokens: exports_external.number(),
1936
+ skillFrontmatter: exports_external.array(exports_external.object({
1937
+ name: exports_external.string(),
1938
+ source: exports_external.string(),
1939
+ tokens: exports_external.number()
1940
+ }))
1941
+ }).optional(),
1942
+ autoCompactThreshold: exports_external.number().optional(),
1943
+ isAutoCompactEnabled: exports_external.boolean(),
1944
+ messageBreakdown: exports_external.object({
1945
+ toolCallTokens: exports_external.number(),
1946
+ toolResultTokens: exports_external.number(),
1947
+ attachmentTokens: exports_external.number(),
1948
+ assistantMessageTokens: exports_external.number(),
1949
+ userMessageTokens: exports_external.number(),
1950
+ toolCallsByType: exports_external.array(exports_external.object({
1951
+ name: exports_external.string(),
1952
+ callTokens: exports_external.number(),
1953
+ resultTokens: exports_external.number()
1954
+ })),
1955
+ attachmentsByType: exports_external.array(exports_external.object({ name: exports_external.string(), tokens: exports_external.number() }))
1956
+ }).optional(),
1957
+ apiUsage: exports_external.object({
1958
+ input_tokens: exports_external.number(),
1959
+ output_tokens: exports_external.number(),
1960
+ cache_creation_input_tokens: exports_external.number(),
1961
+ cache_read_input_tokens: exports_external.number()
1962
+ }).nullable()
1963
+ }).describe("Breakdown of current context window usage by category (system prompt, tools, messages, etc.)."));
1964
+ var SDKControlRewindFilesRequestSchema = lazySchema(() => exports_external.object({
1965
+ subtype: exports_external.literal("rewind_files"),
1966
+ user_message_id: exports_external.string(),
1967
+ dry_run: exports_external.boolean().optional()
1968
+ }).describe("Rewinds file changes made since a specific user message."));
1969
+ var SDKControlRewindFilesResponseSchema = lazySchema(() => exports_external.object({
1970
+ canRewind: exports_external.boolean(),
1971
+ error: exports_external.string().optional(),
1972
+ filesChanged: exports_external.array(exports_external.string()).optional(),
1973
+ insertions: exports_external.number().optional(),
1974
+ deletions: exports_external.number().optional()
1975
+ }).describe("Result of a rewindFiles operation."));
1976
+ var SDKControlCancelAsyncMessageRequestSchema = lazySchema(() => exports_external.object({
1977
+ subtype: exports_external.literal("cancel_async_message"),
1978
+ message_uuid: exports_external.string()
1979
+ }).describe("Drops a pending async user message from the command queue by uuid. No-op if already dequeued for execution."));
1980
+ var SDKControlCancelAsyncMessageResponseSchema = lazySchema(() => exports_external.object({
1981
+ cancelled: exports_external.boolean()
1982
+ }).describe("Result of a cancel_async_message operation. cancelled=false means the message was not in the queue (already dequeued or never enqueued)."));
1983
+ var SDKControlSeedReadStateRequestSchema = lazySchema(() => exports_external.object({
1984
+ subtype: exports_external.literal("seed_read_state"),
1985
+ path: exports_external.string(),
1986
+ mtime: exports_external.number()
1987
+ }).describe("Seeds the readFileState cache with a path+mtime entry. Use when a prior Read was removed from context (e.g. by snip) so Edit validation would fail despite the client having observed the Read. The mtime lets the CLI detect if the file changed since the seeded Read \u2014 same staleness check as the normal path."));
1988
+ var SDKHookCallbackRequestSchema = lazySchema(() => exports_external.object({
1989
+ subtype: exports_external.literal("hook_callback"),
1990
+ callback_id: exports_external.string(),
1991
+ input: HookInputSchema(),
1992
+ tool_use_id: exports_external.string().optional()
1993
+ }).describe("Delivers a hook callback with its input data."));
1994
+ var SDKControlMcpMessageRequestSchema = lazySchema(() => exports_external.object({
1995
+ subtype: exports_external.literal("mcp_message"),
1996
+ server_name: exports_external.string(),
1997
+ message: JSONRPCMessagePlaceholder()
1998
+ }).describe("Sends a JSON-RPC message to a specific MCP server."));
1999
+ var SDKControlMcpSetServersRequestSchema = lazySchema(() => exports_external.object({
2000
+ subtype: exports_external.literal("mcp_set_servers"),
2001
+ servers: exports_external.record(exports_external.string(), McpServerConfigForProcessTransportSchema())
2002
+ }).describe("Replaces the set of dynamically managed MCP servers."));
2003
+ var SDKControlMcpSetServersResponseSchema = lazySchema(() => exports_external.object({
2004
+ added: exports_external.array(exports_external.string()),
2005
+ removed: exports_external.array(exports_external.string()),
2006
+ errors: exports_external.record(exports_external.string(), exports_external.string())
2007
+ }).describe("Result of replacing the set of dynamically managed MCP servers."));
2008
+ var SDKControlReloadPluginsRequestSchema = lazySchema(() => exports_external.object({
2009
+ subtype: exports_external.literal("reload_plugins")
2010
+ }).describe("Reloads plugins from disk and returns the refreshed session components."));
2011
+ var SDKControlReloadPluginsResponseSchema = lazySchema(() => exports_external.object({
2012
+ commands: exports_external.array(SlashCommandSchema()),
2013
+ agents: exports_external.array(AgentInfoSchema()),
2014
+ plugins: exports_external.array(exports_external.object({
2015
+ name: exports_external.string(),
2016
+ path: exports_external.string(),
2017
+ source: exports_external.string().optional()
2018
+ })),
2019
+ mcpServers: exports_external.array(McpServerStatusSchema()),
2020
+ error_count: exports_external.number()
2021
+ }).describe("Refreshed commands, agents, plugins, and MCP server status after reload."));
2022
+ var SDKControlMcpReconnectRequestSchema = lazySchema(() => exports_external.object({
2023
+ subtype: exports_external.literal("mcp_reconnect"),
2024
+ serverName: exports_external.string()
2025
+ }).describe("Reconnects a disconnected or failed MCP server."));
2026
+ var SDKControlMcpToggleRequestSchema = lazySchema(() => exports_external.object({
2027
+ subtype: exports_external.literal("mcp_toggle"),
2028
+ serverName: exports_external.string(),
2029
+ enabled: exports_external.boolean()
2030
+ }).describe("Enables or disables an MCP server."));
2031
+ var SDKControlStopTaskRequestSchema = lazySchema(() => exports_external.object({
2032
+ subtype: exports_external.literal("stop_task"),
2033
+ task_id: exports_external.string()
2034
+ }).describe("Stops a running task."));
2035
+ var SDKControlApplyFlagSettingsRequestSchema = lazySchema(() => exports_external.object({
2036
+ subtype: exports_external.literal("apply_flag_settings"),
2037
+ settings: exports_external.record(exports_external.string(), exports_external.unknown())
2038
+ }).describe("Merges the provided settings into the flag settings layer, updating the active configuration."));
2039
+ var SDKControlGetSettingsRequestSchema = lazySchema(() => exports_external.object({
2040
+ subtype: exports_external.literal("get_settings")
2041
+ }).describe("Returns the effective merged settings and the raw per-source settings."));
2042
+ var SDKControlGetSettingsResponseSchema = lazySchema(() => exports_external.object({
2043
+ effective: exports_external.record(exports_external.string(), exports_external.unknown()),
2044
+ sources: exports_external.array(exports_external.object({
2045
+ source: exports_external.enum([
2046
+ "userSettings",
2047
+ "projectSettings",
2048
+ "localSettings",
2049
+ "flagSettings",
2050
+ "policySettings"
2051
+ ]),
2052
+ settings: exports_external.record(exports_external.string(), exports_external.unknown())
2053
+ })).describe("Ordered low-to-high priority \u2014 later entries override earlier ones."),
2054
+ applied: exports_external.object({
2055
+ model: exports_external.string(),
2056
+ effort: exports_external.enum(["low", "medium", "high", "max"]).nullable()
2057
+ }).optional().describe("Runtime-resolved values after env overrides, session state, and model-specific defaults are applied. Unlike `effective` (disk merge), these reflect what will actually be sent to the API.")
2058
+ }).describe("Effective merged settings plus raw per-source settings in merge order."));
2059
+ var SDKControlElicitationRequestSchema = lazySchema(() => exports_external.object({
2060
+ subtype: exports_external.literal("elicitation"),
2061
+ mcp_server_name: exports_external.string(),
2062
+ message: exports_external.string(),
2063
+ mode: exports_external.enum(["form", "url"]).optional(),
2064
+ url: exports_external.string().optional(),
2065
+ elicitation_id: exports_external.string().optional(),
2066
+ requested_schema: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
2067
+ }).describe("Requests the SDK consumer to handle an MCP elicitation (user input request)."));
2068
+ var SDKControlElicitationResponseSchema = lazySchema(() => exports_external.object({
2069
+ action: exports_external.enum(["accept", "decline", "cancel"]),
2070
+ content: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
2071
+ }).describe("Response from the SDK consumer for an elicitation request."));
2072
+ var SDKControlRequestInnerSchema = lazySchema(() => exports_external.union([
2073
+ SDKControlInterruptRequestSchema(),
2074
+ SDKControlPermissionRequestSchema(),
2075
+ SDKControlInitializeRequestSchema(),
2076
+ SDKControlSetPermissionModeRequestSchema(),
2077
+ SDKControlSetModelRequestSchema(),
2078
+ SDKControlSetMaxThinkingTokensRequestSchema(),
2079
+ SDKControlMcpStatusRequestSchema(),
2080
+ SDKControlGetContextUsageRequestSchema(),
2081
+ SDKHookCallbackRequestSchema(),
2082
+ SDKControlMcpMessageRequestSchema(),
2083
+ SDKControlRewindFilesRequestSchema(),
2084
+ SDKControlCancelAsyncMessageRequestSchema(),
2085
+ SDKControlSeedReadStateRequestSchema(),
2086
+ SDKControlMcpSetServersRequestSchema(),
2087
+ SDKControlReloadPluginsRequestSchema(),
2088
+ SDKControlMcpReconnectRequestSchema(),
2089
+ SDKControlMcpToggleRequestSchema(),
2090
+ SDKControlStopTaskRequestSchema(),
2091
+ SDKControlApplyFlagSettingsRequestSchema(),
2092
+ SDKControlGetSettingsRequestSchema(),
2093
+ SDKControlElicitationRequestSchema()
2094
+ ]));
2095
+ var SDKControlRequestSchema = lazySchema(() => exports_external.object({
2096
+ type: exports_external.literal("control_request"),
2097
+ request_id: exports_external.string(),
2098
+ request: SDKControlRequestInnerSchema()
2099
+ }));
2100
+ var ControlResponseSchema = lazySchema(() => exports_external.object({
2101
+ subtype: exports_external.literal("success"),
2102
+ request_id: exports_external.string(),
2103
+ response: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
2104
+ }));
2105
+ var ControlErrorResponseSchema = lazySchema(() => exports_external.object({
2106
+ subtype: exports_external.literal("error"),
2107
+ request_id: exports_external.string(),
2108
+ error: exports_external.string(),
2109
+ pending_permission_requests: exports_external.array(exports_external.lazy(() => SDKControlRequestSchema())).optional()
2110
+ }));
2111
+ var SDKControlResponseSchema = lazySchema(() => exports_external.object({
2112
+ type: exports_external.literal("control_response"),
2113
+ response: exports_external.union([ControlResponseSchema(), ControlErrorResponseSchema()])
2114
+ }));
2115
+ var SDKControlCancelRequestSchema = lazySchema(() => exports_external.object({
2116
+ type: exports_external.literal("control_cancel_request"),
2117
+ request_id: exports_external.string()
2118
+ }).describe("Cancels a currently open control request."));
2119
+ var SDKKeepAliveMessageSchema = lazySchema(() => exports_external.object({
2120
+ type: exports_external.literal("keep_alive")
2121
+ }).describe("Keep-alive message to maintain WebSocket connection."));
2122
+ var SDKUpdateEnvironmentVariablesMessageSchema = lazySchema(() => exports_external.object({
2123
+ type: exports_external.literal("update_environment_variables"),
2124
+ variables: exports_external.record(exports_external.string(), exports_external.string())
2125
+ }).describe("Updates environment variables at runtime."));
2126
+ var StdoutMessageSchema = lazySchema(() => exports_external.union([
2127
+ SDKMessageSchema(),
2128
+ SDKStreamlinedTextMessageSchema(),
2129
+ SDKStreamlinedToolUseSummaryMessageSchema(),
2130
+ SDKPostTurnSummaryMessageSchema(),
2131
+ SDKControlResponseSchema(),
2132
+ SDKControlRequestSchema(),
2133
+ SDKControlCancelRequestSchema(),
2134
+ SDKKeepAliveMessageSchema()
2135
+ ]));
2136
+ var StdinMessageSchema = lazySchema(() => exports_external.union([
2137
+ SDKUserMessageSchema(),
2138
+ SDKControlRequestSchema(),
2139
+ SDKControlResponseSchema(),
2140
+ SDKKeepAliveMessageSchema(),
2141
+ SDKUpdateEnvironmentVariablesMessageSchema()
2142
+ ]));
2143
+
2144
+ // src/cli/structuredIO.ts
2145
+ init_hooks();
2146
+ init_debug();
2147
+ init_diagLogs();
2148
+ init_errors();
2149
+ init_permissions();
2150
+ init_process();
2151
+ init_slowOperations();
2152
+ init_v4();
2153
+ init_commandLifecycle();
2154
+ init_hooks2();
2155
+ init_PermissionUpdate();
2156
+ init_slowOperations();
2157
+ init_stream();
2158
+
2159
+ // src/cli/ndjsonSafeStringify.ts
2160
+ init_slowOperations();
2161
+ var JS_LINE_TERMINATORS = /\u2028|\u2029/g;
2162
+ function escapeJsLineTerminators(json) {
2163
+ return json.replace(JS_LINE_TERMINATORS, (c) => c === "\u2028" ? "\\u2028" : "\\u2029");
2164
+ }
2165
+ function ndjsonSafeStringify(value) {
2166
+ return escapeJsLineTerminators(jsonStringify(value));
2167
+ }
2168
+
2169
+ // src/cli/structuredIO.ts
2170
+ var SANDBOX_NETWORK_ACCESS_TOOL_NAME = "SandboxNetworkAccess";
2171
+ function serializeDecisionReason(reason) {
2172
+ if (!reason) {
2173
+ return;
2174
+ }
2175
+ if (false) {}
2176
+ switch (reason.type) {
2177
+ case "rule":
2178
+ case "mode":
2179
+ case "subcommandResults":
2180
+ case "permissionPromptTool":
2181
+ return;
2182
+ case "hook":
2183
+ case "asyncAgent":
2184
+ case "sandboxOverride":
2185
+ case "workingDir":
2186
+ case "safetyCheck":
2187
+ case "other":
2188
+ return reason.reason;
2189
+ }
2190
+ }
2191
+ function buildRequiresActionDetails(tool, input, toolUseID, requestId) {
2192
+ let description;
2193
+ try {
2194
+ description = tool.getActivityDescription?.(input) ?? tool.getToolUseSummary?.(input) ?? tool.userFacingName(input);
2195
+ } catch {
2196
+ description = tool.name;
2197
+ }
2198
+ return {
2199
+ tool_name: tool.name,
2200
+ action_description: description,
2201
+ tool_use_id: toolUseID,
2202
+ request_id: requestId,
2203
+ input
2204
+ };
2205
+ }
2206
+ var MAX_RESOLVED_TOOL_USE_IDS = 1000;
2207
+
2208
+ class StructuredIO {
2209
+ input;
2210
+ replayUserMessages;
2211
+ structuredInput;
2212
+ pendingRequests = new Map;
2213
+ restoredWorkerState = Promise.resolve(null);
2214
+ inputClosed = false;
2215
+ unexpectedResponseCallback;
2216
+ resolvedToolUseIds = new Set;
2217
+ prependedLines = [];
2218
+ onControlRequestSent;
2219
+ onControlRequestResolved;
2220
+ outbound = new Stream;
2221
+ constructor(input, replayUserMessages) {
2222
+ this.input = input;
2223
+ this.replayUserMessages = replayUserMessages;
2224
+ this.input = input;
2225
+ this.structuredInput = this.read();
2226
+ }
2227
+ trackResolvedToolUseId(request) {
2228
+ const inner = request.request;
2229
+ if (inner.subtype === "can_use_tool") {
2230
+ this.resolvedToolUseIds.add(inner.tool_use_id);
2231
+ if (this.resolvedToolUseIds.size > MAX_RESOLVED_TOOL_USE_IDS) {
2232
+ const first = this.resolvedToolUseIds.values().next().value;
2233
+ if (first !== undefined) {
2234
+ this.resolvedToolUseIds.delete(first);
2235
+ }
2236
+ }
2237
+ }
2238
+ }
2239
+ flushInternalEvents() {
2240
+ return Promise.resolve();
2241
+ }
2242
+ get internalEventsPending() {
2243
+ return 0;
2244
+ }
2245
+ prependUserMessage(content) {
2246
+ this.prependedLines.push(jsonStringify({
2247
+ type: "user",
2248
+ content,
2249
+ uuid: "",
2250
+ session_id: "",
2251
+ message: { role: "user", content },
2252
+ parent_tool_use_id: null
2253
+ }) + `
2254
+ `);
2255
+ }
2256
+ async* read() {
2257
+ let content = "";
2258
+ const splitAndProcess = async function* () {
2259
+ for (;; ) {
2260
+ if (this.prependedLines.length > 0) {
2261
+ content = this.prependedLines.join("") + content;
2262
+ this.prependedLines = [];
2263
+ }
2264
+ const newline = content.indexOf(`
2265
+ `);
2266
+ if (newline === -1)
2267
+ break;
2268
+ const line = content.slice(0, newline);
2269
+ content = content.slice(newline + 1);
2270
+ const message = await this.processLine(line);
2271
+ if (message) {
2272
+ logForDiagnosticsNoPII("info", "cli_stdin_message_parsed", {
2273
+ type: message.type
2274
+ });
2275
+ yield message;
2276
+ }
2277
+ }
2278
+ }.bind(this);
2279
+ yield* splitAndProcess();
2280
+ for await (const block of this.input) {
2281
+ content += block;
2282
+ yield* splitAndProcess();
2283
+ }
2284
+ if (content) {
2285
+ const message = await this.processLine(content);
2286
+ if (message) {
2287
+ yield message;
2288
+ }
2289
+ }
2290
+ this.inputClosed = true;
2291
+ for (const request of this.pendingRequests.values()) {
2292
+ request.reject(new Error("Tool permission stream closed before response received"));
2293
+ }
2294
+ }
2295
+ getPendingPermissionRequests() {
2296
+ return Array.from(this.pendingRequests.values()).map((entry) => entry.request).filter((pr) => pr.request.subtype === "can_use_tool");
2297
+ }
2298
+ setUnexpectedResponseCallback(callback) {
2299
+ this.unexpectedResponseCallback = callback;
2300
+ }
2301
+ injectControlResponse(response) {
2302
+ const responseInner = response.response;
2303
+ const requestId = responseInner?.request_id;
2304
+ if (!requestId)
2305
+ return;
2306
+ const request = this.pendingRequests.get(requestId);
2307
+ if (!request)
2308
+ return;
2309
+ this.trackResolvedToolUseId(request.request);
2310
+ this.pendingRequests.delete(requestId);
2311
+ this.write({
2312
+ type: "control_cancel_request",
2313
+ request_id: requestId
2314
+ });
2315
+ if (responseInner.subtype === "error") {
2316
+ request.reject(new Error(responseInner.error));
2317
+ } else {
2318
+ const result = responseInner.response;
2319
+ if (request.schema) {
2320
+ try {
2321
+ request.resolve(request.schema.parse(result));
2322
+ } catch (error) {
2323
+ request.reject(error);
2324
+ }
2325
+ } else {
2326
+ request.resolve({});
2327
+ }
2328
+ }
2329
+ }
2330
+ setOnControlRequestSent(callback) {
2331
+ this.onControlRequestSent = callback;
2332
+ }
2333
+ setOnControlRequestResolved(callback) {
2334
+ this.onControlRequestResolved = callback;
2335
+ }
2336
+ async processLine(line) {
2337
+ if (!line) {
2338
+ return;
2339
+ }
2340
+ try {
2341
+ const message = normalizeControlMessageKeys(jsonParse(line));
2342
+ if (message.type === "keep_alive") {
2343
+ return;
2344
+ }
2345
+ if (message.type === "update_environment_variables") {
2346
+ const variables = message.variables;
2347
+ const keys = Object.keys(variables);
2348
+ for (const [key, value] of Object.entries(variables)) {
2349
+ process.env[key] = value;
2350
+ }
2351
+ logForDebugging(`[structuredIO] applied update_environment_variables: ${keys.join(", ")}`);
2352
+ return;
2353
+ }
2354
+ if (message.type === "control_response") {
2355
+ const uuid = "uuid" in message && typeof message.uuid === "string" ? message.uuid : undefined;
2356
+ if (uuid) {
2357
+ notifyCommandLifecycle(uuid, "completed");
2358
+ }
2359
+ const request = this.pendingRequests.get(message.response.request_id);
2360
+ if (!request) {
2361
+ const responsePayload = message.response.subtype === "success" ? message.response.response : undefined;
2362
+ const toolUseID = responsePayload?.toolUseID;
2363
+ if (typeof toolUseID === "string" && this.resolvedToolUseIds.has(toolUseID)) {
2364
+ logForDebugging(`Ignoring duplicate control_response for already-resolved toolUseID=${toolUseID} request_id=${message.response.request_id}`);
2365
+ return;
2366
+ }
2367
+ if (this.unexpectedResponseCallback) {
2368
+ await this.unexpectedResponseCallback(message);
2369
+ }
2370
+ return;
2371
+ }
2372
+ this.trackResolvedToolUseId(request.request);
2373
+ this.pendingRequests.delete(message.response.request_id);
2374
+ if (request.request.request.subtype === "can_use_tool" && this.onControlRequestResolved) {
2375
+ this.onControlRequestResolved(message.response.request_id);
2376
+ }
2377
+ if (message.response.subtype === "error") {
2378
+ request.reject(new Error(message.response.error));
2379
+ return;
2380
+ }
2381
+ const result = message.response.response;
2382
+ if (request.schema) {
2383
+ try {
2384
+ request.resolve(request.schema.parse(result));
2385
+ } catch (error) {
2386
+ request.reject(error);
2387
+ }
2388
+ } else {
2389
+ request.resolve({});
2390
+ }
2391
+ if (this.replayUserMessages) {
2392
+ return message;
2393
+ }
2394
+ return;
2395
+ }
2396
+ if (message.type !== "user" && message.type !== "control_request" && message.type !== "assistant" && message.type !== "system") {
2397
+ logForDebugging(`Ignoring unknown message type: ${message.type}`, {
2398
+ level: "warn"
2399
+ });
2400
+ return;
2401
+ }
2402
+ if (message.type === "control_request") {
2403
+ if (!message.request) {
2404
+ exitWithMessage(`Error: Missing request on control_request`);
2405
+ }
2406
+ return message;
2407
+ }
2408
+ if (message.type === "assistant" || message.type === "system") {
2409
+ return message;
2410
+ }
2411
+ if (message.message.role !== "user") {
2412
+ exitWithMessage(`Error: Expected message role 'user', got '${message.message.role}'`);
2413
+ }
2414
+ return message;
2415
+ } catch (error) {
2416
+ console.error(`Error parsing streaming input line: ${line}: ${error}`);
2417
+ process.exit(1);
2418
+ }
2419
+ }
2420
+ async write(message) {
2421
+ writeToStdout(ndjsonSafeStringify(message) + `
2422
+ `);
2423
+ }
2424
+ async sendRequest(request, schema, signal, requestId = randomUUID2()) {
2425
+ const message = {
2426
+ type: "control_request",
2427
+ request_id: requestId,
2428
+ request
2429
+ };
2430
+ if (this.inputClosed) {
2431
+ throw new Error("Stream closed");
2432
+ }
2433
+ if (signal?.aborted) {
2434
+ throw new Error("Request aborted");
2435
+ }
2436
+ this.outbound.enqueue(message);
2437
+ if (request.subtype === "can_use_tool" && this.onControlRequestSent) {
2438
+ this.onControlRequestSent(message);
2439
+ }
2440
+ const aborted = () => {
2441
+ this.outbound.enqueue({
2442
+ type: "control_cancel_request",
2443
+ request_id: requestId
2444
+ });
2445
+ const request2 = this.pendingRequests.get(requestId);
2446
+ if (request2) {
2447
+ this.trackResolvedToolUseId(request2.request);
2448
+ request2.reject(new AbortError);
2449
+ }
2450
+ };
2451
+ if (signal) {
2452
+ signal.addEventListener("abort", aborted, {
2453
+ once: true
2454
+ });
2455
+ }
2456
+ try {
2457
+ return await new Promise((resolve, reject) => {
2458
+ this.pendingRequests.set(requestId, {
2459
+ request: {
2460
+ type: "control_request",
2461
+ request_id: requestId,
2462
+ request
2463
+ },
2464
+ resolve: (result) => {
2465
+ resolve(result);
2466
+ },
2467
+ reject,
2468
+ schema
2469
+ });
2470
+ });
2471
+ } finally {
2472
+ if (signal) {
2473
+ signal.removeEventListener("abort", aborted);
2474
+ }
2475
+ this.pendingRequests.delete(requestId);
2476
+ }
2477
+ }
2478
+ createCanUseTool(onPermissionPrompt) {
2479
+ return async (tool, input, toolUseContext, assistantMessage, toolUseID, forceDecision) => {
2480
+ const mainPermissionResult = forceDecision ?? await hasPermissionsToUseTool(tool, input, toolUseContext, assistantMessage, toolUseID);
2481
+ if (mainPermissionResult.behavior === "allow" || mainPermissionResult.behavior === "deny") {
2482
+ return mainPermissionResult;
2483
+ }
2484
+ const hookAbortController = new AbortController;
2485
+ const parentSignal = toolUseContext.abortController.signal;
2486
+ const onParentAbort = () => hookAbortController.abort();
2487
+ parentSignal.addEventListener("abort", onParentAbort, { once: true });
2488
+ try {
2489
+ const hookPromise = executePermissionRequestHooksForSDK(tool.name, toolUseID, input, toolUseContext, mainPermissionResult.suggestions).then((decision) => ({ source: "hook", decision }));
2490
+ const requestId = randomUUID2();
2491
+ onPermissionPrompt?.(buildRequiresActionDetails(tool, input, toolUseID, requestId));
2492
+ const sdkPromise = this.sendRequest({
2493
+ subtype: "can_use_tool",
2494
+ tool_name: tool.name,
2495
+ input,
2496
+ permission_suggestions: mainPermissionResult.suggestions,
2497
+ blocked_path: mainPermissionResult.blockedPath,
2498
+ decision_reason: serializeDecisionReason(mainPermissionResult.decisionReason),
2499
+ tool_use_id: toolUseID,
2500
+ agent_id: toolUseContext.agentId
2501
+ }, outputSchema(), hookAbortController.signal, requestId).then((result) => ({ source: "sdk", result }));
2502
+ const winner = await Promise.race([hookPromise, sdkPromise]);
2503
+ if (winner.source === "hook") {
2504
+ if (winner.decision) {
2505
+ sdkPromise.catch(() => {});
2506
+ hookAbortController.abort();
2507
+ return winner.decision;
2508
+ }
2509
+ const sdkResult = await sdkPromise;
2510
+ return permissionPromptToolResultToPermissionDecision(sdkResult.result, tool, input, toolUseContext);
2511
+ }
2512
+ return permissionPromptToolResultToPermissionDecision(winner.result, tool, input, toolUseContext);
2513
+ } catch (error) {
2514
+ return permissionPromptToolResultToPermissionDecision({
2515
+ behavior: "deny",
2516
+ message: `Tool permission request failed: ${error}`,
2517
+ toolUseID
2518
+ }, tool, input, toolUseContext);
2519
+ } finally {
2520
+ if (this.getPendingPermissionRequests().length === 0) {
2521
+ notifySessionStateChanged("running");
2522
+ }
2523
+ parentSignal.removeEventListener("abort", onParentAbort);
2524
+ }
2525
+ };
2526
+ }
2527
+ createHookCallback(callbackId, timeout) {
2528
+ return {
2529
+ type: "callback",
2530
+ timeout,
2531
+ callback: async (input, toolUseID, abort) => {
2532
+ try {
2533
+ const result = await this.sendRequest({
2534
+ subtype: "hook_callback",
2535
+ callback_id: callbackId,
2536
+ input,
2537
+ tool_use_id: toolUseID || undefined
2538
+ }, hookJSONOutputSchema(), abort);
2539
+ return result;
2540
+ } catch (error) {
2541
+ console.error(`Error in hook callback ${callbackId}:`, error);
2542
+ return {};
2543
+ }
2544
+ }
2545
+ };
2546
+ }
2547
+ async handleElicitation(serverName, message, requestedSchema, signal, mode, url, elicitationId) {
2548
+ try {
2549
+ const result = await this.sendRequest({
2550
+ subtype: "elicitation",
2551
+ mcp_server_name: serverName,
2552
+ message,
2553
+ mode,
2554
+ url,
2555
+ elicitation_id: elicitationId,
2556
+ requested_schema: requestedSchema
2557
+ }, SDKControlElicitationResponseSchema(), signal);
2558
+ return result;
2559
+ } catch {
2560
+ return { action: "cancel" };
2561
+ }
2562
+ }
2563
+ createSandboxAskCallback() {
2564
+ return async (hostPattern) => {
2565
+ try {
2566
+ const result = await this.sendRequest({
2567
+ subtype: "can_use_tool",
2568
+ tool_name: SANDBOX_NETWORK_ACCESS_TOOL_NAME,
2569
+ input: { host: hostPattern.host },
2570
+ tool_use_id: randomUUID2(),
2571
+ description: `Allow network connection to ${hostPattern.host}?`
2572
+ }, outputSchema());
2573
+ return result.behavior === "allow";
2574
+ } catch {
2575
+ return false;
2576
+ }
2577
+ };
2578
+ }
2579
+ async sendMcpMessage(serverName, message) {
2580
+ const response = await this.sendRequest({
2581
+ subtype: "mcp_message",
2582
+ server_name: serverName,
2583
+ message
2584
+ }, exports_external.object({
2585
+ mcp_response: exports_external.any()
2586
+ }));
2587
+ return response.mcp_response;
2588
+ }
2589
+ }
2590
+ function exitWithMessage(message) {
2591
+ console.error(message);
2592
+ process.exit(1);
2593
+ }
2594
+ async function executePermissionRequestHooksForSDK(toolName, toolUseID, input, toolUseContext, suggestions) {
2595
+ const appState = toolUseContext.getAppState();
2596
+ const permissionMode = appState.toolPermissionContext.mode;
2597
+ const hookGenerator = executePermissionRequestHooks(toolName, toolUseID, input, toolUseContext, permissionMode, suggestions, toolUseContext.abortController.signal);
2598
+ for await (const hookResult of hookGenerator) {
2599
+ if (hookResult.permissionRequestResult && (hookResult.permissionRequestResult.behavior === "allow" || hookResult.permissionRequestResult.behavior === "deny")) {
2600
+ const decision = hookResult.permissionRequestResult;
2601
+ if (decision.behavior === "allow") {
2602
+ const finalInput = decision.updatedInput || input;
2603
+ const permissionUpdates = decision.updatedPermissions ?? [];
2604
+ if (permissionUpdates.length > 0) {
2605
+ persistPermissionUpdates(permissionUpdates);
2606
+ const currentAppState = toolUseContext.getAppState();
2607
+ const updatedContext = applyPermissionUpdates(currentAppState.toolPermissionContext, permissionUpdates);
2608
+ toolUseContext.setAppState((prev) => {
2609
+ if (prev.toolPermissionContext === updatedContext)
2610
+ return prev;
2611
+ return { ...prev, toolPermissionContext: updatedContext };
2612
+ });
2613
+ }
2614
+ return {
2615
+ behavior: "allow",
2616
+ updatedInput: finalInput,
2617
+ userModified: false,
2618
+ decisionReason: {
2619
+ type: "hook",
2620
+ hookName: "PermissionRequest"
2621
+ }
2622
+ };
2623
+ } else {
2624
+ return {
2625
+ behavior: "deny",
2626
+ message: decision.message || "Permission denied by PermissionRequest hook",
2627
+ decisionReason: {
2628
+ type: "hook",
2629
+ hookName: "PermissionRequest"
2630
+ }
2631
+ };
2632
+ }
2633
+ }
2634
+ }
2635
+ return;
2636
+ }
2637
+
2638
+ // src/utils/messages/systemInit.ts
2639
+ init_state();
2640
+ init_outputStyles();
2641
+ init_constants();
2642
+ init_auth();
2643
+ init_cwd();
2644
+ init_fastMode();
2645
+ init_settings();
2646
+ import { randomUUID as randomUUID3 } from "crypto";
2647
+ function sdkCompatToolName(name) {
2648
+ return name === AGENT_TOOL_NAME ? LEGACY_AGENT_TOOL_NAME : name;
2649
+ }
2650
+ function buildSystemInitMessage(inputs) {
2651
+ const settings = getSettings_DEPRECATED();
2652
+ const outputStyle = settings?.outputStyle ?? DEFAULT_OUTPUT_STYLE_NAME;
2653
+ const initMessage = {
2654
+ type: "system",
2655
+ subtype: "init",
2656
+ cwd: getCwd(),
2657
+ session_id: getSessionId(),
2658
+ tools: inputs.tools.map((tool) => sdkCompatToolName(tool.name)),
2659
+ mcp_servers: inputs.mcpClients.map((client) => ({
2660
+ name: client.name,
2661
+ status: client.type
2662
+ })),
2663
+ model: inputs.model,
2664
+ permissionMode: inputs.permissionMode,
2665
+ slash_commands: inputs.commands.filter((c) => c.userInvocable !== false).map((c) => c.name),
2666
+ apiKeySource: getAnthropicApiKeyWithSource().source,
2667
+ betas: getSdkBetas(),
2668
+ claude_code_version: MACRO.VERSION,
2669
+ output_style: outputStyle,
2670
+ agents: inputs.agents.map((agent) => agent.agentType),
2671
+ skills: inputs.skills.filter((s) => s.userInvocable !== false).map((skill) => skill.name),
2672
+ plugins: inputs.plugins.map((plugin) => ({
2673
+ name: plugin.name,
2674
+ path: plugin.path,
2675
+ source: plugin.source
2676
+ })),
2677
+ uuid: randomUUID3()
2678
+ };
2679
+ if (false) {}
2680
+ initMessage.fast_mode_state = getFastModeState(inputs.model, inputs.fastMode);
2681
+ return initMessage;
2682
+ }
2683
+
2684
+ // src/utils/ultraplan/keyword.ts
2685
+ var OPEN_TO_CLOSE = {
2686
+ "`": "`",
2687
+ '"': '"',
2688
+ "<": ">",
2689
+ "{": "}",
2690
+ "[": "]",
2691
+ "(": ")",
2692
+ "'": "'"
2693
+ };
2694
+ function findKeywordTriggerPositions(text, keyword) {
2695
+ const re = new RegExp(keyword, "i");
2696
+ if (!re.test(text))
2697
+ return [];
2698
+ if (text.startsWith("/"))
2699
+ return [];
2700
+ const quotedRanges = [];
2701
+ let openQuote = null;
2702
+ let openAt = 0;
2703
+ const isWord = (ch) => !!ch && /[\p{L}\p{N}_]/u.test(ch);
2704
+ for (let i = 0;i < text.length; i++) {
2705
+ const ch = text[i];
2706
+ if (openQuote) {
2707
+ if (openQuote === "[" && ch === "[") {
2708
+ openAt = i;
2709
+ continue;
2710
+ }
2711
+ if (ch !== OPEN_TO_CLOSE[openQuote])
2712
+ continue;
2713
+ if (openQuote === "'" && isWord(text[i + 1]))
2714
+ continue;
2715
+ quotedRanges.push({ start: openAt, end: i + 1 });
2716
+ openQuote = null;
2717
+ } else if (ch === "<" && i + 1 < text.length && /[a-zA-Z/]/.test(text[i + 1]) || ch === "'" && !isWord(text[i - 1]) || ch !== "<" && ch !== "'" && ch in OPEN_TO_CLOSE) {
2718
+ openQuote = ch;
2719
+ openAt = i;
2720
+ }
2721
+ }
2722
+ const positions = [];
2723
+ const wordRe = new RegExp(`\\b${keyword}\\b`, "gi");
2724
+ const matches = text.matchAll(wordRe);
2725
+ for (const match of matches) {
2726
+ if (match.index === undefined)
2727
+ continue;
2728
+ const start = match.index;
2729
+ const end = start + match[0].length;
2730
+ if (quotedRanges.some((r) => start >= r.start && start < r.end))
2731
+ continue;
2732
+ const before = text[start - 1];
2733
+ const after = text[end];
2734
+ if (before === "/" || before === "\\" || before === "-")
2735
+ continue;
2736
+ if (after === "/" || after === "\\" || after === "-" || after === "?")
2737
+ continue;
2738
+ if (after === "." && isWord(text[end + 1]))
2739
+ continue;
2740
+ positions.push({ word: match[0], start, end });
2741
+ }
2742
+ return positions;
2743
+ }
2744
+ function findUltrareviewTriggerPositions(text) {
2745
+ return findKeywordTriggerPositions(text, "ultrareview");
2746
+ }
2747
+
2748
+ // src/utils/processUserInput/processUserInput.ts
2749
+ init_analytics();
2750
+ init_messages();
2751
+ init_commands();
2752
+ init_textInputTypes();
2753
+ init_attachments();
2754
+ init_generators();
2755
+ init_hooks2();
2756
+ init_imageResizer();
2757
+ init_imageStore();
2758
+ init_messages();
2759
+ init_queryProfiler();
2760
+ init_slashCommandParsing();
2761
+ import { randomUUID as randomUUID5 } from "crypto";
2762
+
2763
+ // src/utils/processUserInput/processTextPrompt.ts
2764
+ init_state();
2765
+ init_analytics();
2766
+ init_messages();
2767
+ init_events();
2768
+ init_sessionTracing();
2769
+ import { randomUUID as randomUUID4 } from "crypto";
2770
+
2771
+ // src/utils/userPromptKeywords.ts
2772
+ function matchesNegativeKeyword(input) {
2773
+ const lowerInput = input.toLowerCase();
2774
+ const negativePattern = /\b(wtf|wth|ffs|omfg|shit(ty|tiest)?|dumbass|horrible|awful|piss(ed|ing)? off|piece of (shit|crap|junk)|what the (fuck|hell)|fucking? (broken|useless|terrible|awful|horrible)|fuck you|screw (this|you)|so frustrating|this sucks|damn it)\b/;
2775
+ return negativePattern.test(lowerInput);
2776
+ }
2777
+ function matchesKeepGoingKeyword(input) {
2778
+ const lowerInput = input.toLowerCase().trim();
2779
+ if (lowerInput === "continue") {
2780
+ return true;
2781
+ }
2782
+ const keepGoingPattern = /\b(keep going|go on)\b/;
2783
+ return keepGoingPattern.test(lowerInput);
2784
+ }
2785
+
2786
+ // src/utils/processUserInput/processTextPrompt.ts
2787
+ function processTextPrompt(input, imageContentBlocks, imagePasteIds, attachmentMessages, uuid, permissionMode, isMeta) {
2788
+ const promptId = randomUUID4();
2789
+ setPromptId(promptId);
2790
+ const userPromptText = typeof input === "string" ? input : input.find((block) => block.type === "text")?.text || "";
2791
+ startInteractionSpan(userPromptText);
2792
+ const otelPromptText = typeof input === "string" ? input : input.findLast((block) => block.type === "text")?.text || "";
2793
+ if (otelPromptText) {
2794
+ logOTelEvent("user_prompt", {
2795
+ prompt_length: String(otelPromptText.length),
2796
+ prompt: redactIfDisabled(otelPromptText),
2797
+ "prompt.id": promptId
2798
+ });
2799
+ }
2800
+ const isNegative = matchesNegativeKeyword(userPromptText);
2801
+ const isKeepGoing = matchesKeepGoingKeyword(userPromptText);
2802
+ logEvent("tengu_input_prompt", {
2803
+ is_negative: isNegative,
2804
+ is_keep_going: isKeepGoing
2805
+ });
2806
+ if (imageContentBlocks.length > 0) {
2807
+ const textContent = typeof input === "string" ? input.trim() ? [{ type: "text", text: input }] : [] : input;
2808
+ const userMessage2 = createUserMessage({
2809
+ content: [...textContent, ...imageContentBlocks],
2810
+ uuid,
2811
+ imagePasteIds: imagePasteIds.length > 0 ? imagePasteIds : undefined,
2812
+ permissionMode,
2813
+ isMeta: isMeta || undefined
2814
+ });
2815
+ return {
2816
+ messages: [userMessage2, ...attachmentMessages],
2817
+ shouldQuery: true
2818
+ };
2819
+ }
2820
+ const userMessage = createUserMessage({
2821
+ content: input,
2822
+ uuid,
2823
+ permissionMode,
2824
+ isMeta: isMeta || undefined
2825
+ });
2826
+ return {
2827
+ messages: [userMessage, ...attachmentMessages],
2828
+ shouldQuery: true
2829
+ };
2830
+ }
2831
+
2832
+ // src/utils/processUserInput/processUserInput.ts
2833
+ async function processUserInput({
2834
+ input,
2835
+ preExpansionInput,
2836
+ mode,
2837
+ setToolJSX,
2838
+ context,
2839
+ pastedContents,
2840
+ ideSelection,
2841
+ messages,
2842
+ setUserInputOnProcessing,
2843
+ uuid,
2844
+ isAlreadyProcessing,
2845
+ querySource,
2846
+ canUseTool,
2847
+ skipSlashCommands,
2848
+ bridgeOrigin,
2849
+ isMeta,
2850
+ skipAttachments
2851
+ }) {
2852
+ const inputString = typeof input === "string" ? input : null;
2853
+ if (mode === "prompt" && inputString !== null && !isMeta) {
2854
+ setUserInputOnProcessing?.(inputString);
2855
+ }
2856
+ queryCheckpoint("query_process_user_input_base_start");
2857
+ const appState = context.getAppState();
2858
+ const result = await processUserInputBase(input, mode, setToolJSX, context, pastedContents, ideSelection, messages, uuid, isAlreadyProcessing, querySource, canUseTool, appState.toolPermissionContext.mode, skipSlashCommands, bridgeOrigin, isMeta, skipAttachments, preExpansionInput);
2859
+ queryCheckpoint("query_process_user_input_base_end");
2860
+ if (!result.shouldQuery) {
2861
+ return result;
2862
+ }
2863
+ queryCheckpoint("query_hooks_start");
2864
+ const inputMessage = getContentText(input) || "";
2865
+ for await (const hookResult of executeUserPromptSubmitHooks(inputMessage, appState.toolPermissionContext.mode, context, context.requestPrompt)) {
2866
+ if (hookResult.message?.type === "progress") {
2867
+ continue;
2868
+ }
2869
+ if (hookResult.blockingError) {
2870
+ const blockingMessage = getUserPromptSubmitHookBlockingMessage(hookResult.blockingError);
2871
+ return {
2872
+ messages: [
2873
+ createSystemMessage(`${blockingMessage}
2874
+
2875
+ Original prompt: ${input}`, "warning")
2876
+ ],
2877
+ shouldQuery: false,
2878
+ allowedTools: result.allowedTools
2879
+ };
2880
+ }
2881
+ if (hookResult.preventContinuation) {
2882
+ const message = hookResult.stopReason ? `Operation stopped by hook: ${hookResult.stopReason}` : "Operation stopped by hook";
2883
+ result.messages.push(createUserMessage({
2884
+ content: message
2885
+ }));
2886
+ result.shouldQuery = false;
2887
+ return result;
2888
+ }
2889
+ if (hookResult.additionalContexts && hookResult.additionalContexts.length > 0) {
2890
+ result.messages.push(createAttachmentMessage({
2891
+ type: "hook_additional_context",
2892
+ content: hookResult.additionalContexts.map(applyTruncation),
2893
+ hookName: "UserPromptSubmit",
2894
+ toolUseID: `hook-${randomUUID5()}`,
2895
+ hookEvent: "UserPromptSubmit"
2896
+ }));
2897
+ }
2898
+ if (hookResult.message) {
2899
+ switch (hookResult.message.attachment.type) {
2900
+ case "hook_success":
2901
+ if (!hookResult.message.attachment.content) {
2902
+ break;
2903
+ }
2904
+ result.messages.push({
2905
+ ...hookResult.message,
2906
+ attachment: {
2907
+ ...hookResult.message.attachment,
2908
+ content: applyTruncation(hookResult.message.attachment.content)
2909
+ }
2910
+ });
2911
+ break;
2912
+ default:
2913
+ result.messages.push(hookResult.message);
2914
+ break;
2915
+ }
2916
+ }
2917
+ }
2918
+ queryCheckpoint("query_hooks_end");
2919
+ return result;
2920
+ }
2921
+ var MAX_HOOK_OUTPUT_LENGTH = 1e4;
2922
+ function applyTruncation(content) {
2923
+ if (content.length > MAX_HOOK_OUTPUT_LENGTH) {
2924
+ return `${content.substring(0, MAX_HOOK_OUTPUT_LENGTH)}\u2026 [output truncated - exceeded ${MAX_HOOK_OUTPUT_LENGTH} characters]`;
2925
+ }
2926
+ return content;
2927
+ }
2928
+ async function processUserInputBase(input, mode, setToolJSX, context, pastedContents, ideSelection, messages, uuid, isAlreadyProcessing, querySource, canUseTool, permissionMode, skipSlashCommands, bridgeOrigin, isMeta, skipAttachments, preExpansionInput) {
2929
+ let inputString = null;
2930
+ let precedingInputBlocks = [];
2931
+ const imageMetadataTexts = [];
2932
+ let normalizedInput = input;
2933
+ if (typeof input === "string") {
2934
+ inputString = input;
2935
+ } else if (input.length > 0) {
2936
+ queryCheckpoint("query_image_processing_start");
2937
+ const processedBlocks = [];
2938
+ for (const block of input) {
2939
+ if (block.type === "image") {
2940
+ const resized = await maybeResizeAndDownsampleImageBlock(block);
2941
+ if (resized.dimensions) {
2942
+ const metadataText = createImageMetadataText(resized.dimensions);
2943
+ if (metadataText) {
2944
+ imageMetadataTexts.push(metadataText);
2945
+ }
2946
+ }
2947
+ processedBlocks.push(resized.block);
2948
+ } else {
2949
+ processedBlocks.push(block);
2950
+ }
2951
+ }
2952
+ normalizedInput = processedBlocks;
2953
+ queryCheckpoint("query_image_processing_end");
2954
+ const lastBlock = processedBlocks[processedBlocks.length - 1];
2955
+ if (lastBlock?.type === "text") {
2956
+ inputString = lastBlock.text;
2957
+ precedingInputBlocks = processedBlocks.slice(0, -1);
2958
+ } else {
2959
+ precedingInputBlocks = processedBlocks;
2960
+ }
2961
+ }
2962
+ if (inputString === null && mode !== "prompt") {
2963
+ throw new Error(`Mode: ${mode} requires a string input.`);
2964
+ }
2965
+ const imageContents = pastedContents ? Object.values(pastedContents).filter(isValidImagePaste) : [];
2966
+ const imagePasteIds = imageContents.map((img) => img.id);
2967
+ const storedImagePaths = pastedContents ? await storeImages(pastedContents) : new Map;
2968
+ queryCheckpoint("query_pasted_image_processing_start");
2969
+ const imageProcessingResults = await Promise.all(imageContents.map(async (pastedImage) => {
2970
+ const imageBlock = {
2971
+ type: "image",
2972
+ source: {
2973
+ type: "base64",
2974
+ media_type: pastedImage.mediaType || "image/png",
2975
+ data: pastedImage.content
2976
+ }
2977
+ };
2978
+ logEvent("tengu_pasted_image_resize_attempt", {
2979
+ original_size_bytes: pastedImage.content.length
2980
+ });
2981
+ const resized = await maybeResizeAndDownsampleImageBlock(imageBlock);
2982
+ return {
2983
+ resized,
2984
+ originalDimensions: pastedImage.dimensions,
2985
+ sourcePath: pastedImage.sourcePath ?? storedImagePaths.get(pastedImage.id)
2986
+ };
2987
+ }));
2988
+ const imageContentBlocks = [];
2989
+ for (const {
2990
+ resized,
2991
+ originalDimensions,
2992
+ sourcePath
2993
+ } of imageProcessingResults) {
2994
+ if (resized.dimensions) {
2995
+ const metadataText = createImageMetadataText(resized.dimensions, sourcePath);
2996
+ if (metadataText) {
2997
+ imageMetadataTexts.push(metadataText);
2998
+ }
2999
+ } else if (originalDimensions) {
3000
+ const metadataText = createImageMetadataText(originalDimensions, sourcePath);
3001
+ if (metadataText) {
3002
+ imageMetadataTexts.push(metadataText);
3003
+ }
3004
+ } else if (sourcePath) {
3005
+ imageMetadataTexts.push(`[Image source: ${sourcePath}]`);
3006
+ }
3007
+ imageContentBlocks.push(resized.block);
3008
+ }
3009
+ queryCheckpoint("query_pasted_image_processing_end");
3010
+ let effectiveSkipSlash = skipSlashCommands;
3011
+ if (bridgeOrigin && inputString !== null && inputString.startsWith("/")) {
3012
+ const parsed = parseSlashCommand(inputString);
3013
+ const cmd = parsed ? findCommand(parsed.commandName, context.options.commands) : undefined;
3014
+ if (cmd) {
3015
+ if (isBridgeSafeCommand(cmd)) {
3016
+ effectiveSkipSlash = false;
3017
+ } else {
3018
+ const msg = `/${getCommandName(cmd)} isn't available over Remote Control.`;
3019
+ return {
3020
+ messages: [
3021
+ createUserMessage({ content: inputString, uuid }),
3022
+ createCommandInputMessage(`<local-command-stdout>${msg}</local-command-stdout>`)
3023
+ ],
3024
+ shouldQuery: false,
3025
+ resultText: msg
3026
+ };
3027
+ }
3028
+ }
3029
+ }
3030
+ if (false) {}
3031
+ const shouldExtractAttachments = !skipAttachments && inputString !== null && (mode !== "prompt" || effectiveSkipSlash || !inputString.startsWith("/"));
3032
+ queryCheckpoint("query_attachment_loading_start");
3033
+ const attachmentMessages = shouldExtractAttachments ? await toArray(getAttachmentMessages(inputString, context, ideSelection ?? null, [], messages, querySource)) : [];
3034
+ queryCheckpoint("query_attachment_loading_end");
3035
+ if (inputString !== null && mode === "bash") {
3036
+ const { processBashCommand } = await import("./chunk-8wjnca8h.js");
3037
+ return addImageMetadataMessage(await processBashCommand(inputString, precedingInputBlocks, attachmentMessages, context, setToolJSX), imageMetadataTexts);
3038
+ }
3039
+ if (inputString !== null && !effectiveSkipSlash && inputString.startsWith("/")) {
3040
+ const { processSlashCommand } = await import("./chunk-ncnfzby5.js");
3041
+ const slashResult = await processSlashCommand(inputString, precedingInputBlocks, imageContentBlocks, attachmentMessages, context, setToolJSX, uuid, isAlreadyProcessing, canUseTool);
3042
+ return addImageMetadataMessage(slashResult, imageMetadataTexts);
3043
+ }
3044
+ if (inputString !== null && mode === "prompt") {
3045
+ const trimmedInput = inputString.trim();
3046
+ const agentMention = attachmentMessages.find((m) => m.attachment.type === "agent_mention");
3047
+ if (agentMention) {
3048
+ const agentMentionString = `@agent-${agentMention.attachment.agentType}`;
3049
+ const isSubagentOnly = trimmedInput === agentMentionString;
3050
+ const isPrefix = trimmedInput.startsWith(agentMentionString) && !isSubagentOnly;
3051
+ logEvent("tengu_subagent_at_mention", {
3052
+ is_subagent_only: isSubagentOnly,
3053
+ is_prefix: isPrefix
3054
+ });
3055
+ }
3056
+ }
3057
+ return addImageMetadataMessage(processTextPrompt(normalizedInput, imageContentBlocks, imagePasteIds, attachmentMessages, uuid, permissionMode, isMeta), imageMetadataTexts);
3058
+ }
3059
+ function addImageMetadataMessage(result, imageMetadataTexts) {
3060
+ if (imageMetadataTexts.length > 0) {
3061
+ result.messages.push(createUserMessage({
3062
+ content: imageMetadataTexts.map((text) => ({ type: "text", text })),
3063
+ isMeta: true
3064
+ }));
3065
+ }
3066
+ return result;
3067
+ }
3068
+
3069
+ // src/utils/plugins/reconciler.ts
3070
+ init_isEqual();
3071
+ init_state();
3072
+ init_debug();
3073
+ init_errors();
3074
+ init_file();
3075
+ init_git();
3076
+ init_log();
3077
+ init_marketplaceManager();
3078
+ init_schemas();
3079
+ import { isAbsolute, resolve } from "path";
3080
+ function diffMarketplaces(declared, materialized, opts) {
3081
+ const missing = [];
3082
+ const sourceChanged = [];
3083
+ const upToDate = [];
3084
+ for (const [name, intent] of Object.entries(declared)) {
3085
+ const state = materialized[name];
3086
+ const normalizedIntent = normalizeSource(intent.source, opts?.projectRoot);
3087
+ if (!state) {
3088
+ missing.push(name);
3089
+ } else if (intent.sourceIsFallback) {
3090
+ upToDate.push(name);
3091
+ } else if (!isEqual_default(normalizedIntent, state.source)) {
3092
+ sourceChanged.push({
3093
+ name,
3094
+ declaredSource: normalizedIntent,
3095
+ materializedSource: state.source
3096
+ });
3097
+ } else {
3098
+ upToDate.push(name);
3099
+ }
3100
+ }
3101
+ return { missing, sourceChanged, upToDate };
3102
+ }
3103
+ async function reconcileMarketplaces(opts) {
3104
+ const declared = getDeclaredMarketplaces();
3105
+ if (Object.keys(declared).length === 0) {
3106
+ return { installed: [], updated: [], failed: [], upToDate: [], skipped: [] };
3107
+ }
3108
+ let materialized;
3109
+ try {
3110
+ materialized = await loadKnownMarketplacesConfig();
3111
+ } catch (e) {
3112
+ logError(e);
3113
+ materialized = {};
3114
+ }
3115
+ const diff = diffMarketplaces(declared, materialized, {
3116
+ projectRoot: getOriginalCwd()
3117
+ });
3118
+ const work = [
3119
+ ...diff.missing.map((name) => ({
3120
+ name,
3121
+ source: normalizeSource(declared[name].source),
3122
+ action: "install"
3123
+ })),
3124
+ ...diff.sourceChanged.map(({ name, declaredSource }) => ({
3125
+ name,
3126
+ source: declaredSource,
3127
+ action: "update"
3128
+ }))
3129
+ ];
3130
+ const skipped = [];
3131
+ const toProcess = [];
3132
+ for (const item of work) {
3133
+ if (opts?.skip?.(item.name, item.source)) {
3134
+ skipped.push(item.name);
3135
+ continue;
3136
+ }
3137
+ if (item.action === "update" && isLocalMarketplaceSource(item.source) && !await pathExists(item.source.path)) {
3138
+ logForDebugging(`[reconcile] '${item.name}' declared path does not exist; keeping materialized entry`);
3139
+ skipped.push(item.name);
3140
+ continue;
3141
+ }
3142
+ toProcess.push(item);
3143
+ }
3144
+ if (toProcess.length === 0) {
3145
+ return {
3146
+ installed: [],
3147
+ updated: [],
3148
+ failed: [],
3149
+ upToDate: diff.upToDate,
3150
+ skipped
3151
+ };
3152
+ }
3153
+ logForDebugging(`[reconcile] ${toProcess.length} marketplace(s): ${toProcess.map((w) => `${w.name}(${w.action})`).join(", ")}`);
3154
+ const installed = [];
3155
+ const updated = [];
3156
+ const failed = [];
3157
+ for (let i = 0;i < toProcess.length; i++) {
3158
+ const { name, source, action } = toProcess[i];
3159
+ opts?.onProgress?.({
3160
+ type: "installing",
3161
+ name,
3162
+ action,
3163
+ index: i + 1,
3164
+ total: toProcess.length
3165
+ });
3166
+ try {
3167
+ const result = await addMarketplaceSource(source);
3168
+ if (action === "install")
3169
+ installed.push(name);
3170
+ else
3171
+ updated.push(name);
3172
+ opts?.onProgress?.({
3173
+ type: "installed",
3174
+ name,
3175
+ alreadyMaterialized: result.alreadyMaterialized
3176
+ });
3177
+ } catch (e) {
3178
+ const error = errorMessage(e);
3179
+ failed.push({ name, error });
3180
+ opts?.onProgress?.({ type: "failed", name, error });
3181
+ logError(e);
3182
+ }
3183
+ }
3184
+ return { installed, updated, failed, upToDate: diff.upToDate, skipped };
3185
+ }
3186
+ function normalizeSource(source, projectRoot) {
3187
+ if ((source.source === "directory" || source.source === "file") && !isAbsolute(source.path)) {
3188
+ const base = projectRoot ?? getOriginalCwd();
3189
+ const canonicalRoot = findCanonicalGitRoot(base);
3190
+ return {
3191
+ ...source,
3192
+ path: resolve(canonicalRoot ?? base, source.path)
3193
+ };
3194
+ }
3195
+ return source;
3196
+ }
3197
+
3198
+ export { extractInboundMessageFields, sdkCompatToolName, buildSystemInitMessage, MessageSelector, selectableUserMessagesFilter, messagesAfterAreOnlySynthetic, exports_MessageSelector, init_MessageSelector, findUltrareviewTriggerPositions, processUserInput, outputSchema, permissionPromptToolResultToPermissionDecision, ndjsonSafeStringify, StructuredIO, diffMarketplaces, reconcileMarketplaces, getCronJitterConfig, exports_cronJitterConfig, init_cronJitterConfig, createCronScheduler, exports_cronScheduler, init_cronScheduler };