Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(desktop): mark pending token usage (#2201)

tiammomof0466db13d10
diff --git a/apps/desktop/src/renderer/__tests__/runningTokenUsage.test.ts b/apps/desktop/src/renderer/__tests__/runningTokenUsage.test.ts
new file mode 100644
index 0000000000..c57de2d32b
--- /dev/null
+++ b/apps/desktop/src/renderer/__tests__/runningTokenUsage.test.ts
@@ -0,0 +1,15 @@
+import { describe, expect, it } from 'vitest';
+
+import { formatRunningTokenCount } from '@/features/cc-agent/lib/runningTokenUsage';
+
+describe('formatRunningTokenCount', () => {
+ it('marks zero usage as pending while a turn is running', () => {
+ expect(formatRunningTokenCount(0, true)).toBe('—');
+ });
+
+ it('keeps authoritative completed and positive usage values', () => {
+ expect(formatRunningTokenCount(0, false)).toBe('0');
+ expect(formatRunningTokenCount(999, true)).toBe('999');
+ expect(formatRunningTokenCount(1250, true)).toBe('1.3k');
+ });
+});
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
index 8c09af9646..290af4464c 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
@@ -191,6 +191,7 @@ import { useSessionHardwareTaskActions } from './lib/sessionHardwareTaskActions'
import { isRemoteSessionWriteBlocked } from './lib/remoteSessionWriteGuard';
import { getModelById, getDefaultModelForVendor, getModelsForVendor } from '@/lib/modelDefinitions';
import { resolveDisplayContextWindow } from '@/lib/contextWindow';
+import { formatRunningTokenCount } from './lib/runningTokenUsage';
import { matchNavigationCommandName, tryHandleNavigationCommand } from '@/lib/navigationCommands';
import { extractIpcError } from '@/utils/ipcError';
import { listActiveRunsForSession } from '@/features/learn/useLearnRun';
@@ -5049,10 +5050,9 @@ function RunningStatusBar({
// code's CLI status line ticks. The hook re-anchors from the displayed value
// on every target change, so rapid updates blend without snap-back.
const animatedTokens = useAnimatedNumber(tokenUsage, 400);
- const tokenText =
- animatedTokens >= 1000
- ? `${(animatedTokens / 1000).toFixed(1)}k tokens`
- : `${animatedTokens} tokens`;
+ const tokenText = t('chat.messageActionBar.turnTokens', {
+ tokens: formatRunningTokenCount(animatedTokens, visible),
+ });
// 淡入淡出/隐藏占位样式 —— 同时作用于左(状态)、右(elapsed/tokens)两段。
// visibility:hidden 只隐藏不收高,让 linger / fade 阶段稳定;淡出结束后整个
diff --git a/apps/desktop/src/renderer/features/cc-agent/lib/runningTokenUsage.ts b/apps/desktop/src/renderer/features/cc-agent/lib/runningTokenUsage.ts
new file mode 100644
index 0000000000..cb51b9547d
--- /dev/null
+++ b/apps/desktop/src/renderer/features/cc-agent/lib/runningTokenUsage.ts
@@ -0,0 +1,6 @@
+export function formatRunningTokenCount(tokenUsage: number, isRunning: boolean): string {
+ if (isRunning && tokenUsage === 0) return '—';
+ return tokenUsage >= 1000
+ ? `${(tokenUsage / 1000).toFixed(1)}k`
+ : `${tokenUsage}`;
+}