@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,121 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The gate with a password armed and an agent token in hand.
8
+ *
9
+ * This is the case that could not pass before: the scope was the id in the path,
10
+ * compared to the token's session, so a coordinator could not read its worker
11
+ * and a worker could not tell its coordinator. The measured three-worker run
12
+ * only worked because the gate returns before the token check when
13
+ * authentication is off — which is exactly the configuration a real install
14
+ * does not use.
15
+ */
16
+
17
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
18
+ import fs from 'node:fs';
19
+ import os from 'node:os';
20
+ import path from 'node:path';
21
+
22
+ import { authGate, initAuth } from '@/server/lib/auth/guard';
23
+ import { createAgentToken, rememberAgentToken } from '@/server/lib/sessions/agent-token.server';
24
+ import { ensureSessionRelationsSchema } from '@/server/lib/sessions/schema.server';
25
+ import { getDb } from '@/server/db.server';
26
+ import { isolateDb, releaseDb } from '@/test-support/isolated-db';
27
+
28
+ let dataDir: string | null = null;
29
+ let tokenC = '';
30
+ let tokenW1 = '';
31
+
32
+ async function relation(sessionId: string, parentSessionId: string | null): Promise<void> {
33
+ const db = await getDb();
34
+ await db.run(
35
+ 'INSERT INTO session_relations (session_id, parent_session_id, created_at) VALUES (?, ?, ?)',
36
+ [sessionId, parentSessionId, Date.now()],
37
+ );
38
+ }
39
+
40
+ function request(pathname: string, token?: string): Request {
41
+ return new Request(`http://localhost${pathname}`, {
42
+ headers: token ? { authorization: `Bearer ${token}` } : {},
43
+ });
44
+ }
45
+
46
+ beforeEach(async () => {
47
+ await isolateDb();
48
+ await ensureSessionRelationsSchema(await getDb());
49
+ dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kabmo-tree-gate-'));
50
+ Bun.env.KABMO_DATA_DIR = dataDir;
51
+ globalThis.__kabmoAgentTokens = undefined;
52
+
53
+ await relation('C', null);
54
+ await relation('W1', 'C');
55
+ await relation('W2', 'C');
56
+
57
+ tokenC = createAgentToken();
58
+ tokenW1 = createAgentToken();
59
+ await rememberAgentToken('C', tokenC);
60
+ await rememberAgentToken('W1', tokenW1);
61
+
62
+ await initAuth('correct-horse');
63
+ });
64
+
65
+ afterEach(async () => {
66
+ await initAuth(null);
67
+ globalThis.__kabmoAgentTokens = undefined;
68
+ delete Bun.env.KABMO_DATA_DIR;
69
+ if (dataDir) fs.rmSync(dataDir, { recursive: true, force: true });
70
+ dataDir = null;
71
+ await releaseDb();
72
+ });
73
+
74
+ describe('an agent token reaches its tree', () => {
75
+ test('a coordinator may read its worker', async () => {
76
+ expect(await authGate(request('/api/chat/W1', tokenC))).toBeUndefined();
77
+ expect(await authGate(request('/api/agent/W1', tokenC))).toBeUndefined();
78
+ });
79
+
80
+ test('a worker may tell its coordinator', async () => {
81
+ expect(await authGate(request('/api/agent/C', tokenW1))).toBeUndefined();
82
+ expect(await authGate(request('/api/sessions/C/relations', tokenW1))).toBeUndefined();
83
+ });
84
+
85
+ test('any token may spawn under itself', async () => {
86
+ expect(await authGate(request('/api/sessions/spawn', tokenW1))).toBeUndefined();
87
+ });
88
+
89
+ test('a token minted by another process is accepted from the table', async () => {
90
+ // Simulates the peer instance: the cache is empty, the row is not.
91
+ globalThis.__kabmoAgentTokens = undefined;
92
+ expect(await authGate(request('/api/chat/W1', tokenC))).toBeUndefined();
93
+ });
94
+ });
95
+
96
+ describe('an agent token reaches nothing else', () => {
97
+ test('a sibling is refused with a typed code', async () => {
98
+ const response = await authGate(request('/api/chat/W2', tokenW1));
99
+ expect(response?.status).toBe(403);
100
+ expect(await response?.json()).toEqual({
101
+ error: 'That session is not in this session’s tree',
102
+ code: 'session_not_in_tree',
103
+ });
104
+ });
105
+
106
+ test('an unknown session answers the same refusal, not a 404', async () => {
107
+ // Identical to the sibling case on purpose: the gate must not become an id
108
+ // oracle for an agent process.
109
+ const response = await authGate(request('/api/chat/does-not-exist', tokenW1));
110
+ expect(response?.status).toBe(403);
111
+ expect((await response?.json()) as { code?: string }).toEqual(expect.objectContaining({ code: 'session_not_in_tree' }));
112
+ });
113
+
114
+ test('a token is not a UI credential', async () => {
115
+ expect((await authGate(request('/api/settings', tokenC)))?.status).toBe(401);
116
+ });
117
+
118
+ test('a request with no token is still a 401', async () => {
119
+ expect((await authGate(request('/api/chat/W1')))?.status).toBe(401);
120
+ });
121
+ });
@@ -134,10 +134,10 @@ describe('authentication is per run, never inherited from disk', () => {
134
134
  // REAL file into a throwaway data directory and asserts that the gate ignores
135
135
  // it — a stubbed file reader would prove nothing about that.
136
136
 
137
- test('no password means the gate lets everything through', () => {
137
+ test('no password means the gate lets everything through', async () => {
138
138
  expect(isAuthEnabled()).toBe(false);
139
139
  const request = new Request('http://localhost/api/settings');
140
- expect(authGate(request)).toBeUndefined();
140
+ expect(await authGate(request)).toBeUndefined();
141
141
  });
142
142
 
143
143
  test('a stored secret alone does NOT enable authentication', async () => {
@@ -153,7 +153,7 @@ describe('authentication is per run, never inherited from disk', () => {
153
153
  }));
154
154
 
155
155
  expect(isAuthEnabled()).toBe(false);
156
- expect(authGate(new Request('http://localhost/api/settings'))).toBeUndefined();
156
+ expect(await authGate(new Request('http://localhost/api/settings'))).toBeUndefined();
157
157
  });
158
158
 
159
159
  test('initAuth turns the gate on, and it rejects a request with no cookie', async () => {
@@ -161,7 +161,7 @@ describe('authentication is per run, never inherited from disk', () => {
161
161
  await initAuth('correct-horse');
162
162
 
163
163
  expect(isAuthEnabled()).toBe(true);
164
- const response = authGate(new Request('http://localhost/api/settings'));
164
+ const response = await authGate(new Request('http://localhost/api/settings'));
165
165
  expect(response?.status).toBe(401);
166
166
  });
167
167
 
@@ -176,16 +176,16 @@ describe('authentication is per run, never inherited from disk', () => {
176
176
  useTempDataDir();
177
177
  await initAuth('correct-horse');
178
178
 
179
- expect(authGate(new Request('http://localhost/api/updates/android'))).toBeUndefined();
180
- expect(authGate(new Request('http://localhost/api/updates/ios'))).toBeUndefined();
181
- expect(authGate(new Request('http://localhost/api/updates/desktop?kind=macos'))?.status).toBe(401);
179
+ expect(await authGate(new Request('http://localhost/api/updates/android'))).toBeUndefined();
180
+ expect(await authGate(new Request('http://localhost/api/updates/ios'))).toBeUndefined();
181
+ expect((await authGate(new Request('http://localhost/api/updates/desktop?kind=macos')))?.status).toBe(401);
182
182
  });
183
183
 
184
184
  test('a document request is redirected to the login screen, not answered 401', async () => {
185
185
  useTempDataDir();
186
186
  await initAuth('correct-horse');
187
187
 
188
- const response = authGate(new Request('http://localhost/', { headers: { accept: 'text/html' } }));
188
+ const response = await authGate(new Request('http://localhost/', { headers: { accept: 'text/html' } }));
189
189
  // A document has no body to render an error into, so it is sent to the
190
190
  // screen that can ask for the password.
191
191
  expect(response?.status).toBe(302);
@@ -224,7 +224,7 @@ describe('authentication is per run, never inherited from disk', () => {
224
224
  });
225
225
 
226
226
  // The token is good before the revocation…
227
- expect(authGate(withCookie())).toBeUndefined();
227
+ expect(await authGate(withCookie())).toBeUndefined();
228
228
 
229
229
  const result = await revokeAllSessions();
230
230
  expect(result.revoked).toBe(true);
@@ -232,7 +232,7 @@ describe('authentication is per run, never inherited from disk', () => {
232
232
  // …and dead after it, without the password having changed. This is the only
233
233
  // revocation a stateless token admits, and it is what makes "sign out
234
234
  // everywhere" possible at all.
235
- expect(authGate(withCookie())?.status).toBe(401);
235
+ expect((await authGate(withCookie()))?.status).toBe(401);
236
236
 
237
237
  // The new secret is persisted, so the revocation survives a restart rather
238
238
  // than being undone by the old secret being read back from disk.
@@ -256,7 +256,7 @@ describe('authentication is per run, never inherited from disk', () => {
256
256
  headers: { cookie: `omp_session=${fresh}` },
257
257
  });
258
258
  // Revoking everywhere must not lock out the browser that asked for it.
259
- expect(authGate(request)).toBeUndefined();
259
+ expect(await authGate(request)).toBeUndefined();
260
260
  });
261
261
  });
262
262
 
@@ -267,7 +267,7 @@ describe('a session outlives the process that minted it', () => {
267
267
  const first = loadAuthConfig()!;
268
268
  const token = sessionTokenFor(first);
269
269
  const request = new Request('http://localhost/api/settings', { headers: { cookie: `omp_session=${token}` } });
270
- expect(authGate(request)).toBeUndefined();
270
+ expect(await authGate(request)).toBeUndefined();
271
271
 
272
272
  // The second boot, in the same process: exactly what `bun --hot` does on
273
273
  // every save, and what restarting a daemon does. The secret is read back
@@ -281,7 +281,7 @@ describe('a session outlives the process that minted it', () => {
281
281
  // every session — the persisted secret never delivered its documented "a
282
282
  // restart keeps its sessions".
283
283
  expect(second.credentialKey).toBe(first.credentialKey);
284
- expect(authGate(request)).toBeUndefined();
284
+ expect(await authGate(request)).toBeUndefined();
285
285
  });
286
286
 
287
287
  test('a restart with a DIFFERENT password revokes them', async () => {
@@ -293,7 +293,7 @@ describe('a session outlives the process that minted it', () => {
293
293
  // Stable for an unchanged password, still bound to it: replacing the
294
294
  // password is exactly what a session's death must follow.
295
295
  const request = new Request('http://localhost/api/settings', { headers: { cookie: `omp_session=${token}` } });
296
- expect(authGate(request)?.status).toBe(401);
296
+ expect((await authGate(request))?.status).toBe(401);
297
297
  });
298
298
  });
299
299
 
@@ -303,7 +303,7 @@ describe('the login screen is only for a visitor without a session', () => {
303
303
  await initAuth('correct-horse');
304
304
  const token = sessionTokenFor(loadAuthConfig()!);
305
305
 
306
- const response = authGate(new Request('http://localhost/login', {
306
+ const response = await authGate(new Request('http://localhost/login', {
307
307
  headers: { cookie: `omp_session=${token}`, accept: 'text/html' },
308
308
  }));
309
309
 
@@ -319,14 +319,14 @@ describe('the login screen is only for a visitor without a session', () => {
319
319
 
320
320
  // `/login` stays public — it IS the way in — so the gate must let it
321
321
  // through to the shell that renders the form.
322
- expect(authGate(new Request('http://localhost/login', { headers: { accept: 'text/html' } }))).toBeUndefined();
322
+ expect(await authGate(new Request('http://localhost/login', { headers: { accept: 'text/html' } }))).toBeUndefined();
323
323
  });
324
324
 
325
- test('with authentication off there is nothing to log into', () => {
325
+ test('with authentication off there is nothing to log into', async () => {
326
326
  useTempDataDir();
327
327
  // No password armed: every request counts as authenticated, which makes
328
328
  // `/login` a URL with no meaning rather than a screen.
329
- const response = authGate(new Request('http://localhost/login', { headers: { accept: 'text/html' } }));
329
+ const response = await authGate(new Request('http://localhost/login', { headers: { accept: 'text/html' } }));
330
330
  expect(response?.status).toBe(302);
331
331
  expect(response?.headers.get('location')).toBe('/');
332
332
  });
@@ -29,7 +29,8 @@
29
29
 
30
30
  import { hashPassword, deriveCredentialKey, readSessionSecret, writeSessionSecret, type ActiveAuthConfig } from '@/server/lib/auth/config';
31
31
  import { readSessionCookie, verifySessionToken } from '@/server/lib/auth/token';
32
- import { agentTokenScopeForPath, bearerToken, verifyAgentToken } from '@/server/lib/sessions/agent-token.server';
32
+ import { agentGate } from '@/server/lib/auth/agent-gate.server';
33
+ import { bearerToken } from '@/server/lib/sessions/agent-token.server';
33
34
  import { verifyDeviceToken, readDeviceCookie } from '@/server/lib/connect/devices.server';
34
35
  import { rememberClientAddress } from '@/server/lib/auth/client-address';
35
36
  import type { CredentialHandover } from '@/shared/lib/auth/handover';
@@ -275,7 +276,13 @@ function rejectionResponse(pathname: string, wantsHtml: boolean): Response {
275
276
  }
276
277
 
277
278
  /**
278
- * The gate itself. Returns a `Response` to reject, or `undefined` to continue.
279
+ * The gate itself. Resolves to a `Response` to reject, or `undefined` to
280
+ * continue.
281
+ *
282
+ * Async because the agent-token rule is a tree question, and answering it needs
283
+ * one indexed read of `session_relations`. The gate still never touches the
284
+ * request body: the measured Elysia trap is about passing the context to a
285
+ * helper, not about awaiting.
279
286
  *
280
287
  * `clientAddress` comes from the socket (Elysia's `server.requestIP`) and is
281
288
  * recorded for the login route, which throttles by it. It is optional so a test
@@ -285,7 +292,7 @@ function rejectionResponse(pathname: string, wantsHtml: boolean): Response {
285
292
  * the routes that matter are same-origin, so rejecting it would only break
286
293
  * browsers that probe.
287
294
  */
288
- export function authGate(request: Request, clientAddress?: string): Response | undefined {
295
+ export async function authGate(request: Request, clientAddress?: string): Promise<Response | undefined> {
289
296
  if (request.method === 'OPTIONS') return undefined;
290
297
 
291
298
  rememberClientAddress(request, clientAddress);
@@ -314,14 +321,11 @@ export function authGate(request: Request, clientAddress?: string): Response | u
314
321
  return undefined;
315
322
  }
316
323
 
317
- // An agent subprocess carries a bearer token instead of a cookie. It is
318
- // scoped by path to the session it names; spawn is the one path a child may
319
- // call under its own token (to create its own children).
320
- const scope = agentTokenScopeForPath(pathname);
321
- if (scope) {
322
- const agentSession = verifyAgentToken(bearerToken(request));
323
- if (agentSession && (scope === 'any' || scope === agentSession)) return undefined;
324
- }
324
+ // An agent subprocess carries a bearer token instead of a cookie. The rule is
325
+ // a session TREE, not a path id — see `agent-gate.server.ts` for why.
326
+ const agent = await agentGate(request, pathname);
327
+ if (agent.kind === 'pass') return undefined;
328
+ if (agent.kind === 'deny') return agent.response;
325
329
 
326
330
  // A paired device carries its own token, and it is good for the whole console
327
331
  // rather than one path: the device is a browser, not a subprocess. Revoking
@@ -76,7 +76,7 @@ describe('initAuthFromHandover', () => {
76
76
 
77
77
  // A restart must not sign the user out: this is the property the key +
78
78
  // secret pair exists to preserve.
79
- const response = authGate(new Request('http://localhost/api/folders', {
79
+ const response = await authGate(new Request('http://localhost/api/folders', {
80
80
  headers: { cookie: `omp_session=${token}` },
81
81
  }));
82
82
  expect(response).toBeUndefined();
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Attach a change journal to a live session.
8
+ *
9
+ * The subscription is the RAW frame stream when the transport has one: omp's
10
+ * `bash` trace is stripped before ordinary subscribers see it (it is ~a second
11
+ * copy of the output), and the trace is the only structured record of what a
12
+ * shell command ran. A transport without a raw stream (ACP) falls back to
13
+ * `onEvent`; its tool frames still carry `args`, so the tool adapters work and
14
+ * only the shell layer is weaker.
15
+ *
16
+ * The journal is lazy: a session that never calls a tool writes nothing, so a
17
+ * test that spawns a fake child does not touch the developer's real `~/.kabmo`.
18
+ */
19
+
20
+ import os from 'node:os';
21
+ import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
22
+ import { ChangeJournal } from '@/server/lib/changes/journal.server';
23
+ import { ChangeCapture } from '@/server/lib/changes/capture.server';
24
+
25
+ export interface JournalSession {
26
+ readonly sessionId: string;
27
+ readonly cwd: string;
28
+ onEvent(listener: (event: AgentEvent) => void): () => void;
29
+ onRawEvent?(listener: (event: AgentEvent) => void): () => void;
30
+ }
31
+
32
+ export interface JournalAttachment {
33
+ /** Stop listening; the journal flushes and closes in the background. */
34
+ detach(): void;
35
+ /** Await every in-flight capture and append (tests and shutdown). */
36
+ flush(): Promise<void>;
37
+ }
38
+
39
+ /** Start journaling `session`. */
40
+ export function attachChangeJournal(session: JournalSession): JournalAttachment {
41
+ const noop: JournalAttachment = { detach: () => {}, flush: async () => {} };
42
+ if (!session.sessionId) return noop;
43
+ const journal = new ChangeJournal(session.sessionId, session.cwd);
44
+ const capture = new ChangeCapture({ journal, cwd: session.cwd, home: os.homedir() });
45
+ const subscribe = session.onRawEvent ?? session.onEvent;
46
+ // A test double (or a transport that exposes no frame stream) has neither;
47
+ // the journal is an annotation, not a reason to fail a registration.
48
+ if (typeof subscribe !== 'function') return noop;
49
+ const off = subscribe.call(session, (event) => capture.onFrame(event));
50
+ return {
51
+ detach: () => {
52
+ off();
53
+ void capture.flush().finally(() => journal.close());
54
+ },
55
+ flush: () => capture.flush(),
56
+ };
57
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The attach seam: a live session's raw frames reach the journal.
8
+ *
9
+ * The unit tests for the capture and the reader prove the two halves; this one
10
+ * proves the wire between them — `onRawEvent` is the subscription, the real
11
+ * filesystem is the source, and a `bash rm` lands as a `delete` record.
12
+ */
13
+
14
+ import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
15
+ import * as fsp from 'node:fs/promises';
16
+ import * as os from 'node:os';
17
+ import * as path from 'node:path';
18
+ import { attachChangeJournal } from '@/server/lib/changes/attach.server';
19
+ import { journalPath } from '@/server/lib/changes/paths.server';
20
+ import { parseJournalLine, type JournalRecord } from '@/server/lib/changes/records';
21
+ import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
22
+
23
+ let dataDir = '';
24
+ let cwd = '';
25
+ let original: string | undefined;
26
+
27
+ beforeAll(async () => {
28
+ original = Bun.env.KABMO_DATA_DIR;
29
+ dataDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'kabmo-changes-attach-'));
30
+ cwd = await fsp.mkdtemp(path.join(os.tmpdir(), 'kabmo-changes-cwd-'));
31
+ Bun.env.KABMO_DATA_DIR = dataDir;
32
+ });
33
+
34
+ afterAll(async () => {
35
+ if (original === undefined) delete Bun.env.KABMO_DATA_DIR;
36
+ else Bun.env.KABMO_DATA_DIR = original;
37
+ await fsp.rm(dataDir, { recursive: true, force: true });
38
+ await fsp.rm(cwd, { recursive: true, force: true });
39
+ });
40
+
41
+ describe('attachChangeJournal', () => {
42
+ test('subscribes to the raw stream and journals a bash delete', async () => {
43
+ const file = path.join(cwd, 'a.txt');
44
+ await fsp.writeFile(file, 'old');
45
+ const listeners: ((event: AgentEvent) => void)[] = [];
46
+ const session = {
47
+ sessionId: 'attach-1',
48
+ cwd,
49
+ onEvent: () => () => {},
50
+ onRawEvent: (listener: (event: AgentEvent) => void) => {
51
+ listeners.push(listener);
52
+ return () => {};
53
+ },
54
+ };
55
+
56
+ const attachment = attachChangeJournal(session);
57
+ expect(listeners.length).toBe(1);
58
+
59
+ listeners[0]({
60
+ type: 'tool_execution_start',
61
+ toolCallId: 'c1',
62
+ toolName: 'bash',
63
+ args: { command: 'rm -f a.txt' },
64
+ });
65
+ await attachment.flush();
66
+ await fsp.rm(file);
67
+ listeners[0]({
68
+ type: 'tool_execution_end',
69
+ toolCallId: 'c1',
70
+ toolName: 'bash',
71
+ result: { details: { trace: { status: 0, units: [{ nodes: [{ k: 'simple', argv: ['rm', '-f', 'a.txt'], st: 0 }] }] } } },
72
+ });
73
+ await attachment.flush();
74
+ attachment.detach();
75
+
76
+ const text = await Bun.file(journalPath('attach-1')).text();
77
+ const records = text.split('\n').map(parseJournalLine).filter((line): line is JournalRecord => line !== null);
78
+ const change = records.find((line) => line.type === 'change');
79
+ expect(change?.type).toBe('change');
80
+ if (change?.type !== 'change') throw new Error('expected a change record');
81
+ expect(change.op).toBe('delete');
82
+ expect(change.path).toBe(file);
83
+ expect(change.source).toBe('trace');
84
+ });
85
+
86
+ test('a session with no frame stream is a no-op, not a crash', () => {
87
+ const attachment = attachChangeJournal({
88
+ sessionId: 'attach-2',
89
+ cwd,
90
+ onEvent: undefined as never,
91
+ });
92
+ expect(() => attachment.detach()).not.toThrow();
93
+ });
94
+ });
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Content-addressed gzip blobs for the change journal.
8
+ *
9
+ * The key is `<byteLength base36>-<Bun.hash base36>`, the same shape omp uses,
10
+ * so a blob written by either writer is recognisable. The cap is 32 MB — four
11
+ * times omp's 8 MB — because the journal's job is to answer "what did this run
12
+ * do", and a 10 MB file is exactly the case the old cap could not answer. A
13
+ * file over the cap is not stored: the record carries `undefined`, and the
14
+ * reader reports the two sides as unknown rather than inventing them.
15
+ */
16
+
17
+ import { mkdir } from 'node:fs/promises';
18
+ import path from 'node:path';
19
+
20
+ export const MAX_BLOB_BYTES = 32 * 1024 * 1024;
21
+
22
+ export function blobKey(text: string): string {
23
+ const bytes = Buffer.from(text, 'utf8');
24
+ return `${bytes.byteLength.toString(36)}-${Bun.hash(bytes).toString(36)}`;
25
+ }
26
+
27
+ /** Store `text` and return its key; `null` when it exceeds the cap. */
28
+ export async function writeBlob(dir: string, text: string): Promise<string | null> {
29
+ const bytes = Buffer.from(text, 'utf8');
30
+ if (bytes.byteLength > MAX_BLOB_BYTES) return null;
31
+ const key = blobKey(text);
32
+ const file = path.join(dir, key);
33
+ if (await Bun.file(file).exists()) return key;
34
+ await mkdir(dir, { recursive: true, mode: 0o700 });
35
+ await Bun.write(file, Bun.gzipSync(bytes));
36
+ return key;
37
+ }
38
+
39
+ /** Blob content for a key; `null` = absent file, `undefined` = not stored/missing. */
40
+ export async function readBlob(
41
+ dir: string,
42
+ key: string | null | undefined,
43
+ ): Promise<string | null | undefined> {
44
+ if (key === null) return null;
45
+ if (key === undefined) return undefined;
46
+ try {
47
+ const bytes = await Bun.file(path.join(dir, key)).bytes();
48
+ return new TextDecoder().decode(Bun.gunzipSync(bytes));
49
+ } catch {
50
+ return undefined;
51
+ }
52
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The `bash` half of the capture layer: what a shell command changed.
8
+ *
9
+ * Two sources, merged: the script text tokenized at start (which names the
10
+ * redirects the trace does not model) and the trace's `simple` nodes at end
11
+ * (which name the `argv` that actually ran). A rename becomes two records so
12
+ * the existing A/M/D list can render it. An opaque command is reconciled from
13
+ * the two git snapshots, and a command the scan could not cover is a note.
14
+ */
15
+
16
+ import {
17
+ classifyArgv,
18
+ classifyCommand,
19
+ type CommandMutation,
20
+ } from '@/server/lib/changes/classify-command';
21
+ import type {
22
+ ChangeExtra,
23
+ ChangeSource,
24
+ PendingCall,
25
+ ShellTrace,
26
+ } from '@/server/lib/changes/capture-types';
27
+ import type { GitScan } from '@/server/lib/changes/scan.server';
28
+
29
+ export interface BashCaptureHost {
30
+ cwd: string;
31
+ home: string;
32
+ readFile(absolute: string): Promise<string | null | undefined>;
33
+ takeScan(cwd: string): Promise<GitScan | null>;
34
+ readHead(root: string, absolute: string): Promise<string | null>;
35
+ writeChange(
36
+ pending: PendingCall,
37
+ absolute: string,
38
+ before: string | null | undefined,
39
+ after: string | null | undefined,
40
+ source: ChangeSource,
41
+ extra?: ChangeExtra,
42
+ ): Promise<void>;
43
+ note(pending: PendingCall, reason: 'opaque-command' | 'scan-budget', detail?: string): Promise<void>;
44
+ }
45
+
46
+ export async function captureBashChanges(
47
+ pending: PendingCall,
48
+ trace: ShellTrace | null,
49
+ host: BashCaptureHost,
50
+ ): Promise<void> {
51
+ const plan = pending.plan ?? classifyCommand(pending.command ?? '', host.cwd, host.home);
52
+ const mutations = new Map<string, CommandMutation>();
53
+ const remember = (mutation: CommandMutation): void => {
54
+ mutations.set(`${mutation.op}:${mutation.from ?? ''}:${mutation.path}`, mutation);
55
+ };
56
+ for (const mutation of plan.mutations) remember(mutation);
57
+ if (trace) {
58
+ for (const unit of trace.units ?? []) {
59
+ for (const node of unit.nodes ?? []) {
60
+ if (node.k !== 'simple' || !Array.isArray(node.argv) || node.argv.length === 0) continue;
61
+ const argv = node.argv.filter((value): value is string => typeof value === 'string');
62
+ for (const mutation of classifyArgv(argv, host.cwd, host.home).mutations) remember(mutation);
63
+ }
64
+ }
65
+ }
66
+
67
+ const exit = typeof trace?.status === 'number' ? trace.status : undefined;
68
+ for (const mutation of mutations.values()) {
69
+ if (mutation.op === 'rename' && mutation.from) {
70
+ const fromEntry = pending.before.get(mutation.from);
71
+ const before = fromEntry ? fromEntry.text : null;
72
+ const after = await host.readFile(mutation.path);
73
+ if (before === after) continue;
74
+ // Two records, so the existing A/M/D list can render a rename.
75
+ await host.writeChange(pending, mutation.from, before, null, 'trace', { command: pending.command, exit });
76
+ await host.writeChange(pending, mutation.path, null, after, 'trace', { command: pending.command, exit, from: mutation.from });
77
+ continue;
78
+ }
79
+ const pathEntry = pending.before.get(mutation.path);
80
+ const before = pathEntry ? pathEntry.text : null;
81
+ const after = await host.readFile(mutation.path);
82
+ await host.writeChange(pending, mutation.path, before, after, 'trace', { command: pending.command, exit });
83
+ }
84
+
85
+ if (pending.scan) await reconcileScan(pending, pending.scan, host);
86
+ if (plan.opaque) await host.note(pending, 'opaque-command', pending.command);
87
+ }
88
+
89
+ /** Journal the delta an opaque command made, from the two git snapshots. */
90
+ async function reconcileScan(pending: PendingCall, start: GitScan, host: BashCaptureHost): Promise<void> {
91
+ const after = await host.takeScan(host.cwd);
92
+ if (!after) return;
93
+ if (start.truncated || after.truncated) await host.note(pending, 'scan-budget', pending.command);
94
+
95
+ const paths = new Set([...start.dirty.keys(), ...after.dirty.keys()]);
96
+ for (const absolute of paths) {
97
+ const before = start.dirty.has(absolute)
98
+ ? start.dirty.get(absolute) ?? null
99
+ : await host.readHead(start.root, absolute);
100
+ const afterText = after.dirty.has(absolute)
101
+ ? after.dirty.get(absolute) ?? null
102
+ : await host.readFile(absolute);
103
+ if (before === afterText) continue;
104
+ await host.writeChange(pending, absolute, before, afterText, 'scan');
105
+ }
106
+ }