@tokz/cli 0.2.20 → 0.2.22
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.
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
sanitizeProjectPath,
|
|
21
21
|
shortModel,
|
|
22
22
|
usd
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-YVDSYDGL.js";
|
|
24
24
|
|
|
25
25
|
// src/ui/Root.tsx
|
|
26
26
|
import { useEffect as useEffect2, useState as useState6 } from "react";
|
|
@@ -632,9 +632,11 @@ var codebuffAdapter = {
|
|
|
632
632
|
};
|
|
633
633
|
|
|
634
634
|
// src/agents/codex.ts
|
|
635
|
-
import { access as access5,
|
|
635
|
+
import { access as access5, stat as stat2 } from "fs/promises";
|
|
636
|
+
import { createReadStream } from "fs";
|
|
636
637
|
import { homedir as homedir6 } from "os";
|
|
637
638
|
import { join as join6 } from "path";
|
|
639
|
+
import { createInterface } from "readline";
|
|
638
640
|
import { glob as glob4 } from "tinyglobby";
|
|
639
641
|
var DEFAULT_MODEL = "gpt-5";
|
|
640
642
|
var CODEX_AUTO_REVIEW_MODEL = "codex-auto-review";
|
|
@@ -781,53 +783,50 @@ function headlessTimestamp(o, pick) {
|
|
|
781
783
|
const fromFields = (f) => f ? pick(f.timestamp) ?? pick(f.created_at) ?? pick(f.createdAt) : void 0;
|
|
782
784
|
return fromFields(o) ?? fromFields(asDict(o.data)) ?? fromFields(asDict(o.result)) ?? fromFields(asDict(o.response));
|
|
783
785
|
}
|
|
784
|
-
function detectReplaySecond(content, lines) {
|
|
785
|
-
const encoder = new TextEncoder();
|
|
786
|
-
let byteLen = 0;
|
|
787
|
-
let charLimit = 0;
|
|
788
|
-
for (let i = 0; i < content.length; i++) {
|
|
789
|
-
const code = content.charCodeAt(i);
|
|
790
|
-
if (code <= 127) byteLen += 1;
|
|
791
|
-
else if (code <= 2047) byteLen += 2;
|
|
792
|
-
else if (code >= 55296 && code <= 57343) {
|
|
793
|
-
byteLen += 4;
|
|
794
|
-
i++;
|
|
795
|
-
} else byteLen += 3;
|
|
796
|
-
if (byteLen > 16384) break;
|
|
797
|
-
charLimit = i + 1;
|
|
798
|
-
}
|
|
799
|
-
const head = content.slice(0, charLimit);
|
|
800
|
-
if (!head.includes("thread_spawn") && !head.includes("forked_from_id")) return void 0;
|
|
801
|
-
let firstSecond;
|
|
802
|
-
for (const p of lines) {
|
|
803
|
-
if (p.type !== "event_msg" || p.payload?.type !== "token_count") continue;
|
|
804
|
-
const info = p.payload.info;
|
|
805
|
-
if (!info) continue;
|
|
806
|
-
if (!asDict(info.last_token_usage) && !asDict(info.total_token_usage)) continue;
|
|
807
|
-
const ts = p.timestamp;
|
|
808
|
-
if (!ts || typeof ts !== "string" || ts.length < 19) continue;
|
|
809
|
-
const sec = ts.slice(0, 19);
|
|
810
|
-
if (firstSecond === void 0) {
|
|
811
|
-
firstSecond = sec;
|
|
812
|
-
} else {
|
|
813
|
-
if (firstSecond === sec) {
|
|
814
|
-
return sec;
|
|
815
|
-
}
|
|
816
|
-
return void 0;
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
return void 0;
|
|
820
|
-
}
|
|
821
786
|
async function parseCodexRollout(file, seen = /* @__PURE__ */ new Set()) {
|
|
822
787
|
const stats = { file, usageByModel: {}, toolCalls: {}, toolCostUsd: {}, dailyUsage: {} };
|
|
823
|
-
const
|
|
788
|
+
const rl = createInterface({
|
|
789
|
+
input: createReadStream(file, { encoding: "utf8" }),
|
|
790
|
+
crlfDelay: Infinity
|
|
791
|
+
});
|
|
824
792
|
const lines = [];
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
793
|
+
let bytesRead = 0;
|
|
794
|
+
let hasMarker = false;
|
|
795
|
+
try {
|
|
796
|
+
for await (const raw of rl) {
|
|
797
|
+
if (bytesRead <= 16384) {
|
|
798
|
+
if (raw.includes("thread_spawn") || raw.includes("forked_from_id")) {
|
|
799
|
+
hasMarker = true;
|
|
800
|
+
}
|
|
801
|
+
bytesRead += Buffer.byteLength(raw, "utf8") + 1;
|
|
802
|
+
}
|
|
803
|
+
if (!raw.trim()) continue;
|
|
804
|
+
const parsed = parseLine(raw);
|
|
805
|
+
if (parsed) lines.push(parsed);
|
|
806
|
+
}
|
|
807
|
+
} catch (e) {
|
|
808
|
+
}
|
|
809
|
+
let replaySecond;
|
|
810
|
+
if (hasMarker) {
|
|
811
|
+
let firstSecond;
|
|
812
|
+
for (const p of lines) {
|
|
813
|
+
if (p.type !== "event_msg" || p.payload?.type !== "token_count") continue;
|
|
814
|
+
const info = p.payload.info;
|
|
815
|
+
if (!info) continue;
|
|
816
|
+
if (!asDict(info.last_token_usage) && !asDict(info.total_token_usage)) continue;
|
|
817
|
+
const ts = p.timestamp;
|
|
818
|
+
if (!ts || typeof ts !== "string" || ts.length < 19) continue;
|
|
819
|
+
const sec = ts.slice(0, 19);
|
|
820
|
+
if (firstSecond === void 0) {
|
|
821
|
+
firstSecond = sec;
|
|
822
|
+
} else {
|
|
823
|
+
if (firstSecond === sec) {
|
|
824
|
+
replaySecond = sec;
|
|
825
|
+
}
|
|
826
|
+
break;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
829
|
}
|
|
830
|
-
const replaySecond = detectReplaySecond(content, lines);
|
|
831
830
|
let skipReplay = replaySecond !== void 0;
|
|
832
831
|
const modelState = { currentIsFallback: false };
|
|
833
832
|
let prev;
|
|
@@ -81,7 +81,7 @@ function costUsd(usage, modelId) {
|
|
|
81
81
|
cacheRead += usage.longContextCacheReadTokens / 1e6 * (p.inputPerMTok * 2) * readMult;
|
|
82
82
|
}
|
|
83
83
|
if (usage.longContextOutputTokens) {
|
|
84
|
-
output += usage.longContextOutputTokens / 1e6 * (p.outputPerMTok *
|
|
84
|
+
output += usage.longContextOutputTokens / 1e6 * (p.outputPerMTok * 1.5);
|
|
85
85
|
}
|
|
86
86
|
const write1h = Math.min(usage.cacheCreation1hTokens ?? 0, usage.cacheCreationTokens);
|
|
87
87
|
const write5m = usage.cacheCreationTokens - write1h;
|
|
@@ -99,6 +99,9 @@ function addUsage(acc, u) {
|
|
|
99
99
|
acc.cacheCreation1hTokens = (acc.cacheCreation1hTokens ?? 0) + (u.cacheCreation1hTokens ?? 0);
|
|
100
100
|
acc.outputTokens += u.outputTokens;
|
|
101
101
|
acc.turns += u.turns;
|
|
102
|
+
acc.longContextInputTokens = (acc.longContextInputTokens ?? 0) + (u.longContextInputTokens ?? 0);
|
|
103
|
+
acc.longContextCacheReadTokens = (acc.longContextCacheReadTokens ?? 0) + (u.longContextCacheReadTokens ?? 0);
|
|
104
|
+
acc.longContextOutputTokens = (acc.longContextOutputTokens ?? 0) + (u.longContextOutputTokens ?? 0);
|
|
102
105
|
}
|
|
103
106
|
function cacheSavings(usageByModel) {
|
|
104
107
|
let saved = 0;
|
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
buildBlocks,
|
|
4
4
|
renderBlocksReport
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-Q5AEDWTI.js";
|
|
6
6
|
import {
|
|
7
7
|
findMcpServers
|
|
8
8
|
} from "./chunk-65BQE6TI.js";
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
setTimezone,
|
|
18
18
|
tok,
|
|
19
19
|
usd
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-YVDSYDGL.js";
|
|
21
21
|
|
|
22
22
|
// src/cli.ts
|
|
23
23
|
import { createRequire } from "module";
|
|
@@ -234,7 +234,7 @@ program.command("blocks").description("Claude usage grouped into rolling 5-hour
|
|
|
234
234
|
});
|
|
235
235
|
program.command("statusline").description("compact usage line for Claude Code's statusLine hook (reads hook JSON on stdin)").argument("[action]", '"enable" writes the hook into ~/.claude/settings.json, "disable" removes it').option("--cost-source <mode>", "session cost source: auto | cc | calc | both", "auto").action(async (action, opts) => {
|
|
236
236
|
const globals = applyGlobals();
|
|
237
|
-
const sl = await import("./statusline-
|
|
237
|
+
const sl = await import("./statusline-ES3W3TEU.js");
|
|
238
238
|
if (action === "enable" || action === "disable") {
|
|
239
239
|
try {
|
|
240
240
|
console.log(action === "enable" ? await sl.enableStatusline() : await sl.disableStatusline());
|
|
@@ -276,7 +276,7 @@ program.action(async () => {
|
|
|
276
276
|
const [{ render }, React, { Root }, { Fullscreen }] = await Promise.all([
|
|
277
277
|
import("ink"),
|
|
278
278
|
import("react"),
|
|
279
|
-
import("./Root-
|
|
279
|
+
import("./Root-GBSQBWNF.js"),
|
|
280
280
|
import("./Fullscreen-GK2ZYXHV.js")
|
|
281
281
|
]);
|
|
282
282
|
render(React.createElement(Fullscreen, null, React.createElement(Root)));
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
buildBlocks,
|
|
4
4
|
burnRate,
|
|
5
5
|
fmtMs
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-Q5AEDWTI.js";
|
|
7
7
|
import {
|
|
8
8
|
compact,
|
|
9
9
|
costUsd,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
parseTranscript,
|
|
13
13
|
shortModel,
|
|
14
14
|
usd
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-YVDSYDGL.js";
|
|
16
16
|
|
|
17
17
|
// src/statusline.ts
|
|
18
18
|
import { mkdir, readFile, stat, writeFile } from "fs/promises";
|