dsh-plugin-opc 0.1.29 → 0.1.30

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/lib/index.js CHANGED
@@ -431,9 +431,9 @@ var AuthManager = class extends EventEmitter {
431
431
  }
432
432
  })();
433
433
  });
434
- await new Promise((resolve, reject) => {
434
+ await new Promise((resolve2, reject) => {
435
435
  server.once("error", reject);
436
- server.listen(0, "127.0.0.1", resolve);
436
+ server.listen(0, "127.0.0.1", resolve2);
437
437
  });
438
438
  const address = server.address();
439
439
  if (!address || typeof address === "string") {
@@ -588,17 +588,17 @@ function unsafe() {
588
588
  throw new OpcError("SKILL_PACKAGE_UNSAFE");
589
589
  }
590
590
  async function extract(bytes, root) {
591
- const zip = await new Promise((resolve, reject) => fromBuffer(bytes, { lazyEntries: true, validateEntrySizes: true, strictFileNames: true }, (error, value) => error || !value ? reject(error) : resolve(value)));
591
+ const zip = await new Promise((resolve2, reject) => fromBuffer(bytes, { lazyEntries: true, validateEntrySizes: true, strictFileNames: true }, (error, value) => error || !value ? reject(error) : resolve2(value)));
592
592
  const names = /* @__PURE__ */ new Set(), skillPaths = [];
593
593
  let entries = 0, files = 0, total = 0;
594
594
  try {
595
- await new Promise((resolve, reject) => {
595
+ await new Promise((resolve2, reject) => {
596
596
  const fail = (error) => {
597
597
  zip.close();
598
598
  reject(error);
599
599
  };
600
600
  zip.on("error", fail);
601
- zip.on("end", resolve);
601
+ zip.on("end", resolve2);
602
602
  zip.on("entry", (entry) => {
603
603
  void (async () => {
604
604
  const name2 = entry.fileName;
@@ -1225,9 +1225,9 @@ var ManagedMcpMounts = class {
1225
1225
  }
1226
1226
  })();
1227
1227
  });
1228
- await new Promise((resolve, reject) => {
1228
+ await new Promise((resolve2, reject) => {
1229
1229
  server.once("error", reject);
1230
- server.listen(0, "127.0.0.1", resolve);
1230
+ server.listen(0, "127.0.0.1", resolve2);
1231
1231
  });
1232
1232
  try {
1233
1233
  captured.assertCurrent();
@@ -1742,8 +1742,8 @@ var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [
1742
1742
  dirty = false;
1743
1743
  yield await this.state();
1744
1744
  }
1745
- if (!dirty && !signal.aborted) await new Promise((resolve) => {
1746
- wake = resolve;
1745
+ if (!dirty && !signal.aborted) await new Promise((resolve2) => {
1746
+ wake = resolve2;
1747
1747
  });
1748
1748
  }
1749
1749
  } finally {
@@ -1953,15 +1953,450 @@ function registerTools(ctx, core) {
1953
1953
  }
1954
1954
 
1955
1955
  // src/host/app-delivery.ts
1956
- import { createWriteStream, existsSync as existsSync2 } from "node:fs";
1957
- import { spawn } from "node:child_process";
1956
+ import { createWriteStream, existsSync as existsSync3 } from "node:fs";
1957
+ import { spawn as spawn2 } from "node:child_process";
1958
1958
  import { createHash as createHash5, randomUUID as randomUUID4 } from "node:crypto";
1959
1959
  import { copyFile, link, lstat as lstat2, mkdir as mkdir3, readFile as readFile2, readdir as readdir2, stat, writeFile as writeFile3, rename as rename3, rm as rm2 } from "node:fs/promises";
1960
- import { dirname as dirname3, isAbsolute, join as join3 } from "node:path";
1961
- import { homedir } from "node:os";
1960
+ import { dirname as dirname3, isAbsolute, join as join3, resolve } from "node:path";
1961
+ import { homedir as homedir2 } from "node:os";
1962
1962
  import { Transform } from "node:stream";
1963
1963
  import { pipeline } from "node:stream/promises";
1964
1964
  import { fileURLToPath } from "node:url";
1965
+
1966
+ // src/host/python-runtime.ts
1967
+ import { execFile as execFile2, spawn } from "node:child_process";
1968
+ import { existsSync as existsSync2, readdirSync } from "node:fs";
1969
+ import { homedir } from "node:os";
1970
+ import { posix, win32 } from "node:path";
1971
+ import { promisify as promisify2 } from "node:util";
1972
+ var execFileAsync2 = promisify2(execFile2);
1973
+ var PROBE_SCRIPT = 'import json, sys; print(json.dumps({"v": list(sys.version_info[:2]), "exe": sys.executable}))';
1974
+ var MIN_PYTHON_MAJOR = 3;
1975
+ var MIN_PYTHON_MINOR = 9;
1976
+ var WINDOWS_APPS_SEGMENT = /[\\/]Microsoft[\\/]WindowsApps(?:[\\/]|$)/i;
1977
+ var WINDOWS_SAFE_ENV_KEYS = /* @__PURE__ */ new Set([
1978
+ "systemroot",
1979
+ "windir",
1980
+ "systemdrive",
1981
+ "userprofile",
1982
+ "homedrive",
1983
+ "homepath",
1984
+ "localappdata",
1985
+ "appdata",
1986
+ "programdata",
1987
+ "temp",
1988
+ "tmp",
1989
+ "comspec",
1990
+ "pathext"
1991
+ ]);
1992
+ function workerEnv(platform2 = process.platform, sourceEnv = process.env) {
1993
+ const env = { LANG: "en_US.UTF-8" };
1994
+ const pathValue = sourceEnv.PATH ?? sourceEnv.Path;
1995
+ if (pathValue !== void 0) env.PATH = pathValue;
1996
+ if (sourceEnv.HOME !== void 0) env.HOME = sourceEnv.HOME;
1997
+ if (platform2 === "win32") {
1998
+ const seen = /* @__PURE__ */ new Set(["lang", "path", "home"]);
1999
+ for (const [key, value] of Object.entries(sourceEnv)) {
2000
+ if (value === void 0) continue;
2001
+ const lower = key.toLowerCase();
2002
+ if (!WINDOWS_SAFE_ENV_KEYS.has(lower) || seen.has(lower)) continue;
2003
+ seen.add(lower);
2004
+ env[key] = value;
2005
+ }
2006
+ }
2007
+ return env;
2008
+ }
2009
+ function isSupportedVersion(version) {
2010
+ return Array.isArray(version) && version.length >= 2 && typeof version[0] === "number" && typeof version[1] === "number" && (version[0] > MIN_PYTHON_MAJOR || version[0] === MIN_PYTHON_MAJOR && version[1] >= MIN_PYTHON_MINOR);
2011
+ }
2012
+ function safeReadDir(readDir, dir) {
2013
+ try {
2014
+ return readDir(dir);
2015
+ } catch {
2016
+ return [];
2017
+ }
2018
+ }
2019
+ function versionSortKey(name2) {
2020
+ const dotted = name2.match(/(\d+)\.(\d+)/);
2021
+ if (dotted) {
2022
+ const base = Number.parseInt(dotted[1], 10) * 1e3 + Number.parseInt(dotted[2], 10);
2023
+ return base * 2 + (/-32$/i.test(name2) ? 0 : 1);
2024
+ }
2025
+ const compact = name2.match(/python(\d)(\d+)/i);
2026
+ if (compact) {
2027
+ const base = Number.parseInt(compact[1], 10) * 1e3 + Number.parseInt(compact[2], 10);
2028
+ return base * 2 + (/-32$/i.test(name2) ? 0 : 1);
2029
+ }
2030
+ return 0;
2031
+ }
2032
+ function isWindowsAppsPath(pathValue) {
2033
+ return WINDOWS_APPS_SEGMENT.test(pathValue);
2034
+ }
2035
+ function candidateKey(candidate, platform2) {
2036
+ const pathApi = platform2 === "win32" ? win32 : posix;
2037
+ const normalizedCmd = pathApi.isAbsolute(candidate.command) ? pathApi.normalize(candidate.command) : candidate.command;
2038
+ const cmdKey = platform2 === "win32" ? normalizedCmd.toLowerCase() : normalizedCmd;
2039
+ return `${cmdKey}\0${candidate.prefixArgs.join("\0")}`;
2040
+ }
2041
+ function bundledPythonCandidates(options = {}) {
2042
+ const platform2 = options.platform ?? process.platform;
2043
+ const pathApi = platform2 === "win32" ? win32 : posix;
2044
+ const execPath = options.execPath ?? process.execPath;
2045
+ const resourcesPath = options.resourcesPath ?? process.resourcesPath;
2046
+ const env = options.env ?? process.env;
2047
+ const homeDir = options.homeDir ?? homedir();
2048
+ const exists = options.exists ?? existsSync2;
2049
+ const executable = pathApi.dirname(execPath);
2050
+ const dshHome = env.DSH_HOME?.trim() || pathApi.join(homeDir, ".dsh");
2051
+ const runtimeDirs = [
2052
+ env.DSH_PRIMARY_RUNTIME_DIR?.trim(),
2053
+ env.DSH_DESKTOP_PRIMARY_RUNTIME_DIR?.trim()
2054
+ ].filter((value) => Boolean(value));
2055
+ const relExecutables = platform2 === "win32" ? ["dependencies/python/python.exe"] : ["dependencies/python/bin/python3", "dependencies/python/bin/python"];
2056
+ const paths = [];
2057
+ for (const dir of runtimeDirs) {
2058
+ for (const rel of relExecutables) paths.push(pathApi.join(dir, rel));
2059
+ }
2060
+ if (resourcesPath) {
2061
+ for (const rel of relExecutables) paths.push(pathApi.join(resourcesPath, "runtime/primary-runtime", rel));
2062
+ }
2063
+ if (platform2 === "win32") {
2064
+ paths.push(
2065
+ pathApi.join(executable, "resources/runtime/primary-runtime/dependencies/python/python.exe"),
2066
+ pathApi.join(executable, "../resources/runtime/primary-runtime/dependencies/python/python.exe"),
2067
+ pathApi.join(executable, "../../python/python.exe"),
2068
+ pathApi.join(dshHome, "dsh-runtimes/dsh-primary-runtime/dependencies/python/python.exe")
2069
+ );
2070
+ } else {
2071
+ paths.push(
2072
+ pathApi.join(executable, "../Resources/runtime/primary-runtime/dependencies/python/bin/python3"),
2073
+ pathApi.join(executable, "../resources/runtime/primary-runtime/dependencies/python/bin/python3"),
2074
+ pathApi.join(executable, "../../python/bin/python3"),
2075
+ pathApi.join(dshHome, "dsh-runtimes/dsh-primary-runtime/dependencies/python/bin/python3")
2076
+ );
2077
+ }
2078
+ const seen = /* @__PURE__ */ new Set();
2079
+ const result = [];
2080
+ for (const candidatePath of paths) {
2081
+ const key = platform2 === "win32" ? pathApi.normalize(candidatePath).toLowerCase() : pathApi.normalize(candidatePath);
2082
+ if (seen.has(key)) continue;
2083
+ seen.add(key);
2084
+ if (exists(candidatePath)) {
2085
+ result.push({ command: candidatePath, prefixArgs: [] });
2086
+ }
2087
+ }
2088
+ return result;
2089
+ }
2090
+ function parseWindowsRegistryPythonPaths(output) {
2091
+ const results = [];
2092
+ let inInstallPath = false;
2093
+ for (const rawLine of output.split(/\r?\n/)) {
2094
+ const line = rawLine.trim();
2095
+ if (!line) continue;
2096
+ if (/^HKEY_/i.test(line)) {
2097
+ inInstallPath = /\\InstallPath$/i.test(line);
2098
+ continue;
2099
+ }
2100
+ if (!inInstallPath) continue;
2101
+ const execMatch = line.match(/^ExecutablePath\s+REG_(?:SZ|EXPAND_SZ)\s+(.+)$/i);
2102
+ if (execMatch?.[1]) {
2103
+ results.push(execMatch[1].trim());
2104
+ continue;
2105
+ }
2106
+ const defaultMatch = line.match(/^\([^)]+\)\s+REG_(?:SZ|EXPAND_SZ)\s+(.+)$/i);
2107
+ if (defaultMatch?.[1]) {
2108
+ const base = defaultMatch[1].trim();
2109
+ if (base) results.push(/\.exe$/i.test(base) ? base : win32.join(base, "python.exe"));
2110
+ }
2111
+ }
2112
+ return results;
2113
+ }
2114
+ async function defaultQueryWindowsRegistry() {
2115
+ const roots = [
2116
+ "HKCU\\SOFTWARE\\Python",
2117
+ "HKLM\\SOFTWARE\\Python",
2118
+ "HKLM\\SOFTWARE\\WOW6432Node\\Python"
2119
+ ];
2120
+ const found = [];
2121
+ for (const root of roots) {
2122
+ try {
2123
+ const { stdout } = await execFileAsync2("reg.exe", ["query", root, "/s"], {
2124
+ timeout: 3e3,
2125
+ windowsHide: true
2126
+ });
2127
+ found.push(...parseWindowsRegistryPythonPaths(stdout));
2128
+ } catch {
2129
+ }
2130
+ }
2131
+ return found;
2132
+ }
2133
+ function windowsInstallDirCandidates(options = {}) {
2134
+ const env = options.env ?? process.env;
2135
+ const homeDir = options.homeDir ?? homedir();
2136
+ const exists = options.exists ?? existsSync2;
2137
+ const readDir = options.readDir ?? ((dir) => readdirSync(dir));
2138
+ const userProfile = env.USERPROFILE?.trim() || homeDir;
2139
+ const localAppData = env.LOCALAPPDATA?.trim() || win32.join(userProfile, "AppData", "Local");
2140
+ const appData = env.APPDATA?.trim() || win32.join(userProfile, "AppData", "Roaming");
2141
+ const programFiles = env.ProgramFiles?.trim() || "C:\\Program Files";
2142
+ const programFilesX86 = env["ProgramFiles(x86)"]?.trim() || "C:\\Program Files (x86)";
2143
+ const programData = env.ProgramData?.trim() || "C:\\ProgramData";
2144
+ const systemDrive = env.SystemDrive?.trim() || "C:";
2145
+ const rootDrive = systemDrive.endsWith("\\") ? systemDrive : `${systemDrive}\\`;
2146
+ const candidatePaths = [];
2147
+ const versionedParents = [
2148
+ win32.join(localAppData, "Programs", "Python"),
2149
+ programFiles,
2150
+ programFilesX86,
2151
+ rootDrive
2152
+ ];
2153
+ for (const parent of versionedParents) {
2154
+ const dirs = safeReadDir(readDir, parent).filter((name2) => /^Python3\d*(?:-[A-Za-z0-9_]+)?$/i.test(name2)).sort((a, b) => versionSortKey(b) - versionSortKey(a));
2155
+ for (const dir of dirs) {
2156
+ candidatePaths.push(win32.join(parent, dir, "python.exe"), win32.join(parent, dir, "python3.exe"));
2157
+ }
2158
+ }
2159
+ for (const uvRoot of [win32.join(localAppData, "uv", "python"), win32.join(appData, "uv", "python")]) {
2160
+ const dirs = safeReadDir(readDir, uvRoot).filter((name2) => /^cpython-3\./i.test(name2)).sort((a, b) => versionSortKey(b) - versionSortKey(a));
2161
+ for (const dir of dirs) {
2162
+ candidatePaths.push(win32.join(uvRoot, dir, "python.exe"));
2163
+ }
2164
+ }
2165
+ const pyenvVersionsDir = win32.join(userProfile, ".pyenv", "pyenv-win", "versions");
2166
+ for (const dir of safeReadDir(readDir, pyenvVersionsDir).filter((name2) => /^3\./.test(name2)).sort((a, b) => versionSortKey(b) - versionSortKey(a))) {
2167
+ candidatePaths.push(win32.join(pyenvVersionsDir, dir, "python.exe"));
2168
+ }
2169
+ const scoopApps = win32.join(userProfile, "scoop", "apps");
2170
+ for (const dir of safeReadDir(readDir, scoopApps).filter((name2) => /^python/i.test(name2)).sort((a, b) => versionSortKey(b) - versionSortKey(a))) {
2171
+ candidatePaths.push(win32.join(scoopApps, dir, "current", "python.exe"));
2172
+ }
2173
+ candidatePaths.push(win32.join(userProfile, "scoop", "shims", "python.exe"));
2174
+ const chocoBase = env.ChocolateyInstall?.trim() || win32.join(programData, "chocolatey");
2175
+ candidatePaths.push(win32.join(chocoBase, "bin", "python.exe"), win32.join(chocoBase, "bin", "python3.exe"));
2176
+ for (const condaRoot of [
2177
+ win32.join(userProfile, "miniconda3"),
2178
+ win32.join(userProfile, "anaconda3"),
2179
+ win32.join(userProfile, "miniforge3"),
2180
+ win32.join(userProfile, "mambaforge"),
2181
+ win32.join(localAppData, "miniconda3"),
2182
+ win32.join(localAppData, "anaconda3"),
2183
+ win32.join(localAppData, "miniforge3"),
2184
+ win32.join(programData, "miniconda3"),
2185
+ win32.join(programData, "anaconda3"),
2186
+ win32.join(programData, "miniforge3")
2187
+ ]) {
2188
+ candidatePaths.push(win32.join(condaRoot, "python.exe"));
2189
+ }
2190
+ const seen = /* @__PURE__ */ new Set();
2191
+ const result = [];
2192
+ for (const candidatePath of candidatePaths) {
2193
+ const key = win32.normalize(candidatePath).toLowerCase();
2194
+ if (seen.has(key)) continue;
2195
+ seen.add(key);
2196
+ if (exists(candidatePath)) {
2197
+ result.push({ command: candidatePath, prefixArgs: [] });
2198
+ }
2199
+ }
2200
+ return result;
2201
+ }
2202
+ function pathCandidates(options) {
2203
+ const { platform: platform2, env, exists } = options;
2204
+ const pathApi = platform2 === "win32" ? win32 : posix;
2205
+ const rawPath = env.PATH ?? env.Path ?? "";
2206
+ const pathSep = platform2 === "win32" ? ";" : ":";
2207
+ const entries = rawPath.split(pathSep).map((entry) => entry.trim().replace(/^"+|"+$/g, "")).filter(Boolean);
2208
+ const names = platform2 === "win32" ? ["python3.exe", "python.exe"] : ["python3", "python"];
2209
+ const regular = [];
2210
+ const windowsApps = [];
2211
+ for (const dir of entries) {
2212
+ const targetList = platform2 === "win32" && isWindowsAppsPath(dir) ? windowsApps : regular;
2213
+ for (const name2 of names) {
2214
+ const fullPath = pathApi.join(dir, name2);
2215
+ if (exists(fullPath)) {
2216
+ targetList.push({ command: fullPath, prefixArgs: [] });
2217
+ }
2218
+ }
2219
+ }
2220
+ if (platform2 !== "win32") {
2221
+ regular.push({ command: "python3", prefixArgs: [] }, { command: "python", prefixArgs: [] });
2222
+ }
2223
+ return { regular, windowsApps };
2224
+ }
2225
+ function windowsLauncherCandidates(options) {
2226
+ const { env, homeDir, exists } = options;
2227
+ const systemRoot = env.SystemRoot?.trim() || env.SYSTEMROOT?.trim() || env.WINDIR?.trim() || "C:\\Windows";
2228
+ const userProfile = env.USERPROFILE?.trim() || homeDir;
2229
+ const localAppData = env.LOCALAPPDATA?.trim() || win32.join(userProfile, "AppData", "Local");
2230
+ const paths = [
2231
+ win32.join(systemRoot, "py.exe"),
2232
+ win32.join(localAppData, "Programs", "Python", "Launcher", "py.exe")
2233
+ ];
2234
+ const rawPath = env.PATH ?? env.Path ?? "";
2235
+ for (const dir of rawPath.split(";").map((entry) => entry.trim().replace(/^"+|"+$/g, "")).filter(Boolean)) {
2236
+ paths.push(win32.join(dir, "py.exe"));
2237
+ }
2238
+ const seen = /* @__PURE__ */ new Set();
2239
+ const result = [];
2240
+ for (const candidatePath of paths) {
2241
+ const key = win32.normalize(candidatePath).toLowerCase();
2242
+ if (seen.has(key)) continue;
2243
+ seen.add(key);
2244
+ if (exists(candidatePath)) {
2245
+ result.push({ command: candidatePath, prefixArgs: ["-3"] });
2246
+ }
2247
+ }
2248
+ return result;
2249
+ }
2250
+ async function defaultProbePython(candidate, env, signal) {
2251
+ return new Promise((resolve2) => {
2252
+ let settled = false;
2253
+ const finish = (result) => {
2254
+ if (settled) return;
2255
+ settled = true;
2256
+ resolve2(result);
2257
+ };
2258
+ let child;
2259
+ try {
2260
+ child = spawn(candidate.command, [...candidate.prefixArgs, "-I", "-B", "-X", "utf8", "-c", PROBE_SCRIPT], {
2261
+ stdio: ["ignore", "pipe", "ignore"],
2262
+ env,
2263
+ signal,
2264
+ timeout: 5e3,
2265
+ windowsHide: true
2266
+ });
2267
+ } catch {
2268
+ finish({ ok: false });
2269
+ return;
2270
+ }
2271
+ let stdout = "";
2272
+ child.stdout.setEncoding("utf8");
2273
+ child.stdout.on("data", (chunk) => {
2274
+ if (stdout.length < 4096) stdout += chunk;
2275
+ });
2276
+ child.on("error", () => finish({ ok: false }));
2277
+ child.on("close", (code) => {
2278
+ if (code !== 0) {
2279
+ finish({ ok: false });
2280
+ return;
2281
+ }
2282
+ try {
2283
+ const parsed = JSON.parse(stdout.trim());
2284
+ if (!isSupportedVersion(parsed.v)) {
2285
+ finish({ ok: false });
2286
+ return;
2287
+ }
2288
+ finish({
2289
+ ok: true,
2290
+ version: [parsed.v[0], parsed.v[1]],
2291
+ executable: typeof parsed.exe === "string" && parsed.exe ? parsed.exe : void 0
2292
+ });
2293
+ } catch {
2294
+ finish({ ok: false });
2295
+ }
2296
+ });
2297
+ });
2298
+ }
2299
+ var cachedResolution;
2300
+ function resetPythonResolutionCache() {
2301
+ cachedResolution = void 0;
2302
+ }
2303
+ async function discoverPython(options = {}) {
2304
+ const platform2 = options.platform ?? process.platform;
2305
+ const env = options.env ?? process.env;
2306
+ const homeDir = options.homeDir ?? homedir();
2307
+ const exists = options.exists ?? existsSync2;
2308
+ const readDir = options.readDir ?? ((dir) => readdirSync(dir));
2309
+ const queryRegistry = options.queryRegistry ?? defaultQueryWindowsRegistry;
2310
+ const probe = options.probe ?? defaultProbePython;
2311
+ const childEnv = workerEnv(platform2, env);
2312
+ const tried = /* @__PURE__ */ new Set();
2313
+ const tryCandidates = async (candidates) => {
2314
+ for (const candidate of candidates) {
2315
+ options.signal?.throwIfAborted();
2316
+ const key = candidateKey(candidate, platform2);
2317
+ if (tried.has(key)) continue;
2318
+ tried.add(key);
2319
+ const result = await probe(candidate, childEnv, options.signal);
2320
+ options.signal?.throwIfAborted();
2321
+ if (!result.ok) continue;
2322
+ if (candidate.prefixArgs.length > 0 && result.executable && exists(result.executable)) {
2323
+ const direct = { command: result.executable, prefixArgs: [] };
2324
+ const directProbe = await probe(direct, childEnv, options.signal);
2325
+ options.signal?.throwIfAborted();
2326
+ if (directProbe.ok) return direct;
2327
+ }
2328
+ return candidate;
2329
+ }
2330
+ return void 0;
2331
+ };
2332
+ const bundledMatch = await tryCandidates(bundledPythonCandidates({
2333
+ platform: platform2,
2334
+ execPath: options.execPath,
2335
+ resourcesPath: options.resourcesPath,
2336
+ env,
2337
+ homeDir,
2338
+ exists
2339
+ }));
2340
+ if (bundledMatch) return bundledMatch;
2341
+ const fromPath = pathCandidates({ platform: platform2, env, exists });
2342
+ const pathMatch = await tryCandidates(fromPath.regular);
2343
+ if (pathMatch) return pathMatch;
2344
+ if (platform2 === "win32") {
2345
+ const launcherMatch = await tryCandidates(windowsLauncherCandidates({ env, homeDir, exists }));
2346
+ if (launcherMatch) return launcherMatch;
2347
+ const dirMatch = await tryCandidates(windowsInstallDirCandidates({ env, homeDir, exists, readDir }));
2348
+ if (dirMatch) return dirMatch;
2349
+ const registryPaths = await queryRegistry();
2350
+ const registryCandidates = registryPaths.filter((p) => exists(p)).map((p) => ({ command: p, prefixArgs: [] }));
2351
+ const registryMatch = await tryCandidates(registryCandidates);
2352
+ if (registryMatch) return registryMatch;
2353
+ const userProfile = env.USERPROFILE?.trim() || homeDir;
2354
+ const localAppData = env.LOCALAPPDATA?.trim() || win32.join(userProfile, "AppData", "Local");
2355
+ const storeCandidates = [...fromPath.windowsApps];
2356
+ for (const name2 of ["python3.exe", "python.exe"]) {
2357
+ const storePath = win32.join(localAppData, "Microsoft", "WindowsApps", name2);
2358
+ if (exists(storePath)) storeCandidates.push({ command: storePath, prefixArgs: [] });
2359
+ }
2360
+ const storeMatch = await tryCandidates(storeCandidates);
2361
+ if (storeMatch) return storeMatch;
2362
+ }
2363
+ throw new Error("\u9700\u8981 Python 3.9 \u6216\u4EE5\u4E0A\u7248\u672C\uFF1A\u8BF7\u5B89\u88C5\u540E\u91CD\u65B0\u6253\u5F00 DSH\u3002\u539F\u9879\u76EE\u672A\u6539\u52A8\u3002");
2364
+ }
2365
+ async function awaitWithAbort(promise, signal) {
2366
+ if (!signal) return promise;
2367
+ signal.throwIfAborted();
2368
+ return new Promise((resolve2, reject) => {
2369
+ const onAbort = () => reject(signal.reason instanceof Error ? signal.reason : new Error("Aborted"));
2370
+ signal.addEventListener("abort", onAbort, { once: true });
2371
+ promise.then(
2372
+ (value) => {
2373
+ signal.removeEventListener("abort", onAbort);
2374
+ resolve2(value);
2375
+ },
2376
+ (error) => {
2377
+ signal.removeEventListener("abort", onAbort);
2378
+ reject(error);
2379
+ }
2380
+ );
2381
+ });
2382
+ }
2383
+ async function resolvePythonInterpreter(options = {}) {
2384
+ options.signal?.throwIfAborted();
2385
+ if (options.useCache === false) {
2386
+ return discoverPython(options);
2387
+ }
2388
+ if (!cachedResolution) {
2389
+ const { signal: _signal, ...sharedOptions } = options;
2390
+ const pending = discoverPython(sharedOptions).catch((error) => {
2391
+ if (cachedResolution === pending) cachedResolution = void 0;
2392
+ throw error;
2393
+ });
2394
+ cachedResolution = pending;
2395
+ }
2396
+ return awaitWithAbort(cachedResolution, options.signal);
2397
+ }
2398
+
2399
+ // src/host/app-delivery.ts
1965
2400
  var ROLLBACK_NOTICE = "\u56DE\u6EDA\u6062\u590D\u4EE3\u7801\u4E0E\u8FD0\u884C\u914D\u7F6E\uFF0C\u4E0D\u81EA\u52A8\u56DE\u9000\u6570\u636E\u5E93/\u5377\u4E2D\u7684\u4E1A\u52A1\u6570\u636E\uFF1B\u65E7\u4EE3\u7801\u548C\u65B0\u6570\u636E\u517C\u5BB9\u6027\u4ECD\u9700\u9A8C\u8BC1\u3002";
1966
2401
  function analysisQuestions(proposal) {
1967
2402
  const pendingAccount = proposal?.adminAccountPending ? [`\u8BF7${proposal?.contract?.admin_account?.mode === "create" ? "\u8BBE\u7F6E" : "\u586B\u5199\u5DF2\u6709\u7684"}\u7BA1\u7406\u5458\u8D26\u53F7\u548C\u5BC6\u7801\uFF0C\u76F4\u63A5\u5728\u5F53\u524D\u5BF9\u8BDD\u6309\u4E24\u884C\u56DE\u590D\u300C\u8D26\u53F7\uFF1A\u2026\u300D\u548C\u300C\u5BC6\u7801\uFF1A\u2026\u300D\u3002`] : [];
@@ -2027,41 +2462,115 @@ function contains(actual, expected) {
2027
2462
  if (expected && typeof expected === "object") return actual !== null && typeof actual === "object" && Object.entries(expected).every(([k, v]) => contains(actual[k], v));
2028
2463
  return actual === expected;
2029
2464
  }
2030
- function worker(input, signal) {
2031
- const path = fileURLToPath(new URL("../../runtime/worker.py", import.meta.url));
2032
- const runtime = import.meta.url.endsWith("/lib/index.js") ? fileURLToPath(new URL("../runtime/worker.py", import.meta.url)) : path;
2033
- const executable = dirname3(process.execPath);
2034
- const bundled = [
2035
- join3(executable, "../Resources/runtime/primary-runtime/dependencies/python/bin/python3"),
2036
- join3(executable, "../../python/bin/python3")
2037
- ].find((candidate) => existsSync2(candidate));
2038
- return new Promise((resolve, reject) => {
2039
- const child = spawn(bundled ?? "python3", ["-I", "-B", runtime], { stdio: ["pipe", "pipe", "pipe"], env: { PATH: process.env.PATH, HOME: process.env.HOME, LANG: "en_US.UTF-8" }, signal, timeout: 12e4 });
2040
- let stdout = "", stderr = "", exceeded = false;
2041
- child.stdout.on("data", (data) => {
2042
- stdout += data;
2043
- if (stdout.length > 8e6) {
2044
- exceeded = true;
2045
- child.kill();
2046
- }
2047
- });
2048
- child.stderr.on("data", (data) => {
2049
- if (stderr.length < 2e3) stderr += data;
2050
- });
2051
- child.on("error", (error) => reject(new Error(error.message.includes("ENOENT") ? "\u9700\u8981 Python 3.9 \u6216\u4EE5\u4E0A\u7248\u672C\uFF1A\u8BF7\u5B89\u88C5\u540E\u91CD\u65B0\u6253\u5F00 DSH\u3002\u539F\u9879\u76EE\u672A\u6539\u52A8\u3002" : error.message)));
2052
- child.on("close", () => {
2053
- if (exceeded) return reject(new Error("\u5206\u6790\u8F93\u51FA\u8D85\u8FC7\u9650\u5236\uFF0C\u8BF7\u7F29\u5C0F\u8BFB\u53D6\u8303\u56F4"));
2465
+ var workerQueues = /* @__PURE__ */ new Map();
2466
+ async function serializeByRoot(rootKey, signal, fn) {
2467
+ if (!rootKey) return fn();
2468
+ const resolved = resolve(rootKey);
2469
+ const key = process.platform === "win32" ? resolved.toLowerCase() : resolved;
2470
+ const previous = workerQueues.get(key) ?? Promise.resolve();
2471
+ let release;
2472
+ const gate = new Promise((resolveGate) => {
2473
+ release = resolveGate;
2474
+ });
2475
+ const tail = previous.catch(() => {
2476
+ }).then(() => gate);
2477
+ workerQueues.set(key, tail);
2478
+ void tail.finally(() => {
2479
+ if (workerQueues.get(key) === tail) workerQueues.delete(key);
2480
+ });
2481
+ try {
2482
+ if (signal) {
2483
+ signal.throwIfAborted();
2484
+ let onAbort;
2054
2485
  try {
2055
- const result = JSON.parse(stdout);
2056
- if (!result.ok) throw new Error(result.error);
2057
- resolve(result.value);
2058
- } catch (error) {
2059
- reject(new Error(stdout ? error instanceof Error ? error.message : String(error) : `\u5E94\u7528\u51C6\u5907\u5DE5\u5177\u672A\u80FD\u542F\u52A8\uFF1A${stderr.slice(0, 500)}`));
2486
+ await Promise.race([
2487
+ previous.catch(() => {
2488
+ }),
2489
+ new Promise((_, reject) => {
2490
+ onAbort = () => reject(signal.reason instanceof Error ? signal.reason : new Error("Aborted"));
2491
+ signal.addEventListener("abort", onAbort, { once: true });
2492
+ })
2493
+ ]);
2494
+ } finally {
2495
+ if (onAbort) signal.removeEventListener("abort", onAbort);
2060
2496
  }
2497
+ } else {
2498
+ await previous.catch(() => {
2499
+ });
2500
+ }
2501
+ signal?.throwIfAborted();
2502
+ return await fn();
2503
+ } finally {
2504
+ release();
2505
+ }
2506
+ }
2507
+ async function renameWithRetry(src, dest) {
2508
+ const retryable = /* @__PURE__ */ new Set(["EPERM", "EBUSY", "EACCES"]);
2509
+ for (let attempt = 0; ; attempt++) {
2510
+ try {
2511
+ await rename3(src, dest);
2512
+ return;
2513
+ } catch (error) {
2514
+ const code = error?.code;
2515
+ if (process.platform === "win32" && code && retryable.has(code) && attempt < 6) {
2516
+ await new Promise((resolve2) => setTimeout(resolve2, 15 * (attempt + 1)));
2517
+ continue;
2518
+ }
2519
+ throw error;
2520
+ }
2521
+ }
2522
+ }
2523
+ async function worker(input, signal) {
2524
+ const rootKey = typeof input?.root === "string" && input.root ? input.root : void 0;
2525
+ return serializeByRoot(rootKey, signal, async () => {
2526
+ const path = fileURLToPath(new URL("../../runtime/worker.py", import.meta.url));
2527
+ const runtime = import.meta.url.endsWith("/lib/index.js") ? fileURLToPath(new URL("../runtime/worker.py", import.meta.url)) : path;
2528
+ const python = await resolvePythonInterpreter({ signal });
2529
+ return new Promise((resolve2, reject) => {
2530
+ const child = spawn2(python.command, [...python.prefixArgs, "-I", "-B", "-X", "utf8", runtime], {
2531
+ stdio: ["pipe", "pipe", "pipe"],
2532
+ env: workerEnv(),
2533
+ signal,
2534
+ timeout: 12e4,
2535
+ windowsHide: true
2536
+ });
2537
+ let stdout = "", stderr = "", exceeded = false;
2538
+ child.stdout.setEncoding("utf8");
2539
+ child.stderr.setEncoding("utf8");
2540
+ child.stdout.on("data", (data) => {
2541
+ stdout += data;
2542
+ if (stdout.length > 8e6) {
2543
+ exceeded = true;
2544
+ child.kill();
2545
+ }
2546
+ });
2547
+ child.stderr.on("data", (data) => {
2548
+ if (stderr.length < 2e3) stderr += data;
2549
+ });
2550
+ child.on("error", (error) => {
2551
+ if (error.message.includes("ENOENT")) resetPythonResolutionCache();
2552
+ reject(new Error(error.message.includes("ENOENT") ? "\u9700\u8981 Python 3.9 \u6216\u4EE5\u4E0A\u7248\u672C\uFF1A\u8BF7\u5B89\u88C5\u540E\u91CD\u65B0\u6253\u5F00 DSH\u3002\u539F\u9879\u76EE\u672A\u6539\u52A8\u3002" : error.message));
2553
+ });
2554
+ child.on("close", (code, closeSignal) => {
2555
+ if (exceeded) return reject(new Error("\u5206\u6790\u8F93\u51FA\u8D85\u8FC7\u9650\u5236\uFF0C\u8BF7\u7F29\u5C0F\u8BFB\u53D6\u8303\u56F4"));
2556
+ try {
2557
+ const result = JSON.parse(stdout);
2558
+ if (!result.ok) throw new Error(result.error);
2559
+ resolve2(result.value);
2560
+ } catch (error) {
2561
+ if (stdout) {
2562
+ reject(new Error(error instanceof Error ? error.message : String(error)));
2563
+ return;
2564
+ }
2565
+ const trimmedStderr = stderr.trim().slice(0, 500);
2566
+ const detail = trimmedStderr ? `\uFF1A${trimmedStderr}` : closeSignal ? `\uFF08\u8FDB\u7A0B\u88AB\u4FE1\u53F7 ${closeSignal} \u4E2D\u6B62\uFF09` : code !== 0 && code !== null ? `\uFF08\u9000\u51FA\u7801 ${code}\uFF09` : "\uFF08\u672A\u8FD4\u56DE\u4EFB\u4F55\u8F93\u51FA\uFF09";
2567
+ reject(new Error(`\u5E94\u7528\u51C6\u5907\u5DE5\u5177\u672A\u80FD\u542F\u52A8${detail}`));
2568
+ }
2569
+ });
2570
+ child.stdin.on("error", () => {
2571
+ });
2572
+ child.stdin.end(JSON.stringify(input));
2061
2573
  });
2062
- child.stdin.on("error", () => {
2063
- });
2064
- child.stdin.end(JSON.stringify(input));
2065
2574
  });
2066
2575
  }
2067
2576
  var AppRequestError = class extends Error {
@@ -2105,8 +2614,13 @@ var AppDelivery = class {
2105
2614
  async save(root, job) {
2106
2615
  await mkdir3(root, { recursive: true, mode: 448 });
2107
2616
  const temp = join3(root, `job-${randomUUID4()}.tmp`);
2108
- await writeFile3(temp, JSON.stringify(job), { mode: 384 });
2109
- await rename3(temp, join3(root, "job.json"));
2617
+ try {
2618
+ await writeFile3(temp, JSON.stringify(job), { mode: 384 });
2619
+ await renameWithRetry(temp, join3(root, "job.json"));
2620
+ } finally {
2621
+ await rm2(temp, { force: true }).catch(() => {
2622
+ });
2623
+ }
2110
2624
  this.core.emit("change");
2111
2625
  }
2112
2626
  skillPreferencePath(directory, slug) {
@@ -2798,7 +3312,7 @@ ${trimmedFeedback}` : trimmedFeedback || prevFailure).slice(-24e3);
2798
3312
  if (filename !== "summary.json" && hash(bytes) !== job.hashes?.[filename]) throw new Error("\u4EA4\u4ED8\u6587\u4EF6\u5DF2\u53D1\u751F\u53D8\u5316");
2799
3313
  return { filename: `${job.slug}-${filename}`, base64: bytes.toString("base64") };
2800
3314
  }
2801
- async saveLocalArtifact(id, filename, expected, downloads = join3(homedir(), "Downloads")) {
3315
+ async saveLocalArtifact(id, filename, expected, downloads = join3(homedir2(), "Downloads")) {
2802
3316
  const scope = this.scope(expected);
2803
3317
  const { root, job } = await this.open(scope.directory, id);
2804
3318
  if (!["ready", "building", "verifying", "awaiting_page_verification", "verified", "failed"].includes(job.status) || !job.revision || !/^[a-z0-9]+$/i.test(job.revision) || !["app.tar", "skill.zip", "app-manifest.json", "summary.json"].includes(filename)) throw new Error("\u5F53\u524D\u4EA4\u4ED8\u6587\u4EF6\u4E0D\u53EF\u7528");
@@ -3377,7 +3891,7 @@ ${trimmedFeedback}` : trimmedFeedback || prevFailure).slice(-24e3);
3377
3891
  }
3378
3892
  return { filename, base64: result.bytes.toString("base64") };
3379
3893
  }
3380
- async saveDownload(slug, selection, expected, downloads = join3(homedir(), "Downloads")) {
3894
+ async saveDownload(slug, selection, expected, downloads = join3(homedir2(), "Downloads")) {
3381
3895
  const scope = this.scope(expected);
3382
3896
  const { filename, path, query } = this.downloadTarget(slug, selection);
3383
3897
  await mkdir3(downloads, { recursive: true, mode: 448 });
@@ -3523,7 +4037,7 @@ ${trimmedFeedback}` : trimmedFeedback || prevFailure).slice(-24e3);
3523
4037
  if (!(error instanceof AppRequestError) || error.status !== 404) throw error;
3524
4038
  const verDir = join3(scope.directory, "versions", slug, `v${targetVersion}`);
3525
4039
  const localFallback = join3(verDir, "skill.zip");
3526
- if (existsSync2(localFallback)) {
4040
+ if (existsSync3(localFallback)) {
3527
4041
  skillZipBytes = await readFile2(localFallback).catch(() => void 0);
3528
4042
  }
3529
4043
  if (localMeta) {
@@ -3711,7 +4225,7 @@ ${trimmedFeedback}` : trimmedFeedback || prevFailure).slice(-24e3);
3711
4225
  try {
3712
4226
  await writeFile3(temp, enabled ? "enabled" : "disabled", { mode: 384 });
3713
4227
  scope.assertCurrent();
3714
- await rename3(temp, path);
4228
+ await renameWithRetry(temp, path);
3715
4229
  } finally {
3716
4230
  await rm2(temp, { force: true });
3717
4231
  }
@@ -3810,7 +4324,7 @@ function proposalParameters(port) {
3810
4324
  impact: text2,
3811
4325
  recommendation: text2
3812
4326
  } } },
3813
- unresolved: strings,
4327
+ unresolved: { ...strings, description: "\u82E5\u6D89\u53CA\u4EE4\u724C/\u767B\u5F55/\u8D26\u5BC6/\u51ED\u636E/\u6388\u6743\u7801\u7B49\u963B\u585E\u95EE\u9898\uFF0C\u5FC5\u987B\u5728 contract.auth_blockers \u4E2D\u6DFB\u52A0 question \u5B8C\u5168\u4E00\u81F4\u7684\u6761\u76EE\uFF08\u7BA1\u7406\u5458\u767B\u5F55\u901A\u8FC7 admin_account \u5904\u7406\uFF0C\u4E0D\u8981\u5199\u5165 unresolved\uFF09" },
3814
4328
  changes: { ...objects, items: { ...object2, properties: {
3815
4329
  id: text2,
3816
4330
  path: text2,
@@ -3832,7 +4346,7 @@ function proposalParameters(port) {
3832
4346
  } },
3833
4347
  build_context: { ...strings, required: true },
3834
4348
  health: { ...object2, required: true, properties: { path: text2, status: { type: "integer", required: true }, json_contains: { ...object2, required: true } } },
3835
- configs: { ...objects, items: { ...object2, properties: {
4349
+ configs: { ...objects, description: '\u4EC5\u586B\u5199\u6E90\u7801\u771F\u5B9E\u5B58\u5728\u7684\u914D\u7F6E\u952E\uFF08\u53C2\u8003 inventory.source_configuration\uFF09\uFF1Bdefault \u5FC5\u987B\u4E3A\u7A7A\u5B57\u7B26\u4E32 ""\uFF1Bsource \u4EC5\u652F\u6301 YAML/JSON/TOML/.env/properties \u6587\u4EF6\uFF0C\u4E0D\u652F\u6301\u4EE3\u7801\u6587\u4EF6', items: { ...object2, properties: {
3836
4350
  key: text2,
3837
4351
  default: text2,
3838
4352
  secret: { ...bool, required: true },
@@ -3860,7 +4374,7 @@ function proposalParameters(port) {
3860
4374
  source: { ...object2, description: "\u5DF2\u6709\u53EF\u590D\u7528\u660E\u6587\u7684 {username,password} \u5F15\u7528\uFF1A\u7ED3\u6784\u5316\u914D\u7F6E {path,keys}\u3001\u6E90\u7801\u5E38\u91CF {path,line,name} \u6216 SQLite \u660E\u6587\u5B57\u6BB5 {path,table,column,where}\u3002\u7F3A\u4EFB\u4F55\u4E00\u9879\u5219\u7701\u7565 source\u3002" },
3861
4375
  storage: { ...object2, description: "\u9996\u6B21\u5EFA\u53F7\u4EC5\u5728\u4EA4\u4ED8\u526F\u672C\u4E2D\u5199\u5165\u5E94\u7528\u771F\u6B63\u8BFB\u53D6\u7684 SQLite \u6216 JSON/YAML \u6587\u4EF6\uFF0C\u5177\u4F53\u7ED3\u6784\u89C1 references/contract.md\u3002" }
3862
4376
  } },
3863
- auth_rules: { ...objects, description: "\u6BCF\u6761\u89C4\u5219\u987B\u4E8C\u9009\u4E00\u586B\u5199 path \u6216 prefix\uFF1B\u7CBE\u786E\u89C4\u5219\u4F18\u5148", items: { ...object2, properties: {
4377
+ auth_rules: { ...objects, description: '\u6BCF\u6761\u89C4\u5219\u987B\u4E8C\u9009\u4E00\u586B\u5199 path \u6216 prefix\uFF1Bevidence \u662F\u89C4\u5219\u9876\u5C42\u5FC5\u586B\u6570\u7EC4\uFF08\u4E0E auth \u5E73\u7EA7\uFF0C\u4E0D\u8981\u653E\u5728 auth \u5185\u90E8\uFF09\uFF1B\u540C\u6743\u9650\u9875\u9762\u53EF\u7528 target="page" \u4E14 prefix="/" \u7EDF\u4E00\u8986\u76D6', items: { ...object2, properties: {
3864
4378
  target: { ...text2, enum: ["api", "page"] },
3865
4379
  path: str,
3866
4380
  prefix: str,
@@ -3894,7 +4408,7 @@ function proposalParameters(port) {
3894
4408
  items: { ...object2, properties: { auth: routeAuth } }
3895
4409
  },
3896
4410
  verification: object2,
3897
- unresolved: strings
4411
+ unresolved: { ...strings, description: "\u82E5\u6D89\u53CA\u4EE4\u724C/\u767B\u5F55/\u8D26\u5BC6/\u51ED\u636E/\u6388\u6743\u7801\u7B49\u963B\u585E\u95EE\u9898\uFF0C\u5FC5\u987B\u5728 contract.auth_blockers \u4E2D\u6DFB\u52A0 question \u5B8C\u5168\u4E00\u81F4\u7684\u6761\u76EE\uFF08\u7BA1\u7406\u5458\u767B\u5F55\u901A\u8FC7 admin_account \u5904\u7406\uFF0C\u4E0D\u8981\u5199\u5165 unresolved\uFF09" }
3898
4412
  } },
3899
4413
  decisions: { ...objects, items: { ...object2, properties: {
3900
4414
  id: text2,
@@ -3910,6 +4424,7 @@ function proposalParameters(port) {
3910
4424
  // src/host/app-agent.ts
3911
4425
  var ANALYSIS_TIMEOUT_MS = 15 * 6e4;
3912
4426
  var REPLY_TIMEOUT_MS = 30 * 6e4;
4427
+ var MAX_VALIDATION_ERRORS = 10;
3913
4428
  function loadBundledSkillText(relativePath) {
3914
4429
  const fromSrc = fileURLToPath2(new URL(`../../runtime/app_delivery/${relativePath}`, import.meta.url));
3915
4430
  const fromLib = fileURLToPath2(new URL(`../runtime/app_delivery/${relativePath}`, import.meta.url));
@@ -4089,7 +4604,7 @@ function attachAppAgent(ctx, delivery) {
4089
4604
  }));
4090
4605
  child.tools.register(defineTool2({
4091
4606
  name: "opc_delivery_propose_file",
4092
- description: "\u6682\u5B58\u6839\u76EE\u5F55 Dockerfile \u6216\u73B0\u6709\u5E94\u7528\u4EE3\u7801\u7684\u5FC5\u8981\u6539\u52A8\u3002\u539F\u914D\u7F6E\u7531\u7528\u6237\u7EF4\u62A4\u3002\u6682\u5B58\u6587\u4EF6\u5728 opc_delivery_submit \u7684 changes \u4E2D\u6309 id \u548C path \u5F15\u7528\u3002",
4607
+ description: "\u6682\u5B58\u6839\u76EE\u5F55 Dockerfile \u6216\u73B0\u6709\u5E94\u7528\u4EE3\u7801\u7684\u5FC5\u8981\u6539\u52A8\u3002\u7981\u6B62\u65B0\u589E\u6216\u6539\u5199 ENV \u73AF\u5883\u53D8\u91CF\u9ED8\u8BA4\u503C\uFF0C\u7981\u6B62\u65B0\u589E\u5065\u5EB7\u68C0\u67E5\u63A5\u53E3\u3002\u539F\u914D\u7F6E\u7531\u7528\u6237\u7EF4\u62A4\u3002\u6682\u5B58\u6587\u4EF6\u5728 opc_delivery_submit \u7684 changes \u4E2D\u6309 id \u548C path \u5F15\u7528\u3002",
4093
4608
  parameters: {
4094
4609
  id: { type: "string", required: true },
4095
4610
  path: { type: "string", required: true },
@@ -4114,7 +4629,7 @@ function attachAppAgent(ctx, delivery) {
4114
4629
  output,
4115
4630
  async execute(args) {
4116
4631
  if (job.status !== "analyzing") throw new Error("\u672C\u8F6E\u5DF2\u63D0\u4EA4\u65B9\u6848");
4117
- if (repeatedProposal || validationErrors.length >= 6) throw new Error("\u6280\u672F\u65B9\u6848\u8FDE\u7EED\u6821\u9A8C\u672A\u901A\u8FC7\uFF0C\u5DF2\u505C\u6B62\u81EA\u52A8\u91CD\u8BD5");
4632
+ if (repeatedProposal || validationErrors.length >= MAX_VALIDATION_ERRORS) throw new Error("\u6280\u672F\u65B9\u6848\u8FDE\u7EED\u6821\u9A8C\u672A\u901A\u8FC7\uFF0C\u5DF2\u505C\u6B62\u81EA\u52A8\u91CD\u8BD5");
4118
4633
  job.events.push(formatToolStep("submit"));
4119
4634
  delivery.core.emit("change");
4120
4635
  let candidate;
@@ -4128,7 +4643,7 @@ function attachAppAgent(ctx, delivery) {
4128
4643
  await delivery.submit(job, root, candidate, abort);
4129
4644
  } catch (error) {
4130
4645
  const message = error instanceof Error ? error.message : String(error);
4131
- const detail = await worker({ action: "redact_feedback", root, text: message.slice(0, 1e3) }, abort);
4646
+ const detail = await worker({ action: "redact_feedback", root, text: message.slice(0, 2e3) }, abort);
4132
4647
  validationErrors.push(detail);
4133
4648
  job.analysisFailure = detail;
4134
4649
  if (candidate) {
@@ -4148,7 +4663,7 @@ function attachAppAgent(ctx, delivery) {
4148
4663
  }
4149
4664
  job.events.push(`\u63D0\u6848\u6821\u9A8C\u672A\u901A\u8FC7\uFF1A${detail}`);
4150
4665
  delivery.core.emit("change");
4151
- if (validationErrors.length === 6) cancel();
4666
+ if (validationErrors.length === MAX_VALIDATION_ERRORS) cancel();
4152
4667
  throw new Error(detail);
4153
4668
  }
4154
4669
  const questions = analysisQuestions(job.proposal);
@@ -4292,8 +4807,8 @@ ${questions.join("\n")}` : "\u5B8C\u6574\u65B9\u6848\u5DF2\u901A\u8FC7\u6821\u9A
4292
4807
  if (job.status === "review") {
4293
4808
  if (!analysisQuestions(job.proposal).length) return;
4294
4809
  setDeadline(REPLY_TIMEOUT_MS);
4295
- if (!abort.aborted) await new Promise((resolve) => {
4296
- wakeReply = resolve;
4810
+ if (!abort.aborted) await new Promise((resolve2) => {
4811
+ wakeReply = resolve2;
4297
4812
  });
4298
4813
  wakeReply = void 0;
4299
4814
  signal.throwIfAborted();
@@ -4314,7 +4829,7 @@ ${questions.join("\n")}` : "\u5B8C\u6574\u65B9\u6848\u5DF2\u901A\u8FC7\u6821\u9A
4314
4829
  attempt = -1;
4315
4830
  continue;
4316
4831
  }
4317
- if (repeatedProposal || validationErrors.length >= 6) {
4832
+ if (repeatedProposal || validationErrors.length >= MAX_VALIDATION_ERRORS) {
4318
4833
  throw new Error(validationErrors.at(-1) ?? "\u6280\u672F\u65B9\u6848\u8FDE\u7EED\u6821\u9A8C\u672A\u901A\u8FC7\uFF0C\u5DF2\u505C\u6B62\u81EA\u52A8\u91CD\u8BD5");
4319
4834
  }
4320
4835
  abort.throwIfAborted();
@@ -4325,7 +4840,7 @@ ${questions.join("\n")}` : "\u5B8C\u6574\u65B9\u6848\u5DF2\u901A\u8FC7\u6821\u9A
4325
4840
  const badToolJson = /tool input is invalid JSON/i.test(providerMessage);
4326
4841
  const invalidOutput = badToolJson || truncated;
4327
4842
  const networkError = /(?:timed?\s*out|timeout|connection\s*reset|ECONNRESET|ETIMEDOUT|fetch failed|network|terminated)/i.test(providerMessage);
4328
- const reason = invalidOutput ? badToolJson ? "\u6A21\u578B\u8FD4\u56DE\u7684\u5DE5\u5177\u53C2\u6570\u4E0D\u662F\u5408\u6CD5 JSON" : "\u6A21\u578B\u8F93\u51FA\u8FBE\u5230\u957F\u5EA6\u4E0A\u9650" : providerMessage ? await worker({ action: "redact_feedback", root, text: providerMessage.slice(0, 1e3) }, abort) : validationErrors.at(-1) || "AI \u5C1A\u672A\u63D0\u4EA4\u5B8C\u6574\u63D0\u6848";
4843
+ const reason = invalidOutput ? badToolJson ? "\u6A21\u578B\u8FD4\u56DE\u7684\u5DE5\u5177\u53C2\u6570\u4E0D\u662F\u5408\u6CD5 JSON" : "\u6A21\u578B\u8F93\u51FA\u8FBE\u5230\u957F\u5EA6\u4E0A\u9650" : providerMessage ? await worker({ action: "redact_feedback", root, text: providerMessage.slice(0, 2e3) }, abort) : validationErrors.at(-1) || "AI \u5C1A\u672A\u63D0\u4EA4\u5B8C\u6574\u63D0\u6848";
4329
4844
  job.analysisFailure = reason;
4330
4845
  if (providerMessage && !invalidOutput && !networkError) throw new Error(reason);
4331
4846
  if (attempt === 2) {
@@ -4571,7 +5086,7 @@ function apply(ctx, config) {
4571
5086
  async run(session) {
4572
5087
  const login = await auth.startLogin();
4573
5088
  session.notify({ message: "\u8BF7\u5728\u6D4F\u89C8\u5668\u5B8C\u6210\u4F01\u4E1A\u6388\u6743", url: login.authorizeUrl });
4574
- await new Promise((resolve, reject) => {
5089
+ await new Promise((resolve2, reject) => {
4575
5090
  const cleanup = () => {
4576
5091
  auth.off("change", changed);
4577
5092
  session.signal.removeEventListener("abort", cancelled);
@@ -4579,7 +5094,7 @@ function apply(ctx, config) {
4579
5094
  const changed = () => {
4580
5095
  if (auth.state.loginInProgress) return;
4581
5096
  cleanup();
4582
- if (auth.state.signedIn) resolve();
5097
+ if (auth.state.signedIn) resolve2();
4583
5098
  else reject(new Error(auth.state.loginError?.code ?? "LOGIN_CANCELLED"));
4584
5099
  };
4585
5100
  const cancelled = () => {