ccstatusline-zh 2.2.36 → 2.2.37
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
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
_在终端中显示模型信息、Git 分支、Token 用量及其他实时指标_
|
|
6
6
|
|
|
7
|
-
> 本项目是 [ccstatusline](https://github.com/sirmalloc/ccstatusline) 的**中文汉化 Fork**,当前中文包版本为 **2.2.
|
|
7
|
+
> 本项目是 [ccstatusline](https://github.com/sirmalloc/ccstatusline) 的**中文汉化 Fork**,当前中文包版本为 **2.2.37**,同步至上游 **v2.2.34 / main@0c94df7**(2026-11-13 核对,新增提示缓存未命中、周额度耗尽计时和今日超额用量组件,支持细线进度条、Zed 链接及 256 色网格选色,移除终端宽度菜单)。用户界面保持中文,组件标识符、配置字段和纯值输出与上游兼容。
|
|
8
8
|
>
|
|
9
9
|
> 本次同步的完整上游提交:[`0c94df755665ed7794f082863821fd5f428cdf60`](https://github.com/sirmalloc/ccstatusline/commit/0c94df755665ed7794f082863821fd5f428cdf60)。后续同步以此提交为基线,中文包与上游版本号独立递增。
|
|
10
10
|
|
|
@@ -67,8 +67,8 @@ ccstatusline 是一个优秀的 Claude Code CLI 状态栏格式化工具,支
|
|
|
67
67
|
| ---------- | ------------ | ------------------------- |
|
|
68
68
|
| 界面语言 | 英文 | 中文 |
|
|
69
69
|
| 配置兼容性 | — | ✅ 共用相同 settings.json |
|
|
70
|
-
| 功能差异 | — |
|
|
71
|
-
| 同步版本 | 最新 | v2.2.34 / [main@0c94df7](https://github.com/sirmalloc/ccstatusline/commit/0c94df755665ed7794f082863821fd5f428cdf60)(中文包 2.2.
|
|
70
|
+
| 功能差异 | — | 功能一致;2.2.37 额外修复了用量时段回退扫描:不再跟随会话目录中的符号链接,扫描进度逐文件缓存并分次续扫,不再阻塞状态栏 |
|
|
71
|
+
| 同步版本 | 最新 | v2.2.34 / [main@0c94df7](https://github.com/sirmalloc/ccstatusline/commit/0c94df755665ed7794f082863821fd5f428cdf60)(中文包 2.2.37) |
|
|
72
72
|
|
|
73
73
|
---
|
|
74
74
|
|
|
@@ -16509,7 +16509,7 @@ function accumulateCompactionStats(stats, record) {
|
|
|
16509
16509
|
// src/utils/config.ts
|
|
16510
16510
|
import * as fs20 from "node:fs";
|
|
16511
16511
|
import * as os14 from "node:os";
|
|
16512
|
-
import * as
|
|
16512
|
+
import * as path16 from "node:path";
|
|
16513
16513
|
|
|
16514
16514
|
// src/utils/guid.ts
|
|
16515
16515
|
function generateGuid() {
|
|
@@ -17042,7 +17042,7 @@ function writeCachedWidth(sessionId, width, deps = defaultDeps2) {
|
|
|
17042
17042
|
|
|
17043
17043
|
// src/utils/terminal.ts
|
|
17044
17044
|
var __dirname = "/home/runner/work/ccstatusline-zh/ccstatusline-zh/src/utils";
|
|
17045
|
-
var PACKAGE_VERSION = "2.2.
|
|
17045
|
+
var PACKAGE_VERSION = "2.2.37";
|
|
17046
17046
|
function getPackageVersion() {
|
|
17047
17047
|
if (/^\d+\.\d+\.\d+/.test(PACKAGE_VERSION)) {
|
|
17048
17048
|
return PACKAGE_VERSION;
|
|
@@ -29058,13 +29058,13 @@ async function installStatusLine({
|
|
|
29058
29058
|
}
|
|
29059
29059
|
const savedSettings = await loadSavedSettingsForHookSync();
|
|
29060
29060
|
if (savedSettings) {
|
|
29061
|
-
const { syncWidgetHooks } = await import("./hooks-
|
|
29061
|
+
const { syncWidgetHooks } = await import("./hooks-x0y49hsa.js");
|
|
29062
29062
|
await syncWidgetHooks(savedSettings);
|
|
29063
29063
|
}
|
|
29064
29064
|
}
|
|
29065
29065
|
async function uninstallStatusLine() {
|
|
29066
29066
|
const settings = await loadClaudeSettingsForUpdate("重新卸载");
|
|
29067
|
-
const { stripManagedHooksFromSettings } = await import("./hooks-
|
|
29067
|
+
const { stripManagedHooksFromSettings } = await import("./hooks-x0y49hsa.js");
|
|
29068
29068
|
const hadStatusLine = Boolean(settings.statusLine);
|
|
29069
29069
|
delete settings.statusLine;
|
|
29070
29070
|
const hadManagedHooks = stripManagedHooksFromSettings(settings);
|
|
@@ -31139,13 +31139,15 @@ async function fetchAccountEmail() {
|
|
|
31139
31139
|
return email === null ? { status: "unavailable" } : { status: "available", email };
|
|
31140
31140
|
}
|
|
31141
31141
|
// src/utils/jsonl-cache.ts
|
|
31142
|
-
import { createHash as
|
|
31142
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
31143
31143
|
import * as fs16 from "node:fs";
|
|
31144
31144
|
import os11 from "node:os";
|
|
31145
|
-
import
|
|
31145
|
+
import path14 from "node:path";
|
|
31146
31146
|
|
|
31147
31147
|
// src/utils/jsonl-blocks.ts
|
|
31148
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
31148
31149
|
import * as fs15 from "node:fs";
|
|
31150
|
+
import path13 from "node:path";
|
|
31149
31151
|
|
|
31150
31152
|
// node_modules/tinyglobby/dist/index.mjs
|
|
31151
31153
|
import { readdir, readdirSync as readdirSync3, realpath, realpathSync as realpathSync3, stat as stat2, statSync as statSync9 } from "fs";
|
|
@@ -32079,27 +32081,6 @@ async function* iterateJsonlLines(filePath) {
|
|
|
32079
32081
|
stream.destroy();
|
|
32080
32082
|
}
|
|
32081
32083
|
}
|
|
32082
|
-
function* iterateJsonlLinesSync(filePath) {
|
|
32083
|
-
const fd = fs14.openSync(filePath, "r");
|
|
32084
|
-
try {
|
|
32085
|
-
const scratch = Buffer.allocUnsafe(JSONL_READ_CHUNK_BYTES);
|
|
32086
|
-
const splitter = new JsonlLineSplitter;
|
|
32087
|
-
for (;; ) {
|
|
32088
|
-
const bytesRead = fs14.readSync(fd, scratch, 0, scratch.length, null);
|
|
32089
|
-
if (bytesRead === 0) {
|
|
32090
|
-
break;
|
|
32091
|
-
}
|
|
32092
|
-
for (const line of splitter.write(scratch.subarray(0, bytesRead))) {
|
|
32093
|
-
yield line;
|
|
32094
|
-
}
|
|
32095
|
-
}
|
|
32096
|
-
for (const line of splitter.end()) {
|
|
32097
|
-
yield line;
|
|
32098
|
-
}
|
|
32099
|
-
} finally {
|
|
32100
|
-
fs14.closeSync(fd);
|
|
32101
|
-
}
|
|
32102
|
-
}
|
|
32103
32084
|
function* iterateJsonlLinesReverseSync(filePath) {
|
|
32104
32085
|
const fd = fs14.openSync(filePath, "r");
|
|
32105
32086
|
try {
|
|
@@ -32153,49 +32134,197 @@ function parseJsonlLine(line) {
|
|
|
32153
32134
|
}
|
|
32154
32135
|
|
|
32155
32136
|
// src/utils/jsonl-blocks.ts
|
|
32156
|
-
var
|
|
32157
|
-
|
|
32158
|
-
|
|
32159
|
-
|
|
32137
|
+
var LOOKBACK_HOURS = [10, 20, 48];
|
|
32138
|
+
var MAX_LOOKBACK_MS = 48 * 60 * 60 * 1000;
|
|
32139
|
+
var TRANSCRIPT_CACHE_VERSION = 2;
|
|
32140
|
+
var SCAN_STATE_VERSION = 1;
|
|
32141
|
+
var SCAN_STATE_MAX_AGE_MS = 15 * 60 * 1000;
|
|
32142
|
+
var SCAN_STATE_FILE = "scan-state.json";
|
|
32143
|
+
function isDeadlineExceeded(deadlineMs) {
|
|
32144
|
+
return deadlineMs !== undefined && Date.now() >= deadlineMs;
|
|
32145
|
+
}
|
|
32146
|
+
function getTranscriptCachePath(cacheDir, filePath) {
|
|
32147
|
+
const fileHash = createHash5("sha256").update(filePath).digest("hex");
|
|
32148
|
+
return path13.join(cacheDir, `${fileHash}.json`);
|
|
32149
|
+
}
|
|
32150
|
+
function writeJsonAtomic(cachePath, value) {
|
|
32151
|
+
const temporaryPath = `${cachePath}.${process.pid}.tmp`;
|
|
32152
|
+
try {
|
|
32153
|
+
const serialized = JSON.stringify(value);
|
|
32154
|
+
fs15.mkdirSync(path13.dirname(cachePath), { recursive: true });
|
|
32155
|
+
fs15.writeFileSync(temporaryPath, serialized, "utf8");
|
|
32156
|
+
fs15.renameSync(temporaryPath, cachePath);
|
|
32157
|
+
} catch {
|
|
32158
|
+
try {
|
|
32159
|
+
fs15.rmSync(temporaryPath, { force: true });
|
|
32160
|
+
} catch {}
|
|
32161
|
+
}
|
|
32162
|
+
}
|
|
32163
|
+
function readTranscriptCache(cacheDir, filePath) {
|
|
32164
|
+
if (!cacheDir) {
|
|
32160
32165
|
return null;
|
|
32166
|
+
}
|
|
32161
32167
|
try {
|
|
32162
|
-
|
|
32168
|
+
const cache = JSON.parse(fs15.readFileSync(getTranscriptCachePath(cacheDir, filePath), "utf8"));
|
|
32169
|
+
const validNumbers = [cache.mtimeMs, cache.size, cache.offset].every((value) => typeof value === "number" && Number.isFinite(value) && value >= 0);
|
|
32170
|
+
if (cache.version !== TRANSCRIPT_CACHE_VERSION || cache.filePath !== filePath || !validNumbers || typeof cache.remainder !== "string" || typeof cache.firstLine !== "boolean" || typeof cache.complete !== "boolean" || !Array.isArray(cache.timestamps) || !cache.timestamps.every((timestamp) => typeof timestamp === "number" && Number.isFinite(timestamp))) {
|
|
32171
|
+
return null;
|
|
32172
|
+
}
|
|
32173
|
+
return cache;
|
|
32163
32174
|
} catch {
|
|
32164
32175
|
return null;
|
|
32165
32176
|
}
|
|
32166
32177
|
}
|
|
32167
|
-
function
|
|
32168
|
-
|
|
32169
|
-
|
|
32178
|
+
function writeTranscriptCache(cacheDir, filePath, cache) {
|
|
32179
|
+
if (cacheDir) {
|
|
32180
|
+
writeJsonAtomic(getTranscriptCachePath(cacheDir, filePath), cache);
|
|
32181
|
+
}
|
|
32182
|
+
}
|
|
32183
|
+
function getScanStatePath(cacheDir) {
|
|
32184
|
+
return path13.join(cacheDir, SCAN_STATE_FILE);
|
|
32185
|
+
}
|
|
32186
|
+
function readScanState(cacheDir, rootDir) {
|
|
32187
|
+
if (!cacheDir) {
|
|
32188
|
+
return null;
|
|
32189
|
+
}
|
|
32190
|
+
try {
|
|
32191
|
+
const state = JSON.parse(fs15.readFileSync(getScanStatePath(cacheDir), "utf8"));
|
|
32192
|
+
const validFiles = Array.isArray(state.files) && state.files.every((file) => typeof file.file === "string" && typeof file.mtimeMs === "number" && Number.isFinite(file.mtimeMs) && file.mtimeMs >= 0 && typeof file.size === "number" && Number.isFinite(file.size) && file.size >= 0);
|
|
32193
|
+
if (state.version !== SCAN_STATE_VERSION || state.rootDir !== rootDir || typeof state.nowMs !== "number" || !Number.isFinite(state.nowMs) || typeof state.nextFileIndex !== "number" || !Number.isInteger(state.nextFileIndex) || state.nextFileIndex < 0 || !validFiles || !state.files || state.nextFileIndex > state.files.length) {
|
|
32194
|
+
return null;
|
|
32195
|
+
}
|
|
32196
|
+
return state;
|
|
32197
|
+
} catch {
|
|
32198
|
+
return null;
|
|
32199
|
+
}
|
|
32200
|
+
}
|
|
32201
|
+
function writeScanState(cacheDir, state) {
|
|
32202
|
+
if (cacheDir) {
|
|
32203
|
+
writeJsonAtomic(getScanStatePath(cacheDir), state);
|
|
32204
|
+
}
|
|
32205
|
+
}
|
|
32206
|
+
function removeScanState(cacheDir) {
|
|
32207
|
+
if (!cacheDir) {
|
|
32208
|
+
return;
|
|
32209
|
+
}
|
|
32210
|
+
try {
|
|
32211
|
+
fs15.rmSync(getScanStatePath(cacheDir), { force: true });
|
|
32212
|
+
} catch {}
|
|
32213
|
+
}
|
|
32214
|
+
function discoverTranscriptFiles(rootDir, nowMs) {
|
|
32170
32215
|
const files = globSync(["projects/**/*.jsonl"], {
|
|
32171
32216
|
absolute: true,
|
|
32172
|
-
cwd: rootDir
|
|
32217
|
+
cwd: rootDir,
|
|
32218
|
+
followSymbolicLinks: false
|
|
32173
32219
|
});
|
|
32174
|
-
|
|
32175
|
-
|
|
32176
|
-
|
|
32177
|
-
|
|
32178
|
-
|
|
32220
|
+
const oldestMtimeMs = nowMs - MAX_LOOKBACK_MS;
|
|
32221
|
+
return files.map((file) => {
|
|
32222
|
+
const stats = fs15.statSync(file);
|
|
32223
|
+
return { file, mtimeMs: stats.mtimeMs, size: stats.size };
|
|
32224
|
+
}).filter((file) => file.mtimeMs >= oldestMtimeMs).sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
32225
|
+
}
|
|
32226
|
+
function addActivityLine(lineBytes, firstLine, timestamps) {
|
|
32227
|
+
let line = lineBytes.toString("utf8");
|
|
32228
|
+
if (firstLine && line.charCodeAt(0) === 65279) {
|
|
32229
|
+
line = line.slice(1);
|
|
32230
|
+
}
|
|
32231
|
+
if (line.endsWith("\r")) {
|
|
32232
|
+
line = line.slice(0, -1);
|
|
32233
|
+
}
|
|
32234
|
+
if (line.length === 0) {
|
|
32235
|
+
return;
|
|
32236
|
+
}
|
|
32237
|
+
const timestamp = getActivityTimestamp(parseJsonlLine(line));
|
|
32238
|
+
if (timestamp) {
|
|
32239
|
+
timestamps.add(timestamp.getTime());
|
|
32240
|
+
}
|
|
32241
|
+
}
|
|
32242
|
+
function saveTranscriptProgress(cacheDir, file, offset, remainder, firstLine, complete, timestamps) {
|
|
32243
|
+
writeTranscriptCache(cacheDir, file.file, {
|
|
32244
|
+
version: TRANSCRIPT_CACHE_VERSION,
|
|
32245
|
+
filePath: file.file,
|
|
32246
|
+
mtimeMs: file.mtimeMs,
|
|
32247
|
+
size: file.size,
|
|
32248
|
+
offset,
|
|
32249
|
+
remainder: remainder.toString("base64"),
|
|
32250
|
+
firstLine,
|
|
32251
|
+
complete,
|
|
32252
|
+
timestamps: Array.from(timestamps)
|
|
32179
32253
|
});
|
|
32180
|
-
|
|
32181
|
-
|
|
32182
|
-
|
|
32183
|
-
|
|
32184
|
-
|
|
32185
|
-
|
|
32254
|
+
}
|
|
32255
|
+
function readTranscriptActivity(file, cacheDir, deadlineMs) {
|
|
32256
|
+
const cached = readTranscriptCache(cacheDir, file.file);
|
|
32257
|
+
if (cached?.complete && cached.size === file.size && cached.mtimeMs === file.mtimeMs) {
|
|
32258
|
+
return { complete: true, timestamps: new Set(cached.timestamps) };
|
|
32259
|
+
}
|
|
32260
|
+
const canResume = cached !== null && file.size >= cached.offset && (!cached.complete || file.size > cached.size);
|
|
32261
|
+
const timestamps = new Set(canResume ? cached.timestamps : []);
|
|
32262
|
+
let offset = canResume ? cached.offset : 0;
|
|
32263
|
+
let remainder = canResume ? Buffer.from(cached.remainder, "base64") : Buffer.alloc(0);
|
|
32264
|
+
let firstLine = canResume ? cached.firstLine : true;
|
|
32265
|
+
let descriptor;
|
|
32266
|
+
try {
|
|
32267
|
+
descriptor = fs15.openSync(file.file, "r");
|
|
32268
|
+
} catch {
|
|
32269
|
+
return { complete: true, timestamps: new Set };
|
|
32270
|
+
}
|
|
32271
|
+
try {
|
|
32272
|
+
const scratch = Buffer.allocUnsafe(JSONL_READ_CHUNK_BYTES);
|
|
32273
|
+
while (offset < file.size) {
|
|
32274
|
+
const readSize = Math.min(scratch.length, file.size - offset);
|
|
32275
|
+
const bytesRead = fs15.readSync(descriptor, scratch, 0, readSize, offset);
|
|
32276
|
+
if (bytesRead === 0) {
|
|
32277
|
+
break;
|
|
32278
|
+
}
|
|
32279
|
+
offset += bytesRead;
|
|
32280
|
+
const newBytes = scratch.subarray(0, bytesRead);
|
|
32281
|
+
const data = remainder.length > 0 ? Buffer.concat([remainder, newBytes]) : newBytes;
|
|
32282
|
+
let lineStart = 0;
|
|
32283
|
+
let newline = data.indexOf(10, lineStart);
|
|
32284
|
+
while (newline !== -1) {
|
|
32285
|
+
addActivityLine(data.subarray(lineStart, newline), firstLine, timestamps);
|
|
32286
|
+
firstLine = false;
|
|
32287
|
+
lineStart = newline + 1;
|
|
32288
|
+
newline = data.indexOf(10, lineStart);
|
|
32289
|
+
}
|
|
32290
|
+
remainder = Buffer.from(data.subarray(lineStart));
|
|
32291
|
+
if (offset < file.size && isDeadlineExceeded(deadlineMs)) {
|
|
32292
|
+
saveTranscriptProgress(cacheDir, file, offset, remainder, firstLine, false, timestamps);
|
|
32293
|
+
return { complete: false, timestamps };
|
|
32294
|
+
}
|
|
32295
|
+
}
|
|
32296
|
+
if (remainder.length > 0) {
|
|
32297
|
+
addActivityLine(remainder, firstLine, timestamps);
|
|
32298
|
+
firstLine = false;
|
|
32299
|
+
}
|
|
32300
|
+
saveTranscriptProgress(cacheDir, file, offset, remainder, firstLine, true, timestamps);
|
|
32301
|
+
return { complete: true, timestamps };
|
|
32302
|
+
} catch {
|
|
32303
|
+
return { complete: true, timestamps: new Set };
|
|
32304
|
+
} finally {
|
|
32305
|
+
try {
|
|
32306
|
+
fs15.closeSync(descriptor);
|
|
32307
|
+
} catch {}
|
|
32308
|
+
}
|
|
32309
|
+
}
|
|
32310
|
+
function isReusableScanState(state, requestedNowMs) {
|
|
32311
|
+
return state !== null && requestedNowMs >= state.nowMs && requestedNowMs - state.nowMs <= SCAN_STATE_MAX_AGE_MS;
|
|
32312
|
+
}
|
|
32313
|
+
function calculateBlockMetrics(files, activities, nowMs) {
|
|
32314
|
+
const sessionDurationMs = 5 * 60 * 60 * 1000;
|
|
32186
32315
|
let timestamps = [];
|
|
32187
32316
|
let mostRecentTimestamp = null;
|
|
32188
32317
|
let continuousWorkStart = null;
|
|
32189
32318
|
let foundSessionGap = false;
|
|
32190
|
-
for (const lookbackHours of
|
|
32191
|
-
const
|
|
32319
|
+
for (const lookbackHours of LOOKBACK_HOURS) {
|
|
32320
|
+
const cutoffMs = nowMs - lookbackHours * 60 * 60 * 1000;
|
|
32192
32321
|
timestamps = [];
|
|
32193
|
-
for (const
|
|
32194
|
-
if (
|
|
32322
|
+
for (const file of files) {
|
|
32323
|
+
if (file.mtimeMs < cutoffMs) {
|
|
32195
32324
|
break;
|
|
32196
32325
|
}
|
|
32197
|
-
for (const timestamp of
|
|
32198
|
-
timestamps.push(timestamp);
|
|
32326
|
+
for (const timestamp of activities.get(file.file) ?? []) {
|
|
32327
|
+
timestamps.push(new Date(timestamp));
|
|
32199
32328
|
}
|
|
32200
32329
|
}
|
|
32201
32330
|
if (timestamps.length === 0) {
|
|
@@ -32204,29 +32333,26 @@ function findMostRecentBlockStartTime(rootDir, sessionDurationHours = 5) {
|
|
|
32204
32333
|
timestamps.sort((a, b) => b.getTime() - a.getTime());
|
|
32205
32334
|
if (!mostRecentTimestamp && timestamps[0]) {
|
|
32206
32335
|
mostRecentTimestamp = timestamps[0];
|
|
32207
|
-
|
|
32208
|
-
if (timeSinceLastActivity > sessionDurationMs) {
|
|
32336
|
+
if (nowMs - mostRecentTimestamp.getTime() > sessionDurationMs) {
|
|
32209
32337
|
return null;
|
|
32210
32338
|
}
|
|
32211
32339
|
}
|
|
32212
|
-
const isLastChunk = lookbackHours ===
|
|
32340
|
+
const isLastChunk = lookbackHours === LOOKBACK_HOURS[LOOKBACK_HOURS.length - 1];
|
|
32213
32341
|
continuousWorkStart = mostRecentTimestamp;
|
|
32214
|
-
for (let
|
|
32215
|
-
const currentTimestamp = timestamps[
|
|
32216
|
-
const previousTimestamp = timestamps[
|
|
32217
|
-
if (!currentTimestamp || !previousTimestamp)
|
|
32342
|
+
for (let index = 1;index < timestamps.length; index++) {
|
|
32343
|
+
const currentTimestamp = timestamps[index];
|
|
32344
|
+
const previousTimestamp = timestamps[index - 1];
|
|
32345
|
+
if (!currentTimestamp || !previousTimestamp) {
|
|
32218
32346
|
continue;
|
|
32347
|
+
}
|
|
32219
32348
|
const gap = previousTimestamp.getTime() - currentTimestamp.getTime();
|
|
32220
32349
|
if (gap >= sessionDurationMs) {
|
|
32221
|
-
foundSessionGap = isLastChunk || previousTimestamp.getTime() -
|
|
32350
|
+
foundSessionGap = isLastChunk || previousTimestamp.getTime() - cutoffMs >= sessionDurationMs;
|
|
32222
32351
|
break;
|
|
32223
32352
|
}
|
|
32224
32353
|
continuousWorkStart = currentTimestamp;
|
|
32225
32354
|
}
|
|
32226
|
-
if (foundSessionGap) {
|
|
32227
|
-
break;
|
|
32228
|
-
}
|
|
32229
|
-
if (isLastChunk) {
|
|
32355
|
+
if (foundSessionGap || isLastChunk) {
|
|
32230
32356
|
break;
|
|
32231
32357
|
}
|
|
32232
32358
|
}
|
|
@@ -32238,8 +32364,9 @@ function findMostRecentBlockStartTime(rootDir, sessionDurationHours = 5) {
|
|
|
32238
32364
|
let currentBlockStart = null;
|
|
32239
32365
|
let currentBlockEnd = null;
|
|
32240
32366
|
for (const timestamp of sortedTimestamps) {
|
|
32241
|
-
if (timestamp.getTime() < continuousWorkStart.getTime())
|
|
32367
|
+
if (timestamp.getTime() < continuousWorkStart.getTime()) {
|
|
32242
32368
|
continue;
|
|
32369
|
+
}
|
|
32243
32370
|
if (!currentBlockStart || currentBlockEnd && timestamp.getTime() > currentBlockEnd.getTime()) {
|
|
32244
32371
|
currentBlockStart = floorToHour(timestamp);
|
|
32245
32372
|
currentBlockEnd = new Date(currentBlockStart.getTime() + sessionDurationMs);
|
|
@@ -32247,51 +32374,83 @@ function findMostRecentBlockStartTime(rootDir, sessionDurationHours = 5) {
|
|
|
32247
32374
|
}
|
|
32248
32375
|
}
|
|
32249
32376
|
for (const block of blocks) {
|
|
32250
|
-
if (
|
|
32251
|
-
const hasActivity = timestamps.some((
|
|
32377
|
+
if (nowMs >= block.start.getTime() && nowMs <= block.end.getTime()) {
|
|
32378
|
+
const hasActivity = timestamps.some((timestamp) => timestamp.getTime() >= block.start.getTime() && timestamp.getTime() <= block.end.getTime());
|
|
32252
32379
|
if (hasActivity) {
|
|
32253
|
-
return {
|
|
32254
|
-
startTime: block.start,
|
|
32255
|
-
lastActivity: mostRecentTimestamp
|
|
32256
|
-
};
|
|
32380
|
+
return { startTime: block.start, lastActivity: mostRecentTimestamp };
|
|
32257
32381
|
}
|
|
32258
32382
|
}
|
|
32259
32383
|
}
|
|
32260
32384
|
return null;
|
|
32261
32385
|
}
|
|
32262
|
-
function
|
|
32263
|
-
const
|
|
32264
|
-
|
|
32265
|
-
|
|
32266
|
-
|
|
32267
|
-
|
|
32268
|
-
|
|
32269
|
-
|
|
32270
|
-
|
|
32271
|
-
|
|
32272
|
-
|
|
32386
|
+
function scanBlockMetrics(rootDir, options = {}) {
|
|
32387
|
+
const requestedNowMs = options.nowMs ?? Date.now();
|
|
32388
|
+
let state = readScanState(options.cacheDir, rootDir);
|
|
32389
|
+
if (!isReusableScanState(state, requestedNowMs)) {
|
|
32390
|
+
state = {
|
|
32391
|
+
version: SCAN_STATE_VERSION,
|
|
32392
|
+
rootDir,
|
|
32393
|
+
nowMs: requestedNowMs,
|
|
32394
|
+
nextFileIndex: 0,
|
|
32395
|
+
files: discoverTranscriptFiles(rootDir, requestedNowMs)
|
|
32396
|
+
};
|
|
32397
|
+
writeScanState(options.cacheDir, state);
|
|
32398
|
+
}
|
|
32399
|
+
const scanState = state;
|
|
32400
|
+
if (scanState.files.length === 0) {
|
|
32401
|
+
removeScanState(options.cacheDir);
|
|
32402
|
+
return { status: "complete", metrics: null };
|
|
32403
|
+
}
|
|
32404
|
+
const activities = new Map;
|
|
32405
|
+
while (scanState.nextFileIndex < scanState.files.length) {
|
|
32406
|
+
const file = scanState.files[scanState.nextFileIndex];
|
|
32407
|
+
if (!file) {
|
|
32408
|
+
break;
|
|
32409
|
+
}
|
|
32410
|
+
const activity = readTranscriptActivity(file, options.cacheDir, options.deadlineMs);
|
|
32411
|
+
if (!activity.complete) {
|
|
32412
|
+
writeScanState(options.cacheDir, scanState);
|
|
32413
|
+
return { status: "timeout" };
|
|
32414
|
+
}
|
|
32415
|
+
activities.set(file.file, activity.timestamps);
|
|
32416
|
+
scanState.nextFileIndex += 1;
|
|
32417
|
+
if (isDeadlineExceeded(options.deadlineMs)) {
|
|
32418
|
+
writeScanState(options.cacheDir, scanState);
|
|
32419
|
+
return { status: "timeout" };
|
|
32273
32420
|
}
|
|
32274
|
-
return timestamps;
|
|
32275
|
-
} catch {
|
|
32276
|
-
return [];
|
|
32277
32421
|
}
|
|
32422
|
+
writeScanState(options.cacheDir, scanState);
|
|
32423
|
+
for (const file of scanState.files) {
|
|
32424
|
+
if (activities.has(file.file)) {
|
|
32425
|
+
continue;
|
|
32426
|
+
}
|
|
32427
|
+
const cached = readTranscriptCache(options.cacheDir, file.file);
|
|
32428
|
+
if (cached?.complete && cached.size === file.size && cached.mtimeMs === file.mtimeMs) {
|
|
32429
|
+
activities.set(file.file, new Set(cached.timestamps));
|
|
32430
|
+
continue;
|
|
32431
|
+
}
|
|
32432
|
+
const activity = readTranscriptActivity(file, options.cacheDir, undefined);
|
|
32433
|
+
activities.set(file.file, activity.timestamps);
|
|
32434
|
+
}
|
|
32435
|
+
const metrics = calculateBlockMetrics(scanState.files, activities, scanState.nowMs);
|
|
32436
|
+
removeScanState(options.cacheDir);
|
|
32437
|
+
return { status: "complete", metrics };
|
|
32278
32438
|
}
|
|
32279
32439
|
function getActivityTimestamp(json) {
|
|
32280
|
-
const usage = json
|
|
32281
|
-
if (!usage)
|
|
32282
|
-
return null;
|
|
32283
|
-
const hasInputTokens = typeof usage.input_tokens === "number";
|
|
32284
|
-
const hasOutputTokens = typeof usage.output_tokens === "number";
|
|
32285
|
-
if (!hasInputTokens || !hasOutputTokens)
|
|
32440
|
+
const usage = json?.message?.usage;
|
|
32441
|
+
if (!usage) {
|
|
32286
32442
|
return null;
|
|
32287
|
-
|
|
32443
|
+
}
|
|
32444
|
+
if (typeof usage.input_tokens !== "number" || typeof usage.output_tokens !== "number") {
|
|
32288
32445
|
return null;
|
|
32289
|
-
|
|
32446
|
+
}
|
|
32447
|
+
if (json.isSidechain === true || json.isApiErrorMessage === true) {
|
|
32290
32448
|
return null;
|
|
32291
|
-
|
|
32292
|
-
if (typeof timestamp !== "string")
|
|
32449
|
+
}
|
|
32450
|
+
if (typeof json.timestamp !== "string") {
|
|
32293
32451
|
return null;
|
|
32294
|
-
|
|
32452
|
+
}
|
|
32453
|
+
const date = new Date(json.timestamp);
|
|
32295
32454
|
return Number.isNaN(date.getTime()) ? null : date;
|
|
32296
32455
|
}
|
|
32297
32456
|
function floorToHour(timestamp) {
|
|
@@ -32301,18 +32460,23 @@ function floorToHour(timestamp) {
|
|
|
32301
32460
|
}
|
|
32302
32461
|
|
|
32303
32462
|
// src/utils/jsonl-cache.ts
|
|
32304
|
-
var
|
|
32305
|
-
var
|
|
32306
|
-
var
|
|
32463
|
+
var readFileSync13 = fs16.readFileSync;
|
|
32464
|
+
var writeFileSync9 = fs16.writeFileSync;
|
|
32465
|
+
var mkdirSync9 = fs16.mkdirSync;
|
|
32307
32466
|
var existsSync9 = fs16.existsSync;
|
|
32308
32467
|
var EMPTY_RESULT_TTL_MS = 60 * 1000;
|
|
32468
|
+
var BLOCK_SCAN_BUDGET_MS = 1200;
|
|
32469
|
+
var blockScanDeadlines = new Map;
|
|
32309
32470
|
function normalizeConfigDir(configDir) {
|
|
32310
|
-
return
|
|
32471
|
+
return path14.resolve(configDir);
|
|
32311
32472
|
}
|
|
32312
32473
|
function getBlockCachePath(configDir = getClaudeConfigDir()) {
|
|
32313
32474
|
const normalizedConfigDir = normalizeConfigDir(configDir);
|
|
32314
|
-
const configHash =
|
|
32315
|
-
return
|
|
32475
|
+
const configHash = createHash6("sha256").update(normalizedConfigDir).digest("hex").slice(0, 16);
|
|
32476
|
+
return path14.join(os11.homedir(), ".cache", "ccstatusline", `block-cache-${configHash}.json`);
|
|
32477
|
+
}
|
|
32478
|
+
function getBlockScanCacheDir(configDir = getClaudeConfigDir()) {
|
|
32479
|
+
return `${getBlockCachePath(configDir)}.files`;
|
|
32316
32480
|
}
|
|
32317
32481
|
function readBlockCache(expectedConfigDir) {
|
|
32318
32482
|
try {
|
|
@@ -32321,7 +32485,7 @@ function readBlockCache(expectedConfigDir) {
|
|
|
32321
32485
|
if (!existsSync9(cachePath)) {
|
|
32322
32486
|
return null;
|
|
32323
32487
|
}
|
|
32324
|
-
const content =
|
|
32488
|
+
const content = readFileSync13(cachePath, "utf-8");
|
|
32325
32489
|
const cache = JSON.parse(content);
|
|
32326
32490
|
if (typeof cache.startTime !== "string") {
|
|
32327
32491
|
return null;
|
|
@@ -32350,7 +32514,7 @@ function readEmptyBlockCache(expectedConfigDir) {
|
|
|
32350
32514
|
if (!existsSync9(cachePath)) {
|
|
32351
32515
|
return null;
|
|
32352
32516
|
}
|
|
32353
|
-
const content =
|
|
32517
|
+
const content = readFileSync13(cachePath, "utf-8");
|
|
32354
32518
|
const cache = JSON.parse(content);
|
|
32355
32519
|
if (typeof cache.emptyUntil !== "string") {
|
|
32356
32520
|
return null;
|
|
@@ -32376,33 +32540,33 @@ function writeEmptyBlockCache(emptyUntil, configDir = getClaudeConfigDir()) {
|
|
|
32376
32540
|
try {
|
|
32377
32541
|
const normalizedConfigDir = normalizeConfigDir(configDir);
|
|
32378
32542
|
const cachePath = getBlockCachePath(normalizedConfigDir);
|
|
32379
|
-
const cacheDir =
|
|
32543
|
+
const cacheDir = path14.dirname(cachePath);
|
|
32380
32544
|
if (!existsSync9(cacheDir)) {
|
|
32381
|
-
|
|
32545
|
+
mkdirSync9(cacheDir, { recursive: true });
|
|
32382
32546
|
}
|
|
32383
32547
|
const cache = {
|
|
32384
32548
|
emptyUntil: emptyUntil.toISOString(),
|
|
32385
32549
|
configDir: normalizedConfigDir
|
|
32386
32550
|
};
|
|
32387
|
-
|
|
32551
|
+
writeFileSync9(cachePath, JSON.stringify(cache), "utf-8");
|
|
32388
32552
|
} catch {}
|
|
32389
32553
|
}
|
|
32390
32554
|
function writeBlockCache(startTime, configDir = getClaudeConfigDir()) {
|
|
32391
32555
|
try {
|
|
32392
32556
|
const normalizedConfigDir = normalizeConfigDir(configDir);
|
|
32393
32557
|
const cachePath = getBlockCachePath(normalizedConfigDir);
|
|
32394
|
-
const cacheDir =
|
|
32558
|
+
const cacheDir = path14.dirname(cachePath);
|
|
32395
32559
|
if (!existsSync9(cacheDir)) {
|
|
32396
|
-
|
|
32560
|
+
mkdirSync9(cacheDir, { recursive: true });
|
|
32397
32561
|
}
|
|
32398
32562
|
const cache = {
|
|
32399
32563
|
startTime: startTime.toISOString(),
|
|
32400
32564
|
configDir: normalizedConfigDir
|
|
32401
32565
|
};
|
|
32402
|
-
|
|
32566
|
+
writeFileSync9(cachePath, JSON.stringify(cache), "utf-8");
|
|
32403
32567
|
} catch {}
|
|
32404
32568
|
}
|
|
32405
|
-
function getCachedBlockMetrics(sessionDurationHours = 5) {
|
|
32569
|
+
function getCachedBlockMetrics(sessionDurationHours = 5, scanBudgetMs = BLOCK_SCAN_BUDGET_MS) {
|
|
32406
32570
|
const sessionDurationMs = sessionDurationHours * 60 * 60 * 1000;
|
|
32407
32571
|
const now = new Date;
|
|
32408
32572
|
const activeConfigDir = getClaudeConfigDir();
|
|
@@ -32420,7 +32584,28 @@ function getCachedBlockMetrics(sessionDurationHours = 5) {
|
|
|
32420
32584
|
if (emptyUntil && now.getTime() < emptyUntil.getTime() && emptyUntil.getTime() <= now.getTime() + EMPTY_RESULT_TTL_MS) {
|
|
32421
32585
|
return null;
|
|
32422
32586
|
}
|
|
32423
|
-
const
|
|
32587
|
+
const deadlineMs = blockScanDeadlines.get(activeConfigDir) ?? Date.now() + scanBudgetMs;
|
|
32588
|
+
blockScanDeadlines.set(activeConfigDir, deadlineMs);
|
|
32589
|
+
if (Date.now() >= deadlineMs) {
|
|
32590
|
+
return null;
|
|
32591
|
+
}
|
|
32592
|
+
const scan = {};
|
|
32593
|
+
try {
|
|
32594
|
+
withCacheLock(getBlockCachePath(activeConfigDir), () => {
|
|
32595
|
+
scan.result = scanBlockMetrics(activeConfigDir, {
|
|
32596
|
+
cacheDir: getBlockScanCacheDir(activeConfigDir),
|
|
32597
|
+
deadlineMs,
|
|
32598
|
+
nowMs: now.getTime()
|
|
32599
|
+
});
|
|
32600
|
+
});
|
|
32601
|
+
} catch {
|
|
32602
|
+
return null;
|
|
32603
|
+
}
|
|
32604
|
+
if (!scan.result || scan.result.status === "timeout") {
|
|
32605
|
+
return null;
|
|
32606
|
+
}
|
|
32607
|
+
blockScanDeadlines.delete(activeConfigDir);
|
|
32608
|
+
const metrics = scan.result.metrics;
|
|
32424
32609
|
if (metrics) {
|
|
32425
32610
|
writeBlockCache(metrics.startTime, activeConfigDir);
|
|
32426
32611
|
} else {
|
|
@@ -32430,7 +32615,7 @@ function getCachedBlockMetrics(sessionDurationHours = 5) {
|
|
|
32430
32615
|
}
|
|
32431
32616
|
// src/utils/jsonl-metrics.ts
|
|
32432
32617
|
import * as fs17 from "node:fs";
|
|
32433
|
-
import
|
|
32618
|
+
import path15 from "node:path";
|
|
32434
32619
|
|
|
32435
32620
|
// src/utils/jsonl-metadata.ts
|
|
32436
32621
|
var KNOWN_THINKING_EFFORTS = ["low", "medium", "high", "xhigh", "max"];
|
|
@@ -32986,11 +33171,11 @@ function getSubagentTranscriptPaths(transcriptPath, referencedAgentIds) {
|
|
|
32986
33171
|
if (referencedAgentIds.size === 0) {
|
|
32987
33172
|
return [];
|
|
32988
33173
|
}
|
|
32989
|
-
const transcriptDir =
|
|
32990
|
-
const transcriptStem =
|
|
33174
|
+
const transcriptDir = path15.dirname(transcriptPath);
|
|
33175
|
+
const transcriptStem = path15.parse(transcriptPath).name;
|
|
32991
33176
|
const candidateDirs = [
|
|
32992
|
-
|
|
32993
|
-
|
|
33177
|
+
path15.join(transcriptDir, "subagents"),
|
|
33178
|
+
path15.join(transcriptDir, transcriptStem, "subagents")
|
|
32994
33179
|
];
|
|
32995
33180
|
const seenPaths = new Set;
|
|
32996
33181
|
const matchedPaths = [];
|
|
@@ -33011,7 +33196,7 @@ function getSubagentTranscriptPaths(transcriptPath, referencedAgentIds) {
|
|
|
33011
33196
|
if (!referencedAgentIds.has(match[1])) {
|
|
33012
33197
|
continue;
|
|
33013
33198
|
}
|
|
33014
|
-
const fullPath =
|
|
33199
|
+
const fullPath = path15.join(subagentsDir, entry.name);
|
|
33015
33200
|
if (seenPaths.has(fullPath)) {
|
|
33016
33201
|
continue;
|
|
33017
33202
|
}
|
|
@@ -38598,7 +38783,7 @@ var readlink = fs20.promises.readlink;
|
|
|
38598
38783
|
var realpath2 = fs20.promises.realpath;
|
|
38599
38784
|
var stat3 = fs20.promises.stat;
|
|
38600
38785
|
function getDefaultSettingsPath() {
|
|
38601
|
-
return
|
|
38786
|
+
return path16.join(os14.homedir(), ".config", "ccstatusline", "settings.json");
|
|
38602
38787
|
}
|
|
38603
38788
|
var settingsPath = getDefaultSettingsPath();
|
|
38604
38789
|
var lastLoadError = null;
|
|
@@ -38607,7 +38792,7 @@ function getConfigLoadError() {
|
|
|
38607
38792
|
return lastLoadError;
|
|
38608
38793
|
}
|
|
38609
38794
|
function resolveConfigPath(filePath) {
|
|
38610
|
-
return filePath ?
|
|
38795
|
+
return filePath ? path16.resolve(filePath) : getDefaultSettingsPath();
|
|
38611
38796
|
}
|
|
38612
38797
|
function getConfigLoadNotice() {
|
|
38613
38798
|
return unsavedMigration ? "迁移前无法备份 settings.json" : null;
|
|
@@ -38624,7 +38809,7 @@ function isCustomConfigPath() {
|
|
|
38624
38809
|
}
|
|
38625
38810
|
function getSettingsPaths() {
|
|
38626
38811
|
return {
|
|
38627
|
-
configDir:
|
|
38812
|
+
configDir: path16.dirname(settingsPath),
|
|
38628
38813
|
settingsPath
|
|
38629
38814
|
};
|
|
38630
38815
|
}
|
|
@@ -38639,7 +38824,7 @@ async function resolveSymlinkTarget(linkPath) {
|
|
|
38639
38824
|
throw error;
|
|
38640
38825
|
}
|
|
38641
38826
|
const linkTarget = await readlink(linkPath);
|
|
38642
|
-
return
|
|
38827
|
+
return path16.resolve(path16.dirname(linkPath), linkTarget);
|
|
38643
38828
|
}
|
|
38644
38829
|
}
|
|
38645
38830
|
async function resolveAtomicWriteTarget(paths) {
|
|
@@ -38654,7 +38839,7 @@ async function resolveAtomicWriteTarget(paths) {
|
|
|
38654
38839
|
const targetPath = await resolveSymlinkTarget(paths.settingsPath);
|
|
38655
38840
|
return {
|
|
38656
38841
|
targetPath,
|
|
38657
|
-
tempDir:
|
|
38842
|
+
tempDir: path16.dirname(targetPath)
|
|
38658
38843
|
};
|
|
38659
38844
|
} catch (error) {
|
|
38660
38845
|
if (getErrorCode2(error) === "ENOENT") {
|
|
@@ -38676,7 +38861,7 @@ async function getReplacedFileMode(filePath) {
|
|
|
38676
38861
|
async function writeSettingsJson(settings, paths) {
|
|
38677
38862
|
await mkdir2(paths.configDir, { recursive: true });
|
|
38678
38863
|
const writeTarget = await resolveAtomicWriteTarget(paths);
|
|
38679
|
-
const tempPath =
|
|
38864
|
+
const tempPath = path16.join(writeTarget.tempDir, `${path16.basename(writeTarget.targetPath)}.${process.pid}.${Date.now()}.tmp`);
|
|
38680
38865
|
const mode = await getReplacedFileMode(writeTarget.targetPath);
|
|
38681
38866
|
try {
|
|
38682
38867
|
await writeFile2(tempPath, JSON.stringify(settings, null, 2), { encoding: "utf-8", mode });
|
|
@@ -38808,7 +38993,7 @@ async function saveSettings(settings) {
|
|
|
38808
38993
|
};
|
|
38809
38994
|
await writeSettingsJson(settingsWithVersion, paths);
|
|
38810
38995
|
try {
|
|
38811
|
-
const { syncWidgetHooks } = await import("./hooks-
|
|
38996
|
+
const { syncWidgetHooks } = await import("./hooks-x0y49hsa.js");
|
|
38812
38997
|
return await syncWidgetHooks(settings);
|
|
38813
38998
|
} catch {
|
|
38814
38999
|
return null;
|
|
@@ -38816,14 +39001,14 @@ async function saveSettings(settings) {
|
|
|
38816
39001
|
}
|
|
38817
39002
|
function expandPath(filePath) {
|
|
38818
39003
|
if (filePath.startsWith("~/") || filePath === "~") {
|
|
38819
|
-
return
|
|
39004
|
+
return path16.join(os14.homedir(), filePath.slice(2));
|
|
38820
39005
|
}
|
|
38821
39006
|
return filePath;
|
|
38822
39007
|
}
|
|
38823
39008
|
async function exportConfig(settings, filePath) {
|
|
38824
39009
|
const expanded = expandPath(filePath);
|
|
38825
39010
|
const exportData = { ...settings, exportedBy: getPackageVersion() };
|
|
38826
|
-
await mkdir2(
|
|
39011
|
+
await mkdir2(path16.dirname(expanded), { recursive: true });
|
|
38827
39012
|
await writeFile2(expanded, JSON.stringify(exportData, null, 2), "utf-8");
|
|
38828
39013
|
}
|
|
38829
39014
|
async function validateImportFile(filePath) {
|
package/dist/ccstatusline.js
CHANGED
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
initConfigPath,
|
|
42
42
|
loadSettings,
|
|
43
43
|
saveSettings
|
|
44
|
-
} from "./ccstatusline-
|
|
44
|
+
} from "./ccstatusline-ss57aydk.js";
|
|
45
45
|
import {
|
|
46
46
|
string,
|
|
47
47
|
number,
|
|
@@ -1298,7 +1298,7 @@ async function main() {
|
|
|
1298
1298
|
const { updatemessage, ...newSettings } = settings;
|
|
1299
1299
|
await saveSettings(newSettings);
|
|
1300
1300
|
}
|
|
1301
|
-
const { runTUI } = await import("./index-
|
|
1301
|
+
const { runTUI } = await import("./index-1az9bg18.js");
|
|
1302
1302
|
runTUI();
|
|
1303
1303
|
}
|
|
1304
1304
|
}
|