@kabmo-labs/kabmo 0.37.0 → 0.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +551 -531
  3. package/dist/client/static/js/{CsvGrid-xb429wvb.js → CsvGrid-t1n057vw.js} +1 -1
  4. package/dist/client/static/js/{DocxView-g58e0bs7.js → DocxView-c9g6teks.js} +2 -2
  5. package/dist/client/static/js/{DrawioView-1j66avvy.js → DrawioView-gd14j54m.js} +1 -1
  6. package/dist/client/static/js/{ImageView-kraqkypn.js → ImageView-57f1ecdp.js} +1 -1
  7. package/dist/client/static/js/{LayoutWrapper-85dhbn62.js → LayoutWrapper-x7srbpz1.js} +2 -2
  8. package/dist/client/static/js/{Modal-f0nfya07.js → Modal-0bn3f77b.js} +15 -15
  9. package/dist/client/static/js/{PdfView-nddkrky9.js → PdfView-cybz0xbj.js} +1 -1
  10. package/dist/client/static/js/{SessionsView-a595m6g1.js → SessionsView-gx5q68tp.js} +1 -1
  11. package/dist/client/static/js/{SheetView-s2p4sk6b.js → SheetView-1kk5y326.js} +1 -1
  12. package/dist/client/static/js/{SvgPreview-ppdx4yb9.js → SvgPreview-mp4tk37p.js} +1 -1
  13. package/dist/client/static/js/{abnfDiagram-O67JEVCF-5cjzxcaq.js → abnfDiagram-O67JEVCF-78qb3can.js} +1 -1
  14. package/dist/client/static/js/architecture-7GRP2DOG-r8sz34h3.js +1 -0
  15. package/dist/client/static/js/{architectureDiagram-NJMV4G6O-62mygavm.js → architectureDiagram-NJMV4G6O-n0fr4hb6.js} +2 -2
  16. package/dist/client/static/js/{astro-80bs6hvg.js → astro-p3f5p9p2.js} +1 -1
  17. package/dist/client/static/js/{blockDiagram-BEXU5L5S-s5yz9hcd.js → blockDiagram-BEXU5L5S-2xemfrzh.js} +6 -6
  18. package/dist/client/static/js/c-jkdstn33.js +1 -0
  19. package/dist/client/static/js/{c4Diagram-YGBWAQC7-rf9xkmrm.js → c4Diagram-YGBWAQC7-zxfdx3eb.js} +2 -2
  20. package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-zfm2cj2a.js → classDiagram-v2-NBCMYWYE-z9sasy3k.js} +5 -5
  21. package/dist/client/static/js/{cose-bilkent-JH36ORCC-fmgpv55e.js → cose-bilkent-JH36ORCC-9byp0czh.js} +1 -1
  22. package/dist/client/static/js/cpp-9d3xdpe3.js +1 -0
  23. package/dist/client/static/js/css-r3wja1ze.js +1 -0
  24. package/dist/client/static/js/css-sebxkh5f.js +1 -0
  25. package/dist/client/static/js/cynefin-OW5HDTMX-w2f2vev7.js +1 -0
  26. package/dist/client/static/js/{cynefinDiagram-VND7K2PF-468r5xc2.js → cynefinDiagram-VND7K2PF-gnm129fx.js} +1 -1
  27. package/dist/client/static/js/{dagre-6A5THRUB-w370qmgj.js → dagre-6A5THRUB-sc5tfv1w.js} +2 -2
  28. package/dist/client/static/js/{diagram-22UHCM2B-sfvfjjsy.js → diagram-22UHCM2B-hq11eek7.js} +7 -7
  29. package/dist/client/static/js/{diagram-3UASUU5V-3r2c8s14.js → diagram-3UASUU5V-7bk532gd.js} +2 -2
  30. package/dist/client/static/js/{diagram-ATOU4E4O-yathy97a.js → diagram-ATOU4E4O-yt8wxttm.js} +2 -2
  31. package/dist/client/static/js/{diagram-CDSNMT55-kk437kxq.js → diagram-CDSNMT55-n3978w6p.js} +1 -1
  32. package/dist/client/static/js/{diagram-MLGK6HIB-qdxfjjhf.js → diagram-MLGK6HIB-004x4gyw.js} +1 -1
  33. package/dist/client/static/js/{diagram-MPIPVDR6-dfqeqa1d.js → diagram-MPIPVDR6-498nt489.js} +1 -1
  34. package/dist/client/static/js/{dockerfile-yxrt509r.js → dockerfile-6hbcmkc8.js} +1 -1
  35. package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-s0b0vv4k.js → ebnfDiagram-ZINNZB2B-5fkmymqn.js} +1 -1
  36. package/dist/client/static/js/{elixir-rpa1g4gy.js → elixir-jwphgp8j.js} +1 -1
  37. package/dist/client/static/js/{elk-276RUBZZ-mtpw0spa.js → elk-276RUBZZ-6xrfa2kd.js} +1 -1
  38. package/dist/client/static/js/{erDiagram-OPXOYQCR-agjdsm1b.js → erDiagram-OPXOYQCR-byz4zbkn.js} +4 -4
  39. package/dist/client/static/js/eventmodeling-NTZA5JFV-k5n61zzh.js +1 -0
  40. package/dist/client/static/js/flowDiagram-KWPJA3E3-s3fbfwrz.js +1 -0
  41. package/dist/client/static/js/{ganttDiagram-FUAMR5RP-z6ywqqc1.js → ganttDiagram-FUAMR5RP-4fkw1k01.js} +2 -2
  42. package/dist/client/static/js/gitGraph-4MIJSDKK-2gf053bx.js +1 -0
  43. package/dist/client/static/js/{gitGraphDiagram-X574FWY7-bvbmfw6h.js → gitGraphDiagram-X574FWY7-19g84yw8.js} +2 -2
  44. package/dist/client/static/js/graphql-p4cskvad.js +1 -0
  45. package/dist/client/static/js/html-f26r6vv5.js +1 -0
  46. package/dist/client/static/js/{index-z0frtyje.js → index-0v8b5pzb.js} +4 -4
  47. package/dist/client/static/js/{index-z7qnffwj.js → index-1j1s91c4.js} +1 -1
  48. package/dist/client/static/js/{index-jpkj6vqp.js → index-20vhkcb9.js} +1 -1
  49. package/dist/client/static/js/{index-0j518hqm.js → index-3az1w5f8.js} +2 -2
  50. package/dist/client/static/js/{index-qznwd6g8.js → index-3wpsr2bc.js} +184 -184
  51. package/dist/client/static/js/{index-09gx6edj.js → index-3y6krykq.js} +1 -1
  52. package/dist/client/static/js/{index-we1rpftn.js → index-4jbbdq6n.js} +2 -2
  53. package/dist/client/static/js/{index-ntxm8pw3.js → index-4qt2e84b.js} +2 -2
  54. package/dist/client/static/js/{index-49dhv8ry.js → index-57z8mtmx.js} +2 -2
  55. package/dist/client/static/js/{index-qz8mbxm9.js → index-5gn56236.js} +2 -2
  56. package/dist/client/static/js/{index-9t82sx0w.js → index-6k3e5dph.js} +2 -2
  57. package/dist/client/static/js/{index-es3pt29g.js → index-74scnfpk.js} +1 -1
  58. package/dist/client/static/js/{index-0mvcbbmy.js → index-7kafzae0.js} +9 -9
  59. package/dist/client/static/js/{index-pd0140dx.js → index-89a2702q.js} +1 -1
  60. package/dist/client/static/js/{index-059qyaj0.js → index-8j90mdgz.js} +1 -1
  61. package/dist/client/static/js/{index-zvfvqvn9.js → index-9wd9y6m0.js} +2 -2
  62. package/dist/client/static/js/{index-a0bdavdr.js → index-ashpbfqv.js} +1 -1
  63. package/dist/client/static/js/{index-72t6kqjx.js → index-b9b2nwdd.js} +2 -2
  64. package/dist/client/static/js/{index-8e0s9p45.js → index-baet2nv8.js} +1 -1
  65. package/dist/client/static/js/{index-j7r414hf.js → index-bhng2dax.js} +2 -2
  66. package/dist/client/static/js/{index-21b3zyrd.js → index-cj9193d5.js} +2 -2
  67. package/dist/client/static/js/{index-sezz011q.js → index-dd4q54y0.js} +1 -1
  68. package/dist/client/static/js/{index-xearvz2z.js → index-e3w46vsc.js} +7 -7
  69. package/dist/client/static/js/{index-1tyvk778.js → index-e99ec2f0.js} +1 -1
  70. package/dist/client/static/js/{index-w9zxmev3.js → index-ehnztdd2.js} +1 -1
  71. package/dist/client/static/js/{index-actppd4z.js → index-epbqzayj.js} +2 -2
  72. package/dist/client/static/js/{index-k06med7d.js → index-fghst0kd.js} +12 -12
  73. package/dist/client/static/js/{index-t07b31ny.js → index-fpf1jkwd.js} +3 -3
  74. package/dist/client/static/js/{index-hbtk0c12.js → index-g252205p.js} +2 -2
  75. package/dist/client/static/js/{index-vtbbfwx0.js → index-gr6jng0x.js} +2 -2
  76. package/dist/client/static/js/{index-kzhtmrh0.js → index-gxtgyya0.js} +1 -1
  77. package/dist/client/static/js/index-j314me09.js +1 -0
  78. package/dist/client/static/js/{index-5fn0agag.js → index-jbwns6sc.js} +1 -1
  79. package/dist/client/static/js/{index-cx89yk15.js → index-kdgcbt17.js} +2 -2
  80. package/dist/client/static/js/{index-m87yykre.js → index-m4bjsyj2.js} +5 -5
  81. package/dist/client/static/js/{index-15zn3sns.js → index-nd4p98mc.js} +1 -1
  82. package/dist/client/static/js/{index-nmc30xaz.js → index-pfwd0160.js} +1 -1
  83. package/dist/client/static/js/{index-w7xbfv44.js → index-qn4pkjfh.js} +2 -2
  84. package/dist/client/static/js/{index-0sqa91wb.js → index-qntytvt0.js} +2 -2
  85. package/dist/client/static/js/{index-64mb65wx.js → index-r83kr4s5.js} +2 -2
  86. package/dist/client/static/js/{index-7sa2e8mn.js → index-rgdhyry3.js} +2 -2
  87. package/dist/client/static/js/{index-m3j5yx5f.js → index-sjnnv1gd.js} +4 -4
  88. package/dist/client/static/js/{index-6q80csr0.js → index-t5t71dhp.js} +2 -2
  89. package/dist/client/static/js/{index-z6g74h7g.js → index-vb6t44dw.js} +2 -2
  90. package/dist/client/static/js/{index-a293pdg7.js → index-y3hdv561.js} +2 -2
  91. package/dist/client/static/js/{index-302d35e5.js → index-zj45wj1x.js} +34 -34
  92. package/dist/client/static/js/{index-83ts8zmk.js → index-zw7qjx65.js} +1 -1
  93. package/dist/client/static/js/info-A6RAGUB7-3tr0y3s6.js +1 -0
  94. package/dist/client/static/js/{infoDiagram-VRGFBTTK-58bv28d4.js → infoDiagram-VRGFBTTK-aw6ter0a.js} +1 -1
  95. package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-tz6b0caw.js → ishikawaDiagram-OU5B5YK6-62gst5wh.js} +2 -2
  96. package/dist/client/static/js/javascript-nyf39d5r.js +1 -0
  97. package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-ydamm17a.js → journeyDiagram-ZHPQQLJL-6kgv5a4j.js} +3 -3
  98. package/dist/client/static/js/{julia-v7j460gw.js → julia-237yk557.js} +1 -1
  99. package/dist/client/static/js/{kanban-definition-PNTS6WVX-7jxfsf17.js → kanban-definition-PNTS6WVX-8p3515b7.js} +3 -3
  100. package/dist/client/static/js/lua-86fjqj8v.js +1 -0
  101. package/dist/client/static/js/{mermaid.core-vty0aq6f.js → mermaid.core-b6ga2y8y.js} +6 -6
  102. package/dist/client/static/js/{mindmap-definition-NLK3R4M7-ra4wrts4.js → mindmap-definition-NLK3R4M7-na9e9b4a.js} +2 -2
  103. package/dist/client/static/js/one-dark-pro-xp6ssk4z.js +1 -0
  104. package/dist/client/static/js/one-light-xgab7b02.js +1 -0
  105. package/dist/client/static/js/packet-AYTQ26CC-xbsyjzrh.js +1 -0
  106. package/dist/client/static/js/{pegDiagram-GJSIUBJH-ydjcfea9.js → pegDiagram-GJSIUBJH-d1hk7fnq.js} +1 -1
  107. package/dist/client/static/js/{perl-gg4jdkcr.js → perl-dvz4y1tb.js} +1 -1
  108. package/dist/client/static/js/{php-2q8fm6k8.js → php-n6y7dzhm.js} +1 -1
  109. package/dist/client/static/js/pie-WAS4IAKB-j2tpz0cs.js +1 -0
  110. package/dist/client/static/js/{pieDiagram-5QR66LMP-wh04y7wp.js → pieDiagram-5QR66LMP-7b9f4x0y.js} +2 -2
  111. package/dist/client/static/js/{quadrantDiagram-O4NWA36T-4mhbag8n.js → quadrantDiagram-O4NWA36T-q4wxgmhg.js} +1 -1
  112. package/dist/client/static/js/radar-RG4KPBEZ-m3tsyfv0.js +1 -0
  113. package/dist/client/static/js/railroad-74A4TZTK-5p202a4q.js +1 -0
  114. package/dist/client/static/js/railroad-abnf-HS5TGJTU-hj0y9tgn.js +1 -0
  115. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-8c5dct8f.js +1 -0
  116. package/dist/client/static/js/railroad-peg-WCYAUIDC-3tx8z65q.js +1 -0
  117. package/dist/client/static/js/{railroadDiagram-XR7U4H2S-pagmr4hc.js → railroadDiagram-XR7U4H2S-jngq1qx4.js} +1 -1
  118. package/dist/client/static/js/{requirementDiagram-PLB6GJNP-jhfhp4eq.js → requirementDiagram-PLB6GJNP-6xph3b72.js} +4 -4
  119. package/dist/client/static/js/{ruby-vag6a82m.js → ruby-7zye3g0e.js} +1 -1
  120. package/dist/client/static/js/{rust-yntkm6hw.js → rust-w6hen2h4.js} +1 -1
  121. package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-qrfxzvp3.js → sankeyDiagram-IPEJSGJF-ncfzgdj8.js} +1 -1
  122. package/dist/client/static/js/{sass-kbwea482.js → sass-m0h9yzfb.js} +1 -1
  123. package/dist/client/static/js/{scss-zphrqp25.js → scss-2pwwfkvn.js} +1 -1
  124. package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-fpznwnva.js → sequenceDiagram-PO4LG4MO-sqz0yfg0.js} +3 -3
  125. package/dist/client/static/js/{sizeCapture-INFHLROL-3hz930jg.js → sizeCapture-INFHLROL-vt8qp04d.js} +1 -1
  126. package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-2m99syxm.js → stateDiagram-v2-GCMORJYK-myjtrmfe.js} +3 -3
  127. package/dist/client/static/js/{svelte-mwtx07d9.js → svelte-x8f8c8hq.js} +1 -1
  128. package/dist/client/static/js/{swimlanes-2SLR337P-hmhd360r.js → swimlanes-2SLR337P-z9vx7z4j.js} +1 -1
  129. package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-a8b7z74e.js → swimlanesDiagram-TC7HE7FX-5vha7thx.js} +1 -1
  130. package/dist/client/static/js/{timeline-definition-EJHVYXUP-765y3ssa.js → timeline-definition-EJHVYXUP-z815np57.js} +2 -2
  131. package/dist/client/static/js/treeView-Q6P3EWNA-mf0rb2yv.js +1 -0
  132. package/dist/client/static/js/treemap-WGGIJYW6-0x5gf06b.js +1 -0
  133. package/dist/client/static/js/typescript-5nmrzgkj.js +1 -0
  134. package/dist/client/static/js/{usecaseDiagram-POWQR4AR-rex2j507.js → usecaseDiagram-POWQR4AR-06ntggng.js} +13 -13
  135. package/dist/client/static/js/{vennDiagram-UO4OBE2U-wd51qq26.js → vennDiagram-UO4OBE2U-nmtaf5rp.js} +1 -1
  136. package/dist/client/static/js/{vue-j8vb9d7r.js → vue-myjjd0gd.js} +1 -1
  137. package/dist/client/static/js/wardley-WFR3VGLG-x7ej8dms.js +1 -0
  138. package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-6jdqn8f7.js → wardleyDiagram-VNRHLVJA-zgsxmak8.js} +1 -1
  139. package/dist/client/static/js/xml-3dd1pter.js +1 -0
  140. package/dist/client/static/js/{xychartDiagram-PMCCYNJV-kcz8y04e.js → xychartDiagram-PMCCYNJV-8bg9qdra.js} +2 -2
  141. package/package.json +1 -1
  142. package/src/client/components/common/ComposerPicker.tsx +24 -12
  143. package/src/client/components/common/ComposerTextarea.tsx +1 -0
  144. package/src/client/components/layout/session-sidebar/scheduler-modal/ModelFields.tsx +1 -1
  145. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +1 -1
  146. package/src/client/components/workspace/chat-timeline/index.tsx +3 -3
  147. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FormAsk.test.tsx +210 -0
  148. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FormAsk.tsx +342 -0
  149. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/LooseFieldAsk.tsx +44 -0
  150. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/OrphanAsks.test.tsx +44 -1
  151. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/OrphanAsks.tsx +10 -5
  152. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/PluginPendingInteractions.test.ts +1 -0
  153. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +19 -0
  154. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/form-picks.ts +52 -0
  155. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.test.ts +2 -2
  156. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +53 -4
  157. package/src/client/components/workspace/model-dropdown/index.tsx +1 -1
  158. package/src/client/components/workspace/model-dropdown/use-catalog.ts +3 -32
  159. package/src/client/data/settings/omp-schema.json +55 -1
  160. package/src/client/hooks/chat/composer/harness-model-picker.ts +84 -0
  161. package/src/client/hooks/chat/composer/index.ts +26 -6
  162. package/src/client/hooks/chat/timeline/ask-frames.test.ts +80 -7
  163. package/src/client/hooks/chat/timeline/ask-frames.ts +95 -21
  164. package/src/client/hooks/models/use-harnesses.ts +15 -2
  165. package/src/server/lib/auth/agent-gate.server.ts +64 -0
  166. package/src/server/lib/auth/agent-tree-gate.test.ts +121 -0
  167. package/src/server/lib/auth/guard.test.ts +18 -18
  168. package/src/server/lib/auth/guard.ts +15 -11
  169. package/src/server/lib/auth/handover-guard.test.ts +1 -1
  170. package/src/server/lib/changes/attach.server.ts +57 -0
  171. package/src/server/lib/changes/attach.test.ts +94 -0
  172. package/src/server/lib/changes/blobs.server.ts +52 -0
  173. package/src/server/lib/changes/capture-bash.server.ts +171 -0
  174. package/src/server/lib/changes/capture-fs.server.ts +64 -0
  175. package/src/server/lib/changes/capture-races.test.ts +107 -0
  176. package/src/server/lib/changes/capture-runs.test.ts +136 -0
  177. package/src/server/lib/changes/capture-scan.test.ts +157 -0
  178. package/src/server/lib/changes/capture-test-util.ts +46 -0
  179. package/src/server/lib/changes/capture-types.ts +64 -0
  180. package/src/server/lib/changes/capture-write.server.ts +50 -0
  181. package/src/server/lib/changes/capture.server.ts +349 -0
  182. package/src/server/lib/changes/capture.test.ts +293 -0
  183. package/src/server/lib/changes/classify-command.test.ts +172 -0
  184. package/src/server/lib/changes/classify-command.ts +272 -0
  185. package/src/server/lib/changes/classify-git.ts +88 -0
  186. package/src/server/lib/changes/classify-paths.ts +112 -0
  187. package/src/server/lib/changes/classify-tokenize.ts +185 -0
  188. package/src/server/lib/changes/journal.server.ts +185 -0
  189. package/src/server/lib/changes/journal.test.ts +125 -0
  190. package/src/server/lib/changes/merge.test.ts +137 -0
  191. package/src/server/lib/changes/omp-fallback.server.ts +48 -0
  192. package/src/server/lib/changes/omp-fallback.test.ts +75 -0
  193. package/src/server/lib/changes/paths.server.ts +37 -0
  194. package/src/server/lib/changes/purge.server.ts +32 -0
  195. package/src/server/lib/changes/reader.server.ts +350 -0
  196. package/src/server/lib/changes/reader.test.ts +137 -0
  197. package/src/server/lib/changes/records.ts +120 -0
  198. package/src/server/lib/changes/scan.server.ts +139 -0
  199. package/src/server/lib/changes/sessions.server.ts +65 -0
  200. package/src/server/lib/changes/sessions.test.ts +52 -0
  201. package/src/server/lib/harness/register.server.ts +3 -0
  202. package/src/server/lib/omp/rpc/event-fanout.test.ts +58 -0
  203. package/src/server/lib/omp/rpc/event-fanout.ts +19 -0
  204. package/src/server/lib/omp/rpc/manager.ts +4 -3
  205. package/src/server/lib/omp/rpc/session-registration.ts +5 -0
  206. package/src/server/lib/omp/rpc/session-registry.ts +4 -5
  207. package/src/server/lib/omp/session/delete.server.ts +4 -0
  208. package/src/server/lib/sessions/agent-token.server.test.ts +28 -5
  209. package/src/server/lib/sessions/agent-token.server.ts +42 -6
  210. package/src/server/lib/sessions/relation-access.server.test.ts +96 -0
  211. package/src/server/lib/sessions/relation-access.server.ts +71 -0
  212. package/src/server/routes/sessions/changes.ts +1 -1
  213. package/src/shared/lib/chat/ask-form/fields.ts +1 -0
  214. package/src/shared/lib/chat/ask-form/types.ts +6 -0
  215. package/src/shared/lib/chat/ask-questions.ts +56 -3
  216. package/src/shared/lib/chat/composer/delegation.ts +2 -13
  217. package/src/shared/lib/chat/composer/filter.test.ts +39 -0
  218. package/src/shared/lib/chat/composer/filter.ts +23 -13
  219. package/src/shared/lib/chat/composer/harness-model-items.test.ts +54 -0
  220. package/src/shared/lib/chat/composer/harness-model-items.ts +41 -0
  221. package/src/shared/lib/chat/composer/trigger.test.ts +50 -0
  222. package/src/shared/lib/chat/composer/trigger.ts +29 -1
  223. package/src/shared/lib/chat/timeline/changed-files.test.ts +16 -0
  224. package/src/shared/lib/chat/timeline/changed-files.ts +102 -25
  225. package/src/shared/lib/harness/catalog.ts +21 -0
  226. package/src/{client/components/workspace/model-dropdown/harness-models.test.ts → shared/lib/harness/models.test.ts} +1 -1
  227. package/src/shared/lib/models/option.ts +46 -0
  228. package/src/shared/lib/omp/config/schema.test.ts +20 -0
  229. package/src/shared/types/chat.ts +12 -6
  230. package/src/shared/types/omp/agent.ts +9 -0
  231. package/src/shared/types/session-changes.ts +4 -0
  232. package/dist/client/static/js/architecture-7GRP2DOG-7ewrw5vc.js +0 -1
  233. package/dist/client/static/js/c-wkgxb1t1.js +0 -1
  234. package/dist/client/static/js/cpp-y0t6mynx.js +0 -1
  235. package/dist/client/static/js/css-r2nhvzff.js +0 -1
  236. package/dist/client/static/js/css-tf1s0nb7.js +0 -1
  237. package/dist/client/static/js/cynefin-OW5HDTMX-yyyx3px0.js +0 -1
  238. package/dist/client/static/js/eventmodeling-NTZA5JFV-cx3ztxfz.js +0 -1
  239. package/dist/client/static/js/flowDiagram-KWPJA3E3-267mw6sv.js +0 -1
  240. package/dist/client/static/js/gitGraph-4MIJSDKK-eg9r85ak.js +0 -1
  241. package/dist/client/static/js/graphql-skw5krjr.js +0 -1
  242. package/dist/client/static/js/html-pv88ny12.js +0 -1
  243. package/dist/client/static/js/index-tcegdd2t.js +0 -1
  244. package/dist/client/static/js/info-A6RAGUB7-7qhah7fs.js +0 -1
  245. package/dist/client/static/js/javascript-4kw2j9t3.js +0 -1
  246. package/dist/client/static/js/lua-ke895s2q.js +0 -1
  247. package/dist/client/static/js/one-dark-pro-2pywnqrh.js +0 -1
  248. package/dist/client/static/js/one-light-vfgdt4wf.js +0 -1
  249. package/dist/client/static/js/packet-AYTQ26CC-ag2g7tbk.js +0 -1
  250. package/dist/client/static/js/pie-WAS4IAKB-nqcyj3x1.js +0 -1
  251. package/dist/client/static/js/radar-RG4KPBEZ-60gby7be.js +0 -1
  252. package/dist/client/static/js/railroad-74A4TZTK-cnkmcjse.js +0 -1
  253. package/dist/client/static/js/railroad-abnf-HS5TGJTU-qgfdnazd.js +0 -1
  254. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-609h6cpx.js +0 -1
  255. package/dist/client/static/js/railroad-peg-WCYAUIDC-xqnytjhg.js +0 -1
  256. package/dist/client/static/js/treeView-Q6P3EWNA-8djqab8k.js +0 -1
  257. package/dist/client/static/js/treemap-WGGIJYW6-hdztnffk.js +0 -1
  258. package/dist/client/static/js/typescript-0s2t05jj.js +0 -1
  259. package/dist/client/static/js/wardley-WFR3VGLG-avby77vv.js +0 -1
  260. package/dist/client/static/js/xml-81hxjjt4.js +0 -1
  261. /package/src/{client/components/workspace/model-dropdown/harness-models.ts → shared/lib/harness/models.ts} +0 -0
@@ -0,0 +1,120 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The Kabmo change journal's line shapes.
8
+ *
9
+ * One JSON object per line, append-only. The journal is Kabmo's own record of
10
+ * what a run did to the working tree — not omp's `changes.jsonl`, which only
11
+ * sees the edit tools. The extra fields are the point: `toolCallId` joins a
12
+ * write to the call that made it, `source` says which capture layer saw it, and
13
+ * `command`/`exit` make a `bash` mutation explainable.
14
+ *
15
+ * `before`/`after` are blob keys, `null` when the file did not exist, and
16
+ * `undefined` when the content was not stored (over the cap). A `note` line is
17
+ * how the journal says "I could not capture this" instead of guessing.
18
+ */
19
+
20
+ import type { MutationOp } from '@/server/lib/changes/classify-command';
21
+
22
+ export interface JournalSessionRecord {
23
+ v: 1;
24
+ type: 'session';
25
+ at: number;
26
+ sessionId: string;
27
+ cwd: string;
28
+ omp?: string;
29
+ kabmo?: string;
30
+ }
31
+
32
+ export interface JournalRunRecord {
33
+ v: 1;
34
+ type: 'run';
35
+ phase: 'start' | 'end';
36
+ runId: string;
37
+ at: number;
38
+ }
39
+
40
+ export interface JournalCallRecord {
41
+ v: 1;
42
+ type: 'call';
43
+ at: number;
44
+ /** The run this call belongs to; absent on a journal written before runs. */
45
+ runId?: string;
46
+ /** The run's `agent_start` time, so a reader can map it to a chat run. */
47
+ runAt?: number;
48
+ toolCallId: string;
49
+ agent: string;
50
+ parent?: string;
51
+ tool: string;
52
+ intent?: string;
53
+ /** The call's arguments, truncated to a bounded JSON string. */
54
+ args?: unknown;
55
+ argsTruncated?: boolean;
56
+ }
57
+
58
+ export interface JournalChangeRecord {
59
+ v: 1;
60
+ type: 'change';
61
+ at: number;
62
+ runId?: string;
63
+ runAt?: number;
64
+ toolCallId?: string;
65
+ agent: string;
66
+ parent?: string;
67
+ tool: string;
68
+ op: MutationOp;
69
+ /** Absolute path after the write. */
70
+ path: string;
71
+ /** Absolute source path, for a rename. */
72
+ from?: string;
73
+ displayPath: string;
74
+ before: string | null | undefined;
75
+ after: string | null | undefined;
76
+ beforeMtimeMs?: number;
77
+ afterMtimeMs?: number;
78
+ source: 'tool' | 'trace' | 'scan' | 'omp-import';
79
+ command?: string;
80
+ exit?: number;
81
+ }
82
+
83
+ export interface JournalCommitRecord {
84
+ v: 1;
85
+ type: 'commit';
86
+ at: number;
87
+ sha: string;
88
+ paths: string[];
89
+ }
90
+
91
+ export interface JournalNoteRecord {
92
+ v: 1;
93
+ type: 'note';
94
+ at: number;
95
+ runId?: string;
96
+ runAt?: number;
97
+ toolCallId?: string;
98
+ reason: 'too-large' | 'opaque-command' | 'scan-budget' | 'snapshot-race' | 'unknown-tool';
99
+ detail?: string;
100
+ }
101
+
102
+ export type JournalRecord =
103
+ | JournalSessionRecord
104
+ | JournalRunRecord
105
+ | JournalCallRecord
106
+ | JournalChangeRecord
107
+ | JournalCommitRecord
108
+ | JournalNoteRecord;
109
+
110
+ /** Parse one journal line; `null` for a torn or foreign line. */
111
+ export function parseJournalLine(line: string): JournalRecord | null {
112
+ if (!line) return null;
113
+ try {
114
+ const value = JSON.parse(line) as Record<string, unknown>;
115
+ if (value?.v !== 1 || typeof value.type !== 'string') return null;
116
+ return value as unknown as JournalRecord;
117
+ } catch {
118
+ return null;
119
+ }
120
+ }
@@ -0,0 +1,139 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The filesystem reconciliation pass: what an opaque command changed.
8
+ *
9
+ * A `git reset --hard`, a `bun install`, a shell script — the classifier cannot
10
+ * name their targets from `argv`, so the journal takes a cheap snapshot before
11
+ * and after and journals the delta. The snapshot is `git status --porcelain`
12
+ * plus the content of the dirty paths (bounded), because a path that was
13
+ * already dirty has no HEAD version to fall back on.
14
+ *
15
+ * A path that was CLEAN at start has an exact before side: `git show HEAD:path`.
16
+ * A path that was dirty at start is read at snapshot time, so a command that
17
+ * rewrites it is still caught. A path outside the repo, or a repo that is not
18
+ * there, answers `null` and the caller writes a note instead of a guess.
19
+ */
20
+
21
+ import { readdir, stat } from 'node:fs/promises';
22
+ import path from 'node:path';
23
+ import { childEnv } from '@/server/lib/fs/child-env';
24
+
25
+ const SCAN_BUDGET_FILES = 200;
26
+ const GIT_TIMEOUT_MS = 5_000;
27
+ const DIR_SCAN_MAX_BYTES = 10 * 1024 * 1024;
28
+
29
+ export interface GitScan {
30
+ root: string;
31
+ /** Absolute path → content at snapshot time, for paths that were dirty. */
32
+ dirty: Map<string, string | null>;
33
+ /** The budget cut the dirty set; the caller says so rather than pretending. */
34
+ truncated: boolean;
35
+ }
36
+
37
+ async function runGit(cwd: string, args: string[]): Promise<string | null> {
38
+ try {
39
+ const proc = Bun.spawn(['git', '-C', cwd, ...args], {
40
+ env: childEnv(),
41
+ stdout: 'pipe',
42
+ stderr: 'ignore',
43
+ signal: AbortSignal.timeout(GIT_TIMEOUT_MS),
44
+ });
45
+ const [text, code] = await Promise.all([new Response(proc.stdout).text(), proc.exited]);
46
+ return code === 0 ? text : null;
47
+ } catch {
48
+ return null;
49
+ }
50
+ }
51
+
52
+ /** `XY <path>\0` entries; a rename's second entry (the old path) is skipped. */
53
+ function parseStatus(output: string): string[] {
54
+ const paths: string[] = [];
55
+ for (const entry of output.split('\0')) {
56
+ if (entry.length < 4 || entry[2] !== ' ') continue;
57
+ paths.push(entry.slice(3));
58
+ }
59
+ return paths;
60
+ }
61
+
62
+ async function readText(absolute: string): Promise<string | null> {
63
+ try {
64
+ return await Bun.file(absolute).text();
65
+ } catch {
66
+ return null;
67
+ }
68
+ }
69
+
70
+ /** Snapshot the repo's dirty set and its content; `null` outside a repo. */
71
+ export async function takeGitScan(cwd: string): Promise<GitScan | null> {
72
+ const root = (await runGit(cwd, ['rev-parse', '--show-toplevel']))?.trim();
73
+ if (!root) return null;
74
+ // `--no-optional-locks` keeps a concurrent scan from taking the index lock:
75
+ // two sessions in one repo must not make each other's `git status` fail.
76
+ const status = await runGit(root, ['status', '--porcelain=v1', '-z', '--no-optional-locks']);
77
+ if (status === null) return null;
78
+
79
+ const entries = parseStatus(status);
80
+ const dirty = new Map<string, string | null>();
81
+ for (const relative of entries.slice(0, SCAN_BUDGET_FILES)) {
82
+ const absolute = path.resolve(root, relative);
83
+ dirty.set(absolute, await readText(absolute));
84
+ }
85
+ return { root, dirty, truncated: entries.length > SCAN_BUDGET_FILES };
86
+ }
87
+
88
+ /**
89
+ * A non-git fallback: the cwd's own files and their content, bounded.
90
+ *
91
+ * A `python3 script.py` in a temp directory writes files no `argv` names, and
92
+ * there is no git index to ask. The directory scan is the only reconciliation
93
+ * available there; it is bounded to 200 files and 10 MB, and a binary file is
94
+ * skipped rather than journaled as a text diff.
95
+ */
96
+ export async function takeDirScan(cwd: string): Promise<GitScan | null> {
97
+ let entries;
98
+ try {
99
+ entries = await readdir(cwd, { withFileTypes: true });
100
+ } catch {
101
+ return null;
102
+ }
103
+ const dirty = new Map<string, string | null>();
104
+ let bytes = 0;
105
+ let truncated = false;
106
+ for (const entry of entries) {
107
+ if (!entry.isFile()) continue;
108
+ if (dirty.size >= SCAN_BUDGET_FILES) {
109
+ truncated = true;
110
+ break;
111
+ }
112
+ const absolute = path.join(cwd, entry.name);
113
+ const info = await stat(absolute).catch(() => null);
114
+ if (!info) continue;
115
+ if (bytes + info.size > DIR_SCAN_MAX_BYTES) {
116
+ truncated = true;
117
+ continue;
118
+ }
119
+ const text = await readText(absolute);
120
+ if (text === null || text.includes('\0')) continue;
121
+ bytes += info.size;
122
+ dirty.set(absolute, text);
123
+ }
124
+ return { root: cwd, dirty, truncated };
125
+ }
126
+
127
+ /** Git first (exact for tracked files), then the directory scan. */
128
+ export async function takeScan(cwd: string): Promise<GitScan | null> {
129
+ const git = await takeGitScan(cwd);
130
+ if (git) return git;
131
+ return takeDirScan(cwd);
132
+ }
133
+
134
+ /** The content at HEAD for a path that was clean; `null` when it did not exist. */
135
+ export async function readHeadContent(root: string, absolute: string): Promise<string | null> {
136
+ const relative = path.relative(root, absolute);
137
+ if (!relative || relative.startsWith('..') || path.isAbsolute(relative)) return null;
138
+ return runGit(root, ['show', `HEAD:${relative.replaceAll('\\', '/')}`]);
139
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Which sessions share a working directory.
8
+ *
9
+ * The scan layer is the one place a concurrent session can be misattributed: a
10
+ * `git status` or a directory diff sees the other session's file too. Before a
11
+ * scan records a path, it asks this module for the OTHER sessions in the same
12
+ * cwd and skips a path one of them already recorded in the window.
13
+ *
14
+ * The cwd comes from each journal's `session` header, so the map is stable for
15
+ * a session's lifetime. It is cached by the `changes/` root's path + mtime: a
16
+ * new session directory changes the mtime, and a different data root changes
17
+ * the path.
18
+ */
19
+
20
+ import { readdir, stat } from 'node:fs/promises';
21
+ import path from 'node:path';
22
+ import { changesRoot } from '@/server/lib/changes/paths.server';
23
+ import { parseJournalLine } from '@/server/lib/changes/records';
24
+
25
+ interface CwdCache {
26
+ root: string;
27
+ rootMtime: number;
28
+ byCwd: Map<string, string[]>;
29
+ }
30
+
31
+ declare global {
32
+ // eslint-disable-next-line no-var
33
+ var __kabmoSessionsByCwd: CwdCache | undefined;
34
+ }
35
+
36
+ /** Session ids whose journal header names `cwd`, excluding `excludeSessionId`. */
37
+ export async function sessionsInCwd(cwd: string, excludeSessionId: string): Promise<string[]> {
38
+ const root = changesRoot();
39
+ const info = await stat(root).catch(() => null);
40
+ if (!info) return [];
41
+
42
+ let cache = globalThis.__kabmoSessionsByCwd;
43
+ if (!cache || cache.root !== root || cache.rootMtime !== info.mtimeMs) {
44
+ cache = { root, rootMtime: info.mtimeMs, byCwd: await buildByCwd(root) };
45
+ globalThis.__kabmoSessionsByCwd = cache;
46
+ }
47
+ return (cache.byCwd.get(cwd) ?? []).filter((id) => id !== excludeSessionId);
48
+ }
49
+
50
+ async function buildByCwd(root: string): Promise<Map<string, string[]>> {
51
+ const byCwd = new Map<string, string[]>();
52
+ const entries = await readdir(root, { withFileTypes: true }).catch(() => []);
53
+ for (const entry of entries) {
54
+ if (!entry.isDirectory()) continue;
55
+ const file = path.join(root, entry.name, 'changes.jsonl');
56
+ // The header is the first line; a slice keeps a 20 MB journal cheap to read.
57
+ const head = await Bun.file(file).slice(0, 1024).text().catch(() => '');
58
+ const record = parseJournalLine(head.split('\n')[0] ?? '');
59
+ if (record?.type !== 'session') continue;
60
+ const list = byCwd.get(record.cwd) ?? [];
61
+ list.push(entry.name);
62
+ byCwd.set(record.cwd, list);
63
+ }
64
+ return byCwd;
65
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Which sessions share a cwd, from each journal's `session` header.
8
+ *
9
+ * The scan's cross-check depends on this: a path another session in the same
10
+ * cwd already recorded must not be attributed to the current command.
11
+ */
12
+
13
+ import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
14
+ import * as fsp from 'node:fs/promises';
15
+ import * as os from 'node:os';
16
+ import * as path from 'node:path';
17
+ import { ChangeJournal } from '@/server/lib/changes/journal.server';
18
+ import { sessionsInCwd } from '@/server/lib/changes/sessions.server';
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-sessions-'));
26
+ Bun.env.KABMO_DATA_DIR = dataDir;
27
+ const a = new ChangeJournal('sess-a', '/repo');
28
+ const b = new ChangeJournal('sess-b', '/repo');
29
+ const c = new ChangeJournal('sess-c', '/other');
30
+ await a.recordNote({ at: 1, reason: 'opaque-command' });
31
+ await b.recordNote({ at: 1, reason: 'opaque-command' });
32
+ await c.recordNote({ at: 1, reason: 'opaque-command' });
33
+ await Promise.all([a.flush(), b.flush(), c.flush()]);
34
+ });
35
+
36
+ afterAll(async () => {
37
+ if (original === undefined) delete Bun.env.KABMO_DATA_DIR;
38
+ else Bun.env.KABMO_DATA_DIR = original;
39
+ await fsp.rm(dataDir, { recursive: true, force: true });
40
+ });
41
+
42
+ describe('sessionsInCwd', () => {
43
+ test('returns the other sessions in the same cwd', async () => {
44
+ expect((await sessionsInCwd('/repo', 'sess-a')).sort()).toEqual(['sess-b']);
45
+ expect((await sessionsInCwd('/repo', 'sess-x')).sort()).toEqual(['sess-a', 'sess-b']);
46
+ });
47
+
48
+ test('does not mix a different cwd', async () => {
49
+ expect(await sessionsInCwd('/other', 'sess-a')).toEqual(['sess-c']);
50
+ expect(await sessionsInCwd('/none', 'sess-a')).toEqual([]);
51
+ });
52
+ });
@@ -15,6 +15,7 @@
15
15
  */
16
16
 
17
17
  import type { HarnessSession } from '@/server/lib/harness/session';
18
+ import { attachChangeJournal } from '@/server/lib/changes/attach.server';
18
19
 
19
20
  /** Pulled from the omp registry module so there is one map, not two. */
20
21
  export function registerAcpSession(
@@ -27,7 +28,9 @@ export function registerAcpSession(
27
28
  const registry = liveRegistry();
28
29
  registry.set(session.sessionId, session);
29
30
  if (requestedId && requestedId !== session.sessionId) registry.set(requestedId, session);
31
+ const journal = attachChangeJournal(session);
30
32
  session.onDestroy(() => {
33
+ journal.detach();
31
34
  if (registry.get(session.sessionId) === session) registry.delete(session.sessionId);
32
35
  if (registry.get(requestedId) === session) registry.delete(requestedId);
33
36
  // The caller's cleanup rides the SAME hook: `onDestroy` holds one callback,
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The fan-out's two listener lists.
8
+ *
9
+ * `on` is the ordinary stream every subscriber reads; `onRaw` runs first, before
10
+ * `stripShellTrace` mutates the frame in place. The change journal is the only
11
+ * raw listener: it needs the shell trace, and every other subscriber must not
12
+ * pay for it.
13
+ */
14
+
15
+ import { describe, expect, test } from 'bun:test';
16
+ import { EventFanout } from '@/server/lib/omp/rpc/event-fanout';
17
+ import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
18
+
19
+ describe('EventFanout raw listeners', () => {
20
+ test('a raw listener sees the shell trace before the strip', () => {
21
+ const fanout = new EventFanout();
22
+ let rawTrace: unknown;
23
+ let normalTrace: unknown;
24
+ fanout.onRaw((event) => {
25
+ rawTrace = (event.result as { details?: { trace?: unknown } } | undefined)?.details?.trace;
26
+ });
27
+ fanout.on((event) => {
28
+ normalTrace = (event.result as { details?: { trace?: unknown } } | undefined)?.details?.trace;
29
+ });
30
+ fanout.emit({
31
+ type: 'tool_execution_end',
32
+ result: { content: [], details: { exitCode: 0, trace: { v: 1 } } },
33
+ } as unknown as AgentEvent);
34
+ expect(rawTrace).toEqual({ v: 1 });
35
+ expect(normalTrace).toBeUndefined();
36
+ });
37
+
38
+ test('a throwing raw listener does not starve the ordinary ones', () => {
39
+ const fanout = new EventFanout();
40
+ const seen: number[] = [];
41
+ fanout.onRaw(() => {
42
+ throw new Error('journal failed');
43
+ });
44
+ fanout.on((event) => seen.push(event.n as number));
45
+ expect(() => fanout.emit({ type: 'message_update', n: 3 })).not.toThrow();
46
+ expect(seen).toEqual([3]);
47
+ });
48
+
49
+ test('an unsubscribed raw listener no longer fires', () => {
50
+ const fanout = new EventFanout();
51
+ let calls = 0;
52
+ const off = fanout.onRaw(() => calls++);
53
+ fanout.emit({ type: 'message_update' });
54
+ off();
55
+ fanout.emit({ type: 'message_update' });
56
+ expect(calls).toBe(1);
57
+ });
58
+ });
@@ -29,8 +29,18 @@ import { stripShellTrace } from '@/shared/lib/omp/session/shell-trace';
29
29
 
30
30
  export class EventFanout {
31
31
  readonly #listeners: EventListener[] = [];
32
+ readonly #rawListeners: EventListener[] = [];
32
33
 
33
34
  emit(event: AgentEvent): void {
35
+ // Raw listeners run BEFORE the strip: the change journal needs the shell
36
+ // trace, and the strip mutates the frame in place.
37
+ for (const listener of this.#rawListeners) {
38
+ try {
39
+ listener(event);
40
+ } catch {
41
+ // Deliberately swallowed: see the module doc.
42
+ }
43
+ }
34
44
  stripShellTrace(event);
35
45
  for (const listener of this.#listeners) {
36
46
  try {
@@ -49,4 +59,13 @@ export class EventFanout {
49
59
  if (index !== -1) this.#listeners.splice(index, 1);
50
60
  };
51
61
  }
62
+
63
+ /** Register a listener that sees the frame before the shell trace is stripped. */
64
+ onRaw(listener: EventListener): () => void {
65
+ this.#rawListeners.push(listener);
66
+ return () => {
67
+ const index = this.#rawListeners.indexOf(listener);
68
+ if (index !== -1) this.#rawListeners.splice(index, 1);
69
+ };
70
+ }
52
71
  }
@@ -259,9 +259,10 @@ export class AgentSessionWrapper {
259
259
  this.fanout.emit(event);
260
260
  }
261
261
 
262
- onEvent(listener: EventListener): () => void {
263
- return this.fanout.on(listener);
264
- }
262
+ onEvent(listener: EventListener): () => void { return this.fanout.on(listener); }
263
+
264
+ /** Frames before the shell trace is stripped — the change journal's tap. */
265
+ onRawEvent(listener: EventListener): () => void { return this.fanout.onRaw(listener); }
265
266
 
266
267
  /** Dialogs omp is still blocked on, oldest first. A client reattaching to a
267
268
  * live session replays these so the modal it lost on reload comes back. */
@@ -17,6 +17,7 @@
17
17
 
18
18
  import type { AgentSessionWrapper } from '@/server/lib/omp/rpc/manager';
19
19
  import type { HarnessSession } from '@/server/lib/harness/session';
20
+ import { attachChangeJournal } from '@/server/lib/changes/attach.server';
20
21
 
21
22
  /** Any session this registry can hold: the function only touches `sessionId` and
22
23
  * `onDestroy`, which both transports provide. */
@@ -51,7 +52,11 @@ export function registerSpawnedSession(
51
52
  requestedId: string,
52
53
  realSessionId: string,
53
54
  ): void {
55
+ // The journal starts with the session and stops with it. `onDestroy` holds
56
+ // one callback, so the detach rides the same one as the registry cleanup.
57
+ const journal = attachChangeJournal(created);
54
58
  created.onDestroy(() => {
59
+ journal.detach();
55
60
  if (registry.get(created.sessionId) === created) registry.delete(created.sessionId);
56
61
  if (registry.get(realSessionId) === created) registry.delete(realSessionId);
57
62
  // The alias must go too, or a dead wrapper would answer for the requested id
@@ -332,11 +332,10 @@ export async function startNewRpcSession(
332
332
 
333
333
  const registry = getRegistry();
334
334
  const realSessionId = wrapper.sessionId;
335
- wrapper.onDestroy(() => {
336
- if (registry.get(wrapper.sessionId) === wrapper) registry.delete(wrapper.sessionId);
337
- if (registry.get(realSessionId) === wrapper) registry.delete(realSessionId);
338
- });
339
- registry.set(realSessionId, wrapper);
335
+ // The same registration the cold path uses: it installs the destroy cleanup
336
+ // AND starts the change journal, so a prewarmed session is not a second
337
+ // convention.
338
+ registerSpawnedSession(registry, wrapper, realSessionId, realSessionId);
340
339
  // A prewarmed process is adopted here, not in `startRpcSession`, so this is
341
340
  // the only spawn path that sees it — a session's cwd may sit outside every
342
341
  // registered workspace, and the discovery watcher has to learn it. Awaited
@@ -43,6 +43,7 @@ import { siblingDirForSession } from '@/server/lib/omp/subagent/history/paths';
43
43
  import { isSinglePathSegment } from '@/server/lib/fs/path-segment';
44
44
  import { deleteSessionRelations } from '@/server/lib/sessions/relations.server';
45
45
  import { removeSessionMcpOverlay } from '@/server/lib/mcp/session-overlay.server';
46
+ import { purgeChangeJournal } from '@/server/lib/changes/purge.server';
46
47
 
47
48
  export interface SessionPurgeResult {
48
49
  /** Something keyed to this id existed — a transcript, a mock session row, or
@@ -147,6 +148,9 @@ export async function purgeSessionData(sessionId: string): Promise<SessionPurgeR
147
148
  // The overlay is a temp directory, not a row: a deleted session must not
148
149
  // leave one behind for a future id to inherit.
149
150
  await removeSessionMcpOverlay(sessionId);
151
+ // The change journal holds file contents; a deleted session must not keep a
152
+ // copy of every file the run touched.
153
+ await purgeChangeJournal(sessionId);
150
154
 
151
155
  // A prompt waiting on this session will never be released: the dependency is
152
156
  // gone. Fail it BY NAME rather than letting it wait for a session that no
@@ -12,6 +12,7 @@ import {
12
12
  createAgentToken,
13
13
  hashAgentToken,
14
14
  initAgentTokens,
15
+ lookupAgentToken,
15
16
  rememberAgentToken,
16
17
  revokeAgentToken,
17
18
  verifyAgentToken,
@@ -53,12 +54,34 @@ describe('agent tokens', () => {
53
54
  });
54
55
 
55
56
  test('the path scope names the session it may touch', () => {
56
- expect(agentTokenScopeForPath('/api/sessions/spawn')).toBe('any');
57
- expect(agentTokenScopeForPath('/api/agent/s1')).toBe('s1');
58
- expect(agentTokenScopeForPath('/api/chat/s1')).toBe('s1');
59
- expect(agentTokenScopeForPath('/api/sessions/s1/fork')).toBe('s1');
60
- expect(agentTokenScopeForPath('/api/sessions/s1/relations')).toBe('s1');
57
+ expect(agentTokenScopeForPath('/api/sessions/spawn')).toEqual({ kind: 'any' });
58
+ expect(agentTokenScopeForPath('/api/agent/s1')).toEqual({ kind: 'tree', target: 's1' });
59
+ expect(agentTokenScopeForPath('/api/chat/s1')).toEqual({ kind: 'tree', target: 's1' });
60
+ expect(agentTokenScopeForPath('/api/sessions/s1/fork')).toEqual({ kind: 'tree', target: 's1' });
61
+ expect(agentTokenScopeForPath('/api/sessions/s1/relations')).toEqual({ kind: 'tree', target: 's1' });
61
62
  expect(agentTokenScopeForPath('/api/sessions/s1/archive')).toBeNull();
62
63
  expect(agentTokenScopeForPath('/api/settings')).toBeNull();
63
64
  });
65
+
66
+ test('a token this process never minted is found in the table', async () => {
67
+ // The peer-instance case: the owning process spawned the session, so this
68
+ // process's cache is empty while the row exists.
69
+ const token = createAgentToken();
70
+ await rememberAgentToken('s1', token);
71
+ globalThis.__kabmoAgentTokens = undefined;
72
+
73
+ expect(verifyAgentToken(token)).toBeNull();
74
+ expect(await lookupAgentToken(token)).toBe('s1');
75
+ // The read warms the cache, so the next call costs nothing.
76
+ expect(verifyAgentToken(token)).toBe('s1');
77
+ });
78
+
79
+ test('a revoked token is not resurrected by the table fallback', async () => {
80
+ const token = createAgentToken();
81
+ await rememberAgentToken('s1', token);
82
+ await revokeAgentToken('s1');
83
+ globalThis.__kabmoAgentTokens = undefined;
84
+
85
+ expect(await lookupAgentToken(token)).toBeNull();
86
+ });
64
87
  });
@@ -104,15 +104,51 @@ export function agentEnvironment(token: string): Record<string, string> {
104
104
  * What a token may touch, by path.
105
105
  *
106
106
  * `'any'` is only spawn: a child must be allowed to create its own children.
107
- * Every other path carries the session id it names, and the token must be that
108
- * session's. A token is not an admin credential.
107
+ * Every other path names a session, and the token must belong to that session's
108
+ * TREE — itself, an ancestor, or a descendant. The tree rule is what makes the
109
+ * shipped orchestration contract work: a worker tells its coordinator, and a
110
+ * coordinator reads its worker. A token is not an admin credential, and a
111
+ * sibling is not in the tree.
112
+ *
113
+ * The scope is a KIND, not an id, because the gate has to know which question
114
+ * to ask. Returning the id alone made the gate compare it to the token's
115
+ * session, which refused both directions of the parent/child edge.
109
116
  */
110
- export function agentTokenScopeForPath(pathname: string): 'any' | string | null {
111
- if (pathname === '/api/sessions/spawn') return 'any';
117
+ export type AgentPathScope =
118
+ | { kind: 'any' }
119
+ | { kind: 'tree'; target: string };
120
+
121
+ export function agentTokenScopeForPath(pathname: string): AgentPathScope | null {
122
+ if (pathname === '/api/sessions/spawn') return { kind: 'any' };
112
123
  const direct = /^\/api\/(?:agent|chat)\/([^/]+)$/.exec(pathname);
113
- if (direct) return direct[1] ?? null;
124
+ if (direct?.[1]) return { kind: 'tree', target: direct[1] };
114
125
  const sub = /^\/api\/sessions\/([^/]+)\/(?:fork|relations|answer)$/.exec(pathname);
115
- return sub?.[1] ?? null;
126
+ return sub?.[1] ? { kind: 'tree', target: sub[1] } : null;
127
+ }
128
+
129
+ /**
130
+ * The session a bearer token identifies, reading the table when the cache does
131
+ * not know it.
132
+ *
133
+ * The cache is per process and is filled at boot plus on every local spawn. A
134
+ * PEER instance that owns the session never saw that spawn, so a cache-only
135
+ * check answered 401 to a relayed agent request — the same class of failure the
136
+ * tree rule exists to remove. One indexed read on a miss, then the cache is
137
+ * warm for the rest of the process.
138
+ */
139
+ export async function lookupAgentToken(token: string | null): Promise<string | null> {
140
+ const cached = verifyAgentToken(token);
141
+ if (cached) return cached;
142
+ if (!token) return null;
143
+ const hash = hashAgentToken(token);
144
+ const db = await getDb();
145
+ const row = await db.get<{ session_id: string }>(
146
+ 'SELECT session_id FROM session_agent_tokens WHERE token_hash = ? AND revoked_at IS NULL',
147
+ [hash],
148
+ );
149
+ if (!row) return null;
150
+ cache().set(hash, { sessionId: row.session_id });
151
+ return row.session_id;
116
152
  }
117
153
 
118
154
  /** Drop the in-memory entry for a session whose rows are being purged. */