Files
claude-code-haha/desktop/src/lib/formatTokenCount.ts
T
程序员阿江-Relakkes 3754d1f2a5 feat(desktop): replace the settings trace list with an in-session trajectory view (#1443)
Sessions get a Chat / Trajectory switch in the header. The trajectory is a
dense one-line-per-event ledger (system prompt, user, injected context such
as skills and system reminders, assistant responses, tool calls) with a
three-lane minimap, turn folding, search, and a detail panel per row.

- CLI: record a deduplicated prompt snapshot sidecar for desktop sessions
  (system prompt, tool catalog, user context) without touching the transcript.
- Server: project transcript records into trajectory rows with bounded,
  cursor-paged reads, live appends, a turn index, row detail by byte range,
  snapshot blobs, and a time-window lookup into the raw trace capture.
- Desktop: windowed ledger, minimap, detail panel with a raw request summary,
  chat <-> trajectory navigation, subagent drill-in.
- Remove the Settings trace list, trace tabs and the standalone trace
  window; migrate persisted trace tabs to session tabs.
2026-10-04 17:14:07 +08:00

17 lines
802 B
TypeScript

/**
* Compact token-count formatter shared by the chat UI (session header,
* streaming indicator, compact summary, background agents) and trace views,
* so every surface renders token usage with one notation.
* "847" below 1000, "1.2k" up to 1M, "1.2M" beyond — trailing ".0" dropped
* ("1k", not "1.0k") to match the CLI's formatTokens.
*
* Millions take an uppercase "M": these counts sit next to durations such as
* "52m 43s", where a lowercase "145.9m" reads as minutes.
*/
export function formatTokenCount(n?: number): string {
if (typeof n !== 'number' || !Number.isFinite(n) || n < 0) return '--'
if (n < 1000) return String(Math.round(n))
if (n < 1_000_000) return `${(n / 1000).toFixed(1).replace(/\.0$/, '')}k`
return `${(n / 1_000_000).toFixed(1).replace(/\.0$/, '')}M`
}