zcode-app-cli 3.3.6-3 → 3.3.6-5

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 CHANGED
@@ -1,5 +1,8 @@
1
1
  # zcode-app-cli
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/zcode-app-cli.svg?label=npm)](https://www.npmjs.com/package/zcode-app-cli)
4
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
5
+
3
6
  Unofficial terminal client for the official agent runtime shipped with ZCode Desktop.
4
7
 
5
8
  The project extracts the upstream `resources/glm` runtime, injects a local
@@ -12,9 +15,34 @@ This project is not affiliated with or endorsed by Z.ai. ZCode and its bundled
12
15
  runtime remain subject to their upstream terms. Confirm that you are allowed to
13
16
  redistribute the extracted runtime before publishing the npm package.
14
17
 
15
- ## Install and update
18
+ ![zcode-app-cli TUI demo](./docs/assets/demo.svg)
16
19
 
17
- Install or update the CLI through the `latest` dist-tag:
20
+ ## Quick start
21
+
22
+ ```bash
23
+ npm install -g zcode-app-cli@latest
24
+ zcode
25
+ ```
26
+
27
+ On first launch, ZCode creates `~/.zcode/cli/config.json` (or
28
+ `%USERPROFILE%\.zcode\cli\config.json` on Windows) with credential-free
29
+ defaults. Choose one of the three model-access paths in
30
+ [Configuration](./docs/CONFIGURATION.md) before sending your first prompt.
31
+
32
+ ## Table of contents
33
+
34
+ - [Quick start](#quick-start)
35
+ - [Install and update](#install-and-update)
36
+ - [Architecture](#architecture)
37
+ - [Features](#features)
38
+ - [Workspace integration](#workspace-integration)
39
+ - [Requirements](#requirements)
40
+ - [Configuration](#configuration)
41
+ - [Local development](#local-development)
42
+ - [Contributing](#contributing)
43
+ - [License](#license)
44
+
45
+ ## Install and update
18
46
 
19
47
  ```bash
20
48
  npm install -g zcode-app-cli@latest
@@ -26,13 +54,11 @@ Using `@latest` is intentional because the App-aligned release format uses a
26
54
  SemVer prerelease segment such as `3.3.5-2`. The tag always points to the
27
55
  newest validated App-plus-build release.
28
56
 
29
- Interactive startup checks the npm `latest` tag at most once every 20 hours.
30
- A cached newer version is shown as a non-blocking update card with the exact
31
- install command and release-notes link. Missing or stale cache data is refreshed
32
- in the background for the next launch, so registry latency or failure never
33
- delays the editor. Set `ZCODE_DISABLE_UPDATE_CHECK=1` or
34
- `NO_UPDATE_NOTIFIER=1` to disable the check; CI environments skip it
35
- automatically.
57
+ Interactive startup checks the npm `latest` tag at most once every 20 hours
58
+ per installed version and shows a cached newer version as a non-blocking
59
+ update card with the exact install command and release-notes link. CI
60
+ environments skip the check automatically. Set `ZCODE_DISABLE_UPDATE_CHECK=1`
61
+ or `NO_UPDATE_NOTIFIER=1` to disable it.
36
62
 
37
63
  A normal installation requires only Node.js and has no native PTY addon or
38
64
  postinstall build step.
@@ -50,48 +76,58 @@ Node.js npm launcher (config / login / version metadata)
50
76
  The official agent, model, session, tool, plugin, MCP, credential store and
51
77
  provider-configuration logic remains in the extracted runtime. The local
52
78
  package supplies the missing terminal interface and a narrow macOS callback
53
- bridge for Z.AI's registered Desktop OAuth flow.
54
-
55
- Node.js starts the public npm command and remains the compatibility host for the
56
- extracted upstream kernel. The official runtime directly owns raw terminal mode,
57
- IME cursor placement and resize handling; the launcher does not insert a second
58
- PTY or relay terminal bytes. Synchronization adds the local TUI/data bridge,
59
- OAuth compatibility handoff and clearer HTTP diagnostics. OAuth callbacks are
60
- passed to the official runtime over stdin; its encrypted credential store,
61
- Coding Plan key resolver and config writer remain the only persistence path.
62
-
63
- ## Current TUI functionality
64
-
65
- - pi-tui differential rendering and CJK-aware multi-line editor;
66
- - streamed assistant text from official ZCode session events;
67
- - slash-command and workspace-path completion;
68
- - persisted prompt history through ZCode's history API;
69
- - `/mode`, `/model`, `/resume`, `/plugins` and other upstream slash commands;
70
- - searchable model and reasoning-effort selectors, plus MCP and workflow panels;
71
- - status-bar-only Shift+Tab mode (`build` → `edit` → `yolo` → `plan`), Ctrl+N model and empty-prompt Tab effort cycling;
72
- - structured session-goal status in the right side of the turn footer;
73
- - animated active-turn timer with a static `ZCODE_TUI_REDUCED_MOTION=1` fallback;
74
- - responsive context-remaining and session-token metrics in the status line;
75
- - generic upstream selection dialogs for sessions, plugins and checkpoints;
76
- - `/login` setup choices with masked API-key entry, redacted transcript/history and OAuth waiting state;
77
- - suspended Z.AI browser login with terminal restoration and an optional `ZCODE_TUI_LOGIN_CMD` override;
78
- - interactive tool-permission approval dialogs;
79
- - clipboard image attachments through Ctrl+V or `/paste-image`, with a keyboard-selectable attachment row;
80
- - compact tool execution views with path, command, progress, result and image previews;
81
- - parent/child Agent tool trees with resumable subagent metadata and expandable Prompt/Response details;
82
- - syntax-highlighted Markdown code blocks with stable streaming-block rendering;
83
- - Pierre-style inline diffs with line numbers, syntax highlighting, word-level changes and CJK wrapping;
84
- - `/diff` browser for current Git changes and per-turn file changes, including paged details and binary/untracked states;
85
- - terminal-native Mermaid previews with source fallback for unsupported or oversized diagrams;
86
- - `/context` prompt-composition, cache and context-usage details;
87
- - `/status` session, runtime, goal, MCP and workspace details;
88
- - searchable transcript navigation with per-block expansion, selected-block copying and `n`/`N` match traversal;
89
- - persistent active-tool, background-task and open-plan activity between the transcript and editor;
90
- - active-turn steering, cancellation and error reporting;
91
- - unfocused turn-completion notifications through terminal-native OSC 9 or BEL, with optional desktop commands;
92
- - double-Esc rewind with input-point selection and safe conversation/workspace scopes;
93
- - `/copy`, `/clear`, `/exit`, Ctrl+C and Ctrl+D handling with token usage and resume guidance on exit;
94
- - `--no-color` and `NO_COLOR` support.
79
+ bridge for Z.AI's registered Desktop OAuth flow. Node.js starts the public npm
80
+ command and remains the compatibility host for the extracted upstream kernel.
81
+ The official runtime directly owns raw terminal mode, IME cursor placement and
82
+ resize handling; the launcher does not insert a second PTY or relay terminal
83
+ bytes.
84
+
85
+ ## Features
86
+
87
+ **Editor and input.** pi-tui differential rendering with a CJK-aware
88
+ multi-line editor; slash-command and workspace-path completion; persisted
89
+ prompt history through ZCode's history API; `--no-color` and `NO_COLOR`
90
+ support.
91
+
92
+ **Streaming and conversation.** Streamed assistant text from official ZCode
93
+ session events; `/mode`, `/model`, `/resume`, `/plugins` and other upstream
94
+ slash commands; searchable model and reasoning-effort selectors, plus MCP and
95
+ workflow panels; status-bar-only Shift+Tab mode cycling
96
+ (`build` → `edit` → `yolo` → `plan`), Ctrl+N model and empty-prompt Tab effort
97
+ cycling; structured session-goal status in the right side of the turn footer;
98
+ animated active-turn timer with a static `ZCODE_TUI_REDUCED_MOTION=1`
99
+ fallback; responsive context-remaining and session-token metrics.
100
+
101
+ **Login and permissions.** `/login` setup choices with masked API-key entry,
102
+ redacted transcript/history and OAuth waiting state; suspended Z.AI browser
103
+ login with terminal restoration and an optional `ZCODE_TUI_LOGIN_CMD`
104
+ override; interactive tool-permission approval dialogs.
105
+
106
+ **Attachments and rich output.** Clipboard image attachments through Ctrl+V
107
+ or `/paste-image`, with a keyboard-selectable attachment row; compact tool
108
+ execution views with path, command, progress, result and image previews;
109
+ parent/child Agent tool trees with resumable subagent metadata and expandable
110
+ Prompt/Response details; syntax-highlighted Markdown code blocks with stable
111
+ streaming-block rendering; Pierre-style inline diffs with line numbers,
112
+ syntax highlighting, word-level changes and CJK wrapping; terminal-native
113
+ Mermaid previews with source fallback for unsupported or oversized diagrams.
114
+
115
+ **Inspection and navigation.** `/diff` browser for current Git changes and
116
+ per-turn file changes; `/context` prompt-composition, cache and context-usage
117
+ details; `/status` session, runtime, goal, MCP and workspace details;
118
+ `/activity` and `/tasks` for active tools and background tasks; searchable
119
+ transcript navigation with per-block expansion, selected-block copying and
120
+ `n`/`N` match traversal; persistent active-tool, background-task and open-plan
121
+ activity between the transcript and editor.
122
+
123
+ **Steering, rewind and notifications.** Active-turn steering, cancellation
124
+ and error reporting; double-Esc rewind with input-point selection and safe
125
+ conversation/workspace scopes; unfocused turn-completion notifications through
126
+ terminal-native OSC 9 or BEL, with optional desktop commands; `/copy`,
127
+ `/clear`, `/exit`, Ctrl+C and Ctrl+D handling with token usage and resume
128
+ guidance on exit.
129
+
130
+ ## Workspace integration
95
131
 
96
132
  ### Referencing workspace files
97
133
 
@@ -145,68 +181,6 @@ Move the editor cursor to the start of its first line and press `Up`, or run
145
181
  Run `/attachments clear` to remove every pending image at once. `Ctrl+D`
146
182
  retains its terminal-standard empty-editor exit and forward-delete behavior.
147
183
 
148
- ### Theme
149
-
150
- Set `ui.theme` to `"auto"` (terminal detection), `"dark"`, or `"light"` in the
151
- user config: `~/.zcode/cli/config.json` on macOS/Linux or
152
- `%USERPROFILE%\.zcode\cli\config.json` on Windows. An explicit dark/light value
153
- takes priority over terminal probing. `auto` queries the terminal background
154
- color and color scheme at startup and re-applies the matching palette.
155
-
156
- ### Turn completion notifications
157
-
158
- Notifications are enabled by default and emitted after a normal agent turn
159
- completes or fails while the terminal is unfocused. Following Codex's terminal
160
- capability fallback, `auto` uses OSC 9 in Ghostty, iTerm2, Kitty, Warp and
161
- WezTerm, and BEL in terminals such as Apple Terminal. Selecting OSC 9 in an
162
- unsupported terminal also falls back to BEL instead of silently emitting an
163
- ignored sequence.
164
-
165
- The `unfocused` condition uses DEC focus reporting when the terminal provides
166
- it. Until focus support is confirmed, ZCode sends the notification instead of
167
- permanently suppressing it as focused. `native` is an explicit opt-in that uses
168
- an existing system command: `terminal-notifier` on macOS, `notify-send` on
169
- Linux, or `SnoreToast` on Windows. These tools are not bundled, keeping the
170
- default terminal notification path dependency-free. If the selected command is
171
- unavailable or delivery fails, ZCode falls back to BEL. On macOS, the detected
172
- terminal application is used as both the sender and click target. Exact tab or
173
- pane restoration remains terminal-dependent; use the default `auto` setting so
174
- OSC-capable terminals can preserve their native session behavior.
175
-
176
- Open the interactive settings picker inside the TUI (both commands are
177
- equivalent):
178
-
179
- ```text
180
- /config
181
- /settings
182
- ```
183
-
184
- Saving a value returns to the settings root so several options can be changed
185
- in one visit. `Esc` returns from a setting to the root, then closes the root.
186
-
187
- The picker updates the active session immediately and persists the selected
188
- values under `ui.notifications` in the cross-platform user `config.json`:
189
-
190
- ```json
191
- {
192
- "ui": {
193
- "notifications": {
194
- "method": "auto",
195
- "condition": "unfocused"
196
- }
197
- }
198
- }
199
- ```
200
-
201
- Environment variables override `config.json` on startup and are useful for a
202
- temporary per-shell setting:
203
-
204
- ```bash
205
- export ZCODE_TUI_NOTIFICATION_METHOD=auto # auto|osc9|bel|native|off
206
- export ZCODE_TUI_NOTIFICATION_CONDITION=always # unfocused|always
207
- node bin/zcode.js
208
- ```
209
-
210
184
  ### Conversation rewind
211
185
 
212
186
  With an empty editor and no active turn, press `Esc` twice within 800 ms to
@@ -252,9 +226,6 @@ an oversized selected block without rendering the entire message at once.
252
226
  - Node.js 22.19 or newer;
253
227
  - macOS, Linux or Windows on x64 or ARM64.
254
228
 
255
- Developing or publishing from source additionally requires Bun 1.3 or newer.
256
- `7z` is needed only when downloading and extracting a remote installer.
257
-
258
229
  Z.AI browser OAuth currently requires macOS because the registered provider
259
230
  callback is `zcode://zai-auth/callback`; API-key and custom-provider access work
260
231
  on every supported platform.
@@ -262,201 +233,26 @@ on every supported platform.
262
233
  Set `ZCODE_NODE=/absolute/path/to/node` when the desired Node.js executable is
263
234
  not available on `PATH`.
264
235
 
265
- ## Model access and configuration
266
-
267
- On first launch, ZCode recursively creates the configuration directory and a
268
- credential-free `config.json` when it is missing. Existing files are never
269
- replaced. The location is `~/.zcode/cli/config.json` on macOS and Linux, and
270
- `%USERPROFILE%\.zcode\cli\config.json` on Windows. Newly created directories
271
- and files use private permissions on POSIX; Windows keeps the current user's
272
- inherited ACLs.
273
-
274
- The generated file contains the complete non-secret configuration shape plus
275
- valid Z.AI model metadata, but deliberately omits `apiKey` until one is
276
- configured. This lets the official runtime and TUI start cleanly without
277
- pretending that model access is already configured. Choose one of these
278
- model-access paths before sending a prompt:
279
-
280
- - Z.AI OAuth on macOS: run `zcode login` when no provider is configured, or
281
- `zcode login --oauth` to force reauthorization;
282
- - Z.AI/BigModel Coding Plan API key: open `/login` in the TUI and choose the
283
- matching masked API-key option;
284
- - direct API key with a custom provider: use the
285
- [`config.example.json`](./config.example.json) template and do not log in.
286
-
287
- When `model.main` already resolves to a configured provider/model with an
288
- inline API key, plain `zcode login` exits successfully and explains that OAuth
289
- is unnecessary. This prevents a custom provider from being replaced by an
290
- unrelated login flow.
291
-
292
- ### Coding Plan API key
293
-
294
- Start the TUI and open its setup picker:
295
-
296
- ```text
297
- /login
298
- ```
299
-
300
- Choose either **Z.AI Coding Plan API Key** or **BigModel Coding Plan API Key**,
301
- then paste the key into the masked prompt. The raw key is sent only to the
302
- official runtime's `configureCodingPlanApiKey` implementation. The local TUI
303
- does not add it to editor history or the visible/session transcript, and error
304
- messages are redacted before rendering.
305
-
306
- The same picker includes a **Custom provider** entry that points to the
307
- configuration-template path below. Custom providers do not use OAuth.
308
-
309
- Selecting **Z.AI Coding Plan** releases TUI raw mode and starts the registered
310
- Desktop authorization-code flow. On macOS the CLI temporarily installs a
311
- background-only callback receiver, verifies the returned `state`, restores the
312
- previous `zcode://` handler, and hands the callback to the official runtime.
313
- The authorization code travels over stdin instead of command-line arguments or
314
- environment variables. The runtime performs token exchange, encrypted
315
- credential persistence, Coding Plan API-key resolution and `config.json`
316
- updates. The TUI is then restored and the model configuration is re-read.
317
-
318
- The callback receiver is removed after success, cancellation or timeout. A
319
- small recovery record lets the next login restore the previous handler after
320
- an unclean process exit. The BigModel option continues to use the official
321
- localhost-callback implementation inside the runtime.
322
-
323
- ### Custom provider without login
324
-
325
- Start `zcode` once to generate the full user configuration automatically. From
326
- a source checkout, `config.example.json` contains the same initial structure
327
- for reference. Then edit the generated file:
328
-
329
- ```bash
330
- zcode
331
- ```
332
-
333
- Edit these four areas in `~/.zcode/cli/config.json` (or the Windows path shown
334
- above):
335
-
336
- 1. `provider.zai.kind`: use `anthropic`, `openai-compatible`, or `openai`;
337
- 2. `provider.zai.options.baseURL`: use the provider's API root;
338
- 3. `provider.zai.options.apiKey`: insert the direct API key;
339
- 4. replace the entries in `provider.zai.models`, then point both `model.main`
340
- and `model.lite` at the desired model IDs.
341
-
342
- The provider map key is deliberately `zai`. The upstream CLI 0.15.x TUI
343
- considers a direct API key configured only when it is stored under provider ID
344
- `zai` or `bigmodel`. An arbitrary provider ID is valid model configuration,
345
- but as the only provider it still triggers the upstream login gate. The
346
- display name, API format, endpoint, headers and models remain fully custom.
347
-
348
- For an Anthropic-compatible endpoint:
349
-
350
- ```json
351
- {
352
- "kind": "anthropic",
353
- "options": {
354
- "baseURL": "https://example.com/api/anthropic",
355
- "apiKey": "YOUR_API_KEY",
356
- "apiKeyRequired": true
357
- }
358
- }
359
- ```
360
-
361
- Use the API root, not a final `/messages` path. For an OpenAI-compatible
362
- endpoint, set `kind` to `openai-compatible` and normally use a root ending in
363
- `/v1`, not `/chat/completions`. For the official OpenAI API, use `openai`;
364
- `baseURL` can be omitted.
365
-
366
- The object keys form the runtime model reference:
367
-
368
- ```text
369
- provider.<provider-id>.models.<model-id>
370
- -> <provider-id>/<model-id>
371
- ```
372
-
373
- Set both roles to keep all work on the custom provider:
374
-
375
- ```json
376
- {
377
- "model": {
378
- "main": "zai/your-model-id",
379
- "lite": "zai/your-model-id"
380
- }
381
- }
382
- ```
383
-
384
- `main` is the normal conversation model. `lite` is used for lightweight and
385
- subagent work. Model IDs are case-sensitive and must match the endpoint.
386
-
387
- The no-login TUI path currently requires a non-empty `options.apiKey` in the
388
- local config; an environment-only API key does not satisfy the upstream login
389
- gate. Never commit the populated file, and keep its mode at `600`.
390
-
391
- ### Use the custom provider
392
-
393
- After saving the config, no login command is required. Start the client:
394
-
395
- ```bash
396
- node bin/zcode.js
397
- ```
398
-
399
- Or, after `bun link` or an npm installation:
400
-
401
- ```bash
402
- zcode
403
- ```
404
-
405
- Use these commands inside the TUI:
406
-
407
- ```text
408
- /model # show the active and available models
409
- /model zai/your-model-id # switch to the custom provider explicitly
410
- /new # start a new session with the configured default
411
- ```
412
-
413
- The status line should show `zai/your-model-id`. Setting both `model.main` and
414
- `model.lite` in the config makes the custom provider the default for normal,
415
- lightweight and subagent work. A resumed session may retain its previous model,
416
- so use `/new` after changing the default.
417
-
418
- Headless prompts use the same provider configuration:
419
-
420
- ```bash
421
- zcode --prompt "Explain this repository"
422
- ```
423
-
424
- `ZCODE_MODEL`, `zcode.json`, or `.zcode/config.json` can override the
425
- user-level default. Running `/model` does not call the provider, so it is a safe
426
- configuration check before the first prompt.
427
-
428
- ### Request retries and stalled streams
429
-
430
- The CLI leaves retry classification and execution to the official ZCode
431
- runtime. It supplies a default retry budget of five retries; override it when
432
- needed with the runtime's own environment variable:
236
+ ## Configuration
433
237
 
434
- ```bash
435
- ZCODE_MODEL_RETRY_MAX_RETRIES=3 zcode
436
- ```
437
-
438
- Newly generated configs use a 60-second model-stream idle timeout:
439
-
440
- ```json
441
- {
442
- "modelStream": {
443
- "idleTimeoutMs": 60000
444
- }
445
- }
446
- ```
238
+ ZCode reads configuration from `~/.zcode/cli/config.json` (or
239
+ `%USERPROFILE%\.zcode\cli\config.json` on Windows), with project-level
240
+ overrides from `zcode.json` or `.zcode/config.json` in the working directory.
241
+ Existing files are never replaced.
447
242
 
448
- Existing configs are never overwritten, so update this field manually if an
449
- older generated file still contains `600000`. Retryable timeouts, dropped
450
- streams, rate limits and server/network errors are retried and shown in the
451
- TUI. Authentication and invalid-request responses remain non-retryable.
243
+ Three model-access paths are supported: Z.AI OAuth (macOS only), Z.AI/BigModel
244
+ Coding Plan API key, or a direct API key with a custom provider. For detailed
245
+ setup steps, retries/timeouts, theme, and turn-completion notifications, see
246
+ [Configuration](./docs/CONFIGURATION.md).
452
247
 
453
248
  ## Local development
454
249
 
455
- Install dependencies and extract the already installed macOS application:
250
+ Install dependencies and start the client with live TypeScript and auto-sync
251
+ from the local ZCode Desktop installation:
456
252
 
457
253
  ```bash
458
254
  bun install
459
- bun run sync:local
255
+ bun run dev
460
256
  ```
461
257
 
462
258
  Run all validation layers:
@@ -468,262 +264,18 @@ bun run check
468
264
  bun run check:tui
469
265
  ```
470
266
 
471
- `check:tui` runs real-PTY scenarios. The official runtime scenario completes
472
- masked Coding Plan API-key setup in a temporary home, verifies the official
473
- config output, executes `/help`, switches to plan mode, exits, and checks that
474
- the launcher forwards terminal SIGHUP shutdown. The offline
475
- feature scenario also covers suspended login restoration, selectors, image
476
- attachments, nested Agent tools, Markdown, Mermaid, diffs, transcript
477
- navigation, context/status details, MCP actions, background tasks and the
478
- workflow panel. A pressure scenario verifies that steering, UTF-8 input and
479
- Ctrl+C cancellation remain responsive during rapid Bash progress output. The
480
- scenarios advance from observed terminal output instead of fixed timers and do
481
- not make model API calls.
482
-
483
- Start the client directly:
484
-
485
- ```bash
486
- node bin/zcode.js
487
- ```
488
-
489
- For the OAuth path:
490
-
491
- ```bash
492
- node bin/zcode.js login --oauth
493
- node bin/zcode.js
494
- ```
495
-
496
- To print the authorization URL without launching the browser:
497
-
498
- ```bash
499
- node bin/zcode.js login --oauth --no-browser
500
- ```
501
-
502
- The URL must still be opened on the same Mac so its `zcode://` callback reaches
503
- the waiting CLI. Cross-device SSH login is not supported by this provider flow;
504
- use the masked Z.AI Coding Plan API-key option instead. The wrapper no longer
505
- uses the upstream `oauth/cli/init` polling endpoint, which currently returns
506
- HTTP 404.
507
-
508
- Verify native callback capture and automatic handler restoration without
509
- contacting Z.AI or changing the real `zcode://` association:
510
-
511
- ```bash
512
- bun run check:oauth-callback
513
- ```
514
-
515
- ### Continuous integration
516
-
517
- `.github/workflows/ci.yml` runs for pull requests, pushes to `main` and manual
518
- dispatches. It validates the project on the minimum supported Node.js 22.19,
519
- including the locked runtime build, TypeScript and unit tests, PTY scenarios,
520
- the reviewed npm tarball and an isolated installed-package smoke test. A newer
521
- commit to the same pull request or branch automatically cancels its superseded
522
- CI run; unrelated pull requests continue independently.
523
-
524
- To hand `/login` to another interactive command, set an explicit override:
525
-
526
- ```bash
527
- export ZCODE_TUI_LOGIN_CMD='zcode login --oauth'
528
- ```
529
-
530
- The TUI then releases raw terminal mode, runs that command with inherited
531
- stdio, restores the interface, and checks `~/.zcode/cli/config.json` again.
532
-
533
- For the direct API-key path, follow
534
- [Custom provider without login](#custom-provider-without-login) instead.
535
-
536
- Install a local `zcode` command:
537
-
538
- ```bash
539
- bun link
540
- zcode
541
- ```
542
-
543
- Headless and protocol commands use the same inherited stdio path:
544
-
545
- ```bash
546
- zcode --version
547
- zcode doctor --json
548
- zcode --prompt "Explain this repository"
549
- zcode app-server
550
- ```
551
-
552
- ## Remote extraction
553
-
554
- The same path used by CI can be run locally:
555
-
556
- ```bash
557
- brew install sevenzip
558
- bun run sync -- --platform linux --arch x64
559
- ```
560
-
561
- Use the committed artifact instead of the latest updater manifest when
562
- rebuilding a reviewed release:
563
-
564
- ```bash
565
- bun run sync:locked
566
- ```
567
-
568
- The synchronization command:
569
-
570
- 1. reads the official updater manifest;
571
- 2. downloads the matching installer;
572
- 3. verifies its SHA-512 from the manifest;
573
- 4. extracts `resources/glm`;
574
- 5. builds and injects the local `@zcode/tui` adapter;
575
- 6. validates the official CLI version;
576
- 7. records provenance in `vendor/extraction.json`;
577
- 8. records the remote artifact URL and SHA-512 in
578
- `zcode-runtime.lock.json`;
579
- 9. aligns the npm version prefix with the ZCode App version while preserving
580
- the independently incremented CLI build revision.
581
-
582
- ## npm package contents
583
-
584
- The published package is controlled by the `files` allowlist in `package.json`.
585
- It contains only:
586
-
587
- - `bin/zcode.js`, the bundled executable Node.js launcher;
588
- - `vendor/`, the verified official `zcode.cjs` runtime, official bundled
589
- plugins and the compiled local `@zcode/tui` adapter;
590
- - `config.example.json` and `zcode-runtime.lock.json`;
591
- - `README.md`, `LICENSE` and the required npm `package.json`.
592
-
593
- Tests, GitHub workflows, build scripts, launcher/TUI TypeScript sources, local
594
- config, `.release/` artifacts and development `node_modules` are not published.
595
- npm installs only the declared pi-tui runtime dependency. The launcher and TUI
596
- are compiled to JavaScript with `tsdown`; its launcher banner adds the Node.js
597
- shebang directly, with no post-build rewrite. The compiled TUI is injected into
598
- `vendor/` before publication.
599
-
600
- ## Automated npm publishing
601
-
602
- Package versions use `<app-version>-<build>`, for example `3.3.5-2`. The prefix
603
- tracks the upstream ZCode App. The globally increasing build revision tracks
604
- fixes and features in this project. Do not use `3.3.5+build.2`: SemVer ignores
605
- `+build` metadata when comparing upgrades.
606
-
607
- Increment the project revision before publishing a local fix or feature:
608
-
609
- ```bash
610
- bun run version:build
611
- ```
612
-
613
- The release workflows normally perform that increment for you. The command is
614
- also available for local inspection and exceptional manual preparation.
615
-
616
- ### Release flow
617
-
618
- Publishing is split into two workflows so the committed version, npm package,
619
- Git tag and GitHub Release all describe the same release:
620
-
621
- 1. `.github/workflows/prepare-release.yml` extracts and validates the current
622
- official runtime, then opens or updates a Release PR containing the exact
623
- `package.json` version and `zcode-runtime.lock.json` build input;
624
- 2. a maintainer reviews and merges that PR;
625
- 3. `.github/workflows/publish.yml` checks out its merge commit, rebuilds the
626
- exact locked runtime, audits and install-tests the tarball, publishes through
627
- npm Trusted Publishing, then creates `v<version>` and the corresponding
628
- GitHub Release.
629
-
630
- The generated `vendor/` directory remains ignored by Git and is rebuilt in both
631
- workflows. Its updater URL and SHA-512 are committed in
632
- `zcode-runtime.lock.json`. Preparation resolves the latest manifest; publishing
633
- downloads the committed URL and verifies the locked SHA-512, so a later upstream
634
- update cannot silently change a reviewed release.
635
-
636
- The preparation workflow runs every day at 02:23 UTC in `upstream` mode. It
637
- creates a PR when the ZCode App version or the pinned installer changes. A
638
- same-version upstream repack increments the global build so npm still receives
639
- an immutable new version. From the Actions page, run **Prepare ZCode CLI
640
- release** with one of these modes:
641
-
642
- - `cli` increments the global build and also aligns with the latest App;
643
- - `upstream` checks for an App update without incrementing the build.
267
+ For the OAuth path, release workflow details, CI, and the full development
268
+ guide, see [Development](./docs/DEVELOPMENT.md). For maintainer-only release
269
+ and publishing workflows, see [Releasing](./docs/RELEASING.md).
644
270
 
645
- The modes use `release/zcode-cli` and `release/zcode-upstream` respectively. If
646
- both PRs are open, merge one and rerun the other preparation mode so its version
647
- is recalculated from the new `main` branch.
271
+ ## Contributing
648
272
 
649
- Merging either Release PR publishes automatically. **Publish ZCode CLI
650
- release** can also be started manually for recovery. Its `publish` checkbox can
651
- be disabled to run all validation and consistency checks without changing npm,
652
- Git tags or GitHub Releases. Publication, tag creation and GitHub Release
653
- creation are independently idempotent, so a partially completed run can be
654
- retried safely.
273
+ Issues and pull requests are welcome at
274
+ [github.com/kingsword09/zcode-cli](https://github.com/kingsword09/zcode-cli).
275
+ Please open an issue first to discuss substantial changes. See
276
+ [Development](./docs/DEVELOPMENT.md) for the local setup and validation
277
+ commands, and [Releasing](./docs/RELEASING.md) for the release flow.
655
278
 
656
- ### Local release build
657
-
658
- Local packaging uses the same commands as the publishing workflow. Start from
659
- the exact clean commit whose version will be published:
660
-
661
- ```bash
662
- bun install --frozen-lockfile
663
- bun run release:build
664
- git diff --exit-code -- package.json zcode-runtime.lock.json
665
- bun run release:pack
666
- ```
667
-
668
- `release:build` runs TypeScript checking and all tests, downloads the artifact
669
- from `zcode-runtime.lock.json`, verifies its SHA-512, builds and injects the TUI,
670
- then runs runtime and PTY smoke tests. `release:pack` runs the offline
671
- `prepack` guard, creates `.release/zcode-app-cli-<version>.tgz`, audits every
672
- included path and executable mode, installs it into a temporary directory, and
673
- runs the installed `zcode --version`. Its final size, integrity and file count
674
- are written to `.release/release.json`.
675
-
676
- Inspect that manifest and then publish explicitly:
677
-
678
- ```bash
679
- npm login
680
- npm publish --access public --tag latest --provenance=false
681
- ```
279
+ ## License
682
280
 
683
- The final `npm publish` intentionally remains explicit to avoid an accidental
684
- registry mutation. It reruns the same offline `prepack` guard and fails if the
685
- compiled TUI, runtime provenance, lock file, launcher permissions or package
686
- allowlist are stale. `--provenance=false` applies only to this local bootstrap
687
- path; GitHub OIDC generates provenance automatically.
688
-
689
- Publish from the repository root as shown, rather than passing the `.tgz` to
690
- `npm publish`: directory publication lets npm record the current Git `gitHead`,
691
- which the recovery workflow later verifies. The tarball is the audited preview
692
- and install-test artifact.
693
-
694
- ### Initial npm setup
695
-
696
- If the package does not exist on npm yet, bootstrap it once from the exact
697
- committed `main` revision using the local release build above. If its Git diff
698
- check fails, do not publish from that working tree; refresh the Release PR or
699
- restore the committed version and lock first.
700
-
701
- Synchronization preserves the build when the upstream App version changes. For
702
- example, syncing `3.3.5-12` against ZCode App `3.4.0` produces `3.4.0-12`.
703
-
704
- Before enabling publication:
705
-
706
- 1. confirm that `zcode-app-cli` is the npm package name you control;
707
- 2. confirm redistribution rights for the extracted ZCode runtime;
708
- 3. under the GitHub repository's **Settings** → **Actions** → **General**,
709
- enable **Allow GitHub Actions to create and approve pull requests**;
710
- 4. open the package on npmjs.com and select **Settings** →
711
- **Trusted Publisher** → **GitHub Actions**;
712
- 5. enter the GitHub organization or user, repository, and workflow filename
713
- `publish.yml`; leave the environment name empty because this
714
- workflow does not use a GitHub Environment, and select `npm publish` under
715
- **Allowed actions**;
716
- 6. save the publisher, prepare a `cli` release, and merge its Release PR to
717
- verify an OIDC publication.
718
-
719
- The publisher runs on a GitHub-hosted runner with Node 24, grants
720
- `id-token: write`, and updates npm to the current release. It never reads an
721
- `NPM_TOKEN` repository secret; npm attaches provenance from the OIDC identity.
722
- After verifying the first OIDC release, npm recommends setting **Publishing
723
- access** to require 2FA and disallow tokens, then revoking any obsolete
724
- automation token.
725
-
726
- The publisher skips an identical existing version, refuses older versions,
727
- verifies every existing npm release's `gitHead`, and refuses to reuse a tag
728
- that points at another commit. The `latest` dist-tag therefore advances only
729
- to the newest validated App-plus-build release.
281
+ MIT — see [LICENSE](./LICENSE).
package/bin/zcode.js CHANGED
@@ -619,24 +619,44 @@ async function runZaiOAuthLogin(options) {
619
619
  //#region src/launcher.ts
620
620
  const packageRoot = join(dirname(fileURLToPath(import.meta.url)), "..");
621
621
  const packageManifestPath = join(packageRoot, "package.json");
622
+ const extractionMetadataPath = join(packageRoot, "vendor", "extraction.json");
622
623
  const runtimePath = join(packageRoot, "vendor", "zcode.cjs");
623
624
  const launcherPath = join(packageRoot, "bin", "zcode.js");
624
625
  const defaultModelRetryMaxRetries = "5";
626
+ const versionArguments = /* @__PURE__ */ new Set([
627
+ "version",
628
+ "--version",
629
+ "-v"
630
+ ]);
625
631
  function resolveModelRetryMaxRetries(env) {
626
632
  return env.ZCODE_MODEL_RETRY_MAX_RETRIES?.trim() || defaultModelRetryMaxRetries;
627
633
  }
628
634
  function resolveNodeExecutable() {
629
635
  return process.env.ZCODE_NODE?.trim() || process.execPath;
630
636
  }
631
- function readDistributionVersion(manifestPath = packageManifestPath) {
637
+ function safeVersion(value) {
638
+ const version = typeof value === "string" ? value.trim() : "";
639
+ return /^[0-9A-Za-z][0-9A-Za-z.+-]{0,63}$/u.test(version) ? version : void 0;
640
+ }
641
+ function readJsonVersion(path, key) {
632
642
  try {
633
- const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
634
- const version = typeof manifest.version === "string" ? manifest.version.trim() : "";
635
- return /^[0-9A-Za-z][0-9A-Za-z.+-]{0,63}$/u.test(version) ? version : void 0;
643
+ return safeVersion(JSON.parse(readFileSync(path, "utf8"))[key]);
636
644
  } catch {
637
645
  return;
638
646
  }
639
647
  }
648
+ function readDistributionVersion(manifestPath = packageManifestPath) {
649
+ return readJsonVersion(manifestPath, "version");
650
+ }
651
+ function readRuntimeVersion(metadataPath = extractionMetadataPath) {
652
+ return readJsonVersion(metadataPath, "cliVersion");
653
+ }
654
+ function isVersionInvocation(args) {
655
+ return args.length === 1 && versionArguments.has(args[0]);
656
+ }
657
+ function formatVersionOutput(distributionVersion, runtimeVersion) {
658
+ return [`zcode-app-cli ${safeVersion(distributionVersion) ?? "unknown"}`, `zcode-runtime ${safeVersion(runtimeVersion) ?? "unknown"}`].join("\n");
659
+ }
640
660
  function normalizeLoginArgs(args) {
641
661
  if (args.length === 1 && args[0] === "login") return {
642
662
  args,
@@ -736,6 +756,16 @@ async function main(args) {
736
756
  console.error("ZCode runtime is missing. Reinstall the package or run `bun run sync:local` in the source checkout.");
737
757
  return 1;
738
758
  }
759
+ if (isVersionInvocation(args)) {
760
+ const distributionVersion = readDistributionVersion();
761
+ const runtimeVersion = readRuntimeVersion();
762
+ if (!distributionVersion || !runtimeVersion) {
763
+ console.error("Unable to read npm package or bundled runtime version metadata.");
764
+ return 1;
765
+ }
766
+ console.log(formatVersionOutput(distributionVersion, runtimeVersion));
767
+ return 0;
768
+ }
739
769
  try {
740
770
  await ensureUserConfig();
741
771
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcode-app-cli",
3
- "version": "3.3.6-3",
3
+ "version": "3.3.6-5",
4
4
  "description": "Unofficial terminal client for the ZCode agent runtime",
5
5
  "keywords": [
6
6
  "agent",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "appVersion": "3.3.6",
3
3
  "cliVersion": "0.15.2",
4
- "extractedAt": "2026-07-17T03:15:27.269Z",
4
+ "extractedAt": "2026-07-17T13:48:49.896Z",
5
5
  "sha512": "NwQzSBf+Q5FR3VWwAEQUeALHR9jvDjRT7PJLVQ4iLOyTxPm7Lt8kMQbQXI7MJ/wEDQ0EK3FBBjJQVlJiC4Kgsw==",
6
6
  "source": "https://cdn-zcode.z.ai/zcode/electron/releases/3.3.6/linux-x64/ZCode-3.3.6-linux-x64.deb",
7
7
  "tui": {
@@ -276,7 +276,9 @@ function parseUpdateCache(value) {
276
276
  const cache = value;
277
277
  if (typeof cache.latestVersion !== "string" || !parseReleaseVersion(cache.latestVersion)) return void 0;
278
278
  if (typeof cache.lastCheckedAt !== "string" || !Number.isFinite(Date.parse(cache.lastCheckedAt))) return void 0;
279
+ if (cache.checkedVersion !== void 0 && (typeof cache.checkedVersion !== "string" || !parseReleaseVersion(cache.checkedVersion))) return;
279
280
  return {
281
+ checkedVersion: cache.checkedVersion,
280
282
  latestVersion: cache.latestVersion,
281
283
  lastCheckedAt: cache.lastCheckedAt
282
284
  };
@@ -295,13 +297,17 @@ async function readStartupUpdate(options) {
295
297
  const cache = await readUpdateCache(cachePath);
296
298
  const now = options.now ?? Date.now();
297
299
  const checkedAt = cache ? Date.parse(cache.lastCheckedAt) : NaN;
298
- const refreshRequired = !cache || checkedAt < now - 72e6;
300
+ const refreshRequired = !cache || cache.checkedVersion !== options.currentVersion || checkedAt < now - 72e6;
299
301
  return {
300
- availableVersion: cache && compareReleaseVersions(cache.latestVersion, options.currentVersion) > 0 ? cache.latestVersion : void 0,
302
+ availableVersion: cache ? availableUpdateVersion(options.currentVersion, cache.latestVersion) : void 0,
301
303
  cachePath,
302
304
  refreshRequired
303
305
  };
304
306
  }
307
+ function availableUpdateVersion(currentVersion, latestVersion) {
308
+ if (!parseReleaseVersion(currentVersion) || !parseReleaseVersion(latestVersion)) return void 0;
309
+ return compareReleaseVersions(latestVersion, currentVersion) > 0 ? latestVersion : void 0;
310
+ }
305
311
  async function writeUpdateCache(cachePath, cache) {
306
312
  const directory = dirname(cachePath);
307
313
  const temporaryPath = join(directory, `.version.${process.pid}.${randomUUID()}.tmp`);
@@ -341,6 +347,7 @@ async function refreshUpdateCache(options) {
341
347
  const latestVersion = typeof body === "object" && body !== null && !Array.isArray(body) ? body.version : void 0;
342
348
  if (typeof latestVersion !== "string" || !parseReleaseVersion(latestVersion)) throw new Error("npm registry returned an invalid release version.");
343
349
  await writeUpdateCache(options.cachePath, {
350
+ checkedVersion: options.currentVersion,
344
351
  latestVersion,
345
352
  lastCheckedAt: new Date(options.now ?? Date.now()).toISOString()
346
353
  });
@@ -163451,6 +163458,7 @@ const toolLifecycleEventKinds = /* @__PURE__ */ new Set([
163451
163458
  ]);
163452
163459
  const terminalThemeQueryTimeoutMs = 100;
163453
163460
  const exitUsageQueryTimeoutMs = 250;
163461
+ const updateAvailableBlockId = "update_available";
163454
163462
  function modelRetryProgress(event, phase) {
163455
163463
  const retryNumber = phase === "started" ? Math.max(1, (event.attempt ?? 2) - 1) : Math.max(1, (event.nextAttempt ?? (event.attempt ?? 1) + 1) - 1);
163456
163464
  const maxRetries = event.maxRetries ?? (event.maxAttempts !== void 0 ? Math.max(1, event.maxAttempts - 1) : void 0);
@@ -164608,8 +164616,8 @@ var ZCodeTui = class {
164608
164616
  this.ui.requestRender();
164609
164617
  }
164610
164618
  addUpdateAvailable(currentVersion, latestVersion) {
164611
- this.currentToolGroup = void 0;
164612
164619
  this.transcript.addBlock(new UpdateAvailableView(this.theme, currentVersion, latestVersion), {
164620
+ id: updateAvailableBlockId,
164613
164621
  kind: "update",
164614
164622
  searchText: `Update available: ${currentVersion} -> ${latestVersion}\n${updateCommand}`
164615
164623
  });
@@ -164617,12 +164625,17 @@ var ZCodeTui = class {
164617
164625
  }
164618
164626
  startUpdateRefresh(updateCheck) {
164619
164627
  if (!updateCheck?.refreshRequired || !this.distributionVersion) return;
164628
+ const currentVersion = this.distributionVersion;
164620
164629
  const controller = new AbortController();
164621
164630
  this.updateCheckAbortController = controller;
164622
164631
  refreshUpdateCache({
164623
164632
  cachePath: updateCheck.cachePath,
164624
- currentVersion: this.distributionVersion,
164633
+ currentVersion,
164625
164634
  signal: controller.signal
164635
+ }).then((latestVersion) => {
164636
+ const availableVersion = availableUpdateVersion(currentVersion, latestVersion);
164637
+ if (availableVersion) this.addUpdateAvailable(currentVersion, availableVersion);
164638
+ else if (updateCheck.availableVersion && this.transcript.removeBlock(updateAvailableBlockId)) this.ui.requestRender();
164626
164639
  }).catch(() => {}).finally(() => {
164627
164640
  if (this.updateCheckAbortController === controller) this.updateCheckAbortController = void 0;
164628
164641
  });