zcode-app-cli 3.14.4-33 → 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
@@ -510,7 +510,10 @@ zcode --prompt 'Reply with exactly: ok'
510
510
 
511
511
  The browser authorization uses the registered ZCode client ID. The runtime
512
512
  stores the login and resolves Coding Plan access using its native account
513
- 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
514
517
  overrides leave Desktop's credentials and provider configuration untouched.
515
518
  Client headers and a local usage row do not independently prove server-side
516
519
  bonus accounting.
@@ -525,7 +528,7 @@ models demonstrate explicit overrides and manual configuration.
525
528
  [Provider 配置字段参考](./docs/PROVIDER_CONFIG.zh-CN.md)。
526
529
  The project follows the current upstream runtime and configuration schema.
527
530
 
528
- 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
529
532
  Coding Plan API key, or a direct API key with a custom provider. For detailed
530
533
  setup steps, retries/timeouts, theme, and turn-completion notifications, see
531
534
  [Configuration](./docs/CONFIGURATION.md).
@@ -307,6 +307,10 @@ provider configuration is recognized directly; no desktop import step is needed.
307
307
  authorization. `--no-browser` prints the authorization URL.
308
308
  - **Z.AI/BigModel Coding Plan API key:** open `/login` and choose the masked
309
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.
310
314
  - **Custom provider:** configure the native provider file directly. Any provider
311
315
  ID can be used; a separate OAuth login is unnecessary.
312
316
 
@@ -318,7 +322,34 @@ For macOS OAuth, the CLI temporarily registers a callback receiver, checks
318
322
  `state`, restores the previous `zcode://` handler and sends the callback through
319
323
  stdin. The runtime exchanges the token, stores encrypted credentials, resolves
320
324
  the Coding Plan API key and saves the native default model. The TUI then rereads
321
- 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.
322
353
 
323
354
  ## Custom provider
324
355
 
@@ -265,6 +265,9 @@ Provider 文件中的 `config.defaultModelSelection` 决定新会话使用的模
265
265
  `--no-browser` 只输出授权链接。
266
266
  - **Z.AI/BigModel Coding Plan API Key:** 打开 `/login`,选择掩码输入的 API Key 选项。
267
267
  凭证和 provider 的保存由官方 runtime 负责。
268
+ - **BigModel 浏览器 OAuth:** 在 `/login` 中选择 **BigModel Coding Plan**,或运行
269
+ `/login bigmodel-coding-plan`。CLI 通过 Desktop 使用的官方 ZCode 令牌服务交换授权码,
270
+ 无需在 CLI 中配置 OAuth 应用密钥。
268
271
  - **自定义 provider:** 直接配置原生 provider 文件,可使用自定义 ID,无需额外 OAuth 登录。
269
272
 
270
273
  普通的 `zcode login` 会识别已经配置的原生默认模型并提示配置路径。
@@ -272,7 +275,26 @@ Provider 文件中的 `config.defaultModelSelection` 决定新会话使用的模
272
275
 
273
276
  macOS OAuth 会临时注册回调接收器、校验 `state`,恢复原来的 `zcode://` 处理程序,并通过
274
277
  stdin 把回调交给 runtime。Runtime 交换令牌、保存加密凭证、解析 Coding Plan API Key,
275
- 再保存原生默认模型;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 使用。
276
298
 
277
299
  ## 自定义 Provider
278
300
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcode-app-cli",
3
- "version": "3.14.4-33",
3
+ "version": "3.14.5-34",
4
4
  "description": "Unofficial terminal client for the ZCode agent runtime",
5
5
  "keywords": [
6
6
  "agent",
@@ -5,6 +5,7 @@ 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
10
  function homeCliSettingsPath(env, platform, fallbackHome) {
10
11
  const path = platform === "win32" ? node_path.win32 : node_path.posix;
@@ -662,6 +663,74 @@ function appServerRegistryOptions(env, createRefreshReporter) {
662
663
  return appServerAuthMode(env) === "host" ? {} : { standalone: createRefreshReporter(process.stderr) };
663
664
  }
664
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
665
734
  //#region src/config-diagnostics.ts
666
735
  const schemaDiagnosticPrefix = /^(?:<config>|modelStream|permission|storage|network|features|memory|mcp|plugins|skills|skill|command|logging|ui|toolConcurrency|modelAnomalyGuard|hooks)(?:[.:[\]]|$)/u;
667
736
  function publicDiagnostic(diagnostic, scope) {
@@ -872,6 +941,8 @@ async function migrateLegacyProviders(options) {
872
941
  //#endregion
873
942
  exports.appServerRegistryOptions = appServerRegistryOptions;
874
943
  exports.assertSessionModelReady = assertSessionModelReady;
944
+ exports.browserOpenCommand = browserOpenCommand;
945
+ exports.exchangeBigmodelOAuthCode = exchangeBigmodelOAuthCode;
875
946
  exports.inspectRuntimeConfiguration = inspectRuntimeConfiguration;
876
947
  exports.installSqliteWriteRecovery = installSqliteWriteRecovery;
877
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-08T06:18:19.033Z",
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": {
@@ -206,11 +206,26 @@
206
206
  "requirement": "required",
207
207
  "status": "applied"
208
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
+ },
209
219
  {
210
220
  "id": "desktop-oauth",
211
221
  "requirement": "required",
212
222
  "status": "applied"
213
223
  },
224
+ {
225
+ "id": "bigmodel-session-reuse",
226
+ "requirement": "optional",
227
+ "status": "applied"
228
+ },
214
229
  {
215
230
  "id": "login-model-defaults",
216
231
  "requirement": "required",
@@ -166924,6 +166924,7 @@ var ZCodeTui = class {
166924
166924
  this.model = access.model;
166925
166925
  this.setLoginRequired(false);
166926
166926
  this.addNotice(`Model access configured via ${access.configPath}.`, "muted");
166927
+ await this.adoptLoginModel();
166927
166928
  } else if (failure) this.addNotice(`Login command failed: ${failure}`, "error");
166928
166929
  else if (code !== 0) {
166929
166930
  const diagnostic = loginFailureDiagnostic(childStdout, childStderr);
@@ -167424,6 +167425,7 @@ var ZCodeTui = class {
167424
167425
  if (input.startsWith("/") || !this.options.sendInput) {
167425
167426
  const result = await this.options.submitPrompt(input.startsWith("/") ? input : promptInput(runtimeInput, attachments), callOptions);
167426
167427
  await this.handleResult(result, true, settingTargetForCommand(input));
167428
+ if (/^\/login\s+\S/iu.test(input) && isRecord(result) && result.loginRequired === false) await this.adoptLoginModel();
167427
167429
  accepted = true;
167428
167430
  } else {
167429
167431
  const preparedInput = promptInput(runtimeInput, attachments);
@@ -169266,6 +169268,21 @@ var ZCodeTui = class {
169266
169268
  await this.applyModeShortcut(normalizedMode(mode));
169267
169269
  return true;
169268
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
+ }
169269
169286
  /** All model selectors re-read the catalog, including after first-run login. */
169270
169287
  async refreshModelOptions() {
169271
169288
  const load = this.options.reloadModelOptions;
@@ -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({