zcode-app-cli 3.14.4-31 → 3.14.4-32
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 +43 -7
- package/bin/zcode.js +23 -5
- package/docs/CONFIGURATION.md +171 -4
- package/docs/CONFIGURATION.zh-CN.md +151 -4
- 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 +95 -1
- package/vendor/extraction.json +11 -1
- package/vendor/node_modules/@zcode/tui/dist/index.js +4 -2
- package/vendor/zcode.cjs +3 -3
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,48 @@ not available on `PATH`.
|
|
|
458
460
|
|
|
459
461
|
## Configuration
|
|
460
462
|
|
|
461
|
-
ZCode reads
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
Existing files are never replaced.
|
|
463
|
+
ZCode reads MCP servers, hooks, plugins, permissions, network, storage and display
|
|
464
|
+
settings from `~/.zcode/cli/setting.json` (or
|
|
465
|
+
`%USERPROFILE%\.zcode\cli\setting.json` on Windows). Project settings use
|
|
466
|
+
`zcode.json` or `.zcode/config.json`. Existing files are never replaced.
|
|
467
|
+
|
|
468
|
+
Custom MCP servers go in the top-level `mcp.servers` object in `setting.json`.
|
|
469
|
+
See [MCP configuration](./docs/CONFIGURATION.md#mcp-servers) for HTTP/stdio examples,
|
|
470
|
+
supported fields, loading diagnostics and the MCP-specific precedence rule
|
|
471
|
+
(user definitions win over project definitions with the same server name).
|
|
472
|
+
Run `zcode doctor --json` to inspect loaded configuration paths, MCP names and
|
|
473
|
+
sources, and validation errors without starting MCP servers or sending a model
|
|
474
|
+
request. Plugin and built-in MCP servers are added separately when a session starts.
|
|
475
|
+
The `setting.json` filename is this package's adaptation of the upstream CLI's
|
|
476
|
+
`config.json`. See [upstream source and file paths](./docs/CONFIGURATION.md#upstream-source-and-file-paths)
|
|
477
|
+
for the distinction from Desktop's MCP settings.
|
|
465
478
|
|
|
466
479
|
Provider settings and the default model are stored in
|
|
467
480
|
`~/.zcode/v2/provider_config.json`, shared with ZCode Desktop by default.
|
|
468
481
|
Use `ZCODE_PERSONAL_PROVIDER_CONFIG_FILE` for an independent CLI provider file.
|
|
482
|
+
That file has its own custom providers and model overrides. To retain an
|
|
483
|
+
existing Desktop catalog, copy `~/.zcode/v2/provider_config.json` to the chosen
|
|
484
|
+
CLI provider path before the first login, with mode 600. Do not overwrite an
|
|
485
|
+
existing CLI provider file: merge its missing provider and model rules instead,
|
|
486
|
+
preserving the CLI's `defaultModelSelection`. Later Desktop catalog changes
|
|
487
|
+
must also be copied or merged into the independent file.
|
|
488
|
+
To keep CLI OAuth credentials independent of Desktop too, set
|
|
489
|
+
`ZCODE_CLI_CREDENTIALS_FILE` before both login and prompt runs:
|
|
490
|
+
|
|
491
|
+
```bash
|
|
492
|
+
export ZCODE_CLI_CREDENTIALS_FILE="$HOME/.zcode/cli/credentials.json"
|
|
493
|
+
export ZCODE_PERSONAL_PROVIDER_CONFIG_FILE="$HOME/.zcode/cli/provider_config.json"
|
|
494
|
+
zcode login --oauth --no-browser
|
|
495
|
+
zcode --prompt 'Reply with exactly: ok'
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
The browser authorization uses the registered ZCode client ID. The runtime
|
|
499
|
+
stores the login and resolves Coding Plan access using its native account
|
|
500
|
+
provider registry. The credential file remains private (mode 600). These
|
|
501
|
+
overrides leave Desktop's credentials and provider configuration untouched.
|
|
502
|
+
Client headers and a local usage row do not independently prove server-side
|
|
503
|
+
bonus accounting.
|
|
504
|
+
|
|
469
505
|
`/settings` saves the default model; `/model` changes only the current session.
|
|
470
506
|
See [`provider.example.json`](./provider.example.json) for complete field examples
|
|
471
507
|
and the [provider configuration reference](./docs/PROVIDER_CONFIG.md) for multimodal
|
|
@@ -476,7 +512,7 @@ models demonstrate explicit overrides and manual configuration.
|
|
|
476
512
|
[Provider 配置字段参考](./docs/PROVIDER_CONFIG.zh-CN.md)。
|
|
477
513
|
The project follows the current upstream runtime and configuration schema.
|
|
478
514
|
|
|
479
|
-
Three model-access paths are supported: Z.AI OAuth
|
|
515
|
+
Three model-access paths are supported: Z.AI OAuth, Z.AI/BigModel
|
|
480
516
|
Coding Plan API key, or a direct API key with a custom provider. For detailed
|
|
481
517
|
setup steps, retries/timeouts, theme, and turn-completion notifications, see
|
|
482
518
|
[Configuration](./docs/CONFIGURATION.md).
|
package/bin/zcode.js
CHANGED
|
@@ -115,6 +115,9 @@ function providerConfigPath(env = process.env, platform = process.platform, fall
|
|
|
115
115
|
const path = platform === "win32" ? win32 : posix;
|
|
116
116
|
return env.ZCODE_PERSONAL_PROVIDER_CONFIG_FILE?.trim() || path.join(sharedDataBaseDir(env, platform, fallbackHome), ".zcode", "v2", "provider_config.json");
|
|
117
117
|
}
|
|
118
|
+
function credentialsPath(env = process.env) {
|
|
119
|
+
return env.ZCODE_CLI_CREDENTIALS_FILE?.trim() || join(sharedDataBaseDir(env), ".zcode", "v2", "credentials.json");
|
|
120
|
+
}
|
|
118
121
|
function legacyCliConfigPath(env = process.env) {
|
|
119
122
|
return join(dirname(cliSettingsPath(env)), "config.json");
|
|
120
123
|
}
|
|
@@ -243,7 +246,6 @@ function record$1(value) {
|
|
|
243
246
|
}
|
|
244
247
|
/** Configuration presence only; the runtime owns credential decryption and authentication. */
|
|
245
248
|
async function readConfiguredModelAccess(env = process.env) {
|
|
246
|
-
const directory = join(sharedDataBaseDir(env), ".zcode", "v2");
|
|
247
249
|
const configPath = providerConfigPath(env);
|
|
248
250
|
let value;
|
|
249
251
|
try {
|
|
@@ -263,7 +265,7 @@ async function readConfiguredModelAccess(env = process.env) {
|
|
|
263
265
|
providerId
|
|
264
266
|
};
|
|
265
267
|
if (providerId.startsWith("account:")) try {
|
|
266
|
-
const credentials = record$1(JSON.parse(await readFile(
|
|
268
|
+
const credentials = record$1(JSON.parse(await readFile(credentialsPath(env), "utf8")));
|
|
267
269
|
const identity = credentials?.[`account-provider:${providerId}:identity`];
|
|
268
270
|
const keyPrefix = `account-provider:coding-plan:${providerId}:account:`;
|
|
269
271
|
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 +665,9 @@ const supportedLoginFlags = /* @__PURE__ */ new Set([
|
|
|
663
665
|
"--oauth",
|
|
664
666
|
"--verbose"
|
|
665
667
|
]);
|
|
668
|
+
function usesNativeZaiOAuth(platform = process.platform) {
|
|
669
|
+
return platform !== "darwin";
|
|
670
|
+
}
|
|
666
671
|
function classifyZaiOAuthInvocation(args) {
|
|
667
672
|
const positionals = args.filter((argument) => !argument.startsWith("-"));
|
|
668
673
|
if (positionals.length !== 1 || positionals[0] !== "login") return null;
|
|
@@ -1670,26 +1675,32 @@ function isTuiRuntimeInvocation(args, runtimeOptionTypes = readRuntimeCliOptionT
|
|
|
1670
1675
|
const invocation = inspectRuntimeInvocation(args, runtimeOptionTypes);
|
|
1671
1676
|
return !invocation.agentInvocation && !invocation.invalid && !invocation.passthrough && (invocation.command === void 0 || invocation.command === "tui");
|
|
1672
1677
|
}
|
|
1678
|
+
function isDoctorRuntimeInvocation(args, runtimeOptionTypes = readRuntimeCliOptionTypes()) {
|
|
1679
|
+
const invocation = inspectRuntimeInvocation(args, runtimeOptionTypes);
|
|
1680
|
+
return !invocation.agentInvocation && !invocation.invalid && invocation.command === "doctor";
|
|
1681
|
+
}
|
|
1673
1682
|
function firstRunSetupEnv(setupPending, args) {
|
|
1674
1683
|
if (!setupPending || !isTuiRuntimeInvocation(args)) return void 0;
|
|
1675
1684
|
return { ZCODE_CLI_FIRST_RUN: "1" };
|
|
1676
1685
|
}
|
|
1677
|
-
function runtimeEnvironment(extra = {}) {
|
|
1686
|
+
function runtimeEnvironment(extra = {}, inspectConfiguration = false) {
|
|
1678
1687
|
const env = { ...process.env };
|
|
1679
1688
|
delete env.ZCODE_CLI_OAUTH_CALLBACK_STDIN;
|
|
1680
1689
|
delete env.ZCODE_CLI_MIGRATE_CONFIG;
|
|
1681
1690
|
const distributionVersion = readDistributionVersion();
|
|
1691
|
+
const appVersion = readJsonVersion(extractionMetadataPath, "appVersion");
|
|
1682
1692
|
const inherited = {
|
|
1683
1693
|
...env,
|
|
1684
1694
|
...extra
|
|
1685
1695
|
};
|
|
1686
1696
|
const merged = {
|
|
1687
1697
|
...inherited,
|
|
1688
|
-
ZCODE_DATA_BASE_DIR: sharedDataBaseDir(inherited),
|
|
1698
|
+
...inspectConfiguration ? {} : { ZCODE_DATA_BASE_DIR: sharedDataBaseDir(inherited) },
|
|
1689
1699
|
ZCODE_BASE_URL: resolveZCodeBaseUrl(inherited),
|
|
1690
1700
|
ZCODE_MODEL_RETRY_MAX_RETRIES: resolveModelRetryMaxRetries(inherited),
|
|
1691
1701
|
ZCODE_APP_CLI_EXECUTABLE: process.execPath,
|
|
1692
1702
|
ZCODE_APP_CLI_ENTRY: launcherPath,
|
|
1703
|
+
...appVersion ? { ZCODE_APP_VERSION: inherited.ZCODE_APP_VERSION?.trim() || appVersion } : {},
|
|
1693
1704
|
...distributionVersion ? { ZCODE_APP_CLI_VERSION: distributionVersion } : {}
|
|
1694
1705
|
};
|
|
1695
1706
|
return Object.fromEntries(Object.entries(merged).filter((entry) => typeof entry[1] === "string"));
|
|
@@ -1757,7 +1768,7 @@ async function runRuntime(node, args, extraEnv = {}) {
|
|
|
1757
1768
|
const tuiInvocation = isTuiRuntimeInvocation(args);
|
|
1758
1769
|
const child = spawn(node, [runtimePath, ...args], {
|
|
1759
1770
|
cwd: process.cwd(),
|
|
1760
|
-
env: runtimeEnvironment(extraEnv),
|
|
1771
|
+
env: runtimeEnvironment(extraEnv, isDoctorRuntimeInvocation(args)),
|
|
1761
1772
|
stdio: tuiInvocation ? [
|
|
1762
1773
|
"inherit",
|
|
1763
1774
|
"inherit",
|
|
@@ -1830,6 +1841,7 @@ async function main(args) {
|
|
|
1830
1841
|
}
|
|
1831
1842
|
let setupPending = false;
|
|
1832
1843
|
try {
|
|
1844
|
+
if (isDoctorRuntimeInvocation(args)) return await runRuntime(resolveNodeExecutable(), args);
|
|
1833
1845
|
const bootstrap = await ensureCliSettings();
|
|
1834
1846
|
await readCliSettings();
|
|
1835
1847
|
sharedDataBaseDir();
|
|
@@ -1839,6 +1851,7 @@ async function main(args) {
|
|
|
1839
1851
|
} else setupPending = await readSetupPending();
|
|
1840
1852
|
} catch (error) {
|
|
1841
1853
|
console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
1854
|
+
console.error("Run `zcode doctor --json` for configuration diagnostics.");
|
|
1842
1855
|
return 1;
|
|
1843
1856
|
}
|
|
1844
1857
|
const node = resolveNodeExecutable();
|
|
@@ -1903,6 +1916,11 @@ async function main(args) {
|
|
|
1903
1916
|
}
|
|
1904
1917
|
}
|
|
1905
1918
|
if (zaiOAuth) {
|
|
1919
|
+
if (usesNativeZaiOAuth()) {
|
|
1920
|
+
const code = await runRuntime(node, zaiOAuth.runtimeArgs);
|
|
1921
|
+
if (code === 0 && await readConfiguredModelAccess()) await clearSetupPending();
|
|
1922
|
+
return code;
|
|
1923
|
+
}
|
|
1906
1924
|
const abortController = new AbortController();
|
|
1907
1925
|
const cancel = (signal) => () => abortController.abort(signal);
|
|
1908
1926
|
const onSigint = cancel("SIGINT");
|
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 |
|
|
@@ -92,13 +93,179 @@ reported rather than replaced by old settings.
|
|
|
92
93
|
| Resume/restart | Restores the session's model and reasoning options |
|
|
93
94
|
| Language and memory | Reads Desktop `localePreference` / `memoryEnabled`; explicit CLI settings override these values |
|
|
94
95
|
| Theme, terminal layout, copy-on-select and notifications | CLI `setting.json` |
|
|
95
|
-
|
|
|
96
|
+
| MCP servers | CLI `setting.json` → `mcp.servers`; [MCP precedence](#project-settings-and-plugins) applies to project and plugin servers |
|
|
97
|
+
| Tool permissions, retries, stream timeout, hooks, plugins and other runtime settings | CLI `setting.json`, with native project/environment precedence |
|
|
96
98
|
| Update cache, diagnostic logs and migration state | Operational files beneath the CLI directory |
|
|
97
99
|
|
|
98
100
|
The CLI does not add keys to Desktop's `setting.json`. Notification and display
|
|
99
101
|
changes write only the CLI file. Shared preferences are applied while loading
|
|
100
102
|
runtime settings, not copied into CLI settings during unrelated updates.
|
|
101
103
|
|
|
104
|
+
## MCP servers
|
|
105
|
+
|
|
106
|
+
Add servers under the top-level `mcp.servers` object in
|
|
107
|
+
`~/.zcode/cli/setting.json`. The keys are server names. `mcp`, `features`,
|
|
108
|
+
`permission`, `plugins` and `hooks` are siblings in this file; the
|
|
109
|
+
`schemaVersion` / `config` wrapper belongs to `provider_config.json`.
|
|
110
|
+
|
|
111
|
+
Merge this example into your existing settings, replacing the endpoint and
|
|
112
|
+
executable with your own running HTTP server and installed stdio server:
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
{
|
|
116
|
+
"features": {
|
|
117
|
+
"mcp": true
|
|
118
|
+
},
|
|
119
|
+
"mcp": {
|
|
120
|
+
"servers": {
|
|
121
|
+
"basic-memory": {
|
|
122
|
+
"type": "http",
|
|
123
|
+
"url": "http://127.0.0.1:18796/mcp"
|
|
124
|
+
},
|
|
125
|
+
"token-savior": {
|
|
126
|
+
"type": "stdio",
|
|
127
|
+
"command": "/absolute/path/to/token-savior-mcp",
|
|
128
|
+
"args": [],
|
|
129
|
+
"timeoutMs": 30000
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The runtime reads this file on startup. Restart ZCode after changing MCP
|
|
137
|
+
settings. The `settings-v1.json` marker only controls migration from the old
|
|
138
|
+
CLI `config.json`; it does not prevent later edits to `setting.json` from loading.
|
|
139
|
+
Changing the model/provider file or completing provider login does not configure
|
|
140
|
+
custom MCP servers.
|
|
141
|
+
|
|
142
|
+
### Server fields
|
|
143
|
+
|
|
144
|
+
| Field | Applies to | Meaning |
|
|
145
|
+
| --- | --- | --- |
|
|
146
|
+
| `type` | All | `"stdio"`, `"http"` or `"sse"`; use the transport supported by your server |
|
|
147
|
+
| `command` | stdio | Executable name or absolute path; put command arguments in `args` |
|
|
148
|
+
| `args` | stdio | Optional array of strings |
|
|
149
|
+
| `env` | stdio | Optional object of environment variable names to string values |
|
|
150
|
+
| `cwd` | stdio | Optional working directory for the server process |
|
|
151
|
+
| `url` | HTTP / SSE | Server endpoint, including its MCP or SSE path |
|
|
152
|
+
| `headers` | HTTP / SSE | Optional object of header names to string values, such as `Authorization` |
|
|
153
|
+
| `oauth` | HTTP / SSE | Optional OAuth configuration; see below |
|
|
154
|
+
| `enabled` | All | Set to `false` to disable a server while keeping its configuration |
|
|
155
|
+
| `timeoutMs` | All | Optional positive number in milliseconds; use this field instead of `timeout` or `startup_timeout_sec` |
|
|
156
|
+
| `protocolVersion` | All | Optional `"auto"`, `"legacy"` or `"2026-07-28"` in runtime 0.16.9; normally leave unset for automatic negotiation |
|
|
157
|
+
|
|
158
|
+
For OAuth, `oauth.type` accepts `"authorization_code"` or `"client_credentials"`.
|
|
159
|
+
Both accept `clientId`, `clientSecret`, `clientName` and `scope`; client credentials
|
|
160
|
+
requires `clientId` and `clientSecret`, while authorization code also accepts
|
|
161
|
+
`redirectPath`. Configure these only when required by the MCP server.
|
|
162
|
+
|
|
163
|
+
### Project settings and plugins
|
|
164
|
+
|
|
165
|
+
Project `zcode.json` or `.zcode/config.json` files use the same `mcp.servers`
|
|
166
|
+
structure. In a Git worktree, the runtime discovers those files from the worktree
|
|
167
|
+
root through the working directory; outside a worktree, it checks the working
|
|
168
|
+
directory. For project stdio servers, relative `cwd` values resolve against the
|
|
169
|
+
project configuration's base directory (the parent of `.zcode` for
|
|
170
|
+
`.zcode/config.json`); an omitted `cwd` uses that directory.
|
|
171
|
+
|
|
172
|
+
MCP servers merge by name. **User settings take precedence over project settings
|
|
173
|
+
for the same server name** in the current runtime; distinct names from both
|
|
174
|
+
sources remain available. This is an exception to the usual project-override
|
|
175
|
+
rule for other settings. An empty user `mcp.servers` object does not disable
|
|
176
|
+
project or plugin servers. Use `enabled: false` on a named server, or
|
|
177
|
+
`features.mcp: false` to disable MCP as a whole.
|
|
178
|
+
|
|
179
|
+
Enabled plugins also contribute servers. Their definitions come from the
|
|
180
|
+
plugin's `.mcp.json` or manifest, and normally appear as
|
|
181
|
+
`plugin:<plugin-name>:<server-name>`. Keep standalone user MCP definitions in
|
|
182
|
+
`setting.json`; this CLI does not automatically read `.agents/mcp.json`.
|
|
183
|
+
Plugin controls remain under `plugins`, hook declarations under
|
|
184
|
+
`hooks.events.<Event>`, and tool permissions under `permission` in `setting.json`.
|
|
185
|
+
|
|
186
|
+
### Upstream source and file paths
|
|
187
|
+
|
|
188
|
+
These paths distinguish the packaged CLI from the upstream application. The
|
|
189
|
+
source references below are pinned to upstream
|
|
190
|
+
[`29628c9` / `v3.14.3`](https://github.com/zai-org/ZCode/tree/29628c9acdb81b703bbd4080c207a0e7ce5e276e).
|
|
191
|
+
This package's runtime lock selects the separate Desktop 3.14.4 artifact; the
|
|
192
|
+
public source snapshot is not an assertion of that artifact's build commit.
|
|
193
|
+
|
|
194
|
+
| Client / source | User MCP file | JSON path |
|
|
195
|
+
| --- | --- | --- |
|
|
196
|
+
| Unpatched upstream CLI | `~/.zcode/cli/config.json` | `mcp.servers` |
|
|
197
|
+
| This package, `zcode-app-cli` | `~/.zcode/cli/setting.json` | `mcp.servers` |
|
|
198
|
+
| Upstream Desktop's ZCode directory source | `~/.zcode/cli/config.json` | `mcp.servers` |
|
|
199
|
+
| Upstream Desktop's `.agents` fallback | `~/.agents/mcp.json` | `mcpServers` |
|
|
200
|
+
|
|
201
|
+
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)
|
|
202
|
+
defaults to `config.json`. This package's
|
|
203
|
+
[`patchRuntimeSharedConfig`](https://github.com/kingsword09/zcode-cli/blob/e93caf41292314bd751180cf9b08f6d18895a5b5/scripts/sync-runtime.ts#L1026-L1046)
|
|
204
|
+
changes that filename to `setting.json`. The
|
|
205
|
+
[general-settings schema](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/apps/zcode-cli/packages/adapters/src/config/schema.ts#L286-L306)
|
|
206
|
+
contains `mcp`, `plugins`, `permission` and `hooks`. The separate, strict
|
|
207
|
+
[provider-file schema](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/packages/provider-node/src/provider-config-file-codec.ts#L18-L30)
|
|
208
|
+
accepts provider/model rules, provider order and default model selection; adding
|
|
209
|
+
MCP there fails its schema validation. The
|
|
210
|
+
[MCP merge function](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/apps/zcode-cli/packages/adapters/src/config/config-factory.ts#L372-L397)
|
|
211
|
+
explicitly applies user definitions after project definitions.
|
|
212
|
+
|
|
213
|
+
Desktop has a separate
|
|
214
|
+
[MCP directory reader and writer](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/packages/desktop/src/main/mcpUserDirectory/index.ts#L37-L69).
|
|
215
|
+
For each user/project scope, it
|
|
216
|
+
[falls back to `.agents/mcp.json`](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/packages/desktop/src/main/mcpUserDirectory/index.ts#L334-L375)
|
|
217
|
+
when that scope's ZCode file has no MCP entries. Project files are
|
|
218
|
+
`.zcode/config.json` and `.agents/mcp.json`, respectively. Sharing
|
|
219
|
+
`provider_config.json` with Desktop does not synchronize these user MCP files
|
|
220
|
+
with this package's `setting.json`; the old CLI file is only imported during the
|
|
221
|
+
one-time migration described above.
|
|
222
|
+
|
|
223
|
+
### Checking whether settings loaded
|
|
224
|
+
|
|
225
|
+
Run `zcode doctor` to inspect configuration paths, loading status, validated MCP
|
|
226
|
+
server names and their user/project sources. For a report suitable for debugging:
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
zcode doctor --json
|
|
230
|
+
zcode --cwd /path/to/project doctor --json
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
The JSON output keeps the existing runtime metadata and adds `configuration`:
|
|
234
|
+
`user.path` / `user.status`, `project.paths` / `project.status`, `mcp.enabled`,
|
|
235
|
+
`mcp.servers` and `diagnostics`. Status is `loaded`, `missing` or `invalid`.
|
|
236
|
+
Diagnostics identify the file and rejected field. Server records include only
|
|
237
|
+
name, transport, enabled state and source; command arguments, URLs, environment
|
|
238
|
+
variables, headers and credentials are omitted. `provider.path` identifies the
|
|
239
|
+
provider file; this check does not validate provider credentials.
|
|
240
|
+
|
|
241
|
+
Doctor works without login and even when `setting.json` contains invalid JSON.
|
|
242
|
+
It skips first-run settings creation and provider migration, and reports the old
|
|
243
|
+
`config.json` as a migration source only. It does not start MCP servers or send
|
|
244
|
+
model requests. A missing settings file is allowed; rejected settings or skipped
|
|
245
|
+
MCP entries produce exit code `1`. Valid configuration produces exit code `0`.
|
|
246
|
+
|
|
247
|
+
The server list covers user/project configuration. Plugin and built-in MCP
|
|
248
|
+
servers are added separately at session startup, and this check does not test
|
|
249
|
+
connectivity. Use `/status` in the TUI to inspect connected MCP servers. The
|
|
250
|
+
default structured runtime logs are under `~/.zcode/cli/log/`. When a server is
|
|
251
|
+
missing, these events provide the session's loading and connection evidence:
|
|
252
|
+
|
|
253
|
+
| Event | What to check |
|
|
254
|
+
| --- | --- |
|
|
255
|
+
| `bootstrap.app.startup.config.completed` | `context.configSourceUser` indicates whether the user settings file loaded |
|
|
256
|
+
| `config.file.invalid` | `context.configPath` and `context.diagnosticMessage` identify a file-level parsing or schema error |
|
|
257
|
+
| `config.mcp_server.skipped` | `context.diagnosticPath` and `context.diagnosticMessage` identify an invalid server entry |
|
|
258
|
+
| `mcp.configured_servers.connect.started` | `context.serverNames` lists the servers selected for connection |
|
|
259
|
+
| `mcp.configured_servers.connect.completed` | Connection status and tool counts distinguish loading from connection failures |
|
|
260
|
+
|
|
261
|
+
Valid JSON must also satisfy the runtime schema. A schema error outside an
|
|
262
|
+
individual MCP server entry can cause the entire settings file to be ignored.
|
|
263
|
+
For example, `ui.theme: "system"` is invalid; supported values are `"auto"`,
|
|
264
|
+
`"dark"` and `"light"`. In that case the runtime can still start with default
|
|
265
|
+
settings and plugin servers. `features.mcp` defaults to `true`, so seeing MCP
|
|
266
|
+
enabled does not prove the user file loaded. A malformed individual server entry
|
|
267
|
+
is skipped with `config.mcp_server.skipped`; valid entries can still load.
|
|
268
|
+
|
|
102
269
|
## Model catalogs and default selection
|
|
103
270
|
|
|
104
271
|
The native registry loads the bundled catalog and manages upstream catalog
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
[English](CONFIGURATION.md) | 简体中文
|
|
4
4
|
|
|
5
|
-
CLI 跟随当前 ZCode runtime 的 provider registry schema
|
|
6
|
-
|
|
5
|
+
CLI 跟随当前 ZCode runtime 的 provider registry schema。Provider 和模型设置存放在
|
|
6
|
+
`provider_config.json`;MCP、hooks、插件、权限等通用运行设置存放在 CLI 的 `setting.json`。
|
|
7
|
+
模型配置中的“智能配置”对应英文界面的 **Smart configuration**。
|
|
7
8
|
|
|
8
9
|
## 配置文件
|
|
9
10
|
|
|
10
11
|
| 文件 | 用途 |
|
|
11
12
|
| --- | --- |
|
|
12
|
-
| `~/.zcode/cli/setting.json` | CLI
|
|
13
|
+
| `~/.zcode/cli/setting.json` | MCP、hooks、插件、权限、网络、存储和 CLI 显示设置 |
|
|
13
14
|
| `~/.zcode/v2/setting.json` | 桌面端已有的语言和记忆偏好,CLI 只读不修改 |
|
|
14
15
|
| `~/.zcode/v2/provider_config.json` | Provider、模型元数据覆盖和默认模型 |
|
|
15
16
|
| `~/.zcode/v2/credentials.json` | 原生 runtime 持久化的凭证 |
|
|
@@ -78,12 +79,158 @@ CLI 专属字段迁移到 `~/.zcode/cli/setting.json`,省略 provider、main/l
|
|
|
78
79
|
| 恢复会话/重启 | 恢复该会话保存的模型和推理选项 |
|
|
79
80
|
| 语言与记忆 | 读取桌面端 `localePreference`/`memoryEnabled`,显式 CLI 设置优先 |
|
|
80
81
|
| 主题、终端布局、选中复制、通知 | CLI `setting.json` |
|
|
81
|
-
|
|
|
82
|
+
| MCP 服务器 | CLI `setting.json` → `mcp.servers`;项目与插件服务器的合并规则见 [项目配置与插件](#项目配置与插件) |
|
|
83
|
+
| 工具权限、重试、流超时、hooks、插件等运行设置 | CLI `setting.json`,保留原生项目和环境配置优先级 |
|
|
82
84
|
| 更新缓存、诊断日志、迁移状态 | CLI 目录下的运行文件 |
|
|
83
85
|
|
|
84
86
|
CLI 不向桌面端的 `setting.json` 增加字段。通知和显示设置只写 CLI 文件。
|
|
85
87
|
共享偏好在加载 runtime 设置时生效,不会因修改其他 CLI 选项而被复制进 CLI 设置。
|
|
86
88
|
|
|
89
|
+
## MCP 服务器
|
|
90
|
+
|
|
91
|
+
在 `~/.zcode/cli/setting.json` 的顶层 `mcp.servers` 对象中添加服务器,键名就是服务器名。
|
|
92
|
+
`mcp` 与 `features`、`permission`、`plugins`、`hooks` 同级;
|
|
93
|
+
`schemaVersion` / `config` 外层结构属于 `provider_config.json`。
|
|
94
|
+
|
|
95
|
+
将以下内容合并到已有设置中,并把地址和可执行文件路径替换为你实际运行的 HTTP 服务
|
|
96
|
+
及已安装的 stdio 服务:
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
{
|
|
100
|
+
"features": {
|
|
101
|
+
"mcp": true
|
|
102
|
+
},
|
|
103
|
+
"mcp": {
|
|
104
|
+
"servers": {
|
|
105
|
+
"basic-memory": {
|
|
106
|
+
"type": "http",
|
|
107
|
+
"url": "http://127.0.0.1:18796/mcp"
|
|
108
|
+
},
|
|
109
|
+
"token-savior": {
|
|
110
|
+
"type": "stdio",
|
|
111
|
+
"command": "/absolute/path/to/token-savior-mcp",
|
|
112
|
+
"args": [],
|
|
113
|
+
"timeoutMs": 30000
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Runtime 每次启动都会读取此文件,修改 MCP 设置后重启 ZCode 即可。
|
|
121
|
+
`settings-v1.json` 标记只控制从旧 CLI `config.json` 的迁移,不会阻止后续修改
|
|
122
|
+
`setting.json` 生效。修改模型/provider 文件或完成 provider 登录,不会配置自定义 MCP。
|
|
123
|
+
|
|
124
|
+
### 服务器字段
|
|
125
|
+
|
|
126
|
+
| 字段 | 适用类型 | 含义 |
|
|
127
|
+
| --- | --- | --- |
|
|
128
|
+
| `type` | 全部 | `"stdio"`、`"http"` 或 `"sse"`,按服务器支持的传输方式选择 |
|
|
129
|
+
| `command` | stdio | 可执行文件名或绝对路径;命令参数单独放在 `args` 中 |
|
|
130
|
+
| `args` | stdio | 可选,字符串数组 |
|
|
131
|
+
| `env` | stdio | 可选,环境变量名到字符串值的对象 |
|
|
132
|
+
| `cwd` | stdio | 可选,服务器进程的工作目录 |
|
|
133
|
+
| `url` | HTTP / SSE | 服务器地址,包含实际的 MCP 或 SSE 路径 |
|
|
134
|
+
| `headers` | HTTP / SSE | 可选,请求头名称到字符串值的对象,例如 `Authorization` |
|
|
135
|
+
| `oauth` | HTTP / SSE | 可选,OAuth 配置,见下文 |
|
|
136
|
+
| `enabled` | 全部 | 设为 `false` 可禁用服务器并保留配置 |
|
|
137
|
+
| `timeoutMs` | 全部 | 可选,正数,单位为毫秒;超时应使用此字段,`timeout` 和 `startup_timeout_sec` 不生效 |
|
|
138
|
+
| `protocolVersion` | 全部 | Runtime 0.16.9 支持可选值 `"auto"`、`"legacy"`、`"2026-07-28"`;通常省略,使用自动协商 |
|
|
139
|
+
|
|
140
|
+
`oauth.type` 支持 `"authorization_code"` 和 `"client_credentials"`。
|
|
141
|
+
两者都支持 `clientId`、`clientSecret`、`clientName`、`scope`;client credentials 模式
|
|
142
|
+
必须填写 `clientId` 和 `clientSecret`,authorization code 模式还支持 `redirectPath`。
|
|
143
|
+
按 MCP 服务器的鉴权要求配置即可。
|
|
144
|
+
|
|
145
|
+
### 项目配置与插件
|
|
146
|
+
|
|
147
|
+
项目的 `zcode.json` 或 `.zcode/config.json` 使用相同的 `mcp.servers` 结构。
|
|
148
|
+
在 Git 工作树内,runtime 从工作树根目录到当前工作目录发现这些文件;工作树外只检查
|
|
149
|
+
当前工作目录。项目 stdio 服务器的相对 `cwd` 以配置的基础目录解析:
|
|
150
|
+
对 `.zcode/config.json`,基础目录是 `.zcode` 的父目录;省略 `cwd` 时也使用该基础目录。
|
|
151
|
+
|
|
152
|
+
MCP 服务器按名称合并。当前 runtime 中,**同名服务器的用户配置优先于项目配置**;
|
|
153
|
+
不同名称的服务器都会保留。这与其他设置通常由项目覆盖用户配置的规则不同。
|
|
154
|
+
用户配置中的空 `mcp.servers` 对象不会禁用项目或插件服务器。
|
|
155
|
+
可对指定服务器设置 `enabled: false`,或用 `features.mcp: false` 关闭整个 MCP 功能。
|
|
156
|
+
|
|
157
|
+
已启用的插件也会提供 MCP,定义来自插件的 `.mcp.json` 或 manifest,通常显示为
|
|
158
|
+
`plugin:<插件名>:<服务器名>`。独立的用户 MCP 定义放在 `setting.json`;
|
|
159
|
+
此 CLI 不会自动读取 `.agents/mcp.json`。
|
|
160
|
+
插件控制仍在 `setting.json` 的 `plugins` 下,hook 声明在 `hooks.events.<Event>` 下,
|
|
161
|
+
工具权限在 `permission` 下。
|
|
162
|
+
|
|
163
|
+
### 上游源码与配置路径的区别
|
|
164
|
+
|
|
165
|
+
下面区分本发行包与上游应用。源码引用固定在上游
|
|
166
|
+
[`29628c9` / `v3.14.3`](https://github.com/zai-org/ZCode/tree/29628c9acdb81b703bbd4080c207a0e7ce5e276e)。
|
|
167
|
+
本项目 runtime lock 选择的是独立发布的 Desktop 3.14.4 产物,不能据此认定该产物
|
|
168
|
+
由这个公开源码提交构建。
|
|
169
|
+
|
|
170
|
+
| 客户端/配置源 | 用户级 MCP 文件 | JSON 路径 |
|
|
171
|
+
| --- | --- | --- |
|
|
172
|
+
| 未打补丁的上游 CLI | `~/.zcode/cli/config.json` | `mcp.servers` |
|
|
173
|
+
| 本项目 `zcode-app-cli` | `~/.zcode/cli/setting.json` | `mcp.servers` |
|
|
174
|
+
| 上游 Desktop 的 ZCode 目录配置源 | `~/.zcode/cli/config.json` | `mcp.servers` |
|
|
175
|
+
| 上游 Desktop 的 `.agents` 回退配置源 | `~/.agents/mcp.json` | `mcpServers` |
|
|
176
|
+
|
|
177
|
+
上游 [文件加载器](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/apps/zcode-cli/packages/adapters/src/config/file-config.adapter.ts#L61-L118)
|
|
178
|
+
默认使用 `config.json`。本项目的
|
|
179
|
+
[`patchRuntimeSharedConfig`](https://github.com/kingsword09/zcode-cli/blob/e93caf41292314bd751180cf9b08f6d18895a5b5/scripts/sync-runtime.ts#L1026-L1046)
|
|
180
|
+
将文件名改成 `setting.json`。
|
|
181
|
+
[通用设置 schema](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/apps/zcode-cli/packages/adapters/src/config/schema.ts#L286-L306)
|
|
182
|
+
包含 `mcp`、`plugins`、`permission` 和 `hooks`;独立且严格的
|
|
183
|
+
[provider 文件 schema](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/packages/provider-node/src/provider-config-file-codec.ts#L18-L30)
|
|
184
|
+
只接受 provider/模型规则、provider 排序和默认模型选择,向其中添加 MCP 会导致 schema
|
|
185
|
+
校验失败。[MCP 合并函数](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/apps/zcode-cli/packages/adapters/src/config/config-factory.ts#L372-L397)
|
|
186
|
+
明确先应用项目配置,再应用用户配置。
|
|
187
|
+
|
|
188
|
+
Desktop 有独立的
|
|
189
|
+
[MCP 目录读写模块](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/packages/desktop/src/main/mcpUserDirectory/index.ts#L37-L69)。
|
|
190
|
+
在每个用户/项目作用域内,ZCode 文件没有 MCP 条目时,它会
|
|
191
|
+
[回退到 `.agents/mcp.json`](https://github.com/zai-org/ZCode/blob/29628c9acdb81b703bbd4080c207a0e7ce5e276e/packages/desktop/src/main/mcpUserDirectory/index.ts#L334-L375)。
|
|
192
|
+
项目级文件分别是 `.zcode/config.json` 和 `.agents/mcp.json`。
|
|
193
|
+
与 Desktop 共用 `provider_config.json` 不代表这些用户 MCP 文件会与本项目的
|
|
194
|
+
`setting.json` 同步;旧 CLI 文件只在前述一次性迁移时导入。
|
|
195
|
+
|
|
196
|
+
### 确认配置是否加载
|
|
197
|
+
|
|
198
|
+
运行 `zcode doctor` 查看实际配置路径、加载状态、校验通过的 MCP 名称及用户/项目来源。
|
|
199
|
+
需要排查问题时可生成 JSON 报告:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
zcode doctor --json
|
|
203
|
+
zcode --cwd /path/to/project doctor --json
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
JSON 保留原有 runtime 信息,新增 `configuration`:包含 `user.path` / `user.status`、
|
|
207
|
+
`project.paths` / `project.status`、`mcp.enabled`、`mcp.servers` 和 `diagnostics`。
|
|
208
|
+
状态为 `loaded`、`missing` 或 `invalid`;诊断指出对应文件与被拒绝的字段。
|
|
209
|
+
服务器记录只包含名称、传输方式、启用状态和来源,不输出命令参数、URL、环境变量、
|
|
210
|
+
请求头或凭据。`provider.path` 只标明 provider 文件位置,不验证 provider 凭据。
|
|
211
|
+
|
|
212
|
+
Doctor 无需登录,即使 `setting.json` 的 JSON 语法损坏也能运行。它跳过首次设置文件创建
|
|
213
|
+
和 provider 迁移,并将旧 `config.json` 标为仅供迁移使用。它不会启动 MCP 或请求模型。
|
|
214
|
+
设置文件缺失是允许的;配置无效或有 MCP 条目被跳过时退出码为 `1`,有效配置为 `0`。
|
|
215
|
+
|
|
216
|
+
服务器列表覆盖用户/项目配置。插件和内置 MCP 会在会话启动时另外加入,doctor 不测试
|
|
217
|
+
连接是否成功。在 TUI 中使用 `/status` 查看连接状态。结构化 runtime 日志默认位于
|
|
218
|
+
`~/.zcode/cli/log/`;服务器缺失时,以下事件可提供实际会话的加载和连接证据:
|
|
219
|
+
|
|
220
|
+
| 事件 | 检查内容 |
|
|
221
|
+
| --- | --- |
|
|
222
|
+
| `bootstrap.app.startup.config.completed` | `context.configSourceUser` 表示是否成功加载用户设置文件 |
|
|
223
|
+
| `config.file.invalid` | `context.configPath` 和 `context.diagnosticMessage` 指出文件解析或 schema 校验错误 |
|
|
224
|
+
| `config.mcp_server.skipped` | `context.diagnosticPath` 和 `context.diagnosticMessage` 指出无效的服务器配置项 |
|
|
225
|
+
| `mcp.configured_servers.connect.started` | `context.serverNames` 列出准备连接的服务器 |
|
|
226
|
+
| `mcp.configured_servers.connect.completed` | 连接状态和工具数量,可区分配置加载问题与连接失败 |
|
|
227
|
+
|
|
228
|
+
JSON 语法正确还不够,字段也必须符合 runtime 的 schema。单个 MCP 服务器条目以外的
|
|
229
|
+
schema 错误可能导致整份设置文件被忽略。例如 `ui.theme: "system"` 无效,正确值是
|
|
230
|
+
`"auto"`、`"dark"` 或 `"light"`。此时 runtime 仍可能使用默认设置及插件服务器启动。
|
|
231
|
+
`features.mcp` 默认就是 `true`,因此 MCP 开关已开启不能证明用户文件加载成功。
|
|
232
|
+
单个服务器条目无效时,会记录 `config.mcp_server.skipped` 并跳过该条目,其他有效条目仍可加载。
|
|
233
|
+
|
|
87
234
|
## 模型目录与默认选择
|
|
88
235
|
|
|
89
236
|
原生 registry 加载随包提供的目录,并管理上游目录刷新。`/model`、模型循环切换以及
|
package/docs/PROVIDER_CONFIG.md
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
English | [简体中文](PROVIDER_CONFIG.zh-CN.md)
|
|
4
4
|
|
|
5
5
|
ZCode Desktop and CLI share `~/.zcode/v2/provider_config.json` (underscore).
|
|
6
|
-
`ZCODE_PERSONAL_PROVIDER_CONFIG_FILE` can select another file.
|
|
7
|
-
|
|
6
|
+
`ZCODE_PERSONAL_PROVIDER_CONFIG_FILE` can select another file. MCP servers, hooks,
|
|
7
|
+
plugins, permissions, terminal and network settings belong in
|
|
8
|
+
`~/.zcode/cli/setting.json`. See [MCP servers](CONFIGURATION.md#mcp-servers)
|
|
9
|
+
for the `mcp.servers` structure and HTTP/stdio examples.
|
|
8
10
|
|
|
9
11
|
[`provider.example.json`](../provider.example.json) covers the current personal
|
|
10
12
|
provider schema. It is valid JSON without comments. This reference explains the
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
[English](PROVIDER_CONFIG.md) | 简体中文
|
|
4
4
|
|
|
5
5
|
ZCode 桌面端与 CLI 共用 `~/.zcode/v2/provider_config.json`,文件名使用下划线。
|
|
6
|
-
可通过 `ZCODE_PERSONAL_PROVIDER_CONFIG_FILE`
|
|
7
|
-
CLI 设置放在 `~/.zcode/cli/setting.json`。
|
|
6
|
+
可通过 `ZCODE_PERSONAL_PROVIDER_CONFIG_FILE` 指定其他文件。MCP、hooks、插件、权限、
|
|
7
|
+
终端显示和网络等 CLI 设置放在 `~/.zcode/cli/setting.json`。
|
|
8
|
+
`mcp.servers` 的结构及 HTTP/stdio 示例见 [MCP 服务器配置](CONFIGURATION.zh-CN.md#mcp-服务器)。
|
|
8
9
|
|
|
9
10
|
[`provider.example.json`](../provider.example.json) 展示当前个人 provider schema 的配置项。
|
|
10
11
|
它是可以解析的标准 JSON,不包含注释;各字段的含义、可选值及互斥关系由本文说明。
|