Skip to content

Show live model usage in an Analytics surface from the rail - #219

Merged
BunsDev merged 5 commits into
mainfrom
rail-analytics
Oct 15, 2026
Merged

BunsDev merged 5 commits into
mainfrom
rail-analytics

Conversation

@BunsDev

@BunsDev BunsDev commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Adds an Analytics icon to the rail. It opens the usage dashboard from #135 as a third surface beside Chat and Space, showing live usage recorded on this Mac instead of fixture data.

What's recorded

  • Each turn that calls a model, Auto or not, appends one row to app/usage.jsonl (mode 0600):
    • which tool ran (claude-code or codex), the model, the thread, the project and the Codex account binding;
    • the turn's input, cache reads, cache writes and output.
  • UsageMeter now sums input and both cache counts over every call (TurnUsage.totals). Its existing fields are unchanged, and Auto routing reads them as before.
  • Prompts, files and replies are never recorded. Costs stay null (unpriced).
  • A failed write is logged and never changes the turn. Reading skips torn or malformed lines.

How it's shown

  • The dashboard's stylesheet is global (:root, *, button, plus .sidebar and .main), and so is the app's. So the dashboard runs as its own document in a WorkspaceBrowser view, the pattern Knowledge and Canvas already use.
  • Main serves the built page (dist/usage-preview, now packaged) on modex-analytics://app/ in an in-memory session, with the rows at usage.json:
    • only regular files of known types are served from that folder, never anything outside it;
    • the page gets a strict CSP;
    • every other request from the session is refused;
    • the page has no bridge (window.modex and require are undefined).
  • It refreshes every 15 s while visible. Like Knowledge, the view hides under dialogs and menus and while Streamer Mode is on.
  • The Demo Data stamp and other sample wording appear only in the standalone preview (demo prop, default true), so e2e/usage.spec.ts keeps its fixture behavior.
  • Settings → General → Show Analytics in the rail hides the icon. It's stored in Layout and applies right away. The Store app leaves Analytics out.

Verification

  • pnpm build, pnpm typecheck and the full unit suite pass. The three failures in a run at load average around 75 (two Knowledge tests, one terminal-cleanup test) pass when rerun alone.
  • New test/analytics.test.ts:
    • the row's shape, tool mapping and summed input;
    • torn-line skipping and inclusive date filtering;
    • a row for every turn that called a model, and no failed turn when the ledger throws;
    • the origin refuses traversal, encoded traversal, symlinks, other types, other hosts and POST.
  • The four backend and meter tests now also assert totals: Claude and Codex captures are summed from their recorded calls.
  • New e2e/analytics.spec.ts: on a seeded row, it opens Analytics from the rail and reads the dashboard's own document. It checks for the live banner, no Demo stamp and no bridge, then hides the icon from Settings, which returns to Chat.
    • Not verified locally. Every e2e launch on this Mac currently times out waiting for the native show event. The display is asleep, so the window server never reports the window visible; existing specs fail the same way, and Record native window show before E2E observers connect #213's harness change doesn't help. CI's macOS run is the check for this spec.

Docs: docs/usage-preview.md → docs/analytics.md (what is recorded, how it's shown, the standalone preview) and a docs/status.md entry.

Each turn that calls a model, Auto or not, now adds one row to
app/usage.jsonl: tool, model, thread, project, account, and the turn's
input, cache reads and writes (summed over every call by UsageMeter) and
output. Prompts, files and replies are never recorded; costs stay null.
A ledger failure is logged and never changes the turn.

The rail's new Analytics icon opens the existing usage dashboard on
those rows. The dashboard keeps its own global styles, so it runs as a
separate document in a WorkspaceBrowser view served from
modex-analytics://app/ in an in-memory session, with the rows at
usage.json and every other request refused. Its Demo Data wording now
appears only in the standalone preview. Settings > General can hide the
icon; the Store app leaves Analytics out.

Coven-Harness: Claude Code / claude-opus-5-5
# Conflicts:
#	apps/desktop/src/renderer/App.tsx
#	apps/desktop/src/shared/types.ts
#	docs/status.md
@vercel

vercel Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
modex Ready Ready Preview Oct 15, 2026 3:13pm UTC

Request Review

handle("claude:login", () => claudeLogin.run(resolveCli("claude", sessionCliSettings.claude_bin)));
handle("claude:cancelLogin", () => claudeLogin.cancel());
handle("usage:list", (req) => usageLedger.list(req ?? {}), { localOnly: true });
handle("analytics:show", ({ bounds }) => workspaceAnalytics?.show(bounds) ?? null, { localOnly: true });
Settings opens on Auto routing, so the rail option was never on screen.

Coven-Harness: Claude Code / claude-opus-5-5
Settings: keep both new checkboxes, the Fable-to-Opus fallback from #210 and
Show Analytics in the rail.

Coven-Harness: Claude Code / claude-opus-5-5
@BunsDev
BunsDev merged commit a9469b1 into main Oct 15, 2026
12 checks passed
@BunsDev
BunsDev deleted the rail-analytics branch October 15, 2026 15:32

This branch was successfully deployed

1 active deployment
Preview — 1fcd18aa Deployed Oct 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant