@tokz/cli 0.2.20 → 0.2.21

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.
@@ -632,9 +632,11 @@ var codebuffAdapter = {
632
632
  };
633
633
 
634
634
  // src/agents/codex.ts
635
- import { access as access5, readFile as readFile4, stat as stat2 } from "fs/promises";
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 content = await readFile4(file, "utf8").catch(() => "");
788
+ const rl = createInterface({
789
+ input: createReadStream(file, { encoding: "utf8" }),
790
+ crlfDelay: Infinity
791
+ });
824
792
  const lines = [];
825
- for (const raw of content.split("\n")) {
826
- if (!raw.trim()) continue;
827
- const parsed = parseLine(raw);
828
- if (parsed) lines.push(parsed);
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;
package/dist/cli.js CHANGED
@@ -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-KXHC63O2.js"),
279
+ import("./Root-D7W7HP7D.js"),
280
280
  import("./Fullscreen-GK2ZYXHV.js")
281
281
  ]);
282
282
  render(React.createElement(Fullscreen, null, React.createElement(Root)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokz/cli",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "description": "See where your coding agents' tokens and dollars actually go.",
5
5
  "keywords": [
6
6
  "claude",