tokenskyline 0.0.0-stage → 0.1.0
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 +92 -2
- package/bin/tokenskyline.mjs +206 -0
- package/llms.txt +17 -0
- package/package.json +56 -4
- package/template.html +488 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 tokenskyline contributors
|
|
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,93 @@
|
|
|
1
|
-
#
|
|
1
|
+
# tokenskyline
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Your year of AI coding, as a 3D skyline.** One command reads the local logs of your AI coding tools and builds a GitHub-style contribution graph, 3D or flat, in a single HTML file.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx tokenskyline
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Reads local logs from Claude Code, Codex, Gemini CLI / Antigravity, Hermes Agent, Cursor, OpenCode, WorkBuddy, CodeBuddy and 60+ other AI coding tools, then opens `tokenskyline-2026.html` in your browser. Nothing is uploaded. Works on macOS, Linux and Windows (Node 18+).
|
|
10
|
+
|
|
11
|
+
[中文说明](#中文)
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
*Screenshots use sample data (`npx tokenskyline --demo`).*
|
|
18
|
+
|
|
19
|
+
## What you get
|
|
20
|
+
|
|
21
|
+
- **All tools stacked in one grid**: each day's cell is split by how much each tool used that day.
|
|
22
|
+
- **Each tool on its own row**, on the same timeline, so you can see when you switched tools.
|
|
23
|
+
- **3D skyline or flat grid**: isometric bars on a plinth, height = real usage. Opens in 3D; add `#flat` to the URL for the grid.
|
|
24
|
+
- **Three measures**: total tokens, tokens without cache reads (cache reads are often 90%+ of the total), estimated cost in USD.
|
|
25
|
+
- **A local ledger** at `~/.tokenskyline/ledger.json`: every run saves each day's totals, so days stay counted after the tools delete their logs.
|
|
26
|
+
- **One file, about 50 KB**. Send it to anyone, open it on a phone.
|
|
27
|
+
- **No logs yet?** `npx tokenskyline --demo` builds the page from sample data.
|
|
28
|
+
- **English or Chinese**, following your browser language (add `#en` or `#zh` to the URL to force one). The English page starts weeks on Sunday like GitHub; the Chinese page uses 亿/万 and starts on Monday.
|
|
29
|
+
|
|
30
|
+
## FAQ
|
|
31
|
+
|
|
32
|
+
### How do I see my Claude Code token usage as a contribution graph?
|
|
33
|
+
Run `npx tokenskyline`. It picks up `~/.claude/projects` along with every other tool it finds.
|
|
34
|
+
|
|
35
|
+
### Why is my older Claude Code usage missing?
|
|
36
|
+
Claude Code deletes conversation logs older than 30 days by default, and every usage tool (ccusage, tokscale, tokenviz, this one) reads those same logs. Set `"cleanupPeriodDays": 36500` in `~/.claude/settings.json` to keep them. From your first `tokenskyline` run on, daily totals are also kept in the ledger.
|
|
37
|
+
|
|
38
|
+
### Why do ccusage, tokscale and tokenviz show different numbers for Codex?
|
|
39
|
+
Codex writes cumulative counters, and resumed or forked sessions replay earlier events. Tools that add up the cumulative totals count the same tokens several times. On one real machine, the same Codex logs gave 22.1B, 7.7B and 6.1B tokens depending on the method. tokenskyline uses tokscale's counting, the most conservative of the three.
|
|
40
|
+
|
|
41
|
+
### How is this different from ccusage / tokscale / tokenviz?
|
|
42
|
+
|
|
43
|
+
| | tokenskyline | [tokscale](https://github.com/junhoyeo/tokscale) | [ccusage](https://github.com/ryoppippi/ccusage) | [tokenviz](https://github.com/harshkedia177/tokenviz) |
|
|
44
|
+
|---|---|---|---|---|
|
|
45
|
+
| Output | single HTML file | terminal UI, JSON, website | terminal tables, JSON | terminal, PNG |
|
|
46
|
+
| Tools | 60+ (via tokscale) | 60+ | Claude Code, Codex and more | 4 |
|
|
47
|
+
| All tools in one graph and per tool | yes | yes | no | yes |
|
|
48
|
+
| 3D view offline | yes | on tokscale.ai after submitting | no | no |
|
|
49
|
+
| Keeps days after logs are deleted | yes, local ledger | no | no | no |
|
|
50
|
+
| Leaderboard, profile embeds | no | yes | no | no |
|
|
51
|
+
|
|
52
|
+
tokenskyline does not parse logs itself; [tokscale](https://github.com/junhoyeo/tokscale) does that. If you want a public profile or a leaderboard, use tokscale.
|
|
53
|
+
|
|
54
|
+
## Options
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
--year 2026 which year (default: this year)
|
|
58
|
+
-o, --out FILE output path (default ./tokenskyline-<year>.html)
|
|
59
|
+
--clients a,b only these sources (tokscale client names)
|
|
60
|
+
--from FILE use an existing `tokscale graph` JSON instead of scanning
|
|
61
|
+
--demo build from sample data, don't read local logs
|
|
62
|
+
--no-open don't open the browser
|
|
63
|
+
--no-ledger don't read or write ~/.tokenskyline/ledger.json
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## 中文
|
|
67
|
+
|
|
68
|
+
一条命令,把你这一年用 AI 写代码烧掉的 token 画成一片"天际线":GitHub 贡献图那样按天排开,每天一根柱子,默认立体,也能切平面,输出一个单文件网页。
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npx tokenskyline
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
- 支持 Claude Code、Codex、Gemini CLI / Antigravity、Hermes、Cursor、OpenCode、WorkBuddy、CodeBuddy 等 60 多种工具,自动识别本机装了哪些。
|
|
75
|
+
- 数据只在本机,不上传。macOS、Linux、Windows 都能用,需要 Node 18 以上。
|
|
76
|
+
- 每次运行会把每天的数存进 `~/.tokenskyline/ledger.json`。Claude Code 默认 30 天删日志,有了底账,统计过的日子就不会丢。
|
|
77
|
+
- 生成的网页约 50KB,可以直接发给朋友,手机上也能打开。网址末尾加 `#flat` 打开平面格子,加 `#en` / `#zh` 切语言(默认跟浏览器语言)。
|
|
78
|
+
- 还没装 AI 工具?`npx tokenskyline --demo` 用样例数据先看效果。
|
|
79
|
+
|
|
80
|
+
**Claude Code 早期的用量为什么查不到?** Claude Code 默认只保留 30 天对话日志,所有统计工具读的都是这批日志,删了就找不回。在 `~/.claude/settings.json` 里加 `"cleanupPeriodDays": 36500` 可以避免。
|
|
81
|
+
|
|
82
|
+
## Development
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npm test # smoke test; CI runs it on Linux, macOS and Windows with Node 18 and 22
|
|
86
|
+
npm run demo # writes and opens tokenskyline-<year>-demo.html
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`template.html` is the whole page. The CLI inlines the data into it in place of `<script src="data/data.js"></script>`.
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT. Data layer by [tokscale](https://github.com/junhoyeo/tokscale).
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// tokenskyline: one command turns local AI coding token usage into a contribution graph (single HTML file).
|
|
3
|
+
// Data layer: tokscale (open source, reads local logs, uploads nothing). Zero dependencies; macOS / Linux / Windows.
|
|
4
|
+
import { spawnSync, spawn } from "node:child_process";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import os from "node:os";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
|
|
10
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const IS_WIN = process.platform === "win32";
|
|
12
|
+
const HOME_DIR = path.join(os.homedir(), ".tokenskyline");
|
|
13
|
+
const OLD_DIR = path.join(os.homedir(), ".tokenrings"); // early name; move its ledger over once
|
|
14
|
+
const LEDGER = path.join(HOME_DIR, "ledger.json");
|
|
15
|
+
const locale = process.env.LC_ALL || process.env.LANG || Intl.DateTimeFormat().resolvedOptions().locale || "";
|
|
16
|
+
const ZH = /^zh/i.test(locale);
|
|
17
|
+
const t = (zh, en) => (ZH ? zh : en);
|
|
18
|
+
const log = (...a) => console.error(...a);
|
|
19
|
+
|
|
20
|
+
// ---------- args ----------
|
|
21
|
+
const argv = process.argv.slice(2);
|
|
22
|
+
const opt = { year: new Date().getFullYear(), open: true, out: null, from: null, clients: null, ledger: true, demo: false };
|
|
23
|
+
for (let i = 0; i < argv.length; i++) {
|
|
24
|
+
const a = argv[i];
|
|
25
|
+
if (a === "-h" || a === "--help") { help(); process.exit(0); }
|
|
26
|
+
else if (a === "-v" || a === "--version") { console.log(JSON.parse(fs.readFileSync(path.join(HERE, "..", "package.json"), "utf8")).version); process.exit(0); }
|
|
27
|
+
else if (a === "--year") opt.year = +argv[++i];
|
|
28
|
+
else if (a === "-o" || a === "--out") opt.out = argv[++i];
|
|
29
|
+
else if (a === "--from") opt.from = argv[++i];
|
|
30
|
+
else if (a === "--clients") opt.clients = argv[++i];
|
|
31
|
+
else if (a === "--demo") opt.demo = true;
|
|
32
|
+
else if (a === "--no-open") opt.open = false;
|
|
33
|
+
else if (a === "--no-ledger") opt.ledger = false;
|
|
34
|
+
else { log(t(`不认识的参数:${a}(--help 看用法)`, `Unknown option: ${a} (see --help)`)); process.exit(2); }
|
|
35
|
+
}
|
|
36
|
+
function help() {
|
|
37
|
+
console.log(t(
|
|
38
|
+
`用法:npx tokenskyline [选项]
|
|
39
|
+
|
|
40
|
+
读取本机 AI 工具日志(Claude Code、Codex、Gemini/Antigravity、Hermes、Cursor、OpenCode 等 60+ 种),
|
|
41
|
+
生成一个单文件 HTML 天际线图并用浏览器打开。数据只在本机。
|
|
42
|
+
|
|
43
|
+
--year 2026 统计哪一年(默认今年)
|
|
44
|
+
-o, --out 文件 输出路径(默认 ./tokenskyline-<年>.html)
|
|
45
|
+
--clients a,b 只统计这些来源(tokscale 的 client 名)
|
|
46
|
+
--from 文件 直接用已有的 tokscale graph JSON,不再扫描日志
|
|
47
|
+
--demo 用样例数据生成,不读本机日志
|
|
48
|
+
--no-open 生成后不自动打开
|
|
49
|
+
--no-ledger 不读写本地底账 ~/.tokenskyline/ledger.json`,
|
|
50
|
+
`Usage: npx tokenskyline [options]
|
|
51
|
+
|
|
52
|
+
Reads local logs of your AI coding tools (Claude Code, Codex, Gemini/Antigravity, Hermes, Cursor,
|
|
53
|
+
OpenCode and 60+ more), writes a single-file HTML contribution graph and opens it. Nothing is uploaded.
|
|
54
|
+
|
|
55
|
+
--year 2026 which year (default: this year)
|
|
56
|
+
-o, --out FILE output path (default ./tokenskyline-<year>.html)
|
|
57
|
+
--clients a,b only these sources (tokscale client names)
|
|
58
|
+
--from FILE use an existing \`tokscale graph\` JSON instead of scanning
|
|
59
|
+
--demo build from sample data, don't read local logs
|
|
60
|
+
--no-open don't open the browser
|
|
61
|
+
--no-ledger don't read or write ~/.tokenskyline/ledger.json`));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const fmt = n => ZH
|
|
65
|
+
? (n >= 1e8 ? (n / 1e8).toFixed(1) + " 亿" : n >= 1e4 ? Math.round(n / 1e4) + " 万" : String(n))
|
|
66
|
+
: (n >= 1e9 ? (n / 1e9).toFixed(2) + "B" : n >= 1e6 ? (n / 1e6).toFixed(1) + "M" : n >= 1e3 ? Math.round(n / 1e3) + "K" : String(n));
|
|
67
|
+
|
|
68
|
+
// ---------- build days ----------
|
|
69
|
+
let days;
|
|
70
|
+
if (opt.demo) {
|
|
71
|
+
days = demoDays(opt.year);
|
|
72
|
+
} else {
|
|
73
|
+
const graph = scan();
|
|
74
|
+
const ledger = mergeLedger(graph);
|
|
75
|
+
days = compact(ledger);
|
|
76
|
+
}
|
|
77
|
+
if (!Object.keys(days).length) {
|
|
78
|
+
log(t(`${opt.year} 年在本机没有找到任何 AI 工具的用量记录。可以先试试 npx tokenskyline --demo`,
|
|
79
|
+
`No AI tool usage found on this machine for ${opt.year}. Try npx tokenskyline --demo`));
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
const totals = {};
|
|
83
|
+
for (const out of Object.values(days)) for (const [k, a] of Object.entries(out)) totals[k] = (totals[k] || 0) + a[0] + a[1] + a[2] + a[3];
|
|
84
|
+
const payload = {
|
|
85
|
+
generatedAt: new Date().toISOString(), year: opt.year, demo: opt.demo || undefined,
|
|
86
|
+
tools: Object.keys(totals).sort((a, b) => totals[b] - totals[a]),
|
|
87
|
+
fields: ["input", "output", "cacheRead", "cacheWrite", "costUSD", "messages", "topModel"], days,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// ---------- write single file ----------
|
|
91
|
+
const tpl = fs.readFileSync(path.join(HERE, "..", "template.html"), "utf8");
|
|
92
|
+
const json = JSON.stringify(payload).replace(/</g, "\\u003c");
|
|
93
|
+
const html = "<!doctype html>\n" + tpl.replace('<script src="data/data.js"></script>', `<script>window.TOKEN_DATA=${json};</script>`);
|
|
94
|
+
const outFile = path.resolve(opt.out || `tokenskyline-${opt.year}${opt.demo ? "-demo" : ""}.html`);
|
|
95
|
+
fs.mkdirSync(path.dirname(outFile), { recursive: true });
|
|
96
|
+
fs.writeFileSync(outFile, html);
|
|
97
|
+
|
|
98
|
+
const tot = Object.values(totals).reduce((a, b) => a + b, 0);
|
|
99
|
+
log(t(`\n${opt.year} 年合计 ${fmt(tot)} token,${Object.keys(days).length} 天,${payload.tools.length} 个来源`,
|
|
100
|
+
`\n${opt.year}: ${fmt(tot)} tokens over ${Object.keys(days).length} days from ${payload.tools.length} sources`));
|
|
101
|
+
for (const k of payload.tools) log(` ${k.padEnd(14)} ${fmt(totals[k]).padStart(9)} ${(totals[k] / tot * 100).toFixed(1)}%`);
|
|
102
|
+
log(t(`\n已生成 ${outFile}`, `\nWrote ${outFile}`));
|
|
103
|
+
|
|
104
|
+
if (opt.open) {
|
|
105
|
+
const [cmd, args] = process.platform === "darwin" ? ["open", [outFile]]
|
|
106
|
+
: IS_WIN ? ["cmd", ["/c", "start", '""', `"${outFile}"`]]
|
|
107
|
+
: ["xdg-open", [outFile]];
|
|
108
|
+
try { spawn(cmd, args, { stdio: "ignore", detached: true, windowsHide: true, windowsVerbatimArguments: IS_WIN }).unref(); } catch { /* path is printed above */ }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ---------- 1. scan with tokscale ----------
|
|
112
|
+
function scan() {
|
|
113
|
+
if (opt.from) return JSON.parse(fs.readFileSync(opt.from, "utf8"));
|
|
114
|
+
const tmp = path.join(os.tmpdir(), `tokenskyline-${process.pid}.json`);
|
|
115
|
+
const args = ["-y", "tokscale@latest", "graph", "--since", `${opt.year}-01-01`, "--until", `${opt.year}-12-31`,
|
|
116
|
+
"--output", tmp, "--no-spinner"];
|
|
117
|
+
if (opt.clients) args.push("--client", opt.clients);
|
|
118
|
+
log(t("正在扫描本机日志(首次运行会下载 tokscale,稍等)…", "Scanning local logs (first run downloads tokscale)…"));
|
|
119
|
+
// On Windows npx is npx.cmd and must go through the shell
|
|
120
|
+
const r = spawnSync(IS_WIN ? "npx.cmd" : "npx", args, { stdio: ["ignore", "ignore", "inherit"], shell: IS_WIN });
|
|
121
|
+
if (r.status !== 0 || !fs.existsSync(tmp)) {
|
|
122
|
+
log(t("tokscale 运行失败。需要 Node 18+ 并能访问 npm;也可以先跑 `npx tokscale graph --output x.json` 再用 --from x.json。",
|
|
123
|
+
"tokscale failed. Needs Node 18+ and npm access; or run `npx tokscale graph --output x.json` and pass --from x.json."));
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
const g = JSON.parse(fs.readFileSync(tmp, "utf8"));
|
|
127
|
+
fs.rmSync(tmp, { force: true });
|
|
128
|
+
return g;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ---------- 2. local ledger: days stay counted after tools delete their logs ----------
|
|
132
|
+
function mergeLedger(graph) {
|
|
133
|
+
const sumRows = rows => rows.reduce((s, r) => s + Object.values(r.tokens).reduce((a, b) => a + b, 0), 0);
|
|
134
|
+
let ledger = {};
|
|
135
|
+
if (opt.ledger && !fs.existsSync(LEDGER) && fs.existsSync(path.join(OLD_DIR, "ledger.json"))) {
|
|
136
|
+
fs.mkdirSync(HOME_DIR, { recursive: true }); fs.copyFileSync(path.join(OLD_DIR, "ledger.json"), LEDGER);
|
|
137
|
+
}
|
|
138
|
+
if (opt.ledger) { try { ledger = JSON.parse(fs.readFileSync(LEDGER, "utf8")); } catch { ledger = {}; } }
|
|
139
|
+
for (const day of graph.contributions || []) {
|
|
140
|
+
const by = {};
|
|
141
|
+
for (const c of day.clients || []) (by[c.client] ||= []).push(c);
|
|
142
|
+
const slot = (ledger[day.date] ||= {});
|
|
143
|
+
for (const [cl, rows] of Object.entries(by)) {
|
|
144
|
+
if (!slot[cl] || sumRows(rows) >= sumRows(slot[cl])) slot[cl] = rows; // logs only shrink: keep the larger copy
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (opt.ledger) { fs.mkdirSync(HOME_DIR, { recursive: true }); fs.writeFileSync(LEDGER, JSON.stringify(ledger)); }
|
|
148
|
+
return ledger;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ---------- 3. compact: days[date][tool] = [input, output(+reasoning), cacheRead, cacheWrite, costUSD, messages, topModel] ----------
|
|
152
|
+
function compact(ledger) {
|
|
153
|
+
const MERGE = { "antigravity-cli": "antigravity", "antigravity-extension": "antigravity", "micode-desktop": "micode" };
|
|
154
|
+
const out = {};
|
|
155
|
+
for (const [d, slot] of Object.entries(ledger).sort()) {
|
|
156
|
+
if (!d.startsWith(String(opt.year))) continue;
|
|
157
|
+
const day = {};
|
|
158
|
+
for (const [cl, rows] of Object.entries(slot)) {
|
|
159
|
+
const k = MERGE[cl] || cl;
|
|
160
|
+
const a = (day[k] ||= [0, 0, 0, 0, 0, 0, {}]);
|
|
161
|
+
for (const r of rows) {
|
|
162
|
+
const tk = r.tokens;
|
|
163
|
+
a[0] += tk.input || 0; a[1] += (tk.output || 0) + (tk.reasoning || 0);
|
|
164
|
+
a[2] += tk.cacheRead || 0; a[3] += tk.cacheWrite || 0;
|
|
165
|
+
a[4] += r.cost || 0; a[5] += r.messages || 0;
|
|
166
|
+
a[6][r.modelId] = (a[6][r.modelId] || 0) + Object.values(tk).reduce((x, y) => x + y, 0);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
for (const a of Object.values(day)) {
|
|
170
|
+
a[4] = Math.round(a[4] * 100) / 100;
|
|
171
|
+
const m = a[6]; a[6] = Object.keys(m).sort((x, y) => m[y] - m[x])[0] || "";
|
|
172
|
+
}
|
|
173
|
+
out[d] = day;
|
|
174
|
+
}
|
|
175
|
+
return out;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ---------- demo: deterministic sample data ----------
|
|
179
|
+
function demoDays(year) {
|
|
180
|
+
let seed = 20260101;
|
|
181
|
+
const rnd = () => (seed = (seed * 1664525 + 1013904223) % 4294967296) / 4294967296;
|
|
182
|
+
const gauss = () => Math.sqrt(-2 * Math.log(rnd() || 1e-9)) * Math.cos(2 * Math.PI * rnd());
|
|
183
|
+
// tool: [model, $ per token, first month, last month, chance of use on a weekday, typical tokens per day]
|
|
184
|
+
const T = {
|
|
185
|
+
cursor: ["cursor-auto", 0.9e-6, 0, 4, .7, 1.5e7],
|
|
186
|
+
claude: ["claude-sonnet", 1.4e-6, 1, 11, .85, 5.5e7],
|
|
187
|
+
gemini: ["gemini-pro", 0.7e-6, 2, 8, .35, 2.2e7],
|
|
188
|
+
codex: ["gpt-codex", 1.1e-6, 4, 11, .6, 4e7],
|
|
189
|
+
opencode: ["kimi", 0.4e-6, 6, 11, .2, 1e7],
|
|
190
|
+
};
|
|
191
|
+
const out = {};
|
|
192
|
+
const end = new Date(Math.min(Date.now(), new Date(year, 11, 31).getTime()));
|
|
193
|
+
for (let d = new Date(year, 0, 1); d <= end; d.setDate(d.getDate() + 1)) {
|
|
194
|
+
const m = d.getMonth(), wk = d.getDay() === 0 || d.getDay() === 6;
|
|
195
|
+
const iso = `${year}-${String(m + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
196
|
+
const day = {};
|
|
197
|
+
for (const [k, [model, usd, m0, m1, p, base]] of Object.entries(T)) {
|
|
198
|
+
if (m < m0 || m > m1 || rnd() > p * (wk ? .45 : 1)) continue;
|
|
199
|
+
const tot = base * (0.6 + m / 12) * Math.exp(0.8 * gauss());
|
|
200
|
+
day[k] = [Math.round(tot * .055), Math.round(tot * .025), Math.round(tot * .91), Math.round(tot * .01),
|
|
201
|
+
Math.round(tot * usd * 100) / 100, Math.round(tot / 4e5), model];
|
|
202
|
+
}
|
|
203
|
+
if (Object.keys(day).length) out[iso] = day;
|
|
204
|
+
}
|
|
205
|
+
return out;
|
|
206
|
+
}
|
package/llms.txt
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# tokenskyline
|
|
2
|
+
|
|
3
|
+
> One command (`npx tokenskyline`) turns local AI coding token usage into a 3D skyline / GitHub-style contribution graph (3D or flat, English or Chinese), saved as a single HTML file. Reads Claude Code, Codex, Gemini CLI, Antigravity, Hermes Agent, Cursor, OpenCode, WorkBuddy, CodeBuddy and 60+ other tools through tokscale. Nothing is uploaded. macOS, Linux, Windows; Node 18+.
|
|
4
|
+
|
|
5
|
+
## Use
|
|
6
|
+
- `npx tokenskyline`: scan this year, write tokenskyline-<year>.html, open it
|
|
7
|
+
- `npx tokenskyline --demo`: sample data, no logs read
|
|
8
|
+
- `npx tokenskyline --year 2025 --no-open -o usage.html`
|
|
9
|
+
|
|
10
|
+
## Facts
|
|
11
|
+
- Claude Code deletes conversation logs older than 30 days by default; ccusage, tokscale, tokenviz and tokenskyline all read those logs, so deleted days cannot be recovered. Set "cleanupPeriodDays": 36500 in ~/.claude/settings.json. tokenskyline also keeps daily totals in ~/.tokenskyline/ledger.json from the first run on.
|
|
12
|
+
- Codex logs carry cumulative counters and resumed sessions replay earlier events, so tools disagree on Codex totals; tokenskyline uses tokscale's counting.
|
|
13
|
+
- Cache reads are usually over 90% of total tokens, so the page also shows totals without cache reads.
|
|
14
|
+
|
|
15
|
+
## Links
|
|
16
|
+
- README: README.md
|
|
17
|
+
- Data layer: https://github.com/junhoyeo/tokscale
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokenskyline",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Your year of AI coding as a 3D token skyline. One command reads local logs of Claude Code, Codex, Gemini/Antigravity, Hermes, Cursor, OpenCode and 60+ tools and writes a single HTML file: GitHub-style contribution graph, flat or 3D.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"tokenskyline": "bin/tokenskyline.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"template.html",
|
|
12
|
+
"llms.txt"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=18"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"3d",
|
|
19
|
+
"ai-usage",
|
|
20
|
+
"antigravity",
|
|
21
|
+
"ccusage",
|
|
22
|
+
"claude",
|
|
23
|
+
"claude-code",
|
|
24
|
+
"codex",
|
|
25
|
+
"contribution-graph",
|
|
26
|
+
"cursor",
|
|
27
|
+
"gemini-cli",
|
|
28
|
+
"github-contributions",
|
|
29
|
+
"github-skyline",
|
|
30
|
+
"heatmap",
|
|
31
|
+
"skyline",
|
|
32
|
+
"token",
|
|
33
|
+
"token-usage",
|
|
34
|
+
"tokscale",
|
|
35
|
+
"usage",
|
|
36
|
+
"windows",
|
|
37
|
+
"wrapped",
|
|
38
|
+
"year-in-review"
|
|
39
|
+
],
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"test": "node test/check.mjs",
|
|
43
|
+
"demo": "node bin/tokenskyline.mjs --demo"
|
|
44
|
+
},
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/Gan-Git/tokenskyline.git"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/Gan-Git/tokenskyline#readme",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/Gan-Git/tokenskyline/issues"
|
|
52
|
+
},
|
|
53
|
+
"author": "Gan-Git",
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"registry": "https://registry.npmjs.org/",
|
|
56
|
+
"access": "public"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/template.html
ADDED
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
|
|
2
|
+
<title>Token Skyline</title>
|
|
3
|
+
<meta name="claude:viewport-fit-sides" content="cover">
|
|
4
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
5
|
+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Familjen+Grotesk:wght@500;700&family=IBM+Plex+Mono:wght@400;500&display=swap">
|
|
6
|
+
<style>
|
|
7
|
+
/* 版式:一张仪表式的年度账页——顶部大数 + 份额条,中间一张合成网格(平面/立体),下面五家各一行小图,最后脚注说清口径 */
|
|
8
|
+
:root{
|
|
9
|
+
--bg:#F1F3F0; --ink:#141C22; --muted:#5B676E; --rule:#CFD5D2; --empty:#E1E5E1; --hl:#141C22; --pl-t:#E6EAE7; --pl-l:#D7DDDA; --pl-r:#C7CECB;
|
|
10
|
+
--c-claude:#C0522B; --c-codex:#1D6E77; --c-agy:#2E5BC8; --c-hermes:#B98A10; --c-workbuddy:#617F27;
|
|
11
|
+
--f-display:"Familjen Grotesk","PingFang SC","Hiragino Sans GB","Microsoft YaHei",system-ui,sans-serif;
|
|
12
|
+
--f-body:"PingFang SC","Hiragino Sans GB","Microsoft YaHei",system-ui,-apple-system,sans-serif;
|
|
13
|
+
--f-mono:"IBM Plex Mono","SF Mono",Menlo,Consolas,monospace;
|
|
14
|
+
}
|
|
15
|
+
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]){
|
|
16
|
+
--bg:#0F1418; --ink:#E4E9E6; --muted:#8A979D; --rule:#263036; --empty:#1A2227; --hl:#E4E9E6; --pl-t:#161D21; --pl-l:#1E272C; --pl-r:#11171A;
|
|
17
|
+
--c-claude:#E5744A; --c-codex:#3BB0B6; --c-agy:#6B90F2; --c-hermes:#E3B841; --c-workbuddy:#9BBE52; color-scheme:dark}}
|
|
18
|
+
:root[data-theme="dark"]{
|
|
19
|
+
--bg:#0F1418; --ink:#E4E9E6; --muted:#8A979D; --rule:#263036; --empty:#1A2227; --hl:#E4E9E6; --pl-t:#161D21; --pl-l:#1E272C; --pl-r:#11171A;
|
|
20
|
+
--c-claude:#E5744A; --c-codex:#3BB0B6; --c-agy:#6B90F2; --c-hermes:#E3B841; --c-workbuddy:#9BBE52; color-scheme:dark}
|
|
21
|
+
*{box-sizing:border-box}
|
|
22
|
+
[hidden]{display:none!important}
|
|
23
|
+
body{background:var(--bg);color:var(--ink);font-family:var(--f-body);font-size:14px;line-height:1.5}
|
|
24
|
+
.wrap{max-width:1120px;margin:0 auto;padding-block:40px 64px;padding-left:max(16px,env(safe-area-inset-left,0px));padding-right:max(16px,env(safe-area-inset-right,0px));display:grid;gap:40px}
|
|
25
|
+
.num{font-family:var(--f-mono);font-variant-numeric:tabular-nums}
|
|
26
|
+
.eyebrow{font-family:var(--f-mono);font-size:11px;letter-spacing:.12em;text-transform:uppercase;color:var(--muted);display:flex;flex-wrap:wrap;gap:4px 8px;align-items:baseline}
|
|
27
|
+
.cmd{margin-left:auto;font-family:var(--f-mono);font-size:12px;letter-spacing:0;text-transform:none;color:var(--ink);border:1px solid var(--ink);padding:1px 7px}
|
|
28
|
+
.demo{color:var(--bg);background:var(--c-claude,#C0522B);padding:0 6px;letter-spacing:.04em}
|
|
29
|
+
.cmd::before{content:"$ ";color:var(--muted)}
|
|
30
|
+
h1,h2{font-family:var(--f-display);font-weight:700;margin:0;text-wrap:balance}
|
|
31
|
+
|
|
32
|
+
/* 顶部 */
|
|
33
|
+
.head{display:grid;gap:18px}
|
|
34
|
+
.hero{display:flex;flex-wrap:wrap;align-items:flex-end;gap:12px 40px;justify-content:space-between}
|
|
35
|
+
.big{font-family:var(--f-display);font-weight:700;font-size:clamp(52px,10vw,104px);line-height:.9;letter-spacing:-.03em}
|
|
36
|
+
.big small{font-size:.32em;letter-spacing:0;font-weight:500;margin-left:.25em;color:var(--muted)}
|
|
37
|
+
.kpis{display:grid;grid-template-columns:repeat(4,auto);gap:4px 28px}
|
|
38
|
+
.kpi{display:grid;gap:2px}
|
|
39
|
+
.kpi b{font-family:var(--f-mono);font-weight:500;font-size:20px;font-variant-numeric:tabular-nums}
|
|
40
|
+
.kpi span{font-size:12px;color:var(--muted)}
|
|
41
|
+
.kpi .sub{font-family:var(--f-mono);font-size:11px;font-variant-numeric:tabular-nums;border-top:1px solid var(--rule);padding-top:3px;margin-top:2px}
|
|
42
|
+
.share{display:flex;height:10px;width:100%;background:var(--empty)}
|
|
43
|
+
.share i{display:block;height:100%}
|
|
44
|
+
.legend{display:flex;flex-wrap:wrap;gap:6px 22px;font-size:12px;color:var(--muted)}
|
|
45
|
+
.legend span{display:inline-flex;align-items:center;gap:6px}
|
|
46
|
+
.legend i{width:9px;height:9px;display:inline-block}
|
|
47
|
+
|
|
48
|
+
/* 控件 */
|
|
49
|
+
.bar{display:flex;flex-wrap:wrap;gap:10px 22px;align-items:center;border-top:1px solid var(--ink);border-bottom:1px solid var(--rule);padding-block:10px}
|
|
50
|
+
.seg{display:inline-flex;border:1px solid var(--rule)}
|
|
51
|
+
.seg button,.tool{font:inherit;font-size:12.5px;background:none;color:var(--muted);border:0;padding:5px 11px;cursor:pointer}
|
|
52
|
+
.seg button+button{border-left:1px solid var(--rule)}
|
|
53
|
+
.seg button[aria-pressed="true"]{background:var(--ink);color:var(--bg)}
|
|
54
|
+
.tools{display:flex;flex-wrap:wrap;gap:2px}
|
|
55
|
+
.tool{display:inline-flex;align-items:center;gap:7px;padding:5px 9px;border:1px solid transparent}
|
|
56
|
+
.tool i{width:10px;height:10px;display:inline-block;border:1.5px solid currentColor}
|
|
57
|
+
.tool[aria-pressed="true"]{color:var(--ink)}
|
|
58
|
+
.tool[aria-pressed="true"] i{border-color:transparent}
|
|
59
|
+
.tool[aria-pressed="false"] i{background:none!important}
|
|
60
|
+
button:focus-visible{outline:2px solid var(--hl);outline-offset:1px}
|
|
61
|
+
.grow{flex:1}
|
|
62
|
+
|
|
63
|
+
/* 主图 */
|
|
64
|
+
.main{display:grid;gap:10px}
|
|
65
|
+
.scroll{overflow-x:auto;overflow-y:hidden;-webkit-overflow-scrolling:touch}
|
|
66
|
+
#cv3{display:block}
|
|
67
|
+
.scale{display:flex;align-items:center;gap:6px;font-size:11px;color:var(--muted);justify-content:flex-end}
|
|
68
|
+
.scale i{width:11px;height:11px;display:inline-block}
|
|
69
|
+
.note{font-size:12px;color:var(--muted)}
|
|
70
|
+
|
|
71
|
+
/* 分家 */
|
|
72
|
+
.rows{display:grid;gap:0}
|
|
73
|
+
.row{display:grid;grid-template-columns:200px minmax(0,1fr);gap:20px;align-items:start;padding-block:16px;border-top:1px solid var(--rule)}
|
|
74
|
+
.row:last-child{border-bottom:1px solid var(--rule)}
|
|
75
|
+
.row{cursor:pointer}
|
|
76
|
+
.row.off{opacity:.38}
|
|
77
|
+
.row:hover .meta h3{text-decoration:underline;text-underline-offset:3px}
|
|
78
|
+
.cap{display:flex;justify-content:space-between;gap:12px;flex-wrap:wrap;align-items:baseline}
|
|
79
|
+
.cap h2{font-size:17px}
|
|
80
|
+
.meta{display:grid;gap:3px}
|
|
81
|
+
.meta h3{margin:0;font-family:var(--f-display);font-size:18px;font-weight:700;display:flex;align-items:center;gap:8px}
|
|
82
|
+
.meta h3 i{width:10px;height:10px;display:inline-block}
|
|
83
|
+
.meta .t{font-family:var(--f-mono);font-size:15px}
|
|
84
|
+
.meta .s{font-size:12px;color:var(--muted)}
|
|
85
|
+
@media (max-width:720px){.row{grid-template-columns:minmax(0,1fr);gap:8px}.kpis{grid-template-columns:repeat(2,auto)}}
|
|
86
|
+
|
|
87
|
+
.foot{font-size:12px;color:var(--muted);display:grid;gap:6px;max-width:72ch}
|
|
88
|
+
.foot b{color:var(--ink);font-weight:500}
|
|
89
|
+
.foot .gen{display:flex;align-items:baseline;gap:10px;margin-top:6px}
|
|
90
|
+
.foot .gen .cmd{margin-left:0;font-size:14px;padding:3px 10px}
|
|
91
|
+
|
|
92
|
+
#tip{position:fixed;z-index:20;pointer-events:none;background:var(--ink);color:var(--bg);font-size:12px;padding:8px 10px;min-width:170px;display:none}
|
|
93
|
+
#tip .d{font-family:var(--f-mono);margin-bottom:4px}
|
|
94
|
+
#tip .r{display:flex;justify-content:space-between;gap:14px;font-family:var(--f-mono);font-variant-numeric:tabular-nums}
|
|
95
|
+
#tip .r i{width:8px;height:8px;display:inline-block;margin-right:6px}
|
|
96
|
+
#tip .m{opacity:.7;font-size:11px;margin-top:4px}
|
|
97
|
+
svg text{fill:var(--muted);font-family:var(--f-mono);font-size:10px}
|
|
98
|
+
@media (prefers-reduced-motion:no-preference){.share i{transition:width .3s}}
|
|
99
|
+
</style>
|
|
100
|
+
|
|
101
|
+
<div class="wrap">
|
|
102
|
+
<header class="head">
|
|
103
|
+
<div class="eyebrow"><span id="yr"></span> · <span id="brand"></span> · <span id="upd"></span><span class="cmd">npx tokenskyline</span></div>
|
|
104
|
+
<div class="hero">
|
|
105
|
+
<div>
|
|
106
|
+
<div class="big" id="bigNum">—</div>
|
|
107
|
+
<div class="note" id="bigSub"></div>
|
|
108
|
+
</div>
|
|
109
|
+
<div class="kpis" id="kpis"></div>
|
|
110
|
+
</div>
|
|
111
|
+
<div class="share" id="share"></div>
|
|
112
|
+
<div class="legend" id="shareLegend"></div>
|
|
113
|
+
</header>
|
|
114
|
+
|
|
115
|
+
<section class="main">
|
|
116
|
+
<div class="cap"><h2 id="h1"></h2><span class="eyebrow" id="fig1"></span></div>
|
|
117
|
+
<div class="bar">
|
|
118
|
+
<div class="seg" role="group" id="gView">
|
|
119
|
+
<button id="v3d" aria-pressed="true"></button><button id="v2d" aria-pressed="false"></button>
|
|
120
|
+
</div>
|
|
121
|
+
<div class="seg" role="group" id="gMetric">
|
|
122
|
+
<button id="mTotal" aria-pressed="true"></button><button id="mNoCache" aria-pressed="false"></button><button id="mCost" aria-pressed="false"></button>
|
|
123
|
+
</div>
|
|
124
|
+
<div class="seg" role="group" id="gRange">
|
|
125
|
+
<button id="rData" aria-pressed="true"></button><button id="rYear" aria-pressed="false"></button>
|
|
126
|
+
</div>
|
|
127
|
+
<div class="grow"></div>
|
|
128
|
+
<div class="tools" id="tools"></div>
|
|
129
|
+
</div>
|
|
130
|
+
<div class="scroll" id="mainScroll"><div id="w2d" hidden><svg id="grid2d"></svg></div><canvas id="cv3"></canvas></div>
|
|
131
|
+
<div class="scale" id="scale"></div>
|
|
132
|
+
</section>
|
|
133
|
+
|
|
134
|
+
<section class="main">
|
|
135
|
+
<div class="cap"><h2 id="h2"></h2><span class="note" id="h2note"></span></div>
|
|
136
|
+
<div class="rows" id="rows"></div>
|
|
137
|
+
</section>
|
|
138
|
+
|
|
139
|
+
<footer class="foot" id="foot"></footer>
|
|
140
|
+
</div>
|
|
141
|
+
<div id="tip"></div>
|
|
142
|
+
|
|
143
|
+
<script src="data/data.js"></script>
|
|
144
|
+
<script>
|
|
145
|
+
(function(){
|
|
146
|
+
const D = window.TOKEN_DATA;
|
|
147
|
+
const $ = id=>document.getElementById(id);
|
|
148
|
+
|
|
149
|
+
// ---------- 语言:#en / #zh 优先,其次浏览器语言 ----------
|
|
150
|
+
const HASH=location.hash.toLowerCase();
|
|
151
|
+
const LANG=/\ben\b/.test(HASH.replace(/[#-]/g," "))?"en":/\bzh\b/.test(HASH.replace(/[#-]/g," "))?"zh":
|
|
152
|
+
((D.lang||navigator.language||"en").toLowerCase().startsWith("zh")?"zh":"en");
|
|
153
|
+
const ZH=LANG==="zh";
|
|
154
|
+
const L=ZH?{
|
|
155
|
+
title:"Token 天际线", brand:"AI token 天际线", upd:"更新于", demo:"样例数据 · 不是真实用量",
|
|
156
|
+
h1:"合在一起看", fig1:"图 1 · 各家叠加", h2:"分开看", h2note:"每家按自己的分位上色 · 点一行可在图 1 里加上或去掉",
|
|
157
|
+
v3d:"立体", v2d:"平面", mTotal:"全部 token", mNoCache:"不含缓存", mCost:"估算费用", rData:"有记录以来", rYear:"全年",
|
|
158
|
+
gView:"视图", gMetric:"口径", gRange:"时间范围",
|
|
159
|
+
usd:"估算美元", none:"未选", estCost:"按官方价估算", perDay:"日均", cacheShare:"缓存读占", allTok:"全部 token",
|
|
160
|
+
days:n=>n+" 天", activeDays:"有用量的日子", since:d=>d+" 起有记录", streak:"最长连续", peak:"最猛一天", led:n=>n+"主导",
|
|
161
|
+
scale2d:"格内分段 = 各家当天占比 · 深浅按分位五档", cuts:"分界", scale3d:"柱高 = 当天真实用量 · 柱内分段 = 各家当天占比",
|
|
162
|
+
rowTip:n=>"点击:在图 1 里加上或去掉 "+n, from:d=>d+" 起", main:"主力", total:"合计", noRec:"没有记录",
|
|
163
|
+
wd:["一","","三","","五","","日"], weekStart:1,
|
|
164
|
+
foot:(cover,gap)=>`
|
|
165
|
+
<div><b>数据从哪来</b> 本机各家 AI 工具的日志,由开源工具 tokscale 读取,数据只在本机,不上传。每次运行都会把每天的数存进一份本地底账,日志被清理后,统计过的日子不会丢。</div>
|
|
166
|
+
<div><b>口径</b> 全部 token = 输入 + 输出(含思考)+ 缓存读 + 缓存写;缓存读通常占九成以上,所以另给"不含缓存"。费用按各家官方单价估算,不是实际扣费,订阅制下实际花的钱远少于此。</div>
|
|
167
|
+
<div><b>覆盖</b> ${cover}。${gap?"Claude Code 默认只保留 30 天对话日志,更早的已经删掉了;在 ~/.claude/settings.json 里把 cleanupPeriodDays 设大可以避免。":""}</div>
|
|
168
|
+
<div class="gen">生成你自己的:<span class="cmd">npx tokenskyline</span></div>`
|
|
169
|
+
}:{
|
|
170
|
+
title:"Token Skyline", brand:"AI token skyline", upd:"updated", demo:"sample data · not real usage",
|
|
171
|
+
h1:"All tools together", fig1:"fig. 1 · stacked", h2:"One tool at a time", h2note:"each row colored by its own quartiles · click a row to add or remove it from fig. 1",
|
|
172
|
+
v3d:"3D", v2d:"Flat", mTotal:"All tokens", mNoCache:"No cache reads", mCost:"Est. cost", rData:"Since first use", rYear:"Full year",
|
|
173
|
+
gView:"View", gMetric:"Measure", gRange:"Range",
|
|
174
|
+
usd:"est. USD", none:"none", estCost:"at list prices", perDay:"per day", cacheShare:"cache reads", allTok:"all tokens",
|
|
175
|
+
days:n=>n+(n===1?" day":" days"), activeDays:"active days", since:d=>"since "+d, streak:"longest streak", peak:"busiest day", led:n=>"mostly "+n,
|
|
176
|
+
scale2d:"cell split = each tool's share that day · shade = quintile", cuts:"cuts", scale3d:"bar height = real usage that day · segments = each tool's share",
|
|
177
|
+
rowTip:n=>"Click to add or remove "+n+" in fig. 1", from:d=>"since "+d, main:"top model", total:"Total", noRec:"no usage",
|
|
178
|
+
wd:["","Mon","","Wed","","Fri",""], weekStart:0,
|
|
179
|
+
foot:(cover,gap)=>`
|
|
180
|
+
<div><b>Where the data comes from</b> Local logs of your AI coding tools, read by the open-source tokscale. Nothing leaves your machine. Every run saves each day's totals to a local ledger, so days stay counted after the tools delete their logs.</div>
|
|
181
|
+
<div><b>What is counted</b> All tokens = input + output (incl. reasoning) + cache reads + cache writes. Cache reads are usually over 90%, hence the "no cache reads" view. Cost is estimated at list prices, not what you paid; on a subscription you pay far less.</div>
|
|
182
|
+
<div><b>Coverage</b> ${cover}.${gap?" Claude Code keeps only 30 days of conversation logs by default, so earlier days are gone. Set a large cleanupPeriodDays in ~/.claude/settings.json to keep them.":""}</div>
|
|
183
|
+
<div class="gen">Make your own:<span class="cmd">npx tokenskyline</span></div>`
|
|
184
|
+
};
|
|
185
|
+
document.documentElement.lang=ZH?"zh-CN":"en";
|
|
186
|
+
document.title=L.title;
|
|
187
|
+
const MON=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
|
|
188
|
+
const monLab=m=>ZH?(m+1)+"月":MON[m];
|
|
189
|
+
const mdShort=s=>s?(ZH?(+s.slice(5,7))+"."+(+s.slice(8)):MON[+s.slice(5,7)-1]+" "+(+s.slice(8))):"";
|
|
190
|
+
const mdLong=s=>s?(ZH?(+s.slice(5,7))+"月"+(+s.slice(8))+"日":MON[+s.slice(5,7)-1]+" "+(+s.slice(8))):"—";
|
|
191
|
+
|
|
192
|
+
const NAMES={claude:"Claude",codex:"Codex",agy:"agy",antigravity:"Antigravity",hermes:"Hermes",workbuddy:"WorkBuddy",codebuddy:"CodeBuddy",
|
|
193
|
+
opencode:"OpenCode",cursor:"Cursor",gemini:"Gemini CLI",copilot:"Copilot",amp:"Amp",kimi:"Kimi",qwen:"Qwen",trae:"Trae",cline:"Cline",
|
|
194
|
+
roocode:"Roo Code",kilocode:"Kilo",kilo:"Kilo CLI",goose:"Goose",zed:"Zed",kiro:"Kiro",droid:"Droid",openclaw:"OpenClaw",dsh:"DSH",micode:"MiMo Code",crush:"Crush",warp:"Warp",pi:"Pi"};
|
|
195
|
+
const TOOLS=(D.tools||Object.keys(Object.assign({},...Object.values(D.days))))
|
|
196
|
+
.filter(k=>Object.values(D.days).some(x=>x[k])).map(k=>({k,n:(D.names&&D.names[k])||NAMES[k]||k}));
|
|
197
|
+
const TN = Object.fromEntries(TOOLS.map(t=>[t.k,t.n]));
|
|
198
|
+
const S = {view:/\b(2d|flat)\b/.test(HASH.replace(/[#-]/g," "))?"2d":"3d", metric:"total", range:"data", on:new Set(TOOLS.map(t=>t.k))};
|
|
199
|
+
const METRIC = {
|
|
200
|
+
total: {lab:L.mTotal, f:a=>a[0]+a[1]+a[2]+a[3]},
|
|
201
|
+
nocache:{lab:L.mNoCache, f:a=>a[0]+a[1]+a[3]},
|
|
202
|
+
cost: {lab:L.mCost, f:a=>a[4]}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// ---------- 工具 ----------
|
|
206
|
+
const pad=n=>String(n).padStart(2,"0");
|
|
207
|
+
const ymd=d=>`${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())}`;
|
|
208
|
+
const addDays=(d,n)=>{const x=new Date(d);x.setDate(x.getDate()+n);return x};
|
|
209
|
+
const weekStartOf=d=>addDays(d,-((d.getDay()-L.weekStart+7)%7));
|
|
210
|
+
const usd=n=>"$"+(n>=1000?Math.round(n).toLocaleString("en-US"):n.toFixed(n<10?2:0));
|
|
211
|
+
function fmt(n){return S.metric==="cost"?usd(n):fmtTok(n)}
|
|
212
|
+
function fmtTok(n){
|
|
213
|
+
if(ZH){
|
|
214
|
+
if(n>=1e8) return (n/1e8).toFixed(n>=1e10?0:1)+" 亿";
|
|
215
|
+
if(n>=1e4) return Math.round(n/1e4).toLocaleString("en-US")+" 万";
|
|
216
|
+
return Math.round(n).toLocaleString("en-US");
|
|
217
|
+
}
|
|
218
|
+
if(n>=1e9) return (n/1e9).toFixed(n>=1e11?0:n>=1e10?1:2)+" B";
|
|
219
|
+
if(n>=1e6) return (n/1e6).toFixed(n>=1e8?0:1)+" M";
|
|
220
|
+
if(n>=1e3) return Math.round(n/1e3)+" K";
|
|
221
|
+
return String(Math.round(n));
|
|
222
|
+
}
|
|
223
|
+
const css=v=>getComputedStyle(document.documentElement).getPropertyValue(v).trim();
|
|
224
|
+
function hex2rgb(h){h=h.replace("#","");return [0,2,4].map(i=>parseInt(h.substr(i,2),16))}
|
|
225
|
+
function mix(a,b,t){const A=hex2rgb(a),B=hex2rgb(b);return "rgb("+A.map((x,i)=>Math.round(x*t+B[i]*(1-t))).join(",")+")"}
|
|
226
|
+
function shade(a,k){const A=hex2rgb(a);return "rgb("+A.map(x=>Math.round(x*k)).join(",")+")"}
|
|
227
|
+
let C={};
|
|
228
|
+
const PAL={light:["#C0522B","#1D6E77","#2E5BC8","#B98A10","#617F27","#A33B4E","#4E5C69","#8A5A2B","#2B7A4B","#B5651D"],
|
|
229
|
+
dark: ["#E5744A","#3BB0B6","#6B90F2","#E3B841","#9BBE52","#E0708A","#9AA8B6","#C8925A","#5CC48A","#E8954F"]};
|
|
230
|
+
const FIXED={claude:0,codex:1,agy:2,antigravity:2,gemini:2,hermes:3,workbuddy:4,codebuddy:4};
|
|
231
|
+
const SLOT={};(()=>{const used=new Set();TOOLS.forEach(t=>{if(t.k in FIXED&&!used.has(FIXED[t.k])){SLOT[t.k]=FIXED[t.k];used.add(FIXED[t.k])}});
|
|
232
|
+
let n=0;TOOLS.forEach(t=>{if(t.k in SLOT)return;while(used.has(n%10)&&used.size<10)n++;SLOT[t.k]=n%10;used.add(n%10);n++})})();
|
|
233
|
+
function isDark(){const a=document.documentElement.getAttribute("data-theme");return a?a==="dark":matchMedia("(prefers-color-scheme: dark)").matches}
|
|
234
|
+
function readColors(){C={bg:css("--bg"),empty:css("--empty"),ink:css("--ink"),muted:css("--muted"),rule:css("--rule"),plT:css("--pl-t"),plL:css("--pl-l"),plR:css("--pl-r")};
|
|
235
|
+
const pal=PAL[isDark()?"dark":"light"];TOOLS.forEach(t=>{C[t.k]=pal[SLOT[t.k]];document.documentElement.style.setProperty("--c-"+t.k,C[t.k])})}
|
|
236
|
+
|
|
237
|
+
// ---------- 数据视图 ----------
|
|
238
|
+
const allDates = Object.keys(D.days).sort();
|
|
239
|
+
const YEAR = +(D.year||allDates[allDates.length-1].slice(0,4));
|
|
240
|
+
const firstDate = new Date(allDates[0]+"T00:00:00");
|
|
241
|
+
const today = new Date(); today.setHours(0,0,0,0);
|
|
242
|
+
function valOf(date,tool){const a=D.days[date]&&D.days[date][tool];return a?METRIC[S.metric].f(a):0}
|
|
243
|
+
function dayParts(date,set){return TOOLS.filter(t=>set.has(t.k)).map(t=>[t.k,valOf(date,t.k)]).filter(p=>p[1]>0)}
|
|
244
|
+
function rangeDates(){
|
|
245
|
+
let s,e;
|
|
246
|
+
if(S.range==="year"){s=weekStartOf(new Date(YEAR,0,1));e=addDays(weekStartOf(new Date(YEAR,11,31)),6)}
|
|
247
|
+
else{s=weekStartOf(firstDate);e=addDays(weekStartOf(today<new Date(YEAR,11,31)?today:new Date(YEAR,11,31)),6)}
|
|
248
|
+
const out=[];for(let d=new Date(s);d<=e;d=addDays(d,1))out.push(new Date(d));return out;
|
|
249
|
+
}
|
|
250
|
+
// 分位数分 5 档(缓存读会把线性刻度压扁)
|
|
251
|
+
function levels(vals){
|
|
252
|
+
const v=vals.filter(x=>x>0).sort((a,b)=>a-b);
|
|
253
|
+
if(!v.length) return x=>0;
|
|
254
|
+
const q=p=>v[Math.min(v.length-1,Math.floor(p*v.length))];
|
|
255
|
+
const cut=[q(.2),q(.4),q(.6),q(.8)];
|
|
256
|
+
const fn=x=>x<=0?0:1+cut.filter(c=>x>c).length; // 1..5
|
|
257
|
+
fn.cut=cut; return fn;
|
|
258
|
+
}
|
|
259
|
+
const LV=[0,.28,.46,.64,.82,1];
|
|
260
|
+
|
|
261
|
+
// ---------- 顶部 ----------
|
|
262
|
+
function renderHead(){
|
|
263
|
+
const on=S.on, f=METRIC[S.metric].f;
|
|
264
|
+
let tot=0,cost=0,best=["",0],perTool={};
|
|
265
|
+
TOOLS.forEach(t=>perTool[t.k]=0);
|
|
266
|
+
const actSet=new Set();
|
|
267
|
+
for(const d of allDates){
|
|
268
|
+
let dv=0;
|
|
269
|
+
for(const t of TOOLS){ if(!on.has(t.k))continue; const a=D.days[d][t.k]; if(!a)continue;
|
|
270
|
+
const v=f(a); perTool[t.k]+=v; dv+=v; cost+=a[4]; }
|
|
271
|
+
tot+=dv; if(dv>0){actSet.add(d)} if(dv>best[1])best=[d,dv];
|
|
272
|
+
}
|
|
273
|
+
let longest=0,cur=0,prev=null,lsEnd="",curStart="",lsStart="";
|
|
274
|
+
for(const d of [...actSet].sort()){const dt=new Date(d+"T00:00:00");if(prev&&Math.round((dt-prev)/864e5)===1)cur++;else{cur=1;curStart=d}
|
|
275
|
+
if(cur>longest){longest=cur;lsStart=curStart;lsEnd=d}prev=dt}
|
|
276
|
+
let tokAll=0,tokCache=0;for(const d of allDates)for(const k of on){const a=D.days[d][k];if(a){tokAll+=a[0]+a[1]+a[2]+a[3];tokCache+=a[2]}}
|
|
277
|
+
let bestLead="";if(best[0]){const dd=D.days[best[0]];bestLead=TN[[...on].filter(k=>dd[k]).sort((x,y)=>f(dd[y])-f(dd[x]))[0]]||""}
|
|
278
|
+
const big = S.metric==="cost" ? ["$"+Math.round(tot).toLocaleString("en-US"),L.usd] : (()=>{const s=fmtTok(tot).split(" ");return [s[0],(s[1]?s[1]+" ":"")+"tokens"]})();
|
|
279
|
+
$("bigNum").innerHTML=`${big[0]}<small>${ZH?big[1].replace("tokens","token"):big[1]}</small>`;
|
|
280
|
+
$("bigSub").textContent=`${METRIC[S.metric].lab} · ${[...on].map(k=>TN[k]).join(" + ")||L.none}`;
|
|
281
|
+
const cs=`${L.cacheShare} ${(tokCache/(tokAll||1)*100).toFixed(1)}%`;
|
|
282
|
+
$("kpis").innerHTML=[
|
|
283
|
+
S.metric==="cost"?[fmtTok(tokAll),L.allTok,cs]
|
|
284
|
+
:["$"+Math.round(cost).toLocaleString("en-US"),L.estCost,`${L.perDay} $${Math.round(cost/(actSet.size||1))} · ${cs}`],
|
|
285
|
+
[L.days(actSet.size),L.activeDays,L.since(mdShort(allDates[0]))],
|
|
286
|
+
[L.days(longest),L.streak,`${mdShort(lsStart)} – ${mdShort(lsEnd)}`],
|
|
287
|
+
[mdLong(best[0]),L.peak,`${fmt(best[1])} · ${L.led(bestLead)}`]
|
|
288
|
+
].map(([b,s,t])=>`<div class="kpi"><b>${b}</b><span>${s}</span><span class="sub">${t}</span></div>`).join("");
|
|
289
|
+
const sum=Object.values(perTool).reduce((a,b)=>a+b,0)||1;
|
|
290
|
+
$("share").innerHTML=TOOLS.filter(t=>on.has(t.k)).map(t=>`<i style="width:${perTool[t.k]/sum*100}%;background:var(--c-${t.k})" title="${t.n}"></i>`).join("");
|
|
291
|
+
$("shareLegend").innerHTML=TOOLS.filter(t=>on.has(t.k)&&perTool[t.k]>0).sort((a,b)=>perTool[b.k]-perTool[a.k])
|
|
292
|
+
.map(t=>`<span><i style="background:var(--c-${t.k})"></i>${t.n} <b class="num" style="color:var(--ink);font-weight:500">${(perTool[t.k]/sum*100).toFixed(1)}%</b> <span class="num">${fmt(perTool[t.k])}</span></span>`).join("");
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// ---------- 平面网格(SVG) ----------
|
|
296
|
+
function monthLabels(dates,cb){
|
|
297
|
+
let lastM=-1;
|
|
298
|
+
dates.forEach((d,i)=>{if(i%7)return;for(let j=0;j<7;j++){const dd=dates[i+j];
|
|
299
|
+
if(dd&&(dd.getDate()===1||i===0)&&dd.getFullYear()===YEAR&&dd.getMonth()!==lastM){lastM=dd.getMonth();cb(i/7,dd.getMonth());break}}});
|
|
300
|
+
}
|
|
301
|
+
function gridSVG(svg,dates,set,opt){
|
|
302
|
+
const weeks=Math.ceil(dates.length/7), labW=opt.labels?(ZH?22:30):0, topH=opt.labels?16:0;
|
|
303
|
+
const avail=opt.width-labW;
|
|
304
|
+
const step=Math.max(opt.min,Math.min(opt.max,Math.floor(avail/weeks)));
|
|
305
|
+
const gap=Math.max(2,Math.round(step*.16)), cell=step-gap;
|
|
306
|
+
const W=labW+weeks*step, H=topH+7*step;
|
|
307
|
+
svg.setAttribute("width",W);svg.setAttribute("height",H);svg.setAttribute("viewBox",`0 0 ${W} ${H}`);
|
|
308
|
+
const vals=dates.map(d=>dayParts(ymd(d),set).reduce((s,p)=>s+p[1],0));
|
|
309
|
+
const lv=levels(vals);
|
|
310
|
+
let h="";
|
|
311
|
+
if(opt.labels){
|
|
312
|
+
L.wd.forEach((w,i)=>{if(w)h+=`<text x="0" y="${topH+i*step+cell*.8}">${w}</text>`});
|
|
313
|
+
let lastLX=-99;
|
|
314
|
+
monthLabels(dates,(wk,m)=>{const lx=labW+wk*step;if(lx-lastLX>=26){h+=`<text x="${lx}" y="10">${monLab(m)}</text>`;lastLX=lx}});
|
|
315
|
+
}
|
|
316
|
+
dates.forEach((d,i)=>{
|
|
317
|
+
const x=labW+Math.floor(i/7)*step, y=topH+(i%7)*step, ds=ymd(d);
|
|
318
|
+
const future=d>today;
|
|
319
|
+
const parts=dayParts(ds,set), v=parts.reduce((s,p)=>s+p[1],0), Lv=lv(v);
|
|
320
|
+
if(!v){h+=`<rect x="${x}" y="${y}" width="${cell}" height="${cell}" fill="${future?"none":C.empty}" ${future?`stroke="${C.rule}" stroke-width="1"`:""} data-d="${ds}"/>`;return}
|
|
321
|
+
// 有用量:格子按各家占比自下而上分段着色,整体深浅按分位档
|
|
322
|
+
const t=LV[Lv]; let yy=y+cell;
|
|
323
|
+
h+=`<g data-d="${ds}">`;
|
|
324
|
+
parts.sort((a,b)=>TOOLS.findIndex(t=>t.k===a[0])-TOOLS.findIndex(t=>t.k===b[0]));
|
|
325
|
+
parts.forEach(([k,pv])=>{const hh=cell*pv/v;yy-=hh;h+=`<rect x="${x}" y="${yy.toFixed(2)}" width="${cell}" height="${(hh+.3).toFixed(2)}" fill="${mix(C[k],C.empty,t)}"/>`});
|
|
326
|
+
h+=`</g>`;
|
|
327
|
+
});
|
|
328
|
+
svg.innerHTML=h;
|
|
329
|
+
return {lv,step};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// ---------- 立体(canvas 平行轴测) ----------
|
|
333
|
+
let hexes=[];
|
|
334
|
+
function draw3D(dates){
|
|
335
|
+
const cv=$("cv3"), box=$("mainScroll");
|
|
336
|
+
const weeks=Math.ceil(dates.length/7);
|
|
337
|
+
const az=(weeks>30?21:30)*Math.PI/180, el=36*Math.PI/180; // 周数少时转大一点角度,免得太扁
|
|
338
|
+
const uxW=Math.cos(az), uyW=Math.sin(az)*Math.sin(el), uxD=-Math.sin(az), uyD=Math.cos(az)*Math.sin(el);
|
|
339
|
+
const W=Math.max(640,box.clientWidth), padL=40, padR=72;
|
|
340
|
+
const step=Math.min(34,(W-padL-padR)/(weeks*uxW+7*Math.abs(uxD)));
|
|
341
|
+
const span=step*(weeks*uxW+7*Math.abs(uxD));
|
|
342
|
+
const cR=.8, plD=6, pad=.35;
|
|
343
|
+
const vals=dates.map(d=>dayParts(ymd(d),S.on).reduce((s,p)=>s+p[1],0));
|
|
344
|
+
const maxV=Math.max(...vals,0);
|
|
345
|
+
const maxH=Math.min(200,Math.max(130,step*7));
|
|
346
|
+
const hOf=v=>v>0&&maxV>0?Math.max(3.5,v/maxV*maxH):0; // 柱高 = 真实比例
|
|
347
|
+
const ox=(W-span)/2+7*Math.abs(uxD)*step+ (padL-padR)/2;
|
|
348
|
+
const rawY=(w,d,z)=>w*uyW*step+d*uyD*step-z;
|
|
349
|
+
let minY=Math.min(rawY(-pad,-pad,0),rawY(weeks,-pad,maxH));
|
|
350
|
+
dates.forEach((d,i)=>{const y=rawY(Math.floor(i/7),i%7,hOf(vals[i]));if(y<minY)minY=y});
|
|
351
|
+
const maxY=rawY(weeks-.2+pad,7-.2+pad,0)+plD+24;
|
|
352
|
+
const oy=18-minY, H=Math.ceil(oy+maxY+10);
|
|
353
|
+
const dpr=Math.min(devicePixelRatio||1,3);
|
|
354
|
+
cv.width=W*dpr;cv.height=H*dpr;cv.style.width=W+"px";cv.style.height=H+"px";
|
|
355
|
+
const g=cv.getContext("2d");g.setTransform(dpr,0,0,dpr,0,0);g.clearRect(0,0,W,H);
|
|
356
|
+
const P=(w,d,z)=>[ox+w*uxW*step+d*uxD*step, oy+w*uyW*step+d*uyD*step-z];
|
|
357
|
+
const b00=P(-pad,-pad,0),b10=P(weeks-.2+pad,-pad,0),b11=P(weeks-.2+pad,7-.2+pad,0),b01=P(-pad,7-.2+pad,0);
|
|
358
|
+
const dn=(p)=>[p[0],p[1]+plD];
|
|
359
|
+
poly(g,[b00,b10,b11,b01],C.plT,C.rule);
|
|
360
|
+
poly(g,[b01,b11,dn(b11),dn(b01)],C.plL,C.rule);
|
|
361
|
+
poly(g,[b11,b10,dn(b10),dn(b11)],C.plR,C.rule);
|
|
362
|
+
g.font="500 10.5px "+css("--f-mono");g.fillStyle=C.muted;g.strokeStyle=C.muted;g.lineWidth=1;g.textBaseline="top";g.textAlign="left";
|
|
363
|
+
let lastX=-99;
|
|
364
|
+
monthLabels(dates,(wk,m)=>{const e=P(wk,7.15,0);if(e[0]-lastX>=26){g.beginPath();g.moveTo(e[0],e[1]+plD);g.lineTo(e[0],e[1]+plD+4);g.stroke();g.fillText(monLab(m),e[0]-4,e[1]+plD+6);lastX=e[0]}});
|
|
365
|
+
g.textAlign="right";g.textBaseline="middle";
|
|
366
|
+
L.wd.forEach((w,d)=>{if(w){const q=P(-.55,d+.4,0);g.fillText(w,q[0]-4,q[1])}});
|
|
367
|
+
if(maxV>0){const gx=b10[0]+10,gy=b10[1];g.strokeStyle=C.rule;g.beginPath();g.moveTo(gx,gy);g.lineTo(gx,gy-maxH);g.stroke();
|
|
368
|
+
g.textAlign="left";g.fillStyle=C.muted;g.font="10px "+css("--f-mono");
|
|
369
|
+
[0,.5,1].forEach(f=>{const ty=gy-maxH*f;g.beginPath();g.moveTo(gx-3,ty);g.lineTo(gx+3,ty);g.stroke();g.fillText(f?fmt(maxV*f):"0",gx+6,ty)})}
|
|
370
|
+
hexes=[];
|
|
371
|
+
const order=dates.map((d,i)=>i).sort((x,y)=>(Math.floor(x/7)-Math.floor(y/7))||(x%7-y%7));
|
|
372
|
+
for(const i of order){
|
|
373
|
+
const d=dates[i],w=Math.floor(i/7),r=i%7,ds=ymd(d),Ht=hOf(vals[i]);
|
|
374
|
+
const p00=P(w,r,0),p10=P(w+cR,r,0),p11=P(w+cR,r+cR,0),p01=P(w,r+cR,0);
|
|
375
|
+
if(!Ht){ if(d>today)poly(g,[p00,p10,p11,p01],null,C.rule); else poly(g,[p00,p10,p11,p01],C.empty,null); hexes.push({ds,pts:[p00,p10,p11,p01]}); continue }
|
|
376
|
+
const parts=dayParts(ds,S.on).sort((x,y)=>TOOLS.findIndex(t=>t.k===x[0])-TOOLS.findIndex(t=>t.k===y[0]));
|
|
377
|
+
let z=0;const up=(p,zz)=>[p[0],p[1]-zz];
|
|
378
|
+
for(const [tk,pv] of parts){const z1=z+Ht*pv/vals[i],col=C[tk];
|
|
379
|
+
poly(g,[up(p01,z1),up(p11,z1),up(p11,z),up(p01,z)],shade(col,.8));
|
|
380
|
+
poly(g,[up(p11,z1),up(p10,z1),up(p10,z),up(p11,z)],shade(col,.62));
|
|
381
|
+
z=z1}
|
|
382
|
+
poly(g,[up(p00,Ht),up(p10,Ht),up(p11,Ht),up(p01,Ht)],C[parts[parts.length-1][0]]);
|
|
383
|
+
hexes.push({ds,pts:[up(p00,Ht),up(p10,Ht),p10,p11,p01,up(p01,Ht)]});
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
function poly(g,pts,fill,stroke){g.beginPath();g.moveTo(pts[0][0],pts[0][1]);for(let i=1;i<pts.length;i++)g.lineTo(pts[i][0],pts[i][1]);g.closePath();
|
|
387
|
+
if(fill){g.fillStyle=fill;g.fill()} if(stroke){g.strokeStyle=stroke;g.lineWidth=.8;g.stroke()}}
|
|
388
|
+
function inPoly(x,y,p){let c=false;for(let i=0,j=p.length-1;i<p.length;j=i++){if(((p[i][1]>y)!==(p[j][1]>y))&&(x<(p[j][0]-p[i][0])*(y-p[i][1])/(p[j][1]-p[i][1])+p[i][0]))c=!c}return c}
|
|
389
|
+
|
|
390
|
+
// ---------- 分家小图 ----------
|
|
391
|
+
function renderRows(dates){
|
|
392
|
+
const rows=$("rows"); rows.innerHTML="";
|
|
393
|
+
const w=Math.max(rows.clientWidth-(rows.clientWidth>720?220:0),300);
|
|
394
|
+
for(const t of TOOLS){
|
|
395
|
+
let tk=0,cost=0,act=0,models={};
|
|
396
|
+
for(const d of allDates){const a=D.days[d][t.k];if(!a)continue;tk+=a[0]+a[1]+a[2]+a[3];cost+=a[4];act++;models[a[6]]=(models[a[6]]||0)+a[0]+a[1]+a[2]+a[3]}
|
|
397
|
+
if(!act)continue;
|
|
398
|
+
const top=Object.keys(models).sort((x,y)=>models[y]-models[x])[0]||"";
|
|
399
|
+
const first=allDates.find(d=>D.days[d][t.k]);
|
|
400
|
+
const row=document.createElement("div");row.className="row"+(S.on.has(t.k)?"":" off");row.dataset.k=t.k;
|
|
401
|
+
row.title=L.rowTip(t.n);
|
|
402
|
+
row.innerHTML=`<div class="meta"><h3><i style="background:var(--c-${t.k})"></i>${t.n}</h3>
|
|
403
|
+
<div class="t">${fmtTok(tk)} <span class="s">${ZH?"token":"tokens"}</span></div>
|
|
404
|
+
<div class="s num">$${Math.round(cost).toLocaleString("en-US")} · ${L.days(act)}</div>
|
|
405
|
+
<div class="s">${L.from(mdShort(first))} · ${L.main} ${top}</div></div>
|
|
406
|
+
<div class="scroll"><svg></svg></div>`;
|
|
407
|
+
rows.appendChild(row);
|
|
408
|
+
gridSVG(row.querySelector("svg"),dates,new Set([t.k]),{width:w,min:9,max:16,labels:false});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// ---------- 渲染 ----------
|
|
413
|
+
function render(){
|
|
414
|
+
readColors();
|
|
415
|
+
const dates=rangeDates();
|
|
416
|
+
renderHead();
|
|
417
|
+
const box=$("mainScroll");
|
|
418
|
+
if(S.view==="2d"){
|
|
419
|
+
$("w2d").hidden=false;$("cv3").hidden=true;
|
|
420
|
+
const r=gridSVG($("grid2d"),dates,S.on,{width:box.clientWidth,min:11,max:S.range==="year"?20:46,labels:true});
|
|
421
|
+
const cut=r.lv.cut||[];
|
|
422
|
+
$("scale").innerHTML=`${L.scale2d} ${[1,2,3,4,5].map(l=>`<i style="background:${mix(C.ink,C.empty,LV[l]*.85)}"></i>`).join("")} <span class="num">${L.cuts} ${cut.map(fmt).join(" / ")}</span>`;
|
|
423
|
+
}else{
|
|
424
|
+
$("w2d").hidden=true;$("cv3").hidden=false;draw3D(dates);
|
|
425
|
+
$("scale").textContent=L.scale3d;
|
|
426
|
+
}
|
|
427
|
+
renderRows(dates);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// ---------- 悬停 ----------
|
|
431
|
+
const tip=$("tip");
|
|
432
|
+
function showTip(ds,e){
|
|
433
|
+
const day=D.days[ds]||{}; const f=METRIC[S.metric].f;
|
|
434
|
+
const rows=TOOLS.filter(t=>S.on.has(t.k)&&day[t.k]).map(t=>[t,day[t.k]]).sort((x,y)=>f(y[1])-f(x[1]));
|
|
435
|
+
const tot=rows.reduce((s,r)=>s+f(r[1]),0);
|
|
436
|
+
const dt=new Date(ds+"T00:00:00");
|
|
437
|
+
const wdName=ZH?"周"+"日一二三四五六"[dt.getDay()]:dt.toLocaleDateString("en-US",{weekday:"short"});
|
|
438
|
+
tip.innerHTML=`<div class="d">${ds} ${wdName}</div>`+
|
|
439
|
+
(rows.length?rows.map(([t,a])=>`<div class="r"><span><i style="background:var(--c-${t.k})"></i>${t.n}</span><span>${fmt(f(a))}</span></div>`).join("")+
|
|
440
|
+
`<div class="r" style="border-top:1px solid currentColor;margin-top:4px;padding-top:4px"><span>${L.total}</span><span>${fmt(tot)}</span></div>`+
|
|
441
|
+
`<div class="m">${L.main} ${rows.map(([t,a])=>a[6]).filter(Boolean).slice(0,2).join(" / ")}</div>`:`<div class="m">${L.noRec}</div>`);
|
|
442
|
+
tip.style.display="block";
|
|
443
|
+
const x=Math.min(e.clientX+14,innerWidth-tip.offsetWidth-8), y=e.clientY+16+tip.offsetHeight>innerHeight?e.clientY-tip.offsetHeight-10:e.clientY+16;
|
|
444
|
+
tip.style.left=x+"px";tip.style.top=y+"px";
|
|
445
|
+
}
|
|
446
|
+
document.addEventListener("pointermove",e=>{
|
|
447
|
+
let ds=null;
|
|
448
|
+
const el=e.target.closest&&e.target.closest("[data-d]");
|
|
449
|
+
if(el&&el.closest("svg"))ds=el.getAttribute("data-d");
|
|
450
|
+
else if(e.target.id==="cv3"){const r=e.target.getBoundingClientRect(),x=e.clientX-r.left,y=e.clientY-r.top;
|
|
451
|
+
for(let i=hexes.length-1;i>=0;i--){if(inPoly(x,y,hexes[i].pts)){ds=hexes[i].ds;break}}}
|
|
452
|
+
if(ds)showTip(ds,e);else tip.style.display="none";
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
// ---------- 文案 + 控件 ----------
|
|
456
|
+
["h1","fig1","h2","h2note","v3d","v2d","mTotal","mNoCache","mCost","rData","rYear"].forEach(id=>$(id).textContent=L[id]);
|
|
457
|
+
["gView","gMetric","gRange"].forEach(id=>$(id).setAttribute("aria-label",L[id]));
|
|
458
|
+
$("rows").setAttribute("aria-label",L.h2);
|
|
459
|
+
function seg(ids,key,vals){ids.forEach((id,i)=>$(id).addEventListener("click",()=>{S[key]=vals[i];ids.forEach((j,k)=>$(j).setAttribute("aria-pressed",k===i));render()}))}
|
|
460
|
+
seg(["v3d","v2d"],"view",["3d","2d"]);
|
|
461
|
+
seg(["mTotal","mNoCache","mCost"],"metric",["total","nocache","cost"]);
|
|
462
|
+
seg(["rData","rYear"],"range",["data","year"]);
|
|
463
|
+
$("v3d").setAttribute("aria-pressed",S.view==="3d");$("v2d").setAttribute("aria-pressed",S.view==="2d");
|
|
464
|
+
$("tools").innerHTML=TOOLS.map(t=>`<button class="tool" data-k="${t.k}" aria-pressed="true"><i style="background:var(--c-${t.k})"></i>${t.n}</button>`).join("");
|
|
465
|
+
function toggle(k){if(S.on.has(k)){if(S.on.size===1)return;S.on.delete(k)}else S.on.add(k);
|
|
466
|
+
document.querySelectorAll(".tool").forEach(x=>x.setAttribute("aria-pressed",S.on.has(x.dataset.k)));render()}
|
|
467
|
+
$("tools").addEventListener("click",e=>{const b=e.target.closest(".tool");if(b)toggle(b.dataset.k)});
|
|
468
|
+
$("rows").addEventListener("click",e=>{const r=e.target.closest(".row");if(r)toggle(r.dataset.k)});
|
|
469
|
+
// 双击某家 = 只看它
|
|
470
|
+
$("tools").addEventListener("dblclick",e=>{const b=e.target.closest(".tool");if(!b)return;S.on=new Set([b.dataset.k]);
|
|
471
|
+
document.querySelectorAll(".tool").forEach(x=>x.setAttribute("aria-pressed",S.on.has(x.dataset.k)));render()});
|
|
472
|
+
|
|
473
|
+
const g=new Date(D.generatedAt);
|
|
474
|
+
$("brand").textContent=L.brand;
|
|
475
|
+
$("upd").textContent=L.upd+" "+ymd(g)+" "+pad(g.getHours())+":"+pad(g.getMinutes());
|
|
476
|
+
$("yr").textContent=YEAR;
|
|
477
|
+
if(D.demo){const b=document.createElement("span");b.className="demo";b.textContent=L.demo;$("upd").after(b)}
|
|
478
|
+
const cover=TOOLS.map(t=>`${t.n} ${L.from(mdShort(allDates.find(d=>D.days[d][t.k])))}`).join(ZH?",":", ");
|
|
479
|
+
const clFirst=allDates.find(d=>D.days[d].claude);
|
|
480
|
+
const clGap=!!clFirst&&(g-new Date(clFirst+"T00:00:00"))/864e5<45&&clFirst.slice(5)!=="01-01";
|
|
481
|
+
$("foot").innerHTML=L.foot(cover,clGap);
|
|
482
|
+
|
|
483
|
+
let rt;addEventListener("resize",()=>{clearTimeout(rt);rt=setTimeout(render,120)});
|
|
484
|
+
matchMedia("(prefers-color-scheme: dark)").addEventListener("change",render);
|
|
485
|
+
new MutationObserver(render).observe(document.documentElement,{attributes:true,attributeFilter:["data-theme"]});
|
|
486
|
+
render();
|
|
487
|
+
})();
|
|
488
|
+
</script>
|