feat: analytics parity — tool cost, date ranges, budgets, query explorer, replay, snapshots (v2.4.0)

Analytics parity phases 2–7 (docs/plans/analytics-parity/), built on
138e706 and ported onto v2.3.1:
- Cost by AI tool (?tool= on cost/analytics/stats/workflows, by_tool,
  Codex fast/priority and flex tiers, agenthub_cost_usd_total{tool,model})
- Date ranges (from/to) on cost/analytics/workflows; Analytics range select
  with Today / This week (Monday) / This month (1st) / 7d / 30d / 90d / All /
  Custom; workflow filters carried into workflow-stats.js (read worker)
- Budgets and cost alerts as alert rule types (alert_rules rebuilt without
  its rule_type CHECK), GET /api/budgets/status, rule preview, spend pace,
  status-bar budget chip; rules stay editable in place
- Query Explorer (/query, allowlisted sort, CSV/JSON export) and scheduled
  reports (report_definitions/report_runs, Settings → Reports)
- Session Replay tab and immutable snapshots (session_snapshots, /snapshot/:token)
- Remote Codex sync, push ingest with a hashed token, privacy redaction and
  ignored folders (Settings → Data), Cursor sessions (no cost)
- Read-only MCP server, statusline, Grafana/Prometheus files

Also: resizable sidebar, pet run/wave animations, the workspace home keeps a
half-typed prompt, and the pre-commit hook runs only the related tests for a
small commit.
This commit is contained in:
2026-10-06 17:12:28 +07:00
parent 837da6e5de
commit 4aae61297f
146 changed files with 13565 additions and 537 deletions
+15 -6
View File
@@ -15,10 +15,14 @@
* codex-…, Vertex AI or the Gemini API for gemini-…); a router's model id
* (`clinepass/…`, `Highest`) is left to the user.
*
* ponytail: OpenAI's long-context (>272k) and priority/flex tiers are not
* modelled — Codex's context window stays under 272k and runs on the default
* tier; add a service_tier bucket if that changes. Gemini's >200k-token rate
* is not modelled either (the base rate is used).
* A non-Claude model's PRIORITY rates (`*_cost_per_token_priority`) fill the
* fast columns: Codex's fast/priority service tier is booked as `speed = fast`
* (`codex-usage.js`), and its flex tier as `service_tier = 'flex'` (half price,
* like batch, in `ratesForBucket`).
* ponytail: OpenAI's long-context (>272k) and Gemini's >200k-token rates are
* not modelled — Codex's context window (258k) stays under 272k and no current
* Claude model has such a tier; it needs a context-size bucket in token_usage
* (a primary-key rebuild) if that changes.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
@@ -103,6 +107,11 @@ function toRow(fam, e) {
if (input === 0 && output === 0) return null;
const fast = claude && e.supports_fast_mode ? Number(e.provider_specific_entry?.fast) : 0;
const fastOk = Number.isFinite(fast) && fast > 0 && fast <= 10;
const prio = claude
? []
: [per(e.input_cost_per_token_priority), per(e.output_cost_per_token_priority)];
const prioOk =
prio.length > 0 && prio.every((v) => Number.isFinite(v) && v > 0 && v <= MAX_PER_MTOK);
// Rounded: 0.000004 * 1e6 is 3.9999999999999996, which Settings would show.
const r = (n) => Math.round(n * 1e6) / 1e6;
return {
@@ -113,8 +122,8 @@ function toRow(fam, e) {
read: r(read),
w5m: r(w5m),
w1h: r(w1h),
fastIn: fastOk ? r(input * fast) : 0,
fastOut: fastOk ? r(output * fast) : 0,
fastIn: fastOk ? r(input * fast) : prioOk ? r(prio[0]) : 0,
fastOut: fastOk ? r(output * fast) : prioOk ? r(prio[1]) : 0,
};
}