@kabmo-labs/kabmo 0.49.0 → 0.51.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 (524) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +606 -560
  3. package/dist/client/static/js/{Body-9h5hd351.js → Body-s3nh6vet.js} +3 -3
  4. package/dist/client/static/js/{CsvGrid-s05k1q18.js → CsvGrid-j4h6cpnn.js} +2 -2
  5. package/dist/client/static/js/{DocxView-x6sjw5ht.js → DocxView-197x16zq.js} +3 -3
  6. package/dist/client/static/js/{DrawioView-jashn8sf.js → DrawioView-v6ps0cm5.js} +2 -2
  7. package/dist/client/static/js/{HtmlPreview-eygzgtyc.js → HtmlPreview-a2t5zngp.js} +1 -1
  8. package/dist/client/static/js/ImageView-ar7hz7jx.js +1 -0
  9. package/dist/client/static/js/LayoutWrapper-epef152a.js +2 -0
  10. package/dist/client/static/js/MergeDiffView-7rwjvzk5.js +1 -0
  11. package/dist/client/static/js/Modal-9nxt67fm.js +60 -0
  12. package/dist/client/static/js/{PdfView-syhjmyqf.js → PdfView-gzhcym20.js} +1 -1
  13. package/dist/client/static/js/SessionsView-3h872gpe.js +1 -0
  14. package/dist/client/static/js/{SheetView-26r0e506.js → SheetView-baaynkb4.js} +22 -22
  15. package/dist/client/static/js/{SvgPreview-2fk85jzz.js → SvgPreview-jzcqwwcc.js} +1 -1
  16. package/dist/client/static/js/{abnfDiagram-O67JEVCF-fdka7pxr.js → abnfDiagram-O67JEVCF-grb1sfhr.js} +1 -1
  17. package/dist/client/static/js/architecture-7GRP2DOG-3hkq8grc.js +1 -0
  18. package/dist/client/static/js/architectureDiagram-NJMV4G6O-9084jzwr.js +36 -0
  19. package/dist/client/static/js/{astro-rn2bvwpm.js → astro-m3fcq2sa.js} +1 -1
  20. package/dist/client/static/js/bash-n7wcmq3s.js +1 -0
  21. package/dist/client/static/js/{blockDiagram-BEXU5L5S-vpcmd3vx.js → blockDiagram-BEXU5L5S-qqcjrg1b.js} +8 -8
  22. package/dist/client/static/js/c-ypdp030b.js +1 -0
  23. package/dist/client/static/js/{c4Diagram-YGBWAQC7-1rgpdnbq.js → c4Diagram-YGBWAQC7-gc8fqbpc.js} +3 -3
  24. package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-fbsejvb9.js → classDiagram-v2-NBCMYWYE-pp6060kq.js} +9 -9
  25. package/dist/client/static/js/cose-bilkent-JH36ORCC-744ekavk.js +1 -0
  26. package/dist/client/static/js/cpp-cxwev3gs.js +1 -0
  27. package/dist/client/static/js/css-6mxcqf8c.js +1 -0
  28. package/dist/client/static/js/css-9gak6bze.js +1 -0
  29. package/dist/client/static/js/cynefin-OW5HDTMX-9m18e6m5.js +1 -0
  30. package/dist/client/static/js/{cynefinDiagram-VND7K2PF-7ta5vbrw.js → cynefinDiagram-VND7K2PF-57dja6g9.js} +2 -2
  31. package/dist/client/static/js/{dagre-6A5THRUB-b8gtt32x.js → dagre-6A5THRUB-de4xrbrw.js} +2 -2
  32. package/dist/client/static/js/{diagram-22UHCM2B-7emepy7h.js → diagram-22UHCM2B-ky3ncyv8.js} +21 -21
  33. package/dist/client/static/js/diagram-3UASUU5V-zgg82bz9.js +24 -0
  34. package/dist/client/static/js/{diagram-ATOU4E4O-t113exk3.js → diagram-ATOU4E4O-r4s13e4n.js} +3 -3
  35. package/dist/client/static/js/{diagram-CDSNMT55-pyj3x97y.js → diagram-CDSNMT55-my21t0kq.js} +4 -4
  36. package/dist/client/static/js/{diagram-MLGK6HIB-183sgpjh.js → diagram-MLGK6HIB-pvt20jtj.js} +1 -1
  37. package/dist/client/static/js/{diagram-MPIPVDR6-fmbj4hcx.js → diagram-MPIPVDR6-as9dk4f3.js} +2 -2
  38. package/dist/client/static/js/{dockerfile-qay672za.js → dockerfile-3b5caedj.js} +1 -1
  39. package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-eafvfws2.js → ebnfDiagram-ZINNZB2B-tj3hkcj4.js} +1 -1
  40. package/dist/client/static/js/{elixir-t8bep87c.js → elixir-7q2k61zb.js} +1 -1
  41. package/dist/client/static/js/{elk-276RUBZZ-573f1vfs.js → elk-276RUBZZ-5e7wczf3.js} +1 -1
  42. package/dist/client/static/js/{erDiagram-OPXOYQCR-4z1r88ej.js → erDiagram-OPXOYQCR-5jje7qrh.js} +12 -12
  43. package/dist/client/static/js/{erlang-261km7r1.js → erlang-tjsd7n4d.js} +1 -1
  44. package/dist/client/static/js/eventmodeling-NTZA5JFV-d4egnv9v.js +1 -0
  45. package/dist/client/static/js/flowDiagram-KWPJA3E3-pdeqndnd.js +1 -0
  46. package/dist/client/static/js/{ganttDiagram-FUAMR5RP-49jd7msz.js → ganttDiagram-FUAMR5RP-7hresycc.js} +6 -6
  47. package/dist/client/static/js/gitGraph-4MIJSDKK-grqv890n.js +1 -0
  48. package/dist/client/static/js/gitGraphDiagram-X574FWY7-8m202jb7.js +106 -0
  49. package/dist/client/static/js/graphql-6rwdfcnf.js +1 -0
  50. package/dist/client/static/js/html-p76eszt9.js +1 -0
  51. package/dist/client/static/js/{index-0w4jqzqk.js → index-0prwdwyb.js} +2 -2
  52. package/dist/client/static/js/{index-3v8k8ms3.js → index-0y6tstk8.js} +1 -1
  53. package/dist/client/static/js/index-20hj80g4.js +4 -0
  54. package/dist/client/static/js/index-21421tq7.js +2 -0
  55. package/dist/client/static/js/{index-gg910gpv.js → index-254387vg.js} +2 -2
  56. package/dist/client/static/js/index-2y4gk5q5.js +2 -0
  57. package/dist/client/static/js/index-3fk8grhz.js +2 -0
  58. package/dist/client/static/js/index-3rrdmk9m.js +2 -0
  59. package/dist/client/static/js/{index-rz0tz4hg.js → index-3sz9cztk.js} +1 -1
  60. package/dist/client/static/js/index-4m2d73m3.css +1 -0
  61. package/dist/client/static/js/{index-2bf0txsp.js → index-4nvcwtvr.js} +2 -2
  62. package/dist/client/static/js/index-4ppap7vb.js +9 -0
  63. package/dist/client/static/js/{index-qs4n116g.js → index-4tbdws4r.js} +2 -2
  64. package/dist/client/static/js/index-56hy2hcy.js +1 -0
  65. package/dist/client/static/js/{index-7rmps91t.js → index-60g0e74a.js} +2 -2
  66. package/dist/client/static/js/{index-zp40g8ah.js → index-7ag37ghj.js} +12 -12
  67. package/dist/client/static/js/{index-z6y8j93w.js → index-7ehcjb3r.js} +7 -7
  68. package/dist/client/static/js/index-899yw6fh.js +2 -0
  69. package/dist/client/static/js/{index-2yzt8h3d.js → index-8pqx5n2p.js} +2 -2
  70. package/dist/client/static/js/{index-dh060b7r.js → index-91jm3ywm.js} +2 -2
  71. package/dist/client/static/js/{index-yg083mk0.js → index-9qf2h9jb.js} +6 -6
  72. package/dist/client/static/js/{index-tcfpzqb9.js → index-9rp7h1nv.js} +20 -20
  73. package/dist/client/static/js/index-9rr23e0e.js +2 -0
  74. package/dist/client/static/js/index-9wj4ma9g.js +3 -0
  75. package/dist/client/static/js/index-awtk0djy.js +1 -0
  76. package/dist/client/static/js/{index-4dnc1kys.js → index-awz6pyd0.js} +2 -2
  77. package/dist/client/static/js/index-cvx1vkrx.js +1 -0
  78. package/dist/client/static/js/{index-c3whkrwa.js → index-cwwg7k5f.js} +33 -33
  79. package/dist/client/static/js/{index-ykc14gez.js → index-dzatbdws.js} +6 -6
  80. package/dist/client/static/js/{index-j37m7pn9.js → index-e6ew77ph.js} +2 -2
  81. package/dist/client/static/js/{index-tb35a328.js → index-ej1va073.js} +2 -2
  82. package/dist/client/static/js/{index-4ccs971z.js → index-er7pj5k6.js} +2 -2
  83. package/dist/client/static/js/index-fm0t4pct.js +4 -0
  84. package/dist/client/static/js/{index-0857zpr0.js → index-g5wp6ksw.js} +2 -2
  85. package/dist/client/static/js/{index-nzvte8s5.js → index-gy4mtr2e.js} +2 -2
  86. package/dist/client/static/js/{index-1yq96wpa.js → index-j9y4tjk0.js} +2 -2
  87. package/dist/client/static/js/{index-7ff9scbm.js → index-kt7c42n7.js} +2 -2
  88. package/dist/client/static/js/index-ktmb341a.js +468 -0
  89. package/dist/client/static/js/{index-taev57jw.js → index-m6zncj00.js} +2 -2
  90. package/dist/client/static/js/{index-dmc82cxb.js → index-mpyd7qxj.js} +2 -2
  91. package/dist/client/static/js/{index-1p880x6e.js → index-ms80nne4.js} +2 -2
  92. package/dist/client/static/js/{index-yyjw1ty9.js → index-my856e49.js} +2 -2
  93. package/dist/client/static/js/{index-pygy21w5.js → index-nnqyew8n.js} +2 -2
  94. package/dist/client/static/js/{index-qwxawph7.js → index-nt17ejrm.js} +2 -2
  95. package/dist/client/static/js/index-pvv340b4.js +2 -0
  96. package/dist/client/static/js/{index-nbm5r9g1.js → index-pxr36neg.js} +2 -2
  97. package/dist/client/static/js/{index-5ztdqm1w.js → index-q0k1am0g.js} +2 -2
  98. package/dist/client/static/js/{index-tc6k8qt7.js → index-qrpx4sk1.js} +2 -2
  99. package/dist/client/static/js/{index-473hk8nb.js → index-r2zsw7nw.js} +9 -9
  100. package/dist/client/static/js/{index-gaqjrzdb.js → index-rbkvw2xs.js} +2 -2
  101. package/dist/client/static/js/{index-wbsvg1d9.js → index-scmtzcv1.js} +2 -2
  102. package/dist/client/static/js/{index-bmaktvm2.js → index-syvkpnc8.js} +1 -1
  103. package/dist/client/static/js/index-tfqqsj2g.js +1 -0
  104. package/dist/client/static/js/{index-4z5ram7g.js → index-tj7xr4ta.js} +1 -1
  105. package/dist/client/static/js/{index-h8hjcdj1.js → index-wvw70pgd.js} +2 -2
  106. package/dist/client/static/js/{index-5dn4159w.js → index-wxs0x3g1.js} +2 -2
  107. package/dist/client/static/js/index-x507ndnc.js +314 -0
  108. package/dist/client/static/js/{index-gr8sqjpz.js → index-x87scjpa.js} +1 -1
  109. package/dist/client/static/js/{index-s5vegk6q.js → index-xtrsvm0d.js} +2 -2
  110. package/dist/client/static/js/{index-e8mt8rag.js → index-y1j18rha.js} +2 -2
  111. package/dist/client/static/js/{index-7dqq7cjp.js → index-yv2ervdj.js} +5 -5
  112. package/dist/client/static/js/{index-gz7kvpnm.js → index-z2pmt1bc.js} +1 -1
  113. package/dist/client/static/js/{index-5p8dwr4y.js → index-z446edg9.js} +1 -1
  114. package/dist/client/static/js/{index-a4636gt1.js → index-zkgqa0c2.js} +2 -2
  115. package/dist/client/static/js/index-zwbw177x.js +2 -0
  116. package/dist/client/static/js/info-A6RAGUB7-rzpg7qk1.js +1 -0
  117. package/dist/client/static/js/{infoDiagram-VRGFBTTK-xsar9j6v.js → infoDiagram-VRGFBTTK-5mb5w005.js} +2 -2
  118. package/dist/client/static/js/ini-kjcpgebh.js +1 -0
  119. package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-g2rvt9jp.js → ishikawaDiagram-OU5B5YK6-zk7fa0fm.js} +2 -2
  120. package/dist/client/static/js/java-0bcyv1jt.js +1 -0
  121. package/dist/client/static/js/javascript-0mqgcvps.js +1 -0
  122. package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-q95v18zc.js → journeyDiagram-ZHPQQLJL-8jd7b2aw.js} +6 -6
  123. package/dist/client/static/js/json-mb8k0b1n.js +1 -0
  124. package/dist/client/static/js/jsx-8p6dqgpq.js +1 -0
  125. package/dist/client/static/js/{julia-pe5vpc2m.js → julia-nwh5w343.js} +1 -1
  126. package/dist/client/static/js/{kanban-definition-PNTS6WVX-2e7m7ds3.js → kanban-definition-PNTS6WVX-yp9rks4k.js} +7 -7
  127. package/dist/client/static/js/lua-nxnqww9z.js +1 -0
  128. package/dist/client/static/js/markdown-8gbyxxjd.js +1 -0
  129. package/dist/client/static/js/mermaid.core-kxsxr8ec.js +12 -0
  130. package/dist/client/static/js/{mindmap-definition-NLK3R4M7-banecvf8.js → mindmap-definition-NLK3R4M7-anx2kj3b.js} +7 -7
  131. package/dist/client/static/js/one-dark-pro-wyegjr0d.js +1 -0
  132. package/dist/client/static/js/one-light-kp6c3eqh.js +1 -0
  133. package/dist/client/static/js/packet-AYTQ26CC-eac14hsq.js +1 -0
  134. package/dist/client/static/js/{pegDiagram-GJSIUBJH-6erykm1c.js → pegDiagram-GJSIUBJH-9egqyzkc.js} +1 -1
  135. package/dist/client/static/js/{perl-cc2eqye8.js → perl-wb4wtc9x.js} +1 -1
  136. package/dist/client/static/js/{php-p9bvnpsv.js → php-9g594k9f.js} +1 -1
  137. package/dist/client/static/js/pie-WAS4IAKB-a9xqvysf.js +1 -0
  138. package/dist/client/static/js/{pieDiagram-5QR66LMP-jn1d905q.js → pieDiagram-5QR66LMP-f3dvprbm.js} +3 -3
  139. package/dist/client/static/js/properties-d5bwhgwz.js +1 -0
  140. package/dist/client/static/js/python-fdwwjjhh.js +1 -0
  141. package/dist/client/static/js/{quadrantDiagram-O4NWA36T-sz4afnp1.js → quadrantDiagram-O4NWA36T-qsghd295.js} +6 -6
  142. package/dist/client/static/js/r-4d2ygtfj.js +1 -0
  143. package/dist/client/static/js/radar-RG4KPBEZ-jv2pm0fe.js +1 -0
  144. package/dist/client/static/js/railroad-74A4TZTK-j74sc0b6.js +1 -0
  145. package/dist/client/static/js/railroad-abnf-HS5TGJTU-eaf19baz.js +1 -0
  146. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-d4j5nq31.js +1 -0
  147. package/dist/client/static/js/railroad-peg-WCYAUIDC-ba862a9p.js +1 -0
  148. package/dist/client/static/js/{railroadDiagram-XR7U4H2S-ewzhhth2.js → railroadDiagram-XR7U4H2S-6vmazht2.js} +1 -1
  149. package/dist/client/static/js/{requirementDiagram-PLB6GJNP-fcs3xd42.js → requirementDiagram-PLB6GJNP-phs0wn1v.js} +6 -6
  150. package/dist/client/static/js/{ruby-65s2ca5d.js → ruby-c4hxsegh.js} +1 -1
  151. package/dist/client/static/js/{rust-ec1j2hwy.js → rust-e4whdswc.js} +1 -1
  152. package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-2r829rjf.js → sankeyDiagram-IPEJSGJF-vkktegjk.js} +5 -5
  153. package/dist/client/static/js/{sass-p6cssgq8.js → sass-6yxywx7t.js} +1 -1
  154. package/dist/client/static/js/{scss-qfx8wt3b.js → scss-9wz47c6t.js} +1 -1
  155. package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-3mnte9tv.js → sequenceDiagram-PO4LG4MO-37e6se72.js} +13 -13
  156. package/dist/client/static/js/{sizeCapture-INFHLROL-r6hf9265.js → sizeCapture-INFHLROL-3b4nsa4s.js} +1 -1
  157. package/dist/client/static/js/sql-sd00wgem.js +1 -0
  158. package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-hm2f0wdb.js → stateDiagram-v2-GCMORJYK-2nnyqs9x.js} +6 -6
  159. package/dist/client/static/js/{svelte-jz3a190v.js → svelte-mm3jfpje.js} +1 -1
  160. package/dist/client/static/js/{swimlanes-2SLR337P-s58xzqhw.js → swimlanes-2SLR337P-eezd46ps.js} +1 -1
  161. package/dist/client/static/js/swimlanesDiagram-TC7HE7FX-h78096xp.js +8 -0
  162. package/dist/client/static/js/{timeline-definition-EJHVYXUP-ezm1c4pz.js → timeline-definition-EJHVYXUP-pz0f2b4h.js} +12 -12
  163. package/dist/client/static/js/treeView-Q6P3EWNA-e8yb44pd.js +1 -0
  164. package/dist/client/static/js/treemap-WGGIJYW6-zvdv84vp.js +1 -0
  165. package/dist/client/static/js/tsx-dk8rpgtw.js +1 -0
  166. package/dist/client/static/js/typescript-5txwpd9t.js +1 -0
  167. package/dist/client/static/js/{usecaseDiagram-POWQR4AR-ryvgs5ac.js → usecaseDiagram-POWQR4AR-hvg7a87b.js} +82 -82
  168. package/dist/client/static/js/{vennDiagram-UO4OBE2U-rd5prsf1.js → vennDiagram-UO4OBE2U-03zh9phs.js} +8 -8
  169. package/dist/client/static/js/{vue-rv4pea8r.js → vue-rcdqpz7q.js} +1 -1
  170. package/dist/client/static/js/wardley-WFR3VGLG-hbv0cg4s.js +1 -0
  171. package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-1kt8q8a4.js → wardleyDiagram-VNRHLVJA-xy77th92.js} +4 -4
  172. package/dist/client/static/js/xml-vtrdnrn6.js +1 -0
  173. package/dist/client/static/js/{xychartDiagram-PMCCYNJV-q39bbgq4.js → xychartDiagram-PMCCYNJV-h48448cm.js} +4 -4
  174. package/dist/client/static/js/yaml-6k1tmwtm.js +1 -0
  175. package/package.json +2 -1
  176. package/src/client/components/common/MarkdownRenderer.tsx +31 -34
  177. package/src/client/components/common/ViewportSelector.tsx +4 -0
  178. package/src/client/components/common/command-palette/index.tsx +5 -2
  179. package/src/client/components/common/header-button/index.tsx +10 -2
  180. package/src/client/components/common/markdown-inline-file.test.tsx +131 -0
  181. package/src/client/components/common/search-select/OptionList.tsx +164 -0
  182. package/src/client/components/common/search-select/index.tsx +159 -136
  183. package/src/client/components/common/search-select/option.ts +16 -0
  184. package/src/client/components/common/search-select/search-select.test.tsx +61 -2
  185. package/src/client/components/common/sort-menu/index.tsx +9 -4
  186. package/src/client/components/layout/session-sidebar/HarnessFilter.tsx +26 -6
  187. package/src/client/components/layout/session-sidebar/scheduler-modal/ModelFields.tsx +45 -49
  188. package/src/client/components/layout/session-sidebar/scheduler-modal/TaskForm.tsx +31 -25
  189. package/src/client/components/settings/ProjectSelectorDropdown.tsx +40 -101
  190. package/src/client/components/settings/apply-side-effects.test.ts +16 -0
  191. package/src/client/components/settings/apply-side-effects.ts +8 -0
  192. package/src/client/components/settings/categories/AppearanceSettings.test.tsx +1 -0
  193. package/src/client/components/settings/categories/AppearanceSettings.tsx +2 -0
  194. package/src/client/components/settings/categories/HarnessSettings.tsx +8 -0
  195. package/src/client/components/settings/categories/TokenUsageSettings.tsx +26 -3
  196. package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +12 -10
  197. package/src/client/components/settings/categories/appearance-settings/RightSideSection.test.tsx +97 -0
  198. package/src/client/components/settings/categories/appearance-settings/RightSideSection.tsx +94 -0
  199. package/src/client/components/settings/categories/appearance-settings/groups.ts +4 -3
  200. package/src/client/components/settings/categories/command-settings/DetailPane.tsx +12 -10
  201. package/src/client/components/settings/categories/dictation-settings/CaptureSection.tsx +13 -18
  202. package/src/client/components/settings/categories/git-settings/CommitMessageSection.tsx +8 -9
  203. package/src/client/components/settings/categories/harness-settings/AccountLoginPanel.tsx +224 -0
  204. package/src/client/components/settings/categories/harness-settings/AccountsPanel.test.tsx +139 -0
  205. package/src/client/components/settings/categories/harness-settings/AccountsPanel.tsx +349 -0
  206. package/src/client/components/settings/categories/harness-settings/AddAccountForm.tsx +58 -0
  207. package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +33 -0
  208. package/src/client/components/settings/categories/keyboard-settings/ComposerKeys.tsx +10 -10
  209. package/src/client/components/settings/categories/mcp-settings/AdvancedSection.tsx +21 -18
  210. package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +12 -7
  211. package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +11 -11
  212. package/src/client/components/settings/categories/omp-settings/RoleEditor.test.ts +14 -11
  213. package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +17 -16
  214. package/src/client/components/settings/categories/plugin-settings/MarketplacePane.tsx +11 -9
  215. package/src/client/components/settings/categories/plugin-settings/SettingsSection.tsx +10 -9
  216. package/src/client/components/settings/categories/provider-settings/AddModelModal.tsx +10 -8
  217. package/src/client/components/settings/categories/provider-settings/DialectFields.tsx +40 -24
  218. package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +13 -9
  219. package/src/client/components/settings/categories/provider-settings/EntryModal.tsx +22 -17
  220. package/src/client/components/settings/categories/provider-settings/PresetPicker.tsx +79 -50
  221. package/src/client/components/settings/categories/provider-settings/model-dialogs.test.tsx +14 -7
  222. package/src/client/components/settings/categories/token-usage-settings/HarnessFilter.tsx +59 -0
  223. package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +37 -0
  224. package/src/client/components/settings/categories/usage-settings/limit-groups.test.ts +10 -0
  225. package/src/client/components/settings/categories/usage-settings/limit-groups.ts +4 -1
  226. package/src/client/components/settings/categories/usage-settings/providers.ts +28 -0
  227. package/src/client/components/settings/categories/usage-settings/usage-visibility.test.ts +60 -0
  228. package/src/client/components/settings/categories/voice-settings/SpeechSettings.test.tsx +147 -5
  229. package/src/client/components/settings/categories/voice-settings/SpeechSettings.tsx +27 -3
  230. package/src/client/components/settings/categories/voice-settings/speech/EndpointSection.tsx +11 -3
  231. package/src/client/components/settings/categories/voice-settings/speech/EngineSection.tsx +32 -2
  232. package/src/client/components/settings/categories/voice-settings/speech/ModelsSection.tsx +277 -0
  233. package/src/client/components/settings/categories/voice-settings/speech/TestSection.tsx +2 -1
  234. package/src/client/components/settings/categories/voice-settings/speech/VoiceSection.tsx +123 -50
  235. package/src/client/components/workspace/btw-panel/TopicMenu.tsx +20 -2
  236. package/src/client/components/workspace/chat-timeline/AiMessageFooter.speech.test.tsx +35 -6
  237. package/src/client/components/workspace/chat-timeline/SpeechButton.tsx +111 -36
  238. package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.tsx +21 -6
  239. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +7 -4
  240. package/src/client/components/workspace/chat-timeline/chat-input/ThinkingLevelDropdown.tsx +22 -6
  241. package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +17 -1
  242. package/src/client/components/workspace/chat-timeline/tool-renderers/index.tsx +8 -65
  243. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.test.ts +12 -1
  244. package/src/client/components/workspace/chat-timeline/tool-renderers/registry.test.ts +35 -218
  245. package/src/client/components/workspace/chat-timeline/tool-renderers/registry.ts +40 -177
  246. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.test.ts +13 -1
  247. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/FallbackToolJson.test.tsx +79 -0
  248. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/FallbackToolJson.tsx +86 -0
  249. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolBody.tsx +25 -16
  250. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.test.ts +4 -2
  251. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/tool-view.ts +11 -4
  252. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Card.plugin.test.ts +3 -1
  253. package/src/client/components/workspace/file-explorer/ArchiveModals.tsx +15 -15
  254. package/src/client/components/workspace/git-panel/BranchToolbar.tsx +30 -5
  255. package/src/client/components/workspace/usage-panel/index.test.tsx +92 -12
  256. package/src/client/components/workspace/usage-panel/index.tsx +48 -12
  257. package/src/client/data/mock/chat.ts +17 -0
  258. package/src/client/data/mock/token-usage.ts +53 -10
  259. package/src/client/data/samples/tools-session.ts +8 -5
  260. package/src/client/hooks/chat/timeline/reader-input.ts +53 -1
  261. package/src/client/hooks/chat/timeline/scroll-activity.test.ts +103 -0
  262. package/src/client/hooks/chat/timeline/scroll-geometry.ts +9 -4
  263. package/src/client/hooks/chat/timeline/scroll.ts +19 -2
  264. package/src/client/hooks/editor/font.test.ts +21 -0
  265. package/src/client/hooks/editor/font.ts +12 -9
  266. package/src/client/hooks/models/harness-accounts.ts +143 -0
  267. package/src/client/hooks/models/harness-catalog.ts +9 -2
  268. package/src/client/hooks/models/use-harnesses-controller.ts +12 -0
  269. package/src/client/hooks/models/use-harnesses.ts +14 -0
  270. package/src/client/hooks/settings/hide-empty-providers.test.ts +132 -0
  271. package/src/client/hooks/settings/hide-empty-providers.ts +49 -0
  272. package/src/client/hooks/settings/local-tts-models.ts +164 -0
  273. package/src/client/hooks/settings/useTokenUsage.ts +7 -2
  274. package/src/client/hooks/tts/tts-context.ts +6 -0
  275. package/src/client/hooks/tts/use-tts-player.ts +10 -0
  276. package/src/client/hooks/ui/markdown-render.ts +9 -1
  277. package/src/client/hooks/ui/markdown-scoped-links.ts +77 -0
  278. package/src/client/hooks/ui/open-inline-file.test.ts +144 -0
  279. package/src/client/hooks/ui/open-inline-file.ts +71 -0
  280. package/src/client/hooks/workspace/panel-tabs.ts +1 -1
  281. package/src/client/hooks/workspace/right-side.test.ts +75 -1
  282. package/src/client/hooks/workspace/right-side.ts +71 -10
  283. package/src/client/lib/commands/overlays.ts +16 -2
  284. package/src/client/lib/tts/player.test.ts +61 -0
  285. package/src/client/lib/tts/player.ts +120 -41
  286. package/src/client/tailwind.css +16 -0
  287. package/src/server/lib/antigravity/home.server.ts +27 -0
  288. package/src/server/lib/chat/normalize-tools.server.test.ts +79 -0
  289. package/src/server/lib/chat/normalize-tools.server.ts +87 -0
  290. package/src/server/lib/db/schema.ts +5 -1
  291. package/src/server/lib/harness/account-identity.server.ts +163 -0
  292. package/src/server/lib/harness/account-login.server.test.ts +151 -0
  293. package/src/server/lib/harness/account-login.server.ts +232 -0
  294. package/src/server/lib/harness/accounts.server.ts +339 -0
  295. package/src/server/lib/harness/accounts.test.ts +147 -0
  296. package/src/server/lib/harness/acp/background-probe.test.ts +314 -0
  297. package/src/server/lib/harness/acp/background-probe.ts +288 -0
  298. package/src/server/lib/harness/acp/background-replay.test.ts +37 -1
  299. package/src/server/lib/harness/acp/background-replay.ts +8 -3
  300. package/src/server/lib/harness/acp/background-work.test.ts +4 -194
  301. package/src/server/lib/harness/acp/background-work.ts +4 -207
  302. package/src/server/lib/harness/acp/client.ts +3 -0
  303. package/src/server/lib/harness/acp/commands.ts +2 -2
  304. package/src/server/lib/harness/acp/frames-tool-shapes.test.ts +41 -13
  305. package/src/server/lib/harness/acp/frames-vendor-names.test.ts +209 -0
  306. package/src/server/lib/harness/acp/frames.test.ts +11 -20
  307. package/src/server/lib/harness/acp/frames.ts +5 -3
  308. package/src/server/lib/harness/acp/mapper.ts +5 -41
  309. package/src/server/lib/harness/acp/one-shot.server.ts +4 -2
  310. package/src/server/lib/harness/acp/prewarm.server.ts +21 -16
  311. package/src/server/lib/harness/acp/replay-transcript.ts +6 -1
  312. package/src/server/lib/harness/acp/session-background.test.ts +2 -1
  313. package/src/server/lib/harness/acp/session-intake.test.ts +8 -0
  314. package/src/server/lib/harness/acp/session-intake.ts +12 -3
  315. package/src/server/lib/harness/acp/session-options.ts +2 -0
  316. package/src/server/lib/harness/acp/session-process.ts +1 -0
  317. package/src/server/lib/harness/acp/session-wiring.test.ts +2 -0
  318. package/src/server/lib/harness/acp/session-wiring.ts +22 -0
  319. package/src/server/lib/harness/acp/session.ts +3 -3
  320. package/src/server/lib/harness/acp/stdio.test.ts +52 -0
  321. package/src/server/lib/harness/acp/stdio.ts +7 -1
  322. package/src/server/lib/harness/acp/subagent-frames.test.ts +1 -1
  323. package/src/server/lib/harness/acp/subagent-frames.ts +0 -2
  324. package/src/server/lib/harness/acp/tool-calls.ts +5 -16
  325. package/src/server/lib/harness/acp/tool-identity.test.ts +69 -8
  326. package/src/server/lib/harness/acp/tool-identity.ts +58 -10
  327. package/src/server/lib/harness/acp/tool-shape.ts +5 -3
  328. package/src/server/lib/harness/auto-probe.server.ts +2 -2
  329. package/src/server/lib/harness/codex/transcript.server.test.ts +3 -1
  330. package/src/server/lib/harness/codex/transcript.server.ts +8 -15
  331. package/src/server/lib/harness/launch-table.ts +6 -1
  332. package/src/server/lib/harness/launch.ts +1 -0
  333. package/src/server/lib/harness/schema.server.ts +37 -0
  334. package/src/server/lib/harness/session-delete.server.ts +4 -2
  335. package/src/server/lib/harness/session-import.server.ts +21 -7
  336. package/src/server/lib/harness/session-store.server.test.ts +12 -0
  337. package/src/server/lib/harness/session-store.server.ts +21 -6
  338. package/src/server/lib/harness/session-transcript.server.ts +2 -1
  339. package/src/server/lib/harness/spawn.server.ts +27 -6
  340. package/src/server/lib/lifecycle/paths.ts +12 -0
  341. package/src/server/lib/models/provider-icon-fetch.test.ts +57 -3
  342. package/src/server/lib/models/provider-icon-fetch.ts +9 -1
  343. package/src/server/lib/models/provider-icon-store.server.ts +61 -0
  344. package/src/server/lib/models/provider-icon-store.test.ts +55 -0
  345. package/src/server/lib/models/provider-icon-svg.ts +57 -0
  346. package/src/server/lib/omp/session/messages.ts +5 -1
  347. package/src/server/lib/realtime/topics/peer-relay.server.ts +9 -1
  348. package/src/server/lib/realtime/topics/session.server.ts +5 -1
  349. package/src/server/lib/schedule/runtime.server.ts +4 -1
  350. package/src/server/lib/sessions/dispatch.server.ts +4 -1
  351. package/src/server/lib/sessions/fork.server.ts +2 -0
  352. package/src/server/lib/sessions/resolve.server.ts +4 -0
  353. package/src/server/lib/sessions/spawn.server.ts +4 -2
  354. package/src/server/lib/tts/engines/adapters.test.ts +50 -8
  355. package/src/server/lib/tts/engines/deepgram.ts +30 -9
  356. package/src/server/lib/tts/engines/elevenlabs.ts +6 -0
  357. package/src/server/lib/tts/engines/gemini.ts +116 -0
  358. package/src/server/lib/tts/engines/index.ts +14 -0
  359. package/src/server/lib/tts/engines/local.ts +53 -0
  360. package/src/server/lib/tts/engines/openai.ts +21 -4
  361. package/src/server/lib/tts/engines/sherpa-onnx-node.d.ts +38 -0
  362. package/src/server/lib/tts/engines/sherpa.test.ts +53 -0
  363. package/src/server/lib/tts/engines/sherpa.ts +287 -0
  364. package/src/server/lib/tts/local-models.server.ts +257 -0
  365. package/src/server/lib/tts/local-request.test.ts +66 -0
  366. package/src/server/lib/tts/local-request.ts +59 -0
  367. package/src/server/lib/tts/model-manifest.server.test.ts +71 -0
  368. package/src/server/lib/tts/model-manifest.server.ts +154 -0
  369. package/src/server/lib/tts/settings.server.ts +7 -4
  370. package/src/server/lib/tts/wav.test.ts +37 -0
  371. package/src/server/lib/tts/wav.ts +43 -0
  372. package/src/server/lib/usage/antigravity-quota.test.ts +249 -0
  373. package/src/server/lib/usage/antigravity-quota.ts +197 -0
  374. package/src/server/lib/usage/antigravity.test.ts +20 -0
  375. package/src/server/lib/usage/antigravity.ts +267 -0
  376. package/src/server/lib/usage/index-harness.test.ts +162 -0
  377. package/src/server/lib/usage/index-parse.test.ts +1 -0
  378. package/src/server/lib/usage/index-parse.ts +12 -4
  379. package/src/server/lib/usage/index-query.server.ts +64 -2
  380. package/src/server/lib/usage/index-scan.server.ts +68 -152
  381. package/src/server/lib/usage/index-schema.server.ts +24 -8
  382. package/src/server/lib/usage/index-schema.test.ts +54 -0
  383. package/src/server/lib/usage/index-sources.server.ts +54 -0
  384. package/src/server/lib/usage/providers.server.test.ts +67 -1
  385. package/src/server/lib/usage/providers.server.ts +82 -3
  386. package/src/server/lib/usage/sources/claude.server.ts +187 -0
  387. package/src/server/lib/usage/sources/claude.test.ts +86 -0
  388. package/src/server/lib/usage/sources/codex.server.ts +155 -0
  389. package/src/server/lib/usage/sources/codex.test.ts +53 -0
  390. package/src/server/lib/usage/sources/dsh.server.ts +120 -0
  391. package/src/server/lib/usage/sources/dsh.test.ts +49 -0
  392. package/src/server/lib/usage/sources/helpers.ts +191 -0
  393. package/src/server/lib/usage/sources/jsonl.server.ts +78 -0
  394. package/src/server/lib/usage/sources/jsonl.test.ts +72 -0
  395. package/src/server/lib/usage/sources/omp.server.ts +124 -0
  396. package/src/server/lib/usage/sources/opencode.server.ts +203 -0
  397. package/src/server/lib/usage/sources/opencode.test.ts +104 -0
  398. package/src/server/lib/usage/sources/qwen.server.ts +122 -0
  399. package/src/server/lib/usage/sources/qwen.test.ts +62 -0
  400. package/src/server/lib/usage/sources/types.ts +53 -0
  401. package/src/server/lib/usage/sources/zcode.server.ts +131 -0
  402. package/src/server/lib/usage/sources/zcode.test.ts +87 -0
  403. package/src/server/routes/agent/harness-command.ts +2 -0
  404. package/src/server/routes/agent/prewarm.ts +7 -2
  405. package/src/server/routes/chat/session-legacy-tools.test.ts +132 -0
  406. package/src/server/routes/chat/session.ts +10 -4
  407. package/src/server/routes/harness/accounts.test.ts +99 -0
  408. package/src/server/routes/harness/accounts.ts +106 -0
  409. package/src/server/routes/harness/root.ts +13 -1
  410. package/src/server/routes/sessions/local-image.ts +2 -2
  411. package/src/server/routes/telemetry/tokens.test.ts +20 -0
  412. package/src/server/routes/telemetry/tokens.ts +12 -3
  413. package/src/server/routes/tts/index.ts +2 -0
  414. package/src/server/routes/tts/models.test.ts +148 -0
  415. package/src/server/routes/tts/models.ts +89 -0
  416. package/src/server/routes/tts/speak.test.ts +40 -0
  417. package/src/shared/lib/chat/tool/normalize.ts +67 -0
  418. package/src/shared/lib/chat/tool/render-key.test.ts +167 -0
  419. package/src/shared/lib/chat/tool/render-key.ts +247 -0
  420. package/src/shared/lib/chat/tool/tool-aliases.test.ts +42 -0
  421. package/src/shared/lib/chat/tool/tool-aliases.ts +59 -12
  422. package/src/shared/lib/fs/open-reference.test.ts +64 -0
  423. package/src/shared/lib/fs/open-reference.ts +74 -0
  424. package/src/shared/lib/harness/accounts.test.ts +41 -0
  425. package/src/shared/lib/harness/accounts.ts +175 -0
  426. package/src/shared/lib/icons/tint-hues.generated.ts +26 -25
  427. package/src/shared/lib/markdown/ascii-art.test.ts +154 -0
  428. package/src/shared/lib/markdown/ascii-art.ts +158 -0
  429. package/src/shared/lib/markdown/inline-file.test.ts +100 -0
  430. package/src/shared/lib/markdown/inline-file.ts +213 -0
  431. package/src/shared/lib/markdown/marked.ts +24 -2
  432. package/src/shared/lib/models/provider/identity.test.ts +34 -0
  433. package/src/shared/lib/models/provider/identity.ts +28 -0
  434. package/src/shared/lib/omp/session/messages-map.test.ts +2 -1
  435. package/src/shared/lib/omp/session/messages-parse.ts +3 -2
  436. package/src/shared/lib/omp/session/parse-message-blocks.ts +14 -0
  437. package/src/shared/lib/omp/subagent/transcript-client.ts +5 -1
  438. package/src/shared/lib/settings/defaults.ts +2 -0
  439. package/src/shared/lib/tts/engines.test.ts +39 -2
  440. package/src/shared/lib/tts/engines.ts +87 -61
  441. package/src/shared/lib/tts/local-models.test.ts +69 -0
  442. package/src/shared/lib/tts/local-models.ts +200 -0
  443. package/src/shared/lib/tts/settings.ts +1 -1
  444. package/src/shared/lib/tts/speakable.test.ts +21 -1
  445. package/src/shared/lib/tts/speakable.ts +66 -33
  446. package/src/shared/lib/tts/voices.ts +204 -0
  447. package/src/shared/lib/workspace/right-side-hidden.ts +57 -0
  448. package/src/shared/lib/workspace/session-state/store.ts +7 -5
  449. package/src/shared/types/chat.ts +3 -0
  450. package/src/shared/types/harness.ts +5 -0
  451. package/src/shared/types/index.ts +1 -0
  452. package/src/shared/types/settings/state.ts +12 -0
  453. package/src/shared/types/tokenUsage.ts +21 -0
  454. package/src/shared/types/tool-render.ts +37 -0
  455. package/src/test-support/preload.ts +9 -0
  456. package/dist/client/static/js/ImageView-g50pk5pt.js +0 -1
  457. package/dist/client/static/js/LayoutWrapper-tag0qpts.js +0 -2
  458. package/dist/client/static/js/MergeDiffView-c4mb8m1w.js +0 -1
  459. package/dist/client/static/js/Modal-pf9p6m1k.js +0 -59
  460. package/dist/client/static/js/SessionsView-2r1grxxs.js +0 -1
  461. package/dist/client/static/js/architecture-7GRP2DOG-ee9wjsht.js +0 -1
  462. package/dist/client/static/js/architectureDiagram-NJMV4G6O-278nx8rt.js +0 -36
  463. package/dist/client/static/js/bash-36shcpcw.js +0 -1
  464. package/dist/client/static/js/c-kxeqssf9.js +0 -1
  465. package/dist/client/static/js/cose-bilkent-JH36ORCC-ydq7mvy0.js +0 -1
  466. package/dist/client/static/js/cpp-wtk1s3d7.js +0 -1
  467. package/dist/client/static/js/css-0a0r6rp3.js +0 -1
  468. package/dist/client/static/js/css-xhnrhg4e.js +0 -1
  469. package/dist/client/static/js/cynefin-OW5HDTMX-gs16zjqa.js +0 -1
  470. package/dist/client/static/js/diagram-3UASUU5V-06nptkzc.js +0 -24
  471. package/dist/client/static/js/eventmodeling-NTZA5JFV-ftz7zrz5.js +0 -1
  472. package/dist/client/static/js/flowDiagram-KWPJA3E3-ax0qfmp3.js +0 -1
  473. package/dist/client/static/js/gitGraph-4MIJSDKK-3rtkds4s.js +0 -1
  474. package/dist/client/static/js/gitGraphDiagram-X574FWY7-5p9mgq7n.js +0 -106
  475. package/dist/client/static/js/graphql-w9ajhndp.js +0 -1
  476. package/dist/client/static/js/html-krfbq5wp.js +0 -1
  477. package/dist/client/static/js/index-05n22cg9.js +0 -4
  478. package/dist/client/static/js/index-14dgbjsm.js +0 -2
  479. package/dist/client/static/js/index-2jgx68m0.js +0 -1
  480. package/dist/client/static/js/index-333rq9yy.js +0 -1
  481. package/dist/client/static/js/index-38g2eevc.js +0 -314
  482. package/dist/client/static/js/index-80fjn77c.js +0 -2
  483. package/dist/client/static/js/index-9wc36am3.css +0 -1
  484. package/dist/client/static/js/index-bvpzzhn2.js +0 -4
  485. package/dist/client/static/js/index-e19dbqd3.js +0 -2
  486. package/dist/client/static/js/index-epzvftkq.js +0 -1
  487. package/dist/client/static/js/index-fbg5vhhw.js +0 -2
  488. package/dist/client/static/js/index-mbtenbyc.js +0 -9
  489. package/dist/client/static/js/index-pv4z2mp2.js +0 -463
  490. package/dist/client/static/js/index-t522tpxt.js +0 -3
  491. package/dist/client/static/js/index-xw1bptp5.js +0 -2
  492. package/dist/client/static/js/index-yr3exz70.js +0 -2
  493. package/dist/client/static/js/index-zdw8bd5t.js +0 -2
  494. package/dist/client/static/js/index-zyefab6q.js +0 -1
  495. package/dist/client/static/js/info-A6RAGUB7-vr5mxm6f.js +0 -1
  496. package/dist/client/static/js/ini-zx7x1jj1.js +0 -1
  497. package/dist/client/static/js/java-bbw6kdcr.js +0 -1
  498. package/dist/client/static/js/javascript-p2a8rbpw.js +0 -1
  499. package/dist/client/static/js/json-zh7m2fyg.js +0 -1
  500. package/dist/client/static/js/jsx-3zyyt0eh.js +0 -1
  501. package/dist/client/static/js/lua-d656k76a.js +0 -1
  502. package/dist/client/static/js/markdown-b5w681mm.js +0 -1
  503. package/dist/client/static/js/mermaid.core-dzajkp0g.js +0 -12
  504. package/dist/client/static/js/one-dark-pro-z965dedc.js +0 -1
  505. package/dist/client/static/js/one-light-capdx801.js +0 -1
  506. package/dist/client/static/js/packet-AYTQ26CC-ncb5xxtn.js +0 -1
  507. package/dist/client/static/js/pie-WAS4IAKB-ff8fpvc4.js +0 -1
  508. package/dist/client/static/js/properties-3c6rmnqp.js +0 -1
  509. package/dist/client/static/js/python-a3x3zpv1.js +0 -1
  510. package/dist/client/static/js/r-7h3gwype.js +0 -1
  511. package/dist/client/static/js/radar-RG4KPBEZ-gbj4b1hf.js +0 -1
  512. package/dist/client/static/js/railroad-74A4TZTK-ndv5tqgr.js +0 -1
  513. package/dist/client/static/js/railroad-abnf-HS5TGJTU-yjzj09s1.js +0 -1
  514. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-e6pw7e5z.js +0 -1
  515. package/dist/client/static/js/railroad-peg-WCYAUIDC-9734dxy4.js +0 -1
  516. package/dist/client/static/js/sql-7a5vavm0.js +0 -1
  517. package/dist/client/static/js/swimlanesDiagram-TC7HE7FX-z4pt2kn1.js +0 -8
  518. package/dist/client/static/js/treeView-Q6P3EWNA-rs10d4p5.js +0 -1
  519. package/dist/client/static/js/treemap-WGGIJYW6-ey6c5x9f.js +0 -1
  520. package/dist/client/static/js/tsx-4a9b8tqf.js +0 -1
  521. package/dist/client/static/js/typescript-kas107wb.js +0 -1
  522. package/dist/client/static/js/wardley-WFR3VGLG-kd9swrdr.js +0 -1
  523. package/dist/client/static/js/xml-3g4bdtpa.js +0 -1
  524. package/dist/client/static/js/yaml-ktxjn917.js +0 -1
@@ -0,0 +1,203 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * OpenCode's local database: `$XDG_DATA_HOME/opencode/opencode.db`.
8
+ *
9
+ * Two schema generations exist in the wild. `message` (v1) stores the assistant
10
+ * row's `tokens`/`cost` inline; `session_message` (v2) stores the same counters
11
+ * in `data`. A session is read from ONE of them — a migrated install can hold
12
+ * rows in both, and folding both would count the same turn twice. v2 wins for a
13
+ * session that has any v2 message.
14
+ *
15
+ * OpenCode reports its own cost, so a row with tokens and no cost is genuinely
16
+ * unpriced rather than missing a parser.
17
+ */
18
+
19
+ import { Database } from 'bun:sqlite';
20
+ import fs from 'node:fs';
21
+ import { join } from 'node:path';
22
+
23
+ import type { HarnessId } from '@/shared/lib/harness/catalog';
24
+ import { isRecord } from '@/shared/lib/util/guards';
25
+ import type { UsageRollupRow } from '@/server/lib/usage/index-parse';
26
+ import {
27
+ addUsage,
28
+ countOf,
29
+ costOf,
30
+ dayOfMs,
31
+ projectFromCwd,
32
+ statOrNull,
33
+ storeHome,
34
+ } from '@/server/lib/usage/sources/helpers';
35
+ import type { UsageSource, UsageSourceFile, UsageSourceRead } from '@/server/lib/usage/sources/types';
36
+
37
+ const HARNESS: HarnessId = 'opencode';
38
+
39
+ interface MessageRow {
40
+ session_id: string;
41
+ time_created: number;
42
+ data: string;
43
+ }
44
+
45
+ function databasePath(): string {
46
+ return join(storeHome('XDG_DATA_HOME', '.local/share'), 'opencode', 'opencode.db');
47
+ }
48
+
49
+ function projectOf(data: Record<string, unknown>, sessions: Map<string, string>, sessionId: string): string {
50
+ const fromSession = sessions.get(sessionId);
51
+ if (fromSession) return fromSession;
52
+ const path = isRecord(data.path) ? data.path : null;
53
+ return projectFromCwd(path?.cwd) || 'opencode';
54
+ }
55
+
56
+ /** One assistant row's counters, or null when it is not a billed turn. */
57
+ function foldAssistant(
58
+ rows: Map<string, UsageRollupRow>,
59
+ sessions: Map<string, string>,
60
+ row: MessageRow,
61
+ data: Record<string, unknown>,
62
+ ): void {
63
+ const tokens = isRecord(data.tokens) ? data.tokens : null;
64
+ if (!tokens) return;
65
+ const cache = isRecord(tokens.cache) ? tokens.cache : null;
66
+ const input = countOf(tokens.input);
67
+ const output = countOf(tokens.output);
68
+ const reasoning = countOf(tokens.reasoning);
69
+ const cacheRead = countOf(cache?.read);
70
+ const cacheWrite = countOf(cache?.write);
71
+ const total = countOf(tokens.total) || input + output + reasoning + cacheRead + cacheWrite;
72
+ const cost = costOf(data.cost);
73
+ if (total === 0 && cost === 0) return;
74
+
75
+ const model = isRecord(data.model) ? data.model : null;
76
+ const provider = typeof model?.providerID === 'string' && model.providerID
77
+ ? model.providerID
78
+ : typeof data.providerID === 'string' && data.providerID ? data.providerID : HARNESS;
79
+ const modelId = typeof model?.modelID === 'string' && model.modelID
80
+ ? model.modelID
81
+ : typeof model?.id === 'string' && model.id
82
+ ? model.id
83
+ : typeof data.modelID === 'string' && data.modelID ? data.modelID : 'unknown';
84
+ const time = isRecord(data.time) ? data.time : null;
85
+ const day = dayOfMs(time?.created) || dayOfMs(row.time_created);
86
+
87
+ addUsage(rows, {
88
+ project: projectOf(data, sessions, row.session_id),
89
+ harness: HARNESS,
90
+ provider,
91
+ model: modelId,
92
+ day,
93
+ usage: { input, output, reasoning, cacheRead, cacheWrite, total, cost },
94
+ });
95
+ }
96
+
97
+ function sessionProjects(db: Database): Map<string, string> {
98
+ const projects = new Map<string, string>();
99
+ for (const table of ['session', 'session_v2']) {
100
+ try {
101
+ const rows = db.query(`SELECT id, directory FROM ${table}`).all() as { id: string; directory: string }[];
102
+ for (const row of rows) {
103
+ const project = projectFromCwd(row.directory);
104
+ if (project) projects.set(row.id, project);
105
+ }
106
+ return projects;
107
+ } catch {
108
+ // This install predates (or postdates) the table; the next one answers.
109
+ }
110
+ }
111
+ return projects;
112
+ }
113
+
114
+ /**
115
+ * Fold one OpenCode database.
116
+ *
117
+ * `null` means the database could not be READ at all (locked, corrupt, no
118
+ * message table); the caller then keeps the rows it already had. An empty map
119
+ * would tell the index to delete a chat's history because the agent happened to
120
+ * hold the write lock during a scan.
121
+ */
122
+ export function opencodeRowsFromPath(path: string): Map<string, UsageRollupRow> | null {
123
+ const rows = new Map<string, UsageRollupRow>();
124
+ let db: Database | null = null;
125
+ let answered = false;
126
+ try {
127
+ db = new Database(path, { readonly: true });
128
+ db.exec('PRAGMA busy_timeout = 500');
129
+ const sessions = sessionProjects(db);
130
+
131
+ const v2Sessions = new Set<string>();
132
+ const v2Rows: MessageRow[] = [];
133
+ try {
134
+ for (const row of db.query('SELECT session_id, time_created, type, data FROM session_message').all() as Array<MessageRow & { type: string }>) {
135
+ v2Sessions.add(row.session_id);
136
+ if (row.type === 'assistant') v2Rows.push(row);
137
+ }
138
+ answered = true;
139
+ } catch {
140
+ // v1-only install.
141
+ }
142
+
143
+ for (const row of v2Rows) {
144
+ try {
145
+ const data: unknown = JSON.parse(row.data);
146
+ if (isRecord(data)) foldAssistant(rows, sessions, row, data);
147
+ } catch {
148
+ // A torn row is skipped, never invented.
149
+ }
150
+ }
151
+
152
+ let v1Rows: Array<MessageRow & { role?: string }> = [];
153
+ try {
154
+ v1Rows = db.query('SELECT session_id, time_created, data FROM message').all() as Array<MessageRow & { role?: string }>;
155
+ answered = true;
156
+ } catch {
157
+ v1Rows = [];
158
+ }
159
+ for (const row of v1Rows) {
160
+ if (v2Sessions.has(row.session_id)) continue;
161
+ try {
162
+ const data: unknown = JSON.parse(row.data);
163
+ if (isRecord(data) && data.role === 'assistant') foldAssistant(rows, sessions, row, data);
164
+ } catch {
165
+ // Torn row.
166
+ }
167
+ }
168
+ } catch {
169
+ return null;
170
+ } finally {
171
+ db?.close();
172
+ }
173
+ return answered ? rows : null;
174
+ }
175
+
176
+ async function list(): Promise<UsageSourceFile[]> {
177
+ const path = databasePath();
178
+ const stat = await statOrNull(path);
179
+ if (!stat) return [];
180
+ // WAL writes do not touch the main file's mtime, so the -wal sidecar is part
181
+ // of the change signature or a running OpenCode looks unchanged forever.
182
+ const wal = await statOrNull(`${path}-wal`);
183
+ return [{
184
+ key: `opencode:${path}`,
185
+ harness: HARNESS,
186
+ project: 'opencode',
187
+ size: stat.size + (wal?.size ?? 0),
188
+ mtimeMs: Math.max(stat.mtimeMs, wal?.mtimeMs ?? 0),
189
+ }];
190
+ }
191
+
192
+ async function read(file: UsageSourceFile): Promise<UsageSourceRead | null> {
193
+ const path = file.key.slice('opencode:'.length);
194
+ try {
195
+ if (!(await fs.promises.stat(path)).isFile()) return null;
196
+ } catch {
197
+ return null;
198
+ }
199
+ const rows = opencodeRowsFromPath(path);
200
+ return rows ? { rows, nextOffset: file.size, append: false } : null;
201
+ }
202
+
203
+ export const opencodeSource: UsageSource = { id: 'opencode', list, read };
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The OpenCode database reader.
8
+ *
9
+ * v1 (`message`) and v2 (`session_message`) can both hold a migrated session.
10
+ * The v2 row wins, or every migrated turn is counted twice; cost is the
11
+ * provider's own number, and a zero-cost turn is unpriced rather than free.
12
+ */
13
+
14
+ import { Database } from 'bun:sqlite';
15
+ import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
16
+ import fs from 'node:fs';
17
+ import os from 'node:os';
18
+ import { join } from 'node:path';
19
+
20
+ import { opencodeRowsFromPath } from '@/server/lib/usage/sources/opencode.server';
21
+ import { removeDir } from '@/test-support/remove-dir';
22
+
23
+ let dir = '';
24
+ let path = '';
25
+
26
+ beforeAll(() => {
27
+ dir = fs.mkdtempSync(join(os.tmpdir(), 'kabmo-opencode-'));
28
+ path = join(dir, 'opencode.db');
29
+ const db = new Database(path);
30
+ db.exec(`
31
+ CREATE TABLE session (id TEXT PRIMARY KEY, directory TEXT);
32
+ CREATE TABLE message (id TEXT PRIMARY KEY, session_id TEXT, time_created INTEGER, data TEXT);
33
+ CREATE TABLE session_message (id TEXT PRIMARY KEY, session_id TEXT, time_created INTEGER, type TEXT, data TEXT);
34
+ `);
35
+ db.run('INSERT INTO session (id, directory) VALUES (?, ?)', ['both', '/Users/dev/projects/kabmo']);
36
+ db.run('INSERT INTO session (id, directory) VALUES (?, ?)', ['v1', '/Users/dev/projects/omp']);
37
+ // A migrated session: the v1 row must not be read while v2 has a row.
38
+ db.run('INSERT INTO message (id, session_id, time_created, data) VALUES (?, ?, ?, ?)', [
39
+ 'm-v1',
40
+ 'both',
41
+ 1795000000000,
42
+ JSON.stringify({
43
+ role: 'assistant',
44
+ cost: 9,
45
+ tokens: { input: 1, output: 1, cache: { read: 0, write: 0 } },
46
+ modelID: 'old-model',
47
+ providerID: 'opencode',
48
+ }),
49
+ ]);
50
+ db.run('INSERT INTO session_message (id, session_id, time_created, type, data) VALUES (?, ?, ?, ?, ?)', [
51
+ 'm-v2',
52
+ 'both',
53
+ 1795000000000,
54
+ 'assistant',
55
+ JSON.stringify({
56
+ model: { providerID: 'kenari', id: 'deepseek-v4' },
57
+ cost: 0.25,
58
+ tokens: { input: 10, output: 5, reasoning: 2, cache: { read: 100, write: 3 } },
59
+ time: { created: 1795000000000 },
60
+ }),
61
+ ]);
62
+ db.run('INSERT INTO message (id, session_id, time_created, data) VALUES (?, ?, ?, ?)', [
63
+ 'm-v1b',
64
+ 'v1',
65
+ 1795000000000,
66
+ JSON.stringify({
67
+ role: 'assistant',
68
+ cost: 1,
69
+ tokens: { input: 4, output: 2, cache: { read: 40, write: 0 } },
70
+ modelID: 'deepseek-v4',
71
+ providerID: 'kenari',
72
+ }),
73
+ ]);
74
+ db.close();
75
+ });
76
+
77
+ afterAll(() => {
78
+ removeDir(dir);
79
+ });
80
+
81
+ describe('opencodeRowsFromPath', () => {
82
+ test('reads the v2 row for a migrated session and the v1 row for the rest', () => {
83
+ const folded = opencodeRowsFromPath(path);
84
+ expect(folded).not.toBeNull();
85
+ const rows = [...(folded ?? new Map()).values()];
86
+ expect(rows).toHaveLength(2);
87
+ const migrated = rows.find((row) => row.project === 'kabmo');
88
+ const legacy = rows.find((row) => row.project === 'omp');
89
+ expect(migrated?.provider).toBe('kenari');
90
+ expect(migrated?.model).toBe('deepseek-v4');
91
+ expect(migrated?.records).toBe(1);
92
+ expect(migrated?.costTotal).toBe(0.25);
93
+ expect(migrated?.input).toBe(10);
94
+ expect(migrated?.cacheRead).toBe(100);
95
+ expect(legacy?.model).toBe('deepseek-v4');
96
+ expect(legacy?.costTotal).toBe(1);
97
+ });
98
+
99
+ test('an unreadable database is null, not an empty period', () => {
100
+ // Committing an empty map would DELETE the rows a chat already contributed;
101
+ // a locked or corrupt store must leave the index alone.
102
+ expect(opencodeRowsFromPath(join(dir, 'absent.db'))).toBeNull();
103
+ });
104
+ });
@@ -0,0 +1,122 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Qwen CLI's token log: `QWEN_HOME/usage/token-usage-YYYY-MM.jsonl`.
8
+ *
9
+ * The cleanest of the ACP stores — one record per model request with the model,
10
+ * the token split and the session id. It has no cwd, so the project comes from
11
+ * the session's own chat file under `projects/<encoded-cwd>/chats/<id>.jsonl`.
12
+ *
13
+ * `inputTokens` includes the cached prompt (the log reports `cachedTokens`
14
+ * separately), so the uncached input subtracts it, exactly as the Codex reader
15
+ * does; otherwise cache reads are counted twice in the panel's hit rate.
16
+ */
17
+
18
+ import { join } from 'node:path';
19
+
20
+ import type { HarnessId } from '@/shared/lib/harness/catalog';
21
+ import { isRecord } from '@/shared/lib/util/guards';
22
+ import type { UsageRollupRow } from '@/server/lib/usage/index-parse';
23
+ import {
24
+ addUsage,
25
+ countOf,
26
+ dayOfIso,
27
+ names,
28
+ readdirOrEmpty,
29
+ statOrNull,
30
+ storeHome,
31
+ } from '@/server/lib/usage/sources/helpers';
32
+ import type { UsageSource, UsageSourceFile, UsageSourceRead } from '@/server/lib/usage/sources/types';
33
+
34
+ const HARNESS: HarnessId = 'qwen';
35
+ const ISO_DAY = /^\d{4}-\d{2}-\d{2}$/;
36
+
37
+ function qwenHome(): string {
38
+ return storeHome('QWEN_HOME', '.qwen');
39
+ }
40
+
41
+ /** `sessionId → project` from the chat files' own folder names. */
42
+ async function sessionProjects(): Promise<Map<string, string>> {
43
+ const projects = new Map<string, string>();
44
+ const root = join(qwenHome(), 'projects');
45
+ for (const entry of await readdirOrEmpty(root)) {
46
+ if (!entry.isDirectory()) continue;
47
+ for (const file of await names(join(root, entry.name, 'chats'))) {
48
+ if (!file.endsWith('.jsonl')) continue;
49
+ projects.set(file.slice(0, -'.jsonl'.length), entry.name);
50
+ }
51
+ }
52
+ return projects;
53
+ }
54
+
55
+ /** Fold one monthly usage log. Pure, so a fixture can pin it. */
56
+ export function qwenRowsFromText(
57
+ text: string,
58
+ projects: ReadonlyMap<string, string> = new Map(),
59
+ ): Map<string, UsageRollupRow> {
60
+ const rows = new Map<string, UsageRollupRow>();
61
+ for (const raw of text.split('\n')) {
62
+ if (!raw.trim()) continue;
63
+ let record: Record<string, unknown>;
64
+ try {
65
+ const parsed: unknown = JSON.parse(raw);
66
+ if (!isRecord(parsed)) continue;
67
+ record = parsed;
68
+ } catch {
69
+ continue;
70
+ }
71
+ if (record.schemaVersion !== undefined && record.schemaVersion !== 1) continue;
72
+
73
+ const input = countOf(record.inputTokens);
74
+ const cached = countOf(record.cachedTokens);
75
+ const output = countOf(record.outputTokens);
76
+ const reasoning = countOf(record.thoughtsTokens);
77
+ const total = countOf(record.totalTokens) || input + output + reasoning;
78
+ if (total === 0) continue;
79
+
80
+ const sessionId = typeof record.sessionId === 'string' ? record.sessionId : '';
81
+ const localDate = typeof record.localDate === 'string' && ISO_DAY.test(record.localDate) ? record.localDate : '';
82
+ addUsage(rows, {
83
+ project: projects.get(sessionId) ?? HARNESS,
84
+ harness: HARNESS,
85
+ provider: HARNESS,
86
+ model: typeof record.model === 'string' && record.model ? record.model : 'unknown',
87
+ day: localDate || dayOfIso(record.timestamp),
88
+ usage: {
89
+ input: Math.max(0, input - cached),
90
+ cacheRead: cached,
91
+ output,
92
+ reasoning,
93
+ total,
94
+ },
95
+ });
96
+ }
97
+ return rows;
98
+ }
99
+
100
+ async function list(): Promise<UsageSourceFile[]> {
101
+ const root = join(qwenHome(), 'usage');
102
+ const out: UsageSourceFile[] = [];
103
+ for (const name of await names(root)) {
104
+ if (!name.startsWith('token-usage-') || !name.endsWith('.jsonl')) continue;
105
+ const path = join(root, name);
106
+ const stat = await statOrNull(path);
107
+ if (stat) out.push({ key: `qwen:${path}`, harness: HARNESS, project: HARNESS, ...stat });
108
+ }
109
+ return out;
110
+ }
111
+
112
+ async function read(file: UsageSourceFile): Promise<UsageSourceRead | null> {
113
+ let text: string;
114
+ try {
115
+ text = await Bun.file(file.key.slice('qwen:'.length)).text();
116
+ } catch {
117
+ return null;
118
+ }
119
+ return { rows: qwenRowsFromText(text, await sessionProjects()), nextOffset: file.size, append: false };
120
+ }
121
+
122
+ export const qwenSource: UsageSource = { id: 'qwen', list, read };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The Qwen token log reader.
8
+ *
9
+ * The log reports `inputTokens` INCLUDING the cached prompt and `cachedTokens`
10
+ * separately; the index stores the uncached remainder or the panel counts those
11
+ * tokens twice. The project comes from the session's chat file, not the log.
12
+ */
13
+
14
+ import { describe, expect, test } from 'bun:test';
15
+
16
+ import { qwenRowsFromText } from '@/server/lib/usage/sources/qwen.server';
17
+
18
+ function line(value: Record<string, unknown>): string {
19
+ return JSON.stringify(value);
20
+ }
21
+
22
+ describe('qwenRowsFromText', () => {
23
+ test('subtracts cached input and maps the session to its project', () => {
24
+ const rows = qwenRowsFromText([
25
+ line({
26
+ schemaVersion: 1,
27
+ timestamp: '2026-11-06T20:53:12.240Z',
28
+ localDate: '2026-11-07',
29
+ sessionId: 's1',
30
+ model: 'qwen3-coder',
31
+ inputTokens: 100,
32
+ cachedTokens: 40,
33
+ outputTokens: 10,
34
+ thoughtsTokens: 5,
35
+ totalTokens: 115,
36
+ }),
37
+ line({
38
+ schemaVersion: 1,
39
+ timestamp: '2026-11-07T01:00:00.000Z',
40
+ sessionId: 's2',
41
+ model: 'qwen3-coder',
42
+ inputTokens: 0,
43
+ cachedTokens: 0,
44
+ outputTokens: 0,
45
+ thoughtsTokens: 0,
46
+ totalTokens: 0,
47
+ }),
48
+ ].join('\n'), new Map([['s1', 'kabmo']]));
49
+
50
+ expect(rows).toHaveLength(1);
51
+ const row = [...rows.values()][0];
52
+ expect(row.harness).toBe('qwen');
53
+ expect(row.project).toBe('kabmo');
54
+ expect(row.day).toBe('2026-11-07');
55
+ expect(row.input).toBe(60);
56
+ expect(row.cacheRead).toBe(40);
57
+ expect(row.output).toBe(10);
58
+ expect(row.reasoning).toBe(5);
59
+ expect(row.total).toBe(115);
60
+ expect(row.unpriced).toBe(1);
61
+ });
62
+ });
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * One store the Token Usage index folds.
8
+ *
9
+ * omp writes an append-only JSONL transcript, so its source keeps a byte offset
10
+ * and reads only the tail. The ACP harnesses keep SQLite files, zstd JSONL and
11
+ * monthly usage logs instead: those are replaced whole when they change, because
12
+ * a row can be updated in place and a tail read would miss it.
13
+ */
14
+
15
+ import type { HarnessId } from '@/shared/lib/harness/catalog';
16
+ import type { UsageRollupRow } from '@/server/lib/usage/index-parse';
17
+
18
+ /** One transcript/source file, as listed by a source. */
19
+ export interface UsageSourceFile {
20
+ /** Unique store-qualified key stored in `usage_index_file.session_file`. */
21
+ key: string;
22
+ harness: HarnessId;
23
+ /** Project label the rows are attributed to, overridable by `read`. */
24
+ project: string;
25
+ size: number;
26
+ mtimeMs: number;
27
+ }
28
+
29
+ /** A row in `usage_index_file`: how far one source file has been folded. */
30
+ export interface UsageFileState {
31
+ session_file: string;
32
+ source: string;
33
+ harness: string;
34
+ offset: number;
35
+ size: number;
36
+ mtime_ms: number;
37
+ }
38
+
39
+ /** What folding one file produced. */
40
+ export interface UsageSourceRead {
41
+ rows: Map<string, UsageRollupRow>;
42
+ nextOffset: number;
43
+ /** True only for a tail read; a full read replaces the file's rows. */
44
+ append: boolean;
45
+ }
46
+
47
+ /** One readable store. `list` returns [] when the store does not exist. */
48
+ export interface UsageSource {
49
+ id: string;
50
+ list(): Promise<UsageSourceFile[]>;
51
+ /** `null` means "unreadable; keep the rows already indexed". */
52
+ read(file: UsageSourceFile, previous: UsageFileState | null): Promise<UsageSourceRead | null>;
53
+ }
@@ -0,0 +1,131 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * zcode's local database: `ZCODE_HOME/cli/db/db.sqlite`.
8
+ *
9
+ * zcode records one `model_usage` row per model request, already carrying the
10
+ * provider, the model and the token split. `turn_usage` is the same tokens
11
+ * aggregated per turn without a provider/model, so it is deliberately NOT read:
12
+ * folding both would double every number.
13
+ *
14
+ * No cost column exists in either table, so zcode's turns are unpriced rather
15
+ * than free — the panel says which, instead of assuming a rate.
16
+ */
17
+
18
+ import { Database } from 'bun:sqlite';
19
+ import fs from 'node:fs';
20
+ import { join } from 'node:path';
21
+
22
+ import type { HarnessId } from '@/shared/lib/harness/catalog';
23
+ import type { UsageRollupRow } from '@/server/lib/usage/index-parse';
24
+ import {
25
+ addUsage,
26
+ countOf,
27
+ dayOfMs,
28
+ projectFromCwd,
29
+ statOrNull,
30
+ storeHome,
31
+ } from '@/server/lib/usage/sources/helpers';
32
+ import type { UsageSource, UsageSourceFile, UsageSourceRead } from '@/server/lib/usage/sources/types';
33
+
34
+ const HARNESS: HarnessId = 'zcode';
35
+
36
+ function databasePath(): string {
37
+ return join(storeHome('ZCODE_HOME', '.zcode'), 'cli', 'db', 'db.sqlite');
38
+ }
39
+
40
+ interface ModelUsageRow {
41
+ session_id: string;
42
+ provider_id: string;
43
+ model_id: string;
44
+ input_tokens: number;
45
+ output_tokens: number;
46
+ reasoning_tokens: number;
47
+ cache_creation_input_tokens: number;
48
+ cache_read_input_tokens: number;
49
+ computed_total_tokens: number;
50
+ started_at: number;
51
+ }
52
+
53
+ function sessionProjects(db: Database): Map<string, string> {
54
+ const projects = new Map<string, string>();
55
+ try {
56
+ for (const row of db.query('SELECT id, directory FROM session').all() as { id: string; directory: string }[]) {
57
+ const project = projectFromCwd(row.directory);
58
+ if (project) projects.set(row.id, project);
59
+ }
60
+ } catch {
61
+ // No session table: the row still has provider/model, only its project is
62
+ // reported under the harness name.
63
+ }
64
+ return projects;
65
+ }
66
+
67
+ /** Fold one zcode database; `null` means the store could not be read. */
68
+ export function zcodeRowsFromPath(path: string): Map<string, UsageRollupRow> | null {
69
+ const rows = new Map<string, UsageRollupRow>();
70
+ let db: Database | null = null;
71
+ try {
72
+ db = new Database(path, { readonly: true });
73
+ db.exec('PRAGMA busy_timeout = 500');
74
+ const projects = sessionProjects(db);
75
+ const usageRows = db.query(
76
+ `SELECT session_id, provider_id, model_id, input_tokens, output_tokens, reasoning_tokens,
77
+ cache_creation_input_tokens, cache_read_input_tokens, computed_total_tokens, started_at
78
+ FROM model_usage`,
79
+ ).all() as ModelUsageRow[];
80
+
81
+ for (const row of usageRows) {
82
+ const input = countOf(row.input_tokens);
83
+ const output = countOf(row.output_tokens);
84
+ const reasoning = countOf(row.reasoning_tokens);
85
+ const cacheWrite = countOf(row.cache_creation_input_tokens);
86
+ const cacheRead = countOf(row.cache_read_input_tokens);
87
+ const total = countOf(row.computed_total_tokens) || input + output + reasoning + cacheWrite + cacheRead;
88
+ if (total === 0) continue;
89
+ addUsage(rows, {
90
+ project: projects.get(row.session_id) ?? HARNESS,
91
+ harness: HARNESS,
92
+ provider: row.provider_id || HARNESS,
93
+ model: row.model_id || 'unknown',
94
+ day: dayOfMs(row.started_at),
95
+ usage: { input, output, reasoning, cacheRead, cacheWrite, total },
96
+ });
97
+ }
98
+ } catch {
99
+ return null;
100
+ } finally {
101
+ db?.close();
102
+ }
103
+ return rows;
104
+ }
105
+
106
+ async function list(): Promise<UsageSourceFile[]> {
107
+ const path = databasePath();
108
+ const stat = await statOrNull(path);
109
+ if (!stat) return [];
110
+ const wal = await statOrNull(`${path}-wal`);
111
+ return [{
112
+ key: `zcode:${path}`,
113
+ harness: HARNESS,
114
+ project: 'zcode',
115
+ size: stat.size + (wal?.size ?? 0),
116
+ mtimeMs: Math.max(stat.mtimeMs, wal?.mtimeMs ?? 0),
117
+ }];
118
+ }
119
+
120
+ async function read(file: UsageSourceFile): Promise<UsageSourceRead | null> {
121
+ const path = file.key.slice('zcode:'.length);
122
+ try {
123
+ if (!(await fs.promises.stat(path)).isFile()) return null;
124
+ } catch {
125
+ return null;
126
+ }
127
+ const rows = zcodeRowsFromPath(path);
128
+ return rows ? { rows, nextOffset: file.size, append: false } : null;
129
+ }
130
+
131
+ export const zcodeSource: UsageSource = { id: 'zcode', list, read };