Feature: Display Session Cost in Web UI#416
Feature: Display Session Cost in Web UI#416MartinRoberts-Fountain wants to merge 4 commits intoColeMurray:mainfrom
Conversation
Greptile SummaryThis PR adds end-to-end support for displaying the cumulative session cost in the web UI, covering backend persistence (persisting The implementation is clean and well-tested. One functional bug was found:
A minor edge case also exists in Important Files Changed
Prompt To Fix All With AIThis is a comment left during a code review.
Path: packages/web/src/components/sidebar/metadata-section.tsx
Line: 103-107
Comment:
**Dollar sign displayed twice**
The `<span className="w-4 text-center">$</span>` element renders a `$` character as a visual icon, but `formatSessionCost(totalCost)` (in `session-cost.ts` line 13) already returns a string prefixed with `$` — e.g. `"$0.0168"`. The result is the cost rendering as `$ OpenCode cost $0.0168`.
Either remove the `$` icon span and rely on `formatSessionCost`'s output, or keep the icon span and strip the `$` from the formatted value:
```suggestion
{typeof totalCost === "number" && totalCost > 0 && (
<div className="flex items-center gap-2 text-sm text-muted-foreground">
<span className="w-4 text-center">$</span>
<span>Session cost: {totalCost >= 1 ? totalCost.toFixed(2) : totalCost.toFixed(4)}</span>
</div>
)}
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: packages/web/src/lib/session-cost.ts
Line: 11-14
Comment:
**No handling for costs just above zero but effectively zero**
`formatSessionCost` uses a hard threshold of `>= 1` to switch between 2 and 4 decimal places. For very small costs (e.g. `$0.00001`), `toFixed(4)` rounds to `"$0.0000"`, misleadingly suggesting the session was free. Consider using `toPrecision` for sub-cent amounts:
```suggestion
export function formatSessionCost(cost: number): string {
if (cost >= 1) return `$${cost.toFixed(2)}`;
if (cost >= 0.01) return `$${cost.toFixed(4)}`;
return `$${cost.toPrecision(2)}`;
}
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "Display Session Cost in Web UI" | Re-trigger Greptile |
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Architectural feedback: persist cost on
|
Adding a feature to display the session cost in the web interface
