claude-code-hud 0.3.12 → 0.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/tui/hud.tsx +28 -30
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-code-hud",
3
- "version": "0.3.12",
3
+ "version": "0.3.13",
4
4
  "description": "Terminal HUD for Claude Code — real-time token usage, git status, project monitor",
5
5
  "type": "module",
6
6
  "bin": {
package/tui/hud.tsx CHANGED
@@ -219,9 +219,8 @@ async function readSessionTimeline(cwd: string): Promise<TimelineEntry[]> {
219
219
  if (!fs.existsSync(projectsDir)) return [];
220
220
 
221
221
  const targetDirName = cwd.replace(/\//g, '-');
222
+ const allFiles: string[] = [];
222
223
 
223
- let latestFile: string | null = null;
224
- let latestMtime = 0;
225
224
  try {
226
225
  for (const projectHash of fs.readdirSync(projectsDir)) {
227
226
  if (projectHash !== targetDirName) continue;
@@ -229,44 +228,43 @@ async function readSessionTimeline(cwd: string): Promise<TimelineEntry[]> {
229
228
  if (!fs.statSync(sessionDir).isDirectory()) continue;
230
229
  for (const file of fs.readdirSync(sessionDir)) {
231
230
  if (!file.endsWith('.jsonl')) continue;
232
- const filePath = join(sessionDir, file);
233
- try {
234
- const mtime = fs.statSync(filePath).mtimeMs;
235
- if (mtime > latestMtime) { latestMtime = mtime; latestFile = filePath; }
236
- } catch {}
231
+ allFiles.push(join(sessionDir, file));
237
232
  }
238
233
  }
239
234
  } catch {}
240
235
 
241
- if (!latestFile) return [];
236
+ if (allFiles.length === 0) return [];
242
237
 
243
- const lines = fs.readFileSync(latestFile, 'utf-8').split('\n').filter(Boolean);
244
- const entries: TimelineEntry[] = [];
238
+ const entries: (TimelineEntry & { ts: number })[] = [];
245
239
 
246
- for (const line of lines) {
240
+ for (const filePath of allFiles) {
247
241
  try {
248
- const obj = JSON.parse(line);
249
- if (obj.type !== 'user') continue;
250
- const content = obj.message?.content;
251
- // Skip tool_result messages (not direct user prompts)
252
- if (Array.isArray(content) && content.some((b: any) => b.type === 'tool_result')) continue;
253
- const textBlock = Array.isArray(content)
254
- ? content.find((b: any) => b.type === 'text')
255
- : null;
256
- const text: string = textBlock?.text ?? (typeof content === 'string' ? content : '');
257
- if (!text.trim()) continue;
258
-
259
- const ts: string = obj.timestamp ?? '';
260
- let time = '';
261
- if (ts) {
262
- try { time = new Date(ts).toTimeString().slice(0, 5); } catch {}
242
+ const lines = fs.readFileSync(filePath, 'utf-8').split('\n').filter(Boolean);
243
+ for (const line of lines) {
244
+ try {
245
+ const obj = JSON.parse(line);
246
+ if (obj.type !== 'user') continue;
247
+ const content = obj.message?.content;
248
+ if (Array.isArray(content) && content.some((b: any) => b.type === 'tool_result')) continue;
249
+ const textBlock = Array.isArray(content)
250
+ ? content.find((b: any) => b.type === 'text')
251
+ : null;
252
+ const text: string = textBlock?.text ?? (typeof content === 'string' ? content : '');
253
+ if (!text.trim()) continue;
254
+
255
+ const tsStr: string = obj.timestamp ?? '';
256
+ const tsNum = tsStr ? new Date(tsStr).getTime() : 0;
257
+ const time = tsStr ? new Date(tsStr).toTimeString().slice(0, 5) : '';
258
+
259
+ entries.push({ ts: tsNum, time, text: text.replace(/\n/g, ' ').slice(0, 80) });
260
+ } catch {}
263
261
  }
264
-
265
- entries.push({ time, text: text.replace(/\n/g, ' ').slice(0, 80) });
266
262
  } catch {}
267
263
  }
268
264
 
269
- return entries.slice(-30);
265
+ // Sort all sessions by time, return last 50
266
+ entries.sort((a, b) => a.ts - b.ts);
267
+ return entries.slice(-50).map(({ time, text }) => ({ time, text }));
270
268
  }
271
269
 
272
270
  // ── UI Components ──────────────────────────────────────────────────────────
@@ -845,7 +843,7 @@ function App() {
845
843
  let debounceTimer: ReturnType<typeof setTimeout> | null = null;
846
844
  watcher.on('change', () => {
847
845
  if (debounceTimer) clearTimeout(debounceTimer);
848
- debounceTimer = setTimeout(refresh, 800);
846
+ debounceTimer = setTimeout(refresh, 2000);
849
847
  });
850
848
  });
851
849
  }