Conversation
📝 WalkthroughWalkthroughAdds an optional ChangesLLM Usage Display and list --api Integration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
subtrack/src/display.ts (1)
344-471: ⚡ Quick winAdd JSDoc to newly exported display APIs.
Lines 344 and 420 introduce public exported functions without JSDoc. Please add concise API docs for parameters and behavior.
📝 Suggested doc shape
+/** + * Render paid LLM usage entries as a formatted table with a total footer. + */ export function renderUsageTable(entries: LlmUsageEntry[]): void { ... } +/** + * Show current-period API usage summary by provider and total. + */ export function showApiUsage( total: number, byProvider: { provider: string; total: number }[], periodLabel: string, ): void { ... }As per coding guidelines,
subtrack/**/*.{js,jsx,ts,tsx}: Document public APIs with JSDoc comments in JavaScript/TypeScript.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@subtrack/src/display.ts` around lines 344 - 471, The exported functions renderUsageTable and showApiUsage are missing JSDoc documentation. Add JSDoc comments above each function to document the purpose, parameters, and return types. For renderUsageTable, document the entries parameter of type LlmUsageEntry[] and note that it renders to console with no return value. For showApiUsage, document the total, byProvider, and periodLabel parameters and their types, along with the void return type and that it displays API usage summary to console.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@subtrack/src/db.ts`:
- Around line 424-427: The GetLlmUsageOptions type definition (lines 398-404) is
missing the minCost property that is being accessed in the condition check at
line 424. Add the minCost property to the GetLlmUsageOptions interface or type
definition, declaring it as an optional property with an appropriate type
(likely optional number) to match how it is being used in the conditional check
with options?.minCost.
In `@subtrack/src/usage.ts`:
- Line 196: The minCost threshold value of 0.01 is too high and filters out
legitimate paid entries with fractional cents (between 0 and 0.01), not just
zero-cost entries. Change the minCost value to 0 (or use a minimal epsilon
value) to only exclude truly zero-cost entries while preserving all positive
cost entries, regardless of their fractional cent values.
---
Nitpick comments:
In `@subtrack/src/display.ts`:
- Around line 344-471: The exported functions renderUsageTable and showApiUsage
are missing JSDoc documentation. Add JSDoc comments above each function to
document the purpose, parameters, and return types. For renderUsageTable,
document the entries parameter of type LlmUsageEntry[] and note that it renders
to console with no return value. For showApiUsage, document the total,
byProvider, and periodLabel parameters and their types, along with the void
return type and that it displays API usage summary to console.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 82e1ada9-9f5e-4a7f-867c-c59483872646
📒 Files selected for processing (7)
subtrack/src/commands.test.tssubtrack/src/commands.tssubtrack/src/db.tssubtrack/src/display.tssubtrack/src/index.tssubtrack/src/types.tssubtrack/src/usage.ts
| if (options?.minCost !== undefined) { | ||
| conditions.push("cost >= ?") | ||
| params.push(options.minCost) | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Verify local type shape and minCost usage in db.ts + shared type in types.ts"
rg -n 'export type GetLlmUsageOptions|minCost' subtrack/src/db.ts subtrack/src/types.tsRepository: nazozokc/subtrack
Length of output: 419
🏁 Script executed:
sed -n '398,410p' subtrack/src/db.tsRepository: nazozokc/subtrack
Length of output: 352
minCost is used without being declared on this file's options type.
Line 424 accesses options?.minCost, but the local GetLlmUsageOptions type (lines 398–404) does not declare minCost. This breaks the type contract and fails strict TypeScript checks.
💡 Proposed fix
export type GetLlmUsageOptions = {
provider?: string
from?: string
to?: string
limit?: number
offset?: number
+ minCost?: number
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (options?.minCost !== undefined) { | |
| conditions.push("cost >= ?") | |
| params.push(options.minCost) | |
| } | |
| export type GetLlmUsageOptions = { | |
| provider?: string | |
| from?: string | |
| to?: string | |
| limit?: number | |
| offset?: number | |
| minCost?: number | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@subtrack/src/db.ts` around lines 424 - 427, The GetLlmUsageOptions type
definition (lines 398-404) is missing the minCost property that is being
accessed in the condition check at line 424. Add the minCost property to the
GetLlmUsageOptions interface or type definition, declaring it as an optional
property with an appropriate type (likely optional number) to match how it is
being used in the conditional check with options?.minCost.
Source: Coding guidelines
| from: options.from, | ||
| to: options.to, | ||
| limit: 100, | ||
| minCost: 0.01, |
There was a problem hiding this comment.
minCost: 0.01 can hide real paid usage entries.
Line 196 filters out any entry below 0.01 cents. Since cost supports fractional cents, positive (paid) entries between 0 and 0.01 are excluded even though they are not zero-cost.
💡 Safer threshold for “exclude only zero-cost” behavior
- minCost: 0.01,
+ minCost: Number.EPSILON,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| minCost: 0.01, | |
| minCost: Number.EPSILON, |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@subtrack/src/usage.ts` at line 196, The minCost threshold value of 0.01 is
too high and filters out legitimate paid entries with fractional cents (between
0 and 0.01), not just zero-cost entries. Change the minCost value to 0 (or use a
minimal epsilon value) to only exclude truly zero-cost entries while preserving
all positive cost entries, regardless of their fractional cent values.
Changes
usage list: Now filters out zero-cost entries (token-only records). Only entries with actual charges (cost > 0) are displayed. Output format migrated from fixed-width text tocli-table3for consistency withlistcommand.list --api/list -a: New flag to include current month's LLM API usage summary after the subscription table. Shows per-provider breakdown and total cost.Files changed
src/types.tsminCosttoGetLlmUsageOptionssrc/db.tscost >= ?SQL filter forgetLlmUsage()src/index.ts--apiflag tolistcommandsrc/commands.tshandleListnow displays API usage when--apisetsrc/display.tsrenderUsageTable()andshowApiUsage()src/usage.tshandleUsageListalways filtersminCost: 0.01, usescli-table3src/commands.test.tsVerification
pnpm build— ✅pnpm test— ✅ (175 passed)Summary by CodeRabbit
--api/-aflag to the list command to display LLM API usage totals for the current month, including per-provider breakdowns.