@kabmo-labs/kabmo 0.37.0 → 0.38.1

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 (261) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +551 -531
  3. package/dist/client/static/js/{CsvGrid-xb429wvb.js → CsvGrid-t1n057vw.js} +1 -1
  4. package/dist/client/static/js/{DocxView-g58e0bs7.js → DocxView-c9g6teks.js} +2 -2
  5. package/dist/client/static/js/{DrawioView-1j66avvy.js → DrawioView-gd14j54m.js} +1 -1
  6. package/dist/client/static/js/{ImageView-kraqkypn.js → ImageView-57f1ecdp.js} +1 -1
  7. package/dist/client/static/js/{LayoutWrapper-85dhbn62.js → LayoutWrapper-x7srbpz1.js} +2 -2
  8. package/dist/client/static/js/{Modal-f0nfya07.js → Modal-0bn3f77b.js} +15 -15
  9. package/dist/client/static/js/{PdfView-nddkrky9.js → PdfView-cybz0xbj.js} +1 -1
  10. package/dist/client/static/js/{SessionsView-a595m6g1.js → SessionsView-gx5q68tp.js} +1 -1
  11. package/dist/client/static/js/{SheetView-s2p4sk6b.js → SheetView-1kk5y326.js} +1 -1
  12. package/dist/client/static/js/{SvgPreview-ppdx4yb9.js → SvgPreview-mp4tk37p.js} +1 -1
  13. package/dist/client/static/js/{abnfDiagram-O67JEVCF-5cjzxcaq.js → abnfDiagram-O67JEVCF-78qb3can.js} +1 -1
  14. package/dist/client/static/js/architecture-7GRP2DOG-r8sz34h3.js +1 -0
  15. package/dist/client/static/js/{architectureDiagram-NJMV4G6O-62mygavm.js → architectureDiagram-NJMV4G6O-n0fr4hb6.js} +2 -2
  16. package/dist/client/static/js/{astro-80bs6hvg.js → astro-p3f5p9p2.js} +1 -1
  17. package/dist/client/static/js/{blockDiagram-BEXU5L5S-s5yz9hcd.js → blockDiagram-BEXU5L5S-2xemfrzh.js} +6 -6
  18. package/dist/client/static/js/c-jkdstn33.js +1 -0
  19. package/dist/client/static/js/{c4Diagram-YGBWAQC7-rf9xkmrm.js → c4Diagram-YGBWAQC7-zxfdx3eb.js} +2 -2
  20. package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-zfm2cj2a.js → classDiagram-v2-NBCMYWYE-z9sasy3k.js} +5 -5
  21. package/dist/client/static/js/{cose-bilkent-JH36ORCC-fmgpv55e.js → cose-bilkent-JH36ORCC-9byp0czh.js} +1 -1
  22. package/dist/client/static/js/cpp-9d3xdpe3.js +1 -0
  23. package/dist/client/static/js/css-r3wja1ze.js +1 -0
  24. package/dist/client/static/js/css-sebxkh5f.js +1 -0
  25. package/dist/client/static/js/cynefin-OW5HDTMX-w2f2vev7.js +1 -0
  26. package/dist/client/static/js/{cynefinDiagram-VND7K2PF-468r5xc2.js → cynefinDiagram-VND7K2PF-gnm129fx.js} +1 -1
  27. package/dist/client/static/js/{dagre-6A5THRUB-w370qmgj.js → dagre-6A5THRUB-sc5tfv1w.js} +2 -2
  28. package/dist/client/static/js/{diagram-22UHCM2B-sfvfjjsy.js → diagram-22UHCM2B-hq11eek7.js} +7 -7
  29. package/dist/client/static/js/{diagram-3UASUU5V-3r2c8s14.js → diagram-3UASUU5V-7bk532gd.js} +2 -2
  30. package/dist/client/static/js/{diagram-ATOU4E4O-yathy97a.js → diagram-ATOU4E4O-yt8wxttm.js} +2 -2
  31. package/dist/client/static/js/{diagram-CDSNMT55-kk437kxq.js → diagram-CDSNMT55-n3978w6p.js} +1 -1
  32. package/dist/client/static/js/{diagram-MLGK6HIB-qdxfjjhf.js → diagram-MLGK6HIB-004x4gyw.js} +1 -1
  33. package/dist/client/static/js/{diagram-MPIPVDR6-dfqeqa1d.js → diagram-MPIPVDR6-498nt489.js} +1 -1
  34. package/dist/client/static/js/{dockerfile-yxrt509r.js → dockerfile-6hbcmkc8.js} +1 -1
  35. package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-s0b0vv4k.js → ebnfDiagram-ZINNZB2B-5fkmymqn.js} +1 -1
  36. package/dist/client/static/js/{elixir-rpa1g4gy.js → elixir-jwphgp8j.js} +1 -1
  37. package/dist/client/static/js/{elk-276RUBZZ-mtpw0spa.js → elk-276RUBZZ-6xrfa2kd.js} +1 -1
  38. package/dist/client/static/js/{erDiagram-OPXOYQCR-agjdsm1b.js → erDiagram-OPXOYQCR-byz4zbkn.js} +4 -4
  39. package/dist/client/static/js/eventmodeling-NTZA5JFV-k5n61zzh.js +1 -0
  40. package/dist/client/static/js/flowDiagram-KWPJA3E3-s3fbfwrz.js +1 -0
  41. package/dist/client/static/js/{ganttDiagram-FUAMR5RP-z6ywqqc1.js → ganttDiagram-FUAMR5RP-4fkw1k01.js} +2 -2
  42. package/dist/client/static/js/gitGraph-4MIJSDKK-2gf053bx.js +1 -0
  43. package/dist/client/static/js/{gitGraphDiagram-X574FWY7-bvbmfw6h.js → gitGraphDiagram-X574FWY7-19g84yw8.js} +2 -2
  44. package/dist/client/static/js/graphql-p4cskvad.js +1 -0
  45. package/dist/client/static/js/html-f26r6vv5.js +1 -0
  46. package/dist/client/static/js/{index-z0frtyje.js → index-0v8b5pzb.js} +4 -4
  47. package/dist/client/static/js/{index-z7qnffwj.js → index-1j1s91c4.js} +1 -1
  48. package/dist/client/static/js/{index-jpkj6vqp.js → index-20vhkcb9.js} +1 -1
  49. package/dist/client/static/js/{index-0j518hqm.js → index-3az1w5f8.js} +2 -2
  50. package/dist/client/static/js/{index-qznwd6g8.js → index-3wpsr2bc.js} +184 -184
  51. package/dist/client/static/js/{index-09gx6edj.js → index-3y6krykq.js} +1 -1
  52. package/dist/client/static/js/{index-we1rpftn.js → index-4jbbdq6n.js} +2 -2
  53. package/dist/client/static/js/{index-ntxm8pw3.js → index-4qt2e84b.js} +2 -2
  54. package/dist/client/static/js/{index-49dhv8ry.js → index-57z8mtmx.js} +2 -2
  55. package/dist/client/static/js/{index-qz8mbxm9.js → index-5gn56236.js} +2 -2
  56. package/dist/client/static/js/{index-9t82sx0w.js → index-6k3e5dph.js} +2 -2
  57. package/dist/client/static/js/{index-es3pt29g.js → index-74scnfpk.js} +1 -1
  58. package/dist/client/static/js/{index-0mvcbbmy.js → index-7kafzae0.js} +9 -9
  59. package/dist/client/static/js/{index-pd0140dx.js → index-89a2702q.js} +1 -1
  60. package/dist/client/static/js/{index-059qyaj0.js → index-8j90mdgz.js} +1 -1
  61. package/dist/client/static/js/{index-zvfvqvn9.js → index-9wd9y6m0.js} +2 -2
  62. package/dist/client/static/js/{index-a0bdavdr.js → index-ashpbfqv.js} +1 -1
  63. package/dist/client/static/js/{index-72t6kqjx.js → index-b9b2nwdd.js} +2 -2
  64. package/dist/client/static/js/{index-8e0s9p45.js → index-baet2nv8.js} +1 -1
  65. package/dist/client/static/js/{index-j7r414hf.js → index-bhng2dax.js} +2 -2
  66. package/dist/client/static/js/{index-21b3zyrd.js → index-cj9193d5.js} +2 -2
  67. package/dist/client/static/js/{index-sezz011q.js → index-dd4q54y0.js} +1 -1
  68. package/dist/client/static/js/{index-xearvz2z.js → index-e3w46vsc.js} +7 -7
  69. package/dist/client/static/js/{index-1tyvk778.js → index-e99ec2f0.js} +1 -1
  70. package/dist/client/static/js/{index-w9zxmev3.js → index-ehnztdd2.js} +1 -1
  71. package/dist/client/static/js/{index-actppd4z.js → index-epbqzayj.js} +2 -2
  72. package/dist/client/static/js/{index-k06med7d.js → index-fghst0kd.js} +12 -12
  73. package/dist/client/static/js/{index-t07b31ny.js → index-fpf1jkwd.js} +3 -3
  74. package/dist/client/static/js/{index-hbtk0c12.js → index-g252205p.js} +2 -2
  75. package/dist/client/static/js/{index-vtbbfwx0.js → index-gr6jng0x.js} +2 -2
  76. package/dist/client/static/js/{index-kzhtmrh0.js → index-gxtgyya0.js} +1 -1
  77. package/dist/client/static/js/index-j314me09.js +1 -0
  78. package/dist/client/static/js/{index-5fn0agag.js → index-jbwns6sc.js} +1 -1
  79. package/dist/client/static/js/{index-cx89yk15.js → index-kdgcbt17.js} +2 -2
  80. package/dist/client/static/js/{index-m87yykre.js → index-m4bjsyj2.js} +5 -5
  81. package/dist/client/static/js/{index-15zn3sns.js → index-nd4p98mc.js} +1 -1
  82. package/dist/client/static/js/{index-nmc30xaz.js → index-pfwd0160.js} +1 -1
  83. package/dist/client/static/js/{index-w7xbfv44.js → index-qn4pkjfh.js} +2 -2
  84. package/dist/client/static/js/{index-0sqa91wb.js → index-qntytvt0.js} +2 -2
  85. package/dist/client/static/js/{index-64mb65wx.js → index-r83kr4s5.js} +2 -2
  86. package/dist/client/static/js/{index-7sa2e8mn.js → index-rgdhyry3.js} +2 -2
  87. package/dist/client/static/js/{index-m3j5yx5f.js → index-sjnnv1gd.js} +4 -4
  88. package/dist/client/static/js/{index-6q80csr0.js → index-t5t71dhp.js} +2 -2
  89. package/dist/client/static/js/{index-z6g74h7g.js → index-vb6t44dw.js} +2 -2
  90. package/dist/client/static/js/{index-a293pdg7.js → index-y3hdv561.js} +2 -2
  91. package/dist/client/static/js/{index-302d35e5.js → index-zj45wj1x.js} +34 -34
  92. package/dist/client/static/js/{index-83ts8zmk.js → index-zw7qjx65.js} +1 -1
  93. package/dist/client/static/js/info-A6RAGUB7-3tr0y3s6.js +1 -0
  94. package/dist/client/static/js/{infoDiagram-VRGFBTTK-58bv28d4.js → infoDiagram-VRGFBTTK-aw6ter0a.js} +1 -1
  95. package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-tz6b0caw.js → ishikawaDiagram-OU5B5YK6-62gst5wh.js} +2 -2
  96. package/dist/client/static/js/javascript-nyf39d5r.js +1 -0
  97. package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-ydamm17a.js → journeyDiagram-ZHPQQLJL-6kgv5a4j.js} +3 -3
  98. package/dist/client/static/js/{julia-v7j460gw.js → julia-237yk557.js} +1 -1
  99. package/dist/client/static/js/{kanban-definition-PNTS6WVX-7jxfsf17.js → kanban-definition-PNTS6WVX-8p3515b7.js} +3 -3
  100. package/dist/client/static/js/lua-86fjqj8v.js +1 -0
  101. package/dist/client/static/js/{mermaid.core-vty0aq6f.js → mermaid.core-b6ga2y8y.js} +6 -6
  102. package/dist/client/static/js/{mindmap-definition-NLK3R4M7-ra4wrts4.js → mindmap-definition-NLK3R4M7-na9e9b4a.js} +2 -2
  103. package/dist/client/static/js/one-dark-pro-xp6ssk4z.js +1 -0
  104. package/dist/client/static/js/one-light-xgab7b02.js +1 -0
  105. package/dist/client/static/js/packet-AYTQ26CC-xbsyjzrh.js +1 -0
  106. package/dist/client/static/js/{pegDiagram-GJSIUBJH-ydjcfea9.js → pegDiagram-GJSIUBJH-d1hk7fnq.js} +1 -1
  107. package/dist/client/static/js/{perl-gg4jdkcr.js → perl-dvz4y1tb.js} +1 -1
  108. package/dist/client/static/js/{php-2q8fm6k8.js → php-n6y7dzhm.js} +1 -1
  109. package/dist/client/static/js/pie-WAS4IAKB-j2tpz0cs.js +1 -0
  110. package/dist/client/static/js/{pieDiagram-5QR66LMP-wh04y7wp.js → pieDiagram-5QR66LMP-7b9f4x0y.js} +2 -2
  111. package/dist/client/static/js/{quadrantDiagram-O4NWA36T-4mhbag8n.js → quadrantDiagram-O4NWA36T-q4wxgmhg.js} +1 -1
  112. package/dist/client/static/js/radar-RG4KPBEZ-m3tsyfv0.js +1 -0
  113. package/dist/client/static/js/railroad-74A4TZTK-5p202a4q.js +1 -0
  114. package/dist/client/static/js/railroad-abnf-HS5TGJTU-hj0y9tgn.js +1 -0
  115. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-8c5dct8f.js +1 -0
  116. package/dist/client/static/js/railroad-peg-WCYAUIDC-3tx8z65q.js +1 -0
  117. package/dist/client/static/js/{railroadDiagram-XR7U4H2S-pagmr4hc.js → railroadDiagram-XR7U4H2S-jngq1qx4.js} +1 -1
  118. package/dist/client/static/js/{requirementDiagram-PLB6GJNP-jhfhp4eq.js → requirementDiagram-PLB6GJNP-6xph3b72.js} +4 -4
  119. package/dist/client/static/js/{ruby-vag6a82m.js → ruby-7zye3g0e.js} +1 -1
  120. package/dist/client/static/js/{rust-yntkm6hw.js → rust-w6hen2h4.js} +1 -1
  121. package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-qrfxzvp3.js → sankeyDiagram-IPEJSGJF-ncfzgdj8.js} +1 -1
  122. package/dist/client/static/js/{sass-kbwea482.js → sass-m0h9yzfb.js} +1 -1
  123. package/dist/client/static/js/{scss-zphrqp25.js → scss-2pwwfkvn.js} +1 -1
  124. package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-fpznwnva.js → sequenceDiagram-PO4LG4MO-sqz0yfg0.js} +3 -3
  125. package/dist/client/static/js/{sizeCapture-INFHLROL-3hz930jg.js → sizeCapture-INFHLROL-vt8qp04d.js} +1 -1
  126. package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-2m99syxm.js → stateDiagram-v2-GCMORJYK-myjtrmfe.js} +3 -3
  127. package/dist/client/static/js/{svelte-mwtx07d9.js → svelte-x8f8c8hq.js} +1 -1
  128. package/dist/client/static/js/{swimlanes-2SLR337P-hmhd360r.js → swimlanes-2SLR337P-z9vx7z4j.js} +1 -1
  129. package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-a8b7z74e.js → swimlanesDiagram-TC7HE7FX-5vha7thx.js} +1 -1
  130. package/dist/client/static/js/{timeline-definition-EJHVYXUP-765y3ssa.js → timeline-definition-EJHVYXUP-z815np57.js} +2 -2
  131. package/dist/client/static/js/treeView-Q6P3EWNA-mf0rb2yv.js +1 -0
  132. package/dist/client/static/js/treemap-WGGIJYW6-0x5gf06b.js +1 -0
  133. package/dist/client/static/js/typescript-5nmrzgkj.js +1 -0
  134. package/dist/client/static/js/{usecaseDiagram-POWQR4AR-rex2j507.js → usecaseDiagram-POWQR4AR-06ntggng.js} +13 -13
  135. package/dist/client/static/js/{vennDiagram-UO4OBE2U-wd51qq26.js → vennDiagram-UO4OBE2U-nmtaf5rp.js} +1 -1
  136. package/dist/client/static/js/{vue-j8vb9d7r.js → vue-myjjd0gd.js} +1 -1
  137. package/dist/client/static/js/wardley-WFR3VGLG-x7ej8dms.js +1 -0
  138. package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-6jdqn8f7.js → wardleyDiagram-VNRHLVJA-zgsxmak8.js} +1 -1
  139. package/dist/client/static/js/xml-3dd1pter.js +1 -0
  140. package/dist/client/static/js/{xychartDiagram-PMCCYNJV-kcz8y04e.js → xychartDiagram-PMCCYNJV-8bg9qdra.js} +2 -2
  141. package/package.json +1 -1
  142. package/src/client/components/common/ComposerPicker.tsx +24 -12
  143. package/src/client/components/common/ComposerTextarea.tsx +1 -0
  144. package/src/client/components/layout/session-sidebar/scheduler-modal/ModelFields.tsx +1 -1
  145. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +1 -1
  146. package/src/client/components/workspace/chat-timeline/index.tsx +3 -3
  147. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FormAsk.test.tsx +210 -0
  148. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FormAsk.tsx +342 -0
  149. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/LooseFieldAsk.tsx +44 -0
  150. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/OrphanAsks.test.tsx +44 -1
  151. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/OrphanAsks.tsx +10 -5
  152. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/PluginPendingInteractions.test.ts +1 -0
  153. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +19 -0
  154. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/form-picks.ts +52 -0
  155. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.test.ts +2 -2
  156. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +53 -4
  157. package/src/client/components/workspace/model-dropdown/index.tsx +1 -1
  158. package/src/client/components/workspace/model-dropdown/use-catalog.ts +3 -32
  159. package/src/client/data/settings/omp-schema.json +55 -1
  160. package/src/client/hooks/chat/composer/harness-model-picker.ts +84 -0
  161. package/src/client/hooks/chat/composer/index.ts +26 -6
  162. package/src/client/hooks/chat/timeline/ask-frames.test.ts +80 -7
  163. package/src/client/hooks/chat/timeline/ask-frames.ts +95 -21
  164. package/src/client/hooks/models/use-harnesses.ts +15 -2
  165. package/src/server/lib/auth/agent-gate.server.ts +64 -0
  166. package/src/server/lib/auth/agent-tree-gate.test.ts +121 -0
  167. package/src/server/lib/auth/guard.test.ts +18 -18
  168. package/src/server/lib/auth/guard.ts +15 -11
  169. package/src/server/lib/auth/handover-guard.test.ts +1 -1
  170. package/src/server/lib/changes/attach.server.ts +57 -0
  171. package/src/server/lib/changes/attach.test.ts +94 -0
  172. package/src/server/lib/changes/blobs.server.ts +52 -0
  173. package/src/server/lib/changes/capture-bash.server.ts +171 -0
  174. package/src/server/lib/changes/capture-fs.server.ts +64 -0
  175. package/src/server/lib/changes/capture-races.test.ts +107 -0
  176. package/src/server/lib/changes/capture-runs.test.ts +136 -0
  177. package/src/server/lib/changes/capture-scan.test.ts +157 -0
  178. package/src/server/lib/changes/capture-test-util.ts +46 -0
  179. package/src/server/lib/changes/capture-types.ts +64 -0
  180. package/src/server/lib/changes/capture-write.server.ts +50 -0
  181. package/src/server/lib/changes/capture.server.ts +349 -0
  182. package/src/server/lib/changes/capture.test.ts +293 -0
  183. package/src/server/lib/changes/classify-command.test.ts +172 -0
  184. package/src/server/lib/changes/classify-command.ts +272 -0
  185. package/src/server/lib/changes/classify-git.ts +88 -0
  186. package/src/server/lib/changes/classify-paths.ts +112 -0
  187. package/src/server/lib/changes/classify-tokenize.ts +185 -0
  188. package/src/server/lib/changes/journal.server.ts +185 -0
  189. package/src/server/lib/changes/journal.test.ts +125 -0
  190. package/src/server/lib/changes/merge.test.ts +137 -0
  191. package/src/server/lib/changes/omp-fallback.server.ts +48 -0
  192. package/src/server/lib/changes/omp-fallback.test.ts +75 -0
  193. package/src/server/lib/changes/paths.server.ts +37 -0
  194. package/src/server/lib/changes/purge.server.ts +32 -0
  195. package/src/server/lib/changes/reader.server.ts +350 -0
  196. package/src/server/lib/changes/reader.test.ts +137 -0
  197. package/src/server/lib/changes/records.ts +120 -0
  198. package/src/server/lib/changes/scan.server.ts +139 -0
  199. package/src/server/lib/changes/sessions.server.ts +65 -0
  200. package/src/server/lib/changes/sessions.test.ts +52 -0
  201. package/src/server/lib/harness/register.server.ts +3 -0
  202. package/src/server/lib/omp/rpc/event-fanout.test.ts +58 -0
  203. package/src/server/lib/omp/rpc/event-fanout.ts +19 -0
  204. package/src/server/lib/omp/rpc/manager.ts +4 -3
  205. package/src/server/lib/omp/rpc/session-registration.ts +5 -0
  206. package/src/server/lib/omp/rpc/session-registry.ts +4 -5
  207. package/src/server/lib/omp/session/delete.server.ts +4 -0
  208. package/src/server/lib/sessions/agent-token.server.test.ts +28 -5
  209. package/src/server/lib/sessions/agent-token.server.ts +42 -6
  210. package/src/server/lib/sessions/relation-access.server.test.ts +96 -0
  211. package/src/server/lib/sessions/relation-access.server.ts +71 -0
  212. package/src/server/routes/sessions/changes.ts +1 -1
  213. package/src/shared/lib/chat/ask-form/fields.ts +1 -0
  214. package/src/shared/lib/chat/ask-form/types.ts +6 -0
  215. package/src/shared/lib/chat/ask-questions.ts +56 -3
  216. package/src/shared/lib/chat/composer/delegation.ts +2 -13
  217. package/src/shared/lib/chat/composer/filter.test.ts +39 -0
  218. package/src/shared/lib/chat/composer/filter.ts +23 -13
  219. package/src/shared/lib/chat/composer/harness-model-items.test.ts +54 -0
  220. package/src/shared/lib/chat/composer/harness-model-items.ts +41 -0
  221. package/src/shared/lib/chat/composer/trigger.test.ts +50 -0
  222. package/src/shared/lib/chat/composer/trigger.ts +29 -1
  223. package/src/shared/lib/chat/timeline/changed-files.test.ts +16 -0
  224. package/src/shared/lib/chat/timeline/changed-files.ts +102 -25
  225. package/src/shared/lib/harness/catalog.ts +21 -0
  226. package/src/{client/components/workspace/model-dropdown/harness-models.test.ts → shared/lib/harness/models.test.ts} +1 -1
  227. package/src/shared/lib/models/option.ts +46 -0
  228. package/src/shared/lib/omp/config/schema.test.ts +20 -0
  229. package/src/shared/types/chat.ts +12 -6
  230. package/src/shared/types/omp/agent.ts +9 -0
  231. package/src/shared/types/session-changes.ts +4 -0
  232. package/dist/client/static/js/architecture-7GRP2DOG-7ewrw5vc.js +0 -1
  233. package/dist/client/static/js/c-wkgxb1t1.js +0 -1
  234. package/dist/client/static/js/cpp-y0t6mynx.js +0 -1
  235. package/dist/client/static/js/css-r2nhvzff.js +0 -1
  236. package/dist/client/static/js/css-tf1s0nb7.js +0 -1
  237. package/dist/client/static/js/cynefin-OW5HDTMX-yyyx3px0.js +0 -1
  238. package/dist/client/static/js/eventmodeling-NTZA5JFV-cx3ztxfz.js +0 -1
  239. package/dist/client/static/js/flowDiagram-KWPJA3E3-267mw6sv.js +0 -1
  240. package/dist/client/static/js/gitGraph-4MIJSDKK-eg9r85ak.js +0 -1
  241. package/dist/client/static/js/graphql-skw5krjr.js +0 -1
  242. package/dist/client/static/js/html-pv88ny12.js +0 -1
  243. package/dist/client/static/js/index-tcegdd2t.js +0 -1
  244. package/dist/client/static/js/info-A6RAGUB7-7qhah7fs.js +0 -1
  245. package/dist/client/static/js/javascript-4kw2j9t3.js +0 -1
  246. package/dist/client/static/js/lua-ke895s2q.js +0 -1
  247. package/dist/client/static/js/one-dark-pro-2pywnqrh.js +0 -1
  248. package/dist/client/static/js/one-light-vfgdt4wf.js +0 -1
  249. package/dist/client/static/js/packet-AYTQ26CC-ag2g7tbk.js +0 -1
  250. package/dist/client/static/js/pie-WAS4IAKB-nqcyj3x1.js +0 -1
  251. package/dist/client/static/js/radar-RG4KPBEZ-60gby7be.js +0 -1
  252. package/dist/client/static/js/railroad-74A4TZTK-cnkmcjse.js +0 -1
  253. package/dist/client/static/js/railroad-abnf-HS5TGJTU-qgfdnazd.js +0 -1
  254. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-609h6cpx.js +0 -1
  255. package/dist/client/static/js/railroad-peg-WCYAUIDC-xqnytjhg.js +0 -1
  256. package/dist/client/static/js/treeView-Q6P3EWNA-8djqab8k.js +0 -1
  257. package/dist/client/static/js/treemap-WGGIJYW6-hdztnffk.js +0 -1
  258. package/dist/client/static/js/typescript-0s2t05jj.js +0 -1
  259. package/dist/client/static/js/wardley-WFR3VGLG-avby77vv.js +0 -1
  260. package/dist/client/static/js/xml-81hxjjt4.js +0 -1
  261. /package/src/{client/components/workspace/model-dropdown/harness-models.ts → shared/lib/harness/models.ts} +0 -0
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The omp journal as the `write` race fallback.
8
+ *
9
+ * omp reads the file inside the tool, before the write, so its `before` blob is
10
+ * exact where Kabmo's start-frame snapshot can lose the race. The three answers
11
+ * matter: a string (the before content), `null` (the file did not exist), and
12
+ * `undefined` (no matching record — the caller must not read that as absent).
13
+ */
14
+
15
+ import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
16
+ import * as fsp from 'node:fs/promises';
17
+ import * as os from 'node:os';
18
+ import * as path from 'node:path';
19
+ import { readOmpBefore } from '@/server/lib/changes/omp-fallback.server';
20
+ import { clearSessionFileCaches } from '@/server/lib/omp/session/files';
21
+
22
+ const SESSION = 'omp-fallback-1';
23
+ let agentDir = '';
24
+ let original: string | undefined;
25
+
26
+ beforeAll(async () => {
27
+ original = Bun.env.PI_CODING_AGENT_DIR;
28
+ agentDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'kabmo-omp-fallback-'));
29
+ Bun.env.PI_CODING_AGENT_DIR = agentDir;
30
+ clearSessionFileCaches();
31
+
32
+ const projectDir = path.join(agentDir, 'sessions', '-repo');
33
+ await fsp.mkdir(projectDir, { recursive: true });
34
+ const sessionFile = path.join(projectDir, `2026-01-01T00-00-00-000Z_${SESSION}.jsonl`);
35
+ await fsp.writeFile(
36
+ sessionFile,
37
+ `${JSON.stringify({ type: 'session', version: 3, id: SESSION, timestamp: '2026-01-01T00:00:00.000Z', cwd: '/repo' })}\n`,
38
+ );
39
+ const journalDir = sessionFile.slice(0, -'.jsonl'.length);
40
+ await fsp.mkdir(path.join(journalDir, 'blobs'), { recursive: true });
41
+ await fsp.writeFile(path.join(journalDir, 'blobs', 'b1'), Bun.gzipSync(Buffer.from('old', 'utf8')));
42
+ await fsp.writeFile(path.join(journalDir, 'blobs', 'b2'), Bun.gzipSync(Buffer.from('new', 'utf8')));
43
+ await fsp.writeFile(
44
+ path.join(journalDir, 'changes.jsonl'),
45
+ [
46
+ JSON.stringify({ type: 'change', at: 1000, agent: 'Main', tool: 'write', path: '/repo/a.ts', before: 'b1', after: 'b2' }),
47
+ JSON.stringify({ type: 'change', at: 2000, agent: 'Main', tool: 'write', path: '/repo/new.ts', before: null, after: 'b2' }),
48
+ ].join('\n') + '\n',
49
+ );
50
+ });
51
+
52
+ afterAll(async () => {
53
+ if (original === undefined) delete Bun.env.PI_CODING_AGENT_DIR;
54
+ else Bun.env.PI_CODING_AGENT_DIR = original;
55
+ clearSessionFileCaches();
56
+ await fsp.rm(agentDir, { recursive: true, force: true });
57
+ });
58
+
59
+ describe('readOmpBefore', () => {
60
+ test('returns the before content of the matching record', async () => {
61
+ expect(await readOmpBefore(SESSION, '/repo/a.ts', 1000)).toBe('old');
62
+ });
63
+
64
+ test('returns null when the file did not exist', async () => {
65
+ expect(await readOmpBefore(SESSION, '/repo/new.ts', 2000)).toBeNull();
66
+ });
67
+
68
+ test('returns undefined outside the match window', async () => {
69
+ expect(await readOmpBefore(SESSION, '/repo/a.ts', 20_000)).toBeUndefined();
70
+ });
71
+
72
+ test('returns undefined for a path with no record', async () => {
73
+ expect(await readOmpBefore(SESSION, '/repo/missing.ts', 1000)).toBeUndefined();
74
+ });
75
+ });
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Where a session's Kabmo change journal lives.
8
+ *
9
+ * `~/.kabmo/changes/<sessionId>/` — beside the database, the same root `btw/`
10
+ * uses, so a delete of the data directory takes the journals with it. The
11
+ * session id is a single path segment by construction (omp UUIDs, mock
12
+ * integers); the guard is here because the reader is reached from a route
13
+ * parameter, and `path.join` normalizes a `..` into a different directory.
14
+ */
15
+
16
+ import path from 'node:path';
17
+ import { getDataDir } from '@/server/lib/lifecycle/paths';
18
+ import { isSinglePathSegment } from '@/server/lib/fs/path-segment';
19
+
20
+ export function changesRoot(): string {
21
+ return path.join(getDataDir(), 'changes');
22
+ }
23
+
24
+ export function sessionChangesDir(sessionId: string): string {
25
+ if (!isSinglePathSegment(sessionId)) {
26
+ throw new Error(`Invalid session id for a change journal: ${JSON.stringify(sessionId)}`);
27
+ }
28
+ return path.join(changesRoot(), sessionId);
29
+ }
30
+
31
+ export function journalPath(sessionId: string): string {
32
+ return path.join(sessionChangesDir(sessionId), 'changes.jsonl');
33
+ }
34
+
35
+ export function blobsDir(sessionId: string): string {
36
+ return path.join(sessionChangesDir(sessionId), 'blobs');
37
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Remove a session's Kabmo change journal.
8
+ *
9
+ * The journal is derived data, but it holds file contents: leaving it behind
10
+ * after a delete would keep a copy of every file the run touched, under an id
11
+ * the sidebar no longer lists. The directory is the unit — `changes.jsonl`,
12
+ * its rotated siblings and `blobs/` all live under it.
13
+ */
14
+
15
+ import { rm } from 'node:fs/promises';
16
+ import { sessionChangesDir } from '@/server/lib/changes/paths.server';
17
+
18
+ /** True when a journal directory existed and was removed. */
19
+ export async function purgeChangeJournal(sessionId: string): Promise<boolean> {
20
+ let dir: string;
21
+ try {
22
+ dir = sessionChangesDir(sessionId);
23
+ } catch {
24
+ return false;
25
+ }
26
+ try {
27
+ await rm(dir, { recursive: true, force: true });
28
+ return true;
29
+ } catch {
30
+ return false;
31
+ }
32
+ }
@@ -0,0 +1,350 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Read a session's Kabmo change journal, with omp's journal as the fallback and
8
+ * the pre-feature half merged in.
9
+ *
10
+ * The Kabmo journal is the answer when it has any `change` record: it sees the
11
+ * `bash` mutations omp never records, and a delete is a record rather than a
12
+ * creation whose file happens to be gone. A session that predates the feature
13
+ * has no Kabmo journal, so the omp reader answers — read directly, not
14
+ * imported, because an import would duplicate the blobs and the lines.
15
+ *
16
+ * A session that SPANS the feature is the third case: it ran before the journal
17
+ * existed and continued after it. The Kabmo journal then starts mid-session, so
18
+ * the omp records older than its first line are merged in. Newer omp records
19
+ * are not: from the first Kabmo line on, the Kabmo journal is the authority,
20
+ * and merging both would double every edit the two writers both saw.
21
+ *
22
+ * Each merged record carries the store its blob keys belong to, so a diff whose
23
+ * two sides straddle the boundary reads the right blob directory.
24
+ *
25
+ * The parse is cached by the size+mtime of every journal file, the same rule
26
+ * the omp reader follows. A torn final line is skipped, not fatal.
27
+ */
28
+
29
+ import { readdir, stat } from 'node:fs/promises';
30
+ import path from 'node:path';
31
+ import { blobsDir, sessionChangesDir } from '@/server/lib/changes/paths.server';
32
+ import { readBlob } from '@/server/lib/changes/blobs.server';
33
+ import { parseJournalLine, type JournalChangeRecord } from '@/server/lib/changes/records';
34
+ import {
35
+ readSessionChangeIndex as readOmpIndex,
36
+ readSessionChangeList as readOmpList,
37
+ } from '@/server/lib/omp/session/changes';
38
+ import { findSessionFileById } from '@/server/lib/omp/session/locator';
39
+ import { siblingDirForSession } from '@/server/lib/omp/subagent/history/paths';
40
+ import { unifiedDiff } from '@/shared/lib/fs/unified-diff';
41
+ import { patchSides } from '@/shared/lib/fs/patch-sides';
42
+ import type {
43
+ SessionChangeCounts,
44
+ SessionChangeDiff,
45
+ SessionChangeRecord,
46
+ } from '@/shared/types/session-changes';
47
+
48
+ interface CacheEntry {
49
+ signature: string;
50
+ records: JournalChangeRecord[];
51
+ }
52
+
53
+ interface CacheHost {
54
+ entries: Map<string, CacheEntry>;
55
+ }
56
+
57
+ declare global {
58
+ // eslint-disable-next-line no-var
59
+ var __kabmoChangeJournalCache: CacheHost | undefined;
60
+ }
61
+
62
+ function cache(): CacheHost {
63
+ if (!globalThis.__kabmoChangeJournalCache) globalThis.__kabmoChangeJournalCache = { entries: new Map() };
64
+ return globalThis.__kabmoChangeJournalCache;
65
+ }
66
+
67
+ /** Journal files oldest first: rotated `changes.<epoch>.jsonl`, then the current one. */
68
+ function journalFiles(names: string[]): string[] {
69
+ return names
70
+ .filter((name) => name === 'changes.jsonl' || /^changes\.\d+\.jsonl$/.test(name))
71
+ .sort();
72
+ }
73
+
74
+ async function signatureFor(dir: string, files: string[]): Promise<string> {
75
+ const parts: string[] = [];
76
+ for (const name of files) {
77
+ const info = await stat(path.join(dir, name)).catch(() => null);
78
+ parts.push(`${name}:${info?.size ?? 0}:${info?.mtimeMs ?? 0}`);
79
+ }
80
+ return parts.join('|');
81
+ }
82
+
83
+ async function readJournalRecords(sessionId: string): Promise<JournalChangeRecord[]> {
84
+ let dir: string;
85
+ try {
86
+ dir = sessionChangesDir(sessionId);
87
+ } catch {
88
+ return [];
89
+ }
90
+ let names: string[];
91
+ try {
92
+ names = await readdir(dir);
93
+ } catch {
94
+ return [];
95
+ }
96
+ const files = journalFiles(names);
97
+ if (files.length === 0) return [];
98
+
99
+ const signature = await signatureFor(dir, files);
100
+ const cached = cache().entries.get(sessionId);
101
+ if (cached && cached.signature === signature) return cached.records;
102
+
103
+ const records: JournalChangeRecord[] = [];
104
+ for (const name of files) {
105
+ const text = await Bun.file(path.join(dir, name)).text().catch(() => '');
106
+ for (const line of text.split('\n')) {
107
+ const record = parseJournalLine(line);
108
+ if (record?.type === 'change') records.push(record);
109
+ }
110
+ }
111
+ records.sort((a, b) => a.at - b.at);
112
+ cache().entries.set(sessionId, { signature, records });
113
+ return records;
114
+ }
115
+
116
+ /** One record plus the blob store its `before`/`after` keys belong to. */
117
+ interface MergedRecord {
118
+ at: number;
119
+ runId?: string;
120
+ runAt?: number;
121
+ agent: string;
122
+ parent?: string;
123
+ tool: string;
124
+ path: string;
125
+ displayPath: string;
126
+ before: string | null | undefined;
127
+ after: string | null | undefined;
128
+ store: 'kabmo' | 'omp';
129
+ }
130
+
131
+ /** The omp journal's blob directory, or `null` when the session has no file. */
132
+ async function ompBlobDir(sessionId: string): Promise<string | null> {
133
+ const sessionFile = await findSessionFileById(sessionId);
134
+ if (!sessionFile) return null;
135
+ return path.join(siblingDirForSession(sessionFile), 'blobs');
136
+ }
137
+
138
+ /**
139
+ * The session's records, oldest first.
140
+ *
141
+ * `list` selects the omp reader's list variant (which drops a creation whose
142
+ * file is gone) for the no-Kabmo fallback. Once a Kabmo journal exists, the omp
143
+ * half is read RAW: the Kabmo `delete` record is the other half of a
144
+ * create-then-delete, and the client's net logic drops the pair.
145
+ */
146
+ async function readMergedRecords(sessionId: string, list: boolean): Promise<MergedRecord[]> {
147
+ const kabmo = await readJournalRecords(sessionId);
148
+ if (kabmo.length === 0) {
149
+ const omp = list ? await readOmpList(sessionId) : await readOmpIndex(sessionId);
150
+ return omp.map((record) => ({ ...record, store: 'omp' as const }));
151
+ }
152
+
153
+ const firstKabmoAt = kabmo[0].at;
154
+ const omp = await readOmpIndex(sessionId);
155
+ const merged: MergedRecord[] = [];
156
+ for (const record of omp) {
157
+ if (record.at >= firstKabmoAt) continue;
158
+ merged.push({ ...record, store: 'omp' });
159
+ }
160
+ for (const record of kabmo) {
161
+ merged.push({
162
+ at: record.at,
163
+ ...(record.runId ? { runId: record.runId } : {}),
164
+ ...(record.runAt !== undefined ? { runAt: record.runAt } : {}),
165
+ agent: record.agent,
166
+ ...(record.parent ? { parent: record.parent } : {}),
167
+ tool: record.tool,
168
+ path: record.path,
169
+ displayPath: record.displayPath,
170
+ before: record.before,
171
+ after: record.after,
172
+ store: 'kabmo',
173
+ });
174
+ }
175
+ merged.sort((a, b) => a.at - b.at);
176
+ return merged;
177
+ }
178
+
179
+ function toSessionChangeRecord(record: MergedRecord): SessionChangeRecord {
180
+ return {
181
+ at: record.at,
182
+ ...(record.runId ? { runId: record.runId } : {}),
183
+ ...(record.runAt !== undefined ? { runAt: record.runAt } : {}),
184
+ agent: record.agent,
185
+ ...(record.parent ? { parent: record.parent } : {}),
186
+ tool: record.tool,
187
+ path: record.path,
188
+ displayPath: record.displayPath,
189
+ before: record.before,
190
+ after: record.after,
191
+ };
192
+ }
193
+
194
+ /** True when the path is still on disk; a stat error other than ENOENT counts
195
+ * as present, so a permission problem never hides a real change. */
196
+ async function pathExists(absolute: string): Promise<boolean> {
197
+ try {
198
+ await stat(absolute);
199
+ return true;
200
+ } catch (error) {
201
+ return (error as NodeJS.ErrnoException).code !== 'ENOENT';
202
+ }
203
+ }
204
+
205
+ /** Resolve a blob key from the store that wrote it. */
206
+ async function resolveMergedBlob(
207
+ sessionId: string,
208
+ store: MergedRecord['store'],
209
+ key: string | null | undefined,
210
+ ): Promise<string | null | undefined> {
211
+ if (key === null) return null;
212
+ if (key === undefined) return undefined;
213
+ if (store === 'kabmo') return readBlob(blobsDir(sessionId), key);
214
+ const dir = await ompBlobDir(sessionId);
215
+ return dir ? readBlob(dir, key) : undefined;
216
+ }
217
+
218
+ /** The last record for one path, for the scan's same-content dedupe. */
219
+ export async function readSessionChangeLast(
220
+ sessionId: string,
221
+ absolute: string,
222
+ ): Promise<{ at: number; after: string | null | undefined } | null> {
223
+ const records = await readJournalRecords(sessionId);
224
+ let last: JournalChangeRecord | null = null;
225
+ for (const record of records) {
226
+ if (record.path !== absolute) continue;
227
+ if (!last || record.at >= last.at) last = record;
228
+ }
229
+ return last ? { at: last.at, after: last.after } : null;
230
+ }
231
+
232
+ /** The paths one session recorded inside `[from, to]`; the scan's cross-check. */
233
+ export async function readSessionChangePaths(
234
+ sessionId: string,
235
+ from: number,
236
+ to: number,
237
+ ): Promise<Set<string>> {
238
+ const records = await readJournalRecords(sessionId);
239
+ const paths = new Set<string>();
240
+ for (const record of records) {
241
+ if (record.at >= from && record.at <= to) paths.add(record.path);
242
+ }
243
+ return paths;
244
+ }
245
+
246
+ /** Every change record of one session, oldest first, with display paths. */
247
+ export async function readSessionChangeIndex(sessionId: string): Promise<SessionChangeRecord[]> {
248
+ const records = await readMergedRecords(sessionId, false);
249
+ return records.map(toSessionChangeRecord);
250
+ }
251
+
252
+ /**
253
+ * The index the chat's per-run list reads.
254
+ *
255
+ * A session with no Kabmo journal falls back to the omp list, which still needs
256
+ * its "creation whose file is gone" heuristic. Once a Kabmo journal exists, the
257
+ * merged list is raw and the client's net logic drops a create-then-delete.
258
+ */
259
+ export async function readSessionChangeList(sessionId: string): Promise<SessionChangeRecord[]> {
260
+ const records = await readMergedRecords(sessionId, true);
261
+ // The omp half keeps its own heuristic for a path the Kabmo journal never
262
+ // mentions: a creation whose file is gone was created and deleted before the
263
+ // feature, and its net change is zero. A path the Kabmo journal DOES mention
264
+ // is left to the client's net logic, which sees the Kabmo delete record.
265
+ const kabmoPaths = new Set(records.filter((record) => record.store === 'kabmo').map((record) => record.path));
266
+ const gone = new Set<string>();
267
+ await Promise.all(
268
+ records
269
+ .filter((record) => record.store === 'omp' && record.before === null && !kabmoPaths.has(record.path))
270
+ .map(async (record) => {
271
+ if (!(await pathExists(record.path))) gone.add(record.path);
272
+ }),
273
+ );
274
+ return records.filter((record) => !gone.has(record.path)).map(toSessionChangeRecord);
275
+ }
276
+
277
+ /** The net change of `absolutePath` inside `[from, to]`. */
278
+ export async function readSessionChangeDiff(
279
+ sessionId: string,
280
+ absolutePath: string,
281
+ from: number,
282
+ to: number,
283
+ ): Promise<SessionChangeDiff | null> {
284
+ const records = await readMergedRecords(sessionId, false);
285
+ const inRange = records
286
+ .filter((record) => record.path === absolutePath && record.at >= from && record.at <= to)
287
+ .sort((a, b) => a.at - b.at);
288
+ if (inRange.length === 0) return null;
289
+
290
+ const first = inRange[0];
291
+ const last = inRange[inRange.length - 1];
292
+ const status = first.before === null ? 'added' : last.after === null ? 'deleted' : 'modified';
293
+ const [before, after] = await Promise.all([
294
+ resolveMergedBlob(sessionId, first.store, first.before),
295
+ resolveMergedBlob(sessionId, last.store, last.after),
296
+ ]);
297
+ if (before === undefined || after === undefined) {
298
+ return {
299
+ path: absolutePath,
300
+ displayPath: last.displayPath,
301
+ status,
302
+ oldContent: '',
303
+ newContent: '',
304
+ diff: '',
305
+ unavailable: true,
306
+ };
307
+ }
308
+ const oldContent = before ?? '';
309
+ const newContent = after ?? '';
310
+ return {
311
+ path: absolutePath,
312
+ displayPath: last.displayPath,
313
+ status,
314
+ oldContent,
315
+ newContent,
316
+ diff: unifiedDiff(last.displayPath, oldContent, newContent),
317
+ unavailable: false,
318
+ };
319
+ }
320
+
321
+ /** Net `+`/`−` line counts for every path changed inside `[from, to]`. */
322
+ export async function readSessionChangeStats(
323
+ sessionId: string,
324
+ from: number,
325
+ to: number,
326
+ ): Promise<Record<string, SessionChangeCounts>> {
327
+ const records = await readMergedRecords(sessionId, false);
328
+ const spans = new Map<string, { first: MergedRecord; last: MergedRecord }>();
329
+ for (const record of records) {
330
+ if (record.at < from || record.at > to) continue;
331
+ const span = spans.get(record.path);
332
+ if (span) span.last = record;
333
+ else spans.set(record.path, { first: record, last: record });
334
+ }
335
+
336
+ const stats: Record<string, SessionChangeCounts> = {};
337
+ await Promise.all(
338
+ [...spans].map(async ([absolutePath, { first, last }]) => {
339
+ const [before, after] = await Promise.all([
340
+ resolveMergedBlob(sessionId, first.store, first.before),
341
+ resolveMergedBlob(sessionId, last.store, last.after),
342
+ ]);
343
+ if (before === undefined || after === undefined) return;
344
+ const sides = patchSides(unifiedDiff(absolutePath, before ?? '', after ?? ''));
345
+ if (sides.additions === 0 && sides.deletions === 0) return;
346
+ stats[absolutePath] = { added: sides.additions, removed: sides.deletions };
347
+ }),
348
+ );
349
+ return stats;
350
+ }
@@ -0,0 +1,137 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The journal reader: the net change of a run, the `+`/`−` counts, and the
8
+ * fallback to omp's journal for a session that predates the feature.
9
+ *
10
+ * The net rule is the one the diff tab shows — the first record's `before` to
11
+ * the last record's `after` — so a create-then-update reads as one added file,
12
+ * not two writes.
13
+ */
14
+
15
+ import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
16
+ import * as fsp from 'node:fs/promises';
17
+ import * as os from 'node:os';
18
+ import * as path from 'node:path';
19
+ import { ChangeJournal } from '@/server/lib/changes/journal.server';
20
+ import { journalPath } from '@/server/lib/changes/paths.server';
21
+ import {
22
+ readSessionChangeDiff,
23
+ readSessionChangeIndex,
24
+ readSessionChangeList,
25
+ readSessionChangeStats,
26
+ } from '@/server/lib/changes/reader.server';
27
+ import { clearSessionFileCaches } from '@/server/lib/omp/session/files';
28
+
29
+ const SESSION = 'sess-read';
30
+ let dataDir = '';
31
+ let agentDir = '';
32
+ let originalData: string | undefined;
33
+ let originalAgent: string | undefined;
34
+
35
+ beforeAll(async () => {
36
+ originalData = Bun.env.KABMO_DATA_DIR;
37
+ originalAgent = Bun.env.PI_CODING_AGENT_DIR;
38
+ dataDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'kabmo-changes-read-'));
39
+ agentDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'kabmo-changes-agent-'));
40
+ Bun.env.KABMO_DATA_DIR = dataDir;
41
+ Bun.env.PI_CODING_AGENT_DIR = agentDir;
42
+ clearSessionFileCaches();
43
+
44
+ const journal = new ChangeJournal(SESSION, '/repo');
45
+ await journal.recordChange({
46
+ at: 100, runId: 'r-1', runAt: 90, agent: 'Main', tool: 'edit', op: 'create', path: '/repo/a.ts',
47
+ displayPath: 'a.ts', before: null, after: 'A', source: 'tool',
48
+ });
49
+ await journal.recordChange({
50
+ at: 200, agent: 'Main', tool: 'edit', op: 'update', path: '/repo/a.ts',
51
+ displayPath: 'a.ts', before: 'A', after: 'B', source: 'tool',
52
+ });
53
+ await journal.recordChange({
54
+ at: 300, agent: 'Main', tool: 'bash', op: 'delete', path: '/repo/b.ts',
55
+ displayPath: 'b.ts', before: 'X', after: null, source: 'trace', command: 'rm b.ts', exit: 0,
56
+ });
57
+ await journal.flush();
58
+ });
59
+
60
+ afterAll(async () => {
61
+ if (originalData === undefined) delete Bun.env.KABMO_DATA_DIR;
62
+ else Bun.env.KABMO_DATA_DIR = originalData;
63
+ if (originalAgent === undefined) delete Bun.env.PI_CODING_AGENT_DIR;
64
+ else Bun.env.PI_CODING_AGENT_DIR = originalAgent;
65
+ clearSessionFileCaches();
66
+ await fsp.rm(dataDir, { recursive: true, force: true });
67
+ await fsp.rm(agentDir, { recursive: true, force: true });
68
+ });
69
+
70
+ describe('readSessionChangeIndex', () => {
71
+ test('returns every record, oldest first, with display paths', async () => {
72
+ const records = await readSessionChangeIndex(SESSION);
73
+ expect(records.map((record) => record.displayPath)).toEqual(['a.ts', 'a.ts', 'b.ts']);
74
+ expect(records[2]?.tool).toBe('bash');
75
+ });
76
+ });
77
+
78
+ describe('run fields', () => {
79
+ test('maps the run id and its start time', async () => {
80
+ const records = await readSessionChangeIndex(SESSION);
81
+ expect(records[0]?.runId).toBe('r-1');
82
+ expect(records[0]?.runAt).toBe(90);
83
+ expect(records[1]?.runId).toBeUndefined();
84
+ });
85
+ });
86
+
87
+ describe('readSessionChangeList', () => {
88
+ test('keeps a delete record instead of inferring it from the filesystem', async () => {
89
+ const records = await readSessionChangeList(SESSION);
90
+ expect(records.length).toBe(3);
91
+ expect(records.some((record) => record.path === '/repo/b.ts')).toBe(true);
92
+ });
93
+ });
94
+
95
+ describe('readSessionChangeDiff', () => {
96
+ test('is the first before to the last after', async () => {
97
+ const diff = await readSessionChangeDiff(SESSION, '/repo/a.ts', 0, 1000);
98
+ expect(diff?.status).toBe('added');
99
+ expect(diff?.oldContent).toBe('');
100
+ expect(diff?.newContent).toBe('B');
101
+ expect(diff?.unavailable).toBe(false);
102
+ expect(diff?.diff).toContain('+B');
103
+ });
104
+
105
+ test('a deleted path has an empty after side', async () => {
106
+ const diff = await readSessionChangeDiff(SESSION, '/repo/b.ts', 0, 1000);
107
+ expect(diff?.status).toBe('deleted');
108
+ expect(diff?.oldContent).toBe('X');
109
+ expect(diff?.newContent).toBe('');
110
+ });
111
+
112
+ test('a path outside the window has no diff', async () => {
113
+ expect(await readSessionChangeDiff(SESSION, '/repo/a.ts', 500, 1000)).toBeNull();
114
+ });
115
+ });
116
+
117
+ describe('readSessionChangeStats', () => {
118
+ test('counts the net pair, not each write', async () => {
119
+ const stats = await readSessionChangeStats(SESSION, 0, 1000);
120
+ expect(stats['/repo/a.ts']).toEqual({ added: 1, removed: 0 });
121
+ expect(stats['/repo/b.ts']).toEqual({ added: 0, removed: 1 });
122
+ });
123
+ });
124
+
125
+ describe('fallback', () => {
126
+ test('a session with no Kabmo journal answers the omp reader (empty here)', async () => {
127
+ expect(await readSessionChangeIndex('no-such-session')).toEqual([]);
128
+ });
129
+ });
130
+
131
+ describe('torn line', () => {
132
+ test('a partial final line does not hide the earlier records', async () => {
133
+ await fsp.appendFile(journalPath(SESSION), '{"v":1,"type":"change"');
134
+ const records = await readSessionChangeIndex(SESSION);
135
+ expect(records.length).toBe(3);
136
+ });
137
+ });