glm-coding-router 0.1.1 → 0.2.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/README.md +286 -248
- package/dist/bin/glm-chat.js +4 -2
- package/dist/bin/glm-fast.js +50 -0
- package/dist/bin/glm-review.js +4 -2
- package/dist/bin/glm-worker.js +4 -2
- package/dist/core/config.js +10 -0
- package/dist/core/profile.js +57 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,248 +1,286 @@
|
|
|
1
|
-
# GLM Coding Router
|
|
2
|
-
|
|
3
|
-
GLM Coding Plan workers for Claude Code and Codex, on Windows.
|
|
4
|
-
|
|
5
|
-
Claude Code and Codex stay your orchestrators — they keep responsibility for requirements,
|
|
6
|
-
architecture, review, and integration. `glm-coding-router` delegates well-scoped
|
|
7
|
-
implementation work (exploration, CRUD, boilerplate, tests, mechanical refactoring) to
|
|
8
|
-
GLM workers via Z.ai's Anthropic-compatible endpoint.
|
|
9
|
-
|
|
10
|
-
One global npm install replaces the manual `.cmd` shim setup:
|
|
11
|
-
|
|
12
|
-
```text
|
|
13
|
-
Claude / Codex → shell → glm-worker → claude.exe harness → Z.ai endpoint → GLM Coding Plan
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## Architecture
|
|
17
|
-
|
|
18
|
-
```text
|
|
19
|
-
Developer
|
|
20
|
-
│
|
|
21
|
-
┌───────────────┴───────────────┐
|
|
22
|
-
▼ ▼
|
|
23
|
-
Claude Code Codex
|
|
24
|
-
│ │
|
|
25
|
-
└───────────────┬───────────────┘
|
|
26
|
-
shell command
|
|
27
|
-
│
|
|
28
|
-
┌───────────────┼───────────────┐
|
|
29
|
-
▼ ▼ ▼
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
claude.exe
|
|
34
|
-
(injected environment only)
|
|
35
|
-
│
|
|
36
|
-
▼
|
|
37
|
-
https://api.z.ai/api/anthropic
|
|
38
|
-
│
|
|
39
|
-
▼
|
|
40
|
-
GLM Coding Plan
|
|
41
|
-
GLM-5.3 / GLM-5.3-Flash
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Requirements
|
|
45
|
-
|
|
46
|
-
- Windows 10/11 (v0.1; Linux/macOS planned for v0.2)
|
|
47
|
-
- Node.js >= 20
|
|
48
|
-
- Claude Code (`claude.exe`) — the GLM commands run on the Claude Code harness
|
|
49
|
-
- Codex (optional — Claude-only setups are fully supported)
|
|
50
|
-
- A Z.ai Coding Plan API key
|
|
51
|
-
|
|
52
|
-
No Anthropic pay-as-you-go, no OpenAI API, no LiteLLM, no proxy.
|
|
53
|
-
|
|
54
|
-
## Installation
|
|
55
|
-
|
|
56
|
-
```powershell
|
|
57
|
-
npm install -g glm-coding-router
|
|
58
|
-
glm-router init
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
`npx glm-coding-router init` also works for a one-off check, but the global install is
|
|
62
|
-
what puts `glm-worker` on your PATH long-term.
|
|
63
|
-
|
|
64
|
-
## Quick start
|
|
65
|
-
|
|
66
|
-
After `glm-router init`:
|
|
67
|
-
|
|
68
|
-
```powershell
|
|
69
|
-
glm-chat
|
|
70
|
-
glm-
|
|
71
|
-
glm-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
glm-chat
|
|
83
|
-
glm-chat --
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
glm-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
##
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
-
|
|
195
|
-
|
|
196
|
-
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
##
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
`
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
1
|
+
# GLM Coding Router
|
|
2
|
+
|
|
3
|
+
GLM Coding Plan workers for Claude Code and Codex, on Windows.
|
|
4
|
+
|
|
5
|
+
Claude Code and Codex stay your orchestrators — they keep responsibility for requirements,
|
|
6
|
+
architecture, review, and integration. `glm-coding-router` delegates well-scoped
|
|
7
|
+
implementation work (exploration, CRUD, boilerplate, tests, mechanical refactoring) to
|
|
8
|
+
GLM workers via Z.ai's Anthropic-compatible endpoint.
|
|
9
|
+
|
|
10
|
+
One global npm install replaces the manual `.cmd` shim setup:
|
|
11
|
+
|
|
12
|
+
```text
|
|
13
|
+
Claude / Codex → shell → glm-worker → claude.exe harness → Z.ai endpoint → GLM Coding Plan
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Architecture
|
|
17
|
+
|
|
18
|
+
```text
|
|
19
|
+
Developer
|
|
20
|
+
│
|
|
21
|
+
┌───────────────┴───────────────┐
|
|
22
|
+
▼ ▼
|
|
23
|
+
Claude Code Codex
|
|
24
|
+
│ │
|
|
25
|
+
└───────────────┬───────────────┘
|
|
26
|
+
shell command
|
|
27
|
+
│
|
|
28
|
+
┌───────────────┼───────────────┐
|
|
29
|
+
▼ ▼ ▼
|
|
30
|
+
glm-chat glm-fast glm-worker glm-review
|
|
31
|
+
│ │ │ │
|
|
32
|
+
└─────────┴──────────┴──────────┘
|
|
33
|
+
claude.exe
|
|
34
|
+
(injected environment only)
|
|
35
|
+
│
|
|
36
|
+
▼
|
|
37
|
+
https://api.z.ai/api/anthropic
|
|
38
|
+
│
|
|
39
|
+
▼
|
|
40
|
+
GLM Coding Plan
|
|
41
|
+
GLM-5.3 / GLM-5.3-Flash
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Requirements
|
|
45
|
+
|
|
46
|
+
- Windows 10/11 (v0.1; Linux/macOS planned for v0.2)
|
|
47
|
+
- Node.js >= 20
|
|
48
|
+
- Claude Code (`claude.exe`) — the GLM commands run on the Claude Code harness
|
|
49
|
+
- Codex (optional — Claude-only setups are fully supported)
|
|
50
|
+
- A Z.ai Coding Plan API key
|
|
51
|
+
|
|
52
|
+
No Anthropic pay-as-you-go, no OpenAI API, no LiteLLM, no proxy.
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
```powershell
|
|
57
|
+
npm install -g glm-coding-router
|
|
58
|
+
glm-router init
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`npx glm-coding-router init` also works for a one-off check, but the global install is
|
|
62
|
+
what puts `glm-worker` on your PATH long-term.
|
|
63
|
+
|
|
64
|
+
## Quick start
|
|
65
|
+
|
|
66
|
+
After `glm-router init`:
|
|
67
|
+
|
|
68
|
+
```powershell
|
|
69
|
+
glm-chat
|
|
70
|
+
glm-fast
|
|
71
|
+
glm-worker "Implement validation and add tests"
|
|
72
|
+
glm-review "Analyze the auth module"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## glm-chat
|
|
76
|
+
|
|
77
|
+
Interactive GLM-backed Claude Code session. Resolves the Z.ai key, locates `claude.exe`,
|
|
78
|
+
injects the Z.ai environment **into the child process only**, and spawns it with
|
|
79
|
+
pass-through arguments:
|
|
80
|
+
|
|
81
|
+
```powershell
|
|
82
|
+
glm-chat
|
|
83
|
+
glm-chat --version
|
|
84
|
+
glm-chat --any-claude-flag
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Your normal `claude` command and its authentication are untouched.
|
|
88
|
+
|
|
89
|
+
## glm-fast
|
|
90
|
+
|
|
91
|
+
Interactive GLM-backed session pinned to the **fast model** (`models.fast`,
|
|
92
|
+
`glm-5.3-flash` by default) — every model slot in the child environment maps to
|
|
93
|
+
it, so whichever tier Claude Code picks, it gets the fast model. Same pass-through
|
|
94
|
+
arguments as `glm-chat`:
|
|
95
|
+
|
|
96
|
+
```powershell
|
|
97
|
+
glm-fast
|
|
98
|
+
glm-fast --profile air
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## glm-worker
|
|
102
|
+
|
|
103
|
+
Headless implementation worker:
|
|
104
|
+
|
|
105
|
+
```powershell
|
|
106
|
+
glm-worker "Implement validation and add tests"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Or via stdin (a structured task packet):
|
|
110
|
+
|
|
111
|
+
```powershell
|
|
112
|
+
@"
|
|
113
|
+
TASK:
|
|
114
|
+
Implement refresh token validation.
|
|
115
|
+
|
|
116
|
+
SCOPE:
|
|
117
|
+
internal/auth/
|
|
118
|
+
|
|
119
|
+
VALIDATION:
|
|
120
|
+
go test ./internal/auth/...
|
|
121
|
+
"@ | glm-worker
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Input priority: **stdin → arguments → error**. The worker runs with
|
|
125
|
+
`--max-turns 20 --permission-mode acceptEdits --tools Read,Glob,Grep,Edit,Write,Bash`.
|
|
126
|
+
It never uses `--dangerously-skip-permissions`.
|
|
127
|
+
|
|
128
|
+
## glm-review
|
|
129
|
+
|
|
130
|
+
Read-only worker for repository exploration, call-graph discovery, duplicate detection,
|
|
131
|
+
dependency inspection, and preliminary review:
|
|
132
|
+
|
|
133
|
+
```powershell
|
|
134
|
+
glm-review "Inspect this repository"
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Runs with `--tools Read,Glob,Grep` — it cannot edit files or run commands.
|
|
138
|
+
|
|
139
|
+
## Profiles
|
|
140
|
+
|
|
141
|
+
All four task binaries (`glm-chat`, `glm-fast`, `glm-worker`, `glm-review`)
|
|
142
|
+
accept `--profile <name>` to overlay saved model/maxTurns settings. Profiles
|
|
143
|
+
live in `config.json`:
|
|
144
|
+
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"profiles": {
|
|
148
|
+
"test": { "workerMaxTurns": 10, "fast": "glm-5.3-flash" },
|
|
149
|
+
"frontend": { "main": "glm-5.3", "reviewMaxTurns": 30 }
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
```powershell
|
|
155
|
+
glm-worker --profile test "Add failing test then fix it"
|
|
156
|
+
glm-review --profile frontend "Review the component tree"
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Fields (all optional): `main`, `fast`, `workerMaxTurns`, `reviewMaxTurns`.
|
|
160
|
+
Unknown profile names fail with `ERROR [11]` listing the available ones.
|
|
161
|
+
Note: `--profile` belongs to these wrappers — it shadows Claude Code's own
|
|
162
|
+
`--profile` flag inside them.
|
|
163
|
+
|
|
164
|
+
## CLI reference
|
|
165
|
+
|
|
166
|
+
```text
|
|
167
|
+
glm-router init guided setup
|
|
168
|
+
glm-router doctor [--network] full runtime diagnosis
|
|
169
|
+
glm-router status quick offline overview
|
|
170
|
+
glm-router key set store ZAI_API_KEY (Windows User Environment)
|
|
171
|
+
glm-router key check key configured? from which source?
|
|
172
|
+
glm-router config show
|
|
173
|
+
glm-router config set models.main glm-5.3
|
|
174
|
+
glm-router project init CLAUDE.md / AGENTS.md managed blocks (--dry-run supported)
|
|
175
|
+
glm-router project remove
|
|
176
|
+
glm-router skill install optional Codex delegation skill
|
|
177
|
+
glm-router skill remove
|
|
178
|
+
glm-router uninstall guided removal (keeps ZAI_API_KEY by default)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Global flags: `--json --quiet --verbose --dry-run --force --yes`
|
|
182
|
+
|
|
183
|
+
## Claude integration
|
|
184
|
+
|
|
185
|
+
`glm-router project init` adds a **managed block** to `CLAUDE.md` at the project root
|
|
186
|
+
(`git rev-parse --show-toplevel`, falling back to cwd):
|
|
187
|
+
|
|
188
|
+
```text
|
|
189
|
+
<!-- glm-coding-router:start -->
|
|
190
|
+
... delegation policy ...
|
|
191
|
+
<!-- glm-coding-router:end -->
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
- Everything outside the markers is preserved; existing blocks are replaced in place;
|
|
195
|
+
runs are idempotent and never duplicate.
|
|
196
|
+
- Files are updated atomically (tmp file → fsync → rename).
|
|
197
|
+
- On a malformed marker pair the file is left untouched with an actionable error.
|
|
198
|
+
- CRLF/LF and UTF-8 are preserved.
|
|
199
|
+
- `glm-router project remove` deletes only the managed block. A file the router
|
|
200
|
+
created entirely is deleted only when it would otherwise be empty.
|
|
201
|
+
|
|
202
|
+
## Codex integration
|
|
203
|
+
|
|
204
|
+
The same command updates `AGENTS.md` (Codex's repository instruction file) with an
|
|
205
|
+
equivalent managed block. Additionally, `glm-router skill install` installs the optional
|
|
206
|
+
`glm-delegation` skill to `~/.codex/skills/glm-delegation/SKILL.md`. If Codex is not
|
|
207
|
+
detected, the skill step warns and skips — AGENTS.md integration and the core tool are
|
|
208
|
+
unaffected.
|
|
209
|
+
|
|
210
|
+
## Orca behavior (stale environments)
|
|
211
|
+
|
|
212
|
+
Terminals embedded in Orca snapshot the Windows environment at startup. A key added
|
|
213
|
+
after Orca starts is invisible to those terminals. Every GLM command therefore resolves
|
|
214
|
+
the key in this order:
|
|
215
|
+
|
|
216
|
+
1. `process.env.ZAI_API_KEY`
|
|
217
|
+
2. Windows User Environment (via PowerShell)
|
|
218
|
+
3. fail with an actionable error
|
|
219
|
+
|
|
220
|
+
The key is never cached to disk.
|
|
221
|
+
|
|
222
|
+
## Security model
|
|
223
|
+
|
|
224
|
+
- The key lives only in the Windows User Environment; it is never written to
|
|
225
|
+
`config.json`, the repo, logs, or stack traces. Debug output redacts
|
|
226
|
+
`ZAI_API_KEY`, `ANTHROPIC_AUTH_TOKEN`, and Authorization headers.
|
|
227
|
+
- Z.ai routing environment variables (`ANTHROPIC_AUTH_TOKEN`,
|
|
228
|
+
`ANTHROPIC_BASE_URL`, model overrides) are injected **only** into the spawned
|
|
229
|
+
`claude.exe` child process. `ANTHROPIC_API_KEY` is blanked in the child so your
|
|
230
|
+
normal Claude auth is never in play. `ANTHROPIC_BASE_URL` is never persisted globally.
|
|
231
|
+
- Claude Code and Codex global authentication are never modified.
|
|
232
|
+
- Child processes are spawned with argument arrays (`shell: false`) — prompts with
|
|
233
|
+
quotes, pipes, ampersands, or newlines are passed verbatim, never through a shell.
|
|
234
|
+
- No telemetry, no automatic git commits.
|
|
235
|
+
|
|
236
|
+
## Troubleshooting
|
|
237
|
+
|
|
238
|
+
| Symptom | Fix |
|
|
239
|
+
| --- | --- |
|
|
240
|
+
| `ERROR [ZAI_KEY_MISSING]` | `glm-router key set`, then open a **new** terminal |
|
|
241
|
+
| `ERROR [CLAUDE_NOT_FOUND]` | Install Claude Code, or `glm-router config set claudePath C:\path\to\claude.exe` |
|
|
242
|
+
| Key works in a new terminal but not inside Orca | Expected — workers re-read the Windows User Environment automatically; run `glm-router doctor` to confirm |
|
|
243
|
+
| `glm-*` not on PATH after install | Reopen the terminal; check `npm config get prefix` is on PATH |
|
|
244
|
+
| `ERROR [MANAGED_BLOCK_CORRUPT]` | Fix the marker pair in the named file manually, then re-run |
|
|
245
|
+
|
|
246
|
+
Run `glm-router doctor` (add `--network` to probe the Z.ai endpoint) for a full diagnosis.
|
|
247
|
+
|
|
248
|
+
## Uninstall
|
|
249
|
+
|
|
250
|
+
```powershell
|
|
251
|
+
glm-router uninstall
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
The wizard removes the config, the Codex skill, and optionally the current project
|
|
255
|
+
integration. `ZAI_API_KEY` is **kept** by default — removing credentials requires
|
|
256
|
+
explicit consent. Finish with `npm uninstall -g glm-coding-router`.
|
|
257
|
+
|
|
258
|
+
## Development
|
|
259
|
+
|
|
260
|
+
```powershell
|
|
261
|
+
npm install
|
|
262
|
+
npm run build # tsc → dist/
|
|
263
|
+
npm test # vitest run
|
|
264
|
+
npm run lint # eslint src tests
|
|
265
|
+
npm run dev # tsx src/cli.ts <args>
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Integration tests spawn `tests/fixtures/fake-agent.mjs` (via `node.exe`) to verify
|
|
269
|
+
argument passing, environment injection, and exit-code propagation without spending
|
|
270
|
+
API quota. See the `GLM Coding Router — Technical Specification v0.1.md` for the full
|
|
271
|
+
v0.1 contract (exit codes, managed-block test matrix, acceptance criteria).
|
|
272
|
+
|
|
273
|
+
## Publishing
|
|
274
|
+
|
|
275
|
+
```powershell
|
|
276
|
+
npm run build
|
|
277
|
+
npm test
|
|
278
|
+
npm publish
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
`prepublishOnly` runs build + tests. The package ships only `dist/`; the four binaries
|
|
282
|
+
(`glm-router`, `glm-chat`, `glm-fast`, `glm-worker`, `glm-review`) are declared in `bin`.
|
|
283
|
+
|
|
284
|
+
## License
|
|
285
|
+
|
|
286
|
+
MIT
|
package/dist/bin/glm-chat.js
CHANGED
|
@@ -5,6 +5,7 @@ import { createGlmEnv } from "../core/env.js";
|
|
|
5
5
|
import { Errors, formatGlmError, GlmRouterError } from "../core/errors.js";
|
|
6
6
|
import { isMainModule } from "../core/main-guard.js";
|
|
7
7
|
import { logger, redact } from "../core/logging.js";
|
|
8
|
+
import { applyProfile, extractProfileFlag } from "../core/profile.js";
|
|
8
9
|
import { spawnAgent } from "../core/process.js";
|
|
9
10
|
import { resolveZaiApiKey } from "../core/zai-key.js";
|
|
10
11
|
/**
|
|
@@ -12,7 +13,8 @@ import { resolveZaiApiKey } from "../core/zai-key.js";
|
|
|
12
13
|
* spawn claude interactively with pass-through arguments.
|
|
13
14
|
*/
|
|
14
15
|
export async function runChat(argv) {
|
|
15
|
-
const
|
|
16
|
+
const { rest, profile } = extractProfileFlag(argv);
|
|
17
|
+
const config = applyProfile(loadConfig(), profile);
|
|
16
18
|
const resolved = resolveZaiApiKey();
|
|
17
19
|
if (!resolved) {
|
|
18
20
|
throw Errors.zaiKeyMissing();
|
|
@@ -22,7 +24,7 @@ export async function runChat(argv) {
|
|
|
22
24
|
logger.debug(`spawning ${claudePath}`);
|
|
23
25
|
logger.debug(redact(`env ANTHROPIC_BASE_URL=${env.ANTHROPIC_BASE_URL}`, [resolved.key]));
|
|
24
26
|
return spawnAgent(claudePath, {
|
|
25
|
-
args: [...
|
|
27
|
+
args: [...rest],
|
|
26
28
|
cwd: process.cwd(),
|
|
27
29
|
env,
|
|
28
30
|
interactive: true,
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { loadConfig } from "../core/config.js";
|
|
3
|
+
import { locateClaude } from "../core/claude.js";
|
|
4
|
+
import { createGlmEnv } from "../core/env.js";
|
|
5
|
+
import { Errors, formatGlmError, GlmRouterError } from "../core/errors.js";
|
|
6
|
+
import { isMainModule } from "../core/main-guard.js";
|
|
7
|
+
import { logger, redact } from "../core/logging.js";
|
|
8
|
+
import { applyProfile, extractProfileFlag } from "../core/profile.js";
|
|
9
|
+
import { spawnAgent } from "../core/process.js";
|
|
10
|
+
import { resolveZaiApiKey } from "../core/zai-key.js";
|
|
11
|
+
/**
|
|
12
|
+
* Effective config for glm-fast: every model slot pinned to the fast model
|
|
13
|
+
* (specs/glm-fast-profiles.md). Applied AFTER the profile so a profile's
|
|
14
|
+
* `fast` model flows into all slots; a profile's `main` is overridden by design.
|
|
15
|
+
*/
|
|
16
|
+
export function fastModelConfig(config) {
|
|
17
|
+
return { ...config, models: { main: config.models.fast, fast: config.models.fast } };
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* glm-fast (spec §54, specs/glm-fast-profiles.md): interactive chat pinned to
|
|
21
|
+
* the fast model. Pass-through args like glm-chat; supports --profile.
|
|
22
|
+
*/
|
|
23
|
+
export async function runFast(argv) {
|
|
24
|
+
const { rest, profile } = extractProfileFlag(argv);
|
|
25
|
+
const config = fastModelConfig(applyProfile(loadConfig(), profile));
|
|
26
|
+
const resolved = resolveZaiApiKey();
|
|
27
|
+
if (!resolved) {
|
|
28
|
+
throw Errors.zaiKeyMissing();
|
|
29
|
+
}
|
|
30
|
+
const claudePath = locateClaude(config);
|
|
31
|
+
const env = createGlmEnv(config, resolved.key);
|
|
32
|
+
logger.debug(`spawning ${claudePath}`);
|
|
33
|
+
logger.debug(redact(`env ANTHROPIC_BASE_URL=${env.ANTHROPIC_BASE_URL}`, [resolved.key]));
|
|
34
|
+
return spawnAgent(claudePath, {
|
|
35
|
+
args: [...rest],
|
|
36
|
+
cwd: process.cwd(),
|
|
37
|
+
env,
|
|
38
|
+
interactive: true,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (isMainModule(import.meta.url)) {
|
|
42
|
+
runFast(process.argv.slice(2)).then((code) => process.exit(code), (error) => {
|
|
43
|
+
if (error instanceof GlmRouterError) {
|
|
44
|
+
process.stderr.write(formatGlmError(error) + "\n");
|
|
45
|
+
process.exit(error.exitCode);
|
|
46
|
+
}
|
|
47
|
+
process.stderr.write(String(error) + "\n");
|
|
48
|
+
process.exit(1);
|
|
49
|
+
});
|
|
50
|
+
}
|
package/dist/bin/glm-review.js
CHANGED
|
@@ -5,6 +5,7 @@ import { createGlmEnv } from "../core/env.js";
|
|
|
5
5
|
import { Errors, formatGlmError, GlmRouterError } from "../core/errors.js";
|
|
6
6
|
import { isMainModule } from "../core/main-guard.js";
|
|
7
7
|
import { logger, redact } from "../core/logging.js";
|
|
8
|
+
import { applyProfile, extractProfileFlag } from "../core/profile.js";
|
|
8
9
|
import { readStdin, resolvePrompt } from "../core/prompt.js";
|
|
9
10
|
import { spawnAgent } from "../core/process.js";
|
|
10
11
|
import { resolveZaiApiKey } from "../core/zai-key.js";
|
|
@@ -18,8 +19,9 @@ export function buildReviewArgs(prompt, config) {
|
|
|
18
19
|
* discovery, duplicate detection, dependency inspection, and review.
|
|
19
20
|
*/
|
|
20
21
|
export async function runReview(argv) {
|
|
21
|
-
const
|
|
22
|
-
const
|
|
22
|
+
const { rest, profile } = extractProfileFlag(argv);
|
|
23
|
+
const prompt = await resolvePrompt(rest, readStdin, "glm-review");
|
|
24
|
+
const config = applyProfile(loadConfig(), profile);
|
|
23
25
|
const resolved = resolveZaiApiKey();
|
|
24
26
|
if (!resolved) {
|
|
25
27
|
throw Errors.zaiKeyMissing();
|
package/dist/bin/glm-worker.js
CHANGED
|
@@ -5,6 +5,7 @@ import { createGlmEnv } from "../core/env.js";
|
|
|
5
5
|
import { Errors, formatGlmError, GlmRouterError } from "../core/errors.js";
|
|
6
6
|
import { isMainModule } from "../core/main-guard.js";
|
|
7
7
|
import { logger, redact } from "../core/logging.js";
|
|
8
|
+
import { applyProfile, extractProfileFlag } from "../core/profile.js";
|
|
8
9
|
import { resolvePrompt } from "../core/prompt.js";
|
|
9
10
|
import { spawnAgent } from "../core/process.js";
|
|
10
11
|
import { resolveZaiApiKey } from "../core/zai-key.js";
|
|
@@ -28,8 +29,9 @@ export function buildWorkerArgs(prompt, config) {
|
|
|
28
29
|
* --dangerously-skip-permissions.
|
|
29
30
|
*/
|
|
30
31
|
export async function runWorker(argv) {
|
|
31
|
-
const
|
|
32
|
-
const
|
|
32
|
+
const { rest, profile } = extractProfileFlag(argv);
|
|
33
|
+
const prompt = await resolvePrompt(rest);
|
|
34
|
+
const config = applyProfile(loadConfig(), profile);
|
|
33
35
|
const resolved = resolveZaiApiKey();
|
|
34
36
|
if (!resolved) {
|
|
35
37
|
throw Errors.zaiKeyMissing();
|
package/dist/core/config.js
CHANGED
|
@@ -6,6 +6,13 @@ import { configDir, configPath } from "./paths.js";
|
|
|
6
6
|
export const DEFAULT_ANTHROPIC_BASE_URL = "https://api.z.ai/api/anthropic";
|
|
7
7
|
export const DEFAULT_MAIN_MODEL = "glm-5.3";
|
|
8
8
|
export const DEFAULT_FAST_MODEL = "glm-5.3-flash";
|
|
9
|
+
/** Named model/maxTurns overlay selected via --profile (specs/glm-fast-profiles.md). */
|
|
10
|
+
export const ProfileSchema = z.object({
|
|
11
|
+
main: z.string().min(1).optional(),
|
|
12
|
+
fast: z.string().min(1).optional(),
|
|
13
|
+
workerMaxTurns: z.number().int().positive().optional(),
|
|
14
|
+
reviewMaxTurns: z.number().int().positive().optional(),
|
|
15
|
+
});
|
|
9
16
|
export const ConfigSchema = z.object({
|
|
10
17
|
schemaVersion: z.literal(1),
|
|
11
18
|
provider: z.object({
|
|
@@ -30,6 +37,8 @@ export const ConfigSchema = z.object({
|
|
|
30
37
|
// Optional executable overrides used by discovery (spec §33, §34).
|
|
31
38
|
claudePath: z.string().min(1).optional(),
|
|
32
39
|
codexPath: z.string().min(1).optional(),
|
|
40
|
+
// Named overlays selected via --profile (specs/glm-fast-profiles.md).
|
|
41
|
+
profiles: z.record(z.string(), ProfileSchema).default({}),
|
|
33
42
|
});
|
|
34
43
|
export function defaultConfig() {
|
|
35
44
|
return {
|
|
@@ -49,6 +58,7 @@ export function defaultConfig() {
|
|
|
49
58
|
codex: true,
|
|
50
59
|
codexSkill: true,
|
|
51
60
|
},
|
|
61
|
+
profiles: {},
|
|
52
62
|
};
|
|
53
63
|
}
|
|
54
64
|
/**
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Errors } from "./errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Remove the router's --profile flag from argv (specs/glm-fast-profiles.md).
|
|
4
|
+
* Accepts `--profile name` and `--profile=name`; the first occurrence wins,
|
|
5
|
+
* later ones are consumed too so they never leak into the forwarded args.
|
|
6
|
+
*/
|
|
7
|
+
export function extractProfileFlag(argv) {
|
|
8
|
+
const rest = [];
|
|
9
|
+
let profile;
|
|
10
|
+
for (let i = 0; i < argv.length; i++) {
|
|
11
|
+
const arg = argv[i];
|
|
12
|
+
if (arg === "--profile") {
|
|
13
|
+
const value = argv[i + 1];
|
|
14
|
+
if (value === undefined) {
|
|
15
|
+
throw Errors.configInvalid("--profile requires a profile name");
|
|
16
|
+
}
|
|
17
|
+
profile ??= value;
|
|
18
|
+
i++;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (arg.startsWith("--profile=")) {
|
|
22
|
+
const value = arg.slice("--profile=".length);
|
|
23
|
+
if (value.length === 0) {
|
|
24
|
+
throw Errors.configInvalid("--profile requires a profile name");
|
|
25
|
+
}
|
|
26
|
+
profile ??= value;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
rest.push(arg);
|
|
30
|
+
}
|
|
31
|
+
return { rest, profile };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Overlay a named profile onto the config (specs/glm-fast-profiles.md):
|
|
35
|
+
* main/fast models plus worker/review maxTurns. Unknown names fail with
|
|
36
|
+
* ERROR [11] listing the defined profiles.
|
|
37
|
+
*/
|
|
38
|
+
export function applyProfile(config, name) {
|
|
39
|
+
if (!name) {
|
|
40
|
+
return config;
|
|
41
|
+
}
|
|
42
|
+
const profile = config.profiles[name];
|
|
43
|
+
if (!profile) {
|
|
44
|
+
const known = Object.keys(config.profiles);
|
|
45
|
+
const listed = known.length > 0 ? known.sort().join(", ") : "(none defined)";
|
|
46
|
+
throw Errors.configInvalid(`unknown profile "${name}" — available profiles: ${listed}`);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
...config,
|
|
50
|
+
models: {
|
|
51
|
+
main: profile.main ?? config.models.main,
|
|
52
|
+
fast: profile.fast ?? config.models.fast,
|
|
53
|
+
},
|
|
54
|
+
worker: { maxTurns: profile.workerMaxTurns ?? config.worker.maxTurns },
|
|
55
|
+
review: { maxTurns: profile.reviewMaxTurns ?? config.review.maxTurns },
|
|
56
|
+
};
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glm-coding-router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "GLM Coding Plan workers for Claude Code and Codex",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"glm-router": "./dist/cli.js",
|
|
14
14
|
"glm-chat": "./dist/bin/glm-chat.js",
|
|
15
15
|
"glm-worker": "./dist/bin/glm-worker.js",
|
|
16
|
-
"glm-review": "./dist/bin/glm-review.js"
|
|
16
|
+
"glm-review": "./dist/bin/glm-review.js",
|
|
17
|
+
"glm-fast": "./dist/bin/glm-fast.js"
|
|
17
18
|
},
|
|
18
19
|
"files": [
|
|
19
20
|
"dist"
|