@kabmo-labs/kabmo 0.17.0 → 0.19.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.
- package/README.md +10 -7
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +523 -441
- package/dist/client/static/js/{index-rerjq5th.js → index-fcee4c13.js} +828 -818
- package/dist/client/static/js/index-sxdw908m.css +1 -0
- package/marketplace/plugins/command-runner/package.json +3 -2
- package/marketplace/plugins/git-forge/package.json +3 -2
- package/marketplace/plugins/session-info/package.json +3 -2
- package/marketplace/plugins/stats/package.json +3 -2
- package/package.json +3 -1
- package/src/client/components/auth/login-screen/index.tsx +2 -1
- package/src/client/components/common/ComposerPicker.tsx +1 -1
- package/src/client/components/common/FolderPicker.tsx +2 -2
- package/src/client/components/common/MarkdownRenderer.tsx +136 -89
- package/src/client/components/common/Modal.tsx +2 -2
- package/src/client/components/common/PWAInstallButton.tsx +2 -2
- package/src/client/components/common/ViewportSelector.tsx +1 -1
- package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
- package/src/client/components/common/anchored-menu/index.tsx +147 -0
- package/src/client/components/common/batch-selection/SelectionCheckbox.tsx +2 -1
- package/src/client/components/common/brand-wordmark/index.test.tsx +13 -2
- package/src/client/components/common/brand-wordmark/index.tsx +13 -2
- package/src/client/components/common/checkbox/style.test.ts +139 -0
- package/src/client/components/common/checkbox/style.ts +51 -0
- package/src/client/components/common/context-usage-button/index.tsx +2 -2
- package/src/client/components/common/file-icon/index.tsx +23 -9
- package/src/client/components/common/header-controls/MoreMenu.tsx +1 -1
- package/src/client/components/common/markdown-review/ReviewPopover.tsx +144 -0
- package/src/client/components/common/markdown-review/ReviewSummary.tsx +108 -0
- package/src/client/components/common/markdown-review/index.tsx +129 -0
- package/src/client/components/common/panel-mark/index.tsx +97 -0
- package/src/client/components/common/provider-icon/glyphs.test.ts +1 -1
- package/src/client/components/common/provider-icon/index.test.ts +14 -0
- package/src/client/components/common/provider-icon/index.tsx +4 -0
- package/src/client/components/common/provider-icon/resolve.test.ts +8 -7
- package/src/client/components/common/provider-icon/resolve.ts +16 -3
- package/src/client/components/common/server-control/Panel.tsx +33 -23
- package/src/client/components/common/server-control/index.test.tsx +11 -5
- package/src/client/components/common/server-control/index.tsx +10 -8
- package/src/client/components/common/session-actions-menu/index.tsx +1 -1
- package/src/client/components/common/toolbar-row/index.tsx +1 -1
- package/src/client/components/layout/ActivityBar.tsx +22 -3
- package/src/client/components/layout/LeftDock.tsx +9 -2
- package/src/client/components/layout/PanelVisibilityMenu.tsx +1 -1
- package/src/client/components/layout/WindowAura.tsx +27 -0
- package/src/client/components/layout/desktop-layout/LeftColumn.tsx +1 -1
- package/src/client/components/layout/desktop-layout/TopNavbar.tsx +2 -2
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +11 -2
- package/src/client/components/layout/desktop-layout/index.tsx +3 -1
- package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +44 -23
- package/src/client/components/layout/session-sidebar/CategoryHeader.worktree.test.tsx +36 -17
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +8 -7
- package/src/client/components/layout/session-sidebar/Header.tsx +1 -1
- package/src/client/components/layout/session-sidebar/OverflowMenu.tsx +1 -1
- package/src/client/components/layout/session-sidebar/Toolbar.tsx +1 -1
- package/src/client/components/layout/session-sidebar/about-modal/NotesDialog.tsx +94 -0
- package/src/client/components/layout/session-sidebar/about-modal/VersionLine.test.tsx +68 -0
- package/src/client/components/layout/session-sidebar/about-modal/VersionLine.tsx +36 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +57 -34
- package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +1 -1
- package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +40 -14
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +7 -6
- package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +1 -1
- package/src/client/components/layout/session-sidebar/new-workspace-modal/index.tsx +2 -2
- package/src/client/components/layout/session-sidebar/scheduler-modal/TaskForm.tsx +2 -1
- package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +2 -2
- package/src/client/components/layout/update-popup/ReleaseNotes.tsx +8 -3
- package/src/client/components/layout/update-popup/index.tsx +5 -1
- package/src/client/components/mobile/LayoutWrapper.tsx +3 -1
- package/src/client/components/mobile/mobile-main-view/Header.tsx +2 -2
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +13 -15
- package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +23 -1
- package/src/client/components/mobile/mobile-right-sidebar/MissingFileBanner.tsx +30 -0
- package/src/client/components/mobile/mobile-right-sidebar/PreviewScroller.tsx +18 -2
- package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +1 -1
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +22 -67
- package/src/client/components/mobile/mobile-session-sidebar/ItemMenu.tsx +110 -0
- package/src/client/components/mobile/mobile-session-sidebar/Toolbar.tsx +1 -1
- package/src/client/components/mobile/panel-chips.tsx +10 -2
- package/src/client/components/settings/Modal.tsx +4 -4
- package/src/client/components/settings/ProjectSelectorDropdown.tsx +2 -2
- package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
- package/src/client/components/settings/apply-side-effects.test.ts +30 -0
- package/src/client/components/settings/apply-side-effects.ts +14 -0
- package/src/client/components/settings/categories/AgentSettings.tsx +23 -50
- package/src/client/components/settings/categories/AppearanceSettings.tsx +6 -0
- package/src/client/components/settings/categories/CommandSettings.tsx +2 -2
- package/src/client/components/settings/categories/McpSettings.tsx +4 -21
- package/src/client/components/settings/categories/OmpSettings.tsx +147 -194
- package/src/client/components/settings/categories/SkillSettings.tsx +2 -2
- package/src/client/components/settings/categories/TokenUsageSettings.tsx +211 -229
- package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +229 -237
- package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +71 -0
- package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +9 -2
- package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
- package/src/client/components/settings/categories/appearance-settings/EditorBlameSection.tsx +2 -1
- package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +2 -1
- package/src/client/components/settings/categories/appearance-settings/IconStyleSection.tsx +144 -0
- package/src/client/components/settings/categories/appearance-settings/SurfaceStyleSection.test.tsx +120 -0
- package/src/client/components/settings/categories/appearance-settings/SurfaceStyleSection.tsx +180 -0
- package/src/client/components/settings/categories/behavior-settings/Editor.tsx +27 -7
- package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +23 -5
- package/src/client/components/settings/categories/command-settings/DetailPane.tsx +75 -33
- package/src/client/components/settings/categories/command-settings/SidebarList.tsx +7 -0
- package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +93 -77
- package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
- package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +28 -15
- package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +20 -0
- package/src/client/components/settings/categories/omp-settings/ConfigTabs.tsx +97 -36
- package/src/client/components/settings/categories/omp-settings/EngineHeader.tsx +151 -0
- package/src/client/components/settings/categories/omp-settings/ExtensionsPanel.tsx +68 -32
- package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +119 -0
- package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +14 -7
- package/src/client/components/settings/categories/omp-settings/RoleEditor.tsx +15 -6
- package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +165 -226
- package/src/client/components/settings/categories/omp-settings/types.ts +28 -0
- package/src/client/components/settings/categories/panel-plugins/AvailableList.tsx +1 -1
- package/src/client/components/settings/categories/panel-plugins/BuiltinList.tsx +21 -3
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +1 -1
- package/src/client/components/settings/categories/panel-plugins/PluginMark.test.ts +51 -2
- package/src/client/components/settings/categories/panel-plugins/PluginMark.tsx +43 -10
- package/src/client/components/settings/categories/plugin-settings/DetailPane.tsx +2 -1
- package/src/client/components/settings/categories/plugin-settings/SettingsSection.tsx +2 -1
- package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +1 -1
- package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
- package/src/client/components/settings/categories/provider-settings/DeleteProviderModal.tsx +2 -2
- package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +3 -2
- package/src/client/components/settings/categories/provider-settings/LogoutProviderModal.tsx +2 -2
- package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +3 -2
- package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +37 -8
- package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +34 -14
- package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +21 -0
- package/src/client/components/settings/categories/skill-settings/pane.test.tsx +15 -6
- package/src/client/components/settings/categories/token-usage-settings/Breakdown.tsx +242 -102
- package/src/client/components/settings/categories/token-usage-settings/Chart.tsx +130 -56
- package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +135 -0
- package/src/client/components/settings/categories/token-usage-settings/MetricsGrid.tsx +55 -33
- package/src/client/components/settings/categories/token-usage-settings/Provenance.tsx +59 -0
- package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +239 -0
- package/src/client/components/workspace/browser-panel/Screencast.test.ts +1 -0
- package/src/client/components/workspace/browser-panel/Screencast.tsx +17 -22
- package/src/client/components/workspace/browser-panel/TabStrip.test.tsx +158 -0
- package/src/client/components/workspace/browser-panel/TabStrip.tsx +90 -0
- package/src/client/components/workspace/browser-panel/index.tsx +50 -4
- package/src/client/components/workspace/browser-toolbar/index.tsx +41 -1
- package/src/client/components/workspace/btw-panel/TopicMenu.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/NewChatModal.tsx +3 -3
- package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +3 -1
- package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/UndoConfirmModal.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
- package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/chat-input/GoalModal.tsx +4 -3
- package/src/client/components/workspace/chat-timeline/chat-input/ThinkingLevelDropdown.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/plan-review/index.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +2 -6
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +88 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +24 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +34 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +5 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactChip.tsx +7 -6
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +237 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +191 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +1 -1
- package/src/client/components/workspace/context-panel/CostBreakdownPopover.tsx +1 -1
- package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +21 -7
- package/src/client/components/workspace/diff-panel/changes.test.ts +51 -0
- package/src/client/components/workspace/diff-panel/changes.ts +28 -12
- package/src/client/components/workspace/diff-panel/index.tsx +2 -2
- package/src/client/components/workspace/diff-panel/merge.test.ts +28 -0
- package/src/client/components/workspace/diff-panel/merge.ts +21 -1
- package/src/client/components/workspace/editor/Body.tsx +7 -0
- package/src/client/components/workspace/editor/FileDocument.tsx +15 -21
- package/src/client/components/workspace/editor/FilePane.tsx +12 -0
- package/src/client/components/workspace/editor/PluginRail.tsx +1 -1
- package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
- package/src/client/components/workspace/editor/SaveDeletedFileModal.tsx +2 -2
- package/src/client/components/workspace/editor/TabContextMenu.tsx +1 -1
- package/src/client/components/workspace/editor/Tabs.tsx +1 -1
- package/src/client/components/workspace/editor/Toolbar.tsx +17 -1
- package/src/client/components/workspace/editor/index.tsx +25 -22
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +14 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +12 -86
- package/src/client/components/workspace/editor/toolbar-toggle.tsx +53 -0
- package/src/client/components/workspace/editor/toolbar-write-clusters.tsx +112 -0
- package/src/client/components/workspace/file-explorer/ContextMenu.tsx +1 -1
- package/src/client/components/workspace/file-explorer/Modals.tsx +10 -10
- package/src/client/components/workspace/file-explorer/RootMenu.tsx +1 -1
- package/src/client/components/workspace/git-panel/BranchToolbar.test.tsx +130 -0
- package/src/client/components/workspace/git-panel/BranchToolbar.tsx +21 -11
- package/src/client/components/workspace/git-panel/CommitBox.tsx +2 -1
- package/src/client/components/workspace/git-panel/Modals.tsx +2 -2
- package/src/client/components/workspace/git-panel/StashSection.tsx +2 -1
- package/src/client/components/workspace/git-panel/branch-modal/DeleteDialog.tsx +2 -1
- package/src/client/components/workspace/git-panel/branch-modal/RenameDialog.tsx +2 -1
- package/src/client/components/workspace/git-panel/commit-modal/index.tsx +2 -2
- package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
- package/src/client/components/workspace/git-panel/index.tsx +7 -0
- package/src/client/components/workspace/model-dropdown/Panel.tsx +1 -1
- package/src/client/components/workspace/model-dropdown/SpecsTooltip.tsx +1 -1
- package/src/client/components/workspace/plugin-panel/catalog.tsx +7 -0
- package/src/client/components/workspace/plugin-panel/resolve.tsx +4 -0
- package/src/client/components/workspace/search-panel/Body.tsx +1 -1
- package/src/client/components/workspace/usage-panel/ProviderSelect.tsx +1 -1
- package/src/client/components/workspace/user-browser-panel/AddressBar.tsx +5 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateBar.test.tsx +201 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateBar.tsx +112 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateLayer.test.tsx +225 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateLayer.tsx +217 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateTarget.tsx +99 -0
- package/src/client/components/workspace/user-browser-panel/Frame.tsx +30 -1
- package/src/client/components/workspace/user-browser-panel/index.tsx +81 -2
- package/src/client/data/agent-data/builtin.ts +0 -10
- package/src/client/data/agent-data/orchestrator.ts +0 -45
- package/src/client/data/agent-data/specialist.ts +0 -100
- package/src/client/data/mock/token-usage.ts +170 -120
- package/src/client/data/settings/omp-schema.json +33 -1
- package/src/client/glass.css +785 -0
- package/src/client/glass.test.ts +346 -0
- package/src/client/hooks/browser/use-annotate.test.ts +143 -0
- package/src/client/hooks/browser/use-annotate.ts +98 -0
- package/src/client/hooks/browser/use-close-tab.test.ts +148 -0
- package/src/client/hooks/browser/use-close-tab.ts +67 -0
- package/src/client/hooks/browser/use-screencast.ts +13 -1
- package/src/client/hooks/chat/composer/browser-context.test.ts +117 -0
- package/src/client/hooks/chat/composer/browser-context.ts +40 -16
- package/src/client/hooks/chat/composer/items.test.ts +1 -1
- package/src/client/hooks/chat/composer/review-context.ts +38 -0
- package/src/client/hooks/chat/composer/use-draft.test.ts +132 -0
- package/src/client/hooks/chat/composer/use-draft.ts +31 -2
- package/src/client/hooks/chat/timeline/row-window.test.ts +15 -2
- package/src/client/hooks/editor/use-document-annotations.ts +124 -0
- package/src/client/hooks/editor/use-editor-panel-ui.ts +52 -0
- package/src/client/hooks/editor/use-file-review-mode.ts +35 -0
- package/src/client/hooks/editor/use-preview-review.ts +148 -0
- package/src/client/hooks/settings/agents.ts +149 -0
- package/src/client/hooks/settings/crud-list.test.ts +28 -6
- package/src/client/hooks/settings/crud-list.ts +96 -57
- package/src/client/hooks/settings/omp-config.ts +164 -0
- package/src/client/hooks/settings/useTokenUsage.ts +125 -0
- package/src/client/hooks/settings/write-feedback.test.ts +104 -0
- package/src/client/hooks/settings/write-feedback.ts +63 -0
- package/src/client/hooks/ui/glass-support.ts +57 -0
- package/src/client/hooks/ui/icon-style.ts +59 -0
- package/src/client/hooks/ui/markdown-hydration.ts +125 -0
- package/src/client/hooks/ui/stuck-header.test.ts +188 -0
- package/src/client/hooks/ui/stuck-header.ts +91 -0
- package/src/client/hooks/ui/style-attributes.test.ts +120 -0
- package/src/client/hooks/ui/surface-style.ts +56 -0
- package/src/client/hooks/ui/updates/index.test.ts +100 -1
- package/src/client/hooks/ui/updates/index.ts +50 -0
- package/src/client/hooks/ui/updates/notes.test.ts +138 -0
- package/src/client/hooks/ui/updates/notes.ts +57 -0
- package/src/client/hooks/workspace/panel-hues.ts +23 -0
- package/src/client/lib/browser/element-at.test.ts +229 -0
- package/src/client/lib/browser/element-at.ts +139 -0
- package/src/client/lib/review/client.ts +73 -0
- package/src/client/lib/router/search-params.ts +42 -20
- package/src/client/main.tsx +10 -0
- package/src/client/tailwind.css +329 -11
- package/src/server/lib/assets/shell-attributes.server.ts +80 -0
- package/src/server/lib/assets/shell-attributes.test.ts +86 -0
- package/src/server/lib/btw/lifecycle.server.ts +2 -2
- package/src/server/lib/db/schema.ts +7 -0
- package/src/server/lib/db/seed-terminal.test.ts +4 -0
- package/src/server/lib/omp/config/agent-definitions.test.ts +273 -0
- package/src/server/lib/omp/config/agents.ts +231 -61
- package/src/server/lib/omp/config/definitions.test.ts +9 -105
- package/src/server/lib/omp/config/extensions.ts +16 -7
- package/src/server/lib/omp/config/omp-config-files.test.ts +27 -0
- package/src/server/lib/omp/rpc/constants.test.ts +11 -0
- package/src/server/lib/omp/rpc/constants.ts +15 -0
- package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +1 -0
- package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +2 -30
- package/src/server/lib/omp/rpc/frame-fold.test.ts +55 -0
- package/src/server/lib/omp/rpc/frame-fold.ts +4 -0
- package/src/server/lib/omp/rpc/manager.ts +2 -2
- package/src/server/lib/omp/rpc/process-helpers.ts +11 -0
- package/src/server/lib/omp/rpc/process.test.ts +106 -0
- package/src/server/lib/omp/rpc/process.ts +39 -18
- package/src/server/lib/omp/rpc/run-settle.server.ts +12 -0
- package/src/server/lib/omp/rpc/run-settle.test.ts +22 -0
- package/src/server/lib/omp/rpc/session-command-guards.ts +5 -0
- package/src/server/lib/omp/rpc/session-commands.test.ts +9 -1
- package/src/server/lib/omp/rpc/session-commands.ts +17 -3
- package/src/server/lib/omp/rpc/terminal-settle.ts +29 -7
- package/src/server/lib/omp/rpc/utility-agent-dir.test.ts +134 -0
- package/src/server/lib/omp/rpc/utility-agent-dir.ts +138 -0
- package/src/server/lib/omp/rpc/utility.ts +12 -0
- package/src/server/lib/panels/bundled-catalog.server.ts +1 -0
- package/src/server/lib/panels/manifest.test.ts +20 -0
- package/src/server/lib/panels/manifest.ts +12 -0
- package/src/server/lib/panels/scan.server.ts +4 -0
- package/src/server/lib/queue/delivery-dispatch.server.test.ts +48 -0
- package/src/server/lib/queue/delivery-harness.ts +8 -4
- package/src/server/lib/queue/delivery.server.test.ts +29 -0
- package/src/server/lib/queue/delivery.server.ts +39 -0
- package/src/server/lib/queue/store.server.test.ts +22 -2
- package/src/server/lib/queue/store.server.ts +33 -11
- package/src/server/lib/review/schema.server.ts +45 -0
- package/src/server/lib/review/store.server.ts +138 -0
- package/src/server/lib/terminal/attach-replay.test.ts +132 -0
- package/src/server/lib/terminal/output.test.ts +166 -0
- package/src/server/lib/terminal/output.ts +104 -0
- package/src/server/lib/terminal/runtime.server.ts +5 -0
- package/src/server/lib/terminal/send-result.test.ts +33 -0
- package/src/server/lib/terminal/send-result.ts +32 -0
- package/src/server/lib/terminal/session.server.ts +45 -11
- package/src/server/lib/terminal/store-liveness.test.ts +4 -0
- package/src/server/lib/updates/active-notes.test.ts +149 -0
- package/src/server/lib/updates/active-notes.ts +75 -0
- package/src/server/lib/updates/changelog-file.ts +42 -11
- package/src/server/lib/updates/changelog.test.ts +15 -1
- package/src/server/lib/updates/omp.ts +42 -15
- package/src/server/lib/updates/release-url.ts +27 -1
- package/src/server/lib/usage/index-parse.test.ts +200 -0
- package/src/server/lib/usage/index-parse.ts +178 -0
- package/src/server/lib/usage/index-query.server.ts +248 -0
- package/src/server/lib/usage/index-scan.server.ts +343 -0
- package/src/server/lib/usage/index-schema.server.ts +82 -0
- package/src/server/lib/usage/index.test.ts +234 -0
- package/src/server/lib/usage/providers.server.ts +4 -53
- package/src/server/plugins/ssr.ts +22 -5
- package/src/server/routes/browser/index.ts +3 -0
- package/src/server/routes/browser/stream.ts +31 -2
- package/src/server/routes/browser/tabs.test.ts +94 -0
- package/src/server/routes/browser/tabs.ts +85 -0
- package/src/server/routes/index.ts +2 -0
- package/src/server/routes/review/bindings.ts +11 -0
- package/src/server/routes/review/index.ts +127 -0
- package/src/server/routes/review/routes.test.ts +191 -0
- package/src/server/routes/settings/agents.test.ts +180 -0
- package/src/server/routes/settings/agents.ts +95 -102
- package/src/server/routes/settings/mcp.test.ts +135 -0
- package/src/server/routes/settings/mcp.ts +14 -6
- package/src/server/routes/settings/settings-store-routes.test.ts +6 -113
- package/src/server/routes/telemetry/tokens.test.ts +145 -0
- package/src/server/routes/telemetry/tokens.ts +70 -149
- package/src/server/routes/terminal/ws.ts +6 -5
- package/src/server/routes/updates/index.ts +2 -0
- package/src/server/routes/updates/notes.ts +34 -0
- package/src/server/routes/updates/routes.test.ts +49 -0
- package/src/shared/lib/browser/annotate.test.ts +283 -0
- package/src/shared/lib/browser/annotate.ts +231 -0
- package/src/shared/lib/browser/browser-viewer.test.ts +26 -4
- package/src/shared/lib/browser/frame-gate.test.ts +91 -0
- package/src/shared/lib/browser/frame-gate.ts +69 -0
- package/src/shared/lib/browser/frame-params.test.ts +43 -0
- package/src/shared/lib/browser/frame-params.ts +60 -0
- package/src/shared/lib/browser/frame-pipeline.test.ts +132 -0
- package/src/shared/lib/browser/frame-pipeline.ts +80 -0
- package/src/shared/lib/browser/page-context.ts +60 -4
- package/src/shared/lib/browser/snapshot.test.ts +115 -0
- package/src/shared/lib/browser/snapshot.ts +112 -0
- package/src/shared/lib/browser/tab-close.test.ts +74 -0
- package/src/shared/lib/browser/tab-close.ts +77 -0
- package/src/shared/lib/browser/viewer.ts +45 -26
- package/src/shared/lib/chat/timeline/block-chrome.ts +19 -0
- package/src/shared/lib/chat/timeline/tool-render-mode.ts +17 -4
- package/src/shared/lib/chat/tool/artifact.ts +55 -20
- package/src/shared/lib/chat/tool/bash-facts.ts +96 -0
- package/src/shared/lib/chat/tool/minimized.test.ts +98 -0
- package/src/shared/lib/chat/tool/minimized.ts +64 -0
- package/src/shared/lib/chat/tool/summary.test.ts +28 -8
- package/src/shared/lib/chat/tool/summary.ts +3 -32
- package/src/shared/lib/icons/file-brand-color.ts +38 -0
- package/src/shared/lib/icons/icon-paint-css.test.ts +234 -0
- package/src/shared/lib/icons/icon-paint-css.ts +284 -0
- package/src/shared/lib/icons/icon-paint-panel.ts +100 -0
- package/src/shared/lib/icons/tint-hues.generated.ts +230 -0
- package/src/shared/lib/icons/tint.test.ts +273 -0
- package/src/shared/lib/icons/tint.ts +219 -0
- package/src/shared/lib/markdown/blocks/anchor.ts +63 -0
- package/src/shared/lib/markdown/blocks/blocks.test.ts +141 -0
- package/src/shared/lib/markdown/blocks/renderer.ts +120 -0
- package/src/shared/lib/markdown/blocks/scan.ts +100 -0
- package/src/shared/lib/markdown/blocks/types.ts +62 -0
- package/src/shared/lib/markdown/marked.ts +58 -147
- package/src/shared/lib/markdown/math-extensions.ts +168 -0
- package/src/shared/lib/markdown/review/prompt.ts +77 -0
- package/src/shared/lib/markdown/review/reconcile.ts +55 -0
- package/src/shared/lib/markdown/review/review.test.ts +96 -0
- package/src/shared/lib/markdown/xml-sections.test.ts +140 -0
- package/src/shared/lib/markdown/xml-sections.ts +139 -0
- package/src/shared/lib/models/provider/brand-color.test.ts +116 -0
- package/src/shared/lib/models/provider/brand-color.ts +103 -0
- package/src/shared/lib/models/provider/label.ts +57 -0
- package/src/shared/lib/omp/config/agent-file.test.ts +54 -0
- package/src/shared/lib/omp/config/agent-file.ts +43 -0
- package/src/shared/lib/omp/config/row-value.test.ts +95 -0
- package/src/shared/lib/omp/config/row-value.ts +97 -0
- package/src/shared/lib/omp/config/schema.test.ts +31 -0
- package/src/shared/lib/omp/config/schema.ts +6 -0
- package/src/shared/lib/omp/rpc/frame.test.ts +113 -47
- package/src/shared/lib/omp/rpc/frame.ts +107 -43
- package/src/shared/lib/settings/defaults.ts +4 -0
- package/src/shared/lib/theme/catalog.test.ts +5 -4
- package/src/shared/lib/theme/catalog.ts +18 -3
- package/src/shared/lib/theme/glass-support.test.ts +38 -0
- package/src/shared/lib/theme/glass-support.ts +73 -0
- package/src/shared/lib/theme/icon-style.test.ts +74 -0
- package/src/shared/lib/theme/icon-style.ts +90 -0
- package/src/shared/lib/theme/legibility.ts +91 -0
- package/src/shared/lib/theme/palettes/dark-extended.ts +152 -0
- package/src/shared/lib/theme/palettes/light-extended.ts +157 -0
- package/src/shared/lib/theme/surface-style.test.ts +68 -0
- package/src/shared/lib/theme/surface-style.ts +91 -0
- package/src/shared/lib/theme/theme.test.ts +11 -7
- package/src/shared/lib/ui/menu-anchor.test.ts +69 -0
- package/src/shared/lib/ui/menu-anchor.ts +89 -0
- package/src/shared/lib/usage/breakdown.test.ts +197 -0
- package/src/shared/lib/usage/breakdown.ts +241 -0
- package/src/shared/lib/usage/range.test.ts +204 -0
- package/src/shared/lib/usage/range.ts +240 -0
- package/src/shared/lib/usage/view.test.ts +85 -0
- package/src/shared/lib/usage/view.ts +74 -0
- package/src/shared/lib/workspace/panel-hues.test.ts +68 -0
- package/src/shared/lib/workspace/panel-hues.ts +57 -0
- package/src/shared/types/browser.ts +78 -0
- package/src/shared/types/index.ts +1 -0
- package/src/shared/types/panels-registry.ts +6 -0
- package/src/shared/types/panels.ts +14 -0
- package/src/shared/types/settings/agent.ts +28 -6
- package/src/shared/types/settings/state.ts +30 -3
- package/src/shared/types/settings/write.ts +6 -0
- package/src/shared/types/tokenUsage.ts +128 -21
- package/src/shared/types/updates.ts +20 -0
- package/src/test-support/fake-omp-frames.ts +163 -0
- package/dist/client/static/js/index-3ve31rzx.css +0 -1
- package/src/server/lib/omp/session/usage/aggregate-shaping.test.ts +0 -149
- package/src/server/lib/omp/session/usage/aggregate.test.ts +0 -243
- package/src/server/lib/omp/session/usage/aggregate.ts +0 -330
- package/src/server/lib/omp/session/usage/shaping.ts +0 -130
- /package/src/{client/components/common/file-icon/brand-paths.ts → shared/lib/icons/file-brand-paths.ts} +0 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Breakdown and chart view models (`breakdown.ts`).
|
|
8
|
+
*
|
|
9
|
+
* These are the rows 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 per-bucket average divided by the wrong count.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
breakdownRows,
|
|
19
|
+
bucketDays,
|
|
20
|
+
chartSeries,
|
|
21
|
+
dayRows,
|
|
22
|
+
providerModelRows,
|
|
23
|
+
} from '@/shared/lib/usage/breakdown';
|
|
24
|
+
import type { UsageDayRow, UsageProviderRow, UsageTotals } from '@/shared/types';
|
|
25
|
+
|
|
26
|
+
const counters = (cost: number, tokens: number, records = 1, cacheRead = 0, input = 0) => ({
|
|
27
|
+
cost, tokens, input, output: tokens - input - cacheRead, cacheRead, cacheWrite: 0,
|
|
28
|
+
reasoning: 0, cacheReadCost: cost * 0.1, records, unpriced: 0,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const provider = (id: string, name: string, models: Array<[string, number, number]>): UsageProviderRow => {
|
|
32
|
+
const rows = models.map(([model, cost, tokens]) => ({ model, ...counters(cost, tokens) }));
|
|
33
|
+
return {
|
|
34
|
+
id,
|
|
35
|
+
name,
|
|
36
|
+
models: rows,
|
|
37
|
+
...rows.reduce(
|
|
38
|
+
(acc, row) => ({
|
|
39
|
+
...acc,
|
|
40
|
+
cost: acc.cost + row.cost,
|
|
41
|
+
tokens: acc.tokens + row.tokens,
|
|
42
|
+
records: acc.records + row.records,
|
|
43
|
+
}),
|
|
44
|
+
{ cost: 0, tokens: 0, records: 0 },
|
|
45
|
+
),
|
|
46
|
+
input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reasoning: 0, cacheReadCost: 0, unpriced: 0,
|
|
47
|
+
} as UsageProviderRow;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const totals: UsageTotals = {
|
|
51
|
+
...counters(20, 1_000_000, 40, 900_000, 50_000),
|
|
52
|
+
unpriced: 4,
|
|
53
|
+
activeDays: 6,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const day = (key: string, cost: number, tokens: number, providers: Record<string, { cost: number; tokens: number }>): UsageDayRow => ({
|
|
57
|
+
day: key,
|
|
58
|
+
providers,
|
|
59
|
+
...counters(cost, tokens),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('bucketDays', () => {
|
|
63
|
+
const days = [
|
|
64
|
+
day('2026-10-31', 1, 10, { kenari: { cost: 1, tokens: 10 } }),
|
|
65
|
+
day('2026-11-02', 3, 30, { 'kenari-jatis': { cost: 2, tokens: 20 }, kenari: { cost: 1, tokens: 10 } }),
|
|
66
|
+
day('2026-11-03', 4, 40, { 'kenari-jatis': { cost: 4, tokens: 40 } }),
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
test('a week merges its days and sums each provider separately', () => {
|
|
70
|
+
const buckets = bucketDays(days, 'week');
|
|
71
|
+
// Oct 31 is a Saturday in the week of Oct 26; Nov 2–3 fall in the week of Nov 2.
|
|
72
|
+
expect(buckets.map((bucket) => bucket.label)).toEqual(['Oct 26', 'Nov 2']);
|
|
73
|
+
expect(buckets[1].cost).toBe(7);
|
|
74
|
+
expect(buckets[1].byProvider['kenari-jatis']).toEqual({ cost: 6, tokens: 60 });
|
|
75
|
+
expect(buckets[1].byProvider.kenari).toEqual({ cost: 1, tokens: 10 });
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('a month keeps one bucket per month, ordered', () => {
|
|
79
|
+
const buckets = bucketDays(days, 'month');
|
|
80
|
+
expect(buckets.map((bucket) => bucket.label)).toEqual(['Oct', 'Nov']);
|
|
81
|
+
expect(buckets[1].cost).toBe(7);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('the flat series matches the buckets it summarises', () => {
|
|
85
|
+
expect(chartSeries(days, 'day')).toEqual([
|
|
86
|
+
{ label: 'Oct 31', cost: 1, tokens: 10 },
|
|
87
|
+
{ label: 'Nov 2', cost: 3, tokens: 30 },
|
|
88
|
+
{ label: 'Nov 3', cost: 4, tokens: 40 },
|
|
89
|
+
]);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('providerModelRows', () => {
|
|
94
|
+
const providers = [
|
|
95
|
+
provider('kenari-jatis', 'Kenari Jatis', [['deepseek-v4-1-flash', 18, 900]]),
|
|
96
|
+
provider('kenari', 'Kenari.id', [['deepseek-v4-1-flash', 1.5, 80], ['minimax-m3', 0.5, 20]]),
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
test('one model id under two providers is two subtrees, not one row', () => {
|
|
100
|
+
const rows = providerModelRows(providers, 20);
|
|
101
|
+
expect(rows.map((row) => `${row.kind}:${row.label}`)).toEqual([
|
|
102
|
+
'group:Kenari Jatis',
|
|
103
|
+
'row:deepseek-v4-1-flash',
|
|
104
|
+
'group:Kenari.id',
|
|
105
|
+
'row:deepseek-v4-1-flash',
|
|
106
|
+
'row:minimax-m3',
|
|
107
|
+
]);
|
|
108
|
+
// Keys stay unique even where the label repeats.
|
|
109
|
+
expect(new Set(rows.map((row) => row.key)).size).toBe(rows.length);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('model share is of the period, and of its provider', () => {
|
|
113
|
+
const rows = providerModelRows(providers, 20);
|
|
114
|
+
const jatisModel = rows[1];
|
|
115
|
+
expect(jatisModel.sharePercent).toBe(90);
|
|
116
|
+
expect(jatisModel.shareOfParentPercent).toBe(100);
|
|
117
|
+
const kenariSmall = rows[4];
|
|
118
|
+
expect(kenariSmall.sharePercent).toBe(2.5);
|
|
119
|
+
expect(kenariSmall.shareOfParentPercent).toBe(25);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('a row is the period total, with no derived per-day figure', () => {
|
|
123
|
+
const rows = providerModelRows(providers, 20);
|
|
124
|
+
expect(rows[0].cost).toBe(18);
|
|
125
|
+
expect(rows[1].cost).toBe(18);
|
|
126
|
+
expect(rows[1].tokens).toBe(900);
|
|
127
|
+
expect('display' in rows[1]).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('a zero total does not divide by zero', () => {
|
|
131
|
+
const rows = providerModelRows([provider('x', 'X', [['m', 0, 0]])], 0);
|
|
132
|
+
expect(rows.every((row) => row.sharePercent === 0)).toBe(true);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('dayRows', () => {
|
|
137
|
+
const days = [
|
|
138
|
+
day('2026-11-02', 1, 10, { kenari: { cost: 1, tokens: 10 } }),
|
|
139
|
+
day('2026-11-03', 3, 30, { kenari: { cost: 3, tokens: 30 } }),
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
test('lists the period oldest first, and a quiet day is still listed', () => {
|
|
143
|
+
// Nov 1 has no records at all; the table must still show it, or the list
|
|
144
|
+
// silently stops matching the period it claims to describe.
|
|
145
|
+
const rows = dayRows(days, 'day', 4, { from: '2026-11-01', to: '2026-11-03' });
|
|
146
|
+
expect(rows.map((row) => row.label)).toEqual(['Nov 1', 'Nov 2', 'Nov 3']);
|
|
147
|
+
expect(rows[0].cost).toBe(0);
|
|
148
|
+
expect(rows[0].sharePercent).toBe(0);
|
|
149
|
+
expect(rows[2].sharePercent).toBe(75);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('a weekly bucket sums the week into one row per week of the period', () => {
|
|
153
|
+
const rows = dayRows(days, 'week', 4, { from: '2026-11-02', to: '2026-11-03' });
|
|
154
|
+
expect(rows).toHaveLength(1);
|
|
155
|
+
expect(rows[0].label).toBe('Nov 2');
|
|
156
|
+
expect(rows[0].cost).toBe(4);
|
|
157
|
+
expect(rows[0].records).toBe(2);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('all time lists every month between its first and last recorded day', () => {
|
|
161
|
+
// A quiet month in the middle of the history must not vanish: the rows
|
|
162
|
+
// have to add up to the totals shown beside them.
|
|
163
|
+
const rows = dayRows(
|
|
164
|
+
[day('2026-06-24', 1, 10, { kenari: { cost: 1, tokens: 10 } }), day('2026-08-02', 2, 20, { kenari: { cost: 2, tokens: 20 } })],
|
|
165
|
+
'month',
|
|
166
|
+
3,
|
|
167
|
+
{ from: '2026-06-24', to: '2026-08-02' },
|
|
168
|
+
);
|
|
169
|
+
expect(rows.map((row) => row.label)).toEqual(['Jun', 'Jul', 'Aug']);
|
|
170
|
+
expect(rows[1].cost).toBe(0);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('without a window only the days that saw usage are listed', () => {
|
|
174
|
+
// All-time has no bounded window, so the rollup's own days are the list.
|
|
175
|
+
const rows = dayRows(days, 'day', 4, null);
|
|
176
|
+
expect(rows.map((row) => row.label)).toEqual(['Nov 2', 'Nov 3']);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe('breakdownRows', () => {
|
|
181
|
+
const providers = [provider('kenari', 'Kenari.id', [['m', 4, 40]])];
|
|
182
|
+
const payload = {
|
|
183
|
+
totals: { ...totals, cost: 4, tokens: 40, activeDays: 1 },
|
|
184
|
+
providers,
|
|
185
|
+
days: [day('2026-11-03', 4, 40, { kenari: { cost: 4, tokens: 40 } })],
|
|
186
|
+
projects: [],
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
test('provider and model tabs draw the same tree', () => {
|
|
190
|
+
expect(breakdownRows('provider', payload, 'day', null)).toEqual(breakdownRows('model', payload, 'day', null));
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('each tab selects its own source', () => {
|
|
194
|
+
expect(breakdownRows('day', payload, 'day', null)[0].label).toBe('Nov 3');
|
|
195
|
+
expect(breakdownRows('project', payload, 'day', null)).toEqual([]);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The Token Usage breakdown and chart view models.
|
|
8
|
+
*
|
|
9
|
+
* Everything here re-folds data the client ALREADY holds: the payload carries
|
|
10
|
+
* the period's daily rows, so the tab switch costs no request, and the chart's
|
|
11
|
+
* bucket width follows the period's own length (`granularityFor`).
|
|
12
|
+
*
|
|
13
|
+
* Two rules that were bugs before:
|
|
14
|
+
*
|
|
15
|
+
* - a provider is part of a row's identity, so one model id served by two
|
|
16
|
+
* accounts is two subtrees rather than one merged cost;
|
|
17
|
+
* - an unpriced turn is counted per RECORD (tokens, no reported cost), never
|
|
18
|
+
* folded into a zero cost that reads as "free".
|
|
19
|
+
*
|
|
20
|
+
* There is no per-day/per-week figure anywhere: a period is a period, and every
|
|
21
|
+
* row is that period's total.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import type {
|
|
25
|
+
BreakdownTab,
|
|
26
|
+
BucketGranularity,
|
|
27
|
+
ChartSeriesPoint,
|
|
28
|
+
UsageDayRow,
|
|
29
|
+
UsageProjectRow,
|
|
30
|
+
UsageProviderRow,
|
|
31
|
+
UsageTotals,
|
|
32
|
+
} from '@/shared/types';
|
|
33
|
+
import { bucketKey, bucketLabel, compareDayKeys, daysInWindow, type DayWindow } from '@/shared/lib/usage/range';
|
|
34
|
+
import { cacheHitLabel } from '@/shared/lib/usage/view';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Chart points for one granularity, plus the per-provider split the stacked
|
|
38
|
+
* area draws.
|
|
39
|
+
*
|
|
40
|
+
* Buckets are the union of the days present — an empty day inside the range is
|
|
41
|
+
* inserted so the line does not draw a straight diagonal over a gap.
|
|
42
|
+
*/
|
|
43
|
+
export interface CadenceBucket {
|
|
44
|
+
key: string;
|
|
45
|
+
label: string;
|
|
46
|
+
cost: number;
|
|
47
|
+
tokens: number;
|
|
48
|
+
byProvider: Record<string, { cost: number; tokens: number }>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function bucketDays(days: readonly UsageDayRow[], granularity: BucketGranularity): CadenceBucket[] {
|
|
52
|
+
const buckets = new Map<string, CadenceBucket>();
|
|
53
|
+
for (const day of days) {
|
|
54
|
+
const key = bucketKey(day.day, granularity);
|
|
55
|
+
let bucket = buckets.get(key);
|
|
56
|
+
if (!bucket) {
|
|
57
|
+
bucket = { key, label: bucketLabel(key, granularity), cost: 0, tokens: 0, byProvider: {} };
|
|
58
|
+
buckets.set(key, bucket);
|
|
59
|
+
}
|
|
60
|
+
bucket.cost += day.cost;
|
|
61
|
+
bucket.tokens += day.tokens;
|
|
62
|
+
for (const [provider, split] of Object.entries(day.providers)) {
|
|
63
|
+
const current = bucket.byProvider[provider] ?? { cost: 0, tokens: 0 };
|
|
64
|
+
current.cost += split.cost;
|
|
65
|
+
current.tokens += split.tokens;
|
|
66
|
+
bucket.byProvider[provider] = current;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return [...buckets.values()].sort((a, b) => compareDayKeys(a.key, b.key));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Flat series for the single-line chart. */
|
|
73
|
+
export function chartSeries(days: readonly UsageDayRow[], granularity: BucketGranularity): ChartSeriesPoint[] {
|
|
74
|
+
return bucketDays(days, granularity).map((bucket) => ({
|
|
75
|
+
label: bucket.label,
|
|
76
|
+
cost: bucket.cost,
|
|
77
|
+
tokens: bucket.tokens,
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** One row of the breakdown table. */
|
|
82
|
+
export interface BreakdownViewRow {
|
|
83
|
+
/** Stable key (provider slug, model id, day bucket, project path). */
|
|
84
|
+
key: string;
|
|
85
|
+
label: string;
|
|
86
|
+
/** Provider slug for the icon plate; absent on day rows. */
|
|
87
|
+
provider?: string;
|
|
88
|
+
/** Model id, when the row belongs to a provider subtree. */
|
|
89
|
+
model?: string;
|
|
90
|
+
/** `group` rows are provider headers in the two-level tree. */
|
|
91
|
+
kind: 'row' | 'group';
|
|
92
|
+
cost: number;
|
|
93
|
+
tokens: number;
|
|
94
|
+
records: number;
|
|
95
|
+
cacheHit: string;
|
|
96
|
+
/** Share of the period cost, 0..100. */
|
|
97
|
+
sharePercent: number;
|
|
98
|
+
/** Share of the parent provider's cost, for model rows under a group. */
|
|
99
|
+
shareOfParentPercent?: number;
|
|
100
|
+
depth: 0 | 1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function shareOf(part: number, whole: number): number {
|
|
104
|
+
return whole > 0 ? Math.round((part / whole) * 1000) / 10 : 0;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The Model tab's two-level tree: each provider, then its models.
|
|
109
|
+
*
|
|
110
|
+
* The provider row is what the panel was missing — `message.provider` was
|
|
111
|
+
* recorded on every usage entry, yet the breakdown keyed on model alone, so
|
|
112
|
+
* two accounts serving `deepseek-v4-1-flash` reported one merged cost
|
|
113
|
+
* ($1 673.86 measured) instead of $1 619.43 + $54.43.
|
|
114
|
+
*/
|
|
115
|
+
export function providerModelRows(providers: readonly UsageProviderRow[], totalCost: number): BreakdownViewRow[] {
|
|
116
|
+
const rows: BreakdownViewRow[] = [];
|
|
117
|
+
for (const provider of providers) {
|
|
118
|
+
rows.push({
|
|
119
|
+
key: `p:${provider.id}`,
|
|
120
|
+
label: provider.name,
|
|
121
|
+
provider: provider.id,
|
|
122
|
+
kind: 'group',
|
|
123
|
+
cost: provider.cost,
|
|
124
|
+
tokens: provider.tokens,
|
|
125
|
+
records: provider.records,
|
|
126
|
+
cacheHit: cacheHitLabel(provider),
|
|
127
|
+
sharePercent: shareOf(provider.cost, totalCost),
|
|
128
|
+
depth: 0,
|
|
129
|
+
});
|
|
130
|
+
for (const model of provider.models) {
|
|
131
|
+
rows.push({
|
|
132
|
+
key: `m:${provider.id}:${model.model}`,
|
|
133
|
+
label: model.model || 'unknown',
|
|
134
|
+
provider: provider.id,
|
|
135
|
+
model: model.model,
|
|
136
|
+
kind: 'row',
|
|
137
|
+
cost: model.cost,
|
|
138
|
+
tokens: model.tokens,
|
|
139
|
+
records: model.records,
|
|
140
|
+
cacheHit: cacheHitLabel(model),
|
|
141
|
+
sharePercent: shareOf(model.cost, totalCost),
|
|
142
|
+
shareOfParentPercent: shareOf(model.cost, provider.cost),
|
|
143
|
+
depth: 1,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return rows;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Time rows for the whole period, oldest first.
|
|
152
|
+
*
|
|
153
|
+
* `window` is the period's own day range: the payload only carries days that
|
|
154
|
+
* saw usage, so without it a quiet Tuesday simply vanished from the table and
|
|
155
|
+
* the list stopped matching the period it claims to describe. A bucket that
|
|
156
|
+
* never carried a record is listed with zeros rather than omitted.
|
|
157
|
+
*/
|
|
158
|
+
export function dayRows(
|
|
159
|
+
days: readonly UsageDayRow[],
|
|
160
|
+
granularity: BucketGranularity,
|
|
161
|
+
totalCost: number,
|
|
162
|
+
window: DayWindow | null,
|
|
163
|
+
): BreakdownViewRow[] {
|
|
164
|
+
const buckets = bucketDays(days, granularity);
|
|
165
|
+
// One pass collects the counters `bucketDays` does not carry (turns and the
|
|
166
|
+
// input split), so no bucket re-scans the day list.
|
|
167
|
+
const extra = new Map<string, { records: number; cacheRead: number; input: number }>();
|
|
168
|
+
for (const day of days) {
|
|
169
|
+
const key = bucketKey(day.day, granularity);
|
|
170
|
+
const current = extra.get(key) ?? { records: 0, cacheRead: 0, input: 0 };
|
|
171
|
+
current.records += day.records;
|
|
172
|
+
current.cacheRead += day.cacheRead;
|
|
173
|
+
current.input += day.input;
|
|
174
|
+
extra.set(key, current);
|
|
175
|
+
}
|
|
176
|
+
// Fill every bucket the window covers, so the table lists the period rather
|
|
177
|
+
// than only the days that happened to carry usage.
|
|
178
|
+
const known = new Set(buckets.map((bucket) => bucket.key));
|
|
179
|
+
for (const day of window ? daysInWindow(window) : []) {
|
|
180
|
+
const key = bucketKey(day, granularity);
|
|
181
|
+
if (known.has(key)) continue;
|
|
182
|
+
known.add(key);
|
|
183
|
+
buckets.push({ key, label: bucketLabel(key, granularity), cost: 0, tokens: 0, byProvider: {} });
|
|
184
|
+
}
|
|
185
|
+
return [...buckets]
|
|
186
|
+
.sort((a, b) => compareDayKeys(a.key, b.key))
|
|
187
|
+
.map((bucket) => {
|
|
188
|
+
const counts = extra.get(bucket.key) ?? { records: 0, cacheRead: 0, input: 0 };
|
|
189
|
+
return {
|
|
190
|
+
key: `d:${bucket.key}`,
|
|
191
|
+
label: bucket.label,
|
|
192
|
+
kind: 'row' as const,
|
|
193
|
+
cost: bucket.cost,
|
|
194
|
+
tokens: bucket.tokens,
|
|
195
|
+
records: counts.records,
|
|
196
|
+
cacheHit: cacheHitLabel(counts),
|
|
197
|
+
sharePercent: shareOf(bucket.cost, totalCost),
|
|
198
|
+
depth: 0 as const,
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Project rows, ordered by cost. */
|
|
204
|
+
export function projectRows(projects: readonly UsageProjectRow[], totalCost: number): BreakdownViewRow[] {
|
|
205
|
+
return [...projects]
|
|
206
|
+
.sort((a, b) => b.cost - a.cost)
|
|
207
|
+
.map((project) => ({
|
|
208
|
+
key: `j:${project.project}`,
|
|
209
|
+
label: project.project,
|
|
210
|
+
kind: 'row' as const,
|
|
211
|
+
cost: project.cost,
|
|
212
|
+
tokens: project.tokens,
|
|
213
|
+
records: project.records,
|
|
214
|
+
cacheHit: cacheHitLabel(project),
|
|
215
|
+
sharePercent: shareOf(project.cost, totalCost),
|
|
216
|
+
depth: 0 as const,
|
|
217
|
+
}));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** The rows the active tab shows, with the provider tab reusing the tree. */
|
|
221
|
+
export function breakdownRows(
|
|
222
|
+
tab: BreakdownTab,
|
|
223
|
+
payload: {
|
|
224
|
+
totals: UsageTotals;
|
|
225
|
+
providers: readonly UsageProviderRow[];
|
|
226
|
+
days: readonly UsageDayRow[];
|
|
227
|
+
projects: readonly UsageProjectRow[];
|
|
228
|
+
},
|
|
229
|
+
granularity: BucketGranularity,
|
|
230
|
+
window: DayWindow | null,
|
|
231
|
+
): BreakdownViewRow[] {
|
|
232
|
+
switch (tab) {
|
|
233
|
+
case 'provider':
|
|
234
|
+
case 'model':
|
|
235
|
+
return providerModelRows(payload.providers, payload.totals.cost);
|
|
236
|
+
case 'day':
|
|
237
|
+
return dayRows(payload.days, granularity, payload.totals.cost, window);
|
|
238
|
+
case 'project':
|
|
239
|
+
return projectRows(payload.projects, payload.totals.cost);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Day arithmetic for the Token Usage surface.
|
|
8
|
+
*
|
|
9
|
+
* The server decides which rows a period includes and the client buckets those
|
|
10
|
+
* days for the cadence switch, so both sides call THIS module. The cases worth
|
|
11
|
+
* pinning are the ones that made the panel disagree with itself: a UTC-derived
|
|
12
|
+
* day beside a local "Today", a week starting on Sunday, and "last 7 days"
|
|
13
|
+
* silently meaning 7 × 24 h instead of 7 calendar days.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, expect, test } from 'bun:test';
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
bucketKey,
|
|
20
|
+
bucketLabel,
|
|
21
|
+
compareDayKeys,
|
|
22
|
+
dayKeyOfTimestamp,
|
|
23
|
+
dayLabel,
|
|
24
|
+
dayRangeLabel,
|
|
25
|
+
dayWindow,
|
|
26
|
+
daysInWindow,
|
|
27
|
+
granularityFor,
|
|
28
|
+
localDayKey,
|
|
29
|
+
spanOfDays,
|
|
30
|
+
parseIsoDay,
|
|
31
|
+
timeRangeOptions,
|
|
32
|
+
} from '@/shared/lib/usage/range';
|
|
33
|
+
|
|
34
|
+
/** A local-time instant, so the cases read the same in every timezone. */
|
|
35
|
+
const at = (year: number, month: number, day: number, hour = 12) => new Date(year, month - 1, day, hour, 0, 0).getTime();
|
|
36
|
+
const NOW = at(2026, 11, 3);
|
|
37
|
+
|
|
38
|
+
describe('localDayKey', () => {
|
|
39
|
+
test('is the local calendar day, not the UTC prefix', () => {
|
|
40
|
+
// 00:30 local is the previous UTC day west of UTC and the same day east of
|
|
41
|
+
// it; the assertion that matters is that it equals the LOCAL date.
|
|
42
|
+
const instant = at(2026, 11, 3, 0);
|
|
43
|
+
expect(localDayKey(instant)).toBe('2026-11-03');
|
|
44
|
+
expect(localDayKey(at(2026, 11, 3, 23))).toBe('2026-11-03');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('an ISO timestamp with no timezone parses as local', () => {
|
|
48
|
+
expect(dayKeyOfTimestamp(new Date(2026, 10, 3, 1, 5).toISOString())).toBe('2026-11-03');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('a missing or unparseable timestamp yields an empty key', () => {
|
|
52
|
+
expect(dayKeyOfTimestamp(undefined)).toBe('');
|
|
53
|
+
expect(dayKeyOfTimestamp('')).toBe('');
|
|
54
|
+
expect(dayKeyOfTimestamp('not-a-date')).toBe('');
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('parseIsoDay', () => {
|
|
59
|
+
test('accepts real calendar days only', () => {
|
|
60
|
+
expect(parseIsoDay('2026-02-28')).toBe('2026-02-28');
|
|
61
|
+
expect(parseIsoDay('2026-02-30')).toBeNull();
|
|
62
|
+
expect(parseIsoDay('2026-13-01')).toBeNull();
|
|
63
|
+
expect(parseIsoDay('3/11/2026')).toBeNull();
|
|
64
|
+
expect(parseIsoDay('')).toBeNull();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('dayWindow', () => {
|
|
69
|
+
test('today is one local calendar day', () => {
|
|
70
|
+
expect(dayWindow('today', NOW)).toEqual({ from: '2026-11-03', to: '2026-11-03' });
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('last 7 days covers seven calendar days including today', () => {
|
|
74
|
+
expect(dayWindow('7d', NOW)).toEqual({ from: '2026-10-28', to: '2026-11-03' });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('last 30 and 90 days scale the same way', () => {
|
|
78
|
+
expect(dayWindow('30d', NOW)).toEqual({ from: '2026-10-05', to: '2026-11-03' });
|
|
79
|
+
expect(dayWindow('90d', NOW)?.from).toBe('2026-08-06');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('all time is unbounded', () => {
|
|
83
|
+
expect(dayWindow('all', NOW)).toBeNull();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('a valid custom pair is inclusive, and an invalid one falls back to 30d', () => {
|
|
87
|
+
expect(dayWindow('custom', NOW, { from: '2026-01-02', to: '2026-01-09' })).toEqual({
|
|
88
|
+
from: '2026-01-02',
|
|
89
|
+
to: '2026-01-09',
|
|
90
|
+
});
|
|
91
|
+
expect(dayWindow('custom', NOW, { from: '2026-01-09', to: '2026-01-02' })).toEqual({
|
|
92
|
+
from: '2026-10-05',
|
|
93
|
+
to: '2026-11-03',
|
|
94
|
+
});
|
|
95
|
+
expect(dayWindow('custom', NOW, { from: 'nope', to: '2026-01-02' })).toEqual({
|
|
96
|
+
from: '2026-10-05',
|
|
97
|
+
to: '2026-11-03',
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('labels', () => {
|
|
103
|
+
test('a day label is short and a single-day range names its year', () => {
|
|
104
|
+
expect(dayLabel('2026-11-03')).toBe('Nov 3');
|
|
105
|
+
expect(dayRangeLabel('2026-11-03', '2026-11-03', NOW)).toBe('Nov 3, 2026');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('a multi-day range prints both sides, omitting this year on the left', () => {
|
|
109
|
+
expect(dayRangeLabel('2026-10-05', '2026-11-03', NOW)).toBe('Oct 5 – Nov 3, 2026');
|
|
110
|
+
expect(dayRangeLabel('2025-12-01', '2026-01-02', NOW)).toBe('Dec 1, 2025 – Jan 2, 2026');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('the picker lists one period per span, each with the dates it covers', () => {
|
|
114
|
+
const options = timeRangeOptions(NOW);
|
|
115
|
+
expect(options.map((option) => option.id)).toEqual(['today', '7d', '30d', '90d', 'all', 'custom']);
|
|
116
|
+
// Day/Week/Month ARE the spans: there is no separate cadence control.
|
|
117
|
+
expect(options.map((option) => option.label)).toEqual(['Day', 'Week', 'Month', '90 days', 'All time', 'Custom…']);
|
|
118
|
+
expect(options[0].dateRange).toBe('Nov 3, 2026');
|
|
119
|
+
expect(options[1].dateRange).toBe('Oct 28 – Nov 3, 2026');
|
|
120
|
+
expect(options[2].dateRange).toBe('Oct 5 – Nov 3, 2026');
|
|
121
|
+
expect(options[4].dateRange).toBe('All time');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('daysInWindow', () => {
|
|
126
|
+
test('enumerates every calendar day of the span, oldest first', () => {
|
|
127
|
+
expect(daysInWindow({ from: '2026-10-28', to: '2026-11-03' })).toHaveLength(7);
|
|
128
|
+
expect(daysInWindow({ from: '2026-10-28', to: '2026-11-03' })[0]).toBe('2026-10-28');
|
|
129
|
+
expect(daysInWindow({ from: '2026-10-28', to: '2026-11-03' }).at(-1)).toBe('2026-11-03');
|
|
130
|
+
// One day, not zero and not two.
|
|
131
|
+
expect(daysInWindow({ from: '2026-11-03', to: '2026-11-03' })).toEqual(['2026-11-03']);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('a month crosses the month boundary without losing a day', () => {
|
|
135
|
+
const days = daysInWindow({ from: '2026-10-05', to: '2026-11-03' });
|
|
136
|
+
expect(days).toHaveLength(30);
|
|
137
|
+
expect(days).toContain('2026-10-31');
|
|
138
|
+
expect(days).toContain('2026-11-01');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('an inverted or unparseable window yields no days, and a cap bounds it', () => {
|
|
142
|
+
expect(daysInWindow({ from: '2026-11-03', to: '2026-10-01' })).toEqual([]);
|
|
143
|
+
expect(daysInWindow({ from: 'nope', to: '2026-11-03' })).toEqual([]);
|
|
144
|
+
expect(daysInWindow({ from: '2026-01-01', to: '2026-12-31' }, 10)).toHaveLength(10);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('spanOfDays', () => {
|
|
149
|
+
test('is the first and last recorded day, in either input order', () => {
|
|
150
|
+
expect(spanOfDays(['2026-11-03', '2026-06-24', '2026-09-01'])).toEqual({ from: '2026-06-24', to: '2026-11-03' });
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('empty and undated input yield no span', () => {
|
|
154
|
+
expect(spanOfDays([])).toBeNull();
|
|
155
|
+
expect(spanOfDays(['', ''])).toBeNull();
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe('granularityFor', () => {
|
|
160
|
+
test('follows the period length, so the chart stays readable', () => {
|
|
161
|
+
expect(granularityFor('today')).toBe('day');
|
|
162
|
+
expect(granularityFor('7d')).toBe('day');
|
|
163
|
+
expect(granularityFor('30d')).toBe('day');
|
|
164
|
+
expect(granularityFor('90d')).toBe('week');
|
|
165
|
+
expect(granularityFor('all')).toBe('month');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('a custom span picks its width from the span itself', () => {
|
|
169
|
+
expect(granularityFor('custom', { from: '2026-11-01', to: '2026-11-10' })).toBe('day');
|
|
170
|
+
expect(granularityFor('custom', { from: '2026-09-01', to: '2026-11-03' })).toBe('week');
|
|
171
|
+
expect(granularityFor('custom', { from: '2025-01-01', to: '2026-11-03' })).toBe('month');
|
|
172
|
+
// An incomplete custom pair is not a span yet.
|
|
173
|
+
expect(granularityFor('custom', { from: 'nope', to: '2026-11-03' })).toBe('day');
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe('bucketKey', () => {
|
|
178
|
+
test('day keeps the day', () => {
|
|
179
|
+
expect(bucketKey('2026-11-03', 'day')).toBe('2026-11-03');
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('week aligns to Monday', () => {
|
|
183
|
+
// 2026-11-03 is a Tuesday; its Monday is 2026-11-02.
|
|
184
|
+
expect(new Date(2026, 10, 3).getDay()).toBe(2);
|
|
185
|
+
expect(bucketKey('2026-11-03', 'week')).toBe('2026-11-02');
|
|
186
|
+
expect(bucketKey('2026-11-02', 'week')).toBe('2026-11-02');
|
|
187
|
+
// A Sunday belongs to the week that STARTED six days earlier.
|
|
188
|
+
expect(bucketKey('2026-11-08', 'week')).toBe('2026-11-02');
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('month keeps the year and month', () => {
|
|
192
|
+
expect(bucketKey('2026-11-03', 'month')).toBe('2026-11');
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('bucket labels follow the granularity', () => {
|
|
196
|
+
expect(bucketLabel('2026-11', 'month')).toBe('Nov');
|
|
197
|
+
expect(bucketLabel('2025-11', 'month')).toBe('Nov 2025');
|
|
198
|
+
expect(bucketLabel('2026-11-02', 'week')).toBe('Nov 2');
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test('day keys sort lexicographically', () => {
|
|
202
|
+
expect(['2026-11-03', '2026-10-05'].sort(compareDayKeys)).toEqual(['2026-10-05', '2026-11-03']);
|
|
203
|
+
});
|
|
204
|
+
});
|