issue-flow 0.18.0 → 0.20.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 (235) hide show
  1. package/README.md +43 -97
  2. package/dist/agent-4DHRKZ2Z.js +32 -0
  3. package/dist/{analyze-Q4ONIWRZ.js → analyze-UEJ2R3H5.js} +42 -41
  4. package/dist/analyze-UEJ2R3H5.js.map +1 -0
  5. package/dist/{apply-EEFPY2W4.js → apply-QDYNQMUX.js} +22 -24
  6. package/dist/apply-QDYNQMUX.js.map +1 -0
  7. package/dist/artifacts-AMJQJFFV.js +82 -0
  8. package/dist/artifacts-AMJQJFFV.js.map +1 -0
  9. package/dist/{bench-WWWXLTFH.js → bench-RNRXVEFK.js} +42 -42
  10. package/dist/{chunk-RYOUZ6EK.js → chunk-23VHVVKW.js} +3 -3
  11. package/dist/chunk-2EYLOS5I.js +99 -0
  12. package/dist/chunk-2EYLOS5I.js.map +1 -0
  13. package/dist/{chunk-C5TL7T4V.js → chunk-2YM2VH6R.js} +2 -2
  14. package/dist/{chunk-XUEMATVY.js → chunk-37O2FMAN.js} +28 -25
  15. package/dist/chunk-37O2FMAN.js.map +1 -0
  16. package/dist/chunk-44RF3VFG.js +717 -0
  17. package/dist/chunk-44RF3VFG.js.map +1 -0
  18. package/dist/chunk-6AOZCWN2.js +21 -0
  19. package/dist/chunk-6AOZCWN2.js.map +1 -0
  20. package/dist/chunk-7MJGYPHF.js +1571 -0
  21. package/dist/chunk-7MJGYPHF.js.map +1 -0
  22. package/dist/{chunk-SA6HXL4Y.js → chunk-7WBUEBD5.js} +9 -9
  23. package/dist/chunk-7WBUEBD5.js.map +1 -0
  24. package/dist/chunk-7ZZUSMBJ.js +35 -0
  25. package/dist/chunk-7ZZUSMBJ.js.map +1 -0
  26. package/dist/{chunk-QJ44VG5G.js → chunk-ADH6RJNX.js} +3 -3
  27. package/dist/{chunk-34OCSKOB.js → chunk-AKL5UPR6.js} +159 -114
  28. package/dist/chunk-AKL5UPR6.js.map +1 -0
  29. package/dist/{chunk-7F7LGMVO.js → chunk-BTBJ5UOO.js} +12 -12
  30. package/dist/{chunk-7F7LGMVO.js.map → chunk-BTBJ5UOO.js.map} +1 -1
  31. package/dist/{chunk-HOAHMERN.js → chunk-CLZ6RRZL.js} +21 -21
  32. package/dist/chunk-DBLXLKGU.js +1201 -0
  33. package/dist/chunk-DBLXLKGU.js.map +1 -0
  34. package/dist/{chunk-DUS5ZNKL.js → chunk-DIMDAYZS.js} +7 -6
  35. package/dist/chunk-DZ3DZ3EN.js +278 -0
  36. package/dist/chunk-DZ3DZ3EN.js.map +1 -0
  37. package/dist/{chunk-CRGIQFUQ.js → chunk-E2H3JV2E.js} +3 -1
  38. package/dist/chunk-E2H3JV2E.js.map +1 -0
  39. package/dist/{chunk-45WZ6GMI.js → chunk-EORDSKWZ.js} +17 -17
  40. package/dist/chunk-EORDSKWZ.js.map +1 -0
  41. package/dist/{chunk-LTH6XYZ3.js → chunk-EYKPWHT7.js} +40 -30
  42. package/dist/chunk-EYKPWHT7.js.map +1 -0
  43. package/dist/{chunk-OODXFCQV.js → chunk-FU2FQ4JE.js} +14 -16
  44. package/dist/{chunk-OODXFCQV.js.map → chunk-FU2FQ4JE.js.map} +1 -1
  45. package/dist/{chunk-V7QOIQYC.js → chunk-G442RDFX.js} +9 -23
  46. package/dist/{chunk-V7QOIQYC.js.map → chunk-G442RDFX.js.map} +1 -1
  47. package/dist/{chunk-QPGEFLMY.js → chunk-I64N6RL6.js} +7 -7
  48. package/dist/{chunk-KRAGAUKD.js → chunk-JBYXJOJJ.js} +201 -64
  49. package/dist/chunk-JBYXJOJJ.js.map +1 -0
  50. package/dist/{chunk-SOM4QA6C.js → chunk-JCR5C5A7.js} +93 -18
  51. package/dist/chunk-JCR5C5A7.js.map +1 -0
  52. package/dist/{chunk-RNFUVKC3.js → chunk-K5NM26NV.js} +30 -13
  53. package/dist/chunk-K5NM26NV.js.map +1 -0
  54. package/dist/{chunk-YVPZUN6X.js → chunk-KUA6KBBD.js} +335 -38
  55. package/dist/chunk-KUA6KBBD.js.map +1 -0
  56. package/dist/{chunk-KMCS76ZW.js → chunk-KUL64XUF.js} +44 -12
  57. package/dist/chunk-KUL64XUF.js.map +1 -0
  58. package/dist/{chunk-HAKDLR6N.js → chunk-MAJ6QDRL.js} +65 -78
  59. package/dist/chunk-MAJ6QDRL.js.map +1 -0
  60. package/dist/{chunk-DGRTJD5R.js → chunk-MML2G7IC.js} +7 -7
  61. package/dist/chunk-NP47HRX2.js +136 -0
  62. package/dist/chunk-NP47HRX2.js.map +1 -0
  63. package/dist/{chunk-3R27MJ5R.js → chunk-PFWHHYEO.js} +3 -3
  64. package/dist/{chunk-ECU7YO7S.js → chunk-PM5YWJYO.js} +22 -6
  65. package/dist/chunk-PM5YWJYO.js.map +1 -0
  66. package/dist/{chunk-E4I6MMHD.js → chunk-PXPTIXJF.js} +154 -101
  67. package/dist/chunk-PXPTIXJF.js.map +1 -0
  68. package/dist/{chunk-CWSQVHVV.js → chunk-QJHZ3HYJ.js} +248 -102
  69. package/dist/chunk-QJHZ3HYJ.js.map +1 -0
  70. package/dist/{chunk-LI35PIIS.js → chunk-RDPK7LYK.js} +20 -117
  71. package/dist/chunk-RDPK7LYK.js.map +1 -0
  72. package/dist/{chunk-PMLE7KAQ.js → chunk-RMIBLFG3.js} +30 -14
  73. package/dist/chunk-RMIBLFG3.js.map +1 -0
  74. package/dist/{chunk-62GVVZQO.js → chunk-T736DSZI.js} +32 -316
  75. package/dist/chunk-T736DSZI.js.map +1 -0
  76. package/dist/{chunk-TZYINKCC.js → chunk-UDUUUFQF.js} +57 -29
  77. package/dist/chunk-UDUUUFQF.js.map +1 -0
  78. package/dist/{chunk-NEWNXZ65.js → chunk-V7GETODQ.js} +36 -28
  79. package/dist/{chunk-NEWNXZ65.js.map → chunk-V7GETODQ.js.map} +1 -1
  80. package/dist/{chunk-PPZ3K4YM.js → chunk-VHQMMY2D.js} +2 -2
  81. package/dist/{chunk-ZVZMWNCG.js → chunk-VJ3PF6B7.js} +50 -16
  82. package/dist/chunk-VJ3PF6B7.js.map +1 -0
  83. package/dist/{chunk-L6HSKTQE.js → chunk-W7LZLJAF.js} +4 -4
  84. package/dist/{chunk-6K2LCFG6.js → chunk-WB4FA2EH.js} +70 -81
  85. package/dist/chunk-WB4FA2EH.js.map +1 -0
  86. package/dist/{chunk-LGHND47K.js → chunk-WQSGL5LX.js} +22 -16
  87. package/dist/chunk-WQSGL5LX.js.map +1 -0
  88. package/dist/{chunk-ICM463EO.js → chunk-XNK5UN2D.js} +5 -649
  89. package/dist/chunk-XNK5UN2D.js.map +1 -0
  90. package/dist/{chunk-7UMMFOL2.js → chunk-Y2KOWABB.js} +39 -24
  91. package/dist/chunk-Y2KOWABB.js.map +1 -0
  92. package/dist/{chunk-QF7VEL3M.js → chunk-YC24E66P.js} +568 -158
  93. package/dist/chunk-YC24E66P.js.map +1 -0
  94. package/dist/{chunk-EG2MGDP5.js → chunk-Z6RCKCVB.js} +52 -46
  95. package/dist/chunk-Z6RCKCVB.js.map +1 -0
  96. package/dist/{chunk-YUNBOUQH.js → chunk-ZPGNVBWY.js} +8 -8
  97. package/dist/cli.js +132 -62
  98. package/dist/cli.js.map +1 -1
  99. package/dist/compat-OJG76J4I.js +24 -0
  100. package/dist/{config-LEBZZCJP.js → config-6YTWPDBK.js} +20 -17
  101. package/dist/{contract-JH2WBIO6.js → contract-HWLFFL3F.js} +2 -2
  102. package/dist/{conventions-XOT6YW5L.js → conventions-5UPOTU42.js} +20 -16
  103. package/dist/{conventions-XOT6YW5L.js.map → conventions-5UPOTU42.js.map} +1 -1
  104. package/dist/db-QAZG4LQD.js +264 -0
  105. package/dist/db-QAZG4LQD.js.map +1 -0
  106. package/dist/diagnostics-YEFB42E5.js +25 -0
  107. package/dist/execute-QCT64D37.js +38 -0
  108. package/dist/{generate-JGW5JSKB.js → generate-QATMDKOK.js} +46 -43
  109. package/dist/generate-QATMDKOK.js.map +1 -0
  110. package/dist/{git-A2IP32PQ.js → git-XGOECXWG.js} +2 -3
  111. package/dist/history-NBPUZVGQ.js +101 -0
  112. package/dist/history-NBPUZVGQ.js.map +1 -0
  113. package/dist/init-4LB2YKWP.js +28 -0
  114. package/dist/{operations-O4FORFIH.js → operations-RUQP2Y2F.js} +78 -52
  115. package/dist/operations-RUQP2Y2F.js.map +1 -0
  116. package/dist/{permissions-G4XCAESF.js → permissions-QZPUUBSO.js} +5 -6
  117. package/dist/plan-2NMSHTMD.js +38 -0
  118. package/dist/{policy-U5NBFAO5.js → policy-RKKFF5A2.js} +17 -15
  119. package/dist/{policy-U5NBFAO5.js.map → policy-RKKFF5A2.js.map} +1 -1
  120. package/dist/pr-QKFO5HI3.js +42 -0
  121. package/dist/pr-review-H2BFD6F2.js +33 -0
  122. package/dist/prd-ET6XKYRS.js +37 -0
  123. package/dist/{ps-76L6ZAZL.js → ps-UIKSOUAQ.js} +26 -15
  124. package/dist/ps-UIKSOUAQ.js.map +1 -0
  125. package/dist/{recorder-2BAKPBRA.js → recorder-LOU3PTIE.js} +11 -7
  126. package/dist/registry-HV7M6MAH.js +17 -0
  127. package/dist/repository-RCRR6RDE.js +80 -0
  128. package/dist/resume-BWJZGBLZ.js +278 -0
  129. package/dist/resume-BWJZGBLZ.js.map +1 -0
  130. package/dist/review-2MTZLNSS.js +38 -0
  131. package/dist/routing-RM5ABHHD.js +35 -0
  132. package/dist/run-XMACQBRJ.js +61 -0
  133. package/dist/{session-publisher-KAJQRHNZ.js → session-publisher-Q5TNEZPX.js} +3 -3
  134. package/dist/session-publisher-Q5TNEZPX.js.map +1 -0
  135. package/dist/{state-manager-UPHO2EA2.js → state-manager-SRN4VJSX.js} +9 -4
  136. package/dist/state-manager-SRN4VJSX.js.map +1 -0
  137. package/dist/{usage-KTMYXAPF.js → usage-JOODVE5O.js} +69 -63
  138. package/dist/usage-JOODVE5O.js.map +1 -0
  139. package/dist/web-TLMWJ2BM.js +205 -0
  140. package/dist/web-TLMWJ2BM.js.map +1 -0
  141. package/package.json +22 -8
  142. package/prompts/analyze.md +16 -19
  143. package/prompts/execute.md +73 -144
  144. package/prompts/generate.md +23 -10
  145. package/prompts/plan.md +32 -60
  146. package/prompts/pr-review.md +58 -40
  147. package/prompts/pr.md +50 -16
  148. package/prompts/prd.md +26 -19
  149. package/prompts/review.md +41 -18
  150. package/web/public/app.js +111 -112
  151. package/dist/agent-HMZTXCRT.js +0 -30
  152. package/dist/analyze-Q4ONIWRZ.js.map +0 -1
  153. package/dist/apply-EEFPY2W4.js.map +0 -1
  154. package/dist/chunk-34OCSKOB.js.map +0 -1
  155. package/dist/chunk-45WZ6GMI.js.map +0 -1
  156. package/dist/chunk-62GVVZQO.js.map +0 -1
  157. package/dist/chunk-6K2LCFG6.js.map +0 -1
  158. package/dist/chunk-7UMMFOL2.js.map +0 -1
  159. package/dist/chunk-CRGIQFUQ.js.map +0 -1
  160. package/dist/chunk-CWSQVHVV.js.map +0 -1
  161. package/dist/chunk-E4I6MMHD.js.map +0 -1
  162. package/dist/chunk-ECU7YO7S.js.map +0 -1
  163. package/dist/chunk-EG2MGDP5.js.map +0 -1
  164. package/dist/chunk-HAKDLR6N.js.map +0 -1
  165. package/dist/chunk-ICM463EO.js.map +0 -1
  166. package/dist/chunk-KMCS76ZW.js.map +0 -1
  167. package/dist/chunk-KRAGAUKD.js.map +0 -1
  168. package/dist/chunk-LGHND47K.js.map +0 -1
  169. package/dist/chunk-LI35PIIS.js.map +0 -1
  170. package/dist/chunk-LTH6XYZ3.js.map +0 -1
  171. package/dist/chunk-PMLE7KAQ.js.map +0 -1
  172. package/dist/chunk-QF7VEL3M.js.map +0 -1
  173. package/dist/chunk-RNFUVKC3.js.map +0 -1
  174. package/dist/chunk-SA6HXL4Y.js.map +0 -1
  175. package/dist/chunk-SOM4QA6C.js.map +0 -1
  176. package/dist/chunk-TZYINKCC.js.map +0 -1
  177. package/dist/chunk-WCCZJL7W.js +0 -141
  178. package/dist/chunk-WCCZJL7W.js.map +0 -1
  179. package/dist/chunk-XEYH6ZZI.js +0 -289
  180. package/dist/chunk-XEYH6ZZI.js.map +0 -1
  181. package/dist/chunk-XUEMATVY.js.map +0 -1
  182. package/dist/chunk-XZUEFTUP.js +0 -243
  183. package/dist/chunk-XZUEFTUP.js.map +0 -1
  184. package/dist/chunk-YVPZUN6X.js.map +0 -1
  185. package/dist/chunk-ZVZMWNCG.js.map +0 -1
  186. package/dist/diagnostics-HTCWF7F4.js +0 -23
  187. package/dist/execute-LELOSR5T.js +0 -37
  188. package/dist/generate-JGW5JSKB.js.map +0 -1
  189. package/dist/init-TO6MUXO4.js +0 -26
  190. package/dist/operations-O4FORFIH.js.map +0 -1
  191. package/dist/plan-OXAT344Q.js +0 -34
  192. package/dist/pr-UZHNKKZC.js +0 -39
  193. package/dist/pr-review-Q4ACAWDM.js +0 -32
  194. package/dist/prd-6CYEMLDY.js +0 -33
  195. package/dist/ps-76L6ZAZL.js.map +0 -1
  196. package/dist/registry-XLHHYLTR.js +0 -15
  197. package/dist/resume-URCU6CIJ.js +0 -244
  198. package/dist/resume-URCU6CIJ.js.map +0 -1
  199. package/dist/review-LVZT2TMW.js +0 -35
  200. package/dist/routing-EK6RBZM4.js +0 -33
  201. package/dist/run-2RXJCJKT.js +0 -56
  202. package/dist/usage-KTMYXAPF.js.map +0 -1
  203. package/dist/web-B5UPHHR5.js +0 -172
  204. package/dist/web-B5UPHHR5.js.map +0 -1
  205. /package/dist/{agent-HMZTXCRT.js.map → agent-4DHRKZ2Z.js.map} +0 -0
  206. /package/dist/{bench-WWWXLTFH.js.map → bench-RNRXVEFK.js.map} +0 -0
  207. /package/dist/{chunk-RYOUZ6EK.js.map → chunk-23VHVVKW.js.map} +0 -0
  208. /package/dist/{chunk-C5TL7T4V.js.map → chunk-2YM2VH6R.js.map} +0 -0
  209. /package/dist/{chunk-QJ44VG5G.js.map → chunk-ADH6RJNX.js.map} +0 -0
  210. /package/dist/{chunk-HOAHMERN.js.map → chunk-CLZ6RRZL.js.map} +0 -0
  211. /package/dist/{chunk-DUS5ZNKL.js.map → chunk-DIMDAYZS.js.map} +0 -0
  212. /package/dist/{chunk-QPGEFLMY.js.map → chunk-I64N6RL6.js.map} +0 -0
  213. /package/dist/{chunk-DGRTJD5R.js.map → chunk-MML2G7IC.js.map} +0 -0
  214. /package/dist/{chunk-3R27MJ5R.js.map → chunk-PFWHHYEO.js.map} +0 -0
  215. /package/dist/{chunk-PPZ3K4YM.js.map → chunk-VHQMMY2D.js.map} +0 -0
  216. /package/dist/{chunk-L6HSKTQE.js.map → chunk-W7LZLJAF.js.map} +0 -0
  217. /package/dist/{chunk-YUNBOUQH.js.map → chunk-ZPGNVBWY.js.map} +0 -0
  218. /package/dist/{config-LEBZZCJP.js.map → compat-OJG76J4I.js.map} +0 -0
  219. /package/dist/{contract-JH2WBIO6.js.map → config-6YTWPDBK.js.map} +0 -0
  220. /package/dist/{diagnostics-HTCWF7F4.js.map → contract-HWLFFL3F.js.map} +0 -0
  221. /package/dist/{execute-LELOSR5T.js.map → diagnostics-YEFB42E5.js.map} +0 -0
  222. /package/dist/{git-A2IP32PQ.js.map → execute-QCT64D37.js.map} +0 -0
  223. /package/dist/{init-TO6MUXO4.js.map → git-XGOECXWG.js.map} +0 -0
  224. /package/dist/{permissions-G4XCAESF.js.map → init-4LB2YKWP.js.map} +0 -0
  225. /package/dist/{plan-OXAT344Q.js.map → permissions-QZPUUBSO.js.map} +0 -0
  226. /package/dist/{pr-UZHNKKZC.js.map → plan-2NMSHTMD.js.map} +0 -0
  227. /package/dist/{pr-review-Q4ACAWDM.js.map → pr-QKFO5HI3.js.map} +0 -0
  228. /package/dist/{prd-6CYEMLDY.js.map → pr-review-H2BFD6F2.js.map} +0 -0
  229. /package/dist/{recorder-2BAKPBRA.js.map → prd-ET6XKYRS.js.map} +0 -0
  230. /package/dist/{registry-XLHHYLTR.js.map → recorder-LOU3PTIE.js.map} +0 -0
  231. /package/dist/{review-LVZT2TMW.js.map → registry-HV7M6MAH.js.map} +0 -0
  232. /package/dist/{routing-EK6RBZM4.js.map → repository-RCRR6RDE.js.map} +0 -0
  233. /package/dist/{run-2RXJCJKT.js.map → review-2MTZLNSS.js.map} +0 -0
  234. /package/dist/{session-publisher-KAJQRHNZ.js.map → routing-RM5ABHHD.js.map} +0 -0
  235. /package/dist/{state-manager-UPHO2EA2.js.map → run-XMACQBRJ.js.map} +0 -0
@@ -1,244 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- runPipeline
4
- } from "./chunk-CWSQVHVV.js";
5
- import "./chunk-QJ44VG5G.js";
6
- import "./chunk-OODXFCQV.js";
7
- import "./chunk-LTH6XYZ3.js";
8
- import "./chunk-YUNBOUQH.js";
9
- import "./chunk-XUEMATVY.js";
10
- import "./chunk-EG2MGDP5.js";
11
- import {
12
- PIPELINE_PHASES,
13
- PipelineManager,
14
- loadExecutionPlan,
15
- nextQueueIssue
16
- } from "./chunk-7UMMFOL2.js";
17
- import "./chunk-PMLE7KAQ.js";
18
- import "./chunk-KRAGAUKD.js";
19
- import "./chunk-NEWNXZ65.js";
20
- import "./chunk-ECU7YO7S.js";
21
- import "./chunk-E4I6MMHD.js";
22
- import "./chunk-CRGIQFUQ.js";
23
- import "./chunk-L6HSKTQE.js";
24
- import "./chunk-45WZ6GMI.js";
25
- import "./chunk-HOAHMERN.js";
26
- import "./chunk-34OCSKOB.js";
27
- import "./chunk-V7QOIQYC.js";
28
- import "./chunk-SA6HXL4Y.js";
29
- import "./chunk-62GVVZQO.js";
30
- import "./chunk-KMMASOA6.js";
31
- import "./chunk-KMCS76ZW.js";
32
- import "./chunk-7F7LGMVO.js";
33
- import "./chunk-TZYINKCC.js";
34
- import {
35
- parseJournal
36
- } from "./chunk-WCCZJL7W.js";
37
- import "./chunk-DGRTJD5R.js";
38
- import "./chunk-ZVZMWNCG.js";
39
- import "./chunk-C5TL7T4V.js";
40
- import "./chunk-3D4A4B46.js";
41
- import "./chunk-LGHND47K.js";
42
- import "./chunk-QF7VEL3M.js";
43
- import {
44
- resolveProjectPaths
45
- } from "./chunk-LI35PIIS.js";
46
- import {
47
- printError,
48
- printInfo,
49
- printWarning
50
- } from "./chunk-XZUEFTUP.js";
51
- import "./chunk-QPGEFLMY.js";
52
- import {
53
- QUEUES_DIR_NAME,
54
- getIssuePaths
55
- } from "./chunk-HAKDLR6N.js";
56
- import {
57
- describePreflight,
58
- preflightRepository
59
- } from "./chunk-YVPZUN6X.js";
60
- import "./chunk-DUS5ZNKL.js";
61
- import "./chunk-6K2LCFG6.js";
62
- import "./chunk-PPZ3K4YM.js";
63
- import {
64
- loadTaskPlan
65
- } from "./chunk-SOM4QA6C.js";
66
- import {
67
- acquireRunLock,
68
- describeRunLockOwner
69
- } from "./chunk-ICM463EO.js";
70
- import "./chunk-XEYH6ZZI.js";
71
- import "./chunk-P3LRUNC6.js";
72
- import "./chunk-3R27MJ5R.js";
73
-
74
- // src/commands/resume.ts
75
- import { readdir, readFile } from "fs/promises";
76
- import { join } from "path";
77
- async function runResume(issue, options = {}) {
78
- const mode = options.mode ?? "auto";
79
- let project;
80
- try {
81
- project = await resolveProjectPaths();
82
- } catch (err) {
83
- printError(`Cannot resume: ${err instanceof Error ? err.message : String(err)}`);
84
- return 1;
85
- }
86
- const acquisition = await acquireRunLock(project.runLockFile, { target: issue ?? "resume" });
87
- if (!acquisition.ok) {
88
- printError(
89
- `Another issue-flow run owns this project: ${describeRunLockOwner(acquisition.owner)}.`
90
- );
91
- printInfo("Wait for it to finish, or stop that process before resuming.");
92
- return 1;
93
- }
94
- const handle = acquisition.handle;
95
- if (handle.reclaimedFrom !== null) {
96
- printWarning(
97
- `Taking over an interrupted run: ${describeRunLockOwner(handle.reclaimedFrom)}. Its lock was stale.`
98
- );
99
- }
100
- try {
101
- const targets = await findTargets(project, issue, options.all === true);
102
- if (targets.length === 0) {
103
- printInfo(
104
- issue === void 0 ? "Nothing to resume: no issue in this project has an unfinished pipeline." : `Nothing to resume: issue #${issue} has no task plan in this project.`
105
- );
106
- return 0;
107
- }
108
- for (const target of targets) {
109
- const code = await resumeOne(target, mode);
110
- if (code !== 0) return code;
111
- }
112
- return 0;
113
- } finally {
114
- await handle.release();
115
- }
116
- }
117
- async function resumeOne(target, mode) {
118
- const phases = activePhases(target.plan);
119
- const manager = new PipelineManager(target.plan, target.tasksFile, phases);
120
- const next = manager.getNextPhase();
121
- if (next === null) {
122
- printInfo(`Issue #${target.issue} has every phase complete; nothing to resume.`);
123
- return 0;
124
- }
125
- const interrupted = await lastUnfinishedPhase(target);
126
- if (interrupted !== null) {
127
- printInfo(`Issue #${target.issue} was interrupted during the '${interrupted}' phase.`);
128
- }
129
- const sameWork = interrupted === next;
130
- const preflight = await preflightRepository({
131
- expectedBranch: target.plan.noBranch === true ? null : target.plan.branchName,
132
- intent: sameWork ? "resume-same-phase" : "new-phase"
133
- });
134
- if (!preflight.ok) {
135
- printError(`Cannot resume issue #${target.issue}: the repository needs attention first.`);
136
- for (const line of describePreflight(preflight)) {
137
- printError(line);
138
- }
139
- return 1;
140
- }
141
- printInfo(`Resuming issue #${target.issue} from the '${next}' phase.`);
142
- return runPipeline(target.issue, mode, next, void 0, void 0, { only: true });
143
- }
144
- function activePhases(plan) {
145
- const base = plan.noBranch === true ? PIPELINE_PHASES.filter((phase) => phase !== "pr") : [...PIPELINE_PHASES];
146
- return plan.prReview?.enabled === true ? [...base, "pr-review"] : base;
147
- }
148
- async function lastUnfinishedPhase(target) {
149
- const content = `${await readIfPresent(target.rotatedEventsFile)}${await readIfPresent(target.eventsFile)}`;
150
- if (content === "") return null;
151
- const open = [];
152
- for (const entry of parseJournal(content)) {
153
- const event = entry.event;
154
- if (event.type === "phase:start") {
155
- open.push(event.phase);
156
- } else if (event.type === "phase:end") {
157
- const index = open.lastIndexOf(event.phase);
158
- if (index >= 0) open.splice(index, 1);
159
- }
160
- }
161
- return open.at(-1) ?? null;
162
- }
163
- async function readIfPresent(path) {
164
- try {
165
- return await readFile(path, "utf-8");
166
- } catch {
167
- return "";
168
- }
169
- }
170
- async function findTargets(project, issue, all) {
171
- if (issue !== void 0) {
172
- const target = await loadTarget(project.projectId, issue);
173
- return target === null ? [] : [target];
174
- }
175
- const queued = await queueTarget(project);
176
- if (queued !== null && !all) return [queued];
177
- const unfinished = await unfinishedTargets(project);
178
- if (all) return unfinished;
179
- return unfinished.slice(0, 1);
180
- }
181
- async function queueTarget(project) {
182
- const queuesDir = join(project.projectDir, QUEUES_DIR_NAME);
183
- let entries;
184
- try {
185
- entries = await readdir(queuesDir);
186
- } catch {
187
- return null;
188
- }
189
- for (const entry of entries) {
190
- const plan = await loadExecutionPlan(join(queuesDir, entry, "execution-plan.json"));
191
- if (plan === null) continue;
192
- const next = nextQueueIssue(plan);
193
- if (next === null) continue;
194
- const target = await loadTarget(project.projectId, next.id);
195
- if (target !== null) return target;
196
- }
197
- return null;
198
- }
199
- async function unfinishedTargets(project) {
200
- let ids;
201
- try {
202
- ids = await readdir(project.issuesDir);
203
- } catch {
204
- return [];
205
- }
206
- const targets = [];
207
- for (const id of ids) {
208
- const target = await loadTarget(project.projectId, id);
209
- if (target === null) continue;
210
- if (target.plan.issueStatus === "completed") continue;
211
- const manager = new PipelineManager(target.plan, target.tasksFile, activePhases(target.plan));
212
- if (manager.getNextPhase() === null) continue;
213
- targets.push(target);
214
- }
215
- return targets.sort((a, b) => attemptedAt(b.plan) - attemptedAt(a.plan));
216
- }
217
- function attemptedAt(plan) {
218
- const at = Date.parse(plan.lastAttemptAt ?? "");
219
- return Number.isNaN(at) ? 0 : at;
220
- }
221
- async function loadTarget(projectId, issue) {
222
- let paths;
223
- try {
224
- paths = getIssuePaths(projectId, issue);
225
- } catch {
226
- return null;
227
- }
228
- try {
229
- const plan = await loadTaskPlan(paths.tasksFile);
230
- return {
231
- issue,
232
- plan,
233
- tasksFile: paths.tasksFile,
234
- eventsFile: paths.eventsFile,
235
- rotatedEventsFile: paths.rotatedEventsFile
236
- };
237
- } catch {
238
- return null;
239
- }
240
- }
241
- export {
242
- runResume
243
- };
244
- //# sourceMappingURL=resume-URCU6CIJ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/commands/resume.ts"],"sourcesContent":["import { readdir, readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { parseJournal } from '../core/journal.js';\nimport { PIPELINE_PHASES, PipelineManager, type PipelinePhase } from '../core/pipeline.js';\nimport { loadTaskPlan } from '../core/state-manager.js';\nimport { loadExecutionPlan, nextQueueIssue } from '../execution/plan.js';\nimport { acquireRunLock, describeRunLockOwner, type RunLockHandle } from '../storage/lock.js';\nimport { getIssuePaths, QUEUES_DIR_NAME } from '../storage/paths.js';\nimport { resolveProjectPaths } from '../storage/resolve.js';\nimport type { TaskPlan } from '../types.js';\nimport { printError, printInfo, printWarning } from '../ui/logger.js';\nimport { describePreflight, preflightRepository } from '../utils/git.js';\nimport { runPipeline } from './run.js';\n\n/**\n * `issue-flow resume` — explicit recovery.\n *\n * Resumption already worked before this command existed, but only *implicitly*:\n * the user re-ran the same `run` and the pipeline happened to pick up where it\n * left off, because `PipelineManager` skips the phases already marked complete\n * and `nextQueueIssue()` treats a stale `in_progress` as \"do this one first\".\n * That is a coincidence of two mechanisms, not a contract — nothing said what\n * had been interrupted, nothing checked whether the repository was still in a\n * state to continue, and nothing distinguished \"carry on\" from \"start over\".\n *\n * This command makes each of those steps explicit, in this order:\n *\n * 1. **ownership** — a live owner refuses, a dead one is taken over;\n * 2. **plans** — `execution-plan.json` for a queue, `tasks.json` for an issue;\n * 3. **the journal** — the last `phase:start` with no `phase:end` is what was\n * running when the process died, which is the one fact no snapshot keeps;\n * 4. **the preflight** — the repository is described, and a state a human has to\n * settle stops the resume instead of being repaired;\n * 5. **the phase** — `PipelineManager.getNextPhase()`, the same answer `run`\n * has always used, now stated out loud before anything runs.\n *\n * `run` is untouched: its auto-resume still works exactly as it did.\n */\n\nexport interface ResumeOptions {\n /** Resume every unfinished issue of the project, not just one. */\n all?: boolean;\n /** Execution mode handed to the pipeline. Same values as `run`. */\n mode?: string;\n}\n\ninterface ResumeTarget {\n issue: string;\n plan: TaskPlan;\n tasksFile: string;\n eventsFile: string;\n rotatedEventsFile: string;\n}\n\nexport async function runResume(issue?: string, options: ResumeOptions = {}): Promise<number> {\n const mode = options.mode ?? 'auto';\n\n let project: Awaited<ReturnType<typeof resolveProjectPaths>>;\n try {\n project = await resolveProjectPaths();\n } catch (err) {\n printError(`Cannot resume: ${err instanceof Error ? err.message : String(err)}`);\n return 1;\n }\n\n // 1. Ownership, before reading anything else: a resume that runs beside a\n // live owner is the collision this whole layer exists to prevent.\n const acquisition = await acquireRunLock(project.runLockFile, { target: issue ?? 'resume' });\n if (!acquisition.ok) {\n printError(\n `Another issue-flow run owns this project: ${describeRunLockOwner(acquisition.owner)}.`,\n );\n printInfo('Wait for it to finish, or stop that process before resuming.');\n return 1;\n }\n const handle: RunLockHandle = acquisition.handle;\n if (handle.reclaimedFrom !== null) {\n printWarning(\n `Taking over an interrupted run: ${describeRunLockOwner(handle.reclaimedFrom)}. Its lock was stale.`,\n );\n }\n\n try {\n // 2. What is there to resume.\n const targets = await findTargets(project, issue, options.all === true);\n if (targets.length === 0) {\n printInfo(\n issue === undefined\n ? 'Nothing to resume: no issue in this project has an unfinished pipeline.'\n : `Nothing to resume: issue #${issue} has no task plan in this project.`,\n );\n return 0;\n }\n\n for (const target of targets) {\n const code = await resumeOne(target, mode);\n if (code !== 0) return code;\n }\n return 0;\n } finally {\n await handle.release();\n }\n}\n\nasync function resumeOne(target: ResumeTarget, mode: string): Promise<number> {\n const phases = activePhases(target.plan);\n const manager = new PipelineManager(target.plan, target.tasksFile, phases);\n const next = manager.getNextPhase();\n\n if (next === null) {\n printInfo(`Issue #${target.issue} has every phase complete; nothing to resume.`);\n return 0;\n }\n\n // 3. What was running when the process died. The snapshot cannot answer this\n // — it only knows the phase failed or never ended — so the journal does.\n const interrupted = await lastUnfinishedPhase(target);\n if (interrupted !== null) {\n printInfo(`Issue #${target.issue} was interrupted during the '${interrupted}' phase.`);\n }\n\n // 4. The repository, described and never repaired. Continuing the very phase\n // that was interrupted is the one case where uncommitted work is expected;\n // anything else would be carrying changes into work they do not belong to.\n const sameWork = interrupted === next;\n const preflight = await preflightRepository({\n expectedBranch: target.plan.noBranch === true ? null : target.plan.branchName,\n intent: sameWork ? 'resume-same-phase' : 'new-phase',\n });\n if (!preflight.ok) {\n printError(`Cannot resume issue #${target.issue}: the repository needs attention first.`);\n for (const line of describePreflight(preflight)) {\n printError(line);\n }\n return 1;\n }\n\n // 5. The phase, stated before anything runs.\n printInfo(`Resuming issue #${target.issue} from the '${next}' phase.`);\n return runPipeline(target.issue, mode, next, undefined, undefined, { only: true });\n}\n\n/** The phase set this plan's pipeline actually has, so `pr-review` is honoured. */\nfunction activePhases(plan: TaskPlan): readonly PipelinePhase[] {\n const base =\n plan.noBranch === true\n ? PIPELINE_PHASES.filter((phase) => phase !== 'pr')\n : [...PIPELINE_PHASES];\n return plan.prReview?.enabled === true ? [...base, 'pr-review'] : base;\n}\n\n/**\n * The phase the journal shows as started and never ended.\n *\n * Both generations are read, oldest first, because a run long enough to rotate\n * its journal is exactly the kind that gets interrupted. A missing or\n * unreadable journal answers `null`: the resume continues from the plan, which\n * is what it did before a journal existed.\n */\nasync function lastUnfinishedPhase(target: ResumeTarget): Promise<string | null> {\n const content = `${await readIfPresent(target.rotatedEventsFile)}${await readIfPresent(target.eventsFile)}`;\n if (content === '') return null;\n\n const open: string[] = [];\n for (const entry of parseJournal(content)) {\n const event = entry.event;\n if (event.type === 'phase:start') {\n open.push(event.phase);\n } else if (event.type === 'phase:end') {\n const index = open.lastIndexOf(event.phase);\n if (index >= 0) open.splice(index, 1);\n }\n }\n return open.at(-1) ?? null;\n}\n\nasync function readIfPresent(path: string): Promise<string> {\n try {\n return await readFile(path, 'utf-8');\n } catch {\n return '';\n }\n}\n\n/**\n * Which issues to resume.\n *\n * A named issue is taken at its word. Without one, the queue decides when there\n * is a queue — `nextQueueIssue()` is already the project's answer to \"which one\n * first\" — and otherwise the unfinished issues are ordered by when they were\n * last attempted, so `resume` alone picks up the most recent work.\n */\nasync function findTargets(\n project: Awaited<ReturnType<typeof resolveProjectPaths>>,\n issue: string | undefined,\n all: boolean,\n): Promise<ResumeTarget[]> {\n if (issue !== undefined) {\n const target = await loadTarget(project.projectId, issue);\n return target === null ? [] : [target];\n }\n\n const queued = await queueTarget(project);\n if (queued !== null && !all) return [queued];\n\n const unfinished = await unfinishedTargets(project);\n if (all) return unfinished;\n return unfinished.slice(0, 1);\n}\n\n/** The issue a queue would hand out next, when this project has a queue. */\nasync function queueTarget(\n project: Awaited<ReturnType<typeof resolveProjectPaths>>,\n): Promise<ResumeTarget | null> {\n const queuesDir = join(project.projectDir, QUEUES_DIR_NAME);\n let entries: string[];\n try {\n entries = await readdir(queuesDir);\n } catch {\n return null;\n }\n\n for (const entry of entries) {\n const plan = await loadExecutionPlan(join(queuesDir, entry, 'execution-plan.json'));\n if (plan === null) continue;\n const next = nextQueueIssue(plan);\n if (next === null) continue;\n const target = await loadTarget(project.projectId, next.id);\n if (target !== null) return target;\n }\n return null;\n}\n\n/** Every issue whose plan is not finished, most recently attempted first. */\nasync function unfinishedTargets(\n project: Awaited<ReturnType<typeof resolveProjectPaths>>,\n): Promise<ResumeTarget[]> {\n let ids: string[];\n try {\n ids = await readdir(project.issuesDir);\n } catch {\n return [];\n }\n\n const targets: ResumeTarget[] = [];\n for (const id of ids) {\n const target = await loadTarget(project.projectId, id);\n if (target === null) continue;\n if (target.plan.issueStatus === 'completed') continue;\n const manager = new PipelineManager(target.plan, target.tasksFile, activePhases(target.plan));\n if (manager.getNextPhase() === null) continue;\n targets.push(target);\n }\n\n return targets.sort((a, b) => attemptedAt(b.plan) - attemptedAt(a.plan));\n}\n\nfunction attemptedAt(plan: TaskPlan): number {\n const at = Date.parse(plan.lastAttemptAt ?? '');\n return Number.isNaN(at) ? 0 : at;\n}\n\nasync function loadTarget(projectId: string, issue: string): Promise<ResumeTarget | null> {\n let paths: ReturnType<typeof getIssuePaths>;\n try {\n paths = getIssuePaths(projectId, issue);\n } catch {\n // Not a usable issue identifier — a stray file in `issues/`, for instance.\n return null;\n }\n\n try {\n const plan = await loadTaskPlan(paths.tasksFile);\n return {\n issue,\n plan,\n tasksFile: paths.tasksFile,\n eventsFile: paths.eventsFile,\n rotatedEventsFile: paths.rotatedEventsFile,\n };\n } catch {\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,gBAAgB;AAClC,SAAS,YAAY;AAqDrB,eAAsB,UAAU,OAAgB,UAAyB,CAAC,GAAoB;AAC5F,QAAM,OAAO,QAAQ,QAAQ;AAE7B,MAAI;AACJ,MAAI;AACF,cAAU,MAAM,oBAAoB;AAAA,EACtC,SAAS,KAAK;AACZ,eAAW,kBAAkB,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC,EAAE;AAC/E,WAAO;AAAA,EACT;AAIA,QAAM,cAAc,MAAM,eAAe,QAAQ,aAAa,EAAE,QAAQ,SAAS,SAAS,CAAC;AAC3F,MAAI,CAAC,YAAY,IAAI;AACnB;AAAA,MACE,6CAA6C,qBAAqB,YAAY,KAAK,CAAC;AAAA,IACtF;AACA,cAAU,8DAA8D;AACxE,WAAO;AAAA,EACT;AACA,QAAM,SAAwB,YAAY;AAC1C,MAAI,OAAO,kBAAkB,MAAM;AACjC;AAAA,MACE,mCAAmC,qBAAqB,OAAO,aAAa,CAAC;AAAA,IAC/E;AAAA,EACF;AAEA,MAAI;AAEF,UAAM,UAAU,MAAM,YAAY,SAAS,OAAO,QAAQ,QAAQ,IAAI;AACtE,QAAI,QAAQ,WAAW,GAAG;AACxB;AAAA,QACE,UAAU,SACN,4EACA,6BAA6B,KAAK;AAAA,MACxC;AACA,aAAO;AAAA,IACT;AAEA,eAAW,UAAU,SAAS;AAC5B,YAAM,OAAO,MAAM,UAAU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G2MGDP5.js";
5
- import "./chunk-ECU7YO7S.js";
6
- import "./chunk-E4I6MMHD.js";
7
- import "./chunk-L6HSKTQE.js";
8
- import "./chunk-SA6HXL4Y.js";
9
- import "./chunk-62GVVZQO.js";
10
- import "./chunk-KMMASOA6.js";
11
- import "./chunk-KMCS76ZW.js";
12
- import "./chunk-7F7LGMVO.js";
13
- import "./chunk-TZYINKCC.js";
14
- import "./chunk-WCCZJL7W.js";
15
- import "./chunk-DGRTJD5R.js";
16
- import "./chunk-ZVZMWNCG.js";
17
- import "./chunk-LGHND47K.js";
18
- import "./chunk-QF7VEL3M.js";
19
- import "./chunk-LI35PIIS.js";
20
- import "./chunk-XZUEFTUP.js";
21
- import "./chunk-QPGEFLMY.js";
22
- import "./chunk-HAKDLR6N.js";
23
- import "./chunk-YVPZUN6X.js";
24
- import "./chunk-DUS5ZNKL.js";
25
- import "./chunk-6K2LCFG6.js";
26
- import "./chunk-PPZ3K4YM.js";
27
- import "./chunk-SOM4QA6C.js";
28
- import "./chunk-ICM463EO.js";
29
- import "./chunk-XEYH6ZZI.js";
30
- import "./chunk-P3LRUNC6.js";
31
- import "./chunk-3R27MJ5R.js";
32
- export {
33
- runReview
34
- };
35
- //# sourceMappingURL=review-LVZT2TMW.js.map
@@ -1,33 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- ROUTING_COMMAND_SCHEMA_VERSION,
4
- runRoutingExplain,
5
- runRoutingInspect,
6
- runRoutingReport,
7
- runRoutingUse,
8
- writeRoutingPreference
9
- } from "./chunk-HOAHMERN.js";
10
- import "./chunk-ZVZMWNCG.js";
11
- import "./chunk-QF7VEL3M.js";
12
- import "./chunk-LI35PIIS.js";
13
- import "./chunk-XZUEFTUP.js";
14
- import "./chunk-QPGEFLMY.js";
15
- import "./chunk-HAKDLR6N.js";
16
- import "./chunk-YVPZUN6X.js";
17
- import "./chunk-DUS5ZNKL.js";
18
- import "./chunk-6K2LCFG6.js";
19
- import "./chunk-PPZ3K4YM.js";
20
- import "./chunk-SOM4QA6C.js";
21
- import "./chunk-ICM463EO.js";
22
- import "./chunk-XEYH6ZZI.js";
23
- import "./chunk-P3LRUNC6.js";
24
- import "./chunk-3R27MJ5R.js";
25
- export {
26
- ROUTING_COMMAND_SCHEMA_VERSION,
27
- runRoutingExplain,
28
- runRoutingInspect,
29
- runRoutingReport,
30
- runRoutingUse,
31
- writeRoutingPreference
32
- };
33
- //# sourceMappingURL=routing-EK6RBZM4.js.map
@@ -1,56 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- publishIssueDetails,
4
- publishStorySeed,
5
- runPipeline
6
- } from "./chunk-CWSQVHVV.js";
7
- import "./chunk-QJ44VG5G.js";
8
- import "./chunk-OODXFCQV.js";
9
- import "./chunk-LTH6XYZ3.js";
10
- import "./chunk-YUNBOUQH.js";
11
- import "./chunk-XUEMATVY.js";
12
- import "./chunk-EG2MGDP5.js";
13
- import "./chunk-7UMMFOL2.js";
14
- import "./chunk-PMLE7KAQ.js";
15
- import "./chunk-KRAGAUKD.js";
16
- import "./chunk-NEWNXZ65.js";
17
- import "./chunk-ECU7YO7S.js";
18
- import "./chunk-E4I6MMHD.js";
19
- import "./chunk-CRGIQFUQ.js";
20
- import "./chunk-L6HSKTQE.js";
21
- import "./chunk-45WZ6GMI.js";
22
- import "./chunk-HOAHMERN.js";
23
- import "./chunk-34OCSKOB.js";
24
- import "./chunk-V7QOIQYC.js";
25
- import "./chunk-SA6HXL4Y.js";
26
- import "./chunk-62GVVZQO.js";
27
- import "./chunk-KMMASOA6.js";
28
- import "./chunk-KMCS76ZW.js";
29
- import "./chunk-7F7LGMVO.js";
30
- import "./chunk-TZYINKCC.js";
31
- import "./chunk-WCCZJL7W.js";
32
- import "./chunk-DGRTJD5R.js";
33
- import "./chunk-ZVZMWNCG.js";
34
- import "./chunk-C5TL7T4V.js";
35
- import "./chunk-3D4A4B46.js";
36
- import "./chunk-LGHND47K.js";
37
- import "./chunk-QF7VEL3M.js";
38
- import "./chunk-LI35PIIS.js";
39
- import "./chunk-XZUEFTUP.js";
40
- import "./chunk-QPGEFLMY.js";
41
- import "./chunk-HAKDLR6N.js";
42
- import "./chunk-YVPZUN6X.js";
43
- import "./chunk-DUS5ZNKL.js";
44
- import "./chunk-6K2LCFG6.js";
45
- import "./chunk-PPZ3K4YM.js";
46
- import "./chunk-SOM4QA6C.js";
47
- import "./chunk-ICM463EO.js";
48
- import "./chunk-XEYH6ZZI.js";
49
- import "./chunk-P3LRUNC6.js";
50
- import "./chunk-3R27MJ5R.js";
51
- export {
52
- publishIssueDetails,
53
- publishStorySeed,
54
- runPipeline
55
- };
56
- //# sourceMappingURL=run-2RXJCJKT.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/commands/usage.ts"],"sourcesContent":["import { readdir } from 'node:fs/promises';\nimport { loadTaskPlan } from '../core/state-manager.js';\nimport { getIssuePaths } from '../storage/paths.js';\nimport { resolveProjectPaths } from '../storage/resolve.js';\nimport { type GroupKey, groupBy, summarize } from '../telemetry/aggregate.js';\nimport { discardedExecutionCount } from '../telemetry/recorder.js';\nimport type { ExecutionRecord, ExecutionSummary } from '../telemetry/types.js';\nimport type { TaskPlan } from '../types.js';\nimport { printError, printInfo } from '../ui/logger.js';\n\nexport const USAGE_GROUP_KEYS = [\n 'harness',\n 'provider',\n 'model',\n 'purpose',\n 'status',\n] as const satisfies readonly GroupKey[];\n\nexport type UsageGroupKey = (typeof USAGE_GROUP_KEYS)[number];\n\nexport interface UsageOptions {\n issue?: string;\n since?: string;\n by?: UsageGroupKey;\n json?: boolean;\n}\n\nexport interface UsageReport {\n issue: string | null;\n since: string | null;\n by: UsageGroupKey | null;\n discarded: number;\n total: ExecutionSummary;\n groups: Array<{ key: string; summary: ExecutionSummary }>;\n}\n\nfunction sinceCutoff(since: string | undefined): number | null {\n if (since === undefined || since === '') return null;\n const parsed = Date.parse(since);\n return Number.isNaN(parsed) ? null : parsed;\n}\n\nfunction afterCutoff(\n records: readonly ExecutionRecord[],\n cutoff: number | null,\n): ExecutionRecord[] {\n if (cutoff === null) return [...records];\n return records.filter((record) => Date.parse(record.startedAt) >= cutoff);\n}\n\nfunction formatUsd(amount: number): string {\n return `$${amount.toFixed(2)}`;\n}\n\nfunction formatCost(summary: ExecutionSummary): string {\n const parts: string[] = [];\n if (summary.totalCost.reported > 0 || summary.totalCost.estimated === 0) {\n if (summary.count > 0 && summary.totalCost.unknownExecutions < summary.count) {\n parts.push(`${formatUsd(summary.totalCost.reported)} reportado`);\n }\n }\n if (summary.totalCost.estimated > 0) {\n parts.push(`${formatUsd(summary.totalCost.estimated)} estimado`);\n }\n if (summary.totalCost.unknownExecutions > 0) {\n parts.push(`— desconhecido (${summary.totalCost.unknownExecutions})`);\n }\n return parts.length === 0 ? '—' : parts.join(' · ');\n}\n\nfunction formatTokens(summary: ExecutionSummary): string {\n const total = summary.usage.inputTokens + summary.usage.outputTokens;\n if (total >= 1_000_000) return `${(total / 1_000_000).toFixed(1)}M`;\n if (total >= 1_000) return `${(total / 1_000).toFixed(1)}k`;\n return String(total);\n}\n\nfunction successRate(summary: ExecutionSummary): string {\n if (summary.count === 0) return '—';\n const ok = summary.byStatus.completed ?? 0;\n return `${((ok / summary.count) * 100).toFixed(1)}%`;\n}\n\nasync function loadPlans(\n issue: string | undefined,\n): Promise<{ id: string; plan: TaskPlan }[] | null> {\n let project: Awaited<ReturnType<typeof resolveProjectPaths>>;\n try {\n project = await resolveProjectPaths();\n } catch (err) {\n printError(`Not inside a usable project: ${err instanceof Error ? err.message : String(err)}`);\n return null;\n }\n\n if (issue !== undefined) {\n try {\n const paths = getIssuePaths(project.projectId, issue);\n return [{ id: issue, plan: await loadTaskPlan(paths.tasksFile) }];\n } catch (err) {\n printError(\n `No telemetry for issue ${issue}: ${err instanceof Error ? err.message : String(err)}`,\n );\n return null;\n }\n }\n\n let ids: string[];\n try {\n ids = await readdir(project.issuesDir);\n } catch {\n return [];\n }\n\n const loaded: { id: string; plan: TaskPlan }[] = [];\n for (const id of ids) {\n try {\n loaded.push({\n id,\n plan: await loadTaskPlan(getIssuePaths(project.projectId, id).tasksFile),\n });\n } catch {\n // An issue without a readable plan is not telemetry.\n }\n }\n return loaded;\n}\n\nexport function buildUsageReport(\n plans: { id: string; plan: TaskPlan }[],\n options: UsageOptions,\n discarded = 0,\n): UsageReport {\n const cutoff = sinceCutoff(options.since);\n const records = plans.flatMap(({ plan }) => afterCutoff(plan.executions ?? [], cutoff));\n const total = summarize(records, discarded);\n const groups =\n options.by === undefined\n ? []\n : [...groupBy(records, options.by)].map(([key, summary]) => ({ key, summary }));\n return {\n issue: options.issue ?? (plans.length === 1 ? (plans[0]?.id ?? null) : null),\n since: options.since ?? null,\n by: options.by ?? null,\n discarded,\n total,\n groups,\n };\n}\n\nexport function formatUsageReport(report: UsageReport): string {\n if (report.total.count === 0) {\n return 'No execution telemetry recorded yet.';\n }\n\n const header = [\n report.issue === null ? 'project' : `issue #${report.issue}`,\n `${report.total.count} execução${report.total.count === 1 ? '' : 'ões'}`,\n formatCost(report.total),\n ].join(' · ');\n\n if (report.by === null || report.groups.length === 0) {\n return header;\n }\n\n const rows = report.groups.map((group) => {\n const name = group.key.padEnd(14);\n const count = String(group.summary.count).padStart(10);\n const success = successRate(group.summary).padStart(8);\n const tokens = formatTokens(group.summary).padStart(8);\n return `${name}${count}${success}${tokens.padStart(10)} ${formatCost(group.summary)}`;\n });\n const columns = `${report.by.padEnd(14)}${'execuções'.padStart(10)}${'sucesso'.padStart(8)}${'tokens'.padStart(10)} custo`;\n return [`${header}`, columns, ...rows].join('\\n');\n}\n\nexport async function runUsage(\n issue: string | undefined,\n options: UsageOptions = {},\n): Promise<number> {\n const plans = await loadPlans(issue ?? options.issue);\n if (plans === null) return 1;\n\n if (options.since !== undefined && sinceCutoff(options.since) === null) {\n printError(`Invalid --since date: ${options.since}`);\n return 1;\n }\n\n const report = buildUsageReport(plans, { ...options, issue: issue ?? options.issue });\n if (plans.length === 0 || (report.total.count === 0 && (issue ?? options.issue) !== undefined)) {\n printInfo('No execution telemetry recorded yet.');\n return 0;\n }\n\n if (options.json === true) {\n printInfo(JSON.stringify(report, null, 2));\n return 0;\n }\n\n printInfo(formatUsageReport(report));\n return 0;\n}\n\nexport { discardedExecutionCount };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,eAAe;AAUjB,IAAM,mBAAmB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAoBA,SAAS,YAAY,OAA0C;AAC7D,MAAI,UAAU,UAAa,UAAU,GAAI,QAAO;AAChD,QAAM,SAAS,KAAK,MAAM,KAAK;AAC/B,SAAO,OAAO,MAAM,MAAM,IAAI,OAAO;AACvC;AAEA,SAAS,YACP,SACA,QACmB;AACnB,MAAI,WAAW,KAAM,QAAO,CAAC,GAAG,OAAO;AACvC,SAAO,QAAQ,OAAO,CAAC,WAAW,KAAK,MAAM,OAAO,SAAS,KAAK,MAAM;AAC1E;AAEA,SAAS,UAAU,QAAwB;AACzC,SAAO,IAAI,OAAO,QAAQ,CAAC,CAAC;AAC9B;AAEA,SAAS,WAAW,SAAmC;AACrD,QAAM,QAAkB,CAAC;AACzB,MAAI,QAAQ,UAAU,WAAW,KAAK,QAAQ,UAAU,cAAc,GAAG;AACvE,QAAI,QAAQ,QAAQ,KAAK,QAAQ,UAAU,oBAAoB,QAAQ,OAAO;AAC5E,YAAM,KAAK,GAAG,UAAU,QAAQ,UAAU,QAAQ,CAAC,YAAY;AAAA,IACjE;AAAA,EACF;AACA,MAAI,QAAQ,UAAU,YAAY,GAAG;AACnC,UAAM,KAAK,GAAG,UAAU,QAAQ,UAAU,SAAS,CAAC,WAAW;AAAA,EACjE;AACA,MAAI,QAAQ,UAAU,oBAAoB,GAAG;AAC3C,UAAM,KAAK,wBAAmB,QAAQ,UAAU,iBAAiB,GAAG;AAAA,EACtE;AACA,SAAO,MAAM,WAAW,IAAI,WAAM,MAAM,KAAK,QAAK;AACpD;AAEA,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O,GAAG,IAAI,GAAG,KAAK,GAAG,OAAO,GAAG,OAAO,SAAS,EAAE,CAAC,KAAK,WAAW,MAAM,OAAO,CAAC;AAAA,EACtF,CAAC;AACD,QAAM,UAAU,GAAG,OAAO,GAAG,OAAO,EAAE,CAAC,GAAG,kBAAY,SAAS,EAAE,CAAC,GAAG,UAAU,SAAS,CAAC,CAAC,GAAG,SAAS,SAAS,EAAE,CAAC;AAClH,SAAO,CAAC,GAAG,MAAM,IAAI,SAAS,GAAG,IAAI,EAAE,KAAK,IAAI;AAClD;AAEA,eAAsB,SACpB,OACA,UAAwB,CAAC,GACR;AACjB,QAAM,QAAQ,MAAM,UAAU,SAAS,QAAQ,KAAK;AACpD,MAAI,UAAU,KAAM,QAAO;AAE3B,MAAI,QAAQ,UAAU,UAAa,YAAY,QAAQ,KAAK,MAAM,MAAM;AACtE,eAAW,yBAAyB,QAAQ,KAAK,EAAE;AACnD,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,iBAAiB,OAAO,EAAE,GAAG,SAAS,OAAO,SAAS,QAAQ,MAAM,CAAC;AACpF,MAAI,MAAM,WAAW,KAAM,OAAO,MAAM,UAAU,MAAM,SAAS,QAAQ,WAAW,QAAY;AAC9F,cAAU,sCAAsC;AAChD,WAAO;AAAA,EACT;AAEA,MAAI,QAAQ,SAAS,MAAM;AACzB,cAAU,KAAK,UAAU,QAAQ,MAAM,CAAC,CAAC;AACzC,WAAO;AAAA,EACT;AAEA,YAAU,kBAAkB,MAAM,CAAC;AACnC,SAAO;AACT;","names":[]}
@@ -1,172 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- readSessionFile
4
- } from "./chunk-RYOUZ6EK.js";
5
- import {
6
- ensureSingleWebServer,
7
- stopWebMonitor
8
- } from "./chunk-NEWNXZ65.js";
9
- import "./chunk-45WZ6GMI.js";
10
- import "./chunk-HOAHMERN.js";
11
- import "./chunk-7F7LGMVO.js";
12
- import {
13
- parseJournal
14
- } from "./chunk-WCCZJL7W.js";
15
- import "./chunk-ZVZMWNCG.js";
16
- import "./chunk-C5TL7T4V.js";
17
- import {
18
- loadWebConfig
19
- } from "./chunk-QF7VEL3M.js";
20
- import "./chunk-LI35PIIS.js";
21
- import "./chunk-XZUEFTUP.js";
22
- import "./chunk-QPGEFLMY.js";
23
- import {
24
- EVENTS_FILENAME,
25
- ISSUES_DIR_NAME,
26
- PROJECTS_DIR_NAME,
27
- ROTATED_EVENTS_FILENAME,
28
- SESSION_FILENAME,
29
- getGlobalRoot
30
- } from "./chunk-HAKDLR6N.js";
31
- import "./chunk-YVPZUN6X.js";
32
- import "./chunk-DUS5ZNKL.js";
33
- import "./chunk-6K2LCFG6.js";
34
- import "./chunk-PPZ3K4YM.js";
35
- import "./chunk-SOM4QA6C.js";
36
- import "./chunk-ICM463EO.js";
37
- import "./chunk-XEYH6ZZI.js";
38
- import "./chunk-P3LRUNC6.js";
39
- import "./chunk-3R27MJ5R.js";
40
-
41
- // src/web/session-directory.ts
42
- import { readdir, readFile } from "fs/promises";
43
- import { join } from "path";
44
- var DEFAULT_POLL_INTERVAL_MS = 3e3;
45
- var DEFAULT_STALE_AFTER_MS = 9e4;
46
- async function listSubdirectories(dir) {
47
- try {
48
- const entries = await readdir(dir, { withFileTypes: true });
49
- return entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);
50
- } catch {
51
- return [];
52
- }
53
- }
54
- async function discoverSessionFiles(root) {
55
- const projectsDir = join(root, PROJECTS_DIR_NAME);
56
- const projectIds = await listSubdirectories(projectsDir);
57
- const perProject = await Promise.all(
58
- projectIds.map(async (projectId) => {
59
- const issuesDir = join(projectsDir, projectId, ISSUES_DIR_NAME);
60
- const issueIds = await listSubdirectories(issuesDir);
61
- return issueIds.map((issueId) => join(issuesDir, issueId, SESSION_FILENAME));
62
- })
63
- );
64
- return perProject.flat();
65
- }
66
- async function readJournalFile(filePath) {
67
- try {
68
- return parseJournal(await readFile(filePath, "utf-8"));
69
- } catch {
70
- return [];
71
- }
72
- }
73
- function watchSessionDirectory(options = {}) {
74
- const root = getGlobalRoot(options);
75
- const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
76
- const staleAfterMs = options.staleAfterMs ?? DEFAULT_STALE_AFTER_MS;
77
- const warn = options.onWarn;
78
- let sessions = /* @__PURE__ */ new Map();
79
- let warned = false;
80
- async function scan() {
81
- let files;
82
- try {
83
- files = await discoverSessionFiles(root);
84
- } catch (err) {
85
- if (!warned) {
86
- warned = true;
87
- warn?.(
88
- `issue-flow: web monitor could not scan the session directory (will keep retrying silently): ${err instanceof Error ? err.message : String(err)}`
89
- );
90
- }
91
- return;
92
- }
93
- const now = Date.now();
94
- const next = /* @__PURE__ */ new Map();
95
- for (const filePath of files) {
96
- const result = await readSessionFile(filePath);
97
- if (result === null) continue;
98
- if (now - result.updatedAtMs > staleAfterMs) continue;
99
- const sessionId = result.snapshot.sessionId;
100
- next.set(sessionId, {
101
- issueDir: join(filePath, ".."),
102
- filePath,
103
- snapshot: result.snapshot,
104
- updatedAtMs: result.updatedAtMs
105
- });
106
- }
107
- sessions = next;
108
- }
109
- void scan();
110
- const timer = setInterval(() => void scan(), pollIntervalMs);
111
- timer.unref();
112
- return {
113
- sessions: () => [...sessions.values()],
114
- getSession: (sessionId) => sessions.get(sessionId),
115
- events: async (sessionId) => {
116
- const session = sessions.get(sessionId);
117
- if (session === void 0) return void 0;
118
- const [rotated, current] = await Promise.all([
119
- readJournalFile(join(session.issueDir, ROTATED_EVENTS_FILENAME)),
120
- readJournalFile(join(session.issueDir, EVENTS_FILENAME))
121
- ]);
122
- return [...rotated, ...current];
123
- },
124
- refresh: scan,
125
- close: () => clearInterval(timer)
126
- };
127
- }
128
-
129
- // src/commands/web.ts
130
- async function runWebServe(options) {
131
- const cli = {};
132
- if (options.port !== void 0) cli.port = options.port;
133
- if (options.host !== void 0) cli.host = options.host;
134
- if (options.refresh !== void 0) cli.refreshSeconds = options.refresh;
135
- const webConfig = await loadWebConfig({ cli });
136
- const sessions = watchSessionDirectory();
137
- const noop = () => {
138
- };
139
- const handle = await ensureSingleWebServer({
140
- sessions,
141
- port: webConfig.port,
142
- host: webConfig.host,
143
- refreshSeconds: webConfig.refreshSeconds,
144
- unref: false,
145
- info: noop,
146
- warn: noop
147
- });
148
- if (handle === null) {
149
- sessions.close();
150
- return 1;
151
- }
152
- if (handle.server === void 0) {
153
- sessions.close();
154
- return 0;
155
- }
156
- const originalClose = handle.close;
157
- handle.close = async () => {
158
- await originalClose();
159
- sessions.close();
160
- };
161
- return 0;
162
- }
163
- async function runWebStop() {
164
- const webConfig = await loadWebConfig();
165
- const result = await stopWebMonitor({ port: webConfig.port, host: webConfig.host });
166
- return result === "failed" || result === "unowned" ? 1 : 0;
167
- }
168
- export {
169
- runWebServe,
170
- runWebStop
171
- };
172
- //# sourceMappingURL=web-B5UPHHR5.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/web/session-directory.ts","../src/commands/web.ts"],"sourcesContent":["import { readdir, readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { type JournalEntry, parseJournal } from '../core/journal.js';\nimport type { ValidatedSessionSnapshot } from '../schemas.js';\nimport {\n EVENTS_FILENAME,\n type GetGlobalRootOptions,\n getGlobalRoot,\n ISSUES_DIR_NAME,\n PROJECTS_DIR_NAME,\n ROTATED_EVENTS_FILENAME,\n SESSION_FILENAME,\n} from '../storage/paths.js';\nimport { readSessionFile } from '../storage/session-file.js';\n\n/**\n * Multi-session discovery for the web monitoring server (US-003).\n *\n * The single-instance server (`web/lock.ts`) runs decoupled from any one\n * pipeline invocation, so it cannot hold a `SessionPublisher` in memory for\n * \"the\" run being monitored — there may be zero, one or several running at\n * once, each in its own process. Instead this module polls every\n * `~/.issue-flow/projects/<project>/issues/<n>/session.json` on disk (the\n * same file `FilePublisher` already writes) and keeps an in-memory map of the\n * ones that are both well-formed and recently updated.\n *\n * Polling rather than `fs.watch` is a deliberate choice, not a placeholder:\n * `fs.watch`'s `recursive` option is only reliable on macOS and Windows (Linux\n * needs a manual per-directory watch tree, and the whole thing still degrades\n * to polling on network filesystems), while a `~/.issue-flow` tree is small\n * and local — a cheap poll of it is simpler and behaves identically on every\n * platform, which is what the US-003 acceptance criteria ask to validate.\n */\n\n/** How often the directory tree is rescanned, unless overridden. */\nexport const DEFAULT_POLL_INTERVAL_MS = 3000;\n\n/**\n * A session stops being reported once its file has gone this long without an\n * update. `FilePublisher` touches a live session every 10s without rewriting\n * its content. Three missed heartbeats plus ample scheduling/filesystem slack\n * avoid flapping while still removing an abruptly killed run promptly.\n */\nexport const DEFAULT_STALE_AFTER_MS = 90_000;\n\nexport interface ActiveSession {\n /** Directory the session.json was read from, one level up from the file. */\n issueDir: string;\n filePath: string;\n snapshot: ValidatedSessionSnapshot;\n /** mtime of the file at the last successful read, in epoch ms. */\n updatedAtMs: number;\n}\n\nexport interface SessionDirectoryOptions extends GetGlobalRootOptions {\n /** Poll interval, in ms. Default {@link DEFAULT_POLL_INTERVAL_MS}. */\n pollIntervalMs?: number;\n /** Staleness threshold, in ms. Default {@link DEFAULT_STALE_AFTER_MS}. */\n staleAfterMs?: number;\n /** Invoked (at most once) when a poll fails unexpectedly. Best-effort logging only. */\n onWarn?: (message: string) => void;\n}\n\nexport interface SessionDirectoryHandle {\n /** Snapshot of every session currently considered active. */\n sessions(): ActiveSession[];\n /** A single active session by id, or undefined. */\n getSession(sessionId: string): ActiveSession | undefined;\n /** Journal entries for one active session, oldest generation first. */\n events(sessionId: string): Promise<JournalEntry[] | undefined>;\n /** Force an immediate rescan instead of waiting for the next tick. Never throws. */\n refresh(): Promise<void>;\n /** Stop polling. Idempotent. */\n close(): void;\n}\n\nasync function listSubdirectories(dir: string): Promise<string[]> {\n try {\n const entries = await readdir(dir, { withFileTypes: true });\n // Symlinks are skipped on purpose, same discipline as the storage\n // migration walk: following one could pull session data from outside the\n // global tree into the listing.\n return entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);\n } catch {\n // Missing/unreadable projects (or issues) directory reads as \"none yet\" —\n // this is routinely the case before the first --web run ever happens.\n return [];\n }\n}\n\n/** Every `session.json` path currently on disk, one per project/issue pair. */\nasync function discoverSessionFiles(root: string): Promise<string[]> {\n const projectsDir = join(root, PROJECTS_DIR_NAME);\n const projectIds = await listSubdirectories(projectsDir);\n\n const perProject = await Promise.all(\n projectIds.map(async (projectId) => {\n const issuesDir = join(projectsDir, projectId, ISSUES_DIR_NAME);\n const issueIds = await listSubdirectories(issuesDir);\n return issueIds.map((issueId) => join(issuesDir, issueId, SESSION_FILENAME));\n }),\n );\n\n return perProject.flat();\n}\n\nasync function readJournalFile(filePath: string): Promise<JournalEntry[]> {\n try {\n return parseJournal(await readFile(filePath, 'utf-8'));\n } catch {\n return [];\n }\n}\n\n/**\n * Start polling the global storage tree for active sessions.\n *\n * Returns a handle immediately; the first scan happens synchronously in the\n * background and `sessions()` answers `[]` until it completes, same as \"no\n * sessions found yet\" — there is nothing to await here that would not also\n * delay the server's very first bind.\n */\nexport function watchSessionDirectory(\n options: SessionDirectoryOptions = {},\n): SessionDirectoryHandle {\n const root = getGlobalRoot(options);\n const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n const staleAfterMs = options.staleAfterMs ?? DEFAULT_STALE_AFTER_MS;\n const warn = options.onWarn;\n\n // Keyed by sessionId, not by file path: a session's identity is the id\n // inside its content, and that is what /api/status?session=<id> looks up.\n let sessions = new Map<string, ActiveSession>();\n let warned = false;\n\n async function scan(): Promise<void> {\n let files: string[];\n try {\n files = await discoverSessionFiles(root);\n } catch (err) {\n if (!warned) {\n warned = true;\n warn?.(\n `issue-flow: web monitor could not scan the session directory (will keep retrying silently): ${\n err instanceof Error ? err.message : String(err)\n }`,\n );\n }\n return;\n }\n\n const now = Date.now();\n const next = new Map<string, ActiveSession>();\n for (const filePath of files) {\n const result = await readSessionFile(filePath);\n if (result === null) continue;\n if (now - result.updatedAtMs > staleAfterMs) continue; // stopped updating: not active\n const sessionId = result.snapshot.sessionId as string;\n next.set(sessionId, {\n issueDir: join(filePath, '..'),\n filePath,\n snapshot: result.snapshot,\n updatedAtMs: result.updatedAtMs,\n });\n }\n sessions = next;\n }\n\n // The first scan runs immediately (not just after the first interval tick)\n // so a server started right after a session begins does not report \"no\n // sessions\" for a whole poll interval.\n void scan();\n const timer = setInterval(() => void scan(), pollIntervalMs);\n timer.unref();\n\n return {\n sessions: () => [...sessions.values()],\n getSession: (sessionId: string) => sessions.get(sessionId),\n events: async (sessionId: string) => {\n const session = sessions.get(sessionId);\n if (session === undefined) return undefined;\n const [rotated, current] = await Promise.all([\n readJournalFile(join(session.issueDir, ROTATED_EVENTS_FILENAME)),\n readJournalFile(join(session.issueDir, EVENTS_FILENAME)),\n ]);\n return [...rotated, ...current];\n },\n refresh: scan,\n close: () => clearInterval(timer),\n };\n}\n","import { loadWebConfig } from '../config.js';\nimport type { WebConfig } from '../schemas.js';\nimport { ensureSingleWebServer, stopWebMonitor } from '../web/lock.js';\nimport { watchSessionDirectory } from '../web/session-directory.js';\n\n/**\n * `issue-flow web serve` / `issue-flow web stop` (US-002).\n *\n * `serve` is the process `ensureWebMonitor()` (`web/lock.ts`) spawns detached\n * — it is not meant to be run interactively, though nothing stops a user from\n * doing so to watch every session on the machine without going through a\n * pipeline command first. It never exits on its own: the server stays bound\n * (see `unref: false` in `web/server.ts`) until `stop` sends it `SIGTERM`, at\n * which point `startWebServer`'s own signal handler closes it (removing the\n * lock) and re-raises the signal for the default termination behavior.\n */\n\nexport interface RunWebServeOptions {\n port?: number;\n host?: string;\n refresh?: number;\n}\n\n/**\n * Bind (or defer to) the single web monitor instance and keep the process\n * alive for as long as it stays bound. Logging is intentionally silent on the\n * happy path: this process is spawned with `stdio: 'ignore'`, so anything\n * printed here goes nowhere — the caller (`ensureWebMonitor`) is the one that\n * tells the user the server is up.\n */\nexport async function runWebServe(options: RunWebServeOptions): Promise<number> {\n // Built conditionally, not `{ port: options.port, ... }`: loadWebConfig()\n // spreads this object directly over the lower-precedence layers, and an\n // explicit `undefined` value would overwrite an env/.issue-flow.json\n // setting instead of falling through to it (only an *absent* key does).\n const cli: Partial<WebConfig> = {};\n if (options.port !== undefined) cli.port = options.port;\n if (options.host !== undefined) cli.host = options.host;\n if (options.refresh !== undefined) cli.refreshSeconds = options.refresh;\n const webConfig = await loadWebConfig({ cli });\n\n const sessions = watchSessionDirectory();\n\n const noop = (): void => {};\n const handle = await ensureSingleWebServer({\n sessions,\n port: webConfig.port,\n host: webConfig.host,\n refreshSeconds: webConfig.refreshSeconds,\n unref: false,\n info: noop,\n warn: noop,\n });\n\n if (handle === null) {\n sessions.close();\n return 1;\n }\n\n if (handle.server === undefined) {\n // Another instance already won the race (or was already running by the\n // time this process got here): nothing to serve, so it exits right away\n // instead of idling as a redundant detached process.\n sessions.close();\n return 0;\n }\n\n const originalClose = handle.close;\n handle.close = async () => {\n await originalClose();\n sessions.close();\n };\n\n return 0;\n}\n\n/** Stop the single running web monitor instance, if any. */\nexport async function runWebStop(): Promise<number> {\n const webConfig = await loadWebConfig();\n const result = await stopWebMonitor({ port: webConfig.port, host: webConfig.host });\n return result === 'failed' || result === 'unowned' ? 1 : 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,gBAAgB;AAClC,SAAS,YAAY;AAkCd,IAAM,2BAA2B;AAQjC,IAAM,yBAAyB;AAiCtC,eAAe,mBAAmB,KAAgC;AAChE,MAAI;AACF,UAAM,UAAU,MAAM,QAAQ,KAAK,EAAE,eAAe,KAAK,CAAC;AAI1D,WAAO,QAAQ,OAAO,CAAC,UAAU,MAAM,YAAY,CAAC,EAAE,IAAI,CAAC,UAAU,MAAM,IAAI;AAAA,EACjF,QAAQ;AAGN,WAAO,CAAC;AAAA,EACV;AACF;AAGA,eAAe,qBAAqB,MAAiC;AACnE,QAAM,cAAc,KAAK,MAAM,iBAAiB;AAChD,QAAM,aAAa,MAAM,mBAAmB,WAAW;AAEvD,QA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