zcode-app-cli 3.14.4-31 → 3.14.4-33
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 +56 -7
- package/bin/zcode.js +85 -11
- package/docs/CONFIGURATION.md +185 -6
- package/docs/CONFIGURATION.zh-CN.md +161 -5
- package/docs/PROVIDER_CONFIG.md +4 -2
- package/docs/PROVIDER_CONFIG.zh-CN.md +3 -2
- package/package.json +1 -1
- package/vendor/cli-config.cjs +106 -3
- package/vendor/extraction.json +21 -1
- package/vendor/node_modules/@zcode/tui/dist/index.js +51 -10
- package/vendor/zcode.cjs +7 -7
package/README.md
CHANGED
|
@@ -449,8 +449,10 @@ browser for interactive login or verification flows.
|
|
|
449
449
|
- Node.js 22.19 or newer;
|
|
450
450
|
- macOS, Linux or Windows on x64 or ARM64.
|
|
451
451
|
|
|
452
|
-
Z.AI browser OAuth
|
|
453
|
-
|
|
452
|
+
Z.AI browser OAuth uses the official runtime's server-mediated login on Linux
|
|
453
|
+
and Windows: the browser returns to ZCode's registered HTTPS callback while
|
|
454
|
+
the CLI polls for completion. macOS uses `zcode://zai-auth/callback` through
|
|
455
|
+
the Desktop callback bridge. API-key and custom-provider access work
|
|
454
456
|
on every supported platform.
|
|
455
457
|
|
|
456
458
|
Set `ZCODE_NODE=/absolute/path/to/node` when the desired Node.js executable is
|
|
@@ -458,14 +460,61 @@ not available on `PATH`.
|
|
|
458
460
|
|
|
459
461
|
## Configuration
|
|
460
462
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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
|
+
|
|
473
|
+
ZCode reads MCP servers, hooks, plugins, permissions, network, storage and display
|
|
474
|
+
settings from `~/.zcode/cli/setting.json` (or
|
|
475
|
+
`%USERPROFILE%\.zcode\cli\setting.json` on Windows). Project settings use
|
|
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.
|
|
480
|
+
|
|
481
|
+
Custom MCP servers go in the top-level `mcp.servers` object in `setting.json`.
|
|
482
|
+
See [MCP configuration](./docs/CONFIGURATION.md#mcp-servers) for HTTP/stdio examples,
|
|
483
|
+
supported fields, loading diagnostics and the MCP-specific precedence rule
|
|
484
|
+
(user definitions win over project definitions with the same server name).
|
|
485
|
+
Run `zcode doctor --json` to inspect loaded configuration paths, MCP names and
|
|
486
|
+
sources, and validation errors without starting MCP servers or sending a model
|
|
487
|
+
request. Plugin and built-in MCP servers are added separately when a session starts.
|
|
488
|
+
The `setting.json` filename is this package's adaptation of the upstream CLI's
|
|
489
|
+
`config.json`. See [upstream source and file paths](./docs/CONFIGURATION.md#upstream-source-and-file-paths)
|
|
490
|
+
for the distinction from Desktop's MCP settings.
|
|
465
491
|
|
|
466
492
|
Provider settings and the default model are stored in
|
|
467
493
|
`~/.zcode/v2/provider_config.json`, shared with ZCode Desktop by default.
|
|
468
494
|
Use `ZCODE_PERSONAL_PROVIDER_CONFIG_FILE` for an independent CLI provider file.
|
|
495
|
+
That file has its own custom providers and model overrides. To retain an
|
|
496
|
+
existing Desktop catalog, copy `~/.zcode/v2/provider_config.json` to the chosen
|
|
497
|
+
CLI provider path before the first login, with mode 600. Do not overwrite an
|
|
498
|
+
existing CLI provider file: merge its missing provider and model rules instead,
|
|
499
|
+
preserving the CLI's `defaultModelSelection`. Later Desktop catalog changes
|
|
500
|
+
must also be copied or merged into the independent file.
|
|
501
|
+
To keep CLI OAuth credentials independent of Desktop too, set
|
|
502
|
+
`ZCODE_CLI_CREDENTIALS_FILE` before both login and prompt runs:
|
|
503
|
+
|
|
504
|
+
```bash
|
|
505
|
+
export ZCODE_CLI_CREDENTIALS_FILE="$HOME/.zcode/cli/credentials.json"
|
|
506
|
+
export ZCODE_PERSONAL_PROVIDER_CONFIG_FILE="$HOME/.zcode/cli/provider_config.json"
|
|
507
|
+
zcode login --oauth --no-browser
|
|
508
|
+
zcode --prompt 'Reply with exactly: ok'
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
The browser authorization uses the registered ZCode client ID. The runtime
|
|
512
|
+
stores the login and resolves Coding Plan access using its native account
|
|
513
|
+
provider registry. The credential file remains private (mode 600). These
|
|
514
|
+
overrides leave Desktop's credentials and provider configuration untouched.
|
|
515
|
+
Client headers and a local usage row do not independently prove server-side
|
|
516
|
+
bonus accounting.
|
|
517
|
+
|
|
469
518
|
`/settings` saves the default model; `/model` changes only the current session.
|
|
470
519
|
See [`provider.example.json`](./provider.example.json) for complete field examples
|
|
471
520
|
and the [provider configuration reference](./docs/PROVIDER_CONFIG.md) for multimodal
|
|
@@ -476,7 +525,7 @@ models demonstrate explicit overrides and manual configuration.
|
|
|
476
525
|
[Provider 配置字段参考](./docs/PROVIDER_CONFIG.zh-CN.md)。
|
|
477
526
|
The project follows the current upstream runtime and configuration schema.
|
|
478
527
|
|
|
479
|
-
Three model-access paths are supported: Z.AI OAuth
|
|
528
|
+
Three model-access paths are supported: Z.AI OAuth, Z.AI/BigModel
|
|
480
529
|
Coding Plan API key, or a direct API key with a custom provider. For detailed
|
|
481
530
|
setup steps, retries/timeouts, theme, and turn-completion notifications, see
|
|
482
531
|
[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
|
|
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(
|
|
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 {
|
|
@@ -115,6 +124,9 @@ function providerConfigPath(env = process.env, platform = process.platform, fall
|
|
|
115
124
|
const path = platform === "win32" ? win32 : posix;
|
|
116
125
|
return env.ZCODE_PERSONAL_PROVIDER_CONFIG_FILE?.trim() || path.join(sharedDataBaseDir(env, platform, fallbackHome), ".zcode", "v2", "provider_config.json");
|
|
117
126
|
}
|
|
127
|
+
function credentialsPath(env = process.env) {
|
|
128
|
+
return env.ZCODE_CLI_CREDENTIALS_FILE?.trim() || join(sharedDataBaseDir(env), ".zcode", "v2", "credentials.json");
|
|
129
|
+
}
|
|
118
130
|
function legacyCliConfigPath(env = process.env) {
|
|
119
131
|
return join(dirname(cliSettingsPath(env)), "config.json");
|
|
120
132
|
}
|
|
@@ -243,7 +255,6 @@ function record$1(value) {
|
|
|
243
255
|
}
|
|
244
256
|
/** Configuration presence only; the runtime owns credential decryption and authentication. */
|
|
245
257
|
async function readConfiguredModelAccess(env = process.env) {
|
|
246
|
-
const directory = join(sharedDataBaseDir(env), ".zcode", "v2");
|
|
247
258
|
const configPath = providerConfigPath(env);
|
|
248
259
|
let value;
|
|
249
260
|
try {
|
|
@@ -263,7 +274,7 @@ async function readConfiguredModelAccess(env = process.env) {
|
|
|
263
274
|
providerId
|
|
264
275
|
};
|
|
265
276
|
if (providerId.startsWith("account:")) try {
|
|
266
|
-
const credentials = record$1(JSON.parse(await readFile(
|
|
277
|
+
const credentials = record$1(JSON.parse(await readFile(credentialsPath(env), "utf8")));
|
|
267
278
|
const identity = credentials?.[`account-provider:${providerId}:identity`];
|
|
268
279
|
const keyPrefix = `account-provider:coding-plan:${providerId}:account:`;
|
|
269
280
|
return typeof identity === "string" && identity.length > 0 && Object.entries(credentials ?? {}).some(([key, secret]) => key.startsWith(keyPrefix) && key.endsWith(":api-key") && typeof secret === "string" && secret.length > 0) ? result : null;
|
|
@@ -663,6 +674,9 @@ const supportedLoginFlags = /* @__PURE__ */ new Set([
|
|
|
663
674
|
"--oauth",
|
|
664
675
|
"--verbose"
|
|
665
676
|
]);
|
|
677
|
+
function usesNativeZaiOAuth(platform = process.platform) {
|
|
678
|
+
return platform !== "darwin";
|
|
679
|
+
}
|
|
666
680
|
function classifyZaiOAuthInvocation(args) {
|
|
667
681
|
const positionals = args.filter((argument) => !argument.startsWith("-"));
|
|
668
682
|
if (positionals.length !== 1 || positionals[0] !== "login") return null;
|
|
@@ -1460,6 +1474,37 @@ async function missingCodingPlanKey(options = {}) {
|
|
|
1460
1474
|
return message(providerId);
|
|
1461
1475
|
}
|
|
1462
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
|
|
1463
1508
|
//#region src/runtime-capabilities.ts
|
|
1464
1509
|
function isRecord(value) {
|
|
1465
1510
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -1653,12 +1698,13 @@ function inspectRuntimeInvocation(args, runtimeOptionTypes) {
|
|
|
1653
1698
|
resume
|
|
1654
1699
|
};
|
|
1655
1700
|
}
|
|
1656
|
-
async function promptPreflight(args, env = process.env) {
|
|
1701
|
+
async function promptPreflight(args, env = process.env, model) {
|
|
1657
1702
|
const invocation = inspectRuntimeInvocation(args, readRuntimeCliOptionTypes());
|
|
1658
1703
|
if (!invocation.agentInvocation || invocation.invalid || invocation.passthrough || invocation.resume) return;
|
|
1659
1704
|
return missingCodingPlanKey({
|
|
1660
1705
|
env,
|
|
1661
|
-
workingDirectory: invocation.workingDirectory
|
|
1706
|
+
workingDirectory: invocation.workingDirectory,
|
|
1707
|
+
model
|
|
1662
1708
|
});
|
|
1663
1709
|
}
|
|
1664
1710
|
function withDefaultBrowserUse(args, runtimeOptionTypes = readRuntimeCliOptionTypes()) {
|
|
@@ -1670,26 +1716,33 @@ function isTuiRuntimeInvocation(args, runtimeOptionTypes = readRuntimeCliOptionT
|
|
|
1670
1716
|
const invocation = inspectRuntimeInvocation(args, runtimeOptionTypes);
|
|
1671
1717
|
return !invocation.agentInvocation && !invocation.invalid && !invocation.passthrough && (invocation.command === void 0 || invocation.command === "tui");
|
|
1672
1718
|
}
|
|
1719
|
+
function isDoctorRuntimeInvocation(args, runtimeOptionTypes = readRuntimeCliOptionTypes()) {
|
|
1720
|
+
const invocation = inspectRuntimeInvocation(args, runtimeOptionTypes);
|
|
1721
|
+
return !invocation.agentInvocation && !invocation.invalid && invocation.command === "doctor";
|
|
1722
|
+
}
|
|
1673
1723
|
function firstRunSetupEnv(setupPending, args) {
|
|
1674
1724
|
if (!setupPending || !isTuiRuntimeInvocation(args)) return void 0;
|
|
1675
1725
|
return { ZCODE_CLI_FIRST_RUN: "1" };
|
|
1676
1726
|
}
|
|
1677
|
-
function runtimeEnvironment(extra = {}) {
|
|
1727
|
+
function runtimeEnvironment(extra = {}, inspectConfiguration = false) {
|
|
1678
1728
|
const env = { ...process.env };
|
|
1679
1729
|
delete env.ZCODE_CLI_OAUTH_CALLBACK_STDIN;
|
|
1680
1730
|
delete env.ZCODE_CLI_MIGRATE_CONFIG;
|
|
1731
|
+
delete env.ZCODE_CLI_PROMPT_MODEL;
|
|
1681
1732
|
const distributionVersion = readDistributionVersion();
|
|
1733
|
+
const appVersion = readJsonVersion(extractionMetadataPath, "appVersion");
|
|
1682
1734
|
const inherited = {
|
|
1683
1735
|
...env,
|
|
1684
1736
|
...extra
|
|
1685
1737
|
};
|
|
1686
1738
|
const merged = {
|
|
1687
1739
|
...inherited,
|
|
1688
|
-
ZCODE_DATA_BASE_DIR: sharedDataBaseDir(inherited),
|
|
1740
|
+
...inspectConfiguration ? {} : { ZCODE_DATA_BASE_DIR: sharedDataBaseDir(inherited) },
|
|
1689
1741
|
ZCODE_BASE_URL: resolveZCodeBaseUrl(inherited),
|
|
1690
1742
|
ZCODE_MODEL_RETRY_MAX_RETRIES: resolveModelRetryMaxRetries(inherited),
|
|
1691
1743
|
ZCODE_APP_CLI_EXECUTABLE: process.execPath,
|
|
1692
1744
|
ZCODE_APP_CLI_ENTRY: launcherPath,
|
|
1745
|
+
...appVersion ? { ZCODE_APP_VERSION: inherited.ZCODE_APP_VERSION?.trim() || appVersion } : {},
|
|
1693
1746
|
...distributionVersion ? { ZCODE_APP_CLI_VERSION: distributionVersion } : {}
|
|
1694
1747
|
};
|
|
1695
1748
|
return Object.fromEntries(Object.entries(merged).filter((entry) => typeof entry[1] === "string"));
|
|
@@ -1757,7 +1810,7 @@ async function runRuntime(node, args, extraEnv = {}) {
|
|
|
1757
1810
|
const tuiInvocation = isTuiRuntimeInvocation(args);
|
|
1758
1811
|
const child = spawn(node, [runtimePath, ...args], {
|
|
1759
1812
|
cwd: process.cwd(),
|
|
1760
|
-
env: runtimeEnvironment(extraEnv),
|
|
1813
|
+
env: runtimeEnvironment(extraEnv, isDoctorRuntimeInvocation(args)),
|
|
1761
1814
|
stdio: tuiInvocation ? [
|
|
1762
1815
|
"inherit",
|
|
1763
1816
|
"inherit",
|
|
@@ -1828,8 +1881,18 @@ async function main(args) {
|
|
|
1828
1881
|
console.log(formatVersionOutput(distributionVersion, runtimeVersion));
|
|
1829
1882
|
return 0;
|
|
1830
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
|
+
}
|
|
1831
1893
|
let setupPending = false;
|
|
1832
1894
|
try {
|
|
1895
|
+
if (isDoctorRuntimeInvocation(args)) return await runRuntime(resolveNodeExecutable(), args);
|
|
1833
1896
|
const bootstrap = await ensureCliSettings();
|
|
1834
1897
|
await readCliSettings();
|
|
1835
1898
|
sharedDataBaseDir();
|
|
@@ -1839,6 +1902,7 @@ async function main(args) {
|
|
|
1839
1902
|
} else setupPending = await readSetupPending();
|
|
1840
1903
|
} catch (error) {
|
|
1841
1904
|
console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
1905
|
+
console.error("Run `zcode doctor --json` for configuration diagnostics.");
|
|
1842
1906
|
return 1;
|
|
1843
1907
|
}
|
|
1844
1908
|
const node = resolveNodeExecutable();
|
|
@@ -1903,6 +1967,11 @@ async function main(args) {
|
|
|
1903
1967
|
}
|
|
1904
1968
|
}
|
|
1905
1969
|
if (zaiOAuth) {
|
|
1970
|
+
if (usesNativeZaiOAuth()) {
|
|
1971
|
+
const code = await runRuntime(node, zaiOAuth.runtimeArgs);
|
|
1972
|
+
if (code === 0 && await readConfiguredModelAccess()) await clearSetupPending();
|
|
1973
|
+
return code;
|
|
1974
|
+
}
|
|
1906
1975
|
const abortController = new AbortController();
|
|
1907
1976
|
const cancel = (signal) => () => abortController.abort(signal);
|
|
1908
1977
|
const onSigint = cancel("SIGINT");
|
|
@@ -1930,13 +1999,18 @@ async function main(args) {
|
|
|
1930
1999
|
}
|
|
1931
2000
|
}
|
|
1932
2001
|
try {
|
|
1933
|
-
const diagnostic = await readConfiguredModelAccess() ? void 0 : await promptPreflight(login.args);
|
|
2002
|
+
const diagnostic = await readConfiguredModelAccess() ? void 0 : await promptPreflight(login.args, process.env, promptModel);
|
|
1934
2003
|
if (diagnostic) {
|
|
1935
2004
|
console.error(diagnostic);
|
|
1936
2005
|
return 1;
|
|
1937
2006
|
}
|
|
1938
2007
|
const runtimeArgs = withDefaultBrowserUse(login.args);
|
|
1939
|
-
|
|
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;
|
|
1940
2014
|
} catch (error) {
|
|
1941
2015
|
console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
1942
2016
|
return 1;
|
package/docs/CONFIGURATION.md
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
English | [简体中文](CONFIGURATION.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
The CLI follows the current ZCode runtime's provider registry schema.
|
|
6
|
-
|
|
5
|
+
The CLI follows the current ZCode runtime's provider registry schema. Provider
|
|
6
|
+
and model settings live in `provider_config.json`; MCP servers, hooks, plugins,
|
|
7
|
+
permissions and other general runtime settings live in the CLI's `setting.json`.
|
|
7
8
|
|
|
8
9
|
## Configuration files
|
|
9
10
|
|
|
10
11
|
| File | Purpose |
|
|
11
12
|
| --- | --- |
|
|
12
|
-
| `~/.zcode/cli/setting.json` |
|
|
13
|
+
| `~/.zcode/cli/setting.json` | MCP servers, hooks, plugins, permissions, network, storage and CLI display settings |
|
|
13
14
|
| `~/.zcode/v2/setting.json` | Existing Desktop language and memory preferences, read without modification |
|
|
14
15
|
| `~/.zcode/v2/provider_config.json` | Providers, model metadata overrides and the default model |
|
|
15
16
|
| `~/.zcode/v2/credentials.json` | Credentials persisted by the native runtime |
|
|
@@ -20,8 +21,20 @@ both clients. `/model` changes only the current CLI session.
|
|
|
20
21
|
|
|
21
22
|
Set `ZCODE_PERSONAL_PROVIDER_CONFIG_FILE` to a separate file to isolate provider
|
|
22
23
|
settings. `ZCODE_DATA_BASE_DIR` changes the native runtime's base directory,
|
|
23
|
-
including its provider and credential storage. General CLI settings
|
|
24
|
-
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.
|
|
25
38
|
|
|
26
39
|
On first launch, the CLI creates a credential-free general configuration from
|
|
27
40
|
[`setting.example.json`](../setting.example.json). Existing files are not replaced.
|
|
@@ -92,13 +105,179 @@ reported rather than replaced by old settings.
|
|
|
92
105
|
| Resume/restart | Restores the session's model and reasoning options |
|
|
93
106
|
| Language and memory | Reads Desktop `localePreference` / `memoryEnabled`; explicit CLI settings override these values |
|
|
94
107
|
| Theme, terminal layout, copy-on-select and notifications | CLI `setting.json` |
|
|
95
|
-
|
|
|
108
|
+
| MCP servers | CLI `setting.json` → `mcp.servers`; [MCP precedence](#project-settings-and-plugins) applies to project and plugin servers |
|
|
109
|
+
| Tool permissions, retries, stream timeout, hooks, plugins and other runtime settings | CLI `setting.json`, with native project/environment precedence |
|
|
96
110
|
| Update cache, diagnostic logs and migration state | Operational files beneath the CLI directory |
|
|
97
111
|
|
|
98
112
|
The CLI does not add keys to Desktop's `setting.json`. Notification and display
|
|
99
113
|
changes write only the CLI file. Shared preferences are applied while loading
|
|
100
114
|
runtime settings, not copied into CLI settings during unrelated updates.
|
|
101
115
|
|
|
116
|
+
## MCP servers
|
|
117
|
+
|
|
118
|
+
Add servers under the top-level `mcp.servers` object in
|
|
119
|
+
`~/.zcode/cli/setting.json`. The keys are server names. `mcp`, `features`,
|
|
120
|
+
`permission`, `plugins` and `hooks` are siblings in this file; the
|
|
121
|
+
`schemaVersion` / `config` wrapper belongs to `provider_config.json`.
|
|
122
|
+
|
|
123
|
+
Merge this example into your existing settings, replacing the endpoint and
|
|
124
|
+
executable with your own running HTTP server and installed stdio server:
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"features": {
|
|
129
|
+
"mcp": true
|
|
130
|
+
},
|
|
131
|
+
"mcp": {
|
|
132
|
+
"servers": {
|
|
133
|
+
"basic-memory": {
|
|
134
|
+
"type": "http",
|
|
135
|
+
"url": "http://127.0.0.1:18796/mcp"
|
|
136
|
+
},
|
|
137
|
+
"token-savior": {
|
|
138
|
+
"type": "stdio",
|
|
139
|
+
"command": "/absolute/path/to/token-savior-mcp",
|
|
140
|
+
"args": [],
|
|
141
|
+
"timeoutMs": 30000
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The runtime reads this file on startup. Restart ZCode after changing MCP
|
|
149
|
+
settings. The `settings-v1.json` marker only controls migration from the old
|
|
150
|
+
CLI `config.json`; it does not prevent later edits to `setting.json` from loading.
|
|
151
|
+
Changing the model/provider file or completing provider login does not configure
|
|
152
|
+
custom MCP servers.
|
|
153
|
+
|
|
154
|
+
### Server fields
|
|
155
|
+
|
|
156
|
+
| Field | Applies to | Meaning |
|
|
157
|
+
| --- | --- | --- |
|
|
158
|
+
| `type` | All | `"stdio"`, `"http"` or `"sse"`; use the transport supported by your server |
|
|
159
|
+
| `command` | stdio | Executable name or absolute path; put command arguments in `args` |
|
|
160
|
+
| `args` | stdio | Optional array of strings |
|
|
161
|
+
| `env` | stdio | Optional object of environment variable names to string values |
|
|
162
|
+
| `cwd` | stdio | Optional working directory for the server process |
|
|
163
|
+
| `url` | HTTP / SSE | Server endpoint, including its MCP or SSE path |
|
|
164
|
+
| `headers` | HTTP / SSE | Optional object of header names to string values, such as `Authorization` |
|
|
165
|
+
| `oauth` | HTTP / SSE | Optional OAuth configuration; see below |
|
|
166
|
+
| `enabled` | All | Set to `false` to disable a server while keeping its configuration |
|
|
167
|
+
| `timeoutMs` | All | Optional positive number in milliseconds; use this field instead of `timeout` or `startup_timeout_sec` |
|
|
168
|
+
| `protocolVersion` | All | Optional `"auto"`, `"legacy"` or `"2026-07-28"` in runtime 0.16.9; normally leave unset for automatic negotiation |
|
|
169
|
+
|
|
170
|
+
For OAuth, `oauth.type` accepts `"authorization_code"` or `"client_credentials"`.
|
|
171
|
+
Both accept `clientId`, `clientSecret`, `clientName` and `scope`; client credentials
|
|
172
|
+
requires `clientId` and `clientSecret`, while authorization code also accepts
|
|
173
|
+
`redirectPath`. Configure these only when required by the MCP server.
|
|
174
|
+
|
|
175
|
+
### Project settings and plugins
|
|
176
|
+
|
|
177
|
+
Project `zcode.json` or `.zcode/config.json` files use the same `mcp.servers`
|
|
178
|
+
structure. In a Git worktree, the runtime discovers those files from the worktree
|
|
179
|
+
root through the working directory; outside a worktree, it checks the working
|
|
180
|
+
directory. For project stdio servers, relative `cwd` values resolve against the
|
|
181
|
+
project configuration's base directory (the parent of `.zcode` for
|
|
182
|
+
`.zcode/config.json`); an omitted `cwd` uses that directory.
|
|
183
|
+
|
|
184
|
+
MCP servers merge by name. **User settings take precedence over project settings
|
|
185
|
+
for the same server name** in the current runtime; distinct names from both
|
|
186
|
+
sources remain available. This is an exception to the usual project-override
|
|
187
|
+
rule for other settings. An empty user `mcp.servers` object does not disable
|
|
188
|
+
project or plugin servers. Use `enabled: false` on a named server, or
|
|
189
|
+
`features.mcp: false` to disable MCP as a whole.
|
|
190
|
+
|
|
191
|
+
Enabled plugins also contribute servers. Their definitions come from the
|
|
192
|
+
plugin's `.mcp.json` or manifest, and normally appear as
|
|
193
|
+
`plugin:<plugin-name>:<server-name>`. Keep standalone user MCP definitions in
|
|
194
|
+
`setting.json`; this CLI does not automatically read `.agents/mcp.json`.
|
|
195
|
+
Plugin controls remain under `plugins`, hook declarations under
|
|
196
|
+
`hooks.events.<Event>`, and tool permissions under `permission` in `setting.json`.
|
|
197
|
+
|
|
198
|
+
### Upstream source and file paths
|
|
199
|
+
|
|
200
|
+
These paths distinguish the packaged CLI from the upstream application. The
|
|
201
|
+
source references below are pinned to upstream
|
|
202
|
+
[`29628c9` / `v3.14.3`](https://github.com/zai-org/ZCode/tree/29628c9acdb81b703bbd4080c207a0e7ce5e276e).
|
|
203
|
+
This package's runtime lock selects the separate Desktop 3.14.4 artifact; the
|
|
204
|
+
public source snapshot is not an assertion of that artifact's build commit.
|
|
205
|
+
|
|
206
|
+
| Client / source | User MCP file | JSON path |
|
|
207
|
+
| --- | --- | --- |
|
|
208
|
+
| Unpatched upstream CLI | `~/.zcode/cli/config.json` | `mcp.servers` |
|
|
209
|
+
| This package, `zcode-app-cli` | `~/.zcode/cli/setting.json` | `mcp.servers` |
|
|
210
|
+
| Upstream Desktop's ZCode directory source | `~/.zcode/cli/config.json` | `mcp.servers` |
|
|
211
|
+
| Upstream Desktop's `.agents` fallback | `~/.agents/mcp.json` | `mcpServers` |
|
|
212
|
+
|
|
213
|
+
The upstream [file loader](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/apps/zcode-cli/packages/adapters/src/config/file-config.adapter.ts#L61-L118)
|
|
214
|
+
defaults to `config.json`. This package's
|
|
215
|
+
[`patchRuntimeSharedConfig`](https://github.com/kingsword09/zcode-cli/blob/e93caf41292314bd751180cf9b08f6d18895a5b5/scripts/sync-runtime.ts#L1026-L1046)
|
|
216
|
+
changes that filename to `setting.json`. The
|
|
217
|
+
[general-settings schema](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/apps/zcode-cli/packages/adapters/src/config/schema.ts#L286-L306)
|
|
218
|
+
contains `mcp`, `plugins`, `permission` and `hooks`. The separate, strict
|
|
219
|
+
[provider-file schema](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/packages/provider-node/src/provider-config-file-codec.ts#L18-L30)
|
|
220
|
+
accepts provider/model rules, provider order and default model selection; adding
|
|
221
|
+
MCP there fails its schema validation. The
|
|
222
|
+
[MCP merge function](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/apps/zcode-cli/packages/adapters/src/config/config-factory.ts#L372-L397)
|
|
223
|
+
explicitly applies user definitions after project definitions.
|
|
224
|
+
|
|
225
|
+
Desktop has a separate
|
|
226
|
+
[MCP directory reader and writer](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/packages/desktop/src/main/mcpUserDirectory/index.ts#L37-L69).
|
|
227
|
+
For each user/project scope, it
|
|
228
|
+
[falls back to `.agents/mcp.json`](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/packages/desktop/src/main/mcpUserDirectory/index.ts#L334-L375)
|
|
229
|
+
when that scope's ZCode file has no MCP entries. Project files are
|
|
230
|
+
`.zcode/config.json` and `.agents/mcp.json`, respectively. Sharing
|
|
231
|
+
`provider_config.json` with Desktop does not synchronize these user MCP files
|
|
232
|
+
with this package's `setting.json`; the old CLI file is only imported during the
|
|
233
|
+
one-time migration described above.
|
|
234
|
+
|
|
235
|
+
### Checking whether settings loaded
|
|
236
|
+
|
|
237
|
+
Run `zcode doctor` to inspect configuration paths, loading status, validated MCP
|
|
238
|
+
server names and their user/project sources. For a report suitable for debugging:
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
zcode doctor --json
|
|
242
|
+
zcode --cwd /path/to/project doctor --json
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
The JSON output keeps the existing runtime metadata and adds `configuration`:
|
|
246
|
+
`user.path` / `user.status`, `project.paths` / `project.status`, `mcp.enabled`,
|
|
247
|
+
`mcp.servers` and `diagnostics`. Status is `loaded`, `missing` or `invalid`.
|
|
248
|
+
Diagnostics identify the file and rejected field. Server records include only
|
|
249
|
+
name, transport, enabled state and source; command arguments, URLs, environment
|
|
250
|
+
variables, headers and credentials are omitted. `provider.path` identifies the
|
|
251
|
+
provider file; this check does not validate provider credentials.
|
|
252
|
+
|
|
253
|
+
Doctor works without login and even when `setting.json` contains invalid JSON.
|
|
254
|
+
It skips first-run settings creation and provider migration, and reports the old
|
|
255
|
+
`config.json` as a migration source only. It does not start MCP servers or send
|
|
256
|
+
model requests. A missing settings file is allowed; rejected settings or skipped
|
|
257
|
+
MCP entries produce exit code `1`. Valid configuration produces exit code `0`.
|
|
258
|
+
|
|
259
|
+
The server list covers user/project configuration. Plugin and built-in MCP
|
|
260
|
+
servers are added separately at session startup, and this check does not test
|
|
261
|
+
connectivity. Use `/status` in the TUI to inspect connected MCP servers. The
|
|
262
|
+
default structured runtime logs are under `~/.zcode/cli/log/`. When a server is
|
|
263
|
+
missing, these events provide the session's loading and connection evidence:
|
|
264
|
+
|
|
265
|
+
| Event | What to check |
|
|
266
|
+
| --- | --- |
|
|
267
|
+
| `bootstrap.app.startup.config.completed` | `context.configSourceUser` indicates whether the user settings file loaded |
|
|
268
|
+
| `config.file.invalid` | `context.configPath` and `context.diagnosticMessage` identify a file-level parsing or schema error |
|
|
269
|
+
| `config.mcp_server.skipped` | `context.diagnosticPath` and `context.diagnosticMessage` identify an invalid server entry |
|
|
270
|
+
| `mcp.configured_servers.connect.started` | `context.serverNames` lists the servers selected for connection |
|
|
271
|
+
| `mcp.configured_servers.connect.completed` | Connection status and tool counts distinguish loading from connection failures |
|
|
272
|
+
|
|
273
|
+
Valid JSON must also satisfy the runtime schema. A schema error outside an
|
|
274
|
+
individual MCP server entry can cause the entire settings file to be ignored.
|
|
275
|
+
For example, `ui.theme: "system"` is invalid; supported values are `"auto"`,
|
|
276
|
+
`"dark"` and `"light"`. In that case the runtime can still start with default
|
|
277
|
+
settings and plugin servers. `features.mcp` defaults to `true`, so seeing MCP
|
|
278
|
+
enabled does not prove the user file loaded. A malformed individual server entry
|
|
279
|
+
is skipped with `config.mcp_server.skipped`; valid entries can still load.
|
|
280
|
+
|
|
102
281
|
## Model catalogs and default selection
|
|
103
282
|
|
|
104
283
|
The native registry loads the bundled catalog and manages upstream catalog
|