feat: surface cached token counts in /status output (openclaw#21248) thanks @vishaltandale00

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: vishaltandale00 <9222298+vishaltandale00@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
Vishal
2026-02-19 22:06:13 -05:00
committed by GitHub
parent db8ffb13f4
commit f1e1cc4ee3
18 changed files with 766 additions and 9 deletions

View File

@@ -21,18 +21,37 @@ export const shortenText = (value: string, maxLen: number) => {
};
export const formatTokensCompact = (
sess: Pick<SessionStatus, "totalTokens" | "contextTokens" | "percentUsed">,
sess: Pick<
SessionStatus,
"totalTokens" | "contextTokens" | "percentUsed" | "cacheRead" | "cacheWrite"
>,
) => {
const used = sess.totalTokens;
const ctx = sess.contextTokens;
const cacheRead = sess.cacheRead;
const cacheWrite = sess.cacheWrite;
let result = "";
if (used == null) {
return ctx ? `unknown/${formatKTokens(ctx)} (?%)` : "unknown used";
result = ctx ? `unknown/${formatKTokens(ctx)} (?%)` : "unknown used";
} else if (!ctx) {
result = `${formatKTokens(used)} used`;
} else {
const pctLabel = sess.percentUsed != null ? `${sess.percentUsed}%` : "?%";
result = `${formatKTokens(used)}/${formatKTokens(ctx)} (${pctLabel})`;
}
if (!ctx) {
return `${formatKTokens(used)} used`;
// Add cache hit rate if there are cached reads
if (typeof cacheRead === "number" && cacheRead > 0) {
const total =
typeof used === "number"
? used
: cacheRead + (typeof cacheWrite === "number" ? cacheWrite : 0);
const hitRate = Math.round((cacheRead / total) * 100);
result += ` · 🗄️ ${hitRate}% cached`;
}
const pctLabel = sess.percentUsed != null ? `${sess.percentUsed}%` : "?%";
return `${formatKTokens(used)}/${formatKTokens(ctx)} (${pctLabel})`;
return result;
};
export const formatDaemonRuntimeShort = (runtime?: {