glm-quota-line 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.en.md +215 -177
- package/README.md +220 -183
- package/package.json +1 -1
- package/src/cli/commands.js +3 -1
- package/src/cli/registry.js +6 -4
- package/src/core/context/cache.js +5 -1
- package/src/core/context/index.js +0 -4
- package/src/core/context/models.js +0 -8
- package/src/core/quota/parse.js +3 -2
- package/src/core/quota/service.js +28 -2
- package/src/shared/constants.js +5 -1
- package/src/shared/migration.js +0 -7
- package/src/shared/utils.js +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.3.1
|
|
4
|
+
|
|
5
|
+
- Fixed "quota unavailable" on api.z.ai / open.bigmodel.cn: the quota endpoint now returns `{"code":200,...}` without a top-level `success` flag, which made every response parse as unavailable (#6)
|
|
6
|
+
- Added support for credit-based Coding Plans: their 5h/weekly windows are reported as `CREDIT_LIMIT` entries (`usage`/`currentValue`/`remaining`) instead of `TOKENS_LIMIT`, which previously produced no quotas (#6)
|
|
7
|
+
|
|
3
8
|
## 1.3.0
|
|
4
9
|
|
|
5
10
|
- Added `commands` subcommand: list every command with a machine-readable schema via `--json` (name / summary / sideEffect / args / examples), for AI agents and scripting
|
package/README.en.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<h1 align="center">glm-quota-line</h1>
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
A Zhipu GLM Coding Plan quota monitor built for Claude Code
|
|
4
|
+
A Zhipu GLM Coding Plan quota monitor built for Claude Code<br>
|
|
5
|
+
<strong>Focus on coding without switching windows to check your quota</strong>
|
|
5
6
|
</p>
|
|
6
7
|
|
|
7
8
|
<p align="center">
|
|
@@ -15,20 +16,25 @@
|
|
|
15
16
|
<a href="./README.md">简体中文</a>
|
|
16
17
|
</p>
|
|
17
18
|
|
|
18
|
-
##
|
|
19
|
+
## Core Value
|
|
19
20
|
|
|
20
|
-
|
|
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; 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
|
|
27
|
-
- **Smart caching** — tiered refresh by session, TTL, and token usage; `SessionStart` hook pre-refreshes so new sessions never show stale data
|
|
28
|
-
- **Domestic + international endpoints** — auto-detects `open.bigmodel.cn` and `api.z.ai`
|
|
29
|
-
- **Zero dependencies** — no runtime deps, single-purpose CLI
|
|
21
|
+
**Accurate data from official site** → **Real-time status bar display** → **Smart pacing alerts**
|
|
30
22
|
|
|
31
|
-
|
|
23
|
+
After installation, the quota appears automatically in the Claude Code status bar:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
GLM Lite █████████░ 91% | W ▒▒▒▒░░░░░ 47% 11:10 | 14:47 | ctx ███░░░ 45% (glm-4.7/200K)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**See at a glance**:
|
|
30
|
+
- Plan remaining quota (91%) with progress bar
|
|
31
|
+
- Weekly quota consumption (47%) + theoretical budget shadow (▒)
|
|
32
|
+
- Time until reset (14:47)
|
|
33
|
+
- Context window usage (45%)
|
|
34
|
+
|
|
35
|
+
Auto-color alerts when pacing exceeds budget, preventing workflow interruption.
|
|
36
|
+
|
|
37
|
+
## 30-Second Quick Start
|
|
32
38
|
|
|
33
39
|
**One-time query (no install needed):**
|
|
34
40
|
|
|
@@ -36,20 +42,14 @@
|
|
|
36
42
|
npx glm-quota-line
|
|
37
43
|
```
|
|
38
44
|
|
|
39
|
-
**Status line integration (
|
|
45
|
+
**Status line integration (recommended):**
|
|
40
46
|
|
|
41
47
|
```bash
|
|
42
48
|
npm install -g glm-quota-line
|
|
43
49
|
glm-quota-line install
|
|
44
50
|
```
|
|
45
51
|
|
|
46
|
-
Done.
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
GLM Lite █████████░ 91% | W ▒▒▒▒░░░░░ 47% | 14:47 | ctx ███░░░ 45% (glm-4.7/200K)
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
You can also run `glm-quota-line` directly in the terminal to check your quota without launching Claude Code.
|
|
52
|
+
Done. You can run `glm-quota-line` anytime in the terminal to check usage without launching Claude Code.
|
|
53
53
|
|
|
54
54
|
Upgrade:
|
|
55
55
|
|
|
@@ -58,88 +58,41 @@ npm install -g glm-quota-line
|
|
|
58
58
|
glm-quota-line check-update
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
##
|
|
62
|
-
|
|
63
|
-
All options are optional. Persist with `glm-quota-line config set`, or override per-invocation with CLI flags.
|
|
64
|
-
|
|
65
|
-
### style — Output layout
|
|
66
|
-
|
|
67
|
-
| Value | Description | Example |
|
|
68
|
-
|---|---|---|
|
|
69
|
-
| `bar` (default) | Progress bar | `GLM Lite █████████░ 91% \| W ▒▒▒▒░░░░░ 47% \| 14:47 \| ctx ███░░░ 45%` |
|
|
70
|
-
| `text` | Full text | `GLM Lite \| 5h 91% \| week 47% \| reset 14:47 \| ctx 45%` |
|
|
71
|
-
| `compact` | Compact mode | `GLM 5h 91% W 47% \| 14:47` |
|
|
72
|
-
|
|
73
|
-
```bash
|
|
74
|
-
glm-quota-line config set style compact
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### theme — Color theme
|
|
61
|
+
## Common Workflows
|
|
78
62
|
|
|
79
|
-
|
|
80
|
-
|---|---|
|
|
81
|
-
| `dark` (default) | Dark terminal, light pine-green accents |
|
|
82
|
-
| `light` | White/light terminal, teal-blue accents |
|
|
83
|
-
| `mono` | Grayscale, minimal distraction |
|
|
63
|
+
### 📊 Quick quota check
|
|
84
64
|
|
|
85
65
|
```bash
|
|
86
|
-
glm-quota-line
|
|
66
|
+
glm-quota-line
|
|
87
67
|
```
|
|
88
68
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
- Green — remaining >= 60%
|
|
92
|
-
- Yellow — remaining 30%–60%
|
|
93
|
-
- Red — remaining < 30%
|
|
69
|
+
### 🎨 Customize status bar style
|
|
94
70
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
| Value | Description |
|
|
98
|
-
|---|---|
|
|
99
|
-
| `left` (default) | Show remaining quota (bar fills with remaining) |
|
|
100
|
-
| `used` | Show used quota (bar fills with used) |
|
|
71
|
+
**Recommended**: Use interactive configuration with live preview
|
|
101
72
|
|
|
102
73
|
```bash
|
|
103
|
-
glm-quota-line
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### work-days — Work days per week
|
|
107
|
-
|
|
108
|
-
Set the number of work days per week (1–7) for weekly quota theoretical budget and pacing analysis. Default: 5.
|
|
109
|
-
|
|
110
|
-
```bash
|
|
111
|
-
glm-quota-line config set work-days 6
|
|
74
|
+
glm-quota-line configure
|
|
112
75
|
```
|
|
113
76
|
|
|
114
|
-
|
|
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.
|
|
77
|
+
For manual configuration, see [Quick Customization](#quick-customization)
|
|
122
78
|
|
|
123
|
-
|
|
124
|
-
|---|---|---|
|
|
125
|
-
| `time` (default) | Show the reset time point | `reset 14:47` |
|
|
126
|
-
| `countdown` | Show the remaining countdown | `reset 52m` / `reset 2d 5h` |
|
|
79
|
+
### 🤖 Change model or adjust context window
|
|
127
80
|
|
|
128
81
|
```bash
|
|
129
|
-
|
|
82
|
+
# When Zhipu releases a new model, no need to wait for npm updates — write the local overlay immediately:
|
|
83
|
+
glm-quota-line model set glm-5.3 400K
|
|
84
|
+
# View all models and their context window sizes
|
|
85
|
+
glm-quota-line model list
|
|
130
86
|
```
|
|
131
87
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
### --json — JSON output
|
|
135
|
-
|
|
136
|
-
Output structured JSON format (terminal mode only, ignored in status line mode):
|
|
88
|
+
### 🔧 Script integration
|
|
137
89
|
|
|
138
90
|
```bash
|
|
139
91
|
glm-quota-line --json
|
|
140
92
|
```
|
|
141
93
|
|
|
142
|
-
|
|
94
|
+
Outputs structured JSON data:
|
|
95
|
+
|
|
143
96
|
```json
|
|
144
97
|
{
|
|
145
98
|
"level": "Lite",
|
|
@@ -149,12 +102,6 @@ Example output:
|
|
|
149
102
|
"leftPercent": 91,
|
|
150
103
|
"usedPercent": 9,
|
|
151
104
|
"nextResetTime": 1715257200000
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
"label": "week",
|
|
155
|
-
"leftPercent": 47,
|
|
156
|
-
"usedPercent": 53,
|
|
157
|
-
"nextResetTime": 1715744400000
|
|
158
105
|
}
|
|
159
106
|
],
|
|
160
107
|
"mcp": {
|
|
@@ -164,29 +111,83 @@ Example output:
|
|
|
164
111
|
}
|
|
165
112
|
```
|
|
166
113
|
|
|
167
|
-
###
|
|
114
|
+
### ⚠️ Quota exhausted or display issues
|
|
115
|
+
|
|
116
|
+
See [Troubleshooting](#troubleshooting)
|
|
117
|
+
|
|
118
|
+
## Quick Customization
|
|
119
|
+
|
|
120
|
+
### Recommended: Interactive configuration
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
glm-quota-line configure # Live preview, WYSIWYG
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Key bindings**:
|
|
127
|
+
- `↑↓` select component, `Enter` to edit, `Tab` to cycle style, `Space` to toggle
|
|
128
|
+
- `g` for global options (theme, display mode, minimalist, raw-values, reset format)
|
|
129
|
+
- `s` to save, `q` to quit
|
|
130
|
+
|
|
131
|
+
### Common config (non-interactive)
|
|
132
|
+
|
|
133
|
+
#### Style & theme
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
glm-quota-line config set style compact # Compact mode
|
|
137
|
+
glm-quota-line config set theme light # Light theme
|
|
138
|
+
glm-quota-line config set theme mono # Grayscale minimal
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Style comparison**:
|
|
142
|
+
|
|
143
|
+
| Style | Description | Example |
|
|
144
|
+
|---|---|---|
|
|
145
|
+
| `bar` (default) | Progress bar | `GLM Lite █████████░ 91% \| W ▒▒▒▒░░░░░ 47% 11:10 \| 14:47 \| ctx ███░░░ 45%` |
|
|
146
|
+
| `text` | Full text | `GLM Lite \| 5h 91% \| week 47% 11:10 \| reset 14:47 \| ctx 45%` |
|
|
147
|
+
| `compact` | Compact mode | `GLM 5h 91% W 47% 11:10 \| 14:47` |
|
|
168
148
|
|
|
169
|
-
|
|
149
|
+
#### Display options
|
|
170
150
|
|
|
171
151
|
```bash
|
|
172
|
-
glm-quota-line config set
|
|
152
|
+
glm-quota-line config set display used # Show used instead of remaining
|
|
153
|
+
glm-quota-line config set reset-format countdown # Countdown mode (e.g., reset 52m)
|
|
154
|
+
glm-quota-line config set minimalist true # Hide label text
|
|
173
155
|
```
|
|
174
156
|
|
|
175
|
-
|
|
176
|
-
- Off: `GLM Lite █████████░ 91% | W ▒▒▒▒░░░░░ 47% | 14:47`
|
|
177
|
-
- On: `█████████░ 91% | ▒▒▒▒░░░░░ 47% | 14:47`
|
|
157
|
+
**Color logic**:
|
|
178
158
|
|
|
179
|
-
|
|
159
|
+
Quota percentage auto-colors based on remaining amount:
|
|
160
|
+
- 🟢 Green — remaining >= 60%
|
|
161
|
+
- 🟡 Yellow — remaining 30%–60%
|
|
162
|
+
- 🔴 Red — remaining < 30%
|
|
180
163
|
|
|
181
|
-
|
|
164
|
+
Pacing analysis auto-colors based on usage speed:
|
|
165
|
+
- 🟢 Green — usage speed ≤ 1.1x theoretical
|
|
166
|
+
- 🟡 Yellow — usage speed 1.1x–1.3x theoretical
|
|
167
|
+
- 🔴 Red — usage speed > 1.3x theoretical
|
|
168
|
+
|
|
169
|
+
<details>
|
|
170
|
+
<summary><b>Advanced configuration options</b> (click to expand)</summary>
|
|
171
|
+
|
|
172
|
+
### Work days setting
|
|
173
|
+
|
|
174
|
+
Set the number of work days per week (1–7) for weekly quota theoretical budget and pacing analysis. Default: 5.
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
glm-quota-line config set work-days 6
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Raw values mode
|
|
181
|
+
|
|
182
|
+
Display raw values directly, without percentages.
|
|
182
183
|
|
|
183
184
|
```bash
|
|
184
185
|
glm-quota-line config set raw-values true
|
|
185
186
|
```
|
|
186
187
|
|
|
187
|
-
###
|
|
188
|
+
### Custom authentication
|
|
188
189
|
|
|
189
|
-
If Claude Code runs behind a gateway or proxy
|
|
190
|
+
If Claude Code runs behind a gateway or proxy, you can override auth credentials:
|
|
190
191
|
|
|
191
192
|
```bash
|
|
192
193
|
glm-quota-line config set auth-token <your-real-token>
|
|
@@ -197,41 +198,91 @@ glm-quota-line config set base-url https://api.z.ai/api/anthropic
|
|
|
197
198
|
|
|
198
199
|
Clear with `glm-quota-line config unset auth-token` / `base-url`.
|
|
199
200
|
|
|
200
|
-
Auth
|
|
201
|
-
|
|
201
|
+
**Auth priority** (highest to lowest):
|
|
202
202
|
1. Values persisted via `config set`
|
|
203
203
|
2. Environment variables `ANTHROPIC_AUTH_TOKEN` / `ANTHROPIC_BASE_URL`
|
|
204
204
|
3. `env` field in `~/.claude/settings.json`
|
|
205
205
|
|
|
206
|
-
### reset
|
|
206
|
+
### Factory reset
|
|
207
207
|
|
|
208
|
-
One-shot reset of user config. Install state is preserved (status line
|
|
208
|
+
One-shot reset of user config. Install state is preserved (status line/hook not removed).
|
|
209
209
|
|
|
210
210
|
```bash
|
|
211
|
-
glm-quota-line config reset #
|
|
212
|
-
glm-quota-line config reset --models #
|
|
213
|
-
glm-quota-line config reset --yes #
|
|
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
214
|
```
|
|
215
215
|
|
|
216
|
-
- Default scope: all global config
|
|
217
|
-
- `--models` limits
|
|
218
|
-
-
|
|
219
|
-
- After reset
|
|
216
|
+
- Default scope: all global config, component layout, custom model mappings
|
|
217
|
+
- `--models` limits reset to modelMap only; other config untouched
|
|
218
|
+
- Non-interactive sessions (no TTY) require `--yes` or error out
|
|
219
|
+
- After reset, status line still works — model mappings fall back to bundled defaults
|
|
220
220
|
|
|
221
|
-
|
|
221
|
+
</details>
|
|
222
222
|
|
|
223
|
-
|
|
223
|
+
## Advanced Features
|
|
224
|
+
|
|
225
|
+
<details>
|
|
226
|
+
<summary><b>Model mapping management</b> (new model support)</summary>
|
|
227
|
+
|
|
228
|
+
Manage context window size mapping per model. Context window usage percentage is computed from this mapping.
|
|
224
229
|
|
|
225
230
|
```bash
|
|
226
|
-
glm-quota-line
|
|
231
|
+
glm-quota-line model list # List all models and their context window size
|
|
232
|
+
glm-quota-line model get <model-id> # Show the size of a given model
|
|
233
|
+
glm-quota-line model set <model-id> <size> # Set model size (e.g., 300K or 300000)
|
|
234
|
+
glm-quota-line model remove <model-id> # Remove custom mapping (built-in reverts to default)
|
|
227
235
|
```
|
|
228
236
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
-
|
|
237
|
+
**Example `list` output**:
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
glm-4.5-air 128K
|
|
241
|
+
glm-4.7 200K
|
|
242
|
+
glm-5-turbo 200K
|
|
243
|
+
glm-5.2 1M *
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
The `*` marker indicates a user-configured mapping.
|
|
247
|
+
|
|
248
|
+
**Two-layer design**:
|
|
249
|
+
- Bundled `data/models.json` as default base
|
|
250
|
+
- `modelMap` in `~/.claude/glm-quota-line.json` as user overlay (merged key-by-key at runtime)
|
|
251
|
+
|
|
252
|
+
**Advantage**: When Zhipu releases a new model, no need to wait for npm package updates — just run `model set <new-model> <size>` to write the local overlay and it takes effect immediately.
|
|
253
|
+
|
|
254
|
+
To clear all custom model mappings and return to bundled defaults: `glm-quota-line config reset --models --yes`.
|
|
255
|
+
|
|
256
|
+
</details>
|
|
257
|
+
|
|
258
|
+
<details>
|
|
259
|
+
<summary><b>Agent / Automation interface</b></summary>
|
|
260
|
+
|
|
261
|
+
If you are an AI agent (Claude Code / Cursor / Codex) or script author, the following interface is guaranteed stable:
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
# Get full machine-readable schema of all commands in one call
|
|
265
|
+
glm-quota-line commands --json
|
|
266
|
+
|
|
267
|
+
# Focused help for a single command or command group
|
|
268
|
+
glm-quota-line model --help
|
|
269
|
+
glm-quota-line config set --help
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
**Conventions**:
|
|
273
|
+
- **Exit codes**: `0` on success, `1` on error
|
|
274
|
+
- **Side-effect tags**: Each command tagged `read` (safe for automation), `write` (persists config/model map), `mutating` (modifies Claude Code integration), or `interactive` (requires TTY)
|
|
275
|
+
- **Non-blocking**: No command blocks waiting for input
|
|
276
|
+
- **Read query**: `glm-quota-line --json` emits structured quota data
|
|
277
|
+
|
|
278
|
+
Typical agent workflow: Run `commands --json` to discover capabilities → invoke command → parse stdout.
|
|
233
279
|
|
|
234
|
-
|
|
280
|
+
</details>
|
|
281
|
+
|
|
282
|
+
<details>
|
|
283
|
+
<summary><b>Component-level control</b></summary>
|
|
284
|
+
|
|
285
|
+
Through component mode in `glm-quota-line configure`, each display component can be individually toggled and styled. See [Quick Customization](#quick-customization) for key bindings; component capabilities:
|
|
235
286
|
|
|
236
287
|
| Component | Description | Styleable | Hideable |
|
|
237
288
|
|---|---|---|---|
|
|
@@ -241,45 +292,55 @@ Components:
|
|
|
241
292
|
| `reset` | Reset time | — | ✓ |
|
|
242
293
|
| `ctx` | Context window usage | ✓ (bar/text) | ✓ |
|
|
243
294
|
|
|
244
|
-
|
|
295
|
+
</details>
|
|
296
|
+
|
|
297
|
+
## Troubleshooting
|
|
298
|
+
|
|
299
|
+
### Quota not displaying
|
|
245
300
|
|
|
246
|
-
|
|
301
|
+
**Possible causes**:
|
|
302
|
+
1. Auth info missing or expired
|
|
303
|
+
2. Non-GLM provider (endpoint not `open.bigmodel.cn` or `api.z.ai`)
|
|
304
|
+
3. Network connection issues
|
|
247
305
|
|
|
306
|
+
**Solutions**:
|
|
248
307
|
```bash
|
|
249
|
-
|
|
250
|
-
glm-quota-line
|
|
251
|
-
|
|
252
|
-
|
|
308
|
+
# Check auth status
|
|
309
|
+
glm-quota-line
|
|
310
|
+
|
|
311
|
+
# If shows "auth expired", update auth info
|
|
312
|
+
glm-quota-line config set auth-token <your-token>
|
|
313
|
+
glm-quota-line config set base-url https://open.bigmodel.cn/api/anthropic
|
|
253
314
|
```
|
|
254
315
|
|
|
255
|
-
|
|
316
|
+
### Shows "quota unavailable"
|
|
256
317
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
glm-5.2 300K *
|
|
261
|
-
```
|
|
318
|
+
**Possible causes**:
|
|
319
|
+
- Zhipu API interface issues
|
|
320
|
+
- Network connection problems
|
|
262
321
|
|
|
263
|
-
|
|
322
|
+
**Solutions**:
|
|
323
|
+
- Retry later (tool auto-retries)
|
|
324
|
+
- Check network connection
|
|
325
|
+
- If persistent, may be Zhipu service issues
|
|
264
326
|
|
|
265
|
-
|
|
327
|
+
### Install/uninstall issues
|
|
266
328
|
|
|
267
|
-
|
|
329
|
+
**Status bar not updating**:
|
|
330
|
+
```bash
|
|
331
|
+
glm-quota-line uninstall
|
|
332
|
+
glm-quota-line install --force
|
|
333
|
+
```
|
|
268
334
|
|
|
269
|
-
|
|
335
|
+
`install --force` backs up previous config; `uninstall` restores when possible.
|
|
270
336
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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` |
|
|
337
|
+
### Debug mode
|
|
338
|
+
|
|
339
|
+
Set `GLM_QUOTA_DEBUG=1` to output context window debug info to stderr:
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
GLM_QUOTA_DEBUG=1 glm-quota-line
|
|
343
|
+
```
|
|
283
344
|
|
|
284
345
|
## Command Reference
|
|
285
346
|
|
|
@@ -298,43 +359,20 @@ glm-quota-line model list
|
|
|
298
359
|
glm-quota-line model get <model-id>
|
|
299
360
|
glm-quota-line model set <model-id> <size>
|
|
300
361
|
glm-quota-line model remove <model-id>
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
Run `glm-quota-line --help` for full descriptions.
|
|
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
362
|
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
363
|
```
|
|
318
364
|
|
|
319
|
-
|
|
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.
|
|
365
|
+
Run `glm-quota-line --help` for full descriptions.
|
|
326
366
|
|
|
327
|
-
## Notes
|
|
367
|
+
## Technical Notes
|
|
328
368
|
|
|
329
369
|
- Shows `TOKENS_LIMIT` and `MCP_LIMIT` / `TIME_LIMIT` quotas
|
|
330
|
-
- Weekly quota progress bar shadow (▒) is
|
|
331
|
-
- Context window usage
|
|
332
|
-
-
|
|
333
|
-
-
|
|
334
|
-
-
|
|
335
|
-
-
|
|
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
|
|
370
|
+
- Weekly quota progress bar shadow (▒) is the daily pacing baseline: theoretical budget based on elapsed work days
|
|
371
|
+
- Context window usage computed from raw tokens using local model map; falls back to API-provided percentage when mapping unavailable
|
|
372
|
+
- Smart caching: tiered refresh by session, TTL, and token usage; `SessionStart` hook pre-refreshes so new sessions never show stale data
|
|
373
|
+
- Auto-detects domestic (`open.bigmodel.cn`) and international (`api.z.ai`) endpoints
|
|
374
|
+
- Non-GLM providers automatically disable quota queries
|
|
375
|
+
- Zero runtime dependencies
|
|
338
376
|
|
|
339
377
|
## License
|
|
340
378
|
|
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<h1 align="center">glm-quota-line</h1>
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
为 Claude Code 打造的智谱 GLM Coding Plan
|
|
4
|
+
为 Claude Code 打造的智谱 GLM Coding Plan 配额监控工具<br>
|
|
5
|
+
<strong>让你专注编码而不用频繁切换窗口检查配额</strong>
|
|
5
6
|
</p>
|
|
6
7
|
|
|
7
8
|
<p align="center">
|
|
@@ -15,20 +16,25 @@
|
|
|
15
16
|
<a href="./README.en.md">English</a>
|
|
16
17
|
</p>
|
|
17
18
|
|
|
18
|
-
##
|
|
19
|
+
## 核心价值
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
- **Claude Code 状态栏** — 安装后自动嵌入状态栏,实时显示配额余额、重置时间和上下文窗口用量
|
|
22
|
-
- **进度条可视化** — 默认 bar 风格,一眼看清剩余比例;周配额显示理论预算阴影
|
|
23
|
-
- **智能配速分析** — 根据工作日和已过时间计算配额使用速度,超速时自动变色警示
|
|
24
|
-
- **JSON 输出** — 支持 `--json` 参数输出结构化数据,便于脚本调用
|
|
25
|
-
- **交互式配置** — `glm-quota-line configure` 启动 TUI 界面,实时预览、逐项调整组件开关与样式
|
|
26
|
-
- **组件级控制** — 每个显示组件(套餐、5h、周、重置、上下文)可单独开关和设置样式
|
|
27
|
-
- **智能缓存** — 按会话、TTL 和 token 用量分级刷新;`SessionStart` hook 预刷新,新会话不显示旧数据
|
|
28
|
-
- **国内 + 国际端点** — 自动识别 `open.bigmodel.cn` 和 `api.z.ai`
|
|
29
|
-
- **零依赖** — 无运行时依赖,单一用途
|
|
21
|
+
**数据精准同步官网** → **状态栏实时显示** → **智能配速警示**
|
|
30
22
|
|
|
31
|
-
|
|
23
|
+
安装后,Claude Code 底部状态栏会自动显示配额:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
GLM Lite █████████░ 91% | W ▒▒▒▒░░░░░ 47% 11:10 | 14:47 | ctx ███░░░ 45% (glm-4.7/200K)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**一眼看清**:
|
|
30
|
+
- 套餐剩余量(91%)和进度条
|
|
31
|
+
- 周配额消耗情况(47%)+ 理论预算阴影(▒)
|
|
32
|
+
- 距离重置时间(14:47)
|
|
33
|
+
- 上下文窗口用量(45%)
|
|
34
|
+
|
|
35
|
+
超速时自动变色警示,避免配额耗尽中断工作流。
|
|
36
|
+
|
|
37
|
+
## 30 秒快速开始
|
|
32
38
|
|
|
33
39
|
**一次性查询(无需安装):**
|
|
34
40
|
|
|
@@ -36,20 +42,14 @@
|
|
|
36
42
|
npx glm-quota-line
|
|
37
43
|
```
|
|
38
44
|
|
|
39
|
-
|
|
45
|
+
**状态栏集成(推荐):**
|
|
40
46
|
|
|
41
47
|
```bash
|
|
42
48
|
npm install -g glm-quota-line
|
|
43
49
|
glm-quota-line install
|
|
44
50
|
```
|
|
45
51
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
GLM Lite █████████░ 91% | W ▒▒▒▒░░░░░ 47% 11:10 | 14:47 | ctx ███░░░ 45% (glm-4.7/200K)
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
也可以直接在终端运行 `glm-quota-line` 快速查看用量,无需启动 Claude Code。
|
|
52
|
+
安装完成。可以随时在终端运行 `glm-quota-line` 快速查看用量,无需启动 Claude Code。
|
|
53
53
|
|
|
54
54
|
升级版本:
|
|
55
55
|
|
|
@@ -58,150 +58,136 @@ npm install -g glm-quota-line
|
|
|
58
58
|
glm-quota-line check-update
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
##
|
|
62
|
-
|
|
63
|
-
所有配置均为可选,按需调整。通过 `glm-quota-line config set` 持久化,或用 CLI 参数临时覆盖。
|
|
61
|
+
## 常见工作流
|
|
64
62
|
|
|
65
|
-
###
|
|
66
|
-
|
|
67
|
-
| 值 | 说明 | 示例 |
|
|
68
|
-
|---|---|---|
|
|
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` |
|
|
63
|
+
### 📊 我想快速查看配额
|
|
72
64
|
|
|
73
65
|
```bash
|
|
74
|
-
glm-quota-line
|
|
66
|
+
glm-quota-line
|
|
75
67
|
```
|
|
76
68
|
|
|
77
|
-
###
|
|
69
|
+
### 🎨 我想定制状态栏样式
|
|
78
70
|
|
|
79
|
-
|
|
80
|
-
|---|---|
|
|
81
|
-
| `dark`(默认) | 深色终端,浅松绿配色 |
|
|
82
|
-
| `light` | 浅色/白色终端,天青蓝配色 |
|
|
83
|
-
| `mono` | 灰阶,极简低干扰 |
|
|
71
|
+
**推荐方式**:使用交互式配置(实时预览效果)
|
|
84
72
|
|
|
85
73
|
```bash
|
|
86
|
-
glm-quota-line
|
|
74
|
+
glm-quota-line configure
|
|
87
75
|
```
|
|
88
76
|
|
|
89
|
-
|
|
77
|
+
手动配置参见[快速定制](#快速定制)
|
|
90
78
|
|
|
91
|
-
|
|
92
|
-
- 黄色 — 剩余 30%–60%
|
|
93
|
-
- 红色 — 剩余 < 30%
|
|
79
|
+
### 🤖 我想更换模型或调整上下文窗口
|
|
94
80
|
|
|
95
|
-
|
|
81
|
+
```bash
|
|
82
|
+
# 智谱发布新模型时,无需等 npm 更新,立即写入本地覆盖:
|
|
83
|
+
glm-quota-line model set glm-5.3 400K
|
|
84
|
+
# 查看当前所有模型及其上下文窗口
|
|
85
|
+
glm-quota-line model list
|
|
86
|
+
```
|
|
96
87
|
|
|
97
|
-
|
|
98
|
-
|---|---|
|
|
99
|
-
| `left`(默认) | 显示剩余量(进度条填充 = 剩余比例) |
|
|
100
|
-
| `used` | 显示已用量(进度条填充 = 已用比例) |
|
|
88
|
+
### 🔧 我想在脚本中调用
|
|
101
89
|
|
|
102
90
|
```bash
|
|
103
|
-
glm-quota-line
|
|
91
|
+
glm-quota-line --json
|
|
104
92
|
```
|
|
105
93
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
设置每周工作日数量(1-7),用于计算周配额的理论预算和配速分析。默认 5 天。
|
|
94
|
+
输出结构化 JSON 数据:
|
|
109
95
|
|
|
110
|
-
```
|
|
111
|
-
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"level": "Lite",
|
|
99
|
+
"quotas": [
|
|
100
|
+
{
|
|
101
|
+
"label": "5h",
|
|
102
|
+
"leftPercent": 91,
|
|
103
|
+
"usedPercent": 9,
|
|
104
|
+
"nextResetTime": 1715257200000
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
"mcp": {
|
|
108
|
+
"leftPercent": 85,
|
|
109
|
+
"usedPercent": 15
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
- 红色 — 使用速度 > 1.3x 理论值
|
|
114
|
+
### ⚠️ 配额用完了或显示异常
|
|
115
|
+
|
|
116
|
+
参见[故障排查](#故障排查)
|
|
118
117
|
|
|
119
|
-
|
|
118
|
+
## 快速定制
|
|
120
119
|
|
|
121
|
-
|
|
120
|
+
### 推荐方式:交互式配置
|
|
122
121
|
|
|
123
122
|
```bash
|
|
124
|
-
glm-quota-line
|
|
123
|
+
glm-quota-line configure # 实时预览,所见即所得
|
|
125
124
|
```
|
|
126
125
|
|
|
127
|
-
|
|
128
|
-
-
|
|
129
|
-
-
|
|
126
|
+
**操作方式**:
|
|
127
|
+
- `↑↓` 选择组件,`Enter` 进入编辑,`Tab` 切换样式,`Space` 开关显示
|
|
128
|
+
- `g` 进入全局选项(主题、显示模式、极简模式、原始数值、重置时间格式)
|
|
129
|
+
- `s` 保存,`q` 退出
|
|
130
130
|
|
|
131
|
-
###
|
|
131
|
+
### 常用配置(非交互式)
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
#### 风格主题
|
|
134
134
|
|
|
135
135
|
```bash
|
|
136
|
-
glm-quota-line config set
|
|
136
|
+
glm-quota-line config set style compact # 紧凑模式
|
|
137
|
+
glm-quota-line config set theme light # 浅色主题
|
|
138
|
+
glm-quota-line config set theme mono # 灰阶极简
|
|
137
139
|
```
|
|
138
140
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
控制状态栏中重置时间的显示格式。
|
|
141
|
+
**风格对比**:
|
|
142
142
|
|
|
143
|
-
|
|
|
143
|
+
| 风格 | 说明 | 示例 |
|
|
144
144
|
|---|---|---|
|
|
145
|
-
| `
|
|
146
|
-
| `
|
|
145
|
+
| `bar`(默认) | 进度条可视化 | `GLM Lite █████████░ 91% \| W ▒▒▒▒░░░░░ 47% 11:10 \| 14:47 \| ctx ███░░░ 45%` |
|
|
146
|
+
| `text` | 完整文本 | `GLM Lite \| 5h 91% \| week 47% 11:10 \| reset 14:47 \| ctx 45%` |
|
|
147
|
+
| `compact` | 紧凑模式 | `GLM 5h 91% W 47% 11:10 \| 14:47` |
|
|
148
|
+
|
|
149
|
+
#### 显示内容
|
|
147
150
|
|
|
148
151
|
```bash
|
|
149
|
-
glm-quota-line config set
|
|
152
|
+
glm-quota-line config set display used # 显示已用量而非剩余量
|
|
153
|
+
glm-quota-line config set reset-format countdown # 倒计时模式(如 reset 52m)
|
|
154
|
+
glm-quota-line config set minimalist true # 极简模式(隐藏标签文字)
|
|
150
155
|
```
|
|
151
156
|
|
|
152
|
-
|
|
157
|
+
**配色逻辑**:
|
|
153
158
|
|
|
154
|
-
|
|
159
|
+
配额百分比会根据剩余量自动变色:
|
|
160
|
+
- 🟢 绿色 — 剩余 >= 60%
|
|
161
|
+
- 🟡 黄色 — 剩余 30%–60%
|
|
162
|
+
- 🔴 红色 — 剩余 < 30%
|
|
155
163
|
|
|
156
|
-
|
|
164
|
+
配速分析会根据使用速度变色:
|
|
165
|
+
- 🟢 绿色 — 使用速度 ≤ 1.1x 理论值
|
|
166
|
+
- 🟡 黄色 — 使用速度 1.1x–1.3x 理论值
|
|
167
|
+
- 🔴 红色 — 使用速度 > 1.3x 理论值
|
|
157
168
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
```
|
|
169
|
+
<details>
|
|
170
|
+
<summary><b>高级配置选项</b>(点击展开)</summary>
|
|
161
171
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
}
|
|
172
|
+
### 工作日设置
|
|
173
|
+
|
|
174
|
+
设置每周工作日数量(1-7),用于计算周配额的理论预算和配速分析。默认 5 天。
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
glm-quota-line config set work-days 6
|
|
185
178
|
```
|
|
186
179
|
|
|
187
|
-
###
|
|
180
|
+
### 原始数值模式
|
|
188
181
|
|
|
189
|
-
|
|
182
|
+
直接显示原始数值,不显示百分比。
|
|
190
183
|
|
|
191
184
|
```bash
|
|
192
|
-
glm-quota-line config
|
|
193
|
-
glm-quota-line config reset --models # 只清空自定义模型映射(modelMap)
|
|
194
|
-
glm-quota-line config reset --yes # 跳过确认(脚本/CI 用)
|
|
185
|
+
glm-quota-line config set raw-values true
|
|
195
186
|
```
|
|
196
187
|
|
|
197
|
-
|
|
198
|
-
- `--models` 限定只清 modelMap,其它配置不动。
|
|
199
|
-
- 非交互环境(无 TTY)必须加 `--yes`,否则报错退出,避免误删。
|
|
200
|
-
- 重置后状态栏仍正常工作——模型映射会回退到包内默认表(`data/models.json`)。
|
|
201
|
-
|
|
202
|
-
### auth-token / base-url — 自定义鉴权
|
|
188
|
+
### 自定义鉴权
|
|
203
189
|
|
|
204
|
-
当 Claude Code
|
|
190
|
+
当 Claude Code 运行在代理或网关后面时,可手动覆盖鉴权信息:
|
|
205
191
|
|
|
206
192
|
```bash
|
|
207
193
|
glm-quota-line config set auth-token <your-real-token>
|
|
@@ -212,36 +198,32 @@ glm-quota-line config set base-url https://api.z.ai/api/anthropic
|
|
|
212
198
|
|
|
213
199
|
清除:`glm-quota-line config unset auth-token` / `base-url`。
|
|
214
200
|
|
|
215
|
-
|
|
216
|
-
|
|
201
|
+
**鉴权优先级**(从高到低):
|
|
217
202
|
1. `config set` 持久化的值
|
|
218
203
|
2. 环境变量 `ANTHROPIC_AUTH_TOKEN` / `ANTHROPIC_BASE_URL`
|
|
219
204
|
3. `~/.claude/settings.json` 中的 `env` 字段
|
|
220
205
|
|
|
221
|
-
###
|
|
206
|
+
### 恢复出厂配置
|
|
222
207
|
|
|
223
|
-
|
|
208
|
+
一键重置用户配置,保留安装状态(不卸载状态栏/hook)。
|
|
224
209
|
|
|
225
210
|
```bash
|
|
226
|
-
glm-quota-line
|
|
211
|
+
glm-quota-line config reset # 交互确认后重置全部用户配置
|
|
212
|
+
glm-quota-line config reset --models # 只清空自定义模型映射(modelMap)
|
|
213
|
+
glm-quota-line config reset --yes # 跳过确认(脚本/CI 用)
|
|
227
214
|
```
|
|
228
215
|
|
|
229
|
-
|
|
230
|
-
-
|
|
231
|
-
-
|
|
232
|
-
-
|
|
216
|
+
- 默认重置范围:所有全局配置项、组件布局、自定义模型映射
|
|
217
|
+
- `--models` 限定只清 modelMap,其它配置不动
|
|
218
|
+
- 非交互环境(无 TTY)必须加 `--yes`,否则报错退出
|
|
219
|
+
- 重置后状态栏仍正常工作——模型映射会回退到包内默认表
|
|
233
220
|
|
|
234
|
-
|
|
221
|
+
</details>
|
|
235
222
|
|
|
236
|
-
|
|
237
|
-
|---|---|---|---|
|
|
238
|
-
| `level` | 套餐级别(如 GLM Lite) | — | ✓ |
|
|
239
|
-
| `5h` | 5 小时配额 | ✓ (bar/text) | —(必需) |
|
|
240
|
-
| `week` | 周配额 | ✓ (bar/text) | ✓ |
|
|
241
|
-
| `reset` | 重置时间 | — | ✓ |
|
|
242
|
-
| `ctx` | 上下文窗口用量 | ✓ (bar/text) | ✓ |
|
|
223
|
+
## 高级功能
|
|
243
224
|
|
|
244
|
-
|
|
225
|
+
<details>
|
|
226
|
+
<summary><b>模型映射管理</b>(新模型支持)</summary>
|
|
245
227
|
|
|
246
228
|
管理模型的上下文窗口大小映射。上下文窗口用量百分比基于此映射计算。
|
|
247
229
|
|
|
@@ -252,34 +234,113 @@ glm-quota-line model set <model-id> <size> # 设置模型大小(如 300K 或
|
|
|
252
234
|
glm-quota-line model remove <model-id> # 移除自定义映射(内置模型恢复默认值)
|
|
253
235
|
```
|
|
254
236
|
|
|
255
|
-
|
|
237
|
+
**`list` 输出示例**:
|
|
256
238
|
|
|
257
239
|
```
|
|
258
|
-
glm-4.
|
|
259
|
-
glm-
|
|
260
|
-
glm-5
|
|
240
|
+
glm-4.5-air 128K
|
|
241
|
+
glm-4.7 200K
|
|
242
|
+
glm-5-turbo 200K
|
|
243
|
+
glm-5.2 1M *
|
|
261
244
|
```
|
|
262
245
|
|
|
263
246
|
`*` 标记表示用户自定义的映射。
|
|
264
247
|
|
|
265
|
-
|
|
248
|
+
**双层结构设计**:
|
|
249
|
+
- 包内 `data/models.json` 作为默认底层
|
|
250
|
+
- `~/.claude/glm-quota-line.json` 里的 `modelMap` 作为用户覆盖层(运行时逐键覆盖)
|
|
266
251
|
|
|
267
|
-
|
|
252
|
+
**优势**:智谱发布新模型时,无需等待 npm 包更新——直接 `model set <新模型> <大小>` 写入本地覆盖层即可立刻生效。
|
|
268
253
|
|
|
269
|
-
|
|
254
|
+
想清空所有自定义模型映射、回到包内默认表:执行 `glm-quota-line config reset --models --yes`。
|
|
270
255
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
256
|
+
</details>
|
|
257
|
+
|
|
258
|
+
<details>
|
|
259
|
+
<summary><b>Agent / 自动化接口</b></summary>
|
|
260
|
+
|
|
261
|
+
如果你是 AI agent(Claude Code / Cursor / Codex)或脚本作者,以下接口保证稳定:
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
# 一次调用拿到所有命令的 machine-readable schema
|
|
265
|
+
glm-quota-line commands --json
|
|
266
|
+
|
|
267
|
+
# 查看单个命令或命令组的聚焦帮助
|
|
268
|
+
glm-quota-line model --help
|
|
269
|
+
glm-quota-line config set --help
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
**约定**:
|
|
273
|
+
- **退出码**:成功 `0`,失败 `1`
|
|
274
|
+
- **副作用标注**:每个命令标为 `read`(只读)、`write`(改配置)、`mutating`(改 Claude Code 集成)、`interactive`(需 TTY)
|
|
275
|
+
- **非阻塞**:所有命令都不会卡住等待输入
|
|
276
|
+
- **只读查询**:`glm-quota-line --json` 输出结构化配额数据
|
|
277
|
+
|
|
278
|
+
典型 agent 工作流:先 `commands --json` 了解能力 → 调用需要的命令 → 读取 stdout 解析结果。
|
|
279
|
+
|
|
280
|
+
</details>
|
|
281
|
+
|
|
282
|
+
<details>
|
|
283
|
+
<summary><b>组件级控制</b></summary>
|
|
284
|
+
|
|
285
|
+
通过 `glm-quota-line configure` 的组件模式,可单独控制每个显示组件的开关和样式。操作键见[快速定制](#快速定制),各组件能力如下:
|
|
286
|
+
|
|
287
|
+
| 组件 | 说明 | 可设置样式 | 可隐藏 |
|
|
288
|
+
|---|---|---|---|
|
|
289
|
+
| `level` | 套餐级别(如 GLM Lite) | — | ✓ |
|
|
290
|
+
| `5h` | 5 小时配额 | ✓ (bar/text) | —(必需) |
|
|
291
|
+
| `week` | 周配额 | ✓ (bar/text) | ✓ |
|
|
292
|
+
| `reset` | 重置时间 | — | ✓ |
|
|
293
|
+
| `ctx` | 上下文窗口用量 | ✓ (bar/text) | ✓ |
|
|
294
|
+
|
|
295
|
+
</details>
|
|
296
|
+
|
|
297
|
+
## 故障排查
|
|
298
|
+
|
|
299
|
+
### 配额不显示
|
|
300
|
+
|
|
301
|
+
**可能原因**:
|
|
302
|
+
1. 鉴权信息缺失或过期
|
|
303
|
+
2. 非 GLM 提供商(端点不是 `open.bigmodel.cn` 或 `api.z.ai`)
|
|
304
|
+
3. 网络连接问题
|
|
305
|
+
|
|
306
|
+
**解决方法**:
|
|
307
|
+
```bash
|
|
308
|
+
# 检查鉴权状态
|
|
309
|
+
glm-quota-line
|
|
310
|
+
|
|
311
|
+
# 如果显示 "auth expired",更新鉴权信息
|
|
312
|
+
glm-quota-line config set auth-token <your-token>
|
|
313
|
+
glm-quota-line config set base-url https://open.bigmodel.cn/api/anthropic
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### 显示 "quota unavailable"
|
|
317
|
+
|
|
318
|
+
**可能原因**:
|
|
319
|
+
- 智谱 API 接口异常
|
|
320
|
+
- 网络连接问题
|
|
321
|
+
|
|
322
|
+
**解决方法**:
|
|
323
|
+
- 稍后重试(工具会自动重试)
|
|
324
|
+
- 检查网络连接
|
|
325
|
+
- 如果持续出现,可能是智谱服务问题
|
|
326
|
+
|
|
327
|
+
### 安装/卸载问题
|
|
328
|
+
|
|
329
|
+
**状态栏没有更新**:
|
|
330
|
+
```bash
|
|
331
|
+
glm-quota-line uninstall
|
|
332
|
+
glm-quota-line install --force
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
`install --force` 会备份旧配置,`uninstall` 会在可能时恢复。
|
|
336
|
+
|
|
337
|
+
### 调试模式
|
|
338
|
+
|
|
339
|
+
设置 `GLM_QUOTA_DEBUG=1` 可输出上下文窗口调试信息到 stderr:
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
GLM_QUOTA_DEBUG=1 glm-quota-line
|
|
343
|
+
```
|
|
283
344
|
|
|
284
345
|
## 命令参考
|
|
285
346
|
|
|
@@ -298,44 +359,20 @@ glm-quota-line model list
|
|
|
298
359
|
glm-quota-line model get <model-id>
|
|
299
360
|
glm-quota-line model set <model-id> <size>
|
|
300
361
|
glm-quota-line model remove <model-id>
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
运行 `glm-quota-line --help` 查看完整说明。
|
|
304
|
-
|
|
305
|
-
## 给 Agent / 自动化
|
|
306
|
-
|
|
307
|
-
如果你是 AI agent(Claude Code / Cursor / Codex)或脚本作者,以下接口保证稳定:
|
|
308
|
-
|
|
309
|
-
```bash
|
|
310
|
-
# 一次调用拿到所有命令的 machine-readable schema(name / summary / sideEffect / args / examples)
|
|
311
362
|
glm-quota-line commands --json
|
|
312
|
-
|
|
313
|
-
# 查看单个命令或命令组的聚焦帮助
|
|
314
|
-
glm-quota-line model --help
|
|
315
|
-
glm-quota-line config set --help
|
|
316
363
|
```
|
|
317
364
|
|
|
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 解析结果。
|
|
365
|
+
运行 `glm-quota-line --help` 查看完整说明。
|
|
325
366
|
|
|
326
|
-
##
|
|
367
|
+
## 技术说明
|
|
327
368
|
|
|
328
369
|
- 展示 `TOKENS_LIMIT` 配额和 `MCP_LIMIT` / `TIME_LIMIT` 配额
|
|
329
|
-
-
|
|
330
|
-
- 状态栏默认显示上下文窗口用量和模型信息,可通过 `glm-quota-line configure` 交互式关闭
|
|
331
|
-
- 每个组件可单独控制开关和样式,通过 `glm-quota-line configure` 交互式调整
|
|
370
|
+
- 周配额进度条中的阴影(▒)是每日应耗基准线:根据已过工作日计算的理论预算
|
|
332
371
|
- 上下文窗口使用率优先从原始 token 数计算,当模型映射不可用时回退到 API 提供的百分比
|
|
333
|
-
-
|
|
334
|
-
-
|
|
335
|
-
- 非 GLM
|
|
336
|
-
-
|
|
337
|
-
- `install --force` 会备份旧配置,`uninstall` 会在可能时恢复
|
|
338
|
-
- 设置 `GLM_QUOTA_DEBUG=1` 可输出上下文窗口调试信息到 stderr
|
|
372
|
+
- 智能缓存:按会话、TTL 和 token 用量分级刷新;`SessionStart` hook 预刷新,新会话不显示旧数据
|
|
373
|
+
- 支持国内(`open.bigmodel.cn`)和国际(`api.z.ai`)端点自动识别
|
|
374
|
+
- 非 GLM 提供商会自动禁用配额查询
|
|
375
|
+
- 零运行时依赖
|
|
339
376
|
|
|
340
377
|
## 许可证
|
|
341
378
|
|
package/package.json
CHANGED
package/src/cli/commands.js
CHANGED
|
@@ -91,8 +91,10 @@ const CONFIG_KEYS = {
|
|
|
91
91
|
}
|
|
92
92
|
};
|
|
93
93
|
|
|
94
|
+
// Derived from CONFIG_KEYS so the supported list can never drift from the
|
|
95
|
+
// actually-handled keys (a previous hardcoded message omitted reset-format).
|
|
94
96
|
const SUPPORTED_CONFIG_KEYS_MESSAGE =
|
|
95
|
-
|
|
97
|
+
`Supported config keys: ${Object.keys(CONFIG_KEYS).join(", ")}\n`;
|
|
96
98
|
|
|
97
99
|
export async function handleCommand(args, output = process.stdout, dependencies = {}) {
|
|
98
100
|
const getVersion = dependencies.getVersion || getPackageVersion;
|
package/src/cli/registry.js
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
// When you add a branch to handleCommand in commands.js (or a subcommand in
|
|
6
6
|
// modelCommand.js / configCommand.js), add a matching entry here. The
|
|
7
7
|
// integration test asserts every registry entry maps to a real dispatch branch.
|
|
8
|
+
//
|
|
9
|
+
// Note: `session-start-refresh` is intentionally NOT registered here. It is an
|
|
10
|
+
// internal hook command wired up by install.js into Claude Code's SessionStart
|
|
11
|
+
// hooks; it is dispatchable (see commands.js) but deliberately omitted from the
|
|
12
|
+
// public command surface (commands --json / --help / README) so users don't
|
|
13
|
+
// invoke it directly.
|
|
8
14
|
|
|
9
15
|
// sideEffect: read | write | interactive | mutating
|
|
10
16
|
// read — no persisted state change, safe for automation
|
|
@@ -206,10 +212,6 @@ export const COMMAND_GROUPS = {
|
|
|
206
212
|
config: ["config show", "config set", "config unset", "config reset"]
|
|
207
213
|
};
|
|
208
214
|
|
|
209
|
-
export function getCommand(key) {
|
|
210
|
-
return COMMAND_REGISTRY[key] || null;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
215
|
export function allCommands() {
|
|
214
216
|
return Object.values(COMMAND_REGISTRY);
|
|
215
217
|
}
|
|
@@ -61,6 +61,10 @@ export async function writeCtxCache(data, filePath = CACHE_FILE) {
|
|
|
61
61
|
if (!isValidCached(data)) {
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
+
// Fill savedAt here (not at call sites): getContextData's return shape has no
|
|
65
|
+
// savedAt, so callers would otherwise write `undefined` and the field would
|
|
66
|
+
// vanish from the JSON. Centralizing it mirrors quota cache's writeSuccessCache
|
|
67
|
+
// and keeps the timestamp reliable for future staleness checks.
|
|
64
68
|
const payload = {
|
|
65
69
|
modelId: data.modelId,
|
|
66
70
|
usedPercent: data.usedPercent,
|
|
@@ -68,7 +72,7 @@ export async function writeCtxCache(data, filePath = CACHE_FILE) {
|
|
|
68
72
|
windowSize: data.windowSize,
|
|
69
73
|
severity: VALID_SEVERITIES.has(data.severity) ? data.severity : "neutral",
|
|
70
74
|
sessionId: data.sessionId || "",
|
|
71
|
-
savedAt: data.savedAt
|
|
75
|
+
savedAt: Number.isFinite(data.savedAt) ? data.savedAt : Date.now()
|
|
72
76
|
};
|
|
73
77
|
try {
|
|
74
78
|
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
@@ -94,7 +94,3 @@ export function createRenderData(contextData, style = "bar") {
|
|
|
94
94
|
}
|
|
95
95
|
return formatForRender(contextData, style);
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
export { getModelSize, setModelSize, removeModel, mergeModelMap, getAllModels } from "./models.js";
|
|
99
|
-
export { getSeverity, calculateTokenCount } from "./calculator.js";
|
|
100
|
-
export { formatForRender, buildBar, formatWindowSize, formatModelSuffix } from "./formatter.js";
|
|
@@ -101,10 +101,6 @@ export function getModelSize(modelId) {
|
|
|
101
101
|
return findByKey(modelMap, modelId)?.value;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
export function hasModel(modelId) {
|
|
105
|
-
return findByKey(modelMap, modelId) !== undefined;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
104
|
export function setModelSize(modelId, size) {
|
|
109
105
|
if (typeof modelId !== "string" || !modelId) {
|
|
110
106
|
return;
|
|
@@ -128,10 +124,6 @@ export function mergeModelMap(newMap) {
|
|
|
128
124
|
}
|
|
129
125
|
}
|
|
130
126
|
|
|
131
|
-
export function getAllModels() {
|
|
132
|
-
return { ...modelMap };
|
|
133
|
-
}
|
|
134
|
-
|
|
135
127
|
export function removeModel(modelId) {
|
|
136
128
|
if (typeof modelId !== "string" || !modelId) {
|
|
137
129
|
return false;
|
package/src/core/quota/parse.js
CHANGED
|
@@ -107,7 +107,7 @@ function pickSecondaryTokenLimit(tokenLimits, primaryLimit) {
|
|
|
107
107
|
|
|
108
108
|
function pickPrimaryAndSecondaryTokenLimits(limits) {
|
|
109
109
|
const tokenLimits = limits
|
|
110
|
-
.filter((limit) => limit?.type === "TOKENS_LIMIT")
|
|
110
|
+
.filter((limit) => limit?.type === "TOKENS_LIMIT" || limit?.type === "CREDIT_LIMIT")
|
|
111
111
|
.map((limit, index) => ({ ...limit, _index: index }));
|
|
112
112
|
|
|
113
113
|
if (tokenLimits.length === 0) {
|
|
@@ -186,7 +186,8 @@ export function parseQuotaResponse(response) {
|
|
|
186
186
|
return { kind: "unavailable" };
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
|
|
189
|
+
// The current quota endpoint returns code:200 without a success flag
|
|
190
|
+
if (payload.success !== true && payload.code !== 200) {
|
|
190
191
|
if (payload.code === 1001 || payload.code === 401 || isAuthFailureMessage(payload.msg)) {
|
|
191
192
|
return { kind: "auth_error" };
|
|
192
193
|
}
|
|
@@ -8,6 +8,7 @@ import { parseQuotaResponse } from "./parse.js";
|
|
|
8
8
|
import {
|
|
9
9
|
RATE_LIMIT_RETRY_TTL_MS,
|
|
10
10
|
REFRESH_BANDS,
|
|
11
|
+
STALE_SUCCESS_MAX_AGE_MS,
|
|
11
12
|
UNAVAILABLE_RETRY_TTL_MS
|
|
12
13
|
} from "../../shared/constants.js";
|
|
13
14
|
|
|
@@ -36,6 +37,17 @@ function getEffectiveTtlMs(cached) {
|
|
|
36
37
|
return getRefreshTtlMs(cached?.result?.leftPercent);
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
// A cached success value bridges transient failures only while it is still
|
|
41
|
+
// fresh. Once it is older than STALE_SUCCESS_MAX_AGE_MS we stop masking the
|
|
42
|
+
// real (unavailable) state — otherwise an exhausted quota freezes the status
|
|
43
|
+
// bar at the pre-exhaustion percentage indefinitely.
|
|
44
|
+
function isStaleSuccessUsable(cached, now) {
|
|
45
|
+
if (!cached?.result || !Number.isFinite(cached.savedAt)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return now - cached.savedAt < STALE_SUCCESS_MAX_AGE_MS;
|
|
49
|
+
}
|
|
50
|
+
|
|
39
51
|
function shouldRefreshQuota(cached, cacheTtlMs, now, sessionId) {
|
|
40
52
|
if (!cached) {
|
|
41
53
|
return true;
|
|
@@ -88,15 +100,29 @@ export async function resolveQuotaStatus(config, options = {}) {
|
|
|
88
100
|
}
|
|
89
101
|
|
|
90
102
|
if (parsed.kind === "rate_limited") {
|
|
103
|
+
// GLM signals quota exhaustion as HTTP 429, indistinguishable from a
|
|
104
|
+
// genuine rate limit. Bridge with the stale value only while it is still
|
|
105
|
+
// fresh; a sustained 429 past the stale window must surface the real
|
|
106
|
+
// state rather than freeze the bar at a pre-exhaustion percentage.
|
|
91
107
|
await writeFailureCache(config.cacheFilePath, cached, {
|
|
92
108
|
now,
|
|
93
109
|
sessionId,
|
|
94
110
|
failureKind: "rate_limited"
|
|
95
111
|
});
|
|
96
|
-
|
|
112
|
+
if (isStaleSuccessUsable(cached, now)) {
|
|
113
|
+
return cached.result;
|
|
114
|
+
}
|
|
115
|
+
// Stale value expired (or never existed). With an expired cache we must
|
|
116
|
+
// NOT return the frozen old value — surface the real `rate_limited`.
|
|
117
|
+
// With no prior cache at all, fall back to `unavailable` to preserve the
|
|
118
|
+
// first-run contract (no quota has ever been seen).
|
|
119
|
+
return cached?.result ? parsed : getCachedStatus(cached);
|
|
97
120
|
}
|
|
98
121
|
|
|
99
|
-
|
|
122
|
+
// Sustained unavailability: bridge with the stale success value only while
|
|
123
|
+
// it is still fresh. Past the stale window, surface the real state so a
|
|
124
|
+
// truly exhausted quota is not hidden behind a frozen old percentage.
|
|
125
|
+
if (isStaleSuccessUsable(cached, now)) {
|
|
100
126
|
await writeFailureCache(config.cacheFilePath, cached, {
|
|
101
127
|
now,
|
|
102
128
|
sessionId,
|
package/src/shared/constants.js
CHANGED
|
@@ -58,6 +58,10 @@ export const REFRESH_BANDS = [
|
|
|
58
58
|
export const LOW_QUOTA_THRESHOLD = 30;
|
|
59
59
|
export const RATE_LIMIT_RETRY_TTL_MS = 180_000;
|
|
60
60
|
export const UNAVAILABLE_RETRY_TTL_MS = 120_000;
|
|
61
|
+
// A cached *success* value is only trusted to bridge transient failures for
|
|
62
|
+
// this long. Past it, a sustained `unavailable` must surface instead of
|
|
63
|
+
// freezing the status bar at a pre-exhaustion percentage. 10 min.
|
|
64
|
+
export const STALE_SUCCESS_MAX_AGE_MS = 600_000;
|
|
61
65
|
export const DEFAULT_DISPLAY_MODE = "left";
|
|
62
66
|
export const DEFAULT_STYLE = "bar";
|
|
63
67
|
export const DEFAULT_THEME = "dark";
|
|
@@ -209,6 +213,6 @@ export function normalizeConfig(config) {
|
|
|
209
213
|
return { global, lines };
|
|
210
214
|
}
|
|
211
215
|
|
|
212
|
-
// Re-exported for
|
|
216
|
+
// Re-exported for test imports
|
|
213
217
|
export { migrateOldConfig } from "./migration.js";
|
|
214
218
|
|
package/src/shared/migration.js
CHANGED
|
@@ -44,10 +44,3 @@ export function needsMigration(config) {
|
|
|
44
44
|
// Legacy ctxEnabled without lines config requires migration
|
|
45
45
|
return typeof config.ctxEnabled === "boolean" && !config.lines;
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
export function applyMigration(config) {
|
|
49
|
-
if (needsMigration(config)) {
|
|
50
|
-
return migrateOldConfig(config);
|
|
51
|
-
}
|
|
52
|
-
return config;
|
|
53
|
-
}
|
package/src/shared/utils.js
CHANGED
|
@@ -26,11 +26,6 @@ export function clampPercent(value) {
|
|
|
26
26
|
return Math.min(100, Math.max(0, n));
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export function clampRoundPercent(value) {
|
|
30
|
-
const percent = clampPercent(value);
|
|
31
|
-
return percent !== null ? Math.round(percent) : null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
29
|
export function asFiniteNumber(value) {
|
|
35
30
|
return Number.isFinite(value) ? value : null;
|
|
36
31
|
}
|