ai-nianlun 0.1.0 → 0.1.4
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/README.en.md +118 -21
- package/README.md +120 -21
- package/docs//345/233/276//351/243/216/346/240/274//345/210/206/344/272/253/345/233/276-/344/270/244/351/243/216/346/240/274-/344/270/255/350/213/261.png +0 -0
- package/docs//345/233/276//351/243/216/346/240/274//346/210/220/347/273/251/345/215/225-/344/270/255/350/213/261-/346/267/261/350/211/262.png +0 -0
- package/docs//345/233/276//351/243/216/346/240/274//347/273/210/347/253/257/345/205/250/351/203/250/351/241/265-/344/270/255.png +0 -0
- package/docs//345/233/276//351/243/216/346/240/274//347/275/221/351/241/265-/347/256/200/347/272/246.png +0 -0
- package/docs//345/233/276//351/243/216/346/240/274//347/275/221/351/241/265-/350/257/246/347/273/206-/344/270/255.png +0 -0
- package/docs//345/233/276//351/243/216/346/240/274//347/275/221/351/241/265-/350/257/246/347/273/206-/346/211/213/346/234/272.png +0 -0
- package/docs//345/233/276//351/243/216/346/240/274//347/275/221/351/241/265-/350/257/246/347/273/206-/350/213/261.png +0 -0
- package/package.json +16 -12
- package/src/cli/duizhang.js +109 -0
- package/src/cli/keys.js +5 -5
- package/src/cli/main.js +182 -34
- package/src/cli/render.js +37 -10
- package/src/cli/styles.js +34 -76
- package/src/cli/viewer.js +46 -41
- package/src/core/album.js +21 -10
- package/src/core/brands.js +2 -2
- package/src/core/cards.js +148 -10
- package/src/core/color.js +8 -0
- package/src/core/fmt.js +21 -1
- package/src/core/i18n.js +331 -42
- package/src/core/model.js +42 -0
- package/src/core/panel.js +34 -10
- package/src/core/report.js +7 -4
- package/src/core/shard.js +25 -8
- package/src/core/share.js +3 -4
- package/src/core/stats.js +73 -2
- package/src/core/text.js +6 -0
- package/src/node/bundle.js +199 -0
- package/src/node/demo.js +43 -11
- package/src/node/duizhang.js +246 -0
- package/src/node/engine.js +9 -2
- package/src/node/prices.js +2 -1
- package/src/node/scan.js +1 -1
- package/src/node/server.js +22 -5
- package/src/sources/codex.js +238 -32
- package/src/sources/opencode.js +80 -5
- package/web/album.css +66 -0
- package/web/album.js +37 -18
- package/web/app.js +65 -11
- package/web/style.css +76 -2
- package/start.command +0 -8
- package/start.sh +0 -8
- package//345/220/257/345/212/250.bat +0 -11
package/README.en.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
[中文](README.md) · English
|
|
4
4
|
|
|
5
|
-
Your year with AI coding tools, wrapped up in your terminal. It reads the logs that Claude Code, Codex, Cursor and friends already keep on your machine. Zero dependencies, no network, Node.js 18+.
|
|
5
|
+
Your year with AI coding tools, wrapped up in your terminal; press Enter for the full story in your browser. It reads the logs that Claude Code, Codex, Cursor and friends already keep on your machine. Zero dependencies, no network, Node.js 18+.
|
|
6
6
|
|
|
7
7
|
<!-- clone:start -->
|
|
8
8
|
```bash
|
|
9
|
-
git clone
|
|
9
|
+
git clone <repo-url>
|
|
10
10
|
cd ai-nianlun
|
|
11
11
|
npm install -g .
|
|
12
12
|
nianlun
|
|
@@ -15,47 +15,119 @@ nianlun
|
|
|
15
15
|
|
|
16
16
|
Once it's on npm: `npx ai-nianlun`
|
|
17
17
|
|
|
18
|
-

|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
nianlun # Your year
|
|
22
|
-
nianlun
|
|
23
|
-
nianlun share # Save a share card (PNG + SVG) and copy
|
|
24
|
-
nianlun
|
|
21
|
+
nianlun # Your year on one screen; press Enter for the full story in your browser (the web version)
|
|
22
|
+
nianlun web # Open the web version directly: Detailed folio by default; toggles top right for Minimal | Detailed and 中 | EN
|
|
23
|
+
nianlun share # Save a share card (PNG + SVG) and copy the image itself, ready to paste
|
|
24
|
+
nianlun story # Page through the full story in the terminal: lineup, models, API prices, busiest day, streaks… W opens the web version
|
|
25
25
|
nianlun --demo # No logs yet? See it with demo data
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
## Getting to the web version
|
|
29
|
+
|
|
30
|
+
The web version opens on your own computer; nothing is uploaded. Three ways in, all the same:
|
|
31
|
+
|
|
32
|
+
- Run `nianlun`, look at the scorecard, **press Enter**.
|
|
33
|
+
- Run `nianlun web`.
|
|
34
|
+
- Inside `nianlun story`, on any page, **press W**.
|
|
35
|
+
|
|
36
|
+
Your browser opens an `http://127.0.0.1:…` address that only this computer can reach. Press Ctrl+C in the terminal when you're done.
|
|
37
|
+
|
|
28
38
|
## On the web
|
|
29
39
|
|
|
30
|
-
`nianlun web` opens
|
|
40
|
+
`nianlun web` opens the page first and shows the reading progress there. The bar moves by data read, not by tool count ("3.2 GB of 12.5 GB read"), so it keeps moving even through one huge log. When it's done, the folio appears.
|
|
41
|
+
|
|
42
|
+
It is a quiet, paper-toned folio: one big number or name per page, a single line beneath it, and a figure grown from your own data — a woven strip of the whole year, a calendar of dots, a knitted heatmap, the soft curve of your hours, a timeline of your streak. On a computer, click the right side to turn the page and the left side to go back (click three times, turn three pages), or use the arrow keys. On a phone, tap anywhere for the next page and use the little arrow at the bottom left to go back; tall pages scroll up and down as usual. There is no sideways swipe, because it fights the browser's own swipe-to-go-back. The last page is a portrait share card: the main button, "Copy image", puts the picture on your clipboard (if the browser won't allow that, it saves to Downloads instead), next to "Save image" and a small "Copy as text". That is the Detailed look; click "Minimal" top right for a one-page scorecard, or "中 | EN" to switch language. The current choice is the dark one.
|
|
31
43
|
|
|
32
44
|

|
|
33
45
|
|
|
34
|
-
##
|
|
46
|
+
## In the terminal
|
|
35
47
|
|
|
36
|
-
|
|
48
|
+
`nianlun` shows one screen: the hero is how many messages you sent this year, next to your persona and a one-line quip, with a full-year heatmap and eight numbers below (sessions, active days, latest sign-off, ...). The bottom line says "Press Enter to see the full story in your browser". Enter opens the web version and leaves the scorecard and the address in your terminal; Q quits. It fits an 80×24 window. When the output goes to a pipe or a file, it never waits for a key: it prints once and ends with the `nianlun web` command.
|
|
37
49
|
|
|
38
|
-
|
|
39
|
-
- **Detailed** (`detailed`): in the terminal, the same scorecard plus top projects, top commands, peak hours, your AI lineup and the file you hammered the most; on the web and the share card, the paper-toned folio.
|
|
50
|
+

|
|
40
51
|
|
|
41
|
-
|
|
52
|
+
For the full story in the terminal, use `nianlun story`: after the scorecard, one page per Enter: the big picture, your AI lineup, top models, API prices, busiest day, streaks, peak hours, top projects, top commands, most-hammered file, you vs. AI, persona; Enter on the last page makes the share card. The footer on every page says "W full story in browser". Every page fits in 80×24.
|
|
42
53
|
|
|
43
|
-
|
|
54
|
+
## Two looks: Minimal / Detailed
|
|
55
|
+
|
|
56
|
+
The web page and the share card come in two looks. Switch on the web with the toggle top right; pick the share card's look with `nianlun share --style minimal|detailed`. The web opens in Detailed, the share card defaults to Minimal.
|
|
57
|
+
|
|
58
|
+
- **Minimal** (`minimal`): a one-page scorecard with the same numbers as the terminal.
|
|
59
|
+
- **Detailed** (`detailed`): the paper-toned folio, one big number or name per page.
|
|
44
60
|
|
|
45
61
|
## Sharing
|
|
46
62
|
|
|
47
|
-
`nianlun share` writes a 1080×1350 share card
|
|
63
|
+
`nianlun share` writes a 1080×1350 share card. If Edge or Chrome is installed, it turns the card into a PNG (headless, closed right after) and puts the image itself on your clipboard, ready to paste into a chat. It only uses what the system already has: PowerShell on Windows, osascript on macOS, wl-copy or xclip on Linux if present. If that fails (or there's only an SVG), it says so, prints where the image is, and copies a short post that fits in a tweet instead. Nothing is uploaded.
|
|
48
64
|
|
|
49
65
|
```text
|
|
50
66
|
My 2026 in AI
|
|
51
67
|
2,094 messages · 599 sessions · 286 active days
|
|
52
68
|
Mostly Claude Code (67%) · Opus 5.5
|
|
53
|
-
357M tokens · $418 at API prices
|
|
54
|
-
Latest sign-off
|
|
69
|
+
357M tokens with context & cache · $418 at API prices
|
|
70
|
+
Latest sign-off 5:42 AM (Apr 7) · 27-day streak
|
|
55
71
|
Persona: One-File Wonder (edited one file into legend)
|
|
56
72
|
Get yours: npx ai-nianlun
|
|
57
73
|
```
|
|
58
74
|
|
|
75
|
+
## Combining several computers
|
|
76
|
+
|
|
77
|
+
AI Rings only reads the computer it runs on. To add another one (a Raspberry Pi, a work laptop), three steps:
|
|
78
|
+
|
|
79
|
+
1. On the other computer run `nianlun export`. You get `nianlun-<machine>-2026.json` in the current folder (`--out <folder or file>` to put it elsewhere; `--year` and `--tz` work as usual).
|
|
80
|
+
2. Copy that file to your main computer.
|
|
81
|
+
3. There, run `nianlun --merge nianlun-<machine>-2026.json`. `web`, `share` and `story` take `--merge` too, with as many files as you like.
|
|
82
|
+
|
|
83
|
+
The header and overview then say "2 computers", and every page adds both up. A session found on both is counted once, a day you worked on both counts as one day, several exports from the same computer use only the newest, and a file exported from this very computer isn't added again. Different time zones get a warning (export with `--tz` to line them up); an export format it doesn't know is reported, not guessed at.
|
|
84
|
+
|
|
85
|
+
The export holds numbers only: no chat text, catchphrases or code, and session ids are hashed. Projects are just folder names, only the 40 most-edited file names are kept (for the "most-edited file" page), plus the machine name, model names, tool names and command names (`git status` level). Have a look before sending it to anyone.
|
|
86
|
+
|
|
87
|
+
## Personas
|
|
88
|
+
|
|
89
|
+
Every persona has a bar. Of the ones you clear, the one you clear by the most wins: scores are usually "yours ÷ the bar"; for the personas added in 0.1.3, open-ended counts (money, models, subagents, days away) are square-rooted first so one huge number doesn't drown out the rest. Clear none and you're **Just Visiting** (under 30 active days) or **Steady Shipper**.
|
|
90
|
+
|
|
91
|
+
| Persona | Bar |
|
|
92
|
+
|---|---|
|
|
93
|
+
| 3 AM Architect | 30%+ of messages 10 PM–5 AM, peak after 9 PM |
|
|
94
|
+
| Dawn Patrol | 20%+ of messages 5–9 AM, peak before noon |
|
|
95
|
+
| 9-to-5 Ninja | 65%+ of messages on weekdays, 9 to 6 |
|
|
96
|
+
| Weekend Warlord | 40%+ of messages on weekends |
|
|
97
|
+
| Human Daemon | A single session of 4+ hours |
|
|
98
|
+
| Army of One | 30+ messages, 10+ actions per message |
|
|
99
|
+
| Iron Streak | 95%+ attendance, a month or more into the year |
|
|
100
|
+
| The Regular | Not perfect, but 200 days, a 60-day streak, or 60%+ attendance |
|
|
101
|
+
| Human Multithread | 15+ projects |
|
|
102
|
+
| Model Polyglot | 3+ AIs, none above half |
|
|
103
|
+
| Ctrl+Z Samurai | "That's wrong" 30+ times, 1 in 20 messages |
|
|
104
|
+
| Please & Thank You | "Thanks" 30+ times, 1 in 20 messages |
|
|
105
|
+
| Prompt Poet | 50+ messages, 80+ tokens each |
|
|
106
|
+
| Two-Word Tyrant | 200+ tokens back for every token you type |
|
|
107
|
+
| git push Ronin | 150+ git runs, 40%+ of commands |
|
|
108
|
+
| One-File Wonder | One file edited 150+ times |
|
|
109
|
+
| One-Day Blitz | 120+ messages on your busiest day, 6× a normal day |
|
|
110
|
+
| Token Whale | ¥20,000+ (about $3,000) at list API prices |
|
|
111
|
+
| Model Hopper | 8+ models with 30+ replies each |
|
|
112
|
+
| Ride-or-Die | Tried other models, 50+ sessions, still 95%+ from one |
|
|
113
|
+
| Subagent Boss | 300+ subagents, 2+ per session |
|
|
114
|
+
| The "Continue" Masher | 60+ messages that are just "continue", 10%+ of all |
|
|
115
|
+
| Fine, I'll Do It | "Never mind" 15+ times, 1 in 100 messages |
|
|
116
|
+
| Chief Why Officer | 60+ "why"s, 16%+ of messages |
|
|
117
|
+
| Chief Delegator | 100+ messages, 35%+ say "help me" |
|
|
118
|
+
| Net-Negative Legend | Deleted more lines than added (2,000+ deleted, 1,000+ added) |
|
|
119
|
+
| rm -rf Daredevil | 50+ rm / git reset / git clean, 4%+ of commands |
|
|
120
|
+
| Look, Don't Touch | 200+ actions, 60%+ reads and searches, under 5% edits |
|
|
121
|
+
| Prod Firefighter | 50+ ssh / docker / kubectl, 15%+ of commands |
|
|
122
|
+
| Zero-Tab Researcher | 150+ web searches, 20%+ of actions |
|
|
123
|
+
| Monorepo Monk | 30+ active days, 80%+ in one project |
|
|
124
|
+
| Fresh-Chat Addict | 200+ sessions, 3 messages or fewer each |
|
|
125
|
+
| Overnight Boss | 5+ times your last message was 11 PM–3 AM and it kept working 30+ min |
|
|
126
|
+
| The Comeback Kid | A 30+ day break, then 3+ of the next 7 days |
|
|
127
|
+
| Hockey-Stick Dev | One month at 4× your earlier monthly average, 200+ messages |
|
|
128
|
+
| Just Visiting | None of the above, under 30 active days |
|
|
129
|
+
| Steady Shipper | None of the above |
|
|
130
|
+
|
|
59
131
|
## Language
|
|
60
132
|
|
|
61
133
|
Chinese and English. It follows your system: `--lang` first, then `LC_ALL`, `LC_MESSAGES`, `LANG`, then the OS locale. Anything starting with `zh` gets Chinese, everything else gets English. English numbers use K / M / B, and costs are shown in US dollars.
|
|
@@ -71,7 +143,8 @@ Chinese and English. It follows your system: `--lang` first, then `LC_ALL`, `LC_
|
|
|
71
143
|
| DeepSeek desktop | found automatically | real logs |
|
|
72
144
|
| WorkBuddy | found automatically | real logs |
|
|
73
145
|
| Kimi Code | found automatically | real logs |
|
|
74
|
-
| OpenCode | found automatically | real logs |
|
|
146
|
+
| OpenCode 1.x | found automatically | real logs |
|
|
147
|
+
| OpenCode 2.x | found automatically | **fixtures built from the official source schema only; not checked against real 2.x data** |
|
|
75
148
|
| Kiro | found automatically | real logs |
|
|
76
149
|
| GitHub Copilot CLI | found automatically | a single real session |
|
|
77
150
|
| Cursor | found automatically | **made-up samples only** |
|
|
@@ -83,12 +156,13 @@ Chinese and English. It follows your system: `--lang` first, then `LC_ALL`, `LC_
|
|
|
83
156
|
|
|
84
157
|
- Only reads each tool's own log files. Never changes them, never reads credentials, never goes online. The web version listens on 127.0.0.1 only.
|
|
85
158
|
- Share cards and the post leave out project names, file names and anything you typed, unless you add `--full`. The page from `--html` does include them, so check it before sending.
|
|
159
|
+
- Files from `nianlun export` hold numbers only; see "Combining several computers".
|
|
86
160
|
- Stats (not chat text) are cached locally: Windows `%LOCALAPPDATA%\ai-nianlun`, macOS `~/Library/Caches/ai-nianlun`, elsewhere `~/.cache/ai-nianlun`. Safe to delete.
|
|
87
161
|
|
|
88
162
|
## Options
|
|
89
163
|
|
|
90
164
|
```text
|
|
91
|
-
--style minimal Look: minimal · detailed
|
|
165
|
+
--style minimal Look of the share card and web page: minimal · detailed
|
|
92
166
|
--lang zh|en Language (defaults to your system language)
|
|
93
167
|
--year 2026 Which year (in Jan/Feb it defaults to last year)
|
|
94
168
|
--book claude Just one tool (all = everything)
|
|
@@ -101,14 +175,37 @@ Chinese and English. It follows your system: `--lang` first, then `LC_ALL`, `LC_
|
|
|
101
175
|
--no-png Skip the PNG, SVG only
|
|
102
176
|
--html [file] Export a single-file web page
|
|
103
177
|
--json Dump all stats
|
|
104
|
-
--plain No color, no
|
|
178
|
+
--plain No color, no waiting, print once
|
|
105
179
|
--list Supported tools and what was found
|
|
106
180
|
--no-cache Re-read everything
|
|
107
181
|
--port 4731 Web port
|
|
108
182
|
--no-open Don't open a browser
|
|
183
|
+
check [--db file] Compare with CC Switch on this computer (see "Numbers don't match")
|
|
109
184
|
```
|
|
110
185
|
|
|
111
|
-
API value is estimated with the price table and method from [CC Switch](https://github.com/farion1231/cc-switch). If you're on a subscription, that's not what you actually paid.
|
|
186
|
+
API value is estimated at **official list prices** with the price table and method from [CC Switch](https://github.com/farion1231/cc-switch). If you're on a subscription, that's not what you actually paid. Usage through a third-party relay (a custom base URL) counts as long as the logs have token numbers, also priced by model name at official rates; the relay may charge differently. Models with no known price are never dropped silently: the cost page lists them as "Unpriced" with their token count and names. One model with different reasoning-effort, context-length or orchestrator suffixes counts as one (rules in [docs/读取器约定.md](docs/读取器约定.md)).
|
|
187
|
+
|
|
188
|
+
Only logs on **the computer you run it on** are counted: for AI tools you use on a Raspberry Pi or a server, run `npx ai-nianlun` on that machine.
|
|
189
|
+
|
|
190
|
+
## Numbers don't match CC Switch or Codex?
|
|
191
|
+
|
|
192
|
+
Check these three first; they explain most gaps:
|
|
193
|
+
|
|
194
|
+
1. **The big number includes cache reads.** Total tokens = fresh input + output + cache read + cache write, and cache reads (context re-read from the cache) are usually over 90% of it. Tools that show only "input + output" will be an order of magnitude smaller.
|
|
195
|
+
2. **AI Rings counts the whole year, from logs still on disk.** Claude Code keeps 30 days of logs by default; what's deleted can't be read. CC Switch keeps its own copy of what it read earlier, so its history is often longer.
|
|
196
|
+
3. **AI Rings recomputes cost at today's prices every time.** CC Switch stores each record's cost at the price of the moment and never recomputes it.
|
|
197
|
+
|
|
198
|
+
If you have CC Switch installed, run:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
nianlun check
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
It lists both sides per tool and model (requests, the four token kinds, USD), marks the rows that are far apart, compares separately just the days both sides have complete per-request records (CC Switch keeps those for about 30 days) to show how much the reading itself differs, and explains each kind of gap in plain words. The output has only model names and numbers, so you can paste it to someone. It reads only the two usage tables in the CC Switch database, from a copy; it never touches the original or any other table.
|
|
205
|
+
|
|
206
|
+
The rules for reading Claude Code, Codex and OpenCode logs are aligned with CC Switch (from its open-source code, commit 39f1059d). On the author's computer, over the 29 days both have complete records, Claude and Codex agree per model within 1% on all four token kinds (Codex exactly); Codex agrees per model for the whole year except 8 auto-review requests (old Codex copied the previous review's usage into the new file; CC Switch counts it again, AI Rings doesn't).
|
|
207
|
+
|
|
208
|
+
**Fixed in 0.1.4:** up to 0.1.3, resumed or forked Codex sessions that start with earlier cumulative usage or copied parent records were counted again, which could inflate Codex numbers several times over. It now counts each request's own usage like CC Switch and drops the copied part. If you ran an older version, upgrade and run it again.
|
|
112
209
|
|
|
113
210
|
## Adding a tool
|
|
114
211
|
|
package/README.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
中文 · [English](README.en.md)
|
|
4
4
|
|
|
5
|
-
读你电脑上各家 AI
|
|
5
|
+
读你电脑上各家 AI 编程工具的使用记录,在终端里打一张年度成绩单,按一下 Enter 就在浏览器里看完整版。零依赖,不联网,需要 Node.js 18 以上。
|
|
6
6
|
|
|
7
7
|
<!-- clone:start -->
|
|
8
8
|
```bash
|
|
9
|
-
git clone
|
|
9
|
+
git clone <仓库地址>
|
|
10
10
|
cd ai-nianlun
|
|
11
11
|
npm install -g .
|
|
12
12
|
nianlun
|
|
@@ -15,19 +15,31 @@ nianlun
|
|
|
15
15
|
|
|
16
16
|
发布到 npm 之后:`npx ai-nianlun`
|
|
17
17
|
|
|
18
|
-

|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
nianlun #
|
|
22
|
-
nianlun
|
|
23
|
-
nianlun share # 写出分享图(PNG + SVG
|
|
24
|
-
nianlun
|
|
21
|
+
nianlun # 一屏成绩单,按 Enter 在浏览器里看完整版(网页版)
|
|
22
|
+
nianlun web # 直接打开网页版:默认「详细」画册,右上角切「简约 | 详细」和「中 | EN」
|
|
23
|
+
nianlun share # 写出分享图(PNG + SVG),图片复制到剪贴板,去微信里直接粘贴
|
|
24
|
+
nianlun story # 在终端里一页页翻完整版:排行、模型、折合费用、最忙的一天、纪录……W 随时去网页版
|
|
25
25
|
nianlun --demo # 没有记录也能先看看(演示数据)
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
## 怎么去网页版
|
|
29
|
+
|
|
30
|
+
网页版在你自己电脑上打开,数据不上传。三种去法,效果一样:
|
|
31
|
+
|
|
32
|
+
- 运行 `nianlun`,看完那一屏成绩单,**按 Enter**。
|
|
33
|
+
- 直接运行 `nianlun web`。
|
|
34
|
+
- 在 `nianlun story` 里翻到哪一页都行,**按 W**。
|
|
35
|
+
|
|
36
|
+
浏览器会打开一个 `http://127.0.0.1:…` 的地址,只有这台电脑自己能访问。看完回到终端按 Ctrl+C 结束。
|
|
37
|
+
|
|
28
38
|
## 网页版
|
|
29
39
|
|
|
30
|
-
`nianlun web`
|
|
40
|
+
`nianlun web` 先打开网页,读取进度在网页里看:进度条按「已读多少 ÷ 一共多少」的数据量走(写着「已读 3.2 GB / 共 12.5 GB」),大文件读得慢时也在匀速往前,不会卡在某个数上。读完自动出画册。
|
|
41
|
+
|
|
42
|
+
画册是浅纸色的:一页一个大数字或一个名字,配一句短话和一张从数据里长出来的图(全年织纹、日历点阵、针织热力、作息波形、年度时间轴)。电脑上点右边往后翻、点左边往回翻,方向键也行,连着点几下就翻几页。手机上点屏幕任何地方都是下一页,左下角的小箭头回上一页;一页比屏幕高时照常上下滑着看。不做左右滑动翻页,免得和手机浏览器自带的「滑动返回」打架、一滑就退出页面。最后一页是竖版分享卡,主按钮「复制图片」把图片放进剪贴板(浏览器不让复制图片时改成保存到「下载」),旁边是「保存图片」和一个小小的「复制文字版」。这是「详细」;右上角点「简约」换成一页看完的成绩单,点「中 | EN」换语言,当前那个是深色的。
|
|
31
43
|
|
|
32
44
|

|
|
33
45
|
|
|
@@ -35,33 +47,95 @@ nianlun --demo # 没有记录也能先看看(演示数据)
|
|
|
35
47
|
|
|
36
48
|

|
|
37
49
|
|
|
38
|
-
##
|
|
50
|
+
## 终端
|
|
39
51
|
|
|
40
|
-
|
|
52
|
+
`nianlun` 只出一屏:主角是你今年发了多少条消息,旁边是年度称号和一句判词,下面一条整年热力图、八个数(会话、开工天数、最晚收工……),最底下一行「按 Enter,在浏览器里看完整版」。按 Enter 就打开网页版,成绩单和网址留在终端里;按 Q 退出。80×24 的小窗口也放得下。输出接到管道或文件里(不是终端)时不等按键,一次打完,最后写出 `nianlun web` 这条命令。
|
|
41
53
|
|
|
42
|
-
|
|
43
|
-
- **详细**(detailed):终端里是同一张成绩单,下面再加项目榜、命令榜、活跃高峰、各家占比、砸得最狠的文件;网页和分享图是浅纸色的画册。
|
|
54
|
+

|
|
44
55
|
|
|
45
|
-
|
|
56
|
+
想在终端里看完整版,用 `nianlun story`:成绩单之后每按一次 Enter 翻一页:总览、各家排行、模型排行、折合费用、最忙的一天、纪录、活跃高峰、项目榜、命令榜、砸得最狠的文件、你说 vs 它回、年度称号,最后一页按 Enter 生成分享图。底栏每一页都写着「W 浏览器看完整版」。每页都在 80×24 以内。
|
|
46
57
|
|
|
47
|
-

|
|
59
|
+
|
|
60
|
+
## 两种风格:简约 / 详细
|
|
61
|
+
|
|
62
|
+
网页和分享图有两种风格,网页右上角切换,`nianlun share --style minimal|detailed` 指定分享图用哪种。网页默认详细,分享图默认简约。
|
|
63
|
+
|
|
64
|
+
- **简约**(minimal):一页看完的成绩单,和终端那张同一套数。
|
|
65
|
+
- **详细**(detailed):浅纸色的画册,一页一个大数字或一个名字。
|
|
48
66
|
|
|
49
67
|
## 分享
|
|
50
68
|
|
|
51
|
-
`nianlun share` 写出一张 1080×1350
|
|
69
|
+
`nianlun share` 写出一张 1080×1350 的分享图。电脑上装了 Edge 或 Chrome 就顺手转成 PNG(无头模式,转完就关),并把**图片本身**放进剪贴板,提示「图片已复制,去微信里直接粘贴」。放剪贴板只用系统自带的东西:Windows 用 PowerShell,苹果用 osascript,Linux 有 wl-copy 或 xclip 就用。放不进去(或者没有 PNG、只出了 SVG)会直说,写出图片在哪,并退一步把文字版复制上。文字版写最想晒的几样,短到能直接发推特、朋友圈:
|
|
52
70
|
|
|
53
71
|
```text
|
|
54
72
|
我的 2026 AI 年轮
|
|
55
73
|
发了 2,094 条消息 · 599 个会话 · 开工 286 天
|
|
56
74
|
主力 Claude Code 67% · Opus 5.5
|
|
57
|
-
3.6 亿 token · 按 API 价折合 ¥2,798
|
|
58
|
-
最晚收工 凌晨
|
|
75
|
+
3.6 亿 token(含上下文和缓存) · 按 API 价折合 ¥2,798
|
|
76
|
+
最晚收工 凌晨 5:42(4/7) · 最长连续 27 天
|
|
59
77
|
年度称号:文件钉子户——一个文件,改到包浆
|
|
60
78
|
来一份你的:npx ai-nianlun
|
|
61
79
|
```
|
|
62
80
|
|
|
63
81
|
全程不上传、不联网。
|
|
64
82
|
|
|
83
|
+
## 多台电脑怎么合在一起看
|
|
84
|
+
|
|
85
|
+
年轮只读运行它的那台电脑。另一台电脑(比如树莓派、公司电脑)上的用量,三步并进来:
|
|
86
|
+
|
|
87
|
+
1. 在另一台电脑上运行 `nianlun export`,当前文件夹里会多一个 `nianlun-机器名-2026.json`(`--out 文件夹或文件名` 可以换地方,`--year`、`--tz` 和平常一样用)。
|
|
88
|
+
2. 把这个文件拷到主力电脑上,随便放哪。
|
|
89
|
+
3. 在主力电脑上运行 `nianlun --merge nianlun-机器名-2026.json`。`web`、`share`、`story` 一样能加 `--merge`,后面可以跟好几个文件。
|
|
90
|
+
|
|
91
|
+
合并后抬头和总览写「含 2 台电脑」,各页的数都是加在一起的。同一个会话在两边都有只算一次,两台电脑同一天都开工只算一天;同一台电脑导了好几次只用最新那份,本机自己导出的文件不会再加一遍。两台电脑的时区不一样会提醒你(导出时加 `--tz` 对齐);导出格式的版本不认识会直说,不硬读。
|
|
92
|
+
|
|
93
|
+
导出文件里只有统计数字:没有聊天原文、口头禅和代码,会话编号换成了摘要;项目只留文件夹名,文件只留改得最多的 40 个的名字(「砸得最狠的文件」那页要用),另外有机器名、模型名、工具名和命令名(`git status` 这一级)。发给别人之前看一眼。
|
|
94
|
+
|
|
95
|
+
## 年度称号
|
|
96
|
+
|
|
97
|
+
每个称号都有门槛,过了门槛的按「超出门槛多少」排,取最高的那个;分数一般是「实际 ÷ 门槛」;0.1.3 新加的称号里,没有上限的数(钱、模型个数、帮手个数、断档天数)先开平方再比,免得一个大数字把别的都压住。哪个都没过,开工不到 30 天的是「佛系体验官」,其余是「稳定输出机」。作息那页另外从前四个里挑一个当角标。
|
|
98
|
+
|
|
99
|
+
| 称号 | 判词 | 门槛 |
|
|
100
|
+
|---|---|---|
|
|
101
|
+
| 凌晨架构师 | 月亮下班了,你还在线 | 三成以上的消息在晚 10 点到凌晨 5 点,高峰在 21 点以后 |
|
|
102
|
+
| 破晓先锋 | 公司没开门,代码先开张 | 两成以上的消息在早上 5 到 9 点,高峰在中午以前 |
|
|
103
|
+
| 准点交付官 | 上班火力全开,下班准时消失 | 65% 以上的消息在工作日 9 点到 18 点 |
|
|
104
|
+
| 周末不打烊 | 别人的周末,你的冲刺 | 四成以上的消息在周末 |
|
|
105
|
+
| 人肉守护进程 | 一坐下,就是一个版本 | 最长一个会话连着干了 4 小时以上 |
|
|
106
|
+
| 一人成军 | 你动动嘴,它千军万马 | 发过 30 条以上,平均一条消息它动手 10 次以上 |
|
|
107
|
+
| 全勤战神 | 打卡比上班还准时 | 今年过去一个月以上,出勤 95% 以上 |
|
|
108
|
+
| 常驻嘉宾 | 它的熟客名单,你在前排 | 不到全勤,但开工 200 天、或连续 60 天、或出勤六成以上 |
|
|
109
|
+
| 多线程人类 | 项目开得比浏览器标签还多 | 15 个以上的项目 |
|
|
110
|
+
| 端水大师 | 雨露均沾,谁也不得罪 | 用了 3 家以上,最多的一家不到一半 |
|
|
111
|
+
| Ctrl+Z 战神 | 推倒重来,是你的基本功 | 「不对」说了 30 次以上,每 20 条消息就有一次 |
|
|
112
|
+
| 赛博礼仪官 | AI 起义那天,会记得你的好 | 「谢谢」说了 30 次以上,每 20 条消息就有一次 |
|
|
113
|
+
| 提示词诗人 | 每条消息都是一篇小作文 | 发过 50 条以上,平均每条 80 个 token 以上 |
|
|
114
|
+
| 惜字如金 | 你说两个字,它写两千行 | 你打 1 个 token,它回 200 个以上 |
|
|
115
|
+
| git push 武士 | 提交记录就是你的刀谱 | git 跑了 150 次以上,占全部命令四成以上 |
|
|
116
|
+
| 文件钉子户 | 一个文件,改到包浆 | 一个文件改了 150 次以上 |
|
|
117
|
+
| 单日爆肝王 | 那一天,键盘冒烟了 | 最忙那天 120 条消息以上,是平常一天的 6 倍以上 |
|
|
118
|
+
| 算力吞金兽 | 这笔账单,够给它发年终奖了 | 按官方价折合 2 万元以上 |
|
|
119
|
+
| 换模如换衣 | 新模型一发,你永远在第一排 | 正经用过(每个至少 30 次回复)8 个以上的模型 |
|
|
120
|
+
| 硅基纯爱党 | 别的模型再卷,你眼皮都不抬 | 用过不止一个模型、会话 50 个以上,95% 的回复还是同一个 |
|
|
121
|
+
| 赛博包工头 | 活不自己干,全派分身去冲 | 派出帮手(子代理)300 个以上,平均每个会话 2 个以上 |
|
|
122
|
+
| 继续复读机 | 你最强的提示词,只有两个字 | 整句只有「继续」的消息 60 条以上,占一成以上 |
|
|
123
|
+
| 算了文学家 | 教它三遍不会,不如自己上 | 「算了」「我自己来」15 次以上,每 100 条消息就有一次 |
|
|
124
|
+
| 十万个为什么 | 代码先放放,先把原理聊透 | 问「为什么」60 次以上,占消息 16% 以上 |
|
|
125
|
+
| 甩手大甲方 | 开口就是帮我,绝不自己动手 | 发过 100 条以上,35% 以上带着「帮我」 |
|
|
126
|
+
| 删代码艺术家 | 别人靠加法,你靠减法封神 | 删的行比加的多(至少删 2000 行、加过 1000 行) |
|
|
127
|
+
| 删库边缘人 | 每次敲回车,硬盘都在发抖 | rm、git reset、git clean 这类 50 次以上,占命令 4% 以上 |
|
|
128
|
+
| 只读不改党 | 翻遍整个项目,一行没动 | 动手 200 次以上,读和搜占六成以上,改和写不到 5% |
|
|
129
|
+
| 线上消防员 | 别人写需求,你天天救生产 | ssh、docker、kubectl 这类 50 次以上,占命令 15% 以上 |
|
|
130
|
+
| 浏览器终结者 | 搜索引擎没了你,日活少一半 | 替你上网查 150 次以上,占动手两成以上 |
|
|
131
|
+
| 一仓养老党 | 一整年,就死磕这一个项目 | 开工 30 天以上,八成的日子在同一个项目 |
|
|
132
|
+
| 新窗强迫症 | 聊两句就重开,从不回头看 | 200 个会话以上,平均每个只说 3 句以内 |
|
|
133
|
+
| 睡前派单王 | 临睡丢句话,醒来直接验收 | 晚 11 点到凌晨 3 点说完最后一句,它又自己干了半小时以上,全年 5 次以上 |
|
|
134
|
+
| 闭关出山党 | 消失一个多月,回来照样能打 | 中间断了 30 天以上,回来头 7 天就来了 3 天以上 |
|
|
135
|
+
| 突然觉醒者 | 某个月开了窍,用量直接起飞 | 某个月的消息是之前月均的 4 倍以上,那个月至少 200 条 |
|
|
136
|
+
| 佛系体验官 | 偶尔来坐坐,主打随缘 | 哪个都没过,开工不到 30 天 |
|
|
137
|
+
| 稳定输出机 | 不疾不徐,周周有货 | 哪个都没过,开工 30 天以上 |
|
|
138
|
+
|
|
65
139
|
## 语言
|
|
66
140
|
|
|
67
141
|
中文和英文两套。默认跟系统语言走(先看 `--lang`,再看 LC_ALL、LC_MESSAGES、LANG,最后看系统区域设置),以 zh 开头的是中文,其他都是英文。数字中文按万、亿写,英文按 K、M、B 写;英文版的钱按 1 美元 = 6.7 元换回美元。
|
|
@@ -77,7 +151,8 @@ nianlun --demo # 没有记录也能先看看(演示数据)
|
|
|
77
151
|
| DeepSeek 桌面版 | 自动找 | 用真实记录验证过 |
|
|
78
152
|
| WorkBuddy | 自动找 | 用真实记录验证过 |
|
|
79
153
|
| Kimi Code | 自动找 | 用真实记录验证过 |
|
|
80
|
-
| OpenCode | 自动找 | 用真实记录验证过 |
|
|
154
|
+
| OpenCode 1.x | 自动找 | 用真实记录验证过 |
|
|
155
|
+
| OpenCode 2.x | 自动找 | **照官方源码的表结构造样例测过,没在真实的第二版数据上验证** |
|
|
81
156
|
| Kiro | 自动找 | 用真实记录验证过 |
|
|
82
157
|
| GitHub Copilot 命令行 | 自动找 | 只有一个真实会话可验证 |
|
|
83
158
|
| Cursor | 自动找 | **只用编造的样例测过** |
|
|
@@ -89,6 +164,7 @@ nianlun --demo # 没有记录也能先看看(演示数据)
|
|
|
89
164
|
|
|
90
165
|
- 只读各家工具自己的记录文件,不改动、不读登录凭据、不联网;网页版只开在 127.0.0.1。
|
|
91
166
|
- 分享图和文字版默认不带项目名、文件名和你说过的话,加 `--full` 才带;`--html` 导出的网页里有,发出去前看一眼。
|
|
167
|
+
- `nianlun export` 导出的文件只有统计数字,见「多台电脑怎么合在一起看」。
|
|
92
168
|
- 统计结果(不是聊天原文)缓存在本机:Windows `%LOCALAPPDATA%\ai-nianlun`,苹果 `~/Library/Caches/ai-nianlun`,其他 `~/.cache/ai-nianlun`,删掉无妨。
|
|
93
169
|
|
|
94
170
|
## 选项
|
|
@@ -99,7 +175,7 @@ nianlun --demo # 没有记录也能先看看(演示数据)
|
|
|
99
175
|
--only claude,codex 只读这几家
|
|
100
176
|
--path <文件> 加一份导出的聊天记录压缩包,可写多次
|
|
101
177
|
--name <称呼> 怎么称呼你
|
|
102
|
-
--style minimal
|
|
178
|
+
--style minimal 分享图和网页的风格:minimal 简约 · detailed 详细
|
|
103
179
|
--lang zh|en 语言(默认跟系统)
|
|
104
180
|
--out <文件夹> 分享图写到哪
|
|
105
181
|
--no-png 不转 PNG,只出 SVG
|
|
@@ -107,14 +183,37 @@ nianlun --demo # 没有记录也能先看看(演示数据)
|
|
|
107
183
|
--full 分享内容带上项目名、文件名和口头禅
|
|
108
184
|
--html [文件名] 导出单文件网页
|
|
109
185
|
--json 打印全部统计
|
|
110
|
-
--plain
|
|
186
|
+
--plain 不上色、不等按键,一次打完
|
|
111
187
|
--list 列出支持哪些工具、找到了哪些
|
|
112
188
|
--no-cache 不用缓存重新读
|
|
113
189
|
--port 4731 网页版端口
|
|
114
190
|
--no-open 不自动开浏览器
|
|
191
|
+
duizhang [--db 文件] 和本机 CC Switch 对账(check 也行),见「和 CC Switch、Codex 的数对不上怎么办」
|
|
115
192
|
```
|
|
116
193
|
|
|
117
|
-
折合费用按 [CC Switch](https://github.com/farion1231/cc-switch) 的价格表和算法估算(1 美元按 6.7
|
|
194
|
+
折合费用按 [CC Switch](https://github.com/farion1231/cc-switch) 的价格表和算法估算(1 美元按 6.7 元),是**按官方标价估算**:包月订阅的人实际花的不是这个数;走第三方转接地址(自定义接口地址)的用量只要日志里有 token 数就算进去,也按模型名对官方标价估,转接的实际收费可能不同。认不出价钱的模型不会悄悄丢掉,在「按官方标价估算」那页单列「未识别」,写出多少 token、叫什么。同一个模型带不同思考强度、上下文长度后缀或编排模式时合成一个算(规则见 [docs/读取器约定.md](docs/读取器约定.md))。
|
|
195
|
+
|
|
196
|
+
只统计**运行年轮的这台电脑**上的记录:在树莓派、服务器上用的 AI 工具,要在那台机器上跑一次 `npx ai-nianlun` 才统计得到。
|
|
197
|
+
|
|
198
|
+
## 和 CC Switch、Codex 的数对不上怎么办
|
|
199
|
+
|
|
200
|
+
先看三件事,大多数「对不上」就是它们:
|
|
201
|
+
|
|
202
|
+
1. **年轮的大数字含缓存读。** token 总数 = 新输入 + 输出 + 缓存读 + 缓存写,其中缓存读(命中缓存、重复读上下文的部分)通常占九成以上。只看「输入 + 输出」的工具,数字会小一个数量级。
|
|
203
|
+
2. **年轮算的是一整年、只读还在磁盘上的记录。** Claude Code 默认只留 30 天记录,删掉的年轮读不到;CC Switch 早先抄下来的还留在它自己的库里,所以它的历史往往比年轮多。
|
|
204
|
+
3. **年轮每次都按今天的价格重算折合费用。** CC Switch 每条记录写进去那一刻按当时的价算,以后不重算,价格表变了两边就对不上。
|
|
205
|
+
|
|
206
|
+
装了 CC Switch 的话,直接跑:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
nianlun duizhang # 英文别名 check
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
它按工具、按模型把两边的请求数、四种 token、折合美元并排列出来,标出差得多的行,再单独比一段「两边都有完整逐条记录的日子」(CC Switch 只留近 30 天左右的逐条记录),看读法本身差多少,最后用大白话写出每一类差距的原因。输出只有模型名和数字,可以整段复制发给别人。它只读 CC Switch 库里和用量有关的两张表,先抄一份副本再读,不碰原件、不碰别的表。
|
|
213
|
+
|
|
214
|
+
读 Claude Code、Codex、OpenCode 记录的规则和 CC Switch 对齐过(照它的开源代码,提交 39f1059d):在作者电脑上,两边都有完整记录的 29 天里,Claude 和 Codex 的四种 token 逐模型相差都在 1% 以内(Codex 一模一样);Codex 全年逐模型一致,只差 8 次自动审查请求(那是旧版 Codex 把上一次审查的用量抄进新文件,CC Switch 多算了,年轮不算)。
|
|
215
|
+
|
|
216
|
+
**0.1.4 修了一个大问题:** 0.1.3 及以前,Codex 恢复或分叉出来的会话如果开头带着之前的累计用量、或者抄了父会话的记录,会被再算一遍,Codex 的数能虚高好几倍。现在和 CC Switch 一样按每次请求自己的用量记,抄来的那段剔掉。用老版本算过的,升级后重新跑一次。
|
|
118
217
|
|
|
119
218
|
## 加一家
|
|
120
219
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-nianlun",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "AI 年轮 / AI Rings:读本机各家 AI 编程工具的使用记录,在终端里打一张年度成绩单,能出分享图。Your year with AI coding tools, wrapped in your terminal. Zero deps, no network.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -14,9 +14,13 @@
|
|
|
14
14
|
"README.md",
|
|
15
15
|
"README.en.md",
|
|
16
16
|
"LICENSE",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
17
|
+
"docs/图/风格/分享图-两风格-中英.png",
|
|
18
|
+
"docs/图/风格/成绩单-中英-深色.png",
|
|
19
|
+
"docs/图/风格/终端全部页-中.png",
|
|
20
|
+
"docs/图/风格/网页-简约.png",
|
|
21
|
+
"docs/图/风格/网页-详细-中.png",
|
|
22
|
+
"docs/图/风格/网页-详细-手机.png",
|
|
23
|
+
"docs/图/风格/网页-详细-英.png"
|
|
20
24
|
],
|
|
21
25
|
"scripts": {
|
|
22
26
|
"test": "node --test \"test/*.test.mjs\"",
|
|
@@ -26,20 +30,20 @@
|
|
|
26
30
|
"node": ">=18"
|
|
27
31
|
},
|
|
28
32
|
"license": "MIT",
|
|
29
|
-
"repository": {
|
|
30
|
-
"type": "git",
|
|
31
|
-
"url": "git+https://github.com/OWNER/ai-nianlun.git"
|
|
32
|
-
},
|
|
33
33
|
"keywords": [
|
|
34
34
|
"ai",
|
|
35
35
|
"wrapped",
|
|
36
|
+
"year-in-review",
|
|
36
37
|
"年度总结",
|
|
37
|
-
"
|
|
38
|
+
"cli",
|
|
39
|
+
"claude-code",
|
|
38
40
|
"codex",
|
|
39
41
|
"cursor",
|
|
42
|
+
"gemini",
|
|
43
|
+
"antigravity",
|
|
40
44
|
"deepseek",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
45
|
+
"copilot",
|
|
46
|
+
"token",
|
|
47
|
+
"usage"
|
|
44
48
|
]
|
|
45
49
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// nianlun duizhang(check):和本机 CC Switch 对账,打成一段能整段复制的纯文字。
|
|
2
|
+
// 只出模型名和数字:不带路径、用户名、项目名、会话内容。
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import { num } from '../core/fmt.js';
|
|
5
|
+
import { PRODUCT, tr } from '../core/i18n.js';
|
|
6
|
+
import { BRANDS } from '../core/brands.js';
|
|
7
|
+
import { systemZone } from '../core/time.js';
|
|
8
|
+
import { ccswitchDB, compare, readCCSwitch, readNianlun, tokOf } from '../node/duizhang.js';
|
|
9
|
+
import { hasSqlite } from '../node/sqlite.js';
|
|
10
|
+
import { loadUserPrices } from '../node/prices.js';
|
|
11
|
+
import { padEnd, padStart } from './term.js';
|
|
12
|
+
|
|
13
|
+
const MAX_ROWS = 8;
|
|
14
|
+
const int = (n) => Math.round(n || 0).toLocaleString('en-US');
|
|
15
|
+
const usd = (n) => (n >= 100 ? int(n) : (Math.round((n || 0) * 100) / 100).toFixed(2));
|
|
16
|
+
function pctText(x) {
|
|
17
|
+
const v = x * 100;
|
|
18
|
+
if (Math.abs(v) < 0.05) return '0%';
|
|
19
|
+
return (v > 0 ? '+' : '') + (Math.abs(v) >= 10 ? Math.round(v) : v.toFixed(1)) + '%';
|
|
20
|
+
}
|
|
21
|
+
const big = (r) => Math.abs(r.diff) >= 0.05 && Math.max(tokOf(r.nl), tokOf(r.cc)) >= 1e6;
|
|
22
|
+
const nameOf = (id) => (BRANDS[id] && BRANDS[id].name) || id;
|
|
23
|
+
|
|
24
|
+
// 一张表:每个模型两行(年轮 / CC Switch),最后一列是 CC Switch 那行上「年轮比它多 / 少」的比例
|
|
25
|
+
function table(rows, totalRow) {
|
|
26
|
+
const cols = tr('dz.cols');
|
|
27
|
+
const W = [Math.max(14, ...rows.map((r) => r.model.length)), Math.max(4, tr('dz.cc').length), 7, 8, 8, 8, 8, 8, 6];
|
|
28
|
+
const line = (cells) => ' ' + cells.map((c, i) => (i < 2 ? padEnd(c, W[i]) : padStart(c, W[i]))).join(' ');
|
|
29
|
+
const out = [line(cols)];
|
|
30
|
+
const shown = rows.slice(0, MAX_ROWS);
|
|
31
|
+
const pair = (label, r, flag) => {
|
|
32
|
+
const a = r.nl;
|
|
33
|
+
const b = r.cc;
|
|
34
|
+
out.push(line([label, tr('dz.nl'), int(a.n), num(a.in), num(a.out), num(a.cr), num(a.cw), usd(a.usd), '']));
|
|
35
|
+
out.push(line(['', tr('dz.cc'), int(b.n), num(b.in), num(b.out), num(b.cr), num(b.cw), usd(b.usd), pctText(r.diff)]) + (flag ? ' ' + tr('dz.flag') : ''));
|
|
36
|
+
};
|
|
37
|
+
for (const r of shown) pair(r.model, r, big(r));
|
|
38
|
+
if (rows.length > shown.length) out.push(' ' + tr('dz.more', rows.length - shown.length));
|
|
39
|
+
if (totalRow) pair(tr('dz.total'), totalRow, false);
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function renderCheck(res, { zone }) {
|
|
44
|
+
const P = PRODUCT;
|
|
45
|
+
const out = [tr('dz.title', res.year, zone)];
|
|
46
|
+
if (res.window) out.push(tr('dz.until', new Date(Date.parse(res.window.to) - 86400000).toISOString().slice(5, 10)));
|
|
47
|
+
out.push(tr('dz.legend'), '');
|
|
48
|
+
for (const app of res.apps) {
|
|
49
|
+
out.push('== ' + nameOf(app.id) + ' ==');
|
|
50
|
+
out.push(...table(app.rows, app.rows.length > 1 ? app.total : null));
|
|
51
|
+
out.push('');
|
|
52
|
+
if (res.window) {
|
|
53
|
+
const [from, to] = [res.window.from, res.window.to];
|
|
54
|
+
const last = new Date(Date.parse(to) - 86400000).toISOString().slice(0, 10);
|
|
55
|
+
out.push(' ' + tr('dz.winHead', res.window.days, from.slice(5), last.slice(5)));
|
|
56
|
+
if (app.win.length) {
|
|
57
|
+
out.push(...table(app.win, app.win.length > 1 ? { nl: app.winTotal.nl, cc: app.winTotal.cc, diff: (tokOf(app.winTotal.nl) - tokOf(app.winTotal.cc)) / (tokOf(app.winTotal.cc) || 1) } : null));
|
|
58
|
+
out.push(' ' + (app.winTotal.worst <= 0.01 ? tr('dz.winSame') : tr('dz.winOff', pctText(app.winTotal.worst).replace('+', ''))));
|
|
59
|
+
} else out.push(' ' + tr('dz.winNone'));
|
|
60
|
+
} else out.push(' ' + tr('dz.noWin'));
|
|
61
|
+
out.push('');
|
|
62
|
+
// 原因
|
|
63
|
+
const why = [];
|
|
64
|
+
const ccTok = tokOf(app.total.cc) || 1;
|
|
65
|
+
if (app.gone.tok > ccTok * 0.001) why.push(tr('dz.r.gone', app.gone.days, num(app.gone.tok), app.gone.empty, app.id === 'claude'));
|
|
66
|
+
const ccUsd = app.total.cc.usd;
|
|
67
|
+
if (ccUsd > 0 && Math.abs(app.repriced - ccUsd) / ccUsd > 0.01) why.push(tr('dz.r.price', usd(ccUsd), usd(app.repriced)));
|
|
68
|
+
if (app.unpriced.length) why.push(tr('dz.r.unpriced', app.unpriced.slice(0, 6).join(', ')));
|
|
69
|
+
if (app.cw1h > 0) why.push(tr('dz.r.cw1h', num(app.cw1h)));
|
|
70
|
+
if (tokOf(app.before) > 0) why.push(tr('dz.r.before', res.year, num(tokOf(app.before))));
|
|
71
|
+
if (app.extra.tok > ccTok * 0.001) why.push(tr('dz.r.ccOld', app.extra.days, num(app.extra.tok)));
|
|
72
|
+
if (app.id === 'codex') why.push(tr('dz.r.codexDup'));
|
|
73
|
+
if (!why.length) why.push(tr('dz.r.none'));
|
|
74
|
+
out.push(' ' + tr('dz.why'));
|
|
75
|
+
for (const w of why) out.push(' · ' + w);
|
|
76
|
+
out.push('');
|
|
77
|
+
}
|
|
78
|
+
out.push(tr('dz.foot', P));
|
|
79
|
+
return out.join('\n');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 入口。返回进程退出码
|
|
83
|
+
export async function checkMain(o, { home, io, write = (s) => process.stdout.write(s), note = (s) => process.stderr.write(s) } = {}) {
|
|
84
|
+
const file = o.db || ccswitchDB(home);
|
|
85
|
+
if (!fs.existsSync(file)) {
|
|
86
|
+
write('\n ' + tr('dz.noDB') + '\n ' + tr('dz.noDBHow', PRODUCT) + '\n\n');
|
|
87
|
+
return 1;
|
|
88
|
+
}
|
|
89
|
+
if (!hasSqlite) {
|
|
90
|
+
write('\n ' + tr('dz.badDB') + '\n\n');
|
|
91
|
+
return 1;
|
|
92
|
+
}
|
|
93
|
+
const zone = o.zone || systemZone();
|
|
94
|
+
const year = o.year;
|
|
95
|
+
const cc = readCCSwitch(file, { year, zone });
|
|
96
|
+
if (!cc) {
|
|
97
|
+
write('\n ' + tr('dz.badDB') + '\n\n');
|
|
98
|
+
return 1;
|
|
99
|
+
}
|
|
100
|
+
const nl = await readNianlun({ year, zone, io, window: cc.window, onSource: (id) => note(' ' + tr('dz.reading', nameOf(id)) + '\r') });
|
|
101
|
+
note(' '.repeat(60) + '\r');
|
|
102
|
+
const res = compare(cc, nl, { year, prices: o.prices === false ? null : loadUserPrices(home ? { home } : {}) });
|
|
103
|
+
if (!res.apps.length) {
|
|
104
|
+
write('\n ' + tr('dz.empty') + '\n\n');
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
write('\n' + renderCheck(res, { zone }) + '\n\n');
|
|
108
|
+
return 0;
|
|
109
|
+
}
|