@tokz/cli 0.2.6 → 0.2.7

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Abdallah-Alwarawreh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -13,14 +13,14 @@ import {
13
13
  duration,
14
14
  emptyUsage,
15
15
  groupDaily,
16
- parseTranscript,
16
+ parseTranscriptContent,
17
17
  pct,
18
18
  pct1,
19
19
  relativeDate,
20
20
  sanitizeProjectPath,
21
21
  shortModel,
22
22
  usd
23
- } from "./chunk-Z5W5QH2Z.js";
23
+ } from "./chunk-KO5GQL76.js";
24
24
 
25
25
  // src/ui/Root.tsx
26
26
  import { useEffect as useEffect2, useState as useState6 } from "react";
@@ -172,12 +172,18 @@ async function loadProjects(home = homedir(), onProgress) {
172
172
  const seenMessageIds = /* @__PURE__ */ new Map();
173
173
  const seenToolIds = /* @__PURE__ */ new Set();
174
174
  let parsed = 0;
175
+ const contents = /* @__PURE__ */ new Map();
176
+ await Promise.all(
177
+ files.map(
178
+ (f) => readFile(f, "utf8").then((c) => void contents.set(f, c)).catch(() => void contents.set(f, ""))
179
+ )
180
+ );
175
181
  const out = [];
176
182
  for (const [dir, dirFiles] of byDir) {
177
183
  onProgress?.({ parsed, total: files.length, currentProject: realMap.get(dir) ?? dir });
178
184
  const sessions = [];
179
185
  for (const f of dirFiles) {
180
- sessions.push(await parseTranscript(f, seenMessageIds, seenToolIds));
186
+ sessions.push(parseTranscriptContent(contents.get(f) ?? "", f, seenMessageIds, seenToolIds));
181
187
  parsed += 1;
182
188
  onProgress?.({ parsed, total: files.length, currentProject: realMap.get(dir) ?? dir });
183
189
  }
@@ -1523,16 +1529,16 @@ var ADAPTERS = [
1523
1529
  detectOnly("amp", "Amp", "usage-ledger thread format \u2014 parsing not wired yet", [".local", "share", "amp"])
1524
1530
  ];
1525
1531
  async function loadAllAgents(home, onProgress) {
1526
- const out = [];
1527
- for (const adapter of ADAPTERS) {
1528
- const detected = await adapter.detect(home);
1529
- let projects = [];
1530
- if (detected && adapter.supported) {
1531
- projects = await adapter.loadProjects(home, (p) => onProgress?.(adapter.name, p)).catch(() => []);
1532
- }
1533
- out.push({ adapter, detected, projects });
1534
- }
1535
- return out;
1532
+ return Promise.all(
1533
+ ADAPTERS.map(async (adapter) => {
1534
+ const detected = await adapter.detect(home).catch(() => false);
1535
+ let projects = [];
1536
+ if (detected && adapter.supported) {
1537
+ projects = await adapter.loadProjects(home, (p) => onProgress?.(adapter.name, p)).catch(() => []);
1538
+ }
1539
+ return { adapter, detected, projects };
1540
+ })
1541
+ );
1536
1542
  }
1537
1543
 
1538
1544
  // src/ui/App.tsx
@@ -335,8 +335,7 @@ async function findTranscripts(projectPath, home = homedir()) {
335
335
  }
336
336
 
337
337
  // src/transcript.ts
338
- import { createReadStream } from "fs";
339
- import { createInterface } from "readline";
338
+ import { readFile } from "fs/promises";
340
339
  import { z } from "zod";
341
340
  var AssistantLine = z.object({
342
341
  type: z.literal("assistant"),
@@ -359,10 +358,18 @@ var AssistantLine = z.object({
359
358
  })
360
359
  });
361
360
  async function parseTranscript(file, seenMessages = /* @__PURE__ */ new Map(), seenToolIds = /* @__PURE__ */ new Set(), events) {
361
+ let content;
362
+ try {
363
+ content = await readFile(file, "utf8");
364
+ } catch {
365
+ content = "";
366
+ }
367
+ return parseTranscriptContent(content, file, seenMessages, seenToolIds, events);
368
+ }
369
+ function parseTranscriptContent(content, file, seenMessages = /* @__PURE__ */ new Map(), seenToolIds = /* @__PURE__ */ new Set(), events) {
362
370
  const stats = { file, usageByModel: {}, toolCalls: {}, toolCostUsd: {}, dailyUsage: {} };
363
- const rl = createInterface({ input: createReadStream(file, "utf8"), crlfDelay: Infinity });
364
- for await (const line of rl) {
365
- if (!line.trim()) continue;
371
+ for (const line of content.split("\n")) {
372
+ if (line.length < 2 || !line.includes("assistant")) continue;
366
373
  let raw;
367
374
  try {
368
375
  raw = JSON.parse(line);
@@ -467,5 +474,6 @@ export {
467
474
  parseDateArg,
468
475
  sanitizeProjectPath,
469
476
  findTranscripts,
470
- parseTranscript
477
+ parseTranscript,
478
+ parseTranscriptContent
471
479
  };
@@ -6,7 +6,7 @@ import {
6
6
  emptyUsage,
7
7
  shortModel,
8
8
  usd
9
- } from "./chunk-Z5W5QH2Z.js";
9
+ } from "./chunk-KO5GQL76.js";
10
10
 
11
11
  // src/blocks.ts
12
12
  var BLOCK_LENGTH_MS = 5 * 60 * 60 * 1e3;
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  buildBlocks,
4
4
  renderBlocksReport
5
- } from "./chunk-6Y6MKFHZ.js";
5
+ } from "./chunk-VJFLJJGX.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-Z5W5QH2Z.js";
20
+ } from "./chunk-KO5GQL76.js";
21
21
 
22
22
  // src/cli.ts
23
23
  import { createRequire } from "module";
@@ -210,7 +210,7 @@ program.command("blocks").description("Claude usage grouped into rolling 5-hour
210
210
  });
211
211
  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) => {
212
212
  const globals = applyGlobals();
213
- const sl = await import("./statusline-EXFMQYFF.js");
213
+ const sl = await import("./statusline-5SJKELOG.js");
214
214
  if (action === "enable" || action === "disable") {
215
215
  try {
216
216
  console.log(action === "enable" ? await sl.enableStatusline() : await sl.disableStatusline());
@@ -251,7 +251,7 @@ program.action(async () => {
251
251
  const [{ render }, React, { Root }, { Fullscreen }] = await Promise.all([
252
252
  import("ink"),
253
253
  import("react"),
254
- import("./Root-TUEV5MJB.js"),
254
+ import("./Root-ZPDATMNQ.js"),
255
255
  import("./Fullscreen-GK2ZYXHV.js")
256
256
  ]);
257
257
  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-6Y6MKFHZ.js";
6
+ } from "./chunk-VJFLJJGX.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-Z5W5QH2Z.js";
15
+ } from "./chunk-KO5GQL76.js";
16
16
 
17
17
  // src/statusline.ts
18
18
  import { mkdir, readFile, stat, writeFile } from "fs/promises";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokz/cli",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "Audit where your coding agent's context window and API dollars go.",
5
5
  "type": "module",
6
6
  "license": "MIT",