zcode-agent 1.3.1 → 1.4.0
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 +135 -90
- package/bin/zcode-agent.js +62 -28
- package/lib/acp-map.js +22 -18
- package/lib/acp.js +84 -32
- package/lib/appserver.js +26 -17
- package/lib/bootstrap.js +1 -1
- package/lib/brief.js +2 -2
- package/lib/checks.js +23 -5
- package/lib/commands/acp.js +8 -0
- package/lib/commands/cost.js +9 -4
- package/lib/commands/doctor.js +18 -5
- package/lib/commands/exec.js +29 -9
- package/lib/commands/mcp-list.js +49 -4
- package/lib/commands/plan.js +22 -3
- package/lib/commands/sessions.js +27 -6
- package/lib/contract.js +30 -6
- package/lib/cost.js +22 -23
- package/lib/engine.js +0 -3
- package/lib/executor.js +70 -20
- package/lib/help.js +13 -11
- package/lib/isolation.js +73 -29
- package/lib/key.js +1 -5
- package/lib/models.js +93 -22
- package/lib/plan.js +14 -6
- package/lib/ports.js +1 -1
- package/lib/procs.js +35 -0
- package/lib/store.js +0 -1
- package/lib/taskspec.js +1 -1
- package/lib/ui.js +8 -3
- package/lib/verify.js +7 -3
- package/lib/workspace.js +34 -7
- package/package.json +4 -2
- package/skills/claude-code/zcode-agent/SKILL.md +13 -12
- package/skills/codex/zcode-agent/SKILL.md +13 -12
package/lib/isolation.js
CHANGED
|
@@ -20,7 +20,7 @@ const fs = require('node:fs');
|
|
|
20
20
|
const path = require('node:path');
|
|
21
21
|
const os = require('node:os');
|
|
22
22
|
const crypto = require('node:crypto');
|
|
23
|
-
const { DEFAULT_MODEL } = require('./models.js');
|
|
23
|
+
const { DEFAULT_MODEL, addedModelRegistration } = require('./models.js');
|
|
24
24
|
|
|
25
25
|
// The desktop app's live directory. ZAI_CODE_LIVE_DIR points elsewhere
|
|
26
26
|
// (e.g. a second desktop profile, or a fixture in tests).
|
|
@@ -29,7 +29,6 @@ function liveDir(env = process.env) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const LIVE_ZCODE = liveDir({});
|
|
32
|
-
const LIVE_V2 = path.join(LIVE_ZCODE, 'v2');
|
|
33
32
|
|
|
34
33
|
// v2 top-level entries we deliberately never copy.
|
|
35
34
|
const V2_EXCLUDE_FILES = new Set(['credentials.json', '.DS_Store']);
|
|
@@ -79,7 +78,7 @@ function listDir(dir) {
|
|
|
79
78
|
// has no zai-api rule or can't be read: the ZCode app keeps an empty
|
|
80
79
|
// provider_config.json (providerRules: []) when signed in with a coding
|
|
81
80
|
// plan, and recreates it if deleted (1.3.1, issue #2).
|
|
82
|
-
function rewriteProviderConfig(target, key) {
|
|
81
|
+
function rewriteProviderConfig(target, key, builtinConfig) {
|
|
83
82
|
const parsed = readJson(target);
|
|
84
83
|
const rules =
|
|
85
84
|
parsed &&
|
|
@@ -92,16 +91,36 @@ function rewriteProviderConfig(target, key) {
|
|
|
92
91
|
rule.config.group = rule.config.group || 'standard-personal';
|
|
93
92
|
rule.config.access = { type: 'api-key', apiKey: key };
|
|
94
93
|
parsed.config.providerConfigRules.providerRules = [rule];
|
|
94
|
+
registerAddedModels(parsed.config, builtinConfig);
|
|
95
95
|
writeJson600(target, parsed);
|
|
96
96
|
return true;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
// Registers the models the engine's builtin config does not list yet
|
|
100
|
+
// (models.js ADDED_MODELS: GLM-5.4) on the zai-api rule of a personal
|
|
101
|
+
// provider config. The app's own rules for other providers and models are
|
|
102
|
+
// kept; one for the same zai-api model is replaced, since the engine refuses
|
|
103
|
+
// a model declared twice.
|
|
104
|
+
function registerAddedModels(config, builtinConfig) {
|
|
105
|
+
const { ids, rules } = addedModelRegistration(builtinConfig);
|
|
106
|
+
if (!ids.length) return config;
|
|
107
|
+
const rule = config.providerConfigRules.providerRules.find((r) => r.providerId === 'zai-api');
|
|
108
|
+
rule.config.personalModelIds = [...new Set([...(rule.config.personalModelIds || []), ...ids])];
|
|
109
|
+
const mcr = config.modelConfigRules || {};
|
|
110
|
+
const keep = (list) => (Array.isArray(list) ? list : []).filter((r) => !(r && r.providerId === 'zai-api' && ids.includes(r.modelId)));
|
|
111
|
+
config.modelConfigRules = {
|
|
112
|
+
providerModelRules: [...keep(mcr.providerModelRules), ...rules],
|
|
113
|
+
manualProviderModelRules: keep(mcr.manualProviderModelRules),
|
|
114
|
+
};
|
|
115
|
+
return config;
|
|
116
|
+
}
|
|
117
|
+
|
|
99
118
|
// Standalone (no app config to copy). modelConfigRules must be present,
|
|
100
119
|
// even empty: without it the engine registers no zai-api models and
|
|
101
120
|
// session/create fails with "Provider Registry 中不存在 Model:
|
|
102
121
|
// zai-api/GLM-5.3-Flash" (1.0, live-probed).
|
|
103
|
-
function synthesizedProviderConfig(key) {
|
|
104
|
-
|
|
122
|
+
function synthesizedProviderConfig(key, builtinConfig) {
|
|
123
|
+
const parsed = {
|
|
105
124
|
schemaVersion: 1,
|
|
106
125
|
config: {
|
|
107
126
|
modelConfigRules: { providerModelRules: [], manualProviderModelRules: [] },
|
|
@@ -119,6 +138,8 @@ function synthesizedProviderConfig(key) {
|
|
|
119
138
|
},
|
|
120
139
|
},
|
|
121
140
|
};
|
|
141
|
+
registerAddedModels(parsed.config, builtinConfig);
|
|
142
|
+
return parsed;
|
|
122
143
|
}
|
|
123
144
|
|
|
124
145
|
// --- skills -------------------------------------------------------------------
|
|
@@ -258,7 +279,8 @@ function unhealthyMcp(servers, health, now = Date.now()) {
|
|
|
258
279
|
// statuses: the engine's mcp/list status map; inherited: {name: def} of the
|
|
259
280
|
// inherited servers this session registered. Failed ones are recorded,
|
|
260
281
|
// connected ones cleared. Never throws.
|
|
261
|
-
|
|
282
|
+
// `scrub` removes the API key from the stored error text.
|
|
283
|
+
function recordMcpHealth(root, statuses, inherited, { now = Date.now(), scrub = (s) => s } = {}) {
|
|
262
284
|
if (!root || !statuses) return;
|
|
263
285
|
try {
|
|
264
286
|
const health = readMcpHealth(root);
|
|
@@ -273,7 +295,7 @@ function recordMcpHealth(root, statuses, inherited, now = Date.now()) {
|
|
|
273
295
|
sig,
|
|
274
296
|
failedAt: now,
|
|
275
297
|
failures: ((prev && prev.failures) || (prev ? 1 : 0)) + 1,
|
|
276
|
-
error: error ? String(typeof error === 'string' ? error : JSON.stringify(error)).slice(0, 200) : null,
|
|
298
|
+
error: error ? scrub(String(typeof error === 'string' ? error : JSON.stringify(error))).slice(0, 200) : null,
|
|
277
299
|
};
|
|
278
300
|
changed = true;
|
|
279
301
|
} else if (state === 'connected' && health[name]) {
|
|
@@ -284,7 +306,7 @@ function recordMcpHealth(root, statuses, inherited, now = Date.now()) {
|
|
|
284
306
|
if (!changed) return;
|
|
285
307
|
const file = mcpHealthFile(root);
|
|
286
308
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
287
|
-
fs.writeFileSync(tmp, JSON.stringify(health, null, 2) + '\n');
|
|
309
|
+
fs.writeFileSync(tmp, JSON.stringify(health, null, 2) + '\n', { mode: 0o600 });
|
|
288
310
|
fs.renameSync(tmp, file);
|
|
289
311
|
} catch {
|
|
290
312
|
/* health is an optimisation; a failed write just retries the server */
|
|
@@ -429,10 +451,9 @@ function skillsSnapshot(entries, root) {
|
|
|
429
451
|
fs.mkdirSync(base, { recursive: true, mode: 0o700 });
|
|
430
452
|
const tmp = path.join(base, `.tmp-${process.pid}-${crypto.randomBytes(3).toString('hex')}`);
|
|
431
453
|
try {
|
|
432
|
-
for (const { name, from } of entries) {
|
|
433
|
-
fs.cpSync(from, path.join(tmp, name), { recursive: true, dereference: true });
|
|
434
|
-
}
|
|
435
454
|
fs.mkdirSync(tmp, { recursive: true });
|
|
455
|
+
// A skill that cannot be copied is left out (callers see it missing).
|
|
456
|
+
for (const { name, from } of entries) copySkill(from, path.join(tmp, name));
|
|
436
457
|
fs.renameSync(tmp, dir);
|
|
437
458
|
} catch (err) {
|
|
438
459
|
fs.rmSync(tmp, { recursive: true, force: true });
|
|
@@ -456,6 +477,30 @@ function skillsSnapshot(entries, root) {
|
|
|
456
477
|
}
|
|
457
478
|
}
|
|
458
479
|
|
|
480
|
+
// Copies one skill, following links. A dangling link is left out; a skill
|
|
481
|
+
// that still cannot be copied (a link loop) is removed again. One broken
|
|
482
|
+
// skill in the app's skills directory must not fail every session.
|
|
483
|
+
function copySkill(from, to) {
|
|
484
|
+
try {
|
|
485
|
+
fs.cpSync(from, to, {
|
|
486
|
+
recursive: true,
|
|
487
|
+
dereference: true,
|
|
488
|
+
filter: (src) => {
|
|
489
|
+
try {
|
|
490
|
+
fs.statSync(src);
|
|
491
|
+
return true;
|
|
492
|
+
} catch {
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
});
|
|
497
|
+
return true;
|
|
498
|
+
} catch {
|
|
499
|
+
fs.rmSync(to, { recursive: true, force: true });
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
459
504
|
function linkDir(target, link) {
|
|
460
505
|
try {
|
|
461
506
|
fs.symlinkSync(target, link, process.platform === 'win32' ? 'junction' : 'dir');
|
|
@@ -465,13 +510,13 @@ function linkDir(target, link) {
|
|
|
465
510
|
}
|
|
466
511
|
}
|
|
467
512
|
|
|
468
|
-
// Rewrites the frontmatter `model:` of an agent profile when it names
|
|
469
|
-
// GLM-5.
|
|
513
|
+
// Rewrites the frontmatter `model:` of an agent profile when it names a
|
|
514
|
+
// GLM-5.x id (any prefix: "account:x/GLM-5.3",
|
|
470
515
|
// "custom:account%3Ax:GLM-5.3") so its model part is `model`.
|
|
471
516
|
function pinAgentModel(text, model) {
|
|
472
517
|
const m = /^(---\r?\n)([\s\S]*?)(\r?\n---)/.exec(text);
|
|
473
518
|
if (!m) return text;
|
|
474
|
-
const front = m[2].replace(/^(\s*model\s*:\s*["']?)([^\n"']*?)(?:\/|:)GLM-5
|
|
519
|
+
const front = m[2].replace(/^(\s*model\s*:\s*["']?)([^\n"']*?)(?:\/|:)GLM-5\.\d+(?:-Flash)?(["']?\s*)$/im, (all, a, prefix, tail) => {
|
|
475
520
|
const sep = all.slice(a.length + prefix.length, a.length + prefix.length + 1);
|
|
476
521
|
return `${a}${prefix}${sep}${model}${tail}`;
|
|
477
522
|
});
|
|
@@ -495,6 +540,9 @@ function buildEngineHome({
|
|
|
495
540
|
profile = null,
|
|
496
541
|
model = DEFAULT_MODEL,
|
|
497
542
|
instructions = EXECUTOR_AGENTS_MD,
|
|
543
|
+
// The engine's builtin provider config: models it already lists are not
|
|
544
|
+
// registered again. Unknown → every ADDED_MODELS entry is registered.
|
|
545
|
+
builtinConfig = null,
|
|
498
546
|
}) {
|
|
499
547
|
const zdir = path.join(home, '.zcode');
|
|
500
548
|
const v2 = path.join(zdir, 'v2');
|
|
@@ -507,12 +555,14 @@ function buildEngineHome({
|
|
|
507
555
|
const liveV2 = path.join(live, 'v2');
|
|
508
556
|
const v2Files = listDir(liveV2).filter((e) => e.isFile() && !isV2Excluded(e.name));
|
|
509
557
|
for (const entry of v2Files) {
|
|
558
|
+
// The app's v2 files can hold provider keys (v2/config.json): owner-only.
|
|
510
559
|
fs.copyFileSync(path.join(liveV2, entry.name), path.join(v2, entry.name));
|
|
560
|
+
fs.chmodSync(path.join(v2, entry.name), 0o600);
|
|
511
561
|
}
|
|
512
562
|
const providerConfig = path.join(v2, 'provider_config.json');
|
|
513
563
|
const copied = v2Files.some((e) => e.name === 'provider_config.json');
|
|
514
|
-
const mode = copied && rewriteProviderConfig(providerConfig, key) ? 'copied-v2-top-level' : 'synthesized';
|
|
515
|
-
if (mode === 'synthesized') writeJson600(providerConfig, synthesizedProviderConfig(key));
|
|
564
|
+
const mode = copied && rewriteProviderConfig(providerConfig, key, builtinConfig) ? 'copied-v2-top-level' : 'synthesized';
|
|
565
|
+
if (mode === 'synthesized') writeJson600(providerConfig, synthesizedProviderConfig(key, builtinConfig));
|
|
516
566
|
|
|
517
567
|
// cli/config.json: live copy (builtin:zai key swapped) + this run's MCP set.
|
|
518
568
|
const cfg = readJson(path.join(live, 'cli', 'config.json')) || {};
|
|
@@ -544,7 +594,7 @@ function buildEngineHome({
|
|
|
544
594
|
if (!entry.isFile() || !entry.name.endsWith('.md')) continue;
|
|
545
595
|
if (!inheritDesktop && entry.name !== `${profile}.md`) continue;
|
|
546
596
|
fs.mkdirSync(agentsDir, { recursive: true });
|
|
547
|
-
// Profiles pinning a GLM
|
|
597
|
+
// Profiles pinning a GLM id would silently run another model than
|
|
548
598
|
// the session's: the copy follows the session (the live file is never edited).
|
|
549
599
|
const text = fs.readFileSync(path.join(live, 'agents', entry.name), 'utf8');
|
|
550
600
|
fs.writeFileSync(path.join(agentsDir, entry.name), pinAgentModel(text, model));
|
|
@@ -571,6 +621,7 @@ function buildEngineHome({
|
|
|
571
621
|
fs.rmSync(skillsDir, { recursive: true, force: true });
|
|
572
622
|
fs.mkdirSync(skillsDir, { recursive: true });
|
|
573
623
|
let skillsCopied = 0;
|
|
624
|
+
const skillsSkipped = [];
|
|
574
625
|
if (!noSkills && !hermetic) {
|
|
575
626
|
const entries = desktopSkills(live);
|
|
576
627
|
// One shared snapshot per distinct desktop skill set, linked into each
|
|
@@ -578,10 +629,9 @@ function buildEngineHome({
|
|
|
578
629
|
// per session. Without a root (or links), copy as before.
|
|
579
630
|
const snapshot = root ? skillsSnapshot(entries, root) : null;
|
|
580
631
|
for (const { name, from } of entries) {
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
skillsCopied++;
|
|
632
|
+
const shared = snapshot && fs.existsSync(path.join(snapshot, name));
|
|
633
|
+
if ((shared && linkDir(path.join(snapshot, name), path.join(skillsDir, name))) || copySkill(from, path.join(skillsDir, name))) skillsCopied++;
|
|
634
|
+
else skillsSkipped.push(name);
|
|
585
635
|
}
|
|
586
636
|
}
|
|
587
637
|
const skillsInjected = [];
|
|
@@ -603,6 +653,8 @@ function buildEngineHome({
|
|
|
603
653
|
copiedFiles: v2Files.length,
|
|
604
654
|
skillsCopied,
|
|
605
655
|
skillsInjected,
|
|
656
|
+
// Desktop skills that could not be copied (a link loop, unreadable files).
|
|
657
|
+
skillsSkipped,
|
|
606
658
|
mcp: {
|
|
607
659
|
servers,
|
|
608
660
|
// Names the caller explicitly added — the CLI waits for these to
|
|
@@ -712,26 +764,18 @@ function engineEnv({ home, builtinProviderConfig, parentEnv = process.env, sessi
|
|
|
712
764
|
|
|
713
765
|
module.exports = {
|
|
714
766
|
buildEngineHome,
|
|
715
|
-
pinAgentModel,
|
|
716
767
|
engineEnv,
|
|
717
768
|
rootDir,
|
|
718
769
|
liveDir,
|
|
719
770
|
migrateRoot,
|
|
720
771
|
effectiveMcpServers,
|
|
721
772
|
liveMcpServers,
|
|
722
|
-
inheritableMcpServers,
|
|
723
|
-
needsOAuth,
|
|
724
773
|
EXECUTOR_AGENTS_MD,
|
|
725
774
|
ACP_AGENTS_MD,
|
|
726
775
|
DEFAULT_BROWSER_SERVER,
|
|
727
776
|
PLAYWRIGHT_MCP_VERSION,
|
|
728
777
|
readMcpHealth,
|
|
729
778
|
recordMcpHealth,
|
|
730
|
-
unhealthyMcp,
|
|
731
779
|
mcpRetryAfter,
|
|
732
|
-
mcpSignature,
|
|
733
|
-
skillsSnapshot,
|
|
734
|
-
discoverSkillDirs,
|
|
735
780
|
LIVE_ZCODE,
|
|
736
|
-
LIVE_V2,
|
|
737
781
|
};
|
package/lib/key.js
CHANGED
|
@@ -74,8 +74,4 @@ function resolveKeyInfo(env = process.env) {
|
|
|
74
74
|
throw new NoKeyError();
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
return resolveKeyInfo(env).key;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
module.exports = { resolveKey, resolveKeyInfo, readDesktopKey, credentialsPath, rootDir, NoKeyError };
|
|
77
|
+
module.exports = { resolveKeyInfo, readDesktopKey, rootDir, NoKeyError };
|
package/lib/models.js
CHANGED
|
@@ -5,12 +5,15 @@
|
|
|
5
5
|
|
|
6
6
|
const fs = require('node:fs');
|
|
7
7
|
|
|
8
|
-
const DEFAULT_MODEL = 'GLM-5.
|
|
8
|
+
const DEFAULT_MODEL = 'GLM-5.4';
|
|
9
9
|
const DEFAULT_EFFORT = 'high';
|
|
10
10
|
|
|
11
11
|
// Case-insensitive aliases → official ids (exact ids pass through verbatim;
|
|
12
|
-
// they are exactly "GLM-5.3" / "GLM-5.3-Flash").
|
|
12
|
+
// they are exactly "GLM-5.4" / "GLM-5.3" / "GLM-5.3-Flash").
|
|
13
13
|
const ALIASES = new Map([
|
|
14
|
+
['glm-5.4', 'GLM-5.4'],
|
|
15
|
+
['5.4', 'GLM-5.4'],
|
|
16
|
+
['54', 'GLM-5.4'],
|
|
14
17
|
['glm-5.3', 'GLM-5.3'],
|
|
15
18
|
['5.3', 'GLM-5.3'],
|
|
16
19
|
['53', 'GLM-5.3'],
|
|
@@ -20,10 +23,10 @@ const ALIASES = new Map([
|
|
|
20
23
|
['53f', 'GLM-5.3-Flash'],
|
|
21
24
|
]);
|
|
22
25
|
|
|
23
|
-
const SUPPORTED = ['glm-5.3', 'glm-5.3-flash'];
|
|
26
|
+
const SUPPORTED = ['glm-5.4', 'glm-5.3', 'glm-5.3-flash'];
|
|
24
27
|
|
|
25
28
|
// Effort enum per the bundle's schema (DESIGN §8). `high` is the default;
|
|
26
|
-
// `low|high|max` are the levels
|
|
29
|
+
// `low|high|max` are the levels every supported model accepts.
|
|
27
30
|
const EFFORT_LEVELS = ['low', 'medium', 'high', 'xhigh', 'max'];
|
|
28
31
|
|
|
29
32
|
function normalizeEffort(input) {
|
|
@@ -41,11 +44,26 @@ function normalizeModel(input) {
|
|
|
41
44
|
function unknownModelMessage(input) {
|
|
42
45
|
return (
|
|
43
46
|
`unknown model "${input}". zcode-agent supports only ` +
|
|
44
|
-
`${SUPPORTED
|
|
45
|
-
`(official ids: GLM-5.3, GLM-5.3-Flash).`
|
|
47
|
+
`${SUPPORTED.join(', ')} (official ids: ${OFFICIAL_IDS.join(', ')}).`
|
|
46
48
|
);
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
// --- models the engine does not know yet -------------------------------------
|
|
52
|
+
//
|
|
53
|
+
// GLM-5.4 (2026-11-23) is newer than every ZCode release's builtin provider
|
|
54
|
+
// config: the zai-api template's builtinModelIds stop at GLM-5.3 /
|
|
55
|
+
// GLM-5.3-Flash, so the engine would refuse it ("Provider Registry 中不存在
|
|
56
|
+
// Model"). zcode-agent registers it in each session's own provider config the
|
|
57
|
+
// way the app registers a model a user adds by hand: the id in the zai-api
|
|
58
|
+
// rule's personalModelIds plus a providerModelRules entry giving the config
|
|
59
|
+
// the engine needs to call it (window, image input, reasoning levels and the
|
|
60
|
+
// Anthropic-API mapping of a level, copied from the glm-5.3 rules). Once an
|
|
61
|
+
// engine's template lists the id itself, its builtin rules are used instead.
|
|
62
|
+
const REASONING_MAP = '{\n "thinking": {\n "type": "enabled"\n },\n "output_config": {\n "effort": reasoningLevel\n }\n}';
|
|
63
|
+
const ADDED_MODELS = {
|
|
64
|
+
'GLM-5.4': { contextWindow: 1000000, supportsImage: true, levels: ['low', 'high', 'max'], maxOutputTokens: 128000 },
|
|
65
|
+
};
|
|
66
|
+
|
|
49
67
|
// --- supported effort levels per model ---------------------------------------
|
|
50
68
|
//
|
|
51
69
|
// The engine rejects an unsupported reasoning level only after it has been
|
|
@@ -59,28 +77,67 @@ function unknownModelMessage(input) {
|
|
|
59
77
|
// rule that lists values wins. Unreadable or unmatched → the table below
|
|
60
78
|
// (observed in zcode-builtin.json shipped with ZCode 0.16.x).
|
|
61
79
|
const FALLBACK_LEVELS = {
|
|
80
|
+
'GLM-5.4': ADDED_MODELS['GLM-5.4'].levels,
|
|
62
81
|
'GLM-5.3': ['low', 'high', 'max'],
|
|
63
82
|
'GLM-5.3-Flash': ['low', 'high', 'max'],
|
|
64
83
|
};
|
|
65
84
|
const OFFICIAL_IDS = Object.keys(FALLBACK_LEVELS);
|
|
66
85
|
|
|
67
|
-
const
|
|
86
|
+
const configCache = new Map(); // path → {stamp, rules, zaiModelIds}
|
|
68
87
|
|
|
69
|
-
|
|
88
|
+
// {rules: modelRules[], zaiModelIds: the zai-api template's builtinModelIds}
|
|
89
|
+
// of a builtin provider config; empty when unreadable.
|
|
90
|
+
function readBuiltin(file) {
|
|
70
91
|
try {
|
|
71
92
|
const st = fs.statSync(file);
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
93
|
+
const stamp = `${st.mtimeMs}:${st.size}`;
|
|
94
|
+
const hit = configCache.get(file);
|
|
95
|
+
if (hit && hit.stamp === stamp) return hit;
|
|
96
|
+
const config = (JSON.parse(fs.readFileSync(file, 'utf8')) || {}).config || {};
|
|
97
|
+
const rules = config.modelConfigRules && config.modelConfigRules.modelRules;
|
|
98
|
+
const templates = config.providerConfigRules && config.providerConfigRules.templateRules;
|
|
99
|
+
const zai = Array.isArray(templates) && templates.find((t) => t && t.templateId === 'zai-api');
|
|
100
|
+
const ids = zai && zai.config && zai.config.builtinModelIds;
|
|
101
|
+
const entry = { stamp, rules: Array.isArray(rules) ? rules : [], zaiModelIds: Array.isArray(ids) ? ids : [] };
|
|
102
|
+
configCache.set(file, entry);
|
|
103
|
+
return entry;
|
|
79
104
|
} catch {
|
|
80
|
-
return [];
|
|
105
|
+
return { rules: [], zaiModelIds: [] };
|
|
81
106
|
}
|
|
82
107
|
}
|
|
83
108
|
|
|
109
|
+
const readRules = (file) => readBuiltin(file).rules;
|
|
110
|
+
|
|
111
|
+
// The ADDED_MODELS entry zcode-agent registers for `model`, or null when the
|
|
112
|
+
// model is not one of them or the engine's own config already lists it.
|
|
113
|
+
function addedModel(model, file) {
|
|
114
|
+
const added = ADDED_MODELS[model];
|
|
115
|
+
if (!added) return null;
|
|
116
|
+
return file && readBuiltin(file).zaiModelIds.includes(model) ? null : added;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// What buildEngineHome adds to a session's provider config: the ids for the
|
|
120
|
+
// zai-api rule's personalModelIds and their providerModelRules entries.
|
|
121
|
+
function addedModelRegistration(builtinConfig) {
|
|
122
|
+
const ids = Object.keys(ADDED_MODELS).filter((id) => addedModel(id, builtinConfig));
|
|
123
|
+
const rules = ids.map((modelId) => {
|
|
124
|
+
const m = ADDED_MODELS[modelId];
|
|
125
|
+
return {
|
|
126
|
+
providerId: 'zai-api',
|
|
127
|
+
modelId,
|
|
128
|
+
config: {
|
|
129
|
+
enabled: true,
|
|
130
|
+
properties: { contextWindow: m.contextWindow, inputFormat: { supportsImage: m.supportsImage } },
|
|
131
|
+
optionSpecs: {
|
|
132
|
+
reasoningLevel: { values: [...m.levels], map: REASONING_MAP },
|
|
133
|
+
maxOutputTokens: { max: m.maxOutputTokens },
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
return { ids, rules };
|
|
139
|
+
}
|
|
140
|
+
|
|
84
141
|
function builtinConfigPath(env) {
|
|
85
142
|
try {
|
|
86
143
|
const { resolveEngine, resolveBuiltinProviderConfig } = require('./engine.js');
|
|
@@ -93,6 +150,8 @@ function builtinConfigPath(env) {
|
|
|
93
150
|
// Efforts (a subset of EFFORT_LEVELS, in enum order) the model accepts.
|
|
94
151
|
function supportedEfforts(model, { env = process.env, builtinConfig } = {}) {
|
|
95
152
|
const file = builtinConfig || builtinConfigPath(env);
|
|
153
|
+
const added = addedModel(model, file);
|
|
154
|
+
if (added) return [...added.levels];
|
|
96
155
|
let values = null;
|
|
97
156
|
if (file) {
|
|
98
157
|
for (const rule of readRules(file)) {
|
|
@@ -122,11 +181,15 @@ function modelLevels(opts) {
|
|
|
122
181
|
// .inputFormat.supportsImage, last matching rule that sets it wins (the
|
|
123
182
|
// generic `glm-5.3(-flash)?` rule says false, the later `glm-5.3-flash` rule
|
|
124
183
|
// true). GLM-5.3 cannot see images: reading a PNG returns only an upload
|
|
125
|
-
// confirmation, so it must never be the judge of a screenshot.
|
|
126
|
-
|
|
184
|
+
// confirmation, so it must never be the judge of a screenshot. GLM-5.4 sees
|
|
185
|
+
// images (Z.ai, 2026-11-23); until an engine lists it, its ADDED_MODELS entry
|
|
186
|
+
// decides, since only the generic glm-5 rule (text only) would match it.
|
|
187
|
+
const FALLBACK_IMAGES = { 'GLM-5.4': true, 'GLM-5.3': false, 'GLM-5.3-Flash': true };
|
|
127
188
|
|
|
128
189
|
function supportsImage(model, { env = process.env, builtinConfig } = {}) {
|
|
129
190
|
const file = builtinConfig || builtinConfigPath(env);
|
|
191
|
+
const added = addedModel(model, file);
|
|
192
|
+
if (added) return added.supportsImage;
|
|
130
193
|
let value = null;
|
|
131
194
|
if (file) {
|
|
132
195
|
for (const rule of readRules(file)) {
|
|
@@ -150,11 +213,18 @@ function modelVision(opts) {
|
|
|
150
213
|
return Object.fromEntries(OFFICIAL_IDS.map((id) => [id, supportsImage(id, opts)]));
|
|
151
214
|
}
|
|
152
215
|
|
|
153
|
-
// The
|
|
216
|
+
// The model that judges screenshots for the visual verifier: GLM-5.3-Flash,
|
|
217
|
+
// the cheapest image-capable model (the verifier only looks and reports),
|
|
218
|
+
// else the first image-capable one.
|
|
219
|
+
const VERIFIER_PREFERENCE = ['GLM-5.3-Flash', ...OFFICIAL_IDS.filter((id) => id !== 'GLM-5.3-Flash')];
|
|
154
220
|
function visionModel(opts) {
|
|
155
|
-
return
|
|
221
|
+
return VERIFIER_PREFERENCE.find((id) => supportsImage(id, opts)) || DEFAULT_MODEL;
|
|
156
222
|
}
|
|
157
223
|
|
|
224
|
+
// Context window by model for display (ACP usage): the engine's own value
|
|
225
|
+
// when it reports one wins over this.
|
|
226
|
+
const CONTEXT_WINDOWS = { 'GLM-5.4': ADDED_MODELS['GLM-5.4'].contextWindow, 'GLM-5.3': 1000000, 'GLM-5.3-Flash': 200000 };
|
|
227
|
+
|
|
158
228
|
// null when `effort` is usable with `model`, else the one-line refusal.
|
|
159
229
|
// `source` names where the value came from ("--effort", "contract effort").
|
|
160
230
|
function effortProblem(model, effort, { source = '--effort', ...opts } = {}) {
|
|
@@ -164,18 +234,19 @@ function effortProblem(model, effort, { source = '--effort', ...opts } = {}) {
|
|
|
164
234
|
}
|
|
165
235
|
|
|
166
236
|
module.exports = {
|
|
237
|
+
addedModelRegistration,
|
|
238
|
+
CONTEXT_WINDOWS,
|
|
239
|
+
OFFICIAL_IDS,
|
|
167
240
|
supportsImage,
|
|
168
241
|
modelVision,
|
|
169
242
|
visionModel,
|
|
170
243
|
supportedEfforts,
|
|
171
244
|
modelLevels,
|
|
172
245
|
effortProblem,
|
|
173
|
-
FALLBACK_LEVELS,
|
|
174
246
|
DEFAULT_MODEL,
|
|
175
247
|
DEFAULT_EFFORT,
|
|
176
248
|
normalizeModel,
|
|
177
249
|
unknownModelMessage,
|
|
178
250
|
normalizeEffort,
|
|
179
251
|
EFFORT_LEVELS,
|
|
180
|
-
SUPPORTED,
|
|
181
252
|
};
|
package/lib/plan.js
CHANGED
|
@@ -387,9 +387,16 @@ async function supervise(name, { deadline = Infinity, signal } = {}) {
|
|
|
387
387
|
if (!release) return { busy: true };
|
|
388
388
|
try {
|
|
389
389
|
store.updatePlanState(name, { supervisor: { pid: process.pid } });
|
|
390
|
+
let r = null;
|
|
390
391
|
for (;;) {
|
|
391
392
|
const state = store.readPlanState(name);
|
|
392
|
-
|
|
393
|
+
// The plan file is re-read every round. One caught mid-save (or
|
|
394
|
+
// briefly gone) must not end the supervisor: the last good read stands.
|
|
395
|
+
try {
|
|
396
|
+
r = resolvePlan(state.file, state.cwd);
|
|
397
|
+
} catch (err) {
|
|
398
|
+
if (!r || !(err instanceof PlanError)) throw err;
|
|
399
|
+
}
|
|
393
400
|
const sessions = sessionList(r.plan);
|
|
394
401
|
const byId = new Map(sessions.map((s) => [s.id, s]));
|
|
395
402
|
const statuses = sessionStatuses(r, state);
|
|
@@ -418,8 +425,13 @@ async function supervise(name, { deadline = Infinity, signal } = {}) {
|
|
|
418
425
|
}
|
|
419
426
|
}
|
|
420
427
|
|
|
421
|
-
// A detached supervisor process (`zcode __plan <name>`); records its
|
|
428
|
+
// A detached supervisor process (`zcode-agent __plan <name>`); records its
|
|
429
|
+
// pid. A plan that already has a live supervisor keeps it: a second one
|
|
430
|
+
// would find the plan lock taken and exit, leaving its dead pid in the state
|
|
431
|
+
// (the plan then read "interrupted" between stages).
|
|
422
432
|
function startSupervisor(name) {
|
|
433
|
+
const current = store.readPlanState(name);
|
|
434
|
+
if (supervisorAlive(current)) return current.supervisor.pid;
|
|
423
435
|
const dir = store.plansDir();
|
|
424
436
|
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
425
437
|
const log = fs.openSync(path.join(dir, `${name}.log`), 'a', 0o600);
|
|
@@ -439,18 +451,14 @@ module.exports = {
|
|
|
439
451
|
resolvePlan,
|
|
440
452
|
planName,
|
|
441
453
|
sessionList,
|
|
442
|
-
afterOf,
|
|
443
454
|
sessionBase,
|
|
444
455
|
checkPlan,
|
|
445
456
|
sessionStatuses,
|
|
446
|
-
aggregate,
|
|
447
457
|
exitCodeForPlan,
|
|
448
458
|
supervisorAlive,
|
|
449
459
|
planReport,
|
|
450
460
|
launchFailure,
|
|
451
461
|
sessionInvocation,
|
|
452
|
-
preflightContext,
|
|
453
|
-
launchSession,
|
|
454
462
|
resumeSession,
|
|
455
463
|
supervise,
|
|
456
464
|
startSupervisor,
|
package/lib/ports.js
CHANGED
package/lib/procs.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Child process groups that must not outlive this process: engines and
|
|
3
|
+
// checks are spawned detached (their own group, so one kill takes the whole
|
|
4
|
+
// tree) and are normally killed where they are awaited. This registry is the
|
|
5
|
+
// backstop for every other way out (a second Ctrl-C's process.exit, an
|
|
6
|
+
// uncaught error): at 'exit' whatever is still tracked is killed, so an
|
|
7
|
+
// engine in yolo mode never keeps running tools with nothing to stop it.
|
|
8
|
+
// Detached workers and plan supervisors are meant to outlive their parent
|
|
9
|
+
// and are never tracked.
|
|
10
|
+
const tracked = new Set();
|
|
11
|
+
let installed = false;
|
|
12
|
+
|
|
13
|
+
function killAll() {
|
|
14
|
+
for (const pid of tracked) {
|
|
15
|
+
try {
|
|
16
|
+
process.kill(-pid, 'SIGKILL');
|
|
17
|
+
} catch {
|
|
18
|
+
/* already gone */
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
tracked.clear();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Registers a process-group id; returns the function that forgets it.
|
|
25
|
+
function track(pid) {
|
|
26
|
+
if (!pid) return () => {};
|
|
27
|
+
if (!installed) {
|
|
28
|
+
installed = true;
|
|
29
|
+
process.on('exit', killAll);
|
|
30
|
+
}
|
|
31
|
+
tracked.add(pid);
|
|
32
|
+
return () => tracked.delete(pid);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = { track, killAll };
|
package/lib/store.js
CHANGED
package/lib/taskspec.js
CHANGED
package/lib/ui.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// are unset, and nothing animates — the feed is append-only lines, so a
|
|
6
6
|
// non-interactive log reads exactly like the terminal did.
|
|
7
7
|
//
|
|
8
|
-
// ▸ zcode zc-1a2b3c4d task GLM-5.
|
|
8
|
+
// ▸ zcode zc-1a2b3c4d task GLM-5.4 · effort high session header
|
|
9
9
|
// ● executing phase
|
|
10
10
|
// → Edit · ✓ Edit · ✗ Bash tools (dim)
|
|
11
11
|
// ⇢ subagent started / returned subagents
|
|
@@ -199,7 +199,8 @@ function formatResult(r, { color = false } = {}) {
|
|
|
199
199
|
if (r.error && r.error.message && !(r.issues || []).includes(r.error.message)) {
|
|
200
200
|
L.push(`error ${r.error.kind}: ${r.error.message.split('\n')[0]}`);
|
|
201
201
|
}
|
|
202
|
-
|
|
202
|
+
// An ACP session continues in its ACP client, not with `resume`.
|
|
203
|
+
if (r.status !== 'completed' && r.status !== 'cancelled' && r.kind !== 'acp') {
|
|
203
204
|
L.push(c.dim(`next zcode-agent resume ${r.id} "<message>"`));
|
|
204
205
|
}
|
|
205
206
|
return L.join('\n') + '\n';
|
|
@@ -232,7 +233,11 @@ function formatSessionView(v, { events = [] } = {}) {
|
|
|
232
233
|
L.push(` activity ${v.activity.toolCalls || 0} tool calls · ${v.activity.subagentsStarted || 0} subagents${v.activity.lastTool ? ` · last ${v.activity.lastTool}` : ''} · ${v.activity.lastEventAt || ''}`);
|
|
233
234
|
}
|
|
234
235
|
if (v.idleMs !== undefined) L.push(` idle ${Math.round(v.idleMs / 1000)}s since the last engine event${v.stalled ? ' STALLED?' : ''}`);
|
|
235
|
-
if (v.state === 'interrupted')
|
|
236
|
+
if (v.state === 'interrupted') {
|
|
237
|
+
L.push(v.kind === 'acp'
|
|
238
|
+
? ' the ACP agent that ran it is gone; reopen the session in the ACP client'
|
|
239
|
+
: ` the owning process is gone; continue with: zcode-agent resume ${v.id}`);
|
|
240
|
+
}
|
|
236
241
|
if (events.length) {
|
|
237
242
|
L.push(' recent');
|
|
238
243
|
for (const e of events) {
|
package/lib/verify.js
CHANGED
|
@@ -51,7 +51,10 @@ function buildVerifierPrompt(contract, { session, round = 1 }) {
|
|
|
51
51
|
].join('\n');
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
// Ends at a fence on its own line (a ``` quoted inside a "seen" string is
|
|
55
|
+
// not the end); the loose form is tried only when nothing ends properly.
|
|
56
|
+
const BLOCK_RE = /```zcode-visual[^\n]*\n([\s\S]*?)\n[ \t]*```/g;
|
|
57
|
+
const BLOCK_LOOSE_RE = /```zcode-visual[^\n]*\n([\s\S]*?)```/g;
|
|
55
58
|
|
|
56
59
|
function normMet(v) {
|
|
57
60
|
if (v === true || v === false) return v;
|
|
@@ -66,7 +69,8 @@ function normMet(v) {
|
|
|
66
69
|
// {entries: [{criterion, viewport?, met: true|false|null, seen, note, shot}],
|
|
67
70
|
// error}. The LAST block wins; an unparsable or empty block is an error.
|
|
68
71
|
function parseVisualBlock(text) {
|
|
69
|
-
|
|
72
|
+
let matches = [...String(text || '').matchAll(BLOCK_RE)];
|
|
73
|
+
if (!matches.length) matches = [...String(text || '').matchAll(BLOCK_LOOSE_RE)];
|
|
70
74
|
if (!matches.length) return { entries: [], error: 'no zcode-visual block' };
|
|
71
75
|
let raw;
|
|
72
76
|
try {
|
|
@@ -97,4 +101,4 @@ function notVerified(criteria, why) {
|
|
|
97
101
|
return criteria.map((criterion) => ({ criterion, met: null, seen: '', note: `not verified: ${why}` }));
|
|
98
102
|
}
|
|
99
103
|
|
|
100
|
-
module.exports = { buildVerifierPrompt, parseVisualBlock, notVerified
|
|
104
|
+
module.exports = { buildVerifierPrompt, parseVisualBlock, notVerified };
|