fix(panel): add semantic speed/cache color tiers and clean up overview metric subtexts

This commit is contained in:
fish
2026-11-15 18:53:43 +09:00
parent 2db06050be
commit 6517ee434e
14 changed files with 531 additions and 149 deletions
+148 -62
View File
@@ -382,11 +382,10 @@ const I18N_MESSAGES_ZH_CN = Object.freeze({
'ovMetric.context_usage': '上下文占用',
'ovMetric.quota_tightest': '紧俏额度',
'ovMetric.subAvgTtft': '均值 {val}',
'ovMetric.subAvgCache': '均值 {val}',
'ovMetric.subValidSamples': '有效 {samples}',
'ovMetric.subCacheAndTotal': '缓存 {cache}% · 累计 {cost}',
'ovMetric.subStepsAndCache': '{steps} 步 · 缓存 {cache}%',
'ovMetric.subStepCost': '单步 {cost}',
'ovMetric.subPromptHit': '当步 {latest}% · 均值 {avg}%',
'ovMetric.subTotalCost': '累计 {cost}',
'ovMetric.subStepCost': '本次 {cost}',
'ovMetric.subInOutTokens': '入 {inTok} · 出 {outTok}',
'ovMetric.subCtxRatio': '{used} / {limit}',
'ovMetric.subQuotaPool': '{label}',
@@ -860,11 +859,10 @@ const I18N_MESSAGES_EN_US = Object.freeze({
'ovMetric.context_usage': 'Context Usage',
'ovMetric.quota_tightest': 'Tightest Quota',
'ovMetric.subAvgTtft': 'Avg {val}',
'ovMetric.subAvgCache': 'Avg {val}',
'ovMetric.subValidSamples': 'Valid {samples}',
'ovMetric.subCacheAndTotal': 'Cache {cache}% · Total {cost}',
'ovMetric.subStepsAndCache': '{steps} steps · Cache {cache}%',
'ovMetric.subStepCost': 'Latest {cost}',
'ovMetric.subPromptHit': 'Latest {latest}% · Avg {avg}%',
'ovMetric.subTotalCost': 'Total {cost}',
'ovMetric.subStepCost': 'Step {cost}',
'ovMetric.subInOutTokens': 'In {inTok} · Out {outTok}',
'ovMetric.subCtxRatio': '{used} / {limit}',
'ovMetric.subQuotaPool': '{label}',
@@ -1664,6 +1662,53 @@ function formatMetric(value, unit = '') {
return Number.isFinite(value) ? `${value.toFixed(1)}${unit}` : '—';
}
function formatCachePct(value) {
if (value == null || !Number.isFinite(Number(value))) return '—';
const num = Math.max(0, Math.min(100, +Number(value).toFixed(1)));
return `${num}%`;
}
function getSpeedToneClass(tokPerSec) {
if (tokPerSec == null || !Number.isFinite(Number(tokPerSec)) || Number(tokPerSec) <= 0) {
return 'tone-muted';
}
const v = Number(tokPerSec);
if (v >= 60) return 'tone-good';
if (v >= 35) return 'tone-info';
if (v >= 20) return 'tone-warn';
return 'tone-danger';
}
function getCacheToneClass(cacheHitPct, promptTokens = null) {
if (cacheHitPct == null || !Number.isFinite(Number(cacheHitPct))) {
return 'tone-muted';
}
const v = Number(cacheHitPct);
if (promptTokens != null && Number(promptTokens) <= 0 && v <= 0) {
return 'tone-muted';
}
if (v >= 85) return 'tone-good';
if (v >= 65) return 'tone-info';
if (v >= 30) return 'tone-warn';
return 'tone-danger';
}
function getStepCostToneClass(costUsd) {
if (costUsd == null || !Number.isFinite(Number(costUsd))) return '';
const v = Number(costUsd);
if (v >= 0.3) return 'tone-danger';
if (v >= 0.15) return 'tone-warn';
return '';
}
function getTtftToneClass(ttftSec) {
if (ttftSec == null || !Number.isFinite(Number(ttftSec)) || Number(ttftSec) < 0) return '';
const v = Number(ttftSec);
if (v >= 30) return 'tone-danger';
if (v >= 18) return 'tone-warn';
return '';
}
function formatTokens(num) {
const n = Number(num || 0);
if (n >= 1_000_000_000) return `${(n / 1_000_000_000).toFixed(2)}B`;
@@ -7848,6 +7893,7 @@ function resolveQuotaCapsuleSummary(quotas) {
if (!quotas) return null;
const activePool = quotas.activePool;
const weekly = quotas.weekly;
const pools = Array.isArray(quotas.pools) ? quotas.pools : [];
const candidates = [];
const defaultPoolName = isEnglishLocale() ? 'Active Pool' : '当前池';
const wkTag = isEnglishLocale() ? 'Wk' : '周';
@@ -7873,13 +7919,32 @@ function resolveQuotaCapsuleSummary(quotas) {
windowTag: wkTag,
});
}
if (!candidates.length && pools.length > 0) {
for (const p of pools) {
const pLabel = p?.poolLabel || p?.family || defaultPoolName;
if (p && Number.isFinite(Number(p.remainingPct))) {
candidates.push({ pct: Number(p.remainingPct), label: pLabel, windowTag: '5h' });
}
if (p && Number.isFinite(Number(p.weeklyRemainingPct))) {
candidates.push({ pct: Number(p.weeklyRemainingPct), label: pLabel, windowTag: wkTag });
}
}
}
if (!candidates.length) return null;
candidates.sort((a, b) => a.pct - b.pct);
const tightest = candidates[0];
const runnerUp = candidates.length > 1 ? candidates[1] : null;
const rounded = Math.max(0, Math.min(100, Math.round(tightest.pct)));
const runnerPct = runnerUp ? Math.max(0, Math.min(100, Math.round(runnerUp.pct))) : null;
const subLabelText = runnerUp
? runnerUp.label === tightest.label
? `${tightest.label} ${tightest.windowTag} · ${runnerUp.windowTag} ${runnerPct}%`
: `${tightest.label} ${tightest.windowTag} · ${runnerUp.label} ${runnerUp.windowTag} ${runnerPct}%`
: `${tightest.label} · ${tightest.windowTag}`;
return {
roundedPct: rounded,
shortText: t('capsule.quotaLeft', { pct: rounded }),
subLabelText,
detailText: candidates
.map((c) => {
const cPct = Math.max(0, Math.min(100, Math.round(c.pct)));
@@ -8138,6 +8203,10 @@ function resolveCapsuleMetricPresentation(metricKey, slotCtx, ringCircumference)
if (metricKey === 'cache_hit') {
const cachePct = slotCtx.hasTelemetry ? slotCtx.cacheHitPct : null;
const valid = cachePct != null && Number.isFinite(Number(cachePct));
const numVal = valid ? Number(cachePct) : 0;
const hasPrompt = slotCtx.latestPromptTokens == null || Number(slotCtx.latestPromptTokens) > 0;
const isDanger = valid && hasPrompt && numVal < 30;
const isWarn = valid && hasPrompt && !isDanger && numVal < 65;
return {
hidden: false,
metric: 'cache_hit',
@@ -8145,10 +8214,10 @@ function resolveCapsuleMetricPresentation(metricKey, slotCtx, ringCircumference)
textClass: 'wm-slot-text wm-cache-text',
showRing: false,
dashOffset: ringCircumference,
text: valid ? `${Math.round(Number(cachePct))}%` : '--%',
text: valid ? `${Math.round(numVal)}%` : '--%',
running: false,
warn: false,
danger: false,
warn: isWarn,
danger: isDanger,
};
}
@@ -8223,6 +8292,8 @@ function resolveOverviewMetricCell(metricKey, cellCtx = {}) {
const badgeStr = translateRawAgentBadge(active.activeAgentBadge);
const modelAndAgent =
hasSubagents && badgeStr ? `[${badgeStr}] ${activeModelDisplay}` : activeModelDisplay;
const hasSpeed = Number.isFinite(active.latestTokPerSec) && Number(active.latestTokPerSec) > 0;
const speedTone = hasAnySteps && hasSpeed ? getSpeedToneClass(active.latestTokPerSec) : '';
return {
key: 'tps',
label: t('ovMetric.tps'),
@@ -8230,13 +8301,18 @@ function resolveOverviewMetricCell(metricKey, cellCtx = {}) {
iconSize: 10,
isPulsing: Boolean(active.isRunning),
valueText: formatMetric(active.latestTokPerSec, ' tok/s'),
valueClass: 'cell-value accent-speed',
subText: reason ? `${modelAndAgent} · ${reason}` : modelAndAgent,
valueClass: speedTone ? `cell-value ${speedTone}` : 'cell-value',
subText: reason
? !hasSpeed
? `${reason} · ${modelAndAgent}`
: `${modelAndAgent} · ${reason}`
: modelAndAgent,
subClass: 'cell-sub',
};
}
if (metricKey === 'ttft') {
const ttftTone = hasAnySteps ? getTtftToneClass(active.latestTtftSec) : '';
return {
key: 'ttft',
label: t('ovMetric.ttft'),
@@ -8244,7 +8320,7 @@ function resolveOverviewMetricCell(metricKey, cellCtx = {}) {
iconSize: 11,
isPulsing: false,
valueText: formatMetric(active.latestTtftSec, 's'),
valueClass: 'cell-value',
valueClass: ttftTone ? `cell-value ${ttftTone}` : 'cell-value',
subText: t('ovMetric.subAvgTtft', {
val: formatMetric(active.ttftSummary?.avgSec, 's'),
}),
@@ -8268,64 +8344,65 @@ function resolveOverviewMetricCell(metricKey, cellCtx = {}) {
};
}
if (metricKey === 'step_cost') {
if (metricKey === 'step_cost' || metricKey === 'session_cost') {
const stepCost = active.latestStepCostUsd;
const sessCost = Number(active.sessionCostUsd || 0);
const stepCnt = Number(active.stepCount || 0);
const isAllUnpriced =
stepCnt > 0 && Number(active.sessionUnpricedCalls || 0) >= stepCnt && !(sessCost > 0);
const stepCostText =
!hasAnySteps && stepCost == null ? '—' : formatUsd(stepCost, { precise: true });
const totalCostText =
!hasAnySteps && active.sessionCostUsd == null
? '—'
: formatUsd(isAllUnpriced ? null : sessCost, {
precise: sessCost > 0 && sessCost < 0.1,
});
if (metricKey === 'step_cost') {
const costTone = hasAnySteps ? getStepCostToneClass(stepCost) : '';
return {
key: 'step_cost',
label: t('ovMetric.step_cost'),
icon: 'bolt',
iconSize: 11,
isPulsing: false,
valueText: !hasAnySteps && stepCost == null ? '—' : formatUsd(stepCost, { precise: true }),
valueClass: 'cell-value',
subText: t('ovMetric.subCacheAndTotal', {
cache: active.latestCacheHitPct ?? 0,
cost: formatUsd(active.sessionCostUsd || 0),
}),
subClass: 'cell-sub accent-ok',
valueText: stepCostText,
valueClass: costTone ? `cell-value ${costTone}` : 'cell-value',
subText: t('ovMetric.subTotalCost', { cost: totalCostText }),
subClass: 'cell-sub',
};
}
if (metricKey === 'session_cost') {
const sessCost = Number(active.sessionCostUsd || 0);
const stepCnt = Number(active.stepCount || 0);
const isAllUnpriced =
stepCnt > 0 && Number(active.sessionUnpricedCalls || 0) >= stepCnt && !(sessCost > 0);
return {
key: 'session_cost',
label: t('ovMetric.session_cost'),
icon: 'bolt',
iconSize: 11,
isPulsing: false,
valueText:
!hasAnySteps && active.sessionCostUsd == null
? '—'
: formatUsd(isAllUnpriced ? null : sessCost, {
precise: sessCost > 0 && sessCost < 0.1,
}),
valueText: totalCostText,
valueClass: 'cell-value',
subText: t('ovMetric.subStepsAndCache', {
steps: stepCnt,
cache: Math.round(Number(active.sessionCacheHitPct ?? active.latestCacheHitPct ?? 0)),
}),
subClass: 'cell-sub accent-ok',
subText: t('ovMetric.subStepCost', { cost: stepCostText }),
subClass: 'cell-sub',
};
}
if (metricKey === 'cache_hit') {
const avgCache = Number(active.sessionCacheHitPct ?? active.latestCacheHitPct ?? 0);
const latestCache = Number(active.latestCacheHitPct ?? 0);
const latestCache = active.latestCacheHitPct;
const avgCache = active.sessionCacheHitPct ?? active.latestCacheHitPct;
const hasLatest = hasAnySteps && latestCache != null && Number.isFinite(Number(latestCache));
const hasAvg = hasAnySteps && avgCache != null && Number.isFinite(Number(avgCache));
const cacheTone = hasLatest ? getCacheToneClass(latestCache, active.latestPromptTokens) : '';
return {
key: 'cache_hit',
label: t('ovMetric.cache_hit'),
icon: 'layers',
iconSize: 11,
isPulsing: false,
valueText: !hasAnySteps ? '—' : `${Math.round(avgCache)}%`,
valueClass: 'cell-value accent-ok',
subText: t('ovMetric.subPromptHit', {
latest: Math.round(latestCache),
avg: Math.round(avgCache),
valueText: hasLatest ? formatCachePct(latestCache) : '—',
valueClass: cacheTone ? `cell-value ${cacheTone}` : 'cell-value',
subText: t('ovMetric.subAvgCache', {
val: hasAvg ? formatCachePct(avgCache) : '—',
}),
subClass: 'cell-sub',
};
@@ -8395,7 +8472,7 @@ function resolveOverviewMetricCell(metricKey, cellCtx = {}) {
valueText: quotaSum ? quotaSum.shortText : '—',
valueClass: quotaToneCls,
subText: quotaSum
? t('ovMetric.subQuotaPool', { label: quotaSum.detailText })
? t('ovMetric.subQuotaPool', { label: quotaSum.subLabelText })
: t('ovMetric.subQuotaPending'),
subClass: 'cell-sub',
};
@@ -10074,7 +10151,7 @@ const STEP_COLUMN_REGISTRY = Object.freeze({
sigPart: (st) => `${st.tokPerSec}:${st.selectedSpeedReason || ''}`,
createCell: () => {
const speedMain = h('strong', {
className: 'cell-value accent-speed',
className: 'cell-value tone-muted',
style: 'font-size: var(--fs-base-sm);',
});
const speedReason = h('div', {
@@ -10091,6 +10168,7 @@ const STEP_COLUMN_REGISTRY = Object.freeze({
},
updateCell: (refs, st) => {
patchText(refs.speedMain, formatMetric(st.tokPerSec, ' tok/s'));
patchAttr(refs.speedMain, 'class', `cell-value ${getSpeedToneClass(st.tokPerSec)}`);
const reason = speedReasonText(st.selectedSpeedReason);
patchText(refs.speedReason, reason);
patchAttr(refs.speedReason, 'hidden', !reason);
@@ -10109,6 +10187,8 @@ const STEP_COLUMN_REGISTRY = Object.freeze({
},
updateCell: (refs, st) => {
patchText(refs.valEl, formatMetric(st.ttftSec, 's'));
const tone = getTtftToneClass(st.ttftSec);
patchAttr(refs.valEl, 'class', tone || null);
},
},
@@ -10211,21 +10291,24 @@ const STEP_COLUMN_REGISTRY = Object.freeze({
key: 'cache',
thLabel: () => t('stepCol.cache.th'),
optLabel: () => t('stepCol.cache.opt'),
sigPart: (st) => `${st.cacheHitPct ?? 0}`,
sigPart: (st) =>
`${st.cacheHitPct ?? 0}:${(st.inputTokens || 0) + (st.cacheReadTokens || 0) > 0 ? 1 : 0}`,
createCell: () => {
const valEl = h('span');
const td = h(
'td',
{
className: 'cell-value accent-ok',
const valEl = h('span', {
className: 'cell-value tone-muted',
style: 'font-size: var(--fs-base-sm);',
},
[valEl]
);
});
const td = h('td', {}, [valEl]);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st) => {
patchText(refs.valEl, `${Number(st.cacheHitPct ?? 0)}%`);
const promptTokens = Number(st.inputTokens || 0) + Number(st.cacheReadTokens || 0);
patchText(refs.valEl, formatCachePct(st.cacheHitPct ?? 0));
patchAttr(
refs.valEl,
'class',
`cell-value ${getCacheToneClass(st.cacheHitPct ?? 0, promptTokens)}`
);
},
},
@@ -10235,14 +10318,15 @@ const STEP_COLUMN_REGISTRY = Object.freeze({
optLabel: () => t('stepCol.cost.opt'),
sigPart: (st) => `${st.costUsd}`,
createCell: () => {
const valEl = h('span');
const td = h('td', { style: 'font-weight: 600;' }, [valEl]);
const valEl = h('span', { style: 'font-weight: 600;' });
const td = h('td', {}, [valEl]);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st) => {
const costVal = st.costUsd;
patchText(refs.valEl, formatUsd(costVal, { precise: true }));
patchClasses(refs.td, { 'accent-speed': costVal >= 0.15 });
const tone = getStepCostToneClass(costVal);
patchAttr(refs.valEl, 'class', tone || null);
},
},
});
@@ -18225,8 +18309,9 @@ function mountWindowOverlay() {
null;
const cacheHitPct =
Number(capActive.stepCount || 0) > 0
? capActive.sessionCacheHitPct ?? capActive.latestCacheHitPct ?? null
: capActive.latestCacheHitPct ?? null;
? capActive.latestCacheHitPct ?? capActive.sessionCacheHitPct ?? null
: null;
const latestPromptTokens = capActive.latestPromptTokens ?? null;
const capInTok = Math.max(0, Number(capActive.inputTokens || 0));
const capCacheTok = Math.max(0, Number(capActive.cacheReadTokens || 0));
const capOutTok = Math.max(0, Number(capActive.outputTokens || 0));
@@ -18249,6 +18334,7 @@ function mountWindowOverlay() {
stepCost: capsuleStepCost,
sessionCost,
cacheHitPct,
latestPromptTokens,
sessionTokens,
quotas: telemetry.quotas,
});
@@ -103,6 +103,7 @@ function enrichActiveConversationSteps(
let sessionUnpricedCalls = 0;
let sessionInputTokens = 0;
let sessionCacheReadTokens = 0;
let sessionOutputTokens = 0;
const knownUpstreamByModelKey = sharedUpstreamMap || buildKnownUpstreamModelMap();
for (const s of activeSteps) {
@@ -120,6 +121,7 @@ function enrichActiveConversationSteps(
if (costUsd === null) sessionUnpricedCalls++;
sessionInputTokens += st.inputTokens;
sessionCacheReadTokens += st.cacheReadTokens;
sessionOutputTokens += resolveStepOutputTokens(st);
const tokPerSec = metric.value;
const totalPrompt = st.inputTokens + st.cacheReadTokens;
@@ -208,6 +210,7 @@ function enrichActiveConversationSteps(
sessionUnpricedCalls,
sessionInputTokens,
sessionCacheReadTokens,
sessionOutputTokens,
};
}
@@ -524,6 +527,17 @@ function buildAgentUnitTelemetry({
latestStepCostUsd: enrichedRes.latestEnriched?.costUsd ?? null,
sessionCostUsd: roundSessionCost(enrichedRes.sessionCostUsd),
sessionUnpricedCalls: enrichedRes.sessionUnpricedCalls,
inputTokens: enrichedRes.sessionInputTokens,
cacheReadTokens: enrichedRes.sessionCacheReadTokens,
outputTokens: enrichedRes.sessionOutputTokens,
totalTokens:
enrichedRes.sessionInputTokens +
enrichedRes.sessionCacheReadTokens +
enrichedRes.sessionOutputTokens,
latestPromptTokens: enrichedRes.latestEnriched
? Number(enrichedRes.latestEnriched.inputTokens || 0) +
Number(enrichedRes.latestEnriched.cacheReadTokens || 0)
: 0,
latestCacheHitPct: ctxRes.latestCacheHitPct,
sessionCacheHitPct: ctxRes.sessionCacheHitPct,
activeModelShort: enrichedRes.latestEnriched?.modelShort || '模型未知',
@@ -618,6 +632,7 @@ export async function buildTelemetryPayloadInternal(
sessionUnpricedCalls,
sessionInputTokens,
sessionCacheReadTokens,
sessionOutputTokens,
} = mainUnit.enrichedRes;
const { latestCacheHitPct, sessionCacheHitPct, context } = mainUnit.ctxRes;
const mainAgentTelemetry = mainUnit.telemetryUnit;
@@ -631,6 +646,7 @@ export async function buildTelemetryPayloadInternal(
let totalRawSessionCostUsd = sessionCostUsd;
let totalFamilyInputTokens = sessionInputTokens;
let totalFamilyCacheReadTokens = sessionCacheReadTokens;
let totalFamilyOutputTokens = sessionOutputTokens;
for (let idx = 0; idx < subagentSummaries.length; idx++) {
const subSum = subagentSummaries[idx];
@@ -672,6 +688,7 @@ export async function buildTelemetryPayloadInternal(
totalRawSessionCostUsd += subUnit.enrichedRes.sessionCostUsd;
totalFamilyInputTokens += subUnit.enrichedRes.sessionInputTokens;
totalFamilyCacheReadTokens += subUnit.enrichedRes.sessionCacheReadTokens;
totalFamilyOutputTokens += subUnit.enrichedRes.sessionOutputTokens;
subAgentTelemetries.push(subUnit.telemetryUnit);
}
@@ -818,6 +835,11 @@ export async function buildTelemetryPayloadInternal(
latestStepCostUsd: latestMetricAgent.latestStepCostUsd,
sessionCostUsd: totalCostUsd,
sessionUnpricedCalls: totalUnpricedCalls,
inputTokens: totalFamilyInputTokens,
cacheReadTokens: totalFamilyCacheReadTokens,
outputTokens: totalFamilyOutputTokens,
totalTokens: totalFamilyInputTokens + totalFamilyCacheReadTokens + totalFamilyOutputTokens,
latestPromptTokens: latestMetricAgent.latestPromptTokens ?? 0,
latestCacheHitPct: latestMetricAgent.latestCacheHitPct,
sessionCacheHitPct: combinedSessionCacheHitPct,
activeModelShort: latestMetricAgent.activeModelShort,
@@ -1327,6 +1349,13 @@ export async function buildTelemetryPayloadInternal(
latestStepCostUsd: latestEnriched?.costUsd ?? null,
sessionCostUsd: roundSessionCost(sessionCostUsd),
sessionUnpricedCalls,
inputTokens: sessionInputTokens,
cacheReadTokens: sessionCacheReadTokens,
outputTokens: sessionOutputTokens,
totalTokens: sessionInputTokens + sessionCacheReadTokens + sessionOutputTokens,
latestPromptTokens: latestEnriched
? Number(latestEnriched.inputTokens || 0) + Number(latestEnriched.cacheReadTokens || 0)
: 0,
latestCacheHitPct,
sessionCacheHitPct,
activeModelShort: latestEnriched?.modelShort || '模型未知',
+2 -2
View File
@@ -4,11 +4,11 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>用量监控</title>
<link rel="stylesheet" href="/styles.css?v=1794732950908">
<link rel="stylesheet" href="/styles.css?v=1794735908512">
<script src="/preload.js"></script>
</head>
<body>
<div id="app-root"></div>
<script src="/app.js?v=1794732950908"></script>
<script src="/app.js?v=1794735908512"></script>
</body>
</html>
@@ -2784,8 +2784,9 @@ export function mountWindowOverlay() {
null;
const cacheHitPct =
Number(capActive.stepCount || 0) > 0
? capActive.sessionCacheHitPct ?? capActive.latestCacheHitPct ?? null
: capActive.latestCacheHitPct ?? null;
? capActive.latestCacheHitPct ?? capActive.sessionCacheHitPct ?? null
: null;
const latestPromptTokens = capActive.latestPromptTokens ?? null;
const capInTok = Math.max(0, Number(capActive.inputTokens || 0));
const capCacheTok = Math.max(0, Number(capActive.cacheReadTokens || 0));
const capOutTok = Math.max(0, Number(capActive.outputTokens || 0));
@@ -2808,6 +2809,7 @@ export function mountWindowOverlay() {
stepCost: capsuleStepCost,
sessionCost,
cacheHitPct,
latestPromptTokens,
sessionTokens,
quotas: telemetry.quotas,
});
+47
View File
@@ -14,6 +14,53 @@ export function formatMetric(value, unit = '') {
return Number.isFinite(value) ? `${value.toFixed(1)}${unit}` : '—';
}
export function formatCachePct(value) {
if (value == null || !Number.isFinite(Number(value))) return '—';
const num = Math.max(0, Math.min(100, +Number(value).toFixed(1)));
return `${num}%`;
}
export function getSpeedToneClass(tokPerSec) {
if (tokPerSec == null || !Number.isFinite(Number(tokPerSec)) || Number(tokPerSec) <= 0) {
return 'tone-muted';
}
const v = Number(tokPerSec);
if (v >= 60) return 'tone-good';
if (v >= 35) return 'tone-info';
if (v >= 20) return 'tone-warn';
return 'tone-danger';
}
export function getCacheToneClass(cacheHitPct, promptTokens = null) {
if (cacheHitPct == null || !Number.isFinite(Number(cacheHitPct))) {
return 'tone-muted';
}
const v = Number(cacheHitPct);
if (promptTokens != null && Number(promptTokens) <= 0 && v <= 0) {
return 'tone-muted';
}
if (v >= 85) return 'tone-good';
if (v >= 65) return 'tone-info';
if (v >= 30) return 'tone-warn';
return 'tone-danger';
}
export function getStepCostToneClass(costUsd) {
if (costUsd == null || !Number.isFinite(Number(costUsd))) return '';
const v = Number(costUsd);
if (v >= 0.3) return 'tone-danger';
if (v >= 0.15) return 'tone-warn';
return '';
}
export function getTtftToneClass(ttftSec) {
if (ttftSec == null || !Number.isFinite(Number(ttftSec)) || Number(ttftSec) < 0) return '';
const v = Number(ttftSec);
if (v >= 30) return 'tone-danger';
if (v >= 18) return 'tone-warn';
return '';
}
export function formatTokens(num) {
const n = Number(num || 0);
if (n >= 1_000_000_000) return `${(n / 1_000_000_000).toFixed(2)}B`;
+3 -4
View File
@@ -118,11 +118,10 @@ export const I18N_MESSAGES_EN_US = Object.freeze({
'ovMetric.context_usage': 'Context Usage',
'ovMetric.quota_tightest': 'Tightest Quota',
'ovMetric.subAvgTtft': 'Avg {val}',
'ovMetric.subAvgCache': 'Avg {val}',
'ovMetric.subValidSamples': 'Valid {samples}',
'ovMetric.subCacheAndTotal': 'Cache {cache}% · Total {cost}',
'ovMetric.subStepsAndCache': '{steps} steps · Cache {cache}%',
'ovMetric.subStepCost': 'Latest {cost}',
'ovMetric.subPromptHit': 'Latest {latest}% · Avg {avg}%',
'ovMetric.subTotalCost': 'Total {cost}',
'ovMetric.subStepCost': 'Step {cost}',
'ovMetric.subInOutTokens': 'In {inTok} · Out {outTok}',
'ovMetric.subCtxRatio': '{used} / {limit}',
'ovMetric.subQuotaPool': '{label}',
+3 -4
View File
@@ -118,11 +118,10 @@ export const I18N_MESSAGES_ZH_CN = Object.freeze({
'ovMetric.context_usage': '上下文占用',
'ovMetric.quota_tightest': '紧俏额度',
'ovMetric.subAvgTtft': '均值 {val}',
'ovMetric.subAvgCache': '均值 {val}',
'ovMetric.subValidSamples': '有效 {samples}',
'ovMetric.subCacheAndTotal': '缓存 {cache}% · 累计 {cost}',
'ovMetric.subStepsAndCache': '{steps} 步 · 缓存 {cache}%',
'ovMetric.subStepCost': '单步 {cost}',
'ovMetric.subPromptHit': '当步 {latest}% · 均值 {avg}%',
'ovMetric.subTotalCost': '累计 {cost}',
'ovMetric.subStepCost': '本次 {cost}',
'ovMetric.subInOutTokens': '入 {inTok} · 出 {outTok}',
'ovMetric.subCtxRatio': '{used} / {limit}',
'ovMetric.subQuotaPool': '{label}',
+75 -38
View File
@@ -6,9 +6,14 @@
*/
import {
formatCachePct,
formatMetric,
formatTokens,
formatUsd,
getCacheToneClass,
getSpeedToneClass,
getStepCostToneClass,
getTtftToneClass,
resolveModelDisplayInfo,
sampleSummary,
speedReasonText,
@@ -63,6 +68,7 @@ export function resolveQuotaCapsuleSummary(quotas) {
if (!quotas) return null;
const activePool = quotas.activePool;
const weekly = quotas.weekly;
const pools = Array.isArray(quotas.pools) ? quotas.pools : [];
const candidates = [];
const defaultPoolName = isEnglishLocale() ? 'Active Pool' : '当前池';
const wkTag = isEnglishLocale() ? 'Wk' : '周';
@@ -88,13 +94,32 @@ export function resolveQuotaCapsuleSummary(quotas) {
windowTag: wkTag,
});
}
if (!candidates.length && pools.length > 0) {
for (const p of pools) {
const pLabel = p?.poolLabel || p?.family || defaultPoolName;
if (p && Number.isFinite(Number(p.remainingPct))) {
candidates.push({ pct: Number(p.remainingPct), label: pLabel, windowTag: '5h' });
}
if (p && Number.isFinite(Number(p.weeklyRemainingPct))) {
candidates.push({ pct: Number(p.weeklyRemainingPct), label: pLabel, windowTag: wkTag });
}
}
}
if (!candidates.length) return null;
candidates.sort((a, b) => a.pct - b.pct);
const tightest = candidates[0];
const runnerUp = candidates.length > 1 ? candidates[1] : null;
const rounded = Math.max(0, Math.min(100, Math.round(tightest.pct)));
const runnerPct = runnerUp ? Math.max(0, Math.min(100, Math.round(runnerUp.pct))) : null;
const subLabelText = runnerUp
? runnerUp.label === tightest.label
? `${tightest.label} ${tightest.windowTag} · ${runnerUp.windowTag} ${runnerPct}%`
: `${tightest.label} ${tightest.windowTag} · ${runnerUp.label} ${runnerUp.windowTag} ${runnerPct}%`
: `${tightest.label} · ${tightest.windowTag}`;
return {
roundedPct: rounded,
shortText: t('capsule.quotaLeft', { pct: rounded }),
subLabelText,
detailText: candidates
.map((c) => {
const cPct = Math.max(0, Math.min(100, Math.round(c.pct)));
@@ -353,6 +378,10 @@ export function resolveCapsuleMetricPresentation(metricKey, slotCtx, ringCircumf
if (metricKey === 'cache_hit') {
const cachePct = slotCtx.hasTelemetry ? slotCtx.cacheHitPct : null;
const valid = cachePct != null && Number.isFinite(Number(cachePct));
const numVal = valid ? Number(cachePct) : 0;
const hasPrompt = slotCtx.latestPromptTokens == null || Number(slotCtx.latestPromptTokens) > 0;
const isDanger = valid && hasPrompt && numVal < 30;
const isWarn = valid && hasPrompt && !isDanger && numVal < 65;
return {
hidden: false,
metric: 'cache_hit',
@@ -360,10 +389,10 @@ export function resolveCapsuleMetricPresentation(metricKey, slotCtx, ringCircumf
textClass: 'wm-slot-text wm-cache-text',
showRing: false,
dashOffset: ringCircumference,
text: valid ? `${Math.round(Number(cachePct))}%` : '--%',
text: valid ? `${Math.round(numVal)}%` : '--%',
running: false,
warn: false,
danger: false,
warn: isWarn,
danger: isDanger,
};
}
@@ -438,6 +467,8 @@ export function resolveOverviewMetricCell(metricKey, cellCtx = {}) {
const badgeStr = translateRawAgentBadge(active.activeAgentBadge);
const modelAndAgent =
hasSubagents && badgeStr ? `[${badgeStr}] ${activeModelDisplay}` : activeModelDisplay;
const hasSpeed = Number.isFinite(active.latestTokPerSec) && Number(active.latestTokPerSec) > 0;
const speedTone = hasAnySteps && hasSpeed ? getSpeedToneClass(active.latestTokPerSec) : '';
return {
key: 'tps',
label: t('ovMetric.tps'),
@@ -445,13 +476,18 @@ export function resolveOverviewMetricCell(metricKey, cellCtx = {}) {
iconSize: 10,
isPulsing: Boolean(active.isRunning),
valueText: formatMetric(active.latestTokPerSec, ' tok/s'),
valueClass: 'cell-value accent-speed',
subText: reason ? `${modelAndAgent} · ${reason}` : modelAndAgent,
valueClass: speedTone ? `cell-value ${speedTone}` : 'cell-value',
subText: reason
? !hasSpeed
? `${reason} · ${modelAndAgent}`
: `${modelAndAgent} · ${reason}`
: modelAndAgent,
subClass: 'cell-sub',
};
}
if (metricKey === 'ttft') {
const ttftTone = hasAnySteps ? getTtftToneClass(active.latestTtftSec) : '';
return {
key: 'ttft',
label: t('ovMetric.ttft'),
@@ -459,7 +495,7 @@ export function resolveOverviewMetricCell(metricKey, cellCtx = {}) {
iconSize: 11,
isPulsing: false,
valueText: formatMetric(active.latestTtftSec, 's'),
valueClass: 'cell-value',
valueClass: ttftTone ? `cell-value ${ttftTone}` : 'cell-value',
subText: t('ovMetric.subAvgTtft', {
val: formatMetric(active.ttftSummary?.avgSec, 's'),
}),
@@ -483,64 +519,65 @@ export function resolveOverviewMetricCell(metricKey, cellCtx = {}) {
};
}
if (metricKey === 'step_cost') {
if (metricKey === 'step_cost' || metricKey === 'session_cost') {
const stepCost = active.latestStepCostUsd;
const sessCost = Number(active.sessionCostUsd || 0);
const stepCnt = Number(active.stepCount || 0);
const isAllUnpriced =
stepCnt > 0 && Number(active.sessionUnpricedCalls || 0) >= stepCnt && !(sessCost > 0);
const stepCostText =
!hasAnySteps && stepCost == null ? '—' : formatUsd(stepCost, { precise: true });
const totalCostText =
!hasAnySteps && active.sessionCostUsd == null
? '—'
: formatUsd(isAllUnpriced ? null : sessCost, {
precise: sessCost > 0 && sessCost < 0.1,
});
if (metricKey === 'step_cost') {
const costTone = hasAnySteps ? getStepCostToneClass(stepCost) : '';
return {
key: 'step_cost',
label: t('ovMetric.step_cost'),
icon: 'bolt',
iconSize: 11,
isPulsing: false,
valueText: !hasAnySteps && stepCost == null ? '—' : formatUsd(stepCost, { precise: true }),
valueClass: 'cell-value',
subText: t('ovMetric.subCacheAndTotal', {
cache: active.latestCacheHitPct ?? 0,
cost: formatUsd(active.sessionCostUsd || 0),
}),
subClass: 'cell-sub accent-ok',
valueText: stepCostText,
valueClass: costTone ? `cell-value ${costTone}` : 'cell-value',
subText: t('ovMetric.subTotalCost', { cost: totalCostText }),
subClass: 'cell-sub',
};
}
if (metricKey === 'session_cost') {
const sessCost = Number(active.sessionCostUsd || 0);
const stepCnt = Number(active.stepCount || 0);
const isAllUnpriced =
stepCnt > 0 && Number(active.sessionUnpricedCalls || 0) >= stepCnt && !(sessCost > 0);
return {
key: 'session_cost',
label: t('ovMetric.session_cost'),
icon: 'bolt',
iconSize: 11,
isPulsing: false,
valueText:
!hasAnySteps && active.sessionCostUsd == null
? '—'
: formatUsd(isAllUnpriced ? null : sessCost, {
precise: sessCost > 0 && sessCost < 0.1,
}),
valueText: totalCostText,
valueClass: 'cell-value',
subText: t('ovMetric.subStepsAndCache', {
steps: stepCnt,
cache: Math.round(Number(active.sessionCacheHitPct ?? active.latestCacheHitPct ?? 0)),
}),
subClass: 'cell-sub accent-ok',
subText: t('ovMetric.subStepCost', { cost: stepCostText }),
subClass: 'cell-sub',
};
}
if (metricKey === 'cache_hit') {
const avgCache = Number(active.sessionCacheHitPct ?? active.latestCacheHitPct ?? 0);
const latestCache = Number(active.latestCacheHitPct ?? 0);
const latestCache = active.latestCacheHitPct;
const avgCache = active.sessionCacheHitPct ?? active.latestCacheHitPct;
const hasLatest = hasAnySteps && latestCache != null && Number.isFinite(Number(latestCache));
const hasAvg = hasAnySteps && avgCache != null && Number.isFinite(Number(avgCache));
const cacheTone = hasLatest ? getCacheToneClass(latestCache, active.latestPromptTokens) : '';
return {
key: 'cache_hit',
label: t('ovMetric.cache_hit'),
icon: 'layers',
iconSize: 11,
isPulsing: false,
valueText: !hasAnySteps ? '—' : `${Math.round(avgCache)}%`,
valueClass: 'cell-value accent-ok',
subText: t('ovMetric.subPromptHit', {
latest: Math.round(latestCache),
avg: Math.round(avgCache),
valueText: hasLatest ? formatCachePct(latestCache) : '—',
valueClass: cacheTone ? `cell-value ${cacheTone}` : 'cell-value',
subText: t('ovMetric.subAvgCache', {
val: hasAvg ? formatCachePct(avgCache) : '—',
}),
subClass: 'cell-sub',
};
@@ -610,7 +647,7 @@ export function resolveOverviewMetricCell(metricKey, cellCtx = {}) {
valueText: quotaSum ? quotaSum.shortText : '—',
valueClass: quotaToneCls,
subText: quotaSum
? t('ovMetric.subQuotaPool', { label: quotaSum.detailText })
? t('ovMetric.subQuotaPool', { label: quotaSum.subLabelText })
: t('ovMetric.subQuotaPending'),
subClass: 'cell-sub',
};
@@ -5,11 +5,16 @@
* speed reason sub-lines, token combo tooltips, and high-cost highlights.
*/
import { h, patchAttr, patchClasses, patchText } from '../core/domPatch.js';
import { h, patchAttr, patchText } from '../core/domPatch.js';
import {
formatCachePct,
formatMetric,
formatTokens,
formatUsd,
getCacheToneClass,
getSpeedToneClass,
getStepCostToneClass,
getTtftToneClass,
resolveModelDisplayInfo,
speedReasonText,
} from '../core/formatters.js';
@@ -115,7 +120,7 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
sigPart: (st) => `${st.tokPerSec}:${st.selectedSpeedReason || ''}`,
createCell: () => {
const speedMain = h('strong', {
className: 'cell-value accent-speed',
className: 'cell-value tone-muted',
style: 'font-size: var(--fs-base-sm);',
});
const speedReason = h('div', {
@@ -132,6 +137,7 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
},
updateCell: (refs, st) => {
patchText(refs.speedMain, formatMetric(st.tokPerSec, ' tok/s'));
patchAttr(refs.speedMain, 'class', `cell-value ${getSpeedToneClass(st.tokPerSec)}`);
const reason = speedReasonText(st.selectedSpeedReason);
patchText(refs.speedReason, reason);
patchAttr(refs.speedReason, 'hidden', !reason);
@@ -150,6 +156,8 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
},
updateCell: (refs, st) => {
patchText(refs.valEl, formatMetric(st.ttftSec, 's'));
const tone = getTtftToneClass(st.ttftSec);
patchAttr(refs.valEl, 'class', tone || null);
},
},
@@ -252,21 +260,24 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
key: 'cache',
thLabel: () => t('stepCol.cache.th'),
optLabel: () => t('stepCol.cache.opt'),
sigPart: (st) => `${st.cacheHitPct ?? 0}`,
sigPart: (st) =>
`${st.cacheHitPct ?? 0}:${(st.inputTokens || 0) + (st.cacheReadTokens || 0) > 0 ? 1 : 0}`,
createCell: () => {
const valEl = h('span');
const td = h(
'td',
{
className: 'cell-value accent-ok',
const valEl = h('span', {
className: 'cell-value tone-muted',
style: 'font-size: var(--fs-base-sm);',
},
[valEl]
);
});
const td = h('td', {}, [valEl]);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st) => {
patchText(refs.valEl, `${Number(st.cacheHitPct ?? 0)}%`);
const promptTokens = Number(st.inputTokens || 0) + Number(st.cacheReadTokens || 0);
patchText(refs.valEl, formatCachePct(st.cacheHitPct ?? 0));
patchAttr(
refs.valEl,
'class',
`cell-value ${getCacheToneClass(st.cacheHitPct ?? 0, promptTokens)}`
);
},
},
@@ -276,14 +287,15 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
optLabel: () => t('stepCol.cost.opt'),
sigPart: (st) => `${st.costUsd}`,
createCell: () => {
const valEl = h('span');
const td = h('td', { style: 'font-weight: 600;' }, [valEl]);
const valEl = h('span', { style: 'font-weight: 600;' });
const td = h('td', {}, [valEl]);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st) => {
const costVal = st.costUsd;
patchText(refs.valEl, formatUsd(costVal, { precise: true }));
patchClasses(refs.td, { 'accent-speed': costVal >= 0.15 });
const tone = getStepCostToneClass(costVal);
patchAttr(refs.valEl, 'class', tone || null);
},
},
});
+7 -3
View File
@@ -73,13 +73,17 @@
--metric-speed: hsl(14 76% 52%);
--metric-speed-soft: color-mix(in srgb, var(--metric-speed) 14%, transparent);
--metric-ok: hsl(145 64% 38%);
--metric-ok: hsl(145 64% 41%);
--metric-ok-soft: color-mix(in srgb, var(--metric-ok) 14%, transparent);
--metric-warn: hsl(34 86% 44%);
--metric-info: hsl(197 82% 46%);
--metric-info-soft: color-mix(in srgb, var(--metric-info) 14%, transparent);
--metric-warn: hsl(35 88% 47%);
--metric-warn-soft: color-mix(in srgb, var(--metric-warn) 15%, transparent);
--metric-danger: var(--destructive, var(--vscode-errorForeground, hsl(0 74% 50%)));
--metric-danger: hsl(4 78% 55%);
--metric-danger-soft: color-mix(in srgb, var(--metric-danger) 14%, transparent);
/* Context Window 10-Channel Palette */
--ctx-assistant: hsl(217 82% 54%);
+27 -2
View File
@@ -351,14 +351,39 @@
text-overflow: ellipsis;
}
.cell-value.accent-speed {
.cell-value.accent-speed,
.accent-speed {
color: var(--metric-speed);
}
.cell-value.accent-ok {
.cell-value.accent-ok,
.accent-ok,
.cell-value.tone-good,
.tone-good {
color: var(--metric-ok);
}
.cell-value.tone-info,
.tone-info {
color: var(--metric-info);
}
.cell-value.tone-warn,
.tone-warn {
color: var(--metric-warn);
}
.cell-value.tone-danger,
.tone-danger {
color: var(--metric-danger);
}
.cell-value.tone-muted,
.tone-muted {
color: var(--text-muted);
font-weight: 500;
}
.cell-sub {
font-size: var(--fs-sm);
color: var(--text-secondary);
+34 -5
View File
@@ -74,13 +74,17 @@
--metric-speed: hsl(14 76% 52%);
--metric-speed-soft: color-mix(in srgb, var(--metric-speed) 14%, transparent);
--metric-ok: hsl(145 64% 38%);
--metric-ok: hsl(145 64% 41%);
--metric-ok-soft: color-mix(in srgb, var(--metric-ok) 14%, transparent);
--metric-warn: hsl(34 86% 44%);
--metric-info: hsl(197 82% 46%);
--metric-info-soft: color-mix(in srgb, var(--metric-info) 14%, transparent);
--metric-warn: hsl(35 88% 47%);
--metric-warn-soft: color-mix(in srgb, var(--metric-warn) 15%, transparent);
--metric-danger: var(--destructive, var(--vscode-errorForeground, hsl(0 74% 50%)));
--metric-danger: hsl(4 78% 55%);
--metric-danger-soft: color-mix(in srgb, var(--metric-danger) 14%, transparent);
/* Context Window 10-Channel Palette */
--ctx-assistant: hsl(217 82% 54%);
@@ -1498,14 +1502,39 @@ input {
text-overflow: ellipsis;
}
.cell-value.accent-speed {
.cell-value.accent-speed,
.accent-speed {
color: var(--metric-speed);
}
.cell-value.accent-ok {
.cell-value.accent-ok,
.accent-ok,
.cell-value.tone-good,
.tone-good {
color: var(--metric-ok);
}
.cell-value.tone-info,
.tone-info {
color: var(--metric-info);
}
.cell-value.tone-warn,
.tone-warn {
color: var(--metric-warn);
}
.cell-value.tone-danger,
.tone-danger {
color: var(--metric-danger);
}
.cell-value.tone-muted,
.tone-muted {
color: var(--text-muted);
font-weight: 500;
}
.cell-sub {
font-size: var(--fs-sm);
color: var(--text-secondary);
+5
View File
@@ -1098,6 +1098,11 @@ test('reconciles 8-group context breakdown with real API prompt+output tokens an
assert.equal(ctx.totalTokens, 158328);
assert.equal(ctx.usedPct, 61.8);
assert.equal(payload.conversations[0].contextUsedPct, 61.8);
assert.equal(payload.activeConversation.inputTokens, 4989);
assert.equal(payload.activeConversation.cacheReadTokens, 150223);
assert.equal(payload.activeConversation.outputTokens, 3116);
assert.equal(payload.activeConversation.totalTokens, 158328);
assert.equal(payload.activeConversation.latestPromptTokens, 155212);
// Previously dropped Skills & User Rules are restored and scaled cleanly
assert.ok(ctx.skillsTokens >= 2290 && ctx.skillsTokens <= 2300, `skills=${ctx.skillsTokens}`);
+108
View File
@@ -25,6 +25,14 @@ import {
} from '../backend/ls-discovery.mjs';
import { handleMcpJsonRpcMessage } from '../mcp-entry.mjs';
import { computeCapsuleLayoutMode } from '../src/components/layout/WindowOverlayShell.js';
import {
getCacheToneClass,
getSpeedToneClass,
getStepCostToneClass,
getTtftToneClass,
} from '../src/core/formatters.js';
import { setI18nLanguage } from '../src/i18n/index.js';
import { resolveOverviewMetricCell } from '../src/registries/metricRegistry.js';
import { backendHarness } from './backend-harness.mjs';
test('DevToolsActivePort parsing, cross-platform discovery (2.0 + IDE), and strict target/origin filtering', () => {
@@ -4511,3 +4519,103 @@ test('Antigravity IDE composer mount mode (输入框挂载) docks inside extensi
fs.rmSync(tmpDir, { recursive: true, force: true });
}
});
test('Step table semantic tone classes (speed/cache/ttft/cost) and domain-aligned overview metric subtexts', () => {
// 1. Speed 4-tier + muted semantic grading
assert.equal(getSpeedToneClass(null), 'tone-muted');
assert.equal(getSpeedToneClass(0), 'tone-muted');
assert.equal(getSpeedToneClass(86.1), 'tone-good');
assert.equal(getSpeedToneClass(54.9), 'tone-info');
assert.equal(getSpeedToneClass(24.3), 'tone-warn');
assert.equal(getSpeedToneClass(7.6), 'tone-danger');
// 2. Cache hit 4-tier + 0-prompt muted grading
assert.equal(getCacheToneClass(null), 'tone-muted');
assert.equal(getCacheToneClass(0, 0), 'tone-muted');
assert.equal(getCacheToneClass(0, 208700), 'tone-danger');
assert.equal(getCacheToneClass(59.8, 75400), 'tone-warn');
assert.equal(getCacheToneClass(77.6, 96400), 'tone-info');
assert.equal(getCacheToneClass(96.8, 155212), 'tone-good');
// 3. Step cost & TTFT alert grading
assert.equal(getStepCostToneClass(0.056), '');
assert.equal(getStepCostToneClass(0.18), 'tone-warn');
assert.equal(getStepCostToneClass(0.421), 'tone-danger');
assert.equal(getTtftToneClass(12.1), '');
assert.equal(getTtftToneClass(22.3), 'tone-warn');
assert.equal(getTtftToneClass(34.0), 'tone-danger');
// 4. Overview metric cells: current step in primary value, strictly domain-aligned subtexts
setI18nLanguage('zh-CN');
const mockActive = {
stepCount: 787,
isRunning: false,
activeAgentBadge: '主',
activeModelShort: 'gemini-4-carbon',
latestTokPerSec: 54.9,
latestTtftSec: 12.1,
ttftSummary: { avgSec: 14.4 },
avgTokPerSec: 57.3,
speedSummary: { sampleCount: 787, excludedCount: 0 },
latestStepCostUsd: 0.056,
sessionCostUsd: 46.9,
sessionUnpricedCalls: 0,
latestCacheHitPct: 96.8,
sessionCacheHitPct: 92.4,
latestPromptTokens: 155212,
inputTokens: 1_200_000,
cacheReadTokens: 23_900_000,
outputTokens: 400_000,
totalTokens: 25_500_000,
context: { totalTokens: 158328, compactionLimitTokens: 256000, limitTokens: 256000 },
};
const mockQuotas = {
activePool: {
poolLabel: 'Carbon',
family: 'Carbon',
remainingPct: 42,
weeklyRemainingPct: 85,
},
};
const stepCostCell = resolveOverviewMetricCell('step_cost', {
active: mockActive,
hasSubagents: true,
});
assert.equal(stepCostCell.valueText, '$0.056');
assert.equal(stepCostCell.subText, '累计 $46.90', 'No unrelated cache % inside 本次费用');
assert.equal(stepCostCell.subClass, 'cell-sub', 'Neutral subtext color instead of green accent-ok');
const sessCostCell = resolveOverviewMetricCell('session_cost', {
active: mockActive,
hasSubagents: true,
});
assert.equal(sessCostCell.valueText, '$46.90');
assert.equal(sessCostCell.subText, '本次 $0.056', 'No unrelated cache % inside 累计费用');
assert.equal(sessCostCell.subClass, 'cell-sub');
const cacheCell = resolveOverviewMetricCell('cache_hit', {
active: mockActive,
hasSubagents: true,
});
assert.equal(cacheCell.valueText, '96.8%', 'Current step cache hit shown as primary big value');
assert.equal(cacheCell.valueClass, 'cell-value tone-good');
assert.equal(cacheCell.subText, '均值 92.4%', 'Session average shown cleanly in subtext without repetition');
const coldCacheCell = resolveOverviewMetricCell('cache_hit', {
active: { ...mockActive, latestCacheHitPct: 0, latestPromptTokens: 208700 },
});
assert.equal(coldCacheCell.valueText, '0%');
assert.equal(coldCacheCell.valueClass, 'cell-value tone-danger', '0% cold cache miss turns danger red');
const tokCell = resolveOverviewMetricCell('session_tokens', { active: mockActive });
assert.equal(tokCell.valueText, '25.5M');
assert.equal(tokCell.subText, '入 25.1M · 出 400.0k');
const quotaCell = resolveOverviewMetricCell('quota_tightest', {
active: mockActive,
quotas: mockQuotas,
});
assert.equal(quotaCell.valueText, '余 42%');
assert.equal(quotaCell.subText, 'Carbon 5h · 周 85%', 'Identifies pool/window without repeating 余 42%');
});