zcode-app-cli 3.3.5-1 → 3.3.6-3

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
@@ -5,8 +5,8 @@ Unofficial terminal client for the official agent runtime shipped with ZCode Des
5
5
  The project extracts the upstream `resources/glm` runtime, injects a local
6
6
  `@zcode/tui` implementation based on
7
7
  [`@earendil-works/pi-tui`](https://github.com/earendil-works/pi/tree/main/packages/tui),
8
- and starts it through the native [`zigpty`](https://github.com/pithings/zigpty)
9
- PTY binding for Node.js.
8
+ and launches it as a Node.js child process that directly inherits the user's
9
+ terminal.
10
10
 
11
11
  This project is not affiliated with or endorsed by Z.ai. ZCode and its bundled
12
12
  runtime remain subject to their upstream terms. Confirm that you are allowed to
@@ -26,19 +26,25 @@ Using `@latest` is intentional because the App-aligned release format uses a
26
26
  SemVer prerelease segment such as `3.3.5-2`. The tag always points to the
27
27
  newest validated App-plus-build release.
28
28
 
29
- A normal installation requires only Node.js. `zigpty` ships small prebuilt
30
- native bindings for each supported platform, with no compiler or postinstall
31
- step required.
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.
36
+
37
+ A normal installation requires only Node.js and has no native PTY addon or
38
+ postinstall build step.
32
39
 
33
40
  ## Architecture
34
41
 
35
42
  ```text
36
- Node.js npm launcher
37
- └─ zigpty (PTY / resize / input forwarding)
38
- └─ Node.js
39
- └─ official zcode.cjs agent runtime
40
- └─ local @zcode/tui adapter
41
- └─ @earendil-works/pi-tui
43
+ Node.js npm launcher (config / login / version metadata)
44
+ └─ inherited stdin / stdout / stderr
45
+ └─ official zcode.cjs agent runtime
46
+ └─ local @zcode/tui adapter
47
+ └─ @earendil-works/pi-tui
42
48
  ```
43
49
 
44
50
  The official agent, model, session, tool, plugin, MCP, credential store and
@@ -47,12 +53,12 @@ package supplies the missing terminal interface and a narrow macOS callback
47
53
  bridge for Z.AI's registered Desktop OAuth flow.
48
54
 
49
55
  Node.js starts the public npm command and remains the compatibility host for the
50
- extracted upstream kernel. `zigpty` owns the native terminal while the official
51
- runtime stays in a separate PTY child process. Synchronization adds the local
52
- TUI/data bridge, OAuth compatibility handoff and clearer HTTP diagnostics. OAuth
53
- callbacks are passed to the official runtime over stdin; its encrypted credential
54
- store, Coding Plan key resolver and config writer remain the only persistence
55
- path.
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.
56
62
 
57
63
  ## Current TUI functionality
58
64
 
@@ -62,14 +68,15 @@ path.
62
68
  - persisted prompt history through ZCode's history API;
63
69
  - `/mode`, `/model`, `/resume`, `/plugins` and other upstream slash commands;
64
70
  - searchable model and reasoning-effort selectors, plus MCP and workflow panels;
65
- - status-bar-only Shift+Tab mode, Ctrl+N model, Ctrl+L autonomy and empty-prompt Tab effort cycling;
71
+ - status-bar-only Shift+Tab mode (`build` → `edit` → `yolo` → `plan`), Ctrl+N model and empty-prompt Tab effort cycling;
66
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;
67
74
  - responsive context-remaining and session-token metrics in the status line;
68
75
  - generic upstream selection dialogs for sessions, plugins and checkpoints;
69
76
  - `/login` setup choices with masked API-key entry, redacted transcript/history and OAuth waiting state;
70
77
  - suspended Z.AI browser login with terminal restoration and an optional `ZCODE_TUI_LOGIN_CMD` override;
71
78
  - interactive tool-permission approval dialogs;
72
- - clipboard image attachments through Ctrl+V or `/paste-image`;
79
+ - clipboard image attachments through Ctrl+V or `/paste-image`, with a keyboard-selectable attachment row;
73
80
  - compact tool execution views with path, command, progress, result and image previews;
74
81
  - parent/child Agent tool trees with resumable subagent metadata and expandable Prompt/Response details;
75
82
  - syntax-highlighted Markdown code blocks with stable streaming-block rendering;
@@ -102,6 +109,50 @@ Suggestions come from the official ZCode runtime, stay inside the current
102
109
  workspace and exclude common repository metadata and dependency directories.
103
110
  Paths containing spaces are inserted in the quoted `@"..."` form.
104
111
 
112
+ ### Active-turn input
113
+
114
+ While a regular agent turn is running, press `Enter` to send the current text
115
+ as same-turn steering. Until the official runtime reaches a safe model-step
116
+ boundary, the steer stays in a waiting row next to the editor instead of being
117
+ shown as committed conversation history. Once the runtime confirms injection,
118
+ the message moves into the transcript at its actual position and uses the normal
119
+ user-message `›` prefix. The `↪` marker is reserved for the temporary waiting
120
+ row.
121
+
122
+ To keep a follow-up editable instead, press `Tab` while the editor contains
123
+ text and completion is closed. The input remains in the local next-turn queue.
124
+ Queued inputs start in FIFO order after the active turn completes normally.
125
+ With an empty editor, press `Alt+Up` or `Shift+Left` to move the most recently
126
+ queued input back into the editor. Accepted steers cannot be edited because
127
+ they have already been handed to the official runtime, even while the waiting
128
+ row is visible; use `Tab` when the text must remain changeable. A steer rejected
129
+ or discarded before injection returns to the editable next-turn queue.
130
+
131
+ ### Image attachments
132
+
133
+ Press `Ctrl+V` or run `/paste-image` to attach an image from the clipboard.
134
+ Pending images appear above the editor as complete `[Image #N]` tokens.
135
+ Submitting a prompt moves those images into that user turn immediately, so they
136
+ are removed from the pending row and cannot leak into the next prompt.
137
+
138
+ Move the editor cursor to the start of its first line and press `Up`, or run
139
+ `/attachments`, to focus the attachment row. While it is focused:
140
+
141
+ - `Left`/`Right` selects an image;
142
+ - `Backspace` or `Delete` removes the selected image and renumbers the rest;
143
+ - `Down`, `Esc`, `Ctrl+C`, or `Enter` returns to the editor without changing its text.
144
+
145
+ Run `/attachments clear` to remove every pending image at once. `Ctrl+D`
146
+ retains its terminal-standard empty-editor exit and forward-delete behavior.
147
+
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
+
105
156
  ### Turn completion notifications
106
157
 
107
158
  Notifications are enabled by default and emitted after a normal agent turn
@@ -180,6 +231,7 @@ picker to return to input selection, then `Esc` again to close rewind.
180
231
  /diff browse current and per-turn file changes
181
232
  /context inspect context usage and source composition
182
233
  /status inspect detailed runtime and session status
234
+ /activity inspect every active tool and open task
183
235
  /tasks inspect or stop background tasks
184
236
  /search <text> search retained transcript blocks
185
237
  /search next|prev|clear navigate or close transcript search
@@ -201,9 +253,7 @@ an oversized selected block without rendering the entire message at once.
201
253
  - macOS, Linux or Windows on x64 or ARM64.
202
254
 
203
255
  Developing or publishing from source additionally requires Bun 1.3 or newer.
204
- `7z` is needed only when downloading and extracting a remote installer. npm
205
- installs the approximately 422 KB `zigpty` package containing all supported
206
- prebuilt PTY bindings.
256
+ `7z` is needed only when downloading and extracting a remote installer.
207
257
 
208
258
  Z.AI browser OAuth currently requires macOS because the registered provider
209
259
  callback is `zcode://zai-auth/callback`; API-key and custom-provider access work
@@ -375,6 +425,31 @@ zcode --prompt "Explain this repository"
375
425
  user-level default. Running `/model` does not call the provider, so it is a safe
376
426
  configuration check before the first prompt.
377
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:
433
+
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
+ ```
447
+
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.
452
+
378
453
  ## Local development
379
454
 
380
455
  Install dependencies and extract the already installed macOS application:
@@ -393,14 +468,17 @@ bun run check
393
468
  bun run check:tui
394
469
  ```
395
470
 
396
- `check:tui` runs two real-PTY scenarios. The official runtime scenario completes
471
+ `check:tui` runs real-PTY scenarios. The official runtime scenario completes
397
472
  masked Coding Plan API-key setup in a temporary home, verifies the official
398
- config output, executes `/help`, switches to plan mode, and exits. The offline
473
+ config output, executes `/help`, switches to plan mode, exits, and checks that
474
+ the launcher forwards terminal SIGHUP shutdown. The offline
399
475
  feature scenario also covers suspended login restoration, selectors, image
400
476
  attachments, nested Agent tools, Markdown, Mermaid, diffs, transcript
401
477
  navigation, context/status details, MCP actions, background tasks and the
402
- workflow panel. Both scenarios advance from observed terminal output instead
403
- of fixed timers and do not make model API calls.
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.
404
482
 
405
483
  Start the client directly:
406
484
 
@@ -434,6 +512,15 @@ contacting Z.AI or changing the real `zcode://` association:
434
512
  bun run check:oauth-callback
435
513
  ```
436
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
+
437
524
  To hand `/login` to another interactive command, set an explicit override:
438
525
 
439
526
  ```bash
@@ -453,7 +540,7 @@ bun link
453
540
  zcode
454
541
  ```
455
542
 
456
- Headless and protocol commands bypass the PTY and preserve ordinary stdio:
543
+ Headless and protocol commands use the same inherited stdio path:
457
544
 
458
545
  ```bash
459
546
  zcode --version
@@ -505,10 +592,10 @@ It contains only:
505
592
 
506
593
  Tests, GitHub workflows, build scripts, launcher/TUI TypeScript sources, local
507
594
  config, `.release/` artifacts and development `node_modules` are not published.
508
- npm installs only the declared pi-tui and zigpty runtime dependencies. The
509
- launcher and TUI are compiled to JavaScript with `tsdown`; its launcher banner
510
- adds the Node.js shebang directly, with no post-build rewrite. The compiled TUI
511
- is injected into `vendor/` before publication.
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.
512
599
 
513
600
  ## Automated npm publishing
514
601
 
package/bin/zcode.js CHANGED
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawn } from "node:child_process";
3
- import { existsSync } from "node:fs";
3
+ import { existsSync, readFileSync } from "node:fs";
4
4
  import { constants, homedir, tmpdir } from "node:os";
5
5
  import { basename, dirname, join, posix, resolve, sep, win32 } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
- import { hasNative, spawn as spawn$1 } from "zigpty";
8
7
  import { randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
9
8
  import { chmod, link, mkdir, mkdtemp, open, readFile, rm, stat, writeFile } from "node:fs/promises";
10
9
  //#region config.example.json
@@ -27,7 +26,7 @@ var config_example_default = {
27
26
  "lite": "zai/glm-5.1"
28
27
  },
29
28
  modelCatalog: { "overrides": {} },
30
- modelStream: { "idleTimeoutMs": 6e5 },
29
+ modelStream: { "idleTimeoutMs": 6e4 },
31
30
  permission: {
32
31
  "mode": "build",
33
32
  "allowedTools": [],
@@ -268,25 +267,27 @@ async function checkedRun(runner, command, args) {
268
267
  }
269
268
  return result.stdout.trim();
270
269
  }
271
- async function currentDefaultHandler(runner, scheme) {
272
- return checkedRun(runner, "/usr/bin/osascript", [
270
+ async function currentDefaultHandler(runner, scheme, step = "reading current OAuth callback handler") {
271
+ return withStepContext(step, () => checkedRun(runner, "/usr/bin/osascript", [
273
272
  "-l",
274
273
  "JavaScript",
275
274
  "-e",
276
275
  currentHandlerScript,
277
276
  scheme
278
- ]);
279
- }
280
- async function setDefaultHandler(runner, scheme, bundleId) {
281
- const status = await checkedRun(runner, "/usr/bin/osascript", [
282
- "-l",
283
- "JavaScript",
284
- "-e",
285
- setHandlerScript,
286
- scheme,
287
- bundleId
288
- ]);
289
- if (status !== "0") throw new Error(`Unable to register the ${scheme} callback handler (status ${status}).`);
277
+ ]));
278
+ }
279
+ async function setDefaultHandler(runner, scheme, bundleId, step = "activating OAuth callback handler") {
280
+ await withStepContext(step, async () => {
281
+ const status = await checkedRun(runner, "/usr/bin/osascript", [
282
+ "-l",
283
+ "JavaScript",
284
+ "-e",
285
+ setHandlerScript,
286
+ scheme,
287
+ bundleId
288
+ ]);
289
+ if (status !== "0") throw new Error(`Unable to register the ${scheme} callback handler (status ${status}).`);
290
+ });
290
291
  }
291
292
  function appleScriptString(value) {
292
293
  return `"${value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}"`;
@@ -371,7 +372,7 @@ async function recoverStaleDarwinOAuthHandler(options) {
371
372
  return;
372
373
  }
373
374
  if (record.pid !== process.pid && processIsAlive(record.pid)) throw new Error("Another Z.AI login is already waiting for authorization.");
374
- if (await currentDefaultHandler(runner, record.scheme).catch(() => "") === record.bundleId) await setDefaultHandler(runner, record.scheme, record.previousHandler || "none");
375
+ if (await currentDefaultHandler(runner, record.scheme).catch(() => "") === record.bundleId) await setDefaultHandler(runner, record.scheme, record.previousHandler || "none", "restoring stale OAuth callback handler");
375
376
  await unregisterApp(runner, record.appPath);
376
377
  await rm(record.appPath, {
377
378
  recursive: true,
@@ -396,6 +397,14 @@ async function delay(milliseconds, signal) {
396
397
  signal?.addEventListener("abort", onAbort, { once: true });
397
398
  });
398
399
  }
400
+ async function withStepContext(step, action) {
401
+ try {
402
+ return await action();
403
+ } catch (error) {
404
+ const detail = error instanceof Error ? error.message : String(error);
405
+ throw new Error(`${step}: ${detail}`, { cause: error });
406
+ }
407
+ }
399
408
  async function createDarwinUrlCallbackReceiver(options) {
400
409
  if (process.platform !== "darwin") throw new Error("The native zcode:// callback receiver is only available on macOS.");
401
410
  if (!/^[a-z][a-z0-9+.-]*$/u.test(options.scheme)) throw new Error(`Invalid callback scheme: ${options.scheme}`);
@@ -437,23 +446,23 @@ async function createDarwinUrlCallbackReceiver(options) {
437
446
  await chmod(callbackPath, 384);
438
447
  const compileArgs = ["-o", appPath];
439
448
  for (const line of callbackAppleScript(callbackPath, options.scheme, previousHandler)) compileArgs.push("-e", line);
440
- await checkedRun(runner, "/usr/bin/osacompile", compileArgs);
449
+ await withStepContext("compiling OAuth callback app", () => checkedRun(runner, "/usr/bin/osacompile", compileArgs));
441
450
  const infoPlist = join(appPath, "Contents", "Info.plist");
442
- await checkedRun(runner, "/usr/bin/plutil", [
451
+ await withStepContext("setting CFBundleIdentifier", () => checkedRun(runner, "/usr/bin/plutil", [
443
452
  "-insert",
444
453
  "CFBundleIdentifier",
445
454
  "-string",
446
455
  bundleId,
447
456
  infoPlist
448
- ]);
449
- await checkedRun(runner, "/usr/bin/plutil", [
457
+ ]));
458
+ await withStepContext("setting LSUIElement", () => checkedRun(runner, "/usr/bin/plutil", [
450
459
  "-insert",
451
460
  "LSUIElement",
452
461
  "-bool",
453
462
  "true",
454
463
  infoPlist
455
- ]);
456
- await checkedRun(runner, "/usr/bin/plutil", [
464
+ ]));
465
+ await withStepContext("setting CFBundleURLTypes", () => checkedRun(runner, "/usr/bin/plutil", [
457
466
  "-insert",
458
467
  "CFBundleURLTypes",
459
468
  "-json",
@@ -463,15 +472,15 @@ async function createDarwinUrlCallbackReceiver(options) {
463
472
  CFBundleURLSchemes: [options.scheme]
464
473
  }]),
465
474
  infoPlist
466
- ]);
467
- await checkedRun(runner, "/usr/bin/codesign", [
475
+ ]));
476
+ await withStepContext("ad-hoc codesigning callback app", () => checkedRun(runner, "/usr/bin/codesign", [
468
477
  "--force",
469
478
  "--deep",
470
479
  "--sign",
471
480
  "-",
472
481
  appPath
473
- ]);
474
- await checkedRun(runner, launchServicesRegister, ["-f", appPath]);
482
+ ]));
483
+ await withStepContext("registering callback app with LaunchServices", () => checkedRun(runner, launchServicesRegister, ["-f", appPath]));
475
484
  const record = {
476
485
  appPath,
477
486
  bundleId,
@@ -483,7 +492,7 @@ async function createDarwinUrlCallbackReceiver(options) {
483
492
  await chmod(recovery, 384);
484
493
  await setDefaultHandler(runner, options.scheme, bundleId);
485
494
  handlerChanged = true;
486
- if (await currentDefaultHandler(runner, options.scheme) !== bundleId) throw new Error(`macOS did not activate the ${options.scheme} callback handler.`);
495
+ if (await currentDefaultHandler(runner, options.scheme, "verifying OAuth callback handler") !== bundleId) throw new Error(`macOS did not activate the ${options.scheme} callback handler. Remove stale \`ZCode CLI OAuth Callback *.app\` entries from \`~/Applications\`, then retry \`zcode login\`.`);
487
496
  } catch (error) {
488
497
  await cleanup();
489
498
  throw error;
@@ -500,7 +509,7 @@ async function createDarwinUrlCallbackReceiver(options) {
500
509
  if (callback.trim()) return callback.trim();
501
510
  await delay(100, signal);
502
511
  }
503
- throw new Error("Authorization timed out. Please retry login.");
512
+ throw new Error("Authorization timed out. Please retry `zcode login`. If the browser routed the callback elsewhere, check for a stale `ZCode CLI OAuth Callback *.app` entry in `~/Applications` and remove it before retrying.");
504
513
  }
505
514
  };
506
515
  }
@@ -609,61 +618,25 @@ async function runZaiOAuthLogin(options) {
609
618
  //#endregion
610
619
  //#region src/launcher.ts
611
620
  const packageRoot = join(dirname(fileURLToPath(import.meta.url)), "..");
621
+ const packageManifestPath = join(packageRoot, "package.json");
612
622
  const runtimePath = join(packageRoot, "vendor", "zcode.cjs");
613
623
  const launcherPath = join(packageRoot, "bin", "zcode.js");
614
- const NON_TUI_COMMANDS = /* @__PURE__ */ new Set([
615
- "app-server",
616
- "commands",
617
- "doctor",
618
- "login",
619
- "logout",
620
- "plugins",
621
- "skills",
622
- "version"
623
- ]);
624
- const NON_TUI_FLAGS = /* @__PURE__ */ new Set([
625
- "-h",
626
- "--help",
627
- "-v",
628
- "--version",
629
- "-p",
630
- "--prompt",
631
- "--json",
632
- "--target"
633
- ]);
634
- const FLAGS_WITH_VALUES = /* @__PURE__ */ new Set([
635
- "-p",
636
- "--prompt",
637
- "--attach",
638
- "--cwd",
639
- "--disallowedTools",
640
- "--disallowed-tools",
641
- "--locale",
642
- "--mode",
643
- "--resume",
644
- "--target"
645
- ]);
646
- function isTuiInvocation(args) {
647
- if (args.some((argument) => NON_TUI_FLAGS.has(argument))) return false;
648
- let command;
649
- for (let index = 0; index < args.length; index += 1) {
650
- const argument = args[index];
651
- if (argument.startsWith("--") && argument.includes("=")) continue;
652
- if (FLAGS_WITH_VALUES.has(argument)) {
653
- index += 1;
654
- continue;
655
- }
656
- if (!argument.startsWith("-")) {
657
- command = argument;
658
- break;
659
- }
660
- }
661
- if (command === "tui") return true;
662
- return command ? !NON_TUI_COMMANDS.has(command) : true;
624
+ const defaultModelRetryMaxRetries = "5";
625
+ function resolveModelRetryMaxRetries(env) {
626
+ return env.ZCODE_MODEL_RETRY_MAX_RETRIES?.trim() || defaultModelRetryMaxRetries;
663
627
  }
664
628
  function resolveNodeExecutable() {
665
629
  return process.env.ZCODE_NODE?.trim() || process.execPath;
666
630
  }
631
+ function readDistributionVersion(manifestPath = packageManifestPath) {
632
+ 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;
636
+ } catch {
637
+ return;
638
+ }
639
+ }
667
640
  function normalizeLoginArgs(args) {
668
641
  if (args.length === 1 && args[0] === "login") return {
669
642
  args,
@@ -681,11 +654,17 @@ function normalizeLoginArgs(args) {
681
654
  function runtimeEnvironment(extra = {}) {
682
655
  const env = { ...process.env };
683
656
  delete env.ZCODE_CLI_OAUTH_CALLBACK_STDIN;
684
- const merged = {
657
+ const distributionVersion = readDistributionVersion();
658
+ const inherited = {
685
659
  ...env,
686
- ...extra,
660
+ ...extra
661
+ };
662
+ const merged = {
663
+ ...inherited,
664
+ ZCODE_MODEL_RETRY_MAX_RETRIES: resolveModelRetryMaxRetries(inherited),
687
665
  ZCODE_APP_CLI_EXECUTABLE: process.execPath,
688
- ZCODE_APP_CLI_ENTRY: launcherPath
666
+ ZCODE_APP_CLI_ENTRY: launcherPath,
667
+ ...distributionVersion ? { ZCODE_APP_CLI_VERSION: distributionVersion } : {}
689
668
  };
690
669
  return Object.fromEntries(Object.entries(merged).filter((entry) => typeof entry[1] === "string"));
691
670
  }
@@ -709,7 +688,7 @@ async function waitForChild(child) {
709
688
  child.once("exit", (code, signal) => finish(code ?? signalExitCode(signal)));
710
689
  });
711
690
  }
712
- async function runWithInheritedStdio(node, args) {
691
+ async function runRuntime(node, args) {
713
692
  const child = spawn(node, [runtimePath, ...args], {
714
693
  cwd: process.cwd(),
715
694
  env: runtimeEnvironment(),
@@ -720,56 +699,16 @@ async function runWithInheritedStdio(node, args) {
720
699
  };
721
700
  const onSigint = () => forwardSignal("SIGINT");
722
701
  const onSigterm = () => forwardSignal("SIGTERM");
702
+ const onSighup = () => forwardSignal("SIGHUP");
723
703
  process.once("SIGINT", onSigint);
724
704
  process.once("SIGTERM", onSigterm);
705
+ if (process.platform !== "win32") process.once("SIGHUP", onSighup);
725
706
  try {
726
707
  return await waitForChild(child);
727
708
  } finally {
728
709
  process.off("SIGINT", onSigint);
729
710
  process.off("SIGTERM", onSigterm);
730
- }
731
- }
732
- async function runInNativeTerminal(node, args) {
733
- if (!hasNative) throw new Error("zigpty has no native binding for this platform. Reinstall zcode-app-cli on a supported target.");
734
- const wasRaw = process.stdin.isRaw ?? false;
735
- const inputDecoder = new TextDecoder();
736
- const pty = spawn$1(node, [runtimePath, ...args], {
737
- cols: process.stdout.columns ?? 80,
738
- rows: process.stdout.rows ?? 24,
739
- cwd: process.cwd(),
740
- env: {
741
- ...runtimeEnvironment(),
742
- TERM: process.env.TERM ?? "xterm-256color"
743
- },
744
- name: process.env.TERM ?? "xterm-256color",
745
- encoding: null
746
- });
747
- const output = pty.onData((data) => process.stdout.write(data));
748
- const onInput = (data) => {
749
- if (pty.exitCode === null) pty.write(typeof data === "string" ? data : inputDecoder.decode(data, { stream: true }));
750
- };
751
- const onResize = () => {
752
- if (pty.exitCode === null) pty.resize(process.stdout.columns ?? 80, process.stdout.rows ?? 24);
753
- };
754
- const onSigint = () => pty.kill("SIGINT");
755
- const onSigterm = () => pty.kill("SIGTERM");
756
- try {
757
- process.stdin.setRawMode?.(true);
758
- process.stdin.resume();
759
- process.stdin.on("data", onInput);
760
- process.stdout.on("resize", onResize);
761
- process.once("SIGINT", onSigint);
762
- process.once("SIGTERM", onSigterm);
763
- return await pty.exited;
764
- } finally {
765
- output.dispose();
766
- process.stdin.off("data", onInput);
767
- process.stdout.off("resize", onResize);
768
- process.off("SIGINT", onSigint);
769
- process.off("SIGTERM", onSigterm);
770
- process.stdin.setRawMode?.(wasRaw);
771
- if (!wasRaw) process.stdin.pause();
772
- pty.close();
711
+ if (process.platform !== "win32") process.off("SIGHUP", onSighup);
773
712
  }
774
713
  }
775
714
  async function completeOfficialZaiLogin(node, payload, runtimeArgs, abortSignal) {
@@ -833,9 +772,8 @@ async function main(args) {
833
772
  process.off("SIGTERM", cancel);
834
773
  }
835
774
  }
836
- const interactive = isTuiInvocation(login.args) && process.stdin.isTTY && process.stdout.isTTY;
837
775
  try {
838
- return interactive ? await runInNativeTerminal(node, login.args) : await runWithInheritedStdio(node, login.args);
776
+ return await runRuntime(node, login.args);
839
777
  } catch (error) {
840
778
  console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
841
779
  return 1;
@@ -26,7 +26,7 @@
26
26
  "overrides": {}
27
27
  },
28
28
  "modelStream": {
29
- "idleTimeoutMs": 600000
29
+ "idleTimeoutMs": 60000
30
30
  },
31
31
  "permission": {
32
32
  "mode": "build",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcode-app-cli",
3
- "version": "3.3.5-1",
3
+ "version": "3.3.6-3",
4
4
  "description": "Unofficial terminal client for the ZCode agent runtime",
5
5
  "keywords": [
6
6
  "agent",
@@ -10,12 +10,10 @@
10
10
  "glm",
11
11
  "node",
12
12
  "pi-tui",
13
- "pty",
14
13
  "terminal",
15
14
  "tui",
16
15
  "z-ai",
17
- "zcode",
18
- "zigpty"
16
+ "zcode"
19
17
  ],
20
18
  "homepage": "https://github.com/kingsword09/zcode-cli#readme",
21
19
  "bugs": {
@@ -43,14 +41,18 @@
43
41
  "build": "tsdown",
44
42
  "build:launcher": "tsdown --filter launcher",
45
43
  "build:tui": "tsdown --filter tui",
44
+ "bench:tui-memory": "bun --expose-gc scripts/bench-tui-memory.ts",
45
+ "bench:tui-stream": "bun scripts/bench-tui-stream.ts",
46
+ "dev": "bun run sync:local && ZCODE_NODE=node bun bin/zcode.ts",
46
47
  "sync": "bun run build && bun scripts/sync-runtime.ts",
47
48
  "sync:locked": "bun run build && bun scripts/sync-runtime.ts --lock zcode-runtime.lock.json",
48
49
  "sync:local": "bun run build && bun scripts/sync-runtime.ts --app /Applications/ZCode.app",
49
50
  "check": "bun run build && bun scripts/check-runtime.ts",
50
51
  "check:oauth-callback": "bun scripts/smoke-oauth-callback.ts",
51
- "check:tui": "bun scripts/smoke-tui.ts && bun scripts/smoke-tui-features.ts",
52
+ "check:tui": "bun scripts/smoke-tui.ts && bun scripts/smoke-tui-features.ts && bun scripts/smoke-tui-pressure.ts && bun scripts/smoke-tui-widths.ts",
52
53
  "test": "bun test",
53
54
  "typecheck": "tsc --noEmit",
55
+ "verify:tui-perf": "bun scripts/verify-tui-perf.ts",
54
56
  "version:build": "bun scripts/bump-build.ts",
55
57
  "release:prepare": "bun scripts/build-release.ts --latest",
56
58
  "release:build": "bun scripts/build-release.ts",
@@ -66,8 +68,7 @@
66
68
  "provenance": true
67
69
  },
68
70
  "dependencies": {
69
- "@earendil-works/pi-tui": "^0.80.6",
70
- "zigpty": "^0.2.1"
71
+ "@earendil-works/pi-tui": "^0.80.6"
71
72
  },
72
73
  "devDependencies": {
73
74
  "beautiful-mermaid": "^1.1.3",
@@ -1,9 +1,9 @@
1
1
  {
2
- "appVersion": "3.3.5",
2
+ "appVersion": "3.3.6",
3
3
  "cliVersion": "0.15.2",
4
- "extractedAt": "2026-07-14T13:28:18.944Z",
5
- "sha512": "lMzz5ZzNUFpBF4Oo7CMsEDxul4aZKBOwZCkyRIgIv2q43ko3ifvfAN4esNO+KXc2f11YczZxOWIJzep+Xj+LdA==",
6
- "source": "https://cdn-zcode.z.ai/zcode/electron/releases/update/linux/x64/ZCode-3.3.5-linux-x64.deb",
4
+ "extractedAt": "2026-07-17T03:15:27.269Z",
5
+ "sha512": "NwQzSBf+Q5FR3VWwAEQUeALHR9jvDjRT7PJLVQ4iLOyTxPm7Lt8kMQbQXI7MJ/wEDQ0EK3FBBjJQVlJiC4Kgsw==",
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": {
8
8
  "implementation": "@zcode/tui",
9
9
  "foundation": "@earendil-works/pi-tui"