nolzu 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (491) hide show
  1. package/LICENSE +105 -0
  2. package/README.md +24 -7
  3. package/build/client/_app/immutable/assets/0.SPD4wYkc.css +1 -0
  4. package/build/client/_app/immutable/assets/1.BRilEoOO.css +1 -0
  5. package/build/client/_app/immutable/assets/10.DwLiBGDj.css +1 -0
  6. package/build/client/_app/immutable/assets/11.D_TtWT3D.css +1 -0
  7. package/build/client/_app/immutable/assets/12.CSVGmtUY.css +1 -0
  8. package/build/client/_app/immutable/assets/13.qTa7IHbg.css +1 -0
  9. package/build/client/_app/immutable/assets/19.CbCFXKb8.css +1 -0
  10. package/build/client/_app/immutable/assets/2.CfHhgI77.css +1 -0
  11. package/build/client/_app/immutable/assets/20.C5CSZhyT.css +1 -0
  12. package/build/client/_app/immutable/assets/21.BBpYkZcc.css +1 -0
  13. package/build/client/_app/immutable/assets/22.C9RgY9kl.css +1 -0
  14. package/build/client/_app/immutable/assets/23.B6Dp9RJO.css +1 -0
  15. package/build/client/_app/immutable/assets/24.C7g2abUW.css +1 -0
  16. package/build/client/_app/immutable/assets/26.DTMI6ROV.css +1 -0
  17. package/build/client/_app/immutable/assets/27.AxXMpDkB.css +1 -0
  18. package/build/client/_app/immutable/assets/28.939ac-98.css +1 -0
  19. package/build/client/_app/immutable/assets/3.3lqex1t-.css +1 -0
  20. package/build/client/_app/immutable/assets/4.C52MzO_d.css +1 -0
  21. package/build/client/_app/immutable/assets/5.CsfJAwvS.css +1 -0
  22. package/build/client/_app/immutable/assets/8.ByspUp-s.css +1 -0
  23. package/build/client/_app/immutable/assets/9.BCSFZmce.css +1 -0
  24. package/build/client/_app/immutable/assets/Banner.DDqfpWLD.css +1 -0
  25. package/build/client/_app/immutable/assets/BoardOff.mpX08-Be.css +1 -0
  26. package/build/client/_app/immutable/assets/Button.BlwsEgUc.css +1 -0
  27. package/build/client/_app/immutable/assets/Chip.qAAa6_e5.css +1 -0
  28. package/build/client/_app/immutable/assets/Dialog.D5Ln60a8.css +1 -0
  29. package/build/client/_app/immutable/assets/FeaturePanels.DZ_Mth5M.css +1 -0
  30. package/build/client/_app/immutable/assets/FolderBrowser.DBmRWDCH.css +1 -0
  31. package/build/client/_app/immutable/assets/Geist-Variable.Bj2R_7yk.woff2 +0 -0
  32. package/build/client/_app/immutable/assets/GeistMono-Variable.Dispecij.woff2 +0 -0
  33. package/build/client/_app/immutable/assets/HelpTip.DF6T9nns.css +1 -0
  34. package/build/client/_app/immutable/assets/InfoBox.CpavOykF.css +1 -0
  35. package/build/client/_app/immutable/assets/KeyCaps.D2t-lY-8.css +1 -0
  36. package/build/client/_app/immutable/assets/LogLine.Bu4feLn5.css +1 -0
  37. package/build/client/_app/immutable/assets/Markdown.DI6AtWAc.css +1 -0
  38. package/build/client/_app/immutable/assets/ModelPicker.DQzj7Nj8.css +1 -0
  39. package/build/client/_app/immutable/assets/OptionButtons.BYiyOXOE.css +1 -0
  40. package/build/client/_app/immutable/assets/PeekPanel.DzMdHoqg.css +1 -0
  41. package/build/client/_app/immutable/assets/ScoutPage.CVIiLy5c.css +1 -0
  42. package/build/client/_app/immutable/assets/SetupSteps.B6pZP1Bk.css +1 -0
  43. package/build/client/_app/immutable/assets/Skeleton.BC-1_U5d.css +1 -0
  44. package/build/client/_app/immutable/assets/SlotsMeter.Dq7GGYlD.css +1 -0
  45. package/build/client/_app/immutable/assets/StartConfirm.DxNN2AOb.css +1 -0
  46. package/build/client/_app/immutable/assets/StatePill.CGWFVUUg.css +1 -0
  47. package/build/client/_app/immutable/assets/Streamed.DpZ6wgO2.css +1 -0
  48. package/build/client/_app/immutable/assets/card-pulls.C5uGMuAh.css +1 -0
  49. package/build/client/_app/immutable/assets/next-step.CKg1w06J.css +1 -0
  50. package/build/client/_app/immutable/chunks/-B5EclhK.js +1 -0
  51. package/build/client/_app/immutable/chunks/-Q3zApAy.js +1 -0
  52. package/build/client/_app/immutable/chunks/6-hwN_Ik.js +3 -0
  53. package/build/client/_app/immutable/chunks/B16UF4PA.js +11 -0
  54. package/build/client/_app/immutable/chunks/B1V3h1VF.js +1 -0
  55. package/build/client/_app/immutable/chunks/B2d2Mkuz.js +68 -0
  56. package/build/client/_app/immutable/chunks/B2yzhiEa.js +1 -0
  57. package/build/client/_app/immutable/chunks/B5zDDQUU.js +2 -0
  58. package/build/client/_app/immutable/chunks/B8DHSiWf.js +1 -0
  59. package/build/client/_app/immutable/chunks/B8z33EzI.js +1 -0
  60. package/build/client/_app/immutable/chunks/BCRkrH6c.js +1 -0
  61. package/build/client/_app/immutable/chunks/BCScjOxu.js +1 -0
  62. package/build/client/_app/immutable/chunks/BMUQtCEC.js +1 -0
  63. package/build/client/_app/immutable/chunks/BNnfkvZM.js +1 -0
  64. package/build/client/_app/immutable/chunks/BelWyZaW.js +1 -0
  65. package/build/client/_app/immutable/chunks/BhZpqODT.js +1 -0
  66. package/build/client/_app/immutable/chunks/Bjy-W4x2.js +81 -0
  67. package/build/client/_app/immutable/chunks/BmafI-Bs.js +1 -0
  68. package/build/client/_app/immutable/chunks/BvRk9kiK.js +0 -0
  69. package/build/client/_app/immutable/chunks/C4i6bdQg.js +1 -0
  70. package/build/client/_app/immutable/chunks/C8u5TyIB.js +1 -0
  71. package/build/client/_app/immutable/chunks/CFs2xhoy.js +1 -0
  72. package/build/client/_app/immutable/chunks/CIm2DioU.js +1 -0
  73. package/build/client/_app/immutable/chunks/CONqGBXC.js +1 -0
  74. package/build/client/_app/immutable/chunks/CSOz40qO.js +1 -0
  75. package/build/client/_app/immutable/chunks/CXxuD1ef.js +3 -0
  76. package/build/client/_app/immutable/chunks/CarrGsZA.js +2 -0
  77. package/build/client/_app/immutable/chunks/CdrmTD44.js +1 -0
  78. package/build/client/_app/immutable/chunks/CfJRH9gh.js +2 -0
  79. package/build/client/_app/immutable/chunks/Ci7C9Cki.js +1 -0
  80. package/build/client/_app/immutable/chunks/CkOTL1vK.js +1 -0
  81. package/build/client/_app/immutable/chunks/CngTtGc_.js +1 -0
  82. package/build/client/_app/immutable/chunks/Cp3A1zR8.js +1 -0
  83. package/build/client/_app/immutable/chunks/CwtMnwNL.js +3 -0
  84. package/build/client/_app/immutable/chunks/Cy7f_oXg.js +1 -0
  85. package/build/client/_app/immutable/chunks/D-wwLm5t.js +1 -0
  86. package/build/client/_app/immutable/chunks/D2imbgaf.js +1 -0
  87. package/build/client/_app/immutable/chunks/D32mip60.js +1 -0
  88. package/build/client/_app/immutable/chunks/D46Vk19W.js +1 -0
  89. package/build/client/_app/immutable/chunks/DCUUgo-6.js +1 -0
  90. package/build/client/_app/immutable/chunks/DFjnjJjy.js +1 -0
  91. package/build/client/_app/immutable/chunks/DHMbSbMg.js +1 -0
  92. package/build/client/_app/immutable/chunks/DJOFx2wx.js +1 -0
  93. package/build/client/_app/immutable/chunks/DV4tvxHp.js +3 -0
  94. package/build/client/_app/immutable/chunks/DXk_5YEw.js +1 -0
  95. package/build/client/_app/immutable/chunks/DjgnRLJt.js +1 -0
  96. package/build/client/_app/immutable/chunks/DlWlQ_vP.js +1 -0
  97. package/build/client/_app/immutable/chunks/DpIAei2y.js +2 -0
  98. package/build/client/_app/immutable/chunks/Dt-HX3Vu.js +1 -0
  99. package/build/client/_app/immutable/chunks/DuSthUWX.js +1 -0
  100. package/build/client/_app/immutable/chunks/Ecfl8TOn.js +2 -0
  101. package/build/client/_app/immutable/chunks/ITHE99Aa.js +1 -0
  102. package/build/client/_app/immutable/chunks/Khdge0KS.js +1 -0
  103. package/build/client/_app/immutable/chunks/LMEKNlm0.js +1 -0
  104. package/build/client/_app/immutable/chunks/OnIeaiuO.js +1 -0
  105. package/build/client/_app/immutable/chunks/VFQLu55q.js +1 -0
  106. package/build/client/_app/immutable/chunks/ZsUxKnQw.js +1 -0
  107. package/build/client/_app/immutable/chunks/aWP8DVhV.js +1 -0
  108. package/build/client/_app/immutable/chunks/bB04Xp1f.js +1 -0
  109. package/build/client/_app/immutable/chunks/eylBqhv8.js +3 -0
  110. package/build/client/_app/immutable/chunks/hx0ssLL_.js +2 -0
  111. package/build/client/_app/immutable/chunks/mumDj17t.js +1 -0
  112. package/build/client/_app/immutable/chunks/pZYp3_TE.js +1 -0
  113. package/build/client/_app/immutable/chunks/tImwjqWn.js +1 -0
  114. package/build/client/_app/immutable/chunks/uBIymjUX.js +1 -0
  115. package/build/client/_app/immutable/chunks/xihTtKlq.js +1 -0
  116. package/build/client/_app/immutable/entry/app.DVZ1wE36.js +2 -0
  117. package/build/client/_app/immutable/entry/start.DluCc61B.js +1 -0
  118. package/build/client/_app/immutable/nodes/0.CwNFevXf.js +1 -0
  119. package/build/client/_app/immutable/nodes/1.BR6FYiC-.js +1 -0
  120. package/build/client/_app/immutable/nodes/10.wNwBFtom.js +2 -0
  121. package/build/client/_app/immutable/nodes/11.DpoIbMNF.js +2 -0
  122. package/build/client/_app/immutable/nodes/12.CWdUJ8l3.js +2 -0
  123. package/build/client/_app/immutable/nodes/13.CZ2uTvNS.js +1 -0
  124. package/build/client/_app/immutable/nodes/14.CzgyXuvL.js +1 -0
  125. package/build/client/_app/immutable/nodes/15.CzgyXuvL.js +1 -0
  126. package/build/client/_app/immutable/nodes/16.odL9eB2N.js +1 -0
  127. package/build/client/_app/immutable/nodes/17.B-RnUeVU.js +1 -0
  128. package/build/client/_app/immutable/nodes/18.BLYKxyq2.js +1 -0
  129. package/build/client/_app/immutable/nodes/19.CgyFfPqF.js +3 -0
  130. package/build/client/_app/immutable/nodes/2.CCWT41Qr.js +1 -0
  131. package/build/client/_app/immutable/nodes/20.BBk5-krg.js +1 -0
  132. package/build/client/_app/immutable/nodes/21.CJoU3s1A.js +2 -0
  133. package/build/client/_app/immutable/nodes/22.CoRvPh8m.js +1 -0
  134. package/build/client/_app/immutable/nodes/23.zXO3NjnM.js +3 -0
  135. package/build/client/_app/immutable/nodes/24.CmO27TED.js +1 -0
  136. package/build/client/_app/immutable/nodes/26.TVKNr_xX.js +18 -0
  137. package/build/client/_app/immutable/nodes/27.RojtGU_o.js +1 -0
  138. package/build/client/_app/immutable/nodes/28.CVTdeeSI.js +2 -0
  139. package/build/client/_app/immutable/nodes/3.Cgib7Vi6.js +1 -0
  140. package/build/client/_app/immutable/nodes/4.CnMwOCec.js +1 -0
  141. package/build/client/_app/immutable/nodes/5.-NqYtQj_.js +1 -0
  142. package/build/client/_app/immutable/nodes/6.D5xk-UBM.js +1 -0
  143. package/build/client/_app/immutable/nodes/7.IL4b-DII.js +1 -0
  144. package/build/client/_app/immutable/nodes/8.DJrguHjO.js +11 -0
  145. package/build/client/_app/immutable/nodes/9.DTUSzWiK.js +1 -0
  146. package/build/client/_app/version.json +1 -0
  147. package/build/client/favicon.svg +7 -0
  148. package/build/env.js +70 -0
  149. package/build/handler.js +26 -0
  150. package/build/index.js +149 -0
  151. package/build/server/chunks/chunks/Banner.js-D4mtxUfF.js +17 -0
  152. package/build/server/chunks/chunks/BoardOff.js-Dg5-LoR3.js +1627 -0
  153. package/build/server/chunks/chunks/Button.js-Buh9rnpu.js +43 -0
  154. package/build/server/chunks/chunks/Chip.js-xZ7vFkHx.js +12 -0
  155. package/build/server/chunks/chunks/Dialog.js-CGpwdpM-.js +60 -0
  156. package/build/server/chunks/chunks/FeaturePanels.js-B2sKozgF.js +84 -0
  157. package/build/server/chunks/chunks/FolderBrowser.js-DUHFhDaX.js +28 -0
  158. package/build/server/chunks/chunks/HelpTip.js-CzemvmjC.js +19 -0
  159. package/build/server/chunks/chunks/InfoBox.js-BJiVzZgw.js +10 -0
  160. package/build/server/chunks/chunks/KeyCaps.js-BMI2Hrh2.js +37 -0
  161. package/build/server/chunks/chunks/LogLine.js-2b7uX__H.js +35 -0
  162. package/build/server/chunks/chunks/Markdown.js-Clud88KU.js +4233 -0
  163. package/build/server/chunks/chunks/ModelPicker.js-FuBgyKIA.js +141 -0
  164. package/build/server/chunks/chunks/OptionButtons.js-LQKrAwUX.js +28 -0
  165. package/build/server/chunks/chunks/PeekPanel.js-aZ-r_v3N.js +375 -0
  166. package/build/server/chunks/chunks/ScoutPage.js-2DcNia96.js +733 -0
  167. package/build/server/chunks/chunks/SetupSteps.js-D7TAF7xa.js +66 -0
  168. package/build/server/chunks/chunks/Skeleton.js-diCP2sd5.js +30 -0
  169. package/build/server/chunks/chunks/SlotsMeter.js-BV_sAGf5.js +18 -0
  170. package/build/server/chunks/chunks/StartConfirm.js-CzEdFtbO.js +124 -0
  171. package/build/server/chunks/chunks/StatePill.js-CM7-HXNM.js +27 -0
  172. package/build/server/chunks/chunks/Streamed.js-_NgwNMMs.js +43 -0
  173. package/build/server/chunks/chunks/_page.server.js-BaGoctEY.js +1419 -0
  174. package/build/server/chunks/chunks/activity.js-CSoPUQLq.js +84 -0
  175. package/build/server/chunks/chunks/add-repo.js-DtHEobfm.js +305 -0
  176. package/build/server/chunks/chunks/app-header.js-CCflgeEQ.js +13 -0
  177. package/build/server/chunks/chunks/app.js-CuPn8jtk.js +12 -0
  178. package/build/server/chunks/chunks/bin.js-Cyb2cYLc.js +58 -0
  179. package/build/server/chunks/chunks/board-keys.js-CW3qw-MC.js +32 -0
  180. package/build/server/chunks/chunks/board-page.js-D0tdsE9J.js +860 -0
  181. package/build/server/chunks/chunks/board.js-BxL3CjB1.js +203 -0
  182. package/build/server/chunks/chunks/browser-test.js-DJEpOoVz.js +170 -0
  183. package/build/server/chunks/chunks/card-pulls.js-d_uGmBB3.js +229 -0
  184. package/build/server/chunks/chunks/card-repos.js-QaMCxiyV.js +59 -0
  185. package/build/server/chunks/chunks/chain-store.js-D42m8DUo.js +91 -0
  186. package/build/server/chunks/chunks/chain.js-CJFRywIC.js +52 -0
  187. package/build/server/chunks/chunks/changes.js-D8ITRMgU.js +513 -0
  188. package/build/server/chunks/chunks/checkout.js-Ys5L_gA4.js +319 -0
  189. package/build/server/chunks/chunks/client.js-B7jIMDuS.js +68 -0
  190. package/build/server/chunks/chunks/clipboard.js-qXskOBim.js +12 -0
  191. package/build/server/chunks/chunks/cloud-status.js-hy-9zUVX.js +95 -0
  192. package/build/server/chunks/chunks/coach.js-BhNB14rV.js +296 -0
  193. package/build/server/chunks/chunks/comments.js-1nWJQptB.js +311 -0
  194. package/build/server/chunks/chunks/commit-message.js-CMcNZUZw.js +8 -0
  195. package/build/server/chunks/chunks/create-card.js-DKtprMG6.js +498 -0
  196. package/build/server/chunks/chunks/db.js-pqoVpAzG.js +80 -0
  197. package/build/server/chunks/chunks/diff-comments.js-BSCuay_U.js +95 -0
  198. package/build/server/chunks/chunks/discussion.js-rJ5OMfvX.js +355 -0
  199. package/build/server/chunks/chunks/display.js-Bf-vGQ7Q.js +61 -0
  200. package/build/server/chunks/chunks/elapsed.js-DikkNhaD.js +27 -0
  201. package/build/server/chunks/chunks/engine.js-DS5zUwsE.js +115 -0
  202. package/build/server/chunks/chunks/env.js-l0sNRNKZ.js +2 -0
  203. package/build/server/chunks/chunks/estimate.js-BHTYVTaQ.js +2484 -0
  204. package/build/server/chunks/chunks/evidence-timeline.js-Dk0dTZIy.js +253 -0
  205. package/build/server/chunks/chunks/evidence.js-CT3tWdbB.js +257 -0
  206. package/build/server/chunks/chunks/exports.js-Hn-WQRMB.js +150 -0
  207. package/build/server/chunks/chunks/features.svelte.js-DNsFmFZb.js +10 -0
  208. package/build/server/chunks/chunks/files.js-V46lE0-6.js +46 -0
  209. package/build/server/chunks/chunks/filter.js-CsmCtJMd.js +11 -0
  210. package/build/server/chunks/chunks/forms.js-03E8qnFz.js +35 -0
  211. package/build/server/chunks/chunks/gate.js-Cbqo8Yy0.js +82 -0
  212. package/build/server/chunks/chunks/getting-started.js-DKbHofN5.js +55 -0
  213. package/build/server/chunks/chunks/git.js-l43vBHqs.js +16 -0
  214. package/build/server/chunks/chunks/home-path.js-BXgrl3TP.js +11 -0
  215. package/build/server/chunks/chunks/hub-link.js-B5kjLyyd.js +1532 -0
  216. package/build/server/chunks/chunks/internal.js-DaSBO6jY.js +1239 -0
  217. package/build/server/chunks/chunks/internal2.js-D6AKyUgY.js +27 -0
  218. package/build/server/chunks/chunks/knowledge-page.js-D2ALB3v9.js +292 -0
  219. package/build/server/chunks/chunks/knowledge-revert.js-2eyN9Lcb.js +109 -0
  220. package/build/server/chunks/chunks/knowledge.js--eAgdzNx.js +394 -0
  221. package/build/server/chunks/chunks/last-board.js-BemeiK3t.js +23 -0
  222. package/build/server/chunks/chunks/log.js-R2zUph6T.js +228 -0
  223. package/build/server/chunks/chunks/loop.js-D3guWKLp.js +4038 -0
  224. package/build/server/chunks/chunks/loop2.js-B_Qd2m4y.js +67 -0
  225. package/build/server/chunks/chunks/navigation.js-DQJMz-SM.js +2 -0
  226. package/build/server/chunks/chunks/new-project.js-DNcr9JpB.js +305 -0
  227. package/build/server/chunks/chunks/next-step.js-B8Kl0Iv9.js +522 -0
  228. package/build/server/chunks/chunks/node.js-Bz2jT5wt.js +3381 -0
  229. package/build/server/chunks/chunks/now-live.svelte.js-hIaDgjJ3.js +13 -0
  230. package/build/server/chunks/chunks/now-snapshot.js-zGKLIzox.js +207 -0
  231. package/build/server/chunks/chunks/now.js-Dfm-o0Ha.js +765 -0
  232. package/build/server/chunks/chunks/onboard.js-LBqPOxyU.js +1525 -0
  233. package/build/server/chunks/chunks/ordinal.js-Bm_9QEBD.js +12 -0
  234. package/build/server/chunks/chunks/overview.js-C32iHkXD.js +1108 -0
  235. package/build/server/chunks/chunks/page-keys.svelte.js-D8vXA_8Z.js +14 -0
  236. package/build/server/chunks/chunks/patch.js-Bl7vwsUj.js +62 -0
  237. package/build/server/chunks/chunks/paths.js-DVRjNYFW.js +19 -0
  238. package/build/server/chunks/chunks/peek.js-D9sSjT9t.js +95 -0
  239. package/build/server/chunks/chunks/plan.js-DFq5ntMM.js +143 -0
  240. package/build/server/chunks/chunks/project-files-notice.js-CcqcBgUP.js +19 -0
  241. package/build/server/chunks/chunks/project-files.js-DTC4jUxy.js +52 -0
  242. package/build/server/chunks/chunks/project-folder.js-CoKgPiM0.js +22 -0
  243. package/build/server/chunks/chunks/projects.js-bw2V11od.js +989 -0
  244. package/build/server/chunks/chunks/prs.js-CLfImauu.js +118 -0
  245. package/build/server/chunks/chunks/publish.js-D2vWpIJU.js +195 -0
  246. package/build/server/chunks/chunks/pull-list.js-BCIBJdyz.js +691 -0
  247. package/build/server/chunks/chunks/qa-ask.svelte.js-8Hf1JWW2.js +47 -0
  248. package/build/server/chunks/chunks/qa-setup.js-DFOEcNxH.js +1241 -0
  249. package/build/server/chunks/chunks/quiet.js-1GKY40Ay.js +104 -0
  250. package/build/server/chunks/chunks/rail.js-BePBwOqZ.js +135 -0
  251. package/build/server/chunks/chunks/review.js-MPqnq9Gy.js +98 -0
  252. package/build/server/chunks/chunks/routing.js-B8s1QwSP.js +265 -0
  253. package/build/server/chunks/chunks/run-log.js-CnN2jOcg.js +94 -0
  254. package/build/server/chunks/chunks/run.js-COSejjLl.js +34 -0
  255. package/build/server/chunks/chunks/scout-findings.js-CqJti10a.js +940 -0
  256. package/build/server/chunks/chunks/scout.js-Bm7wQLX2.js +62 -0
  257. package/build/server/chunks/chunks/sentinels.js-BXvpnzr3.js +13 -0
  258. package/build/server/chunks/chunks/server.js-BR0D07DR.js +3803 -0
  259. package/build/server/chunks/chunks/settings-sections.js-V70W7BkZ.js +103 -0
  260. package/build/server/chunks/chunks/shared.js-BgfCUZUJ.js +776 -0
  261. package/build/server/chunks/chunks/sign-in.js-O-pBhi19.js +14 -0
  262. package/build/server/chunks/chunks/snapshot.js-BekzL_He.js +38 -0
  263. package/build/server/chunks/chunks/spend.js-BabnR69T.js +63 -0
  264. package/build/server/chunks/chunks/src.js-Cm8RAH_q.js +609 -0
  265. package/build/server/chunks/chunks/src2.js-CV8tsClO.js +1186 -0
  266. package/build/server/chunks/chunks/src3.js-h9tTEbVb.js +11222 -0
  267. package/build/server/chunks/chunks/stack.js-CMWXhMZS.js +13 -0
  268. package/build/server/chunks/chunks/standup.js-D-qBnMx4.js +103 -0
  269. package/build/server/chunks/chunks/state.js-BTDrgu7s.js +71 -0
  270. package/build/server/chunks/chunks/stream.js-D6r6iqjD.js +66 -0
  271. package/build/server/chunks/chunks/terms.js-DPZztSEn.js +88 -0
  272. package/build/server/chunks/chunks/ticket-system.js-Dj9R3XJw.js +147 -0
  273. package/build/server/chunks/chunks/ticket.js-6sj-2ZEM.js +110 -0
  274. package/build/server/chunks/chunks/timesheet.js-DfhIokoE.js +212 -0
  275. package/build/server/chunks/chunks/timesheet2.js-Cu95ddl3.js +84 -0
  276. package/build/server/chunks/chunks/to-workspace.js-DiOJP59J.js +308 -0
  277. package/build/server/chunks/chunks/toast-stack.svelte.js-CXIg3_KT.js +10 -0
  278. package/build/server/chunks/chunks/uneval.js-VnZcgzZr.js +488 -0
  279. package/build/server/chunks/chunks/utils.js-DQTBh7_6.js +1006 -0
  280. package/build/server/chunks/chunks/when-said.js-0F9asAma.js +35 -0
  281. package/build/server/chunks/chunks/workspace.js-BBdJRon9.js +212 -0
  282. package/build/server/chunks/entries/endpoints/api/board/_server.ts.js-BlYC_lpV.js +69 -0
  283. package/build/server/chunks/entries/endpoints/api/board/minimize/_server.ts.js-Wddt9YPR.js +68 -0
  284. package/build/server/chunks/entries/endpoints/api/board/move/_server.ts.js-BwZpCKx0.js +68 -0
  285. package/build/server/chunks/entries/endpoints/api/board/promote/_server.ts.js-Cw6kvkMq.js +68 -0
  286. package/build/server/chunks/entries/endpoints/api/board/pulls/_server.ts.js-DFhpbiMo.js +71 -0
  287. package/build/server/chunks/entries/endpoints/api/board/stop/_server.ts.js-D5eylDMw.js +68 -0
  288. package/build/server/chunks/entries/endpoints/api/card/_key_/answer/_server.ts.js-CG8xh52y.js +68 -0
  289. package/build/server/chunks/entries/endpoints/api/card/_key_/branch/_server.ts.js-a5_P9voA.js +40 -0
  290. package/build/server/chunks/entries/endpoints/api/card/_key_/chain/_server.ts.js-tJvQy6RK.js +70 -0
  291. package/build/server/chunks/entries/endpoints/api/card/_key_/checkouts/_server.ts.js-B2_gx6vF.js +41 -0
  292. package/build/server/chunks/entries/endpoints/api/card/_key_/choice/_server.ts.js-pmAdIQkK.js +34 -0
  293. package/build/server/chunks/entries/endpoints/api/card/_key_/comments/_id_/_server.ts.js-C5NxGWw3.js +68 -0
  294. package/build/server/chunks/entries/endpoints/api/card/_key_/comments/_server.ts.js-0rw7UNv8.js +64 -0
  295. package/build/server/chunks/entries/endpoints/api/card/_key_/commit/_server.ts.js-_yXWCOlQ.js +68 -0
  296. package/build/server/chunks/entries/endpoints/api/card/_key_/commit-diff/_server.ts.js-CRPV3z-g.js +61 -0
  297. package/build/server/chunks/entries/endpoints/api/card/_key_/commit-message/_server.ts.js-CO9mD3u6.js +82 -0
  298. package/build/server/chunks/entries/endpoints/api/card/_key_/context/_server.ts.js-7kzrigFz.js +42 -0
  299. package/build/server/chunks/entries/endpoints/api/card/_key_/delete/_server.ts.js-DH0nO9wG.js +516 -0
  300. package/build/server/chunks/entries/endpoints/api/card/_key_/file/_server.ts.js-D80SvJDi.js +35 -0
  301. package/build/server/chunks/entries/endpoints/api/card/_key_/files/_...path_/_server.ts.js-GxFjb2H0.js +34 -0
  302. package/build/server/chunks/entries/endpoints/api/card/_key_/fix/_server.ts.js-B-HAB050.js +68 -0
  303. package/build/server/chunks/entries/endpoints/api/card/_key_/knowledge/_server.ts.js-D4fN-j7X.js +81 -0
  304. package/build/server/chunks/entries/endpoints/api/card/_key_/link/_other_/_server.ts.js-C00pQDCu.js +42 -0
  305. package/build/server/chunks/entries/endpoints/api/card/_key_/log/_server.ts.js-BXW_tG-I.js +32 -0
  306. package/build/server/chunks/entries/endpoints/api/card/_key_/log/raw/_server.ts.js-pT8StZGR.js +32 -0
  307. package/build/server/chunks/entries/endpoints/api/card/_key_/message/_server.ts.js-ZMno2Hu6.js +68 -0
  308. package/build/server/chunks/entries/endpoints/api/card/_key_/models/_server.ts.js-DEZVpqO3.js +73 -0
  309. package/build/server/chunks/entries/endpoints/api/card/_key_/patch/_server.ts.js-BxfLi-Zs.js +61 -0
  310. package/build/server/chunks/entries/endpoints/api/card/_key_/peek/_server.ts.js-CsTKWIP_.js +169 -0
  311. package/build/server/chunks/entries/endpoints/api/card/_key_/pr/_server.ts.js-CsOeAXkf.js +53 -0
  312. package/build/server/chunks/entries/endpoints/api/card/_key_/pr/comments/_server.ts.js-DZ2XHOhF.js +71 -0
  313. package/build/server/chunks/entries/endpoints/api/card/_key_/pr/discuss/_server.ts.js-CO8eM0e8.js +72 -0
  314. package/build/server/chunks/entries/endpoints/api/card/_key_/pr/discussions/_server.ts.js-Lp7l0Yqv.js +71 -0
  315. package/build/server/chunks/entries/endpoints/api/card/_key_/pr/fix/_server.ts.js-CeIhjpQ4.js +68 -0
  316. package/build/server/chunks/entries/endpoints/api/card/_key_/pr/fix-all/_server.ts.js-D-DKoCpQ.js +68 -0
  317. package/build/server/chunks/entries/endpoints/api/card/_key_/pr/links/_server.ts.js-B_q3jUP3.js +72 -0
  318. package/build/server/chunks/entries/endpoints/api/card/_key_/pr/qa/_server.ts.js-BulVcJY9.js +68 -0
  319. package/build/server/chunks/entries/endpoints/api/card/_key_/pr/seen/_server.ts.js-Z06A6MS1.js +71 -0
  320. package/build/server/chunks/entries/endpoints/api/card/_key_/pr/triage/_server.ts.js-qADU4URF.js +68 -0
  321. package/build/server/chunks/entries/endpoints/api/card/_key_/pull/_server.ts.js-CHnTH9WK.js +58 -0
  322. package/build/server/chunks/entries/endpoints/api/card/_key_/push/_server.ts.js-BPdPwPo2.js +83 -0
  323. package/build/server/chunks/entries/endpoints/api/card/_key_/repos/_server.ts.js-Bjqa3Uoo.js +73 -0
  324. package/build/server/chunks/entries/endpoints/api/card/_key_/research/_server.ts.js-DzQjoHOZ.js +138 -0
  325. package/build/server/chunks/entries/endpoints/api/card/_key_/retry/_server.ts.js-CAodrXqd.js +68 -0
  326. package/build/server/chunks/entries/endpoints/api/card/_key_/send-back/_server.ts.js-CmJSnvTx.js +68 -0
  327. package/build/server/chunks/entries/endpoints/api/card/_key_/stack/_server.ts.js-DjI8S94J.js +82 -0
  328. package/build/server/chunks/entries/endpoints/api/card/_key_/tasks/_server.ts.js-BzX_nNJk.js +71 -0
  329. package/build/server/chunks/entries/endpoints/api/card/_key_/thread/_server.ts.js-Dn36Guxk.js +33 -0
  330. package/build/server/chunks/entries/endpoints/api/cards/_server.ts.js-DPMOBsvp.js +77 -0
  331. package/build/server/chunks/entries/endpoints/api/cards/context/_server.ts.js-D6y-g2O-.js +52 -0
  332. package/build/server/chunks/entries/endpoints/api/cards/next/_server.ts.js-C2se67rf.js +55 -0
  333. package/build/server/chunks/entries/endpoints/api/chain/_server.ts.js-DKO5Q8GV.js +70 -0
  334. package/build/server/chunks/entries/endpoints/api/clones/_server.ts.js-Bgcc_Beg.js +56 -0
  335. package/build/server/chunks/entries/endpoints/api/current-project/_server.ts.js-DZCtSlXs.js +81 -0
  336. package/build/server/chunks/entries/endpoints/api/evidence/timesheet/_server.ts.js-xJwzSrcl.js +32 -0
  337. package/build/server/chunks/entries/endpoints/api/folders/_server.ts.js-BdcE7k8S.js +83 -0
  338. package/build/server/chunks/entries/endpoints/api/gh/_server.ts.js-CGvM8fn7.js +66 -0
  339. package/build/server/chunks/entries/endpoints/api/gh/name/_server.ts.js-CHh3tAu7.js +36 -0
  340. package/build/server/chunks/entries/endpoints/api/health/_server.ts.js-DLUfrHo6.js +22 -0
  341. package/build/server/chunks/entries/endpoints/api/login-item/_server.ts.js-Cya7S7W6.js +77 -0
  342. package/build/server/chunks/entries/endpoints/api/notes/_server.ts.js-DaUFVqSM.js +26 -0
  343. package/build/server/chunks/entries/endpoints/api/notifications/_server.ts.js-DK6NFnII.js +76 -0
  344. package/build/server/chunks/entries/endpoints/api/now/_server.ts.js-xW0jeJdy.js +83 -0
  345. package/build/server/chunks/entries/endpoints/api/package/entry/_server.ts.js-DQyZanpo.js +35 -0
  346. package/build/server/chunks/entries/endpoints/api/projects/_server.ts.js-CzXJTj_l.js +58 -0
  347. package/build/server/chunks/entries/endpoints/api/qa-setup/_server.ts.js-DujrYbEP.js +76 -0
  348. package/build/server/chunks/entries/endpoints/api/remove-check/_server.ts.js-1KAi9LDi.js +58 -0
  349. package/build/server/chunks/entries/endpoints/api/setup/_server.ts.js-D0MKtjR7.js +69 -0
  350. package/build/server/chunks/entries/endpoints/api/tickets/jira/_server.ts.js-Z2LdOr5l.js +39 -0
  351. package/build/server/chunks/entries/endpoints/api/tickets/read/_server.ts.js-BziHtc8Y.js +68 -0
  352. package/build/server/chunks/entries/endpoints/api/tools/_server.ts.js-oyvq8i1y.js +30 -0
  353. package/build/server/chunks/entries/endpoints/api/workspace/_server.ts.js-CMGBL5cX.js +58 -0
  354. package/build/server/chunks/entries/endpoints/api/workspace/commit/_server.ts.js-BZQQJ1YG.js +66 -0
  355. package/build/server/chunks/entries/endpoints/api/workspace/patch/_server.ts.js-xrjgHECx.js +64 -0
  356. package/build/server/chunks/entries/endpoints/api/workspace/push/_server.ts.js-CTdia7Uz.js +66 -0
  357. package/build/server/chunks/entries/hooks.server.js-B0jE-ELC.js +211 -0
  358. package/build/server/chunks/entries/pages/_error.svelte.js-DPcKI5sX.js +25 -0
  359. package/build/server/chunks/entries/pages/_layout.server.ts.js-Jj3i2Th9.js +134 -0
  360. package/build/server/chunks/entries/pages/_layout.svelte.js-Cu3ghN80.js +1251 -0
  361. package/build/server/chunks/entries/pages/_page.svelte.js-DEYydBCm.js +662 -0
  362. package/build/server/chunks/entries/pages/accept/_page.server.ts.js-BF7MrA5s.js +29 -0
  363. package/build/server/chunks/entries/pages/accept/_page.svelte.js-8yPsedd-.js +54 -0
  364. package/build/server/chunks/entries/pages/b/_board_/_page.svelte.js-S9acLF3f.js +68 -0
  365. package/build/server/chunks/entries/pages/b/_board_/_page.ts.js-BcKdG_Tp.js +21 -0
  366. package/build/server/chunks/entries/pages/b/research/_page.svelte.js-FW6Hw9g5.js +68 -0
  367. package/build/server/chunks/entries/pages/b/research/_page.ts.js-Ds2AjFFK.js +13 -0
  368. package/build/server/chunks/entries/pages/evidence/_page.server.ts.js-uwu2X7bA.js +1382 -0
  369. package/build/server/chunks/entries/pages/evidence/_page.svelte.js-DBCjiT59.js +594 -0
  370. package/build/server/chunks/entries/pages/f/_...path_/_page.svelte.js-DxwJaJzh.js +58 -0
  371. package/build/server/chunks/entries/pages/knowledge/_page.server.ts.js-BAUvFEcM.js +80 -0
  372. package/build/server/chunks/entries/pages/knowledge/_page.svelte.js-D9117gHM.js +732 -0
  373. package/build/server/chunks/entries/pages/new/_page.server.ts.js-BNCQQpyw.js +110 -0
  374. package/build/server/chunks/entries/pages/new/_page.svelte.js-Ben8-N_h.js +503 -0
  375. package/build/server/chunks/entries/pages/new/idea/_page.server.ts.js-jssA29y3.js +46 -0
  376. package/build/server/chunks/entries/pages/new/idea/_page.svelte.js-XoKspqAc.js +210 -0
  377. package/build/server/chunks/entries/pages/new/task/_page.server.ts.js-CmZgfvyt.js +66 -0
  378. package/build/server/chunks/entries/pages/new/task/_page.svelte.js-BKpERKvm.js +169 -0
  379. package/build/server/chunks/entries/pages/onboard/_page.server.ts.js-pmc_pXvs.js +12 -0
  380. package/build/server/chunks/entries/pages/onboard/_page.svelte.js-C7LNK-ba.js +5 -0
  381. package/build/server/chunks/entries/pages/projects/_page.server.ts.js-BEhLRfJ_.js +12 -0
  382. package/build/server/chunks/entries/pages/projects/_page.svelte.js-OraOjsyb.js +5 -0
  383. package/build/server/chunks/entries/pages/scout/_page.server.ts.js-hQYnMHwY.js +10 -0
  384. package/build/server/chunks/entries/pages/scout/_page.svelte.js-7q4d044Z.js +40 -0
  385. package/build/server/chunks/entries/pages/scout/f/_id_/_page.server.ts.js-BN4TnSpB.js +22 -0
  386. package/build/server/chunks/entries/pages/scout/f/_id_/_page.svelte.js-GzpLhARi.js +40 -0
  387. package/build/server/chunks/entries/pages/settings/_layout.server.ts.js-B5LgqMMT.js +12 -0
  388. package/build/server/chunks/entries/pages/settings/_layout.svelte.js-CSCpV6qA.js +81 -0
  389. package/build/server/chunks/entries/pages/settings/_page.svelte.js-DNpsNFo0.js +25 -0
  390. package/build/server/chunks/entries/pages/settings/_section_/_page.server.ts.js-nRDEV3i_.js +348 -0
  391. package/build/server/chunks/entries/pages/settings/_section_/_page.svelte.js-BihUf-nY.js +1052 -0
  392. package/build/server/chunks/entries/pages/settings/integrations/_page.server.ts.js-BTuRpg8m.js +58 -0
  393. package/build/server/chunks/entries/pages/settings/integrations/_page.svelte.js-C8i8ZmZR.js +161 -0
  394. package/build/server/chunks/entries/pages/settings/mcp/_page.server.ts.js-TFISfO1a.js +925 -0
  395. package/build/server/chunks/entries/pages/settings/mcp/_page.svelte.js-D1X0TNOm.js +433 -0
  396. package/build/server/chunks/entries/pages/settings/phases/_page.server.ts.js-CgK7MTZf.js +48 -0
  397. package/build/server/chunks/entries/pages/settings/phases/_page.svelte.js-u-sTQ-ue.js +80 -0
  398. package/build/server/chunks/entries/pages/settings/project/_page.server.ts.js-CCnk9WbO.js +363 -0
  399. package/build/server/chunks/entries/pages/settings/project/_page.svelte.js-MxvNqYlQ.js +1269 -0
  400. package/build/server/chunks/entries/pages/settings/wall/_page.server.ts.js-Bt5siY_N.js +12 -0
  401. package/build/server/chunks/entries/pages/settings/wall/_page.svelte.js-CMR4zSAt.js +43 -0
  402. package/build/server/chunks/entries/pages/t/_key_/_layout.server.ts.js-W6YPvOCA.js +124 -0
  403. package/build/server/chunks/entries/pages/t/_key_/_layout.svelte.js-CK0PiWsz.js +543 -0
  404. package/build/server/chunks/entries/pages/t/_key_/_page.server.ts.js-CdB7v0WX.js +15 -0
  405. package/build/server/chunks/entries/pages/t/_key_/_tab_/_page.server.ts.js-Bksaje8R.js +75 -0
  406. package/build/server/chunks/entries/pages/t/_key_/_tab_/_page.svelte.js-9OQ2eQxu.js +4607 -0
  407. package/build/server/chunks/entries/pages/team/_page.svelte.js-BdUSXC04.js +18 -0
  408. package/build/server/chunks/entries/pages/team/_page.ts.js-DfhJmoZI.js +20 -0
  409. package/build/server/chunks/entries/pages/workspace/_page.svelte.js-DLaWe23r.js +579 -0
  410. package/build/server/chunks/handler-Dlwmumt5.js +1735 -0
  411. package/build/server/chunks/index.js-BX0fZD5G.js +3701 -0
  412. package/build/server/chunks/manifest.js-B2Of6Dj7.js +761 -0
  413. package/build/server/chunks/nodes/0.js-DSzhdY0D.js +87 -0
  414. package/build/server/chunks/nodes/1.js-j4osL1br.js +9 -0
  415. package/build/server/chunks/nodes/10.js-jkvevEFY.js +75 -0
  416. package/build/server/chunks/nodes/11.js-plyiDP2n.js +72 -0
  417. package/build/server/chunks/nodes/12.js-DwtvDAyM.js +78 -0
  418. package/build/server/chunks/nodes/13.js-BpxwqFh4.js +72 -0
  419. package/build/server/chunks/nodes/14.js-B5iNIKGy.js +15 -0
  420. package/build/server/chunks/nodes/15.js-CXCAqUsG.js +15 -0
  421. package/build/server/chunks/nodes/16.js-oxkLEH0n.js +76 -0
  422. package/build/server/chunks/nodes/17.js-B-ZJEo9K.js +76 -0
  423. package/build/server/chunks/nodes/18.js-C0OUCEux.js +9 -0
  424. package/build/server/chunks/nodes/19.js-M8EAQJdW.js +76 -0
  425. package/build/server/chunks/nodes/2.js-ZedduK-3.js +33 -0
  426. package/build/server/chunks/nodes/20.js-BHvsLNjD.js +72 -0
  427. package/build/server/chunks/nodes/21.js-eOaW4si1.js +76 -0
  428. package/build/server/chunks/nodes/22.js-CbJ6tQSs.js +38 -0
  429. package/build/server/chunks/nodes/23.js-DXk8ejlx.js +81 -0
  430. package/build/server/chunks/nodes/24.js-C4qGJc4X.js +33 -0
  431. package/build/server/chunks/nodes/25.js-Cal8uT5V.js +21 -0
  432. package/build/server/chunks/nodes/26.js-Cp5jBcrN.js +80 -0
  433. package/build/server/chunks/nodes/27.js-Do55o_cb.js +17 -0
  434. package/build/server/chunks/nodes/28.js-SNz3QVix.js +9 -0
  435. package/build/server/chunks/nodes/3.js-DyivQ5dN.js +75 -0
  436. package/build/server/chunks/nodes/4.js-BGgTTQFR.js +9 -0
  437. package/build/server/chunks/nodes/5.js-DQYA2BBI.js +31 -0
  438. package/build/server/chunks/nodes/6.js-BVTi2KFL.js +24 -0
  439. package/build/server/chunks/nodes/7.js-CnprIn3p.js +12 -0
  440. package/build/server/chunks/nodes/8.js-Bdicn369.js +50 -0
  441. package/build/server/chunks/nodes/9.js-DVclPGXf.js +9 -0
  442. package/build/shims.js +33 -0
  443. package/dist/THIRD-PARTY-NOTICES.md +659 -0
  444. package/dist/detect-BmI_gskA.js +585 -0
  445. package/dist/fonts/OFL.txt +92 -0
  446. package/dist/nolzu.js +48 -0
  447. package/dist/package-vezZOzhD.js +181 -0
  448. package/dist/shared/finish.md +110 -0
  449. package/dist/shared/knowledge.md +72 -0
  450. package/dist/shared/verdict.md +42 -0
  451. package/dist/skills/.gitkeep +0 -0
  452. package/dist/skills/nolzu-architecture/SKILL.md +140 -0
  453. package/dist/skills/nolzu-architecture/finish.md +110 -0
  454. package/dist/skills/nolzu-assess/SKILL.md +99 -0
  455. package/dist/skills/nolzu-assess/finish.md +110 -0
  456. package/dist/skills/nolzu-design/SKILL.md +115 -0
  457. package/dist/skills/nolzu-design/finish.md +110 -0
  458. package/dist/skills/nolzu-feedback/SKILL.md +107 -0
  459. package/dist/skills/nolzu-feedback/finish.md +110 -0
  460. package/dist/skills/nolzu-implement/SKILL.md +138 -0
  461. package/dist/skills/nolzu-implement/finish.md +110 -0
  462. package/dist/skills/nolzu-investigate/SKILL.md +139 -0
  463. package/dist/skills/nolzu-investigate/finish.md +110 -0
  464. package/dist/skills/nolzu-learn-repo/SKILL.md +115 -0
  465. package/dist/skills/nolzu-learn-repo/finish.md +110 -0
  466. package/dist/skills/nolzu-learn-repo/knowledge.md +72 -0
  467. package/dist/skills/nolzu-optimize/SKILL.md +82 -0
  468. package/dist/skills/nolzu-optimize/finish.md +110 -0
  469. package/dist/skills/nolzu-optimize/knowledge.md +72 -0
  470. package/dist/skills/nolzu-orient/SKILL.md +115 -0
  471. package/dist/skills/nolzu-orient/finish.md +110 -0
  472. package/dist/skills/nolzu-orient/knowledge.md +72 -0
  473. package/dist/skills/nolzu-plan/SKILL.md +165 -0
  474. package/dist/skills/nolzu-plan/finish.md +110 -0
  475. package/dist/skills/nolzu-pr-review/SKILL.md +150 -0
  476. package/dist/skills/nolzu-pr-review/finish.md +110 -0
  477. package/dist/skills/nolzu-qa/SKILL.md +177 -0
  478. package/dist/skills/nolzu-qa/finish.md +110 -0
  479. package/dist/skills/nolzu-qa/verdict.md +42 -0
  480. package/dist/skills/nolzu-refine/SKILL.md +145 -0
  481. package/dist/skills/nolzu-refine/finish.md +110 -0
  482. package/dist/skills/nolzu-research/SKILL.md +140 -0
  483. package/dist/skills/nolzu-research/finish.md +110 -0
  484. package/dist/skills/nolzu-wrapup/SKILL.md +126 -0
  485. package/dist/skills/nolzu-wrapup/finish.md +110 -0
  486. package/dist/skills/nolzu-wrapup/knowledge.md +72 -0
  487. package/dist/src-BG8LaXLS.js +723 -0
  488. package/dist/src-DPfcvRqs.js +4 -0
  489. package/dist/start-ItZOcBtM.js +362 -0
  490. package/package.json +49 -9
  491. package/bin/nolzu.js +0 -8
@@ -0,0 +1,3381 @@
1
+ import { i as isBoardKind, P as PASSES, k as keyPrefixFor } from './board.js-BxL3CjB1.js';
2
+ import { s as spendOf } from './spend.js-BabnR69T.js';
3
+ import { r as readSetting, i as isMachineKey, M as MACHINE_KEYS, v as validateSetting, p as presetProfiles, a as renamedActions, b as validateModelTable, s as startsInCardFolder, c as resolveModels, d as stageSays, e as projectRepos, f as canMove, g as phaseOnEnter, h as boardFor, j as isAction, k as presetRange, l as estimateOf, m as historyEstimate, n as estimateSum, o as siteOrigin, q as validateRepos } from './estimate.js-BHTYVTaQ.js';
4
+ import { l as localTitle, a as localKey, c as cardKeyOf, t as ticketRefProblem, b as cardKeyProblem } from './src.js-Cm8RAH_q.js';
5
+ import { m as matchPlan } from './snapshot.js-BekzL_He.js';
6
+ import { i as isScoutSourceKind } from './scout.js-Bm7wQLX2.js';
7
+ import { mkdirSync, rmSync, renameSync, readdirSync } from 'node:fs';
8
+ import { join, resolve, dirname, relative, sep, isAbsolute, basename } from 'node:path';
9
+ import { DatabaseSync } from 'node:sqlite';
10
+ import { uptime, homedir } from 'node:os';
11
+ import { randomUUID } from 'node:crypto';
12
+
13
+ //#region ../../packages/protocol/src/env.ts
14
+ function isFakeMode(env) {
15
+ return env.NOLZU_FAKE_AGENT === "1";
16
+ }
17
+ var OPTION = /^(?:[-*+]|\d+[.)])\s+(.+?):\s+(.+)$/;
18
+ var unique = (options) => new Set(options.map((option) => option.label)).size === options.length;
19
+ var fits = (options) => options.length >= 2 && options.length <= 6 && unique(options);
20
+ /**
21
+ * The answers a blocked run offered, read from the question file the finish rules ask for.
22
+ *
23
+ * All or nothing. One line that is not an answer with its meaning, a list of one, a list past the
24
+ * cap or the same answer twice, and the whole file reads as no options. The question then shows as
25
+ * plain text, the way it did before the file, and never as half a list.
26
+ */
27
+ function parseQuestionOptions(text) {
28
+ if (text === null) return null;
29
+ const options = [];
30
+ for (const raw of text.split("\n")) {
31
+ const line = raw.trim();
32
+ if (line === "" || line.startsWith("#")) continue;
33
+ const found = OPTION.exec(line.replaceAll("**", ""));
34
+ const label = found?.[1]?.trim() ?? "";
35
+ const means = found?.[2]?.trim() ?? "";
36
+ if (label === "" || means === "") return null;
37
+ options.push({
38
+ label,
39
+ means
40
+ });
41
+ }
42
+ return fits(options) ? options : null;
43
+ }
44
+ /**
45
+ * The options as a run row stores them, or null for a run that offered none.
46
+ *
47
+ * The row is the loop's own, but a hand edit or a later build may have written it, so a value that
48
+ * is not a list of answers reads as none rather than stopping the board.
49
+ */
50
+ function storedQuestionOptions(json) {
51
+ if (json === null) return null;
52
+ try {
53
+ const value = JSON.parse(json);
54
+ if (!Array.isArray(value)) return null;
55
+ const options = value.filter((one) => typeof one?.label === "string" && one.label !== "" && typeof one.means === "string").map(({ label, means }) => ({
56
+ label,
57
+ means
58
+ }));
59
+ return options.length === value.length && fits(options) ? options : null;
60
+ } catch {
61
+ return null;
62
+ }
63
+ }
64
+ //#endregion
65
+ //#region ../../packages/core/src/queue.ts
66
+ var LANES = {
67
+ stack: 1,
68
+ knowledge: 1,
69
+ scout: 1
70
+ };
71
+ var isRun = (entry, runId, project) => entry.runId === runId && (project === void 0 || entry.project === project);
72
+ function createQueue(slots) {
73
+ return {
74
+ slots,
75
+ waiting: [],
76
+ running: []
77
+ };
78
+ }
79
+ function laneFree(running, lane, alsoStarting) {
80
+ if (lane === null) return true;
81
+ const capacity = Object.hasOwn(LANES, lane) ? LANES[lane] : 1;
82
+ return [...running, ...alsoStarting].filter((entry) => entry.lane === lane).length < capacity;
83
+ }
84
+ function enqueue(state, job) {
85
+ if ([...state.waiting, ...state.running].some((entry) => entry.cardKey === job.cardKey && entry.project === job.project)) throw new Error(`${job.cardKey} already has a run in the queue. A card runs one phase at a time.`);
86
+ return {
87
+ ...state,
88
+ waiting: [...state.waiting, job]
89
+ };
90
+ }
91
+ function pick(state) {
92
+ const started = [];
93
+ const stillWaiting = [];
94
+ for (const job of state.waiting) if (state.running.length + started.length < state.slots && laneFree(state.running, job.lane, started)) started.push(job);
95
+ else stillWaiting.push(job);
96
+ return {
97
+ state: {
98
+ ...state,
99
+ waiting: stillWaiting,
100
+ running: [...state.running, ...started]
101
+ },
102
+ started
103
+ };
104
+ }
105
+ function promote(state, runId, project) {
106
+ const index = state.waiting.findIndex((entry) => isRun(entry, runId, project));
107
+ if (index <= 0) return state;
108
+ const job = state.waiting[index];
109
+ if (job === void 0) return state;
110
+ return {
111
+ ...state,
112
+ waiting: [job, ...state.waiting.filter((entry) => entry !== job)]
113
+ };
114
+ }
115
+ function remove(state, runId, project) {
116
+ return {
117
+ ...state,
118
+ waiting: state.waiting.filter((entry) => !isRun(entry, runId, project)),
119
+ running: state.running.filter((entry) => !isRun(entry, runId, project))
120
+ };
121
+ }
122
+ function waitFor(state, runId, project) {
123
+ const index = state.waiting.findIndex((entry) => isRun(entry, runId, project));
124
+ if (index === -1) return null;
125
+ const job = state.waiting[index];
126
+ if (job === void 0) return null;
127
+ return {
128
+ reason: laneFree(state.running, job.lane, []) ? "slot" : "lane",
129
+ position: index + 1
130
+ };
131
+ }
132
+ //#endregion
133
+ //#region ../../packages/core/src/scout.ts
134
+ /**
135
+ * The pure half of the Scout pipeline: normalize, fingerprint, dedup.
136
+ *
137
+ * `PROJECT.md` section 6 is the contract. Nothing here calls an engine, because fetching, counting,
138
+ * pattern matching and change detection are plain code and the agent runs only when something new
139
+ * or changed appears. A wrong answer here costs either a finding per log line, which is the noise
140
+ * Scout exists to remove, or one finding over two real problems, which hides the second.
141
+ */
142
+ var VARIABLE = [
143
+ [/\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?/g, "<time>"],
144
+ [/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi, "<id>"],
145
+ [/\b0x[0-9a-f]+\b/gi, "<id>"],
146
+ [/\b\d{1,2}:\d{2}:\d{2}(?:\.\d+)?\b/g, "<time>"],
147
+ [/\b(?=[0-9a-f]*\d)(?=[0-9a-f]*[a-f])[0-9a-f]{3,}\b/gi, "<id>"],
148
+ [/\b[a-f]{8,}\b/gi, "<id>"],
149
+ [/\d+/g, "<n>"]
150
+ ];
151
+ /**
152
+ * The invisible characters out of a line.
153
+ *
154
+ * Zero-width spaces, a zero-width joiner, a word joiner and a byte order mark. They survive a trim
155
+ * and they are not whitespace, so one of them in front of a line would give the same event a second
156
+ * fingerprint that can never merge. Every adapter that reads text a person typed or pasted owes this:
157
+ * a search term, a name or an id copied from a web page carries them, and a Windows shipper writes
158
+ * the byte order mark in front of every line.
159
+ *
160
+ * Its own function and not part of `normalize`, because `normalize` is the contract in `PROJECT.md`
161
+ * section 6 and moving the strip inside it changes every fingerprint the pipeline has ever made.
162
+ */
163
+ var visible = (text) => text.replace(/[\u200B-\u200D\u2060\uFEFF]/g, "");
164
+ /**
165
+ * One occurrence, as the event behind it.
166
+ *
167
+ * Ids, timestamps, numbers and hashes go, and the words stay, because a person reads the message on
168
+ * the finding and a line stripped to tokens tells them nothing.
169
+ */
170
+ function normalize$1(message) {
171
+ let text = message;
172
+ for (const [pattern, token] of VARIABLE) text = text.replace(pattern, token);
173
+ return text.replace(/\s+/g, " ").trim();
174
+ }
175
+ var TOKENS = /<time>|<id>|<n>/g;
176
+ var key = (message) => normalize$1(message).replace(TOKENS, "<v>");
177
+ function hash(text) {
178
+ let low = 2166136261;
179
+ let high = 2646966556;
180
+ for (let at = 0; at < text.length; at += 1) {
181
+ const code = text.charCodeAt(at);
182
+ low = Math.imul(low ^ code, 16777619) >>> 0;
183
+ high = Math.imul(high ^ code + 2654435769, 2246822507) >>> 0;
184
+ }
185
+ return high.toString(16).padStart(8, "0") + low.toString(16).padStart(8, "0");
186
+ }
187
+ /**
188
+ * The id one event keeps across its occurrences.
189
+ *
190
+ * The same fingerprint updates one finding, with its occurrence count and its last seen time,
191
+ * rather than making a second. The source kind leads the id, so a finding says at a glance which
192
+ * adapter found it and two sources can never collide.
193
+ */
194
+ function fingerprint(item) {
195
+ if (item.sourceId !== void 0 && item.sourceId !== "") return `${item.sourceKind}:${encodeURIComponent(item.sourceId)}`;
196
+ return `${item.sourceKind}:${hash([
197
+ item.errorType,
198
+ key(item.message),
199
+ item.location
200
+ ].join("\0"))}`;
201
+ }
202
+ /**
203
+ * One fetch, as the events behind it.
204
+ *
205
+ * Runs before anything is stored, so a fetch of ten thousand log lines reaches the database as the
206
+ * handful of events behind them. The order is the order each event was first seen, because that is
207
+ * the order the source reported them in and a person reads the list that way.
208
+ */
209
+ function dedup(items) {
210
+ const found = /* @__PURE__ */ new Map();
211
+ for (const item of items) {
212
+ const id = fingerprint(item);
213
+ const seen = found.get(id);
214
+ if (seen === void 0) found.set(id, {
215
+ fingerprint: id,
216
+ count: 1,
217
+ first: item,
218
+ last: item
219
+ });
220
+ else {
221
+ seen.count += 1;
222
+ seen.last = item;
223
+ }
224
+ }
225
+ return [...found.values()];
226
+ }
227
+ //#endregion
228
+ //#region ../../packages/core/src/scout-paste.ts
229
+ var PASTE = "paste";
230
+ var LINES_PER_ITEM = 50;
231
+ /**
232
+ * One paste, as the occurrences in it.
233
+ *
234
+ * Synchronous, because a paste does no IO. The cursor is the digest of the text: a person who
235
+ * pastes the same text twice has not seen the event twice, so a second read of that exact text
236
+ * carries nothing and the finding keeps the count it had. The digest is over the text as pasted and
237
+ * not the normalized text, so a paste that differs by a single character is genuinely new.
238
+ *
239
+ * One slot, so it remembers the previous paste only. A paste that alternates with another one, or
240
+ * that appends to an earlier one, is read again, and those repeats fold into the count of the finding
241
+ * that is already there.
242
+ *
243
+ * `errorType` and `location` stay empty and `sourceId` is left out, because pasted text names
244
+ * neither. Guessing an error class or a file path out of it costs findings in both directions, and
245
+ * the message alone already tells two events apart.
246
+ */
247
+ function fetchPaste(text, cursor) {
248
+ const digest = hash(text);
249
+ if (cursor === digest) return {
250
+ items: [],
251
+ cursor: digest
252
+ };
253
+ const items = [];
254
+ let held = 0;
255
+ let waiting = false;
256
+ for (const raw of text.split(/\r\n?|\n/)) {
257
+ const clean = visible(raw);
258
+ const line = clean.trim();
259
+ if (line === "") continue;
260
+ const open = items.at(-1);
261
+ const joins = /^\s/.test(clean) || line.startsWith("at ") || line.startsWith("Caused by:") || waiting;
262
+ if (open !== void 0 && held < LINES_PER_ITEM && joins) {
263
+ open.message += `\n${line}`;
264
+ held += 1;
265
+ if (!/^\s/.test(clean)) waiting = false;
266
+ continue;
267
+ }
268
+ items.push({
269
+ sourceKind: PASTE,
270
+ errorType: "",
271
+ message: line,
272
+ location: ""
273
+ });
274
+ held = 1;
275
+ waiting = line.startsWith("Traceback (most recent call last)");
276
+ }
277
+ if (items.length === 0) return {
278
+ items,
279
+ cursor: cursor ?? digest
280
+ };
281
+ return {
282
+ items,
283
+ cursor: digest
284
+ };
285
+ }
286
+ //#endregion
287
+ //#region ../../packages/core/src/scout-tickets.ts
288
+ var TICKETS = "tickets";
289
+ var SEPARATOR = " ";
290
+ var runId = (id) => `ci:${id}`;
291
+ /**
292
+ * The ticket one item is about, or null where the item is no ticket.
293
+ *
294
+ * It lives here because this file is the only one that writes `sourceId` on a ticket, and a reader
295
+ * that guessed from the stored line would have to tell `PROJ-123` from `acme/app@main`, which a
296
+ * failed run writes into the same field. A run carries no `sourceId`, so it answers null.
297
+ */
298
+ var ticketKeyOf = (item) => item.sourceKind === TICKETS && item.sourceId !== void 0 && item.sourceId !== "" ? item.sourceId : null;
299
+ /**
300
+ * One answered query, as the occurrences behind it.
301
+ *
302
+ * A ticket is not an event stream: it exists once and a check meets it once. So the cursor holds
303
+ * what the last check reported, and only an id that is not in it becomes an item. Without that, every
304
+ * check would add one to the occurrence count of every open ticket, and both lists on the Scout
305
+ * screen are ordered by the time a finding was last seen.
306
+ *
307
+ * The first check, with no cursor, therefore reports the whole page the caller asked for. The page
308
+ * is what bounds it: a backlog of five hundred tickets becomes as many findings as the caller's
309
+ * limit, and the next check adds only what came in since.
310
+ *
311
+ * A ticket sets `sourceId` to its own key, so the fingerprint is the key and a reworded title keeps
312
+ * the finding it already has. A failed run sets none: its id changes on every run, so the run number
313
+ * would give one finding per run. Without an id the fingerprint is built from `errorType`, the
314
+ * message and the location, which are the workflow and the branch, so one workflow that keeps
315
+ * failing is one finding with a count.
316
+ */
317
+ function fetchTickets(tickets, runs, cursor) {
318
+ const reported = new Set(cursor === null || cursor === "" ? [] : cursor.split(SEPARATOR));
319
+ const items = [];
320
+ const ids = [];
321
+ for (const ticket of tickets) {
322
+ ids.push(ticket.key);
323
+ if (reported.has(ticket.key)) continue;
324
+ items.push({
325
+ sourceKind: TICKETS,
326
+ errorType: "",
327
+ message: ticket.title === "" ? ticket.key : ticket.title,
328
+ location: ticket.key,
329
+ sourceId: ticket.key
330
+ });
331
+ }
332
+ for (const run of runs) {
333
+ const id = runId(run.id);
334
+ ids.push(id);
335
+ if (reported.has(id)) continue;
336
+ items.push({
337
+ sourceKind: TICKETS,
338
+ errorType: "ci",
339
+ message: `${run.workflow} failed on ${run.branch}`,
340
+ location: `${run.repo}@${run.branch}`
341
+ });
342
+ }
343
+ ids.sort();
344
+ return {
345
+ items,
346
+ cursor: ids.length === 0 ? null : ids.join(SEPARATOR)
347
+ };
348
+ }
349
+ var OWNER_REPO = /^([A-Za-z0-9._-]+)\/([A-Za-z0-9._-]+)$/;
350
+ /**
351
+ * The team keys a person typed, as the adapter takes them.
352
+ *
353
+ * Commas or spaces, because both are how a person writes a short list. Upper case, because a Linear
354
+ * team key is upper case and the case somebody typed is not worth a refusal.
355
+ */
356
+ var teamKeys = (value) => value.split(/[\s,]+/).filter((one) => one !== "").map((one) => one.toUpperCase());
357
+ /**
358
+ * The settings a person saved, as the query their system answers.
359
+ *
360
+ * Every check of a ticket source starts here, on this machine and on the server, so the two cannot
361
+ * ask GitHub two different questions from one saved source. It reaches nothing: no process, no
362
+ * socket, no keychain, no database. That is also what makes it the right place for the cheap checks.
363
+ * A repository that is not `owner/repo`, a site address that is not https and a teams field that
364
+ * holds no key are all refused here, and the caller reads a keychain only after this has answered.
365
+ * A keychain read can put an OS password dialog in front of the person, and a typo must not cost
366
+ * them that.
367
+ *
368
+ * The four systems and their settings keys are the ones the Scout source forms collect. A stored
369
+ * system this version does not know is what a source added by a later version looks like after a
370
+ * downgrade, so the last sentence says what to do about it.
371
+ */
372
+ function ticketPlan(config) {
373
+ const system = config.system ?? "";
374
+ if (system === "github") {
375
+ const named = OWNER_REPO.exec(config.repo ?? "");
376
+ if (named === null) throw new Error(`${config.repo ?? "The repository"} is not a repository name. Open the source on the Scout page and write it as owner/repo, such as acme/app.`);
377
+ return {
378
+ system,
379
+ owner: named[1] ?? "",
380
+ repo: named[2] ?? "",
381
+ query: {
382
+ limit: 30,
383
+ repos: [config.repo ?? ""],
384
+ terms: config.query
385
+ },
386
+ ciLimit: 20
387
+ };
388
+ }
389
+ if (system === "gitlab") return {
390
+ system,
391
+ project: config.project ?? "",
392
+ terms: config.query,
393
+ limit: 30
394
+ };
395
+ if (system === "jira") {
396
+ const site = config.site ?? "";
397
+ siteOrigin(site);
398
+ return {
399
+ system,
400
+ site: {
401
+ url: site,
402
+ email: config.email ?? ""
403
+ },
404
+ query: {
405
+ limit: 30,
406
+ repos: [],
407
+ terms: config.jql
408
+ }
409
+ };
410
+ }
411
+ if (system === "linear") {
412
+ const teams = teamKeys(config.teams ?? "");
413
+ if (teams.length === 0) throw new Error(`"${config.teams ?? ""}" holds no Linear team key. Open the source on the Scout page and write them as PROJ, OPS.`);
414
+ return {
415
+ system,
416
+ query: {
417
+ limit: 30,
418
+ repos: teams
419
+ }
420
+ };
421
+ }
422
+ throw new Error(`This version does not know the ticket system "${system}". Remove the source on the Scout page and add it again as GitHub, GitLab, Jira or Linear.`);
423
+ }
424
+ //#endregion
425
+ //#region ../../packages/core/src/node/migrations.ts
426
+ var migrations = [
427
+ `
428
+ CREATE TABLE projects (
429
+ id INTEGER PRIMARY KEY,
430
+ name TEXT NOT NULL
431
+ ) STRICT;
432
+
433
+ CREATE TABLE cards (
434
+ key TEXT PRIMARY KEY,
435
+ board TEXT NOT NULL,
436
+ stage TEXT NOT NULL,
437
+ state TEXT NOT NULL DEFAULT 'idle',
438
+ title TEXT NOT NULL,
439
+ summary TEXT,
440
+ extra_context TEXT,
441
+ models_json TEXT,
442
+ minimized INTEGER NOT NULL DEFAULT 0,
443
+ assignee TEXT
444
+ ) STRICT;
445
+
446
+ CREATE TABLE card_events (
447
+ id INTEGER PRIMARY KEY,
448
+ card_key TEXT NOT NULL REFERENCES cards (key) ON DELETE CASCADE,
449
+ from_stage TEXT,
450
+ to_stage TEXT NOT NULL,
451
+ who TEXT NOT NULL,
452
+ at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ')),
453
+ started_phase TEXT
454
+ ) STRICT;
455
+
456
+ CREATE INDEX card_events_card_key ON card_events (card_key);
457
+
458
+ -- No foreign key on card_key: a run can belong to a pseudo-ticket that has no card row.
459
+ CREATE TABLE runs (
460
+ id INTEGER PRIMARY KEY,
461
+ card_key TEXT NOT NULL,
462
+ phase TEXT NOT NULL,
463
+ engine TEXT NOT NULL,
464
+ model TEXT,
465
+ effort TEXT,
466
+ session_id TEXT,
467
+ tokens INTEGER,
468
+ cost_estimate REAL,
469
+ duration_ms INTEGER,
470
+ log_path TEXT,
471
+ error TEXT,
472
+ result TEXT
473
+ ) STRICT;
474
+
475
+ CREATE INDEX runs_card_key ON runs (card_key);
476
+
477
+ CREATE TABLE settings (
478
+ key TEXT PRIMARY KEY,
479
+ value TEXT NOT NULL
480
+ ) STRICT;
481
+
482
+ CREATE TABLE seq (
483
+ name TEXT PRIMARY KEY,
484
+ value INTEGER NOT NULL
485
+ ) STRICT;
486
+ `,
487
+ `
488
+ -- The run row could not answer what the agents drawer and the phase strip ask: which
489
+ -- state a run is in, which lane it holds, when it started and ended, and what it asked.
490
+ ALTER TABLE runs ADD COLUMN state TEXT;
491
+ ALTER TABLE runs ADD COLUMN lane TEXT;
492
+ ALTER TABLE runs ADD COLUMN started_at TEXT;
493
+ ALTER TABLE runs ADD COLUMN ended_at TEXT;
494
+ ALTER TABLE runs ADD COLUMN question TEXT;
495
+ ALTER TABLE runs ADD COLUMN attempt INTEGER;
496
+ ALTER TABLE runs ADD COLUMN plain_summary TEXT;
497
+
498
+ -- A run reports four token counts and a cache read costs a fraction of an input token,
499
+ -- so one total cannot produce an honest cost report. The old column goes, because two
500
+ -- sources of truth would drift apart.
501
+ ALTER TABLE runs ADD COLUMN tokens_input INTEGER;
502
+ ALTER TABLE runs ADD COLUMN tokens_output INTEGER;
503
+ ALTER TABLE runs ADD COLUMN tokens_cache_read INTEGER;
504
+ ALTER TABLE runs ADD COLUMN tokens_cache_creation INTEGER;
505
+ ALTER TABLE runs DROP COLUMN tokens;
506
+
507
+ -- Where the card came from. Everything that existed before this migration was typed by
508
+ -- hand, which is what a local ticket is.
509
+ ALTER TABLE cards ADD COLUMN source TEXT NOT NULL DEFAULT 'local';
510
+ ALTER TABLE cards ADD COLUMN source_ref TEXT;
511
+
512
+ -- Undirected, so the pair is stored once in a fixed order and the check refuses the
513
+ -- mirror image. That also refuses a card linked to itself, and it makes the primary key
514
+ -- enough to keep one row per pair. No reason column: "same parent" is computed when the
515
+ -- Add card dialog previews it, and is not a fact worth storing.
516
+ CREATE TABLE card_links (
517
+ a TEXT NOT NULL REFERENCES cards (key) ON DELETE CASCADE,
518
+ b TEXT NOT NULL REFERENCES cards (key) ON DELETE CASCADE,
519
+ PRIMARY KEY (a, b),
520
+ CHECK (a < b)
521
+ ) STRICT;
522
+
523
+ -- The primary key already covers a lookup by a, and this covers the other direction.
524
+ CREATE INDEX card_links_b ON card_links (b);
525
+ `,
526
+ `
527
+ -- One writer per data directory. Two schedulers on one folder would both claim the same cards and
528
+ -- start the same run twice, and sqlite's own lock does not prevent that: it serialises writes, it
529
+ -- does not say who owns the queue. One row only, which the check pins.
530
+ CREATE TABLE writer (
531
+ id INTEGER PRIMARY KEY CHECK (id = 1),
532
+ pid INTEGER NOT NULL,
533
+ at TEXT NOT NULL
534
+ ) STRICT;
535
+ `,
536
+ `
537
+ -- The discussion. One thread per phase, one per review action, and one "ask" thread that belongs
538
+ -- to no phase. The thread column holds the phase id, the review ref or the word ask, so a new
539
+ -- kind of thread needs no column.
540
+ --
541
+ -- run_id is the run a message belongs to: the agent message it came from, or for a person's
542
+ -- message the run whose session it continued. Null for a message typed before anything ran,
543
+ -- which the ask thread allows.
544
+ CREATE TABLE messages (
545
+ id INTEGER PRIMARY KEY,
546
+ card_key TEXT NOT NULL REFERENCES cards (key) ON DELETE CASCADE,
547
+ thread TEXT NOT NULL,
548
+ -- who wrote it: person or agent. Not a boolean, because a third writer arrives with the hubs.
549
+ author TEXT NOT NULL,
550
+ body TEXT NOT NULL,
551
+ at TEXT NOT NULL,
552
+ run_id INTEGER REFERENCES runs (id) ON DELETE SET NULL
553
+ ) STRICT;
554
+
555
+ -- Every read is one card's one thread, in order.
556
+ CREATE INDEX messages_card_thread ON messages (card_key, thread, id);
557
+ `,
558
+ `
559
+ -- One row per knowledge file a run touched. Every row of one run carries the same commit, because
560
+ -- one run is one commit, while the Knowledge screen asks per file: who taught this file, what
561
+ -- changed in it, and revert this one path.
562
+ --
563
+ -- No foreign key on card_key: a knowledge maintenance run belongs to no card and carries the
564
+ -- reserved key kb-maintenance, the same way a pseudo-ticket run does in the runs table.
565
+ --
566
+ -- commit_sha is null while a change waits for review, because there is no commit yet. status is
567
+ -- applied, reverted or pending, and the check refuses a fourth word rather than letting the
568
+ -- screen meet one it cannot draw.
569
+ CREATE TABLE knowledge_changes (
570
+ id INTEGER PRIMARY KEY,
571
+ card_key TEXT NOT NULL,
572
+ run_id INTEGER NOT NULL REFERENCES runs (id) ON DELETE CASCADE,
573
+ file_path TEXT NOT NULL,
574
+ commit_sha TEXT,
575
+ summary TEXT,
576
+ status TEXT NOT NULL CHECK (status IN ('applied', 'reverted', 'pending'))
577
+ ) STRICT;
578
+
579
+ -- The two reads the Knowledge screen makes: one file's history, and one run's whole change.
580
+ CREATE INDEX knowledge_changes_file ON knowledge_changes (file_path, id);
581
+ CREATE INDEX knowledge_changes_run ON knowledge_changes (run_id);
582
+ `,
583
+ `
584
+ -- What a QA run decided, and how its stack ended. Both belong to the run and not to the card: a
585
+ -- card checked twice has two verdicts, and the ticket page shows each run its own.
586
+ --
587
+ -- verdict is PASS, FAIL or BLOCKED, and null when the run printed no verdict line at all, which
588
+ -- is not a pass. verdict_reason carries the sentence either way, so a run with no verdict can
589
+ -- still say why the card was left for a person.
590
+ ALTER TABLE runs ADD COLUMN verdict TEXT;
591
+ ALTER TABLE runs ADD COLUMN verdict_reason TEXT;
592
+
593
+ -- The stack the run was checked against: off, up or failed, with the command's own words when
594
+ -- there are any. A stack that would not come up stops the run, and an unload that failed leaves
595
+ -- the stack up and says so.
596
+ ALTER TABLE runs ADD COLUMN stack_state TEXT;
597
+ ALTER TABLE runs ADD COLUMN stack_reason TEXT;
598
+ `,
599
+ `
600
+ -- Review adds two things a change row has to carry: the status returned, for a change a person
601
+ -- sent back instead of applying, and the note they wrote with it. sqlite cannot widen a CHECK,
602
+ -- so the table is rebuilt with the new word in it and the rows are copied over.
603
+ --
604
+ -- note belongs to the return. Every row of a returned run carries the same sentence, because a
605
+ -- person returns one run's change and the next wrap-up of that card reads that sentence in its
606
+ -- prompt.
607
+ CREATE TABLE knowledge_changes_next (
608
+ id INTEGER PRIMARY KEY,
609
+ card_key TEXT NOT NULL,
610
+ run_id INTEGER NOT NULL REFERENCES runs (id) ON DELETE CASCADE,
611
+ file_path TEXT NOT NULL,
612
+ commit_sha TEXT,
613
+ summary TEXT,
614
+ status TEXT NOT NULL CHECK (status IN ('applied', 'reverted', 'pending', 'returned')),
615
+ note TEXT
616
+ ) STRICT;
617
+
618
+ INSERT INTO knowledge_changes_next (id, card_key, run_id, file_path, commit_sha, summary, status)
619
+ SELECT id, card_key, run_id, file_path, commit_sha, summary, status FROM knowledge_changes;
620
+
621
+ DROP TABLE knowledge_changes;
622
+ ALTER TABLE knowledge_changes_next RENAME TO knowledge_changes;
623
+
624
+ CREATE INDEX knowledge_changes_file ON knowledge_changes (file_path, id);
625
+ CREATE INDEX knowledge_changes_run ON knowledge_changes (run_id);
626
+ `,
627
+ `
628
+ -- The stack of this card as Nolzu last saw it. The two run columns above are the audit trail of
629
+ -- one QA run and stay that. These two are the live state the stack panel reads, and the Load,
630
+ -- Unload and Force buttons write, because a person can take a stack up or down with no run going.
631
+ ALTER TABLE cards ADD COLUMN stack_state TEXT;
632
+ ALTER TABLE cards ADD COLUMN stack_reason TEXT;
633
+ `,
634
+ `
635
+ -- Where Scout looks. One row per source a person added, with the adapter's own settings as JSON
636
+ -- and never a secret in it: a credential goes to the OS keychain under its own name and nothing
637
+ -- of it reaches this file.
638
+ CREATE TABLE scout_sources (
639
+ id INTEGER PRIMARY KEY,
640
+ -- Which adapter fetches it. The four the first phase ships, mirroring the union in protocol.
641
+ kind TEXT NOT NULL CHECK (kind IN ('paste', 'tickets', 'sentry', 'search')),
642
+ -- What the person typed, so two sources of one kind are told apart on the screen.
643
+ label TEXT NOT NULL,
644
+ -- The adapter's own settings. A secret never goes in here, and the module that writes this
645
+ -- column is the one place that says so.
646
+ config_json TEXT NOT NULL DEFAULT '{}',
647
+ -- A source turned off keeps its row and its cursor, so turning it on again does not replay
648
+ -- everything it has already seen.
649
+ enabled INTEGER NOT NULL DEFAULT 1,
650
+ -- The two opt-ins of PROJECT.md section 6, both off until a person turns them on. A source
651
+ -- that made cards or started runs the moment it was added would act before anybody agreed.
652
+ create_cards INTEGER NOT NULL DEFAULT 0,
653
+ auto_assess INTEGER NOT NULL DEFAULT 0,
654
+ -- Where the last fetch stopped, as the adapter writes it. A person reads it on the screen, so
655
+ -- it is short text and not an opaque blob.
656
+ cursor TEXT,
657
+ last_checked TEXT,
658
+ -- What the last check failed with, in the source's own words. Null once one succeeds.
659
+ last_error TEXT
660
+ ) STRICT;
661
+ `,
662
+ `
663
+ -- What Scout found: one row per event, never one per occurrence. dedup folds a fetch into the
664
+ -- handful of events behind it before anything is stored, which is why there is no items table.
665
+ -- The two message columns below are the evidence a person reads on the detail.
666
+ CREATE TABLE scout_findings (
667
+ id INTEGER PRIMARY KEY,
668
+ -- The cascade is the whole delete. A finding whose source is gone can never be checked again,
669
+ -- and PRAGMA foreign_keys is on, so no application code has to remember this.
670
+ source_id INTEGER NOT NULL REFERENCES scout_sources (id) ON DELETE CASCADE,
671
+ -- The id one event keeps across its occurrences, as fingerprint writes it.
672
+ fingerprint TEXT NOT NULL,
673
+ -- The four kinds of PRODUCT-BRIEF.md. This is the finding's kind and not the source's: one
674
+ -- paste can hold a bug and an insight. A new finding is a bug until somebody says otherwise.
675
+ kind TEXT NOT NULL DEFAULT 'bug' CHECK (kind IN ('bug', 'regression', 'improvement', 'insight')),
676
+ -- The five open columns of the findings board and the two collapsed ones. All seven words are
677
+ -- in the check although this version only ever writes new: sqlite cannot widen a CHECK, and
678
+ -- migration 7 above is what one more word costs once there are rows, a whole table rebuilt and
679
+ -- copied over.
680
+ status TEXT NOT NULL DEFAULT 'new' CHECK (status IN ('new', 'assess', 'decide', 'started', 'done', 'parked', 'dismissed')),
681
+ -- Over every check this finding was met in, not in the last one. A check adds what its fetch
682
+ -- counted.
683
+ occurrences INTEGER NOT NULL DEFAULT 0,
684
+ -- When the event opened this row, and when it was last met. first_seen is never moved again, so
685
+ -- the detail can say how long the problem has been going on.
686
+ first_seen TEXT NOT NULL,
687
+ last_seen TEXT NOT NULL,
688
+ -- The evidence: the line as it was pasted, for the first occurrence and for the newest one. Both
689
+ -- are kept because the fingerprint reads past the ids and the numbers, so those two lines differ
690
+ -- exactly where a person needs to see that they differ. Whatever was pasted is in this file.
691
+ first_message TEXT NOT NULL,
692
+ last_message TEXT NOT NULL,
693
+ -- Where the event happens. It is part of the fingerprint, so every occurrence of one finding
694
+ -- names the same place and this column never moves. Empty where the source names no place, and
695
+ -- pasted text names none.
696
+ location TEXT NOT NULL DEFAULT '',
697
+ -- The card this finding became, once a person accepts it. No foreign key, for the reason the
698
+ -- runs table gives: the key can name a pseudo-ticket that has no card row.
699
+ card_key TEXT,
700
+ -- One finding per event per source. Two sources that see the same line get one finding each,
701
+ -- because the same problem in two places is two things to fix. The index this makes is also the
702
+ -- one a read of a source's findings uses, so no second index is needed.
703
+ UNIQUE (source_id, fingerprint)
704
+ ) STRICT;
705
+ `,
706
+ `
707
+ -- The pull request a card on the PR reviews board was made from. The title and the key are the
708
+ -- card's own columns already, and the review round is not here: the review writes it in the
709
+ -- card's folder, and no review runs yet.
710
+ ALTER TABLE cards ADD COLUMN pr_author TEXT;
711
+ -- APPROVED, CHANGES_REQUESTED or REVIEW_REQUIRED. Null on every card that is not a pull request,
712
+ -- which is what tells the two apart: a pull request always has one of the three words. The check
713
+ -- holds all three, because sqlite cannot add one to a column later without rebuilding the table.
714
+ ALTER TABLE cards ADD COLUMN pr_decision TEXT CHECK (pr_decision IN ('APPROVED', 'CHANGES_REQUESTED', 'REVIEW_REQUIRED'));
715
+ -- When the head commit was made, so the board can say how old the code under review is.
716
+ ALTER TABLE cards ADD COLUMN pr_head_at TEXT;
717
+ ALTER TABLE cards ADD COLUMN pr_draft INTEGER NOT NULL DEFAULT 0;
718
+ `,
719
+ `
720
+ -- The ticket a finding is about, for a finding a ticket query found. The key itself and not a
721
+ -- flag, because the card a person starts from such a finding is that ticket and takes its key.
722
+ -- Null on every other finding. It cannot be read off the location column: a ticket writes its key
723
+ -- there and a failed CI run writes repo@branch into the same one, so nothing told the two apart.
724
+ ALTER TABLE scout_findings ADD COLUMN external_key TEXT;
725
+ `,
726
+ `
727
+ -- How often Nolzu cloud checks this source, in minutes, and whether a new finding notifies the
728
+ -- person. Columns of the source and not a settings row, because a removed source has to take its
729
+ -- schedule with it and the row already cascades. Zero is off, which is what every source starts
730
+ -- as: a schedule runs on the server, and no source may start costing the person money by itself.
731
+ ALTER TABLE scout_sources ADD COLUMN schedule_minutes INTEGER NOT NULL DEFAULT 0;
732
+ ALTER TABLE scout_sources ADD COLUMN notify INTEGER NOT NULL DEFAULT 0;
733
+ `,
734
+ `
735
+ -- Whether the pull request of a card is still open, written when the board reads its repository
736
+ -- again. The card stays on the board after its pull request closed and says so, because a review in
737
+ -- progress is still worth reading. Null on every card that is not a pull request, and on one made
738
+ -- before this column, which was open when it was made. All three words are in the check, because
739
+ -- sqlite cannot widen one later without rebuilding the table.
740
+ ALTER TABLE cards ADD COLUMN pr_state TEXT CHECK (pr_state IN ('open', 'closed', 'merged'));
741
+ `,
742
+ `
743
+ -- The Merge column is gone, so a Delivery card standing on merge would stand on no column. PR watch is
744
+ -- the stage the pull request flow has at that place, and the card's branch is merged already, so it
745
+ -- waits there for a person to drag it on to wrap-up. The board filter keeps any other board's
746
+ -- stage of the same name where it is.
747
+ UPDATE cards SET stage = 'pr-watch' WHERE board = 'delivery' AND stage = 'merge';
748
+ `,
749
+ `
750
+ -- The repositories a card works in, as a JSON list of the paths in the project's repos setting, and
751
+ -- who set the list. Refine and plan pick it, and a person can change it, which wins over both. Null
752
+ -- on every card made before, which on a project with one repository means that repository.
753
+ ALTER TABLE cards ADD COLUMN repos TEXT;
754
+ ALTER TABLE cards ADD COLUMN repos_by TEXT CHECK (repos_by IN ('refine', 'plan', 'person'));
755
+ `,
756
+ `
757
+ -- The folder a run started in. An engine files a session under that folder, so a resume has to
758
+ -- start there too. Refine and plan on several repositories start in the project folder until the
759
+ -- card has a root, and only this column says which one a session was made in. Null on every run
760
+ -- made before.
761
+ ALTER TABLE runs ADD COLUMN cwd TEXT;
762
+ `,
763
+ `
764
+ -- The knowledge folder a change was committed in, written when a project of one repository becomes a
765
+ -- workspace and its knowledge moves to the workspace's own folder. The commit stays in the old
766
+ -- folder, so Revert cannot act on it here. Null on every change made in the folder in use now.
767
+ ALTER TABLE knowledge_changes ADD COLUMN moved_from TEXT;
768
+ `,
769
+ `
770
+ -- The time trackers a week of the timesheet is sent to, one row per destination. The token is not
771
+ -- here. It is in the OS keychain under export-<destination>, so this row can be listed and drawn
772
+ -- without asking the person for their keychain password.
773
+ CREATE TABLE exporters (
774
+ destination TEXT PRIMARY KEY CHECK (destination IN ('toggl', 'harvest', 'clockify', 'jira')),
775
+ -- The ids the destination needs, such as a workspace, as a JSON object. Never the token.
776
+ settings_json TEXT NOT NULL DEFAULT '{}',
777
+ created_at TEXT NOT NULL,
778
+ updated_at TEXT NOT NULL,
779
+ last_export_at TEXT,
780
+ -- What the last export stopped on or failed with, in the destination's words. Null once one
781
+ -- export had nothing go wrong.
782
+ last_error TEXT
783
+ ) STRICT;
784
+
785
+ -- Every entry an export tried, per destination, keyed by the external id the timesheet built. A row
786
+ -- with sent_at is never posted again, so a second press of Export writes nothing new. No foreign key
787
+ -- to exporters: a removed connection keeps these rows, so connecting the tracker again does not
788
+ -- bill the same week twice.
789
+ CREATE TABLE export_entries (
790
+ destination TEXT NOT NULL,
791
+ -- nolzu:<project id>:<card>:<day>, with no figure in it, so a day that changed keeps its id.
792
+ external_id TEXT NOT NULL,
793
+ day TEXT NOT NULL,
794
+ -- The minutes that went out, which stay as they were billed when the week changes after.
795
+ minutes INTEGER NOT NULL,
796
+ sent_at TEXT,
797
+ -- The id the destination gave the entry, so a person can follow one row to the other system.
798
+ remote_id TEXT,
799
+ -- Failed tries. Past five the entry is left alone with the sentence it last failed with.
800
+ attempts INTEGER NOT NULL DEFAULT 0,
801
+ last_error TEXT,
802
+ updated_at TEXT NOT NULL,
803
+ PRIMARY KEY (destination, external_id)
804
+ ) STRICT;
805
+ `,
806
+ `
807
+ -- A card made from a GitHub issue is keyed repo#n, like a pull request card, so it names a folder
808
+ -- and can run. A card keyed owner/repo#n moves to repo#n with every row that names it, and its full
809
+ -- name stays as its source ref. A card whose new key another card holds stays on its old key, where
810
+ -- it cannot run, as before: nothing is merged and nothing is lost. A GitLab key has the same shape,
811
+ -- group/project#n, so the rows are picked by where they came from and never by the shape of a key.
812
+ PRAGMA defer_foreign_keys = ON;
813
+
814
+ -- json_valid first, because json_extract throws on a config written by hand, and a throw here would
815
+ -- stop the app from opening.
816
+ CREATE TEMP TABLE github_sources AS
817
+ SELECT id FROM scout_sources
818
+ WHERE kind = 'tickets' AND CASE WHEN json_valid(config_json) THEN json_extract(config_json, '$.system') END = 'github';
819
+
820
+ -- Add card writes source github for an issue and nothing else. A card Scout started is external, and
821
+ -- a finding of a GitHub source names it. A card whose source was removed cannot be told apart from a
822
+ -- GitLab one any more, so it stays.
823
+ CREATE TEMP TABLE issue_keys (old TEXT PRIMARY KEY, new TEXT NOT NULL);
824
+ INSERT INTO issue_keys (old, new)
825
+ SELECT key, substr(key, instr(key, '/') + 1) FROM cards
826
+ WHERE key GLOB '*/*#[0-9]*' AND key NOT GLOB '*/*/*'
827
+ AND (source = 'github' OR (source = 'external' AND key IN (SELECT card_key FROM scout_findings WHERE source_id IN (SELECT id FROM github_sources))));
828
+ -- A new key another card holds, and the second of two cards that would land on one key. Two owners'
829
+ -- repositories of one name meet here.
830
+ DELETE FROM issue_keys WHERE new IN (SELECT key FROM cards);
831
+ DELETE FROM issue_keys WHERE old NOT IN (SELECT min(old) FROM issue_keys GROUP BY new);
832
+
833
+ UPDATE cards SET key = (SELECT new FROM issue_keys WHERE old = cards.key) WHERE key IN (SELECT old FROM issue_keys);
834
+ UPDATE card_events SET card_key = (SELECT new FROM issue_keys WHERE old = card_events.card_key) WHERE card_key IN (SELECT old FROM issue_keys);
835
+ UPDATE messages SET card_key = (SELECT new FROM issue_keys WHERE old = messages.card_key) WHERE card_key IN (SELECT old FROM issue_keys);
836
+ UPDATE runs SET card_key = (SELECT new FROM issue_keys WHERE old = runs.card_key) WHERE card_key IN (SELECT old FROM issue_keys);
837
+ UPDATE knowledge_changes SET card_key = (SELECT new FROM issue_keys WHERE old = knowledge_changes.card_key) WHERE card_key IN (SELECT old FROM issue_keys);
838
+ UPDATE scout_findings SET card_key = (SELECT new FROM issue_keys WHERE old = scout_findings.card_key) WHERE card_key IN (SELECT old FROM issue_keys);
839
+ -- A link is stored once with a before b, and the new key can sort the other way. SET reads the old
840
+ -- row on both sides, so one statement puts the pair back in order.
841
+ UPDATE card_links SET
842
+ a = min(coalesce((SELECT new FROM issue_keys WHERE old = card_links.a), a), coalesce((SELECT new FROM issue_keys WHERE old = card_links.b), b)),
843
+ b = max(coalesce((SELECT new FROM issue_keys WHERE old = card_links.a), a), coalesce((SELECT new FROM issue_keys WHERE old = card_links.b), b))
844
+ WHERE a IN (SELECT old FROM issue_keys) OR b IN (SELECT old FROM issue_keys);
845
+ -- The card key sits encoded inside the export id, nolzu:<project>:<card>:<day>. A GitHub name holds
846
+ -- no character the encoding changes but the slash and the hash.
847
+ UPDATE export_entries SET external_id = replace(external_id, ':' || replace(replace(m.old, '/', '%2F'), '#', '%23') || ':', ':' || replace(m.new, '#', '%23') || ':')
848
+ FROM issue_keys AS m
849
+ WHERE instr(export_entries.external_id, ':' || replace(replace(m.old, '/', '%2F'), '#', '%23') || ':') > 0;
850
+
851
+ -- The dedup key of a GitHub ticket finding is its key, so it moves too, or the next check would make
852
+ -- a second finding for every ticket. An owner renamed, or a repository moved to another owner, left
853
+ -- two findings for one repo#n. The one last seen is the live one and moves. The other keeps its old
854
+ -- key and is never met again.
855
+ CREATE TEMP TABLE issue_findings AS
856
+ SELECT id, new FROM (
857
+ SELECT id, 'tickets:' || substr(fingerprint, instr(fingerprint, '%2F') + 3) AS new,
858
+ row_number() OVER (PARTITION BY source_id, substr(fingerprint, instr(fingerprint, '%2F') + 3) ORDER BY last_seen DESC, id DESC) AS place
859
+ FROM scout_findings
860
+ WHERE source_id IN (SELECT id FROM github_sources) AND fingerprint GLOB 'tickets:*%2F*%23*')
861
+ WHERE place = 1;
862
+ -- OR IGNORE all the same, so a row that holds the new key already cannot stop the app from opening.
863
+ UPDATE OR IGNORE scout_findings SET
864
+ fingerprint = (SELECT new FROM issue_findings WHERE id = scout_findings.id),
865
+ external_key = CASE WHEN external_key GLOB '*/*' THEN substr(external_key, instr(external_key, '/') + 1) ELSE external_key END,
866
+ location = CASE WHEN location GLOB '*/*#*' THEN substr(location, instr(location, '/') + 1) ELSE location END
867
+ WHERE id IN (SELECT id FROM issue_findings);
868
+ -- The cursor is what the last check reported, ids with a space between them. Left as it was, the
869
+ -- next check would meet every ticket on the page again. A ci:<run> id holds no slash and stays.
870
+ -- Sorted again, the way a check writes it, because a stripped owner can change the order.
871
+ UPDATE scout_sources SET cursor = (
872
+ SELECT group_concat(id, ' ' ORDER BY id) FROM (
873
+ SELECT CASE WHEN value GLOB '*/*' THEN substr(value, instr(value, '/') + 1) ELSE value END AS id
874
+ FROM json_each('["' || replace(cursor, ' ', '","') || '"]')))
875
+ WHERE id IN (SELECT id FROM github_sources) AND cursor GLOB '*/*' AND json_valid('["' || replace(cursor, ' ', '","') || '"]');
876
+
877
+ DROP TABLE temp.issue_findings;
878
+ DROP TABLE temp.issue_keys;
879
+ DROP TABLE temp.github_sources;
880
+ `,
881
+ `
882
+ -- A card Scout started from a GitLab issue is keyed project#n, the last part of the path, like a
883
+ -- GitHub issue card, so it names a folder and can run. A card keyed group/project#n moves with every
884
+ -- row that names it, and its full name stays as its source ref. A card whose new key another card
885
+ -- holds stays on its old key, where it cannot run, as before. sqlite has no last instr, so the last
886
+ -- part of x is substr(x, length(rtrim(x, replace(x, '/', ''))) + 1): the rtrim takes off every
887
+ -- character after the last slash.
888
+ PRAGMA defer_foreign_keys = ON;
889
+
890
+ -- json_valid first, because json_extract throws on a config written by hand, and a throw here would
891
+ -- stop the app from opening.
892
+ CREATE TEMP TABLE ticket_sources AS
893
+ SELECT id, json_extract(config_json, '$.system') AS system FROM scout_sources
894
+ WHERE kind = 'tickets' AND CASE WHEN json_valid(config_json) THEN json_extract(config_json, '$.system') END IN ('github', 'gitlab');
895
+
896
+ -- Three kinds of card. An external card a finding of a GitHub or a GitLab source names was started
897
+ -- from that issue. An external card no finding names lost its source, so its system is unknown. Only
898
+ -- Start on a GitHub or a GitLab issue wrote an external card with a slash. Both take the last part
899
+ -- now, so the card moves all the same. A github card is an issue card the migration before this one
900
+ -- left on a taken key, and it gets another try. A card a source of no known system names stays.
901
+ CREATE TEMP TABLE slash_keys (old TEXT PRIMARY KEY, new TEXT NOT NULL);
902
+ INSERT INTO slash_keys (old, new)
903
+ SELECT key, substr(key, length(rtrim(key, replace(key, '/', ''))) + 1) FROM cards
904
+ WHERE key GLOB '*/*#[0-9]*'
905
+ AND (source = 'github' OR (source = 'external' AND (
906
+ key IN (SELECT card_key FROM scout_findings WHERE source_id IN (SELECT id FROM ticket_sources))
907
+ OR key NOT IN (SELECT card_key FROM scout_findings WHERE card_key IS NOT NULL))));
908
+ -- A new key another card holds, and the second of two cards that would land on one key. A GitHub
909
+ -- app#1 and a GitLab app#1 meet here, and so do two groups' projects of one name.
910
+ DELETE FROM slash_keys WHERE new IN (SELECT key FROM cards);
911
+ DELETE FROM slash_keys WHERE old NOT IN (SELECT min(old) FROM slash_keys GROUP BY new);
912
+
913
+ UPDATE cards SET key = (SELECT new FROM slash_keys WHERE old = cards.key), source_ref = coalesce(source_ref, key) WHERE key IN (SELECT old FROM slash_keys);
914
+ UPDATE card_events SET card_key = (SELECT new FROM slash_keys WHERE old = card_events.card_key) WHERE card_key IN (SELECT old FROM slash_keys);
915
+ UPDATE messages SET card_key = (SELECT new FROM slash_keys WHERE old = messages.card_key) WHERE card_key IN (SELECT old FROM slash_keys);
916
+ UPDATE runs SET card_key = (SELECT new FROM slash_keys WHERE old = runs.card_key) WHERE card_key IN (SELECT old FROM slash_keys);
917
+ UPDATE knowledge_changes SET card_key = (SELECT new FROM slash_keys WHERE old = knowledge_changes.card_key) WHERE card_key IN (SELECT old FROM slash_keys);
918
+ UPDATE scout_findings SET card_key = (SELECT new FROM slash_keys WHERE old = scout_findings.card_key) WHERE card_key IN (SELECT old FROM slash_keys);
919
+ -- A link is stored once with a before b, and the new key can sort the other way.
920
+ UPDATE card_links SET
921
+ a = min(coalesce((SELECT new FROM slash_keys WHERE old = card_links.a), a), coalesce((SELECT new FROM slash_keys WHERE old = card_links.b), b)),
922
+ b = max(coalesce((SELECT new FROM slash_keys WHERE old = card_links.a), a), coalesce((SELECT new FROM slash_keys WHERE old = card_links.b), b))
923
+ WHERE a IN (SELECT old FROM slash_keys) OR b IN (SELECT old FROM slash_keys);
924
+ -- The card key sits encoded inside the export id, nolzu:<project>:<card>:<day>. A GitLab path holds
925
+ -- no character the encoding changes but the slash and the hash.
926
+ UPDATE export_entries SET external_id = replace(external_id, ':' || replace(replace(m.old, '/', '%2F'), '#', '%23') || ':', ':' || replace(m.new, '#', '%23') || ':')
927
+ FROM slash_keys AS m
928
+ WHERE instr(export_entries.external_id, ':' || replace(replace(m.old, '/', '%2F'), '#', '%23') || ':') > 0;
929
+
930
+ -- The dedup key of a GitLab ticket finding is its key, so it moves too, or the next check would make
931
+ -- a second finding for every ticket. Read with its slashes put back, so the last part is found the
932
+ -- same way. A project moved to another group left two findings for one project#n: the one last seen
933
+ -- moves, and the other keeps its old key and is never met again. GitHub findings moved before.
934
+ CREATE TEMP TABLE slash_findings AS
935
+ SELECT id, 'tickets:' || substr(path, length(rtrim(path, replace(path, '/', ''))) + 1) AS new, source_id, last_seen FROM (
936
+ SELECT id, source_id, last_seen, replace(fingerprint, '%2F', '/') AS path FROM scout_findings
937
+ WHERE source_id IN (SELECT id FROM ticket_sources WHERE system = 'gitlab') AND fingerprint GLOB 'tickets:*%2F*%23*');
938
+ DELETE FROM slash_findings WHERE id NOT IN (
939
+ SELECT id FROM (SELECT id, row_number() OVER (PARTITION BY source_id, new ORDER BY last_seen DESC, id DESC) AS place FROM slash_findings) WHERE place = 1);
940
+ -- OR IGNORE, so a row that holds the new key already cannot stop the app from opening.
941
+ UPDATE OR IGNORE scout_findings SET
942
+ fingerprint = (SELECT new FROM slash_findings WHERE id = scout_findings.id),
943
+ external_key = CASE WHEN external_key GLOB '*/*' THEN substr(external_key, length(rtrim(external_key, replace(external_key, '/', ''))) + 1) ELSE external_key END,
944
+ location = CASE WHEN location GLOB '*/*#*' THEN substr(location, length(rtrim(location, replace(location, '/', ''))) + 1) ELSE location END
945
+ WHERE id IN (SELECT id FROM slash_findings);
946
+ -- The cursor is what the last check reported, ids with a space between them. Left as it was, the
947
+ -- next check would meet every ticket on the page again. Sorted again, the way a check writes it.
948
+ UPDATE scout_sources SET cursor = (
949
+ SELECT group_concat(id, ' ' ORDER BY id) FROM (
950
+ SELECT substr(value, length(rtrim(value, replace(value, '/', ''))) + 1) AS id
951
+ FROM json_each('["' || replace(cursor, ' ', '","') || '"]')))
952
+ WHERE id IN (SELECT id FROM ticket_sources WHERE system = 'gitlab') AND cursor GLOB '*/*' AND json_valid('["' || replace(cursor, ' ', '","') || '"]');
953
+
954
+ DROP TABLE temp.slash_findings;
955
+ DROP TABLE temp.slash_keys;
956
+ DROP TABLE temp.ticket_sources;
957
+ `,
958
+ `
959
+ -- 1 for a run that goes on from earlier work: an answer, a discussion message, a retry, a run told
960
+ -- to go on from a progress file, or a run that waited out an API error. Its cost and time say
961
+ -- nothing about a fresh start, so the estimates leave it out. Null on every row made before this column. No column kept says which kind of run
962
+ -- it was, since session_id takes the engine's id at the end and a retry was written like a first
963
+ -- run, so those rows are left out too rather than guessed.
964
+ ALTER TABLE runs ADD COLUMN resumed INTEGER CHECK (resumed IN (0, 1));
965
+ -- The model the run asked for. model takes what the engine reports at the end, a full id or a
966
+ -- label, and the estimate is looked up by the name the start line shows.
967
+ ALTER TABLE runs ADD COLUMN asked_model TEXT;
968
+ `,
969
+ `
970
+ -- The answers a blocked run offered with its question, as a JSON list of label and meaning, read
971
+ -- from the question file the run wrote. Null on a run that offered none and on every row made
972
+ -- before this column, and the question then shows as plain text.
973
+ ALTER TABLE runs ADD COLUMN question_options TEXT;
974
+ `,
975
+ `
976
+ -- The size a person picked in Add card. The chain suggestion and the small-card cost read it. Null
977
+ -- on a card with none picked and on every card made before this column.
978
+ ALTER TABLE cards ADD COLUMN size TEXT CHECK (size IN ('small', 'medium', 'large'));
979
+ `,
980
+ `
981
+ -- Why the chain a person allowed did not start the next stage after this run ended, as the sentence
982
+ -- Now shows. Null on every other run. On the run row, so it goes as soon as the card runs again.
983
+ ALTER TABLE runs ADD COLUMN chain_refused TEXT;
984
+ `,
985
+ `
986
+ -- The wait a run sits in after an API error, for the countdown on Now, the card and the log: why it
987
+ -- waits, how many tries the schedule allows, and when the next try starts in Unix milliseconds.
988
+ -- Written with each wait and cleared by the run's end. Null on every row made before these columns.
989
+ ALTER TABLE runs ADD COLUMN retry_reason TEXT;
990
+ ALTER TABLE runs ADD COLUMN retry_max INTEGER;
991
+ ALTER TABLE runs ADD COLUMN retry_until INTEGER;
992
+ `,
993
+ `
994
+ -- The one line a person wrote when they moved a card on after QA failed it ("Accept anyway"), for
995
+ -- the trail and the closed card's record. Null on every other move and on every row made before
996
+ -- this column.
997
+ ALTER TABLE card_events ADD COLUMN reason TEXT;
998
+ `,
999
+ `
1000
+ -- A person's comments on lines of a card's diff. line is the line's number in the folder when the
1001
+ -- comment was made, and line_text the line as it read then, so the line is found again after an
1002
+ -- edit moves it. commit_sha is the commit the checkout was on. sent_at stays null until the comment
1003
+ -- goes back to Implement with a send back.
1004
+ CREATE TABLE diff_comments (
1005
+ id INTEGER PRIMARY KEY,
1006
+ card_key TEXT NOT NULL REFERENCES cards (key) ON DELETE CASCADE,
1007
+ repo TEXT NOT NULL,
1008
+ file TEXT NOT NULL,
1009
+ line INTEGER NOT NULL CHECK (line > 0),
1010
+ line_text TEXT NOT NULL,
1011
+ body TEXT NOT NULL,
1012
+ commit_sha TEXT NOT NULL,
1013
+ created_at TEXT NOT NULL,
1014
+ sent_at TEXT
1015
+ ) STRICT;
1016
+
1017
+ -- Every read is one card's comments, in the order they were made.
1018
+ CREATE INDEX diff_comments_card ON diff_comments (card_key, id);
1019
+ `,
1020
+ `
1021
+ -- The ask discussion an Ask run answers in, such as ask or ask-2, so a later message goes on in the
1022
+ -- same read-only session. Null on every other run and on every row made before this column.
1023
+ ALTER TABLE runs ADD COLUMN thread TEXT;
1024
+ `,
1025
+ `
1026
+ -- The built-in preset a card follows when a person picked one on its Settings tab that differs from
1027
+ -- the project's. Null follows the project's preset, which is every card made before this column.
1028
+ ALTER TABLE cards ADD COLUMN preset TEXT CHECK (preset IN ('light', 'default', 'heavy'));
1029
+ `,
1030
+ `
1031
+ -- What tells a pull request card that its author pushed since the last review round. pr_seen_sha and
1032
+ -- pr_seen_commits are the head and the commit count the last read of GitHub saw. pr_head_sha and
1033
+ -- pr_head_commits are the same two at the start of the last review round that wrote a round file,
1034
+ -- and pr_round is that round's number. Null on every card no read or round has written, which is
1035
+ -- every card made before these columns, so none of them claims a push.
1036
+ ALTER TABLE cards ADD COLUMN pr_seen_sha TEXT;
1037
+ ALTER TABLE cards ADD COLUMN pr_seen_commits INTEGER;
1038
+ ALTER TABLE cards ADD COLUMN pr_head_sha TEXT;
1039
+ ALTER TABLE cards ADD COLUMN pr_head_commits INTEGER;
1040
+ ALTER TABLE cards ADD COLUMN pr_round INTEGER CHECK (pr_round > 0);
1041
+ `,
1042
+ `
1043
+ -- The writer lock moved to machine.db (its second migration), so one Nolzu holds the machine whatever
1044
+ -- project it opens. With this table gone, the name writer on a project connection reads the attached
1045
+ -- machine's table.
1046
+ DROP TABLE writer;
1047
+ `,
1048
+ `
1049
+ -- Who set a card's title after it was made. Refine writes a short title on a local card, and the next
1050
+ -- Refine may write another. A title a person set is never replaced. Null is the title the card was
1051
+ -- made with, which is every card made before this column.
1052
+ ALTER TABLE cards ADD COLUMN title_by TEXT CHECK (title_by IN ('refine', 'person'));
1053
+ `,
1054
+ `
1055
+ -- The plan step an epic's task was made from. The person may retitle a task before adding it, and the
1056
+ -- epic still pairs the step with that task. Null on a link made by hand or before this column, which
1057
+ -- pairs by title as before.
1058
+ ALTER TABLE card_links ADD COLUMN step TEXT;
1059
+ `,
1060
+ `
1061
+ -- The Epics board's Mockups stage and phase are Design now. An epic standing on mockups would stand on
1062
+ -- no column, and its runs, moves and discussion would name a phase no stage starts, so a resume or a
1063
+ -- thread of the old phase would not find its own history. Only Epics ever had the stage, and only its
1064
+ -- stage ever ran the phase. The card folder keeps its mockups/ files, which the readers still take.
1065
+ UPDATE cards SET stage = 'design' WHERE board = 'epics' AND stage = 'mockups';
1066
+ UPDATE card_events SET from_stage = 'design' WHERE from_stage = 'mockups' AND card_key IN (SELECT key FROM cards WHERE board = 'epics');
1067
+ UPDATE card_events SET to_stage = 'design' WHERE to_stage = 'mockups' AND card_key IN (SELECT key FROM cards WHERE board = 'epics');
1068
+ UPDATE card_events SET started_phase = 'design' WHERE started_phase = 'mockups';
1069
+ UPDATE runs SET phase = 'design' WHERE phase = 'mockups';
1070
+ UPDATE messages SET thread = 'design' WHERE thread = 'mockups';
1071
+ `,
1072
+ `
1073
+ -- Whether a run's process started in the card folder, which only Codex under its own sandbox does.
1074
+ -- A resume starts where its session started, because the paths the session wrote are relative to
1075
+ -- that folder. Null on every run made before, which started where the rule of that day said.
1076
+ ALTER TABLE runs ADD COLUMN in_card_folder INTEGER CHECK (in_card_folder IN (0, 1));
1077
+ `,
1078
+ `
1079
+ -- What the git compare after a read-only run found, as JSON (ReadOnlyBreak), so the card page shows
1080
+ -- it after a reload. Null on a run that changed nothing, and on every run that is not read-only.
1081
+ ALTER TABLE runs ADD COLUMN read_only_break TEXT;
1082
+ `,
1083
+ `
1084
+ -- The wall that held the run (WallKind), so the card shows it beside the engine. Null on every run
1085
+ -- made before, which then shows nothing rather than a guess.
1086
+ ALTER TABLE runs ADD COLUMN wall TEXT CHECK (wall IN ('macos', 'bubblewrap', 'codex', 'none'));
1087
+ `,
1088
+ `
1089
+ -- The branch name a person typed on the card page. It wins over the template, so a card with no
1090
+ -- checkout yet starts on it and Refine leaves it alone. Null on a card that keeps the template's name.
1091
+ ALTER TABLE cards ADD COLUMN branch TEXT;
1092
+ `,
1093
+ `
1094
+ -- What happened while the person was away, kept after its toast is gone (notifications.ts). The id is
1095
+ -- the event's own key, such as run:12, so a second write of one event adds no row. A card key and an
1096
+ -- address are both optional: a Scout finding names no card, and a card item links to its card.
1097
+ CREATE TABLE notifications (
1098
+ id TEXT PRIMARY KEY,
1099
+ at TEXT NOT NULL,
1100
+ kind TEXT NOT NULL CHECK (kind IN ('success', 'error', 'warning', 'info')),
1101
+ card_key TEXT,
1102
+ text TEXT NOT NULL,
1103
+ href TEXT,
1104
+ read_at TEXT
1105
+ );
1106
+ CREATE INDEX notifications_at ON notifications (at);
1107
+ `,
1108
+ `
1109
+ -- What the output check found in the files a finished run wrote, as JSON (OutputCheck). Null on a run
1110
+ -- that was not checked: one that did not end ready, an Ask, a pass, and every run made before.
1111
+ ALTER TABLE runs ADD COLUMN output_check TEXT;
1112
+ `,
1113
+ `
1114
+ -- The project's saved preset a card follows, by name, picked on its Settings tab. Null follows the
1115
+ -- built-in preset in the preset column, which is every card made before this column.
1116
+ ALTER TABLE cards ADD COLUMN saved_preset TEXT;
1117
+ `,
1118
+ `
1119
+ -- The pull requests of a Delivery card and what people wrote on them (pr-discussions.ts). Comment text
1120
+ -- stays in these tables: nothing that goes to the hub reads them. repo is owner/name in lower case,
1121
+ -- because GitHub names are case insensitive. found_by says whether the card's branch found it or a
1122
+ -- person attached it. title and state are as the last read of GitHub saw them.
1123
+ CREATE TABLE card_pulls (
1124
+ id INTEGER PRIMARY KEY,
1125
+ card_key TEXT NOT NULL REFERENCES cards (key) ON DELETE CASCADE,
1126
+ repo TEXT NOT NULL,
1127
+ number INTEGER NOT NULL CHECK (number > 0),
1128
+ url TEXT,
1129
+ title TEXT,
1130
+ state TEXT CHECK (state IN ('open', 'closed', 'merged')),
1131
+ found_by TEXT NOT NULL CHECK (found_by IN ('branch', 'attached')),
1132
+ -- When its comments were last read, null before any read.
1133
+ read_at TEXT,
1134
+ UNIQUE (card_key, repo, number)
1135
+ ) STRICT;
1136
+
1137
+ -- One row per review thread, review body or issue comment. ref is T1, T2 in the order the card first
1138
+ -- saw them, and never changes. fixed_at is when the status last became fixed, so a reviewer message
1139
+ -- after it reopens the row. needs_action is the person's override of the verdict, null when unset.
1140
+ -- fix_failed is why the last Fix of the row failed or was stopped, cleared when the next one starts.
1141
+ CREATE TABLE pr_discussions (
1142
+ id INTEGER PRIMARY KEY,
1143
+ card_key TEXT NOT NULL REFERENCES cards (key) ON DELETE CASCADE,
1144
+ pull_id INTEGER NOT NULL REFERENCES card_pulls (id) ON DELETE CASCADE,
1145
+ ref TEXT NOT NULL,
1146
+ kind TEXT NOT NULL CHECK (kind IN ('thread', 'review', 'comment')),
1147
+ github_id TEXT NOT NULL,
1148
+ path TEXT,
1149
+ line INTEGER,
1150
+ resolved INTEGER NOT NULL DEFAULT 0,
1151
+ outdated INTEGER NOT NULL DEFAULT 0,
1152
+ status TEXT NOT NULL DEFAULT 'new' CHECK (status IN ('new', 'fixing', 'fixed', 'done')),
1153
+ verdict TEXT CHECK (verdict IN ('fix', 'reject', 'clarify', 'defer', 'none')),
1154
+ summary TEXT,
1155
+ reason TEXT,
1156
+ reply TEXT,
1157
+ fix_note TEXT,
1158
+ fixed_at TEXT,
1159
+ fix_failed TEXT,
1160
+ needs_action INTEGER,
1161
+ UNIQUE (card_key, ref),
1162
+ UNIQUE (pull_id, github_id)
1163
+ ) STRICT;
1164
+
1165
+ -- The messages of a discussion. A GitHub id is unique in its discussion, so a second read adds
1166
+ -- nothing twice, and the same pull request on two cards keeps its messages on both. mine is a
1167
+ -- message by the login gh runs as, which is never unread.
1168
+ CREATE TABLE pr_messages (
1169
+ id INTEGER PRIMARY KEY,
1170
+ discussion_id INTEGER NOT NULL REFERENCES pr_discussions (id) ON DELETE CASCADE,
1171
+ github_id TEXT NOT NULL,
1172
+ author TEXT,
1173
+ body TEXT NOT NULL,
1174
+ created_at TEXT NOT NULL,
1175
+ url TEXT,
1176
+ mine INTEGER NOT NULL,
1177
+ unread INTEGER NOT NULL,
1178
+ UNIQUE (discussion_id, github_id)
1179
+ ) STRICT;
1180
+ CREATE INDEX pr_messages_discussion ON pr_messages (discussion_id, created_at);
1181
+ `,
1182
+ `
1183
+ -- The sentences an Implement run that made a commit or pushed ends with (PRF9), so the card page
1184
+ -- warns after a reload. Null on a run that moved nothing, on a Fix run, which says it on its row,
1185
+ -- and on every run made before.
1186
+ ALTER TABLE runs ADD COLUMN commit_warning TEXT;
1187
+ `,
1188
+ `
1189
+ -- The project-wide stack hook moves to Start the app: its three commands become your own commands
1190
+ -- under '*', which run once per card in the card's checkout root, as the hook ran. An answer the
1191
+ -- project already has under '*' is kept. The one answer stored before answers were per repository is
1192
+ -- turned into the map first, the way the setting's reader turns it (to its repository for a start
1193
+ -- command, else to '*'). The hook rows go either way. Each command is trimmed of spaces, tabs and line
1194
+ -- ends, as the setting's reader trims it, so a blank hook makes no answer the reader would refuse.
1195
+ INSERT INTO settings (key, value)
1196
+ SELECT 'qaApp', json_insert(
1197
+ coalesce(
1198
+ (SELECT CASE
1199
+ WHEN json_type(value) IS NOT 'object' THEN '{}'
1200
+ WHEN json_type(value, '$.mode') IS NULL THEN value
1201
+ WHEN json_extract(value, '$.mode') = 'dev' THEN json_object(json_extract(value, '$.repo'), json(value))
1202
+ ELSE json_object('*', json(value))
1203
+ END FROM settings WHERE key = 'qaApp' AND json_valid(value)),
1204
+ '{}'
1205
+ ),
1206
+ '$."*"',
1207
+ json_object(
1208
+ 'mode', 'own',
1209
+ 'start', trim(json_extract(hook.value, '$'), char(32, 9, 10, 13)),
1210
+ 'stop', (SELECT nullif(trim(json_extract(value, '$'), char(32, 9, 10, 13)), '') FROM settings WHERE key = 'stackUnloadHook' AND json_valid(value) AND json_type(value) = 'text'),
1211
+ 'status', (SELECT nullif(trim(json_extract(value, '$'), char(32, 9, 10, 13)), '') FROM settings WHERE key = 'stackStatusHook' AND json_valid(value) AND json_type(value) = 'text')
1212
+ )
1213
+ )
1214
+ FROM settings AS hook
1215
+ WHERE hook.key = 'stackHook' AND json_valid(hook.value) AND json_type(hook.value) = 'text' AND trim(json_extract(hook.value, '$'), char(32, 9, 10, 13)) <> ''
1216
+ ON CONFLICT (key) DO UPDATE SET value = excluded.value;
1217
+ DELETE FROM settings WHERE key IN ('stackHook', 'stackUnloadHook', 'stackStatusHook');
1218
+ `,
1219
+ `
1220
+ -- The subject of an Ask discussion, which its list row shows. A small pass writes it after the first
1221
+ -- answer, and a person can rename it. by_person marks a name a person gave, which the pass never
1222
+ -- writes over.
1223
+ CREATE TABLE thread_subjects (
1224
+ card_key TEXT NOT NULL REFERENCES cards (key) ON DELETE CASCADE,
1225
+ thread TEXT NOT NULL,
1226
+ subject TEXT NOT NULL,
1227
+ by_person INTEGER NOT NULL DEFAULT 0 CHECK (by_person IN (0, 1)),
1228
+ PRIMARY KEY (card_key, thread)
1229
+ ) STRICT;
1230
+ `,
1231
+ `
1232
+ -- Research is one board now, and its two kinds share their column ids: Research where a question had
1233
+ -- researching and an investigation had running, and Review where they had answer and report. A card
1234
+ -- on an old id would stand on no column. The phases keep their names, so runs and threads stay.
1235
+ UPDATE cards SET stage = 'research' WHERE (board = 'questions' AND stage = 'researching') OR (board = 'investigations' AND stage = 'running');
1236
+ UPDATE cards SET stage = 'review' WHERE (board = 'questions' AND stage = 'answer') OR (board = 'investigations' AND stage = 'report');
1237
+ UPDATE card_events SET from_stage = 'research' WHERE from_stage = 'researching' AND card_key IN (SELECT key FROM cards WHERE board = 'questions');
1238
+ UPDATE card_events SET from_stage = 'research' WHERE from_stage = 'running' AND card_key IN (SELECT key FROM cards WHERE board = 'investigations');
1239
+ UPDATE card_events SET from_stage = 'review' WHERE from_stage = 'answer' AND card_key IN (SELECT key FROM cards WHERE board = 'questions');
1240
+ UPDATE card_events SET from_stage = 'review' WHERE from_stage = 'report' AND card_key IN (SELECT key FROM cards WHERE board = 'investigations');
1241
+ UPDATE card_events SET to_stage = 'research' WHERE to_stage = 'researching' AND card_key IN (SELECT key FROM cards WHERE board = 'questions');
1242
+ UPDATE card_events SET to_stage = 'research' WHERE to_stage = 'running' AND card_key IN (SELECT key FROM cards WHERE board = 'investigations');
1243
+ UPDATE card_events SET to_stage = 'review' WHERE to_stage = 'answer' AND card_key IN (SELECT key FROM cards WHERE board = 'questions');
1244
+ UPDATE card_events SET to_stage = 'review' WHERE to_stage = 'report' AND card_key IN (SELECT key FROM cards WHERE board = 'investigations');
1245
+ `,
1246
+ `
1247
+ -- PR reviews has no Re-review column now: Agent pre-review runs every round. A card on the old column
1248
+ -- would stand on no column, so it goes to Agent pre-review, and so do its moves, so the trail names a
1249
+ -- column the board still draws. The runs keep the pr-review phase, and the rounds stay in the folder.
1250
+ UPDATE cards SET stage = 'pre-review' WHERE board = 'prreview' AND stage = 're-review';
1251
+ UPDATE card_events SET from_stage = 'pre-review' WHERE from_stage = 're-review' AND card_key IN (SELECT key FROM cards WHERE board = 'prreview');
1252
+ UPDATE card_events SET to_stage = 'pre-review' WHERE to_stage = 're-review' AND card_key IN (SELECT key FROM cards WHERE board = 'prreview');
1253
+ `,
1254
+ `
1255
+ -- The tickets a person deleted from the board, by the reference the card kept (repo#n of a pull request,
1256
+ -- owner/repo#n of an issue, PROJ-123 of Jira). The read of pull requests skips one listed here, so a
1257
+ -- deleted card does not come back on the next read. Adding the ticket again by hand takes it off.
1258
+ CREATE TABLE deleted_tickets (
1259
+ source_ref TEXT PRIMARY KEY,
1260
+ source TEXT NOT NULL,
1261
+ card_key TEXT NOT NULL,
1262
+ at TEXT NOT NULL
1263
+ ) STRICT;
1264
+ `
1265
+ ];
1266
+ var machineMigrations = [`
1267
+ -- The settings that follow the machine and not one project (MACHINE_KEYS), in the shape of a project's
1268
+ -- settings table.
1269
+ CREATE TABLE settings (
1270
+ key TEXT PRIMARY KEY,
1271
+ value TEXT NOT NULL
1272
+ ) STRICT;
1273
+
1274
+ -- The projects this machine runs, by the file of each one's database relative to the data folder.
1275
+ -- The name is one no project database uses, so the same query reads it on a machine connection and on
1276
+ -- a project connection with the machine database attached.
1277
+ CREATE TABLE project_registry (
1278
+ id INTEGER PRIMARY KEY,
1279
+ file TEXT NOT NULL UNIQUE
1280
+ ) STRICT;
1281
+ `, `
1282
+ -- One writer per machine. Two schedulers on one data folder would both claim the same cards and start
1283
+ -- the same run twice, whatever project each opened. One row only, which the check pins.
1284
+ CREATE TABLE writer (
1285
+ id INTEGER PRIMARY KEY CHECK (id = 1),
1286
+ pid INTEGER NOT NULL,
1287
+ at TEXT NOT NULL
1288
+ ) STRICT;
1289
+ `];
1290
+ //#endregion
1291
+ //#region ../../packages/core/src/node/db.ts
1292
+ var MACHINE_FILE = "machine.db";
1293
+ var FIRST_PROJECT = "nolzu.db";
1294
+ var withMachine = /* @__PURE__ */ new WeakMap();
1295
+ var machineAttached = (db) => withMachine.has(db);
1296
+ function insideDataDir(dataDir, file) {
1297
+ const path = resolve(dataDir, file);
1298
+ const from = relative(resolve(dataDir), path);
1299
+ if (from === "" || from === ".." || from.startsWith(`..${sep}`) || isAbsolute(from) || from.toLowerCase() === MACHINE_FILE) throw new Error(`The project database ${file} is not inside ${dataDir}, so Nolzu does not open it.`);
1300
+ return from;
1301
+ }
1302
+ function openDatabase(dataDir, migrations$1 = migrations, file = FIRST_PROJECT) {
1303
+ const inside = insideDataDir(dataDir, file);
1304
+ openMachine(dataDir).close();
1305
+ const db = openFile(dataDir, inside, migrations$1);
1306
+ try {
1307
+ db.prepare("ATTACH DATABASE ? AS machine").run(join(dataDir, MACHINE_FILE));
1308
+ withMachine.set(db, {
1309
+ dataDir,
1310
+ file
1311
+ });
1312
+ adoptFirstProject(db);
1313
+ if (file === "nolzu.db") takeBackProjectKeys(db);
1314
+ return db;
1315
+ } catch (error) {
1316
+ db.close();
1317
+ throw error;
1318
+ }
1319
+ }
1320
+ /**
1321
+ * A data folder from before the machine database: its `nolzu.db` becomes the first project, where it
1322
+ * lies, and its machine keys are copied by the rule of `machineRow`, for every key at once.
1323
+ *
1324
+ * One write, so a registry row means the copy is done too, and every later boot changes nothing.
1325
+ */
1326
+ function adoptFirstProject(db) {
1327
+ if (registeredProjects(db).length > 0) return;
1328
+ db.exec("BEGIN IMMEDIATE");
1329
+ try {
1330
+ if (registeredProjects(db).length === 0) {
1331
+ registerProject(db, FIRST_PROJECT);
1332
+ db.prepare(`INSERT OR IGNORE INTO machine.settings (key, value)
1333
+ SELECT key, value FROM main.settings WHERE key IN (${MACHINE_KEYS.map(() => "?").join(", ")})`).run(...MACHINE_KEYS);
1334
+ }
1335
+ db.exec("COMMIT");
1336
+ } catch (error) {
1337
+ if (db.isTransaction) db.exec("ROLLBACK");
1338
+ throw error;
1339
+ }
1340
+ }
1341
+ var BACK_TO_PROJECT = ["teamHubJobDone"];
1342
+ /**
1343
+ * Moves a key that left `MACHINE_KEYS` from the machine database back into the first project, once.
1344
+ *
1345
+ * `teamHubJobDone` was the mark of the one team socket a machine held, and that socket belonged to the
1346
+ * project open at start, which is the first project on a machine that held a team socket before
1347
+ * several projects. The machine's row is the newer one: the project's row was never written after the
1348
+ * machine database came.
1349
+ */
1350
+ function takeBackProjectKeys(db) {
1351
+ const marks = BACK_TO_PROJECT.map(() => "?").join(", ");
1352
+ if (db.prepare(`SELECT 1 FROM machine.settings WHERE key IN (${marks})`).get(...BACK_TO_PROJECT) === void 0) return;
1353
+ db.exec("BEGIN IMMEDIATE");
1354
+ try {
1355
+ db.prepare(`INSERT OR REPLACE INTO main.settings (key, value) SELECT key, value FROM machine.settings WHERE key IN (${marks})`).run(...BACK_TO_PROJECT);
1356
+ db.prepare(`DELETE FROM machine.settings WHERE key IN (${marks})`).run(...BACK_TO_PROJECT);
1357
+ db.exec("COMMIT");
1358
+ } catch (error) {
1359
+ if (db.isTransaction) db.exec("ROLLBACK");
1360
+ throw error;
1361
+ }
1362
+ }
1363
+ function openMachine(dataDir) {
1364
+ return openFile(dataDir, MACHINE_FILE, machineMigrations);
1365
+ }
1366
+ function openFile(dataDir, name, migrations) {
1367
+ const file = join(dataDir, name);
1368
+ mkdirSync(dirname(file), { recursive: true });
1369
+ const db = new DatabaseSync(file);
1370
+ try {
1371
+ db.exec("PRAGMA busy_timeout = 5000");
1372
+ db.exec("PRAGMA journal_mode = WAL");
1373
+ db.exec("PRAGMA foreign_keys = ON");
1374
+ migrate(db, file, migrations);
1375
+ return db;
1376
+ } catch (error) {
1377
+ db.close();
1378
+ throw error;
1379
+ }
1380
+ }
1381
+ var registeredProjects = (db) => db.prepare("SELECT id, file FROM project_registry ORDER BY id").all();
1382
+ function registerProject(db, file) {
1383
+ return Number(db.prepare("INSERT INTO project_registry (file) VALUES (?)").run(file).lastInsertRowid);
1384
+ }
1385
+ function openProject(dataDir, id) {
1386
+ const machine = openMachine(dataDir);
1387
+ let file;
1388
+ try {
1389
+ file = registeredProjects(machine).find((one) => one.id === id)?.file;
1390
+ } finally {
1391
+ machine.close();
1392
+ }
1393
+ if (file === void 0) throw new Error(`There is no project ${id} in ${dataDir}.`);
1394
+ return openDatabase(dataDir, migrations, file);
1395
+ }
1396
+ function projectOf(db) {
1397
+ const own = withMachine.get(db);
1398
+ const project = own === void 0 ? void 0 : registeredProjects(db).find((one) => one.file === own.file);
1399
+ return own === void 0 || project === void 0 ? void 0 : {
1400
+ dataDir: own.dataDir,
1401
+ project
1402
+ };
1403
+ }
1404
+ /**
1405
+ * A new project, for New project on a plan with several: its database in the projects folder, named by
1406
+ * the id the registry gives it, which counts on from the highest.
1407
+ *
1408
+ * Written through the machine's own connection, so a damaged first project does not stop New project.
1409
+ * A registry with no row yet opens the first project once, so a data folder that never opened it still
1410
+ * adopts `nolzu.db` as project 1 before this one.
1411
+ */
1412
+ function createProject(dataDir) {
1413
+ let machine = openMachine(dataDir);
1414
+ if (registeredProjects(machine).length === 0) {
1415
+ machine.close();
1416
+ openDatabase(dataDir).close();
1417
+ machine = openMachine(dataDir);
1418
+ }
1419
+ let id;
1420
+ try {
1421
+ id = Number(machine.prepare("INSERT INTO project_registry (id, file) SELECT next, 'projects/' || next || '.db' FROM (SELECT coalesce(max(id), 0) + 1 AS next FROM project_registry)").run().lastInsertRowid);
1422
+ } finally {
1423
+ machine.close();
1424
+ }
1425
+ return openProject(dataDir, id);
1426
+ }
1427
+ function dropProject(db) {
1428
+ const own = withMachine.get(db);
1429
+ if (own === void 0 || own.file === "nolzu.db") throw new Error("The first project cannot be taken back.");
1430
+ db.prepare("DELETE FROM project_registry WHERE file = ?").run(own.file);
1431
+ db.close();
1432
+ const path = join(own.dataDir, own.file);
1433
+ for (const end of [
1434
+ "",
1435
+ "-wal",
1436
+ "-shm"
1437
+ ]) rmSync(`${path}${end}`, { force: true });
1438
+ }
1439
+ var projectFiles = (dataDir, project) => project.file === "nolzu.db" ? dataDir : join(dataDir, "projects", String(project.id));
1440
+ function userVersion(db) {
1441
+ return db.prepare("PRAGMA user_version").get().user_version;
1442
+ }
1443
+ function migrate(db, file, migrations) {
1444
+ const start = userVersion(db);
1445
+ if (start > 0 && start < migrations.length) try {
1446
+ backup(db, join(dirname(file), "backups", basename(file, ".db")));
1447
+ } catch (error) {
1448
+ throw Object.assign(new Error(`Nolzu could not copy ${file} before updating it, so it left it as it is. ${error.message}`, { cause: error }), { errcode: error.errcode });
1449
+ }
1450
+ for (;;) {
1451
+ const version = userVersion(db);
1452
+ if (version > migrations.length) throw new Error(`${file} has schema version ${version}, and this Nolzu knows versions up to ${migrations.length}. Update Nolzu to open it.`);
1453
+ if (version === migrations.length) return;
1454
+ db.exec("BEGIN IMMEDIATE");
1455
+ try {
1456
+ const current = userVersion(db);
1457
+ const sql = migrations[current];
1458
+ if (sql !== void 0) {
1459
+ db.exec(sql);
1460
+ db.exec(`PRAGMA user_version = ${current + 1}`);
1461
+ }
1462
+ db.exec("COMMIT");
1463
+ } catch (error) {
1464
+ if (db.isTransaction) db.exec("ROLLBACK");
1465
+ throw error;
1466
+ }
1467
+ }
1468
+ }
1469
+ function nextSeq(db, name) {
1470
+ return db.prepare("INSERT INTO seq (name, value) VALUES (?, 1) ON CONFLICT (name) DO UPDATE SET value = value + 1 RETURNING value").get(name).value;
1471
+ }
1472
+ var VERSION = "snapshot";
1473
+ function bumpVersion(db) {
1474
+ return nextSeq(db, VERSION);
1475
+ }
1476
+ function boardVersion(db) {
1477
+ return db.prepare("SELECT value FROM seq WHERE name = ?").get(VERSION)?.value ?? 0;
1478
+ }
1479
+ var backupName = /^nolzu-\d{8}-\d{6}\.db$/;
1480
+ function backup(db, dir) {
1481
+ mkdirSync(dir, { recursive: true });
1482
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace(/[-:]/g, "").replace("T", "-");
1483
+ const file = join(dir, `nolzu-${stamp}.db`);
1484
+ const partial = `${file}.partial`;
1485
+ rmSync(partial, { force: true });
1486
+ try {
1487
+ db.prepare("VACUUM INTO ?").run(partial);
1488
+ renameSync(partial, file);
1489
+ } catch (error) {
1490
+ rmSync(partial, { force: true });
1491
+ throw error;
1492
+ }
1493
+ const backups = readdirSync(dir).filter((name) => backupName.test(name)).sort();
1494
+ for (const name of backups.slice(0, -7)) rmSync(join(dir, name));
1495
+ return file;
1496
+ }
1497
+ //#endregion
1498
+ //#region ../../packages/core/src/node/settings-store.ts
1499
+ var rowIn = (db, table, key) => db.prepare(`SELECT value FROM ${table} WHERE key = ?`).get(key)?.value;
1500
+ /**
1501
+ * A machine key's stored row.
1502
+ *
1503
+ * An upgrade finds every machine key in the project's table, so a key the machine database lacks is
1504
+ * copied from there once, as it is stored, and read from the machine from then on. The first boot
1505
+ * copies them all this way (`adoptFirstProject` in `db.ts`); this catches a row that turns up later,
1506
+ * such as one an older Nolzu wrote. The project's row is never written again. A connection with no
1507
+ * machine database reads its own table.
1508
+ */
1509
+ function machineRow(db, key) {
1510
+ if (!machineAttached(db)) return rowIn(db, "settings", key);
1511
+ const held = rowIn(db, "machine.settings", key);
1512
+ if (held !== void 0) return held;
1513
+ const old = rowIn(db, "main.settings", key);
1514
+ if (old === void 0) return void 0;
1515
+ db.prepare("INSERT OR IGNORE INTO machine.settings (key, value) VALUES (?, ?)").run(key, old);
1516
+ return rowIn(db, "machine.settings", key);
1517
+ }
1518
+ var rawSetting = (db, key) => isMachineKey(key) ? machineRow(db, key) : rowIn(db, "settings", key);
1519
+ var tableFor = (db, key) => isMachineKey(key) && machineAttached(db) ? "machine.settings" : "settings";
1520
+ var inWorkspace = (db) => readSetting("workspace", rawSetting(db, "workspace")).value === true;
1521
+ function getSetting(db, key) {
1522
+ return readSetting(key, rawSetting(db, key), key === "repos" && inWorkspace(db)).value;
1523
+ }
1524
+ function projectOutsideGit(db) {
1525
+ const repos = getSetting(db, "repos");
1526
+ return getSetting(db, "projectPath") !== null && getSetting(db, "workspace") !== true && repos !== null && !repos.some((repo) => repo.path === ".");
1527
+ }
1528
+ function projectProfiles(db) {
1529
+ return presetProfiles(getSetting(db, "engineProfiles"), getSetting(db, "presetEngine"));
1530
+ }
1531
+ function checked(db, key, value) {
1532
+ const result = validateSetting(key, value, key === "repos" && inWorkspace(db));
1533
+ if (!result.ok || key !== "workspace") return result;
1534
+ const raw = rawSetting(db, "repos");
1535
+ let stored = null;
1536
+ try {
1537
+ stored = raw === void 0 ? null : JSON.parse(raw);
1538
+ } catch {}
1539
+ const refused = stored === null ? null : validateRepos(stored, value === true);
1540
+ return refused === null ? result : {
1541
+ ok: false,
1542
+ message: refused
1543
+ };
1544
+ }
1545
+ function settingProblem(db, key, value) {
1546
+ const result = checked(db, key, value);
1547
+ return result.ok ? null : result.message;
1548
+ }
1549
+ function writeSetting(db, key, value) {
1550
+ const result = checked(db, key, value);
1551
+ if (!result.ok) throw new Error(result.message);
1552
+ db.prepare(`INSERT INTO ${tableFor(db, key)} (key, value) VALUES (?, ?) ON CONFLICT (key) DO UPDATE SET value = excluded.value`).run(key, JSON.stringify(result.value));
1553
+ bumpVersion(db);
1554
+ }
1555
+ //#endregion
1556
+ //#region ../../packages/core/src/node/cards.ts
1557
+ async function moveCard(db, board, key, to, startRun, who = "you", reason = null) {
1558
+ let phase;
1559
+ db.exec("BEGIN IMMEDIATE");
1560
+ try {
1561
+ const card = db.prepare("SELECT stage, state FROM cards WHERE key = ? AND board = ?").get(key, board.kind);
1562
+ if (!card) throw new Error(`The ${board.kind} board has no card ${key}.`);
1563
+ if (!board.stages.some((stage) => stage.id === to)) throw new Error(`The ${board.kind} board has no ${to} column, so ${key} cannot move there.`);
1564
+ if (!canMove(board, card, to)) throw new Error(`${key} cannot move from ${card.stage} to ${to} while it is ${card.state}. A card moves one stage forward or any number back, and never while it is queued or running.`);
1565
+ phase = phaseOnEnter(board, card.stage, to);
1566
+ recordMove(db, key, card.stage, to, who, phase ?? null, reason);
1567
+ db.prepare("UPDATE cards SET stage = ?, state = ? WHERE key = ?").run(to, phase ? "queued" : "idle", key);
1568
+ bumpVersion(db);
1569
+ db.exec("COMMIT");
1570
+ } catch (error) {
1571
+ if (db.isTransaction) db.exec("ROLLBACK");
1572
+ throw error;
1573
+ }
1574
+ if (!phase) return;
1575
+ try {
1576
+ await startRun(key, phase);
1577
+ } catch (error) {
1578
+ db.prepare("UPDATE cards SET state = 'failed' WHERE key = ?").run(key);
1579
+ throw error;
1580
+ }
1581
+ }
1582
+ function recordMove(db, key, from, to, who, startedPhase, reason = null) {
1583
+ db.prepare("INSERT INTO card_events (card_key, from_stage, to_stage, who, started_phase, reason) VALUES (?, ?, ?, ?, ?, ?)").run(key, from, to, who, startedPhase, reason);
1584
+ }
1585
+ function allCardMoves(db) {
1586
+ return db.prepare("SELECT id, card_key, from_stage, to_stage, who, at, started_phase FROM card_events ORDER BY id").all().map((row) => ({
1587
+ id: row.id,
1588
+ cardKey: row.card_key,
1589
+ fromStage: row.from_stage,
1590
+ toStage: row.to_stage,
1591
+ who: row.who,
1592
+ at: row.at,
1593
+ startedPhase: row.started_phase
1594
+ }));
1595
+ }
1596
+ function setMinimized(db, key, minimized) {
1597
+ if (db.prepare("UPDATE cards SET minimized = ? WHERE key = ?").run(minimized ? 1 : 0, key).changes === 0) return false;
1598
+ bumpVersion(db);
1599
+ return true;
1600
+ }
1601
+ function seenHead(db, key) {
1602
+ return db.prepare("SELECT pr_seen_sha AS sha, pr_seen_commits AS commits FROM cards WHERE key = ?").get(key) ?? {
1603
+ sha: null,
1604
+ commits: null
1605
+ };
1606
+ }
1607
+ /**
1608
+ * The round a review run wrote, and the head it read. A later read that sees another head is how the
1609
+ * card says "1 new commit", and how a card that waits on the author goes back to Incoming
1610
+ * (`refreshPulls`). No round starts by itself: that is a person's drop on Agent pre-review.
1611
+ */
1612
+ function savePullRound(db, key, round, head) {
1613
+ db.prepare("UPDATE cards SET pr_round = ?, pr_head_sha = ?, pr_head_commits = ? WHERE key = ?").run(round, head.sha, head.commits, key);
1614
+ bumpVersion(db);
1615
+ }
1616
+ /**
1617
+ * The board a card belongs to, or null when there is no such card.
1618
+ *
1619
+ * A stage id repeats across boards: `inbox`, `refine`, `plan`, `review` and `wrapup` are on Epics
1620
+ * as well as on Delivery. So a reader that takes a card's stage against the wrong board's stage
1621
+ * list answers about another board's columns rather than answering nothing, which is the failure
1622
+ * this exists to stop.
1623
+ */
1624
+ function boardOfCard(db, key) {
1625
+ const row = db.prepare("SELECT board FROM cards WHERE key = ?").get(key);
1626
+ return row !== void 0 && isBoardKind(row.board) ? row.board : null;
1627
+ }
1628
+ function createCard(db, card) {
1629
+ const problem = cardKeyProblem(card.key);
1630
+ if (problem !== null) throw new Error(`${problem} No card was made.`);
1631
+ if (db.prepare("SELECT key FROM cards WHERE key = ?").get(card.key) !== void 0) throw new Error(`${card.key} is already on the board. Open that card, or use another key.`);
1632
+ const pull = card.pull ?? null;
1633
+ db.prepare(`INSERT INTO cards (key, board, stage, title, summary, source, source_ref, pr_author, pr_decision, pr_head_at, pr_draft, pr_seen_sha, pr_seen_commits, size)
1634
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(card.key, card.board, card.stage, card.title, card.summary ?? null, card.source ?? "local", card.sourceRef ?? null, pull?.author ?? null, pull?.decision ?? null, pull?.headCommittedAt ?? null, pull?.draft === true ? 1 : 0, pull?.headSha ?? null, pull?.commits ?? null, card.size ?? null);
1635
+ if (card.sourceRef != null) db.prepare("DELETE FROM deleted_tickets WHERE source_ref = ?").run(card.sourceRef);
1636
+ bumpVersion(db);
1637
+ }
1638
+ var ticketSeq = (projectId, prefix) => `ticket:${projectId}:${prefix}`;
1639
+ function peekLocalKey(db, projectId, prefix) {
1640
+ let n = (db.prepare("SELECT value FROM seq WHERE name = ?").get(ticketSeq(projectId, prefix))?.value ?? 0) + 1;
1641
+ while (db.prepare("SELECT key FROM cards WHERE key = ?").get(localKey(prefix, n)) !== void 0) n += 1;
1642
+ return {
1643
+ key: localKey(prefix, n),
1644
+ n
1645
+ };
1646
+ }
1647
+ function createLocalTicket(db, ticket) {
1648
+ const prefix = keyPrefixFor(ticket.board ?? "delivery", ticket.prefix);
1649
+ const { key, n } = peekLocalKey(db, ticket.projectId, prefix);
1650
+ db.prepare("INSERT INTO seq (name, value) VALUES (?, ?) ON CONFLICT (name) DO UPDATE SET value = excluded.value").run(ticketSeq(ticket.projectId, prefix), n);
1651
+ const typed = ticket.title.trim();
1652
+ const title = localTitle(typed);
1653
+ const description = ticket.description.trim();
1654
+ const summary = title === typed ? description : description === "" ? typed : `${typed}\n\n${description}`;
1655
+ createCard(db, {
1656
+ key,
1657
+ board: ticket.board ?? "delivery",
1658
+ stage: ticket.stage ?? "inbox",
1659
+ title,
1660
+ summary: summary === "" ? null : summary,
1661
+ size: ticket.size ?? null
1662
+ });
1663
+ return { key };
1664
+ }
1665
+ /**
1666
+ * A card's title, set by Refine or by a person. Answers whether it changed.
1667
+ *
1668
+ * Refine sets it only on a local card: a GitHub or Jira card keeps the title its ticket has. It never
1669
+ * replaces a title a person set. Refine puts the old title in an empty description first, so the
1670
+ * idea a card was made from is not lost.
1671
+ */
1672
+ function setCardTitle(db, key, title, by) {
1673
+ const next = localTitle(title);
1674
+ if (next === "") return false;
1675
+ const card = db.prepare("SELECT title, summary, source, title_by FROM cards WHERE key = ?").get(key);
1676
+ if (card === void 0 || card.title === next) return false;
1677
+ if ((card.source !== "local" || card.title_by === "person")) return false;
1678
+ const summary = (card.summary ?? "").trim() === "" ? card.title : card.summary;
1679
+ db.prepare("UPDATE cards SET title = ?, summary = ?, title_by = ? WHERE key = ?").run(next, summary, by, key);
1680
+ bumpVersion(db);
1681
+ return true;
1682
+ }
1683
+ function linkCards(db, one, other) {
1684
+ if (one === other) throw new Error(`${one} cannot be linked to itself.`);
1685
+ const [a, b] = one < other ? [one, other] : [other, one];
1686
+ const missing = [a, b].find((key) => db.prepare("SELECT key FROM cards WHERE key = ?").get(key) === void 0);
1687
+ if (missing !== void 0) throw new Error(`The board has no card ${missing}, so it cannot be linked.`);
1688
+ db.prepare("INSERT OR IGNORE INTO card_links (a, b) VALUES (?, ?)").run(a, b);
1689
+ }
1690
+ function relatedCards(db, key) {
1691
+ return db.prepare(`SELECT c.key, c.title FROM card_links l JOIN cards c ON c.key = CASE WHEN l.a = ? THEN l.b ELSE l.a END
1692
+ WHERE l.a = ? OR l.b = ? ORDER BY c.key`).all(key, key, key);
1693
+ }
1694
+ function epicOfTask(db, key) {
1695
+ return db.prepare(`SELECT e.key, e.title FROM cards t
1696
+ JOIN card_links l ON l.a = t.key OR l.b = t.key
1697
+ JOIN cards e ON e.key = CASE WHEN l.a = t.key THEN l.b ELSE l.a END AND e.board = 'epics'
1698
+ WHERE t.key = ? AND t.board = 'delivery' ORDER BY e.rowid LIMIT 1`).get(key) ?? null;
1699
+ }
1700
+ function unlinkCards(db, one, other) {
1701
+ const [a, b] = one < other ? [one, other] : [other, one];
1702
+ return db.prepare("DELETE FROM card_links WHERE a = ? AND b = ?").run(a, b).changes > 0;
1703
+ }
1704
+ function setExtraContext(db, key, text) {
1705
+ const value = text.trim() === "" ? null : text;
1706
+ const changed = db.prepare("UPDATE cards SET extra_context = ? WHERE key = ?").run(value, key).changes > 0;
1707
+ if (changed) bumpVersion(db);
1708
+ return changed;
1709
+ }
1710
+ function cardModels(db, key) {
1711
+ const row = db.prepare("SELECT models_json FROM cards WHERE key = ?").get(key);
1712
+ if (row?.models_json == null) return null;
1713
+ try {
1714
+ const table = renamedActions(JSON.parse(row.models_json));
1715
+ return validateModelTable(table) === null ? table : null;
1716
+ } catch {
1717
+ return null;
1718
+ }
1719
+ }
1720
+ function setCardModels(db, key, table) {
1721
+ if (db.prepare("UPDATE cards SET models_json = ? WHERE key = ?").run(table === null ? null : JSON.stringify(table), key).changes === 0) return false;
1722
+ bumpVersion(db);
1723
+ return true;
1724
+ }
1725
+ function cardPreset(db, key) {
1726
+ return db.prepare("SELECT preset FROM cards WHERE key = ?").get(key)?.preset ?? getSetting(db, "modelPreset");
1727
+ }
1728
+ /**
1729
+ * Moves a card onto a preset and clears its own rows in one write (owner question 25), so "follows
1730
+ * Heavy" means Heavy and nothing the card set before. The project's own preset is stored as null, so
1731
+ * the card keeps following the project when the project changes preset later. A project on a saved
1732
+ * preset is not on the built-in one under it, so a pick of that one is stored. False when there is no
1733
+ * such card.
1734
+ */
1735
+ function followPreset(db, key, preset) {
1736
+ const stored = preset === getSetting(db, "modelPreset") && getSetting(db, "savedPreset") === null ? null : preset;
1737
+ if (db.prepare("UPDATE cards SET preset = ?, saved_preset = NULL, models_json = NULL WHERE key = ?").run(stored, key).changes === 0) return false;
1738
+ bumpVersion(db);
1739
+ return true;
1740
+ }
1741
+ function cardFollowsProject(db, key) {
1742
+ const row = db.prepare("SELECT preset, saved_preset FROM cards WHERE key = ?").get(key);
1743
+ return row !== void 0 && row.preset === null && row.saved_preset === null;
1744
+ }
1745
+ function cardSavedPreset(db, key) {
1746
+ const name = db.prepare("SELECT saved_preset FROM cards WHERE key = ?").get(key)?.saved_preset ?? null;
1747
+ return name === null ? null : getSetting(db, "savedPresets").find((one) => one.name === name) ?? null;
1748
+ }
1749
+ /**
1750
+ * The table a card's own rows sit on: its saved preset's, or the project's rows.
1751
+ *
1752
+ * A saved preset holds the engine, model and effort of every phase, so it takes the place of the
1753
+ * project's rows and not of the built-in preset under them. Every reader that resolves a card's
1754
+ * models asks this beside `cardPreset`, so the tab, the board and the run agree.
1755
+ */
1756
+ function cardBase(db, key) {
1757
+ return cardSavedPreset(db, key)?.models ?? getSetting(db, "models");
1758
+ }
1759
+ function followSavedPreset(db, key, name) {
1760
+ if (db.prepare("UPDATE cards SET preset = NULL, saved_preset = ?, models_json = NULL WHERE key = ?").run(name, key).changes === 0) return false;
1761
+ bumpVersion(db);
1762
+ return true;
1763
+ }
1764
+ function renameCardPresets(db, from, to) {
1765
+ if (db.prepare("UPDATE cards SET saved_preset = ? WHERE saved_preset = ?").run(to, from).changes > 0) bumpVersion(db);
1766
+ }
1767
+ var projectPaths = (db) => projectRepos({
1768
+ repos: getSetting(db, "repos"),
1769
+ baseBranch: getSetting(db, "baseBranch")
1770
+ }).map((repo) => repo.path);
1771
+ function cardRepos(db, key) {
1772
+ const row = db.prepare("SELECT repos, repos_by FROM cards WHERE key = ?").get(key);
1773
+ if (row?.repos == null || row.repos_by == null) return null;
1774
+ try {
1775
+ const repos = JSON.parse(row.repos);
1776
+ return Array.isArray(repos) && repos.length > 0 && repos.every((repo) => typeof repo === "string") ? {
1777
+ repos,
1778
+ by: row.repos_by
1779
+ } : null;
1780
+ } catch {
1781
+ return null;
1782
+ }
1783
+ }
1784
+ function setCardRepos(db, key, repos, by) {
1785
+ const unique = [...new Set(repos)];
1786
+ const known = projectPaths(db);
1787
+ const unknown = unique.find((repo) => !known.includes(repo));
1788
+ if (unknown !== void 0) throw new Error(`The project has no repository ${unknown}.`);
1789
+ const value = unique.length === 0 ? null : JSON.stringify(unique);
1790
+ const guard = by === "person" ? "" : " AND (repos_by IS NULL OR repos_by != 'person')";
1791
+ if (db.prepare(`UPDATE cards SET repos = ?, repos_by = ? WHERE key = ?${guard}`).run(value, value === null ? null : by, key).changes === 0) return false;
1792
+ bumpVersion(db);
1793
+ return true;
1794
+ }
1795
+ function reposOfCard(db, key) {
1796
+ if (db.prepare("SELECT 1 FROM cards WHERE key = ?").get(key) === void 0) return null;
1797
+ const project = projectPaths(db);
1798
+ if (project.length === 1) return project;
1799
+ const stored = cardRepos(db, key)?.repos ?? [];
1800
+ const picked = project.filter((repo) => stored.includes(repo));
1801
+ if (picked.length === 0) return null;
1802
+ return project[0] === "." && picked[0] !== "." ? [".", ...picked] : picked;
1803
+ }
1804
+ function cardStack(db, key) {
1805
+ const row = db.prepare("SELECT stack_state, stack_reason FROM cards WHERE key = ?").get(key);
1806
+ return row?.stack_state == null ? null : {
1807
+ state: row.stack_state,
1808
+ reason: row.stack_reason
1809
+ };
1810
+ }
1811
+ function setCardStack(db, key, stack) {
1812
+ db.prepare("UPDATE cards SET stack_state = ?, stack_reason = ? WHERE key = ?").run(stack.state, stack.reason, key);
1813
+ bumpVersion(db);
1814
+ }
1815
+ var deletedKey = (key) => `${key} (deleted)`;
1816
+ /**
1817
+ * Deletes a card and its rows, in one transaction. Answers the log files of its runs, which the caller
1818
+ * removes after the commit, or the sentence the delete was refused with when a run is queued or going.
1819
+ * Whether this process holds the card's app is the caller's to ask, right before, since core cannot see
1820
+ * it. The stored app state alone refuses nothing: it outlives a restart, and often nothing resets it.
1821
+ *
1822
+ * The card's moves, discussion, links, diff comments, pull requests and thread names go with the card
1823
+ * row, by their foreign keys. Its bell rows go too, since they link to a page that is gone. The runs and
1824
+ * knowledge changes stay, under `deletedKey`: the time and cost were spent, and the timesheet, the spend
1825
+ * and an export already sent still count them. A Scout finding keeps the old key, so it says its card
1826
+ * is gone and offers Start again. A ticket card is recorded in `deleted_tickets`, so a read of its
1827
+ * system leaves it off.
1828
+ */
1829
+ function deleteCardRows(db, key) {
1830
+ db.exec("BEGIN IMMEDIATE");
1831
+ try {
1832
+ const card = db.prepare("SELECT state, source, source_ref FROM cards WHERE key = ?").get(key);
1833
+ const run = db.prepare("SELECT state FROM runs WHERE card_key = ? AND state IN ('queued', 'running') ORDER BY state = 'running' DESC LIMIT 1").get(key);
1834
+ const busy = card?.state === "running" || run?.state === "running" ? "going" : card?.state === "queued" || run !== void 0 ? "in the queue" : null;
1835
+ const refused = card === void 0 ? `There is no card ${key} on the board, so there is nothing to delete.` : busy !== null ? `${key} has a run ${busy}. Stop the run first, then delete the card.` : null;
1836
+ if (refused !== null || card === void 0) {
1837
+ db.exec("ROLLBACK");
1838
+ return { refused: refused ?? "" };
1839
+ }
1840
+ const logs = db.prepare("SELECT log_path FROM runs WHERE card_key = ? AND coalesce(log_path, '') <> ''").all(key).map((row) => row.log_path);
1841
+ if (card.source !== "local" && card.source_ref !== null) db.prepare("INSERT OR REPLACE INTO deleted_tickets (source_ref, source, card_key, at) VALUES (?, ?, ?, ?)").run(card.source_ref, card.source, key, (/* @__PURE__ */ new Date()).toISOString());
1842
+ const gone = deletedKey(key);
1843
+ db.prepare("UPDATE runs SET card_key = ?, log_path = NULL WHERE card_key = ?").run(gone, key);
1844
+ db.prepare("UPDATE knowledge_changes SET card_key = ? WHERE card_key = ?").run(gone, key);
1845
+ const from = `:${encodeURIComponent(key)}:`;
1846
+ db.prepare("UPDATE OR IGNORE export_entries SET external_id = replace(external_id, ?, ?) WHERE instr(external_id, ?) > 0").run(from, `:${encodeURIComponent(gone)}:`, from);
1847
+ db.prepare("DELETE FROM notifications WHERE card_key = ?").run(key);
1848
+ db.prepare("DELETE FROM cards WHERE key = ?").run(key);
1849
+ bumpVersion(db);
1850
+ db.exec("COMMIT");
1851
+ return { logs };
1852
+ } catch (error) {
1853
+ if (db.isTransaction) db.exec("ROLLBACK");
1854
+ throw error;
1855
+ }
1856
+ }
1857
+ //#endregion
1858
+ //#region ../../packages/core/src/node/data-dir.ts
1859
+ function resolveDataDir(env) {
1860
+ if (isFakeMode(env)) return join(homedir(), ".nolzu-fake");
1861
+ return env.NOLZU_DATA_DIR ? resolve(env.NOLZU_DATA_DIR) : join(homedir(), ".nolzu");
1862
+ }
1863
+ //#endregion
1864
+ //#region ../../packages/core/src/node/estimates.ts
1865
+ var keyOf = (vendor, phase, model, effort) => JSON.stringify([
1866
+ vendor ?? "",
1867
+ phase,
1868
+ model,
1869
+ effort
1870
+ ]);
1871
+ var vendorOf = (profile) => profile.split("#")[0];
1872
+ var held = /* @__PURE__ */ new WeakMap();
1873
+ /**
1874
+ * The history figure of every phase, model and effort this project has enough runs of.
1875
+ *
1876
+ * A sample is a completed first run. Complete includes a run that ended on a question, because a
1877
+ * drop starts exactly that run and the answer is a start of its own. A row from before the resumed
1878
+ * column is null there and left out, since nothing says what kind of run it was.
1879
+ */
1880
+ function history(db) {
1881
+ const version = boardVersion(db);
1882
+ const cached = held.get(db);
1883
+ if (cached?.version === version) return cached.figures;
1884
+ const rows = db.prepare(`SELECT r.engine, r.phase, r.asked_model, r.effort, r.cost_estimate, r.started_at, r.ended_at
1885
+ FROM runs r
1886
+ WHERE r.state = 'complete' AND r.resumed = 0 AND r.asked_model IS NOT NULL AND r.effort IS NOT NULL
1887
+ AND r.started_at IS NOT NULL AND r.ended_at IS NOT NULL`).all();
1888
+ const all = /* @__PURE__ */ new Map();
1889
+ for (const row of rows) {
1890
+ const wallMs = Date.parse(row.ended_at) - Date.parse(row.started_at);
1891
+ if (!(wallMs >= 0)) continue;
1892
+ const key = keyOf(vendorOf(row.engine), row.phase, row.asked_model, row.effort);
1893
+ const sample = {
1894
+ costUsd: row.cost_estimate,
1895
+ wallMs
1896
+ };
1897
+ const group = all.get(key);
1898
+ if (group === void 0) all.set(key, [sample]);
1899
+ else group.push(sample);
1900
+ }
1901
+ const figures = /* @__PURE__ */ new Map();
1902
+ for (const [key, samples] of all) {
1903
+ const found = historyEstimate(samples);
1904
+ if (found !== null) figures.set(key, found);
1905
+ }
1906
+ held.set(db, {
1907
+ version,
1908
+ figures
1909
+ });
1910
+ return figures;
1911
+ }
1912
+ function startEstimate(db, start) {
1913
+ const found = history(db).get(keyOf(start.vendor, start.phase, start.model, start.effort));
1914
+ if (found !== void 0) return found;
1915
+ const range = isAction(start.phase) ? presetRange(start.vendor, start.phase, start.model, start.effort) : null;
1916
+ return estimateOf([], range) ?? void 0;
1917
+ }
1918
+ /**
1919
+ * What a card costs and takes when each of its steps runs on the engine profile, model and effort
1920
+ * given, or undefined when one step has too few measured runs.
1921
+ *
1922
+ * Read over this project's own runs, and never off a preset's range: a sum with one made-up step is a
1923
+ * made-up number (owner question 57).
1924
+ */
1925
+ function cardEstimate(db, steps) {
1926
+ const figures = history(db);
1927
+ let total;
1928
+ for (const step of steps) {
1929
+ const one = figures.get(keyOf(vendorOf(step.engine), step.phase, step.model, step.effort));
1930
+ if (one === void 0) return void 0;
1931
+ total = total === void 0 ? one : estimateSum(total, one);
1932
+ }
1933
+ return total;
1934
+ }
1935
+ //#endregion
1936
+ //#region ../../packages/core/src/node/knowledge-changes.ts
1937
+ var read$2 = (row) => ({
1938
+ id: row.id,
1939
+ cardKey: row.card_key,
1940
+ runId: row.run_id,
1941
+ filePath: row.file_path,
1942
+ commitSha: row.commit_sha,
1943
+ summary: row.summary,
1944
+ status: row.status,
1945
+ note: row.note,
1946
+ movedFrom: row.moved_from
1947
+ });
1948
+ /**
1949
+ * The rows behind one knowledge commit, written together.
1950
+ *
1951
+ * One transaction, because every row of a run names the same commit. Half of them would describe a
1952
+ * commit the screen could revert only in part.
1953
+ */
1954
+ function recordKnowledgeChanges(db, write) {
1955
+ const insert = db.prepare("INSERT INTO knowledge_changes (card_key, run_id, file_path, commit_sha, summary, status) VALUES (?, ?, ?, ?, ?, ?)");
1956
+ db.exec("BEGIN IMMEDIATE");
1957
+ try {
1958
+ for (const file of write.files) insert.run(write.cardKey, write.runId, file.path, write.commitSha, file.summary, write.status);
1959
+ db.exec("COMMIT");
1960
+ } catch (error) {
1961
+ db.exec("ROLLBACK");
1962
+ throw error;
1963
+ }
1964
+ }
1965
+ function pendingKnowledgeChanges(db) {
1966
+ return db.prepare("SELECT * FROM knowledge_changes WHERE status = 'pending' ORDER BY id").all().map(read$2);
1967
+ }
1968
+ /**
1969
+ * Every change ever recorded, oldest first.
1970
+ *
1971
+ * The Knowledge screen reads them all in one go: the history of the open file, the pending list and
1972
+ * the day of the last applied change come from the same rows.
1973
+ */
1974
+ function allKnowledgeChanges(db) {
1975
+ return db.prepare("SELECT * FROM knowledge_changes ORDER BY id").all().map(read$2);
1976
+ }
1977
+ /**
1978
+ * One change by its id, or null when there is no such row.
1979
+ *
1980
+ * The Knowledge screen's revert names a row and not a run. The history it sits in is per file, and
1981
+ * one run's commit can carry several files.
1982
+ */
1983
+ function knowledgeChange(db, id) {
1984
+ const row = db.prepare("SELECT * FROM knowledge_changes WHERE id = ?").get(id);
1985
+ return row === void 0 ? null : read$2(row);
1986
+ }
1987
+ function knowledgeChangesOfRun(db, runId) {
1988
+ return db.prepare("SELECT * FROM knowledge_changes WHERE run_id = ? ORDER BY id").all(runId).map(read$2);
1989
+ }
1990
+ /**
1991
+ * The rows of one run, from pending to applied, with the commit they were applied as.
1992
+ *
1993
+ * Only the pending rows, so a second approve of the same run moves nothing and the caller sees
1994
+ * that it changed no row.
1995
+ */
1996
+ function applyKnowledgeChanges(db, runId, commitSha) {
1997
+ const done = db.prepare("UPDATE knowledge_changes SET status = 'applied', commit_sha = ? WHERE run_id = ? AND status = 'pending'").run(commitSha, runId);
1998
+ return Number(done.changes);
1999
+ }
2000
+ function returnKnowledgeChanges(db, runId, note) {
2001
+ const done = db.prepare("UPDATE knowledge_changes SET status = 'returned', note = ? WHERE run_id = ? AND status = 'pending'").run(note, runId);
2002
+ return Number(done.changes);
2003
+ }
2004
+ /**
2005
+ * The note the next knowledge run of a card has to read, or null.
2006
+ *
2007
+ * Only when the card's newest change is a returned one. A run that wrote knowledge after the
2008
+ * return left newer rows, so its own answer to the note is already in the folder and the note is
2009
+ * read once rather than handed to every run of that card forever.
2010
+ *
2011
+ * `phase` keeps to the changes runs of that phase made. Optimize and Learn this project share the
2012
+ * reserved key, and a note written for one is no instruction for the other.
2013
+ */
2014
+ function returnedKnowledgeNote(db, cardKey, phase) {
2015
+ const ofPhase = phase === void 0 ? "" : " AND run_id IN (SELECT id FROM runs WHERE phase = ?)";
2016
+ const row = db.prepare(`SELECT status, note FROM knowledge_changes WHERE card_key = ?${ofPhase} ORDER BY id DESC LIMIT 1`).get(cardKey, ...phase === void 0 ? [] : [phase]);
2017
+ return row?.status === "returned" ? row.note : null;
2018
+ }
2019
+ /**
2020
+ * One row, from applied to reverted.
2021
+ *
2022
+ * Only an applied row, so a second revert of the same change moves nothing and the caller sees that
2023
+ * it changed no row. The commit stays on the row: the screen still shows what the change was, with
2024
+ * the word that says it was taken back.
2025
+ */
2026
+ function revertKnowledgeChange(db, id) {
2027
+ const done = db.prepare("UPDATE knowledge_changes SET status = 'reverted' WHERE id = ? AND status = 'applied'").run(id);
2028
+ return Number(done.changes);
2029
+ }
2030
+ /**
2031
+ * Marks every change not marked yet as committed in `folder`, which the project no longer uses.
2032
+ *
2033
+ * A row marked by an earlier move keeps its folder, because its commit is still in that one.
2034
+ */
2035
+ function markKnowledgeMoved(db, folder) {
2036
+ return Number(db.prepare("UPDATE knowledge_changes SET moved_from = ? WHERE moved_from IS NULL").run(folder).changes);
2037
+ }
2038
+ var NOW$4 = "strftime('%Y-%m-%dT%H:%M:%fZ')";
2039
+ /**
2040
+ * Keeps one event. The id is the event's own key (`run:12`), so the same event written twice, from a
2041
+ * retried path or a second tab's request, stays one row. Answers whether a row was added.
2042
+ */
2043
+ function addNotification(db, notice) {
2044
+ const added = db.prepare(`INSERT OR IGNORE INTO notifications (id, at, kind, card_key, text, href) VALUES (?, ${NOW$4}, ?, ?, ?, ?)`).run(notice.id, notice.kind, notice.card ?? null, notice.text, notice.href ?? null).changes > 0;
2045
+ if (added) db.prepare("DELETE FROM notifications WHERE rowid NOT IN (SELECT rowid FROM notifications ORDER BY at DESC, rowid DESC LIMIT ?)").run(200);
2046
+ return added;
2047
+ }
2048
+ /** Newest first. */
2049
+ function notifications(db, limit = 200) {
2050
+ return db.prepare("SELECT * FROM notifications ORDER BY at DESC, rowid DESC LIMIT ?").all(limit).map((row) => ({
2051
+ id: row.id,
2052
+ at: row.at,
2053
+ kind: row.kind,
2054
+ card: row.card_key,
2055
+ text: row.text,
2056
+ href: row.href,
2057
+ read: row.read_at !== null
2058
+ }));
2059
+ }
2060
+ function unreadNotifications(db) {
2061
+ return db.prepare("SELECT count(*) AS n FROM notifications WHERE read_at IS NULL").get().n;
2062
+ }
2063
+ /** Opening the panel reads them all. Answers whether any was unread. */
2064
+ function markNotificationsRead(db) {
2065
+ return db.prepare(`UPDATE notifications SET read_at = ${NOW$4} WHERE read_at IS NULL`).run().changes > 0;
2066
+ }
2067
+ //#endregion
2068
+ //#region ../../packages/core/src/node/pr-discussions.ts
2069
+ /**
2070
+ * Keeps one pull request of a card and answers its row id. A second save of the same one keeps how it
2071
+ * was first found, so a pull request a person attached stays attached when the branch finds it too.
2072
+ * A title or state left out keeps the one an earlier read saw.
2073
+ */
2074
+ function saveCardPull(db, card, pull) {
2075
+ return db.prepare("INSERT INTO card_pulls (card_key, repo, number, url, title, state, found_by) VALUES (?, ?, ?, ?, ?, ?, ?) ON CONFLICT (card_key, repo, number) DO UPDATE SET url = coalesce(excluded.url, url), title = coalesce(excluded.title, title), state = coalesce(excluded.state, state) RETURNING id").get(card, pull.repo.toLowerCase(), pull.number, pull.url, pull.title ?? null, pull.state ?? null, pull.foundBy).id;
2076
+ }
2077
+ function cardPullRows(db, card) {
2078
+ return db.prepare("SELECT id, card_key, repo, number, url, title, state, found_by, read_at FROM card_pulls WHERE card_key = ? ORDER BY id").all(card).map((row) => ({
2079
+ id: row.id,
2080
+ card: row.card_key,
2081
+ repo: row.repo,
2082
+ number: row.number,
2083
+ url: row.url,
2084
+ title: row.title,
2085
+ state: row.state,
2086
+ foundBy: row.found_by,
2087
+ readAt: row.read_at
2088
+ }));
2089
+ }
2090
+ /**
2091
+ * Takes an attached pull request off a card, with its discussions and their messages (the foreign keys
2092
+ * cascade). One the branch found stays, because the next read would find it again, and so does one a
2093
+ * fix is running on. The answer says which it was.
2094
+ */
2095
+ function detachCardPull(db, card, repo, number) {
2096
+ const row = db.prepare("SELECT id, found_by FROM card_pulls WHERE card_key = ? AND repo = ? AND number = ?").get(card, repo.toLowerCase(), number);
2097
+ if (row === void 0) return "missing";
2098
+ if (row.found_by === "branch") return "branch";
2099
+ if (db.prepare("SELECT 1 FROM pr_discussions WHERE pull_id = ? AND status = 'fixing'").get(row.id) !== void 0) return "fixing";
2100
+ db.exec("BEGIN IMMEDIATE");
2101
+ try {
2102
+ db.prepare("INSERT INTO seq (name, value) VALUES (?, ?) ON CONFLICT (name) DO UPDATE SET value = max(value, excluded.value)").run(refSeq(card), topRef(db, card));
2103
+ db.prepare("DELETE FROM card_pulls WHERE id = ?").run(row.id);
2104
+ db.exec("COMMIT");
2105
+ } catch (error) {
2106
+ db.exec("ROLLBACK");
2107
+ throw error;
2108
+ }
2109
+ return "detached";
2110
+ }
2111
+ var refSeq = (card) => `pr-refs:${card}`;
2112
+ function topRef(db, card) {
2113
+ return db.prepare("SELECT max(coalesce((SELECT max(CAST(substr(ref, 2) AS INTEGER)) FROM pr_discussions WHERE card_key = ?), 0), coalesce((SELECT value FROM seq WHERE name = ?), 0)) AS n").get(card, refSeq(card)).n;
2114
+ }
2115
+ var after = (one, other) => Date.parse(one) > Date.parse(other);
2116
+ /**
2117
+ * Stores one read of a pull request's discussions, under these rules:
2118
+ *
2119
+ * - A discussion seen for the first time gets the next free ref of the card, oldest first message first.
2120
+ * - A message is added once, by its GitHub id. One by the viewer is mine and never unread.
2121
+ * - A message whose text changed on GitHub since takes the new text, and is unread again unless it is
2122
+ * mine. An edit alone changes nothing else on its discussion.
2123
+ * - A thread that became resolved on GitHub since the last read is done. While a fix runs on it, it
2124
+ * waits for the first read after the fix.
2125
+ * - A reviewer message newer than the fix reopens a fixed discussion.
2126
+ * - Nothing else changes the status, so a person's done stays done, and a discussion that is gone on
2127
+ * GitHub stays as it was.
2128
+ */
2129
+ function storeDiscussions(db, pullId, viewer, read) {
2130
+ const pull = db.prepare("SELECT card_key FROM card_pulls WHERE id = ?").get(pullId);
2131
+ if (pull === void 0) throw new Error(`No pull request ${pullId} is stored, so its comments have nowhere to go.`);
2132
+ const card = pull.card_key;
2133
+ const first = (item) => item.messages.reduce((min, one) => min === "" || after(min, one.createdAt) ? one.createdAt : min, "");
2134
+ const items = read.filter((item) => item.messages.length > 0).sort((one, other) => Date.parse(first(one)) - Date.parse(first(other)));
2135
+ const mineOf = (author) => viewer !== null && author !== null && author.toLowerCase() === viewer.toLowerCase();
2136
+ const done = {
2137
+ added: 0,
2138
+ messages: 0,
2139
+ reopened: 0,
2140
+ done: 0
2141
+ };
2142
+ db.exec("BEGIN IMMEDIATE");
2143
+ try {
2144
+ let next = topRef(db, card) + 1;
2145
+ const find = db.prepare("SELECT id, resolved, status, fixed_at FROM pr_discussions WHERE pull_id = ? AND github_id = ?");
2146
+ const insert = db.prepare("INSERT INTO pr_discussions (card_key, pull_id, ref, kind, github_id, path, line, resolved, outdated, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id");
2147
+ const update = db.prepare("UPDATE pr_discussions SET path = ?, line = ?, resolved = ?, outdated = ?, status = ? WHERE id = ?");
2148
+ const message = db.prepare("INSERT OR IGNORE INTO pr_messages (discussion_id, github_id, author, body, created_at, url, mine, unread) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
2149
+ const edited = db.prepare("UPDATE pr_messages SET body = ?, unread = 1 - mine WHERE discussion_id = ? AND github_id = ? AND body != ?");
2150
+ for (const item of items) {
2151
+ const was = find.get(pullId, item.githubId);
2152
+ let id;
2153
+ let status;
2154
+ if (was === void 0) {
2155
+ status = item.resolved ? "done" : "new";
2156
+ id = insert.get(card, pullId, `T${next}`, item.kind, item.githubId, item.path, item.line, item.resolved ? 1 : 0, item.outdated ? 1 : 0, status).id;
2157
+ next += 1;
2158
+ done.added += 1;
2159
+ } else {
2160
+ id = was.id;
2161
+ status = was.status;
2162
+ }
2163
+ let answered = false;
2164
+ for (const one of item.messages) {
2165
+ const mine = mineOf(one.author);
2166
+ if (!(message.run(id, one.githubId, one.author, one.body, one.createdAt, one.url ?? null, mine ? 1 : 0, mine ? 0 : 1).changes > 0)) {
2167
+ edited.run(one.body, id, one.githubId, one.body);
2168
+ continue;
2169
+ }
2170
+ done.messages += 1;
2171
+ if (!mine && was?.fixed_at != null && after(one.createdAt, was.fixed_at)) answered = true;
2172
+ }
2173
+ if (was !== void 0) {
2174
+ if (item.resolved && was.resolved === 0 && status !== "fixing" && status !== "done") {
2175
+ status = "done";
2176
+ done.done += 1;
2177
+ } else if (answered && status === "fixed") {
2178
+ status = "new";
2179
+ done.reopened += 1;
2180
+ }
2181
+ const resolved = status === "fixing" ? was.resolved : item.resolved ? 1 : 0;
2182
+ update.run(item.path, item.line, resolved, item.outdated ? 1 : 0, status, id);
2183
+ }
2184
+ }
2185
+ db.prepare("UPDATE card_pulls SET read_at = strftime('%Y-%m-%dT%H:%M:%fZ') WHERE id = ?").run(pullId);
2186
+ db.exec("COMMIT");
2187
+ } catch (error) {
2188
+ if (db.isTransaction) db.exec("ROLLBACK");
2189
+ throw error;
2190
+ }
2191
+ return done;
2192
+ }
2193
+ /**
2194
+ * Starts a Fix on one discussion: it becomes fixing and its last failure goes. Refused with the sentence
2195
+ * the PRs tab shows for a ref the card does not have, a done row, and while any row of the card is
2196
+ * fixing, because one Implement session cannot take two fixes at once.
2197
+ */
2198
+ function beginFix(db, card, ref) {
2199
+ const rows = cardDiscussions(db, card);
2200
+ const row = rows.find((one) => one.ref === ref);
2201
+ if (row === void 0) return {
2202
+ ok: false,
2203
+ reason: `${card} has no discussion ${ref}. Read comments on its PRs tab first.`
2204
+ };
2205
+ const running = rows.find((one) => one.status === "fixing");
2206
+ if (running !== void 0) return {
2207
+ ok: false,
2208
+ reason: running.ref === ref ? `${ref} is being fixed now. Wait for that fix to end.` : `${running.ref} is being fixed now. One fix runs at a time, so wait for it to end.`
2209
+ };
2210
+ if (row.status === "done") return {
2211
+ ok: false,
2212
+ reason: `${ref} is done. Reopen it first if it still needs a fix.`
2213
+ };
2214
+ db.prepare("UPDATE pr_discussions SET status = 'fixing', fix_failed = NULL WHERE id = ?").run(row.id);
2215
+ return {
2216
+ ok: true,
2217
+ row: {
2218
+ ...row,
2219
+ status: "fixing"
2220
+ }
2221
+ };
2222
+ }
2223
+ /**
2224
+ * Starts Fix all: every row triage wants fixed that is new goes fixing, for one Implement run. Refused
2225
+ * while any row of the card is fixing, and when no such row is left. The rows come back as they were,
2226
+ * with why the last fix of each did not hold, so the run's message can say it.
2227
+ */
2228
+ function beginFixAll(db, card) {
2229
+ const rows = cardDiscussions(db, card);
2230
+ const running = rows.find((one) => one.status === "fixing");
2231
+ if (running !== void 0) return {
2232
+ ok: false,
2233
+ reason: `${running.ref} is being fixed now. One fix runs at a time, so wait for it to end.`
2234
+ };
2235
+ const due = rows.filter((one) => one.verdict === "fix" && one.status === "new");
2236
+ if (due.length === 0) return {
2237
+ ok: false,
2238
+ reason: `${card} has no comment left that triage wants fixed. Run triage first, or use Fix on a row.`
2239
+ };
2240
+ const mark = db.prepare("UPDATE pr_discussions SET status = 'fixing', fix_failed = NULL WHERE id = ?");
2241
+ for (const row of due) mark.run(row.id);
2242
+ return {
2243
+ ok: true,
2244
+ rows: due.map((row) => ({
2245
+ ...row,
2246
+ status: "fixing"
2247
+ }))
2248
+ };
2249
+ }
2250
+ /**
2251
+ * The rows QA the fixes checks: fixed after the newest QA run that gave PASS or FAIL. A BLOCKED QA, or
2252
+ * one with no verdict, checked nothing, so its rows stay due.
2253
+ */
2254
+ function fixedSinceQa(db, card) {
2255
+ const last = lastJudgedQa(db, card);
2256
+ return cardDiscussions(db, card).filter((row) => row.status === "fixed" && row.fixedAt !== null && (last === null || row.fixedAt > last));
2257
+ }
2258
+ /** When the newest QA run of the card that gave PASS or FAIL started, or null before one did. */
2259
+ function lastJudgedQa(db, card) {
2260
+ return db.prepare("SELECT max(started_at) AS at FROM runs WHERE card_key = ? AND phase = 'qa' AND verdict IN ('PASS', 'FAIL')").get(card).at;
2261
+ }
2262
+ /** QA of the fixes failed these rows: each one still fixed goes back to new with QA's reason. */
2263
+ function reopenFixed(db, card, failed) {
2264
+ const back = db.prepare("UPDATE pr_discussions SET status = 'new', fix_failed = ? WHERE card_key = ? AND ref = ? AND status = 'fixed'");
2265
+ for (const one of failed) back.run(one.reason, card, one.ref);
2266
+ }
2267
+ /**
2268
+ * Ends a Fix. One that ended well is fixed with its one line note, stamped, so a later reviewer message
2269
+ * reopens it. One that failed, asked or was stopped is new again with the reason. Only a row that is
2270
+ * still fixing, so nothing here undoes what happened to it in between.
2271
+ */
2272
+ function endFix(db, id, outcome) {
2273
+ if (outcome.ok) db.prepare("UPDATE pr_discussions SET status = 'fixed', fix_note = ?, fix_failed = NULL, fixed_at = strftime('%Y-%m-%dT%H:%M:%fZ') WHERE id = ? AND status = 'fixing'").run(outcome.note, id);
2274
+ else db.prepare("UPDATE pr_discussions SET status = 'new', fix_failed = ? WHERE id = ? AND status = 'fixing'").run(outcome.reason, id);
2275
+ }
2276
+ /** Marks every message of a card seen, which opening its PRs tab does, and answers how many were unread. */
2277
+ function markDiscussionsSeen(db, card) {
2278
+ return Number(db.prepare("UPDATE pr_messages SET unread = 0 WHERE unread = 1 AND discussion_id IN (SELECT id FROM pr_discussions WHERE card_key = ?)").run(card).changes);
2279
+ }
2280
+ /**
2281
+ * The person's own call on a discussion. Done sets it done and drops the override, so it goes to the
2282
+ * "Nothing to action" footer. Reopen sets a done one back to new and sets the override, so it stays out
2283
+ * of the footer whatever the verdict says. A read never undoes either, except that a thread resolved on
2284
+ * GitHub becomes done. One a fix runs on is left alone, because the fix writes its status when it ends.
2285
+ */
2286
+ function markDiscussion(db, card, ref, action) {
2287
+ const row = db.prepare("SELECT id, status FROM pr_discussions WHERE card_key = ? AND ref = ?").get(card, ref);
2288
+ if (row === void 0) return "missing";
2289
+ if (row.status === "fixing") return "fixing";
2290
+ if (action === "done") db.prepare("UPDATE pr_discussions SET status = 'done', needs_action = NULL WHERE id = ?").run(row.id);
2291
+ else db.prepare("UPDATE pr_discussions SET status = CASE WHEN status = 'done' THEN 'new' ELSE status END, needs_action = 1 WHERE id = ?").run(row.id);
2292
+ return "marked";
2293
+ }
2294
+ /**
2295
+ * Writes what a triage run said onto the card's rows: the verdict, summary, reason and drafted reply.
2296
+ * Only an open row takes it. A done one, whether a person marked it or GitHub resolved it, is left
2297
+ * as it is, and so is a ref the card does not have. The status never changes here, so a fix that
2298
+ * runs keeps fixing, and a fixed row stays fixed until a reviewer answers.
2299
+ */
2300
+ function applyTriage(db, card, blocks) {
2301
+ const update = db.prepare("UPDATE pr_discussions SET verdict = ?, summary = ?, reason = ?, reply = ? WHERE card_key = ? AND ref = ? AND status != 'done'");
2302
+ let applied = 0;
2303
+ db.exec("BEGIN IMMEDIATE");
2304
+ try {
2305
+ for (const one of blocks) applied += Number(update.run(one.verdict, one.summary, one.reason, one.reply, card, one.ref).changes);
2306
+ db.exec("COMMIT");
2307
+ } catch (error) {
2308
+ if (db.isTransaction) db.exec("ROLLBACK");
2309
+ throw error;
2310
+ }
2311
+ return {
2312
+ applied,
2313
+ ignored: blocks.length - applied
2314
+ };
2315
+ }
2316
+ /** Every discussion of a card in ref order, each with its messages oldest first. */
2317
+ function cardDiscussions(db, card) {
2318
+ const rows = db.prepare("SELECT * FROM pr_discussions WHERE card_key = ? ORDER BY CAST(substr(ref, 2) AS INTEGER)").all(card);
2319
+ const messages = db.prepare("SELECT id, github_id, author, body, created_at, url, mine, unread FROM pr_messages WHERE discussion_id = ? ORDER BY created_at, id");
2320
+ const blocked = db.prepare("SELECT state FROM cards WHERE key = ?").get(card)?.state === "blocked";
2321
+ const asked = db.prepare("SELECT question FROM runs WHERE card_key = ? AND phase = 'implement' AND thread IS NOT NULL ORDER BY id DESC LIMIT 1");
2322
+ const asks = (row) => blocked && row.status === "fixing" ? asked.get(card)?.question ?? null : null;
2323
+ return rows.map((row) => ({
2324
+ id: row.id,
2325
+ pull: row.pull_id,
2326
+ ref: row.ref,
2327
+ kind: row.kind,
2328
+ githubId: row.github_id,
2329
+ path: row.path,
2330
+ line: row.line,
2331
+ resolved: row.resolved === 1,
2332
+ outdated: row.outdated === 1,
2333
+ status: row.status,
2334
+ verdict: row.verdict,
2335
+ summary: row.summary,
2336
+ reason: row.reason,
2337
+ reply: row.reply,
2338
+ fixNote: row.fix_note,
2339
+ fixedAt: row.fixed_at,
2340
+ fixFailed: row.fix_failed,
2341
+ fixAsks: asks(row),
2342
+ needsAction: row.needs_action === null ? null : row.needs_action === 1,
2343
+ messages: messages.all(row.id).map((one) => ({
2344
+ id: one.id,
2345
+ githubId: one.github_id,
2346
+ author: one.author,
2347
+ body: one.body,
2348
+ createdAt: one.created_at,
2349
+ url: one.url,
2350
+ mine: one.mine === 1,
2351
+ unread: one.unread === 1
2352
+ }))
2353
+ }));
2354
+ }
2355
+ /**
2356
+ * What the board card says about each card's discussions, counts only: the rows triage wants fixed that
2357
+ * are not fixed yet, and the rows with a message nobody opened the PRs tab on. A card with neither is
2358
+ * left out. One query for the whole board, and no comment text, so the snapshot never carries any.
2359
+ */
2360
+ function feedbackCounts(db) {
2361
+ const rows = db.prepare(`SELECT card_key, count(CASE WHEN verdict = 'fix' AND status IN ('new', 'fixing') THEN 1 END) AS to_fix,
2362
+ sum(EXISTS (SELECT 1 FROM pr_messages m WHERE m.discussion_id = d.id AND m.unread = 1)) AS unread
2363
+ FROM pr_discussions d GROUP BY card_key`).all();
2364
+ return new Map(rows.filter((row) => row.to_fix > 0 || row.unread > 0).map((row) => [row.card_key, {
2365
+ toFix: row.to_fix,
2366
+ unread: row.unread
2367
+ }]));
2368
+ }
2369
+ //#endregion
2370
+ //#region ../../packages/core/src/node/runs.ts
2371
+ var NOT_A_PASS = `phase NOT IN (${[...PASSES, "ask"].map((one) => `'${one}'`).join(", ")})`;
2372
+ var ENDED = [
2373
+ "complete",
2374
+ "failed",
2375
+ "stopped",
2376
+ "interrupted"
2377
+ ];
2378
+ var NOW$3 = "strftime('%Y-%m-%dT%H:%M:%fZ')";
2379
+ function startRun(db, start) {
2380
+ const written = db.prepare(`INSERT INTO runs (card_key, phase, engine, model, effort, session_id, log_path, lane, state, resumed, asked_model, thread)
2381
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'queued', ?, ?, ?)`).run(start.cardKey, start.phase, start.engine, start.model, start.effort, start.sessionId, start.logPath, start.lane, start.resumed === true ? 1 : 0, start.model, start.thread ?? null);
2382
+ return Number(written.lastInsertRowid);
2383
+ }
2384
+ function sessionFolder(db, cardKey, sessionId) {
2385
+ return db.prepare("SELECT cwd FROM runs WHERE card_key = ? AND session_id = ? AND cwd IS NOT NULL ORDER BY id LIMIT 1").get(cardKey, sessionId)?.cwd ?? null;
2386
+ }
2387
+ function sessionInCardFolder(db, cardKey, sessionId, vendor, phase) {
2388
+ const row = db.prepare("SELECT in_card_folder FROM runs WHERE card_key = ? AND session_id = ? ORDER BY id LIMIT 1").get(cardKey, sessionId);
2389
+ if (row !== void 0 && row.in_card_folder !== null) return row.in_card_folder === 1;
2390
+ return startsInCardFolder(vendor, phase, true);
2391
+ }
2392
+ function markRunning(db, id) {
2393
+ db.prepare(`UPDATE runs SET state = 'running', started_at = coalesce(started_at, ${NOW$3}) WHERE id = ?`).run(id);
2394
+ db.prepare("UPDATE cards SET state = 'running' WHERE key = (SELECT card_key FROM runs WHERE id = ?)").run(id);
2395
+ bumpVersion(db);
2396
+ }
2397
+ function ownCost(db, id, run) {
2398
+ if (run.costUsd === null || run.costIsSessionTotal !== true) return run.costUsd;
2399
+ const session = run.sessionId ?? db.prepare("SELECT session_id FROM runs WHERE id = ?").get(id)?.session_id ?? null;
2400
+ if (session === null) return run.costUsd;
2401
+ const { earlier } = db.prepare("SELECT coalesce(sum(cost_estimate), 0) AS earlier FROM runs WHERE session_id = ? AND id < ?").get(session, id);
2402
+ return Math.max(0, run.costUsd - earlier);
2403
+ }
2404
+ function saveRun(db, id, run) {
2405
+ const cost = ownCost(db, id, run);
2406
+ db.prepare(`UPDATE runs SET
2407
+ model = coalesce(?, model), session_id = coalesce(?, session_id), cost_estimate = ?,
2408
+ -- The engine's own time where it reports one. Codex reports none, so an ended run counts it
2409
+ -- from its start to now, the end this same write stamps.
2410
+ duration_ms = coalesce(?, CASE WHEN ? AND started_at IS NOT NULL THEN CAST(round((julianday(${NOW$3}) - julianday(started_at)) * 86400000) AS INTEGER) END),
2411
+ tokens_input = ?, tokens_output = ?, tokens_cache_read = ?, tokens_cache_creation = ?,
2412
+ question = ?, error = ?, state = ?, attempt = ?, retry_reason = ?, retry_max = ?, retry_until = ?,
2413
+ -- A wait for an API error resumes the session in this same row, and the cost and the
2414
+ -- duration that reach the row are the last attempt's alone. So it leaves the estimates.
2415
+ resumed = CASE WHEN ? THEN 1 ELSE resumed END,
2416
+ -- Stamped on the first event the run reports, and never moved after that. A job can wait a
2417
+ -- long time for a slot or a lane, and the browser counts elapsed from this, so the queue wait
2418
+ -- is not part of it.
2419
+ started_at = coalesce(started_at, ${NOW$3}),
2420
+ ended_at = CASE WHEN ? THEN coalesce(ended_at, ${NOW$3}) ELSE ended_at END
2421
+ WHERE id = ?`).run(run.model, run.sessionId, cost, run.durationMs, ENDED.includes(run.state) ? 1 : 0, run.tokens?.input ?? null, run.tokens?.output ?? null, run.tokens?.cacheRead ?? null, run.tokens?.cacheCreation ?? null, run.question, run.failureReason, run.state, run.retry?.attempt ?? null, run.retry?.reason ?? null, run.retry?.maxRetries ?? null, run.retry?.until ?? null, run.retry === null ? 0 : 1, ENDED.includes(run.state) ? 1 : 0, id);
2422
+ bumpVersion(db);
2423
+ }
2424
+ function retryWait(db, id) {
2425
+ const row = db.prepare("SELECT state, attempt, retry_max, retry_reason, retry_until FROM runs WHERE id = ?").get(id);
2426
+ if (row?.state !== "retrying" || row.retry_until === null || row.attempt === null) return null;
2427
+ return {
2428
+ attempt: row.attempt,
2429
+ maxRetries: row.retry_max,
2430
+ reason: row.retry_reason,
2431
+ until: row.retry_until
2432
+ };
2433
+ }
2434
+ function saveVerdict(db, id, found) {
2435
+ db.prepare("UPDATE runs SET verdict = ?, verdict_reason = ? WHERE id = ?").run(found.verdict, found.reason, id);
2436
+ bumpVersion(db);
2437
+ }
2438
+ function saveQuestionOptions(db, id, options) {
2439
+ db.prepare("UPDATE runs SET question_options = ? WHERE id = ?").run(options === null ? null : JSON.stringify(options), id);
2440
+ bumpVersion(db);
2441
+ }
2442
+ function saveStackStatus(db, id, status) {
2443
+ db.prepare("UPDATE runs SET stack_state = ?, stack_reason = ? WHERE id = ?").run(status.state, status.reason, id);
2444
+ bumpVersion(db);
2445
+ }
2446
+ function saveReadOnlyBreak(db, id, found) {
2447
+ db.prepare("UPDATE runs SET read_only_break = ? WHERE id = ?").run(JSON.stringify(found), id);
2448
+ bumpVersion(db);
2449
+ }
2450
+ function clearReadOnlyBreaks(db, key, before) {
2451
+ const cleared = db.prepare("UPDATE runs SET read_only_break = NULL WHERE card_key = ? AND id < ? AND read_only_break IS NOT NULL").run(key, before).changes > 0;
2452
+ if (cleared) bumpVersion(db);
2453
+ return cleared;
2454
+ }
2455
+ function otherRunOfCard(db, key, id, since) {
2456
+ return db.prepare("SELECT 1 FROM runs WHERE card_key = ? AND id != ? AND (state IN ('queued', 'running') OR (? IS NOT NULL AND ended_at >= ?)) LIMIT 1").get(key, id, since ?? null, since ?? null) !== void 0;
2457
+ }
2458
+ function readOnlyBreakOf(db, key) {
2459
+ const row = db.prepare("SELECT phase, engine, wall, read_only_break FROM runs WHERE card_key = ? AND read_only_break IS NOT NULL ORDER BY id DESC LIMIT 1").get(key);
2460
+ if (row === void 0) return null;
2461
+ try {
2462
+ const found = JSON.parse(row.read_only_break);
2463
+ const walled = row.wall === "macos" || row.wall === "bubblewrap";
2464
+ return {
2465
+ phase: row.phase,
2466
+ engine: row.engine,
2467
+ walled,
2468
+ restored: found.restored === true,
2469
+ diff: String(found.diff ?? ""),
2470
+ undone: found.undone ?? [],
2471
+ left: found.left ?? []
2472
+ };
2473
+ } catch {
2474
+ return null;
2475
+ }
2476
+ }
2477
+ function saveCommitWarning(db, id, sentences) {
2478
+ db.prepare("UPDATE runs SET commit_warning = ? WHERE id = ?").run(sentences, id);
2479
+ bumpVersion(db);
2480
+ }
2481
+ function commitWarningOf(db, key) {
2482
+ return db.prepare("SELECT commit_warning FROM runs WHERE card_key = ? AND phase = 'implement' ORDER BY id DESC LIMIT 1").get(key)?.commit_warning ?? null;
2483
+ }
2484
+ function saveOutputCheck(db, id, check) {
2485
+ db.prepare("UPDATE runs SET output_check = ? WHERE id = ?").run(JSON.stringify(check), id);
2486
+ bumpVersion(db);
2487
+ }
2488
+ function outputCheckOf(db, id) {
2489
+ return parseOutputCheck(db.prepare("SELECT output_check FROM runs WHERE id = ?").get(id)?.output_check ?? null);
2490
+ }
2491
+ /**
2492
+ * What a card still holds for the person that a closed card would hide, as the sentence Now shows, or
2493
+ * null. A knowledge change of any of its runs that waits for review comes first, then problems the
2494
+ * output check found on the run the card shows. A wrap-up that leaves either stays on Wrap-up.
2495
+ */
2496
+ function cardHolds(db, key) {
2497
+ if (db.prepare("SELECT 1 FROM knowledge_changes WHERE card_key = ? AND status = 'pending' LIMIT 1").get(key) !== void 0) return "A knowledge change waits for your review on Knowledge.";
2498
+ return (parseOutputCheck(db.prepare(`SELECT output_check FROM runs WHERE card_key = ? AND ${NOT_A_PASS} ORDER BY id DESC LIMIT 1`).get(key)?.output_check ?? null)?.problems.length ?? 0) > 0 ? "The output check found problems in what the run wrote. Open the card to read them." : null;
2499
+ }
2500
+ function parseOutputCheck(stored) {
2501
+ if (stored === null) return null;
2502
+ try {
2503
+ const found = JSON.parse(stored);
2504
+ return {
2505
+ problems: Array.isArray(found.problems) ? found.problems : [],
2506
+ note: typeof found.note === "string" ? found.note : null
2507
+ };
2508
+ } catch {
2509
+ return null;
2510
+ }
2511
+ }
2512
+ function savePlainSummary(db, id, text) {
2513
+ db.prepare("UPDATE runs SET plain_summary = ? WHERE id = ?").run(text, id);
2514
+ bumpVersion(db);
2515
+ }
2516
+ var COLUMNS = `id, card_key, phase, engine, model, effort, session_id, cost_estimate, duration_ms,
2517
+ tokens_input, tokens_output, tokens_cache_read, tokens_cache_creation,
2518
+ question, error, state, attempt, lane, log_path, started_at, ended_at,
2519
+ verdict, verdict_reason, stack_state, stack_reason, wall`;
2520
+ function readRun(db, id) {
2521
+ const row = db.prepare(`SELECT ${COLUMNS} FROM runs WHERE id = ?`).get(id);
2522
+ return row === void 0 ? null : stored(row);
2523
+ }
2524
+ function cardRuns(db, key) {
2525
+ return db.prepare(`SELECT ${COLUMNS} FROM runs WHERE card_key = ? ORDER BY id`).all(key).map(stored);
2526
+ }
2527
+ function boardRuns(db, board) {
2528
+ return db.prepare(`SELECT ${COLUMNS} FROM runs WHERE card_key IN (SELECT key FROM cards WHERE board = ?) ORDER BY id`).all(board).map(stored);
2529
+ }
2530
+ function stored(row) {
2531
+ const tokens = [
2532
+ row.tokens_input,
2533
+ row.tokens_output,
2534
+ row.tokens_cache_read,
2535
+ row.tokens_cache_creation
2536
+ ].every((count) => count === null) ? null : {
2537
+ input: row.tokens_input ?? 0,
2538
+ output: row.tokens_output ?? 0,
2539
+ cacheRead: row.tokens_cache_read ?? 0,
2540
+ cacheCreation: row.tokens_cache_creation ?? 0
2541
+ };
2542
+ return {
2543
+ id: row.id,
2544
+ cardKey: row.card_key,
2545
+ phase: row.phase,
2546
+ engine: row.engine,
2547
+ model: row.model,
2548
+ effort: row.effort,
2549
+ sessionId: row.session_id,
2550
+ costUsd: row.cost_estimate,
2551
+ durationMs: row.duration_ms,
2552
+ tokens,
2553
+ question: row.question,
2554
+ failureReason: row.error,
2555
+ state: row.state,
2556
+ attempt: row.attempt,
2557
+ lane: row.lane,
2558
+ logPath: row.log_path ?? "",
2559
+ startedAt: row.started_at,
2560
+ endedAt: row.ended_at,
2561
+ verdict: row.verdict,
2562
+ verdictReason: row.verdict_reason,
2563
+ stackState: row.stack_state,
2564
+ stackReason: row.stack_reason,
2565
+ wall: row.wall
2566
+ };
2567
+ }
2568
+ function allRuns(db) {
2569
+ return db.prepare(`SELECT ${COLUMNS} FROM runs ORDER BY id`).all().map(stored);
2570
+ }
2571
+ //#endregion
2572
+ //#region ../../packages/core/src/node/recovery.ts
2573
+ var NOW$2 = "strftime('%Y-%m-%dT%H:%M:%fZ')";
2574
+ var RESTARTED = "Nolzu restarted while this run was going, so it was stopped.";
2575
+ var FIX_CUT = "Nolzu restarted while this fix ran, so it was stopped. Look at the Changes tab, then press Fix again.";
2576
+ function recoverRuns(db, reason = RESTARTED) {
2577
+ const marks = ENDED.map(() => "?").join(", ");
2578
+ const live = db.prepare(`SELECT id, card_key, phase, thread FROM runs WHERE state IS NOT NULL AND state NOT IN (${marks}) ORDER BY id`).all(...ENDED);
2579
+ for (const row of live) db.prepare(`UPDATE runs SET state = 'interrupted', error = ?, ended_at = coalesce(ended_at, ${NOW$2}) WHERE id = ?`).run(reason, row.id);
2580
+ const fix = (row) => row.phase === "implement" && row.thread !== null;
2581
+ const cards = [...new Set(live.filter((row) => !fix(row)).map((row) => row.card_key))];
2582
+ for (const key of cards) db.prepare("UPDATE cards SET state = 'failed' WHERE key = ? AND state IN ('queued', 'running')").run(key);
2583
+ db.prepare("UPDATE cards SET state = 'idle' WHERE state IN ('queued', 'running')").run();
2584
+ db.prepare("UPDATE pr_discussions SET status = 'new', fix_failed = ? WHERE status = 'fixing'").run(FIX_CUT);
2585
+ return {
2586
+ runs: live.length,
2587
+ cards
2588
+ };
2589
+ }
2590
+ var BEFORE_BOOT = 6e4;
2591
+ var processRunning = (pid) => {
2592
+ try {
2593
+ process.kill(pid, 0);
2594
+ return true;
2595
+ } catch (error) {
2596
+ return error.code === "EPERM";
2597
+ }
2598
+ };
2599
+ function takeWriter(db, options) {
2600
+ const pid = options.pid ?? process.pid;
2601
+ const alive = options.alive ?? processRunning;
2602
+ const bootedAt = options.bootedAt ?? Date.now() - uptime() * 1e3;
2603
+ const startedAt = options.startedAt ?? (() => null);
2604
+ db.exec("BEGIN IMMEDIATE");
2605
+ try {
2606
+ const held = db.prepare("SELECT pid, at FROM writer WHERE id = 1").get();
2607
+ const thisBoot = held !== void 0 && Date.parse(held.at) >= bootedAt - BEFORE_BOOT;
2608
+ const started = held === void 0 ? null : startedAt(held.pid);
2609
+ const reused = held !== void 0 && started !== null && started > Date.parse(held.at) + 2e3;
2610
+ if (held !== void 0 && held.pid !== pid && thisBoot && alive(held.pid) && !reused) throw new Error(`Nolzu is already running on ${options.dataDir} as process ${held.pid}. Close that window, or stop that process, before starting another one.`);
2611
+ db.prepare(`INSERT INTO writer (id, pid, at) VALUES (1, ?, ${NOW$2}) ON CONFLICT (id) DO UPDATE SET pid = excluded.pid, at = excluded.at`).run(pid);
2612
+ db.exec("COMMIT");
2613
+ } catch (error) {
2614
+ if (db.isTransaction) db.exec("ROLLBACK");
2615
+ throw error;
2616
+ }
2617
+ }
2618
+ function startWriting(db, options) {
2619
+ takeWriter(db, options);
2620
+ return recoverRuns(db);
2621
+ }
2622
+ //#endregion
2623
+ //#region ../../packages/core/src/node/scout-sources.ts
2624
+ /**
2625
+ * The field names a secret hides behind.
2626
+ *
2627
+ * `PROJECT.md` section 6 says a source secret goes to the OS keychain, never into sqlite and never
2628
+ * into a log, and a comment saying so is not what holds it: the config is a map of whatever the
2629
+ * caller passes, so one forgotten field puts a token in the database file and in every backup of
2630
+ * it. These names are refused instead. A secret with a name nobody guessed still gets through, so
2631
+ * this catches the mistake and not an attacker.
2632
+ */
2633
+ var SECRET_NAMES = [
2634
+ "token",
2635
+ "secret",
2636
+ "password",
2637
+ "passwd",
2638
+ "apikey",
2639
+ "api_key",
2640
+ "credential",
2641
+ "bearer",
2642
+ "privatekey",
2643
+ "private_key"
2644
+ ];
2645
+ function refuseSecret(config) {
2646
+ const named = Object.keys(config).find((name) => SECRET_NAMES.some((secret) => name.toLowerCase().includes(secret)));
2647
+ if (named === void 0) return;
2648
+ throw new Error(`A source's settings may not hold ${JSON.stringify(named)}. A secret goes to the OS keychain under the source's own entry, never into the database, so store it there and keep the settings to what a person may read.`);
2649
+ }
2650
+ function readConfig(text) {
2651
+ try {
2652
+ const parsed = JSON.parse(text);
2653
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return {};
2654
+ return Object.fromEntries(Object.entries(parsed).flatMap(([name, value]) => typeof value === "string" ? [[name, value]] : []));
2655
+ } catch {
2656
+ return {};
2657
+ }
2658
+ }
2659
+ var read$1 = (row) => ({
2660
+ id: row.id,
2661
+ kind: isScoutSourceKind(row.kind) ? row.kind : "paste",
2662
+ label: row.label,
2663
+ config: readConfig(row.config_json),
2664
+ enabled: row.enabled === 1,
2665
+ createCards: row.create_cards === 1,
2666
+ autoAssess: row.auto_assess === 1,
2667
+ scheduleMinutes: row.schedule_minutes,
2668
+ notify: row.notify === 1,
2669
+ cursor: row.cursor,
2670
+ lastChecked: row.last_checked,
2671
+ lastError: row.last_error
2672
+ });
2673
+ function scoutSources(db) {
2674
+ return db.prepare("SELECT * FROM scout_sources ORDER BY id").all().map(read$1);
2675
+ }
2676
+ function scoutSource(db, id) {
2677
+ const row = db.prepare("SELECT * FROM scout_sources WHERE id = ?").get(id);
2678
+ return row === void 0 ? null : read$1(row);
2679
+ }
2680
+ function addScoutSource(db, source) {
2681
+ refuseSecret(source.config ?? {});
2682
+ return db.prepare("INSERT INTO scout_sources (kind, label, config_json) VALUES (?, ?, ?) RETURNING id").get(source.kind, source.label, JSON.stringify(source.config ?? {})).id;
2683
+ }
2684
+ /**
2685
+ * One source's own settings, as far as a person sets them.
2686
+ *
2687
+ * The cursor, the last check and the last error are not here. Those belong to a check, and
2688
+ * `finishScoutCheck` below is the one writer of them, so a screen cannot make a source look checked
2689
+ * when nothing ran.
2690
+ */
2691
+ function setScoutSource(db, id, patch) {
2692
+ refuseSecret(patch.config ?? {});
2693
+ const columns = [];
2694
+ if (patch.label !== void 0) columns.push(["label", patch.label]);
2695
+ if (patch.config !== void 0) columns.push(["config_json", JSON.stringify(patch.config)]);
2696
+ if (patch.enabled !== void 0) columns.push(["enabled", patch.enabled ? 1 : 0]);
2697
+ if (patch.createCards !== void 0) columns.push(["create_cards", patch.createCards ? 1 : 0]);
2698
+ if (patch.autoAssess !== void 0) columns.push(["auto_assess", patch.autoAssess ? 1 : 0]);
2699
+ if (patch.scheduleMinutes !== void 0) columns.push(["schedule_minutes", patch.scheduleMinutes]);
2700
+ if (patch.notify !== void 0) columns.push(["notify", patch.notify ? 1 : 0]);
2701
+ if (columns.length === 0) return;
2702
+ db.prepare(`UPDATE scout_sources SET ${columns.map(([name]) => `${name} = ?`).join(", ")} WHERE id = ?`).run(...columns.map(([, value]) => value), id);
2703
+ }
2704
+ /**
2705
+ * The marker of one source, cleared.
2706
+ *
2707
+ * Its own function and not a field of `setScoutSource`, so a screen still cannot make a source look
2708
+ * checked. A settings change that names other rows has to clear it: a source pointed at another index
2709
+ * keeps asking for rows newer than the last check of the old one, and an older index answers nothing
2710
+ * for good, on every press, with no way out but removing the source and its findings.
2711
+ */
2712
+ function clearScoutCursor(db, id) {
2713
+ db.prepare("UPDATE scout_sources SET cursor = NULL WHERE id = ?").run(id);
2714
+ }
2715
+ var NOW$1 = "strftime('%Y-%m-%dT%H:%M:%fZ')";
2716
+ /**
2717
+ * Where a check ends: the three columns `setScoutSource` cannot write.
2718
+ *
2719
+ * All three move together, because a cursor written without a time would leave a source that looks
2720
+ * unchecked while it has already read everything, and the person would paste it all again.
2721
+ */
2722
+ function finishScoutCheck(db, id, end) {
2723
+ db.prepare(`UPDATE scout_sources SET cursor = ?, last_checked = ${NOW$1}, last_error = ? WHERE id = ?`).run(end.cursor, end.error ?? null, id);
2724
+ }
2725
+ function removeScoutSource(db, id) {
2726
+ db.prepare("DELETE FROM scout_sources WHERE id = ?").run(id);
2727
+ }
2728
+ //#endregion
2729
+ //#region ../../packages/core/src/node/scout-findings.ts
2730
+ var read = (row) => ({
2731
+ id: row.id,
2732
+ sourceId: row.source_id,
2733
+ fingerprint: row.fingerprint,
2734
+ kind: row.kind,
2735
+ status: row.status,
2736
+ occurrences: row.occurrences,
2737
+ firstSeen: row.first_seen,
2738
+ lastSeen: row.last_seen,
2739
+ firstMessage: row.first_message,
2740
+ lastMessage: row.last_message,
2741
+ location: row.location,
2742
+ cardKey: row.card_key,
2743
+ externalKey: row.external_key
2744
+ });
2745
+ var NOW = "strftime('%Y-%m-%dT%H:%M:%fZ')";
2746
+ /**
2747
+ * The groups of one fetch, written onto the findings of one source.
2748
+ *
2749
+ * The same fingerprint updates the one finding it already has, adding what this fetch counted and
2750
+ * moving the last seen time, because `PROJECT.md` section 6 asks for one finding per event and not
2751
+ * one per check. `first_seen` and `first_message` are left where the first check put them: they are
2752
+ * how the detail says how long the problem has been going on.
2753
+ *
2754
+ * A dismissed finding is skipped whole. Both lists order by `last_seen`, so moving that column would
2755
+ * put the muted finding back at the top of the screen, which is the one thing a mute has to stop.
2756
+ */
2757
+ /**
2758
+ * The most occurrences one save may add, and the most a row may hold.
2759
+ *
2760
+ * The column is read back as a JavaScript number, and a value past 2^53 makes `node:sqlite` throw on
2761
+ * the READ, after the write has landed. One such row takes every read of this table with it, so the
2762
+ * screen a person would use to delete the row is the screen that stops opening. A hub job carrying
2763
+ * `Number.MAX_SAFE_INTEGER` proved that before these two caps existed.
2764
+ *
2765
+ * A trillion, which no real source reaches: five hundred lines every quarter of an hour is seventeen
2766
+ * million a year, so this is twenty thousand years of the widest source.
2767
+ *
2768
+ * TWO CAPS AND NOT ONE, and the second is double the first on purpose. A row this save opened holds
2769
+ * exactly what the save added, which is how the count below tells an opened row from a met one. With
2770
+ * one cap a met row already at it would hold exactly the added value too, and every capped finding
2771
+ * would report as new on every check. Because a row holds at least one occurrence, a sum capped at
2772
+ * twice the addition is always larger than the addition, so that test stays sound. Both are far
2773
+ * enough below 2^53 that the sum is exact.
2774
+ */
2775
+ var MAX_ADDED = 0xe8d4a51000;
2776
+ var MAX_OCCURRENCES = MAX_ADDED * 2;
2777
+ function saveScoutFindings(db, sourceId, groups) {
2778
+ const write = db.prepare(`INSERT INTO scout_findings (source_id, fingerprint, occurrences, first_seen, last_seen, first_message, last_message, location, external_key)
2779
+ VALUES (?, ?, ?, ${NOW}, ${NOW}, ?, ?, ?, ?)
2780
+ ON CONFLICT (source_id, fingerprint) DO UPDATE SET
2781
+ -- Capped, because the sum is read back as a JavaScript number and node:sqlite throws a
2782
+ -- RangeError on one past 2^53. That throw is not recoverable by a person: the row is already
2783
+ -- written, and every later read of this table raises it, which takes the whole findings screen
2784
+ -- down and with it the Dismiss and Unmute buttons that would have removed the row. An adapter
2785
+ -- that reports a wrong count is a bug worth a wrong number on a screen and never worth that.
2786
+ occurrences = min(occurrences + excluded.occurrences, ${MAX_OCCURRENCES}),
2787
+ last_seen = excluded.last_seen,
2788
+ last_message = excluded.last_message,
2789
+ location = excluded.location,
2790
+ -- coalesce and not the new value alone, so a row written before the column was there picks its
2791
+ -- ticket up on the next check. Nothing reaches the null side today: a ticket's fingerprint is
2792
+ -- built from its key, so a row cannot be met by an item carrying no key.
2793
+ external_key = coalesce(excluded.external_key, external_key)
2794
+ WHERE status <> 'dismissed'
2795
+ RETURNING occurrences`);
2796
+ const change = {
2797
+ added: 0,
2798
+ met: 0,
2799
+ muted: 0
2800
+ };
2801
+ for (const group of groups) {
2802
+ const count = Math.min(Math.max(Math.trunc(group.count), 0), MAX_ADDED);
2803
+ const after = write.get(sourceId, group.fingerprint, count, group.first.message, group.last.message, group.last.location, ticketKeyOf(group.last));
2804
+ if (after === void 0) change.muted += 1;
2805
+ else if (after.occurrences === count) change.added += 1;
2806
+ else change.met += 1;
2807
+ }
2808
+ if (change.added > 0) {
2809
+ const label = scoutSource(db, sourceId)?.label;
2810
+ const text = `Scout: ${change.added} new ${change.added === 1 ? "finding" : "findings"}${label === void 0 ? "" : ` from ${label}`}`;
2811
+ addNotification(db, {
2812
+ id: `scout:${sourceId}:${randomUUID()}`,
2813
+ kind: "info",
2814
+ text,
2815
+ href: "/scout"
2816
+ });
2817
+ }
2818
+ return change;
2819
+ }
2820
+ function allScoutFindings(db) {
2821
+ return db.prepare("SELECT * FROM scout_findings ORDER BY last_seen DESC, id DESC").all().map(read);
2822
+ }
2823
+ function scoutFinding(db, id) {
2824
+ const row = db.prepare("SELECT * FROM scout_findings WHERE id = ?").get(id);
2825
+ return row === void 0 ? null : read(row);
2826
+ }
2827
+ /**
2828
+ * The finding one source holds under one fingerprint, or null when it holds none.
2829
+ *
2830
+ * The pair is the table's unique key, so this answers one row and reads the index that key made. It
2831
+ * is how a caller that has just saved a group learns the id of the row the save opened or met:
2832
+ * `saveScoutFindings` counts what changed and a count names no row.
2833
+ */
2834
+ function scoutFindingOf(db, sourceId, fingerprint) {
2835
+ const row = db.prepare("SELECT * FROM scout_findings WHERE source_id = ? AND fingerprint = ?").get(sourceId, fingerprint);
2836
+ return row === void 0 ? null : read(row);
2837
+ }
2838
+ /**
2839
+ * One finding muted, which is the mute itself and no second table: the row is already unique on
2840
+ * `(source_id, fingerprint)`, and that pair is what a mute applies to.
2841
+ *
2842
+ * False for an id that is not there and for one that is dismissed already, so a screen answers a
2843
+ * sentence instead of claiming a change nothing made.
2844
+ *
2845
+ * ponytail: no reason and no muted_at. Both are columns, so both cost a migration, and the row
2846
+ * already says when the finding was last seen. They arrive with the migration that adds them.
2847
+ */
2848
+ function dismissScoutFinding(db, id) {
2849
+ return db.prepare("UPDATE scout_findings SET status = 'dismissed' WHERE id = ? AND status <> 'dismissed'").run(id).changes > 0;
2850
+ }
2851
+ /**
2852
+ * A muted finding back on the list, with the count and the first seen time it went away with.
2853
+ *
2854
+ * Only the word moves. Those two numbers are still true, so the finding comes back saying how often
2855
+ * it has been seen and since when, and the next check adds to what it kept.
2856
+ *
2857
+ * It comes back as `started` where it already has a card key, and as `new` otherwise. `new` for both
2858
+ * threw away the one column that says a finding is on a board: the row then read New beside a live
2859
+ * card, and Assess was offered on work somebody had already started. A key whose card was deleted
2860
+ * still reads `started`, which is the column Start is offered from again.
2861
+ */
2862
+ function unmuteScoutFinding(db, id) {
2863
+ return db.prepare("UPDATE scout_findings SET status = CASE WHEN card_key IS NULL THEN 'new' ELSE 'started' END WHERE id = ? AND status = 'dismissed'").run(id).changes > 0;
2864
+ }
2865
+ /**
2866
+ * One finding moved to the assessment column, which is what starting an assessment writes.
2867
+ *
2868
+ * Only from `new`, so a dismissed finding is not brought back by a button on the list and a finding
2869
+ * already in assessment does not move twice. False in both cases, the way dismiss and unmute answer,
2870
+ * so the screen says a sentence instead of claiming a change nothing made.
2871
+ *
2872
+ * The assessment itself is a file in the run's own folder and no column here: every phase writes its
2873
+ * artifact there, the run row already carries the state, the cost and the log path, and a column
2874
+ * costs an appended migration. The status word is all the board needs to draw the finding in the
2875
+ * right column.
2876
+ */
2877
+ function assessScoutFinding(db, id) {
2878
+ return db.prepare("UPDATE scout_findings SET status = 'assess' WHERE id = ? AND status = 'new'").run(id).changes > 0;
2879
+ }
2880
+ /**
2881
+ * The columns a finding can be started from.
2882
+ *
2883
+ * `done` is finished and `dismissed` is muted, so neither starts. `started` is in the list because a
2884
+ * card can be deleted: the finding then names a key the board does not answer, and without this it
2885
+ * would sit on that key for good. A finding whose card is still there is refused by the card check
2886
+ * below, not by this list.
2887
+ */
2888
+ var CAN_START = [
2889
+ "new",
2890
+ "assess",
2891
+ "decide",
2892
+ "parked",
2893
+ "started"
2894
+ ];
2895
+ /**
2896
+ * Whether Start would be accepted, so a screen offers the button exactly where the writer takes it.
2897
+ *
2898
+ * The writer asks the status half of this too. Two copies of that list would let a button appear
2899
+ * where the answer is a refusal, which is the one thing a button must not do. The card half is the
2900
+ * writer's own line, because it has a sentence naming the card and this answers only true or false.
2901
+ */
2902
+ var canStartFinding = (status, hasCard) => !hasCard && CAN_START.includes(status);
2903
+ /**
2904
+ * How much of the collected line the card carries.
2905
+ *
2906
+ * One pasted line can be fifty thousand characters. The card is a ticket a person reads and an agent
2907
+ * is handed, not the evidence store, and every character stays on the finding's own page, so the
2908
+ * card takes the head of the line and says where the rest is.
2909
+ */
2910
+ var LINE_CAP = 2e3;
2911
+ /**
2912
+ * What the card says about the finding it was made from.
2913
+ *
2914
+ * The newest line and not both of them: the first line seen, the times and the count are on the
2915
+ * finding's page, and a card that copied the whole page would be a second place to keep it up to
2916
+ * date. The newest line is here because it is the one thing the work needs in front of it, on the
2917
+ * card page and in the prompt of whatever run the card starts later.
2918
+ *
2919
+ * The line goes in the body and never in the title. A title reaches a branch name, and `slugify`
2920
+ * keeps the letters and the digits of whatever it is handed, so a token in a collected line would
2921
+ * become part of a name that is pushed to a remote and cannot be taken back.
2922
+ *
2923
+ * The body is not free of it. The summary is what the prompt of a later run carries, so a token in
2924
+ * the line is in front of the engine. That is the exposure the pasted line already has, on the
2925
+ * finding's own page and in sqlite, and the person pasting it chose it. A card a run is handed
2926
+ * without the line it is about would send that run to read the finding instead.
2927
+ */
2928
+ function cardBody(one) {
2929
+ const parts = [
2930
+ "Scout found this, and a person started it from the Scout screen.",
2931
+ "The newest line it was seen on:",
2932
+ one.lastMessage.length > LINE_CAP ? `${one.lastMessage.slice(0, LINE_CAP)}\n[The line is cut here. Finding ${one.id} has all of it.]` : one.lastMessage
2933
+ ];
2934
+ if (one.location !== "") parts.push(`Where it happens: ${one.location}`);
2935
+ parts.push(one.occurrences === 1 ? "Seen once." : `Seen ${one.occurrences} times.`);
2936
+ parts.push(`Finding ${one.id} on the Scout screen keeps the whole evidence: the first line seen, the newest one and the times.`);
2937
+ return parts.join("\n\n");
2938
+ }
2939
+ /**
2940
+ * One finding accepted, as a card on the board that was asked for.
2941
+ *
2942
+ * One writer for both buttons, with the board as its argument. Start as Delivery and Start as
2943
+ * Investigation differ in that one word, so a second writer would be a copy of this one.
2944
+ *
2945
+ * The card and the two columns of the finding move in one transaction, so the board never holds a
2946
+ * card whose finding still reads `new`, and a finding never points at a card that was not written.
2947
+ *
2948
+ * No run starts. The card lands in the board's first column and waits there like every other card,
2949
+ * which is what keeps this a person's decision.
2950
+ *
2951
+ * The key is the project's own ticket key, the same counter the Add card dialog draws from. It is
2952
+ * one plain name, so the card gets a card folder, it is unique because the counter skips a number
2953
+ * another card already holds, and a person reads `APP-7` on the board rather than a shape only this
2954
+ * screen writes.
2955
+ *
2956
+ * A finding a ticket query found is the one exception. It keeps the ticket's own key, because the
2957
+ * card is that ticket, and where the ticket is already on the board the finding points at the card
2958
+ * that is there. Both are what stops one Jira ticket becoming two cards.
2959
+ */
2960
+ function startScoutFinding(db, id, board = "delivery") {
2961
+ db.exec("BEGIN IMMEDIATE");
2962
+ const refuse = (message) => {
2963
+ db.exec("ROLLBACK");
2964
+ return {
2965
+ ok: false,
2966
+ message
2967
+ };
2968
+ };
2969
+ try {
2970
+ const one = scoutFinding(db, id);
2971
+ if (one === null) return refuse(`There is no finding ${id} on this machine. It may have gone with the source that found it.`);
2972
+ if (one.cardKey !== null && db.prepare("SELECT key FROM cards WHERE key = ?").get(one.cardKey) !== void 0) return refuse(`Finding ${id} is already on the board as ${one.cardKey}. Open that card instead of making a second one.`);
2973
+ if (!canStartFinding(one.status, false)) return refuse(one.status === "dismissed" ? `Finding ${id} is muted, so nothing is started from it. Unmute it first, then start it.` : `Finding ${id} is done, so there is nothing to start. Its work is over.`);
2974
+ const source = scoutSource(db, one.sourceId);
2975
+ const label = source?.label ?? "";
2976
+ const stage = boardFor(board, getSetting(db, "deliveryFlow")).stages[0]?.id ?? "inbox";
2977
+ const ticket = one.externalKey;
2978
+ if (ticket !== null) {
2979
+ const key = cardKeyOf(ticket);
2980
+ const config = source?.config;
2981
+ const path = config?.system === "github" ? config.repo : config?.system === "gitlab" ? config.project : void 0;
2982
+ const owner = /^(.+)\/[^/]+$/.exec(path ?? "")?.[1];
2983
+ const ref = key !== ticket || owner === void 0 ? ticket : `${owner.toLowerCase()}/${ticket}`;
2984
+ const held = db.prepare("SELECT source_ref FROM cards WHERE key = ?").get(key);
2985
+ const problem = ticketRefProblem(ticket);
2986
+ const badKey = `Finding ${id} is a ticket whose key cannot be a card key, so no card was made. ${problem}`;
2987
+ if (held !== void 0 && held.source_ref !== null && held.source_ref !== ref) return refuse(problem !== null ? badKey : `Finding ${id} is ${ref}, and ${key} on the board is ${held.source_ref}. A card key carries no owner or group, so no card was made.`);
2988
+ const already = held !== void 0;
2989
+ if (!already) {
2990
+ if (problem !== null) return refuse(badKey);
2991
+ createCard(db, {
2992
+ key,
2993
+ board,
2994
+ stage,
2995
+ title: one.lastMessage,
2996
+ summary: cardBody(one),
2997
+ source: config?.system === "jira" ? "jira" : "external",
2998
+ sourceRef: ref
2999
+ });
3000
+ }
3001
+ db.prepare("UPDATE scout_findings SET card_key = ?, status = 'started' WHERE id = ?").run(key, id);
3002
+ db.exec("COMMIT");
3003
+ return already ? {
3004
+ ok: true,
3005
+ key,
3006
+ alreadyOnBoard: true
3007
+ } : {
3008
+ ok: true,
3009
+ key
3010
+ };
3011
+ }
3012
+ const { key } = createLocalTicket(db, {
3013
+ projectId: 1,
3014
+ prefix: getSetting(db, "localKeyPrefix"),
3015
+ title: label === "" ? `Scout finding ${id}` : `Scout finding ${id}, from ${label}`,
3016
+ description: cardBody(one),
3017
+ board,
3018
+ stage
3019
+ });
3020
+ db.prepare("UPDATE scout_findings SET card_key = ?, status = 'started' WHERE id = ?").run(key, id);
3021
+ db.exec("COMMIT");
3022
+ return {
3023
+ ok: true,
3024
+ key
3025
+ };
3026
+ } catch (error) {
3027
+ if (db.isTransaction) db.exec("ROLLBACK");
3028
+ throw error;
3029
+ }
3030
+ }
3031
+ //#endregion
3032
+ //#region ../../packages/core/src/node/scout-check.ts
3033
+ var refused = (error) => ({
3034
+ added: 0,
3035
+ met: 0,
3036
+ muted: 0,
3037
+ error
3038
+ });
3039
+ /**
3040
+ * One paste source, checked.
3041
+ *
3042
+ * The whole pipeline of `PROJECT.md` section 6, and no engine in it: read the source, fetch from its
3043
+ * cursor, fold the occurrences into events, write the findings, stamp the check. Nothing new means
3044
+ * no group, which means no write to a finding and no run row anywhere. The agent is what the
3045
+ * findings board starts later, on a finding a person picked.
3046
+ *
3047
+ * One source, because the screen has one button per source. A check of all of them would read a
3048
+ * paste box that belongs to one of them.
3049
+ */
3050
+ function checkPasteSource(db, id, text) {
3051
+ const source = scoutSource(db, id);
3052
+ if (source === null) return refused("That source is gone. Pick one from the sources on the Scout page.");
3053
+ if (!source.enabled) return refused(`The source "${source.label}" is turned off. Turn it on in the source on the Scout page to check it.`);
3054
+ if (source.kind !== "paste") return refused(`The source "${source.label}" is not a pasted source, so there is no text to read. Check it from its own screen.`);
3055
+ const fetched = fetchPaste(text, source.cursor);
3056
+ return store(db, id, dedup(fetched.items), fetched.cursor);
3057
+ }
3058
+ /**
3059
+ * One ticket query source, checked.
3060
+ *
3061
+ * Both ticket systems answer rows and no grouping of their own, so their occurrences go through
3062
+ * `dedup` here. What that gives, and the guards and the stamp around it, are `overNetwork` below.
3063
+ */
3064
+ async function checkTicketSource(db, id, read) {
3065
+ return overNetwork(db, id, {
3066
+ kind: "tickets",
3067
+ wrongKind: (label) => `The source "${label}" is not a ticket query, so there is nothing to ask a ticket system. Check it from its own screen.`,
3068
+ silent: "The ticket system did not answer.",
3069
+ read: async (source) => {
3070
+ const fetched = await read(source);
3071
+ return {
3072
+ groups: dedup(fetched.items),
3073
+ cursor: fetched.cursor
3074
+ };
3075
+ }
3076
+ });
3077
+ }
3078
+ /**
3079
+ * One Sentry source, checked.
3080
+ *
3081
+ * Its own action and no branch inside the ticket check, because the two answer different shapes:
3082
+ * Sentry has already grouped its events, so the adapter hands over groups and `dedup` is not run over
3083
+ * them. Everything else, the guards, the fetch outside the transaction and the stamp, is shared below.
3084
+ */
3085
+ async function checkSentrySource(db, id, read) {
3086
+ return overNetwork(db, id, {
3087
+ kind: "sentry",
3088
+ wrongKind: (label) => `The source "${label}" is not a Sentry project, so there is nothing to ask Sentry. Check it from its own screen.`,
3089
+ silent: "Sentry did not answer.",
3090
+ read
3091
+ });
3092
+ }
3093
+ /**
3094
+ * One log query source, checked.
3095
+ *
3096
+ * The source that puts real text through `normalize`, `fingerprint` and `dedup`: a log line carries no
3097
+ * identity of its own, so the same error at two timestamps folds into one finding with two occurrences
3098
+ * here. Sentry and the ticket systems each carry an id, so this is the only source whose findings the
3099
+ * pipeline has to work out for itself.
3100
+ */
3101
+ async function checkSearchSource(db, id, read) {
3102
+ return overNetwork(db, id, {
3103
+ kind: "search",
3104
+ wrongKind: (label) => `The source "${label}" is not a log query, so there is no cluster to ask. Check it from its own screen.`,
3105
+ silent: "The cluster did not answer.",
3106
+ read: async (source) => {
3107
+ const fetched = await read(source);
3108
+ return {
3109
+ groups: dedup(fetched.items),
3110
+ cursor: fetched.cursor
3111
+ };
3112
+ }
3113
+ });
3114
+ }
3115
+ /**
3116
+ * The guards, the fetch and the stamp every source read over the network shares.
3117
+ *
3118
+ * The fetch happens before the transaction and never inside it. `DatabaseSync` is synchronous and
3119
+ * `BEGIN IMMEDIATE` takes sqlite's write lock at once, so an awaited call between it and the COMMIT
3120
+ * would hold the write lock of the whole database across a network call and every other writer would
3121
+ * wait out the busy timeout.
3122
+ *
3123
+ * A fetch that worked and a write that failed rolls back whole, so the cursor stays where it was: the
3124
+ * same events come back on the next check and are counted once. The other order cannot be recovered,
3125
+ * because a cursor moved past an event that was never stored never reports it again.
3126
+ *
3127
+ * Unlike a pasted source, a failed fetch is stamped on the row: `gh` may not be logged in and a token
3128
+ * may be refused, and those are sentences a person has to be able to read later on the Scout page. The
3129
+ * cursor is written back as it was, so a network blip does not replay the whole query.
3130
+ */
3131
+ async function overNetwork(db, id, adapter) {
3132
+ const source = scoutSource(db, id);
3133
+ if (source === null) return refused("That source is gone. Pick one from the sources on the Scout page.");
3134
+ if (!source.enabled) return refused(`The source "${source.label}" is turned off. Turn it on in the source on the Scout page to check it.`);
3135
+ if (source.kind !== adapter.kind) return refused(adapter.wrongKind(source.label));
3136
+ let fetched;
3137
+ try {
3138
+ fetched = await adapter.read(source);
3139
+ } catch (error) {
3140
+ const said = error instanceof Error ? error.message : adapter.silent;
3141
+ finishScoutCheck(db, id, {
3142
+ cursor: source.cursor,
3143
+ error: said
3144
+ });
3145
+ return refused(said);
3146
+ }
3147
+ return store(db, id, fetched.groups, fetched.cursor);
3148
+ }
3149
+ /**
3150
+ * The findings and the cursor, written together or not at all.
3151
+ *
3152
+ * Half the findings with a moved cursor cannot be recovered: the events that were skipped never come
3153
+ * back, and the ones that were stored are counted twice on the next check. Shared by every check
3154
+ * because they all owe exactly this, and a copy of it would be a second chance to get the order wrong.
3155
+ */
3156
+ function store(db, id, groups, cursor) {
3157
+ db.exec("BEGIN IMMEDIATE");
3158
+ try {
3159
+ const change = saveScoutFindings(db, id, groups);
3160
+ finishScoutCheck(db, id, { cursor });
3161
+ db.exec("COMMIT");
3162
+ return {
3163
+ ...change,
3164
+ error: null
3165
+ };
3166
+ } catch (error) {
3167
+ if (db.isTransaction) db.exec("ROLLBACK");
3168
+ return refused(`The findings could not be stored, so nothing was checked. ${error instanceof Error ? error.message : "The database refused the write."}`);
3169
+ }
3170
+ }
3171
+ //#endregion
3172
+ //#region ../../packages/core/src/node/snapshot.ts
3173
+ /**
3174
+ * The commits pushed since the last review round read the head, or null while there is nothing new.
3175
+ *
3176
+ * A head is compared and not a count, because a force push can leave the count as it was.
3177
+ * ponytail: a rewrite that drops commits reads as 1 new commit. The head did move, which is what the
3178
+ * person needs to know; telling a rewrite apart needs a compare call per card.
3179
+ */
3180
+ function newCommitsOf(row) {
3181
+ if (row.pr_seen_sha === null || row.pr_head_sha === null || row.pr_seen_sha === row.pr_head_sha) return null;
3182
+ return Math.max(1, (row.pr_seen_commits ?? 0) - (row.pr_head_commits ?? 0));
3183
+ }
3184
+ function outputProblemsOf(stored) {
3185
+ const problems = parseOutputCheck(stored)?.problems ?? [];
3186
+ return problems.length === 0 ? {} : { outputProblems: problems };
3187
+ }
3188
+ /**
3189
+ * Every epic's tasks, read in one query for the whole board, oldest first.
3190
+ *
3191
+ * A task is a linked card on the Delivery board. `card_links` keeps the pair once in key order, so
3192
+ * nothing records which side is the epic and both columns have to be asked. Done is the Delivery
3193
+ * board's archive stage, read off the board, because the flow swaps a stage in the middle and a
3194
+ * second copy of the id here would be the one that goes stale. Ordered by rowid and not by key: a key
3195
+ * sorts as text, so APP-10 would land before APP-2.
3196
+ *
3197
+ * ponytail: a Delivery card a person links to an epic by hand counts as a task as well, which is
3198
+ * most likely what they meant by linking it. Telling the two apart needs a column of its own, so a
3199
+ * migration, and a second meaning for this table.
3200
+ */
3201
+ function epicTasks(db, flow) {
3202
+ const closed = boardFor("delivery").stages.find((stage) => stage.role === "archive")?.id ?? "closed";
3203
+ const rows = db.prepare(`SELECT e.key AS epic, d.key, d.title, d.state, d.stage, l.step
3204
+ FROM cards e
3205
+ JOIN card_links l ON l.a = e.key OR l.b = e.key
3206
+ JOIN cards d ON d.key = CASE WHEN l.a = e.key THEN l.b ELSE l.a END AND d.board = 'delivery'
3207
+ WHERE e.board = 'epics'
3208
+ ORDER BY d.rowid`).all();
3209
+ return new Map([...Map.groupBy(rows, (row) => row.epic)].map(([epic, list]) => [epic, list.map((row) => ({
3210
+ key: row.key,
3211
+ title: row.title,
3212
+ state: row.state,
3213
+ done: row.stage === closed,
3214
+ ...row.step === null ? {} : { step: row.step }
3215
+ }))]));
3216
+ }
3217
+ function deliveredOf(tasks, planned, following) {
3218
+ const notAdded = following ? matchPlan(planned ?? [], tasks).filter((task) => task === null).length : 0;
3219
+ const done = tasks.filter((task) => task.done).length;
3220
+ const total = tasks.length + notAdded;
3221
+ return {
3222
+ delivered: total === 0 ? null : {
3223
+ done,
3224
+ total
3225
+ },
3226
+ ...tasks.length === 0 ? {} : { tasks },
3227
+ ...following && total > 0 && done === total ? { finished: true } : {}
3228
+ };
3229
+ }
3230
+ /**
3231
+ * The run state a person is shown. A wrap-up held for Knowledge is the person's only while a change waits
3232
+ * for them; held behind a knowledge run alone, it is a wait for the Knowledge lane. Its row keeps
3233
+ * `waiting_review`, which is what a Stop finds it by. Every screen that draws a run's state reads it
3234
+ * through this, so the board, Now, the trail and History say the same.
3235
+ */
3236
+ function shownRunState(db) {
3237
+ const pending = pendingKnowledgeChanges(db).length > 0;
3238
+ return (state) => state === "waiting_review" && !pending ? "waiting_lane" : state;
3239
+ }
3240
+ function boardSnapshot(db, input) {
3241
+ const { board, queue, models, project: projectId } = input;
3242
+ const preset = getSetting(db, "modelPreset");
3243
+ const global = getSetting(db, "models");
3244
+ const profiles = projectProfiles(db);
3245
+ const place = {
3246
+ outsideGit: projectOutsideGit(db),
3247
+ wall: input.wall
3248
+ };
3249
+ const project = resolveModels(null, global, preset, models, profiles, null, place);
3250
+ const startsOf = (table, phase) => {
3251
+ if (!isAction(phase)) return null;
3252
+ const resolved = table[phase];
3253
+ const modelState = resolved.missingProfile ? "no-profile" : resolved.refusal !== null ? "vendor" : resolved.gone ? "gone" : "ok";
3254
+ const vendor = profiles.find((one) => one.id === resolved.engine)?.vendor;
3255
+ return {
3256
+ phase,
3257
+ model: resolved.model,
3258
+ effort: resolved.effort,
3259
+ engine: resolved.engine,
3260
+ modelState,
3261
+ refusal: resolved.refusal,
3262
+ ...profiles.length > 1 ? { severalProfiles: true } : {},
3263
+ estimate: modelState === "ok" ? startEstimate(db, {
3264
+ phase,
3265
+ model: resolved.model,
3266
+ effort: resolved.effort,
3267
+ vendor
3268
+ }) : void 0
3269
+ };
3270
+ };
3271
+ const cardStartsOf = (key) => {
3272
+ const own = cardModels(db, key);
3273
+ const mine = cardPreset(db, key);
3274
+ if (own === null && mine === preset && cardSavedPreset(db, key) === null) return null;
3275
+ const table = resolveModels(own, cardBase(db, key), mine, models, profiles, null, place);
3276
+ const starts = {};
3277
+ for (const stage of board.stages) {
3278
+ const found = stage.phase === void 0 ? null : startsOf(table, stage.phase);
3279
+ if (found !== null && stage.phase !== void 0) starts[stage.phase] = found;
3280
+ }
3281
+ return starts;
3282
+ };
3283
+ const rows = db.prepare("SELECT key, title, stage, state, minimized, pr_author, pr_decision, pr_head_at, pr_draft, pr_state, pr_seen_sha, pr_seen_commits, pr_head_sha, pr_head_commits, pr_round FROM cards WHERE board = ? ORDER BY key").all(board.kind);
3284
+ const tasks = board.kind === "epics" ? epicTasks(db, getSetting(db, "deliveryFlow")) : /* @__PURE__ */ new Map();
3285
+ const following = board.kind === "epics" ? board.stages.find((stage) => stage.role === "auto")?.id : void 0;
3286
+ const archive = board.stages.find((stage) => stage.role === "archive")?.id;
3287
+ const feedback = board.kind === "delivery" ? feedbackCounts(db) : /* @__PURE__ */ new Map();
3288
+ const runs = db.prepare(`SELECT r.id, r.card_key, r.phase, r.engine, r.model, r.effort, r.state, r.started_at, r.lane, r.cost_estimate, r.question, r.question_options, r.error,
3289
+ r.verdict, r.verdict_reason, r.output_check
3290
+ FROM runs r
3291
+ JOIN (SELECT card_key, max(id) AS id FROM runs WHERE ${NOT_A_PASS} GROUP BY card_key) newest ON newest.id = r.id`).all();
3292
+ const newest = new Map(runs.map((row) => [row.card_key, row]));
3293
+ const runsOf = Map.groupBy(boardRuns(db, board.kind), (run) => run.cardKey);
3294
+ const jobs = new Map([...queue.waiting, ...queue.running].filter((job) => projectId === void 0 || job.project === projectId).map((job) => [job.cardKey, job]));
3295
+ const shown = runs.some((run) => run.state === "waiting_review") ? shownRunState(db) : (state) => state;
3296
+ const runStateOf = (run) => shown(run?.state ?? null);
3297
+ const cards = rows.map((row) => {
3298
+ const run = newest.get(row.key) ?? null;
3299
+ const job = jobs.get(row.key) ?? null;
3300
+ const wait = job === null ? null : waitFor(queue, job.runId, projectId);
3301
+ const options = storedQuestionOptions(run?.question_options ?? null);
3302
+ const follows = following !== void 0 && row.stage === following;
3303
+ const pushed = newCommitsOf(row);
3304
+ const comments = row.stage === archive ? void 0 : feedback.get(row.key);
3305
+ return {
3306
+ key: row.key,
3307
+ title: row.title,
3308
+ stage: row.stage,
3309
+ state: row.state,
3310
+ queuePosition: wait?.position ?? null,
3311
+ runId: run?.id ?? job?.runId ?? null,
3312
+ runState: wait === null ? runStateOf(run) : wait.reason === "lane" ? "waiting_lane" : "queued",
3313
+ runPhase: run?.phase ?? null,
3314
+ runStartedAt: run?.started_at ?? null,
3315
+ lane: job?.lane ?? run?.lane ?? null,
3316
+ engine: run?.engine ?? null,
3317
+ model: run?.model ?? null,
3318
+ effort: run?.effort ?? null,
3319
+ costUsd: run?.cost_estimate ?? null,
3320
+ totalUsd: spendOf(runsOf.get(row.key) ?? []).costUsd,
3321
+ question: run?.question ?? null,
3322
+ ...options === null ? {} : { questionOptions: options },
3323
+ failureReason: run?.error ?? null,
3324
+ minimized: row.minimized === 1,
3325
+ verdict: run?.verdict ?? null,
3326
+ verdictReason: run?.verdict_reason ?? null,
3327
+ ...row.stage === archive ? {} : outputProblemsOf(run?.output_check ?? null),
3328
+ ...comments === void 0 ? {} : { feedback: comments },
3329
+ pull: row.pr_decision === null ? null : {
3330
+ author: row.pr_author,
3331
+ decision: row.pr_decision,
3332
+ headCommittedAt: row.pr_head_at,
3333
+ draft: row.pr_draft === 1,
3334
+ round: row.pr_round,
3335
+ ...pushed === null ? {} : { newCommits: pushed },
3336
+ ...row.pr_state === "closed" || row.pr_state === "merged" ? { ended: row.pr_state } : {}
3337
+ },
3338
+ starts: cardStartsOf(row.key),
3339
+ ...deliveredOf(tasks.get(row.key) ?? [], follows ? input.planned?.(row.key) ?? null : null, follows)
3340
+ };
3341
+ });
3342
+ const counts = /* @__PURE__ */ new Map();
3343
+ for (const row of rows) counts.set(row.stage, (counts.get(row.stage) ?? 0) + 1);
3344
+ const stages = board.stages.map((stage) => {
3345
+ const says = stageSays(board.kind, stage.id);
3346
+ return {
3347
+ ...says === void 0 ? {} : { says },
3348
+ id: stage.id,
3349
+ label: stage.label,
3350
+ role: stage.role,
3351
+ count: counts.get(stage.id) ?? 0,
3352
+ cadence: null,
3353
+ starts: stage.phase === void 0 ? null : startsOf(project, stage.phase)
3354
+ };
3355
+ });
3356
+ const lanes = Object.keys(LANES).map((name) => {
3357
+ const holder = queue.running.find((job) => job.lane === name);
3358
+ const elsewhere = holder?.project !== void 0 && projectId !== void 0 && holder.project !== projectId;
3359
+ return {
3360
+ name,
3361
+ heldBy: holder?.cardKey ?? null,
3362
+ ...elsewhere ? { project: holder.project } : {}
3363
+ };
3364
+ });
3365
+ return {
3366
+ version: boardVersion(db),
3367
+ kind: board.kind,
3368
+ flow: getSetting(db, "deliveryFlow"),
3369
+ stages,
3370
+ cards,
3371
+ slots: {
3372
+ busy: queue.running.length,
3373
+ total: queue.slots
3374
+ },
3375
+ lanes,
3376
+ quietAfterMs: getSetting(db, "quietAfterMs")
3377
+ };
3378
+ }
3379
+
3380
+ export { scoutFindingOf as $, cardEstimate as A, renameCardPresets as B, storedQuestionOptions as C, shownRunState as D, readOnlyBreakOf as E, commitWarningOf as F, peekLocalKey as G, relatedCards as H, newCommitsOf as I, cardRepos as J, cardPullRows as K, allRuns as L, allCardMoves as M, NOT_A_PASS as N, registeredProjects as O, allScoutFindings as P, scoutSources as Q, moveCard as R, addNotification as S, setMinimized as T, bumpVersion as U, knowledgeChangesOfRun as V, returnKnowledgeChanges as W, readRun as X, applyKnowledgeChanges as Y, ENDED as Z, scoutSource as _, allKnowledgeChanges as a, dismissScoutFinding as a$, saveScoutFindings as a0, openProject as a1, openMachine as a2, FIRST_PROJECT as a3, openDatabase as a4, createLocalTicket as a5, createCard as a6, setCardRepos as a7, linkCards as a8, saveCardPull as a9, setCardStack as aA, startRun as aB, otherRunOfCard as aC, clearReadOnlyBreaks as aD, saveReadOnlyBreak as aE, beginFix as aF, beginFixAll as aG, fixedSinceQa as aH, lastJudgedQa as aI, assessScoutFinding as aJ, boardSnapshot as aK, applyTriage as aL, saveOutputCheck as aM, savePlainSummary as aN, promote as aO, remove as aP, enqueue as aQ, createQueue as aR, pick as aS, cardStack as aT, notifications as aU, unreadNotifications as aV, takeWriter as aW, setScoutSource as aX, addScoutSource as aY, checkPasteSource as aZ, startScoutFinding as a_, markDiscussion as aa, markDiscussionsSeen as ab, storeDiscussions as ac, cardDiscussions as ad, recordMove as ae, detachCardPull as af, projectFiles as ag, markRunning as ah, seenHead as ai, saveStackStatus as aj, saveRun as ak, recordKnowledgeChanges as al, savePullRound as am, saveQuestionOptions as an, parseQuestionOptions as ao, saveVerdict as ap, saveCommitWarning as aq, endFix as ar, reopenFixed as as, startWriting as at, recoverRuns as au, epicOfTask as av, returnedKnowledgeNote as aw, setCardTitle as ax, scoutFinding as ay, cardHolds as az, reposOfCard as b, unmuteScoutFinding as b0, removeScoutSource as b1, clearScoutCursor as b2, canStartFinding as b3, waitFor as b4, retryWait as b5, markKnowledgeMoved as b6, knowledgeChange as b7, revertKnowledgeChange as b8, projectOf as b9, createProject as ba, dropProject as bb, checkSearchSource as bc, checkSentrySource as bd, checkTicketSource as be, ticketPlan as bf, visible as bg, fingerprint as bh, fetchTickets as bi, deleteCardRows as bj, markNotificationsRead as bk, cardRuns as c, boardOfCard as d, projectProfiles as e, cardPreset as f, getSetting as g, cardBase as h, isFakeMode as i, cardModels as j, startEstimate as k, sessionInCardFolder as l, sessionFolder as m, setExtraContext as n, outputCheckOf as o, pendingKnowledgeChanges as p, followPreset as q, resolveDataDir as r, settingProblem as s, followSavedPreset as t, unlinkCards as u, setCardModels as v, writeSetting as w, cardSavedPreset as x, projectOutsideGit as y, cardFollowsProject as z };
3381
+ //# sourceMappingURL=node.js-Bz2jT5wt.js.map