@moberg_hr/work-tree 2.9.3 → 2.10.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 (360) hide show
  1. package/dist/{account-NG75VLRU.js → account-QSNXX5YV.js} +81 -98
  2. package/dist/account-QSNXX5YV.js.map +1 -0
  3. package/dist/{add-repo-EDU3QEYI.js → add-repo-YZ32MLZG.js} +32 -28
  4. package/dist/{add-repo-EDU3QEYI.js.map → add-repo-YZ32MLZG.js.map} +1 -1
  5. package/dist/{answer-MHOJ2J6S.js → answer-Y4T5X446.js} +16 -13
  6. package/dist/{answer-MHOJ2J6S.js.map → answer-Y4T5X446.js.map} +1 -1
  7. package/dist/{attach-37JOJ4C3.js → attach-XPYWYHDP.js} +25 -19
  8. package/dist/{attach-37JOJ4C3.js.map → attach-XPYWYHDP.js.map} +1 -1
  9. package/dist/bin.js +4 -4
  10. package/dist/{block-D5CAR53T.js → block-JVAGG5QA.js} +22 -13
  11. package/dist/block-JVAGG5QA.js.map +1 -0
  12. package/dist/{broadcast-LLYHUWXA.js → broadcast-FATIANHX.js} +11 -9
  13. package/dist/{broadcast-LLYHUWXA.js.map → broadcast-FATIANHX.js.map} +1 -1
  14. package/dist/{catchup-2SL3JGA7.js → catchup-OTI2KZG5.js} +17 -15
  15. package/dist/{catchup-2SL3JGA7.js.map → catchup-OTI2KZG5.js.map} +1 -1
  16. package/dist/{chunk-37XQIG7F.js → chunk-27LWL6QE.js} +111 -49
  17. package/dist/chunk-27LWL6QE.js.map +1 -0
  18. package/dist/chunk-2HHIDWHH.js +50 -0
  19. package/dist/chunk-2HHIDWHH.js.map +1 -0
  20. package/dist/{chunk-T7AFYEQ7.js → chunk-2K5TDJ7M.js} +5 -5
  21. package/dist/{chunk-2JNW2AQ2.js → chunk-2MAZV5KS.js} +17 -2
  22. package/dist/chunk-2MAZV5KS.js.map +1 -0
  23. package/dist/{chunk-S3FMTEFR.js → chunk-2VRZVUM7.js} +13 -6
  24. package/dist/chunk-2VRZVUM7.js.map +1 -0
  25. package/dist/{chunk-63VY4YJM.js → chunk-34E2LA3M.js} +34 -9
  26. package/dist/chunk-34E2LA3M.js.map +1 -0
  27. package/dist/{chunk-QL36KN7X.js → chunk-353ZINJ2.js} +3 -3
  28. package/dist/{chunk-5QGCF3PS.js → chunk-3BSFVKMK.js} +2 -2
  29. package/dist/{chunk-WTQ2QCAG.js → chunk-3S6L437Q.js} +4 -5
  30. package/dist/chunk-3S6L437Q.js.map +1 -0
  31. package/dist/{chunk-AAYWHIIT.js → chunk-3XG23PLG.js} +8 -55
  32. package/dist/chunk-3XG23PLG.js.map +1 -0
  33. package/dist/{chunk-RFINYWID.js → chunk-46XSWHCQ.js} +14 -5
  34. package/dist/{chunk-RFINYWID.js.map → chunk-46XSWHCQ.js.map} +1 -1
  35. package/dist/{chunk-J36ULZBO.js → chunk-4K4S53KX.js} +2 -2
  36. package/dist/{chunk-ZI2KXTKM.js → chunk-4O4VQQEA.js} +6 -10
  37. package/dist/chunk-4O4VQQEA.js.map +1 -0
  38. package/dist/chunk-4TTYEMOY.js +180 -0
  39. package/dist/chunk-4TTYEMOY.js.map +1 -0
  40. package/dist/{chunk-GRLKPVTP.js → chunk-5R5JEQW7.js} +55 -80
  41. package/dist/chunk-5R5JEQW7.js.map +1 -0
  42. package/dist/chunk-63ZLPXRL.js +199 -0
  43. package/dist/chunk-63ZLPXRL.js.map +1 -0
  44. package/dist/{chunk-QHTXLCG7.js → chunk-66VPQOVZ.js} +17 -14
  45. package/dist/chunk-66VPQOVZ.js.map +1 -0
  46. package/dist/{chunk-6FVYSW3E.js → chunk-6J6U7JXN.js} +20 -5
  47. package/dist/chunk-6J6U7JXN.js.map +1 -0
  48. package/dist/{chunk-P2HOLCBF.js → chunk-6UTH3A76.js} +18 -2
  49. package/dist/{chunk-P2HOLCBF.js.map → chunk-6UTH3A76.js.map} +1 -1
  50. package/dist/{chunk-HCVONKJI.js → chunk-6YMLYU5G.js} +15 -17
  51. package/dist/{chunk-HCVONKJI.js.map → chunk-6YMLYU5G.js.map} +1 -1
  52. package/dist/chunk-7E5XPDKX.js +22 -0
  53. package/dist/chunk-7E5XPDKX.js.map +1 -0
  54. package/dist/chunk-7QNVFVG6.js +196 -0
  55. package/dist/chunk-7QNVFVG6.js.map +1 -0
  56. package/dist/chunk-7S2NQRWL.js +9 -0
  57. package/dist/{chunk-NWIVXGSL.js.map → chunk-7S2NQRWL.js.map} +1 -1
  58. package/dist/{chunk-P4EQWC5W.js → chunk-ADIN3DTD.js} +2 -2
  59. package/dist/{chunk-IWJXFNM4.js → chunk-AHI2WVWP.js} +16 -24
  60. package/dist/chunk-AHI2WVWP.js.map +1 -0
  61. package/dist/{chunk-KUCMJHQW.js → chunk-AHYCZUPI.js} +2 -2
  62. package/dist/chunk-AQP6SCCJ.js +66 -0
  63. package/dist/chunk-AQP6SCCJ.js.map +1 -0
  64. package/dist/chunk-B5WDN63X.js +84 -0
  65. package/dist/chunk-B5WDN63X.js.map +1 -0
  66. package/dist/{chunk-26OVU2AE.js → chunk-BNKVENDF.js} +8 -8
  67. package/dist/chunk-DAKJTB6N.js +76 -0
  68. package/dist/chunk-DAKJTB6N.js.map +1 -0
  69. package/dist/{chunk-3N3UQEC4.js → chunk-DCCC7LEP.js} +4 -3
  70. package/dist/chunk-DCCC7LEP.js.map +1 -0
  71. package/dist/chunk-E67DOUVU.js +289 -0
  72. package/dist/chunk-E67DOUVU.js.map +1 -0
  73. package/dist/{chunk-6E2I2FBJ.js → chunk-E7WPTSHQ.js} +22 -22
  74. package/dist/chunk-EL3XL2OC.js +150 -0
  75. package/dist/chunk-EL3XL2OC.js.map +1 -0
  76. package/dist/{chunk-CLBQ7ZC4.js → chunk-F3PEUOTP.js} +3 -3
  77. package/dist/{chunk-ICJPVSRY.js → chunk-FKM67CZZ.js} +53 -51
  78. package/dist/chunk-FKM67CZZ.js.map +1 -0
  79. package/dist/{chunk-CCTALU3C.js → chunk-FMLE2WSN.js} +2 -2
  80. package/dist/{chunk-QSOEMCWQ.js → chunk-FSQJOZS4.js} +17 -10
  81. package/dist/chunk-FSQJOZS4.js.map +1 -0
  82. package/dist/chunk-FZHFD2AY.js +27 -0
  83. package/dist/chunk-FZHFD2AY.js.map +1 -0
  84. package/dist/{chunk-OTAZOIXK.js → chunk-GZGJQKQT.js} +2 -2
  85. package/dist/{chunk-5WM24P5N.js → chunk-I6MILNM5.js} +2 -2
  86. package/dist/chunk-I6MILNM5.js.map +1 -0
  87. package/dist/{chunk-S3BAD4IR.js → chunk-ICXUTMGH.js} +2 -2
  88. package/dist/{chunk-PRDRRU2B.js → chunk-IDQVTWLX.js} +5 -5
  89. package/dist/{chunk-3C3BKZ3H.js → chunk-IFQOOCT7.js} +8 -8
  90. package/dist/{chunk-TPSFJSO7.js → chunk-IKX3B26P.js} +13 -10
  91. package/dist/chunk-IKX3B26P.js.map +1 -0
  92. package/dist/{chunk-OMIMK3LB.js → chunk-IOHK45WE.js} +2 -2
  93. package/dist/{chunk-SG5LUMGE.js → chunk-JNBMANFM.js} +6 -3
  94. package/dist/chunk-JNBMANFM.js.map +1 -0
  95. package/dist/{chunk-QEVYCCKD.js → chunk-JNCKZ3OF.js} +12 -34
  96. package/dist/chunk-JNCKZ3OF.js.map +1 -0
  97. package/dist/{chunk-CMO5YUZR.js → chunk-JVBIWU7S.js} +4 -4
  98. package/dist/chunk-JVE2JFLV.js +15 -0
  99. package/dist/chunk-JVE2JFLV.js.map +1 -0
  100. package/dist/{chunk-MG5TTLYZ.js → chunk-KDO7D46L.js} +3 -3
  101. package/dist/{chunk-CYWI3ZW7.js → chunk-KL4YYV37.js} +4 -4
  102. package/dist/chunk-KSVYR4G2.js +47 -0
  103. package/dist/chunk-KSVYR4G2.js.map +1 -0
  104. package/dist/{chunk-RYNBBSLY.js → chunk-KWHHB737.js} +6 -8
  105. package/dist/chunk-KWHHB737.js.map +1 -0
  106. package/dist/chunk-L22AWXWA.js +29 -0
  107. package/dist/chunk-L22AWXWA.js.map +1 -0
  108. package/dist/{chunk-WXE7D44E.js → chunk-LJKF73JB.js} +8 -8
  109. package/dist/chunk-LJKF73JB.js.map +1 -0
  110. package/dist/{chunk-BSP2Z7B7.js → chunk-LKESANVD.js} +6 -6
  111. package/dist/{chunk-XVNRP7XE.js → chunk-LZZCJAJQ.js} +11 -11
  112. package/dist/{chunk-IPGH7TXJ.js → chunk-MM7344RC.js} +2 -2
  113. package/dist/{chunk-HMK3INUS.js → chunk-MQCDFSVF.js} +2 -2
  114. package/dist/{chunk-VJ7SVDED.js → chunk-MSJWQC7H.js} +6 -4
  115. package/dist/chunk-MSJWQC7H.js.map +1 -0
  116. package/dist/chunk-NWOCQVSL.js +307 -0
  117. package/dist/chunk-NWOCQVSL.js.map +1 -0
  118. package/dist/{chunk-RGUSVBGN.js → chunk-OCMNBOPX.js} +2 -2
  119. package/dist/{chunk-72IBYKIY.js → chunk-PCNNW63Z.js} +16 -5
  120. package/dist/chunk-PCNNW63Z.js.map +1 -0
  121. package/dist/chunk-PHGVVFTF.js +1603 -0
  122. package/dist/chunk-PHGVVFTF.js.map +1 -0
  123. package/dist/{chunk-4NITDMDH.js → chunk-PPZP7CA7.js} +9 -186
  124. package/dist/chunk-PPZP7CA7.js.map +1 -0
  125. package/dist/{chunk-X4AXKO3A.js → chunk-RGLIW45S.js} +2 -2
  126. package/dist/{chunk-P6BHOAQG.js → chunk-RHDZPV6C.js} +2 -2
  127. package/dist/{chunk-3GIH4WTA.js → chunk-RJUMLWXP.js} +109 -104
  128. package/dist/chunk-RJUMLWXP.js.map +1 -0
  129. package/dist/chunk-RQFHA5BM.js +1443 -0
  130. package/dist/chunk-RQFHA5BM.js.map +1 -0
  131. package/dist/chunk-S3CTXKSN.js +17 -0
  132. package/dist/chunk-S3CTXKSN.js.map +1 -0
  133. package/dist/chunk-SJBEIYLK.js +16 -0
  134. package/dist/chunk-SJBEIYLK.js.map +1 -0
  135. package/dist/chunk-TIG7NHVO.js +231 -0
  136. package/dist/chunk-TIG7NHVO.js.map +1 -0
  137. package/dist/{chunk-ATED7SAH.js → chunk-TKWUSJNQ.js} +36 -23
  138. package/dist/chunk-TKWUSJNQ.js.map +1 -0
  139. package/dist/{chunk-DQCUYCMX.js → chunk-UP2JTDBI.js} +3 -3
  140. package/dist/chunk-V4U5RGEG.js +59 -0
  141. package/dist/chunk-V4U5RGEG.js.map +1 -0
  142. package/dist/{chunk-HEPBANFJ.js → chunk-V7GCYL6A.js} +93 -196
  143. package/dist/chunk-V7GCYL6A.js.map +1 -0
  144. package/dist/{chunk-WC534PXU.js → chunk-VFH4SU3M.js} +34 -23
  145. package/dist/chunk-VFH4SU3M.js.map +1 -0
  146. package/dist/{chunk-KSUOVFO3.js → chunk-VV3NFLLP.js} +16 -9
  147. package/dist/chunk-VV3NFLLP.js.map +1 -0
  148. package/dist/{chunk-INQQGV2G.js → chunk-WKOJ7NXD.js} +4 -4
  149. package/dist/{chunk-7OUIZ2YQ.js → chunk-WVV54JP3.js} +56 -58
  150. package/dist/chunk-WVV54JP3.js.map +1 -0
  151. package/dist/chunk-WY7QZ2P7.js +71 -0
  152. package/dist/chunk-WY7QZ2P7.js.map +1 -0
  153. package/dist/{chunk-YYBXQBW2.js → chunk-Y7T73SAP.js} +13 -3
  154. package/dist/chunk-Y7T73SAP.js.map +1 -0
  155. package/dist/{chunk-WXMWZRBH.js → chunk-Z6ZMWFNV.js} +25 -7
  156. package/dist/chunk-Z6ZMWFNV.js.map +1 -0
  157. package/dist/{chunk-VUAVPBFR.js → chunk-Z7I6DQAR.js} +42 -57
  158. package/dist/chunk-Z7I6DQAR.js.map +1 -0
  159. package/dist/{chunk-GNGXYXBC.js → chunk-ZRATYLBB.js} +2 -2
  160. package/dist/{cleanup-5PSLKZLF.js → cleanup-M5TY4FQS.js} +46 -34
  161. package/dist/{cleanup-5PSLKZLF.js.map → cleanup-M5TY4FQS.js.map} +1 -1
  162. package/dist/cli-446A536X.js +19 -0
  163. package/dist/{completion-MXX5TRIV.js → completion-IAH7WRKJ.js} +3 -2
  164. package/dist/{completion-MXX5TRIV.js.map → completion-IAH7WRKJ.js.map} +1 -1
  165. package/dist/{config-6MSITKGB.js → config-JLORGUXN.js} +16 -13
  166. package/dist/{config-6MSITKGB.js.map → config-JLORGUXN.js.map} +1 -1
  167. package/dist/{diff-Q7MV6YGJ.js → diff-4O5HXNZ7.js} +23 -20
  168. package/dist/{diff-Q7MV6YGJ.js.map → diff-4O5HXNZ7.js.map} +1 -1
  169. package/dist/{digest-KUMVYXKZ.js → digest-IAAZXJCC.js} +13 -11
  170. package/dist/{digest-KUMVYXKZ.js.map → digest-IAAZXJCC.js.map} +1 -1
  171. package/dist/{fork-OFENISEM.js → fork-ULJYPEKY.js} +41 -28
  172. package/dist/{fork-OFENISEM.js.map → fork-ULJYPEKY.js.map} +1 -1
  173. package/dist/{history-5WKRWARZ.js → history-JFZF22M7.js} +12 -10
  174. package/dist/{hook-ARS32DG2.js → hook-UYOIQVJ7.js} +54 -20
  175. package/dist/hook-UYOIQVJ7.js.map +1 -0
  176. package/dist/{hydrate-LCT6DVB3.js → hydrate-DROI4RJ7.js} +14 -12
  177. package/dist/{hydrate-LCT6DVB3.js.map → hydrate-DROI4RJ7.js.map} +1 -1
  178. package/dist/{init-FJKPEY5N.js → init-FF75CQM7.js} +27 -19
  179. package/dist/{init-FJKPEY5N.js.map → init-FF75CQM7.js.map} +1 -1
  180. package/dist/install-skills-XSAHNBYD.js +22 -0
  181. package/dist/install-skills-bin.js +8 -6
  182. package/dist/install-skills-bin.js.map +1 -1
  183. package/dist/{list-GTKP5FAW.js → list-5FEHBP6N.js} +15 -13
  184. package/dist/{list-GTKP5FAW.js.map → list-5FEHBP6N.js.map} +1 -1
  185. package/dist/{move-GOCLEFGZ.js → move-422L6PPI.js} +33 -24
  186. package/dist/{move-GOCLEFGZ.js.map → move-422L6PPI.js.map} +1 -1
  187. package/dist/{note-B7TQBXQF.js → note-AAXPD5VA.js} +14 -12
  188. package/dist/{note-B7TQBXQF.js.map → note-AAXPD5VA.js.map} +1 -1
  189. package/dist/{overlaps-UKQHIJMU.js → overlaps-WPNUYOFF.js} +21 -11
  190. package/dist/{overlaps-UKQHIJMU.js.map → overlaps-WPNUYOFF.js.map} +1 -1
  191. package/dist/{pin-UZZCDK7M.js → pin-QXPF23BB.js} +14 -12
  192. package/dist/{pin-UZZCDK7M.js.map → pin-QXPF23BB.js.map} +1 -1
  193. package/dist/{pr-NU2ME2XW.js → pr-QLGXPKPQ.js} +46 -21
  194. package/dist/pr-QLGXPKPQ.js.map +1 -0
  195. package/dist/{prune-IZGEYTSB.js → prune-GRHKRRVT.js} +44 -32
  196. package/dist/{prune-IZGEYTSB.js.map → prune-GRHKRRVT.js.map} +1 -1
  197. package/dist/{pty-host-AWDIKPQN.js → pty-host-XDDXA4SL.js} +103 -39
  198. package/dist/pty-host-XDDXA4SL.js.map +1 -0
  199. package/dist/{read-U6GBGA5E.js → read-YWKD2DGP.js} +13 -11
  200. package/dist/{read-U6GBGA5E.js.map → read-YWKD2DGP.js.map} +1 -1
  201. package/dist/{recent-2DUMLUDG.js → recent-SI5BDVVH.js} +35 -26
  202. package/dist/recent-SI5BDVVH.js.map +1 -0
  203. package/dist/{remove-OXUP4O33.js → remove-RXXCHY44.js} +48 -36
  204. package/dist/{remove-OXUP4O33.js.map → remove-RXXCHY44.js.map} +1 -1
  205. package/dist/{restart-QEW4DJC3.js → restart-CPNDEXU6.js} +17 -15
  206. package/dist/{restart-QEW4DJC3.js.map → restart-CPNDEXU6.js.map} +1 -1
  207. package/dist/{resume-K45IT4QO.js → resume-BLP4TTJK.js} +35 -20
  208. package/dist/resume-BLP4TTJK.js.map +1 -0
  209. package/dist/review-now-ADWZPELT.js +22 -0
  210. package/dist/review-now-ADWZPELT.js.map +1 -0
  211. package/dist/{run-42LORGPS.js → run-JFCDJ3EV.js} +21 -15
  212. package/dist/run-JFCDJ3EV.js.map +1 -0
  213. package/dist/{screen-2TLIUH3G.js → screen-LBOPAUXV.js} +14 -12
  214. package/dist/{screen-2TLIUH3G.js.map → screen-LBOPAUXV.js.map} +1 -1
  215. package/dist/{search-7E4B2KX6.js → search-AMEGRH24.js} +10 -8
  216. package/dist/{search-7E4B2KX6.js.map → search-AMEGRH24.js.map} +1 -1
  217. package/dist/{section-OVA5VD7L.js → section-73Z34PVE.js} +14 -12
  218. package/dist/{section-OVA5VD7L.js.map → section-73Z34PVE.js.map} +1 -1
  219. package/dist/{send-BJY5CYLO.js → send-IZBSEET5.js} +19 -16
  220. package/dist/send-IZBSEET5.js.map +1 -0
  221. package/dist/{sessions-4A24ZORW.js → sessions-WVQ2U2W4.js} +58 -23
  222. package/dist/sessions-WVQ2U2W4.js.map +1 -0
  223. package/dist/{snooze-WIVKB3GH.js → snooze-7IBHY5MY.js} +13 -11
  224. package/dist/{snooze-WIVKB3GH.js.map → snooze-7IBHY5MY.js.map} +1 -1
  225. package/dist/{start-G6GR533S.js → start-AU62TW6M.js} +14 -12
  226. package/dist/{start-G6GR533S.js.map → start-AU62TW6M.js.map} +1 -1
  227. package/dist/{state-S3DGLT4J.js → state-IZV7DAPL.js} +8 -5
  228. package/dist/state-IZV7DAPL.js.map +1 -0
  229. package/dist/{status-BTAWY6JQ.js → status-Z7OMNYZX.js} +38 -13
  230. package/dist/status-Z7OMNYZX.js.map +1 -0
  231. package/dist/{statusline-WLXEU5DM.js → statusline-VJFY7ZAB.js} +12 -11
  232. package/dist/{statusline-WLXEU5DM.js.map → statusline-VJFY7ZAB.js.map} +1 -1
  233. package/dist/{statusline-hook-OVWHHFBV.js → statusline-hook-JA7MNE5H.js} +4 -3
  234. package/dist/{statusline-hook-OVWHHFBV.js.map → statusline-hook-JA7MNE5H.js.map} +1 -1
  235. package/dist/{stop-FN6EPFJ4.js → stop-PWNXSFBD.js} +14 -12
  236. package/dist/{stop-FN6EPFJ4.js.map → stop-PWNXSFBD.js.map} +1 -1
  237. package/dist/{sync-T3BSHX6Q.js → sync-2BTZVDDG.js} +44 -32
  238. package/dist/{sync-T3BSHX6Q.js.map → sync-2BTZVDDG.js.map} +1 -1
  239. package/dist/{time-5CH5O5MZ.js → time-CTCIAXIY.js} +15 -13
  240. package/dist/{time-5CH5O5MZ.js.map → time-CTCIAXIY.js.map} +1 -1
  241. package/dist/{time-actions-XEUQ3UF7.js → time-actions-UYBOXET6.js} +5 -4
  242. package/dist/{timesheet-FMQKPS5S.js → timesheet-BUFQ34FC.js} +24 -15
  243. package/dist/{timesheet-FMQKPS5S.js.map → timesheet-BUFQ34FC.js.map} +1 -1
  244. package/dist/{todo-23COLGR2.js → todo-2R7VID57.js} +4 -4
  245. package/dist/{tree-T33VU473.js → tree-LQDPAXQA.js} +65 -45
  246. package/dist/tree-LQDPAXQA.js.map +1 -0
  247. package/dist/{update-PJRSKQZ2.js → update-2IYJHY7H.js} +24 -14
  248. package/dist/{update-PJRSKQZ2.js.map → update-2IYJHY7H.js.map} +1 -1
  249. package/dist/{usage-TL66LWO4.js → usage-IR5GNF4R.js} +13 -11
  250. package/dist/{usage-TL66LWO4.js.map → usage-IR5GNF4R.js.map} +1 -1
  251. package/dist/version-ONEI52TI.js +115 -0
  252. package/dist/version-ONEI52TI.js.map +1 -0
  253. package/dist/{wait-YIEJO6YM.js → wait-6DH34L53.js} +16 -13
  254. package/dist/{wait-YIEJO6YM.js.map → wait-6DH34L53.js.map} +1 -1
  255. package/dist/wd-bin.js +6 -6
  256. package/dist/web/assets/{PtyView-DnDd6jLI.js → PtyView-kBcAOwHr.js} +2 -2
  257. package/dist/web/assets/{PtyView-DnDd6jLI.js.map → PtyView-kBcAOwHr.js.map} +1 -1
  258. package/dist/web/assets/index-BgfR3N99.js +124 -0
  259. package/dist/web/assets/index-BgfR3N99.js.map +1 -0
  260. package/dist/web/assets/index-CKpHjII8.css +1 -0
  261. package/dist/web/index.html +2 -2
  262. package/dist/{web-IYUNJMQD.js → web-RIHGV7YY.js} +2786 -451
  263. package/dist/web-RIHGV7YY.js.map +1 -0
  264. package/npm-shrinkwrap.json +2 -2
  265. package/package.json +1 -1
  266. package/plugins/work-tree/skills/wd-review/SKILL.md +1 -1
  267. package/plugins/work-tree/skills/work-sessions/SKILL.md +2 -2
  268. package/dist/account-NG75VLRU.js.map +0 -1
  269. package/dist/block-D5CAR53T.js.map +0 -1
  270. package/dist/chunk-2JNW2AQ2.js.map +0 -1
  271. package/dist/chunk-37XQIG7F.js.map +0 -1
  272. package/dist/chunk-3GIH4WTA.js.map +0 -1
  273. package/dist/chunk-3N3UQEC4.js.map +0 -1
  274. package/dist/chunk-4NITDMDH.js.map +0 -1
  275. package/dist/chunk-5WM24P5N.js.map +0 -1
  276. package/dist/chunk-63VY4YJM.js.map +0 -1
  277. package/dist/chunk-6FVYSW3E.js.map +0 -1
  278. package/dist/chunk-72IBYKIY.js.map +0 -1
  279. package/dist/chunk-7OUIZ2YQ.js.map +0 -1
  280. package/dist/chunk-AAYWHIIT.js.map +0 -1
  281. package/dist/chunk-ATED7SAH.js.map +0 -1
  282. package/dist/chunk-GRLKPVTP.js.map +0 -1
  283. package/dist/chunk-HEPBANFJ.js.map +0 -1
  284. package/dist/chunk-ICJPVSRY.js.map +0 -1
  285. package/dist/chunk-IWJXFNM4.js.map +0 -1
  286. package/dist/chunk-KSUOVFO3.js.map +0 -1
  287. package/dist/chunk-NWIVXGSL.js +0 -9
  288. package/dist/chunk-PTWVOT7A.js +0 -551
  289. package/dist/chunk-PTWVOT7A.js.map +0 -1
  290. package/dist/chunk-QEVYCCKD.js.map +0 -1
  291. package/dist/chunk-QHTXLCG7.js.map +0 -1
  292. package/dist/chunk-QSOEMCWQ.js.map +0 -1
  293. package/dist/chunk-RCYI7SRA.js +0 -15
  294. package/dist/chunk-RCYI7SRA.js.map +0 -1
  295. package/dist/chunk-RYNBBSLY.js.map +0 -1
  296. package/dist/chunk-S3FMTEFR.js.map +0 -1
  297. package/dist/chunk-SG5LUMGE.js.map +0 -1
  298. package/dist/chunk-TPSFJSO7.js.map +0 -1
  299. package/dist/chunk-VJ7SVDED.js.map +0 -1
  300. package/dist/chunk-VTLDYH3C.js +0 -227
  301. package/dist/chunk-VTLDYH3C.js.map +0 -1
  302. package/dist/chunk-VUAVPBFR.js.map +0 -1
  303. package/dist/chunk-WC534PXU.js.map +0 -1
  304. package/dist/chunk-WTQ2QCAG.js.map +0 -1
  305. package/dist/chunk-WXE7D44E.js.map +0 -1
  306. package/dist/chunk-WXMWZRBH.js.map +0 -1
  307. package/dist/chunk-YYBXQBW2.js.map +0 -1
  308. package/dist/chunk-ZDMJPEBO.js +0 -31
  309. package/dist/chunk-ZDMJPEBO.js.map +0 -1
  310. package/dist/chunk-ZI2KXTKM.js.map +0 -1
  311. package/dist/cli-AF7636FA.js +0 -19
  312. package/dist/hook-ARS32DG2.js.map +0 -1
  313. package/dist/install-skills-UYAFVJBA.js +0 -20
  314. package/dist/pr-NU2ME2XW.js.map +0 -1
  315. package/dist/pty-host-AWDIKPQN.js.map +0 -1
  316. package/dist/recent-2DUMLUDG.js.map +0 -1
  317. package/dist/resume-K45IT4QO.js.map +0 -1
  318. package/dist/run-42LORGPS.js.map +0 -1
  319. package/dist/send-BJY5CYLO.js.map +0 -1
  320. package/dist/sessions-4A24ZORW.js.map +0 -1
  321. package/dist/state-S3DGLT4J.js.map +0 -1
  322. package/dist/status-BTAWY6JQ.js.map +0 -1
  323. package/dist/tree-T33VU473.js.map +0 -1
  324. package/dist/web/assets/index-DxozAoUO.css +0 -1
  325. package/dist/web/assets/index-InmdAx6g.js +0 -120
  326. package/dist/web/assets/index-InmdAx6g.js.map +0 -1
  327. package/dist/web-IYUNJMQD.js.map +0 -1
  328. /package/dist/{chunk-T7AFYEQ7.js.map → chunk-2K5TDJ7M.js.map} +0 -0
  329. /package/dist/{chunk-QL36KN7X.js.map → chunk-353ZINJ2.js.map} +0 -0
  330. /package/dist/{chunk-5QGCF3PS.js.map → chunk-3BSFVKMK.js.map} +0 -0
  331. /package/dist/{chunk-J36ULZBO.js.map → chunk-4K4S53KX.js.map} +0 -0
  332. /package/dist/{chunk-P4EQWC5W.js.map → chunk-ADIN3DTD.js.map} +0 -0
  333. /package/dist/{chunk-KUCMJHQW.js.map → chunk-AHYCZUPI.js.map} +0 -0
  334. /package/dist/{chunk-26OVU2AE.js.map → chunk-BNKVENDF.js.map} +0 -0
  335. /package/dist/{chunk-6E2I2FBJ.js.map → chunk-E7WPTSHQ.js.map} +0 -0
  336. /package/dist/{chunk-CLBQ7ZC4.js.map → chunk-F3PEUOTP.js.map} +0 -0
  337. /package/dist/{chunk-CCTALU3C.js.map → chunk-FMLE2WSN.js.map} +0 -0
  338. /package/dist/{chunk-OTAZOIXK.js.map → chunk-GZGJQKQT.js.map} +0 -0
  339. /package/dist/{chunk-S3BAD4IR.js.map → chunk-ICXUTMGH.js.map} +0 -0
  340. /package/dist/{chunk-PRDRRU2B.js.map → chunk-IDQVTWLX.js.map} +0 -0
  341. /package/dist/{chunk-3C3BKZ3H.js.map → chunk-IFQOOCT7.js.map} +0 -0
  342. /package/dist/{chunk-OMIMK3LB.js.map → chunk-IOHK45WE.js.map} +0 -0
  343. /package/dist/{chunk-CMO5YUZR.js.map → chunk-JVBIWU7S.js.map} +0 -0
  344. /package/dist/{chunk-MG5TTLYZ.js.map → chunk-KDO7D46L.js.map} +0 -0
  345. /package/dist/{chunk-CYWI3ZW7.js.map → chunk-KL4YYV37.js.map} +0 -0
  346. /package/dist/{chunk-BSP2Z7B7.js.map → chunk-LKESANVD.js.map} +0 -0
  347. /package/dist/{chunk-XVNRP7XE.js.map → chunk-LZZCJAJQ.js.map} +0 -0
  348. /package/dist/{chunk-IPGH7TXJ.js.map → chunk-MM7344RC.js.map} +0 -0
  349. /package/dist/{chunk-HMK3INUS.js.map → chunk-MQCDFSVF.js.map} +0 -0
  350. /package/dist/{chunk-RGUSVBGN.js.map → chunk-OCMNBOPX.js.map} +0 -0
  351. /package/dist/{chunk-X4AXKO3A.js.map → chunk-RGLIW45S.js.map} +0 -0
  352. /package/dist/{chunk-P6BHOAQG.js.map → chunk-RHDZPV6C.js.map} +0 -0
  353. /package/dist/{chunk-DQCUYCMX.js.map → chunk-UP2JTDBI.js.map} +0 -0
  354. /package/dist/{chunk-INQQGV2G.js.map → chunk-WKOJ7NXD.js.map} +0 -0
  355. /package/dist/{chunk-GNGXYXBC.js.map → chunk-ZRATYLBB.js.map} +0 -0
  356. /package/dist/{cli-AF7636FA.js.map → cli-446A536X.js.map} +0 -0
  357. /package/dist/{history-5WKRWARZ.js.map → history-JFZF22M7.js.map} +0 -0
  358. /package/dist/{install-skills-UYAFVJBA.js.map → install-skills-XSAHNBYD.js.map} +0 -0
  359. /package/dist/{time-actions-XEUQ3UF7.js.map → time-actions-UYBOXET6.js.map} +0 -0
  360. /package/dist/{todo-23COLGR2.js.map → todo-2R7VID57.js.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/pty/output-status.ts","../src/core/pty/pty-pool.ts","../src/core/sessions/web-state.ts"],"sourcesContent":["import type { SessionAttention } from '../api-types.js';\n\n/**\n * A status for a session whose tool isn't Claude Code (config `aiCommand`,\n * e.g. opencode): no hooks report its turns, so the PTY host's \"last printed\n * anything\" stands in — a working agent redraws its spinner, an idle one\n * prints nothing. Working while it printed in the last `OUTPUT_WORKING_MS`,\n * idle after; never \"done, unseen\" or \"needs input\" (output can't tell a\n * finished turn from a question). Pure.\n */\n\nexport const OUTPUT_WORKING_MS = 10_000;\n\nexport interface PtyOutput {\n /** The tool's binary (the host's spawn spec). */\n tool?: string;\n /** When it last printed (ISO). */\n lastOutputAt?: string;\n startedAt: string;\n}\n\nexport function statusFromOutput(p: PtyOutput, now: number): SessionAttention | null {\n if (!p.tool || p.tool === 'claude' || !p.lastOutputAt) return null;\n const at = Date.parse(p.lastOutputAt);\n if (!Number.isFinite(at)) return null;\n const working = now - at < OUTPUT_WORKING_MS;\n return {\n state: working ? 'working' : 'idle',\n seen: true,\n since: p.lastOutputAt,\n updatedAt: p.lastOutputAt,\n stale: false,\n summary: `${working ? 'Printing' : 'Quiet'} — from its terminal output (${p.tool} has no status hooks)`,\n };\n}\n","import path from 'node:path';\nimport type { AgentAdapter } from '../agents/types.js';\nimport { agentFor, agentSettings, assistantAgent } from '../agents/index.js';\nimport { statusFromOutput, type PtyOutput } from './output-status.js';\nimport type { SessionAttention } from '../api-types.js';\nimport type { HostBeat } from './host-health.js';\nimport { PtyHostBusyError } from './pty-host-client.js';\nimport { noClaudeBecause } from '../archive/archiving.js';\nimport { findSession, sessionIdFor } from '../sessions/web-state.js';\nimport type { WorktreeSession } from '../sessions/history.js';\nimport { hostStartLockPath, type SpawnSpec, type HostInfo, type PtyInfo } from './pty-host-protocol.js';\nimport { dbPtySessions } from './pty-sessions-file.js';\nimport { ensureFile, withFileLock } from '../platform/fs-safe.js';\nimport { forgetPersistedSession } from './pty-sessions-file.js';\nimport { loadConfig } from '../platform/config.js';\nimport { hasEnvDelta, type EnvDelta } from '../platform/env-delta.js';\nimport { ensureHost, findHost, PtyHostClient, findHostPatient, PtyHostVersionError } from './pty-host-client.js';\nimport { logSwallowed, swallow } from '../platform/best-effort.js';\nimport { ASSISTANT_ID, prepareAssistantDir } from '../agents/assistant.js';\n\n/**\n * `work web`'s view of the Claude PTYs. The PTYs themselves live in the\n * PTY host (`work pty-host`, see core/pty-host.ts), a separate long-lived\n * process — so restarting or rebuilding `work web` never kills an agent,\n * and a real terminal (`work attach`) can share the same session.\n *\n * This module resolves a dashboard session to a spawn spec, asks the host\n * to spawn it on first attach, and keeps a small cache of which sessions\n * have a live PTY for the synchronous badge path (`peekPty`).\n */\n\nlet workBin = process.argv[1] ?? '';\n/** Whether this server may start the PTY host when none runs (not the dev server: see configurePtyPool). */\nlet mayStartHost = true;\nlet client: PtyHostClient | null = null;\nlet live = new Set<string>();\n/** The pids of those PTYs' processes (the Claudes the app runs). */\nlet livePids = new Set<number>();\n/** Each live PTY's tool and last output (for output-status.ts). */\nlet outputs = new Map<string, PtyOutput & { pid: number }>();\nlet refreshTimer: NodeJS.Timeout | null = null;\n/** The heartbeat (host-health.ts): each list request is one. */\nconst beat: HostBeat = { known: false, lastOkAt: null, latencyMs: null, lastError: null, hostVersion: null };\n\n/** How the host answered lately (for GET /api/pty-host/health). */\nexport function hostBeat(): HostBeat {\n return { ...beat };\n}\nconst REFRESH_MS = 2000;\n\n/** Called by `work web` at startup with the resolved `work` binary path,\n * which is what the host is spawned from. */\nexport function configurePtyPool(opts: { workBin: string; startHost?: boolean }): void {\n workBin = opts.workBin;\n // The dev server (`work web --dev`) uses the host that runs and never starts one: started\n // from a checkout's build, the long-lived host that owns every Claude would outlive it,\n // and the installed work would become a client of the checkout's code.\n mayStartHost = opts.startHost ?? true;\n}\n\n/** The `work` binary path, for routes that launch `work attach`. */\nexport function getWorkBin(): string {\n return workBin;\n}\n\nasync function getClient(spawnIfMissing: boolean): Promise<PtyHostClient | null> {\n if (client) {\n // Cheap liveness re-check happens in refresh(); a dead host surfaces\n // as a failed call, which resets `client` below.\n return client;\n }\n const info = spawnIfMissing && mayStartHost ? await ensureHost(workBin) : await findHost();\n if (!info && spawnIfMissing && !mayStartHost)\n throw new Error(\n \"No PTY host is running, and the dev server doesn't start one: start the installed work (its app or `work web`) first.\",\n );\n if (!info) return null;\n client = new PtyHostClient(info);\n startRefresh();\n return client;\n}\n\nasync function refresh(): Promise<void> {\n const t0 = Date.now();\n try {\n const c = await getClient(false);\n if (!c) {\n beat.known = false;\n beat.hostVersion = null; // gone: the next host says its own\n live = new Set();\n livePids = new Set();\n outputs = new Map();\n return;\n }\n beat.known = true;\n const ptys = await c.list();\n beat.lastOkAt = Date.now();\n beat.latencyMs = beat.lastOkAt - t0;\n beat.lastError = null;\n // Asked once per host (the client keeps it): the release it runs, to say when it's older than this work.\n beat.hostVersion = await c.workVersion();\n live = new Set(ptys.filter((p) => !p.exited).map((p) => p.id));\n livePids = new Set(ptys.filter((p) => !p.exited).map((p) => p.pid));\n outputs = new Map(\n ptys.filter((p) => !p.exited).map((p) => [p.id, { tool: p.tool, lastOutputAt: p.lastOutputAt, startedAt: p.startedAt, pid: p.pid }]),\n );\n } catch (err) {\n // Host went away (or was restarted on a new port) — rediscover next tick.\n // A busy host is still a host (it is there, just not answering).\n beat.known = beat.known || err instanceof PtyHostBusyError;\n beat.lastError = (err as Error).message;\n client = null;\n beat.hostVersion = null;\n live = new Set();\n livePids = new Set();\n outputs = new Map();\n }\n}\n\nfunction startRefresh(): void {\n if (refreshTimer) return;\n refreshTimer = setInterval(() => void refresh(), REFRESH_MS);\n refreshTimer.unref?.();\n}\n\n/** Connect to an already-running host at `work web` startup so badges for\n * PTYs that survived a web restart show immediately. Never spawns. */\n/** Re-read the host's PTY list now (the periodic refresh can be seconds old,\n * or not have run at all right after `work web` started). */\nexport async function syncPtyPool(): Promise<void> {\n await refresh();\n}\n\nexport async function initPtyPool(): Promise<void> {\n await refresh().catch(() => {});\n startRefresh();\n}\n\n/**\n * After a reboot (or a host crash) nothing is running but\n * `pty-sessions.json` still lists the sessions that were live. Starting the\n * host restores them; do that when there's something to restore, so\n * reopening `work web` picks up where you left off. Returns how many\n * sessions the host will bring back (0 = nothing to do).\n */\nexport async function resumePersistedSessions(): Promise<number> {\n let count: number;\n try {\n count = Object.keys(dbPtySessions.read()).length;\n } catch {\n return 0;\n }\n if (count === 0) return 0;\n if (await findHost().catch(() => true)) return 0; // already running\n await getClient(true);\n await refresh();\n return count;\n}\n\n/**\n * Where Claude runs for a session — the same directory `work tree` launches\n * in: the worktree for a single repo, the group root (parent of the\n * sub-repos) for a group.\n */\nexport { ASSISTANT_ID };\n\n/** The assistant runs config `assistantAgent` (Claude Code by default), in its folder written for that agent. */\nexport function assistantSpec(): { cwd: string; tool: ReturnType<AgentAdapter['launch']['tool']>; agentEnv?: EnvDelta } {\n const settings = agentSettings();\n const agent = assistantAgent(settings);\n // Work's own session, not any session's: the configured default account (`launch.env(null)`).\n const agentEnv = agent.launch.env?.(null);\n return { cwd: prepareAssistantDir(agent), tool: agent.launch.tool(settings), ...(hasEnvDelta(agentEnv) ? { agentEnv } : {}) };\n}\n\nexport function spawnSpecFor(session: WorktreeSession): SpawnSpec | null {\n const first = session.paths[0];\n if (!first) return null;\n const cwd = session.isGroup ? path.dirname(first) : first;\n const config = loadConfig();\n const launch = agentFor(config, session).launch;\n // The session's account: its agent's folder env, applied by the host over whatever environment it starts with.\n const agentEnv = launch.env?.(session);\n return { cwd, tool: launch.tool(config), port: session.port, ...(hasEnvDelta(agentEnv) ? { agentEnv } : {}) };\n}\n\n/**\n * Ensure a live PTY exists for the session (spawning Claude in the host if\n * needed) and return the host WebSocket URL to attach to. Null for an\n * unknown session.\n */\nexport async function ensurePty(sessionId: string, extra: { initialPrompt?: string } = {}): Promise<string | null> {\n // The dashboard assistant (Ctrl+K) is not a worktree: it runs in its own\n // folder, which is (re)written first (assistant.ts).\n const session = sessionId === ASSISTANT_ID ? null : findSession(sessionId);\n // Not for a session being archived, or archived: its Claude was stopped on\n // purpose (a Terminal tab still open on it reconnects and would start it).\n const refused = sessionId === ASSISTANT_ID ? null : noClaudeBecause(session, sessionId);\n if (refused) throw new Error(refused);\n const base = sessionId === ASSISTANT_ID ? assistantSpec() : session ? spawnSpecFor(session) : null;\n if (!base) return null;\n // The first prompt only applies to a fresh spawn (the host ignores the\n // spec when the session's PTY is already running).\n const spec = extra.initialPrompt ? { ...base, initialPrompt: extra.initialPrompt } : base;\n\n let c = await getClient(true);\n if (!c) return null;\n // A host from before accounts would start it on its own environment — another account than the session's.\n if (setsEnv(spec.agentEnv) && !(await hostTakesAgentEnv(c)) && !(await runsIn(c, sessionId))) throw new Error(OLD_HOST_ACCOUNTS);\n try {\n await c.spawn(sessionId, spec);\n } catch (err) {\n // Stale client (host restarted on a new port) — retry once, fresh.\n client = null;\n c = await getClient(true);\n if (!c) throw err;\n await c.spawn(sessionId, spec);\n }\n live.add(sessionId);\n return c.attachUrl(sessionId);\n}\n\n/** Side-effect-free check: does an active (non-exited) PTY exist for this\n * session? Served from the refresh cache — used by session-meta for the\n * \"running/idle\" badge, which must stay synchronous. */\n/** Every PTY in the host, fresh (never starts a host; [] without one). */\nexport async function listHostPtys(): Promise<PtyInfo[]> {\n const c = await getClient(false);\n return c ? c.list() : [];\n}\n\n/** Pids of the Claudes running in the PTY host (from the refresh cache). */\nexport function ptyPids(): ReadonlySet<number> {\n return livePids;\n}\n\n/** A status from its terminal output, for a session whose tool has no hooks (output-status.ts); null for Claude or no PTY. */\nexport function outputStatus(sessionId: string, now = Date.now()): SessionAttention | null {\n const o = outputs.get(sessionId);\n return o ? statusFromOutput(o, now) : null;\n}\n\n/** When a session's terminal last printed (ms, from the refresh cache); null with no PTY or a host that doesn't say. */\nexport function ptyLastOutputMs(sessionId: string): number | null {\n const at = outputs.get(sessionId)?.lastOutputAt;\n const ms = at ? Date.parse(at) : NaN;\n return Number.isFinite(ms) ? ms : null;\n}\n\n/** Its agent's process id in the host (from the refresh cache); null with no PTY. */\nexport function ptyPid(sessionId: string): number | null {\n return outputs.get(sessionId)?.pid ?? null;\n}\n\nexport function peekPty(sessionId: string): boolean {\n return live.has(sessionId);\n}\n\n/** A session's live PTY screen as text; null when there is none (never spawns). */\nexport async function readPtyScreen(sessionId: string): Promise<string | null> {\n if (!live.has(sessionId)) return null;\n const c = await getClient(false);\n return c ? c.screen(sessionId) : null;\n}\n\n/** Write to a session's live PTY. False when there is none (never spawns). */\nexport async function writeToPty(sessionId: string, data: string): Promise<boolean> {\n if (!live.has(sessionId)) return false;\n const c = await getClient(false);\n return c ? c.write(sessionId, data) : false;\n}\n\n/**\n * Restart a session's agent in the host, resuming its conversation, its terminals\n * kept attached (agent-restart.ts). A host from before that call: stopped and\n * started again (an open Terminal tab then offers Enter, as after a stop).\n */\nexport async function restartPty(sessionId: string): Promise<string | void> {\n let c = await getClient(false);\n if (!c) throw new Error('the PTY host is not running');\n let how: Awaited<ReturnType<PtyHostClient['restart']>>;\n try {\n how = await c.restart(sessionId);\n } catch (err) {\n // A stale client (the host restarted on a new port before the refresh noticed): once more, fresh.\n client = null;\n c = await getClient(false);\n if (!c) throw err;\n how = await c.restart(sessionId);\n }\n if (how === 'not-running') throw new Error('its agent is not running in the PTY host');\n if (how === 'unsupported') {\n await disposePty(sessionId);\n if (!(await ensurePty(sessionId))) throw new Error('its agent could not be started again');\n return OLD_HOST_RESTART;\n }\n}\n\n/**\n * Stop a session's agent and keep its session in the host (entry, restore record, attached terminals) until `resumePty`:\n * a switch of account moves its conversation files in between. `stopped`: a host from before the call stopped it the old\n * way (its terminals were told it ended; `resumePtyOnAccount` then starts it fresh); `gone`: nothing was running.\n */\nexport async function haltPty(sessionId: string): Promise<'halted' | 'stopped' | 'gone'> {\n let c = await getClient(false);\n if (!c) throw new Error('the PTY host is not running');\n let how: Awaited<ReturnType<PtyHostClient['halt']>>;\n try {\n how = await c.halt(sessionId);\n } catch (err) {\n // A stale client (the host restarted on a new port before the refresh noticed): once more, fresh.\n client = null;\n c = await getClient(false);\n if (!c) throw err;\n how = await c.halt(sessionId);\n }\n if (how === 'not-running') return 'gone';\n if (how === 'unsupported') {\n await disposePty(sessionId);\n return 'stopped';\n }\n return 'halted';\n}\n\n/** Why a switch of account can't be done in this PTY host now (it is from before accounts), or null: asked before halting. */\nexport async function accountSwitchRefusal(): Promise<string | null> {\n const c = await getClient(false);\n return c && !(await hostTakesAgentEnv(c)) ? OLD_HOST_ACCOUNTS : null;\n}\n\n/**\n * Start a halted session's agent again in place, on `opts.agentEnv` (its terminals carry on). `not-halted`: it isn't\n * halted any more — the host started it again by itself (HALT_RESUME_MS) or restarted, on its old spec.\n */\nexport async function resumePty(sessionId: string, opts: { agentEnv?: EnvDelta } = {}): Promise<'resumed' | 'not-halted'> {\n let c = await getClient(false);\n if (!c) throw new Error('the PTY host is not running');\n if (hasEnvDelta(opts.agentEnv) && !(await hostTakesAgentEnv(c))) throw new Error(OLD_HOST_ACCOUNTS);\n let how: Awaited<ReturnType<PtyHostClient['resume']>>;\n try {\n how = await c.resume(sessionId, opts);\n } catch (err) {\n client = null;\n c = await getClient(false);\n if (!c) throw err;\n how = await c.resume(sessionId, opts);\n }\n return how;\n}\n\n/**\n * Start the agent of a session `haltPty` stopped, on the account the session records NOW (after a switch: the new one;\n * after one that failed: the old): resumed in place with that environment, or — `stopped`, an older host — started\n * again from a fresh spec (its terminals show it ended; opening the session reconnects).\n */\nexport async function resumePtyOnAccount(sessionId: string, how: 'halted' | 'stopped'): Promise<string | void> {\n if (how === 'stopped') {\n if (!(await ensurePty(sessionId))) throw new Error('its agent could not be started again');\n return OLD_HOST_RESTART;\n }\n const session = findSession(sessionId);\n const spec = session ? spawnSpecFor(session) : null;\n if (!spec) throw new Error('unknown session');\n // Nothing in the delta means no account change to apply (the default, with no accounts configured): a plain resume.\n const agentEnv = hasEnvDelta(spec.agentEnv) ? spec.agentEnv : undefined;\n if ((await resumePty(sessionId, agentEnv ? { agentEnv } : {})) === 'resumed') return;\n // Started again meanwhile on its OLD spec (the host's own resume after HALT_RESUME_MS — a long move —, or a host\n // restart's restore): restarted in place on the account the session records now, so it doesn't stay on the old one.\n const c = await getClient(false);\n if (!c) throw new Error('the PTY host is not running');\n const restarted = await c.restart(sessionId, agentEnv ? { agentEnv } : {});\n if (restarted === 'restarted') return RESTARTED_AFTER_AUTO_RESUME;\n // Not running now (it ended), or a host that couldn't take the environment in place: started fresh from the new spec.\n if (restarted === 'unsupported') await disposePty(sessionId);\n if (!(await ensurePty(sessionId))) throw new Error('its agent could not be started again');\n return RESTARTED_AFTER_AUTO_RESUME;\n}\n\n/** What a switch says when its halted Claude had been started again (on the old account) before the move was done. */\nexport const RESTARTED_AFTER_AUTO_RESUME =\n 'it had been started again on its old account while the conversation moved, so it was restarted on the new one';\n\n/** Said when a session on a named account would start in a PTY host that drops the account (one from before accounts). */\nexport const OLD_HOST_ACCOUNTS = 'the PTY host is from before Claude accounts: run `work pty-host --restart`';\n\n/** The delta sets a variable (a session on a named account): what an older host would drop, starting it elsewhere. */\nconst setsEnv = (d: EnvDelta | undefined): boolean => !!d && Object.values(d).some((v) => typeof v === 'string');\n\n/** The host applies `agentEnv`; one that can't be asked right now is given the benefit of the doubt (its restart says). */\nasync function hostTakesAgentEnv(c: PtyHostClient): Promise<boolean> {\n const f = await c.features();\n return f === null || f.includes('agentEnv');\n}\n\n/** Its agent runs in this host now (a spawn would only attach to it). */\nasync function runsIn(c: PtyHostClient, sessionId: string): Promise<boolean> {\n return (await c.list()).some((p) => p.id === sessionId && !p.exited);\n}\n\n/** How a restart on a PTY host from before restart-in-place went: what differs, and the way to the real thing. */\nexport const OLD_HOST_RESTART =\n 'stopped and started again (an older PTY host: open terminals show it ended, and it runs with only the variables `hostEnv` keeps; `work pty-host --restart` gets restarts in place)';\n\n/** Kill one session's PTY (if any). Called before removing a worktree so\n * the Claude process doesn't hold its cwd open (Windows refuses to delete\n * a directory that is some process's working directory). */\nexport async function disposePty(sessionId: string): Promise<void> {\n live.delete(sessionId);\n let c = client;\n if (!c) {\n // A busy host (mid-restore) is waited for, not skipped: skipping left\n // Claude running inside the worktree about to be deleted. A host from\n // another build can't be talked to — nothing to do but proceed.\n let info: HostInfo | null;\n try {\n info = await findHostPatient();\n } catch (err) {\n if (err instanceof PtyHostVersionError) return;\n throw err; // still busy after waiting: let the caller report it\n }\n if (!info) return;\n c = new PtyHostClient(info);\n }\n await c.kill(sessionId).catch(swallow(`stop session ${sessionId} in the PTY host`));\n}\n\n/**\n * Stop a session's Claude in the PTY host before its worktree is deleted —\n * from any caller, including the CLI (`work remove` / prune / sync), which\n * doesn't run a pool. Never starts a host; waits for the process to exit\n * (the host's kill does) so Windows can then delete the directory.\n * Best-effort: no host, or a host that can't be reached, is a no-op.\n */\nexport async function stopSessionPty(target: string, branch: string): Promise<void> {\n const id = sessionIdFor({ target, branch } as WorktreeSession);\n live.delete(id);\n // Under the host START lock: a host that's starting holds it until it has\n // restored, so we either see it running (and kill the session) or know\n // none is — and then drop the session from the saved list so a later\n // start doesn't restore Claude into a worktree that's being deleted.\n const lock = hostStartLockPath();\n ensureFile(lock, '');\n await withFileLock(lock, async () => {\n let info;\n try {\n info = await findHostPatient();\n } catch (err) {\n // A host from another build can't be talked to; one still busy after\n // waiting is running and owns the session — leave both alone (and\n // never drop the saved entry: the host is what it belongs to).\n logSwallowed(`stop session ${id}: PTY host`, err);\n return;\n }\n if (info) await new PtyHostClient(info).kill(id).catch(swallow(`stop session ${id} in the PTY host`));\n else await forgetPersistedSession(id).catch(swallow(`forget saved session ${id}`));\n }).catch(swallow(`stop session ${id}: host start lock`));\n}\n\n/** `work web` shutdown. Deliberately does NOT kill anything: the PTYs belong\n * to the host and outlive the dashboard. Just stops polling. */\nexport function detachPtyPool(): void {\n if (refreshTimer) clearInterval(refreshTimer);\n refreshTimer = null;\n client = null;\n live = new Set();\n livePids = new Set();\n}\n","import { createFsWatcher, type FsWatcher } from '../platform/fs-watcher.js';\nimport { findSessionById, type WorktreeSession } from './history.js';\n\nexport { sessionIdFor } from './session-id.js';\n\n/** A session by id — a primary-key lookup (every /api/sessions/:id/*\n * request does one; it used to load and hash every row). */\nexport function findSession(sessionId: string): WorktreeSession | null {\n return findSessionById(sessionId);\n}\n\ninterface WatcherEntry {\n watcher: FsWatcher;\n subscribers: Set<() => void>;\n}\n\nconst sessionWatchers = new Map<string, WatcherEntry>();\nconst DEBOUNCE_MS = 150;\n\n/**\n * Subscribe to filesystem changes for a session's worktree(s). The watch is\n * started on first subscriber and stopped when the last one leaves —\n * reference-counted so the cost stays proportional to what's actually being\n * viewed in the browser. It is the shared fs-watcher: dependency and build\n * folders (node_modules, bin/obj, dist, …) are left out, and on Windows and\n * macOS it is one recursive OS watch per root. A chokidar watch over the\n * whole worktree used to open one watch per folder, node_modules included.\n *\n * Returns an unsubscribe function. Safe to call multiple times.\n */\nexport function subscribeSession(sessionId: string, onChange: () => void): () => void {\n const session = findSession(sessionId);\n if (!session)\n return () => {\n /* unknown session */\n };\n\n let entry = sessionWatchers.get(sessionId);\n if (!entry) {\n const subscribers = new Set<() => void>();\n const newEntry: WatcherEntry = {\n subscribers,\n watcher: createFsWatcher({\n roots: session.paths,\n debounceMs: DEBOUNCE_MS,\n onChange: () => {\n for (const cb of subscribers) {\n try {\n cb();\n } catch {\n /* swallow */\n }\n }\n },\n }),\n };\n sessionWatchers.set(sessionId, newEntry);\n entry = newEntry;\n }\n\n entry.subscribers.add(onChange);\n\n let released = false;\n return () => {\n if (released) return;\n released = true;\n entry!.subscribers.delete(onChange);\n if (entry!.subscribers.size === 0) {\n entry!.watcher.stop();\n if (sessionWatchers.get(sessionId) === entry) {\n sessionWatchers.delete(sessionId);\n }\n }\n };\n}\n\n/**\n * Force-stop one session's watcher regardless of subscribers. Used before\n * removing a worktree: on Windows an open directory watch keeps a handle\n * on the tree and makes `git worktree remove` fail. Late unsubscribes from\n * the orphaned entry are harmless (see the identity check above).\n */\nexport async function disposeSessionWatcher(sessionId: string): Promise<void> {\n const entry = sessionWatchers.get(sessionId);\n if (!entry) return;\n sessionWatchers.delete(sessionId);\n entry.subscribers.clear();\n entry.watcher.stop();\n}\n\n/** Stop every active session watcher. Called on server shutdown. */\nexport function disposeAllWatchers(): void {\n for (const [, entry] of sessionWatchers) entry.watcher.stop();\n sessionWatchers.clear();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWO,IAAM,oBAAoB;AAU1B,SAAS,iBAAiB,GAAc,KAAsC;AACnF,MAAI,CAAC,EAAE,QAAQ,EAAE,SAAS,YAAY,CAAC,EAAE,aAAc,QAAO;AAC9D,QAAM,KAAK,KAAK,MAAM,EAAE,YAAY;AACpC,MAAI,CAAC,OAAO,SAAS,EAAE,EAAG,QAAO;AACjC,QAAM,UAAU,MAAM,KAAK;AAC3B,SAAO;AAAA,IACL,OAAO,UAAU,YAAY;AAAA,IAC7B,MAAM;AAAA,IACN,OAAO,EAAE;AAAA,IACT,WAAW,EAAE;AAAA,IACb,OAAO;AAAA,IACP,SAAS,GAAG,UAAU,aAAa,OAAO,qCAAgC,EAAE,IAAI;AAAA,EAClF;AACF;;;AClCA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/sessions/account-switch-rules.ts","../src/core/sessions/account-switch.ts","../src/core/sessions/account-switch-deps.ts"],"sourcesContent":["import fs from 'node:fs';\nimport { findOnPath } from '../platform/find-on-path.js';\nimport type { PtyInfo } from './pty-host-protocol.js';\nimport { LATER_TEXT, restartCountsText } from './restart-view.js';\n\n/**\n * Restarting the agents in the PTY host — after their tool updated (Claude Code\n * replaced its binary; a running Claude keeps the old one until it starts again),\n * or when asked. A restart is its agent stopped and started again in place,\n * resuming its conversation; never in the middle of a turn: a session working or\n * waiting on you restarts when its turn ends.\n */\n\n/** Before this, an mtime isn't when the file was installed: npm unpacks every file dated 1985-10-26. */\nconst PACKED_MTIME_BEFORE = Date.parse('1990-01-01T00:00:00Z');\n\n/**\n * When the file a tool's command runs was installed, following links\n * (`~/.local/bin/claude` → `versions/2.1.296`): the later of its modification time\n * and its creation — an updater that copies the new file keeping its build date\n * still creates it now. A file npm unpacked with its fixed old date, on a system\n * that doesn't record creation, falls back to its change time (the unpacking).\n * Not the change time otherwise: a chmod or a relink moves it, and every running\n * agent would read as outdated. Null when it isn't on PATH.\n */\nexport function installedAt(cmd: string, find: (cmd: string) => string | null = findOnPath): number | null {\n const file = find(cmd);\n if (!file) return null;\n try {\n return installTime(fs.statSync(fs.realpathSync(file)));\n } catch {\n return null;\n }\n}\n\n/** installedAt's rule on a file's times. Pure. */\nexport function installTime(st: { mtimeMs: number; ctimeMs: number; birthtimeMs: number }): number {\n const real = (ms: number) => (ms >= PACKED_MTIME_BEFORE ? ms : null);\n const known = [real(st.mtimeMs), real(st.birthtimeMs)].filter((x): x is number => x !== null);\n return known.length ? Math.max(...known) : st.ctimeMs;\n}\n\n/**\n * `installedAt` per tool, read again only after `ttlMs`: a lookup walks PATH with a\n * stat per folder and extension, synchronously, and the dashboard asks every few\n * minutes per window.\n */\nexport function installedAtCache(ttlMs = 60_000, look: (cmd: string) => number | null = installedAt, now: () => number = Date.now) {\n const cache = new Map<string, { at: number | null; read: number }>();\n return (cmd: string): number | null => {\n const hit = cache.get(cmd);\n if (hit && now() - hit.read < ttlMs) return hit.at;\n const at = look(cmd);\n cache.set(cmd, { at, read: now() });\n return at;\n };\n}\n\n/**\n * The live PTYs whose process started before its tool's file was installed: they\n * run the version from before. A PTY whose tool isn't known (a host from before\n * `tool`) or isn't on PATH is left out: nothing says it's outdated. Pure.\n */\nexport function outdatedPtys(ptys: readonly PtyInfo[], toolInstalledAt: (tool: string) => number | null): PtyInfo[] {\n return ptys.filter((p) => {\n if (p.exited || !p.tool) return false;\n const at = toolInstalledAt(p.tool);\n const started = Date.parse(p.startedAt);\n return at !== null && Number.isFinite(started) && started < at;\n });\n}\n\n/** How recently a terminal printed for its agent to count as at work: a working one redraws its spinner, an idle one prints nothing. */\nexport const PRINTING_MS = 10_000;\n\n/**\n * At work, for a restart: what the agent itself says (Claude Code's own state for its process: mid-turn, or\n * waiting on you; at a permission dialog it prints nothing, so only this tells), or its status (the hooks' as\n * the dashboard reads it, corrected by the transcript and decayed) is working or waiting on you, or its\n * terminal printed in the last few seconds, which catches a turn both missed. An agent that says nothing and\n * has no status (a tool with no hooks or process state) has only the last: one silent at a prompt of its own\n * can't be told from idle. Pure.\n */\nexport function busyForRestart(\n state: 'working' | 'needs_input' | 'idle' | null,\n lastOutputMs: number | null,\n now = Date.now(),\n live: 'busy' | 'idle' | 'waiting' | null = null,\n): boolean {\n if (live === 'busy' || live === 'waiting') return true;\n if (state === 'working' || state === 'needs_input') return true;\n return lastOutputMs !== null && now - lastOutputMs < PRINTING_MS;\n}\n\n/** Which of `ids` restart now and which after their turn (working, or waiting on you). Pure. */\nexport function restartPlan(ids: readonly string[], busy: (id: string) => boolean): { now: string[]; later: string[] } {\n const now: string[] = [];\n const later: string[] = [];\n for (const id of new Set(ids)) (busy(id) ? later : now).push(id);\n return { now, later };\n}\n\n/** Restarts run this many at a time. */\nexport const RESTART_AT_ONCE = 3;\n\nexport interface RestarterDeps {\n /** Restart its agent in place (the host keeps attached terminals); a string: how it went instead (an older host). */\n restart: (id: string) => Promise<string | void>;\n /** Working, or waiting on you: not now. `turnEnded`: its turn just ended (the Stop), so the final message it\n * printed a moment ago isn't work going on. */\n busy: (id: string, opts?: { turnEnded?: boolean }) => boolean;\n /** Its agent runs in the host (a queued one stopped meanwhile needs nothing). */\n running: (id: string) => boolean;\n /** What one request (or one turn's end) decided, at once: one Activity run, not one per session. */\n report?: (notes: RestartNote[]) => void;\n /** When the waiting ones are looked at next (the Activity panel's schedule); null when nothing waits. */\n scheduled?: (nextAt: number | null) => void;\n changed?: () => void;\n /** A look again a little later (default setTimeout, unref'd): a turn-end the status hasn't caught up with yet. */\n later?: (fn: () => void, ms: number) => void;\n /**\n * Something else that restarts its agent anyway is waiting or under way (a switch of account, account-switch.ts): what\n * it is, in a few words; null: nothing. A restart asked for then is folded into it (answered as waiting, never a\n * second restart), and a queued one is dropped when its turn comes.\n */\n foldedInto?: (id: string) => string | null;\n}\n\nexport interface RestartNote {\n id: string;\n text: string;\n level: 'action' | 'info' | 'warn';\n}\n\ntype OneRestart = { ok: true; how: string } | { ok: false; error: string };\n\nexport interface RestartOutcome {\n now: string[];\n later: string[];\n failed: Array<{ id: string; error: string }>;\n}\n\n/** One request's decisions in a line, for its Activity run (restart-view.ts's wording). Pure. */\nexport function restartNotesSummary(notes: readonly RestartNote[]): string {\n const n = (level: RestartNote['level']) => notes.filter((x) => x.level === level).length;\n return restartCountsText({ restarted: n('action'), later: n('info'), failed: n('warn') });\n}\n\n/** While anything waits, how often it is looked at again: a turn whose end no hook reported, or a terminal that was\n * only redrawing (the printing check) — never left for the 5-minute sweep, which `--dev` and lean don't run. */\nexport const QUEUE_RECHECK_MS = 15_000;\n/** After a turn ends, how long before its agent is restarted: the Stop's own hooks (`work hook turn-end`: the\n * checkpoint, the status) run as its children, and stopping it at once would kill them mid-way. */\nexport const TURN_END_GRACE_MS = 10_000;\n\n/**\n * Restarts now what can go now, and the rest when their turn ends (`turnEnded`,\n * from the status hook — and once more a little later, should the status still\n * say working then) or on a later `retry` (a turn whose end no hook reported).\n * One restart per session at a time: asked again meanwhile, it shares that one's\n * outcome.\n */\nexport function createRestarter(deps: RestarterDeps) {\n const queued = new Set<string>();\n const inFlight = new Map<string, Promise<OneRestart>>();\n const later = deps.later ?? ((fn: () => void, ms: number) => void setTimeout(fn, ms).unref?.());\n\n /** Restart one: how it went (a different way, on an older host), or why not. */\n const one = (id: string): Promise<OneRestart> => {\n const running = inFlight.get(id);\n if (running) return running;\n queued.delete(id);\n const p = deps.restart(id).then(\n (how): OneRestart => ({ ok: true, how: how || 'restarted its agent (its conversation goes on)' }),\n (err: Error): OneRestart => ({ ok: false, error: err.message }),\n );\n inFlight.set(id, p);\n void p.finally(() => inFlight.delete(id));\n return p;\n };\n\n /** Restart these, RESTART_AT_ONCE at a time; each waits for its old process to exit. */\n const run = async (ids: string[], notes: RestartNote[]) => {\n const failed: RestartOutcome['failed'] = [];\n const ok = new Set<string>();\n const queue = [...ids];\n const worker = async () => {\n for (let id = queue.shift(); id !== undefined; id = queue.shift()) {\n const r = await one(id);\n if (r.ok) {\n ok.add(id);\n notes.push({ id, text: r.how, level: 'action' });\n } else {\n failed.push({ id, error: r.error });\n notes.push({ id, text: `couldn't restart its agent: ${r.error}`, level: 'warn' });\n }\n }\n };\n await Promise.all(Array.from({ length: Math.min(RESTART_AT_ONCE, queue.length) }, worker));\n return { done: ids.filter((id) => ok.has(id)), failed };\n };\n\n const finish = (notes: RestartNote[]) => {\n if (!notes.length) return;\n deps.report?.(notes);\n deps.changed?.();\n };\n\n /** Restart these (the caller found them running in the host: its list is fresh, `running` is a cache). */\n const request = async (ids: readonly string[]): Promise<RestartOutcome> => {\n const notes: RestartNote[] = [];\n const folded: string[] = [];\n for (const id of ids) {\n const into = deps.foldedInto?.(id);\n if (!into) continue;\n folded.push(id);\n notes.push({ id, text: `restarts with ${into} (no second restart)`, level: 'info' });\n }\n const plan = restartPlan(\n ids.filter((id) => !folded.includes(id)),\n (id) => deps.busy(id),\n );\n for (const id of plan.later) {\n queued.add(id);\n notes.push({ id, text: `${LATER_TEXT} (it is working or waiting on you)`, level: 'info' });\n }\n const { done, failed } = await run(plan.now, notes);\n finish(notes);\n tick();\n return { now: done, later: [...folded, ...plan.later], failed };\n };\n\n // While anything waits, it is looked at again every QUEUE_RECHECK_MS.\n let ticking = false;\n const tick = () => {\n if (ticking) return;\n if (queued.size === 0) {\n deps.scheduled?.(null);\n return;\n }\n ticking = true;\n deps.scheduled?.(Date.now() + QUEUE_RECHECK_MS);\n later(() => {\n ticking = false;\n void retry()\n .catch(() => {})\n .finally(tick);\n }, QUEUE_RECHECK_MS);\n };\n\n /** Restart the queued ones (or `only`) that can go now; a queued one stopped meanwhile is dropped. */\n const retry = async (only?: string, opts?: { turnEnded?: boolean }): Promise<void> => {\n const notes: RestartNote[] = [];\n const ready: string[] = [];\n for (const id of [...queued]) {\n if (only !== undefined && id !== only) continue;\n if (!deps.running(id)) {\n queued.delete(id);\n notes.push({ id, text: 'no longer waits to restart: it was stopped meanwhile (it starts on the new version)', level: 'info' });\n continue;\n }\n const into = deps.foldedInto?.(id);\n if (into) {\n queued.delete(id);\n notes.push({ id, text: `no longer waits to restart: ${into} restarts it`, level: 'info' });\n continue;\n }\n if (!deps.busy(id, opts)) ready.push(id);\n }\n await run(ready, notes);\n finish(notes);\n };\n\n return {\n request,\n retry: () => retry(),\n /** A session's turn ended: restart it if it was waiting for that — and if it still reads as busy, look again shortly. */\n turnEnded: (id: string): void => {\n if (!queued.has(id)) return;\n later(() => void retry(id, { turnEnded: true }).catch(() => {}), TURN_END_GRACE_MS);\n },\n queued: (): string[] => [...queued],\n /** Take one off the queue (it no longer waits for its turn); false when it wasn't waiting (not queued, or running now). */\n cancel: (id: string): boolean => {\n if (!queued.delete(id)) return false;\n if (queued.size === 0) deps.scheduled?.(null);\n deps.changed?.();\n return true;\n },\n /** Being restarted now (the host lists them as exited meanwhile: still this session's). */\n restarting: (): string[] => [...inFlight.keys()],\n };\n}\n\nexport type Restarter = ReturnType<typeof createRestarter>;\n","/**\n * When a switch of account is refused before anything is stopped or moved — the rules the real switch\n * (account-switch.ts) and the demo's (server/demo/demo-accounts.ts) share. Pure: no imports.\n */\n\n/** An account as the rules see it (agents/types.ts `AccountInfo`; the wire's `AccountWire`). */\nexport interface SwitchAccountInfo {\n name: string;\n /** Logged in; null: can't tell (macOS keeps Claude's credentials in the keychain) — allowed. */\n loggedIn: boolean | null;\n}\n\nexport interface SwitchFacts {\n /** Archived, or being archived right now. */\n archived: boolean;\n /** Its agent's accounts and the one it is on; null: its agent has none. */\n accounts: { list: readonly SwitchAccountInfo[]; current: string } | null;\n /** Where a switch already waiting for its turn (or being done now) goes; null: none. */\n pendingTo: string | null;\n /** Its agent runs in the PTY host (a switch can stop and start it there). */\n inHost: boolean;\n /** Its agent runs in a terminal outside work. */\n runningOutside: boolean;\n}\n\nexport type SwitchRefusal = { status: 400 | 409; error: string };\n\n/** Why the session can't be moved to `to` (status and reason), or null. In the order the user is told them. */\nexport function switchRefusal(to: string, f: SwitchFacts): SwitchRefusal | null {\n if (f.archived) return { status: 409, error: 'it is archived: restore it first' };\n if (!f.accounts) return { status: 409, error: \"its agent doesn't have accounts\" };\n const target = f.accounts.list.find((a) => a.name === to);\n if (!target) return { status: 400, error: `no account “${to}” (see \\`work account list\\`)` };\n if (target.loggedIn === false)\n return { status: 409, error: `nobody is logged in on “${to}”: run \\`work account add ${to}\\` again to log in, or /login on it` };\n if (f.pendingTo !== null)\n return { status: 409, error: `a switch is already waiting for its turn to end (to ${f.pendingTo || 'another account'})` };\n if (f.accounts.current === to) return { status: 409, error: `it already runs on “${to}”` };\n if (!f.inHost && f.runningOutside)\n return {\n status: 409,\n error: 'its Claude runs in a terminal outside work: stop it there first (its conversation would be moved from under it)',\n };\n return null;\n}\n","import type { AccountInfo } from '../agents/types.js';\nimport { createRestarter, type Restarter } from '../pty/agent-restart.js';\nimport type { WorktreeSession } from './session-types.js';\nimport type { ActivityLog } from '../platform/activity.js';\nimport { switchRefusal } from './account-switch-rules.js';\n\n/**\n * Moving a session to another account of its agent (Claude: another login, for when the first one's limit runs out).\n * The policy is here; I/O is passed in (account-routes.ts and web-server.ts give the real one, tests a fake).\n *\n * Refused: an unknown or archived session, an agent with no accounts, an unknown account, one nobody is logged in to, the\n * account it is on, a Claude running in a terminal outside work (a switch can't stop it), one switch already waiting.\n *\n * Not running in the PTY host: its conversations move and the account is recorded — the next start uses it. Running and\n * idle: its Claude is halted in the host (stopped, its terminals kept), the conversations move, the account is recorded, and it\n * is resumed in place on the new account — in that order, so nothing writes into the old folder while it moves. Working, or waiting\n * on you: after its turn — through the agent restarter's queue (agent-restart.ts), so the rule for \"not mid-turn\" is the\n * restart's own, with a switch as the thing that runs when its turn ends.\n */\n\nexport interface AccountSwitchDeps {\n session: (id: string) => WorktreeSession | null;\n /** Being archived right now (its Claude was stopped on purpose, and mustn't be started again). */\n beingArchived: (id: string) => boolean;\n /** Its agent's accounts; null: its agent has none. */\n accounts: (session: WorktreeSession) => { list: AccountInfo[]; current: string } | null;\n /** Move its conversations to `to`'s folders (puts back what it moved when it fails, and throws). */\n switchFiles: (session: WorktreeSession, to: string) => Promise<{ moved: string[] }>;\n /** Record the account on the session, in one transaction. */\n record: (session: WorktreeSession, to: string) => Promise<void>;\n /** Its Claude runs in the PTY host. */\n hostRuns: (id: string) => boolean;\n /** Its Claude runs in a terminal outside work. */\n runningOutside: (id: string) => boolean;\n /** A folder whose conversations the switch would move where another agent (of any account, not this session's own in\n * the host) runs now — its files would move from under it; null: none. */\n othersRunningIn?: (session: WorktreeSession, id: string) => string | null;\n /** Why the PTY host can't run it on another account (one from before accounts), or null. Asked before anything stops. */\n hostRefusal?: () => Promise<string | null>;\n /** Working, or waiting on you (`turnEnded`: its turn just ended, so what it printed a moment ago isn't work going on). */\n busy: (id: string, opts?: { turnEnded?: boolean }) => boolean;\n /** Stop its Claude in the host and keep its session (terminals attached) until `resume`: the files move only after it is stopped.\n * `stopped`: an older host stopped it the old way; `gone`: nothing was running. */\n halt: (id: string) => Promise<'halted' | 'stopped' | 'gone'>;\n /** Start it again after `halt`, on the account the session records now (so the old one after a switch that failed): in place\n * when it was `halted` (its terminals carry on), from a fresh spec when `stopped` (an older host). A string: how it went instead. */\n resume: (id: string, how: 'halted' | 'stopped') => Promise<string | void>;\n /** One line of what a switch decided, for the Activity panel. */\n note?: (id: string, text: string, level: 'action' | 'info' | 'warn') => void;\n changed?: () => void;\n scheduled?: (nextAt: number | null) => void;\n /** A look again a little later (the restarter's own default: setTimeout). */\n later?: (fn: () => void, ms: number) => void;\n /** Drop an agent restart waiting for its turn (agent-restart.ts): the switch restarts it anyway. True when one was waiting. */\n cancelRestart?: (id: string) => boolean;\n}\n\nexport type SwitchOutcome = 'switched' | 'queued' | 'recorded';\n\nexport type SwitchResult =\n { ok: true; outcome: SwitchOutcome; moved?: number } | { ok: false; status: 400 | 404 | 409 | 502; error: string };\n\nconst msg = (err: unknown) => (err instanceof Error ? err.message : String(err));\n\nexport function createAccountSwitcher(deps: AccountSwitchDeps) {\n /** Where each waiting (or running) switch goes. */\n const targets = new Map<string, string>();\n /** How many entries each finished switch moved, for the answer. */\n const movedBy = new Map<string, number>();\n\n const name = (s: WorktreeSession) => `${s.target} ${s.branch}`;\n\n /** Move the files and record the account; a failed record puts the files back. Returns how many entries moved. */\n const moveAndRecord = async (s: WorktreeSession, to: string, from: string): Promise<number> => {\n const { moved } = await deps.switchFiles(s, to);\n try {\n await deps.record(s, to);\n } catch (err) {\n // The files are in the new account's folders and the session still says the old one: back, or its --continue finds\n // nothing. A move back that fails is said with the error (its message names what is stuck where).\n const back = await deps.switchFiles({ ...s, account: to }, from).then(\n () => '',\n (e2: unknown) => `; and its conversations couldn't all be moved back: ${msg(e2)}`,\n );\n throw new Error(`${msg(err)}${back}`, { cause: err });\n }\n return moved.length;\n };\n\n /** What the restarter runs for a session (at once when idle, after its turn when not): the move, the record, the restart. */\n const perform = async (id: string): Promise<string | void> => {\n const to = targets.get(id);\n const s = deps.session(id);\n try {\n if (!to || !s) throw new Error('the session is gone');\n if (s.archivedAt || deps.beingArchived(id)) throw new Error('it was archived meanwhile');\n const acc = deps.accounts(s);\n if (!acc) throw new Error('its agent has no accounts');\n const from = acc.current;\n if (from === to) return `already on ${to}`;\n const before = await refusalBeforeStop(s, id);\n if (before) throw new Error(`stays on ${from}: ${before}`);\n // A restart of its agent that waited for this turn too would stop it a second time: the switch's restart does its job.\n if (deps.cancelRestart?.(id)) deps.note?.(id, 'its agent restart that waited for this turn is done by the switch instead', 'info');\n // Stopped first: a running (or just exiting) Claude writes to its transcript, and on Windows holds the file.\n let halted: 'halted' | 'stopped' | null = null;\n if (deps.hostRuns(id)) {\n let h: 'halted' | 'stopped' | 'gone';\n try {\n h = await deps.halt(id);\n } catch (err) {\n throw new Error(`stays on ${from}: couldn't stop its Claude: ${msg(err)}`, { cause: err });\n }\n if (h !== 'gone') halted = h;\n }\n /** Start it again on the account the session records (still the old one until the record is made). */\n const resume = async (): Promise<string | void> => (halted ? deps.resume(id, halted) : undefined);\n let moved: number;\n try {\n moved = await moveAndRecord(s, to, from);\n } catch (err) {\n // Put back (the move rolled itself back, a failed record moved the files back): it goes on running on the account it has.\n const back = await resume().then(\n () => '',\n (e2: unknown) => ` (and couldn't start its Claude again: ${msg(e2)}; opening the session starts it)`,\n );\n throw new Error(`stays on ${from}: ${msg(err)}${back}`, { cause: err });\n }\n movedBy.set(id, moved);\n if (!halted) {\n deps.note?.(id, `moved to the ${to} account (${moved} entries moved; its next start uses it)`, 'action');\n return `moved to the ${to} account`;\n }\n try {\n const how = await resume();\n deps.note?.(id, `moved to the ${to} account: its Claude restarted on it${how ? ` (${how})` : ''}`, 'action');\n return how || `moved to the ${to} account: its Claude restarted on it`;\n } catch (err) {\n // The account is recorded and the files are there: opening the session starts it on the new one.\n const why = `moved to the ${to} account, but its Claude couldn't be restarted: ${msg(err)} (opening the session starts it on ${to})`;\n deps.note?.(id, why, 'warn');\n throw new Error(why, { cause: err });\n }\n } catch (err) {\n if (s && !String(msg(err)).startsWith('moved to')) deps.note?.(id, `couldn't switch: ${msg(err)}`, 'warn');\n throw err;\n } finally {\n targets.delete(id);\n }\n };\n\n const restarter: Restarter = createRestarter({\n restart: perform,\n busy: deps.busy,\n // A queued switch is never dropped as \"stopped meanwhile\": perform handles a Claude no longer running (it records the account).\n running: () => true,\n changed: deps.changed,\n scheduled: deps.scheduled,\n later: deps.later,\n });\n\n /** What stops a switch before anything is stopped or moved: an older PTY host, another Claude in one of its folders. */\n const refusalBeforeStop = async (s: WorktreeSession, id: string): Promise<string | null> => {\n const other = deps.othersRunningIn?.(s, id);\n if (other) return `a Claude outside this session runs in ${other}`;\n return deps.hostRuns(id) ? ((await deps.hostRefusal?.()) ?? null) : null;\n };\n\n const pending = (id: string) => restarter.queued().includes(id) || restarter.restarting().includes(id);\n\n async function switchAccount(id: string, to: string): Promise<SwitchResult> {\n const s = deps.session(id);\n if (!s) return { ok: false, status: 404, error: 'unknown session' };\n const acc = deps.accounts(s);\n const inHost = deps.hostRuns(id);\n const refused = switchRefusal(to, {\n archived: !!s.archivedAt || deps.beingArchived(id),\n accounts: acc,\n pendingTo: pending(id) ? (targets.get(id) ?? '') : null,\n inHost,\n runningOutside: !inHost && deps.runningOutside(id),\n });\n if (refused) return { ok: false, ...refused };\n if (!acc) return { ok: false, status: 409, error: \"its agent doesn't have accounts\" }; // (refused above: for the type)\n\n const before = await refusalBeforeStop(s, id);\n if (before) return { ok: false, status: 409, error: `stays on ${acc.current}: ${before}` };\n\n if (!inHost) {\n // Nothing to stop: the files move and the account is recorded; the next start uses it.\n try {\n const moved = await moveAndRecord(s, to, acc.current);\n deps.note?.(id, `${name(s)}: moved to the ${to} account (${moved} entries moved; its next start uses it)`, 'action');\n deps.changed?.();\n return { ok: true, outcome: 'recorded', moved };\n } catch (err) {\n deps.note?.(id, `couldn't switch: ${msg(err)}`, 'warn');\n return { ok: false, status: 502, error: `stays on ${acc.current}: ${msg(err)}` };\n }\n }\n\n targets.set(id, to);\n movedBy.delete(id);\n const r = await restarter.request([id]);\n if (r.later.includes(id)) {\n deps.note?.(id, `will move to the ${to} account when its turn ends (it is working or waiting on you)`, 'info');\n return { ok: true, outcome: 'queued' };\n }\n const failed = r.failed.find((f) => f.id === id);\n if (failed) return { ok: false, status: 502, error: failed.error };\n return { ok: true, outcome: 'switched', moved: movedBy.get(id) };\n }\n\n return {\n switchAccount,\n /** Its turn ended: do the switch that waited for it. */\n turnEnded: (id: string) => restarter.turnEnded(id),\n /** Do the waiting switches that can go now (a turn whose end no hook reported). */\n retry: () => restarter.retry(),\n /** Sessions waiting for their turn to end, and where each goes. */\n waiting: (): Array<{ id: string; to: string }> => restarter.queued().map((id) => ({ id, to: targets.get(id) ?? '' })),\n /** The account a switch waiting for its turn, or being done now, moves it to; null: none. Either way its agent restarts. */\n restartsAnyway: (id: string): string | null => (pending(id) ? (targets.get(id) ?? '') : null),\n /** The account a session is waiting to move to (its turn first), or null. Kept in memory: a work web restart drops it. */\n pendingFor: (id: string): string | null => (restarter.queued().includes(id) ? (targets.get(id) ?? null) : null),\n /**\n * Drop the switch waiting for its turn to end. `running`: it is being done right now (too late to cancel); `none`:\n * nothing waits for it.\n */\n cancel: (id: string): 'cancelled' | 'running' | 'none' => {\n if (restarter.restarting().includes(id)) return 'running';\n const to = targets.get(id);\n if (!restarter.cancel(id)) return 'none';\n targets.delete(id);\n deps.note?.(id, `no longer moves to the ${to ?? 'other'} account: the switch was cancelled`, 'info');\n return 'cancelled';\n },\n };\n}\n\nexport type AccountSwitcher = ReturnType<typeof createAccountSwitcher>;\n\n/**\n * The switcher's `note` as Activity runs: one run per note, a failure (`warn`) failing it — so a switch that waited for its\n * turn and then couldn't be done lights the Activity dot, rather than passing as a run that went fine.\n */\nexport function accountSwitchNote(\n activity: Pick<ActivityLog, 'start'>,\n label: (id: string) => string | null,\n): NonNullable<AccountSwitchDeps['note']> {\n return (id, text, level) => {\n const name = label(id);\n const run = activity.start('accounts', 'Switching a Claude account');\n run.note(`${name ?? id}: ${text}`, { level, sessionId: name ? id : undefined });\n if (level === 'warn') run.fail(text);\n else run.done(text);\n };\n}\n","import path from 'node:path';\nimport { agentOf, liveAgents } from '../agents/index.js';\nimport { isArchiving } from '../archive/archiving.js';\nimport { accountSwitchRefusal, peekPty, ptyPid, ptyPids, haltPty, resumePtyOnAccount } from '../pty/pty-pool.js';\nimport type { AccountSwitchDeps } from './account-switch.js';\nimport { loadHistory, setSessionAccount } from './history.js';\nimport { agentsBySession } from './live-agents.js';\nimport { findSession } from './web-state.js';\n\n/** The real inputs of createAccountSwitcher (account-switch.ts); work web gives `busy`, the Activity notes and the broadcast. */\nexport function defaultAccountSwitchDeps(opts: Pick<AccountSwitchDeps, 'busy'> & Partial<AccountSwitchDeps>): AccountSwitchDeps {\n return {\n session: findSession,\n beingArchived: isArchiving,\n accounts: (s) => {\n const accounts = agentOf(s).accounts;\n return accounts ? { list: accounts.list(), current: accounts.current(s) } : null;\n },\n switchFiles: (s, to) => {\n const accounts = agentOf(s).accounts;\n if (!accounts) throw new Error('its agent has no accounts');\n return accounts.switchFiles(s, to);\n },\n record: async (s, to) => {\n if (!(await setSessionAccount(s.target, s.branch, to))) throw new Error('unknown session');\n },\n hostRuns: peekPty,\n // Claude Code's process files say one runs for it that isn't the host's (terminal-ws.ts, session-control-routes.ts).\n runningOutside: (id) => {\n const hostPids = ptyPids();\n return (agentsBySession(liveAgents(), loadHistory()).get(id) ?? []).some((c) => !hostPids.has(c.pid));\n },\n othersRunningIn: (s, id) => {\n const folders = agentOf(s).accounts?.folders(s) ?? [];\n if (!folders.length) return null;\n const own = ptyPid(id);\n const key = (p: string) => {\n const r = path.resolve(p).replace(/[\\\\/]+$/, '');\n return process.platform === 'win32' ? r.toLowerCase() : r;\n };\n const wanted = new Map(folders.map((f) => [key(f), f]));\n const other = liveAgents().find((a) => a.pid !== own && wanted.has(key(a.cwd)));\n return other ? (wanted.get(key(other.cwd)) ?? other.cwd) : null;\n },\n hostRefusal: acc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;AAAA,MAC1D;AACA,YAAM,SAAS,IAAI,IAAI,QAAQ,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACtD,YAAM,QAAQ,WAAW,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,OAAO,OAAO,IAAI,IAAI,EAAE,GAAG,CAAC,CAAC;AAC9E,aAAO,QAAS,OAAO,IAAI,IAAI,MAAM,GAAG,CAAC,KAAK,MAAM,MAAO;AAAA,IAC7D;AAAA,IACA,aAAa;AAAA,IACb,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,GAAG;AAAA,EACL;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/archive/restore-leftovers.ts","../src/core/pr/pr-ref.ts","../src/core/pr/pr-start.ts"],"sourcesContent":["import { isLeftover } from '../worktree/leftover.js';\nimport { describeProcess, findHolders, normDir, stopRunningFrom, type Holders } from '../platform/running-from.js';\n\n/**\n * Before a Restore makes a worktree again over what git left of it (a folder\n * it removed only in part, leftover.ts): that folder has to be moved out of\n * the way, and can't be while something runs from it — a dev server its\n * Claude left running. One place for both front-ends: the dashboard's\n * Restore (which asks \"Stop it and restore?\") and `work tree` (which says\n * what to stop).\n */\n\nexport interface LeftoverIo {\n /** What runs from or names the folders (running-from.ts). */\n holders?: (dirs: string[]) => Promise<Holders>;\n /** Stop what runs from them, saying what. */\n stop?: (dirs: string[]) => Promise<string[]>;\n}\n\n/** The session's folders git removed only in part. */\nexport function leftoversOf(paths: string[]): string[] {\n return paths.filter((p) => isLeftover(p));\n}\n\nconst names = (procs: Holders['stoppable'], dirs: string[]) =>\n procs.map((p) =>\n describeProcess(\n p,\n dirs.map((d) => normDir(d)),\n ),\n );\n\n/** What runs from the leftovers, and what has them open: one look at the processes (null: no answer). */\nexport async function lookAtLeftovers(leftovers: string[], io: LeftoverIo = {}): Promise<{ running: string[]; open: string[] } | null> {\n if (leftovers.length === 0) return { running: [], open: [] };\n const h = await (io.holders ?? ((d: string[]) => findHolders(d)))(leftovers).catch(() => null);\n if (!h) return null;\n const running = names(h.stoppable, leftovers);\n return { running, open: [...running, ...names(h.others, leftovers)] };\n}\n\n/** What runs from the leftovers now (\"node …\\vite\\bin\\vite.js --mode demo (PID 35464)\"): none to wait for, []. */\nexport async function runningFromLeftovers(leftovers: string[], io: LeftoverIo = {}): Promise<string[]> {\n return (await lookAtLeftovers(leftovers, io))?.running ?? [];\n}\n\n/** Stop what runs from the leftovers (asked for), saying what. */\nexport async function freeLeftovers(leftovers: string[], io: LeftoverIo = {}): Promise<string[]> {\n if (leftovers.length === 0) return [];\n return (io.stop ?? ((d: string[]) => stopRunningFrom(d)))(leftovers).catch(() => []);\n}\n\n/** Everything that has the leftovers open — what runs from them and what only names them (an editor) — for a failure's message. */\nexport async function openInLeftovers(leftovers: string[], io: LeftoverIo = {}): Promise<string[]> {\n return (await lookAtLeftovers(leftovers, io))?.open ?? [];\n}\n","/**\n * Starting a session on someone else's pull request — on their branch, so\n * what you push lands in their PR. Pure (the SPA and the demo use it): how a\n * PR is named, and what its session's Claude is told first. The lookup\n * (`gh pr view`) is `pr-start.ts`.\n */\n\nimport type { PrToStart } from '../api-types.js';\n\nexport type { PrToStart };\n\n/** A PR as you'd name it: its link (repo known), or its number (in a repo you pick). */\nexport interface PrRef {\n /** `owner/name`, lowercase, from a link. */\n repo?: string;\n number: number;\n}\n\n/** A PR link (`https://github.com/owner/repo/pull/123`, any tail), `#123` or `123`; null for anything else. */\nexport function parsePrRef(input: string): PrRef | null {\n const s = input.trim();\n const url = /^(?:https?:\\/\\/)?(?:www\\.)?github\\.com\\/([^/\\s]+)\\/([^/\\s]+)\\/pull\\/(\\d+)(?:[/?#].*)?$/i.exec(s);\n if (url) return { repo: `${url[1]}/${url[2]}`.toLowerCase(), number: Number(url[3]) };\n const n = /^#?(\\d+)$/.exec(s);\n return n && Number(n[1]) > 0 ? { number: Number(n[1]) } : null;\n}\n\n/**\n * The first message to the session's Claude: whose PR this is, that what it\n * pushes lands there, and to get up to speed — then do `instruction`, or\n * with none, say where it stands and wait for what the user wants. Nothing\n * on GitHub (no comments, reviews or replies): that's the author's\n * conversation.\n */\nexport function workOnPrPrompt(pr: Pick<PrToStart, 'number' | 'title' | 'url'> & { author?: string }, instruction?: string): string {\n const who = pr.author ? `@${pr.author}` : 'its author';\n const todo = instruction?.trim();\n const upToSpeed = `Get up to speed first (gh pr view ${pr.number}, gh pr diff ${pr.number})`;\n return [\n `Work on PR #${pr.number} by ${who}: ${pr.title}`,\n pr.url,\n '',\n `This worktree is on ${who}'s branch: what you commit and push lands in their PR.`,\n ...(todo ? [`${upToSpeed}, then:`, '', todo, ''] : [`${upToSpeed}, tell me where it stands, and wait for what I want done.`]),\n \"Don't post on GitHub (no comments, reviews or replies).\",\n ].join('\\n');\n}\n","import type { WorkConfig } from '../platform/config.js';\nimport { githubRepoOf } from './pr.js';\nimport { readGitConfig } from '../worktree/repo-scan.js';\nimport { parsePrRef, type PrToStart } from './pr-ref.js';\nimport { defaultRunner, type CommandRunner } from './ship.js';\n\nexport type PrStartResult = { ok: true; pr: PrToStart } | { ok: false; error: string };\n\nexport interface PrStartDeps {\n run?: CommandRunner;\n /** A repo's `.git/config` text (tests pass their own). */\n gitConfig?: (repoPath: string) => string | null;\n}\n\n/** The fields of `gh pr view --json …` this reads; all optional — it is someone else's output. */\ninterface GhPrView {\n number?: number;\n title?: string;\n url?: string;\n headRefName?: string;\n headRefOid?: string;\n baseRefName?: string;\n state?: string;\n isCrossRepository?: boolean;\n author?: { login?: string } | null;\n headRepositoryOwner?: { login?: string } | null;\n}\n\n/**\n * Which of your repos a PR is in, and its branch: from its link (the repo\n * matched by its origin) or its number (in `target`, a repo). Refused: a\n * repo you haven't enrolled, a group as the repo of a bare number, a PR\n * that isn't open, and one from a fork — its branch isn't on origin, so the\n * session couldn't push to it (and `work tree` would make a new, empty\n * branch of that name instead).\n */\nexport async function resolvePrToStart(\n input: string,\n config: Pick<WorkConfig, 'repos' | 'groups'>,\n target?: string,\n deps: PrStartDeps = {},\n): Promise<PrStartResult> {\n const run = deps.run ?? defaultRunner;\n const gitConfig = deps.gitConfig ?? readGitConfig;\n const ref = parsePrRef(input);\n if (!ref) return { ok: false, error: 'Give a pull request link (https://github.com/owner/repo/pull/123), or its number with a repo.' };\n\n const repoOf = (alias: string) => githubRepoOf(gitConfig(config.repos[alias]) ?? '');\n let alias: string | undefined;\n if (ref.repo) {\n const matches = Object.keys(config.repos).filter((a) => repoOf(a) === ref.repo);\n if (!matches.length) return { ok: false, error: `${ref.repo} isn't one of your repos: add it first (work config add <alias> <path>).` };\n // A target named beside a link must hold it: the repo itself, or a group with it among its repos.\n const within = target ? (config.groups?.[target] ?? [target]) : matches;\n alias = matches.find((a) => within.includes(a));\n if (!alias) return { ok: false, error: `PR #${ref.number} is in ${matches.join(' / ')} (${ref.repo}), not ${target}.` };\n } else {\n if (!target) return { ok: false, error: `PR #${ref.number}: which repo? Give its link, or pick the repo.` };\n if (config.groups?.[target])\n return { ok: false, error: `${target} is a group: a PR is one repo's. Give its link, or one of the group's repos.` };\n if (!config.repos[target]) return { ok: false, error: `${target} isn't one of your repos.` };\n alias = target;\n }\n const github = repoOf(alias);\n if (!github) return { ok: false, error: `${alias} isn't on github.com: work can only look up GitHub PRs.` };\n\n const view = await run(\n 'gh',\n [\n 'pr',\n 'view',\n String(ref.number),\n '--repo',\n github,\n '--json',\n 'number,title,url,headRefName,headRefOid,baseRefName,state,isCrossRepository,author,headRepositoryOwner',\n ],\n config.repos[alias],\n );\n if (view.code === 127) return { ok: false, error: 'GitHub CLI (gh) not found: install it to start from a PR.' };\n if (view.code !== 0)\n return { ok: false, error: `PR #${ref.number} in ${github}: ${view.stderr.trim().split('\\n')[0] || 'gh pr view failed'}` };\n let pr: GhPrView;\n try {\n pr = JSON.parse(view.stdout) as GhPrView;\n } catch {\n return { ok: false, error: \"Couldn't read what gh said about the PR.\" };\n }\n if (pr.state && pr.state !== 'OPEN') return { ok: false, error: `PR #${ref.number} is ${pr.state.toLowerCase()}.` };\n if (pr.isCrossRepository) {\n const owner = pr.headRepositoryOwner?.login ?? 'a fork';\n return {\n ok: false,\n error: `PR #${ref.number} comes from a fork (${owner}): its branch isn't on origin, so a session couldn't push to it.`,\n };\n }\n if (!pr.headRefName) return { ok: false, error: `PR #${ref.number}: gh didn't say its branch.` };\n const stale = await localGoneOtherWay(run, config.repos[alias], pr.headRefName, pr.headRefOid);\n if (stale) return { ok: false, error: stale };\n return {\n ok: true,\n pr: {\n alias,\n number: pr.number ?? ref.number,\n title: pr.title ?? '',\n url: pr.url ?? '',\n branch: pr.headRefName,\n base: pr.baseRefName ?? '',\n author: (pr.author?.login ?? '').replace(/^app\\//, ''),\n },\n };\n}\n\n/**\n * `work tree` takes a local branch of that name over origin's, moving it\n * forward when it can. One that has gone another way than the PR (the author\n * force-pushed, or an unrelated branch of the same name) would open on the\n * wrong commits, and what's pushed from it wouldn't go. Ahead (your commits\n * on top) or behind (it fast-forwards) is fine; when git can't tell (no\n * fetch), the usual warning on entering is left to say it.\n */\nasync function localGoneOtherWay(run: CommandRunner, repoPath: string, branch: string, headOid?: string): Promise<string | null> {\n if (!headOid) return null;\n const local = await run('git', ['rev-parse', '--verify', '--quiet', `refs/heads/${branch}`], repoPath);\n if (local.code !== 0) return null;\n await run('git', ['fetch', '--quiet', 'origin', branch], repoPath);\n const contains = await run('git', ['merge-base', '--is-ancestor', headOid, `refs/heads/${branch}`], repoPath);\n if (contains.code === 0) return null;\n const behind = await run('git', ['merge-base', '--is-ancestor', `refs/heads/${branch}`, headOid], repoPath);\n if (behind.code !== 1 || contains.code !== 1) return null; // 1 = not an ancestor; anything else: git couldn't say\n return `Your local branch ${branch} and the PR's have gone separate ways (a force-push, or another branch of that name): rename yours (git branch -m ${branch} ${branch}-old) and try again, or go into its session as it is (work tree <repo> ${branch}).`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoBO,SAAS,YAAY,OAA2B;AACrD,SAAO,MAAM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,0EAA0E,MAAM;AACzP;","names":["alias"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/cleanup/build-folders-scan.ts","../src/core/cleanup/build-folders-deps.ts","../src/core/cleanup/branch-tidy.ts","../src/core/cleanup/branch-tidy-deps.ts"],"sourcesContent":["import fs from 'node:fs';\nimport { buildFoldersOf, clearBuildFolders } from './build-folders.js';\nimport type { BuildFolder, BuildFolderCandidate, BuildFoldersApplyResult, BuildFoldersState } from '../api-types.js';\nimport type { CommandRunner } from '../pr/ship.js';\nimport type { ActivityLog } from '../platform/activity.js';\n\n/** Sessions idle at least this long are offered (a week). */\nexport const BUILD_FOLDERS_IDLE_MS = 7 * 24 * 60 * 60 * 1000;\n\nexport interface BuildFolderSession {\n id: string;\n target: string;\n branch: string;\n paths: string[];\n lastActiveMs: number;\n /** A Claude runs in it now: left alone (it may be building). */\n running: boolean;\n /** A repo's own checkout rather than a worktree. */\n baseCheckout?: boolean;\n}\n\nexport interface BuildFoldersDeps {\n sessions: () => Promise<BuildFolderSession[]>;\n run?: CommandRunner;\n now?: () => number;\n}\n\n/** Idle long enough, and no Claude in it: the rule for offering AND for clearing. */\nconst idleEnough = (s: BuildFolderSession, now: number) => !s.running && now - s.lastActiveMs >= BUILD_FOLDERS_IDLE_MS;\n\n/** The worktrees idle a week or more, and the build folders they hold, biggest first. */\nexport async function scanBuildFolders(\n deps: BuildFoldersDeps,\n onProgress?: (checked: number, total: number) => void,\n): Promise<BuildFolderCandidate[]> {\n const now = (deps.now ?? Date.now)();\n const eligible = (await deps.sessions()).filter((s) => idleEnough(s, now) && s.paths.some((p) => fs.existsSync(p)));\n const out: BuildFolderCandidate[] = [];\n let checked = 0;\n for (const s of eligible) {\n const folders: BuildFolder[] = [];\n for (const p of s.paths) if (fs.existsSync(p)) folders.push(...(await buildFoldersOf(p, deps.run)));\n const bytes = folders.reduce((n, f) => n + f.bytes, 0);\n if (bytes > 0)\n out.push({\n sessionId: s.id,\n target: s.target,\n branch: s.branch,\n ...(s.baseCheckout ? { baseCheckout: true } : {}),\n lastActive: new Date(s.lastActiveMs).toISOString(),\n folders,\n bytes,\n });\n onProgress?.(++checked, eligible.length);\n }\n return out.sort((a, b) => b.bytes - a.bytes);\n}\n\n/** One scan at a time; its latest result kept for the view. */\nexport function createBuildFoldersJob(deps: BuildFoldersDeps, activity?: ActivityLog) {\n let state: BuildFoldersState = { scanning: false, checked: 0, total: 0, scannedAt: null, candidates: [] };\n return {\n state: () => state,\n scan: () => {\n if (state.scanning) return;\n state = { ...state, scanning: true, checked: 0, total: 0 };\n const run = activity?.start('build-folders', 'Measuring build folders in idle worktrees');\n void scanBuildFolders(deps, (checked, total) => {\n state = { ...state, checked, total };\n run?.progress(checked, total);\n })\n .then((candidates) => {\n state = { ...state, scanning: false, candidates, scannedAt: new Date().toISOString() };\n const gb = candidates.reduce((n, c) => n + c.bytes, 0) / 1e9;\n run?.done(`${candidates.length} idle worktree${candidates.length === 1 ? '' : 's'} with build output · ${gb.toFixed(1)} GB`);\n })\n .catch((err: Error) => {\n state = { ...state, scanning: false };\n run?.fail(err.message);\n });\n },\n /** Clear the build folders of these sessions (each checked again as it goes). */\n apply: async (ids: string[]) => {\n const sessions = new Map((await deps.sessions()).map((s) => [s.id, s]));\n const results: BuildFoldersApplyResult[] = [];\n for (const id of ids) {\n const s = sessions.get(id);\n if (!s) {\n results.push({ sessionId: id, ok: false, removed: 0, message: 'Unknown session.' });\n continue;\n }\n if (s.running) {\n results.push({ sessionId: id, ok: false, removed: 0, message: 'Its Claude is running now: left alone.' });\n continue;\n }\n // Checked again, not trusted from the scan (or the caller): used since → left alone.\n if (!idleEnough(s, (deps.now ?? Date.now)())) {\n results.push({ sessionId: id, ok: false, removed: 0, message: 'Used in the last week: left alone.' });\n continue;\n }\n let removed = 0;\n const failed: string[] = [];\n for (const p of s.paths) {\n if (!fs.existsSync(p)) continue;\n const r = await clearBuildFolders(p, deps.run);\n removed += r.removed.length;\n failed.push(...r.failed.map((f) => f.path));\n }\n results.push({\n sessionId: id,\n ok: failed.length === 0,\n removed,\n message: failed.length ? `Could not remove: ${failed.join(', ')}` : `Removed ${removed} folder(s)`,\n });\n }\n const done = new Set(results.filter((r) => r.ok).map((r) => r.sessionId));\n state = { ...state, candidates: state.candidates.filter((c) => !done.has(c.sessionId)) };\n return results;\n },\n };\n}\n","import { defaultCleanupDeps } from './cleanup-deps.js';\nimport { normPath } from './cleanup.js';\nimport { loadConfig } from '../platform/config.js';\nimport { agentsBySession } from '../sessions/live-agents.js';\nimport { liveAgents } from '../agents/index.js';\nimport { loadHistory } from '../sessions/history.js';\nimport type { BuildFoldersDeps } from './build-folders-scan.js';\n\n/** The real inputs for the build-folder scan: cleanup's session list (with\n * \"last active\"), and which of them have a Claude running now. The same for\n * the dashboard and `work cleanup --build-folders`. */\nexport function defaultBuildFoldersDeps(): BuildFoldersDeps {\n const cleanup = defaultCleanupDeps();\n return {\n sessions: async () => {\n const running = agentsBySession(liveAgents(), loadHistory());\n const repos = new Set(Object.values(loadConfig()?.repos ?? {}).map(normPath));\n return (await cleanup.sessions()).map((s) => ({\n id: s.id,\n target: s.target,\n branch: s.branch,\n paths: s.paths,\n lastActiveMs: s.lastActiveMs,\n running: running.has(s.id),\n baseCheckout: s.paths.some((p) => repos.has(normPath(p))),\n }));\n },\n };\n}\n","import type { BranchCandidate } from '../api-types.js';\nimport { defaultRunner, type CommandRunner } from '../pr/ship.js';\n\n/**\n * Local branches whose work is already in the main branch, left behind after\n * their PR merged. Offered for deletion only when that is certain:\n *\n * - merged: `git branch --merged <origin's default>` lists it, or\n * - squash-merged: its upstream is gone and GitHub has a MERGED PR whose\n * head is exactly this branch's tip (a squash merge leaves no merge\n * commit to find).\n *\n * Never offered: a branch checked out in any worktree, one a current (not\n * archived) session uses, the default branch, or a long-lived name (main,\n * master, dev, develop, staging, production, …). An archived session's\n * branch is offered with a warning: its Restore needs the branch.\n */\n\nconst LONG_LIVED = /^(main|master|dev|develop|development|staging|stage|production|prod|release|trunk)$/;\n\nexport interface BranchRepo {\n alias: string;\n path: string;\n}\n\nexport interface BranchTidyDeps {\n repos: () => BranchRepo[];\n /** Branches sessions use, per repo alias → branch → the session. */\n sessionBranches: () => Map<string, Map<string, { id: string; archived: boolean }>>;\n run?: CommandRunner;\n}\n\nasync function git(run: CommandRunner, cwd: string, ...args: string[]) {\n return run('git', ['-C', cwd, ...args], cwd);\n}\n\n/** origin's default branch as a ref (origin/main), else a local main/master. */\nasync function baseRef(run: CommandRunner, repo: string): Promise<string | null> {\n const head = await git(run, repo, 'rev-parse', '--abbrev-ref', 'origin/HEAD');\n if (head.code === 0 && head.stdout.trim() && head.stdout.trim() !== 'origin/HEAD') return head.stdout.trim();\n for (const b of ['origin/main', 'origin/master', 'main', 'master']) {\n if ((await git(run, repo, 'rev-parse', '--verify', '--quiet', b)).code === 0) return b;\n }\n return null;\n}\n\n/** `only`: look at just these branches (the re-check before deleting), not every repo's. */\nexport async function findMergedBranches(deps: BranchTidyDeps, only?: Array<{ repo: string; branch: string }>): Promise<BranchCandidate[]> {\n const run = deps.run ?? defaultRunner;\n const sessions = deps.sessionBranches();\n const out: BranchCandidate[] = [];\n const wanted = only && new Set(only.map((o) => `${o.repo}\\0${o.branch}`));\n for (const repo of deps.repos()) {\n if (only && !only.some((o) => o.repo === repo.alias)) continue;\n const base = await baseRef(run, repo.path);\n if (!base) continue;\n const baseName = base.replace(/^origin\\//, '');\n const checkedOut = new Set(\n (await git(run, repo.path, 'worktree', 'list', '--porcelain')).stdout\n .split('\\n')\n .map((l) => /^branch refs\\/heads\\/(.+)$/.exec(l.trim())?.[1])\n .filter((b): b is string => !!b),\n );\n const merged = new Set(\n (await git(run, repo.path, 'branch', '--merged', base, '--format=%(refname:short)')).stdout\n .split('\\n')\n .map((l) => l.trim())\n .filter(Boolean),\n );\n const refs = (\n await git(run, repo.path, 'for-each-ref', '--format=%(refname:short)%09%(objectname)%09%(upstream:track)', 'refs/heads')\n ).stdout\n .split('\\n')\n .map((l) => l.split('\\t'))\n .filter((p) => p[0]);\n const used = sessions.get(repo.alias) ?? new Map();\n for (const [branch, tip, track] of refs) {\n if (wanted && !wanted.has(`${repo.alias}\\0${branch}`)) continue;\n if (branch === baseName || LONG_LIVED.test(branch) || checkedOut.has(branch)) continue;\n const session = used.get(branch);\n if (session && !session.archived) continue;\n let reason: BranchCandidate['reason'] | null = null;\n let prNumber: number | undefined;\n if (merged.has(branch)) reason = 'merged';\n else if ((track ?? '').includes('gone')) {\n const pr = await run(\n 'gh',\n ['pr', 'list', '--state', 'merged', '--head', branch, '--json', 'number,headRefOid', '--limit', '5'],\n repo.path,\n );\n if (pr.code === 0) {\n try {\n const list = JSON.parse(pr.stdout) as Array<{ number: number; headRefOid: string }>;\n const hit = list.find((p) => p.headRefOid === tip);\n if (hit) {\n reason = 'squash-merged';\n prNumber = hit.number;\n }\n } catch {\n /* not JSON: not certain, not offered */\n }\n }\n }\n if (!reason) continue;\n out.push({\n repo: repo.alias,\n repoPath: repo.path,\n branch,\n tip,\n reason,\n ...(prNumber ? { prNumber } : {}),\n ...(session ? { archivedSession: session.id } : {}),\n });\n }\n }\n return out;\n}\n\n/**\n * Delete the chosen branches — each checked again first (still merged, still\n * not checked out, and at the `tip` you were shown when one is given), then\n * `git branch -D` (a squash merge is not \"merged\" to git, so -d would refuse\n * what we just verified).\n */\nexport async function deleteMergedBranches(\n chosen: Array<{ repo: string; branch: string; tip?: string }>,\n deps: BranchTidyDeps,\n): Promise<Array<{ repo: string; branch: string; ok: boolean; message: string }>> {\n const run = deps.run ?? defaultRunner;\n const fresh = await findMergedBranches(deps, chosen);\n const results: Array<{ repo: string; branch: string; ok: boolean; message: string }> = [];\n for (const { repo, branch, tip } of chosen) {\n const now = fresh.find((f) => f.repo === repo && f.branch === branch);\n if (!now) {\n results.push({ repo, branch, ok: false, message: 'Not deleted: no longer certain it is merged (or it is in use).' });\n continue;\n }\n if (tip && now.tip !== tip) {\n results.push({ repo, branch, ok: false, message: 'Not deleted: it has moved since you looked.' });\n continue;\n }\n const r = await git(run, now.repoPath, 'branch', '-D', now.branch);\n results.push({\n repo,\n branch,\n ok: r.code === 0,\n message: r.code === 0 ? `Deleted (was ${now.tip.slice(0, 8)})` : r.stderr.trim() || 'git refused',\n });\n }\n return results;\n}\n","import fs from 'node:fs';\nimport { loadConfig } from '../platform/config.js';\nimport { loadHistory } from '../sessions/history.js';\nimport { sessionIdFor } from '../sessions/session-id.js';\nimport type { WorktreeSession } from '../sessions/session-types.js';\nimport type { BranchTidyDeps } from './branch-tidy.js';\nimport { sessionAliases } from '../sessions/session-repos.js';\n\n/**\n * Which branches sessions use, per repo alias. A repo + branch can belong to\n * several sessions (a single-repo one and a group's): a current one's use\n * wins over an archived one's, whatever order the history lists them in.\n */\nexport function sessionBranchUse(\n sessions: WorktreeSession[],\n groups: Record<string, string[]>,\n): Map<string, Map<string, { id: string; archived: boolean }>> {\n const out = new Map<string, Map<string, { id: string; archived: boolean }>>();\n for (const s of sessions) {\n // Its own repos (a row from before: the group's config members).\n const aliases = sessionAliases(s, { groups });\n for (const a of aliases) {\n const m = out.get(a) ?? new Map<string, { id: string; archived: boolean }>();\n if (m.get(s.branch)?.archived !== false) m.set(s.branch, { id: sessionIdFor(s), archived: !!s.archivedAt });\n out.set(a, m);\n }\n }\n return out;\n}\n\n/** The real inputs: the configured repos, and which branches sessions use (per repo alias). */\nexport function defaultBranchTidyDeps(): BranchTidyDeps {\n return {\n repos: () =>\n Object.entries(loadConfig()?.repos ?? {})\n .filter(([, p]) => fs.existsSync(p))\n .map(([alias, path]) => ({ alias, path })),\n sessionBranches: () => sessionBranchUse(loadHistory(), loadConfig()?.groups ?? {}),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,QAAQ;AAOR,IAAM,wBAAwB,IAAI,KAAK,KAAK,KAAK;AAqBxD,IAAM,aAAa,CAAC,GAAuB,QAAgB,CAAC,EAAE,WAAW,MAAM,EAAE,gBAAgB;AAGjG,eA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,UAAU,eAAe,GAAG,EAAE,OAAO,CAAC;AAC5C,eAAW,KAAK,SAAS;AACvB,YAAM,IAAI,IAAI,IAAI,CAAC,KAAK,oBAAI,IAA+C;AAC3E,UAAI,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,MAAO,GAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,aAAa,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,WAAW,CAAC;AAC1G,UAAI,IAAI,GAAG,CAAC;AAAA,IACd;AAAA,EACF;AACA,SAAO;AACT;AAGO,SAAS,wBAAwC;AACtD,SAAO;AAAA,IACL,OAAO,MACL,OAAO,QAAQ,WAAW,GAAG,SAAS,CAAC,CAAC,EACrC,OAAO,CAAC,CAAC,EAAE,CAAC,MAAMC,IAAG,WAAW,CAAC,CAAC,EAClC,IAAI,CAAC,CAAC,OAAO,IAAI,OAAO,EAAE,OAAO,KAAK,EAAE;AAAA,IAC7C,iBAAiB,MAAM,iBAAiB,YAAY,GAAG,WAAW,GAAG,UAAU,CAAC,CAAC;AAAA,EACnF;AACF;","names":["fs","fs"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/platform/launch.ts"],"sourcesContent":["import spawn from './spawn.js';\nimport { detachHere } from './process.js';\nimport { applyEnvDelta, hasEnvDelta, type EnvDelta } from './env-delta.js';\nimport { buildAiLaunchArgs, type AiLaunchOpts, type AiToolSpec } from './ai-launcher.js';\n\n/** Get the platform-appropriate default editor. */\nexport function getEditor(): string {\n return process.env.EDITOR ?? process.env.VISUAL ?? (process.platform === 'win32' ? 'notepad' : 'vi');\n}\n\n/** Open a file in the user's editor. */\nexport function openInEditor(filePath: string): void {\n const editor = getEditor();\n // This terminal's (vi) or a window of its own (notepad): to be seen.\n spawn.sync(editor, [filePath], { stdio: 'inherit', windowsHide: false });\n}\n\n/** Open a URL in the default browser. */\nexport function openUrl(url: string): void {\n const cmd = process.platform === 'win32' ? 'cmd' : process.platform === 'darwin' ? 'open' : 'xdg-open';\n const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url];\n // `cmd /c start` is a console program: hidden, or a window flashes before the browser opens.\n spawn(cmd, args, { stdio: 'ignore', detached: detachHere(), windowsHide: true }).unref();\n}\n\n/** VS Code and the editors built on it: the folder, then `--goto file:line`, opens the file at its line in that folder's window. */\nconst VSCODE_LIKE = /^(code|code-insiders|codium|vscodium|cursor|windsurf)$/i;\n/** JetBrains' launchers: `--line N file`. */\nconst JETBRAINS = /^(idea|rider|webstorm|pycharm|goland|clion|phpstorm|rubymine|datagrip)(64)?$/i;\n/** Sublime Text: `file:line`. */\nconst SUBLIME = /^(subl|sublime_text)$/i;\n\n/**\n * The arguments that open `folder` in `editor`, or a file in it at a line. An editor work doesn't know how to send\n * to a line gets the file alone (it opens at the top); with no file, the folder, as before.\n */\nexport function editorArgs(editor: string, folder: string, file?: { path: string; line?: number }): string[] {\n if (!file) return [folder];\n // Either separator, whatever this platform's: a config written on Windows names `C:\\…\\code.cmd`.\n const name = (editor.trim().split(/[\\\\/]/).pop() ?? '').replace(/\\.(cmd|bat|exe|sh)$/i, '');\n const line = file.line && file.line > 0 ? Math.floor(file.line) : undefined;\n if (VSCODE_LIKE.test(name)) return [folder, '--goto', line ? `${file.path}:${line}` : file.path];\n if (JETBRAINS.test(name)) return line ? [folder, '--line', String(line), file.path] : [folder, file.path];\n if (SUBLIME.test(name)) return [folder, line ? `${file.path}:${line}` : file.path];\n return [file.path];\n}\n\n/** Open VS Code in the given directory. */\nexport function openVSCode(dir: string): void {\n spawn.sync('code', ['.'], { cwd: dir, stdio: 'inherit', windowsHide: false }); // the editor's window is the point\n}\n\n/**\n * Launch the configured AI tool in the given directory.\n *\n * When `port` is provided it is injected as `$PORT` into the launched process\n * so dev servers started by parallel agent sessions don't collide.\n */\nexport function launchAi(cwd: string, tool: AiToolSpec, opts: AiLaunchOpts = {}, port?: number, agentEnv?: EnvDelta): void {\n const { cmd, args } = buildAiLaunchArgs(tool, opts);\n // This terminal's environment, with the session's account change over it (agent.launch.env) and its port.\n const env =\n hasEnvDelta(agentEnv) || port !== undefined\n ? { ...applyEnvDelta(process.env, agentEnv), ...(port !== undefined ? { PORT: String(port) } : {}) }\n : undefined;\n const spawnOpts: Parameters<typeof spawn.sync>[2] =\n // The AI tool runs in this terminal: nothing to hide.\n env ? { cwd, stdio: 'inherit', windowsHide: false, env: env as NodeJS.ProcessEnv } : { cwd, stdio: 'inherit', windowsHide: false };\n spawn.sync(cmd, args, spawnOpts);\n}\n"],"mappings":";;;;;;;;;;;;;;AAMO,SAAS,YAAoB;AAClC,SAAO,QAAQ,IAAI,UAAU,QAAQ,IAAI,WAAW,QAAQ,aAAa,UAAU,YAAY;AACjG;AAGO,SAAS,aAAa,UAAwB;AACnD,QAAM,SAAS,UAAU;AAEzB,gBAAM,KAAK,QAAQ,CAAC,QAAQ,GAAG,EAAE,OAAO,WAAW,aAAa,MAAM,CAAC;AACzE;AAGO,SAAS,QAAQ,KAAmB;AACzC,QAAM,MAAM,QAAQ,aAAa,UAAU,QAAQ,QAAQ,aAAa,WAAW,SAAS;AAC5F,QAAM,OAAO,QAAQ,aAAa,UAAU,CAAC,MAAM,SAAS,IAAI,GAAG,IAAI,CAAC,GAAG;AAE3E,gBAAM,KAAK,MAAM,EAAE,OAAO,UAAU,UAAU,WAAW,GAAG,aAAa,KAAK,CAAC,EAAE,MAAM;AACzF;AAGA,IAAM,cAAc;AAEpB,IAAM,YAAY;AAElB,IAAM,UAAU;AAMT,SAAS,WAAW,QAAgB,QAAgB,MAAkD;AAC3G,MAAI,CAAC,KAAM,QAAO,CAAC,MAAM;AAEzB,QAAM,QAAQ,OAAO,KAAK,EAAE,MAAM,OAAO,EAAE,IAAI,KAAK,IAAI,QAAQ,wBAAwB,EAAE;AAC1F,QAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,IAAI,KAAK,MAAM,KAAK,IAAI,IAAI;AAClE,MAAI,YAAY,KAAK,IAAI,EAAG,QAAO,CAAC,QAAQ,UAAU,OAAO,GA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