galaxyproject / galaxyproject/loom

Embed CodeBurn cost dashboard in Orbit (per-project, historical, per-model)

Open
#32 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
14
Forks
12
Avg merge
6d 5h
Merged PRs (30d)
17

Description

Followup to README change in nekrut:notebook-rewire-pure-md @ 84119f9 (which adds option A — point users at \`npx codeburn\` from a separate terminal).

## Why an in-app version

[CodeBurn](https://github.com/getagentseal/codeburn) reads Pi sessions directly from \`~/.pi/agent/sessions/\` and computes accurate cost via LiteLLM's pricing catalog. Pi is a first-class supported provider — zero config, every Loom session is already visible to it. It produces:

- Daily / weekly / monthly / yearly / all-time totals
- Per-project breakdown (CodeBurn keys on the session cwd, which is the Loom project boundary)
- Per-model, per-tool, per-MCP, per-shell-command breakdowns
- Cache-hit %, average cost per session, top 5 most expensive sessions
- One-shot success rate per activity type
- CSV / JSON export

We don't try to compute any of that in Orbit today. Our footer is live in-flight cost only (from pi-ai's per-stream-event \`usage.cost\`).

CodeBurn also avoids a maintenance gap we already hit on \`#13\`: when a new model ships (Opus 4.7 etc.), CodeBurn picks up pricing automatically; our hand-coded \`PRICING\` table at \`app/src/renderer/app.ts:46\` does not.

## Proposed shape

Add a **\"Cost\" tab** (or a Preferences pane) in Orbit that spawns:

\`\`\`
codeburn report --format json
codeburn report -p 30days --format json
codeburn report -p all --format json
\`\`\`

…from the main process via \`spawn\` and renders the JSON natively in the renderer. Refresh on tab open + a manual refresh button (CodeBurn's own dashboard auto-refreshes every 30s — we can mirror that or rely on tab-open).

The JSON CodeBurn returns includes everything the dashboard renders:
- \`overview\` (cost, calls, sessions, cache hit %)
- \`daily\` (per-day breakdown for the period)
- \`projects\` (with \`avgCostPerSession\`)
- \`models\` (with token counts + cost)
- \`activities\` (with one-shot rates)
- \`coreTools\`, \`mcpServers\`, \`shellCommands\`

So we'd render a few stacked tables/cards keyed off those panels. No need to re-implement any pricing logic.

## Implementation sketch

- \`app/src/main/codeburn-handler.ts\` (~80 lines): IPC handler that runs \`npx codeburn report --format json -p \` (or \`codeburn\` if installed globally; check via \`which\`), parses the result, returns it to the renderer. Cache the result for ~10 s to avoid re-spawning on every tab switch.
- \`app/src/renderer/cost-tab.ts\` (~200 lines): renders the overview + per-project + per-model tables. Reuses the existing chat-table-styling CSS.
- \`app/src/renderer/index.html\`: add a \`Cost\` tab button next to Notebook / Activity / File.
- \`app/src/renderer/artifacts/artifact-panel.ts\`: extend \`TabKey\` with \`\"cost\"\`, route the new tab.
- Optional: a fallback message if \`codeburn\` isn't installed (\"Run \`npm install -g codeburn\` to enable this view\" — or rely on \`npx\` always working).

Estimated scope: ~6 files, ~350 lines, 1-2 days.

## Tradeoffs

- **Pro**: zero pricing logic to maintain in Orbit; CodeBurn handles every model from LiteLLM's catalog.
- **Pro**: per-project view answers \"what did this analysis cost?\" without us re-implementing it.
- **Pro**: integration is JSON-over-spawn — clean boundary, easy to mock in tests.
- **Con**: shells out to \`npx codeburn\` (or requires \`codeburn\` on PATH). First invocation has npx cold-start latency (~2-3s for the npm registry lookup); subsequent ones are fast.
- **Con**: adds an external runtime dependency. If CodeBurn changes its JSON schema we have to track. Mitigation: pin a version range in our docs / probe via \`codeburn --version\` before parsing.

## Related

- \`#13\` (dynamic model list / pricing) — partially obsoleted by CodeBurn for the cost-display side; the dropdown problem is separate.
- \`nekrut:notebook-rewire-pure-md @ 84119f9\` — the README pointer to CodeBurn.

## Branch

Defer until \`notebook-rewire-pure-md\` settles. Prefer landing this on top of whatever ships from that branch rather than stacking another concurrent in-flight refactor.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.