Budget Intelligence & TUI — programmatic spend data, live dashboard, mission cost tracking #5

Merged
vigilio merged 3 commits from budget-intel into main 2026-04-08 09:12:08 +00:00
Member

Closes #3

What's in this PR

Three new capabilities for token-monitor:

1. node analyze.js --budget-json

Agent-consumable structured budget decision:

  • budget_decision — recommended provider, avoid list, reason
  • providers — all Teams with utilization, USD estimates (utilization × $7.50/week), severity
  • xai — per-key spend breakdown from management API (when XAI_MANAGEMENT_KEY set)
  • alerts — warnings for maxed providers + low xAI prepaid balance
  • Config via ~/.config/token-monitor/config.json (seat price, seats per team)
  • Existing --json flag unchanged (backward compat)

2. node analyze.js --mission <ref> / --mission-window <start> <end>

Mission cost attribution via time-window utilization delta:

  • --mission token-monitor#3 resolves start/end timestamps from Forgejo issue comments
  • --mission-window works without Forgejo (manual ISO time range)
  • Anthropic: utilization delta × weekly seat cost = estimated USD
  • xAI: exact spend from management API for the time window
  • Repo mapping via ~/.config/token-monitor/mission-repos.json

3. node tui.js

Live ANSI terminal dashboard:

  • Anthropic Teams: severity-colored rows (green/yellow/red), resets, utilization
  • xAI: per-key spend with bar graphs, prepaid balance
  • Budget decision recommendation prominently displayed
  • Alerts section
  • 60s auto-refresh, flicker-free (cursor-home, not clear-screen)
  • [r] force refresh, [q] clean exit restoring terminal
  • Degrades gracefully when XAI_MANAGEMENT_KEY absent
  • No external npm dependencies — pure Node stdlib

Amy gate: PASS

Full post-delivery validation in docs/missions/budget-intel-gates.md

Commits

  • 8daa396 feat: --budget-json and --mission cost tracking
  • 35d8cb5 feat: tui.js — live ANSI terminal dashboard
Closes #3 ## What's in this PR Three new capabilities for token-monitor: ### 1. `node analyze.js --budget-json` Agent-consumable structured budget decision: - `budget_decision` — recommended provider, avoid list, reason - `providers` — all Teams with utilization, USD estimates (utilization × $7.50/week), severity - `xai` — per-key spend breakdown from management API (when `XAI_MANAGEMENT_KEY` set) - `alerts` — warnings for maxed providers + low xAI prepaid balance - Config via `~/.config/token-monitor/config.json` (seat price, seats per team) - **Existing `--json` flag unchanged** (backward compat) ### 2. `node analyze.js --mission <ref>` / `--mission-window <start> <end>` Mission cost attribution via time-window utilization delta: - `--mission token-monitor#3` resolves start/end timestamps from Forgejo issue comments - `--mission-window` works without Forgejo (manual ISO time range) - Anthropic: utilization delta × weekly seat cost = estimated USD - xAI: exact spend from management API for the time window - Repo mapping via `~/.config/token-monitor/mission-repos.json` ### 3. `node tui.js` Live ANSI terminal dashboard: - Anthropic Teams: severity-colored rows (green/yellow/red), resets, utilization - xAI: per-key spend with bar graphs, prepaid balance - Budget decision recommendation prominently displayed - Alerts section - 60s auto-refresh, flicker-free (cursor-home, not clear-screen) - `[r]` force refresh, `[q]` clean exit restoring terminal - Degrades gracefully when `XAI_MANAGEMENT_KEY` absent - **No external npm dependencies** — pure Node stdlib ## Amy gate: PASS Full post-delivery validation in `docs/missions/budget-intel-gates.md` ## Commits - `8daa396` feat: --budget-json and --mission cost tracking - `35d8cb5` feat: tui.js — live ANSI terminal dashboard
hannibal added 3 commits 2026-04-08 08:34:08 +00:00
- anthropic-teams.js: detect HTTP 400 extra-usage policy blocks, return
  status='policy_rejected' with quota headers still readable
- report.js: display policy_rejected as CRITICAL with 'POLICY BLOCKED' label
- getSeverity: treat policy_rejected as critical

Currently the direct API (used by monitor) returns 200; pi's OAuth path
returns 400. This fix future-proofs against the block extending to direct
API calls, and correctly classifies the status if it does.

Refs: trentuna/commons#17, trentuna/token-monitor#4
Implements token-monitor#3 objectives 1 and 2:

--budget-json: structured agent-consumable budget decision schema
  - budget_decision with recommended_provider, avoid list, reason
  - providers: all Teams with utilization, USD estimates, severity
  - xai: per-key spend breakdown from management API (if XAI_MANAGEMENT_KEY set)
  - alerts: warnings/critical for maxed providers + low xAI prepaid balance
  - config from ~/.config/token-monitor/config.json (default .50/week/seat)

--mission <ref>: mission cost attribution via Forgejo issue time windows
  - resolves start/end timestamps from Forgejo issue comments
  - requires FORGEJO_TOKEN env var + ~/.config/token-monitor/mission-repos.json
  - repo mapping: { 'bookmarko': 'trentuna/bookmarko', ... }

--mission-window <iso-start> <iso-end>: same without Forgejo dep

Both: utilization delta × weekly seat cost = estimated Anthropic spend
Both: exact xAI spend via management API for time window (if key set)
Existing --json flag unchanged (backward compat preserved)

Co-authored-by: Hannibal Smith <hannibal@a-team>
Implements token-monitor#3 objective 3:

node tui.js starts a live terminal dashboard:
  - Full layout: Anthropic Teams (severity-colored) + xAI section
  - 60s auto-refresh with 1s countdown
  - Flicker-free via cursor-home (not clear-screen)
  - [r] forces immediate refresh
  - [q] or Ctrl-C exits cleanly, restores terminal + cursor
  - Severity coloring: green=ok, yellow=warning, red=critical/maxed
  - xAI section hidden when XAI_MANAGEMENT_KEY not set (graceful degradation)
  - Budget decision: recommended provider + avoid list prominently displayed
  - Alerts section (up to 3, warning/critical only)
  - No external npm dependencies — pure Node stdlib + project analyze.js

Data source: spawns analyze.js --budget-json internally (reuses cached probe
data if fresh, avoids double-probe on each TUI refresh)

Co-authored-by: Hannibal Smith <hannibal@a-team>
vigilio merged commit aefa35a5ca into main 2026-04-08 09:12:08 +00:00
Sign in to join this conversation.
No description provided.