@ponbac/token-ledger 0.1.0 → 0.1.1

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.
Files changed (3) hide show
  1. package/README.md +6 -1
  2. package/dist/main.js +26 -12
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -38,6 +38,11 @@ npx @ponbac/token-ledger@latest config-example > token-ledger.json
38
38
  JSON stdout contains only the structured report, including coverage and pricing
39
39
  metadata; diagnostics go to stderr. Unknown costs are `null`, not zero.
40
40
  Terminal reports sort projects by descending API estimate, with color when supported.
41
+ The `Cost %` column shows each project’s share of the total API estimate. With
42
+ incomplete pricing, `Known cost %` shows shares of the priced subtotal; unknown
43
+ costs are excluded. A zero subtotal shows `—`. Percentages use unrounded costs
44
+ and are displayed to one decimal place, so rounded project shares may not sum
45
+ exactly to 100%.
41
46
  Set `NO_COLOR=1` for plain output. Run `--help` for options.
42
47
 
43
48
  ### Run from source
@@ -361,7 +366,7 @@ For manual publication:
361
366
  1. Log in with `npm login` using an account with publish access to `@ponbac/token-ledger`.
362
367
  2. Run `bun run check`. The CLI test packs the package, installs it offline outside
363
368
  the repository with lifecycle scripts disabled, and exercises the installed CLI.
364
- 3. Run `bun run pack` to create `dist/ponbac-token-ledger-0.1.0.tgz` (filename follows version).
369
+ 3. Run `bun run pack` to create `dist/ponbac-token-ledger-0.1.1.tgz` (filename follows version).
365
370
  4. Inspect `npm publish ./dist/npm --dry-run`.
366
371
  5. Publish with `npm publish ./dist/npm --access public`; complete npm's authentication
367
372
  prompt if requested.
package/dist/main.js CHANGED
@@ -39400,7 +39400,7 @@ var runWith2 = (command, config) => {
39400
39400
  // packages/cli/package.json
39401
39401
  var package_default = {
39402
39402
  name: "@ponbac/token-ledger",
39403
- version: "0.1.0",
39403
+ version: "0.1.1",
39404
39404
  private: true,
39405
39405
  type: "module",
39406
39406
  bin: {
@@ -40385,12 +40385,26 @@ function table2(report, columns = 120, colorful = false) {
40385
40385
  }
40386
40386
  if (projects.size === 0)
40387
40387
  return `No observed usage from ${report.since} through ${report.until} (UTC).`;
40388
- const headings = ["Project", "Input", "Cache read", "Cache write", "Output", "API estimate"];
40388
+ const cost = [...projects.values()].reduce((sum3, project) => sum3 + project.cost, 0);
40389
+ const unpriced = [...projects.values()].reduce((sum3, project) => sum3 + project.unpriced, 0);
40390
+ const headings = [
40391
+ "Project",
40392
+ "Input",
40393
+ "Cache read",
40394
+ "Cache write",
40395
+ "Output",
40396
+ "API estimate",
40397
+ unpriced ? "Known cost %" : "Cost %"
40398
+ ];
40399
+ const percentage = new Intl.NumberFormat("en-US", {
40400
+ style: "percent",
40401
+ minimumFractionDigits: 1,
40402
+ maximumFractionDigits: 1
40403
+ });
40404
+ const share2 = (value5) => cost > 0 ? percentage.format(value5 / cost) : "—";
40389
40405
  const number4 = new Intl.NumberFormat("en-US");
40390
40406
  const dollars = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" });
40391
40407
  let allTokens = zeroTokens;
40392
- let cost = 0;
40393
- let unpriced = 0;
40394
40408
  const rows = [];
40395
40409
  const ranked = [...projects].toSorted(([leftProject, left], [rightProject, right]) => right.cost - left.cost || leftProject.localeCompare(rightProject));
40396
40410
  for (const [project, total] of ranked) {
@@ -40400,11 +40414,10 @@ function table2(report, columns = 120, colorful = false) {
40400
40414
  number4.format(total.tokens.cacheRead),
40401
40415
  number4.format(total.tokens.cacheWrite),
40402
40416
  number4.format(total.tokens.output),
40403
- `${dollars.format(total.cost)}${total.unpriced ? " + unknown" : ""}`
40417
+ `${dollars.format(total.cost)}${total.unpriced ? " + unknown" : ""}`,
40418
+ share2(total.cost)
40404
40419
  ]);
40405
40420
  allTokens = addTokens(allTokens, total.tokens);
40406
- cost += total.cost;
40407
- unpriced += total.unpriced;
40408
40421
  }
40409
40422
  rows.push([
40410
40423
  "Total",
@@ -40412,16 +40425,17 @@ function table2(report, columns = 120, colorful = false) {
40412
40425
  number4.format(allTokens.cacheRead),
40413
40426
  number4.format(allTokens.cacheWrite),
40414
40427
  number4.format(allTokens.output),
40415
- `${dollars.format(cost)}${unpriced ? " + unknown" : ""}`
40428
+ `${dollars.format(cost)}${unpriced ? " + unknown" : ""}`,
40429
+ share2(cost)
40416
40430
  ]);
40417
40431
  const numericWidths = headings.slice(1).map((heading, i) => Math.max(heading.length, ...rows.map((row) => row[i + 1]?.length ?? 0)) + 2);
40418
- const projectWidth = columns - numericWidths.reduce((sum3, width2) => sum3 + width2, 0) - 7;
40432
+ const projectWidth = columns - numericWidths.reduce((sum3, width2) => sum3 + width2, 0) - (headings.length + 1);
40419
40433
  const narrow = projectWidth < 22;
40420
40434
  const colWidths = narrow ? [16, Math.max(4, columns - 19)] : [Math.min(50, projectWidth), ...numericWidths];
40421
40435
  const output = new import_cli_table3.default({
40422
40436
  head: narrow ? [] : headings.map((heading) => paint(["bold", "cyan"], heading)),
40423
40437
  colWidths,
40424
- colAligns: narrow ? ["left", "right"] : ["left", "right", "right", "right", "right", "right"],
40438
+ colAligns: narrow ? ["left", "right"] : ["left", "right", "right", "right", "right", "right", "right"],
40425
40439
  wordWrap: false,
40426
40440
  style: { head: [], border: [] }
40427
40441
  });
@@ -40445,7 +40459,7 @@ function table2(report, columns = 120, colorful = false) {
40445
40459
  return paint(["bold", "magenta"], cell);
40446
40460
  if (column === 0)
40447
40461
  return paint(projectColors[index2 % projectColors.length] ?? "cyan", cell);
40448
- if (column === headings.length - 1)
40462
+ if (column >= headings.length - 2)
40449
40463
  return paint(value5.includes("unknown") ? "yellow" : "green", cell);
40450
40464
  return cell === "0" ? paint("dim", cell) : cell;
40451
40465
  });
@@ -40465,7 +40479,7 @@ function table2(report, columns = 120, colorful = false) {
40465
40479
  "",
40466
40480
  paint("bold", `${colorful ? "\uD83D\uDCCA " : ""}${number4.format(totalTokens(allTokens))} observed tokens · ${number4.format(projects.size)} ${projects.size === 1 ? "project" : "projects"}`),
40467
40481
  ...unpriced > 0 ? [
40468
- paint("yellow", "Incomplete pricing: sorted by known API subtotal; unknown costs are additional.")
40482
+ paint("yellow", "Incomplete pricing: sorting and percentages use known API subtotals; unknown costs are additional.")
40469
40483
  ] : [],
40470
40484
  paint("dim", "USD API-equivalent estimates; not your subscription bill.")
40471
40485
  ].join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ponbac/token-ledger",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Local AI token usage and API-equivalent cost reports by project",
5
5
  "license": "MIT",
6
6
  "engines": {