@kabmo-labs/kabmo 0.37.0 → 0.38.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 (254) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +547 -528
  3. package/dist/client/static/js/{CsvGrid-xb429wvb.js → CsvGrid-90zfbn7f.js} +1 -1
  4. package/dist/client/static/js/{DocxView-g58e0bs7.js → DocxView-vwq2rf16.js} +2 -2
  5. package/dist/client/static/js/{DrawioView-1j66avvy.js → DrawioView-bvx7eqcz.js} +1 -1
  6. package/dist/client/static/js/{ImageView-kraqkypn.js → ImageView-q6xfmbrq.js} +1 -1
  7. package/dist/client/static/js/{LayoutWrapper-85dhbn62.js → LayoutWrapper-qatdaw3n.js} +2 -2
  8. package/dist/client/static/js/{Modal-f0nfya07.js → Modal-6jx1fvfb.js} +15 -15
  9. package/dist/client/static/js/{PdfView-nddkrky9.js → PdfView-tkv2d2zs.js} +1 -1
  10. package/dist/client/static/js/{SessionsView-a595m6g1.js → SessionsView-rbnecykz.js} +1 -1
  11. package/dist/client/static/js/{SheetView-s2p4sk6b.js → SheetView-t08g8kdr.js} +1 -1
  12. package/dist/client/static/js/{SvgPreview-ppdx4yb9.js → SvgPreview-9vh6mdcp.js} +1 -1
  13. package/dist/client/static/js/{abnfDiagram-O67JEVCF-5cjzxcaq.js → abnfDiagram-O67JEVCF-bxcn33e1.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-40ggw6e8.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-k41cvjrd.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-rdcmn6ac.js} +2 -2
  20. package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-zfm2cj2a.js → classDiagram-v2-NBCMYWYE-txbmbkxv.js} +5 -5
  21. package/dist/client/static/js/{cose-bilkent-JH36ORCC-fmgpv55e.js → cose-bilkent-JH36ORCC-bxzh3qj1.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-abx5343b.js} +1 -1
  27. package/dist/client/static/js/{dagre-6A5THRUB-w370qmgj.js → dagre-6A5THRUB-baj278kt.js} +2 -2
  28. package/dist/client/static/js/{diagram-22UHCM2B-sfvfjjsy.js → diagram-22UHCM2B-vqvhdc5m.js} +7 -7
  29. package/dist/client/static/js/{diagram-3UASUU5V-3r2c8s14.js → diagram-3UASUU5V-w328rfx0.js} +2 -2
  30. package/dist/client/static/js/{diagram-ATOU4E4O-yathy97a.js → diagram-ATOU4E4O-zzcmwnm8.js} +2 -2
  31. package/dist/client/static/js/{diagram-CDSNMT55-kk437kxq.js → diagram-CDSNMT55-8yw39mmj.js} +1 -1
  32. package/dist/client/static/js/{diagram-MLGK6HIB-qdxfjjhf.js → diagram-MLGK6HIB-zgc386pv.js} +1 -1
  33. package/dist/client/static/js/{diagram-MPIPVDR6-dfqeqa1d.js → diagram-MPIPVDR6-efmvvscm.js} +1 -1
  34. package/dist/client/static/js/{dockerfile-yxrt509r.js → dockerfile-bp5dre33.js} +1 -1
  35. package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-s0b0vv4k.js → ebnfDiagram-ZINNZB2B-p66h0dzq.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-g0jjxcqd.js} +1 -1
  38. package/dist/client/static/js/{erDiagram-OPXOYQCR-agjdsm1b.js → erDiagram-OPXOYQCR-39gat96z.js} +4 -4
  39. package/dist/client/static/js/eventmodeling-NTZA5JFV-k5n61zzh.js +1 -0
  40. package/dist/client/static/js/flowDiagram-KWPJA3E3-f6jpcqyq.js +1 -0
  41. package/dist/client/static/js/{ganttDiagram-FUAMR5RP-z6ywqqc1.js → ganttDiagram-FUAMR5RP-nsjv1zt4.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-r4vnkcy3.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-83ts8zmk.js → index-0kxqzafy.js} +1 -1
  47. package/dist/client/static/js/{index-kzhtmrh0.js → index-11bdd235.js} +1 -1
  48. package/dist/client/static/js/{index-we1rpftn.js → index-1qszrvzk.js} +2 -2
  49. package/dist/client/static/js/{index-21b3zyrd.js → index-24yyj78e.js} +2 -2
  50. package/dist/client/static/js/{index-nmc30xaz.js → index-2drjp9ks.js} +1 -1
  51. package/dist/client/static/js/{index-w9zxmev3.js → index-2ndq1ngv.js} +1 -1
  52. package/dist/client/static/js/{index-0j518hqm.js → index-3az1w5f8.js} +2 -2
  53. package/dist/client/static/js/{index-8e0s9p45.js → index-50z4ek83.js} +1 -1
  54. package/dist/client/static/js/{index-sezz011q.js → index-5ebhb94w.js} +1 -1
  55. package/dist/client/static/js/{index-302d35e5.js → index-5y0bvq4q.js} +34 -34
  56. package/dist/client/static/js/{index-jpkj6vqp.js → index-6ax2z70w.js} +1 -1
  57. package/dist/client/static/js/{index-9t82sx0w.js → index-6k3e5dph.js} +2 -2
  58. package/dist/client/static/js/{index-09gx6edj.js → index-73jwm4d5.js} +1 -1
  59. package/dist/client/static/js/{index-zvfvqvn9.js → index-9wd9y6m0.js} +2 -2
  60. package/dist/client/static/js/{index-m3j5yx5f.js → index-9wtg6ywn.js} +4 -4
  61. package/dist/client/static/js/{index-j7r414hf.js → index-a74k07z2.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-cx89yk15.js → index-c15r8jd3.js} +2 -2
  65. package/dist/client/static/js/{index-49dhv8ry.js → index-da10qpns.js} +2 -2
  66. package/dist/client/static/js/{index-xearvz2z.js → index-dfgdn3fj.js} +7 -7
  67. package/dist/client/static/js/{index-0mvcbbmy.js → index-dkseg29t.js} +9 -9
  68. package/dist/client/static/js/{index-0sqa91wb.js → index-e1pr3k50.js} +2 -2
  69. package/dist/client/static/js/{index-k06med7d.js → index-fghst0kd.js} +12 -12
  70. package/dist/client/static/js/{index-vtbbfwx0.js → index-gr6jng0x.js} +2 -2
  71. package/dist/client/static/js/{index-5fn0agag.js → index-gwhx66f4.js} +1 -1
  72. package/dist/client/static/js/{index-z7qnffwj.js → index-h8h5c2r8.js} +1 -1
  73. package/dist/client/static/js/{index-qz8mbxm9.js → index-ha75kff0.js} +2 -2
  74. package/dist/client/static/js/{index-z0frtyje.js → index-hzx81cjq.js} +4 -4
  75. package/dist/client/static/js/{index-es3pt29g.js → index-k9xsvab3.js} +1 -1
  76. package/dist/client/static/js/{index-15zn3sns.js → index-nd4p98mc.js} +1 -1
  77. package/dist/client/static/js/{index-w7xbfv44.js → index-qn4pkjfh.js} +2 -2
  78. package/dist/client/static/js/{index-64mb65wx.js → index-r83kr4s5.js} +2 -2
  79. package/dist/client/static/js/{index-pd0140dx.js → index-ra38ggke.js} +1 -1
  80. package/dist/client/static/js/{index-m87yykre.js → index-rf0p3v7q.js} +5 -5
  81. package/dist/client/static/js/{index-1tyvk778.js → index-rgp69pa8.js} +1 -1
  82. package/dist/client/static/js/{index-actppd4z.js → index-rqrcw8nj.js} +2 -2
  83. package/dist/client/static/js/{index-qznwd6g8.js → index-st202rjv.js} +184 -184
  84. package/dist/client/static/js/{index-6q80csr0.js → index-t5t71dhp.js} +2 -2
  85. package/dist/client/static/js/{index-ntxm8pw3.js → index-tfsaj5d1.js} +2 -2
  86. package/dist/client/static/js/{index-059qyaj0.js → index-tv61v3t3.js} +1 -1
  87. package/dist/client/static/js/index-tzm90bsz.js +1 -0
  88. package/dist/client/static/js/{index-z6g74h7g.js → index-vb6t44dw.js} +2 -2
  89. package/dist/client/static/js/{index-t07b31ny.js → index-vnn7m9yp.js} +3 -3
  90. package/dist/client/static/js/{index-hbtk0c12.js → index-vxd4gykh.js} +2 -2
  91. package/dist/client/static/js/{index-a293pdg7.js → index-y3hdv561.js} +2 -2
  92. package/dist/client/static/js/{index-7sa2e8mn.js → index-z0cpp5bc.js} +2 -2
  93. package/dist/client/static/js/info-A6RAGUB7-3tr0y3s6.js +1 -0
  94. package/dist/client/static/js/{infoDiagram-VRGFBTTK-58bv28d4.js → infoDiagram-VRGFBTTK-e39pvm4j.js} +1 -1
  95. package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-tz6b0caw.js → ishikawaDiagram-OU5B5YK6-rqhszgvp.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-wgy5qrsv.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-b8bxn0h1.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-vb5ehtre.js} +6 -6
  102. package/dist/client/static/js/{mindmap-definition-NLK3R4M7-ra4wrts4.js → mindmap-definition-NLK3R4M7-t4p38s38.js} +2 -2
  103. package/dist/client/static/js/one-dark-pro-dhybn1ff.js +1 -0
  104. package/dist/client/static/js/one-light-bqg77ay0.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-3gp4madx.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-0cbm773h.js} +2 -2
  111. package/dist/client/static/js/{quadrantDiagram-O4NWA36T-4mhbag8n.js → quadrantDiagram-O4NWA36T-jwg7fc9f.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-38xh691s.js} +1 -1
  118. package/dist/client/static/js/{requirementDiagram-PLB6GJNP-jhfhp4eq.js → requirementDiagram-PLB6GJNP-gpddawxh.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-bx3ecv4n.js} +1 -1
  121. package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-qrfxzvp3.js → sankeyDiagram-IPEJSGJF-s6t6bbhk.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-wkq51pmb.js} +3 -3
  125. package/dist/client/static/js/{sizeCapture-INFHLROL-3hz930jg.js → sizeCapture-INFHLROL-xtwexf8k.js} +1 -1
  126. package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-2m99syxm.js → stateDiagram-v2-GCMORJYK-jnwsqa7y.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-mnkkqcbx.js} +1 -1
  129. package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-a8b7z74e.js → swimlanesDiagram-TC7HE7FX-6xmrz03n.js} +1 -1
  130. package/dist/client/static/js/{timeline-definition-EJHVYXUP-765y3ssa.js → timeline-definition-EJHVYXUP-rxq6heqh.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-dz94f57t.js} +13 -13
  135. package/dist/client/static/js/{vennDiagram-UO4OBE2U-wd51qq26.js → vennDiagram-UO4OBE2U-5mmvkhsq.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-dctdntpa.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-njyfrqkv.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 +106 -0
  174. package/src/server/lib/changes/capture-fs.server.ts +64 -0
  175. package/src/server/lib/changes/capture-runs.test.ts +136 -0
  176. package/src/server/lib/changes/capture-test-util.ts +46 -0
  177. package/src/server/lib/changes/capture-types.ts +62 -0
  178. package/src/server/lib/changes/capture.server.ts +333 -0
  179. package/src/server/lib/changes/capture.test.ts +245 -0
  180. package/src/server/lib/changes/classify-command.test.ts +172 -0
  181. package/src/server/lib/changes/classify-command.ts +272 -0
  182. package/src/server/lib/changes/classify-git.ts +88 -0
  183. package/src/server/lib/changes/classify-paths.ts +112 -0
  184. package/src/server/lib/changes/classify-tokenize.ts +185 -0
  185. package/src/server/lib/changes/journal.server.ts +183 -0
  186. package/src/server/lib/changes/journal.test.ts +125 -0
  187. package/src/server/lib/changes/merge.test.ts +137 -0
  188. package/src/server/lib/changes/paths.server.ts +37 -0
  189. package/src/server/lib/changes/purge.server.ts +32 -0
  190. package/src/server/lib/changes/reader.server.ts +322 -0
  191. package/src/server/lib/changes/reader.test.ts +137 -0
  192. package/src/server/lib/changes/records.ts +120 -0
  193. package/src/server/lib/changes/scan.server.ts +89 -0
  194. package/src/server/lib/harness/register.server.ts +3 -0
  195. package/src/server/lib/omp/rpc/event-fanout.test.ts +58 -0
  196. package/src/server/lib/omp/rpc/event-fanout.ts +19 -0
  197. package/src/server/lib/omp/rpc/manager.ts +4 -3
  198. package/src/server/lib/omp/rpc/session-registration.ts +5 -0
  199. package/src/server/lib/omp/rpc/session-registry.ts +4 -5
  200. package/src/server/lib/omp/session/delete.server.ts +4 -0
  201. package/src/server/lib/sessions/agent-token.server.test.ts +28 -5
  202. package/src/server/lib/sessions/agent-token.server.ts +42 -6
  203. package/src/server/lib/sessions/relation-access.server.test.ts +96 -0
  204. package/src/server/lib/sessions/relation-access.server.ts +71 -0
  205. package/src/server/routes/sessions/changes.ts +1 -1
  206. package/src/shared/lib/chat/ask-form/fields.ts +1 -0
  207. package/src/shared/lib/chat/ask-form/types.ts +6 -0
  208. package/src/shared/lib/chat/ask-questions.ts +56 -3
  209. package/src/shared/lib/chat/composer/delegation.ts +2 -13
  210. package/src/shared/lib/chat/composer/filter.test.ts +39 -0
  211. package/src/shared/lib/chat/composer/filter.ts +23 -13
  212. package/src/shared/lib/chat/composer/harness-model-items.test.ts +54 -0
  213. package/src/shared/lib/chat/composer/harness-model-items.ts +41 -0
  214. package/src/shared/lib/chat/composer/trigger.test.ts +50 -0
  215. package/src/shared/lib/chat/composer/trigger.ts +29 -1
  216. package/src/shared/lib/chat/timeline/changed-files.test.ts +16 -0
  217. package/src/shared/lib/chat/timeline/changed-files.ts +102 -25
  218. package/src/shared/lib/harness/catalog.ts +21 -0
  219. package/src/{client/components/workspace/model-dropdown/harness-models.test.ts → shared/lib/harness/models.test.ts} +1 -1
  220. package/src/shared/lib/models/option.ts +46 -0
  221. package/src/shared/lib/omp/config/schema.test.ts +20 -0
  222. package/src/shared/types/chat.ts +12 -6
  223. package/src/shared/types/omp/agent.ts +9 -0
  224. package/src/shared/types/session-changes.ts +4 -0
  225. package/dist/client/static/js/architecture-7GRP2DOG-7ewrw5vc.js +0 -1
  226. package/dist/client/static/js/c-wkgxb1t1.js +0 -1
  227. package/dist/client/static/js/cpp-y0t6mynx.js +0 -1
  228. package/dist/client/static/js/css-r2nhvzff.js +0 -1
  229. package/dist/client/static/js/css-tf1s0nb7.js +0 -1
  230. package/dist/client/static/js/cynefin-OW5HDTMX-yyyx3px0.js +0 -1
  231. package/dist/client/static/js/eventmodeling-NTZA5JFV-cx3ztxfz.js +0 -1
  232. package/dist/client/static/js/flowDiagram-KWPJA3E3-267mw6sv.js +0 -1
  233. package/dist/client/static/js/gitGraph-4MIJSDKK-eg9r85ak.js +0 -1
  234. package/dist/client/static/js/graphql-skw5krjr.js +0 -1
  235. package/dist/client/static/js/html-pv88ny12.js +0 -1
  236. package/dist/client/static/js/index-tcegdd2t.js +0 -1
  237. package/dist/client/static/js/info-A6RAGUB7-7qhah7fs.js +0 -1
  238. package/dist/client/static/js/javascript-4kw2j9t3.js +0 -1
  239. package/dist/client/static/js/lua-ke895s2q.js +0 -1
  240. package/dist/client/static/js/one-dark-pro-2pywnqrh.js +0 -1
  241. package/dist/client/static/js/one-light-vfgdt4wf.js +0 -1
  242. package/dist/client/static/js/packet-AYTQ26CC-ag2g7tbk.js +0 -1
  243. package/dist/client/static/js/pie-WAS4IAKB-nqcyj3x1.js +0 -1
  244. package/dist/client/static/js/radar-RG4KPBEZ-60gby7be.js +0 -1
  245. package/dist/client/static/js/railroad-74A4TZTK-cnkmcjse.js +0 -1
  246. package/dist/client/static/js/railroad-abnf-HS5TGJTU-qgfdnazd.js +0 -1
  247. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-609h6cpx.js +0 -1
  248. package/dist/client/static/js/railroad-peg-WCYAUIDC-xqnytjhg.js +0 -1
  249. package/dist/client/static/js/treeView-Q6P3EWNA-8djqab8k.js +0 -1
  250. package/dist/client/static/js/treemap-WGGIJYW6-hdztnffk.js +0 -1
  251. package/dist/client/static/js/typescript-0s2t05jj.js +0 -1
  252. package/dist/client/static/js/wardley-WFR3VGLG-avby77vv.js +0 -1
  253. package/dist/client/static/js/xml-81hxjjt4.js +0 -1
  254. /package/src/{client/components/workspace/model-dropdown/harness-models.ts → shared/lib/harness/models.ts} +0 -0
@@ -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,322 @@
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
+ /** Every change record of one session, oldest first, with display paths. */
219
+ export async function readSessionChangeIndex(sessionId: string): Promise<SessionChangeRecord[]> {
220
+ const records = await readMergedRecords(sessionId, false);
221
+ return records.map(toSessionChangeRecord);
222
+ }
223
+
224
+ /**
225
+ * The index the chat's per-run list reads.
226
+ *
227
+ * A session with no Kabmo journal falls back to the omp list, which still needs
228
+ * its "creation whose file is gone" heuristic. Once a Kabmo journal exists, the
229
+ * merged list is raw and the client's net logic drops a create-then-delete.
230
+ */
231
+ export async function readSessionChangeList(sessionId: string): Promise<SessionChangeRecord[]> {
232
+ const records = await readMergedRecords(sessionId, true);
233
+ // The omp half keeps its own heuristic for a path the Kabmo journal never
234
+ // mentions: a creation whose file is gone was created and deleted before the
235
+ // feature, and its net change is zero. A path the Kabmo journal DOES mention
236
+ // is left to the client's net logic, which sees the Kabmo delete record.
237
+ const kabmoPaths = new Set(records.filter((record) => record.store === 'kabmo').map((record) => record.path));
238
+ const gone = new Set<string>();
239
+ await Promise.all(
240
+ records
241
+ .filter((record) => record.store === 'omp' && record.before === null && !kabmoPaths.has(record.path))
242
+ .map(async (record) => {
243
+ if (!(await pathExists(record.path))) gone.add(record.path);
244
+ }),
245
+ );
246
+ return records.filter((record) => !gone.has(record.path)).map(toSessionChangeRecord);
247
+ }
248
+
249
+ /** The net change of `absolutePath` inside `[from, to]`. */
250
+ export async function readSessionChangeDiff(
251
+ sessionId: string,
252
+ absolutePath: string,
253
+ from: number,
254
+ to: number,
255
+ ): Promise<SessionChangeDiff | null> {
256
+ const records = await readMergedRecords(sessionId, false);
257
+ const inRange = records
258
+ .filter((record) => record.path === absolutePath && record.at >= from && record.at <= to)
259
+ .sort((a, b) => a.at - b.at);
260
+ if (inRange.length === 0) return null;
261
+
262
+ const first = inRange[0];
263
+ const last = inRange[inRange.length - 1];
264
+ const status = first.before === null ? 'added' : last.after === null ? 'deleted' : 'modified';
265
+ const [before, after] = await Promise.all([
266
+ resolveMergedBlob(sessionId, first.store, first.before),
267
+ resolveMergedBlob(sessionId, last.store, last.after),
268
+ ]);
269
+ if (before === undefined || after === undefined) {
270
+ return {
271
+ path: absolutePath,
272
+ displayPath: last.displayPath,
273
+ status,
274
+ oldContent: '',
275
+ newContent: '',
276
+ diff: '',
277
+ unavailable: true,
278
+ };
279
+ }
280
+ const oldContent = before ?? '';
281
+ const newContent = after ?? '';
282
+ return {
283
+ path: absolutePath,
284
+ displayPath: last.displayPath,
285
+ status,
286
+ oldContent,
287
+ newContent,
288
+ diff: unifiedDiff(last.displayPath, oldContent, newContent),
289
+ unavailable: false,
290
+ };
291
+ }
292
+
293
+ /** Net `+`/`−` line counts for every path changed inside `[from, to]`. */
294
+ export async function readSessionChangeStats(
295
+ sessionId: string,
296
+ from: number,
297
+ to: number,
298
+ ): Promise<Record<string, SessionChangeCounts>> {
299
+ const records = await readMergedRecords(sessionId, false);
300
+ const spans = new Map<string, { first: MergedRecord; last: MergedRecord }>();
301
+ for (const record of records) {
302
+ if (record.at < from || record.at > to) continue;
303
+ const span = spans.get(record.path);
304
+ if (span) span.last = record;
305
+ else spans.set(record.path, { first: record, last: record });
306
+ }
307
+
308
+ const stats: Record<string, SessionChangeCounts> = {};
309
+ await Promise.all(
310
+ [...spans].map(async ([absolutePath, { first, last }]) => {
311
+ const [before, after] = await Promise.all([
312
+ resolveMergedBlob(sessionId, first.store, first.before),
313
+ resolveMergedBlob(sessionId, last.store, last.after),
314
+ ]);
315
+ if (before === undefined || after === undefined) return;
316
+ const sides = patchSides(unifiedDiff(absolutePath, before ?? '', after ?? ''));
317
+ if (sides.additions === 0 && sides.deletions === 0) return;
318
+ stats[absolutePath] = { added: sides.additions, removed: sides.deletions };
319
+ }),
320
+ );
321
+ return stats;
322
+ }
@@ -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
+ });
@@ -0,0 +1,120 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The Kabmo change journal's line shapes.
8
+ *
9
+ * One JSON object per line, append-only. The journal is Kabmo's own record of
10
+ * what a run did to the working tree — not omp's `changes.jsonl`, which only
11
+ * sees the edit tools. The extra fields are the point: `toolCallId` joins a
12
+ * write to the call that made it, `source` says which capture layer saw it, and
13
+ * `command`/`exit` make a `bash` mutation explainable.
14
+ *
15
+ * `before`/`after` are blob keys, `null` when the file did not exist, and
16
+ * `undefined` when the content was not stored (over the cap). A `note` line is
17
+ * how the journal says "I could not capture this" instead of guessing.
18
+ */
19
+
20
+ import type { MutationOp } from '@/server/lib/changes/classify-command';
21
+
22
+ export interface JournalSessionRecord {
23
+ v: 1;
24
+ type: 'session';
25
+ at: number;
26
+ sessionId: string;
27
+ cwd: string;
28
+ omp?: string;
29
+ kabmo?: string;
30
+ }
31
+
32
+ export interface JournalRunRecord {
33
+ v: 1;
34
+ type: 'run';
35
+ phase: 'start' | 'end';
36
+ runId: string;
37
+ at: number;
38
+ }
39
+
40
+ export interface JournalCallRecord {
41
+ v: 1;
42
+ type: 'call';
43
+ at: number;
44
+ /** The run this call belongs to; absent on a journal written before runs. */
45
+ runId?: string;
46
+ /** The run's `agent_start` time, so a reader can map it to a chat run. */
47
+ runAt?: number;
48
+ toolCallId: string;
49
+ agent: string;
50
+ parent?: string;
51
+ tool: string;
52
+ intent?: string;
53
+ /** The call's arguments, truncated to a bounded JSON string. */
54
+ args?: unknown;
55
+ argsTruncated?: boolean;
56
+ }
57
+
58
+ export interface JournalChangeRecord {
59
+ v: 1;
60
+ type: 'change';
61
+ at: number;
62
+ runId?: string;
63
+ runAt?: number;
64
+ toolCallId?: string;
65
+ agent: string;
66
+ parent?: string;
67
+ tool: string;
68
+ op: MutationOp;
69
+ /** Absolute path after the write. */
70
+ path: string;
71
+ /** Absolute source path, for a rename. */
72
+ from?: string;
73
+ displayPath: string;
74
+ before: string | null | undefined;
75
+ after: string | null | undefined;
76
+ beforeMtimeMs?: number;
77
+ afterMtimeMs?: number;
78
+ source: 'tool' | 'trace' | 'scan' | 'omp-import';
79
+ command?: string;
80
+ exit?: number;
81
+ }
82
+
83
+ export interface JournalCommitRecord {
84
+ v: 1;
85
+ type: 'commit';
86
+ at: number;
87
+ sha: string;
88
+ paths: string[];
89
+ }
90
+
91
+ export interface JournalNoteRecord {
92
+ v: 1;
93
+ type: 'note';
94
+ at: number;
95
+ runId?: string;
96
+ runAt?: number;
97
+ toolCallId?: string;
98
+ reason: 'too-large' | 'opaque-command' | 'scan-budget' | 'snapshot-race' | 'unknown-tool';
99
+ detail?: string;
100
+ }
101
+
102
+ export type JournalRecord =
103
+ | JournalSessionRecord
104
+ | JournalRunRecord
105
+ | JournalCallRecord
106
+ | JournalChangeRecord
107
+ | JournalCommitRecord
108
+ | JournalNoteRecord;
109
+
110
+ /** Parse one journal line; `null` for a torn or foreign line. */
111
+ export function parseJournalLine(line: string): JournalRecord | null {
112
+ if (!line) return null;
113
+ try {
114
+ const value = JSON.parse(line) as Record<string, unknown>;
115
+ if (value?.v !== 1 || typeof value.type !== 'string') return null;
116
+ return value as unknown as JournalRecord;
117
+ } catch {
118
+ return null;
119
+ }
120
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The filesystem reconciliation pass: what an opaque command changed.
8
+ *
9
+ * A `git reset --hard`, a `bun install`, a shell script — the classifier cannot
10
+ * name their targets from `argv`, so the journal takes a cheap snapshot before
11
+ * and after and journals the delta. The snapshot is `git status --porcelain`
12
+ * plus the content of the dirty paths (bounded), because a path that was
13
+ * already dirty has no HEAD version to fall back on.
14
+ *
15
+ * A path that was CLEAN at start has an exact before side: `git show HEAD:path`.
16
+ * A path that was dirty at start is read at snapshot time, so a command that
17
+ * rewrites it is still caught. A path outside the repo, or a repo that is not
18
+ * there, answers `null` and the caller writes a note instead of a guess.
19
+ */
20
+
21
+ import path from 'node:path';
22
+ import { childEnv } from '@/server/lib/fs/child-env';
23
+
24
+ const SCAN_BUDGET_FILES = 200;
25
+ const GIT_TIMEOUT_MS = 5_000;
26
+
27
+ export interface GitScan {
28
+ root: string;
29
+ /** Absolute path → content at snapshot time, for paths that were dirty. */
30
+ dirty: Map<string, string | null>;
31
+ /** The budget cut the dirty set; the caller says so rather than pretending. */
32
+ truncated: boolean;
33
+ }
34
+
35
+ async function runGit(cwd: string, args: string[]): Promise<string | null> {
36
+ try {
37
+ const proc = Bun.spawn(['git', '-C', cwd, ...args], {
38
+ env: childEnv(),
39
+ stdout: 'pipe',
40
+ stderr: 'ignore',
41
+ signal: AbortSignal.timeout(GIT_TIMEOUT_MS),
42
+ });
43
+ const [text, code] = await Promise.all([new Response(proc.stdout).text(), proc.exited]);
44
+ return code === 0 ? text : null;
45
+ } catch {
46
+ return null;
47
+ }
48
+ }
49
+
50
+ /** `XY <path>\0` entries; a rename's second entry (the old path) is skipped. */
51
+ function parseStatus(output: string): string[] {
52
+ const paths: string[] = [];
53
+ for (const entry of output.split('\0')) {
54
+ if (entry.length < 4 || entry[2] !== ' ') continue;
55
+ paths.push(entry.slice(3));
56
+ }
57
+ return paths;
58
+ }
59
+
60
+ async function readText(absolute: string): Promise<string | null> {
61
+ try {
62
+ return await Bun.file(absolute).text();
63
+ } catch {
64
+ return null;
65
+ }
66
+ }
67
+
68
+ /** Snapshot the repo's dirty set and its content; `null` outside a repo. */
69
+ export async function takeGitScan(cwd: string): Promise<GitScan | null> {
70
+ const root = (await runGit(cwd, ['rev-parse', '--show-toplevel']))?.trim();
71
+ if (!root) return null;
72
+ const status = await runGit(root, ['status', '--porcelain=v1', '-z']);
73
+ if (status === null) return null;
74
+
75
+ const entries = parseStatus(status);
76
+ const dirty = new Map<string, string | null>();
77
+ for (const relative of entries.slice(0, SCAN_BUDGET_FILES)) {
78
+ const absolute = path.resolve(root, relative);
79
+ dirty.set(absolute, await readText(absolute));
80
+ }
81
+ return { root, dirty, truncated: entries.length > SCAN_BUDGET_FILES };
82
+ }
83
+
84
+ /** The content at HEAD for a path that was clean; `null` when it did not exist. */
85
+ export async function readHeadContent(root: string, absolute: string): Promise<string | null> {
86
+ const relative = path.relative(root, absolute);
87
+ if (!relative || relative.startsWith('..') || path.isAbsolute(relative)) return null;
88
+ return runGit(root, ['show', `HEAD:${relative.replaceAll('\\', '/')}`]);
89
+ }