zcode-app-cli 3.14.4-32 → 3.14.5-34

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
@@ -460,10 +460,23 @@ not available on `PATH`.
460
460
 
461
461
  ## Configuration
462
462
 
463
+ Select a model for one headless prompt without changing the saved default:
464
+
465
+ ```bash
466
+ zcode --model account:zai-individual-coding-plan/GLM-5.3-Flash --prompt 'Reply with exactly: ok'
467
+ ```
468
+
469
+ `--model` requires a full provider/model ID and `--prompt` (or `-p`). It also
470
+ overrides a resumed session's model for that run. Unknown or unavailable models
471
+ fail before a prompt is sent, rather than falling back to the default.
472
+
463
473
  ZCode reads MCP servers, hooks, plugins, permissions, network, storage and display
464
474
  settings from `~/.zcode/cli/setting.json` (or
465
475
  `%USERPROFILE%\.zcode\cli\setting.json` on Windows). Project settings use
466
476
  `zcode.json` or `.zcode/config.json`. Existing files are never replaced.
477
+ Set `ZCODE_CLI_SETTINGS_FILE` to an absolute path to give one process its own user
478
+ settings file. See [host integration](./docs/HOST_INTEGRATION.md#environment-and-configuration)
479
+ for migration behavior and the separate session, provider and credential overrides.
467
480
 
468
481
  Custom MCP servers go in the top-level `mcp.servers` object in `setting.json`.
469
482
  See [MCP configuration](./docs/CONFIGURATION.md#mcp-servers) for HTTP/stdio examples,
@@ -497,7 +510,10 @@ zcode --prompt 'Reply with exactly: ok'
497
510
 
498
511
  The browser authorization uses the registered ZCode client ID. The runtime
499
512
  stores the login and resolves Coding Plan access using its native account
500
- provider registry. The credential file remains private (mode 600). These
513
+ provider registry. `/login bigmodel-coding-plan` first reuses a BigModel
514
+ session that Desktop stored in the shared credential file, without opening a
515
+ browser; set `ZCODE_CLI_BIGMODEL_REUSE_SESSION=0` to always sign in again. An
516
+ open TUI session switches to the newly saved model after any login. The credential file remains private (mode 600). These
501
517
  overrides leave Desktop's credentials and provider configuration untouched.
502
518
  Client headers and a local usage row do not independently prove server-side
503
519
  bonus accounting.
@@ -512,7 +528,7 @@ models demonstrate explicit overrides and manual configuration.
512
528
  [Provider 配置字段参考](./docs/PROVIDER_CONFIG.zh-CN.md)。
513
529
  The project follows the current upstream runtime and configuration schema.
514
530
 
515
- Three model-access paths are supported: Z.AI OAuth, Z.AI/BigModel
531
+ Three model-access paths are supported: Z.AI/BigModel OAuth, Z.AI/BigModel
516
532
  Coding Plan API key, or a direct API key with a custom provider. For detailed
517
533
  setup steps, retries/timeouts, theme, and turn-completion notifications, see
518
534
  [Configuration](./docs/CONFIGURATION.md).
package/bin/zcode.js CHANGED
@@ -88,13 +88,22 @@ var setting_example_default = {
88
88
  };
89
89
  //#endregion
90
90
  //#region src/config-paths.ts
91
- function cliSettingsPath(env = process.env, platform = process.platform, fallbackHome = homedir()) {
91
+ function homeCliSettingsPath(env, platform, fallbackHome) {
92
92
  const path = platform === "win32" ? win32 : posix;
93
93
  const home = (platform === "win32" ? env.USERPROFILE : env.HOME)?.trim() || fallbackHome;
94
94
  return path.join(home, ".zcode", "cli", "setting.json");
95
95
  }
96
+ /**
97
+ * The CLI settings file. `ZCODE_CLI_SETTINGS_FILE` lets a host run one process
98
+ * on its own settings file (hooks, MCP servers, permissions) without editing
99
+ * the user's `~/.zcode/cli/setting.json`. Files that are derived from the
100
+ * settings location (migration markers, the legacy `config.json`) follow it.
101
+ */
102
+ function cliSettingsPath(env = process.env, platform = process.platform, fallbackHome = homedir()) {
103
+ return env.ZCODE_CLI_SETTINGS_FILE?.trim() || homeCliSettingsPath(env, platform, fallbackHome);
104
+ }
96
105
  function desktopSettingsPath(env = process.env) {
97
- return join(dirname(dirname(cliSettingsPath(env))), "v2", "setting.json");
106
+ return join(dirname(dirname(homeCliSettingsPath(env, process.platform, homedir()))), "v2", "setting.json");
98
107
  }
99
108
  function readDesktopSettings(env = process.env) {
100
109
  try {
@@ -1465,6 +1474,37 @@ async function missingCodingPlanKey(options = {}) {
1465
1474
  return message(providerId);
1466
1475
  }
1467
1476
  //#endregion
1477
+ //#region src/prompt-model.ts
1478
+ function extractPromptModel(args, optionTypes) {
1479
+ const parsed = parseArgs({
1480
+ args,
1481
+ allowPositionals: true,
1482
+ strict: false,
1483
+ tokens: true,
1484
+ options: {
1485
+ ...Object.fromEntries(Object.entries(optionTypes).map(([name, type]) => [name, { type }])),
1486
+ prompt: {
1487
+ type: "string",
1488
+ short: "p"
1489
+ },
1490
+ model: { type: "string" }
1491
+ }
1492
+ });
1493
+ const tokens = parsed.tokens.filter((token) => token.kind === "option" && token.name === "model");
1494
+ if (tokens.length === 0) return { args };
1495
+ if (tokens.length !== 1) throw new Error("Specify --model only once.");
1496
+ if (typeof parsed.values.prompt !== "string") throw new Error("--model requires --prompt or -p.");
1497
+ const model = String(parsed.values.model).trim();
1498
+ if (!/^[^/\s]+\/\S+$/u.test(model)) throw new Error("--model must be a provider/model ID.");
1499
+ const token = tokens[0];
1500
+ const removed = /* @__PURE__ */ new Set([token.index]);
1501
+ if (token.kind === "option" && !token.inlineValue) removed.add(token.index + 1);
1502
+ return {
1503
+ args: args.filter((_, index) => !removed.has(index)),
1504
+ model
1505
+ };
1506
+ }
1507
+ //#endregion
1468
1508
  //#region src/runtime-capabilities.ts
1469
1509
  function isRecord(value) {
1470
1510
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -1658,12 +1698,13 @@ function inspectRuntimeInvocation(args, runtimeOptionTypes) {
1658
1698
  resume
1659
1699
  };
1660
1700
  }
1661
- async function promptPreflight(args, env = process.env) {
1701
+ async function promptPreflight(args, env = process.env, model) {
1662
1702
  const invocation = inspectRuntimeInvocation(args, readRuntimeCliOptionTypes());
1663
1703
  if (!invocation.agentInvocation || invocation.invalid || invocation.passthrough || invocation.resume) return;
1664
1704
  return missingCodingPlanKey({
1665
1705
  env,
1666
- workingDirectory: invocation.workingDirectory
1706
+ workingDirectory: invocation.workingDirectory,
1707
+ model
1667
1708
  });
1668
1709
  }
1669
1710
  function withDefaultBrowserUse(args, runtimeOptionTypes = readRuntimeCliOptionTypes()) {
@@ -1687,6 +1728,7 @@ function runtimeEnvironment(extra = {}, inspectConfiguration = false) {
1687
1728
  const env = { ...process.env };
1688
1729
  delete env.ZCODE_CLI_OAUTH_CALLBACK_STDIN;
1689
1730
  delete env.ZCODE_CLI_MIGRATE_CONFIG;
1731
+ delete env.ZCODE_CLI_PROMPT_MODEL;
1690
1732
  const distributionVersion = readDistributionVersion();
1691
1733
  const appVersion = readJsonVersion(extractionMetadataPath, "appVersion");
1692
1734
  const inherited = {
@@ -1839,6 +1881,15 @@ async function main(args) {
1839
1881
  console.log(formatVersionOutput(distributionVersion, runtimeVersion));
1840
1882
  return 0;
1841
1883
  }
1884
+ let promptModel;
1885
+ try {
1886
+ const parsed = extractPromptModel(args, readRuntimeCliOptionTypes());
1887
+ args = parsed.args;
1888
+ promptModel = parsed.model;
1889
+ } catch (error) {
1890
+ console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
1891
+ return 1;
1892
+ }
1842
1893
  let setupPending = false;
1843
1894
  try {
1844
1895
  if (isDoctorRuntimeInvocation(args)) return await runRuntime(resolveNodeExecutable(), args);
@@ -1948,13 +1999,18 @@ async function main(args) {
1948
1999
  }
1949
2000
  }
1950
2001
  try {
1951
- const diagnostic = await readConfiguredModelAccess() ? void 0 : await promptPreflight(login.args);
2002
+ const diagnostic = await readConfiguredModelAccess() ? void 0 : await promptPreflight(login.args, process.env, promptModel);
1952
2003
  if (diagnostic) {
1953
2004
  console.error(diagnostic);
1954
2005
  return 1;
1955
2006
  }
1956
2007
  const runtimeArgs = withDefaultBrowserUse(login.args);
1957
- return await runRuntime(node, runtimeArgs, firstRunSetupEnv(setupPending, runtimeArgs));
2008
+ const code = await runRuntime(node, runtimeArgs, {
2009
+ ...firstRunSetupEnv(setupPending, runtimeArgs),
2010
+ ...promptModel ? { ZCODE_CLI_PROMPT_MODEL: promptModel } : {}
2011
+ });
2012
+ if (code === 0 && (args.includes("--help") || args.includes("-h"))) console.log("\n --model <provider/model> Select a model for this --prompt run without changing the saved default.");
2013
+ return code;
1958
2014
  } catch (error) {
1959
2015
  console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
1960
2016
  return 1;
@@ -21,8 +21,20 @@ both clients. `/model` changes only the current CLI session.
21
21
 
22
22
  Set `ZCODE_PERSONAL_PROVIDER_CONFIG_FILE` to a separate file to isolate provider
23
23
  settings. `ZCODE_DATA_BASE_DIR` changes the native runtime's base directory,
24
- including its provider and credential storage. General CLI settings still use
25
- the user's `~/.zcode/cli/setting.json`.
24
+ including its provider and credential storage. General CLI settings default to
25
+ the user's `~/.zcode/cli/setting.json`. Set `ZCODE_CLI_SETTINGS_FILE` to an absolute
26
+ file path to give one process its own settings. Unset or whitespace-only values
27
+ use the default. The selected file replaces the user settings source; explicit
28
+ runtime file paths and project configuration keep their existing precedence.
29
+
30
+ Legacy `config.json` and `migrations/` markers follow the selected file's directory.
31
+ Hook trust commands use that file's `storage.dir` too. Providers, credentials and
32
+ the session database (including persisted project permissions) have separate path
33
+ overrides; changing only the settings file does not isolate those stores. See
34
+ [host integration](HOST_INTEGRATION.md#environment-and-configuration) for examples.
35
+ Desktop preferences remain in `~/.zcode/v2/setting.json`; Desktop's user hooks and
36
+ MCP configuration in `~/.zcode/cli/config.json` are not continuously synchronized
37
+ with the CLI settings file.
26
38
 
27
39
  On first launch, the CLI creates a credential-free general configuration from
28
40
  [`setting.example.json`](../setting.example.json). Existing files are not replaced.
@@ -295,6 +307,10 @@ provider configuration is recognized directly; no desktop import step is needed.
295
307
  authorization. `--no-browser` prints the authorization URL.
296
308
  - **Z.AI/BigModel Coding Plan API key:** open `/login` and choose the masked
297
309
  API-key option. The official runtime owns credential and provider persistence.
310
+ - **BigModel browser OAuth:** choose **BigModel Coding Plan** in `/login`, or run
311
+ `/login bigmodel-coding-plan`. The CLI exchanges the authorization code through
312
+ the official ZCode token service used by Desktop. No OAuth app secret needs to
313
+ be configured in the CLI.
298
314
  - **Custom provider:** configure the native provider file directly. Any provider
299
315
  ID can be used; a separate OAuth login is unnecessary.
300
316
 
@@ -306,7 +322,34 @@ For macOS OAuth, the CLI temporarily registers a callback receiver, checks
306
322
  `state`, restores the previous `zcode://` handler and sends the callback through
307
323
  stdin. The runtime exchanges the token, stores encrypted credentials, resolves
308
324
  the Coding Plan API key and saves the native default model. The TUI then rereads
309
- provider configuration. BigModel uses the runtime's localhost callback.
325
+ provider configuration. BigModel uses the runtime's localhost callback, checks
326
+ `state`, and sends the matching callback URI and state to
327
+ `https://zcode.z.ai/api/v1/oauth/token`. Both the BigModel access token and ZCode
328
+ JWT are saved in the native encrypted credential store before account setup
329
+ completes. The callback must reach the machine running the CLI; with SSH, forward
330
+ the port shown in the callback URL to that machine.
331
+
332
+ On Windows, the CLI opens the browser through PowerShell so the authorization
333
+ URL's query parameters survive command-line parsing. If opening it manually,
334
+ copy the entire URL, including `redirect` and `state`, into the browser address
335
+ bar instead of passing it to `cmd.exe /c start`.
336
+
337
+ If BigModel's authorization page shows `--` for the account name or reports a
338
+ missing account ID, try signing in at [BigModel](https://bigmodel.cn/login) in
339
+ the same browser first, then run `/login bigmodel-coding-plan` again. This error
340
+ occurs on the website before the CLI receives an authorization code. The account
341
+ ID comes from the website's login session; it is not the OAuth `appId`. If the
342
+ browser asks to access apps or services on this device, allow it for this login
343
+ so it can reach the localhost callback.
344
+
345
+ For API-key setup without a browser or SSH callback forwarding, get your key from the
346
+ [Coding Plan overview](https://bigmodel.cn/coding-plan/personal/overview), then
347
+ choose **BigModel Coding Plan API Key** in `/login`. The native runtime encrypts
348
+ the key and saves the account provider's default model; manual plaintext edits
349
+ to `provider_config.json` are unnecessary. Login and subsequent requests must
350
+ use the same credential file and `ZCODE_CREDENTIAL_SECRET` (if set). Credentials
351
+ encrypted with another secret must be configured again with the CLI's key-entry
352
+ flow; ciphertext is not an API key.
310
353
 
311
354
  ## Custom provider
312
355
 
@@ -20,7 +20,16 @@ Windows 使用 `%USERPROFILE%` 代替 `~`。Provider 文件默认与桌面端共
20
20
 
21
21
  设置 `ZCODE_PERSONAL_PROVIDER_CONFIG_FILE` 可使用独立的 provider 文件。
22
22
  `ZCODE_DATA_BASE_DIR` 改变原生 runtime 的基础目录,包括 provider 和凭证存储。
23
- CLI 通用设置仍使用用户目录中的 `~/.zcode/cli/setting.json`。
23
+ CLI 通用设置默认使用用户目录中的 `~/.zcode/cli/setting.json`。
24
+ 设置 `ZCODE_CLI_SETTINGS_FILE` 为绝对文件路径,可为单个进程指定独立设置。
25
+ 未设置或仅含空白时使用默认路径。所选文件替换用户级设置来源;显式 runtime 文件路径和
26
+ 项目配置保留原有优先级。
27
+
28
+ 旧 `config.json` 和 `migrations/` 标记使用所选文件所在目录,hook 信任命令也读取该文件的
29
+ `storage.dir`。Provider、凭证和会话数据库(含持久化项目权限)有各自的路径覆盖变量,
30
+ 仅切换设置文件不会隔离这些存储,示例见[宿主集成](HOST_INTEGRATION.md#environment-and-configuration)。
31
+ Desktop 偏好仍位于 `~/.zcode/v2/setting.json`;桌面端保存在 `~/.zcode/cli/config.json`
32
+ 中的用户 hooks 和 MCP 配置不会与 CLI 设置文件持续同步。
24
33
 
25
34
  首次启动时,CLI 根据不含凭证的 [`setting.example.json`](../setting.example.json)
26
35
  创建通用设置,不覆盖已有文件。Provider 配置由原生登录创建,或参考
@@ -256,6 +265,9 @@ Provider 文件中的 `config.defaultModelSelection` 决定新会话使用的模
256
265
  `--no-browser` 只输出授权链接。
257
266
  - **Z.AI/BigModel Coding Plan API Key:** 打开 `/login`,选择掩码输入的 API Key 选项。
258
267
  凭证和 provider 的保存由官方 runtime 负责。
268
+ - **BigModel 浏览器 OAuth:** 在 `/login` 中选择 **BigModel Coding Plan**,或运行
269
+ `/login bigmodel-coding-plan`。CLI 通过 Desktop 使用的官方 ZCode 令牌服务交换授权码,
270
+ 无需在 CLI 中配置 OAuth 应用密钥。
259
271
  - **自定义 provider:** 直接配置原生 provider 文件,可使用自定义 ID,无需额外 OAuth 登录。
260
272
 
261
273
  普通的 `zcode login` 会识别已经配置的原生默认模型并提示配置路径。
@@ -263,7 +275,26 @@ Provider 文件中的 `config.defaultModelSelection` 决定新会话使用的模
263
275
 
264
276
  macOS OAuth 会临时注册回调接收器、校验 `state`,恢复原来的 `zcode://` 处理程序,并通过
265
277
  stdin 把回调交给 runtime。Runtime 交换令牌、保存加密凭证、解析 Coding Plan API Key,
266
- 再保存原生默认模型;TUI 随后重新读取 provider 配置。BigModel 使用 runtime 的 localhost 回调。
278
+ 再保存原生默认模型;TUI 随后重新读取 provider 配置。BigModel 使用 runtime 的 localhost
279
+ 回调,校验 `state` 后,将匹配的回调地址和 state 提交到
280
+ `https://zcode.z.ai/api/v1/oauth/token`。BigModel access token 和 ZCode JWT 均通过原生
281
+ 凭证存储加密保存。回调须能访问运行 CLI 的机器;SSH 环境需要将回调 URL 中的端口转发到该机器。
282
+
283
+ Windows 上,CLI 通过 PowerShell 打开浏览器,保留授权链接中的全部查询参数。
284
+ 手动打开时,请将包含 `redirect` 和 `state` 的完整 URL 粘贴到浏览器地址栏,
285
+ 避免通过 `cmd.exe /c start` 传递链接。
286
+
287
+ 若 BigModel 授权页的账号名称显示为 `--`,或提示缺少账号 ID,可先在同一浏览器中
288
+ 登录 [BigModel 官网](https://bigmodel.cn/login),再重新运行 `/login bigmodel-coding-plan`。
289
+ 该错误发生在网页端,早于 CLI 收到授权码;账号 ID 来自网站登录会话,并非 OAuth 的 `appId`。
290
+ 浏览器若询问是否允许访问此设备上的应用或服务,请为此次登录允许访问,以便完成 localhost 回调。
291
+
292
+ 不使用浏览器或 SSH 回调端口转发时,可在
293
+ [Coding Plan 概览](https://bigmodel.cn/coding-plan/personal/overview) 获取密钥,
294
+ 再在 `/login` 中选择 **BigModel Coding Plan API Key**。原生 runtime 会加密保存密钥并设置
295
+ 账号 provider 的默认模型,无需手动在 `provider_config.json` 中填写明文密钥。
296
+ 登录和后续请求须使用同一凭证文件及 `ZCODE_CREDENTIAL_SECRET`(若已设置)。
297
+ 其他密钥加密的凭证需要通过 CLI 的密钥输入流程重新配置,不能将密文当作 API Key 使用。
267
298
 
268
299
  ## 自定义 Provider
269
300
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcode-app-cli",
3
- "version": "3.14.4-32",
3
+ "version": "3.14.5-34",
4
4
  "description": "Unofficial terminal client for the ZCode agent runtime",
5
5
  "keywords": [
6
6
  "agent",
@@ -5,14 +5,24 @@ let node_path = require("node:path");
5
5
  let node_crypto = require("node:crypto");
6
6
  let node_os = require("node:os");
7
7
  let node_async_hooks = require("node:async_hooks");
8
+ let node_buffer = require("node:buffer");
8
9
  //#region src/config-paths.ts
9
- function cliSettingsPath(env = process.env, platform = process.platform, fallbackHome = (0, node_os.homedir)()) {
10
+ function homeCliSettingsPath(env, platform, fallbackHome) {
10
11
  const path = platform === "win32" ? node_path.win32 : node_path.posix;
11
12
  const home = (platform === "win32" ? env.USERPROFILE : env.HOME)?.trim() || fallbackHome;
12
13
  return path.join(home, ".zcode", "cli", "setting.json");
13
14
  }
15
+ /**
16
+ * The CLI settings file. `ZCODE_CLI_SETTINGS_FILE` lets a host run one process
17
+ * on its own settings file (hooks, MCP servers, permissions) without editing
18
+ * the user's `~/.zcode/cli/setting.json`. Files that are derived from the
19
+ * settings location (migration markers, the legacy `config.json`) follow it.
20
+ */
21
+ function cliSettingsPath(env = process.env, platform = process.platform, fallbackHome = (0, node_os.homedir)()) {
22
+ return env.ZCODE_CLI_SETTINGS_FILE?.trim() || homeCliSettingsPath(env, platform, fallbackHome);
23
+ }
14
24
  function desktopSettingsPath(env = process.env) {
15
- return (0, node_path.join)((0, node_path.dirname)((0, node_path.dirname)(cliSettingsPath(env))), "v2", "setting.json");
25
+ return (0, node_path.join)((0, node_path.dirname)((0, node_path.dirname)(homeCliSettingsPath(env, process.platform, (0, node_os.homedir)()))), "v2", "setting.json");
16
26
  }
17
27
  function readDesktopSettings(env = process.env) {
18
28
  try {
@@ -653,6 +663,74 @@ function appServerRegistryOptions(env, createRefreshReporter) {
653
663
  return appServerAuthMode(env) === "host" ? {} : { standalone: createRefreshReporter(process.stderr) };
654
664
  }
655
665
  //#endregion
666
+ //#region src/bigmodel-oauth.ts
667
+ function record$1(value) {
668
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
669
+ }
670
+ function nonempty(value) {
671
+ return typeof value === "string" ? value.trim() || void 0 : void 0;
672
+ }
673
+ /** Match Desktop's BigModelProviderAdapter: the official server owns the app secret. */
674
+ async function exchangeBigmodelOAuthCode(options) {
675
+ options.abortSignal?.throwIfAborted();
676
+ if (!nonempty(options.code) || !nonempty(options.redirectUri) || !nonempty(options.state)) throw new Error("BigModel OAuth requires an authorization code, redirect URI and state.");
677
+ const response = await options.httpClient.request({
678
+ body: new TextEncoder().encode(JSON.stringify({
679
+ provider: "bigmodel",
680
+ code: options.code,
681
+ redirect_uri: options.redirectUri,
682
+ state: options.state
683
+ })),
684
+ headers: { "Content-Type": "application/json" },
685
+ maxResponseBytes: 65536,
686
+ method: "POST",
687
+ trace: options.trace,
688
+ url: "https://zcode.z.ai/api/v1/oauth/token"
689
+ }, options.abortSignal);
690
+ let envelope;
691
+ try {
692
+ envelope = record$1(JSON.parse(new TextDecoder().decode(response.body)));
693
+ } catch {
694
+ throw new Error(`BigModel OAuth HTTP ${response.status}: token response is not valid JSON.`);
695
+ }
696
+ const message = nonempty(envelope.msg);
697
+ if (response.status < 200 || response.status >= 300) throw new Error(`BigModel OAuth HTTP ${response.status}${message ? `: ${message}` : "."}`);
698
+ if (envelope.code !== void 0 && envelope.code !== 0) throw new Error(`BigModel OAuth token exchange failed${message ? `: ${message}` : "."}`);
699
+ const data = record$1(envelope.data), bigmodel = record$1(data.bigmodel);
700
+ const zcodeJwtToken = nonempty(data.token);
701
+ const accessToken = nonempty(bigmodel.access_token) ?? nonempty(bigmodel.accessToken) ?? nonempty(data.access_token) ?? nonempty(data.accessToken);
702
+ if (!zcodeJwtToken) throw new Error("BigModel OAuth token response is missing data.token.");
703
+ if (!accessToken) throw new Error("BigModel OAuth token response is missing data.bigmodel.access_token.");
704
+ const refreshToken = nonempty(bigmodel.refresh_token) ?? nonempty(bigmodel.refreshToken);
705
+ return {
706
+ accessToken,
707
+ zcodeJwtToken,
708
+ ...refreshToken ? { refreshToken } : {}
709
+ };
710
+ }
711
+ //#endregion
712
+ //#region src/browser-open.ts
713
+ function browserOpenCommand(platform, url) {
714
+ if (platform === "darwin") return {
715
+ executable: "open",
716
+ args: [url]
717
+ };
718
+ if (platform !== "win32") return {
719
+ executable: "xdg-open",
720
+ args: [url]
721
+ };
722
+ const command = `Start-Process -FilePath ([Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${node_buffer.Buffer.from(url, "utf8").toString("base64")}')))`;
723
+ return {
724
+ executable: "powershell.exe",
725
+ args: [
726
+ "-NoProfile",
727
+ "-NonInteractive",
728
+ "-EncodedCommand",
729
+ node_buffer.Buffer.from(command, "utf16le").toString("base64")
730
+ ]
731
+ };
732
+ }
733
+ //#endregion
656
734
  //#region src/config-diagnostics.ts
657
735
  const schemaDiagnosticPrefix = /^(?:<config>|modelStream|permission|storage|network|features|memory|mcp|plugins|skills|skill|command|logging|ui|toolConcurrency|modelAnomalyGuard|hooks)(?:[.:[\]]|$)/u;
658
736
  function publicDiagnostic(diagnostic, scope) {
@@ -863,6 +941,8 @@ async function migrateLegacyProviders(options) {
863
941
  //#endregion
864
942
  exports.appServerRegistryOptions = appServerRegistryOptions;
865
943
  exports.assertSessionModelReady = assertSessionModelReady;
944
+ exports.browserOpenCommand = browserOpenCommand;
945
+ exports.exchangeBigmodelOAuthCode = exchangeBigmodelOAuthCode;
866
946
  exports.inspectRuntimeConfiguration = inspectRuntimeConfiguration;
867
947
  exports.installSqliteWriteRecovery = installSqliteWriteRecovery;
868
948
  exports.mergeDesktopSettings = mergeDesktopSettings;
@@ -1,9 +1,9 @@
1
1
  {
2
- "appVersion": "3.14.4",
2
+ "appVersion": "3.14.5",
3
3
  "cliVersion": "0.16.9",
4
- "extractedAt": "2026-10-05T04:52:23.363Z",
5
- "sha512": "CMaAUbHehEEGuClDJeJI30ufA0zAgzfXgzV4ES200EuGDt0yYhEpzvtjayxvE/ag9T9ThnDg1eP4o3j9HkCHKg==",
6
- "source": "https://cdn-zcode.z.ai/zcode/electron/releases/3.14.4/linux-x64/ZCode-3.14.4-linux-x64.deb",
4
+ "extractedAt": "2026-10-11T04:05:50.928Z",
5
+ "sha512": "FNqGJ+XVyUxIdZ7bxppph4R5M9kFS0zL64ztpItZV933eKVuVxtpZ3BnLMRpwIXouPGrLIDw8zSTrctiUgbmbA==",
6
+ "source": "https://cdn-zcode.z.ai/zcode/electron/releases/3.14.5/linux-x64/ZCode-3.14.5-linux-x64.deb",
7
7
  "runtimeCapabilities": {
8
8
  "schemaVersion": 1,
9
9
  "cli": {
@@ -116,6 +116,11 @@
116
116
  "requirement": "required",
117
117
  "status": "applied"
118
118
  },
119
+ {
120
+ "id": "cli-settings-file",
121
+ "requirement": "required",
122
+ "status": "applied"
123
+ },
119
124
  {
120
125
  "id": "configuration-diagnostics",
121
126
  "requirement": "required",
@@ -196,11 +201,31 @@
196
201
  "requirement": "required",
197
202
  "status": "applied"
198
203
  },
204
+ {
205
+ "id": "prompt-model",
206
+ "requirement": "required",
207
+ "status": "applied"
208
+ },
209
+ {
210
+ "id": "bigmodel-oauth",
211
+ "requirement": "required",
212
+ "status": "applied"
213
+ },
214
+ {
215
+ "id": "browser-url-opening",
216
+ "requirement": "required",
217
+ "status": "applied"
218
+ },
199
219
  {
200
220
  "id": "desktop-oauth",
201
221
  "requirement": "required",
202
222
  "status": "applied"
203
223
  },
224
+ {
225
+ "id": "bigmodel-session-reuse",
226
+ "requirement": "optional",
227
+ "status": "applied"
228
+ },
204
229
  {
205
230
  "id": "login-model-defaults",
206
231
  "requirement": "required",
@@ -89,13 +89,22 @@ var setting_example_default = {
89
89
  };
90
90
  //#endregion
91
91
  //#region src/config-paths.ts
92
- function cliSettingsPath(env = process.env, platform = process.platform, fallbackHome = homedir()) {
92
+ function homeCliSettingsPath(env, platform, fallbackHome) {
93
93
  const path = platform === "win32" ? win32 : posix;
94
94
  const home = (platform === "win32" ? env.USERPROFILE : env.HOME)?.trim() || fallbackHome;
95
95
  return path.join(home, ".zcode", "cli", "setting.json");
96
96
  }
97
+ /**
98
+ * The CLI settings file. `ZCODE_CLI_SETTINGS_FILE` lets a host run one process
99
+ * on its own settings file (hooks, MCP servers, permissions) without editing
100
+ * the user's `~/.zcode/cli/setting.json`. Files that are derived from the
101
+ * settings location (migration markers, the legacy `config.json`) follow it.
102
+ */
103
+ function cliSettingsPath(env = process.env, platform = process.platform, fallbackHome = homedir()) {
104
+ return env.ZCODE_CLI_SETTINGS_FILE?.trim() || homeCliSettingsPath(env, platform, fallbackHome);
105
+ }
97
106
  function desktopSettingsPath(env = process.env) {
98
- return join(dirname(dirname(cliSettingsPath(env))), "v2", "setting.json");
107
+ return join(dirname(dirname(homeCliSettingsPath(env, process.platform, homedir()))), "v2", "setting.json");
99
108
  }
100
109
  function readDesktopSettings(env = process.env) {
101
110
  try {
@@ -157567,6 +157576,7 @@ var ChoiceDialog = class {
157567
157576
  contentLabel;
157568
157577
  maxContentLines;
157569
157578
  maxExpandedContentLines;
157579
+ filterList;
157570
157580
  filter = "";
157571
157581
  selectionPreview;
157572
157582
  contentExpanded = false;
@@ -157575,7 +157585,7 @@ var ChoiceDialog = class {
157575
157585
  contentPageSize = 1;
157576
157586
  /** Number of quick-selectable items; digits beyond this are ignored. */
157577
157587
  numberShortcutCount = 0;
157578
- constructor(title, prompt, help, list, theme, content, contentLabel = "Details", maxContentLines = 0, maxExpandedContentLines = 0) {
157588
+ constructor(title, prompt, help, list, theme, content, contentLabel = "Details", maxContentLines = 0, maxExpandedContentLines = 0, filterList) {
157579
157589
  this.title = title;
157580
157590
  this.prompt = prompt;
157581
157591
  this.help = help;
@@ -157585,6 +157595,7 @@ var ChoiceDialog = class {
157585
157595
  this.contentLabel = contentLabel;
157586
157596
  this.maxContentLines = maxContentLines;
157587
157597
  this.maxExpandedContentLines = maxExpandedContentLines;
157598
+ this.filterList = filterList;
157588
157599
  }
157589
157600
  setSelectionPreview(preview) {
157590
157601
  if (this.selectionPreview !== preview) this.contentOffset = 0;
@@ -157691,7 +157702,13 @@ var ChoiceDialog = class {
157691
157702
  }
157692
157703
  updateFilter(filter) {
157693
157704
  this.filter = filter;
157694
- this.list.setFilter(filter);
157705
+ if (this.filterList) {
157706
+ const next = this.filterList(filter);
157707
+ next.onSelect = this.list.onSelect;
157708
+ next.onCancel = this.list.onCancel;
157709
+ next.onSelectionChange = this.list.onSelectionChange;
157710
+ this.list = next;
157711
+ } else this.list.setFilter(filter);
157695
157712
  const selected = this.list.getSelectedItem();
157696
157713
  if (selected) this.list.onSelectionChange?.(selected);
157697
157714
  else this.setSelectionPreview(void 0);
@@ -157760,7 +157777,10 @@ function choose(ui, host, theme, options) {
157760
157777
  list.setSelectedIndex(options.selectedIndex ?? 0);
157761
157778
  const maxContentLines = Math.max(0, ui.terminal.rows - maxVisible - 9);
157762
157779
  const maxExpandedContentLines = Math.max(2, maxContentLines, ui.terminal.rows - 8);
157763
- const dialog = new ChoiceDialog(sanitizeTerminalText(options.title, { preserveSgr: false }), sanitizeTerminalText(options.prompt, { preserveSgr: false }), sanitizeTerminalText(options.help ?? (hasDetails ? numberShortcutsEnabled ? "Type to filter · number selects · Up/Down choose · Ctrl+O details · ←/→ or PgUp/PgDn scroll · Enter confirm · Esc cancel" : "Type to filter · Up/Down choose · Ctrl+O details · ←/→ or PgUp/PgDn scroll · Enter confirm · Esc cancel" : numberShortcutsEnabled ? "Type to filter · number selects · Up/Down choose · Enter confirm · Esc cancel · Ctrl+U clear" : "Type to filter · Up/Down choose · Enter confirm · Esc cancel · Ctrl+U clear"), { preserveSgr: false }), list, theme, options.content, sanitizeTerminalText(options.contentLabel ?? "Details", { preserveSgr: false }), maxContentLines, maxExpandedContentLines);
157780
+ const dialog = new ChoiceDialog(sanitizeTerminalText(options.title, { preserveSgr: false }), sanitizeTerminalText(options.prompt, { preserveSgr: false }), sanitizeTerminalText(options.help ?? (hasDetails ? numberShortcutsEnabled ? "Type to filter · number selects · Up/Down choose · Ctrl+O details · ←/→ or PgUp/PgDn scroll · Enter confirm · Esc cancel" : "Type to filter · Up/Down choose · Ctrl+O details · ←/→ or PgUp/PgDn scroll · Enter confirm · Esc cancel" : numberShortcutsEnabled ? "Type to filter · number selects · Up/Down choose · Enter confirm · Esc cancel · Ctrl+U clear" : "Type to filter · Up/Down choose · Enter confirm · Esc cancel · Ctrl+U clear"), { preserveSgr: false }), list, theme, options.content, sanitizeTerminalText(options.contentLabel ?? "Details", { preserveSgr: false }), maxContentLines, maxExpandedContentLines, options.filterMode === "substring" ? (filter) => {
157781
+ const query = filter.toLowerCase();
157782
+ return new SelectList(searchableItems.filter((item) => item.label.toLowerCase().includes(query) || item.description?.toLowerCase().includes(query)), maxVisible, theme.select);
157783
+ } : void 0);
157764
157784
  dialog.numberShortcutCount = numberShortcutsEnabled ? options.items.length : 0;
157765
157785
  const previewFor = (item) => {
157766
157786
  if (!item) return void 0;
@@ -161577,6 +161597,19 @@ var PermissionRequestQueue = class {
161577
161597
  return result;
161578
161598
  }
161579
161599
  };
161600
+ /**
161601
+ * The abort signal of one permission request. The runtime passes its broker
161602
+ * options (`{ signal, claimResponse, timeoutMs }`) as the request context and
161603
+ * aborts `signal` when another responder settles the request first, such as a
161604
+ * `PermissionRequest` hook that allows or denies the call. `abortSignal` is
161605
+ * accepted as well for callers that use the TUI's own option name.
161606
+ */
161607
+ function permissionRequestSignal(context) {
161608
+ if (typeof context !== "object" || context === null) return void 0;
161609
+ const record = context;
161610
+ if (record.signal instanceof AbortSignal) return record.signal;
161611
+ if (record.abortSignal instanceof AbortSignal) return record.abortSignal;
161612
+ }
161580
161613
  //#endregion
161581
161614
  //#region src/app-server-client.ts
161582
161615
  const maximumOutputBytes = 16 * 1024 * 1024;
@@ -166891,6 +166924,7 @@ var ZCodeTui = class {
166891
166924
  this.model = access.model;
166892
166925
  this.setLoginRequired(false);
166893
166926
  this.addNotice(`Model access configured via ${access.configPath}.`, "muted");
166927
+ await this.adoptLoginModel();
166894
166928
  } else if (failure) this.addNotice(`Login command failed: ${failure}`, "error");
166895
166929
  else if (code !== 0) {
166896
166930
  const diagnostic = loginFailureDiagnostic(childStdout, childStderr);
@@ -167391,6 +167425,7 @@ var ZCodeTui = class {
167391
167425
  if (input.startsWith("/") || !this.options.sendInput) {
167392
167426
  const result = await this.options.submitPrompt(input.startsWith("/") ? input : promptInput(runtimeInput, attachments), callOptions);
167393
167427
  await this.handleResult(result, true, settingTargetForCommand(input));
167428
+ if (/^\/login\s+\S/iu.test(input) && isRecord(result) && result.loginRequired === false) await this.adoptLoginModel();
167394
167429
  accepted = true;
167395
167430
  } else {
167396
167431
  const preparedInput = promptInput(runtimeInput, attachments);
@@ -168864,11 +168899,14 @@ var ZCodeTui = class {
168864
168899
  this.ui.requestRender();
168865
168900
  }
168866
168901
  requestPermission(requestValue, context) {
168867
- const contextRecord = isRecord(context) ? context : void 0;
168868
- const signal = contextRecord?.abortSignal instanceof AbortSignal ? contextRecord.abortSignal : this.turnAbortController?.signal;
168902
+ const signal = permissionRequestSignal(context) ?? this.turnAbortController?.signal;
168869
168903
  return this.permissionRequests.run(() => this.requestPermissionUnqueued(requestValue, signal));
168870
168904
  }
168871
168905
  async requestPermissionUnqueued(requestValue, signal) {
168906
+ if (signal?.aborted) return {
168907
+ decision: "deny",
168908
+ reason: "Permission request cancelled"
168909
+ };
168872
168910
  const request = isRecord(requestValue) ? requestValue : {};
168873
168911
  const toolName = asString(request.toolName) ?? "tool";
168874
168912
  const asksUserQuestion = isAskUserQuestionTool(toolName);
@@ -168879,7 +168917,8 @@ var ZCodeTui = class {
168879
168917
  if (asksUserQuestion) response = await this.requestUserQuestions(request.input, signal);
168880
168918
  else if (isExitPlanModeTool(toolName)) response = await this.requestPlanApproval(request.input, signal);
168881
168919
  else response = await this.requestToolPermission(request, toolName, signal);
168882
- if (tool) {
168920
+ const settledElsewhere = signal?.aborted === true && this.turnAbortController?.signal.aborted !== true;
168921
+ if (tool && !settledElsewhere) {
168883
168922
  const record = isRecord(response) ? response : void 0;
168884
168923
  const decision = asString(record?.decision)?.toLowerCase();
168885
168924
  const allowed = decision === "allow" || decision === "modify";
@@ -169229,6 +169268,21 @@ var ZCodeTui = class {
169229
169268
  await this.applyModeShortcut(normalizedMode(mode));
169230
169269
  return true;
169231
169270
  }
169271
+ /**
169272
+ * Login writes credentials and the default model behind the running provider
169273
+ * registry, which only re-reads them on refresh. Reload it and move this
169274
+ * session onto the new default, or the next turn starts without a model.
169275
+ */
169276
+ async adoptLoginModel() {
169277
+ await this.refreshModelOptions();
169278
+ const access = await readConfiguredModelAccess().catch(() => null);
169279
+ if (!access || !this.options.setTransientModel) return;
169280
+ try {
169281
+ await this.handleResult(await this.options.setTransientModel(access.model), false);
169282
+ } catch (error) {
169283
+ this.addNotice(`Could not switch this session to ${access.model}: ${error instanceof Error ? error.message : String(error)}`, "warning");
169284
+ }
169285
+ }
169232
169286
  /** All model selectors re-read the catalog, including after first-run login. */
169233
169287
  async refreshModelOptions() {
169234
169288
  const load = this.options.reloadModelOptions;
@@ -169257,6 +169311,7 @@ var ZCodeTui = class {
169257
169311
  ...item,
169258
169312
  payload: item.value
169259
169313
  })),
169314
+ filterMode: "substring",
169260
169315
  selectedIndex: picker.selectedIndex
169261
169316
  }))?.payload;
169262
169317
  if (typeof modelId !== "string") {
@@ -169301,6 +169356,7 @@ var ZCodeTui = class {
169301
169356
  prompt: "Select the model used for new sessions.",
169302
169357
  help: "Up/Down choose · Enter save · Esc back to settings",
169303
169358
  items: picker.items,
169359
+ filterMode: "substring",
169304
169360
  selectedIndex: picker.selectedIndex
169305
169361
  });
169306
169362
  if (!choice) return;
@@ -87460,7 +87460,7 @@ var ZCODE_CUA_HELPER_BUILD_ID;
87460
87460
  var init_cua_version = __esm({
87461
87461
  "src/broker/shared/cua-version.ts"() {
87462
87462
  "use strict";
87463
- ZCODE_CUA_HELPER_BUILD_ID = true ? "pipeline-298526-10bbcea5" : "";
87463
+ ZCODE_CUA_HELPER_BUILD_ID = true ? "pipeline-299589-639500b6" : "";
87464
87464
  }
87465
87465
  });
87466
87466
  var init_shared = __esm({