@alexgreensh/token-optimizer 5.13.68 → 5.13.70
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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/PRIVACY.md +4 -0
- package/hooks/hooks.json +11 -1
- package/hooks/module_runner.py +4 -1
- package/hooks/posttooluse_runner.py +44 -48
- package/hooks/sessionstart_runner.py +24 -5
- package/hooks/stop_runner.py +6 -6
- package/package.json +1 -1
- package/skills/fleet-auditor/references/fleet-systems.md +38 -0
- package/skills/fleet-auditor/scripts/fleet.py +63 -92
- package/skills/fleet-auditor/scripts/fleet_base.py +106 -0
- package/skills/fleet-auditor/scripts/fleet_cursor_adapter.py +376 -0
- package/skills/token-coach/SKILL.md +21 -23
- package/skills/token-dashboard/SKILL.md +5 -4
- package/skills/token-optimizer/SKILL.md +1 -1
- package/skills/token-optimizer/assets/dashboard.html +492 -551
- package/skills/token-optimizer/assets/savings_story.js +661 -0
- package/skills/token-optimizer/pricing/prices.json +1 -0
- package/skills/token-optimizer/references/cli-reference.md +1 -1
- package/skills/token-optimizer/references/cursor-workflow.md +1 -1
- package/skills/token-optimizer/references/implementation-playbook.md +3 -0
- package/skills/token-optimizer/references/phase0-setup.md +1 -1
- package/skills/token-optimizer/references/presentation-workflow.md +1 -1
- package/skills/token-optimizer/scripts/_measure/__init__.py +3 -1
- package/skills/token-optimizer/scripts/_measure/archive_health.py +14 -0
- package/skills/token-optimizer/scripts/_measure/archive_void_codex.py +163 -0
- package/skills/token-optimizer/scripts/_measure/archive_void_evidence.py +165 -0
- package/skills/token-optimizer/scripts/_measure/audit.py +27 -135
- package/skills/token-optimizer/scripts/_measure/baseline_provenance.py +339 -0
- package/skills/token-optimizer/scripts/_measure/cache_policy.py +261 -581
- package/skills/token-optimizer/scripts/_measure/checkpoint_direction.py +97 -0
- package/skills/token-optimizer/scripts/_measure/checkpoint_retention.py +20 -0
- package/skills/token-optimizer/scripts/_measure/cli.py +98 -8
- package/skills/token-optimizer/scripts/_measure/codex_quality.py +246 -0
- package/skills/token-optimizer/scripts/_measure/compaction_survival.py +158 -0
- package/skills/token-optimizer/scripts/_measure/compression_fixture_void.py +147 -0
- package/skills/token-optimizer/scripts/_measure/compression_scan_checkpoint.py +72 -0
- package/skills/token-optimizer/scripts/_measure/context_reset_marker.py +64 -0
- package/skills/token-optimizer/scripts/_measure/continuity.py +64 -118
- package/skills/token-optimizer/scripts/_measure/cost_per_message_trend.py +40 -0
- package/skills/token-optimizer/scripts/_measure/counted_cap.py +28 -0
- package/skills/token-optimizer/scripts/_measure/counted_orphans.py +190 -0
- package/skills/token-optimizer/scripts/_measure/counted_position.py +20 -0
- package/skills/token-optimizer/scripts/_measure/counted_pricing_v5.py +267 -0
- package/skills/token-optimizer/scripts/_measure/counted_subagents.py +371 -0
- package/skills/token-optimizer/scripts/_measure/coverage_report.py +285 -0
- package/skills/token-optimizer/scripts/_measure/daemon.py +61 -94
- package/skills/token-optimizer/scripts/_measure/dashboard.py +149 -187
- package/skills/token-optimizer/scripts/_measure/dashboard_heal_claim.py +36 -0
- package/skills/token-optimizer/scripts/_measure/dashboard_history.py +79 -0
- package/skills/token-optimizer/scripts/_measure/evidence_parallel.py +95 -0
- package/skills/token-optimizer/scripts/_measure/feature_health.py +256 -0
- package/skills/token-optimizer/scripts/_measure/file_refetch.py +250 -0
- package/skills/token-optimizer/scripts/_measure/first_call_context.py +216 -0
- package/skills/token-optimizer/scripts/_measure/first_read_outcomes.py +261 -0
- package/skills/token-optimizer/scripts/_measure/first_read_revive.py +137 -0
- package/skills/token-optimizer/scripts/_measure/fixture_context.py +65 -0
- package/skills/token-optimizer/scripts/_measure/headline.py +100 -0
- package/skills/token-optimizer/scripts/_measure/holdout_fallback.py +96 -0
- package/skills/token-optimizer/scripts/_measure/holdout_report.py +125 -0
- package/skills/token-optimizer/scripts/_measure/keepwarm_economics.py +201 -0
- package/skills/token-optimizer/scripts/_measure/keepwarm_fork.py +140 -0
- package/skills/token-optimizer/scripts/_measure/keepwarm_guard.py +35 -0
- package/skills/token-optimizer/scripts/_measure/keepwarm_guard_server.py +85 -0
- package/skills/token-optimizer/scripts/_measure/keepwarm_linux.py +121 -0
- package/skills/token-optimizer/scripts/_measure/keepwarm_prefix.py +143 -0
- package/skills/token-optimizer/scripts/_measure/keepwarm_response_filter.py +84 -0
- package/skills/token-optimizer/scripts/_measure/keepwarm_safety.py +256 -0
- package/skills/token-optimizer/scripts/_measure/lean_resume_receivers.py +260 -0
- package/skills/token-optimizer/scripts/_measure/lean_resume_threshold.py +76 -0
- package/skills/token-optimizer/scripts/_measure/lease_candidate_cleanup.py +82 -0
- package/skills/token-optimizer/scripts/_measure/lifecycle.py +59 -168
- package/skills/token-optimizer/scripts/_measure/mcp_archive_tripwire.py +120 -0
- package/skills/token-optimizer/scripts/_measure/mod_action_booking.py +178 -0
- package/skills/token-optimizer/scripts/_measure/mod_compaction_booking.py +276 -0
- package/skills/token-optimizer/scripts/_measure/mod_fresh_booking.py +105 -0
- package/skills/token-optimizer/scripts/_measure/output_reread.py +629 -0
- package/skills/token-optimizer/scripts/_measure/own_price_card.py +268 -0
- package/skills/token-optimizer/scripts/_measure/periphery_exposure.py +85 -0
- package/skills/token-optimizer/scripts/_measure/pricing.py +152 -87
- package/skills/token-optimizer/scripts/_measure/quality_archive.py +159 -215
- package/skills/token-optimizer/scripts/_measure/quality_checkpoint.py +173 -0
- package/skills/token-optimizer/scripts/_measure/quality_continuity.py +43 -0
- package/skills/token-optimizer/scripts/_measure/rework_metrics.py +194 -0
- package/skills/token-optimizer/scripts/_measure/routing_period.py +48 -0
- package/skills/token-optimizer/scripts/_measure/savings.py +451 -933
- package/skills/token-optimizer/scripts/_measure/savings_story.py +187 -0
- package/skills/token-optimizer/scripts/_measure/session_best.py +24 -0
- package/skills/token-optimizer/scripts/_measure/session_effect.py +557 -0
- package/skills/token-optimizer/scripts/_measure/session_flush_lock.py +75 -0
- package/skills/token-optimizer/scripts/_measure/session_store_spool.py +220 -0
- package/skills/token-optimizer/scripts/_measure/sessions.py +154 -216
- package/skills/token-optimizer/scripts/_measure/setup_attachment_counter.py +196 -0
- package/skills/token-optimizer/scripts/_measure/setup_budget_monitor.py +180 -0
- package/skills/token-optimizer/scripts/_measure/setup_connector_ledger.py +126 -0
- package/skills/token-optimizer/scripts/_measure/setup_step.py +220 -0
- package/skills/token-optimizer/scripts/_measure/status_bar_lock.py +117 -0
- package/skills/token-optimizer/scripts/_measure/structural_archives.py +79 -0
- package/skills/token-optimizer/scripts/_measure/structural_dedupe.py +91 -0
- package/skills/token-optimizer/scripts/_measure/structural_ledger.py +418 -0
- package/skills/token-optimizer/scripts/_measure/structural_listing.py +163 -0
- package/skills/token-optimizer/scripts/_measure/structural_report.py +339 -0
- package/skills/token-optimizer/scripts/_measure/structural_seed.py +164 -0
- package/skills/token-optimizer/scripts/_measure/structural_value.py +248 -0
- package/skills/token-optimizer/scripts/_measure/structure_funnel.py +97 -0
- package/skills/token-optimizer/scripts/_measure/timestamp_cache.py +11 -0
- package/skills/token-optimizer/scripts/_measure/token_type_split.py +29 -0
- package/skills/token-optimizer/scripts/_measure/transcript_backfill.py +419 -0
- package/skills/token-optimizer/scripts/_measure/transcript_product.py +228 -0
- package/skills/token-optimizer/scripts/_measure/transcript_stream.py +279 -0
- package/skills/token-optimizer/scripts/_measure/trends.py +44 -185
- package/skills/token-optimizer/scripts/_measure/ttl_period.py +6 -0
- package/skills/token-optimizer/scripts/_measure/upgrade_drain_control.py +287 -0
- package/skills/token-optimizer/scripts/_measure/weekly_activity.py +69 -0
- package/skills/token-optimizer/scripts/activity_tracker.py +4 -33
- package/skills/token-optimizer/scripts/antigravity_install.py +6 -0
- package/skills/token-optimizer/scripts/archive_result.py +15 -19
- package/skills/token-optimizer/scripts/archive_verify.py +165 -0
- package/skills/token-optimizer/scripts/bash_compress.py +22 -83
- package/skills/token-optimizer/scripts/bash_compress_hook.py +137 -1
- package/skills/token-optimizer/scripts/bash_search_results.py +43 -0
- package/skills/token-optimizer/scripts/checkpoint_state.py +2 -2
- package/skills/token-optimizer/scripts/cloud_kit.py +3 -6
- package/skills/token-optimizer/scripts/codemap.py +274 -0
- package/skills/token-optimizer/scripts/codemap_hint.py +153 -0
- package/skills/token-optimizer/scripts/codemap_index.py +656 -0
- package/skills/token-optimizer/scripts/codemap_ledger.py +309 -0
- package/skills/token-optimizer/scripts/codemap_reread.py +161 -0
- package/skills/token-optimizer/scripts/codex_doctor.py +9 -1
- package/skills/token-optimizer/scripts/codex_log_index.py +34 -15
- package/skills/token-optimizer/scripts/codex_session.py +16 -216
- package/skills/token-optimizer/scripts/compression_backfill.py +4 -35
- package/skills/token-optimizer/scripts/context_intel.py +5 -3
- package/skills/token-optimizer/scripts/copilot_install.py +6 -0
- package/skills/token-optimizer/scripts/coverage_funnel.py +261 -0
- package/skills/token-optimizer/scripts/credential_patterns.py +4 -19
- package/skills/token-optimizer/scripts/credential_url_patterns.py +42 -0
- package/skills/token-optimizer/scripts/cursor_audit.py +723 -0
- package/skills/token-optimizer/scripts/cursor_bridge_checkpoint.py +213 -0
- package/skills/token-optimizer/scripts/cursor_bridge_payload.py +170 -0
- package/skills/token-optimizer/scripts/cursor_bridge_rewrite.py +106 -0
- package/skills/token-optimizer/scripts/cursor_bridge_rollup.py +115 -0
- package/skills/token-optimizer/scripts/cursor_coach.py +485 -0
- package/skills/token-optimizer/scripts/cursor_doctor.py +89 -9
- package/skills/token-optimizer/scripts/cursor_hook_bridge.py +393 -276
- package/skills/token-optimizer/scripts/cursor_install.py +118 -19
- package/skills/token-optimizer/scripts/cursor_quality.py +457 -0
- package/skills/token-optimizer/scripts/cursor_read_cache.py +597 -0
- package/skills/token-optimizer/scripts/cursor_session.py +26 -5
- package/skills/token-optimizer/scripts/cursor_state.py +8 -0
- package/skills/token-optimizer/scripts/cursor_statusline.py +372 -0
- package/skills/token-optimizer/scripts/cursor_thrash.py +78 -0
- package/skills/token-optimizer/scripts/cursor_transcript.py +223 -0
- package/skills/token-optimizer/scripts/dashboard_assets.py +21 -0
- package/skills/token-optimizer/scripts/deterministic_candidates.py +2 -10
- package/skills/token-optimizer/scripts/devin_source.py +19 -4
- package/skills/token-optimizer/scripts/devin_verify.py +13 -6
- package/skills/token-optimizer/scripts/grok_install.py +6 -0
- package/skills/token-optimizer/scripts/heal_report.py +7 -6
- package/skills/token-optimizer/scripts/hermes_doctor.py +12 -1
- package/skills/token-optimizer/scripts/hermes_install.py +10 -1
- package/skills/token-optimizer/scripts/hermes_session.py +14 -136
- package/skills/token-optimizer/scripts/hint_paths.py +21 -0
- package/skills/token-optimizer/scripts/holdout.py +136 -0
- package/skills/token-optimizer/scripts/hook_runtime.py +1 -0
- package/skills/token-optimizer/scripts/hook_skip_log.py +89 -0
- package/skills/token-optimizer/scripts/large_transcripts.py +31 -0
- package/skills/token-optimizer/scripts/lean_resume_carry.py +518 -0
- package/skills/token-optimizer/scripts/measure.py +36 -78
- package/skills/token-optimizer/scripts/post_run_classify.py +349 -0
- package/skills/token-optimizer/scripts/preserved_reinject.py +54 -0
- package/skills/token-optimizer/scripts/read_cache.py +99 -100
- package/skills/token-optimizer/scripts/reset_epoch.py +3 -3
- package/skills/token-optimizer/scripts/session_store.py +49 -99
- package/skills/token-optimizer/scripts/session_store_guard.py +75 -0
- package/skills/token-optimizer/scripts/settings_backup.py +379 -0
- package/skills/token-optimizer/scripts/shipped_hook_templates.py +1 -0
- package/skills/token-optimizer/scripts/statusline.js +1 -1
- package/skills/token-optimizer/scripts/structural.py +25 -0
- package/skills/token-optimizer/scripts/structure_map.py +4 -26
- package/skills/token-optimizer/scripts/thrash_guard.py +10 -5
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
@media (prefers-reduced-motion: reduce) {
|
|
21
21
|
*, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
|
|
22
22
|
}
|
|
23
|
-
|
|
24
23
|
/* ========== THEME TOKENS ==========
|
|
25
24
|
Dark is the DEFAULT and is pixel-unchanged: every value below is the exact
|
|
26
25
|
literal the dashboard already shipped, just lifted into a named token. The
|
|
@@ -135,7 +134,6 @@
|
|
|
135
134
|
--glow-sm: 0 0 10px var(--c-accent-glow);
|
|
136
135
|
--glow-text: 0 0 8px rgba(0, 240, 255, 0.6);
|
|
137
136
|
}
|
|
138
|
-
|
|
139
137
|
/* ========== LIGHT THEME ==========
|
|
140
138
|
Same visual language (cyan-accent technical dashboard), inverted lightness.
|
|
141
139
|
Activation order (no FOUC, see inline boot script in <head>):
|
|
@@ -274,7 +272,7 @@ th, td { padding: 10px !important; }
|
|
|
274
272
|
gap: 8px; font-family: var(--font-mono); font-size: 14px;
|
|
275
273
|
color: var(--c-accent-cyan); user-select: none; padding: 6px 0;
|
|
276
274
|
}
|
|
277
|
-
.fold > summary::-webkit-details-marker { display: none; }
|
|
275
|
+
.fold > summary { position:relative; min-height:40px; } .fold__body { opacity:1; transform:translateY(0); transition:opacity .18s ease-out, transform .18s ease-out; } @starting-style { .fold[open] > .fold__body { opacity:0; transform:translateY(4px); } } .fold > summary::-webkit-details-marker { display: none; }
|
|
278
276
|
.fold > summary::before {
|
|
279
277
|
content: "\25B8"; font-size: 11px; display: inline-block;
|
|
280
278
|
transition: transform .15s ease;
|
|
@@ -396,13 +394,12 @@ h1, h2, h3, h4 { font-weight: 400; }
|
|
|
396
394
|
text-transform: uppercase;
|
|
397
395
|
letter-spacing: 0.1em;
|
|
398
396
|
font-size: 15px;
|
|
399
|
-
border-
|
|
397
|
+
border-radius: 6px;
|
|
400
398
|
}
|
|
401
399
|
|
|
402
400
|
.nav-item:hover, .nav-item.active {
|
|
403
401
|
color: var(--c-text-main);
|
|
404
402
|
background: var(--c-accent-soft);
|
|
405
|
-
border-left-color: var(--c-accent-cyan);
|
|
406
403
|
text-shadow: var(--glow-text);
|
|
407
404
|
}
|
|
408
405
|
|
|
@@ -431,7 +428,7 @@ h1, h2, h3, h4 { font-weight: 400; }
|
|
|
431
428
|
|
|
432
429
|
.user-profile i {
|
|
433
430
|
font-family: var(--font-mono);
|
|
434
|
-
font-style:
|
|
431
|
+
font-style: normal;
|
|
435
432
|
color: var(--c-accent-cyan);
|
|
436
433
|
}
|
|
437
434
|
|
|
@@ -1375,9 +1372,8 @@ input:checked + .slider:before {
|
|
|
1375
1372
|
.metric-unit {
|
|
1376
1373
|
font-family: var(--font-sans);
|
|
1377
1374
|
font-weight: 500;
|
|
1378
|
-
font-size:
|
|
1379
|
-
color: var(--c-text-
|
|
1380
|
-
letter-spacing: 0.03em;
|
|
1375
|
+
font-size: 22px;
|
|
1376
|
+
color: var(--c-text-main);
|
|
1381
1377
|
}
|
|
1382
1378
|
.metric-sub.tight {
|
|
1383
1379
|
font-size: 18px;
|
|
@@ -1392,18 +1388,17 @@ input:checked + .slider:before {
|
|
|
1392
1388
|
.ts-divider { height: 1px; background: var(--c-border); margin: var(--s-4) 0 var(--s-3); }
|
|
1393
1389
|
|
|
1394
1390
|
.ts-section-label {
|
|
1395
|
-
font-family: var(--font-
|
|
1396
|
-
font-size:
|
|
1397
|
-
|
|
1398
|
-
text-
|
|
1399
|
-
letter-spacing: 0.08em;
|
|
1391
|
+
font-family: var(--font-sans);
|
|
1392
|
+
font-size: 17px;
|
|
1393
|
+
font-weight: 600;
|
|
1394
|
+
color: var(--c-text-main);
|
|
1400
1395
|
margin-bottom: var(--s-2);
|
|
1401
1396
|
display: flex;
|
|
1402
1397
|
justify-content: space-between;
|
|
1403
1398
|
align-items: baseline;
|
|
1404
1399
|
gap: var(--s-3);
|
|
1405
1400
|
}
|
|
1406
|
-
.ts-section-label .muted {
|
|
1401
|
+
.ts-section-label .muted { color: var(--c-text-main); font-weight: 400; font-size: 14px; }
|
|
1407
1402
|
|
|
1408
1403
|
/* spent-vs-saved combined bar: one row, two proportional segments. */
|
|
1409
1404
|
.sv-bar {
|
|
@@ -1424,9 +1419,9 @@ input:checked + .slider:before {
|
|
|
1424
1419
|
|
|
1425
1420
|
.ts-foot {
|
|
1426
1421
|
margin-top: var(--s-4);
|
|
1427
|
-
font-family: var(--font-
|
|
1428
|
-
font-size:
|
|
1429
|
-
color: var(--c-text-
|
|
1422
|
+
font-family: var(--font-sans);
|
|
1423
|
+
font-size: 15px;
|
|
1424
|
+
color: var(--c-text-main);
|
|
1430
1425
|
line-height: 1.6;
|
|
1431
1426
|
text-wrap: pretty;
|
|
1432
1427
|
}
|
|
@@ -1546,7 +1541,6 @@ input:checked + .slider:before {
|
|
|
1546
1541
|
.rec-callout {
|
|
1547
1542
|
background: var(--c-surface);
|
|
1548
1543
|
border: 1px solid var(--c-border);
|
|
1549
|
-
border-left: 3px solid var(--c-accent-cyan);
|
|
1550
1544
|
border-radius: 8px;
|
|
1551
1545
|
padding: var(--s-3) var(--s-4);
|
|
1552
1546
|
margin-bottom: var(--s-2);
|
|
@@ -1714,6 +1708,99 @@ input:checked + .slider:before {
|
|
|
1714
1708
|
border: 1px solid var(--c-border);
|
|
1715
1709
|
}
|
|
1716
1710
|
|
|
1711
|
+
/* ========== SAVINGS STORY (U9, assets/savings_story.js) ==========
|
|
1712
|
+
Card titles are headings (no small-caps labels above them). Sans for words,
|
|
1713
|
+
mono only for standalone figures; numbers inside sentences use the sans face
|
|
1714
|
+
with tabular figures. Secondary lines stay in --c-text-main for readability. */
|
|
1715
|
+
html { -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums; } h1,h2,h3 { text-wrap: balance; } p,li { text-wrap: pretty; } .st-enter .st > * { animation: st-enter .32s ease-out both; } .st-enter .st > :nth-child(2) { animation-delay:90ms; } .st-enter .st > :nth-child(3) { animation-delay:180ms; } .st-enter .st > :nth-child(4) { animation-delay:270ms; } .st-enter .st > :nth-child(5) { animation-delay:360ms; } .st-enter .st > :nth-child(6) { animation-delay:450ms; } @keyframes st-enter { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:translateY(0); } } @media (prefers-reduced-motion:reduce) { .st-enter .st > * { animation:none; } .fold__body { transition:none; } .fold > summary::before { transition:none; } } .st { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-3); margin-bottom: var(--s-3); } .st .card.wide { grid-column: auto; }
|
|
1716
|
+
.st .card { padding: var(--s-4); border: 0; box-shadow: 0 0 0 1px rgba(255,255,255,.09), 0 2px 6px rgba(0,0,0,.12); } [data-theme="light"] .st .card { box-shadow: 0 0 0 1px rgba(0,0,0,.08), 0 2px 5px rgba(0,0,0,.06); } .st .st-table { box-shadow: 0 0 0 1px rgba(251,191,36,.4), 0 0 44px rgba(251,191,36,.1); }
|
|
1717
|
+
.st .st-limits-card { padding: 12px var(--s-4); } .st-limits__top { display:flex; align-items:baseline; flex-wrap:wrap; gap: 8px 24px; } .st-limits__bottom { display:flex; align-items:center; justify-content:space-between; gap:16px; font-size:14px; } .st-limits__bottom .fold { margin:0; } .st-transform .st-mega__item { gap:0; } .st-transform .st-lead { max-width:65ch; margin-top:8px; } .st-transform .fold, .st-hero .fold { margin-top:0; } .st-table__body > .st-mega__item { margin-top:0; } .st-reread__body { display:flex; align-items:center; gap:32px; } .st-reread__body .st-lead { margin:0; } .st-h { font: 600 20px/1.3 var(--font-sans); color: var(--c-text-main); display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-2) 12px; }
|
|
1718
|
+
.st-tag { font: 500 13px/1 var(--font-sans); letter-spacing: 0.01em; color: var(--c-text-main); border: 1px solid var(--c-border-strong); border-radius: 999px; padding: 5px 10px; }
|
|
1719
|
+
.st-num { font-family: var(--font-sans); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--c-accent-cyan); white-space: nowrap; }
|
|
1720
|
+
.st-v { font-family: var(--font-mono); font-variant-numeric: tabular-nums; color: var(--c-text-main); text-align: right; white-space: nowrap; }
|
|
1721
|
+
.st-lead { font-size: 17px; line-height: 1.6; color: var(--c-text-main); margin-top: var(--s-3); max-width: 60ch; text-wrap: pretty; }
|
|
1722
|
+
.st-lead strong { font-weight: 600; }
|
|
1723
|
+
.st-big { font: 400 22px/1.45 var(--font-sans); color: var(--c-text-main); margin-top: var(--s-3); text-wrap: pretty; }
|
|
1724
|
+
.st-big .st-num { font-size: 34px; }
|
|
1725
|
+
.st-hero { padding: var(--s-4) !important; }
|
|
1726
|
+
/* The big numbers: the Tokens Saved card's display treatment (thin mono,
|
|
1727
|
+
saturated savings green or accent cyan, soft glow in dark mode). */
|
|
1728
|
+
.st-mega__row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s-3) var(--s-6, 48px); margin: var(--s-3) 0 12px; }
|
|
1729
|
+
.st-mega__item { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
|
|
1730
|
+
.st-mega__item--card { margin-top: var(--s-3); }
|
|
1731
|
+
.st-mega { font: 300 clamp(72px, 8.4vw, 116px)/0.9 var(--font-mono); letter-spacing: -0.035em; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|
1732
|
+
.st-mega--usd { color: var(--c-savings); text-shadow: 0 0 26px rgba(74,222,128,0.34), 0 0 2px rgba(74,222,128,0.4); }
|
|
1733
|
+
.st-mega--tok { color: var(--c-accent-cyan); text-shadow: 0 0 26px rgba(0,240,255,0.32), 0 0 2px rgba(0,240,255,0.4); }
|
|
1734
|
+
.st-mega--card { font-size: clamp(60px, 5.6vw, 84px); }
|
|
1735
|
+
.st-mega__unit { font: 500 19px/1.3 var(--font-sans); color: var(--c-text-main); }
|
|
1736
|
+
[data-theme="light"] .st-mega { text-shadow: none; }
|
|
1737
|
+
.st-bar { display: flex; gap: 3px; height: 8px; border-radius: 4px; overflow: hidden; opacity: 0.85; }
|
|
1738
|
+
.st-bar__m { background: var(--c-savings); border-radius: 7px 0 0 7px; }
|
|
1739
|
+
.st-bar__e { background: repeating-linear-gradient(135deg, var(--c-savings) 0 3px, transparent 3px 7px); box-shadow: inset 0 0 0 1.5px var(--c-savings); border-radius: 0 7px 7px 0; }
|
|
1740
|
+
.st-bands { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2) var(--s-5); margin-top: var(--s-3); }
|
|
1741
|
+
.st-legend { display: flex; align-items: center; gap: 10px; font: 600 17px/1.3 var(--font-sans); color: var(--c-text-main); }
|
|
1742
|
+
.st-legend .st-v { margin-left: auto; font-size: 19px; font-weight: 500; }
|
|
1743
|
+
.st-sw { width: 14px; height: 14px; border-radius: 3px; flex: none; }
|
|
1744
|
+
.st-sw.st-m { background: var(--c-savings); }
|
|
1745
|
+
.st-sw.st-e { background: repeating-linear-gradient(135deg, var(--c-savings) 0 2px, transparent 2px 4px); box-shadow: inset 0 0 0 1.5px var(--c-savings); }
|
|
1746
|
+
.st-rows { list-style: none; margin-top: var(--s-2); border-top: 1px solid var(--c-border); }
|
|
1747
|
+
.st-rows li { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s-3); padding: 9px 0; border-bottom: 1px solid var(--c-border); font-size: 16px; line-height: 1.4; color: var(--c-text-main); }
|
|
1748
|
+
.st-rows--card { margin-top: var(--s-3); }
|
|
1749
|
+
.st-sub { display: block; font: 400 14px/1.5 var(--font-sans); color: var(--c-text-main); margin-top: 2px; }
|
|
1750
|
+
.st-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: var(--s-3); }
|
|
1751
|
+
.st-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--s-5); }
|
|
1752
|
+
.st-mega__row--hero { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; gap: var(--s-4); }
|
|
1753
|
+
.st-mega__row--hero .st-mega { font-size: clamp(60px, 6.2vw, 96px); }
|
|
1754
|
+
.st-mega__note { font: 600 17px/1.3 var(--font-sans); color: var(--c-savings); }
|
|
1755
|
+
.st-mega--route { color: var(--c-info); text-shadow: 0 0 26px rgba(96,165,250,0.36), 0 0 2px rgba(96,165,250,0.4); }
|
|
1756
|
+
.st-mega--warm { color: var(--c-warning-2); text-shadow: 0 0 28px rgba(251,191,36,0.38), 0 0 2px rgba(251,191,36,0.45); }
|
|
1757
|
+
.st-table { border: 0; box-shadow: 0 0 0 1px rgba(251,191,36,0.35), 0 0 44px rgba(251,191,36,0.10); }
|
|
1758
|
+
[data-theme="light"] .st-table { box-shadow: 0 0 0 1px rgba(150,95,0,.3), 0 2px 5px rgba(0,0,0,.06); }
|
|
1759
|
+
.st-table__body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: var(--s-3) var(--s-5); align-items: center; }
|
|
1760
|
+
.st-table__rows .st-rows--card { margin-top: 0; }
|
|
1761
|
+
.st-bar__title { font: 600 17px/1.3 var(--font-sans); color: var(--c-text-main); margin: var(--s-4) 0 var(--s-2); }
|
|
1762
|
+
.st-grid > :last-child:nth-child(odd) { grid-column: 1 / -1; }
|
|
1763
|
+
.st-ratio__track { display: block; height: 12px; border-radius: 6px; background: var(--c-elev-3); overflow: hidden; }
|
|
1764
|
+
.st-ratio__carry { display: block; height: 100%; border-radius: 6px; background: var(--c-accent-cyan); }
|
|
1765
|
+
.st-quality { margin-top: var(--s-3); max-width: 640px; }
|
|
1766
|
+
.st-cov { font-size: 17px; line-height: 1.6; color: var(--c-text-main); padding: 0 var(--s-1); max-width: 90ch; }
|
|
1767
|
+
.st-morerow { display: flex; flex-wrap: wrap; gap: 0 var(--s-4); padding: var(--s-2) var(--s-1) 0; border-top: 1px solid var(--c-border); margin-bottom: var(--s-4); }
|
|
1768
|
+
.st-morerow > .fold { margin-top: 0; }
|
|
1769
|
+
.st-morerow > .fold[open] { flex-basis: 100%; }
|
|
1770
|
+
.st-morerow > .fold > summary { font-size: 15px; }
|
|
1771
|
+
.st-morerow .fold__body { max-width: none; }
|
|
1772
|
+
.st-health { margin-top: var(--s-3); }
|
|
1773
|
+
.st-gap { margin-top: var(--s-4); }
|
|
1774
|
+
.st-limits { display: grid; gap: 10px; flex: 1 1 520px; min-width: 0; }
|
|
1775
|
+
.st-limit { display: grid; grid-template-columns: max-content minmax(120px, 1fr) max-content max-content; align-items: center; gap: 8px 20px; font: 500 15px/1.3 var(--font-sans); color: var(--c-text-main); }
|
|
1776
|
+
.st-limit__name { font-weight: 600; }
|
|
1777
|
+
.st-limit__meter { position: relative; height: 10px; border-radius: 999px; overflow: hidden; background: var(--c-elev-3); box-shadow: inset 0 0 0 1px var(--c-border); }
|
|
1778
|
+
.st-limit__ghost, .st-limit__fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; transition-property: width; transition-duration: 600ms; transition-timing-function: cubic-bezier(0.2, 0, 0, 1); }
|
|
1779
|
+
.st-limit__ghost { background: repeating-linear-gradient(135deg, var(--c-warning-2) 0 3px, transparent 3px 7px); opacity: 0.7; }
|
|
1780
|
+
.st-limit__fill { background: var(--c-accent-cyan); box-shadow: 0 0 10px var(--c-accent-cyan); }
|
|
1781
|
+
.st-limit__stat { display: inline-flex; align-items: baseline; gap: 6px; white-space: nowrap; }
|
|
1782
|
+
.st-limit__stat--over { color: var(--c-warning-2); font-weight: 600; }
|
|
1783
|
+
@media (max-width: 720px) { .st-limit { grid-template-columns: 1fr max-content max-content; } .st-limit__meter { grid-column: 1 / -1; grid-row: 2; } }
|
|
1784
|
+
.st-mega__per { font: 500 clamp(20px, 2vw, 26px)/1 var(--font-sans); letter-spacing: 0; text-shadow: none; color: var(--c-text-main); }
|
|
1785
|
+
.st-limit__used, .st-limit__num { font: 500 24px/1 var(--font-mono); font-variant-numeric: tabular-nums; text-shadow: 0 0 18px currentColor; } .st-limit__used { color: var(--c-accent-cyan); }
|
|
1786
|
+
.st-limit__num { color: var(--c-warning-2); }
|
|
1787
|
+
@media (max-width: 900px) {
|
|
1788
|
+
.st-grid, .st-bands, .st-mega__row--hero, .st-table__body, .st-cols { grid-template-columns: 1fr; }
|
|
1789
|
+
.st-grid > :last-child:nth-child(odd) { grid-column: auto; }
|
|
1790
|
+
.st-mega__row--hero .st-mega { font-size: 72px; }
|
|
1791
|
+
}
|
|
1792
|
+
@media (max-width: 520px) {
|
|
1793
|
+
.st-limits__bottom, .st-reread__body { flex-wrap:wrap; } .st-limits__bottom { gap:0 16px; } .st-reread__body { gap:8px; }
|
|
1794
|
+
.st .card { padding: var(--s-3); }
|
|
1795
|
+
.st-hero { padding: var(--s-4) var(--s-3) var(--s-3) !important; }
|
|
1796
|
+
.st-hero .st-rows { display: none; }
|
|
1797
|
+
.st-bands { gap: var(--s-2); }
|
|
1798
|
+
.st-mega, .st-mega__row--hero .st-mega { font-size: 64px; }
|
|
1799
|
+
.st-mega--card { font-size: 56px; }
|
|
1800
|
+
.st-mega__row { gap: var(--s-3); }
|
|
1801
|
+
.st-morerow { flex-direction: column; }
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1717
1804
|
/* ========== RESPONSIVE ========== */
|
|
1718
1805
|
@media (max-width: 1024px) {
|
|
1719
1806
|
.layout { grid-template-columns: 200px 1fr; }
|
|
@@ -1728,8 +1815,14 @@ input:checked + .slider:before {
|
|
|
1728
1815
|
padding: var(--s-3);
|
|
1729
1816
|
}
|
|
1730
1817
|
.main-col { padding: var(--s-3); }
|
|
1818
|
+
.nav-col .brand { margin-bottom: var(--s-2); font-size: 20px; }
|
|
1819
|
+
.nav-menu { flex-direction: row; overflow-x: auto; gap: 4px; margin: 0 calc(-1 * var(--s-3)); padding: 0 var(--s-3) 2px; scrollbar-width: none; }
|
|
1820
|
+
.nav-menu::-webkit-scrollbar { display: none; }
|
|
1821
|
+
.nav-menu .nav-item { flex: none; white-space: nowrap; padding: 8px 12px; gap: 8px; }
|
|
1822
|
+
.nav-menu .nav-separator { display: none; }
|
|
1823
|
+
.user-profile { display: none; }
|
|
1731
1824
|
.dashboard-grid { grid-template-columns: 1fr; }
|
|
1732
|
-
.stat-row { grid-template-columns: 1fr; }
|
|
1825
|
+
.stat-row { grid-template-columns: 1fr !important; } /* rows set 3 columns inline */
|
|
1733
1826
|
}
|
|
1734
1827
|
/* ========== HOOK TOGGLES ========== */
|
|
1735
1828
|
.hook-toggle { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
|
|
@@ -2405,8 +2498,31 @@ function memCountSuffix(mr) { return mr && mr.scan_partial ? '+' : ''; }
|
|
|
2405
2498
|
function isNoInstructionHost(data) {
|
|
2406
2499
|
return !!data && (data.runtime === 'cursor' || data.runtime === 'antigravity');
|
|
2407
2500
|
}
|
|
2501
|
+
// U8: the removed pool is split by what it is, never called "fresh" (it holds
|
|
2502
|
+
// resume and output tokens). Old payloads without the split keep one total.
|
|
2503
|
+
function tokenSplitText(h, fmt) {
|
|
2504
|
+
var parts = [];
|
|
2505
|
+
if (h.context_removed_tokens != null) {
|
|
2506
|
+
parts.push('~' + fmt(h.context_removed_tokens || 0) + ' context removed');
|
|
2507
|
+
if (h.output_not_generated_tokens) parts.push('~' + fmt(h.output_not_generated_tokens) + ' output not generated');
|
|
2508
|
+
if (h.reload_avoided_tokens) parts.push('~' + fmt(h.reload_avoided_tokens) + ' reload avoided');
|
|
2509
|
+
} else {
|
|
2510
|
+
parts.push('~' + fmt(h.removed_tokens || 0) + ' removed');
|
|
2511
|
+
}
|
|
2512
|
+
parts.push(h.reread_available ? '~' + fmt(h.reread_tokens || 0) + ' re-reads avoided' : 're-reads unavailable');
|
|
2513
|
+
return parts.join(' · ');
|
|
2514
|
+
}
|
|
2515
|
+
/*@include savings_story.js*//*@include first_call_context.js*/
|
|
2516
|
+
// Feature health card (Health tab): assets/feature_health.js.
|
|
2517
|
+
/*@include feature_health.js*/
|
|
2518
|
+
// Command-output coverage card (Health tab): assets/coverage_funnel.js.
|
|
2519
|
+
/*@include coverage_funnel.js*/
|
|
2520
|
+
// Control-group card (Health tab, shown only when the holdout is on): assets/holdout_card.js.
|
|
2521
|
+
/*@include holdout_card.js*/
|
|
2522
|
+
/*@include keepwarm_health.js*/
|
|
2523
|
+
|
|
2408
2524
|
function hostRefreshHtml(data) {
|
|
2409
|
-
return tcliHtml('<span class="update-cmd">TOKEN_OPTIMIZER_RUNTIME=' + esc(data.runtime) + ' python3 measure.py dashboard</span>');
|
|
2525
|
+
return tcliHtml('<span class="update-cmd">TOKEN_OPTIMIZER_RUNTIME=' + esc(data.runtime) + ' python3 measure.py dashboard --user</span>');
|
|
2410
2526
|
}
|
|
2411
2527
|
function hermesComponentDetails(c) {
|
|
2412
2528
|
function fileSub(x, missing) {
|
|
@@ -2841,7 +2957,7 @@ var DB = (function() {
|
|
|
2841
2957
|
label: 'First-Read Skeleton (serve, not just measure)',
|
|
2842
2958
|
what: "When on, validated CODE cohorts are served a structural skeleton (signatures/imports) on first read instead of the full file. When off, those cohorts are measured only and served full.",
|
|
2843
2959
|
value: "A large first-read code file comes back as a compact API skeleton, with the full content one `expand` away. As of v5.11.27 markdown/prose is NOT skeletoned -- only code.",
|
|
2844
|
-
how: "
|
|
2960
|
+
how: "When enabled, the target is read in full and bounded maps of related files may be added. Outcome comparisons are diagnostic; existing cohort demotions remain in place.",
|
|
2845
2961
|
risk: "Low. Code skeletons preserve structure; the full file is always recoverable. Set TOKEN_OPTIMIZER_FIRST_READ_ACTIVE=0 (or toggle here) to serve full content while keeping measurement.",
|
|
2846
2962
|
env_var: 'TOKEN_OPTIMIZER_FIRST_READ_ACTIVE'
|
|
2847
2963
|
}
|
|
@@ -3131,10 +3247,11 @@ var DB = (function() {
|
|
|
3131
3247
|
memoryExists = true;
|
|
3132
3248
|
}
|
|
3133
3249
|
var barsHtml = vals.map(function(v, i) {
|
|
3250
|
+
if (i === 1 && !memoryExists) return '';
|
|
3134
3251
|
var w = logBar(v);
|
|
3135
3252
|
var fixedClass = i === vals.length - 1 ? ' fixed' : '';
|
|
3136
3253
|
var pctText = (v / ctxWindow * 100).toFixed(1) + '%';
|
|
3137
|
-
var valText =
|
|
3254
|
+
var valText = fn(v) + ' (' + pctText + ')';
|
|
3138
3255
|
return '<div class="bar-row">' +
|
|
3139
3256
|
'<span class="bar-label">' + barLabels[i] + '</span>' +
|
|
3140
3257
|
'<div class="bar-track"><div class="bar-fill' + fixedClass + '" style="width:' + w + '%"></div></div>' +
|
|
@@ -3181,15 +3298,15 @@ var DB = (function() {
|
|
|
3181
3298
|
fn(ctrl) + ' of your ' + fn(total) + ' tokens are controllable. No specific token-saving optimizations identified, but check the behavioral recommendations below.';
|
|
3182
3299
|
}
|
|
3183
3300
|
|
|
3184
|
-
// Component cards (expandable)
|
|
3185
3301
|
var componentData = getComponentDetails(data);
|
|
3186
3302
|
var cardsHtml = '';
|
|
3187
3303
|
componentData.forEach(function(comp, ci) {
|
|
3304
|
+
if (comp.key === 'memory_md' && comp.tokens === 0 && c.memory_md && c.memory_md.exists === false) return;
|
|
3188
3305
|
cardsHtml += '<div class="component-card" data-comp="' + ci + '">' +
|
|
3189
3306
|
'<div class="component-card-header">' +
|
|
3190
3307
|
'<span class="cc-name">' + esc(comp.name) + '</span>' +
|
|
3191
3308
|
'<span class="cc-right">' +
|
|
3192
|
-
'<span class="cc-tokens">' +
|
|
3309
|
+
'<span class="cc-tokens">' + fn(comp.tokens) + ' tokens</span>' +
|
|
3193
3310
|
'<span class="chevron">▾</span></span></div>' +
|
|
3194
3311
|
'<div class="component-card-sub">' + esc(comp.sub) + '</div>' +
|
|
3195
3312
|
'<div class="component-card-detail" id="comp-detail-' + ci + '">' +
|
|
@@ -3475,12 +3592,7 @@ var DB = (function() {
|
|
|
3475
3592
|
var untrackedTokens = (denom > modelTotal) ? (denom - modelTotal) : 0;
|
|
3476
3593
|
var out = '';
|
|
3477
3594
|
if (isCodex) {
|
|
3478
|
-
out += '<p style="font-size:
|
|
3479
|
-
} else if (modelCount <= 1) {
|
|
3480
|
-
var singleModel = Object.keys(modelMix)[0] || 'unknown';
|
|
3481
|
-
out += '<p style="font-size:13px;color:var(--c-text-dim);font-family:var(--font-mono);margin-bottom:var(--s-2);">All sessions use ' + esc(singleModel) + '. Consider defaulting agents to haiku (5x cheaper) or sonnet for data-gathering tasks.</p>';
|
|
3482
|
-
} else {
|
|
3483
|
-
out += '<p style="font-size:13px;color:var(--c-text-dim);font-family:var(--font-mono);margin-bottom:var(--s-2);">Haiku is 5x cheaper for data-gathering. If you see mostly Opus, consider defaulting agents to Sonnet/Haiku.</p>';
|
|
3595
|
+
out += '<p style="font-size:15px;color:var(--c-text-main);margin-bottom:var(--s-2);">Codex model names are read from session logs when available. Unknown future model IDs are shown by name but left unpriced until rates are known.</p>';
|
|
3484
3596
|
}
|
|
3485
3597
|
out += '<div class="model-bar">';
|
|
3486
3598
|
modelOrder.forEach(function(m) {
|
|
@@ -3523,110 +3635,34 @@ var DB = (function() {
|
|
|
3523
3635
|
return out;
|
|
3524
3636
|
}
|
|
3525
3637
|
|
|
3526
|
-
//
|
|
3527
|
-
// usage bar + footer. Hoisted to module scope so BOTH renderTrends and
|
|
3528
|
-
// renderSavings render it identically without duplicating the body logic.
|
|
3529
|
-
// Reads trends data from the global `data`; the savings object is passed as
|
|
3530
|
-
// `savings` (data.savings in renderTrends, the in-scope `s` in renderSavings).
|
|
3531
|
-
// SPENT = deduplicated fresh input + output on actual activity days.
|
|
3532
|
-
// Cache reads and writes are excluded. NOT sum(model_mix):
|
|
3533
|
-
// model_mix can omit unattributed tokens. Fail-open to that sum rather than 0.
|
|
3534
|
-
// SAVED = savings.total_tokens. Fail-open: measured AND estimated both ≤ 0 →
|
|
3535
|
-
// return '' (omit card entirely); either > 0 → render (estimates still show
|
|
3536
|
-
// when the measured floor is zero). SAVED > 0 but SPENT missing/zero →
|
|
3537
|
-
// render hero + footer only.
|
|
3538
|
-
// The model-mix "where the spent went" bar reconciles to SPENT via a trailing
|
|
3539
|
-
// "untracked" segment for SPENT - sum(model_mix) (tokens billed without a
|
|
3540
|
-
// model tag). Returns '' when the card should not render.
|
|
3638
|
+
// Share the Savings story calculation and period, including its eligibility rules.
|
|
3541
3639
|
function tokensSavedCardHtml(savings) {
|
|
3542
3640
|
var s = savings || {};
|
|
3543
|
-
var
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
var
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
(
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
if (tk > 0) tsEstItems.push({ label: label, tokens: tk });
|
|
3569
|
-
})(s.resume_lean_estimated, 'lean resumes');
|
|
3570
|
-
(function pushEst(obj, label) {
|
|
3571
|
-
var tk = Number(obj && obj.tokens_saved) || 0;
|
|
3572
|
-
if (tk > 0) tsEstItems.push({ label: label, tokens: tk });
|
|
3573
|
-
})(s.checkpoint_restore_estimated, 'checkpoint restores');
|
|
3574
|
-
var tsEstTokens = tsEstItems.reduce(function(a, b) { return a + b.tokens; }, 0);
|
|
3575
|
-
var tsEstLabelList = tsEstItems.map(function(it) { return it.label; }).join(', ');
|
|
3576
|
-
if (tsSavedTokens <= 0 && tsEstTokens <= 0) return '';
|
|
3577
|
-
var tsTrends = data.trends || {};
|
|
3578
|
-
var tsSpentBasis = tsTrends.spent_token_basis || {};
|
|
3579
|
-
var tsModelMix = tsTrends.model_mix || {};
|
|
3580
|
-
var tsModelTotal = 0;
|
|
3581
|
-
for (var tsMk in tsModelMix) { tsModelTotal += tsModelMix[tsMk]; }
|
|
3582
|
-
var tsIsCodex = data.runtime === 'codex';
|
|
3583
|
-
var tsPeriodDays = Number(tsTrends.period_days) || Number(s.period_days) || 30;
|
|
3584
|
-
// Missing dated coverage must not be replaced by lifetime model totals.
|
|
3585
|
-
var tsReportedTotal = Number(tsTrends.total_tokens) || 0;
|
|
3586
|
-
var tsSpentTokens = Object.prototype.hasOwnProperty.call(tsTrends, 'total_tokens') ? Math.max(0, tsReportedTotal) : tsModelTotal;
|
|
3587
|
-
// (tsWouldSendTotal / percentages are computed below, AFTER the estimated
|
|
3588
|
-
// tier is summed: the card headlines the FULL saved total in every state.)
|
|
3589
|
-
// FULL saved total = measured floor + estimated tier. The headline is
|
|
3590
|
-
// ALWAYS the full number, never the floor alone; the measured-vs-estimated
|
|
3591
|
-
// split stays visible right under it so the honesty travels with the size,
|
|
3592
|
-
// and the %-prevented / spent-vs-saved bar / would-send total are all
|
|
3593
|
-
// computed against the same full figure.
|
|
3594
|
-
var tsFullSaved = tsSavedTokens + tsEstTokens;
|
|
3595
|
-
var tsWouldSendTotal = tsSpentTokens + tsFullSaved;
|
|
3596
|
-
var tsSavedPct = (tsWouldSendTotal > 0) ? Math.round(tsFullSaved / tsWouldSendTotal * 100) : 0;
|
|
3597
|
-
var tsSpentPct = 100 - tsSavedPct; // no 101% rounding
|
|
3598
|
-
var tsSplitShort = fn(tsSavedTokens) + ' measured' + (tsEstTokens > 0 ? ' + ' + fn(tsEstTokens) + ' estimated' : '');
|
|
3599
|
-
|
|
3600
|
-
var out = '<div class="card wide"><div class="card-header"><span>Tokens Saved</span><span class="label">Last ' + tsPeriodDays + ' days · measured + estimated</span></div>';
|
|
3601
|
-
// HERO: total tokens saved, savings-green, mono, tabular-nums.
|
|
3602
|
-
out += '<div style="display:flex;align-items:baseline;gap:var(--s-3);flex-wrap:wrap;margin-top:var(--s-2)"><div class="metric-large savings-hero">' + fn(tsFullSaved) + '</div><div class="metric-unit">tokens saved</div></div>';
|
|
3603
|
-
out += '<div class="metric-sub tight" style="margin-top:2px;">' + fn(tsFullSaved) + ' saved · ' + tsSplitShort + '</div>';
|
|
3604
|
-
if (tsSpentTokens > 0) {
|
|
3605
|
-
out += '<div class="metric-sub tight">Token Optimizer prevented <span class="pct">≈' + tsSavedPct + '%</span> of the tokens this workload would otherwise have sent. Claude <code>/stats</code>-compatible spent: <b>' + fn(tsSpentTokens) + '</b>; tokens never sent: <b>' + fn(tsFullSaved) + '</b> (' + tsSplitShort + ').</div>';
|
|
3606
|
-
// Spent vs Saved bar: one row, two proportional segments (spent+saved).
|
|
3607
|
-
out += '<div class="ts-divider"></div>';
|
|
3608
|
-
out += '<div class="ts-section-label"><span>Spent vs Saved</span><span class="muted">without Token Optimizer: ≈' + fn(tsWouldSendTotal) + '</span></div>';
|
|
3609
|
-
out += '<div class="sv-bar" title="spent ' + fn(tsSpentTokens) + ' + saved ' + fn(tsFullSaved) + ' (' + tsSplitShort + ') = ' + fn(tsWouldSendTotal) + ' would-be total">';
|
|
3610
|
-
out += '<div class="sv-seg spent" style="width:' + tsSpentPct + '%">spent · ' + fn(tsSpentTokens) + '</div>';
|
|
3611
|
-
out += '<div class="sv-seg saved" style="width:' + tsSavedPct + '%">saved · ' + fn(tsFullSaved) + '</div>';
|
|
3612
|
-
out += '</div>';
|
|
3613
|
-
out += '<div class="sv-caption">Without Token Optimizer you\'d have sent <b>≈' + fn(tsWouldSendTotal) + '</b> to do the same work.</div>';
|
|
3614
|
-
// Model mix relabeled as USAGE: where the SPENT went. Bar + legend
|
|
3615
|
-
// reconcile to SPENT via a trailing "untracked" segment for tokens
|
|
3616
|
-
// billed without a model tag (SPENT - sum(model_mix)).
|
|
3617
|
-
if (tsModelTotal > 0) {
|
|
3618
|
-
out += '<div class="ts-divider"></div>';
|
|
3619
|
-
out += '<div class="ts-section-label"><span>Where the ' + fn(tsSpentTokens) + ' you spent went</span><span class="muted">which models do the work</span></div>';
|
|
3620
|
-
out += modelMixBodyHtml(tsModelMix, tsIsCodex, tsSpentTokens);
|
|
3621
|
-
}
|
|
3622
|
-
} else {
|
|
3623
|
-
// SAVED exists but SPENT is unknown (no billable total AND no
|
|
3624
|
-
// model_mix). Render the hero + footer only.
|
|
3625
|
-
out += '<div class="metric-sub tight">Token Optimizer saved <b>' + fn(tsFullSaved) + '</b> tokens that never had to be sent (' + tsSplitShort + ').</div>';
|
|
3626
|
-
}
|
|
3627
|
-
// Footer: metered floor + optional estimated-slice sentence + plan note.
|
|
3628
|
-
out += '<div class="ts-foot"><span class="tier">Measured + estimated.</span> ' + fn(tsSavedTokens) + ' of these tokens are metered action by action (the floor)' + (tsEstTokens > 0 ? '; ≈' + fn(tsEstTokens) + ' are estimated (' + esc(tsEstLabelList) + ') and are included in the headline, labelled.' : '.') + (tsSpentBasis.basis ? ' Spent basis: ' + esc(tsSpentBasis.basis) + '.' : '') + ' Subscription plan — counted in tokens, no per-token cost.</div>';
|
|
3629
|
-
out += '</div>';
|
|
3641
|
+
var storyAvailable = typeof savingsStoryOn === 'function' && savingsStoryOn(data);
|
|
3642
|
+
var bands = typeof savingsStoryBands === 'function' ? savingsStoryBands(data) : null;
|
|
3643
|
+
var total = bands ? bands.totalTok : Number((s.token_headline || {}).total_tokens) || 0;
|
|
3644
|
+
if (total <= 0) return '';
|
|
3645
|
+
var formatTokens = typeof savingsStoryFmt === 'function' ? savingsStoryFmt().tok : fn;
|
|
3646
|
+
var removed = Number((s.token_headline || {}).removed_tokens) || 0;
|
|
3647
|
+
var trends = data.trends || {};
|
|
3648
|
+
var mix = trends.model_mix || {};
|
|
3649
|
+
var modelTotal = 0;
|
|
3650
|
+
for (var model in mix) { modelTotal += Number(mix[model]) || 0; }
|
|
3651
|
+
var spent = Object.prototype.hasOwnProperty.call(trends, 'total_tokens') ? Math.max(0, Number(trends.total_tokens) || 0) : modelTotal;
|
|
3652
|
+
var days = Number(s.period_days) || 30;
|
|
3653
|
+
var out = '<div class="card wide"><div class="card-header"><span>Tokens Saved</span></div>';
|
|
3654
|
+
out += '<div style="display:flex;align-items:baseline;gap:var(--s-3);flex-wrap:wrap;margin-top:var(--s-2)"><div class="metric-large savings-hero">' + formatTokens(total) + '</div><div class="metric-unit">tokens kept out of context in the last ' + days + ' days</div></div>';
|
|
3655
|
+
var types = s.token_type_breakdown || {};
|
|
3656
|
+
var typeRows = [['cache_reread', 'Modeled cache re-reads avoided'], ['cache_write', 'Modeled cache writes avoided'], ['fresh', 'Fresh input and output avoided']];
|
|
3657
|
+
typeRows = typeRows.filter(function(row) { return typeof types[row[0]] === 'number' && isFinite(types[row[0]]); });
|
|
3658
|
+
if (typeRows.length) out += '<div class="ts-divider"></div><h3 class="ts-section-label">Tokens by type, partial ledger</h3><div class="st-bands">' + typeRows.map(function(row) {
|
|
3659
|
+
return '<div class="st-band">' + row[1] + '<br><strong>' + formatTokens(types[row[0]]) + '</strong></div>';
|
|
3660
|
+
}).join('') + '</div>';
|
|
3661
|
+
if (modelTotal > 0) {
|
|
3662
|
+
out += '<div class="ts-divider"></div><h3 class="ts-section-label">Model usage</h3>';
|
|
3663
|
+
out += modelMixBodyHtml(mix, data.runtime === 'codex', spent > 0 ? spent : modelTotal);
|
|
3664
|
+
}
|
|
3665
|
+
out += '<div class="ts-foot">' + (storyAvailable ? 'Same figure as the Savings card.<br>' : '') + formatTokens(removed) + ' tokens removed once.</div></div>';
|
|
3630
3666
|
return out;
|
|
3631
3667
|
}
|
|
3632
3668
|
|
|
@@ -3645,15 +3681,17 @@ var DB = (function() {
|
|
|
3645
3681
|
'</div>' +
|
|
3646
3682
|
'<div class="last-updated">Last updated: ' + esc(ts) + '</div>';
|
|
3647
3683
|
|
|
3648
|
-
|
|
3649
|
-
//
|
|
3650
|
-
html +=
|
|
3684
|
+
html += tokensSavedCardHtml(data.savings || {}) + runwayCardHtml();
|
|
3685
|
+
// Context before the first message is not a saving: it lives here, not on Savings.
|
|
3686
|
+
if (typeof firstCallContextHtml === 'function') html += firstCallContextHtml((t || {}).first_call_context);
|
|
3651
3687
|
|
|
3652
3688
|
if (!t) {
|
|
3653
3689
|
var collectNote = isCodex
|
|
3654
3690
|
? tcliHtml('Codex sessions can be collected manually for now: <span class="update-cmd">TOKEN_OPTIMIZER_RUNTIME=codex python3 measure.py collect</span>')
|
|
3655
3691
|
: tcliHtml('Sessions are collected automatically via the SessionEnd hook. Run a few sessions first, or manually: <span class="update-cmd">python3 measure.py collect</span>');
|
|
3656
|
-
html += '<div class="empty-state">No trends data yet. ' + collectNote +
|
|
3692
|
+
html += '<div class="empty-state">No trends data yet. ' + collectNote +
|
|
3693
|
+
' <button class="date-nav-btn" onclick="window.__TOKEN_LOAD_HISTORY(\'all\', document.getElementById(\'history-load-message\'))">Load full history</button>' +
|
|
3694
|
+
'<span id="history-load-message" role="status"></span></div>';
|
|
3657
3695
|
el.innerHTML = html;
|
|
3658
3696
|
return;
|
|
3659
3697
|
}
|
|
@@ -3702,21 +3740,30 @@ var DB = (function() {
|
|
|
3702
3740
|
.filter(function(label) { return !!label; })
|
|
3703
3741
|
.join(' | ');
|
|
3704
3742
|
|
|
3705
|
-
var tokenLabel = isCodex ? 'Measured/Estimated Tokens' : '
|
|
3743
|
+
var tokenLabel = isCodex ? 'Measured/Estimated Tokens' : 'Deduplicated Fresh Input + Output';
|
|
3706
3744
|
var tokenNote = isCodex
|
|
3707
3745
|
? 'Codex logs use token_count snapshots when present; older sessions fall back to local estimates.'
|
|
3708
|
-
: '
|
|
3746
|
+
: 'Deduplicated usage; the raw token classes below use a different basis.';
|
|
3709
3747
|
var pop = t.population_metrics || {};
|
|
3710
3748
|
var eligibleCacheHit = Number(pop.cache_eligible_main_hit_rate);
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
var
|
|
3749
|
+
// Claude: lead with the token-weighted rate across every scanned session;
|
|
3750
|
+
// the per-session averages become secondary lines.
|
|
3751
|
+
var overallCacheHit = Number((data.cache_health || {}).overall_cache_hit_rate);
|
|
3752
|
+
var cacheOverall = !isCodex && (data.cache_health || {}).overall_cache_hit_rate != null && Number.isFinite(overallCacheHit) && overallCacheHit >= 0;
|
|
3753
|
+
var avgCacheDisplay = cacheOverall ? (overallCacheHit * 100).toFixed(1).replace(/\.0$/, '')
|
|
3754
|
+
: (Number.isFinite(eligibleCacheHit) && pop.cache_eligible_main_sessions ? Math.round(eligibleCacheHit * 100) : avgCacheHit);
|
|
3755
|
+
var cacheLabel = isCodex ? 'Cached Input Share' : (cacheOverall ? 'Cache hit rate (all tokens)' : 'Main-work cache hit rate');
|
|
3756
|
+
var cacheSessionLines = cacheOverall
|
|
3757
|
+
? (pop.cache_eligible_main_sessions ? '<div style="font-size:12px;color:var(--c-text-main);margin-top:6px">Average session, 20+ messages: ' + Math.round((Number(pop.cache_eligible_main_hit_rate) || 0) * 100) + '%</div>' : '') +
|
|
3758
|
+
(pop.cache_ineligible_sessions ? '<div style="font-size:12px;color:var(--c-text-main);margin-top:2px">Average short or delegated session: ' + Math.round((Number(pop.cache_ineligible_hit_rate) || 0) * 100) + '%</div>' : '') +
|
|
3759
|
+
'<div style="font-size:11px;color:var(--c-text-dim);margin-top:2px">Session lines average each session’s own rate; the big number weights every token.</div>'
|
|
3760
|
+
: '<div style="font-size:11px;color:var(--c-text-dim);margin-top:4px">' + (pop.cache_eligible_main_sessions || 0) + ' cache-building main-work sessions · ' + (pop.cache_ineligible_sessions || 0) + ' short/delegated sessions at ' + Math.round((Number(pop.cache_ineligible_hit_rate) || 0) * 100) + '%</div>';
|
|
3714
3761
|
var cacheNote = isCodex
|
|
3715
3762
|
? 'Share of logged input tokens Codex says were cached_input_tokens. Similar to a cache hit rate, but Codex does not expose cache-write TTL or write-size fields.'
|
|
3716
|
-
: 'Main-work sessions with 20+ messages.
|
|
3763
|
+
: (cacheOverall ? '' : 'Main-work sessions with 20+ messages.');
|
|
3717
3764
|
var tokenBreakdownNote = isCodex
|
|
3718
3765
|
? 'fresh:' + fn(t.total_fresh_input || 0) + ' · cached input:' + fn(t.total_cache_read || 0) + ' · out:' + fn(t.total_output_tokens || 0)
|
|
3719
|
-
: 'fresh:' + fn(t.total_fresh_input || 0) + ' · cache-write:' + fn(t.total_cache_create || 0) + ' · out:' + fn(t.total_output_tokens || 0);
|
|
3766
|
+
: 'raw fresh:' + fn(t.total_fresh_input || 0) + ' · cache-write:' + fn(t.total_cache_create || 0) + ' · out:' + fn(t.total_output_tokens || 0);
|
|
3720
3767
|
var codexCostNote = '';
|
|
3721
3768
|
if (isCodex && typeof t.total_cost_usd === 'number') {
|
|
3722
3769
|
codexCostNote = '<div style="font-size:10px;color:var(--c-text-dim);margin-top:2px">API-equivalent known cost: $' + t.total_cost_usd.toFixed(2);
|
|
@@ -3730,7 +3777,7 @@ var DB = (function() {
|
|
|
3730
3777
|
}
|
|
3731
3778
|
var cacheExtra = isCodex
|
|
3732
3779
|
? '<div style="font-size:11px;color:var(--c-text-dim);margin-top:4px">' + cacheNote + '</div>'
|
|
3733
|
-
: '<div style="font-size:11px;color:var(--c-text-dim);margin-top:4px">Cache writes: ' + esc(globalTtlMix) + '</div><div style="font-size:11px;color:var(--c-text-dim);margin-top:4px">' + esc(globalTtlSessionLabel) + '</div><div style="font-size:11px;color:var(--c-text-dim);margin-top:4px">' + esc(ttlPeriodSummary || 'TTL period summary unavailable') + '</div
|
|
3780
|
+
: '<div style="font-size:11px;color:var(--c-text-dim);margin-top:4px">Cache writes: ' + esc(globalTtlMix) + '</div><div style="font-size:11px;color:var(--c-text-dim);margin-top:4px">' + esc(globalTtlSessionLabel) + '</div><div style="font-size:11px;color:var(--c-text-dim);margin-top:4px">' + esc(ttlPeriodSummary || 'TTL period summary unavailable') + '</div>' + (cacheNote ? '<div style="font-size:11px;color:var(--c-text-dim);margin-top:4px">' + cacheNote + '</div>' : '');
|
|
3734
3781
|
|
|
3735
3782
|
html += '<div class="stat-row" style="grid-template-columns:repeat(3,1fr);margin-bottom:var(--s-3)">' +
|
|
3736
3783
|
'<div class="stat-card"><div class="stat-card-value">' + t.session_count + '</div><div class="stat-card-label">All logged sessions (' + t.period_days + 'd)</div><div style="font-size:11px;color:var(--c-text-dim);margin-top:4px">' + (pop.main_work_sessions || 0) + ' main-work · ' + (pop.delegated_sessions || 0) + ' delegated/subagent</div></div>' +
|
|
@@ -3740,38 +3787,41 @@ var DB = (function() {
|
|
|
3740
3787
|
'<div class="stat-row" style="grid-template-columns:repeat(3,1fr)">' +
|
|
3741
3788
|
'<div class="stat-card"><div class="stat-card-value">' + Math.round(t.avg_duration_minutes || 0) + 'm</div><div class="stat-card-label">Avg duration, all logged</div></div>' +
|
|
3742
3789
|
'<div class="stat-card"><div class="stat-card-value">' + fn((t.avg_input_tokens || 0) + (t.avg_output_tokens || 0)) + '</div><div class="stat-card-label">Avg tokens, all logged sessions</div></div>' +
|
|
3743
|
-
'<div class="stat-card"><div class="stat-card-value" style="color:var(--c-savings-strong, #22c55e)">' + avgCacheDisplay +
|
|
3790
|
+
(avgCacheDisplay === 'N/A' ? '' : '<div class="stat-card"><div class="stat-card-value" style="color:var(--c-savings-strong, #22c55e)">' + avgCacheDisplay + '%</div><div class="stat-card-label">' + cacheLabel + '</div>' + cacheSessionLines + cacheExtra + '</div>') +
|
|
3744
3791
|
'</div>';
|
|
3745
3792
|
|
|
3746
|
-
// Shared data for skills sections
|
|
3747
3793
|
var skillsDetail = (data.snapshot && data.snapshot.components && data.snapshot.components.skills_detail) || {};
|
|
3748
3794
|
|
|
3749
|
-
// Tokens Saved card: the full card (hero + spent-vs-saved + model-mix-as-
|
|
3750
|
-
// usage + footer). Rendered in BOTH Trends and Savings (sharing the
|
|
3751
|
-
// hoisted tokensSavedCardHtml + modelMixBodyHtml helpers). Replaces the
|
|
3752
|
-
// former standalone Model Mix card — the model-mix-as-usage section is
|
|
3753
|
-
// now inside the Tokens Saved card, reconciled to the billable SPENT.
|
|
3754
|
-
// Fail-open: returns '' only when measured AND estimated are both ≤ 0.
|
|
3755
|
-
html += tokensSavedCardHtml(data.savings || {});
|
|
3756
3795
|
|
|
3757
3796
|
// Daily breakdown with date navigation
|
|
3758
3797
|
var daily = t.daily || [];
|
|
3759
3798
|
if (daily.length > 0) {
|
|
3760
|
-
|
|
3799
|
+
var selectedRange = '7';
|
|
3800
|
+
try { selectedRange = localStorage.getItem('to-daily-range') || '7'; } catch (e) {}
|
|
3801
|
+
if (['7', '14', '30', '90', '180', 'all'].indexOf(selectedRange) < 0) selectedRange = '7';
|
|
3761
3802
|
html += '<div class="card wide" id="daily-breakdown-card">' +
|
|
3762
3803
|
'<div class="card-header"><span>Daily Breakdown</span></div>' +
|
|
3763
3804
|
'<div style="font-size:12px;color:var(--c-text-dim);padding:0 0 var(--s-2) 0;">Click any row to expand per-session details with cost, quality scores, and cache data. ' + (isCodex ? 'Codex cache write TTL is not exposed, so those fields are hidden.' : 'Claude cache TTL mix is shown when available.') + ' Click a session for per-turn token breakdown.</div>' +
|
|
3764
3805
|
'<div class="date-nav">' +
|
|
3765
|
-
'<button class="date-nav-btn
|
|
3806
|
+
'<button class="date-nav-btn" data-range="7">7 days</button>' +
|
|
3766
3807
|
'<button class="date-nav-btn" data-range="14">14 days</button>' +
|
|
3767
3808
|
'<button class="date-nav-btn" data-range="30">30 days</button>' +
|
|
3809
|
+
'<button class="date-nav-btn" data-range="90">90 days</button>' +
|
|
3810
|
+
'<button class="date-nav-btn" data-range="180">180 days</button>' +
|
|
3811
|
+
'<button class="date-nav-btn" data-range="all">All</button>' +
|
|
3812
|
+
'<button class="date-nav-btn" id="load-full-history">Load full history</button>' +
|
|
3813
|
+
'<span id="history-load-message" role="status"></span>' +
|
|
3768
3814
|
'<span style="color:var(--c-text-dim);font-size:12px;margin:0 4px;">|</span>' +
|
|
3769
3815
|
'<label style="font-size:12px;color:var(--c-text-dim);font-family:var(--font-mono);">Jump to:</label>' +
|
|
3770
3816
|
'<input type="date" class="date-picker-input" id="daily-date-picker" value="' + esc(daily[0].date) + '">' +
|
|
3771
3817
|
'</div>';
|
|
3772
3818
|
html += '<div id="daily-table-container">';
|
|
3773
|
-
html += buildDailyTable(daily,
|
|
3819
|
+
html += buildDailyTable(daily, selectedRange, null);
|
|
3774
3820
|
html += '</div></div>';
|
|
3821
|
+
} else {
|
|
3822
|
+
html += '<div class="empty-state">No daily sessions in this window. ' +
|
|
3823
|
+
'<button class="date-nav-btn" onclick="window.__TOKEN_LOAD_HISTORY(\'all\', document.getElementById(\'history-load-message\'))">Load full history</button>' +
|
|
3824
|
+
'<span id="history-load-message" role="status"></span></div>';
|
|
3775
3825
|
}
|
|
3776
3826
|
|
|
3777
3827
|
// Skills usage bar chart with clickable skill details
|
|
@@ -3792,9 +3842,9 @@ var DB = (function() {
|
|
|
3792
3842
|
topSkills.forEach(function(entry) {
|
|
3793
3843
|
var w = Math.max(3, (entry[1] / maxSkill) * 100);
|
|
3794
3844
|
var sd = skillsDetail[entry[0]];
|
|
3795
|
-
var tokNote = sd ? sd.frontmatter_tokens + '
|
|
3845
|
+
var tokNote = sd && typeof sd.frontmatter_tokens === 'number' ? ' (' + sd.frontmatter_tokens + ' frontmatter tokens)' : '';
|
|
3796
3846
|
html += '<div class="bar-row" data-skill-name="' + esc(entry[0]) + '" style="cursor:pointer;">' +
|
|
3797
|
-
'<span class="bar-label" style="width:120px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="' + esc(entry[0]
|
|
3847
|
+
'<span class="bar-label" style="width:120px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="' + esc(entry[0] + tokNote) + '">' + esc(entry[0]) + '</span>' +
|
|
3798
3848
|
'<div class="bar-track"><div class="bar-fill" style="width:' + w + '%"></div></div>' +
|
|
3799
3849
|
'<span class="bar-value" style="width:60px;text-align:right;">' + entry[1] + ' sess</span></div>';
|
|
3800
3850
|
});
|
|
@@ -3804,11 +3854,10 @@ var DB = (function() {
|
|
|
3804
3854
|
// Never-used skills with expandable detail (half-folded)
|
|
3805
3855
|
var neverUsed = t.skills ? t.skills.never_used : [];
|
|
3806
3856
|
if (!isCodex && neverUsed.length > 0) {
|
|
3807
|
-
var overhead = t.skills.never_used_overhead || (neverUsed.length * 100);
|
|
3808
3857
|
var PREVIEW_COUNT = 4;
|
|
3809
|
-
html += '<div class="card wide"><div class="card-header"><span>Not Invoked (' + neverUsed.length + ' skills)</span
|
|
3858
|
+
html += '<div class="card wide"><div class="card-header"><span>Not Invoked (' + neverUsed.length + ' skills)</span></div>' +
|
|
3810
3859
|
'<p style="font-size:13px;color:var(--c-text-dim);font-family:var(--font-mono);margin-bottom:var(--s-2);">' +
|
|
3811
|
-
'No Skill call or slash command for these in the window.
|
|
3860
|
+
'No Skill call or slash command for these in the window. A skill you drive by slash command counts as invoked; if one you use often shows here, open an issue. Click a skill for details, or "Quick Wins" to archive.</p>';
|
|
3812
3861
|
|
|
3813
3862
|
function buildSkillRow(name) {
|
|
3814
3863
|
var sd = skillsDetail[name];
|
|
@@ -3816,7 +3865,7 @@ var DB = (function() {
|
|
|
3816
3865
|
'<div class="skill-detail-header">' +
|
|
3817
3866
|
'<input type="checkbox" class="skill-archive-check" data-skill="' + esc(name) + '" title="Select to archive">' +
|
|
3818
3867
|
'<span class="skill-name">' + esc(name) + '</span>' +
|
|
3819
|
-
'<span class="skill-tokens">' +
|
|
3868
|
+
(sd && typeof sd.frontmatter_tokens === 'number' ? '<span class="skill-tokens">' + sd.frontmatter_tokens + ' frontmatter tokens</span>' : '') +
|
|
3820
3869
|
'<span class="expand-arrow">\u25B6</span>' +
|
|
3821
3870
|
'</div>' +
|
|
3822
3871
|
'<div class="skill-detail-body"><div class="skill-detail-content">';
|
|
@@ -3858,27 +3907,34 @@ var DB = (function() {
|
|
|
3858
3907
|
|
|
3859
3908
|
el.innerHTML = html;
|
|
3860
3909
|
|
|
3861
|
-
//
|
|
3910
|
+
// The table range is local to the browser; the embedded window is saved
|
|
3911
|
+
// by the generator and can be expanded explicitly through the local server.
|
|
3862
3912
|
if (daily.length > 0) {
|
|
3863
3913
|
var container = document.getElementById('daily-table-container');
|
|
3864
3914
|
var rangeBtns = document.querySelectorAll('.date-nav-btn[data-range]');
|
|
3915
|
+
var historyMessage = document.getElementById('history-load-message');
|
|
3916
|
+
function setRange(range) {
|
|
3917
|
+
selectedRange = range;
|
|
3918
|
+
try { localStorage.setItem('to-daily-range', range); } catch (e) {}
|
|
3919
|
+
rangeBtns.forEach(function(b) { b.classList.toggle('active', b.getAttribute('data-range') === range); });
|
|
3920
|
+
container.innerHTML = buildDailyTable(daily, range, null);
|
|
3921
|
+
}
|
|
3922
|
+
setRange(selectedRange);
|
|
3865
3923
|
rangeBtns.forEach(function(btn) {
|
|
3866
3924
|
btn.addEventListener('click', function() {
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
container.innerHTML = buildDailyTable(daily, range, null);
|
|
3925
|
+
var range = this.getAttribute('data-range');
|
|
3926
|
+
setRange(range);
|
|
3927
|
+
if (range !== 'all' && Number(range) > Number(t.period_days || 0)) window.__TOKEN_LOAD_HISTORY(Number(range), historyMessage);
|
|
3871
3928
|
});
|
|
3872
3929
|
});
|
|
3930
|
+
document.getElementById('load-full-history').addEventListener('click', function() {
|
|
3931
|
+
setRange('all');
|
|
3932
|
+
window.__TOKEN_LOAD_HISTORY('all', historyMessage);
|
|
3933
|
+
});
|
|
3873
3934
|
var picker = document.getElementById('daily-date-picker');
|
|
3874
|
-
if (picker) {
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
var range = activeBtn ? parseInt(activeBtn.getAttribute('data-range'), 10) || 7 : 7;
|
|
3878
|
-
rangeBtns.forEach(function(b) { b.classList.remove('active'); });
|
|
3879
|
-
container.innerHTML = buildDailyTable(daily, range, this.value);
|
|
3880
|
-
});
|
|
3881
|
-
}
|
|
3935
|
+
if (picker) picker.addEventListener('change', function() {
|
|
3936
|
+
container.innerHTML = buildDailyTable(daily, selectedRange, this.value);
|
|
3937
|
+
});
|
|
3882
3938
|
}
|
|
3883
3939
|
|
|
3884
3940
|
// Bind skill detail expand
|
|
@@ -3971,7 +4027,7 @@ var DB = (function() {
|
|
|
3971
4027
|
names.forEach(function(name) {
|
|
3972
4028
|
cmd += ' && mv "$HOME/.claude/skills/"' + shellQuote(name) + ' "$ARCHIVE_DIR/"';
|
|
3973
4029
|
});
|
|
3974
|
-
cmd += ' && echo "Archived ' + names.length + tcli(' skill(s). Regenerate dashboard: python3 measure.py dashboard"');
|
|
4030
|
+
cmd += ' && echo "Archived ' + names.length + tcli(' skill(s). Regenerate dashboard: python3 measure.py dashboard --user"');
|
|
3975
4031
|
|
|
3976
4032
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
3977
4033
|
navigator.clipboard.writeText(cmd).then(function() {
|
|
@@ -3995,26 +4051,24 @@ var DB = (function() {
|
|
|
3995
4051
|
}
|
|
3996
4052
|
|
|
3997
4053
|
function gapSummary(avgGap, maxGap) {
|
|
3998
|
-
if (avgGap == null && maxGap == null) return '
|
|
4054
|
+
if (avgGap == null && maxGap == null) return '';
|
|
3999
4055
|
if (avgGap == null) return 'max ' + fmtGap(maxGap);
|
|
4000
4056
|
if (maxGap == null) return 'avg ' + fmtGap(avgGap);
|
|
4001
4057
|
return 'avg ' + fmtGap(avgGap) + ' | max ' + fmtGap(maxGap);
|
|
4002
4058
|
}
|
|
4003
4059
|
|
|
4004
|
-
function
|
|
4060
|
+
function selectDailyRange(daily, range, jumpToDate) {
|
|
4061
|
+
if (!daily.length) return [];
|
|
4062
|
+
var start = jumpToDate || daily[0].date;
|
|
4063
|
+
if (range === 'all') return daily.filter(function(d) { return d.date <= start; });
|
|
4064
|
+
var end = new Date(start + 'T00:00:00Z');
|
|
4065
|
+
end.setUTCDate(end.getUTCDate() - Number(range) + 1);
|
|
4066
|
+
var cutoff = end.toISOString().slice(0, 10);
|
|
4067
|
+
return daily.filter(function(d) { return d.date <= start && d.date >= cutoff; });
|
|
4068
|
+
}
|
|
4005
4069
|
|
|
4006
|
-
|
|
4007
|
-
var filtered;
|
|
4008
|
-
if (jumpToDate) {
|
|
4009
|
-
// Show 7 days starting from the selected date
|
|
4010
|
-
var startDate = jumpToDate;
|
|
4011
|
-
var endDate = new Date(jumpToDate);
|
|
4012
|
-
endDate.setDate(endDate.getDate() - range + 1);
|
|
4013
|
-
var endStr = endDate.toISOString().slice(0, 10);
|
|
4014
|
-
filtered = daily.filter(function(d) { return d.date <= startDate && d.date >= endStr; });
|
|
4015
|
-
} else {
|
|
4016
|
-
filtered = daily.slice(0, range);
|
|
4017
|
-
}
|
|
4070
|
+
function buildDailyTable(daily, range, jumpToDate) {
|
|
4071
|
+
var filtered = selectDailyRange(daily, range, jumpToDate);
|
|
4018
4072
|
|
|
4019
4073
|
if (filtered.length === 0) {
|
|
4020
4074
|
return '<div class="empty-state">No sessions found for this period.</div>';
|
|
@@ -4125,7 +4179,7 @@ var DB = (function() {
|
|
|
4125
4179
|
(isCodex ? '' : '<td style="font-family:var(--font-mono);font-size:11px;">' + esc(ttlStr) + '</td>') +
|
|
4126
4180
|
'<td style="font-family:var(--font-mono);font-size:11px;">' + esc(pacingStr) + '</td>' +
|
|
4127
4181
|
'<td style="color:var(--c-accent-cyan);font-family:var(--font-mono);font-size:12px;">' + costStr + '</td>' +
|
|
4128
|
-
'<td><span class="quality-badge ' + qBadgeClass + '">' + qGrade + ' (' + qs + ')</span></td>' +
|
|
4182
|
+
'<td><span class="quality-badge ' + qBadgeClass + '">' + (sd.quality_measured === false ? (sd.quality_score == null ? '--' : '~' + qs) : qGrade + ' (' + qs + ')') + '</span></td>' +
|
|
4129
4183
|
'<td style="color:var(--c-text-dim);font-size:11px;">' + esc(modelStr) + '</td>' +
|
|
4130
4184
|
'<td style="color:var(--c-text-dim);font-size:12px;" title="' + esc(sdTopic) + '">' + esc(sdTopic.length > 35 ? sdTopic.slice(0,33) + '\u2026' : sdTopic) + '</td>' +
|
|
4131
4185
|
'</tr>';
|
|
@@ -4216,11 +4270,14 @@ var DB = (function() {
|
|
|
4216
4270
|
var savedUsd = Number(w.saved_usd);
|
|
4217
4271
|
var spanWord = w.key === 'five_hour' ? '5h' : 'week';
|
|
4218
4272
|
var hasUsd = isFinite(savedUsd) && (w.key === 'five_hour' ? savedUsd > 0 : savedUsd >= 15);
|
|
4219
|
-
|
|
4220
|
-
|
|
4273
|
+
// Without a whole-week estimate the figure is only the event-by-event count, so say so.
|
|
4274
|
+
var usdCaption = w.full_value
|
|
4275
|
+
? (w.key === 'seven_day' ? 'in API-equivalent savings this week' : 'in API-equivalent savings this 5h')
|
|
4276
|
+
: (w.key === 'seven_day' ? 'in counted savings this week (partial)' : 'in counted savings this 5h (partial)');
|
|
4221
4277
|
var usdExplainer = w.full_value
|
|
4222
4278
|
? 'Estimated additional cost at API prices for the same work without Token Optimizer. Includes lighter context, fewer repeat reads and working habits, counted once. Your plan may cover some or all of that usage.'
|
|
4223
|
-
: 'API
|
|
4279
|
+
: 'Only the savings counted one event at a time, at API prices. This is a floor, not the whole saving. A whole-week estimate appears when your work measures consistently against your baseline; this window it did not.';
|
|
4280
|
+
if (w.full_value && w.full_value.coverage && w.full_value.coverage.priced_sessions < w.full_value.coverage.total_sessions && Number(w.full_value.saved_usd) >= savedUsd) usdExplainer += ' Based on ' + Number(w.full_value.coverage.priced_sessions) + ' of ' + Number(w.full_value.coverage.total_sessions) + ' sessions; missing sessions are not estimated.';
|
|
4224
4281
|
if (w.full_value && w.full_value.start) {
|
|
4225
4282
|
usdExplainer += ' Since ' + esc(new Date(w.full_value.start).toLocaleString([], {month:'short', day:'numeric', hour:'numeric', minute:'2-digit'})) + '.';
|
|
4226
4283
|
}
|
|
@@ -4253,6 +4310,11 @@ var DB = (function() {
|
|
|
4253
4310
|
'</div>' +
|
|
4254
4311
|
'</div>';
|
|
4255
4312
|
}).join('');
|
|
4313
|
+
// With the story module inlined, windows render as "X% used / would be Y%
|
|
4314
|
+
// without" (live, else the last stored reading); the older per-window cards
|
|
4315
|
+
// remain only for a template without it.
|
|
4316
|
+
var rwLimitsHtml = '';
|
|
4317
|
+
if (typeof savingsLimitWindows === 'function') { rwLimitsHtml = savingsLimitWindows(rw); rwCards = ''; }
|
|
4256
4318
|
// Savings remain available when the quota meter has no weekly reading.
|
|
4257
4319
|
var standaloneWeek = rw.weekly_full_value;
|
|
4258
4320
|
if (standaloneWeek && Number(standaloneWeek.saved_usd) >= 15 &&
|
|
@@ -4260,7 +4322,7 @@ var DB = (function() {
|
|
|
4260
4322
|
rwCards += '<div style="padding:var(--s-3);border:1px solid var(--c-border);border-radius:8px;">' +
|
|
4261
4323
|
'<div class="label">Weekly savings</div><div style="font-size:22px;color:var(--c-savings-alt,#10b981);">≈' +
|
|
4262
4324
|
rwMoney(standaloneWeek.saved_usd) + ' in API-equivalent savings this week</div>' +
|
|
4263
|
-
'<p>Full workload estimate since ' + esc(new Date(standaloneWeek.start).toLocaleString()) +
|
|
4325
|
+
'<p>Full workload estimate' + (standaloneWeek.coverage && standaloneWeek.coverage.priced_sessions < standaloneWeek.coverage.total_sessions ? ' based on ' + Number(standaloneWeek.coverage.priced_sessions) + ' of ' + Number(standaloneWeek.coverage.total_sessions) + ' sessions, missing sessions are not estimated,' : '') + ' since ' + esc(new Date(standaloneWeek.start).toLocaleString()) +
|
|
4264
4326
|
'. Your weekly limit reading is unavailable.</p></div>';
|
|
4265
4327
|
}
|
|
4266
4328
|
// USD-per-window headline: the dollar figure reuses the metered
|
|
@@ -4271,10 +4333,7 @@ var DB = (function() {
|
|
|
4271
4333
|
(rw.windows || []).forEach(function (w) {
|
|
4272
4334
|
var v = Number(w.saved_usd);
|
|
4273
4335
|
if (!isFinite(v) || v <= 0) return;
|
|
4274
|
-
//
|
|
4275
|
-
// a slice of a longer ledger. The weekly dollar is aligned to the
|
|
4276
|
-
// subscription limit reset boundary (not a rolling 7-day lookback), so
|
|
4277
|
-
// it does not drift down as heavy days age out.
|
|
4336
|
+
// The weekly figure follows the subscription reset boundary.
|
|
4278
4337
|
var span = w.key === 'five_hour' ? 'past 5h' : 'since your limit reset';
|
|
4279
4338
|
usdParts.push('<em style="font-style:normal;color:var(--c-accent-cyan);">' + rwMoney(v) + '</em> ' + span);
|
|
4280
4339
|
});
|
|
@@ -4284,9 +4343,9 @@ var DB = (function() {
|
|
|
4284
4343
|
var rwCostCut = Number(rw.per_session_cost_reduction_pct);
|
|
4285
4344
|
var rwCostCutDisplay = isFinite(rwCostCut) ? Math.round(rwCostCut / 5) * 5 : null;
|
|
4286
4345
|
var rwSpentTokens = Number(rw.tokens_consumed);
|
|
4287
|
-
var rwSavedTokens = Number(rw.
|
|
4346
|
+
var rwSavedTokens = Number(rw.context_tokens_saved);
|
|
4288
4347
|
var rwTokenFloorPct = (isFinite(rwSpentTokens) && rwSpentTokens > 0 && isFinite(rwSavedTokens) && rwSavedTokens > 0)
|
|
4289
|
-
? Math.round(
|
|
4348
|
+
? Math.round((1 - 1 / Number(rw.context_multiplier)) * 1000) / 10
|
|
4290
4349
|
: null;
|
|
4291
4350
|
var rwEfficiencyHeadline = rwHasCostEfficiency
|
|
4292
4351
|
? '<div class="metric-large" style="text-wrap:balance;text-shadow:none;"><em style="font-style:normal;color:var(--c-accent-cyan);">≈' + rwEfficiencyMult.toFixed(1) + '×</em> work per dollar</div>'
|
|
@@ -4347,25 +4406,13 @@ var DB = (function() {
|
|
|
4347
4406
|
: 'Context ×' + rw.context_multiplier + ' and ' + rwRoutingMethod + ' give a per-token throughput multiplier, shown separately from the window headroom and dollar figures.';
|
|
4348
4407
|
rwEfficiencyMethod += rwRoutingScope;
|
|
4349
4408
|
var rwTokenFloorDetail = (rwTokenFloorPct !== null)
|
|
4350
|
-
? '<div class="plain-line">
|
|
4409
|
+
? '<div class="plain-line">Estimated <strong>~' + fn(rwSavedTokens) + '</strong> tokens kept out of context · ' + tokenSplitText(rw.token_headline || {}, fn) + ', roughly ' + rwTokenFloorPct + '% of would-be input and output including cache.' + (rw.tokens_consumed_basis_complete === false ? ' Traffic coverage is incomplete.' : '') + '</div>'
|
|
4351
4410
|
: '';
|
|
4352
4411
|
var rwTokenFloorMethod = (rwTokenFloorPct !== null)
|
|
4353
|
-
? '
|
|
4412
|
+
? 'Estimated savings on ' + fn(rwSpentTokens) + ' input and output tokens, including cache reads and writes; repeat reads assume the same trajectory until compaction.'
|
|
4354
4413
|
: '';
|
|
4355
|
-
// Tier chip reflects the USD spine's measured-vs-estimated boundary:
|
|
4356
|
-
// context $ is metered, routing $ is an estimated counterfactual.
|
|
4357
|
-
// When routing savings contribute, the dollar figure is estimated; when
|
|
4358
|
-
// only context $ contributes, it is measured. None -> no chip change.
|
|
4359
|
-
var usdTierChip = (rw.saved_usd_tier === 'measured') ? 'METERED $'
|
|
4360
|
-
: (rw.saved_usd_tier === 'estimated') ? 'ESTIMATED $' : 'ESTIMATED';
|
|
4361
4414
|
html += '<div class="card" style="margin-bottom:18px;border-color:rgba(0,240,255,.28);box-shadow:0 4px 20px rgba(0,0,0,.3),0 0 40px rgba(0,240,255,.05);">' +
|
|
4362
|
-
|
|
4363
|
-
// siblings the chip inherits the label's block layout and stretches to the
|
|
4364
|
-
// full card width, which reads as a broken banner.
|
|
4365
|
-
'<div style="display:flex;align-items:center;gap:var(--s-2);flex-wrap:wrap;">' +
|
|
4366
|
-
'<span class="label">Your plan goes further</span>' +
|
|
4367
|
-
'<span style="font-size:12px;letter-spacing:.12em;color:var(--c-text-dim);border:1px solid var(--c-border);border-radius:20px;padding:3px 12px;white-space:nowrap;">' + usdTierChip + '</span>' +
|
|
4368
|
-
'</div>' +
|
|
4415
|
+
'<h2 class="st-h">Your limits go further</h2>' +
|
|
4369
4416
|
// No glow on this headline. `.metric-large` carries a text-shadow built
|
|
4370
4417
|
// from --c-border-strong, which is a light veil on dark but resolves to a
|
|
4371
4418
|
// DARK halo in light mode, so the words read as smudged rather than lit.
|
|
@@ -4382,9 +4429,8 @@ var DB = (function() {
|
|
|
4382
4429
|
// Per-window bars when the meter is fresh enough; otherwise a note so the
|
|
4383
4430
|
// card degrades instead of vanishing (the multiplier + savings above still
|
|
4384
4431
|
// stand without the live meter).
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
: '<div style="padding:var(--s-3);border:1px dashed var(--c-border);border-radius:8px;color:var(--c-text-dim);font-size:15px;line-height:1.5;text-wrap:pretty;">Your live 5-hour and weekly limit view refreshes while you are actively working — it reappears here on your next session.</div>') +
|
|
4432
|
+
rwLimitsHtml +
|
|
4433
|
+
(rwCards ? '<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(320px,1fr));gap:var(--s-3);">' + rwCards + '</div>' : '') +
|
|
4388
4434
|
// Freshness of the WINDOW reading itself (not the dashboard build). The
|
|
4389
4435
|
// meter only refreshes while Claude Code is actively running, so a
|
|
4390
4436
|
// dashboard opened later shows the last real reading -- label it with its
|
|
@@ -4423,10 +4469,10 @@ var DB = (function() {
|
|
|
4423
4469
|
: '';
|
|
4424
4470
|
return '<div style="margin-top:var(--s-3);font-size:13px;color:' + col + ';">' +
|
|
4425
4471
|
(stale ? '⚠ ' : '') + 'Window reading as of ' + esc(whenStr) + ' (' + ageStr + ').' + staleNote +
|
|
4426
|
-
' <button id="to-regen-btn" onclick="window.__TOKEN_REGENERATE&&window.__TOKEN_REGENERATE()" ' +
|
|
4472
|
+
(window.location.protocol === 'file:' ? (window.__TOKEN_FILE_DAEMON_LIVE ? ' Open ' + DAEMON_URL + '/token-optimizer for live numbers.' : ' Run <code>python3 skills/token-optimizer/scripts/measure.py setup-daemon</code> to see live numbers.') : ' <button id="to-regen-btn" onclick="window.__TOKEN_REGENERATE&&window.__TOKEN_REGENERATE()" ' +
|
|
4427
4473
|
'style="margin-left:8px;padding:2px 10px;font:inherit;font-size:12px;cursor:pointer;' +
|
|
4428
4474
|
'background:transparent;color:inherit;border:1px solid currentColor;border-radius:4px;">' +
|
|
4429
|
-
'Regenerate savings</button>' +
|
|
4475
|
+
'Regenerate savings</button>') +
|
|
4430
4476
|
'<span id="to-regen-msg" style="margin-left:8px;"></span>' +
|
|
4431
4477
|
'<span id="to-live-stamp" hidden style="margin-left:8px;font-size:12px;color:var(--c-savings-alt, #10b981);"></span>' +
|
|
4432
4478
|
// Persistent regenerate failure surfaces here, not in the tiny
|
|
@@ -4436,7 +4482,6 @@ var DB = (function() {
|
|
|
4436
4482
|
'<div id="to-regen-error" hidden style="margin-top:10px;padding:10px 14px;font-size:15px;font-weight:500;color:var(--c-waste);background:rgba(255,95,95,.08);border:1px solid rgba(255,95,95,.35);border-radius:8px;line-height:1.5;text-wrap:pretty;"></div></div>';
|
|
4437
4483
|
})() +
|
|
4438
4484
|
'<div style="margin-top:var(--s-4);padding-top:var(--s-3);border-top:1px solid var(--c-border);font-size:15px;color:var(--c-text-main);line-height:1.6;text-wrap:pretty;">' +
|
|
4439
|
-
'Your window usage is measured. The savings comparison is an estimate.' +
|
|
4440
4485
|
// Technical method lives in a fold. rw.proxy is the single source of the
|
|
4441
4486
|
// measured-vs-estimated boundary AND the ledger detail; we add only the
|
|
4442
4487
|
// one fact proxy can't carry -- the headline figure is its own unit, not
|
|
@@ -4460,7 +4505,6 @@ var DB = (function() {
|
|
|
4460
4505
|
function renderSavings() {
|
|
4461
4506
|
var el = document.getElementById('view-savings');
|
|
4462
4507
|
if (!el) return;
|
|
4463
|
-
// Live refresh must not close the explanation someone is reading.
|
|
4464
4508
|
var openFolds = Array.from(el.querySelectorAll('details[open] > summary')).map(function(summary) {
|
|
4465
4509
|
return summary.textContent;
|
|
4466
4510
|
});
|
|
@@ -4512,7 +4556,6 @@ var DB = (function() {
|
|
|
4512
4556
|
if (v >= 1e3) return Math.round(v / 1e3) + 'K';
|
|
4513
4557
|
return String(Math.round(v));
|
|
4514
4558
|
}
|
|
4515
|
-
// Foldable "read more". Pass body as ready HTML (wrap prose in <p>...</p>).
|
|
4516
4559
|
// Native <details> means click-to-unfold works with no event wiring.
|
|
4517
4560
|
function fold(summary, bodyHtml) {
|
|
4518
4561
|
// summary is escaped (it is always plain label text); bodyHtml is trusted
|
|
@@ -4531,11 +4574,12 @@ var DB = (function() {
|
|
|
4531
4574
|
// ---- mechanism pillars (structural / runtime / behavioral). Behavioral holds only
|
|
4532
4575
|
// what you're actually getting (realized routing + estimated loop prevention); cache-drop
|
|
4533
4576
|
// and output-waste are OPPORTUNITY (avoidable waste TO does not yet prevent), not here. ----
|
|
4534
|
-
var
|
|
4577
|
+
var ce = s.contamination_exit || {}, hr = s.handover_rerun || {};
|
|
4535
4578
|
var rs = s.retrieval_serve || {};
|
|
4536
|
-
var rle =
|
|
4537
|
-
var vs =
|
|
4538
|
-
var
|
|
4579
|
+
var rle = {}; // The avoided reload is diagnostic, not a credited saving.
|
|
4580
|
+
var vs = {};
|
|
4581
|
+
var vo = {};
|
|
4582
|
+
var cr = {}; // Historical restore sizes may include injected context.
|
|
4539
4583
|
var cp = s.counted_period || {};
|
|
4540
4584
|
var rereadMo = cp.available ? mo(cp.reread_usd) : 0;
|
|
4541
4585
|
var hf = s.hint_followed || {};
|
|
@@ -4548,32 +4592,29 @@ var DB = (function() {
|
|
|
4548
4592
|
var avoidedSearchN = hfHasData ? (Number(hf.events) || 0) : (Number(rs.served_sessions) || 0);
|
|
4549
4593
|
var avoidedSearchUnit = hfHasData ? 'hints used' : 'served';
|
|
4550
4594
|
var structMo = mo(sd.cost_saved_usd);
|
|
4551
|
-
var runtimeMo = Math.max(0, mo(s.total_cost_usd) - structMo) + mo(unc.cost_saved_usd)
|
|
4552
|
-
// behavioral holds every estimated behavioral item (
|
|
4595
|
+
var runtimeMo = Math.max(0, mo(s.total_cost_usd) - structMo) + mo(unc.cost_saved_usd);
|
|
4596
|
+
// behavioral holds every estimated behavioral item (loops + the cohort
|
|
4553
4597
|
// estimators + avoided-search), so the pillars (struct + runtime + behavioral)
|
|
4554
4598
|
// always reconcile exactly to gettingMo (measured + estimated). Every estItems
|
|
4555
4599
|
// entry maps to exactly one pillar: loops/sub-agent/mcp_cap -> runtime;
|
|
4556
4600
|
// heeded/handover/avoided-search/lean-resumes -> behavioral.
|
|
4557
|
-
var behavMo = mo(
|
|
4558
|
-
// ---- trust tiers: measured / estimated / opportunity. Opportunity
|
|
4559
|
-
//
|
|
4560
|
-
//
|
|
4561
|
-
|
|
4562
|
-
var routingEstimated = mr.evidence === 'estimated';
|
|
4563
|
-
var measuredMo = mo(s.total_cost_usd) + (routingEstimated ? 0 : mo(mr.realized_cost_usd));
|
|
4601
|
+
var behavMo = mo(beh.cost_saved_usd) + mo(ce.cost_saved_usd) + mo(hr.cost_saved_usd) + avoidedSearchMo + mo(rle.cost_saved_usd) + mo(vs.cost_saved_usd) + mo(cr.cost_saved_usd);
|
|
4602
|
+
// ---- trust tiers: measured / estimated / opportunity. Opportunity and the
|
|
4603
|
+
// routing assumption NEVER fold into the headline. ----
|
|
4604
|
+
// Measured = billable events we metered (runtime compression).
|
|
4605
|
+
var measuredMo = mo(s.total_cost_usd);
|
|
4564
4606
|
// Estimated = genuine TO-realized counterfactuals grounded in YOUR behavior; each carries a sample size.
|
|
4565
|
-
//
|
|
4607
|
+
// Pillars and estimated amounts reconcile to gettingMo.
|
|
4566
4608
|
var estItems = [
|
|
4567
|
-
{ key: 'routing_estimated', label: 'model routing', amt: routingEstimated ? mo(mr.realized_cost_usd) : 0, n: (mr.baseline_reference_priced || []).length, unit: 'model families on one newest-card price list' },
|
|
4568
4609
|
{ key: 'behavioral_estimate', label: 'loops prevented', amt: mo(beh.cost_saved_usd), n: Number(beh.loop_events) || 0, unit: 'events' },
|
|
4569
4610
|
{ key: 'uncaptured_runtime', label: 'sub-agent runtime', amt: mo(unc.cost_saved_usd), n: Number(unc.subagent_dispatches) || 0, unit: 'dispatches' },
|
|
4570
|
-
{ key: 'mcp_cap_estimated', label: 'MCP output cap', amt: mo(mce.cost_saved_usd), n: Number(mce.events) || 0, unit: 'capped results' },
|
|
4571
4611
|
{ key: 'contamination_exit', label: 'avoided rework (heeded nudges)', amt: mo(ce.cost_saved_usd), n: Number(ce.heeded_sessions) || 0, unit: 'heeded', conf: ce.confidence },
|
|
4572
4612
|
{ key: 'handover_rerun', label: 'continuity handover', amt: mo(hr.cost_saved_usd), n: Number(hr.restored_sessions) || 0, unit: 'restored', conf: hr.confidence },
|
|
4573
4613
|
{ key: 'avoided_search', label: 'avoided search (hints)', amt: avoidedSearchMo, n: avoidedSearchN, unit: avoidedSearchUnit, conf: hfHasData ? 'trigger observed, size estimated' : rs.confidence },
|
|
4574
|
-
{ key: 'resume_lean_estimated', label: 'lean resumes (cold reload avoided)', amt: mo(rle.cost_saved_usd), n: Number(rle.events) || 0, unit: 'resumes' },
|
|
4575
4614
|
{ key: 'checkpoint_restore_estimated', label: 'checkpoint restores (working-set re-reads)', amt: mo(cr.cost_saved_usd), n: Number(cr.events) || 0, unit: 'restores' },
|
|
4576
|
-
{ key: 'verbosity_steer', label: 'concise output nudges', amt: mo(vs.cost_saved_usd), n: Number(vs.events) || 0, unit: 'nudges' }
|
|
4615
|
+
{ key: 'verbosity_steer', label: 'concise output nudges', amt: mo(vs.cost_saved_usd), n: Number(vs.events) || 0, unit: 'nudges' },
|
|
4616
|
+
{ key: 'verbosity_output_estimated', label: 'shorter replies and their re-reads (net of un-nudged replies)', amt: mo(vo.cost_saved_usd), n: Number(vo.events) || 0, unit: 'calibrated nudges',
|
|
4617
|
+
conf: vo.basis === 'no_reduction_net_of_control' ? 'no reduction net of the control' : (vo.basis === 'not_measured' && vo.events ? 'NOT MEASURED: no un-nudged control yet' : undefined) }
|
|
4577
4618
|
].filter(function(it){ return it.amt > 0 || it.conf; });
|
|
4578
4619
|
var estimatedMo = estItems.reduce(function(a, b){ return a + b.amt; }, 0);
|
|
4579
4620
|
// What you're getting = measured + estimated (both real value; estimated shown split-out, never hidden).
|
|
@@ -4582,9 +4623,9 @@ var DB = (function() {
|
|
|
4582
4623
|
// retain the component calculation above until their next regeneration.
|
|
4583
4624
|
var actionSavings = s.action_savings;
|
|
4584
4625
|
if (actionSavings) {
|
|
4585
|
-
measuredMo = mo(actionSavings.logged_usd) + mo(actionSavings.
|
|
4626
|
+
measuredMo = mo(actionSavings.logged_usd) + mo(actionSavings.class_premium_usd || 0);
|
|
4586
4627
|
rereadMo = mo(actionSavings.reread_usd);
|
|
4587
|
-
estimatedMo = mo(actionSavings.estimated_usd)
|
|
4628
|
+
estimatedMo = mo(actionSavings.estimated_usd);
|
|
4588
4629
|
gettingMo = mo(actionSavings.total_usd);
|
|
4589
4630
|
}
|
|
4590
4631
|
// Whole-cent display values from the payload: the parts shown on the card
|
|
@@ -4596,11 +4637,11 @@ var DB = (function() {
|
|
|
4596
4637
|
var estSumCents = Object.keys(de).reduce(function(a, k) { return a + de[k]; }, 0);
|
|
4597
4638
|
exactCents = {
|
|
4598
4639
|
total: dispCents.total_cents,
|
|
4599
|
-
logged: dc.logged + dc.
|
|
4640
|
+
logged: dc.logged + (Number(dc.class_premium) || 0),
|
|
4641
|
+
premium: Number(dc.class_premium) || 0,
|
|
4600
4642
|
reread: dc.reread,
|
|
4601
|
-
other: estSumCents
|
|
4643
|
+
other: estSumCents,
|
|
4602
4644
|
est: de,
|
|
4603
|
-
routingEstimated: dc.routing_estimated,
|
|
4604
4645
|
avoidedKey: actionSavings.avoided_search_source
|
|
4605
4646
|
};
|
|
4606
4647
|
}
|
|
@@ -4609,14 +4650,20 @@ var DB = (function() {
|
|
|
4609
4650
|
}
|
|
4610
4651
|
function estCents(item) {
|
|
4611
4652
|
var key = item.key === 'avoided_search' ? exactCents.avoidedKey : item.key;
|
|
4612
|
-
return
|
|
4653
|
+
return exactCents.est[key];
|
|
4613
4654
|
}
|
|
4614
4655
|
// Opportunity = realizable if you act; never realized, never summed into "getting".
|
|
4615
4656
|
// output-waste is $ here; cache-drop is shown separately in TOKENS (re-written prefix) —
|
|
4616
4657
|
// its $ is Anthropic-specific (OpenAI/OpenCode cache writes are free), but the token count
|
|
4617
4658
|
// is a provider-neutral fact, matching Claude Code's own token-denominated display.
|
|
4618
4659
|
var recl = s.stale_reads_reclaimable || {};
|
|
4619
|
-
var cdTokensMo = Math.round((Number(cd.
|
|
4660
|
+
var cdTokensMo = Math.round((Number(cd.rebuilt_tokens) > 0 ? Number(cd.rebuilt_tokens)
|
|
4661
|
+
: (Number(cd.est_drops) || 0) * (Number(cd.prefix_tokens) || 0)) / Math.max(days, 1) * 30);
|
|
4662
|
+
// The cache TTL this user's own writes show: 1 hour (Claude Code) or 5 minutes.
|
|
4663
|
+
var cdShortTtl = Number(cd.ttl_seconds) > 0 && Number(cd.ttl_seconds) < 3600;
|
|
4664
|
+
var cdCacheName = cdShortTtl ? 'the 5-minute cache' : (Number(cd.ttl_seconds) >= 3600 ? 'the 1-hour cache' : 'the cache window');
|
|
4665
|
+
var cdResume = cdShortTtl ? 'Resume within 5 minutes' : 'Resume within the hour';
|
|
4666
|
+
var cdRebuilds = Number(cd.est_drops) || 0;
|
|
4620
4667
|
// The big opportunity number holds only evidence-backed items (unused skills,
|
|
4621
4668
|
// stale re-reads, full-file Writes). Routing rests on an assumed share of your
|
|
4622
4669
|
// Opus work, so it gets its own line below the number and is never added in.
|
|
@@ -4645,117 +4692,33 @@ var DB = (function() {
|
|
|
4645
4692
|
var routingTarget = mr.target_model || "Sonnet";
|
|
4646
4693
|
var unusedSkills = Number(sp.unused_skills) || 0;
|
|
4647
4694
|
var currOpus = Math.round((Number(mr.current_opus_share) || 0) * 100);
|
|
4695
|
+
var fmtPct = function(x) { return Math.round((Number(x) || 0) * 1000) / 10; };
|
|
4696
|
+
var routingRealizedMo = mo(actionSavings && actionSavings.routing_usd != null
|
|
4697
|
+
? actionSavings.routing_usd : mr.realized_cost_usd);
|
|
4698
|
+
var routingBaselinePct = fmtPct(mr.baseline_opus_share);
|
|
4699
|
+
var routingAssumption = (mr.baseline_provenance && mr.baseline_provenance.short) ? String(mr.baseline_provenance.short)
|
|
4700
|
+
: mr.baseline_source === 'pretool_baseline'
|
|
4701
|
+
? 'assuming ' + routingBaselinePct + '% Opus before Token Optimizer'
|
|
4702
|
+
: (mr.baseline_opus_share != null
|
|
4703
|
+
? 'against a measured ' + routingBaselinePct + '% Opus baseline'
|
|
4704
|
+
: 'against an Opus baseline');
|
|
4705
|
+
var routingAltShare = mr.measured_baseline_opus_share;
|
|
4706
|
+
var routingAltMo = mr.measured_baseline_realized_cost_usd != null ? mo(mr.measured_baseline_realized_cost_usd) : null;
|
|
4648
4707
|
var ts = data.generated_at ? new Date(data.generated_at).toLocaleString() : 'unknown';
|
|
4708
|
+
// U9: the savings story leads when the payload carries session_effect;
|
|
4709
|
+
// older payloads (or a template without the inlined module) keep the
|
|
4710
|
+
// previous layout unchanged.
|
|
4711
|
+
var story = '';
|
|
4712
|
+
try { story = (typeof savingsStoryHtml === 'function') ? savingsStoryHtml(data) : ''; } catch (e) { story = ''; }
|
|
4649
4713
|
|
|
4650
4714
|
var html = '<div class="section-header">' +
|
|
4651
|
-
'<div class="label">Value</div><h1>Savings</h1>' +
|
|
4652
|
-
|
|
4715
|
+
(story ? '<h1>Savings</h1>' : '<div class="label">Value</div><h1>Savings</h1>' +
|
|
4716
|
+
'<p>Your savings, with the time period and method shown for each total.</p>') +
|
|
4653
4717
|
'</div>' +
|
|
4654
4718
|
'<div class="last-updated">Updated ' + esc(ts) + ' · refreshes after every session</div>';
|
|
4655
4719
|
|
|
4656
|
-
html += runwayCardHtml();
|
|
4657
|
-
|
|
4658
|
-
// ---- HERO: the before/after transformation (THE headline). Current activity priced at
|
|
4659
|
-
// your pre-TO per-session weight + mix vs actual — comprehensive (volume + structural +
|
|
4660
|
-
// routing + sub-agents), grounded in your own earliest-vs-recent sessions. ----
|
|
4661
|
-
var ba = s.before_after || {};
|
|
4662
|
-
if (Number(ba.monthly_savings_usd) > 0) {
|
|
4663
|
-
var wp = ba.session_weight_pool || null;
|
|
4664
|
-
var wpUnit = (wp && wp.work_unit === 'message') ? 'message' : 'API call';
|
|
4665
|
-
var oldCost = Number(ba.counterfactual_monthly_usd) || 0;
|
|
4666
|
-
var nowCost = Number(ba.actual_monthly_usd) || 0;
|
|
4667
|
-
// Use the displayed saving so a spend-capped headline cannot retain the
|
|
4668
|
-
// larger, uncapped percentage implied by the counterfactual arms.
|
|
4669
|
-
var shownSaving = Number(ba.monthly_savings_usd) || 0;
|
|
4670
|
-
var costCut = oldCost > 0 ? Math.max(0, shownSaving / oldCost * 100) : 0;
|
|
4671
|
-
// A neutral add-back reprice (routing pending or unavailable) shrinks the
|
|
4672
|
-
// transformation figure without any visible reason -- say why, plainly.
|
|
4673
|
-
var baRepriceBasis = ba.compression_reprice_basis;
|
|
4674
|
-
var baRepriceNote = (baRepriceBasis === 'routing_pending')
|
|
4675
|
-
? 'Model-mix repricing is paused while sessions finish re-measuring, so the add-backs in this estimate show their measured value.'
|
|
4676
|
-
: (baRepriceBasis === 'routing_unavailable'
|
|
4677
|
-
? 'Model-mix repricing could not be measured, so the add-backs in this estimate show their measured value.'
|
|
4678
|
-
: '');
|
|
4679
|
-
html += '<div class="card wide savings-transformation" style="padding:var(--s-4);margin-bottom:var(--s-3);">' +
|
|
4680
|
-
'<div class="label">Transformation · last ' + days + ' days · estimated</div>' +
|
|
4681
|
-
'<div class="savings-amount">' + money(ba.monthly_savings_usd) +
|
|
4682
|
-
'<span class="savings-unit"> saved · ~' + Math.round(costCut) + '% lower cost</span></div>' +
|
|
4683
|
-
'<p class="lede">Your recent workload compared with your earlier way of working, at the same token prices.</p>' +
|
|
4684
|
-
'<div class="savings-split"><span>Now <strong>' + money(nowCost) + '</strong></span>' +
|
|
4685
|
-
'<span>Earlier workflow <strong>' + money(oldCost) + '</strong></span></div>' +
|
|
4686
|
-
'<div class="plain-line">Overlaps with the action savings below. Do not add the two totals.</div>' +
|
|
4687
|
-
(baRepriceNote ? '<div class="plain-line">' + baRepriceNote + '</div>' : '') +
|
|
4688
|
-
fold('How this is estimated',
|
|
4689
|
-
countedList([ba.savings_capped && ba.savings_cap_note ? esc(ba.savings_cap_note) : '']) +
|
|
4690
|
-
(wp
|
|
4691
|
-
? '<p>Baseline: <strong>' + esc(wp.anchor_month) + '</strong>. We compare cost per ' + wpUnit +
|
|
4692
|
-
' at constant prices, then apply the difference to the <strong>' +
|
|
4693
|
-
(Number(wp.now_units) || 0).toLocaleString() + '</strong> ' + wpUnit +
|
|
4694
|
-
's in this period. Current cost: ' + money(Number(wp.after_cost_per_unit)) +
|
|
4695
|
-
' per ' + wpUnit + '; baseline: ' + money(Number(wp.before_cost_per_unit)) + '.</p>' +
|
|
4696
|
-
'<p>More, smaller sessions are not counted as dollar savings. Changes in model prices and model mix are excluded. ' +
|
|
4697
|
-
'Delegated work attached to a main session is included in its cost; it is not added again.</p>'
|
|
4698
|
-
: '<p>We price your frozen baseline session using your earlier and current model and cache patterns, ' +
|
|
4699
|
-
'then scale the difference to this period. Context savings and normalized delegated work complete the estimate.</p>') +
|
|
4700
|
-
'<p>This comparison includes changes in your own habits. It cannot isolate Token Optimizer’s contribution. ' +
|
|
4701
|
-
'An API call is a workload proxy, not a measure of task difficulty or quality.</p>' +
|
|
4702
|
-
'<p>' + billingCaption + '</p>') +
|
|
4703
|
-
'</div>';
|
|
4704
|
-
} else if (ba.baseline_building) {
|
|
4705
|
-
// New install: no frozen baseline yet, so the headline transformation can't be
|
|
4706
|
-
// computed. Explain WHY (it uses the user's OWN history, never a fake anchor) and
|
|
4707
|
-
// show progress, instead of silently rendering nothing and leaving only the small
|
|
4708
|
-
// measured floor below (which reads as "TO only saved me $X").
|
|
4709
|
-
var bb = ba.baseline_building;
|
|
4710
|
-
var sNeed = Number(bb.sessions_needed) || 30;
|
|
4711
|
-
var sHave = Math.min(sNeed, Number(bb.sessions_in_window) || 0);
|
|
4712
|
-
var dLeft = Number(bb.days_left) || 0;
|
|
4713
|
-
var pct = sNeed > 0 ? Math.min(100, Math.round(sHave / sNeed * 100)) : 0;
|
|
4714
|
-
html += '<div class="card wide" style="padding:var(--s-5) var(--s-4);margin-bottom:var(--s-3);border:1px solid var(--c-accent-blue);box-shadow:0 0 0 1px rgba(0,102,255,0.12);">' +
|
|
4715
|
-
'<div class="label" style="margin-bottom:var(--s-2);color:var(--c-accent-cyan);">Your savings baseline is still building</div>' +
|
|
4716
|
-
'<div class="lede">Token Optimizer measures your savings against <strong>your own</strong> pre-optimization baseline, frozen from your first ' + (Number(bb.early_window_days) || 30) + ' days of real sessions. It never uses anyone else\'s numbers, and never freezes a half-formed anchor.</div>' +
|
|
4717
|
-
'<div class="lede" style="margin-top:var(--s-2);"><strong>' + sHave + ' of ~' + sNeed + ' sessions</strong> collected in your baseline window' + (dLeft > 0 ? ', about <strong>' + dLeft + ' day' + (dLeft === 1 ? '' : 's') + '</strong> until it locks in' : '') + '. Until then, the figure below is the directly-metered floor, not your full savings.</div>' +
|
|
4718
|
-
'<div style="margin-top:var(--s-4);height:8px;background:rgba(255,255,255,0.08);border-radius:4px;overflow:hidden;"><div style="height:100%;width:' + pct + '%;background:var(--c-accent-cyan);box-shadow:0 0 12px var(--c-accent-glow);transition:width .3s;"></div></div>' +
|
|
4719
|
-
'</div>';
|
|
4720
|
-
} else if (ba.reason === 'net_negative') {
|
|
4721
|
-
// Baseline is frozen, but efficiency was flat-to-negative this period (now costs about
|
|
4722
|
-
// the same as — or slightly more than — the frozen baseline would have). We show NO
|
|
4723
|
-
// counterfactual headline (a saving we didn't make), just an honest neutral note plus
|
|
4724
|
-
// the arms; the directly-metered floor card below still reports realized savings. This
|
|
4725
|
-
// is the net<=0 branch — parity with OpenClaw/OpenCode.
|
|
4726
|
-
html += '<div class="card wide" style="padding:var(--s-5) var(--s-4);margin-bottom:var(--s-3);">' +
|
|
4727
|
-
'<div class="label" style="margin-bottom:var(--s-2);">At or above your baseline this period</div>' +
|
|
4728
|
-
'<div class="lede">Your recent sessions cost about what your frozen baseline would have — est. <strong>' + money(ba.actual_monthly_usd) + '/mo</strong> now vs <strong>' + money(ba.counterfactual_monthly_usd) + '/mo</strong> the old way. There is no net saving to headline this period, so we are not showing one. The figure below is what Token Optimizer counted directly, action by action.</div>' +
|
|
4729
|
-
'</div>';
|
|
4730
|
-
} else if (ba.reason === 'flat') {
|
|
4731
|
-
// Both work-unit methods sit within a few percent of spend: no
|
|
4732
|
-
// measurable whole-workload change, so no headline and no scary number.
|
|
4733
|
-
html += '<div class="card wide" style="padding:var(--s-5) var(--s-4);margin-bottom:var(--s-3);">' +
|
|
4734
|
-
'<div class="label" style="margin-bottom:var(--s-2);">No measurable change in cost per unit of work</div>' +
|
|
4735
|
-
'<div class="plain-line">Your recent work costs about the same per request as before install (' + money(ba.actual_monthly_usd) + '/mo now vs ' + money(ba.counterfactual_monthly_usd) + '/mo the old way). The savings below are counted action by action.</div>' +
|
|
4736
|
-
'</div>';
|
|
4737
|
-
} else if (ba.reason === 'methods_disagree') {
|
|
4738
|
-
// The two independent work-unit methods (per-API-call and per-message)
|
|
4739
|
-
// landed more than 10% apart, so neither figure is trustworthy enough to
|
|
4740
|
-
// headline. Show both, headline nothing; the metered floor card below
|
|
4741
|
-
// still reports realized savings. Same neutral-card shape as
|
|
4742
|
-
// net_negative, with signed money for the cross-check figure.
|
|
4743
|
-
var swp = ba.session_weight_pool || {};
|
|
4744
|
-
var swpCross = swp.crosscheck || {};
|
|
4745
|
-
var mainUsd = Number(swp.transformation_usd) || 0;
|
|
4746
|
-
var crossUsd = Number(swpCross.transformation_usd) || 0;
|
|
4747
|
-
var mainUnit = swp.work_unit === 'message' ? 'per-message' : 'per-API-call';
|
|
4748
|
-
var crossUnit = swpCross.unit === 'api_call' ? 'per-API-call' : 'per-message';
|
|
4749
|
-
var signedMoney = function (n) {
|
|
4750
|
-
var v = Number(n) || 0;
|
|
4751
|
-
return (v < 0 ? '-' : '') + money(Math.abs(v));
|
|
4752
|
-
};
|
|
4753
|
-
html += '<div class="card wide" style="padding:var(--s-5) var(--s-4);margin-bottom:var(--s-3);">' +
|
|
4754
|
-
'<div class="label" style="margin-bottom:var(--s-2);">Two estimates disagree this period</div>' +
|
|
4755
|
-
'<div class="lede">The ' + mainUnit + ' estimate is <strong>' + signedMoney(mainUsd) + '/mo</strong> and the ' + crossUnit +
|
|
4756
|
-
' estimate is <strong>' + signedMoney(crossUsd) + '/mo</strong>. They are too far apart to headline either one. The figure below is what Token Optimizer counted directly, action by action.</div>' +
|
|
4757
|
-
'</div>';
|
|
4758
|
-
}
|
|
4720
|
+
html += story || runwayCardHtml();
|
|
4721
|
+
var storyHead = html; html = '';
|
|
4759
4722
|
|
|
4760
4723
|
// ---- Tokens Saved card: the full card (hero + spent-vs-saved + model-
|
|
4761
4724
|
// mix-as-usage + footer). Rendered as the 2nd card in the Savings view,
|
|
@@ -4763,15 +4726,14 @@ var DB = (function() {
|
|
|
4763
4726
|
// "Counted directly" measured-floor card below. Also rendered in the
|
|
4764
4727
|
// Trends view — both call the shared hoisted tokensSavedCardHtml helper
|
|
4765
4728
|
// so the card is identical across views. SPENT = trends.total_tokens
|
|
4766
|
-
// (billable total)
|
|
4729
|
+
// (billable total); the savings total comes from savingsStoryBands. See tokensSavedCardHtml
|
|
4767
4730
|
// for the full fail-open spec. ----
|
|
4768
4731
|
// Add only rereads to the one-shot ledger. Adding the counted-period total
|
|
4769
4732
|
// would count its initial removals twice and discard unmatched logged events.
|
|
4770
4733
|
html += '<div style="display:flex;gap:var(--s-3);flex-wrap:wrap;margin-bottom:var(--s-3);">';
|
|
4771
4734
|
var periodLabel = runRate ? 'last ' + days + ' days' : trackedDays + ' days tracked';
|
|
4772
4735
|
var heroAmt = gettingMo;
|
|
4773
|
-
//
|
|
4774
|
-
// other counting note lives in the card's "Breakdown and method" fold.
|
|
4736
|
+
// Incomplete pricing is disclosed here; the full method is in the fold.
|
|
4775
4737
|
var actionPricingIncomplete = !!(cp.reread_pricing_note ||
|
|
4776
4738
|
(actionSavings && actionSavings.reread_prices_available === false) || cp.reread_prices_available === false ||
|
|
4777
4739
|
Number(s.compression_unpriced_tokens) > 0 ||
|
|
@@ -4779,18 +4741,17 @@ var DB = (function() {
|
|
|
4779
4741
|
html += '<div class="card savings-actions" style="flex:2;min-width:min(100%,320px);padding:var(--s-4);">' +
|
|
4780
4742
|
'<div class="label">Action savings · ' + periodLabel + '</div>' +
|
|
4781
4743
|
'<div class="savings-amount">' + (exactCents ? moneyCents(exactCents.total) : money(periodValue(heroAmt))) + '<span class="savings-unit"> logged + estimated</span></div>' +
|
|
4744
|
+
(s.token_headline ? '<p class="plain-line">~' + fmtTok(s.token_headline.total_tokens) + ' tokens kept out of context · ' + tokenSplitText(s.token_headline, fmtTok) + ' (estimated)' + (s.token_headline.refresh_incomplete_events || s.token_headline.unmeasured_events ? ', incomplete coverage' : '') + '.</p>' : '') +
|
|
4782
4745
|
'<div class="savings-split"><span>Logged actions <strong>' + (exactCents ? moneyCents(exactCents.logged) : money(periodValue(measuredMo))) + '</strong></span>' +
|
|
4783
|
-
|
|
4784
|
-
(
|
|
4785
|
-
((actionSavings && actionSavings.reread_prices_available === false) || cp.reread_prices_available === false ?
|
|
4786
|
-
'Unpriced' : '~' + (exactCents ? moneyCents(exactCents.reread) : money(periodValue(rereadMo))))) + '</strong></span>' +
|
|
4746
|
+
((!cp.available && !(actionSavings && actionSavings.reread_available === true)) || (actionSavings && (actionSavings.reread_available === false || actionSavings.reread_prices_available === false)) || cp.reread_prices_available === false ? '' :
|
|
4747
|
+
'<span>Repeat reads avoided <strong>~' + (exactCents ? moneyCents(exactCents.reread) : money(periodValue(rereadMo))) + '</strong></span>') +
|
|
4787
4748
|
'<span>Other estimates <strong>~' + (exactCents ? moneyCents(exactCents.other) : money(periodValue(estimatedMo))) + '</strong></span></div>' +
|
|
4749
|
+
(Number(routingRealizedMo) > 0
|
|
4750
|
+
? '<p class="plain-line"><strong>Model routing:</strong> ~' + money(periodValue(routingRealizedMo)) + esc(per) +
|
|
4751
|
+
' ' + esc(routingAssumption) + (currOpus ? ' (now ' + currOpus + '% Opus)' : '') + '. Not in this total.</p>' : '') +
|
|
4788
4752
|
(actionPricingIncomplete
|
|
4789
4753
|
? '<p class="plain-line">Some older history has no exact price, so this is a priced subtotal.</p>'
|
|
4790
4754
|
: (!cp.available ? '<p class="plain-line">Repeat reads are not available here. Logged actions are still counted.</p>' : '')) +
|
|
4791
|
-
(mr.evidence === 'pending'
|
|
4792
|
-
? '<p class="plain-line routing-pending">Model routing: re-measuring (' + Number(mr.pending_sessions || 0).toLocaleString() +
|
|
4793
|
-
' session' + (Number(mr.pending_sessions) === 1 ? '' : 's') + ' left). It is added to this total when the re-measurement finishes.</p>' : '') +
|
|
4794
4755
|
// Usage without a token-class split (Cursor totals, model-daily-only
|
|
4795
4756
|
// history, legacy rows) sits outside both routing arms. Say so instead of
|
|
4796
4757
|
// letting an empty or partial routing figure read as complete coverage.
|
|
@@ -4799,6 +4760,7 @@ var DB = (function() {
|
|
|
4799
4760
|
' tokens without a token-class split are left out of model routing.</p>' : '') +
|
|
4800
4761
|
fold('Breakdown and method',
|
|
4801
4762
|
countedList([
|
|
4763
|
+
s.token_type_breakdown && Object.keys(s.token_type_breakdown).length ? 'Token types cover only ledger events with recorded turn classes. Repeat reads are modeled as cache reads except for detected cache rebuilds; write totals include detected rebuilds and initial removals recorded at a write rate. Unclassified tokens are excluded.' : '',
|
|
4802
4764
|
'Includes the later benefit of context removed during this period. Initial removals are counted once.',
|
|
4803
4765
|
cp.reread_pricing_note ? esc(cp.reread_pricing_note) : '',
|
|
4804
4766
|
actionSavings && actionSavings.total_clamped ? 'Signed adjustments give a net total of ' +
|
|
@@ -4813,13 +4775,19 @@ var DB = (function() {
|
|
|
4813
4775
|
Math.round(Number(s.reprice_detail.unpriced_tokens)).toLocaleString() +
|
|
4814
4776
|
' logged tokens ran on models with no known rate; their dollar value is not included.' : '',
|
|
4815
4777
|
op.removal_events > 0 ? 'Initial removals above are priced at the input rate, a minimum.' +
|
|
4816
|
-
(
|
|
4817
|
-
?
|
|
4818
|
-
|
|
4819
|
-
|
|
4778
|
+
(actionSavings && 'class_premium_usd' in actionSavings
|
|
4779
|
+
? (Number(actionSavings.class_premium_usd) >= 0.005
|
|
4780
|
+
? ' The next call billed new context at a cache-write rate for ' +
|
|
4781
|
+
Math.round(Number(op.class_events) || 0).toLocaleString() + ' removals. That write-class premium, ' +
|
|
4782
|
+
(exactCents ? moneyCents(exactCents.premium) : money(periodValue(mo(actionSavings.class_premium_usd)))) +
|
|
4783
|
+
', is measured and included in Logged actions.' : '')
|
|
4784
|
+
: (Number(op.class_premium_usd) >= 0.005
|
|
4785
|
+
? ' The next call billed new context at a cache-write rate for ' +
|
|
4786
|
+
Math.round(Number(op.class_events) || 0).toLocaleString() + ' removals: about ' +
|
|
4787
|
+
money(Number(op.class_premium_usd)) + ' more, not in the total.' : '')) : '',
|
|
4820
4788
|
!cp.available ? 'Repeat-read coverage is unavailable here; logged actions are still included.' : ''
|
|
4821
4789
|
]) +
|
|
4822
|
-
'<p>Logged actions include output trims, context reductions
|
|
4790
|
+
'<p>Logged actions include output trims, context reductions and setup changes. ' +
|
|
4823
4791
|
'Prices may be allocated from each session’s recorded model mix.</p>' +
|
|
4824
4792
|
'<p>Repeat reads use recorded later turns up to each session’s next compaction. ' +
|
|
4825
4793
|
'This assumes the removed context would otherwise have stayed until that compaction. ' +
|
|
@@ -4834,7 +4802,10 @@ var DB = (function() {
|
|
|
4834
4802
|
((mr.baseline_reference_priced || []).length
|
|
4835
4803
|
? '<p>Routing compares your earlier and current mix on one price list, the newest card of each family (' +
|
|
4836
4804
|
esc(mr.baseline_reference_priced.map(function(f) { return f.charAt(0).toUpperCase() + f.slice(1); }).join(', ')) +
|
|
4837
|
-
'), because your earlier mix records no model generations.
|
|
4805
|
+
'), because your earlier mix records no model generations. It is shown separately from the totals above.</p>' : '') +
|
|
4806
|
+
(routingAltShare != null
|
|
4807
|
+
? '<p>Measured alternative: your earliest tracked month had ' + fmtPct(routingAltShare) + '% Opus' +
|
|
4808
|
+
(routingAltMo != null ? '; the same comparison gives ~' + money(periodValue(routingAltMo)) + esc(per) : '') + '.</p>' : '') +
|
|
4838
4809
|
(Math.abs(mo(mr.generation_price_delta_usd)) >= 0.01
|
|
4839
4810
|
? '<p>At the exact cards you ran, the same work cost about ' + money(Math.abs(mo(mr.generation_price_delta_usd))) +
|
|
4840
4811
|
(Number(mr.generation_price_delta_usd) > 0 ? ' more' : ' less') +
|
|
@@ -4862,27 +4833,36 @@ var DB = (function() {
|
|
|
4862
4833
|
var sia = (si && si.all_in) || null;
|
|
4863
4834
|
if (sia && Number(sia.total_usd) > 0) {
|
|
4864
4835
|
var siaParts = sia.components_usd || {};
|
|
4865
|
-
var siaRouting = (Number(siaParts.routing_measured) || 0) + (Number(siaParts.routing_estimated) || 0);
|
|
4836
|
+
var siaRouting = Number(sia.routing_usd) || ((Number(siaParts.routing_measured) || 0) + (Number(siaParts.routing_estimated) || 0));
|
|
4837
|
+
var siaRoutingNote = (sia.routing_baseline_provenance && sia.routing_baseline_provenance.short) ? String(sia.routing_baseline_provenance.short)
|
|
4838
|
+
: sia.routing_baseline_opus_share != null
|
|
4839
|
+
? ((sia.routing_baseline_source === 'stated' || sia.routing_baseline_source === 'pretool_baseline' ? 'assuming ' : 'against a measured ') +
|
|
4840
|
+
fmtPct(sia.routing_baseline_opus_share) + '% Opus' +
|
|
4841
|
+
(sia.routing_baseline_source === 'stated' || sia.routing_baseline_source === 'pretool_baseline' ? ' before Token Optimizer' : ' baseline'))
|
|
4842
|
+
: 'an estimate';
|
|
4866
4843
|
var siaPending = sia.routing_pending || sia.remeasuring;
|
|
4867
4844
|
var siaLeft = Math.max(Number(sia.routing_pending_sessions) || 0, Number(sia.remeasuring_sessions) || 0);
|
|
4868
4845
|
html += '<div class="card savings-history" style="flex:1;min-width:min(100%,260px);padding:var(--s-4);">' +
|
|
4869
4846
|
'<div class="label">Saved since ' + esc(prettyDate(si.install_date)) + '</div>' +
|
|
4870
4847
|
'<div class="savings-amount">' + money(sia.total_usd) +
|
|
4871
4848
|
(siaPending ? ' <span class="remeasuring-tag" style="font-size:0.45em;color:var(--c-text-dim);">so far</span>' : '') + '</div>' +
|
|
4872
|
-
(siaPending ? '<p class="plain-line remeasuring">
|
|
4849
|
+
(siaPending ? '<p class="plain-line remeasuring">Updating older history (' + siaLeft.toLocaleString() +
|
|
4873
4850
|
' session' + (siaLeft === 1 ? '' : 's') + ' left). This total will grow when they finish.</p>' : '') +
|
|
4874
|
-
'<p class="plain-line">Same
|
|
4851
|
+
'<p class="plain-line">Same parts as the monthly total, added up since install.</p>' +
|
|
4875
4852
|
fold('Breakdown and history',
|
|
4876
|
-
'<p>Model routing: <strong>' + money(siaRouting) + '</strong> (
|
|
4853
|
+
'<p>Model routing: <strong>' + money(siaRouting) + '</strong> (' + esc(siaRoutingNote) + '), not in the total above.</p>' +
|
|
4854
|
+
(sia.routing_measured_baseline_opus_share != null
|
|
4855
|
+
? '<p>Measured alternative: your earliest tracked month had ' + fmtPct(sia.routing_measured_baseline_opus_share) + '% Opus' +
|
|
4856
|
+
(sia.routing_measured_baseline_realized_cost_usd != null ? '; the same comparison gives ' + money(sia.routing_measured_baseline_realized_cost_usd) : '') + '.</p>' : '') +
|
|
4877
4857
|
(Number(sia.routing_unsplit_tokens) > 0
|
|
4878
4858
|
? '<p>' + Number(sia.routing_unsplit_tokens).toLocaleString() +
|
|
4879
4859
|
' tokens without a token-class split are left out of model routing.</p>' : '') +
|
|
4880
4860
|
'<p>Repeat reads avoided: <strong>' + money(siaParts.reread) + '</strong> (modeled).</p>' +
|
|
4881
|
-
'<p>Logged actions: <strong>' + money(siaParts.logged) + '</strong>.</p>' +
|
|
4861
|
+
'<p>Logged actions: <strong>' + money((Number(siaParts.logged) || 0) + (Number(siaParts.class_premium) || 0)) + '</strong>.</p>' +
|
|
4882
4862
|
'<p>Other estimates: <strong>' + money(sia.estimated_usd) + '</strong>.</p>' +
|
|
4883
|
-
((Number(cc.total_usd) > 0 || cc.available) ?
|
|
4863
|
+
((Number(cc.total_usd) > 0 || cc.available) && cc.prices_available !== false ?
|
|
4884
4864
|
'<p>Context trimming on its own (initial removals + repeat reads): ' +
|
|
4885
|
-
|
|
4865
|
+
money(Math.max(0, Number(cc.total_usd) || 0)) + '.</p>' : '') +
|
|
4886
4866
|
countedList([
|
|
4887
4867
|
cc.pricing_note ? esc(cc.pricing_note) : '',
|
|
4888
4868
|
cc.media_note ? esc(cc.media_note) : ''
|
|
@@ -4890,14 +4870,14 @@ var DB = (function() {
|
|
|
4890
4870
|
'<p>Tracked over ' + Number(si.days || 0).toLocaleString() + ' days. Historical entries remain after their source transcripts rotate.</p>' +
|
|
4891
4871
|
'<p>' + billingCaption + '</p>') +
|
|
4892
4872
|
'</div>';
|
|
4893
|
-
} else if (Number(cc.total_usd) > 0 || (cc.available && Number(cc.events) > 0)) {
|
|
4873
|
+
} else if (cc.prices_available !== false && (Number(cc.total_usd) > 0 || (cc.available && Number(cc.events) > 0))) {
|
|
4894
4874
|
html += '<div class="card savings-history" style="flex:1;min-width:min(100%,260px);padding:var(--s-4);">' +
|
|
4895
4875
|
'<div class="label">Context savings · all time</div>' +
|
|
4896
|
-
'<div class="savings-amount">' +
|
|
4876
|
+
'<div class="savings-amount">' + money(Math.max(0, Number(cc.total_usd) || 0)) +
|
|
4897
4877
|
(cc.remeasuring ? ' <span class="remeasuring-tag" style="font-size:0.45em;color:var(--c-text-dim);">so far</span>' : '') + '</div>' +
|
|
4898
|
-
(cc.remeasuring ? '<p class="plain-line remeasuring">
|
|
4878
|
+
(cc.remeasuring ? '<p class="plain-line remeasuring">Updating history (' + Number(cc.remeasuring_sessions || 0).toLocaleString() +
|
|
4899
4879
|
' session' + (Number(cc.remeasuring_sessions) === 1 ? '' : 's') + ' left). This subtotal is in progress and will change when they finish.</p>' : '') +
|
|
4900
|
-
'<p class="plain-line">' + (cp.available
|
|
4880
|
+
'<p class="plain-line">' + (cp.available && cp.prices_available !== false ? '<strong>' + money(cp.total_usd) + '</strong> from removals in the last ' + days + ' days. ' : '') +
|
|
4901
4881
|
'Overlaps with action savings.</p>' +
|
|
4902
4882
|
fold('History and coverage',
|
|
4903
4883
|
countedList([
|
|
@@ -4907,8 +4887,8 @@ var DB = (function() {
|
|
|
4907
4887
|
Number(cc.total_usd) < 0 ? 'Signed net: ' + money(cc.total_usd) + '. Savings headline is floored at zero.' : '',
|
|
4908
4888
|
'Excludes routing, setup and other estimates.'
|
|
4909
4889
|
]) +
|
|
4910
|
-
|
|
4911
|
-
|
|
4890
|
+
(cc.oneshot_prices_available === false ? '' : '<p>' + money(cc.oneshot_usd) + ' initial removals.</p>') +
|
|
4891
|
+
(cc.reread_prices_available === false ? '' : '<p>' + money(cc.reread_usd) + ' modeled repeat reads.</p>') +
|
|
4912
4892
|
'<p>Stored history since ' + esc(prettyDate(cc.window_start)) + '. ' +
|
|
4913
4893
|
'Same removal-date method as the period total. Historical entries remain after their source transcripts rotate.</p>' +
|
|
4914
4894
|
'<p>Repeat reads assume the removed context would otherwise have stayed until the session’s next compaction. ' +
|
|
@@ -4925,25 +4905,49 @@ var DB = (function() {
|
|
|
4925
4905
|
}
|
|
4926
4906
|
html += '</div>';
|
|
4927
4907
|
html += fold('Token savings and model usage', tokensSavedCardHtml(s));
|
|
4908
|
+
var ledgerHtml = html;
|
|
4909
|
+
html = storyHead + (story ? '' : ledgerHtml);
|
|
4928
4910
|
|
|
4929
4911
|
// ---- SAVE MORE: suggestions, promoted right under the hero ----
|
|
4930
4912
|
var parts = [];
|
|
4931
4913
|
if ((Number(sp.cost_saved_usd) || 0) > 0 && unusedSkills > 0) {
|
|
4932
|
-
parts.push('Review ' + unusedSkills + ' skill' + (unusedSkills === 1 ? '' : 's') + ' not invoked in this window.
|
|
4914
|
+
parts.push('Review ' + unusedSkills + ' skill' + (unusedSkills === 1 ? '' : 's') + ' not invoked in this window.');
|
|
4933
4915
|
}
|
|
4934
4916
|
if ((Number(recl.cost_usd) || 0) > 0) {
|
|
4935
4917
|
parts.push('Avoid re-reading files that have not changed, or add them to .contextignore. ' + (Number(recl.tokens) || 0).toLocaleString() + ' tokens of stale re-reads across ' + (Number(recl.sessions) || 0).toLocaleString() + ' sessions are worth about ' + moneyCents(oppCents.reclaimable) + per + '.');
|
|
4936
4918
|
}
|
|
4937
|
-
if ((Number(mr.potential_cost_usd) || 0) > 0) {
|
|
4919
|
+
if (!story && (Number(mr.potential_cost_usd) || 0) > 0) {
|
|
4938
4920
|
parts.push('Route routine work to lighter models and keep Opus for the work that needs it. The routing line above shows the size of that assumption.');
|
|
4939
4921
|
}
|
|
4940
4922
|
if (cdTokensMo > 0) {
|
|
4941
|
-
parts.push(
|
|
4923
|
+
parts.push(cdResume + ', or batch related work before stepping away. ' + (Number(cd.drop_sessions) || 0) + ' of your sessions idled past ' + cdCacheName + ' and re-wrote the prefix' + (cdRebuilds > 0 ? ' ' + cdRebuilds.toLocaleString() + ' time' + (cdRebuilds === 1 ? '' : 's') : '') + ', about ' + cdTokensMo.toLocaleString() + ' tokens' + per + (cdCostMo > 0 ? ', worth about ' + money(cdCostMo) + per + ' at API rates' : '') + '.');
|
|
4942
4924
|
}
|
|
4943
4925
|
if ((Number(ow.cost_saved_usd) || 0) > 0) {
|
|
4944
4926
|
parts.push('Favor targeted Edits over full-file Writes. About ' + (Number(ow.avoidable_writes) || 0) + ' of your Writes could have been Edits, worth about ' + moneyCents(oppCents.output) + per + ' in output.');
|
|
4945
4927
|
}
|
|
4946
|
-
|
|
4928
|
+
var moreFolds = [];
|
|
4929
|
+
if (story) {
|
|
4930
|
+
// U9: nothing else on the tab. Opportunity, coverage detail, the previous
|
|
4931
|
+
// cards and diagnostics sit in one row of folds at the bottom; the
|
|
4932
|
+
// whole-workload comparison is no longer shown here.
|
|
4933
|
+
if (parts.length > 0) {
|
|
4934
|
+
moreFolds.push('<details class="fold"><summary>Room to save more</summary><div class="fold__body">' +
|
|
4935
|
+
'<p>More changes you could make to your setup or habits, beyond Still on the table. None of this is in any total above.</p>' +
|
|
4936
|
+
parts.map(function(p) { return '<p>' + esc(p) + '</p>'; }).join('') +
|
|
4937
|
+
(data.runtime !== 'cursor' && data.runtime !== 'antigravity' ? '<p>Run <strong>/token-optimizer</strong> and follow its suggestions to claim it.</p>' : '') +
|
|
4938
|
+
'</div></details>');
|
|
4939
|
+
}
|
|
4940
|
+
var covFold = (typeof savingsCoverageFold === 'function') ? savingsCoverageFold(data) : '';
|
|
4941
|
+
if (covFold) moreFolds.push(covFold);
|
|
4942
|
+
// The previous action-savings, since-install and Tokens Saved cards are not
|
|
4943
|
+
// shown in story mode: they still add routing to their totals and count
|
|
4944
|
+
// tokens on another basis, so they would contradict the hero.
|
|
4945
|
+
var ledgerBody = (typeof savingsLedgerHtml === 'function') ? savingsLedgerHtml(data) : ledgerHtml;
|
|
4946
|
+
var mixTotal = 0, mix = (data.trends && data.trends.model_mix) || {};
|
|
4947
|
+
for (var mixK in mix) { mixTotal += Number(mix[mixK]) || 0; }
|
|
4948
|
+
if (mixTotal > 0 && typeof modelMixBodyHtml === 'function') ledgerBody += '<h3 class="ts-section-label st-gap">Which models did the work</h3>' + modelMixBodyHtml(mix, data.runtime === 'codex', mixTotal);
|
|
4949
|
+
moreFolds.push('<details class="fold"><summary>Full ledger and history</summary><div class="fold__body">' + ledgerBody + '</div></details>');
|
|
4950
|
+
} else if (parts.length > 0) {
|
|
4947
4951
|
html += '<div class="card wide" style="padding:var(--s-5) var(--s-4);margin-bottom:var(--s-3);border:1px solid var(--c-amber);box-shadow:0 0 0 1px rgba(217,164,65,0.18), 0 0 44px rgba(217,164,65,0.12);">';
|
|
4948
4952
|
html += '<div class="label" style="margin-bottom:var(--s-2);color:var(--c-amber);letter-spacing:0.08em;">Money on the table · opportunity</div>';
|
|
4949
4953
|
if (opportunityMo > 0) {
|
|
@@ -4957,11 +4961,11 @@ var DB = (function() {
|
|
|
4957
4961
|
}
|
|
4958
4962
|
if (cdTokensMo > 0) {
|
|
4959
4963
|
html += '<div class="cache-drop-opportunity" style="margin-top:var(--s-3);font-family:var(--font-mono);font-size:17px;line-height:1.6;color:var(--c-text-main);max-width:820px;">' +
|
|
4960
|
-
'Cache drops (an opportunity, not a measurement): ' + (Number(cd.drop_sessions) || 0) + ' sessions idled past
|
|
4964
|
+
'Cache drops (an opportunity, not a measurement): ' + (Number(cd.drop_sessions) || 0) + ' sessions idled past ' + cdCacheName + ' and re-wrote ~' + fmtTok(cdTokensMo) + ' tokens' + esc(per) + ' of prefix' +
|
|
4961
4965
|
(cdCostMo > 0 ? ', about <span style="color:var(--c-amber);">' + money(cdCostMo) + esc(per) + '</span> at API rates' : '') + '.' +
|
|
4962
4966
|
'</div>';
|
|
4963
4967
|
html += '<div class="plain-line">Not part of the savings number above.</div>';
|
|
4964
|
-
html += fold('How the cache drop figure is priced', '<p>
|
|
4968
|
+
html += fold('How the cache drop figure is priced', '<p>Each rebuild is the prefix the cache had held before the gap, priced at its own cache write rate (1 hour or 5 minutes) minus the cache read it would have cost, at the models you ran and at API rates. It is not part of the number above.</p>' + ((Number(cd.unscanned_large_sessions) || 0) > 0 ? '<p>' + Number(cd.unscanned_large_sessions) + ' very large session' + (Number(cd.unscanned_large_sessions) === 1 ? ' was' : 's were') + ' not scanned; savings there are understated.</p>' : ''));
|
|
4965
4969
|
}
|
|
4966
4970
|
if (routingPotentialMo > 0) {
|
|
4967
4971
|
html += '<div class="routing-assumption" style="margin-top:var(--s-3);font-family:var(--font-mono);font-size:17px;line-height:1.6;color:var(--c-text-main);max-width:820px;">' +
|
|
@@ -5022,7 +5026,7 @@ var DB = (function() {
|
|
|
5022
5026
|
trendTxt = dd > 3 ? 'trending up' : (dd < -3 ? 'trending down' : 'holding steady');
|
|
5023
5027
|
}
|
|
5024
5028
|
}
|
|
5025
|
-
if (avgQ !== null) {
|
|
5029
|
+
if (avgQ !== null && !story) {
|
|
5026
5030
|
var barPct = Math.min(100, Math.max(0, avgQ));
|
|
5027
5031
|
html += '<div class="card wide" style="margin-top:var(--s-3);"><div class="card-header"><span>Context quality · 30-day average</span>' +
|
|
5028
5032
|
(trendTxt ? '<span class="label">' + esc(trendTxt) + '</span>' : '') + '</div>';
|
|
@@ -5068,44 +5072,13 @@ var DB = (function() {
|
|
|
5068
5072
|
bucket.forEach(function(e) { ccHtml += covRow(e); });
|
|
5069
5073
|
ccHtml += '</div>';
|
|
5070
5074
|
});
|
|
5071
|
-
|
|
5072
|
-
if (pr) {
|
|
5073
|
-
var ready = pr.promotion_ready;
|
|
5074
|
-
ccHtml += '<div style="margin-top:var(--s-3);padding-top:var(--s-2);border-top:1px solid rgba(255,255,255,0.08);">' +
|
|
5075
|
-
'<div style="font-weight:500;">First-read skeleton — safety check</div>' +
|
|
5076
|
-
'<div class="plain-line">' + (Number(pr.edits_after_read) || 0) + ' of ' + (Number(pr.shadow_reads) || 0) +
|
|
5077
|
-
' large files were edited soon after the read (' + (Number(pr.edit_rate_pct) || 0).toFixed(1) + '%). ' +
|
|
5078
|
-
'Currently <strong>' + (ready ? 'ready to promote' : 'still measuring') + '</strong>.</div>' +
|
|
5079
|
-
fold('How this check works', '<p>' +
|
|
5080
|
-
'Of ' + (Number(pr.shadow_reads) || 0) + ' large files where a skeleton would have saved tokens, ' +
|
|
5081
|
-
(Number(pr.edits_after_read) || 0) + ' were edited soon after the read — an edit rate of ' +
|
|
5082
|
-
'<span style="font-family:var(--font-mono);color:' + (ready ? 'var(--c-accent-cyan)' : 'var(--c-text-main)') + ';">' + (Number(pr.edit_rate_pct) || 0).toFixed(1) + '%</span>. ' +
|
|
5083
|
-
'Skeletons turn on automatically only once this stays under ' + (Number(pr.promotion_gate_pct) || 15) + '% (the model rarely needed the full file).</p>') +
|
|
5084
|
-
'</div>';
|
|
5085
|
-
}
|
|
5086
|
-
// Runtime tripwire: per-cohort LIVE edit-rate + any auto-demotions.
|
|
5075
|
+
// Existing demotions remain until explicitly reviewed.
|
|
5087
5076
|
var tw = cc.cohort_tripwire || {};
|
|
5088
|
-
var twCohorts = tw.cohorts || [];
|
|
5089
5077
|
var twDemoted = tw.demoted || [];
|
|
5090
|
-
if (
|
|
5078
|
+
if (twDemoted.length) {
|
|
5091
5079
|
ccHtml += '<div style="margin-top:var(--s-3);padding-top:var(--s-2);border-top:1px solid rgba(255,255,255,0.08);">' +
|
|
5092
|
-
'<div style="font-weight:500;">
|
|
5093
|
-
fold('How
|
|
5094
|
-
twCohorts.forEach(function(c) {
|
|
5095
|
-
var dem = !!c.demoted;
|
|
5096
|
-
// T9: interpolated cohorts (promoted on a thin sample via an adjacent
|
|
5097
|
-
// passing band) carry a higher exposure risk — label them so the
|
|
5098
|
-
// edit-rate is read with that context.
|
|
5099
|
-
var interp = c.basis === 'interpolated';
|
|
5100
|
-
ccHtml += '<div style="display:flex;justify-content:space-between;gap:var(--s-3);padding:4px 0;' + (dem ? 'opacity:0.72;' : '') + '">' +
|
|
5101
|
-
'<span>' + esc(String(c.language)) + ' · ' + esc(String(c.band)) +
|
|
5102
|
-
(interp ? ' <span title="Promoted on a thin sample because an adjacent size band of the same language passed the full gate. Higher exposure; tighter tripwire floor." style="font-size:11px;color:var(--c-text-dim);border:1px solid var(--c-border-strong, rgba(255,255,255,0.2));border-radius:4px;padding:1px 5px;">interpolated</span>' : '') +
|
|
5103
|
-
(dem ? ' <span style="font-size:11px;color:var(--c-warning);border:1px solid rgba(230,162,60,0.4);border-radius:4px;padding:1px 5px;">demoted</span>' : '') + '</span>' +
|
|
5104
|
-
'<span style="font-family:var(--font-mono);color:var(--c-text-dim);">' +
|
|
5105
|
-
(Number(c.skeletons) || 0) + ' reads · ' + (Number(c.followups) || 0) + ' edits · ' +
|
|
5106
|
-
(Number(c.edit_rate_pct) || 0).toFixed(1) + '%</span>' +
|
|
5107
|
-
'</div>';
|
|
5108
|
-
});
|
|
5080
|
+
'<div style="font-weight:500;">First-read cohorts</div>' +
|
|
5081
|
+
fold('How this works', '<p>Existing demotions stay in place. Outcome comparisons run in shadow and do not automatically promote or demote cohorts.</p>');
|
|
5109
5082
|
if (twDemoted.length) {
|
|
5110
5083
|
var demStr = twDemoted.map(function(c) { return esc(String(c[0])) + ':' + esc(String(c[1])); }).join(', ');
|
|
5111
5084
|
ccHtml += '<div style="font-size:13px;color:var(--c-text-dim);margin-top:4px;">' +
|
|
@@ -5115,7 +5088,8 @@ var DB = (function() {
|
|
|
5115
5088
|
ccHtml += '</div>';
|
|
5116
5089
|
}
|
|
5117
5090
|
ccHtml += '</div>';
|
|
5118
|
-
|
|
5091
|
+
if (story) moreFolds.push('<details class="fold"><summary>Compression coverage (diagnostic)</summary><div class="fold__body">' + ccHtml + '</div></details>');
|
|
5092
|
+
else html += ccHtml;
|
|
5119
5093
|
}
|
|
5120
5094
|
|
|
5121
5095
|
// ---- Cache Health: TTL-expiry watchdog (opportunity tier). Observed
|
|
@@ -5200,89 +5174,9 @@ var DB = (function() {
|
|
|
5200
5174
|
chHtml += '</div>';
|
|
5201
5175
|
if (!CACHE_HEALTH_HIDDEN) html += chHtml;
|
|
5202
5176
|
|
|
5203
|
-
|
|
5204
|
-
// In probe-only mode it renders $0 realized / $0 spend / $0 NET, which reads
|
|
5205
|
-
// as "zero value" / broken to users. The keepwarm data is still computed
|
|
5206
|
-
// (measure.py keepwarm_cache_health_block) and carried in
|
|
5207
|
-
// data.cache_health.keepwarm; restore the panel by reverting this hunk.
|
|
5208
|
-
var kw = null;
|
|
5209
|
-
if (kw) {
|
|
5210
|
-
var kwState = kw.state || 'platform-gap';
|
|
5211
|
-
var kwBadge = ({
|
|
5212
|
-
'active-probe': 'probe-only · active',
|
|
5213
|
-
'active-sustain': 'sustain · active',
|
|
5214
|
-
'off-subscription': 'off · subscription',
|
|
5215
|
-
'demoted-by-tripwire': 'off · tripwire',
|
|
5216
|
-
'platform-gap': 'platform gap'
|
|
5217
|
-
})[kwState] || kwState;
|
|
5218
|
-
var kwHtml = '<div class="card wide" style="margin-top:var(--s-3);"><div class="card-header">' +
|
|
5219
|
-
'<span>Keep-warm cache automation</span>' +
|
|
5220
|
-
'<span class="label" style="border:1px solid rgba(255,255,255,0.12);border-radius:4px;padding:1px 5px;">' + esc(kwBadge) + '</span>' +
|
|
5221
|
-
'</div>';
|
|
5222
|
-
if (kwState === 'platform-gap') {
|
|
5223
|
-
kwHtml += '<div style="margin-top:var(--s-2);font-size:13px;color:var(--c-text-dim);line-height:1.6;">' +
|
|
5224
|
-
esc(kw.note || 'Keep-warm ships for Claude Code only.') + '</div>';
|
|
5225
|
-
} else if (kwState === 'off-subscription') {
|
|
5226
|
-
kwHtml += '<div style="margin-top:var(--s-2);font-size:13px;color:var(--c-text-dim);line-height:1.6;">' +
|
|
5227
|
-
esc(kw.honest_line || 'Keep-warm is off on subscription billing: pings spend quota and recover no write premium.') + '</div>';
|
|
5228
|
-
} else {
|
|
5229
|
-
if (kwState === 'demoted-by-tripwire') {
|
|
5230
|
-
kwHtml += '<div style="margin-top:var(--s-2);font-size:13px;color:var(--c-amber, #d9a441);line-height:1.6;">' +
|
|
5231
|
-
'Auto-demoted to OFF by the tripwire (rolling 7d realized/spend ≤ 1.0). Re-enable with keepwarm-enable to reset the ladder.</div>';
|
|
5232
|
-
}
|
|
5233
|
-
// Realized vs spend vs NET (30d) — NET prominent.
|
|
5234
|
-
var net = Number(kw.net_usd) || 0;
|
|
5235
|
-
var netColor = net >= 0 ? 'var(--c-savings, #4ade80)' : 'var(--c-waste, #f87171)';
|
|
5236
|
-
kwHtml += '<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:var(--s-3);margin-top:var(--s-2);">' +
|
|
5237
|
-
'<div><div style="font-size:12px;color:var(--c-text-dim);">Realized (30d)</div>' +
|
|
5238
|
-
'<div style="font-family:var(--font-mono);font-size:20px;">$' + (Number(kw.realized_usd) || 0).toFixed(2) + '</div></div>' +
|
|
5239
|
-
'<div><div style="font-size:12px;color:var(--c-text-dim);">Ping spend (30d)</div>' +
|
|
5240
|
-
'<div style="font-family:var(--font-mono);font-size:20px;color:var(--c-text-dim);">$' + (Number(kw.spend_usd) || 0).toFixed(2) + '</div></div>' +
|
|
5241
|
-
'<div><div style="font-size:12px;color:var(--c-text-dim);">NET (30d)</div>' +
|
|
5242
|
-
'<div style="font-family:var(--font-mono);font-size:20px;color:' + netColor + ';">$' + net.toFixed(2) + '</div></div>' +
|
|
5243
|
-
'<div><div style="font-size:12px;color:var(--c-text-dim);">Tripwire ratio (7d)</div>' +
|
|
5244
|
-
'<div style="font-family:var(--font-mono);font-size:20px;">' + (kw.tripwire_ratio_7d == null ? 'n/a' : (Number(kw.tripwire_ratio_7d)).toFixed(2)) + '</div></div>' +
|
|
5245
|
-
'</div>';
|
|
5246
|
-
if (!kw.has_pings) {
|
|
5247
|
-
kwHtml += '<div style="margin-top:var(--s-2);font-size:12px;color:var(--c-text-dim);">No keep-warm pings yet — numbers fill in once an eligible paused session is probe-refreshed.</div>';
|
|
5248
|
-
}
|
|
5249
|
-
// Health signal.
|
|
5250
|
-
var hh = kw.health || {};
|
|
5251
|
-
if (Number(hh.total_pings) > 0) {
|
|
5252
|
-
kwHtml += '<div style="margin-top:var(--s-2);font-size:12px;color:' + (hh.alarm ? 'var(--c-waste, #f87171)' : 'var(--c-text-dim)') + ';">' +
|
|
5253
|
-
'Pings on never-resumed pauses: ' + (Number(hh.pings_on_never_resumed) || 0) + '/' + (Number(hh.total_pings) || 0) +
|
|
5254
|
-
' (' + Math.round((Number(hh.fraction) || 0) * 100) + '%)' + (hh.alarm ? ' — ALARM (>50%)' : '') + '</div>';
|
|
5255
|
-
}
|
|
5256
|
-
// Predictor transparency (feature names; relevant when sustain activates).
|
|
5257
|
-
var feats = kw.predictor_features || [];
|
|
5258
|
-
if (kwState === 'active-sustain' && feats.length) {
|
|
5259
|
-
kwHtml += '<div style="margin-top:var(--s-2);font-size:12px;color:var(--c-text-dim);line-height:1.5;">' +
|
|
5260
|
-
'Sustain predictor (threshold ' + (Number(kw.predictor_threshold) || 0).toFixed(2) + '): ' +
|
|
5261
|
-
feats.map(function(f) { return esc(f); }).join(', ') + '</div>';
|
|
5262
|
-
}
|
|
5263
|
-
// Top sessions by realized.
|
|
5264
|
-
var ts2 = kw.top_sessions || [];
|
|
5265
|
-
if (ts2.length) {
|
|
5266
|
-
kwHtml += '<div style="margin-top:var(--s-3);"><div style="font-size:12px;color:var(--c-text-dim);margin-bottom:6px;">Top sessions by realized</div>' +
|
|
5267
|
-
'<table style="width:100%;border-collapse:collapse;font-size:12px;">' +
|
|
5268
|
-
'<thead><tr style="color:var(--c-text-dim);text-align:left;">' +
|
|
5269
|
-
'<th style="padding:4px 6px;">Session</th><th style="padding:4px 6px;">Realized $</th>' +
|
|
5270
|
-
'<th style="padding:4px 6px;">Spend $</th><th style="padding:4px 6px;">Pings</th></tr></thead><tbody>';
|
|
5271
|
-
ts2.forEach(function(t) {
|
|
5272
|
-
kwHtml += '<tr style="border-top:1px solid rgba(255,255,255,0.06);">' +
|
|
5273
|
-
'<td style="padding:4px 6px;font-family:var(--font-mono);">' + esc(String(t.session_id || '').slice(0, 28)) + '</td>' +
|
|
5274
|
-
'<td style="padding:4px 6px;font-family:var(--font-mono);">$' + (Number(t.realized_usd) || 0).toFixed(2) + '</td>' +
|
|
5275
|
-
'<td style="padding:4px 6px;font-family:var(--font-mono);color:var(--c-text-dim);">$' + (Number(t.spend_usd) || 0).toFixed(2) + '</td>' +
|
|
5276
|
-
'<td style="padding:4px 6px;font-family:var(--font-mono);">' + (Number(t.pings) || 0) + '</td></tr>';
|
|
5277
|
-
});
|
|
5278
|
-
kwHtml += '</tbody></table></div>';
|
|
5279
|
-
}
|
|
5280
|
-
}
|
|
5281
|
-
kwHtml += '</div>';
|
|
5282
|
-
html += kwHtml;
|
|
5283
|
-
}
|
|
5177
|
+
if (moreFolds.length) html += '<div class="st-morerow">' + moreFolds.join('') + '</div>';
|
|
5284
5178
|
|
|
5285
|
-
el.innerHTML = html;
|
|
5179
|
+
if (el.classList && el.dataset) { el.classList.toggle('st-enter', !el.dataset.storyRendered); el.dataset.storyRendered = '1'; } el.innerHTML = html;
|
|
5286
5180
|
el.querySelectorAll('details > summary').forEach(function(summary) {
|
|
5287
5181
|
if (openFolds.indexOf(summary.textContent) >= 0) summary.parentElement.open = true;
|
|
5288
5182
|
});
|
|
@@ -5302,8 +5196,12 @@ var DB = (function() {
|
|
|
5302
5196
|
'</div>' +
|
|
5303
5197
|
'<div class="last-updated">Last updated: ' + esc(ts) + '</div>';
|
|
5304
5198
|
|
|
5199
|
+
if (typeof keepwarmHealthHtml === 'function') html += keepwarmHealthHtml(data);
|
|
5305
5200
|
if (!h) {
|
|
5306
5201
|
html += '<div class="empty-state">No health data available. This usually means no ' + esc(data.runtime_label || 'Claude Code') + ' processes are currently running.</div>';
|
|
5202
|
+
try { if (typeof featureHealthHtml === 'function') html += featureHealthHtml(data); } catch (e) {}
|
|
5203
|
+
try { if (typeof coverageFunnelHtml === 'function') html += coverageFunnelHtml(data); } catch (e) {}
|
|
5204
|
+
try { if (typeof holdoutHtml === 'function') html += holdoutHtml(data); } catch (e) {}
|
|
5307
5205
|
el.innerHTML = html;
|
|
5308
5206
|
return;
|
|
5309
5207
|
}
|
|
@@ -5317,6 +5215,13 @@ var DB = (function() {
|
|
|
5317
5215
|
'<p style="font-size:13px;color:var(--c-text-dim);margin-bottom:0;">Codex process version comparison is not exposed reliably in local session data, so version/outdated rows are hidden. This tab focuses on running sessions, hook health, and context quality.</p></div>';
|
|
5318
5216
|
}
|
|
5319
5217
|
|
|
5218
|
+
// Archive replacement self-check (scripts/archive_verify.py)
|
|
5219
|
+
var arc = data.archive_replacement_check;
|
|
5220
|
+
if (arc && arc.status === 'warning') {
|
|
5221
|
+
html += '<div class="card wide" style="background:rgba(239,68,68,0.08);border:1px solid rgba(239,68,68,0.2)"><div class="card-header"><span>Tool archive not applied</span><span class="label">' + esc(String(arc.full_streak)) + ' in a row</span></div>' +
|
|
5222
|
+
'<p style="font-size:13px;line-height:1.5;margin-bottom:0;">' + esc(arc.message || '') + '</p></div>';
|
|
5223
|
+
}
|
|
5224
|
+
|
|
5320
5225
|
// Running sessions table
|
|
5321
5226
|
var sessions = h.running_sessions || [];
|
|
5322
5227
|
html += '<div class="card wide"><div class="card-header"><span>Running Sessions</span><span class="label">' + sessions.length + ' active</span></div>';
|
|
@@ -5522,6 +5427,11 @@ var DB = (function() {
|
|
|
5522
5427
|
});
|
|
5523
5428
|
html += '</div>';
|
|
5524
5429
|
}
|
|
5430
|
+
// U9: context quality and hook time limits moved here from the Savings tab.
|
|
5431
|
+
try { if (typeof healthNotesHtml === 'function') html += healthNotesHtml(data); } catch (e) {}
|
|
5432
|
+
try { if (typeof featureHealthHtml === 'function') html += featureHealthHtml(data); } catch (e) {}
|
|
5433
|
+
try { if (typeof coverageFunnelHtml === 'function') html += coverageFunnelHtml(data); } catch (e) {}
|
|
5434
|
+
try { if (typeof holdoutHtml === 'function') html += holdoutHtml(data); } catch (e) {}
|
|
5525
5435
|
|
|
5526
5436
|
el.innerHTML = html;
|
|
5527
5437
|
}
|
|
@@ -5555,15 +5465,13 @@ var DB = (function() {
|
|
|
5555
5465
|
return it && it.state !== 'not_applicable';
|
|
5556
5466
|
});
|
|
5557
5467
|
var urWins = ur.wins || [];
|
|
5558
|
-
if (urItems.length > 0
|
|
5468
|
+
if (urItems.length > 0) {
|
|
5559
5469
|
html += '<div class="card wide"><div class="card-header"><span>From your own usage</span>' +
|
|
5560
5470
|
(ur.measured_ts
|
|
5561
5471
|
? '<span class="label">measured ' + esc(timeAgo(new Date(ur.measured_ts * 1000))) + ', last ' + esc(String(ur.window_days || 30)) + ' days</span>'
|
|
5562
5472
|
: '') +
|
|
5563
5473
|
'</div>' +
|
|
5564
|
-
|
|
5565
|
-
? '<div style="color:var(--c-text-dim);font-size:14px;">Measuring in the background, check back after your next session</div>'
|
|
5566
|
-
: '');
|
|
5474
|
+
'';
|
|
5567
5475
|
var urCap = function(s) { s = String(s || ''); return s.charAt(0).toUpperCase() + s.slice(1); };
|
|
5568
5476
|
urItems.forEach(function(it, urIdx) {
|
|
5569
5477
|
// The card header already draws a line above the first row.
|
|
@@ -5801,8 +5709,8 @@ var DB = (function() {
|
|
|
5801
5709
|
var isCodex = data.runtime === 'codex';
|
|
5802
5710
|
var codexSetup = (data.manage && data.manage.codex) || {};
|
|
5803
5711
|
var refreshCmd = isCodex
|
|
5804
|
-
? tcli('TOKEN_OPTIMIZER_RUNTIME=codex python3 measure.py dashboard')
|
|
5805
|
-
: tcli('python3 measure.py dashboard');
|
|
5712
|
+
? tcli('TOKEN_OPTIMIZER_RUNTIME=codex python3 measure.py dashboard --user')
|
|
5713
|
+
: tcli('python3 measure.py dashboard --user');
|
|
5806
5714
|
|
|
5807
5715
|
var html = '<div class="section-header">' +
|
|
5808
5716
|
'<div class="label">Configuration</div>' +
|
|
@@ -6064,7 +5972,7 @@ var DB = (function() {
|
|
|
6064
5972
|
? 'Your ' + esc(data.runtime_label || 'runtime') + ' skills and MCP servers, read from its own files. Token Optimizer feature toggles are below.'
|
|
6065
5973
|
: window.__TOKEN_API_LIVE
|
|
6066
5974
|
? '<span style="color:var(--c-accent-cyan);font-weight:600;">Live mode</span> — toggles apply instantly to settings. <strong>Restart ' + (isCodex ? 'Codex' : isNoInstructionHost(data) ? esc(data.runtime_label || 'the runtime') : 'Claude') + '</strong> to activate changes.'
|
|
6067
|
-
: tcliHtml('Open in serve mode for live toggles: <code style="background:var(--c-bg);padding:2px 5px;border-radius:4px;">python3 measure.py dashboard --serve</code>')) +
|
|
5975
|
+
: tcliHtml('Open in serve mode for live toggles: <code style="background:var(--c-bg);padding:2px 5px;border-radius:4px;">python3 measure.py dashboard --user --serve</code>')) +
|
|
6068
5976
|
'</p>' +
|
|
6069
5977
|
'</div>';
|
|
6070
5978
|
|
|
@@ -6084,7 +5992,7 @@ var DB = (function() {
|
|
|
6084
5992
|
var onCount = 0;
|
|
6085
5993
|
var offRecommended = 0;
|
|
6086
5994
|
v5Names.forEach(function(n) {
|
|
6087
|
-
if (v5Features[n].enabled) onCount++;
|
|
5995
|
+
if (n === 'keepwarm') return; if (v5Features[n].enabled) onCount++;
|
|
6088
5996
|
else if (v5Features[n].recommended) offRecommended++;
|
|
6089
5997
|
});
|
|
6090
5998
|
|
|
@@ -6097,7 +6005,7 @@ var DB = (function() {
|
|
|
6097
6005
|
'<div class="card-header" style="padding:18px var(--s-3);">' +
|
|
6098
6006
|
'<span style="font-size:22px;font-weight:700;">' + v5Title + '</span>' +
|
|
6099
6007
|
'<span class="label" style="font-size:14px;background:' + headerColor + ';color:var(--c-bg);padding:6px 12px;border-radius:4px;font-weight:700;">' +
|
|
6100
|
-
onCount + '/' + v5Names.length + ' ON' +
|
|
6008
|
+
onCount + '/' + v5Names.filter(function(n) { return n !== 'keepwarm'; }).length + ' ON' +
|
|
6101
6009
|
'</span>' +
|
|
6102
6010
|
'</div>' +
|
|
6103
6011
|
'<p style="font-size:17px;color:var(--c-text-main);padding:0 var(--s-3) var(--s-2);line-height:1.6;">' +
|
|
@@ -6106,7 +6014,7 @@ var DB = (function() {
|
|
|
6106
6014
|
'</p>';
|
|
6107
6015
|
|
|
6108
6016
|
v5Names.forEach(function(fname) {
|
|
6109
|
-
var f = v5Features[fname];
|
|
6017
|
+
var f = v5Features[fname]; if (fname === 'keepwarm') { html += '<div class="hook-row" style="padding:20px var(--s-3);border-top:1px solid var(--c-border);">Keep-warm: paused while we prove it is safe and saves you money</div>'; return; }
|
|
6110
6018
|
var unavailable = !!f.unavailable || f.source === 'codex api gap';
|
|
6111
6019
|
var managedByHooks = !!f.managed_by_hooks || (isCodex && (f.source === 'codex hook' || f.source === 'codex opt-in' || f.source === 'codex hook-managed'));
|
|
6112
6020
|
var riskBg = 'var(--c-badge-savings)';
|
|
@@ -6442,7 +6350,7 @@ var DB = (function() {
|
|
|
6442
6350
|
title: 'Toggling v5 features needs a terminal',
|
|
6443
6351
|
body: 'The read-only dashboard server can\u2019t write config. Run this in a terminal:',
|
|
6444
6352
|
cmd: cliCmd,
|
|
6445
|
-
hint: tcli('Or re-open the dashboard with full API: python3 measure.py dashboard --serve')
|
|
6353
|
+
hint: tcli('Or re-open the dashboard with full API: python3 measure.py dashboard --user --serve')
|
|
6446
6354
|
});
|
|
6447
6355
|
return;
|
|
6448
6356
|
}
|
|
@@ -7480,7 +7388,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
|
7480
7388
|
|
|
7481
7389
|
var data = window.__TOKEN_DATA__;
|
|
7482
7390
|
if (!data) {
|
|
7483
|
-
document.body.innerHTML = '<div style="max-width:820px;margin:80px auto;padding:32px;border:1px solid var(--c-border);border-radius:14px;background:var(--c-surface);color:var(--c-text-main);font-family:system-ui,sans-serif;line-height:1.6;"><h1 style="margin-top:0;">Token Optimizer</h1><p><strong>You opened the dashboard template.</strong> This file intentionally contains no local metrics. Generate the runtime dashboard first, then open the generated file.</p><p style="margin-bottom:8px;color:var(--c-text-dim);">From the Token Optimizer checkout:</p><code style="display:block;white-space:normal;background:var(--c-elev-3);padding:12px;border-radius:8px;color:var(--c-text-main);">TOKEN_OPTIMIZER_RUNTIME=codex python3 skills/token-optimizer/scripts/measure.py dashboard</code><p style="margin:18px 0 8px;color:var(--c-text-dim);">Generated Codex dashboard path:</p><code style="display:block;white-space:normal;background:var(--c-elev-3);padding:12px;border-radius:8px;color:var(--c-text-main);">~/.codex/_backups/token-optimizer/dashboard.html</code></div>';
|
|
7391
|
+
document.body.innerHTML = '<div style="max-width:820px;margin:80px auto;padding:32px;border:1px solid var(--c-border);border-radius:14px;background:var(--c-surface);color:var(--c-text-main);font-family:system-ui,sans-serif;line-height:1.6;"><h1 style="margin-top:0;">Token Optimizer</h1><p><strong>You opened the dashboard template.</strong> This file intentionally contains no local metrics. Generate the runtime dashboard first, then open the generated file.</p><p style="margin-bottom:8px;color:var(--c-text-dim);">From the Token Optimizer checkout:</p><code style="display:block;white-space:normal;background:var(--c-elev-3);padding:12px;border-radius:8px;color:var(--c-text-main);">TOKEN_OPTIMIZER_RUNTIME=codex python3 skills/token-optimizer/scripts/measure.py dashboard --user</code><p style="margin:18px 0 8px;color:var(--c-text-dim);">Generated Codex dashboard path:</p><code style="display:block;white-space:normal;background:var(--c-elev-3);padding:12px;border-radius:8px;color:var(--c-text-main);">~/.codex/_backups/token-optimizer/dashboard.html</code></div>';
|
|
7484
7392
|
return;
|
|
7485
7393
|
}
|
|
7486
7394
|
var runtimeLabel = data.runtime_label || (data.runtime === 'codex' ? 'Codex' : 'Claude Code');
|
|
@@ -7498,7 +7406,15 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
|
7498
7406
|
brandMeta.textContent = brandParts.join(' \u00b7 ');
|
|
7499
7407
|
}
|
|
7500
7408
|
|
|
7501
|
-
function startApp() {
|
|
7409
|
+
function startApp() {
|
|
7410
|
+
DB.init(data); refreshSavingsLive();
|
|
7411
|
+
try {
|
|
7412
|
+
if (sessionStorage.getItem('to-history-return')) {
|
|
7413
|
+
sessionStorage.removeItem('to-history-return');
|
|
7414
|
+
document.querySelector('.nav-item[data-view="trends"]').click();
|
|
7415
|
+
}
|
|
7416
|
+
} catch (e) {}
|
|
7417
|
+
}
|
|
7502
7418
|
|
|
7503
7419
|
// Pull fresh savings from the daemon and live-patch the Savings/Overview tiles.
|
|
7504
7420
|
// No-op unless the custom API is live (served over http, health probe passed) —
|
|
@@ -7538,24 +7454,15 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
|
7538
7454
|
}, 60000);
|
|
7539
7455
|
}
|
|
7540
7456
|
|
|
7541
|
-
// Probe
|
|
7542
|
-
// When served from the daemon (http://localhost:*), a relative /api/health works.
|
|
7543
|
-
// When viewed as file://, stay in static read-only mode to avoid CORS noise.
|
|
7457
|
+
// Probe the daemon; file pages stay read-only.
|
|
7544
7458
|
var DAEMON_URL = data.runtime === 'codex' ? 'http://localhost:24843' : 'http://localhost:24842';
|
|
7545
7459
|
function _setApiLive(baseUrl) {
|
|
7546
7460
|
window.__TOKEN_API_LIVE = true;
|
|
7547
7461
|
window.__TOKEN_API_BASE = baseUrl || '';
|
|
7548
7462
|
}
|
|
7549
|
-
//
|
|
7550
|
-
// CSRF token header so the server accepts the request. Without this, POSTs
|
|
7551
|
-
// are rejected with 403 -- that's the whole point of the CSRF hardening.
|
|
7552
|
-
//
|
|
7553
|
-
// Surface auth errors as a distinct message
|
|
7554
|
-
// rather than letting callers hit r.json() on a text body ("Forbidden:
|
|
7555
|
-
// invalid token") and seeing a confusing JSON parse error. The helper
|
|
7556
|
-
// intercepts 403 responses and rejects with an Error whose .authError flag
|
|
7557
|
-
// lets call sites show a reload-page hint.
|
|
7463
|
+
// All mutations carry the per-install token and surface authorization failures.
|
|
7558
7464
|
window.__TOKEN_API_POST = function(path, body) {
|
|
7465
|
+
if (window.location && window.location.protocol === 'file:') return Promise.reject(new Error('Open the live dashboard to make changes.'));
|
|
7559
7466
|
var base = window.__TOKEN_API_BASE || '';
|
|
7560
7467
|
var headers = { 'Content-Type': 'application/json' };
|
|
7561
7468
|
if (window.__TOKEN_API_TOKEN) headers['X-TO-Token'] = window.__TOKEN_API_TOKEN;
|
|
@@ -7575,10 +7482,48 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
|
7575
7482
|
});
|
|
7576
7483
|
};
|
|
7577
7484
|
|
|
7578
|
-
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
|
|
7485
|
+
function waitForRegen(result, message) {
|
|
7486
|
+
if (!result.ok) return Promise.reject(new Error('Could not update the dashboard. Please try again.'));
|
|
7487
|
+
if (!result.job_id) return Promise.resolve();
|
|
7488
|
+
function poll() {
|
|
7489
|
+
return window.__TOKEN_API_POST('/api/regenerate/status', {job_id: result.job_id})
|
|
7490
|
+
.then(function(r) { return r.json(); }).then(function(state) {
|
|
7491
|
+
if (message) message.textContent = state.progress || 'Updating the dashboard.';
|
|
7492
|
+
if (state.state === 'done') return;
|
|
7493
|
+
if (state.state !== 'running') throw new Error('Could not update the dashboard. Please try again.');
|
|
7494
|
+
return new Promise(function(resolve) { setTimeout(resolve, 1000); }).then(poll);
|
|
7495
|
+
});
|
|
7496
|
+
}
|
|
7497
|
+
return poll();
|
|
7498
|
+
}
|
|
7499
|
+
|
|
7500
|
+
window.__TOKEN_LOAD_HISTORY = function(choice, message) {
|
|
7501
|
+
if (choice === 'all') { try { localStorage.setItem('to-daily-range', 'all'); } catch (e) {} }
|
|
7502
|
+
if (!window.__TOKEN_API_LIVE) {
|
|
7503
|
+
message.textContent = 'Open the dashboard through the local server to load more history.';
|
|
7504
|
+
return;
|
|
7505
|
+
}
|
|
7506
|
+
message.textContent = 'Loading history…';
|
|
7507
|
+
function attempt(retried) {
|
|
7508
|
+
window.__TOKEN_API_POST('/api/regenerate', {days: choice}).then(function(r) { return r.json(); })
|
|
7509
|
+
.then(function(result) {
|
|
7510
|
+
return waitForRegen(result, message);
|
|
7511
|
+
}).then(function() {
|
|
7512
|
+
try { sessionStorage.setItem('to-history-return', '1'); } catch (e) {}
|
|
7513
|
+
location.reload();
|
|
7514
|
+
}).catch(function(err) {
|
|
7515
|
+
if (err.authError && !retried) {
|
|
7516
|
+
_fetchToken(window.__TOKEN_API_BASE || '').then(function() { attempt(true); })
|
|
7517
|
+
.catch(function() { message.textContent = 'Could not load history. Please try again.'; });
|
|
7518
|
+
} else message.textContent = 'Could not load history. Please try again.';
|
|
7519
|
+
});
|
|
7520
|
+
}
|
|
7521
|
+
if (window.__TOKEN_API_TOKEN) attempt(false);
|
|
7522
|
+
else _fetchToken(window.__TOKEN_API_BASE || '').then(function() { attempt(false); })
|
|
7523
|
+
.catch(function() { message.textContent = 'Could not load history. Please try again.'; });
|
|
7524
|
+
};
|
|
7525
|
+
|
|
7526
|
+
// Manual regeneration waits for the background job before reloading.
|
|
7582
7527
|
window.__TOKEN_REGENERATE = function() {
|
|
7583
7528
|
var btn = document.getElementById('to-regen-btn');
|
|
7584
7529
|
var msg = document.getElementById('to-regen-msg');
|
|
@@ -7602,16 +7547,15 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
|
7602
7547
|
}
|
|
7603
7548
|
function fail(e) {
|
|
7604
7549
|
btn.disabled = false; btn.textContent = was;
|
|
7605
|
-
var txt = (e && e.authError)
|
|
7606
|
-
? 'Auth failed after a token refresh — reload the page.'
|
|
7607
|
-
: ('Failed: ' + ((e && e.message) || e || 'unknown error'));
|
|
7550
|
+
var txt = (e && e.authError) ? 'Authentication failed. Reload the page and try again.' : 'Could not update the dashboard. Please try again.';
|
|
7608
7551
|
if (msg) msg.textContent = '';
|
|
7609
7552
|
if (errBox) { errBox.textContent = txt; errBox.hidden = false; }
|
|
7610
7553
|
else if (msg) { msg.textContent = txt; }
|
|
7611
7554
|
}
|
|
7612
7555
|
function succeed(d) {
|
|
7613
|
-
|
|
7614
|
-
|
|
7556
|
+
return waitForRegen(d || {}, msg).then(function() {
|
|
7557
|
+
location.reload();
|
|
7558
|
+
}).catch(fail);
|
|
7615
7559
|
}
|
|
7616
7560
|
// At most ONE 403->refetch->retry. Without the cap a persistently-bad token
|
|
7617
7561
|
// loops forever; without the retry a stale/empty page token silently 403'd
|
|
@@ -7655,17 +7599,14 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
|
7655
7599
|
}
|
|
7656
7600
|
if (typeof fetch === 'function') {
|
|
7657
7601
|
var isHttp = window.location.protocol.indexOf('http') === 0;
|
|
7658
|
-
|
|
7659
|
-
|
|
7660
|
-
return;
|
|
7661
|
-
}
|
|
7662
|
-
var probe = '/api/health';
|
|
7602
|
+
var base = isHttp ? '' : DAEMON_URL;
|
|
7603
|
+
var probe = base + '/api/health';
|
|
7663
7604
|
try {
|
|
7664
|
-
fetch(probe, { method: 'GET' })
|
|
7665
|
-
.then(function(r) { return r.json(); })
|
|
7605
|
+
fetch(probe, isHttp ? { method: 'GET' } : { method: 'GET', mode: 'no-cors' })
|
|
7606
|
+
.then(function(r) { return !isHttp && r.type === 'opaque' ? {ok: true} : r.json(); })
|
|
7666
7607
|
.then(function(d) {
|
|
7667
7608
|
if (d && d.ok) {
|
|
7668
|
-
|
|
7609
|
+
if (!isHttp) { window.__TOKEN_FILE_DAEMON_LIVE = true; return; }
|
|
7669
7610
|
_setApiLive(base);
|
|
7670
7611
|
return _fetchToken(base);
|
|
7671
7612
|
}
|