diff --git a/sidecars/panel/backend/cli-statusline-config.mjs b/sidecars/panel/backend/cli-statusline-config.mjs index c83c215..9752ebc 100644 --- a/sidecars/panel/backend/cli-statusline-config.mjs +++ b/sidecars/panel/backend/cli-statusline-config.mjs @@ -33,7 +33,7 @@ import { resolveCapsuleQuotaSlotPct, } from '../shared/telemetry-display-rules.mjs'; -// 24-bit ANSI 前景 SGR 调色板(透明底色,与桌面端四档语义色阶及 CLI 原生底栏色调对齐,无任何背景填充或非 SGR 控制符) +// 24-bit ANSI SGR 调色板(和桌面端语义色阶及 CLI 原生底栏对齐;上下文和配额槽位采用 24-bit 底色胶囊填充,零 OSC 序列) const SGR_RESET = '\x1b[0m'; const SGR_BOLD = '\x1b[1m'; const SGR_FG_BRIGHT = '\x1b[38;2;226;232;240m'; @@ -44,7 +44,6 @@ const SGR_FG_CHROME = '\x1b[38;2;136;142;150m'; const SGR_FG_SEP = '\x1b[38;2;110;122;140m'; const SGR_FG_DOT_IDLE = '\x1b[38;2;100;116;139m'; const SGR_FG_ACCENT = '\x1b[38;2;96;165;250m'; -const SGR_FG_TEAL = '\x1b[38;2;45;212;191m'; const SGR_FG_GOOD = '\x1b[38;2;52;211;153m'; const SGR_FG_INFO = '\x1b[38;2;56;189;248m'; const SGR_FG_WARN = '\x1b[38;2;251;191;36m'; @@ -52,6 +51,20 @@ const SGR_FG_DANGER = '\x1b[38;2;248;113;113m'; const SGR_FG_MODE_AUTO = '\x1b[38;2;234;179;8m'; const SGR_FG_MODE_VIOLET = '\x1b[38;2;192;132;252m'; +// 底色胶囊专用 24-bit 背景和前景对比色(深灰暗轨 + 四档低刺眼饱和填充底色 + 亮白数字) +const SGR_BG_PILL_TRACK = '\x1b[48;2;36;40;50m'; +const SGR_BG_PILL_BLUE = '\x1b[48;2;36;72;128m'; +const SGR_BG_PILL_GREEN = '\x1b[48;2;24;96;68m'; +const SGR_BG_PILL_WARN = '\x1b[48;2;116;84;22m'; +const SGR_BG_PILL_DANGER = '\x1b[48;2;124;42;48m'; +const SGR_FG_PILL_LABEL_TRACK = '\x1b[38;2;176;186;202m'; +const SGR_FG_PILL_VAL_TRACK = `${SGR_BOLD}\x1b[38;2;238;242;248m`; +const SGR_FG_PILL_LABEL_BLUE = '\x1b[38;2;216;230;250m'; +const SGR_FG_PILL_LABEL_GREEN = '\x1b[38;2;210;244;228m'; +const SGR_FG_PILL_LABEL_WARN = '\x1b[38;2;254;240;199m'; +const SGR_FG_PILL_LABEL_DANGER = '\x1b[38;2;254;222;224m'; +const SGR_FG_PILL_VAL_FILLED = `${SGR_BOLD}\x1b[38;2;248;250;252m`; + function isCliStatusPlainObject(v) { return Boolean(v) && typeof v === 'object' && !Array.isArray(v); } @@ -691,24 +704,71 @@ function cliComposeBalancedThreeColumn(leftStr, centerStr, rightStr, maxWidth) { return cw <= maxWidth ? centerStr : ''; } -function cliBuildMiniProgressBar( +/** + * 将标签和百分比渲染为从左往右按占比填充背景的 24-bit 底色胶囊(如 ` 上下文 17% ` / ` G5h 83% `)。 + * 百分比按 3-4 列右对齐以防数值变化引起整行抖动,CJK 全角字符按 2 列中点判定归属。 + */ +function cliBuildPillGauge( + label, pct, - { width = 8, fillSgr = SGR_FG_TEAL, emptyChar = '⢕', useColor = true } = {} + { + fillBg = SGR_BG_PILL_BLUE, + fillLabelFg = SGR_FG_PILL_LABEL_BLUE, + fillValFg = SGR_FG_PILL_VAL_FILLED, + trackBg = SGR_BG_PILL_TRACK, + trackLabelFg = SGR_FG_PILL_LABEL_TRACK, + trackValFg = SGR_FG_PILL_VAL_TRACK, + } = {} ) { - if (!(width > 0)) return ''; - const clamped = Math.max(0, Math.min(100, Number(pct))); - let filled = Math.round((clamped / 100) * width); - if (clamped > 0 && filled === 0) filled = 1; - if (clamped < 95 && filled >= width) filled = Math.max(0, width - 1); - const empty = Math.max(0, width - filled); - const filledStr = '█'.repeat(filled); - const emptyStr = emptyChar.repeat(empty); - if (!useColor) { - return `${filledStr}${emptyStr}`; + const clamped = Math.max(0, Math.min(100, Number(pct) || 0)); + const valStr = `${Math.round(clamped)}%`.padStart(3, ' '); + const prefixText = ` ${label} `; + const valText = `${valStr} `; + + const cells = []; + let totalCols = 0; + for (const ch of prefixText) { + const w = cliDisplayWidth(ch) || 1; + cells.push({ ch, w, col: totalCols, isVal: false }); + totalCols += w; } - const fillPart = filledStr ? `${fillSgr}${filledStr}` : ''; - const emptyPart = emptyStr ? `${SGR_FG_DIM}${emptyStr}` : ''; - return `${fillPart}${emptyPart}${SGR_RESET}`; + for (const ch of valText) { + const w = cliDisplayWidth(ch) || 1; + cells.push({ ch, w, col: totalCols, isVal: true }); + totalCols += w; + } + + const exactFill = (clamped / 100) * totalCols; + const lastIdx = cells.length - 1; + let out = ''; + let curStyle = ''; + + for (let i = 0; i < cells.length; i += 1) { + const cell = cells[i]; + let isFilled = clamped > 0 && cell.col + cell.w / 2 <= exactFill; + if (i === 0 && clamped > 0) isFilled = true; + if (i === lastIdx && clamped < 96) isFilled = false; + if (clamped >= 100) isFilled = true; + + const bg = isFilled ? fillBg : trackBg; + const fg = isFilled + ? cell.isVal + ? fillValFg + : fillLabelFg + : cell.isVal + ? trackValFg + : trackLabelFg; + const style = `${bg}${fg}`; + if (style !== curStyle) { + // 切换样式时若此前带粗体而目标不带粗体,先重置再写入避免粗体残留 + const prevBold = curStyle.includes(SGR_BOLD); + const nextBold = style.includes(SGR_BOLD); + out += prevBold && !nextBold ? `${SGR_RESET}${style}` : style; + curStyle = style; + } + out += cell.ch; + } + return `${out}${SGR_RESET}`; } function cliResolveQuotaSlotPrefix(metricKey, isEn) { @@ -720,12 +780,12 @@ function cliResolveQuotaSlotPrefix(metricKey, isEn) { } /** - * 将单槽位指标格式化为纯文本及无背景前景语义 SGR 片段。 + * 将单槽位指标格式化为纯文本及 24-bit 终端语义 SGR 片段(上下文和配额支持底色胶囊填充)。 */ function cliRenderSingleSlot( metricKey, slotCtx, - { isEn = false, useColor = true, slotSet, barWidth = 8 } = {} + { isEn = false, useColor = true, slotSet, usePill = true } = {} ) { const hasTelemetry = slotCtx.hasTelemetry !== false; @@ -734,24 +794,23 @@ function cliRenderSingleSlot( const pctNum = valid ? Math.max(0, Math.min(100, Math.round(Number(slotCtx.usedPct)))) : null; const label = isEn ? 'Ctx' : '上下文'; const textVal = pctNum != null ? `${pctNum}%` : '--%'; + if (!useColor) { + return `${label} ${textVal}`; + } const isDanger = pctNum != null && pctNum >= 88; const isWarn = !isDanger && pctNum != null && pctNum >= 70; - const isMid = !isDanger && !isWarn && pctNum != null && pctNum >= 50; - const barColor = isDanger - ? SGR_FG_DANGER - : isWarn - ? SGR_FG_WARN - : isMid - ? SGR_FG_ACCENT - : pctNum != null - ? SGR_FG_TEAL - : SGR_FG_MUTED; - const barSegment = - barWidth > 0 && pctNum != null - ? `${cliBuildMiniProgressBar(pctNum, { width: barWidth, fillSgr: barColor, emptyChar: '⢕', useColor })} ` - : ''; - if (!useColor) { - return `${label} ${barSegment}${textVal}`; + if (usePill && pctNum != null) { + const fillBg = isDanger + ? SGR_BG_PILL_DANGER + : isWarn + ? SGR_BG_PILL_WARN + : SGR_BG_PILL_BLUE; + const fillLabelFg = isDanger + ? SGR_FG_PILL_LABEL_DANGER + : isWarn + ? SGR_FG_PILL_LABEL_WARN + : SGR_FG_PILL_LABEL_BLUE; + return cliBuildPillGauge(label, pctNum, { fillBg, fillLabelFg }); } const valColor = isDanger ? `${SGR_BOLD}${SGR_FG_DANGER}` @@ -760,7 +819,7 @@ function cliRenderSingleSlot( : pctNum != null ? `${SGR_BOLD}${SGR_FG_BRIGHT}` : SGR_FG_MUTED; - return `${SGR_FG_MUTED}${label} ${barSegment}${valColor}${textVal}${SGR_RESET}`; + return `${SGR_FG_MUTED}${label} ${valColor}${textVal}${SGR_RESET}`; } if (metricKey === 'tps') { @@ -854,20 +913,12 @@ function cliRenderSingleSlot( const prefix = cliResolveQuotaSlotPrefix(metricKey, isEn); const isDanger = quotaPct != null && quotaPct <= 15; const isWarn = !isDanger && quotaPct != null && quotaPct <= 30; - const isMid = !isDanger && !isWarn && quotaPct != null && quotaPct <= 60; - const fillSgr = isDanger - ? SGR_FG_DANGER - : isWarn - ? SGR_FG_WARN - : isMid - ? SGR_FG_INFO - : SGR_FG_GOOD; const pctSgr = isDanger ? `${SGR_BOLD}${SGR_FG_DANGER}` : isWarn ? `${SGR_BOLD}${SGR_FG_WARN}` : quotaPct != null - ? SGR_FG_NORMAL + ? SGR_FG_GOOD : SGR_FG_MUTED; if (quotaPct == null) { @@ -876,27 +927,25 @@ function cliRenderSingleSlot( return useColor ? `${SGR_FG_MUTED}${emptyText}${SGR_RESET}` : emptyText; } - if (barWidth > 0) { - const bar = cliBuildMiniProgressBar(quotaPct, { - width: barWidth, - fillSgr, - emptyChar: '⣿', - useColor, - }); - if (!useColor) { - return `${prefix} ${bar} ${quotaPct}%`; - } - return `${SGR_FG_MUTED}${prefix} ${bar} ${pctSgr}${quotaPct}%${SGR_RESET}`; + if (!useColor) { + return `${prefix} ${quotaPct}%`; } - const compactText = - metricKey === 'quota_auto' - ? isEn - ? `${quotaPct}% left` - : `余 ${quotaPct}%` - : `${prefix} ${quotaPct}%`; - if (!useColor) return compactText; - return `${pctSgr}${compactText}${SGR_RESET}`; + if (usePill) { + const fillBg = isDanger + ? SGR_BG_PILL_DANGER + : isWarn + ? SGR_BG_PILL_WARN + : SGR_BG_PILL_GREEN; + const fillLabelFg = isDanger + ? SGR_FG_PILL_LABEL_DANGER + : isWarn + ? SGR_FG_PILL_LABEL_WARN + : SGR_FG_PILL_LABEL_GREEN; + return cliBuildPillGauge(prefix, quotaPct, { fillBg, fillLabelFg }); + } + + return `${SGR_FG_MUTED}${prefix} ${pctSgr}${quotaPct}%${SGR_RESET}`; } /** @@ -1110,12 +1159,12 @@ export function formatCliStatusLineCapsule(slotCtx = {}, options = {}) { ? cliStatusFormatAnomalyTag(slotCtx.latestAnomaly, { isEn, useColor }) : ''; - const defaultBarWidth = options.showProgressBars === false ? 0 : 8; + const defaultUsePill = options.showProgressBars !== false; - const buildCapsulesForSlots = (slotList, includeAnomaly = true, barWidth = defaultBarWidth) => { + const buildCapsulesForSlots = (slotList, includeAnomaly = true, usePill = defaultUsePill) => { const slotSet = new Set(slotList); const rendered = slotList.map((key) => - cliRenderSingleSlot(key, slotCtx, { isEn, useColor, slotSet, barWidth }) + cliRenderSingleSlot(key, slotCtx, { isEn, useColor, slotSet, usePill }) ); if (includeAnomaly && anomalyBadge) { rendered.push(anomalyBadge); @@ -1128,7 +1177,7 @@ export function formatCliStatusLineCapsule(slotCtx = {}, options = {}) { }; }; - const baseCapsules = buildCapsulesForSlots(activeSlots, true, defaultBarWidth); + const baseCapsules = buildCapsulesForSlots(activeSlots, true, defaultUsePill); const rawWidth = Number(options.terminalWidth); if (!Number.isFinite(rawWidth) || rawWidth <= 0) { return baseCapsules.fullCapsule; @@ -1167,44 +1216,32 @@ export function formatCliStatusLineCapsule(slotCtx = {}, options = {}) { ); if (fullPrimary) return fullPrimary; - // 中等终端优先把进度条从 8 格微缩至 5 格以保住左右完整原生提示,再逐级收缩左右栏和槽位 - if (defaultBarWidth > 5) { - const compactBarCapsules = buildCapsulesForSlots(activeSlots, true, 5); - const fullCompactBar = cliComposeBalancedThreeColumn( - fullLeft, - compactBarCapsules.fullCapsule, - fullRight, - maxWidth - ); - if (fullCompactBar) return fullCompactBar; - } - const primaryComposed = tryCompose(baseCapsules); if (primaryComposed) return primaryComposed; - if (defaultBarWidth > 5) { - const compactBarCapsules = buildCapsulesForSlots(activeSlots, true, 5); - const compactBarComposed = tryCompose(compactBarCapsules); - if (compactBarComposed) return compactBarComposed; - } - if (defaultBarWidth > 0) { - const noBarCapsules = buildCapsulesForSlots(activeSlots, true, 0); - const noBarComposed = tryCompose(noBarCapsules); - if (noBarComposed) return noBarComposed; + if (defaultUsePill) { + const noPillCapsules = buildCapsulesForSlots(activeSlots, true, false); + const noPillComposed = tryCompose(noPillCapsules); + if (noPillComposed) return noPillComposed; } let reducedSlots = [...activeSlots]; while (reducedSlots.length > 1) { reducedSlots = cliStatusShedLowestPrioritySlot(reducedSlots); - const reducedCap = buildCapsulesForSlots(reducedSlots, true, 0); + const reducedCap = buildCapsulesForSlots(reducedSlots, true, defaultUsePill); const composed = tryCompose(reducedCap); if (composed) return composed; + if (defaultUsePill) { + const reducedPlain = buildCapsulesForSlots(reducedSlots, true, false); + const composedPlain = tryCompose(reducedPlain); + if (composedPlain) return composedPlain; + } } if (cliDisplayWidth(baseCapsules.fullCapsule) <= maxWidth) { return baseCapsules.fullCapsule; } - const minimalCap = buildCapsulesForSlots(reducedSlots, false, 0); + const minimalCap = buildCapsulesForSlots(reducedSlots, false, false); if (cliDisplayWidth(minimalCap.fullCapsule) <= maxWidth) { return minimalCap.fullCapsule; } diff --git a/sidecars/panel/src/styles/views-settings.css b/sidecars/panel/src/styles/views-settings.css index 4294961..de6aefe 100644 --- a/sidecars/panel/src/styles/views-settings.css +++ b/sidecars/panel/src/styles/views-settings.css @@ -1428,6 +1428,8 @@ } .cli-preview-slot { + display: inline-flex; + align-items: center; color: var(--text-primary); font-weight: 500; } @@ -1453,38 +1455,53 @@ font-weight: 400; } -.cli-preview-bar-fill { - letter-spacing: 0; -} - -.cli-preview-bar-empty { - color: var(--text-muted); - opacity: 0.65; - letter-spacing: 0; -} - .cli-preview-val { color: var(--text-primary); } -.cli-preview-slot.tone-good .cli-preview-val, -.cli-preview-slot.tone-good .cli-preview-bar-fill { +.cli-preview-slot.tone-good .cli-preview-val { color: var(--metric-ok); } -.cli-preview-slot.tone-info .cli-preview-val, -.cli-preview-slot.tone-info .cli-preview-bar-fill { +.cli-preview-slot.tone-info .cli-preview-val { color: var(--metric-info); } -.cli-preview-slot.tone-accent .cli-preview-bar-fill { - color: var(--accent-primary); -} - .cli-preview-slot.tone-muted .cli-preview-val { color: var(--text-secondary); } +.cli-preview-slot.is-pill { + --cli-pill-track: color-mix(in srgb, var(--text-primary) 10%, var(--surface-panel)); + --cli-pill-fill: color-mix(in srgb, var(--accent-primary) 34%, var(--surface-panel)); + padding: 1px 6px; + border-radius: 3px; + background: linear-gradient( + to right, + var(--cli-pill-fill) 0%, + var(--cli-pill-fill) var(--cli-pill-pct, 0%), + var(--cli-pill-track) var(--cli-pill-pct, 0%), + var(--cli-pill-track) 100% + ); +} + +.cli-preview-slot.is-pill.tone-good { + --cli-pill-fill: color-mix(in srgb, var(--metric-ok) 32%, var(--surface-panel)); +} + +.cli-preview-slot.is-pill.tone-accent { + --cli-pill-fill: color-mix(in srgb, var(--accent-primary) 34%, var(--surface-panel)); +} + +.cli-preview-slot.is-pill .cli-preview-prefix { + color: color-mix(in srgb, var(--text-primary) 82%, transparent); +} + +.cli-preview-slot.is-pill .cli-preview-val { + color: var(--text-primary); + font-weight: 600; +} + .cli-status-footer { display: flex; flex-direction: column; diff --git a/sidecars/panel/src/views/settings/SettingsStructureTab.js b/sidecars/panel/src/views/settings/SettingsStructureTab.js index b9bb992..84eff9d 100644 --- a/sidecars/panel/src/views/settings/SettingsStructureTab.js +++ b/sidecars/panel/src/views/settings/SettingsStructureTab.js @@ -103,87 +103,74 @@ function isSameList(a, b) { return true; } -function buildCliPreviewMiniBar(pct, width = 8, emptyChar = '⢕') { - const clamped = Math.max(0, Math.min(100, Number(pct))); - let filled = Math.round((clamped / 100) * width); - if (clamped > 0 && filled === 0) filled = 1; - if (clamped < 95 && filled >= width) filled = Math.max(0, width - 1); - return { - barFilled: '█'.repeat(filled), - barEmpty: emptyChar.repeat(Math.max(0, width - filled)), - }; -} - function formatCliPreviewSlot(slotKey, isEn) { switch (slotKey) { case 'tps': - return { prefix: '', barFilled: '', barEmpty: '', text: '68.4 t/s', tone: 'good' }; + return { prefix: '', text: '68.4 t/s', tone: 'good', pillPct: null }; case 'avg_tps': return { prefix: '', - barFilled: '', - barEmpty: '', text: isEn ? 'avg 54.0' : '均 54.0', tone: 'info', + pillPct: null, }; case 'ttft': - return { prefix: '', barFilled: '', barEmpty: '', text: '1.1s', tone: 'good' }; + return { prefix: '', text: '1.1s', tone: 'good', pillPct: null }; case 'cost': - return { prefix: '', barFilled: '', barEmpty: '', text: '$0.040', tone: 'normal' }; + return { prefix: '', text: '$0.040', tone: 'normal', pillPct: null }; case 'session_cost': - return { prefix: '', barFilled: '', barEmpty: '', text: '$0.42', tone: 'normal' }; + return { prefix: '', text: '$0.42', tone: 'normal', pillPct: null }; case 'cache_hit': return { prefix: '', - barFilled: '', - barEmpty: '', text: isEn ? 'cache 92%' : '缓 92%', tone: 'good', + pillPct: null, }; case 'session_tokens': - return { prefix: '', barFilled: '', barEmpty: '', text: '142K tok', tone: 'muted' }; + return { prefix: '', text: '142K tok', tone: 'muted', pillPct: null }; case 'quota_auto': return { prefix: isEn ? '5h ' : '余 ', - ...buildCliPreviewMiniBar(64, 8, '⣿'), - text: ' 64%', + text: '64%', tone: 'good', + pillPct: 64, }; case 'gemini_5h': return { prefix: 'G5h ', - ...buildCliPreviewMiniBar(64, 8, '⣿'), - text: ' 64%', + text: '64%', tone: 'good', + pillPct: 64, }; case 'gemini_weekly': return { prefix: isEn ? 'Gw ' : 'G周 ', - ...buildCliPreviewMiniBar(88, 8, '⣿'), - text: ' 88%', + text: '88%', tone: 'good', + pillPct: 88, }; case 'claude_5h': return { prefix: 'C5h ', - ...buildCliPreviewMiniBar(96, 8, '⣿'), - text: ' 96%', + text: '96%', tone: 'good', + pillPct: 96, }; case 'claude_weekly': return { prefix: isEn ? 'Cw ' : 'C周 ', - ...buildCliPreviewMiniBar(99, 8, '⣿'), - text: ' 99%', + text: '99%', tone: 'good', + pillPct: 99, }; case 'context': default: return { prefix: isEn ? 'Ctx ' : '上下文 ', - ...buildCliPreviewMiniBar(56), - text: ' 56%', + text: '56%', tone: 'accent', + pillPct: 56, }; } } @@ -503,16 +490,12 @@ export const SettingsStructureTab = defineComponent({ cliPreviewChildren.push(sepEl); } const prefixEl = h('span', { className: 'cli-preview-prefix' }); - const barFillEl = h('span', { className: 'cli-preview-bar-fill' }); - const barEmptyEl = h('span', { className: 'cli-preview-bar-empty' }); const valueEl = h('span', { className: 'cli-preview-val' }); const slotEl = h('span', { className: 'cli-preview-slot' }, [ prefixEl, - barFillEl, - barEmptyEl, valueEl, ]); - cliPreviewSlotParts.push({ slotEl, prefixEl, barFillEl, barEmptyEl, valueEl }); + cliPreviewSlotParts.push({ slotEl, prefixEl, valueEl }); cliPreviewChildren.push(slotEl); } const cliPreviewEl = h('div', { className: 'cli-status-preview' }, cliPreviewChildren); @@ -645,12 +628,13 @@ export const SettingsStructureTab = defineComponent({ if (sepEl) patchAttr(sepEl, 'hidden', !visible); if (visible) { const item = formatCliPreviewSlot(key, isEn); + const isPill = Number.isFinite(item.pillPct); patchAttr(parts.slotEl, 'data-metric', key); patchText(parts.prefixEl, item.prefix || ''); - patchText(parts.barFillEl, item.barFilled || ''); - patchText(parts.barEmptyEl, item.barEmpty || ''); patchText(parts.valueEl, item.text || ''); + patchStyleVar(parts.slotEl, '--cli-pill-pct', isPill ? `${item.pillPct}%` : ''); patchClasses(parts.slotEl, { + 'is-pill': isPill, 'tone-good': item.tone === 'good', 'tone-info': item.tone === 'info', 'tone-accent': item.tone === 'accent', diff --git a/sidecars/panel/styles.css b/sidecars/panel/styles.css index 89d1bc4..ca50ccc 100644 --- a/sidecars/panel/styles.css +++ b/sidecars/panel/styles.css @@ -6136,6 +6136,8 @@ html[data-standalone="true"] .app-shell { } .cli-preview-slot { + display: inline-flex; + align-items: center; color: var(--text-primary); font-weight: 500; } @@ -6161,38 +6163,53 @@ html[data-standalone="true"] .app-shell { font-weight: 400; } -.cli-preview-bar-fill { - letter-spacing: 0; -} - -.cli-preview-bar-empty { - color: var(--text-muted); - opacity: 0.65; - letter-spacing: 0; -} - .cli-preview-val { color: var(--text-primary); } -.cli-preview-slot.tone-good .cli-preview-val, -.cli-preview-slot.tone-good .cli-preview-bar-fill { +.cli-preview-slot.tone-good .cli-preview-val { color: var(--metric-ok); } -.cli-preview-slot.tone-info .cli-preview-val, -.cli-preview-slot.tone-info .cli-preview-bar-fill { +.cli-preview-slot.tone-info .cli-preview-val { color: var(--metric-info); } -.cli-preview-slot.tone-accent .cli-preview-bar-fill { - color: var(--accent-primary); -} - .cli-preview-slot.tone-muted .cli-preview-val { color: var(--text-secondary); } +.cli-preview-slot.is-pill { + --cli-pill-track: color-mix(in srgb, var(--text-primary) 10%, var(--surface-panel)); + --cli-pill-fill: color-mix(in srgb, var(--accent-primary) 34%, var(--surface-panel)); + padding: 1px 6px; + border-radius: 3px; + background: linear-gradient( + to right, + var(--cli-pill-fill) 0%, + var(--cli-pill-fill) var(--cli-pill-pct, 0%), + var(--cli-pill-track) var(--cli-pill-pct, 0%), + var(--cli-pill-track) 100% + ); +} + +.cli-preview-slot.is-pill.tone-good { + --cli-pill-fill: color-mix(in srgb, var(--metric-ok) 32%, var(--surface-panel)); +} + +.cli-preview-slot.is-pill.tone-accent { + --cli-pill-fill: color-mix(in srgb, var(--accent-primary) 34%, var(--surface-panel)); +} + +.cli-preview-slot.is-pill .cli-preview-prefix { + color: color-mix(in srgb, var(--text-primary) 82%, transparent); +} + +.cli-preview-slot.is-pill .cli-preview-val { + color: var(--text-primary); + font-weight: 600; +} + .cli-status-footer { display: flex; flex-direction: column; diff --git a/sidecars/panel/test/backend.test.mjs b/sidecars/panel/test/backend.test.mjs index a250dcf..bc791a4 100644 --- a/sidecars/panel/test/backend.test.mjs +++ b/sidecars/panel/test/backend.test.mjs @@ -1948,7 +1948,7 @@ test('provisions Antigravity CLI statusLine safely and renders live capsule from effort: 'high', }); - // Capsule formatting in NO_COLOR and 24-bit ANSI modes uses transparent background (zero 48;...m SGR) + // Capsule formatting: NO_COLOR renders compact plain text; 24-bit ANSI renders inline pill gauges (48;2;...m) with zero OSC const plainCapsule = h.formatCliStatusLineCapsule( { hasTelemetry: true, @@ -1966,7 +1966,7 @@ test('provisions Antigravity CLI statusLine safely and renders live capsule from color: false, } ); - assert.equal(plainCapsule, '● 0 运行中 11.8s | 38.1 t/s | 余 █████⣿⣿⣿ 57% | 上下文 █⢕⢕⢕⢕⢕⢕⢕ 17%'); + assert.equal(plainCapsule, '● 0 运行中 11.8s | 38.1 t/s | 余 57% | 上下文 17%'); const ansiCapsule = h.formatCliStatusLineCapsule( { @@ -1985,14 +1985,15 @@ test('provisions Antigravity CLI statusLine safely and renders live capsule from color: true, } ); - assert.equal(/\x1b\[48;/.test(ansiCapsule), false, 'Emits zero background SGR codes'); + assert.equal(/\x1b\[48;2;116;84;22m/.test(ansiCapsule), true, 'Emits warm amber 24-bit pill fill for warn quota/context'); + assert.equal(/\x1b\[48;2;36;40;50m/.test(ansiCapsule), true, 'Emits dark slate unfilled pill track'); assert.equal(/\x1b\]/.test(ansiCapsule), false, 'Contains zero OSC sequences so Bubble Tea width never breaks'); assert.equal( ansiCapsule.replace(/\x1b\[[0-9;]*m/g, ''), - '● 2 运行中 · 1 子 1.3s | 68.4 t/s | 余 ██⣿⣿⣿⣿⣿⣿ 22% | 上下文 ██████⢕⢕ 75%' + '● 2 运行中 · 1 子 1.3s | 68.4 t/s | 余 22% | 上下文 75% ' ); - // Full 3-column single-line bar with left shortcuts, centered metrics, and right mode/model/effort + // Full 3-column single-line bar with left shortcuts, centered pill metrics, and right mode/model/effort const inlineBar120 = h.formatCliStatusLineCapsule( { hasTelemetry: true, @@ -2014,18 +2015,19 @@ test('provisions Antigravity CLI statusLine safely and renders live capsule from modelEffort: 'medium', } ); - assert.equal(/\x1b\[48;/.test(inlineBar120), false, 'Inline 3-column bar has zero background SGR'); + assert.equal(/\x1b\[48;2;24;96;68m/.test(inlineBar120), true, 'Quota normal pill uses deep emerald fill'); + assert.equal(/\x1b\[48;2;36;72;128m/.test(inlineBar120), true, 'Context normal pill uses slate-blue fill'); const plainBar120 = inlineBar120.replace(/\x1b\[[0-9;]*m/g, ''); assert.ok(plainBar120.startsWith('? for shortcuts '), 'Keeps ? for shortcuts on the left'); assert.ok( - plainBar120.includes('● 2 运行中 5.6s | 22.0 t/s | 余 ████⣿⣿⣿⣿ 54% | 上下文 █⢕⢕⢕⢕⢕⢕⢕ 2%'), - 'Keeps full 8-cell Braille bars and full chrome when 4 slots fit in 120 columns' + plainBar120.includes('● 2 运行中 5.6s | 22.0 t/s | 余 54% | 上下文 2% '), + 'Keeps compact pill gauges with right-aligned percentage and full chrome in 120 columns' ); assert.ok(plainBar120.endsWith(' auto · Gemini 4 Hydrogen · medium'), 'Renders deduplicated mode · model · effort on the right'); assert.equal(h.cliDisplayWidth(inlineBar120), 119, 'Fits cleanly within terminalWidth - 1 without wrapping'); - // Mid-width 115-column terminal steps down 8-cell bars to 5-cell bars before trimming chrome - const inlineBar115 = h.formatCliStatusLineCapsule( + // Compact 108-column terminal still fits full 3-column chrome AND pill gauges cleanly (saves ~12 cols over Braille bars) + const inlineBar108 = h.formatCliStatusLineCapsule( { hasTelemetry: true, runningCount: 2, @@ -2040,20 +2042,20 @@ test('provisions Antigravity CLI statusLine safely and renders live capsule from showMultiSession: true, language: 'zh-CN', color: true, - terminalWidth: 115, + terminalWidth: 108, cycleMode: 'auto', modelDisplayName: 'Gemini 4 Hydrogen (Medium)', modelEffort: 'medium', } ); - const plainBar115 = inlineBar115.replace(/\x1b\[[0-9;]*m/g, ''); - assert.ok(plainBar115.startsWith('? for shortcuts '), 'Keeps ? for shortcuts when stepping down to 5-cell bars'); + const plainBar108 = inlineBar108.replace(/\x1b\[[0-9;]*m/g, ''); + assert.ok(plainBar108.startsWith('? for shortcuts '), 'Keeps ? for shortcuts at 108 columns'); assert.ok( - plainBar115.includes('● 2 运行中 5.6s | 22.0 t/s | 余 ███⣿⣿ 54% | 上下文 █⢕⢕⢕⢕ 2%'), - 'Gracefully steps down 8-cell bars to 5-cell bars on 115-col terminal while keeping full chrome' + plainBar108.includes('● 2 运行中 5.6s | 22.0 t/s | 余 54% | 上下文 2% '), + 'Fits compact pill gauges and full chrome even at 108 columns' ); - assert.ok(plainBar115.endsWith(' auto · Gemini 4 Hydrogen · medium'), 'Keeps full right chrome on 115-col terminal'); - assert.equal(h.cliDisplayWidth(inlineBar115), 114, '115-col bar fits cleanly within terminalWidth - 1'); + assert.ok(plainBar108.endsWith(' auto · Gemini 4 Hydrogen · medium'), 'Keeps full right chrome at 108 columns'); + assert.equal(h.cliDisplayWidth(inlineBar108), 107, '108-col bar fits cleanly within terminalWidth - 1'); // Narrow 80-column terminal gracefully compacts without wrapping const inlineBar80 = h.formatCliStatusLineCapsule( @@ -2227,7 +2229,7 @@ test('provisions Antigravity CLI statusLine safely and renders live capsule from input: stdinPayload, encoding: 'utf8', }).trim(); - assert.equal(capsuleOut, '● 0 运行中 1.8s | 38.1 t/s | 余 █████⣿⣿⣿ 57% | 上下文 █⢕⢕⢕⢕⢕⢕⢕ 17%'); + assert.equal(capsuleOut, '● 0 运行中 1.8s | 38.1 t/s | 余 57% | 上下文 17%'); // Full 3-column single-line E2E with terminal_width + cycle_mode + model + native stdin quota fallback const emptySnapDir = join(tempRoot, 'empty-data'); @@ -2262,10 +2264,10 @@ test('provisions Antigravity CLI statusLine safely and renders live capsule from input: fullLineStdin, encoding: 'utf8', }).replace(/\r?\n$/, ''); - assert.equal(/\x1b\[48;/.test(fullLineOut), false, 'E2E ANSI output has zero background fill'); + assert.equal(/\x1b\[48;2;/.test(fullLineOut), true, 'E2E ANSI output renders 24-bit pill background fill'); const plainFullLine = fullLineOut.replace(/\x1b\[[0-9;]*m/g, ''); assert.ok(plainFullLine.startsWith('? for shortcuts ')); - assert.ok(plainFullLine.includes('● 1 运行中 1.8s | 38.1 t/s | 余 ████⣿⣿⣿⣿ 54% | 上下文 █⢕⢕⢕⢕⢕⢕⢕ 2%')); + assert.ok(plainFullLine.includes('● 1 运行中 1.8s | 38.1 t/s | 余 54% | 上下文 2% ')); assert.ok(plainFullLine.endsWith(' auto · Gemini 4 Hydrogen · medium')); assert.equal(h.cliDisplayWidth(fullLineOut), 129); @@ -2276,7 +2278,7 @@ test('provisions Antigravity CLI statusLine safely and renders live capsule from input: stdinPayload, encoding: 'utf8', }).trim(); - assert.equal(cmdCapsuleOut, '● 0 运行中 1.8s | 38.1 t/s | 余 █████⣿⣿⣿ 57% | 上下文 █⢕⢕⢕⢕⢕⢕⢕ 17%'); + assert.equal(cmdCapsuleOut, '● 0 运行中 1.8s | 38.1 t/s | 余 57% | 上下文 17%'); const spaceDir = join(tempRoot, 'Dir With Spaces'); mkdirSync(spaceDir, { recursive: true }); @@ -2292,7 +2294,7 @@ test('provisions Antigravity CLI statusLine safely and renders live capsule from input: stdinPayload, encoding: 'utf8', }).trim(); - assert.equal(autorunOut, '● 0 运行中 1.8s | 38.1 t/s | 余 █████⣿⣿⣿ 57% | 上下文 █⢕⢕⢕⢕⢕⢕⢕ 17%'); + assert.equal(autorunOut, '● 0 运行中 1.8s | 38.1 t/s | 余 57% | 上下文 17%'); } // Verify compaction-line precedence: when local trajectory reports maxContextTokens (e.g. 512k), @@ -2355,10 +2357,17 @@ test('provisions Antigravity CLI statusLine safely and renders live capsule from encoding: 'utf8', }).trim(); assert.ok( - limitOut.includes('上下文 ███████⢕ 92%'), + limitOut.includes('上下文 92%'), `expected compaction-limit 92% instead of physical 42%, got: ${limitOut}` ); assert.equal(limitOut.includes('42%'), false); + const limitAnsiOut = execFileSync(process.execPath, [statusLineScript], { + env: installEnv, + input: limitStdin, + encoding: 'utf8', + }).trim(); + assert.equal(/\x1b\[48;2;124;42;48m/.test(limitAnsiOut), true, '92% compaction limit uses danger crimson pill'); + assert.ok(limitAnsiOut.replace(/\x1b\[[0-9;]*m/g, '').includes(' 上下文 92% ')); // Verify real non-test.invalid buildTelemetryPayload writes cli-status-snapshot.json cleanly without throwing const builderUrl = new URL('../backend/telemetry-builder.mjs', import.meta.url).href; @@ -2508,9 +2517,9 @@ test('CLI statusLine v1.5.4 upgrades: /statusline inline flags, preserved manage color: false, } ); - assert.equal(freshBar, '● 0 运行中 空闲 | 余 ████████ 98% | 上下文 █⢕⢕⢕⢕⢕⢕⢕ 16%'); + assert.equal(freshBar, '● 0 运行中 空闲 | 余 98% | 上下文 16%'); - // 5b. Dedicated 5h / weekly / context 8-cell mini progress bars in zh-CN & en-US + // 5b. Dedicated 5h / weekly / context slots in NO_COLOR and pill ANSI modes (zh-CN & en-US) const quotaBarCtx = { hasTelemetry: true, stepCount: 3, @@ -2529,7 +2538,20 @@ test('CLI statusLine v1.5.4 upgrades: /statusline inline flags, preserved manage language: 'zh-CN', color: false, }), - 'G5h █████⣿⣿⣿ 64% | G周 ███████⣿ 88% | C5h ████████ 96% | C周 █⣿⣿⣿⣿⣿⣿⣿ 14% | 上下文 ████⢕⢕⢕⢕ 56%' + 'G5h 64% | G周 88% | C5h 96% | C周 14% | 上下文 56%' + ); + const quotaPillAnsi = h.formatCliStatusLineCapsule(quotaBarCtx, { + slots: ['gemini_5h', 'claude_weekly', 'context'], + showMultiSession: false, + language: 'zh-CN', + color: true, + }); + assert.equal(/\x1b\[48;2;24;96;68m/.test(quotaPillAnsi), true, '64% quota uses green pill fill'); + assert.equal(/\x1b\[48;2;124;42;48m/.test(quotaPillAnsi), true, '14% quota uses danger red pill fill'); + assert.equal(/\x1b\[48;2;36;72;128m/.test(quotaPillAnsi), true, '56% context uses blue pill fill'); + assert.equal( + quotaPillAnsi.replace(/\x1b\[[0-9;]*m/g, ''), + ' G5h 64% | C周 14% | 上下文 56% ' ); assert.equal( h.formatCliStatusLineCapsule(quotaBarCtx, { @@ -2538,7 +2560,7 @@ test('CLI statusLine v1.5.4 upgrades: /statusline inline flags, preserved manage language: 'en-US', color: false, }), - 'Gw ███████⣿ 88% | Cw █⣿⣿⣿⣿⣿⣿⣿ 14% | Ctx ████⢕⢕⢕⢕ 56%' + 'Gw 88% | Cw 14% | Ctx 56%' ); // 5c. Local SQLite WAITING step immediately turns CLI dot amber even while Desktop snapshot is still false @@ -2592,7 +2614,7 @@ test('CLI statusLine v1.5.4 upgrades: /statusline inline flags, preserved manage }); assert.equal(resumedFromLocalDb.hasWaiting, false); - // 6. Anomaly badge (toggleable via showAnomaly) + zero background SGR / OSC + // 6. Anomaly badge (toggleable via showAnomaly) + pill SGR & zero OSC const withAnom = h.formatCliStatusLineCapsule( { hasTelemetry: true, @@ -2609,9 +2631,9 @@ test('CLI statusLine v1.5.4 upgrades: /statusline inline flags, preserved manage color: true, } ); - assert.equal(/\x1b\[48;/.test(withAnom), false); + assert.equal(/\x1b\[48;2;36;72;128m/.test(withAnom), true); assert.equal(/\x1b\]/.test(withAnom), false); - assert.equal(withAnom.replace(/\x1b\[[0-9;]*m/g, ''), '● 1 运行中 44.2 t/s | 2.1s | 上下文 ███⢕⢕⢕⢕⢕ 35% | ! 503'); + assert.equal(withAnom.replace(/\x1b\[[0-9;]*m/g, ''), '● 1 运行中 44.2 t/s | 2.1s | 上下文 35% | ! 503'); const withoutAnom = h.formatCliStatusLineCapsule( { @@ -2630,7 +2652,7 @@ test('CLI statusLine v1.5.4 upgrades: /statusline inline flags, preserved manage color: false, } ); - assert.equal(withoutAnom, '● 1 运行中 44.2 t/s | 2.1s | 上下文 ███⢕⢕⢕⢕⢕ 35%'); + assert.equal(withoutAnom, '● 1 运行中 44.2 t/s | 2.1s | 上下文 35%'); // 7. Narrow 72-column terminal progressively sheds lower-priority slots without wrapping const narrow72 = h.formatCliStatusLineCapsule( @@ -2707,7 +2729,7 @@ test('CLI statusLine v1.5.4 upgrades: /statusline inline flags, preserved manage encoding: 'utf8', } ).trim(); - assert.equal(inlineOut, 'Idle | 5h ███████⣿ 91% | Ctx ██⢕⢕⢕⢕⢕⢕ 19%'); + assert.equal(inlineOut, 'Idle | 5h 91% | Ctx 19%'); // 9. Runtime CLI installation & status detection (strictly gated on antigravity-cli dir) + forceReplaceCustom recovery const { ensureCliStatusLineConfigured, getCliStatusLineRuntimeStatus } = await import( diff --git a/sidecars/panel/test/window-bridge.test.mjs b/sidecars/panel/test/window-bridge.test.mjs index ff137f4..b1742b7 100644 --- a/sidecars/panel/test/window-bridge.test.mjs +++ b/sidecars/panel/test/window-bridge.test.mjs @@ -5927,9 +5927,13 @@ test('SettingsStructureTab CLI statusLine controls stay hidden unless CLI is det .querySelectorAll('.cli-preview-slot') .filter((el) => !el.hasAttribute('hidden')) .map((el) => el.textContent); - assert.deepEqual(visibleSlots(), ['68.4 t/s', '1.1s', '$0.42', '余 █████⣿⣿⣿ 64%', '上下文 ████⢕⢕⢕⢕ 56%']); + assert.deepEqual(visibleSlots(), ['68.4 t/s', '1.1s', '$0.42', '余 64%', '上下文 56%']); + const pillSlots1 = previewEl + .querySelectorAll('.cli-preview-slot.is-pill') + .filter((el) => !el.hasAttribute('hidden')); + assert.equal(pillSlots1.length, 2, 'Quota and context slots render as background-filled pills'); - // 3. Dedicated 5h / weekly / context slots render distinct mini progress bars in live preview + // 3. Dedicated 5h / weekly / context slots render distinct pill gauges in live preview strTab.refs.renderSettings( { enableCliStatusLine: true, @@ -5940,12 +5944,16 @@ test('SettingsStructureTab CLI statusLine controls stay hidden unless CLI is det { installed: true, configured: true, preservedCustom: false, managedFlags: '' } ); assert.deepEqual(visibleSlots(), [ - 'G5h █████⣿⣿⣿ 64%', - 'G周 ███████⣿ 88%', - 'C5h ████████ 96%', - 'C周 ████████ 99%', - '上下文 ████⢕⢕⢕⢕ 56%', + 'G5h 64%', + 'G周 88%', + 'C5h 96%', + 'C周 99%', + '上下文 56%', ]); + const pillSlots2 = previewEl + .querySelectorAll('.cli-preview-slot.is-pill') + .filter((el) => !el.hasAttribute('hidden')); + assert.equal(pillSlots2.length, 5); // 4. Turning CLI statusLine off collapses detail panel strTab.refs.renderSettings(