glm-quota-line 1.1.1 → 1.3.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/CHANGELOG.md +34 -0
- package/README.en.md +192 -17
- package/README.md +195 -19
- package/data/models.json +10 -0
- package/package.json +4 -2
- package/src/claude/sessionStart.js +1 -1
- package/src/claude/settings.js +76 -5
- package/src/cli/args.js +39 -40
- package/src/cli/commands.js +63 -10
- package/src/cli/configCommand.js +86 -0
- package/src/cli/help.js +263 -0
- package/src/cli/index.js +143 -83
- package/src/cli/modelCommand.js +127 -0
- package/src/cli/registry.js +236 -0
- package/src/core/context/cache.js +98 -0
- package/src/core/context/calculator.js +48 -0
- package/src/core/context/formatter.js +85 -0
- package/src/core/context/index.js +100 -0
- package/src/core/context/models.js +153 -0
- package/src/core/context/parser.js +54 -0
- package/src/core/query/format.js +1 -12
- package/src/core/quota/cache.js +85 -1
- package/src/core/quota/parse.js +1 -12
- package/src/core/status/format.js +299 -154
- package/src/core/status/theme.js +51 -98
- package/src/core/status/viewModel.js +104 -18
- package/src/shared/ansi.js +52 -0
- package/src/shared/bar.js +40 -0
- package/src/shared/config.js +19 -54
- package/src/shared/constants.js +166 -4
- package/src/shared/migration.js +53 -0
- package/src/shared/utils.js +56 -0
- package/src/tui/index.js +273 -0
- package/src/tui/utils/demoData.js +27 -0
- package/src/claude/contextWindow.js +0 -39
- package/src/core/status/bar.js +0 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
- Added `commands` subcommand: list every command with a machine-readable schema via `--json` (name / summary / sideEffect / args / examples), for AI agents and scripting
|
|
6
|
+
- Added per-subcommand `--help` (e.g. `model --help`, `config set --help`) — focused help derived from a single command registry
|
|
7
|
+
- **User-customizable model mapping table** — model context window sizes are now managed by the user at runtime. The bundled `data/models.json` is just a frozen base; your local `modelMap` overlays it, so adapting to a new model (e.g. `glm-5.2` with 1M context) needs only `model set <id> <size>` — no package update or upgrade required
|
|
8
|
+
- Added `model` subcommands: `list`, `get`, `set`, `remove` — manage model context window size mappings via CLI
|
|
9
|
+
- Added `modelMap` persistence in tool config — custom model sizes survive across sessions
|
|
10
|
+
- Added `config reset [--models] [--yes]` — restore user config to defaults. `--models` limits the reset to custom model mappings. Preserves install state; prompts unless `--yes` (required in non-interactive sessions)
|
|
11
|
+
- Model ids reported with a bracket suffix (e.g. `glm-5.2[1M]`) are now normalized to the bare id for lookup and display
|
|
12
|
+
- Updated default table: added `glm-5.2` (1M context), removed `glm-5` and `glm-5.1` (no longer in plan)
|
|
13
|
+
- Added `reset-format` config (`time` / `countdown`) — show reset time as countdown duration instead of time point
|
|
14
|
+
- Weekly quota now displays reset time (time point or countdown) alongside the progress bar
|
|
15
|
+
- Context window resolution now relies solely on the local model map: stdin `context_window_size` is ignored, and stdin-provided window percentages are no longer used as a fallback (they are often inaccurate). If the current model id is not in the map, the context segment is simply not shown rather than guessing
|
|
16
|
+
- ctx cache now keyed by session id + model id: token usage can be 0 or missing on individual status-line frames (session start, between requests), which would make the context segment flash. The cache falls back to the last valid value for the same session and model so the display stays stable — a stale value from a different session or model is never shown
|
|
17
|
+
- Refactored command dispatch into `configCommand.js` / `modelCommand.js`, and extracted a shared `bar.js` and a context-scoped `cache.js`. No behavior change
|
|
18
|
+
- Hardcoded `glm-4.7` fallback remains as a defensive guard against `data/models.json` I/O failure
|
|
19
|
+
|
|
20
|
+
## 1.2.0
|
|
21
|
+
|
|
22
|
+
- Added interactive TUI configuration: `glm-quota-line configure` — live preview, per-component toggle and style, global options
|
|
23
|
+
- Added component-level control: each display component (plan, 5h, week, reset, context) can be individually toggled and styled
|
|
24
|
+
- Added `minimalist` config to hide all labels, showing only progress bars and values
|
|
25
|
+
- Added `raw-values` config to hide labels and show raw values
|
|
26
|
+
- Added `--json` flag for structured JSON output in terminal mode (useful for scripting and automation)
|
|
27
|
+
- Added `work-days` config (1-7) to customize weekly working days for quota pacing calculation
|
|
28
|
+
- Added one-time query via `npx glm-quota-line` without global install
|
|
29
|
+
- Context window now displays model ID and window size (e.g., `glm-4.7 (200K)`)
|
|
30
|
+
- Context window usage is now calculated from raw tokens when model mapping is available
|
|
31
|
+
- Weekly quota bar now shows theoretical budget with shade segments (▒) when pacing data is available
|
|
32
|
+
- Weekly quota severity now uses pacing-based calculation: good (≤1.1x), warn (1.1-1.3x), danger (>1.3x)
|
|
33
|
+
- Added GLM provider detection to disable quota for non-Zhipu API endpoints
|
|
34
|
+
- Replaced `--ctx on|off` CLI flag and `config set/unset ctx` with TUI component config
|
|
35
|
+
- Consolidated duplicate utility functions into shared `utils.js` module
|
|
36
|
+
|
|
3
37
|
## 1.1.1
|
|
4
38
|
|
|
5
39
|
- Fixed MCP quota not displaying when API returns `TIME_LIMIT` type instead of `MCP_LIMIT`
|
package/README.en.md
CHANGED
|
@@ -19,13 +19,25 @@
|
|
|
19
19
|
|
|
20
20
|
- **Terminal quick check** — run `glm-quota-line` in any terminal to view your quota (including MCP) without launching Claude Code
|
|
21
21
|
- **Claude Code status line** — auto-embeds in the status bar after install, shows quota balance, reset time, and context window usage in real time
|
|
22
|
-
- **Bar visualization** — default bar style shows remaining quota at a glance
|
|
22
|
+
- **Bar visualization** — default bar style shows remaining quota at a glance; weekly quota shows theoretical budget shadow
|
|
23
|
+
- **Weekly pacing analysis** — calculates usage speed based on work days, auto-highlights when exceeding theoretical budget
|
|
24
|
+
- **JSON output** — `--json` flag outputs structured data for scripting
|
|
25
|
+
- **Interactive configuration** — `glm-quota-line configure` launches a TUI with live preview and per-component controls
|
|
26
|
+
- **Component-level control** — each display component (plan, 5h, week, reset, context) can be individually toggled and styled
|
|
23
27
|
- **Smart caching** — tiered refresh by session, TTL, and token usage; `SessionStart` hook pre-refreshes so new sessions never show stale data
|
|
24
28
|
- **Domestic + international endpoints** — auto-detects `open.bigmodel.cn` and `api.z.ai`
|
|
25
29
|
- **Zero dependencies** — no runtime deps, single-purpose CLI
|
|
26
30
|
|
|
27
31
|
## Quick Start
|
|
28
32
|
|
|
33
|
+
**One-time query (no install needed):**
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npx glm-quota-line
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Status line integration (global install required):**
|
|
40
|
+
|
|
29
41
|
```bash
|
|
30
42
|
npm install -g glm-quota-line
|
|
31
43
|
glm-quota-line install
|
|
@@ -34,7 +46,7 @@ glm-quota-line install
|
|
|
34
46
|
Done. Your Claude Code status bar will now show the quota:
|
|
35
47
|
|
|
36
48
|
```
|
|
37
|
-
GLM Lite █████████░ 91% | W 47% | 14:47 | ctx ███░░░ 45%
|
|
49
|
+
GLM Lite █████████░ 91% | W ▒▒▒▒░░░░░ 47% | 14:47 | ctx ███░░░ 45% (glm-4.7/200K)
|
|
38
50
|
```
|
|
39
51
|
|
|
40
52
|
You can also run `glm-quota-line` directly in the terminal to check your quota without launching Claude Code.
|
|
@@ -54,7 +66,7 @@ All options are optional. Persist with `glm-quota-line config set`, or override
|
|
|
54
66
|
|
|
55
67
|
| Value | Description | Example |
|
|
56
68
|
|---|---|---|
|
|
57
|
-
| `bar` (default) | Progress bar | `GLM Lite █████████░ 91% \| W 47% \| 14:47 \| ctx ███░░░ 45%` |
|
|
69
|
+
| `bar` (default) | Progress bar | `GLM Lite █████████░ 91% \| W ▒▒▒▒░░░░░ 47% \| 14:47 \| ctx ███░░░ 45%` |
|
|
58
70
|
| `text` | Full text | `GLM Lite \| 5h 91% \| week 47% \| reset 14:47 \| ctx 45%` |
|
|
59
71
|
| `compact` | Compact mode | `GLM 5h 91% W 47% \| 14:47` |
|
|
60
72
|
|
|
@@ -91,24 +103,86 @@ Quota percentage colors change automatically based on remaining amount:
|
|
|
91
103
|
glm-quota-line config set display used
|
|
92
104
|
```
|
|
93
105
|
|
|
94
|
-
###
|
|
106
|
+
### work-days — Work days per week
|
|
95
107
|
|
|
96
|
-
|
|
108
|
+
Set the number of work days per week (1–7) for weekly quota theoretical budget and pacing analysis. Default: 5.
|
|
97
109
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
110
|
+
```bash
|
|
111
|
+
glm-quota-line config set work-days 6
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Pacing analysis calculates theoretical budget based on elapsed work days:
|
|
115
|
+
- Green — usage speed ≤ 1.1x theoretical
|
|
116
|
+
- Yellow — usage speed 1.1x–1.3x theoretical
|
|
117
|
+
- Red — usage speed > 1.3x theoretical
|
|
118
|
+
|
|
119
|
+
### reset-format — Reset time format
|
|
120
|
+
|
|
121
|
+
Controls how the reset time is displayed in the status line.
|
|
122
|
+
|
|
123
|
+
| Value | Description | Example |
|
|
124
|
+
|---|---|---|
|
|
125
|
+
| `time` (default) | Show the reset time point | `reset 14:47` |
|
|
126
|
+
| `countdown` | Show the remaining countdown | `reset 52m` / `reset 2d 5h` |
|
|
102
127
|
|
|
103
128
|
```bash
|
|
104
|
-
glm-quota-line config set
|
|
129
|
+
glm-quota-line config set reset-format countdown
|
|
105
130
|
```
|
|
106
131
|
|
|
107
|
-
|
|
132
|
+
The weekly quota also shows the reset info (time point or countdown) alongside its progress bar.
|
|
108
133
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
134
|
+
### --json — JSON output
|
|
135
|
+
|
|
136
|
+
Output structured JSON format (terminal mode only, ignored in status line mode):
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
glm-quota-line --json
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Example output:
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"level": "Lite",
|
|
146
|
+
"quotas": [
|
|
147
|
+
{
|
|
148
|
+
"label": "5h",
|
|
149
|
+
"leftPercent": 91,
|
|
150
|
+
"usedPercent": 9,
|
|
151
|
+
"nextResetTime": 1715257200000
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"label": "week",
|
|
155
|
+
"leftPercent": 47,
|
|
156
|
+
"usedPercent": 53,
|
|
157
|
+
"nextResetTime": 1715744400000
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
"mcp": {
|
|
161
|
+
"leftPercent": 85,
|
|
162
|
+
"usedPercent": 15
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### minimalist — Minimal mode
|
|
168
|
+
|
|
169
|
+
Hide all labels, show only progress bars and values.
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
glm-quota-line config set minimalist true
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Effect:
|
|
176
|
+
- Off: `GLM Lite █████████░ 91% | W ▒▒▒▒░░░░░ 47% | 14:47`
|
|
177
|
+
- On: `█████████░ 91% | ▒▒▒▒░░░░░ 47% | 14:47`
|
|
178
|
+
|
|
179
|
+
### raw-values — Raw values
|
|
180
|
+
|
|
181
|
+
Hide all labels and show raw values directly.
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
glm-quota-line config set raw-values true
|
|
185
|
+
```
|
|
112
186
|
|
|
113
187
|
### auth-token / base-url — Custom auth
|
|
114
188
|
|
|
@@ -129,6 +203,69 @@ Auth source priority (highest to lowest):
|
|
|
129
203
|
2. Environment variables `ANTHROPIC_AUTH_TOKEN` / `ANTHROPIC_BASE_URL`
|
|
130
204
|
3. `env` field in `~/.claude/settings.json`
|
|
131
205
|
|
|
206
|
+
### reset — Restore defaults
|
|
207
|
+
|
|
208
|
+
One-shot reset of user config. Install state is preserved (status line / hook are not removed).
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
glm-quota-line config reset # reset all user config (interactive confirm)
|
|
212
|
+
glm-quota-line config reset --models # reset only custom model mappings (modelMap)
|
|
213
|
+
glm-quota-line config reset --yes # skip confirmation (scripts / CI)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
- Default scope: all global config keys (theme/display/style/work-days/minimalist/raw-values/reset-format/auth-token/base-url), component layout (lines), and custom model mappings (modelMap).
|
|
217
|
+
- `--models` limits the reset to modelMap only; other config is left untouched.
|
|
218
|
+
- In non-interactive sessions (no TTY) `--yes` is required, otherwise it errors out — to avoid accidental deletion.
|
|
219
|
+
- After reset the status line still works — model mappings fall back to the bundled table (`data/models.json`).
|
|
220
|
+
|
|
221
|
+
### configure — Interactive TUI setup
|
|
222
|
+
|
|
223
|
+
Launch a terminal UI with live preview to adjust component toggles, styles, and global options.
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
glm-quota-line configure
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Key bindings:
|
|
230
|
+
- `↑↓` select component, `Enter` to edit, `Tab` to cycle style, `Space` to toggle
|
|
231
|
+
- `g` to enter global options (theme, display mode, minimalist, raw-values)
|
|
232
|
+
- `s` to save, `q` to quit
|
|
233
|
+
|
|
234
|
+
Components:
|
|
235
|
+
|
|
236
|
+
| Component | Description | Styleable | Hideable |
|
|
237
|
+
|---|---|---|---|
|
|
238
|
+
| `level` | Plan level (e.g. GLM Lite) | — | ✓ |
|
|
239
|
+
| `5h` | 5-hour quota | ✓ (bar/text) | — (required) |
|
|
240
|
+
| `week` | Weekly quota | ✓ (bar/text) | ✓ |
|
|
241
|
+
| `reset` | Reset time | — | ✓ |
|
|
242
|
+
| `ctx` | Context window usage | ✓ (bar/text) | ✓ |
|
|
243
|
+
|
|
244
|
+
### model — Context window management
|
|
245
|
+
|
|
246
|
+
Manage the context window size mapping per model. The context window usage percentage is computed from this mapping.
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
glm-quota-line model list # list all models and their context window size
|
|
250
|
+
glm-quota-line model get <model-id> # show the size of a given model
|
|
251
|
+
glm-quota-line model set <model-id> <size> # set a model size (e.g. 300K or 300000)
|
|
252
|
+
glm-quota-line model remove <model-id> # remove a custom mapping (built-in model reverts to default)
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Example `list` output:
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
glm-4.7 200K
|
|
259
|
+
glm-5.1 200K
|
|
260
|
+
glm-5.2 300K *
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
The `*` marker indicates a user-configured mapping.
|
|
264
|
+
|
|
265
|
+
The model mapping is a two-layer system: the bundled `data/models.json` is the default base, and the `modelMap` in `~/.claude/glm-quota-line.json` is the user overlay (merged key-by-key at runtime). **When Zhipu releases a new model, you don't need to wait for an npm package update — just run `model set <new-model> <size>` to write the local overlay and it takes effect immediately.**
|
|
266
|
+
|
|
267
|
+
To clear all custom model mappings and return to the bundled default table, run `glm-quota-line config reset --models --yes`.
|
|
268
|
+
|
|
132
269
|
## Recommended Combinations
|
|
133
270
|
|
|
134
271
|
| Use case | Config |
|
|
@@ -137,29 +274,67 @@ Auth source priority (highest to lowest):
|
|
|
137
274
|
| Light terminal | `style=bar`, `theme=light` |
|
|
138
275
|
| Minimal setup | `style=compact`, `theme=mono` |
|
|
139
276
|
| Track usage | `style=bar`, `display=used` |
|
|
277
|
+
| Countdown reset | `reset-format=countdown` |
|
|
278
|
+
| Scripting | `--json` |
|
|
279
|
+
| 6-day work week | `work-days=6` |
|
|
280
|
+
| Minimal values | `minimalist=true` |
|
|
281
|
+
| Custom model | `glm-quota-line model set glm-5.2 300K` |
|
|
282
|
+
| Interactive setup | `glm-quota-line configure` |
|
|
140
283
|
|
|
141
284
|
## Command Reference
|
|
142
285
|
|
|
143
286
|
```bash
|
|
144
|
-
glm-quota-line [--style text|compact|bar] [--display left|used] [--theme dark|light|mono] [--
|
|
287
|
+
glm-quota-line [--style text|compact|bar] [--display left|used] [--theme dark|light|mono] [--json]
|
|
145
288
|
glm-quota-line install [--force]
|
|
146
289
|
glm-quota-line uninstall
|
|
147
290
|
glm-quota-line version
|
|
148
291
|
glm-quota-line check-update
|
|
292
|
+
glm-quota-line configure
|
|
149
293
|
glm-quota-line config show
|
|
150
|
-
glm-quota-line config set <style|display|theme|
|
|
294
|
+
glm-quota-line config set <style|display|theme|auth-token|base-url|work-days|minimalist|raw-values|reset-format> <value>
|
|
151
295
|
glm-quota-line config unset <key>
|
|
296
|
+
glm-quota-line config reset [--models] [--yes]
|
|
297
|
+
glm-quota-line model list
|
|
298
|
+
glm-quota-line model get <model-id>
|
|
299
|
+
glm-quota-line model set <model-id> <size>
|
|
300
|
+
glm-quota-line model remove <model-id>
|
|
152
301
|
```
|
|
153
302
|
|
|
154
303
|
Run `glm-quota-line --help` for full descriptions.
|
|
155
304
|
|
|
305
|
+
## For Agents / Automation
|
|
306
|
+
|
|
307
|
+
If you are an AI agent (Claude Code / Cursor / Codex) or a script author, the following surface is guaranteed stable:
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
# Get the full machine-readable schema of every command in one call
|
|
311
|
+
# (name / summary / sideEffect / args / examples)
|
|
312
|
+
glm-quota-line commands --json
|
|
313
|
+
|
|
314
|
+
# Focused help for a single command or command group
|
|
315
|
+
glm-quota-line model --help
|
|
316
|
+
glm-quota-line config set --help
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Conventions:
|
|
320
|
+
- **Exit codes**: `0` on success, `1` on error.
|
|
321
|
+
- **Side-effect tagging**: every command is tagged `read` (safe for automation), `write` (persists config / model map), `mutating` (modifies Claude Code integration), or `interactive` (requires a TTY).
|
|
322
|
+
- **Non-blocking**: no command blocks waiting for input (`config reset` needs `--yes` in non-interactive sessions; `configure` prints a hint instead of launching the TUI when there is no TTY).
|
|
323
|
+
- **Read query**: `glm-quota-line --json` emits structured quota data (5h / week / MCP + reset times).
|
|
324
|
+
|
|
325
|
+
Typical agent workflow: run `commands --json` to discover capabilities → invoke the command you need → parse stdout.
|
|
326
|
+
|
|
156
327
|
## Notes
|
|
157
328
|
|
|
158
329
|
- Shows `TOKENS_LIMIT` and `MCP_LIMIT` / `TIME_LIMIT` quotas
|
|
159
|
-
-
|
|
330
|
+
- Weekly quota progress bar shadow (▒) is a daily pacing baseline: the theoretical budget based on elapsed work days — the more the filled bar (█) extends past the shadow, the faster you're consuming
|
|
331
|
+
- Context window usage is shown by default; toggle via `glm-quota-line configure`
|
|
332
|
+
- Context window usage is computed from raw tokens using the local model map; if the current model id is not in the map, the context segment is not shown (no guessing)
|
|
333
|
+
- Each component can be individually toggled and styled via `glm-quota-line configure`
|
|
160
334
|
- Missing auth returns `GLM | auth expired`; API failures return `GLM | quota unavailable`
|
|
161
335
|
- `install` does not replace an unmanaged status line unless `--force` is used
|
|
162
336
|
- `install --force` backs up the previous entry; `uninstall` restores it when possible
|
|
337
|
+
- Set `GLM_QUOTA_DEBUG=1` to output context window debug info to stderr
|
|
163
338
|
|
|
164
339
|
## License
|
|
165
340
|
|
package/README.md
CHANGED
|
@@ -19,13 +19,25 @@
|
|
|
19
19
|
|
|
20
20
|
- **终端快速查询** — 直接运行 `glm-quota-line` 即可在终端查看配额(含 MCP),无需启动 Claude Code
|
|
21
21
|
- **Claude Code 状态栏** — 安装后自动嵌入状态栏,实时显示配额余额、重置时间和上下文窗口用量
|
|
22
|
-
- **进度条可视化** — 默认 bar
|
|
22
|
+
- **进度条可视化** — 默认 bar 风格,一眼看清剩余比例;周配额显示理论预算阴影
|
|
23
|
+
- **智能配速分析** — 根据工作日和已过时间计算配额使用速度,超速时自动变色警示
|
|
24
|
+
- **JSON 输出** — 支持 `--json` 参数输出结构化数据,便于脚本调用
|
|
25
|
+
- **交互式配置** — `glm-quota-line configure` 启动 TUI 界面,实时预览、逐项调整组件开关与样式
|
|
26
|
+
- **组件级控制** — 每个显示组件(套餐、5h、周、重置、上下文)可单独开关和设置样式
|
|
23
27
|
- **智能缓存** — 按会话、TTL 和 token 用量分级刷新;`SessionStart` hook 预刷新,新会话不显示旧数据
|
|
24
28
|
- **国内 + 国际端点** — 自动识别 `open.bigmodel.cn` 和 `api.z.ai`
|
|
25
29
|
- **零依赖** — 无运行时依赖,单一用途
|
|
26
30
|
|
|
27
31
|
## 快速开始
|
|
28
32
|
|
|
33
|
+
**一次性查询(无需安装):**
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npx glm-quota-line
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**状态栏集成(需要全局安装):**
|
|
40
|
+
|
|
29
41
|
```bash
|
|
30
42
|
npm install -g glm-quota-line
|
|
31
43
|
glm-quota-line install
|
|
@@ -34,7 +46,7 @@ glm-quota-line install
|
|
|
34
46
|
安装完成。Claude Code 底部状态栏会自动显示配额:
|
|
35
47
|
|
|
36
48
|
```
|
|
37
|
-
GLM Lite █████████░ 91% | W 47% | 14:47 | ctx ███░░░ 45%
|
|
49
|
+
GLM Lite █████████░ 91% | W ▒▒▒▒░░░░░ 47% 11:10 | 14:47 | ctx ███░░░ 45% (glm-4.7/200K)
|
|
38
50
|
```
|
|
39
51
|
|
|
40
52
|
也可以直接在终端运行 `glm-quota-line` 快速查看用量,无需启动 Claude Code。
|
|
@@ -54,9 +66,9 @@ glm-quota-line check-update
|
|
|
54
66
|
|
|
55
67
|
| 值 | 说明 | 示例 |
|
|
56
68
|
|---|---|---|
|
|
57
|
-
| `bar`(默认) | 进度条可视化 | `GLM Lite █████████░ 91% \| W 47% \| 14:47 \| ctx ███░░░ 45%` |
|
|
58
|
-
| `text` | 完整文本 | `GLM Lite \| 5h 91% \| week 47% \| reset 14:47 \| ctx 45%` |
|
|
59
|
-
| `compact` | 紧凑模式 | `GLM 5h 91% W 47% \| 14:47` |
|
|
69
|
+
| `bar`(默认) | 进度条可视化 | `GLM Lite █████████░ 91% \| W ▒▒▒▒░░░░░ 47% 11:10 \| 14:47 \| ctx ███░░░ 45%` |
|
|
70
|
+
| `text` | 完整文本 | `GLM Lite \| 5h 91% \| week 47% 11:10 \| reset 14:47 \| ctx 45%` |
|
|
71
|
+
| `compact` | 紧凑模式 | `GLM 5h 91% W 47% 11:10 \| 14:47` |
|
|
60
72
|
|
|
61
73
|
```bash
|
|
62
74
|
glm-quota-line config set style compact
|
|
@@ -91,24 +103,101 @@ glm-quota-line config set theme light
|
|
|
91
103
|
glm-quota-line config set display used
|
|
92
104
|
```
|
|
93
105
|
|
|
94
|
-
###
|
|
106
|
+
### work-days — 每周工作日
|
|
95
107
|
|
|
96
|
-
|
|
108
|
+
设置每周工作日数量(1-7),用于计算周配额的理论预算和配速分析。默认 5 天。
|
|
97
109
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
110
|
+
```bash
|
|
111
|
+
glm-quota-line config set work-days 6
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
配速分析会根据已过工作日计算理论预算,并判断使用速度:
|
|
115
|
+
- 绿色 — 使用速度 ≤ 1.1x 理论值
|
|
116
|
+
- 黄色 — 使用速度 1.1x–1.3x 理论值
|
|
117
|
+
- 红色 — 使用速度 > 1.3x 理论值
|
|
118
|
+
|
|
119
|
+
### minimalist — 极简模式
|
|
120
|
+
|
|
121
|
+
隐藏所有标签文字,只保留进度条和数值。
|
|
102
122
|
|
|
103
123
|
```bash
|
|
104
|
-
glm-quota-line config set
|
|
124
|
+
glm-quota-line config set minimalist true
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
效果对比:
|
|
128
|
+
- 关闭:`GLM Lite █████████░ 91% | W ▒▒▒▒░░░░░ 47% 11:10 | 14:47`
|
|
129
|
+
- 开启:`█████████░ 91% | ▒▒▒▒░░░░░ 47% 11:10 | 14:47`
|
|
130
|
+
|
|
131
|
+
### raw-values — 原始数值
|
|
132
|
+
|
|
133
|
+
隐藏所有标签文字,直接显示原始数值。
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
glm-quota-line config set raw-values true
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### reset-format — 重置时间格式
|
|
140
|
+
|
|
141
|
+
控制状态栏中重置时间的显示格式。
|
|
142
|
+
|
|
143
|
+
| 值 | 说明 | 示例 |
|
|
144
|
+
|---|---|---|
|
|
145
|
+
| `time`(默认) | 显示重置时间点 | `reset 14:47` |
|
|
146
|
+
| `countdown` | 显示剩余倒计时 | `reset 52m` / `reset 2d 5h` |
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
glm-quota-line config set reset-format countdown
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
周配额也会同步显示重置信息(时间点或倒计时)。
|
|
153
|
+
|
|
154
|
+
### --json — JSON 输出
|
|
155
|
+
|
|
156
|
+
输出结构化 JSON 格式(仅终端模式,状态栏模式忽略):
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
glm-quota-line --json
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
输出示例:
|
|
163
|
+
```json
|
|
164
|
+
{
|
|
165
|
+
"level": "Lite",
|
|
166
|
+
"quotas": [
|
|
167
|
+
{
|
|
168
|
+
"label": "5h",
|
|
169
|
+
"leftPercent": 91,
|
|
170
|
+
"usedPercent": 9,
|
|
171
|
+
"nextResetTime": 1715257200000
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"label": "week",
|
|
175
|
+
"leftPercent": 47,
|
|
176
|
+
"usedPercent": 53,
|
|
177
|
+
"nextResetTime": 1715744400000
|
|
178
|
+
}
|
|
179
|
+
],
|
|
180
|
+
"mcp": {
|
|
181
|
+
"leftPercent": 85,
|
|
182
|
+
"usedPercent": 15
|
|
183
|
+
}
|
|
184
|
+
}
|
|
105
185
|
```
|
|
106
186
|
|
|
107
|
-
|
|
187
|
+
### reset — 恢复出厂配置
|
|
188
|
+
|
|
189
|
+
一键重置用户配置,保留安装状态(不卸载状态栏/hook)。
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
glm-quota-line config reset # 交互确认后重置全部用户配置
|
|
193
|
+
glm-quota-line config reset --models # 只清空自定义模型映射(modelMap)
|
|
194
|
+
glm-quota-line config reset --yes # 跳过确认(脚本/CI 用)
|
|
195
|
+
```
|
|
108
196
|
|
|
109
|
-
-
|
|
110
|
-
-
|
|
111
|
-
-
|
|
197
|
+
- 默认重置范围:所有全局配置项(theme/display/style/work-days/minimalist/raw-values/reset-format/auth-token/base-url)、组件布局(lines)、自定义模型映射(modelMap)。
|
|
198
|
+
- `--models` 限定只清 modelMap,其它配置不动。
|
|
199
|
+
- 非交互环境(无 TTY)必须加 `--yes`,否则报错退出,避免误删。
|
|
200
|
+
- 重置后状态栏仍正常工作——模型映射会回退到包内默认表(`data/models.json`)。
|
|
112
201
|
|
|
113
202
|
### auth-token / base-url — 自定义鉴权
|
|
114
203
|
|
|
@@ -129,6 +218,54 @@ glm-quota-line config set base-url https://api.z.ai/api/anthropic
|
|
|
129
218
|
2. 环境变量 `ANTHROPIC_AUTH_TOKEN` / `ANTHROPIC_BASE_URL`
|
|
130
219
|
3. `~/.claude/settings.json` 中的 `env` 字段
|
|
131
220
|
|
|
221
|
+
### configure — 交互式 TUI 配置
|
|
222
|
+
|
|
223
|
+
启动终端交互界面,实时预览状态栏效果,逐项调整组件开关、样式和全局选项。
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
glm-quota-line configure
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
操作方式:
|
|
230
|
+
- `↑↓` 选择组件,`Enter` 进入编辑,`Tab` 切换样式,`Space` 开关显示
|
|
231
|
+
- `g` 进入全局选项(主题、显示模式、极简模式、原始数值、重置时间格式)
|
|
232
|
+
- `s` 保存,`q` 退出
|
|
233
|
+
|
|
234
|
+
组件列表:
|
|
235
|
+
|
|
236
|
+
| 组件 | 说明 | 可设置样式 | 可隐藏 |
|
|
237
|
+
|---|---|---|---|
|
|
238
|
+
| `level` | 套餐级别(如 GLM Lite) | — | ✓ |
|
|
239
|
+
| `5h` | 5 小时配额 | ✓ (bar/text) | —(必需) |
|
|
240
|
+
| `week` | 周配额 | ✓ (bar/text) | ✓ |
|
|
241
|
+
| `reset` | 重置时间 | — | ✓ |
|
|
242
|
+
| `ctx` | 上下文窗口用量 | ✓ (bar/text) | ✓ |
|
|
243
|
+
|
|
244
|
+
### model — 模型上下文窗口管理
|
|
245
|
+
|
|
246
|
+
管理模型的上下文窗口大小映射。上下文窗口用量百分比基于此映射计算。
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
glm-quota-line model list # 查看所有模型及其上下文窗口大小
|
|
250
|
+
glm-quota-line model get <model-id> # 查看指定模型的大小
|
|
251
|
+
glm-quota-line model set <model-id> <size> # 设置模型大小(如 300K 或 300000)
|
|
252
|
+
glm-quota-line model remove <model-id> # 移除自定义映射(内置模型恢复默认值)
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
`list` 输出示例:
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
glm-4.7 200K
|
|
259
|
+
glm-5.1 200K
|
|
260
|
+
glm-5.2 300K *
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
`*` 标记表示用户自定义的映射。
|
|
264
|
+
|
|
265
|
+
模型映射采用双层结构:包内 `data/models.json` 作为默认底层,`~/.claude/glm-quota-line.json` 里的 `modelMap` 作为用户覆盖层(运行时逐键覆盖)。**智谱发布新模型时,无需等待 npm 包更新——直接 `model set <新模型> <大小>` 写入本地覆盖层即可立刻生效。**
|
|
266
|
+
|
|
267
|
+
想清空所有自定义模型映射、回到包内默认表:执行 `glm-quota-line config reset --models --yes`。
|
|
268
|
+
|
|
132
269
|
## 推荐搭配
|
|
133
270
|
|
|
134
271
|
| 使用场景 | 配置 |
|
|
@@ -137,29 +274,68 @@ glm-quota-line config set base-url https://api.z.ai/api/anthropic
|
|
|
137
274
|
| 浅色终端 | `style=bar`, `theme=light` |
|
|
138
275
|
| 极简工作流 | `style=compact`, `theme=mono` |
|
|
139
276
|
| 关注已用量 | `style=bar`, `display=used` |
|
|
277
|
+
| 倒计时重置 | `reset-format=countdown` |
|
|
278
|
+
| 脚本调用 | `--json` |
|
|
279
|
+
| 6 天工作制 | `work-days=6` |
|
|
280
|
+
| 极简数值 | `minimalist=true` |
|
|
281
|
+
| 自定义模型 | `glm-quota-line model set glm-5.2 300K` |
|
|
282
|
+
| 交互式配置 | `glm-quota-line configure` |
|
|
140
283
|
|
|
141
284
|
## 命令参考
|
|
142
285
|
|
|
143
286
|
```bash
|
|
144
|
-
glm-quota-line [--style text|compact|bar] [--display left|used] [--theme dark|light|mono] [--
|
|
287
|
+
glm-quota-line [--style text|compact|bar] [--display left|used] [--theme dark|light|mono] [--json]
|
|
145
288
|
glm-quota-line install [--force]
|
|
146
289
|
glm-quota-line uninstall
|
|
147
290
|
glm-quota-line version
|
|
148
291
|
glm-quota-line check-update
|
|
292
|
+
glm-quota-line configure
|
|
149
293
|
glm-quota-line config show
|
|
150
|
-
glm-quota-line config set <style|display|theme|
|
|
294
|
+
glm-quota-line config set <style|display|theme|auth-token|base-url|work-days|minimalist|raw-values|reset-format> <value>
|
|
151
295
|
glm-quota-line config unset <key>
|
|
296
|
+
glm-quota-line config reset [--models] [--yes]
|
|
297
|
+
glm-quota-line model list
|
|
298
|
+
glm-quota-line model get <model-id>
|
|
299
|
+
glm-quota-line model set <model-id> <size>
|
|
300
|
+
glm-quota-line model remove <model-id>
|
|
152
301
|
```
|
|
153
302
|
|
|
154
303
|
运行 `glm-quota-line --help` 查看完整说明。
|
|
155
304
|
|
|
305
|
+
## 给 Agent / 自动化
|
|
306
|
+
|
|
307
|
+
如果你是 AI agent(Claude Code / Cursor / Codex)或脚本作者,以下接口保证稳定:
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
# 一次调用拿到所有命令的 machine-readable schema(name / summary / sideEffect / args / examples)
|
|
311
|
+
glm-quota-line commands --json
|
|
312
|
+
|
|
313
|
+
# 查看单个命令或命令组的聚焦帮助
|
|
314
|
+
glm-quota-line model --help
|
|
315
|
+
glm-quota-line config set --help
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
约定:
|
|
319
|
+
- **退出码**:成功 `0`,失败 `1`。
|
|
320
|
+
- **副作用标注**:每个命令标为 `read`(只读,自动化安全)、`write`(改配置/模型映射)、`mutating`(改 Claude Code 集成)、`interactive`(需 TTY)。
|
|
321
|
+
- **非阻塞**:所有命令都不会卡住等待输入(仅 `config reset` 在非交互环境需 `--yes`,`configure` 在非 TTY 时打印提示而非启动 TUI)。
|
|
322
|
+
- **只读查询**:`glm-quota-line --json` 输出结构化配额数据(5h/week/MCP + 重置时间)。
|
|
323
|
+
|
|
324
|
+
典型 agent 工作流:先 `commands --json` 了解能力 → 调用需要的命令 → 读取 stdout 解析结果。
|
|
325
|
+
|
|
156
326
|
## 说明
|
|
157
327
|
|
|
158
328
|
- 展示 `TOKENS_LIMIT` 配额和 `MCP_LIMIT` / `TIME_LIMIT` 配额
|
|
159
|
-
-
|
|
329
|
+
- 周配额进度条中的阴影(▒)是每日应耗基准线:根据已过工作日计算的理论预算,已用部分(█)超过阴影越多,说明消耗越快
|
|
330
|
+
- 状态栏默认显示上下文窗口用量和模型信息,可通过 `glm-quota-line configure` 交互式关闭
|
|
331
|
+
- 每个组件可单独控制开关和样式,通过 `glm-quota-line configure` 交互式调整
|
|
332
|
+
- 上下文窗口使用率优先从原始 token 数计算,当模型映射不可用时回退到 API 提供的百分比
|
|
333
|
+
- 模型上下文窗口大小可通过 `glm-quota-line model` 命令自定义,支持查看、设置、移除和批量导入
|
|
160
334
|
- 鉴权缺失返回 `GLM | auth expired`;接口异常返回 `GLM | quota unavailable`
|
|
335
|
+
- 非 GLM 提供商(非智谱 AI 端点)会自动禁用配额查询
|
|
161
336
|
- `install` 默认不会覆盖非本工具管理的状态栏,除非使用 `--force`
|
|
162
337
|
- `install --force` 会备份旧配置,`uninstall` 会在可能时恢复
|
|
338
|
+
- 设置 `GLM_QUOTA_DEBUG=1` 可输出上下文窗口调试信息到 stderr
|
|
163
339
|
|
|
164
340
|
## 许可证
|
|
165
341
|
|
package/data/models.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glm-quota-line",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Zhipu GLM Coding Plan quota monitor for Claude Code status line.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"z.ai",
|
|
14
14
|
"coding-plan",
|
|
15
15
|
"quota",
|
|
16
|
-
"statusline"
|
|
16
|
+
"statusline",
|
|
17
|
+
"tui"
|
|
17
18
|
],
|
|
18
19
|
"repository": {
|
|
19
20
|
"type": "git",
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
},
|
|
29
30
|
"files": [
|
|
30
31
|
"src",
|
|
32
|
+
"data",
|
|
31
33
|
"README.md",
|
|
32
34
|
"README.en.md",
|
|
33
35
|
"LICENSE",
|
|
@@ -3,7 +3,7 @@ import { resolveQuotaStatus } from "../core/quota/service.js";
|
|
|
3
3
|
import { readStatusLineInput } from "./input.js";
|
|
4
4
|
import { readToolConfig } from "./settings.js";
|
|
5
5
|
|
|
6
|
-
export const SESSION_START_MATCHERS = ["startup", "resume", "clear"];
|
|
6
|
+
export const SESSION_START_MATCHERS = ["startup", "resume", "clear", "compact"];
|
|
7
7
|
|
|
8
8
|
export async function refreshQuotaOnSessionStart(options = {}) {
|
|
9
9
|
const hookInput = await readStatusLineInput(options.stdin ?? process.stdin);
|