@moberg_hr/work-tree 2.11.4 → 2.12.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 (312) hide show
  1. package/dist/{account-JOKEFQ46.js → account-V6GS7DII.js} +41 -27
  2. package/dist/account-V6GS7DII.js.map +1 -0
  3. package/dist/{add-repo-JKVHNRWU.js → add-repo-HG24PKHR.js} +25 -25
  4. package/dist/{answer-PDCLL5Z2.js → answer-S3VZFV4N.js} +15 -15
  5. package/dist/{attach-BIFQP5OY.js → attach-RKIACTP2.js} +21 -21
  6. package/dist/bin.js +4 -4
  7. package/dist/{block-EI3OQVDM.js → block-UUK564QX.js} +20 -20
  8. package/dist/{broadcast-ZSA3L5FY.js → broadcast-73JJELJF.js} +12 -12
  9. package/dist/{catchup-SNMGWNRX.js → catchup-JUEBM3QQ.js} +18 -18
  10. package/dist/{chunk-RIEBQWQC.js → chunk-2KW4TFVP.js} +2 -2
  11. package/dist/{chunk-33XSEAHO.js → chunk-2Y2ARDXI.js} +2 -2
  12. package/dist/{chunk-HECIDNBU.js → chunk-2YTCAJT5.js} +11 -11
  13. package/dist/{chunk-WV5U4S5N.js → chunk-3GCD3DAB.js} +9 -9
  14. package/dist/{chunk-DMGNJ73M.js → chunk-42MD5W5R.js} +49 -4
  15. package/dist/chunk-42MD5W5R.js.map +1 -0
  16. package/dist/{chunk-SC2FQ6BR.js → chunk-4F2AH2LC.js} +5 -5
  17. package/dist/{chunk-KJRUC2QY.js → chunk-4GNX6CQ2.js} +3 -3
  18. package/dist/{chunk-F7IOGLKV.js → chunk-4GPKT5A2.js} +29 -9
  19. package/dist/chunk-4GPKT5A2.js.map +1 -0
  20. package/dist/{chunk-GAE3NB3G.js → chunk-52KXG5D3.js} +10 -10
  21. package/dist/{chunk-6MMXVHPL.js → chunk-552RUECR.js} +7 -7
  22. package/dist/{chunk-RUUEZSQY.js → chunk-5VV5IQC6.js} +12 -10
  23. package/dist/{chunk-RUUEZSQY.js.map → chunk-5VV5IQC6.js.map} +1 -1
  24. package/dist/{chunk-E6WVQXF4.js → chunk-6Q4PTZ3J.js} +3 -3
  25. package/dist/{chunk-7OZZUQDW.js → chunk-6RVZYOED.js} +5 -5
  26. package/dist/{chunk-CL3SSNBC.js → chunk-6SRDHIAK.js} +3 -3
  27. package/dist/{chunk-K7Y7YTN3.js → chunk-7LQTBAYP.js} +2 -2
  28. package/dist/{chunk-PMEOGFGV.js → chunk-7UXV4X2Y.js} +2 -2
  29. package/dist/{chunk-GV3KXHF3.js → chunk-7XT5MRJ2.js} +4 -4
  30. package/dist/{chunk-BLOV7ECI.js → chunk-AGRUEZQX.js} +2 -2
  31. package/dist/{chunk-RH4BGTER.js → chunk-AMEJQT64.js} +4 -4
  32. package/dist/{chunk-2R6EHVZG.js → chunk-AORYYUMW.js} +4 -4
  33. package/dist/{chunk-HRUKMBF3.js → chunk-AYHDJMMJ.js} +2 -2
  34. package/dist/{chunk-7HQM5NYN.js → chunk-BK73QU45.js} +3 -3
  35. package/dist/{chunk-DMA3XCMF.js → chunk-BMNH6B5U.js} +11 -7
  36. package/dist/chunk-BMNH6B5U.js.map +1 -0
  37. package/dist/{chunk-M7FX37Z2.js → chunk-CLPCEQA2.js} +10 -8
  38. package/dist/{chunk-M7FX37Z2.js.map → chunk-CLPCEQA2.js.map} +1 -1
  39. package/dist/{chunk-KP2CI5QU.js → chunk-CS5VPO7A.js} +5 -5
  40. package/dist/{chunk-FFL7ETBY.js → chunk-D7ZQNQOJ.js} +7 -7
  41. package/dist/{chunk-VQACXAFX.js → chunk-DW245WK4.js} +9 -4
  42. package/dist/chunk-DW245WK4.js.map +1 -0
  43. package/dist/{chunk-MBSCZQ2C.js → chunk-DZ6SLAIZ.js} +2 -2
  44. package/dist/{chunk-BDPRYJL3.js → chunk-FFYYODXG.js} +2 -2
  45. package/dist/{chunk-WYQD44Y4.js → chunk-G2V2V5UC.js} +7 -3
  46. package/dist/chunk-G2V2V5UC.js.map +1 -0
  47. package/dist/{chunk-3XU7Y2MV.js → chunk-G6JZ3ZQI.js} +2 -2
  48. package/dist/chunk-G7OFGBLT.js +9 -0
  49. package/dist/{chunk-MGNJPBZU.js → chunk-GGYXNTEB.js} +6 -6
  50. package/dist/{chunk-NFWSJFYY.js → chunk-HHXVHUGP.js} +2 -2
  51. package/dist/{chunk-YKQLHFY4.js → chunk-HUD4JLK3.js} +58 -6
  52. package/dist/chunk-HUD4JLK3.js.map +1 -0
  53. package/dist/{chunk-U3RRXU6W.js → chunk-HUX6XT2P.js} +7 -7
  54. package/dist/{chunk-PHHBZDO2.js → chunk-HXQYGI3R.js} +58 -58
  55. package/dist/{chunk-O5ZJY5BT.js → chunk-INI6TEYT.js} +2 -1
  56. package/dist/chunk-INI6TEYT.js.map +1 -0
  57. package/dist/{chunk-7OFVXQSM.js → chunk-JQ42ERH3.js} +2 -2
  58. package/dist/{chunk-2VYWTBC6.js → chunk-JVG4U3LK.js} +4 -4
  59. package/dist/{chunk-CSTPOCV2.js → chunk-K5EAVRXX.js} +3 -3
  60. package/dist/{chunk-3PXA5RJ2.js → chunk-KHGP6MS2.js} +38 -119
  61. package/dist/chunk-KHGP6MS2.js.map +1 -0
  62. package/dist/{chunk-QRYZAY7R.js → chunk-KX75V4AT.js} +9 -9
  63. package/dist/{chunk-SMXRY653.js → chunk-LN2DDJGG.js} +8 -8
  64. package/dist/{chunk-HJ2RKMBI.js → chunk-LNRODEIP.js} +2 -2
  65. package/dist/{chunk-KKVWDMSM.js → chunk-LSZ6HI3U.js} +2 -2
  66. package/dist/{chunk-BTR2E5WD.js → chunk-LYZQ6IKY.js} +18 -17
  67. package/dist/chunk-LYZQ6IKY.js.map +1 -0
  68. package/dist/{chunk-N75AJ3ZR.js → chunk-M4NZ4UJA.js} +4 -4
  69. package/dist/{chunk-253Q6TOC.js → chunk-MKQ7IA6U.js} +3 -3
  70. package/dist/{chunk-DGVCN7HB.js → chunk-MOTKVMGL.js} +2 -2
  71. package/dist/{chunk-CJ2QTQHG.js → chunk-MX3JVY64.js} +2 -2
  72. package/dist/{chunk-TW44C7CG.js → chunk-NDIAONVE.js} +7 -7
  73. package/dist/{chunk-RXZKYHSW.js → chunk-NGHIFLCM.js} +5 -5
  74. package/dist/{chunk-XZKQHQBB.js → chunk-NLSFJYU6.js} +8 -6
  75. package/dist/{chunk-XZKQHQBB.js.map → chunk-NLSFJYU6.js.map} +1 -1
  76. package/dist/{chunk-LPHYUNMD.js → chunk-P6LDKZEY.js} +7 -5
  77. package/dist/{chunk-LPHYUNMD.js.map → chunk-P6LDKZEY.js.map} +1 -1
  78. package/dist/{chunk-3QEDOZMA.js → chunk-QJZCTK25.js} +4 -4
  79. package/dist/{chunk-AU7XGTJZ.js → chunk-QULZNML4.js} +3 -3
  80. package/dist/{chunk-RUYTU2WJ.js → chunk-RRNIJ7YO.js} +7 -3
  81. package/dist/chunk-RRNIJ7YO.js.map +1 -0
  82. package/dist/{chunk-7DUGVGUZ.js → chunk-RVSRZ57P.js} +2 -2
  83. package/dist/{chunk-ZX2VBM2F.js → chunk-S4L6BURS.js} +4 -4
  84. package/dist/{chunk-SQ4ZGEZY.js → chunk-SNUAISLX.js} +2 -2
  85. package/dist/{chunk-VADGWMXL.js → chunk-SOOPR7HU.js} +7 -7
  86. package/dist/{chunk-IYWNDEXA.js → chunk-SQI5NYRZ.js} +6 -6
  87. package/dist/{chunk-6C7CR2W2.js → chunk-TMBO55MM.js} +2 -2
  88. package/dist/{chunk-5DUKO7WC.js → chunk-TUDDISCX.js} +6 -3
  89. package/dist/{chunk-3LDQPUJ6.js → chunk-TW57JSKU.js} +11 -11
  90. package/dist/{chunk-3UI35AFZ.js → chunk-U2MOKVPZ.js} +2 -2
  91. package/dist/{chunk-JVHHSKBJ.js → chunk-UH72CZAX.js} +2 -2
  92. package/dist/{chunk-6UTH3A76.js → chunk-UVZITL47.js} +1 -1
  93. package/dist/chunk-UVZITL47.js.map +1 -0
  94. package/dist/{chunk-73MGZAGV.js → chunk-UXL75FQC.js} +6 -6
  95. package/dist/{chunk-BENY64FW.js → chunk-WIJO2LYS.js} +4 -4
  96. package/dist/{chunk-VJ5XMYXE.js → chunk-XTRC6IOA.js} +3 -3
  97. package/dist/{chunk-WQN7HJK6.js → chunk-XXKEL6JG.js} +12 -12
  98. package/dist/chunk-Y2RCCYRA.js +37 -0
  99. package/dist/chunk-Y2RCCYRA.js.map +1 -0
  100. package/dist/{chunk-2YKV6MNQ.js → chunk-YWB42FW6.js} +3 -3
  101. package/dist/{chunk-KCDHOW22.js → chunk-Z6B4ICOI.js} +188 -96
  102. package/dist/chunk-Z6B4ICOI.js.map +1 -0
  103. package/dist/{chunk-5ZU6H62F.js → chunk-ZIFWZJ7X.js} +2 -2
  104. package/dist/{chunk-GG4VKPAX.js → chunk-ZLQGKBBE.js} +2 -2
  105. package/dist/{chunk-ZJBVZ4OJ.js → chunk-ZRY7AOET.js} +6 -6
  106. package/dist/{chunk-3QKH7JNR.js → chunk-ZS7ZXAXB.js} +33 -2
  107. package/dist/chunk-ZS7ZXAXB.js.map +1 -0
  108. package/dist/{cleanup-5CPX253G.js → cleanup-5DPCUQJQ.js} +43 -43
  109. package/dist/cli-IELHMGEY.js +20 -0
  110. package/dist/{completion-QCB7PKKT.js → completion-OEU4UZEA.js} +4 -4
  111. package/dist/{config-EQFAXBMQ.js → config-E6ORLTCE.js} +17 -17
  112. package/dist/{diff-MLCUMIYC.js → diff-DQFERMIX.js} +17 -17
  113. package/dist/{digest-KSAGLQND.js → digest-ALSU7EYK.js} +14 -14
  114. package/dist/{fork-RCTVMUYI.js → fork-NY4QWSPG.js} +39 -39
  115. package/dist/{history-N4ZURR4F.js → history-JY54YEZX.js} +11 -11
  116. package/dist/{hook-DRZVYLJB.js → hook-7Q53RMB2.js} +20 -20
  117. package/dist/{hydrate-NVJZZAFT.js → hydrate-PV3F3QEI.js} +13 -13
  118. package/dist/{init-RF6YC4BQ.js → init-OH6UWFOJ.js} +22 -22
  119. package/dist/install-skills-7DE3ADWA.js +23 -0
  120. package/dist/install-skills-bin.js +9 -9
  121. package/dist/{keep-7Q3B6QT5.js → keep-H5VWXD2E.js} +14 -14
  122. package/dist/{list-PIJ4ROHR.js → list-7OTXLACR.js} +13 -13
  123. package/dist/{move-XAZG3MJT.js → move-UOKARORU.js} +28 -28
  124. package/dist/{note-JJXIQ4QK.js → note-2BW5MIC6.js} +15 -15
  125. package/dist/{overlaps-3YN4UQWC.js → overlaps-UHF6XJML.js} +21 -21
  126. package/dist/{pin-OOCB6DFR.js → pin-GP6BZYYM.js} +15 -15
  127. package/dist/{pr-LCG4W65A.js → pr-F5PWLPUU.js} +30 -30
  128. package/dist/{prune-2NGAUOPI.js → prune-ISXTZRRM.js} +41 -41
  129. package/dist/{pty-host-XRXRI6UL.js → pty-host-IKZRLX3W.js} +39 -19
  130. package/dist/pty-host-IKZRLX3W.js.map +1 -0
  131. package/dist/{read-FJDDCX4D.js → read-ARVCB7A2.js} +14 -14
  132. package/dist/{recent-AAXLCQUF.js → recent-NZMHV2NQ.js} +20 -20
  133. package/dist/{remove-VO5V45IJ.js → remove-NCWMZUDU.js} +53 -41
  134. package/dist/remove-NCWMZUDU.js.map +1 -0
  135. package/dist/{restart-AP763LE2.js → restart-QQEWWBSM.js} +15 -15
  136. package/dist/{resume-SPO5XNDT.js → resume-V4P7XAT2.js} +20 -20
  137. package/dist/{review-5IGFQF2T.js → review-VCMEMSGB.js} +14 -11
  138. package/dist/review-VCMEMSGB.js.map +1 -0
  139. package/dist/{review-now-HHQIBVUS.js → review-now-NXMBEJ5R.js} +4 -4
  140. package/dist/{run-JZWZHJOE.js → run-M4RWGT2R.js} +11 -11
  141. package/dist/{screen-JRMMYVHB.js → screen-KCVCST6K.js} +15 -15
  142. package/dist/{search-XOWMVFP2.js → search-BRKX3NF5.js} +11 -11
  143. package/dist/{section-7WO7IHG6.js → section-272JIEIG.js} +15 -15
  144. package/dist/{send-OCSMOCUE.js → send-4LFQLZR3.js} +16 -16
  145. package/dist/{sessions-UAZALGGH.js → sessions-Y7JJHAVI.js} +34 -34
  146. package/dist/{snooze-UDJ5UDCS.js → snooze-LJ3INJ47.js} +14 -14
  147. package/dist/{start-OEG3T2SW.js → start-MULJ7JIP.js} +15 -15
  148. package/dist/{state-BR43ONIH.js → state-LDDRQFWX.js} +7 -5
  149. package/dist/{state-BR43ONIH.js.map → state-LDDRQFWX.js.map} +1 -1
  150. package/dist/{status-R4T2EHG5.js → status-Q4ZX37RP.js} +18 -18
  151. package/dist/{statusline-3H3HAPCZ.js → statusline-MIFW47UA.js} +7 -7
  152. package/dist/{statusline-hook-FILOARNM.js → statusline-hook-W7KWKWAC.js} +5 -5
  153. package/dist/{stop-D3LRCCJS.js → stop-CBCMLFNH.js} +15 -15
  154. package/dist/{sync-FWC2EWLW.js → sync-IYFBEFQX.js} +41 -41
  155. package/dist/{time-AMAMIDWD.js → time-WSCPEGQC.js} +16 -16
  156. package/dist/{time-actions-YOXF5WC7.js → time-actions-KYFYV7F2.js} +4 -4
  157. package/dist/{timesheet-QFBA2Z2A.js → timesheet-6W6OPPVP.js} +23 -23
  158. package/dist/{todo-TALKJYK6.js → todo-54OJY5VV.js} +4 -4
  159. package/dist/{tree-PJM2R2VA.js → tree-32OEZDDU.js} +48 -43
  160. package/dist/{tree-PJM2R2VA.js.map → tree-32OEZDDU.js.map} +1 -1
  161. package/dist/{update-RVZMM54Z.js → update-JQSKHI47.js} +24 -24
  162. package/dist/{usage-W4UXQUPD.js → usage-5BOIIANY.js} +14 -14
  163. package/dist/{version-WPF664CL.js → version-4S7I7GHM.js} +9 -9
  164. package/dist/{wait-C3S7Q6FA.js → wait-I3I35CV6.js} +15 -15
  165. package/dist/wd-bin.js +7 -7
  166. package/dist/web/assets/{PtyView-Bq8MHIjd.js → PtyView-BLYE_3wP.js} +2 -2
  167. package/dist/web/assets/{PtyView-Bq8MHIjd.js.map → PtyView-BLYE_3wP.js.map} +1 -1
  168. package/dist/web/assets/{index-vHIk7hQs.css → index-I3G9prc8.css} +1 -1
  169. package/dist/web/assets/index-k8sUbiKa.js +126 -0
  170. package/dist/web/assets/index-k8sUbiKa.js.map +1 -0
  171. package/dist/web/index.html +2 -2
  172. package/dist/{web-MPSYOYQ2.js → web-JBDK5WWW.js} +1955 -1119
  173. package/dist/web-JBDK5WWW.js.map +1 -0
  174. package/npm-shrinkwrap.json +2 -2
  175. package/package.json +1 -1
  176. package/dist/account-JOKEFQ46.js.map +0 -1
  177. package/dist/chunk-3PXA5RJ2.js.map +0 -1
  178. package/dist/chunk-3QKH7JNR.js.map +0 -1
  179. package/dist/chunk-6UTH3A76.js.map +0 -1
  180. package/dist/chunk-AWY2HWAQ.js +0 -9
  181. package/dist/chunk-BTR2E5WD.js.map +0 -1
  182. package/dist/chunk-DMA3XCMF.js.map +0 -1
  183. package/dist/chunk-DMGNJ73M.js.map +0 -1
  184. package/dist/chunk-F7IOGLKV.js.map +0 -1
  185. package/dist/chunk-KCDHOW22.js.map +0 -1
  186. package/dist/chunk-O5ZJY5BT.js.map +0 -1
  187. package/dist/chunk-RUYTU2WJ.js.map +0 -1
  188. package/dist/chunk-VQACXAFX.js.map +0 -1
  189. package/dist/chunk-WYQD44Y4.js.map +0 -1
  190. package/dist/chunk-YKQLHFY4.js.map +0 -1
  191. package/dist/cli-D2RPZWWM.js +0 -20
  192. package/dist/install-skills-DV7JBW56.js +0 -23
  193. package/dist/pty-host-XRXRI6UL.js.map +0 -1
  194. package/dist/remove-VO5V45IJ.js.map +0 -1
  195. package/dist/review-5IGFQF2T.js.map +0 -1
  196. package/dist/web/assets/index-DkVQmwkZ.js +0 -126
  197. package/dist/web/assets/index-DkVQmwkZ.js.map +0 -1
  198. package/dist/web-MPSYOYQ2.js.map +0 -1
  199. /package/dist/{add-repo-JKVHNRWU.js.map → add-repo-HG24PKHR.js.map} +0 -0
  200. /package/dist/{answer-PDCLL5Z2.js.map → answer-S3VZFV4N.js.map} +0 -0
  201. /package/dist/{attach-BIFQP5OY.js.map → attach-RKIACTP2.js.map} +0 -0
  202. /package/dist/{block-EI3OQVDM.js.map → block-UUK564QX.js.map} +0 -0
  203. /package/dist/{broadcast-ZSA3L5FY.js.map → broadcast-73JJELJF.js.map} +0 -0
  204. /package/dist/{catchup-SNMGWNRX.js.map → catchup-JUEBM3QQ.js.map} +0 -0
  205. /package/dist/{chunk-RIEBQWQC.js.map → chunk-2KW4TFVP.js.map} +0 -0
  206. /package/dist/{chunk-33XSEAHO.js.map → chunk-2Y2ARDXI.js.map} +0 -0
  207. /package/dist/{chunk-HECIDNBU.js.map → chunk-2YTCAJT5.js.map} +0 -0
  208. /package/dist/{chunk-WV5U4S5N.js.map → chunk-3GCD3DAB.js.map} +0 -0
  209. /package/dist/{chunk-SC2FQ6BR.js.map → chunk-4F2AH2LC.js.map} +0 -0
  210. /package/dist/{chunk-KJRUC2QY.js.map → chunk-4GNX6CQ2.js.map} +0 -0
  211. /package/dist/{chunk-GAE3NB3G.js.map → chunk-52KXG5D3.js.map} +0 -0
  212. /package/dist/{chunk-6MMXVHPL.js.map → chunk-552RUECR.js.map} +0 -0
  213. /package/dist/{chunk-E6WVQXF4.js.map → chunk-6Q4PTZ3J.js.map} +0 -0
  214. /package/dist/{chunk-7OZZUQDW.js.map → chunk-6RVZYOED.js.map} +0 -0
  215. /package/dist/{chunk-CL3SSNBC.js.map → chunk-6SRDHIAK.js.map} +0 -0
  216. /package/dist/{chunk-K7Y7YTN3.js.map → chunk-7LQTBAYP.js.map} +0 -0
  217. /package/dist/{chunk-PMEOGFGV.js.map → chunk-7UXV4X2Y.js.map} +0 -0
  218. /package/dist/{chunk-GV3KXHF3.js.map → chunk-7XT5MRJ2.js.map} +0 -0
  219. /package/dist/{chunk-BLOV7ECI.js.map → chunk-AGRUEZQX.js.map} +0 -0
  220. /package/dist/{chunk-RH4BGTER.js.map → chunk-AMEJQT64.js.map} +0 -0
  221. /package/dist/{chunk-2R6EHVZG.js.map → chunk-AORYYUMW.js.map} +0 -0
  222. /package/dist/{chunk-HRUKMBF3.js.map → chunk-AYHDJMMJ.js.map} +0 -0
  223. /package/dist/{chunk-7HQM5NYN.js.map → chunk-BK73QU45.js.map} +0 -0
  224. /package/dist/{chunk-KP2CI5QU.js.map → chunk-CS5VPO7A.js.map} +0 -0
  225. /package/dist/{chunk-FFL7ETBY.js.map → chunk-D7ZQNQOJ.js.map} +0 -0
  226. /package/dist/{chunk-MBSCZQ2C.js.map → chunk-DZ6SLAIZ.js.map} +0 -0
  227. /package/dist/{chunk-BDPRYJL3.js.map → chunk-FFYYODXG.js.map} +0 -0
  228. /package/dist/{chunk-3XU7Y2MV.js.map → chunk-G6JZ3ZQI.js.map} +0 -0
  229. /package/dist/{chunk-AWY2HWAQ.js.map → chunk-G7OFGBLT.js.map} +0 -0
  230. /package/dist/{chunk-MGNJPBZU.js.map → chunk-GGYXNTEB.js.map} +0 -0
  231. /package/dist/{chunk-NFWSJFYY.js.map → chunk-HHXVHUGP.js.map} +0 -0
  232. /package/dist/{chunk-U3RRXU6W.js.map → chunk-HUX6XT2P.js.map} +0 -0
  233. /package/dist/{chunk-PHHBZDO2.js.map → chunk-HXQYGI3R.js.map} +0 -0
  234. /package/dist/{chunk-7OFVXQSM.js.map → chunk-JQ42ERH3.js.map} +0 -0
  235. /package/dist/{chunk-2VYWTBC6.js.map → chunk-JVG4U3LK.js.map} +0 -0
  236. /package/dist/{chunk-CSTPOCV2.js.map → chunk-K5EAVRXX.js.map} +0 -0
  237. /package/dist/{chunk-QRYZAY7R.js.map → chunk-KX75V4AT.js.map} +0 -0
  238. /package/dist/{chunk-SMXRY653.js.map → chunk-LN2DDJGG.js.map} +0 -0
  239. /package/dist/{chunk-HJ2RKMBI.js.map → chunk-LNRODEIP.js.map} +0 -0
  240. /package/dist/{chunk-KKVWDMSM.js.map → chunk-LSZ6HI3U.js.map} +0 -0
  241. /package/dist/{chunk-N75AJ3ZR.js.map → chunk-M4NZ4UJA.js.map} +0 -0
  242. /package/dist/{chunk-253Q6TOC.js.map → chunk-MKQ7IA6U.js.map} +0 -0
  243. /package/dist/{chunk-DGVCN7HB.js.map → chunk-MOTKVMGL.js.map} +0 -0
  244. /package/dist/{chunk-CJ2QTQHG.js.map → chunk-MX3JVY64.js.map} +0 -0
  245. /package/dist/{chunk-TW44C7CG.js.map → chunk-NDIAONVE.js.map} +0 -0
  246. /package/dist/{chunk-RXZKYHSW.js.map → chunk-NGHIFLCM.js.map} +0 -0
  247. /package/dist/{chunk-3QEDOZMA.js.map → chunk-QJZCTK25.js.map} +0 -0
  248. /package/dist/{chunk-AU7XGTJZ.js.map → chunk-QULZNML4.js.map} +0 -0
  249. /package/dist/{chunk-7DUGVGUZ.js.map → chunk-RVSRZ57P.js.map} +0 -0
  250. /package/dist/{chunk-ZX2VBM2F.js.map → chunk-S4L6BURS.js.map} +0 -0
  251. /package/dist/{chunk-SQ4ZGEZY.js.map → chunk-SNUAISLX.js.map} +0 -0
  252. /package/dist/{chunk-VADGWMXL.js.map → chunk-SOOPR7HU.js.map} +0 -0
  253. /package/dist/{chunk-IYWNDEXA.js.map → chunk-SQI5NYRZ.js.map} +0 -0
  254. /package/dist/{chunk-6C7CR2W2.js.map → chunk-TMBO55MM.js.map} +0 -0
  255. /package/dist/{chunk-5DUKO7WC.js.map → chunk-TUDDISCX.js.map} +0 -0
  256. /package/dist/{chunk-3LDQPUJ6.js.map → chunk-TW57JSKU.js.map} +0 -0
  257. /package/dist/{chunk-3UI35AFZ.js.map → chunk-U2MOKVPZ.js.map} +0 -0
  258. /package/dist/{chunk-JVHHSKBJ.js.map → chunk-UH72CZAX.js.map} +0 -0
  259. /package/dist/{chunk-73MGZAGV.js.map → chunk-UXL75FQC.js.map} +0 -0
  260. /package/dist/{chunk-BENY64FW.js.map → chunk-WIJO2LYS.js.map} +0 -0
  261. /package/dist/{chunk-VJ5XMYXE.js.map → chunk-XTRC6IOA.js.map} +0 -0
  262. /package/dist/{chunk-WQN7HJK6.js.map → chunk-XXKEL6JG.js.map} +0 -0
  263. /package/dist/{chunk-2YKV6MNQ.js.map → chunk-YWB42FW6.js.map} +0 -0
  264. /package/dist/{chunk-5ZU6H62F.js.map → chunk-ZIFWZJ7X.js.map} +0 -0
  265. /package/dist/{chunk-GG4VKPAX.js.map → chunk-ZLQGKBBE.js.map} +0 -0
  266. /package/dist/{chunk-ZJBVZ4OJ.js.map → chunk-ZRY7AOET.js.map} +0 -0
  267. /package/dist/{cleanup-5CPX253G.js.map → cleanup-5DPCUQJQ.js.map} +0 -0
  268. /package/dist/{cli-D2RPZWWM.js.map → cli-IELHMGEY.js.map} +0 -0
  269. /package/dist/{completion-QCB7PKKT.js.map → completion-OEU4UZEA.js.map} +0 -0
  270. /package/dist/{config-EQFAXBMQ.js.map → config-E6ORLTCE.js.map} +0 -0
  271. /package/dist/{diff-MLCUMIYC.js.map → diff-DQFERMIX.js.map} +0 -0
  272. /package/dist/{digest-KSAGLQND.js.map → digest-ALSU7EYK.js.map} +0 -0
  273. /package/dist/{fork-RCTVMUYI.js.map → fork-NY4QWSPG.js.map} +0 -0
  274. /package/dist/{history-N4ZURR4F.js.map → history-JY54YEZX.js.map} +0 -0
  275. /package/dist/{hook-DRZVYLJB.js.map → hook-7Q53RMB2.js.map} +0 -0
  276. /package/dist/{hydrate-NVJZZAFT.js.map → hydrate-PV3F3QEI.js.map} +0 -0
  277. /package/dist/{init-RF6YC4BQ.js.map → init-OH6UWFOJ.js.map} +0 -0
  278. /package/dist/{install-skills-DV7JBW56.js.map → install-skills-7DE3ADWA.js.map} +0 -0
  279. /package/dist/{keep-7Q3B6QT5.js.map → keep-H5VWXD2E.js.map} +0 -0
  280. /package/dist/{list-PIJ4ROHR.js.map → list-7OTXLACR.js.map} +0 -0
  281. /package/dist/{move-XAZG3MJT.js.map → move-UOKARORU.js.map} +0 -0
  282. /package/dist/{note-JJXIQ4QK.js.map → note-2BW5MIC6.js.map} +0 -0
  283. /package/dist/{overlaps-3YN4UQWC.js.map → overlaps-UHF6XJML.js.map} +0 -0
  284. /package/dist/{pin-OOCB6DFR.js.map → pin-GP6BZYYM.js.map} +0 -0
  285. /package/dist/{pr-LCG4W65A.js.map → pr-F5PWLPUU.js.map} +0 -0
  286. /package/dist/{prune-2NGAUOPI.js.map → prune-ISXTZRRM.js.map} +0 -0
  287. /package/dist/{read-FJDDCX4D.js.map → read-ARVCB7A2.js.map} +0 -0
  288. /package/dist/{recent-AAXLCQUF.js.map → recent-NZMHV2NQ.js.map} +0 -0
  289. /package/dist/{restart-AP763LE2.js.map → restart-QQEWWBSM.js.map} +0 -0
  290. /package/dist/{resume-SPO5XNDT.js.map → resume-V4P7XAT2.js.map} +0 -0
  291. /package/dist/{review-now-HHQIBVUS.js.map → review-now-NXMBEJ5R.js.map} +0 -0
  292. /package/dist/{run-JZWZHJOE.js.map → run-M4RWGT2R.js.map} +0 -0
  293. /package/dist/{screen-JRMMYVHB.js.map → screen-KCVCST6K.js.map} +0 -0
  294. /package/dist/{search-XOWMVFP2.js.map → search-BRKX3NF5.js.map} +0 -0
  295. /package/dist/{section-7WO7IHG6.js.map → section-272JIEIG.js.map} +0 -0
  296. /package/dist/{send-OCSMOCUE.js.map → send-4LFQLZR3.js.map} +0 -0
  297. /package/dist/{sessions-UAZALGGH.js.map → sessions-Y7JJHAVI.js.map} +0 -0
  298. /package/dist/{snooze-UDJ5UDCS.js.map → snooze-LJ3INJ47.js.map} +0 -0
  299. /package/dist/{start-OEG3T2SW.js.map → start-MULJ7JIP.js.map} +0 -0
  300. /package/dist/{status-R4T2EHG5.js.map → status-Q4ZX37RP.js.map} +0 -0
  301. /package/dist/{statusline-3H3HAPCZ.js.map → statusline-MIFW47UA.js.map} +0 -0
  302. /package/dist/{statusline-hook-FILOARNM.js.map → statusline-hook-W7KWKWAC.js.map} +0 -0
  303. /package/dist/{stop-D3LRCCJS.js.map → stop-CBCMLFNH.js.map} +0 -0
  304. /package/dist/{sync-FWC2EWLW.js.map → sync-IYFBEFQX.js.map} +0 -0
  305. /package/dist/{time-AMAMIDWD.js.map → time-WSCPEGQC.js.map} +0 -0
  306. /package/dist/{time-actions-YOXF5WC7.js.map → time-actions-KYFYV7F2.js.map} +0 -0
  307. /package/dist/{timesheet-QFBA2Z2A.js.map → timesheet-6W6OPPVP.js.map} +0 -0
  308. /package/dist/{todo-TALKJYK6.js.map → todo-54OJY5VV.js.map} +0 -0
  309. /package/dist/{update-RVZMM54Z.js.map → update-JQSKHI47.js.map} +0 -0
  310. /package/dist/{usage-W4UXQUPD.js.map → usage-5BOIIANY.js.map} +0 -0
  311. /package/dist/{version-WPF664CL.js.map → version-4S7I7GHM.js.map} +0 -0
  312. /package/dist/{wait-C3S7Q6FA.js.map → wait-I3I35CV6.js.map} +0 -0
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  ensureAgentPath,
4
4
  restartHost
5
- } from "./chunk-MGNJPBZU.js";
5
+ } from "./chunk-GGYXNTEB.js";
6
6
  import {
7
7
  createMonthGather,
8
8
  defaultTimeDeps,
@@ -16,7 +16,7 @@ import {
16
16
  graphProblem,
17
17
  signOutGraph,
18
18
  startDeviceLogin
19
- } from "./chunk-QRYZAY7R.js";
19
+ } from "./chunk-KX75V4AT.js";
20
20
  import {
21
21
  addTask,
22
22
  completeTask,
@@ -24,7 +24,7 @@ import {
24
24
  getTasks,
25
25
  removeTask,
26
26
  uncompleteTask
27
- } from "./chunk-7OFVXQSM.js";
27
+ } from "./chunk-JQ42ERH3.js";
28
28
  import {
29
29
  commentInputSchema,
30
30
  detectParentBranch,
@@ -38,7 +38,7 @@ import {
38
38
  serveSpa,
39
39
  sessionBaseForPath,
40
40
  submitReviewSchema
41
- } from "./chunk-SC2FQ6BR.js";
41
+ } from "./chunk-4F2AH2LC.js";
42
42
  import {
43
43
  announceChange,
44
44
  createArchivedRows,
@@ -53,31 +53,31 @@ import {
53
53
  stageSeenKey,
54
54
  storeHolding,
55
55
  withRestoring
56
- } from "./chunk-WQN7HJK6.js";
56
+ } from "./chunk-XXKEL6JG.js";
57
57
  import {
58
58
  createDigestSource
59
- } from "./chunk-7OZZUQDW.js";
59
+ } from "./chunk-6RVZYOED.js";
60
60
  import {
61
61
  createBuildFoldersJob,
62
62
  defaultBranchTidyDeps,
63
63
  defaultBuildFoldersDeps,
64
64
  deleteMergedBranches,
65
65
  findMergedBranches
66
- } from "./chunk-GAE3NB3G.js";
66
+ } from "./chunk-52KXG5D3.js";
67
67
  import {
68
68
  defaultCleanupDeps
69
- } from "./chunk-WV5U4S5N.js";
69
+ } from "./chunk-3GCD3DAB.js";
70
70
  import {
71
71
  DiffStatCache,
72
72
  findOverlaps,
73
73
  wantsDiffStat
74
- } from "./chunk-E6WVQXF4.js";
74
+ } from "./chunk-6Q4PTZ3J.js";
75
75
  import {
76
76
  MAX_NOTE_CHARS,
77
77
  readNote,
78
78
  saveNote,
79
79
  sessionsWithNotes
80
- } from "./chunk-33XSEAHO.js";
80
+ } from "./chunk-2Y2ARDXI.js";
81
81
  import {
82
82
  addBlocker,
83
83
  allBlocks,
@@ -89,13 +89,13 @@ import {
89
89
  removeBlocker,
90
90
  sweepBlocks,
91
91
  unblockedPrompt
92
- } from "./chunk-GV3KXHF3.js";
92
+ } from "./chunk-7XT5MRJ2.js";
93
93
  import {
94
94
  jiraWorklogPoster,
95
95
  logWorkDay,
96
96
  loggedDays,
97
97
  worklogSettings
98
- } from "./chunk-GG4VKPAX.js";
98
+ } from "./chunk-ZLQGKBBE.js";
99
99
  import {
100
100
  accountOverview,
101
101
  accountSkillsNote,
@@ -107,16 +107,16 @@ import {
107
107
  removeAgentAccount,
108
108
  setDefaultAgentAccount,
109
109
  switchRefusal
110
- } from "./chunk-6MMXVHPL.js";
110
+ } from "./chunk-552RUECR.js";
111
111
  import {
112
112
  buildUsage,
113
113
  realUsageDeps,
114
114
  setupAgentUsage
115
- } from "./chunk-ZJBVZ4OJ.js";
115
+ } from "./chunk-ZRY7AOET.js";
116
116
  import {
117
117
  sessionWorkTime
118
- } from "./chunk-2YKV6MNQ.js";
119
- import "./chunk-6UTH3A76.js";
118
+ } from "./chunk-YWB42FW6.js";
119
+ import "./chunk-UVZITL47.js";
120
120
  import {
121
121
  sendToSession
122
122
  } from "./chunk-KWHHB737.js";
@@ -124,11 +124,11 @@ import {
124
124
  defaultForkDeps,
125
125
  forkSession,
126
126
  startSessionWithPrompt
127
- } from "./chunk-RUUEZSQY.js";
127
+ } from "./chunk-5VV5IQC6.js";
128
128
  import {
129
129
  addRepoRefusal,
130
130
  addedRepoNote
131
- } from "./chunk-K7Y7YTN3.js";
131
+ } from "./chunk-7LQTBAYP.js";
132
132
  import {
133
133
  BehindCache,
134
134
  behindMain,
@@ -144,14 +144,14 @@ import {
144
144
  stackedOn,
145
145
  updateFromBase,
146
146
  updateFromMain
147
- } from "./chunk-FFL7ETBY.js";
147
+ } from "./chunk-D7ZQNQOJ.js";
148
148
  import {
149
149
  askCatchUp,
150
150
  cachedCatchUp,
151
151
  catchUp,
152
152
  catchUpFacts,
153
153
  forgetCatchUp
154
- } from "./chunk-KP2CI5QU.js";
154
+ } from "./chunk-CS5VPO7A.js";
155
155
  import {
156
156
  applyPlacePatch,
157
157
  applySectionOp,
@@ -160,7 +160,7 @@ import {
160
160
  cleanSectionOp,
161
161
  placeSession,
162
162
  readRailLayout
163
- } from "./chunk-DGVCN7HB.js";
163
+ } from "./chunk-MOTKVMGL.js";
164
164
  import {
165
165
  DEFAULT_CATCH_UP_DAYS,
166
166
  addDays,
@@ -185,7 +185,7 @@ import {
185
185
  tempoSetup,
186
186
  timeRange,
187
187
  updateDay
188
- } from "./chunk-VJ5XMYXE.js";
188
+ } from "./chunk-XTRC6IOA.js";
189
189
  import {
190
190
  DISCUSSION_OPEN_MIN_MS,
191
191
  LEFT_OVER_SUBMIT,
@@ -208,7 +208,9 @@ import {
208
208
  leftOverToDoubt,
209
209
  linesWorthReading,
210
210
  markStaleClaim,
211
+ parseAgentPass,
211
212
  preparedOn,
213
+ promptPaths,
212
214
  readReview,
213
215
  refusalStatus,
214
216
  removeDraft,
@@ -225,7 +227,7 @@ import {
225
227
  withClaim,
226
228
  withFixClaim,
227
229
  withoutFixClaim
228
- } from "./chunk-YKQLHFY4.js";
230
+ } from "./chunk-HUD4JLK3.js";
229
231
  import {
230
232
  asData,
231
233
  asDataBlock
@@ -241,12 +243,12 @@ import {
241
243
  readWebUrl,
242
244
  writeDevWebDiscovery,
243
245
  writeWebDiscovery
244
- } from "./chunk-6C7CR2W2.js";
246
+ } from "./chunk-TMBO55MM.js";
245
247
  import {
246
248
  checkTools,
247
249
  saveFolders,
248
250
  setupState
249
- } from "./chunk-RXZKYHSW.js";
251
+ } from "./chunk-NGHIFLCM.js";
250
252
  import {
251
253
  RepoAdminError,
252
254
  deleteGroup,
@@ -258,7 +260,7 @@ import {
258
260
  setRepoIgnored,
259
261
  setReviewMode,
260
262
  setScanRoot
261
- } from "./chunk-BENY64FW.js";
263
+ } from "./chunk-WIJO2LYS.js";
262
264
  import {
263
265
  freeLeftovers,
264
266
  leftoversOf,
@@ -267,37 +269,32 @@ import {
267
269
  parsePrRef,
268
270
  resolvePrToStart,
269
271
  workOnPrPrompt
270
- } from "./chunk-U3RRXU6W.js";
272
+ } from "./chunk-HUX6XT2P.js";
271
273
  import {
272
274
  legacyUnsafeCheck
273
- } from "./chunk-VADGWMXL.js";
275
+ } from "./chunk-SOOPR7HU.js";
274
276
  import {
275
277
  agentsBySession,
276
278
  summarizeAgents
277
- } from "./chunk-CL3SSNBC.js";
279
+ } from "./chunk-6SRDHIAK.js";
278
280
  import {
279
281
  howToLift
280
282
  } from "./chunk-FZHFD2AY.js";
281
- import {
282
- childText,
283
- createInChild,
284
- createInProcess,
285
- keyedQueue,
286
- oneAtATime,
287
- runWorkChild
288
- } from "./chunk-DMA3XCMF.js";
289
283
  import {
290
284
  resolveWorkBinPath
291
285
  } from "./chunk-AH5TM3NB.js";
292
286
  import {
293
287
  editorArgs,
294
288
  openUrl
295
- } from "./chunk-IYWNDEXA.js";
289
+ } from "./chunk-SQI5NYRZ.js";
290
+ import {
291
+ removeWorktreeInChild
292
+ } from "./chunk-Y2RCCYRA.js";
296
293
  import {
297
294
  archiveMergedSession,
298
295
  archiveWaiting,
299
296
  defaultArchiveDeps
300
- } from "./chunk-BTR2E5WD.js";
297
+ } from "./chunk-LYZQ6IKY.js";
301
298
  import {
302
299
  cleanupVerdict,
303
300
  createCleanupJob
@@ -317,7 +314,7 @@ import {
317
314
  retireResolvedReplies,
318
315
  sessionRepoRefs,
319
316
  withThreadContext
320
- } from "./chunk-M7FX37Z2.js";
317
+ } from "./chunk-CLPCEQA2.js";
321
318
  import {
322
319
  DEFAULT_TRUSTED_BOTS,
323
320
  createCiStore,
@@ -327,27 +324,40 @@ import {
327
324
  openThreadsOf,
328
325
  reviewMessage,
329
326
  subAgentHint
330
- } from "./chunk-2VYWTBC6.js";
327
+ } from "./chunk-JVG4U3LK.js";
331
328
  import {
332
329
  sessionStatusView,
333
330
  shownState
334
- } from "./chunk-RH4BGTER.js";
331
+ } from "./chunk-AMEJQT64.js";
335
332
  import {
336
333
  internalReadOnly,
337
334
  runInternal,
338
335
  runInternalReadOnly,
339
336
  summarizeCheckpoint,
340
337
  throttleTrailing
341
- } from "./chunk-F7IOGLKV.js";
338
+ } from "./chunk-4GPKT5A2.js";
342
339
  import {
343
340
  computeDiff,
344
341
  computeRangeDiff,
345
342
  parseGitDiff
346
- } from "./chunk-ZX2VBM2F.js";
343
+ } from "./chunk-S4L6BURS.js";
347
344
  import {
345
+ commandWords,
346
+ describeProcess,
347
+ isPtyHelper,
348
348
  listProcesses,
349
- runningFromNames
350
- } from "./chunk-5DUKO7WC.js";
349
+ normDir,
350
+ runningFromNames,
351
+ runsFrom
352
+ } from "./chunk-TUDDISCX.js";
353
+ import {
354
+ childText,
355
+ createInChild,
356
+ createInProcess,
357
+ keyedQueue,
358
+ oneAtATime,
359
+ runWorkChild
360
+ } from "./chunk-BMNH6B5U.js";
351
361
  import {
352
362
  configurePtyPool,
353
363
  detachPtyPool,
@@ -371,42 +381,42 @@ import {
371
381
  syncPtyPool,
372
382
  terminalTicketUrl,
373
383
  writeToPty
374
- } from "./chunk-3LDQPUJ6.js";
375
- import "./chunk-AU7XGTJZ.js";
384
+ } from "./chunk-TW57JSKU.js";
385
+ import "./chunk-QULZNML4.js";
376
386
  import {
377
387
  disposeAllWatchers,
378
388
  disposeSessionWatcher,
379
389
  findSession as findSession2,
380
390
  subscribeSession
381
- } from "./chunk-HJ2RKMBI.js";
382
- import "./chunk-KJRUC2QY.js";
383
- import "./chunk-BDPRYJL3.js";
391
+ } from "./chunk-LNRODEIP.js";
392
+ import "./chunk-4GNX6CQ2.js";
393
+ import "./chunk-FFYYODXG.js";
384
394
  import {
385
395
  teardownWorktree,
386
396
  toBaseSpec,
387
397
  wouldRefuseRemoval
388
- } from "./chunk-HECIDNBU.js";
389
- import "./chunk-JVHHSKBJ.js";
398
+ } from "./chunk-2YTCAJT5.js";
399
+ import "./chunk-UH72CZAX.js";
390
400
  import {
391
401
  isWorktreeFolder
392
- } from "./chunk-KKVWDMSM.js";
402
+ } from "./chunk-LSZ6HI3U.js";
393
403
  import {
394
404
  ASSISTANT_ID,
395
405
  assistantDir,
396
406
  describeView,
397
407
  writeAssistantContext
398
- } from "./chunk-SQ4ZGEZY.js";
408
+ } from "./chunk-SNUAISLX.js";
399
409
  import "./chunk-7E5XPDKX.js";
400
- import "./chunk-CJ2QTQHG.js";
410
+ import "./chunk-MX3JVY64.js";
401
411
  import {
402
412
  NOTE_NUDGE,
403
413
  findSessionForCwd,
404
414
  readPendingForSession,
405
415
  readPendingForWorktree
406
- } from "./chunk-LPHYUNMD.js";
416
+ } from "./chunk-P6LDKZEY.js";
407
417
  import {
408
418
  getCommentFileStore
409
- } from "./chunk-7DUGVGUZ.js";
419
+ } from "./chunk-RVSRZ57P.js";
410
420
  import "./chunk-ZSHWP2VS.js";
411
421
  import {
412
422
  createCommentStore
@@ -423,17 +433,17 @@ import {
423
433
  stageInputOf,
424
434
  withRequiredChecks,
425
435
  workElsewhere
426
- } from "./chunk-SMXRY653.js";
436
+ } from "./chunk-LN2DDJGG.js";
427
437
  import {
428
438
  createSessionBranches
429
- } from "./chunk-XZKQHQBB.js";
439
+ } from "./chunk-NLSFJYU6.js";
430
440
  import {
431
441
  defaultHost,
432
442
  hostById,
433
443
  hostForRepo,
434
444
  hostOfPrUrl,
435
445
  originHostname
436
- } from "./chunk-TW44C7CG.js";
446
+ } from "./chunk-NDIAONVE.js";
437
447
  import {
438
448
  MAX_THREAD_BODY
439
449
  } from "./chunk-FGPXMAYU.js";
@@ -446,16 +456,16 @@ import {
446
456
  readSessionBranches,
447
457
  repoNameOf,
448
458
  wasPushed
449
- } from "./chunk-73MGZAGV.js";
459
+ } from "./chunk-UXL75FQC.js";
450
460
  import {
451
461
  enrollProblem,
452
462
  groupProblem,
453
463
  suggestAlias
454
- } from "./chunk-BLOV7ECI.js";
455
- import "./chunk-5ZU6H62F.js";
464
+ } from "./chunk-AGRUEZQX.js";
465
+ import "./chunk-ZIFWZJ7X.js";
456
466
  import {
457
467
  defaultRunner
458
- } from "./chunk-253Q6TOC.js";
468
+ } from "./chunk-MKQ7IA6U.js";
459
469
  import {
460
470
  DECISION_MARKER,
461
471
  DEFAULT_HOST,
@@ -470,7 +480,6 @@ import {
470
480
  bestEffort,
471
481
  bestEffortAsync,
472
482
  buildDigest,
473
- checkedOutBranch,
474
483
  cleanSnoozeRequest,
475
484
  cleanStageRef,
476
485
  clearCheckpoints,
@@ -487,7 +496,6 @@ import {
487
496
  findSession,
488
497
  findSessionById,
489
498
  getScope,
490
- gitDirs,
491
499
  headAdvancedSinceInitial,
492
500
  headBroughtInOtherWork,
493
501
  hostName,
@@ -513,7 +521,6 @@ import {
513
521
  readSnooze,
514
522
  readStatus,
515
523
  recordStatusEvent,
516
- refShaFromFiles,
517
524
  registerScope,
518
525
  removeScope,
519
526
  removeSession,
@@ -549,9 +556,8 @@ import {
549
556
  turnInProgress,
550
557
  updateCheckpoint,
551
558
  whileRestoring,
552
- workingBranch,
553
559
  writeArchiveRecord
554
- } from "./chunk-3PXA5RJ2.js";
560
+ } from "./chunk-KHGP6MS2.js";
555
561
  import {
556
562
  dayKey
557
563
  } from "./chunk-NEJVK5CF.js";
@@ -562,7 +568,7 @@ import {
562
568
  sessionIdFor,
563
569
  tx,
564
570
  withDb
565
- } from "./chunk-RUYTU2WJ.js";
571
+ } from "./chunk-RRNIJ7YO.js";
566
572
  import {
567
573
  packageRoot
568
574
  } from "./chunk-LNHSBM4L.js";
@@ -573,25 +579,30 @@ import {
573
579
  agentFor,
574
580
  agentOf,
575
581
  agentWriteMs,
582
+ checkedOutBranch,
583
+ gitDirs,
576
584
  isOwnCheckout,
577
585
  knownAgents,
578
586
  lineTimeOf,
579
587
  liveAgents,
580
- readJsonlSince
581
- } from "./chunk-KCDHOW22.js";
588
+ ownsBranch,
589
+ readJsonlSince,
590
+ refShaFromFiles,
591
+ workingBranch
592
+ } from "./chunk-Z6B4ICOI.js";
582
593
  import {
583
594
  VERSION
584
- } from "./chunk-AWY2HWAQ.js";
595
+ } from "./chunk-G7OFGBLT.js";
585
596
  import {
586
597
  resolveProjectTarget
587
- } from "./chunk-PMEOGFGV.js";
598
+ } from "./chunk-7UXV4X2Y.js";
588
599
  import {
589
600
  git
590
- } from "./chunk-CSTPOCV2.js";
601
+ } from "./chunk-K5EAVRXX.js";
591
602
  import {
592
603
  usageDir
593
604
  } from "./chunk-CBCOVIXZ.js";
594
- import "./chunk-7HQM5NYN.js";
605
+ import "./chunk-BK73QU45.js";
595
606
  import {
596
607
  QUEUE_RECHECK_MS,
597
608
  busyForRestart,
@@ -599,18 +610,18 @@ import {
599
610
  installedAtCache,
600
611
  outdatedPtys,
601
612
  restartNotesSummary
602
- } from "./chunk-MBSCZQ2C.js";
613
+ } from "./chunk-DZ6SLAIZ.js";
603
614
  import "./chunk-TNJF7T33.js";
604
615
  import {
605
616
  accountLoginId,
606
617
  accountOfLoginId
607
618
  } from "./chunk-SJBEIYLK.js";
608
- import "./chunk-HRUKMBF3.js";
609
- import "./chunk-DMGNJ73M.js";
619
+ import "./chunk-AYHDJMMJ.js";
620
+ import "./chunk-42MD5W5R.js";
610
621
  import {
611
622
  DEFAULT_ACCOUNT_NAME,
612
623
  accountNameProblem
613
- } from "./chunk-NFWSJFYY.js";
624
+ } from "./chunk-HHXVHUGP.js";
614
625
  import {
615
626
  DEFAULT_ACCOUNT,
616
627
  DEFAULT_PROMPTS,
@@ -618,21 +629,23 @@ import {
618
629
  getConfigPath,
619
630
  isWorkday,
620
631
  loadConfig
621
- } from "./chunk-O5ZJY5BT.js";
632
+ } from "./chunk-INI6TEYT.js";
622
633
  import {
623
634
  bootTime,
624
635
  detachHere,
625
636
  isPidAlive,
637
+ killTreeAsync,
626
638
  recentProcessTable
627
- } from "./chunk-WYQD44Y4.js";
639
+ } from "./chunk-G2V2V5UC.js";
628
640
  import {
629
641
  shellEnv,
630
642
  spawn_default
631
- } from "./chunk-VQACXAFX.js";
643
+ } from "./chunk-DW245WK4.js";
632
644
  import {
633
645
  explainNotOnPath,
634
- programPath
635
- } from "./chunk-3QKH7JNR.js";
646
+ programPath,
647
+ takeSlowestSync
648
+ } from "./chunk-ZS7ZXAXB.js";
636
649
  import {
637
650
  atomicWriteFile
638
651
  } from "./chunk-D2J3AD6L.js";
@@ -760,12 +773,12 @@ function mountSessionControlRoutes(app, opts) {
760
773
  // src/core/stacks/stack-sync.ts
761
774
  var busyWhy = (state) => state === "working" ? "its Claude is working" : state === "needs_input" ? "its Claude is waiting for your answer" : null;
762
775
  async function syncStackChild(child, parentBranch, deps) {
763
- const run = deps.run ?? defaultRunner;
776
+ const run2 = deps.run ?? defaultRunner;
764
777
  const busy = busyWhy(deps.shownState(child));
765
778
  if (busy) return { updated: false, why: busy };
766
779
  const behind = [];
767
780
  for (const p of child.paths) {
768
- const b = await behindMain(p, run, parentBranch);
781
+ const b = await behindMain(p, run2, parentBranch);
769
782
  if (b && b.commits > 0) behind.push({ path: p, b });
770
783
  }
771
784
  if (behind.length === 0) return { updated: false, why: `already on top of ${parentBranch}` };
@@ -773,9 +786,9 @@ async function syncStackChild(child, parentBranch, deps) {
773
786
  return { updated: false, why: `bringing in ${parentBranch} would conflict: left for you (Update from ${parentBranch})` };
774
787
  const heads = /* @__PURE__ */ new Map();
775
788
  for (const { path: p } of behind) {
776
- const st = await run("git", ["-C", p, "status", "--porcelain"], p);
789
+ const st = await run2("git", ["-C", p, "status", "--porcelain"], p);
777
790
  if (st.code !== 0 || st.stdout.trim()) return { updated: false, why: "it has uncommitted changes" };
778
- const head = await run("git", ["-C", p, "rev-parse", "HEAD"], p);
791
+ const head = await run2("git", ["-C", p, "rev-parse", "HEAD"], p);
779
792
  if (head.code !== 0) return { updated: false, why: `${p}: ${head.stderr.trim() || "no HEAD"}` };
780
793
  heads.set(p, head.stdout.trim());
781
794
  }
@@ -784,9 +797,9 @@ async function syncStackChild(child, parentBranch, deps) {
784
797
  const done = [];
785
798
  for (const { path: p } of behind) {
786
799
  const nowBusy = busyWhy(deps.shownState(child));
787
- const r = nowBusy ? null : await updateFromMain(p, run, parentBranch);
800
+ const r = nowBusy ? null : await updateFromMain(p, run2, parentBranch);
788
801
  if (!r || !r.ok) {
789
- for (const q of done) await run("git", ["-C", q, "reset", "--hard", "--quiet", heads.get(q)], q);
802
+ for (const q of done) await run2("git", ["-C", q, "reset", "--hard", "--quiet", heads.get(q)], q);
790
803
  return {
791
804
  updated: false,
792
805
  why: nowBusy ?? `${r.repo}: ${r.reason}${done.length ? " (the others were put back)" : ""}`
@@ -808,15 +821,15 @@ async function syncStackChild(child, parentBranch, deps) {
808
821
  return { updated: true, commits, how, told };
809
822
  }
810
823
  async function retargetIfMerged(child, parent, config, deps) {
811
- const run = deps.run ?? defaultRunner;
824
+ const run2 = deps.run ?? defaultRunner;
812
825
  const busy = busyWhy(deps.shownState(child));
813
826
  if (busy) return { updated: false, why: busy };
814
827
  const tips = /* @__PURE__ */ new Map();
815
- for (const p of child.paths) tips.set(p, await parentTipFor(p, parent, config, run));
828
+ for (const p of child.paths) tips.set(p, await parentTipFor(p, parent, config, run2));
816
829
  for (const p of child.paths) {
817
830
  const tip = tips.get(p);
818
831
  if (!tip) return { updated: false, why: `${parent.branch} merged, but its tip is unknown here: Move onto main by hand` };
819
- const blocker = await retargetBlocker(p, { branch: parent.branch, tip }, run);
832
+ const blocker = await retargetBlocker(p, { branch: parent.branch, tip }, run2);
820
833
  if (blocker?.handOff) {
821
834
  const key = `${sessionIdFor(child)}:${tip}`;
822
835
  if (handedOff.has(key))
@@ -828,7 +841,7 @@ async function retargetIfMerged(child, parent, config, deps) {
828
841
  await deps.tell(child, ontoMainPrompt(parent.branch)).catch((err) => logSwallowed(`asking ${child.branch} to move onto main`, err));
829
842
  return { updated: false, why: `${parent.branch} was rewritten before it merged: its Claude was asked to move this branch onto main` };
830
843
  }
831
- if (!await retargetIsClean(p, { branch: parent.branch, tip }, run)) {
844
+ if (!await retargetIsClean(p, { branch: parent.branch, tip }, run2)) {
832
845
  return {
833
846
  updated: false,
834
847
  why: `${parent.branch} merged; moving onto main isn't sure to go cleanly (a conflict, uncommitted changes, a rewritten parent, or an old git): left for you`
@@ -838,7 +851,7 @@ async function retargetIfMerged(child, parent, config, deps) {
838
851
  const r = await retargetOntoMain(
839
852
  child,
840
853
  async (p) => ({ branch: parent.branch, tip: tips.get(p) ?? null }),
841
- run,
854
+ run2,
842
855
  () => busyWhy(deps.shownState(child))
843
856
  );
844
857
  if (!r.ok)
@@ -869,7 +882,7 @@ async function retargetChildrenOf(parentId, deps) {
869
882
  const stacks = sessionStacks(history, config);
870
883
  const children = history.filter((s) => stacks.mergedParentOf.get(sessionIdFor(s))?.id === parentId);
871
884
  if (children.length === 0) return 0;
872
- const run = deps.startRun();
885
+ const run2 = deps.startRun();
873
886
  let moved = 0;
874
887
  for (const child of children) {
875
888
  const id = sessionIdFor(child);
@@ -880,18 +893,18 @@ async function retargetChildrenOf(parentId, deps) {
880
893
  if (r.updated) {
881
894
  moved++;
882
895
  deps.invalidate(id);
883
- run.note(
896
+ run2.note(
884
897
  `${child.branch}: ${r.how} (its parent merged and was archived)${r.told ? "; its Claude was told" : " \u2014 telling its Claude failed"}`,
885
898
  { sessionId: id, ...r.told ? {} : { level: "warn" } }
886
899
  );
887
- } else run.note(`${child.branch}: left as it is \u2014 ${r.why}`, { sessionId: id });
900
+ } else run2.note(`${child.branch}: left as it is \u2014 ${r.why}`, { sessionId: id });
888
901
  } catch (err) {
889
- run.note(`${child.branch}: ${err.message}`, { sessionId: id, level: "warn" });
902
+ run2.note(`${child.branch}: ${err.message}`, { sessionId: id, level: "warn" });
890
903
  } finally {
891
904
  deps.busy.delete(id);
892
905
  }
893
906
  }
894
- run.done(moved ? `${moved} moved onto main` : "none could move by itself");
907
+ run2.done(moved ? `${moved} moved onto main` : "none could move by itself");
895
908
  return moved;
896
909
  }
897
910
  async function syncStacksAfterTurn(sessionId, deps) {
@@ -904,7 +917,7 @@ async function syncStacksAfterTurn(sessionId, deps) {
904
917
  if (candidates2.length === 0 && !merged) return 0;
905
918
  for (const c of candidates2) deps.invalidate(sessionIdFor(c));
906
919
  if (config?.stacks?.autoUpdate === false) return 0;
907
- const run = deps.startRun();
920
+ const run2 = deps.startRun();
908
921
  let updated = 0;
909
922
  if (self && merged && !deps.busy.has(sessionId)) {
910
923
  deps.busy.add(sessionId);
@@ -913,13 +926,13 @@ async function syncStacksAfterTurn(sessionId, deps) {
913
926
  if (r.updated) {
914
927
  updated++;
915
928
  deps.invalidate(sessionId);
916
- run.note(`${self.branch}: ${r.how} (${merged.branch} merged)${r.told ? "; its Claude was told" : " \u2014 telling its Claude failed"}`, {
929
+ run2.note(`${self.branch}: ${r.how} (${merged.branch} merged)${r.told ? "; its Claude was told" : " \u2014 telling its Claude failed"}`, {
917
930
  sessionId,
918
931
  ...r.told ? {} : { level: "warn" }
919
932
  });
920
- } else run.note(`${self.branch}: left as it is \u2014 ${r.why}`, { sessionId });
933
+ } else run2.note(`${self.branch}: left as it is \u2014 ${r.why}`, { sessionId });
921
934
  } catch (err) {
922
- run.note(`${self.branch}: ${err.message}`, { sessionId, level: "warn" });
935
+ run2.note(`${self.branch}: ${err.message}`, { sessionId, level: "warn" });
923
936
  } finally {
924
937
  deps.busy.delete(sessionId);
925
938
  }
@@ -934,20 +947,20 @@ async function syncStacksAfterTurn(sessionId, deps) {
934
947
  if (r.updated) {
935
948
  updated++;
936
949
  deps.invalidate(childId);
937
- run.note(
950
+ run2.note(
938
951
  `${child.branch}: ${r.commits} commit${r.commits === 1 ? "" : "s"} from ${parent.branch} (${r.how})${r.told ? "; its Claude was told" : "; telling its Claude failed \u2014 it doesn't know yet"}`,
939
952
  { sessionId: childId, ...r.told ? {} : { level: "warn" } }
940
953
  );
941
954
  } else {
942
- run.note(`${child.branch}: left as it is \u2014 ${r.why}`, { sessionId: childId });
955
+ run2.note(`${child.branch}: left as it is \u2014 ${r.why}`, { sessionId: childId });
943
956
  }
944
957
  } catch (err) {
945
- run.note(`${child.branch}: ${err.message}`, { sessionId: childId, level: "warn" });
958
+ run2.note(`${child.branch}: ${err.message}`, { sessionId: childId, level: "warn" });
946
959
  } finally {
947
960
  deps.busy.delete(childId);
948
961
  }
949
962
  }
950
- run.done(updated ? `${updated} brought up to date` : "nothing to bring in");
963
+ run2.done(updated ? `${updated} brought up to date` : "nothing to bring in");
951
964
  return updated;
952
965
  }
953
966
 
@@ -1169,18 +1182,587 @@ function mountNoteRoutes(app, opts) {
1169
1182
  });
1170
1183
  }
1171
1184
 
1185
+ // src/core/sessions/process-view.ts
1186
+ var LEFTOVER_AFTER_MS = 24 * 36e5;
1187
+ function formatBytes(bytes) {
1188
+ const mb = bytes / (1024 * 1024);
1189
+ return mb >= 1024 ? `${(mb / 1024).toFixed(1)} GB` : `${Math.round(mb)} MB`;
1190
+ }
1191
+
1192
+ // src/core/sessions/process-stop.ts
1193
+ function stopRefusal(now, pid, startedAt) {
1194
+ const p = now.processes.find((x) => x.pid === pid);
1195
+ if (!p) return "it is no longer running for this session";
1196
+ if (p.agent) return "that is its agent: stop it from the session instead";
1197
+ if (p.startedAt === null || startedAt === null || Math.abs(p.startedAt - startedAt) > 2e3)
1198
+ return "the process under that number is not the one that was listed";
1199
+ return null;
1200
+ }
1201
+
1202
+ // src/core/sessions/session-processes.ts
1203
+ function descendantsOf(procs, roots) {
1204
+ const children = /* @__PURE__ */ new Map();
1205
+ for (const p of procs) children.set(p.ppid, [...children.get(p.ppid) ?? [], p.pid]);
1206
+ const out = /* @__PURE__ */ new Set();
1207
+ const todo = [...roots].filter((r) => procs.some((p) => p.pid === r));
1208
+ while (todo.length) {
1209
+ const pid = todo.pop();
1210
+ if (out.has(pid)) continue;
1211
+ out.add(pid);
1212
+ todo.push(...children.get(pid) ?? []);
1213
+ }
1214
+ return out;
1215
+ }
1216
+ function sessionProcesses(procs, opts) {
1217
+ const windows = opts.windows ?? process.platform === "win32";
1218
+ const byPid = new Map(procs.map((p) => [p.pid, p]));
1219
+ const real = procs.map((p) => {
1220
+ const parent = byPid.get(p.ppid);
1221
+ const stale = parent && p.startedAt !== null && parent.startedAt !== null && parent.startedAt > p.startedAt + 1e3;
1222
+ return stale ? { ...p, ppid: 0 } : p;
1223
+ });
1224
+ const tree = descendantsOf(real, opts.agentPids);
1225
+ const dirs = opts.dirs.map((d) => normDir(d, windows));
1226
+ const mine = real.filter((p) => !isPtyHelper(p) && (tree.has(p.pid) || dirs.length > 0 && runsFrom(p, dirs, windows)));
1227
+ const rows = mine.map((p) => {
1228
+ const agent = opts.agentPids.has(p.pid);
1229
+ const ageMs = p.startedAt === null ? null : Math.max(0, opts.now - p.startedAt);
1230
+ return {
1231
+ pid: p.pid,
1232
+ // Its name and command with the session's folder shortened, without the pid (it has its own field).
1233
+ what: describeProcess(p, dirs, windows).replace(/ \(PID \d+\)$/, ""),
1234
+ memBytes: p.memBytes,
1235
+ startedAt: p.startedAt,
1236
+ ...agent ? { agent: true } : {},
1237
+ ...!agent && ageMs !== null && ageMs >= LEFTOVER_AFTER_MS ? { leftover: true } : {}
1238
+ };
1239
+ }).sort((a, b) => (b.memBytes ?? 0) - (a.memBytes ?? 0) || a.pid - b.pid);
1240
+ return {
1241
+ at: opts.now,
1242
+ totalBytes: rows.reduce((n, r) => n + (r.memBytes ?? 0), 0),
1243
+ leftovers: rows.filter((r) => r.leftover).length,
1244
+ processes: rows
1245
+ };
1246
+ }
1247
+
1248
+ // src/server/routes/session-process-routes.ts
1249
+ var LIST_FOR_MS = 3e3;
1250
+ function mountSessionProcessRoutes(app, deps) {
1251
+ const now = deps.now ?? Date.now;
1252
+ let kept = null;
1253
+ const listed = (fresh = false) => {
1254
+ if (fresh || !kept || now() - kept.at >= LIST_FOR_MS) kept = { at: now(), list: deps.list() };
1255
+ return kept.list;
1256
+ };
1257
+ const of = async (id, fresh = false) => {
1258
+ const session = findSession2(id);
1259
+ if (!session) return "unknown";
1260
+ const procs = await listed(fresh);
1261
+ if (procs.length === 0) return "unreadable";
1262
+ const pid = deps.agentPid(id);
1263
+ return sessionProcesses(procs, { agentPids: new Set(pid ? [pid] : []), dirs: session.paths, now: now() });
1264
+ };
1265
+ app.get("/api/sessions/:id/processes", async (c) => {
1266
+ const r = await of(c.req.param("id"));
1267
+ if (r === "unknown") return c.json({ error: "unknown session" }, 404);
1268
+ if (r === "unreadable") return c.json({ error: "couldn't read the running processes" }, 502);
1269
+ return c.json(r);
1270
+ });
1271
+ app.post("/api/sessions/:id/processes/stop", async (c) => {
1272
+ const id = c.req.param("id");
1273
+ const body = await c.req.json().catch(() => null);
1274
+ if (typeof body?.pid !== "number" || !Number.isInteger(body.pid) || body.pid <= 0)
1275
+ return c.json({ error: "expected {pid, startedAt}" }, 400);
1276
+ const r = await of(id, true);
1277
+ if (r === "unknown") return c.json({ error: "unknown session" }, 404);
1278
+ if (r === "unreadable") return c.json({ error: "couldn't read the running processes" }, 502);
1279
+ const why = stopRefusal(r, body.pid, typeof body.startedAt === "number" ? body.startedAt : null);
1280
+ if (why) return c.json({ error: `Not stopped: ${why}.` }, 409);
1281
+ if (!await deps.kill(body.pid)) return c.json({ error: "Couldn't stop it." }, 500);
1282
+ const after = await of(id, true);
1283
+ return c.json(typeof after === "string" ? { ...r, processes: r.processes.filter((p) => p.pid !== body.pid) } : after);
1284
+ });
1285
+ }
1286
+
1287
+ // src/core/review/local-review.ts
1288
+ import crypto from "crypto";
1289
+ function diffSignature(files) {
1290
+ const h = crypto.createHash("sha1");
1291
+ for (const f of files) {
1292
+ h.update(`${f.path}\0${f.status}\0${f.added}\0${f.deleted}\0`);
1293
+ for (const hunk2 of f.hunks) for (const l of hunk2.lines) h.update(`${l.kind[0]}${l.content}
1294
+ `);
1295
+ }
1296
+ return h.digest("hex").slice(0, 16);
1297
+ }
1298
+ function localMeta(session, repo, base, signature) {
1299
+ return {
1300
+ repo,
1301
+ number: 0,
1302
+ title: session.title ? `${session.title} (local changes on ${session.branch})` : `Local changes on ${session.branch}`,
1303
+ url: "",
1304
+ author: "you",
1305
+ branch: session.branch,
1306
+ base,
1307
+ headSha: signature
1308
+ };
1309
+ }
1310
+ var REPOS_JOIN = " + ";
1311
+ function inRepo(name, f) {
1312
+ const at = (p) => p === "/dev/null" ? p : `${name}/${p}`;
1313
+ return { ...f, path: at(f.path), oldPath: at(f.oldPath), newPath: at(f.newPath) };
1314
+ }
1315
+ function focusLines(name) {
1316
+ return [
1317
+ `These changes span several repos; each path starts with its repo's name. This pass is about the repo "${name}" alone: another pass writes the stories and reads the other repos.`,
1318
+ `Read every file under "${name}/" closely and add review notes on those files only. The other repos' files are context: use them to answer what "${name}" depends on (an endpoint it calls, a setting or a header the other side sends), and write no note asking what they already show.`,
1319
+ 'Answer with "stories": [], "flows": [], "fileSummaries": {} and "asserts": {} left empty, and no "recommendation": only "notes" is read from this pass.'
1320
+ ];
1321
+ }
1322
+ var SAME_PLACE = 3;
1323
+ function withFocusNotes(main, passes, paths) {
1324
+ if (!main) return null;
1325
+ const start = main.indexOf("{");
1326
+ const end = main.lastIndexOf("}");
1327
+ let raw;
1328
+ try {
1329
+ raw = JSON.parse(main.slice(start, end + 1));
1330
+ } catch {
1331
+ return main;
1332
+ }
1333
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return main;
1334
+ const o = raw;
1335
+ const notes = Array.isArray(o.notes) ? [...o.notes] : [];
1336
+ const taken = (p, line) => notes.some((n) => {
1337
+ const x = n ?? {};
1338
+ return x.path === p && typeof x.line === "number" && Math.abs(x.line - line) <= SAME_PLACE;
1339
+ });
1340
+ let added = 0;
1341
+ for (const pass of passes) {
1342
+ for (const n of parseAgentPass(pass.answer, [...paths])?.notes ?? []) {
1343
+ if (!n.path.startsWith(`${pass.repo}/`) || taken(n.path, n.line)) continue;
1344
+ notes.push(n);
1345
+ added++;
1346
+ }
1347
+ }
1348
+ return added ? JSON.stringify({ ...o, notes }) : main;
1349
+ }
1350
+ function pickChanges(diff, repo) {
1351
+ const changed = diff.repos.filter((r) => r.files.length > 0);
1352
+ const picked = repo === void 0 ? changed : changed.filter((r) => r.name === repo);
1353
+ const together = picked.length > 1;
1354
+ const all = together ? picked.flatMap((r) => r.files.map((f) => inRepo(r.name, f))) : picked[0]?.files ?? [];
1355
+ return { repos: changed.map((r) => r.name), picked, together, all };
1356
+ }
1357
+ function localSignature(diff, repo) {
1358
+ return diffSignature(pickChanges(diff, repo).all);
1359
+ }
1360
+ async function prepareLocalReview(session, repo, deps) {
1361
+ const diff = deps.diff(session);
1362
+ if (repo !== void 0 && !diff.repos.some((r) => r.name === repo)) throw new Error(`${repo} is not one of this session's repos`);
1363
+ const { repos, picked, together, all } = pickChanges(diff, repo);
1364
+ if (picked.length === 0)
1365
+ throw new Error(
1366
+ repo ? `Nothing has changed in ${repo} since ${diff.resolvedBase}.` : `Nothing has changed on this branch since ${diff.resolvedBase}.`
1367
+ );
1368
+ const { files, ignored } = splitIgnored(all);
1369
+ const extras = { whitespaceOnly: /* @__PURE__ */ new Set(), generated: /* @__PURE__ */ new Set() };
1370
+ const rules = deps.rules?.();
1371
+ const meta = localMeta(session, picked.map((r) => r.name).join(REPOS_JOIN), diff.resolvedBase, diffSignature(all));
1372
+ const kinds = kindsOf(files, extras, rules);
1373
+ const agent = deps.agent;
1374
+ const prompt = agent ? reviewPrompt(meta, files, kinds) : null;
1375
+ const tree = prompt && agent && deps.inTree ? await deps.inTree(
1376
+ session,
1377
+ picked.map((r) => r.name)
1378
+ ).catch((err) => ({ why: err.message })) : null;
1379
+ const inTree = tree && "ask" in tree ? tree : null;
1380
+ let fellBack = 0;
1381
+ let passesAsked = 0;
1382
+ const ask = async (opts = {}) => {
1383
+ if (!agent) return null;
1384
+ passesAsked++;
1385
+ if (inTree) {
1386
+ const there = reviewPrompt(meta, files, kinds, { ...opts, checkout: inTree.lines });
1387
+ const answer2 = there ? await inTree.ask(there).catch(() => null) : null;
1388
+ if (answer2) return answer2;
1389
+ fellBack++;
1390
+ }
1391
+ const plain = reviewPrompt(meta, files, kinds, opts);
1392
+ return plain ? agent(plain).catch(() => null) : null;
1393
+ };
1394
+ const asked = promptPaths(kinds);
1395
+ const focused = together && prompt ? picked.map((r) => r.name).filter((name) => asked.some((p) => p.startsWith(`${name}/`))) : [];
1396
+ const [main, ...passes] = prompt && agent ? await Promise.all([ask(), ...focused.map((name) => ask({ focus: focusLines(name), first: (p) => p.startsWith(`${name}/`) }))]) : [void 0];
1397
+ const answer = main === void 0 ? void 0 : withFocusNotes(
1398
+ main,
1399
+ focused.map((name, i) => ({ repo: name, answer: passes[i] ?? null })),
1400
+ asked
1401
+ );
1402
+ const review = buildReview(meta, files, extras, answer, {
1403
+ ...rules ? { rules } : {},
1404
+ ...deps.now ? { now: deps.now() } : {},
1405
+ ...deps.agent ? {} : { notAskedWhy: "no agent for the AI step: stories are by folder" },
1406
+ ignored
1407
+ });
1408
+ const how = !prompt ? void 0 : inTree ? fellBack === 0 ? "read in its folder" : fellBack === passesAsked ? "read from the diff alone (the run in its folder gave no answer)" : `read in its folder (${fellBack} of ${passesAsked} passes from the diff alone: the run in its folder gave no answer)` : tree && "why" in tree ? `read from the diff alone (${tree.why})` : "read from the diff alone";
1409
+ return { review, repo: together ? null : picked[0].name, files, repos, ...how ? { how } : {} };
1410
+ }
1411
+ function createLocalReviews(deps) {
1412
+ const kept = /* @__PURE__ */ new Map();
1413
+ const now = () => (deps.now?.() ?? /* @__PURE__ */ new Date()).toISOString();
1414
+ const of = (sessionId) => {
1415
+ const k = kept.get(sessionId);
1416
+ if (k) return k;
1417
+ const s = deps.store?.read(sessionId);
1418
+ if (!s) return void 0;
1419
+ const back = {
1420
+ status: "ready",
1421
+ repo: s.repo,
1422
+ repos: s.repos,
1423
+ prepared: s.prepared,
1424
+ at: s.at,
1425
+ sent: s.sent,
1426
+ dismissed: s.dismissed
1427
+ };
1428
+ kept.set(sessionId, back);
1429
+ return back;
1430
+ };
1431
+ const persist = (sessionId, k) => {
1432
+ if (k.status !== "ready" || !k.prepared) return;
1433
+ deps.store?.save(sessionId, { repo: k.repo, repos: k.repos, prepared: k.prepared, at: k.at, sent: k.sent, dismissed: k.dismissed });
1434
+ };
1435
+ const wire = (k) => !k ? { status: "none", repo: null, repos: [] } : {
1436
+ status: k.status,
1437
+ repo: k.repo,
1438
+ repos: k.repos,
1439
+ at: k.at,
1440
+ ...k.prepared ? { review: k.prepared.review, sent: k.sent, dismissed: k.dismissed } : {},
1441
+ ...k.prepared?.how ? { how: k.prepared.how } : {},
1442
+ ...k.error ? { error: k.error } : {}
1443
+ };
1444
+ const mark = (sessionId, change) => {
1445
+ const k = of(sessionId);
1446
+ if (!k?.prepared) return false;
1447
+ change(k, new Set(k.prepared.review.drafts.map((d) => d.id)));
1448
+ persist(sessionId, k);
1449
+ return true;
1450
+ };
1451
+ return {
1452
+ state: (sessionId) => wire(of(sessionId)),
1453
+ /** The diff the kept review was made of; null when none is ready. */
1454
+ files: (sessionId) => of(sessionId)?.prepared?.files ?? null,
1455
+ start(sessionId, session, repo) {
1456
+ const was = of(sessionId);
1457
+ if (was?.status === "running") return wire(was);
1458
+ const running = {
1459
+ status: "running",
1460
+ repo: repo ?? null,
1461
+ repos: was?.repos ?? [],
1462
+ at: now(),
1463
+ sent: was?.prepared ? was.sent : [],
1464
+ dismissed: was?.prepared ? was.dismissed : [],
1465
+ ...was?.prepared ? { prepared: was.prepared } : {}
1466
+ };
1467
+ kept.set(sessionId, running);
1468
+ void deps.prepare(session, repo).then(
1469
+ // Another review: none of its notes is sent or dismissed yet.
1470
+ (p) => ({ status: "ready", repo: p.repo, repos: p.repos, prepared: p, at: now(), sent: [], dismissed: [] }),
1471
+ // The one from before stays the kept one (and the stored one): only this try failed.
1472
+ (err) => ({
1473
+ status: "failed",
1474
+ repo: repo ?? null,
1475
+ repos: running.repos,
1476
+ error: err.message,
1477
+ at: now(),
1478
+ sent: running.sent,
1479
+ dismissed: running.dismissed,
1480
+ ...running.prepared ? { prepared: running.prepared } : {}
1481
+ })
1482
+ ).then((next) => {
1483
+ if (kept.get(sessionId) !== running) return;
1484
+ kept.set(sessionId, next);
1485
+ persist(sessionId, next);
1486
+ deps.onChange(sessionId);
1487
+ });
1488
+ return wire(running);
1489
+ },
1490
+ /** These notes were handed to the agent (only ones the review has). */
1491
+ markSent: (sessionId, ids) => mark(sessionId, (k, known) => {
1492
+ k.sent = [.../* @__PURE__ */ new Set([...k.sent, ...ids.filter((x) => known.has(x))])];
1493
+ }),
1494
+ /** Dismiss a note (`on` false: bring it back). False when no review is ready, or it has no such note. */
1495
+ dismiss(sessionId, noteId, on = true) {
1496
+ let found = false;
1497
+ const ok = mark(sessionId, (k, known) => {
1498
+ found = known.has(noteId);
1499
+ if (!found) return;
1500
+ k.dismissed = on ? [.../* @__PURE__ */ new Set([...k.dismissed, noteId])] : k.dismissed.filter((x) => x !== noteId);
1501
+ });
1502
+ return ok && found;
1503
+ },
1504
+ drop: (sessionId) => {
1505
+ kept.delete(sessionId);
1506
+ deps.store?.drop(sessionId);
1507
+ }
1508
+ };
1509
+ }
1510
+ var MAX_NOTE = 1500;
1511
+ function localReviewNote(review, ids) {
1512
+ const keep = ids ? new Set(ids) : null;
1513
+ const notes = review.drafts.filter((d) => d.state === "draft" && (!keep || keep.has(d.id)));
1514
+ if (notes.length === 0) return null;
1515
+ return [
1516
+ `A review of this branch's changes in ${review.repo} raised ${notes.length} point${notes.length === 1 ? "" : "s"}. Each is a reviewer's reading of the diff, between <<< and >>>: weigh it, don't just obey it.`,
1517
+ ...review.repo.includes(REPOS_JOIN) ? ["Each path starts with its repo's name."] : [],
1518
+ ...notes.map((d) => `- ${asData(d.path, 160)}:${d.line}: <<< ${asData(d.body, MAX_NOTE)} >>>`),
1519
+ "For each: say whether you agree, and fix the ones you agree with (with a test where it applies). Leave the ones you disagree with and say why. Then build and run the tests."
1520
+ ].join("\n");
1521
+ }
1522
+
1523
+ // src/server/routes/session-review-routes.ts
1524
+ function mountSessionReviewRoutes(app, deps) {
1525
+ const reviews = createLocalReviews({
1526
+ prepare: deps.prepare,
1527
+ onChange: (sessionId) => deps.broadcast("session-review-changed", { sessionId }),
1528
+ ...deps.store ? { store: deps.store } : {}
1529
+ });
1530
+ app.get("/api/sessions/:id/review", (c) => {
1531
+ const id = c.req.param("id");
1532
+ if (!findSession2(id)) return c.json({ error: "unknown session" }, 404);
1533
+ return c.json(reviews.state(id));
1534
+ });
1535
+ app.post("/api/sessions/:id/review", async (c) => {
1536
+ const id = c.req.param("id");
1537
+ const session = findSession2(id);
1538
+ if (!session) return c.json({ error: "unknown session" }, 404);
1539
+ if (session.archivedAt) return c.json({ error: "It is archived: restore it first." }, 409);
1540
+ const body = await c.req.json().catch(() => ({}));
1541
+ if (body.repo !== void 0 && typeof body.repo !== "string") return c.json({ error: "repo: string" }, 400);
1542
+ return c.json(reviews.start(id, session, body.repo));
1543
+ });
1544
+ app.get("/api/sessions/:id/review/diff", (c) => {
1545
+ const id = c.req.param("id");
1546
+ if (!findSession2(id)) return c.json({ error: "unknown session" }, 404);
1547
+ const files = reviews.files(id);
1548
+ return files ? c.json({ files }) : c.json({ error: "no review of it is prepared" }, 404);
1549
+ });
1550
+ app.get("/api/sessions/:id/review/current", (c) => {
1551
+ const id = c.req.param("id");
1552
+ const session = findSession2(id);
1553
+ if (!session) return c.json({ error: "unknown session" }, 404);
1554
+ const kept = reviews.state(id);
1555
+ if (!kept.review) return c.json({ error: "no review of it is prepared" }, 404);
1556
+ if (session.archivedAt) return c.json({ current: true });
1557
+ let now;
1558
+ try {
1559
+ now = deps.signature(session, kept.repo);
1560
+ } catch (err) {
1561
+ return c.json({ error: err.message }, 502);
1562
+ }
1563
+ return c.json({ current: now === kept.review.headSha });
1564
+ });
1565
+ app.post("/api/sessions/:id/review/send", async (c) => {
1566
+ const id = c.req.param("id");
1567
+ if (!findSession2(id)) return c.json({ error: "unknown session" }, 404);
1568
+ const body = await c.req.json().catch(() => ({}));
1569
+ const ids = body.ids === void 0 ? void 0 : Array.isArray(body.ids) ? body.ids.filter((x) => typeof x === "string") : null;
1570
+ if (ids === null) return c.json({ error: "ids: string[]" }, 400);
1571
+ const kept = reviews.state(id);
1572
+ const review = kept.review;
1573
+ if (!review) return c.json({ error: "no review of it is prepared" }, 409);
1574
+ const gone = new Set(kept.dismissed ?? []);
1575
+ const wanted = ids ?? review.drafts.filter((d) => d.state === "draft" && !gone.has(d.id)).map((d) => d.id);
1576
+ const note = localReviewNote(review, wanted);
1577
+ if (!note) return c.json({ error: "It has no notes to hand over." }, 409);
1578
+ try {
1579
+ await deps.tell(id, note);
1580
+ } catch (err) {
1581
+ return c.json({ error: err.message }, 502);
1582
+ }
1583
+ const went = wanted.filter((x) => review.drafts.some((d) => d.id === x && d.state === "draft"));
1584
+ reviews.markSent(id, went);
1585
+ deps.broadcast("session-review-changed", { sessionId: id });
1586
+ return c.json({ ok: true, sent: went.length });
1587
+ });
1588
+ app.post("/api/sessions/:id/review/dismiss", async (c) => {
1589
+ const id = c.req.param("id");
1590
+ if (!findSession2(id)) return c.json({ error: "unknown session" }, 404);
1591
+ const body = await c.req.json().catch(() => ({}));
1592
+ if (typeof body.id !== "string" || !body.id) return c.json({ error: "id: string" }, 400);
1593
+ if (!reviews.dismiss(id, body.id, body.undo !== true)) return c.json({ error: "no such note in the review prepared for it" }, 404);
1594
+ deps.broadcast("session-review-changed", { sessionId: id });
1595
+ return c.json(reviews.state(id));
1596
+ });
1597
+ return { drop: reviews.drop };
1598
+ }
1599
+
1600
+ // src/core/review/local-review-store.ts
1601
+ var strings2 = (v) => Array.isArray(v) && v.every((x) => typeof x === "string");
1602
+ function isStoredLocalReview(v) {
1603
+ const o = v;
1604
+ if (!o || typeof o !== "object") return false;
1605
+ const p = o.prepared;
1606
+ return (o.repo === null || typeof o.repo === "string") && strings2(o.repos) && typeof o.at === "string" && strings2(o.sent) && strings2(o.dismissed) && !!p && typeof p === "object" && Array.isArray(p.files) && strings2(p.repos) && !!p.review && typeof p.review === "object" && typeof p.review.headSha === "string" && Array.isArray(p.review.drafts) && Array.isArray(p.review.stories) && Array.isArray(p.review.files);
1607
+ }
1608
+ function readLocalReview(sessionId) {
1609
+ const row = withDb(
1610
+ (d) => d.prepare("SELECT data FROM session_reviews WHERE session_id = ?").get(sessionId)
1611
+ );
1612
+ const v = row ? json.parse(row.data) : null;
1613
+ return isStoredLocalReview(v) ? v : null;
1614
+ }
1615
+ function saveLocalReview(sessionId, review) {
1616
+ withDb(
1617
+ (d) => d.prepare("INSERT OR REPLACE INTO session_reviews (session_id, data) VALUES (?, ?)").run(sessionId, JSON.stringify(review))
1618
+ );
1619
+ }
1620
+ function dropLocalReview(sessionId) {
1621
+ withDb((d) => d.prepare("DELETE FROM session_reviews WHERE session_id = ?").run(sessionId));
1622
+ }
1623
+
1624
+ // src/core/review/local-review-tree.ts
1625
+ import path2 from "path";
1626
+ var norm = (p) => path2.resolve(p).replace(/\\/g, "/").replace(/\/+$/, "");
1627
+ function sessionTree(paths, names) {
1628
+ const byName = /* @__PURE__ */ new Map();
1629
+ for (const p of paths) byName.set(path2.basename(norm(p)), [...byName.get(path2.basename(norm(p))) ?? [], norm(p)]);
1630
+ const dirs = names.map((n) => byName.get(n));
1631
+ if (names.length === 0 || dirs.some((d) => !d || d.length !== 1)) return null;
1632
+ const found = dirs.map((d) => d[0]);
1633
+ if (names.length === 1) return { cwd: found[0], repos: [{ dir: found[0], sub: null }] };
1634
+ const parent = path2.posix.dirname(found[0]);
1635
+ if (found.some((d) => path2.posix.dirname(d) !== parent)) return null;
1636
+ return { cwd: parent, repos: found.map((dir, i) => ({ dir, sub: names[i] })) };
1637
+ }
1638
+ var LOCAL_TREE_TIMEOUT_MS = 42e4;
1639
+ var SEVERAL_REPOS_LINE = "The folder holds several repos, each in the folder its paths start with: a file's path as listed is its path from where you are.";
1640
+ async function localTreeRun(paths, names, deps) {
1641
+ const mode = deps.readOnly();
1642
+ if (!mode?.localLines) return { why: "the agent has no read-only mode" };
1643
+ const tree = sessionTree(paths, names);
1644
+ if (!tree) return { why: "its repos are not in one folder" };
1645
+ if (!deps.exists(tree.cwd) || tree.repos.some((r) => !deps.exists(r.dir))) return { why: "its folder is not there" };
1646
+ const can = await (mode.available?.() ?? Promise.resolve({ ok: true }));
1647
+ if (!can.ok) return { why: can.why ?? "the read-only mode is not available" };
1648
+ const deny = mode.denyRules?.(tree.repos) ?? [];
1649
+ return {
1650
+ lines: [...mode.localLines, ...tree.repos.length > 1 ? [SEVERAL_REPOS_LINE] : []],
1651
+ ask: (prompt) => deps.run(prompt, tree.cwd, deny)
1652
+ };
1653
+ }
1654
+
1655
+ // src/core/platform/process-usage.ts
1656
+ import { execFile } from "child_process";
1657
+ import path3 from "path";
1658
+ var num = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? v : null;
1659
+ function parseCimUsage(json2) {
1660
+ let data;
1661
+ try {
1662
+ data = JSON.parse(json2);
1663
+ } catch {
1664
+ return [];
1665
+ }
1666
+ const rows = Array.isArray(data) ? data : data ? [data] : [];
1667
+ const out = [];
1668
+ for (const r of rows) {
1669
+ if (!r || typeof r !== "object") continue;
1670
+ const o = r;
1671
+ if (typeof o.ProcessId !== "number") continue;
1672
+ const started = num(o.Started);
1673
+ out.push({
1674
+ pid: o.ProcessId,
1675
+ ppid: typeof o.ParentProcessId === "number" ? o.ParentProcessId : 0,
1676
+ name: typeof o.Name === "string" ? o.Name : "",
1677
+ exe: typeof o.ExecutablePath === "string" ? o.ExecutablePath : null,
1678
+ command: typeof o.CommandLine === "string" ? o.CommandLine : "",
1679
+ memBytes: num(o.PrivatePageCount),
1680
+ // 0: a system process with no creation date.
1681
+ startedAt: started ? started : null
1682
+ });
1683
+ }
1684
+ return out;
1685
+ }
1686
+ function elapsedMs(etime) {
1687
+ const m = /^(?:(\d+)-)?(?:(\d+):)?(\d+):(\d+)$/.exec(etime.trim());
1688
+ if (!m) return null;
1689
+ const [days, hours, mins, secs] = [m[1], m[2], m[3], m[4]].map((x) => Number(x ?? 0));
1690
+ return (((days * 24 + hours) * 60 + mins) * 60 + secs) * 1e3;
1691
+ }
1692
+ function parsePsUsage(stdout, now) {
1693
+ const out = [];
1694
+ for (const line of stdout.split(/\r?\n/)) {
1695
+ const m = /^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.*)$/.exec(line);
1696
+ if (!m) continue;
1697
+ const command = m[5].trim();
1698
+ const first = commandWords(command)[0] ?? "";
1699
+ const elapsed = elapsedMs(m[4]);
1700
+ out.push({
1701
+ pid: Number(m[1]),
1702
+ ppid: Number(m[2]),
1703
+ name: path3.posix.basename(first),
1704
+ exe: first.startsWith("/") ? first : null,
1705
+ command,
1706
+ memBytes: Number(m[3]) * 1024,
1707
+ startedAt: elapsed === null ? null : now - elapsed
1708
+ });
1709
+ }
1710
+ return out;
1711
+ }
1712
+ var run = (cmd, args) => new Promise(
1713
+ (resolve) => execFile(
1714
+ programPath(cmd),
1715
+ args,
1716
+ { encoding: "utf-8", windowsHide: true, timeout: 2e4, maxBuffer: 64 * 1024 * 1024 },
1717
+ (_err, stdout) => resolve(stdout ?? "")
1718
+ )
1719
+ );
1720
+ var CIM_USAGE = "[Console]::OutputEncoding = [Text.Encoding]::UTF8; Get-CimInstance Win32_Process | Select-Object ProcessId,ParentProcessId,Name,ExecutablePath,CommandLine,PrivatePageCount,@{n='Started';e={ if ($_.CreationDate) { ([DateTimeOffset]$_.CreationDate).ToUnixTimeMilliseconds() } else { 0 } }} | ConvertTo-Json -Compress";
1721
+ async function listProcessUsage(now = Date.now()) {
1722
+ if (process.platform === "win32") return parseCimUsage(await run("powershell", ["-NoProfile", "-NonInteractive", "-Command", CIM_USAGE]));
1723
+ return parsePsUsage(await run("ps", ["-A", "-o", "pid=,ppid=,rss=,etime=,args="]), now);
1724
+ }
1725
+
1726
+ // src/core/sessions/leftover-sweep.ts
1727
+ async function sweepLeftovers(deps) {
1728
+ const procs = await deps.list();
1729
+ if (procs.length === 0) return null;
1730
+ const now = (deps.now ?? Date.now)();
1731
+ const found = { sessions: 0, processes: 0, bytes: 0 };
1732
+ for (const s of deps.sessions()) {
1733
+ const pid = deps.agentPid(s.id);
1734
+ const left = sessionProcesses(procs, { agentPids: new Set(pid ? [pid] : []), dirs: s.paths, now }).processes.filter((p) => p.leftover);
1735
+ if (left.length === 0) continue;
1736
+ const bytes = left.reduce((n, p) => n + (p.memBytes ?? 0), 0);
1737
+ found.sessions++;
1738
+ found.processes += left.length;
1739
+ found.bytes += bytes;
1740
+ const names = left.slice(0, 2).map((p) => p.what);
1741
+ deps.note(
1742
+ `${s.name}: ${left.length} process${left.length === 1 ? "" : "es"} left running for over a day (${formatBytes(bytes)}): ${names.join("; ")}${left.length > 2 ? ` and ${left.length - 2} more` : ""} \u2014 its \u22EF menu \u2192 Processes\u2026 stops them`,
1743
+ { level: "warn", sessionId: s.id }
1744
+ );
1745
+ }
1746
+ return found;
1747
+ }
1748
+ function leftoverSummary(found) {
1749
+ if (!found) return "couldn't read the running processes";
1750
+ if (found.processes === 0) return "nothing left running for over a day";
1751
+ return `${found.processes} process${found.processes === 1 ? "" : "es"} left running for over a day in ${found.sessions} session${found.sessions === 1 ? "" : "s"} (${formatBytes(found.bytes)})`;
1752
+ }
1753
+
1172
1754
  // src/core/worktree/code-browse.ts
1173
1755
  import fs3 from "fs";
1174
- import path2 from "path";
1756
+ import path4 from "path";
1175
1757
  var MAX_CODE_FILES = 5e4;
1176
1758
  var MAX_CODE_FILE_BYTES = 2 * 1024 * 1024;
1177
1759
  var LIST_TTL_MS = 3e3;
1178
1760
  function codeRoots(s) {
1179
- return s.paths.map((p) => ({ name: path2.basename(p), root: p }));
1761
+ return s.paths.map((p) => ({ name: path4.basename(p), root: p }));
1180
1762
  }
1181
1763
  function groupRoot(s) {
1182
1764
  if (!s.isGroup || s.paths.length === 0) return null;
1183
- const parents = [...new Set(s.paths.map((p) => path2.dirname(p)))];
1765
+ const parents = [...new Set(s.paths.map((p) => path4.dirname(p)))];
1184
1766
  return parents.length === 1 ? parents[0] : null;
1185
1767
  }
1186
1768
  var realIo = {
@@ -1289,11 +1871,11 @@ async function codeFilePath(s, repo, rel, io = realIo) {
1289
1871
  if (!root) return { error: "unknown repo" };
1290
1872
  if (!allowed) return { error: "not listed" };
1291
1873
  try {
1292
- const full = path2.resolve(root, rel);
1874
+ const full = path4.resolve(root, rel);
1293
1875
  const realRoot = fs3.realpathSync.native(root);
1294
1876
  const real = fs3.realpathSync.native(full);
1295
- const inside2 = path2.relative(realRoot, real);
1296
- if (!inside2 || inside2.startsWith("..") || path2.isAbsolute(inside2)) return { error: "not listed" };
1877
+ const inside2 = path4.relative(realRoot, real);
1878
+ if (!inside2 || inside2.startsWith("..") || path4.isAbsolute(inside2)) return { error: "not listed" };
1297
1879
  const st = fs3.statSync(real);
1298
1880
  if (!st.isFile()) return { error: "unreadable" };
1299
1881
  return { real, size: st.size };
@@ -1387,9 +1969,9 @@ var NOT_NAMES = /* @__PURE__ */ new Set([
1387
1969
  "typeof",
1388
1970
  "await"
1389
1971
  ]);
1390
- function declarationOf(path20, text) {
1972
+ function declarationOf(path22, text) {
1391
1973
  for (const r of RULES) {
1392
- if (!r.ext.test(path20)) continue;
1974
+ if (!r.ext.test(path22)) continue;
1393
1975
  const m = r.re.exec(text);
1394
1976
  if (!m) continue;
1395
1977
  const name = r.name(m);
@@ -1747,7 +2329,7 @@ function mountSetupRoutes(app, opts) {
1747
2329
 
1748
2330
  // src/core/updates/update-source.ts
1749
2331
  import fs4 from "fs";
1750
- import path3 from "path";
2332
+ import path5 from "path";
1751
2333
 
1752
2334
  // src/core/updates/updates.ts
1753
2335
  function parseVersion(v) {
@@ -1804,8 +2386,8 @@ function whatsNewFor(i) {
1804
2386
  }
1805
2387
  function installKindOf(packageRoot2, configDir, hasGit) {
1806
2388
  if (!packageRoot2) return "npm";
1807
- const norm2 = (p) => p.replace(/\\/g, "/").replace(/\/+$/, "").toLowerCase();
1808
- if (norm2(packageRoot2).startsWith(`${norm2(configDir)}/runtime/`)) return "desktop";
2389
+ const norm3 = (p) => p.replace(/\\/g, "/").replace(/\/+$/, "").toLowerCase();
2390
+ if (norm3(packageRoot2).startsWith(`${norm3(configDir)}/runtime/`)) return "desktop";
1809
2391
  return hasGit ? "dev" : "npm";
1810
2392
  }
1811
2393
  function parseDesktopUpdate(text) {
@@ -1832,9 +2414,9 @@ function parseDesktopUpdate(text) {
1832
2414
  var RELEASES_REPO = "moberghr/cli-work-tree-manager";
1833
2415
  var RELEASES_URL = `https://api.github.com/repos/${RELEASES_REPO}/releases?per_page=30`;
1834
2416
  var SEEN_KEY = "ui:seen-version";
1835
- var desktopUpdatePath = () => path3.join(getConfigDir(), "desktop-update.json");
1836
- var desktopRequestPath = () => path3.join(getConfigDir(), "desktop-request.json");
1837
- async function fetchReleases(get = (url) => fetch(url, { headers: { "User-Agent": "work", Accept: "application/vnd.github+json" }, signal: AbortSignal.timeout(15e3) }), run = defaultRunner) {
2417
+ var desktopUpdatePath = () => path5.join(getConfigDir(), "desktop-update.json");
2418
+ var desktopRequestPath = () => path5.join(getConfigDir(), "desktop-request.json");
2419
+ async function fetchReleases(get = (url) => fetch(url, { headers: { "User-Agent": "work", Accept: "application/vnd.github+json" }, signal: AbortSignal.timeout(15e3) }), run2 = defaultRunner) {
1838
2420
  const why = await get(RELEASES_URL).then(
1839
2421
  async (res) => res.ok ? parseReleases(await res.json()) : res.status === 403 ? "GitHub's limit for this address is spent" : `GitHub answered ${res.status}`,
1840
2422
  (err) => err
@@ -1843,7 +2425,7 @@ async function fetchReleases(get = (url) => fetch(url, { headers: { "User-Agent"
1843
2425
  const offline = networkFailure(why);
1844
2426
  if (offline) throw new Error(offline);
1845
2427
  } else if (typeof why !== "string") return why;
1846
- const r = await run("gh", ["api", `repos/${RELEASES_REPO}/releases?per_page=30`], process.cwd());
2428
+ const r = await run2("gh", ["api", `repos/${RELEASES_REPO}/releases?per_page=30`], process.cwd());
1847
2429
  if (r.code === 0) {
1848
2430
  try {
1849
2431
  return parseReleases(JSON.parse(r.stdout));
@@ -1895,7 +2477,7 @@ function markSeenVersion(version) {
1895
2477
  }
1896
2478
  function installKind() {
1897
2479
  const root = packageRoot();
1898
- return installKindOf(root, getConfigDir(), !!root && fs4.existsSync(path3.join(root, ".git")));
2480
+ return installKindOf(root, getConfigDir(), !!root && fs4.existsSync(path5.join(root, ".git")));
1899
2481
  }
1900
2482
  var defaultDeps = () => ({
1901
2483
  fetchReleases: () => fetchReleases(),
@@ -1946,12 +2528,12 @@ function createUpdates(deps = defaultDeps()) {
1946
2528
  checkedAt: () => checkedAt
1947
2529
  };
1948
2530
  }
1949
- async function lookForUpdates(updates, run, changed) {
2531
+ async function lookForUpdates(updates, run2, changed) {
1950
2532
  const before = updates.wire().latest;
1951
2533
  await updates.refresh();
1952
2534
  const w = updates.wire();
1953
- if (w.checkError) run.fail(w.checkError);
1954
- else run.done(w.available ? `work ${w.available.version} is out (this is ${w.running})` : `up to date (${w.running})`);
2535
+ if (w.checkError) run2.fail(w.checkError);
2536
+ else run2.done(w.available ? `work ${w.available.version} is out (this is ${w.running})` : `up to date (${w.running})`);
1955
2537
  if (w.latest !== before) changed();
1956
2538
  }
1957
2539
 
@@ -2090,7 +2672,7 @@ function mountRepoRoutes(app, opts) {
2090
2672
  const regenerate = (name) => {
2091
2673
  const bin = opts.workBin?.();
2092
2674
  if (!bin) return;
2093
- const run = opts.activity?.start("groups", `Writing ${name}'s combined instructions`);
2675
+ const run2 = opts.activity?.start("groups", `Writing ${name}'s combined instructions`);
2094
2676
  const child = spawn_default(
2095
2677
  process.execPath,
2096
2678
  [...process.execArgv.filter((f) => !/^--inspect/.test(f)), bin, "config", "group", "regen", name],
@@ -2100,8 +2682,8 @@ function mountRepoRoutes(app, opts) {
2100
2682
  env: { ...process.env, NO_COLOR: "1" }
2101
2683
  }
2102
2684
  );
2103
- child.on("error", (e) => run?.fail(e.message));
2104
- child.on("close", (code) => code === 0 ? run?.done("written") : run?.fail(`work config group regen exited ${code}`));
2685
+ child.on("error", (e) => run2?.fail(e.message));
2686
+ child.on("close", (code) => code === 0 ? run2?.done("written") : run2?.fail(`work config group regen exited ${code}`));
2105
2687
  };
2106
2688
  app.get("/api/repos", (c) => {
2107
2689
  try {
@@ -2160,8 +2742,8 @@ var SETTING_PATTERNS = {
2160
2742
  agentId: "^[\\w.-]+$",
2161
2743
  envName: "^[A-Za-z_][A-Za-z0-9_]*$"
2162
2744
  };
2163
- var bool = (path20, section, label, help, def, when) => ({
2164
- path: path20,
2745
+ var bool = (path22, section, label, help, def, when) => ({
2746
+ path: path22,
2165
2747
  section,
2166
2748
  label,
2167
2749
  help,
@@ -2274,6 +2856,14 @@ var SETTINGS = [
2274
2856
  false,
2275
2857
  "at the next terminal start"
2276
2858
  ),
2859
+ bool(
2860
+ "agentsLowPriority",
2861
+ "Agents & terminals",
2862
+ "Run agents below normal priority",
2863
+ "What an agent runs (builds, tests) uses the cores nothing else wants and gives way to what you look at. Try it if the computer freezes while sessions build.",
2864
+ false,
2865
+ "at the next agent start (a running one: restart it)"
2866
+ ),
2277
2867
  // ---- Pull requests
2278
2868
  bool(
2279
2869
  "prWatch.autoArchive",
@@ -2519,7 +3109,7 @@ var SETTINGS = [
2519
3109
  "at the next work web start"
2520
3110
  )
2521
3111
  ];
2522
- var settingAt = (path20) => SETTINGS.find((f) => f.path === path20);
3112
+ var settingAt = (path22) => SETTINGS.find((f) => f.path === path22);
2523
3113
  function checkSetting(field, raw) {
2524
3114
  const checked = checkValue(field, raw);
2525
3115
  if (checked.ok && checked.value === null && field.required) return { ok: false, error: "it can\u2019t be left empty" };
@@ -2565,16 +3155,16 @@ function checkValue(field, raw) {
2565
3155
  return typeof raw === "string" && k.options.some((o) => o.value === raw) ? { ok: true, value: raw } : { ok: false, error: `one of ${k.options.map((o) => o.value).join(", ")}` };
2566
3156
  }
2567
3157
  }
2568
- function valueAt(obj, path20) {
3158
+ function valueAt(obj, path22) {
2569
3159
  let cur = obj;
2570
- for (const key of path20.split(".")) {
3160
+ for (const key of path22.split(".")) {
2571
3161
  if (!cur || typeof cur !== "object" || Array.isArray(cur)) return void 0;
2572
3162
  cur = cur[key];
2573
3163
  }
2574
3164
  return cur;
2575
3165
  }
2576
- function setValueAt(obj, path20, value) {
2577
- const keys = path20.split(".");
3166
+ function setValueAt(obj, path22, value) {
3167
+ const keys = path22.split(".");
2578
3168
  const chain = [obj];
2579
3169
  let cur = obj;
2580
3170
  for (const key of keys.slice(0, -1)) {
@@ -2611,8 +3201,8 @@ function checkRepoSetting(key, raw) {
2611
3201
  return raw === "all" || raw === "asked" || raw === "off" ? { ok: true, value: raw } : { ok: false, error: "all, asked or off" };
2612
3202
  }
2613
3203
  function repoSettingsOf(raw, alias) {
2614
- const map = (path20) => {
2615
- const m = valueAt(raw, path20);
3204
+ const map = (path22) => {
3205
+ const m = valueAt(raw, path22);
2616
3206
  return m && typeof m === "object" && !Array.isArray(m) ? m : {};
2617
3207
  };
2618
3208
  const checks = map(REPO_SETTING_PATH.requiredChecks)[alias];
@@ -2668,7 +3258,7 @@ function mountSettingsRoutes(app, opts) {
2668
3258
 
2669
3259
  // src/core/settings/settings-admin.ts
2670
3260
  import fs6 from "fs";
2671
- import path4 from "path";
3261
+ import path6 from "path";
2672
3262
  function rawConfig(file = getConfigPath()) {
2673
3263
  try {
2674
3264
  const raw = JSON.parse(fs6.readFileSync(file, "utf-8"));
@@ -2686,13 +3276,13 @@ function readSettings() {
2686
3276
  }
2687
3277
  return { values, configPath: getConfigPath() };
2688
3278
  }
2689
- async function writeSetting(path20, value) {
2690
- const field = settingAt(path20);
2691
- if (!field) throw new SettingsError(`no setting ${path20}`, 404);
3279
+ async function writeSetting(path22, value) {
3280
+ const field = settingAt(path22);
3281
+ if (!field) throw new SettingsError(`no setting ${path22}`, 404);
2692
3282
  const checked = checkSetting(field, value);
2693
3283
  if (!checked.ok) throw new SettingsError(`${field.label}: ${checked.error}`);
2694
- const toWrite = checkedFolders(path20, checked.value);
2695
- await editConfig((raw) => setValueAt(raw, path20, toWrite)).catch((err) => {
3284
+ const toWrite = checkedFolders(path22, checked.value);
3285
+ await editConfig((raw) => setValueAt(raw, path22, toWrite)).catch((err) => {
2696
3286
  throw err instanceof RepoAdminError ? new SettingsError(err.message) : err;
2697
3287
  });
2698
3288
  return readSettings();
@@ -2706,9 +3296,9 @@ function checkedFolders(at, value) {
2706
3296
  if (at === "scanRoots" && Array.isArray(value))
2707
3297
  return value.map((v) => {
2708
3298
  const p = expandHome(v);
2709
- if (!path4.isAbsolute(p))
3299
+ if (!path6.isAbsolute(p))
2710
3300
  throw new SettingsError(`Folders scanned for repos: ${v} isn't a full path (start it from the drive, / or ~)`);
2711
- const full = path4.resolve(p);
3301
+ const full = path6.resolve(p);
2712
3302
  if (!fs6.statSync(full, { throwIfNoEntry: false })?.isDirectory())
2713
3303
  throw new SettingsError(`Folders scanned for repos: ${full} isn't a folder`);
2714
3304
  return full;
@@ -2759,7 +3349,7 @@ var configSettings = {
2759
3349
  };
2760
3350
 
2761
3351
  // src/core/conversations/timeline-source.ts
2762
- import path5 from "path";
3352
+ import path7 from "path";
2763
3353
 
2764
3354
  // src/core/conversations/timeline.ts
2765
3355
  var SIZE_LABEL = /^(\d+ files? · \+\d+ −\d+|no changes)$/;
@@ -2800,19 +3390,19 @@ function order(k) {
2800
3390
  var DAYS = 30;
2801
3391
  var MAX_TRANSCRIPT_BYTES = 8 << 20;
2802
3392
  var MAX_COMMITS = 100;
2803
- async function commitsOf(repo, since, run) {
2804
- const git3 = (...args) => run("git", ["-C", repo, ...args], repo);
3393
+ async function commitsOf(repo, since, run2) {
3394
+ const git3 = (...args) => run2("git", ["-C", repo, ...args], repo);
2805
3395
  const base = (await git3("merge-base", "HEAD", "origin/HEAD")).stdout.trim();
2806
3396
  const range = base ? [`${base}..HEAD`] : [`--since=${since}`, "HEAD"];
2807
3397
  const log = await git3("log", `--max-count=${MAX_COMMITS}`, "--format=%H%x09%aI%x09%s", ...range);
2808
3398
  if (log.code !== 0) return [];
2809
3399
  return log.stdout.split("\n").filter(Boolean).map((line) => {
2810
3400
  const [sha, at, ...subject] = line.split(" ");
2811
- return { repo: path5.basename(repo), sha, at, subject: subject.join(" ") };
3401
+ return { repo: path7.basename(repo), sha, at, subject: subject.join(" ") };
2812
3402
  });
2813
3403
  }
2814
3404
  async function sessionTimeline(s, deps = {}) {
2815
- const run = deps.run ?? defaultRunner;
3405
+ const run2 = deps.run ?? defaultRunner;
2816
3406
  const since = Math.max(Date.parse(s.createdAt) || 0, (deps.now ?? Date.now()) - DAYS * 864e5);
2817
3407
  const transcripts = [];
2818
3408
  const conv = agentOf(s).conversation;
@@ -2823,7 +3413,7 @@ async function sessionTimeline(s, deps = {}) {
2823
3413
  } catch {
2824
3414
  }
2825
3415
  }
2826
- const commits = s.archivedAt ? [] : (await Promise.all(s.paths.map((p) => commitsOf(p, s.createdAt, run).catch(() => [])))).flat();
3416
+ const commits = s.archivedAt ? [] : (await Promise.all(s.paths.map((p) => commitsOf(p, s.createdAt, run2).catch(() => [])))).flat();
2827
3417
  const prs = (deps.ci?.repos ?? []).filter((r) => r.pr).map((r) => ({
2828
3418
  repo: r.name,
2829
3419
  number: r.pr.number,
@@ -2876,7 +3466,7 @@ function mountBlockRoutes(app, opts) {
2876
3466
 
2877
3467
  // src/server/routes/jira-watch-routes.ts
2878
3468
  import fs7 from "fs";
2879
- import path6 from "path";
3469
+ import path8 from "path";
2880
3470
 
2881
3471
  // src/core/jira/jira-prompt.ts
2882
3472
  var branchFor = (issue) => `feat/${issue.key}`;
@@ -3097,14 +3687,14 @@ async function sweepJira(deps) {
3097
3687
  var EVERY_MS = 5 * 6e4;
3098
3688
  function aboutRepo(dir) {
3099
3689
  try {
3100
- const readme = ["README.md", "readme.md", "README"].map((n) => path6.join(dir, n)).find((f) => fs7.existsSync(f));
3690
+ const readme = ["README.md", "readme.md", "README"].map((n) => path8.join(dir, n)).find((f) => fs7.existsSync(f));
3101
3691
  if (readme) {
3102
3692
  const line = fs7.readFileSync(readme, "utf8").split(/\r?\n/).map(
3103
3693
  (l) => l.replace(/^[#>*\-\s]+/, "").replace(/[`*_[\]]/g, "").trim()
3104
3694
  ).find((l) => l.length > 20 && !/^(!|<|http)/.test(l));
3105
3695
  if (line) return line.slice(0, 160);
3106
3696
  }
3107
- const pkg = path6.join(dir, "package.json");
3697
+ const pkg = path8.join(dir, "package.json");
3108
3698
  if (fs7.existsSync(pkg)) {
3109
3699
  const d = JSON.parse(fs7.readFileSync(pkg, "utf8")).description;
3110
3700
  if (typeof d === "string" && d.trim()) return d.trim().slice(0, 160);
@@ -3118,7 +3708,7 @@ function watchTargets(cfg = loadConfig()) {
3118
3708
  const repos = Object.entries(cfg.repos).map(([alias, dir]) => ({
3119
3709
  name: alias,
3120
3710
  kind: "repo",
3121
- members: [path6.basename(dir)],
3711
+ members: [path8.basename(dir)],
3122
3712
  about: aboutRepo(dir)
3123
3713
  }));
3124
3714
  const groups = Object.entries(cfg.groups).map(([name, aliases]) => ({ name, kind: "group", members: aliases }));
@@ -3150,7 +3740,7 @@ function mountJiraWatchRoutes(app, opts) {
3150
3740
  running ??= (async () => {
3151
3741
  try {
3152
3742
  if (!readSettings2().enabled) return;
3153
- const run = opts.activity?.start("jira-watch", "Looking for newly assigned Jira issues");
3743
+ const run2 = opts.activity?.start("jira-watch", "Looking for newly assigned Jira issues");
3154
3744
  const deps = {
3155
3745
  // Throws when acli can't list them: the sweep fails (said in Activity) rather than reading "none".
3156
3746
  fetchIssues: fetchMyIssuesOrThrow,
@@ -3159,17 +3749,17 @@ function mountJiraWatchRoutes(app, opts) {
3159
3749
  sessions: () => loadHistory(),
3160
3750
  ask: (prompt) => runInternal(prompt, 9e4),
3161
3751
  start: (target, branch, issue) => start(target, branch, issue, true),
3162
- note: (text, level, sessionId) => run?.note(text, { level, ...sessionId ? { sessionId } : {} }),
3752
+ note: (text, level, sessionId) => run2?.note(text, { level, ...sessionId ? { sessionId } : {} }),
3163
3753
  maxPerDay: loadConfig()?.jiraWatch?.maxPerDay
3164
3754
  };
3165
3755
  try {
3166
3756
  const r = await sweepJira(deps);
3167
- run?.done(
3757
+ run2?.done(
3168
3758
  r.started || r.suggested || r.waiting ? `${r.started} started \xB7 ${r.suggested} to start yourself${r.waiting ? ` \xB7 ${r.waiting} waiting` : ""}` : "no new issues"
3169
3759
  );
3170
3760
  if (r.started || r.suggested) changed();
3171
3761
  } catch (err) {
3172
- run?.fail(err.message);
3762
+ run2?.fail(err.message);
3173
3763
  }
3174
3764
  lastRunAt = (/* @__PURE__ */ new Date()).toISOString();
3175
3765
  } finally {
@@ -3262,6 +3852,7 @@ function mountJiraWatchRoutes(app, opts) {
3262
3852
  // src/server/loop-watch.ts
3263
3853
  import { monitorEventLoopDelay } from "perf_hooks";
3264
3854
  function watchLoop(opts) {
3855
+ const ranSince = opts.ran ?? takeSlowestSync;
3265
3856
  const every = opts.everyMs ?? 1e4;
3266
3857
  const threshold = opts.thresholdMs ?? 1e3;
3267
3858
  const h = monitorEventLoopDelay({ resolution: 20 });
@@ -3272,7 +3863,8 @@ function watchLoop(opts) {
3272
3863
  h.reset();
3273
3864
  const s = slowest;
3274
3865
  slowest = null;
3275
- if (blockedMs >= threshold) opts.onStall({ blockedMs, slowest: s });
3866
+ const ran = ranSince();
3867
+ if (blockedMs >= threshold) opts.onStall({ blockedMs, slowest: s, ran });
3276
3868
  }, every);
3277
3869
  timer.unref?.();
3278
3870
  return {
@@ -3288,11 +3880,11 @@ function watchLoop(opts) {
3288
3880
  }
3289
3881
  function describeStall(s) {
3290
3882
  const secs = (s.blockedMs / 1e3).toFixed(1);
3291
- return `the server was blocked for ${secs} s (status updates, terminals and notifications waited)${s.slowest ? `; slowest request: ${s.slowest.what} (${(s.slowest.ms / 1e3).toFixed(1)} s)` : ""}`;
3883
+ return `the server was blocked for ${secs} s (status updates, terminals and notifications waited)${s.slowest ? `; slowest request: ${s.slowest.what} (${(s.slowest.ms / 1e3).toFixed(1)} s)` : ""}${s.ran ? `; it ran: ${s.ran.what} (${(s.ran.ms / 1e3).toFixed(1)} s)` : ""}`;
3292
3884
  }
3293
3885
 
3294
3886
  // src/server/web-server.ts
3295
- import path17 from "path";
3887
+ import path19 from "path";
3296
3888
  import { Hono } from "hono";
3297
3889
  import { streamSSE as streamSSE2 } from "hono/streaming";
3298
3890
 
@@ -3413,7 +4005,8 @@ var realBranchCheckDeps = {
3413
4005
  (prefix) => git(["show-ref", "--verify", "--quiet", `${prefix}${branch}`], repoPath).exitCode === 0
3414
4006
  ),
3415
4007
  validBranch: (name) => !name.startsWith("-") && git(["check-ref-format", "--branch", name], os.tmpdir()).exitCode === 0,
3416
- sessions: loadHistory
4008
+ sessions: loadHistory,
4009
+ ownsBranch: (target, branch, config) => ownsBranch(target, branch, config)
3417
4010
  };
3418
4011
  function checkBranch(target, branch, config, deps = realBranchCheckDeps) {
3419
4012
  const resolved = resolveProjectTarget(target, config);
@@ -3427,7 +4020,8 @@ function checkBranch(target, branch, config, deps = realBranchCheckDeps) {
3427
4020
  valid,
3428
4021
  exists: repoPaths.some((p) => deps.branchExists(p, branch)),
3429
4022
  session: s ? { id: sessionIdFor(s), archived: !!s.archivedAt } : null,
3430
- free: valid ? firstFreeBranch(branch, taken) : null
4023
+ free: valid ? firstFreeBranch(branch, taken) : null,
4024
+ ...deps.ownsBranch(target, branch, config) ? { ownCheckout: true } : {}
3431
4025
  };
3432
4026
  }
3433
4027
 
@@ -3527,19 +4121,19 @@ function mountPanesRoutes(app, opts) {
3527
4121
  const prsFetch = createSharedFetch(async () => {
3528
4122
  const config = loadConfig();
3529
4123
  if (!config) return { prs: [] };
3530
- const run = opts.activity?.start("pr-list", "Listing open pull requests");
4124
+ const run2 = opts.activity?.start("pr-list", "Listing open pull requests");
3531
4125
  try {
3532
4126
  const { map, incomplete } = await fetchAllPullRequests(config.repos);
3533
4127
  const prs = Array.from(map.values()).flat();
3534
4128
  if (incomplete.length)
3535
- run?.note(
4129
+ run2?.note(
3536
4130
  `couldn't list every PR of ${incomplete.join(", ")} (gh failed, or 100+ open): archiving isn't suggested for sessions there`,
3537
4131
  { level: "warn" }
3538
4132
  );
3539
- run?.done(`${prs.length} open PR${prs.length === 1 ? "" : "s"} in ${Object.keys(config.repos).length} repos`);
4133
+ run2?.done(`${prs.length} open PR${prs.length === 1 ? "" : "s"} in ${Object.keys(config.repos).length} repos`);
3540
4134
  return incomplete.length ? { prs, incomplete } : { prs };
3541
4135
  } catch (err) {
3542
- run?.fail(err.message);
4136
+ run2?.fail(err.message);
3543
4137
  throw err;
3544
4138
  }
3545
4139
  }, PRS_TTL_MS);
@@ -3560,14 +4154,14 @@ function mountPanesRoutes(app, opts) {
3560
4154
  app.get("/api/jira", async (c) => {
3561
4155
  if (!jiraInFlight) {
3562
4156
  jiraInFlight = (async () => {
3563
- const run = opts.activity?.start("jira", "Fetching your Jira issues");
4157
+ const run2 = opts.activity?.start("jira", "Fetching your Jira issues");
3564
4158
  try {
3565
4159
  const r = await fetchJiraPane();
3566
- if (!r.available) run?.fail("Jira CLI (acli) not available or not logged in");
3567
- else run?.done(`${r.issues.length} issue${r.issues.length === 1 ? "" : "s"}`);
4160
+ if (!r.available) run2?.fail("Jira CLI (acli) not available or not logged in");
4161
+ else run2?.done(`${r.issues.length} issue${r.issues.length === 1 ? "" : "s"}`);
3568
4162
  return r;
3569
4163
  } catch (err) {
3570
- run?.fail(err.message);
4164
+ run2?.fail(err.message);
3571
4165
  throw err;
3572
4166
  } finally {
3573
4167
  jiraInFlight = null;
@@ -3629,7 +4223,7 @@ function mountPanesRoutes(app, opts) {
3629
4223
 
3630
4224
  // src/server/routes/worktree-routes.ts
3631
4225
  import fs8 from "fs";
3632
- import path7 from "path";
4226
+ import path9 from "path";
3633
4227
  import { spawn } from "child_process";
3634
4228
 
3635
4229
  // src/core/platform/started.ts
@@ -3815,7 +4409,7 @@ function mountWorktreeRoutes(app, opts) {
3815
4409
  const wantsFile = !!body && typeof body === "object" && "path" in body;
3816
4410
  const asked = wantsFile ? openFileSchema.safeParse(body) : null;
3817
4411
  if (asked && !asked.success) return c.json({ error: "repo and path required" }, 400);
3818
- const folder = session.isGroup ? path7.dirname(session.paths[0]) : session.paths[0];
4412
+ const folder = session.isGroup ? path9.dirname(session.paths[0]) : session.paths[0];
3819
4413
  let file;
3820
4414
  if (asked?.success) {
3821
4415
  const at = await codeFilePath(session, asked.data.repo, asked.data.path);
@@ -3884,7 +4478,7 @@ function mountWorktreeRoutes(app, opts) {
3884
4478
  import { zValidator as zValidator6 } from "@hono/zod-validator";
3885
4479
  import { z as z5 } from "zod";
3886
4480
  import { EventEmitter } from "events";
3887
- import path8 from "path";
4481
+ import path10 from "path";
3888
4482
  import { streamSSE } from "hono/streaming";
3889
4483
  function mountScopeRoutes(app, opts) {
3890
4484
  const background = /* @__PURE__ */ new Set();
@@ -4131,7 +4725,7 @@ function mountScopeRoutes(app, opts) {
4131
4725
  const fromSha = fromEntry.repos[p] ?? "HEAD";
4132
4726
  const toSha = toEntry === void 0 ? "working" : toEntry.repos[p] ?? "HEAD";
4133
4727
  return {
4134
- name: path8.basename(p),
4728
+ name: path10.basename(p),
4135
4729
  root: p,
4136
4730
  files: computeRangeDiff({ root: p, fromRef: fromSha, toRef: toSha })
4137
4731
  };
@@ -4148,7 +4742,7 @@ function mountScopeRoutes(app, opts) {
4148
4742
  }
4149
4743
  const resolved = scope.paths.map((p) => resolveRepoDiff(p, base, sessionBaseForPath(p)));
4150
4744
  const repos = scope.paths.map((p, i) => ({
4151
- name: path8.basename(p),
4745
+ name: path10.basename(p),
4152
4746
  root: p,
4153
4747
  resolvedBase: resolved[i].resolvedBase,
4154
4748
  files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
@@ -4179,7 +4773,7 @@ function mountScopeRoutes(app, opts) {
4179
4773
  if (!relPath || !Number.isInteger(start) || !Number.isInteger(end)) {
4180
4774
  return c.json({ error: "bad path/start/end" }, 400);
4181
4775
  }
4182
- const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) => path8.basename(p) === repoName);
4776
+ const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) => path10.basename(p) === repoName);
4183
4777
  if (!root) return c.json({ error: "unknown repo" }, 404);
4184
4778
  const result = readContextLines({ root, relPath, start, end, ref });
4185
4779
  if (!result) return c.json({ error: "cannot read file" }, 400);
@@ -4360,7 +4954,7 @@ function mountScopeRoutes(app, opts) {
4360
4954
  // src/core/pty/terminal-perf.ts
4361
4955
  var MAX_KEYS = 200;
4362
4956
  var MAX_STALLS = 100;
4363
- var num = (x) => typeof x === "number" && Number.isFinite(x) && x >= 0 && x < 1e13;
4957
+ var num2 = (x) => typeof x === "number" && Number.isFinite(x) && x >= 0 && x < 1e13;
4364
4958
  function cleanPerfReport(x) {
4365
4959
  if (!x || typeof x !== "object") return null;
4366
4960
  const r = x;
@@ -4371,13 +4965,13 @@ function cleanPerfReport(x) {
4371
4965
  const keys = [];
4372
4966
  for (const k of r.keys.slice(0, MAX_KEYS)) {
4373
4967
  const o = k;
4374
- if (!o || !num(o.arrived) || !(o.shown === null || num(o.shown))) return null;
4968
+ if (!o || !num2(o.arrived) || !(o.shown === null || num2(o.shown))) return null;
4375
4969
  keys.push({ arrived: Math.round(o.arrived), shown: o.shown === null ? null : Math.round(o.shown) });
4376
4970
  }
4377
4971
  const stalls = [];
4378
4972
  for (const s of r.stalls.slice(0, MAX_STALLS)) {
4379
4973
  const o = s;
4380
- if (!o || !num(o.at) || !num(o.ms) || !(o.blocking === null || num(o.blocking)) || typeof o.what !== "string") return null;
4974
+ if (!o || !num2(o.at) || !num2(o.ms) || !(o.blocking === null || num2(o.blocking)) || typeof o.what !== "string") return null;
4381
4975
  stalls.push({
4382
4976
  at: o.at,
4383
4977
  ms: Math.round(o.ms),
@@ -4437,7 +5031,7 @@ function mountTerminalRoutes(app, opts) {
4437
5031
  }
4438
5032
 
4439
5033
  // src/server/routes/status-routes.ts
4440
- import path9 from "path";
5034
+ import path11 from "path";
4441
5035
 
4442
5036
  // src/core/status/notifier.ts
4443
5037
  var MESSAGES = {
@@ -4585,7 +5179,7 @@ function mountStatusRoutes(app, opts) {
4585
5179
  const kind = notifyKindForTransition(status.prevState ? { state: status.prevState } : null, status);
4586
5180
  if (kind) {
4587
5181
  const config = loadConfig();
4588
- const launchDir = session.isGroup && session.paths[0] ? path9.dirname(session.paths[0]) : session.paths[0] ?? body.cwd;
5182
+ const launchDir = session.isGroup && session.paths[0] ? path11.dirname(session.paths[0]) : session.paths[0] ?? body.cwd;
4589
5183
  const name = `${session.target} \xB7 ${session.branch}`;
4590
5184
  const snooze = readSnooze(id);
4591
5185
  const route = snooze?.until && snoozeActive(snooze, { attention: status }) ? "none" : presence.route(id);
@@ -4907,16 +5501,16 @@ function createPrWatch(deps) {
4907
5501
  const me = ci.repos.find((r) => r.name === f.repo)?.viewer ?? ci.viewer;
4908
5502
  return !!me && me.toLowerCase() === author.toLowerCase();
4909
5503
  }
4910
- function check(id, session, act = true, run) {
5504
+ function check(id, session, act = true, run2) {
4911
5505
  const running2 = inflight.get(id);
4912
5506
  if (running2) return running2;
4913
- const p = checkNow(id, session, act, run).finally(() => inflight.delete(id));
5507
+ const p = checkNow(id, session, act, run2).finally(() => inflight.delete(id));
4914
5508
  inflight.set(id, p);
4915
5509
  return p;
4916
5510
  }
4917
- async function checkNow(id, session, act = true, run) {
5511
+ async function checkNow(id, session, act = true, run2) {
4918
5512
  const name = `${session.target} ${session.branch}`;
4919
- const note = (text, level = "info") => run?.note(`${name}: ${text}`, { level, sessionId: id });
5513
+ const note = (text, level = "info") => run2?.note(`${name}: ${text}`, { level, sessionId: id });
4920
5514
  let pre;
4921
5515
  try {
4922
5516
  pre = await deps.preflight(session, { resting });
@@ -5184,20 +5778,20 @@ function createPrWatch(deps) {
5184
5778
  if (!restingNames()) schedule?.resume();
5185
5779
  const queue = due;
5186
5780
  const ids = queue.map((q) => q.id);
5187
- const run = deps.activity?.start("pr-watch", "Checking pull requests");
5781
+ const run2 = deps.activity?.start("pr-watch", "Checking pull requests");
5188
5782
  let done = 0;
5189
- run?.progress(0, ids.length);
5783
+ run2?.progress(0, ids.length);
5190
5784
  const worker = async () => {
5191
5785
  for (let next = queue.shift(); next; next = queue.shift()) {
5192
- await check(next.id, next.session, !deps.lookOnly, run);
5193
- run?.progress(++done, ids.length);
5786
+ await check(next.id, next.session, !deps.lookOnly, run2);
5787
+ run2?.progress(++done, ids.length);
5194
5788
  }
5195
5789
  };
5196
5790
  try {
5197
5791
  await Promise.all(Array.from({ length: CONCURRENCY }, worker));
5198
- run?.done(sweepSummary(ids));
5792
+ run2?.done(sweepSummary(ids));
5199
5793
  } catch (err) {
5200
- run?.fail(err.message);
5794
+ run2?.fail(err.message);
5201
5795
  throw err;
5202
5796
  }
5203
5797
  })().finally(() => {
@@ -5258,7 +5852,7 @@ function repoServer(repoPath) {
5258
5852
  const { origin } = hostForRepo(repoPath);
5259
5853
  return origin ? originHostname(origin) : null;
5260
5854
  }
5261
- function viewerLogin(run, lookup = hostOf, serverOf = repoServer) {
5855
+ function viewerLogin(run2, lookup = hostOf, serverOf = repoServer) {
5262
5856
  const known = /* @__PURE__ */ new Map();
5263
5857
  return async (hostId, repoPath) => {
5264
5858
  const host = lookup(hostId);
@@ -5266,21 +5860,21 @@ function viewerLogin(run, lookup = hostOf, serverOf = repoServer) {
5266
5860
  ${repoPath ? serverOf(repoPath) ?? "" : ""}`;
5267
5861
  const was = known.get(key);
5268
5862
  if (was) return was;
5269
- const login = await host.viewer(run, repoPath ?? process.cwd()).catch(() => null);
5863
+ const login = await host.viewer(run2, repoPath ?? process.cwd()).catch(() => null);
5270
5864
  if (login) known.set(key, login);
5271
5865
  return login || null;
5272
5866
  };
5273
5867
  }
5274
- async function fetchReviewFeedback(repoPath, prNumber, run) {
5275
- return hostForRepo(repoPath).host.reviewFeedback(run, repoPath, prNumber);
5868
+ async function fetchReviewFeedback(repoPath, prNumber, run2) {
5869
+ return hostForRepo(repoPath).host.reviewFeedback(run2, repoPath, prNumber);
5276
5870
  }
5277
5871
  function hostRateLimited(hostId, text) {
5278
5872
  return hostOf(hostId).rateLimited(text);
5279
5873
  }
5280
- function prWatchHostDeps(run) {
5874
+ function prWatchHostDeps(run2) {
5281
5875
  return {
5282
- viewer: viewerLogin(run),
5283
- reviewFeedback: (repoPath, n) => fetchReviewFeedback(repoPath, n, run),
5876
+ viewer: viewerLogin(run2),
5877
+ reviewFeedback: (repoPath, n) => fetchReviewFeedback(repoPath, n, run2),
5284
5878
  rateLimited: hostRateLimited
5285
5879
  };
5286
5880
  }
@@ -5356,7 +5950,7 @@ function branchFactsOf(pre) {
5356
5950
  }))
5357
5951
  );
5358
5952
  }
5359
- function listedPrsIo(run, opts = {}) {
5953
+ function listedPrsIo(run2, opts = {}) {
5360
5954
  return {
5361
5955
  repoIdOf: (repoPath) => {
5362
5956
  const { host, origin } = hostForRepo(repoPath);
@@ -5366,19 +5960,19 @@ function listedPrsIo(run, opts = {}) {
5366
5960
  const h = hostOfPrUrl(url)?.host;
5367
5961
  return h ? h.id === DEFAULT_HOST ? void 0 : h.id : null;
5368
5962
  },
5369
- lookup: (cwd, host, ref) => hostOf(host).prForRef(run, cwd ?? os2.tmpdir(), ref),
5963
+ lookup: (cwd, host, ref) => hostOf(host).prForRef(run2, cwd ?? os2.tmpdir(), ref),
5370
5964
  ...opts
5371
5965
  };
5372
5966
  }
5373
- async function shipPreflightWithListed(session, run, io = {}) {
5374
- const pre = await (io.preflight ?? shipPreflight)(session, run);
5375
- return (await withListedPrs(pre, readSessionPrs(sessionIdFor(session)), io.listed ?? listedPrsIo(run))).pre;
5967
+ async function shipPreflightWithListed(session, run2, io = {}) {
5968
+ const pre = await (io.preflight ?? shipPreflight)(session, run2);
5969
+ return (await withListedPrs(pre, readSessionPrs(sessionIdFor(session)), io.listed ?? listedPrsIo(run2))).pre;
5376
5970
  }
5377
- async function watchPreflight(session, run, opts = {}, io = {}) {
5971
+ async function watchPreflight(session, run2, opts = {}, io = {}) {
5378
5972
  const id = sessionIdFor(session);
5379
5973
  const last = opts.last ?? null;
5380
5974
  const repoOf = (name) => last?.repos.find((x) => x.name === name);
5381
- const pre = await (io.preflight ?? shipPreflight)(session, run, {
5975
+ const pre = await (io.preflight ?? shipPreflight)(session, run2, {
5382
5976
  askGh: watchAskGh(opts.resting, (name) => !!repoOf(name)?.pr),
5383
5977
  ...watchBranchOptions(
5384
5978
  readSessionBranches(id),
@@ -5390,7 +5984,7 @@ async function watchPreflight(session, run, opts = {}, io = {}) {
5390
5984
  const facts = branchFactsOf(pre);
5391
5985
  if (facts.length) bestEffort(`keep the branch facts of ${id}`, () => noteBranchFacts(id, facts));
5392
5986
  const previous = (url) => last ? prsOfCheck(last).find((p) => p.pr.url.toLowerCase() === url.toLowerCase())?.pr : void 0;
5393
- const listed = io.listed ?? listedPrsIo(run, { ...opts.resting ? { resting: opts.resting } : {}, previous });
5987
+ const listed = io.listed ?? listedPrsIo(run2, { ...opts.resting ? { resting: opts.resting } : {}, previous });
5394
5988
  const found = await withListedPrs(pre, readSessionPrs(id), listed);
5395
5989
  const aliases = new Map(sessionRepos(session, loadConfig()).map((r) => [r.path, r.alias]));
5396
5990
  const keys = new Map(pre.repos.map((r) => [r.name, [aliases.get(r.path), listed.repoIdOf(r.path)]]));
@@ -5412,7 +6006,7 @@ function mountShipRoutes(app, opts) {
5412
6006
  let warnings = [];
5413
6007
  const keepOnRestore = !archived && archivedForMerge(id);
5414
6008
  if (archived) {
5415
- const out = await archiveSession(session, defaultArchiveDeps({ release: opts.release }), {
6009
+ const out = await archiveSession(session, defaultArchiveDeps({ release: opts.release, removeWorktree: opts.removeWorktree }), {
5416
6010
  force,
5417
6011
  merged,
5418
6012
  by: merged ? "shipped" : "you"
@@ -5502,7 +6096,7 @@ function mountShipRoutes(app, opts) {
5502
6096
  selection,
5503
6097
  body.method ?? "squash",
5504
6098
  opts.run,
5505
- (s, run) => shipPreflightWithListed(s, run)
6099
+ (s, run2) => shipPreflightWithListed(s, run2)
5506
6100
  );
5507
6101
  opts.onRepoChanged?.(id);
5508
6102
  let archived = false;
@@ -5615,13 +6209,13 @@ function mountRailRoutes(app, opts) {
5615
6209
 
5616
6210
  // src/core/worktree/shared-folders.ts
5617
6211
  import fs9 from "fs";
5618
- import path10 from "path";
5619
- var norm = (p) => path10.resolve(p).replace(/\\/g, "/").toLowerCase();
6212
+ import path12 from "path";
6213
+ var norm2 = (p) => path12.resolve(p).replace(/\\/g, "/").toLowerCase();
5620
6214
  function shadowedSessions(sessions, branchCheckedOut2) {
5621
6215
  const byFolder = /* @__PURE__ */ new Map();
5622
6216
  for (const s of sessions) {
5623
6217
  if (s.isGroup || s.paths.length !== 1) continue;
5624
- const key = norm(s.paths[0]);
6218
+ const key = norm2(s.paths[0]);
5625
6219
  byFolder.set(key, [...byFolder.get(key) ?? [], s]);
5626
6220
  }
5627
6221
  const shadowed = /* @__PURE__ */ new Set();
@@ -5635,14 +6229,14 @@ function shadowedSessions(sessions, branchCheckedOut2) {
5635
6229
  }
5636
6230
  function branchCheckedOut(dir) {
5637
6231
  try {
5638
- const dotGit = path10.join(dir, ".git");
6232
+ const dotGit = path12.join(dir, ".git");
5639
6233
  let gitDir = dotGit;
5640
6234
  if (fs9.statSync(dotGit).isFile()) {
5641
6235
  const m = /^gitdir:\s*(.+)$/m.exec(fs9.readFileSync(dotGit, "utf8"));
5642
6236
  if (!m) return null;
5643
- gitDir = path10.resolve(dir, m[1].trim());
6237
+ gitDir = path12.resolve(dir, m[1].trim());
5644
6238
  }
5645
- const head = fs9.readFileSync(path10.join(gitDir, "HEAD"), "utf8");
6239
+ const head = fs9.readFileSync(path12.join(gitDir, "HEAD"), "utf8");
5646
6240
  const ref = /^ref:\s*refs\/heads\/(.+)$/m.exec(head);
5647
6241
  return ref ? ref[1].trim() : null;
5648
6242
  } catch {
@@ -5736,13 +6330,13 @@ function mountCleanupRoutes(app, opts) {
5736
6330
  app.post("/api/cleanup/branches/scan", (c) => {
5737
6331
  if (!branches.scanning) {
5738
6332
  branches = { ...branches, scanning: true };
5739
- const run = opts.activity?.start("branches", "Looking for merged local branches");
6333
+ const run2 = opts.activity?.start("branches", "Looking for merged local branches");
5740
6334
  void findMergedBranches(branchDeps).then((candidates2) => {
5741
6335
  branches = { scanning: false, scannedAt: (/* @__PURE__ */ new Date()).toISOString(), candidates: candidates2 };
5742
- run?.done(`${candidates2.length} merged local branch${candidates2.length === 1 ? "" : "es"}`);
6336
+ run2?.done(`${candidates2.length} merged local branch${candidates2.length === 1 ? "" : "es"}`);
5743
6337
  }).catch((err) => {
5744
6338
  branches = { ...branches, scanning: false };
5745
- run?.fail(err.message);
6339
+ run2?.fail(err.message);
5746
6340
  });
5747
6341
  }
5748
6342
  return c.json(branches);
@@ -5753,10 +6347,10 @@ function mountCleanupRoutes(app, opts) {
5753
6347
  (i) => !!i && typeof i.repo === "string" && typeof i.branch === "string"
5754
6348
  ).map((i) => ({ repo: i.repo, branch: i.branch, ...typeof i.tip === "string" ? { tip: i.tip } : {} })) : [];
5755
6349
  if (items.length === 0) return c.json({ error: "items: [{repo, branch, tip?}]" }, 400);
5756
- const run = opts.activity?.start("branches", "Deleting merged local branches");
6350
+ const run2 = opts.activity?.start("branches", "Deleting merged local branches");
5757
6351
  const results = await deleteMergedBranches(items, branchDeps);
5758
- for (const r of results) run?.note(`${r.repo} ${r.branch}: ${r.message}`, { level: r.ok ? "action" : "warn" });
5759
- run?.done(`${results.filter((r) => r.ok).length} of ${results.length} deleted`);
6352
+ for (const r of results) run2?.note(`${r.repo} ${r.branch}: ${r.message}`, { level: r.ok ? "action" : "warn" });
6353
+ run2?.done(`${results.filter((r) => r.ok).length} of ${results.length} deleted`);
5760
6354
  const gone = new Set(results.filter((r) => r.ok).map((r) => `${r.repo}\0${r.branch}`));
5761
6355
  branches = { ...branches, candidates: branches.candidates.filter((b) => !gone.has(`${b.repo}\0${b.branch}`)) };
5762
6356
  return c.json({ results, state: branches });
@@ -5806,14 +6400,14 @@ function createActivityLog(opts = {}) {
5806
6400
  let recent = [];
5807
6401
  const lastOk = /* @__PURE__ */ new Map();
5808
6402
  const schedules = /* @__PURE__ */ new Map();
5809
- const finish = (run) => {
5810
- running.delete(run.id);
5811
- recent = [run, ...recent].slice(0, keep);
6403
+ const finish = (run2) => {
6404
+ running.delete(run2.id);
6405
+ recent = [run2, ...recent].slice(0, keep);
5812
6406
  changed();
5813
6407
  };
5814
6408
  return {
5815
6409
  start(kind, label) {
5816
- const run = {
6410
+ const run2 = {
5817
6411
  id: nextId++,
5818
6412
  kind,
5819
6413
  label,
@@ -5824,31 +6418,31 @@ function createActivityLog(opts = {}) {
5824
6418
  summary: null,
5825
6419
  notes: []
5826
6420
  };
5827
- running.set(run.id, run);
6421
+ running.set(run2.id, run2);
5828
6422
  changed();
5829
- const open = () => run.status === "running";
6423
+ const open = () => run2.status === "running";
5830
6424
  return {
5831
6425
  progress(done, total) {
5832
6426
  if (!open()) return;
5833
- run.progress = { done, total };
6427
+ run2.progress = { done, total };
5834
6428
  changed();
5835
6429
  },
5836
6430
  note(text, o = {}) {
5837
6431
  if (!open()) return;
5838
6432
  const n = { at: iso(), text, level: o.level ?? "info", ...o.sessionId ? { sessionId: o.sessionId } : {} };
5839
- run.notes = [...run.notes, n].slice(-KEEP_NOTES);
6433
+ run2.notes = [...run2.notes, n].slice(-KEEP_NOTES);
5840
6434
  changed();
5841
6435
  },
5842
6436
  done(summary) {
5843
6437
  if (!open()) return;
5844
- Object.assign(run, { status: "done", endedAt: iso(), summary });
5845
- lastOk.set(run.kind, run.endedAt);
5846
- finish(run);
6438
+ Object.assign(run2, { status: "done", endedAt: iso(), summary });
6439
+ lastOk.set(run2.kind, run2.endedAt);
6440
+ finish(run2);
5847
6441
  },
5848
6442
  fail(error) {
5849
6443
  if (!open()) return;
5850
- Object.assign(run, { status: "failed", endedAt: iso(), summary: error });
5851
- finish(run);
6444
+ Object.assign(run2, { status: "failed", endedAt: iso(), summary: error });
6445
+ finish(run2);
5852
6446
  }
5853
6447
  };
5854
6448
  },
@@ -5904,7 +6498,7 @@ function threadsWithoutDraft(open, replies) {
5904
6498
  return open.filter((t) => !drafted.has(t.threadId));
5905
6499
  }
5906
6500
  function mountPrReplyRoutes(app, opts) {
5907
- const run = opts.run ?? defaultRunner;
6501
+ const run2 = opts.run ?? defaultRunner;
5908
6502
  const changed = (sessionId) => {
5909
6503
  if (opts.watch) markPostedAnswered(sessionId, opts.watch);
5910
6504
  opts.broadcast("replies-changed", { sessionId });
@@ -5926,7 +6520,7 @@ function mountPrReplyRoutes(app, opts) {
5926
6520
  if (typeof b.body !== "string") return c.json({ error: "body: string" }, 400);
5927
6521
  const r = await draftReply(id, c.req.param("thread"), b.body, {
5928
6522
  repos: () => sessionRepoRefs(session),
5929
- run
6523
+ run: run2
5930
6524
  });
5931
6525
  if (!r.ok) return c.json({ error: r.error }, 400);
5932
6526
  changed(id);
@@ -5949,7 +6543,7 @@ function mountPrReplyRoutes(app, opts) {
5949
6543
  return c.json({ error: "body: the reply text" }, 400);
5950
6544
  const thread = c.req.param("thread");
5951
6545
  const cwd = replyFolder(session, listReplies(id).find((r2) => r2.threadId === thread)?.repo);
5952
- const r = await postReply(id, thread, b.body, { resolve: b.resolve === true, cwd, run });
6546
+ const r = await postReply(id, thread, b.body, { resolve: b.resolve === true, cwd, run: run2 });
5953
6547
  if (!r.ok) return c.json({ error: r.error }, 502);
5954
6548
  const act = opts.activity?.start("pr-watch", "Posting a review reply");
5955
6549
  act?.note(`${session.target} ${session.branch}: posted your reply${r.resolved ? " and resolved the thread" : ""}`, {
@@ -5970,7 +6564,7 @@ function mountPrReplyRoutes(app, opts) {
5970
6564
 
5971
6565
  // src/core/archive/archive-retention.ts
5972
6566
  import fs11 from "fs";
5973
- import path11 from "path";
6567
+ import path13 from "path";
5974
6568
  import zlib from "zlib";
5975
6569
  var DEFAULT_COMPRESS_AFTER_DAYS = 30;
5976
6570
  var DAY_MS = 24 * 36e5;
@@ -5991,14 +6585,14 @@ function applyArchiveRetention(opts) {
5991
6585
  if (!rec) continue;
5992
6586
  const age = now - Date.parse(rec.archivedAt);
5993
6587
  if (!Number.isFinite(age)) continue;
5994
- const ignored = path11.join(archiveDirFor(id, root), "ignored");
6588
+ const ignored = path13.join(archiveDirFor(id, root), "ignored");
5995
6589
  if (compressAfter > 0 && age >= compressAfter * DAY_MS && !rec.ignoredDroppedAt && fs11.existsSync(ignored)) {
5996
6590
  fs11.rmSync(ignored, { recursive: true, force: true });
5997
6591
  rec.ignoredDroppedAt = new Date(now).toISOString();
5998
6592
  writeArchiveRecord(rec, root);
5999
6593
  }
6000
6594
  if (rec.transcriptsDroppedAt) continue;
6001
- const dir = path11.join(archiveDirFor(id, root), "transcripts");
6595
+ const dir = path13.join(archiveDirFor(id, root), "transcripts");
6002
6596
  if (dropAfter > 0 && age >= dropAfter * DAY_MS) {
6003
6597
  out.bytesSaved += dirBytes(dir);
6004
6598
  fs11.rmSync(dir, { recursive: true, force: true });
@@ -6009,7 +6603,7 @@ function applyArchiveRetention(opts) {
6009
6603
  }
6010
6604
  if (compressAfter <= 0 || rec.compressedAt || age < compressAfter * DAY_MS) continue;
6011
6605
  for (const t of rec.transcripts) {
6012
- const plain = path11.join(dir, t.file);
6606
+ const plain = path13.join(dir, t.file);
6013
6607
  if (!fs11.existsSync(plain)) continue;
6014
6608
  const data = fs11.readFileSync(plain);
6015
6609
  const gz = zlib.gzipSync(data);
@@ -6030,7 +6624,7 @@ function applyArchiveRetention(opts) {
6030
6624
  function dirBytes(dir) {
6031
6625
  let n = 0;
6032
6626
  try {
6033
- for (const f of fs11.readdirSync(dir)) n += fs11.statSync(path11.join(dir, f)).size;
6627
+ for (const f of fs11.readdirSync(dir)) n += fs11.statSync(path13.join(dir, f)).size;
6034
6628
  } catch {
6035
6629
  }
6036
6630
  return n;
@@ -6054,7 +6648,7 @@ function createTimeKeeper(deps, opts) {
6054
6648
  if (d === today) return true;
6055
6649
  return needsBuild(d, builtAt.get(d));
6056
6650
  });
6057
- const run2 = opts.activity?.start("time", days.length === 1 ? "Updating today" : `Building ${days.length} days`);
6651
+ const run3 = opts.activity?.start("time", days.length === 1 ? "Updating today" : `Building ${days.length} days`);
6058
6652
  const failed = [];
6059
6653
  let built = 0;
6060
6654
  for (const d of days) {
@@ -6066,11 +6660,11 @@ function createTimeKeeper(deps, opts) {
6066
6660
  }
6067
6661
  }
6068
6662
  if (built) opts.changed();
6069
- if (failed.length) run2?.fail(`${failed.length} of ${days.length} not built \u2014 ${failed.join("; ")}`);
6070
- else run2?.done(days.length === 1 ? "today updated" : `${days.length} days built`);
6663
+ if (failed.length) run3?.fail(`${failed.length} of ${days.length} not built \u2014 ${failed.join("; ")}`);
6664
+ else run3?.done(days.length === 1 ? "today updated" : `${days.length} days built`);
6071
6665
  }
6072
6666
  let again = null;
6073
- const run = (what = "all") => {
6667
+ const run2 = (what = "all") => {
6074
6668
  if (busy) {
6075
6669
  again = again === "all" || what === "all" ? "all" : "local";
6076
6670
  return busy;
@@ -6092,12 +6686,12 @@ function createTimeKeeper(deps, opts) {
6092
6686
  return busy;
6093
6687
  };
6094
6688
  return {
6095
- run,
6689
+ run: run2,
6096
6690
  soon: () => {
6097
6691
  if (timer) return;
6098
6692
  timer = setTimeout(() => {
6099
6693
  timer = null;
6100
- void run("local");
6694
+ void run2("local");
6101
6695
  }, AFTER_TURN_MS);
6102
6696
  timer.unref?.();
6103
6697
  },
@@ -6336,14 +6930,14 @@ function settleLeftOverClaims(deps) {
6336
6930
  function tidyLeftOverSubmits(deps, activity, changed) {
6337
6931
  const done = settleLeftOverClaims(deps);
6338
6932
  if (!done.length) return;
6339
- const run = activity?.start("reviews", "Submits left mid-way");
6933
+ const run2 = activity?.start("reviews", "Submits left mid-way");
6340
6934
  for (const r of done) {
6341
- run?.note(`${r.repo} #${r.number}: work stopped while submitting your review \u2014 look at the PR and say whether it went`, {
6935
+ run2?.note(`${r.repo} #${r.number}: work stopped while submitting your review \u2014 look at the PR and say whether it went`, {
6342
6936
  level: "warn"
6343
6937
  });
6344
6938
  changed(r);
6345
6939
  }
6346
- run?.done(`${done.length} submit${done.length === 1 ? "" : "s"} in doubt`);
6940
+ run2?.done(`${done.length} submit${done.length === 1 ? "" : "s"} in doubt`);
6347
6941
  }
6348
6942
 
6349
6943
  // src/core/review/review-fix.ts
@@ -6422,10 +7016,10 @@ async function fixItMyself(deps, repo, number, input) {
6422
7016
  const no = claimRefused;
6423
7017
  if (no) return { ok: false, ...no };
6424
7018
  const release = () => deps.update(repo, number, (cur) => cur.fixing?.at === claimAt ? withoutFixClaim(cur) : cur);
6425
- const run = deps.activity?.start("reviews", `Fix it myself: ${repo} #${number}`);
7019
+ const run2 = deps.activity?.start("reviews", `Fix it myself: ${repo} #${number}`);
6426
7020
  const fail = (status, error, sessionId) => {
6427
7021
  release();
6428
- run?.fail(error);
7022
+ run2?.fail(error);
6429
7023
  return { ok: false, status, error, ...sessionId ? { sessionId } : {} };
6430
7024
  };
6431
7025
  try {
@@ -6486,13 +7080,13 @@ async function fixItMyself(deps, repo, number, input) {
6486
7080
  `${plural(left.length, "comment")} stayed on the review (posted, or a submit took ${left.length === 1 ? "it" : "them"} meanwhile): the session has ${left.length === 1 ? "it" : "them"} too`
6487
7081
  );
6488
7082
  const said = `${plural(moved, "comment")} on #${number} being fixed in ${label}${created ? " (new session)" : ""}`;
6489
- run?.note(said, { level: "action", sessionId });
6490
- for (const w of warnings) run?.note(`${label}: ${w}`, { level: "warn", sessionId });
6491
- run?.done(said);
7083
+ run2?.note(said, { level: "action", sessionId });
7084
+ for (const w of warnings) run2?.note(`${label}: ${w}`, { level: "warn", sessionId });
7085
+ run2?.done(said);
6492
7086
  return { ok: true, sessionId, created, review: next ?? claimed, ...warnings.length ? { warnings } : {} };
6493
7087
  } catch (err) {
6494
7088
  release();
6495
- run?.fail(err.message);
7089
+ run2?.fail(err.message);
6496
7090
  throw err;
6497
7091
  }
6498
7092
  }
@@ -6508,7 +7102,7 @@ function reviewModeOf(alias, config) {
6508
7102
  return { mode: "all", from: "default" };
6509
7103
  }
6510
7104
  function reviewProjects(config) {
6511
- return Object.entries(config.repos).map(([alias, path20]) => ({ alias, path: path20, mode: reviewModeOf(alias, config).mode }));
7105
+ return Object.entries(config.repos).map(([alias, path22]) => ({ alias, path: path22, mode: reviewModeOf(alias, config).mode }));
6512
7106
  }
6513
7107
  function reviewLimits(config) {
6514
7108
  return {
@@ -6519,7 +7113,7 @@ function reviewLimits(config) {
6519
7113
  var isReviewMode = (v) => v === "all" || v === "asked" || v === "off";
6520
7114
 
6521
7115
  // src/server/routes/review-routes.ts
6522
- var num2 = (s) => /^\d+$/.test(s) ? Number(s) : null;
7116
+ var num3 = (s) => /^\d+$/.test(s) ? Number(s) : null;
6523
7117
  function mountReviewRoutes(app, deps) {
6524
7118
  const changed = (repo, number) => deps.broadcast("reviews-changed", { repo, number });
6525
7119
  app.get("/api/reviews", (c) => {
@@ -6540,13 +7134,13 @@ function mountReviewRoutes(app, deps) {
6540
7134
  return c.json(deps.settings());
6541
7135
  });
6542
7136
  app.get("/api/reviews/:repo/:number", (c) => {
6543
- const n = num2(c.req.param("number"));
7137
+ const n = num3(c.req.param("number"));
6544
7138
  const r = n === null ? null : deps.read(c.req.param("repo"), n);
6545
7139
  return r ? c.json(shownReview(deps, r)) : c.json({ error: "no review of that PR" }, 404);
6546
7140
  });
6547
7141
  app.get("/api/reviews/:repo/:number/diff", async (c) => {
6548
7142
  const repo = c.req.param("repo");
6549
- const n = num2(c.req.param("number"));
7143
+ const n = num3(c.req.param("number"));
6550
7144
  const r = n === null ? null : deps.read(repo, n);
6551
7145
  const at = deps.repoPath(repo);
6552
7146
  if (!r || n === null || !r.mergeBase || !at) return c.json({ error: "no prepared review of that PR" }, 404);
@@ -6555,7 +7149,7 @@ function mountReviewRoutes(app, deps) {
6555
7149
  });
6556
7150
  app.post("/api/reviews/:repo/:number", async (c) => {
6557
7151
  const repo = c.req.param("repo");
6558
- const n = num2(c.req.param("number"));
7152
+ const n = num3(c.req.param("number"));
6559
7153
  if (n === null) return c.json({ error: "not a PR number" }, 400);
6560
7154
  const r = await deps.runNow(repo, n);
6561
7155
  changed(repo, n);
@@ -6563,7 +7157,7 @@ function mountReviewRoutes(app, deps) {
6563
7157
  });
6564
7158
  app.post("/api/reviews/:repo/:number/discussion", async (c) => {
6565
7159
  const repo = c.req.param("repo");
6566
- const n = num2(c.req.param("number"));
7160
+ const n = num3(c.req.param("number"));
6567
7161
  if (n === null || !deps.read(repo, n)) return c.json({ error: "no review of that PR" }, 404);
6568
7162
  const was = deps.read(repo, n)?.discussion?.at;
6569
7163
  const r = await deps.refreshDiscussion(repo, n);
@@ -6573,7 +7167,7 @@ function mountReviewRoutes(app, deps) {
6573
7167
  });
6574
7168
  app.post("/api/reviews/:repo/:number/drafts", async (c) => {
6575
7169
  const repo = c.req.param("repo");
6576
- const n = num2(c.req.param("number"));
7170
+ const n = num3(c.req.param("number"));
6577
7171
  if (n === null || !deps.read(repo, n)) return c.json({ error: "no review of that PR" }, 404);
6578
7172
  const body = await c.req.json().catch(() => null);
6579
7173
  let error = null;
@@ -6591,7 +7185,7 @@ function mountReviewRoutes(app, deps) {
6591
7185
  });
6592
7186
  app.post("/api/reviews/:repo/:number/submit", async (c) => {
6593
7187
  const repo = c.req.param("repo");
6594
- const n = num2(c.req.param("number"));
7188
+ const n = num3(c.req.param("number"));
6595
7189
  if (n === null) return c.json({ error: "no review of that PR" }, 404);
6596
7190
  const input = await c.req.json().catch(() => null);
6597
7191
  const out = await submitPrReview(deps, repo, n, input);
@@ -6601,7 +7195,7 @@ function mountReviewRoutes(app, deps) {
6601
7195
  });
6602
7196
  app.post("/api/reviews/:repo/:number/fix-myself", async (c) => {
6603
7197
  const repo = c.req.param("repo");
6604
- const n = num2(c.req.param("number"));
7198
+ const n = num3(c.req.param("number"));
6605
7199
  if (n === null || !deps.read(repo, n)) return c.json({ error: "no review of that PR" }, 404);
6606
7200
  if (!deps.fixMyself) return c.json({ error: "not available on this server" }, 501);
6607
7201
  const input = await c.req.json().catch(() => null);
@@ -6614,7 +7208,7 @@ function mountReviewRoutes(app, deps) {
6614
7208
  });
6615
7209
  app.post("/api/reviews/:repo/:number/in-doubt", async (c) => {
6616
7210
  const repo = c.req.param("repo");
6617
- const n = num2(c.req.param("number"));
7211
+ const n = num3(c.req.param("number"));
6618
7212
  if (n === null || !deps.read(repo, n)) return c.json({ error: "no review of that PR" }, 404);
6619
7213
  const body = await c.req.json().catch(() => null);
6620
7214
  if (!body || typeof body.went !== "boolean") return c.json({ error: "expected {went: true|false}" }, 400);
@@ -6625,7 +7219,7 @@ function mountReviewRoutes(app, deps) {
6625
7219
  });
6626
7220
  app.delete("/api/reviews/:repo/:number/dropped", (c) => {
6627
7221
  const repo = c.req.param("repo");
6628
- const n = num2(c.req.param("number"));
7222
+ const n = num3(c.req.param("number"));
6629
7223
  const next = n === null ? null : deps.update(repo, n, clearDropped);
6630
7224
  if (!next || n === null) return c.json({ error: "no review of that PR" }, 404);
6631
7225
  changed(repo, n);
@@ -6633,7 +7227,7 @@ function mountReviewRoutes(app, deps) {
6633
7227
  });
6634
7228
  app.delete("/api/reviews/:repo/:number/drafts/:id", (c) => {
6635
7229
  const repo = c.req.param("repo");
6636
- const n = num2(c.req.param("number"));
7230
+ const n = num3(c.req.param("number"));
6637
7231
  if (n === null || !deps.read(repo, n)) return c.json({ error: "no review of that PR" }, 404);
6638
7232
  const id = c.req.param("id");
6639
7233
  let refused = null;
@@ -6656,41 +7250,41 @@ function mountReviewRoutes(app, deps) {
6656
7250
  // src/core/review/review-tree.ts
6657
7251
  import { randomBytes } from "crypto";
6658
7252
  import fs12 from "fs";
6659
- import path12 from "path";
7253
+ import path14 from "path";
6660
7254
 
6661
7255
  // src/core/review/review-source.ts
6662
7256
  var reviewRef = (number) => `refs/work/review/${number}`;
6663
7257
  var ATTR_CHUNK = 200;
6664
- var git2 = (run, cwd, ...args) => run("git", args, cwd);
6665
- async function preparePr(run, repoPath, host, pr) {
7258
+ var git2 = (run2, cwd, ...args) => run2("git", args, cwd);
7259
+ async function preparePr(run2, repoPath, host, pr) {
6666
7260
  const ref = reviewRef(pr.number);
6667
- const head = await git2(run, repoPath, "fetch", "--quiet", "--no-tags", "origin", `+${host.prRef(pr.number)}:${ref}`);
7261
+ const head = await git2(run2, repoPath, "fetch", "--quiet", "--no-tags", "origin", `+${host.prRef(pr.number)}:${ref}`);
6668
7262
  if (head.code !== 0)
6669
7263
  return { ok: false, error: `couldn't fetch the PR's code: ${head.stderr.trim().split("\n")[0] || "git fetch failed"}` };
6670
7264
  if (host.prRefIsMerge) {
6671
- const second = await git2(run, repoPath, "rev-parse", "--verify", "--quiet", `${ref}^2`);
7265
+ const second = await git2(run2, repoPath, "rev-parse", "--verify", "--quiet", `${ref}^2`);
6672
7266
  const tip = second.stdout.trim();
6673
7267
  if (second.code !== 0 || !tip) return { ok: false, error: "the PR's merge ref has no second parent: can't tell its head" };
6674
- const moved = await git2(run, repoPath, "update-ref", ref, tip);
7268
+ const moved = await git2(run2, repoPath, "update-ref", ref, tip);
6675
7269
  if (moved.code !== 0) return { ok: false, error: `couldn't keep the PR's head: ${moved.stderr.trim().split(/\r?\n/)[0]}` };
6676
7270
  }
6677
- if (pr.base) await git2(run, repoPath, "fetch", "--quiet", "--no-tags", "origin", `+refs/heads/${pr.base}:refs/remotes/origin/${pr.base}`);
6678
- const sha = (await git2(run, repoPath, "rev-parse", ref)).stdout.trim();
7271
+ if (pr.base) await git2(run2, repoPath, "fetch", "--quiet", "--no-tags", "origin", `+refs/heads/${pr.base}:refs/remotes/origin/${pr.base}`);
7272
+ const sha = (await git2(run2, repoPath, "rev-parse", ref)).stdout.trim();
6679
7273
  const baseRef = pr.base ? `refs/remotes/origin/${pr.base}` : "origin/HEAD";
6680
- const mb = await git2(run, repoPath, "merge-base", baseRef, ref);
7274
+ const mb = await git2(run2, repoPath, "merge-base", baseRef, ref);
6681
7275
  if (mb.code !== 0 || !mb.stdout.trim()) return { ok: false, error: `no common commit with ${pr.base || "the default branch"}` };
6682
7276
  const mergeBase = mb.stdout.trim();
6683
- const files = await reviewDiff(run, repoPath, mergeBase, ref);
7277
+ const files = await reviewDiff(run2, repoPath, mergeBase, ref);
6684
7278
  if (!files) return { ok: false, error: "git couldn't diff the PR" };
6685
- return { ok: true, files, extras: await diffExtras(run, repoPath, mergeBase, ref, files), mergeBase, headSha: sha };
7279
+ return { ok: true, files, extras: await diffExtras(run2, repoPath, mergeBase, ref, files), mergeBase, headSha: sha };
6686
7280
  }
6687
- async function reviewDiff(run, repoPath, from, to) {
6688
- const d = await git2(run, repoPath, "diff", "--no-color", "--no-ext-diff", "-M", from, to);
7281
+ async function reviewDiff(run2, repoPath, from, to) {
7282
+ const d = await git2(run2, repoPath, "diff", "--no-color", "--no-ext-diff", "-M", from, to);
6689
7283
  return d.code === 0 ? parseGitDiff(d.stdout) : null;
6690
7284
  }
6691
- async function diffExtras(run, repoPath, from, to, files) {
7285
+ async function diffExtras(run2, repoPath, from, to, files) {
6692
7286
  const changed = files.filter((f) => f.added + f.deleted > 0).map((f) => f.path);
6693
- const w = await git2(run, repoPath, "diff", "--no-color", "--no-ext-diff", "-M", "-w", "--name-only", from, to);
7287
+ const w = await git2(run2, repoPath, "diff", "--no-color", "--no-ext-diff", "-M", "-w", "--name-only", from, to);
6694
7288
  const real = new Set(
6695
7289
  w.code === 0 ? w.stdout.split("\n").map((l) => l.trim()).filter(Boolean) : changed
6696
7290
  );
@@ -6698,7 +7292,7 @@ async function diffExtras(run, repoPath, from, to, files) {
6698
7292
  const generated = /* @__PURE__ */ new Set();
6699
7293
  const paths = files.map((f) => f.path);
6700
7294
  for (let i = 0; i < paths.length; i += ATTR_CHUNK) {
6701
- const attr = await git2(run, repoPath, "check-attr", `--source=${to}`, "linguist-generated", "--", ...paths.slice(i, i + ATTR_CHUNK));
7295
+ const attr = await git2(run2, repoPath, "check-attr", `--source=${to}`, "linguist-generated", "--", ...paths.slice(i, i + ATTR_CHUNK));
6702
7296
  if (attr.code !== 0) break;
6703
7297
  for (const line of attr.stdout.split("\n")) {
6704
7298
  const m = /^(.*): linguist-generated: (set|true)$/.exec(line.trim());
@@ -6707,18 +7301,18 @@ async function diffExtras(run, repoPath, from, to, files) {
6707
7301
  }
6708
7302
  return { whitespaceOnly, generated };
6709
7303
  }
6710
- async function dropReviewRef(run, repoPath, number) {
6711
- await git2(run, repoPath, "update-ref", "-d", reviewRef(number));
7304
+ async function dropReviewRef(run2, repoPath, number) {
7305
+ await git2(run2, repoPath, "update-ref", "-d", reviewRef(number));
6712
7306
  }
6713
7307
 
6714
7308
  // src/core/review/review-tree.ts
6715
- var reviewTreesDir = () => path12.join(getConfigDir(), "review-trees");
7309
+ var reviewTreesDir = () => path14.join(getConfigDir(), "review-trees");
6716
7310
  var NO_HOOKS = ".no-hooks";
6717
7311
  var NO_LFS = ["-c", "filter.lfs.smudge=", "-c", "filter.lfs.process=", "-c", "filter.lfs.required=false"];
6718
7312
  var NO_LFS_ENV = { GIT_LFS_SKIP_SMUDGE: "1" };
6719
- function reviewTreeName(alias, number, headSha, run) {
7313
+ function reviewTreeName(alias, number, headSha, run2) {
6720
7314
  const safe = alias.replace(/[^A-Za-z0-9._-]/g, "_").replace(/^\.+/, "_") || "repo";
6721
- const tag = run.replace(/[^A-Za-z0-9]/g, "");
7315
+ const tag = run2.replace(/[^A-Za-z0-9]/g, "");
6722
7316
  return `${safe}-${number}-${headSha.slice(0, 8)}${tag ? `-${tag}` : ""}`;
6723
7317
  }
6724
7318
  var runSuffix = () => `${process.pid.toString(36)}${randomBytes(3).toString("hex")}`;
@@ -6730,13 +7324,13 @@ function rmTree(dir) {
6730
7324
  }
6731
7325
  return !fs12.existsSync(dir);
6732
7326
  }
6733
- async function createReviewTree(run, at, opts) {
7327
+ async function createReviewTree(run2, at, opts) {
6734
7328
  const root = opts.root ?? reviewTreesDir();
6735
- const dir = path12.join(root, reviewTreeName(at.alias, at.number, at.headSha, opts.run ?? runSuffix()));
6736
- const noHooks = path12.join(root, NO_HOOKS);
7329
+ const dir = path14.join(root, reviewTreeName(at.alias, at.number, at.headSha, opts.run ?? runSuffix()));
7330
+ const noHooks = path14.join(root, NO_HOOKS);
6737
7331
  fs12.mkdirSync(noHooks, { recursive: true });
6738
- if (fs12.existsSync(dir)) await removeReviewTree(run, at.repoPath, dir);
6739
- const added = await run(
7332
+ if (fs12.existsSync(dir)) await removeReviewTree(run2, at.repoPath, dir);
7333
+ const added = await run2(
6740
7334
  "git",
6741
7335
  [
6742
7336
  "-c",
@@ -6755,58 +7349,58 @@ async function createReviewTree(run, at, opts) {
6755
7349
  NO_LFS_ENV
6756
7350
  );
6757
7351
  if (added.code !== 0) {
6758
- await removeReviewTree(run, at.repoPath, dir);
7352
+ await removeReviewTree(run2, at.repoPath, dir);
6759
7353
  return { ok: false, error: `couldn't check the PR out: ${firstLine(added.stderr) || "git worktree add failed"}` };
6760
7354
  }
6761
- const head = await run("git", ["rev-parse", "HEAD"], dir);
7355
+ const head = await run2("git", ["rev-parse", "HEAD"], dir);
6762
7356
  if (head.code !== 0 || head.stdout.trim() !== at.headSha) {
6763
- await removeReviewTree(run, at.repoPath, dir);
7357
+ await removeReviewTree(run2, at.repoPath, dir);
6764
7358
  return { ok: false, error: "the checkout isn't at the reviewed commit (the PR moved meanwhile)" };
6765
7359
  }
6766
- const listed = await run("git", ["ls-files", "-z"], dir);
7360
+ const listed = await run2("git", ["ls-files", "-z"], dir);
6767
7361
  if (listed.code !== 0) {
6768
- await removeReviewTree(run, at.repoPath, dir);
7362
+ await removeReviewTree(run2, at.repoPath, dir);
6769
7363
  return { ok: false, error: "couldn't list the checkout's files to remove its settings" };
6770
7364
  }
6771
7365
  const removed = [];
6772
7366
  for (const rel of listed.stdout.split("\0").filter((rel2) => opts.strip(rel2))) {
6773
- const file = path12.join(dir, rel);
7367
+ const file = path14.join(dir, rel);
6774
7368
  fs12.rmSync(file, { recursive: true, force: true });
6775
7369
  if (fs12.existsSync(file)) {
6776
- await removeReviewTree(run, at.repoPath, dir);
7370
+ await removeReviewTree(run2, at.repoPath, dir);
6777
7371
  return { ok: false, error: `couldn't remove ${rel} from the checkout` };
6778
7372
  }
6779
7373
  removed.push(rel);
6780
7374
  }
6781
7375
  return { ok: true, dir, removed };
6782
7376
  }
6783
- async function removeReviewTree(run, repoPath, dir) {
6784
- if (fs12.existsSync(dir)) await run("git", ["worktree", "remove", "--force", "--force", dir], repoPath);
7377
+ async function removeReviewTree(run2, repoPath, dir) {
7378
+ if (fs12.existsSync(dir)) await run2("git", ["worktree", "remove", "--force", "--force", dir], repoPath);
6785
7379
  const gone = rmTree(dir);
6786
- await run("git", ["worktree", "prune"], repoPath);
7380
+ await run2("git", ["worktree", "prune"], repoPath);
6787
7381
  return gone;
6788
7382
  }
6789
- async function withReviewTree(run, at, use, opts) {
6790
- const tree = await createReviewTree(run, at, opts);
7383
+ async function withReviewTree(run2, at, use, opts) {
7384
+ const tree = await createReviewTree(run2, at, opts);
6791
7385
  if (!tree.ok) return tree;
6792
7386
  let value;
6793
7387
  let gone;
6794
7388
  try {
6795
7389
  value = await use(tree.dir, tree.removed);
6796
7390
  } finally {
6797
- gone = await removeReviewTree(run, at.repoPath, tree.dir).catch(() => false);
7391
+ gone = await removeReviewTree(run2, at.repoPath, tree.dir).catch(() => false);
6798
7392
  }
6799
7393
  return { ok: true, value, ...gone ? {} : { left: tree.dir } };
6800
7394
  }
6801
7395
  function gitDirOf(dir) {
6802
7396
  try {
6803
- const m = /^gitdir:\s*(.+)$/m.exec(fs12.readFileSync(path12.join(dir, ".git"), "utf8"));
6804
- return m ? path12.resolve(dir, m[1].trim(), "..", "..") : null;
7397
+ const m = /^gitdir:\s*(.+)$/m.exec(fs12.readFileSync(path14.join(dir, ".git"), "utf8"));
7398
+ return m ? path14.resolve(dir, m[1].trim(), "..", "..") : null;
6805
7399
  } catch {
6806
7400
  return null;
6807
7401
  }
6808
7402
  }
6809
- async function sweepReviewTrees(run, opts = {}) {
7403
+ async function sweepReviewTrees(run2, opts = {}) {
6810
7404
  const root = opts.root ?? reviewTreesDir();
6811
7405
  const now = opts.now?.() ?? Date.now();
6812
7406
  const swept = [];
@@ -6818,14 +7412,14 @@ async function sweepReviewTrees(run, opts = {}) {
6818
7412
  return { swept, failed };
6819
7413
  }
6820
7414
  for (const name of names) {
6821
- const dir = path12.join(root, name);
7415
+ const dir = path14.join(root, name);
6822
7416
  try {
6823
7417
  if (opts.olderThanMs && now - fs12.statSync(dir).mtimeMs < opts.olderThanMs) continue;
6824
7418
  } catch {
6825
7419
  continue;
6826
7420
  }
6827
7421
  const gitDir = gitDirOf(dir);
6828
- const gone = gitDir && fs12.existsSync(gitDir) ? await removeReviewTree(run, gitDir, dir) : rmTree(dir);
7422
+ const gone = gitDir && fs12.existsSync(gitDir) ? await removeReviewTree(run2, gitDir, dir) : rmTree(dir);
6829
7423
  (gone ? swept : failed).push(name);
6830
7424
  }
6831
7425
  return { swept, failed };
@@ -7023,8 +7617,8 @@ function createReviewQueue(deps) {
7023
7617
  }
7024
7618
  }
7025
7619
  async function sweepNow() {
7026
- const run = deps.activity?.start("reviews", "Preparing PR reviews");
7027
- const note = (text, level = "info") => run?.note(text, { level });
7620
+ const run2 = deps.activity?.start("reviews", "Preparing PR reviews");
7621
+ const note = (text, level = "info") => run2?.note(text, { level });
7028
7622
  const { maxPerDay } = deps.limits();
7029
7623
  const asked = [];
7030
7624
  const open = /* @__PURE__ */ new Set();
@@ -7113,9 +7707,9 @@ function createReviewQueue(deps) {
7113
7707
  note(`${talk.length - DISCUSSIONS_PER_SWEEP} more discussions to read again: the next sweep`);
7114
7708
  if (read) note(`read the discussion of ${plural2(read, "PR")} again (moved on the host, or half an hour old)`);
7115
7709
  deps.changed();
7116
- run?.done(todo.length ? `${plural2(todo.length, "PR")} looked at` : read ? `${plural2(read, "discussion")} read again` : "nothing new");
7710
+ run2?.done(todo.length ? `${plural2(todo.length, "PR")} looked at` : read ? `${plural2(read, "discussion")} read again` : "nothing new");
7117
7711
  } catch (err) {
7118
- run?.fail(err.message);
7712
+ run2?.fail(err.message);
7119
7713
  }
7120
7714
  }
7121
7715
  return {
@@ -7133,11 +7727,11 @@ function createReviewQueue(deps) {
7133
7727
  if (!list.ok) return { ok: false, error: list.error };
7134
7728
  const pr = list.prs.find((p) => p.number === number);
7135
7729
  if (!pr) return { ok: false, error: `#${number} isn't an open pull request of ${repo}` };
7136
- const run = deps.activity?.start("reviews", `Preparing the review of ${repo} #${number}`);
7137
- const note = (text, level = "info") => run?.note(text, { level });
7730
+ const run2 = deps.activity?.start("reviews", `Preparing the review of ${repo} #${number}`);
7731
+ const note = (text, level = "info") => run2?.note(text, { level });
7138
7732
  const r = await oneAtATime2(() => prepareOne(project, metaOf(repo, host, pr), pr, false, note));
7139
- if (r.ok) run?.done(`prepared${r.how ? `; ${r.how}` : ""}`);
7140
- else run?.fail(r.error);
7733
+ if (r.ok) run2?.done(`prepared${r.how ? `; ${r.how}` : ""}`);
7734
+ else run2?.fail(r.error);
7141
7735
  return r.ok ? { ok: true, review: r.review } : { ok: false, error: r.error };
7142
7736
  },
7143
7737
  async refreshDiscussion(repo, number) {
@@ -7299,7 +7893,7 @@ function startReviewSweeps(opts) {
7299
7893
  }
7300
7894
 
7301
7895
  // src/core/diff/session-history.ts
7302
- import path13 from "path";
7896
+ import path15 from "path";
7303
7897
 
7304
7898
  // src/core/diff/diff-points.ts
7305
7899
  var SHA = /^[0-9a-f]{7,40}$/;
@@ -7395,12 +7989,12 @@ async function sessionHistory(session, others = []) {
7395
7989
  });
7396
7990
  if (diffArg === "HEAD") continue;
7397
7991
  const log = await g(["log", `-n${MAX_COMMITS2}`, "--format=%H%x1f%cI%x1f%s", `${diffArg}..HEAD`, "--"], root);
7398
- if (log.ok && log.out) commits.push(...parseLog(log.out, path13.basename(root)));
7992
+ if (log.ok && log.out) commits.push(...parseLog(log.out, path15.basename(root)));
7399
7993
  }
7400
7994
  for (const b of others) {
7401
7995
  const tip = await tipOf(b);
7402
7996
  if (!tip) continue;
7403
- const repo = path13.basename(b.path);
7997
+ const repo = path15.basename(b.path);
7404
7998
  const start = liveStart(b) ?? b.start;
7405
7999
  let list = [];
7406
8000
  let base;
@@ -7461,7 +8055,7 @@ function parseLog(stdout, repo) {
7461
8055
  return out;
7462
8056
  }
7463
8057
  function computeSessionRange(session, from, to) {
7464
- const paths = session.paths.map((p) => path13.resolve(p));
8058
+ const paths = session.paths.map((p) => path15.resolve(p));
7465
8059
  const refs = rangeRefs(paths, loadManifest(scopeHashForPaths(paths)).entries, from, to);
7466
8060
  if ("error" in refs) return refs;
7467
8061
  return { repos: refs.map((r) => ({ name: r.name, root: r.root, files: computeRangeDiff(r) })) };
@@ -7480,17 +8074,17 @@ async function sessionHistoryWire(session) {
7480
8074
  }
7481
8075
 
7482
8076
  // src/server/routes/revert-routes.ts
7483
- import path15 from "path";
8077
+ import path17 from "path";
7484
8078
  import { zValidator as zValidator7 } from "@hono/zod-validator";
7485
8079
  import { z as z6 } from "zod";
7486
8080
 
7487
8081
  // src/core/diff/revert.ts
7488
8082
  import fs14 from "fs";
7489
- import path14 from "path";
8083
+ import path16 from "path";
7490
8084
  function inside(root, rel) {
7491
- const abs = path14.resolve(root, rel);
7492
- const back = path14.relative(path14.resolve(root), abs);
7493
- if (!back || back.startsWith("..") || path14.isAbsolute(back)) return null;
8085
+ const abs = path16.resolve(root, rel);
8086
+ const back = path16.relative(path16.resolve(root), abs);
8087
+ if (!back || back.startsWith("..") || path16.isAbsolute(back)) return null;
7494
8088
  return abs;
7495
8089
  }
7496
8090
  function inHead(root, rel) {
@@ -7603,8 +8197,8 @@ function mountRevertRoutes(app, opts) {
7603
8197
  if (!session) return c.json({ error: "unknown session" }, 404);
7604
8198
  const body = c.req.valid("json");
7605
8199
  const repo = opts.uncommitted(session).find((r) => r.name === body.repo);
7606
- const allowed = new Set(session.paths.map((p) => path15.resolve(p).toLowerCase()));
7607
- if (!repo || !allowed.has(path15.resolve(repo.root).toLowerCase())) {
8200
+ const allowed = new Set(session.paths.map((p) => path17.resolve(p).toLowerCase()));
8201
+ if (!repo || !allowed.has(path17.resolve(repo.root).toLowerCase())) {
7608
8202
  return c.json({ error: `unknown repo: ${body.repo}` }, 404);
7609
8203
  }
7610
8204
  const file = repo.files.find((f) => f.path === body.path);
@@ -7762,10 +8356,10 @@ function mountCiRoutes(app, opts) {
7762
8356
 
7763
8357
  // src/core/diff/diffs-sweep.ts
7764
8358
  import fs16 from "fs";
7765
- import path16 from "path";
8359
+ import path18 from "path";
7766
8360
  var SWEEP_AFTER_DAYS = 30;
7767
8361
  var DISPOSABLE = /\.(html|log)$/i;
7768
- function sweepOldDiffArtifacts(now = Date.now(), maxAgeDays = SWEEP_AFTER_DAYS, dir = path16.join(getConfigDir(), "diffs")) {
8362
+ function sweepOldDiffArtifacts(now = Date.now(), maxAgeDays = SWEEP_AFTER_DAYS, dir = path18.join(getConfigDir(), "diffs")) {
7769
8363
  const cutoff = now - maxAgeDays * 24 * 60 * 60 * 1e3;
7770
8364
  let removed = 0;
7771
8365
  let bytes = 0;
@@ -7777,7 +8371,7 @@ function sweepOldDiffArtifacts(now = Date.now(), maxAgeDays = SWEEP_AFTER_DAYS,
7777
8371
  }
7778
8372
  for (const name of names) {
7779
8373
  if (!DISPOSABLE.test(name)) continue;
7780
- const file = path16.join(dir, name);
8374
+ const file = path18.join(dir, name);
7781
8375
  try {
7782
8376
  const st = fs16.statSync(file);
7783
8377
  if (!st.isFile() || st.mtimeMs >= cutoff) continue;
@@ -7991,6 +8585,39 @@ function mountAgentRestartRoutes(app, opts) {
7991
8585
  // src/server/routes/account-routes.ts
7992
8586
  import { zValidator as zValidator8 } from "@hono/zod-validator";
7993
8587
  import { z as z7 } from "zod";
8588
+
8589
+ // src/core/sessions/account-switch-all.ts
8590
+ function sessionsToSwitch(sessions, accountOf, to, from) {
8591
+ return sessions.filter((s) => !s.archivedAt && accountOf(s) !== to && (from === void 0 || accountOf(s) === from));
8592
+ }
8593
+ async function switchAllSessions(deps, to, from) {
8594
+ const rows = [];
8595
+ for (const s of sessionsToSwitch(deps.sessions(), deps.accountOf, to, from)) {
8596
+ const id = deps.idOf(s);
8597
+ const label = `${s.target} \xB7 ${s.branch}`;
8598
+ const r = await deps.switchAccount(id, to).catch((err) => ({
8599
+ ok: false,
8600
+ status: 502,
8601
+ error: err instanceof Error ? err.message : String(err)
8602
+ }));
8603
+ rows.push(r.ok ? { id, label, outcome: r.outcome } : { id, label, error: r.error });
8604
+ }
8605
+ return rows;
8606
+ }
8607
+ function switchAllSummary(rows, to) {
8608
+ if (rows.length === 0) return `No session to move: every one is on ${to} already.`;
8609
+ const n = (o) => rows.filter((r) => r.outcome === o).length;
8610
+ const moved = rows.filter((r) => r.outcome).length;
8611
+ const refused = rows.length - moved;
8612
+ const parts = [
8613
+ n("switched") ? `${n("switched")} restarted on it` : "",
8614
+ n("queued") ? `${n("queued")} when its turn ends` : "",
8615
+ n("recorded") ? `${n("recorded")} on its next start` : ""
8616
+ ].filter(Boolean);
8617
+ return `${moved} session${moved === 1 ? "" : "s"} moved to ${to}${parts.length ? `: ${parts.join(", ")}` : ""}` + (refused ? `; ${refused} refused` : "");
8618
+ }
8619
+
8620
+ // src/server/routes/account-routes.ts
7994
8621
  function mountAccountRoutes(app, opts) {
7995
8622
  const accountsNow = opts.accounts ?? (() => agentFor(loadConfig()).accounts);
7996
8623
  const readings = opts.readings ?? (() => agentFor(loadConfig()).usage?.read() ?? []);
@@ -8095,6 +8722,26 @@ function mountAccountRoutes(app, opts) {
8095
8722
  return c.json({ error: e instanceof Error ? e.message : String(e) }, 502);
8096
8723
  }
8097
8724
  });
8725
+ app.post("/api/accounts/:name/sessions", zValidator8("json", z7.object({ from: z7.string().min(1).max(64).optional() })), async (c) => {
8726
+ if (opts.lookOnly) return c.json({ error: opts.lookOnly }, 409);
8727
+ const to = c.req.param("name");
8728
+ const { from } = c.req.valid("json");
8729
+ const rows = await switchAllSessions(
8730
+ {
8731
+ sessions,
8732
+ accountOf: (s) => s.account ?? DEFAULT_ACCOUNT,
8733
+ idOf: sessionIdFor,
8734
+ switchAccount: (id, name) => opts.switcher.switchAccount(id, name)
8735
+ },
8736
+ to,
8737
+ from
8738
+ );
8739
+ if (rows.length > 0 && rows.every((r) => r.error) && new Set(rows.map((r) => r.error)).size === 1)
8740
+ return c.json({ error: rows[0].error ?? "" }, 409);
8741
+ opts.broadcast("sessions-changed", { ts: Date.now() });
8742
+ changed();
8743
+ return c.json({ ok: true, summary: switchAllSummary(rows, to), sessions: rows });
8744
+ });
8098
8745
  app.post("/api/sessions/:id/account", zValidator8("json", z7.object({ to: z7.string().min(1).max(64) })), async (c) => {
8099
8746
  if (opts.lookOnly) return c.json({ error: opts.lookOnly }, 409);
8100
8747
  const r = await opts.switcher.switchAccount(c.req.param("id"), c.req.valid("json").to).catch((err) => ({
@@ -8118,9 +8765,9 @@ function mountAccountRoutes(app, opts) {
8118
8765
 
8119
8766
  // src/core/sessions/account-skills-child.ts
8120
8767
  var lastLine = (text) => text.split("\n").map((l) => l.trim()).filter(Boolean).pop() ?? "";
8121
- function accountSkillsInChild(workBin, run = runWorkChild) {
8768
+ function accountSkillsInChild(workBin, run2 = runWorkChild) {
8122
8769
  return async (name) => {
8123
- const r = await run(workBin(), ["account", "skills", name], { timeoutMs: 5 * 6e4 });
8770
+ const r = await run2(workBin(), ["account", "skills", name], { timeoutMs: 5 * 6e4 });
8124
8771
  if (r.spawnError) return { ok: false, message: `couldn't start work: ${r.spawnError}` };
8125
8772
  if (r.timedOut) return { ok: false, message: "installing work\u2019s skills took too long" };
8126
8773
  const said = lastLine(r.stdout) || lastLine(r.stderr);
@@ -8280,10 +8927,11 @@ function sleepChecks() {
8280
8927
  }
8281
8928
 
8282
8929
  // src/server/web-server.ts
8930
+ var LEFTOVERS_EVERY_MS = 60 * 6e4;
8283
8931
  function computeSessionDiff(s, base) {
8284
8932
  const resolved = s.paths.map((p) => resolveRepoDiff(p, base, s.baseBranches?.[p] ?? s.baseBranch));
8285
8933
  const repos = s.paths.map((p, i) => ({
8286
- name: path17.basename(p),
8934
+ name: path19.basename(p),
8287
8935
  root: p,
8288
8936
  resolvedBase: resolved[i].resolvedBase,
8289
8937
  files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
@@ -8387,7 +9035,7 @@ async function startWebServer(opts = {}) {
8387
9035
  }, 500);
8388
9036
  }
8389
9037
  });
8390
- const repoNames = (s) => s.isGroup ? s.paths.map((p) => path17.basename(p)) : [s.target];
9038
+ const repoNames = (s) => s.isGroup ? s.paths.map((p) => path19.basename(p)) : [s.target];
8391
9039
  const diffStatFor = (id, s, hasStatus) => wantsDiffStat(s, hasStatus) ? diffStats.get(id, s.paths, repoNames(s)) : null;
8392
9040
  const archivedRow = createArchivedRows();
8393
9041
  app.get("/api/sessions", (c) => {
@@ -8532,7 +9180,11 @@ async function startWebServer(opts = {}) {
8532
9180
  },
8533
9181
  activity,
8534
9182
  // The PR merged: nothing waiting in it holds it up — the archive keeps it.
8535
- archive: (id) => archiveMergedSession(id, defaultArchiveDeps({ release: releaseSession }), () => broadcast("sessions-changed", { ts: Date.now() }))
9183
+ archive: (id) => archiveMergedSession(
9184
+ id,
9185
+ defaultArchiveDeps({ release: releaseSession, removeWorktree: removeWorktreeInChild(getWorkBin) }),
9186
+ () => broadcast("sessions-changed", { ts: Date.now() })
9187
+ )
8536
9188
  });
8537
9189
  const stopPrWatch = lean ? null : prWatch.start(dev ? 10 * 6e4 : 18e4);
8538
9190
  const SLEEP_EVERY_MS = 5 * 6e4;
@@ -8555,12 +9207,12 @@ async function startWebServer(opts = {}) {
8555
9207
  busy: restartBusy,
8556
9208
  running: peekPty,
8557
9209
  report: (notes) => {
8558
- const run = activity.start("agents", "Restarting agents");
9210
+ const run2 = activity.start("agents", "Restarting agents");
8559
9211
  for (const { id, text, level } of notes) {
8560
9212
  const s = findSession2(id);
8561
- run.note(`${s ? `${s.target} ${s.branch}` : id}: ${text}`, { level, sessionId: s ? id : void 0 });
9213
+ run2.note(`${s ? `${s.target} ${s.branch}` : id}: ${text}`, { level, sessionId: s ? id : void 0 });
8562
9214
  }
8563
- run.done(restartNotesSummary(notes));
9215
+ run2.done(restartNotesSummary(notes));
8564
9216
  },
8565
9217
  changed: () => {
8566
9218
  broadcast("agents-changed", { ts: Date.now() });
@@ -8600,7 +9252,7 @@ async function startWebServer(opts = {}) {
8600
9252
  const minutes = loadConfig()?.sleepIdleAfterMinutes ?? DEFAULT_SLEEP_AFTER_MINUTES;
8601
9253
  if (sleepAfterMs(minutes) === 0)
8602
9254
  return activity.skip("idle-sleep", "Looking for idle Claudes", "turned off (sleepIdleAfterMinutes: 0)");
8603
- const run = activity.start("idle-sleep", "Looking for idle Claudes");
9255
+ const run2 = activity.start("idle-sleep", "Looking for idle Claudes");
8604
9256
  const ptys = await listHostPtys().catch(() => []);
8605
9257
  const quiet = new Set(sleepCandidates(ptys, Date.now(), sleepAfterMs(minutes), agentBusy));
8606
9258
  const plan = await sleepPlan(
@@ -8609,7 +9261,7 @@ async function startWebServer(opts = {}) {
8609
9261
  );
8610
9262
  for (const { id, why } of plan.awake) {
8611
9263
  const s = findSession2(id);
8612
- run.note(`${s ? `${s.target} ${s.branch}` : id}: kept awake: ${why}`, { sessionId: s ? id : void 0 });
9264
+ run2.note(`${s ? `${s.target} ${s.branch}` : id}: kept awake: ${why}`, { sessionId: s ? id : void 0 });
8613
9265
  }
8614
9266
  const ids = plan.sleep;
8615
9267
  for (const id of ids) {
@@ -8619,16 +9271,16 @@ async function startWebServer(opts = {}) {
8619
9271
  async () => {
8620
9272
  await markAgentStopped(id).catch(() => {
8621
9273
  });
8622
- run.note(
9274
+ run2.note(
8623
9275
  `${s ? `${s.target} ${s.branch}` : id}: put its Claude to sleep (printed nothing for ${sleepAfterMs(minutes) / 6e4} min, nothing attached; opening it resumes the conversation)`,
8624
9276
  { level: "action", sessionId: id }
8625
9277
  );
8626
9278
  },
8627
- (err) => run.note(`${id}: couldn't stop its Claude: ${err.message}`, { level: "warn", sessionId: id })
9279
+ (err) => run2.note(`${id}: couldn't stop its Claude: ${err.message}`, { level: "warn", sessionId: id })
8628
9280
  );
8629
9281
  }
8630
9282
  const slept = ids.length;
8631
- run.done(`${ptys.length} Claude${ptys.length === 1 ? "" : "s"} running \xB7 ${slept ? `${slept} put to sleep` : "none idle long enough"}`);
9283
+ run2.done(`${ptys.length} Claude${ptys.length === 1 ? "" : "s"} running \xB7 ${slept ? `${slept} put to sleep` : "none idle long enough"}`);
8632
9284
  if (ids.length) broadcast("sessions-changed", { ts: Date.now() });
8633
9285
  };
8634
9286
  sleepSchedule?.next(Date.now() + SLEEP_EVERY_MS);
@@ -8667,15 +9319,15 @@ async function startWebServer(opts = {}) {
8667
9319
  const archiveUpkeep = () => {
8668
9320
  retentionSchedule?.next(Date.now() + RETENTION_EVERY_MS);
8669
9321
  const cfg = loadConfig()?.archive;
8670
- const run = activity.start("archive", "Compressing old archived conversations");
9322
+ const run2 = activity.start("archive", "Compressing old archived conversations");
8671
9323
  try {
8672
9324
  const r = applyArchiveRetention({ compressAfterDays: cfg?.compressAfterDays, dropAfterDays: cfg?.dropTranscriptsAfterDays });
8673
9325
  const mb = Math.round(r.bytesSaved / 1e6);
8674
- run.done(
9326
+ run2.done(
8675
9327
  r.compressed.length || r.dropped.length ? `${r.compressed.length} compressed${r.dropped.length ? `, ${r.dropped.length} conversations deleted (config)` : ""} \xB7 ${mb} MB freed` : "nothing old enough"
8676
9328
  );
8677
9329
  } catch (err) {
8678
- run.fail(err.message);
9330
+ run2.fail(err.message);
8679
9331
  }
8680
9332
  };
8681
9333
  const retentionFirst = !jobs ? null : setTimeout(archiveUpkeep, 3 * 6e4);
@@ -8691,18 +9343,18 @@ async function startWebServer(opts = {}) {
8691
9343
  conversationsSchedule?.next(Date.now() + CONVERSATIONS_EVERY_MS);
8692
9344
  if (conversationsBusy) return;
8693
9345
  conversationsBusy = true;
8694
- const run = activity.start("conversations", "Copying new conversation lines");
9346
+ const run2 = activity.start("conversations", "Copying new conversation lines");
8695
9347
  try {
8696
9348
  const r = await syncConversations(loadHistory().filter((s) => !s.archivedAt));
8697
9349
  const packed = await compressQuietCopies();
8698
- run.done(
9350
+ run2.done(
8699
9351
  [
8700
9352
  r.files ? `${r.sessions} session${r.sessions === 1 ? "" : "s"} \xB7 ${r.files} transcript${r.files === 1 ? "" : "s"} \xB7 ${Math.round(r.bytes / 1e3)} KB copied` : "all up to date",
8701
9353
  packed.files ? `${packed.files} quiet one${packed.files === 1 ? "" : "s"} compressed \xB7 ${Math.round(packed.bytesSaved / 1e6)} MB freed` : ""
8702
9354
  ].filter(Boolean).join(" \xB7 ")
8703
9355
  );
8704
9356
  } catch (err) {
8705
- run.fail(err.message);
9357
+ run2.fail(err.message);
8706
9358
  } finally {
8707
9359
  conversationsBusy = false;
8708
9360
  }
@@ -8768,7 +9420,7 @@ async function startWebServer(opts = {}) {
8768
9420
  blocksSchedule?.next(Date.now() + BLOCKS_EVERY_MS);
8769
9421
  if (blocksBusy || allBlocks().size === 0) return;
8770
9422
  blocksBusy = true;
8771
- const run = activity.start("blocks", "Checking what sessions wait on");
9423
+ const run2 = activity.start("blocks", "Checking what sessions wait on");
8772
9424
  try {
8773
9425
  const history = loadHistory();
8774
9426
  const live = new Set(history.filter((x) => !x.archivedAt).map((x) => sessionIdFor(x)));
@@ -8780,7 +9432,7 @@ async function startWebServer(opts = {}) {
8780
9432
  const r = await blockedPrState(url, defaultRunner);
8781
9433
  if (r && "rateLimited" in r) {
8782
9434
  ghRestUntil = Date.now() + 10 * 6e4;
8783
- run.note(`${r.host} API limit reached: resting 10 minutes`, { level: "warn" });
9435
+ run2.note(`${r.host} API limit reached: resting 10 minutes`, { level: "warn" });
8784
9436
  return null;
8785
9437
  }
8786
9438
  return r?.state ?? null;
@@ -8788,7 +9440,7 @@ async function startWebServer(opts = {}) {
8788
9440
  unblocked: async (id, done) => {
8789
9441
  const s = history.find((x) => sessionIdFor(x) === id);
8790
9442
  const name = s ? `${s.target} \xB7 ${s.branch}` : id;
8791
- run.note(`${name}: no longer waiting (${done.map((b) => b.label).join(", ")})`, { sessionId: id });
9443
+ run2.note(`${name}: no longer waiting (${done.map((b) => b.label).join(", ")})`, { sessionId: id });
8792
9444
  const event = {
8793
9445
  sessionId: id,
8794
9446
  kind: "unblocked",
@@ -8800,14 +9452,40 @@ async function startWebServer(opts = {}) {
8800
9452
  if (s) await stackDeps.tell(s, unblockedPrompt(done)).catch((err) => logSwallowed(`telling ${name} it is unblocked`, err));
8801
9453
  }
8802
9454
  });
8803
- run.done(freed.length ? `${freed.length} unblocked` : "still waiting");
9455
+ run2.done(freed.length ? `${freed.length} unblocked` : "still waiting");
8804
9456
  if (freed.length) broadcast("sessions-changed", { ts: Date.now() });
8805
9457
  } catch (err) {
8806
- run.fail(err.message);
9458
+ run2.fail(err.message);
8807
9459
  } finally {
8808
9460
  blocksBusy = false;
8809
9461
  }
8810
9462
  };
9463
+ const leftoversSchedule = !jobs ? null : activity.schedule("processes", "Processes left running", LEFTOVERS_EVERY_MS);
9464
+ let leftoversBusy = false;
9465
+ const sweepLeftoversNow = async () => {
9466
+ leftoversSchedule?.next(Date.now() + LEFTOVERS_EVERY_MS);
9467
+ if (leftoversBusy) return;
9468
+ leftoversBusy = true;
9469
+ const run2 = activity.start("processes", "Looking for processes left running");
9470
+ try {
9471
+ const found = await sweepLeftovers({
9472
+ sessions: () => loadHistory().filter((x) => !x.archivedAt).map((x) => ({ id: sessionIdFor(x), name: `${x.target} \xB7 ${x.branch}`, paths: x.paths })),
9473
+ list: () => listProcessUsage(),
9474
+ agentPid: ptyPid,
9475
+ note: (text, o) => run2.note(text, o)
9476
+ });
9477
+ if (found) run2.done(leftoverSummary(found));
9478
+ else run2.fail(leftoverSummary(found));
9479
+ } catch (err) {
9480
+ run2.fail(err.message);
9481
+ } finally {
9482
+ leftoversBusy = false;
9483
+ }
9484
+ };
9485
+ const leftoversFirst = !jobs ? null : setTimeout(() => void sweepLeftoversNow(), 10 * 6e4);
9486
+ leftoversFirst?.unref?.();
9487
+ const leftoversTimer = !jobs ? null : setInterval(() => void sweepLeftoversNow(), LEFTOVERS_EVERY_MS);
9488
+ leftoversTimer?.unref?.();
8811
9489
  const blocksTimer = !jobs ? null : setInterval(() => void sweepBlocksNow(), BLOCKS_EVERY_MS);
8812
9490
  blocksTimer?.unref?.();
8813
9491
  const offArchived = lean ? () => {
@@ -8884,7 +9562,13 @@ async function startWebServer(opts = {}) {
8884
9562
  const s = findSession2(id);
8885
9563
  if (s) scopeApi?.releaseSessionScope(s.paths, false);
8886
9564
  };
8887
- mountShipRoutes(app, { broadcast, onRepoChanged: (id) => diffStats.invalidate(id), release: releaseSession, create: makeWorktree });
9565
+ mountShipRoutes(app, {
9566
+ broadcast,
9567
+ onRepoChanged: (id) => diffStats.invalidate(id),
9568
+ release: releaseSession,
9569
+ create: makeWorktree,
9570
+ removeWorktree: removeWorktreeInChild(getWorkBin)
9571
+ });
8888
9572
  mountSessionRepoRoutes(app, {
8889
9573
  broadcast,
8890
9574
  run: addRepoInChild(getWorkBin),
@@ -8902,6 +9586,24 @@ async function startWebServer(opts = {}) {
8902
9586
  mountSessionOrderRoutes(app, { broadcast });
8903
9587
  mountRailRoutes(app, { broadcast });
8904
9588
  mountNoteRoutes(app, { broadcast });
9589
+ mountSessionReviewRoutes(app, {
9590
+ prepare: (session, repo) => prepareLocalReview(session, repo, {
9591
+ diff: (s) => computeSessionDiff(s, "branch"),
9592
+ agent: (prompt) => runInternal(prompt, 24e4, { lane: "localReviews" }),
9593
+ // Read-only in the session's own folder when the agent can: it then answers what the diff leaves open.
9594
+ inTree: (s, names) => localTreeRun(s.paths, names, {
9595
+ readOnly: internalReadOnly,
9596
+ run: (prompt, cwd, deny) => runInternalReadOnly(prompt, cwd, LOCAL_TREE_TIMEOUT_MS, { lane: "localReviews", deny }),
9597
+ exists: (dir) => fs17.existsSync(dir)
9598
+ }),
9599
+ rules: () => rulesWith(loadConfig()?.reviews?.rules)
9600
+ }),
9601
+ signature: (s, repo) => localSignature(computeSessionDiff(s, "branch"), repo ?? void 0),
9602
+ store: { read: readLocalReview, save: saveLocalReview, drop: dropLocalReview },
9603
+ tell: noteThroughComments(app),
9604
+ broadcast
9605
+ });
9606
+ mountSessionProcessRoutes(app, { list: () => listProcessUsage(), agentPid: ptyPid, kill: killTreeAsync });
8905
9607
  mountCodeRoutes(app);
8906
9608
  mountDiffSeenRoutes(app);
8907
9609
  mountDiffPageRoutes(app, { ensureScope: sessionScope });
@@ -8987,6 +9689,8 @@ async function startWebServer(opts = {}) {
8987
9689
  offArchived();
8988
9690
  offArchiving();
8989
9691
  if (blocksTimer) clearInterval(blocksTimer);
9692
+ if (leftoversTimer) clearInterval(leftoversTimer);
9693
+ if (leftoversFirst) clearTimeout(leftoversFirst);
8990
9694
  if (hostTick) clearInterval(hostTick);
8991
9695
  loop.stop();
8992
9696
  jiraWatch.stop();
@@ -9059,10 +9763,10 @@ function startAccountSync(deps) {
9059
9763
 
9060
9764
  // src/core/platform/autostart.ts
9061
9765
  import fs18 from "fs";
9062
- import path18 from "path";
9766
+ import path20 from "path";
9063
9767
  function startupScriptPath() {
9064
9768
  if (process.platform !== "win32" || !process.env.APPDATA) return null;
9065
- return path18.join(process.env.APPDATA, "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "work-web.vbs");
9769
+ return path20.join(process.env.APPDATA, "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "work-web.vbs");
9066
9770
  }
9067
9771
  function vbsQuote(s) {
9068
9772
  return '"' + s.replace(/"/g, '""') + '"';
@@ -9080,7 +9784,7 @@ function setAutostart(enabled, workBin) {
9080
9784
  const file = startupScriptPath();
9081
9785
  if (!file) throw new Error("Autostart is only supported on Windows so far.");
9082
9786
  if (enabled) {
9083
- fs18.mkdirSync(path18.dirname(file), { recursive: true });
9787
+ fs18.mkdirSync(path20.dirname(file), { recursive: true });
9084
9788
  fs18.writeFileSync(file, buildStartupScript(process.execPath, workBin), "utf-8");
9085
9789
  } else {
9086
9790
  try {
@@ -9091,31 +9795,506 @@ function setAutostart(enabled, workBin) {
9091
9795
  return file;
9092
9796
  }
9093
9797
 
9094
- // src/server/demo/demo-server.ts
9095
- import { Hono as Hono2 } from "hono";
9096
- import { streamSSE as streamSSE3 } from "hono/streaming";
9097
- import { WebSocketServer as WebSocketServer2 } from "ws";
9098
-
9099
- // src/server/demo/demo-repos.ts
9100
- var DemoRepoError = class extends Error {
9101
- constructor(message, sessions = []) {
9102
- super(message);
9103
- this.sessions = sessions;
9104
- }
9105
- };
9106
- function createDemoRepos(liveTargets) {
9107
- const root = "~/repos";
9108
- const repos = {
9109
- api: `${root}/api`,
9110
- web: `${root}/web`,
9111
- backend: `${root}/shop-backend`,
9112
- frontend: `${root}/shop-frontend`,
9113
- // On Azure DevOps (#65): its PRs come through the az adapter in the real dashboard.
9114
- payments: `${root}/payments`
9115
- };
9116
- const groups = { shop: ["backend", "frontend"] };
9117
- const ignored = /* @__PURE__ */ new Set();
9118
- const found = [
9798
+ // src/server/demo/demo-reviews.ts
9799
+ async function demoHostSubmit(url, review) {
9800
+ if (review.body.includes("#timeout"))
9801
+ return {
9802
+ ok: false,
9803
+ error: "the host timed out (demo)",
9804
+ inDoubt: { comments: review.comments.map((_, i) => i), summary: !!review.body.trim() }
9805
+ };
9806
+ return { ok: true, url: `${url}#pullrequestreview-1` };
9807
+ }
9808
+ var hunk = (path22, lines, status = "modified") => {
9809
+ const added = lines.filter((l) => l.startsWith("+")).length;
9810
+ const deleted = lines.filter((l) => l.startsWith("-")).length;
9811
+ const context = lines.length - added - deleted;
9812
+ return [
9813
+ `diff --git a/${path22} b/${path22}`,
9814
+ ...status === "added" ? ["new file mode 100644", "index 0000000..1111111", "--- /dev/null"] : ["index 1111111..2222222 100644", `--- a/${path22}`],
9815
+ `+++ b/${path22}`,
9816
+ `@@ -${status === "added" ? 0 : 1},${status === "added" ? 0 : context + deleted} +1,${context + added} @@`,
9817
+ ...lines
9818
+ ].join("\n");
9819
+ };
9820
+ var DIFF = [
9821
+ hunk(
9822
+ "src/Shop.Api/Controllers/RefundsController.cs",
9823
+ [
9824
+ "+using System;",
9825
+ "+using Microsoft.AspNetCore.Mvc;",
9826
+ "+using Shop.Orders.Refunds;",
9827
+ "+",
9828
+ "+[ApiController]",
9829
+ '+[Route("orders/{orderId}/refunds")]',
9830
+ "+public class RefundsController(IRefundHandler refunds) : ControllerBase",
9831
+ "+{",
9832
+ "+ [HttpPost]",
9833
+ "+ public async Task<IActionResult> Create(Guid orderId, RefundRequest request)",
9834
+ "+ => Ok(await refunds.Handle(orderId, request));",
9835
+ "+}"
9836
+ ],
9837
+ "added"
9838
+ ),
9839
+ hunk(
9840
+ "src/Shop.Orders/Refunds/RefundHandler.cs",
9841
+ [
9842
+ "+public class RefundHandler(ShopDb db, IPayments payments) : IRefundHandler",
9843
+ "+{",
9844
+ "+ public async Task<RefundResult> Handle(Guid orderId, RefundRequest request)",
9845
+ "+ {",
9846
+ "+ var order = await db.Orders.FindAsync(orderId);",
9847
+ "+ await payments.Refund(order!.PaymentId, request.Amount);",
9848
+ "+ order.Refunded += request.Amount;",
9849
+ "+ await db.SaveChangesAsync();",
9850
+ "+ return new RefundResult(order.Refunded);",
9851
+ "+ }",
9852
+ "+}"
9853
+ ],
9854
+ "added"
9855
+ ),
9856
+ hunk(
9857
+ "src/Shop.Orders/Refunds/RefundValidator.cs",
9858
+ [
9859
+ "+public class RefundValidator : AbstractValidator<RefundRequest>",
9860
+ "+{",
9861
+ "+ public RefundValidator() => RuleFor(x => x.Amount).GreaterThan(0);",
9862
+ "+}"
9863
+ ],
9864
+ "added"
9865
+ ),
9866
+ hunk("src/Shop.Orders/Pricing/Rounding.cs", [
9867
+ " public static class Rounding",
9868
+ " {",
9869
+ "- public static decimal Cents(decimal x) => Math.Round(x, 2);",
9870
+ "+ public static decimal Cents(decimal x) => Math.Round(x, 2, MidpointRounding.AwayFromZero);",
9871
+ " }"
9872
+ ]),
9873
+ hunk(
9874
+ "src/Shop.Data/Migrations/20261102_AddRefunds.cs",
9875
+ [
9876
+ "+public partial class AddRefunds : Migration",
9877
+ "+{",
9878
+ '+ protected override void Up(MigrationBuilder b) => b.AddColumn<decimal>("Refunded", "Orders", nullable: false, defaultValue: 0m);',
9879
+ "+}"
9880
+ ],
9881
+ "added"
9882
+ ),
9883
+ hunk("src/Shop.Data/Migrations/20261102_AddRefunds.Designer.cs", ["+// <auto-generated />", "+partial class AddRefunds { }"], "added"),
9884
+ hunk("src/Shop.Data/Migrations/ShopDbModelSnapshot.cs", [' b.Property<decimal>("Total");', '+ b.Property<decimal>("Refunded");']),
9885
+ hunk("src/Shop.Api/Program.cs", [
9886
+ " builder.Services.AddScoped<IOrders, Orders>();",
9887
+ "+builder.Services.AddScoped<IRefundHandler, RefundHandler>();"
9888
+ ]),
9889
+ hunk("src/Shop.Orders/Shop.Orders.csproj", [
9890
+ '- <PackageReference Include="FluentValidation" Version="11.9.0" />',
9891
+ '+ <PackageReference Include="FluentValidation" Version="11.11.0" />'
9892
+ ]),
9893
+ hunk("src/Shop.Orders/OrderService.cs", ["-using System.Linq;", "+using System.Collections.Generic;", "+using System.Linq;"]),
9894
+ hunk("web/package-lock.json", ['- "version": "1.4.0",', '+ "version": "1.4.1",']),
9895
+ hunk(
9896
+ "tests/Shop.Orders.Tests/RefundHandlerTests.cs",
9897
+ [
9898
+ "+public class RefundHandlerTests",
9899
+ "+{",
9900
+ "+ [Fact]",
9901
+ "+ public async Task Refunds_part_of_an_order()",
9902
+ "+ {",
9903
+ "+ var result = await new RefundHandler(Db(), Payments()).Handle(Order, new(10m));",
9904
+ "+ Assert.Equal(10m, result.Refunded);",
9905
+ "+ }",
9906
+ "+ [Theory]",
9907
+ "+ [InlineData(0)]",
9908
+ "+ [InlineData(-5)]",
9909
+ "+ public void Rejects_amounts_that_are_not_positive(decimal amount) { }",
9910
+ "+}"
9911
+ ],
9912
+ "added"
9913
+ )
9914
+ ].join("\n");
9915
+ var DEMO_ANSWER = JSON.stringify({
9916
+ recommendation: {
9917
+ verdict: "fix-first",
9918
+ text: "Fix the refund limit before this is merged: nothing compares a refund with what the customer paid, so a refund can exceed the order total. Two refunds of one order at the same time can also both pass, which needs a decision on locking. The rounding change is fine on its own but moves amounts by a cent everywhere, so say so in the release notes."
9919
+ },
9920
+ flows: [
9921
+ {
9922
+ change: "added",
9923
+ title: "Support staff refund part of a paid order.",
9924
+ steps: [
9925
+ "A support user posts an amount to the order\u2019s new refund endpoint.",
9926
+ "RefundValidator rejects an amount that is not positive.",
9927
+ "RefundHandler asks the payment provider to refund that amount.",
9928
+ "The handler adds the amount to the order\u2019s new Refunded total and saves the order."
9929
+ ]
9930
+ },
9931
+ {
9932
+ change: "changed",
9933
+ title: "Every price is rounded to cents.",
9934
+ steps: [
9935
+ "A price, total or refund amount is computed with more than two decimals.",
9936
+ "Rounding.Cents rounds it half away from zero; before, it rounded half to the nearest even cent."
9937
+ ]
9938
+ }
9939
+ ],
9940
+ summary: "Adds partial refunds to paid orders: a POST endpoint, a handler that refunds through the payment provider and records the amount on the order, and a validator for the amount. A migration adds the column, and prices now round half away from zero.",
9941
+ stories: [
9942
+ {
9943
+ title: "Support staff can now refund part of a paid order, and the refunded amount is recorded on the order.",
9944
+ what: "A refund request for an order is sent to the payment provider for the requested amount, and the amount is then added to the order\u2019s new Refunded total. The validator only accepts a positive amount. Nothing compares the amount with what the customer paid, so a refund can exceed the order total. Existing orders start with a Refunded total of 0, and no existing caller changes.",
9945
+ why: "The handler moves the money and the validator decides which requests reach it: one cannot be reviewed without the other.",
9946
+ risk: "It moves real money through the payment provider. Two refunds of the same order at once both read the old Refunded total, and nothing stops a refund larger than what was paid.",
9947
+ riskLevel: 5,
9948
+ flags: ["data-loss", "concurrency"],
9949
+ files: ["src/Shop.Orders/Refunds/RefundHandler.cs", "src/Shop.Orders/Refunds/RefundValidator.cs"]
9950
+ },
9951
+ {
9952
+ title: "Prices that end in half a cent now round away from zero instead of to the nearest even cent.",
9953
+ what: "Rounding.Cents now passes MidpointRounding.AwayFromZero, so 2.345 becomes 2.35 where it used to become 2.34. Every price, total and refund goes through this method, so amounts can move by one cent wherever a half cent appears. Invoices already issued keep their stored amounts; new ones may differ from an old calculation of the same order.",
9954
+ why: "It is a one-line change on its own, but every amount the shop computes passes through it.",
9955
+ risk: "A one-cent difference on .5 amounts shows up everywhere at once, including in totals other systems compare against.",
9956
+ riskLevel: 3,
9957
+ flags: ["public-contract"],
9958
+ files: ["src/Shop.Orders/Pricing/Rounding.cs"]
9959
+ }
9960
+ ],
9961
+ fileSummaries: {
9962
+ "src/Shop.Orders/Refunds/RefundHandler.cs": "New handler that loads the order, asks the payment provider to refund the amount, and adds it to the order\u2019s Refunded total before saving. It does not check the order exists or that the amount fits within what was paid.",
9963
+ "src/Shop.Orders/Refunds/RefundValidator.cs": "New validator for refund requests: the amount must be greater than zero. It is the only check a request passes before money moves.",
9964
+ "src/Shop.Orders/Pricing/Rounding.cs": "Cents now rounds half a cent away from zero (MidpointRounding.AwayFromZero) instead of to even. Every amount the shop computes passes through it.",
9965
+ "src/Shop.Api/Controllers/RefundsController.cs": "New endpoint POST /orders/{orderId}/refunds that hands the request to the refund handler and returns the new refunded total. It is a new public route for API clients.",
9966
+ "src/Shop.Data/Migrations/20261102_AddRefunds.cs": "Adds a non-null Refunded column to the Orders table with a default of 0, so existing orders read as not refunded.",
9967
+ "src/Shop.Api/Program.cs": "Registers the refund handler for dependency injection, so the new controller can be constructed."
9968
+ },
9969
+ notes: [
9970
+ {
9971
+ path: "src/Shop.Orders/Refunds/RefundHandler.cs",
9972
+ line: 6,
9973
+ body: "Ivo\u2019s open question about locking the row is still not answered by the code: two refunds at once both read the old `Refunded`. A row version, or a check in the update, would settle it."
9974
+ },
9975
+ { path: "src/Shop.Orders/Refunds/RefundHandler.cs", line: 7, body: "Nothing stops refunding more than the order total." },
9976
+ // A line the diff doesn't show: set aside with its text (the host would refuse the whole review for it).
9977
+ { path: "src/Shop.Orders/Pricing/Rounding.cs", line: 90, body: "Is MidpointRounding used the same way in the invoice export?" }
9978
+ ],
9979
+ asserts: {
9980
+ Refunds_part_of_an_order: "the refunded amount comes back \u2014 not that the payment provider was called",
9981
+ Rejects_amounts_that_are_not_positive: "nothing yet: its body is empty"
9982
+ }
9983
+ });
9984
+ var ALL_FILES = parseGitDiff(DIFF);
9985
+ var SPLIT = splitIgnored(ALL_FILES);
9986
+ var FILES = SPLIT.files;
9987
+ var demoReviewFiles = () => FILES;
9988
+ function demoDiscussion(now = /* @__PURE__ */ new Date()) {
9989
+ const ago = (h) => new Date(now.getTime() - h * 36e5).toISOString();
9990
+ const url = (id) => `https://github.com/example/api/pull/231#discussion_${id}`;
9991
+ return {
9992
+ at: now.toISOString(),
9993
+ updatedAt: ago(2),
9994
+ threads: [
9995
+ {
9996
+ id: "PRRT_demo1",
9997
+ path: "src/Shop.Orders/Refunds/RefundHandler.cs",
9998
+ line: 6,
9999
+ side: "right",
10000
+ outdated: false,
10001
+ resolved: false,
10002
+ url: url("r1"),
10003
+ comments: [
10004
+ {
10005
+ author: "ivo",
10006
+ association: "MEMBER",
10007
+ body: "Is `FindAsync` enough here, or should this lock the order row? Two support agents refunding the same order is not unusual.",
10008
+ at: ago(20),
10009
+ url: url("r1")
10010
+ },
10011
+ {
10012
+ author: "marta",
10013
+ association: "CONTRIBUTOR",
10014
+ body: "Good point. I will look at a row version on Orders.",
10015
+ at: ago(18),
10016
+ url: url("r1b")
10017
+ }
10018
+ ]
10019
+ },
10020
+ {
10021
+ id: "PRRT_demo2",
10022
+ path: "src/Shop.Orders/Refunds/RefundValidator.cs",
10023
+ line: 3,
10024
+ side: "right",
10025
+ outdated: false,
10026
+ resolved: true,
10027
+ url: url("r2"),
10028
+ comments: [
10029
+ { author: "ana", association: "OWNER", body: "Should a refund of 0 be allowed?", at: ago(30), url: url("r2") },
10030
+ { author: "marta", association: "CONTRIBUTOR", body: "No: changed to `GreaterThan(0)`.", at: ago(26), url: url("r2b") }
10031
+ ]
10032
+ },
10033
+ {
10034
+ id: "PRRT_demo3",
10035
+ path: "src/Shop.Orders/Pricing/Rounding.cs",
10036
+ line: null,
10037
+ originalLine: 3,
10038
+ side: "right",
10039
+ outdated: true,
10040
+ resolved: false,
10041
+ url: url("r3"),
10042
+ comments: [
10043
+ {
10044
+ author: "ivo",
10045
+ association: "MEMBER",
10046
+ body: "Why banker\u2019s rounding in the first place? The invoices round half up.",
10047
+ at: ago(40),
10048
+ url: url("r3")
10049
+ }
10050
+ ]
10051
+ }
10052
+ ],
10053
+ reviews: [
10054
+ { author: "ivo", association: "MEMBER", state: "commented", body: "", at: ago(20), url: url("v1") },
10055
+ { author: "ana", association: "OWNER", state: "approved", body: "Fine once the row locking is sorted.", at: ago(25), url: url("v2") }
10056
+ ],
10057
+ comments: [
10058
+ {
10059
+ author: "lea",
10060
+ association: "MEMBER",
10061
+ body: "Can this go in before Friday\u2019s release? Support is waiting for it.",
10062
+ at: ago(6),
10063
+ url: "https://github.com/example/api/pull/231#issuecomment-1"
10064
+ }
10065
+ ]
10066
+ };
10067
+ }
10068
+ function demoReview(now = /* @__PURE__ */ new Date()) {
10069
+ return {
10070
+ ...buildReview(
10071
+ {
10072
+ repo: "api",
10073
+ number: 231,
10074
+ title: "Refunds: partial refunds on paid orders",
10075
+ url: "https://github.com/example/api/pull/231",
10076
+ author: "marta",
10077
+ branch: "feat/refunds",
10078
+ base: "main",
10079
+ headSha: "a1b2c3d"
10080
+ },
10081
+ FILES,
10082
+ { whitespaceOnly: /* @__PURE__ */ new Set(), generated: /* @__PURE__ */ new Set() },
10083
+ DEMO_ANSWER,
10084
+ { now, ignored: SPLIT.ignored }
10085
+ ),
10086
+ mergeBase: "base",
10087
+ preparedAt: now.toISOString(),
10088
+ discussion: demoDiscussion(now)
10089
+ };
10090
+ }
10091
+ function waitingReview(now) {
10092
+ const { discussion: _none, ...prepared } = demoReview(now);
10093
+ return {
10094
+ ...prepared,
10095
+ number: 236,
10096
+ title: "Upgrade to .NET 10",
10097
+ url: "https://github.com/example/api/pull/236",
10098
+ author: "ivo",
10099
+ status: "waiting",
10100
+ why: "4812 changed lines: over the size limit (3000), so it waits for your click",
10101
+ size: { files: 0, added: 4100, deleted: 712 },
10102
+ files: [],
10103
+ stories: [],
10104
+ unstoried: [],
10105
+ drafts: [],
10106
+ tests: { list: [], counts: { added: 0, changed: 0, removed: 0, skipped: 0 }, gaps: [], covers: {}, unitOnlyForSchema: false },
10107
+ asserts: {},
10108
+ aiStep: "none"
10109
+ };
10110
+ }
10111
+ var noSessions = {
10112
+ liveOn: () => null,
10113
+ create: (alias, branch) => ({ id: `${alias}-${branch}`, label: `${alias} \xB7 ${branch}` }),
10114
+ note: () => void 0
10115
+ };
10116
+ function mountDemoReviews(app, broadcast, sessions = noSessions) {
10117
+ const now = /* @__PURE__ */ new Date();
10118
+ const reviews = /* @__PURE__ */ new Map([
10119
+ ["api#231", demoReview(now)],
10120
+ ["api#236", waitingReview(new Date(now.getTime() - 36e5))]
10121
+ ]);
10122
+ const modes = { api: "all", web: "asked", docs: "off" };
10123
+ const settings = () => ({
10124
+ projects: Object.entries(modes).map(([name, mode]) => ({ name, kind: "repo", mode, from: "repo" })),
10125
+ maxPerDay: null,
10126
+ maxLines: 3e3
10127
+ });
10128
+ const key = (repo, n) => `${repo}#${n}`;
10129
+ const store = {
10130
+ read: (rp, num4) => reviews.get(key(rp, String(num4))) ?? null,
10131
+ update: (rp, num4, change) => {
10132
+ const was = reviews.get(key(rp, String(num4)));
10133
+ if (!was) return null;
10134
+ const next = change(was);
10135
+ reviews.set(key(rp, String(num4)), next);
10136
+ return next;
10137
+ },
10138
+ pid: 0,
10139
+ bootedAt: () => 0,
10140
+ alive: () => true
10141
+ };
10142
+ app.get(
10143
+ "/api/reviews",
10144
+ (c) => c.json({
10145
+ reviews: [...reviews.values()].map(summaryOf).sort((a, b) => b.at.localeCompare(a.at)),
10146
+ today: 1,
10147
+ maxPerDay: null
10148
+ })
10149
+ );
10150
+ app.get("/api/reviews/settings", (c) => c.json(settings()));
10151
+ app.put("/api/reviews/settings", async (c) => {
10152
+ const body = await c.req.json().catch(() => null);
10153
+ if (!body || typeof body.project !== "string" || !isReviewMode(body.mode))
10154
+ return c.json({ error: "expected {project, mode: all|asked|off}" }, 400);
10155
+ modes[body.project] = body.mode;
10156
+ broadcast("reviews-changed", { settings: true });
10157
+ return c.json(settings());
10158
+ });
10159
+ app.get("/api/reviews/:repo/:number", (c) => {
10160
+ const r = reviews.get(key(c.req.param("repo"), c.req.param("number")));
10161
+ return r ? c.json(shownReview(store, r)) : c.json({ error: "no review of that PR" }, 404);
10162
+ });
10163
+ app.get("/api/reviews/:repo/:number/diff", (c) => {
10164
+ const r = reviews.get(key(c.req.param("repo"), c.req.param("number")));
10165
+ return r && r.status === "ready" ? c.json({ files: FILES }) : c.json({ error: "no prepared review of that PR" }, 404);
10166
+ });
10167
+ app.post("/api/reviews/:repo/:number", (c) => {
10168
+ const k = key(c.req.param("repo"), c.req.param("number"));
10169
+ const was = reviews.get(k);
10170
+ if (!was) return c.json({ error: "isn't an open pull request" }, 409);
10171
+ const r = { ...demoReview(/* @__PURE__ */ new Date()), number: was.number, title: was.title, url: was.url, author: was.author };
10172
+ reviews.set(k, r);
10173
+ broadcast("reviews-changed", { repo: r.repo, number: r.number });
10174
+ return c.json(r);
10175
+ });
10176
+ app.post("/api/reviews/:repo/:number/discussion", (c) => {
10177
+ const r = reviews.get(key(c.req.param("repo"), c.req.param("number")));
10178
+ return r ? c.json(shownReview(store, r)) : c.json({ error: "no review of that PR" }, 404);
10179
+ });
10180
+ app.post("/api/reviews/:repo/:number/drafts", async (c) => {
10181
+ const k = key(c.req.param("repo"), c.req.param("number"));
10182
+ const r = reviews.get(k);
10183
+ if (!r) return c.json({ error: "no review of that PR" }, 404);
10184
+ const added = addDraft(r, await c.req.json().catch(() => null));
10185
+ if ("error" in added) return c.json({ error: added.error }, 400);
10186
+ reviews.set(k, added.review);
10187
+ broadcast("reviews-changed", { repo: r.repo, number: r.number });
10188
+ return c.json(added.review);
10189
+ });
10190
+ app.post("/api/reviews/:repo/:number/submit", async (c) => {
10191
+ const repo = c.req.param("repo");
10192
+ const n = /^\d+$/.test(c.req.param("number")) ? Number(c.req.param("number")) : null;
10193
+ if (n === null) return c.json({ error: "no review of that PR" }, 404);
10194
+ const input = await c.req.json().catch(() => null);
10195
+ const out = await submitPrReview(
10196
+ {
10197
+ ...store,
10198
+ repoPath: (alias) => alias === "api" ? "/demo/api" : null,
10199
+ submit: async (_at, num4, review) => demoHostSubmit(reviews.get(key(repo, String(num4)))?.url ?? "", review)
10200
+ },
10201
+ repo,
10202
+ n,
10203
+ input
10204
+ );
10205
+ if (out.ok || out.review) broadcast("reviews-changed", { repo, number: n });
10206
+ if (out.ok) return c.json(out.review);
10207
+ return c.json({ error: out.error, ...out.review ? { review: out.review } : {} }, out.status);
10208
+ });
10209
+ app.post("/api/reviews/:repo/:number/fix-myself", async (c) => {
10210
+ const repo = c.req.param("repo");
10211
+ const n = /^\d+$/.test(c.req.param("number")) ? Number(c.req.param("number")) : null;
10212
+ if (n === null || !reviews.get(key(repo, String(n)))) return c.json({ error: "no review of that PR" }, 404);
10213
+ const input = await c.req.json().catch(() => null);
10214
+ const out = await fixItMyself(
10215
+ {
10216
+ read: store.read,
10217
+ update: store.update,
10218
+ lookUp: async (r) => r.fork ? { ok: false, error: "it comes from a fork: its branch isn't on origin" } : {
10219
+ ok: true,
10220
+ pr: { alias: r.repo, number: r.number, title: r.title, url: r.url, branch: r.branch, base: r.base, author: r.author }
10221
+ },
10222
+ liveSessionOn: (alias, branch) => sessions.liveOn(alias, branch),
10223
+ create: async (alias, branch, name) => {
10224
+ const s = sessions.create(alias, branch, name);
10225
+ return { ok: true, sessionId: s.id, label: s.label };
10226
+ },
10227
+ // The demo's agent "starts" on its instruction: a note it answers, as every demo note.
10228
+ start: async (id, prompt) => sessions.note(id, prompt),
10229
+ note: async (id, body) => sessions.note(id, body)
10230
+ },
10231
+ repo,
10232
+ n,
10233
+ input
10234
+ );
10235
+ if (!out.ok) return c.json({ error: out.error }, out.status);
10236
+ broadcast("reviews-changed", { repo, number: n });
10237
+ broadcast("sessions-changed", { ts: Date.now() });
10238
+ const { ok: _ok, ...wire } = out;
10239
+ return c.json(wire);
10240
+ });
10241
+ app.post("/api/reviews/:repo/:number/in-doubt", async (c) => {
10242
+ const k = key(c.req.param("repo"), c.req.param("number"));
10243
+ const r = reviews.get(k);
10244
+ if (!r) return c.json({ error: "no review of that PR" }, 404);
10245
+ const body = await c.req.json().catch(() => null);
10246
+ if (!body || typeof body.went !== "boolean") return c.json({ error: "expected {went: true|false}" }, 400);
10247
+ const out = settlePrReview(store, r.repo, r.number, body.went);
10248
+ if (!out.ok) return c.json({ error: out.error }, out.status);
10249
+ broadcast("reviews-changed", { repo: r.repo, number: r.number });
10250
+ return c.json(out.review);
10251
+ });
10252
+ app.delete("/api/reviews/:repo/:number/dropped", (c) => {
10253
+ const k = key(c.req.param("repo"), c.req.param("number"));
10254
+ const r = reviews.get(k);
10255
+ if (!r) return c.json({ error: "no review of that PR" }, 404);
10256
+ const next = clearDropped(r);
10257
+ reviews.set(k, next);
10258
+ broadcast("reviews-changed", { repo: r.repo, number: r.number });
10259
+ return c.json(next);
10260
+ });
10261
+ app.delete("/api/reviews/:repo/:number/drafts/:id", (c) => {
10262
+ const k = key(c.req.param("repo"), c.req.param("number"));
10263
+ const r = reviews.get(k);
10264
+ if (!r) return c.json({ error: "no review of that PR" }, 404);
10265
+ const out = removeDraft(r, c.req.param("id"));
10266
+ if ("error" in out) return c.json({ error: out.error }, out.status);
10267
+ reviews.set(k, out.review);
10268
+ broadcast("reviews-changed", { repo: r.repo, number: r.number });
10269
+ return c.json(out.review);
10270
+ });
10271
+ }
10272
+
10273
+ // src/server/demo/demo-server.ts
10274
+ import { Hono as Hono2 } from "hono";
10275
+ import { streamSSE as streamSSE3 } from "hono/streaming";
10276
+ import { WebSocketServer as WebSocketServer2 } from "ws";
10277
+
10278
+ // src/server/demo/demo-repos.ts
10279
+ var DemoRepoError = class extends Error {
10280
+ constructor(message, sessions = []) {
10281
+ super(message);
10282
+ this.sessions = sessions;
10283
+ }
10284
+ };
10285
+ function createDemoRepos(liveTargets) {
10286
+ const root = "~/repos";
10287
+ const repos = {
10288
+ api: `${root}/api`,
10289
+ web: `${root}/web`,
10290
+ backend: `${root}/shop-backend`,
10291
+ frontend: `${root}/shop-frontend`,
10292
+ // On Azure DevOps (#65): its PRs come through the az adapter in the real dashboard.
10293
+ payments: `${root}/payments`
10294
+ };
10295
+ const groups = { shop: ["backend", "frontend"] };
10296
+ const ignored = /* @__PURE__ */ new Set();
10297
+ const found = [
9119
10298
  { path: `${root}/api`, folder: "api", origin: "example/api" },
9120
10299
  { path: `${root}/web`, folder: "web", origin: "example/web" },
9121
10300
  { path: `${root}/shop-backend`, folder: "shop-backend", origin: "example/shop-backend" },
@@ -9131,7 +10310,7 @@ function createDemoRepos(liveTargets) {
9131
10310
  /** GET /api/projects: what New worktree offers, as the real one reads config. */
9132
10311
  projects() {
9133
10312
  return {
9134
- singles: Object.entries(repos).map(([name, path20]) => ({ name, kind: "single", path: path20 })),
10313
+ singles: Object.entries(repos).map(([name, path22]) => ({ name, kind: "single", path: path22 })),
9135
10314
  groups: Object.entries(groups).map(([name, members]) => ({ name, kind: "group", members }))
9136
10315
  };
9137
10316
  },
@@ -9173,12 +10352,12 @@ function createDemoRepos(liveTargets) {
9173
10352
  }));
9174
10353
  return { roots: [root], repos: rows, groups: groupRows };
9175
10354
  },
9176
- enroll(alias, path20) {
9177
- if (!found.some((f) => f.path === path20)) throw new DemoRepoError(`${path20} is not the top folder of a git repository`);
9178
- const problem = enrollProblem(alias, path20, config());
10355
+ enroll(alias, path22) {
10356
+ if (!found.some((f) => f.path === path22)) throw new DemoRepoError(`${path22} is not the top folder of a git repository`);
10357
+ const problem = enrollProblem(alias, path22, config());
9179
10358
  if (problem) throw new DemoRepoError(problem);
9180
- repos[alias] = path20;
9181
- ignored.delete(path20);
10359
+ repos[alias] = path22;
10360
+ ignored.delete(path22);
9182
10361
  },
9183
10362
  remove(alias, force) {
9184
10363
  if (!(alias in repos)) throw new DemoRepoError(`no repo \u201C${alias}\u201D`);
@@ -9187,9 +10366,9 @@ function createDemoRepos(liveTargets) {
9187
10366
  delete repos[alias];
9188
10367
  for (const g2 of Object.keys(groups)) groups[g2] = groups[g2].filter((m) => m !== alias);
9189
10368
  },
9190
- ignore(path20, on) {
9191
- if (on) ignored.add(path20);
9192
- else ignored.delete(path20);
10369
+ ignore(path22, on) {
10370
+ if (on) ignored.add(path22);
10371
+ else ignored.delete(path22);
9193
10372
  },
9194
10373
  saveGroup(name, members, creating) {
9195
10374
  const problem = groupProblem(name, members, config(), { creating });
@@ -9589,8 +10768,8 @@ var DemoScenario = class {
9589
10768
  this.pending = this.pending.filter((p) => !ready.includes(p));
9590
10769
  for (const p of ready) p.run();
9591
10770
  }
9592
- after(ms, run) {
9593
- this.pending.push({ at: this.now() + ms * this.speed, run });
10771
+ after(ms, run2) {
10772
+ this.pending.push({ at: this.now() + ms * this.speed, run: run2 });
9594
10773
  }
9595
10774
  // -- seed -----------------------------------------------------------------
9596
10775
  iso(minutesAgo) {
@@ -10429,15 +11608,15 @@ ${reply}\r
10429
11608
  if (refusal || !s) return { ok: false, status: refusal?.status ?? 404, error: refusal?.error ?? "unknown session" };
10430
11609
  s.repos.push({ name: alias, uncommitted: "", sinceBranch: "", published: false, pr: null });
10431
11610
  const from = base || "main";
10432
- const path20 = this.wire(s).paths[s.repos.length - 1];
11611
+ const path22 = this.wire(s).paths[s.repos.length - 1];
10433
11612
  s.comments.post({
10434
11613
  side: "general",
10435
11614
  status: "published",
10436
- body: addedRepoNote({ alias, path: path20, branch: s.branch, from, imported: true })
11615
+ body: addedRepoNote({ alias, path: path22, branch: s.branch, from, imported: true })
10437
11616
  });
10438
11617
  this.emit("comments-changed", { sessionId: id });
10439
11618
  this.changed();
10440
- return { ok: true, wire: { ok: true, path: path20, branch: s.branch, created: true, from, imported: true, warnings: [] } };
11619
+ return { ok: true, wire: { ok: true, path: path22, branch: s.branch, created: true, from, imported: true, warnings: [] } };
10441
11620
  }
10442
11621
  // -- CI (the PR watch, simulated) ------------------------------------------
10443
11622
  /** The Today digest, through the same builder as work web: the demo's
@@ -11009,733 +12188,283 @@ function demoCodeFiles(repos, group) {
11009
12188
  return {
11010
12189
  group,
11011
12190
  rootFiles: group ? ["CLAUDE.md"] : [],
11012
- repos: repos.map((r) => {
11013
- const changed = r.changed.filter((f) => f.status !== "deleted").map((f) => f.path);
11014
- return { name: r.name, files: [.../* @__PURE__ */ new Set([...Object.keys(COMMON), ...changed])].sort(), changed: changed.sort(), truncated: false };
11015
- })
11016
- };
11017
- }
11018
- function demoCodeFile(repos, group, repo, path20) {
11019
- if (repo === "") {
11020
- if (!group || path20 !== "CLAUDE.md") return null;
11021
- const text2 = `# Group instructions
11022
-
11023
- Repos: ${repos.map((r2) => r2.name).join(", ")}.
11024
- `;
11025
- return { repo, path: path20, size: text2.length, text: text2 };
11026
- }
11027
- const r = repos.find((x) => x.name === repo);
11028
- if (!r) return null;
11029
- const changed = r.changed.find((f) => f.path === path20 && f.status !== "deleted");
11030
- const text = changed ? newSide(changed) : COMMON[path20]?.replace(/\{repo\}/g, repo);
11031
- return text === void 0 ? null : { repo, path: path20, size: text.length, text };
11032
- }
11033
- function demoCodeSearch(repos, group, query) {
11034
- const q = query.trim();
11035
- if (q.length < 2) return { query: q, symbols: [], text: [], truncated: false };
11036
- const symbols = [];
11037
- const text = [];
11038
- const fold = (x) => ignoresCase(q) ? x.toLowerCase() : x;
11039
- for (const r of demoCodeFiles(repos, group).repos) {
11040
- for (const path20 of r.files) {
11041
- const lines = (demoCodeFile(repos, group, r.name, path20)?.text ?? "").split("\n");
11042
- lines.forEach((line, i) => {
11043
- const d = declarationOf(path20, line);
11044
- if (d) symbols.push({ ...d, repo: r.name, path: path20, line: i + 1, text: line.trim() });
11045
- if (fold(line).includes(fold(q))) text.push({ repo: r.name, path: path20, line: i + 1, text: line });
11046
- });
11047
- }
11048
- }
11049
- return { query: q, symbols: matchSymbols(symbols, q), text, truncated: false };
11050
- }
11051
-
11052
- // src/server/demo/demo-activity.ts
11053
- var SWEEP_EVERY_MS = 3e4;
11054
- var STEP_MS = 700;
11055
- function createDemoActivity(scenario, emit) {
11056
- const log = createActivityLog({ onChange: emit });
11057
- const prCheck = log.schedule("pr-watch", "Pull request check", SWEEP_EVERY_MS);
11058
- const idle = log.schedule("idle-sleep", "Idle Claude check", 5 * 6e4);
11059
- idle.next(Date.now() + 4 * 6e4);
11060
- log.start("jira", "Fetching your Jira issues").done(`${scenario.jira().length} issues`);
11061
- log.start("pr-list", "Listing open pull requests").done(`${scenario.prs().length} open PRs in 3 repos`);
11062
- const sleep = log.start("idle-sleep", "Looking for idle Claudes");
11063
- sleep.done(`${scenario.list().length} Claudes running \xB7 none idle long enough`);
11064
- let timers = [];
11065
- const later = (ms, fn) => {
11066
- const t = setTimeout(fn, ms);
11067
- t.unref?.();
11068
- timers.push(t);
11069
- };
11070
- const sweep = () => {
11071
- prCheck.next(Date.now() + SWEEP_EVERY_MS);
11072
- const sessions = scenario.list().filter((s) => !s.archivedAt);
11073
- const run = log.start("pr-watch", "Checking pull requests");
11074
- run.progress(0, sessions.length);
11075
- let prs = 0;
11076
- let threads = 0;
11077
- let failing = 0;
11078
- sessions.forEach((s, i) => {
11079
- later((i + 1) * STEP_MS, () => {
11080
- for (const r of scenario.ci(s.id)?.repos ?? []) {
11081
- if (r.pr?.state !== "OPEN") continue;
11082
- prs++;
11083
- threads += r.openThreads ?? 0;
11084
- if (r.pr.checks === "fail") {
11085
- failing++;
11086
- run.note(
11087
- `${s.target} ${s.branch}: checks fail on #${r.pr.number} (${(r.pr.failing ?? []).map((f) => f.name).join(", ")}): already told its Claude`,
11088
- { sessionId: s.id }
11089
- );
11090
- }
11091
- if (r.openThreads)
11092
- run.note(`${s.target} ${s.branch}: ${r.openThreads} unresolved review threads on #${r.pr.number}`, { sessionId: s.id });
11093
- }
11094
- run.progress(i + 1, sessions.length);
11095
- if (i === sessions.length - 1) {
11096
- const parts = [`${sessions.length} sessions`, `${prs} open PRs`];
11097
- if (threads) parts.push(`${threads} unresolved review threads`);
11098
- if (failing) parts.push(`${failing} failing`);
11099
- run.done(parts.join(" \xB7 "));
11100
- }
11101
- });
11102
- });
11103
- if (sessions.length === 0) run.done("0 sessions");
11104
- };
11105
- later(3e3, sweep);
11106
- prCheck.next(Date.now() + 3e3);
11107
- const every = setInterval(sweep, SWEEP_EVERY_MS);
11108
- every.unref?.();
11109
- return {
11110
- log,
11111
- stop: () => {
11112
- clearInterval(every);
11113
- for (const t of timers) clearTimeout(t);
11114
- timers = [];
11115
- }
11116
- };
11117
- }
11118
-
11119
- // src/server/demo/demo-time.ts
11120
- var SETTINGS2 = { ...DEFAULT_TIME_SETTINGS, gapTicket: "OPS-1", timeOffTicket: "HR-1" };
11121
- var TITLES = {
11122
- "PAY-12": "Export invoices as CSV",
11123
- "PAY-15": "Invoice PDF",
11124
- "SHOP-7": "Checkout in two steps",
11125
- "WEB-3": "Price and brand filters in search",
11126
- "WEB-9": "Login redirect loop",
11127
- "OPS-1": "Meetings, reviews and support",
11128
- "HR-1": "Time off"
11129
- };
11130
- var WORK = [
11131
- { id: "demo-api-feat-invoice-export", label: "api \xB7 feat/invoice-export", key: "PAY-12" },
11132
- { id: "demo-api-feat-invoice-pdf", label: "api \xB7 feat/invoice-pdf", key: "PAY-15" },
11133
- { id: "demo-shop-feat-checkout-v2", label: "shop \xB7 feat/checkout-v2", key: "SHOP-7" },
11134
- { id: "demo-web-feat-search-filters", label: "web \xB7 feat/search-filters", key: "WEB-3" },
11135
- { id: "demo-web-fix-login-redirect", label: "web \xB7 fix/login-redirect", key: "WEB-9" }
11136
- ];
11137
- function evidenceFor(n) {
11138
- const pick = [WORK[n % WORK.length], WORK[(n + 2) % WORK.length]];
11139
- return {
11140
- sessions: [
11141
- { sessionId: pick[0].id, label: pick[0].label, key: pick[0].key, minutes: 25 + n * 7 % 30 },
11142
- { sessionId: pick[1].id, label: pick[1].label, key: pick[1].key, minutes: 8 + n * 5 % 15 },
11143
- ...n % 3 === 0 ? [{ sessionId: "demo-api-chore-deps-update", label: "api \xB7 chore/deps-update", key: null, minutes: 12 }] : []
11144
- ],
11145
- commits: [
11146
- {
11147
- repo: pick[0].id.split("-")[1],
11148
- sha: `c0ffee${n}0`,
11149
- subject: `${pick[0].key}: ${TITLES[pick[0].key].toLowerCase()}, part ${n % 4 + 1}`,
11150
- keys: [pick[0].key]
11151
- }
11152
- ],
11153
- jira: n % 4 === 1 ? [{ key: "WEB-9", summary: TITLES["WEB-9"], what: "moved (now In review)" }] : []
11154
- };
11155
- }
11156
- var DEMO_DAYS = 31;
11157
- function createDemoTime(now) {
11158
- const edits = /* @__PURE__ */ new Map();
11159
- const record = (day) => {
11160
- const today = localDay(now());
11161
- if (day > today) return null;
11162
- const all = daysBetween(addDays(today, -(DEMO_DAYS - 1)), today);
11163
- const n = all.indexOf(day);
11164
- const e = edits.get(day) ?? {};
11165
- if (n < 0 && !e.edited && !e.dayOff) return null;
11166
- return {
11167
- day,
11168
- evidence: n >= 0 && isWorkday(day, SETTINGS2) ? evidenceFor(n) : { sessions: [], commits: [], jira: [] },
11169
- titles: TITLES,
11170
- builtAt: new Date(now()).toISOString(),
11171
- edited: e.edited ?? null,
11172
- dayOff: e.dayOff ?? false,
11173
- posted: e.posted ?? null
11174
- };
11175
- };
11176
- return {
11177
- days: (from, to) => daysWireOf(
11178
- from,
11179
- to,
11180
- SETTINGS2,
11181
- daysBetween(from, to).map(record).filter((r) => !!r)
11182
- ),
11183
- month: (month) => {
11184
- const today = localDay(now());
11185
- const r = monthRange(month, today);
11186
- const records = r ? daysBetween(r.from, r.to).map(record).filter((x) => !!x) : [];
11187
- return { ...monthWireOf(month, today, SETTINGS2, records), gathering: false, gatherError: null, posting: { ready: true, why: null } };
11188
- },
11189
- day: (day) => ({ ...dayWireOf(day, SETTINGS2, record(day)), posting: { ready: true, why: null } }),
11190
- update: (day, change) => {
11191
- edits.set(day, { ...edits.get(day) ?? {}, ...change });
11192
- return { ...dayWireOf(day, SETTINGS2, record(day)), posting: { ready: true, why: null } };
11193
- },
11194
- /** "Posting": what the day shows is now what Tempo has (nothing leaves the demo). */
11195
- post: (day) => {
11196
- const w = dayWireOf(day, SETTINGS2, record(day));
11197
- const before = record(day)?.posted?.entries ?? [];
11198
- const kept = w.entries.filter((e) => before.some((b) => b.key === e.key && b.hours === e.hours)).length;
11199
- edits.set(day, { ...edits.get(day) ?? {}, posted: { at: new Date(now()).toISOString(), entries: w.entries, worklogs: [] } });
11200
- return {
11201
- posted: w.entries.length - kept,
11202
- removed: before.length - kept,
11203
- kept,
11204
- coveredByHand: 0,
11205
- otherByHand: 0,
11206
- failed: [],
11207
- day: { ...dayWireOf(day, SETTINGS2, record(day)), posting: { ready: true, why: null } }
11208
- };
11209
- },
11210
- settings: SETTINGS2
12191
+ repos: repos.map((r) => {
12192
+ const changed = r.changed.filter((f) => f.status !== "deleted").map((f) => f.path);
12193
+ return { name: r.name, files: [.../* @__PURE__ */ new Set([...Object.keys(COMMON), ...changed])].sort(), changed: changed.sort(), truncated: false };
12194
+ })
11211
12195
  };
11212
12196
  }
12197
+ function demoCodeFile(repos, group, repo, path22) {
12198
+ if (repo === "") {
12199
+ if (!group || path22 !== "CLAUDE.md") return null;
12200
+ const text2 = `# Group instructions
11213
12201
 
11214
- // src/server/demo/demo-replies.ts
11215
- function mountDemoReplies(app, scenario, emit) {
11216
- const byId = /* @__PURE__ */ new Map();
11217
- const deps = scenario.list().find((s) => s.branch === "chore/deps-update");
11218
- if (deps) {
11219
- const at = new Date(Date.now() - 20 * 6e4).toISOString();
11220
- byId.set(deps.id, [
11221
- {
11222
- threadId: "PRRT_demo_zod",
11223
- repo: "api",
11224
- prNumber: 212,
11225
- url: "https://github.com/example/api/pull/212#discussion_r1",
11226
- where: "src/schema.ts:14",
11227
- reviewer: "dana",
11228
- excerpt: "zod 4 changed `.nonempty()` \u2014 does this still reject empty arrays?",
11229
- body: "zod 4 changed `.nonempty()` \u2014 does this still reject empty arrays?\n\nIf not, this would do it:\n\n```suggestion\n items: z.array(Item).min(1),\n```",
11230
- code: {
11231
- hunk: '@@ -10,6 +10,6 @@ export const Order = z.object({\n id: z.string().uuid(),\n customer: Customer,\n currency: z.enum(["EUR", "USD"]),\n- items: z.array(Item).min(1),\n+ items: z.array(Item).nonempty(),\n note: z.string().optional(),',
11232
- lines: 1
11233
- },
11234
- status: "draft",
11235
- draft: "Yes \u2014 switched to `.min(1)`, which zod 4 keeps, and added a test for the empty case (a1b2c3d).",
11236
- sentAt: at,
11237
- draftedAt: at
11238
- },
11239
- {
11240
- threadId: "PRRT_demo_lock",
11241
- repo: "api",
11242
- prNumber: 212,
11243
- url: "https://github.com/example/api/pull/212#discussion_r2",
11244
- where: "package-lock.json",
11245
- reviewer: "copilot-pull-request-reviewer",
11246
- excerpt: "The lockfile also bumps `express` to a new major version; was that intended?",
11247
- status: "sent",
11248
- draft: null,
11249
- sentAt: at
11250
- }
11251
- ]);
12202
+ Repos: ${repos.map((r2) => r2.name).join(", ")}.
12203
+ `;
12204
+ return { repo, path: path22, size: text2.length, text: text2 };
11252
12205
  }
11253
- const list = (id) => byId.get(id) ?? [];
11254
- const find = (id, thread) => list(id).find((r) => r.threadId === thread);
11255
- app.get("/api/sessions/:id/replies", (c) => c.json({ replies: list(c.req.param("id")), waiting: [] }));
11256
- app.put("/api/sessions/:id/replies/:thread", async (c) => {
11257
- const r = find(c.req.param("id"), c.req.param("thread"));
11258
- const b = await c.req.json().catch(() => ({}));
11259
- if (!r || typeof b.body !== "string" || !b.body.trim()) return c.json({ error: "unknown thread or empty reply" }, 400);
11260
- Object.assign(r, { status: "draft", draft: b.body.trim(), draftedAt: (/* @__PURE__ */ new Date()).toISOString() });
11261
- emit(c.req.param("id"));
11262
- return c.json({ reply: r });
11263
- });
11264
- app.delete("/api/sessions/:id/replies/:thread", (c) => {
11265
- const id = c.req.param("id");
11266
- byId.set(
11267
- id,
11268
- list(id).filter((r) => r.threadId !== c.req.param("thread"))
11269
- );
11270
- emit(id);
11271
- return c.json({ ok: true });
11272
- });
11273
- app.post("/api/sessions/:id/replies/:thread/post", async (c) => {
11274
- const r = find(c.req.param("id"), c.req.param("thread"));
11275
- const b = await c.req.json().catch(() => ({}));
11276
- if (!r || typeof b.body !== "string" || !b.body.trim()) return c.json({ error: "unknown thread or empty reply" }, 400);
11277
- Object.assign(r, {
11278
- status: "posted",
11279
- draft: b.body.trim(),
11280
- postedAt: (/* @__PURE__ */ new Date()).toISOString(),
11281
- postedUrl: r.url,
11282
- resolved: b.resolve === true
11283
- });
11284
- emit(c.req.param("id"));
11285
- return c.json({ ok: true, url: r.url, resolved: b.resolve === true });
11286
- });
11287
- app.post("/api/replies-changed", (c) => c.json({ ok: true }));
11288
- return (id) => list(id).filter((r) => r.status === "draft").length;
12206
+ const r = repos.find((x) => x.name === repo);
12207
+ if (!r) return null;
12208
+ const changed = r.changed.find((f) => f.path === path22 && f.status !== "deleted");
12209
+ const text = changed ? newSide(changed) : COMMON[path22]?.replace(/\{repo\}/g, repo);
12210
+ return text === void 0 ? null : { repo, path: path22, size: text.length, text };
11289
12211
  }
11290
-
11291
- // src/server/demo/demo-reviews.ts
11292
- async function demoHostSubmit(url, review) {
11293
- if (review.body.includes("#timeout"))
11294
- return {
11295
- ok: false,
11296
- error: "the host timed out (demo)",
11297
- inDoubt: { comments: review.comments.map((_, i) => i), summary: !!review.body.trim() }
11298
- };
11299
- return { ok: true, url: `${url}#pullrequestreview-1` };
12212
+ function demoCodeSearch(repos, group, query) {
12213
+ const q = query.trim();
12214
+ if (q.length < 2) return { query: q, symbols: [], text: [], truncated: false };
12215
+ const symbols = [];
12216
+ const text = [];
12217
+ const fold = (x) => ignoresCase(q) ? x.toLowerCase() : x;
12218
+ for (const r of demoCodeFiles(repos, group).repos) {
12219
+ for (const path22 of r.files) {
12220
+ const lines = (demoCodeFile(repos, group, r.name, path22)?.text ?? "").split("\n");
12221
+ lines.forEach((line, i) => {
12222
+ const d = declarationOf(path22, line);
12223
+ if (d) symbols.push({ ...d, repo: r.name, path: path22, line: i + 1, text: line.trim() });
12224
+ if (fold(line).includes(fold(q))) text.push({ repo: r.name, path: path22, line: i + 1, text: line });
12225
+ });
12226
+ }
12227
+ }
12228
+ return { query: q, symbols: matchSymbols(symbols, q), text, truncated: false };
11300
12229
  }
11301
- var hunk = (path20, lines, status = "modified") => {
11302
- const added = lines.filter((l) => l.startsWith("+")).length;
11303
- const deleted = lines.filter((l) => l.startsWith("-")).length;
11304
- const context = lines.length - added - deleted;
11305
- return [
11306
- `diff --git a/${path20} b/${path20}`,
11307
- ...status === "added" ? ["new file mode 100644", "index 0000000..1111111", "--- /dev/null"] : ["index 1111111..2222222 100644", `--- a/${path20}`],
11308
- `+++ b/${path20}`,
11309
- `@@ -${status === "added" ? 0 : 1},${status === "added" ? 0 : context + deleted} +1,${context + added} @@`,
11310
- ...lines
11311
- ].join("\n");
11312
- };
11313
- var DIFF = [
11314
- hunk(
11315
- "src/Shop.Api/Controllers/RefundsController.cs",
11316
- [
11317
- "+using System;",
11318
- "+using Microsoft.AspNetCore.Mvc;",
11319
- "+using Shop.Orders.Refunds;",
11320
- "+",
11321
- "+[ApiController]",
11322
- '+[Route("orders/{orderId}/refunds")]',
11323
- "+public class RefundsController(IRefundHandler refunds) : ControllerBase",
11324
- "+{",
11325
- "+ [HttpPost]",
11326
- "+ public async Task<IActionResult> Create(Guid orderId, RefundRequest request)",
11327
- "+ => Ok(await refunds.Handle(orderId, request));",
11328
- "+}"
11329
- ],
11330
- "added"
11331
- ),
11332
- hunk(
11333
- "src/Shop.Orders/Refunds/RefundHandler.cs",
11334
- [
11335
- "+public class RefundHandler(ShopDb db, IPayments payments) : IRefundHandler",
11336
- "+{",
11337
- "+ public async Task<RefundResult> Handle(Guid orderId, RefundRequest request)",
11338
- "+ {",
11339
- "+ var order = await db.Orders.FindAsync(orderId);",
11340
- "+ await payments.Refund(order!.PaymentId, request.Amount);",
11341
- "+ order.Refunded += request.Amount;",
11342
- "+ await db.SaveChangesAsync();",
11343
- "+ return new RefundResult(order.Refunded);",
11344
- "+ }",
11345
- "+}"
11346
- ],
11347
- "added"
11348
- ),
11349
- hunk(
11350
- "src/Shop.Orders/Refunds/RefundValidator.cs",
11351
- [
11352
- "+public class RefundValidator : AbstractValidator<RefundRequest>",
11353
- "+{",
11354
- "+ public RefundValidator() => RuleFor(x => x.Amount).GreaterThan(0);",
11355
- "+}"
11356
- ],
11357
- "added"
11358
- ),
11359
- hunk("src/Shop.Orders/Pricing/Rounding.cs", [
11360
- " public static class Rounding",
11361
- " {",
11362
- "- public static decimal Cents(decimal x) => Math.Round(x, 2);",
11363
- "+ public static decimal Cents(decimal x) => Math.Round(x, 2, MidpointRounding.AwayFromZero);",
11364
- " }"
11365
- ]),
11366
- hunk(
11367
- "src/Shop.Data/Migrations/20261102_AddRefunds.cs",
11368
- [
11369
- "+public partial class AddRefunds : Migration",
11370
- "+{",
11371
- '+ protected override void Up(MigrationBuilder b) => b.AddColumn<decimal>("Refunded", "Orders", nullable: false, defaultValue: 0m);',
11372
- "+}"
11373
- ],
11374
- "added"
11375
- ),
11376
- hunk("src/Shop.Data/Migrations/20261102_AddRefunds.Designer.cs", ["+// <auto-generated />", "+partial class AddRefunds { }"], "added"),
11377
- hunk("src/Shop.Data/Migrations/ShopDbModelSnapshot.cs", [' b.Property<decimal>("Total");', '+ b.Property<decimal>("Refunded");']),
11378
- hunk("src/Shop.Api/Program.cs", [
11379
- " builder.Services.AddScoped<IOrders, Orders>();",
11380
- "+builder.Services.AddScoped<IRefundHandler, RefundHandler>();"
11381
- ]),
11382
- hunk("src/Shop.Orders/Shop.Orders.csproj", [
11383
- '- <PackageReference Include="FluentValidation" Version="11.9.0" />',
11384
- '+ <PackageReference Include="FluentValidation" Version="11.11.0" />'
11385
- ]),
11386
- hunk("src/Shop.Orders/OrderService.cs", ["-using System.Linq;", "+using System.Collections.Generic;", "+using System.Linq;"]),
11387
- hunk("web/package-lock.json", ['- "version": "1.4.0",', '+ "version": "1.4.1",']),
11388
- hunk(
11389
- "tests/Shop.Orders.Tests/RefundHandlerTests.cs",
11390
- [
11391
- "+public class RefundHandlerTests",
11392
- "+{",
11393
- "+ [Fact]",
11394
- "+ public async Task Refunds_part_of_an_order()",
11395
- "+ {",
11396
- "+ var result = await new RefundHandler(Db(), Payments()).Handle(Order, new(10m));",
11397
- "+ Assert.Equal(10m, result.Refunded);",
11398
- "+ }",
11399
- "+ [Theory]",
11400
- "+ [InlineData(0)]",
11401
- "+ [InlineData(-5)]",
11402
- "+ public void Rejects_amounts_that_are_not_positive(decimal amount) { }",
11403
- "+}"
11404
- ],
11405
- "added"
11406
- )
11407
- ].join("\n");
11408
- var DEMO_ANSWER = JSON.stringify({
11409
- summary: "Adds partial refunds to paid orders: a POST endpoint, a handler that refunds through the payment provider and records the amount on the order, and a validator for the amount. A migration adds the column, and prices now round half away from zero.",
11410
- stories: [
11411
- {
11412
- title: "Support staff can now refund part of a paid order, and the refunded amount is recorded on the order.",
11413
- what: "A refund request for an order is sent to the payment provider for the requested amount, and the amount is then added to the order\u2019s new Refunded total. The validator only accepts a positive amount. Nothing compares the amount with what the customer paid, so a refund can exceed the order total. Existing orders start with a Refunded total of 0, and no existing caller changes.",
11414
- why: "The handler moves the money and the validator decides which requests reach it: one cannot be reviewed without the other.",
11415
- risk: "It moves real money through the payment provider. Two refunds of the same order at once both read the old Refunded total, and nothing stops a refund larger than what was paid.",
11416
- riskLevel: 5,
11417
- flags: ["data-loss", "concurrency"],
11418
- files: ["src/Shop.Orders/Refunds/RefundHandler.cs", "src/Shop.Orders/Refunds/RefundValidator.cs"]
11419
- },
11420
- {
11421
- title: "Prices that end in half a cent now round away from zero instead of to the nearest even cent.",
11422
- what: "Rounding.Cents now passes MidpointRounding.AwayFromZero, so 2.345 becomes 2.35 where it used to become 2.34. Every price, total and refund goes through this method, so amounts can move by one cent wherever a half cent appears. Invoices already issued keep their stored amounts; new ones may differ from an old calculation of the same order.",
11423
- why: "It is a one-line change on its own, but every amount the shop computes passes through it.",
11424
- risk: "A one-cent difference on .5 amounts shows up everywhere at once, including in totals other systems compare against.",
11425
- riskLevel: 3,
11426
- flags: ["public-contract"],
11427
- files: ["src/Shop.Orders/Pricing/Rounding.cs"]
12230
+
12231
+ // src/server/demo/demo-activity.ts
12232
+ var SWEEP_EVERY_MS = 3e4;
12233
+ var STEP_MS = 700;
12234
+ function createDemoActivity(scenario, emit) {
12235
+ const log = createActivityLog({ onChange: emit });
12236
+ const prCheck = log.schedule("pr-watch", "Pull request check", SWEEP_EVERY_MS);
12237
+ const idle = log.schedule("idle-sleep", "Idle Claude check", 5 * 6e4);
12238
+ idle.next(Date.now() + 4 * 6e4);
12239
+ log.start("jira", "Fetching your Jira issues").done(`${scenario.jira().length} issues`);
12240
+ log.start("pr-list", "Listing open pull requests").done(`${scenario.prs().length} open PRs in 3 repos`);
12241
+ const sleep = log.start("idle-sleep", "Looking for idle Claudes");
12242
+ sleep.done(`${scenario.list().length} Claudes running \xB7 none idle long enough`);
12243
+ let timers = [];
12244
+ const later = (ms, fn) => {
12245
+ const t = setTimeout(fn, ms);
12246
+ t.unref?.();
12247
+ timers.push(t);
12248
+ };
12249
+ const sweep = () => {
12250
+ prCheck.next(Date.now() + SWEEP_EVERY_MS);
12251
+ const sessions = scenario.list().filter((s) => !s.archivedAt);
12252
+ const run2 = log.start("pr-watch", "Checking pull requests");
12253
+ run2.progress(0, sessions.length);
12254
+ let prs = 0;
12255
+ let threads = 0;
12256
+ let failing = 0;
12257
+ sessions.forEach((s, i) => {
12258
+ later((i + 1) * STEP_MS, () => {
12259
+ for (const r of scenario.ci(s.id)?.repos ?? []) {
12260
+ if (r.pr?.state !== "OPEN") continue;
12261
+ prs++;
12262
+ threads += r.openThreads ?? 0;
12263
+ if (r.pr.checks === "fail") {
12264
+ failing++;
12265
+ run2.note(
12266
+ `${s.target} ${s.branch}: checks fail on #${r.pr.number} (${(r.pr.failing ?? []).map((f) => f.name).join(", ")}): already told its Claude`,
12267
+ { sessionId: s.id }
12268
+ );
12269
+ }
12270
+ if (r.openThreads)
12271
+ run2.note(`${s.target} ${s.branch}: ${r.openThreads} unresolved review threads on #${r.pr.number}`, { sessionId: s.id });
12272
+ }
12273
+ run2.progress(i + 1, sessions.length);
12274
+ if (i === sessions.length - 1) {
12275
+ const parts = [`${sessions.length} sessions`, `${prs} open PRs`];
12276
+ if (threads) parts.push(`${threads} unresolved review threads`);
12277
+ if (failing) parts.push(`${failing} failing`);
12278
+ run2.done(parts.join(" \xB7 "));
12279
+ }
12280
+ });
12281
+ });
12282
+ if (sessions.length === 0) run2.done("0 sessions");
12283
+ };
12284
+ later(3e3, sweep);
12285
+ prCheck.next(Date.now() + 3e3);
12286
+ const every = setInterval(sweep, SWEEP_EVERY_MS);
12287
+ every.unref?.();
12288
+ return {
12289
+ log,
12290
+ stop: () => {
12291
+ clearInterval(every);
12292
+ for (const t of timers) clearTimeout(t);
12293
+ timers = [];
11428
12294
  }
11429
- ],
11430
- fileSummaries: {
11431
- "src/Shop.Orders/Refunds/RefundHandler.cs": "New handler that loads the order, asks the payment provider to refund the amount, and adds it to the order\u2019s Refunded total before saving. It does not check the order exists or that the amount fits within what was paid.",
11432
- "src/Shop.Orders/Refunds/RefundValidator.cs": "New validator for refund requests: the amount must be greater than zero. It is the only check a request passes before money moves.",
11433
- "src/Shop.Orders/Pricing/Rounding.cs": "Cents now rounds half a cent away from zero (MidpointRounding.AwayFromZero) instead of to even. Every amount the shop computes passes through it.",
11434
- "src/Shop.Api/Controllers/RefundsController.cs": "New endpoint POST /orders/{orderId}/refunds that hands the request to the refund handler and returns the new refunded total. It is a new public route for API clients.",
11435
- "src/Shop.Data/Migrations/20261102_AddRefunds.cs": "Adds a non-null Refunded column to the Orders table with a default of 0, so existing orders read as not refunded.",
11436
- "src/Shop.Api/Program.cs": "Registers the refund handler for dependency injection, so the new controller can be constructed."
11437
- },
11438
- notes: [
11439
- {
11440
- path: "src/Shop.Orders/Refunds/RefundHandler.cs",
11441
- line: 6,
11442
- body: "Ivo\u2019s open question about locking the row is still not answered by the code: two refunds at once both read the old `Refunded`. A row version, or a check in the update, would settle it."
11443
- },
11444
- { path: "src/Shop.Orders/Refunds/RefundHandler.cs", line: 7, body: "Nothing stops refunding more than the order total." },
11445
- // A line the diff doesn't show: set aside with its text (the host would refuse the whole review for it).
11446
- { path: "src/Shop.Orders/Pricing/Rounding.cs", line: 90, body: "Is MidpointRounding used the same way in the invoice export?" }
11447
- ],
11448
- asserts: {
11449
- Refunds_part_of_an_order: "the refunded amount comes back \u2014 not that the payment provider was called",
11450
- Rejects_amounts_that_are_not_positive: "nothing yet: its body is empty"
11451
- }
11452
- });
11453
- var ALL_FILES = parseGitDiff(DIFF);
11454
- var SPLIT = splitIgnored(ALL_FILES);
11455
- var FILES = SPLIT.files;
11456
- function demoDiscussion(now = /* @__PURE__ */ new Date()) {
11457
- const ago = (h) => new Date(now.getTime() - h * 36e5).toISOString();
11458
- const url = (id) => `https://github.com/example/api/pull/231#discussion_${id}`;
12295
+ };
12296
+ }
12297
+
12298
+ // src/server/demo/demo-time.ts
12299
+ var SETTINGS2 = { ...DEFAULT_TIME_SETTINGS, gapTicket: "OPS-1", timeOffTicket: "HR-1" };
12300
+ var TITLES = {
12301
+ "PAY-12": "Export invoices as CSV",
12302
+ "PAY-15": "Invoice PDF",
12303
+ "SHOP-7": "Checkout in two steps",
12304
+ "WEB-3": "Price and brand filters in search",
12305
+ "WEB-9": "Login redirect loop",
12306
+ "OPS-1": "Meetings, reviews and support",
12307
+ "HR-1": "Time off"
12308
+ };
12309
+ var WORK = [
12310
+ { id: "demo-api-feat-invoice-export", label: "api \xB7 feat/invoice-export", key: "PAY-12" },
12311
+ { id: "demo-api-feat-invoice-pdf", label: "api \xB7 feat/invoice-pdf", key: "PAY-15" },
12312
+ { id: "demo-shop-feat-checkout-v2", label: "shop \xB7 feat/checkout-v2", key: "SHOP-7" },
12313
+ { id: "demo-web-feat-search-filters", label: "web \xB7 feat/search-filters", key: "WEB-3" },
12314
+ { id: "demo-web-fix-login-redirect", label: "web \xB7 fix/login-redirect", key: "WEB-9" }
12315
+ ];
12316
+ function evidenceFor(n) {
12317
+ const pick = [WORK[n % WORK.length], WORK[(n + 2) % WORK.length]];
11459
12318
  return {
11460
- at: now.toISOString(),
11461
- updatedAt: ago(2),
11462
- threads: [
11463
- {
11464
- id: "PRRT_demo1",
11465
- path: "src/Shop.Orders/Refunds/RefundHandler.cs",
11466
- line: 6,
11467
- side: "right",
11468
- outdated: false,
11469
- resolved: false,
11470
- url: url("r1"),
11471
- comments: [
11472
- {
11473
- author: "ivo",
11474
- association: "MEMBER",
11475
- body: "Is `FindAsync` enough here, or should this lock the order row? Two support agents refunding the same order is not unusual.",
11476
- at: ago(20),
11477
- url: url("r1")
11478
- },
11479
- {
11480
- author: "marta",
11481
- association: "CONTRIBUTOR",
11482
- body: "Good point. I will look at a row version on Orders.",
11483
- at: ago(18),
11484
- url: url("r1b")
11485
- }
11486
- ]
11487
- },
11488
- {
11489
- id: "PRRT_demo2",
11490
- path: "src/Shop.Orders/Refunds/RefundValidator.cs",
11491
- line: 3,
11492
- side: "right",
11493
- outdated: false,
11494
- resolved: true,
11495
- url: url("r2"),
11496
- comments: [
11497
- { author: "ana", association: "OWNER", body: "Should a refund of 0 be allowed?", at: ago(30), url: url("r2") },
11498
- { author: "marta", association: "CONTRIBUTOR", body: "No: changed to `GreaterThan(0)`.", at: ago(26), url: url("r2b") }
11499
- ]
11500
- },
11501
- {
11502
- id: "PRRT_demo3",
11503
- path: "src/Shop.Orders/Pricing/Rounding.cs",
11504
- line: null,
11505
- originalLine: 3,
11506
- side: "right",
11507
- outdated: true,
11508
- resolved: false,
11509
- url: url("r3"),
11510
- comments: [
11511
- {
11512
- author: "ivo",
11513
- association: "MEMBER",
11514
- body: "Why banker\u2019s rounding in the first place? The invoices round half up.",
11515
- at: ago(40),
11516
- url: url("r3")
11517
- }
11518
- ]
11519
- }
11520
- ],
11521
- reviews: [
11522
- { author: "ivo", association: "MEMBER", state: "commented", body: "", at: ago(20), url: url("v1") },
11523
- { author: "ana", association: "OWNER", state: "approved", body: "Fine once the row locking is sorted.", at: ago(25), url: url("v2") }
12319
+ sessions: [
12320
+ { sessionId: pick[0].id, label: pick[0].label, key: pick[0].key, minutes: 25 + n * 7 % 30 },
12321
+ { sessionId: pick[1].id, label: pick[1].label, key: pick[1].key, minutes: 8 + n * 5 % 15 },
12322
+ ...n % 3 === 0 ? [{ sessionId: "demo-api-chore-deps-update", label: "api \xB7 chore/deps-update", key: null, minutes: 12 }] : []
11524
12323
  ],
11525
- comments: [
12324
+ commits: [
11526
12325
  {
11527
- author: "lea",
11528
- association: "MEMBER",
11529
- body: "Can this go in before Friday\u2019s release? Support is waiting for it.",
11530
- at: ago(6),
11531
- url: "https://github.com/example/api/pull/231#issuecomment-1"
12326
+ repo: pick[0].id.split("-")[1],
12327
+ sha: `c0ffee${n}0`,
12328
+ subject: `${pick[0].key}: ${TITLES[pick[0].key].toLowerCase()}, part ${n % 4 + 1}`,
12329
+ keys: [pick[0].key]
11532
12330
  }
11533
- ]
12331
+ ],
12332
+ jira: n % 4 === 1 ? [{ key: "WEB-9", summary: TITLES["WEB-9"], what: "moved (now In review)" }] : []
11534
12333
  };
11535
12334
  }
11536
- function demoReview(now = /* @__PURE__ */ new Date()) {
11537
- return {
11538
- ...buildReview(
11539
- {
11540
- repo: "api",
11541
- number: 231,
11542
- title: "Refunds: partial refunds on paid orders",
11543
- url: "https://github.com/example/api/pull/231",
11544
- author: "marta",
11545
- branch: "feat/refunds",
11546
- base: "main",
11547
- headSha: "a1b2c3d"
11548
- },
11549
- FILES,
11550
- { whitespaceOnly: /* @__PURE__ */ new Set(), generated: /* @__PURE__ */ new Set() },
11551
- DEMO_ANSWER,
11552
- { now, ignored: SPLIT.ignored }
11553
- ),
11554
- mergeBase: "base",
11555
- preparedAt: now.toISOString(),
11556
- discussion: demoDiscussion(now)
12335
+ var DEMO_DAYS = 31;
12336
+ function createDemoTime(now) {
12337
+ const edits = /* @__PURE__ */ new Map();
12338
+ const record = (day) => {
12339
+ const today = localDay(now());
12340
+ if (day > today) return null;
12341
+ const all = daysBetween(addDays(today, -(DEMO_DAYS - 1)), today);
12342
+ const n = all.indexOf(day);
12343
+ const e = edits.get(day) ?? {};
12344
+ if (n < 0 && !e.edited && !e.dayOff) return null;
12345
+ return {
12346
+ day,
12347
+ evidence: n >= 0 && isWorkday(day, SETTINGS2) ? evidenceFor(n) : { sessions: [], commits: [], jira: [] },
12348
+ titles: TITLES,
12349
+ builtAt: new Date(now()).toISOString(),
12350
+ edited: e.edited ?? null,
12351
+ dayOff: e.dayOff ?? false,
12352
+ posted: e.posted ?? null
12353
+ };
11557
12354
  };
11558
- }
11559
- function waitingReview(now) {
11560
- const { discussion: _none, ...prepared } = demoReview(now);
11561
12355
  return {
11562
- ...prepared,
11563
- number: 236,
11564
- title: "Upgrade to .NET 10",
11565
- url: "https://github.com/example/api/pull/236",
11566
- author: "ivo",
11567
- status: "waiting",
11568
- why: "4812 changed lines: over the size limit (3000), so it waits for your click",
11569
- size: { files: 0, added: 4100, deleted: 712 },
11570
- files: [],
11571
- stories: [],
11572
- unstoried: [],
11573
- drafts: [],
11574
- tests: { list: [], counts: { added: 0, changed: 0, removed: 0, skipped: 0 }, gaps: [], covers: {}, unitOnlyForSchema: false },
11575
- asserts: {},
11576
- aiStep: "none"
11577
- };
11578
- }
11579
- var noSessions = {
11580
- liveOn: () => null,
11581
- create: (alias, branch) => ({ id: `${alias}-${branch}`, label: `${alias} \xB7 ${branch}` }),
11582
- note: () => void 0
11583
- };
11584
- function mountDemoReviews(app, broadcast, sessions = noSessions) {
11585
- const now = /* @__PURE__ */ new Date();
11586
- const reviews = /* @__PURE__ */ new Map([
11587
- ["api#231", demoReview(now)],
11588
- ["api#236", waitingReview(new Date(now.getTime() - 36e5))]
11589
- ]);
11590
- const modes = { api: "all", web: "asked", docs: "off" };
11591
- const settings = () => ({
11592
- projects: Object.entries(modes).map(([name, mode]) => ({ name, kind: "repo", mode, from: "repo" })),
11593
- maxPerDay: null,
11594
- maxLines: 3e3
11595
- });
11596
- const key = (repo, n) => `${repo}#${n}`;
11597
- const store = {
11598
- read: (rp, num3) => reviews.get(key(rp, String(num3))) ?? null,
11599
- update: (rp, num3, change) => {
11600
- const was = reviews.get(key(rp, String(num3)));
11601
- if (!was) return null;
11602
- const next = change(was);
11603
- reviews.set(key(rp, String(num3)), next);
11604
- return next;
12356
+ days: (from, to) => daysWireOf(
12357
+ from,
12358
+ to,
12359
+ SETTINGS2,
12360
+ daysBetween(from, to).map(record).filter((r) => !!r)
12361
+ ),
12362
+ month: (month) => {
12363
+ const today = localDay(now());
12364
+ const r = monthRange(month, today);
12365
+ const records = r ? daysBetween(r.from, r.to).map(record).filter((x) => !!x) : [];
12366
+ return { ...monthWireOf(month, today, SETTINGS2, records), gathering: false, gatherError: null, posting: { ready: true, why: null } };
11605
12367
  },
11606
- pid: 0,
11607
- bootedAt: () => 0,
11608
- alive: () => true
12368
+ day: (day) => ({ ...dayWireOf(day, SETTINGS2, record(day)), posting: { ready: true, why: null } }),
12369
+ update: (day, change) => {
12370
+ edits.set(day, { ...edits.get(day) ?? {}, ...change });
12371
+ return { ...dayWireOf(day, SETTINGS2, record(day)), posting: { ready: true, why: null } };
12372
+ },
12373
+ /** "Posting": what the day shows is now what Tempo has (nothing leaves the demo). */
12374
+ post: (day) => {
12375
+ const w = dayWireOf(day, SETTINGS2, record(day));
12376
+ const before = record(day)?.posted?.entries ?? [];
12377
+ const kept = w.entries.filter((e) => before.some((b) => b.key === e.key && b.hours === e.hours)).length;
12378
+ edits.set(day, { ...edits.get(day) ?? {}, posted: { at: new Date(now()).toISOString(), entries: w.entries, worklogs: [] } });
12379
+ return {
12380
+ posted: w.entries.length - kept,
12381
+ removed: before.length - kept,
12382
+ kept,
12383
+ coveredByHand: 0,
12384
+ otherByHand: 0,
12385
+ failed: [],
12386
+ day: { ...dayWireOf(day, SETTINGS2, record(day)), posting: { ready: true, why: null } }
12387
+ };
12388
+ },
12389
+ settings: SETTINGS2
11609
12390
  };
11610
- app.get(
11611
- "/api/reviews",
11612
- (c) => c.json({
11613
- reviews: [...reviews.values()].map(summaryOf).sort((a, b) => b.at.localeCompare(a.at)),
11614
- today: 1,
11615
- maxPerDay: null
11616
- })
11617
- );
11618
- app.get("/api/reviews/settings", (c) => c.json(settings()));
11619
- app.put("/api/reviews/settings", async (c) => {
11620
- const body = await c.req.json().catch(() => null);
11621
- if (!body || typeof body.project !== "string" || !isReviewMode(body.mode))
11622
- return c.json({ error: "expected {project, mode: all|asked|off}" }, 400);
11623
- modes[body.project] = body.mode;
11624
- broadcast("reviews-changed", { settings: true });
11625
- return c.json(settings());
11626
- });
11627
- app.get("/api/reviews/:repo/:number", (c) => {
11628
- const r = reviews.get(key(c.req.param("repo"), c.req.param("number")));
11629
- return r ? c.json(shownReview(store, r)) : c.json({ error: "no review of that PR" }, 404);
11630
- });
11631
- app.get("/api/reviews/:repo/:number/diff", (c) => {
11632
- const r = reviews.get(key(c.req.param("repo"), c.req.param("number")));
11633
- return r && r.status === "ready" ? c.json({ files: FILES }) : c.json({ error: "no prepared review of that PR" }, 404);
11634
- });
11635
- app.post("/api/reviews/:repo/:number", (c) => {
11636
- const k = key(c.req.param("repo"), c.req.param("number"));
11637
- const was = reviews.get(k);
11638
- if (!was) return c.json({ error: "isn't an open pull request" }, 409);
11639
- const r = { ...demoReview(/* @__PURE__ */ new Date()), number: was.number, title: was.title, url: was.url, author: was.author };
11640
- reviews.set(k, r);
11641
- broadcast("reviews-changed", { repo: r.repo, number: r.number });
11642
- return c.json(r);
11643
- });
11644
- app.post("/api/reviews/:repo/:number/discussion", (c) => {
11645
- const r = reviews.get(key(c.req.param("repo"), c.req.param("number")));
11646
- return r ? c.json(shownReview(store, r)) : c.json({ error: "no review of that PR" }, 404);
11647
- });
11648
- app.post("/api/reviews/:repo/:number/drafts", async (c) => {
11649
- const k = key(c.req.param("repo"), c.req.param("number"));
11650
- const r = reviews.get(k);
11651
- if (!r) return c.json({ error: "no review of that PR" }, 404);
11652
- const added = addDraft(r, await c.req.json().catch(() => null));
11653
- if ("error" in added) return c.json({ error: added.error }, 400);
11654
- reviews.set(k, added.review);
11655
- broadcast("reviews-changed", { repo: r.repo, number: r.number });
11656
- return c.json(added.review);
11657
- });
11658
- app.post("/api/reviews/:repo/:number/submit", async (c) => {
11659
- const repo = c.req.param("repo");
11660
- const n = /^\d+$/.test(c.req.param("number")) ? Number(c.req.param("number")) : null;
11661
- if (n === null) return c.json({ error: "no review of that PR" }, 404);
11662
- const input = await c.req.json().catch(() => null);
11663
- const out = await submitPrReview(
11664
- {
11665
- ...store,
11666
- repoPath: (alias) => alias === "api" ? "/demo/api" : null,
11667
- submit: async (_at, num3, review) => demoHostSubmit(reviews.get(key(repo, String(num3)))?.url ?? "", review)
11668
- },
11669
- repo,
11670
- n,
11671
- input
11672
- );
11673
- if (out.ok || out.review) broadcast("reviews-changed", { repo, number: n });
11674
- if (out.ok) return c.json(out.review);
11675
- return c.json({ error: out.error, ...out.review ? { review: out.review } : {} }, out.status);
11676
- });
11677
- app.post("/api/reviews/:repo/:number/fix-myself", async (c) => {
11678
- const repo = c.req.param("repo");
11679
- const n = /^\d+$/.test(c.req.param("number")) ? Number(c.req.param("number")) : null;
11680
- if (n === null || !reviews.get(key(repo, String(n)))) return c.json({ error: "no review of that PR" }, 404);
11681
- const input = await c.req.json().catch(() => null);
11682
- const out = await fixItMyself(
12391
+ }
12392
+
12393
+ // src/server/demo/demo-replies.ts
12394
+ function mountDemoReplies(app, scenario, emit) {
12395
+ const byId = /* @__PURE__ */ new Map();
12396
+ const deps = scenario.list().find((s) => s.branch === "chore/deps-update");
12397
+ if (deps) {
12398
+ const at = new Date(Date.now() - 20 * 6e4).toISOString();
12399
+ byId.set(deps.id, [
11683
12400
  {
11684
- read: store.read,
11685
- update: store.update,
11686
- lookUp: async (r) => r.fork ? { ok: false, error: "it comes from a fork: its branch isn't on origin" } : {
11687
- ok: true,
11688
- pr: { alias: r.repo, number: r.number, title: r.title, url: r.url, branch: r.branch, base: r.base, author: r.author }
11689
- },
11690
- liveSessionOn: (alias, branch) => sessions.liveOn(alias, branch),
11691
- create: async (alias, branch, name) => {
11692
- const s = sessions.create(alias, branch, name);
11693
- return { ok: true, sessionId: s.id, label: s.label };
12401
+ threadId: "PRRT_demo_zod",
12402
+ repo: "api",
12403
+ prNumber: 212,
12404
+ url: "https://github.com/example/api/pull/212#discussion_r1",
12405
+ where: "src/schema.ts:14",
12406
+ reviewer: "dana",
12407
+ excerpt: "zod 4 changed `.nonempty()` \u2014 does this still reject empty arrays?",
12408
+ body: "zod 4 changed `.nonempty()` \u2014 does this still reject empty arrays?\n\nIf not, this would do it:\n\n```suggestion\n items: z.array(Item).min(1),\n```",
12409
+ code: {
12410
+ hunk: '@@ -10,6 +10,6 @@ export const Order = z.object({\n id: z.string().uuid(),\n customer: Customer,\n currency: z.enum(["EUR", "USD"]),\n- items: z.array(Item).min(1),\n+ items: z.array(Item).nonempty(),\n note: z.string().optional(),',
12411
+ lines: 1
11694
12412
  },
11695
- // The demo's agent "starts" on its instruction: a note it answers, as every demo note.
11696
- start: async (id, prompt) => sessions.note(id, prompt),
11697
- note: async (id, body) => sessions.note(id, body)
12413
+ status: "draft",
12414
+ draft: "Yes \u2014 switched to `.min(1)`, which zod 4 keeps, and added a test for the empty case (a1b2c3d).",
12415
+ sentAt: at,
12416
+ draftedAt: at
11698
12417
  },
11699
- repo,
11700
- n,
11701
- input
11702
- );
11703
- if (!out.ok) return c.json({ error: out.error }, out.status);
11704
- broadcast("reviews-changed", { repo, number: n });
11705
- broadcast("sessions-changed", { ts: Date.now() });
11706
- const { ok: _ok, ...wire } = out;
11707
- return c.json(wire);
11708
- });
11709
- app.post("/api/reviews/:repo/:number/in-doubt", async (c) => {
11710
- const k = key(c.req.param("repo"), c.req.param("number"));
11711
- const r = reviews.get(k);
11712
- if (!r) return c.json({ error: "no review of that PR" }, 404);
11713
- const body = await c.req.json().catch(() => null);
11714
- if (!body || typeof body.went !== "boolean") return c.json({ error: "expected {went: true|false}" }, 400);
11715
- const out = settlePrReview(store, r.repo, r.number, body.went);
11716
- if (!out.ok) return c.json({ error: out.error }, out.status);
11717
- broadcast("reviews-changed", { repo: r.repo, number: r.number });
11718
- return c.json(out.review);
12418
+ {
12419
+ threadId: "PRRT_demo_lock",
12420
+ repo: "api",
12421
+ prNumber: 212,
12422
+ url: "https://github.com/example/api/pull/212#discussion_r2",
12423
+ where: "package-lock.json",
12424
+ reviewer: "copilot-pull-request-reviewer",
12425
+ excerpt: "The lockfile also bumps `express` to a new major version; was that intended?",
12426
+ status: "sent",
12427
+ draft: null,
12428
+ sentAt: at
12429
+ }
12430
+ ]);
12431
+ }
12432
+ const list = (id) => byId.get(id) ?? [];
12433
+ const find = (id, thread) => list(id).find((r) => r.threadId === thread);
12434
+ app.get("/api/sessions/:id/replies", (c) => c.json({ replies: list(c.req.param("id")), waiting: [] }));
12435
+ app.put("/api/sessions/:id/replies/:thread", async (c) => {
12436
+ const r = find(c.req.param("id"), c.req.param("thread"));
12437
+ const b = await c.req.json().catch(() => ({}));
12438
+ if (!r || typeof b.body !== "string" || !b.body.trim()) return c.json({ error: "unknown thread or empty reply" }, 400);
12439
+ Object.assign(r, { status: "draft", draft: b.body.trim(), draftedAt: (/* @__PURE__ */ new Date()).toISOString() });
12440
+ emit(c.req.param("id"));
12441
+ return c.json({ reply: r });
11719
12442
  });
11720
- app.delete("/api/reviews/:repo/:number/dropped", (c) => {
11721
- const k = key(c.req.param("repo"), c.req.param("number"));
11722
- const r = reviews.get(k);
11723
- if (!r) return c.json({ error: "no review of that PR" }, 404);
11724
- const next = clearDropped(r);
11725
- reviews.set(k, next);
11726
- broadcast("reviews-changed", { repo: r.repo, number: r.number });
11727
- return c.json(next);
12443
+ app.delete("/api/sessions/:id/replies/:thread", (c) => {
12444
+ const id = c.req.param("id");
12445
+ byId.set(
12446
+ id,
12447
+ list(id).filter((r) => r.threadId !== c.req.param("thread"))
12448
+ );
12449
+ emit(id);
12450
+ return c.json({ ok: true });
11728
12451
  });
11729
- app.delete("/api/reviews/:repo/:number/drafts/:id", (c) => {
11730
- const k = key(c.req.param("repo"), c.req.param("number"));
11731
- const r = reviews.get(k);
11732
- if (!r) return c.json({ error: "no review of that PR" }, 404);
11733
- const out = removeDraft(r, c.req.param("id"));
11734
- if ("error" in out) return c.json({ error: out.error }, out.status);
11735
- reviews.set(k, out.review);
11736
- broadcast("reviews-changed", { repo: r.repo, number: r.number });
11737
- return c.json(out.review);
12452
+ app.post("/api/sessions/:id/replies/:thread/post", async (c) => {
12453
+ const r = find(c.req.param("id"), c.req.param("thread"));
12454
+ const b = await c.req.json().catch(() => ({}));
12455
+ if (!r || typeof b.body !== "string" || !b.body.trim()) return c.json({ error: "unknown thread or empty reply" }, 400);
12456
+ Object.assign(r, {
12457
+ status: "posted",
12458
+ draft: b.body.trim(),
12459
+ postedAt: (/* @__PURE__ */ new Date()).toISOString(),
12460
+ postedUrl: r.url,
12461
+ resolved: b.resolve === true
12462
+ });
12463
+ emit(c.req.param("id"));
12464
+ return c.json({ ok: true, url: r.url, resolved: b.resolve === true });
11738
12465
  });
12466
+ app.post("/api/replies-changed", (c) => c.json({ ok: true }));
12467
+ return (id) => list(id).filter((r) => r.status === "draft").length;
11739
12468
  }
11740
12469
 
11741
12470
  // src/server/demo/demo-settings.ts
@@ -11763,13 +12492,13 @@ function createDemoSettings(repoPathOf) {
11763
12492
  };
11764
12493
  return {
11765
12494
  read,
11766
- async write(path20, value) {
11767
- const f = settingAt(path20);
11768
- if (!f) throw new SettingsError(`no setting ${path20}`, 404);
12495
+ async write(path22, value) {
12496
+ const f = settingAt(path22);
12497
+ if (!f) throw new SettingsError(`no setting ${path22}`, 404);
11769
12498
  const r = checkSetting(f, value);
11770
12499
  if (!r.ok) throw new SettingsError(`${f.label}: ${r.error}`);
11771
- if (r.value === null) delete values[path20];
11772
- else values[path20] = r.value;
12500
+ if (r.value === null) delete values[path22];
12501
+ else values[path22] = r.value;
11773
12502
  return read();
11774
12503
  },
11775
12504
  readRepo,
@@ -11951,6 +12680,101 @@ async function startDemoServer(opts) {
11951
12680
  });
11952
12681
  return c.json({ events });
11953
12682
  });
12683
+ const localReviews = /* @__PURE__ */ new Set();
12684
+ const demoLocalReview = (w) => {
12685
+ if (!localReviews.has(w.id)) return { status: "none", repo: null, repos: [] };
12686
+ const r = demoReview(new Date(scenario.clockMs()));
12687
+ return {
12688
+ status: "ready",
12689
+ repo: r.repo,
12690
+ repos: [r.repo],
12691
+ at: new Date(scenario.clockMs()).toISOString(),
12692
+ review: { ...r, number: 0, url: "", author: "you", title: `Local changes on ${w.branch}`, branch: w.branch, discussion: void 0 }
12693
+ };
12694
+ };
12695
+ app.get("/api/sessions/:id/review", (c) => {
12696
+ const w = scenario.list().find((x) => x.id === c.req.param("id"));
12697
+ return w ? c.json(demoLocalReview(w)) : notFound(c);
12698
+ });
12699
+ app.post("/api/sessions/:id/review", (c) => {
12700
+ const w = scenario.list().find((x) => x.id === c.req.param("id"));
12701
+ if (!w) return notFound(c);
12702
+ if (w.archivedAt) return c.json({ error: "It is archived: restore it first." }, 409);
12703
+ localReviews.add(w.id);
12704
+ broadcast({ event: "session-review-changed", data: { sessionId: w.id } });
12705
+ return c.json(demoLocalReview(w));
12706
+ });
12707
+ const demoDismissed = /* @__PURE__ */ new Map();
12708
+ app.post("/api/sessions/:id/review/dismiss", async (c) => {
12709
+ const w = scenario.list().find((x) => x.id === c.req.param("id"));
12710
+ if (!w) return notFound(c);
12711
+ const body = await json2(c);
12712
+ const review = demoLocalReview(w).review;
12713
+ if (typeof body.id !== "string" || !review?.drafts.some((d) => d.id === body.id))
12714
+ return c.json({ error: "no such note in the review prepared for it" }, 404);
12715
+ const set = demoDismissed.get(w.id) ?? /* @__PURE__ */ new Set();
12716
+ if (body.undo === true) set.delete(body.id);
12717
+ else set.add(body.id);
12718
+ demoDismissed.set(w.id, set);
12719
+ return c.json({ ...demoLocalReview(w), sent: [], dismissed: [...set] });
12720
+ });
12721
+ app.get("/api/sessions/:id/review/current", (c) => {
12722
+ const w = scenario.list().find((x) => x.id === c.req.param("id"));
12723
+ if (!w) return notFound(c);
12724
+ return localReviews.has(w.id) ? c.json({ current: true }) : c.json({ error: "no review of it is prepared" }, 404);
12725
+ });
12726
+ app.get("/api/sessions/:id/review/diff", (c) => {
12727
+ const w = scenario.list().find((x) => x.id === c.req.param("id"));
12728
+ if (!w) return notFound(c);
12729
+ return localReviews.has(w.id) ? c.json({ files: demoReviewFiles() }) : c.json({ error: "no review of it is prepared" }, 404);
12730
+ });
12731
+ app.post("/api/sessions/:id/review/send", async (c) => {
12732
+ const w = scenario.list().find((x) => x.id === c.req.param("id"));
12733
+ if (!w) return notFound(c);
12734
+ const review = demoLocalReview(w).review;
12735
+ if (!review) return c.json({ error: "no review of it is prepared" }, 409);
12736
+ const body = await json2(c);
12737
+ const ids = Array.isArray(body.ids) ? new Set(body.ids) : null;
12738
+ const sent = review.drafts.filter((d) => d.state === "draft" && (!ids || ids.has(d.id))).length;
12739
+ return sent ? c.json({ ok: true, sent }) : c.json({ error: "It has no notes to hand over." }, 409);
12740
+ });
12741
+ const stoppedProcs = /* @__PURE__ */ new Set();
12742
+ const demoProcesses = (id) => {
12743
+ const at = scenario.clockMs();
12744
+ const base = 4e3 + parseInt(id.slice(0, 4), 16) % 3e3;
12745
+ const all = [
12746
+ { pid: base, what: "claude --continue", memBytes: 760 * 1048576, startedAt: at - 3 * 36e5, agent: true },
12747
+ {
12748
+ pid: base + 1,
12749
+ what: "node \u2026/node_modules/vite/bin/vite.js --mode mock",
12750
+ memBytes: 1340 * 1048576,
12751
+ startedAt: at - 50 * 36e5,
12752
+ leftover: true
12753
+ },
12754
+ { pid: base + 2, what: "dotnet test", memBytes: 510 * 1048576, startedAt: at - 12 * 6e4 }
12755
+ ];
12756
+ const processes = all.filter((p) => !stoppedProcs.has(`${id}:${p.pid}`));
12757
+ return {
12758
+ at,
12759
+ totalBytes: processes.reduce((n, p) => n + (p.memBytes ?? 0), 0),
12760
+ leftovers: processes.filter((p) => p.leftover).length,
12761
+ processes
12762
+ };
12763
+ };
12764
+ app.get("/api/sessions/:id/processes", (c) => {
12765
+ const w = scenario.list().find((x) => x.id === c.req.param("id"));
12766
+ return w ? c.json(demoProcesses(w.id)) : notFound(c);
12767
+ });
12768
+ app.post("/api/sessions/:id/processes/stop", async (c) => {
12769
+ const w = scenario.list().find((x) => x.id === c.req.param("id"));
12770
+ if (!w) return notFound(c);
12771
+ const body = await json2(c);
12772
+ if (typeof body.pid !== "number") return c.json({ error: "expected {pid, startedAt}" }, 400);
12773
+ const why = stopRefusal(demoProcesses(w.id), body.pid, typeof body.startedAt === "number" ? body.startedAt : null);
12774
+ if (why) return c.json({ error: `Not stopped: ${why}.` }, 409);
12775
+ stoppedProcs.add(`${w.id}:${body.pid}`);
12776
+ return c.json(demoProcesses(w.id));
12777
+ });
11954
12778
  const notes = /* @__PURE__ */ new Map();
11955
12779
  app.get("/api/sessions/:id/note", (c) => {
11956
12780
  const w = scenario.list().find((x) => x.id === c.req.param("id"));
@@ -12591,6 +13415,18 @@ async function startDemoServer(opts) {
12591
13415
  scenario.accountsChanged();
12592
13416
  return c.json({ ok: true, installingSkills: false });
12593
13417
  });
13418
+ app.post("/api/accounts/:name/sessions", async (c) => {
13419
+ const to = c.req.param("name");
13420
+ const from = (await json2(c)).from;
13421
+ const rows = scenario.list().filter((w) => !w.archivedAt && (w.account ?? "default") !== to && (typeof from !== "string" || (w.account ?? "default") === from)).map((w) => {
13422
+ const r = scenario.switchAccount(w.id, to);
13423
+ const label = `${w.target} \xB7 ${w.branch}`;
13424
+ return r?.ok ? { id: w.id, label, outcome: r.body.outcome } : { id: w.id, label, error: r?.error ?? "unknown session" };
13425
+ });
13426
+ if (rows.length > 0 && rows.every((r) => "error" in r)) return c.json({ error: rows[0].error }, 409);
13427
+ scenario.accountsChanged();
13428
+ return c.json({ ok: true, summary: switchAllSummary(rows, to), sessions: rows });
13429
+ });
12594
13430
  app.post("/api/sessions/:id/account", async (c) => {
12595
13431
  const to = (await json2(c)).to;
12596
13432
  if (typeof to !== "string" || !to) return c.json({ error: "to is required" }, 400);
@@ -12793,8 +13629,8 @@ async function startDemoServer(opts) {
12793
13629
 
12794
13630
  // src/core/platform/web-life.ts
12795
13631
  import fs19 from "fs";
12796
- import path19 from "path";
12797
- var lifePath = () => path19.join(getConfigDir(), "web-life.json");
13632
+ import path21 from "path";
13633
+ var lifePath = () => path21.join(getConfigDir(), "web-life.json");
12798
13634
  function isLife(v) {
12799
13635
  const l = v;
12800
13636
  return !!l && typeof l === "object" && typeof l.pid === "number" && typeof l.version === "string" && typeof l.startedAt === "string" && typeof l.lastSeen === "string" && (l.ended === void 0 || typeof l.ended?.at === "string" && typeof l.ended?.how === "string");
@@ -13184,4 +14020,4 @@ export {
13184
14020
  stopExisting,
13185
14021
  webCommand
13186
14022
  };
13187
- //# sourceMappingURL=web-MPSYOYQ2.js.map
14023
+ //# sourceMappingURL=web-JBDK5WWW.js.map