@codexhost/cli-darwin-x64 0.11.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
  }
@@ -12592,7 +12592,7 @@ var require_dist = __commonJS({
12592
12592
 
12593
12593
  // ../qoder/dist/qoder-adapter.js
12594
12594
  import { randomUUID as randomUUID2 } from "node:crypto";
12595
- import path5 from "node:path";
12595
+ import path6 from "node:path";
12596
12596
 
12597
12597
  // ../../../node_modules/zod/v4/classic/external.js
12598
12598
  var external_exports = {};
@@ -13360,10 +13360,10 @@ function mergeDefs(...defs) {
13360
13360
  function cloneDef(schema) {
13361
13361
  return mergeDefs(schema._zod.def);
13362
13362
  }
13363
- function getElementAtPath(obj, path6) {
13364
- if (!path6)
13363
+ function getElementAtPath(obj, path7) {
13364
+ if (!path7)
13365
13365
  return obj;
13366
- return path6.reduce((acc, key) => acc?.[key], obj);
13366
+ return path7.reduce((acc, key) => acc?.[key], obj);
13367
13367
  }
13368
13368
  function promiseAllObject(promisesObj) {
13369
13369
  const keys = Object.keys(promisesObj);
@@ -13772,11 +13772,11 @@ function explicitlyAborted(x3, startIndex = 0) {
13772
13772
  }
13773
13773
  return false;
13774
13774
  }
13775
- function prefixIssues(path6, issues) {
13775
+ function prefixIssues(path7, issues) {
13776
13776
  return issues.map((iss) => {
13777
13777
  var _a5;
13778
13778
  (_a5 = iss).path ?? (_a5.path = []);
13779
- iss.path.unshift(path6);
13779
+ iss.path.unshift(path7);
13780
13780
  return iss;
13781
13781
  });
13782
13782
  }
@@ -13923,16 +13923,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
13923
13923
  }
13924
13924
  function formatError(error51, mapper = (issue2) => issue2.message) {
13925
13925
  const fieldErrors = { _errors: [] };
13926
- const processError = (error52, path6 = []) => {
13926
+ const processError = (error52, path7 = []) => {
13927
13927
  for (const issue2 of error52.issues) {
13928
13928
  if (issue2.code === "invalid_union" && issue2.errors.length) {
13929
- issue2.errors.map((issues) => processError({ issues }, [...path6, ...issue2.path]));
13929
+ issue2.errors.map((issues) => processError({ issues }, [...path7, ...issue2.path]));
13930
13930
  } else if (issue2.code === "invalid_key") {
13931
- processError({ issues: issue2.issues }, [...path6, ...issue2.path]);
13931
+ processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
13932
13932
  } else if (issue2.code === "invalid_element") {
13933
- processError({ issues: issue2.issues }, [...path6, ...issue2.path]);
13933
+ processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
13934
13934
  } else {
13935
- const fullpath = [...path6, ...issue2.path];
13935
+ const fullpath = [...path7, ...issue2.path];
13936
13936
  if (fullpath.length === 0) {
13937
13937
  fieldErrors._errors.push(mapper(issue2));
13938
13938
  } else {
@@ -13959,17 +13959,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
13959
13959
  }
13960
13960
  function treeifyError(error51, mapper = (issue2) => issue2.message) {
13961
13961
  const result = { errors: [] };
13962
- const processError = (error52, path6 = []) => {
13962
+ const processError = (error52, path7 = []) => {
13963
13963
  var _a5, _b;
13964
13964
  for (const issue2 of error52.issues) {
13965
13965
  if (issue2.code === "invalid_union" && issue2.errors.length) {
13966
- issue2.errors.map((issues) => processError({ issues }, [...path6, ...issue2.path]));
13966
+ issue2.errors.map((issues) => processError({ issues }, [...path7, ...issue2.path]));
13967
13967
  } else if (issue2.code === "invalid_key") {
13968
- processError({ issues: issue2.issues }, [...path6, ...issue2.path]);
13968
+ processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
13969
13969
  } else if (issue2.code === "invalid_element") {
13970
- processError({ issues: issue2.issues }, [...path6, ...issue2.path]);
13970
+ processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
13971
13971
  } else {
13972
- const fullpath = [...path6, ...issue2.path];
13972
+ const fullpath = [...path7, ...issue2.path];
13973
13973
  if (fullpath.length === 0) {
13974
13974
  result.errors.push(mapper(issue2));
13975
13975
  continue;
@@ -14001,8 +14001,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
14001
14001
  }
14002
14002
  function toDotPath(_path) {
14003
14003
  const segs = [];
14004
- const path6 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
14005
- for (const seg of path6) {
14004
+ const path7 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
14005
+ for (const seg of path7) {
14006
14006
  if (typeof seg === "number")
14007
14007
  segs.push(`[${seg}]`);
14008
14008
  else if (typeof seg === "symbol")
@@ -26694,13 +26694,13 @@ function resolveRef(ref, ctx) {
26694
26694
  if (!ref.startsWith("#")) {
26695
26695
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
26696
26696
  }
26697
- const path6 = ref.slice(1).split("/").filter(Boolean);
26698
- if (path6.length === 0) {
26697
+ const path7 = ref.slice(1).split("/").filter(Boolean);
26698
+ if (path7.length === 0) {
26699
26699
  return ctx.rootSchema;
26700
26700
  }
26701
26701
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
26702
- if (path6[0] === defsKey) {
26703
- const key = path6[1];
26702
+ if (path7[0] === defsKey) {
26703
+ const key = path7[1];
26704
26704
  if (!key || !ctx.defs[key]) {
26705
26705
  throw new Error(`Reference not found: ${ref}`);
26706
26706
  }
@@ -27178,6 +27178,20 @@ var harnessDisplaySetSchema = external_exports.strictObject({
27178
27178
  initializeOnly: external_exports.boolean().optional()
27179
27179
  });
27180
27180
 
27181
+ // ../../shared-contracts/dist/ids.js
27182
+ var opaqueIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
27183
+ message: "Identifier must not be empty or whitespace"
27184
+ });
27185
+ var harnessIdSchema = opaqueIdSchema.brand();
27186
+ var hostThreadIdSchema = opaqueIdSchema.brand();
27187
+ var hostTurnIdSchema = opaqueIdSchema.brand();
27188
+ var hostItemIdSchema = opaqueIdSchema.brand();
27189
+ var hostInteractionIdSchema = opaqueIdSchema.brand();
27190
+
27191
+ // ../../shared-contracts/dist/thread-prewarm.js
27192
+ var threadPrewarmDiscardParamsSchema = external_exports.object({ threadId: hostThreadIdSchema });
27193
+ var threadPrewarmDiscardResultSchema = external_exports.object({ discarded: external_exports.boolean() });
27194
+
27181
27195
  // ../../shared-contracts/dist/console.js
27182
27196
  var consoleAnnouncementSchema = external_exports.strictObject({
27183
27197
  title: external_exports.string().trim().min(1).max(200),
@@ -27190,10 +27204,14 @@ var consoleOpenResultSchema = external_exports.strictObject({
27190
27204
  url: external_exports.string().max(2048).regex(/^http:\/\/(?:127\.0\.0\.1|localhost):\d{1,5}\/(?:\?.*)?$/u)
27191
27205
  });
27192
27206
  var CONSOLE_HOST_METHODS = Object.freeze([
27207
+ "codexhost/console/remote-connections",
27208
+ "codexhost/runtime/status",
27209
+ "codexhost/remote/ssh-setup",
27193
27210
  "codexhost/harness/plugins/list",
27194
27211
  "codexhost/harness/display-settings/get",
27195
27212
  "codexhost/harness/display-settings/set",
27196
27213
  "codexhost/harness/inspect",
27214
+ "codexhost/harness/installation",
27197
27215
  "codexhost/harness/launch-settings/get",
27198
27216
  "codexhost/harness/launch-settings/set",
27199
27217
  "codexhost/harness/web-ui/open",
@@ -27255,16 +27273,6 @@ var loadedSessionsSchema = external_exports.array(external_exports.strictObject(
27255
27273
  inactiveMs: external_exports.number().nonnegative()
27256
27274
  }));
27257
27275
 
27258
- // ../../shared-contracts/dist/ids.js
27259
- var opaqueIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
27260
- message: "Identifier must not be empty or whitespace"
27261
- });
27262
- var harnessIdSchema = opaqueIdSchema.brand();
27263
- var hostThreadIdSchema = opaqueIdSchema.brand();
27264
- var hostTurnIdSchema = opaqueIdSchema.brand();
27265
- var hostItemIdSchema = opaqueIdSchema.brand();
27266
- var hostInteractionIdSchema = opaqueIdSchema.brand();
27267
-
27268
27276
  // ../../shared-contracts/dist/manual-compaction.js
27269
27277
  var threadManualCompactionStartedSchema = external_exports.strictObject({
27270
27278
  threadId: hostThreadIdSchema,
@@ -27840,14 +27848,17 @@ var harnessLaunchSettingsSchema = external_exports.object({
27840
27848
  // ../../shared-contracts/dist/harness-installation.js
27841
27849
  var harnessInstallationParamsSchema = external_exports.object({
27842
27850
  harnessId: harnessIdSchema,
27843
- action: external_exports.enum(["check", "update"])
27851
+ action: external_exports.enum(["check", "update", "install"])
27844
27852
  }).strict();
27845
27853
  var harnessInstallationStateSchema = external_exports.object({
27846
27854
  currentVersion: external_exports.string().min(1).max(128),
27847
27855
  latestVersion: external_exports.string().min(1).max(128),
27848
27856
  updateAvailable: external_exports.boolean(),
27849
27857
  canUpdate: external_exports.boolean(),
27850
- message: external_exports.string().max(2048).optional()
27858
+ // Adapter-owned diagnostic text; UI uses messageCode rather than displaying it verbatim.
27859
+ message: external_exports.string().max(2048).optional(),
27860
+ messageCode: external_exports.string().min(1).max(128).optional(),
27861
+ latestVersionKind: external_exports.enum(["unknown", "tracking-branch"]).optional()
27851
27862
  }).strict();
27852
27863
 
27853
27864
  // ../../shared-contracts/dist/codex-accounts.js
@@ -28149,6 +28160,80 @@ var updateStatusResultSchema = external_exports.strictObject({
28149
28160
  status: updateStatusSchema.nullable()
28150
28161
  });
28151
28162
 
28163
+ // ../../shared-contracts/dist/remote-runtime.js
28164
+ var remoteUpdatePhaseSchema = external_exports.enum([
28165
+ "idle",
28166
+ "installing",
28167
+ "restarting",
28168
+ "succeeded",
28169
+ "failed"
28170
+ ]);
28171
+ var runtimeStatusSchema = external_exports.object({
28172
+ runningVersion: external_exports.string().nullable(),
28173
+ installedVersion: external_exports.string().nullable(),
28174
+ restartRequired: external_exports.boolean(),
28175
+ remote: external_exports.boolean(),
28176
+ updateSupported: external_exports.boolean(),
28177
+ update: external_exports.object({
28178
+ phase: remoteUpdatePhaseSchema,
28179
+ targetVersion: external_exports.string().nullable(),
28180
+ error: external_exports.string().nullable()
28181
+ })
28182
+ });
28183
+ var remoteUpdateParamsSchema = external_exports.object({
28184
+ version: external_exports.string().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u)
28185
+ }).strict();
28186
+ var remoteSshSetupParamsSchema = external_exports.object({
28187
+ hostname: external_exports.string().min(1).max(1024).refine((value) => !value.startsWith("-") && !/\s/u.test(value)),
28188
+ port: external_exports.number().int().min(1).max(65535).nullable(),
28189
+ identity: external_exports.string().max(4096).nullable(),
28190
+ action: external_exports.enum(["inspect", "install", "update", "repair", "uninstall"]),
28191
+ uninstallPackage: external_exports.boolean().optional(),
28192
+ version: external_exports.string().regex(/^\d+\.\d+\.\d+$/u).nullable()
28193
+ }).strict();
28194
+ var remoteSshSetupResultSchema = external_exports.object({ state: external_exports.enum(["installed", "not-installed"]) }).strict();
28195
+
28196
+ // ../../shared-contracts/dist/remote-connections.js
28197
+ var hostId = external_exports.string().min(1).max(1024);
28198
+ var codexSshConnectionSchema = external_exports.object({
28199
+ hostId,
28200
+ displayName: external_exports.string().min(1).max(1024),
28201
+ source: external_exports.enum(["codex-managed", "discovered"]),
28202
+ sshAlias: external_exports.string().max(1024).nullable(),
28203
+ sshHost: external_exports.string().min(1).max(1024),
28204
+ sshPort: external_exports.number().int().min(1).max(65535).nullable(),
28205
+ identity: external_exports.string().max(4096).nullable(),
28206
+ autoConnect: external_exports.boolean(),
28207
+ connectionAnalyticsId: external_exports.string().max(1024).optional()
28208
+ });
28209
+ var codexSshDraftSchema = external_exports.strictObject({
28210
+ displayName: external_exports.string().min(1).max(1024),
28211
+ hostname: external_exports.string().min(1).max(1024),
28212
+ sshPort: external_exports.number().int().min(1).max(65535).nullable(),
28213
+ identity: external_exports.string().max(4096).nullable()
28214
+ });
28215
+ var remoteConnectionsRequestSchema = external_exports.discriminatedUnion("action", [
28216
+ external_exports.strictObject({ action: external_exports.literal("list") }),
28217
+ external_exports.strictObject({
28218
+ action: external_exports.literal("save"),
28219
+ draft: codexSshDraftSchema,
28220
+ previous: codexSshConnectionSchema.nullable()
28221
+ }),
28222
+ external_exports.strictObject({ action: external_exports.literal("remove"), previous: codexSshConnectionSchema }),
28223
+ external_exports.strictObject({ action: external_exports.literal("connect"), hostId, enabled: external_exports.boolean() }),
28224
+ external_exports.strictObject({ action: external_exports.literal("state"), hostId }),
28225
+ external_exports.strictObject({ action: external_exports.literal("runtime"), hostId }),
28226
+ external_exports.strictObject({
28227
+ action: external_exports.literal("update"),
28228
+ hostId: hostId.refine((id) => id !== "local"),
28229
+ version: remoteUpdateParamsSchema.shape.version
28230
+ })
28231
+ ]);
28232
+ var remoteConnectionsReplySchema = external_exports.union([
28233
+ external_exports.strictObject({ result: jsonValueSchema }),
28234
+ external_exports.strictObject({ error: external_exports.strictObject({ code: external_exports.number().int(), message: external_exports.string() }) })
28235
+ ]);
28236
+
28152
28237
  // ../../shared-contracts/dist/index.js
28153
28238
  var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
28154
28239
 
@@ -28488,6 +28573,75 @@ function createInstallationManager(options) {
28488
28573
  return updating;
28489
28574
  };
28490
28575
  }
28576
+ async function fetchInstallationText(url2) {
28577
+ const request = async () => {
28578
+ const response = await fetch(url2, { signal: AbortSignal.timeout(15e3) });
28579
+ if (!response.ok)
28580
+ throw new Error("Could not check the latest Harness version");
28581
+ return response.text();
28582
+ };
28583
+ try {
28584
+ return await request();
28585
+ } catch (error51) {
28586
+ if (error51 instanceof DOMException && (error51.name === "AbortError" || error51.name === "TimeoutError"))
28587
+ throw error51;
28588
+ return request();
28589
+ }
28590
+ }
28591
+
28592
+ // ../../harness-discovery/dist/installer.js
28593
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
28594
+ import { tmpdir } from "node:os";
28595
+ import { join } from "node:path";
28596
+ function createHarnessInstaller(environment, source) {
28597
+ return async () => {
28598
+ if (!["darwin", "linux", "win32"].includes(process.platform))
28599
+ throw new Error("Unsupported installation platform");
28600
+ const env = withNodeRuntimeOnPath(environment);
28601
+ if ("npm" in source) {
28602
+ const npm = resolveHarnessExecutable({
28603
+ id: "npm",
28604
+ command: "npm",
28605
+ installRoots: {
28606
+ posix: [
28607
+ "~/.npm-global/bin",
28608
+ "~/.local/bin",
28609
+ VERSION_MANAGER_ROOTS,
28610
+ "/opt/homebrew/bin",
28611
+ "/usr/local/bin",
28612
+ "/usr/bin"
28613
+ ],
28614
+ windows: [
28615
+ "${APPDATA}/npm",
28616
+ VERSION_MANAGER_ROOTS,
28617
+ "${ProgramFiles}/nodejs",
28618
+ "${LOCALAPPDATA}/Programs/nodejs"
28619
+ ]
28620
+ }
28621
+ }, { environment: env });
28622
+ if (!npm)
28623
+ throw new Error("Install Node.js and npm first");
28624
+ await runInstallationCommand(npm.executable, ["install", "--global", source.npm], {
28625
+ ...env,
28626
+ ...source.allowScripts ? { npm_config_allow_scripts: source.allowScripts } : {}
28627
+ }, 6e5);
28628
+ return;
28629
+ }
28630
+ const windows = process.platform === "win32";
28631
+ const url2 = windows ? source.windows : source.posix;
28632
+ if (new URL(url2).protocol !== "https:")
28633
+ throw new Error("Installer requires HTTPS");
28634
+ const script = await fetchInstallationText(url2);
28635
+ const directory = await mkdtemp(join(tmpdir(), "codexhost-installer-"));
28636
+ try {
28637
+ const file2 = join(directory, windows ? "install.ps1" : "install.sh");
28638
+ await writeFile(file2, script, { mode: 384 });
28639
+ await runInstallationCommand(windows ? "powershell.exe" : source.shell ?? "bash", windows ? ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", file2] : [file2], env, 6e5);
28640
+ } finally {
28641
+ await rm(directory, { recursive: true, force: true });
28642
+ }
28643
+ };
28644
+ }
28491
28645
 
28492
28646
  // ../qoder/dist/qoder-command.js
28493
28647
  var QoderExecutableError = class extends Error {
@@ -28745,6 +28899,26 @@ function mapQoderException(error51) {
28745
28899
  };
28746
28900
  }
28747
28901
 
28902
+ // ../qoder/dist/qoder-login-check.js
28903
+ import { execFile as execFile2 } from "node:child_process";
28904
+ function qoderLoginRequired(text) {
28905
+ return /\bnot logged in\b|\bauthentication (?:required|expired)\b/i.test(text);
28906
+ }
28907
+ function checkQoderLogin(executable, environment, cwd) {
28908
+ return new Promise((resolve) => {
28909
+ execFile2(executable, ["--list-models"], {
28910
+ env: environment,
28911
+ cwd,
28912
+ timeout: 1e4,
28913
+ maxBuffer: 64 * 1024,
28914
+ windowsHide: true
28915
+ }, (error51, stdout, stderr) => {
28916
+ resolve(Boolean(error51 && !error51.killed && qoderLoginRequired(`${stdout}
28917
+ ${stderr}`)));
28918
+ });
28919
+ });
28920
+ }
28921
+
28748
28922
  // ../../harness-adapter/dist/approval.js
28749
28923
  function invalidRequest(message) {
28750
28924
  return { code: "invalidRequest", message, retryable: false };
@@ -30096,8 +30270,8 @@ function getErrorMap2() {
30096
30270
 
30097
30271
  // ../../../node_modules/zod/v3/helpers/parseUtil.js
30098
30272
  var makeIssue = (params) => {
30099
- const { data, path: path6, errorMaps, issueData } = params;
30100
- const fullPath = [...path6, ...issueData.path || []];
30273
+ const { data, path: path7, errorMaps, issueData } = params;
30274
+ const fullPath = [...path7, ...issueData.path || []];
30101
30275
  const fullIssue = {
30102
30276
  ...issueData,
30103
30277
  path: fullPath
@@ -30212,11 +30386,11 @@ var errorUtil;
30212
30386
 
30213
30387
  // ../../../node_modules/zod/v3/types.js
30214
30388
  var ParseInputLazyPath = class {
30215
- constructor(parent, value, path6, key) {
30389
+ constructor(parent, value, path7, key) {
30216
30390
  this._cachedPath = [];
30217
30391
  this.parent = parent;
30218
30392
  this.data = value;
30219
- this._path = path6;
30393
+ this._path = path7;
30220
30394
  this._key = key;
30221
30395
  }
30222
30396
  get path() {
@@ -33743,11 +33917,11 @@ function normalizeObjectSchema(schema) {
33743
33917
  }
33744
33918
  return void 0;
33745
33919
  }
33746
- function getDotPath(path6) {
33747
- if (path6.length === 0) {
33920
+ function getDotPath(path7) {
33921
+ if (path7.length === 0) {
33748
33922
  return "object root";
33749
33923
  }
33750
- return path6.reduce((acc, seg, index) => {
33924
+ return path7.reduce((acc, seg, index) => {
33751
33925
  if (index === 0) {
33752
33926
  return String(seg);
33753
33927
  }
@@ -52318,12 +52492,171 @@ var QoderSession = class {
52318
52492
  }
52319
52493
  };
52320
52494
 
52495
+ // ../qoder/dist/qoder-session-import.js
52496
+ import { stat } from "node:fs/promises";
52497
+ import path5 from "node:path";
52498
+
52499
+ // ../../harness-adapter/dist/session-import.js
52500
+ var STORAGE_ACCESS_ERRORS = /* @__PURE__ */ new Set(["EACCES", "EPERM", "EIO", "EMFILE", "ENFILE"]);
52501
+ function isStorageAccessError(error51) {
52502
+ return typeof error51 === "object" && error51 !== null && "code" in error51 && typeof error51.code === "string" && STORAGE_ACCESS_ERRORS.has(error51.code);
52503
+ }
52504
+ function sessionImportTitle(value, maxLength = HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH) {
52505
+ if (typeof value !== "string")
52506
+ return null;
52507
+ const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
52508
+ if (!normalized)
52509
+ return null;
52510
+ if (normalized.length <= maxLength)
52511
+ return normalized;
52512
+ const characters = [...normalized];
52513
+ if (characters.length <= maxLength)
52514
+ return normalized;
52515
+ return `${characters.slice(0, maxLength - 1).join("").trimEnd()}…`;
52516
+ }
52517
+ function sessionImportCandidate(input) {
52518
+ const time3 = typeof input.updatedAt === "number" ? input.updatedAt : typeof input.updatedAt === "string" ? Date.parse(input.updatedAt) : Number.NaN;
52519
+ const parsed = harnessSessionImportCandidateSchema.safeParse({
52520
+ nativeSessionId: input.nativeSessionId,
52521
+ cwd: input.cwd,
52522
+ title: typeof input.title === "string" && input.title.trim().length > 0 ? input.title : null,
52523
+ updatedAt: Math.floor(time3),
52524
+ // Unknown must stay unknown; only an explicit boolean is a native statement.
52525
+ running: typeof input.running === "boolean" ? input.running : null
52526
+ });
52527
+ return parsed.success ? parsed.data : null;
52528
+ }
52529
+ var SessionImportScope = class {
52530
+ #abort = new AbortController();
52531
+ #options;
52532
+ #pending = /* @__PURE__ */ new Set();
52533
+ constructor(options) {
52534
+ this.#options = options;
52535
+ }
52536
+ #closed() {
52537
+ return {
52538
+ ok: false,
52539
+ error: { code: "invalidState", message: this.#options.closedMessage, retryable: false }
52540
+ };
52541
+ }
52542
+ read(operation) {
52543
+ const signal = this.#abort.signal;
52544
+ if (signal.aborted)
52545
+ return Promise.resolve(this.#closed());
52546
+ let started;
52547
+ try {
52548
+ started = operation(signal);
52549
+ } catch (error51) {
52550
+ started = Promise.reject(error51 instanceof Error ? error51 : new Error("Session read failed"));
52551
+ }
52552
+ const request = started.then((value) => signal.aborted ? this.#closed() : { ok: true, value }).catch(() => signal.aborted ? this.#closed() : {
52553
+ ok: false,
52554
+ error: {
52555
+ code: "unavailable",
52556
+ message: this.#options.unavailableMessage,
52557
+ retryable: true
52558
+ }
52559
+ }).finally(() => this.#pending.delete(request));
52560
+ this.#pending.add(request);
52561
+ return request;
52562
+ }
52563
+ /** `read` for `resolveCandidate`: a null source is the selected Session having disappeared. */
52564
+ async resolve(operation) {
52565
+ const result = await this.read(operation);
52566
+ if (!result.ok)
52567
+ return result;
52568
+ return result.value ? { ok: true, value: result.value } : {
52569
+ ok: false,
52570
+ error: {
52571
+ code: "sessionNotFound",
52572
+ message: this.#options.notFoundMessage,
52573
+ retryable: false
52574
+ }
52575
+ };
52576
+ }
52577
+ /** Idempotent. Resolves after every started read has settled. */
52578
+ async close() {
52579
+ this.#abort.abort();
52580
+ await Promise.allSettled(this.#pending);
52581
+ }
52582
+ };
52583
+
52584
+ // ../qoder/dist/qoder-session-import.js
52585
+ var QoderSessionImport = class {
52586
+ #dependencies;
52587
+ #scope;
52588
+ constructor(dependencies) {
52589
+ this.#dependencies = dependencies;
52590
+ const name = dependencies.displayName;
52591
+ this.#scope = new SessionImportScope({
52592
+ closedMessage: `${name} Session import is closed`,
52593
+ unavailableMessage: `${name} sessions could not be read; check storage access and retry`,
52594
+ notFoundMessage: `${name} Session is no longer importable`
52595
+ });
52596
+ }
52597
+ listCandidates() {
52598
+ return this.#scope.read(async (signal) => {
52599
+ const candidates = /* @__PURE__ */ new Map();
52600
+ for (const info of await this.#dependencies.listSessions()) {
52601
+ signal.throwIfAborted();
52602
+ const candidate = await this.#candidate(info);
52603
+ if (candidate && !candidates.has(candidate.nativeSessionId))
52604
+ candidates.set(candidate.nativeSessionId, candidate);
52605
+ }
52606
+ return [...candidates.values()];
52607
+ });
52608
+ }
52609
+ resolveCandidate(nativeSessionId) {
52610
+ return this.#scope.resolve(async (signal) => {
52611
+ const info = await this.#dependencies.getSessionInfo(nativeSessionId);
52612
+ signal.throwIfAborted();
52613
+ if (info?.sessionId !== nativeSessionId)
52614
+ return null;
52615
+ const candidate = await this.#candidate(info);
52616
+ if (!candidate)
52617
+ return null;
52618
+ return {
52619
+ candidate,
52620
+ nativeRef: nativeSessionRefSchema.parse({
52621
+ harnessId: this.#dependencies.harnessId,
52622
+ nativeSessionId,
52623
+ formatVersion: 1
52624
+ })
52625
+ };
52626
+ });
52627
+ }
52628
+ close() {
52629
+ return this.#scope.close();
52630
+ }
52631
+ async #candidate(info) {
52632
+ if (typeof info.cwd !== "string" || !path5.isAbsolute(info.cwd))
52633
+ return null;
52634
+ const cwd = path5.resolve(info.cwd);
52635
+ try {
52636
+ if (!(await stat(cwd)).isDirectory())
52637
+ return null;
52638
+ } catch (error51) {
52639
+ if (isStorageAccessError(error51))
52640
+ throw error51;
52641
+ return null;
52642
+ }
52643
+ return sessionImportCandidate({
52644
+ nativeSessionId: info.sessionId,
52645
+ cwd,
52646
+ title: sessionImportTitle(info.customTitle) ?? sessionImportTitle(info.summary) ?? sessionImportTitle(info.firstPrompt),
52647
+ updatedAt: info.lastModified
52648
+ // The SDK exposes no cross-process activity marker: idleness cannot be established.
52649
+ });
52650
+ }
52651
+ };
52652
+
52321
52653
  // ../qoder/dist/qoder-adapter.js
52322
52654
  var QoderAdapter = class {
52323
52655
  harnessId;
52324
52656
  #variant;
52325
52657
  commandCatalog = QODER_FALLBACK_COMMAND_CATALOG;
52326
52658
  liveCommandCatalog = true;
52659
+ sessionImport;
52327
52660
  #commandOverride;
52328
52661
  #environment;
52329
52662
  #platform;
@@ -52347,6 +52680,12 @@ var QoderAdapter = class {
52347
52680
  this.#forkSession = options.forkSession ?? runtime.sdk.forkSession;
52348
52681
  this.#getSessionMessages = options.getSessionMessages ?? runtime.sdk.getSessionMessages;
52349
52682
  this.#getSessionInfo = options.getSessionInfo ?? runtime.sdk.getSessionInfo;
52683
+ this.sessionImport = new QoderSessionImport({
52684
+ harnessId: this.harnessId,
52685
+ displayName: this.#variant === "cn" ? "Qoder CN" : "Qoder",
52686
+ listSessions: options.listSessions ?? (() => runtime.sdk.listSessions()),
52687
+ getSessionInfo: this.#getSessionInfo
52688
+ });
52350
52689
  this.#getAvailableModels = options.getAvailableModels;
52351
52690
  this.#resolveExecutable = options.resolveExecutable ?? ((input, dependencies) => resolveQoderExecutable({ ...input, variant: this.#variant }, dependencies));
52352
52691
  }
@@ -52411,11 +52750,15 @@ var QoderAdapter = class {
52411
52750
  } catch {
52412
52751
  }
52413
52752
  } else {
52753
+ let stderr = "";
52414
52754
  try {
52415
52755
  const probeQuery = this.#queryFactory({
52416
52756
  prompt: "",
52417
52757
  options: {
52418
52758
  cwd: input?.cwd ?? process.cwd(),
52759
+ stderr: (chunk) => {
52760
+ stderr = (stderr + chunk).slice(-8192);
52761
+ },
52419
52762
  pathToQoderCLIExecutable: executable,
52420
52763
  ...this.#environment ? { env: this.#environment } : {},
52421
52764
  auth: qoderAuthForEnvironment(this.#variant, this.#environment)
@@ -52432,9 +52775,14 @@ var QoderAdapter = class {
52432
52775
  }
52433
52776
  }
52434
52777
  } catch (error51) {
52778
+ 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
52779
  const result2 = {
52436
52780
  status: "unavailable",
52437
- error: mapQoderException(error51)
52781
+ error: needsLogin ? {
52782
+ code: "authenticationRequired",
52783
+ message: `Please run ${this.#variant === "cn" ? "qoderclicn" : "qodercli"} login to authenticate.`,
52784
+ retryable: false
52785
+ } : mapQoderException(error51)
52438
52786
  };
52439
52787
  return result2;
52440
52788
  }
@@ -52556,7 +52904,7 @@ var QoderAdapter = class {
52556
52904
  sourceInfo = await this.#getSessionInfo(sourceRef.data.nativeSessionId, { dir: input.cwd });
52557
52905
  } catch {
52558
52906
  }
52559
- if (sourceInfo?.cwd && path5.resolve(sourceInfo.cwd) !== path5.resolve(input.cwd)) {
52907
+ if (sourceInfo?.cwd && path6.resolve(sourceInfo.cwd) !== path6.resolve(input.cwd)) {
52560
52908
  return {
52561
52909
  ok: false,
52562
52910
  error: {
@@ -52706,7 +53054,7 @@ var QoderAdapter = class {
52706
53054
  this.#sessions.clear();
52707
53055
  this.#inspections.clear();
52708
53056
  this.#inFlightInspections.clear();
52709
- await Promise.all(sessions.map((s) => s.close()));
53057
+ await Promise.all([this.sessionImport.close(), ...sessions.map((s) => s.close())]);
52710
53058
  }
52711
53059
  };
52712
53060
 
@@ -52722,6 +53070,7 @@ function createQoderInstallation(environment, command, variant = "global") {
52722
53070
  latestVersion: "Unknown",
52723
53071
  updateAvailable: false,
52724
53072
  canUpdate: false,
53073
+ messageCode: "qoder-check-unavailable",
52725
53074
  message: "This Qoder China release does not expose a non-installing update check. Use its original installer."
52726
53075
  };
52727
53076
  const output = await run(["update", "--check"]);
@@ -52757,7 +53106,13 @@ function createHarnessAdapter(context, variant = "global") {
52757
53106
  variant,
52758
53107
  environment,
52759
53108
  platform: context.platform
52760
- }), { installation: createQoderInstallation(environment, command, variant) });
53109
+ }), {
53110
+ installation: createQoderInstallation(environment, command, variant),
53111
+ install: createHarnessInstaller(environment, variant === "cn" ? {
53112
+ posix: "https://static.qoder.com.cn/qoder-cli-cn/install.sh",
53113
+ windows: "https://static.qoder.com.cn/qoder-cli-cn/install.ps1"
53114
+ } : { posix: "https://qoder.com/install", windows: "https://qoder.com/install.ps1" })
53115
+ });
52761
53116
  }
52762
53117
 
52763
53118
  // dist/plugin.js