@kabmo-labs/kabmo 0.36.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 (292) 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-1h3bcak7.js → CsvGrid-90zfbn7f.js} +2 -2
  4. package/dist/client/static/js/{DocxView-ndca8jch.js → DocxView-vwq2rf16.js} +2 -2
  5. package/dist/client/static/js/{DrawioView-kpzd6y0b.js → DrawioView-bvx7eqcz.js} +2 -2
  6. package/dist/client/static/js/{ImageView-79prn3dg.js → ImageView-q6xfmbrq.js} +1 -1
  7. package/dist/client/static/js/{LayoutWrapper-v2wn2sb2.js → LayoutWrapper-qatdaw3n.js} +2 -2
  8. package/dist/client/static/js/{Modal-99j0zz3z.js → Modal-6jx1fvfb.js} +15 -15
  9. package/dist/client/static/js/{PdfView-2rjd87ay.js → PdfView-tkv2d2zs.js} +1 -1
  10. package/dist/client/static/js/{SessionsView-t7f3s71b.js → SessionsView-rbnecykz.js} +1 -1
  11. package/dist/client/static/js/{SheetView-ehb976st.js → SheetView-t08g8kdr.js} +4 -4
  12. package/dist/client/static/js/{SvgPreview-de2bbba6.js → SvgPreview-9vh6mdcp.js} +1 -1
  13. package/dist/client/static/js/{abnfDiagram-O67JEVCF-nx9jzn7m.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-170v67rr.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-16q285n1.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-rn3qt45h.js → c4Diagram-YGBWAQC7-rdcmn6ac.js} +2 -2
  20. package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-r26wg74e.js → classDiagram-v2-NBCMYWYE-txbmbkxv.js} +5 -5
  21. package/dist/client/static/js/{cose-bilkent-JH36ORCC-82kwe7ha.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-tcxdn6pa.js → cynefinDiagram-VND7K2PF-abx5343b.js} +1 -1
  27. package/dist/client/static/js/{dagre-6A5THRUB-g833ata3.js → dagre-6A5THRUB-baj278kt.js} +2 -2
  28. package/dist/client/static/js/{diagram-22UHCM2B-f1fq8xec.js → diagram-22UHCM2B-vqvhdc5m.js} +7 -7
  29. package/dist/client/static/js/{diagram-3UASUU5V-6j2w016f.js → diagram-3UASUU5V-w328rfx0.js} +2 -2
  30. package/dist/client/static/js/{diagram-ATOU4E4O-6t2qxsk4.js → diagram-ATOU4E4O-zzcmwnm8.js} +2 -2
  31. package/dist/client/static/js/{diagram-CDSNMT55-7abar8s7.js → diagram-CDSNMT55-8yw39mmj.js} +1 -1
  32. package/dist/client/static/js/{diagram-MLGK6HIB-s68rgy16.js → diagram-MLGK6HIB-zgc386pv.js} +1 -1
  33. package/dist/client/static/js/{diagram-MPIPVDR6-azgkm6w8.js → diagram-MPIPVDR6-efmvvscm.js} +1 -1
  34. package/dist/client/static/js/{dockerfile-47e33kqa.js → dockerfile-bp5dre33.js} +1 -1
  35. package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-esrjz750.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-fhr4b4jj.js → elk-276RUBZZ-g0jjxcqd.js} +1 -1
  38. package/dist/client/static/js/{erDiagram-OPXOYQCR-5r3fmdnz.js → erDiagram-OPXOYQCR-39gat96z.js} +4 -4
  39. package/dist/client/static/js/{erlang-bh5cbm8m.js → erlang-6m6tpt72.js} +1 -1
  40. package/dist/client/static/js/eventmodeling-NTZA5JFV-k5n61zzh.js +1 -0
  41. package/dist/client/static/js/flowDiagram-KWPJA3E3-f6jpcqyq.js +1 -0
  42. package/dist/client/static/js/{ganttDiagram-FUAMR5RP-j4pf6rdn.js → ganttDiagram-FUAMR5RP-nsjv1zt4.js} +2 -2
  43. package/dist/client/static/js/gitGraph-4MIJSDKK-2gf053bx.js +1 -0
  44. package/dist/client/static/js/{gitGraphDiagram-X574FWY7-x5epk0gr.js → gitGraphDiagram-X574FWY7-r4vnkcy3.js} +2 -2
  45. package/dist/client/static/js/graphql-p4cskvad.js +1 -0
  46. package/dist/client/static/js/html-f26r6vv5.js +1 -0
  47. package/dist/client/static/js/{index-c1j0xb0w.js → index-0kxqzafy.js} +1 -1
  48. package/dist/client/static/js/{index-3kgrcaq1.js → index-11bdd235.js} +1 -1
  49. package/dist/client/static/js/{index-b48p8d1j.js → index-1qszrvzk.js} +2 -2
  50. package/dist/client/static/js/{index-3vdmwpbh.js → index-24yyj78e.js} +2 -2
  51. package/dist/client/static/js/{index-63c6t75t.js → index-2drjp9ks.js} +1 -1
  52. package/dist/client/static/js/{index-d2km9egp.js → index-2ndq1ngv.js} +4 -4
  53. package/dist/client/static/js/{index-0j518hqm.js → index-3az1w5f8.js} +2 -2
  54. package/dist/client/static/js/{index-ye450a7z.js → index-50z4ek83.js} +1 -1
  55. package/dist/client/static/js/{index-60ceydzn.js → index-5ebhb94w.js} +1 -1
  56. package/dist/client/static/js/{index-ctgefatv.js → index-5y0bvq4q.js} +34 -34
  57. package/dist/client/static/js/{index-40ve7zzv.js → index-6ax2z70w.js} +1 -1
  58. package/dist/client/static/js/{index-9t82sx0w.js → index-6k3e5dph.js} +2 -2
  59. package/dist/client/static/js/{index-6xzfta4b.js → index-73jwm4d5.js} +1 -1
  60. package/dist/client/static/js/{index-8cy3x2y8.js → index-7fdp9c7m.js} +2 -2
  61. package/dist/client/static/js/{index-zvfvqvn9.js → index-9wd9y6m0.js} +2 -2
  62. package/dist/client/static/js/{index-q5t4sy22.js → index-9wtg6ywn.js} +4 -4
  63. package/dist/client/static/js/{index-nws03exw.js → index-a74k07z2.js} +2 -2
  64. package/dist/client/static/js/{index-982jyfsb.js → index-ashpbfqv.js} +2 -2
  65. package/dist/client/static/js/{index-zp73zexp.js → index-b9b2nwdd.js} +2 -2
  66. package/dist/client/static/js/{index-h1e1abpt.js → index-c15r8jd3.js} +2 -2
  67. package/dist/client/static/js/{index-5rzk1226.js → index-da10qpns.js} +2 -2
  68. package/dist/client/static/js/{index-ky0prc71.js → index-dfgdn3fj.js} +9 -9
  69. package/dist/client/static/js/{index-c09a5s1n.js → index-dkseg29t.js} +9 -9
  70. package/dist/client/static/js/{index-w3n97x4b.js → index-dt7e1328.js} +2 -2
  71. package/dist/client/static/js/{index-sar2ggde.js → index-e1pr3k50.js} +2 -2
  72. package/dist/client/static/js/{index-0b1kwsam.js → index-fghst0kd.js} +32 -32
  73. package/dist/client/static/js/{index-af24nes6.js → index-gbfg0anm.js} +2 -2
  74. package/dist/client/static/js/{index-vtbbfwx0.js → index-gr6jng0x.js} +2 -2
  75. package/dist/client/static/js/{index-44qrckd2.js → index-gwhx66f4.js} +1 -1
  76. package/dist/client/static/js/{index-55pqvh82.js → index-h7pn9qw6.js} +2 -2
  77. package/dist/client/static/js/{index-97t3mv1v.js → index-h8h5c2r8.js} +1 -1
  78. package/dist/client/static/js/{index-v5t761a1.js → index-ha75kff0.js} +2 -2
  79. package/dist/client/static/js/{index-ydvfc9td.js → index-hzx81cjq.js} +4 -4
  80. package/dist/client/static/js/{index-be6gevq8.js → index-k9xsvab3.js} +1 -1
  81. package/dist/client/static/js/{index-v8qd8ypc.js → index-nd4p98mc.js} +2 -2
  82. package/dist/client/static/js/{index-dmgawfhw.js → index-qkscve6n.js} +2 -2
  83. package/dist/client/static/js/{index-w7xbfv44.js → index-qn4pkjfh.js} +2 -2
  84. package/dist/client/static/js/{index-zdtsvnpq.js → index-r83kr4s5.js} +2 -2
  85. package/dist/client/static/js/{index-htt8qxm3.js → index-ra38ggke.js} +1 -1
  86. package/dist/client/static/js/{index-skm6k5w2.js → index-rf0p3v7q.js} +5 -5
  87. package/dist/client/static/js/{index-7r1hw2gd.js → index-rgp69pa8.js} +1 -1
  88. package/dist/client/static/js/{index-8e15fzax.js → index-rqrcw8nj.js} +2 -2
  89. package/dist/client/static/js/{index-63jbb4kf.js → index-sa9cp6km.js} +2 -2
  90. package/dist/client/static/js/{index-75haaj8g.js → index-st202rjv.js} +184 -184
  91. package/dist/client/static/js/{index-mm1rf116.js → index-t5t71dhp.js} +2 -2
  92. package/dist/client/static/js/{index-ktvbsj6w.js → index-tfsaj5d1.js} +2 -2
  93. package/dist/client/static/js/{index-k1xt92h4.js → index-tv61v3t3.js} +1 -1
  94. package/dist/client/static/js/index-tzm90bsz.js +1 -0
  95. package/dist/client/static/js/{index-z6g74h7g.js → index-vb6t44dw.js} +2 -2
  96. package/dist/client/static/js/{index-pyx8n25s.js → index-vnn7m9yp.js} +3 -3
  97. package/dist/client/static/js/{index-5kjpacvd.js → index-vxd4gykh.js} +2 -2
  98. package/dist/client/static/js/{index-r8pckaqe.js → index-xya34x4v.js} +2 -2
  99. package/dist/client/static/js/{index-a293pdg7.js → index-y3hdv561.js} +2 -2
  100. package/dist/client/static/js/{index-9gf8b73w.js → index-z0cpp5bc.js} +2 -2
  101. package/dist/client/static/js/info-A6RAGUB7-3tr0y3s6.js +1 -0
  102. package/dist/client/static/js/{infoDiagram-VRGFBTTK-ktc8nb8g.js → infoDiagram-VRGFBTTK-e39pvm4j.js} +1 -1
  103. package/dist/client/static/js/ini-cg0a5wm3.js +1 -0
  104. package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-n3dk6227.js → ishikawaDiagram-OU5B5YK6-rqhszgvp.js} +2 -2
  105. package/dist/client/static/js/java-vcck089n.js +1 -0
  106. package/dist/client/static/js/javascript-nyf39d5r.js +1 -0
  107. package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-f0p1h8qn.js → journeyDiagram-ZHPQQLJL-wgy5qrsv.js} +3 -3
  108. package/dist/client/static/js/jsx-ht9zyzwa.js +1 -0
  109. package/dist/client/static/js/{julia-73zjh2w6.js → julia-237yk557.js} +1 -1
  110. package/dist/client/static/js/{kanban-definition-PNTS6WVX-7jdt7dv1.js → kanban-definition-PNTS6WVX-b8bxn0h1.js} +3 -3
  111. package/dist/client/static/js/lua-86fjqj8v.js +1 -0
  112. package/dist/client/static/js/markdown-gwmsh53r.js +1 -0
  113. package/dist/client/static/js/{mermaid.core-e8rzrjt9.js → mermaid.core-vb5ehtre.js} +6 -6
  114. package/dist/client/static/js/{mindmap-definition-NLK3R4M7-7shv6ge0.js → mindmap-definition-NLK3R4M7-t4p38s38.js} +3 -3
  115. package/dist/client/static/js/one-dark-pro-dhybn1ff.js +1 -0
  116. package/dist/client/static/js/one-light-bqg77ay0.js +1 -0
  117. package/dist/client/static/js/packet-AYTQ26CC-xbsyjzrh.js +1 -0
  118. package/dist/client/static/js/{pegDiagram-GJSIUBJH-17ak2zx3.js → pegDiagram-GJSIUBJH-3gp4madx.js} +1 -1
  119. package/dist/client/static/js/{perl-8z46dmze.js → perl-dvz4y1tb.js} +1 -1
  120. package/dist/client/static/js/{php-6qvnp2t6.js → php-n6y7dzhm.js} +1 -1
  121. package/dist/client/static/js/pie-WAS4IAKB-j2tpz0cs.js +1 -0
  122. package/dist/client/static/js/{pieDiagram-5QR66LMP-at4x1g4q.js → pieDiagram-5QR66LMP-0cbm773h.js} +2 -2
  123. package/dist/client/static/js/properties-mzvvbqg5.js +1 -0
  124. package/dist/client/static/js/python-3w64wsyd.js +1 -0
  125. package/dist/client/static/js/{quadrantDiagram-O4NWA36T-apzhwrn4.js → quadrantDiagram-O4NWA36T-jwg7fc9f.js} +1 -1
  126. package/dist/client/static/js/r-32re2zwb.js +1 -0
  127. package/dist/client/static/js/radar-RG4KPBEZ-m3tsyfv0.js +1 -0
  128. package/dist/client/static/js/railroad-74A4TZTK-5p202a4q.js +1 -0
  129. package/dist/client/static/js/railroad-abnf-HS5TGJTU-hj0y9tgn.js +1 -0
  130. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-8c5dct8f.js +1 -0
  131. package/dist/client/static/js/railroad-peg-WCYAUIDC-3tx8z65q.js +1 -0
  132. package/dist/client/static/js/{railroadDiagram-XR7U4H2S-rw8cj5f3.js → railroadDiagram-XR7U4H2S-38xh691s.js} +1 -1
  133. package/dist/client/static/js/{requirementDiagram-PLB6GJNP-qyrse7mb.js → requirementDiagram-PLB6GJNP-gpddawxh.js} +4 -4
  134. package/dist/client/static/js/{ruby-qy8mhstq.js → ruby-7zye3g0e.js} +1 -1
  135. package/dist/client/static/js/{rust-fpshqnk0.js → rust-bx3ecv4n.js} +1 -1
  136. package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-254qr59q.js → sankeyDiagram-IPEJSGJF-s6t6bbhk.js} +1 -1
  137. package/dist/client/static/js/{sass-kbwea482.js → sass-m0h9yzfb.js} +1 -1
  138. package/dist/client/static/js/{scss-zphrqp25.js → scss-2pwwfkvn.js} +1 -1
  139. package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-y9xjxfc5.js → sequenceDiagram-PO4LG4MO-wkq51pmb.js} +3 -3
  140. package/dist/client/static/js/{sizeCapture-INFHLROL-sc5e60t3.js → sizeCapture-INFHLROL-xtwexf8k.js} +1 -1
  141. package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-r134s4xr.js → stateDiagram-v2-GCMORJYK-jnwsqa7y.js} +3 -3
  142. package/dist/client/static/js/{svelte-mwtx07d9.js → svelte-x8f8c8hq.js} +1 -1
  143. package/dist/client/static/js/{swimlanes-2SLR337P-xc7rbawt.js → swimlanes-2SLR337P-mnkkqcbx.js} +1 -1
  144. package/dist/client/static/js/swimlanesDiagram-TC7HE7FX-6xmrz03n.js +8 -0
  145. package/dist/client/static/js/{timeline-definition-EJHVYXUP-cgjd8shk.js → timeline-definition-EJHVYXUP-rxq6heqh.js} +2 -2
  146. package/dist/client/static/js/treeView-Q6P3EWNA-mf0rb2yv.js +1 -0
  147. package/dist/client/static/js/treemap-WGGIJYW6-0x5gf06b.js +1 -0
  148. package/dist/client/static/js/typescript-5nmrzgkj.js +1 -0
  149. package/dist/client/static/js/{usecaseDiagram-POWQR4AR-9qsmjhm6.js → usecaseDiagram-POWQR4AR-dz94f57t.js} +13 -13
  150. package/dist/client/static/js/{vennDiagram-UO4OBE2U-4grw9awx.js → vennDiagram-UO4OBE2U-5mmvkhsq.js} +1 -1
  151. package/dist/client/static/js/{vue-j8vb9d7r.js → vue-myjjd0gd.js} +1 -1
  152. package/dist/client/static/js/wardley-WFR3VGLG-x7ej8dms.js +1 -0
  153. package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-8gxy0wat.js → wardleyDiagram-VNRHLVJA-dctdntpa.js} +1 -1
  154. package/dist/client/static/js/xml-3dd1pter.js +1 -0
  155. package/dist/client/static/js/{xychartDiagram-PMCCYNJV-5sh7tdrx.js → xychartDiagram-PMCCYNJV-njyfrqkv.js} +2 -2
  156. package/dist/client/static/js/yaml-yssayv8a.js +1 -0
  157. package/package.json +1 -1
  158. package/src/client/components/common/ComposerPicker.tsx +24 -12
  159. package/src/client/components/common/ComposerTextarea.tsx +1 -0
  160. package/src/client/components/layout/session-sidebar/scheduler-modal/ModelFields.tsx +1 -1
  161. package/src/client/components/settings/apply-side-effects.test.ts +5 -4
  162. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +1 -1
  163. package/src/client/components/workspace/chat-timeline/index.tsx +3 -3
  164. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FormAsk.test.tsx +210 -0
  165. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FormAsk.tsx +342 -0
  166. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/LooseFieldAsk.tsx +44 -0
  167. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/OrphanAsks.test.tsx +44 -1
  168. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/OrphanAsks.tsx +10 -5
  169. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/PluginPendingInteractions.test.ts +1 -0
  170. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +19 -0
  171. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/form-picks.ts +52 -0
  172. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.test.ts +2 -2
  173. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +53 -4
  174. package/src/client/components/workspace/model-dropdown/index.tsx +1 -1
  175. package/src/client/components/workspace/model-dropdown/use-catalog.ts +3 -32
  176. package/src/client/data/settings/omp-schema.json +55 -1
  177. package/src/client/hooks/chat/composer/harness-model-picker.ts +84 -0
  178. package/src/client/hooks/chat/composer/index.ts +26 -6
  179. package/src/client/hooks/chat/timeline/ask-frames.test.ts +80 -7
  180. package/src/client/hooks/chat/timeline/ask-frames.ts +95 -21
  181. package/src/client/hooks/models/use-harnesses.ts +15 -2
  182. package/src/client/hooks/ui/icon-style.ts +7 -4
  183. package/src/client/hooks/ui/style-attributes.test.ts +11 -11
  184. package/src/client/hooks/ui/surface-style.ts +8 -5
  185. package/src/server/lib/assets/shell-attributes.server.ts +12 -9
  186. package/src/server/lib/assets/shell-attributes.test.ts +18 -13
  187. package/src/server/lib/auth/agent-gate.server.ts +64 -0
  188. package/src/server/lib/auth/agent-tree-gate.test.ts +121 -0
  189. package/src/server/lib/auth/guard.test.ts +18 -18
  190. package/src/server/lib/auth/guard.ts +15 -11
  191. package/src/server/lib/auth/handover-guard.test.ts +1 -1
  192. package/src/server/lib/changes/attach.server.ts +57 -0
  193. package/src/server/lib/changes/attach.test.ts +94 -0
  194. package/src/server/lib/changes/blobs.server.ts +52 -0
  195. package/src/server/lib/changes/capture-bash.server.ts +106 -0
  196. package/src/server/lib/changes/capture-fs.server.ts +64 -0
  197. package/src/server/lib/changes/capture-runs.test.ts +136 -0
  198. package/src/server/lib/changes/capture-test-util.ts +46 -0
  199. package/src/server/lib/changes/capture-types.ts +62 -0
  200. package/src/server/lib/changes/capture.server.ts +333 -0
  201. package/src/server/lib/changes/capture.test.ts +245 -0
  202. package/src/server/lib/changes/classify-command.test.ts +172 -0
  203. package/src/server/lib/changes/classify-command.ts +272 -0
  204. package/src/server/lib/changes/classify-git.ts +88 -0
  205. package/src/server/lib/changes/classify-paths.ts +112 -0
  206. package/src/server/lib/changes/classify-tokenize.ts +185 -0
  207. package/src/server/lib/changes/journal.server.ts +183 -0
  208. package/src/server/lib/changes/journal.test.ts +125 -0
  209. package/src/server/lib/changes/merge.test.ts +137 -0
  210. package/src/server/lib/changes/paths.server.ts +37 -0
  211. package/src/server/lib/changes/purge.server.ts +32 -0
  212. package/src/server/lib/changes/reader.server.ts +322 -0
  213. package/src/server/lib/changes/reader.test.ts +137 -0
  214. package/src/server/lib/changes/records.ts +120 -0
  215. package/src/server/lib/changes/scan.server.ts +89 -0
  216. package/src/server/lib/harness/register.server.ts +3 -0
  217. package/src/server/lib/omp/rpc/event-fanout.test.ts +58 -0
  218. package/src/server/lib/omp/rpc/event-fanout.ts +19 -0
  219. package/src/server/lib/omp/rpc/manager.ts +4 -3
  220. package/src/server/lib/omp/rpc/session-registration.ts +5 -0
  221. package/src/server/lib/omp/rpc/session-registry.ts +4 -5
  222. package/src/server/lib/omp/session/delete.server.ts +4 -0
  223. package/src/server/lib/sessions/agent-token.server.test.ts +28 -5
  224. package/src/server/lib/sessions/agent-token.server.ts +42 -6
  225. package/src/server/lib/sessions/relation-access.server.test.ts +96 -0
  226. package/src/server/lib/sessions/relation-access.server.ts +71 -0
  227. package/src/server/routes/sessions/changes.ts +1 -1
  228. package/src/shared/lib/chat/ask-form/fields.ts +1 -0
  229. package/src/shared/lib/chat/ask-form/types.ts +6 -0
  230. package/src/shared/lib/chat/ask-questions.ts +56 -3
  231. package/src/shared/lib/chat/composer/delegation.ts +2 -13
  232. package/src/shared/lib/chat/composer/filter.test.ts +39 -0
  233. package/src/shared/lib/chat/composer/filter.ts +23 -13
  234. package/src/shared/lib/chat/composer/harness-model-items.test.ts +54 -0
  235. package/src/shared/lib/chat/composer/harness-model-items.ts +41 -0
  236. package/src/shared/lib/chat/composer/trigger.test.ts +50 -0
  237. package/src/shared/lib/chat/composer/trigger.ts +29 -1
  238. package/src/shared/lib/chat/timeline/changed-files.test.ts +16 -0
  239. package/src/shared/lib/chat/timeline/changed-files.ts +102 -25
  240. package/src/shared/lib/harness/catalog.ts +21 -0
  241. package/src/{client/components/workspace/model-dropdown/harness-models.test.ts → shared/lib/harness/models.test.ts} +1 -1
  242. package/src/shared/lib/icons/icon-paint-authority.ts +5 -3
  243. package/src/shared/lib/models/option.ts +46 -0
  244. package/src/shared/lib/omp/config/schema.test.ts +20 -0
  245. package/src/shared/lib/theme/icon-style.test.ts +8 -5
  246. package/src/shared/lib/theme/icon-style.ts +15 -7
  247. package/src/shared/lib/theme/surface-style.test.ts +8 -5
  248. package/src/shared/lib/theme/surface-style.ts +17 -7
  249. package/src/shared/lib/workspace/sidebar-style.test.ts +7 -8
  250. package/src/shared/lib/workspace/sidebar-style.ts +7 -8
  251. package/src/shared/types/chat.ts +12 -6
  252. package/src/shared/types/omp/agent.ts +9 -0
  253. package/src/shared/types/session-changes.ts +4 -0
  254. package/dist/client/static/js/architecture-7GRP2DOG-aqft2erp.js +0 -1
  255. package/dist/client/static/js/c-wkgxb1t1.js +0 -1
  256. package/dist/client/static/js/cpp-y0t6mynx.js +0 -1
  257. package/dist/client/static/js/css-r2nhvzff.js +0 -1
  258. package/dist/client/static/js/css-tf1s0nb7.js +0 -1
  259. package/dist/client/static/js/cynefin-OW5HDTMX-v2sz60t6.js +0 -1
  260. package/dist/client/static/js/eventmodeling-NTZA5JFV-8qbefe4m.js +0 -1
  261. package/dist/client/static/js/flowDiagram-KWPJA3E3-krsvgcq7.js +0 -1
  262. package/dist/client/static/js/gitGraph-4MIJSDKK-9bx1a38k.js +0 -1
  263. package/dist/client/static/js/graphql-xnpp5gn9.js +0 -1
  264. package/dist/client/static/js/html-pv88ny12.js +0 -1
  265. package/dist/client/static/js/index-dh1vd0d9.js +0 -1
  266. package/dist/client/static/js/info-A6RAGUB7-j51t7jhh.js +0 -1
  267. package/dist/client/static/js/ini-ygfyhprj.js +0 -1
  268. package/dist/client/static/js/java-gm49vw59.js +0 -1
  269. package/dist/client/static/js/javascript-4kw2j9t3.js +0 -1
  270. package/dist/client/static/js/jsx-ksxw1byz.js +0 -1
  271. package/dist/client/static/js/lua-53gzb9bx.js +0 -1
  272. package/dist/client/static/js/markdown-tk3cd3vs.js +0 -1
  273. package/dist/client/static/js/one-dark-pro-39bt34v9.js +0 -1
  274. package/dist/client/static/js/one-light-xec0sehr.js +0 -1
  275. package/dist/client/static/js/packet-AYTQ26CC-n83gfj2g.js +0 -1
  276. package/dist/client/static/js/pie-WAS4IAKB-5c5pctwz.js +0 -1
  277. package/dist/client/static/js/properties-2tcybqjk.js +0 -1
  278. package/dist/client/static/js/python-qph3dntq.js +0 -1
  279. package/dist/client/static/js/r-gd26x93y.js +0 -1
  280. package/dist/client/static/js/radar-RG4KPBEZ-52e5n99a.js +0 -1
  281. package/dist/client/static/js/railroad-74A4TZTK-44nqxxpy.js +0 -1
  282. package/dist/client/static/js/railroad-abnf-HS5TGJTU-25jxgwg7.js +0 -1
  283. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-64pqpf2y.js +0 -1
  284. package/dist/client/static/js/railroad-peg-WCYAUIDC-0p5sxzpx.js +0 -1
  285. package/dist/client/static/js/swimlanesDiagram-TC7HE7FX-kdcdamkj.js +0 -8
  286. package/dist/client/static/js/treeView-Q6P3EWNA-8j14nnd1.js +0 -1
  287. package/dist/client/static/js/treemap-WGGIJYW6-esf993kk.js +0 -1
  288. package/dist/client/static/js/typescript-0s2t05jj.js +0 -1
  289. package/dist/client/static/js/wardley-WFR3VGLG-v4dxm2sb.js +0 -1
  290. package/dist/client/static/js/xml-0py2vkw7.js +0 -1
  291. package/dist/client/static/js/yaml-vghdz0f0.js +0 -1
  292. /package/src/{client/components/workspace/model-dropdown/harness-models.ts → shared/lib/harness/models.ts} +0 -0
@@ -0,0 +1,88 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The `git` branch of the command classifier.
8
+ *
9
+ * `git` is the one verb whose effect depends on a subcommand, and the split is
10
+ * deliberate: a read-only subcommand (`status`, `diff`, `log`) is not a
11
+ * mutation; a path restore (`checkout --`, `restore`) names its files; and a
12
+ * subcommand that rewrites the tree in ways argv cannot name (`reset --hard`,
13
+ * `clean`, `stash`) is opaque, so the scan pass answers instead of a guess.
14
+ */
15
+
16
+ import type { CommandMutation, CommandPlan, MutationOp } from '@/server/lib/changes/classify-command';
17
+ import { isSpecialFile, nonFlagArgs, resolvePath } from '@/server/lib/changes/classify-paths';
18
+
19
+ /** `git` subcommands that never write the working tree. */
20
+ const GIT_READ_ONLY: Record<string, true> = {
21
+ status: true, diff: true, log: true, show: true, branch: true,
22
+ 'rev-parse': true, 'ls-files': true, remote: true, config: true,
23
+ blame: true, describe: true, tag: true, shortlog: true, reflog: true,
24
+ grep: true, 'ls-tree': true, 'cat-file': true, 'show-ref': true,
25
+ 'for-each-ref': true, add: true, commit: true, fetch: true, push: true,
26
+ init: true, clone: true, help: true, version: true, 'count-objects': true,
27
+ fsck: true,
28
+ };
29
+
30
+ /** `git` subcommands that rewrite the working tree in ways argv cannot name. */
31
+ const GIT_OPAQUE: Record<string, true> = {
32
+ clean: true, reset: true, stash: true, apply: true, am: true,
33
+ rebase: true, merge: true, pull: true, 'cherry-pick': true, revert: true,
34
+ bisect: true, worktree: true, submodule: true, 'filter-branch': true,
35
+ };
36
+
37
+ export function classifyGit(
38
+ args: readonly string[],
39
+ cwd: string,
40
+ home: string,
41
+ mutations: CommandMutation[],
42
+ opaque: boolean,
43
+ readOnly: boolean,
44
+ ): CommandPlan {
45
+ const sub = args[0];
46
+ if (!sub) return { mutations, opaque, readOnly };
47
+ if (GIT_READ_ONLY[sub] === true) return { mutations, opaque, readOnly };
48
+
49
+ const add = (op: MutationOp, raw: string, from?: string): void => {
50
+ if (isSpecialFile(raw)) return;
51
+ const resolved = resolvePath(cwd, home, raw);
52
+ if (!resolved) {
53
+ opaque = true;
54
+ return;
55
+ }
56
+ mutations.push(from ? { op, path: resolved, from } : { op, path: resolved });
57
+ readOnly = false;
58
+ };
59
+
60
+ if (sub === 'mv') {
61
+ const files = nonFlagArgs(args.slice(1));
62
+ if (files.length < 2) return { mutations, opaque: true, readOnly: false };
63
+ const from = resolvePath(cwd, home, files[0]);
64
+ const to = resolvePath(cwd, home, files[files.length - 1]);
65
+ if (!from || !to) return { mutations, opaque: true, readOnly: false };
66
+ mutations.push({ op: 'rename', path: to, from });
67
+ return { mutations, opaque, readOnly: false };
68
+ }
69
+ if (sub === 'rm') {
70
+ for (const file of nonFlagArgs(args.slice(1))) add('delete', file);
71
+ return { mutations, opaque, readOnly };
72
+ }
73
+ if (sub === 'checkout' || sub === 'restore') {
74
+ const separator = args.indexOf('--');
75
+ if (separator !== -1) {
76
+ for (const file of args.slice(separator + 1)) add('update', file);
77
+ return { mutations, opaque, readOnly };
78
+ }
79
+ if (sub === 'restore') {
80
+ for (const file of nonFlagArgs(args.slice(1))) add('update', file);
81
+ return { mutations, opaque, readOnly };
82
+ }
83
+ return { mutations, opaque: true, readOnly: false };
84
+ }
85
+ if (GIT_OPAQUE[sub] === true) return { mutations, opaque: true, readOnly: false };
86
+
87
+ return { mutations, opaque: true, readOnly: false };
88
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Path and operand helpers shared by the command classifier and its `git`
8
+ * branch.
9
+ *
10
+ * `resolvePath` is the security-relevant one: a glob is refused rather than
11
+ * expanded, because the shell expands it and a guess would journal a file that
12
+ * was never touched. The caller marks the command opaque instead.
13
+ */
14
+
15
+ import path from 'node:path';
16
+ import type { CommandMutation } from '@/server/lib/changes/classify-command';
17
+
18
+ /** Device files a redirect may name; they are not working-tree mutations. */
19
+ const SPECIAL_FILES: Record<string, true> = {
20
+ '/dev/null': true,
21
+ '/dev/stdout': true,
22
+ '/dev/stderr': true,
23
+ '/dev/tty': true,
24
+ };
25
+
26
+ /** A device file a redirect may name; it is not a working-tree mutation. */
27
+ export function isSpecialFile(raw: string): boolean {
28
+ return SPECIAL_FILES[raw] === true;
29
+ }
30
+
31
+ /** Resolve a shell path against the session cwd; `null` for a glob or empty. */
32
+ export function resolvePath(cwd: string, home: string, raw: string): string | null {
33
+ if (!raw) return null;
34
+ // A truncated command (the transcript's `…`) or an unexpanded variable
35
+ // (`$M/$D.md`) names no real path; the command is opaque instead.
36
+ if (raw.includes('…') || raw.includes('$')) return null;
37
+ if (raw.includes('*') || raw.includes('?') || raw.includes('[')) return null;
38
+ let value = raw;
39
+ if (value === '~') value = home;
40
+ else if (value.startsWith('~/')) value = path.join(home, value.slice(2));
41
+ const resolved = path.isAbsolute(value) ? path.normalize(value) : path.resolve(cwd, value);
42
+ return SPECIAL_FILES[resolved] === true ? null : resolved;
43
+ }
44
+
45
+ /** Arguments that are not flags; `--` ends flag parsing. */
46
+ export function nonFlagArgs(args: readonly string[]): string[] {
47
+ const out: string[] = [];
48
+ let end = false;
49
+ for (const arg of args) {
50
+ if (!end && arg === '--') {
51
+ end = true;
52
+ continue;
53
+ }
54
+ if (!end && arg.startsWith('-') && arg !== '-') continue;
55
+ out.push(arg);
56
+ }
57
+ return out;
58
+ }
59
+
60
+ export function flagValue(args: readonly string[], flag: string): string | undefined {
61
+ const index = args.indexOf(flag);
62
+ if (index === -1) return undefined;
63
+ const value = args[index + 1];
64
+ return value && !value.startsWith('-') ? value : undefined;
65
+ }
66
+
67
+ /** `sed`/`perl` file operands: the script is the first non-flag argument. */
68
+ export function scriptFiles(args: readonly string[]): string[] {
69
+ const files: string[] = [];
70
+ let scriptSeen = false;
71
+ for (let i = 0; i < args.length; i++) {
72
+ const arg = args[i];
73
+ if (arg === '-e' || arg === '--expression' || arg === '-f' || arg === '--file') {
74
+ i++;
75
+ scriptSeen = true;
76
+ continue;
77
+ }
78
+ if (arg.startsWith('-')) continue;
79
+ if (!scriptSeen) {
80
+ scriptSeen = true;
81
+ continue;
82
+ }
83
+ files.push(arg);
84
+ }
85
+ return files;
86
+ }
87
+
88
+ export function truncateFiles(args: readonly string[]): string[] {
89
+ const files: string[] = [];
90
+ for (let i = 0; i < args.length; i++) {
91
+ const arg = args[i];
92
+ if (arg === '-s' || arg === '--size' || arg === '-r' || arg === '--reference') {
93
+ i++;
94
+ continue;
95
+ }
96
+ if (arg.startsWith('-')) continue;
97
+ files.push(arg);
98
+ }
99
+ return files;
100
+ }
101
+
102
+ export function dedupe(mutations: CommandMutation[]): CommandMutation[] {
103
+ const seen = new Set<string>();
104
+ const out: CommandMutation[] = [];
105
+ for (const mutation of mutations) {
106
+ const key = `${mutation.op}:${mutation.from ?? ''}:${mutation.path}`;
107
+ if (seen.has(key)) continue;
108
+ seen.add(key);
109
+ out.push(mutation);
110
+ }
111
+ return out;
112
+ }
@@ -0,0 +1,185 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * A small shell tokenizer, enough to find a command's words and its output
8
+ * redirects.
9
+ *
10
+ * It is not a shell: no expansion, no substitution, no heredoc body. It exists
11
+ * because omp's trace models `argv` but not redirections (measured: `bun test >
12
+ * /tmp/n1.log 2>&1` yields only `and_or`/`pipeline`/`simple`/`word` nodes), and
13
+ * a redirect is a file write the journal must see.
14
+ *
15
+ * `2>&1` and `>&2` are fd duplications, not file targets, so they become a
16
+ * `fddup` operator the splitter drops. `2>` and `2>>` are output redirects on
17
+ * descriptor 2 and keep their target.
18
+ */
19
+
20
+ export interface Token {
21
+ kind: 'word' | 'op';
22
+ value: string;
23
+ }
24
+
25
+ export interface SimpleCommand {
26
+ words: string[];
27
+ redirects: { op: string; target: string }[];
28
+ }
29
+
30
+ /** Tokenize a shell script into words and operators. */
31
+ export function tokenizeCommand(script: string): Token[] {
32
+ const tokens: Token[] = [];
33
+ let word = '';
34
+ let hasWord = false;
35
+ const flush = (): void => {
36
+ if (!hasWord) return;
37
+ tokens.push({ kind: 'word', value: word });
38
+ word = '';
39
+ hasWord = false;
40
+ };
41
+
42
+ for (let i = 0; i < script.length; i++) {
43
+ const ch = script[i];
44
+ if (ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r') {
45
+ flush();
46
+ continue;
47
+ }
48
+ if (ch === '#' && !hasWord) {
49
+ while (i < script.length && script[i] !== '\n') i++;
50
+ continue;
51
+ }
52
+ if (ch === "'") {
53
+ hasWord = true;
54
+ i++;
55
+ while (i < script.length && script[i] !== "'") word += script[i++];
56
+ continue;
57
+ }
58
+ if (ch === '"') {
59
+ hasWord = true;
60
+ i++;
61
+ while (i < script.length && script[i] !== '"') {
62
+ if (script[i] === '\\' && i + 1 < script.length) {
63
+ i++;
64
+ word += script[i++];
65
+ } else {
66
+ word += script[i++];
67
+ }
68
+ }
69
+ continue;
70
+ }
71
+ if (ch === '\\' && i + 1 < script.length) {
72
+ hasWord = true;
73
+ word += script[++i];
74
+ continue;
75
+ }
76
+ // `2>&1` / `>&2` are fd duplications, not file targets.
77
+ if (!hasWord && ch === '2' && script[i + 1] === '>' && script[i + 2] === '&') {
78
+ let j = i + 3;
79
+ while (j < script.length && /[0-9-]/.test(script[j])) j++;
80
+ tokens.push({ kind: 'op', value: 'fddup' });
81
+ i = j - 1;
82
+ continue;
83
+ }
84
+ if (!hasWord && ch === '&' && script[i + 1] === '>') {
85
+ if (script[i + 2] === '&') {
86
+ tokens.push({ kind: 'op', value: '&>>' });
87
+ i += 2;
88
+ } else {
89
+ tokens.push({ kind: 'op', value: '&>' });
90
+ i += 1;
91
+ }
92
+ continue;
93
+ }
94
+ // `2>` / `2>>` — the `2` is a descriptor, not an argument.
95
+ if (ch === '2' && script[i + 1] === '>' && (!hasWord || word === '2')) {
96
+ if (word === '2') {
97
+ word = '';
98
+ hasWord = false;
99
+ }
100
+ const op = script[i + 2] === '>' ? '2>>' : '2>';
101
+ tokens.push({ kind: 'op', value: op });
102
+ i += op.length - 1;
103
+ continue;
104
+ }
105
+ if (ch === '|' || ch === '&' || ch === ';' || ch === '<' || ch === '>') {
106
+ flush();
107
+ const two = script.slice(i, i + 2);
108
+ if (two === '&&' || two === '||' || two === '>>' || two === '<<' || two === '>&') {
109
+ tokens.push({ kind: 'op', value: two });
110
+ i++;
111
+ continue;
112
+ }
113
+ tokens.push({ kind: 'op', value: ch });
114
+ continue;
115
+ }
116
+ hasWord = true;
117
+ word += ch;
118
+ }
119
+ flush();
120
+ return tokens;
121
+ }
122
+
123
+ /**
124
+ * Drop heredoc BODIES, keeping the command line that opens them.
125
+ *
126
+ * A heredoc body is data, not shell: `cat > f <<'EOF'` followed by lines that
127
+ * happen to contain `>` or `rm` must not be parsed as commands. Measured on a
128
+ * real session: an `AGENTS.md` heredoc whose prose named a file produced a
129
+ * phantom `cat > Panduan` mutation. The delimiter line itself is dropped too.
130
+ */
131
+ export function stripHeredocs(script: string): string {
132
+ const lines = script.split('\n');
133
+ const out: string[] = [];
134
+ let pending: string | null = null;
135
+ let stripTabs = false;
136
+ for (const line of lines) {
137
+ if (pending !== null) {
138
+ const candidate = stripTabs ? line.replace(/^\t+/, '') : line;
139
+ if (candidate === pending) pending = null;
140
+ out.push('');
141
+ continue;
142
+ }
143
+ out.push(line);
144
+ const match = /<<-?\s*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/.exec(line);
145
+ if (match?.[2]) {
146
+ pending = match[2];
147
+ stripTabs = line.includes('<<-');
148
+ }
149
+ }
150
+ return out.join('\n');
151
+ }
152
+
153
+ /** Split tokens into simple commands, keeping each command's output redirects. */
154
+ export function splitCommands(tokens: Token[]): SimpleCommand[] {
155
+ const commands: SimpleCommand[] = [];
156
+ let current: SimpleCommand = { words: [], redirects: [] };
157
+ const push = (): void => {
158
+ if (current.words.length > 0 || current.redirects.length > 0) commands.push(current);
159
+ current = { words: [], redirects: [] };
160
+ };
161
+
162
+ for (let i = 0; i < tokens.length; i++) {
163
+ const token = tokens[i];
164
+ if (token.kind === 'word') {
165
+ current.words.push(token.value);
166
+ continue;
167
+ }
168
+ if (token.value === ';' || token.value === '&&' || token.value === '||' || token.value === '|' || token.value === '&') {
169
+ push();
170
+ continue;
171
+ }
172
+ if (token.value === 'fddup') continue;
173
+ if (token.value === '<' || token.value === '<<' || token.value === '>&') {
174
+ i++;
175
+ continue;
176
+ }
177
+ const target = tokens[i + 1];
178
+ if (target?.kind === 'word') {
179
+ current.redirects.push({ op: token.value, target: target.value });
180
+ i++;
181
+ }
182
+ }
183
+ push();
184
+ return commands;
185
+ }
@@ -0,0 +1,183 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The Kabmo change journal writer: one append-only JSONL per session.
8
+ *
9
+ * Every append goes through one promise chain, so two parallel subagents cannot
10
+ * interleave a half line. A failed append is logged and swallowed — the journal
11
+ * is an annotation on a run, and a full disk must not kill the run it reports
12
+ * on. A torn final line is tolerated by the reader, the same rule omp's own
13
+ * journal follows.
14
+ *
15
+ * The directory is created lazily, on the first record: a session that never
16
+ * calls a tool writes nothing, which is what keeps a test that spawns a fake
17
+ * child from touching the developer's real `~/.kabmo`.
18
+ *
19
+ * Rotation: when the journal passes 20 MB it is renamed to
20
+ * `changes.<epoch>.jsonl` and a fresh `changes.jsonl` starts with a new header.
21
+ * The reader reads every `changes*.jsonl` in name order, so a rotated file is
22
+ * older than the current one and the sequence is preserved.
23
+ */
24
+
25
+ import { appendFile, mkdir, rename, stat } from 'node:fs/promises';
26
+ import path from 'node:path';
27
+ import { blobsDir, journalPath, sessionChangesDir } from '@/server/lib/changes/paths.server';
28
+ import { writeBlob } from '@/server/lib/changes/blobs.server';
29
+ import type { MutationOp } from '@/server/lib/changes/classify-command';
30
+ import type {
31
+ JournalCallRecord,
32
+ JournalChangeRecord,
33
+ JournalNoteRecord,
34
+ JournalRecord,
35
+ JournalRunRecord,
36
+ JournalSessionRecord,
37
+ } from '@/server/lib/changes/records';
38
+
39
+ const MAX_JOURNAL_BYTES = 20 * 1024 * 1024;
40
+ const MAX_ARGS_BYTES = 4 * 1024;
41
+
42
+ export interface ChangeInput {
43
+ at: number;
44
+ runId?: string;
45
+ runAt?: number;
46
+ toolCallId?: string;
47
+ agent: string;
48
+ parent?: string;
49
+ tool: string;
50
+ op: MutationOp;
51
+ path: string;
52
+ from?: string;
53
+ displayPath: string;
54
+ /** Full text before the write; `null` absent, `undefined` not stored. */
55
+ before: string | null | undefined;
56
+ /** Full text after the write; `null` absent, `undefined` not stored. */
57
+ after: string | null | undefined;
58
+ beforeMtimeMs?: number;
59
+ afterMtimeMs?: number;
60
+ source: JournalChangeRecord['source'];
61
+ command?: string;
62
+ exit?: number;
63
+ }
64
+
65
+ export class ChangeJournal {
66
+ readonly dir: string;
67
+ readonly #startedAt = Date.now();
68
+ #chain: Promise<void> = Promise.resolve();
69
+ #ready: Promise<void> | null = null;
70
+ #closed = false;
71
+ #bytes = 0;
72
+
73
+ constructor(
74
+ readonly sessionId: string,
75
+ readonly cwd: string,
76
+ ) {
77
+ this.dir = sessionChangesDir(sessionId);
78
+ }
79
+
80
+ recordCall(input: Omit<JournalCallRecord, 'v' | 'type'>): Promise<void> {
81
+ const args = truncateArgs(input.args);
82
+ return this.#enqueue(() => this.#appendLine({ v: 1, type: 'call', ...input, ...args }));
83
+ }
84
+
85
+ recordChange(input: ChangeInput): Promise<void> {
86
+ return this.#enqueue(async () => {
87
+ const before = input.before === null || input.before === undefined
88
+ ? input.before
89
+ : await this.#blob(input.before);
90
+ const after = input.after === null || input.after === undefined
91
+ ? input.after
92
+ : await this.#blob(input.after);
93
+ if (before === undefined || after === undefined) {
94
+ await this.#appendLine({
95
+ v: 1,
96
+ type: 'note',
97
+ at: input.at,
98
+ ...(input.toolCallId ? { toolCallId: input.toolCallId } : {}),
99
+ reason: 'too-large',
100
+ detail: input.path,
101
+ });
102
+ }
103
+ await this.#appendLine({ v: 1, type: 'change', ...input, before, after });
104
+ });
105
+ }
106
+
107
+ recordNote(input: Omit<JournalNoteRecord, 'v' | 'type'>): Promise<void> {
108
+ return this.#enqueue(() => this.#appendLine({ v: 1, type: 'note', ...input }));
109
+ }
110
+
111
+ recordRun(input: Omit<JournalRunRecord, 'v' | 'type'>): Promise<void> {
112
+ return this.#enqueue(() => this.#appendLine({ v: 1, type: 'run', ...input }));
113
+ }
114
+
115
+ flush(): Promise<void> {
116
+ return this.#chain;
117
+ }
118
+
119
+ close(): void {
120
+ this.#closed = true;
121
+ }
122
+
123
+ #enqueue(task: () => Promise<void>): Promise<void> {
124
+ this.#chain = this.#chain.then(task).catch((error: unknown) => {
125
+ console.error(`[changes] journal append failed for ${this.sessionId}:`, error);
126
+ });
127
+ return this.#chain;
128
+ }
129
+
130
+ async #blob(text: string): Promise<string | null | undefined> {
131
+ const key = await writeBlob(blobsDir(this.sessionId), text);
132
+ return key === null ? undefined : key;
133
+ }
134
+
135
+ async #appendLine(record: JournalRecord): Promise<void> {
136
+ if (this.#closed) return;
137
+ await this.#ensure();
138
+ const line = `${JSON.stringify(record)}\n`;
139
+ await appendFile(journalPath(this.sessionId), line);
140
+ this.#bytes += Buffer.byteLength(line);
141
+ if (this.#bytes >= MAX_JOURNAL_BYTES) await this.#rotate();
142
+ }
143
+
144
+ #ensure(): Promise<void> {
145
+ if (!this.#ready) this.#ready = this.#init();
146
+ return this.#ready;
147
+ }
148
+
149
+ async #init(): Promise<void> {
150
+ await mkdir(this.dir, { recursive: true, mode: 0o700 });
151
+ await mkdir(blobsDir(this.sessionId), { recursive: true, mode: 0o700 });
152
+ const file = journalPath(this.sessionId);
153
+ const info = await stat(file).catch(() => null);
154
+ this.#bytes = info?.size ?? 0;
155
+ if (!info) await this.#writeHeader(file);
156
+ }
157
+
158
+ async #writeHeader(file: string): Promise<void> {
159
+ const header: JournalSessionRecord = {
160
+ v: 1,
161
+ type: 'session',
162
+ at: this.#startedAt,
163
+ sessionId: this.sessionId,
164
+ cwd: this.cwd,
165
+ };
166
+ const line = `${JSON.stringify(header)}\n`;
167
+ await Bun.write(file, line);
168
+ this.#bytes = Buffer.byteLength(line);
169
+ }
170
+
171
+ async #rotate(): Promise<void> {
172
+ const file = journalPath(this.sessionId);
173
+ await rename(file, path.join(this.dir, `changes.${Date.now()}.jsonl`));
174
+ await this.#writeHeader(file);
175
+ }
176
+ }
177
+
178
+ function truncateArgs(args: unknown): { args?: unknown; argsTruncated?: boolean } {
179
+ if (args === undefined) return {};
180
+ const json = JSON.stringify(args);
181
+ if (json.length <= MAX_ARGS_BYTES) return { args };
182
+ return { args: json.slice(0, MAX_ARGS_BYTES), argsTruncated: true };
183
+ }
@@ -0,0 +1,125 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The journal writer: one append-only JSONL, content-addressed blobs, and the
8
+ * two rules a reader depends on — a header on the first line and a torn line
9
+ * that never poisons the rest.
10
+ */
11
+
12
+ import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
13
+ import * as fsp from 'node:fs/promises';
14
+ import * as os from 'node:os';
15
+ import * as path from 'node:path';
16
+ import { ChangeJournal } from '@/server/lib/changes/journal.server';
17
+ import { blobsDir, journalPath } from '@/server/lib/changes/paths.server';
18
+ import { parseJournalLine, type JournalRecord } from '@/server/lib/changes/records';
19
+
20
+ let dataDir = '';
21
+ let original: string | undefined;
22
+
23
+ beforeAll(async () => {
24
+ original = Bun.env.KABMO_DATA_DIR;
25
+ dataDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'kabmo-changes-'));
26
+ Bun.env.KABMO_DATA_DIR = dataDir;
27
+ });
28
+
29
+ afterAll(async () => {
30
+ if (original === undefined) delete Bun.env.KABMO_DATA_DIR;
31
+ else Bun.env.KABMO_DATA_DIR = original;
32
+ await fsp.rm(dataDir, { recursive: true, force: true });
33
+ });
34
+
35
+ async function readLines(sessionId: string): Promise<JournalRecord[]> {
36
+ const text = await Bun.file(journalPath(sessionId)).text();
37
+ return text.split('\n').map(parseJournalLine).filter((line): line is JournalRecord => line !== null);
38
+ }
39
+
40
+ describe('ChangeJournal', () => {
41
+ test('writes a session header, then the change with blob keys', async () => {
42
+ const journal = new ChangeJournal('sess-write', '/repo');
43
+ await journal.recordChange({
44
+ at: 100,
45
+ agent: 'Main',
46
+ tool: 'edit',
47
+ op: 'update',
48
+ path: '/repo/a.ts',
49
+ displayPath: 'a.ts',
50
+ before: 'old',
51
+ after: 'new',
52
+ source: 'tool',
53
+ });
54
+ await journal.flush();
55
+
56
+ const lines = await readLines('sess-write');
57
+ expect(lines[0]?.type).toBe('session');
58
+ const change = lines[1];
59
+ expect(change?.type).toBe('change');
60
+ if (change?.type !== 'change') throw new Error('expected a change record');
61
+ expect(change.before).toMatch(/^3-/);
62
+ expect(change.after).toMatch(/^3-/);
63
+ expect(change.before).not.toBe(change.after);
64
+
65
+ const blobs = await fsp.readdir(blobsDir('sess-write'));
66
+ expect(blobs.length).toBe(2);
67
+ });
68
+
69
+ test('reuses a blob for the same content', async () => {
70
+ const journal = new ChangeJournal('sess-dedupe', '/repo');
71
+ await journal.recordChange({
72
+ at: 1, agent: 'Main', tool: 'edit', op: 'update', path: '/repo/a.ts',
73
+ displayPath: 'a.ts', before: 'same', after: 'one', source: 'tool',
74
+ });
75
+ await journal.recordChange({
76
+ at: 2, agent: 'Main', tool: 'edit', op: 'update', path: '/repo/b.ts',
77
+ displayPath: 'b.ts', before: 'same', after: 'two', source: 'tool',
78
+ });
79
+ await journal.flush();
80
+
81
+ const blobs = await fsp.readdir(blobsDir('sess-dedupe'));
82
+ // 'same' once, 'one' once, 'two' once.
83
+ expect(blobs.length).toBe(3);
84
+ });
85
+
86
+ test('truncates a large call argument bag and says so', async () => {
87
+ const journal = new ChangeJournal('sess-call', '/repo');
88
+ await journal.recordCall({
89
+ at: 1,
90
+ toolCallId: 'c1',
91
+ agent: 'Main',
92
+ tool: 'bash',
93
+ args: { command: 'x'.repeat(5000) },
94
+ });
95
+ await journal.flush();
96
+
97
+ const call = (await readLines('sess-call')).find((line) => line.type === 'call');
98
+ expect(call?.type).toBe('call');
99
+ if (call?.type !== 'call') throw new Error('expected a call record');
100
+ expect(call.argsTruncated).toBe(true);
101
+ expect(typeof call.args).toBe('string');
102
+ });
103
+
104
+ test('records a note without inventing a change', async () => {
105
+ const journal = new ChangeJournal('sess-note', '/repo');
106
+ await journal.recordNote({ at: 1, toolCallId: 'c1', reason: 'opaque-command', detail: 'bun test' });
107
+ await journal.flush();
108
+
109
+ const lines = await readLines('sess-note');
110
+ expect(lines.map((line) => line.type)).toEqual(['session', 'note']);
111
+ });
112
+
113
+ test('a torn final line is skipped by the parser', async () => {
114
+ const journal = new ChangeJournal('sess-torn', '/repo');
115
+ await journal.recordChange({
116
+ at: 1, agent: 'Main', tool: 'edit', op: 'create', path: '/repo/a.ts',
117
+ displayPath: 'a.ts', before: null, after: 'A', source: 'tool',
118
+ });
119
+ await journal.flush();
120
+ await fsp.appendFile(journalPath('sess-torn'), '{"v":1,"type":"change"');
121
+
122
+ const lines = await readLines('sess-torn');
123
+ expect(lines.map((line) => line.type)).toEqual(['session', 'change']);
124
+ });
125
+ });