ccstatusline-zh 2.2.34 → 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 +18 -7
- package/dist/{ccstatusline-rdsx5ab1.js → ccstatusline-71188a0p.js} +23 -25
- package/dist/ccstatusline-88bs860s.js +6063 -0
- package/dist/{ccstatusline-jp52tswn.js → ccstatusline-98magj3t.js} +1578 -6733
- package/dist/ccstatusline-j1gdxtq4.js +180 -0
- package/dist/ccstatusline.js +390 -15
- package/dist/dev-reload-egdx2kp5.js +23 -0
- package/dist/{hooks-0wev7tf6.js → hooks-zr7bxw3x.js} +23 -14
- package/dist/{index-pzts8765.js → index-7sf5nvak.js} +302 -81
- package/package.json +3 -3
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) => {
|
|
@@ -102,6 +115,7 @@ var StatusJSONSchema = looseObject({
|
|
|
102
115
|
remaining_percentage: CoercedNumberSchema.nullable().optional()
|
|
103
116
|
}).nullable().optional(),
|
|
104
117
|
vim: object({ mode: string().optional() }).nullable().optional(),
|
|
118
|
+
fast_mode: boolean().nullable().optional().catch(undefined),
|
|
105
119
|
worktree: object({
|
|
106
120
|
name: string().optional(),
|
|
107
121
|
path: string().optional(),
|
|
@@ -109,6 +123,14 @@ var StatusJSONSchema = looseObject({
|
|
|
109
123
|
original_cwd: string().optional(),
|
|
110
124
|
original_branch: string().optional()
|
|
111
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(),
|
|
112
134
|
rate_limits: object({
|
|
113
135
|
five_hour: RateLimitPeriodSchema.optional(),
|
|
114
136
|
seven_day: RateLimitPeriodSchema.optional(),
|
|
@@ -212,9 +234,315 @@ function handleHookInput(input) {
|
|
|
212
234
|
} catch {}
|
|
213
235
|
}
|
|
214
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
|
+
|
|
215
541
|
// src/utils/usage-prefetch.ts
|
|
216
542
|
var BASE_USAGE_WIDGET_TYPES = [
|
|
217
543
|
"session-usage",
|
|
544
|
+
"block-forecast",
|
|
545
|
+
"block-limit-timer",
|
|
218
546
|
"weekly-usage",
|
|
219
547
|
"block-timer",
|
|
220
548
|
"reset-timer",
|
|
@@ -222,6 +550,7 @@ var BASE_USAGE_WIDGET_TYPES = [
|
|
|
222
550
|
"extra-usage-utilization",
|
|
223
551
|
"extra-usage-remaining",
|
|
224
552
|
"extra-usage-used",
|
|
553
|
+
"extra-usage-limit",
|
|
225
554
|
"extra-usage-daily-budget",
|
|
226
555
|
"spend-limit-usage",
|
|
227
556
|
"spend-limit-amount"
|
|
@@ -248,6 +577,8 @@ var USAGE_DATA_FIELDS = [
|
|
|
248
577
|
var EMPTY_USAGE_REQUIREMENTS = [];
|
|
249
578
|
var USAGE_WIDGET_REQUIREMENTS = {
|
|
250
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 }],
|
|
251
582
|
"weekly-usage": [{ field: "weeklyUsage" }],
|
|
252
583
|
...Object.fromEntries(WEEKLY_MODEL_USAGE_BUCKETS.map((bucket) => [bucket.widgetType, [{ field: bucket.usageField }]])),
|
|
253
584
|
"block-timer": [{ field: "sessionResetAt", suppressFetchError: true }],
|
|
@@ -266,6 +597,10 @@ var USAGE_WIDGET_REQUIREMENTS = {
|
|
|
266
597
|
{ field: "extraUsageEnabled" },
|
|
267
598
|
{ field: "extraUsageUsed" }
|
|
268
599
|
],
|
|
600
|
+
"extra-usage-limit": [
|
|
601
|
+
{ field: "extraUsageEnabled" },
|
|
602
|
+
{ field: "extraUsageLimit" }
|
|
603
|
+
],
|
|
269
604
|
"extra-usage-daily-budget": [
|
|
270
605
|
{ field: "extraUsageEnabled" },
|
|
271
606
|
{ field: "extraUsageLimit" },
|
|
@@ -277,6 +612,14 @@ var USAGE_CURSOR_REQUIREMENTS = {
|
|
|
277
612
|
"weekly-usage": { field: "weeklyResetAt" },
|
|
278
613
|
...Object.fromEntries(WEEKLY_MODEL_USAGE_BUCKETS.map((bucket) => [bucket.widgetType, { field: bucket.resetField, alternatives: ["weeklyResetAt"] }]))
|
|
279
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
|
+
}
|
|
280
623
|
function hasUsageDependentWidgets(lines) {
|
|
281
624
|
return lines.some((line) => line.some((item) => USAGE_WIDGET_TYPES.has(item.type)));
|
|
282
625
|
}
|
|
@@ -292,6 +635,9 @@ function getUsageFieldRequirements(lines) {
|
|
|
292
635
|
if (cursorRequirement && isUsageCursorEnabled(item)) {
|
|
293
636
|
requirements.push(cursorRequirement);
|
|
294
637
|
}
|
|
638
|
+
if (readsSessionLimit(item)) {
|
|
639
|
+
requirements.push(SESSION_LIMIT_HIDE_REQUIREMENT);
|
|
640
|
+
}
|
|
295
641
|
}
|
|
296
642
|
}
|
|
297
643
|
return requirements;
|
|
@@ -309,7 +655,7 @@ function getMissingFetchRequirements(data, requirements) {
|
|
|
309
655
|
const missing = new Set;
|
|
310
656
|
let hasUnsuppressedMissingRequirement = false;
|
|
311
657
|
for (const requirement of requirements) {
|
|
312
|
-
if (!isUsageRequirementSatisfied(data, requirement)) {
|
|
658
|
+
if (requirement.fromApi || !isUsageRequirementSatisfied(data, requirement)) {
|
|
313
659
|
missing.add(requirement.field);
|
|
314
660
|
if (!requirement.suppressFetchError) {
|
|
315
661
|
hasUnsuppressedMissingRequirement = true;
|
|
@@ -387,9 +733,13 @@ async function prefetchUsageDataIfNeeded(lines, data) {
|
|
|
387
733
|
}
|
|
388
734
|
const apiData = await fetchUsageData({ requiredFields: missingFields });
|
|
389
735
|
if (apiData.error && missingRequirements.suppressFetchError) {
|
|
390
|
-
return rateLimitsData;
|
|
736
|
+
return hasAnyUsageDataField(apiData) ? mergeUsageData(rateLimitsData, { ...apiData, error: undefined }) : rateLimitsData;
|
|
391
737
|
}
|
|
392
|
-
|
|
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;
|
|
393
743
|
}
|
|
394
744
|
|
|
395
745
|
// src/utils/windows-code-page.ts
|
|
@@ -404,10 +754,19 @@ function ensureWindowsUtf8CodePage(platform = process.platform) {
|
|
|
404
754
|
}
|
|
405
755
|
|
|
406
756
|
// src/ccstatusline.ts
|
|
757
|
+
var LAUNCH_ARGS = process.argv.slice(2);
|
|
407
758
|
function hasSessionDurationInStatusJson(data) {
|
|
408
759
|
const durationMs = data.cost?.total_duration_ms;
|
|
409
760
|
return typeof durationMs === "number" && Number.isFinite(durationMs) && durationMs >= 0;
|
|
410
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
|
+
}
|
|
411
770
|
async function readStdin() {
|
|
412
771
|
if (process.stdin.isTTY) {
|
|
413
772
|
return null;
|
|
@@ -442,6 +801,7 @@ async function renderMultipleLines(data) {
|
|
|
442
801
|
const hasCompactionWidget = lines.some((line) => line.some((item) => item.type === "compaction-counter"));
|
|
443
802
|
const hasThinkingEffortWidget = lines.some((line) => line.some((item) => item.type === "thinking-effort"));
|
|
444
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"));
|
|
445
805
|
const needsTranscriptThinkingEffort = hasThinkingEffortWidget && (!data.effort || !("level" in data.effort));
|
|
446
806
|
const requestedSpeedWindows = new Set;
|
|
447
807
|
for (const line of lines) {
|
|
@@ -460,11 +820,13 @@ async function renderMultipleLines(data) {
|
|
|
460
820
|
includeThinkingEffort: needsTranscriptThinkingEffort,
|
|
461
821
|
includeSessionName: hasSessionNameWidget
|
|
462
822
|
}) : Promise.resolve(null);
|
|
463
|
-
const [transcriptAnalysis, usageData, claudeStatusData] = await Promise.all([
|
|
823
|
+
const [transcriptAnalysis, usageData, claudeStatusData, accountEmail] = await Promise.all([
|
|
464
824
|
transcriptAnalysisPromise,
|
|
465
825
|
prefetchUsageDataIfNeeded(lines, data),
|
|
466
|
-
prefetchClaudeStatusIfNeeded(lines)
|
|
826
|
+
prefetchClaudeStatusIfNeeded(lines),
|
|
827
|
+
hasAccountEmailWidget ? fetchAccountEmail() : Promise.resolve(undefined)
|
|
467
828
|
]);
|
|
829
|
+
const sessionForecast = computeSessionForecastIfNeeded(lines, usageData, getDefaultSessionUsageHistoryDeps(data));
|
|
468
830
|
const tokenMetrics = transcriptAnalysis?.tokenMetrics ?? null;
|
|
469
831
|
const sessionDuration = transcriptAnalysis?.sessionDuration ?? null;
|
|
470
832
|
const speedMetrics = transcriptAnalysis?.speedMetricsCollection?.sessionAverage ?? null;
|
|
@@ -480,7 +842,9 @@ async function renderMultipleLines(data) {
|
|
|
480
842
|
speedMetrics,
|
|
481
843
|
windowedSpeedMetrics,
|
|
482
844
|
usageData,
|
|
845
|
+
sessionForecast,
|
|
483
846
|
claudeStatusData,
|
|
847
|
+
accountEmail,
|
|
484
848
|
sessionDuration,
|
|
485
849
|
transcriptSessionName: hasSessionNameWidget ? transcriptAnalysis?.sessionName ?? null : undefined,
|
|
486
850
|
transcriptThinkingEffort: needsTranscriptThinkingEffort ? transcriptAnalysis?.thinkingEffort ?? null : undefined,
|
|
@@ -601,7 +965,12 @@ async function main() {
|
|
|
601
965
|
const input = await readStdin();
|
|
602
966
|
if (input && input.trim() !== "") {
|
|
603
967
|
try {
|
|
604
|
-
const
|
|
968
|
+
const parsed = JSON.parse(input);
|
|
969
|
+
if (isDispatchableHookPayload(parsed)) {
|
|
970
|
+
handleHookInput(input);
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
const result = StatusJSONSchema.safeParse(parsed);
|
|
605
974
|
if (!result.success) {
|
|
606
975
|
console.error("Invalid status JSON format:", result.error.message);
|
|
607
976
|
process.exit(1);
|
|
@@ -616,12 +985,18 @@ async function main() {
|
|
|
616
985
|
process.exit(1);
|
|
617
986
|
}
|
|
618
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
|
+
}
|
|
619
994
|
const settings = await loadSettings();
|
|
620
995
|
if (settings.updatemessage) {
|
|
621
996
|
const { updatemessage, ...newSettings } = settings;
|
|
622
997
|
await saveSettings(newSettings);
|
|
623
998
|
}
|
|
624
|
-
const { runTUI } = await import("./index-
|
|
999
|
+
const { runTUI } = await import("./index-7sf5nvak.js");
|
|
625
1000
|
runTUI();
|
|
626
1001
|
}
|
|
627
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
|
+
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import"./ccstatusline-88bs860s.js";
|
|
1
2
|
import {
|
|
2
3
|
loadClaudeSettings,
|
|
3
4
|
saveClaudeSettings,
|
|
4
5
|
getExistingStatusLine,
|
|
5
6
|
getWidget
|
|
6
|
-
} from "./ccstatusline-
|
|
7
|
+
} from "./ccstatusline-98magj3t.js";
|
|
7
8
|
|
|
8
9
|
// src/utils/hooks.ts
|
|
9
10
|
var HOOK_TAG = "ccstatusline-managed";
|
|
@@ -44,28 +45,35 @@ function stripManagedHooks(hooks) {
|
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
|
-
function
|
|
48
|
-
const
|
|
49
|
-
const defs = [];
|
|
48
|
+
function getHookWidgets(settings) {
|
|
49
|
+
const widgets = new Set;
|
|
50
50
|
for (const line of settings.lines) {
|
|
51
51
|
for (const item of line) {
|
|
52
52
|
const widget = getWidget(item.type);
|
|
53
|
-
if (
|
|
54
|
-
|
|
53
|
+
if (hasWidgetHooks(widget)) {
|
|
54
|
+
widgets.add(widget);
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return [...widgets];
|
|
59
|
+
}
|
|
60
|
+
function getActiveHookDefs(widgets) {
|
|
61
|
+
const seen = new Set;
|
|
62
|
+
const defs = [];
|
|
63
|
+
for (const widget of widgets) {
|
|
64
|
+
for (const hook of widget.getHooks()) {
|
|
65
|
+
const key = `${hook.event}:${hook.matcher ?? ""}`;
|
|
66
|
+
if (!seen.has(key)) {
|
|
67
|
+
seen.add(key);
|
|
68
|
+
defs.push(hook);
|
|
62
69
|
}
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
72
|
return defs;
|
|
66
73
|
}
|
|
67
74
|
async function syncWidgetHooks(settings) {
|
|
68
|
-
const
|
|
75
|
+
const hookWidgets = getHookWidgets(settings);
|
|
76
|
+
const needed = getActiveHookDefs(hookWidgets);
|
|
69
77
|
const claudeSettings = await loadClaudeSettings({ logErrors: false });
|
|
70
78
|
const hooks = claudeSettings.hooks ?? {};
|
|
71
79
|
stripManagedHooks(hooks);
|
|
@@ -73,7 +81,7 @@ async function syncWidgetHooks(settings) {
|
|
|
73
81
|
if (!statusCommand?.includes("ccstatusline")) {
|
|
74
82
|
claudeSettings.hooks = Object.keys(hooks).length > 0 ? hooks : undefined;
|
|
75
83
|
await saveClaudeSettings(claudeSettings);
|
|
76
|
-
return;
|
|
84
|
+
return statusCommand && needed.length > 0 ? { statusCommand, widgetNames: hookWidgets.map((widget) => widget.getDisplayName()) } : null;
|
|
77
85
|
}
|
|
78
86
|
const hookCommand = `${statusCommand} --hook`;
|
|
79
87
|
for (const def of needed) {
|
|
@@ -89,6 +97,7 @@ async function syncWidgetHooks(settings) {
|
|
|
89
97
|
}
|
|
90
98
|
claudeSettings.hooks = Object.keys(hooks).length > 0 ? hooks : undefined;
|
|
91
99
|
await saveClaudeSettings(claudeSettings);
|
|
100
|
+
return null;
|
|
92
101
|
}
|
|
93
102
|
async function removeManagedHooks() {
|
|
94
103
|
const claudeSettings = await loadClaudeSettings({ logErrors: false });
|