zcode-app-cli 3.10.2-19 → 3.11.2-20

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/bin/zcode.js CHANGED
@@ -5,7 +5,7 @@ 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
7
  import { randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
8
- import { chmod, link, mkdir, mkdtemp, open, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
8
+ import { access, chmod, link, mkdir, mkdtemp, open, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
9
9
  import { createInterface } from "node:readline/promises";
10
10
  import { parseArgs } from "node:util";
11
11
  //#region config.example.json
@@ -1288,6 +1288,50 @@ async function runPluginCommand(args, options) {
1288
1288
  }
1289
1289
  }
1290
1290
  //#endregion
1291
+ //#region src/prompt-preflight.ts
1292
+ function record(value) {
1293
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
1294
+ }
1295
+ async function exists(path) {
1296
+ try {
1297
+ await access(path);
1298
+ return true;
1299
+ } catch (error) {
1300
+ return error.code !== "ENOENT";
1301
+ }
1302
+ }
1303
+ /** Diagnose only unambiguous keyless Coding Plan configs, not general model access. */
1304
+ async function missingCodingPlanKey(options = {}) {
1305
+ const env = options.env ?? process.env;
1306
+ if (Object.entries(env).some(([key, value]) => value?.trim() && key !== "ZCODE_BASE_URL" && !key.startsWith("ZCODE_MODEL_RETRY_") && key !== "ZCODE_MODEL_TELEMETRY_ENABLED" && /^(?:ZCODE|ZAI|BIGMODEL|ZHIPU|ANTHROPIC)_.*(?:KEY|TOKEN|MODEL|CONFIG|PROVIDER|BASE_URL)/u.test(key))) return;
1307
+ let directory = resolve(options.workingDirectory ?? process.cwd());
1308
+ while (true) {
1309
+ if ((await Promise.all([
1310
+ join(directory, "zcode.json"),
1311
+ join(directory, ".zcode", "config.json"),
1312
+ join(directory, ".env")
1313
+ ].map(exists))).some(Boolean)) return void 0;
1314
+ const parent = dirname(directory);
1315
+ if (parent === directory) break;
1316
+ directory = parent;
1317
+ }
1318
+ let config;
1319
+ try {
1320
+ config = record(JSON.parse(await readFile(userConfigPath(env), "utf8")));
1321
+ } catch {
1322
+ return;
1323
+ }
1324
+ const model = options.model ?? record(config?.model)?.main;
1325
+ if (typeof model !== "string") return void 0;
1326
+ const providerId = model.split("/", 1)[0];
1327
+ if (providerId !== "zai" && providerId !== "bigmodel") return void 0;
1328
+ const provider = record(record(config?.provider)?.[providerId]);
1329
+ const settings = record(provider?.options);
1330
+ const expectedUrl = providerId === "zai" ? "https://api.z.ai/api/anthropic" : "https://open.bigmodel.cn/api/anthropic";
1331
+ if (provider?.kind !== "anthropic" || settings?.baseURL !== expectedUrl || settings?.apiKeyRequired !== true || typeof settings.apiKey === "string" && settings.apiKey.trim() || settings.apiKey !== void 0 && typeof settings.apiKey !== "string" || Object.keys(record(provider.headers) ?? {}).length > 0) return void 0;
1332
+ return `Model access is not configured for ${providerId}. Run /login or /setup in zcode, or configure its API key before sending a prompt. No model request was sent.`;
1333
+ }
1334
+ //#endregion
1291
1335
  //#region src/runtime-capabilities.ts
1292
1336
  function isRecord(value) {
1293
1337
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -1421,6 +1465,8 @@ function inspectRuntimeInvocation(args, runtimeOptionTypes) {
1421
1465
  let invalid = false;
1422
1466
  let passthrough = false;
1423
1467
  let presentationSurface = false;
1468
+ let workingDirectory;
1469
+ let resume = false;
1424
1470
  for (let index = 0; index < args.length; index += 1) {
1425
1471
  const argument = args[index];
1426
1472
  if (argument === "--") {
@@ -1430,6 +1476,8 @@ function inspectRuntimeInvocation(args, runtimeOptionTypes) {
1430
1476
  if (argument.startsWith("--")) {
1431
1477
  const option = longOptionName(argument);
1432
1478
  const inlineValue = option.length !== argument.length;
1479
+ if (option === "--cwd") workingDirectory = inlineValue ? argument.slice(option.length + 1) : args[index + 1];
1480
+ if (option === "--resume" || option === "--continue") resume = true;
1433
1481
  if (option === "--browser-use") {
1434
1482
  explicitBrowserUse = true;
1435
1483
  if (!inlineValue) if (index + 1 >= args.length || args[index + 1].startsWith("-")) invalid = true;
@@ -1481,7 +1529,10 @@ function inspectRuntimeInvocation(args, runtimeOptionTypes) {
1481
1529
  else index += 1;
1482
1530
  continue;
1483
1531
  }
1484
- if (argument === "-c" || argument === "-f") continue;
1532
+ if (argument === "-c" || argument === "-f") {
1533
+ if (argument === "-c") resume = true;
1534
+ continue;
1535
+ }
1485
1536
  invalid = true;
1486
1537
  continue;
1487
1538
  }
@@ -1493,9 +1544,19 @@ function inspectRuntimeInvocation(args, runtimeOptionTypes) {
1493
1544
  command,
1494
1545
  explicitBrowserUse,
1495
1546
  invalid,
1496
- passthrough
1547
+ passthrough,
1548
+ workingDirectory,
1549
+ resume
1497
1550
  };
1498
1551
  }
1552
+ async function promptPreflight(args, env = process.env) {
1553
+ const invocation = inspectRuntimeInvocation(args, readRuntimeCliOptionTypes());
1554
+ if (!invocation.agentInvocation || invocation.invalid || invocation.passthrough || invocation.resume) return;
1555
+ return missingCodingPlanKey({
1556
+ env,
1557
+ workingDirectory: invocation.workingDirectory
1558
+ });
1559
+ }
1499
1560
  function withDefaultBrowserUse(args, runtimeOptionTypes = readRuntimeCliOptionTypes()) {
1500
1561
  const invocation = inspectRuntimeInvocation(args, runtimeOptionTypes);
1501
1562
  if (invocation.explicitBrowserUse || invocation.passthrough || invocation.invalid || !invocation.agentInvocation && invocation.command !== void 0 && invocation.command !== "tui") return args;
@@ -1722,6 +1783,11 @@ async function main(args) {
1722
1783
  }
1723
1784
  }
1724
1785
  try {
1786
+ const diagnostic = await promptPreflight(login.args);
1787
+ if (diagnostic) {
1788
+ console.error(diagnostic);
1789
+ return 1;
1790
+ }
1725
1791
  const runtimeArgs = withDefaultBrowserUse(login.args);
1726
1792
  return await runRuntime(node, runtimeArgs, firstRunSetupEnv(setupPending, runtimeArgs));
1727
1793
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcode-app-cli",
3
- "version": "3.10.2-19",
3
+ "version": "3.11.2-20",
4
4
  "description": "Unofficial terminal client for the ZCode agent runtime",
5
5
  "keywords": [
6
6
  "agent",
@@ -1,9 +1,9 @@
1
1
  {
2
- "appVersion": "3.10.2",
2
+ "appVersion": "3.11.2",
3
3
  "cliVersion": "0.16.5",
4
- "extractedAt": "2026-09-02T10:09:32.133Z",
5
- "sha512": "bb9VQ+/T8Lu4YIgiTOHVIlVRzY8XnRvDzXvOrcYFIWCl8FVgb8bRhfA5/5oewXgLGY2rTSGYQZlnHbeZ2jVl3Q==",
6
- "source": "https://cdn-zcode.z.ai/zcode/electron/releases/3.10.2/linux-x64/ZCode-3.10.2-linux-x64.deb",
4
+ "extractedAt": "2026-09-05T15:48:54.303Z",
5
+ "sha512": "4UAMZSP9ZWBrnb8wGaP39rb5dB5ikPx4aYPXKXGea1Vmd6L6vGma3rXwRxKbhBxgsCIE9jv6tmrdSL60RrzGcA==",
6
+ "source": "https://cdn-zcode.z.ai/zcode/electron/releases/3.11.2/linux-x64/ZCode-3.11.2-linux-x64.deb",
7
7
  "runtimeCapabilities": {
8
8
  "schemaVersion": 1,
9
9
  "cli": {
@@ -79,6 +79,11 @@
79
79
  }
80
80
  },
81
81
  "runtimePatches": [
82
+ {
83
+ "id": "official-mcp-availability",
84
+ "requirement": "optional",
85
+ "status": "applied"
86
+ },
82
87
  {
83
88
  "id": "tui-bridge",
84
89
  "requirement": "required",
@@ -114,6 +119,11 @@
114
119
  "requirement": "required",
115
120
  "status": "applied"
116
121
  },
122
+ {
123
+ "id": "stream-eof-finish-guard",
124
+ "requirement": "required",
125
+ "status": "applied"
126
+ },
117
127
  {
118
128
  "id": "oauth-http-errors",
119
129
  "requirement": "optional",
@@ -3,8 +3,8 @@ import { spawn } from "node:child_process";
3
3
  import { accessSync, appendFileSync, closeSync, constants, fstatSync, openSync, readSync } from "node:fs";
4
4
  import { constants as constants$1, homedir } from "node:os";
5
5
  import { basename, dirname, extname, isAbsolute, join, posix, resolve, sep, win32 } from "node:path";
6
+ import { access, copyFile, link, mkdir, open, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
6
7
  import { randomUUID } from "node:crypto";
7
- import { copyFile, link, mkdir, open, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
8
8
  import { Box, CombinedAutocompleteProvider, Container, Editor, Image, Input, Markdown, ProcessTerminal, ScrollView, SelectList, Spacer, Text, TuiAltScreen, TuiMainScreen, VStack, decodeKittyPrintable, getKeybindings, isKeyRelease, isViewportTUI, matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
9
9
  import { isDeepStrictEqual } from "node:util";
10
10
  var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
@@ -273,6 +273,65 @@ async function clearSetupPending(env = process.env) {
273
273
  await rm(setupPendingPath(env), { force: true }).catch(() => {});
274
274
  }
275
275
  //#endregion
276
+ //#region src/prompt-preflight.ts
277
+ function record$4(value) {
278
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
279
+ }
280
+ async function exists(path) {
281
+ try {
282
+ await access(path);
283
+ return true;
284
+ } catch (error) {
285
+ return error.code !== "ENOENT";
286
+ }
287
+ }
288
+ /** Diagnose only unambiguous keyless Coding Plan configs, not general model access. */
289
+ async function missingCodingPlanKey(options = {}) {
290
+ const env = options.env ?? process.env;
291
+ if (Object.entries(env).some(([key, value]) => value?.trim() && key !== "ZCODE_BASE_URL" && !key.startsWith("ZCODE_MODEL_RETRY_") && key !== "ZCODE_MODEL_TELEMETRY_ENABLED" && /^(?:ZCODE|ZAI|BIGMODEL|ZHIPU|ANTHROPIC)_.*(?:KEY|TOKEN|MODEL|CONFIG|PROVIDER|BASE_URL)/u.test(key))) return;
292
+ let directory = resolve(options.workingDirectory ?? process.cwd());
293
+ while (true) {
294
+ if ((await Promise.all([
295
+ join(directory, "zcode.json"),
296
+ join(directory, ".zcode", "config.json"),
297
+ join(directory, ".env")
298
+ ].map(exists))).some(Boolean)) return void 0;
299
+ const parent = dirname(directory);
300
+ if (parent === directory) break;
301
+ directory = parent;
302
+ }
303
+ let config;
304
+ try {
305
+ config = record$4(JSON.parse(await readFile(userConfigPath(env), "utf8")));
306
+ } catch {
307
+ return;
308
+ }
309
+ const model = options.model ?? record$4(config?.model)?.main;
310
+ if (typeof model !== "string") return void 0;
311
+ const providerId = model.split("/", 1)[0];
312
+ if (providerId !== "zai" && providerId !== "bigmodel") return void 0;
313
+ const provider = record$4(record$4(config?.provider)?.[providerId]);
314
+ const settings = record$4(provider?.options);
315
+ const expectedUrl = providerId === "zai" ? "https://api.z.ai/api/anthropic" : "https://open.bigmodel.cn/api/anthropic";
316
+ if (provider?.kind !== "anthropic" || settings?.baseURL !== expectedUrl || settings?.apiKeyRequired !== true || typeof settings.apiKey === "string" && settings.apiKey.trim() || settings.apiKey !== void 0 && typeof settings.apiKey !== "string" || Object.keys(record$4(provider.headers) ?? {}).length > 0) return void 0;
317
+ return `Model access is not configured for ${providerId}. Run /login or /setup in zcode, or configure its API key before sending a prompt. No model request was sent.`;
318
+ }
319
+ //#endregion
320
+ //#region packages/zcode-tui/src/prompt-preflight.ts
321
+ /** Preserve rejected input without replacing a draft typed during validation. */
322
+ async function preflightSubmission(options) {
323
+ const diagnostic = await options.validate();
324
+ if (options.isStopped()) return false;
325
+ if (!diagnostic) return true;
326
+ if (options.queued || options.editor.getText() !== "") options.inputQueue.restoreFollowUp(options.submission);
327
+ else {
328
+ options.editor.setText(options.submission.input);
329
+ options.inputQueue.autoSend = false;
330
+ }
331
+ options.warn(diagnostic);
332
+ return false;
333
+ }
334
+ //#endregion
276
335
  //#region src/desktop-migration.ts
277
336
  const desktopConfigDirectory = "v2";
278
337
  const knownFamilies = ["zai", "bigmodel"];
@@ -162162,6 +162221,7 @@ var TurnNotifier = class {
162162
162221
  settings;
162163
162222
  active = false;
162164
162223
  focusReporting = false;
162224
+ focusReportingRequired;
162165
162225
  terminalFocus = "unknown";
162166
162226
  terminalUnavailable = false;
162167
162227
  constructor(options) {
@@ -162170,6 +162230,7 @@ var TurnNotifier = class {
162170
162230
  this.platform = options.platform ?? process.platform;
162171
162231
  this.nativeNotify = options.nativeNotify ?? ((platform, title, body) => sendNativeNotification(platform, title, body, this.env));
162172
162232
  this.settings = options.settings ?? notificationSettings(this.env);
162233
+ this.focusReportingRequired = options.focusReportingRequired === true;
162173
162234
  }
162174
162235
  start() {
162175
162236
  this.active = true;
@@ -162196,6 +162257,11 @@ var TurnNotifier = class {
162196
162257
  this.settings = { ...settings };
162197
162258
  this.syncFocusReporting();
162198
162259
  }
162260
+ setFocusReportingRequired(required) {
162261
+ if (this.focusReportingRequired === required) return;
162262
+ this.focusReportingRequired = required;
162263
+ this.syncFocusReporting();
162264
+ }
162199
162265
  handleInput(data) {
162200
162266
  if (data === focusIn) {
162201
162267
  this.terminalFocus = "focused";
@@ -162249,7 +162315,7 @@ var TurnNotifier = class {
162249
162315
  }
162250
162316
  }
162251
162317
  syncFocusReporting() {
162252
- if (!this.active || this.settings.method === "off" || this.settings.condition !== "unfocused") {
162318
+ if (!this.active || !this.focusReportingRequired && (this.settings.method === "off" || this.settings.condition !== "unfocused")) {
162253
162319
  this.disableFocusReporting();
162254
162320
  return;
162255
162321
  }
@@ -162678,6 +162744,11 @@ var InputQueue = class {
162678
162744
  if (submission) this.syncView();
162679
162745
  return submission;
162680
162746
  }
162747
+ restoreFollowUp(submission) {
162748
+ this.queuedFollowUps.unshift(submission);
162749
+ this.autoSendEnabled = false;
162750
+ this.syncView();
162751
+ }
162681
162752
  editLatestFollowUp() {
162682
162753
  const submission = this.queuedFollowUps.pop();
162683
162754
  if (submission) this.syncView();
@@ -165779,6 +165850,7 @@ const runtimeCommandSummaries = /* @__PURE__ */ new Map([
165779
165850
  const terminalThemeQueryTimeoutMs = 100;
165780
165851
  const exitUsageQueryTimeoutMs = 250;
165781
165852
  const fullscreenWelcomeTransitionMs = 180;
165853
+ const terminalFocusIn = "\x1B[I";
165782
165854
  const updateAvailableBlockId = "update_available";
165783
165855
  const modelRetryBlockIdPrefix = "model_retry_status";
165784
165856
  const questionBackValue = "__back__";
@@ -165944,6 +166016,14 @@ var ZCodeAltScreen = class extends TuiAltScreen {
165944
166016
  setCurrentInput(data) {
165945
166017
  this.currentInput = data;
165946
166018
  }
166019
+ /**
166020
+ * The terminal can lose visible rows while this process is unfocused even
166021
+ * though pi-tui's logical frame remains unchanged. Invalidate its
166022
+ * differential cache so the next frame repaints every row.
166023
+ */
166024
+ forceFullRedraw() {
166025
+ process.nextTick(() => this.requestRender(true));
166026
+ }
165947
166027
  isOverlayFocused() {
165948
166028
  if (super.isOverlayFocused()) return true;
165949
166029
  return this.viewportInputDeferral?.(this.currentInput ?? "") === true;
@@ -165953,10 +166033,14 @@ var ZCodeAltScreen = class extends TuiAltScreen {
165953
166033
  var NotifyingProcessTerminal = class extends ProcessTerminal {
165954
166034
  beforeInput;
165955
166035
  afterInput;
165956
- constructor(beforeInput, afterInput) {
166036
+ onFocusIn;
166037
+ onTerminalResize;
166038
+ constructor(beforeInput, afterInput, onFocusIn, onTerminalResize) {
165957
166039
  super();
165958
166040
  this.beforeInput = beforeInput;
165959
166041
  this.afterInput = afterInput;
166042
+ this.onFocusIn = onFocusIn;
166043
+ this.onTerminalResize = onTerminalResize;
165960
166044
  }
165961
166045
  start(onInput, onResize) {
165962
166046
  super.start((data) => {
@@ -165965,8 +166049,12 @@ var NotifyingProcessTerminal = class extends ProcessTerminal {
165965
166049
  onInput(data);
165966
166050
  } finally {
165967
166051
  this.afterInput?.();
166052
+ if (data === terminalFocusIn) this.onFocusIn?.();
165968
166053
  }
165969
- }, onResize);
166054
+ }, () => {
166055
+ onResize();
166056
+ this.onTerminalResize?.();
166057
+ });
165970
166058
  }
165971
166059
  };
165972
166060
  function signalExitCode(signal) {
@@ -166119,7 +166207,10 @@ var ZCodeTui = class {
166119
166207
  this.skillCatalog = new SkillCatalog(options.listSkills);
166120
166208
  this.tuiMode = resolveTuiMode(process.env, { ui: { tuiMode: options.initialTuiMode } });
166121
166209
  this.ui = this.createTui(this.tuiMode);
166122
- this.notifications = new TurnNotifier({ writeTerminal: (data) => this.ui.terminal.write(data) });
166210
+ this.notifications = new TurnNotifier({
166211
+ writeTerminal: (data) => this.ui.terminal.write(data),
166212
+ focusReportingRequired: this.tuiMode === "fullscreen"
166213
+ });
166123
166214
  this.status = new StatusLine();
166124
166215
  this.turnStatus = new FooterBar();
166125
166216
  this.queuedInputView = new QueuedInputView(this.theme);
@@ -166173,6 +166264,7 @@ var ZCodeTui = class {
166173
166264
  if (effective !== this.tuiMode) {
166174
166265
  this.ui = this.createTui(effective);
166175
166266
  this.tuiMode = effective;
166267
+ this.notifications.setFocusReportingRequired(effective === "fullscreen");
166176
166268
  this.editor = this.createEditor(this.ui);
166177
166269
  }
166178
166270
  } catch {}
@@ -166283,7 +166375,7 @@ var ZCodeTui = class {
166283
166375
  const terminal = new NotifyingProcessTerminal((data) => {
166284
166376
  fullscreenTui?.setCurrentInput(data);
166285
166377
  this.notifications?.handleInput(data);
166286
- }, () => fullscreenTui?.setCurrentInput(void 0));
166378
+ }, () => fullscreenTui?.setCurrentInput(void 0), () => fullscreenTui?.forceFullRedraw(), () => fullscreenTui?.forceFullRedraw());
166287
166379
  if (mode !== "fullscreen") return new TuiMainScreen(terminal, true);
166288
166380
  const tui = new ZCodeAltScreen(terminal, true, void 0, {
166289
166381
  copySelection: async (text) => {
@@ -166471,6 +166563,7 @@ var ZCodeTui = class {
166471
166563
  this.ui.stop({ preserveScreen: true });
166472
166564
  this.ui = this.createTui(next);
166473
166565
  this.tuiMode = next;
166566
+ this.notifications.setFocusReportingRequired(next === "fullscreen");
166474
166567
  this.sessionHasContent = hadSessionContent;
166475
166568
  this.fullscreenWelcomeVisible = !hadSessionContent;
166476
166569
  this.fullscreenHeader.setPhase(hadSessionContent ? "rail" : "welcome");
@@ -166496,6 +166589,7 @@ var ZCodeTui = class {
166496
166589
  } catch {}
166497
166590
  this.ui = previousUi;
166498
166591
  this.tuiMode = previousMode;
166592
+ this.notifications.setFocusReportingRequired(previousMode === "fullscreen");
166499
166593
  this.sessionHasContent = hadSessionContent;
166500
166594
  this.fullscreenWelcomeVisible = previousMode === "fullscreen" ? !hadSessionContent : true;
166501
166595
  this.fullscreenHeader.setPhase(hadSessionContent ? "rail" : "welcome");
@@ -166824,6 +166918,23 @@ var ZCodeTui = class {
166824
166918
  const input = (queuedSubmission?.input ?? rawInput).trim();
166825
166919
  if (!input || this.stopped) return false;
166826
166920
  const submission = queuedSubmission ?? protectSubmission(input);
166921
+ if (!input.startsWith("/") && !this.primaryTurnActive) {
166922
+ if (!await preflightSubmission({
166923
+ validate: () => missingCodingPlanKey({
166924
+ model: this.model,
166925
+ workingDirectory: this.options.workspaceDirectory
166926
+ }),
166927
+ isStopped: () => this.stopped,
166928
+ submission,
166929
+ queued: queuedSubmission !== void 0,
166930
+ editor: {
166931
+ getText: () => this.editor.getText(),
166932
+ setText: (text) => this.editor.setText(text)
166933
+ },
166934
+ inputQueue: this.inputQueue,
166935
+ warn: (message) => this.addNotice(message, "warning")
166936
+ })) return false;
166937
+ }
166827
166938
  if (submission.recordHistory) {
166828
166939
  this.rememberEditorHistory(input);
166829
166940
  this.editor.addToHistory(input);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-use",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Built-in browser automation runtime and guidance for Desktop IAB and explicitly enabled CLI-managed headless CDP: open, navigate, inspect, click, type, screenshot, record workspace WebM videos, and verify web pages and local dev targets.",
5
5
  "author": { "name": "Z.ai" },
6
6
  "license": "MIT",