Skip to content

Commit 4863e44

Browse files
rajbosCopilot
andcommitted
feat: add token count column to diagnostics session files tab
- Add tokens? field to SessionFileDetails interface - Populate tokens from cache in getSessionFileDetailsFromCache() and updateCacheWithSessionDetails() - Add Tokens column in the diagnostics session table with compact K/M formatting - Add Total Tokens summary card to the session files summary row - Tooltip shows exact token count on hover Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e2ee422 commit 4863e44

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

vscode-extension/src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,6 +3144,7 @@ class CopilotTokenTracker implements vscode.Disposable {
31443144
size: cached.size || stat.size,
31453145
modified: stat.mtime.toISOString(),
31463146
interactions: cached.interactions,
3147+
tokens: cached.tokens || 0,
31473148
contextReferences: cached.usageAnalysis.contextReferences,
31483149
firstInteraction: cached.firstInteraction || null,
31493150
lastInteraction: lastInteraction,
@@ -3170,6 +3171,9 @@ class CopilotTokenTracker implements vscode.Disposable {
31703171
// Get existing cache entry if available
31713172
const existingCache = this.getCachedSessionData(sessionFile);
31723173

3174+
// Enrich details with token count from existing cache (populated by main stats calculation)
3175+
details.tokens = existingCache?.tokens || 0;
3176+
31733177
// Create or update cache entry
31743178
const cacheEntry: SessionFileCache = {
31753179
tokens: existingCache?.tokens || 0,

vscode-extension/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ export interface SessionFileDetails {
314314
size: number;
315315
modified: string;
316316
interactions: number;
317+
tokens?: number; // estimated token count for the session
317318
contextReferences: ContextReferenceUsage;
318319
firstInteraction: string | null;
319320
lastInteraction: string | null;

vscode-extension/src/webview/diagnostics/main.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type SessionFileDetails = {
2424
size: number;
2525
modified: string;
2626
interactions: number;
27+
tokens?: number;
2728
contextReferences: ContextReferenceUsage;
2829
firstInteraction: string | null;
2930
lastInteraction: string | null;
@@ -188,6 +189,14 @@ function sanitizeNumber(value: number | undefined | null): string {
188189
return Math.floor(n).toString();
189190
}
190191

192+
function formatTokenCount(value: number | undefined | null): string {
193+
const n = Number(value ?? 0);
194+
if (!Number.isFinite(n) || n === 0) { return "0"; }
195+
if (n >= 1_000_000) { return `${(n / 1_000_000).toFixed(1)}M`; }
196+
if (n >= 1_000) { return `${(n / 1_000).toFixed(1)}K`; }
197+
return Math.floor(n).toString();
198+
}
199+
191200
/**
192201
* Build a DOM element showing all candidate paths the extension considers,
193202
* with their existence status. Helps users understand why data may be missing.
@@ -509,6 +518,10 @@ function renderSessionTable(
509518
(sum, sf) => sum + Number(sf.interactions || 0),
510519
0,
511520
);
521+
const totalTokens = filteredFiles.reduce(
522+
(sum, sf) => sum + Number(sf.tokens || 0),
523+
0,
524+
);
512525
const totalContextRefs = filteredFiles.reduce(
513526
(sum, sf) => sum + getTotalContextRefs(sf.contextReferences),
514527
0,
@@ -581,6 +594,10 @@ function renderSessionTable(
581594
<div class="summary-label">💬 Interactions</div>
582595
<div class="summary-value">${totalInteractions}</div>
583596
</div>
597+
<div class="summary-card">
598+
<div class="summary-label">🪙 Tokens</div>
599+
<div class="summary-value" title="${totalTokens.toLocaleString()} tokens">${formatTokenCount(totalTokens)}</div>
600+
</div>
584601
<div class="summary-card">
585602
<div class="summary-label">🔗 Context References</div>
586603
<div class="summary-value">${safeText(totalContextRefs)}</div>
@@ -618,6 +635,7 @@ function renderSessionTable(
618635
<th>Title</th>
619636
<th>Repository</th>
620637
<th>Size</th>
638+
<th>Tokens</th>
621639
<th>Interactions</th>
622640
<th>Context Refs</th>
623641
<th class="sortable" data-sort="lastInteraction">Last Interaction${getSortIndicator("lastInteraction")}</th>
@@ -636,6 +654,7 @@ function renderSessionTable(
636654
</td>
637655
<td class="repository-cell" title="${sf.repository ? escapeHtml(sf.repository) : "No repository detected"}">${sf.repository ? escapeHtml(getRepoDisplayName(sf.repository)) : '<span style="color: #666;">—</span>'}</td>
638656
<td>${formatFileSize(sf.size)}</td>
657+
<td title="${Number(sf.tokens || 0).toLocaleString()} tokens">${formatTokenCount(sf.tokens)}</td>
639658
<td>${sanitizeNumber(sf.interactions)}</td>
640659
<td title="${escapeHtml(getContextRefsSummary(sf.contextReferences))}">${sanitizeNumber(getTotalContextRefs(sf.contextReferences))}</td>
641660
<td>${formatDate(sf.lastInteraction)}</td>

0 commit comments

Comments
 (0)