@kabmo-labs/kabmo 0.46.1 → 0.48.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 (339) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +506 -502
  3. package/dist/client/static/js/Body-3tspyjtk.js +3 -0
  4. package/dist/client/static/js/{CsvGrid-qdkmv8bj.js → CsvGrid-3pwsfmxp.js} +2 -2
  5. package/dist/client/static/js/{DocxView-k84ns803.js → DocxView-xcg9jktb.js} +3 -3
  6. package/dist/client/static/js/{DrawioView-r1n717f7.js → DrawioView-2q19tgkx.js} +2 -2
  7. package/dist/client/static/js/HtmlPreview-92cadvbr.js +1 -0
  8. package/dist/client/static/js/ImageView-pr4h38hb.js +1 -0
  9. package/dist/client/static/js/LayoutWrapper-n4tzhjes.js +2 -0
  10. package/dist/client/static/js/MergeDiffView-0t15nh9f.js +1 -0
  11. package/dist/client/static/js/{Modal-xe6h99jn.js → Modal-77hgx4dw.js} +20 -20
  12. package/dist/client/static/js/{PdfView-ffg4mccg.js → PdfView-gzxhvxe8.js} +1 -1
  13. package/dist/client/static/js/{SessionsView-cdcbsee9.js → SessionsView-2tdqrvk0.js} +1 -1
  14. package/dist/client/static/js/{SheetView-89sscpz6.js → SheetView-w5w2m2de.js} +22 -22
  15. package/dist/client/static/js/{SvgPreview-68c0ccbv.js → SvgPreview-mtk6de6h.js} +1 -1
  16. package/dist/client/static/js/{abnfDiagram-O67JEVCF-h3a5s259.js → abnfDiagram-O67JEVCF-tha4j2fn.js} +1 -1
  17. package/dist/client/static/js/architecture-7GRP2DOG-zs15nydj.js +1 -0
  18. package/dist/client/static/js/{architectureDiagram-NJMV4G6O-983p0jgn.js → architectureDiagram-NJMV4G6O-heep78p6.js} +6 -6
  19. package/dist/client/static/js/{astro-hyj5wege.js → astro-r4dp34pw.js} +1 -1
  20. package/dist/client/static/js/bash-8d3wrx5c.js +1 -0
  21. package/dist/client/static/js/{blockDiagram-BEXU5L5S-16pse5mh.js → blockDiagram-BEXU5L5S-6mzgfqh8.js} +5 -5
  22. package/dist/client/static/js/c-rn3z0csz.js +1 -0
  23. package/dist/client/static/js/{c4Diagram-YGBWAQC7-mvnb00zt.js → c4Diagram-YGBWAQC7-sfkcw7g9.js} +4 -4
  24. package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-kmpd91xb.js → classDiagram-v2-NBCMYWYE-v530ny5e.js} +6 -6
  25. package/dist/client/static/js/{cose-bilkent-JH36ORCC-3ek5r5se.js → cose-bilkent-JH36ORCC-ybv1ttbx.js} +1 -1
  26. package/dist/client/static/js/cpp-99ws9nak.js +1 -0
  27. package/dist/client/static/js/css-narcr42w.js +1 -0
  28. package/dist/client/static/js/cynefin-OW5HDTMX-p3y1b4ap.js +1 -0
  29. package/dist/client/static/js/{cynefinDiagram-VND7K2PF-jkbh84zn.js → cynefinDiagram-VND7K2PF-k8f3z0mm.js} +2 -2
  30. package/dist/client/static/js/{dagre-6A5THRUB-4fdc0sgn.js → dagre-6A5THRUB-gk0gp124.js} +2 -2
  31. package/dist/client/static/js/{diagram-22UHCM2B-hbk61nq9.js → diagram-22UHCM2B-2zh2957c.js} +15 -15
  32. package/dist/client/static/js/{diagram-3UASUU5V-hfpbr9qh.js → diagram-3UASUU5V-bzstt5e2.js} +2 -2
  33. package/dist/client/static/js/{diagram-ATOU4E4O-fn0nt71a.js → diagram-ATOU4E4O-16adx4g0.js} +3 -3
  34. package/dist/client/static/js/{diagram-CDSNMT55-ssswxjeb.js → diagram-CDSNMT55-1ja98ens.js} +5 -5
  35. package/dist/client/static/js/{diagram-MLGK6HIB-whnzxv6f.js → diagram-MLGK6HIB-f9nnyjbq.js} +2 -2
  36. package/dist/client/static/js/{diagram-MPIPVDR6-hk1chzxk.js → diagram-MPIPVDR6-3qgadfjz.js} +2 -2
  37. package/dist/client/static/js/{dockerfile-zmsj8r4g.js → dockerfile-04tc68pq.js} +1 -1
  38. package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-q1vkg5mr.js → ebnfDiagram-ZINNZB2B-022cz603.js} +1 -1
  39. package/dist/client/static/js/{elixir-80wq7gak.js → elixir-61gbjv6c.js} +1 -1
  40. package/dist/client/static/js/{elk-276RUBZZ-kt98vg8j.js → elk-276RUBZZ-2anf1c36.js} +1 -1
  41. package/dist/client/static/js/{erDiagram-OPXOYQCR-ey3avsn9.js → erDiagram-OPXOYQCR-ndd27fz1.js} +7 -7
  42. package/dist/client/static/js/{erlang-814e8qy5.js → erlang-bh5cbm8m.js} +1 -1
  43. package/dist/client/static/js/eventmodeling-NTZA5JFV-sx2cwkz3.js +1 -0
  44. package/dist/client/static/js/flowDiagram-KWPJA3E3-dsc17mty.js +1 -0
  45. package/dist/client/static/js/{ganttDiagram-FUAMR5RP-a9k1at43.js → ganttDiagram-FUAMR5RP-9gm6hkgn.js} +4 -4
  46. package/dist/client/static/js/gitGraph-4MIJSDKK-yqhbscsd.js +1 -0
  47. package/dist/client/static/js/{gitGraphDiagram-X574FWY7-gnekjfym.js → gitGraphDiagram-X574FWY7-78bxa67c.js} +8 -8
  48. package/dist/client/static/js/graphql-tr0jcndy.js +1 -0
  49. package/dist/client/static/js/html-n8fdvrdk.js +1 -0
  50. package/dist/client/static/js/index-0e51wknc.js +10 -0
  51. package/dist/client/static/js/{index-z25ss7xj.js → index-13g17wa3.js} +1 -1
  52. package/dist/client/static/js/index-1hb8fvw9.js +1 -0
  53. package/dist/client/static/js/{index-1c2jvnyh.js → index-2bsnywea.js} +2 -2
  54. package/dist/client/static/js/{index-g7s0wsag.js → index-2n1fgpjv.js} +2 -2
  55. package/dist/client/static/js/{index-3x7h2eqj.js → index-30a8py59.js} +2 -2
  56. package/dist/client/static/js/{index-qf3y3ahx.js → index-34aq5bz5.js} +2 -2
  57. package/dist/client/static/js/index-3en15m75.js +2 -0
  58. package/dist/client/static/js/{index-nw5mvcaj.js → index-417fbrqk.js} +2 -2
  59. package/dist/client/static/js/{index-z4530r3c.js → index-45p59fxq.js} +2 -2
  60. package/dist/client/static/js/index-4n7t26ap.js +2 -0
  61. package/dist/client/static/js/{index-kty4ncsr.js → index-55pqvh82.js} +2 -2
  62. package/dist/client/static/js/index-5mpv57fn.js +12 -0
  63. package/dist/client/static/js/{index-x9r7zfp4.js → index-7pz6n3pg.js} +2 -2
  64. package/dist/client/static/js/{index-1ax52p0q.js → index-7whstwc7.js} +2 -2
  65. package/dist/client/static/js/index-869vdnz8.js +2 -0
  66. package/dist/client/static/js/{index-fzngzhww.js → index-8tvrzce0.js} +2 -2
  67. package/dist/client/static/js/index-9a78xmkk.js +462 -0
  68. package/dist/client/static/js/{index-33qxg79j.js → index-a58rkn3f.js} +5 -5
  69. package/dist/client/static/js/{index-60v30k5h.js → index-aa3hmn6j.js} +64 -64
  70. package/dist/client/static/js/{index-wrcdc9vz.js → index-aabp7nt6.js} +1 -1
  71. package/dist/client/static/js/{index-64sqfr4a.js → index-abrrqhne.js} +2 -2
  72. package/dist/client/static/js/{index-9vv7wr1n.js → index-ac2q5903.js} +2 -2
  73. package/dist/client/static/js/index-axtm1aq8.js +2 -0
  74. package/dist/client/static/js/index-b2cs4c51.js +4 -0
  75. package/dist/client/static/js/{index-8g7q8mz4.js → index-c250nzm1.js} +3 -3
  76. package/dist/client/static/js/{index-abs635a1.js → index-dxnkwf39.js} +48 -48
  77. package/dist/client/static/js/{index-kbhrvep8.js → index-e6ny4gd9.js} +6 -6
  78. package/dist/client/static/js/index-ebf50mrs.js +9 -0
  79. package/dist/client/static/js/{index-trvqvb1v.js → index-ep6bqcmg.js} +2 -2
  80. package/dist/client/static/js/{index-qfxn7yh5.js → index-fb2s080r.js} +2 -2
  81. package/dist/client/static/js/index-fryp0kgf.js +2 -0
  82. package/dist/client/static/js/{index-2ks0m8ss.js → index-g3rg6vsd.js} +2 -2
  83. package/dist/client/static/js/{index-sa1675y0.js → index-g8rpydkr.js} +2 -2
  84. package/dist/client/static/js/{index-bsr7wmj2.js → index-gkmn4y1v.js} +1 -1
  85. package/dist/client/static/js/{index-xq5f3nxa.js → index-gpmcth0x.js} +2 -2
  86. package/dist/client/static/js/{index-e9cxje00.js → index-hcmhdpp4.js} +10 -10
  87. package/dist/client/static/js/{index-kb14dhrx.js → index-he4k2j91.js} +2 -2
  88. package/dist/client/static/js/{index-wbws16ag.js → index-hq28918s.js} +2 -2
  89. package/dist/client/static/js/{index-84fyq5a6.js → index-hwzxdwwg.js} +1 -1
  90. package/dist/client/static/js/{index-2a6qp9y6.js → index-jnkc9p53.js} +1 -1
  91. package/dist/client/static/js/{index-pavvxrsz.js → index-k39be93q.js} +1 -1
  92. package/dist/client/static/js/{index-c9e417cs.js → index-kaxvwh07.js} +2 -2
  93. package/dist/client/static/js/{index-ykm7a3cp.js → index-kjr68pcj.js} +2 -2
  94. package/dist/client/static/js/{index-b5dfvget.js → index-m0fatq7c.js} +4 -4
  95. package/dist/client/static/js/{index-atq9q1s7.js → index-m39gbcxn.js} +1 -1
  96. package/dist/client/static/js/{index-hnb66d3s.js → index-mqzgf7rw.js} +2 -2
  97. package/dist/client/static/js/{index-5wz0y88c.js → index-pzsp1src.js} +2 -2
  98. package/dist/client/static/js/{index-yf93db65.js → index-qe0vfv6s.js} +1 -1
  99. package/dist/client/static/js/{index-q9ytjey8.js → index-qek9mt5w.js} +1 -1
  100. package/dist/client/static/js/{index-d23eacf2.js → index-qxzj780x.js} +2 -2
  101. package/dist/client/static/js/index-rgxg0azs.css +1 -0
  102. package/dist/client/static/js/{index-m4k054wz.js → index-rq4dk4tp.js} +4 -4
  103. package/dist/client/static/js/{index-fj5rsp5v.js → index-seekt5k3.js} +2 -2
  104. package/dist/client/static/js/{index-561gkvve.js → index-sng4prpr.js} +2 -2
  105. package/dist/client/static/js/{index-vjmg7kn5.js → index-t4s10406.js} +2 -2
  106. package/dist/client/static/js/{index-b2e5pwx7.js → index-tzz5gp8a.js} +5 -5
  107. package/dist/client/static/js/index-vnv9z0a1.js +1 -0
  108. package/dist/client/static/js/{index-19x11s5w.js → index-x7rajphe.js} +2 -2
  109. package/dist/client/static/js/{index-dxvtjn6a.js → index-xny7vsfz.js} +2 -2
  110. package/dist/client/static/js/index-xr4hjv01.js +2 -0
  111. package/dist/client/static/js/{index-65afr75v.js → index-ya9yqj5w.js} +2 -2
  112. package/dist/client/static/js/{index-z0fkfphe.js → index-zcgqacvx.js} +2 -2
  113. package/dist/client/static/js/info-A6RAGUB7-0sd3zzgg.js +1 -0
  114. package/dist/client/static/js/{infoDiagram-VRGFBTTK-r1p25738.js → infoDiagram-VRGFBTTK-bxk0g0pe.js} +2 -2
  115. package/dist/client/static/js/ini-tnaw7zjy.js +1 -0
  116. package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-afgrqdrt.js → ishikawaDiagram-OU5B5YK6-d1kdkhth.js} +3 -3
  117. package/dist/client/static/js/java-m4dpc2vw.js +1 -0
  118. package/dist/client/static/js/javascript-8y26t991.js +1 -0
  119. package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-hepa4wk7.js → journeyDiagram-ZHPQQLJL-cahg3zjq.js} +4 -4
  120. package/dist/client/static/js/json-azm7bdqd.js +1 -0
  121. package/dist/client/static/js/jsx-p9j1k773.js +1 -0
  122. package/dist/client/static/js/{julia-yv2j8qd0.js → julia-2n5k898q.js} +1 -1
  123. package/dist/client/static/js/{kanban-definition-PNTS6WVX-jysft8ya.js → kanban-definition-PNTS6WVX-nq7t83en.js} +6 -6
  124. package/dist/client/static/js/lua-hbm9rhz9.js +1 -0
  125. package/dist/client/static/js/markdown-tk3cd3vs.js +1 -0
  126. package/dist/client/static/js/{mermaid.core-0m90b0s8.js → mermaid.core-6nw0853j.js} +8 -8
  127. package/dist/client/static/js/{mindmap-definition-NLK3R4M7-x2rrzpvr.js → mindmap-definition-NLK3R4M7-cm7ykxf2.js} +3 -3
  128. package/dist/client/static/js/one-dark-pro-2cdc2nk7.js +1 -0
  129. package/dist/client/static/js/one-light-bt6z4jf0.js +1 -0
  130. package/dist/client/static/js/packet-AYTQ26CC-13w2v5bb.js +1 -0
  131. package/dist/client/static/js/{pegDiagram-GJSIUBJH-z7vb7f1z.js → pegDiagram-GJSIUBJH-xwxz8nsq.js} +1 -1
  132. package/dist/client/static/js/{perl-917pjq5a.js → perl-66vb5pz7.js} +1 -1
  133. package/dist/client/static/js/{php-hwz75qzt.js → php-4e9we8am.js} +1 -1
  134. package/dist/client/static/js/pie-WAS4IAKB-swtnysgn.js +1 -0
  135. package/dist/client/static/js/{pieDiagram-5QR66LMP-jqv6v4e6.js → pieDiagram-5QR66LMP-n910k9th.js} +3 -3
  136. package/dist/client/static/js/properties-6911ckw7.js +1 -0
  137. package/dist/client/static/js/python-44cvj250.js +1 -0
  138. package/dist/client/static/js/{quadrantDiagram-O4NWA36T-w2h8yxrv.js → quadrantDiagram-O4NWA36T-dxkwxbqb.js} +6 -6
  139. package/dist/client/static/js/r-t3sepzm4.js +1 -0
  140. package/dist/client/static/js/radar-RG4KPBEZ-vtvxkx55.js +1 -0
  141. package/dist/client/static/js/railroad-74A4TZTK-5sp2d63r.js +1 -0
  142. package/dist/client/static/js/railroad-abnf-HS5TGJTU-kg706fan.js +1 -0
  143. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-4ra1gzx5.js +1 -0
  144. package/dist/client/static/js/railroad-peg-WCYAUIDC-hms3zpjm.js +1 -0
  145. package/dist/client/static/js/{railroadDiagram-XR7U4H2S-nd09yac3.js → railroadDiagram-XR7U4H2S-xb1smt7r.js} +1 -1
  146. package/dist/client/static/js/{requirementDiagram-PLB6GJNP-t61zxh5v.js → requirementDiagram-PLB6GJNP-6kb21b9f.js} +6 -6
  147. package/dist/client/static/js/{ruby-er7ayhte.js → ruby-v7nmcvyr.js} +1 -1
  148. package/dist/client/static/js/{rust-avnkhh0p.js → rust-5ersd7be.js} +1 -1
  149. package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-2f7h2cmw.js → sankeyDiagram-IPEJSGJF-74z0fskw.js} +4 -4
  150. package/dist/client/static/js/{sass-n47tt136.js → sass-h3nvy4c8.js} +1 -1
  151. package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-kfb5d7zd.js → sequenceDiagram-PO4LG4MO-apn6kezn.js} +17 -17
  152. package/dist/client/static/js/{sizeCapture-INFHLROL-amfg19se.js → sizeCapture-INFHLROL-2drzcjb8.js} +1 -1
  153. package/dist/client/static/js/sql-zdkawqx3.js +1 -0
  154. package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-k5hx7btx.js → stateDiagram-v2-GCMORJYK-ma09vhby.js} +3 -3
  155. package/dist/client/static/js/{svelte-2pmz35vx.js → svelte-dhspkgss.js} +1 -1
  156. package/dist/client/static/js/{swimlanes-2SLR337P-wv3rp8kk.js → swimlanes-2SLR337P-f6y9xqnx.js} +1 -1
  157. package/dist/client/static/js/swimlanesDiagram-TC7HE7FX-3dwas56m.js +8 -0
  158. package/dist/client/static/js/{timeline-definition-EJHVYXUP-0re95wtn.js → timeline-definition-EJHVYXUP-zmcmvq00.js} +5 -5
  159. package/dist/client/static/js/treeView-Q6P3EWNA-7t5k6rs2.js +1 -0
  160. package/dist/client/static/js/treemap-WGGIJYW6-w56ry3bg.js +1 -0
  161. package/dist/client/static/js/tsx-b7eabr17.js +1 -0
  162. package/dist/client/static/js/typescript-nnkvhwfy.js +1 -0
  163. package/dist/client/static/js/{usecaseDiagram-POWQR4AR-yrje14qp.js → usecaseDiagram-POWQR4AR-wfaa019a.js} +24 -24
  164. package/dist/client/static/js/{vennDiagram-UO4OBE2U-jxkmrfy5.js → vennDiagram-UO4OBE2U-46wf2pgd.js} +8 -8
  165. package/dist/client/static/js/{vue-d5gpjfgn.js → vue-ffngx2b3.js} +1 -1
  166. package/dist/client/static/js/wardley-WFR3VGLG-rtjb9kgv.js +1 -0
  167. package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-d3v2m9b1.js → wardleyDiagram-VNRHLVJA-10ph3bzq.js} +4 -4
  168. package/dist/client/static/js/xml-xy1tw6b2.js +1 -0
  169. package/dist/client/static/js/{xychartDiagram-PMCCYNJV-9a1s1rjt.js → xychartDiagram-PMCCYNJV-2ba825z9.js} +5 -5
  170. package/dist/client/static/js/yaml-0fexqg2d.js +1 -0
  171. package/marketplace/marketplace.json +34 -7
  172. package/marketplace/plugins/kanban/README.md +143 -0
  173. package/marketplace/plugins/kanban/icon.svg +5 -0
  174. package/marketplace/plugins/kanban/package.json +30 -0
  175. package/marketplace/plugins/kanban/src/app.tsx +34 -0
  176. package/marketplace/plugins/kanban/src/mcp-tools.ts +296 -0
  177. package/marketplace/plugins/kanban/src/mcp.test.ts +199 -0
  178. package/marketplace/plugins/kanban/src/mcp.ts +148 -0
  179. package/marketplace/plugins/kanban/src/panel/CardSheet.tsx +319 -0
  180. package/marketplace/plugins/kanban/src/panel/CardTile.tsx +97 -0
  181. package/marketplace/plugins/kanban/src/panel/StageColumn.tsx +116 -0
  182. package/marketplace/plugins/kanban/src/panel/StageSheet.tsx +249 -0
  183. package/marketplace/plugins/kanban/src/panel/catalogs.ts +114 -0
  184. package/marketplace/plugins/kanban/src/panel/index.tsx +327 -0
  185. package/marketplace/plugins/kanban/src/panel/panel.test.ts +219 -0
  186. package/marketplace/plugins/kanban/src/panel/start-work.ts +132 -0
  187. package/marketplace/plugins/kanban/src/panel/use-board.ts +148 -0
  188. package/marketplace/plugins/kanban/src/panel/use-card-detail.ts +70 -0
  189. package/marketplace/plugins/kanban/src/panel/use-writes.ts +123 -0
  190. package/marketplace/plugins/kanban/src/protocol.ts +180 -0
  191. package/marketplace/plugins/kanban/src/server.test.ts +113 -0
  192. package/marketplace/plugins/kanban/src/server.ts +227 -0
  193. package/marketplace/plugins/kanban/src/store/board.test.ts +311 -0
  194. package/marketplace/plugins/kanban/src/store/board.ts +147 -0
  195. package/marketplace/plugins/kanban/src/store/cards.ts +228 -0
  196. package/marketplace/plugins/kanban/src/store/fs.ts +159 -0
  197. package/marketplace/plugins/kanban/src/store/ops.ts +245 -0
  198. package/marketplace/plugins/kanban/src/store/resolve.test.ts +82 -0
  199. package/marketplace/plugins/kanban/src/store/resolve.ts +135 -0
  200. package/marketplace/plugins/kanban/tsconfig.json +26 -0
  201. package/package.json +2 -2
  202. package/src/client/components/common/file-icon/index.tsx +1 -1
  203. package/src/client/components/layout/desktop-layout/LeftColumn.tsx +12 -3
  204. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +34 -7
  205. package/src/client/components/layout/desktop-layout/index.tsx +17 -22
  206. package/src/client/components/mobile/mobile-right-sidebar/EditorSurface.tsx +2 -0
  207. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +11 -3
  208. package/src/client/components/settings/categories/appearance-settings/EditorThemeSection.test.tsx +21 -0
  209. package/src/client/components/settings/categories/appearance-settings/EditorThemeSection.tsx +8 -4
  210. package/src/client/components/settings/categories/appearance-settings/ThemeCard.tsx +8 -2
  211. package/src/client/components/settings/categories/appearance-settings/ThemeGrid.tsx +15 -4
  212. package/src/client/components/settings/categories/usage-settings/LimitsSection.tsx +10 -3
  213. package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +27 -4
  214. package/src/client/components/settings/categories/usage-settings/TokenHarborCard.tsx +160 -0
  215. package/src/client/components/settings/categories/usage-settings/TokenPortalCard.tsx +104 -0
  216. package/src/client/components/settings/categories/usage-settings/format.ts +35 -0
  217. package/src/client/components/settings/categories/usage-settings/limits-section.test.tsx +16 -0
  218. package/src/client/components/settings/categories/usage-settings/providers.ts +26 -4
  219. package/src/client/components/settings/categories/usage-settings/token-harbor-card.test.tsx +114 -0
  220. package/src/client/components/settings/categories/usage-settings/token-harbor-hint.test.ts +68 -0
  221. package/src/client/components/settings/categories/usage-settings/token-portal-card.test.tsx +81 -0
  222. package/src/client/components/settings/categories/usage-settings/usage-and-picker.test.ts +66 -0
  223. package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.test.ts +21 -0
  224. package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.tsx +7 -1
  225. package/src/client/components/workspace/chat-timeline/chat-input/ThinkingLevelDropdown.tsx +3 -1
  226. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +1 -1
  227. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.test.ts +13 -0
  228. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.tsx +41 -18
  229. package/src/client/components/workspace/editor/BodyLazy.tsx +40 -0
  230. package/src/client/components/workspace/editor/FilePane.tsx +4 -2
  231. package/src/client/components/workspace/editor/Tabs.tsx +7 -1
  232. package/src/client/components/workspace/editor/Toolbar.tsx +7 -1
  233. package/src/client/components/workspace/editor/chrome-rows.test.tsx +126 -0
  234. package/src/client/components/workspace/editor/index.tsx +2 -2
  235. package/src/client/components/workspace/editor/viewers/HtmlPreview.test.tsx +94 -0
  236. package/src/client/components/workspace/editor/viewers/HtmlPreview.tsx +71 -0
  237. package/src/client/components/workspace/editor/viewers/bytes.ts +1 -1
  238. package/src/client/components/workspace/editor/viewers/dispatch.tsx +18 -2
  239. package/src/client/components/workspace/editor/viewers/viewers.test.ts +14 -1
  240. package/src/client/components/workspace/panel-header/index.test.tsx +2 -1
  241. package/src/client/components/workspace/panel-header/index.tsx +6 -4
  242. package/src/client/data/settings/omp-schema.json +33 -10
  243. package/src/client/hooks/editor/resolve-viewer.ts +1 -1
  244. package/src/client/hooks/editor/use-editor-drop.ts +14 -0
  245. package/src/client/hooks/editor/use-editor-tab-state.ts +5 -4
  246. package/src/client/hooks/ui/media-query.ts +27 -0
  247. package/src/client/hooks/workspace/file-tabs.ts +10 -0
  248. package/src/client/hooks/workspace/right-panel-presence.test.ts +152 -0
  249. package/src/client/hooks/workspace/right-panel-presence.ts +119 -0
  250. package/src/client/lib/router/search-params.test.ts +83 -0
  251. package/src/client/lib/router/search-params.ts +14 -3
  252. package/src/server/lib/mcp/session-mcp.test.ts +64 -1
  253. package/src/server/lib/mcp/session-overlay.server.ts +7 -4
  254. package/src/server/lib/omp/rpc/constants.test.ts +31 -0
  255. package/src/server/lib/omp/rpc/constants.ts +19 -0
  256. package/src/server/lib/omp/rpc/session-new.ts +78 -0
  257. package/src/server/lib/omp/rpc/session-registry.ts +22 -49
  258. package/src/server/lib/omp/rpc/spawn-mcp.ts +8 -1
  259. package/src/server/lib/omp/session/blobs.server.ts +2 -1
  260. package/src/server/lib/plugins/e2e.test.ts +71 -2
  261. package/src/server/lib/plugins/loader.server.ts +20 -1
  262. package/src/server/lib/plugins/module-import.server.ts +45 -0
  263. package/src/server/lib/usage/provider-key.ts +18 -0
  264. package/src/server/lib/usage/providers.server.ts +27 -3
  265. package/src/server/lib/usage/report.server.ts +24 -0
  266. package/src/server/lib/usage/token-harbor.test.ts +191 -0
  267. package/src/server/lib/usage/token-harbor.ts +207 -0
  268. package/src/server/lib/usage/token-portal.test.ts +140 -0
  269. package/src/server/lib/usage/token-portal.ts +179 -0
  270. package/src/server/lib/usage/vendor-http.test.ts +52 -0
  271. package/src/server/lib/usage/vendor-http.ts +9 -2
  272. package/src/server/routes/agent/new-prompt.test.ts +81 -0
  273. package/src/server/routes/agent/new.ts +78 -4
  274. package/src/server/routes/fs/raw.test.ts +12 -0
  275. package/src/server/routes/fs/raw.ts +2 -6
  276. package/src/server/routes/wiki/asset.ts +1 -1
  277. package/src/shared/lib/fs/document-kind.test.ts +39 -2
  278. package/src/shared/lib/fs/document-kind.ts +49 -1
  279. package/src/shared/lib/fs/file-kind.test.ts +30 -3
  280. package/src/shared/lib/fs/file-kind.ts +7 -104
  281. package/src/shared/lib/fs/mime.ts +159 -0
  282. package/src/shared/lib/omp/config/schema-releases.test.ts +22 -0
  283. package/src/shared/lib/workspace/sidebar-width.test.ts +34 -0
  284. package/src/shared/lib/workspace/sidebar-width.ts +33 -0
  285. package/src/shared/lib/workspace/workspace-panel-widths.test.ts +124 -0
  286. package/src/shared/lib/workspace/workspace-panel-widths.ts +115 -18
  287. package/src/shared/types/settings/usage.ts +89 -2
  288. package/dist/client/static/js/ImageView-jkrdrq8v.js +0 -1
  289. package/dist/client/static/js/LayoutWrapper-sh634350.js +0 -2
  290. package/dist/client/static/js/architecture-7GRP2DOG-pvb4d65d.js +0 -1
  291. package/dist/client/static/js/bash-8d8z8zrg.js +0 -1
  292. package/dist/client/static/js/c-acmn1zc9.js +0 -1
  293. package/dist/client/static/js/cpp-620mvjkk.js +0 -1
  294. package/dist/client/static/js/css-bt76kxbq.js +0 -1
  295. package/dist/client/static/js/cynefin-OW5HDTMX-gmx4vean.js +0 -1
  296. package/dist/client/static/js/eventmodeling-NTZA5JFV-vrnheyh7.js +0 -1
  297. package/dist/client/static/js/flowDiagram-KWPJA3E3-7gvtpn3d.js +0 -1
  298. package/dist/client/static/js/gitGraph-4MIJSDKK-n6wnc8st.js +0 -1
  299. package/dist/client/static/js/graphql-j1a6zp7m.js +0 -1
  300. package/dist/client/static/js/html-m0megrvb.js +0 -1
  301. package/dist/client/static/js/index-4cag7w6k.js +0 -479
  302. package/dist/client/static/js/index-5ka2tyf9.js +0 -3
  303. package/dist/client/static/js/index-83rkg916.js +0 -2
  304. package/dist/client/static/js/index-amsa0tfs.js +0 -2
  305. package/dist/client/static/js/index-dn7hg4em.js +0 -2
  306. package/dist/client/static/js/index-dpy3ewrn.css +0 -1
  307. package/dist/client/static/js/index-dt6q3rws.js +0 -12
  308. package/dist/client/static/js/index-hgzntg2j.js +0 -2
  309. package/dist/client/static/js/index-vkqb4dnt.js +0 -1
  310. package/dist/client/static/js/index-xwjbq003.js +0 -2
  311. package/dist/client/static/js/info-A6RAGUB7-1xtdxjz2.js +0 -1
  312. package/dist/client/static/js/ini-5f4zqtqr.js +0 -1
  313. package/dist/client/static/js/java-jj41mty3.js +0 -1
  314. package/dist/client/static/js/javascript-n9w9p97f.js +0 -1
  315. package/dist/client/static/js/json-rnh2h17x.js +0 -1
  316. package/dist/client/static/js/jsx-4gecrt29.js +0 -1
  317. package/dist/client/static/js/lua-zszaw2f7.js +0 -1
  318. package/dist/client/static/js/markdown-nm6gw4v4.js +0 -1
  319. package/dist/client/static/js/one-dark-pro-09d8p5vy.js +0 -1
  320. package/dist/client/static/js/one-light-g3ednt6p.js +0 -1
  321. package/dist/client/static/js/packet-AYTQ26CC-zm1r82x5.js +0 -1
  322. package/dist/client/static/js/pie-WAS4IAKB-sqa7321j.js +0 -1
  323. package/dist/client/static/js/properties-rkptax7r.js +0 -1
  324. package/dist/client/static/js/python-qf1se1mj.js +0 -1
  325. package/dist/client/static/js/r-ms0cygq2.js +0 -1
  326. package/dist/client/static/js/radar-RG4KPBEZ-z3z82syp.js +0 -1
  327. package/dist/client/static/js/railroad-74A4TZTK-z6swcqq2.js +0 -1
  328. package/dist/client/static/js/railroad-abnf-HS5TGJTU-33km6py4.js +0 -1
  329. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-1zbf1xmq.js +0 -1
  330. package/dist/client/static/js/railroad-peg-WCYAUIDC-wte1xzzy.js +0 -1
  331. package/dist/client/static/js/sql-hd42h8wx.js +0 -1
  332. package/dist/client/static/js/swimlanesDiagram-TC7HE7FX-6y8zdbm4.js +0 -8
  333. package/dist/client/static/js/treeView-Q6P3EWNA-pvgx6n22.js +0 -1
  334. package/dist/client/static/js/treemap-WGGIJYW6-3n9zm628.js +0 -1
  335. package/dist/client/static/js/tsx-gx7td06z.js +0 -1
  336. package/dist/client/static/js/typescript-1a808spn.js +0 -1
  337. package/dist/client/static/js/wardley-WFR3VGLG-7m07ewc4.js +0 -1
  338. package/dist/client/static/js/xml-3117mxd9.js +0 -1
  339. package/dist/client/static/js/yaml-dmvh8vyt.js +0 -1
@@ -0,0 +1,228 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * One card file: parse it, summarise it, write it back without losing fields.
8
+ *
9
+ * Split from `board.ts` because the two halves have different failure modes. A
10
+ * board is a single document with stages; a card is a row that ANOTHER PROCESS
11
+ * (the MCP child, or an agent with a text editor) also writes. So this file owns
12
+ * the concurrency token (`updatedAt`, bumped strictly forward), the write lock,
13
+ * and the rule that an unknown field survives.
14
+ */
15
+
16
+ import fs from 'fs';
17
+ import path from 'path';
18
+
19
+ import {
20
+ CARD_ID,
21
+ MAX_IMAGES,
22
+ MAX_IMAGE_BYTES,
23
+ MAX_PROMPT_CHARS,
24
+ STAGE_ID,
25
+ type BoardError,
26
+ type Card,
27
+ type CardSummary,
28
+ } from '../protocol';
29
+ import {
30
+ KanbanError,
31
+ cardFile,
32
+ cardsDir,
33
+ exists,
34
+ messageOf,
35
+ readJson,
36
+ withWriteLock,
37
+ writeJsonAtomic,
38
+ } from './fs';
39
+ import { asRecord, asString } from './board';
40
+
41
+ /** Every card file, as a summary, plus the files that could not be read. */
42
+ export async function listCards(dataDir: string): Promise<{ cards: CardSummary[]; errors: BoardError[] }> {
43
+ const dir = cardsDir(dataDir);
44
+ let names: string[];
45
+ try {
46
+ names = await fs.promises.readdir(dir);
47
+ } catch (cause) {
48
+ if ((cause as NodeJS.ErrnoException).code === 'ENOENT') return { cards: [], errors: [] };
49
+ throw new KanbanError('io', `Could not list ${dir}: ${messageOf(cause)}`);
50
+ }
51
+ const cards: CardSummary[] = [];
52
+ const errors: BoardError[] = [];
53
+ for (const name of names.filter((entry) => entry.endsWith('.json') && !entry.startsWith('.')).sort()) {
54
+ const file = path.join(dir, name);
55
+ try {
56
+ const card = parseCard(await readJson(file), name.slice(0, -'.json'.length));
57
+ cards.push(summarize(card));
58
+ } catch (cause) {
59
+ // A file an agent broke is REPORTED with its path, never skipped: a board
60
+ // that silently drops a card is worse than one that says which is bad.
61
+ //
62
+ // Board-relative, with a forward slash on EVERY platform: this string is
63
+ // read by a person and by an agent (`cards/<id>.json` is what the board's
64
+ // README names), so `path.join` — which answers `cards\k-abcdef.json` on
65
+ // Windows — would make the sentence depend on the host it was written on.
66
+ errors.push({ path: `cards/${name}`, message: messageOf(cause) });
67
+ }
68
+ }
69
+ return { cards, errors };
70
+ }
71
+
72
+ /** The card without its prose, which is all a board view draws. */
73
+ export function summarize(card: Card): CardSummary {
74
+ const { task, ...rest } = card;
75
+ return { ...rest, hasPrompt: task.prompt.length > 0, imageCount: task.images.length };
76
+ }
77
+
78
+ /** Validate one parsed card file. Throws with the sentence the panel shows. */
79
+ export function parseCard(raw: unknown, idFromName: string): Card {
80
+ const record = asRecord(raw);
81
+ const id = asString(record.id) || idFromName;
82
+ if (!CARD_ID.test(id)) throw new KanbanError('invalid', `Card id "${id}" is not a k-xxxxxx id.`);
83
+ const task = asRecord(record.task);
84
+ const images = Array.isArray(task.images)
85
+ ? task.images.filter((entry): entry is { name: string; mimeType: string; dataBase64: string } => {
86
+ const image = asRecord(entry);
87
+ return typeof image.dataBase64 === 'string';
88
+ }).map((entry) => ({
89
+ name: asString(asRecord(entry).name) || 'image',
90
+ mimeType: asString(asRecord(entry).mimeType) || 'image/png',
91
+ dataBase64: asString(asRecord(entry).dataBase64),
92
+ }))
93
+ : [];
94
+ return {
95
+ schema: 2,
96
+ id,
97
+ title: asString(record.title) || '(untitled)',
98
+ status: asString(record.status) || 'open',
99
+ priority: typeof record.priority === 'number' ? record.priority : 2,
100
+ workspace: typeof record.workspace === 'string' && record.workspace ? record.workspace : null,
101
+ task: {
102
+ prompt: asString(task.prompt),
103
+ images,
104
+ ...(task.agent !== undefined ? { agent: asRecord(task.agent) as Card['task']['agent'] } : {}),
105
+ },
106
+ sessionId: asString(record.sessionId) || null,
107
+ createdAt: asString(record.createdAt) || new Date().toISOString(),
108
+ updatedAt: asString(record.updatedAt) || new Date().toISOString(),
109
+ movedAt: asString(record.movedAt) || null,
110
+ };
111
+ }
112
+
113
+ /** One card, with the raw record so a write can preserve unknown fields. */
114
+ export async function readCard(dataDir: string, id: string): Promise<{ card: Card; raw: Record<string, unknown> }> {
115
+ if (!CARD_ID.test(id)) throw new KanbanError('invalid', `"${id}" is not a card id.`);
116
+ const file = cardFile(dataDir, id);
117
+ const parsed = await readJson(file).catch((cause: unknown) => {
118
+ throw new KanbanError('io', `Could not read ${file}: ${messageOf(cause)}`);
119
+ });
120
+ if (parsed === null) throw new KanbanError('not_found', `No card "${id}".`);
121
+ return { card: parseCard(parsed, id), raw: asRecord(parsed) };
122
+ }
123
+
124
+ /**
125
+ * A stamp strictly after `previous`.
126
+ *
127
+ * Two writes can land inside one millisecond, and `baseUpdatedAt` compares
128
+ * strings — so an unchanged `updatedAt` would let the second write through as if
129
+ * the first never happened. Bumping by a millisecond keeps the field a usable
130
+ * concurrency token without a separate counter.
131
+ */
132
+ function nextStamp(previous: string): string {
133
+ const now = Date.now();
134
+ const last = Date.parse(previous);
135
+ return new Date(Number.isFinite(last) && last >= now ? last + 1 : now).toISOString();
136
+ }
137
+
138
+ /** Write one card, preserving every field the caller did not touch. */
139
+ export async function writeCard(dataDir: string, card: Card, raw: Record<string, unknown>): Promise<Card> {
140
+ validateCard(card);
141
+ const next: Card = { ...card, updatedAt: nextStamp(card.updatedAt) };
142
+ await writeJsonAtomic(cardFile(dataDir, next.id), { ...raw, ...next, task: next.task });
143
+ return next;
144
+ }
145
+
146
+ /** The rules a write must satisfy, each refused by name. */
147
+ export function validateCard(card: Card): void {
148
+ if (!CARD_ID.test(card.id)) throw new KanbanError('invalid', `"${card.id}" is not a card id.`);
149
+ if (!card.title.trim()) throw new KanbanError('invalid', 'A card needs a title.');
150
+ if (!STAGE_ID.test(card.status)) throw new KanbanError('invalid', `"${card.status}" is not a stage id.`);
151
+ if (!Number.isInteger(card.priority) || card.priority < 0 || card.priority > 4) {
152
+ throw new KanbanError('invalid', 'Priority is 0..4 (P0 urgent … P4 backlog).');
153
+ }
154
+ if (card.task.prompt.length > MAX_PROMPT_CHARS) {
155
+ throw new KanbanError('invalid', `A prompt is limited to ${MAX_PROMPT_CHARS} characters.`);
156
+ }
157
+ if (card.task.images.length > MAX_IMAGES) {
158
+ throw new KanbanError('invalid', `A card holds at most ${MAX_IMAGES} images.`);
159
+ }
160
+ const bytes = card.task.images.reduce((sum, image) => sum + image.dataBase64.length, 0);
161
+ if (bytes > MAX_IMAGE_BYTES * 1.4) {
162
+ // base64 is ~1.37x the decoded size; the cap is stated in decoded bytes.
163
+ throw new KanbanError('invalid', 'A card’s images exceed 2 MB.');
164
+ }
165
+ }
166
+
167
+ /** A card id nobody holds, checked against the directory. */
168
+ async function freshId(dataDir: string): Promise<string> {
169
+ for (let attempt = 0; attempt < 32; attempt += 1) {
170
+ const id = `k-${Bun.randomUUIDv7().replace(/-/g, '').slice(-6)}`;
171
+ if (!(await exists(cardFile(dataDir, id)))) return id;
172
+ }
173
+ throw new KanbanError('io', 'Could not allocate a card id.');
174
+ }
175
+
176
+ /** Create one card. The caller supplies everything but the id and the stamps. */
177
+ export async function createCard(
178
+ dataDir: string,
179
+ input: { title: string; status?: string; workspace?: string | null; task?: Partial<Card['task']>; priority?: number },
180
+ ): Promise<Card> {
181
+ return withWriteLock(dataDir, async () => {
182
+ const now = new Date().toISOString();
183
+ const card: Card = {
184
+ schema: 2,
185
+ id: await freshId(dataDir),
186
+ title: input.title,
187
+ status: input.status ?? 'open',
188
+ priority: input.priority ?? 2,
189
+ workspace: input.workspace ?? null,
190
+ task: { prompt: input.task?.prompt ?? '', images: input.task?.images ?? [], ...(input.task?.agent ? { agent: input.task.agent } : {}) },
191
+ sessionId: null,
192
+ createdAt: now,
193
+ updatedAt: now,
194
+ movedAt: null,
195
+ };
196
+ validateCard(card);
197
+ await writeJsonAtomic(cardFile(dataDir, card.id), card);
198
+ return card;
199
+ });
200
+ }
201
+
202
+ /** Delete one card file. */
203
+ export async function deleteCard(dataDir: string, id: string): Promise<void> {
204
+ if (!CARD_ID.test(id)) throw new KanbanError('invalid', `"${id}" is not a card id.`);
205
+ await withWriteLock(dataDir, async () => {
206
+ try {
207
+ await fs.promises.rm(cardFile(dataDir, id));
208
+ } catch (cause) {
209
+ throw new KanbanError('not_found', `No card "${id}" (${messageOf(cause)}).`);
210
+ }
211
+ });
212
+ }
213
+
214
+ /** Apply a change under the lock, re-reading first so an agent's edit is not lost. */
215
+ export async function mutateCard(
216
+ dataDir: string,
217
+ id: string,
218
+ change: (card: Card, raw: Record<string, unknown>) => Card | Promise<Card>,
219
+ options: { baseUpdatedAt?: string } = {},
220
+ ): Promise<Card> {
221
+ return withWriteLock(dataDir, async () => {
222
+ const { card, raw } = await readCard(dataDir, id);
223
+ if (options.baseUpdatedAt && options.baseUpdatedAt !== card.updatedAt) {
224
+ throw new KanbanError('stale', 'This card changed on disk — reload it before saving.');
225
+ }
226
+ return writeCard(dataDir, await change(card, raw), raw);
227
+ });
228
+ }
@@ -0,0 +1,159 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The board's files, and the two primitives every write goes through.
8
+ *
9
+ * The board lives OUTSIDE every checkout (`<dataDir>/kanban`), because it is one
10
+ * queue for the person rather than an artifact of a repository: a per-repo board
11
+ * dies with its clone, and "what am I working on" then needs a tool to answer.
12
+ *
13
+ * Two writers exist — Kabmo's process (the panel's RPC) and the MCP child (a
14
+ * separate Bun process an agent talks to). `rename` keeps a reader from seeing a
15
+ * torn file but does not stop a lost update, so every read-modify-write takes
16
+ * `cards/.write.lock`. That is the whole concurrency story and it is deliberate:
17
+ * a database would be a second store, and the point of files is that an agent
18
+ * with nothing but its file tools can read them.
19
+ */
20
+
21
+ import fs from 'fs';
22
+ import path from 'path';
23
+
24
+ import type { KanbanErrorCode } from '../protocol';
25
+
26
+ /** A refusal the panel and the MCP tools both surface verbatim. */
27
+ export class KanbanError extends Error {
28
+ readonly code: KanbanErrorCode;
29
+
30
+ constructor(code: KanbanErrorCode, message: string) {
31
+ super(message);
32
+ this.code = code;
33
+ this.name = 'KanbanError';
34
+ }
35
+ }
36
+
37
+ /** The board root for a host data dir. */
38
+ export function boardDir(dataDir: string): string {
39
+ return path.join(dataDir, 'kanban');
40
+ }
41
+
42
+ export function cardsDir(dataDir: string): string {
43
+ return path.join(boardDir(dataDir), 'cards');
44
+ }
45
+
46
+ export function boardFile(dataDir: string): string {
47
+ return path.join(boardDir(dataDir), 'board.json');
48
+ }
49
+
50
+ /** Whether a board exists, without parsing it. */
51
+ export async function hasBoard(dataDir: string): Promise<boolean> {
52
+ return exists(boardFile(dataDir));
53
+ }
54
+
55
+ export function cardFile(dataDir: string, id: string): string {
56
+ return path.join(cardsDir(dataDir), `${id}.json`);
57
+ }
58
+
59
+ /** `<dir>/.write.lock` — held across one read-modify-write. */
60
+ function lockFile(dataDir: string): string {
61
+ return path.join(cardsDir(dataDir), '.write.lock');
62
+ }
63
+
64
+ const LOCK_ATTEMPTS = 20;
65
+ const LOCK_RETRY_MS = 5;
66
+ const LOCK_STALE_MS = 5_000;
67
+
68
+ function sleep(ms: number): Promise<void> {
69
+ const { promise, resolve } = Promise.withResolvers<void>();
70
+ setTimeout(resolve, ms);
71
+ return promise;
72
+ }
73
+
74
+ /**
75
+ * Run `work` while holding the board's write lock.
76
+ *
77
+ * A lock left behind by a process that died is taken over after
78
+ * `LOCK_STALE_MS`; without that, one crash would freeze every future write.
79
+ */
80
+ export async function withWriteLock<T>(dataDir: string, work: () => Promise<T>): Promise<T> {
81
+ await fs.promises.mkdir(cardsDir(dataDir), { recursive: true });
82
+ const file = lockFile(dataDir);
83
+ let handle: fs.promises.FileHandle | null = null;
84
+ for (let attempt = 0; attempt < LOCK_ATTEMPTS && !handle; attempt += 1) {
85
+ try {
86
+ handle = await fs.promises.open(file, 'wx');
87
+ } catch (cause) {
88
+ if ((cause as NodeJS.ErrnoException).code !== 'EEXIST') throw cause;
89
+ const age = await lockAge(file);
90
+ if (age !== null && age > LOCK_STALE_MS) {
91
+ await fs.promises.rm(file, { force: true });
92
+ continue;
93
+ }
94
+ await sleep(LOCK_RETRY_MS);
95
+ }
96
+ }
97
+ if (!handle) {
98
+ throw new KanbanError('io', 'The board is busy: another writer holds cards/.write.lock.');
99
+ }
100
+ try {
101
+ return await work();
102
+ } finally {
103
+ await handle.close().catch(() => undefined);
104
+ await fs.promises.rm(file, { force: true }).catch(() => undefined);
105
+ }
106
+ }
107
+
108
+ async function lockAge(file: string): Promise<number | null> {
109
+ try {
110
+ const stat = await fs.promises.stat(file);
111
+ return Date.now() - stat.mtimeMs;
112
+ } catch {
113
+ return null;
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Write JSON through a sibling temp file and a rename.
119
+ *
120
+ * Same directory, so the rename cannot cross a mount and is atomic; the temp
121
+ * name is unique per write so two writers cannot clobber each other's file even
122
+ * if the lock is somehow skipped.
123
+ */
124
+ export async function writeJsonAtomic(file: string, value: unknown): Promise<void> {
125
+ const dir = path.dirname(file);
126
+ await fs.promises.mkdir(dir, { recursive: true });
127
+ const temp = path.join(dir, `.${path.basename(file)}.${process.pid}.${Date.now()}.tmp`);
128
+ await fs.promises.writeFile(temp, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
129
+ try {
130
+ await fs.promises.rename(temp, file);
131
+ } catch (cause) {
132
+ await fs.promises.rm(temp, { force: true }).catch(() => undefined);
133
+ throw new KanbanError('io', `Could not write ${file}: ${messageOf(cause)}`);
134
+ }
135
+ }
136
+
137
+ export function messageOf(cause: unknown): string {
138
+ return cause instanceof Error ? cause.message : String(cause);
139
+ }
140
+
141
+ /** Read and parse one JSON file, or null when it does not exist. */
142
+ export async function readJson(file: string): Promise<unknown | null> {
143
+ try {
144
+ return JSON.parse(await fs.promises.readFile(file, 'utf8')) as unknown;
145
+ } catch (cause) {
146
+ if ((cause as NodeJS.ErrnoException).code === 'ENOENT') return null;
147
+ throw cause;
148
+ }
149
+ }
150
+
151
+ /** Whether a path exists (a directory or a file). */
152
+ export async function exists(file: string): Promise<boolean> {
153
+ try {
154
+ await fs.promises.stat(file);
155
+ return true;
156
+ } catch {
157
+ return false;
158
+ }
159
+ }
@@ -0,0 +1,245 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The board's operations, shared by the panel's RPC and the MCP child.
8
+ *
9
+ * Every one of them is the same three steps — read the board, read the card,
10
+ * write the card under the lock — because the two writers must not each invent
11
+ * their own. `move` is the one an agent uses most, and it carries the rule the
12
+ * whole design turns on: a move into a stage that RUNS a session does not start
13
+ * one. It answers `next: "start_work_required"` and the panel offers the button,
14
+ * because a spawn nobody asked for is worse than one click.
15
+ */
16
+
17
+ import fs from 'fs';
18
+ import path from 'path';
19
+
20
+ import {
21
+ STAGE_ID,
22
+ START_STAGE,
23
+ type Board,
24
+ type BoardRead,
25
+ type BoardSnapshot,
26
+ type Card,
27
+ type CardSummary,
28
+ type CardDetail,
29
+ type Stage,
30
+ } from '../protocol';
31
+ import { KanbanError, boardDir, hasBoard, boardFile, withWriteLock, writeJsonAtomic } from './fs';
32
+ import { initBoard, readBoard, stageOf } from './board';
33
+ import { createCard, deleteCard, listCards, mutateCard, readCard, validateCard } from './cards';
34
+
35
+ /** What a move answers. */
36
+ export interface MoveResult {
37
+ card: Card;
38
+ /** Set when the target stage runs a session and the card has none. */
39
+ next?: 'start_work_required';
40
+ }
41
+
42
+ /** The whole board, slim. A missing board is a `no_board` refusal, not an empty one. */
43
+ export async function snapshot(dataDir: string): Promise<BoardSnapshot> {
44
+ const board = await readBoard(dataDir);
45
+ const { cards, errors } = await listCards(dataDir);
46
+ // The revision is a CONTENT stamp, not a counter: two readers (a panel and a
47
+ // second tab) must agree on it without talking to each other, and a watcher
48
+ // event can then be compared against what the caller already has.
49
+ const revision = await contentRevision(dataDir, cards);
50
+ return { dataDir: boardDir(dataDir), revision, board, cards, errors };
51
+ }
52
+
53
+ /**
54
+ * A cheap stamp over the card files' size + mtime.
55
+ *
56
+ * Reading every card to hash it would cost the same as the read the caller is
57
+ * about to do; `stat` per file is what a watcher can afford on every tick.
58
+ */
59
+ async function contentRevision(dataDir: string, cards: readonly CardSummary[]): Promise<number> {
60
+ let stamp = 0;
61
+ for (const card of cards) {
62
+ try {
63
+ const stat = await fs.promises.stat(path.join(boardDir(dataDir), 'cards', `${card.id}.json`));
64
+ stamp = (stamp * 31 + Math.round(stat.mtimeMs) + stat.size) % Number.MAX_SAFE_INTEGER;
65
+ } catch {
66
+ // A card that vanished mid-walk is the watcher's business, not the read's.
67
+ }
68
+ }
69
+ return stamp;
70
+ }
71
+
72
+ /**
73
+ * The board, or the fact that it does not exist yet.
74
+ *
75
+ * `snapshot` throws `no_board` for callers that require a board (a move cannot
76
+ * invent one); this is the read the PANEL makes, where absence is a screen.
77
+ */
78
+ export async function readBoardState(dataDir: string): Promise<BoardRead> {
79
+ if (!(await hasBoard(dataDir))) return { exists: false, dataDir: boardDir(dataDir) };
80
+ return { exists: true, ...(await snapshot(dataDir)) };
81
+ }
82
+
83
+ /** Create a board, then answer it. */
84
+ export async function createBoard(dataDir: string): Promise<BoardSnapshot> {
85
+ if (!(await hasBoard(dataDir))) await initBoard(dataDir);
86
+ return snapshot(dataDir);
87
+ }
88
+
89
+ /** One card with its stage, for the sheet. */
90
+ export async function cardDetail(dataDir: string, id: string): Promise<CardDetail> {
91
+ const board = await readBoard(dataDir);
92
+ const { card } = await readCard(dataDir, id);
93
+ return { card, board };
94
+ }
95
+
96
+ /** Add a card. The workspace stamp is the caller's, never the server's cwd. */
97
+ export async function addCard(
98
+ dataDir: string,
99
+ input: { title: string; status?: string; workspace?: string | null; priority?: number; task?: Partial<Card['task']> },
100
+ ): Promise<Card> {
101
+ const board = await readBoard(dataDir);
102
+ const status = input.status ?? 'open';
103
+ if (!stageOf(board, status)) {
104
+ throw new KanbanError('invalid', `Stage "${status}" does not exist.`);
105
+ }
106
+ return createCard(dataDir, { ...input, status });
107
+ }
108
+
109
+ /** Move a card between stages. */
110
+ export async function moveCard(
111
+ dataDir: string,
112
+ id: string,
113
+ status: string,
114
+ baseUpdatedAt?: string,
115
+ ): Promise<MoveResult> {
116
+ const board = await readBoard(dataDir);
117
+ const stage = stageOf(board, status);
118
+ if (!stage) throw new KanbanError('invalid', `Stage "${status}" does not exist.`);
119
+ const card = await mutateCard(
120
+ dataDir,
121
+ id,
122
+ (current) => ({ ...current, status, movedAt: new Date().toISOString() }),
123
+ { baseUpdatedAt },
124
+ );
125
+ return stage.session && !card.sessionId ? { card, next: 'start_work_required' } : { card };
126
+ }
127
+
128
+ /** Change the fields the board owns. A field absent from the patch is untouched. */
129
+ export async function updateCard(
130
+ dataDir: string,
131
+ id: string,
132
+ patch: { title?: string; priority?: number; workspace?: string | null; task?: Partial<Card['task']> },
133
+ baseUpdatedAt?: string,
134
+ ): Promise<Card> {
135
+ return mutateCard(
136
+ dataDir,
137
+ id,
138
+ (current) => {
139
+ const next: Card = {
140
+ ...current,
141
+ ...(patch.title !== undefined ? { title: patch.title } : {}),
142
+ ...(patch.priority !== undefined ? { priority: patch.priority } : {}),
143
+ ...(patch.workspace !== undefined ? { workspace: patch.workspace } : {}),
144
+ ...(patch.task
145
+ ? {
146
+ task: {
147
+ ...current.task,
148
+ ...patch.task,
149
+ images: patch.task.images ?? current.task.images,
150
+ },
151
+ }
152
+ : {}),
153
+ };
154
+ validateCard(next);
155
+ return next;
156
+ },
157
+ { baseUpdatedAt },
158
+ );
159
+ }
160
+
161
+ /** Link a session, or unlink it. */
162
+ export async function linkSession(dataDir: string, id: string, sessionId: string | null): Promise<Card> {
163
+ return mutateCard(dataDir, id, (current) => ({ ...current, sessionId }));
164
+ }
165
+
166
+ /**
167
+ * Claim a card for a session: record it and land in the working stage.
168
+ *
169
+ * One write, so a claim cannot half-apply — a card that says In Progress with no
170
+ * session is exactly the state the pill would then have to apologise for.
171
+ */
172
+ export async function claimCard(dataDir: string, id: string, sessionId?: string): Promise<Card> {
173
+ const board = await readBoard(dataDir);
174
+ const start = stageOf(board, START_STAGE) ?? board.stages.find((stage) => stage.session);
175
+ return mutateCard(dataDir, id, (current) => ({
176
+ ...current,
177
+ ...(sessionId ? { sessionId } : {}),
178
+ ...(start ? { status: start.id, movedAt: new Date().toISOString() } : {}),
179
+ }));
180
+ }
181
+
182
+ /** Remove a card. */
183
+ export async function removeCard(dataDir: string, id: string): Promise<void> {
184
+ await deleteCard(dataDir, id);
185
+ }
186
+
187
+ /** Replace the stage list. Refuses a duplicate or an unreachable id. */
188
+ export async function saveStages(
189
+ dataDir: string,
190
+ stages: Board['stages'],
191
+ ): Promise<BoardSnapshot> {
192
+ const board = await readBoard(dataDir);
193
+ const seen = new Set<string>();
194
+ for (const stage of stages) {
195
+ // The id becomes a value in every card file and a lane key in the panel, so
196
+ // it is validated as an identifier rather than as display text.
197
+ if (!STAGE_ID.test(stage.id)) {
198
+ throw new KanbanError('invalid', `"${stage.id}" is not a stage id (lowercase, underscores, 32 max).`);
199
+ }
200
+ if (seen.has(stage.id)) throw new KanbanError('invalid', `Stage "${stage.id}" is listed twice.`);
201
+ seen.add(stage.id);
202
+ if (!stage.label.trim()) throw new KanbanError('invalid', `Stage "${stage.id}" needs a label.`);
203
+ }
204
+ await withWriteLock(dataDir, async () => {
205
+ await writeJsonAtomic(boardFile(dataDir), { ...board, stages, updatedAt: new Date().toISOString() });
206
+ });
207
+ return snapshot(dataDir);
208
+ }
209
+
210
+ /** Replace the board's defaults. */
211
+ export async function saveDefaults(dataDir: string, defaults: Board['defaults']): Promise<BoardSnapshot> {
212
+ const board = await readBoard(dataDir);
213
+ await withWriteLock(dataDir, async () => {
214
+ await writeJsonAtomic(boardFile(dataDir), { ...board, defaults, updatedAt: new Date().toISOString() });
215
+ });
216
+ return snapshot(dataDir);
217
+ }
218
+
219
+ /**
220
+ * The stage that ends the board: the LAST one that does not run a session.
221
+ *
222
+ * Not the literal id `done`: a board may rename it or add a lane after it, and a
223
+ * next-card query that hard-coded the id would keep offering finished work from
224
+ * a stage nobody named `done`.
225
+ */
226
+ export function terminalStageId(board: { stages: readonly Stage[] }): string {
227
+ const terminal = [...board.stages].reverse().find((stage) => !stage.session);
228
+ return terminal?.id ?? 'done';
229
+ }
230
+
231
+ /** The highest-priority card that is not done and has no live session. */
232
+ export async function nextCard(dataDir: string, workspace?: string | null): Promise<Card | null> {
233
+ const board = await readBoard(dataDir);
234
+ const { cards } = await listCards(dataDir);
235
+ const done = new Set([terminalStageId(board)]);
236
+ const candidates = cards
237
+ .filter((card) => !done.has(card.status))
238
+ .filter((card) => workspace === undefined || card.workspace === workspace)
239
+ .sort((left, right) => left.priority - right.priority || right.updatedAt.localeCompare(left.updatedAt));
240
+ const first = candidates[0];
241
+ if (!first) return null;
242
+ const { card } = await readCard(dataDir, first.id);
243
+ return card;
244
+ }
245
+