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.
- package/LICENSE +21 -0
- package/README.md +114 -2
- package/bin/llmtop.mjs +101 -0
- package/dashboard/dist/apple-touch-icon.png +0 -0
- package/dashboard/dist/assets/index-BVbAwMVB.js +9 -0
- package/dashboard/dist/assets/index-Cp7Swcz5.css +1 -0
- package/dashboard/dist/assets/llmtop-lockup-DtFPJmhv.svg +1 -0
- package/dashboard/dist/assets/llmtop-lockup-reversed-D9OmQIVU.svg +1 -0
- package/dashboard/dist/favicon.ico +0 -0
- package/dashboard/dist/favicon.svg +1 -0
- package/dashboard/dist/index.html +19 -0
- package/dashboard/dist/llmtop-mark-192.png +0 -0
- package/dashboard/dist/llmtop-mark-512.png +0 -0
- package/dashboard/dist/site.webmanifest +11 -0
- package/dashboard/src/App.tsx +213 -0
- package/dashboard/src/controls/DateRange.tsx +108 -0
- package/dashboard/src/controls/Disclosure.tsx +15 -0
- package/dashboard/src/controls/Search.tsx +18 -0
- package/dashboard/src/controls/Select.tsx +48 -0
- package/dashboard/src/controls/popover.tsx +31 -0
- package/dashboard/src/dash.ts +23 -0
- package/dashboard/src/extra.test.ts +9 -0
- package/dashboard/src/extra.ts +16 -0
- package/dashboard/src/format.ts +29 -0
- package/dashboard/src/i18n.tsx +52 -0
- package/dashboard/src/index.ts +7 -0
- package/dashboard/src/main.tsx +7 -0
- package/dashboard/src/model.test.ts +110 -0
- package/dashboard/src/model.ts +255 -0
- package/dashboard/src/state.test.ts +48 -0
- package/dashboard/src/state.ts +61 -0
- package/dashboard/src/styles.css +401 -0
- package/dashboard/src/tip.ts +51 -0
- package/dashboard/src/treemap.test.ts +23 -0
- package/dashboard/src/treemap.ts +30 -0
- package/dashboard/src/ui.tsx +327 -0
- package/dashboard/src/views/Activity.tsx +177 -0
- package/dashboard/src/views/Context.tsx +183 -0
- package/dashboard/src/views/Models.tsx +155 -0
- package/dashboard/src/views/Overview.tsx +83 -0
- package/dashboard/src/views/Projects.tsx +116 -0
- package/dashboard/src/views/Sessions.tsx +54 -0
- package/dashboard/src/views/Subagents.tsx +102 -0
- package/docs/brand/README.md +91 -0
- package/docs/brand/brand.json +67 -0
- package/docs/brand/favicon.ico +0 -0
- package/docs/brand/png/apple-touch-icon.png +0 -0
- package/docs/brand/png/favicon-16.png +0 -0
- package/docs/brand/png/favicon-32.png +0 -0
- package/docs/brand/png/favicon-48.png +0 -0
- package/docs/brand/png/llmtop-lockup-reversed@2x.png +0 -0
- package/docs/brand/png/llmtop-lockup@2x.png +0 -0
- package/docs/brand/png/llmtop-mark-1024.png +0 -0
- package/docs/brand/png/llmtop-mark-192.png +0 -0
- package/docs/brand/png/llmtop-mark-512.png +0 -0
- package/docs/brand/png/llmtop-wordmark@2x.png +0 -0
- package/docs/brand/source/build_brand.py +173 -0
- package/docs/brand/svg/favicon.svg +1 -0
- package/docs/brand/svg/llmtop-glyph.svg +1 -0
- package/docs/brand/svg/llmtop-lockup-reversed.svg +1 -0
- package/docs/brand/svg/llmtop-lockup.svg +1 -0
- package/docs/brand/svg/llmtop-mark-light.svg +1 -0
- package/docs/brand/svg/llmtop-mark.svg +1 -0
- package/docs/brand/svg/llmtop-wordmark-reversed.svg +1 -0
- package/docs/brand/svg/llmtop-wordmark.svg +1 -0
- package/llmtop.config.example.json +10 -0
- package/package.json +73 -4
- package/prices.md +27 -0
- package/src/api.mjs +53 -0
- package/src/archive.mjs +142 -0
- package/src/config.mjs +55 -0
- package/src/context.mjs +151 -0
- package/src/dashboard.mjs +61 -0
- package/src/db.mjs +102 -0
- package/src/derive.mjs +346 -0
- package/src/effort.mjs +18 -0
- package/src/format.mjs +19 -0
- package/src/paths.mjs +82 -0
- package/src/prices-command.mjs +25 -0
- package/src/prices.mjs +146 -0
- package/src/providers/agy.mjs +438 -0
- package/src/providers/claude.mjs +274 -0
- package/src/providers/codex.mjs +589 -0
- package/src/providers/index.mjs +25 -0
- package/src/rebuilds.mjs +85 -0
- package/src/scan.mjs +214 -0
- package/src/serve.mjs +44 -0
- package/src/show.mjs +20 -0
- package/src/usage-command.mjs +110 -0
- package/src/usage.mjs +388 -0
- 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
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
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
|
+
[](https://www.npmjs.com/package/llmtop)
|
|
11
|
+
[](https://github.com/nguyencanhtrung/llmtop/blob/main/package.json)
|
|
12
|
+
[](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 & 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
|
+
}
|
|
Binary file
|