dsh-plugin-opc 0.1.28 → 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();
@@ -1459,6 +1459,48 @@ var OpcConfigStore = class {
1459
1459
 
1460
1460
  // src/host/remote-service.ts
1461
1461
  var execFileAsync = promisify(execFile);
1462
+ var WIN32_FOLDER_PICKER_SCRIPT = [
1463
+ "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8",
1464
+ "Add-Type -AssemblyName System.Windows.Forms",
1465
+ "$owner = New-Object System.Windows.Forms.Form",
1466
+ "$owner.TopMost = $true",
1467
+ "$dialog = New-Object System.Windows.Forms.FolderBrowserDialog",
1468
+ "$dialog.Description = '\u9009\u62E9\u5E94\u7528\u6E90\u7801\u76EE\u5F55'",
1469
+ "$dialog.ShowNewFolderButton = $false",
1470
+ "if ($dialog.ShowDialog($owner) -eq [System.Windows.Forms.DialogResult]::OK) { Write-Output $dialog.SelectedPath }",
1471
+ "$owner.Dispose()",
1472
+ "$dialog.Dispose()"
1473
+ ].join("; ");
1474
+ async function pickSourceFolder(platform2 = process.platform, exec = execFileAsync) {
1475
+ if (platform2 === "darwin") {
1476
+ try {
1477
+ const { stdout } = await exec(
1478
+ "osascript",
1479
+ ["-e", 'POSIX path of (choose folder with prompt "\u9009\u62E9\u5E94\u7528\u6E90\u7801\u76EE\u5F55")'],
1480
+ { timeout: 12e4 }
1481
+ );
1482
+ const path = stdout.trim().replace(/\/+$/, "") || "/";
1483
+ return { path };
1484
+ } catch {
1485
+ return { cancelled: true };
1486
+ }
1487
+ }
1488
+ if (platform2 === "win32") {
1489
+ try {
1490
+ const { stdout } = await exec(
1491
+ "powershell.exe",
1492
+ ["-NoProfile", "-NonInteractive", "-STA", "-Command", WIN32_FOLDER_PICKER_SCRIPT],
1493
+ { timeout: 12e4, windowsHide: true }
1494
+ );
1495
+ const path = stdout.trim();
1496
+ return path ? { path } : { cancelled: true };
1497
+ } catch (error) {
1498
+ if (error?.code === "ENOENT") return { cancelled: true, unsupported: true };
1499
+ return { cancelled: true };
1500
+ }
1501
+ }
1502
+ return { cancelled: true, unsupported: true };
1503
+ }
1462
1504
  var _decideDebugInvocation_dec, _unmountMcpService_dec, _mountMcpService_dec, _invokeMcpTool_dec, _listMcpServices_dec, _readKnowledgeDocument_dec, _searchKnowledge_dec, _setPinnedKnowledgeScope_dec, _uninstallSkill_dec, _setSkillEnabled_dec, _installSkill_dec, _listSkillsCatalog_dec, _listKnowledgeBases_dec, _switchTenant_dec, _logout_dec, _cancelLogin_dec, _startLogin_dec, _watchState_dec, _state_dec, _opcConfigTest_dec, _opcConfigReset_dec, _opcConfigUpdate_dec, _opcConfigGet_dec, _appRollback_dec, _appDelete_dec, _appUpdateConfig_dec, _appRecheck_dec, _appSaveDownload_dec, _appDownload_dec, _appStorage_dec, _appLogs_dec, _appVersions_dec, _appDetails_dec, _appResources_dec, _appSetSkillEnabled_dec, _appVerifyWithOptions_dec, _appVerify_dec, _appPublish_dec, _appConfirmDeployment_dec, _appSkillPreview_dec, _appHandoff_dec, _appSaveLocalArtifact_dec, _appLocalArtifact_dec, _appSaveConfigDraft_dec, _appConfigDraft_dec, _appCancelAnalysis_dec, _appReopenDeployment_dec, _appReopenReview_dec, _appPrepare_dec, _appAnalyzeWithMode_dec, _appAnalyze_dec, _appCreate_dec, _appCatalog_dec, _appModels_dec, _appPickSourceFolder_dec, _appOpcConfig_dec, _appCheckSlug_dec, _appJobByAnalysisSession_dec, _appJob_dec, _appList_dec, _a, _init;
1463
1505
  var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [Remote], _appJob_dec = [Remote], _appJobByAnalysisSession_dec = [Remote], _appCheckSlug_dec = [Remote], _appOpcConfig_dec = [Remote], _appPickSourceFolder_dec = [Remote], _appModels_dec = [Remote], _appCatalog_dec = [Remote], _appCreate_dec = [Remote], _appAnalyze_dec = [Remote], _appAnalyzeWithMode_dec = [Remote], _appPrepare_dec = [Remote], _appReopenReview_dec = [Remote], _appReopenDeployment_dec = [Remote], _appCancelAnalysis_dec = [Remote], _appConfigDraft_dec = [Remote], _appSaveConfigDraft_dec = [Remote], _appLocalArtifact_dec = [Remote], _appSaveLocalArtifact_dec = [Remote], _appHandoff_dec = [Remote], _appSkillPreview_dec = [Remote], _appConfirmDeployment_dec = [Remote], _appPublish_dec = [Remote], _appVerify_dec = [Remote], _appVerifyWithOptions_dec = [Remote], _appSetSkillEnabled_dec = [Remote], _appResources_dec = [Remote], _appDetails_dec = [Remote], _appVersions_dec = [Remote], _appLogs_dec = [Remote], _appStorage_dec = [Remote], _appDownload_dec = [Remote], _appSaveDownload_dec = [Remote], _appRecheck_dec = [Remote], _appUpdateConfig_dec = [Remote], _appDelete_dec = [Remote], _appRollback_dec = [Remote], _opcConfigGet_dec = [Remote], _opcConfigUpdate_dec = [Remote], _opcConfigReset_dec = [Remote], _opcConfigTest_dec = [Remote], _state_dec = [Remote], _watchState_dec = [Remote({ mode: "stream" })], _startLogin_dec = [Remote], _cancelLogin_dec = [Remote], _logout_dec = [Remote], _switchTenant_dec = [Remote], _listKnowledgeBases_dec = [Remote], _listSkillsCatalog_dec = [Remote], _installSkill_dec = [Remote], _setSkillEnabled_dec = [Remote], _uninstallSkill_dec = [Remote], _setPinnedKnowledgeScope_dec = [Remote], _searchKnowledge_dec = [Remote], _readKnowledgeDocument_dec = [Remote], _listMcpServices_dec = [Remote], _invokeMcpTool_dec = [Remote], _mountMcpService_dec = [Remote], _unmountMcpService_dec = [Remote], _decideDebugInvocation_dec = [Remote], _a) {
1464
1506
  constructor(ctx, options) {
@@ -1516,14 +1558,7 @@ var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [
1516
1558
  }
1517
1559
  async appPickSourceFolder(expectedContextId) {
1518
1560
  this.core.auth.contexts.captureApplication(expectedContextId);
1519
- if (process.platform !== "darwin") return JSON.stringify({ cancelled: true, unsupported: true });
1520
- try {
1521
- const { stdout } = await execFileAsync("osascript", ["-e", 'POSIX path of (choose folder with prompt "\u9009\u62E9\u5E94\u7528\u6E90\u7801\u76EE\u5F55")'], { timeout: 12e4 });
1522
- const path = stdout.trim().replace(/\/+$/, "") || "/";
1523
- return JSON.stringify({ path });
1524
- } catch {
1525
- return JSON.stringify({ cancelled: true });
1526
- }
1561
+ return JSON.stringify(await pickSourceFolder());
1527
1562
  }
1528
1563
  async appModels(expectedContextId) {
1529
1564
  const scope = this.core.auth.contexts.captureApplication(expectedContextId);
@@ -1707,8 +1742,8 @@ var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [
1707
1742
  dirty = false;
1708
1743
  yield await this.state();
1709
1744
  }
1710
- if (!dirty && !signal.aborted) await new Promise((resolve) => {
1711
- wake = resolve;
1745
+ if (!dirty && !signal.aborted) await new Promise((resolve2) => {
1746
+ wake = resolve2;
1712
1747
  });
1713
1748
  }
1714
1749
  } finally {
@@ -1918,15 +1953,450 @@ function registerTools(ctx, core) {
1918
1953
  }
1919
1954
 
1920
1955
  // src/host/app-delivery.ts
1921
- import { createWriteStream, existsSync as existsSync2 } from "node:fs";
1922
- import { spawn } from "node:child_process";
1956
+ import { createWriteStream, existsSync as existsSync3 } from "node:fs";
1957
+ import { spawn as spawn2 } from "node:child_process";
1923
1958
  import { createHash as createHash5, randomUUID as randomUUID4 } from "node:crypto";
1924
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";
1925
- import { dirname as dirname3, isAbsolute, join as join3 } from "node:path";
1926
- 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";
1927
1962
  import { Transform } from "node:stream";
1928
1963
  import { pipeline } from "node:stream/promises";
1929
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
1930
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";
1931
2401
  function analysisQuestions(proposal) {
1932
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`] : [];
@@ -1992,41 +2462,115 @@ function contains(actual, expected) {
1992
2462
  if (expected && typeof expected === "object") return actual !== null && typeof actual === "object" && Object.entries(expected).every(([k, v]) => contains(actual[k], v));
1993
2463
  return actual === expected;
1994
2464
  }
1995
- function worker(input, signal) {
1996
- const path = fileURLToPath(new URL("../../runtime/worker.py", import.meta.url));
1997
- const runtime = import.meta.url.endsWith("/lib/index.js") ? fileURLToPath(new URL("../runtime/worker.py", import.meta.url)) : path;
1998
- const executable = dirname3(process.execPath);
1999
- const bundled = [
2000
- join3(executable, "../Resources/runtime/primary-runtime/dependencies/python/bin/python3"),
2001
- join3(executable, "../../python/bin/python3")
2002
- ].find((candidate) => existsSync2(candidate));
2003
- return new Promise((resolve, reject) => {
2004
- 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 });
2005
- let stdout = "", stderr = "", exceeded = false;
2006
- child.stdout.on("data", (data) => {
2007
- stdout += data;
2008
- if (stdout.length > 8e6) {
2009
- exceeded = true;
2010
- child.kill();
2011
- }
2012
- });
2013
- child.stderr.on("data", (data) => {
2014
- if (stderr.length < 2e3) stderr += data;
2015
- });
2016
- 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)));
2017
- child.on("close", () => {
2018
- 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;
2019
2485
  try {
2020
- const result = JSON.parse(stdout);
2021
- if (!result.ok) throw new Error(result.error);
2022
- resolve(result.value);
2023
- } catch (error) {
2024
- 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);
2025
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));
2026
2573
  });
2027
- child.stdin.on("error", () => {
2028
- });
2029
- child.stdin.end(JSON.stringify(input));
2030
2574
  });
2031
2575
  }
2032
2576
  var AppRequestError = class extends Error {
@@ -2070,8 +2614,13 @@ var AppDelivery = class {
2070
2614
  async save(root, job) {
2071
2615
  await mkdir3(root, { recursive: true, mode: 448 });
2072
2616
  const temp = join3(root, `job-${randomUUID4()}.tmp`);
2073
- await writeFile3(temp, JSON.stringify(job), { mode: 384 });
2074
- 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
+ }
2075
2624
  this.core.emit("change");
2076
2625
  }
2077
2626
  skillPreferencePath(directory, slug) {
@@ -2763,7 +3312,7 @@ ${trimmedFeedback}` : trimmedFeedback || prevFailure).slice(-24e3);
2763
3312
  if (filename !== "summary.json" && hash(bytes) !== job.hashes?.[filename]) throw new Error("\u4EA4\u4ED8\u6587\u4EF6\u5DF2\u53D1\u751F\u53D8\u5316");
2764
3313
  return { filename: `${job.slug}-${filename}`, base64: bytes.toString("base64") };
2765
3314
  }
2766
- async saveLocalArtifact(id, filename, expected, downloads = join3(homedir(), "Downloads")) {
3315
+ async saveLocalArtifact(id, filename, expected, downloads = join3(homedir2(), "Downloads")) {
2767
3316
  const scope = this.scope(expected);
2768
3317
  const { root, job } = await this.open(scope.directory, id);
2769
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");
@@ -3342,7 +3891,7 @@ ${trimmedFeedback}` : trimmedFeedback || prevFailure).slice(-24e3);
3342
3891
  }
3343
3892
  return { filename, base64: result.bytes.toString("base64") };
3344
3893
  }
3345
- async saveDownload(slug, selection, expected, downloads = join3(homedir(), "Downloads")) {
3894
+ async saveDownload(slug, selection, expected, downloads = join3(homedir2(), "Downloads")) {
3346
3895
  const scope = this.scope(expected);
3347
3896
  const { filename, path, query } = this.downloadTarget(slug, selection);
3348
3897
  await mkdir3(downloads, { recursive: true, mode: 448 });
@@ -3488,7 +4037,7 @@ ${trimmedFeedback}` : trimmedFeedback || prevFailure).slice(-24e3);
3488
4037
  if (!(error instanceof AppRequestError) || error.status !== 404) throw error;
3489
4038
  const verDir = join3(scope.directory, "versions", slug, `v${targetVersion}`);
3490
4039
  const localFallback = join3(verDir, "skill.zip");
3491
- if (existsSync2(localFallback)) {
4040
+ if (existsSync3(localFallback)) {
3492
4041
  skillZipBytes = await readFile2(localFallback).catch(() => void 0);
3493
4042
  }
3494
4043
  if (localMeta) {
@@ -3676,7 +4225,7 @@ ${trimmedFeedback}` : trimmedFeedback || prevFailure).slice(-24e3);
3676
4225
  try {
3677
4226
  await writeFile3(temp, enabled ? "enabled" : "disabled", { mode: 384 });
3678
4227
  scope.assertCurrent();
3679
- await rename3(temp, path);
4228
+ await renameWithRetry(temp, path);
3680
4229
  } finally {
3681
4230
  await rm2(temp, { force: true });
3682
4231
  }
@@ -3775,7 +4324,7 @@ function proposalParameters(port) {
3775
4324
  impact: text2,
3776
4325
  recommendation: text2
3777
4326
  } } },
3778
- 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" },
3779
4328
  changes: { ...objects, items: { ...object2, properties: {
3780
4329
  id: text2,
3781
4330
  path: text2,
@@ -3797,7 +4346,7 @@ function proposalParameters(port) {
3797
4346
  } },
3798
4347
  build_context: { ...strings, required: true },
3799
4348
  health: { ...object2, required: true, properties: { path: text2, status: { type: "integer", required: true }, json_contains: { ...object2, required: true } } },
3800
- 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: {
3801
4350
  key: text2,
3802
4351
  default: text2,
3803
4352
  secret: { ...bool, required: true },
@@ -3825,7 +4374,7 @@ function proposalParameters(port) {
3825
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" },
3826
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" }
3827
4376
  } },
3828
- 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: {
3829
4378
  target: { ...text2, enum: ["api", "page"] },
3830
4379
  path: str,
3831
4380
  prefix: str,
@@ -3859,7 +4408,7 @@ function proposalParameters(port) {
3859
4408
  items: { ...object2, properties: { auth: routeAuth } }
3860
4409
  },
3861
4410
  verification: object2,
3862
- 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" }
3863
4412
  } },
3864
4413
  decisions: { ...objects, items: { ...object2, properties: {
3865
4414
  id: text2,
@@ -3875,6 +4424,7 @@ function proposalParameters(port) {
3875
4424
  // src/host/app-agent.ts
3876
4425
  var ANALYSIS_TIMEOUT_MS = 15 * 6e4;
3877
4426
  var REPLY_TIMEOUT_MS = 30 * 6e4;
4427
+ var MAX_VALIDATION_ERRORS = 10;
3878
4428
  function loadBundledSkillText(relativePath) {
3879
4429
  const fromSrc = fileURLToPath2(new URL(`../../runtime/app_delivery/${relativePath}`, import.meta.url));
3880
4430
  const fromLib = fileURLToPath2(new URL(`../runtime/app_delivery/${relativePath}`, import.meta.url));
@@ -4054,7 +4604,7 @@ function attachAppAgent(ctx, delivery) {
4054
4604
  }));
4055
4605
  child.tools.register(defineTool2({
4056
4606
  name: "opc_delivery_propose_file",
4057
- 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",
4058
4608
  parameters: {
4059
4609
  id: { type: "string", required: true },
4060
4610
  path: { type: "string", required: true },
@@ -4079,7 +4629,7 @@ function attachAppAgent(ctx, delivery) {
4079
4629
  output,
4080
4630
  async execute(args) {
4081
4631
  if (job.status !== "analyzing") throw new Error("\u672C\u8F6E\u5DF2\u63D0\u4EA4\u65B9\u6848");
4082
- 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");
4083
4633
  job.events.push(formatToolStep("submit"));
4084
4634
  delivery.core.emit("change");
4085
4635
  let candidate;
@@ -4093,7 +4643,7 @@ function attachAppAgent(ctx, delivery) {
4093
4643
  await delivery.submit(job, root, candidate, abort);
4094
4644
  } catch (error) {
4095
4645
  const message = error instanceof Error ? error.message : String(error);
4096
- 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);
4097
4647
  validationErrors.push(detail);
4098
4648
  job.analysisFailure = detail;
4099
4649
  if (candidate) {
@@ -4113,7 +4663,7 @@ function attachAppAgent(ctx, delivery) {
4113
4663
  }
4114
4664
  job.events.push(`\u63D0\u6848\u6821\u9A8C\u672A\u901A\u8FC7\uFF1A${detail}`);
4115
4665
  delivery.core.emit("change");
4116
- if (validationErrors.length === 6) cancel();
4666
+ if (validationErrors.length === MAX_VALIDATION_ERRORS) cancel();
4117
4667
  throw new Error(detail);
4118
4668
  }
4119
4669
  const questions = analysisQuestions(job.proposal);
@@ -4257,8 +4807,8 @@ ${questions.join("\n")}` : "\u5B8C\u6574\u65B9\u6848\u5DF2\u901A\u8FC7\u6821\u9A
4257
4807
  if (job.status === "review") {
4258
4808
  if (!analysisQuestions(job.proposal).length) return;
4259
4809
  setDeadline(REPLY_TIMEOUT_MS);
4260
- if (!abort.aborted) await new Promise((resolve) => {
4261
- wakeReply = resolve;
4810
+ if (!abort.aborted) await new Promise((resolve2) => {
4811
+ wakeReply = resolve2;
4262
4812
  });
4263
4813
  wakeReply = void 0;
4264
4814
  signal.throwIfAborted();
@@ -4279,7 +4829,7 @@ ${questions.join("\n")}` : "\u5B8C\u6574\u65B9\u6848\u5DF2\u901A\u8FC7\u6821\u9A
4279
4829
  attempt = -1;
4280
4830
  continue;
4281
4831
  }
4282
- if (repeatedProposal || validationErrors.length >= 6) {
4832
+ if (repeatedProposal || validationErrors.length >= MAX_VALIDATION_ERRORS) {
4283
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");
4284
4834
  }
4285
4835
  abort.throwIfAborted();
@@ -4290,7 +4840,7 @@ ${questions.join("\n")}` : "\u5B8C\u6574\u65B9\u6848\u5DF2\u901A\u8FC7\u6821\u9A
4290
4840
  const badToolJson = /tool input is invalid JSON/i.test(providerMessage);
4291
4841
  const invalidOutput = badToolJson || truncated;
4292
4842
  const networkError = /(?:timed?\s*out|timeout|connection\s*reset|ECONNRESET|ETIMEDOUT|fetch failed|network|terminated)/i.test(providerMessage);
4293
- 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";
4294
4844
  job.analysisFailure = reason;
4295
4845
  if (providerMessage && !invalidOutput && !networkError) throw new Error(reason);
4296
4846
  if (attempt === 2) {
@@ -4536,7 +5086,7 @@ function apply(ctx, config) {
4536
5086
  async run(session) {
4537
5087
  const login = await auth.startLogin();
4538
5088
  session.notify({ message: "\u8BF7\u5728\u6D4F\u89C8\u5668\u5B8C\u6210\u4F01\u4E1A\u6388\u6743", url: login.authorizeUrl });
4539
- await new Promise((resolve, reject) => {
5089
+ await new Promise((resolve2, reject) => {
4540
5090
  const cleanup = () => {
4541
5091
  auth.off("change", changed);
4542
5092
  session.signal.removeEventListener("abort", cancelled);
@@ -4544,7 +5094,7 @@ function apply(ctx, config) {
4544
5094
  const changed = () => {
4545
5095
  if (auth.state.loginInProgress) return;
4546
5096
  cleanup();
4547
- if (auth.state.signedIn) resolve();
5097
+ if (auth.state.signedIn) resolve2();
4548
5098
  else reject(new Error(auth.state.loginError?.code ?? "LOGIN_CANCELLED"));
4549
5099
  };
4550
5100
  const cancelled = () => {