@kabmo-labs/kabmo 0.17.0 → 0.18.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 (269) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +538 -457
  3. package/dist/client/static/js/index-hp75vsv9.css +1 -0
  4. package/dist/client/static/js/{index-rerjq5th.js → index-tc09dtca.js} +823 -814
  5. package/package.json +1 -1
  6. package/src/client/components/common/MarkdownRenderer.tsx +136 -89
  7. package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
  8. package/src/client/components/common/anchored-menu/index.tsx +143 -0
  9. package/src/client/components/common/markdown-review/ReviewPopover.tsx +144 -0
  10. package/src/client/components/common/markdown-review/ReviewSummary.tsx +108 -0
  11. package/src/client/components/common/markdown-review/index.tsx +129 -0
  12. package/src/client/components/common/server-control/Panel.tsx +33 -23
  13. package/src/client/components/common/server-control/index.test.tsx +11 -5
  14. package/src/client/components/common/server-control/index.tsx +10 -8
  15. package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +42 -21
  16. package/src/client/components/layout/session-sidebar/CategoryHeader.worktree.test.tsx +36 -17
  17. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +8 -7
  18. package/src/client/components/layout/session-sidebar/about-modal/NotesDialog.tsx +94 -0
  19. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.test.tsx +68 -0
  20. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.tsx +36 -0
  21. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +57 -34
  22. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +28 -10
  23. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +7 -6
  24. package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +1 -1
  25. package/src/client/components/layout/update-popup/ReleaseNotes.tsx +8 -3
  26. package/src/client/components/layout/update-popup/index.tsx +5 -1
  27. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +13 -15
  28. package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +23 -1
  29. package/src/client/components/mobile/mobile-right-sidebar/MissingFileBanner.tsx +30 -0
  30. package/src/client/components/mobile/mobile-right-sidebar/PreviewScroller.tsx +18 -2
  31. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +22 -67
  32. package/src/client/components/mobile/mobile-session-sidebar/ItemMenu.tsx +110 -0
  33. package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
  34. package/src/client/components/settings/categories/AgentSettings.tsx +23 -50
  35. package/src/client/components/settings/categories/CommandSettings.tsx +2 -2
  36. package/src/client/components/settings/categories/McpSettings.tsx +4 -21
  37. package/src/client/components/settings/categories/OmpSettings.tsx +147 -194
  38. package/src/client/components/settings/categories/SkillSettings.tsx +2 -2
  39. package/src/client/components/settings/categories/TokenUsageSettings.tsx +211 -229
  40. package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +229 -237
  41. package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +71 -0
  42. package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +9 -2
  43. package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
  44. package/src/client/components/settings/categories/behavior-settings/Editor.tsx +27 -7
  45. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +23 -5
  46. package/src/client/components/settings/categories/command-settings/DetailPane.tsx +75 -33
  47. package/src/client/components/settings/categories/command-settings/SidebarList.tsx +7 -0
  48. package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +91 -76
  49. package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
  50. package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +26 -13
  51. package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +20 -0
  52. package/src/client/components/settings/categories/omp-settings/ConfigTabs.tsx +97 -36
  53. package/src/client/components/settings/categories/omp-settings/EngineHeader.tsx +151 -0
  54. package/src/client/components/settings/categories/omp-settings/ExtensionsPanel.tsx +68 -32
  55. package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +119 -0
  56. package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +14 -7
  57. package/src/client/components/settings/categories/omp-settings/RoleEditor.tsx +15 -6
  58. package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +165 -226
  59. package/src/client/components/settings/categories/omp-settings/types.ts +28 -0
  60. package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +35 -7
  61. package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +34 -14
  62. package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +21 -0
  63. package/src/client/components/settings/categories/skill-settings/pane.test.tsx +15 -6
  64. package/src/client/components/settings/categories/token-usage-settings/Breakdown.tsx +242 -102
  65. package/src/client/components/settings/categories/token-usage-settings/Chart.tsx +130 -56
  66. package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +135 -0
  67. package/src/client/components/settings/categories/token-usage-settings/MetricsGrid.tsx +55 -33
  68. package/src/client/components/settings/categories/token-usage-settings/Provenance.tsx +59 -0
  69. package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +239 -0
  70. package/src/client/components/workspace/browser-panel/Screencast.test.ts +1 -0
  71. package/src/client/components/workspace/browser-panel/Screencast.tsx +17 -22
  72. package/src/client/components/workspace/browser-panel/TabStrip.test.tsx +158 -0
  73. package/src/client/components/workspace/browser-panel/TabStrip.tsx +90 -0
  74. package/src/client/components/workspace/browser-panel/index.tsx +50 -4
  75. package/src/client/components/workspace/browser-toolbar/index.tsx +41 -1
  76. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +3 -1
  77. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +2 -0
  78. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
  79. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +88 -0
  80. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +24 -1
  81. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +34 -0
  82. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +5 -1
  83. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactChip.tsx +7 -6
  84. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +237 -0
  85. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +191 -0
  86. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +1 -1
  87. package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +21 -7
  88. package/src/client/components/workspace/diff-panel/changes.test.ts +51 -0
  89. package/src/client/components/workspace/diff-panel/changes.ts +28 -12
  90. package/src/client/components/workspace/diff-panel/merge.test.ts +28 -0
  91. package/src/client/components/workspace/diff-panel/merge.ts +21 -1
  92. package/src/client/components/workspace/editor/Body.tsx +7 -0
  93. package/src/client/components/workspace/editor/FileDocument.tsx +15 -21
  94. package/src/client/components/workspace/editor/FilePane.tsx +12 -0
  95. package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
  96. package/src/client/components/workspace/editor/Toolbar.tsx +17 -1
  97. package/src/client/components/workspace/editor/index.tsx +25 -22
  98. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +14 -0
  99. package/src/client/components/workspace/editor/toolbar-clusters.tsx +12 -86
  100. package/src/client/components/workspace/editor/toolbar-toggle.tsx +53 -0
  101. package/src/client/components/workspace/editor/toolbar-write-clusters.tsx +112 -0
  102. package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
  103. package/src/client/components/workspace/user-browser-panel/AddressBar.tsx +5 -0
  104. package/src/client/components/workspace/user-browser-panel/AnnotateBar.test.tsx +201 -0
  105. package/src/client/components/workspace/user-browser-panel/AnnotateBar.tsx +112 -0
  106. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.test.tsx +225 -0
  107. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.tsx +217 -0
  108. package/src/client/components/workspace/user-browser-panel/AnnotateTarget.tsx +99 -0
  109. package/src/client/components/workspace/user-browser-panel/Frame.tsx +30 -1
  110. package/src/client/components/workspace/user-browser-panel/index.tsx +81 -2
  111. package/src/client/data/agent-data/builtin.ts +0 -10
  112. package/src/client/data/agent-data/orchestrator.ts +0 -45
  113. package/src/client/data/agent-data/specialist.ts +0 -100
  114. package/src/client/data/mock/token-usage.ts +170 -120
  115. package/src/client/data/settings/omp-schema.json +33 -1
  116. package/src/client/hooks/browser/use-annotate.test.ts +143 -0
  117. package/src/client/hooks/browser/use-annotate.ts +98 -0
  118. package/src/client/hooks/browser/use-close-tab.test.ts +148 -0
  119. package/src/client/hooks/browser/use-close-tab.ts +67 -0
  120. package/src/client/hooks/browser/use-screencast.ts +13 -1
  121. package/src/client/hooks/chat/composer/browser-context.test.ts +117 -0
  122. package/src/client/hooks/chat/composer/browser-context.ts +40 -16
  123. package/src/client/hooks/chat/composer/items.test.ts +1 -1
  124. package/src/client/hooks/chat/composer/review-context.ts +38 -0
  125. package/src/client/hooks/chat/composer/use-draft.test.ts +132 -0
  126. package/src/client/hooks/chat/composer/use-draft.ts +31 -2
  127. package/src/client/hooks/chat/timeline/row-window.test.ts +15 -2
  128. package/src/client/hooks/editor/use-document-annotations.ts +124 -0
  129. package/src/client/hooks/editor/use-editor-panel-ui.ts +52 -0
  130. package/src/client/hooks/editor/use-file-review-mode.ts +35 -0
  131. package/src/client/hooks/editor/use-preview-review.ts +148 -0
  132. package/src/client/hooks/settings/agents.ts +149 -0
  133. package/src/client/hooks/settings/crud-list.test.ts +28 -6
  134. package/src/client/hooks/settings/crud-list.ts +96 -57
  135. package/src/client/hooks/settings/omp-config.ts +164 -0
  136. package/src/client/hooks/settings/useTokenUsage.ts +125 -0
  137. package/src/client/hooks/settings/write-feedback.test.ts +104 -0
  138. package/src/client/hooks/settings/write-feedback.ts +63 -0
  139. package/src/client/hooks/ui/markdown-hydration.ts +125 -0
  140. package/src/client/hooks/ui/updates/index.test.ts +100 -1
  141. package/src/client/hooks/ui/updates/index.ts +50 -0
  142. package/src/client/hooks/ui/updates/notes.test.ts +138 -0
  143. package/src/client/hooks/ui/updates/notes.ts +57 -0
  144. package/src/client/lib/browser/element-at.test.ts +229 -0
  145. package/src/client/lib/browser/element-at.ts +139 -0
  146. package/src/client/lib/review/client.ts +73 -0
  147. package/src/client/lib/router/search-params.ts +42 -20
  148. package/src/client/tailwind.css +65 -0
  149. package/src/server/lib/btw/lifecycle.server.ts +2 -2
  150. package/src/server/lib/db/schema.ts +7 -0
  151. package/src/server/lib/db/seed-terminal.test.ts +4 -0
  152. package/src/server/lib/omp/config/agent-definitions.test.ts +273 -0
  153. package/src/server/lib/omp/config/agents.ts +231 -61
  154. package/src/server/lib/omp/config/definitions.test.ts +9 -105
  155. package/src/server/lib/omp/config/extensions.ts +16 -7
  156. package/src/server/lib/omp/config/omp-config-files.test.ts +27 -0
  157. package/src/server/lib/omp/rpc/constants.test.ts +11 -0
  158. package/src/server/lib/omp/rpc/constants.ts +15 -0
  159. package/src/server/lib/omp/rpc/process.ts +11 -14
  160. package/src/server/lib/omp/rpc/session-commands.ts +6 -3
  161. package/src/server/lib/omp/rpc/utility-agent-dir.test.ts +134 -0
  162. package/src/server/lib/omp/rpc/utility-agent-dir.ts +138 -0
  163. package/src/server/lib/omp/rpc/utility.ts +12 -0
  164. package/src/server/lib/review/schema.server.ts +45 -0
  165. package/src/server/lib/review/store.server.ts +138 -0
  166. package/src/server/lib/terminal/attach-replay.test.ts +132 -0
  167. package/src/server/lib/terminal/output.test.ts +166 -0
  168. package/src/server/lib/terminal/output.ts +104 -0
  169. package/src/server/lib/terminal/runtime.server.ts +5 -0
  170. package/src/server/lib/terminal/send-result.test.ts +33 -0
  171. package/src/server/lib/terminal/send-result.ts +32 -0
  172. package/src/server/lib/terminal/session.server.ts +45 -11
  173. package/src/server/lib/terminal/store-liveness.test.ts +4 -0
  174. package/src/server/lib/updates/active-notes.test.ts +149 -0
  175. package/src/server/lib/updates/active-notes.ts +75 -0
  176. package/src/server/lib/updates/changelog-file.ts +42 -11
  177. package/src/server/lib/updates/changelog.test.ts +15 -1
  178. package/src/server/lib/updates/omp.ts +42 -15
  179. package/src/server/lib/updates/release-url.ts +27 -1
  180. package/src/server/lib/usage/index-parse.test.ts +200 -0
  181. package/src/server/lib/usage/index-parse.ts +178 -0
  182. package/src/server/lib/usage/index-query.server.ts +248 -0
  183. package/src/server/lib/usage/index-scan.server.ts +343 -0
  184. package/src/server/lib/usage/index-schema.server.ts +82 -0
  185. package/src/server/lib/usage/index.test.ts +234 -0
  186. package/src/server/lib/usage/providers.server.ts +4 -53
  187. package/src/server/routes/browser/index.ts +3 -0
  188. package/src/server/routes/browser/stream.ts +31 -2
  189. package/src/server/routes/browser/tabs.test.ts +94 -0
  190. package/src/server/routes/browser/tabs.ts +85 -0
  191. package/src/server/routes/index.ts +2 -0
  192. package/src/server/routes/review/bindings.ts +11 -0
  193. package/src/server/routes/review/index.ts +127 -0
  194. package/src/server/routes/review/routes.test.ts +191 -0
  195. package/src/server/routes/settings/agents.test.ts +180 -0
  196. package/src/server/routes/settings/agents.ts +95 -102
  197. package/src/server/routes/settings/mcp.test.ts +135 -0
  198. package/src/server/routes/settings/mcp.ts +14 -6
  199. package/src/server/routes/settings/settings-store-routes.test.ts +6 -113
  200. package/src/server/routes/telemetry/tokens.test.ts +145 -0
  201. package/src/server/routes/telemetry/tokens.ts +70 -149
  202. package/src/server/routes/terminal/ws.ts +6 -5
  203. package/src/server/routes/updates/index.ts +2 -0
  204. package/src/server/routes/updates/notes.ts +34 -0
  205. package/src/server/routes/updates/routes.test.ts +49 -0
  206. package/src/shared/lib/browser/annotate.test.ts +283 -0
  207. package/src/shared/lib/browser/annotate.ts +231 -0
  208. package/src/shared/lib/browser/browser-viewer.test.ts +26 -4
  209. package/src/shared/lib/browser/frame-gate.test.ts +91 -0
  210. package/src/shared/lib/browser/frame-gate.ts +69 -0
  211. package/src/shared/lib/browser/frame-params.test.ts +43 -0
  212. package/src/shared/lib/browser/frame-params.ts +60 -0
  213. package/src/shared/lib/browser/frame-pipeline.test.ts +132 -0
  214. package/src/shared/lib/browser/frame-pipeline.ts +80 -0
  215. package/src/shared/lib/browser/page-context.ts +60 -4
  216. package/src/shared/lib/browser/snapshot.test.ts +115 -0
  217. package/src/shared/lib/browser/snapshot.ts +112 -0
  218. package/src/shared/lib/browser/tab-close.test.ts +74 -0
  219. package/src/shared/lib/browser/tab-close.ts +77 -0
  220. package/src/shared/lib/browser/viewer.ts +45 -26
  221. package/src/shared/lib/chat/timeline/block-chrome.ts +19 -0
  222. package/src/shared/lib/chat/timeline/tool-render-mode.ts +17 -4
  223. package/src/shared/lib/chat/tool/artifact.ts +55 -20
  224. package/src/shared/lib/chat/tool/bash-facts.ts +96 -0
  225. package/src/shared/lib/chat/tool/minimized.test.ts +98 -0
  226. package/src/shared/lib/chat/tool/minimized.ts +64 -0
  227. package/src/shared/lib/chat/tool/summary.test.ts +28 -8
  228. package/src/shared/lib/chat/tool/summary.ts +3 -32
  229. package/src/shared/lib/markdown/blocks/anchor.ts +63 -0
  230. package/src/shared/lib/markdown/blocks/blocks.test.ts +141 -0
  231. package/src/shared/lib/markdown/blocks/renderer.ts +120 -0
  232. package/src/shared/lib/markdown/blocks/scan.ts +100 -0
  233. package/src/shared/lib/markdown/blocks/types.ts +62 -0
  234. package/src/shared/lib/markdown/marked.ts +58 -147
  235. package/src/shared/lib/markdown/math-extensions.ts +168 -0
  236. package/src/shared/lib/markdown/review/prompt.ts +77 -0
  237. package/src/shared/lib/markdown/review/reconcile.ts +55 -0
  238. package/src/shared/lib/markdown/review/review.test.ts +96 -0
  239. package/src/shared/lib/markdown/xml-sections.test.ts +140 -0
  240. package/src/shared/lib/markdown/xml-sections.ts +139 -0
  241. package/src/shared/lib/models/provider/label.ts +57 -0
  242. package/src/shared/lib/omp/config/agent-file.test.ts +54 -0
  243. package/src/shared/lib/omp/config/agent-file.ts +43 -0
  244. package/src/shared/lib/omp/config/row-value.test.ts +95 -0
  245. package/src/shared/lib/omp/config/row-value.ts +97 -0
  246. package/src/shared/lib/omp/config/schema.test.ts +31 -0
  247. package/src/shared/lib/omp/config/schema.ts +6 -0
  248. package/src/shared/lib/omp/rpc/frame.test.ts +48 -47
  249. package/src/shared/lib/omp/rpc/frame.ts +49 -40
  250. package/src/shared/lib/ui/menu-anchor.test.ts +69 -0
  251. package/src/shared/lib/ui/menu-anchor.ts +89 -0
  252. package/src/shared/lib/usage/breakdown.test.ts +197 -0
  253. package/src/shared/lib/usage/breakdown.ts +241 -0
  254. package/src/shared/lib/usage/range.test.ts +204 -0
  255. package/src/shared/lib/usage/range.ts +240 -0
  256. package/src/shared/lib/usage/view.test.ts +85 -0
  257. package/src/shared/lib/usage/view.ts +74 -0
  258. package/src/shared/types/browser.ts +78 -0
  259. package/src/shared/types/index.ts +1 -0
  260. package/src/shared/types/settings/agent.ts +28 -6
  261. package/src/shared/types/settings/state.ts +4 -3
  262. package/src/shared/types/settings/write.ts +6 -0
  263. package/src/shared/types/tokenUsage.ts +128 -21
  264. package/src/shared/types/updates.ts +20 -0
  265. package/dist/client/static/js/index-3ve31rzx.css +0 -1
  266. package/src/server/lib/omp/session/usage/aggregate-shaping.test.ts +0 -149
  267. package/src/server/lib/omp/session/usage/aggregate.test.ts +0 -243
  268. package/src/server/lib/omp/session/usage/aggregate.ts +0 -330
  269. package/src/server/lib/omp/session/usage/shaping.ts +0 -130
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The Token Usage panel's view models.
8
+ *
9
+ * These are the numbers a user reads, so each case pins a value that would be a
10
+ * bug if it drifted: a model shown under the wrong provider, a share computed
11
+ * against the wrong denominator, a cadence that relabels without re-bucketing,
12
+ * or a cache rate that divides by the wrong input.
13
+ */
14
+
15
+ import { describe, expect, test } from 'bun:test';
16
+
17
+ import {
18
+ cacheHitLabel,
19
+ cacheHitRate,
20
+ costLabel,
21
+ costPerMillionLabel,
22
+ tokenLabel,
23
+ toMetricSet,
24
+ } from '@/shared/lib/usage/view';
25
+ import type { UsageTotals } from '@/shared/types';
26
+
27
+ const counters = (cost: number, tokens: number, records = 1, cacheRead = 0, input = 0) => ({
28
+ cost, tokens, input, output: tokens - input - cacheRead, cacheRead, cacheWrite: 0,
29
+ reasoning: 0, cacheReadCost: cost * 0.1, records, unpriced: 0,
30
+ });
31
+
32
+ const totals: UsageTotals = {
33
+ ...counters(20, 1_000_000, 40, 900_000, 50_000),
34
+ unpriced: 4,
35
+ activeDays: 6,
36
+ };
37
+
38
+ describe('formatting', () => {
39
+ test('token labels switch unit at the decimal boundary', () => {
40
+ expect(tokenLabel(0)).toBe('0');
41
+ expect(tokenLabel(999)).toBe('999');
42
+ expect(tokenLabel(1_500)).toBe('1.5K');
43
+ expect(tokenLabel(2_219_000_000)).toBe('2.2B');
44
+ });
45
+
46
+ test('a nonzero sub-cent cost is not rounded into "free"', () => {
47
+ expect(costLabel(0)).toBe('$0.00');
48
+ expect(costLabel(1.234)).toBe('$1.23');
49
+ expect(costLabel(0.0009)).toBe('< $0.01');
50
+ expect(costLabel(0.01)).toBe('$0.01');
51
+ });
52
+
53
+ test('cost per million is derived from cost and tokens, and blank when empty', () => {
54
+ expect(costPerMillionLabel({ cost: 1.7, tokens: 1_000_000 })).toBe('$1.70');
55
+ expect(costPerMillionLabel({ cost: 1.7, tokens: 0 })).toBe('—');
56
+ });
57
+
58
+ test('cache hit rate is cache reads over ALL observed input', () => {
59
+ expect(cacheHitRate({ cacheRead: 900, input: 100 })).toBeCloseTo(0.9, 10);
60
+ expect(cacheHitLabel({ cacheRead: 900, input: 100 })).toBe('90.0%');
61
+ // Nothing observed is not a 100% hit rate.
62
+ expect(cacheHitLabel({ cacheRead: 0, input: 0 })).toBe('—');
63
+ });
64
+ });
65
+
66
+ describe('toMetricSet', () => {
67
+ test('every figure is the period total', () => {
68
+ const metrics = toMetricSet(totals);
69
+ expect(metrics.rawCost).toBe('$20.00');
70
+ expect(metrics.processedTokens).toBe('1.0M');
71
+ expect(metrics.cachedInput).toBe('900.0K');
72
+ expect(metrics.uncachedInput).toBe('50.0K');
73
+ expect(metrics.costPerMillion).toBe('$20.00');
74
+ });
75
+
76
+ test('the activity hint counts the period days, singular at one', () => {
77
+ expect(toMetricSet(totals).activeRate).toBe('6 active days');
78
+ expect(toMetricSet({ ...totals, activeDays: 1 }).activeRate).toBe('1 active day');
79
+ });
80
+
81
+ test('there is no per-day or per-week figure in the set', () => {
82
+ const metrics = toMetricSet(totals);
83
+ expect(Object.keys(metrics).some((key) => /perDay|perWeek|perMonth|average/i.test(key))).toBe(false);
84
+ });
85
+ });
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Formatting and the headline metric set for the Token Usage panel.
8
+ *
9
+ * Nothing here divides or averages: the panel reports ONE period, so every
10
+ * figure is that period's total. A cadence switch used to exist beside the
11
+ * period switch, and a period total cannot move when days are regrouped — which
12
+ * made the control look broken. The period IS the switch now.
13
+ *
14
+ * Pure and shared, so the panel's components hold no arithmetic.
15
+ */
16
+
17
+ import type { TokenUsageMetricSet, UsageCounters, UsageTotals } from '@/shared/types';
18
+
19
+ /**
20
+ * `$1.23` for a cost row, `< $0.01` for a real but sub-cent amount.
21
+ *
22
+ * Rounding a nonzero cost to `$0.00` reads as "this was free", which is the
23
+ * one thing an unpriced/free provider is NOT. `<$0.01` says the cost exists
24
+ * and is below the display precision.
25
+ */
26
+ export function costLabel(value: number, fractionDigits = 2): string {
27
+ if (value > 0 && Number(value.toFixed(fractionDigits)) === 0) return '< $0.01';
28
+ return `$${value.toFixed(fractionDigits)}`;
29
+ }
30
+
31
+ /** Compact token count with decimal units, matching the rest of the app. */
32
+ export function tokenLabel(value: number): string {
33
+ if (!Number.isFinite(value) || value <= 0) return '0';
34
+ if (value >= 1_000_000_000) return `${(value / 1_000_000_000).toFixed(1)}B`;
35
+ if (value >= 1_000_000) return `${(value / 1_000_000).toFixed(1)}M`;
36
+ if (value >= 1_000) return `${(value / 1_000).toFixed(1)}K`;
37
+ return String(Math.round(value));
38
+ }
39
+
40
+ /** Cache-hit percentage over observed input (cache read + uncached input). */
41
+ export function cacheHitRate(counters: Pick<UsageCounters, 'cacheRead' | 'input'>): number | null {
42
+ const observed = counters.cacheRead + counters.input;
43
+ return observed > 0 ? counters.cacheRead / observed : null;
44
+ }
45
+
46
+ /** `98.7%` or `—` when nothing was cached or read. */
47
+ export function cacheHitLabel(counters: Pick<UsageCounters, 'cacheRead' | 'input'>): string {
48
+ const rate = cacheHitRate(counters);
49
+ return rate === null ? '—' : `${(rate * 100).toFixed(1)}%`;
50
+ }
51
+
52
+ /** `$0.07` per 1M tokens, or `—` when no tokens were processed. */
53
+ export function costPerMillionLabel(counters: Pick<UsageCounters, 'cost' | 'tokens'>): string {
54
+ if (counters.tokens <= 0) return '—';
55
+ return `$${((counters.cost / counters.tokens) * 1_000_000).toFixed(2)}`;
56
+ }
57
+
58
+ /** The headline tiles, as display strings for the selected period. */
59
+ export function toMetricSet(totals: UsageTotals): TokenUsageMetricSet {
60
+ return {
61
+ rawCost: costLabel(totals.cost),
62
+ costPerMillion: costPerMillionLabel(totals),
63
+ processedTokens: tokenLabel(totals.tokens),
64
+ activeRate: `${totals.activeDays} active ${totals.activeDays === 1 ? 'day' : 'days'}`,
65
+ cachedInput: tokenLabel(totals.cacheRead),
66
+ cachedPercent: `${cacheHitLabel(totals)} of observed input`,
67
+ uncachedInput: tokenLabel(totals.input),
68
+ cacheWrite: tokenLabel(totals.cacheWrite),
69
+ outputTokens: tokenLabel(totals.output),
70
+ reasoning: `${tokenLabel(totals.reasoning)} reasoning`,
71
+ records: totals.records,
72
+ unpricedRecords: totals.unpriced,
73
+ };
74
+ }
@@ -51,8 +51,86 @@ export interface BrowserPanelAction {
51
51
  label: string;
52
52
  }
53
53
 
54
+ /**
55
+ * How the user marked a spot on the user-browser panel.
56
+ *
57
+ * The panel is a cross-origin iframe, so a mark can never carry PIXELS: the
58
+ * page inside is unreadable to this origin (`contentDocument` is null,
59
+ * `drawImage(iframe)` throws, and a capture would show the user's whole
60
+ * screen). What travels is geometry plus words — the exact region, and what
61
+ * the user says is wrong there.
62
+ */
63
+ export type AnnotateTool = 'box' | 'pin' | 'arrow';
64
+
65
+ /** One point, normalized to the measured panel: 0..1 on both axes. */
66
+ export interface AnnotatePoint {
67
+ x: number;
68
+ y: number;
69
+ }
70
+
71
+ /**
72
+ * What the marked spot IS, when the page allows reading it.
73
+ *
74
+ * Only a SAME-ORIGIN frame can be read (`contentDocument` is non-null); a real
75
+ * dev server runs on its own port, which is a different origin even on the same
76
+ * host — measured in Chromium: `:7101` reading `:7102` yields `contentDocument
77
+ * === null`. So this is present only when the page was readable, and the prompt
78
+ * says so when it is absent instead of pretending.
79
+ */
80
+ export interface AnnotateElement {
81
+ /** `section[aria-label="Ringkasan"] > button#pay`, at most 4 levels. */
82
+ path: string;
83
+ /** Lowercase tag name, e.g. `select`. */
84
+ tag: string;
85
+ /** Explicit `role`, when the element declares one. */
86
+ role?: string;
87
+ /** Visible text, whitespace-collapsed and cut short. */
88
+ text?: string;
89
+ /** `<select>` value and option count, `disabled`, and similar. */
90
+ state?: string;
91
+ }
92
+
93
+ /**
94
+ * One numbered mark. `box`/`arrow` use both points; `pin` uses `start`.
95
+ *
96
+ * `label` is the user's NAME for the region ("Ringkasan pesanan", "form
97
+ * alamat"). It is not derived from the page: the label is the one fact a
98
+ * cross-origin frame can never give us, and the user always has it.
99
+ */
100
+ export interface AnnotateShape {
101
+ id: string;
102
+ tool: AnnotateTool;
103
+ start: AnnotatePoint;
104
+ end: AnnotatePoint;
105
+ /** The user's name for the region; empty until they say it. */
106
+ label: string;
107
+ /** What the user says about this region; empty while they are still drawing. */
108
+ note: string;
109
+ /** The element under the mark, when the frame was same-origin and readable. */
110
+ element?: AnnotateElement;
111
+ }
112
+
113
+ /**
114
+ * The panel box the marks were drawn on, in CSS px.
115
+ *
116
+ * Percentages alone are not enough: `12% of a 1024px panel` and `12% of a
117
+ * 375px panel` are different places, and the agent has to know which page
118
+ * shape the user was looking at to reproduce the view.
119
+ */
120
+ export interface AnnotatePanelSize {
121
+ width: number;
122
+ height: number;
123
+ viewportMode: string;
124
+ /** CSS zoom the panel was showing at (100 = none). */
125
+ zoom: number;
126
+ }
127
+
54
128
  /** Page context handed from a browser panel to the chat composer draft. */
55
129
  export interface BrowserPageContext {
56
130
  url: string;
57
131
  title?: string;
132
+ /** The marks the user made, in draw order. Absent when they only shared a page. */
133
+ annotations?: AnnotateShape[];
134
+ /** The box those marks were normalized against. Present whenever `annotations` is. */
135
+ panel?: AnnotatePanelSize;
58
136
  }
@@ -18,6 +18,7 @@ export * from '@/shared/types/settings/mcp';
18
18
  export * from '@/shared/types/settings/usage';
19
19
  export * from '@/shared/types/settings/skill';
20
20
  export * from '@/shared/types/settings/plugin';
21
+ export * from '@/shared/types/settings/write';
21
22
  export * from '@/shared/types/context';
22
23
  export * from '@/shared/types/omp/session';
23
24
  export * from '@/shared/types/omp/agent';
@@ -1,16 +1,38 @@
1
- export type AgentMode = 'primary' | 'subagent' | 'all';
1
+ /**
2
+ * An omp agent definition.
3
+ *
4
+ * The field set is omp's OWN frontmatter contract (`parseAgentFields` in
5
+ * `@oh-my-pi/pi-coding-agent`), not a shape Kabmo invented: `name`,
6
+ * `description`, `tools`, `spawns`, `model`, `thinkingLevel`, and the body as
7
+ * the system prompt. `mode`/`temperature`/`topP` used to be offered here and
8
+ * were never read by omp, so three controls edited a file to no effect — they
9
+ * are gone, and the pane no longer implies they work.
10
+ */
11
+
2
12
  export type AgentScope = 'system' | 'user' | 'project';
3
13
 
14
+ /** A model selector: `provider/model`, or a role selector such as `@smol`. */
15
+ export type AgentModelSelector = string;
16
+
4
17
  export interface AgentItem {
5
18
  id: string;
6
19
  name: string;
7
20
  description: string;
8
21
  scope: AgentScope;
9
- mode: AgentMode;
10
- overrideModel?: string;
11
- thinkingVariant?: string;
12
- temperature?: number | null;
13
- topP?: number | null;
22
+ /** Absent means omp's default tool set. */
23
+ tools?: string[];
24
+ /** `"*"` or a name list: which agents this one may spawn. */
25
+ spawns?: string;
26
+ model?: AgentModelSelector;
27
+ /** `off` … `max`, or `auto`; absent means the session's level. */
28
+ thinkingLevel?: string;
14
29
  systemPrompt: string;
30
+ /** Listed but not editable: a project agent belongs to that workspace. */
15
31
  isBuiltIn?: boolean;
32
+ /** Absolute path of the definition file omp loads; absent for a demo preset. */
33
+ filePath?: string;
34
+ /** Base name of that file (no `.md`), which is what a write sends. */
35
+ fileName?: string;
36
+ /** Which root the definition was discovered in. */
37
+ sourceRoot?: 'user' | 'project';
16
38
  }
@@ -100,9 +100,10 @@ export interface SettingsState {
100
100
  chatWidthMode: ChatWidthMode;
101
101
  /**
102
102
  * How a tool call is drawn in the transcript (`card` | `compact` | `trace` |
103
- * `minimal`). A reading style: every mode renders the same call, facts and
104
- * body — only the frame, density and grouping change. Global, like the chat
105
- * width, because density is a property of the person and the display.
103
+ * `minimal` | `tui`). A reading style: every mode renders the same call,
104
+ * facts and body — only the frame, density and grouping change. Global, like
105
+ * the chat width, because density is a property of the person and the
106
+ * display.
106
107
  */
107
108
  toolRenderStyle: ToolRenderMode;
108
109
  /**
@@ -0,0 +1,6 @@
1
+ /** What a settings write did, so a pane reports the server's own answer. */
2
+ export interface WriteOutcome {
3
+ ok: boolean;
4
+ /** The refusal's sentence (the payload's `error`, or the transport failure). */
5
+ error?: string;
6
+ }
@@ -1,44 +1,151 @@
1
- export type CadenceType = 'daily' | 'weekly' | 'monthly';
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The Token Usage surface's wire contract (`GET /api/telemetry/tokens`).
8
+ *
9
+ * One payload carries every view the panel can draw for the requested period:
10
+ * totals, the provider → model tree, the per-day rows the chart and the time
11
+ * breakdown are both derived from, and the project rows. The breakdown tabs
12
+ * therefore cost no request — they re-bucket data the client already holds.
13
+ *
14
+ * Every number here is RAW. Formatting (`$1.23`, `2.2M`) is the client's job,
15
+ * because a formatted string cannot be re-aggregated and cannot be compared
16
+ * against a threshold.
17
+ */
18
+
19
+ /**
20
+ * The PERIOD the panel reports — the one thing the header's switch selects.
21
+ *
22
+ * `today`/`7d`/`30d`/`90d` are trailing calendar spans ending today, labelled
23
+ * Day/Week/Month/90 days; `all` is unbounded. None of them is a grouping
24
+ * cadence: a period is a period, and every figure on the panel is the total for
25
+ * exactly that period.
26
+ */
2
27
  export type TimeRangeType = 'today' | '7d' | '30d' | '90d' | 'all' | 'custom';
3
- export type BreakdownTab = 'model' | 'day' | 'project';
28
+
29
+ /**
30
+ * How the selected period is chopped up for the chart and the time tab only.
31
+ *
32
+ * Derived from the period's own length (`granularityFor`), never chosen by the
33
+ * user: a month draws days, a quarter draws weeks, all time draws months.
34
+ */
35
+ export type BucketGranularity = 'day' | 'week' | 'month';
36
+ /** Breakdown tabs. `provider` and `model` render as one two-level tree. */
37
+ export type BreakdownTab = 'provider' | 'model' | 'day' | 'project';
4
38
  export type ChartMetric = 'cost' | 'tokens';
5
39
 
6
- export interface ChartSeriesPoint {
40
+ export interface TimeRangeOption {
41
+ id: TimeRangeType;
7
42
  label: string;
8
- cost: number;
9
- tokens: number;
43
+ /** The dates this range covers, already formatted for the header. */
44
+ dateRange: string;
10
45
  }
11
46
 
12
- export interface CustomRange {
13
- from: string;
14
- to: string;
47
+ /** Token and cost counters shared by every rollup row. */
48
+ export interface UsageCounters {
49
+ cost: number;
50
+ tokens: number;
51
+ input: number;
52
+ output: number;
53
+ cacheRead: number;
54
+ cacheWrite: number;
55
+ reasoning: number;
56
+ /** Cache-read rate: the observed input that was served from cache. */
57
+ cacheReadCost: number;
58
+ /** Usage records folded into this row. */
59
+ records: number;
60
+ /** Records carrying tokens but no provider-reported cost. */
61
+ unpriced: number;
15
62
  }
16
63
 
17
- export interface BreakdownRow {
18
- name: string;
19
- cost: string;
20
- share: string;
21
- tokens: string;
22
- sharePercent: number;
23
- dotColorClass: string;
64
+ /** Totals for the selected period. */
65
+ export interface UsageTotals extends UsageCounters {
66
+ /** Distinct days with at least one record. */
67
+ activeDays: number;
24
68
  }
25
69
 
26
- export interface TimeRangeOption {
27
- id: TimeRangeType;
70
+ /** One point of the flat chart series (single line, e.g. the mobile view). */
71
+ export interface ChartSeriesPoint {
28
72
  label: string;
29
- dateRange: string;
73
+ cost: number;
74
+ tokens: number;
30
75
  }
31
76
 
77
+ /** Display strings behind the headline tiles, already formatted. */
32
78
  export interface TokenUsageMetricSet {
33
79
  rawCost: string;
80
+ costPerMillion: string;
34
81
  processedTokens: string;
35
82
  activeRate: string;
36
83
  cachedInput: string;
37
84
  cachedPercent: string;
38
85
  uncachedInput: string;
86
+ cacheWrite: string;
39
87
  outputTokens: string;
40
88
  reasoning: string;
41
- cacheSavings: string;
42
- scannedTranscripts: number;
43
- usageRecords: number;
89
+ records: number;
90
+ unpricedRecords: number;
91
+ }
92
+
93
+ /** One model under a provider. `model` is omp's own id, verbatim. */
94
+ export interface UsageModelRow extends UsageCounters {
95
+ model: string;
96
+ }
97
+
98
+ /** One provider, with its models ordered by cost. */
99
+ export interface UsageProviderRow extends UsageCounters {
100
+ /** Canonical provider slug — stable identity, used as the selection key. */
101
+ id: string;
102
+ /** Display name (`Kenari.id`, `DeepSeek`, `Command Code`, …). */
103
+ name: string;
104
+ models: UsageModelRow[];
105
+ }
106
+
107
+ /** One calendar day, with the per-provider split the stacked chart needs. */
108
+ export interface UsageDayRow extends UsageCounters {
109
+ /** `YYYY-MM-DD` in the reader's local calendar. */
110
+ day: string;
111
+ /** Cost/tokens keyed by canonical provider slug. */
112
+ providers: Record<string, { cost: number; tokens: number }>;
113
+ }
114
+
115
+ /** One project (the sessions-tree folder the transcript lives in). */
116
+ export interface UsageProjectRow extends UsageCounters {
117
+ project: string;
118
+ }
119
+
120
+ /** How far the on-disk index has got, shown in the panel's footer. */
121
+ export interface UsageIndexState {
122
+ /** `building` while a scan is in flight; the panel polls and keeps the data. */
123
+ state: 'ready' | 'building' | 'failed';
124
+ /** Transcripts indexed (or visited so far, while building). */
125
+ transcripts: number;
126
+ /** Usage records indexed across every period. */
127
+ records: number;
128
+ /** Epoch ms of the last completed scan. */
129
+ indexedAt: number;
130
+ /** Wall-clock cost of that scan, so a slow disk is visible rather than guessed. */
131
+ scanMs: number;
132
+ /** Sentence for the panel when `state` is `failed`. */
133
+ error?: string;
134
+ }
135
+
136
+ /** Response body of `GET /api/telemetry/tokens`. */
137
+ export interface TokenUsagePayload {
138
+ generatedAt: number;
139
+ index: UsageIndexState;
140
+ timeRanges: TimeRangeOption[];
141
+ range: TimeRangeType;
142
+ /** Human period label, e.g. `Oct 5 – Nov 3, 2026`. */
143
+ periodLabel: string;
144
+ totals: UsageTotals;
145
+ /** Providers ordered by cost, each with its models ordered by cost. */
146
+ providers: UsageProviderRow[];
147
+ /** Daily rows ordered by day, ascending. */
148
+ days: UsageDayRow[];
149
+ /** Projects ordered by cost. */
150
+ projects: UsageProjectRow[];
44
151
  }
@@ -78,6 +78,26 @@ export interface UpdateChangelog {
78
78
  error: string | null;
79
79
  }
80
80
 
81
+ /**
82
+ * The release notes for the version a target is ACTUALLY RUNNING.
83
+ *
84
+ * This is the About modal's pair of "What's new" buttons: the update popup
85
+ * answers "what would I get", these answer "what am I running". Both versions
86
+ * are read server-side from the install itself, never from the caller, so the
87
+ * section shown always belongs to the copy on disk.
88
+ */
89
+ export interface ActiveReleaseNotes {
90
+ target: UpdateTarget;
91
+ /** The installed/running version whose section is shown, or null when unreadable. */
92
+ version: string | null;
93
+ /** That version's changelog section, or null when the file does not name it. */
94
+ note: ReleaseNote | null;
95
+ /** The repository changelog, for the "Full changelog" link. */
96
+ changelogUrl: string;
97
+ /** Human-readable reason `note` is absent, or null. */
98
+ error: string | null;
99
+ }
100
+
81
101
  export interface UpdateApplyResult {
82
102
  success: boolean;
83
103
  target: UpdateTarget;