claude-code-hud 0.3.5 → 0.3.6
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.
- package/package.json +1 -1
- package/scripts/lib/token-reader.mjs +19 -10
- package/tui/hud.tsx +7 -4
package/package.json
CHANGED
|
@@ -34,15 +34,23 @@ function getContextWindow(model) {
|
|
|
34
34
|
return 200000;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
/**
|
|
38
|
-
function
|
|
37
|
+
/** Convert cwd to the Claude project directory name (/ replaced with -) */
|
|
38
|
+
function cwdToProjectDir(cwd) {
|
|
39
|
+
return cwd.replace(/\//g, '-');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Find the most recently modified .jsonl session file for the given cwd */
|
|
43
|
+
function findLatestSession(cwd) {
|
|
39
44
|
const projectsDir = path.join(os.homedir(), '.claude', 'projects');
|
|
40
45
|
if (!fs.existsSync(projectsDir)) return null;
|
|
41
46
|
|
|
47
|
+
const targetDir = cwd ? cwdToProjectDir(cwd) : null;
|
|
48
|
+
|
|
42
49
|
let latest = null;
|
|
43
50
|
let latestMtime = 0;
|
|
44
51
|
|
|
45
|
-
const projects = fs.readdirSync(projectsDir)
|
|
52
|
+
const projects = fs.readdirSync(projectsDir)
|
|
53
|
+
.filter(p => !targetDir || p === targetDir);
|
|
46
54
|
for (const proj of projects) {
|
|
47
55
|
const projDir = path.join(projectsDir, proj);
|
|
48
56
|
|
|
@@ -66,12 +74,13 @@ function findLatestSession() {
|
|
|
66
74
|
return latest;
|
|
67
75
|
}
|
|
68
76
|
|
|
69
|
-
/** Collect all JSONL lines
|
|
70
|
-
function readAllLines() {
|
|
77
|
+
/** Collect all JSONL lines for the given cwd (or all projects if no cwd) */
|
|
78
|
+
function readAllLines(cwd) {
|
|
71
79
|
const projectsDir = path.join(os.homedir(), '.claude', 'projects');
|
|
72
80
|
if (!fs.existsSync(projectsDir)) return [];
|
|
81
|
+
const targetDir = cwd ? cwdToProjectDir(cwd) : null;
|
|
73
82
|
const result = [];
|
|
74
|
-
for (const proj of fs.readdirSync(projectsDir)) {
|
|
83
|
+
for (const proj of fs.readdirSync(projectsDir).filter(p => !targetDir || p === targetDir)) {
|
|
75
84
|
const projDir = path.join(projectsDir, proj);
|
|
76
85
|
let files = [];
|
|
77
86
|
try { files = fs.readdirSync(projDir).filter(f => f.endsWith('.jsonl')); } catch { continue; }
|
|
@@ -94,8 +103,8 @@ function readAllLines() {
|
|
|
94
103
|
return result;
|
|
95
104
|
}
|
|
96
105
|
|
|
97
|
-
export function readTokenHistory() {
|
|
98
|
-
const allLines = readAllLines();
|
|
106
|
+
export function readTokenHistory(cwd) {
|
|
107
|
+
const allLines = readAllLines(cwd);
|
|
99
108
|
const now = Date.now();
|
|
100
109
|
const h5 = now - 5 * 60 * 60 * 1000;
|
|
101
110
|
const wk = now - 7 * 24 * 60 * 60 * 1000;
|
|
@@ -143,8 +152,8 @@ export function readTokenHistory() {
|
|
|
143
152
|
return { last5h: acc5h, lastWeek: accWk, hourlyBuckets: buckets };
|
|
144
153
|
}
|
|
145
154
|
|
|
146
|
-
export function readTokenUsage() {
|
|
147
|
-
const sessionFile = findLatestSession();
|
|
155
|
+
export function readTokenUsage(cwd) {
|
|
156
|
+
const sessionFile = findLatestSession(cwd);
|
|
148
157
|
if (!sessionFile) {
|
|
149
158
|
return empty();
|
|
150
159
|
}
|
package/tui/hud.tsx
CHANGED
|
@@ -218,10 +218,13 @@ async function readSessionTimeline(cwd: string): Promise<TimelineEntry[]> {
|
|
|
218
218
|
const projectsDir = join(os.homedir(), '.claude', 'projects');
|
|
219
219
|
if (!fs.existsSync(projectsDir)) return [];
|
|
220
220
|
|
|
221
|
+
const targetDirName = cwd.replace(/\//g, '-');
|
|
222
|
+
|
|
221
223
|
let latestFile: string | null = null;
|
|
222
224
|
let latestMtime = 0;
|
|
223
225
|
try {
|
|
224
226
|
for (const projectHash of fs.readdirSync(projectsDir)) {
|
|
227
|
+
if (projectHash !== targetDirName) continue;
|
|
225
228
|
const sessionDir = join(projectsDir, projectHash);
|
|
226
229
|
if (!fs.statSync(sessionDir).isDirectory()) continue;
|
|
227
230
|
for (const file of fs.readdirSync(sessionDir)) {
|
|
@@ -715,8 +718,8 @@ function App() {
|
|
|
715
718
|
const cwd = process.env.CLAUDE_PROJECT_ROOT || process.cwd();
|
|
716
719
|
const C = makeTheme(accent);
|
|
717
720
|
|
|
718
|
-
const [usage, setUsage] = useState<any>(readTokenUsage());
|
|
719
|
-
const [history, setHistory] = useState<any>(readTokenHistory());
|
|
721
|
+
const [usage, setUsage] = useState<any>(readTokenUsage(cwd));
|
|
722
|
+
const [history, setHistory] = useState<any>(readTokenHistory(cwd));
|
|
720
723
|
const [git, setGit] = useState<any>(readGitInfo(cwd));
|
|
721
724
|
const [project, setProject] = useState<ProjectInfo | null>(null);
|
|
722
725
|
const [rateLimits, setRateLimits] = useState<any>(getUsageSync());
|
|
@@ -741,8 +744,8 @@ function App() {
|
|
|
741
744
|
const [currentActivity, setCurrentActivity] = useState<string>('');
|
|
742
745
|
|
|
743
746
|
const refresh = useCallback(() => {
|
|
744
|
-
setUsage(readTokenUsage());
|
|
745
|
-
setHistory(readTokenHistory());
|
|
747
|
+
setUsage(readTokenUsage(cwd));
|
|
748
|
+
setHistory(readTokenHistory(cwd));
|
|
746
749
|
setGit(readGitInfo(cwd));
|
|
747
750
|
setUpdatedAt(Date.now());
|
|
748
751
|
getUsage().then(setRateLimits).catch(() => {});
|