@alexgreensh/token-optimizer 5.13.62 → 5.13.64
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/hooks/sessionstart_runner.py +25 -4
- package/package.json +1 -1
- package/skills/fleet-auditor/SKILL.md +1 -1
- package/skills/fleet-auditor/scripts/fleet.py +4 -1
- package/skills/fleet-auditor/scripts/shared.py +31 -14
- package/skills/token-coach/SKILL.md +49 -40
- package/skills/token-coach/references/deterministic-stages.md +1 -1
- package/skills/token-coach/references/keepwarm-consent.md +7 -7
- package/skills/token-dashboard/SKILL.md +30 -6
- package/skills/token-optimizer/SKILL.md +42 -44
- package/skills/token-optimizer/assets/dashboard.html +571 -106
- package/skills/token-optimizer/references/agent-prompts.md +4 -1
- package/skills/token-optimizer/references/codex-workflow.md +30 -12
- package/skills/token-optimizer/references/cursor-workflow.md +9 -7
- package/skills/token-optimizer/references/implementation-playbook.md +4 -4
- package/skills/token-optimizer/references/keepwarm-consent.md +7 -7
- package/skills/token-optimizer/references/opencode-workflow.md +4 -2
- package/skills/token-optimizer/references/optimization-checklist.md +9 -9
- package/skills/token-optimizer/references/phase0-setup.md +9 -9
- package/skills/token-optimizer/references/presentation-workflow.md +3 -3
- package/skills/token-optimizer/references/session-continuity.md +1 -1
- package/skills/token-optimizer/references/token-flow-architecture.md +2 -1
- package/skills/token-optimizer/scripts/adapter_hook_command.py +94 -0
- package/skills/token-optimizer/scripts/antigravity_doctor.py +12 -0
- package/skills/token-optimizer/scripts/antigravity_hook_bridge.py +4 -0
- package/skills/token-optimizer/scripts/antigravity_install.py +9 -18
- package/skills/token-optimizer/scripts/antigravity_session.py +31 -6
- package/skills/token-optimizer/scripts/archive_result.py +6 -1
- package/skills/token-optimizer/scripts/archive_window.py +274 -0
- package/skills/token-optimizer/scripts/checkpoint_state.py +385 -0
- package/skills/token-optimizer/scripts/codex_install.py +5 -3
- package/skills/token-optimizer/scripts/codex_session.py +149 -1
- package/skills/token-optimizer/scripts/cursor_doctor.py +12 -27
- package/skills/token-optimizer/scripts/cursor_install.py +11 -19
- package/skills/token-optimizer/scripts/devin_source.py +3 -3
- package/skills/token-optimizer/scripts/grok_doctor.py +12 -24
- package/skills/token-optimizer/scripts/grok_install.py +9 -16
- package/skills/token-optimizer/scripts/measure.py +7300 -1642
- package/skills/token-optimizer/scripts/read_cache.py +52 -27
- package/skills/token-optimizer/scripts/recovery_output.py +67 -18
- package/skills/token-optimizer/scripts/refetch_guard.py +9 -3
- package/skills/token-optimizer/scripts/session_activity.py +169 -0
- package/skills/token-optimizer/scripts/session_store.py +127 -9
- package/skills/token-optimizer/scripts/statusline.js +4 -6
|
@@ -287,6 +287,9 @@ th, td { padding: 10px !important; }
|
|
|
287
287
|
}
|
|
288
288
|
.fold__body p { margin: 0 0 var(--s-3); }
|
|
289
289
|
.fold__body p:last-child { margin-bottom: 0; }
|
|
290
|
+
.fold__body ul { margin: 0 0 var(--s-3); padding-left: 1.3em; }
|
|
291
|
+
.fold__body li { margin: 0 0 var(--s-2); }
|
|
292
|
+
.fold__body li:last-child { margin-bottom: 0; }
|
|
290
293
|
.fold__body strong, .fold__body b { color: var(--c-text-main); font-weight: 600; }
|
|
291
294
|
|
|
292
295
|
/* Visible lead sentence above a fold: sized to read, capped near 62ch so lines
|
|
@@ -301,6 +304,12 @@ th, td { padding: 10px !important; }
|
|
|
301
304
|
}
|
|
302
305
|
.lede + .lede { margin-top: var(--s-3); }
|
|
303
306
|
.lede strong, .lede b { color: var(--c-text-main); font-weight: 500; }
|
|
307
|
+
/* One short readable line under a number: normal text colour, never grey fine print.
|
|
308
|
+
Anything longer belongs in a .fold. */
|
|
309
|
+
.plain-line {
|
|
310
|
+
font-size: 15px; line-height: 1.6; color: var(--c-text-main);
|
|
311
|
+
max-width: 62ch; text-wrap: pretty; margin: var(--s-2) 0 0;
|
|
312
|
+
}
|
|
304
313
|
/* Plain inline note (methodology one-liners under bars/cards). */
|
|
305
314
|
.note {
|
|
306
315
|
font-size: 14px; line-height: 1.75; color: var(--c-text-dim);
|
|
@@ -2389,10 +2398,51 @@ function codexMemCardHtml(mr, fn) { return '<div class="card"><div class="card-h
|
|
|
2389
2398
|
'<div style="text-align:center;padding:0 0 var(--s-3);font-size:12px;color:var(--c-text-dim);">Measured from Codex state; no file structure audit</div>' +
|
|
2390
2399
|
'</div>'; }
|
|
2391
2400
|
function memCountSuffix(mr) { return mr && mr.scan_partial ? '+' : ''; }
|
|
2401
|
+
// Cursor and Antigravity have no CLAUDE.md or MEMORY.md and no ~/.claude
|
|
2402
|
+
// folder to manage, and the /token-optimizer audit is Claude Code only (see
|
|
2403
|
+
// references/cursor-workflow.md), so the Claude-shaped labels, cards and
|
|
2404
|
+
// pointers are replaced for them.
|
|
2405
|
+
function isNoInstructionHost(data) {
|
|
2406
|
+
return !!data && (data.runtime === 'cursor' || data.runtime === 'antigravity');
|
|
2407
|
+
}
|
|
2408
|
+
function hostRefreshHtml(data) {
|
|
2409
|
+
return tcliHtml('<span class="update-cmd">TOKEN_OPTIMIZER_RUNTIME=' + esc(data.runtime) + ' python3 measure.py dashboard</span>');
|
|
2410
|
+
}
|
|
2411
|
+
function hermesComponentDetails(c) {
|
|
2412
|
+
function fileSub(x, missing) {
|
|
2413
|
+
return (x && x.exists) ? (x.lines || 0) + ' lines loaded every session' : missing;
|
|
2414
|
+
}
|
|
2415
|
+
var sk = c.skills || {}, mcp = c.mcp_tools || {};
|
|
2416
|
+
return [
|
|
2417
|
+
{ key: 'hermes_soul', name: 'SOUL.md', tokens: c.hermes_soul ? c.hermes_soul.tokens : 0,
|
|
2418
|
+
sub: fileSub(c.hermes_soul, 'No SOUL.md in your Hermes home'),
|
|
2419
|
+
what: 'Hermes loads SOUL.md from its home folder into every session as the agent identity.',
|
|
2420
|
+
top: [], issues: [], related: [] },
|
|
2421
|
+
{ key: 'hermes_memory', name: 'Memory', tokens: c.hermes_memory ? c.hermes_memory.tokens : 0,
|
|
2422
|
+
sub: fileSub(c.hermes_memory, 'No MEMORY.md or USER.md yet'),
|
|
2423
|
+
what: 'MEMORY.md and USER.md from memories/ are added to the system prompt as a snapshot when a session starts.',
|
|
2424
|
+
top: [], issues: [], related: [] },
|
|
2425
|
+
{ key: 'skills', name: 'Skills', tokens: sk.tokens || 0,
|
|
2426
|
+
sub: (sk.count || 0) + ' skills listed' + (sk.archived_count ? ', ' + sk.archived_count + ' archived' : '') +
|
|
2427
|
+
(sk.disabled_count ? ', ' + sk.disabled_count + ' disabled' : ''),
|
|
2428
|
+
what: 'Hermes lists each skill name and description in the system prompt and loads the full skill only when it is used. Short descriptions keep the list small.',
|
|
2429
|
+
top: [], issues: [], related: [] },
|
|
2430
|
+
{ key: 'mcp_tools', name: 'MCP Servers', tokens: mcp.tokens || 0,
|
|
2431
|
+
sub: (mcp.server_count || 0) + ' servers enabled' + (mcp.disabled_count ? ', ' + mcp.disabled_count + ' disabled' : ''),
|
|
2432
|
+
what: 'Servers from mcp_servers in config.yaml. With tool search on (the Hermes default), their tools are listed briefly and full schemas load on demand.',
|
|
2433
|
+
top: [], issues: [], related: [] },
|
|
2434
|
+
{ key: 'core_system', name: 'Core System', tokens: c.core_system ? c.core_system.tokens : 0,
|
|
2435
|
+
sub: 'Not exposed for measurement',
|
|
2436
|
+
what: "Hermes's built-in instructions and tools. Hermes does not expose their size, so it is not counted here.",
|
|
2437
|
+
top: [], issues: [], related: [] }
|
|
2438
|
+
];
|
|
2439
|
+
}
|
|
2440
|
+
|
|
2392
2441
|
function getComponentDetails(data) {
|
|
2393
2442
|
var c = data.snapshot.components;
|
|
2394
2443
|
var cd = data.snapshot.component_details || {};
|
|
2395
2444
|
var isCodex = data.runtime === 'codex';
|
|
2445
|
+
if (data.runtime === 'hermes') return hermesComponentDetails(c);
|
|
2396
2446
|
|
|
2397
2447
|
var ct = 0;
|
|
2398
2448
|
for (var k in c) {
|
|
@@ -2489,7 +2539,16 @@ function getComponentDetails(data) {
|
|
|
2489
2539
|
{
|
|
2490
2540
|
key: 'mcp_tools', name: 'MCP Tools',
|
|
2491
2541
|
tokens: c.mcp_tools ? c.mcp_tools.tokens : 0,
|
|
2492
|
-
sub: (
|
|
2542
|
+
sub: (function() {
|
|
2543
|
+
var m = c.mcp_tools;
|
|
2544
|
+
var s = (m ? m.server_count : '?') + ' servers, ~' + (m ? m.tool_count_estimate : '?') + ' tools';
|
|
2545
|
+
if (m) {
|
|
2546
|
+
var dis = m.disabled_for_project || [], pen = m.pending_project_approval || [];
|
|
2547
|
+
if (dis.length) s += ', ' + dis.length + ' disabled for this project';
|
|
2548
|
+
if (pen.length) s += ', ' + pen.length + ' pending approval';
|
|
2549
|
+
}
|
|
2550
|
+
return s;
|
|
2551
|
+
})(),
|
|
2493
2552
|
what: isCodex
|
|
2494
2553
|
? 'Codex MCP servers can expand the active tool surface with names, descriptions, and schemas. The dashboard counts configured servers and uses conservative metadata estimates when exact schemas are not exposed.'
|
|
2495
2554
|
: "MCP server tool definitions are loaded when servers connect. Each tool's name, description, and parameter schema contribute to token cost.",
|
|
@@ -2504,11 +2563,20 @@ function getComponentDetails(data) {
|
|
|
2504
2563
|
sub: 'Fixed overhead, not optimizable',
|
|
2505
2564
|
what: isCodex
|
|
2506
2565
|
? "Codex's built-in instructions and tool definitions. This is fixed by the runtime and cannot be reduced by project configuration."
|
|
2566
|
+
: data.runtime && data.runtime !== 'claude'
|
|
2567
|
+
? (data.runtime_label || 'The runtime') + "'s built-in instructions and tool definitions. Fixed by the runtime; not reducible through configuration."
|
|
2507
2568
|
: "Claude Code's built-in system prompt, tool definitions, safety instructions, and MCP protocol overhead. This is fixed by Anthropic and cannot be reduced by user configuration changes.",
|
|
2508
2569
|
top: [], issues: [], related: []
|
|
2509
2570
|
}
|
|
2510
2571
|
];
|
|
2511
2572
|
|
|
2573
|
+
if (isNoInstructionHost(data)) {
|
|
2574
|
+
// Drop the rows that name files and commands this runtime does not have.
|
|
2575
|
+
components = components.filter(function(comp) {
|
|
2576
|
+
return comp.key !== 'claude_md' && comp.key !== 'memory_md' && comp.key !== 'commands';
|
|
2577
|
+
});
|
|
2578
|
+
}
|
|
2579
|
+
|
|
2512
2580
|
// Override with detailed data if available
|
|
2513
2581
|
components.forEach(function(comp) {
|
|
2514
2582
|
var d = cd[comp.key];
|
|
@@ -2984,7 +3052,7 @@ var DB = (function() {
|
|
|
2984
3052
|
var ts = data.generated_at ? new Date(data.generated_at).toLocaleString() : 'unknown';
|
|
2985
3053
|
var staleMinutes = data.generated_at ? Math.round((Date.now() - new Date(data.generated_at).getTime()) / 60000) : 0;
|
|
2986
3054
|
var isStale = staleMinutes > 60;
|
|
2987
|
-
var refreshHint = data.runtime === 'codex' ? 'run the Codex dashboard refresh command' : 'run /token-optimizer';
|
|
3055
|
+
var refreshHint = data.runtime === 'codex' ? 'run the Codex dashboard refresh command' : isNoInstructionHost(data) ? 'regenerate the dashboard' : 'run /token-optimizer';
|
|
2988
3056
|
var staleWarning = isStale ? ' <span style="color:var(--c-warning, #ff9f43);font-weight:500;">(data is ' + (staleMinutes > 1440 ? Math.round(staleMinutes / 1440) + 'd' : Math.round(staleMinutes / 60) + 'h') + ' old — ' + refreshHint + ' to refresh)</span>' : '';
|
|
2989
3057
|
var headerEl = document.querySelector('#view-overview .header');
|
|
2990
3058
|
if (headerEl) {
|
|
@@ -2996,11 +3064,15 @@ var DB = (function() {
|
|
|
2996
3064
|
tsDiv.innerHTML = 'Last updated: ' + esc(ts) + staleWarning +
|
|
2997
3065
|
(data.runtime === 'codex'
|
|
2998
3066
|
? tcliHtml(' · Run <span class="update-cmd">TOKEN_OPTIMIZER_RUNTIME=codex python3 measure.py session-end-flush --trigger manual</span> for a fresh Codex audit.')
|
|
3067
|
+
: isNoInstructionHost(data)
|
|
3068
|
+
? ' · To refresh, run ' + hostRefreshHtml(data) + '.'
|
|
2999
3069
|
: ' · Run <span class="update-cmd">/token-optimizer</span> for a full audit with recommendations.');
|
|
3000
3070
|
} else {
|
|
3001
3071
|
tsDiv.innerHTML = 'Last updated: ' + esc(ts) + staleWarning +
|
|
3002
3072
|
(data.runtime === 'codex'
|
|
3003
3073
|
? tcliHtml(' · To refresh, run <span class="update-cmd">TOKEN_OPTIMIZER_RUNTIME=codex python3 measure.py session-end-flush --trigger manual</span>.')
|
|
3074
|
+
: isNoInstructionHost(data)
|
|
3075
|
+
? ' · To refresh, run ' + hostRefreshHtml(data) + '.'
|
|
3004
3076
|
: ' · To refresh, run <span class="update-cmd">/token-optimizer</span> again.');
|
|
3005
3077
|
}
|
|
3006
3078
|
headerEl.appendChild(tsDiv);
|
|
@@ -3012,6 +3084,8 @@ var DB = (function() {
|
|
|
3012
3084
|
// Generate bar chart from components
|
|
3013
3085
|
var c = data.snapshot.components;
|
|
3014
3086
|
var isCodexOverview = data.runtime === 'codex';
|
|
3087
|
+
var isHermesOverview = data.runtime === 'hermes';
|
|
3088
|
+
var isHostOverview = isNoInstructionHost(data);
|
|
3015
3089
|
var vals = [];
|
|
3016
3090
|
var ct = 0; for (var k in c) {
|
|
3017
3091
|
if (!c[k] || !c[k].tokens) continue;
|
|
@@ -3042,6 +3116,20 @@ var DB = (function() {
|
|
|
3042
3116
|
barLabels.push('MCP Tools');
|
|
3043
3117
|
barLabels.push('Core System');
|
|
3044
3118
|
var memoryExists = c.memory_md && c.memory_md.exists !== false;
|
|
3119
|
+
if (isHermesOverview) {
|
|
3120
|
+
// Hermes: SOUL.md, memory snapshot, skills index, MCP servers, core.
|
|
3121
|
+
var hc = hermesComponentDetails(c);
|
|
3122
|
+
vals = hc.map(function(x) { return x.tokens || 0; });
|
|
3123
|
+
barLabels = hc.map(function(x) { return x.name; });
|
|
3124
|
+
memoryExists = !!(c.hermes_memory && c.hermes_memory.exists);
|
|
3125
|
+
}
|
|
3126
|
+
if (isHostOverview) {
|
|
3127
|
+
vals = [(c.skills ? c.skills.tokens : 0) + (c.plugin_skills ? c.plugin_skills.tokens : 0),
|
|
3128
|
+
c.mcp_tools ? c.mcp_tools.tokens : 0,
|
|
3129
|
+
c.core_system ? c.core_system.tokens : 0];
|
|
3130
|
+
barLabels = ['Skills', 'MCP Tools', 'Core System'];
|
|
3131
|
+
memoryExists = true;
|
|
3132
|
+
}
|
|
3045
3133
|
var barsHtml = vals.map(function(v, i) {
|
|
3046
3134
|
var w = logBar(v);
|
|
3047
3135
|
var fixedClass = i === vals.length - 1 ? ' fixed' : '';
|
|
@@ -3057,7 +3145,7 @@ var DB = (function() {
|
|
|
3057
3145
|
document.getElementById('sat-desc').textContent =
|
|
3058
3146
|
isCodexOverview
|
|
3059
3147
|
? 'Bars show % of the logged Codex context window each component uses. Core System is fixed by Codex. AGENTS.md, memories, skills/plugins, MCP, and hooks are yours to tune.'
|
|
3060
|
-
: 'Bars show % of context window each component uses. Core System is fixed by Claude Code. Everything else is yours to trim.';
|
|
3148
|
+
: 'Bars show % of context window each component uses. Core System is fixed by ' + (data.runtime_label || 'Claude Code') + '. Everything else is yours to trim.';
|
|
3061
3149
|
var caveatEl = document.getElementById('sat-caveat');
|
|
3062
3150
|
if (!caveatEl) {
|
|
3063
3151
|
caveatEl = document.createElement('div');
|
|
@@ -3086,7 +3174,7 @@ var DB = (function() {
|
|
|
3086
3174
|
} else if (data.standalone) {
|
|
3087
3175
|
document.getElementById('stat-potential').innerHTML = fn(ctrl) + ' <span class="mini-label">controllable tokens</span>';
|
|
3088
3176
|
document.getElementById('potential-desc').textContent =
|
|
3089
|
-
fn(ctrl) + ' of your ' + fn(total) + ' tokens are things you can change. ' + (isCodexOverview ? 'Use the Codex dashboard refresh command for a full local audit with specific savings estimates.' : 'Run /token-optimizer for a full audit with specific savings estimates.');
|
|
3177
|
+
fn(ctrl) + ' of your ' + fn(total) + ' tokens are things you can change. ' + (isCodexOverview ? 'Use the Codex dashboard refresh command for a full local audit with specific savings estimates.' : (isHostOverview ? '' : 'Run /token-optimizer for a full audit with specific savings estimates.'));
|
|
3090
3178
|
} else {
|
|
3091
3179
|
document.getElementById('stat-potential').innerHTML = fn(ctrl) + ' <span class="mini-label">controllable tokens</span>';
|
|
3092
3180
|
document.getElementById('potential-desc').textContent =
|
|
@@ -3198,11 +3286,11 @@ var DB = (function() {
|
|
|
3198
3286
|
ctaEl.innerHTML = '<div class="card-header"><span>Auto-Detected Recommendations</span></div>' +
|
|
3199
3287
|
'<div class="empty-state" style="text-align:left;color:var(--c-text-dim);font-size:14px;">' +
|
|
3200
3288
|
'These recommendations are auto-generated from your config. Browse them in the tabs on the left.<br>' +
|
|
3201
|
-
(isCodexOverview ? 'For deeper analysis, refresh the Codex dashboard after a few real turns so quality and continuity signals are available.' : 'For deeper analysis (semantic duplication, content quality), run <code style="color:var(--c-accent-cyan)">/token-optimizer</code> for a full LLM-powered audit.') + '</div>';
|
|
3289
|
+
(isCodexOverview ? 'For deeper analysis, refresh the Codex dashboard after a few real turns so quality and continuity signals are available.' : isHostOverview ? '' : 'For deeper analysis (semantic duplication, content quality), run <code style="color:var(--c-accent-cyan)">/token-optimizer</code> for a full LLM-powered audit.') + '</div>';
|
|
3202
3290
|
} else {
|
|
3203
3291
|
ctaEl.innerHTML = '<div class="card-header"><span>Optimization Recommendations</span></div>' +
|
|
3204
3292
|
'<div class="empty-state">No auto-detected issues. Your setup looks clean.<br>' +
|
|
3205
|
-
(isCodexOverview ? 'Refresh the Codex dashboard after live usage for deeper quality analysis.' : 'Run <code style="color:var(--c-accent-cyan)">/token-optimizer</code> for a full audit with deeper analysis.') + '</div>';
|
|
3293
|
+
(isCodexOverview ? 'Refresh the Codex dashboard after live usage for deeper quality analysis.' : isHostOverview ? '' : 'Run <code style="color:var(--c-accent-cyan)">/token-optimizer</code> for a full audit with deeper analysis.') + '</div>';
|
|
3206
3294
|
}
|
|
3207
3295
|
gridEl.parentNode.insertBefore(ctaEl, gridEl.nextSibling);
|
|
3208
3296
|
}
|
|
@@ -3267,20 +3355,20 @@ var DB = (function() {
|
|
|
3267
3355
|
|
|
3268
3356
|
if (data.auto_plan) {
|
|
3269
3357
|
html += '<div class="last-updated">Last updated: ' + esc(ts) +
|
|
3270
|
-
(data.runtime === 'codex' ? ' · Auto-detected from Codex local config and logs.</div>' : ' · Auto-detected. Run <span class="update-cmd">/token-optimizer</span> for deeper LLM-powered analysis.</div>');
|
|
3358
|
+
(data.runtime === 'codex' ? ' · Auto-detected from Codex local config and logs.</div>' : (isNoInstructionHost(data) ? ' · Auto-detected from local config and logs.</div>' : ' · Auto-detected. Run <span class="update-cmd">/token-optimizer</span> for deeper LLM-powered analysis.</div>'));
|
|
3271
3359
|
} else if (data.standalone) {
|
|
3272
3360
|
html += '<div class="last-updated">Last updated: ' + esc(ts) +
|
|
3273
|
-
(data.runtime === 'codex' ? ' · Optimization data is limited until Codex session logs are collected.</div>' : ' · Optimization data not available in standalone mode. Run <span class="update-cmd">/token-optimizer</span> for a full audit with recommendations.</div>');
|
|
3361
|
+
(data.runtime === 'codex' ? ' · Optimization data is limited until Codex session logs are collected.</div>' : (isNoInstructionHost(data) ? ' · Optimization data is limited in standalone mode.</div>' : ' · Optimization data not available in standalone mode. Run <span class="update-cmd">/token-optimizer</span> for a full audit with recommendations.</div>'));
|
|
3274
3362
|
} else {
|
|
3275
3363
|
html += '<div class="last-updated">Last updated: ' + esc(ts) +
|
|
3276
|
-
(data.runtime === 'codex' ? ' · To refresh, use the Codex dashboard refresh command.</div>' : ' · To refresh, run <span class="update-cmd">/token-optimizer</span> again.</div>');
|
|
3364
|
+
(data.runtime === 'codex' ? ' · To refresh, use the Codex dashboard refresh command.</div>' : (isNoInstructionHost(data) ? ' · To refresh, run ' + hostRefreshHtml(data) + '.</div>' : ' · To refresh, run <span class="update-cmd">/token-optimizer</span> again.</div>'));
|
|
3277
3365
|
}
|
|
3278
3366
|
|
|
3279
3367
|
if (secItems.length === 0) {
|
|
3280
3368
|
if (!data.plan && !data.auto_plan) {
|
|
3281
3369
|
html += '<div class="empty-state" style="text-align:center;padding:2rem 1rem;">' +
|
|
3282
3370
|
'<div style="font-size:1.5rem;margin-bottom:0.5rem;">No optimization plan yet</div>' +
|
|
3283
|
-
'<div style="color:var(--c-text-dim);margin-bottom:1rem;">' + (data.runtime === 'codex' ? 'Use live Codex sessions and refresh the dashboard to generate personalized recommendations with toggle items here.' : 'Run <span class="update-cmd" style="cursor:pointer">/token-optimizer</span> in ' + esc(data.runtime_label || 'Claude Code') + ' to generate personalized recommendations with toggle items here.') + '</div>' +
|
|
3371
|
+
'<div style="color:var(--c-text-dim);margin-bottom:1rem;">' + (data.runtime === 'codex' ? 'Use live Codex sessions and refresh the dashboard to generate personalized recommendations with toggle items here.' : (isNoInstructionHost(data) ? 'Refresh the dashboard to generate recommendations from your ' + esc(data.runtime_label || 'runtime') + ' config here.' : 'Run <span class="update-cmd" style="cursor:pointer">/token-optimizer</span> in ' + esc(data.runtime_label || 'Claude Code') + ' to generate personalized recommendations with toggle items here.')) + '</div>' +
|
|
3284
3372
|
'</div>';
|
|
3285
3373
|
} else {
|
|
3286
3374
|
html += '<div class="empty-state">No items in this category.</div>';
|
|
@@ -3440,34 +3528,23 @@ var DB = (function() {
|
|
|
3440
3528
|
// renderSavings render it identically without duplicating the body logic.
|
|
3441
3529
|
// Reads trends data from the global `data`; the savings object is passed as
|
|
3442
3530
|
// `savings` (data.savings in renderTrends, the in-scope `s` in renderSavings).
|
|
3443
|
-
// SPENT =
|
|
3444
|
-
//
|
|
3445
|
-
// transcripts, with cache read/write classes excluded. NOT sum(model_mix):
|
|
3531
|
+
// SPENT = deduplicated fresh input + output on actual activity days.
|
|
3532
|
+
// Cache reads and writes are excluded. NOT sum(model_mix):
|
|
3446
3533
|
// model_mix can omit unattributed tokens. Fail-open to that sum rather than 0.
|
|
3447
|
-
// SAVED = savings.total_tokens. Fail-open:
|
|
3448
|
-
// entirely);
|
|
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.
|
|
3449
3538
|
// The model-mix "where the spent went" bar reconciles to SPENT via a trailing
|
|
3450
3539
|
// "untracked" segment for SPENT - sum(model_mix) (tokens billed without a
|
|
3451
3540
|
// model tag). Returns '' when the card should not render.
|
|
3452
3541
|
function tokensSavedCardHtml(savings) {
|
|
3453
3542
|
var s = savings || {};
|
|
3454
3543
|
var tsSavedTokens = Number(s.total_tokens) || 0;
|
|
3455
|
-
if (tsSavedTokens <= 0) return '';
|
|
3456
|
-
var tsTrends = data.trends || {};
|
|
3457
|
-
var tsSpentBasis = tsTrends.spent_token_basis || {};
|
|
3458
|
-
var tsModelMix = tsTrends.model_mix || {};
|
|
3459
|
-
var tsModelTotal = 0;
|
|
3460
|
-
for (var tsMk in tsModelMix) { tsModelTotal += tsModelMix[tsMk]; }
|
|
3461
|
-
var tsIsCodex = data.runtime === 'codex';
|
|
3462
|
-
var tsPeriodDays = Number(tsTrends.period_days) || Number(s.period_days) || 30;
|
|
3463
|
-
// SPENT = provider-stats-compatible total, fail-open to sum(model_mix).
|
|
3464
|
-
var tsReportedTotal = Number(tsTrends.total_tokens) || 0;
|
|
3465
|
-
var tsSpentTokens = tsReportedTotal > 0 ? tsReportedTotal : tsModelTotal;
|
|
3466
|
-
// (tsWouldSendTotal / percentages are computed below, AFTER the estimated
|
|
3467
|
-
// tier is summed: the card headlines the FULL saved total in every state.)
|
|
3468
3544
|
// Estimated-tier tokens (kept OUT of the measured SAVED total by
|
|
3469
|
-
// _get_savings_summary). Surfaced
|
|
3470
|
-
//
|
|
3545
|
+
// _get_savings_summary). Surfaced in the footer as the estimated slice,
|
|
3546
|
+
// labelled with whichever estimated categories are present, and they keep
|
|
3547
|
+
// the card alive when the measured floor is zero.
|
|
3471
3548
|
// Field names match _get_merged_savings' re-export: mcp_cap_estimated
|
|
3472
3549
|
// keeps its suffix; hint_followed and verbosity_steer drop the _estimated
|
|
3473
3550
|
// suffix (the summary's *_estimated locals are re-keyed without it).
|
|
@@ -3490,8 +3567,25 @@ var DB = (function() {
|
|
|
3490
3567
|
var tk = Number(obj && obj.tokens_saved) || 0;
|
|
3491
3568
|
if (tk > 0) tsEstItems.push({ label: label, tokens: tk });
|
|
3492
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');
|
|
3493
3574
|
var tsEstTokens = tsEstItems.reduce(function(a, b) { return a + b.tokens; }, 0);
|
|
3494
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.)
|
|
3495
3589
|
// FULL saved total = measured floor + estimated tier. The headline is
|
|
3496
3590
|
// ALWAYS the full number, never the floor alone; the measured-vs-estimated
|
|
3497
3591
|
// split stays visible right under it so the honesty travels with the size,
|
|
@@ -3564,6 +3658,10 @@ var DB = (function() {
|
|
|
3564
3658
|
return;
|
|
3565
3659
|
}
|
|
3566
3660
|
|
|
3661
|
+
if (t.activity_coverage && t.activity_coverage.complete === false) {
|
|
3662
|
+
html += '<div class="empty-state">Usage coverage incomplete: ' + fn(t.activity_coverage.undated_sessions || 0) + ' sessions have missing activity dates. Undated usage is excluded from period totals.</div>';
|
|
3663
|
+
}
|
|
3664
|
+
|
|
3567
3665
|
// Pricing tier display
|
|
3568
3666
|
var tierLabel = (data.pricing_tier_label || t.pricing_tier_label || (isCodex ? 'OpenAI API-equivalent pricing' : 'Anthropic API'));
|
|
3569
3667
|
var tiers = data.pricing_tiers || {};
|
|
@@ -3653,7 +3751,7 @@ var DB = (function() {
|
|
|
3653
3751
|
// hoisted tokensSavedCardHtml + modelMixBodyHtml helpers). Replaces the
|
|
3654
3752
|
// former standalone Model Mix card — the model-mix-as-usage section is
|
|
3655
3753
|
// now inside the Tokens Saved card, reconciled to the billable SPENT.
|
|
3656
|
-
// Fail-open: returns '' when
|
|
3754
|
+
// Fail-open: returns '' only when measured AND estimated are both ≤ 0.
|
|
3657
3755
|
html += tokensSavedCardHtml(data.savings || {});
|
|
3658
3756
|
|
|
3659
3757
|
// Daily breakdown with date navigation
|
|
@@ -4195,11 +4293,64 @@ var DB = (function() {
|
|
|
4195
4293
|
: ((isFinite(Number(rw.extra_work_pct)) && Number(rw.extra_work_pct) > 0)
|
|
4196
4294
|
? '<div class="metric-large" style="text-wrap:balance;text-shadow:none;"><em style="font-style:normal;color:var(--c-accent-cyan);">≈' + rw.extra_work_pct + '%</em> more work per token</div>'
|
|
4197
4295
|
: '<div class="metric-large" style="text-wrap:balance;text-shadow:none;">' + (usdHeadline || '<em style="font-style:normal;color:var(--c-accent-cyan);">more work</em>') + '</div>');
|
|
4296
|
+
// Visible: one short plain line. The technical explanation of how each
|
|
4297
|
+
// figure is built goes to the fold at the bottom of the card.
|
|
4298
|
+
// Lever copy follows each factor's own value: a routing factor below 1 is
|
|
4299
|
+
// a heavier mix and is never called lighter; pending or unavailable
|
|
4300
|
+
// routing is stated instead of shown as a number.
|
|
4301
|
+
var rwContextMult = Number(rw.context_multiplier);
|
|
4302
|
+
var rwContextLighter = isFinite(rwContextMult) && rwContextMult > 1;
|
|
4303
|
+
var rwContextText = rwContextLighter
|
|
4304
|
+
? 'Lighter context (×' + rw.context_multiplier + ')'
|
|
4305
|
+
: 'Context is unchanged (×1)';
|
|
4306
|
+
var rwRoutingMult = rw.routing_multiplier == null ? NaN : Number(rw.routing_multiplier);
|
|
4307
|
+
var rwRoutingKnown = isFinite(rwRoutingMult) && rwRoutingMult > 0;
|
|
4308
|
+
var rwPendingSessions = Number(rw.routing_pending_sessions);
|
|
4309
|
+
var rwRoutingMissing = rw.routing_state === 'pending'
|
|
4310
|
+
? 'model routing is pending while ' + (rwPendingSessions > 0 ? rwPendingSessions + ' sessions are' : 'sessions are') + ' re-measured, so it is not included yet'
|
|
4311
|
+
: 'model routing could not be measured, so it is not included';
|
|
4312
|
+
var rwLeverDetail;
|
|
4313
|
+
if (rwRoutingKnown && rwRoutingMult > 1) {
|
|
4314
|
+
rwLeverDetail = rwContextText + (rwContextLighter
|
|
4315
|
+
? ' and a lighter model mix (×' + rwRoutingMult + ') let each token do more.'
|
|
4316
|
+
: '; a lighter model mix (×' + rwRoutingMult + ') lets each token do more.');
|
|
4317
|
+
} else if (rwRoutingKnown && rwRoutingMult < 1) {
|
|
4318
|
+
rwLeverDetail = rwContextText + (rwContextLighter ? ' lets each token do more; a' : '; a') + ' heavier model mix (×' + rwRoutingMult + ') means each token uses more of your plan.';
|
|
4319
|
+
} else if (rwRoutingKnown) {
|
|
4320
|
+
rwLeverDetail = rwContextText + (rwContextLighter ? ' lets each token do more;' : ';') + ' the model mix is unchanged (×1).';
|
|
4321
|
+
} else {
|
|
4322
|
+
rwLeverDetail = rwContextText + (rwContextLighter ? ' lets each token do more;' : ';') + ' ' + rwRoutingMissing + '.';
|
|
4323
|
+
}
|
|
4324
|
+
var rwRoutingMethod = rwRoutingKnown
|
|
4325
|
+
? 'model mix ×' + rwRoutingMult + ' (above 1 lighter, below 1 heavier, from the routing estimate on the Savings tab)'
|
|
4326
|
+
: 'no model-mix factor (' + (rw.routing_state === 'pending' ? 'routing pending' : 'routing unavailable') + ')';
|
|
4327
|
+
var rwRoutingCoverage = Number(rw.routing_coverage);
|
|
4328
|
+
var rwRoutingExcluded = rw.routing_excluded_models || {};
|
|
4329
|
+
var rwRoutingOut = [].concat(rwRoutingExcluded.premium || [], rwRoutingExcluded.unpriced || [], rwRoutingExcluded.free || []);
|
|
4330
|
+
// The coverage line names the window the snapshot actually computed over
|
|
4331
|
+
// (routing_window_days); payloads from before the field fall back to 30.
|
|
4332
|
+
var rwRoutingDays = Number(rw.routing_window_days);
|
|
4333
|
+
if (!isFinite(rwRoutingDays) || rwRoutingDays <= 0) rwRoutingDays = 30;
|
|
4334
|
+
var rwRoutingWindowTxt = 'the last ' + rwRoutingDays + (rwRoutingDays === 1 ? ' day’s' : ' days’');
|
|
4335
|
+
var rwRoutingScope = (rwRoutingKnown && isFinite(rwRoutingCoverage) && rwRoutingCoverage > 0)
|
|
4336
|
+
? ' The model mix compares ' + Math.round(rwRoutingCoverage * 100) + '% of ' + rwRoutingWindowTxt + ' tokens' + (rwRoutingOut.length ? '; left out: ' + esc(rwRoutingOut.join(', ')) : '') + '.'
|
|
4337
|
+
: '';
|
|
4338
|
+
var rwRoutingUnsplit = Number(rw.routing_unsplit_tokens);
|
|
4339
|
+
if (rwRoutingUnsplit > 0) {
|
|
4340
|
+
rwRoutingScope += ' Left out of the model-mix comparison: ' + fn(rwRoutingUnsplit) + ' tokens without a token-class split.';
|
|
4341
|
+
}
|
|
4198
4342
|
var rwEfficiencyDetail = rwHasCostEfficiency
|
|
4199
|
-
? 'A comparable session fell from <strong>' + rwMoney(rwBeforeCost) + '</strong> to <strong>' + rwMoney(rwAfterCost) + '</strong>' + (rwCostCutDisplay !== null ? '
|
|
4200
|
-
:
|
|
4343
|
+
? 'A comparable session fell from <strong>' + rwMoney(rwBeforeCost) + '</strong> to <strong>' + rwMoney(rwAfterCost) + '</strong>' + (rwCostCutDisplay !== null ? ' (about ' + rwCostCutDisplay + '% cheaper)' : '') + '.'
|
|
4344
|
+
: rwLeverDetail;
|
|
4345
|
+
var rwEfficiencyMethod = rwHasCostEfficiency
|
|
4346
|
+
? 'This cost-efficiency lens combines lighter context, the cache re-read cascade, and model routing.'
|
|
4347
|
+
: 'Context ×' + rw.context_multiplier + ' and ' + rwRoutingMethod + ' give a per-token throughput multiplier, shown separately from the window headroom and dollar figures.';
|
|
4348
|
+
rwEfficiencyMethod += rwRoutingScope;
|
|
4201
4349
|
var rwTokenFloorDetail = (rwTokenFloorPct !== null)
|
|
4202
|
-
? '<div
|
|
4350
|
+
? '<div class="plain-line">About <strong>' + fn(rwSavedTokens) + '</strong> tokens never had to be sent, roughly ' + rwTokenFloorPct + '% of what would have been.</div>'
|
|
4351
|
+
: '';
|
|
4352
|
+
var rwTokenFloorMethod = (rwTokenFloorPct !== null)
|
|
4353
|
+
? 'Separate measured token floor: ' + fn(rwSavedTokens) + ' never sent on ' + fn(rwSpentTokens) + ' <code>/stats</code>-compatible spent, ≈' + rwTokenFloorPct + '% of the would-be token load.'
|
|
4203
4354
|
: '';
|
|
4204
4355
|
// Tier chip reflects the USD spine's measured-vs-estimated boundary:
|
|
4205
4356
|
// context $ is metered, routing $ is an estimated counterfactual.
|
|
@@ -4221,13 +4372,13 @@ var DB = (function() {
|
|
|
4221
4372
|
// Cost efficiency is the transformation lens; the token floor remains a
|
|
4222
4373
|
// separate measured line so neither percentage is forced to equal the other.
|
|
4223
4374
|
rwEfficiencyHeadline +
|
|
4224
|
-
'<div
|
|
4375
|
+
'<div class="plain-line">' + rwEfficiencyDetail + '</div>' +
|
|
4225
4376
|
rwTokenFloorDetail +
|
|
4226
4377
|
// Stands alone. An earlier revision opened with "before you hit your usage
|
|
4227
4378
|
// limits.", a continuation of the headline that reads as a truncated
|
|
4228
4379
|
// fragment once it wraps to its own line, and the limit panels below
|
|
4229
4380
|
// already establish which limits are meant.
|
|
4230
|
-
'<p style="margin:
|
|
4381
|
+
'<p style="margin:var(--s-3) 0 var(--s-4);color:var(--c-text-main);font-size:17px;line-height:1.6;text-wrap:pretty;">Token Optimizer keeps junk out of context' + (rwRoutingKnown && rwRoutingMult > 1 ? ' and runs routine turns on lighter models' : '') + ', so more of your plan goes to real work instead of waste.</p>' +
|
|
4231
4382
|
// Per-window bars when the meter is fresh enough; otherwise a note so the
|
|
4232
4383
|
// card degrades instead of vanishing (the multiplier + savings above still
|
|
4233
4384
|
// stand without the live meter).
|
|
@@ -4268,7 +4419,7 @@ var DB = (function() {
|
|
|
4268
4419
|
// report. Keep the button (it rebuilds savings/the rest), just stop
|
|
4269
4420
|
// implying it refreshes the window.
|
|
4270
4421
|
var staleNote = stale
|
|
4271
|
-
? '
|
|
4422
|
+
? ' It updates only while ' + esc(data.runtime_label || 'Claude Code') + ' is running; Regenerate will not refresh it.'
|
|
4272
4423
|
: '';
|
|
4273
4424
|
return '<div style="margin-top:var(--s-3);font-size:13px;color:' + col + ';">' +
|
|
4274
4425
|
(stale ? '⚠ ' : '') + 'Window reading as of ' + esc(whenStr) + ' (' + ageStr + ').' + staleNote +
|
|
@@ -4284,16 +4435,22 @@ var DB = (function() {
|
|
|
4284
4435
|
// block makes "clicked but nothing happened" impossible to miss.
|
|
4285
4436
|
'<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>';
|
|
4286
4437
|
})() +
|
|
4287
|
-
'<div style="margin-top:var(--s-4);padding-top:var(--s-3);border-top:1px solid var(--c-border);font-size:
|
|
4288
|
-
|
|
4289
|
-
//
|
|
4290
|
-
//
|
|
4291
|
-
// carry -- the
|
|
4292
|
-
// because it needs the live JS value.
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4438
|
+
'<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
|
+
// Technical method lives in a fold. rw.proxy is the single source of the
|
|
4441
|
+
// measured-vs-estimated boundary AND the ledger detail; we add only the
|
|
4442
|
+
// one fact proxy can't carry -- the headline figure is its own unit, not
|
|
4443
|
+
// a sum of the dollars -- because it needs the live JS value.
|
|
4444
|
+
'<details class="fold"><summary>How these numbers are measured</summary><div class="fold__body">' +
|
|
4445
|
+
'<p>' + esc(rw.proxy) + '</p>' +
|
|
4446
|
+
'<p>' + rwEfficiencyMethod + '</p>' +
|
|
4447
|
+
(rwTokenFloorMethod ? '<p>' + rwTokenFloorMethod + '</p>' : '') +
|
|
4448
|
+
'<p>' + (rwHasCostEfficiency
|
|
4449
|
+
? 'The ≈' + rwEfficiencyMult.toFixed(1) + '× figure is the before/after per-session cost ratio, not a sum of the token floor or per-window dollar figures.'
|
|
4450
|
+
: (rwHasLegacyMultiplier
|
|
4451
|
+
? 'The ≈' + rw.extra_work_pct + '% is a separate per-token throughput multiplier, not a sum of the per-window dollar figures.'
|
|
4452
|
+
: 'The per-token throughput multiplier is separate from the per-window dollar figures.')) + '</p>' +
|
|
4453
|
+
'</div></details>' +
|
|
4297
4454
|
'</div>' +
|
|
4298
4455
|
'</div>';
|
|
4299
4456
|
}
|
|
@@ -4312,6 +4469,7 @@ var DB = (function() {
|
|
|
4312
4469
|
var days = Number(s.period_days) || 30;
|
|
4313
4470
|
var mr = s.model_routing || {};
|
|
4314
4471
|
var cd = s.cache_drop || {};
|
|
4472
|
+
var op = s.oneshot_pricing || {};
|
|
4315
4473
|
var ow = s.output_waste || {};
|
|
4316
4474
|
var beh = s.behavioral_estimate || {};
|
|
4317
4475
|
var sd = s.structural_detail || {};
|
|
@@ -4349,6 +4507,7 @@ var DB = (function() {
|
|
|
4349
4507
|
}
|
|
4350
4508
|
function fmtTok(n) {
|
|
4351
4509
|
var v = Number(n) || 0;
|
|
4510
|
+
if (v >= 1e9) return (v / 1e9).toFixed(1) + 'B';
|
|
4352
4511
|
if (v >= 1e6) return (v / 1e6).toFixed(1) + 'M';
|
|
4353
4512
|
if (v >= 1e3) return Math.round(v / 1e3) + 'K';
|
|
4354
4513
|
return String(Math.round(v));
|
|
@@ -4361,6 +4520,13 @@ var DB = (function() {
|
|
|
4361
4520
|
return '<details class="fold"><summary>' + esc(summary) + '</summary>' +
|
|
4362
4521
|
'<div class="fold__body">' + bodyHtml + '</div></details>';
|
|
4363
4522
|
}
|
|
4523
|
+
// "How this is counted" bullets for a fold. Items are ready HTML (esc()'d by the
|
|
4524
|
+
// caller); falsy items are skipped so callers can pass conditionals inline.
|
|
4525
|
+
function countedList(items) {
|
|
4526
|
+
var li = items.filter(Boolean);
|
|
4527
|
+
return li.length ? '<p><strong>How this is counted</strong></p><ul>' +
|
|
4528
|
+
li.map(function(x) { return '<li>' + x + '</li>'; }).join('') + '</ul>' : '';
|
|
4529
|
+
}
|
|
4364
4530
|
|
|
4365
4531
|
// ---- mechanism pillars (structural / runtime / behavioral). Behavioral holds only
|
|
4366
4532
|
// what you're actually getting (realized routing + estimated loop prevention); cache-drop
|
|
@@ -4369,11 +4535,13 @@ var DB = (function() {
|
|
|
4369
4535
|
var rs = s.retrieval_serve || {};
|
|
4370
4536
|
var rle = s.resume_lean_estimated || {};
|
|
4371
4537
|
var vs = s.verbosity_steer || {};
|
|
4538
|
+
var cr = s.checkpoint_restore_estimated || {};
|
|
4372
4539
|
var cp = s.counted_period || {};
|
|
4373
4540
|
var rereadMo = cp.available ? mo(cp.reread_usd) : 0;
|
|
4374
4541
|
var hf = s.hint_followed || {};
|
|
4375
|
-
// Avoided-search: prefer the
|
|
4376
|
-
//
|
|
4542
|
+
// Avoided-search: prefer the hint->read estimate (hint_followed; the
|
|
4543
|
+
// hint->read pair is observed, the avoided-search magnitude is a fixed
|
|
4544
|
+
// estimate); fall back to the cohort estimate only before any hint has
|
|
4377
4545
|
// fired, so the two are never summed (no double-count).
|
|
4378
4546
|
var hfHasData = (Number(hf.events) || 0) > 0;
|
|
4379
4547
|
var avoidedSearchMo = hfHasData ? mo(hf.cost_saved_usd) : mo(rs.cost_saved_usd);
|
|
@@ -4386,33 +4554,95 @@ var DB = (function() {
|
|
|
4386
4554
|
// always reconcile exactly to gettingMo (measured + estimated). Every estItems
|
|
4387
4555
|
// entry maps to exactly one pillar: loops/sub-agent/mcp_cap -> runtime;
|
|
4388
4556
|
// heeded/handover/avoided-search/lean-resumes -> behavioral.
|
|
4389
|
-
var behavMo = mo(mr.realized_cost_usd) + 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);
|
|
4557
|
+
var behavMo = mo(mr.realized_cost_usd) + 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);
|
|
4390
4558
|
// ---- trust tiers: measured / estimated / opportunity. Opportunity NEVER folds into the headline. ----
|
|
4391
4559
|
// Measured = billable events we metered (runtime compression + realized model routing).
|
|
4392
|
-
|
|
4560
|
+
// Routing joins the measured tier only when its valuation is measured; the
|
|
4561
|
+
// standardized newest-card schedule makes it an estimate (Other estimates).
|
|
4562
|
+
var routingEstimated = mr.evidence === 'estimated';
|
|
4563
|
+
var measuredMo = mo(s.total_cost_usd) + (routingEstimated ? 0 : mo(mr.realized_cost_usd));
|
|
4393
4564
|
// Estimated = genuine TO-realized counterfactuals grounded in YOUR behavior; each carries a sample size.
|
|
4394
4565
|
// (Pillars + estimated reconcile to gettingMo: mcp_cap folds into runtime.)
|
|
4395
4566
|
var estItems = [
|
|
4396
|
-
{ label: '
|
|
4397
|
-
{ label: '
|
|
4398
|
-
{
|
|
4399
|
-
{ label: '
|
|
4400
|
-
{ label: '
|
|
4401
|
-
{
|
|
4402
|
-
{ label: '
|
|
4403
|
-
{ label: '
|
|
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
|
+
{ key: 'behavioral_estimate', label: 'loops prevented', amt: mo(beh.cost_saved_usd), n: Number(beh.loop_events) || 0, unit: 'events' },
|
|
4569
|
+
{ 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
|
+
{ 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
|
+
{ key: 'handover_rerun', label: 'continuity handover', amt: mo(hr.cost_saved_usd), n: Number(hr.restored_sessions) || 0, unit: 'restored', conf: hr.confidence },
|
|
4573
|
+
{ 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
|
+
{ 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' }
|
|
4404
4577
|
].filter(function(it){ return it.amt > 0 || it.conf; });
|
|
4405
4578
|
var estimatedMo = estItems.reduce(function(a, b){ return a + b.amt; }, 0);
|
|
4406
4579
|
// What you're getting = measured + estimated (both real value; estimated shown split-out, never hidden).
|
|
4407
4580
|
var gettingMo = measuredMo + rereadMo + estimatedMo;
|
|
4581
|
+
// New payloads share the CLI's complete action total. Older saved dashboards
|
|
4582
|
+
// retain the component calculation above until their next regeneration.
|
|
4583
|
+
var actionSavings = s.action_savings;
|
|
4584
|
+
if (actionSavings) {
|
|
4585
|
+
measuredMo = mo(actionSavings.logged_usd) + mo(actionSavings.routing_measured_usd);
|
|
4586
|
+
rereadMo = mo(actionSavings.reread_usd);
|
|
4587
|
+
estimatedMo = mo(actionSavings.estimated_usd) + mo(actionSavings.routing_estimated_usd);
|
|
4588
|
+
gettingMo = mo(actionSavings.total_usd);
|
|
4589
|
+
}
|
|
4590
|
+
// Whole-cent display values from the payload: the parts shown on the card
|
|
4591
|
+
// add up to the total shown, with the exact amounts kept in the payload.
|
|
4592
|
+
var exactCents = null;
|
|
4593
|
+
var dispCents = actionSavings && actionSavings.display;
|
|
4594
|
+
if (dispCents && dispCents.components_cents && dispCents.estimates_cents) {
|
|
4595
|
+
var dc = dispCents.components_cents, de = dispCents.estimates_cents;
|
|
4596
|
+
var estSumCents = Object.keys(de).reduce(function(a, k) { return a + de[k]; }, 0);
|
|
4597
|
+
exactCents = {
|
|
4598
|
+
total: dispCents.total_cents,
|
|
4599
|
+
logged: dc.logged + dc.routing_measured,
|
|
4600
|
+
reread: dc.reread,
|
|
4601
|
+
other: estSumCents + dc.routing_estimated,
|
|
4602
|
+
est: de,
|
|
4603
|
+
routingEstimated: dc.routing_estimated,
|
|
4604
|
+
avoidedKey: actionSavings.avoided_search_source
|
|
4605
|
+
};
|
|
4606
|
+
}
|
|
4607
|
+
function moneyCents(c) {
|
|
4608
|
+
return (c < 0 ? '-$' : '$') + (Math.abs(c) / 100).toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2});
|
|
4609
|
+
}
|
|
4610
|
+
function estCents(item) {
|
|
4611
|
+
var key = item.key === 'avoided_search' ? exactCents.avoidedKey : item.key;
|
|
4612
|
+
return key === 'routing_estimated' ? exactCents.routingEstimated : exactCents.est[key];
|
|
4613
|
+
}
|
|
4408
4614
|
// Opportunity = realizable if you act; never realized, never summed into "getting".
|
|
4409
4615
|
// output-waste is $ here; cache-drop is shown separately in TOKENS (re-written prefix) —
|
|
4410
4616
|
// its $ is Anthropic-specific (OpenAI/OpenCode cache writes are free), but the token count
|
|
4411
4617
|
// is a provider-neutral fact, matching Claude Code's own token-denominated display.
|
|
4412
4618
|
var recl = s.stale_reads_reclaimable || {};
|
|
4413
4619
|
var cdTokensMo = Math.round((Number(cd.est_drops) || 0) * (Number(cd.prefix_tokens) || 0) / Math.max(days, 1) * 30);
|
|
4414
|
-
|
|
4415
|
-
|
|
4620
|
+
// The big opportunity number holds only evidence-backed items (unused skills,
|
|
4621
|
+
// stale re-reads, full-file Writes). Routing rests on an assumed share of your
|
|
4622
|
+
// Opus work, so it gets its own line below the number and is never added in.
|
|
4623
|
+
var opportunityMo = mo(sp.cost_saved_usd) + mo(recl.cost_usd) + mo(ow.cost_saved_usd);
|
|
4624
|
+
// Round once: each item gets its floor in cents and the missing cents go to
|
|
4625
|
+
// the largest remainders, so the items shown add up to the number shown.
|
|
4626
|
+
var oppCents = (function(values) {
|
|
4627
|
+
// Snap to a millionth of a cent first so float noise from the monthly
|
|
4628
|
+
// scaling (32.625 becoming 32.62499...) rounds the same way as the text report.
|
|
4629
|
+
var exact = values.map(function(v) { var n = Math.round(Number(v) * 1e8) / 1e6; return isFinite(n) ? n : 0; });
|
|
4630
|
+
var floors = exact.map(function(x) { return Math.floor(x); });
|
|
4631
|
+
var total = Math.round(Math.round(exact.reduce(function(a, b) { return a + b; }, 0) * 1e6) / 1e6);
|
|
4632
|
+
var left = total - floors.reduce(function(a, b) { return a + b; }, 0);
|
|
4633
|
+
exact.map(function(x, i) { return i; })
|
|
4634
|
+
.sort(function(a, b) { return (exact[b] - floors[b]) - (exact[a] - floors[a]) || a - b; })
|
|
4635
|
+
.slice(0, Math.max(0, Math.min(left, exact.length)))
|
|
4636
|
+
.forEach(function(i) { floors[i] += 1; });
|
|
4637
|
+
return { structural: floors[0], output: floors[1], reclaimable: floors[2], total: total };
|
|
4638
|
+
})([mo(sp.cost_saved_usd), mo(ow.cost_saved_usd), mo(recl.cost_usd)]);
|
|
4639
|
+
var routingPotentialMo = mo(mr.potential_cost_usd);
|
|
4640
|
+
var cdCostMo = mo(cd.cost_saved_usd);
|
|
4641
|
+
var routingTokensMo = Number(mr.potential_tokens_monthly) > 0
|
|
4642
|
+
? Number(mr.potential_tokens_monthly)
|
|
4643
|
+
: mo(mr.potential_tokens);
|
|
4644
|
+
var routingFracPct = Math.round((mr.routable_fraction == null ? 0.2 : Number(mr.routable_fraction)) * 10000) / 100;
|
|
4645
|
+
var routingTarget = mr.target_model || "Sonnet";
|
|
4416
4646
|
var unusedSkills = Number(sp.unused_skills) || 0;
|
|
4417
4647
|
var currOpus = Math.round((Number(mr.current_opus_share) || 0) * 100);
|
|
4418
4648
|
var ts = data.generated_at ? new Date(data.generated_at).toLocaleString() : 'unknown';
|
|
@@ -4438,6 +4668,14 @@ var DB = (function() {
|
|
|
4438
4668
|
// larger, uncapped percentage implied by the counterfactual arms.
|
|
4439
4669
|
var shownSaving = Number(ba.monthly_savings_usd) || 0;
|
|
4440
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
|
+
: '');
|
|
4441
4679
|
html += '<div class="card wide savings-transformation" style="padding:var(--s-4);margin-bottom:var(--s-3);">' +
|
|
4442
4680
|
'<div class="label">Transformation · last ' + days + ' days · estimated</div>' +
|
|
4443
4681
|
'<div class="savings-amount">' + money(ba.monthly_savings_usd) +
|
|
@@ -4445,11 +4683,10 @@ var DB = (function() {
|
|
|
4445
4683
|
'<p class="lede">Your recent workload compared with your earlier way of working, at the same token prices.</p>' +
|
|
4446
4684
|
'<div class="savings-split"><span>Now <strong>' + money(nowCost) + '</strong></span>' +
|
|
4447
4685
|
'<span>Earlier workflow <strong>' + money(oldCost) + '</strong></span></div>' +
|
|
4448
|
-
'<div class="
|
|
4449
|
-
(
|
|
4450
|
-
? '<div class="note" style="margin-top:var(--s-2);">' + esc(ba.savings_cap_note) + '</div>'
|
|
4451
|
-
: '') +
|
|
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>' : '') +
|
|
4452
4688
|
fold('How this is estimated',
|
|
4689
|
+
countedList([ba.savings_capped && ba.savings_cap_note ? esc(ba.savings_cap_note) : '']) +
|
|
4453
4690
|
(wp
|
|
4454
4691
|
? '<p>Baseline: <strong>' + esc(wp.anchor_month) + '</strong>. We compare cost per ' + wpUnit +
|
|
4455
4692
|
' at constant prices, then apply the difference to the <strong>' +
|
|
@@ -4490,6 +4727,34 @@ var DB = (function() {
|
|
|
4490
4727
|
'<div class="label" style="margin-bottom:var(--s-2);">At or above your baseline this period</div>' +
|
|
4491
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>' +
|
|
4492
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>';
|
|
4493
4758
|
}
|
|
4494
4759
|
|
|
4495
4760
|
// ---- Tokens Saved card: the full card (hero + spent-vs-saved + model-
|
|
@@ -4505,22 +4770,80 @@ var DB = (function() {
|
|
|
4505
4770
|
html += '<div style="display:flex;gap:var(--s-3);flex-wrap:wrap;margin-bottom:var(--s-3);">';
|
|
4506
4771
|
var periodLabel = runRate ? 'last ' + days + ' days' : trackedDays + ' days tracked';
|
|
4507
4772
|
var heroAmt = gettingMo;
|
|
4773
|
+
// One plain visible line only when some of the total could not be priced; every
|
|
4774
|
+
// other counting note lives in the card's "Breakdown and method" fold.
|
|
4775
|
+
var actionPricingIncomplete = !!(cp.reread_pricing_note ||
|
|
4776
|
+
(actionSavings && actionSavings.reread_prices_available === false) || cp.reread_prices_available === false ||
|
|
4777
|
+
Number(s.compression_unpriced_tokens) > 0 ||
|
|
4778
|
+
(s.reprice_detail && Number(s.reprice_detail.unpriced_tokens) > 0));
|
|
4508
4779
|
html += '<div class="card savings-actions" style="flex:2;min-width:min(100%,320px);padding:var(--s-4);">' +
|
|
4509
4780
|
'<div class="label">Action savings · ' + periodLabel + '</div>' +
|
|
4510
|
-
'<div class="savings-amount">' + money(periodValue(heroAmt)) + '<span class="savings-unit"> logged + estimated</span></div>' +
|
|
4511
|
-
'<div class="savings-split"><span>Logged actions <strong>' + money(periodValue(measuredMo)) + '</strong></span>' +
|
|
4512
|
-
'<span>Repeat reads avoided <strong
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4781
|
+
'<div class="savings-amount">' + (exactCents ? moneyCents(exactCents.total) : money(periodValue(heroAmt))) + '<span class="savings-unit"> logged + estimated</span></div>' +
|
|
4782
|
+
'<div class="savings-split"><span>Logged actions <strong>' + (exactCents ? moneyCents(exactCents.logged) : money(periodValue(measuredMo))) + '</strong></span>' +
|
|
4783
|
+
'<span>Repeat reads avoided <strong>' +
|
|
4784
|
+
(actionSavings && actionSavings.reread_available === false ? 'Unavailable' :
|
|
4785
|
+
((actionSavings && actionSavings.reread_prices_available === false) || cp.reread_prices_available === false ?
|
|
4786
|
+
'Unpriced' : '~' + (exactCents ? moneyCents(exactCents.reread) : money(periodValue(rereadMo))))) + '</strong></span>' +
|
|
4787
|
+
'<span>Other estimates <strong>~' + (exactCents ? moneyCents(exactCents.other) : money(periodValue(estimatedMo))) + '</strong></span></div>' +
|
|
4788
|
+
(actionPricingIncomplete
|
|
4789
|
+
? '<p class="plain-line">Some older history has no exact price, so this is a priced subtotal.</p>'
|
|
4790
|
+
: (!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
|
+
// Usage without a token-class split (Cursor totals, model-daily-only
|
|
4795
|
+
// history, legacy rows) sits outside both routing arms. Say so instead of
|
|
4796
|
+
// letting an empty or partial routing figure read as complete coverage.
|
|
4797
|
+
(Number(mr.unsplit_tokens) > 0
|
|
4798
|
+
? '<p class="plain-line">' + Number(mr.unsplit_tokens).toLocaleString() +
|
|
4799
|
+
' tokens without a token-class split are left out of model routing.</p>' : '') +
|
|
4516
4800
|
fold('Breakdown and method',
|
|
4517
|
-
|
|
4801
|
+
countedList([
|
|
4802
|
+
'Includes the later benefit of context removed during this period. Initial removals are counted once.',
|
|
4803
|
+
cp.reread_pricing_note ? esc(cp.reread_pricing_note) : '',
|
|
4804
|
+
actionSavings && actionSavings.total_clamped ? 'Signed adjustments give a net total of ' +
|
|
4805
|
+
money(actionSavings.net_total_usd) + '; the headline has a $0 floor.' : '',
|
|
4806
|
+
Number(s.compression_unpriced_tokens) > 0 ?
|
|
4807
|
+
Math.round(Number(s.compression_unpriced_tokens)).toLocaleString() +
|
|
4808
|
+
' compression tokens are counted without a dollar value because their model rate is unavailable' +
|
|
4809
|
+
((Number(s.compression_unpriced_credit_tokens) > 0 || Number(s.compression_unpriced_debit_tokens) > 0)
|
|
4810
|
+
? ' (' + Math.round(Number(s.compression_unpriced_credit_tokens) || 0).toLocaleString() + ' credits, ' +
|
|
4811
|
+
Math.round(Number(s.compression_unpriced_debit_tokens) || 0).toLocaleString() + ' debits)' : '') + '.' : '',
|
|
4812
|
+
s.reprice_detail && Number(s.reprice_detail.unpriced_tokens) > 0 ?
|
|
4813
|
+
Math.round(Number(s.reprice_detail.unpriced_tokens)).toLocaleString() +
|
|
4814
|
+
' logged tokens ran on models with no known rate; their dollar value is not included.' : '',
|
|
4815
|
+
op.removal_events > 0 ? 'Initial removals above are priced at the input rate, a minimum.' +
|
|
4816
|
+
(Number(op.class_premium_usd) >= 0.005
|
|
4817
|
+
? ' The next call billed new context at a cache-write rate for ' +
|
|
4818
|
+
Math.round(Number(op.class_events) || 0).toLocaleString() + ' removals: about ' +
|
|
4819
|
+
money(Number(op.class_premium_usd)) + ' more, not in the total.' : '') : '',
|
|
4820
|
+
!cp.available ? 'Repeat-read coverage is unavailable here; logged actions are still included.' : ''
|
|
4821
|
+
]) +
|
|
4822
|
+
'<p>Logged actions include output trims, context reductions, setup changes and, when your earlier model mix is priced from your own usage, routing savings. ' +
|
|
4518
4823
|
'Prices may be allocated from each session’s recorded model mix.</p>' +
|
|
4519
4824
|
'<p>Repeat reads use recorded later turns up to each session’s next compaction. ' +
|
|
4520
4825
|
'This assumes the removed context would otherwise have stayed until that compaction. ' +
|
|
4521
|
-
'The value belongs to the date of removal, not the date of each later read. Missing transcripts
|
|
4522
|
-
'<p>Stored repeat-read values
|
|
4826
|
+
'The value belongs to the date of removal, not the date of each later read. Missing transcripts add no new repeat-read estimate; previously verified history is retained.</p>' +
|
|
4827
|
+
'<p>Stored repeat-read values include only verified per-turn rates. Unpriced contributions retain their token counts.' +
|
|
4523
4828
|
(cp.computed_at ? ' Last counted: ' + esc(new Date(cp.computed_at).toLocaleString()) + '.' : '') + '</p>' +
|
|
4829
|
+
(Number(mr.premium_share) > 0
|
|
4830
|
+
? '<p>Routing compares your current model mix with your earlier mix. Premium models you chose (' +
|
|
4831
|
+
esc((mr.premium_models || []).map(function(f) { return f.charAt(0).toUpperCase() + f.slice(1); }).join(', ')) + ', ' +
|
|
4832
|
+
Math.round(Number(mr.premium_share) * 100) + '% of tokens, about ' + money(mo(mr.premium_cost_usd)) + per +
|
|
4833
|
+
' at API rates) are left out, so they do not offset the shift toward lighter models.</p>' : '') +
|
|
4834
|
+
((mr.baseline_reference_priced || []).length
|
|
4835
|
+
? '<p>Routing compares your earlier and current mix on one price list, the newest card of each family (' +
|
|
4836
|
+
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. The figure is listed under estimates.</p>' : '') +
|
|
4838
|
+
(Math.abs(mo(mr.generation_price_delta_usd)) >= 0.01
|
|
4839
|
+
? '<p>At the exact cards you ran, the same work cost about ' + money(Math.abs(mo(mr.generation_price_delta_usd))) +
|
|
4840
|
+
(Number(mr.generation_price_delta_usd) > 0 ? ' more' : ' less') +
|
|
4841
|
+
' than on that price list. That gap is model generation pricing, not routing.</p>' : '') +
|
|
4842
|
+
((Number(mr.unpriced_tokens) > 0 || Number(mr.free_tokens) > 0)
|
|
4843
|
+
? '<p>Models without a known price (' +
|
|
4844
|
+
esc((mr.unpriced_models || []).concat(mr.free_models || []).slice(0, 3).join(', ')) + ', ' +
|
|
4845
|
+
(Number(mr.unpriced_tokens || 0) + Number(mr.free_tokens || 0)).toLocaleString() +
|
|
4846
|
+
' tokens) are left out of the routing comparison, not counted as free.</p>' : '') +
|
|
4524
4847
|
((s.reprice_detail && Number(s.reprice_detail.delta_usd) !== 0)
|
|
4525
4848
|
? '<p>Model-rate allocation: ' + money(Number(s.reprice_detail.delta_usd)) +
|
|
4526
4849
|
' across ' + Number(s.reprice_detail.repriced_tokens || 0).toLocaleString() +
|
|
@@ -4529,21 +4852,63 @@ var DB = (function() {
|
|
|
4529
4852
|
'<span>Runtime <strong>' + money(periodValue(runtimeMo + rereadMo)) + '</strong></span>' +
|
|
4530
4853
|
'<span>Habits <strong>' + money(periodValue(behavMo)) + '</strong></span></div>' +
|
|
4531
4854
|
(estItems.length ? '<p>Other estimates:</p>' + estItems.map(function(it) {
|
|
4532
|
-
|
|
4855
|
+
var shown = exactCents && estCents(it) != null ? moneyCents(estCents(it)) : money(periodValue(it.amt));
|
|
4856
|
+
return '<p>' + esc(it.label) + ': <strong>' + shown + '</strong> (' +
|
|
4533
4857
|
it.n.toLocaleString() + ' ' + esc(it.unit) + (it.conf ? ', ' + esc(String(it.conf)) : '') + ').</p>';
|
|
4534
4858
|
}).join('') : '') +
|
|
4535
4859
|
'<p>' + billingCaption + '</p>') +
|
|
4536
4860
|
'</div>';
|
|
4537
4861
|
var cc = s.counted_cumulative || {};
|
|
4538
|
-
|
|
4862
|
+
var sia = (si && si.all_in) || null;
|
|
4863
|
+
if (sia && Number(sia.total_usd) > 0) {
|
|
4864
|
+
var siaParts = sia.components_usd || {};
|
|
4865
|
+
var siaRouting = (Number(siaParts.routing_measured) || 0) + (Number(siaParts.routing_estimated) || 0);
|
|
4866
|
+
var siaPending = sia.routing_pending || sia.remeasuring;
|
|
4867
|
+
var siaLeft = Math.max(Number(sia.routing_pending_sessions) || 0, Number(sia.remeasuring_sessions) || 0);
|
|
4868
|
+
html += '<div class="card savings-history" style="flex:1;min-width:min(100%,260px);padding:var(--s-4);">' +
|
|
4869
|
+
'<div class="label">Saved since ' + esc(prettyDate(si.install_date)) + '</div>' +
|
|
4870
|
+
'<div class="savings-amount">' + money(sia.total_usd) +
|
|
4871
|
+
(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">Re-measuring older history (' + siaLeft.toLocaleString() +
|
|
4873
|
+
' session' + (siaLeft === 1 ? '' : 's') + ' left). This total will grow when they finish.</p>' : '') +
|
|
4874
|
+
'<p class="plain-line">Same four parts as the monthly total, added up since install.</p>' +
|
|
4875
|
+
fold('Breakdown and history',
|
|
4876
|
+
'<p>Model routing: <strong>' + money(siaRouting) + '</strong> (estimated).</p>' +
|
|
4877
|
+
(Number(sia.routing_unsplit_tokens) > 0
|
|
4878
|
+
? '<p>' + Number(sia.routing_unsplit_tokens).toLocaleString() +
|
|
4879
|
+
' tokens without a token-class split are left out of model routing.</p>' : '') +
|
|
4880
|
+
'<p>Repeat reads avoided: <strong>' + money(siaParts.reread) + '</strong> (modeled).</p>' +
|
|
4881
|
+
'<p>Logged actions: <strong>' + money(siaParts.logged) + '</strong>.</p>' +
|
|
4882
|
+
'<p>Other estimates: <strong>' + money(sia.estimated_usd) + '</strong>.</p>' +
|
|
4883
|
+
((Number(cc.total_usd) > 0 || cc.available) ?
|
|
4884
|
+
'<p>Context trimming on its own (initial removals + repeat reads): ' +
|
|
4885
|
+
(cc.prices_available === false ? 'Unpriced' : money(Math.max(0, Number(cc.total_usd) || 0))) + '.</p>' : '') +
|
|
4886
|
+
countedList([
|
|
4887
|
+
cc.pricing_note ? esc(cc.pricing_note) : '',
|
|
4888
|
+
cc.media_note ? esc(cc.media_note) : ''
|
|
4889
|
+
]) +
|
|
4890
|
+
'<p>Tracked over ' + Number(si.days || 0).toLocaleString() + ' days. Historical entries remain after their source transcripts rotate.</p>' +
|
|
4891
|
+
'<p>' + billingCaption + '</p>') +
|
|
4892
|
+
'</div>';
|
|
4893
|
+
} else if (Number(cc.total_usd) > 0 || (cc.available && Number(cc.events) > 0)) {
|
|
4539
4894
|
html += '<div class="card savings-history" style="flex:1;min-width:min(100%,260px);padding:var(--s-4);">' +
|
|
4540
4895
|
'<div class="label">Context savings · all time</div>' +
|
|
4541
|
-
'<div class="savings-amount">' + money(cc.total_usd)
|
|
4542
|
-
|
|
4543
|
-
(
|
|
4544
|
-
|
|
4896
|
+
'<div class="savings-amount">' + (cc.prices_available === false ? 'Unpriced' : money(Math.max(0, Number(cc.total_usd) || 0))) +
|
|
4897
|
+
(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">Re-measuring (' + Number(cc.remeasuring_sessions || 0).toLocaleString() +
|
|
4899
|
+
' 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 ? '<strong>' + (cp.prices_available === false ? 'Unpriced' : money(cp.total_usd)) + '</strong> from removals in the last ' + days + ' days. ' : '') +
|
|
4901
|
+
'Overlaps with action savings.</p>' +
|
|
4545
4902
|
fold('History and coverage',
|
|
4546
|
-
|
|
4903
|
+
countedList([
|
|
4904
|
+
'Initial removals + modeled repeat reads.',
|
|
4905
|
+
cc.pricing_note ? esc(cc.pricing_note) : '',
|
|
4906
|
+
cc.media_note ? esc(cc.media_note) : '',
|
|
4907
|
+
Number(cc.total_usd) < 0 ? 'Signed net: ' + money(cc.total_usd) + '. Savings headline is floored at zero.' : '',
|
|
4908
|
+
'Excludes routing, setup and other estimates.'
|
|
4909
|
+
]) +
|
|
4910
|
+
'<p>' + (cc.oneshot_prices_available === false ? 'Unpriced' : money(cc.oneshot_usd)) + ' initial removals + ' +
|
|
4911
|
+
(cc.reread_prices_available === false ? 'Unpriced' : money(cc.reread_usd)) + ' modeled repeat reads.</p>' +
|
|
4547
4912
|
'<p>Stored history since ' + esc(prettyDate(cc.window_start)) + '. ' +
|
|
4548
4913
|
'Same removal-date method as the period total. Historical entries remain after their source transcripts rotate.</p>' +
|
|
4549
4914
|
'<p>Repeat reads assume the removed context would otherwise have stayed until the session’s next compaction. ' +
|
|
@@ -4564,33 +4929,73 @@ var DB = (function() {
|
|
|
4564
4929
|
// ---- SAVE MORE: suggestions, promoted right under the hero ----
|
|
4565
4930
|
var parts = [];
|
|
4566
4931
|
if ((Number(sp.cost_saved_usd) || 0) > 0 && unusedSkills > 0) {
|
|
4567
|
-
parts.push('Review ' + unusedSkills + ' skill' + (unusedSkills === 1 ? '' : 's') + ' not invoked in this window. Archiving what you no longer need is worth about ' +
|
|
4932
|
+
parts.push('Review ' + unusedSkills + ' skill' + (unusedSkills === 1 ? '' : 's') + ' not invoked in this window. Archiving what you no longer need is worth about ' + moneyCents(oppCents.structural) + per + ', automatically, from then on.');
|
|
4933
|
+
}
|
|
4934
|
+
if ((Number(recl.cost_usd) || 0) > 0) {
|
|
4935
|
+
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 + '.');
|
|
4568
4936
|
}
|
|
4569
4937
|
if ((Number(mr.potential_cost_usd) || 0) > 0) {
|
|
4570
|
-
parts.push('
|
|
4938
|
+
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.');
|
|
4571
4939
|
}
|
|
4572
4940
|
if (cdTokensMo > 0) {
|
|
4573
|
-
parts.push('Resume within the hour, or batch related work before stepping away. ' + (Number(cd.drop_sessions) || 0) + ' of your sessions idled past the cache window and re-wrote the prefix
|
|
4941
|
+
parts.push('Resume within the hour, or batch related work before stepping away. ' + (Number(cd.drop_sessions) || 0) + ' of your sessions idled past the cache window and re-wrote the prefix, about ' + cdTokensMo.toLocaleString() + ' tokens' + per + (cdCostMo > 0 ? ', worth about ' + money(cdCostMo) + per + ' at API rates' : '') + '.');
|
|
4574
4942
|
}
|
|
4575
4943
|
if ((Number(ow.cost_saved_usd) || 0) > 0) {
|
|
4576
|
-
parts.push('Favor targeted Edits over full-file Writes. About ' + (Number(ow.avoidable_writes) || 0) + ' of your Writes could have been Edits, worth about ' +
|
|
4944
|
+
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.');
|
|
4577
4945
|
}
|
|
4578
4946
|
if (parts.length > 0) {
|
|
4579
4947
|
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);">';
|
|
4580
4948
|
html += '<div class="label" style="margin-bottom:var(--s-2);color:var(--c-amber);letter-spacing:0.08em;">Money on the table · opportunity</div>';
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4949
|
+
if (opportunityMo > 0) {
|
|
4950
|
+
html += '<div style="display:flex;align-items:baseline;gap:var(--s-2);flex-wrap:wrap;">' +
|
|
4951
|
+
'<span style="font-family:var(--font-mono);font-weight:300;font-size:76px;line-height:0.9;color:var(--c-amber);text-shadow:0 0 30px rgba(217,164,65,0.5);letter-spacing:-0.02em;">' + moneyCents(oppCents.total) + '</span>' +
|
|
4952
|
+
'<span style="font-size:23px;color:var(--c-text-dim);font-family:var(--font-mono);">' + per + ' still on the table</span>' +
|
|
4953
|
+
'</div>';
|
|
4954
|
+
html += '<div class="lede" style="margin-top:var(--s-2);">Potential savings if you change your setup or habits. Excluded from the totals above.</div>';
|
|
4955
|
+
} else {
|
|
4956
|
+
html += '<div class="lede">Potential savings if you change your setup or habits. Excluded from the totals above.</div>';
|
|
4957
|
+
}
|
|
4958
|
+
if (cdTokensMo > 0) {
|
|
4959
|
+
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 the cache window and re-wrote ~' + fmtTok(cdTokensMo) + ' tokens' + esc(per) + ' of prefix' +
|
|
4961
|
+
(cdCostMo > 0 ? ', about <span style="color:var(--c-amber);">' + money(cdCostMo) + esc(per) + '</span> at API rates' : '') + '.' +
|
|
4962
|
+
'</div>';
|
|
4963
|
+
html += '<div class="plain-line">Not part of the savings number above.</div>';
|
|
4964
|
+
html += fold('How the cache drop figure is priced', '<p>Cache write rate minus the cache read it would have cost, at the models you ran. It is not part of the number above.</p>');
|
|
4965
|
+
}
|
|
4966
|
+
if (routingPotentialMo > 0) {
|
|
4967
|
+
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;">' +
|
|
4968
|
+
'Routing (an assumption, not a measurement): if about ' + routingFracPct + '% of your Opus work (grunt tasks) ran on ' + esc(routingTarget) + ': new input and output only' +
|
|
4969
|
+
(mo(mr.potential_unsplit_excluded_tokens) > 0 ? ' (~' + fmtTok(mo(mr.potential_unsplit_excluded_tokens)) + ' Opus tokens' + esc(per) + ' without a class split are left out)' : '') + ', about <span style="color:var(--c-amber);">' + money(routingPotentialMo) + esc(per) + '</span> at API rates.' +
|
|
4970
|
+
(routingTokensMo > 0 ? ' ~' + fmtTok(routingTokensMo) + ' tokens' + esc(per) + '.' : '') +
|
|
4971
|
+
'</div>';
|
|
4972
|
+
html += '<div class="plain-line">An assumption about your own work, not a measured saving, and not part of the number above.</div>';
|
|
4973
|
+
var classLabels = { fresh_input: 'Fresh input', cache_create_5m: 'Cache writes (5 min)', cache_create_1h: 'Cache writes (1 hour)',
|
|
4974
|
+
cache_read: 'Cache reads', output: 'Output' };
|
|
4975
|
+
var byClass = mr.potential_by_class || {};
|
|
4976
|
+
var classRows = Object.keys(byClass).filter(function(k) { return classLabels[k]; })
|
|
4977
|
+
.sort(function(a, b) { return (Number(byClass[b].usd) || 0) - (Number(byClass[a].usd) || 0); });
|
|
4978
|
+
if (classRows.length) {
|
|
4979
|
+
html += fold('How the routing figure is priced',
|
|
4980
|
+
'<p>Some Opus work is worth keeping on Opus.</p>' +
|
|
4981
|
+
'<p>Each kind of token is priced at the rate of the model you ran, and the lighter model at the newest Sonnet rates. ' +
|
|
4982
|
+
'The figure is the rate difference on about ' + routingFracPct + '% of your remaining Opus tokens.</p>' +
|
|
4983
|
+
classRows.map(function(k) {
|
|
4984
|
+
return '<p>' + esc(classLabels[k]) + ': ~' + fmtTok(mo(byClass[k].tokens)) + ' tokens' + esc(per) + ', about ' + money(mo(byClass[k].usd)) + ' at API rates.</p>';
|
|
4985
|
+
}).join(''));
|
|
4986
|
+
} else {
|
|
4987
|
+
html += fold('About this assumption', '<p>Some Opus work is worth keeping on Opus.</p>');
|
|
4988
|
+
}
|
|
4989
|
+
}
|
|
4586
4990
|
html += '<details class="fold"><summary>Ways to save more</summary><div class="fold__body">';
|
|
4991
|
+
html += '<p>' + billingCaption + '</p>';
|
|
4587
4992
|
parts.forEach(function(p, i){
|
|
4588
4993
|
html += '<div style="display:flex;gap:var(--s-3);align-items:flex-start;">' +
|
|
4589
4994
|
'<div style="flex-shrink:0;width:34px;height:34px;border-radius:50%;border:1.5px solid var(--c-amber);background:rgba(217,164,65,0.08);display:flex;align-items:center;justify-content:center;font-family:var(--font-mono);font-size:16px;color:var(--c-amber);margin-top:2px;">' + (i+1) + '</div>' +
|
|
4590
4995
|
'<div style="font-size:18px;color:var(--c-text-main);line-height:1.7;max-width:760px;">' + esc(p) + '</div></div>';
|
|
4591
4996
|
});
|
|
4592
4997
|
html += '</div>';
|
|
4593
|
-
html += '<div style="margin-top:var(--s-5);padding:var(--s-4);background:rgba(217,164,65,0.07);border:1px solid var(--c-amber);border-radius:10px;font-family:var(--font-mono);font-size:17px;line-height:1.6;color:var(--c-text-main);font-weight:500;">Run <span style="color:var(--c-amber);">/token-optimizer</span> and follow its suggestions to claim the rest →</div>';
|
|
4998
|
+
if (data.runtime !== 'cursor' && data.runtime !== 'antigravity') html += '<div style="margin-top:var(--s-5);padding:var(--s-4);background:rgba(217,164,65,0.07);border:1px solid var(--c-amber);border-radius:10px;font-family:var(--font-mono);font-size:17px;line-height:1.6;color:var(--c-text-main);font-weight:500;">Run <span style="color:var(--c-amber);">/token-optimizer</span> and follow its suggestions to claim the rest →</div>';
|
|
4594
4999
|
html += '</details></div>';
|
|
4595
5000
|
}
|
|
4596
5001
|
|
|
@@ -4625,7 +5030,8 @@ var DB = (function() {
|
|
|
4625
5030
|
'<div style="font-family:var(--font-mono);font-weight:300;font-size:48px;line-height:1;color:var(--c-accent-cyan);">' + avgQ + '<span style="font-size:18px;color:var(--c-text-dim);">/100</span></div>' +
|
|
4626
5031
|
'<div style="flex:1;min-width:220px;">' +
|
|
4627
5032
|
'<div style="height:8px;border-radius:5px;background:rgba(255,255,255,0.06);overflow:hidden;"><div style="height:100%;width:' + barPct + '%;background:linear-gradient(90deg,var(--c-accent-blue),var(--c-accent-cyan));"></div></div>' +
|
|
4628
|
-
'<div
|
|
5033
|
+
'<div class="plain-line">Across your last ' + sessionsCounted + ' sessions, Token Optimizer kept your context averaging ' + avgQ + '/100.</div>' +
|
|
5034
|
+
fold('What this means', '<p>Savings are only half the story. Tighter context means sharper answers and fewer compaction interruptions.</p><p>This is the average across sessions; the Health tab scores your single latest session.</p>') +
|
|
4629
5035
|
'</div>' +
|
|
4630
5036
|
'</div></div>';
|
|
4631
5037
|
}
|
|
@@ -4667,13 +5073,15 @@ var DB = (function() {
|
|
|
4667
5073
|
var ready = pr.promotion_ready;
|
|
4668
5074
|
ccHtml += '<div style="margin-top:var(--s-3);padding-top:var(--s-2);border-top:1px solid rgba(255,255,255,0.08);">' +
|
|
4669
5075
|
'<div style="font-weight:500;">First-read skeleton — safety check</div>' +
|
|
4670
|
-
'<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>' +
|
|
4671
5080
|
'Of ' + (Number(pr.shadow_reads) || 0) + ' large files where a skeleton would have saved tokens, ' +
|
|
4672
5081
|
(Number(pr.edits_after_read) || 0) + ' were edited soon after the read — an edit rate of ' +
|
|
4673
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>. ' +
|
|
4674
|
-
'Skeletons turn on automatically only once this stays under ' + (Number(pr.promotion_gate_pct) || 15) + '% (the model rarely needed the full file)
|
|
4675
|
-
|
|
4676
|
-
'</div></div>';
|
|
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>';
|
|
4677
5085
|
}
|
|
4678
5086
|
// Runtime tripwire: per-cohort LIVE edit-rate + any auto-demotions.
|
|
4679
5087
|
var tw = cc.cohort_tripwire || {};
|
|
@@ -4682,9 +5090,7 @@ var DB = (function() {
|
|
|
4682
5090
|
if (twCohorts.length || twDemoted.length) {
|
|
4683
5091
|
ccHtml += '<div style="margin-top:var(--s-3);padding-top:var(--s-2);border-top:1px solid rgba(255,255,255,0.08);">' +
|
|
4684
5092
|
'<div style="font-weight:500;">Active cohort tripwire — live quality guard</div>' +
|
|
4685
|
-
'<
|
|
4686
|
-
'Each promoted cohort’s live edit-after-skeleton rate. A cohort auto-demotes to measure-only if it crosses 15% (no flapping — re-promote is manual or by the next backfill).' +
|
|
4687
|
-
'</div>';
|
|
5093
|
+
fold('How the tripwire works', '<p>Each promoted cohort’s live edit-after-skeleton rate. A cohort auto-demotes to measure-only if it crosses 15% (no flapping — re-promote is manual or by the next backfill).</p>');
|
|
4688
5094
|
twCohorts.forEach(function(c) {
|
|
4689
5095
|
var dem = !!c.demoted;
|
|
4690
5096
|
// T9: interpolated cohorts (promoted on a thin sample via an adjacent
|
|
@@ -4736,10 +5142,10 @@ var DB = (function() {
|
|
|
4736
5142
|
'<div><div style="font-size:12px;color:var(--c-text-dim);">Affected sessions</div>' +
|
|
4737
5143
|
'<div style="font-family:var(--font-mono);font-size:20px;">' + (Number(ch.affected_sessions) || 0) + '<span style="font-size:13px;color:var(--c-text-dim);"> / ' + (Number(ch.scanned_sessions) || 0) + '</span></div></div>' +
|
|
4738
5144
|
(Number(ch.would_be_savings_1h_usd) > 0 ?
|
|
4739
|
-
'<div><div style="font-size:12px;color:var(--c-text-dim);" title="API/SDK sessions only: a 1-hour cache_control would avoid the repeat writes. Does not apply to Claude Code, which already holds a 1h cache.">Recoverable via 1h cache (API/SDK)</div>' +
|
|
5145
|
+
'<div><div style="font-size:12px;color:var(--c-text-dim);" title="' + ((!data.runtime || data.runtime === 'claude') ? 'API/SDK sessions only: a 1-hour cache_control would avoid the repeat writes. Does not apply to Claude Code, which already holds a 1h cache.' : 'Where the provider offers a 1-hour cache, using it would avoid these repeat writes.') + '">Recoverable via 1h cache (API/SDK)</div>' +
|
|
4740
5146
|
'<div style="font-family:var(--font-mono);font-size:20px;color:var(--c-text-dim);">$' + (Number(ch.would_be_savings_1h_usd) || 0).toFixed(2) + '</div></div>' : '') +
|
|
4741
5147
|
(Number(ch.avoidable_behavioral_usd) > 0 ?
|
|
4742
|
-
'<div><div style="font-size:12px;color:var(--c-text-dim);" title="Claude Code already holds a 1-hour cache. This is avoidable only behaviorally
|
|
5148
|
+
'<div><div style="font-size:12px;color:var(--c-text-dim);" title="' + ((!data.runtime || data.runtime === 'claude') ? 'Claude Code already holds a 1-hour cache. This is avoidable only behaviorally, by resuming within the hour or batching related work. No setting extends it.' : 'Avoidable by resuming before the cache expires or batching related work.') + '">Avoidable by resuming in-hour</div>' +
|
|
4743
5149
|
'<div style="font-family:var(--font-mono);font-size:20px;color:var(--c-text-dim);">$' + (Number(ch.avoidable_behavioral_usd) || 0).toFixed(2) + '</div></div>' : '') +
|
|
4744
5150
|
'</div>';
|
|
4745
5151
|
if (Number(ch.no_cache_economics_sessions) > 0) {
|
|
@@ -5030,11 +5436,19 @@ var DB = (function() {
|
|
|
5030
5436
|
{ key: 'stale_reads', label: 'Stale Reads', icon: '\uD83D\uDCC4', tip: 'Files read earlier that have since changed. The model may be working with outdated content.' },
|
|
5031
5437
|
{ key: 'bloated_results', label: 'Bloated Results', icon: '\uD83D\uDCE6', tip: 'Tool outputs sitting in context that were never referenced. Wasted space.' },
|
|
5032
5438
|
{ key: 'duplicates', label: 'Duplicates', icon: '\uD83D\uDD04', tip: 'Same system reminders or content injected multiple times. Pure waste.' },
|
|
5033
|
-
{ key: 'compaction_depth', label: 'Compactions', icon: '\uD83D\uDDDC', tip: 'Each compaction loses 60-70% of conversation. After 2: ~88% gone.' },
|
|
5034
5439
|
{ key: 'decision_density', label: 'Decision Density', icon: '\uD83C\uDFAF', tip: 'Ratio of actual decisions and work vs overhead and boilerplate.' },
|
|
5035
5440
|
{ key: 'agent_efficiency', label: 'Agent Efficiency', icon: '\u2699\uFE0F', tip: 'Whether dispatched agents produced useful output relative to their token cost.' }
|
|
5036
5441
|
];
|
|
5037
5442
|
html += '<div style="padding:0 var(--s-3) var(--s-3);">';
|
|
5443
|
+
// Compactions are metadata, with no health bar or fixed loss claim.
|
|
5444
|
+
var compactData = bd.compactions || bd.compaction_depth;
|
|
5445
|
+
var recoveryData = bd.compaction_recovery;
|
|
5446
|
+
if (compactData || recoveryData) {
|
|
5447
|
+
var compactCount = compactData ? (compactData.count != null ? compactData.count : compactData.compactions) : q.compactions;
|
|
5448
|
+
html += '<div style="display:flex;flex-wrap:wrap;gap:var(--s-2);margin-bottom:10px;font-size:15px;color:var(--c-text-dim);">' +
|
|
5449
|
+
'<span>Compactions: ' + esc(compactCount == null ? 'unknown' : compactCount + ' compactions') + '</span>' +
|
|
5450
|
+
'<span>Recovery: ' + (compactCount === 0 ? 'no compactions' : 'observing') + '</span></div>';
|
|
5451
|
+
}
|
|
5038
5452
|
signals.forEach(function(sig) {
|
|
5039
5453
|
var d = bd[sig.key];
|
|
5040
5454
|
if (!d) return;
|
|
@@ -5203,7 +5617,7 @@ var DB = (function() {
|
|
|
5203
5617
|
|
|
5204
5618
|
// Snapshot summary
|
|
5205
5619
|
var snap = c.snapshot || {};
|
|
5206
|
-
var instructionLabel = snap.instruction_label || (isCodex ? 'AGENTS.md' : 'CLAUDE.md');
|
|
5620
|
+
var instructionLabel = snap.instruction_label || (isCodex ? 'AGENTS.md' : isNoInstructionHost(data) ? 'agent instructions' : 'CLAUDE.md');
|
|
5207
5621
|
html += '<div class="dashboard-grid">' +
|
|
5208
5622
|
'<div class="card"><div class="card-header"><span>Startup Overhead</span></div>' +
|
|
5209
5623
|
'<div style="font-size:11px;color:var(--c-text-dim);padding:0 0 4px 0;">Tokens loaded before you type. Includes ' + esc(instructionLabel) + ', skills/plugin metadata, MCP tools, and system prompt.</div>' +
|
|
@@ -5646,8 +6060,10 @@ var DB = (function() {
|
|
|
5646
6060
|
'<p id="manage-mode-desc">' +
|
|
5647
6061
|
(isCodex
|
|
5648
6062
|
? 'Codex setup uses real local logs plus project hooks. Balanced hooks are on by default; noisy per-tool hooks stay opt-in so Desktop users are not spammed.'
|
|
6063
|
+
: m && m.read_only
|
|
6064
|
+
? 'Your ' + esc(data.runtime_label || 'runtime') + ' skills and MCP servers, read from its own files. Token Optimizer feature toggles are below.'
|
|
5649
6065
|
: window.__TOKEN_API_LIVE
|
|
5650
|
-
? '<span style="color:var(--c-accent-cyan);font-weight:600;">Live mode</span> — toggles apply instantly to settings. <strong>Restart ' + (isCodex ? 'Codex' : 'Claude') + '</strong> to activate changes.'
|
|
6066
|
+
? '<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.'
|
|
5651
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>')) +
|
|
5652
6068
|
'</p>' +
|
|
5653
6069
|
'</div>';
|
|
@@ -5656,6 +6072,7 @@ var DB = (function() {
|
|
|
5656
6072
|
html += '<div style="padding:12px var(--s-3);margin-bottom:var(--s-2);background:var(--c-bg);border-left:3px solid var(--c-accent-cyan);border-radius:4px;font-size:14px;color:var(--c-text-dim);">' +
|
|
5657
6073
|
(isCodex
|
|
5658
6074
|
? 'Showing default Codex feature state. Run a Codex dashboard refresh to reflect your actual config.'
|
|
6075
|
+
: isNoInstructionHost(data) ? 'Showing default feature state.'
|
|
5659
6076
|
: 'Showing default feature state. Run <code style="background:var(--c-bg);padding:2px 5px;border-radius:4px;">/token-optimizer</code> once to reflect your actual config and enable live toggles.') +
|
|
5660
6077
|
'</div>';
|
|
5661
6078
|
}
|
|
@@ -5835,8 +6252,56 @@ var DB = (function() {
|
|
|
5835
6252
|
html += '</div></div></div>';
|
|
5836
6253
|
}
|
|
5837
6254
|
|
|
6255
|
+
// --- READ-ONLY INVENTORY (Hermes) ---
|
|
6256
|
+
// Listed only: the toggles below manage Claude Code folders, so they must
|
|
6257
|
+
// never act on another runtime's skills or servers.
|
|
6258
|
+
if (!isCodex && m.read_only) {
|
|
6259
|
+
var roLabel = data.runtime_label || 'This runtime';
|
|
6260
|
+
var roRow = function(name, desc, meta) {
|
|
6261
|
+
return '<div class="hook-row" style="padding:8px var(--s-3);">' +
|
|
6262
|
+
'<div class="hook-info">' +
|
|
6263
|
+
'<div class="hook-label" style="font-size:14px;font-family:var(--font-mono);">' + esc(name) + '</div>' +
|
|
6264
|
+
(desc ? '<div class="hook-desc">' + esc(desc) + '</div>' : '') +
|
|
6265
|
+
'<div style="font-size:11px;color:var(--c-text-dim);margin-top:2px;">' + esc(meta) + '</div>' +
|
|
6266
|
+
'</div></div>';
|
|
6267
|
+
};
|
|
6268
|
+
var roList = function(title, items, label, empty, rowFn) {
|
|
6269
|
+
var out = '<div class="card wide"><div class="card-header"><span>' + esc(title) + ' (' + items.length + ')</span>' +
|
|
6270
|
+
(label ? '<span class="label">' + esc(label) + '</span>' : '') + '</div>';
|
|
6271
|
+
if (items.length === 0) return out + '<div class="empty-state" style="font-size:13px;">' + esc(empty) + '</div></div>';
|
|
6272
|
+
return out + '<div style="max-height:500px;overflow-y:auto;">' + items.map(rowFn).join('') + '</div></div>';
|
|
6273
|
+
};
|
|
6274
|
+
var roSkills = (m.skills && m.skills.active) || [];
|
|
6275
|
+
var roSkillTokens = roSkills.reduce(function(s, sk) { return s + (sk.tokens || 0); }, 0);
|
|
6276
|
+
var skillRow = function(sk) {
|
|
6277
|
+
return roRow(sk.name, sk.description || '', (sk.category ? sk.category + ' · ' : '') + (sk.tokens || 0) + ' tokens in the skill list');
|
|
6278
|
+
};
|
|
6279
|
+
html += roList('Skills', roSkills, fn(roSkillTokens) + ' tokens/session', 'No skills found in your ' + roLabel + ' skills folder.', skillRow);
|
|
6280
|
+
var roArchived = ((m.skills && m.skills.archived) || []).concat((m.skills && m.skills.disabled) || []);
|
|
6281
|
+
if (roArchived.length) html += roList('Archived or disabled skills', roArchived, 'not in the skill list', '', function(sk) {
|
|
6282
|
+
return roRow(sk.name, sk.description || '', sk.path || '');
|
|
6283
|
+
});
|
|
6284
|
+
var roMcp = ((m.mcp_servers && m.mcp_servers.active) || []).concat((m.mcp_servers && m.mcp_servers.disabled) || []);
|
|
6285
|
+
html += roList('MCP servers', roMcp, '', 'No mcp_servers in your ' + roLabel + ' config.yaml.', function(srv) {
|
|
6286
|
+
return roRow(srv.name, '', (srv.enabled ? '' : 'disabled · ') + srv.transport + (srv.command ? ' · ' + srv.command : ''));
|
|
6287
|
+
});
|
|
6288
|
+
html += '<p style="font-size:13px;color:var(--c-text-dim);padding:0 var(--s-3);">Read from ' + esc(roLabel) +
|
|
6289
|
+
'\'s own skills folder and config.yaml. Change them in ' + esc(roLabel) + '; this list updates on the next refresh.</p>';
|
|
6290
|
+
}
|
|
6291
|
+
|
|
6292
|
+
// --- NO SKILL/MCP MANAGEMENT (Cursor, Antigravity) ---
|
|
6293
|
+
// The skill and MCP controls below act on a Claude Code setup, so they are
|
|
6294
|
+
// not shown for runtimes that have no such folder.
|
|
6295
|
+
if (isNoInstructionHost(data)) {
|
|
6296
|
+
html += '<div class="card wide"><div class="card-header"><span>Skills and MCP servers</span></div>' +
|
|
6297
|
+
'<div style="padding:var(--s-3);color:var(--c-text-dim);font-size:14px;line-height:1.6;">' +
|
|
6298
|
+
'Skill and MCP management is not available under ' + esc(data.runtime_label || 'this runtime') +
|
|
6299
|
+
'. It applies to a Claude Code setup, and Token Optimizer does not change ' + esc(data.runtime_label || 'this runtime') + ' skills or servers.' +
|
|
6300
|
+
'</div></div>';
|
|
6301
|
+
}
|
|
6302
|
+
|
|
5838
6303
|
// --- SKILLS SECTION ---
|
|
5839
|
-
if (!isCodex) {
|
|
6304
|
+
if (!isCodex && !m.read_only && !isNoInstructionHost(data)) {
|
|
5840
6305
|
var activeSkills = (m.skills && m.skills.active) || [];
|
|
5841
6306
|
var archivedSkills = (m.skills && m.skills.archived) || [];
|
|
5842
6307
|
var totalTokens = activeSkills.reduce(function(s, sk) { return s + (sk.tokens || 100); }, 0);
|
|
@@ -6208,7 +6673,7 @@ var DB = (function() {
|
|
|
6208
6673
|
|
|
6209
6674
|
if (count === 0) {
|
|
6210
6675
|
if (!data.plan && !data.auto_plan) {
|
|
6211
|
-
listEl.innerHTML = '<div class="empty-state">Run <span class="update-cmd">/token-optimizer</span> to generate optimization items you can toggle here.</div>';
|
|
6676
|
+
listEl.innerHTML = (isNoInstructionHost(data) ? '<div class="empty-state">No optimization items to toggle for ' + esc(data.runtime_label || 'this runtime') + ' yet.</div>' : '<div class="empty-state">Run <span class="update-cmd">/token-optimizer</span> to generate optimization items you can toggle here.</div>');
|
|
6212
6677
|
} else {
|
|
6213
6678
|
listEl.innerHTML = '<div class="empty-state">Toggle items in Quick Wins, Medium, or Deep to build your optimization prompt.</div>';
|
|
6214
6679
|
}
|