@zhushanwen/zcode-subagent-cli 0.3.2 → 0.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/dist/{chunk-YVCSSNF6.js → chunk-U56IBQ47.js} +139 -47
- package/dist/index.cjs +188 -99
- package/dist/index.d.cts +24 -14
- package/dist/index.d.ts +24 -14
- package/dist/index.js +1 -1
- package/dist/main.cjs +191 -102
- package/dist/main.js +1 -1
- package/package.json +3 -3
package/dist/main.cjs
CHANGED
|
@@ -23,10 +23,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
));
|
|
24
24
|
|
|
25
25
|
// src/main.ts
|
|
26
|
-
var
|
|
26
|
+
var import_subagent_engine_sdk15 = require("@zhushanwen/subagent-engine-sdk");
|
|
27
27
|
|
|
28
28
|
// src/server.ts
|
|
29
|
-
var
|
|
29
|
+
var import_subagent_engine_sdk14 = require("@zhushanwen/subagent-engine-sdk");
|
|
30
30
|
|
|
31
31
|
// src/constants.ts
|
|
32
32
|
var ZCODE_ENGINE_ID = "zcode";
|
|
@@ -34,7 +34,6 @@ var ZCODE_ADAPTER_VERSION = "2.0.0";
|
|
|
34
34
|
var ZCODE_CLI_DEFAULT_PATH = "/Applications/ZCode.app/Contents/Resources/glm/zcode.cjs";
|
|
35
35
|
var ZCODE_V2_CONFIG_PATH_SUFFIX = [".zcode", "v2", "config.json"];
|
|
36
36
|
var ZCODE_FALLBACK_DEFAULT_MODEL = "builtin:bigmodel-coding-plan/GLM-5.3";
|
|
37
|
-
var ZCODE_HOST_DB_SUFFIX = [".zcode", "cli", "db", "db.sqlite"];
|
|
38
37
|
var ZCODE_KILL_GRACE_MS = 5e3;
|
|
39
38
|
var ZCODE_ERROR_TAIL_CHARS = 2e3;
|
|
40
39
|
var ZCODE_APPSERVER_REQUEST_TIMEOUT_MS = 15e3;
|
|
@@ -73,13 +72,13 @@ var ZCODE_RESUME_CHARS_PER_TOKEN = 4;
|
|
|
73
72
|
var ZCODE_SESSION_SWEEP_DEFER_MS = 50;
|
|
74
73
|
|
|
75
74
|
// src/registration.ts
|
|
76
|
-
var
|
|
75
|
+
var import_subagent_engine_sdk12 = require("@zhushanwen/subagent-engine-sdk");
|
|
77
76
|
|
|
78
77
|
// src/zcode-engine.ts
|
|
79
78
|
var fs6 = __toESM(require("fs"), 1);
|
|
80
79
|
var path4 = __toESM(require("path"), 1);
|
|
81
|
-
var import_subagent_engine_sdk9 = require("@zhushanwen/subagent-engine-sdk");
|
|
82
80
|
var import_subagent_engine_sdk10 = require("@zhushanwen/subagent-engine-sdk");
|
|
81
|
+
var import_subagent_engine_sdk11 = require("@zhushanwen/subagent-engine-sdk");
|
|
83
82
|
|
|
84
83
|
// src/journal-io.ts
|
|
85
84
|
var import_subagent_engine_sdk = require("@zhushanwen/subagent-engine-sdk");
|
|
@@ -95,11 +94,12 @@ function replayJournalToSessionView(handle, engineId) {
|
|
|
95
94
|
// src/db-path.ts
|
|
96
95
|
var os = __toESM(require("os"), 1);
|
|
97
96
|
var path = __toESM(require("path"), 1);
|
|
97
|
+
var import_subagent_engine_sdk3 = require("@zhushanwen/subagent-engine-sdk");
|
|
98
98
|
function zcodeSessionDbPath(engineDataDir) {
|
|
99
|
-
return path.join(engineDataDir,
|
|
99
|
+
return path.join(engineDataDir, ...import_subagent_engine_sdk3.ZCODE_ISOLATED_DB_SEGMENTS);
|
|
100
100
|
}
|
|
101
101
|
function hostZcodeDbPath() {
|
|
102
|
-
return path.join(os.homedir(), ...ZCODE_HOST_DB_SUFFIX);
|
|
102
|
+
return path.join(os.homedir(), ...import_subagent_engine_sdk3.ZCODE_HOST_DB_SUFFIX);
|
|
103
103
|
}
|
|
104
104
|
function zcodeDbPathAllowlist(dataDir) {
|
|
105
105
|
return [zcodeSessionDbPath(dataDir), hostZcodeDbPath()];
|
|
@@ -268,7 +268,7 @@ var fs2 = __toESM(require("fs"), 1);
|
|
|
268
268
|
var path3 = __toESM(require("path"), 1);
|
|
269
269
|
|
|
270
270
|
// src/error-message.ts
|
|
271
|
-
var
|
|
271
|
+
var import_subagent_engine_sdk4 = require("@zhushanwen/subagent-engine-sdk");
|
|
272
272
|
|
|
273
273
|
// src/appserver-launcher.ts
|
|
274
274
|
var ZCODE_APPSERVER_LAUNCHER_NAME = "appserver-launcher.cjs";
|
|
@@ -368,8 +368,63 @@ if (text !== null) {
|
|
|
368
368
|
};
|
|
369
369
|
}
|
|
370
370
|
|
|
371
|
-
// \
|
|
372
|
-
//
|
|
371
|
+
// \u5185\u5EFA provider \u914D\u7F6E\u5B9A\u4F4D\uFF08\u6F02\u79FB\u9762\u2461\uFF09\uFF1A3.12.x \u8D77\u914D\u7F6E\u6587\u4EF6\u632A\u4F4D + CLI \u4F9D\u8D56\u5BBF\u4E3B\u6CE8\u5165
|
|
372
|
+
// ZCODE_BUILTIN_PROVIDER_CONFIG_FILE \u76F4\u63A5\u5B9A\u4F4D\uFF1BZCode \u684C\u9762 spawn \u94FE\u81EA\u5E26\u8BE5\u952E\uFF0C
|
|
373
|
+
// \u672C wrapper \u94FE\u9700\u81EA\u7ED9\u3002\u663E\u5F0F\u4F20\u5165\u4F18\u5148 \u2192 v2 runtime \u76EE\u5F55\u4E0B\u5E73\u53F0\u76EE\u5F55\uFF08\u7CBE\u786E
|
|
374
|
+
// <plat>-<arch> \u4F18\u5148\uFF0CRust arch \u53D8\u4F53\u5982 darwin-aarch64 \u5B57\u5178\u5E8F\u8DDF\u540E\uFF09\xD7 \u7248\u672C\u76EE\u5F55
|
|
375
|
+
// \uFF08semver \u6700\u5927\uFF09\u7684 endpoint-*/zcode-builtin.json \u2192 \u90FD\u627E\u4E0D\u5230\u5219\u4E0D\u8BBE\u952E\uFF0C\u8BA9 CLI
|
|
376
|
+
// \u539F\u751F\u62A5\u9519\u900F\u51FA\uFF08\u9519\u8BEF\u6587\u6848\u542B\u6062\u590D\u6307\u5F15\uFF09\u3002
|
|
377
|
+
if (!process.env.ZCODE_BUILTIN_PROVIDER_CONFIG_FILE) {
|
|
378
|
+
let located = null;
|
|
379
|
+
try {
|
|
380
|
+
const providerRoot = path.join(os.homedir(), '.zcode', 'v2', 'runtime', 'provider');
|
|
381
|
+
// \u5E73\u53F0\u76EE\u5F55\u53CC\u547D\u540D\uFF1ANode \u5F62\u6001 <plat>-<arch>\uFF08darwin-arm64\uFF09\u4E0E\u684C\u9762 app \u7684 Rust
|
|
382
|
+
// arch \u547D\u540D\uFF08darwin-aarch64/linux-x86_64\uFF09\u5E76\u5B58\u2014\u2014\u6309\u5E73\u53F0\u524D\u7F00\u6536\u96C6\u5B50\u76EE\u5F55\uFF0C
|
|
383
|
+
// \u7CBE\u786E\u5F62\u6001\u6392\u6700\u5148\uFF08\u5411\u540E\u517C\u5BB9\u81EA\u5EFA\u5E03\u5C40\uFF09\uFF0CRust \u53D8\u4F53\u6309\u5B57\u5178\u5E8F\u8DDF\u540E\u9010\u4E2A\u5C1D\u8BD5
|
|
384
|
+
const exact = process.platform + '-' + process.arch;
|
|
385
|
+
const platDirs = fs.readdirSync(providerRoot, { withFileTypes: true })
|
|
386
|
+
.filter((d) => d.isDirectory() && d.name.startsWith(process.platform + '-'))
|
|
387
|
+
.map((d) => d.name)
|
|
388
|
+
.sort((a, b) => {
|
|
389
|
+
if ((a === exact) !== (b === exact)) return a === exact ? -1 : 1;
|
|
390
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
391
|
+
});
|
|
392
|
+
const byVerDesc = (a, b) => {
|
|
393
|
+
const pa = a.split('.'), pb = b.split('.');
|
|
394
|
+
for (let i = 0; i < 3; i++) {
|
|
395
|
+
const na = parseInt(pa[i], 10) || 0, nb = parseInt(pb[i], 10) || 0;
|
|
396
|
+
if (na !== nb) return nb - na;
|
|
397
|
+
}
|
|
398
|
+
return 0;
|
|
399
|
+
};
|
|
400
|
+
for (const plat of platDirs) {
|
|
401
|
+
const rtRoot = path.join(providerRoot, plat);
|
|
402
|
+
let vers = [];
|
|
403
|
+
try { vers = fs.readdirSync(rtRoot).filter((v) => /^\\d+\\.\\d+/.test(v)).sort(byVerDesc); } catch { /* \u5E73\u53F0\u76EE\u5F55\u4E0D\u53EF\u8BFB \u2192 \u8BD5\u4E0B\u4E00\u4E2A */ }
|
|
404
|
+
for (const ver of vers) {
|
|
405
|
+
const verDir = path.join(rtRoot, ver);
|
|
406
|
+
let endpoints = [];
|
|
407
|
+
try { endpoints = fs.readdirSync(verDir).filter((e) => e.startsWith('endpoint-')).sort(); } catch { /* \u7248\u672C\u76EE\u5F55\u4E0D\u53EF\u8BFB \u2192 \u8DF3\u8FC7 */ }
|
|
408
|
+
for (const ep of endpoints) {
|
|
409
|
+
const candidate = path.join(verDir, ep, 'zcode-builtin.json');
|
|
410
|
+
if (fs.existsSync(candidate)) { located = candidate; break; }
|
|
411
|
+
}
|
|
412
|
+
if (located) break;
|
|
413
|
+
}
|
|
414
|
+
if (located) break;
|
|
415
|
+
}
|
|
416
|
+
} catch { /* provider \u76EE\u5F55\u7F3A\u5931/\u4E0D\u53EF\u8BFB \u2192 \u4E0D\u8BBE\u952E */ }
|
|
417
|
+
if (located) process.env.ZCODE_BUILTIN_PROVIDER_CONFIG_FILE = located;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// \u4E0A\u6E38 provider bootstrap \u4EE5 argv[1] \u4E3A\u5165\u53E3\u951A\uFF0C\u4ECE\u8BE5\u8DEF\u5F84\u90BB\u8FD1\u5B9A\u4F4D CLI \u5185\u5EFA
|
|
421
|
+
// provider \u914D\u7F6E\u2014\u2014wrapper \u5F62\u6001\u4E0B argv[1] = \u672C wrapper \u843D\u76D8\u8DEF\u5F84\uFF0Cbootstrap \u4F1A\u5728
|
|
422
|
+
// wrapper \u90BB\u57DF\u627E provider \u914D\u7F6E\u800C\u5931\u8D25\uFF08\u771F\u673A\u62A5\u300C\u65E0\u6CD5\u5B9A\u4F4D CLI ZCode Built-in Provider
|
|
423
|
+
// Config\u300D\u542F\u52A8\u5373\u9000\uFF09\u3002import \u524D\u628A argv[1] \u6539\u5199\u4E3A CLI_PATH\uFF1ACLI \u770B\u5230\u7684 argv \u5E8F\u5217\u4E0E
|
|
424
|
+
// \u65E0 wrapper \u76F4\u8DD1\uFF08node <cliPath> app-server ...\uFF09\u9010\u4F4D\u4E00\u81F4\uFF0Cargv[0]=node\u3001
|
|
425
|
+
// argv[2]='app-server' \u4E0D\u53D8\uFF0Cincludes('app-server') \u5B50\u547D\u4EE4\u5224\u5B9A\u4E0D\u53D7\u5F71\u54CD\u3002
|
|
426
|
+
// import() \u517C\u5BB9 CJS/ESM \u5165\u53E3\u3002
|
|
427
|
+
process.argv[1] = CLI_PATH;
|
|
373
428
|
import(CLI_PATH).catch((err) => {
|
|
374
429
|
process.stderr.write('[zcode-launcher] zcode.cjs \u52A0\u8F7D\u5931\u8D25: ' + (err && err.message || err) + '\\n');
|
|
375
430
|
process.exit(3);
|
|
@@ -386,7 +441,7 @@ function ensureAppServerLauncher(engineDataDir) {
|
|
|
386
441
|
fs2.writeFileSync(tmp, APPSERVER_LAUNCHER_SOURCE);
|
|
387
442
|
fs2.renameSync(tmp, file);
|
|
388
443
|
} catch (err) {
|
|
389
|
-
const reason = (0,
|
|
444
|
+
const reason = (0, import_subagent_engine_sdk4.toErrorMessage)(err);
|
|
390
445
|
throw new Error(
|
|
391
446
|
`zcode app-server launcher \u843D\u76D8\u5931\u8D25: ${file}\uFF08${reason}\uFF09\u3002\u6062\u590D\uFF1A\u68C0\u67E5\u5F15\u64CE\u6570\u636E\u76EE\u5F55 \u5199\u6743\u9650\u4E0E\u78C1\u76D8\u7A7A\u95F4\uFF08engineDataDir \u7531\u5BBF\u4E3B\u4F20\u5165\uFF0C\u8DEF\u5F84\u89C1\u4E0A\uFF09\u540E\u91CD\u8BD5\u3002`
|
|
392
447
|
);
|
|
@@ -437,26 +492,40 @@ function usageFromStepFinish(part) {
|
|
|
437
492
|
cacheWrite: finiteOr2(cache.write, 0)
|
|
438
493
|
};
|
|
439
494
|
}
|
|
440
|
-
function
|
|
441
|
-
|
|
442
|
-
|
|
495
|
+
function stateFromString(raw) {
|
|
496
|
+
try {
|
|
497
|
+
const v = JSON.parse(raw);
|
|
498
|
+
return typeof v === "object" && v !== null && !Array.isArray(v) ? v : void 0;
|
|
499
|
+
} catch {
|
|
500
|
+
return void 0;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
function stateFromPart(part) {
|
|
504
|
+
if (typeof part.state === "object" && part.state !== null && !Array.isArray(part.state)) {
|
|
505
|
+
return part.state;
|
|
506
|
+
}
|
|
443
507
|
if (typeof part.state === "string") {
|
|
444
|
-
|
|
445
|
-
const v = JSON.parse(part.state);
|
|
446
|
-
state = typeof v === "object" && v !== null ? v : void 0;
|
|
447
|
-
} catch {
|
|
448
|
-
state = void 0;
|
|
449
|
-
}
|
|
508
|
+
return stateFromString(part.state);
|
|
450
509
|
}
|
|
510
|
+
return void 0;
|
|
511
|
+
}
|
|
512
|
+
function toolResultFromOutput(errorText, output) {
|
|
513
|
+
if (errorText !== void 0) return { content: [errorText] };
|
|
514
|
+
if (typeof output === "string") return { content: [output] };
|
|
515
|
+
if (typeof output === "object" && output !== null) return { details: output };
|
|
516
|
+
return void 0;
|
|
517
|
+
}
|
|
518
|
+
function toolFromPart(part) {
|
|
519
|
+
const toolName = typeof part.tool === "string" ? part.tool : "unknown";
|
|
520
|
+
const state = stateFromPart(part);
|
|
451
521
|
const status = typeof state?.status === "string" ? state.status : "unknown";
|
|
452
522
|
const output = state?.output;
|
|
523
|
+
const errorText = status !== "completed" && typeof state?.error === "string" ? state.error : void 0;
|
|
524
|
+
const result = toolResultFromOutput(errorText, output);
|
|
453
525
|
return {
|
|
454
526
|
toolName,
|
|
455
527
|
...state?.input !== void 0 ? { args: state.input } : {},
|
|
456
|
-
|
|
457
|
-
// 的 content[] / details,不发明第二形状
|
|
458
|
-
...typeof output === "string" ? { result: { content: [output] } } : {},
|
|
459
|
-
...typeof output === "object" && output !== null ? { result: { details: output } } : {},
|
|
528
|
+
...result !== void 0 ? { result } : {},
|
|
460
529
|
...status !== "completed" ? { isError: true } : {}
|
|
461
530
|
};
|
|
462
531
|
}
|
|
@@ -630,21 +699,21 @@ async function readZcodeSessionView(dbPath, sessionId) {
|
|
|
630
699
|
var fs4 = __toESM(require("fs"), 1);
|
|
631
700
|
var import_node_path = require("path");
|
|
632
701
|
var import_node_os = require("os");
|
|
633
|
-
var
|
|
702
|
+
var import_subagent_engine_sdk7 = require("@zhushanwen/subagent-engine-sdk");
|
|
634
703
|
|
|
635
704
|
// src/logs/stderr-rotation.ts
|
|
636
|
-
var import_subagent_engine_sdk4 = require("@zhushanwen/subagent-engine-sdk");
|
|
637
705
|
var import_subagent_engine_sdk5 = require("@zhushanwen/subagent-engine-sdk");
|
|
706
|
+
var import_subagent_engine_sdk6 = require("@zhushanwen/subagent-engine-sdk");
|
|
638
707
|
var ZCODE_STDERR_LOG_PREFIX = "zcode-appserver-stderr-";
|
|
639
708
|
function stderrLogPathFor(engineDataDir, pid) {
|
|
640
|
-
return (0,
|
|
709
|
+
return (0, import_subagent_engine_sdk5.stderrLogPathFor)(engineDataDir, pid, ZCODE_STDERR_LOG_PREFIX);
|
|
641
710
|
}
|
|
642
711
|
function cleanupSiblingStderrLogs(logPath, env, now) {
|
|
643
|
-
return (0,
|
|
712
|
+
return (0, import_subagent_engine_sdk5.cleanupSiblingStderrLogs)(logPath, env, ZCODE_STDERR_LOG_PREFIX, now);
|
|
644
713
|
}
|
|
645
714
|
|
|
646
715
|
// src/connection.ts
|
|
647
|
-
var logger = (0,
|
|
716
|
+
var logger = (0, import_subagent_engine_sdk7.getLogger)("subagents");
|
|
648
717
|
var RAW_FRAME_LOG_CHARS = 200;
|
|
649
718
|
var RUNTIME_PREFERENCES = Object.freeze({
|
|
650
719
|
nativeSearchEnhancementsEnabled: true,
|
|
@@ -666,11 +735,11 @@ function frameIdOf(frame) {
|
|
|
666
735
|
return typeof id === "string" || typeof id === "number" ? id : void 0;
|
|
667
736
|
}
|
|
668
737
|
function errMessage(err) {
|
|
669
|
-
return (0,
|
|
738
|
+
return (0, import_subagent_engine_sdk4.toErrorMessage)(err);
|
|
670
739
|
}
|
|
671
740
|
function buildAppServerEnv(baseEnv = process.env) {
|
|
672
741
|
return {
|
|
673
|
-
...(0,
|
|
742
|
+
...(0, import_subagent_engine_sdk7.buildNestedSpawnEnv)(baseEnv),
|
|
674
743
|
ZCODE_MODEL_TELEMETRY_ENABLED: "false"
|
|
675
744
|
};
|
|
676
745
|
}
|
|
@@ -820,7 +889,7 @@ var AppServerConnection = class {
|
|
|
820
889
|
close() {
|
|
821
890
|
const child = this.child;
|
|
822
891
|
if (child === null || this.killChainPromise !== void 0) return;
|
|
823
|
-
this.killChainPromise = (0,
|
|
892
|
+
this.killChainPromise = (0, import_subagent_engine_sdk7.killChain)(child, { graceMs: ZCODE_KILL_GRACE_MS });
|
|
824
893
|
}
|
|
825
894
|
/**
|
|
826
895
|
* 异步完整关闭面:SIGTERM → grace → SIGKILL 杀链走完(含收尸),resolve 于进程
|
|
@@ -832,7 +901,7 @@ var AppServerConnection = class {
|
|
|
832
901
|
if (this.killChainPromise === void 0) {
|
|
833
902
|
const child = this.child;
|
|
834
903
|
if (child === null) return;
|
|
835
|
-
this.killChainPromise = (0,
|
|
904
|
+
this.killChainPromise = (0, import_subagent_engine_sdk7.killChain)(child, { graceMs: opts?.graceMs ?? ZCODE_KILL_GRACE_MS });
|
|
836
905
|
}
|
|
837
906
|
await this.killChainPromise;
|
|
838
907
|
}
|
|
@@ -851,10 +920,10 @@ var AppServerConnection = class {
|
|
|
851
920
|
this.generation += 1;
|
|
852
921
|
const gen = this.generation;
|
|
853
922
|
const script = this.launcherScript ?? this.cliPath;
|
|
854
|
-
const child = (0,
|
|
923
|
+
const child = (0, import_subagent_engine_sdk7.spawnEngineChild)({
|
|
855
924
|
command: this.nodeBin,
|
|
856
925
|
args: [script, "app-server", "--cwd", this.cwd],
|
|
857
|
-
env: (0,
|
|
926
|
+
env: (0, import_subagent_engine_sdk7.buildEngineChildEnv)(this.env, {
|
|
858
927
|
// L0 TAIJI_AGENT_DATA_DIR 缺省链:显式传参 > 宿主注入 env > tmpdir 占位
|
|
859
928
|
//(app-server 不消费该键,占位仅满足 L0 必注入契约;生产调用方
|
|
860
929
|
// zcode-engine.ensureAppServerRuntime 恒传 engineDataDir)。
|
|
@@ -892,7 +961,7 @@ var AppServerConnection = class {
|
|
|
892
961
|
}
|
|
893
962
|
}
|
|
894
963
|
};
|
|
895
|
-
(0,
|
|
964
|
+
(0, import_subagent_engine_sdk7.pumpNdjsonLines)(child.stdout, (line) => this.handleLine(line));
|
|
896
965
|
child.stderr?.setEncoding("utf8");
|
|
897
966
|
child.stderr?.on("data", (chunk) => {
|
|
898
967
|
this.stderrTail = (this.stderrTail + chunk).slice(-ZCODE_APPSERVER_STDERR_TAIL_BUFFER_CHARS);
|
|
@@ -1033,8 +1102,8 @@ var AppServerConnection = class {
|
|
|
1033
1102
|
}
|
|
1034
1103
|
this.stderrStream.write(chunk);
|
|
1035
1104
|
if (this.activeStderrLogPath !== null) {
|
|
1036
|
-
const params = (0,
|
|
1037
|
-
if ((0,
|
|
1105
|
+
const params = (0, import_subagent_engine_sdk6.stderrRotationParams)(process.env);
|
|
1106
|
+
if ((0, import_subagent_engine_sdk6.rotateStderrLogIfNeeded)(this.activeStderrLogPath, params)) {
|
|
1038
1107
|
this.closeStderrStream();
|
|
1039
1108
|
}
|
|
1040
1109
|
}
|
|
@@ -1052,8 +1121,8 @@ var AppServerConnection = class {
|
|
|
1052
1121
|
|
|
1053
1122
|
// src/session-channel.ts
|
|
1054
1123
|
var import_node_crypto = require("crypto");
|
|
1055
|
-
var
|
|
1056
|
-
var logger2 = (0,
|
|
1124
|
+
var import_subagent_engine_sdk8 = require("@zhushanwen/subagent-engine-sdk");
|
|
1125
|
+
var logger2 = (0, import_subagent_engine_sdk8.getLogger)("subagents");
|
|
1057
1126
|
var SUBSCRIBE_DELIVERY_KIND = "desktop-continuous";
|
|
1058
1127
|
var WORKSPACE_KEY_HASH_CHARS = 16;
|
|
1059
1128
|
var CREATE_REPLY_LOG_CHARS = 300;
|
|
@@ -1062,7 +1131,7 @@ function isRecord3(v) {
|
|
|
1062
1131
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1063
1132
|
}
|
|
1064
1133
|
function errMessage2(err) {
|
|
1065
|
-
return (0,
|
|
1134
|
+
return (0, import_subagent_engine_sdk4.toErrorMessage)(err);
|
|
1066
1135
|
}
|
|
1067
1136
|
function stableWorkspaceKey(workspacePath) {
|
|
1068
1137
|
return "ws-" + (0, import_node_crypto.createHash)("sha256").update(workspacePath).digest("hex").slice(0, WORKSPACE_KEY_HASH_CHARS);
|
|
@@ -1354,7 +1423,8 @@ var SessionChannel = class {
|
|
|
1354
1423
|
* session/resume 读通道([U6 / §3.2.6 要点 3,P-1 探针实证]):应答自带完整
|
|
1355
1424
|
* 双向 messages 历史(user/assistant 全量、tokens、parts)——zcode 续聊选型的
|
|
1356
1425
|
* 历史来源(读通道成立;原地 resume 续写被 -32031 卡死,写通道不可用)。错误
|
|
1357
|
-
* 原样上抛(调用方决定降级形态——引擎侧 warn
|
|
1426
|
+
* 原样上抛(调用方决定降级形态——引擎侧 warn 后注入锚失效声明段继续执行,
|
|
1427
|
+
* run 不失败,[U3])。
|
|
1358
1428
|
* 经 conn.request 惰性启动连接(resume 是 run 的**首个**请求——调用时点连接
|
|
1359
1429
|
* 可能尚未启动,与 readBestEffort 的「已死跳过」判据不同场景,不做 alive 守卫)。
|
|
1360
1430
|
*/
|
|
@@ -1709,8 +1779,8 @@ var SessionChannel = class {
|
|
|
1709
1779
|
|
|
1710
1780
|
// src/session-db-maintenance.ts
|
|
1711
1781
|
var fs5 = __toESM(require("fs"), 1);
|
|
1712
|
-
var
|
|
1713
|
-
var logger3 = (0,
|
|
1782
|
+
var import_subagent_engine_sdk9 = require("@zhushanwen/subagent-engine-sdk");
|
|
1783
|
+
var logger3 = (0, import_subagent_engine_sdk9.getLogger)("subagents");
|
|
1714
1784
|
var ZCODE_SESSION_TTL_MS = 2592e6;
|
|
1715
1785
|
var ZCODE_SESSION_SWEEP_INTERVAL_MS = 864e5;
|
|
1716
1786
|
var SWEEP_BUSY_TIMEOUT_MS = 5e3;
|
|
@@ -1866,7 +1936,7 @@ function maybeSweepExpiredZcodeSessions(dbPath, opts = {}) {
|
|
|
1866
1936
|
}
|
|
1867
1937
|
|
|
1868
1938
|
// src/zcode-engine.ts
|
|
1869
|
-
var logger4 = (0,
|
|
1939
|
+
var logger4 = (0, import_subagent_engine_sdk10.getLogger)("subagents");
|
|
1870
1940
|
var PROBE_VERSION_TIMEOUT_MS = 15e3;
|
|
1871
1941
|
var COMMON_THOUGHT_LEVELS = ["low", "high", "max"];
|
|
1872
1942
|
var ZcodeEngine = class {
|
|
@@ -1902,8 +1972,9 @@ var ZcodeEngine = class {
|
|
|
1902
1972
|
personaInjection: "prompt",
|
|
1903
1973
|
// app-server 推送流实时流出(session/event payload.delta → text_delta)
|
|
1904
1974
|
eventGranularity: "stream",
|
|
1905
|
-
//
|
|
1906
|
-
|
|
1975
|
+
// 无 OS sandbox;worktree 隔离由公共层 worktree-manager 承担(引擎侧仅消费
|
|
1976
|
+
// task.cwd → session/create 的 workspacePath)= emulated(pi 同款声明语义)
|
|
1977
|
+
sandbox: "emulated",
|
|
1907
1978
|
// sqlite 三级 JOIN 完整重建 turns(reader 实测)
|
|
1908
1979
|
sessionRead: "full",
|
|
1909
1980
|
// --resume 冷启动可用(实测)
|
|
@@ -1987,8 +2058,9 @@ var ZcodeEngine = class {
|
|
|
1987
2058
|
if (ctx.signal?.aborted === true) {
|
|
1988
2059
|
return this.abortedAppServerRun(task, ctx, startedAt);
|
|
1989
2060
|
}
|
|
1990
|
-
const
|
|
1991
|
-
|
|
2061
|
+
const requestedModel = task.model?.trim();
|
|
2062
|
+
const modelRef = requestedModel !== void 0 && requestedModel !== "" ? resolveZcodeModelRef(requestedModel, this.deps.sources) : void 0;
|
|
2063
|
+
this.warnIgnoredCtxModel(task, ctx);
|
|
1992
2064
|
this.warnThoughtLevelUncommon(task, ctx);
|
|
1993
2065
|
const cwd = task.cwd ?? process.cwd();
|
|
1994
2066
|
const schema = isPlainObject(task.schema) ? task.schema : void 0;
|
|
@@ -2089,8 +2161,7 @@ var ZcodeEngine = class {
|
|
|
2089
2161
|
*/
|
|
2090
2162
|
async attemptAppServerTurn(task, ctx, modelRef, cwd, prompt, opts = {}) {
|
|
2091
2163
|
const rt = this.ensureAppServerRuntime();
|
|
2092
|
-
const
|
|
2093
|
-
const createParams = buildAppServerCreateParams(task, providerId, modelId, cwd);
|
|
2164
|
+
const createParams = buildAppServerCreateParams(task, modelRef, cwd);
|
|
2094
2165
|
let currentSessionId;
|
|
2095
2166
|
let signalSessionCreated;
|
|
2096
2167
|
const sessionCreated = new Promise((resolve2) => {
|
|
@@ -2363,7 +2434,7 @@ var ZcodeEngine = class {
|
|
|
2363
2434
|
/** abort 合成终态:exitCode=null(record 正常收尾,不留僵尸)。 */
|
|
2364
2435
|
applyAbortedOutcome(outcome, task, ctx, final, emit) {
|
|
2365
2436
|
outcome.exitCode = null;
|
|
2366
|
-
outcome.error = isHostTimeoutAbort(ctx) ? (0,
|
|
2437
|
+
outcome.error = isHostTimeoutAbort(ctx) ? (0, import_subagent_engine_sdk11.synthesizeTimeoutOutcome)(task, final.output.stdoutText, ZCODE_ENGINE_ID).error ?? (0, import_subagent_engine_sdk11.engineTimeoutDetail)(final.output.stdoutText) : final.abortMessage ?? `engine_run_failed: zcode \u4EFB\u52A1\u88AB\u4E2D\u6B62\uFF08app-server abort \u94FE\u6536\u53E3\uFF0C\u5BBF\u4E3B\u5408\u6210\u7EC8\u6001\uFF09\u3002\u8F93\u51FA\u5C3E\u90E8: ${final.output.stdoutText.slice(-ZCODE_ERROR_TAIL_CHARS)}`;
|
|
2367
2438
|
emit({ type: "error", message: outcome.error });
|
|
2368
2439
|
}
|
|
2369
2440
|
/**
|
|
@@ -2411,10 +2482,17 @@ var ZcodeEngine = class {
|
|
|
2411
2482
|
}
|
|
2412
2483
|
/**
|
|
2413
2484
|
* [u-h2 D2-2] 派发同步期 model 校验:委托 resolveZcodeModelRef(与 run prepare 期
|
|
2414
|
-
*
|
|
2415
|
-
*
|
|
2416
|
-
* D2-1 ctxModel 不透传的承接面)。校验失败原样抛 ZcodePrepareError,由编排层
|
|
2485
|
+
* 显式路径同一函数——canonicalRef 归一化、短名缺省 provider、凭据与清单校验单一
|
|
2486
|
+
* 权威,无双实现)。校验失败原样抛 ZcodePrepareError,由编排层
|
|
2417
2487
|
* (engine/model-validation.ts)包装成「引擎与模型不配套」文案。
|
|
2488
|
+
*
|
|
2489
|
+
* [R4/D6-②] 缺席语义:本实现是进程内形态 + 协议诊断面(宿主 cli 形态消费的是
|
|
2490
|
+
* RemoteEngine 的 manifest 本地判定,不经本方法——SDK protocol methods.ts 明示
|
|
2491
|
+
* validateModel 为诊断面)。缺席 modelRef 时返回 ZCODE_FALLBACK_DEFAULT_MODEL
|
|
2492
|
+
* canonical 全名作为「引擎缺省模型」的呈现值(诊断面只读不 create,不参与
|
|
2493
|
+
* create 缺席不携带的 G3 行为链)。帧应答形态维持 {canonicalRef: string}(SDK
|
|
2494
|
+
* port-contract 契约必填——「帧字段缺席」的 optional 对齐需放宽 SDK 契约与
|
|
2495
|
+
* server handler 签名,非本包单方面可完成)。
|
|
2418
2496
|
*/
|
|
2419
2497
|
validateModel(modelRef) {
|
|
2420
2498
|
return { canonicalRef: resolveZcodeModelRef(modelRef, this.deps.sources) };
|
|
@@ -2450,7 +2528,7 @@ var ZcodeEngine = class {
|
|
|
2450
2528
|
}
|
|
2451
2529
|
} else {
|
|
2452
2530
|
const poolDir = path4.resolve(
|
|
2453
|
-
(0,
|
|
2531
|
+
(0, import_subagent_engine_sdk11.resolvePoolDir)(this.deps.engineDataDir(), ZCODE_ENGINE_ID, import_subagent_engine_sdk11.SHARED_POOL_KEY)
|
|
2454
2532
|
);
|
|
2455
2533
|
const resolved = path4.resolve(poolDir, dbPathRaw);
|
|
2456
2534
|
if (resolved.startsWith(poolDir + path4.sep)) {
|
|
@@ -2468,7 +2546,7 @@ var ZcodeEngine = class {
|
|
|
2468
2546
|
logger4.warn("[zcode-engine] native session read failed, degrade to journal replay", {
|
|
2469
2547
|
dbPath,
|
|
2470
2548
|
sessionId,
|
|
2471
|
-
reason: (0,
|
|
2549
|
+
reason: (0, import_subagent_engine_sdk4.toErrorMessage)(err)
|
|
2472
2550
|
});
|
|
2473
2551
|
}
|
|
2474
2552
|
}
|
|
@@ -2498,30 +2576,33 @@ var ZcodeEngine = class {
|
|
|
2498
2576
|
}
|
|
2499
2577
|
/**
|
|
2500
2578
|
* [F16b] ctxModel 忽略留痕:ctxModel 是 pi 链路的第三层兜底(port.ts 契约——
|
|
2501
|
-
* 依赖 pi resolveModel 链的引擎才消费它),zcode
|
|
2502
|
-
*
|
|
2503
|
-
*
|
|
2504
|
-
*
|
|
2505
|
-
*
|
|
2506
|
-
*
|
|
2579
|
+
* 依赖 pi resolveModel 链的引擎才消费它),zcode 不消费。「调用方给了 ctxModel 但
|
|
2580
|
+
* task.model 未显式指定」时出声一行。只在「ctx 有模型但被忽略」场景输出:显式
|
|
2581
|
+
* task.model 走正常解析链、ctx 本就无模型属预期缺省,均不出声(避免噪音)。
|
|
2582
|
+
* [R4/G3] 文案更新:缺席 model 时 create 不携带 model 键(缺省模型由 zcode 自身
|
|
2583
|
+
* 解析——用户 defaultModelSelection 优先),不再声称「实际使用引擎缺省模型
|
|
2584
|
+
* <fallback>」(恒传时代的表述,与缺席不携带的新行为不符)。modelRef 参数已随
|
|
2585
|
+
* R4 条件携带移除——warn 可达即缺席态(显式 task.model 在 requested 非空早退处
|
|
2586
|
+
* 返回),无第三形态。
|
|
2507
2587
|
*/
|
|
2508
|
-
warnIgnoredCtxModel(task, ctx
|
|
2588
|
+
warnIgnoredCtxModel(task, ctx) {
|
|
2509
2589
|
if (ctx.ctxModel === void 0) return;
|
|
2510
2590
|
const requested = task.model?.trim();
|
|
2511
2591
|
if (requested !== void 0 && requested !== "") return;
|
|
2512
2592
|
logger4.warn(
|
|
2513
|
-
`[zcode-engine] ctx.ctxModel\uFF08${ctx.ctxModel.id}\uFF09\u88AB\u5FFD\u7565\u2014\u2014ctxModel \u662F pi \u94FE\u8DEF\u515C\u5E95\uFF0Czcode \u4E0D\u6D88\u8D39\uFF1Btask.model \u672A\u663E\u5F0F\u6307\u5B9A\
|
|
2593
|
+
`[zcode-engine] ctx.ctxModel\uFF08${ctx.ctxModel.id}\uFF09\u88AB\u5FFD\u7565\u2014\u2014ctxModel \u662F pi \u94FE\u8DEF\u515C\u5E95\uFF0Czcode \u4E0D\u6D88\u8D39\uFF1Btask.model \u672A\u663E\u5F0F\u6307\u5B9A\uFF0Ccreate \u4E0D\u643A\u5E26 model \u952E\uFF0C\u7F3A\u7701\u6A21\u578B\u7531 zcode \u81EA\u8EAB\u89E3\u6790\uFF08\u7528\u6237 defaultModelSelection \u4F18\u5148\uFF09`,
|
|
2514
2594
|
{ taskId: ctx.taskId }
|
|
2515
2595
|
);
|
|
2516
2596
|
}
|
|
2517
2597
|
/**
|
|
2518
2598
|
* [U6 / §3.2.6 要点 3] resume 锚 → 历史前缀(interact-resume 的读半段)。
|
|
2519
2599
|
*
|
|
2520
|
-
* 无锚 / 非 zcode 锚形态 → undefined
|
|
2521
|
-
*
|
|
2522
|
-
*
|
|
2523
|
-
*
|
|
2524
|
-
*
|
|
2600
|
+
* 无锚 / 非 zcode 锚形态 → undefined(行为不变)。读通道失败(会话失效 / 控制
|
|
2601
|
+
* 面错误)= 锚真失效的权威信号——宿主侧库投影预检查已退役(app-server 落库滞后
|
|
2602
|
+
* 于 create 应答,分钟级窗 + 部分行永不落库,预检查系统性误判;resume 走
|
|
2603
|
+
* app-server resident 内存态才是真实活性判据),因此此处不再静默降级为无前缀
|
|
2604
|
+
* 裸跑,而是返回锚失效声明段:让模型知情「延续但无历史」,基于最新消息独立
|
|
2605
|
+
* 续推,而非在缺上下文时臆测连续性。用户消息照常执行,不炸轮。
|
|
2525
2606
|
*/
|
|
2526
2607
|
async buildResumeHistoryPrefix(ctx) {
|
|
2527
2608
|
const anchor = zcodeResumeAnchorOf(ctx, this.deps.engineDataDir());
|
|
@@ -2535,10 +2616,10 @@ var ZcodeEngine = class {
|
|
|
2535
2616
|
tokens = extractResumeTotalTokens(result);
|
|
2536
2617
|
} catch (err) {
|
|
2537
2618
|
logger4.warn(
|
|
2538
|
-
`[zcode-engine] session/resume \u8BFB\u5386\u53F2\u5931\u8D25\uFF08\u951A ${anchor.sessionId}\uFF09\u2014\u2014\
|
|
2619
|
+
`[zcode-engine] session/resume \u8BFB\u5386\u53F2\u5931\u8D25\uFF08\u951A ${anchor.sessionId}\uFF09\u2014\u2014\u5224\u5B9A\u951A\u771F\u5931\u6548\uFF0C\u6CE8\u5165\u951A\u5931\u6548\u58F0\u660E\u6BB5\u7EE7\u7EED\u6267\u884C: ${errMessage3(err)}`,
|
|
2539
2620
|
{ taskId: ctx.taskId }
|
|
2540
2621
|
);
|
|
2541
|
-
return
|
|
2622
|
+
return buildResumeUnavailableNoticeSegment();
|
|
2542
2623
|
}
|
|
2543
2624
|
if (history.length === 0) return void 0;
|
|
2544
2625
|
return buildResumeInjectionSegment(history, anchor.sessionId, tokens);
|
|
@@ -2552,7 +2633,7 @@ var ZcodeEngine = class {
|
|
|
2552
2633
|
buildPrompt(task, schema) {
|
|
2553
2634
|
const segments = [...task.appendSystemPrompt ?? []];
|
|
2554
2635
|
segments.push(task.prompt);
|
|
2555
|
-
if (schema !== void 0) segments.push((0,
|
|
2636
|
+
if (schema !== void 0) segments.push((0, import_subagent_engine_sdk11.buildSchemaEmulationSegment)(schema));
|
|
2556
2637
|
return segments.join("\n\n");
|
|
2557
2638
|
}
|
|
2558
2639
|
};
|
|
@@ -2588,6 +2669,9 @@ ${omissionNote}${kept.join("\n")}
|
|
|
2588
2669
|
|
|
2589
2670
|
`;
|
|
2590
2671
|
}
|
|
2672
|
+
function buildResumeUnavailableNoticeSegment() {
|
|
2673
|
+
return "[\u4F1A\u8BDD\u5EF6\u7EED\u63D0\u793A] \u672C\u6D88\u606F\u662F\u540C\u4E00\u4EFB\u52A1\u7684\u5EF6\u7EED\u4F1A\u8BDD\uFF0C\u4F46\u4E0A\u4E00\u4F1A\u8BDD\u7684\u5386\u53F2\u8BB0\u5F55\u4E0D\u53EF\u6062\u590D\uFF08\u539F\u59CB\u4F1A\u8BDD\u5DF2\u5931\u6548\uFF09\u3002\n\u6CA1\u6709\u66F4\u65E9\u7684\u5BF9\u8BDD\u4E0A\u4E0B\u6587\u53EF\u5F15\u7528\u2014\u2014\u8BF7\u57FA\u4E8E\u4E0B\u65B9\u6700\u65B0\u6D88\u606F\u72EC\u7ACB\u5224\u65AD\u5E76\u7EE7\u7EED\u63A8\u8FDB\u4EFB\u52A1\u3002\n\n";
|
|
2674
|
+
}
|
|
2591
2675
|
var ZCODE_TURN_RETRY_MIN_BUDGET_MS = 3e5;
|
|
2592
2676
|
function resolveTransientRetryBudget(totalBudgetMs, consumedMs) {
|
|
2593
2677
|
if (totalBudgetMs === void 0) return { state: "unbounded" };
|
|
@@ -2602,7 +2686,7 @@ function isPlainObject(v) {
|
|
|
2602
2686
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
2603
2687
|
}
|
|
2604
2688
|
function errMessage3(err) {
|
|
2605
|
-
return (0,
|
|
2689
|
+
return (0, import_subagent_engine_sdk4.toErrorMessage)(err);
|
|
2606
2690
|
}
|
|
2607
2691
|
function resolveAppserverTimingMs(envName, fallbackMs, label) {
|
|
2608
2692
|
const raw = process.env[envName];
|
|
@@ -2684,15 +2768,16 @@ function appendSchemaRetryDirective(basePrompt, validationError) {
|
|
|
2684
2768
|
Your previous answer failed schema validation: ${validationError}
|
|
2685
2769
|
Answer again. Output ONLY the JSON value conforming to the schema above \u2014 no prose, no markdown fences, no extra text.`;
|
|
2686
2770
|
}
|
|
2687
|
-
function buildAppServerCreateParams(task,
|
|
2771
|
+
function buildAppServerCreateParams(task, modelRef, cwd) {
|
|
2688
2772
|
const denyTools = (task.denyTools ?? []).filter((t) => typeof t === "string" && t.trim() !== "");
|
|
2689
2773
|
const thoughtLevel = task.thinkingLevel?.trim();
|
|
2774
|
+
const model = modelRef !== void 0 && modelRef !== "" ? splitZcodeModelRef(modelRef) : void 0;
|
|
2690
2775
|
return {
|
|
2691
2776
|
workspacePath: cwd,
|
|
2692
2777
|
mode: "yolo",
|
|
2693
|
-
// per-session model(G3
|
|
2694
|
-
//
|
|
2695
|
-
model
|
|
2778
|
+
// per-session model(G3):显式指定时 create 参数透传(A.2 ① strict 对象)——同进程任务
|
|
2779
|
+
// 各用各的模型,互不干扰;缺席不设键(zcode 自身缺省解析)
|
|
2780
|
+
...model !== void 0 ? { model } : {},
|
|
2696
2781
|
...thoughtLevel !== void 0 && thoughtLevel !== "" ? { thoughtLevel } : {},
|
|
2697
2782
|
...denyTools.length > 0 ? { toolDenylist: denyTools } : {}
|
|
2698
2783
|
};
|
|
@@ -2710,7 +2795,7 @@ function parsedAppServerAttempt(task, r) {
|
|
|
2710
2795
|
kind: "parsed",
|
|
2711
2796
|
output: syntheticAppServerOutput(0),
|
|
2712
2797
|
payload: turnResultToPayload(r),
|
|
2713
|
-
...schema !== void 0 ? { schemaResult: (0,
|
|
2798
|
+
...schema !== void 0 ? { schemaResult: (0, import_subagent_engine_sdk11.extractAndValidateStructuredOutput)(r.response, schema) } : {}
|
|
2714
2799
|
};
|
|
2715
2800
|
}
|
|
2716
2801
|
function failedTerminalAppServerAttempt(r) {
|
|
@@ -2781,16 +2866,16 @@ function buildAppServerTimeoutMessage(err, sessionId, stopPath, retried = false)
|
|
|
2781
2866
|
${rerunGuide}${selfHelp}\u82E5\u6301\u7EED\u51FA\u73B0\uFF0C\u68C0\u67E5 ZCode \u684C\u9762\u7AEF\u6A21\u578B\u8FDE\u901A\u6027\u6216\u6539\u7528 engine: pi\u3002`;
|
|
2782
2867
|
}
|
|
2783
2868
|
function isHostTimeoutAbort(ctx) {
|
|
2784
|
-
return ctx.signal?.aborted === true && ctx.signal.reason ===
|
|
2869
|
+
return ctx.signal?.aborted === true && ctx.signal.reason === import_subagent_engine_sdk11.HOST_TIMEOUT_ABORT_REASON;
|
|
2785
2870
|
}
|
|
2786
2871
|
var PROBE_STDOUT_CAP_CHARS = 4096;
|
|
2787
2872
|
async function defaultProbeVersion(cliPath, dataDir) {
|
|
2788
2873
|
try {
|
|
2789
2874
|
return await new Promise((resolve2, reject) => {
|
|
2790
|
-
const child = (0,
|
|
2875
|
+
const child = (0, import_subagent_engine_sdk11.spawnEngineChild)({
|
|
2791
2876
|
command: "node",
|
|
2792
2877
|
args: [cliPath, "--version"],
|
|
2793
|
-
env: (0,
|
|
2878
|
+
env: (0, import_subagent_engine_sdk11.buildEngineChildEnv)(process.env, { dataDir }),
|
|
2794
2879
|
stdout: "pipe",
|
|
2795
2880
|
stderr: "ignore",
|
|
2796
2881
|
signal: AbortSignal.timeout(PROBE_VERSION_TIMEOUT_MS)
|
|
@@ -2808,7 +2893,7 @@ async function defaultProbeVersion(cliPath, dataDir) {
|
|
|
2808
2893
|
});
|
|
2809
2894
|
} catch (err) {
|
|
2810
2895
|
logger4.debug(
|
|
2811
|
-
`[zcode-engine] probe version check failed (best-effort continue): ${(0,
|
|
2896
|
+
`[zcode-engine] probe version check failed (best-effort continue): ${(0, import_subagent_engine_sdk4.toErrorMessage)(err)}`
|
|
2812
2897
|
);
|
|
2813
2898
|
return void 0;
|
|
2814
2899
|
}
|
|
@@ -2816,7 +2901,7 @@ async function defaultProbeVersion(cliPath, dataDir) {
|
|
|
2816
2901
|
|
|
2817
2902
|
// src/registration.ts
|
|
2818
2903
|
function defaultEngineDataDir() {
|
|
2819
|
-
return (0,
|
|
2904
|
+
return (0, import_subagent_engine_sdk12.resolveEngineDataDir)(process.env);
|
|
2820
2905
|
}
|
|
2821
2906
|
function createZcodeEngine(deps) {
|
|
2822
2907
|
return new ZcodeEngine(deps);
|
|
@@ -2829,7 +2914,7 @@ function createDefaultZcodeEngine() {
|
|
|
2829
2914
|
}
|
|
2830
2915
|
|
|
2831
2916
|
// src/port-types.ts
|
|
2832
|
-
var
|
|
2917
|
+
var import_subagent_engine_sdk13 = require("@zhushanwen/subagent-engine-sdk");
|
|
2833
2918
|
|
|
2834
2919
|
// src/server.ts
|
|
2835
2920
|
var REVERSE_TIMEOUT_DEFAULT_MS = 6e4;
|
|
@@ -2850,11 +2935,11 @@ var EngineProtocolServer = class {
|
|
|
2850
2935
|
}
|
|
2851
2936
|
/** 入站帧消费(请求帧 + 反向请求应答帧;main.ts 的行解析器拆行后喂入)。 */
|
|
2852
2937
|
handleFrame(frame) {
|
|
2853
|
-
if ((0,
|
|
2938
|
+
if ((0, import_subagent_engine_sdk14.isResponseFrame)(frame)) {
|
|
2854
2939
|
this.settleReverse(frame.id, frame);
|
|
2855
2940
|
return;
|
|
2856
2941
|
}
|
|
2857
|
-
if ((0,
|
|
2942
|
+
if ((0, import_subagent_engine_sdk14.isReverseRequestFrame)(frame)) {
|
|
2858
2943
|
this.write({
|
|
2859
2944
|
id: 0,
|
|
2860
2945
|
error: {
|
|
@@ -2880,7 +2965,7 @@ var EngineProtocolServer = class {
|
|
|
2880
2965
|
async dispatch(id, method, params) {
|
|
2881
2966
|
const handler = this.methodHandlers[method];
|
|
2882
2967
|
if (handler === void 0) {
|
|
2883
|
-
throw new
|
|
2968
|
+
throw new import_subagent_engine_sdk14.EngineSdkError(
|
|
2884
2969
|
"engine_protocol_unknown_method",
|
|
2885
2970
|
`unknown protocol method: ${method} (request id ${id})`,
|
|
2886
2971
|
"The engine speaks protocol v1; check the installed engine package version vs the host."
|
|
@@ -2908,17 +2993,17 @@ var EngineProtocolServer = class {
|
|
|
2908
2993
|
};
|
|
2909
2994
|
// ── initialize:版本协商(越界 → engine_protocol_mismatch)+ 能力应答 ──
|
|
2910
2995
|
initialize(params) {
|
|
2911
|
-
if (params?.protocolVersion !==
|
|
2912
|
-
throw new
|
|
2996
|
+
if (params?.protocolVersion !== import_subagent_engine_sdk14.ENGINE_PROTOCOL_VERSION) {
|
|
2997
|
+
throw new import_subagent_engine_sdk14.EngineSdkError(
|
|
2913
2998
|
"engine_protocol_mismatch",
|
|
2914
|
-
`host protocol version ${String(params?.protocolVersion)} is not compatible with engine protocol v${
|
|
2915
|
-
`Upgrade the engine package or the host so both speak protocol v${
|
|
2999
|
+
`host protocol version ${String(params?.protocolVersion)} is not compatible with engine protocol v${import_subagent_engine_sdk14.ENGINE_PROTOCOL_VERSION}`,
|
|
3000
|
+
`Upgrade the engine package or the host so both speak protocol v${import_subagent_engine_sdk14.ENGINE_PROTOCOL_VERSION}.`
|
|
2916
3001
|
);
|
|
2917
3002
|
}
|
|
2918
3003
|
this.initialized = true;
|
|
2919
3004
|
const models = this.engine.listModels?.() ?? null;
|
|
2920
3005
|
return {
|
|
2921
|
-
protocolVersion:
|
|
3006
|
+
protocolVersion: import_subagent_engine_sdk14.ENGINE_PROTOCOL_VERSION,
|
|
2922
3007
|
engineId: this.engine.id,
|
|
2923
3008
|
engineVersion: ZCODE_ADAPTER_VERSION,
|
|
2924
3009
|
adapterVersion: ZCODE_ADAPTER_VERSION,
|
|
@@ -2929,7 +3014,7 @@ var EngineProtocolServer = class {
|
|
|
2929
3014
|
// ── run:协议载荷 → 本地 AgentCallOpts/RunContext;事件 → 通知/host 通道 ──
|
|
2930
3015
|
async run(params) {
|
|
2931
3016
|
if (!this.initialized) {
|
|
2932
|
-
throw new
|
|
3017
|
+
throw new import_subagent_engine_sdk14.EngineSdkError(
|
|
2933
3018
|
"engine_protocol_not_initialized",
|
|
2934
3019
|
"run before initialize is a protocol violation",
|
|
2935
3020
|
"The host must complete the initialize handshake before dispatching runs."
|
|
@@ -2939,8 +3024,12 @@ var EngineProtocolServer = class {
|
|
|
2939
3024
|
const controller = new AbortController();
|
|
2940
3025
|
const active = { controller, seq: 0 };
|
|
2941
3026
|
this.activeRuns.set(runId, active);
|
|
2942
|
-
const fullTask = {
|
|
2943
|
-
|
|
3027
|
+
const fullTask = {
|
|
3028
|
+
...task,
|
|
3029
|
+
...ctx.model !== void 0 ? { model: ctx.model } : {},
|
|
3030
|
+
...ctx.cwd !== void 0 ? { cwd: ctx.cwd } : {}
|
|
3031
|
+
};
|
|
3032
|
+
const ctxModel = (0, import_subagent_engine_sdk13.parseCtxModel)(ctx.ctxModel);
|
|
2944
3033
|
const stream = ctx.streamMode === "stream" ? { onDelta: (delta) => {
|
|
2945
3034
|
void this.reverseRequestInternal("host/streamDelta", { runId, delta });
|
|
2946
3035
|
} } : void 0;
|
|
@@ -2976,7 +3065,7 @@ var EngineProtocolServer = class {
|
|
|
2976
3065
|
}
|
|
2977
3066
|
validateModel(params) {
|
|
2978
3067
|
if (this.engine.validateModel === void 0) {
|
|
2979
|
-
throw new
|
|
3068
|
+
throw new import_subagent_engine_sdk14.EngineSdkError(
|
|
2980
3069
|
"engine_capability_unsupported",
|
|
2981
3070
|
"engine does not implement validateModel",
|
|
2982
3071
|
"Manifest omits modelCatalog; model validation falls back to run-time engine checks."
|
|
@@ -3022,7 +3111,7 @@ var EngineProtocolServer = class {
|
|
|
3022
3111
|
clearTimeout(pending.timer);
|
|
3023
3112
|
this.reverseClock?.acked(String(id));
|
|
3024
3113
|
this.reverseClock?.settled(String(id));
|
|
3025
|
-
if (frame.error !== void 0) pending.reject(new Error(`reverse request ${String(id)} rejected: ${(0,
|
|
3114
|
+
if (frame.error !== void 0) pending.reject(new Error(`reverse request ${String(id)} rejected: ${(0, import_subagent_engine_sdk4.toErrorMessage)(frame.error)}`));
|
|
3026
3115
|
else pending.resolve(frame.result);
|
|
3027
3116
|
}
|
|
3028
3117
|
};
|
|
@@ -3030,17 +3119,17 @@ function probeParamsOf(params) {
|
|
|
3030
3119
|
return typeof params === "object" && params !== null ? params : void 0;
|
|
3031
3120
|
}
|
|
3032
3121
|
function toProtocolError(err) {
|
|
3033
|
-
if (err instanceof
|
|
3122
|
+
if (err instanceof import_subagent_engine_sdk14.EngineSdkError) return err.toStructured();
|
|
3034
3123
|
return {
|
|
3035
3124
|
code: "engine_run_failed",
|
|
3036
|
-
message: (0,
|
|
3125
|
+
message: (0, import_subagent_engine_sdk4.toErrorMessage)(err),
|
|
3037
3126
|
recovery: "Check the engine process logs (engineDataDir/logs/) and rerun; if persistent, reinstall or upgrade the engine package."
|
|
3038
3127
|
};
|
|
3039
3128
|
}
|
|
3040
3129
|
|
|
3041
3130
|
// src/main.ts
|
|
3042
|
-
var clock = (0,
|
|
3043
|
-
(0,
|
|
3131
|
+
var clock = (0, import_subagent_engine_sdk15.armEngineSelfDestruct)({ stdin: process.stdin });
|
|
3132
|
+
(0, import_subagent_engine_sdk15.runEngineCliEntry)({
|
|
3044
3133
|
component: "zcode-engine-cli",
|
|
3045
3134
|
server: new EngineProtocolServer({
|
|
3046
3135
|
write: (frame) => {
|