@zltquant/zlt-mcp 0.6.1-beta.8 → 0.6.1
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 +16 -4
- package/package.json +1 -1
- package/zlt-mcp-proxy.bundle.cjs +923 -529
package/zlt-mcp-proxy.bundle.cjs
CHANGED
|
@@ -1147,8 +1147,8 @@ var require_command = __commonJS({
|
|
|
1147
1147
|
"../../../../node_modules/.pnpm/commander@13.1.0/node_modules/commander/lib/command.js"(exports2) {
|
|
1148
1148
|
var EventEmitter = require("node:events").EventEmitter;
|
|
1149
1149
|
var childProcess = require("node:child_process");
|
|
1150
|
-
var
|
|
1151
|
-
var
|
|
1150
|
+
var path17 = require("node:path");
|
|
1151
|
+
var fs17 = require("node:fs");
|
|
1152
1152
|
var process4 = require("node:process");
|
|
1153
1153
|
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
1154
1154
|
var { CommanderError: CommanderError2 } = require_error();
|
|
@@ -2129,7 +2129,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2129
2129
|
* @param {string} subcommandName
|
|
2130
2130
|
*/
|
|
2131
2131
|
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
2132
|
-
if (
|
|
2132
|
+
if (fs17.existsSync(executableFile)) return;
|
|
2133
2133
|
const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
|
|
2134
2134
|
const executableMissing = `'${executableFile}' does not exist
|
|
2135
2135
|
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
@@ -2147,11 +2147,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2147
2147
|
let launchWithNode = false;
|
|
2148
2148
|
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
2149
2149
|
function findFile(baseDir, baseName) {
|
|
2150
|
-
const localBin =
|
|
2151
|
-
if (
|
|
2152
|
-
if (sourceExt.includes(
|
|
2150
|
+
const localBin = path17.resolve(baseDir, baseName);
|
|
2151
|
+
if (fs17.existsSync(localBin)) return localBin;
|
|
2152
|
+
if (sourceExt.includes(path17.extname(baseName))) return void 0;
|
|
2153
2153
|
const foundExt = sourceExt.find(
|
|
2154
|
-
(ext) =>
|
|
2154
|
+
(ext) => fs17.existsSync(`${localBin}${ext}`)
|
|
2155
2155
|
);
|
|
2156
2156
|
if (foundExt) return `${localBin}${foundExt}`;
|
|
2157
2157
|
return void 0;
|
|
@@ -2163,21 +2163,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2163
2163
|
if (this._scriptPath) {
|
|
2164
2164
|
let resolvedScriptPath;
|
|
2165
2165
|
try {
|
|
2166
|
-
resolvedScriptPath =
|
|
2166
|
+
resolvedScriptPath = fs17.realpathSync(this._scriptPath);
|
|
2167
2167
|
} catch {
|
|
2168
2168
|
resolvedScriptPath = this._scriptPath;
|
|
2169
2169
|
}
|
|
2170
|
-
executableDir =
|
|
2171
|
-
|
|
2170
|
+
executableDir = path17.resolve(
|
|
2171
|
+
path17.dirname(resolvedScriptPath),
|
|
2172
2172
|
executableDir
|
|
2173
2173
|
);
|
|
2174
2174
|
}
|
|
2175
2175
|
if (executableDir) {
|
|
2176
2176
|
let localFile = findFile(executableDir, executableFile);
|
|
2177
2177
|
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
2178
|
-
const legacyName =
|
|
2178
|
+
const legacyName = path17.basename(
|
|
2179
2179
|
this._scriptPath,
|
|
2180
|
-
|
|
2180
|
+
path17.extname(this._scriptPath)
|
|
2181
2181
|
);
|
|
2182
2182
|
if (legacyName !== this._name) {
|
|
2183
2183
|
localFile = findFile(
|
|
@@ -2188,7 +2188,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2188
2188
|
}
|
|
2189
2189
|
executableFile = localFile || executableFile;
|
|
2190
2190
|
}
|
|
2191
|
-
launchWithNode = sourceExt.includes(
|
|
2191
|
+
launchWithNode = sourceExt.includes(path17.extname(executableFile));
|
|
2192
2192
|
let proc;
|
|
2193
2193
|
if (process4.platform !== "win32") {
|
|
2194
2194
|
if (launchWithNode) {
|
|
@@ -3035,7 +3035,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3035
3035
|
* @return {Command}
|
|
3036
3036
|
*/
|
|
3037
3037
|
nameFromFilename(filename) {
|
|
3038
|
-
this._name =
|
|
3038
|
+
this._name = path17.basename(filename, path17.extname(filename));
|
|
3039
3039
|
return this;
|
|
3040
3040
|
}
|
|
3041
3041
|
/**
|
|
@@ -3049,9 +3049,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3049
3049
|
* @param {string} [path]
|
|
3050
3050
|
* @return {(string|null|Command)}
|
|
3051
3051
|
*/
|
|
3052
|
-
executableDir(
|
|
3053
|
-
if (
|
|
3054
|
-
this._executableDir =
|
|
3052
|
+
executableDir(path18) {
|
|
3053
|
+
if (path18 === void 0) return this._executableDir;
|
|
3054
|
+
this._executableDir = path18;
|
|
3055
3055
|
return this;
|
|
3056
3056
|
}
|
|
3057
3057
|
/**
|
|
@@ -6274,7 +6274,7 @@ var require_compile = __commonJS({
|
|
|
6274
6274
|
const schOrFunc = root.refs[ref];
|
|
6275
6275
|
if (schOrFunc)
|
|
6276
6276
|
return schOrFunc;
|
|
6277
|
-
let _sch =
|
|
6277
|
+
let _sch = resolve9.call(this, root, ref);
|
|
6278
6278
|
if (_sch === void 0) {
|
|
6279
6279
|
const schema = (_a = root.localRefs) === null || _a === void 0 ? void 0 : _a[ref];
|
|
6280
6280
|
const { schemaId } = this.opts;
|
|
@@ -6301,7 +6301,7 @@ var require_compile = __commonJS({
|
|
|
6301
6301
|
function sameSchemaEnv(s1, s2) {
|
|
6302
6302
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
6303
6303
|
}
|
|
6304
|
-
function
|
|
6304
|
+
function resolve9(root, ref) {
|
|
6305
6305
|
let sch;
|
|
6306
6306
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
6307
6307
|
ref = sch;
|
|
@@ -6516,8 +6516,8 @@ var require_utils = __commonJS({
|
|
|
6516
6516
|
}
|
|
6517
6517
|
return ind;
|
|
6518
6518
|
}
|
|
6519
|
-
function removeDotSegments(
|
|
6520
|
-
let input =
|
|
6519
|
+
function removeDotSegments(path17) {
|
|
6520
|
+
let input = path17;
|
|
6521
6521
|
const output = [];
|
|
6522
6522
|
let nextSlash = -1;
|
|
6523
6523
|
let len = 0;
|
|
@@ -6716,8 +6716,8 @@ var require_schemes = __commonJS({
|
|
|
6716
6716
|
wsComponent.secure = void 0;
|
|
6717
6717
|
}
|
|
6718
6718
|
if (wsComponent.resourceName) {
|
|
6719
|
-
const [
|
|
6720
|
-
wsComponent.path =
|
|
6719
|
+
const [path17, query] = wsComponent.resourceName.split("?");
|
|
6720
|
+
wsComponent.path = path17 && path17 !== "/" ? path17 : void 0;
|
|
6721
6721
|
wsComponent.query = query;
|
|
6722
6722
|
wsComponent.resourceName = void 0;
|
|
6723
6723
|
}
|
|
@@ -6876,7 +6876,7 @@ var require_fast_uri = __commonJS({
|
|
|
6876
6876
|
}
|
|
6877
6877
|
return uri;
|
|
6878
6878
|
}
|
|
6879
|
-
function
|
|
6879
|
+
function resolve9(baseURI, relativeURI, options) {
|
|
6880
6880
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
6881
6881
|
const resolved = resolveComponent(parse3(baseURI, schemelessOptions), parse3(relativeURI, schemelessOptions), schemelessOptions, true);
|
|
6882
6882
|
schemelessOptions.skipEscape = true;
|
|
@@ -7103,7 +7103,7 @@ var require_fast_uri = __commonJS({
|
|
|
7103
7103
|
var fastUri = {
|
|
7104
7104
|
SCHEMES,
|
|
7105
7105
|
normalize: normalize2,
|
|
7106
|
-
resolve:
|
|
7106
|
+
resolve: resolve9,
|
|
7107
7107
|
resolveComponent,
|
|
7108
7108
|
equal,
|
|
7109
7109
|
serialize,
|
|
@@ -10079,12 +10079,12 @@ var require_dist = __commonJS({
|
|
|
10079
10079
|
throw new Error(`Unknown format "${name}"`);
|
|
10080
10080
|
return f;
|
|
10081
10081
|
};
|
|
10082
|
-
function addFormats(ajv, list,
|
|
10082
|
+
function addFormats(ajv, list, fs17, exportName) {
|
|
10083
10083
|
var _a;
|
|
10084
10084
|
var _b;
|
|
10085
10085
|
(_a = (_b = ajv.opts.code).formats) !== null && _a !== void 0 ? _a : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
|
|
10086
10086
|
for (const f of list)
|
|
10087
|
-
ajv.addFormat(f,
|
|
10087
|
+
ajv.addFormat(f, fs17[f]);
|
|
10088
10088
|
}
|
|
10089
10089
|
module2.exports = exports2 = formatsPlugin;
|
|
10090
10090
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -10097,8 +10097,8 @@ var require_windows = __commonJS({
|
|
|
10097
10097
|
"../../../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js"(exports2, module2) {
|
|
10098
10098
|
module2.exports = isexe;
|
|
10099
10099
|
isexe.sync = sync;
|
|
10100
|
-
var
|
|
10101
|
-
function checkPathExt(
|
|
10100
|
+
var fs17 = require("fs");
|
|
10101
|
+
function checkPathExt(path17, options) {
|
|
10102
10102
|
var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
|
|
10103
10103
|
if (!pathext) {
|
|
10104
10104
|
return true;
|
|
@@ -10109,25 +10109,25 @@ var require_windows = __commonJS({
|
|
|
10109
10109
|
}
|
|
10110
10110
|
for (var i = 0; i < pathext.length; i++) {
|
|
10111
10111
|
var p = pathext[i].toLowerCase();
|
|
10112
|
-
if (p &&
|
|
10112
|
+
if (p && path17.substr(-p.length).toLowerCase() === p) {
|
|
10113
10113
|
return true;
|
|
10114
10114
|
}
|
|
10115
10115
|
}
|
|
10116
10116
|
return false;
|
|
10117
10117
|
}
|
|
10118
|
-
function checkStat(stat,
|
|
10118
|
+
function checkStat(stat, path17, options) {
|
|
10119
10119
|
if (!stat.isSymbolicLink() && !stat.isFile()) {
|
|
10120
10120
|
return false;
|
|
10121
10121
|
}
|
|
10122
|
-
return checkPathExt(
|
|
10122
|
+
return checkPathExt(path17, options);
|
|
10123
10123
|
}
|
|
10124
|
-
function isexe(
|
|
10125
|
-
|
|
10126
|
-
cb(er, er ? false : checkStat(stat,
|
|
10124
|
+
function isexe(path17, options, cb) {
|
|
10125
|
+
fs17.stat(path17, function(er, stat) {
|
|
10126
|
+
cb(er, er ? false : checkStat(stat, path17, options));
|
|
10127
10127
|
});
|
|
10128
10128
|
}
|
|
10129
|
-
function sync(
|
|
10130
|
-
return checkStat(
|
|
10129
|
+
function sync(path17, options) {
|
|
10130
|
+
return checkStat(fs17.statSync(path17), path17, options);
|
|
10131
10131
|
}
|
|
10132
10132
|
}
|
|
10133
10133
|
});
|
|
@@ -10137,14 +10137,14 @@ var require_mode = __commonJS({
|
|
|
10137
10137
|
"../../../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js"(exports2, module2) {
|
|
10138
10138
|
module2.exports = isexe;
|
|
10139
10139
|
isexe.sync = sync;
|
|
10140
|
-
var
|
|
10141
|
-
function isexe(
|
|
10142
|
-
|
|
10140
|
+
var fs17 = require("fs");
|
|
10141
|
+
function isexe(path17, options, cb) {
|
|
10142
|
+
fs17.stat(path17, function(er, stat) {
|
|
10143
10143
|
cb(er, er ? false : checkStat(stat, options));
|
|
10144
10144
|
});
|
|
10145
10145
|
}
|
|
10146
|
-
function sync(
|
|
10147
|
-
return checkStat(
|
|
10146
|
+
function sync(path17, options) {
|
|
10147
|
+
return checkStat(fs17.statSync(path17), options);
|
|
10148
10148
|
}
|
|
10149
10149
|
function checkStat(stat, options) {
|
|
10150
10150
|
return stat.isFile() && checkMode(stat, options);
|
|
@@ -10168,7 +10168,7 @@ var require_mode = __commonJS({
|
|
|
10168
10168
|
// ../../../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js
|
|
10169
10169
|
var require_isexe = __commonJS({
|
|
10170
10170
|
"../../../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js"(exports2, module2) {
|
|
10171
|
-
var
|
|
10171
|
+
var fs17 = require("fs");
|
|
10172
10172
|
var core;
|
|
10173
10173
|
if (process.platform === "win32" || global.TESTING_WINDOWS) {
|
|
10174
10174
|
core = require_windows();
|
|
@@ -10177,7 +10177,7 @@ var require_isexe = __commonJS({
|
|
|
10177
10177
|
}
|
|
10178
10178
|
module2.exports = isexe;
|
|
10179
10179
|
isexe.sync = sync;
|
|
10180
|
-
function isexe(
|
|
10180
|
+
function isexe(path17, options, cb) {
|
|
10181
10181
|
if (typeof options === "function") {
|
|
10182
10182
|
cb = options;
|
|
10183
10183
|
options = {};
|
|
@@ -10186,17 +10186,17 @@ var require_isexe = __commonJS({
|
|
|
10186
10186
|
if (typeof Promise !== "function") {
|
|
10187
10187
|
throw new TypeError("callback not provided");
|
|
10188
10188
|
}
|
|
10189
|
-
return new Promise(function(
|
|
10190
|
-
isexe(
|
|
10189
|
+
return new Promise(function(resolve9, reject) {
|
|
10190
|
+
isexe(path17, options || {}, function(er, is) {
|
|
10191
10191
|
if (er) {
|
|
10192
10192
|
reject(er);
|
|
10193
10193
|
} else {
|
|
10194
|
-
|
|
10194
|
+
resolve9(is);
|
|
10195
10195
|
}
|
|
10196
10196
|
});
|
|
10197
10197
|
});
|
|
10198
10198
|
}
|
|
10199
|
-
core(
|
|
10199
|
+
core(path17, options || {}, function(er, is) {
|
|
10200
10200
|
if (er) {
|
|
10201
10201
|
if (er.code === "EACCES" || options && options.ignoreErrors) {
|
|
10202
10202
|
er = null;
|
|
@@ -10206,9 +10206,9 @@ var require_isexe = __commonJS({
|
|
|
10206
10206
|
cb(er, is);
|
|
10207
10207
|
});
|
|
10208
10208
|
}
|
|
10209
|
-
function sync(
|
|
10209
|
+
function sync(path17, options) {
|
|
10210
10210
|
try {
|
|
10211
|
-
return core.sync(
|
|
10211
|
+
return core.sync(path17, options || {});
|
|
10212
10212
|
} catch (er) {
|
|
10213
10213
|
if (options && options.ignoreErrors || er.code === "EACCES") {
|
|
10214
10214
|
return false;
|
|
@@ -10224,7 +10224,7 @@ var require_isexe = __commonJS({
|
|
|
10224
10224
|
var require_which = __commonJS({
|
|
10225
10225
|
"../../../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js"(exports2, module2) {
|
|
10226
10226
|
var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
|
|
10227
|
-
var
|
|
10227
|
+
var path17 = require("path");
|
|
10228
10228
|
var COLON = isWindows ? ";" : ":";
|
|
10229
10229
|
var isexe = require_isexe();
|
|
10230
10230
|
var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" });
|
|
@@ -10257,27 +10257,27 @@ var require_which = __commonJS({
|
|
|
10257
10257
|
opt = {};
|
|
10258
10258
|
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
10259
10259
|
const found = [];
|
|
10260
|
-
const step = (i) => new Promise((
|
|
10260
|
+
const step = (i) => new Promise((resolve9, reject) => {
|
|
10261
10261
|
if (i === pathEnv.length)
|
|
10262
|
-
return opt.all && found.length ?
|
|
10262
|
+
return opt.all && found.length ? resolve9(found) : reject(getNotFoundError(cmd));
|
|
10263
10263
|
const ppRaw = pathEnv[i];
|
|
10264
10264
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
10265
|
-
const pCmd =
|
|
10265
|
+
const pCmd = path17.join(pathPart, cmd);
|
|
10266
10266
|
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
10267
|
-
|
|
10267
|
+
resolve9(subStep(p, i, 0));
|
|
10268
10268
|
});
|
|
10269
|
-
const subStep = (p, i, ii) => new Promise((
|
|
10269
|
+
const subStep = (p, i, ii) => new Promise((resolve9, reject) => {
|
|
10270
10270
|
if (ii === pathExt.length)
|
|
10271
|
-
return
|
|
10271
|
+
return resolve9(step(i + 1));
|
|
10272
10272
|
const ext = pathExt[ii];
|
|
10273
10273
|
isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
|
|
10274
10274
|
if (!er && is) {
|
|
10275
10275
|
if (opt.all)
|
|
10276
10276
|
found.push(p + ext);
|
|
10277
10277
|
else
|
|
10278
|
-
return
|
|
10278
|
+
return resolve9(p + ext);
|
|
10279
10279
|
}
|
|
10280
|
-
return
|
|
10280
|
+
return resolve9(subStep(p, i, ii + 1));
|
|
10281
10281
|
});
|
|
10282
10282
|
});
|
|
10283
10283
|
return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
|
|
@@ -10289,7 +10289,7 @@ var require_which = __commonJS({
|
|
|
10289
10289
|
for (let i = 0; i < pathEnv.length; i++) {
|
|
10290
10290
|
const ppRaw = pathEnv[i];
|
|
10291
10291
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
10292
|
-
const pCmd =
|
|
10292
|
+
const pCmd = path17.join(pathPart, cmd);
|
|
10293
10293
|
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
10294
10294
|
for (let j = 0; j < pathExt.length; j++) {
|
|
10295
10295
|
const cur = p + pathExt[j];
|
|
@@ -10337,7 +10337,7 @@ var require_path_key = __commonJS({
|
|
|
10337
10337
|
var require_resolveCommand = __commonJS({
|
|
10338
10338
|
"../../../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports2, module2) {
|
|
10339
10339
|
"use strict";
|
|
10340
|
-
var
|
|
10340
|
+
var path17 = require("path");
|
|
10341
10341
|
var which = require_which();
|
|
10342
10342
|
var getPathKey = require_path_key();
|
|
10343
10343
|
function resolveCommandAttempt(parsed, withoutPathExt) {
|
|
@@ -10355,7 +10355,7 @@ var require_resolveCommand = __commonJS({
|
|
|
10355
10355
|
try {
|
|
10356
10356
|
resolved = which.sync(parsed.command, {
|
|
10357
10357
|
path: env[getPathKey({ env })],
|
|
10358
|
-
pathExt: withoutPathExt ?
|
|
10358
|
+
pathExt: withoutPathExt ? path17.delimiter : void 0
|
|
10359
10359
|
});
|
|
10360
10360
|
} catch (e) {
|
|
10361
10361
|
} finally {
|
|
@@ -10364,7 +10364,7 @@ var require_resolveCommand = __commonJS({
|
|
|
10364
10364
|
}
|
|
10365
10365
|
}
|
|
10366
10366
|
if (resolved) {
|
|
10367
|
-
resolved =
|
|
10367
|
+
resolved = path17.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
|
|
10368
10368
|
}
|
|
10369
10369
|
return resolved;
|
|
10370
10370
|
}
|
|
@@ -10418,8 +10418,8 @@ var require_shebang_command = __commonJS({
|
|
|
10418
10418
|
if (!match) {
|
|
10419
10419
|
return null;
|
|
10420
10420
|
}
|
|
10421
|
-
const [
|
|
10422
|
-
const binary =
|
|
10421
|
+
const [path17, argument] = match[0].replace(/#! ?/, "").split(" ");
|
|
10422
|
+
const binary = path17.split("/").pop();
|
|
10423
10423
|
if (binary === "env") {
|
|
10424
10424
|
return argument;
|
|
10425
10425
|
}
|
|
@@ -10432,16 +10432,16 @@ var require_shebang_command = __commonJS({
|
|
|
10432
10432
|
var require_readShebang = __commonJS({
|
|
10433
10433
|
"../../../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js"(exports2, module2) {
|
|
10434
10434
|
"use strict";
|
|
10435
|
-
var
|
|
10435
|
+
var fs17 = require("fs");
|
|
10436
10436
|
var shebangCommand = require_shebang_command();
|
|
10437
10437
|
function readShebang(command) {
|
|
10438
10438
|
const size = 150;
|
|
10439
10439
|
const buffer = Buffer.alloc(size);
|
|
10440
10440
|
let fd;
|
|
10441
10441
|
try {
|
|
10442
|
-
fd =
|
|
10443
|
-
|
|
10444
|
-
|
|
10442
|
+
fd = fs17.openSync(command, "r");
|
|
10443
|
+
fs17.readSync(fd, buffer, 0, size, 0);
|
|
10444
|
+
fs17.closeSync(fd);
|
|
10445
10445
|
} catch (e) {
|
|
10446
10446
|
}
|
|
10447
10447
|
return shebangCommand(buffer.toString());
|
|
@@ -10454,7 +10454,7 @@ var require_readShebang = __commonJS({
|
|
|
10454
10454
|
var require_parse = __commonJS({
|
|
10455
10455
|
"../../../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js"(exports2, module2) {
|
|
10456
10456
|
"use strict";
|
|
10457
|
-
var
|
|
10457
|
+
var path17 = require("path");
|
|
10458
10458
|
var resolveCommand = require_resolveCommand();
|
|
10459
10459
|
var escape2 = require_escape();
|
|
10460
10460
|
var readShebang = require_readShebang();
|
|
@@ -10479,7 +10479,7 @@ var require_parse = __commonJS({
|
|
|
10479
10479
|
const needsShell = !isExecutableRegExp.test(commandFile);
|
|
10480
10480
|
if (parsed.options.forceShell || needsShell) {
|
|
10481
10481
|
const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
|
|
10482
|
-
parsed.command =
|
|
10482
|
+
parsed.command = path17.normalize(parsed.command);
|
|
10483
10483
|
parsed.command = escape2.command(parsed.command);
|
|
10484
10484
|
parsed.args = parsed.args.map((arg) => escape2.argument(arg, needsDoubleEscapeMetaChars));
|
|
10485
10485
|
const shellCommand = [parsed.command].concat(parsed.args).join(" ");
|
|
@@ -10606,13 +10606,340 @@ var {
|
|
|
10606
10606
|
Help
|
|
10607
10607
|
} = import_index.default;
|
|
10608
10608
|
|
|
10609
|
+
// src/cli-evidence.ts
|
|
10610
|
+
var fs = __toESM(require("node:fs"), 1);
|
|
10611
|
+
var path = __toESM(require("node:path"), 1);
|
|
10612
|
+
function evidenceDirectoryArg(args) {
|
|
10613
|
+
if (!["call", "list"].includes(args[0])) return void 0;
|
|
10614
|
+
let directory;
|
|
10615
|
+
const valueOptions = /* @__PURE__ */ new Set(["--args-json", "--args-file", "--output-json", "--tool", "--timeout-ms", "--max-total-timeout-ms"]);
|
|
10616
|
+
for (let i = 1; i < args.length && args[i] !== "--"; i++) {
|
|
10617
|
+
const arg = args[i];
|
|
10618
|
+
if (valueOptions.has(arg)) {
|
|
10619
|
+
i++;
|
|
10620
|
+
continue;
|
|
10621
|
+
}
|
|
10622
|
+
if (arg !== "--evidence-dir" && !arg.startsWith("--evidence-dir=")) continue;
|
|
10623
|
+
if (directory !== void 0) throw new Error("Specify --evidence-dir only once");
|
|
10624
|
+
const value = arg === "--evidence-dir" ? args[++i] : arg.slice("--evidence-dir=".length);
|
|
10625
|
+
if (!value || value.startsWith("--")) throw new Error("--evidence-dir requires a new directory path");
|
|
10626
|
+
directory = value;
|
|
10627
|
+
}
|
|
10628
|
+
return directory;
|
|
10629
|
+
}
|
|
10630
|
+
var CliEvidence = class {
|
|
10631
|
+
resultFile;
|
|
10632
|
+
diagnosticsFile;
|
|
10633
|
+
executionFile;
|
|
10634
|
+
state;
|
|
10635
|
+
diagnosticFailure;
|
|
10636
|
+
originalWrite = process.stderr.write;
|
|
10637
|
+
logFd;
|
|
10638
|
+
teeWrite;
|
|
10639
|
+
constructor(directory, provenance, command) {
|
|
10640
|
+
const root = path.resolve(directory);
|
|
10641
|
+
fs.mkdirSync(root);
|
|
10642
|
+
this.resultFile = path.join(root, "result.json");
|
|
10643
|
+
this.diagnosticsFile = path.join(root, "diagnostics.log");
|
|
10644
|
+
this.executionFile = path.join(root, "execution.json");
|
|
10645
|
+
this.state = {
|
|
10646
|
+
schemaVersion: 1,
|
|
10647
|
+
command,
|
|
10648
|
+
cliProvenance: provenance,
|
|
10649
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10650
|
+
state: "running",
|
|
10651
|
+
stage: "arguments",
|
|
10652
|
+
toolExecution: "not_started",
|
|
10653
|
+
business: "not_reported",
|
|
10654
|
+
exitCode: null,
|
|
10655
|
+
resultFile: this.resultFile,
|
|
10656
|
+
diagnosticsFile: this.diagnosticsFile,
|
|
10657
|
+
retry: "inspect_state_before_retry"
|
|
10658
|
+
};
|
|
10659
|
+
this.logFd = fs.openSync(this.diagnosticsFile, "wx");
|
|
10660
|
+
try {
|
|
10661
|
+
this.persist();
|
|
10662
|
+
} catch (error2) {
|
|
10663
|
+
fs.closeSync(this.logFd);
|
|
10664
|
+
throw error2;
|
|
10665
|
+
}
|
|
10666
|
+
this.teeWrite = ((...args) => {
|
|
10667
|
+
try {
|
|
10668
|
+
const chunk = args[0];
|
|
10669
|
+
fs.writeSync(this.logFd, typeof chunk === "string" ? Buffer.from(chunk, typeof args[1] === "string" ? args[1] : "utf8") : chunk);
|
|
10670
|
+
} catch (error2) {
|
|
10671
|
+
this.diagnosticFailure = error2 instanceof Error ? error2 : new Error(String(error2));
|
|
10672
|
+
}
|
|
10673
|
+
return this.originalWrite.apply(process.stderr, args);
|
|
10674
|
+
});
|
|
10675
|
+
process.stderr.write = this.teeWrite;
|
|
10676
|
+
}
|
|
10677
|
+
persist() {
|
|
10678
|
+
const temporary = this.executionFile + ".tmp";
|
|
10679
|
+
fs.writeFileSync(temporary, JSON.stringify(this.state) + "\n", { encoding: "utf8", flag: "w" });
|
|
10680
|
+
fs.renameSync(temporary, this.executionFile);
|
|
10681
|
+
}
|
|
10682
|
+
checkDiagnostics() {
|
|
10683
|
+
if (this.diagnosticFailure) throw new Error(`Saving diagnostics failed: ${this.diagnosticFailure.message}`);
|
|
10684
|
+
}
|
|
10685
|
+
started(tool) {
|
|
10686
|
+
this.checkDiagnostics();
|
|
10687
|
+
this.state = { ...this.state, ...tool ? { tool } : {}, stage: "tool_call", toolExecution: "unknown" };
|
|
10688
|
+
this.persist();
|
|
10689
|
+
}
|
|
10690
|
+
completed(business, exitCode) {
|
|
10691
|
+
this.checkDiagnostics();
|
|
10692
|
+
this.state = {
|
|
10693
|
+
...this.state,
|
|
10694
|
+
state: exitCode === 0 ? "completed" : "failed",
|
|
10695
|
+
stage: "complete",
|
|
10696
|
+
toolExecution: "response_received",
|
|
10697
|
+
business,
|
|
10698
|
+
exitCode,
|
|
10699
|
+
finishedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10700
|
+
retry: exitCode === 0 ? "none" : "inspect_result_before_retry"
|
|
10701
|
+
};
|
|
10702
|
+
this.persist();
|
|
10703
|
+
}
|
|
10704
|
+
helpDisplayed() {
|
|
10705
|
+
this.checkDiagnostics();
|
|
10706
|
+
this.state = {
|
|
10707
|
+
...this.state,
|
|
10708
|
+
state: "completed",
|
|
10709
|
+
stage: "help",
|
|
10710
|
+
exitCode: 0,
|
|
10711
|
+
finishedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10712
|
+
retry: "none"
|
|
10713
|
+
};
|
|
10714
|
+
this.persist();
|
|
10715
|
+
}
|
|
10716
|
+
failed(stage, toolExecution, business = "not_reported") {
|
|
10717
|
+
this.state = {
|
|
10718
|
+
...this.state,
|
|
10719
|
+
state: "failed",
|
|
10720
|
+
stage,
|
|
10721
|
+
toolExecution,
|
|
10722
|
+
business,
|
|
10723
|
+
exitCode: 1,
|
|
10724
|
+
finishedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10725
|
+
retry: toolExecution === "not_started" ? "fix_input_then_retry" : toolExecution === "response_received" ? "inspect_result_before_retry" : "inspect_state_before_retry"
|
|
10726
|
+
};
|
|
10727
|
+
this.persist();
|
|
10728
|
+
}
|
|
10729
|
+
failedCurrent(stage) {
|
|
10730
|
+
this.failed(stage, this.state.toolExecution, this.state.business);
|
|
10731
|
+
}
|
|
10732
|
+
receiptFields() {
|
|
10733
|
+
return { executionFile: this.executionFile, diagnosticsFile: this.diagnosticsFile };
|
|
10734
|
+
}
|
|
10735
|
+
close() {
|
|
10736
|
+
if (process.stderr.write === this.teeWrite) process.stderr.write = this.originalWrite;
|
|
10737
|
+
fs.closeSync(this.logFd);
|
|
10738
|
+
}
|
|
10739
|
+
};
|
|
10740
|
+
|
|
10741
|
+
// src/cli-usage.ts
|
|
10742
|
+
var COMMON_CALL_HELP = `
|
|
10743
|
+
Input: omitted arguments mean {}; use --args-json for a JSON object or --args-file
|
|
10744
|
+
for nested or shell-sensitive input. Read the current schema with
|
|
10745
|
+
list --tool <name> --json; schema properties are JSON keys, not CLI flags.
|
|
10746
|
+
Output: stdout contains the complete MCP JSON envelope by default. --output-json
|
|
10747
|
+
saves that envelope to a new file and prints a compact receipt. --evidence-dir
|
|
10748
|
+
saves an execution record in a new directory; it cannot be combined with
|
|
10749
|
+
--output-json. Preserve stderr and the CLI exit code before parsing business data.
|
|
10750
|
+
Do not append echo or pipe the command through a parser that can hide its exit.
|
|
10751
|
+
In evidence mode, read execution.json instead of inferring state from a parent shell.
|
|
10752
|
+
Credentials belong in the configured local credential store, never in arguments.
|
|
10753
|
+
`;
|
|
10754
|
+
var INSTALL_CALL_HELP = `Installation: call zlt-runtime-install stays on the
|
|
10755
|
+
same MCP connection through mcp-wait. Keep the command alive and read progress on
|
|
10756
|
+
stderr; component percentages may reset. Installer completion is not runtime
|
|
10757
|
+
readiness. Omit --max-total-timeout-ms unless a hard deadline is required. Timeout,
|
|
10758
|
+
cancellation, or a killed host leaves the outcome unknown; inspect before retrying.`;
|
|
10759
|
+
var BACKTEST_CALL_HELP = `Backtests: create-and-run/re-backtest stay on the
|
|
10760
|
+
same MCP connection through mcp-wait. Progress can remain unchanged while data is
|
|
10761
|
+
prepared; read stderr and do not restart from a progress warning. If isTerminal=true,
|
|
10762
|
+
finalize that run without waiting again. Interrupted waits identify the runId,
|
|
10763
|
+
codePath, and attemptFence for inspection; never restart automatically.`;
|
|
10764
|
+
var REFERENCING_TOOLS = /* @__PURE__ */ new Set(["mcp-get-cache-diff", "mcp-get-cloud-data-list"]);
|
|
10765
|
+
var REFERENCE_SOURCE_TOOL = "mcp-download-data";
|
|
10766
|
+
var REFERENCE_PROPERTY = "exchange_id";
|
|
10767
|
+
function record(value) {
|
|
10768
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
10769
|
+
}
|
|
10770
|
+
function cloneValue(value) {
|
|
10771
|
+
return value === void 0 ? value : JSON.parse(JSON.stringify(value));
|
|
10772
|
+
}
|
|
10773
|
+
function schemaProperty(tool, property) {
|
|
10774
|
+
const schema = record(tool.inputSchema);
|
|
10775
|
+
const properties = record(schema?.properties);
|
|
10776
|
+
const params = record(properties?.params);
|
|
10777
|
+
const items = record(params?.items);
|
|
10778
|
+
const itemProperties = record(items?.properties);
|
|
10779
|
+
return record(itemProperties?.[property]);
|
|
10780
|
+
}
|
|
10781
|
+
var UNSUPPORTED_SCHEMA_KEYWORDS = [
|
|
10782
|
+
"oneOf",
|
|
10783
|
+
"anyOf",
|
|
10784
|
+
"allOf",
|
|
10785
|
+
"not",
|
|
10786
|
+
"if",
|
|
10787
|
+
"then",
|
|
10788
|
+
"else",
|
|
10789
|
+
"minProperties",
|
|
10790
|
+
"maxProperties",
|
|
10791
|
+
"dependentRequired",
|
|
10792
|
+
"dependencies",
|
|
10793
|
+
"patternProperties",
|
|
10794
|
+
"propertyNames",
|
|
10795
|
+
"unevaluatedProperties"
|
|
10796
|
+
];
|
|
10797
|
+
function unsupportedSchemaConstraint(schemaValue, path17 = "inputSchema") {
|
|
10798
|
+
const schema = record(schemaValue);
|
|
10799
|
+
if (!schema) return path17;
|
|
10800
|
+
for (const keyword of UNSUPPORTED_SCHEMA_KEYWORDS) {
|
|
10801
|
+
if (Object.prototype.hasOwnProperty.call(schema, keyword)) return `${path17}.${keyword}`;
|
|
10802
|
+
}
|
|
10803
|
+
const properties = record(schema.properties);
|
|
10804
|
+
if (properties) {
|
|
10805
|
+
for (const [name, property] of Object.entries(properties)) {
|
|
10806
|
+
const unsupported = unsupportedSchemaConstraint(property, `${path17}.properties.${name}`);
|
|
10807
|
+
if (unsupported) return unsupported;
|
|
10808
|
+
}
|
|
10809
|
+
}
|
|
10810
|
+
if (schema.items !== void 0) {
|
|
10811
|
+
const unsupported = unsupportedSchemaConstraint(schema.items, `${path17}.items`);
|
|
10812
|
+
if (unsupported) return unsupported;
|
|
10813
|
+
}
|
|
10814
|
+
return void 0;
|
|
10815
|
+
}
|
|
10816
|
+
function explicitValue(schemaValue, path17) {
|
|
10817
|
+
const schema = record(schemaValue);
|
|
10818
|
+
if (!schema) return { available: false, missing: [path17] };
|
|
10819
|
+
if (Object.prototype.hasOwnProperty.call(schema, "example")) {
|
|
10820
|
+
return { available: true, value: cloneValue(schema.example), missing: [] };
|
|
10821
|
+
}
|
|
10822
|
+
if (Array.isArray(schema.examples) && schema.examples.length > 0) {
|
|
10823
|
+
return { available: true, value: cloneValue(schema.examples[0]), missing: [] };
|
|
10824
|
+
}
|
|
10825
|
+
if (Object.prototype.hasOwnProperty.call(schema, "default")) {
|
|
10826
|
+
return { available: true, value: cloneValue(schema.default), missing: [] };
|
|
10827
|
+
}
|
|
10828
|
+
if (Object.prototype.hasOwnProperty.call(schema, "const")) {
|
|
10829
|
+
return { available: true, value: cloneValue(schema.const), missing: [] };
|
|
10830
|
+
}
|
|
10831
|
+
if (Array.isArray(schema.enum) && schema.enum.length > 0) {
|
|
10832
|
+
return { available: true, value: cloneValue(schema.enum[0]), missing: [] };
|
|
10833
|
+
}
|
|
10834
|
+
if (schema.type === "object") {
|
|
10835
|
+
const properties = record(schema.properties) ?? {};
|
|
10836
|
+
const required2 = Array.isArray(schema.required) ? schema.required.filter((item) => typeof item === "string") : [];
|
|
10837
|
+
const value = {};
|
|
10838
|
+
const missing = [];
|
|
10839
|
+
for (const name of required2) {
|
|
10840
|
+
const child = explicitValue(properties[name], path17 ? `${path17}.${name}` : name);
|
|
10841
|
+
if (child.available) value[name] = child.value;
|
|
10842
|
+
missing.push(...child.missing);
|
|
10843
|
+
}
|
|
10844
|
+
return { available: missing.length === 0, value, missing };
|
|
10845
|
+
}
|
|
10846
|
+
return { available: false, missing: [path17] };
|
|
10847
|
+
}
|
|
10848
|
+
function buildArgumentExample(tool) {
|
|
10849
|
+
const schema = record(tool.inputSchema);
|
|
10850
|
+
const unsupported = unsupportedSchemaConstraint(schema);
|
|
10851
|
+
if (!schema || unsupported) {
|
|
10852
|
+
return {
|
|
10853
|
+
executable: false,
|
|
10854
|
+
arguments: {},
|
|
10855
|
+
missingRequired: [],
|
|
10856
|
+
instruction: `Non-executable template: fill arguments from the complete schema; this helper cannot prove ${unsupported ?? "inputSchema"} is satisfied.`,
|
|
10857
|
+
authorization: "A schema-derived example is documentation only and does not authorize a business operation.",
|
|
10858
|
+
valueSources: "schema example/examples/default/const/enum only"
|
|
10859
|
+
};
|
|
10860
|
+
}
|
|
10861
|
+
const generated = explicitValue(schema, "");
|
|
10862
|
+
const args = record(generated.value) ?? {};
|
|
10863
|
+
if (generated.available) {
|
|
10864
|
+
return {
|
|
10865
|
+
executable: true,
|
|
10866
|
+
arguments: args,
|
|
10867
|
+
authorization: "A schema-derived example is documentation only and does not authorize a business operation.",
|
|
10868
|
+
valueSources: "schema example/examples/default/const/enum only"
|
|
10869
|
+
};
|
|
10870
|
+
}
|
|
10871
|
+
return {
|
|
10872
|
+
executable: false,
|
|
10873
|
+
arguments: args,
|
|
10874
|
+
missingRequired: generated.missing.filter(Boolean),
|
|
10875
|
+
instruction: "Non-executable template: fill the listed required properties from the task; no business value was guessed.",
|
|
10876
|
+
authorization: "A schema-derived example is documentation only and does not authorize a business operation.",
|
|
10877
|
+
valueSources: "schema example/examples/default/const/enum only"
|
|
10878
|
+
};
|
|
10879
|
+
}
|
|
10880
|
+
function relatedParameterHelp(tool, tools) {
|
|
10881
|
+
const name = typeof tool.name === "string" ? tool.name : "";
|
|
10882
|
+
if (!REFERENCING_TOOLS.has(name)) return void 0;
|
|
10883
|
+
const referenced = schemaProperty(tool, REFERENCE_PROPERTY);
|
|
10884
|
+
if (typeof referenced?.description !== "string" || !referenced.description.includes(REFERENCE_SOURCE_TOOL)) return void 0;
|
|
10885
|
+
const source = tools.find((candidate) => candidate.name === REFERENCE_SOURCE_TOOL);
|
|
10886
|
+
const sourceProperty = source && schemaProperty(source, REFERENCE_PROPERTY);
|
|
10887
|
+
if (typeof sourceProperty?.description !== "string" || sourceProperty.description.length === 0) return void 0;
|
|
10888
|
+
return [{
|
|
10889
|
+
sourceTool: REFERENCE_SOURCE_TOOL,
|
|
10890
|
+
property: REFERENCE_PROPERTY,
|
|
10891
|
+
description: sourceProperty.description
|
|
10892
|
+
}];
|
|
10893
|
+
}
|
|
10894
|
+
function buildCliUsage(tool, tools) {
|
|
10895
|
+
const name = typeof tool.name === "string" ? tool.name : "";
|
|
10896
|
+
const usage = {
|
|
10897
|
+
command: `call ${name}`,
|
|
10898
|
+
argumentsOption: "--args-json",
|
|
10899
|
+
argumentsAreCliFlags: false,
|
|
10900
|
+
instruction: "Put tool schema properties inside one JSON object passed to --args-json (or use --args-file). Do not turn properties into --flags.",
|
|
10901
|
+
execution: {
|
|
10902
|
+
argumentsFileOption: "--args-file",
|
|
10903
|
+
schemaCommand: `list --tool ${name} --json`,
|
|
10904
|
+
example: buildArgumentExample(tool)
|
|
10905
|
+
},
|
|
10906
|
+
output: {
|
|
10907
|
+
default: "Read the complete MCP JSON envelope from stdout and preserve stderr and the CLI exit code.",
|
|
10908
|
+
outputJson: {
|
|
10909
|
+
option: "--output-json <new-file>",
|
|
10910
|
+
result: "The complete envelope is saved; stdout is a compact receipt."
|
|
10911
|
+
},
|
|
10912
|
+
evidenceDirectory: {
|
|
10913
|
+
option: "--evidence-dir <new-directory>",
|
|
10914
|
+
mutuallyExclusiveWith: "--output-json",
|
|
10915
|
+
files: {
|
|
10916
|
+
resultJson: "result.json is exclusively reserved before execution. It is parseable only after a complete response is saved; existence alone does not prove a response was received, and disconnects or write failures can leave it empty or partial.",
|
|
10917
|
+
diagnosticsLog: "diagnostics.log captures CLI and child-MCP diagnostics while stderr remains live.",
|
|
10918
|
+
executionJson: "execution.json records state, toolExecution, business outcome, and the CLI exitCode."
|
|
10919
|
+
},
|
|
10920
|
+
states: ["running", "completed", "failed"],
|
|
10921
|
+
toolExecution: ["not_started", "unknown", "response_received"],
|
|
10922
|
+
business: ["success", "error", "not_reported"],
|
|
10923
|
+
boundary: "Use execution.json as the state evidence. Argument syntax errors happen before evidence files are reserved. A force-killed process may leave running and unknown. The CLI cannot record parent-shell or npm failures before it starts. Raw argv and credentials are not recorded."
|
|
10924
|
+
}
|
|
10925
|
+
}
|
|
10926
|
+
};
|
|
10927
|
+
const related = relatedParameterHelp(tool, tools);
|
|
10928
|
+
if (related) usage.relatedParameterHelp = related;
|
|
10929
|
+
if (name === "zlt-runtime-install") usage.lifecycleHelp = INSTALL_CALL_HELP;
|
|
10930
|
+
if (name === "mcp-create-and-run-backtest" || name === "mcp-re-backtest") {
|
|
10931
|
+
usage.lifecycleHelp = BACKTEST_CALL_HELP;
|
|
10932
|
+
}
|
|
10933
|
+
return usage;
|
|
10934
|
+
}
|
|
10935
|
+
|
|
10609
10936
|
// src/index.ts
|
|
10610
|
-
var
|
|
10611
|
-
var
|
|
10937
|
+
var fs16 = __toESM(require("node:fs"), 1);
|
|
10938
|
+
var path16 = __toESM(require("node:path"), 1);
|
|
10612
10939
|
|
|
10613
10940
|
// src/cli.ts
|
|
10614
|
-
var
|
|
10615
|
-
var
|
|
10941
|
+
var fs10 = __toESM(require("fs"), 1);
|
|
10942
|
+
var path10 = __toESM(require("path"), 1);
|
|
10616
10943
|
|
|
10617
10944
|
// ../../../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/core.js
|
|
10618
10945
|
var NEVER = Object.freeze({
|
|
@@ -10809,10 +11136,10 @@ function assignProp(target, prop, value) {
|
|
|
10809
11136
|
configurable: true
|
|
10810
11137
|
});
|
|
10811
11138
|
}
|
|
10812
|
-
function getElementAtPath(obj,
|
|
10813
|
-
if (!
|
|
11139
|
+
function getElementAtPath(obj, path17) {
|
|
11140
|
+
if (!path17)
|
|
10814
11141
|
return obj;
|
|
10815
|
-
return
|
|
11142
|
+
return path17.reduce((acc, key) => acc?.[key], obj);
|
|
10816
11143
|
}
|
|
10817
11144
|
function promiseAllObject(promisesObj) {
|
|
10818
11145
|
const keys = Object.keys(promisesObj);
|
|
@@ -11132,11 +11459,11 @@ function aborted(x, startIndex = 0) {
|
|
|
11132
11459
|
}
|
|
11133
11460
|
return false;
|
|
11134
11461
|
}
|
|
11135
|
-
function prefixIssues(
|
|
11462
|
+
function prefixIssues(path17, issues) {
|
|
11136
11463
|
return issues.map((iss) => {
|
|
11137
11464
|
var _a;
|
|
11138
11465
|
(_a = iss).path ?? (_a.path = []);
|
|
11139
|
-
iss.path.unshift(
|
|
11466
|
+
iss.path.unshift(path17);
|
|
11140
11467
|
return iss;
|
|
11141
11468
|
});
|
|
11142
11469
|
}
|
|
@@ -14153,7 +14480,7 @@ var ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
|
|
|
14153
14480
|
inst.keyType = def.keyType;
|
|
14154
14481
|
inst.valueType = def.valueType;
|
|
14155
14482
|
});
|
|
14156
|
-
function
|
|
14483
|
+
function record2(keyType, valueType, params) {
|
|
14157
14484
|
return new ZodRecord({
|
|
14158
14485
|
type: "record",
|
|
14159
14486
|
keyType,
|
|
@@ -14623,7 +14950,7 @@ var ImplementationSchema = BaseMetadataSchema.extend({
|
|
|
14623
14950
|
});
|
|
14624
14951
|
var FormElicitationCapabilitySchema = intersection(object2({
|
|
14625
14952
|
applyDefaults: boolean2().optional()
|
|
14626
|
-
}),
|
|
14953
|
+
}), record2(string2(), unknown()));
|
|
14627
14954
|
var ElicitationCapabilitySchema = preprocess((value) => {
|
|
14628
14955
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
14629
14956
|
if (Object.keys(value).length === 0) {
|
|
@@ -14634,7 +14961,7 @@ var ElicitationCapabilitySchema = preprocess((value) => {
|
|
|
14634
14961
|
}, intersection(object2({
|
|
14635
14962
|
form: FormElicitationCapabilitySchema.optional(),
|
|
14636
14963
|
url: AssertObjectSchema.optional()
|
|
14637
|
-
}),
|
|
14964
|
+
}), record2(string2(), unknown()).optional()));
|
|
14638
14965
|
var ClientTasksCapabilitySchema = looseObject({
|
|
14639
14966
|
/**
|
|
14640
14967
|
* Present if the client supports listing tasks.
|
|
@@ -14687,7 +15014,7 @@ var ClientCapabilitiesSchema = object2({
|
|
|
14687
15014
|
/**
|
|
14688
15015
|
* Experimental, non-standard capabilities that the client supports.
|
|
14689
15016
|
*/
|
|
14690
|
-
experimental:
|
|
15017
|
+
experimental: record2(string2(), AssertObjectSchema).optional(),
|
|
14691
15018
|
/**
|
|
14692
15019
|
* Present if the client supports sampling from an LLM.
|
|
14693
15020
|
*/
|
|
@@ -14722,7 +15049,7 @@ var ClientCapabilitiesSchema = object2({
|
|
|
14722
15049
|
/**
|
|
14723
15050
|
* Extensions that the client supports. Keys are extension identifiers (vendor-prefix/extension-name).
|
|
14724
15051
|
*/
|
|
14725
|
-
extensions:
|
|
15052
|
+
extensions: record2(string2(), AssertObjectSchema).optional()
|
|
14726
15053
|
});
|
|
14727
15054
|
var InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
14728
15055
|
/**
|
|
@@ -14740,7 +15067,7 @@ var ServerCapabilitiesSchema = object2({
|
|
|
14740
15067
|
/**
|
|
14741
15068
|
* Experimental, non-standard capabilities that the server supports.
|
|
14742
15069
|
*/
|
|
14743
|
-
experimental:
|
|
15070
|
+
experimental: record2(string2(), AssertObjectSchema).optional(),
|
|
14744
15071
|
/**
|
|
14745
15072
|
* Present if the server supports sending log messages to the client.
|
|
14746
15073
|
*/
|
|
@@ -14787,7 +15114,7 @@ var ServerCapabilitiesSchema = object2({
|
|
|
14787
15114
|
/**
|
|
14788
15115
|
* Extensions that the server supports. Keys are extension identifiers (vendor-prefix/extension-name).
|
|
14789
15116
|
*/
|
|
14790
|
-
extensions:
|
|
15117
|
+
extensions: record2(string2(), AssertObjectSchema).optional()
|
|
14791
15118
|
});
|
|
14792
15119
|
var InitializeResultSchema = ResultSchema.extend({
|
|
14793
15120
|
/**
|
|
@@ -14925,7 +15252,7 @@ var ResourceContentsSchema = object2({
|
|
|
14925
15252
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
14926
15253
|
* for notes on _meta usage.
|
|
14927
15254
|
*/
|
|
14928
|
-
_meta:
|
|
15255
|
+
_meta: record2(string2(), unknown()).optional()
|
|
14929
15256
|
});
|
|
14930
15257
|
var TextResourceContentsSchema = ResourceContentsSchema.extend({
|
|
14931
15258
|
/**
|
|
@@ -15119,7 +15446,7 @@ var GetPromptRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
|
15119
15446
|
/**
|
|
15120
15447
|
* Arguments to use for templating the prompt.
|
|
15121
15448
|
*/
|
|
15122
|
-
arguments:
|
|
15449
|
+
arguments: record2(string2(), string2()).optional()
|
|
15123
15450
|
});
|
|
15124
15451
|
var GetPromptRequestSchema = RequestSchema.extend({
|
|
15125
15452
|
method: literal("prompts/get"),
|
|
@@ -15139,7 +15466,7 @@ var TextContentSchema = object2({
|
|
|
15139
15466
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
15140
15467
|
* for notes on _meta usage.
|
|
15141
15468
|
*/
|
|
15142
|
-
_meta:
|
|
15469
|
+
_meta: record2(string2(), unknown()).optional()
|
|
15143
15470
|
});
|
|
15144
15471
|
var ImageContentSchema = object2({
|
|
15145
15472
|
type: literal("image"),
|
|
@@ -15159,7 +15486,7 @@ var ImageContentSchema = object2({
|
|
|
15159
15486
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
15160
15487
|
* for notes on _meta usage.
|
|
15161
15488
|
*/
|
|
15162
|
-
_meta:
|
|
15489
|
+
_meta: record2(string2(), unknown()).optional()
|
|
15163
15490
|
});
|
|
15164
15491
|
var AudioContentSchema = object2({
|
|
15165
15492
|
type: literal("audio"),
|
|
@@ -15179,7 +15506,7 @@ var AudioContentSchema = object2({
|
|
|
15179
15506
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
15180
15507
|
* for notes on _meta usage.
|
|
15181
15508
|
*/
|
|
15182
|
-
_meta:
|
|
15509
|
+
_meta: record2(string2(), unknown()).optional()
|
|
15183
15510
|
});
|
|
15184
15511
|
var ToolUseContentSchema = object2({
|
|
15185
15512
|
type: literal("tool_use"),
|
|
@@ -15197,12 +15524,12 @@ var ToolUseContentSchema = object2({
|
|
|
15197
15524
|
* Arguments to pass to the tool.
|
|
15198
15525
|
* Must conform to the tool's inputSchema.
|
|
15199
15526
|
*/
|
|
15200
|
-
input:
|
|
15527
|
+
input: record2(string2(), unknown()),
|
|
15201
15528
|
/**
|
|
15202
15529
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
15203
15530
|
* for notes on _meta usage.
|
|
15204
15531
|
*/
|
|
15205
|
-
_meta:
|
|
15532
|
+
_meta: record2(string2(), unknown()).optional()
|
|
15206
15533
|
});
|
|
15207
15534
|
var EmbeddedResourceSchema = object2({
|
|
15208
15535
|
type: literal("resource"),
|
|
@@ -15215,7 +15542,7 @@ var EmbeddedResourceSchema = object2({
|
|
|
15215
15542
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
15216
15543
|
* for notes on _meta usage.
|
|
15217
15544
|
*/
|
|
15218
|
-
_meta:
|
|
15545
|
+
_meta: record2(string2(), unknown()).optional()
|
|
15219
15546
|
});
|
|
15220
15547
|
var ResourceLinkSchema = ResourceSchema.extend({
|
|
15221
15548
|
type: literal("resource_link")
|
|
@@ -15305,7 +15632,7 @@ var ToolSchema = object2({
|
|
|
15305
15632
|
*/
|
|
15306
15633
|
inputSchema: object2({
|
|
15307
15634
|
type: literal("object"),
|
|
15308
|
-
properties:
|
|
15635
|
+
properties: record2(string2(), AssertObjectSchema).optional(),
|
|
15309
15636
|
required: array(string2()).optional()
|
|
15310
15637
|
}).catchall(unknown()),
|
|
15311
15638
|
/**
|
|
@@ -15315,7 +15642,7 @@ var ToolSchema = object2({
|
|
|
15315
15642
|
*/
|
|
15316
15643
|
outputSchema: object2({
|
|
15317
15644
|
type: literal("object"),
|
|
15318
|
-
properties:
|
|
15645
|
+
properties: record2(string2(), AssertObjectSchema).optional(),
|
|
15319
15646
|
required: array(string2()).optional()
|
|
15320
15647
|
}).catchall(unknown()).optional(),
|
|
15321
15648
|
/**
|
|
@@ -15330,7 +15657,7 @@ var ToolSchema = object2({
|
|
|
15330
15657
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
15331
15658
|
* for notes on _meta usage.
|
|
15332
15659
|
*/
|
|
15333
|
-
_meta:
|
|
15660
|
+
_meta: record2(string2(), unknown()).optional()
|
|
15334
15661
|
});
|
|
15335
15662
|
var ListToolsRequestSchema = PaginatedRequestSchema.extend({
|
|
15336
15663
|
method: literal("tools/list")
|
|
@@ -15351,7 +15678,7 @@ var CallToolResultSchema = ResultSchema.extend({
|
|
|
15351
15678
|
*
|
|
15352
15679
|
* If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
|
|
15353
15680
|
*/
|
|
15354
|
-
structuredContent:
|
|
15681
|
+
structuredContent: record2(string2(), unknown()).optional(),
|
|
15355
15682
|
/**
|
|
15356
15683
|
* Whether the tool call ended in an error.
|
|
15357
15684
|
*
|
|
@@ -15379,7 +15706,7 @@ var CallToolRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
|
15379
15706
|
/**
|
|
15380
15707
|
* Arguments to pass to the tool.
|
|
15381
15708
|
*/
|
|
15382
|
-
arguments:
|
|
15709
|
+
arguments: record2(string2(), unknown()).optional()
|
|
15383
15710
|
});
|
|
15384
15711
|
var CallToolRequestSchema = RequestSchema.extend({
|
|
15385
15712
|
method: literal("tools/call"),
|
|
@@ -15481,7 +15808,7 @@ var ToolResultContentSchema = object2({
|
|
|
15481
15808
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
15482
15809
|
* for notes on _meta usage.
|
|
15483
15810
|
*/
|
|
15484
|
-
_meta:
|
|
15811
|
+
_meta: record2(string2(), unknown()).optional()
|
|
15485
15812
|
});
|
|
15486
15813
|
var SamplingContentSchema = discriminatedUnion("type", [TextContentSchema, ImageContentSchema, AudioContentSchema]);
|
|
15487
15814
|
var SamplingMessageContentBlockSchema = discriminatedUnion("type", [
|
|
@@ -15498,7 +15825,7 @@ var SamplingMessageSchema = object2({
|
|
|
15498
15825
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
15499
15826
|
* for notes on _meta usage.
|
|
15500
15827
|
*/
|
|
15501
|
-
_meta:
|
|
15828
|
+
_meta: record2(string2(), unknown()).optional()
|
|
15502
15829
|
});
|
|
15503
15830
|
var CreateMessageRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
15504
15831
|
messages: array(SamplingMessageSchema),
|
|
@@ -15686,7 +16013,7 @@ var ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
|
15686
16013
|
*/
|
|
15687
16014
|
requestedSchema: object2({
|
|
15688
16015
|
type: literal("object"),
|
|
15689
|
-
properties:
|
|
16016
|
+
properties: record2(string2(), PrimitiveSchemaDefinitionSchema),
|
|
15690
16017
|
required: array(string2()).optional()
|
|
15691
16018
|
})
|
|
15692
16019
|
});
|
|
@@ -15738,7 +16065,7 @@ var ElicitResultSchema = ResultSchema.extend({
|
|
|
15738
16065
|
* Per MCP spec, content is "typically omitted" for decline/cancel actions.
|
|
15739
16066
|
* We normalize null to undefined for leniency while maintaining type compatibility.
|
|
15740
16067
|
*/
|
|
15741
|
-
content: preprocess((val) => val === null ? void 0 : val,
|
|
16068
|
+
content: preprocess((val) => val === null ? void 0 : val, record2(string2(), union([string2(), number2(), boolean2(), array(string2())])).optional())
|
|
15742
16069
|
});
|
|
15743
16070
|
var ResourceTemplateReferenceSchema = object2({
|
|
15744
16071
|
type: literal("ref/resource"),
|
|
@@ -15773,7 +16100,7 @@ var CompleteRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
|
15773
16100
|
/**
|
|
15774
16101
|
* Previously-resolved variables in a URI template or prompt.
|
|
15775
16102
|
*/
|
|
15776
|
-
arguments:
|
|
16103
|
+
arguments: record2(string2(), string2()).optional()
|
|
15777
16104
|
}).optional()
|
|
15778
16105
|
});
|
|
15779
16106
|
var CompleteRequestSchema = RequestSchema.extend({
|
|
@@ -15809,7 +16136,7 @@ var RootSchema = object2({
|
|
|
15809
16136
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
15810
16137
|
* for notes on _meta usage.
|
|
15811
16138
|
*/
|
|
15812
|
-
_meta:
|
|
16139
|
+
_meta: record2(string2(), unknown()).optional()
|
|
15813
16140
|
});
|
|
15814
16141
|
var ListRootsRequestSchema = RequestSchema.extend({
|
|
15815
16142
|
method: literal("roots/list"),
|
|
@@ -16454,7 +16781,7 @@ var Protocol = class {
|
|
|
16454
16781
|
return;
|
|
16455
16782
|
}
|
|
16456
16783
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
16457
|
-
await new Promise((
|
|
16784
|
+
await new Promise((resolve9) => setTimeout(resolve9, pollInterval));
|
|
16458
16785
|
options?.signal?.throwIfAborted();
|
|
16459
16786
|
}
|
|
16460
16787
|
} catch (error2) {
|
|
@@ -16471,7 +16798,7 @@ var Protocol = class {
|
|
|
16471
16798
|
*/
|
|
16472
16799
|
request(request, resultSchema, options) {
|
|
16473
16800
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
16474
|
-
return new Promise((
|
|
16801
|
+
return new Promise((resolve9, reject) => {
|
|
16475
16802
|
const earlyReject = (error2) => {
|
|
16476
16803
|
reject(error2);
|
|
16477
16804
|
};
|
|
@@ -16549,7 +16876,7 @@ var Protocol = class {
|
|
|
16549
16876
|
if (!parseResult.success) {
|
|
16550
16877
|
reject(parseResult.error);
|
|
16551
16878
|
} else {
|
|
16552
|
-
|
|
16879
|
+
resolve9(parseResult.data);
|
|
16553
16880
|
}
|
|
16554
16881
|
} catch (error2) {
|
|
16555
16882
|
reject(error2);
|
|
@@ -16810,12 +17137,12 @@ var Protocol = class {
|
|
|
16810
17137
|
}
|
|
16811
17138
|
} catch {
|
|
16812
17139
|
}
|
|
16813
|
-
return new Promise((
|
|
17140
|
+
return new Promise((resolve9, reject) => {
|
|
16814
17141
|
if (signal.aborted) {
|
|
16815
17142
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
16816
17143
|
return;
|
|
16817
17144
|
}
|
|
16818
|
-
const timeoutId = setTimeout(
|
|
17145
|
+
const timeoutId = setTimeout(resolve9, interval);
|
|
16819
17146
|
signal.addEventListener("abort", () => {
|
|
16820
17147
|
clearTimeout(timeoutId);
|
|
16821
17148
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -17766,7 +18093,7 @@ var StdioClientTransport = class {
|
|
|
17766
18093
|
if (this._process) {
|
|
17767
18094
|
throw new Error("StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.");
|
|
17768
18095
|
}
|
|
17769
|
-
return new Promise((
|
|
18096
|
+
return new Promise((resolve9, reject) => {
|
|
17770
18097
|
this._process = (0, import_cross_spawn.default)(this._serverParams.command, this._serverParams.args ?? [], {
|
|
17771
18098
|
// merge default env with server env because mcp server needs some env vars
|
|
17772
18099
|
env: {
|
|
@@ -17783,7 +18110,7 @@ var StdioClientTransport = class {
|
|
|
17783
18110
|
this.onerror?.(error2);
|
|
17784
18111
|
});
|
|
17785
18112
|
this._process.on("spawn", () => {
|
|
17786
|
-
|
|
18113
|
+
resolve9();
|
|
17787
18114
|
});
|
|
17788
18115
|
this._process.on("close", (_code) => {
|
|
17789
18116
|
this._process = void 0;
|
|
@@ -17842,22 +18169,22 @@ var StdioClientTransport = class {
|
|
|
17842
18169
|
if (this._process) {
|
|
17843
18170
|
const processToClose = this._process;
|
|
17844
18171
|
this._process = void 0;
|
|
17845
|
-
const closePromise = new Promise((
|
|
18172
|
+
const closePromise = new Promise((resolve9) => {
|
|
17846
18173
|
processToClose.once("close", () => {
|
|
17847
|
-
|
|
18174
|
+
resolve9();
|
|
17848
18175
|
});
|
|
17849
18176
|
});
|
|
17850
18177
|
try {
|
|
17851
18178
|
processToClose.stdin?.end();
|
|
17852
18179
|
} catch {
|
|
17853
18180
|
}
|
|
17854
|
-
await Promise.race([closePromise, new Promise((
|
|
18181
|
+
await Promise.race([closePromise, new Promise((resolve9) => setTimeout(resolve9, 2e3).unref())]);
|
|
17855
18182
|
if (processToClose.exitCode === null) {
|
|
17856
18183
|
try {
|
|
17857
18184
|
processToClose.kill("SIGTERM");
|
|
17858
18185
|
} catch {
|
|
17859
18186
|
}
|
|
17860
|
-
await Promise.race([closePromise, new Promise((
|
|
18187
|
+
await Promise.race([closePromise, new Promise((resolve9) => setTimeout(resolve9, 2e3).unref())]);
|
|
17861
18188
|
}
|
|
17862
18189
|
if (processToClose.exitCode === null) {
|
|
17863
18190
|
try {
|
|
@@ -17869,15 +18196,15 @@ var StdioClientTransport = class {
|
|
|
17869
18196
|
this._readBuffer.clear();
|
|
17870
18197
|
}
|
|
17871
18198
|
send(message) {
|
|
17872
|
-
return new Promise((
|
|
18199
|
+
return new Promise((resolve9) => {
|
|
17873
18200
|
if (!this._process?.stdin) {
|
|
17874
18201
|
throw new Error("Not connected");
|
|
17875
18202
|
}
|
|
17876
18203
|
const json = serializeMessage(message);
|
|
17877
18204
|
if (this._process.stdin.write(json)) {
|
|
17878
|
-
|
|
18205
|
+
resolve9();
|
|
17879
18206
|
} else {
|
|
17880
|
-
this._process.stdin.once("drain",
|
|
18207
|
+
this._process.stdin.once("drain", resolve9);
|
|
17881
18208
|
}
|
|
17882
18209
|
});
|
|
17883
18210
|
}
|
|
@@ -17885,10 +18212,10 @@ var StdioClientTransport = class {
|
|
|
17885
18212
|
|
|
17886
18213
|
// ../zlt-runtime-core/dist/zltaf-ipc.js
|
|
17887
18214
|
var import_node_crypto = require("node:crypto");
|
|
17888
|
-
var
|
|
18215
|
+
var fs2 = __toESM(require("node:fs"), 1);
|
|
17889
18216
|
var net = __toESM(require("node:net"), 1);
|
|
17890
18217
|
var os = __toESM(require("node:os"), 1);
|
|
17891
|
-
var
|
|
18218
|
+
var path2 = __toESM(require("node:path"), 1);
|
|
17892
18219
|
|
|
17893
18220
|
// ../zlt-runtime-core/dist/packet-encoding.js
|
|
17894
18221
|
function decodePacketBody(body) {
|
|
@@ -18056,7 +18383,7 @@ var ZltafHttpPacket = class {
|
|
|
18056
18383
|
}
|
|
18057
18384
|
}
|
|
18058
18385
|
};
|
|
18059
|
-
var LOG_FILE =
|
|
18386
|
+
var LOG_FILE = path2.join(os.tmpdir(), "zlt-mcp-proxy.log");
|
|
18060
18387
|
var pendingLogLines = [];
|
|
18061
18388
|
var logWriteInFlight = false;
|
|
18062
18389
|
function log(tag, message) {
|
|
@@ -18073,7 +18400,7 @@ function flushLogQueue() {
|
|
|
18073
18400
|
logWriteInFlight = true;
|
|
18074
18401
|
const batch = pendingLogLines.splice(0).join("");
|
|
18075
18402
|
try {
|
|
18076
|
-
|
|
18403
|
+
fs2.appendFile(LOG_FILE, batch, "utf8", () => {
|
|
18077
18404
|
logWriteInFlight = false;
|
|
18078
18405
|
flushLogQueue();
|
|
18079
18406
|
});
|
|
@@ -18115,7 +18442,7 @@ var ZltafIpcClient = class {
|
|
|
18115
18442
|
log("CONNECT", "IPC \u8FDE\u63A5\u5EFA\u7ACB\u5B8C\u6210");
|
|
18116
18443
|
}
|
|
18117
18444
|
invoke(uri, params, body = "{}", timeout = 5e3, customHeaders = []) {
|
|
18118
|
-
return new Promise((
|
|
18445
|
+
return new Promise((resolve9, reject) => {
|
|
18119
18446
|
if (!this.workSocket || !this.connected) {
|
|
18120
18447
|
log("INVOKE", `\u8C03\u7528\u5931\u8D25: \u672A\u8FDE\u63A5 (hasSocket=${Boolean(this.workSocket)}, connected=${this.connected})`);
|
|
18121
18448
|
reject(new Error("Not connected"));
|
|
@@ -18142,7 +18469,7 @@ var ZltafIpcClient = class {
|
|
|
18142
18469
|
log("REQ", `seq=${seq} \u8D85\u65F6 (timeout=${timeout}ms)`);
|
|
18143
18470
|
reject(new Error(`RPC timeout for ${uri} (seq=${seq})`));
|
|
18144
18471
|
}, timeout);
|
|
18145
|
-
this.pendingRequests.set(seq, { resolve:
|
|
18472
|
+
this.pendingRequests.set(seq, { resolve: resolve9, reject, timer });
|
|
18146
18473
|
this.workSocket.write(request.generatePacket());
|
|
18147
18474
|
});
|
|
18148
18475
|
}
|
|
@@ -18164,11 +18491,11 @@ var ZltafIpcClient = class {
|
|
|
18164
18491
|
log("DISCONNECT", "\u4E3B\u52A8\u65AD\u5F00\u8FDE\u63A5");
|
|
18165
18492
|
}
|
|
18166
18493
|
connectWorkPipe(pipeName, timeout) {
|
|
18167
|
-
return new Promise((
|
|
18494
|
+
return new Promise((resolve9, reject) => {
|
|
18168
18495
|
const timer = setTimeout(() => reject(new Error(`Work pipe connect timeout: ${pipeName}`)), timeout);
|
|
18169
18496
|
this.workSocket = net.connect(pipeName, () => {
|
|
18170
18497
|
clearTimeout(timer);
|
|
18171
|
-
|
|
18498
|
+
resolve9();
|
|
18172
18499
|
});
|
|
18173
18500
|
this.workSocket.on("error", (error2) => {
|
|
18174
18501
|
clearTimeout(timer);
|
|
@@ -18193,13 +18520,13 @@ var ZltafIpcClient = class {
|
|
|
18193
18520
|
this.onDisconnect?.();
|
|
18194
18521
|
}
|
|
18195
18522
|
connectAndSend(pipePath, data, timeout) {
|
|
18196
|
-
return new Promise((
|
|
18523
|
+
return new Promise((resolve9, reject) => {
|
|
18197
18524
|
const timer = setTimeout(() => {
|
|
18198
18525
|
if (this.mainSocket) {
|
|
18199
18526
|
this.mainSocket.destroy();
|
|
18200
18527
|
this.mainSocket = null;
|
|
18201
18528
|
}
|
|
18202
|
-
|
|
18529
|
+
resolve9(null);
|
|
18203
18530
|
}, timeout);
|
|
18204
18531
|
let responseBuffer = Buffer.alloc(0);
|
|
18205
18532
|
this.mainSocket = net.connect(pipePath, () => this.mainSocket.write(data));
|
|
@@ -18210,7 +18537,7 @@ var ZltafIpcClient = class {
|
|
|
18210
18537
|
clearTimeout(timer);
|
|
18211
18538
|
this.mainSocket.destroy();
|
|
18212
18539
|
this.mainSocket = null;
|
|
18213
|
-
|
|
18540
|
+
resolve9(packet);
|
|
18214
18541
|
}
|
|
18215
18542
|
});
|
|
18216
18543
|
this.mainSocket.on("error", (error2) => {
|
|
@@ -18254,11 +18581,11 @@ __export(config_exports, {
|
|
|
18254
18581
|
resolveDefaultConfigPath: () => resolveDefaultConfigPath,
|
|
18255
18582
|
resolveDefaultRuntimeConfigPath: () => resolveDefaultRuntimeConfigPath
|
|
18256
18583
|
});
|
|
18257
|
-
var
|
|
18258
|
-
var
|
|
18584
|
+
var fs9 = __toESM(require("fs"), 1);
|
|
18585
|
+
var path9 = __toESM(require("path"), 1);
|
|
18259
18586
|
|
|
18260
18587
|
// ../zlt-runtime-core/dist/config.js
|
|
18261
|
-
var
|
|
18588
|
+
var fs3 = __toESM(require("fs"), 1);
|
|
18262
18589
|
var EXDATA_SERVICE_INDEX = 2;
|
|
18263
18590
|
var FACTOR_SERVICE_INDEX = 3;
|
|
18264
18591
|
var SDK_SERVICE_INDEX = 6;
|
|
@@ -18500,7 +18827,7 @@ var defaultAssistantRuntimeConfig = {
|
|
|
18500
18827
|
function loadAssistantRuntimeConfig(configPath) {
|
|
18501
18828
|
if (!configPath)
|
|
18502
18829
|
return applyEnvOverrides(defaultAssistantRuntimeConfig);
|
|
18503
|
-
const raw = JSON.parse(
|
|
18830
|
+
const raw = JSON.parse(fs3.readFileSync(configPath, "utf-8"));
|
|
18504
18831
|
if (!raw.assistant)
|
|
18505
18832
|
return applyEnvOverrides(defaultAssistantRuntimeConfig);
|
|
18506
18833
|
const assistant = raw.assistant;
|
|
@@ -18789,7 +19116,7 @@ function buildPowerShellRegistryArgs() {
|
|
|
18789
19116
|
return ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", READ_REGISTRY_VALUE_SCRIPT];
|
|
18790
19117
|
}
|
|
18791
19118
|
function readRegistryValueWithPowerShell(registryKey, valueName) {
|
|
18792
|
-
return new Promise((
|
|
19119
|
+
return new Promise((resolve9, reject) => {
|
|
18793
19120
|
(0, import_child_process.execFile)(POWERSHELL_EXE, buildPowerShellRegistryArgs(), {
|
|
18794
19121
|
encoding: "utf-8",
|
|
18795
19122
|
env: buildPowerShellRegistryEnvironment(registryKey, valueName),
|
|
@@ -18798,7 +19125,7 @@ function readRegistryValueWithPowerShell(registryKey, valueName) {
|
|
|
18798
19125
|
if (error2)
|
|
18799
19126
|
reject(error2);
|
|
18800
19127
|
else
|
|
18801
|
-
|
|
19128
|
+
resolve9(stdout.trim());
|
|
18802
19129
|
});
|
|
18803
19130
|
});
|
|
18804
19131
|
}
|
|
@@ -18824,8 +19151,8 @@ async function readAssistantRegistryStringValue(config2, valueName, _suppressStd
|
|
|
18824
19151
|
}
|
|
18825
19152
|
|
|
18826
19153
|
// ../zlt-runtime-core/dist/pipe.js
|
|
18827
|
-
var
|
|
18828
|
-
var
|
|
19154
|
+
var fs4 = __toESM(require("fs"), 1);
|
|
19155
|
+
var path3 = __toESM(require("path"), 1);
|
|
18829
19156
|
function matchingPipeNames(entries, prefix) {
|
|
18830
19157
|
const searchPrefix = `${prefix}_`;
|
|
18831
19158
|
const exactResults = [];
|
|
@@ -18846,13 +19173,13 @@ function selectUnambiguousPipeName(entries, prefix) {
|
|
|
18846
19173
|
function enumeratePipeNames(prefix) {
|
|
18847
19174
|
try {
|
|
18848
19175
|
if (process.platform === "win32") {
|
|
18849
|
-
return matchingPipeNames(
|
|
19176
|
+
return matchingPipeNames(fs4.readdirSync("\\\\.\\pipe\\"), prefix);
|
|
18850
19177
|
}
|
|
18851
19178
|
const socketResults = [];
|
|
18852
|
-
for (const name of matchingPipeNames(
|
|
18853
|
-
const fullPath =
|
|
19179
|
+
for (const name of matchingPipeNames(fs4.readdirSync("/tmp"), prefix)) {
|
|
19180
|
+
const fullPath = path3.join("/tmp", name);
|
|
18854
19181
|
try {
|
|
18855
|
-
if (!
|
|
19182
|
+
if (!fs4.statSync(fullPath).isSocket())
|
|
18856
19183
|
continue;
|
|
18857
19184
|
socketResults.push(name);
|
|
18858
19185
|
} catch {
|
|
@@ -18875,26 +19202,26 @@ function toPipeEndpoint(pipeName) {
|
|
|
18875
19202
|
}
|
|
18876
19203
|
function pipeEndpointExists(pipePath) {
|
|
18877
19204
|
try {
|
|
18878
|
-
return
|
|
19205
|
+
return fs4.existsSync(pipePath);
|
|
18879
19206
|
} catch {
|
|
18880
19207
|
return false;
|
|
18881
19208
|
}
|
|
18882
19209
|
}
|
|
18883
19210
|
function readZltHostPipeName(clientRootDir) {
|
|
18884
|
-
let configPath =
|
|
18885
|
-
if (!
|
|
18886
|
-
configPath =
|
|
19211
|
+
let configPath = path3.join(clientRootDir, "zlthost.json");
|
|
19212
|
+
if (!fs4.existsSync(configPath)) {
|
|
19213
|
+
configPath = path3.join(clientRootDir, "zltHost", "zlthost.json");
|
|
18887
19214
|
}
|
|
18888
|
-
if (!
|
|
19215
|
+
if (!fs4.existsSync(configPath))
|
|
18889
19216
|
return null;
|
|
18890
|
-
const parsed = JSON.parse(
|
|
19217
|
+
const parsed = JSON.parse(fs4.readFileSync(configPath, "utf-8"));
|
|
18891
19218
|
return parsed.pipName || null;
|
|
18892
19219
|
}
|
|
18893
19220
|
function readZltPipeSuffix(clientRootDir) {
|
|
18894
|
-
const zltFile =
|
|
18895
|
-
if (!
|
|
19221
|
+
const zltFile = path3.join(clientRootDir, "Temporary", "zlt");
|
|
19222
|
+
if (!fs4.existsSync(zltFile))
|
|
18896
19223
|
return null;
|
|
18897
|
-
return
|
|
19224
|
+
return fs4.readFileSync(zltFile, "utf-8").trim() || null;
|
|
18898
19225
|
}
|
|
18899
19226
|
function resolveInstallPipeName(clientRootDir, pipeName) {
|
|
18900
19227
|
const suffix = readZltPipeSuffix(clientRootDir);
|
|
@@ -18933,9 +19260,9 @@ function pipeExists(clientRootDir, explicitPipeName) {
|
|
|
18933
19260
|
}
|
|
18934
19261
|
|
|
18935
19262
|
// ../zlt-runtime-core/dist/runtime.js
|
|
18936
|
-
var
|
|
19263
|
+
var fs7 = __toESM(require("fs"), 1);
|
|
18937
19264
|
var os2 = __toESM(require("os"), 1);
|
|
18938
|
-
var
|
|
19265
|
+
var path7 = __toESM(require("path"), 1);
|
|
18939
19266
|
var http = __toESM(require("http"), 1);
|
|
18940
19267
|
var https = __toESM(require("https"), 1);
|
|
18941
19268
|
var import_crypto3 = require("crypto");
|
|
@@ -18943,7 +19270,7 @@ var import_child_process3 = require("child_process");
|
|
|
18943
19270
|
|
|
18944
19271
|
// ../zlt-runtime-core/dist/assistant-ipc.js
|
|
18945
19272
|
var net2 = __toESM(require("net"), 1);
|
|
18946
|
-
var
|
|
19273
|
+
var path4 = __toESM(require("path"), 1);
|
|
18947
19274
|
var import_crypto = require("crypto");
|
|
18948
19275
|
var ASSISTANT_CONNECT_MAX_ATTEMPTS = 3;
|
|
18949
19276
|
var ASSISTANT_CONNECT_RETRY_DELAY_MS = 1e3;
|
|
@@ -19199,7 +19526,7 @@ var AssistantMasterIpcClient = class {
|
|
|
19199
19526
|
this.buffer = Buffer.alloc(0);
|
|
19200
19527
|
}
|
|
19201
19528
|
connectMainPipe(pipePath, timeout) {
|
|
19202
|
-
return new Promise((
|
|
19529
|
+
return new Promise((resolve9, reject) => {
|
|
19203
19530
|
const socket = net2.connect(pipePath);
|
|
19204
19531
|
const timer = setTimeout(() => {
|
|
19205
19532
|
socket.destroy();
|
|
@@ -19208,7 +19535,7 @@ var AssistantMasterIpcClient = class {
|
|
|
19208
19535
|
socket.once("connect", () => {
|
|
19209
19536
|
clearTimeout(timer);
|
|
19210
19537
|
this.mainSocket = socket;
|
|
19211
|
-
|
|
19538
|
+
resolve9();
|
|
19212
19539
|
});
|
|
19213
19540
|
socket.once("error", (error2) => {
|
|
19214
19541
|
clearTimeout(timer);
|
|
@@ -19217,7 +19544,7 @@ var AssistantMasterIpcClient = class {
|
|
|
19217
19544
|
});
|
|
19218
19545
|
}
|
|
19219
19546
|
sendHandshake(timeout) {
|
|
19220
|
-
return new Promise((
|
|
19547
|
+
return new Promise((resolve9, reject) => {
|
|
19221
19548
|
if (!this.mainSocket) {
|
|
19222
19549
|
reject(new Error("Assistant master pipe is not connected"));
|
|
19223
19550
|
return;
|
|
@@ -19246,7 +19573,7 @@ var AssistantMasterIpcClient = class {
|
|
|
19246
19573
|
reject(new Error(`Assistant master pipe handshake failed: ${buffer.slice(0, 200)}`));
|
|
19247
19574
|
return;
|
|
19248
19575
|
}
|
|
19249
|
-
|
|
19576
|
+
resolve9();
|
|
19250
19577
|
};
|
|
19251
19578
|
this.mainSocket.on("data", onData);
|
|
19252
19579
|
this.mainSocket.on("error", onError);
|
|
@@ -19262,7 +19589,7 @@ var AssistantMasterIpcClient = class {
|
|
|
19262
19589
|
});
|
|
19263
19590
|
}
|
|
19264
19591
|
connectBusinessPipe(pipePath, timeout) {
|
|
19265
|
-
return new Promise((
|
|
19592
|
+
return new Promise((resolve9, reject) => {
|
|
19266
19593
|
const socket = net2.connect(pipePath);
|
|
19267
19594
|
const timer = setTimeout(() => {
|
|
19268
19595
|
socket.destroy();
|
|
@@ -19273,7 +19600,7 @@ var AssistantMasterIpcClient = class {
|
|
|
19273
19600
|
this.businessSocket = socket;
|
|
19274
19601
|
socket.on("data", (chunk) => this.onBusinessData(chunk));
|
|
19275
19602
|
socket.on("close", () => this.rejectAll(new Error("Assistant business pipe closed")));
|
|
19276
|
-
|
|
19603
|
+
resolve9();
|
|
19277
19604
|
});
|
|
19278
19605
|
socket.once("error", (error2) => {
|
|
19279
19606
|
clearTimeout(timer);
|
|
@@ -19282,7 +19609,7 @@ var AssistantMasterIpcClient = class {
|
|
|
19282
19609
|
});
|
|
19283
19610
|
}
|
|
19284
19611
|
sendRequest(moduleName, funcName, data, timeout) {
|
|
19285
|
-
return new Promise((
|
|
19612
|
+
return new Promise((resolve9, reject) => {
|
|
19286
19613
|
if (!this.businessSocket || !this.connected) {
|
|
19287
19614
|
reject(new Error("Assistant business pipe is not connected"));
|
|
19288
19615
|
return;
|
|
@@ -19305,7 +19632,7 @@ var AssistantMasterIpcClient = class {
|
|
|
19305
19632
|
this.pending.delete(seq);
|
|
19306
19633
|
reject(new Error(`Assistant IPC request timeout: ${moduleName}/${funcName}`));
|
|
19307
19634
|
}, timeout);
|
|
19308
|
-
this.pending.set(seq, { resolve:
|
|
19635
|
+
this.pending.set(seq, { resolve: resolve9, reject, timer });
|
|
19309
19636
|
this.businessSocket.write(request);
|
|
19310
19637
|
});
|
|
19311
19638
|
}
|
|
@@ -19522,18 +19849,18 @@ async function waitForPipe(workRoot, pipePrefix, timeout) {
|
|
|
19522
19849
|
throw new Error(`\u7B49\u5F85 ${pipePrefix} \u7BA1\u9053\u8D85\u65F6`);
|
|
19523
19850
|
}
|
|
19524
19851
|
async function readZltContent(workRoot, temporaryZltFile) {
|
|
19525
|
-
const
|
|
19526
|
-
const
|
|
19527
|
-
const zltFile =
|
|
19528
|
-
return
|
|
19852
|
+
const fs17 = await import("fs");
|
|
19853
|
+
const path17 = await import("path");
|
|
19854
|
+
const zltFile = path17.join(workRoot, temporaryZltFile || "Temporary/zlt");
|
|
19855
|
+
return fs17.existsSync(zltFile) ? fs17.readFileSync(zltFile, "utf-8").trim() : "";
|
|
19529
19856
|
}
|
|
19530
19857
|
async function pipeExists2(pipeName) {
|
|
19531
|
-
const
|
|
19858
|
+
const fs17 = await import("fs");
|
|
19532
19859
|
try {
|
|
19533
19860
|
if (process.platform === "win32") {
|
|
19534
|
-
return
|
|
19861
|
+
return fs17.readdirSync("\\\\.\\pipe\\").includes(pipeName);
|
|
19535
19862
|
}
|
|
19536
|
-
return
|
|
19863
|
+
return fs17.existsSync(`/tmp/${pipeName}`);
|
|
19537
19864
|
} catch {
|
|
19538
19865
|
return false;
|
|
19539
19866
|
}
|
|
@@ -19623,7 +19950,7 @@ function isUpgradeBusyError(message) {
|
|
|
19623
19950
|
}
|
|
19624
19951
|
function isRecoverableTyCodeCoverFailure(message, workRoot) {
|
|
19625
19952
|
const normalizedMessage = message.replaceAll("/", "\\").toLowerCase();
|
|
19626
|
-
const managedCodePath =
|
|
19953
|
+
const managedCodePath = path4.join(workRoot, "vscode", "Code.exe").toLowerCase();
|
|
19627
19954
|
return normalizedMessage.includes("\u521B\u5EFA\u89E3\u538B\u76EE\u6807\u6587\u4EF6") && normalizedMessage.includes(managedCodePath) && normalizedMessage.includes("\u5931\u8D25");
|
|
19628
19955
|
}
|
|
19629
19956
|
function isClientCoverBoundaryError(message) {
|
|
@@ -19661,17 +19988,17 @@ function formatModuleInstallError(message, moduleIndex, progress) {
|
|
|
19661
19988
|
return `${message}: moduleIndex=${moduleIndex}, status=${progress.status}, phase=${progress.phase}, process=${progress.process}, response=${JSON.stringify(progress.response)}`;
|
|
19662
19989
|
}
|
|
19663
19990
|
function sleep(ms) {
|
|
19664
|
-
return new Promise((
|
|
19991
|
+
return new Promise((resolve9) => setTimeout(resolve9, ms));
|
|
19665
19992
|
}
|
|
19666
19993
|
|
|
19667
19994
|
// ../zlt-runtime-core/dist/runtime-lifecycle.js
|
|
19668
|
-
var
|
|
19669
|
-
var
|
|
19995
|
+
var fs5 = __toESM(require("fs"), 1);
|
|
19996
|
+
var path5 = __toESM(require("path"), 1);
|
|
19670
19997
|
var import_crypto2 = require("crypto");
|
|
19671
19998
|
var import_child_process2 = require("child_process");
|
|
19672
19999
|
var LOCK_WAIT_MS = 1e4;
|
|
19673
20000
|
var LOCK_RETRY_MS = 100;
|
|
19674
|
-
var STATE_RELATIVE_PATH =
|
|
20001
|
+
var STATE_RELATIVE_PATH = path5.join("Temporary", "zlt-mcp-runtime");
|
|
19675
20002
|
async function acquireRuntimeLease(workRoot, role, options = {}) {
|
|
19676
20003
|
const deps = options.deps ?? defaultRuntimeLifecycleDeps;
|
|
19677
20004
|
return withLifecycleLock(workRoot, deps, async (stateDir) => {
|
|
@@ -19696,7 +20023,7 @@ async function acquireRuntimeLease(workRoot, role, options = {}) {
|
|
|
19696
20023
|
}
|
|
19697
20024
|
}
|
|
19698
20025
|
const handle = {
|
|
19699
|
-
workRoot:
|
|
20026
|
+
workRoot: path5.resolve(workRoot),
|
|
19700
20027
|
token: deps.randomToken(),
|
|
19701
20028
|
holder: deps.currentProcess(),
|
|
19702
20029
|
role
|
|
@@ -19749,9 +20076,9 @@ async function updateRuntimeLeaseActiveJob(handle, runId, active2, options = {})
|
|
|
19749
20076
|
async function releaseRuntimeLease(handle, options = {}) {
|
|
19750
20077
|
const deps = options.deps ?? defaultRuntimeLifecycleDeps;
|
|
19751
20078
|
return withLifecycleLock(handle.workRoot, deps, async (stateDir) => {
|
|
19752
|
-
const
|
|
19753
|
-
if (
|
|
19754
|
-
|
|
20079
|
+
const record4 = readJson(leasePath(stateDir, handle.token));
|
|
20080
|
+
if (record4 && sameIdentity(record4.holder, handle.holder)) {
|
|
20081
|
+
fs5.rmSync(leasePath(stateDir, handle.token), { force: true });
|
|
19755
20082
|
}
|
|
19756
20083
|
const recordedOwner = readJson(ownerPath(stateDir));
|
|
19757
20084
|
const store = readAndPruneStore(stateDir, deps);
|
|
@@ -19765,19 +20092,19 @@ async function releaseRuntimeLease(handle, options = {}) {
|
|
|
19765
20092
|
}
|
|
19766
20093
|
const current = deps.inspectProcess(store.owner.process.pid);
|
|
19767
20094
|
if (!current || !sameIdentity(current, store.owner.process)) {
|
|
19768
|
-
|
|
20095
|
+
fs5.rmSync(ownerPath(stateDir), { force: true });
|
|
19769
20096
|
return { stopped: false, reason: "owner-mismatch" };
|
|
19770
20097
|
}
|
|
19771
20098
|
assertOwnedZltafIdentity(handle.workRoot, current);
|
|
19772
20099
|
deps.terminateProcess(current);
|
|
19773
|
-
|
|
20100
|
+
fs5.rmSync(ownerPath(stateDir), { force: true });
|
|
19774
20101
|
return { stopped: true, reason: "stopped" };
|
|
19775
20102
|
});
|
|
19776
20103
|
}
|
|
19777
20104
|
function inspectRuntimeProcess(pid) {
|
|
19778
20105
|
if (process.platform !== "win32" || !Number.isInteger(pid) || pid <= 0)
|
|
19779
20106
|
return null;
|
|
19780
|
-
const powershell =
|
|
20107
|
+
const powershell = path5.join(process.env.SystemRoot || "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
19781
20108
|
const command = [
|
|
19782
20109
|
'$p = Get-CimInstance Win32_Process -Filter "ProcessId=$env:ZLT_RUNTIME_PID" -ErrorAction SilentlyContinue',
|
|
19783
20110
|
"if ($p) { [pscustomobject]@{ pid=[int]$p.ProcessId; executablePath=[string]$p.ExecutablePath; creationTime=$p.CreationDate.ToUniversalTime().ToString('o') } | ConvertTo-Json -Compress }"
|
|
@@ -19806,7 +20133,7 @@ var defaultRuntimeLifecycleDeps = {
|
|
|
19806
20133
|
},
|
|
19807
20134
|
inspectProcess: inspectRuntimeProcess,
|
|
19808
20135
|
terminateProcess: (identity) => {
|
|
19809
|
-
const powershell =
|
|
20136
|
+
const powershell = path5.join(process.env.SystemRoot || "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
19810
20137
|
const command = [
|
|
19811
20138
|
'$p = Get-CimInstance Win32_Process -Filter "ProcessId=$env:ZLT_RUNTIME_PID" -ErrorAction SilentlyContinue',
|
|
19812
20139
|
"if (-not $p) { exit 3 }",
|
|
@@ -19833,12 +20160,12 @@ var defaultRuntimeLifecycleDeps = {
|
|
|
19833
20160
|
},
|
|
19834
20161
|
randomToken: import_crypto2.randomUUID,
|
|
19835
20162
|
now: Date.now,
|
|
19836
|
-
sleep: (ms) => new Promise((
|
|
20163
|
+
sleep: (ms) => new Promise((resolve9) => setTimeout(resolve9, ms))
|
|
19837
20164
|
};
|
|
19838
20165
|
async function withLifecycleLock(workRoot, deps, action) {
|
|
19839
20166
|
const stateDir = stateDirectory(workRoot);
|
|
19840
|
-
|
|
19841
|
-
const lockPath =
|
|
20167
|
+
fs5.mkdirSync(path5.join(stateDir, "leases"), { recursive: true });
|
|
20168
|
+
const lockPath = path5.join(stateDir, "lifecycle.lock");
|
|
19842
20169
|
const lock = {
|
|
19843
20170
|
token: deps.randomToken(),
|
|
19844
20171
|
holder: deps.currentProcess(),
|
|
@@ -19847,11 +20174,11 @@ async function withLifecycleLock(workRoot, deps, action) {
|
|
|
19847
20174
|
const deadline = deps.now() + LOCK_WAIT_MS;
|
|
19848
20175
|
while (true) {
|
|
19849
20176
|
try {
|
|
19850
|
-
const descriptor =
|
|
20177
|
+
const descriptor = fs5.openSync(lockPath, "wx");
|
|
19851
20178
|
try {
|
|
19852
|
-
|
|
20179
|
+
fs5.writeFileSync(descriptor, JSON.stringify(lock), "utf8");
|
|
19853
20180
|
} finally {
|
|
19854
|
-
|
|
20181
|
+
fs5.closeSync(descriptor);
|
|
19855
20182
|
}
|
|
19856
20183
|
break;
|
|
19857
20184
|
} catch (error2) {
|
|
@@ -19879,9 +20206,9 @@ async function withLifecycleLock(workRoot, deps, action) {
|
|
|
19879
20206
|
}
|
|
19880
20207
|
function readLifecycleLock(lockPath) {
|
|
19881
20208
|
try {
|
|
19882
|
-
const before =
|
|
19883
|
-
const raw =
|
|
19884
|
-
const after =
|
|
20209
|
+
const before = fs5.statSync(lockPath);
|
|
20210
|
+
const raw = fs5.readFileSync(lockPath);
|
|
20211
|
+
const after = fs5.statSync(lockPath);
|
|
19885
20212
|
if (before.mtimeMs !== after.mtimeMs || before.size !== after.size)
|
|
19886
20213
|
return null;
|
|
19887
20214
|
return {
|
|
@@ -19911,14 +20238,14 @@ function sameLifecycleLockIdentity(left, right) {
|
|
|
19911
20238
|
function restoreMovedLifecycleLock(movedPath, lockPath) {
|
|
19912
20239
|
let restored = false;
|
|
19913
20240
|
try {
|
|
19914
|
-
|
|
20241
|
+
fs5.linkSync(movedPath, lockPath);
|
|
19915
20242
|
restored = true;
|
|
19916
20243
|
} catch (error2) {
|
|
19917
20244
|
if (error2.code === "EEXIST") {
|
|
19918
20245
|
restored = true;
|
|
19919
20246
|
} else {
|
|
19920
20247
|
try {
|
|
19921
|
-
|
|
20248
|
+
fs5.copyFileSync(movedPath, lockPath, fs5.constants.COPYFILE_EXCL);
|
|
19922
20249
|
restored = true;
|
|
19923
20250
|
} catch (restoreError) {
|
|
19924
20251
|
if (restoreError.code === "EEXIST")
|
|
@@ -19927,12 +20254,12 @@ function restoreMovedLifecycleLock(movedPath, lockPath) {
|
|
|
19927
20254
|
}
|
|
19928
20255
|
}
|
|
19929
20256
|
if (restored)
|
|
19930
|
-
|
|
20257
|
+
fs5.rmSync(movedPath, { force: true });
|
|
19931
20258
|
}
|
|
19932
20259
|
function retireLifecycleLockIfUnchanged(lockPath, expected) {
|
|
19933
20260
|
const movedPath = `${lockPath}.${process.pid}.${(0, import_crypto2.randomUUID)()}.retired`;
|
|
19934
20261
|
try {
|
|
19935
|
-
|
|
20262
|
+
fs5.renameSync(lockPath, movedPath);
|
|
19936
20263
|
} catch (error2) {
|
|
19937
20264
|
if (error2.code === "ENOENT")
|
|
19938
20265
|
return false;
|
|
@@ -19943,49 +20270,49 @@ function retireLifecycleLockIfUnchanged(lockPath, expected) {
|
|
|
19943
20270
|
restoreMovedLifecycleLock(movedPath, lockPath);
|
|
19944
20271
|
return false;
|
|
19945
20272
|
}
|
|
19946
|
-
|
|
20273
|
+
fs5.rmSync(movedPath, { force: true });
|
|
19947
20274
|
return true;
|
|
19948
20275
|
}
|
|
19949
20276
|
function readAndPruneStore(stateDir, deps) {
|
|
19950
|
-
const leasesDir =
|
|
20277
|
+
const leasesDir = path5.join(stateDir, "leases");
|
|
19951
20278
|
const leases = [];
|
|
19952
|
-
for (const entry of
|
|
20279
|
+
for (const entry of fs5.readdirSync(leasesDir, { withFileTypes: true })) {
|
|
19953
20280
|
if (!entry.isFile() || !entry.name.endsWith(".json"))
|
|
19954
20281
|
continue;
|
|
19955
|
-
const filePath =
|
|
19956
|
-
const
|
|
19957
|
-
const current =
|
|
19958
|
-
if (!
|
|
19959
|
-
|
|
20282
|
+
const filePath = path5.join(leasesDir, entry.name);
|
|
20283
|
+
const record4 = readJson(filePath);
|
|
20284
|
+
const current = record4 ? deps.inspectProcess(record4.holder.pid) : null;
|
|
20285
|
+
if (!record4 || !current || !sameIdentity(current, record4.holder)) {
|
|
20286
|
+
fs5.rmSync(filePath, { force: true });
|
|
19960
20287
|
continue;
|
|
19961
20288
|
}
|
|
19962
|
-
leases.push(
|
|
20289
|
+
leases.push(record4);
|
|
19963
20290
|
}
|
|
19964
20291
|
let owner = normalizeRuntimeOwnerRecord(readJson(ownerPath(stateDir)));
|
|
19965
20292
|
if (owner) {
|
|
19966
20293
|
const current = deps.inspectProcess(owner.process.pid);
|
|
19967
20294
|
if (!current || !sameIdentity(current, owner.process)) {
|
|
19968
|
-
|
|
20295
|
+
fs5.rmSync(ownerPath(stateDir), { force: true });
|
|
19969
20296
|
owner = null;
|
|
19970
20297
|
}
|
|
19971
20298
|
}
|
|
19972
20299
|
return { owner, leases };
|
|
19973
20300
|
}
|
|
19974
|
-
function normalizeRuntimeOwnerRecord(
|
|
19975
|
-
if (!
|
|
20301
|
+
function normalizeRuntimeOwnerRecord(record4) {
|
|
20302
|
+
if (!record4)
|
|
19976
20303
|
return null;
|
|
19977
|
-
const activeJobIds = new Set(normalizeRunIds(
|
|
19978
|
-
const legacyBoundJobIds = normalizeRunIds(
|
|
19979
|
-
const legacyResolvedJobIds = new Set(normalizeRunIds(
|
|
20304
|
+
const activeJobIds = new Set(normalizeRunIds(record4.activeJobIds));
|
|
20305
|
+
const legacyBoundJobIds = normalizeRunIds(record4.legacyBoundJobIds);
|
|
20306
|
+
const legacyResolvedJobIds = new Set(normalizeRunIds(record4.legacyResolvedJobIds));
|
|
19980
20307
|
for (const runId of legacyBoundJobIds) {
|
|
19981
20308
|
activeJobIds.add(runId);
|
|
19982
20309
|
legacyResolvedJobIds.delete(runId);
|
|
19983
20310
|
}
|
|
19984
20311
|
return {
|
|
19985
|
-
process:
|
|
19986
|
-
startedAt:
|
|
20312
|
+
process: record4.process,
|
|
20313
|
+
startedAt: record4.startedAt,
|
|
19987
20314
|
activeJobIds: [...activeJobIds].sort(),
|
|
19988
|
-
legacyActiveJobs:
|
|
20315
|
+
legacyActiveJobs: record4.legacyActiveJobs === void 0 ? normalizeLegacyActiveJobs(record4.activeJobs) : normalizeLegacyActiveJobs(record4.legacyActiveJobs),
|
|
19989
20316
|
legacyBoundJobIds,
|
|
19990
20317
|
legacyResolvedJobIds: [...legacyResolvedJobIds].sort()
|
|
19991
20318
|
};
|
|
@@ -20001,24 +20328,24 @@ function normalizeLegacyActiveJobs(value) {
|
|
|
20001
20328
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.trunc(value) : 0;
|
|
20002
20329
|
}
|
|
20003
20330
|
function stateDirectory(workRoot) {
|
|
20004
|
-
const resolvedRoot =
|
|
20005
|
-
const stateDir =
|
|
20006
|
-
const prefix = `${resolvedRoot}${
|
|
20331
|
+
const resolvedRoot = path5.resolve(workRoot);
|
|
20332
|
+
const stateDir = path5.resolve(resolvedRoot, STATE_RELATIVE_PATH);
|
|
20333
|
+
const prefix = `${resolvedRoot}${path5.sep}`.toLowerCase();
|
|
20007
20334
|
if (!stateDir.toLowerCase().startsWith(prefix))
|
|
20008
20335
|
throw new Error(`runtime lifecycle path \u8D8A\u754C: ${stateDir}`);
|
|
20009
20336
|
return stateDir;
|
|
20010
20337
|
}
|
|
20011
20338
|
function assertOwnedZltafIdentity(workRoot, identity) {
|
|
20012
|
-
const expected =
|
|
20013
|
-
if (
|
|
20339
|
+
const expected = path5.resolve(workRoot, "zltaf", "zltaf.exe");
|
|
20340
|
+
if (path5.resolve(identity.executablePath).toLowerCase() !== expected.toLowerCase()) {
|
|
20014
20341
|
throw new Error(`\u62D2\u7EDD\u7BA1\u7406\u975E\u76EE\u6807 ZLTAF \u8FDB\u7A0B: ${identity.executablePath}`);
|
|
20015
20342
|
}
|
|
20016
20343
|
}
|
|
20017
20344
|
function sameIdentity(left, right) {
|
|
20018
|
-
return left.pid === right.pid &&
|
|
20345
|
+
return left.pid === right.pid && path5.resolve(left.executablePath).toLowerCase() === path5.resolve(right.executablePath).toLowerCase() && left.creationTime === right.creationTime;
|
|
20019
20346
|
}
|
|
20020
20347
|
function ownerPath(stateDir) {
|
|
20021
|
-
return
|
|
20348
|
+
return path5.join(stateDir, "owner.json");
|
|
20022
20349
|
}
|
|
20023
20350
|
function writeRuntimeOwnerRecord(stateDir, owner) {
|
|
20024
20351
|
writeJson(ownerPath(stateDir), {
|
|
@@ -20029,24 +20356,24 @@ function writeRuntimeOwnerRecord(stateDir, owner) {
|
|
|
20029
20356
|
function leasePath(stateDir, token) {
|
|
20030
20357
|
if (!/^[A-Za-z0-9-]+$/.test(token))
|
|
20031
20358
|
throw new Error(`\u975E\u6CD5 runtime lease token: ${token}`);
|
|
20032
|
-
return
|
|
20359
|
+
return path5.join(stateDir, "leases", `${token}.json`);
|
|
20033
20360
|
}
|
|
20034
20361
|
function readJson(filePath) {
|
|
20035
20362
|
try {
|
|
20036
|
-
return JSON.parse(
|
|
20363
|
+
return JSON.parse(fs5.readFileSync(filePath, "utf8"));
|
|
20037
20364
|
} catch {
|
|
20038
20365
|
return null;
|
|
20039
20366
|
}
|
|
20040
20367
|
}
|
|
20041
20368
|
function writeJson(filePath, value) {
|
|
20042
20369
|
const temporary = `${filePath}.${process.pid}.${(0, import_crypto2.randomUUID)()}.tmp`;
|
|
20043
|
-
|
|
20044
|
-
|
|
20370
|
+
fs5.writeFileSync(temporary, JSON.stringify(value), "utf8");
|
|
20371
|
+
fs5.renameSync(temporary, filePath);
|
|
20045
20372
|
}
|
|
20046
20373
|
|
|
20047
20374
|
// ../zlt-runtime-core/dist/assistant-base-upgrade.js
|
|
20048
|
-
var
|
|
20049
|
-
var
|
|
20375
|
+
var fs6 = __toESM(require("fs"), 1);
|
|
20376
|
+
var path6 = __toESM(require("path"), 1);
|
|
20050
20377
|
|
|
20051
20378
|
// ../zlt-runtime-core/dist/version-gates.js
|
|
20052
20379
|
function versionGatesDisabled() {
|
|
@@ -20060,7 +20387,7 @@ var requirementCache = /* @__PURE__ */ new Map();
|
|
|
20060
20387
|
var requirementInFlight = /* @__PURE__ */ new Map();
|
|
20061
20388
|
function readInstalledAssistantBaseVersion(workRoot) {
|
|
20062
20389
|
try {
|
|
20063
|
-
const content =
|
|
20390
|
+
const content = fs6.readFileSync(path6.join(workRoot, INSTALL_INFO_FILE), "utf-8");
|
|
20064
20391
|
const matched = content.match(/<InstallAppReleaseVer>(.*?)<\/InstallAppReleaseVer>/i);
|
|
20065
20392
|
const version2 = matched?.[1]?.trim();
|
|
20066
20393
|
return version2 ? version2 : null;
|
|
@@ -20200,12 +20527,12 @@ var MANAGED_PROCESS_EXIT_INTERVAL_MS = 200;
|
|
|
20200
20527
|
var MANAGED_PROCESS_RESPAWN_RETRY_ROUNDS = 3;
|
|
20201
20528
|
function getDefaultInstallPath() {
|
|
20202
20529
|
if (process.platform === "win32") {
|
|
20203
|
-
return
|
|
20530
|
+
return fs7.existsSync("D:\\") ? "D:\\ZLTClient" : "C:\\ZLTClient";
|
|
20204
20531
|
}
|
|
20205
|
-
return
|
|
20532
|
+
return path7.join(os2.homedir(), "ZLTClient");
|
|
20206
20533
|
}
|
|
20207
20534
|
function validateWorkRootComplete(workRoot, _config) {
|
|
20208
|
-
if (!
|
|
20535
|
+
if (!fs7.existsSync(workRoot)) {
|
|
20209
20536
|
return { complete: false, reason: `\u5DE5\u7A0B\u8DEF\u5F84\u4E0D\u5B58\u5728: ${workRoot}` };
|
|
20210
20537
|
}
|
|
20211
20538
|
const requiredPaths = [
|
|
@@ -20213,17 +20540,17 @@ function validateWorkRootComplete(workRoot, _config) {
|
|
|
20213
20540
|
{ label: "ZLTAF \u914D\u7F6E", filePath: getZltafConfigPath(workRoot) }
|
|
20214
20541
|
];
|
|
20215
20542
|
for (const item of requiredPaths) {
|
|
20216
|
-
if (!
|
|
20543
|
+
if (!fs7.existsSync(item.filePath)) {
|
|
20217
20544
|
return { complete: false, reason: `\u7F3A\u5C11${item.label}: ${item.filePath}` };
|
|
20218
20545
|
}
|
|
20219
20546
|
}
|
|
20220
20547
|
return { complete: true };
|
|
20221
20548
|
}
|
|
20222
20549
|
function validateAssistantBaseComplete(workRoot, config2) {
|
|
20223
|
-
if (!
|
|
20550
|
+
if (!fs7.existsSync(workRoot))
|
|
20224
20551
|
return { complete: false, reason: `\u5DE5\u7A0B\u8DEF\u5F84\u4E0D\u5B58\u5728: ${workRoot}` };
|
|
20225
|
-
const hostPath =
|
|
20226
|
-
return
|
|
20552
|
+
const hostPath = path7.join(workRoot, config2.hostPath);
|
|
20553
|
+
return fs7.existsSync(hostPath) ? { complete: true } : { complete: false, reason: `\u7F3A\u5C11\u667A\u80FD\u7BA1\u5BB6\u7A0B\u5E8F: ${hostPath}` };
|
|
20227
20554
|
}
|
|
20228
20555
|
function validateDependencyWorkRootComplete(workRoot, config2) {
|
|
20229
20556
|
const launchReady = validateRuntimeLaunchReady(workRoot, config2);
|
|
@@ -20240,21 +20567,21 @@ function validateRuntimeLaunchReady(workRoot, config2) {
|
|
|
20240
20567
|
{ label: "MinGit \u7A0B\u5E8F", filePath: getGitExePath(workRoot) }
|
|
20241
20568
|
];
|
|
20242
20569
|
for (const item of requiredPaths) {
|
|
20243
|
-
if (!
|
|
20570
|
+
if (!fs7.existsSync(item.filePath)) {
|
|
20244
20571
|
return { complete: false, reason: `\u7F3A\u5C11${item.label}: ${item.filePath}` };
|
|
20245
20572
|
}
|
|
20246
20573
|
}
|
|
20247
20574
|
return { complete: true };
|
|
20248
20575
|
}
|
|
20249
20576
|
function ensureUsersProjectsDirectory(workRoot) {
|
|
20250
|
-
const projectsDir =
|
|
20251
|
-
if (
|
|
20252
|
-
if (!
|
|
20577
|
+
const projectsDir = path7.join(workRoot, "Users", "projects");
|
|
20578
|
+
if (fs7.existsSync(projectsDir)) {
|
|
20579
|
+
if (!fs7.statSync(projectsDir).isDirectory()) {
|
|
20253
20580
|
throw new Error(`Users\\projects \u8DEF\u5F84\u5DF2\u5B58\u5728\u4F46\u4E0D\u662F\u76EE\u5F55: ${projectsDir}`);
|
|
20254
20581
|
}
|
|
20255
20582
|
return projectsDir;
|
|
20256
20583
|
}
|
|
20257
|
-
|
|
20584
|
+
fs7.mkdirSync(projectsDir, { recursive: true });
|
|
20258
20585
|
return projectsDir;
|
|
20259
20586
|
}
|
|
20260
20587
|
async function readRegistryInstallLocation(config2) {
|
|
@@ -20293,7 +20620,7 @@ async function resolveRuntimeRoot(config2, options = {}) {
|
|
|
20293
20620
|
const workRoot = candidate?.trim();
|
|
20294
20621
|
if (!workRoot)
|
|
20295
20622
|
continue;
|
|
20296
|
-
const key =
|
|
20623
|
+
const key = path7.resolve(workRoot).toLowerCase();
|
|
20297
20624
|
if (seen.has(key))
|
|
20298
20625
|
continue;
|
|
20299
20626
|
seen.add(key);
|
|
@@ -20336,7 +20663,7 @@ async function runDoctor(config2, options = {}) {
|
|
|
20336
20663
|
}
|
|
20337
20664
|
const assistant = workRoot ? validateWorkRootComplete(workRoot, config2) : { complete: false, reason: "\u672A\u53D1\u73B0\u53EF\u7528 InstallLocation" };
|
|
20338
20665
|
const dependency = workRoot ? validateDependencyWorkRootComplete(workRoot, config2) : { complete: false, reason: "\u672A\u53D1\u73B0\u53EF\u7528 InstallLocation" };
|
|
20339
|
-
const zltFile = workRoot ?
|
|
20666
|
+
const zltFile = workRoot ? path7.join(workRoot, config2.temporaryZltFile) : void 0;
|
|
20340
20667
|
let pipePath;
|
|
20341
20668
|
let ipcReachable = false;
|
|
20342
20669
|
const explicitPipeName = process.env.ZLT_PIPE_NAME?.trim();
|
|
@@ -20378,20 +20705,20 @@ async function runDoctor(config2, options = {}) {
|
|
|
20378
20705
|
}
|
|
20379
20706
|
function startZltafRuntime(workRoot, config2) {
|
|
20380
20707
|
const zltafPath = getZltafExePath(workRoot);
|
|
20381
|
-
if (!
|
|
20708
|
+
if (!fs7.existsSync(zltafPath)) {
|
|
20382
20709
|
throw new Error(`ZLTAF \u7A0B\u5E8F\u4E0D\u5B58\u5728: ${zltafPath}`);
|
|
20383
20710
|
}
|
|
20384
20711
|
const configPath = resolveZltafLaunchConfigPath(workRoot, config2);
|
|
20385
|
-
if (!
|
|
20712
|
+
if (!fs7.existsSync(configPath)) {
|
|
20386
20713
|
throw new Error(`ZLTAF \u914D\u7F6E\u4E0D\u5B58\u5728: ${configPath}`);
|
|
20387
20714
|
}
|
|
20388
|
-
const tmpDir =
|
|
20389
|
-
|
|
20715
|
+
const tmpDir = path7.join(workRoot, "zltaf", "tmp");
|
|
20716
|
+
fs7.mkdirSync(tmpDir, { recursive: true });
|
|
20390
20717
|
const child = (0, import_child_process3.spawn)(zltafPath, [
|
|
20391
20718
|
`-Dconfig.path=${configPath}`,
|
|
20392
20719
|
`-Djava.io.tmpdir=${tmpDir}`
|
|
20393
20720
|
], {
|
|
20394
|
-
cwd:
|
|
20721
|
+
cwd: path7.dirname(zltafPath),
|
|
20395
20722
|
detached: true,
|
|
20396
20723
|
stdio: "ignore",
|
|
20397
20724
|
windowsHide: true
|
|
@@ -20452,15 +20779,15 @@ async function ensureAssistantHostRunning(workRoot, config2, onProgress, options
|
|
|
20452
20779
|
if (zltContent && masterPipeExists(zltContent))
|
|
20453
20780
|
return zltContent;
|
|
20454
20781
|
}
|
|
20455
|
-
throw new Error(`\u7B49\u5F85\u667A\u80FD\u7BA1\u5BB6 IPC \u914D\u7F6E\u8D85\u65F6\uFF08\u540E\u7F00\u6587\u4EF6\u6216\u4E3B\u7BA1\u9053\u672A\u5C31\u7EEA\uFF09: ${
|
|
20782
|
+
throw new Error(`\u7B49\u5F85\u667A\u80FD\u7BA1\u5BB6 IPC \u914D\u7F6E\u8D85\u65F6\uFF08\u540E\u7F00\u6587\u4EF6\u6216\u4E3B\u7BA1\u9053\u672A\u5C31\u7EEA\uFF09: ${path7.join(workRoot, config2.temporaryZltFile)}`);
|
|
20456
20783
|
}
|
|
20457
|
-
var ASSISTANT_UPGRADE_FINISH_LOCK =
|
|
20784
|
+
var ASSISTANT_UPGRADE_FINISH_LOCK = path7.join("Temporary", "upgradeFinsh.lock");
|
|
20458
20785
|
function launchAssistantHost(workRoot, config2, onProgress) {
|
|
20459
|
-
const hostPath =
|
|
20786
|
+
const hostPath = path7.join(workRoot, config2.hostPath);
|
|
20460
20787
|
onProgress?.("\u542F\u52A8\u667A\u80FD\u7BA1\u5BB6");
|
|
20461
20788
|
const { ELECTRON_RUN_AS_NODE: _dropped, ...env } = process.env;
|
|
20462
20789
|
const child = (0, import_child_process3.spawn)(hostPath, ["startwithplugin", "selfstart"], {
|
|
20463
|
-
cwd:
|
|
20790
|
+
cwd: path7.dirname(hostPath),
|
|
20464
20791
|
detached: true,
|
|
20465
20792
|
stdio: "ignore",
|
|
20466
20793
|
windowsHide: true,
|
|
@@ -20477,7 +20804,7 @@ async function locateInstalledRuntime(config2) {
|
|
|
20477
20804
|
return workRoot;
|
|
20478
20805
|
}
|
|
20479
20806
|
async function waitForUpgradedAssistantClient(workRoot, config2, onProgress, versionBefore) {
|
|
20480
|
-
const finishLockPath =
|
|
20807
|
+
const finishLockPath = path7.join(workRoot, ASSISTANT_UPGRADE_FINISH_LOCK);
|
|
20481
20808
|
const finishStartedAt = Date.now();
|
|
20482
20809
|
const versionRaised = () => {
|
|
20483
20810
|
if (!versionBefore)
|
|
@@ -20485,7 +20812,7 @@ async function waitForUpgradedAssistantClient(workRoot, config2, onProgress, ver
|
|
|
20485
20812
|
const current = readInstalledAssistantBaseVersion(workRoot);
|
|
20486
20813
|
return Boolean(current) && compareAssistantVersions(current, versionBefore) > 0;
|
|
20487
20814
|
};
|
|
20488
|
-
while (!
|
|
20815
|
+
while (!fs7.existsSync(finishLockPath)) {
|
|
20489
20816
|
if (versionRaised()) {
|
|
20490
20817
|
onProgress?.("\u5BA2\u6237\u7AEF\u7248\u672C\u53F7\u5DF2\u88AB\u8986\u76D6\u62AC\u9AD8\uFF0C\u89C6\u4E3A Client \u8986\u76D6\u5B8C\u6210\uFF08\u672A\u51FA\u73B0 upgradeFinsh.lock\uFF09");
|
|
20491
20818
|
break;
|
|
@@ -20547,9 +20874,9 @@ async function installRuntime(options) {
|
|
|
20547
20874
|
}
|
|
20548
20875
|
const installDir = options.installDir || getDefaultInstallPath();
|
|
20549
20876
|
const installerPath = options.installerPath || await downloadRuntimeInstaller(options.config, options.onProgress, options.installType || "full");
|
|
20550
|
-
|
|
20551
|
-
const installerLogPath =
|
|
20552
|
-
|
|
20877
|
+
fs7.mkdirSync(installDir, { recursive: true });
|
|
20878
|
+
const installerLogPath = path7.join(installDir, "Temporary", "logs", "install.log");
|
|
20879
|
+
fs7.mkdirSync(path7.dirname(installerLogPath), { recursive: true });
|
|
20553
20880
|
options.onProgress?.(`\u6267\u884C\u5B89\u88C5\u7A0B\u5E8F: ${installerPath}`);
|
|
20554
20881
|
const exitCode = await executeInstallerProcess(installerPath, installDir, installerLogPath);
|
|
20555
20882
|
options.onProgress?.(`\u5B89\u88C5\u8FDB\u7A0B\u9000\u51FA\u7801: ${exitCode}`);
|
|
@@ -20633,7 +20960,7 @@ async function installMissingBacktestModules(workRoot, config2, onProgress, opti
|
|
|
20633
20960
|
if (moduleIndex !== CLIENT_PLUGIN_MODULE_INDEX && moduleIndex !== TY_MODULE_INDEX)
|
|
20634
20961
|
return;
|
|
20635
20962
|
if (moduleIndex === CLIENT_PLUGIN_MODULE_INDEX) {
|
|
20636
|
-
|
|
20963
|
+
fs7.rmSync(path7.join(workRoot, ASSISTANT_UPGRADE_FINISH_LOCK), { force: true });
|
|
20637
20964
|
}
|
|
20638
20965
|
await quiesceTyModuleProcesses(workRoot, onProgress, (selected) => {
|
|
20639
20966
|
stoppedPayloadProcesses = [...stoppedPayloadProcesses, ...selected];
|
|
@@ -20648,7 +20975,7 @@ async function installMissingBacktestModules(workRoot, config2, onProgress, opti
|
|
|
20648
20975
|
const upgradedZltContent = await waitForUpgradedAssistantClient(workRoot, config2, onProgress, baseVersionBeforeCover ?? void 0);
|
|
20649
20976
|
onProgress?.("\u667A\u80FD\u7BA1\u5BB6 Client \u5347\u7EA7\u540E IPC \u5DF2\u6062\u590D");
|
|
20650
20977
|
await installBacktestModules(workRoot, upgradedZltContent, config2, onProgress, installHooks);
|
|
20651
|
-
|
|
20978
|
+
fs7.rmSync(path7.join(workRoot, ASSISTANT_UPGRADE_FINISH_LOCK), { force: true });
|
|
20652
20979
|
}
|
|
20653
20980
|
} catch (error2) {
|
|
20654
20981
|
if (runtimeStopped || stoppedPayloadProcesses.length > 0) {
|
|
@@ -20721,30 +21048,30 @@ function prepareRuntimeToolchain(workRoot, onProgress) {
|
|
|
20721
21048
|
}
|
|
20722
21049
|
function ensurePythonToolchain(workRoot) {
|
|
20723
21050
|
const targetPython = getPythonExePath(workRoot);
|
|
20724
|
-
if (!
|
|
21051
|
+
if (!fs7.existsSync(targetPython)) {
|
|
20725
21052
|
throw new Error(`\u6295\u7814\u6A21\u5757\u5C1A\u672A\u4E0B\u53D1 Python \u8FD0\u884C\u65F6: ${targetPython}\u3002\u8BF7\u5728\u667A\u80FD\u7BA1\u5BB6\u4E2D\u5B89\u88C5\u6216\u4FEE\u590D\u6295\u7814\u6A21\u5757\u540E\u91CD\u8BD5\u3002`);
|
|
20726
21053
|
}
|
|
20727
|
-
const abiDll =
|
|
20728
|
-
if (!
|
|
21054
|
+
const abiDll = path7.join(path7.dirname(targetPython), `python${PYTHON_SDK_ABI_TAG.replace(/^cp/, "")}.dll`);
|
|
21055
|
+
if (!fs7.existsSync(abiDll)) {
|
|
20729
21056
|
throw new Error(`\u6295\u7814\u6A21\u5757\u4E0B\u53D1\u7684 Python \u4E0E zltsdk-plugin \u7684 ${PYTHON_SDK_ABI_TAG} wheel ABI \u4E0D\u5339\u914D\uFF1A\u672A\u627E\u5230 ${abiDll}\u3002\u8BF7\u5728\u667A\u80FD\u7BA1\u5BB6\u4E2D\u91CD\u65B0\u5B89\u88C5\u6295\u7814\u6A21\u5757\u3002`);
|
|
20730
21057
|
}
|
|
20731
21058
|
return targetPython;
|
|
20732
21059
|
}
|
|
20733
21060
|
function toolchainDownloadCacheDir() {
|
|
20734
|
-
return
|
|
21061
|
+
return path7.join(os2.tmpdir(), "zlt-runtime-toolchains");
|
|
20735
21062
|
}
|
|
20736
21063
|
async function ensureVerifiedToolchainAsset(options) {
|
|
20737
21064
|
const { label, url, sha256, destination, timeoutMs, onProgress } = options;
|
|
20738
21065
|
if (!url || !sha256) {
|
|
20739
21066
|
throw new Error(`${label} \u672A\u914D\u7F6E\u56FA\u5B9A URL/SHA256`);
|
|
20740
21067
|
}
|
|
20741
|
-
if (
|
|
21068
|
+
if (fs7.existsSync(destination)) {
|
|
20742
21069
|
try {
|
|
20743
21070
|
assertFileSha256(destination, sha256);
|
|
20744
21071
|
onProgress?.(`\u590D\u7528\u5DF2\u6821\u9A8C ${label}: ${destination}`);
|
|
20745
21072
|
return;
|
|
20746
21073
|
} catch {
|
|
20747
|
-
|
|
21074
|
+
fs7.rmSync(destination, { force: true });
|
|
20748
21075
|
}
|
|
20749
21076
|
}
|
|
20750
21077
|
onProgress?.(`\u4E0B\u8F7D ${label}: ${url}`);
|
|
@@ -20753,8 +21080,8 @@ async function ensureVerifiedToolchainAsset(options) {
|
|
|
20753
21080
|
onProgress?.(`${label} SHA256 \u6821\u9A8C\u901A\u8FC7: ${sha256}`);
|
|
20754
21081
|
}
|
|
20755
21082
|
async function ensureManagedPipWheel(workRoot, config2, onProgress) {
|
|
20756
|
-
const destination =
|
|
20757
|
-
|
|
21083
|
+
const destination = path7.join(toolchainDownloadCacheDir(), "pip-26.1.2-py3-none-any.whl");
|
|
21084
|
+
fs7.mkdirSync(path7.dirname(destination), { recursive: true });
|
|
20758
21085
|
await ensureVerifiedToolchainAsset({
|
|
20759
21086
|
label: "pip 26.1.2 wheel",
|
|
20760
21087
|
url: config2.pythonPipWheelUrl,
|
|
@@ -20766,7 +21093,7 @@ async function ensureManagedPipWheel(workRoot, config2, onProgress) {
|
|
|
20766
21093
|
return destination;
|
|
20767
21094
|
}
|
|
20768
21095
|
function assertFileSha256(filePath, expectedSha256) {
|
|
20769
|
-
const actual = (0, import_crypto3.createHash)("sha256").update(
|
|
21096
|
+
const actual = (0, import_crypto3.createHash)("sha256").update(fs7.readFileSync(filePath)).digest("hex").toUpperCase();
|
|
20770
21097
|
const expected = expectedSha256.trim().toUpperCase();
|
|
20771
21098
|
if (actual !== expected) {
|
|
20772
21099
|
throw new Error(`SHA256 \u6821\u9A8C\u5931\u8D25: ${filePath}, actual=${actual}, expected=${expected}`);
|
|
@@ -20775,27 +21102,27 @@ function assertFileSha256(filePath, expectedSha256) {
|
|
|
20775
21102
|
async function quiesceTyModuleProcesses(workRoot, onProgress, onWillStop) {
|
|
20776
21103
|
if (process.platform !== "win32")
|
|
20777
21104
|
return [];
|
|
20778
|
-
const managedCodePath =
|
|
20779
|
-
const jsserviceRoot = `${
|
|
20780
|
-
const managedGitRoot =
|
|
21105
|
+
const managedCodePath = path7.resolve(workRoot, "vscode", "Code.exe");
|
|
21106
|
+
const jsserviceRoot = `${path7.resolve(workRoot, "jsservice")}${path7.sep}`.toLowerCase();
|
|
21107
|
+
const managedGitRoot = path7.resolve(workRoot, "mingit");
|
|
20781
21108
|
assertPathInside(workRoot, managedGitRoot);
|
|
20782
21109
|
const executablePaths = [
|
|
20783
|
-
|
|
20784
|
-
|
|
20785
|
-
|
|
20786
|
-
|
|
21110
|
+
path7.join(workRoot, "zltaf", "zltaf.exe"),
|
|
21111
|
+
path7.join(workRoot, "python", "python.exe"),
|
|
21112
|
+
path7.join(workRoot, "mingit", "cmd", "git.exe"),
|
|
21113
|
+
path7.join(workRoot, "zltHost", "ZltDcmClient.exe"),
|
|
20787
21114
|
managedCodePath
|
|
20788
21115
|
].map((candidate) => {
|
|
20789
|
-
const resolved =
|
|
21116
|
+
const resolved = path7.resolve(candidate);
|
|
20790
21117
|
assertPathInside(workRoot, resolved);
|
|
20791
21118
|
return resolved;
|
|
20792
21119
|
});
|
|
20793
|
-
const installedExecutablePaths = executablePaths.filter((candidate) =>
|
|
20794
|
-
const installedExecutableRoots =
|
|
21120
|
+
const installedExecutablePaths = executablePaths.filter((candidate) => fs7.existsSync(candidate));
|
|
21121
|
+
const installedExecutableRoots = fs7.existsSync(managedGitRoot) ? [`${managedGitRoot}${path7.sep}`] : [];
|
|
20795
21122
|
if (installedExecutablePaths.length === 0 && installedExecutableRoots.length === 0)
|
|
20796
21123
|
return [];
|
|
20797
21124
|
const selectTyPayloadProcesses = () => listManagedRuntimeProcesses(installedExecutablePaths, installedExecutableRoots).filter((item) => {
|
|
20798
|
-
if (
|
|
21125
|
+
if (path7.resolve(item.executablePath).toLowerCase() !== managedCodePath.toLowerCase())
|
|
20799
21126
|
return true;
|
|
20800
21127
|
const commandLine = item.commandLine.replaceAll("/", "\\").toLowerCase();
|
|
20801
21128
|
return commandLine.includes(jsserviceRoot) && commandLine.includes("--ms-enable-electron-run-as-node");
|
|
@@ -20853,16 +21180,16 @@ async function stopManagedRuntimeProcesses(workRoot, config2, onProgress, messag
|
|
|
20853
21180
|
if (process.platform !== "win32")
|
|
20854
21181
|
return [];
|
|
20855
21182
|
const executablePaths = [
|
|
20856
|
-
|
|
20857
|
-
|
|
20858
|
-
|
|
20859
|
-
|
|
21183
|
+
path7.join(workRoot, config2.hostPath),
|
|
21184
|
+
path7.join(workRoot, config2.backservicePath),
|
|
21185
|
+
path7.join(workRoot, "zltHost", "zlthost.exe"),
|
|
21186
|
+
path7.join(workRoot, "zltaf", "zltaf.exe")
|
|
20860
21187
|
].map((candidate) => {
|
|
20861
|
-
const resolved =
|
|
21188
|
+
const resolved = path7.resolve(candidate);
|
|
20862
21189
|
assertPathInside(workRoot, resolved);
|
|
20863
21190
|
return resolved;
|
|
20864
21191
|
});
|
|
20865
|
-
const installedExecutablePaths = executablePaths.filter((candidate) =>
|
|
21192
|
+
const installedExecutablePaths = executablePaths.filter((candidate) => fs7.existsSync(candidate));
|
|
20866
21193
|
if (installedExecutablePaths.length === 0)
|
|
20867
21194
|
return [];
|
|
20868
21195
|
const running = listManagedRuntimeProcesses(installedExecutablePaths);
|
|
@@ -20875,9 +21202,9 @@ async function stopManagedRuntimeProcesses(workRoot, config2, onProgress, messag
|
|
|
20875
21202
|
throw new Error(`${messages.failed}: ${formatManagedProcessList(remaining)}\u3002\u8BF7\u5173\u95ED\u667A\u91CF\u901A\u76F8\u5173\u4EFB\u52A1\u540E\u91CD\u8BD5\u5B89\u88C5\u3002`);
|
|
20876
21203
|
}
|
|
20877
21204
|
}
|
|
20878
|
-
const zltMarker =
|
|
21205
|
+
const zltMarker = path7.resolve(workRoot, config2.temporaryZltFile || "Temporary/zlt");
|
|
20879
21206
|
assertPathInside(workRoot, zltMarker);
|
|
20880
|
-
|
|
21207
|
+
fs7.rmSync(zltMarker, { force: true });
|
|
20881
21208
|
if (running.length > 0)
|
|
20882
21209
|
onProgress?.(messages.stopped);
|
|
20883
21210
|
return running;
|
|
@@ -20947,7 +21274,7 @@ ${result.stderr || ""}`);
|
|
|
20947
21274
|
return [];
|
|
20948
21275
|
return [{
|
|
20949
21276
|
pid,
|
|
20950
|
-
name: typeof item.Name === "string" ? item.Name :
|
|
21277
|
+
name: typeof item.Name === "string" ? item.Name : path7.basename(item.ExecutablePath),
|
|
20951
21278
|
executablePath: item.ExecutablePath,
|
|
20952
21279
|
commandLine: typeof item.CommandLine === "string" ? item.CommandLine : ""
|
|
20953
21280
|
}];
|
|
@@ -20955,14 +21282,14 @@ ${result.stderr || ""}`);
|
|
|
20955
21282
|
}
|
|
20956
21283
|
function windowsSystemToolPath(relativePath) {
|
|
20957
21284
|
const systemRoot = process.env.SystemRoot || process.env.WINDIR;
|
|
20958
|
-
if (!systemRoot || !
|
|
21285
|
+
if (!systemRoot || !path7.isAbsolute(systemRoot)) {
|
|
20959
21286
|
throw new Error("\u65E0\u6CD5\u5B89\u5168\u5B9A\u4F4D Windows \u7CFB\u7EDF\u5DE5\u5177: SystemRoot \u672A\u8BBE\u7F6E");
|
|
20960
21287
|
}
|
|
20961
|
-
return
|
|
21288
|
+
return path7.join(systemRoot, "System32", ...relativePath.split("/"));
|
|
20962
21289
|
}
|
|
20963
21290
|
function ensureGitToolchain(workRoot) {
|
|
20964
21291
|
const targetGit = getGitExePath(workRoot);
|
|
20965
|
-
if (!
|
|
21292
|
+
if (!fs7.existsSync(targetGit)) {
|
|
20966
21293
|
throw new Error(`\u6295\u7814\u6A21\u5757\u5C1A\u672A\u4E0B\u53D1 MinGit \u5DE5\u5177\u94FE: ${targetGit}\u3002\u8BF7\u5728\u667A\u80FD\u7BA1\u5BB6\u4E2D\u5B89\u88C5\u6216\u4FEE\u590D\u6295\u7814\u6A21\u5757\u540E\u91CD\u8BD5\u3002`);
|
|
20967
21294
|
}
|
|
20968
21295
|
return targetGit;
|
|
@@ -20972,7 +21299,7 @@ function validatePythonSdkComplete(workRoot, config2) {
|
|
|
20972
21299
|
if (packages.length === 0)
|
|
20973
21300
|
return { complete: true };
|
|
20974
21301
|
const pythonPath = getPythonExePath(workRoot);
|
|
20975
|
-
if (!
|
|
21302
|
+
if (!fs7.existsSync(pythonPath)) {
|
|
20976
21303
|
return { complete: false, reason: `\u7F3A\u5C11Python \u7A0B\u5E8F: ${pythonPath}` };
|
|
20977
21304
|
}
|
|
20978
21305
|
if (areBundledSitePackagesPresent(workRoot, packages)) {
|
|
@@ -21020,7 +21347,7 @@ async function installPythonSdk(workRoot, config2, onProgress) {
|
|
|
21020
21347
|
return;
|
|
21021
21348
|
}
|
|
21022
21349
|
const pythonPath = getPythonExePath(workRoot);
|
|
21023
|
-
if (!
|
|
21350
|
+
if (!fs7.existsSync(pythonPath)) {
|
|
21024
21351
|
throw new Error(`\u65E0\u6CD5\u5B89\u88C5 Python SDK\uFF0C\u7F3A\u5C11 Python \u7A0B\u5E8F: ${pythonPath}`);
|
|
21025
21352
|
}
|
|
21026
21353
|
const packages = normalizePythonSdkPackages(config2);
|
|
@@ -21113,16 +21440,16 @@ function buildManagedPipEnvironment(runtimeIndexUrl, baseEnvironment = process.e
|
|
|
21113
21440
|
async function downloadRuntimeInstaller(config2, onProgress, installType = "full") {
|
|
21114
21441
|
const url = resolveAssistantDownloadUrl(config2, installType);
|
|
21115
21442
|
const sha256 = resolveAssistantDownloadSha256(config2, installType);
|
|
21116
|
-
const filename =
|
|
21117
|
-
const dir =
|
|
21118
|
-
const destination =
|
|
21119
|
-
|
|
21443
|
+
const filename = path7.basename(new URL(url).pathname) || "zlt-runtime-installer.exe";
|
|
21444
|
+
const dir = path7.join(os2.tmpdir(), config2.downloadTempDir);
|
|
21445
|
+
const destination = path7.join(dir, filename);
|
|
21446
|
+
fs7.mkdirSync(dir, { recursive: true });
|
|
21120
21447
|
onProgress?.(`\u4E0B\u8F7D\u5B89\u88C5\u5305: ${url}`);
|
|
21121
21448
|
await downloadFile(url, destination);
|
|
21122
21449
|
try {
|
|
21123
21450
|
assertFileSha256(destination, sha256);
|
|
21124
21451
|
} catch (error2) {
|
|
21125
|
-
|
|
21452
|
+
fs7.rmSync(destination, { force: true });
|
|
21126
21453
|
throw error2;
|
|
21127
21454
|
}
|
|
21128
21455
|
onProgress?.(`\u5B89\u88C5\u5305 SHA256 \u6821\u9A8C\u901A\u8FC7: ${sha256}`);
|
|
@@ -21150,7 +21477,7 @@ function describeInstallerExitCode(exitCode) {
|
|
|
21150
21477
|
}
|
|
21151
21478
|
}
|
|
21152
21479
|
function executeInstallerProcess(installerPath, installDir, logPath) {
|
|
21153
|
-
return new Promise((
|
|
21480
|
+
return new Promise((resolve9, reject) => {
|
|
21154
21481
|
const child = (0, import_child_process3.spawn)(installerPath, [
|
|
21155
21482
|
"/VERYSILENT",
|
|
21156
21483
|
"/SUPPRESSMSGBOXES",
|
|
@@ -21172,14 +21499,14 @@ function executeInstallerProcess(installerPath, installDir, logPath) {
|
|
|
21172
21499
|
} else if (code === null) {
|
|
21173
21500
|
reject(new Error("\u5B89\u88C5\u7A0B\u5E8F\u6267\u884C\u5931\u8D25\uFF0C\u672A\u8FD4\u56DE\u9000\u51FA\u7801"));
|
|
21174
21501
|
} else {
|
|
21175
|
-
|
|
21502
|
+
resolve9(code);
|
|
21176
21503
|
}
|
|
21177
21504
|
});
|
|
21178
21505
|
child.on("error", (error2) => reject(new Error(`\u5B89\u88C5\u7A0B\u5E8F\u542F\u52A8\u5931\u8D25: ${error2.message}`)));
|
|
21179
21506
|
});
|
|
21180
21507
|
}
|
|
21181
21508
|
function runPythonSdkInstall(pythonPath, args, timeoutMs, bootstrapPipWheelPath, environment = process.env) {
|
|
21182
|
-
return new Promise((
|
|
21509
|
+
return new Promise((resolve9, reject) => {
|
|
21183
21510
|
const commandArgs = bootstrapPipWheelPath ? buildPipBootstrapCommand(args, bootstrapPipWheelPath) : args;
|
|
21184
21511
|
const child = (0, import_child_process3.spawn)(pythonPath, commandArgs, {
|
|
21185
21512
|
env: environment,
|
|
@@ -21200,7 +21527,7 @@ function runPythonSdkInstall(pythonPath, args, timeoutMs, bootstrapPipWheelPath,
|
|
|
21200
21527
|
child.on("close", (code) => {
|
|
21201
21528
|
clearTimeout(timer);
|
|
21202
21529
|
if (code === 0) {
|
|
21203
|
-
|
|
21530
|
+
resolve9();
|
|
21204
21531
|
} else {
|
|
21205
21532
|
reject(new Error(`Python SDK \u5B89\u88C5\u5931\u8D25\uFF0C\u9000\u51FA\u7801: ${code ?? "unknown"}, output=${truncateOutput(output)}`));
|
|
21206
21533
|
}
|
|
@@ -21258,14 +21585,14 @@ function downloadFile(url, destination, redirectCount = 0, timeoutMs = 0, initia
|
|
|
21258
21585
|
if (redirectCount > 5) {
|
|
21259
21586
|
return Promise.reject(new Error(`\u4E0B\u8F7D\u91CD\u5B9A\u5411\u8FC7\u591A: ${url}`));
|
|
21260
21587
|
}
|
|
21261
|
-
|
|
21588
|
+
fs7.mkdirSync(path7.dirname(destination), { recursive: true });
|
|
21262
21589
|
const partialPath = `${destination}.${process.pid}.${(0, import_crypto3.randomUUID)()}.part`;
|
|
21263
|
-
return new Promise((
|
|
21590
|
+
return new Promise((resolve9, reject) => {
|
|
21264
21591
|
let settled = false;
|
|
21265
21592
|
let file;
|
|
21266
21593
|
const cleanupPartial = () => {
|
|
21267
21594
|
file?.destroy();
|
|
21268
|
-
|
|
21595
|
+
fs7.rmSync(partialPath, { force: true });
|
|
21269
21596
|
};
|
|
21270
21597
|
const fail2 = (error2) => {
|
|
21271
21598
|
if (settled)
|
|
@@ -21278,10 +21605,10 @@ function downloadFile(url, destination, redirectCount = 0, timeoutMs = 0, initia
|
|
|
21278
21605
|
if (settled)
|
|
21279
21606
|
return;
|
|
21280
21607
|
try {
|
|
21281
|
-
|
|
21282
|
-
|
|
21608
|
+
fs7.rmSync(destination, { force: true });
|
|
21609
|
+
fs7.renameSync(partialPath, destination);
|
|
21283
21610
|
settled = true;
|
|
21284
|
-
|
|
21611
|
+
resolve9();
|
|
21285
21612
|
} catch (error2) {
|
|
21286
21613
|
fail2(error2);
|
|
21287
21614
|
}
|
|
@@ -21306,7 +21633,7 @@ function downloadFile(url, destination, redirectCount = 0, timeoutMs = 0, initia
|
|
|
21306
21633
|
if (settled)
|
|
21307
21634
|
return;
|
|
21308
21635
|
settled = true;
|
|
21309
|
-
|
|
21636
|
+
resolve9();
|
|
21310
21637
|
}, fail2);
|
|
21311
21638
|
return;
|
|
21312
21639
|
}
|
|
@@ -21315,7 +21642,7 @@ function downloadFile(url, destination, redirectCount = 0, timeoutMs = 0, initia
|
|
|
21315
21642
|
fail2(new Error(`\u4E0B\u8F7D\u5931\u8D25: HTTP ${statusCode}`));
|
|
21316
21643
|
return;
|
|
21317
21644
|
}
|
|
21318
|
-
file =
|
|
21645
|
+
file = fs7.createWriteStream(partialPath, { flags: "wx" });
|
|
21319
21646
|
response.on("aborted", () => fail2(new Error(`\u4E0B\u8F7D\u54CD\u5E94\u4E2D\u65AD: ${url}`)));
|
|
21320
21647
|
response.on("error", fail2);
|
|
21321
21648
|
response.on("close", () => {
|
|
@@ -21341,41 +21668,41 @@ function downloadFile(url, destination, redirectCount = 0, timeoutMs = 0, initia
|
|
|
21341
21668
|
});
|
|
21342
21669
|
}
|
|
21343
21670
|
function delay(ms) {
|
|
21344
|
-
return new Promise((
|
|
21671
|
+
return new Promise((resolve9) => setTimeout(resolve9, ms));
|
|
21345
21672
|
}
|
|
21346
21673
|
function getZltafExePath(workRoot) {
|
|
21347
|
-
return
|
|
21674
|
+
return path7.join(workRoot, "zltaf", "zltaf.exe");
|
|
21348
21675
|
}
|
|
21349
21676
|
function getZltafConfigPath(workRoot) {
|
|
21350
|
-
return
|
|
21677
|
+
return path7.join(workRoot, "zltaf", "application-local.properties");
|
|
21351
21678
|
}
|
|
21352
21679
|
function resolveZltafLaunchConfigPath(workRoot, config2) {
|
|
21353
21680
|
if (config2.zltafConfigFile === ZLTAF_CONFIG_FILE_DEFAULT) {
|
|
21354
21681
|
return getZltafConfigPath(workRoot);
|
|
21355
21682
|
}
|
|
21356
|
-
const preferred =
|
|
21357
|
-
if (
|
|
21683
|
+
const preferred = path7.join(workRoot, "zltaf", config2.zltafConfigFile);
|
|
21684
|
+
if (fs7.existsSync(preferred)) {
|
|
21358
21685
|
return preferred;
|
|
21359
21686
|
}
|
|
21360
21687
|
const base = getZltafConfigPath(workRoot);
|
|
21361
|
-
process.stderr.write(`[zlt-runtime] ZLTAF \u914D\u7F6E ${config2.zltafConfigFile} \u4E0D\u5B58\u5728\uFF0C\u56DE\u9000\u5230 ${
|
|
21688
|
+
process.stderr.write(`[zlt-runtime] ZLTAF \u914D\u7F6E ${config2.zltafConfigFile} \u4E0D\u5B58\u5728\uFF0C\u56DE\u9000\u5230 ${path7.basename(base)}
|
|
21362
21689
|
`);
|
|
21363
21690
|
return base;
|
|
21364
21691
|
}
|
|
21365
21692
|
function getPythonExePath(workRoot) {
|
|
21366
|
-
return
|
|
21693
|
+
return path7.join(workRoot, "python", "python.exe");
|
|
21367
21694
|
}
|
|
21368
21695
|
function getGitExePath(workRoot) {
|
|
21369
|
-
return
|
|
21696
|
+
return path7.join(workRoot, "mingit", "cmd", "git.exe");
|
|
21370
21697
|
}
|
|
21371
21698
|
function areBacktestModuleRuntimeFilesPresent(workRoot) {
|
|
21372
|
-
return
|
|
21699
|
+
return fs7.existsSync(getZltafExePath(workRoot)) && fs7.existsSync(getZltafConfigPath(workRoot));
|
|
21373
21700
|
}
|
|
21374
21701
|
function assertPathInside(root, targetPath) {
|
|
21375
|
-
const resolvedRoot =
|
|
21376
|
-
const resolvedTarget =
|
|
21377
|
-
const relative2 =
|
|
21378
|
-
if (relative2.startsWith("..") ||
|
|
21702
|
+
const resolvedRoot = path7.resolve(root);
|
|
21703
|
+
const resolvedTarget = path7.resolve(targetPath);
|
|
21704
|
+
const relative2 = path7.relative(resolvedRoot, resolvedTarget);
|
|
21705
|
+
if (relative2.startsWith("..") || path7.isAbsolute(relative2)) {
|
|
21379
21706
|
throw new Error(`\u62D2\u7EDD\u5199\u5165\u5B89\u88C5\u76EE\u5F55\u5916\u8DEF\u5F84: ${resolvedTarget}`);
|
|
21380
21707
|
}
|
|
21381
21708
|
}
|
|
@@ -21391,12 +21718,12 @@ function normalizeRequiredPythonPackages(config2) {
|
|
|
21391
21718
|
function areBundledSitePackagesPresent(workRoot, packages) {
|
|
21392
21719
|
if (packages.some(hasPythonVersionSpecifier))
|
|
21393
21720
|
return false;
|
|
21394
|
-
const sitePackages =
|
|
21395
|
-
if (!
|
|
21721
|
+
const sitePackages = path7.join(workRoot, "python", "Lib", "site-packages");
|
|
21722
|
+
if (!fs7.existsSync(sitePackages))
|
|
21396
21723
|
return false;
|
|
21397
21724
|
let entries = [];
|
|
21398
21725
|
try {
|
|
21399
|
-
entries =
|
|
21726
|
+
entries = fs7.readdirSync(sitePackages).map((entry) => entry.toLowerCase());
|
|
21400
21727
|
} catch {
|
|
21401
21728
|
return false;
|
|
21402
21729
|
}
|
|
@@ -21405,12 +21732,12 @@ function areBundledSitePackagesPresent(workRoot, packages) {
|
|
|
21405
21732
|
const normalized = normalizePythonPackageName(requirementName);
|
|
21406
21733
|
const importName = pythonDistributionImportName(packageName);
|
|
21407
21734
|
const candidateFiles = [
|
|
21408
|
-
|
|
21409
|
-
|
|
21410
|
-
|
|
21411
|
-
|
|
21735
|
+
path7.join(sitePackages, requirementName, "__init__.py"),
|
|
21736
|
+
path7.join(sitePackages, `${requirementName}.py`),
|
|
21737
|
+
path7.join(sitePackages, importName, "__init__.py"),
|
|
21738
|
+
path7.join(sitePackages, `${importName}.py`)
|
|
21412
21739
|
];
|
|
21413
|
-
return candidateFiles.some((candidate) =>
|
|
21740
|
+
return candidateFiles.some((candidate) => fs7.existsSync(candidate)) || entries.some((entry) => entry.startsWith(`${normalized}-`) && (entry.endsWith(".dist-info") || entry.endsWith(".egg-info")));
|
|
21414
21741
|
});
|
|
21415
21742
|
}
|
|
21416
21743
|
function hasPythonVersionSpecifier(packageSpec) {
|
|
@@ -21452,27 +21779,27 @@ async function waitForZltafPipe(workRoot, config2, options) {
|
|
|
21452
21779
|
}
|
|
21453
21780
|
|
|
21454
21781
|
// ../zlt-runtime-core/dist/auth.js
|
|
21455
|
-
var
|
|
21782
|
+
var fs8 = __toESM(require("fs"), 1);
|
|
21456
21783
|
var os3 = __toESM(require("os"), 1);
|
|
21457
|
-
var
|
|
21784
|
+
var path8 = __toESM(require("path"), 1);
|
|
21458
21785
|
var DEFAULT_ZLTQUANT_API_BASE = "https://api.zltquant.com";
|
|
21459
21786
|
function resolveZltQuantHome(env = process.env) {
|
|
21460
21787
|
const configuredHome = env.ZLTQUANT_HOME?.trim();
|
|
21461
21788
|
if (configuredHome)
|
|
21462
21789
|
return expandHome(configuredHome);
|
|
21463
|
-
return
|
|
21790
|
+
return path8.join(os3.homedir(), ".zltquant");
|
|
21464
21791
|
}
|
|
21465
21792
|
function resolveCredentialsPath(env = process.env) {
|
|
21466
21793
|
const configuredPath = env.ZLTQUANT_CREDENTIALS?.trim();
|
|
21467
21794
|
if (configuredPath)
|
|
21468
21795
|
return expandHome(configuredPath);
|
|
21469
|
-
return
|
|
21796
|
+
return path8.join(resolveZltQuantHome(env), "credentials.json");
|
|
21470
21797
|
}
|
|
21471
21798
|
function readCredentials(env = process.env) {
|
|
21472
21799
|
const credentialsPath = resolveCredentialsPath(env);
|
|
21473
|
-
if (!
|
|
21800
|
+
if (!fs8.existsSync(credentialsPath))
|
|
21474
21801
|
return null;
|
|
21475
|
-
const parsed = JSON.parse(
|
|
21802
|
+
const parsed = JSON.parse(fs8.readFileSync(credentialsPath, "utf-8"));
|
|
21476
21803
|
const apiKey = typeof parsed.apiKey === "string" ? parsed.apiKey.trim() : "";
|
|
21477
21804
|
if (!apiKey)
|
|
21478
21805
|
return null;
|
|
@@ -21512,16 +21839,16 @@ function writeCredentials(input, env = process.env) {
|
|
|
21512
21839
|
source,
|
|
21513
21840
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
21514
21841
|
};
|
|
21515
|
-
|
|
21842
|
+
fs8.mkdirSync(path8.dirname(credentialsPath), { recursive: true });
|
|
21516
21843
|
const tempPath = `${credentialsPath}.${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp`;
|
|
21517
21844
|
try {
|
|
21518
|
-
|
|
21845
|
+
fs8.writeFileSync(tempPath, `${JSON.stringify(credentials, null, 2)}
|
|
21519
21846
|
`, { encoding: "utf-8", mode: 384 });
|
|
21520
21847
|
chmodOwnerOnly(tempPath);
|
|
21521
|
-
|
|
21848
|
+
fs8.renameSync(tempPath, credentialsPath);
|
|
21522
21849
|
chmodOwnerOnly(credentialsPath);
|
|
21523
21850
|
} finally {
|
|
21524
|
-
|
|
21851
|
+
fs8.rmSync(tempPath, { force: true });
|
|
21525
21852
|
}
|
|
21526
21853
|
return fileAuthStatus(credentialsPath, resolveZltQuantHome(env), credentials);
|
|
21527
21854
|
}
|
|
@@ -21585,9 +21912,9 @@ function expandHome(input) {
|
|
|
21585
21912
|
if (input === "~")
|
|
21586
21913
|
return os3.homedir();
|
|
21587
21914
|
if (input.startsWith("~/") || input.startsWith("~\\")) {
|
|
21588
|
-
return
|
|
21915
|
+
return path8.join(os3.homedir(), input.slice(2));
|
|
21589
21916
|
}
|
|
21590
|
-
return
|
|
21917
|
+
return path8.resolve(input);
|
|
21591
21918
|
}
|
|
21592
21919
|
function tryReadCredentials(env) {
|
|
21593
21920
|
try {
|
|
@@ -21598,7 +21925,7 @@ function tryReadCredentials(env) {
|
|
|
21598
21925
|
}
|
|
21599
21926
|
function chmodOwnerOnly(filePath) {
|
|
21600
21927
|
try {
|
|
21601
|
-
|
|
21928
|
+
fs8.chmodSync(filePath, 384);
|
|
21602
21929
|
} catch {
|
|
21603
21930
|
}
|
|
21604
21931
|
}
|
|
@@ -21616,30 +21943,30 @@ function fileAuthStatus(credentialsPath, zltquantHome, credentials) {
|
|
|
21616
21943
|
|
|
21617
21944
|
// src/config.ts
|
|
21618
21945
|
function loadConfig(configPath) {
|
|
21619
|
-
const raw =
|
|
21946
|
+
const raw = fs9.readFileSync(configPath, "utf-8");
|
|
21620
21947
|
return JSON.parse(raw);
|
|
21621
21948
|
}
|
|
21622
21949
|
function resolveDefaultConfigPath() {
|
|
21623
21950
|
if (process.env.ZLT_MCP_CONFIG) return process.env.ZLT_MCP_CONFIG;
|
|
21624
|
-
const cwdCandidate =
|
|
21951
|
+
const cwdCandidate = path9.resolve(process.cwd(), "config.json");
|
|
21625
21952
|
const candidates = [
|
|
21626
|
-
|
|
21627
|
-
|
|
21953
|
+
path9.resolve(path9.dirname(process.argv[1] || ""), "..", "config.json"),
|
|
21954
|
+
path9.resolve(path9.dirname(process.argv[1] || ""), "config.json"),
|
|
21628
21955
|
cwdCandidate
|
|
21629
21956
|
];
|
|
21630
21957
|
for (const candidate of candidates) {
|
|
21631
|
-
if (
|
|
21958
|
+
if (fs9.existsSync(candidate)) return candidate;
|
|
21632
21959
|
}
|
|
21633
21960
|
return cwdCandidate;
|
|
21634
21961
|
}
|
|
21635
21962
|
function resolveDefaultRuntimeConfigPath() {
|
|
21636
21963
|
if (process.env.ZLT_RUNTIME_CONFIG) return process.env.ZLT_RUNTIME_CONFIG;
|
|
21637
21964
|
const candidates = [
|
|
21638
|
-
|
|
21639
|
-
|
|
21640
|
-
|
|
21965
|
+
path9.resolve(path9.dirname(process.argv[1] || ""), "..", "runtime.cfg.json"),
|
|
21966
|
+
path9.resolve(path9.dirname(process.argv[1] || ""), "runtime.cfg.json"),
|
|
21967
|
+
path9.resolve(process.cwd(), "runtime.cfg.json")
|
|
21641
21968
|
];
|
|
21642
|
-
return candidates.find((candidate) =>
|
|
21969
|
+
return candidates.find((candidate) => fs9.existsSync(candidate));
|
|
21643
21970
|
}
|
|
21644
21971
|
var matchingPipeNames2 = matchingPipeNames;
|
|
21645
21972
|
|
|
@@ -21689,46 +22016,46 @@ function getTimestampISO() {
|
|
|
21689
22016
|
return (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").substring(0, 19);
|
|
21690
22017
|
}
|
|
21691
22018
|
function ensureDir(dir) {
|
|
21692
|
-
|
|
22019
|
+
fs10.mkdirSync(dir, { recursive: true });
|
|
21693
22020
|
}
|
|
21694
22021
|
function writeResponseFile(outputDir, content) {
|
|
21695
22022
|
ensureDir(outputDir);
|
|
21696
22023
|
const filename = `resp_${getTimestamp()}.json`;
|
|
21697
|
-
const filePath =
|
|
21698
|
-
|
|
22024
|
+
const filePath = path10.join(outputDir, filename);
|
|
22025
|
+
fs10.writeFileSync(filePath, content, "utf-8");
|
|
21699
22026
|
return filePath;
|
|
21700
22027
|
}
|
|
21701
22028
|
function appendHistory(outputDir, uri, statusCode, contentSize, respFile) {
|
|
21702
22029
|
ensureDir(outputDir);
|
|
21703
|
-
const historyPath =
|
|
21704
|
-
if (
|
|
21705
|
-
const lines =
|
|
22030
|
+
const historyPath = path10.join(outputDir, "history.jsonl");
|
|
22031
|
+
if (fs10.existsSync(historyPath)) {
|
|
22032
|
+
const lines = fs10.readFileSync(historyPath, "utf-8").split("\n").filter((l) => l.trim());
|
|
21706
22033
|
if (lines.length > HISTORY_MAX_LINES) {
|
|
21707
22034
|
const kept = lines.slice(lines.length - HISTORY_MAX_LINES);
|
|
21708
|
-
|
|
22035
|
+
fs10.writeFileSync(historyPath, kept.join("\n") + "\n", "utf-8");
|
|
21709
22036
|
}
|
|
21710
22037
|
}
|
|
21711
|
-
const
|
|
22038
|
+
const record4 = {
|
|
21712
22039
|
time: getTimestampISO(),
|
|
21713
22040
|
uri,
|
|
21714
22041
|
status: statusCode,
|
|
21715
22042
|
size: contentSize
|
|
21716
22043
|
};
|
|
21717
|
-
if (respFile)
|
|
21718
|
-
|
|
22044
|
+
if (respFile) record4.file = respFile;
|
|
22045
|
+
fs10.appendFileSync(historyPath, JSON.stringify(record4) + "\n", "utf-8");
|
|
21719
22046
|
}
|
|
21720
22047
|
function cleanOutput(clientRootDir, maxDays = 1) {
|
|
21721
22048
|
const outputDir = getOutputDir(clientRootDir);
|
|
21722
|
-
if (!
|
|
22049
|
+
if (!fs10.existsSync(outputDir)) return 0;
|
|
21723
22050
|
const now = Date.now();
|
|
21724
22051
|
const cutoff = now - maxDays * 864e5;
|
|
21725
22052
|
let removed = 0;
|
|
21726
|
-
for (const entry of
|
|
22053
|
+
for (const entry of fs10.readdirSync(outputDir)) {
|
|
21727
22054
|
if (!entry.startsWith("resp_") || !entry.endsWith(".json")) continue;
|
|
21728
|
-
const filePath =
|
|
21729
|
-
const stat =
|
|
22055
|
+
const filePath = path10.join(outputDir, entry);
|
|
22056
|
+
const stat = fs10.statSync(filePath);
|
|
21730
22057
|
if (stat.mtimeMs < cutoff) {
|
|
21731
|
-
|
|
22058
|
+
fs10.unlinkSync(filePath);
|
|
21732
22059
|
removed++;
|
|
21733
22060
|
}
|
|
21734
22061
|
}
|
|
@@ -21736,7 +22063,7 @@ function cleanOutput(clientRootDir, maxDays = 1) {
|
|
|
21736
22063
|
}
|
|
21737
22064
|
async function execCommand(funcName, options) {
|
|
21738
22065
|
const resolver = resolveDefaultConfigPath;
|
|
21739
|
-
const configPath = typeof resolver === "function" ? resolver() : process.env.ZLT_MCP_CONFIG ||
|
|
22066
|
+
const configPath = typeof resolver === "function" ? resolver() : process.env.ZLT_MCP_CONFIG || path10.resolve(process.cwd(), "config.json");
|
|
21740
22067
|
const config2 = loadConfig2(configPath);
|
|
21741
22068
|
const clientRootDir = options.root || process.env.ZLT_CLIENT_ROOT || config2.zltconfig.clientRootDir;
|
|
21742
22069
|
if (options.pipe) {
|
|
@@ -21753,7 +22080,7 @@ async function execCommand(funcName, options) {
|
|
|
21753
22080
|
}
|
|
21754
22081
|
let bodyFromFile = bodyOverride || "";
|
|
21755
22082
|
if (!bodyFromFile && bodyFile) {
|
|
21756
|
-
bodyFromFile =
|
|
22083
|
+
bodyFromFile = fs10.readFileSync(bodyFile, "utf-8");
|
|
21757
22084
|
}
|
|
21758
22085
|
const tool = config2.tools.find((t) => t.name === funcName);
|
|
21759
22086
|
if (tool?.localHandler === "currentUser") {
|
|
@@ -21819,7 +22146,7 @@ function parseMcpArgs(argsJson, argsFile) {
|
|
|
21819
22146
|
if (argsJson !== void 0 && argsFile !== void 0) {
|
|
21820
22147
|
throw new Error("Use only one of --args-json and --args-file");
|
|
21821
22148
|
}
|
|
21822
|
-
const raw = argsFile !== void 0 ?
|
|
22149
|
+
const raw = argsFile !== void 0 ? fs10.readFileSync(argsFile, "utf-8") : argsJson !== void 0 ? argsJson : "{}";
|
|
21823
22150
|
let parsed;
|
|
21824
22151
|
try {
|
|
21825
22152
|
parsed = JSON.parse(raw);
|
|
@@ -21888,17 +22215,17 @@ function backtestHandoff(result) {
|
|
|
21888
22215
|
const payload = parseMcpResult(result);
|
|
21889
22216
|
const data = payload?.Data;
|
|
21890
22217
|
if (!data || typeof data !== "object" || Array.isArray(data)) return null;
|
|
21891
|
-
const
|
|
21892
|
-
const status = Number(
|
|
22218
|
+
const record4 = data;
|
|
22219
|
+
const status = Number(record4.status);
|
|
21893
22220
|
if (Number.isFinite(status) && status !== 0 && status !== 1) return null;
|
|
21894
|
-
const runId = typeof
|
|
22221
|
+
const runId = typeof record4.runId === "string" ? record4.runId.trim() : "";
|
|
21895
22222
|
if (!runId) return null;
|
|
21896
|
-
const evidence =
|
|
21897
|
-
const rawCodePath = typeof
|
|
22223
|
+
const evidence = record4.evidence && typeof record4.evidence === "object" && !Array.isArray(record4.evidence) ? record4.evidence : void 0;
|
|
22224
|
+
const rawCodePath = typeof record4.codePath === "string" ? record4.codePath.trim() : typeof evidence?.runDir === "string" ? evidence.runDir.trim() : "";
|
|
21898
22225
|
return {
|
|
21899
22226
|
runId,
|
|
21900
|
-
...rawCodePath &&
|
|
21901
|
-
...
|
|
22227
|
+
...rawCodePath && path10.isAbsolute(rawCodePath) ? { codePath: rawCodePath } : {},
|
|
22228
|
+
...record4.attemptFence !== void 0 ? { attemptFence: record4.attemptFence } : {}
|
|
21902
22229
|
};
|
|
21903
22230
|
}
|
|
21904
22231
|
function mcpErrorCode(result) {
|
|
@@ -21914,7 +22241,7 @@ function mergeBacktestWait(launched, waited, handoff) {
|
|
|
21914
22241
|
for (const id of [data.runId, data.backtestId]) {
|
|
21915
22242
|
if (id !== void 0 && id !== handoff.runId) throw new Error("Backtest wait returned a different run ID");
|
|
21916
22243
|
}
|
|
21917
|
-
if (data.codePath !== void 0 && handoff.codePath && (typeof data.codePath !== "string" ||
|
|
22244
|
+
if (data.codePath !== void 0 && handoff.codePath && (typeof data.codePath !== "string" || path10.resolve(data.codePath).toLowerCase() !== path10.resolve(handoff.codePath).toLowerCase())) {
|
|
21918
22245
|
throw new Error("Backtest wait returned a different run directory");
|
|
21919
22246
|
}
|
|
21920
22247
|
const status = typeof data.status === "number" || typeof data.status === "string" && data.status.trim() ? Number(data.status) : NaN;
|
|
@@ -22121,8 +22448,8 @@ function buildIpcTimeout(tool, options, defaultTimeout) {
|
|
|
22121
22448
|
}
|
|
22122
22449
|
|
|
22123
22450
|
// src/skill-generator.ts
|
|
22124
|
-
var
|
|
22125
|
-
var
|
|
22451
|
+
var fs11 = __toESM(require("fs"), 1);
|
|
22452
|
+
var path11 = __toESM(require("path"), 1);
|
|
22126
22453
|
function generateSkills(configPath, opts) {
|
|
22127
22454
|
const config2 = loadConfig(configPath);
|
|
22128
22455
|
const toolsWithSkills = config2.tools.filter((t) => t.skill);
|
|
@@ -22139,11 +22466,11 @@ ${content}
|
|
|
22139
22466
|
`);
|
|
22140
22467
|
} else {
|
|
22141
22468
|
const outDir = opts.output || ".claude/skills/zlt";
|
|
22142
|
-
if (!
|
|
22143
|
-
|
|
22469
|
+
if (!fs11.existsSync(outDir)) {
|
|
22470
|
+
fs11.mkdirSync(outDir, { recursive: true });
|
|
22144
22471
|
}
|
|
22145
|
-
const filePath =
|
|
22146
|
-
|
|
22472
|
+
const filePath = path11.join(outDir, `zlt-${tool.name.replace(/_/g, "-")}.md`);
|
|
22473
|
+
fs11.writeFileSync(filePath, content);
|
|
22147
22474
|
process.stderr.write(`Generated: ${filePath}
|
|
22148
22475
|
`);
|
|
22149
22476
|
}
|
|
@@ -22823,52 +23150,52 @@ var StdioServerTransport = class {
|
|
|
22823
23150
|
this.onclose?.();
|
|
22824
23151
|
}
|
|
22825
23152
|
send(message) {
|
|
22826
|
-
return new Promise((
|
|
23153
|
+
return new Promise((resolve9) => {
|
|
22827
23154
|
const json = serializeMessage(message);
|
|
22828
23155
|
if (this._stdout.write(json)) {
|
|
22829
|
-
|
|
23156
|
+
resolve9();
|
|
22830
23157
|
} else {
|
|
22831
|
-
this._stdout.once("drain",
|
|
23158
|
+
this._stdout.once("drain", resolve9);
|
|
22832
23159
|
}
|
|
22833
23160
|
});
|
|
22834
23161
|
}
|
|
22835
23162
|
};
|
|
22836
23163
|
|
|
22837
23164
|
// src/mcp-server.ts
|
|
22838
|
-
var
|
|
23165
|
+
var fs15 = __toESM(require("node:fs"), 1);
|
|
22839
23166
|
|
|
22840
23167
|
// src/install-task.ts
|
|
22841
|
-
var
|
|
23168
|
+
var fs12 = __toESM(require("node:fs"), 1);
|
|
22842
23169
|
var os4 = __toESM(require("node:os"), 1);
|
|
22843
|
-
var
|
|
23170
|
+
var path12 = __toESM(require("node:path"), 1);
|
|
22844
23171
|
var import_node_child_process = require("node:child_process");
|
|
22845
|
-
var DEFAULT_TASK_ROOT =
|
|
23172
|
+
var DEFAULT_TASK_ROOT = path12.join(os4.tmpdir(), "zlt-mcp-install-tasks");
|
|
22846
23173
|
var STARTUP_GRACE_MS = 3e4;
|
|
22847
23174
|
function taskRoot() {
|
|
22848
23175
|
return process.env.ZLT_MCP_INSTALL_TASK_ROOT || DEFAULT_TASK_ROOT;
|
|
22849
23176
|
}
|
|
22850
23177
|
function taskPath(taskId) {
|
|
22851
|
-
return
|
|
23178
|
+
return path12.join(taskRoot(), `${taskId}.json`);
|
|
22852
23179
|
}
|
|
22853
|
-
function write(
|
|
22854
|
-
|
|
22855
|
-
const target = taskPath(
|
|
23180
|
+
function write(record4) {
|
|
23181
|
+
fs12.mkdirSync(taskRoot(), { recursive: true });
|
|
23182
|
+
const target = taskPath(record4.taskId);
|
|
22856
23183
|
const temporary = `${target}.${process.pid}.tmp`;
|
|
22857
|
-
|
|
23184
|
+
fs12.writeFileSync(temporary, `${JSON.stringify(record4)}
|
|
22858
23185
|
`, "utf8");
|
|
22859
|
-
|
|
23186
|
+
fs12.renameSync(temporary, target);
|
|
22860
23187
|
}
|
|
22861
23188
|
function readRaw(taskId) {
|
|
22862
23189
|
if (!/^[A-Za-z0-9_-]+$/.test(taskId)) return void 0;
|
|
22863
23190
|
try {
|
|
22864
|
-
const
|
|
22865
|
-
return
|
|
23191
|
+
const record4 = JSON.parse(fs12.readFileSync(taskPath(taskId), "utf8"));
|
|
23192
|
+
return record4.taskId === taskId ? record4 : void 0;
|
|
22866
23193
|
} catch {
|
|
22867
23194
|
return void 0;
|
|
22868
23195
|
}
|
|
22869
23196
|
}
|
|
22870
|
-
function active(
|
|
22871
|
-
return
|
|
23197
|
+
function active(record4) {
|
|
23198
|
+
return record4.status === "queued" || record4.status === "running";
|
|
22872
23199
|
}
|
|
22873
23200
|
function alive(pid) {
|
|
22874
23201
|
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
@@ -22893,7 +23220,7 @@ function readInstallTask(taskId) {
|
|
|
22893
23220
|
let pid = current.workerPid;
|
|
22894
23221
|
if (!pid) {
|
|
22895
23222
|
try {
|
|
22896
|
-
pid = Number(
|
|
23223
|
+
pid = Number(fs12.readFileSync(`${taskPath(taskId)}.pid`, "utf8"));
|
|
22897
23224
|
} catch {
|
|
22898
23225
|
}
|
|
22899
23226
|
}
|
|
@@ -22905,7 +23232,7 @@ function readInstallTask(taskId) {
|
|
|
22905
23232
|
function startInstallTask(entrypoint, argsJson, spawnProcess = import_node_child_process.spawn) {
|
|
22906
23233
|
let files = [];
|
|
22907
23234
|
try {
|
|
22908
|
-
files =
|
|
23235
|
+
files = fs12.readdirSync(taskRoot());
|
|
22909
23236
|
} catch (error2) {
|
|
22910
23237
|
if (error2.code !== "ENOENT") throw error2;
|
|
22911
23238
|
}
|
|
@@ -22916,17 +23243,17 @@ function startInstallTask(entrypoint, argsJson, spawnProcess = import_node_child
|
|
|
22916
23243
|
if (existing && active(existing)) return readInstallTask(taskId2);
|
|
22917
23244
|
}
|
|
22918
23245
|
const taskId = `install-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
|
|
22919
|
-
const
|
|
23246
|
+
const record4 = {
|
|
22920
23247
|
taskId,
|
|
22921
23248
|
status: "queued",
|
|
22922
23249
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
22923
23250
|
launcherPid: process.pid,
|
|
22924
|
-
logPath:
|
|
23251
|
+
logPath: path12.join(taskRoot(), `${taskId}.log`)
|
|
22925
23252
|
};
|
|
22926
|
-
write(
|
|
23253
|
+
write(record4);
|
|
22927
23254
|
let logFd;
|
|
22928
23255
|
try {
|
|
22929
|
-
logFd =
|
|
23256
|
+
logFd = fs12.openSync(record4.logPath, "a");
|
|
22930
23257
|
const child = spawnProcess(process.execPath, [entrypoint, "__install-worker", taskId, argsJson], {
|
|
22931
23258
|
detached: true,
|
|
22932
23259
|
stdio: ["ignore", logFd, logFd],
|
|
@@ -22939,12 +23266,12 @@ function startInstallTask(entrypoint, argsJson, spawnProcess = import_node_child
|
|
|
22939
23266
|
child.once("exit", (code, signal) => {
|
|
22940
23267
|
fail(taskId, `${INTERRUPTED} (exit=${code}, signal=${signal})`);
|
|
22941
23268
|
});
|
|
22942
|
-
if (child.pid)
|
|
23269
|
+
if (child.pid) fs12.writeFileSync(`${taskPath(taskId)}.pid`, String(child.pid), "utf8");
|
|
22943
23270
|
child.unref();
|
|
22944
23271
|
} catch (error2) {
|
|
22945
23272
|
fail(taskId, `\u5B89\u88C5\u5DE5\u4F5C\u8FDB\u7A0B\u542F\u52A8\u5931\u8D25: ${error2 instanceof Error ? error2.message : String(error2)}`);
|
|
22946
23273
|
} finally {
|
|
22947
|
-
if (logFd !== void 0)
|
|
23274
|
+
if (logFd !== void 0) fs12.closeSync(logFd);
|
|
22948
23275
|
}
|
|
22949
23276
|
return readRaw(taskId);
|
|
22950
23277
|
}
|
|
@@ -23030,8 +23357,8 @@ var NPM_PACKAGE_CONFIG_TOOL_NAMES = Object.freeze([
|
|
|
23030
23357
|
]);
|
|
23031
23358
|
|
|
23032
23359
|
// src/tool-pipeline.ts
|
|
23033
|
-
var
|
|
23034
|
-
var
|
|
23360
|
+
var fs14 = __toESM(require("node:fs"), 1);
|
|
23361
|
+
var path14 = __toESM(require("node:path"), 1);
|
|
23035
23362
|
var import_node_crypto3 = require("node:crypto");
|
|
23036
23363
|
|
|
23037
23364
|
// src/feature-set.ts
|
|
@@ -23042,8 +23369,8 @@ var MASKED_FACTOR_MESSAGE = "\u56E0\u5B50\u7814\u7A76\u529F\u80FD\u5728\u5F53\u5
|
|
|
23042
23369
|
var MASKED_FUTURES_MESSAGE = "\u671F\u8D27\u56DE\u6D4B\u5728\u5F53\u524D\u7248\u672C\u672A\u5F00\u653E\uFF1ArunParams.marketIds \u542B\u671F\u8D27\u4EA4\u6613\u6240\uFF08zj/zs/ds/sq/gq\uFF09\u6216 account_list \u7684 account_type \u4E3A\u671F\u8D27\u3002\u8BF7\u4F7F\u7528\u80A1\u7968\u5E02\u573A\uFF08sh/sz\uFF09\u4E0E account_type=1\u3002";
|
|
23043
23370
|
|
|
23044
23371
|
// src/backtest-config.ts
|
|
23045
|
-
var
|
|
23046
|
-
var
|
|
23372
|
+
var fs13 = __toESM(require("node:fs"), 1);
|
|
23373
|
+
var path13 = __toESM(require("node:path"), 1);
|
|
23047
23374
|
var import_node_crypto2 = require("node:crypto");
|
|
23048
23375
|
var BACKTEST_CONFIG_KEYS = [
|
|
23049
23376
|
"start",
|
|
@@ -23082,48 +23409,48 @@ var FEE_KEYS = [
|
|
|
23082
23409
|
"close_tax",
|
|
23083
23410
|
"margin_ratio"
|
|
23084
23411
|
];
|
|
23085
|
-
var
|
|
23412
|
+
var record3 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
23086
23413
|
var pick2 = (v, keys) => Object.fromEntries(keys.filter((k) => Object.prototype.hasOwnProperty.call(v, k)).map((k) => [k, v[k]]));
|
|
23087
23414
|
function readBacktestBaseline(tool, args) {
|
|
23088
23415
|
const create = tool === "mcp-create-and-run-backtest";
|
|
23089
23416
|
if (!create && tool !== "mcp-re-backtest") return void 0;
|
|
23090
23417
|
const directory = args[create ? "strategyPath" : "codePath"];
|
|
23091
23418
|
if (directory === void 0) return void 0;
|
|
23092
|
-
if (typeof directory !== "string" || !
|
|
23093
|
-
const root =
|
|
23094
|
-
if (create &&
|
|
23419
|
+
if (typeof directory !== "string" || !path13.isAbsolute(directory)) throw new Error("Configuration baseline requires an absolute directory path");
|
|
23420
|
+
const root = fs13.realpathSync(directory);
|
|
23421
|
+
if (create && path13.basename(path13.dirname(root)).toLowerCase() === "backtest") {
|
|
23095
23422
|
throw new Error("strategyPath must identify the strategy root, not a historical backtest directory");
|
|
23096
23423
|
}
|
|
23097
|
-
const file =
|
|
23098
|
-
const raw =
|
|
23424
|
+
const file = path13.join(root, ".vscode", "tradesetting.json");
|
|
23425
|
+
const raw = fs13.readFileSync(file);
|
|
23099
23426
|
let config2;
|
|
23100
23427
|
try {
|
|
23101
23428
|
config2 = JSON.parse(raw.toString("utf8").replace(/^\uFEFF/, ""));
|
|
23102
23429
|
} catch {
|
|
23103
23430
|
throw new Error("Configuration baseline is not valid JSON");
|
|
23104
23431
|
}
|
|
23105
|
-
if (!
|
|
23432
|
+
if (!record3(config2) || config2.strategy_id !== args.strategyId) throw new Error("Configuration baseline strategy_id is missing or mismatched");
|
|
23106
23433
|
if (!create && (typeof args.runId !== "string" || config2.backtest_id !== args.runId)) {
|
|
23107
23434
|
throw new Error("Configuration baseline backtest_id does not match the requested runId");
|
|
23108
23435
|
}
|
|
23109
23436
|
const params = pick2(config2, [...BACKTEST_CONFIG_KEYS, ...INTERNAL_CONFIG_KEYS]);
|
|
23110
23437
|
for (const key of ["base_tpl_obj", "ratio_tpl_obj"]) {
|
|
23111
|
-
if (params[key] !== void 0 && !
|
|
23438
|
+
if (params[key] !== void 0 && !record3(params[key])) throw new Error(`Configuration baseline ${key} must be an object`);
|
|
23112
23439
|
}
|
|
23113
|
-
if (
|
|
23114
|
-
if (
|
|
23440
|
+
if (record3(params.base_tpl_obj)) params.base_tpl_obj = pick2(params.base_tpl_obj, BASE_KEYS);
|
|
23441
|
+
if (record3(params.ratio_tpl_obj)) {
|
|
23115
23442
|
const fees = params.ratio_tpl_obj;
|
|
23116
23443
|
for (const asset of ["stock", "future", "fund", "bond"]) {
|
|
23117
|
-
if (fees[asset] !== void 0 && !
|
|
23444
|
+
if (fees[asset] !== void 0 && !record3(fees[asset])) throw new Error(`Configuration baseline fee section ${asset} must be an object`);
|
|
23118
23445
|
}
|
|
23119
23446
|
params.ratio_tpl_obj = {
|
|
23120
23447
|
...pick2(fees, ["name", "zhCnName"]),
|
|
23121
|
-
...Object.fromEntries(["stock", "future", "fund", "bond"].filter((k) =>
|
|
23448
|
+
...Object.fromEntries(["stock", "future", "fund", "bond"].filter((k) => record3(fees[k])).map((k) => [k, pick2(fees[k], FEE_KEYS)]))
|
|
23122
23449
|
};
|
|
23123
23450
|
}
|
|
23124
23451
|
if (Array.isArray(params.account_list)) {
|
|
23125
23452
|
params.account_list = params.account_list.map((account) => {
|
|
23126
|
-
if (!
|
|
23453
|
+
if (!record3(account)) throw new Error("Configuration baseline account_list contains a non-object");
|
|
23127
23454
|
const result = pick2(account, ["pindex", "account_id", "cash", "account_type"]);
|
|
23128
23455
|
if (create && typeof result.account_id === "string" && /^RN-[A-Za-z0-9-]+_\d+$/.test(result.account_id)) result.account_id = "";
|
|
23129
23456
|
return result;
|
|
@@ -23137,7 +23464,7 @@ function readBacktestBaseline(tool, args) {
|
|
|
23137
23464
|
}
|
|
23138
23465
|
function reconcileBaselineCapital(params, overrides) {
|
|
23139
23466
|
const accounts = params.account_list;
|
|
23140
|
-
if (!Array.isArray(accounts) || !accounts.length || accounts.some((a) => !
|
|
23467
|
+
if (!Array.isArray(accounts) || !accounts.length || accounts.some((a) => !record3(a) || typeof a.cash !== "number" || !Number.isFinite(a.cash) || a.cash < 0)) {
|
|
23141
23468
|
throw new Error("Configuration baseline requires accounts with finite nonnegative cash");
|
|
23142
23469
|
}
|
|
23143
23470
|
const explicitCapital = Object.prototype.hasOwnProperty.call(overrides, "initial_capital");
|
|
@@ -23227,7 +23554,7 @@ function prepareToolCallArgs(tool, args, contexts) {
|
|
|
23227
23554
|
}
|
|
23228
23555
|
function validateDataRangeArguments(args) {
|
|
23229
23556
|
const errors = [];
|
|
23230
|
-
const error2 = (
|
|
23557
|
+
const error2 = (path17, message) => errors.push({ path: path17, message });
|
|
23231
23558
|
const input = stripControlParams(args);
|
|
23232
23559
|
for (const key of Object.keys(input)) {
|
|
23233
23560
|
if (key !== "params") error2(`$.${key}`, "Unsupported top-level field; query combinations belong in params[]. Date filters are not accepted.");
|
|
@@ -23389,7 +23716,7 @@ function readSlaveProperties(filePath) {
|
|
|
23389
23716
|
const entries = /* @__PURE__ */ new Map();
|
|
23390
23717
|
let raw;
|
|
23391
23718
|
try {
|
|
23392
|
-
raw =
|
|
23719
|
+
raw = fs14.readFileSync(filePath, "utf-8");
|
|
23393
23720
|
} catch {
|
|
23394
23721
|
return entries;
|
|
23395
23722
|
}
|
|
@@ -23413,18 +23740,18 @@ function resolveFactorProjectRoot(clientRootDir) {
|
|
|
23413
23740
|
if (cached2) return cached2;
|
|
23414
23741
|
const root = clientRootDir.replace(/[\\/]+$/, "");
|
|
23415
23742
|
const configured = expandSlaveValue(
|
|
23416
|
-
readSlaveProperties(
|
|
23743
|
+
readSlaveProperties(path14.join(root, ...ZLTAF_CONFIG_SEGMENTS)),
|
|
23417
23744
|
"slave.factor.project-path",
|
|
23418
23745
|
root
|
|
23419
23746
|
);
|
|
23420
|
-
const resolved = configured ?
|
|
23747
|
+
const resolved = configured ? path14.normalize(configured) : path14.join(root, ...FALLBACK_FACTOR_PROJECT_PATH);
|
|
23421
23748
|
factorProjectRootCache.set(clientRootDir, resolved);
|
|
23422
23749
|
return resolved;
|
|
23423
23750
|
}
|
|
23424
23751
|
function resolveFactorWorkspacePath(clientRootDir, factorId) {
|
|
23425
23752
|
if (!clientRootDir || !factorId) return void 0;
|
|
23426
23753
|
const projectRoot = resolveFactorProjectRoot(clientRootDir);
|
|
23427
|
-
return projectRoot ?
|
|
23754
|
+
return projectRoot ? path14.join(projectRoot, factorId) : void 0;
|
|
23428
23755
|
}
|
|
23429
23756
|
var MODULE_LEVEL_FACTOR_EXPORT = /^(?:(?:async\s+)?def\s+get_factor\s*\(|get_factor\s*=(?!=)|Factor\s*=(?!=))/m;
|
|
23430
23757
|
function checkFactorSourceLoadable(clientRootDir, factorId) {
|
|
@@ -23432,7 +23759,7 @@ function checkFactorSourceLoadable(clientRootDir, factorId) {
|
|
|
23432
23759
|
if (!workspacePath) return null;
|
|
23433
23760
|
let source;
|
|
23434
23761
|
try {
|
|
23435
|
-
source =
|
|
23762
|
+
source = fs14.readFileSync(path14.join(workspacePath, "main.py"), "utf8");
|
|
23436
23763
|
} catch {
|
|
23437
23764
|
return null;
|
|
23438
23765
|
}
|
|
@@ -23675,18 +24002,18 @@ function backtestWindowPreflightError(tool, reason, message, details) {
|
|
|
23675
24002
|
}, true);
|
|
23676
24003
|
}
|
|
23677
24004
|
function isExistingAbsoluteDirectory(value) {
|
|
23678
|
-
if (!value || !
|
|
24005
|
+
if (!value || !path14.isAbsolute(value)) return false;
|
|
23679
24006
|
try {
|
|
23680
|
-
return
|
|
24007
|
+
return fs14.statSync(value).isDirectory();
|
|
23681
24008
|
} catch {
|
|
23682
24009
|
return false;
|
|
23683
24010
|
}
|
|
23684
24011
|
}
|
|
23685
24012
|
function readBacktestIdFromCodePath(codePath) {
|
|
23686
24013
|
try {
|
|
23687
|
-
const tradesettingPath =
|
|
23688
|
-
if (!
|
|
23689
|
-
const parsed = JSON.parse(
|
|
24014
|
+
const tradesettingPath = path14.join(codePath, ".vscode", "tradesetting.json");
|
|
24015
|
+
if (!fs14.existsSync(tradesettingPath)) return void 0;
|
|
24016
|
+
const parsed = JSON.parse(fs14.readFileSync(tradesettingPath, "utf-8"));
|
|
23690
24017
|
if (!isRecord2(parsed)) return void 0;
|
|
23691
24018
|
const value = parsed.backtest_id ?? parsed.backtestId;
|
|
23692
24019
|
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
@@ -24383,9 +24710,9 @@ var FACTOR_FAILURE_SIGNATURES = [
|
|
|
24383
24710
|
function factorFailureMessage(data) {
|
|
24384
24711
|
if (typeof data.errorMessage === "string" && data.errorMessage) return data.errorMessage;
|
|
24385
24712
|
for (const key of ["calculateRecord", "detectRecord"]) {
|
|
24386
|
-
const
|
|
24387
|
-
if (isRecord2(
|
|
24388
|
-
return
|
|
24713
|
+
const record4 = data[key];
|
|
24714
|
+
if (isRecord2(record4) && typeof record4.errorMessage === "string" && record4.errorMessage) {
|
|
24715
|
+
return record4.errorMessage;
|
|
24389
24716
|
}
|
|
24390
24717
|
}
|
|
24391
24718
|
return "";
|
|
@@ -24437,14 +24764,14 @@ var BACKTEST_WAIT_POLL_IDENTITY = {
|
|
|
24437
24764
|
};
|
|
24438
24765
|
function sleepUnlessAborted(ms, abortSignal) {
|
|
24439
24766
|
if (abortSignal?.aborted) return Promise.resolve();
|
|
24440
|
-
return new Promise((
|
|
24767
|
+
return new Promise((resolve9) => {
|
|
24441
24768
|
const onAbort = () => {
|
|
24442
24769
|
clearTimeout(timer);
|
|
24443
|
-
|
|
24770
|
+
resolve9();
|
|
24444
24771
|
};
|
|
24445
24772
|
const timer = setTimeout(() => {
|
|
24446
24773
|
abortSignal?.removeEventListener("abort", onAbort);
|
|
24447
|
-
|
|
24774
|
+
resolve9();
|
|
24448
24775
|
}, ms);
|
|
24449
24776
|
abortSignal?.addEventListener("abort", onAbort, { once: true });
|
|
24450
24777
|
});
|
|
@@ -24863,11 +25190,11 @@ function applyBacktestResultGuards(tool, args, result, states, contexts, activeR
|
|
|
24863
25190
|
}
|
|
24864
25191
|
function readRunResultFile(codePath) {
|
|
24865
25192
|
try {
|
|
24866
|
-
const resultPath =
|
|
24867
|
-
if (!
|
|
24868
|
-
const before =
|
|
24869
|
-
const raw =
|
|
24870
|
-
const after =
|
|
25193
|
+
const resultPath = path14.join(codePath, "log", "result.json");
|
|
25194
|
+
if (!fs14.existsSync(resultPath)) return null;
|
|
25195
|
+
const before = fs14.statSync(resultPath);
|
|
25196
|
+
const raw = fs14.readFileSync(resultPath);
|
|
25197
|
+
const after = fs14.statSync(resultPath);
|
|
24871
25198
|
if (before.mtimeMs !== after.mtimeMs || before.size !== after.size) return null;
|
|
24872
25199
|
const parsed = JSON.parse(raw.toString("utf-8"));
|
|
24873
25200
|
if (!isRecord2(parsed)) return null;
|
|
@@ -25082,9 +25409,9 @@ function echoResolvedBacktestConfig(tool, args, result, contexts) {
|
|
|
25082
25409
|
function hashBacktestSource(codePath) {
|
|
25083
25410
|
if (!codePath) return void 0;
|
|
25084
25411
|
try {
|
|
25085
|
-
const sourcePath =
|
|
25086
|
-
if (!
|
|
25087
|
-
return (0, import_node_crypto3.createHash)("sha256").update(
|
|
25412
|
+
const sourcePath = path14.join(codePath, "main.py");
|
|
25413
|
+
if (!fs14.statSync(sourcePath).isFile()) return void 0;
|
|
25414
|
+
return (0, import_node_crypto3.createHash)("sha256").update(fs14.readFileSync(sourcePath)).digest("hex");
|
|
25088
25415
|
} catch {
|
|
25089
25416
|
return void 0;
|
|
25090
25417
|
}
|
|
@@ -25130,7 +25457,7 @@ function resolveBacktestBenchmark(runParams) {
|
|
|
25130
25457
|
var STRATEGY_DOCS_TOOLS = /* @__PURE__ */ new Set(["mcp-create-strategy", "mcp-create-strategy-with-template"]);
|
|
25131
25458
|
function resolveStrategyDocsPath(clientRootDir) {
|
|
25132
25459
|
if (!clientRootDir) return void 0;
|
|
25133
|
-
const docsPath =
|
|
25460
|
+
const docsPath = path14.join(
|
|
25134
25461
|
clientRootDir,
|
|
25135
25462
|
"python",
|
|
25136
25463
|
"Lib",
|
|
@@ -25140,7 +25467,7 @@ function resolveStrategyDocsPath(clientRootDir) {
|
|
|
25140
25467
|
"docs"
|
|
25141
25468
|
);
|
|
25142
25469
|
try {
|
|
25143
|
-
if (!
|
|
25470
|
+
if (!fs14.existsSync(docsPath)) return void 0;
|
|
25144
25471
|
} catch {
|
|
25145
25472
|
return void 0;
|
|
25146
25473
|
}
|
|
@@ -25157,7 +25484,7 @@ function injectDebugRunId(tool, result) {
|
|
|
25157
25484
|
const localPath = typeof parsed.Data.localPath === "string" ? parsed.Data.localPath.trim() : "";
|
|
25158
25485
|
if (!localPath) return result;
|
|
25159
25486
|
const settings = JSON.parse(
|
|
25160
|
-
|
|
25487
|
+
fs14.readFileSync(path14.join(localPath, ".vscode", "tradesetting.json"), "utf8")
|
|
25161
25488
|
);
|
|
25162
25489
|
const debugRunId = isRecord2(settings) && typeof settings.backtest_id === "string" ? settings.backtest_id.trim() : "";
|
|
25163
25490
|
if (!debugRunId) return result;
|
|
@@ -25653,12 +25980,12 @@ function preflightCreatedBacktestSource(toolName, body) {
|
|
|
25653
25980
|
if (toolName !== "mcp-create-and-run-backtest") return null;
|
|
25654
25981
|
const runId = typeof body.runId === "string" ? body.runId.trim() : "";
|
|
25655
25982
|
const codePath = typeof body.codePath === "string" ? body.codePath.trim() : "";
|
|
25656
|
-
if (!codePath || !
|
|
25657
|
-
const sourcePath =
|
|
25658
|
-
if (!
|
|
25983
|
+
if (!codePath || !fs14.existsSync(codePath)) return null;
|
|
25984
|
+
const sourcePath = path14.join(codePath, "main.py");
|
|
25985
|
+
if (!fs14.existsSync(sourcePath)) return null;
|
|
25659
25986
|
let source;
|
|
25660
25987
|
try {
|
|
25661
|
-
source =
|
|
25988
|
+
source = fs14.readFileSync(sourcePath, "utf8");
|
|
25662
25989
|
} catch (error2) {
|
|
25663
25990
|
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
25664
25991
|
return jsonToolResult(10061, "\u56DE\u6D4B\u4EE3\u7801\u5FEB\u7167\u65E0\u6CD5\u8BFB\u53D6\uFF0C\u672A\u542F\u52A8\u7B56\u7565\u5F15\u64CE\u3002", {
|
|
@@ -25898,7 +26225,7 @@ function normalizeDataRoot(raw, clientRootDir) {
|
|
|
25898
26225
|
}
|
|
25899
26226
|
function readJsonFile(filePath) {
|
|
25900
26227
|
try {
|
|
25901
|
-
const parsed = JSON.parse(
|
|
26228
|
+
const parsed = JSON.parse(fs14.readFileSync(filePath, "utf-8"));
|
|
25902
26229
|
return isRecord2(parsed) ? parsed : void 0;
|
|
25903
26230
|
} catch {
|
|
25904
26231
|
return void 0;
|
|
@@ -25912,8 +26239,8 @@ function resolveDataRoots(clientRootDir) {
|
|
|
25912
26239
|
const cached2 = Date.now() - readAt < DATA_ROOTS_TTL_MS ? dataRootsCache.get(clientRootDir) : void 0;
|
|
25913
26240
|
if (cached2) return cached2;
|
|
25914
26241
|
const root = clientRootDir.replace(/[\\/]+$/, "");
|
|
25915
|
-
const dcSdk = readJsonFile(
|
|
25916
|
-
const dcm = readJsonFile(
|
|
26242
|
+
const dcSdk = readJsonFile(path14.join(root, ...DC_SDK_CONFIG_SEGMENTS));
|
|
26243
|
+
const dcm = readJsonFile(path14.join(root, ...DCM_CONFIG_SEGMENTS));
|
|
25917
26244
|
const engineRoot = normalizeDataRoot(isRecord2(dcSdk?.mdf) ? dcSdk.mdf.path : void 0, root);
|
|
25918
26245
|
const downloadRoot = normalizeDataRoot(dcm?.download_home, root);
|
|
25919
26246
|
const resolved = Boolean(engineRoot && downloadRoot);
|
|
@@ -25943,9 +26270,9 @@ function hqSeriesFromResults(resultItems) {
|
|
|
25943
26270
|
function engineHasAnyHqSeries(engineRoot, series) {
|
|
25944
26271
|
if (!engineRoot || series.length === 0) return void 0;
|
|
25945
26272
|
for (const { exchangeId, dataType } of series) {
|
|
25946
|
-
const dir =
|
|
26273
|
+
const dir = path14.join(engineRoot, "hqdata", "his", exchangeId, dataType);
|
|
25947
26274
|
try {
|
|
25948
|
-
if (
|
|
26275
|
+
if (fs14.existsSync(dir) && fs14.readdirSync(dir).length > 0) return true;
|
|
25949
26276
|
} catch {
|
|
25950
26277
|
return void 0;
|
|
25951
26278
|
}
|
|
@@ -27386,8 +27713,8 @@ async function waitForInstallTask(taskId, control, doctor) {
|
|
|
27386
27713
|
}, !ready);
|
|
27387
27714
|
}
|
|
27388
27715
|
if (task.status === "failed") return jsonToolResult(10012, task.error || "runtime \u5B89\u88C5\u5931\u8D25\u3002", { ...task, isTerminal: true, nextAction: "inspect-error" }, true);
|
|
27389
|
-
await new Promise((
|
|
27390
|
-
const timer = setTimeout(
|
|
27716
|
+
await new Promise((resolve9, reject) => {
|
|
27717
|
+
const timer = setTimeout(resolve9, 2e3);
|
|
27391
27718
|
control.abortSignal?.addEventListener("abort", () => {
|
|
27392
27719
|
clearTimeout(timer);
|
|
27393
27720
|
reject(new Error("aborted"));
|
|
@@ -27597,7 +27924,7 @@ function syncCredentialsFromEnvAtStartup() {
|
|
|
27597
27924
|
function inspectDoctorAuth() {
|
|
27598
27925
|
try {
|
|
27599
27926
|
const auth = getAuthStatus();
|
|
27600
|
-
const invalidFile = !auth.configured &&
|
|
27927
|
+
const invalidFile = !auth.configured && fs15.existsSync(auth.credentialsPath);
|
|
27601
27928
|
return {
|
|
27602
27929
|
configured: auth.configured,
|
|
27603
27930
|
status: auth.configured ? "configured" : invalidFile ? "invalid-config" : "missing",
|
|
@@ -27733,7 +28060,16 @@ function writeCliArgumentError(message, write2) {
|
|
|
27733
28060
|
if (process.argv.length <= 2) {
|
|
27734
28061
|
startMcpServer();
|
|
27735
28062
|
} else {
|
|
28063
|
+
let evidence;
|
|
28064
|
+
let evidenceSetupError;
|
|
28065
|
+
try {
|
|
28066
|
+
const directory = evidenceDirectoryArg(process.argv.slice(2));
|
|
28067
|
+
if (directory !== void 0) evidence = new CliEvidence(directory, resolveCliPackageProvenance(), process.argv[2]);
|
|
28068
|
+
} catch (error2) {
|
|
28069
|
+
evidenceSetupError = error2;
|
|
28070
|
+
}
|
|
27736
28071
|
const program2 = new Command();
|
|
28072
|
+
if (evidence) program2.exitOverride();
|
|
27737
28073
|
program2.command("__install-worker <taskId> <argsJson>", { hidden: true }).action(async (taskId, argsJson) => {
|
|
27738
28074
|
await runInstallWorker(taskId, argsJson, async (args, onProgress) => installRuntime({
|
|
27739
28075
|
config: loadAssistantRuntimeConfig(resolveDefaultRuntimeConfigPath?.()),
|
|
@@ -27748,58 +28084,21 @@ if (process.argv.length <= 2) {
|
|
|
27748
28084
|
}));
|
|
27749
28085
|
});
|
|
27750
28086
|
program2.name(CLI_NAME).description("MCP proxy for ZLTHost IPC service").version(resolveCliVersion()).configureOutput({ outputError: writeCliArgumentError }).addHelpText("after", "\nDiscovery: list for names; list --tool <name> --json for one complete input schema.\nUse call --help for input, output and diagnostic handling.\nFor npx registry selection, put --registry before the package name; it is not a zlt-mcp option.");
|
|
27751
|
-
program2.command("call <tool>").description("Call any MCP tool through the bundled MCP server").configureOutput({ outputError: writeCliArgumentError }).option("--args-json <json>", "JSON object containing tool arguments").option("--args-file <path>", "Read the JSON argument object from a file").option("--output-json <path>", "Save the complete result to a new JSON file and print a compact receipt").option("--timeout-ms <ms>", "MCP request inactivity timeout in milliseconds").option("--max-total-timeout-ms <ms>", "Optional hard upper bound for the call, including install/backtest wait").option("--no-progress", "Suppress progress diagnostics on stderr").addHelpText("after",
|
|
27752
|
-
Input: omitted arguments mean {}; use --args-json for small objects and --args-file
|
|
27753
|
-
for nested configuration or shell-sensitive text. Follow the selected tool schema
|
|
27754
|
-
from list --tool <name> --json. Windows paths must be native paths (C:/...), not /c/....
|
|
27755
|
-
Tool schema properties are JSON keys, NOT CLI flags: use --args-json '{"params": [...]}'
|
|
27756
|
-
for a tool's params property, not --params. Pass the complete argument object.
|
|
27757
|
-
Output: by default stdout contains the complete MCP JSON envelope plus cliProvenance.
|
|
27758
|
-
JSON business responses are inside content[].text (or structuredContent when present).
|
|
27759
|
-
Use --output-json for large results or downstream evidence: it saves the complete
|
|
27760
|
-
envelope and prints only a compact receipt. The parent directory must exist and the
|
|
27761
|
-
file must be new. A receipt is not the full business response.
|
|
27762
|
-
Installation: call zlt-runtime-install stays running through mcp-wait on the same
|
|
27763
|
-
connection and returns the terminal install result. Keep the host command alive;
|
|
27764
|
-
use its supported background-task mode if needed. Task ID/log path are on stderr.
|
|
27765
|
-
Install progress includes the current component, step percentage and elapsed time;
|
|
27766
|
-
step percentages may reset between components. Base installer success is not runtime
|
|
27767
|
-
readiness. If stderr is redirected, read that log while the background task runs.
|
|
27768
|
-
Omit --max-total-timeout-ms unless a hard deadline is required; it can interrupt
|
|
27769
|
-
a healthy first install while dependencies are still being installed.
|
|
27770
|
-
Timeout or cancellation leaves the install outcome unknown; inspect before retrying.
|
|
27771
|
-
Backtests: create-and-run/re-backtest keep the same MCP consumer until mcp-wait
|
|
27772
|
-
returns a terminal state or requires action (such as no-progress). The JSON keeps
|
|
27773
|
-
launch identity/configuration plus authoritative wait state. No detached keeper.
|
|
27774
|
-
Progress messages distinguish data preparation from strategy execution and report
|
|
27775
|
-
elapsed time and unchanged observations. Unchanged progress is not proof of failure.
|
|
27776
|
-
Read redirected stderr during background waits; do not restart on a progress warning.
|
|
27777
|
-
If isTerminal=true, finalize that run directly; do not wait again. The total timeout
|
|
27778
|
-
covers launch plus wait. Interrupted waits print backtest runId/codePath/attemptFence
|
|
27779
|
-
for recovery; the runtime may stop when the host closes. Never restart automatically.
|
|
27780
|
-
Diagnostics: preserve stderr separately and check this process's exit code before
|
|
27781
|
-
parsing output. Do not discard stderr, merge it into JSON, or pipe calls through
|
|
27782
|
-
head/tail/parsers that can hide the CLI exit code. --no-progress only disables progress.
|
|
27783
|
-
If saving fails after execution, the complete response is on stdout; preserve it
|
|
27784
|
-
and inspect the returned state before retrying any operation that may have run.
|
|
27785
|
-
Thrown call failures emit Error: followed by JSON on stderr with stage, message,
|
|
27786
|
-
toolExecution and retry. not_started means the CLI did not call the tool; correct
|
|
27787
|
-
the input/path before retrying. unknown means execution may have occurred (including
|
|
27788
|
-
transport or keepalive failure); inspect state first. response_received means a
|
|
27789
|
-
response was received, not that the business succeeded; inspect that result first.
|
|
27790
|
-
Credentials belong in the configured local credential store, never in arguments.
|
|
27791
|
-
`).action(async (tool, options) => {
|
|
28087
|
+
program2.command("call <tool>").description("Call any MCP tool through the bundled MCP server").configureOutput({ outputError: writeCliArgumentError }).option("--args-json <json>", "JSON object containing tool arguments").option("--args-file <path>", "Read the JSON argument object from a file").option("--output-json <path>", "Save the complete result to a new JSON file and print a compact receipt").option("--evidence-dir <path>", "Create a new directory for the result, diagnostics and execution status").option("--timeout-ms <ms>", "MCP request inactivity timeout in milliseconds").option("--max-total-timeout-ms <ms>", "Optional hard upper bound for the call, including install/backtest wait").option("--no-progress", "Suppress progress diagnostics on stderr").addHelpText("after", COMMON_CALL_HELP).action(async (tool, options) => {
|
|
27792
28088
|
let outputFd;
|
|
27793
28089
|
let stage = "arguments";
|
|
27794
28090
|
let toolExecution = "not_started";
|
|
28091
|
+
let business = "not_reported";
|
|
27795
28092
|
try {
|
|
28093
|
+
if (evidence && options.outputJson !== void 0) throw new Error("Use only one of --evidence-dir and --output-json");
|
|
27796
28094
|
const args = parseMcpArgs(options.argsJson, options.argsFile);
|
|
27797
28095
|
const timeoutMs = parseTimeoutOption(options.timeoutMs, "--timeout-ms");
|
|
27798
28096
|
const maxTotalTimeoutMs = parseTimeoutOption(options.maxTotalTimeoutMs, "--max-total-timeout-ms");
|
|
27799
|
-
const resultFile = options.outputJson === void 0 ? void 0 :
|
|
28097
|
+
const resultFile = evidence?.resultFile ?? (options.outputJson === void 0 ? void 0 : path16.resolve(options.outputJson));
|
|
27800
28098
|
stage = "output_prepare";
|
|
27801
|
-
if (resultFile !== void 0) outputFd =
|
|
28099
|
+
if (resultFile !== void 0) outputFd = fs16.openSync(resultFile, "wx");
|
|
27802
28100
|
stage = "tool_call";
|
|
28101
|
+
evidence?.started(tool);
|
|
27803
28102
|
toolExecution = "unknown";
|
|
27804
28103
|
const result = await callMcpTool(tool, args, {
|
|
27805
28104
|
timeoutMs,
|
|
@@ -27809,19 +28108,24 @@ Credentials belong in the configured local credential store, never in arguments.
|
|
|
27809
28108
|
toolExecution = "response_received";
|
|
27810
28109
|
stage = "output_serialize";
|
|
27811
28110
|
const complete = withCliProvenance(result);
|
|
28111
|
+
business = businessOutcome(result);
|
|
28112
|
+
const exitCode = business === "error" ? 1 : 0;
|
|
28113
|
+
if (exitCode !== 0) process.exitCode = exitCode;
|
|
27812
28114
|
const serialized = JSON.stringify(complete) + "\n";
|
|
27813
28115
|
if (outputFd !== void 0 && resultFile !== void 0) {
|
|
27814
28116
|
stage = "output_write";
|
|
27815
28117
|
try {
|
|
27816
|
-
|
|
27817
|
-
|
|
28118
|
+
fs16.writeFileSync(outputFd, serialized, "utf-8");
|
|
28119
|
+
const fd = outputFd;
|
|
27818
28120
|
outputFd = void 0;
|
|
28121
|
+
fs16.closeSync(fd);
|
|
27819
28122
|
} catch (error2) {
|
|
27820
28123
|
process.stdout.write(serialized);
|
|
27821
28124
|
throw new Error(`Tool returned a result, but saving ${resultFile} failed; complete result is on stdout. Do not repeat the tool automatically. ${String(error2)}`);
|
|
27822
28125
|
}
|
|
27823
28126
|
stage = "output_emit";
|
|
27824
|
-
|
|
28127
|
+
evidence?.completed(business, exitCode);
|
|
28128
|
+
const receipt = { ...compactCliReceipt(tool, complete, resultFile), ...evidence?.receiptFields() };
|
|
27825
28129
|
process.stdout.write(JSON.stringify(receipt) + "\n");
|
|
27826
28130
|
if (!receipt.ok) process.exitCode = 1;
|
|
27827
28131
|
} else {
|
|
@@ -27838,28 +28142,69 @@ Credentials belong in the configured local credential store, never in arguments.
|
|
|
27838
28142
|
stage,
|
|
27839
28143
|
toolExecution,
|
|
27840
28144
|
retry,
|
|
28145
|
+
...evidence?.receiptFields(),
|
|
27841
28146
|
...typeof code === "string" ? { code } : {},
|
|
27842
28147
|
...error2?.backtest ? { backtest: error2.backtest } : {},
|
|
27843
28148
|
message
|
|
27844
28149
|
})}
|
|
27845
28150
|
`);
|
|
27846
28151
|
process.exitCode = 1;
|
|
28152
|
+
try {
|
|
28153
|
+
evidence?.failed(stage, toolExecution, business);
|
|
28154
|
+
} catch (saveError) {
|
|
28155
|
+
process.stderr.write(`Error: execution evidence could not be finalized: ${String(saveError)}
|
|
28156
|
+
`);
|
|
28157
|
+
}
|
|
27847
28158
|
} finally {
|
|
27848
|
-
if (outputFd !== void 0)
|
|
28159
|
+
if (outputFd !== void 0) {
|
|
28160
|
+
const fd = outputFd;
|
|
28161
|
+
outputFd = void 0;
|
|
28162
|
+
try {
|
|
28163
|
+
fs16.closeSync(fd);
|
|
28164
|
+
} catch (error2) {
|
|
28165
|
+
process.exitCode = 1;
|
|
28166
|
+
process.stderr.write(`Error: result file close failed; toolExecution=${toolExecution}; ${String(error2)}
|
|
28167
|
+
`);
|
|
28168
|
+
try {
|
|
28169
|
+
evidence?.failed("output_close", toolExecution, business);
|
|
28170
|
+
} catch (saveError) {
|
|
28171
|
+
process.stderr.write(`Error: execution evidence could not be finalized: ${String(saveError)}
|
|
28172
|
+
`);
|
|
28173
|
+
}
|
|
28174
|
+
}
|
|
28175
|
+
}
|
|
27849
28176
|
}
|
|
27850
28177
|
});
|
|
27851
|
-
program2.command("list").description("List MCP tools exposed by the bundled server").option("--json", "Emit the complete tools/list response as JSON").option("--tool <name>", "Select one exact tool name; combine with --json for its complete schema").addHelpText("after", "\nReuse discovery within a task. Query one schema with list --tool <name> --json.\nUnknown names fail with exit code 1. Preserve stderr separately from JSON stdout.").action(async (options) => {
|
|
28178
|
+
program2.command("list").description("List MCP tools exposed by the bundled server").option("--json", "Emit the complete tools/list response as JSON").option("--tool <name>", "Select one exact tool name; combine with --json for its complete schema").option("--evidence-dir <path>", "Create a new directory for discovery, diagnostics and execution status").addHelpText("after", "\nReuse discovery within a task. Query one schema with list --tool <name> --json.\nUnknown names fail with exit code 1. Preserve stderr separately from JSON stdout.").action(async (options) => {
|
|
28179
|
+
let toolExecution = "not_started";
|
|
27852
28180
|
try {
|
|
28181
|
+
evidence?.started();
|
|
28182
|
+
toolExecution = "unknown";
|
|
27853
28183
|
let result = await listMcpTools();
|
|
28184
|
+
toolExecution = "response_received";
|
|
27854
28185
|
if (options.tool !== void 0) {
|
|
27855
28186
|
const tools2 = Array.isArray(result.tools) ? result.tools.filter((tool) => tool.name === options.tool) : [];
|
|
27856
28187
|
if (tools2.length === 0) throw new Error(`Unknown tool: ${options.tool}. Use list to discover available names.`);
|
|
27857
|
-
result = { ...result, tools: tools2, cliUsage:
|
|
27858
|
-
|
|
27859
|
-
|
|
27860
|
-
|
|
27861
|
-
|
|
27862
|
-
|
|
28188
|
+
result = { ...result, tools: tools2, cliUsage: buildCliUsage(tools2[0], result.tools) };
|
|
28189
|
+
}
|
|
28190
|
+
if (evidence) {
|
|
28191
|
+
const complete = withCliProvenance(result);
|
|
28192
|
+
const serialized = JSON.stringify(complete) + "\n";
|
|
28193
|
+
try {
|
|
28194
|
+
fs16.writeFileSync(evidence.resultFile, serialized, { encoding: "utf8", flag: "wx" });
|
|
28195
|
+
evidence.completed("not_reported", 0);
|
|
28196
|
+
} catch (error2) {
|
|
28197
|
+
process.stdout.write(serialized);
|
|
28198
|
+
throw error2;
|
|
28199
|
+
}
|
|
28200
|
+
process.stdout.write(JSON.stringify({
|
|
28201
|
+
ok: true,
|
|
28202
|
+
command: "list",
|
|
28203
|
+
resultFile: evidence.resultFile,
|
|
28204
|
+
cliProvenance: complete.cliProvenance,
|
|
28205
|
+
...evidence.receiptFields()
|
|
28206
|
+
}) + "\n");
|
|
28207
|
+
return;
|
|
27863
28208
|
}
|
|
27864
28209
|
if (options.json) {
|
|
27865
28210
|
process.stdout.write(JSON.stringify(withCliProvenance(result)) + "\n");
|
|
@@ -27877,6 +28222,12 @@ Credentials belong in the configured local credential store, never in arguments.
|
|
|
27877
28222
|
process.stderr.write(`Error: ${message}
|
|
27878
28223
|
`);
|
|
27879
28224
|
process.exitCode = 1;
|
|
28225
|
+
try {
|
|
28226
|
+
evidence?.failed("discovery", toolExecution);
|
|
28227
|
+
} catch (saveError) {
|
|
28228
|
+
process.stderr.write(`Error: execution evidence could not be finalized: ${String(saveError)}
|
|
28229
|
+
`);
|
|
28230
|
+
}
|
|
27880
28231
|
}
|
|
27881
28232
|
});
|
|
27882
28233
|
program2.command("exec").description("Execute an IPC tool call").allowUnknownOption().allowExcessArguments(true).action(async () => {
|
|
@@ -27919,28 +28270,66 @@ Credentials belong in the configured local credential store, never in arguments.
|
|
|
27919
28270
|
const configPath = resolveDefaultConfigPath();
|
|
27920
28271
|
generateSkills(configPath, { output: options.output, stdout: options.stdout });
|
|
27921
28272
|
});
|
|
27922
|
-
|
|
27923
|
-
|
|
27924
|
-
process.stderr.write(`Error: ${message}
|
|
28273
|
+
if (evidenceSetupError) {
|
|
28274
|
+
process.stderr.write(`Error: evidence setup failed; toolExecution=not_started; ${String(evidenceSetupError)}
|
|
27925
28275
|
`);
|
|
27926
28276
|
process.exitCode = 1;
|
|
27927
|
-
}
|
|
28277
|
+
} else {
|
|
28278
|
+
void program2.parseAsync().catch((error2) => {
|
|
28279
|
+
const informational = error2 instanceof CommanderError && error2.exitCode === 0;
|
|
28280
|
+
if (informational) {
|
|
28281
|
+
try {
|
|
28282
|
+
evidence?.helpDisplayed();
|
|
28283
|
+
} catch (saveError) {
|
|
28284
|
+
process.stderr.write(`Error: execution evidence could not be finalized: ${String(saveError)}
|
|
28285
|
+
`);
|
|
28286
|
+
process.exitCode = 1;
|
|
28287
|
+
}
|
|
28288
|
+
} else {
|
|
28289
|
+
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
28290
|
+
if (!(error2 instanceof CommanderError)) process.stderr.write(`Error: ${message}
|
|
28291
|
+
`);
|
|
28292
|
+
process.exitCode = 1;
|
|
28293
|
+
try {
|
|
28294
|
+
if (error2 instanceof CommanderError) evidence?.failed("arguments", "not_started");
|
|
28295
|
+
else evidence?.failedCurrent("cli_error");
|
|
28296
|
+
} catch (saveError) {
|
|
28297
|
+
process.stderr.write(`Error: execution evidence could not be finalized: ${String(saveError)}
|
|
28298
|
+
`);
|
|
28299
|
+
}
|
|
28300
|
+
}
|
|
28301
|
+
}).finally(() => {
|
|
28302
|
+
try {
|
|
28303
|
+
evidence?.close();
|
|
28304
|
+
} catch (error2) {
|
|
28305
|
+
process.exitCode = 1;
|
|
28306
|
+
process.stderr.write(`Error: diagnostics close failed: ${String(error2)}
|
|
28307
|
+
`);
|
|
28308
|
+
try {
|
|
28309
|
+
evidence?.failedCurrent("diagnostics_close");
|
|
28310
|
+
} catch (saveError) {
|
|
28311
|
+
process.stderr.write(`Error: execution evidence could not be finalized: ${String(saveError)}
|
|
28312
|
+
`);
|
|
28313
|
+
}
|
|
28314
|
+
}
|
|
28315
|
+
});
|
|
28316
|
+
}
|
|
27928
28317
|
}
|
|
27929
28318
|
function resolveCliVersion() {
|
|
27930
28319
|
return resolveCliPackageProvenance().packageVersion;
|
|
27931
28320
|
}
|
|
27932
28321
|
function resolveCliPackageProvenance() {
|
|
27933
|
-
let current =
|
|
28322
|
+
let current = path16.dirname(path16.resolve(process.argv[1] || process.cwd()));
|
|
27934
28323
|
for (let depth = 0; depth < 6; depth += 1) {
|
|
27935
|
-
const manifestPath =
|
|
28324
|
+
const manifestPath = path16.join(current, "package.json");
|
|
27936
28325
|
try {
|
|
27937
|
-
const manifest = JSON.parse(
|
|
28326
|
+
const manifest = JSON.parse(fs16.readFileSync(manifestPath, "utf-8"));
|
|
27938
28327
|
if ((manifest.name === "@zltquant/zlt-mcp" || manifest.name === "zlt-mcp-proxy") && typeof manifest.version === "string") {
|
|
27939
28328
|
return { packageName: manifest.name, packageVersion: manifest.version };
|
|
27940
28329
|
}
|
|
27941
28330
|
} catch {
|
|
27942
28331
|
}
|
|
27943
|
-
const parent =
|
|
28332
|
+
const parent = path16.dirname(current);
|
|
27944
28333
|
if (parent === current) break;
|
|
27945
28334
|
current = parent;
|
|
27946
28335
|
}
|
|
@@ -27949,6 +28338,11 @@ function resolveCliPackageProvenance() {
|
|
|
27949
28338
|
function withCliProvenance(result) {
|
|
27950
28339
|
return { ...result, cliProvenance: resolveCliPackageProvenance() };
|
|
27951
28340
|
}
|
|
28341
|
+
function businessOutcome(result) {
|
|
28342
|
+
const code = parseMcpResult(result)?.ErrNo;
|
|
28343
|
+
if (result.isError === true || code !== void 0 && code !== null && Number(code) !== 0) return "error";
|
|
28344
|
+
return code === void 0 || code === null ? "not_reported" : "success";
|
|
28345
|
+
}
|
|
27952
28346
|
function compactCliReceipt(tool, result, resultFile) {
|
|
27953
28347
|
const payload = parseMcpResult(result);
|
|
27954
28348
|
const code = payload?.ErrNo;
|