codex-copilot-dx 1.2.4 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,11 +14,11 @@ npm install -g codex-copilot-dx@latest
14
14
  ccdx
15
15
  ```
16
16
 
17
- No Node or Git? Download [install.sh](https://github.com/DaleXiao/codex-copilot-dx/releases/download/v1.2.4/install.sh) (macOS/Linux) or [install.ps1](https://github.com/DaleXiao/codex-copilot-dx/releases/download/v1.2.4/install.ps1) (Windows), then run `sh install.sh` or `./install.ps1` under your current shell policy. The bootstrap reuses compatible Node/npm or installs verified official Node 24.22.0 privately for CCDX. It adds no Git, compiler or system package manager. It keeps registry/proxy/certificate policy, verifies the Release package and installed runtime, and restores the prior CCDX package if installation fails. Dependencies still need your configured registry. See [installation limits and private command paths](docs/REFERENCE.md#install-without-node-or-git).
17
+ No Node or Git? Download [install.sh](https://github.com/DaleXiao/codex-copilot-dx/releases/download/v1.2.5/install.sh) (macOS/Linux) or [install.ps1](https://github.com/DaleXiao/codex-copilot-dx/releases/download/v1.2.5/install.ps1) (Windows), then run `sh install.sh` or `./install.ps1` under your current shell policy. The bootstrap reuses compatible Node/npm or installs verified official Node 24.22.0 privately for CCDX. It adds no Git, compiler or system package manager. It keeps registry/proxy/certificate policy, verifies the Release package and installed runtime, and restores the prior CCDX package if installation fails. Dependencies still need your configured registry. See [installation limits and private command paths](docs/REFERENCE.md#install-without-node-or-git).
18
18
 
19
19
  CCDX reuses a compatible local credential or starts GitHub Device Flow, listens on `127.0.0.1:2026`, configures Codex, and opens the App. Interactive desktop starts also open the local WebUI once; use `ccdx --no-browser` or disable this in WebUI settings. No client binary patch is needed. On Windows, open the App manually unless native prediction setup is enabled. In restricted Windows PowerShell, use `npm.cmd` to install and `ccdx.cmd` for the first launch, or run `ccdx.cmd doctor --fix`. Startup, updates and explicit repair remove only CCDX's exact npm-generated `.ps1` launchers so later calls can use `ccdx`. The npm package adds no install hook or policy change; custom launchers are preserved. npm's own script is untouched. The configured `dummy` API key is a placeholder, not a credential.
20
20
 
21
- The [local control console](http://127.0.0.1:2026/) keeps indented Codex/Claude pages, Model sources, Usage, Requests and Settings. Codex owns source/model, Auto Review, images, input suggestions and conversation buffering; Model sources owns accounts, catalogs and Microsoft 365 access. Browsing a catalog never changes routing. The existing visual style, logo and motion remain.
21
+ The [local control console](http://127.0.0.1:2026/) keeps indented Codex/Claude pages, Model sources, Usage, Requests and Settings. Codex owns source/model, Auto Review, images, input suggestions and conversation buffering; Model sources owns accounts, catalogs and Microsoft 365 access. Browsing a catalog never changes routing. Usage offers animated bars (default) or curves without extra requests; reduced motion keeps them static. Overview shows an approximate token cache hit rate, retaining partial/unknown states. The existing visual style and logo remain.
22
22
 
23
23
  Startup shows bounded checks, sources with discovered model lists and Claude Code/App configuration. Prediction normally uses one summary line; `ccdx prediction status` retains recovery and environment details. After Ready, an interactive terminal shows current source/Claude state and a line-framed table of this process's returned usage and inference counters. Notices and activity each have their own line; individual requests do not scroll. Input includes reused input tokens. `ccdx --verbose` (also `--show-request-id`, or debug logging) retains detail output; optional file logging remains independently controlled. Source and Claude summaries wrap on narrow terminals. Failed reads show previous-data status and the last successful update time. Non-TTY, CI, dumb, or terminals too small for the full region use plain output (at least 40 columns / 16 rows are required). `Ready` only means the core service is available; discovered catalogs and configured clients do not prove inference access.
24
24
 
@@ -277,6 +277,8 @@ while visible/automatic, and source/settings evidence every eight status ticks.
277
277
  Catalog and retained-log reads retain their slower, view-scoped policy. Animation
278
278
  frames still load once per page when opened.
279
279
 
280
+ `dashboard/usage.js` owns bar/curve geometry and viewport-gated, one-shot Web Animations. The two views share retained analytics and accessible day buttons; their paths never connect unavailable history or overshoot adjacent values. View-only changes leave the calendar nodes intact. The UI lifecycle cancels motion on hidden/suspended views and reduced-motion changes; no animation timer or chart dependency is added. `usage-store.mjs` shares cache-evidence validation between retained summaries and process-local totals; runtime snapshots expose the weighted cache ratio plus a partial-evidence flag, without new persistence or log scans. The Overview renderer formats that snapshot and preserves unknown/invalid values.
281
+
280
282
  `dashboard-updates.mjs` is loaded only by the protected update-information route. It projects bounded public stable-release metadata and publication dates, with process-local single-flight, five-minute success and one-minute failure caches. Its asynchronous npm network-configuration read reuses the installer's existing policy-preserving downloader; it adds no runtime dependency, credentials or synchronous child process on the service event loop. Metadata has a four-second per-request deadline and 128 KiB decoded-body bound. It never installs or restarts anything and does not alter startup's independent web-redirect lookup. `dashboard/updates.js` renders current/available/unknown states and validated, pinned installation command text; `refresh.js` owns its visible Settings refresh cadence. Failed checks preserve explicitly labeled prior metadata. No provider authentication or inference is involved.
281
283
 
282
284
  `claude-models.mjs` owns exact ID spelling and capability-cap projection shared by
package/docs/REFERENCE.md CHANGED
@@ -1004,7 +1004,7 @@ Unknown support prevents an explicitly requested exception from starting.
1004
1004
  For an older updater that still requires Git, install the Release tarball directly:
1005
1005
 
1006
1006
  ```sh
1007
- npm install -g https://github.com/DaleXiao/codex-copilot-dx/releases/download/v1.2.4/codex-copilot-dx-1.2.4.tgz
1007
+ npm install -g https://github.com/DaleXiao/codex-copilot-dx/releases/download/v1.2.5/codex-copilot-dx-1.2.5.tgz
1008
1008
  # Windows PowerShell: use npm.cmd instead of npm.
1009
1009
  ```
1010
1010
 
@@ -1200,14 +1200,18 @@ are not guessed into one. Legacy untagged Provider records retain their historic
1200
1200
  GitHub attribution. Cache-read tokens are included in input, not added twice.
1201
1201
  The separate current-run summary updates from returned usage in memory, without
1202
1202
  rescanning retained logs at the status cadence.
1203
+ Overview adds an approximate token cache hit rate: returned reused input tokens divided by returned input tokens, weighted by tokens rather than request percentages. Missing evidence is distinct from an explicit zero; all-unknown cache evidence, zero input and invalid counts display `—`. Mixed complete/incomplete cache evidence displays `~` before the recorded aggregate ratio. This describes recorded input reuse, not a request success ratio, invoice or whole-account cache statistic. Missing output alone does not invalidate usable input/cache evidence.
1203
1204
 
1204
- Usage analytics remains collapsed until opened: 7/30/90-day bars and a bounded
1205
+ Usage analytics remains collapsed until opened: 7/30/90-day charts and a bounded
1205
1206
  365-day calendar in the browser time zone. Model/range/day selection reuses its
1206
1207
  snapshot. Days outside retained history are distinct from zero recorded activity.
1207
1208
  Filters, chart nodes and unsaved animation selection survive unrelated refreshes.
1208
1209
  Dark/light, English/Chinese and reduced motion remain supported. Language changes
1209
1210
  translate page labels in place without fetching models or rebuilding charts;
1210
1211
  commands, identifiers and upstream error text retain their original values.
1212
+ Chart view defaults to Bar chart on each page load; its dropdown switches to Line chart without another request or log scan. Both views retain the same input/output values, scale, model/source/range filters and date selection. Lines show separate input/output series, pass through each known day's value, stay between neighboring values and break across unavailable history; a lone known day is a point. The calendar is unchanged by view switching.
1213
+
1214
+ Visible bar stacks rise from the baseline once over 450 ms; curves draw left to right over 600 ms (a lone point fades in over 200 ms). Opening/revealing a chart and changing its data, filters or view can replay the entrance. Selecting a day, changing calendar measure and unchanged background refreshes do not replay it. Hidden/collapsed views, page suspension and reduced-motion preferences cancel active chart motion; reduced-motion or unsupported animation APIs retain the complete static chart. Chart motion adds no polling loop, chart library or runtime dependency.
1211
1215
 
1212
1216
  The atom logo stays in the sidebar brand (compact top navigation on narrow screens).
1213
1217
  It rotates once on load and manual Refresh, never on scheduled reads, and respects
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-copilot-dx",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "Local Codex adapter and optional Microsoft 365 Claude gateway",
5
5
  "author": "Dale Xiao",
6
6
  "type": "module",
@@ -47,7 +47,7 @@
47
47
  label(el("page-title"), titles[next]);
48
48
  if (["codex", "models", "system"].includes(next)) void loadSettings();
49
49
  if (next === "models") { void dashboardRefresh.refresh("models");void dashboardRefresh.refresh("auth"); }
50
- if (next === "usage") void dashboardRefresh.refresh("usage");
50
+ if (next === "usage") { void dashboardRefresh.refresh("usage");usageView.revealChart(); } else usageView.stopMotion();
51
51
  if (next === "system") { void dashboardRefresh.refresh("animation");void dashboardRefresh.refresh("updates"); }
52
52
  syncAnimationPreview();
53
53
  }
@@ -52,7 +52,7 @@
52
52
  <div class="table-wrap"><table><thead><tr><th data-i18n="source">Source</th><th data-i18n="client">APP</th><th data-i18n="state">STATE</th><th data-i18n="gateway">LOCAL ACCESS</th><th data-i18n="last_request">LAST REQUEST</th></tr></thead><tbody id="provider-clients"></tbody></table></div>
53
53
  <div id="provider-requests" class="hint"></div>
54
54
  </details>
55
- <section class="panel dashboard-section"><h2 data-i18n="this_run_usage">THIS RUN</h2><p id="runtime-usage" class="table-note"></p><p class="hint" data-i18n="updated_from_returned_usage_not_a_live_bill_pending_usage_is_not">Counts returned usage only. Pending usage is not included. This is not a live bill.</p></section>
55
+ <section class="panel dashboard-section"><h2 data-i18n="this_run_usage">THIS RUN</h2><p id="runtime-usage" class="table-note"></p><p class="table-note"><span data-i18n="approx_cache_hit_rate">Approx. cache hit rate</span>: <strong id="runtime-cache-hit" data-i18n-title="runtime_cache_hit_basis" title="Reused input / input tokens. ~ Partial counts. — Unknown or invalid.">—</strong></p><p class="hint" data-i18n="updated_from_returned_usage_not_a_live_bill_pending_usage_is_not">Counts returned usage only. Pending usage is not included. This is not a live bill.</p></section>
56
56
  </div>
57
57
  <div data-view="codex" hidden>
58
58
  <section class="panel dashboard-section" aria-labelledby="routing-heading">
@@ -166,6 +166,7 @@
166
166
  <div class="analytics-controls">
167
167
  <label><span data-i18n="model_5e2c6">Model</span> <select id="analytics-model"><option value="" data-i18n="all_models">All models</option></select></label>
168
168
  <label><span data-i18n="daily_range">Date range</span> <select id="analytics-range"><option value="7" data-i18n="7_days">Last 7 days</option><option value="30" selected data-i18n="30_days">Last 30 days</option><option value="90" data-i18n="90_days">Last 90 days</option></select></label>
169
+ <label><span data-i18n="chart_view">Chart view</span> <select id="analytics-view"><option value="bars" selected data-i18n="bar_chart">Bar chart</option><option value="line" data-i18n="line_chart">Line chart</option></select></label>
169
170
  <label><span data-i18n="activity">Measure</span> <select id="analytics-metric"><option value="requests" data-i18n="calls_b73a5">Requests</option><option value="tokens" data-i18n="tokens">Usage (Token)</option></select></label>
170
171
  </div>
171
172
  <p id="analytics-note" class="table-note" role="status" data-i18n="open_to_read_retained_usage_history">Open to view usage trends.</p>
@@ -1,5 +1,10 @@
1
1
  (() => {
2
2
  const translations = {
3
+ "chart_view": ["Chart view", "图表视图"],
4
+ "bar_chart": ["Bar chart", "柱状图"],
5
+ "line_chart": ["Line chart", "曲线图"],
6
+ "approx_cache_hit_rate": ["Approx. cache hit rate", "粗略缓存命中率"],
7
+ "runtime_cache_hit_basis": ["Reused input / input tokens. ~ Partial counts. — Unknown or invalid.", "复用输入 ÷ 输入 Token。\n~:数据不完整。—:未知或无效。"],
3
8
  "provider_status_scope": ["Source and application status", "模型来源与应用状态"],
4
9
  "version_updates": ["VERSION & UPDATES", "版本与更新"],
5
10
  "copy_command": ["Copy command", "复制指令"],
@@ -214,6 +214,8 @@
214
214
  const usage = data.runtime_usage;
215
215
  text("runtime-usage", usage ? "records_usage_records_input_input_cache_read_cached_output_outpu" : "—",
216
216
  usage ? { records: number(usage.records), input: number(usage.input_tokens), cached: number(usage.cached_input_tokens), output: number(usage.output_tokens), partial: usage.partial_records ? " ~" : "" } : {});
217
+ const rate = usage?.cache_hit_rate;
218
+ text("runtime-cache-hit", Number.isFinite(rate) && rate >= 0 && rate <= 1 ? `${usage.cache_hit_rate_partial ? "~" : ""}${(rate * 100).toFixed(1)}%` : "—");
217
219
  element("process-state").textContent = `PID ${data.pid || "—"} / ${globalThis.location?.origin || ""}`;
218
220
  text("process-memory", "rss_rss_heap_heap", { rss: mib(data.process?.rss_bytes), heap: mib(data.process?.heap_used_bytes) });
219
221
  text("process-queues", "codex_body_admission_active_active_queued_queued_queue_limit_lim", {
@@ -110,6 +110,14 @@ select { max-width: 260px; padding: 5px; font: inherit; color: var(--text); back
110
110
  .daily-bars { display: flex; align-items: end; gap: 3px; height: 130px; border-bottom: 1px solid var(--border); }
111
111
  .daily-bar { height: 100%; flex: 1; min-width: 0; padding: 0; border: 0; display: flex; flex-direction: column; justify-content: end; background: transparent; border-radius: 0; }
112
112
  .daily-bar span { display: block; flex-shrink: 0; width: 100%; }
113
+ .daily-bar .bar-stack { display:flex; flex-direction:column; justify-content:end; height:100%; transform-origin:center bottom; }
114
+ .daily-lines { position:relative; gap:0; }
115
+ .daily-line-plot { position:absolute; inset:0; width:100%; height:100%; pointer-events:none; overflow:visible; }
116
+ .daily-curve { fill:none; stroke-width:2; stroke-linecap:round; stroke-linejoin:round; stroke-dasharray:1; stroke-dashoffset:0; }
117
+ .curve-input { stroke:var(--accent-soft); }
118
+ .curve-output { stroke:var(--ansi-39); }
119
+ .daily-lines .daily-bar { z-index:1; }
120
+ .daily-lines .daily-bar:hover { background:color-mix(in srgb, var(--accent-soft) 10%, transparent); }
113
121
  .bar-input { background: var(--accent-soft); }
114
122
  .bar-output { background: var(--ansi-39); }
115
123
  .daily-bar:hover { background: var(--option-hover); }
@@ -119,6 +127,7 @@ select { max-width: 260px; padding: 5px; font: inherit; color: var(--text); back
119
127
  .chart-legend span::before { content: "■"; margin-right: 6px; }
120
128
  .legend-input::before { color: var(--accent-soft); }
121
129
  .legend-output::before { color: var(--ansi-39); }
130
+ .daily-lines ~ .chart-legend span::before { content:"━"; }
122
131
  .calendar-scroll { overflow-x: auto; padding: 4px; }
123
132
  .calendar-grid { width: max-content; }
124
133
  .calendar-months { display: grid; grid-auto-columns: 12px; gap: 4px; margin-bottom: 7px; color: var(--muted); font-size: 9px; height: 14px; }
@@ -15,7 +15,8 @@ const text = (id, key, values) => { localize(element(id), key, values); };
15
15
  const finite = (value) => value !== null && value !== undefined && Number.isFinite(Number(value));
16
16
  const number = (value) => finite(value) ? Math.max(0, Math.round(Number(value))).toLocaleString() : "—";
17
17
  const mib = (value) => finite(value) ? `${(Number(value) / 1048576).toFixed(1)} MiB` : "—";
18
- const viewHelpers = { element, phrase, localize, text, finite, number, mib, tableRow, emptyTable, document, navigator: globalThis.navigator };
18
+ const viewHelpers = { element, phrase, localize, text, finite, number, mib, tableRow, emptyTable, document, navigator: globalThis.navigator,
19
+ motionAllowed: () => !reducedMotion.matches && document.visibilityState === "visible" && element("usage-analytics").open && element("model-usage").open && !element("model-usage").closest("[hidden]") };
19
20
  const { render, renderProviders, renderFailures, renderContext } = globalThis.ccdxDashboardStatus.create(viewHelpers);
20
21
  const usageView = globalThis.ccdxDashboardUsage.create(viewHelpers);
21
22
  const { applyUsage, renderUsageState, renderAnalytics, renderUsageTable, selectUsageDay } = usageView;
@@ -104,6 +105,9 @@ new IntersectionObserver(([entry]) => {
104
105
  }).observe(element("animation-options"));
105
106
  document.addEventListener("visibilitychange", syncAnimationPreview);
106
107
  reducedMotion.addEventListener("change", syncAnimationPreview);
108
+ reducedMotion.addEventListener("change", () => { if (reducedMotion.matches) usageView.stopMotion(); });
109
+ document.addEventListener("visibilitychange", () => { if (document.visibilityState !== "visible") usageView.stopMotion(); });
110
+ new IntersectionObserver(([entry]) => usageView.setChartVisible(entry.isIntersecting)).observe(element("daily-bars"));
107
111
 
108
112
  function buildAnimationOptions(data) {
109
113
  const container = element("animation-options");
@@ -516,7 +520,7 @@ element("auto-refresh").addEventListener("click", () => {
516
520
  try { localStorage.setItem(autoRefreshKey, dashboardRefresh.automatic ? "on" : "off"); } catch { /* Keep the current choice. */ }
517
521
  });
518
522
  document.addEventListener("visibilitychange", () => dashboardRefresh.visibilityChanged());
519
- window.addEventListener("pagehide", () => { dashboardRefresh.suspend(); stopAnimationPreview(); });
523
+ window.addEventListener("pagehide", () => { dashboardRefresh.suspend(); stopAnimationPreview();usageView.stopMotion(); });
520
524
  window.addEventListener("pageshow", () => { dashboardRefresh.resume(); syncAnimationPreview(); });
521
525
 
522
526
  for (const [id, key] of [["account-authorization", "auth"], ["client-features", "status"], ["request-context", "status"], ["recent-failures", "status"], ["upstream-models", "models"], ["model-usage", "usage"]]) {
@@ -535,9 +539,10 @@ element("animation-settings").addEventListener("toggle", () => {
535
539
  syncAnimationPreview();
536
540
  });
537
541
  element("usage-analytics").addEventListener("toggle", () => {
542
+ if (element("usage-analytics").open) usageView.revealChart();else usageView.stopMotion();
538
543
  if (element("usage-analytics").open && element("model-usage").open) dashboardRefresh.refresh("usage");
539
544
  });
540
- for (const id of ["analytics-model", "analytics-range", "analytics-metric"]) element(id).addEventListener("change", () => {
545
+ for (const id of ["analytics-model", "analytics-range", "analytics-metric", "analytics-view"]) element(id).addEventListener("change", () => {
541
546
  renderAnalytics();
542
547
  if (usageView.data && usageView.selectedDate) renderUsageTable();
543
548
  });
@@ -1,5 +1,13 @@
1
1
  (() => {
2
- function create({ element, phrase, localize, text, finite, number, mib, tableRow, emptyTable, document, navigator }) {
2
+ function curvePath(points) {
3
+ return points.map(([x, y], index) => {
4
+ if (!index) return `M${x},${y}`;
5
+ const [previousX, previousY] = points[index - 1], middle = (previousX + x) / 2;
6
+ return `C${middle},${previousY} ${middle},${y} ${x},${y}`;
7
+ }).join(" ");
8
+ }
9
+
10
+ function create({ element, phrase, localize, text, finite, number, mib, tableRow, emptyTable, document, navigator, motionAllowed = () => false }) {
3
11
  function usageValues(row) {
4
12
  const rate = Number.isFinite(row.cache_hit_rate) && row.cache_hit_rate >= 0 && row.cache_hit_rate <= 1
5
13
  ? `${row.cache_hit_rate_partial ? "~" : ""}${(row.cache_hit_rate * 100).toFixed(1)}%` : "—";
@@ -7,8 +15,92 @@
7
15
  }
8
16
 
9
17
  let usageData = null;
10
- let analyticsSignature;
18
+ let analyticsSignature, calendarSignature;
11
19
  let selectedUsageDate = "";
20
+ let dailySignature, dailySelection, chartVisible = false, motionPending = false;
21
+ let motionTargets = [];
22
+ const animations = new Set();
23
+
24
+ function stopMotion() {
25
+ for (const animation of animations) animation.cancel();
26
+ animations.clear();motionPending = false;
27
+ }
28
+
29
+ function playMotion() {
30
+ if (!motionPending || !chartVisible || !motionAllowed()) return;
31
+ stopMotion();
32
+ for (const { node, line, point } of motionTargets) {
33
+ if (!node.animate) continue;
34
+ const animation = node.animate(point ? [{ opacity: 0 }, { opacity: 1 }] : line
35
+ ? [{ strokeDashoffset: 1 }, { strokeDashoffset: 0 }]
36
+ : [{ transform: "scaleY(0)" }, { transform: "scaleY(1)" }],
37
+ { duration: point ? 200 : line ? 600 : 450, easing: "cubic-bezier(0.25, 1, 0.5, 1)" });
38
+ animations.add(animation);
39
+ animation.finished?.then(() => animations.delete(animation), () => animations.delete(animation));
40
+ }
41
+ }
42
+
43
+ function revealChart() { motionPending = true;playMotion(); }
44
+ function setChartVisible(value) { chartVisible = value;if (value) playMotion();else if (animations.size) stopMotion(); }
45
+
46
+ function svgNode(tag, attributes) {
47
+ const node = document.createElementNS("http://www.w3.org/2000/svg", tag);
48
+ for (const [key, value] of Object.entries(attributes)) node.setAttribute(key, String(value));
49
+ return node;
50
+ }
51
+
52
+ function renderDaily(daily, model, maximum) {
53
+ const line = element("analytics-view").value === "line";
54
+ const signature = JSON.stringify([daily, model, line]);
55
+ if (signature === dailySignature && selectedUsageDate === dailySelection) return;
56
+ const changed = signature !== dailySignature;
57
+ dailySignature = signature;dailySelection = selectedUsageDate;
58
+ stopMotion();motionTargets = [];
59
+ const chart = element("daily-bars");
60
+ chart.className = line ? "daily-bars daily-lines" : "daily-bars";
61
+ chart.replaceChildren();
62
+ if (line) {
63
+ const plot = svgNode("svg", { class: "daily-line-plot", viewBox: "0 0 1000 130", preserveAspectRatio: "none", "aria-hidden": "true", focusable: "false" });
64
+ for (const key of ["input_tokens", "output_tokens"]) {
65
+ let segment = [];
66
+ const color = key === "input_tokens" ? "curve-input" : "curve-output";
67
+ const flush = () => {
68
+ if (segment.length > 1) {
69
+ const path = svgNode("path", { d: curvePath(segment), class: `daily-curve ${color}`, pathLength: 1, "vector-effect": "non-scaling-stroke" });
70
+ plot.append(path);motionTargets.push({ node: path, line: true });
71
+ } else if (segment.length === 1) {
72
+ const [x, y] = segment[0];
73
+ const circle = svgNode("circle", { cx: x, cy: y, r: 2, class: color, fill: "none", "stroke-width": 2, "vector-effect": "non-scaling-stroke" });
74
+ plot.append(circle);motionTargets.push({ node: circle, point: true });
75
+ }
76
+ segment = [];
77
+ };
78
+ daily.forEach((day, index) => {
79
+ if (!day.available) { flush();return; }
80
+ const point = analyticsPoint(day, model), x = (index + 0.5) / daily.length * 1000, y = 128 - point[key] / maximum * 124;
81
+ segment.push([x, y]);
82
+ });
83
+ flush();
84
+ }
85
+ chart.append(plot);
86
+ }
87
+ for (const day of daily) {
88
+ const point = analyticsPoint(day, model), button = dayButton(day, point);
89
+ button.className = "daily-bar";
90
+ if (!line) {
91
+ const stack = document.createElement("span");stack.className = "bar-stack";
92
+ for (const key of ["output_tokens", "input_tokens"]) {
93
+ const segment = document.createElement("span");
94
+ segment.className = key === "input_tokens" ? "bar-input" : "bar-output";
95
+ segment.style.height = `${point[key] / maximum * 100}%`;
96
+ stack.append(segment);
97
+ }
98
+ button.append(stack);motionTargets.push({ node: stack, line: false });
99
+ }
100
+ chart.append(button);
101
+ }
102
+ motionPending = changed;playMotion();
103
+ }
12
104
 
13
105
  function renderUsageTable() {
14
106
  const day = selectedUsageDate && usageData.analytics?.days.find((entry) => entry.date === selectedUsageDate);
@@ -61,7 +153,8 @@
61
153
  const analytics = usageData?.analytics;
62
154
  if (!analytics) return;
63
155
  const model = element("analytics-model").value;
64
- const signature = JSON.stringify([analytics, model, element("analytics-range").value, element("analytics-metric").value, selectedUsageDate]);
156
+ const commonSignature = JSON.stringify([analytics, model, element("analytics-range").value, element("analytics-metric").value, selectedUsageDate]);
157
+ const signature = `${commonSignature}:${element("analytics-view").value}`;
65
158
  if (signature === analyticsSignature) return;
66
159
  analyticsSignature = signature;
67
160
  const days = analytics.days;
@@ -70,22 +163,11 @@
70
163
  const point = analyticsPoint(day, model);
71
164
  return point.input_tokens + point.output_tokens;
72
165
  }));
73
- const bars = element("daily-bars");
74
- bars.replaceChildren();
75
- for (const day of daily) {
76
- const point = analyticsPoint(day, model);
77
- const button = dayButton(day, point);
78
- button.className = "daily-bar";
79
- for (const key of ["output_tokens", "input_tokens"]) {
80
- const segment = document.createElement("span");
81
- segment.className = key === "input_tokens" ? "bar-input" : "bar-output";
82
- segment.style.height = `${point[key] / maximum * 100}%`;
83
- button.append(segment);
84
- }
85
- bars.append(button);
86
- }
166
+ renderDaily(daily, model, maximum);
87
167
  text("daily-from", daily[0].date);
88
168
  text("daily-to", analytics.to);
169
+ if (commonSignature === calendarSignature) return;
170
+ calendarSignature = commonSignature;
89
171
  const metric = element("analytics-metric").value;
90
172
  const value = (day) => {
91
173
  const point = analyticsPoint(day, model);
@@ -157,7 +239,7 @@
157
239
  text("analytics-updated", "updated_time", { time: new Date().toLocaleTimeString() });
158
240
  }
159
241
  }
160
- return { applyUsage, renderUsageState, renderAnalytics, renderUsageTable, selectUsageDay, usageValues, get data() { return usageData; }, get selectedDate() { return selectedUsageDate; } };
242
+ return { applyUsage, renderUsageState, renderAnalytics, renderUsageTable, selectUsageDay, usageValues, setChartVisible, revealChart, stopMotion, get data() { return usageData; }, get selectedDate() { return selectedUsageDate; } };
161
243
  }
162
- globalThis.ccdxDashboardUsage = { create };
244
+ globalThis.ccdxDashboardUsage = { create, curvePath };
163
245
  })();
@@ -27,7 +27,12 @@ let writeFailures = 0;
27
27
  const runtimeUsage = { since: new Date().toISOString(), records: 0, input_tokens: 0, cached_input_tokens: 0, output_tokens: 0, partial_records: 0 };
28
28
  const runtimeUsageByProvider = new Map();
29
29
 
30
- export function runtimeUsageSnapshot() { return { ...runtimeUsage, by_provider: Object.fromEntries([...runtimeUsageByProvider].map(([id, totals]) => [id, { ...totals }])) }; }
30
+ export function runtimeUsageSnapshot() {
31
+ const snapshot = totals => ({ ...totals,
32
+ cache_hit_rate: totals.records > (totals.cache_hit_unknown_requests || 0) ? usageCacheHitRate(totals) : null,
33
+ cache_hit_rate_partial: (totals.cache_hit_unknown_requests || 0) > 0 });
34
+ return { ...snapshot(runtimeUsage), by_provider: Object.fromEntries([...runtimeUsageByProvider].map(([id, totals]) => [id, snapshot(totals)])) };
35
+ }
31
36
 
32
37
  export function usageLoggingStats() {
33
38
  return { pending_records: pendingRecords, pending_bytes: pendingBytes, dropped_records: droppedRecords,
@@ -186,14 +191,17 @@ function scheduleUsageWriteDrain() {
186
191
  export function recordUsage(record) {
187
192
  if (!record) return Promise.resolve();
188
193
  const usage = record.usage || {};
194
+ const { cached, unknown, invalid } = usageCacheEvidence(usage);
189
195
  const provider = usageProvider(record), label = runtimeUsageByProvider.has(provider) || runtimeUsageByProvider.size < 16 ? provider : "other";
190
196
  if (!runtimeUsageByProvider.has(label)) runtimeUsageByProvider.set(label, { records: 0, input_tokens: 0, cached_input_tokens: 0, output_tokens: 0, partial_records: 0 });
191
197
  for (const totals of [runtimeUsage, runtimeUsageByProvider.get(label)]) {
192
198
  totals.records++;
193
- for (const [target, value] of [["input_tokens", usage.input_tokens], ["cached_input_tokens", cacheReadTokens(usage)], ["output_tokens", usage.output_tokens]]) {
199
+ for (const [target, value] of [["input_tokens", usage.input_tokens], ["cached_input_tokens", cached], ["output_tokens", usage.output_tokens]]) {
194
200
  if (Number.isFinite(value) && value >= 0) totals[target] += value;
195
201
  }
196
- if (!Number.isFinite(usage.input_tokens) || !Number.isFinite(usage.output_tokens) || cacheReadTokens(usage) === undefined) totals.partial_records++;
202
+ if (!Number.isFinite(usage.input_tokens) || !Number.isFinite(usage.output_tokens) || cached === undefined) totals.partial_records++;
203
+ if (unknown) totals.cache_hit_unknown_requests = (totals.cache_hit_unknown_requests || 0) + 1;
204
+ if (invalid) totals.cache_hit_invalid_requests = (totals.cache_hit_invalid_requests || 0) + 1;
197
205
  }
198
206
  if (process.env.CCDX_DISABLE_USAGE === "1") return Promise.resolve();
199
207
  const filePath = usageLogPath();
@@ -320,13 +328,7 @@ export function summarizeUsage(records, { provider = "" } = {}) {
320
328
  const modelTotals = summary.byModel[model];
321
329
  modelTotals.requests += 1;
322
330
  addUsageTotals(modelTotals, record.usage);
323
- const input = record.usage?.input_tokens;
324
- const cached = cacheReadTokens(record.usage || {});
325
- const cacheCounts = [record.usage?.cached_input_tokens, record.usage?.cache_read_input_tokens];
326
- const unknown = !Number.isFinite(input) || input < 0 || !Number.isFinite(cached) || cached < 0 || cached > input;
327
- const invalid = (input != null && (!Number.isFinite(input) || input < 0))
328
- || cacheCounts.some(value => value != null && (!Number.isFinite(value) || value < 0))
329
- || (Number.isFinite(input) && Number.isFinite(cached) && cached > input);
331
+ const { unknown, invalid } = usageCacheEvidence(record.usage || {});
330
332
  const qualified = `${source} / ${model}`;
331
333
  if (!Object.hasOwn(summary.bySourceModel, qualified)) summary.bySourceModel[qualified] = { requests: 0 };
332
334
  const sourceTotals = summary.bySourceModel[qualified];
@@ -424,3 +426,12 @@ export function usageCacheHitRate(usage = {}) {
424
426
  || !Number.isFinite(cached) || cached < 0 || cached > input) return null;
425
427
  return cached / input;
426
428
  }
429
+
430
+ function usageCacheEvidence(usage) {
431
+ const input = usage.input_tokens, cached = cacheReadTokens(usage);
432
+ const unknown = !Number.isFinite(input) || input < 0 || !Number.isFinite(cached) || cached < 0 || cached > input;
433
+ const invalid = (input != null && (!Number.isFinite(input) || input < 0))
434
+ || [usage.cached_input_tokens, usage.cache_read_input_tokens].some(value => value != null && (!Number.isFinite(value) || value < 0))
435
+ || (Number.isFinite(input) && Number.isFinite(cached) && cached > input);
436
+ return { cached, unknown, invalid };
437
+ }