Commit graph

3 commits

Author SHA1 Message Date
8daa396549
feat: --budget-json and --mission cost tracking (Face + Murdock objectives)
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>
2026-04-08 08:28:18 +00:00
2371e02d57
feat: xAI Management API billing module (token-monitor#2)
- providers/xai-billing.js: fetchXaiUsage, fetchXaiInvoicePreview,
  aggregateByKey, renderXaiSection
- analyze.js: --xai flag for standalone view; xAI section appended
  to full report when XAI_MANAGEMENT_KEY is set
- Verified against live API: per-key spend by unit type, prepaid
  balance, current billing period total
- Usage endpoint: POST /v1/billing/teams/{id}/usage (analyticsRequest)
- Invoice endpoint: GET /v1/billing/teams/{id}/postpaid/invoice/preview
2026-04-06 08:19:27 +00:00
34898b1196
Phase 2: analysis layer (analyze.js), cache guard, log hygiene
- analyze.js: burn rate, weekly reconstruction, cycle stagger, rotation
  rank, underspend alerts, log prune with weekly archive
- logger.js: getCachedRun(maxAgeMinutes) — skip probing if recent data exists
- monitor.js: cache guard at wake — 20-min dedup, zero extra API calls
- test.js: fix type assertion for gemini-api/xai-api providers (+5 passing);
  add 14 new tests for cache guard and analyze.js (162 total, all green)
- docs/analyze.md: usage reference

Co-authored-by: Hannibal Smith <hannibal@trentuna.com>
2026-04-05 04:49:05 +00:00