feat(cli): upgrade statusLine with Braille progress bars, instant waiting sync, /statusline flags, and CLI-gated settings

This commit is contained in:
fish
2026-11-21 21:44:32 +09:00
parent 71fc7d5279
commit 3eb9e0e2a5
20 changed files with 2690 additions and 111 deletions
+50 -1
View File
@@ -63,7 +63,10 @@ import {
resolveDevToolsPortCandidates,
startDefaultWindowBridge,
} from './window-bridge.mjs';
import { ensureCliStatusLineConfigured } from './cli-statusline-config.mjs';
import {
ensureCliStatusLineConfigured,
getCliStatusLineRuntimeStatus,
} from './cli-statusline-config.mjs';
export const bootBundleVersion = computeRuntimeCodeVersion();
@@ -632,6 +635,49 @@ export async function executeBridgeRelaunchAction() {
};
}
export function executeCliStatusLineAction(rawAction) {
const action = String(rawAction || '').trim();
if (action !== 'force_install' && action !== 'clear_flags') {
return {
status: 400,
contentType: 'application/json',
headers: { 'Cache-Control': 'no-store' },
body: JSON.stringify({ ok: false, error: 'Unsupported CLI statusLine action' }),
};
}
let current = loadSettings();
if (action === 'force_install' && current.enableCliStatusLine === false) {
const nextSettings = normalizeFullSettings({
...current,
enableCliStatusLine: true,
});
if (saveJson(SETTINGS_FILE, nextSettings)) {
current = nextSettings;
}
}
const result = ensureCliStatusLineConfigured({
enabled: true,
forceReplaceCustom: action === 'force_install',
preserveManagedFlags: false,
});
const cliStatusLine = getCliStatusLineRuntimeStatus();
const ok = Boolean(result?.updated || result?.alreadyConfigured || cliStatusLine.configured);
return {
status: ok ? 200 : 500,
contentType: 'application/json',
headers: { 'Cache-Control': 'no-store' },
body: JSON.stringify({
ok,
action,
result,
cliStatusLine,
settings: current,
}),
};
}
const BRIDGE_ROUTE_LOOKUP = new Map(
BRIDGE_API_ROUTE_DEFS.map((r) => [`${r.method}:${r.path}`, r.action])
);
@@ -645,6 +691,9 @@ export async function dispatchBridgeApiRequest(pathname, method, data, opts = un
if (isPlainObject(data) && data.__bridgeAction === 'relaunch') {
return executeBridgeRelaunchAction();
}
if (isPlainObject(data) && typeof data.__cliStatusLineAction === 'string') {
return executeCliStatusLineAction(data.__cliStatusLineAction);
}
return executeSettingsAction(data);
case 'accounts_get':
return executeAccountCredentialAction(undefined, opts);
+412 -58
View File
@@ -15,7 +15,13 @@ import { existsSync, readFileSync, renameSync, unlinkSync, writeFileSync } from
import { homedir } from 'node:os';
import { delimiter, dirname, join } from 'node:path';
import { pathToFileURL } from 'node:url';
import { HERE, lsRuntimeEndpoint, normalizeLanguageSetting, normalizeTopbarCapsuleSlots } from './config.mjs';
import {
HERE,
lsRuntimeEndpoint,
normalizeCliStatusLineSlots,
normalizeLanguageSetting,
normalizeTopbarCapsuleSlots,
} from './config.mjs';
import {
classifyCacheTier,
classifySpeedTier,
@@ -35,9 +41,10 @@ const SGR_FG_NORMAL = '\x1b[38;2;203;213;225m';
const SGR_FG_MUTED = '\x1b[38;2;148;163;184m';
const SGR_FG_DIM = '\x1b[38;2;120;133;155m';
const SGR_FG_CHROME = '\x1b[38;2;136;142;150m';
const SGR_FG_SEP = '\x1b[38;2;90;100;116m';
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';
@@ -149,24 +156,29 @@ export function buildCliStatusLineCommand(
platform = process.platform,
execPath = process.execPath,
nodeOnPath = true,
extraFlags = '',
} = {}
) {
const normScript = String(scriptPath || '').trim().replace(/\\/g, '/');
const cleanFlags = String(extraFlags || '').trim().replace(/"/g, '');
if (platform === 'win32') {
const normExec = String(execPath || 'node').trim().replace(/\\/g, '/');
const runner = nodeOnPath || /\s/.test(normExec) ? 'node' : normExec;
if (!/\s/.test(normScript)) {
return `${runner} ${normScript}`;
return cleanFlags ? `${runner} ${normScript} ${cleanFlags}` : `${runner} ${normScript}`;
}
const fileUrl = toPercentEncodedFileUrl(normScript).replace(/'/g, '%27');
return `${runner} --input-type=module -e import('${fileUrl}')`;
const base = `${runner} --input-type=module -e import('${fileUrl}')`;
return cleanFlags ? `${base} -- ${cleanFlags}` : base;
}
if (nodeOnPath) {
return `node "${normScript.replace(/"/g, '\\"')}"`;
const base = `node "${normScript.replace(/"/g, '\\"')}"`;
return cleanFlags ? `${base} ${cleanFlags}` : base;
}
const escapedExec = String(execPath || 'node').replace(/"/g, '\\"');
const escapedScript = normScript.replace(/"/g, '\\"');
return `"${escapedExec}" "${escapedScript}"`;
const base = `"${escapedExec}" "${escapedScript}"`;
return cleanFlags ? `${base} ${cleanFlags}` : base;
}
/**
@@ -183,21 +195,107 @@ export function isManagedCliStatusLineCommand(cmd) {
}
/**
* 在纯对象层面更新或移除本插件托管的 `statusLine` 配置,绝不覆盖用户自定义的第三方脚本。
* 提取用户通过 `/statusline` 追加在托管命令末尾的参数(如 `--slots tps,cost,context --no-multi`)。
*
* @param {unknown} cmd
* @returns {string}
*/
export function extractManagedCliStatusLineFlags(cmd) {
if (!isManagedCliStatusLineCommand(cmd)) return '';
const trimmed = String(cmd || '').trim();
const m = trimmed.match(/cli-statusline\.mjs(?:#autorun)?(?:["')]+)?\s+(--[\s\S]+)$/i);
if (!m) return '';
return m[1].replace(/^--\s+/, '').trim();
}
/**
* 探测本机是否已安装并初始化 Antigravity CLI(`~/.gemini/antigravity-cli`),
* 及当前 CLI `settings.json` 中的 `statusLine` 托管状态(零子进程、纯本地文件探测)。
*
* @param {{ env?: Record<string, string|undefined>, homeDir?: string }} [options]
* @returns {{ installed: boolean, configured: boolean, preservedCustom: boolean, managedFlags: string }}
*/
export function getCliStatusLineRuntimeStatus({
env = process.env,
homeDir = homedir(),
} = {}) {
const settingsPath = resolveCliSettingsPath(env, homeDir);
const cliDir = dirname(settingsPath);
let installed = false;
try {
installed = existsSync(cliDir);
} catch {
installed = false;
}
if (!installed) {
return {
installed: false,
configured: false,
preservedCustom: false,
managedFlags: '',
};
}
let configured = false;
let preservedCustom = false;
let managedFlags = '';
try {
if (existsSync(settingsPath)) {
const raw = readFileSync(settingsPath, 'utf8').replace(/^\uFEFF/, '').trim();
if (raw) {
const parsed = JSON.parse(raw);
const sl = parsed?.statusLine;
if (isCliStatusPlainObject(sl)) {
const cmd = typeof sl.command === 'string' ? sl.command.trim() : '';
if (cmd) {
if (isManagedCliStatusLineCommand(cmd)) {
configured = sl.enabled !== false;
managedFlags = extractManagedCliStatusLineFlags(cmd);
} else {
preservedCustom = true;
}
}
} else if (sl !== undefined && sl !== null) {
preservedCustom = true;
}
}
}
} catch {
// 忽略损坏或无权限读取的 CLI settings.json
}
return {
installed: true,
configured,
preservedCustom,
managedFlags,
};
}
/**
* 在纯对象层面更新或移除本插件托管的 `statusLine` 配置,绝不覆盖用户自定义的第三方脚本,
* 并在未显式覆盖参数时保留用户在 `/statusline` 命令末尾附加的定制参数。
*
* @param {unknown} rawObj
* @param {{ enabled?: boolean, command?: string, stackWithDefault?: boolean }} [options]
* @param {{ enabled?: boolean, command?: string, stackWithDefault?: boolean, preserveManagedFlags?: boolean }} [options]
*/
export function applyCliStatusLineToSettingsObject(
rawObj,
{ enabled = true, command = '', stackWithDefault = false } = {}
{
enabled = true,
command = '',
stackWithDefault = false,
preserveManagedFlags = true,
forceReplaceCustom = false,
} = {}
) {
const baseObj = isCliStatusPlainObject(rawObj) ? rawObj : {};
const existing = baseObj.statusLine;
let existingCmd = '';
if (isCliStatusPlainObject(existing)) {
const existingCmd = typeof existing.command === 'string' ? existing.command.trim() : '';
if (existingCmd && !isManagedCliStatusLineCommand(existingCmd)) {
existingCmd = typeof existing.command === 'string' ? existing.command.trim() : '';
if (existingCmd && !isManagedCliStatusLineCommand(existingCmd) && !forceReplaceCustom) {
return {
changed: false,
preservedCustom: true,
@@ -205,7 +303,7 @@ export function applyCliStatusLineToSettingsObject(
object: baseObj,
};
}
} else if (existing !== undefined && existing !== null) {
} else if (existing !== undefined && existing !== null && !forceReplaceCustom) {
return {
changed: false,
preservedCustom: true,
@@ -231,7 +329,7 @@ export function applyCliStatusLineToSettingsObject(
};
}
const cleanCmd = String(command || '').trim();
let cleanCmd = String(command || '').trim();
if (!cleanCmd) {
return {
changed: false,
@@ -239,6 +337,13 @@ export function applyCliStatusLineToSettingsObject(
object: baseObj,
};
}
if (preserveManagedFlags && !extractManagedCliStatusLineFlags(cleanCmd)) {
const prevFlags = extractManagedCliStatusLineFlags(existingCmd);
if (prevFlags) {
const isAutorun = cleanCmd.includes('--input-type=module -e import(');
cleanCmd = isAutorun ? `${cleanCmd} -- ${prevFlags}` : `${cleanCmd} ${prevFlags}`;
}
}
const prevBlock = isCliStatusPlainObject(existing) ? existing : {};
const desiredPadding =
@@ -301,6 +406,9 @@ export function ensureCliStatusLineConfigured({
platform = process.platform,
execPath = process.execPath,
nodeOnPath,
extraFlags = '',
preserveManagedFlags = true,
forceReplaceCustom = false,
} = {}) {
if (
lsRuntimeEndpoint.addr === 'test.invalid' &&
@@ -346,9 +454,15 @@ export function ensureCliStatusLineConfigured({
platform,
execPath,
nodeOnPath: hasNodePath,
extraFlags,
});
const applied = applyCliStatusLineToSettingsObject(currentObj, { enabled, command });
const applied = applyCliStatusLineToSettingsObject(currentObj, {
enabled,
command,
preserveManagedFlags: extraFlags ? false : preserveManagedFlags,
forceReplaceCustom,
});
if (!applied.changed) {
return {
checked: true,
@@ -577,28 +691,68 @@ function cliComposeBalancedThreeColumn(leftStr, centerStr, rightStr, maxWidth) {
return cw <= maxWidth ? centerStr : '';
}
function cliBuildMiniProgressBar(
pct,
{ width = 8, fillSgr = SGR_FG_TEAL, emptyChar = '⢕', useColor = true } = {}
) {
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 fillPart = filledStr ? `${fillSgr}${filledStr}` : '';
const emptyPart = emptyStr ? `${SGR_FG_DIM}${emptyStr}` : '';
return `${fillPart}${emptyPart}${SGR_RESET}`;
}
function cliResolveQuotaSlotPrefix(metricKey, isEn) {
if (metricKey === 'gemini_5h') return 'G5h';
if (metricKey === 'gemini_weekly') return isEn ? 'Gw' : 'G周';
if (metricKey === 'claude_5h') return 'C5h';
if (metricKey === 'claude_weekly') return isEn ? 'Cw' : 'C周';
return isEn ? '5h' : '余';
}
/**
* 将单槽位指标格式化为纯文本与无背景前景语义 SGR 片段。
* 将单槽位指标格式化为纯文本及无背景前景语义 SGR 片段。
*/
function cliRenderSingleSlot(metricKey, slotCtx, { isEn = false, useColor = true, slotSet } = {}) {
function cliRenderSingleSlot(
metricKey,
slotCtx,
{ isEn = false, useColor = true, slotSet, barWidth = 8 } = {}
) {
const hasTelemetry = slotCtx.hasTelemetry !== false;
if (metricKey === 'context') {
const valid = hasTelemetry && slotCtx.usedPct != null && Number.isFinite(Number(slotCtx.usedPct));
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 `◎ ${textVal}`;
}
const isDanger = pctNum != null && pctNum >= 88;
const isWarn = !isDanger && pctNum != null && pctNum >= 70;
const ringColor = isDanger
const isMid = !isDanger && !isWarn && pctNum != null && pctNum >= 50;
const barColor = isDanger
? SGR_FG_DANGER
: isWarn
? SGR_FG_WARN
: pctNum != null
: isMid
? SGR_FG_ACCENT
: SGR_FG_MUTED;
: 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}`;
}
const valColor = isDanger
? `${SGR_BOLD}${SGR_FG_DANGER}`
: isWarn
@@ -606,7 +760,7 @@ function cliRenderSingleSlot(metricKey, slotCtx, { isEn = false, useColor = true
: pctNum != null
? `${SGR_BOLD}${SGR_FG_BRIGHT}`
: SGR_FG_MUTED;
return `${ringColor}◎ ${valColor}${textVal}${SGR_RESET}`;
return `${SGR_FG_MUTED}${label} ${barSegment}${valColor}${textVal}${SGR_RESET}`;
}
if (metricKey === 'tps') {
@@ -697,23 +851,52 @@ function cliRenderSingleSlot(metricKey, slotCtx, { isEn = false, useColor = true
}
const quotaPct = hasTelemetry ? cliResolveQuotaPct(slotCtx.quotas, metricKey) : null;
const textVal =
quotaPct != null
? isEn
? `${quotaPct}% left`
: `余 ${quotaPct}%`
: isEn
? 'Quota --'
: '余 --%';
if (!useColor) return textVal;
const prefix = cliResolveQuotaSlotPrefix(metricKey, isEn);
const isDanger = quotaPct != null && quotaPct <= 15;
const isWarn = !isDanger && quotaPct != null && quotaPct <= 30;
const color = isDanger
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}`
: SGR_FG_MUTED;
return `${color}${textVal}${SGR_RESET}`;
: quotaPct != null
? SGR_FG_NORMAL
: SGR_FG_MUTED;
if (quotaPct == null) {
const emptyText =
metricKey === 'quota_auto' && isEn ? 'Quota --' : `${prefix} --%`;
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}`;
}
const compactText =
metricKey === 'quota_auto'
? isEn
? `${quotaPct}% left`
: `余 ${quotaPct}%`
: `${prefix} ${quotaPct}%`;
if (!useColor) return compactText;
return `${pctSgr}${compactText}${SGR_RESET}`;
}
/**
@@ -767,13 +950,128 @@ function detectCliHostLanguageIsEn() {
return false;
}
const CLI_STATUS_SLOT_KEEP_PRIORITY = Object.freeze({
context: 100,
tps: 90,
quota_auto: 80,
gemini_5h: 78,
claude_5h: 76,
ttft: 70,
session_cost: 60,
cost: 58,
cache_hit: 50,
avg_tps: 45,
session_tokens: 40,
gemini_weekly: 35,
claude_weekly: 30,
});
function cliStatusHasRenderableValue(metricKey, slotCtx) {
if (slotCtx.hasTelemetry === false) return false;
if (metricKey === 'context') {
return slotCtx.usedPct != null && Number.isFinite(Number(slotCtx.usedPct));
}
if (metricKey === 'tps') {
return Number.isFinite(Number(slotCtx.tps)) && Number(slotCtx.tps) > 0;
}
if (metricKey === 'avg_tps') {
return Number.isFinite(Number(slotCtx.avgTps)) && Number(slotCtx.avgTps) > 0;
}
if (metricKey === 'ttft') {
return (
slotCtx.ttft != null &&
Number.isFinite(Number(slotCtx.ttft)) &&
Number(slotCtx.ttft) >= 0
);
}
if (metricKey === 'cost') {
return slotCtx.stepCost != null && Number.isFinite(Number(slotCtx.stepCost));
}
if (metricKey === 'session_cost') {
return slotCtx.sessionCost != null && Number.isFinite(Number(slotCtx.sessionCost));
}
if (metricKey === 'cache_hit') {
return slotCtx.cacheHitPct != null && Number.isFinite(Number(slotCtx.cacheHitPct));
}
if (metricKey === 'session_tokens') {
return (
slotCtx.sessionTokens != null &&
Number.isFinite(Number(slotCtx.sessionTokens)) &&
Number(slotCtx.sessionTokens) >= 0
);
}
return cliResolveQuotaPct(slotCtx.quotas, metricKey) != null;
}
function cliStatusFormatAnomalyTag(anomaly, { isEn = false, useColor = true } = {}) {
if (!anomaly || !(Number(anomaly.count) > 0)) return '';
const n = Math.max(1, Math.floor(Number(anomaly.count) || 1));
const kind = String(anomaly.primaryKind || 'error');
let label = '';
if (isEn) {
if (kind === 'capacity') label = n === 1 ? '503' : `503x${n}`;
else if (kind === 'upstream') label = n === 1 ? '500' : `500x${n}`;
else if (kind === 'rate_limit') label = `429x${n}`;
else if (kind === 'timeout') label = `TO${n}`;
else if (kind === 'disconnect') label = `Drop${n}`;
else if (kind === 'model_output') label = `Fix${n}`;
else if (kind === 'safety') label = `Safe${n}`;
else if (kind === 'mixed') label = `Warn${n}`;
else label = `Err${n}`;
} else {
if (kind === 'capacity') label = n === 1 ? '503' : `503×${n}`;
else if (kind === 'upstream') label = n === 1 ? '500' : `500×${n}`;
else if (kind === 'rate_limit') label = `限流${n}`;
else if (kind === 'timeout') label = `超时${n}`;
else if (kind === 'disconnect') label = `断连${n}`;
else if (kind === 'model_output') label = `纠偏${n}`;
else if (kind === 'safety') label = `过滤${n}`;
else if (kind === 'auth_or_model') label = `受限${n}`;
else if (kind === 'mixed') label = `异常${n}`;
else label = `报错${n}`;
}
const plain = `! ${label}`;
if (!useColor) return plain;
const color =
anomaly.severity === 'danger' || kind === 'rate_limit' || kind === 'auth_or_model'
? `${SGR_BOLD}${SGR_FG_DANGER}`
: `${SGR_BOLD}${SGR_FG_WARN}`;
return `${color}${plain}${SGR_RESET}`;
}
function cliStatusShedLowestPrioritySlot(slotKeys) {
if (!Array.isArray(slotKeys) || slotKeys.length <= 1) return slotKeys;
let dropIdx = slotKeys.length - 1;
let lowestPrio = Infinity;
for (let i = 0; i < slotKeys.length; i += 1) {
const prio = CLI_STATUS_SLOT_KEEP_PRIORITY[slotKeys[i]] ?? 50;
if (prio <= lowestPrio) {
lowestPrio = prio;
dropIdx = i;
}
}
return slotKeys.filter((_, idx) => idx !== dropIdx);
}
export function formatCliStatusLineCapsule(slotCtx = {}, options = {}) {
const slots = normalizeTopbarCapsuleSlots(options.slots);
const normalizedCliSlots = normalizeCliStatusLineSlots(options.slots);
const rawSlots = normalizedCliSlots || normalizeTopbarCapsuleSlots(options.slots);
const showMulti = options.showMultiSession !== false;
const showAnomaly = options.showAnomaly !== false;
const normLang = normalizeLanguageSetting(options.language);
const isEn = normLang === 'auto' ? detectCliHostLanguageIsEn() : normLang === 'en-US';
const useColor = options.color !== false;
const slotSet = new Set(slots);
// 新会话尚无任何完成步骤(stepCount === 0)时,隐藏纯占位性的 "--s" / "--" 槽位,避免刚启动显得满屏缺数据
let activeSlots = rawSlots;
if (slotCtx.stepCount === 0) {
const filtered = rawSlots.filter(
(key) => key === 'tps' || cliStatusHasRenderableValue(key, slotCtx)
);
if (filtered.length > 0) {
activeSlots = filtered;
}
}
const runningCount = Math.max(0, Math.floor(Number(slotCtx.runningCount) || 0));
const runningSubCount = Math.max(0, Math.floor(Number(slotCtx.runningSubCount) || 0));
@@ -807,21 +1105,37 @@ export function formatCliStatusLineCapsule(slotCtx = {}, options = {}) {
}
}
const renderedSlots = slots.map((key) =>
cliRenderSingleSlot(key, slotCtx, { isEn, useColor, slotSet })
);
const sep = useColor ? `${SGR_FG_SEP} | ${SGR_RESET}` : ' | ';
const slotsBody = renderedSlots.join(sep);
const fullCapsule = multiCore ? `${multiCore} ${slotsBody}` : slotsBody;
const anomalyBadge = showAnomaly
? cliStatusFormatAnomalyTag(slotCtx.latestAnomaly, { isEn, useColor })
: '';
const defaultBarWidth = options.showProgressBars === false ? 0 : 8;
const buildCapsulesForSlots = (slotList, includeAnomaly = true, barWidth = defaultBarWidth) => {
const slotSet = new Set(slotList);
const rendered = slotList.map((key) =>
cliRenderSingleSlot(key, slotCtx, { isEn, useColor, slotSet, barWidth })
);
if (includeAnomaly && anomalyBadge) {
rendered.push(anomalyBadge);
}
const body = rendered.join(sep);
return {
slotsBody: body,
fullCapsule: multiCore ? `${multiCore} ${body}` : body,
compactCapsule: multiCore ? `${multiCore} ${body}` : body,
};
};
const baseCapsules = buildCapsulesForSlots(activeSlots, true, defaultBarWidth);
const rawWidth = Number(options.terminalWidth);
if (!Number.isFinite(rawWidth) || rawWidth <= 0) {
return fullCapsule;
return baseCapsules.fullCapsule;
}
// 预留右侧 1 列安全边距,与 `agy` 原生底栏右边缘对齐并避免 Windows `conhost`/`cmd.exe` 末列自动折行
// 预留右侧 1 列安全边距,和 `agy` 原生底栏右边缘对齐并避免 Windows `conhost`/`cmd.exe` 末列自动折行
const maxWidth = Math.max(1, Math.floor(rawWidth) - 1);
const compactCapsule = multiCore ? `${multiCore} ${slotsBody}` : slotsBody;
const fullLeft = cliBuildLeftSegment({ vimMode: options.vimMode, short: false, useColor });
const shortLeft = cliBuildLeftSegment({ vimMode: '', short: true, useColor });
const fullRight = cliBuildRightSegment({
@@ -839,20 +1153,60 @@ export function formatCliStatusLineCapsule(slotCtx = {}, options = {}) {
useColor,
});
const tier1 = cliComposeBalancedThreeColumn(fullLeft, fullCapsule, fullRight, maxWidth);
if (tier1) return tier1;
const tryCompose = (cap) =>
cliComposeBalancedThreeColumn(fullLeft, cap.fullCapsule, fullRight, maxWidth) ||
cliComposeBalancedThreeColumn(shortLeft, cap.fullCapsule, fullRight, maxWidth) ||
cliComposeBalancedThreeColumn(shortLeft, cap.compactCapsule, compactRight, maxWidth) ||
cliComposeBalancedThreeColumn('', cap.compactCapsule, compactRight, maxWidth);
const tier2 = cliComposeBalancedThreeColumn(shortLeft, fullCapsule, fullRight, maxWidth);
if (tier2) return tier2;
const fullPrimary = cliComposeBalancedThreeColumn(
fullLeft,
baseCapsules.fullCapsule,
fullRight,
maxWidth
);
if (fullPrimary) return fullPrimary;
const tier3 = cliComposeBalancedThreeColumn(shortLeft, compactCapsule, compactRight, maxWidth);
if (tier3) return tier3;
const tier4 = cliComposeBalancedThreeColumn('', compactCapsule, compactRight, maxWidth);
if (tier4) return tier4;
if (cliDisplayWidth(fullCapsule) <= maxWidth) {
return fullCapsule;
// 中等终端优先把进度条从 8 格微缩至 5 格以保住左右完整原生提示,再逐级收缩左右栏和槽位
if (defaultBarWidth > 5) {
const compactBarCapsules = buildCapsulesForSlots(activeSlots, true, 5);
const fullCompactBar = cliComposeBalancedThreeColumn(
fullLeft,
compactBarCapsules.fullCapsule,
fullRight,
maxWidth
);
if (fullCompactBar) return fullCompactBar;
}
return slotsBody;
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;
}
let reducedSlots = [...activeSlots];
while (reducedSlots.length > 1) {
reducedSlots = cliStatusShedLowestPrioritySlot(reducedSlots);
const reducedCap = buildCapsulesForSlots(reducedSlots, true, 0);
const composed = tryCompose(reducedCap);
if (composed) return composed;
}
if (cliDisplayWidth(baseCapsules.fullCapsule) <= maxWidth) {
return baseCapsules.fullCapsule;
}
const minimalCap = buildCapsulesForSlots(reducedSlots, false, 0);
if (cliDisplayWidth(minimalCap.fullCapsule) <= maxWidth) {
return minimalCap.fullCapsule;
}
return minimalCap.slotsBody;
}
+6
View File
@@ -17,6 +17,8 @@ import { writeTrajectoryCacheFile } from './trajectory-cache-file.mjs';
import { normalizeFullSettings } from './settings-schema.mjs';
export {
CLI_STATUSLINE_PRESETS,
DEFAULT_CLI_STATUSLINE_SLOTS,
DEFAULT_HOVER_MODULES,
DEFAULT_OVERVIEW_METRICS,
DEFAULT_OVERVIEW_MODULES,
@@ -26,8 +28,10 @@ export {
DEFAULT_STEP_TOKEN_COMBO_FORMAT,
DEFAULT_TOPBAR_SLOTS,
FONT_SCALE_KEYS,
MAX_CLI_STATUSLINE_SLOTS,
MAX_POPOVER_WIDTH,
MAX_TOPBAR_SLOTS,
MIN_CLI_STATUSLINE_SLOTS,
MIN_POPOVER_WIDTH,
MIN_TOPBAR_SLOTS,
OVERVIEW_METRIC_KEYS,
@@ -37,6 +41,7 @@ export {
THEME_ACCENT_KEYS,
TOPBAR_SLOT_KEYS,
createDefaultSettingsObject,
normalizeCliStatusLineSlots,
normalizeFontScale,
normalizeFullSettings,
normalizeHoverModules,
@@ -57,6 +62,7 @@ export {
normalizeWeeklyLimitMode,
normalizeWindowMountMode,
parseStepTokenComboSegments,
resolveEffectiveCliStatusLineSlots,
} from './settings-schema.mjs';
/**
@@ -6,6 +6,8 @@
import { isContextWindowSettingId, isContextWindowOption } from './context-windows.mjs';
import {
CLI_STATUSLINE_PRESETS,
DEFAULT_CLI_STATUSLINE_SLOTS,
DEFAULT_HOVER_MODULES,
DEFAULT_OVERVIEW_METRICS,
DEFAULT_OVERVIEW_MODULES,
@@ -14,8 +16,10 @@ import {
DEFAULT_STEP_TOKEN_COMBO_FORMAT,
DEFAULT_TOPBAR_SLOTS,
FONT_SCALE_KEYS,
MAX_CLI_STATUSLINE_SLOTS,
MAX_POPOVER_WIDTH,
MAX_TOPBAR_SLOTS,
MIN_CLI_STATUSLINE_SLOTS,
MIN_POPOVER_WIDTH,
MIN_TOPBAR_SLOTS,
OVERVIEW_METRIC_KEYS,
@@ -26,6 +30,7 @@ import {
SUPPORTED_LANGUAGES,
THEME_ACCENT_KEYS,
TOPBAR_SLOT_KEYS,
normalizeCliStatusLineSlots,
normalizeExperimentalModernUi,
normalizeFontScale,
normalizeHoverModules,
@@ -46,9 +51,12 @@ import {
normalizeWeeklyLimitMode,
normalizeWindowMountMode,
parseStepTokenComboSegments,
resolveEffectiveCliStatusLineSlots,
} from '../shared/settings-normalization.mjs';
export {
CLI_STATUSLINE_PRESETS,
DEFAULT_CLI_STATUSLINE_SLOTS,
DEFAULT_HOVER_MODULES,
DEFAULT_OVERVIEW_METRICS,
DEFAULT_OVERVIEW_MODULES,
@@ -57,8 +65,10 @@ export {
DEFAULT_STEP_TOKEN_COMBO_FORMAT,
DEFAULT_TOPBAR_SLOTS,
FONT_SCALE_KEYS,
MAX_CLI_STATUSLINE_SLOTS,
MAX_POPOVER_WIDTH,
MAX_TOPBAR_SLOTS,
MIN_CLI_STATUSLINE_SLOTS,
MIN_POPOVER_WIDTH,
MIN_TOPBAR_SLOTS,
OVERVIEW_METRIC_KEYS,
@@ -69,6 +79,7 @@ export {
SUPPORTED_LANGUAGES,
THEME_ACCENT_KEYS,
TOPBAR_SLOT_KEYS,
normalizeCliStatusLineSlots,
normalizeExperimentalModernUi,
normalizeFontScale,
normalizeHoverModules,
@@ -89,6 +100,7 @@ export {
normalizeWeeklyLimitMode,
normalizeWindowMountMode,
parseStepTokenComboSegments,
resolveEffectiveCliStatusLineSlots,
};
function isSchemaPlainObject(v) {
@@ -127,6 +139,7 @@ export const DEFAULT_SETTINGS_SCHEMA = Object.freeze({
popoverWidthMode: 'auto',
popoverWidth: DEFAULT_POPOVER_WIDTH,
enableCliStatusLine: true,
cliStatusLineSlots: null,
standalonePort: 0,
showTopbarMultiSession: true,
topbarCapsuleSlots: DEFAULT_TOPBAR_SLOTS,
@@ -203,6 +216,7 @@ export function normalizeFullSettings(rawInput) {
popoverWidthMode: normalizePopoverWidthMode(safeRaw.popoverWidthMode),
popoverWidth: normalizePopoverWidth(safeRaw.popoverWidth),
enableCliStatusLine: safeRaw.enableCliStatusLine !== false,
cliStatusLineSlots: normalizeCliStatusLineSlots(safeRaw.cliStatusLineSlots),
standalonePort: normalizeStandalonePort(safeRaw.standalonePort),
showTopbarMultiSession: safeRaw.showTopbarMultiSession !== false,
topbarCapsuleSlots: normalizeTopbarCapsuleSlots(safeRaw.topbarCapsuleSlots),
+34 -1
View File
@@ -31,6 +31,7 @@ import {
} from './config.mjs';
import { getEndpointCacheStore } from './endpoint-registry.mjs';
import { getContextWindowGroups, getContextWindowModels } from './context-windows.mjs';
import { getCliStatusLineRuntimeStatus } from './cli-statusline-config.mjs';
import { readLocalSummarySnapshot } from './cli-sqlite-reader.mjs';
import { enumerateAndSyncConversations } from './local-scanner.mjs';
import { ensureLsEndpointDiscovered } from './ls-discovery.mjs';
@@ -2073,6 +2074,7 @@ export async function buildTelemetryPayloadInternal(
},
uiBundleVersion,
windowBridge: getDefaultWindowBridgeStatus(),
cliStatusLine: getCliStatusLineRuntimeStatus(),
settings: loadSettings(),
contextWindowModels: getContextWindowGroups(getContextWindowModels(clientConfigs, contextModelCatalog)).map((group) => {
const latest = group.members.reduce((previous, id) => {
@@ -2477,6 +2479,34 @@ export function buildCliStatusSnapshot(finalPayload, updatedAtMs = Date.now()) {
const runningList = Array.isArray(finalPayload?.runningConversations)
? finalPayload.runningConversations
: [];
const activeSteps = Array.isArray(ac.recentSteps) ? ac.recentSteps : [];
let sessionAnomalyCount = 0;
let latestAnomaly = null;
for (let i = 0; i < activeSteps.length; i += 1) {
const a = activeSteps[i]?.anomaly;
if (a && Number(a.count) > 0) {
sessionAnomalyCount += Number(a.count);
}
}
const lastStepAnomaly = activeSteps.length > 0 ? activeSteps[activeSteps.length - 1]?.anomaly : null;
if (lastStepAnomaly && Number(lastStepAnomaly.count) > 0) {
latestAnomaly = {
primaryKind: String(lastStepAnomaly.primaryKind || 'error'),
count: Number(lastStepAnomaly.count),
severity: lastStepAnomaly.severity === 'danger' ? 'danger' : 'warn',
totalDelaySec: Number(lastStepAnomaly.totalDelaySec || 0),
};
}
const waitingCascadeIds = runningList
.filter(
(item) =>
item?.mainActivity?.phase === 'waiting' ||
(Array.isArray(item?.subagents) &&
item.subagents.some((sub) => sub?.isRunning && sub?.liveActivity?.phase === 'waiting'))
)
.map((item) => String(item?.cascadeId || '').toLowerCase())
.filter(Boolean);
return {
updatedAtMs,
@@ -2485,7 +2515,8 @@ export function buildCliStatusSnapshot(finalPayload, updatedAtMs = Date.now()) {
(acc, item) => acc + Number(item?.runningSubagentCount || 0),
0
),
hasWaiting: runningList.some((item) => item?.mainActivity?.phase === 'waiting'),
hasWaiting: waitingCascadeIds.length > 0,
waitingCascadeIds,
quotas: finalPayload?.quotas || null,
activeConversation: {
cascadeId: ac.cascadeId || '',
@@ -2500,6 +2531,8 @@ export function buildCliStatusSnapshot(finalPayload, updatedAtMs = Date.now()) {
latestCacheHitPct: capSource.latestCacheHitPct ?? ac.latestCacheHitPct ?? null,
latestPromptTokens: Number(capSource.latestPromptTokens ?? ac.latestPromptTokens ?? 0),
totalTokens: Number(capSource.totalTokens ?? ac.totalTokens ?? 0),
...(latestAnomaly ? { latestAnomaly } : {}),
...(sessionAnomalyCount > 0 ? { sessionAnomalyCount } : {}),
},
};
}