@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,343 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The incremental scan behind the Token Usage panel.
|
|
8
|
+
*
|
|
9
|
+
* The panel's old cost model was "read the world, cache it for 60 seconds":
|
|
10
|
+
* 1 227 transcripts / 1 580 MB, measured 3.8–8.0 s cold, and every Kabmo
|
|
11
|
+
* restart or 60-second idle paid it again — inside the request that asked for
|
|
12
|
+
* the panel. This module replaces it with an on-disk index:
|
|
13
|
+
*
|
|
14
|
+
* - `usage_index_file` records how many bytes of each transcript are already
|
|
15
|
+
* folded, so an append costs a tail read instead of a whole-file parse;
|
|
16
|
+
* - `usage_rollup` holds the counters per (file, day, provider, model,
|
|
17
|
+
* project), which the payload query then `GROUP BY`s in milliseconds.
|
|
18
|
+
*
|
|
19
|
+
* A request never waits for a scan that is not the first: `ensureUsageIndex`
|
|
20
|
+
* answers with the current state and starts a background pass, and the client
|
|
21
|
+
* keeps showing the data it has (with a live "indexing…" line) until the next
|
|
22
|
+
* poll reports `ready`.
|
|
23
|
+
*
|
|
24
|
+
* Every file write is one transaction with a compare-and-swap on the row it
|
|
25
|
+
* read: a second Kabmo on another port indexing the same tree loses the swap
|
|
26
|
+
* rather than double-counting the same bytes.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import fs from 'node:fs';
|
|
30
|
+
import { join } from 'node:path';
|
|
31
|
+
|
|
32
|
+
import { getDb } from '@/server/db.server';
|
|
33
|
+
import type { DbClient } from '@/server/lib/db/client';
|
|
34
|
+
import { getSessionsDir } from '@/server/lib/omp/core/paths';
|
|
35
|
+
import { completeLineOffset, foldUsageText, type UsageRollupRow } from '@/server/lib/usage/index-parse';
|
|
36
|
+
import type { UsageIndexState } from '@/shared/types';
|
|
37
|
+
|
|
38
|
+
/** Re-check the tree at most this often; the walk is a stat pass (~200 ms). */
|
|
39
|
+
const INDEX_TTL_MS = 20_000;
|
|
40
|
+
/** A transcript larger than this is not a session we can fold cheaply. */
|
|
41
|
+
const MAX_TRANSCRIPT_BYTES = 64 * 1024 * 1024;
|
|
42
|
+
/** Yield to the event loop this often while scanning. */
|
|
43
|
+
const YIELD_EVERY = 20;
|
|
44
|
+
|
|
45
|
+
interface IndexHost {
|
|
46
|
+
inFlight: Promise<void> | null;
|
|
47
|
+
lastCheck: number;
|
|
48
|
+
state: UsageIndexState;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const globalKey = '__kabmoUsageIndex';
|
|
52
|
+
|
|
53
|
+
function host(): IndexHost {
|
|
54
|
+
const slot = globalThis as typeof globalThis & { [globalKey]?: IndexHost };
|
|
55
|
+
slot[globalKey] ??= {
|
|
56
|
+
inFlight: null,
|
|
57
|
+
lastCheck: 0,
|
|
58
|
+
state: { state: 'ready', transcripts: 0, records: 0, indexedAt: 0, scanMs: 0 },
|
|
59
|
+
};
|
|
60
|
+
return slot[globalKey];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface FileStateRow {
|
|
64
|
+
session_file: string;
|
|
65
|
+
offset: number;
|
|
66
|
+
size: number;
|
|
67
|
+
mtime_ms: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface ScannedFile {
|
|
71
|
+
path: string;
|
|
72
|
+
project: string;
|
|
73
|
+
size: number;
|
|
74
|
+
mtimeMs: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Every transcript under the sessions root, with the project folder it lives in. */
|
|
78
|
+
async function listTranscripts(root: string): Promise<ScannedFile[]> {
|
|
79
|
+
const out: ScannedFile[] = [];
|
|
80
|
+
let entries: fs.Dirent[];
|
|
81
|
+
try {
|
|
82
|
+
entries = await fs.promises.readdir(root, { withFileTypes: true });
|
|
83
|
+
} catch {
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
for (const entry of entries) {
|
|
87
|
+
const projectPath = join(root, entry.name);
|
|
88
|
+
if (entry.isFile()) {
|
|
89
|
+
// A transcript written directly under the sessions root still belongs to
|
|
90
|
+
// a project: its own name is the only one it has.
|
|
91
|
+
if (!entry.name.endsWith('.jsonl')) continue;
|
|
92
|
+
const stat = await safeStat(projectPath);
|
|
93
|
+
if (stat) out.push({ path: projectPath, project: entry.name, ...stat });
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (!entry.isDirectory()) continue;
|
|
97
|
+
let names: string[];
|
|
98
|
+
try {
|
|
99
|
+
names = await fs.promises.readdir(projectPath);
|
|
100
|
+
} catch {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
for (const name of names) {
|
|
104
|
+
if (!name.endsWith('.jsonl')) continue;
|
|
105
|
+
const path = join(projectPath, name);
|
|
106
|
+
const stat = await safeStat(path);
|
|
107
|
+
if (stat) out.push({ path, project: entry.name, ...stat });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function safeStat(path: string): Promise<{ size: number; mtimeMs: number } | null> {
|
|
114
|
+
try {
|
|
115
|
+
const stat = await fs.promises.stat(path);
|
|
116
|
+
return stat.isFile() ? { size: stat.size, mtimeMs: stat.mtimeMs } : null;
|
|
117
|
+
} catch {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const ROLLUP_COLUMNS = [
|
|
123
|
+
'session_file', 'day', 'provider', 'model', 'project', 'records', 'unpriced',
|
|
124
|
+
'input', 'output', 'cache_read', 'cache_write', 'reasoning', 'total',
|
|
125
|
+
'cost_total', 'cost_input', 'cost_output', 'cost_cache_read', 'cost_cache_write',
|
|
126
|
+
] as const;
|
|
127
|
+
|
|
128
|
+
const INSERT_SET = ROLLUP_COLUMNS.slice(5).map((column) => `${column} = ${column} + excluded.${column}`).join(', ');
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Write one file's contribution.
|
|
132
|
+
*
|
|
133
|
+
* `append` accumulates onto the rows already stored for that file (a tail read
|
|
134
|
+
* holds only NEW entries); a full read replaces them, which is also how a
|
|
135
|
+
* truncated or rewritten transcript stops contributing its old numbers.
|
|
136
|
+
*
|
|
137
|
+
* Returns false when another writer won the swap — the caller then leaves the
|
|
138
|
+
* file alone rather than folding the same bytes twice.
|
|
139
|
+
*/
|
|
140
|
+
async function commitFile(
|
|
141
|
+
file: ScannedFile,
|
|
142
|
+
rows: Map<string, UsageRollupRow>,
|
|
143
|
+
previous: FileStateRow | null,
|
|
144
|
+
nextOffset: number,
|
|
145
|
+
append: boolean,
|
|
146
|
+
): Promise<boolean> {
|
|
147
|
+
const db = await getDb();
|
|
148
|
+
const values = [...rows.values()];
|
|
149
|
+
const insertSql = append
|
|
150
|
+
? `INSERT INTO usage_rollup (${ROLLUP_COLUMNS.join(', ')}) VALUES (${ROLLUP_COLUMNS.map(() => '?').join(', ')})
|
|
151
|
+
ON CONFLICT(session_file, day, provider, model, project) DO UPDATE SET ${INSERT_SET}`
|
|
152
|
+
: `INSERT OR REPLACE INTO usage_rollup (${ROLLUP_COLUMNS.join(', ')}) VALUES (${ROLLUP_COLUMNS.map(() => '?').join(', ')})`;
|
|
153
|
+
|
|
154
|
+
return db.raw.transaction(() => {
|
|
155
|
+
let claimed: number;
|
|
156
|
+
if (previous) {
|
|
157
|
+
const claim = db.raw.query(
|
|
158
|
+
'UPDATE usage_index_file SET offset = ?, size = ?, mtime_ms = ?, indexed_at = ? WHERE session_file = ? AND offset = ? AND size = ?',
|
|
159
|
+
).run(nextOffset, file.size, file.mtimeMs, Date.now(), file.path, previous.offset, previous.size);
|
|
160
|
+
claimed = claim.changes;
|
|
161
|
+
} else {
|
|
162
|
+
const claim = db.raw.query(
|
|
163
|
+
'INSERT INTO usage_index_file (session_file, offset, size, mtime_ms, indexed_at) VALUES (?, ?, ?, ?, ?) ON CONFLICT(session_file) DO NOTHING',
|
|
164
|
+
).run(file.path, nextOffset, file.size, file.mtimeMs, Date.now());
|
|
165
|
+
claimed = claim.changes;
|
|
166
|
+
}
|
|
167
|
+
if (claimed === 0) return false;
|
|
168
|
+
if (!append) db.raw.query('DELETE FROM usage_rollup WHERE session_file = ?').run(file.path);
|
|
169
|
+
const insert = db.raw.query(insertSql);
|
|
170
|
+
for (const row of values) {
|
|
171
|
+
insert.run(
|
|
172
|
+
file.path, row.day, row.provider, row.model, file.project, row.records, row.unpriced,
|
|
173
|
+
row.input, row.output, row.cacheRead, row.cacheWrite, row.reasoning, row.total,
|
|
174
|
+
row.costTotal, row.costInput, row.costOutput, row.costCacheRead, row.costCacheWrite,
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
return true;
|
|
178
|
+
})();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Fold one transcript, reading only what has been appended since the last pass. */
|
|
182
|
+
async function indexFile(file: ScannedFile, previous: FileStateRow | null): Promise<'skipped' | 'full' | 'append' | 'lost'> {
|
|
183
|
+
const rows = new Map<string, UsageRollupRow>();
|
|
184
|
+
|
|
185
|
+
if (file.size > MAX_TRANSCRIPT_BYTES) return 'skipped';
|
|
186
|
+
|
|
187
|
+
// Unchanged: nothing to read. mtime is part of the key because a file can be
|
|
188
|
+
// rewritten with the same length (a rotated session, an in-place repair).
|
|
189
|
+
if (previous && previous.size === file.size && previous.mtime_ms === file.mtimeMs) return 'skipped';
|
|
190
|
+
|
|
191
|
+
let text: string;
|
|
192
|
+
let append = false;
|
|
193
|
+
let baseOffset = 0;
|
|
194
|
+
// A tail read is only safe once the index has seen the WHOLE file: a row
|
|
195
|
+
// written by an older build may have counted a file the old way, and adding
|
|
196
|
+
// to it would mix two attributions. Starting from 0 also means a truncated
|
|
197
|
+
// or rewritten transcript is rebuilt rather than patched.
|
|
198
|
+
const canAppend = previous !== null && previous.offset > 0 && previous.size === previous.offset;
|
|
199
|
+
try {
|
|
200
|
+
if (previous && canAppend && file.size > previous.size) {
|
|
201
|
+
// Only the appended bytes: the tick between two scans is usually a few
|
|
202
|
+
// lines, not the 11 MB the whole file would cost.
|
|
203
|
+
text = await Bun.file(file.path).slice(previous.size, file.size).text();
|
|
204
|
+
baseOffset = previous.size;
|
|
205
|
+
append = true;
|
|
206
|
+
} else {
|
|
207
|
+
text = await Bun.file(file.path).text();
|
|
208
|
+
}
|
|
209
|
+
} catch {
|
|
210
|
+
return 'skipped';
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// A tail read can stop mid-line; keep only whole lines so the next pass
|
|
214
|
+
// resumes at a boundary instead of re-parsing half an entry.
|
|
215
|
+
foldUsageText(rows, file.project, text, append);
|
|
216
|
+
const nextOffset = baseOffset + completeLineOffset(text);
|
|
217
|
+
|
|
218
|
+
const won = await commitFile(file, rows, previous, nextOffset, append);
|
|
219
|
+
if (!won) return 'lost';
|
|
220
|
+
return append ? 'append' : 'full';
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** One full pass over the tree. Returns the state it leaves behind. */
|
|
224
|
+
async function scanOnce(): Promise<UsageIndexState> {
|
|
225
|
+
const startedAt = Date.now();
|
|
226
|
+
const db = await getDb();
|
|
227
|
+
const existing = await db.all<FileStateRow>('SELECT session_file, offset, size, mtime_ms FROM usage_index_file');
|
|
228
|
+
const known = new Map(existing.map((row) => [row.session_file, row]));
|
|
229
|
+
|
|
230
|
+
let failed: string | undefined;
|
|
231
|
+
let visited = 0;
|
|
232
|
+
try {
|
|
233
|
+
const transcripts = await listTranscripts(getSessionsDir());
|
|
234
|
+
// A removed or pruned session must stop contributing: its rollup rows
|
|
235
|
+
// would otherwise keep costing money on a panel that no longer has the
|
|
236
|
+
// transcript they came from.
|
|
237
|
+
const present = new Set(transcripts.map((file) => file.path));
|
|
238
|
+
for (const stale of [...known.keys()]) {
|
|
239
|
+
if (present.has(stale)) continue;
|
|
240
|
+
await db.raw.query('DELETE FROM usage_rollup WHERE session_file = ?').run(stale);
|
|
241
|
+
await db.raw.query('DELETE FROM usage_index_file WHERE session_file = ?').run(stale);
|
|
242
|
+
}
|
|
243
|
+
for (const file of transcripts) {
|
|
244
|
+
visited++;
|
|
245
|
+
try {
|
|
246
|
+
await indexFile(file, known.get(file.path) ?? null);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
// One unreadable transcript must not fail the report; the index keeps
|
|
249
|
+
// whatever it already had for it.
|
|
250
|
+
failed ??= error instanceof Error ? error.message : String(error);
|
|
251
|
+
}
|
|
252
|
+
if (visited % YIELD_EVERY === 0) await Bun.sleep(0);
|
|
253
|
+
}
|
|
254
|
+
} catch (error) {
|
|
255
|
+
failed = error instanceof Error ? error.message : String(error);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const totals = await db.get<{ records: number | null; transcripts: number }>(
|
|
259
|
+
'SELECT (SELECT SUM(records) FROM usage_rollup) AS records, (SELECT COUNT(*) FROM usage_index_file) AS transcripts',
|
|
260
|
+
);
|
|
261
|
+
const state: UsageIndexState = {
|
|
262
|
+
state: failed ? 'failed' : 'ready',
|
|
263
|
+
transcripts: totals?.transcripts ?? 0,
|
|
264
|
+
records: totals?.records ?? 0,
|
|
265
|
+
indexedAt: Date.now(),
|
|
266
|
+
scanMs: Date.now() - startedAt,
|
|
267
|
+
...(failed ? { error: failed } : {}),
|
|
268
|
+
};
|
|
269
|
+
host().state = state;
|
|
270
|
+
return state;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Bring the index up to date as far as this request is allowed to.
|
|
275
|
+
*
|
|
276
|
+
* The FIRST request waits (there is no data to draw yet). Every later one
|
|
277
|
+
* starts a background pass and answers immediately — the panel polls while
|
|
278
|
+
* `state` is `building`, so a slow disk shows progress instead of a spinner.
|
|
279
|
+
*/
|
|
280
|
+
export async function ensureUsageIndex(options: { wait?: boolean; force?: boolean } = {}): Promise<UsageIndexState> {
|
|
281
|
+
const state = host();
|
|
282
|
+
const db = await getDb();
|
|
283
|
+
const meta = await db.get<{ value: string }>('SELECT value FROM usage_index_meta WHERE key = ?', ['indexed_at']);
|
|
284
|
+
const lastIndexedAt = meta ? Number(meta.value) : 0;
|
|
285
|
+
|
|
286
|
+
// A fresh process starts with no in-memory counters, while the index on disk
|
|
287
|
+
// may be complete. Hydrate before answering, or the first request after a
|
|
288
|
+
// restart would report "0 transcripts" beside a fully populated table.
|
|
289
|
+
if (state.state.indexedAt === 0 && lastIndexedAt > 0) {
|
|
290
|
+
const counts = await readCounts(db);
|
|
291
|
+
const scanMs = await db.get<{ value: string }>('SELECT value FROM usage_index_meta WHERE key = ?', ['scan_ms']);
|
|
292
|
+
state.state = {
|
|
293
|
+
state: 'ready',
|
|
294
|
+
...counts,
|
|
295
|
+
indexedAt: lastIndexedAt,
|
|
296
|
+
scanMs: Number(scanMs?.value ?? 0),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (state.inFlight) return options.wait ? await settle(state) : state.state;
|
|
301
|
+
// `force` is the user's own Refresh: it accepts the stat pass now rather
|
|
302
|
+
// than waiting out the TTL.
|
|
303
|
+
if (!options.force && lastIndexedAt > 0 && Date.now() - state.lastCheck < INDEX_TTL_MS) return state.state;
|
|
304
|
+
|
|
305
|
+
state.lastCheck = Date.now();
|
|
306
|
+
const run = scanOnce()
|
|
307
|
+
.catch((error: unknown) => {
|
|
308
|
+
state.state = {
|
|
309
|
+
...state.state,
|
|
310
|
+
state: 'failed',
|
|
311
|
+
error: error instanceof Error ? error.message : String(error),
|
|
312
|
+
};
|
|
313
|
+
return state.state;
|
|
314
|
+
})
|
|
315
|
+
.then(async (result) => {
|
|
316
|
+
const handle = await getDb();
|
|
317
|
+
await handle.run('INSERT OR REPLACE INTO usage_index_meta (key, value) VALUES (?, ?)', ['indexed_at', String(result.indexedAt)]);
|
|
318
|
+
await handle.run('INSERT OR REPLACE INTO usage_index_meta (key, value) VALUES (?, ?)', ['scan_ms', String(result.scanMs)]);
|
|
319
|
+
state.inFlight = null;
|
|
320
|
+
});
|
|
321
|
+
state.inFlight = run;
|
|
322
|
+
state.state = { ...state.state, state: 'building' };
|
|
323
|
+
|
|
324
|
+
if (lastIndexedAt === 0 || options.wait) return await settle(state);
|
|
325
|
+
return state.state;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
async function readCounts(db: DbClient): Promise<{ transcripts: number; records: number }> {
|
|
329
|
+
const totals = await db.get<{ records: number | null; transcripts: number }>(
|
|
330
|
+
'SELECT (SELECT SUM(records) FROM usage_rollup) AS records, (SELECT COUNT(*) FROM usage_index_file) AS transcripts',
|
|
331
|
+
);
|
|
332
|
+
return { transcripts: totals?.transcripts ?? 0, records: totals?.records ?? 0 };
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
async function settle(state: IndexHost): Promise<UsageIndexState> {
|
|
336
|
+
await state.inFlight;
|
|
337
|
+
return state.state;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** The index's current state without touching the disk. */
|
|
341
|
+
export function currentUsageIndexState(): UsageIndexState {
|
|
342
|
+
return host().state;
|
|
343
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The Token Usage index's own tables.
|
|
8
|
+
*
|
|
9
|
+
* The panel used to re-read the whole sessions tree (measured: 1 227 files /
|
|
10
|
+
* 1 580 MB, 3.8–8.0 s) because its only cache was a 60-second in-memory scan.
|
|
11
|
+
* Two tables replace that: `usage_rollup` holds counters per
|
|
12
|
+
* (file, day, provider, model, project) — small enough to `GROUP BY` in
|
|
13
|
+
* milliseconds — and `usage_index_file` holds how far each transcript has been
|
|
14
|
+
* read, so the next pass reads only the bytes appended since.
|
|
15
|
+
*
|
|
16
|
+
* The unit of a rollup row is a FILE's contribution to one day, not one
|
|
17
|
+
* message: a resumed session can add 40 000 entries for the same day, and one
|
|
18
|
+
* row per message would make the index larger than the thing it indexes.
|
|
19
|
+
* Re-indexing a file therefore REPLACES its rows (delete-then-insert), which
|
|
20
|
+
* also makes a truncated or rewritten transcript correct rather than
|
|
21
|
+
* double-counted.
|
|
22
|
+
*
|
|
23
|
+
* `day` is `''` (not NULL) for a record with no usable timestamp: SQLite
|
|
24
|
+
* treats NULLs as distinct in a primary key, so two undated contributions
|
|
25
|
+
* would both insert instead of accumulating, and every scan would grow the
|
|
26
|
+
* table. An empty string sorts and groups as one bucket, which is also how the
|
|
27
|
+
* window filters keep such records in EVERY period.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import type { DbClient } from '@/server/lib/db/client';
|
|
31
|
+
|
|
32
|
+
/** Bumped when a rollup row's meaning changes; the index is dropped and rebuilt. */
|
|
33
|
+
export const USAGE_INDEX_VERSION = 1;
|
|
34
|
+
|
|
35
|
+
const USAGE_INDEX_SCHEMA_SQL = `
|
|
36
|
+
CREATE TABLE IF NOT EXISTS usage_rollup (
|
|
37
|
+
session_file TEXT NOT NULL,
|
|
38
|
+
day TEXT NOT NULL,
|
|
39
|
+
provider TEXT NOT NULL,
|
|
40
|
+
model TEXT NOT NULL,
|
|
41
|
+
project TEXT NOT NULL,
|
|
42
|
+
records INTEGER NOT NULL,
|
|
43
|
+
unpriced INTEGER NOT NULL,
|
|
44
|
+
input INTEGER NOT NULL,
|
|
45
|
+
output INTEGER NOT NULL,
|
|
46
|
+
cache_read INTEGER NOT NULL,
|
|
47
|
+
cache_write INTEGER NOT NULL,
|
|
48
|
+
reasoning INTEGER NOT NULL,
|
|
49
|
+
total INTEGER NOT NULL,
|
|
50
|
+
cost_total REAL NOT NULL,
|
|
51
|
+
cost_input REAL NOT NULL,
|
|
52
|
+
cost_output REAL NOT NULL,
|
|
53
|
+
cost_cache_read REAL NOT NULL,
|
|
54
|
+
cost_cache_write REAL NOT NULL,
|
|
55
|
+
PRIMARY KEY (session_file, day, provider, model, project)
|
|
56
|
+
);
|
|
57
|
+
CREATE INDEX IF NOT EXISTS idx_usage_rollup_day ON usage_rollup (day);
|
|
58
|
+
|
|
59
|
+
CREATE TABLE IF NOT EXISTS usage_index_file (
|
|
60
|
+
session_file TEXT PRIMARY KEY,
|
|
61
|
+
offset INTEGER NOT NULL,
|
|
62
|
+
size INTEGER NOT NULL,
|
|
63
|
+
mtime_ms REAL NOT NULL,
|
|
64
|
+
indexed_at INTEGER NOT NULL
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
CREATE TABLE IF NOT EXISTS usage_index_meta (
|
|
68
|
+
key TEXT PRIMARY KEY,
|
|
69
|
+
value TEXT NOT NULL
|
|
70
|
+
);
|
|
71
|
+
`;
|
|
72
|
+
|
|
73
|
+
/** Idempotent: the usage index's tables, created on every database open. */
|
|
74
|
+
export async function ensureUsageIndexSchema(db: DbClient): Promise<void> {
|
|
75
|
+
await db.exec(USAGE_INDEX_SCHEMA_SQL);
|
|
76
|
+
const row = await db.get<{ value: string }>('SELECT value FROM usage_index_meta WHERE key = ?', ['version']);
|
|
77
|
+
if (row?.value === String(USAGE_INDEX_VERSION)) return;
|
|
78
|
+
// A different row meaning cannot be reinterpreted: drop the derived data and
|
|
79
|
+
// let the next scan rebuild it. Never a silent misread.
|
|
80
|
+
await db.exec('DELETE FROM usage_rollup; DELETE FROM usage_index_file;');
|
|
81
|
+
await db.run('INSERT OR REPLACE INTO usage_index_meta (key, value) VALUES (?, ?)', ['version', String(USAGE_INDEX_VERSION)]);
|
|
82
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The Token Usage index end to end: an incremental scan over a real (temp)
|
|
8
|
+
* sessions tree, and the payload arithmetic that used to run per request.
|
|
9
|
+
*
|
|
10
|
+
* The cases that matter are the ones a wrong index would silently corrupt:
|
|
11
|
+
*
|
|
12
|
+
* - re-indexing an unchanged file must add NOTHING (a double-counted append is
|
|
13
|
+
* a doubled bill);
|
|
14
|
+
* - a truncated or rewritten transcript must REPLACE its contribution;
|
|
15
|
+
* - a removed transcript must stop contributing;
|
|
16
|
+
* - an undated record counts in every window;
|
|
17
|
+
* - two accounts serving one model id stay two rows.
|
|
18
|
+
*
|
|
19
|
+
* The line-level rules live in `index-parse.test.ts`. The DB is a temp file via
|
|
20
|
+
* `isolateDb` and the sessions root a temp tree, so nothing here can reach the
|
|
21
|
+
* developer's real `~/.kabmo` or `~/.omp`.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
|
25
|
+
import fs from 'node:fs';
|
|
26
|
+
import os from 'node:os';
|
|
27
|
+
import path from 'node:path';
|
|
28
|
+
|
|
29
|
+
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
30
|
+
import { removeDir } from '@/test-support/remove-dir';
|
|
31
|
+
import { getDb } from '@/server/db.server';
|
|
32
|
+
import { buildTokenUsagePayload } from '@/server/lib/usage/index-query.server';
|
|
33
|
+
|
|
34
|
+
const dirs: string[] = [];
|
|
35
|
+
let savedAgentDir: string | undefined;
|
|
36
|
+
let sessionsRoot = '';
|
|
37
|
+
|
|
38
|
+
function tempDir(): string {
|
|
39
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kabmo-usage-'));
|
|
40
|
+
dirs.push(dir);
|
|
41
|
+
return dir;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
beforeAll(async () => {
|
|
45
|
+
await isolateDb();
|
|
46
|
+
savedAgentDir = Bun.env.PI_CODING_AGENT_DIR;
|
|
47
|
+
const agent = path.join(tempDir(), 'agent');
|
|
48
|
+
Bun.env.PI_CODING_AGENT_DIR = agent;
|
|
49
|
+
sessionsRoot = path.join(agent, 'sessions');
|
|
50
|
+
fs.mkdirSync(sessionsRoot, { recursive: true });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
afterAll(async () => {
|
|
54
|
+
if (savedAgentDir === undefined) delete Bun.env.PI_CODING_AGENT_DIR;
|
|
55
|
+
else Bun.env.PI_CODING_AGENT_DIR = savedAgentDir;
|
|
56
|
+
await releaseDb();
|
|
57
|
+
for (const dir of dirs.splice(0)) removeDir(dir);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
function messageLine(options: {
|
|
61
|
+
timestamp?: string;
|
|
62
|
+
provider?: string;
|
|
63
|
+
model?: string;
|
|
64
|
+
usage?: Record<string, unknown>;
|
|
65
|
+
}): string {
|
|
66
|
+
return JSON.stringify({
|
|
67
|
+
type: 'message',
|
|
68
|
+
timestamp: options.timestamp,
|
|
69
|
+
message: {
|
|
70
|
+
role: 'assistant',
|
|
71
|
+
provider: options.provider,
|
|
72
|
+
model: options.model,
|
|
73
|
+
usage: options.usage ?? {},
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function writeTranscript(file: string, lines: string[], project = 'proj'): string {
|
|
79
|
+
const target = path.join(sessionsRoot, project, file);
|
|
80
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
81
|
+
fs.writeFileSync(target, lines.join('\n') + '\n');
|
|
82
|
+
return target;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function appendTo(target: string, lines: string[]): void {
|
|
86
|
+
fs.appendFileSync(target, lines.join('\n') + '\n');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function costed(options: {
|
|
90
|
+
timestamp: string;
|
|
91
|
+
provider: string;
|
|
92
|
+
model: string;
|
|
93
|
+
input: number;
|
|
94
|
+
output: number;
|
|
95
|
+
cacheRead: number;
|
|
96
|
+
cost: number;
|
|
97
|
+
}): string {
|
|
98
|
+
return messageLine({
|
|
99
|
+
timestamp: options.timestamp,
|
|
100
|
+
provider: options.provider,
|
|
101
|
+
model: options.model,
|
|
102
|
+
usage: {
|
|
103
|
+
input: options.input,
|
|
104
|
+
output: options.output,
|
|
105
|
+
cacheRead: options.cacheRead,
|
|
106
|
+
cacheWrite: 0,
|
|
107
|
+
totalTokens: options.input + options.output + options.cacheRead,
|
|
108
|
+
cost: { total: options.cost, input: options.cost / 2, output: options.cost / 4, cacheRead: options.cost / 4, cacheWrite: 0 },
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
describe('buildTokenUsagePayload', () => {
|
|
114
|
+
const NOW = new Date(2026, 10, 3, 12, 0, 0).getTime();
|
|
115
|
+
|
|
116
|
+
beforeAll(async () => {
|
|
117
|
+
for (const entry of fs.readdirSync(sessionsRoot)) {
|
|
118
|
+
removeDir(path.join(sessionsRoot, entry));
|
|
119
|
+
}
|
|
120
|
+
const db = await getDb();
|
|
121
|
+
await db.exec('DELETE FROM usage_rollup; DELETE FROM usage_index_file; DELETE FROM usage_index_meta;');
|
|
122
|
+
|
|
123
|
+
writeTranscript('a.jsonl', [
|
|
124
|
+
costed({ timestamp: new Date(2026, 9, 10, 10, 0, 0).toISOString(), provider: 'kenari-jatis', model: 'deepseek-v4-1-flash', input: 100, output: 50, cacheRead: 1000, cost: 9 }),
|
|
125
|
+
costed({ timestamp: new Date(2026, 9, 10, 11, 0, 0).toISOString(), provider: 'kenari-jatis', model: 'deepseek-v4-1-flash', input: 100, output: 50, cacheRead: 1000, cost: 9 }),
|
|
126
|
+
costed({ timestamp: new Date(2026, 9, 20, 9, 0, 0).toISOString(), provider: 'kenari', model: 'deepseek-v4-1-flash', input: 10, output: 5, cacheRead: 100, cost: 1 }),
|
|
127
|
+
]);
|
|
128
|
+
writeTranscript('b.jsonl', [
|
|
129
|
+
costed({ timestamp: new Date(2026, 10, 2, 9, 0, 0).toISOString(), provider: 'deepseek', model: 'deepseek-flash', input: 4, output: 2, cacheRead: 40, cost: 0.5 }),
|
|
130
|
+
], 'other');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('splits one model across the providers that served it', async () => {
|
|
134
|
+
const payload = await buildTokenUsagePayload({ range: '30d', now: NOW, wait: true });
|
|
135
|
+
const kenariJatis = payload.providers.find((provider) => provider.id === 'kenari-jatis');
|
|
136
|
+
const kenari = payload.providers.find((provider) => provider.id === 'kenari');
|
|
137
|
+
expect(kenariJatis?.cost).toBeCloseTo(18, 10);
|
|
138
|
+
expect(kenariJatis?.records).toBe(2);
|
|
139
|
+
expect(kenari?.cost).toBeCloseTo(1, 10);
|
|
140
|
+
// Both report the same model id under their own provider.
|
|
141
|
+
expect(kenariJatis?.models.map((model) => model.model)).toEqual(['deepseek-v4-1-flash']);
|
|
142
|
+
expect(kenari?.models.map((model) => model.model)).toEqual(['deepseek-v4-1-flash']);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('totals, active days and the period label describe the window', async () => {
|
|
146
|
+
const payload = await buildTokenUsagePayload({ range: '30d', now: NOW, wait: true });
|
|
147
|
+
expect(payload.totals.cost).toBeCloseTo(19.5, 10);
|
|
148
|
+
expect(payload.totals.records).toBe(4);
|
|
149
|
+
expect(payload.totals.activeDays).toBe(3);
|
|
150
|
+
expect(payload.periodLabel).toBe('Oct 5 – Nov 3, 2026');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('a narrower window drops the older records but keeps the same shape', async () => {
|
|
154
|
+
const payload = await buildTokenUsagePayload({ range: '7d', now: NOW, wait: true });
|
|
155
|
+
expect(payload.totals.records).toBe(1);
|
|
156
|
+
expect(payload.providers.map((provider) => provider.id)).toEqual(['deepseek']);
|
|
157
|
+
expect(payload.days.map((day) => day.day)).toEqual(['2026-11-02']);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('the provider-split days carry the cost the stacked chart draws', async () => {
|
|
161
|
+
const payload = await buildTokenUsagePayload({ range: '30d', now: NOW, wait: true });
|
|
162
|
+
const day = payload.days.find((row) => row.day === '2026-10-10');
|
|
163
|
+
expect(day?.cost).toBeCloseTo(18, 10);
|
|
164
|
+
expect(day?.providers['kenari-jatis']?.cost).toBeCloseTo(18, 10);
|
|
165
|
+
expect(Object.keys(day?.providers ?? {})).toEqual(['kenari-jatis']);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('projects are attributed to the sessions folder the transcript lives in', async () => {
|
|
169
|
+
const payload = await buildTokenUsagePayload({ range: '30d', now: NOW, wait: true });
|
|
170
|
+
expect(payload.projects.map((row) => row.project).sort()).toEqual(['other', 'proj']);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('an append is indexed without re-reading the whole file', async () => {
|
|
174
|
+
const target = path.join(sessionsRoot, 'proj', 'a.jsonl');
|
|
175
|
+
appendTo(target, [
|
|
176
|
+
costed({ timestamp: new Date(2026, 10, 3, 9, 0, 0).toISOString(), provider: 'kenari-jatis', model: 'deepseek-v4-1-flash', input: 1, output: 1, cacheRead: 1, cost: 0.25 }),
|
|
177
|
+
]);
|
|
178
|
+
const payload = await buildTokenUsagePayload({ range: '30d', now: NOW, wait: true, force: true });
|
|
179
|
+
const provider = payload.providers.find((row) => row.id === 'kenari-jatis');
|
|
180
|
+
expect(provider?.records).toBe(3);
|
|
181
|
+
expect(provider?.cost).toBeCloseTo(18.25, 10);
|
|
182
|
+
|
|
183
|
+
// Unchanged files add nothing on the next pass.
|
|
184
|
+
const again = await buildTokenUsagePayload({ range: '30d', now: NOW, wait: true });
|
|
185
|
+
expect(again.providers.find((row) => row.id === 'kenari-jatis')?.records).toBe(3);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('a truncated transcript replaces its contribution instead of double-counting', async () => {
|
|
189
|
+
const target = writeTranscript('c.jsonl', [
|
|
190
|
+
costed({ timestamp: new Date(2026, 10, 1, 8, 0, 0).toISOString(), provider: 'sumopod', model: 'netra', input: 5, output: 5, cacheRead: 5, cost: 2 }),
|
|
191
|
+
costed({ timestamp: new Date(2026, 10, 1, 9, 0, 0).toISOString(), provider: 'sumopod', model: 'netra', input: 5, output: 5, cacheRead: 5, cost: 2 }),
|
|
192
|
+
]);
|
|
193
|
+
const before = await buildTokenUsagePayload({ range: '30d', now: NOW, wait: true, force: true });
|
|
194
|
+
expect(before.providers.find((row) => row.id === 'sumopod')?.cost).toBeCloseTo(4, 10);
|
|
195
|
+
|
|
196
|
+
// Rewrite with one entry: the old two must not linger.
|
|
197
|
+
fs.writeFileSync(target, `${costed({ timestamp: new Date(2026, 10, 1, 8, 0, 0).toISOString(), provider: 'sumopod', model: 'netra', input: 5, output: 5, cacheRead: 5, cost: 2 })}\n`);
|
|
198
|
+
const after = await buildTokenUsagePayload({ range: '30d', now: NOW, wait: true, force: true });
|
|
199
|
+
expect(after.providers.find((row) => row.id === 'sumopod')?.cost).toBeCloseTo(2, 10);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('a removed transcript stops contributing', async () => {
|
|
203
|
+
const before = await buildTokenUsagePayload({ range: '30d', now: NOW, wait: true, force: true });
|
|
204
|
+
expect(before.providers.some((row) => row.id === 'deepseek')).toBe(true);
|
|
205
|
+
|
|
206
|
+
fs.rmSync(path.join(sessionsRoot, 'other', 'b.jsonl'));
|
|
207
|
+
const after = await buildTokenUsagePayload({ range: '30d', now: NOW, wait: true, force: true });
|
|
208
|
+
expect(after.providers.some((row) => row.id === 'deepseek')).toBe(false);
|
|
209
|
+
// The index drops the file's rows too, not just its totals.
|
|
210
|
+
const db = await getDb();
|
|
211
|
+
const rows = await db.all<{ project: string }>('SELECT project FROM usage_rollup WHERE project = ?', ['other']);
|
|
212
|
+
expect(rows).toEqual([]);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test('undated records stay in every window', async () => {
|
|
216
|
+
writeTranscript('d.jsonl', [messageLine({ provider: 'kiosapi', model: 'm', usage: { input: 3, output: 1, cost: { total: 0.75 } } })]);
|
|
217
|
+
const payload = await buildTokenUsagePayload({ range: 'today', now: NOW, wait: true, force: true });
|
|
218
|
+
expect(payload.providers.find((row) => row.id === 'kiosapi')?.cost).toBeCloseTo(0.75, 10);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('a custom period is inclusive of both endpoints', async () => {
|
|
222
|
+
const payload = await buildTokenUsagePayload({
|
|
223
|
+
range: 'custom',
|
|
224
|
+
customFrom: '2026-10-10',
|
|
225
|
+
customTo: '2026-10-10',
|
|
226
|
+
now: NOW,
|
|
227
|
+
wait: true,
|
|
228
|
+
});
|
|
229
|
+
// Two records on Oct 10, plus the undated one from the previous case: a
|
|
230
|
+
// missing date is not evidence of age, so it counts in every window.
|
|
231
|
+
expect(payload.totals.records).toBe(3);
|
|
232
|
+
expect(payload.periodLabel).toBe('Oct 10, 2026');
|
|
233
|
+
});
|
|
234
|
+
});
|