@codexhost/cli-darwin-x64 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3229,8 +3229,8 @@ var require_utils = __commonJS({
3229
3229
  }
3230
3230
  return ind;
3231
3231
  }
3232
- function removeDotSegments(path6) {
3233
- let input = path6;
3232
+ function removeDotSegments(path7) {
3233
+ let input = path7;
3234
3234
  const output = [];
3235
3235
  let nextSlash = -1;
3236
3236
  let len = 0;
@@ -3482,8 +3482,8 @@ var require_schemes = __commonJS({
3482
3482
  wsComponent.secure = void 0;
3483
3483
  }
3484
3484
  if (wsComponent.resourceName) {
3485
- const [path6, query] = wsComponent.resourceName.split("?");
3486
- wsComponent.path = path6 && path6 !== "/" ? path6 : void 0;
3485
+ const [path7, query] = wsComponent.resourceName.split("?");
3486
+ wsComponent.path = path7 && path7 !== "/" ? path7 : void 0;
3487
3487
  wsComponent.query = query;
3488
3488
  wsComponent.resourceName = void 0;
3489
3489
  }
@@ -12590,9 +12590,412 @@ var require_dist = __commonJS({
12590
12590
  }
12591
12591
  });
12592
12592
 
12593
+ // ../../harness-discovery/dist/environment.js
12594
+ import fs from "node:fs";
12595
+ import path from "node:path";
12596
+ function targetPath(platform) {
12597
+ return platform === "win32" ? path.win32 : path.posix;
12598
+ }
12599
+ function environmentValue(environment, name) {
12600
+ const lowered = name.toLowerCase();
12601
+ for (const [key, value] of Object.entries(environment)) {
12602
+ if (key.toLowerCase() === lowered)
12603
+ return value;
12604
+ }
12605
+ return void 0;
12606
+ }
12607
+ function pathDelimiter(platform) {
12608
+ return platform === "win32" ? ";" : ":";
12609
+ }
12610
+ function pathDirectories(environment, platform) {
12611
+ return (environmentValue(environment, "PATH") ?? "").split(pathDelimiter(platform)).map((directory) => directory.trim().replace(/^"|"$/gu, "")).filter(Boolean);
12612
+ }
12613
+ function executableExtensions(command, platform, environment) {
12614
+ if (platform !== "win32")
12615
+ return [""];
12616
+ if (targetPath(platform).extname(command) !== "")
12617
+ return [""];
12618
+ return (environmentValue(environment, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD").split(";").map((extension) => extension.trim()).filter(Boolean);
12619
+ }
12620
+ function isExecutableFile(filePath, platform) {
12621
+ try {
12622
+ fs.accessSync(filePath, platform === "win32" ? fs.constants.F_OK : fs.constants.X_OK);
12623
+ return fs.statSync(filePath).isFile();
12624
+ } catch {
12625
+ return false;
12626
+ }
12627
+ }
12628
+ function subdirectoryNames(directory) {
12629
+ try {
12630
+ return fs.readdirSync(directory, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
12631
+ } catch {
12632
+ return [];
12633
+ }
12634
+ }
12635
+ function newestFirst(names) {
12636
+ return [...names].sort((left, right) => right.localeCompare(left, void 0, { numeric: true }));
12637
+ }
12638
+
12639
+ // ../../harness-discovery/dist/invocation.js
12640
+ import path2 from "node:path";
12641
+ function commandInvocation(command, arguments_, environment, platform = process.platform) {
12642
+ const extension = path2.win32.extname(command).toLowerCase();
12643
+ if (platform !== "win32" || ![".cmd", ".bat"].includes(extension)) {
12644
+ return { command, arguments: [...arguments_], windowsVerbatimArguments: false };
12645
+ }
12646
+ const quote = (value) => `"${value.replaceAll("%", "%%").replaceAll('"', '""')}"`;
12647
+ const commandLine = [command, ...arguments_].map(quote).join(" ");
12648
+ return {
12649
+ command: environmentValue(environment, "ComSpec") ?? "cmd.exe",
12650
+ arguments: ["/d", "/v:off", "/s", "/c", `"${commandLine}"`],
12651
+ windowsVerbatimArguments: true
12652
+ };
12653
+ }
12654
+
12655
+ // ../../harness-discovery/dist/node-runtime.js
12656
+ import path3 from "node:path";
12657
+ function withNodeRuntimeOnPath(environment, runtimeExecutable = process.execPath, platform = process.platform) {
12658
+ const pathKey = Object.keys(environment).find((name) => name.toLowerCase() === "path") ?? "PATH";
12659
+ const delimiter = platform === "win32" ? ";" : ":";
12660
+ const runtimeDirectory = path3.dirname(runtimeExecutable);
12661
+ const directories = (environment[pathKey] ?? "").split(delimiter).filter(Boolean);
12662
+ const equal = platform === "win32" ? (value) => value.toLowerCase() : (value) => value;
12663
+ if (!directories.some((directory) => equal(directory) === equal(runtimeDirectory))) {
12664
+ directories.push(runtimeDirectory);
12665
+ }
12666
+ return { ...environment, [pathKey]: directories.join(delimiter) };
12667
+ }
12668
+
12669
+ // ../../harness-discovery/dist/resolve.js
12670
+ import os from "node:os";
12671
+
12672
+ // ../../harness-discovery/dist/version-managers.js
12673
+ function versionManagerBinaryDirectories(context) {
12674
+ const { platform, environment, home } = context;
12675
+ const list = context.subdirectories ?? subdirectoryNames;
12676
+ const pathFlavor = targetPath(platform);
12677
+ const value = (name) => environmentValue(environment, name);
12678
+ const directories = [];
12679
+ const versioned = (root, ...tail) => {
12680
+ for (const version2 of newestFirst(list(root))) {
12681
+ directories.push(pathFlavor.join(root, version2, ...tail));
12682
+ }
12683
+ };
12684
+ if (platform === "win32") {
12685
+ const appData = value("APPDATA") ?? pathFlavor.join(home, "AppData", "Roaming");
12686
+ const localAppData = value("LOCALAPPDATA") ?? pathFlavor.join(home, "AppData", "Local");
12687
+ versioned(pathFlavor.join(appData, "nvm"));
12688
+ versioned(value("FNM_DIR") ?? pathFlavor.join(appData, "fnm", "node-versions"), "installation");
12689
+ directories.push(pathFlavor.join(localAppData, "Volta", "bin"));
12690
+ directories.push(pathFlavor.join(home, ".bun", "bin"));
12691
+ const pnpmHome2 = value("PNPM_HOME");
12692
+ if (pnpmHome2)
12693
+ directories.push(pnpmHome2);
12694
+ directories.push(pathFlavor.join(localAppData, "pnpm"));
12695
+ return directories;
12696
+ }
12697
+ versioned(pathFlavor.join(value("NVM_DIR") ?? pathFlavor.join(home, ".nvm"), "versions", "node"), "bin");
12698
+ const fnmRoots = [
12699
+ value("FNM_DIR"),
12700
+ pathFlavor.join(home, ".local", "share", "fnm"),
12701
+ pathFlavor.join(home, "Library", "Application Support", "fnm")
12702
+ ].filter((root) => root !== void 0);
12703
+ for (const root of fnmRoots) {
12704
+ versioned(pathFlavor.join(root, "node-versions"), "installation", "bin");
12705
+ }
12706
+ const voltaHome = value("VOLTA_HOME") ?? pathFlavor.join(home, ".volta");
12707
+ versioned(pathFlavor.join(voltaHome, "tools", "image", "node"), "bin");
12708
+ directories.push(pathFlavor.join(voltaHome, "bin"));
12709
+ const asdfHome = value("ASDF_DATA_DIR") ?? pathFlavor.join(home, ".asdf");
12710
+ versioned(pathFlavor.join(asdfHome, "installs", "nodejs"), "bin");
12711
+ directories.push(pathFlavor.join(asdfHome, "shims"));
12712
+ const nodenvHome = value("NODENV_ROOT") ?? pathFlavor.join(home, ".nodenv");
12713
+ versioned(pathFlavor.join(nodenvHome, "versions"), "bin");
12714
+ directories.push(pathFlavor.join(nodenvHome, "shims"));
12715
+ versioned(pathFlavor.join(value("N_PREFIX") ?? "/usr/local", "n", "versions", "node"), "bin");
12716
+ directories.push(pathFlavor.join(home, ".bun", "bin"));
12717
+ const pnpmHome = value("PNPM_HOME");
12718
+ if (pnpmHome)
12719
+ directories.push(pnpmHome);
12720
+ directories.push(pathFlavor.join(home, "Library", "pnpm"));
12721
+ directories.push(pathFlavor.join(home, ".local", "share", "pnpm"));
12722
+ for (const prefix of ["/opt/homebrew/opt", "/usr/local/opt"]) {
12723
+ for (const formula of newestFirst(list(prefix).filter((name) => name.startsWith("node@")))) {
12724
+ directories.push(pathFlavor.join(prefix, formula, "bin"));
12725
+ }
12726
+ }
12727
+ return directories;
12728
+ }
12729
+
12730
+ // ../../harness-discovery/dist/resolve.js
12731
+ var VERSION_MANAGER_ROOTS = "<version-managers>";
12732
+ function installRootExtensions(platform) {
12733
+ return platform === "win32" ? [".exe", ".cmd"] : [""];
12734
+ }
12735
+ function resolveHomeDirectory(input) {
12736
+ return input.homeDirectory ?? environmentValue(input.environment, "HOME") ?? environmentValue(input.environment, "USERPROFILE") ?? os.homedir();
12737
+ }
12738
+ function templateVariables(environment, platform, home) {
12739
+ const pathFlavor = targetPath(platform);
12740
+ return {
12741
+ HOME: home,
12742
+ USERPROFILE: home,
12743
+ APPDATA: environmentValue(environment, "APPDATA") ?? pathFlavor.join(home, "AppData", "Roaming"),
12744
+ LOCALAPPDATA: environmentValue(environment, "LOCALAPPDATA") ?? pathFlavor.join(home, "AppData", "Local")
12745
+ };
12746
+ }
12747
+ function joinTemplate(platform, value) {
12748
+ const pathFlavor = targetPath(platform);
12749
+ const segments = value.split("/");
12750
+ const head = segments[0] ?? "";
12751
+ const tail = segments.slice(1);
12752
+ if (head === "")
12753
+ return pathFlavor.join(pathFlavor.sep, ...tail);
12754
+ return tail.length === 0 ? head : pathFlavor.join(head, ...tail);
12755
+ }
12756
+ function expandInstallRoot(template, environment, platform, home) {
12757
+ const variables = templateVariables(environment, platform, home);
12758
+ let unresolved = false;
12759
+ const substituted = template.replace(/^~(?=\/|$)/u, home).replace(/\$\{(\w+)\}/gu, (_match, name) => {
12760
+ const value = variables[name] ?? environmentValue(environment, name);
12761
+ if (value === void 0 || value === "") {
12762
+ unresolved = true;
12763
+ return "";
12764
+ }
12765
+ return value;
12766
+ });
12767
+ return unresolved ? void 0 : joinTemplate(platform, substituted);
12768
+ }
12769
+ function installRootDirectories(spec, input, dependencies, platform, home) {
12770
+ const templates = (platform === "win32" ? spec.installRoots?.windows : spec.installRoots?.posix) ?? [];
12771
+ const directories = [];
12772
+ for (const template of templates) {
12773
+ if (template === VERSION_MANAGER_ROOTS) {
12774
+ directories.push(...versionManagerBinaryDirectories({
12775
+ platform,
12776
+ environment: input.environment,
12777
+ home,
12778
+ ...dependencies.subdirectories ? { subdirectories: dependencies.subdirectories } : {}
12779
+ }));
12780
+ continue;
12781
+ }
12782
+ const directory = expandInstallRoot(template, input.environment, platform, home);
12783
+ if (directory !== void 0)
12784
+ directories.push(directory);
12785
+ }
12786
+ return directories;
12787
+ }
12788
+ function harnessCandidates(spec, input, dependencies = {}) {
12789
+ const platform = input.platform ?? process.platform;
12790
+ const pathFlavor = targetPath(platform);
12791
+ const configured = input.command ?? (spec.commandEnvironmentVariable ? environmentValue(input.environment, spec.commandEnvironmentVariable) : void 0);
12792
+ const command = configured ?? spec.command;
12793
+ if (pathFlavor.isAbsolute(command) || command.includes("/") || command.includes("\\")) {
12794
+ return [{ candidate: command, source: "configured" }];
12795
+ }
12796
+ const candidates = [];
12797
+ const extensions = executableExtensions(command, platform, input.environment);
12798
+ for (const directory of pathDirectories(input.environment, platform)) {
12799
+ for (const extension of extensions) {
12800
+ candidates.push({
12801
+ candidate: pathFlavor.join(directory, command + extension),
12802
+ source: "path"
12803
+ });
12804
+ }
12805
+ }
12806
+ if (configured !== void 0)
12807
+ return candidates;
12808
+ const home = resolveHomeDirectory(input);
12809
+ for (const directory of installRootDirectories(spec, input, dependencies, platform, home)) {
12810
+ for (const extension of installRootExtensions(platform)) {
12811
+ candidates.push({
12812
+ candidate: pathFlavor.join(directory, spec.command + extension),
12813
+ source: "install-root"
12814
+ });
12815
+ }
12816
+ }
12817
+ return candidates;
12818
+ }
12819
+ function resolveHarnessExecutable(spec, input, dependencies = {}) {
12820
+ const platform = input.platform ?? process.platform;
12821
+ const isExecutable = dependencies.isExecutable ?? ((candidate) => isExecutableFile(candidate, platform));
12822
+ const runnable = spec.runnableCandidate ?? ((candidate) => candidate);
12823
+ const context = { platform, isExecutable };
12824
+ for (const { candidate, source } of harnessCandidates(spec, input, dependencies)) {
12825
+ const executable = runnable(candidate, context);
12826
+ if (executable !== void 0 && isExecutable(executable))
12827
+ return { executable, source };
12828
+ }
12829
+ return void 0;
12830
+ }
12831
+
12832
+ // ../../harness-discovery/dist/installation.js
12833
+ import { execFile } from "node:child_process";
12834
+ import { homedir } from "node:os";
12835
+ function runInstallationCommand(command, args, environment, timeout = 3e4) {
12836
+ const env = withNodeRuntimeOnPath(environment);
12837
+ const invocation = /\.[cm]?js$/i.test(command) ? commandInvocation(process.execPath, [command, ...args], env) : commandInvocation(command, args, env);
12838
+ return new Promise((resolve, reject) => {
12839
+ const child = execFile(invocation.command, invocation.arguments, {
12840
+ env,
12841
+ cwd: env.HOME ?? env.USERPROFILE ?? homedir(),
12842
+ encoding: "utf8",
12843
+ timeout,
12844
+ killSignal: "SIGKILL",
12845
+ maxBuffer: 1024 * 1024,
12846
+ windowsHide: true,
12847
+ windowsVerbatimArguments: invocation.windowsVerbatimArguments
12848
+ }, (error51, stdout, stderr) => {
12849
+ if (error51)
12850
+ reject(new Error(error51.killed ? "Harness command timed out" : "Harness command failed; check the native installation and retry"));
12851
+ else
12852
+ resolve((stdout || stderr).trim());
12853
+ });
12854
+ child.stdin?.end();
12855
+ });
12856
+ }
12857
+ function installationVersion(value) {
12858
+ if (typeof value !== "string" || !/^v?\d+(?:\.\d+){1,3}(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(value.trim()))
12859
+ throw new Error("Harness returned an invalid version");
12860
+ return value.trim().replace(/^v/, "");
12861
+ }
12862
+ function versionFromOutput(output) {
12863
+ return installationVersion(output.match(/\b\d+(?:\.\d+){1,3}(?:-[\w.-]+)?(?:\+[\w.-]+)?\b/)?.[0]);
12864
+ }
12865
+ function newerInstallationVersion(current, latest) {
12866
+ const a = installationVersion(current).replace(/\+.*/, "");
12867
+ const b = installationVersion(latest).replace(/\+.*/, "");
12868
+ const coreA = a.replace(/-.*/, "").split(".").map(BigInt);
12869
+ const coreB = b.replace(/-.*/, "").split(".").map(BigInt);
12870
+ for (let i = 0; i < Math.max(coreA.length, coreB.length); i++) {
12871
+ if ((coreA[i] ?? 0n) !== (coreB[i] ?? 0n))
12872
+ return (coreB[i] ?? 0n) > (coreA[i] ?? 0n);
12873
+ }
12874
+ const preA = a.includes("-") ? a.slice(a.indexOf("-") + 1).split(".") : [];
12875
+ const preB = b.includes("-") ? b.slice(b.indexOf("-") + 1).split(".") : [];
12876
+ if (!preA.length || !preB.length)
12877
+ return !!preA.length && !preB.length;
12878
+ for (let i = 0; i < Math.max(preA.length, preB.length); i++) {
12879
+ const x3 = preA[i];
12880
+ const y = preB[i];
12881
+ if (x3 === y)
12882
+ continue;
12883
+ if (x3 === void 0 || y === void 0)
12884
+ return x3 === void 0;
12885
+ const numericX = /^\d+$/.test(x3);
12886
+ const numericY = /^\d+$/.test(y);
12887
+ if (numericX && numericY) {
12888
+ if (BigInt(x3) === BigInt(y))
12889
+ continue;
12890
+ return BigInt(y) > BigInt(x3);
12891
+ }
12892
+ if (numericX !== numericY)
12893
+ return numericX;
12894
+ return y > x3;
12895
+ }
12896
+ return false;
12897
+ }
12898
+ function createInstallationManager(options) {
12899
+ let checking;
12900
+ let updating;
12901
+ const check2 = () => checking ??= options.check().finally(() => {
12902
+ checking = void 0;
12903
+ });
12904
+ return (action) => {
12905
+ if (updating)
12906
+ return updating;
12907
+ if (action === "check")
12908
+ return check2();
12909
+ updating = (async () => {
12910
+ const before = await check2();
12911
+ if (!before.updateAvailable)
12912
+ return before;
12913
+ if (!before.canUpdate)
12914
+ throw new Error(before.message ?? "This installation cannot be updated automatically");
12915
+ await options.update(before);
12916
+ const after = await check2();
12917
+ if (after.currentVersion === before.currentVersion)
12918
+ throw new Error("The Harness version did not change; check the native updater and retry");
12919
+ return after;
12920
+ })().finally(() => {
12921
+ updating = void 0;
12922
+ });
12923
+ return updating;
12924
+ };
12925
+ }
12926
+ async function fetchInstallationText(url2) {
12927
+ const request = async () => {
12928
+ const response = await fetch(url2, { signal: AbortSignal.timeout(15e3) });
12929
+ if (!response.ok)
12930
+ throw new Error("Could not check the latest Harness version");
12931
+ return response.text();
12932
+ };
12933
+ try {
12934
+ return await request();
12935
+ } catch (error51) {
12936
+ if (error51 instanceof DOMException && (error51.name === "AbortError" || error51.name === "TimeoutError"))
12937
+ throw error51;
12938
+ return request();
12939
+ }
12940
+ }
12941
+
12942
+ // ../../harness-discovery/dist/installer.js
12943
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
12944
+ import { tmpdir } from "node:os";
12945
+ import { join } from "node:path";
12946
+ function createHarnessInstaller(environment, source) {
12947
+ return async () => {
12948
+ if (!["darwin", "linux", "win32"].includes(process.platform))
12949
+ throw new Error("Unsupported installation platform");
12950
+ const env = withNodeRuntimeOnPath(environment);
12951
+ if ("npm" in source) {
12952
+ const npm = resolveHarnessExecutable({
12953
+ id: "npm",
12954
+ command: "npm",
12955
+ installRoots: {
12956
+ posix: [
12957
+ "~/.npm-global/bin",
12958
+ "~/.local/bin",
12959
+ VERSION_MANAGER_ROOTS,
12960
+ "/opt/homebrew/bin",
12961
+ "/usr/local/bin",
12962
+ "/usr/bin"
12963
+ ],
12964
+ windows: [
12965
+ "${APPDATA}/npm",
12966
+ VERSION_MANAGER_ROOTS,
12967
+ "${ProgramFiles}/nodejs",
12968
+ "${LOCALAPPDATA}/Programs/nodejs"
12969
+ ]
12970
+ }
12971
+ }, { environment: env });
12972
+ if (!npm)
12973
+ throw new Error("Install Node.js and npm first");
12974
+ await runInstallationCommand(npm.executable, ["install", "--global", source.npm], {
12975
+ ...env,
12976
+ ...source.allowScripts ? { npm_config_allow_scripts: source.allowScripts } : {}
12977
+ }, 6e5);
12978
+ return;
12979
+ }
12980
+ const windows = process.platform === "win32";
12981
+ const url2 = windows ? source.windows : source.posix;
12982
+ if (new URL(url2).protocol !== "https:")
12983
+ throw new Error("Installer requires HTTPS");
12984
+ const script = await fetchInstallationText(url2);
12985
+ const directory = await mkdtemp(join(tmpdir(), "codexhost-installer-"));
12986
+ try {
12987
+ const file2 = join(directory, windows ? "install.ps1" : "install.sh");
12988
+ await writeFile(file2, script, { mode: 384 });
12989
+ await runInstallationCommand(windows ? "powershell.exe" : source.shell ?? "bash", windows ? ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", file2] : [file2], env, 6e5);
12990
+ } finally {
12991
+ await rm(directory, { recursive: true, force: true });
12992
+ }
12993
+ };
12994
+ }
12995
+
12593
12996
  // dist/qoder-adapter.js
12594
12997
  import { randomUUID as randomUUID2 } from "node:crypto";
12595
- import path5 from "node:path";
12998
+ import path6 from "node:path";
12596
12999
 
12597
13000
  // ../../../node_modules/zod/v4/classic/external.js
12598
13001
  var external_exports = {};
@@ -13360,10 +13763,10 @@ function mergeDefs(...defs) {
13360
13763
  function cloneDef(schema) {
13361
13764
  return mergeDefs(schema._zod.def);
13362
13765
  }
13363
- function getElementAtPath(obj, path6) {
13364
- if (!path6)
13766
+ function getElementAtPath(obj, path7) {
13767
+ if (!path7)
13365
13768
  return obj;
13366
- return path6.reduce((acc, key) => acc?.[key], obj);
13769
+ return path7.reduce((acc, key) => acc?.[key], obj);
13367
13770
  }
13368
13771
  function promiseAllObject(promisesObj) {
13369
13772
  const keys = Object.keys(promisesObj);
@@ -13772,11 +14175,11 @@ function explicitlyAborted(x3, startIndex = 0) {
13772
14175
  }
13773
14176
  return false;
13774
14177
  }
13775
- function prefixIssues(path6, issues) {
14178
+ function prefixIssues(path7, issues) {
13776
14179
  return issues.map((iss) => {
13777
14180
  var _a5;
13778
14181
  (_a5 = iss).path ?? (_a5.path = []);
13779
- iss.path.unshift(path6);
14182
+ iss.path.unshift(path7);
13780
14183
  return iss;
13781
14184
  });
13782
14185
  }
@@ -13923,16 +14326,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
13923
14326
  }
13924
14327
  function formatError(error51, mapper = (issue2) => issue2.message) {
13925
14328
  const fieldErrors = { _errors: [] };
13926
- const processError = (error52, path6 = []) => {
14329
+ const processError = (error52, path7 = []) => {
13927
14330
  for (const issue2 of error52.issues) {
13928
14331
  if (issue2.code === "invalid_union" && issue2.errors.length) {
13929
- issue2.errors.map((issues) => processError({ issues }, [...path6, ...issue2.path]));
14332
+ issue2.errors.map((issues) => processError({ issues }, [...path7, ...issue2.path]));
13930
14333
  } else if (issue2.code === "invalid_key") {
13931
- processError({ issues: issue2.issues }, [...path6, ...issue2.path]);
14334
+ processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
13932
14335
  } else if (issue2.code === "invalid_element") {
13933
- processError({ issues: issue2.issues }, [...path6, ...issue2.path]);
14336
+ processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
13934
14337
  } else {
13935
- const fullpath = [...path6, ...issue2.path];
14338
+ const fullpath = [...path7, ...issue2.path];
13936
14339
  if (fullpath.length === 0) {
13937
14340
  fieldErrors._errors.push(mapper(issue2));
13938
14341
  } else {
@@ -13959,17 +14362,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
13959
14362
  }
13960
14363
  function treeifyError(error51, mapper = (issue2) => issue2.message) {
13961
14364
  const result = { errors: [] };
13962
- const processError = (error52, path6 = []) => {
14365
+ const processError = (error52, path7 = []) => {
13963
14366
  var _a5, _b;
13964
14367
  for (const issue2 of error52.issues) {
13965
14368
  if (issue2.code === "invalid_union" && issue2.errors.length) {
13966
- issue2.errors.map((issues) => processError({ issues }, [...path6, ...issue2.path]));
14369
+ issue2.errors.map((issues) => processError({ issues }, [...path7, ...issue2.path]));
13967
14370
  } else if (issue2.code === "invalid_key") {
13968
- processError({ issues: issue2.issues }, [...path6, ...issue2.path]);
14371
+ processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
13969
14372
  } else if (issue2.code === "invalid_element") {
13970
- processError({ issues: issue2.issues }, [...path6, ...issue2.path]);
14373
+ processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
13971
14374
  } else {
13972
- const fullpath = [...path6, ...issue2.path];
14375
+ const fullpath = [...path7, ...issue2.path];
13973
14376
  if (fullpath.length === 0) {
13974
14377
  result.errors.push(mapper(issue2));
13975
14378
  continue;
@@ -14001,8 +14404,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
14001
14404
  }
14002
14405
  function toDotPath(_path) {
14003
14406
  const segs = [];
14004
- const path6 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
14005
- for (const seg of path6) {
14407
+ const path7 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
14408
+ for (const seg of path7) {
14006
14409
  if (typeof seg === "number")
14007
14410
  segs.push(`[${seg}]`);
14008
14411
  else if (typeof seg === "symbol")
@@ -26694,13 +27097,13 @@ function resolveRef(ref, ctx) {
26694
27097
  if (!ref.startsWith("#")) {
26695
27098
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
26696
27099
  }
26697
- const path6 = ref.slice(1).split("/").filter(Boolean);
26698
- if (path6.length === 0) {
27100
+ const path7 = ref.slice(1).split("/").filter(Boolean);
27101
+ if (path7.length === 0) {
26699
27102
  return ctx.rootSchema;
26700
27103
  }
26701
27104
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
26702
- if (path6[0] === defsKey) {
26703
- const key = path6[1];
27105
+ if (path7[0] === defsKey) {
27106
+ const key = path7[1];
26704
27107
  if (!key || !ctx.defs[key]) {
26705
27108
  throw new Error(`Reference not found: ${ref}`);
26706
27109
  }
@@ -27194,6 +27597,7 @@ var CONSOLE_HOST_METHODS = Object.freeze([
27194
27597
  "codexhost/harness/display-settings/get",
27195
27598
  "codexhost/harness/display-settings/set",
27196
27599
  "codexhost/harness/inspect",
27600
+ "codexhost/harness/installation",
27197
27601
  "codexhost/harness/launch-settings/get",
27198
27602
  "codexhost/harness/launch-settings/set",
27199
27603
  "codexhost/harness/web-ui/open",
@@ -27840,14 +28244,17 @@ var harnessLaunchSettingsSchema = external_exports.object({
27840
28244
  // ../../shared-contracts/dist/harness-installation.js
27841
28245
  var harnessInstallationParamsSchema = external_exports.object({
27842
28246
  harnessId: harnessIdSchema,
27843
- action: external_exports.enum(["check", "update"])
28247
+ action: external_exports.enum(["check", "update", "install"])
27844
28248
  }).strict();
27845
28249
  var harnessInstallationStateSchema = external_exports.object({
27846
28250
  currentVersion: external_exports.string().min(1).max(128),
27847
28251
  latestVersion: external_exports.string().min(1).max(128),
27848
28252
  updateAvailable: external_exports.boolean(),
27849
28253
  canUpdate: external_exports.boolean(),
27850
- message: external_exports.string().max(2048).optional()
28254
+ // Adapter-owned diagnostic text; UI uses messageCode rather than displaying it verbatim.
28255
+ message: external_exports.string().max(2048).optional(),
28256
+ messageCode: external_exports.string().min(1).max(128).optional(),
28257
+ latestVersionKind: external_exports.enum(["unknown", "tracking-branch"]).optional()
27851
28258
  }).strict();
27852
28259
 
27853
28260
  // ../../shared-contracts/dist/codex-accounts.js
@@ -28149,347 +28556,43 @@ var updateStatusResultSchema = external_exports.strictObject({
28149
28556
  status: updateStatusSchema.nullable()
28150
28557
  });
28151
28558
 
28559
+ // ../../shared-contracts/dist/remote-runtime.js
28560
+ var remoteUpdatePhaseSchema = external_exports.enum([
28561
+ "idle",
28562
+ "installing",
28563
+ "restarting",
28564
+ "succeeded",
28565
+ "failed"
28566
+ ]);
28567
+ var runtimeStatusSchema = external_exports.object({
28568
+ runningVersion: external_exports.string().nullable(),
28569
+ installedVersion: external_exports.string().nullable(),
28570
+ restartRequired: external_exports.boolean(),
28571
+ remote: external_exports.boolean(),
28572
+ updateSupported: external_exports.boolean(),
28573
+ update: external_exports.object({
28574
+ phase: remoteUpdatePhaseSchema,
28575
+ targetVersion: external_exports.string().nullable(),
28576
+ error: external_exports.string().nullable()
28577
+ })
28578
+ });
28579
+ var remoteUpdateParamsSchema = external_exports.object({
28580
+ version: external_exports.string().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u)
28581
+ }).strict();
28582
+ var remoteSshSetupParamsSchema = external_exports.object({
28583
+ hostname: external_exports.string().min(1).max(1024).refine((value) => !value.startsWith("-") && !/\s/u.test(value)),
28584
+ port: external_exports.number().int().min(1).max(65535).nullable(),
28585
+ identity: external_exports.string().max(4096).nullable(),
28586
+ action: external_exports.enum(["inspect", "install", "update", "repair"]),
28587
+ version: external_exports.string().regex(/^\d+\.\d+\.\d+$/u).nullable()
28588
+ }).strict();
28589
+ var remoteSshSetupResultSchema = external_exports.object({ state: external_exports.enum(["installed", "not-installed"]) }).strict();
28590
+
28152
28591
  // ../../shared-contracts/dist/index.js
28153
28592
  var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
28154
28593
 
28155
28594
  // dist/qoder-command.js
28156
28595
  import path4 from "node:path";
28157
-
28158
- // ../../harness-discovery/dist/environment.js
28159
- import fs from "node:fs";
28160
- import path from "node:path";
28161
- function targetPath(platform) {
28162
- return platform === "win32" ? path.win32 : path.posix;
28163
- }
28164
- function environmentValue(environment, name) {
28165
- const lowered = name.toLowerCase();
28166
- for (const [key, value] of Object.entries(environment)) {
28167
- if (key.toLowerCase() === lowered)
28168
- return value;
28169
- }
28170
- return void 0;
28171
- }
28172
- function pathDelimiter(platform) {
28173
- return platform === "win32" ? ";" : ":";
28174
- }
28175
- function pathDirectories(environment, platform) {
28176
- return (environmentValue(environment, "PATH") ?? "").split(pathDelimiter(platform)).map((directory) => directory.trim().replace(/^"|"$/gu, "")).filter(Boolean);
28177
- }
28178
- function executableExtensions(command, platform, environment) {
28179
- if (platform !== "win32")
28180
- return [""];
28181
- if (targetPath(platform).extname(command) !== "")
28182
- return [""];
28183
- return (environmentValue(environment, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD").split(";").map((extension) => extension.trim()).filter(Boolean);
28184
- }
28185
- function isExecutableFile(filePath, platform) {
28186
- try {
28187
- fs.accessSync(filePath, platform === "win32" ? fs.constants.F_OK : fs.constants.X_OK);
28188
- return fs.statSync(filePath).isFile();
28189
- } catch {
28190
- return false;
28191
- }
28192
- }
28193
- function subdirectoryNames(directory) {
28194
- try {
28195
- return fs.readdirSync(directory, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
28196
- } catch {
28197
- return [];
28198
- }
28199
- }
28200
- function newestFirst(names) {
28201
- return [...names].sort((left, right) => right.localeCompare(left, void 0, { numeric: true }));
28202
- }
28203
-
28204
- // ../../harness-discovery/dist/invocation.js
28205
- import path2 from "node:path";
28206
- function commandInvocation(command, arguments_, environment, platform = process.platform) {
28207
- const extension = path2.win32.extname(command).toLowerCase();
28208
- if (platform !== "win32" || ![".cmd", ".bat"].includes(extension)) {
28209
- return { command, arguments: [...arguments_], windowsVerbatimArguments: false };
28210
- }
28211
- const quote = (value) => `"${value.replaceAll("%", "%%").replaceAll('"', '""')}"`;
28212
- const commandLine = [command, ...arguments_].map(quote).join(" ");
28213
- return {
28214
- command: environmentValue(environment, "ComSpec") ?? "cmd.exe",
28215
- arguments: ["/d", "/v:off", "/s", "/c", `"${commandLine}"`],
28216
- windowsVerbatimArguments: true
28217
- };
28218
- }
28219
-
28220
- // ../../harness-discovery/dist/node-runtime.js
28221
- import path3 from "node:path";
28222
- function withNodeRuntimeOnPath(environment, runtimeExecutable = process.execPath, platform = process.platform) {
28223
- const pathKey = Object.keys(environment).find((name) => name.toLowerCase() === "path") ?? "PATH";
28224
- const delimiter = platform === "win32" ? ";" : ":";
28225
- const runtimeDirectory = path3.dirname(runtimeExecutable);
28226
- const directories = (environment[pathKey] ?? "").split(delimiter).filter(Boolean);
28227
- const equal = platform === "win32" ? (value) => value.toLowerCase() : (value) => value;
28228
- if (!directories.some((directory) => equal(directory) === equal(runtimeDirectory))) {
28229
- directories.push(runtimeDirectory);
28230
- }
28231
- return { ...environment, [pathKey]: directories.join(delimiter) };
28232
- }
28233
-
28234
- // ../../harness-discovery/dist/resolve.js
28235
- import os from "node:os";
28236
-
28237
- // ../../harness-discovery/dist/version-managers.js
28238
- function versionManagerBinaryDirectories(context) {
28239
- const { platform, environment, home } = context;
28240
- const list = context.subdirectories ?? subdirectoryNames;
28241
- const pathFlavor = targetPath(platform);
28242
- const value = (name) => environmentValue(environment, name);
28243
- const directories = [];
28244
- const versioned = (root, ...tail) => {
28245
- for (const version2 of newestFirst(list(root))) {
28246
- directories.push(pathFlavor.join(root, version2, ...tail));
28247
- }
28248
- };
28249
- if (platform === "win32") {
28250
- const appData = value("APPDATA") ?? pathFlavor.join(home, "AppData", "Roaming");
28251
- const localAppData = value("LOCALAPPDATA") ?? pathFlavor.join(home, "AppData", "Local");
28252
- versioned(pathFlavor.join(appData, "nvm"));
28253
- versioned(value("FNM_DIR") ?? pathFlavor.join(appData, "fnm", "node-versions"), "installation");
28254
- directories.push(pathFlavor.join(localAppData, "Volta", "bin"));
28255
- directories.push(pathFlavor.join(home, ".bun", "bin"));
28256
- const pnpmHome2 = value("PNPM_HOME");
28257
- if (pnpmHome2)
28258
- directories.push(pnpmHome2);
28259
- directories.push(pathFlavor.join(localAppData, "pnpm"));
28260
- return directories;
28261
- }
28262
- versioned(pathFlavor.join(value("NVM_DIR") ?? pathFlavor.join(home, ".nvm"), "versions", "node"), "bin");
28263
- const fnmRoots = [
28264
- value("FNM_DIR"),
28265
- pathFlavor.join(home, ".local", "share", "fnm"),
28266
- pathFlavor.join(home, "Library", "Application Support", "fnm")
28267
- ].filter((root) => root !== void 0);
28268
- for (const root of fnmRoots) {
28269
- versioned(pathFlavor.join(root, "node-versions"), "installation", "bin");
28270
- }
28271
- const voltaHome = value("VOLTA_HOME") ?? pathFlavor.join(home, ".volta");
28272
- versioned(pathFlavor.join(voltaHome, "tools", "image", "node"), "bin");
28273
- directories.push(pathFlavor.join(voltaHome, "bin"));
28274
- const asdfHome = value("ASDF_DATA_DIR") ?? pathFlavor.join(home, ".asdf");
28275
- versioned(pathFlavor.join(asdfHome, "installs", "nodejs"), "bin");
28276
- directories.push(pathFlavor.join(asdfHome, "shims"));
28277
- const nodenvHome = value("NODENV_ROOT") ?? pathFlavor.join(home, ".nodenv");
28278
- versioned(pathFlavor.join(nodenvHome, "versions"), "bin");
28279
- directories.push(pathFlavor.join(nodenvHome, "shims"));
28280
- versioned(pathFlavor.join(value("N_PREFIX") ?? "/usr/local", "n", "versions", "node"), "bin");
28281
- directories.push(pathFlavor.join(home, ".bun", "bin"));
28282
- const pnpmHome = value("PNPM_HOME");
28283
- if (pnpmHome)
28284
- directories.push(pnpmHome);
28285
- directories.push(pathFlavor.join(home, "Library", "pnpm"));
28286
- directories.push(pathFlavor.join(home, ".local", "share", "pnpm"));
28287
- for (const prefix of ["/opt/homebrew/opt", "/usr/local/opt"]) {
28288
- for (const formula of newestFirst(list(prefix).filter((name) => name.startsWith("node@")))) {
28289
- directories.push(pathFlavor.join(prefix, formula, "bin"));
28290
- }
28291
- }
28292
- return directories;
28293
- }
28294
-
28295
- // ../../harness-discovery/dist/resolve.js
28296
- var VERSION_MANAGER_ROOTS = "<version-managers>";
28297
- function installRootExtensions(platform) {
28298
- return platform === "win32" ? [".exe", ".cmd"] : [""];
28299
- }
28300
- function resolveHomeDirectory(input) {
28301
- return input.homeDirectory ?? environmentValue(input.environment, "HOME") ?? environmentValue(input.environment, "USERPROFILE") ?? os.homedir();
28302
- }
28303
- function templateVariables(environment, platform, home) {
28304
- const pathFlavor = targetPath(platform);
28305
- return {
28306
- HOME: home,
28307
- USERPROFILE: home,
28308
- APPDATA: environmentValue(environment, "APPDATA") ?? pathFlavor.join(home, "AppData", "Roaming"),
28309
- LOCALAPPDATA: environmentValue(environment, "LOCALAPPDATA") ?? pathFlavor.join(home, "AppData", "Local")
28310
- };
28311
- }
28312
- function joinTemplate(platform, value) {
28313
- const pathFlavor = targetPath(platform);
28314
- const segments = value.split("/");
28315
- const head = segments[0] ?? "";
28316
- const tail = segments.slice(1);
28317
- if (head === "")
28318
- return pathFlavor.join(pathFlavor.sep, ...tail);
28319
- return tail.length === 0 ? head : pathFlavor.join(head, ...tail);
28320
- }
28321
- function expandInstallRoot(template, environment, platform, home) {
28322
- const variables = templateVariables(environment, platform, home);
28323
- let unresolved = false;
28324
- const substituted = template.replace(/^~(?=\/|$)/u, home).replace(/\$\{(\w+)\}/gu, (_match, name) => {
28325
- const value = variables[name] ?? environmentValue(environment, name);
28326
- if (value === void 0 || value === "") {
28327
- unresolved = true;
28328
- return "";
28329
- }
28330
- return value;
28331
- });
28332
- return unresolved ? void 0 : joinTemplate(platform, substituted);
28333
- }
28334
- function installRootDirectories(spec, input, dependencies, platform, home) {
28335
- const templates = (platform === "win32" ? spec.installRoots?.windows : spec.installRoots?.posix) ?? [];
28336
- const directories = [];
28337
- for (const template of templates) {
28338
- if (template === VERSION_MANAGER_ROOTS) {
28339
- directories.push(...versionManagerBinaryDirectories({
28340
- platform,
28341
- environment: input.environment,
28342
- home,
28343
- ...dependencies.subdirectories ? { subdirectories: dependencies.subdirectories } : {}
28344
- }));
28345
- continue;
28346
- }
28347
- const directory = expandInstallRoot(template, input.environment, platform, home);
28348
- if (directory !== void 0)
28349
- directories.push(directory);
28350
- }
28351
- return directories;
28352
- }
28353
- function harnessCandidates(spec, input, dependencies = {}) {
28354
- const platform = input.platform ?? process.platform;
28355
- const pathFlavor = targetPath(platform);
28356
- const configured = input.command ?? (spec.commandEnvironmentVariable ? environmentValue(input.environment, spec.commandEnvironmentVariable) : void 0);
28357
- const command = configured ?? spec.command;
28358
- if (pathFlavor.isAbsolute(command) || command.includes("/") || command.includes("\\")) {
28359
- return [{ candidate: command, source: "configured" }];
28360
- }
28361
- const candidates = [];
28362
- const extensions = executableExtensions(command, platform, input.environment);
28363
- for (const directory of pathDirectories(input.environment, platform)) {
28364
- for (const extension of extensions) {
28365
- candidates.push({
28366
- candidate: pathFlavor.join(directory, command + extension),
28367
- source: "path"
28368
- });
28369
- }
28370
- }
28371
- if (configured !== void 0)
28372
- return candidates;
28373
- const home = resolveHomeDirectory(input);
28374
- for (const directory of installRootDirectories(spec, input, dependencies, platform, home)) {
28375
- for (const extension of installRootExtensions(platform)) {
28376
- candidates.push({
28377
- candidate: pathFlavor.join(directory, spec.command + extension),
28378
- source: "install-root"
28379
- });
28380
- }
28381
- }
28382
- return candidates;
28383
- }
28384
- function resolveHarnessExecutable(spec, input, dependencies = {}) {
28385
- const platform = input.platform ?? process.platform;
28386
- const isExecutable = dependencies.isExecutable ?? ((candidate) => isExecutableFile(candidate, platform));
28387
- const runnable = spec.runnableCandidate ?? ((candidate) => candidate);
28388
- const context = { platform, isExecutable };
28389
- for (const { candidate, source } of harnessCandidates(spec, input, dependencies)) {
28390
- const executable = runnable(candidate, context);
28391
- if (executable !== void 0 && isExecutable(executable))
28392
- return { executable, source };
28393
- }
28394
- return void 0;
28395
- }
28396
-
28397
- // ../../harness-discovery/dist/installation.js
28398
- import { execFile } from "node:child_process";
28399
- import { homedir } from "node:os";
28400
- function runInstallationCommand(command, args, environment, timeout = 3e4) {
28401
- const env = withNodeRuntimeOnPath(environment);
28402
- const invocation = /\.[cm]?js$/i.test(command) ? commandInvocation(process.execPath, [command, ...args], env) : commandInvocation(command, args, env);
28403
- return new Promise((resolve, reject) => {
28404
- const child = execFile(invocation.command, invocation.arguments, {
28405
- env,
28406
- cwd: env.HOME ?? env.USERPROFILE ?? homedir(),
28407
- encoding: "utf8",
28408
- timeout,
28409
- killSignal: "SIGKILL",
28410
- maxBuffer: 1024 * 1024,
28411
- windowsHide: true,
28412
- windowsVerbatimArguments: invocation.windowsVerbatimArguments
28413
- }, (error51, stdout, stderr) => {
28414
- if (error51)
28415
- reject(new Error(error51.killed ? "Harness command timed out" : "Harness command failed; check the native installation and retry"));
28416
- else
28417
- resolve((stdout || stderr).trim());
28418
- });
28419
- child.stdin?.end();
28420
- });
28421
- }
28422
- function installationVersion(value) {
28423
- if (typeof value !== "string" || !/^v?\d+(?:\.\d+){1,3}(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(value.trim()))
28424
- throw new Error("Harness returned an invalid version");
28425
- return value.trim().replace(/^v/, "");
28426
- }
28427
- function versionFromOutput(output) {
28428
- return installationVersion(output.match(/\b\d+(?:\.\d+){1,3}(?:-[\w.-]+)?(?:\+[\w.-]+)?\b/)?.[0]);
28429
- }
28430
- function newerInstallationVersion(current, latest) {
28431
- const a = installationVersion(current).replace(/\+.*/, "");
28432
- const b = installationVersion(latest).replace(/\+.*/, "");
28433
- const coreA = a.replace(/-.*/, "").split(".").map(BigInt);
28434
- const coreB = b.replace(/-.*/, "").split(".").map(BigInt);
28435
- for (let i = 0; i < Math.max(coreA.length, coreB.length); i++) {
28436
- if ((coreA[i] ?? 0n) !== (coreB[i] ?? 0n))
28437
- return (coreB[i] ?? 0n) > (coreA[i] ?? 0n);
28438
- }
28439
- const preA = a.includes("-") ? a.slice(a.indexOf("-") + 1).split(".") : [];
28440
- const preB = b.includes("-") ? b.slice(b.indexOf("-") + 1).split(".") : [];
28441
- if (!preA.length || !preB.length)
28442
- return !!preA.length && !preB.length;
28443
- for (let i = 0; i < Math.max(preA.length, preB.length); i++) {
28444
- const x3 = preA[i];
28445
- const y = preB[i];
28446
- if (x3 === y)
28447
- continue;
28448
- if (x3 === void 0 || y === void 0)
28449
- return x3 === void 0;
28450
- const numericX = /^\d+$/.test(x3);
28451
- const numericY = /^\d+$/.test(y);
28452
- if (numericX && numericY) {
28453
- if (BigInt(x3) === BigInt(y))
28454
- continue;
28455
- return BigInt(y) > BigInt(x3);
28456
- }
28457
- if (numericX !== numericY)
28458
- return numericX;
28459
- return y > x3;
28460
- }
28461
- return false;
28462
- }
28463
- function createInstallationManager(options) {
28464
- let checking;
28465
- let updating;
28466
- const check2 = () => checking ??= options.check().finally(() => {
28467
- checking = void 0;
28468
- });
28469
- return (action) => {
28470
- if (updating)
28471
- return updating;
28472
- if (action === "check")
28473
- return check2();
28474
- updating = (async () => {
28475
- const before = await check2();
28476
- if (!before.updateAvailable)
28477
- return before;
28478
- if (!before.canUpdate)
28479
- throw new Error(before.message ?? "This installation cannot be updated automatically");
28480
- await options.update(before);
28481
- const after = await check2();
28482
- if (after.currentVersion === before.currentVersion)
28483
- throw new Error("The Harness version did not change; check the native updater and retry");
28484
- return after;
28485
- })().finally(() => {
28486
- updating = void 0;
28487
- });
28488
- return updating;
28489
- };
28490
- }
28491
-
28492
- // dist/qoder-command.js
28493
28596
  var QoderExecutableError = class extends Error {
28494
28597
  code = "QODER_NOT_FOUND";
28495
28598
  };
@@ -28745,6 +28848,26 @@ function mapQoderException(error51) {
28745
28848
  };
28746
28849
  }
28747
28850
 
28851
+ // dist/qoder-login-check.js
28852
+ import { execFile as execFile2 } from "node:child_process";
28853
+ function qoderLoginRequired(text) {
28854
+ return /\bnot logged in\b|\bauthentication (?:required|expired)\b/i.test(text);
28855
+ }
28856
+ function checkQoderLogin(executable, environment, cwd) {
28857
+ return new Promise((resolve) => {
28858
+ execFile2(executable, ["--list-models"], {
28859
+ env: environment,
28860
+ cwd,
28861
+ timeout: 1e4,
28862
+ maxBuffer: 64 * 1024,
28863
+ windowsHide: true
28864
+ }, (error51, stdout, stderr) => {
28865
+ resolve(Boolean(error51 && !error51.killed && qoderLoginRequired(`${stdout}
28866
+ ${stderr}`)));
28867
+ });
28868
+ });
28869
+ }
28870
+
28748
28871
  // ../../harness-adapter/dist/approval.js
28749
28872
  function invalidRequest(message) {
28750
28873
  return { code: "invalidRequest", message, retryable: false };
@@ -30096,8 +30219,8 @@ function getErrorMap2() {
30096
30219
 
30097
30220
  // ../../../node_modules/zod/v3/helpers/parseUtil.js
30098
30221
  var makeIssue = (params) => {
30099
- const { data, path: path6, errorMaps, issueData } = params;
30100
- const fullPath = [...path6, ...issueData.path || []];
30222
+ const { data, path: path7, errorMaps, issueData } = params;
30223
+ const fullPath = [...path7, ...issueData.path || []];
30101
30224
  const fullIssue = {
30102
30225
  ...issueData,
30103
30226
  path: fullPath
@@ -30212,11 +30335,11 @@ var errorUtil;
30212
30335
 
30213
30336
  // ../../../node_modules/zod/v3/types.js
30214
30337
  var ParseInputLazyPath = class {
30215
- constructor(parent, value, path6, key) {
30338
+ constructor(parent, value, path7, key) {
30216
30339
  this._cachedPath = [];
30217
30340
  this.parent = parent;
30218
30341
  this.data = value;
30219
- this._path = path6;
30342
+ this._path = path7;
30220
30343
  this._key = key;
30221
30344
  }
30222
30345
  get path() {
@@ -33743,11 +33866,11 @@ function normalizeObjectSchema(schema) {
33743
33866
  }
33744
33867
  return void 0;
33745
33868
  }
33746
- function getDotPath(path6) {
33747
- if (path6.length === 0) {
33869
+ function getDotPath(path7) {
33870
+ if (path7.length === 0) {
33748
33871
  return "object root";
33749
33872
  }
33750
- return path6.reduce((acc, seg, index) => {
33873
+ return path7.reduce((acc, seg, index) => {
33751
33874
  if (index === 0) {
33752
33875
  return String(seg);
33753
33876
  }
@@ -52318,12 +52441,171 @@ var QoderSession = class {
52318
52441
  }
52319
52442
  };
52320
52443
 
52444
+ // dist/qoder-session-import.js
52445
+ import { stat } from "node:fs/promises";
52446
+ import path5 from "node:path";
52447
+
52448
+ // ../../harness-adapter/dist/session-import.js
52449
+ var STORAGE_ACCESS_ERRORS = /* @__PURE__ */ new Set(["EACCES", "EPERM", "EIO", "EMFILE", "ENFILE"]);
52450
+ function isStorageAccessError(error51) {
52451
+ return typeof error51 === "object" && error51 !== null && "code" in error51 && typeof error51.code === "string" && STORAGE_ACCESS_ERRORS.has(error51.code);
52452
+ }
52453
+ function sessionImportTitle(value, maxLength = HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH) {
52454
+ if (typeof value !== "string")
52455
+ return null;
52456
+ const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
52457
+ if (!normalized)
52458
+ return null;
52459
+ if (normalized.length <= maxLength)
52460
+ return normalized;
52461
+ const characters = [...normalized];
52462
+ if (characters.length <= maxLength)
52463
+ return normalized;
52464
+ return `${characters.slice(0, maxLength - 1).join("").trimEnd()}…`;
52465
+ }
52466
+ function sessionImportCandidate(input) {
52467
+ const time3 = typeof input.updatedAt === "number" ? input.updatedAt : typeof input.updatedAt === "string" ? Date.parse(input.updatedAt) : Number.NaN;
52468
+ const parsed = harnessSessionImportCandidateSchema.safeParse({
52469
+ nativeSessionId: input.nativeSessionId,
52470
+ cwd: input.cwd,
52471
+ title: typeof input.title === "string" && input.title.trim().length > 0 ? input.title : null,
52472
+ updatedAt: Math.floor(time3),
52473
+ // Unknown must stay unknown; only an explicit boolean is a native statement.
52474
+ running: typeof input.running === "boolean" ? input.running : null
52475
+ });
52476
+ return parsed.success ? parsed.data : null;
52477
+ }
52478
+ var SessionImportScope = class {
52479
+ #abort = new AbortController();
52480
+ #options;
52481
+ #pending = /* @__PURE__ */ new Set();
52482
+ constructor(options) {
52483
+ this.#options = options;
52484
+ }
52485
+ #closed() {
52486
+ return {
52487
+ ok: false,
52488
+ error: { code: "invalidState", message: this.#options.closedMessage, retryable: false }
52489
+ };
52490
+ }
52491
+ read(operation) {
52492
+ const signal = this.#abort.signal;
52493
+ if (signal.aborted)
52494
+ return Promise.resolve(this.#closed());
52495
+ let started;
52496
+ try {
52497
+ started = operation(signal);
52498
+ } catch (error51) {
52499
+ started = Promise.reject(error51 instanceof Error ? error51 : new Error("Session read failed"));
52500
+ }
52501
+ const request = started.then((value) => signal.aborted ? this.#closed() : { ok: true, value }).catch(() => signal.aborted ? this.#closed() : {
52502
+ ok: false,
52503
+ error: {
52504
+ code: "unavailable",
52505
+ message: this.#options.unavailableMessage,
52506
+ retryable: true
52507
+ }
52508
+ }).finally(() => this.#pending.delete(request));
52509
+ this.#pending.add(request);
52510
+ return request;
52511
+ }
52512
+ /** `read` for `resolveCandidate`: a null source is the selected Session having disappeared. */
52513
+ async resolve(operation) {
52514
+ const result = await this.read(operation);
52515
+ if (!result.ok)
52516
+ return result;
52517
+ return result.value ? { ok: true, value: result.value } : {
52518
+ ok: false,
52519
+ error: {
52520
+ code: "sessionNotFound",
52521
+ message: this.#options.notFoundMessage,
52522
+ retryable: false
52523
+ }
52524
+ };
52525
+ }
52526
+ /** Idempotent. Resolves after every started read has settled. */
52527
+ async close() {
52528
+ this.#abort.abort();
52529
+ await Promise.allSettled(this.#pending);
52530
+ }
52531
+ };
52532
+
52533
+ // dist/qoder-session-import.js
52534
+ var QoderSessionImport = class {
52535
+ #dependencies;
52536
+ #scope;
52537
+ constructor(dependencies) {
52538
+ this.#dependencies = dependencies;
52539
+ const name = dependencies.displayName;
52540
+ this.#scope = new SessionImportScope({
52541
+ closedMessage: `${name} Session import is closed`,
52542
+ unavailableMessage: `${name} sessions could not be read; check storage access and retry`,
52543
+ notFoundMessage: `${name} Session is no longer importable`
52544
+ });
52545
+ }
52546
+ listCandidates() {
52547
+ return this.#scope.read(async (signal) => {
52548
+ const candidates = /* @__PURE__ */ new Map();
52549
+ for (const info of await this.#dependencies.listSessions()) {
52550
+ signal.throwIfAborted();
52551
+ const candidate = await this.#candidate(info);
52552
+ if (candidate && !candidates.has(candidate.nativeSessionId))
52553
+ candidates.set(candidate.nativeSessionId, candidate);
52554
+ }
52555
+ return [...candidates.values()];
52556
+ });
52557
+ }
52558
+ resolveCandidate(nativeSessionId) {
52559
+ return this.#scope.resolve(async (signal) => {
52560
+ const info = await this.#dependencies.getSessionInfo(nativeSessionId);
52561
+ signal.throwIfAborted();
52562
+ if (info?.sessionId !== nativeSessionId)
52563
+ return null;
52564
+ const candidate = await this.#candidate(info);
52565
+ if (!candidate)
52566
+ return null;
52567
+ return {
52568
+ candidate,
52569
+ nativeRef: nativeSessionRefSchema.parse({
52570
+ harnessId: this.#dependencies.harnessId,
52571
+ nativeSessionId,
52572
+ formatVersion: 1
52573
+ })
52574
+ };
52575
+ });
52576
+ }
52577
+ close() {
52578
+ return this.#scope.close();
52579
+ }
52580
+ async #candidate(info) {
52581
+ if (typeof info.cwd !== "string" || !path5.isAbsolute(info.cwd))
52582
+ return null;
52583
+ const cwd = path5.resolve(info.cwd);
52584
+ try {
52585
+ if (!(await stat(cwd)).isDirectory())
52586
+ return null;
52587
+ } catch (error51) {
52588
+ if (isStorageAccessError(error51))
52589
+ throw error51;
52590
+ return null;
52591
+ }
52592
+ return sessionImportCandidate({
52593
+ nativeSessionId: info.sessionId,
52594
+ cwd,
52595
+ title: sessionImportTitle(info.customTitle) ?? sessionImportTitle(info.summary) ?? sessionImportTitle(info.firstPrompt),
52596
+ updatedAt: info.lastModified
52597
+ // The SDK exposes no cross-process activity marker: idleness cannot be established.
52598
+ });
52599
+ }
52600
+ };
52601
+
52321
52602
  // dist/qoder-adapter.js
52322
52603
  var QoderAdapter = class {
52323
52604
  harnessId;
52324
52605
  #variant;
52325
52606
  commandCatalog = QODER_FALLBACK_COMMAND_CATALOG;
52326
52607
  liveCommandCatalog = true;
52608
+ sessionImport;
52327
52609
  #commandOverride;
52328
52610
  #environment;
52329
52611
  #platform;
@@ -52347,6 +52629,12 @@ var QoderAdapter = class {
52347
52629
  this.#forkSession = options.forkSession ?? runtime.sdk.forkSession;
52348
52630
  this.#getSessionMessages = options.getSessionMessages ?? runtime.sdk.getSessionMessages;
52349
52631
  this.#getSessionInfo = options.getSessionInfo ?? runtime.sdk.getSessionInfo;
52632
+ this.sessionImport = new QoderSessionImport({
52633
+ harnessId: this.harnessId,
52634
+ displayName: this.#variant === "cn" ? "Qoder CN" : "Qoder",
52635
+ listSessions: options.listSessions ?? (() => runtime.sdk.listSessions()),
52636
+ getSessionInfo: this.#getSessionInfo
52637
+ });
52350
52638
  this.#getAvailableModels = options.getAvailableModels;
52351
52639
  this.#resolveExecutable = options.resolveExecutable ?? ((input, dependencies) => resolveQoderExecutable({ ...input, variant: this.#variant }, dependencies));
52352
52640
  }
@@ -52411,11 +52699,15 @@ var QoderAdapter = class {
52411
52699
  } catch {
52412
52700
  }
52413
52701
  } else {
52702
+ let stderr = "";
52414
52703
  try {
52415
52704
  const probeQuery = this.#queryFactory({
52416
52705
  prompt: "",
52417
52706
  options: {
52418
52707
  cwd: input?.cwd ?? process.cwd(),
52708
+ stderr: (chunk) => {
52709
+ stderr = (stderr + chunk).slice(-8192);
52710
+ },
52419
52711
  pathToQoderCLIExecutable: executable,
52420
52712
  ...this.#environment ? { env: this.#environment } : {},
52421
52713
  auth: qoderAuthForEnvironment(this.#variant, this.#environment)
@@ -52432,9 +52724,14 @@ var QoderAdapter = class {
52432
52724
  }
52433
52725
  }
52434
52726
  } catch (error51) {
52727
+ const needsLogin = qoderLoginRequired(stderr) || error51 instanceof Error && error51.message === "Transport closed" && qoderAuthForEnvironment(this.#variant, this.#environment).type === "qodercli" && await checkQoderLogin(executable, this.#environment, input?.cwd);
52435
52728
  const result2 = {
52436
52729
  status: "unavailable",
52437
- error: mapQoderException(error51)
52730
+ error: needsLogin ? {
52731
+ code: "authenticationRequired",
52732
+ message: `Please run ${this.#variant === "cn" ? "qoderclicn" : "qodercli"} login to authenticate.`,
52733
+ retryable: false
52734
+ } : mapQoderException(error51)
52438
52735
  };
52439
52736
  return result2;
52440
52737
  }
@@ -52556,7 +52853,7 @@ var QoderAdapter = class {
52556
52853
  sourceInfo = await this.#getSessionInfo(sourceRef.data.nativeSessionId, { dir: input.cwd });
52557
52854
  } catch {
52558
52855
  }
52559
- if (sourceInfo?.cwd && path5.resolve(sourceInfo.cwd) !== path5.resolve(input.cwd)) {
52856
+ if (sourceInfo?.cwd && path6.resolve(sourceInfo.cwd) !== path6.resolve(input.cwd)) {
52560
52857
  return {
52561
52858
  ok: false,
52562
52859
  error: {
@@ -52706,7 +53003,7 @@ var QoderAdapter = class {
52706
53003
  this.#sessions.clear();
52707
53004
  this.#inspections.clear();
52708
53005
  this.#inFlightInspections.clear();
52709
- await Promise.all(sessions.map((s) => s.close()));
53006
+ await Promise.all([this.sessionImport.close(), ...sessions.map((s) => s.close())]);
52710
53007
  }
52711
53008
  };
52712
53009
 
@@ -52722,6 +53019,7 @@ function createQoderInstallation(environment, command, variant = "global") {
52722
53019
  latestVersion: "Unknown",
52723
53020
  updateAvailable: false,
52724
53021
  canUpdate: false,
53022
+ messageCode: "qoder-check-unavailable",
52725
53023
  message: "This Qoder China release does not expose a non-installing update check. Use its original installer."
52726
53024
  };
52727
53025
  const output = await run(["update", "--check"]);
@@ -52757,7 +53055,13 @@ function createHarnessAdapter(context, variant = "global") {
52757
53055
  variant,
52758
53056
  environment,
52759
53057
  platform: context.platform
52760
- }), { installation: createQoderInstallation(environment, command, variant) });
53058
+ }), {
53059
+ installation: createQoderInstallation(environment, command, variant),
53060
+ install: createHarnessInstaller(environment, variant === "cn" ? {
53061
+ posix: "https://static.qoder.com.cn/qoder-cli-cn/install.sh",
53062
+ windows: "https://static.qoder.com.cn/qoder-cli-cn/install.ps1"
53063
+ } : { posix: "https://qoder.com/install", windows: "https://qoder.com/install.ps1" })
53064
+ });
52761
53065
  }
52762
53066
  export {
52763
53067
  CODEXHOST_QODER_COMMAND,