@liberseek/boft-cli-win32-arm64 0.7.5 → 0.7.6

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.
@@ -8,7 +8,7 @@ var __export = (target, all) => {
8
8
  // dist/opencode-adapter.js
9
9
  import { randomUUID } from "node:crypto";
10
10
  import fs4 from "node:fs";
11
- import path6 from "node:path";
11
+ import path8 from "node:path";
12
12
 
13
13
  // ../../../node_modules/zod/v4/classic/external.js
14
14
  var external_exports = {};
@@ -776,10 +776,10 @@ function mergeDefs(...defs) {
776
776
  function cloneDef(schema) {
777
777
  return mergeDefs(schema._zod.def);
778
778
  }
779
- function getElementAtPath(obj, path9) {
780
- if (!path9)
779
+ function getElementAtPath(obj, path12) {
780
+ if (!path12)
781
781
  return obj;
782
- return path9.reduce((acc, key) => acc?.[key], obj);
782
+ return path12.reduce((acc, key) => acc?.[key], obj);
783
783
  }
784
784
  function promiseAllObject(promisesObj) {
785
785
  const keys = Object.keys(promisesObj);
@@ -1188,11 +1188,11 @@ function explicitlyAborted(x, startIndex = 0) {
1188
1188
  }
1189
1189
  return false;
1190
1190
  }
1191
- function prefixIssues(path9, issues) {
1191
+ function prefixIssues(path12, issues) {
1192
1192
  return issues.map((iss) => {
1193
1193
  var _a3;
1194
1194
  (_a3 = iss).path ?? (_a3.path = []);
1195
- iss.path.unshift(path9);
1195
+ iss.path.unshift(path12);
1196
1196
  return iss;
1197
1197
  });
1198
1198
  }
@@ -1339,16 +1339,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
1339
1339
  }
1340
1340
  function formatError(error51, mapper = (issue2) => issue2.message) {
1341
1341
  const fieldErrors = { _errors: [] };
1342
- const processError = (error52, path9 = []) => {
1342
+ const processError = (error52, path12 = []) => {
1343
1343
  for (const issue2 of error52.issues) {
1344
1344
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1345
- issue2.errors.map((issues) => processError({ issues }, [...path9, ...issue2.path]));
1345
+ issue2.errors.map((issues) => processError({ issues }, [...path12, ...issue2.path]));
1346
1346
  } else if (issue2.code === "invalid_key") {
1347
- processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
1347
+ processError({ issues: issue2.issues }, [...path12, ...issue2.path]);
1348
1348
  } else if (issue2.code === "invalid_element") {
1349
- processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
1349
+ processError({ issues: issue2.issues }, [...path12, ...issue2.path]);
1350
1350
  } else {
1351
- const fullpath = [...path9, ...issue2.path];
1351
+ const fullpath = [...path12, ...issue2.path];
1352
1352
  if (fullpath.length === 0) {
1353
1353
  fieldErrors._errors.push(mapper(issue2));
1354
1354
  } else {
@@ -1375,17 +1375,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
1375
1375
  }
1376
1376
  function treeifyError(error51, mapper = (issue2) => issue2.message) {
1377
1377
  const result = { errors: [] };
1378
- const processError = (error52, path9 = []) => {
1378
+ const processError = (error52, path12 = []) => {
1379
1379
  var _a3, _b;
1380
1380
  for (const issue2 of error52.issues) {
1381
1381
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1382
- issue2.errors.map((issues) => processError({ issues }, [...path9, ...issue2.path]));
1382
+ issue2.errors.map((issues) => processError({ issues }, [...path12, ...issue2.path]));
1383
1383
  } else if (issue2.code === "invalid_key") {
1384
- processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
1384
+ processError({ issues: issue2.issues }, [...path12, ...issue2.path]);
1385
1385
  } else if (issue2.code === "invalid_element") {
1386
- processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
1386
+ processError({ issues: issue2.issues }, [...path12, ...issue2.path]);
1387
1387
  } else {
1388
- const fullpath = [...path9, ...issue2.path];
1388
+ const fullpath = [...path12, ...issue2.path];
1389
1389
  if (fullpath.length === 0) {
1390
1390
  result.errors.push(mapper(issue2));
1391
1391
  continue;
@@ -1417,8 +1417,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
1417
1417
  }
1418
1418
  function toDotPath(_path) {
1419
1419
  const segs = [];
1420
- const path9 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1421
- for (const seg of path9) {
1420
+ const path12 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1421
+ for (const seg of path12) {
1422
1422
  if (typeof seg === "number")
1423
1423
  segs.push(`[${seg}]`);
1424
1424
  else if (typeof seg === "symbol")
@@ -14110,13 +14110,13 @@ function resolveRef(ref, ctx) {
14110
14110
  if (!ref.startsWith("#")) {
14111
14111
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
14112
14112
  }
14113
- const path9 = ref.slice(1).split("/").filter(Boolean);
14114
- if (path9.length === 0) {
14113
+ const path12 = ref.slice(1).split("/").filter(Boolean);
14114
+ if (path12.length === 0) {
14115
14115
  return ctx.rootSchema;
14116
14116
  }
14117
14117
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
14118
- if (path9[0] === defsKey) {
14119
- const key = path9[1];
14118
+ if (path12[0] === defsKey) {
14119
+ const key = path12[1];
14120
14120
  if (!key || !ctx.defs[key]) {
14121
14121
  throw new Error(`Reference not found: ${ref}`);
14122
14122
  }
@@ -14579,6 +14579,55 @@ var credentialImportsParamsSchema = external_exports.object({
14579
14579
  request: credentialImportsRequestSchema
14580
14580
  }).strict();
14581
14581
 
14582
+ // ../../shared-contracts/dist/harness-display-settings.js
14583
+ var harnessDisplayEntriesSchema = external_exports.array(external_exports.strictObject({
14584
+ agent: external_exports.string().min(1).max(128),
14585
+ section: external_exports.enum(["main", "more", "auto"])
14586
+ })).max(256).refine((entries) => new Set(entries.map((entry) => entry.agent)).size === entries.length, "Duplicate Harness IDs");
14587
+ var harnessDisplaySettingsSchema = external_exports.strictObject({
14588
+ entries: harnessDisplayEntriesSchema.nullable()
14589
+ });
14590
+ var harnessDisplayGetSchema = external_exports.strictObject({});
14591
+ var harnessDisplaySetSchema = external_exports.strictObject({
14592
+ entries: harnessDisplayEntriesSchema,
14593
+ /** Import legacy Desktop preferences only if no shared settings exist yet. */
14594
+ initializeOnly: external_exports.boolean().optional()
14595
+ });
14596
+
14597
+ // ../../shared-contracts/dist/console.js
14598
+ var consoleAnnouncementSchema = external_exports.strictObject({
14599
+ title: external_exports.string().trim().min(1).max(200),
14600
+ type: external_exports.enum(["info", "warning", "danger"]),
14601
+ body: external_exports.string().trim().min(1).max(16 * 1024)
14602
+ });
14603
+ var consoleOpenParamsSchema = external_exports.strictObject({});
14604
+ var consoleOpenResultSchema = external_exports.strictObject({
14605
+ /** The console address. */
14606
+ url: external_exports.string().max(2048).regex(/^http:\/\/(?:127\.0\.0\.1|localhost):\d{1,5}\/(?:\?.*)?$/u)
14607
+ });
14608
+ var CONSOLE_HOST_METHODS = Object.freeze([
14609
+ "codexhost/harness/plugins/list",
14610
+ "codexhost/harness/display-settings/get",
14611
+ "codexhost/harness/display-settings/set",
14612
+ "codexhost/harness/inspect",
14613
+ "codexhost/harness/launch-settings/get",
14614
+ "codexhost/harness/launch-settings/set",
14615
+ "codexhost/harness/web-ui/open",
14616
+ "codexhost/harness/accounts/sources",
14617
+ "codexhost/harness/accounts/list",
14618
+ "codexhost/harness/accounts/inspect",
14619
+ "codexhost/harness/credential-imports",
14620
+ "codexhost/harness/session-import/sources",
14621
+ "codexhost/harness/session-import/list",
14622
+ "codexhost/harness/session-import/import",
14623
+ "codexhost/account/list",
14624
+ "codexhost/account/refresh",
14625
+ "codexhost/account/usage/inspect",
14626
+ "codexhost/update/check",
14627
+ "codexhost/update/start",
14628
+ "codexhost/update/status"
14629
+ ]);
14630
+
14582
14631
  // ../../shared-contracts/dist/version.js
14583
14632
  var WORKSPACE_CONTRACT_VERSION = 1;
14584
14633
 
@@ -14632,6 +14681,12 @@ var hostTurnIdSchema = opaqueIdSchema.brand();
14632
14681
  var hostItemIdSchema = opaqueIdSchema.brand();
14633
14682
  var hostInteractionIdSchema = opaqueIdSchema.brand();
14634
14683
 
14684
+ // ../../shared-contracts/dist/manual-compaction.js
14685
+ var threadManualCompactionStartedSchema = external_exports.strictObject({
14686
+ threadId: hostThreadIdSchema,
14687
+ turnId: hostTurnIdSchema
14688
+ });
14689
+
14635
14690
  // ../../shared-contracts/dist/thread-usage.js
14636
14691
  var nonNegativeSafeIntegerSchema = external_exports.number().int().safe().nonnegative();
14637
14692
  var finiteNonNegativeNumberSchema = external_exports.number().finite().nonnegative();
@@ -14692,6 +14747,10 @@ var threadUsageSnapshotSchema = external_exports.object({
14692
14747
  var usagePercentSchema = external_exports.number().finite().min(0).max(100);
14693
14748
  var accountCreditsProductUsageSchema = external_exports.object({
14694
14749
  product: external_exports.string().min(1),
14750
+ used: external_exports.number().finite().nonnegative().optional(),
14751
+ // Zero is a real empty cap, not an absent field.
14752
+ limit: external_exports.number().finite().nonnegative().optional(),
14753
+ unit: external_exports.string().min(1).max(32).optional(),
14695
14754
  usagePercent: usagePercentSchema,
14696
14755
  resetsAt: external_exports.string().min(1).optional()
14697
14756
  }).strict();
@@ -14701,11 +14760,14 @@ var accountResetCreditsSchema = external_exports.object({
14701
14760
  expiresAt: external_exports.array(external_exports.string().min(1)).min(1).max(32).optional()
14702
14761
  }).strict();
14703
14762
  var accountCreditsSnapshotSchema = external_exports.object({
14763
+ used: external_exports.number().finite().nonnegative().optional(),
14764
+ // Zero is a real empty cap, not an absent field.
14765
+ limit: external_exports.number().finite().nonnegative().optional(),
14766
+ unit: external_exports.string().trim().min(1).max(32).optional(),
14704
14767
  /** Native label when the primary limit is scoped to a model or product group. */
14705
14768
  label: external_exports.string().min(1).optional(),
14706
14769
  usedPercent: usagePercentSchema.optional(),
14707
14770
  remaining: external_exports.number().finite().optional(),
14708
- unit: external_exports.string().trim().min(1).max(32).optional(),
14709
14771
  resetsAt: external_exports.string().min(1).optional(),
14710
14772
  periodType: external_exports.enum(["weekly", "monthly", "five_hour", "seven_day", "unknown"]),
14711
14773
  productUsage: external_exports.array(accountCreditsProductUsageSchema).min(1).optional(),
@@ -14736,12 +14798,27 @@ var threadUsageInspectionSchema = external_exports.object({
14736
14798
  }).strict();
14737
14799
 
14738
14800
  // ../../shared-contracts/dist/harness-accounts.js
14739
- var harnessAccountSnapshotSchema = external_exports.object({
14801
+ var accountBalanceSnapshotSchema = external_exports.object({
14802
+ amount: external_exports.number().finite().nonnegative(),
14803
+ /** ISO 4217 code as reported by the Provider, for example `CNY`. */
14804
+ currency: external_exports.string().trim().min(1).max(8),
14805
+ /** Native label when the Harness exposes several Billing Sources. */
14806
+ label: external_exports.string().trim().min(1).max(128).optional()
14807
+ }).strict();
14808
+ var harnessAccountSnapshotObject = external_exports.object({
14740
14809
  email: external_exports.string().trim().min(1).max(320).optional(),
14741
14810
  label: external_exports.string().trim().min(1).max(256).optional(),
14742
14811
  plan: external_exports.string().trim().min(1).max(128).optional(),
14743
- credits: accountCreditsSnapshotSchema
14812
+ credits: accountCreditsSnapshotSchema.optional(),
14813
+ balance: accountBalanceSnapshotSchema.optional()
14744
14814
  }).strict();
14815
+ function requireReportedQuota(schema) {
14816
+ return schema.refine((value) => {
14817
+ const reported = value;
14818
+ return reported.credits !== void 0 || reported.balance !== void 0;
14819
+ }, { message: "Account must report either credits or a balance" });
14820
+ }
14821
+ var harnessAccountSnapshotSchema = requireReportedQuota(harnessAccountSnapshotObject);
14745
14822
  var harnessAccountIdentityShape = {
14746
14823
  harnessId: harnessIdSchema,
14747
14824
  harnessName: external_exports.string().trim().min(1).max(128)
@@ -14752,11 +14829,13 @@ var harnessAccountSourceListResultSchema = external_exports.object({ sources: ex
14752
14829
  var harnessAccountInspectParamsSchema = external_exports.object({ harnessId: harnessIdSchema, refresh: external_exports.boolean().optional() }).strict();
14753
14830
  var harnessAccountInspectResultSchema = external_exports.object({
14754
14831
  ...harnessAccountIdentityShape,
14755
- account: harnessAccountSnapshotSchema.nullable()
14832
+ account: harnessAccountSnapshotSchema.nullable(),
14833
+ /** Every Billing Source from one Harness; `account` remains the first for older clients. */
14834
+ accounts: external_exports.array(harnessAccountSnapshotSchema).max(8).optional()
14756
14835
  }).strict();
14757
14836
  var harnessAccountListParamsSchema = external_exports.object({ refresh: external_exports.boolean().optional() }).strict();
14758
14837
  var harnessAccountListResultSchema = external_exports.object({
14759
- accounts: external_exports.array(harnessAccountSnapshotSchema.extend(harnessAccountIdentityShape)).max(128)
14838
+ accounts: external_exports.array(requireReportedQuota(harnessAccountSnapshotObject.extend(harnessAccountIdentityShape))).max(128)
14760
14839
  }).strict();
14761
14840
 
14762
14841
  // ../../shared-contracts/dist/json-value.js
@@ -14894,6 +14973,8 @@ var harnessModelSchema = external_exports.object({
14894
14973
  ref: harnessModelRefSchema,
14895
14974
  label: nonBlankTextSchema2.max(HARNESS_MODEL_LABEL_MAX_LENGTH),
14896
14975
  resolvedModelLabel: harnessResolvedModelLabelSchema.optional(),
14976
+ /** Optional opaque selection for this same Model with priority processing enabled. */
14977
+ fastModel: harnessModelRefSchema.optional(),
14897
14978
  supportedThinkingOptionIds: external_exports.array(harnessThinkingOptionIdSchema).optional()
14898
14979
  }).strict();
14899
14980
  var harnessThinkingOptionsSchema = external_exports.array(harnessThinkingOptionSchema).superRefine((options, context) => {
@@ -14926,6 +15007,16 @@ var harnessModelCatalogSchema = external_exports.object({
14926
15007
  });
14927
15008
  }
14928
15009
  refs.add(model.ref.id);
15010
+ if (model.fastModel) {
15011
+ if (refs.has(model.fastModel.id) || catalog.models.some((entry) => entry.ref.id === model.fastModel?.id)) {
15012
+ context.addIssue({
15013
+ code: "custom",
15014
+ message: "Fast Model refs must be distinct and unique",
15015
+ path: ["models", index, "fastModel"]
15016
+ });
15017
+ }
15018
+ refs.add(model.fastModel.id);
15019
+ }
14929
15020
  const supportedThinkingIds = /* @__PURE__ */ new Set();
14930
15021
  for (const [optionIndex, optionId] of (model.supportedThinkingOptionIds ?? []).entries()) {
14931
15022
  if (supportedThinkingIds.has(optionId)) {
@@ -15048,11 +15139,13 @@ var threadThinkingSelectParamsSchema = external_exports.object({
15048
15139
  thinkingOptionId: harnessThinkingOptionIdSchema
15049
15140
  }).strict();
15050
15141
  var threadInspectionParamsSchema = external_exports.object({
15051
- threadId: hostThreadIdSchema
15142
+ threadId: hostThreadIdSchema,
15143
+ includeReferenceCapability: external_exports.boolean().optional()
15052
15144
  }).strict();
15053
15145
  var codexThreadInspectionSchema = external_exports.object({
15054
15146
  owner: external_exports.literal("codex"),
15055
- locked: external_exports.literal(true)
15147
+ locked: external_exports.literal(true),
15148
+ supportsThreadReferences: external_exports.literal(true).optional()
15056
15149
  }).strict();
15057
15150
  var externalThreadInspectionSchema = external_exports.object({
15058
15151
  owner: external_exports.literal("external"),
@@ -15180,10 +15273,31 @@ var harnessLaunchSettingsSchema = external_exports.object({
15180
15273
  restartRequired: external_exports.boolean()
15181
15274
  }).strict();
15182
15275
 
15276
+ // ../../shared-contracts/dist/harness-installation.js
15277
+ var harnessInstallationParamsSchema = external_exports.object({
15278
+ harnessId: harnessIdSchema,
15279
+ action: external_exports.enum(["check", "update"])
15280
+ }).strict();
15281
+ var harnessInstallationStateSchema = external_exports.object({
15282
+ currentVersion: external_exports.string().min(1).max(128),
15283
+ latestVersion: external_exports.string().min(1).max(128),
15284
+ updateAvailable: external_exports.boolean(),
15285
+ canUpdate: external_exports.boolean(),
15286
+ message: external_exports.string().max(2048).optional()
15287
+ }).strict();
15288
+
15183
15289
  // ../../shared-contracts/dist/codex-accounts.js
15184
15290
  var accountIdSchema = external_exports.string().min(1).max(256).regex(/^[A-Za-z0-9._~-]+$/u);
15185
15291
  var nonBlankTextSchema3 = external_exports.string().trim().min(1);
15186
15292
  var codexAccountAuthKindSchema = external_exports.enum(["api", "chatgpt"]);
15293
+ var codexAccountSiteUrlPattern = /^https?:\/\/(?:\[[0-9a-fA-F:]+\]|[^/\s:@?#]+)(?::\d{1,5})?(?:[/?#][^\s]*)?$/u;
15294
+ function isCodexAccountSiteUrl(value) {
15295
+ return value.length > 0 && value.length <= 2048 && codexAccountSiteUrlPattern.test(value);
15296
+ }
15297
+ var externalUrlOpenParamsSchema = external_exports.object({
15298
+ url: external_exports.string().max(2048).refine(isCodexAccountSiteUrl, "External URL must be http(s)")
15299
+ }).strict();
15300
+ var externalUrlOpenResultSchema = external_exports.object({}).strict();
15187
15301
  var codexAccountPlanTypeSchema = external_exports.enum([
15188
15302
  "free",
15189
15303
  "go",
@@ -15209,7 +15323,8 @@ var codexAccountSchema = external_exports.object({
15209
15323
  email: external_exports.string().email().max(320).optional(),
15210
15324
  planType: codexAccountPlanTypeSchema.optional(),
15211
15325
  authKind: codexAccountAuthKindSchema.optional(),
15212
- authIdentity: nonBlankTextSchema3.max(256).optional()
15326
+ authIdentity: nonBlankTextSchema3.max(256).optional(),
15327
+ siteUrl: external_exports.string().refine(isCodexAccountSiteUrl, "Account site URL must be http(s)").optional()
15213
15328
  }).strict();
15214
15329
  var codexAccountPhaseSchema = external_exports.enum(["ready", "unavailable"]);
15215
15330
  var codexAccountListResultSchema = external_exports.object({
@@ -16107,8 +16222,9 @@ var OpenCodeTransportError = class extends Error {
16107
16222
  import { randomBytes } from "node:crypto";
16108
16223
  import { spawn, spawnSync } from "node:child_process";
16109
16224
  import fs2 from "node:fs";
16110
- import { homedir, tmpdir } from "node:os";
16111
- import path4 from "node:path";
16225
+ import { createServer } from "node:net";
16226
+ import { homedir as homedir2, tmpdir } from "node:os";
16227
+ import path6 from "node:path";
16112
16228
 
16113
16229
  // ../../../node_modules/@opencode-ai/sdk/dist/v2/gen/core/serverSentEvents.gen.js
16114
16230
  var createSseClient = ({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url: url2, ...options }) => {
@@ -16334,7 +16450,7 @@ var serializeObjectParam = ({ allowReserved, explode, name, style, value, valueO
16334
16450
 
16335
16451
  // ../../../node_modules/@opencode-ai/sdk/dist/v2/gen/core/utils.gen.js
16336
16452
  var PATH_PARAM_RE = /\{[^{}]+\}/g;
16337
- var defaultPathSerializer = ({ path: path9, url: _url2 }) => {
16453
+ var defaultPathSerializer = ({ path: path12, url: _url2 }) => {
16338
16454
  let url2 = _url2;
16339
16455
  const matches = _url2.match(PATH_PARAM_RE);
16340
16456
  if (matches) {
@@ -16353,7 +16469,7 @@ var defaultPathSerializer = ({ path: path9, url: _url2 }) => {
16353
16469
  name = name.substring(1);
16354
16470
  style = "matrix";
16355
16471
  }
16356
- const value = path9[name];
16472
+ const value = path12[name];
16357
16473
  if (value === void 0 || value === null) {
16358
16474
  continue;
16359
16475
  }
@@ -16384,11 +16500,11 @@ var defaultPathSerializer = ({ path: path9, url: _url2 }) => {
16384
16500
  }
16385
16501
  return url2;
16386
16502
  };
16387
- var getUrl = ({ baseUrl, path: path9, query, querySerializer, url: _url2 }) => {
16503
+ var getUrl = ({ baseUrl, path: path12, query, querySerializer, url: _url2 }) => {
16388
16504
  const pathUrl = _url2.startsWith("/") ? _url2 : `/${_url2}`;
16389
16505
  let url2 = (baseUrl ?? "") + pathUrl;
16390
- if (path9) {
16391
- url2 = defaultPathSerializer({ path: path9, url: url2 });
16506
+ if (path12) {
16507
+ url2 = defaultPathSerializer({ path: path12, url: url2 });
16392
16508
  }
16393
16509
  let search = query ? querySerializer(query) : "";
16394
16510
  if (search.startsWith("?")) {
@@ -21511,7 +21627,7 @@ function createOpencodeClient(config2) {
21511
21627
  }
21512
21628
 
21513
21629
  // dist/command.js
21514
- import path3 from "node:path";
21630
+ import path5 from "node:path";
21515
21631
 
21516
21632
  // ../../harness-discovery/dist/environment.js
21517
21633
  import fs from "node:fs";
@@ -21575,6 +21691,20 @@ function commandInvocation(command, arguments_, environment, platform = process.
21575
21691
  };
21576
21692
  }
21577
21693
 
21694
+ // ../../harness-discovery/dist/node-runtime.js
21695
+ import path3 from "node:path";
21696
+ function withNodeRuntimeOnPath(environment, runtimeExecutable = process.execPath, platform = process.platform) {
21697
+ const pathKey = Object.keys(environment).find((name) => name.toLowerCase() === "path") ?? "PATH";
21698
+ const delimiter = platform === "win32" ? ";" : ":";
21699
+ const runtimeDirectory = path3.dirname(runtimeExecutable);
21700
+ const directories = (environment[pathKey] ?? "").split(delimiter).filter(Boolean);
21701
+ const equal = platform === "win32" ? (value) => value.toLowerCase() : (value) => value;
21702
+ if (!directories.some((directory) => equal(directory) === equal(runtimeDirectory))) {
21703
+ directories.push(runtimeDirectory);
21704
+ }
21705
+ return { ...environment, [pathKey]: directories.join(delimiter) };
21706
+ }
21707
+
21578
21708
  // ../../harness-discovery/dist/resolve.js
21579
21709
  import os from "node:os";
21580
21710
 
@@ -21738,6 +21868,195 @@ function resolveHarnessExecutable(spec, input, dependencies = {}) {
21738
21868
  return void 0;
21739
21869
  }
21740
21870
 
21871
+ // ../../harness-discovery/dist/installation.js
21872
+ import { execFile } from "node:child_process";
21873
+ import { homedir } from "node:os";
21874
+ function runInstallationCommand(command, args, environment, timeout = 3e4) {
21875
+ const env = withNodeRuntimeOnPath(environment);
21876
+ const invocation = /\.[cm]?js$/i.test(command) ? commandInvocation(process.execPath, [command, ...args], env) : commandInvocation(command, args, env);
21877
+ return new Promise((resolve, reject) => {
21878
+ const child = execFile(invocation.command, invocation.arguments, {
21879
+ env,
21880
+ cwd: env.HOME ?? env.USERPROFILE ?? homedir(),
21881
+ encoding: "utf8",
21882
+ timeout,
21883
+ killSignal: "SIGKILL",
21884
+ maxBuffer: 1024 * 1024,
21885
+ windowsHide: true,
21886
+ windowsVerbatimArguments: invocation.windowsVerbatimArguments
21887
+ }, (error51, stdout, stderr) => {
21888
+ if (error51)
21889
+ reject(new Error(error51.killed ? "Harness command timed out" : "Harness command failed; check the native installation and retry"));
21890
+ else
21891
+ resolve((stdout || stderr).trim());
21892
+ });
21893
+ child.stdin?.end();
21894
+ });
21895
+ }
21896
+ function installationVersion(value) {
21897
+ if (typeof value !== "string" || !/^v?\d+(?:\.\d+){1,3}(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(value.trim()))
21898
+ throw new Error("Harness returned an invalid version");
21899
+ return value.trim().replace(/^v/, "");
21900
+ }
21901
+ function versionFromOutput(output) {
21902
+ return installationVersion(output.match(/\b\d+(?:\.\d+){1,3}(?:-[\w.-]+)?(?:\+[\w.-]+)?\b/)?.[0]);
21903
+ }
21904
+ function newerInstallationVersion(current, latest) {
21905
+ const a = installationVersion(current).replace(/\+.*/, "");
21906
+ const b = installationVersion(latest).replace(/\+.*/, "");
21907
+ const coreA = a.replace(/-.*/, "").split(".").map(BigInt);
21908
+ const coreB = b.replace(/-.*/, "").split(".").map(BigInt);
21909
+ for (let i = 0; i < Math.max(coreA.length, coreB.length); i++) {
21910
+ if ((coreA[i] ?? 0n) !== (coreB[i] ?? 0n))
21911
+ return (coreB[i] ?? 0n) > (coreA[i] ?? 0n);
21912
+ }
21913
+ const preA = a.includes("-") ? a.slice(a.indexOf("-") + 1).split(".") : [];
21914
+ const preB = b.includes("-") ? b.slice(b.indexOf("-") + 1).split(".") : [];
21915
+ if (!preA.length || !preB.length)
21916
+ return !!preA.length && !preB.length;
21917
+ for (let i = 0; i < Math.max(preA.length, preB.length); i++) {
21918
+ const x = preA[i];
21919
+ const y = preB[i];
21920
+ if (x === y)
21921
+ continue;
21922
+ if (x === void 0 || y === void 0)
21923
+ return x === void 0;
21924
+ const numericX = /^\d+$/.test(x);
21925
+ const numericY = /^\d+$/.test(y);
21926
+ if (numericX && numericY) {
21927
+ if (BigInt(x) === BigInt(y))
21928
+ continue;
21929
+ return BigInt(y) > BigInt(x);
21930
+ }
21931
+ if (numericX !== numericY)
21932
+ return numericX;
21933
+ return y > x;
21934
+ }
21935
+ return false;
21936
+ }
21937
+ function createInstallationManager(options) {
21938
+ let checking;
21939
+ let updating;
21940
+ const check2 = () => checking ??= options.check().finally(() => {
21941
+ checking = void 0;
21942
+ });
21943
+ return (action) => {
21944
+ if (updating)
21945
+ return updating;
21946
+ if (action === "check")
21947
+ return check2();
21948
+ updating = (async () => {
21949
+ const before = await check2();
21950
+ if (!before.updateAvailable)
21951
+ return before;
21952
+ if (!before.canUpdate)
21953
+ throw new Error(before.message ?? "This installation cannot be updated automatically");
21954
+ await options.update(before);
21955
+ const after = await check2();
21956
+ if (after.currentVersion === before.currentVersion)
21957
+ throw new Error("The Harness version did not change; check the native updater and retry");
21958
+ return after;
21959
+ })().finally(() => {
21960
+ updating = void 0;
21961
+ });
21962
+ return updating;
21963
+ };
21964
+ }
21965
+ async function fetchInstallationText(url2) {
21966
+ const request = async () => {
21967
+ const response = await fetch(url2, { signal: AbortSignal.timeout(15e3) });
21968
+ if (!response.ok)
21969
+ throw new Error("Could not check the latest Harness version");
21970
+ return response.text();
21971
+ };
21972
+ try {
21973
+ return await request();
21974
+ } catch (error51) {
21975
+ if (error51 instanceof DOMException && (error51.name === "AbortError" || error51.name === "TimeoutError"))
21976
+ throw error51;
21977
+ return request();
21978
+ }
21979
+ }
21980
+
21981
+ // ../../harness-discovery/dist/npm-installation.js
21982
+ import { readFile, realpath } from "node:fs/promises";
21983
+ import path4 from "node:path";
21984
+ function referencesNpmBin(shim, name, bin) {
21985
+ if (bin.includes(".."))
21986
+ return false;
21987
+ const target = `node_modules/${name}/${bin.replace(/^\.\//, "")}`.toLowerCase();
21988
+ const text = shim.replaceAll("\\", "/").toLowerCase();
21989
+ return text.includes(`%dp0%/${target}"`) || text.includes(`%~dp0/${target}"`);
21990
+ }
21991
+ async function npmInstallation(command, packages, environment) {
21992
+ let selected = await realpath(command);
21993
+ if (process.platform === "win32" && /\.(cmd|bat)$/i.test(selected)) {
21994
+ const shim = (await readFile(selected, "utf8")).replaceAll("\\", "/");
21995
+ const root = path4.dirname(selected);
21996
+ for (const name of packages) {
21997
+ const directory2 = path4.join(root, "node_modules", ...name.split("/"));
21998
+ const metadata = await readFile(path4.join(directory2, "package.json"), "utf8").then((text) => JSON.parse(text)).catch(() => null);
21999
+ const bins = typeof metadata?.bin === "string" ? [metadata.bin] : Object.values(metadata?.bin ?? {});
22000
+ const bin = bins.find((entry) => referencesNpmBin(shim, name, entry));
22001
+ if (bin) {
22002
+ selected = await realpath(path4.join(directory2, bin));
22003
+ break;
22004
+ }
22005
+ }
22006
+ }
22007
+ let directory = path4.dirname(selected);
22008
+ for (let depth = 0; depth < 8; depth++) {
22009
+ const metadata = await readFile(path4.join(directory, "package.json"), "utf8").then((text) => JSON.parse(text)).catch(() => null);
22010
+ if (metadata?.name && packages.includes(metadata.name)) {
22011
+ const name = metadata.name;
22012
+ const currentVersion = installationVersion(metadata.version);
22013
+ const segments = name.split("/");
22014
+ let modules = directory;
22015
+ for (let index = 0; index < segments.length; index++)
22016
+ modules = path4.dirname(modules);
22017
+ const prefix = process.platform === "win32" ? path4.dirname(modules) : path4.dirname(path4.dirname(modules));
22018
+ const globalRoot = process.platform === "win32" ? path4.join(prefix, "node_modules") : path4.join(prefix, "lib", "node_modules");
22019
+ const env = withNodeRuntimeOnPath(environment);
22020
+ const npm = resolveHarnessExecutable({ id: "npm", command: "npm", installRoots: { posix: [], windows: [] } }, { environment: env });
22021
+ let globalInstall = modules === globalRoot;
22022
+ if (process.platform === "win32") {
22023
+ const project = (await Promise.all(["package.json", "package-lock.json", "npm-shrinkwrap.json"].map((file2) => readFile(path4.join(prefix, file2), "utf8").then(() => true, (error51) => error51.code !== "ENOENT")))).some(Boolean);
22024
+ const bins = typeof metadata.bin === "string" ? { [name.split("/").at(-1) ?? name]: metadata.bin } : metadata.bin ?? {};
22025
+ const launchers = await Promise.all(Object.entries(bins).map(async ([bin, entry]) => {
22026
+ if (path4.basename(bin) !== bin || entry.includes(".."))
22027
+ return false;
22028
+ const target = await realpath(path4.join(directory, entry)).catch(() => "");
22029
+ if (target.toLowerCase() !== selected.toLowerCase())
22030
+ return false;
22031
+ const shim = await readFile(path4.join(prefix, `${bin}.cmd`), "utf8").catch(() => "");
22032
+ return referencesNpmBin(shim, name, entry);
22033
+ }));
22034
+ globalInstall = globalInstall && !project && launchers.some(Boolean);
22035
+ }
22036
+ const canUpdate = globalInstall && !!npm;
22037
+ return {
22038
+ prefix,
22039
+ currentVersion,
22040
+ canUpdate,
22041
+ latest: async () => {
22042
+ const data = JSON.parse(await fetchInstallationText(`https://registry.npmjs.org/${encodeURIComponent(name)}/latest`));
22043
+ return installationVersion(data.version);
22044
+ },
22045
+ update: async (version2) => {
22046
+ if (!canUpdate || !npm)
22047
+ throw new Error("Use the original package manager to update this installation");
22048
+ await runInstallationCommand(npm.executable, ["install", "--global", "--prefix", prefix, `${name}@${installationVersion(version2)}`], env, 3e5);
22049
+ }
22050
+ };
22051
+ }
22052
+ const parent = path4.dirname(directory);
22053
+ if (parent === directory)
22054
+ break;
22055
+ directory = parent;
22056
+ }
22057
+ return null;
22058
+ }
22059
+
21741
22060
  // dist/command.js
21742
22061
  var OpenCodeExecutableError = class extends Error {
21743
22062
  code = "OPENCODE_NOT_FOUND";
@@ -21772,16 +22091,34 @@ function resolveOpenCodeExecutable(input = {}, dependencies = {}) {
21772
22091
  }, dependencies);
21773
22092
  if (!resolution)
21774
22093
  throw new OpenCodeExecutableError();
21775
- return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable : path3.resolve(resolution.executable);
22094
+ return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable : path5.resolve(resolution.executable);
21776
22095
  }
21777
- function openCodeServerInvocation(executable, environment, platform = process.platform) {
21778
- return commandInvocation(executable, ["serve", "--hostname=127.0.0.1", "--port=0"], environment, platform);
22096
+ function openCodeServerInvocation(executable, environment, platform = process.platform, port = 0) {
22097
+ return commandInvocation(executable, ["serve", "--hostname=127.0.0.1", `--port=${port}`], environment, platform);
21779
22098
  }
21780
22099
 
21781
22100
  // dist/server-connection.js
21782
22101
  var DEFAULT_STARTUP_TIMEOUT_MS = 2e4;
21783
22102
  var DEFAULT_CLOSE_TIMEOUT_MS = 3e3;
22103
+ var STARTUP_ATTEMPTS = 3;
21784
22104
  var SERVER_USERNAME = "codexhost";
22105
+ function freeLoopbackPort() {
22106
+ return new Promise((resolve, reject) => {
22107
+ const probe = createServer();
22108
+ probe.unref();
22109
+ probe.once("error", reject);
22110
+ probe.listen({ host: "127.0.0.1", port: 0 }, () => {
22111
+ const address = probe.address();
22112
+ const port = typeof address === "object" && address ? address.port : 0;
22113
+ probe.close(() => {
22114
+ if (port)
22115
+ resolve(port);
22116
+ else
22117
+ reject(new Error("Failed to assign an OpenCode Server loopback port"));
22118
+ });
22119
+ });
22120
+ });
22121
+ }
21785
22122
  function isRecord2(value) {
21786
22123
  return typeof value === "object" && value !== null && !Array.isArray(value);
21787
22124
  }
@@ -21849,9 +22186,9 @@ function signalProcessTree(child, signal) {
21849
22186
  }
21850
22187
  }
21851
22188
  function safeOpenCodeServerCwd(environment) {
21852
- const candidates = [environment.USERPROFILE, environment.HOME, homedir(), tmpdir()];
22189
+ const candidates = [environment.USERPROFILE, environment.HOME, homedir2(), tmpdir()];
21853
22190
  for (const candidate of candidates) {
21854
- if (!candidate || !path4.isAbsolute(candidate))
22191
+ if (!candidate || !path6.isAbsolute(candidate))
21855
22192
  continue;
21856
22193
  try {
21857
22194
  if (!fs2.statSync(candidate).isDirectory())
@@ -21903,7 +22240,8 @@ var OpenCodeServerConnection = class {
21903
22240
  ...spawnOptions,
21904
22241
  windowsVerbatimArguments: spawnOptions.windowsVerbatimArguments
21905
22242
  }),
21906
- sleep: (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds))
22243
+ sleep: (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)),
22244
+ assignPort: freeLoopbackPort
21907
22245
  }) {
21908
22246
  this.#options = options;
21909
22247
  this.#environment = options.environment ?? process.env;
@@ -21959,11 +22297,26 @@ var OpenCodeServerConnection = class {
21959
22297
  OPENCODE_SERVER_USERNAME: SERVER_USERNAME,
21960
22298
  OPENCODE_SERVER_PASSWORD: password
21961
22299
  };
21962
- const invocation = openCodeServerInvocation(executable, environment);
21963
22300
  const serverCwd = (this.#dependencies.resolveServerCwd ?? safeOpenCodeServerCwd)(environment);
21964
22301
  if (!serverCwd) {
21965
22302
  throw new OpenCodeTransportError("unavailable", "OpenCode Server requires a writable startup directory");
21966
22303
  }
22304
+ let lastError;
22305
+ for (let attempt = 0; attempt < STARTUP_ATTEMPTS; attempt += 1) {
22306
+ try {
22307
+ return await this.#startAttempt(executable, environment, serverCwd, password);
22308
+ } catch (error51) {
22309
+ lastError = error51;
22310
+ if (!(error51 instanceof OpenCodeTransportError) || error51.code !== "processExited") {
22311
+ throw classifySdkError(error51, "Server startup");
22312
+ }
22313
+ }
22314
+ }
22315
+ throw classifySdkError(lastError, "Server startup");
22316
+ }
22317
+ async #startAttempt(executable, environment, serverCwd, password) {
22318
+ const port = await (this.#dependencies.assignPort ?? freeLoopbackPort)();
22319
+ const invocation = openCodeServerInvocation(executable, environment, process.platform, port);
21967
22320
  let child;
21968
22321
  try {
21969
22322
  child = this.#dependencies.spawn(invocation.command, invocation.arguments, {
@@ -22024,7 +22377,7 @@ var OpenCodeServerConnection = class {
22024
22377
  return { baseUrl, authorization };
22025
22378
  } catch (error51) {
22026
22379
  await this.#stopChild(child).catch(() => void 0);
22027
- throw classifySdkError(error51, "Server startup");
22380
+ throw error51;
22028
22381
  }
22029
22382
  }
22030
22383
  async #stopChild(child) {
@@ -22284,7 +22637,7 @@ var SdkOpenCodeTransport = class {
22284
22637
 
22285
22638
  // dist/file-change-verification.js
22286
22639
  import fs3 from "node:fs";
22287
- import path5 from "node:path";
22640
+ import path7 from "node:path";
22288
22641
  function missingPath(error51) {
22289
22642
  if (!error51 || typeof error51 !== "object")
22290
22643
  return false;
@@ -22296,33 +22649,33 @@ function hasDotPathSegment(value) {
22296
22649
  return segments.some((segment) => segment === "." || segment === "..");
22297
22650
  }
22298
22651
  function canonicalDirectoryPath(value) {
22299
- let candidate = path5.resolve(value);
22652
+ let candidate = path7.resolve(value);
22300
22653
  const missingSegments = [];
22301
22654
  for (; ; ) {
22302
22655
  try {
22303
- return path5.join(fs3.realpathSync.native(candidate), ...missingSegments);
22656
+ return path7.join(fs3.realpathSync.native(candidate), ...missingSegments);
22304
22657
  } catch (error51) {
22305
22658
  if (!missingPath(error51))
22306
22659
  return void 0;
22307
- const parent = path5.dirname(candidate);
22660
+ const parent = path7.dirname(candidate);
22308
22661
  if (parent === candidate)
22309
22662
  return void 0;
22310
- missingSegments.unshift(path5.basename(candidate));
22663
+ missingSegments.unshift(path7.basename(candidate));
22311
22664
  candidate = parent;
22312
22665
  }
22313
22666
  }
22314
22667
  }
22315
22668
  function canonicalFilePath(value) {
22316
- const absolute = path5.resolve(value);
22317
- const parent = canonicalDirectoryPath(path5.dirname(absolute));
22318
- return parent ? path5.join(parent, path5.basename(absolute)) : void 0;
22669
+ const absolute = path7.resolve(value);
22670
+ const parent = canonicalDirectoryPath(path7.dirname(absolute));
22671
+ return parent ? path7.join(parent, path7.basename(absolute)) : void 0;
22319
22672
  }
22320
22673
  function pathIsWithin(root, candidate, allowRoot) {
22321
- const relative = path5.relative(root, candidate);
22322
- return allowRoot && relative === "" || relative !== "" && relative !== ".." && !relative.startsWith(`..${path5.sep}`) && !path5.isAbsolute(relative);
22674
+ const relative = path7.relative(root, candidate);
22675
+ return allowRoot && relative === "" || relative !== "" && relative !== ".." && !relative.startsWith(`..${path7.sep}`) && !path7.isAbsolute(relative);
22323
22676
  }
22324
22677
  function verifiedOpenCodeWorktree(sessionDirectory, paths) {
22325
- if (!paths || typeof paths !== "object" || typeof sessionDirectory !== "string" || typeof paths.directory !== "string" || typeof paths.worktree !== "string" || hasDotPathSegment(sessionDirectory) || hasDotPathSegment(paths.directory) || hasDotPathSegment(paths.worktree) || !path5.isAbsolute(sessionDirectory) || !path5.isAbsolute(paths.directory) || !path5.isAbsolute(paths.worktree)) {
22678
+ if (!paths || typeof paths !== "object" || typeof sessionDirectory !== "string" || typeof paths.directory !== "string" || typeof paths.worktree !== "string" || hasDotPathSegment(sessionDirectory) || hasDotPathSegment(paths.directory) || hasDotPathSegment(paths.worktree) || !path7.isAbsolute(sessionDirectory) || !path7.isAbsolute(paths.directory) || !path7.isAbsolute(paths.worktree)) {
22326
22679
  return void 0;
22327
22680
  }
22328
22681
  const session = canonicalDirectoryPath(sessionDirectory);
@@ -22334,10 +22687,10 @@ function verifiedOpenCodeWorktree(sessionDirectory, paths) {
22334
22687
  return worktree;
22335
22688
  }
22336
22689
  function openCodeFileIdentity(file2, worktree) {
22337
- if (typeof file2 !== "string" || typeof worktree !== "string" || hasDotPathSegment(file2) || hasDotPathSegment(worktree) || !path5.isAbsolute(worktree) || !file2 || file2.includes("\0") || file2.includes("\n") || file2.includes("\r")) {
22690
+ if (typeof file2 !== "string" || typeof worktree !== "string" || hasDotPathSegment(file2) || hasDotPathSegment(worktree) || !path7.isAbsolute(worktree) || !file2 || file2.includes("\0") || file2.includes("\n") || file2.includes("\r")) {
22338
22691
  return void 0;
22339
22692
  }
22340
- const candidate = canonicalFilePath(path5.isAbsolute(file2) ? file2 : path5.resolve(worktree, file2));
22693
+ const candidate = canonicalFilePath(path7.isAbsolute(file2) ? file2 : path7.resolve(worktree, file2));
22341
22694
  return candidate && pathIsWithin(worktree, candidate, false) ? candidate : void 0;
22342
22695
  }
22343
22696
 
@@ -22631,7 +22984,7 @@ function sameCwd(left, right) {
22631
22984
  try {
22632
22985
  return fs4.realpathSync.native(value);
22633
22986
  } catch {
22634
- return path6.resolve(value);
22987
+ return path8.resolve(value);
22635
22988
  }
22636
22989
  };
22637
22990
  return canonical(left) === canonical(right);
@@ -23986,7 +24339,7 @@ var OpenCodeAdapter = class {
23986
24339
  };
23987
24340
 
23988
24341
  // dist/version.js
23989
- import { execFile } from "node:child_process";
24342
+ import { execFile as execFile2 } from "node:child_process";
23990
24343
  import { promisify } from "node:util";
23991
24344
  function openCodeMajor(version2) {
23992
24345
  const match = /^(?:opencode\s+)?v?([12])\.\d+\.\d+(?:[-+][\w.-]+)?$/u.exec(version2.trim());
@@ -24001,7 +24354,7 @@ async function detectOpenCode(options) {
24001
24354
  environment
24002
24355
  });
24003
24356
  const invocation = commandInvocation(executable, ["--version"], environment);
24004
- const { stdout } = await promisify(execFile)(invocation.command, invocation.arguments, {
24357
+ const { stdout } = await promisify(execFile2)(invocation.command, invocation.arguments, {
24005
24358
  env: environment,
24006
24359
  timeout: options.startupTimeoutMs ?? 2e4,
24007
24360
  maxBuffer: 16384,
@@ -24017,7 +24370,7 @@ import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
24017
24370
 
24018
24371
  // dist/v2/state.js
24019
24372
  import fs5 from "node:fs";
24020
- import path7 from "node:path";
24373
+ import path9 from "node:path";
24021
24374
  var harnessId = harnessIdSchema.parse("opencode");
24022
24375
  function failure(message, code = "nativeFailure") {
24023
24376
  return {
@@ -24037,7 +24390,7 @@ function sameDirectory(left, right) {
24037
24390
  try {
24038
24391
  return fs5.realpathSync(value);
24039
24392
  } catch {
24040
- return path7.resolve(value);
24393
+ return path9.resolve(value);
24041
24394
  }
24042
24395
  };
24043
24396
  return canonical(left) === canonical(right);
@@ -25952,7 +26305,7 @@ var V2Connection = class {
25952
26305
  };
25953
26306
 
25954
26307
  // dist/v2/history.js
25955
- import path8 from "node:path";
26308
+ import path10 from "node:path";
25956
26309
  async function readMessages(client2, sessionID) {
25957
26310
  const messages = [];
25958
26311
  let cursor;
@@ -26077,9 +26430,9 @@ function fileChanges(session, turn, diffs) {
26077
26430
  if (!diffs.length)
26078
26431
  return void 0;
26079
26432
  const changes = diffs.map((diff) => {
26080
- const absolute = path8.resolve(session.location.directory, diff.file);
26081
- const relative = path8.relative(session.location.directory, absolute);
26082
- if (relative.startsWith(`..${path8.sep}`) || relative === ".." || path8.isAbsolute(relative))
26433
+ const absolute = path10.resolve(session.location.directory, diff.file);
26434
+ const relative = path10.relative(session.location.directory, absolute);
26435
+ if (relative.startsWith(`..${path10.sep}`) || relative === ".." || path10.isAbsolute(relative))
26083
26436
  throw new Error("OpenCode v2 diff escaped the Session directory");
26084
26437
  return {
26085
26438
  path: absolute,
@@ -26986,14 +27339,58 @@ function normalize(error51) {
26986
27339
  return failure(error51 instanceof Error ? error51.message : String(error51), error51 instanceof OpenCodeExecutableError ? "notInstalled" : "unavailable");
26987
27340
  }
26988
27341
 
27342
+ // dist/installation.js
27343
+ import { realpath as realpath2 } from "node:fs/promises";
27344
+ import { homedir as homedir3 } from "node:os";
27345
+ import path11 from "node:path";
27346
+ function createOpenCodeInstallation(environment, command) {
27347
+ let update;
27348
+ return createInstallationManager({
27349
+ async check() {
27350
+ const executable = resolveOpenCodeExecutable({
27351
+ environment,
27352
+ ...command ? { command } : {}
27353
+ });
27354
+ const currentVersion = versionFromOutput(await runInstallationCommand(executable, ["--version"], environment));
27355
+ const npm = await npmInstallation(executable, ["opencode-ai"], environment);
27356
+ let latestVersion;
27357
+ let canUpdate;
27358
+ if (npm) {
27359
+ latestVersion = await npm.latest();
27360
+ canUpdate = npm.canUpdate;
27361
+ update = npm.update;
27362
+ } else {
27363
+ const release = JSON.parse(await fetchInstallationText("https://api.github.com/repos/anomalyco/opencode/releases/latest"));
27364
+ latestVersion = installationVersion(release.tag_name);
27365
+ const home = environment.HOME ?? environment.USERPROFILE ?? homedir3();
27366
+ const standard = path11.join(home, ".opencode", "bin", process.platform === "win32" ? "opencode.exe" : "opencode");
27367
+ canUpdate = process.platform !== "win32" && path11.resolve(executable) === standard && await realpath2(executable) === standard;
27368
+ update = async (version2) => {
27369
+ await runInstallationCommand(executable, ["upgrade", version2, "--method", "curl"], environment, 3e5);
27370
+ };
27371
+ }
27372
+ return {
27373
+ currentVersion,
27374
+ latestVersion,
27375
+ updateAvailable: newerInstallationVersion(currentVersion, latestVersion),
27376
+ canUpdate,
27377
+ ...!canUpdate ? { message: "Use the original package manager to update this OpenCode installation." } : {}
27378
+ };
27379
+ },
27380
+ async update(state) {
27381
+ await update(state.latestVersion);
27382
+ }
27383
+ });
27384
+ }
27385
+
26989
27386
  // dist/plugin.js
26990
27387
  var OPENCODE_COMMAND_ENV = "CODEXHOST_OPENCODE_COMMAND";
26991
27388
  function createHarnessAdapter(context) {
26992
27389
  const environment = { ...context.environment };
26993
- return new OpenCodeAdapter2({
27390
+ return Object.assign(new OpenCodeAdapter2({
26994
27391
  ...environment[OPENCODE_COMMAND_ENV] ? { command: environment[OPENCODE_COMMAND_ENV] } : {},
26995
27392
  environment
26996
- });
27393
+ }), { installation: createOpenCodeInstallation(environment, environment[OPENCODE_COMMAND_ENV]) });
26997
27394
  }
26998
27395
  export {
26999
27396
  OPENCODE_COMMAND_ENV,