llmtop 0.0.0-stage → 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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +114 -2
  3. package/bin/llmtop.mjs +101 -0
  4. package/dashboard/dist/apple-touch-icon.png +0 -0
  5. package/dashboard/dist/assets/index-BVbAwMVB.js +9 -0
  6. package/dashboard/dist/assets/index-Cp7Swcz5.css +1 -0
  7. package/dashboard/dist/assets/llmtop-lockup-DtFPJmhv.svg +1 -0
  8. package/dashboard/dist/assets/llmtop-lockup-reversed-D9OmQIVU.svg +1 -0
  9. package/dashboard/dist/favicon.ico +0 -0
  10. package/dashboard/dist/favicon.svg +1 -0
  11. package/dashboard/dist/index.html +19 -0
  12. package/dashboard/dist/llmtop-mark-192.png +0 -0
  13. package/dashboard/dist/llmtop-mark-512.png +0 -0
  14. package/dashboard/dist/site.webmanifest +11 -0
  15. package/dashboard/src/App.tsx +213 -0
  16. package/dashboard/src/controls/DateRange.tsx +108 -0
  17. package/dashboard/src/controls/Disclosure.tsx +15 -0
  18. package/dashboard/src/controls/Search.tsx +18 -0
  19. package/dashboard/src/controls/Select.tsx +48 -0
  20. package/dashboard/src/controls/popover.tsx +31 -0
  21. package/dashboard/src/dash.ts +23 -0
  22. package/dashboard/src/extra.test.ts +9 -0
  23. package/dashboard/src/extra.ts +16 -0
  24. package/dashboard/src/format.ts +29 -0
  25. package/dashboard/src/i18n.tsx +52 -0
  26. package/dashboard/src/index.ts +7 -0
  27. package/dashboard/src/main.tsx +7 -0
  28. package/dashboard/src/model.test.ts +110 -0
  29. package/dashboard/src/model.ts +255 -0
  30. package/dashboard/src/state.test.ts +48 -0
  31. package/dashboard/src/state.ts +61 -0
  32. package/dashboard/src/styles.css +401 -0
  33. package/dashboard/src/tip.ts +51 -0
  34. package/dashboard/src/treemap.test.ts +23 -0
  35. package/dashboard/src/treemap.ts +30 -0
  36. package/dashboard/src/ui.tsx +327 -0
  37. package/dashboard/src/views/Activity.tsx +177 -0
  38. package/dashboard/src/views/Context.tsx +183 -0
  39. package/dashboard/src/views/Models.tsx +155 -0
  40. package/dashboard/src/views/Overview.tsx +83 -0
  41. package/dashboard/src/views/Projects.tsx +116 -0
  42. package/dashboard/src/views/Sessions.tsx +54 -0
  43. package/dashboard/src/views/Subagents.tsx +102 -0
  44. package/docs/brand/README.md +91 -0
  45. package/docs/brand/brand.json +67 -0
  46. package/docs/brand/favicon.ico +0 -0
  47. package/docs/brand/png/apple-touch-icon.png +0 -0
  48. package/docs/brand/png/favicon-16.png +0 -0
  49. package/docs/brand/png/favicon-32.png +0 -0
  50. package/docs/brand/png/favicon-48.png +0 -0
  51. package/docs/brand/png/llmtop-lockup-reversed@2x.png +0 -0
  52. package/docs/brand/png/llmtop-lockup@2x.png +0 -0
  53. package/docs/brand/png/llmtop-mark-1024.png +0 -0
  54. package/docs/brand/png/llmtop-mark-192.png +0 -0
  55. package/docs/brand/png/llmtop-mark-512.png +0 -0
  56. package/docs/brand/png/llmtop-wordmark@2x.png +0 -0
  57. package/docs/brand/source/build_brand.py +173 -0
  58. package/docs/brand/svg/favicon.svg +1 -0
  59. package/docs/brand/svg/llmtop-glyph.svg +1 -0
  60. package/docs/brand/svg/llmtop-lockup-reversed.svg +1 -0
  61. package/docs/brand/svg/llmtop-lockup.svg +1 -0
  62. package/docs/brand/svg/llmtop-mark-light.svg +1 -0
  63. package/docs/brand/svg/llmtop-mark.svg +1 -0
  64. package/docs/brand/svg/llmtop-wordmark-reversed.svg +1 -0
  65. package/docs/brand/svg/llmtop-wordmark.svg +1 -0
  66. package/llmtop.config.example.json +10 -0
  67. package/package.json +73 -4
  68. package/prices.md +27 -0
  69. package/src/api.mjs +53 -0
  70. package/src/archive.mjs +142 -0
  71. package/src/config.mjs +55 -0
  72. package/src/context.mjs +151 -0
  73. package/src/dashboard.mjs +61 -0
  74. package/src/db.mjs +102 -0
  75. package/src/derive.mjs +346 -0
  76. package/src/effort.mjs +18 -0
  77. package/src/format.mjs +19 -0
  78. package/src/paths.mjs +82 -0
  79. package/src/prices-command.mjs +25 -0
  80. package/src/prices.mjs +146 -0
  81. package/src/providers/agy.mjs +438 -0
  82. package/src/providers/claude.mjs +274 -0
  83. package/src/providers/codex.mjs +589 -0
  84. package/src/providers/index.mjs +25 -0
  85. package/src/rebuilds.mjs +85 -0
  86. package/src/scan.mjs +214 -0
  87. package/src/serve.mjs +44 -0
  88. package/src/show.mjs +20 -0
  89. package/src/usage-command.mjs +110 -0
  90. package/src/usage.mjs +388 -0
  91. package/src/zone.mjs +15 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Trung Nguyen
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.
package/README.md CHANGED
@@ -1,3 +1,115 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nguyencanhtrung/llmtop/main/docs/brand/svg/llmtop-lockup-reversed.svg">
5
+ <img alt="llmtop" src="https://raw.githubusercontent.com/nguyencanhtrung/llmtop/main/docs/brand/svg/llmtop-lockup.svg" width="320">
6
+ </picture>
7
+
8
+ **Local usage and cost analytics for Claude Code, Codex and Antigravity**
9
+
10
+ [![npm](https://img.shields.io/npm/v/llmtop?color=blue)](https://www.npmjs.com/package/llmtop)
11
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D22.15-blue)](https://github.com/nguyencanhtrung/llmtop/blob/main/package.json)
12
+ [![License](https://img.shields.io/badge/license-MIT-blue)](https://github.com/nguyencanhtrung/llmtop/blob/main/LICENSE)
13
+
14
+ <picture>
15
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nguyencanhtrung/llmtop/main/docs/assets/overview-dark.png">
16
+ <img src="https://raw.githubusercontent.com/nguyencanhtrung/llmtop/main/docs/assets/overview-light.png" alt="llmtop overview dashboard showing multi-provider tokens, cost, sessions and cache metrics" width="900">
17
+ </picture>
18
+
19
+ <sub>Synthetic multi-provider demo data served by <code>make demo</code>.</sub>
20
+
21
+ </div>
22
+
23
+ ## Quickstart
24
+
25
+ ```bash
26
+ npm install -g llmtop
27
+ llmtop serve
28
+ ```
29
+
30
+ Or run without installing: `npx llmtop serve`. Open <http://localhost:4310>.
31
+
32
+ - **Local-only:** Binds `127.0.0.1` only; zero telemetry, zero outbound requests, zero runtime npm dependencies.
33
+ - **Zero setup:** Automatically reads `~/.claude/projects`, `~/.codex/sessions`, and `~/.gemini/antigravity-cli`, skipping absent tools.
34
+ - **Persistent archive:** Copies transcripts into append-only `.jsonl.zst` frames and indexes them into SQLite (`node:sqlite`) under `~/.config/llmtop/data/`. Requires **Node.js 22.15+**.
35
+
36
+ ## Views
37
+
38
+ - **Overview & Projects:** Cost, output tokens, cache savings, speed, daily splits (model / provider / project / effort), and Git-aware project treemap.
39
+ - **Models & Subagents:** Request behavior, effort comparisons, and main-thread vs. delegated subagent work across providers.
40
+ - **Activity & Cache:** Working hours heatmap, tool calls, skill sources, and prompt cache rebuilds by cause (`start`, `compaction`, `idle`, `other`).
41
+ - **Context & Sessions:** Pre/post-compaction context cost, counterfactual compaction replay, and sortable bilingual (EN/VI) session explorer.
42
+
43
+ <details>
44
+ <summary><strong>More screenshots (light &amp; dark)</strong></summary>
45
+
46
+ <p align="center">
47
+ <picture>
48
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nguyencanhtrung/llmtop/main/docs/assets/models-dark.png">
49
+ <img src="https://raw.githubusercontent.com/nguyencanhtrung/llmtop/main/docs/assets/models-light.png" alt="Main thread and subagent output by model" width="880">
50
+ </picture>
51
+ <br><sub>Main thread and subagent breakdown across providers.</sub>
52
+ </p>
53
+
54
+ <p align="center">
55
+ <picture>
56
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nguyencanhtrung/llmtop/main/docs/assets/treemap-dark.png">
57
+ <img src="https://raw.githubusercontent.com/nguyencanhtrung/llmtop/main/docs/assets/treemap-light.png" alt="Repository cost share treemap" width="880">
58
+ </picture>
59
+ <br><sub>Repository cost share treemap.</sub>
60
+ </p>
61
+
62
+ <p align="center">
63
+ <picture>
64
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nguyencanhtrung/llmtop/main/docs/assets/cache-dark.png">
65
+ <img src="https://raw.githubusercontent.com/nguyencanhtrung/llmtop/main/docs/assets/cache-light.png" alt="Prompt cache rebuilds by cause and extra cost" width="880">
66
+ </picture>
67
+ <br><sub>Prompt cache rebuilds by cause and extra cost.</sub>
68
+ </p>
69
+
70
+ <p align="center">
71
+ <picture>
72
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nguyencanhtrung/llmtop/main/docs/assets/context-dark.png">
73
+ <img src="https://raw.githubusercontent.com/nguyencanhtrung/llmtop/main/docs/assets/context-light.png" alt="Counterfactual compaction threshold replay" width="880">
74
+ </picture>
75
+ <br><sub>Compaction threshold replay.</sub>
76
+ </p>
77
+
78
+ <p align="center">
79
+ <picture>
80
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nguyencanhtrung/llmtop/main/docs/assets/sessions-dark.png">
81
+ <img src="https://raw.githubusercontent.com/nguyencanhtrung/llmtop/main/docs/assets/sessions-light.png" alt="Sortable sessions explorer" width="880">
82
+ </picture>
83
+ <br><sub>Sortable session explorer.</sub>
84
+ </p>
85
+
86
+ </details>
87
+
88
+ ## CLI
89
+
90
+ CLI and dashboard totals stay identical for the same window and filters (`--json` supported on listing commands).
91
+
92
+ ```bash
93
+ llmtop serve [--port n] # Dashboard at http://localhost:4310
94
+ llmtop scan # Archive new transcript lines into usage.db
95
+ llmtop usage [--days n | --since d --until d] [--by day|model|provider|effort|project|session|hour|tool|skill|subagent]
96
+ [--provider name] [--project name] [--model family] [--effort level] [--json]
97
+ llmtop prices [--json] # Verify prices.md against host cost records
98
+ llmtop show <session>:<line> # Print one archived record
99
+ llmtop --help | --version
100
+ ```
101
+
102
+ ## Configuration
103
+
104
+ Optional settings live in `~/.config/llmtop/config.json` (see [llmtop.config.example.json](https://github.com/nguyencanhtrung/llmtop/blob/main/llmtop.config.example.json)). Override paths with `XDG_CONFIG_HOME`, `LLMTOP_CONFIG`, or `LLMTOP_DATA`. Token rates come from [prices.md](https://github.com/nguyencanhtrung/llmtop/blob/main/prices.md).
105
+
106
+ ## Development
107
+
108
+ ```bash
109
+ git clone https://github.com/nguyencanhtrung/llmtop.git && cd llmtop
110
+ make start # Build dashboard and serve at http://localhost:4310 (make stop to end)
111
+ make demo # Serve 10 weeks of synthetic data at http://localhost:4311
112
+ make test # Run node --test suite (make check / make build / make screenshots)
113
+ ```
114
+
115
+ See [CONTRIBUTING.md](https://github.com/nguyencanhtrung/llmtop/blob/main/CONTRIBUTING.md) and [docs/brand/README.md](https://github.com/nguyencanhtrung/llmtop/blob/main/docs/brand/README.md). [MIT License](https://github.com/nguyencanhtrung/llmtop/blob/main/LICENSE).
package/bin/llmtop.mjs ADDED
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { loadConfig, ROOT } from "../src/config.mjs";
5
+ import { localTime } from "../src/format.mjs";
6
+ import { pricesCommand } from "../src/prices-command.mjs";
7
+ import { scan, scanReport } from "../src/scan.mjs";
8
+ import { serve } from "../src/serve.mjs";
9
+ import { show } from "../src/show.mjs";
10
+ import { usageCommand } from "../src/usage-command.mjs";
11
+
12
+ const { version: VERSION } = JSON.parse(readFileSync(join(ROOT, "package.json"), "utf8"));
13
+
14
+ const USAGE = `usage: llmtop <command> [options]
15
+
16
+ scan archive new transcript lines and ingest them
17
+ show <session>:<line> print one archived record
18
+ usage [--days n | --since d --until d] [--by day|model|provider|effort|project|session|hour|tool|skill|subagent]
19
+ [--provider name] [--project name] [--model family] [--effort level]
20
+ prices the price table checked against the host's cost records
21
+ serve [--port n] the built dashboard on http://localhost:<port>
22
+
23
+ Options:
24
+ -h, --help show this help message
25
+ -v, --version show version (${VERSION})
26
+
27
+ Listing commands accept --json. Config and data default to ~/.config/llmtop
28
+ (override with LLMTOP_CONFIG and LLMTOP_DATA).`;
29
+
30
+ const COMMANDS = {
31
+ async scan({ config, out }) {
32
+ const t = await scan(config);
33
+ reportScan(t, out);
34
+ return t.prices.errors.length ? 1 : 0;
35
+ },
36
+ async show({ config, positional, out }) {
37
+ out.write(`${await show(config, positional[0])}\n`);
38
+ },
39
+ usage: usageCommand,
40
+ async serve({ config, options, out }) {
41
+ const port = options.port === undefined ? config.port : Number(options.port);
42
+ if (!Number.isInteger(port) || port < 0 || port > 65535) throw new UsageError(`--port needs a port number, got ${options.port}`);
43
+ const at = localTime(config.timeZone);
44
+ const server = await serve(config, { port, onScan: (t) => reportScan(t, out, `${at(new Date().toISOString())} `) });
45
+ out.write(`dashboard at http://localhost:${server.address().port}: its Refresh button scans again, Ctrl+C to stop\n`);
46
+ },
47
+ prices: pricesCommand,
48
+ };
49
+
50
+ // Options are --name value or --flag; FLAGS lists the ones without a value.
51
+ const FLAGS = new Set(["json"]);
52
+ function parseArgs(argv) {
53
+ const positional = [];
54
+ const options = {};
55
+ for (let i = 0; i < argv.length; i++) {
56
+ const arg = argv[i];
57
+ if (!arg.startsWith("--")) {
58
+ positional.push(arg);
59
+ continue;
60
+ }
61
+ const name = arg.slice(2);
62
+ if (FLAGS.has(name)) options[name] = true;
63
+ else if (i + 1 < argv.length) options[name] = argv[++i];
64
+ else throw new UsageError(`option --${name} needs a value`);
65
+ }
66
+ return { positional, options };
67
+ }
68
+
69
+ class UsageError extends Error {}
70
+
71
+ function reportScan(t, out, prefix = "") {
72
+ const { lines, errors } = scanReport(t);
73
+ for (const l of lines) out.write(`${prefix}${l}\n`);
74
+ for (const e of errors) process.stderr.write(`${prefix}${e}\n`);
75
+ }
76
+
77
+ async function main(argv) {
78
+ const [command, ...rest] = argv;
79
+ if (command === "-v" || command === "--version" || command === "version") {
80
+ process.stdout.write(`${VERSION}\n`);
81
+ return 0;
82
+ }
83
+ if (command === "-h" || command === "--help" || command === "help") {
84
+ process.stdout.write(`${USAGE}\n`);
85
+ return 0;
86
+ }
87
+ const run = COMMANDS[command];
88
+ if (!run) {
89
+ process.stderr.write(`${command ? `unknown command: ${command}\n\n` : ""}${USAGE}\n`);
90
+ return 2;
91
+ }
92
+ const { positional, options } = parseArgs(rest);
93
+ return (await run({ config: loadConfig(), positional, options, out: process.stdout })) ?? 0;
94
+ }
95
+
96
+ try {
97
+ process.exitCode = await main(process.argv.slice(2));
98
+ } catch (err) {
99
+ process.stderr.write(`${err instanceof UsageError ? `${err.message}\n\n${USAGE}` : `error: ${err.message}`}\n`);
100
+ process.exitCode = err instanceof UsageError ? 2 : 1;
101
+ }