ccstatusline-zh 2.2.33 → 2.2.35
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/README.md +22 -8
- package/dist/{ccstatusline-rdsx5ab1.js → ccstatusline-71188a0p.js} +23 -25
- package/dist/ccstatusline-88bs860s.js +6063 -0
- package/dist/{ccstatusline-3tcnryv5.js → ccstatusline-98magj3t.js} +1907 -6930
- package/dist/ccstatusline-j1gdxtq4.js +180 -0
- package/dist/ccstatusline.js +407 -18
- package/dist/dev-reload-egdx2kp5.js +23 -0
- package/dist/{devtools-3w5md92d.js → devtools-nceaxkjz.js} +1713 -2407
- package/dist/{hooks-q322knq1.js → hooks-zr7bxw3x.js} +23 -14
- package/dist/{index-d0c2je2n.js → index-7sf5nvak.js} +328 -91
- package/package.json +5 -5
package/dist/ccstatusline.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
source_default,
|
|
4
|
-
string,
|
|
5
|
-
number,
|
|
6
|
-
object,
|
|
7
|
-
looseObject,
|
|
8
|
-
union,
|
|
9
|
-
preprocess,
|
|
10
4
|
getVisibleText,
|
|
11
5
|
updateColorMap,
|
|
12
6
|
prefetchClaudeStatusIfNeeded,
|
|
13
7
|
ZERO_COMPACTION_STATS,
|
|
14
8
|
getPackageVersion,
|
|
15
9
|
getTerminalWidth,
|
|
10
|
+
isHidden,
|
|
16
11
|
resolveExecutable,
|
|
17
12
|
sanitizeTerminalText,
|
|
18
13
|
GIT_REVIEW_REFRESH_FLAG,
|
|
@@ -22,9 +17,18 @@ import {
|
|
|
22
17
|
preRenderAllWidgets,
|
|
23
18
|
calculateMaxWidthsFromPreRendered,
|
|
24
19
|
renderStatusLine,
|
|
20
|
+
SESSION_UNDER_LIMIT_HIDEABLE_STATE,
|
|
21
|
+
SESSION_AT_LIMIT_HIDEABLE_STATE,
|
|
22
|
+
getClaudeConfigDir,
|
|
25
23
|
setUsageField,
|
|
26
24
|
WEEKLY_MODEL_USAGE_BUCKETS,
|
|
25
|
+
isStaleUsageFallback,
|
|
26
|
+
getUsageFetchedAtMs,
|
|
27
|
+
getUsageLoginFingerprint,
|
|
27
28
|
fetchUsageData,
|
|
29
|
+
fetchAccountEmail,
|
|
30
|
+
iterateJsonlLinesReverseSync,
|
|
31
|
+
parseJsonlLine,
|
|
28
32
|
getTranscriptAnalysis,
|
|
29
33
|
getWidgetSpeedWindowSeconds,
|
|
30
34
|
isWidgetSpeedWindowEnabled,
|
|
@@ -32,11 +36,20 @@ import {
|
|
|
32
36
|
initConfigPath,
|
|
33
37
|
loadSettings,
|
|
34
38
|
saveSettings
|
|
35
|
-
} from "./ccstatusline-
|
|
39
|
+
} from "./ccstatusline-98magj3t.js";
|
|
40
|
+
import {
|
|
41
|
+
string,
|
|
42
|
+
number,
|
|
43
|
+
boolean,
|
|
44
|
+
object,
|
|
45
|
+
looseObject,
|
|
46
|
+
union,
|
|
47
|
+
preprocess
|
|
48
|
+
} from "./ccstatusline-88bs860s.js";
|
|
36
49
|
import {
|
|
37
50
|
advanceGlobalPowerlineThemeIndex,
|
|
38
51
|
advanceGlobalSeparatorIndex
|
|
39
|
-
} from "./ccstatusline-
|
|
52
|
+
} from "./ccstatusline-71188a0p.js";
|
|
40
53
|
|
|
41
54
|
// src/types/StatusJSON.ts
|
|
42
55
|
var CoercedNumberSchema = preprocess((value) => {
|
|
@@ -54,6 +67,11 @@ var RateLimitPeriodSchema = object({
|
|
|
54
67
|
used_percentage: CoercedNumberSchema.nullable().optional(),
|
|
55
68
|
resets_at: CoercedNumberSchema.nullable().optional()
|
|
56
69
|
});
|
|
70
|
+
var SpendLimitSchema = RateLimitPeriodSchema.extend({
|
|
71
|
+
used_usd: CoercedNumberSchema.nullable().optional(),
|
|
72
|
+
limit_usd: CoercedNumberSchema.nullable().optional(),
|
|
73
|
+
period: string().nullable().optional()
|
|
74
|
+
});
|
|
57
75
|
var StatusJSONSchema = looseObject({
|
|
58
76
|
hook_event_name: string().optional(),
|
|
59
77
|
session_id: string().optional(),
|
|
@@ -97,6 +115,7 @@ var StatusJSONSchema = looseObject({
|
|
|
97
115
|
remaining_percentage: CoercedNumberSchema.nullable().optional()
|
|
98
116
|
}).nullable().optional(),
|
|
99
117
|
vim: object({ mode: string().optional() }).nullable().optional(),
|
|
118
|
+
fast_mode: boolean().nullable().optional().catch(undefined),
|
|
100
119
|
worktree: object({
|
|
101
120
|
name: string().optional(),
|
|
102
121
|
path: string().optional(),
|
|
@@ -104,11 +123,20 @@ var StatusJSONSchema = looseObject({
|
|
|
104
123
|
original_cwd: string().optional(),
|
|
105
124
|
original_branch: string().optional()
|
|
106
125
|
}).nullable().optional(),
|
|
126
|
+
prompt_cache: object({
|
|
127
|
+
warm: boolean().nullable().optional(),
|
|
128
|
+
caching_observed: boolean().nullable().optional(),
|
|
129
|
+
ttl: string().nullable().optional(),
|
|
130
|
+
expires_at: CoercedNumberSchema.nullable().optional(),
|
|
131
|
+
hit_ratio: CoercedNumberSchema.nullable().optional(),
|
|
132
|
+
recache_tokens_if_cold: CoercedNumberSchema.nullable().optional()
|
|
133
|
+
}).nullable().optional(),
|
|
107
134
|
rate_limits: object({
|
|
108
135
|
five_hour: RateLimitPeriodSchema.optional(),
|
|
109
136
|
seven_day: RateLimitPeriodSchema.optional(),
|
|
110
137
|
seven_day_sonnet: RateLimitPeriodSchema.nullable().optional(),
|
|
111
|
-
seven_day_opus: RateLimitPeriodSchema.nullable().optional()
|
|
138
|
+
seven_day_opus: RateLimitPeriodSchema.nullable().optional(),
|
|
139
|
+
spend_limit: SpendLimitSchema.nullable().optional()
|
|
112
140
|
}).nullable().optional()
|
|
113
141
|
});
|
|
114
142
|
|
|
@@ -206,9 +234,315 @@ function handleHookInput(input) {
|
|
|
206
234
|
} catch {}
|
|
207
235
|
}
|
|
208
236
|
|
|
237
|
+
// src/utils/session-forecast.ts
|
|
238
|
+
var SESSION_WINDOW_MS = 5 * 60 * 60 * 1000;
|
|
239
|
+
var LOOKBACK_MS = 30 * 60 * 1000;
|
|
240
|
+
var MIN_SPAN_MS = 10 * 60 * 1000;
|
|
241
|
+
var FUTURE_TOLERANCE_MS = 60 * 1000;
|
|
242
|
+
function getKnownPoints({ readings, nowMs, resetAtMs, percent }) {
|
|
243
|
+
const windowStartMs = resetAtMs - SESSION_WINDOW_MS;
|
|
244
|
+
const points = [{ timeMs: windowStartMs, percent: 0 }];
|
|
245
|
+
for (const [firstSeenMs, lastSeenMs, readingPercent] of readings) {
|
|
246
|
+
if (firstSeenMs > nowMs + FUTURE_TOLERANCE_MS) {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
for (const timeMs of [firstSeenMs, Math.min(lastSeenMs, nowMs)]) {
|
|
250
|
+
if (timeMs >= windowStartMs) {
|
|
251
|
+
points.push({ timeMs, percent: readingPercent });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
points.push({ timeMs: nowMs, percent });
|
|
256
|
+
return points.sort((a, b) => a.timeMs - b.timeMs);
|
|
257
|
+
}
|
|
258
|
+
function getCurrentPercent({ readings, nowMs, percent }) {
|
|
259
|
+
const seenPercents = readings.filter(([firstSeenMs]) => firstSeenMs <= nowMs + FUTURE_TOLERANCE_MS).map(([, , readingPercent]) => readingPercent);
|
|
260
|
+
return Math.max(percent, ...seenPercents);
|
|
261
|
+
}
|
|
262
|
+
function percentAt(points, timeMs) {
|
|
263
|
+
let before;
|
|
264
|
+
for (const point of points) {
|
|
265
|
+
if (point.timeMs > timeMs && before) {
|
|
266
|
+
return before.percent + (point.percent - before.percent) * (timeMs - before.timeMs) / (point.timeMs - before.timeMs);
|
|
267
|
+
}
|
|
268
|
+
before = point;
|
|
269
|
+
}
|
|
270
|
+
return before?.percent ?? 0;
|
|
271
|
+
}
|
|
272
|
+
function forecastSessionUsage(input) {
|
|
273
|
+
const { nowMs, resetAtMs } = input;
|
|
274
|
+
const percent = getCurrentPercent(input);
|
|
275
|
+
const leftMs = resetAtMs - nowMs;
|
|
276
|
+
if (leftMs <= 0 || percent >= 100) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
const startMs = Math.max(nowMs - LOOKBACK_MS, resetAtMs - SESSION_WINDOW_MS);
|
|
280
|
+
const spanMs = nowMs - startMs;
|
|
281
|
+
if (spanMs < MIN_SPAN_MS) {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
const rise = percent - percentAt(getKnownPoints({ ...input, percent }), startMs);
|
|
285
|
+
if (rise <= 0) {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
const projectedPercent = percent + rise * leftMs / spanMs;
|
|
289
|
+
const msToLimit = (100 - percent) * spanMs / rise;
|
|
290
|
+
return {
|
|
291
|
+
currentPercent: percent,
|
|
292
|
+
projectedPercent: Math.min(100, projectedPercent),
|
|
293
|
+
limitInMs: msToLimit < leftMs ? msToLimit : null
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// src/utils/session-usage-history.ts
|
|
298
|
+
import * as fs3 from "node:fs";
|
|
299
|
+
import * as os2 from "node:os";
|
|
300
|
+
import * as path3 from "node:path";
|
|
301
|
+
var HISTORY_SCHEMA_VERSION = 1;
|
|
302
|
+
var WINDOW_MATCH_MS = 60 * 1000;
|
|
303
|
+
var LAST_SEEN_WRITE_INTERVAL_MS = 60 * 1000;
|
|
304
|
+
var ORPHANED_TEMP_FILE_AGE_MS = 60 * 1000;
|
|
305
|
+
var STALE_LOCK_AGE_MS = 10 * 1000;
|
|
306
|
+
var SYNTHETIC_MODEL = "<synthetic>";
|
|
307
|
+
function getLastResponseAtMs(transcriptPath) {
|
|
308
|
+
if (transcriptPath === undefined) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
try {
|
|
312
|
+
for (const line of iterateJsonlLinesReverseSync(transcriptPath)) {
|
|
313
|
+
const entry = parseJsonlLine(line);
|
|
314
|
+
if (entry?.type !== "assistant" || entry.isApiErrorMessage === true || entry.message?.model === SYNTHETIC_MODEL) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
const timestampMs = typeof entry.timestamp === "string" ? Date.parse(entry.timestamp) : Number.NaN;
|
|
318
|
+
if (Number.isFinite(timestampMs)) {
|
|
319
|
+
return timestampMs;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
} catch {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
function getDefaultSessionUsageHistoryDeps(payload) {
|
|
328
|
+
const isPayloadPercent = typeof payload?.rate_limits?.five_hour?.used_percentage === "number";
|
|
329
|
+
return {
|
|
330
|
+
readFileSync: (p) => fs3.readFileSync(p, "utf-8"),
|
|
331
|
+
writeFileSync: (p, data) => {
|
|
332
|
+
fs3.writeFileSync(p, data, "utf-8");
|
|
333
|
+
},
|
|
334
|
+
createFileExclusiveSync: (p) => {
|
|
335
|
+
fs3.writeFileSync(p, "", { flag: "wx" });
|
|
336
|
+
},
|
|
337
|
+
renameSync: (from, to) => {
|
|
338
|
+
fs3.renameSync(from, to);
|
|
339
|
+
},
|
|
340
|
+
unlinkSync: (p) => {
|
|
341
|
+
fs3.unlinkSync(p);
|
|
342
|
+
},
|
|
343
|
+
readdirSync: (p) => fs3.readdirSync(p),
|
|
344
|
+
statSync: (p) => fs3.statSync(p),
|
|
345
|
+
mkdirSync: (p) => {
|
|
346
|
+
fs3.mkdirSync(p, { recursive: true });
|
|
347
|
+
},
|
|
348
|
+
now: () => Date.now(),
|
|
349
|
+
percentSeenAt: isPayloadPercent ? () => getLastResponseAtMs(payload.transcript_path) : getUsageFetchedAtMs,
|
|
350
|
+
loginFingerprint: getUsageLoginFingerprint,
|
|
351
|
+
cachePath: path3.join(os2.homedir(), ".cache", "ccstatusline", "session-usage-history.json")
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
function isReading(value) {
|
|
355
|
+
return Array.isArray(value) && value.length === 3 && value.every((part) => typeof part === "number" && Number.isFinite(part));
|
|
356
|
+
}
|
|
357
|
+
function isUsageWindow(value) {
|
|
358
|
+
if (typeof value !== "object" || value === null) {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
const usageWindow = value;
|
|
362
|
+
return typeof usageWindow.resetAt === "number" && Array.isArray(usageWindow.readings) && usageWindow.readings.every(isReading);
|
|
363
|
+
}
|
|
364
|
+
function readHistory(deps) {
|
|
365
|
+
const empty = { version: HISTORY_SCHEMA_VERSION, profiles: {} };
|
|
366
|
+
try {
|
|
367
|
+
const parsed = JSON.parse(deps.readFileSync(deps.cachePath));
|
|
368
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
369
|
+
return empty;
|
|
370
|
+
}
|
|
371
|
+
const data = parsed;
|
|
372
|
+
if (data.version !== HISTORY_SCHEMA_VERSION || typeof data.profiles !== "object" || data.profiles === null) {
|
|
373
|
+
return empty;
|
|
374
|
+
}
|
|
375
|
+
const profiles = {};
|
|
376
|
+
for (const [key, windows] of Object.entries(data.profiles)) {
|
|
377
|
+
if (Array.isArray(windows)) {
|
|
378
|
+
profiles[key] = windows.filter(isUsageWindow);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return { version: HISTORY_SCHEMA_VERSION, profiles };
|
|
382
|
+
} catch {
|
|
383
|
+
return empty;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
function pruneWindows(windows, nowMs) {
|
|
387
|
+
const lookbackStartMs = nowMs - LOOKBACK_MS;
|
|
388
|
+
return windows.filter((usageWindow) => usageWindow.resetAt > nowMs).map((usageWindow) => {
|
|
389
|
+
const readings = usageWindow.readings.filter(([firstSeenMs]) => firstSeenMs <= nowMs + FUTURE_TOLERANCE_MS);
|
|
390
|
+
let keepFrom = 0;
|
|
391
|
+
for (let index = 0;index < readings.length; index++) {
|
|
392
|
+
if ((readings[index]?.[0] ?? Number.POSITIVE_INFINITY) <= lookbackStartMs) {
|
|
393
|
+
keepFrom = index;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return { resetAt: usageWindow.resetAt, readings: readings.slice(keepFrom) };
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
function getSeenAtLookup(deps, nowMs) {
|
|
400
|
+
let looked = false;
|
|
401
|
+
let seenAtMs;
|
|
402
|
+
return () => {
|
|
403
|
+
if (!looked) {
|
|
404
|
+
looked = true;
|
|
405
|
+
seenAtMs = deps.percentSeenAt ? deps.percentSeenAt() : nowMs;
|
|
406
|
+
seenAtMs = seenAtMs !== undefined && Number.isFinite(seenAtMs) ? Math.min(nowMs, seenAtMs) : undefined;
|
|
407
|
+
}
|
|
408
|
+
return seenAtMs;
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
function removeOrphanedTempFiles(deps, nowMs) {
|
|
412
|
+
const dir = path3.dirname(deps.cachePath);
|
|
413
|
+
const prefix = `${path3.basename(deps.cachePath)}.`;
|
|
414
|
+
let names;
|
|
415
|
+
try {
|
|
416
|
+
names = deps.readdirSync(dir);
|
|
417
|
+
} catch {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
for (const name of names) {
|
|
421
|
+
if (!name.startsWith(prefix) || !/^\d+\.tmp$/.test(name.slice(prefix.length))) {
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
const tempPath = path3.join(dir, name);
|
|
425
|
+
try {
|
|
426
|
+
if (nowMs - deps.statSync(tempPath).mtimeMs >= ORPHANED_TEMP_FILE_AGE_MS) {
|
|
427
|
+
deps.unlinkSync(tempPath);
|
|
428
|
+
}
|
|
429
|
+
} catch {}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
function addReading(history, profileKey, resetAtMs, percent, nowMs, seenAt) {
|
|
433
|
+
const profiles = {};
|
|
434
|
+
for (const [key, windows] of Object.entries(history.profiles)) {
|
|
435
|
+
const kept = pruneWindows(windows, nowMs);
|
|
436
|
+
if (kept.length > 0) {
|
|
437
|
+
profiles[key] = kept;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
const windows = profiles[profileKey] ?? [];
|
|
441
|
+
let usageWindow = windows.find((candidate) => Math.abs(candidate.resetAt - resetAtMs) <= WINDOW_MATCH_MS);
|
|
442
|
+
if (!usageWindow) {
|
|
443
|
+
usageWindow = { resetAt: resetAtMs, readings: [] };
|
|
444
|
+
windows.push(usageWindow);
|
|
445
|
+
}
|
|
446
|
+
profiles[profileKey] = windows;
|
|
447
|
+
const readings = usageWindow.readings;
|
|
448
|
+
const last = readings[readings.length - 1];
|
|
449
|
+
if (last !== undefined && percent < last[2]) {
|
|
450
|
+
return { profiles, readings, changed: false };
|
|
451
|
+
}
|
|
452
|
+
if (last?.[2] !== percent) {
|
|
453
|
+
const firstSeenMs = Math.max(seenAt() ?? nowMs, last?.[1] ?? Number.NEGATIVE_INFINITY);
|
|
454
|
+
readings.push([firstSeenMs, firstSeenMs, percent]);
|
|
455
|
+
return { profiles, readings, changed: true };
|
|
456
|
+
}
|
|
457
|
+
if (nowMs - last[1] < LAST_SEEN_WRITE_INTERVAL_MS) {
|
|
458
|
+
return { profiles, readings, changed: false };
|
|
459
|
+
}
|
|
460
|
+
const lastSeenMs = seenAt() ?? last[1];
|
|
461
|
+
if (lastSeenMs - last[1] < LAST_SEEN_WRITE_INTERVAL_MS) {
|
|
462
|
+
return { profiles, readings, changed: false };
|
|
463
|
+
}
|
|
464
|
+
last[1] = lastSeenMs;
|
|
465
|
+
return { profiles, readings, changed: true };
|
|
466
|
+
}
|
|
467
|
+
function lockHistory(deps, nowMs) {
|
|
468
|
+
const lockPath = `${deps.cachePath}.lock`;
|
|
469
|
+
try {
|
|
470
|
+
deps.mkdirSync(path3.dirname(deps.cachePath));
|
|
471
|
+
deps.createFileExclusiveSync(lockPath);
|
|
472
|
+
return true;
|
|
473
|
+
} catch {}
|
|
474
|
+
try {
|
|
475
|
+
if (Math.abs(nowMs - deps.statSync(lockPath).mtimeMs) < STALE_LOCK_AGE_MS) {
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
deps.unlinkSync(lockPath);
|
|
479
|
+
deps.createFileExclusiveSync(lockPath);
|
|
480
|
+
return true;
|
|
481
|
+
} catch {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
function unlockHistory(deps) {
|
|
486
|
+
try {
|
|
487
|
+
deps.unlinkSync(`${deps.cachePath}.lock`);
|
|
488
|
+
} catch {}
|
|
489
|
+
}
|
|
490
|
+
function writeHistory(deps, profiles) {
|
|
491
|
+
const tempPath = `${deps.cachePath}.${process.pid}.tmp`;
|
|
492
|
+
try {
|
|
493
|
+
const history = { version: HISTORY_SCHEMA_VERSION, profiles };
|
|
494
|
+
deps.writeFileSync(tempPath, JSON.stringify(history));
|
|
495
|
+
deps.renameSync(tempPath, deps.cachePath);
|
|
496
|
+
} catch {
|
|
497
|
+
try {
|
|
498
|
+
deps.unlinkSync(tempPath);
|
|
499
|
+
} catch {}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
function recordSessionUsageReading(profileKey, resetAtMs, percent, deps = getDefaultSessionUsageHistoryDeps()) {
|
|
503
|
+
const nowMs = deps.now();
|
|
504
|
+
const clampedPercent = Math.max(0, Math.min(100, percent));
|
|
505
|
+
const seenAt = getSeenAtLookup(deps, nowMs);
|
|
506
|
+
const unlocked = addReading(readHistory(deps), profileKey, resetAtMs, clampedPercent, nowMs, seenAt);
|
|
507
|
+
if (!unlocked.changed || !lockHistory(deps, nowMs)) {
|
|
508
|
+
return unlocked.readings;
|
|
509
|
+
}
|
|
510
|
+
try {
|
|
511
|
+
const locked = addReading(readHistory(deps), profileKey, resetAtMs, clampedPercent, nowMs, seenAt);
|
|
512
|
+
if (locked.changed) {
|
|
513
|
+
writeHistory(deps, locked.profiles);
|
|
514
|
+
removeOrphanedTempFiles(deps, nowMs);
|
|
515
|
+
}
|
|
516
|
+
return locked.readings;
|
|
517
|
+
} finally {
|
|
518
|
+
unlockHistory(deps);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// src/utils/session-forecast-prefetch.ts
|
|
523
|
+
var SESSION_FORECAST_WIDGET_TYPES = new Set(["block-forecast", "block-limit-timer"]);
|
|
524
|
+
function computeSessionForecastIfNeeded(lines, usageData, deps = getDefaultSessionUsageHistoryDeps()) {
|
|
525
|
+
if (!lines.some((line) => line.some((item) => SESSION_FORECAST_WIDGET_TYPES.has(item.type)))) {
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
const percent = usageData?.sessionUsage;
|
|
529
|
+
const resetAtMs = usageData?.sessionResetAt === undefined ? Number.NaN : Date.parse(usageData.sessionResetAt);
|
|
530
|
+
const nowMs = deps.now();
|
|
531
|
+
if (percent === undefined || !Number.isFinite(resetAtMs) || resetAtMs <= nowMs) {
|
|
532
|
+
return null;
|
|
533
|
+
}
|
|
534
|
+
const clampedPercent = Math.max(0, Math.min(100, percent));
|
|
535
|
+
const login = deps.loginFingerprint?.() ?? null;
|
|
536
|
+
const profileKey = login === null ? getClaudeConfigDir() : `${getClaudeConfigDir()}#${login}`;
|
|
537
|
+
const readings = recordSessionUsageReading(profileKey, resetAtMs, clampedPercent, deps);
|
|
538
|
+
return forecastSessionUsage({ readings, nowMs, resetAtMs, percent: clampedPercent });
|
|
539
|
+
}
|
|
540
|
+
|
|
209
541
|
// src/utils/usage-prefetch.ts
|
|
210
542
|
var BASE_USAGE_WIDGET_TYPES = [
|
|
211
543
|
"session-usage",
|
|
544
|
+
"block-forecast",
|
|
545
|
+
"block-limit-timer",
|
|
212
546
|
"weekly-usage",
|
|
213
547
|
"block-timer",
|
|
214
548
|
"reset-timer",
|
|
@@ -216,7 +550,10 @@ var BASE_USAGE_WIDGET_TYPES = [
|
|
|
216
550
|
"extra-usage-utilization",
|
|
217
551
|
"extra-usage-remaining",
|
|
218
552
|
"extra-usage-used",
|
|
219
|
-
"extra-usage-
|
|
553
|
+
"extra-usage-limit",
|
|
554
|
+
"extra-usage-daily-budget",
|
|
555
|
+
"spend-limit-usage",
|
|
556
|
+
"spend-limit-amount"
|
|
220
557
|
];
|
|
221
558
|
var USAGE_WIDGET_TYPES = new Set([
|
|
222
559
|
...BASE_USAGE_WIDGET_TYPES,
|
|
@@ -228,6 +565,9 @@ var USAGE_DATA_FIELDS = [
|
|
|
228
565
|
"weeklyUsage",
|
|
229
566
|
"weeklyResetAt",
|
|
230
567
|
...WEEKLY_MODEL_USAGE_BUCKETS.flatMap((bucket) => [bucket.usageField, bucket.resetField]),
|
|
568
|
+
"spendLimitUsage",
|
|
569
|
+
"spendLimitUsedUsd",
|
|
570
|
+
"spendLimitLimitUsd",
|
|
231
571
|
"extraUsageEnabled",
|
|
232
572
|
"extraUsageLimit",
|
|
233
573
|
"extraUsageUsed",
|
|
@@ -237,6 +577,8 @@ var USAGE_DATA_FIELDS = [
|
|
|
237
577
|
var EMPTY_USAGE_REQUIREMENTS = [];
|
|
238
578
|
var USAGE_WIDGET_REQUIREMENTS = {
|
|
239
579
|
"session-usage": [{ field: "sessionUsage" }],
|
|
580
|
+
"block-forecast": [{ field: "sessionUsage", suppressFetchError: true }, { field: "sessionResetAt", suppressFetchError: true }],
|
|
581
|
+
"block-limit-timer": [{ field: "sessionUsage", suppressFetchError: true }, { field: "sessionResetAt", suppressFetchError: true }],
|
|
240
582
|
"weekly-usage": [{ field: "weeklyUsage" }],
|
|
241
583
|
...Object.fromEntries(WEEKLY_MODEL_USAGE_BUCKETS.map((bucket) => [bucket.widgetType, [{ field: bucket.usageField }]])),
|
|
242
584
|
"block-timer": [{ field: "sessionResetAt", suppressFetchError: true }],
|
|
@@ -255,6 +597,10 @@ var USAGE_WIDGET_REQUIREMENTS = {
|
|
|
255
597
|
{ field: "extraUsageEnabled" },
|
|
256
598
|
{ field: "extraUsageUsed" }
|
|
257
599
|
],
|
|
600
|
+
"extra-usage-limit": [
|
|
601
|
+
{ field: "extraUsageEnabled" },
|
|
602
|
+
{ field: "extraUsageLimit" }
|
|
603
|
+
],
|
|
258
604
|
"extra-usage-daily-budget": [
|
|
259
605
|
{ field: "extraUsageEnabled" },
|
|
260
606
|
{ field: "extraUsageLimit" },
|
|
@@ -266,6 +612,14 @@ var USAGE_CURSOR_REQUIREMENTS = {
|
|
|
266
612
|
"weekly-usage": { field: "weeklyResetAt" },
|
|
267
613
|
...Object.fromEntries(WEEKLY_MODEL_USAGE_BUCKETS.map((bucket) => [bucket.widgetType, { field: bucket.resetField, alternatives: ["weeklyResetAt"] }]))
|
|
268
614
|
};
|
|
615
|
+
var SESSION_LIMIT_HIDE_REQUIREMENT = { field: "sessionUsage", fromApi: true, suppressFetchError: true };
|
|
616
|
+
function readsSessionLimit(item) {
|
|
617
|
+
return item.type === "reset-timer" && isHidden(item, SESSION_UNDER_LIMIT_HIDEABLE_STATE.key) || item.type === "session-usage" && isHidden(item, SESSION_AT_LIMIT_HIDEABLE_STATE.key);
|
|
618
|
+
}
|
|
619
|
+
function isFromCurrentBlock(apiData) {
|
|
620
|
+
const resetAtMs = apiData.sessionResetAt === undefined ? Number.NaN : Date.parse(apiData.sessionResetAt);
|
|
621
|
+
return Number.isNaN(resetAtMs) || resetAtMs > Date.now();
|
|
622
|
+
}
|
|
269
623
|
function hasUsageDependentWidgets(lines) {
|
|
270
624
|
return lines.some((line) => line.some((item) => USAGE_WIDGET_TYPES.has(item.type)));
|
|
271
625
|
}
|
|
@@ -281,6 +635,9 @@ function getUsageFieldRequirements(lines) {
|
|
|
281
635
|
if (cursorRequirement && isUsageCursorEnabled(item)) {
|
|
282
636
|
requirements.push(cursorRequirement);
|
|
283
637
|
}
|
|
638
|
+
if (readsSessionLimit(item)) {
|
|
639
|
+
requirements.push(SESSION_LIMIT_HIDE_REQUIREMENT);
|
|
640
|
+
}
|
|
284
641
|
}
|
|
285
642
|
}
|
|
286
643
|
return requirements;
|
|
@@ -298,7 +655,7 @@ function getMissingFetchRequirements(data, requirements) {
|
|
|
298
655
|
const missing = new Set;
|
|
299
656
|
let hasUnsuppressedMissingRequirement = false;
|
|
300
657
|
for (const requirement of requirements) {
|
|
301
|
-
if (!isUsageRequirementSatisfied(data, requirement)) {
|
|
658
|
+
if (requirement.fromApi || !isUsageRequirementSatisfied(data, requirement)) {
|
|
302
659
|
missing.add(requirement.field);
|
|
303
660
|
if (!requirement.suppressFetchError) {
|
|
304
661
|
hasUnsuppressedMissingRequirement = true;
|
|
@@ -348,7 +705,10 @@ function extractUsageDataFromRateLimits(rateLimits) {
|
|
|
348
705
|
sessionUsage: rateLimits.five_hour?.used_percentage ?? undefined,
|
|
349
706
|
sessionResetAt: epochSecondsToIsoString(rateLimits.five_hour?.resets_at),
|
|
350
707
|
weeklyUsage: rateLimits.seven_day?.used_percentage ?? undefined,
|
|
351
|
-
weeklyResetAt: epochSecondsToIsoString(rateLimits.seven_day?.resets_at)
|
|
708
|
+
weeklyResetAt: epochSecondsToIsoString(rateLimits.seven_day?.resets_at),
|
|
709
|
+
spendLimitUsage: rateLimits.spend_limit?.used_percentage ?? undefined,
|
|
710
|
+
spendLimitUsedUsd: rateLimits.spend_limit?.used_usd ?? undefined,
|
|
711
|
+
spendLimitLimitUsd: rateLimits.spend_limit?.limit_usd ?? undefined
|
|
352
712
|
};
|
|
353
713
|
for (const bucket of WEEKLY_MODEL_USAGE_BUCKETS) {
|
|
354
714
|
if (!bucket.apiBucketKey) {
|
|
@@ -373,9 +733,13 @@ async function prefetchUsageDataIfNeeded(lines, data) {
|
|
|
373
733
|
}
|
|
374
734
|
const apiData = await fetchUsageData({ requiredFields: missingFields });
|
|
375
735
|
if (apiData.error && missingRequirements.suppressFetchError) {
|
|
376
|
-
return rateLimitsData;
|
|
736
|
+
return hasAnyUsageDataField(apiData) ? mergeUsageData(rateLimitsData, { ...apiData, error: undefined }) : rateLimitsData;
|
|
377
737
|
}
|
|
378
|
-
|
|
738
|
+
const usageData = mergeUsageData(rateLimitsData, apiData);
|
|
739
|
+
if (requirements.includes(SESSION_LIMIT_HIDE_REQUIREMENT) && apiData.sessionUsage !== undefined && isFromCurrentBlock(apiData) && !isStaleUsageFallback(apiData)) {
|
|
740
|
+
usageData.apiSessionUsage = apiData.sessionUsage;
|
|
741
|
+
}
|
|
742
|
+
return usageData;
|
|
379
743
|
}
|
|
380
744
|
|
|
381
745
|
// src/utils/windows-code-page.ts
|
|
@@ -390,10 +754,19 @@ function ensureWindowsUtf8CodePage(platform = process.platform) {
|
|
|
390
754
|
}
|
|
391
755
|
|
|
392
756
|
// src/ccstatusline.ts
|
|
757
|
+
var LAUNCH_ARGS = process.argv.slice(2);
|
|
393
758
|
function hasSessionDurationInStatusJson(data) {
|
|
394
759
|
const durationMs = data.cost?.total_duration_ms;
|
|
395
760
|
return typeof durationMs === "number" && Number.isFinite(durationMs) && durationMs >= 0;
|
|
396
761
|
}
|
|
762
|
+
var DISPATCHABLE_HOOK_EVENT_NAMES = new Set(["PreToolUse", "UserPromptSubmit"]);
|
|
763
|
+
function isDispatchableHookPayload(data) {
|
|
764
|
+
if (typeof data !== "object" || data === null) {
|
|
765
|
+
return false;
|
|
766
|
+
}
|
|
767
|
+
const { hook_event_name: hookEventName, session_id: sessionId } = data;
|
|
768
|
+
return typeof hookEventName === "string" && DISPATCHABLE_HOOK_EVENT_NAMES.has(hookEventName) && typeof sessionId === "string" && sessionId.length > 0;
|
|
769
|
+
}
|
|
397
770
|
async function readStdin() {
|
|
398
771
|
if (process.stdin.isTTY) {
|
|
399
772
|
return null;
|
|
@@ -428,6 +801,7 @@ async function renderMultipleLines(data) {
|
|
|
428
801
|
const hasCompactionWidget = lines.some((line) => line.some((item) => item.type === "compaction-counter"));
|
|
429
802
|
const hasThinkingEffortWidget = lines.some((line) => line.some((item) => item.type === "thinking-effort"));
|
|
430
803
|
const hasSessionNameWidget = lines.some((line) => line.some((item) => item.type === "session-name"));
|
|
804
|
+
const hasAccountEmailWidget = lines.some((line) => line.some((item) => item.type === "claude-account-email"));
|
|
431
805
|
const needsTranscriptThinkingEffort = hasThinkingEffortWidget && (!data.effort || !("level" in data.effort));
|
|
432
806
|
const requestedSpeedWindows = new Set;
|
|
433
807
|
for (const line of lines) {
|
|
@@ -446,11 +820,13 @@ async function renderMultipleLines(data) {
|
|
|
446
820
|
includeThinkingEffort: needsTranscriptThinkingEffort,
|
|
447
821
|
includeSessionName: hasSessionNameWidget
|
|
448
822
|
}) : Promise.resolve(null);
|
|
449
|
-
const [transcriptAnalysis, usageData, claudeStatusData] = await Promise.all([
|
|
823
|
+
const [transcriptAnalysis, usageData, claudeStatusData, accountEmail] = await Promise.all([
|
|
450
824
|
transcriptAnalysisPromise,
|
|
451
825
|
prefetchUsageDataIfNeeded(lines, data),
|
|
452
|
-
prefetchClaudeStatusIfNeeded(lines)
|
|
826
|
+
prefetchClaudeStatusIfNeeded(lines),
|
|
827
|
+
hasAccountEmailWidget ? fetchAccountEmail() : Promise.resolve(undefined)
|
|
453
828
|
]);
|
|
829
|
+
const sessionForecast = computeSessionForecastIfNeeded(lines, usageData, getDefaultSessionUsageHistoryDeps(data));
|
|
454
830
|
const tokenMetrics = transcriptAnalysis?.tokenMetrics ?? null;
|
|
455
831
|
const sessionDuration = transcriptAnalysis?.sessionDuration ?? null;
|
|
456
832
|
const speedMetrics = transcriptAnalysis?.speedMetricsCollection?.sessionAverage ?? null;
|
|
@@ -466,7 +842,9 @@ async function renderMultipleLines(data) {
|
|
|
466
842
|
speedMetrics,
|
|
467
843
|
windowedSpeedMetrics,
|
|
468
844
|
usageData,
|
|
845
|
+
sessionForecast,
|
|
469
846
|
claudeStatusData,
|
|
847
|
+
accountEmail,
|
|
470
848
|
sessionDuration,
|
|
471
849
|
transcriptSessionName: hasSessionNameWidget ? transcriptAnalysis?.sessionName ?? null : undefined,
|
|
472
850
|
transcriptThinkingEffort: needsTranscriptThinkingEffort ? transcriptAnalysis?.thinkingEffort ?? null : undefined,
|
|
@@ -587,7 +965,12 @@ async function main() {
|
|
|
587
965
|
const input = await readStdin();
|
|
588
966
|
if (input && input.trim() !== "") {
|
|
589
967
|
try {
|
|
590
|
-
const
|
|
968
|
+
const parsed = JSON.parse(input);
|
|
969
|
+
if (isDispatchableHookPayload(parsed)) {
|
|
970
|
+
handleHookInput(input);
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
const result = StatusJSONSchema.safeParse(parsed);
|
|
591
974
|
if (!result.success) {
|
|
592
975
|
console.error("Invalid status JSON format:", result.error.message);
|
|
593
976
|
process.exit(1);
|
|
@@ -602,12 +985,18 @@ async function main() {
|
|
|
602
985
|
process.exit(1);
|
|
603
986
|
}
|
|
604
987
|
} else {
|
|
988
|
+
if (process.env.CCSTATUSLINE_DEV_RELOAD === "1") {
|
|
989
|
+
const { getDevReloadMode, superviseDevReload } = await import("./dev-reload-egdx2kp5.js");
|
|
990
|
+
if (getDevReloadMode(process.env) === "supervisor") {
|
|
991
|
+
process.exit(await superviseDevReload(LAUNCH_ARGS));
|
|
992
|
+
}
|
|
993
|
+
}
|
|
605
994
|
const settings = await loadSettings();
|
|
606
995
|
if (settings.updatemessage) {
|
|
607
996
|
const { updatemessage, ...newSettings } = settings;
|
|
608
997
|
await saveSettings(newSettings);
|
|
609
998
|
}
|
|
610
|
-
const { runTUI } = await import("./index-
|
|
999
|
+
const { runTUI } = await import("./index-7sf5nvak.js");
|
|
611
1000
|
runTUI();
|
|
612
1001
|
}
|
|
613
1002
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEV_RELOAD_EXIT_CODE2,
|
|
3
|
+
getDevReloadMode2,
|
|
4
|
+
getDevReloadStateFile2,
|
|
5
|
+
writeDevReloadSnapshot2,
|
|
6
|
+
discardDevReloadSnapshot2,
|
|
7
|
+
readDevReloadSnapshot2,
|
|
8
|
+
requestDevReload2,
|
|
9
|
+
isDevReloadRequested2,
|
|
10
|
+
superviseDevReload2
|
|
11
|
+
} from "./ccstatusline-j1gdxtq4.js";
|
|
12
|
+
import"./ccstatusline-88bs860s.js";
|
|
13
|
+
export {
|
|
14
|
+
DEV_RELOAD_EXIT_CODE2 as DEV_RELOAD_EXIT_CODE,
|
|
15
|
+
discardDevReloadSnapshot2 as discardDevReloadSnapshot,
|
|
16
|
+
getDevReloadMode2 as getDevReloadMode,
|
|
17
|
+
getDevReloadStateFile2 as getDevReloadStateFile,
|
|
18
|
+
isDevReloadRequested2 as isDevReloadRequested,
|
|
19
|
+
readDevReloadSnapshot2 as readDevReloadSnapshot,
|
|
20
|
+
requestDevReload2 as requestDevReload,
|
|
21
|
+
superviseDevReload2 as superviseDevReload,
|
|
22
|
+
writeDevReloadSnapshot2 as writeDevReloadSnapshot
|
|
23
|
+
};
|